forge-cc 0.1.40 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +454 -338
  2. package/dist/cli.js +194 -906
  3. package/dist/cli.js.map +1 -1
  4. package/dist/config/loader.d.ts +1 -1
  5. package/dist/config/loader.js +49 -56
  6. package/dist/config/loader.js.map +1 -1
  7. package/dist/config/schema.d.ts +37 -125
  8. package/dist/config/schema.js +13 -28
  9. package/dist/config/schema.js.map +1 -1
  10. package/dist/doctor.d.ts +10 -0
  11. package/dist/doctor.js +148 -0
  12. package/dist/doctor.js.map +1 -0
  13. package/dist/gates/index.d.ts +14 -12
  14. package/dist/gates/index.js +53 -105
  15. package/dist/gates/index.js.map +1 -1
  16. package/dist/gates/lint-gate.d.ts +2 -2
  17. package/dist/gates/lint-gate.js +60 -66
  18. package/dist/gates/lint-gate.js.map +1 -1
  19. package/dist/gates/tests-gate.d.ts +2 -4
  20. package/dist/gates/tests-gate.js +75 -203
  21. package/dist/gates/tests-gate.js.map +1 -1
  22. package/dist/gates/types-gate.d.ts +2 -2
  23. package/dist/gates/types-gate.js +53 -59
  24. package/dist/gates/types-gate.js.map +1 -1
  25. package/dist/go/linear-sync-cli.js +13 -4
  26. package/dist/go/linear-sync-cli.js.map +1 -1
  27. package/dist/go/linear-sync.d.ts +1 -0
  28. package/dist/go/linear-sync.js +67 -4
  29. package/dist/go/linear-sync.js.map +1 -1
  30. package/dist/linear/client.d.ts +34 -105
  31. package/dist/linear/client.js +85 -365
  32. package/dist/linear/client.js.map +1 -1
  33. package/dist/linear/issues.d.ts +3 -1
  34. package/dist/linear/issues.js +14 -2
  35. package/dist/linear/issues.js.map +1 -1
  36. package/dist/linear/projects.js +3 -2
  37. package/dist/linear/projects.js.map +1 -1
  38. package/dist/linear/sync.d.ts +15 -0
  39. package/dist/linear/sync.js +102 -0
  40. package/dist/linear/sync.js.map +1 -0
  41. package/dist/runner/loop.d.ts +4 -0
  42. package/dist/runner/loop.js +168 -0
  43. package/dist/runner/loop.js.map +1 -0
  44. package/dist/runner/prompt.d.ts +14 -0
  45. package/dist/runner/prompt.js +59 -0
  46. package/dist/runner/prompt.js.map +1 -0
  47. package/dist/runner/update.d.ts +1 -0
  48. package/dist/runner/update.js +72 -0
  49. package/dist/runner/update.js.map +1 -0
  50. package/dist/server.d.ts +6 -2
  51. package/dist/server.js +43 -101
  52. package/dist/server.js.map +1 -1
  53. package/dist/setup.d.ts +5 -0
  54. package/dist/setup.js +208 -0
  55. package/dist/setup.js.map +1 -0
  56. package/dist/state/cache.d.ts +3 -0
  57. package/dist/state/cache.js +23 -0
  58. package/dist/state/cache.js.map +1 -0
  59. package/dist/state/status.d.ts +66 -0
  60. package/dist/state/status.js +96 -0
  61. package/dist/state/status.js.map +1 -0
  62. package/dist/types.d.ts +46 -114
  63. package/dist/worktree/manager.d.ts +6 -103
  64. package/dist/worktree/manager.js +25 -296
  65. package/dist/worktree/manager.js.map +1 -1
  66. package/hooks/pre-commit-verify.js +109 -109
  67. package/package.json +3 -2
  68. package/skills/forge-go.md +583 -575
  69. package/skills/forge-setup.md +149 -388
  70. package/skills/forge-spec.md +367 -342
  71. package/skills/forge-triage.md +179 -133
  72. package/skills/forge-update.md +87 -93
