agile-context-engineering 0.1.0 → 0.2.1

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 (84) hide show
  1. package/LICENSE +30 -0
  2. package/README.md +272 -78
  3. package/agents/ace-code-discovery-analyst.md +245 -0
  4. package/agents/ace-code-integration-analyst.md +248 -0
  5. package/agents/ace-code-reviewer.md +375 -0
  6. package/agents/ace-product-owner.md +361 -0
  7. package/agents/ace-project-researcher.md +606 -0
  8. package/agents/ace-research-synthesizer.md +228 -0
  9. package/agents/ace-technical-application-architect.md +287 -0
  10. package/agents/ace-wiki-mapper.md +334 -0
  11. package/agile-context-engineering/src/ace-tools.js +2881 -0
  12. package/agile-context-engineering/src/ace-tools.test.js +1089 -0
  13. package/agile-context-engineering/templates/_command.md +54 -0
  14. package/agile-context-engineering/templates/_workflow.xml +17 -0
  15. package/agile-context-engineering/templates/config.json +0 -0
  16. package/agile-context-engineering/templates/product/external-solution.xml +832 -0
  17. package/agile-context-engineering/templates/product/feature.xml +361 -0
  18. package/agile-context-engineering/templates/product/integration-solution.xml +0 -0
  19. package/agile-context-engineering/templates/product/product-backlog.xml +231 -0
  20. package/agile-context-engineering/templates/product/product-vision.xml +227 -0
  21. package/agile-context-engineering/templates/product/story-integration-solution.xml +1014 -0
  22. package/agile-context-engineering/templates/product/story-technical-solution.xml +1025 -0
  23. package/agile-context-engineering/templates/product/story-wiki.xml +190 -0
  24. package/agile-context-engineering/templates/product/story.xml +451 -0
  25. package/agile-context-engineering/templates/wiki/coding-standards.xml +493 -0
  26. package/agile-context-engineering/templates/wiki/decizions.xml +115 -0
  27. package/agile-context-engineering/templates/wiki/guide.xml +137 -0
  28. package/agile-context-engineering/templates/wiki/module-discovery.xml +174 -0
  29. package/agile-context-engineering/templates/wiki/pattern.xml +159 -0
  30. package/agile-context-engineering/templates/wiki/subsystem-architecture.xml +343 -0
  31. package/agile-context-engineering/templates/wiki/subsystem-structure.xml +235 -0
  32. package/agile-context-engineering/templates/wiki/system-architecture.xml +254 -0
  33. package/agile-context-engineering/templates/wiki/system-cross-cutting.xml +197 -0
  34. package/agile-context-engineering/templates/wiki/system-structure.xml +178 -0
  35. package/agile-context-engineering/templates/wiki/system.xml +381 -0
  36. package/agile-context-engineering/templates/wiki/tech-debt-index.xml +125 -0
  37. package/agile-context-engineering/templates/wiki/testing-framework.xml +283 -0
  38. package/agile-context-engineering/templates/wiki/wiki-readme.xml +276 -0
  39. package/agile-context-engineering/utils/questioning.xml +111 -0
  40. package/agile-context-engineering/utils/ui-formatting.md +300 -0
  41. package/agile-context-engineering/workflows/execute-story.xml +1145 -0
  42. package/agile-context-engineering/workflows/help.xml +540 -0
  43. package/agile-context-engineering/workflows/init-coding-standards.xml +386 -0
  44. package/agile-context-engineering/workflows/map-story.xml +797 -0
  45. package/agile-context-engineering/workflows/map-subsystem.xml +1177 -0
  46. package/agile-context-engineering/workflows/map-system.xml +672 -0
  47. package/agile-context-engineering/workflows/plan-backlog.xml +1356 -0
  48. package/agile-context-engineering/workflows/plan-feature.xml +1495 -0
  49. package/agile-context-engineering/workflows/plan-product-vision.xml +342 -0
  50. package/agile-context-engineering/workflows/plan-story.xml +909 -0
  51. package/agile-context-engineering/workflows/research-external-solution.xml +659 -0
  52. package/agile-context-engineering/workflows/research-integration-solution.xml +712 -0
  53. package/agile-context-engineering/workflows/research-story-wiki.xml +474 -0
  54. package/agile-context-engineering/workflows/research-technical-solution.xml +762 -0
  55. package/agile-context-engineering/workflows/review-story.xml +281 -0
  56. package/bin/install.js +102 -166
  57. package/commands/ace/execute-story.md +137 -0
  58. package/commands/ace/help.md +93 -0
  59. package/commands/ace/init-coding-standards.md +83 -0
  60. package/commands/ace/map-story.md +156 -0
  61. package/commands/ace/map-subsystem.md +138 -0
  62. package/commands/ace/map-system.md +92 -0
  63. package/commands/ace/plan-backlog.md +83 -0
  64. package/commands/ace/plan-feature.md +89 -0
  65. package/commands/ace/plan-product-vision.md +81 -0
  66. package/commands/ace/plan-story.md +145 -0
  67. package/commands/ace/research-external-solution.md +138 -0
  68. package/commands/ace/research-integration-solution.md +135 -0
  69. package/commands/ace/research-story-wiki.md +116 -0
  70. package/commands/ace/research-technical-solution.md +147 -0
  71. package/commands/ace/review-story.md +109 -0
  72. package/package.json +5 -8
  73. package/agents/executor.md +0 -88
  74. package/agents/planner.md +0 -78
  75. package/agents/researcher.md +0 -77
  76. package/agents/verifier.md +0 -116
  77. package/commands/ace-execute-story.md +0 -114
  78. package/commands/ace-init.md +0 -254
  79. package/commands/ace-plan-epic.md +0 -79
  80. package/commands/ace-plan-feature.md +0 -78
  81. package/commands/ace-plan-project.md +0 -205
  82. package/commands/ace-plan-story.md +0 -97
  83. package/commands/ace-refine-story.md +0 -90
  84. package/commands/ace-verify-story.md +0 -127
