forge-cc 0.1.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 (105) hide show
  1. package/.forge.json +5 -0
  2. package/AGENTS.md +42 -0
  3. package/README.md +283 -0
  4. package/dist/cli.d.ts +2 -0
  5. package/dist/cli.js +148 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/config/loader.d.ts +2 -0
  8. package/dist/config/loader.js +44 -0
  9. package/dist/config/loader.js.map +1 -0
  10. package/dist/config/schema.d.ts +57 -0
  11. package/dist/config/schema.js +15 -0
  12. package/dist/config/schema.js.map +1 -0
  13. package/dist/gates/index.d.ts +11 -0
  14. package/dist/gates/index.js +106 -0
  15. package/dist/gates/index.js.map +1 -0
  16. package/dist/gates/lint-gate.d.ts +2 -0
  17. package/dist/gates/lint-gate.js +66 -0
  18. package/dist/gates/lint-gate.js.map +1 -0
  19. package/dist/gates/prd-gate.d.ts +7 -0
  20. package/dist/gates/prd-gate.js +193 -0
  21. package/dist/gates/prd-gate.js.map +1 -0
  22. package/dist/gates/runtime-gate.d.ts +5 -0
  23. package/dist/gates/runtime-gate.js +99 -0
  24. package/dist/gates/runtime-gate.js.map +1 -0
  25. package/dist/gates/tests-gate.d.ts +2 -0
  26. package/dist/gates/tests-gate.js +116 -0
  27. package/dist/gates/tests-gate.js.map +1 -0
  28. package/dist/gates/types-gate.d.ts +2 -0
  29. package/dist/gates/types-gate.js +59 -0
  30. package/dist/gates/types-gate.js.map +1 -0
  31. package/dist/gates/visual-gate.d.ts +6 -0
  32. package/dist/gates/visual-gate.js +118 -0
  33. package/dist/gates/visual-gate.js.map +1 -0
  34. package/dist/go/auto-chain.d.ts +107 -0
  35. package/dist/go/auto-chain.js +303 -0
  36. package/dist/go/auto-chain.js.map +1 -0
  37. package/dist/go/executor.d.ts +130 -0
  38. package/dist/go/executor.js +409 -0
  39. package/dist/go/executor.js.map +1 -0
  40. package/dist/go/finalize.d.ts +58 -0
  41. package/dist/go/finalize.js +200 -0
  42. package/dist/go/finalize.js.map +1 -0
  43. package/dist/go/linear-sync.d.ts +75 -0
  44. package/dist/go/linear-sync.js +239 -0
  45. package/dist/go/linear-sync.js.map +1 -0
  46. package/dist/go/verify-loop.d.ts +47 -0
  47. package/dist/go/verify-loop.js +172 -0
  48. package/dist/go/verify-loop.js.map +1 -0
  49. package/dist/hooks/pre-commit.d.ts +5 -0
  50. package/dist/hooks/pre-commit.js +69 -0
  51. package/dist/hooks/pre-commit.js.map +1 -0
  52. package/dist/linear/client.d.ts +108 -0
  53. package/dist/linear/client.js +388 -0
  54. package/dist/linear/client.js.map +1 -0
  55. package/dist/linear/issues.d.ts +20 -0
  56. package/dist/linear/issues.js +39 -0
  57. package/dist/linear/issues.js.map +1 -0
  58. package/dist/linear/milestones.d.ts +11 -0
  59. package/dist/linear/milestones.js +32 -0
  60. package/dist/linear/milestones.js.map +1 -0
  61. package/dist/linear/projects.d.ts +16 -0
  62. package/dist/linear/projects.js +50 -0
  63. package/dist/linear/projects.js.map +1 -0
  64. package/dist/reporter/human.d.ts +2 -0
  65. package/dist/reporter/human.js +63 -0
  66. package/dist/reporter/human.js.map +1 -0
  67. package/dist/reporter/json.d.ts +2 -0
  68. package/dist/reporter/json.js +4 -0
  69. package/dist/reporter/json.js.map +1 -0
  70. package/dist/server.d.ts +2 -0
  71. package/dist/server.js +109 -0
  72. package/dist/server.js.map +1 -0
  73. package/dist/spec/generator.d.ts +14 -0
  74. package/dist/spec/generator.js +206 -0
  75. package/dist/spec/generator.js.map +1 -0
  76. package/dist/spec/interview.d.ts +104 -0
  77. package/dist/spec/interview.js +342 -0
  78. package/dist/spec/interview.js.map +1 -0
  79. package/dist/spec/linear-sync.d.ts +48 -0
  80. package/dist/spec/linear-sync.js +125 -0
  81. package/dist/spec/linear-sync.js.map +1 -0
  82. package/dist/spec/scanner.d.ts +45 -0
  83. package/dist/spec/scanner.js +473 -0
  84. package/dist/spec/scanner.js.map +1 -0
  85. package/dist/spec/templates.d.ts +345 -0
  86. package/dist/spec/templates.js +86 -0
  87. package/dist/spec/templates.js.map +1 -0
  88. package/dist/state/reader.d.ts +29 -0
  89. package/dist/state/reader.js +116 -0
  90. package/dist/state/reader.js.map +1 -0
  91. package/dist/state/writer.d.ts +60 -0
  92. package/dist/state/writer.js +222 -0
  93. package/dist/state/writer.js.map +1 -0
  94. package/dist/types.d.ts +64 -0
  95. package/dist/types.js +2 -0
  96. package/dist/types.js.map +1 -0
  97. package/dist/utils/browser.d.ts +10 -0
  98. package/dist/utils/browser.js +89 -0
  99. package/dist/utils/browser.js.map +1 -0
  100. package/hooks/pre-commit-verify.js +103 -0
  101. package/package.json +68 -0
  102. package/skills/README.md +33 -0
  103. package/skills/forge-go.md +332 -0
  104. package/skills/forge-spec.md +251 -0
  105. package/skills/forge-triage.md +133 -0
