@zeyue0329/xiaoma-cli 1.12.0 → 1.13.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 (56) hide show
  1. package/.playwright-cli/console-2026-05-13T06-36-26-793Z.log +2 -0
  2. package/.playwright-cli/page-2026-05-13T06-36-27-725Z.yml +1 -0
  3. package/CLAUDE.md +1 -0
  4. package/XiaoMa-CLI-2026H2-/350/277/255/344/273/243/350/247/204/345/210/222.pptx +0 -0
  5. package/demo/xiaoma-bug-circle-resolve/SKILL.md +1 -1
  6. package/demo/xiaoma-bug-circle-resolve/workflow.md +72 -30
  7. package/demo/xiaoma-prd-saas-zh/README.md +57 -0
  8. package/demo/xiaoma-prd-saas-zh/domain-research.md +128 -0
  9. package/demo/xiaoma-prd-saas-zh/epics.md +303 -0
  10. package/demo/xiaoma-prd-saas-zh/market-research-2026-q1.md +183 -0
  11. package/demo/xiaoma-prd-saas-zh/prd-bad-examples.md +268 -0
  12. package/demo/xiaoma-prd-saas-zh/prd.md +409 -0
  13. package/demo/xiaoma-prd-saas-zh/product-brief.md +97 -0
  14. package/demo/xiaoma-prd-saas-zh/validation-report.md +279 -0
  15. package/media/doc1_fig1.png +0 -0
  16. package/media/doc1_fig2.png +0 -0
  17. package/media/doc1_fig3.png +0 -0
  18. package/media/doc1_fig4.png +0 -0
  19. package/media/doc2_fig1.png +0 -0
  20. package/media/doc2_fig2.png +0 -0
  21. package/media/doc2_fig3.png +0 -0
  22. package/media/doc2_fig4.png +0 -0
  23. package/media/doc3_fig1.png +0 -0
  24. package/media/doc3_fig2.png +0 -0
  25. package/media/doc3_fig3.png +0 -0
  26. package/media/doc3_fig4.png +0 -0
  27. package/media/doc4_fig1.png +0 -0
  28. package/media/doc4_fig2.png +0 -0
  29. package/media/doc4_fig3.png +0 -0
  30. package/media/doc5_fig1.png +0 -0
  31. package/media/doc5_fig2.png +0 -0
  32. package/media/doc5_fig3.png +0 -0
  33. package/package.json +1 -1
  34. package/patent-disclosure-optimized/SKILL.md +135 -17
  35. package/patent-disclosure-optimized/references/docx-format-spec.md +183 -0
  36. package/patent-disclosure-optimized/scripts/md2docx.js +777 -0
  37. package/src/core/tasks/xiaoma-create-prd/data/prd-purpose.md +157 -0
  38. package/src/core/tasks/xiaoma-create-prd/data/upstream-input-contract.md +168 -0
  39. package/src/core/tasks/xiaoma-create-prd/templates/prd-skeleton-reference.md +428 -0
  40. package/src/core/tasks/xiaoma-create-prd/templates/prd-template.md +101 -3
  41. package/src/xmc/agents/sm.agent.yaml +4 -0
  42. package/src/xmc/workflows/2-plan-workflows/xiaoma-validate-prd/data/prd-quality-rubric.csv +14 -0
  43. package/src/xmc/workflows/5-full-pipeline/auto-prd-to-stories/SKILL.md +6 -0
  44. package/src/xmc/workflows/5-full-pipeline/auto-prd-to-stories/checklist.md +43 -0
  45. package/src/xmc/workflows/5-full-pipeline/auto-prd-to-stories/steps/step-01-init-and-validate.md +155 -0
  46. package/src/xmc/workflows/5-full-pipeline/auto-prd-to-stories/steps/step-02-create-epics.md +156 -0
  47. package/src/xmc/workflows/5-full-pipeline/auto-prd-to-stories/steps/step-03-bridge-sprint-planning.md +143 -0
  48. package/src/xmc/workflows/5-full-pipeline/auto-prd-to-stories/steps/step-04-batch-create-stories.md +309 -0
  49. package/src/xmc/workflows/5-full-pipeline/auto-prd-to-stories/steps/step-05-finalize.md +311 -0
  50. package/src/xmc/workflows/5-full-pipeline/auto-prd-to-stories/workflow.md +105 -0
  51. package/src/xmc/workflows/5-full-pipeline/auto-prd-to-stories/xiaoma-skill-manifest.yaml +3 -0
  52. package//344/270/223/345/210/251/344/272/244/345/272/225/344/271/246_1_/351/235/242/345/220/221AI/346/231/272/350/203/275/344/275/223/347/232/204/345/244/232/351/200/232/351/201/223/344/276/235/350/265/226_20260318.md +483 -0
  53. package//344/270/223/345/210/251/344/272/244/345/272/225/344/271/246_2_/345/237/272/344/272/216/351/205/215/347/275/256/351/251/261/345/212/250/347/232/204/350/267/250/345/271/263/345/217/260IDE/346/231/272/350/203/275_20260318.md +592 -0
  54. package//344/270/223/345/210/251/344/272/244/345/272/225/344/271/246_3_AI/346/231/272/350/203/275/344/275/223/345/243/260/346/230/216/345/274/217/345/256/232/344/271/211/347/232/204/347/274/226/350/257/221/346/265/201/346/260/264_20260318.md +624 -0
  55. package//344/270/223/345/210/251/344/272/244/345/272/225/344/271/246_4_/345/237/272/344/272/216/345/223/210/345/270/214/346/214/207/347/272/271/347/232/204/346/231/272/350/203/275/344/275/223/351/231/204/345/261/236/350/265/204/346/272/220/351/200/211_20260318.md +628 -0
  56. package//344/270/223/345/210/251/344/272/244/345/272/225/344/271/246_5_AI/346/231/272/350/203/275/344/275/223/350/247/246/345/217/221/346/214/207/344/273/244/347/232/204/345/244/215/345/220/210/346/240/274/345/274/217/346/240/241_20260318.md +652 -0