@@ -0,0 +1,909 @@
1
+ <workflow>
2
+
3
+ <purpose>
4
+ Orchestrate story specification: load a story seed (from file or GitHub issue),
5
+ absorb any existing description, conduct deep questioning to define CRYSTAL-CLEAR
6
+ acceptance criteria with ZERO ambiguity, write the story specification (pass 1),
7
+ then dispatch passes 2-5 as background agents that write their outputs directly
8
+ to files — keeping this orchestrator's context window clean.
9
+
10
+ Produces `.ace/artifacts/product/&lt;id-epic_name&gt;/&lt;id-feature_name&gt;/&lt;id-story_name&gt;/&lt;id-story_name&gt;.md`
11
+ — a complete story specification with INVEST-compliant user story, Gherkin acceptance
12
+ criteria, definition of done, scope boundaries, and relevant wiki references.
13
+
14
+ Additionally produces (via background agents):
15
+ - `external-analysis.md` in story directory (OPTIONAL — pass 3)
16
+ - `integration-analysis.md` in story directory (pass 4)
17
+ - Technical Solution section appended to story file (pass 5)
18
+
19
+ The orchestrator's context window contains ONLY story requirements information.
20
+ Passes 2-5 write to disk and return only completion confirmations.
21
+ The orchestrator MUST NOT call TaskOutput on any background agent.
22
+ TaskOutput returns the agent's FULL internal transcript (every file read, every search,
23
+ every tool call) — calling it will inflate the context window by 10-20%. THIS IS FORBIDDEN.
24
+ Do NOT call TaskOutput. Do NOT call TaskOutput. Do NOT call TaskOutput.
25
+ </purpose>
26
+
27
+ <mandatory-context>
28
+ Read all files referenced by the invoking command's execution-context before starting.
29
+ Also read any document or text passed as parameter ($ARGUMENTS) in the invoking command.
30
+ </mandatory-context>
31
+
32
+ <process>
33
+
34
+ <!-- ══════════════════════════════════════════════════════════════════ -->
35
+ <!-- STEP 1: SETUP -->
36
+ <!-- ══════════════════════════════════════════════════════════════════ -->
37
+
38
+ <step name="setup" order="1">
39
+ **MANDATORY FIRST STEP — Execute environment detection before any user interaction:**
40
+
41
+ Parse `$ARGUMENTS` to extract:
42
+ - `story` (REQUIRED): file path or GitHub URL/issue number
43
+ - `external-codebase` (OPTIONAL): path or GitHub URL to external system
44
+ - `external-docs` (OPTIONAL): weblink or filepath to external docs
45
+
46
+ ```bash
47
+ INIT=$(node ~/.claude/agile-context-engineering/src/ace-tools.js init plan-story {story_param})
48
+ ```
49
+
50
+ Parse INIT JSON for:
51
+ - `product_owner_model`, `commit_docs`
52
+ - `has_git`, `has_gh_cli`, `github_project`
53
+ - `is_brownfield`, `is_greenfield`, `has_wiki`
54
+ - `has_product_vision`, `has_product_backlog`
55
+ - `story_source`, `story_valid`, `story_error`, `story_content`
56
+ - `story` (id, title, status, size), `feature` (id, title), `epic` (id, title)
57
+ - `user_story`, `description`, `acceptance_criteria_count`
58
+ - `paths.*` (story_dir, story_file, feature_dir, feature_file, etc.)
59
+ - `has_external_analysis`, `has_integration_analysis`, `has_feature_file`, `has_story_file`
60
+
61
+ Also resolve the product owner model:
62
+ ```bash
63
+ PO_MODEL=$(node ~/.claude/agile-context-engineering/src/ace-tools.js resolve-model ace-product-owner --raw)
64
+ ```
65
+
66
+ Display stage banner:
67
+
68
+ ```
69
+ ╔══════════════════════════════════════════════════╗
70
+ ║ ACE > Plan Story ║
71
+ ╚══════════════════════════════════════════════════╝
72
+ ```
73
+
74
+ **If `has_git` is false:** Initialize git:
75
+ ```bash
76
+ git init
77
+ ```
78
+
79
+ **If `INIT.story_valid` is false:**
80
+ Display error using `INIT.story_error` and exit:
81
+ ```
82
+ x {INIT.story_error}
83
+ Provide a valid story file path or GitHub issue.
84
+ ```
85
+
86
+ Store `EXTERNAL_CODEBASE` and `EXTERNAL_DOCS` from parsed arguments (may be null).
87
+ </step>
88
+
89
+ <!-- ══════════════════════════════════════════════════════════════════ -->
90
+ <!-- STEP 2: LOAD STORY SEED -->
91
+ <!-- ══════════════════════════════════════════════════════════════════ -->
92
+
93
+ <step name="load-story-seed" order="2">
94
+
95
+ The story seed is the raw description of what needs to be built.
96
+ It may come from:
97
+ - A stub file created by `plan-feature` (has Description section)
98
+ - A GitHub issue with free-text description
99
+ - Any markdown file with story context
100
+
101
+ **Read the story content** (already available in `INIT.story_content`).
102
+ Parse and hold as `STORY_SEED`:
103
+ - Title (from header or first heading)
104
+ - Description (any free-text description of what needs to be done)
105
+ - Any existing AC scenarios (if the story was previously partially refined)
106
+ - Any images referenced (markdown `![](path)` or HTML `&lt;img src="path"&gt;`)
107
+
108
+ <!-- ── 2a: Image validation ──────────────────────────────────── -->
109
+
110
+ Extract ALL image references from the story content:
111
+ - Markdown: `![alt](path)`
112
+ - HTML: `&lt;img src="path"&gt;`
113
+
114
+ For EACH image reference, attempt to READ it using the Read tool.
115
+
116
+ **IF ANY IMAGE CANNOT BE READ:**
117
+ ```
118
+ x STOP: Cannot proceed — Referenced images are not accessible.
119
+
120
+ Image validation results:
121
+ - [image1.png] -> SUCCESS
122
+ - [image2.png] -> FAILED: File not found
123
+
124
+ Please provide correct paths or describe what each missing image contains.
125
+ ```
126
+ Wait for user response before proceeding.
127
+
128
+ <!-- ── 2b: Detect run mode ───────────────────────────────────── -->
129
+
130
+ **If `INIT.acceptance_criteria_count > 0`:**
131
+ The story has existing AC — this is a REFINE run.
132
+ Set `RUN_MODE = REFINE`.
133
+
134
+ Use AskUserQuestion:
135
+ - header: "Story exists"
136
+ - question: "This story already has {INIT.acceptance_criteria_count} acceptance criteria scenarios. What would you like to do?"
137
+ - options:
138
+ - "Refine it" — Review and update the existing specification
139
+ - "Start fresh" — Discard existing AC and rebuild from the description
140
+ - "Skip to research" — Keep current AC, skip to passes 2-5
141
+
142
+ If "Start fresh": set `RUN_MODE = CREATE`, clear existing AC from working copy.
143
+ If "Skip to research": jump directly to step 7 (dispatch passes 2-5).
144
+ If "Refine it": continue to step 3 with existing content as context.
145
+
146
+ **If `INIT.acceptance_criteria_count == 0`:**
147
+ Set `RUN_MODE = CREATE`. Continue to step 3.
148
+
149
+ Display:
150
+ ```
151
+ i Story loaded: {title}
152
+ Source: {file path or GitHub issue}
153
+ Mode: {CREATE | REFINE}
154
+ Description: {first 100 chars of description}...
155
+ ```
156
+ </step>
157
+
158
+ <!-- ══════════════════════════════════════════════════════════════════ -->
159
+ <!-- STEP 3: LOAD FOUNDATION CONTEXT -->
160
+ <!-- ══════════════════════════════════════════════════════════════════ -->
161
+
162
+ <step name="load-foundation" order="3">
163
+
164
+ **3a. Load parent feature document (if exists):**
165
+
166
+ If `INIT.has_feature_file` is true:
167
+ - Read the feature document at `INIT.paths.feature_file`
168
+ - Extract: Feature description, scope (includes/excludes), benefit hypothesis,
169
+ story breakdown (other stories and their scopes), acceptance criteria, technical context
170
+ - Hold as `FEATURE_CONTEXT`
171
+
172
+ If false: set `FEATURE_CONTEXT = null`
173
+
174
+ **3b. Load product vision (if exists):**
175
+
176
+ If `INIT.has_product_vision` is true:
177
+ - Read `.docs/product/product-vision.md`
178
+ - Extract personas, target audience, key objectives
179
+ - Hold as `VISION` (used to validate persona in user story statement)
180
+
181
+ If false: set `VISION = null`
182
+
183
+ **3c. Load product backlog (if exists):**
184
+
185
+ If `INIT.has_product_backlog` is true:
186
+ - Read `.ace/artifacts/product/product-backlog.md`
187
+ - Extract the parent epic's context and any related features
188
+ - Hold as `BACKLOG_CONTEXT`
189
+
190
+ If false: set `BACKLOG_CONTEXT = null`
191
+
192
+ Display loaded context:
193
+ ```
194
+ i Context loaded:
195
+ [+] Parent feature document ({lines} lines)
196
+ [+] Product vision (personas: {list})
197
+ [ ] Product backlog (not found)
198
+ ```
199
+ </step>
200
+
201
+ <!-- ══════════════════════════════════════════════════════════════════ -->
202
+ <!-- STEP 4: DEEP QUESTIONING -->
203
+ <!-- ══════════════════════════════════════════════════════════════════ -->
204
+
205
+ <step name="deep-questioning" order="4">
206
+ Follow the questioning guide from `questioning.xml`. You are a thinking partner,
207
+ not an interviewer.
208
+
209
+ Display:
210
+ ```
211
+ ┌──────────────────────────────────────────────────┐
212
+ │ ACE > Plan Story > Questioning │
213
+ └──────────────────────────────────────────────────┘
214
+ ```
215
+
216
+ <!-- ── 4a: Opening — present what you know ───────────────────── -->
217
+
218
+ Start by presenting your understanding of the story from the seed:
219
+
220
+ "Based on the story description and feature context, here's what I understand
221
+ this story delivers: {summary}. Let me ask some questions to make sure the
222
+ acceptance criteria are crystal clear."
223
+
224
+ If FEATURE_CONTEXT is available, reference the story's position within
225
+ the feature — what it builds on and what it enables.
226
+
227
+ <!-- ── 4b: ZERO-ASSUMPTION questioning ───────────────────────── -->
228
+
229
+ **CRITICAL MANDATE: ZERO ASSUMPTIONS**
230
+
231
+ Every acceptance criterion MUST be so explicit that an AI agent with NO prior
232
+ context can implement it correctly. This means:
233
+
234
+ **For EVERY behavior, probe until you have:**
235
+ 1. **Exact trigger** — What SPECIFIC user action or system event starts this?
236
+ - Bad: "When the user submits" → Submit what? Where? How?
237
+ - Good: "When the user clicks the 'Save' button on the Settings page"
238
+
239
+ 2. **Exact preconditions** — What state MUST exist before the trigger?
240
+ - Bad: "Given the user is logged in" → What kind of user? What permissions?
241
+ - Good: "Given a user with 'admin' role is authenticated and on the Dashboard page"
242
+
243
+ 3. **Exact expected outcome** — What OBSERVABLE result occurs?
244
+ - Bad: "Then it works" → How do you KNOW it works?
245
+ - Bad: "Then the data is saved" → Saved WHERE? What confirmation does the user see?
246
+ - Good: "Then a success toast appears with message 'Settings saved' and the page
247
+ reflects the updated value without requiring a refresh"
248
+
249
+ 4. **Exact data/values** — What SPECIFIC data is involved?
250
+ - Bad: "The form has fields" → Which fields? What types? What validation?
251
+ - Good: "The form contains: Name (text, required, max 100 chars), Email (email format,
252
+ required), Role (dropdown: Admin/Editor/Viewer, default: Viewer)"
253
+
254
+ 5. **Exact error handling** — What happens when things go wrong?
255
+ - Bad: "Show an error" → What error? Where? What message?
256
+ - Good: "Display inline validation error below the Email field: 'Please enter a valid
257
+ email address' in red (#DC3545), field border turns red"
258
+
259
+ 6. **Exact edge cases** — What happens at boundaries?
260
+ - What if the list is empty? What placeholder is shown?
261
+ - What if the input is at max length? What happens at max+1?
262
+ - What if the network request fails? Timeout? 403? 500?
263
+ - What if the user double-clicks? Navigates away mid-operation?
264
+
265
+ **QUESTIONING TECHNIQUES for extracting precision:**
266
+
267
+ - "You said [vague thing]. What does that actually look like on screen?"
268
+ - "Walk me through exactly what happens, step by step, from the user's perspective."
269
+ - "What does the user SEE when this succeeds? What EXACT message, where on the page?"
270
+ - "What if [edge case]? What should happen? What should the user see?"
271
+ - "You mentioned [behavior]. Is that a modal dialog, an inline message, a page redirect, or something else?"
272
+ - "When you say 'update', do you mean replace the entire record, merge specific fields, or append?"
273
+ - "What validation rules apply? Be specific: required/optional, min/max, format, allowed values."
274
+ - "How does the user know this worked? What visual feedback do they get?"
275
+
276
+ **USE AskUserQuestion for specific clarification:**
277
+
278
+ When the user gives a vague answer, present concrete interpretations:
279
+
280
+ ```
281
+ header: "Behavior"
282
+ question: "When the save fails due to network error, what should the user see?"
283
+ options:
284
+ - "Toast notification" — Non-blocking message at top of page
285
+ - "Modal dialog" — Blocking popup requiring acknowledgment
286
+ - "Inline error" — Error message below the form
287
+ - "Let me explain" — Different approach
288
+ ```
289
+
290
+ <!-- ── 4c: Template-field coverage (background checklist) ────── -->
291
+
292
+ As you question, mentally track coverage against story.xml template sections:
293
+ - [ ] **User Story** — As/I want/So that (persona must match vision if available)
294
+ - [ ] **Description** — 2-4 sentences of observable user behavior and feature context
295
+ - [ ] **Acceptance Criteria** — ALL scenarios with EXACT Given/When/Then
296
+ - [ ] Happy path(s) — main success scenario(s)
297
+ - [ ] Edge cases — boundary conditions, empty states, max limits
298
+ - [ ] Error paths — validation failures, network errors, permission issues
299
+ - [ ] Each scenario: EXACT trigger, EXACT precondition, EXACT outcome
300
+ - [ ] **Out of Scope** — Things someone might assume are included but are NOT
301
+ - [ ] **Dependencies** — Blocked by, Blocks, External
302
+ - [ ] **Definition of Done** — Any story-specific additions to the default checklist
303
+ - [ ] **Size** — Fibonacci estimate (1, 2, 3, 5, 8)
304
+
305
+ Don't walk through this as a checklist. Weave questions naturally.
306
+ When gaps remain after conversation feels complete, probe those areas.
307
+
308
+ <!-- ── 4d: AC Scenario crafting ──────────────────────────────── -->
309
+
310
+ Once you have enough context, draft the Gherkin scenarios:
311
+
312
+ Present each scenario and VALIDATE with the user:
313
+
314
+ ```
315
+ Here's what I have so far:
316
+
317
+ ### Scenario: Successful settings save
318
+ **Given** an admin user is on the Settings page with unsaved changes
319
+ **When** they click the "Save Settings" button
320
+ **Then** a success toast appears with message "Settings saved successfully"
321
+ **And** the updated values are reflected on the page without refresh
322
+ **And** the "Save Settings" button becomes disabled (no unsaved changes)
323
+
324
+ ### Scenario: Validation failure — invalid email
325
+ **Given** an admin user is on the Settings page
326
+ **When** they enter "not-an-email" in the Contact Email field and click "Save Settings"
327
+ **Then** the Contact Email field border turns red
328
+ **And** an inline error appears below the field: "Please enter a valid email address"
329
+ **And** the form is NOT submitted
330
+ **And** focus moves to the Contact Email field
331
+
332
+ Does this capture the behavior correctly? Anything missing or wrong?
333
+ ```
334
+
335
+ Use AskUserQuestion:
336
+ - header: "Scenarios"
337
+ - question: "Review the acceptance criteria scenarios above. Are they correct and complete?"
338
+ - options:
339
+ - "Looks good" — Scenarios are accurate and complete
340
+ - "Fix a scenario" — Something is wrong or missing in a scenario
341
+ - "Add a scenario" — There's a case I haven't mentioned
342
+ - "Too many" — Some scenarios should be removed or combined
343
+
344
+ Loop until the user confirms all scenarios are correct.
345
+
346
+ **CRITICAL: Scenario count check.**
347
+ If more than 6-8 scenarios are needed, the story is likely too large:
348
+ ```
349
+ ! This story has {N} scenarios, which suggests it may be too large.
350
+ Stories with more than 6-8 scenarios should usually be split.
351
+ ```
352
+
353
+ Use AskUserQuestion:
354
+ - header: "Story size"
355
+ - question: "This story has {N} acceptance criteria. Should we split it?"
356
+ - options:
357
+ - "Keep as-is" — The story is coherent and should not be split
358
+ - "Split it" — Let's break this into smaller stories
359
+
360
+ If "Split it": discuss the split, identify natural cut points, and restart
361
+ questioning for the reduced-scope story.
362
+
363
+ <!-- ── 4e: Decision gate ─────────────────────────────────────── -->
364
+
365
+ When story specification feels complete:
366
+
367
+ Use AskUserQuestion:
368
+ - header: "Ready?"
369
+ - question: "I have the full story spec: {N} acceptance criteria, size {estimate}. Ready to write the story document?"
370
+ - options:
371
+ - "Write story document" — Create the specification
372
+ - "Keep exploring" — I want to add or change something
373
+ - "Show summary" — Show me what you have before deciding
374
+
375
+ If "Show summary":
376
+ ```
377
+ Story: {ID} — {Title}
378
+ Feature: {Feature ID} — {Feature Title}
379
+
380
+ User Story:
381
+ > As a [persona], I want [action], so that [benefit].
382
+
383
+ Description: {2-4 sentences}
384
+
385
+ Acceptance Criteria: {N} scenarios
386
+ 1. {scenario name} — {one-line summary}
387
+ 2. {scenario name} — {one-line summary}
388
+ ...
389
+
390
+ Out of Scope: {M} items
391
+ Size: {estimate}
392
+ ```
393
+ Return to decision gate.
394
+
395
+ If "Keep exploring" — ask what they want to add or identify gaps.
396
+ Loop until "Write story document" selected.
397
+ </step>
398
+
399
+ <!-- ══════════════════════════════════════════════════════════════════ -->
400
+ <!-- STEP 5: WRITE STORY DOCUMENT (Pass 1) -->
401
+ <!-- ══════════════════════════════════════════════════════════════════ -->
402
+
403
+ <step name="write-story" order="5">
404
+
405
+ Display:
406
+ ```
407
+ ┌──────────────────────────────────────────────────┐
408
+ │ ACE > Plan Story > Writing Document (Pass 1) │
409
+ └──────────────────────────────────────────────────┘
410
+
411
+ i Writing story specification...
412
+ Output: {STORY_FILE}
413
+ ```
414
+
415
+ Create directory structure:
416
+ ```bash
417
+ mkdir -p {INIT.paths.story_dir}
418
+ ```
419
+
420
+ Prepare the full story document following the story.xml template EXACTLY.
421
+ Include ALL sections 1-8:
422
+ - **Header**: Story ID, Title, Feature reference, Epic reference, Status=Refined,
423
+ Size, Sprint=—, Link
424
+ - **User Story**: As/I want/So that format
425
+ - **Description**: 2-4 sentences of observable behavior and feature context
426
+ - **Acceptance Criteria**: ALL Gherkin scenarios from questioning
427
+ - **Out of Scope**: Explicit exclusions
428
+ - **Dependencies**: Blocked By, Blocks, External
429
+ - **Definition of Done**: Standard checklist + any story-specific items
430
+ - **Relevant Wiki**: Placeholder — `&lt;!-- Pass 2. Populated by research-story-wiki. --&gt;`
431
+ - **Technical Solution**: Placeholder — `&lt;!-- Pass 5. Populated by research-technical-solution. --&gt;`
432
+ - **Metadata**: Created date, Last refined date, Refinements count, Feature path
433
+
434
+ Write the file using the Write tool to `{INIT.paths.story_file}`.
435
+
436
+ **If RUN_MODE is REFINE:**
437
+ Increment the metadata refinement count and update "Last refined" date.
438
+ Preserve any existing Relevant Wiki or Technical Solution sections.
439
+
440
+ Display:
441
+ ```
442
+ + Story specification written to {INIT.paths.story_file}
443
+ Sections 1-8 complete. {N} acceptance criteria scenarios.
444
+ ```
445
+ </step>
446
+
447
+ <!-- ══════════════════════════════════════════════════════════════════ -->
448
+ <!-- STEP 6: REVIEW AND APPROVE (Pass 1) -->
449
+ <!-- ══════════════════════════════════════════════════════════════════ -->
450
+
451
+ <step name="review-pass1" order="6">
452
+
453
+ Use AskUserQuestion:
454
+ - header: "Story"
455
+ - question: "Story specification written to `{INIT.paths.story_file}`. Review the file in your editor. Does it look right?"
456
+ - options:
457
+ - "Approve" — Looks good, proceed to research passes
458
+ - "Adjust" — I want to change some things
459
+ - "Redo questioning" — Let's go back and explore more
460
+
461
+ **If "Adjust":**
462
+ - Ask what needs changing
463
+ - Apply edits using the Edit tool directly on `{INIT.paths.story_file}`
464
+ - Present for review again. Loop until approved.
465
+
466
+ **If "Redo questioning":**
467
+ - Return to step 4 (deep-questioning)
468
+ - Preserve FEATURE_CONTEXT, VISION, BACKLOG_CONTEXT
469
+ - Hold previous answers as additional context
470
+
471
+ **If "Approve":**
472
+ Continue to step 7.
473
+ </step>
474
+
475
+ <!-- ══════════════════════════════════════════════════════════════════ -->
476
+ <!-- STEP 7: DISPATCH RESEARCH PASSES (2-5) -->
477
+ <!-- ══════════════════════════════════════════════════════════════════ -->
478
+
479
+ <step name="dispatch-research" order="7">
480
+
481
+ Display:
482
+ ```
483
+ ┌──────────────────────────────────────────────────┐
484
+ │ ACE > Plan Story > Research Passes │
485
+ └──────────────────────────────────────────────────┘
486
+
487
+ i Story requirements complete. Dispatching research passes...
488
+ ```
489
+
490
+ <!-- ── 7a: Offer external analysis (Pass 3 — OPTIONAL) ──────── -->
491
+
492
+ **If `EXTERNAL_CODEBASE` was provided as parameter:**
493
+ Set `RUN_EXTERNAL = true`.
494
+
495
+ **If `EXTERNAL_CODEBASE` was NOT provided:**
496
+
497
+ Use AskUserQuestion:
498
+ - header: "External"
499
+ - question: "Does this story reference an external system or reference implementation you'd like to analyze?"
500
+ - options:
501
+ - "No external system" — Skip external analysis
502
+ - "Yes, provide path" — I have an external codebase to analyze
503
+
504
+ If "Yes, provide path":
505
+ Ask for the external-codebase path (and optionally external-docs).
506
+ Set `EXTERNAL_CODEBASE` and `EXTERNAL_DOCS` from user response.
507
+ Set `RUN_EXTERNAL = true`.
508
+
509
+ If "No external system":
510
+ Set `RUN_EXTERNAL = false`.
511
+
512
+ <!-- ── 7b: Dispatch Pass 2 — Wiki Research ──────────────────── -->
513
+
514
+ **If `has_wiki` is false:** Skip pass 2. Display:
515
+ ```
516
+ i No wiki found. Skipping pass 2 (wiki research).
517
+ ```
518
+
519
+ **If `has_wiki` is true:**
520
+
521
+ Display:
522
+ ```
523
+ i Pass 2: Dispatching wiki research...
524
+ Agent will update story file with Relevant Wiki section.
525
+ ```
526
+
527
+ **CRITICAL — Context Window Protection:**
528
+ The agent writes to the story file and returns ONLY a ~10-line confirmation.
529
+ This prevents agent output from inflating the main context window.
530
+
531
+ **CRITICAL — Do NOT call TaskOutput. NEVER. UNDER NO CIRCUMSTANCES.**
532
+ After spawning the background agent, do NOT call TaskOutput to read its results.
533
+ You will be automatically notified when the agent completes — IGNORE those notifications.
534
+ The agent writes directly to the story file on disk. You do not need the return message.
535
+ TaskOutput returns the agent's FULL internal transcript (every file read, every search,
536
+ every tool call) — calling it will inflate the context window by 10-20%. THIS IS FORBIDDEN.
537
+ After the notification arrives, verify the file with `wc -l`, then READ the file
538
+ directly from disk using the Read tool if needed. That is how you get the results.
539
+
540
+ Spawn background agent:
541
+ ```
542
+ Agent(
543
+ prompt="/ace:research-story-wiki story={INIT.paths.story_file}
544
+
545
+ Execute the research-story-wiki workflow end-to-end.
546
+ Write the Relevant Wiki section directly into the story file.
547
+
548
+ **Return format — ONLY this, nothing else:**
549
+ DONE
550
+ - Story: {story ID} — {story title}
551
+ - Wiki refs: {count} total ({system_wide} system-wide + {subsystem} subsystem)
552
+ - File updated: {story file path}",
553
+ subagent_type="ace-wiki-mapper",
554
+ model="{PO_MODEL}",
555
+ run_in_background=true,
556
+ description="Pass 2: Wiki research"
557
+ )
558
+ ```
559
+
560
+ Store the agent task ID as `PASS2_TASK`.
561
+
562
+ **After background notification arrives — IGNORE it:**
563
+
564
+ Do NOT call TaskOutput. Do NOT call TaskOutput. Do NOT call TaskOutput.
565
+ Just verify the file and read it directly from disk if needed.
566
+
567
+ <!-- ── 7c: Dispatch Pass 3 — External Analysis (OPTIONAL) ───── -->
568
+
569
+ **If `RUN_EXTERNAL` is false:** Skip pass 3.
570
+
571
+ **If `RUN_EXTERNAL` is true:**
572
+
573
+ Display:
574
+ ```
575
+ i Pass 3: Dispatching external analysis...
576
+ Agent will create external-analysis.md in story directory.
577
+ ```
578
+
579
+ **CRITICAL — Context Window Protection:**
580
+ The agent writes to a separate file and returns ONLY a ~10-line confirmation.
581
+ This prevents agent output from inflating the main context window.
582
+
583
+ **CRITICAL — Do NOT call TaskOutput. NEVER. UNDER NO CIRCUMSTANCES.**
584
+ After spawning the background agent, do NOT call TaskOutput to read its results.
585
+ You will be automatically notified when the agent completes — IGNORE those notifications.
586
+ The agent writes to `{INIT.paths.external_analysis_file}` on disk. You do not need the return message.
587
+ TaskOutput returns the agent's FULL internal transcript (every file read, every search,
588
+ every tool call) — calling it will inflate the context window by 10-20%. THIS IS FORBIDDEN.
589
+
590
+ Spawn background agent:
591
+ ```
592
+ Agent(
593
+ prompt="/ace:research-external-solution story={INIT.paths.story_file} external-codebase={EXTERNAL_CODEBASE} {external-docs={EXTERNAL_DOCS} if provided}
594
+
595
+ Execute the research-external-solution workflow end-to-end.
596
+ Write the output to {INIT.paths.external_analysis_file}.
597
+
598
+ **Return format — ONLY this, nothing else:**
599
+ DONE
600
+ - Story: {story ID} — {story title}
601
+ - External files analyzed: {count}
602
+ - Output: {external analysis file path}",
603
+ subagent_type="ace-code-discovery-analyst",
604
+ model="{PO_MODEL}",
605
+ run_in_background=true,
606
+ description="Pass 3: External analysis"
607
+ )
608
+ ```
609
+
610
+ Store the agent task ID as `PASS3_TASK`.
611
+
612
+ **After background notification arrives — IGNORE it:**
613
+
614
+ Do NOT call TaskOutput. Do NOT call TaskOutput. Do NOT call TaskOutput.
615
+ Just verify the file and read it directly from disk if needed.
616
+
617
+ <!-- ── 7d: Wait for passes 2 (and 3 if running) before pass 4 ── -->
618
+
619
+ Display:
620
+ ```
621
+ i Waiting for pass 2{" and pass 3" if RUN_EXTERNAL} to complete
622
+ before dispatching integration analysis (pass 4)...
623
+ ```
624
+
625
+ **Wait for PASS2_TASK notification** (and PASS3_TASK if running).
626
+ Do NOT call TaskOutput. Do NOT call TaskOutput. Do NOT call TaskOutput.
627
+ Just wait for the background notifications.
628
+
629
+ After notifications arrive, verify the outputs exist:
630
+ ```bash
631
+ wc -l {INIT.paths.story_file}
632
+ ```
633
+ If RUN_EXTERNAL:
634
+ ```bash
635
+ wc -l {INIT.paths.external_analysis_file}
636
+ ```
637
+
638
+ Display:
639
+ ```
640
+ + Pass 2 complete. Story file updated with Relevant Wiki section.
641
+ {+ Pass 3 complete. External analysis written. (if applicable)}
642
+ ```
643
+
644
+ <!-- ── 7e: Dispatch Pass 4 — Integration Analysis ───────────── -->
645
+
646
+ Display:
647
+ ```
648
+ i Pass 4: Dispatching integration analysis...
649
+ Agent will create integration-analysis.md in story directory.
650
+ ```
651
+
652
+ **CRITICAL — Context Window Protection:**
653
+ The agent writes to a separate file and returns ONLY a ~10-line confirmation.
654
+ This prevents agent output from inflating the main context window.
655
+
656
+ **CRITICAL — Do NOT call TaskOutput. NEVER. UNDER NO CIRCUMSTANCES.**
657
+ After spawning the background agent, do NOT call TaskOutput to read its results.
658
+ You will be automatically notified when the agent completes — IGNORE those notifications.
659
+ The agent writes to `{INIT.paths.integration_analysis_file}` on disk. You do not need the return message.
660
+ TaskOutput returns the agent's FULL internal transcript (every file read, every search,
661
+ every tool call) — calling it will inflate the context window by 10-20%. THIS IS FORBIDDEN.
662
+
663
+ Spawn background agent:
664
+ ```
665
+ Agent(
666
+ prompt="/ace:research-integration-solution story={INIT.paths.story_file}
667
+
668
+ Execute the research-integration-solution workflow end-to-end.
669
+ Write the output to {INIT.paths.integration_analysis_file}.
670
+ The story file now has the Relevant Wiki section (pass 2 complete).
671
+ {If external analysis exists: The external-analysis.md file exists in the story directory.}
672
+
673
+ **Return format — ONLY this, nothing else:**
674
+ DONE
675
+ - Story: {story ID} — {story title}
676
+ - Integration points found: {count}
677
+ - Output: {integration analysis file path}",
678
+ subagent_type="ace-code-integration-analyst",
679
+ model="{PO_MODEL}",
680
+ run_in_background=true,
681
+ description="Pass 4: Integration analysis"
682
+ )
683
+ ```
684
+
685
+ Store the agent task ID as `PASS4_TASK`.
686
+
687
+ **After background notification arrives — IGNORE it:**
688
+
689
+ Do NOT call TaskOutput. Do NOT call TaskOutput. Do NOT call TaskOutput.
690
+ Just verify the file and read it directly from disk if needed.
691
+
692
+ <!-- ── 7f: Wait for pass 4 before pass 5 ────────────────────── -->
693
+
694
+ **Wait for PASS4_TASK notification.**
695
+ Do NOT call TaskOutput. Do NOT call TaskOutput. Do NOT call TaskOutput.
696
+
697
+ After notification arrives, verify:
698
+ ```bash
699
+ wc -l {INIT.paths.integration_analysis_file}
700
+ ```
701
+
702
+ Display:
703
+ ```
704
+ + Pass 4 complete. Integration analysis written.
705
+ ```
706
+
707
+ <!-- ── 7g: Dispatch Pass 5 — Technical Solution ─────────────── -->
708
+
709
+ Display:
710
+ ```
711
+ i Pass 5: Dispatching technical solution design...
712
+ Agent will append Technical Solution to story file.
713
+ ```
714
+
715
+ **CRITICAL — Context Window Protection:**
716
+ The agent writes directly into the story file and returns ONLY a ~10-line confirmation.
717
+ This prevents agent output from inflating the main context window.
718
+
719
+ **CRITICAL — Do NOT call TaskOutput. NEVER. UNDER NO CIRCUMSTANCES.**
720
+ After spawning the background agent, do NOT call TaskOutput to read its results.
721
+ You will be automatically notified when the agent completes — IGNORE those notifications.
722
+ The agent writes directly to the story file on disk. You do not need the return message.
723
+ TaskOutput returns the agent's FULL internal transcript (every file read, every search,
724
+ every tool call) — calling it will inflate the context window by 10-20%. THIS IS FORBIDDEN.
725
+
726
+ Spawn background agent:
727
+ ```
728
+ Agent(
729
+ prompt="/ace:research-technical-solution story={INIT.paths.story_file}
730
+
731
+ Execute the research-technical-solution workflow end-to-end.
732
+ The story file has the full requirements + Relevant Wiki section.
733
+ The integration-analysis.md exists in the story directory.
734
+ {If external analysis exists: The external-analysis.md exists in the story directory.}
735
+ Append the Technical Solution section to the story file.
736
+
737
+ **Return format — ONLY this, nothing else:**
738
+ DONE
739
+ - Story: {story ID} — {story title}
740
+ - Components designed: {count}
741
+ - Sequence diagrams: {count}
742
+ - Story file updated: {story file path}",
743
+ subagent_type="ace-technical-application-architect",
744
+ model="{PO_MODEL}",
745
+ run_in_background=true,
746
+ description="Pass 5: Technical solution"
747
+ )
748
+ ```
749
+
750
+ Store the agent task ID as `PASS5_TASK`.
751
+
752
+ **After background notification arrives — IGNORE it:**
753
+
754
+ Do NOT call TaskOutput. Do NOT call TaskOutput. Do NOT call TaskOutput.
755
+ Just verify the file and read it directly from disk if needed.
756
+
757
+ <!-- ── 7h: Wait for pass 5 ──────────────────────────────────── -->
758
+
759
+ **Wait for PASS5_TASK notification.**
760
+ Do NOT call TaskOutput. Do NOT call TaskOutput. Do NOT call TaskOutput.
761
+
762
+ After notification arrives, verify:
763
+ ```bash
764
+ wc -l {INIT.paths.story_file}
765
+ ```
766
+
767
+ Display:
768
+ ```
769
+ + Pass 5 complete. Technical solution appended to story file.
770
+ ```
771
+ </step>
772
+
773
+ <!-- ══════════════════════════════════════════════════════════════════ -->
774
+ <!-- STEP 8: STATE UPDATES -->
775
+ <!-- ══════════════════════════════════════════════════════════════════ -->
776
+
777
+ <step name="state-updates" order="8">
778
+
779
+ <substep order="8.1" name="update-state-via-tools">
780
+ ```bash
781
+ node ~/.claude/agile-context-engineering/src/ace-tools.js story update-state \
782
+ story={INIT.paths.story_file} \
783
+ status=Refined
784
+ ```
785
+
786
+ Parse result for: `story_updated`, `feature_updated`, `backlog_updated`.
787
+
788
+ ```
789
+ + Story status updated to Refined
790
+ {+ Feature file updated (if feature_updated)}
791
+ {+ Product backlog updated (if backlog_updated)}
792
+ ```
793
+ </substep>
794
+
795
+ Continue to step 9.
796
+ </step>
797
+
798
+ <!-- ══════════════════════════════════════════════════════════════════ -->
799
+ <!-- STEP 9: GITHUB SYNC -->
800
+ <!-- ══════════════════════════════════════════════════════════════════ -->
801
+
802
+ <step name="github-sync" order="9">
803
+
804
+ <variant condition="INIT.github_project.enabled is false OR INIT.has_gh_cli is false">
805
+ ```
806
+ — GitHub sync skipped (not configured or gh CLI unavailable).
807
+ ```
808
+ Continue to step 10.
809
+ </variant>
810
+
811
+ <variant condition="INIT.github_project.enabled is true AND INIT.has_gh_cli is true">
812
+ Sync story and feature GitHub issues in a single call.
813
+ This command prints status lines directly to the console (stderr)
814
+ so the user ALWAYS sees whether each issue was updated or not.
815
+
816
+ ```bash
817
+ node ~/.claude/agile-context-engineering/src/ace-tools.js github sync-story \
818
+ repo={INIT.github_project.repo} \
819
+ story_file={INIT.paths.story_file} \
820
+ feature_file={INIT.paths.feature_file} \
821
+ owner={INIT.github_project.owner} \
822
+ project={INIT.github_project.project_number}
823
+ ```
824
+
825
+ The command handles all cases:
826
+ - Story/feature has no GitHub issue linked → prints skip message
827
+ - Update succeeds → prints success message with issue number
828
+ - Update fails → prints error message with details
829
+
830
+ Continue to step 10.
831
+ </variant>
832
+ </step>
833
+
834
+ <!-- ══════════════════════════════════════════════════════════════════ -->
835
+ <!-- STEP 10: COMMIT -->
836
+ <!-- ══════════════════════════════════════════════════════════════════ -->
837
+
838
+ <step name="commit" order="10">
839
+
840
+ **If `commit_docs` is false:** Skip commit.
841
+
842
+ Stage all changed/created files:
843
+ ```bash
844
+ git add {INIT.paths.story_dir}/
845
+ git add {INIT.paths.feature_file} .ace/artifacts/product/product-backlog.md
846
+ ```
847
+
848
+ Commit with descriptive message:
849
+ - CREATE mode: `git commit -m "docs: plan story {Story ID} — {Story Title}"`
850
+ - REFINE mode: `git commit -m "docs: refine story {Story ID} — {brief summary of changes}"`
851
+
852
+ Display completion:
853
+
854
+ ```
855
+ ╔══════════════════════════════════════════════════╗
856
+ ║ ACE > Story [Planned | Refined] ║
857
+ ║ {Story ID} "{Story Title}" ║
858
+ ╚══════════════════════════════════════════════════╝
859
+
860
+ + Story specification complete. All passes finished.
861
+
862
+ Artifacts:
863
+ ────────
864
+ Story file: {INIT.paths.story_file}
865
+ {External analysis: {INIT.paths.external_analysis_file} (if created)}
866
+ Integration analysis: {INIT.paths.integration_analysis_file}
867
+
868
+ Summary:
869
+ ────────
870
+ Acceptance criteria: {N} scenarios
871
+ Size: {estimate}
872
+ Passes completed: {2-5 count}
873
+
874
+ Next > /ace:execute-story story={INIT.paths.story_file}
875
+ Execute the story implementation.
876
+ > /ace:plan-story story={next story}
877
+ Plan the next story in the feature.
878
+ ```
879
+ </step>
880
+
881
+ </process>
882
+
883
+ <success_criteria>
884
+ - Init function executed (environment detected, story validated, paths computed)
885
+ - Story seed loaded and parsed (title, description, images validated)
886
+ - CREATE vs REFINE mode correctly determined
887
+ - Feature context loaded (parent feature document, if available)
888
+ - Deep questioning conducted with ZERO-ASSUMPTION mandate
889
+ - Every acceptance criterion has EXACT trigger, precondition, outcome, data, error handling
890
+ - No vague terms remain ("it works", "shows error", "updates data" — all must be specific)
891
+ - All Gherkin scenarios follow Given/When/Then format correctly
892
+ - Scenarios are independent — no scenario depends on another's state
893
+ - Minimum coverage: happy path + edge case + error path
894
+ - Story passes INVEST checklist
895
+ - Story size is Fibonacci (1, 2, 3, 5, 8) — split if > 8 or > 6-8 scenarios
896
+ - Story document written following story.xml template exactly (sections 1-8)
897
+ - User reviewed and approved pass 1 output
898
+ - Pass 2 (wiki research) dispatched as background agent, wrote to story file
899
+ - Pass 3 (external analysis) offered/dispatched if external-codebase provided
900
+ - Pass 4 (integration analysis) dispatched AFTER passes 2-3 complete
901
+ - Pass 5 (technical solution) dispatched AFTER pass 4 complete
902
+ - NO TaskOutput called on ANY background agent — context window stays clean
903
+ - Each background agent wrote output directly to disk (story file or separate artifact)
904
+ - Story status updated to Refined via ace-tools (story file, feature file, product backlog)
905
+ - GitHub issue updated (if applicable)
906
+ - All artifacts committed with descriptive message (story dir + feature file + backlog)
907
+ </success_criteria>
908
+
909
+ </workflow>