@@ -0,0 +1,332 @@
1
+ # /forge:go — Execute Milestones with Wave-Based Agent Teams
2
+
3
+ Execute the next milestone from your PRD with wave-based agent teams, self-healing verification, and automatic state management. Run one milestone at a time (default) or chain all remaining milestones with `--auto`.
4
+
5
+ ## Instructions
6
+
7
+ Follow these steps exactly. The execution engine at `src/go/executor.ts` provides the programmatic logic — this skill drives the agent orchestration.
8
+
9
+ ### Step 1 — Orient
10
+
11
+ Read project state files to determine current position:
12
+
13
+ ```
14
+ Read these files in parallel:
15
+ - CLAUDE.md
16
+ - .planning/STATE.md
17
+ - .planning/ROADMAP.md
18
+ ```
19
+
20
+ From STATE.md, extract:
21
+ - **Current milestone number** (from `**Milestone:**` field)
22
+ - **Branch** (from `**Branch:**` field)
23
+ - **Active PRD path** (from `**Active PRD:**` field)
24
+
25
+ From ROADMAP.md, find the next milestone with status "Pending". If STATE.md says the current milestone is complete, advance to the next pending one.
26
+
27
+ If no active PRD exists:
28
+
29
+ > No active PRD found. Run `/forge:spec` first to create a PRD with milestones.
30
+
31
+ If all milestones are complete:
32
+
33
+ > All milestones complete! Create a PR with `gh pr create` or run `/forge:spec` to start a new project.
34
+
35
+ ### Step 2 — Pre-flight Checks
36
+
37
+ Verify the execution environment is ready:
38
+
39
+ 1. **Branch check:** Confirm you are on the correct feature branch (from STATE.md). If on `main`/`master`, warn and abort:
40
+
41
+ > You're on the main branch. Switch to your feature branch first: `git checkout {branch}`
42
+
43
+ 2. **Milestone exists:** Read ONLY the current milestone section from the PRD (progressive disclosure — NOT the full PRD). Use the executor's `readCurrentMilestone()` approach — match `### Milestone N:` header and extract until the next milestone header.
44
+
45
+ 3. **Not already complete:** Check ROADMAP.md to confirm this milestone is not already marked complete. If it is, advance to the next pending milestone.
46
+
47
+ 4. **Clean state:** Run `git status` to check for uncommitted changes. If dirty, warn:
48
+
49
+ > You have uncommitted changes. Commit or stash them before running /forge:go.
50
+
51
+ Print the pre-flight summary:
52
+
53
+ ```
54
+ ## Pre-flight Check
55
+
56
+ - Branch: feat/forge-build (OK)
57
+ - Milestone: 4 — Execution Engine (go) (Pending)
58
+ - PRD: .planning/prds/forge-build.md (found)
59
+ - Working tree: clean
60
+
61
+ Ready to execute Milestone 4.
62
+ ```
63
+
64
+ ### Step 3 — Execute Waves
65
+
66
+ Parse the milestone section from the PRD. Each milestone contains waves with agent definitions:
67
+
68
+ ```
69
+ **Wave N (M agents parallel):**
70
+ 1. **agent-name**: task description
71
+ - Creates: file1, file2
72
+ - Modifies: file3
73
+ ```
74
+
75
+ For each wave, in order:
76
+
77
+ #### 3a. Build Agent Prompts
78
+
79
+ For each agent in the wave, construct a prompt that includes:
80
+
81
+ 1. **Agent identity:** "You are **{agent-name}** working on Milestone {N}: {name}."
82
+ 2. **Milestone goal:** The `**Goal:**` line from the milestone section.
83
+ 3. **Agent task:** The specific task description from the wave definition.
84
+ 4. **Files to create/modify:** The explicit file list from the agent's definition.
85
+ 5. **Existing code context:** Read the actual contents of files the agent depends on (imports, types, utilities). **Inline the actual code** — never reference files by path alone. This is critical for agents that run in isolated contexts.
86
+ 6. **Lessons:** Read `tasks/lessons.md` and include all active lessons.
87
+ 7. **Rules:**
88
+ - Use ES module imports with `.js` extension in import paths
89
+ - Stage only your files (never `git add .` or `git add -A`)
90
+ - Run `npx tsc --noEmit` after creating files to verify compilation
91
+ - Do NOT commit — the orchestrator handles commits
92
+
93
+ #### 3b. Spawn Agents in Parallel
94
+
95
+ Use the Task tool to spawn all agents in the current wave simultaneously:
96
+
97
+ ```
98
+ For each agent in the wave, use the Task tool with:
99
+ - The constructed prompt as the task description
100
+ - subagent_type appropriate for the work (typically a full-capability agent)
101
+ ```
102
+
103
+ Wait for ALL agents in the wave to complete before moving to the next step.
104
+
105
+ #### 3c. Restage Files at Wave Boundary
106
+
107
+ **IMPORTANT:** Parallel agents can disrupt each other's git index. After all agents in a wave complete, restage all files:
108
+
109
+ ```bash
110
+ git add {all files from this wave's agents}
111
+ ```
112
+
113
+ This is a learned lesson — always restage at wave boundaries.
114
+
115
+ #### 3d. Run Verification
116
+
117
+ After each wave completes, run forge verification:
118
+
119
+ ```bash
120
+ npx tsc --noEmit
121
+ ```
122
+
123
+ If the project has additional verification configured (tests, lint), also run:
124
+
125
+ ```bash
126
+ npx forge verify
127
+ ```
128
+
129
+ If verification **passes**: print a wave completion summary and proceed to the next wave.
130
+
131
+ ```
132
+ ## Wave {N} Complete
133
+
134
+ - agent-1: OK (created file1.ts, file2.ts)
135
+ - agent-2: OK (modified file3.ts)
136
+ - Verification: PASSED
137
+
138
+ Proceeding to Wave {N+1}...
139
+ ```
140
+
141
+ If verification **fails**: proceed to Step 4 (self-healing loop).
142
+
143
+ ### Step 4 — Self-Healing Verify Loop
144
+
145
+ When verification fails after a wave:
146
+
147
+ 1. Parse the verification errors into structured feedback. Include:
148
+ - Gate name (types, lint, tests)
149
+ - Error messages with file paths and line numbers
150
+ - Remediation hints if available
151
+
152
+ 2. Spawn a **fix agent** with a prompt that includes:
153
+ - The specific errors to fix
154
+ - The files that need modification
155
+ - The original task context
156
+ - "Fix ONLY the errors listed. Do not refactor or add features."
157
+
158
+ 3. After the fix agent completes, restage files and re-run verification.
159
+
160
+ 4. Repeat up to `maxIterations` (default: 5, configurable via `.forge.json`).
161
+
162
+ 5. If max iterations reached without passing:
163
+
164
+ ```
165
+ ## Verification Failed After {N} Iterations
166
+
167
+ ### Remaining Errors:
168
+ - types: src/go/executor.ts:42 — Type 'string' is not assignable to type 'number'
169
+ - lint: src/go/executor.ts:55 — Unused variable 'foo'
170
+
171
+ The self-healing loop could not resolve all errors.
172
+ Please fix the remaining issues manually, then run `/forge:go` again.
173
+ ```
174
+
175
+ **Stop execution.** Do not proceed to the next wave or milestone.
176
+
177
+ ### Step 5 — Commit
178
+
179
+ After ALL waves pass verification:
180
+
181
+ 1. Stage all files created/modified across all waves:
182
+
183
+ ```bash
184
+ git add {all files from all waves}
185
+ ```
186
+
187
+ 2. Commit with a structured message:
188
+
189
+ ```bash
190
+ git commit -m "feat: {Milestone Name} (Milestone {N})"
191
+ ```
192
+
193
+ 3. Push to the remote branch:
194
+
195
+ ```bash
196
+ git push origin {branch}
197
+ ```
198
+
199
+ ### Step 6 — Update State
200
+
201
+ Update project state files:
202
+
203
+ 1. **STATE.md:** Update the milestone progress table — mark the completed milestone's status as `Complete ({date})`. If there is a next milestone, update the `**Milestone:**` line to point to it. Update `**Last Session:**` to today's date.
204
+
205
+ 2. **ROADMAP.md:** Update the milestone table row to `Complete ({date})`.
206
+
207
+ 3. **Session memory:** Write session state for the current branch using the writer module's pattern.
208
+
209
+ 4. Commit the state updates:
210
+
211
+ ```bash
212
+ git add .planning/STATE.md .planning/ROADMAP.md
213
+ git commit -m "docs: mark Milestone {N} complete, update session state"
214
+ git push origin {branch}
215
+ ```
216
+
217
+ ### Step 7 — Linear Sync (If Configured)
218
+
219
+ If the project has a `linearProject` configured in `.forge.json` or the PRD:
220
+
221
+ 1. Transition issues for the completed milestone to appropriate state:
222
+ - If this was the **last milestone**: move issues to "In Review"
223
+ - Otherwise: keep issues as-is (they were set to "In Progress" at start)
224
+
225
+ 2. If this is the **last milestone**, also:
226
+ - Transition the project to "In Review"
227
+ - Create a PR (see Step 8)
228
+
229
+ If Linear is not configured, skip this step silently.
230
+
231
+ ### Step 8 — Route Next
232
+
233
+ After milestone completion, determine the next action:
234
+
235
+ #### If this is NOT the last milestone:
236
+
237
+ ```
238
+ ## Milestone {N} Complete
239
+
240
+ **{Milestone Name}** completed successfully.
241
+
242
+ - Files created: {count}
243
+ - Files modified: {count}
244
+ - Verification: PASSED
245
+ - Branch: {branch} (pushed)
246
+
247
+ **Next:** Run `/clear` to reset context, then `/forge:go` for Milestone {N+1}: {Next Milestone Name}.
248
+ ```
249
+
250
+ #### If this IS the last milestone:
251
+
252
+ Create a pull request:
253
+
254
+ ```bash
255
+ gh pr create --title "feat: {Project Name}" --body "$(cat <<'EOF'
256
+ ## Summary
257
+ {Brief description from PRD overview}
258
+
259
+ ## Milestones Completed
260
+ - [x] Milestone 1: {name}
261
+ - [x] Milestone 2: {name}
262
+ ...
263
+
264
+ ## Verification
265
+ All milestones passed forge verification (types, lint, tests).
266
+
267
+ ---
268
+ Generated by forge-cc
269
+ EOF
270
+ )"
271
+ ```
272
+
273
+ Then print:
274
+
275
+ ```
276
+ ## All Milestones Complete!
277
+
278
+ **PR created:** {PR URL}
279
+
280
+ - {N} milestones completed
281
+ - {total files} files created/modified
282
+ - All verification gates passed
283
+
284
+ The PR is ready for review.
285
+ ```
286
+
287
+ ### Auto Mode (`--auto`)
288
+
289
+ When invoked with `--auto` (e.g., `/forge:go --auto`), chain all remaining milestones with context resets between each.
290
+
291
+ After each milestone completes (Step 5-7):
292
+
293
+ 1. Print the completion summary for the milestone.
294
+ 2. Print instructions for the context reset:
295
+
296
+ ```
297
+ ## Context Reset for Milestone {N+1}
298
+
299
+ Milestone {N} is complete and committed. Starting fresh context for the next milestone.
300
+
301
+ To continue autonomously, start a new session and run:
302
+ > /forge:go --auto
303
+
304
+ The new session will read STATE.md (just updated) and pick up at Milestone {N+1}.
305
+ ```
306
+
307
+ **IMPORTANT:** Auto mode does NOT continue in the same context window. Each milestone gets a fresh context (the Ralph Loop pattern). The `--auto` flag simply means "after completing this milestone, print the instructions for continuing" rather than "execute everything in one session."
308
+
309
+ This prevents context rot — each milestone starts with clean context reading CLAUDE.md + STATE.md + current milestone section only (~20% of context window).
310
+
311
+ ### Step 9 — Linear Issue Start (On Milestone Begin)
312
+
313
+ At the START of milestone execution (between Step 2 and Step 3), if Linear is configured:
314
+
315
+ 1. Find issues associated with this milestone in Linear.
316
+ 2. Transition them to "In Progress".
317
+ 3. Transition the project to "In Progress" (if not already).
318
+ 4. Add a brief comment: "Starting execution via forge:go."
319
+
320
+ If Linear is not configured, skip silently.
321
+
322
+ ## Edge Cases
323
+
324
+ - **No PRD:** Abort with message to run `/forge:spec` first.
325
+ - **No waves in milestone:** The milestone section may not have structured wave definitions (e.g., it was written by hand without the spec engine). In this case, treat the entire milestone as a single wave with one agent whose task is the milestone's goal.
326
+ - **Agent failure:** If an agent in a wave fails (exits with error, times out), record the failure, include the error in the wave result, and proceed to verification. The self-healing loop may fix the issue.
327
+ - **Branch diverged:** If `git push` fails due to divergence, attempt `git pull --rebase` first. If that fails, stop and ask the user.
328
+ - **Interrupted execution:** If execution is interrupted mid-wave, the state files are NOT updated. Running `/forge:go` again will retry the same milestone from the beginning. Completed agents' work will be in the working tree — the new run's verification will detect what's already working.
329
+ - **Empty milestone section:** If the PRD has a milestone header but no content, abort with:
330
+ > Milestone {N} has no wave definitions. Update the PRD with agent assignments before running /forge:go.
331
+ - **Already on correct milestone:** If STATE.md's current milestone matches the target, proceed normally (this is the expected case).
332
+ - **Linear auth fails:** Warn but continue execution. Linear sync is not blocking.
@@ -0,0 +1,251 @@
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 — Adaptive Interview
77
+
78
+ Conduct an adaptive interview using the interview engine logic from `src/spec/interview.ts`. The interview covers 5 sections in priority order:
79
+
80
+ 1. **Problem & Goals** — what problem, desired outcome, success criteria
81
+ 2. **User Stories** — primary users, workflows, secondary users
82
+ 3. **Technical Approach** — architecture decisions, constraints, stack
83
+ 4. **Scope** — what's out, sacred files, boundaries
84
+ 5. **Milestones** — phasing, dependencies, delivery chunks
85
+
86
+ **Interview Rules:**
87
+
88
+ - **Lead with recommendations.** Every question includes context from the codebase scan. Never ask a blank "what do you want to build?" question.
89
+ - **Ask 1-3 questions per round.** Present them as a numbered list. The user can answer all at once or pick which to answer.
90
+ - **Follow interesting threads.** If the user mentions migration, breaking changes, multiple user types, or external integrations, follow up with targeted questions.
91
+ - **Show progress.** After each answer round, show a compact status:
92
+
93
+ ```
94
+ Progress: [##---] Problem & Goals (2/2) | User Stories (0/2) | Technical (0/1) | Scope (0/1) | Milestones (0/1)
95
+ ```
96
+
97
+ - **Update the PRD draft every 2-3 answers.** Write the current draft to `.planning/prds/{project-slug}.md`. Tell the user:
98
+
99
+ > Updated PRD draft at `.planning/prds/{slug}.md` — you can review it anytime.
100
+
101
+ - **Stop when complete.** When all sections have enough info (Problem 2+, Users 2+, Technical 1+, Scope 1+, Milestones 1+), move to Step 4. Don't drag the interview out.
102
+ - **Allow early exit.** If the user says "that's enough", "skip", or "generate it", respect that and move to Step 4 with what you have.
103
+
104
+ **Question Format:**
105
+
106
+ ```
107
+ ### Round N
108
+
109
+ Based on your codebase scan, I have some questions:
110
+
111
+ 1. **[Section]** Context from scan or previous answers.
112
+ Question text here?
113
+
114
+ 2. **[Section]** Context observation.
115
+ Question text here?
116
+
117
+ > Answer by number (e.g., "1. My answer to first question. 2. Second answer") or answer all at once.
118
+ ```
119
+
120
+ ### Step 4 — Generate PRD
121
+
122
+ Using all gathered interview answers and codebase scan results, generate the final PRD. Use the generator module at `src/spec/generator.ts`:
123
+
124
+ The PRD should follow this structure:
125
+
126
+ ```markdown
127
+ # PRD: {Project Name}
128
+
129
+ ## Problem & Goals
130
+ {Synthesized from interview answers}
131
+
132
+ ## User Stories
133
+ {Structured user stories derived from interview}
134
+
135
+ ## Technical Approach
136
+ {Stack decisions, architecture, constraints — informed by codebase scan}
137
+
138
+ ## Scope
139
+ ### In Scope
140
+ {What will be built}
141
+
142
+ ### Out of Scope
143
+ {Explicitly excluded items}
144
+
145
+ ### Sacred Files
146
+ {Files/areas not to be touched}
147
+
148
+ ## Milestones
149
+
150
+ ### Milestone 1: {Name}
151
+ **Goal:** {What this delivers}
152
+ **Issues:**
153
+ - [ ] Issue title — brief description
154
+ - [ ] Issue title — brief description
155
+
156
+ ### Milestone 2: {Name}
157
+ ...
158
+ ```
159
+
160
+ Write the final PRD to `.planning/prds/{project-slug}.md`. Tell the user:
161
+
162
+ > Final PRD written to `.planning/prds/{slug}.md`.
163
+
164
+ Present the full PRD in chat for review and ask:
165
+
166
+ > Review the PRD above. You can:
167
+ > - **Approve** — I'll create milestones and issues in Linear
168
+ > - **Edit** — tell me what to change (e.g., "add a milestone for testing" or "remove the admin user story")
169
+ > - **Regenerate** — start the interview over
170
+ >
171
+ > What would you like to do?
172
+
173
+ Wait for approval before continuing to Step 5.
174
+
175
+ ### Step 5 — Sync to Linear
176
+
177
+ After the user approves the PRD, create milestones and issues in Linear.
178
+
179
+ First, get the team ID:
180
+
181
+ ```
182
+ Use mcp__linear__list_teams to get available teams.
183
+ ```
184
+
185
+ If there is only one team, use it automatically. If multiple, ask the user which team.
186
+
187
+ For each milestone in the PRD:
188
+
189
+ ```
190
+ Use mcp__linear__create_milestone with:
191
+ - projectId: the selected project's ID
192
+ - name: milestone name
193
+ - description: milestone goal
194
+ ```
195
+
196
+ For each issue under that milestone:
197
+
198
+ ```
199
+ Use mcp__linear__create_issue with:
200
+ - title: issue title
201
+ - description: issue description (from PRD)
202
+ - teamId: the team ID
203
+ - projectId: the project ID
204
+ - milestoneId: the milestone ID just created
205
+ ```
206
+
207
+ After all milestones and issues are created, transition the project to "Planned":
208
+
209
+ ```
210
+ Use mcp__linear__update_project to set the project state to "planned".
211
+ ```
212
+
213
+ Print a summary:
214
+
215
+ ```
216
+ ## Synced to Linear
217
+
218
+ - **Project:** {name} (now "Planned")
219
+ - **Milestones:** {N} created
220
+ - **Issues:** {M} created across all milestones
221
+
222
+ View in Linear: {project URL}
223
+ ```
224
+
225
+ If any creation fails, report the error and continue with remaining items.
226
+
227
+ ### Step 6 — Handoff
228
+
229
+ After sync, print the handoff prompt:
230
+
231
+ ```
232
+ ## Ready for Development
233
+
234
+ PRD: `.planning/prds/{slug}.md`
235
+ Linear: {project URL}
236
+
237
+ **Next step:** Run `/forge:go` to start executing Milestone 1. The execution engine will:
238
+ - Read the PRD and milestone plan
239
+ - Spawn agent teams for each issue
240
+ - Verify each change with forge-mcp gates
241
+ - Open PRs and transition issues automatically
242
+ ```
243
+
244
+ ## Edge Cases
245
+
246
+ - **No Linear connection:** Warn the user. Still generate the PRD locally — skip the Linear sync steps.
247
+ - **Empty codebase:** The interview still works — questions will be more open-ended without scan context. Note this to the user.
248
+ - **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.
249
+ - **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.
250
+ - **Very large codebase:** Scan agents may return truncated results. That's fine — the interview fills in gaps.
251
+ - **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.