@@ -0,0 +1,309 @@
1
+ ---
2
+ name: 'step-04-batch-create-stories'
3
+ description: 'Phase 3 — Batch create detailed story files: for each backlog story, launch an Agent subprocess running xiaoma-create-story (and ONLY that — no dev/review/test)'
4
+ nextStepFile: './step-05-finalize.md'
5
+ ---
6
+
7
+ # Step 4 of 5: Batch Create Detailed Story Files
8
+
9
+ **Goal:** For every backlog story in `sprint-status.yaml`, launch an independent Agent subprocess that runs `xiaoma-create-story` to produce a detailed `{story_key}.md` file. The Agent stops immediately after story creation — it does NOT enter development, code-review, or testing.
10
+
11
+ **Role:** SM (xiaomin) — Pipeline Batch Scheduler
12
+
13
+ ---
14
+
15
+ ## Core Architecture: Agent-Isolated Story Creation (Narrowed)
16
+
17
+ **Why this architecture:** Each story is delegated to an independent Agent subprocess so the main scheduler stays lightweight and isolated from per-story context bloat. This mirrors the proven `auto-story-pipeline-batch` (ASB) pattern.
18
+
19
+ **KEY DIFFERENCE from ASB:** ASB's Agent runs steps 02→08 (create + validate + develop + review + test + fix + complete). **THIS pipeline's Agent runs ONLY xiaoma-create-story and exits.** It is a hard error for an Agent here to enter validate-story, develop-story, code-review, test-story, fix-and-retest, or complete-story.
20
+
21
+ ```
22
+ Main conversation (scheduler, minimal context)
23
+ ├── Agent #1 → xiaoma-create-story for Story A → returns STORY_RESULT, exits
24
+ ├── Agent #2 → xiaoma-create-story for Story B → returns STORY_RESULT, exits
25
+ ├── Agent #3 → xiaoma-create-story for Story C → returns STORY_RESULT, exits
26
+ └── ...until backlog queue is empty
27
+ ```
28
+
29
+ ### Core Rules (Strictly Follow)
30
+
31
+ 1. **Each story processed by independent Agent** — Use the Agent tool to launch a general-purpose subprocess, pass complete story info + paths, have the Agent run `xiaoma-create-story` end-to-end, then return a structured summary
32
+ 2. **Agent must STOP after xiaoma-create-story** — Do NOT chain into any downstream step. This is enforced in the Agent prompt with explicit hard-boundary instructions
33
+ 3. **Main loop stays lightweight** — Main scheduler only: query sprint-status → launch Agent → read result → query remaining → continue or end
34
+ 4. **Serial processing** — Process one story at a time, wait for Agent completion before next, avoid concurrent modification conflicts on `sprint-status.yaml`
35
+ 5. **Failure tolerance** — A failed Agent does NOT halt the batch; the story key goes onto a blacklist and the loop continues
36
+
37
+ ---
38
+
39
+ ## EXECUTION SEQUENCE
40
+
41
+ ### 1. Announce Phase Entry
42
+
43
+ **Output:**
44
+
45
+ ```
46
+ ═══════════════════════════════════════════════════
47
+ Phase 3 of 3 — Batch Create Detailed Story Files
48
+ ═══════════════════════════════════════════════════
49
+
50
+ Switching role to SM (xiaomin) batch scheduler...
51
+ Using Agent subprocess isolation — each story processed independently.
52
+
53
+ For each story, an independent Agent will:
54
+ • Read and follow xiaoma-create-story workflow
55
+ • Produce {implementation_artifacts}/{story_key}.md
56
+ • Update sprint-status.yaml status to "ready-for-dev"
57
+ • Return STORY_RESULT summary and EXIT
58
+
59
+ ⚠️ Agent will NOT enter dev/review/test — this pipeline stops at story creation.
60
+ ───────────────────────────────────────────────────
61
+ ```
62
+
63
+ ### 2. Initial Sprint Status Load
64
+
65
+ 1. Load the FULL file: `{implementation_artifacts}/sprint-status.yaml`
66
+ 2. Read ALL lines from beginning to end — do not skip
67
+ 3. Parse the `development_status:` section completely
68
+ 4. Initial counts:
69
+ - `{backlog_count}` — Stories with status `backlog`
70
+ - `{ready_count}` — Stories with status `ready-for-dev` (pre-existing files; will be SKIPPED in this phase)
71
+ 5. If `{backlog_count}` == 0:
72
+ - If `{ready_count}` > 0: Output INFO — "{ready_count} stories already have files at ready-for-dev (from prior runs). Nothing to create. Proceeding to Step 4." → GOTO Step 4
73
+ - If `{ready_count}` == 0: HALT — "Sprint status has no backlog stories. Cannot proceed."
74
+
75
+ ### 3. Batch Loop
76
+
77
+ Repeat the following until the backlog queue is empty:
78
+
79
+ #### 3.1 Find Next Processable Story
80
+
81
+ 1. **Fresh read from disk:** Load the FULL `{implementation_artifacts}/sprint-status.yaml` again (do NOT rely on cached in-memory state — the previous iteration's Agent updated the file)
82
+ 2. Read ALL lines from beginning to end
83
+ 3. Parse `development_status:` completely
84
+ 4. Find the FIRST story (reading top to bottom) where:
85
+ - Key matches pattern `<digit>-<digit>-*` (e.g., `1-2-user-auth`)
86
+ - NOT an epic key (`epic-N`) or retrospective (`epic-N-retrospective`)
87
+ - Key is NOT in `{failed_story_keys}` (skip blacklisted stories)
88
+ - Status value equals `backlog`
89
+ 5. If no processable backlog story found → GOTO Step 4 (queue empty)
90
+
91
+ Set `{current_story_key}` = the found story key.
92
+
93
+ #### 3.2 Output Per-Story Progress Header
94
+
95
+ ```
96
+ ───────────────────────────────────────────────────
97
+ Creating story: {current_story_key}
98
+ Stories created so far: {stories_created} | Failed: {stories_failed}
99
+ ───────────────────────────────────────────────────
100
+ ```
101
+
102
+ #### 3.3 Launch Independent Agent Subprocess
103
+
104
+ <critical>
105
+
106
+ Use the **Agent tool** to launch a **general-purpose subprocess** to create this story.
107
+
108
+ The Agent's prompt MUST contain the following complete information for independent work:
109
+
110
+ **1. Story Information:**
111
+
112
+ - Story key: `{current_story_key}`
113
+ - Current status: `backlog`
114
+ - Expected output file: `{implementation_artifacts}/{current_story_key}.md`
115
+
116
+ **2. Configuration (inline all resolved values):**
117
+
118
+ - `project_name`: `{project_name}`
119
+ - `user_name`: `{user_name}`
120
+ - `communication_language`: `{communication_language}`
121
+ - `document_output_language`: `{document_output_language}`
122
+ - `user_skill_level`: `{user_skill_level}`
123
+ - `planning_artifacts`: `{planning_artifacts}`
124
+ - `implementation_artifacts`: `{implementation_artifacts}`
125
+ - `sprint_status`: `{implementation_artifacts}/sprint-status.yaml`
126
+ - `date`: current datetime
127
+ - `architecture_absent`: `{architecture_absent}` (boolean from step-01; controls whether Data Model subsection must default to "TBD by architect")
128
+
129
+ **3. Workflow Path (single workflow, narrow scope):**
130
+
131
+ - `create_story_workflow`: `{project-root}/_xiaoma/xmc/workflows/4-implementation/xiaoma-create-story/workflow.md`
132
+
133
+ **4. Project Context:**
134
+
135
+ - Include the actual CONTENT of `project-context.md` if it exists (pass content inline, not just the path)
136
+
137
+ **5. Processing Instructions (paste verbatim into the Agent prompt):**
138
+
139
+ > You are an SM (xiaomin) story-creation specialist running in an isolated subprocess. Your one and only job is to create the detailed user-story file for `{current_story_key}` by reading and following the `xiaoma-create-story` workflow at `{create_story_workflow}`.
140
+ >
141
+ > **Steps:**
142
+ >
143
+ > 1. Read the workflow at `{create_story_workflow}` completely.
144
+ > 2. Follow ALL its `<step>` blocks (step n=1 through step n=6) sequentially. The workflow auto-discovers the next backlog story from `sprint-status.yaml` — it will land on `{current_story_key}` because that's the first backlog story.
145
+ > 3. Produce the story file at `{implementation_artifacts}/{current_story_key}.md`.
146
+ > 4. **APPLY THE DETAILED DESIGN OUTPUT CONTRACT below before saving** — the create-story workflow's template is intentionally lean; this contract is mandatory and supersedes the template's defaults for the Dev Notes section.
147
+ > 5. Update `sprint-status.yaml`: set `development_status[{current_story_key}] = "ready-for-dev"`.
148
+ > 6. Return the STORY_RESULT summary (format below) and EXIT.
149
+ >
150
+ > **DETAILED DESIGN OUTPUT CONTRACT (mandatory) — applies to the story's `## Dev Notes` section:**
151
+ >
152
+ > The Dev Notes section MUST contain these three subsections (in this order). Do NOT omit, do NOT collapse, do NOT replace with a single paragraph.
153
+ >
154
+ > ```
155
+ > ### Functional Requirements Addressed
156
+ > - List EVERY FR/feature point from prd.md (or epics.md) that this story implements
157
+ > - For each: FR reference (e.g., "FR-3", "PRD §4.2", or epic-story acceptance criteria number) → one-line restatement
158
+ > - If a parent epic's FR list mentions FRs that this story is logically responsible for but you cannot find concrete acceptance criteria for them, list them anyway with the note "AC missing — needs PM review"
159
+ >
160
+ > ### Data Model & Database Design
161
+ > - Tables / collections / entities touched by this story (give candidate names if not yet created in the codebase)
162
+ > - Field list per entity: name, type, nullability, constraints, indexes, foreign keys
163
+ > - Migration / schema-change notes if the story implies new tables or column changes
164
+ > - **Source attribution:** every claim must end with `[Source: prd.md#<section>]` or `[Source: epics.md#<epic-story>]` or `[Source: architecture.md#<section>]`
165
+ > - **TBD policy:**
166
+ > - If `architecture_absent == true` AND prd.md contains data-model clues (DDL snippets, ER hints, field lists): extract them and write the schema explicitly with `[Source: prd.md#<section>]`
167
+ > - If `architecture_absent == true` AND no data-model clues exist anywhere: write the literal line `TBD by architect — no data-model clues in prd.md or epics.md.` Do NOT silently omit this subsection.
168
+ > - If `architecture_absent == false`: extract data-model from architecture.md and cite it. If architecture.md does not cover this story's entities, write `TBD by architect — architecture.md does not cover <entity>.`
169
+ >
170
+ > ### Implementation Logic
171
+ > - Key interface / function signatures (TypeScript-like or pseudocode form, even if the actual language differs)
172
+ > - Core algorithm, state machine, or event flow — numbered steps or a small block diagram in ASCII
173
+ > - Error-handling cases and boundary conditions (list the invariants and what should happen when they break)
174
+ > - External-service / API integration points (endpoint, method, request/response shape)
175
+ > - **Source attribution:** every claim must cite `[Source: prd.md#<section>]`, `[Source: epics.md#<epic-story>]`, or `[Source: architecture.md#<section>]`
176
+ > - **TBD policy:** if no source covers the required logic, write `TBD by architect — <specific question>.` rather than fabricating logic. A specific TBD is better than a confident hallucination.
177
+ > ```
178
+ >
179
+ > Standard create-story Dev Notes content (architecture patterns, source-tree components, testing standards) should still be produced — append them AFTER the three mandatory subsections above (e.g., as `### Architecture Patterns`, `### Source Tree Components`, `### Testing Standards`).
180
+ >
181
+ > **HARD BOUNDARY — DO NOT CROSS:**
182
+ >
183
+ > - After `xiaoma-create-story` workflow completes (and the contract above is applied), you are DONE.
184
+ > - Do NOT read `auto-story-pipeline/steps/step-03-validate-story.md` or any subsequent step.
185
+ > - Do NOT enter validate-story, develop-story, code-review, test-story, fix-and-retest, complete-story, or finalize.
186
+ > - Do NOT read or follow ANY workflow under `5-full-pipeline/` (including auto-full-pipeline, auto-prd-to-stories itself, or any other pipeline workflow). The only workflow you may read is `{create_story_workflow}`.
187
+ > - Do NOT read or follow `auto-story-pipeline-batch/workflow.md` or `auto-story-pipeline/workflow.md` — those are batch schedulers and downstream pipelines outside your scope.
188
+ > - Do NOT write any code, run any tests, or modify any source files outside `{planning_artifacts}` and `{implementation_artifacts}`.
189
+ > - Do NOT touch `sprint-status.yaml` beyond setting this one story's status to `ready-for-dev`.
190
+ > - The main scheduler handles everything after you return.
191
+ >
192
+ > **Execution Rules:**
193
+ >
194
+ > - Execute the create-story workflow's steps in exact order; do NOT skip steps.
195
+ > - When reading the story file or sprint-status in later substeps, always perform a FRESH read from disk.
196
+ > - Do not stop because of "milestones" or "significant progress" — continue until the story file is created and sprint-status updated.
197
+ > - If `xiaoma-create-story` asks for any user input (e.g., the "choose story" prompt in its step n=1), automatically pick option `{current_story_key}` (or let auto-discovery proceed — it will pick the first backlog story, which is this one).
198
+ > - When the create-story workflow's step n=6 outputs guidance like "Next Steps: Run dev agents `dev-story`", IGNORE it. That guidance is for interactive single-story mode; in this batch pipeline, the main scheduler handles next steps.
199
+
200
+ **6. Return Format (Agent must produce exactly this block at the end of its output):**
201
+
202
+ ```
203
+ STORY_RESULT:
204
+ - story_key: {story_key}
205
+ - final_status: created | failed
206
+ - file_path: {implementation_artifacts}/{story_key}.md
207
+ - summary: {one-line description of what was created}
208
+ - frs_addressed: [list of FR references / PRD section refs / acceptance-criteria ids that this story covers; empty list if none claimed]
209
+ - db_design_status: present | tbd-flagged | missing
210
+ - impl_logic_status: present | tbd-flagged | missing
211
+ - error: {error message if failed, empty otherwise}
212
+ ```
213
+
214
+ **Status-tag semantics (the Agent must self-assess and report honestly):**
215
+
216
+ - `present` — the subsection contains concrete schema/logic content with source attributions
217
+ - `tbd-flagged` — the subsection contains a clear "TBD by architect — <reason>" line as required by the contract
218
+ - `missing` — the subsection is absent or empty (this should NEVER happen if the contract is followed; if reported, the main scheduler will flag the story for re-creation)
219
+
220
+ </critical>
221
+
222
+ #### 3.4 Read Agent Result and Handle Outcome
223
+
224
+ Read the Agent's returned STORY_RESULT block.
225
+
226
+ **IF the Agent succeeded (`final_status: created`):**
227
+
228
+ 1. Verify the file actually exists at `{implementation_artifacts}/{current_story_key}.md` (defense in depth — sometimes Agents claim success without writing the file)
229
+ - If file missing despite `final_status: created`: treat as failure (proceed to failure branch below)
230
+ 2. Increment `{stories_created}` by 1
231
+ 3. Append to `{story_results}`: `{ story_key, final_status: "created", file_path, summary, frs_addressed, db_design_status, impl_logic_status }` — preserve ALL fields from STORY_RESULT for step-05's report
232
+ 4. If `db_design_status == "missing"` OR `impl_logic_status == "missing"`: output WARNING — "Story {current_story_key} created but reported `missing` for a mandatory subsection. step-05 will surface this in Structural Warnings."
233
+
234
+ **IF the Agent failed (`final_status: failed`, no STORY_RESULT block, or file-missing case above):**
235
+
236
+ 1. Increment `{stories_failed}` by 1
237
+ 2. Add `{current_story_key}` to `{failed_story_keys}` (prevents infinite re-selection)
238
+ 3. Append to `{story_results}`: `{ story_key, final_status: "failed", error }`
239
+ 4. Output: "⚠️ Story {current_story_key} failed. Reason: {error}. Skipping and continuing to next story."
240
+ 5. **Do NOT halt the batch.**
241
+
242
+ #### 3.5 Refresh Sprint Status and Output Checkpoint
243
+
244
+ 1. Re-read `{implementation_artifacts}/sprint-status.yaml` from disk (fresh read)
245
+ 2. Recount: `{backlog_count}`, `{ready_count}`
246
+ 3. Output checkpoint:
247
+
248
+ ```
249
+ [Checkpoint] Stories created: {stories_created} | Failed: {stories_failed} | Backlog remaining: {backlog_count}
250
+ Last story: {current_story_key} ({final_status})
251
+ ```
252
+
253
+ 4. If `{backlog_count}` > 0 (and at least one backlog story is NOT in `{failed_story_keys}`): Continue loop — return to 3.1
254
+ 5. Otherwise: GOTO Step 4 (queue empty)
255
+
256
+ ### 4. Determine Phase 3 Status
257
+
258
+ After loop exits:
259
+
260
+ - If `{stories_created}` > 0 AND `{stories_failed}` == 0: `{phase_3_status}` = "success"
261
+ - If `{stories_created}` > 0 AND `{stories_failed}` > 0: `{phase_3_status}` = "partial"
262
+ - If `{stories_created}` == 0 AND `{stories_failed}` > 0: `{phase_3_status}` = "failed"
263
+ - If `{stories_created}` == 0 AND `{stories_failed}` == 0: `{phase_3_status}` = "success" (nothing to do, but not an error — e.g., all stories pre-existing)
264
+
265
+ ### 5. Update Master Pipeline State
266
+
267
+ - `{prd_to_stories_status}` = "complete"
268
+ - `{steps_completed}` = 4
269
+
270
+ ### 6. Output Phase 3 Summary
271
+
272
+ ```
273
+ ───────────────────────────────────────────────────
274
+ Phase 3 Complete — Story File Generation
275
+ ───────────────────────────────────────────────────
276
+
277
+ Stories Created: {stories_created}
278
+ Stories Failed: {stories_failed}
279
+ Failed Story Keys: {failed_story_keys joined by comma, or "none"}
280
+
281
+ Phase 3 Status: {phase_3_status}
282
+ Master Step: 4/5
283
+
284
+ Proceeding to Finalization...
285
+ ───────────────────────────────────────────────────
286
+ ```
287
+
288
+ **Auto-Proceed:** YES — Do NOT wait for user input. Immediately proceed to step-05.
289
+
290
+ ---
291
+
292
+ ## NEXT STEP
293
+
294
+ **NEXT:** Read fully and follow: `{project-root}/_xiaoma/xmc/workflows/5-full-pipeline/auto-prd-to-stories/steps/step-05-finalize.md`
295
+
296
+ ---
297
+
298
+ ## SUCCESS METRICS
299
+
300
+ - Every backlog story has either: (a) a corresponding `.md` file at `ready-for-dev`, OR (b) an entry in `{failed_story_keys}` with documented error
301
+ - Main scheduler context stayed lightweight (no per-story bloat)
302
+ - No Agent crossed the hard boundary into dev/review/test
303
+ - `sprint-status.yaml` reflects all successful creations
304
+
305
+ ## FAILURE MODES
306
+
307
+ - All Agent subprocesses failing (likely indicates a workflow-installation issue)
308
+ - An Agent ignoring the hard-boundary instruction and entering downstream steps — if observed, the main scheduler should still record STORY_RESULT and continue, but the user should be warned in the final report
309
+ - `sprint-status.yaml` corruption from concurrent modification — mitigated by strict serial processing
@@ -0,0 +1,311 @@
1
+ ---
2
+ name: 'step-05-finalize'
3
+ description: 'Validate all artifacts, run completion checklist, and generate the final report for business-architect review'
4
+ nextStepFile: null
5
+ ---
6
+
7
+ # Step 5 of 5: Finalize PRD-to-Stories Pipeline
8
+
9
+ **Goal:** Validate all output artifacts, run the completion checklist, and generate the unified report that business architects will use to evaluate the quality of the generated user stories.
10
+
11
+ **Role:** Pipeline Orchestrator
12
+
13
+ ---
14
+
15
+ ## EXECUTION SEQUENCE
16
+
17
+ ### 1. Validate All Artifacts
18
+
19
+ Check that ALL expected output files exist:
20
+
21
+ **Phase 1 — Epics Artifact:**
22
+
23
+ 1. `{planning_artifacts}/epics.md` — Required
24
+
25
+ **Phase 2 — Sprint Planning Artifact:**
26
+
27
+ 2. `{implementation_artifacts}/sprint-status.yaml` — Required
28
+
29
+ **Phase 3 — Story File Artifacts:**
30
+
31
+ 3. For each story key in sprint-status.yaml (excluding those in `{failed_story_keys}`), a corresponding file at `{implementation_artifacts}/{story_key}.md` — Required
32
+
33
+ For each missing artifact:
34
+
35
+ - If epics.md or sprint-status.yaml is missing: log CRITICAL FAILURE
36
+ - If a per-story file is missing but its key is NOT in `{failed_story_keys}`: log CRITICAL FAILURE (the Agent claimed success without writing the file)
37
+ - If a per-story file is missing AND its key IS in `{failed_story_keys}`: expected (documented failure), no action
38
+
39
+ ### 2. Read Final Sprint Status
40
+
41
+ Fresh-read `{implementation_artifacts}/sprint-status.yaml` and parse:
42
+
43
+ - `{final_epic_count}` — Number of `epic-N` entries
44
+ - `{final_story_count}` — Total story keys matching `<digit>-<digit>-*`
45
+ - `{final_ready_count}` — Stories with status `ready-for-dev`
46
+ - `{final_backlog_count}` — Stories still at `backlog` (should equal `{stories_failed}` if pipeline ran fully)
47
+
48
+ **Sanity check:** `{final_ready_count}` should equal `{stories_created}` + (any pre-existing ready-for-dev stories from re-runs).
49
+
50
+ ### 3. Run Completion Checklist
51
+
52
+ If `{installed_path}/checklist.md` is readable, load it and evaluate each item against the artifacts on disk. For each failed item, append a line to the final report's "Checklist Findings" section.
53
+
54
+ If checklist.md is missing, skip this section silently.
55
+
56
+ ### 4. Validate Story File Structure (Full Scan + Deep Subsection Check)
57
+
58
+ For **EVERY** successfully created story file (NOT sampled — scan all of them):
59
+
60
+ 1. Read the file fully
61
+ 2. **Top-level required sections** (case-insensitive heading search):
62
+ - `Status` (and value contains `ready-for-dev`)
63
+ - `Story` (with "As a / I want / so that" pattern)
64
+ - `Acceptance Criteria`
65
+ - `Tasks` (or `Tasks / Subtasks`)
66
+ - `Dev Notes`
67
+ 3. **Dev Notes mandatory subsections** (the three from the step-04 Detailed Design Output Contract):
68
+ - `### Functional Requirements Addressed` (or case-insensitive variant matching `Functional Requirements`)
69
+ - `### Data Model & Database Design` (or case-insensitive variant matching any of: `Data Model`, `Database Design`, `Database Schema`, `数据模型`, `数据库设计`)
70
+ - `### Implementation Logic` (or case-insensitive variant matching any of: `Implementation Logic`, `Implementation Detail`, `Pseudocode`, `接口设计`, `实现逻辑`)
71
+ 4. **Subsection content quality (lightweight heuristic):**
72
+ - Data Model subsection: content non-empty AND (contains a table/field-list line OR contains the literal "TBD by architect")
73
+ - Implementation Logic subsection: content non-empty AND (contains code-fence / function signature / numbered steps OR contains the literal "TBD by architect")
74
+ - A subsection that contains only a heading with no body fails this check.
75
+
76
+ For each story file, classify:
77
+
78
+ - **Tier A — Fully Compliant:** all top-level sections present, all three Dev Notes subsections present and content-positive (no `TBD by architect`)
79
+ - **Tier B — TBD-flagged:** all sections present, but one or more subsections contain `TBD by architect` (this is acceptable — it surfaces unknowns honestly for the architect)
80
+ - **Tier C — Structurally Incomplete:** one or more required top-level sections missing, OR a required Dev Notes subsection missing, OR a subsection has only a heading with no body
81
+
82
+ Compute the coverage tallies for the final report:
83
+
84
+ - `{dev_notes_db_coverage}` = count of story files with a non-empty `Data Model & Database Design` subsection / `{stories_created}`
85
+ - `{dev_notes_impl_coverage}` = count of story files with a non-empty `Implementation Logic` subsection / `{stories_created}`
86
+ - `{tier_a_count}`, `{tier_b_count}`, `{tier_c_count}` for the per-tier breakdown
87
+
88
+ For every Tier C file, add a line to "Structural Warnings" listing the file path and exactly which sections/subsections failed.
89
+
90
+ Also cross-check `story_results` from step-04: if any story has `db_design_status: missing` or `impl_logic_status: missing` reported by the Agent, list it in Structural Warnings even if heading-based detection passed (the Agent self-reported missing content).
91
+
92
+ ### 4b. FR Reverse-Traceability Check
93
+
94
+ This implements Must Fix #4: ensure every functional requirement in `prd.md` is referenced by at least one story file.
95
+
96
+ 1. **Parse PRD functional requirements:**
97
+ - Read `{planning_artifacts}/prd.md` fully
98
+ - Extract FR identifiers using these patterns (in priority order, stop after the first that yields ≥1 match):
99
+ a. Lines matching `^FR-?\d+\b` or `^\*\*FR-?\d+\*\*` (canonical FR-N format)
100
+ b. Lines under a section titled `## Functional Requirements` or `## 功能需求`, where each bullet/numbered item is treated as one FR (assign synthetic ids `FR-1`, `FR-2`, ...)
101
+ c. Numbered headings under `## Features` or `## 功能点` (assign synthetic ids `FEAT-1`, `FEAT-2`, ...)
102
+ - If no patterns match (PRD has no structured FR list): skip the rest of this section and log INFO — "PRD has no structured FR list; reverse traceability skipped. Architects should manually verify coverage from epics.md and story files."
103
+ - Otherwise, set `{prd_fr_inventory}` = the list of extracted FR identifiers + their short title
104
+
105
+ 2. **For each FR in `{prd_fr_inventory}`:**
106
+ - Search ALL story files (`{implementation_artifacts}/<digit>-<digit>-*.md`) for ANY of:
107
+ - The exact FR identifier (e.g., `FR-3`)
108
+ - The FR's short title text (substring match, case-insensitive, length ≥ 8 chars to avoid false positives)
109
+ - A `[Source: prd.md#<section>]` citation whose `<section>` matches the FR's parent section
110
+ - If at least one story file references the FR: mark `covered`
111
+ - If no story file references the FR: mark `uncovered`
112
+
113
+ 3. **Compute coverage:**
114
+ - `{fr_coverage_numerator}` = count of FRs marked `covered`
115
+ - `{fr_coverage_denominator}` = `len(prd_fr_inventory)`
116
+ - `{uncovered_frs}` = list of FR identifiers marked `uncovered`
117
+
118
+ 4. **For each uncovered FR:**
119
+ - Add a HIGH-PRIORITY line to "Structural Warnings": `Uncovered FR: {fr_id} — "{fr_title}" — NO story file references this requirement. The pipeline may have dropped this feature.`
120
+
121
+ 5. **Cross-check epics.md FR Coverage Map** (if `{epics_fr_count}` was set in step-02):
122
+ - If `{fr_coverage_denominator}` significantly differs from `{epics_fr_count}` (delta > 20%): add WARNING to Structural Warnings — "FR-Coverage-Map count ({epics_fr_count}) vs PRD-extracted FR count ({fr_coverage_denominator}) differ by >20%. epics.md may have an incomplete FR Coverage Map."
123
+
124
+ ### 5. Generate Final Report
125
+
126
+ Set `{prd_to_stories_status}` = "complete" and `{steps_completed}` = 5 BEFORE printing.
127
+
128
+ **Output:**
129
+
130
+ ```
131
+ ═══════════════════════════════════════════════════════════════
132
+ Auto PRD-to-Stories Pipeline — COMPLETE
133
+ ═══════════════════════════════════════════════════════════════
134
+
135
+ Project: {project_name}
136
+ Date: {date}
137
+ Master Steps Completed: {steps_completed}/5
138
+
139
+ Input:
140
+ 📋 PRD: {planning_artifacts}/prd.md
141
+
142
+ Outputs:
143
+ 📄 Epics: {planning_artifacts}/epics.md [{phase_1_status}]
144
+ 📊 Sprint Status: {implementation_artifacts}/sprint-status.yaml [{phase_2_status}]
145
+ 📁 Story Files: {implementation_artifacts}/<story_key>.md × {stories_created} [{phase_3_status}]
146
+
147
+ Phase Breakdown:
148
+ Phase 1 — Create Epics [{phase_1_status}]
149
+ └─ Total Epics: {final_epic_count}
150
+ └─ Total Stories (in epics.md): {final_story_count}
151
+ └─ FRs in Coverage Map: {epics_fr_count}
152
+
153
+ Phase 2 — Sprint Planning Bridge [{phase_2_status}]
154
+ └─ Stories tracked: {final_story_count}
155
+
156
+ Phase 3 — Batch Story File Creation [{phase_3_status}]
157
+ ├─ Stories Successfully Created: {stories_created}
158
+ ├─ Stories Failed: {stories_failed}
159
+ └─ Failed Keys: {failed_story_keys joined, or "none"}
160
+
161
+ 🔎 Quality Coverage (for architect review):
162
+ ├─ FR Coverage: {fr_coverage_numerator}/{fr_coverage_denominator}
163
+ ├─ Data Model subsection: {dev_notes_db_coverage}/{stories_created} (present)
164
+ ├─ Implementation Logic subsec: {dev_notes_impl_coverage}/{stories_created} (present)
165
+ ├─ Tier A (fully compliant): {tier_a_count}
166
+ ├─ Tier B (TBD-flagged honest): {tier_b_count}
167
+ └─ Tier C (structurally incomplete): {tier_c_count} ⚠ if > 0, see Structural Warnings below
168
+
169
+ Pipeline Status: {prd_to_stories_status}
170
+ ═══════════════════════════════════════════════════════════════
171
+
172
+ 📋 Story Files Generated (for business-architect review):
173
+ {for each entry in story_results where final_status == "created":
174
+ ✅ {story_key}.md — {summary}
175
+ }
176
+
177
+ ❌ Story Files Failed:
178
+ {for each entry in story_results where final_status == "failed":
179
+ ⚠️ {story_key} — {error}
180
+ }
181
+
182
+ {IF "Structural Warnings" non-empty:}
183
+ ⚠️ Structural Warnings (high → low priority):
184
+
185
+ -- FR Coverage Gaps (HIGHEST priority — these features may have been dropped) --
186
+ {for each uncovered_fr: "Uncovered FR: {fr_id} — \"{fr_title}\" — NO story file references this. The pipeline may have dropped this feature."}
187
+
188
+ -- Structural Incompleteness (Tier C files) --
189
+ {for each Tier C entry: story_key — missing sections/subsections list}
190
+
191
+ -- Self-Reported Missing Content (from Agent STORY_RESULT) --
192
+ {for each story with db_design_status == "missing" or impl_logic_status == "missing": story_key — which subsection Agent reported missing}
193
+
194
+ -- FR Coverage Map Discrepancy (if any) --
195
+ {if FR-coverage-map count delta > 20%: warning text}
196
+
197
+ {IF "Checklist Findings" non-empty:}
198
+ 📋 Checklist Findings:
199
+ {for each failed item: item description}
200
+ ```
201
+
202
+ ### 6. Architect Review Guidance
203
+
204
+ ```
205
+ ───────────────────────────────────────────────────────────────
206
+ 🎯 Next: Business-Architect Quality Review
207
+ ───────────────────────────────────────────────────────────────
208
+
209
+ The pipeline stops HERE intentionally. The generated artifacts are
210
+ the input to a manual quality review:
211
+
212
+ 1. **Start with the Quality Coverage block above.**
213
+ - If FR Coverage < 100%: find the listed uncovered FRs FIRST — these
214
+ are features from prd.md that no story addresses. Run create-epics-
215
+ and-stories again or manually add the missing stories.
216
+ - If Tier C count > 0: open those files first — they have structural
217
+ holes that block downstream development.
218
+
219
+ 2. Review epics.md for completeness vs. the input prd.md
220
+ (Are all PRD features represented? Right epic granularity?
221
+ Cross-check the FR Coverage Map section.)
222
+
223
+ 3. Review each {story_key}.md for:
224
+ - Story statement clarity (As a / I want / so that)
225
+ - Acceptance Criteria testability (BDD Given/When/Then quality)
226
+ - Task decomposition concreteness
227
+ - **Data Model & Database Design subsection** — Are the tables/fields/
228
+ indexes/constraints concrete? If "TBD by architect", is the missing
229
+ piece something prd.md should have specified, or is it genuinely a
230
+ design decision for the architect to make now?
231
+ - **Implementation Logic subsection** — Are interface signatures,
232
+ algorithms, and error-handling concrete? Or hand-wavy?
233
+ - **Functional Requirements Addressed subsection** — Does it cite
234
+ specific FRs/sections from prd.md or epics.md?
235
+
236
+ 4. Capture feedback on which dimensions are weak — feed back
237
+ into the create-epics-and-stories / create-story prompts
238
+ to improve generation quality.
239
+
240
+ 5. When ready to enter development, run:
241
+ /xiaoma → load sm → ASB
242
+ (auto-story-pipeline-batch will pick up from ready-for-dev.)
243
+
244
+ ───────────────────────────────────────────────────────────────
245
+ ```
246
+
247
+ ### 7. Generate Machine-Readable Status File
248
+
249
+ Write to: `{implementation_artifacts}/prd-to-stories-status.json`
250
+
251
+ ```json
252
+ {
253
+ "pipeline": "auto-prd-to-stories",
254
+ "date": "{date}",
255
+ "project": "{project_name}",
256
+ "status": "{prd_to_stories_status}",
257
+ "master_steps_completed": 5,
258
+ "input": {
259
+ "prd": "{planning_artifacts}/prd.md"
260
+ },
261
+ "phases": {
262
+ "epics": {
263
+ "status": "{phase_1_status}",
264
+ "artifact": "{planning_artifacts}/epics.md",
265
+ "epic_count": "{final_epic_count}",
266
+ "story_count": "{final_story_count}"
267
+ },
268
+ "sprint_planning": {
269
+ "status": "{phase_2_status}",
270
+ "artifact": "{implementation_artifacts}/sprint-status.yaml"
271
+ },
272
+ "story_creation": {
273
+ "status": "{phase_3_status}",
274
+ "stories_created": "{stories_created}",
275
+ "stories_failed": "{stories_failed}",
276
+ "failed_story_keys": "{failed_story_keys}",
277
+ "quality_coverage": {
278
+ "fr_coverage": {
279
+ "covered": "{fr_coverage_numerator}",
280
+ "total": "{fr_coverage_denominator}",
281
+ "uncovered_frs": "{uncovered_frs}"
282
+ },
283
+ "data_model_present": "{dev_notes_db_coverage}",
284
+ "implementation_logic_present": "{dev_notes_impl_coverage}",
285
+ "tier_a_count": "{tier_a_count}",
286
+ "tier_b_count": "{tier_b_count}",
287
+ "tier_c_count": "{tier_c_count}"
288
+ }
289
+ }
290
+ }
291
+ }
292
+ ```
293
+
294
+ ### 8. Pipeline Complete
295
+
296
+ **Pipeline execution is COMPLETE. HALT.**
297
+
298
+ ---
299
+
300
+ ## SUCCESS METRICS
301
+
302
+ - All 3 phases reported with status
303
+ - All successfully created story files exist on disk and contain required sections
304
+ - Final report output with architect-review guidance
305
+ - Machine-readable status file written
306
+
307
+ ## FAILURE MODES
308
+
309
+ - Missing epics.md or sprint-status.yaml when at least one phase claimed success
310
+ - Story files claimed created but missing on disk
311
+ - Failure to write the final status JSON