|
1 | 1 | --- |
2 | | -description: Onboard an existing project to gstack in one command. |
| 2 | +description: Onboard a new or existing project to gstack in one command. |
3 | 3 | --- |
4 | 4 |
|
5 | 5 | # /gstack init |
6 | 6 |
|
7 | | -You are the `init` skill for gstack. Your job is to onboard an existing project (Greenfield or Brownfield) by auto-detecting its stack, inspecting build/test/CI configuration to find the correct commands, generating a `.gstack.json` file, and scaffolding a default review checklist if one is missing. |
| 7 | +You are the `init` skill for gstack. Your job is to onboard a project — whether it's an empty directory (Greenfield) or an existing codebase (Brownfield) — by detecting the situation, scaffolding if needed, auto-detecting the stack, generating `.gstack.json`, and scaffolding a review checklist and AI context file. |
8 | 8 |
|
9 | 9 | Follow these steps precisely: |
10 | 10 |
|
11 | | -1. **Pre-flight Checks** |
12 | | - - Check if you are currently executing inside a gstack installation directory itself (e.g., if `./setup` and `browse/src/cli.ts` exist relative to the root). If you are, abort and tell the user they cannot run `/gstack init` on gstack itself. |
13 | | - - Look for an existing `.gstack.json` in the current project root directory. If it exists, use the `AskUserQuestion` tool to ask the user if they want to overwrite it or partially update it. If they decline, abort. |
14 | | - |
15 | | -2. **Auto-detect Stack from Project Files** |
16 | | - - Look at the files in the current root directory (`package.json`, `Gemfile`, `go.mod`, `Cargo.toml`, `pyproject.toml`, `build.gradle`, etc.). |
17 | | - - Identify the primary language and framework. For monorepos, multiple stacks can match; pick the root or dominant one. |
18 | | - |
19 | | -3. **Inspect Actual Commands** |
20 | | - - Examine the configuration files from the detected stack to determine the correct test and build/eval commands. |
21 | | - - For Node.js/TypeScript: Check `package.json` for `scripts.test`, `scripts.build`, etc. |
22 | | - - For Ruby on Rails: Look for `bin/test` or `rspec` in `Gemfile`. |
23 | | - - For Go: Assume `go test ./...` if `go.mod` is present. |
24 | | - - For Rust: Assume `cargo test` if `Cargo.toml` is present. |
25 | | - - For Python: Look at `pyproject.toml` or `tox.ini` for `pytest` or `tox`. |
26 | | - - **Crucial step**: Search for CI configuration files (e.g., `.github/workflows/*.yml` or `.gitlab-ci.yml`) to see exactly how tests are run in CI. Extract those commands if they are robust, as CI is the ground truth. |
27 | | - |
28 | | -4. **Generate `.gstack.json`** |
29 | | - - Present the detected test and eval commands to the user using the `AskUserQuestion` tool to confirm before writing them. |
30 | | - - Once confirmed (or adjusted by the user), generate the `.gstack.json` file in the current root directory using the following schema (include `evalCommand` as `null` if none, and an empty array for `evalPatterns` if none): |
31 | | - ```json |
32 | | - { |
33 | | - "testCommand": "<detected or user-supplied command>", |
34 | | - "evalCommand": "<detected or null>", |
35 | | - "evalPatterns": [], |
36 | | - "reviewChecklist": ".claude/skills/review/checklist.md" |
37 | | - } |
38 | | - ``` |
39 | | - |
40 | | -5. **Scaffold Review Checklist if Missing** |
41 | | - - Check if `.claude/skills/review/checklist.md` exists in the current project. |
42 | | - - If it does NOT exist, create the directory `.claude/skills/review/` if necessary. |
43 | | - - Read the universal default checklist from the gstack installation at `.claude/skills/gstack/review/checklists/default.md`. |
44 | | - - Write the exact contents of that file to `.claude/skills/review/checklist.md` in the current project. |
45 | | - |
46 | | -6. **Summary Output** |
47 | | - - Output a short, helpful summary of what was detected and created (e.g., ".gstack.json created", "checklist.md scaffolded"). |
48 | | - - Conclude by telling the user: "You are now ready to use gstack! Use `/review` to review your code, and `/ship` to ship it." |
| 11 | +--- |
| 12 | + |
| 13 | +## Step 0: Pre-flight Checks |
| 14 | + |
| 15 | +- Check if you are currently executing inside a gstack installation directory itself (e.g., if `./setup` and `browse/src/cli.ts` exist relative to the root). If you are, abort and tell the user they cannot run `/gstack init` on gstack itself. |
| 16 | +- Look for an existing `.gstack.json` in the current project root directory. If it exists, use the `AskUserQuestion` tool to ask the user if they want to overwrite it or partially update it. If they decline, abort. |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## Step 1: Detect Project Mode |
| 21 | + |
| 22 | +List the files in the current directory. Determine the mode: |
| 23 | + |
| 24 | +- **Greenfield Mode**: The directory is empty, or contains only `.git`, `.gitignore`, `README.md`, `.DS_Store`, or similar boilerplate. There are no language-specific project files. |
| 25 | +- **Brownfield Mode**: The directory contains project files like `package.json`, `Gemfile`, `go.mod`, `Cargo.toml`, `pyproject.toml`, etc. |
| 26 | + |
| 27 | +If Greenfield, proceed to **Step 2**. If Brownfield, skip directly to **Step 5**. |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Step 2 (Greenfield): Ask What to Build |
| 32 | + |
| 33 | +Use the `AskUserQuestion` tool to prompt: |
| 34 | + |
| 35 | +> "It looks like you're starting a new project! What are you building and what tech stack would you like to use?" |
| 36 | +> |
| 37 | +> Examples: "A SaaS dashboard with Next.js and Tailwind", "A CLI tool in Go", "A REST API with Rails" |
| 38 | +
|
| 39 | +--- |
| 40 | + |
| 41 | +## Step 3 (Greenfield): Scaffold the Project |
| 42 | + |
| 43 | +Based on the user's answer, determine and execute the correct scaffolding command **in the current directory**. Examples: |
| 44 | + |
| 45 | +| Stack | Command | |
| 46 | +|---|---| |
| 47 | +| Next.js | `npx -y create-next-app@latest . --use-npm` | |
| 48 | +| Vite (React) | `npm create vite@latest . -- --template react-ts` | |
| 49 | +| Rails | `rails new . --skip-git` | |
| 50 | +| Go | `go mod init <module-name>` | |
| 51 | +| Rust | `cargo init .` | |
| 52 | +| Python | `mkdir -p src && touch src/__init__.py && python3 -m venv .venv` | |
| 53 | + |
| 54 | +Use the table above as guidance, but reason about the best command based on what the user actually asked for. Always scaffold into the current directory (`.`), not a subdirectory. If the scaffold command requires interactive input, prefer flags that skip prompts (e.g., `--yes`, `--use-npm`, `--skip-git`). |
| 55 | + |
| 56 | +After execution, verify the scaffold succeeded by checking that new project files were created. |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +## Step 4 (Greenfield): Scaffold AI Context File |
| 61 | + |
| 62 | +Create an `AGENTS.md` file in the project root with conventions tailored to the chosen stack. This file helps AI coding agents understand the project's patterns. Example content for a Next.js project: |
| 63 | + |
| 64 | +```markdown |
| 65 | +# AI Agent Context |
| 66 | + |
| 67 | +## Stack |
| 68 | +- Next.js (App Router) with TypeScript |
| 69 | +- Styling: Tailwind CSS |
| 70 | + |
| 71 | +## Conventions |
| 72 | +- Use React Server Components by default; add "use client" only when needed |
| 73 | +- Use the App Router (`app/` directory), not Pages Router |
| 74 | +- Prefer server actions over API routes for mutations |
| 75 | +- Use `next/image` for all images |
| 76 | +- Keep components in `src/components/`, utilities in `src/lib/` |
| 77 | +``` |
| 78 | + |
| 79 | +Tailor the content to whatever stack the user chose. Keep it concise (under 30 lines) and focused on patterns that an AI agent would need to know. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## Step 5 (Brownfield): Auto-detect Stack from Project Files |
| 84 | + |
| 85 | +- Look at the files in the current root directory (`package.json`, `Gemfile`, `go.mod`, `Cargo.toml`, `pyproject.toml`, `build.gradle`, etc.). |
| 86 | +- Identify the primary language and framework. For monorepos, multiple stacks can match; pick the root or dominant one. |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## Step 6: Inspect Actual Commands |
| 91 | + |
| 92 | +- Examine the configuration files from the detected stack to determine the correct test and build/eval commands. |
| 93 | +- For Node.js/TypeScript: Check `package.json` for `scripts.test`, `scripts.build`, etc. |
| 94 | +- For Ruby on Rails: Look for `bin/test` or `rspec` in `Gemfile`. |
| 95 | +- For Go: Assume `go test ./...` if `go.mod` is present. |
| 96 | +- For Rust: Assume `cargo test` if `Cargo.toml` is present. |
| 97 | +- For Python: Look at `pyproject.toml` or `tox.ini` for `pytest` or `tox`. |
| 98 | +- **Crucial step**: Search for CI configuration files (e.g., `.github/workflows/*.yml` or `.gitlab-ci.yml`) to see exactly how tests are run in CI. Extract those commands if they are robust, as CI is the ground truth. |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## Step 7: Generate `.gstack.json` |
| 103 | + |
| 104 | +- Present the detected test and eval commands to the user using the `AskUserQuestion` tool to confirm before writing them. |
| 105 | +- Once confirmed (or adjusted by the user), generate the `.gstack.json` file in the current root directory using the following schema (include `evalCommand` as `null` if none, and an empty array for `evalPatterns` if none): |
| 106 | + ```json |
| 107 | + { |
| 108 | + "testCommand": "<detected or user-supplied command>", |
| 109 | + "evalCommand": "<detected or null>", |
| 110 | + "evalPatterns": [], |
| 111 | + "reviewChecklist": ".claude/skills/review/checklist.md" |
| 112 | + } |
| 113 | + ``` |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +## Step 8: Scaffold Review Checklist if Missing |
| 118 | + |
| 119 | +- Check if `.claude/skills/review/checklist.md` exists in the current project. |
| 120 | +- If it does NOT exist, create the directory `.claude/skills/review/` if necessary. |
| 121 | +- Read the universal default checklist from the gstack installation at `.claude/skills/gstack/review/checklists/default.md`. |
| 122 | +- Write the exact contents of that file to `.claude/skills/review/checklist.md` in the current project. |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +## Step 9: Summary Output |
| 127 | + |
| 128 | +- Output a short, helpful summary of what was detected and created (e.g., "Project scaffolded with Next.js", ".gstack.json created", "checklist.md scaffolded", "AGENTS.md created"). |
| 129 | +- Conclude by telling the user: "You are now ready to use gstack! Use `/review` to review your code, and `/ship` to ship it." |
0 commit comments