@@ -1,342 +1,367 @@
1
- # /forge:spec — Linear Project to PRD with Milestones
2
-
3
- Turn a Linear project into a detailed PRD with milestones and issues. This skill scans the codebase, conducts an adaptive interview, generates a PRD, and syncs the plan back to Linear.
4
-
5
- ## Instructions
6
-
7
- Follow these steps exactly. The interview is adaptive — lead with recommendations, not blank-slate questions.
8
-
9
- ### Step 1 — Select Linear Project
10
-
11
- Fetch incomplete projects from Linear:
12
-
13
- ```
14
- Use mcp__linear__list_projects to get all existing projects.
15
- ```
16
-
17
- Filter to projects in "Backlog" state (these are triaged but not yet specced). Present them as a numbered list:
18
-
19
- ```
20
- ## Projects Ready for Spec
21
-
22
- 1. **Project Name** — description
23
- 2. **Project Name** — description
24
- ```
25
-
26
- Then ask:
27
-
28
- > Which project would you like to spec? Pick a number, or type a project name.
29
-
30
- If no Backlog projects exist, say:
31
-
32
- > No projects in Backlog state. Run `/forge:triage` first to create projects from your ideas, or create one directly in Linear.
33
-
34
- Wait for the user's selection before continuing.
35
-
36
- ### Step 2 — Scan the Codebase
37
-
38
- Run 3 parallel codebase scan agents using the Task tool. Each agent should use the scanner module at `src/spec/scanners.ts`:
39
-
40
- **Agent 1 — Structure Scanner:**
41
- ```
42
- Scan the project directory for framework, language, config files, dependencies, and key files.
43
- Use the scanStructure() function from the scanner module.
44
- Report the StructureScanResult.
45
- ```
46
-
47
- **Agent 2 — Routes/UI Scanner:**
48
- ```
49
- Scan for route files, pages, API routes, layouts, and routing framework.
50
- Use the scanRoutes() function from the scanner module.
51
- Report the RoutesScanResult.
52
- ```
53
-
54
- **Agent 3 — Data/APIs Scanner:**
55
- ```
56
- Scan for API endpoints, database files, env files, external services, and schema files.
57
- Use the scanDataAPIs() function from the scanner module.
58
- Report the DataAPIsScanResult.
59
- ```
60
-
61
- Combine the results into a `ScanAllResult`. Print a brief summary:
62
-
63
- ```
64
- ## Codebase Scan Complete
65
-
66
- - **Framework:** Next.js (TypeScript)
67
- - **Pages:** 12 | **API Routes:** 8
68
- - **Dependencies:** 24 | **DB Files:** 3
69
- - **Key Files:** src/lib/auth.ts, src/db/schema.prisma, ...
70
- ```
71
-
72
- If the current working directory does not look like a project (no package.json, no src/), warn:
73
-
74
- > This directory doesn't look like a project root. Should I scan here, or provide a path to the project?
75
-
76
- ### Step 3 — LLM-Driven Adaptive Interview
77
-
78
- You (the LLM) drive the interview. The interview engine (`src/spec/interview.ts`) is a state tracker and coverage analyzer you decide what to ask and when to stop. Use `createInterview()` to initialize state, `addQuestion()` to register each question you ask, `recordAnswer()` to record responses, and `getCoverageAnalysis()` to assess coverage gaps.
79
-
80
- The interview covers 5 sections:
81
-
82
- 1. **Problem & Goals** — core problem, desired outcome, success criteria, impact/urgency, current workarounds, who feels the pain
83
- 2. **User Stories** — primary users, user workflows step-by-step, secondary users, edge cases, permissions/roles, error states
84
- 3. **Technical Approach** — architecture pattern, data model/schema, APIs/integrations, auth/security, performance requirements, error handling, existing code to leverage
85
- 4. **Scope** — in scope boundaries, out of scope, sacred files/areas, constraints, future phases explicitly deferred
86
- 5. **Milestones** — breakdown into chunks, dependencies between milestones, sizing (fits in one agent context?), verification criteria, delivery order, risk areas
87
-
88
- **Interview Loop — You Drive:**
89
-
90
- 1. Initialize interview state with `createInterview(projectName, scanResults)`
91
- 2. Start with a broad opening question for Problem & Goals, informed by scan results
92
- 3. After each answer:
93
- - Assess coverage gaps mentally (which topics are uncovered? which answers were vague?)
94
- - Generate the next question based on: scan results, all prior Q&A, what's still ambiguous
95
- - Probe deeper on vague or short answers don't accept "TBD" or one-liners for important topics
96
- - Move to the next section when the current one has thorough coverage
97
- - Revisit earlier sections if later answers reveal new info
98
- 4. Register each question with `addQuestion(state, section, text, context, depth)` for tracking
99
- 5. Record each answer with `recordAnswer(state, questionId, answer)`
100
-
101
- **Question Principles Encode These:**
102
-
103
- - Ask about edge cases, error states, and "what could go wrong"
104
- - When the user mentions an integration, ask about auth, rate limits, failure modes
105
- - When the user describes a workflow, walk through it step-by-step
106
- - For milestones, actively challenge sizing "is this too big for one context window?"
107
- - Don't ask yes/no questions ask "how" and "what" questions that elicit detail
108
- - Circle back to earlier sections when new info surfaces
109
- - Follow interesting threads: if the user mentions migration, breaking changes, multiple user types, or external services, dig deeper
110
-
111
- **Stop Condition:**
112
-
113
- You determine you have enough detail for a thorough PRD across ALL sections, with no significant ambiguity remaining. Before transitioning to Step 4, print a coverage summary showing the final state of each section.
114
-
115
- **Early Exit:**
116
-
117
- If the user says "stop", "that's enough", "skip", or "generate it" at any time, respect that and move to Step 4 with what you have.
118
-
119
- **Milestone Sizing Constraint (Hard Rule):**
120
-
121
- Each milestone MUST be completable in one main agent context window. If a milestone requires more than ~4 agents across 2-3 waves, split it. This is non-negotiable — large milestones cause context overflow and execution failures. When interviewing about milestones, actively recommend splitting any milestone that looks too large.
122
-
123
- **Milestone Dependencies (dependsOn):**
124
-
125
- During the milestones phase of the interview, ask about milestone dependencies using AskUserQuestion. For each milestone after the first, ask:
126
-
127
- - question: "Does Milestone {N} depend on any previous milestones?"
128
- - options:
129
- - "No dependencies can start immediately"
130
- - "Depends on Milestone {N-1} (sequential)"
131
- - "Depends on specific milestones (I'll specify)"
132
-
133
- If milestones have explicit dependencies, include `**dependsOn:** 1, 2` in the milestone section of the PRD. If no dependencies are specified, omit the field (backward compatible — treated as sequential).
134
-
135
- Independent milestones enable parallel execution via `/forge:go`, which creates separate worktrees for each parallel milestone.
136
-
137
- **Question Format:**
138
-
139
- Mix AskUserQuestion (for structured choices) and conversational questions (for open-ended probing):
140
-
141
- - **Use AskUserQuestion** when there are clear option sets (architecture choices, yes/no with detail, picking from scan-derived options). Provide 2-4 options plus "Other (I'll describe)".
142
- - **Use conversational questions** when probing for depth, asking "how" or "what" questions, or exploring topics that don't have predefined options.
143
- - **NEVER present questions as numbered text lists.** Each structured question gets its own AskUserQuestion call.
144
- - **Lead with recommendations.** Every question includes context from the codebase scan. Never ask a blank "what do you want to build?" question.
145
-
146
- **Progress Display:**
147
-
148
- After each answer, show a compact coverage status:
149
-
150
- ```
151
- Progress: Problem & Goals [thorough] | User Stories [moderate] | Technical [thin] | Scope [none] | Milestones [none]
152
- ```
153
-
154
- **Draft Updates:**
155
-
156
- - **Update the PRD draft every 2-3 answers** (use `shouldUpdateDraft(state)` to check, `markDraftUpdated(state)` after writing). Write to `.planning/prds/{project-slug}.md`. Tell the user:
157
-
158
- > Updated PRD draft at `.planning/prds/{slug}.md` — you can review it anytime.
159
-
160
- **Do NOT do this (anti-pattern):**
161
-
162
- ```
163
- ### Round N
164
-
165
- 1. **[Section]** Question text?
166
- 2. **[Section]** Question text?
167
-
168
- > Answer by number...
169
- ```
170
-
171
- This numbered-text format is explicitly prohibited. Always use AskUserQuestion for structured choices.
172
-
173
- ### Step 4Generate PRD
174
-
175
- Using all gathered interview answers and codebase scan results, generate the final PRD. Use the generator module at `src/spec/generator.ts`:
176
-
177
- The PRD should follow this structure:
178
-
179
- ```markdown
180
- # PRD: {Project Name}
181
-
182
- ## Problem & Goals
183
- {Synthesized from interview answers}
184
-
185
- ## User Stories
186
- {Structured user stories derived from interview}
187
-
188
- ## Technical Approach
189
- {Stack decisions, architecture, constraints — informed by codebase scan}
190
-
191
- ## Scope
192
- ### In Scope
193
- {What will be built}
194
-
195
- ### Out of Scope
196
- {Explicitly excluded items}
197
-
198
- ### Sacred Files
199
- {Files/areas not to be touched}
200
-
201
- ## Milestones
202
-
203
- ### Milestone 1: {Name}
204
- **Goal:** {What this delivers}
205
- **Issues:**
206
- - [ ] Issue title — brief description
207
- - [ ] Issue title — brief description
208
-
209
- ### Milestone 2: {Name}
210
- **dependsOn:** 1
211
- **Goal:** {What this delivers}
212
- ...
213
- ```
214
-
215
- **Milestone sizing check:** Before finalizing, review each milestone against the sizing constraint. Every milestone MUST fit in one agent context window (~4 agents across 2-3 waves max). If any milestone exceeds this, split it into smaller milestones before writing the final PRD. Set `maxContextWindowFit: true` on all milestones — if you cannot make a milestone fit, flag it as `maxContextWindowFit: false` and warn the user.
216
-
217
- **Test criteria guidance:** Test criteria are optional. Only include them when the milestone produces testable behavior. Verification commands (`npx tsc --noEmit`, `npx forge verify`) are always included automatically — test criteria are for additional functional checks beyond mechanical gates. When including test criteria, make them **functional**, not structural:
218
- - Good: "CLI `npx forge verify` runs and exits 0", "tsc compiles with no errors", "the new gate produces structured JSON output"
219
- - Bad: "All new source files must have corresponding test files", "Run npx forge verify --gate tests"
220
-
221
- Write the final PRD to `.planning/prds/{project-slug}.md`.
222
-
223
- After writing the PRD file, **execute BOTH steps below — do not skip either**:
224
-
225
- 1. **Create status file:** Write `.planning/status/<slug>.json` with all milestones set to "pending". **You MUST include `linearProjectId`** — this is the Linear project UUID from the project selected in Step 1. Without it, `/forge:go` cannot sync Linear issue or project state and will silently skip all Linear operations. Copy the exact project ID string — do not omit this field:
226
- ```json
227
- {
228
- "project": "{project name}",
229
- "slug": "{slug}",
230
- "branch": "feat/{slug}",
231
- "createdAt": "{today}",
232
- "linearProjectId": "{Linear project UUID from Step 1}",
233
- "milestones": {
234
- "1": { "status": "pending" },
235
- "2": { "status": "pending" },
236
- ...
237
- }
238
- }
239
- ```
240
-
241
- 2. **Create feature branch:** `git checkout -b feat/{slug}`
242
-
243
- Tell the user:
244
-
245
- > Final PRD written to `.planning/prds/{slug}.md`.
246
- > Status file created at `.planning/status/{slug}.json`.
247
- > Feature branch `feat/{slug}` created.
248
-
249
- Present the full PRD in chat for review and ask:
250
-
251
- > Review the PRD above. You can:
252
- > - **Approve** — I'll create milestones and issues in Linear
253
- > - **Edit** — tell me what to change (e.g., "add a milestone for testing" or "remove the admin user story")
254
- > - **Regenerate** start the interview over
255
- >
256
- > What would you like to do?
257
-
258
- Wait for approval before continuing to Step 5.
259
-
260
- ### Step 5 Sync to Linear
261
-
262
- After the user approves the PRD, create milestones and issues in Linear.
263
-
264
- First, get the team ID:
265
-
266
- ```
267
- Use mcp__linear__list_teams to get available teams.
268
- ```
269
-
270
- If there is only one team, use it automatically. If multiple, ask the user which team.
271
-
272
- For each milestone in the PRD:
273
-
274
- ```
275
- Use mcp__linear__create_milestone with:
276
- - projectId: the selected project's ID
277
- - name: milestone name
278
- - description: milestone goal
279
- ```
280
-
281
- For each issue under that milestone:
282
-
283
- ```
284
- Use mcp__linear__create_issue with:
285
- - title: issue title
286
- - description: issue description (from PRD)
287
- - teamId: the team ID
288
- - projectId: the project ID
289
- - milestoneId: the milestone ID just created
290
- ```
291
-
292
- **After all milestones and issues are created, transition the project to "Planned" — this is a separate mandatory step, do not skip it:**
293
-
294
- ```
295
- Use mcp__linear__update_project to set the project state to "planned".
296
- ```
297
-
298
- **The project is a separate entity from its milestones and issues.** Creating milestones and issues does NOT automatically update the project state. You must explicitly call `mcp__linear__update_project`. Without this transition, `/forge:go` will find the project still in "Backlog" and the state machine will reject the "In Progress" transition.
299
-
300
- Print a summary:
301
-
302
- ```
303
- ## Synced to Linear
304
-
305
- - **Project:** {name} (now "Planned")
306
- - **Milestones:** {N} created
307
- - **Issues:** {M} created across all milestones
308
-
309
- View in Linear: {project URL}
310
- ```
311
-
312
- If any creation fails, report the error and continue with remaining items.
313
-
314
- ### Step 6 Handoff
315
-
316
- After sync, print the handoff prompt:
317
-
318
- ```
319
- ## Ready for Development
320
-
321
- PRD: `.planning/prds/{slug}.md`
322
- Status: `.planning/status/{slug}.json`
323
- Branch: `feat/{slug}`
324
- Linear: {project URL}
325
-
326
- **Next step:** Run `/forge:go` for one milestone at a time, or exit and run `npx forge run` to execute all milestones autonomously. The execution engine will:
327
- - Read the PRD and per-PRD status file
328
- - Spawn agent teams for each milestone
329
- - Verify each change with forge verification gates
330
- - Update status JSON and transition Linear issues automatically
331
- ```
332
-
333
- **Note:** `/forge:go` now uses git worktrees for session isolation. Multiple users can run `/forge:go` on different milestones simultaneously without conflicts.
334
-
335
- ## Edge Cases
336
-
337
- - **No Linear connection:** Warn the user. Still generate the PRD locally — skip the Linear sync steps.
338
- - **Empty codebase:** The interview still works — questions will be more open-ended without scan context. Note this to the user.
339
- - **User wants to spec a project not in Linear:** Allow it. Skip Step 1 project selection, ask for a project name, and create the Linear project in Step 5 before creating milestones.
340
- - **User provides info upfront:** If the user includes project details in the same message as `/forge:spec`, use that info to pre-fill interview answers and skip questions that are already answered.
341
- - **Very large codebase:** Scan agents may return truncated results. That's fine — the interview fills in gaps.
342
- - **Interrupted interview:** If the user stops mid-interview, save what you have to the PRD draft. They can resume by running `/forge:spec` again and selecting the same project.
1
+ # /forge:spec — Linear Project to PRD with Milestones
2
+
3
+ Turn a Linear project into a detailed PRD with milestones and issues. This skill scans the codebase, conducts an adaptive interview, generates a PRD, and syncs the plan back to Linear.
4
+
5
+ ## Instructions
6
+
7
+ Follow these steps exactly. The interview is adaptive — lead with recommendations, not blank-slate questions.
8
+
9
+ ### Step 1 — Select Linear Project
10
+
11
+ Fetch incomplete projects from Linear:
12
+
13
+ ```
14
+ Use mcp__linear__list_projects to get all existing projects.
15
+ ```
16
+
17
+ Filter to projects in "Backlog" state (these are triaged but not yet specced). Present them as a numbered list:
18
+
19
+ ```
20
+ ## Projects Ready for Spec
21
+
22
+ 1. **Project Name** — description
23
+ 2. **Project Name** — description
24
+ ```
25
+
26
+ Then ask:
27
+
28
+ > Which project would you like to spec? Pick a number, or type a project name.
29
+
30
+ If no Backlog projects exist, say:
31
+
32
+ > No projects in Backlog state. Run `/forge:triage` first to create projects from your ideas, or create one directly in Linear.
33
+
34
+ Wait for the user's selection before continuing.
35
+
36
+ ### Step 2 — Scan the Codebase
37
+
38
+ Run 3 parallel codebase scan agents using the Task tool (subagent_type: Explore):
39
+
40
+ **Agent 1 — Structure Scanner:**
41
+ ```
42
+ Use Glob and Read tools to scan for: package.json, tsconfig.json, .env*, config files, key directories (src/, app/, pages/, lib/).
43
+ Report: framework, language, dependencies, project structure, build tools.
44
+ ```
45
+
46
+ **Agent 2 — Routes/UI Scanner:**
47
+ ```
48
+ Use Glob and Grep tools to scan for: route files, pages, layouts, navigation components, route definitions.
49
+ Look in common locations: src/app/, src/pages/, src/routes/, app/, pages/.
50
+ Grep for route patterns (e.g., "createBrowserRouter", "Route", "router.", "app.get", "app.post").
51
+ Report: routing framework, page count, API route count, layout structure.
52
+ ```
53
+
54
+ **Agent 3 — Data/APIs Scanner:**
55
+ ```
56
+ Use Glob and Grep tools to scan for: API endpoints, database files (schema.prisma, migrations/, models/), env files (.env*), external service configs, ORM setup, SDK clients.
57
+ Grep for patterns like "fetch(", "axios", "prisma.", "mongoose.", "createClient".
58
+ Report: database type, API patterns, external integrations, auth setup.
59
+ ```
60
+
61
+ Combine the results into a plain-text summary. Print a brief overview:
62
+
63
+ ```
64
+ ## Codebase Scan Complete
65
+
66
+ - **Framework:** Next.js (TypeScript)
67
+ - **Pages:** 12 | **API Routes:** 8
68
+ - **Dependencies:** 24 | **DB Files:** 3
69
+ - **Key Files:** src/lib/auth.ts, src/db/schema.prisma, ...
70
+ ```
71
+
72
+ If the current working directory does not look like a project (no package.json, no src/), warn:
73
+
74
+ > This directory doesn't look like a project root. Should I scan here, or provide a path to the project?
75
+
76
+ ### Step 3 — LLM-Driven Adaptive Interview
77
+
78
+ You (the LLM) drive the interview directly. Track coverage mentally across the 5 sections. No TypeScript state tracking you are the state tracker.
79
+
80
+ The interview covers 5 sections:
81
+
82
+ 1. **Problem & Goals** — core problem, desired outcome, success criteria, impact/urgency, current workarounds, who feels the pain
83
+ 2. **User Stories** — primary users, user workflows step-by-step, secondary users, edge cases, permissions/roles, error states
84
+ 3. **Technical Approach** — architecture pattern, data model/schema, APIs/integrations, auth/security, performance requirements, error handling, existing code to leverage
85
+ 4. **Scope** — in scope boundaries, out of scope, sacred files/areas, constraints, future phases explicitly deferred
86
+ 5. **Milestones** — breakdown into chunks, dependencies between milestones, sizing (fits in one agent context?), verification criteria, delivery order, risk areas
87
+
88
+ **Interview Loop — You Drive:**
89
+
90
+ 1. Start with a broad opening question for Problem & Goals, informed by scan results
91
+ 2. After each answer:
92
+ - Assess coverage gaps mentally (which topics are uncovered? which answers were vague?)
93
+ - Generate the next question based on: scan results, all prior Q&A, what's still ambiguous
94
+ - Probe deeper on vague or short answers don't accept "TBD" or one-liners for important topics
95
+ - Move to the next section when the current one has thorough coverage
96
+ - Revisit earlier sections if later answers reveal new info
97
+ 3. Continue until all 5 sections have adequate coverage
98
+
99
+ **Question Principles Encode These:**
100
+
101
+ - Ask about edge cases, error states, and "what could go wrong"
102
+ - When the user mentions an integration, ask about auth, rate limits, failure modes
103
+ - When the user describes a workflow, walk through it step-by-step
104
+ - For milestones, actively challenge sizing "is this too big for one context window?"
105
+ - Don't ask yes/no questions ask "how" and "what" questions that elicit detail
106
+ - Circle back to earlier sections when new info surfaces
107
+ - Follow interesting threads: if the user mentions migration, breaking changes, multiple user types, or external services, dig deeper
108
+
109
+ **Stop Condition:**
110
+
111
+ You determine you have enough detail for a thorough PRD across ALL sections, with no significant ambiguity remaining. Before transitioning to Step 4, print a coverage summary showing the final state of each section.
112
+
113
+ **Early Exit:**
114
+
115
+ If the user says "stop", "that's enough", "skip", or "generate it" at any time, respect that and move to Step 4 with what you have.
116
+
117
+ **Milestone Sizing Constraint (Hard Rule):**
118
+
119
+ Each milestone MUST be completable in one main agent context window. If a milestone requires more than ~4 agents across 2-3 waves, split it. This is non-negotiable — large milestones cause context overflow and execution failures. When interviewing about milestones, actively recommend splitting any milestone that looks too large.
120
+
121
+ **Milestone Dependencies (dependsOn):**
122
+
123
+ During the milestones phase of the interview, ask about milestone dependencies using AskUserQuestion. For each milestone after the first, ask:
124
+
125
+ - question: "Does Milestone {N} depend on any previous milestones?"
126
+ - options:
127
+ - "No dependencies can start immediately"
128
+ - "Depends on Milestone {N-1} (sequential)"
129
+ - "Depends on specific milestones (I'll specify)"
130
+
131
+ If milestones have explicit dependencies, include `**dependsOn:** 1, 2` in the milestone section of the PRD. If no dependencies are specified, omit the field (backward compatible — treated as sequential).
132
+
133
+ Independent milestones enable parallel execution via `/forge:go`, which creates separate worktrees for each parallel milestone.
134
+
135
+ **Question Format:**
136
+
137
+ Mix AskUserQuestion (for structured choices) and conversational questions (for open-ended probing):
138
+
139
+ - **Use AskUserQuestion** when there are clear option sets (architecture choices, yes/no with detail, picking from scan-derived options). Provide 2-4 options plus "Other (I'll describe)".
140
+ - **Use conversational questions** when probing for depth, asking "how" or "what" questions, or exploring topics that don't have predefined options.
141
+ - **NEVER present questions as numbered text lists.** Each structured question gets its own AskUserQuestion call.
142
+ - **Lead with recommendations.** Every question includes context from the codebase scan. Never ask a blank "what do you want to build?" question.
143
+
144
+ **Progress Display:**
145
+
146
+ After each answer, show a compact coverage status:
147
+
148
+ ```
149
+ Progress: Problem & Goals [thorough] | User Stories [moderate] | Technical [thin] | Scope [none] | Milestones [none]
150
+ ```
151
+
152
+ **Draft Updates:**
153
+
154
+ - **Update the PRD draft every 2-3 answers.** Write to `.planning/prds/{project-slug}.md`. Tell the user:
155
+
156
+ > Updated PRD draft at `.planning/prds/{slug}.md` you can review it anytime.
157
+
158
+ **Do NOT do this (anti-pattern):**
159
+
160
+ ```
161
+ ### Round N
162
+
163
+ 1. **[Section]** Question text?
164
+ 2. **[Section]** Question text?
165
+
166
+ > Answer by number...
167
+ ```
168
+
169
+ This numbered-text format is explicitly prohibited. Always use AskUserQuestion for structured choices.
170
+
171
+ ### Step 4 Generate PRD
172
+
173
+ Using all gathered interview answers and codebase scan results, generate the final PRD directly. The LLM synthesizes all interview data into the PRD no external generator module needed.
174
+
175
+ The PRD should follow this structure:
176
+
177
+ ```markdown
178
+ # PRD: {Project Name}
179
+
180
+ ## Problem & Goals
181
+ {Synthesized from interview answers}
182
+
183
+ ## User Stories
184
+ {Structured user stories derived from interview}
185
+
186
+ ## Technical Approach
187
+ {Stack decisions, architecture, constraints — informed by codebase scan}
188
+
189
+ ## Scope
190
+ ### In Scope
191
+ {What will be built}
192
+
193
+ ### Out of Scope
194
+ {Explicitly excluded items}
195
+
196
+ ### Sacred Files
197
+ {Files/areas not to be touched}
198
+
199
+ ## Milestones
200
+
201
+ ### Milestone 1: {Name}
202
+ **Goal:** {What this delivers}
203
+ **Issues:**
204
+ - [ ] Issue title — brief description
205
+ - [ ] Issue title — brief description
206
+
207
+ ### Milestone 2: {Name}
208
+ **dependsOn:** 1
209
+ **Goal:** {What this delivers}
210
+ ...
211
+ ```
212
+
213
+ **Milestone sizing check:** Before finalizing, review each milestone against the sizing constraint. Every milestone MUST fit in one agent context window (~4 agents across 2-3 waves max). If any milestone exceeds this, split it into smaller milestones before writing the final PRD. Set `maxContextWindowFit: true` on all milestones — if you cannot make a milestone fit, flag it as `maxContextWindowFit: false` and warn the user.
214
+
215
+ **Test criteria guidance:** Test criteria are optional. Only include them when the milestone produces testable behavior. Verification commands (`npx tsc --noEmit`, `npx forge verify`) are always included automatically test criteria are for additional functional checks beyond mechanical gates. When including test criteria, make them **functional**, not structural:
216
+ - Good: "CLI `npx forge verify` runs and exits 0", "tsc compiles with no errors", "the new gate produces structured JSON output"
217
+ - Bad: "All new source files must have corresponding test files", "Run npx forge verify --gate tests"
218
+
219
+ Write the final PRD to `.planning/prds/{project-slug}.md`.
220
+
221
+ After writing the PRD file, **execute BOTH steps below — do not skip either**:
222
+
223
+ 1. **Create status file:** Write `.planning/status/<slug>.json` with all milestones set to "pending". **You MUST include `linearProjectId` and `linearTeamId`** these are the Linear project UUID and team UUID from the project selected in Step 1. Without `linearProjectId`, `/forge:go` cannot sync Linear issue or project state and will silently skip all Linear operations. Without `linearTeamId`, `forge linear-sync` silently skips all operations. Copy the exact IDs — do not omit these fields:
224
+ ```json
225
+ {
226
+ "project": "{project name}",
227
+ "slug": "{slug}",
228
+ "branch": "feat/{slug}",
229
+ "createdAt": "{today}",
230
+ "linearProjectId": "{Linear project UUID from Step 1}",
231
+ "linearTeamId": "{team UUID — resolved in Step 5, but placeholder here}",
232
+ "milestones": {
233
+ "1": { "status": "pending" },
234
+ "2": { "status": "pending" }
235
+ }
236
+ }
237
+ ```
238
+
239
+ 2. **Create feature branch:** `git checkout -b feat/{slug}`
240
+
241
+ Tell the user:
242
+
243
+ > Final PRD written to `.planning/prds/{slug}.md`.
244
+ > Status file created at `.planning/status/{slug}.json`.
245
+ > Feature branch `feat/{slug}` created.
246
+
247
+ Present the full PRD in chat for review and ask:
248
+
249
+ > Review the PRD above. You can:
250
+ > - **Approve** — I'll create milestones and issues in Linear
251
+ > - **Edit** tell me what to change (e.g., "add a milestone for testing" or "remove the admin user story")
252
+ > - **Regenerate** — start the interview over
253
+ >
254
+ > What would you like to do?
255
+
256
+ Wait for approval before continuing to Step 5.
257
+
258
+ ### Step 5 Sync to Linear
259
+
260
+ After the user approves the PRD, create milestones and issues in Linear.
261
+
262
+ First, get the team ID:
263
+
264
+ ```
265
+ Use mcp__linear__list_teams to get available teams.
266
+ ```
267
+
268
+ If there is only one team, use it automatically. If multiple, ask the user which team.
269
+
270
+ **Store the team ID** it will be written to the status file after sync.
271
+
272
+ For each milestone in the PRD:
273
+
274
+ ```
275
+ Use mcp__linear__create_milestone with:
276
+ - projectId: the selected project's ID
277
+ - name: milestone name
278
+ - description: milestone goal
279
+ ```
280
+
281
+ **Record the returned milestone ID** for each milestone.
282
+
283
+ For each issue under that milestone:
284
+
285
+ ```
286
+ Use mcp__linear__create_issue with:
287
+ - title: issue title
288
+ - description: issue description (from PRD)
289
+ - teamId: the team ID
290
+ - projectId: the project ID
291
+ - milestoneId: the milestone ID just created
292
+ ```
293
+
294
+ **Record the returned issue IDs** for each milestone.
295
+
296
+ **After all milestones and issues are created, do THREE things:**
297
+
298
+ 1. **Transition the project to "Planned":**
299
+
300
+ ```
301
+ Use mcp__linear__update_project to set the project state to "planned".
302
+ ```
303
+
304
+ **The project is a separate entity from its milestones and issues.** Creating milestones and issues does NOT automatically update the project state. You must explicitly call `mcp__linear__update_project`. Without this transition, `/forge:go` will find the project still in "Backlog" and the state machine will reject the "In Progress" transition.
305
+
306
+ 2. **Update the status file** at `.planning/status/<slug>.json` with the Linear IDs:
307
+
308
+ ```json
309
+ {
310
+ "project": "{project name}",
311
+ "slug": "{slug}",
312
+ "branch": "feat/{slug}",
313
+ "createdAt": "{today}",
314
+ "linearProjectId": "{Linear project UUID from Step 1}",
315
+ "linearTeamId": "{team UUID from this step}",
316
+ "milestones": {
317
+ "1": { "status": "pending", "linearMilestoneId": "{id}", "linearIssueIds": ["{id1}", "{id2}"] },
318
+ "2": { "status": "pending", "linearMilestoneId": "{id}", "linearIssueIds": ["{id1}", "{id2}"] }
319
+ }
320
+ }
321
+ ```
322
+
323
+ **`linearTeamId` is MANDATORY.** Without it, `forge linear-sync` silently skips all operations. **`linearMilestoneId` and `linearIssueIds` per milestone are MANDATORY.** These enable `/forge:go` to transition issues as milestones are completed.
324
+
325
+ 3. **Print a summary:**
326
+
327
+ ```
328
+ ## Synced to Linear
329
+
330
+ - **Project:** {name} (now "Planned")
331
+ - **Milestones:** {N} created
332
+ - **Issues:** {M} created across all milestones
333
+
334
+ View in Linear: {project URL}
335
+ ```
336
+
337
+ If any creation fails, report the error and continue with remaining items.
338
+
339
+ ### Step 6 Handoff
340
+
341
+ After sync, print the handoff prompt:
342
+
343
+ ```
344
+ ## Ready for Development
345
+
346
+ PRD: `.planning/prds/{slug}.md`
347
+ Status: `.planning/status/{slug}.json`
348
+ Branch: `feat/{slug}`
349
+ Linear: {project URL}
350
+
351
+ **Next step:** Run `/forge:go` for one milestone at a time, or exit and run `npx forge run` to execute all milestones autonomously. The execution engine will:
352
+ - Read the PRD and per-PRD status file
353
+ - Spawn agent teams for each milestone
354
+ - Verify each change with forge verification gates
355
+ - Update status JSON and transition Linear issues automatically
356
+ ```
357
+
358
+ **Note:** `/forge:go` now uses git worktrees for session isolation. Multiple users can run `/forge:go` on different milestones simultaneously without conflicts.
359
+
360
+ ## Edge Cases
361
+
362
+ - **No Linear connection:** Warn the user. Still generate the PRD locally — skip the Linear sync steps.
363
+ - **Empty codebase:** The interview still works — questions will be more open-ended without scan context. Note this to the user.
364
+ - **User wants to spec a project not in Linear:** Allow it. Skip Step 1 project selection, ask for a project name, and create the Linear project in Step 5 before creating milestones.
365
+ - **User provides info upfront:** If the user includes project details in the same message as `/forge:spec`, use that info to pre-fill interview answers and skip questions that are already answered.
366
+ - **Very large codebase:** Scan agents may return truncated results. That's fine — the interview fills in gaps.
367
+ - **Interrupted interview:** If the user stops mid-interview, save what you have to the PRD draft. They can resume by running `/forge:spec` again and selecting the same project.