agile-context-engineering 0.2.2 → 0.3.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 (51) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/LICENSE +51 -51
  3. package/README.md +324 -323
  4. package/agents/ace-research-synthesizer.md +228 -228
  5. package/agents/ace-technical-application-architect.md +28 -0
  6. package/agents/ace-wiki-mapper.md +445 -334
  7. package/agile-context-engineering/src/ace-tools.test.js +1089 -1089
  8. package/agile-context-engineering/templates/_command.md +53 -53
  9. package/agile-context-engineering/templates/_workflow.xml +16 -16
  10. package/agile-context-engineering/templates/product/product-backlog.xml +231 -231
  11. package/agile-context-engineering/templates/product/story-integration-solution.xml +1 -0
  12. package/agile-context-engineering/templates/product/story-wiki.xml +4 -0
  13. package/agile-context-engineering/templates/wiki/coding-standards.xml +38 -0
  14. package/agile-context-engineering/templates/wiki/decizions.xml +115 -115
  15. package/agile-context-engineering/templates/wiki/guide.xml +137 -137
  16. package/agile-context-engineering/templates/wiki/module-discovery.xml +174 -174
  17. package/agile-context-engineering/templates/wiki/pattern.xml +159 -159
  18. package/agile-context-engineering/templates/wiki/system-architecture.xml +254 -254
  19. package/agile-context-engineering/templates/wiki/system-cross-cutting.xml +197 -197
  20. package/agile-context-engineering/templates/wiki/system.xml +381 -381
  21. package/agile-context-engineering/templates/wiki/walkthrough.xml +255 -0
  22. package/agile-context-engineering/templates/wiki/wiki-readme.xml +297 -276
  23. package/agile-context-engineering/utils/questioning.xml +110 -110
  24. package/agile-context-engineering/workflows/execute-story.xml +1219 -1145
  25. package/agile-context-engineering/workflows/help.xml +540 -540
  26. package/agile-context-engineering/workflows/init-coding-standards.xml +386 -386
  27. package/agile-context-engineering/workflows/map-story.xml +1046 -797
  28. package/agile-context-engineering/workflows/map-subsystem.xml +2 -1
  29. package/agile-context-engineering/workflows/map-walkthrough.xml +457 -0
  30. package/agile-context-engineering/workflows/plan-feature.xml +1495 -1495
  31. package/agile-context-engineering/workflows/plan-story.xml +36 -1
  32. package/agile-context-engineering/workflows/research-integration-solution.xml +1 -0
  33. package/agile-context-engineering/workflows/research-story-wiki.xml +2 -1
  34. package/agile-context-engineering/workflows/research-technical-solution.xml +1 -0
  35. package/agile-context-engineering/workflows/review-story.xml +281 -281
  36. package/agile-context-engineering/workflows/update.xml +238 -207
  37. package/bin/install.js +8 -0
  38. package/commands/ace/execute-story.md +1 -0
  39. package/commands/ace/help.md +93 -93
  40. package/commands/ace/init-coding-standards.md +83 -83
  41. package/commands/ace/map-story.md +165 -156
  42. package/commands/ace/map-subsystem.md +140 -138
  43. package/commands/ace/map-system.md +92 -92
  44. package/commands/ace/map-walkthrough.md +127 -0
  45. package/commands/ace/plan-feature.md +89 -89
  46. package/commands/ace/plan-story.md +15 -1
  47. package/commands/ace/review-story.md +109 -109
  48. package/commands/ace/update.md +56 -54
  49. package/hooks/ace-check-update.js +62 -62
  50. package/hooks/ace-statusline.js +89 -89
  51. package/package.json +4 -3
@@ -1,797 +1,1046 @@
1
- <workflow>
2
-
3
- <purpose>
4
- Orchestrate living knowledge documentation: analyze what was built (story mode) or what
5
- exists (file mode), then create or update topic-scoped documents in
6
- `.docs/wiki/subsystems/[subsystem-name]/`.
7
-
8
- Produces documents across five categories:
9
- - systems/ — WHAT exists (domain subsystems and their current state)
10
- - patterns/ — HOW things work (reusable implementation patterns)
11
- - cross-cutting/ — concerns spanning multiple systems
12
- - guides/ — step-by-step recipes for common implementation tasks
13
- - decisions/ WHY significant choices were made (ADRs)
14
-
15
- Two input modes that converge into ONE execution flow:
16
- - **Story mode** (user-invoked): Analyzes git changes after story implementation,
17
- detects affected subsystem(s), spawns one agent per subsystem.
18
- - **File mode** (invoked by map-subsystem step 8.7): Receives a file list for one
19
- module in one subsystem, spawns one agent for that subsystem.
20
-
21
- Both modes produce the same output: `{ subsystem: files }` map fed to per-subsystem
22
- agents. The agents are identical regardless of mode they read all source files,
23
- read ALL existing wiki docs, and make thorough create-vs-update decisions.
24
- </purpose>
25
-
26
- <mandatory-context>
27
- The orchestrator reads ONLY this workflow — it stays lightweight.
28
- Each sub-agent reads the five document templates itself before writing.
29
- Also read any parameters passed as $ARGUMENTS in the invoking command.
30
- </mandatory-context>
31
-
32
- <process>
33
-
34
- <!-- ══════════════════════════════════════════════════════════════════ -->
35
- <!-- STEP 1: SETUP AND MODE DETECTION -->
36
- <!-- ══════════════════════════════════════════════════════════════════ -->
37
-
38
- <step name="setup" order="1">
39
-
40
- <substep order="1.1" name="detect-mode">
41
- Parse $ARGUMENTS to determine execution mode:
42
-
43
- <mode-rules>
44
- <rule condition="files parameter provided" result="file mode" />
45
- <rule condition="story-context parameter provided" result="story mode" />
46
- <rule condition="neither parameter provided" result="story mode (analyze staged + unstaged changes)" />
47
- </mode-rules>
48
- </substep>
49
-
50
- <substep order="1.2" name="parse-parameters">
51
- <parameters mode="story">
52
- <param name="story-context" required="false" type="path">Path to story artifacts folder</param>
53
- <param name="commits" required="false" type="string">Number of recent commits OR comma-separated SHAs</param>
54
- <param name="tech-debt" required="false" type="text|path">Tech debt from code review. Plain text, YAML, or file path.</param>
55
- </parameters>
56
-
57
- <parameters mode="file">
58
- <param name="files" required="true" type="csv">Comma-separated source file paths</param>
59
- <param name="module-name" required="true" type="string">Human-readable module name</param>
60
- <param name="subsystem-name" required="true" type="string">Subsystem this module belongs to</param>
61
- <param name="existing-docs" required="false" type="csv">Comma-separated file paths and/or directory paths to pre-existing documentation</param>
62
- <param name="existing-docs-inventory" required="false" type="path">Path to a pre-built inventory file (existing-docs-inventory.md) that indexes a large doc directory. When provided, the curation agent reads this inventory instead of re-scanning the directory.</param>
63
- </parameters>
64
- </substep>
65
-
66
- <substep order="1.3" name="display-banner">
67
- Display stage banner:
68
-
69
- ```
70
- ┌──────────────────────────────────────────────────┐
71
- │ ACE > Map Story > [story mode | file mode] │
72
- └──────────────────────────────────────────────────┘
73
- ```
74
- </substep>
75
-
76
- Continue to step 2.
77
- </step>
78
-
79
- <!-- ══════════════════════════════════════════════════════════════════ -->
80
- <!-- STEP 2: BUILD SUBSYSTEM WORK MAP -->
81
- <!-- -->
82
- <!-- This is the ONLY step that differs by mode. -->
83
- <!-- Both modes produce the same output: a subsystem_work map. -->
84
- <!-- ══════════════════════════════════════════════════════════════════ -->
85
-
86
- <step name="build-work-map" order="2">
87
-
88
- <output-schema>
89
- ```
90
- subsystem_work = {
91
- "[subsystem-name]": {
92
- "files": [list of source file paths],
93
- "file_statuses": { "path": "A|M|D" }, // story mode only
94
- "story_summary": "...", // story mode only
95
- "tech_debt_items": [...] // story mode only, if tech-debt provided
96
- "module_name": "...", // file mode only
97
- "existing_docs": [...] // file mode only, if provided
98
- }
99
- }
100
- ```
101
- </output-schema>
102
-
103
- <!-- ── Story Mode ─────────────────────────────────────────────── -->
104
-
105
- <mode name="story">
106
-
107
- <substep order="2a" name="collect-changes">
108
- Collect changed file names and statuses.
109
-
110
- Determine the diff range:
111
-
112
- <variant condition="commits is a number N">
113
- ```bash
114
- git log --name-status -n [N]
115
- git diff --name-status HEAD~[N]..HEAD
116
- ```
117
- </variant>
118
-
119
- <variant condition="commits is comma-separated SHAs">
120
- ```bash
121
- git log --name-status [first-sha]^..[last-sha]
122
- git diff --name-status [first-sha]^..[last-sha]
123
- ```
124
- </variant>
125
-
126
- <variant condition="commits not provided">
127
- ```bash
128
- git diff --name-status
129
- git diff --name-status --cached
130
- ```
131
- </variant>
132
-
133
- Collect every changed file with its status (A = added, M = modified, D = deleted).
134
- </substep>
135
-
136
- <substep order="2b" name="group-by-subsystem">
137
- Map each changed file path to its subsystem:
138
-
139
- <mapping-rules>
140
- <rule path="src/Qarc/Web/qarc-charts-v2/" subsystem="qarc-charts-v2" />
141
- <rule path="src/Qarc/Web/qarc-workspace/" subsystem="qarc-workspace" />
142
- <rule path="src/Qarc/Web/qarc-web/" subsystem="qarc-web" />
143
- <rule path="src/Qarc/Engine/" subsystem="engine" />
144
- <rule path="src/Qarc/DataIngestion/" subsystem="data-ingestion" />
145
- <rule path="src/Qarc/DataStreaming/" subsystem="data-streaming" />
146
- <rule path="src/Qarc/ChartManagement/" subsystem="chart-management" />
147
- <rule path="src/Qarc/Gateway/" subsystem="gateway" />
148
- <rule path="src/Qarc/[ServiceName]/" subsystem="[service-name] (kebab-case)" />
149
- <rule path="outside src/Qarc/" subsystem="skip" />
150
- </mapping-rules>
151
-
152
- Build one entry per subsystem in `subsystem_work`.
153
- </substep>
154
-
155
- <substep order="2c" name="read-story-context">
156
- Read story context (if provided) and produce a brief summary.
157
-
158
- <variant condition="story-context parameter was provided">
159
- <task-list>
160
- <task>Read all markdown files in the story artifacts folder</task>
161
- <task>Extract a summary (10-15 lines max): what the story intended, key acceptance
162
- criteria, significant decisions mentioned</task>
163
- <task>Attach the same summary to every subsystem entry (shared intent context)</task>
164
- </task-list>
165
- NOTE: The implementation may deviate from the plan — agents document
166
- what WAS built, not what was planned.
167
- </variant>
168
-
169
- <variant condition="no story-context">
170
- Set story_summary = "No story artifacts. Document from code changes."
171
- </variant>
172
-
173
- Display to user:
174
- ```
175
- Affected subsystems:
176
- - [subsystem] ([N] files changed)
177
- - [subsystem] ([M] files changed)
178
- ```
179
- </substep>
180
-
181
- <substep order="2d" name="distribute-tech-debt">
182
- <variant condition="tech-debt parameter was provided">
183
- Parse the tech debt input (plain text, YAML, or read from file path).
184
- Each tech debt item has a `file` field use the same subsystem mapping
185
- rules from step 2b to assign each item to its subsystem.
186
- Attach the filtered items to each subsystem entry as `tech_debt_items`.
187
-
188
- Store the full parsed tech debt list as `ALL_TECH_DEBT` for step 4
189
- (tech-debt-index update).
190
-
191
- Display:
192
- ```
193
- i Tech debt: {total_count} items distributed across {subsystem_count} subsystem(s)
194
- ```
195
- </variant>
196
-
197
- <variant condition="no tech-debt parameter">
198
- Skip no tech debt to integrate.
199
- </variant>
200
- </substep>
201
-
202
- </mode>
203
-
204
- <!-- ── File Mode ──────────────────────────────────────────────── -->
205
-
206
- <mode name="file">
207
-
208
- <substep order="2a" name="resolve-existing-docs">
209
- Resolve existing-docs entries.
210
-
211
- Split the `existing-docs` parameter into individual entries. Classify each entry:
212
-
213
- <classification>
214
- <type name="file-path">Keep as-is (already curated by the caller)</type>
215
- <type name="directory-path">Needs curation (may contain hundreds of irrelevant files)</type>
216
- </classification>
217
-
218
- <variant condition="ANY entry is a directory">
219
- Spawn a curation agent to select only relevant docs.
220
- If `existing-docs-inventory` was provided (not `none`), pass it to the agent
221
- so it reads the pre-built inventory instead of re-scanning the directory.
222
-
223
- ```
224
- Task(
225
- prompt="You are a documentation curation agent. Your job is to select ONLY the
226
- documentation files relevant to a specific code module from a large doc directory.
227
-
228
- **Module name:** [module-name param]
229
- **Source files in this module:** [files param]
230
- **Documentation directory:** [directory path]
231
- **Pre-built inventory (if available):** [existing-docs-inventory path, or 'none']
232
-
233
- Process:
234
-
235
- IF a pre-built inventory file was provided (not 'none'):
236
- 1. Read the inventory file — it contains file paths, titles, and summaries
237
- for every doc in the directory, already indexed
238
- 2. Compare each inventory entry against the module's source files and name
239
- 3. Select ONLY entries whose subject matter is relevant to this module
240
- 4. Return the file paths from the selected inventory entries
241
- (Do NOT re-scan the directory the inventory is the source of truth)
242
-
243
- IF no inventory file is available:
244
- 1. Recursively list ALL files in the documentation directory down to every leaf
245
- subdirectory. Use Glob(pattern='**/*', path='[directory path]') to ensure
246
- no nesting level is missed. Do NOT use shallow ls or single-level globs.
247
- 2. For each file, read its title and first 10-20 lines to understand its subject
248
- 3. Compare against the module's source files and module name
249
- 4. Select ONLY files whose subject matter is relevant to this module
250
-
251
- Relevance criteria (both paths):
252
- - Documents describing the same domain concepts
253
- - Architecture docs covering systems these files participate in
254
- - API docs for interfaces these files implement or consume
255
- - Decision records about choices visible in this code
256
- Be SELECTIVE fewer relevant docs is better than many tangential ones.
257
-
258
- Return ONLY a comma-separated list of relevant file paths (absolute or relative).
259
- If no docs are relevant, return 'none'.
260
- Do NOT return explanations just the file list.",
261
- subagent_type="ace-wiki-mapper",
262
- description="Curate relevant docs for [module-name]"
263
- )
264
- ```
265
-
266
- Replace the directory entry with the curated file list returned by the agent.
267
- Merge with any file-path entries that were already curated.
268
- The final `existing_docs` is a flat list of relevant file paths only.
269
-
270
- Display curated docs to user:
271
-
272
- ```
273
- ┌──────────────────────────────────────────────────┐
274
- │ Curated Existing Docs for [module-name] │
275
- └──────────────────────────────────────────────────┘
276
-
277
- Directory scanned: [directory path]
278
- Relevant docs selected ([N] of [total] files):
279
-
280
- - [file path 1]
281
- - [file path 2]
282
- - ...
283
-
284
- [If none selected: "No relevant docs found in directory."]
285
- ```
286
- </variant>
287
-
288
- <variant condition="ALL entries are file paths">
289
- Skip curation — use them directly.
290
- </variant>
291
- </substep>
292
-
293
- <substep order="2b" name="build-work-map">
294
- Build the work map:
295
-
296
- ```
297
- subsystem_work = {
298
- "[subsystem-name param]": {
299
- "files": [split files param into list],
300
- "module_name": "[module-name param]",
301
- "existing_docs": [resolved flat list of curated file paths, or empty]
302
- }
303
- }
304
- ```
305
- </substep>
306
-
307
- </mode>
308
-
309
- Continue to step 3.
310
- </step>
311
-
312
- <!-- ══════════════════════════════════════════════════════════════════ -->
313
- <!-- STEP 3: SPAWN PER-SUBSYSTEM AGENTS -->
314
- <!-- -->
315
- <!-- From here, story mode and file mode are IDENTICAL. -->
316
- <!-- One agent per subsystem. Same agent logic. Same thoroughness. -->
317
- <!-- ══════════════════════════════════════════════════════════════════ -->
318
-
319
- <step name="spawn-agents" order="3">
320
-
321
- <substep order="3.1" name="determine-parallelism">
322
- <rule condition="1 subsystem">Run agent in foreground.</rule>
323
- <rule condition="2+ subsystems">Run ALL agents with `run_in_background=true`.</rule>
324
- </substep>
325
-
326
- <substep order="3.2" name="spawn-agent-per-subsystem">
327
- For each entry in `subsystem_work`, spawn one ace-wiki-mapper agent.
328
-
329
- Each agent receives a self-contained prompt. The prompt MUST include all the
330
- instructions below the agent has no other source of truth for how to work.
331
-
332
- ```
333
- Task(
334
- prompt="You are creating or updating living knowledge documentation for the
335
- [subsystem_name] subsystem.
336
-
337
- <agent-instructions>
338
-
339
- <instruction order="0" name="read-templates">
340
- TEMPLATES Read ALL of these before writing ANY docs:
341
-
342
- - System docs: .claude/templates/system.xml
343
- - Pattern docs: .claude/templates/pattern.xml
344
- - Cross-cutting docs: .claude/templates/system-cross-cutting.xml
345
- - Guide docs: .claude/templates/guide.xml
346
- - Decision docs: .claude/templates/decizions.xml
347
- </instruction>
348
-
349
- <instruction order="0" name="inputs">
350
- YOUR INPUTS:
351
-
352
- **Subsystem:** [subsystem_name]
353
- **Wiki directory:** .docs/wiki/subsystems/[subsystem_name]/
354
-
355
- **Source files to analyze:**
356
- [list every file path with its A/M/D status (story mode) or just paths (file mode)]
357
-
358
- <variant condition="story mode">
359
- **Story context:**
360
- [story_summary from step 2c]
361
- </variant>
362
-
363
- <variant condition="file mode">
364
- **Module name:** [module_name]
365
- **Pre-existing documentation:** [existing_docs paths, or 'none']
366
- </variant>
367
-
368
- <variant condition="tech_debt_items is not empty">
369
- **Tech debt items to integrate:**
370
- [tech_debt_items YAML for this subsystem]
371
- </variant>
372
- </instruction>
373
-
374
- <instruction order="A" name="read-source-files">
375
- Read EVERY source file listed above (skip deleted files — note them for
376
- removal from existing docs). For each file, understand:
377
-
378
- <checklist>
379
- <item>Class hierarchies and interface implementations</item>
380
- <item>Function signatures and contracts</item>
381
- <item>State management (Redux slices, local state, database)</item>
382
- <item>Constants, enums, and configuration</item>
383
- <item>Integration points (imports from other systems, event handling)</item>
384
- <item>Error handling patterns</item>
385
- <item>DI registrations, factory/registry entries</item>
386
- </checklist>
387
-
388
- THE ACTUAL CODE IS THE SOURCE OF TRUTH. Story docs and existing docs
389
- are context for intent — the code is what gets documented.
390
-
391
- <variant condition="file mode and existing_docs is not 'none'">
392
- Also read the pre-existing documentation files. These contain prior
393
- knowledge about intent, decisions, and history. Use them to understand
394
- WHY things were built a certain way, but the source code always wins
395
- when there is a conflict.
396
- </variant>
397
- </instruction>
398
-
399
- <instruction order="B" name="read-existing-wiki">
400
- READ ALL EXISTING WIKI DOCS (MANDATORY — NO SHORTCUTS)
401
-
402
- Before writing ANYTHING, you MUST read ALL existing wiki documents for
403
- this subsystem. Not titles. Not summaries. THE FULL CONTENT of every
404
- single document.
405
-
406
- <substep order="B.1">
407
- Scan for existing docs use the Glob tool (NOT bash find):
408
- ```
409
- Glob(pattern='**/*.md', path='.docs/wiki/subsystems/[subsystem_name]')
410
- ```
411
- </substep>
412
-
413
- <substep order="B.2">
414
- Read EVERY document found fully:
415
- <checklist>
416
- <item>systems/*.md every system document, complete</item>
417
- <item>patterns/*.md — every pattern document, complete</item>
418
- <item>cross-cutting/*.md every cross-cutting document, complete</item>
419
- <item>guides/*.md — every guide document, complete</item>
420
- <item>decisions/*.md — every ADR, complete</item>
421
- </checklist>
422
- </substep>
423
-
424
- <substep order="B.3">
425
- Build a mental map of what is ALREADY documented:
426
- <checklist>
427
- <item>Which systems already have docs? What sections do they cover?</item>
428
- <item>Which patterns are already documented? What implementations are listed?</item>
429
- <item>Which cross-cutting concerns are documented? What registrations are listed?</item>
430
- <item>Which guides exist? Are the steps still accurate?</item>
431
- <item>Which decisions are recorded?</item>
432
- </checklist>
433
- </substep>
434
-
435
- This map is your ANTI-DUPLICATION defense. You cannot avoid creating
436
- duplicate content if you have not read what already exists.
437
-
438
- If the wiki directory does not exist:
439
- ```bash
440
- mkdir -p .docs/wiki/subsystems/[subsystem_name]/{systems,patterns,cross-cutting,guides,decisions}
441
- ```
442
- </instruction>
443
-
444
- <instruction order="C" name="analyze-and-categorize">
445
- ANALYZE AND CATEGORIZE
446
-
447
- <substep order="C.1" name="classify-code">
448
- For each significant component/change in the source files, determine
449
- which doc category it affects:
450
-
451
- <categorization-rules>
452
- <rule pattern="Coherent domain system (E2E flow)" target="systems/" />
453
- <rule pattern="Reusable structural pattern (2+ similar)" target="patterns/" />
454
- <rule pattern="Shared infrastructure (DI, events, registry)" target="cross-cutting/" />
455
- <rule pattern="Common repeatable task recipe" target="guides/" />
456
- <rule pattern="Significant architectural 'why' decision" target="decisions/" />
457
- </categorization-rules>
458
- </substep>
459
-
460
- <substep order="C.2" name="create-vs-update">
461
- CREATE vs UPDATE the critical decision.
462
-
463
- For EACH item you want to document, check your mental map from Step B:
464
-
465
- <decision-tree>
466
- <question ask="Does an existing doc ALREADY cover this topic?">
467
- <answer value="yes">UPDATE that doc. Add/expand sections. Do NOT create a new doc.</answer>
468
- <answer value="no">CREATE a new doc. But ONLY if this is a genuinely new topic.</answer>
469
- </question>
470
- <question ask="Could this content be a new SECTION in an existing system/pattern doc?">
471
- <answer value="yes">Add the section there. Do NOT create a separate doc.</answer>
472
- </question>
473
- <question ask="Is there ANY overlap with existing docs?">
474
- <answer value="yes">Merge into the existing doc. NEVER create parallel docs about the same concern.</answer>
475
- </question>
476
- </decision-tree>
477
-
478
- NEVER create a story-scoped or module-scoped document.
479
- All docs are TOPIC-scoped — about the concern, not about the story or module.
480
-
481
- When updating: ADD new sections or expand existing ones. Do NOT rewrite
482
- sections that have not changed. UPDATE file trees to reflect current state.
483
- REMOVE references to deleted files or components.
484
- </substep>
485
- </instruction>
486
-
487
- <instruction order="D" name="write-documentation">
488
- WRITE DOCUMENTATION
489
-
490
- For each item in your action plan:
491
-
492
- <substep order="D.1" name="apply-template">
493
- Read the appropriate template XML (from the list above).
494
- <variant condition="CREATE">Follow the template structure, fill all relevant sections,
495
- omit sections that genuinely don't apply.</variant>
496
- <variant condition="UPDATE">Read the existing doc, add/expand sections, preserve
497
- unchanged content, match existing style.</variant>
498
- </substep>
499
-
500
- <substep order="D.2" name="diagram-rules">
501
- DIAGRAM RULE — ALL visual representations of architecture, dependencies, flows,
502
- or relationships MUST use ```mermaid fenced code blocks.
503
- This means: NO ASCII arrows (->), NO tree structures for dependencies, NO PlantUML,
504
- NO custom notation. If you would write `A -> B -> C`, write a mermaid flowchart instead.
505
- The ONLY exception for ASCII is file trees (directory listings).
506
- </substep>
507
-
508
- <substep order="D.3" name="e2e-flow-rule">
509
- E2E FLOW RULE — Every systems/*.md doc MUST have at least one ```mermaid sequenceDiagram.
510
- This is non-negotiable. Trace the complete E2E flow from entry point through all layers
511
- to data store and back. If you cannot trace it, read more source files until you can.
512
- </substep>
513
-
514
- <substep order="D.4" name="style-guidelines">
515
- Documentation style (ALL docs):
516
- <checklist>
517
- <item>EXTREMELY SUCCINCT every word must add value</item>
518
- <item>NO FLUFF direct, actionable information only</item>
519
- <item>Bullet points over paragraphs</item>
520
- <item>File trees: ASCII only (|-- and backtick-dash-dash) — NEVER Unicode box-drawing</item>
521
- <item>Diagrams (sequence, class, boundary): MUST be ```mermaid fenced blocks</item>
522
- <item>Code references: `file-path:ClassName.methodName` or `file-path:functionName`
523
- NEVER use line numbers (they go stale with every edit)</item>
524
- <item>Inline snippets ONLY for interfaces, types, and contracts that define API shape</item>
525
- <item>When referencing a class/module: `file-path:ClassName`</item>
526
- <item>When referencing a method: `file-path:ClassName.methodName`</item>
527
- <item>When referencing a function: `file-path:functionName`</item>
528
- <item>When referencing a type/interface: `file-path:InterfaceName`</item>
529
- <item>Cross-reference related docs with markdown links</item>
530
- </checklist>
531
- </substep>
532
-
533
- <substep order="D.5" name="exclusions">
534
- What NOT to document:
535
- <exclusion-list>
536
- <exclude>Story numbers, sprint context, or agile artifacts</exclude>
537
- <exclude>Planned vs Actual comparisons</exclude>
538
- <exclude>Acceptance criteria checklists</exclude>
539
- <exclude>Revision history (git handles this)</exclude>
540
- <exclude>Duplicated implementation code (reference it, don't copy it)</exclude>
541
- <exclude>Line numbers in references (they go stale)</exclude>
542
- <exclude>Testing docs, coverage metrics, test code</exclude>
543
- <exclude>Performance benchmarks</exclude>
544
- <exclude>Debugging utilities or monitoring code</exclude>
545
- <exclude>ASCII art for diagrams (ALL diagrams MUST be ```mermaid blocks; exception: file trees use ASCII)</exclude>
546
- </exclusion-list>
547
- </substep>
548
- </instruction>
549
-
550
- <instruction order="E" name="quality-verification">
551
- QUALITY VERIFICATION
552
-
553
- After writing all docs, verify each one:
554
-
555
- <verification-checklist>
556
- <check>File exists and has substantial content (>10 lines for new docs)</check>
557
- <check>Code references use `file:Symbol` format — no line numbers</check>
558
- <check>No document is story-scoped or module-scoped in its title or structure</check>
559
- <check>Related systems/patterns/cross-cutting docs are cross-referenced with links</check>
560
- <check>File trees use ASCII only — no Unicode box-drawing characters</check>
561
- <check>Constants and enums locations are documented (agents must never hardcode)</check>
562
- <check>No content duplicated from another existing doc in this subsystem</check>
563
- <check>Every doc answers ONE clear question about how the system works</check>
564
- </verification-checklist>
565
- </instruction>
566
-
567
- <instruction order="E2" name="integrate-tech-debt">
568
- TECH DEBT INTEGRATION (only if tech_debt_items were provided)
569
-
570
- For each tech debt item assigned to this subsystem:
571
-
572
- <substep order="E2.1" name="find-target-doc">
573
- Determine which wiki doc the item belongs to based on the file path
574
- and the item's subsystem/description. It will be a systems/ or
575
- cross-cutting/ doc (tech debt lives in concrete code areas).
576
- </substep>
577
-
578
- <substep order="E2.2" name="add-tech-debt-section">
579
- If the target doc exists: add or update the `## Tech Debt` section.
580
- If the target doc was just created: include the `## Tech Debt` section.
581
-
582
- Use the verbose format from the wiki templates (NOT tables):
583
- ```
584
- ### [Short descriptive title]
585
- - **Severity:** high | medium | low
586
- - **File:** `[file-path:SymbolName]`
587
- - **Description:** What the issue is, why it matters
588
- - **Discovered during:** [story-id] — [story title]
589
- ```
590
-
591
- Do NOT duplicate items already in the doc's Tech Debt section.
592
- Remove items that have been fixed (file no longer has the issue).
593
- </substep>
594
-
595
- Include tech debt integration in your report.
596
- </instruction>
597
-
598
- <instruction order="F" name="report">
599
- YOUR REPORT (return this)
600
-
601
- Return a structured report:
602
-
603
- Subsystem: [subsystem_name]
604
-
605
- Documents created:
606
- - [path] ([line count] lines) [what this doc covers]
607
-
608
- Documents updated:
609
- - [path] — [what sections were added/changed]
610
-
611
- Documents unchanged:
612
- - [path] — [why no change was needed]
613
-
614
- Issues found (if any):
615
- - [description of any problems encountered]
616
- </instruction>
617
-
618
- </agent-instructions>
619
- ",
620
-
621
- subagent_type="ace-wiki-mapper",
622
- description="Document [subsystem_name] subsystem"
623
- )
624
- ```
625
- </substep>
626
-
627
- Continue to step 4.
628
- </step>
629
-
630
- <!-- ══════════════════════════════════════════════════════════════════ -->
631
- <!-- STEP 4: COLLECT RESULTS -->
632
- <!-- ══════════════════════════════════════════════════════════════════ -->
633
-
634
- <step name="collect-results" order="4">
635
-
636
- <substep order="4.1" name="wait-for-agents">
637
- If agents were spawned in background, wait for all to complete.
638
- Read each agent's report.
639
- </substep>
640
-
641
- <substep order="4.2" name="handle-failures">
642
- If any agent failed:
643
- <task-list>
644
- <task>Note the failure and the subsystem affected</task>
645
- <task>Do NOT re-attempt inform the user and let them decide</task>
646
- </task-list>
647
- </substep>
648
-
649
- <substep order="4.3" name="merge-reports">
650
- Merge all agent reports into a combined result.
651
- </substep>
652
-
653
- Continue to step 5.
654
- </step>
655
-
656
- <!-- ══════════════════════════════════════════════════════════════════ -->
657
- <!-- STEP 5: UPDATE TECH DEBT INDEX (story mode only, if tech debt) -->
658
- <!-- ══════════════════════════════════════════════════════════════════ -->
659
-
660
- <step name="update-tech-debt-index" order="5">
661
-
662
- <variant condition="story mode AND ALL_TECH_DEBT is not empty">
663
- Update `.docs/wiki/system-wide/tech-debt-index.md` using the
664
- tech-debt-index template (from execution-context).
665
-
666
- <substep order="5.1" name="read-existing-index">
667
- Read `.docs/wiki/system-wide/tech-debt-index.md` if it exists.
668
- If it doesn't exist, create it from the template.
669
- </substep>
670
-
671
- <substep order="5.2" name="merge-items">
672
- For each item in ALL_TECH_DEBT:
673
- - Add to the By Subsystem table under the correct subsystem
674
- - Add to the By Severity table under the correct severity
675
- - Do NOT duplicate items already in the index
676
- - Remove items that have been fixed
677
- </substep>
678
-
679
- <substep order="5.3" name="recalculate-counts">
680
- Recalculate all summary counts:
681
- - Total items, high/medium/low breakdown
682
- - Per-subsystem counts
683
- - Update the "Last updated" date
684
- </substep>
685
- </variant>
686
-
687
- <variant condition="file mode OR no tech debt">
688
- Skip no tech debt index update needed.
689
- </variant>
690
-
691
- Continue to step 6.
692
- </step>
693
-
694
- <!-- ══════════════════════════════════════════════════════════════════ -->
695
- <!-- STEP 6: SECURITY SCAN AND REPORT -->
696
- <!-- ══════════════════════════════════════════════════════════════════ -->
697
-
698
- <step name="report" order="6">
699
-
700
- <substep order="5.1" name="security-scan">
701
- Security scan across all affected subsystems — use the Grep tool (NOT bash grep):
702
-
703
- ```
704
- Grep(
705
- pattern="(sk-[a-zA-Z0-9]{20,}|sk_live_|sk_test_|ghp_[a-zA-Z0-9]{36}|AKIA[A-Z0-9]{16}|-----BEGIN.*PRIVATE KEY)",
706
- path=".docs/wiki/subsystems/",
707
- output_mode="content"
708
- )
709
- ```
710
-
711
- <variant condition="matches found">SECRETS_FOUND pause and alert user.</variant>
712
- <variant condition="no matches">CLEAN.</variant>
713
- </substep>
714
-
715
- <substep order="5.2" name="display-report">
716
-
717
- <!-- ── Story Mode Report ──────────────────────────────────────── -->
718
-
719
- <mode name="story">
720
- Display the combined report:
721
-
722
- ```
723
- ┌──────────────────────────────────────────────────┐
724
- │ ACE > Map Story > Complete │
725
- └──────────────────────────────────────────────────┘
726
-
727
- ## Documentation Update Report
728
-
729
- **Story**: [story name from artifacts, or "Git changes"]
730
- **Affected Subsystems**: [list]
731
-
732
- [For each subsystem, include the agent's report:]
733
-
734
- ### [subsystem_name]
735
-
736
- Documents created:
737
- - [path] ([line count] lines) [description]
738
-
739
- Documents updated:
740
- - [path] — [what changed]
741
-
742
- [If tech debt was integrated:]
743
- ### Tech Debt Integrated
744
- - [N] items added across [M] subsystem wiki docs
745
- - Tech debt index updated: .docs/wiki/system-wide/tech-debt-index.md
746
-
747
- [If any agent failures:]
748
- ### Failures
749
- - [subsystem]: [error]
750
-
751
- Next > `/clear` first for a fresh context window, then:
752
-
753
- /ace:map-story document another story
754
- /ace:map-subsystem [subsystem] map or refresh an entire subsystem
755
- Review files in .docs/wiki/subsystems/
756
- ```
757
- </mode>
758
-
759
- <!-- ── File Mode Report ───────────────────────────────────────── -->
760
-
761
- <mode name="file">
762
- Return the agent's report directly to the calling workflow
763
- (map-subsystem step 8.7). Do NOT display banners or next steps —
764
- the calling workflow handles presentation.
765
- </mode>
766
-
767
- </substep>
768
-
769
- End workflow.
770
- </step>
771
-
772
- </process>
773
-
774
- <success_criteria>
775
- <criterion>Mode correctly detected from parameters</criterion>
776
- <criterion>subsystem_work map built correctly from either mode's inputs</criterion>
777
- <criterion>One agent spawned per subsystem (parallel when 2+)</criterion>
778
- <criterion>Each agent reads ALL source files for its subsystem (not just names)</criterion>
779
- <criterion>Each agent reads ALL existing wiki docs for its subsystem FULLY (not summaries, not titles — complete content)</criterion>
780
- <criterion>Each agent checks every existing doc before deciding create vs update</criterion>
781
- <criterion>No duplicate documentation created — agent merges into existing docs when topic overlaps</criterion>
782
- <criterion>No story-scoped or module-scoped documents created (all topic-scoped)</criterion>
783
- <criterion>Each document follows its template structure from the XML templates</criterion>
784
- <criterion>Updates ADD to existing docs rather than rewriting unchanged sections</criterion>
785
- <criterion>Code references use `file:Symbol` format (not line numbers)</criterion>
786
- <criterion>File trees use ASCII only (no Unicode box-drawing)</criterion>
787
- <criterion>Diagrams use mermaid (not ASCII art)</criterion>
788
- <criterion>Every systems/*.md doc has at least one mermaid sequenceDiagram (E2E flow is mandatory)</criterion>
789
- <criterion>Inline code only for interface/type contracts</criterion>
790
- <criterion>Related systems cross-referenced with markdown links</criterion>
791
- <criterion>Tech debt items integrated into relevant subsystem wiki docs (if provided)</criterion>
792
- <criterion>Tech debt index updated with new items and recalculated counts (if provided)</criterion>
793
- <criterion>Security scan passed (no secrets in generated docs)</criterion>
794
- <criterion>Clear structured report from each agent, merged into final report</criterion>
795
- </success_criteria>
796
-
797
- </workflow>
1
+ <workflow>
2
+
3
+ <purpose>
4
+ Orchestrate living knowledge documentation: analyze what was built (story mode) or what
5
+ exists (file mode), then create or update topic-scoped documents in
6
+ `.docs/wiki/subsystems/[subsystem-name]/`.
7
+
8
+ Produces documents across six categories:
9
+ - systems/ — WHAT exists (domain subsystems and their current state)
10
+ - patterns/ — HOW things work (reusable implementation patterns)
11
+ - cross-cutting/ — concerns spanning multiple systems
12
+ - guides/ — step-by-step recipes for common implementation tasks
13
+ - walkthroughs/ deep tutorial-style flow explanations with actual code snippets
14
+ - decisions/ — WHY significant choices were made (ADRs)
15
+
16
+ Two input modes that converge into ONE execution flow:
17
+ - **Story mode** (user-invoked): Analyzes git changes after story implementation,
18
+ detects affected subsystem(s), spawns one agent per subsystem.
19
+ - **File mode** (invoked by map-subsystem step 8.7): Receives a file list for one
20
+ module in one subsystem, spawns one agent for that subsystem.
21
+
22
+ Both modes produce the same output: `{ subsystem: files }` map fed to per-subsystem
23
+ agents. The agents are identical regardless of mode they read all source files,
24
+ read ALL existing wiki docs, and make thorough create-vs-update decisions.
25
+ </purpose>
26
+
27
+ <mandatory-context>
28
+ The orchestrator reads ONLY this workflow it stays lightweight.
29
+ Each sub-agent reads the five document templates itself before writing.
30
+ Also read any parameters passed as $ARGUMENTS in the invoking command.
31
+ </mandatory-context>
32
+
33
+ <process>
34
+
35
+ <!-- ══════════════════════════════════════════════════════════════════ -->
36
+ <!-- STEP 1: SETUP AND MODE DETECTION -->
37
+ <!-- ══════════════════════════════════════════════════════════════════ -->
38
+
39
+ <step name="setup" order="1">
40
+
41
+ <substep order="1.1" name="detect-mode">
42
+ Parse $ARGUMENTS to determine execution mode:
43
+
44
+ <mode-rules>
45
+ <rule condition="files parameter provided" result="file mode" />
46
+ <rule condition="story-context parameter provided" result="story mode" />
47
+ <rule condition="neither parameter provided" result="story mode (analyze staged + unstaged changes)" />
48
+ </mode-rules>
49
+ </substep>
50
+
51
+ <substep order="1.2" name="parse-parameters">
52
+ <parameters mode="story">
53
+ <param name="story-context" required="false" type="path">Path to story artifacts folder</param>
54
+ <param name="commits" required="false" type="string">Number of recent commits OR comma-separated SHAs</param>
55
+ <param name="tech-debt" required="false" type="text|path">Tech debt from code review. Plain text, YAML, or file path.</param>
56
+ </parameters>
57
+
58
+ <parameters mode="file">
59
+ <param name="files" required="true" type="csv">Comma-separated source file paths</param>
60
+ <param name="module-name" required="true" type="string">Human-readable module name</param>
61
+ <param name="subsystem-name" required="true" type="string">Subsystem this module belongs to</param>
62
+ <param name="existing-docs" required="false" type="csv">Comma-separated file paths and/or directory paths to pre-existing documentation</param>
63
+ <param name="existing-docs-inventory" required="false" type="path">Path to a pre-built inventory file (existing-docs-inventory.md) that indexes a large doc directory. When provided, the curation agent reads this inventory instead of re-scanning the directory.</param>
64
+ </parameters>
65
+ </substep>
66
+
67
+ <substep order="1.3" name="display-banner">
68
+ Display stage banner:
69
+
70
+ ```
71
+ ┌──────────────────────────────────────────────────┐
72
+ │ ACE > Map Story > [story mode | file mode] │
73
+ └──────────────────────────────────────────────────┘
74
+ ```
75
+ </substep>
76
+
77
+ Continue to step 2.
78
+ </step>
79
+
80
+ <!-- ══════════════════════════════════════════════════════════════════ -->
81
+ <!-- STEP 2: BUILD SUBSYSTEM WORK MAP -->
82
+ <!-- -->
83
+ <!-- This is the ONLY step that differs by mode. -->
84
+ <!-- Both modes produce the same output: a subsystem_work map. -->
85
+ <!-- ══════════════════════════════════════════════════════════════════ -->
86
+
87
+ <step name="build-work-map" order="2">
88
+
89
+ <output-schema>
90
+ ```
91
+ subsystem_work = {
92
+ "[subsystem-name]": {
93
+ "files": [list of source file paths],
94
+ "file_statuses": { "path": "A|M|D" }, // story mode only
95
+ "story_summary": "...", // story mode only
96
+ "tech_debt_items": [...] // story mode only, if tech-debt provided
97
+ "module_name": "...", // file mode only
98
+ "existing_docs": [...] // file mode only, if provided
99
+ }
100
+ }
101
+ ```
102
+ </output-schema>
103
+
104
+ <!-- ── Story Mode ─────────────────────────────────────────────── -->
105
+
106
+ <mode name="story">
107
+
108
+ <substep order="2a" name="collect-changes">
109
+ Collect changed file names and statuses.
110
+
111
+ Determine the diff range:
112
+
113
+ <variant condition="commits is a number N">
114
+ ```bash
115
+ git log --name-status -n [N]
116
+ git diff --name-status HEAD~[N]..HEAD
117
+ ```
118
+ </variant>
119
+
120
+ <variant condition="commits is comma-separated SHAs">
121
+ ```bash
122
+ git log --name-status [first-sha]^..[last-sha]
123
+ git diff --name-status [first-sha]^..[last-sha]
124
+ ```
125
+ </variant>
126
+
127
+ <variant condition="commits not provided">
128
+ ```bash
129
+ git diff --name-status
130
+ git diff --name-status --cached
131
+ ```
132
+ </variant>
133
+
134
+ Collect every changed file with its status (A = added, M = modified, D = deleted).
135
+ </substep>
136
+
137
+ <substep order="2b" name="group-by-subsystem">
138
+ Map each changed file path to its subsystem:
139
+
140
+ <mapping-rules>
141
+ <rule path="src/Qarc/Web/qarc-charts-v2/" subsystem="qarc-charts-v2" />
142
+ <rule path="src/Qarc/Web/qarc-workspace/" subsystem="qarc-workspace" />
143
+ <rule path="src/Qarc/Web/qarc-web/" subsystem="qarc-web" />
144
+ <rule path="src/Qarc/Engine/" subsystem="engine" />
145
+ <rule path="src/Qarc/DataIngestion/" subsystem="data-ingestion" />
146
+ <rule path="src/Qarc/DataStreaming/" subsystem="data-streaming" />
147
+ <rule path="src/Qarc/ChartManagement/" subsystem="chart-management" />
148
+ <rule path="src/Qarc/Gateway/" subsystem="gateway" />
149
+ <rule path="src/Qarc/[ServiceName]/" subsystem="[service-name] (kebab-case)" />
150
+ <rule path="outside src/Qarc/" subsystem="skip" />
151
+ </mapping-rules>
152
+
153
+ Build one entry per subsystem in `subsystem_work`.
154
+ </substep>
155
+
156
+ <substep order="2c" name="read-story-context">
157
+ Read story context (if provided) and produce a brief summary.
158
+
159
+ <variant condition="story-context parameter was provided">
160
+ <task-list>
161
+ <task>Read all markdown files in the story artifacts folder</task>
162
+ <task>Extract a summary (10-15 lines max): what the story intended, key acceptance
163
+ criteria, significant decisions mentioned</task>
164
+ <task>Attach the same summary to every subsystem entry (shared intent context)</task>
165
+ </task-list>
166
+ NOTE: The implementation may deviate from the plan — agents document
167
+ what WAS built, not what was planned.
168
+ </variant>
169
+
170
+ <variant condition="no story-context">
171
+ Set story_summary = "No story artifacts. Document from code changes."
172
+ </variant>
173
+
174
+ Display to user:
175
+ ```
176
+ Affected subsystems:
177
+ - [subsystem] ([N] files changed)
178
+ - [subsystem] ([M] files changed)
179
+ ```
180
+ </substep>
181
+
182
+ <substep order="2d" name="distribute-tech-debt">
183
+ <variant condition="tech-debt parameter was provided">
184
+ Parse the tech debt input (plain text, YAML, or read from file path).
185
+ Each tech debt item has a `file` field use the same subsystem mapping
186
+ rules from step 2b to assign each item to its subsystem.
187
+ Attach the filtered items to each subsystem entry as `tech_debt_items`.
188
+
189
+ Store the full parsed tech debt list as `ALL_TECH_DEBT` for step 4
190
+ (tech-debt-index update).
191
+
192
+ Display:
193
+ ```
194
+ i Tech debt: {total_count} items distributed across {subsystem_count} subsystem(s)
195
+ ```
196
+ </variant>
197
+
198
+ <variant condition="no tech-debt parameter">
199
+ Skip — no tech debt to integrate.
200
+ </variant>
201
+ </substep>
202
+
203
+ <substep order="2e" name="detect-new-subsystems">
204
+ Detect whether any subsystems in `subsystem_work` are NEW (not yet documented
205
+ in system-structure.md). If found, offer to run full subsystem mapping via
206
+ /ace:map-subsystem before proceeding with per-change documentation.
207
+
208
+ Only runs in story mode. Naturally skipped when map-story is invoked as a
209
+ background agent (e.g., from execute-story) because the required tools —
210
+ Agent, AskUserQuestion — are unavailable to ace-wiki-mapper agents.
211
+
212
+ <substep order="2e.1" name="check-system-structure">
213
+ Check if `.docs/wiki/system-wide/system-structure.md` exists.
214
+
215
+ <variant condition="file does not exist">
216
+ Display:
217
+ ```
218
+ i system-structure.md not found skipping new subsystem detection.
219
+ Run /ace:map-system first to create system-wide documentation.
220
+ ```
221
+ Skip the rest of substep 2e.
222
+ </variant>
223
+
224
+ <variant condition="file exists">
225
+ Read `.docs/wiki/system-wide/system-structure.md`.
226
+ Parse the **Subsystem Index** table to extract known subsystem
227
+ directory paths (the Directory column values).
228
+ Store as `known_subsystems`.
229
+ </variant>
230
+ </substep>
231
+
232
+ <substep order="2e.2" name="identify-new-subsystems">
233
+ For each subsystem key in `subsystem_work`, determine its source
234
+ directory path from the changed file paths (the common parent
235
+ directory at the subsystem root level).
236
+
237
+ Compare against `known_subsystems`. Any subsystem whose directory
238
+ path is NOT in the list add to `new_subsystems` with name and path.
239
+
240
+ <variant condition="new_subsystems is empty">
241
+ No new subsystems detectedskip the rest of substep 2e.
242
+ </variant>
243
+ </substep>
244
+
245
+ <substep order="2e.3" name="ask-user-approval">
246
+ Display:
247
+ ```
248
+ ! New subsystem(s) detected not yet in system-structure.md:
249
+
250
+ [For each new subsystem:]
251
+ - [subsystem-name] at [path] ([N] changed files)
252
+ ```
253
+
254
+ Use AskUserQuestion:
255
+ - header: "New Subsystem"
256
+ - question: "This story added files in [count] subsystem(s) not yet
257
+ documented in system-structure.md:\n\n[list: name at path]\n\nFull
258
+ mapping creates structure.md, architecture.md, module discovery, and
259
+ all knowledge docs (systems/, patterns/, cross-cutting/, guides/,
260
+ decisions/). It also updates system-structure.md and
261
+ system-architecture.md.\n\nShould I run full subsystem mapping?"
262
+ - options:
263
+ - "Yes, map new subsystem(s)" — Run /ace:map-subsystem for each
264
+ new subsystem, then continue with remaining work
265
+ - "No, just document the changes" — Treat them like existing
266
+ subsystems (lightweight per-change docs only)
267
+
268
+ <option value="No, just document the changes">
269
+ Skip the rest of substep 2e — new subsystems stay in
270
+ `subsystem_work` for normal step 3 processing.
271
+ </option>
272
+ </substep>
273
+
274
+ <substep order="2e.4" name="run-map-subsystem" condition="user approved">
275
+ For each subsystem in `new_subsystems`, run map-subsystem SEQUENTIALLY
276
+ (each spawns many internal sub-agents — parallel would be too heavy).
277
+
278
+ Store results in `new_subsystem_reports` list.
279
+
280
+ <loop for-each="subsystem in new_subsystems">
281
+ Display:
282
+ ```
283
+ ┌──────────────────────────────────────────────────┐
284
+ │ ACE > Map Story > New Subsystem Mapping │
285
+ └──────────────────────────────────────────────────┘
286
+
287
+ Mapping [subsystem.name] at [subsystem.path]...
288
+ ([index] of [total] new subsystems)
289
+ ```
290
+
291
+ ```
292
+ Agent(
293
+ prompt="/ace:map-subsystem subsystem=\"[subsystem.path]\"
294
+
295
+ Execute the map-subsystem workflow end-to-end.
296
+ This is a NEW subsystem — no existing docs to triage
297
+ (all documents will be created fresh).
298
+
299
+ **Return format ONLY this, nothing else:**
300
+ MAP-SUBSYSTEM COMPLETE
301
+ Subsystem: [subsystem.name]
302
+ - Structure: created ([N] lines)
303
+ - Architecture: created ([N] lines)
304
+ - Modules discovered: [count]
305
+ - Knowledge docs created: [count]
306
+ - system-structure.md: updated
307
+ - system-architecture.md: updated",
308
+ subagent_type="general-purpose",
309
+ description="Map new subsystem [subsystem.name]"
310
+ )
311
+ ```
312
+
313
+ Parse the agent's return and add to `new_subsystem_reports`.
314
+
315
+ Display:
316
+ ```
317
+ + [subsystem.name] mapping complete — [count] docs created
318
+ ```
319
+ </loop>
320
+ </substep>
321
+
322
+ <substep order="2e.5" name="prune-work-map" condition="user approved">
323
+ Remove all `new_subsystems` entries from `subsystem_work` to prevent
324
+ duplicate documentation in step 3 (map-subsystem already created full
325
+ structure, architecture, module discovery, AND all knowledge docs).
326
+
327
+ Display:
328
+ ```
329
+ i Removed [count] fully-mapped subsystem(s) from work queue.
330
+ Remaining for per-change documentation: [list remaining, or "none"]
331
+ ```
332
+
333
+ <variant condition="subsystem_work is now empty AND tech_debt_items exist for new subsystems">
334
+ map-subsystem does NOT handle tech debt integration. Spawn a
335
+ lightweight ace-wiki-mapper agent per new subsystem that has
336
+ tech_debt_items, with instructions to ONLY add ## Tech Debt
337
+ sections to the docs that map-subsystem just created.
338
+ </variant>
339
+
340
+ <variant condition="subsystem_work is now empty AND no tech debt">
341
+ Skip steps 3-4, jump to step 5 (tech debt index update).
342
+ </variant>
343
+
344
+ <variant condition="subsystem_work still has entries">
345
+ Continue to step 3 normally with the reduced work map.
346
+ </variant>
347
+ </substep>
348
+ </substep>
349
+
350
+ </mode>
351
+
352
+ <!-- ── File Mode ──────────────────────────────────────────────── -->
353
+
354
+ <mode name="file">
355
+
356
+ <substep order="2a" name="resolve-existing-docs">
357
+ Resolve existing-docs entries.
358
+
359
+ Split the `existing-docs` parameter into individual entries. Classify each entry:
360
+
361
+ <classification>
362
+ <type name="file-path">Keep as-is (already curated by the caller)</type>
363
+ <type name="directory-path">Needs curation (may contain hundreds of irrelevant files)</type>
364
+ </classification>
365
+
366
+ <variant condition="ANY entry is a directory">
367
+ Spawn a curation agent to select only relevant docs.
368
+ If `existing-docs-inventory` was provided (not `none`), pass it to the agent
369
+ so it reads the pre-built inventory instead of re-scanning the directory.
370
+
371
+ ```
372
+ Task(
373
+ prompt="You are a documentation curation agent. Your job is to select ONLY the
374
+ documentation files relevant to a specific code module from a large doc directory.
375
+
376
+ **Module name:** [module-name param]
377
+ **Source files in this module:** [files param]
378
+ **Documentation directory:** [directory path]
379
+ **Pre-built inventory (if available):** [existing-docs-inventory path, or 'none']
380
+
381
+ Process:
382
+
383
+ IF a pre-built inventory file was provided (not 'none'):
384
+ 1. Read the inventory file — it contains file paths, titles, and summaries
385
+ for every doc in the directory, already indexed
386
+ 2. Compare each inventory entry against the module's source files and name
387
+ 3. Select ONLY entries whose subject matter is relevant to this module
388
+ 4. Return the file paths from the selected inventory entries
389
+ (Do NOT re-scan the directory — the inventory is the source of truth)
390
+
391
+ IF no inventory file is available:
392
+ 1. Recursively list ALL files in the documentation directory down to every leaf
393
+ subdirectory. Use Glob(pattern='**/*', path='[directory path]') to ensure
394
+ no nesting level is missed. Do NOT use shallow ls or single-level globs.
395
+ 2. For each file, read its title and first 10-20 lines to understand its subject
396
+ 3. Compare against the module's source files and module name
397
+ 4. Select ONLY files whose subject matter is relevant to this module
398
+
399
+ Relevance criteria (both paths):
400
+ - Documents describing the same domain concepts
401
+ - Architecture docs covering systems these files participate in
402
+ - API docs for interfaces these files implement or consume
403
+ - Decision records about choices visible in this code
404
+ Be SELECTIVE — fewer relevant docs is better than many tangential ones.
405
+
406
+ Return ONLY a comma-separated list of relevant file paths (absolute or relative).
407
+ If no docs are relevant, return 'none'.
408
+ Do NOT return explanations — just the file list.",
409
+ subagent_type="ace-wiki-mapper",
410
+ description="Curate relevant docs for [module-name]"
411
+ )
412
+ ```
413
+
414
+ Replace the directory entry with the curated file list returned by the agent.
415
+ Merge with any file-path entries that were already curated.
416
+ The final `existing_docs` is a flat list of relevant file paths only.
417
+
418
+ Display curated docs to user:
419
+
420
+ ```
421
+ ┌──────────────────────────────────────────────────┐
422
+ │ Curated Existing Docs for [module-name] │
423
+ └──────────────────────────────────────────────────┘
424
+
425
+ Directory scanned: [directory path]
426
+ Relevant docs selected ([N] of [total] files):
427
+
428
+ - [file path 1]
429
+ - [file path 2]
430
+ - ...
431
+
432
+ [If none selected: "No relevant docs found in directory."]
433
+ ```
434
+ </variant>
435
+
436
+ <variant condition="ALL entries are file paths">
437
+ Skip curation — use them directly.
438
+ </variant>
439
+ </substep>
440
+
441
+ <substep order="2b" name="build-work-map">
442
+ Build the work map:
443
+
444
+ ```
445
+ subsystem_work = {
446
+ "[subsystem-name param]": {
447
+ "files": [split files param into list],
448
+ "module_name": "[module-name param]",
449
+ "existing_docs": [resolved flat list of curated file paths, or empty]
450
+ }
451
+ }
452
+ ```
453
+ </substep>
454
+
455
+ </mode>
456
+
457
+ Continue to step 3.
458
+ </step>
459
+
460
+ <!-- ══════════════════════════════════════════════════════════════════ -->
461
+ <!-- STEP 3: SPAWN PER-SUBSYSTEM AGENTS -->
462
+ <!-- -->
463
+ <!-- From here, story mode and file mode are IDENTICAL. -->
464
+ <!-- One agent per subsystem. Same agent logic. Same thoroughness. -->
465
+ <!-- ══════════════════════════════════════════════════════════════════ -->
466
+
467
+ <step name="spawn-agents" order="3">
468
+
469
+ <substep order="3.1" name="determine-parallelism">
470
+ <rule condition="1 subsystem">Run agent in foreground.</rule>
471
+ <rule condition="2+ subsystems">Run ALL agents with `run_in_background=true`.</rule>
472
+ </substep>
473
+
474
+ <substep order="3.2" name="spawn-agent-per-subsystem">
475
+ For each entry in `subsystem_work`, spawn one ace-wiki-mapper agent.
476
+
477
+ Each agent receives a self-contained prompt. The prompt MUST include all the
478
+ instructions below the agent has no other source of truth for how to work.
479
+
480
+ ```
481
+ Task(
482
+ prompt="You are creating or updating living knowledge documentation for the
483
+ [subsystem_name] subsystem.
484
+
485
+ <agent-instructions>
486
+
487
+ <instruction order="0" name="read-templates">
488
+ TEMPLATES — Read ALL of these before writing ANY docs:
489
+
490
+ - System docs: .claude/templates/system.xml
491
+ - Pattern docs: .claude/templates/pattern.xml
492
+ - Cross-cutting docs: .claude/templates/system-cross-cutting.xml
493
+ - Guide docs: .claude/templates/guide.xml
494
+ - Walkthrough docs: .claude/templates/walkthrough.xml
495
+ - Decision docs: .claude/templates/decizions.xml
496
+ </instruction>
497
+
498
+ <instruction order="0" name="inputs">
499
+ YOUR INPUTS:
500
+
501
+ **Subsystem:** [subsystem_name]
502
+ **Wiki directory:** .docs/wiki/subsystems/[subsystem_name]/
503
+
504
+ **Source files to analyze:**
505
+ [list every file path with its A/M/D status (story mode) or just paths (file mode)]
506
+
507
+ <variant condition="story mode">
508
+ **Story context:**
509
+ [story_summary from step 2c]
510
+ </variant>
511
+
512
+ <variant condition="file mode">
513
+ **Module name:** [module_name]
514
+ **Pre-existing documentation:** [existing_docs paths, or 'none']
515
+ </variant>
516
+
517
+ <variant condition="tech_debt_items is not empty">
518
+ **Tech debt items to integrate:**
519
+ [tech_debt_items YAML for this subsystem]
520
+ </variant>
521
+ </instruction>
522
+
523
+ <instruction order="A" name="read-source-files">
524
+ Read EVERY source file listed above (skip deleted files note them for
525
+ removal from existing docs). For each file, understand:
526
+
527
+ <checklist>
528
+ <item>Class hierarchies and interface implementations</item>
529
+ <item>Function signatures and contracts</item>
530
+ <item>State management (Redux slices, local state, database)</item>
531
+ <item>Constants, enums, and configuration</item>
532
+ <item>Integration points (imports from other systems, event handling)</item>
533
+ <item>Error handling patterns</item>
534
+ <item>DI registrations, factory/registry entries</item>
535
+ </checklist>
536
+
537
+ THE ACTUAL CODE IS THE SOURCE OF TRUTH. Story docs and existing docs
538
+ are context for intent — the code is what gets documented.
539
+
540
+ <variant condition="file mode and existing_docs is not 'none'">
541
+ Also read the pre-existing documentation files. These contain prior
542
+ knowledge about intent, decisions, and history. Use them to understand
543
+ WHY things were built a certain way, but the source code always wins
544
+ when there is a conflict.
545
+ </variant>
546
+ </instruction>
547
+
548
+ <instruction order="B" name="read-existing-wiki">
549
+ READ ALL EXISTING WIKI DOCS (MANDATORY — NO SHORTCUTS)
550
+
551
+ Before writing ANYTHING, you MUST read ALL existing wiki documents for
552
+ this subsystem. Not titles. Not summaries. THE FULL CONTENT of every
553
+ single document.
554
+
555
+ <substep order="B.1">
556
+ Scan for existing docs use the Glob tool (NOT bash find):
557
+ ```
558
+ Glob(pattern='**/*.md', path='.docs/wiki/subsystems/[subsystem_name]')
559
+ ```
560
+ </substep>
561
+
562
+ <substep order="B.2">
563
+ Read EVERY document found fully:
564
+ <checklist>
565
+ <item>systems/*.md — every system document, complete</item>
566
+ <item>patterns/*.md — every pattern document, complete</item>
567
+ <item>cross-cutting/*.md every cross-cutting document, complete</item>
568
+ <item>guides/*.md every guide document, complete</item>
569
+ <item>walkthroughs/*.md — every walkthrough document, complete</item>
570
+ <item>decisions/*.md every ADR, complete</item>
571
+ </checklist>
572
+ </substep>
573
+
574
+ <substep order="B.3">
575
+ Build a mental map of what is ALREADY documented:
576
+ <checklist>
577
+ <item>Which systems already have docs? What sections do they cover?</item>
578
+ <item>Which patterns are already documented? What implementations are listed?</item>
579
+ <item>Which cross-cutting concerns are documented? What registrations are listed?</item>
580
+ <item>Which guides exist? Are the steps still accurate?</item>
581
+ <item>Which walkthroughs exist? Are the code snippets still accurate? Which flows do they cover?</item>
582
+ <item>Which decisions are recorded?</item>
583
+ </checklist>
584
+ </substep>
585
+
586
+ This map is your ANTI-DUPLICATION defense. You cannot avoid creating
587
+ duplicate content if you have not read what already exists.
588
+
589
+ If the wiki directory does not exist:
590
+ ```bash
591
+ mkdir -p .docs/wiki/subsystems/[subsystem_name]/{systems,patterns,cross-cutting,guides,walkthroughs,decisions}
592
+ ```
593
+ </instruction>
594
+
595
+ <instruction order="C" name="analyze-and-categorize">
596
+ ANALYZE AND CATEGORIZE
597
+
598
+ <substep order="C.1" name="classify-code">
599
+ For each significant component/change in the source files, determine
600
+ which doc category it affects:
601
+
602
+ <categorization-rules>
603
+ <rule pattern="Coherent domain system (E2E flow)" target="systems/" />
604
+ <rule pattern="Reusable structural pattern (2+ similar)" target="patterns/" />
605
+ <rule pattern="Shared infrastructure (DI, events, registry)" target="cross-cutting/" />
606
+ <rule pattern="Common repeatable task recipe" target="guides/" />
607
+ <rule pattern="Complex multi-class flow with framework involvement" target="walkthroughs/" />
608
+ <rule pattern="Significant architectural 'why' decision" target="decisions/" />
609
+ </categorization-rules>
610
+ </substep>
611
+
612
+ <substep order="C.2" name="create-vs-update">
613
+ CREATE vs UPDATE — the critical decision.
614
+
615
+ For EACH item you want to document, check your mental map from Step B:
616
+
617
+ <decision-tree>
618
+ <question ask="Does an existing doc ALREADY cover this topic?">
619
+ <answer value="yes">UPDATE that doc. Add/expand sections. Do NOT create a new doc.</answer>
620
+ <answer value="no">CREATE a new doc. But ONLY if this is a genuinely new topic.</answer>
621
+ </question>
622
+ <question ask="Could this content be a new SECTION in an existing system/pattern doc?">
623
+ <answer value="yes">Add the section there. Do NOT create a separate doc.</answer>
624
+ </question>
625
+ <question ask="Is there ANY overlap with existing docs?">
626
+ <answer value="yes">Merge into the existing doc. NEVER create parallel docs about the same concern.</answer>
627
+ </question>
628
+ </decision-tree>
629
+
630
+ NEVER create a story-scoped or module-scoped document.
631
+ All docs are TOPIC-scoped — about the concern, not about the story or module.
632
+
633
+ When updating: ADD new sections or expand existing ones. Do NOT rewrite
634
+ sections that have not changed. UPDATE file trees to reflect current state.
635
+ REMOVE references to deleted files or components.
636
+ </substep>
637
+ </instruction>
638
+
639
+ <instruction order="D" name="write-documentation">
640
+ WRITE DOCUMENTATION
641
+
642
+ For each item in your action plan:
643
+
644
+ <substep order="D.1" name="apply-template">
645
+ Read the appropriate template XML (from the list above).
646
+ <variant condition="CREATE">Follow the template structure, fill all relevant sections,
647
+ omit sections that genuinely don't apply.</variant>
648
+ <variant condition="UPDATE">Read the existing doc, add/expand sections, preserve
649
+ unchanged content, match existing style.</variant>
650
+ </substep>
651
+
652
+ <substep order="D.2" name="diagram-rules">
653
+ DIAGRAM RULE ALL visual representations of architecture, dependencies, flows,
654
+ or relationships MUST use ```mermaid fenced code blocks.
655
+ This means: NO ASCII arrows (->), NO tree structures for dependencies, NO PlantUML,
656
+ NO custom notation. If you would write `A -> B -> C`, write a mermaid flowchart instead.
657
+ The ONLY exception for ASCII is file trees (directory listings).
658
+ </substep>
659
+
660
+ <substep order="D.3" name="e2e-flow-rule">
661
+ E2E FLOW RULE — Every systems/*.md doc MUST have at least one ```mermaid sequenceDiagram.
662
+ This is non-negotiable. Trace the complete E2E flow from entry point through all layers
663
+ to data store and back. If you cannot trace it, read more source files until you can.
664
+ </substep>
665
+
666
+ <substep order="D.4" name="style-guidelines">
667
+ Documentation style (ALL docs):
668
+ <checklist>
669
+ <item>EXTREMELY SUCCINCT — every word must add value</item>
670
+ <item>NO FLUFF — direct, actionable information only</item>
671
+ <item>Bullet points over paragraphs</item>
672
+ <item>File trees: ASCII only (|-- and backtick-dash-dash) — NEVER Unicode box-drawing</item>
673
+ <item>Diagrams (sequence, class, boundary): MUST be ```mermaid fenced blocks</item>
674
+ <item>Code references: `file-path:ClassName.methodName` or `file-path:functionName`
675
+ NEVER use line numbers (they go stale with every edit)</item>
676
+ <item>Inline snippets ONLY for interfaces, types, and contracts that define API shape</item>
677
+ <item>When referencing a class/module: `file-path:ClassName`</item>
678
+ <item>When referencing a method: `file-path:ClassName.methodName`</item>
679
+ <item>When referencing a function: `file-path:functionName`</item>
680
+ <item>When referencing a type/interface: `file-path:InterfaceName`</item>
681
+ <item>Cross-reference related docs with markdown links</item>
682
+ </checklist>
683
+ </substep>
684
+
685
+ <substep order="D.5" name="exclusions">
686
+ What NOT to document:
687
+ <exclusion-list>
688
+ <exclude>Story numbers, sprint context, or agile artifacts</exclude>
689
+ <exclude>Planned vs Actual comparisons</exclude>
690
+ <exclude>Acceptance criteria checklists</exclude>
691
+ <exclude>Revision history (git handles this)</exclude>
692
+ <exclude>Duplicated implementation code (reference it, don't copy it)</exclude>
693
+ <exclude>Line numbers in references (they go stale)</exclude>
694
+ <exclude>Testing docs, coverage metrics, test code</exclude>
695
+ <exclude>Performance benchmarks</exclude>
696
+ <exclude>Debugging utilities or monitoring code</exclude>
697
+ <exclude>ASCII art for diagrams (ALL diagrams MUST be ```mermaid blocks; exception: file trees use ASCII)</exclude>
698
+ </exclusion-list>
699
+ </substep>
700
+ </instruction>
701
+
702
+ <instruction order="E" name="quality-verification">
703
+ QUALITY VERIFICATION
704
+
705
+ After writing all docs, verify each one:
706
+
707
+ <verification-checklist>
708
+ <check>File exists and has substantial content (>10 lines for new docs)</check>
709
+ <check>Code references use `file:Symbol` format — no line numbers</check>
710
+ <check>No document is story-scoped or module-scoped in its title or structure</check>
711
+ <check>Related systems/patterns/cross-cutting docs are cross-referenced with links</check>
712
+ <check>File trees use ASCII only — no Unicode box-drawing characters</check>
713
+ <check>Constants and enums locations are documented (agents must never hardcode)</check>
714
+ <check>No content duplicated from another existing doc in this subsystem</check>
715
+ <check>Every doc answers ONE clear question about how the system works</check>
716
+ </verification-checklist>
717
+ </instruction>
718
+
719
+ <instruction order="E2" name="integrate-tech-debt">
720
+ TECH DEBT INTEGRATION (only if tech_debt_items were provided)
721
+
722
+ For each tech debt item assigned to this subsystem:
723
+
724
+ <substep order="E2.1" name="find-target-doc">
725
+ Determine which wiki doc the item belongs to based on the file path
726
+ and the item's subsystem/description. It will be a systems/ or
727
+ cross-cutting/ doc (tech debt lives in concrete code areas).
728
+ </substep>
729
+
730
+ <substep order="E2.2" name="add-tech-debt-section">
731
+ If the target doc exists: add or update the `## Tech Debt` section.
732
+ If the target doc was just created: include the `## Tech Debt` section.
733
+
734
+ Use the verbose format from the wiki templates (NOT tables):
735
+ ```
736
+ ### [Short descriptive title]
737
+ - **Severity:** high | medium | low
738
+ - **File:** `[file-path:SymbolName]`
739
+ - **Description:** What the issue is, why it matters
740
+ - **Discovered during:** [story-id] — [story title]
741
+ ```
742
+
743
+ Do NOT duplicate items already in the doc's Tech Debt section.
744
+ Remove items that have been fixed (file no longer has the issue).
745
+ </substep>
746
+
747
+ Include tech debt integration in your report.
748
+ </instruction>
749
+
750
+ <instruction order="F" name="walkthrough-suggestions">
751
+ WALKTHROUGH SUGGESTIONS
752
+
753
+ After documenting, analyze the code you just read for potential
754
+ walkthrough candidates. A flow is a walkthrough candidate when:
755
+ - It spans 3+ classes across multiple layers (handler -> service -> repository -> db)
756
+ - External frameworks/libraries are involved (SignalR, EF Core, gRPC, Microsoft Agent Framework etc.)
757
+ - The flow is complex enough that an intern couldn't follow it from code alone
758
+ - No existing walkthrough already covers this flow
759
+
760
+ Check `.docs/wiki/subsystems/[subsystem_name]/walkthroughs/` for existing
761
+ walkthroughs. Do NOT suggest flows already covered.
762
+
763
+ For each candidate, identify:
764
+ - A natural language flow description (start -> end)
765
+ - Which emphasis-frameworks would be valuable (if any)
766
+ - Why this flow deserves a walkthrough (1 line)
767
+ </instruction>
768
+
769
+ <instruction order="G" name="report">
770
+ YOUR REPORT (return this)
771
+
772
+ Return a structured report:
773
+
774
+ Subsystem: [subsystem_name]
775
+
776
+ Documents created:
777
+ - [path] ([line count] lines) [what this doc covers]
778
+
779
+ Documents updated:
780
+ - [path] [what sections were added/changed]
781
+
782
+ Documents unchanged:
783
+ - [path] [why no change was needed]
784
+
785
+ Issues found (if any):
786
+ - [description of any problems encountered]
787
+
788
+ Walkthrough suggestions:
789
+ - FLOW: [natural language flow description]
790
+ SUBSYSTEM: [subsystem_name]
791
+ EMPHASIS: [framework1, framework2, or "none"]
792
+ REASON: [why this deserves a walkthrough]
793
+ - FLOW: ...
794
+
795
+ [If no walkthrough candidates found:]
796
+ Walkthrough suggestions: none
797
+ </instruction>
798
+
799
+ </agent-instructions>
800
+ ",
801
+
802
+ subagent_type="ace-wiki-mapper",
803
+ description="Document [subsystem_name] subsystem"
804
+ )
805
+ ```
806
+ </substep>
807
+
808
+ Continue to step 4.
809
+ </step>
810
+
811
+ <!-- ══════════════════════════════════════════════════════════════════ -->
812
+ <!-- STEP 4: COLLECT RESULTS -->
813
+ <!-- ══════════════════════════════════════════════════════════════════ -->
814
+
815
+ <step name="collect-results" order="4">
816
+
817
+ <substep order="4.1" name="wait-for-agents">
818
+ If agents were spawned in background, wait for all to complete.
819
+ Read each agent's report.
820
+ </substep>
821
+
822
+ <substep order="4.2" name="handle-failures">
823
+ If any agent failed:
824
+ <task-list>
825
+ <task>Note the failure and the subsystem affected</task>
826
+ <task>Do NOT re-attempt — inform the user and let them decide</task>
827
+ </task-list>
828
+ </substep>
829
+
830
+ <substep order="4.3" name="merge-reports">
831
+ Merge all agent reports into a combined result.
832
+ </substep>
833
+
834
+ Continue to step 5.
835
+ </step>
836
+
837
+ <!-- ══════════════════════════════════════════════════════════════════ -->
838
+ <!-- STEP 5: UPDATE TECH DEBT INDEX (story mode only, if tech debt) -->
839
+ <!-- ══════════════════════════════════════════════════════════════════ -->
840
+
841
+ <step name="update-tech-debt-index" order="5">
842
+
843
+ <variant condition="story mode AND ALL_TECH_DEBT is not empty">
844
+ Update `.docs/wiki/system-wide/tech-debt-index.md` using the
845
+ tech-debt-index template (from execution-context).
846
+
847
+ <substep order="5.1" name="read-existing-index">
848
+ Read `.docs/wiki/system-wide/tech-debt-index.md` if it exists.
849
+ If it doesn't exist, create it from the template.
850
+ </substep>
851
+
852
+ <substep order="5.2" name="merge-items">
853
+ For each item in ALL_TECH_DEBT:
854
+ - Add to the By Subsystem table under the correct subsystem
855
+ - Add to the By Severity table under the correct severity
856
+ - Do NOT duplicate items already in the index
857
+ - Remove items that have been fixed
858
+ </substep>
859
+
860
+ <substep order="5.3" name="recalculate-counts">
861
+ Recalculate all summary counts:
862
+ - Total items, high/medium/low breakdown
863
+ - Per-subsystem counts
864
+ - Update the "Last updated" date
865
+ </substep>
866
+ </variant>
867
+
868
+ <variant condition="file mode OR no tech debt">
869
+ Skip — no tech debt index update needed.
870
+ </variant>
871
+
872
+ Continue to step 6.
873
+ </step>
874
+
875
+ <!-- ══════════════════════════════════════════════════════════════════ -->
876
+ <!-- STEP 6: SECURITY SCAN AND REPORT -->
877
+ <!-- ══════════════════════════════════════════════════════════════════ -->
878
+
879
+ <step name="report" order="6">
880
+
881
+ <substep order="5.1" name="security-scan">
882
+ Security scan across all affected subsystems — use the Grep tool (NOT bash grep):
883
+
884
+ ```
885
+ Grep(
886
+ pattern="(sk-[a-zA-Z0-9]{20,}|sk_live_|sk_test_|ghp_[a-zA-Z0-9]{36}|AKIA[A-Z0-9]{16}|-----BEGIN.*PRIVATE KEY)",
887
+ path=".docs/wiki/subsystems/",
888
+ output_mode="content"
889
+ )
890
+ ```
891
+
892
+ <variant condition="matches found">SECRETS_FOUND — pause and alert user.</variant>
893
+ <variant condition="no matches">CLEAN.</variant>
894
+ </substep>
895
+
896
+ <substep order="5.2" name="display-report">
897
+
898
+ <!-- ── Story Mode Report ──────────────────────────────────────── -->
899
+
900
+ <mode name="story">
901
+ Display the combined report:
902
+
903
+ ```
904
+ ┌──────────────────────────────────────────────────┐
905
+ │ ACE > Map Story > Complete │
906
+ └──────────────────────────────────────────────────┘
907
+
908
+ ## Documentation Update Report
909
+
910
+ **Story**: [story name from artifacts, or "Git changes"]
911
+ **Affected Subsystems**: [list]
912
+
913
+ [If new_subsystem_reports is not empty:]
914
+
915
+ ### New Subsystems Mapped (via map-subsystem)
916
+ [For each new subsystem report:]
917
+ - **[subsystem.name]** at `[subsystem.path]` — [modules] modules, [docs] knowledge docs
918
+ Docs: `.docs/wiki/subsystems/[subsystem.name]/`
919
+
920
+ [For each remaining subsystem, include the agent's report:]
921
+
922
+ ### [subsystem_name]
923
+
924
+ Documents created:
925
+ - [path] ([line count] lines) — [description]
926
+
927
+ Documents updated:
928
+ - [path] — [what changed]
929
+
930
+ [If tech debt was integrated:]
931
+ ### Tech Debt Integrated
932
+ - [N] items added across [M] subsystem wiki docs
933
+ - Tech debt index updated: .docs/wiki/system-wide/tech-debt-index.md
934
+
935
+ [If any agent failures:]
936
+ ### Failures
937
+ - [subsystem]: [error]
938
+
939
+ [If any agent reports contain walkthrough suggestions:]
940
+
941
+ ### Walkthrough Suggestions
942
+
943
+ [For each suggestion, numbered:]
944
+ [N]. [flow description]
945
+ Subsystem: [subsystem] | Emphasis: [frameworks or "none"]
946
+ [reason]
947
+ ```
948
+
949
+ **If walkthrough suggestions exist:**
950
+ Use AskUserQuestion:
951
+ - header: "Walkthroughs"
952
+ - question: "Would you like to create any of these walkthroughs?\nYou can also describe your own."
953
+ - options:
954
+ - "Create [numbers]" — e.g., "Create 1,3" or "Create all"
955
+ - "Custom" — user describes their own walkthrough
956
+ - "Skip" — no walkthroughs
957
+
958
+ **If "Skip":** Display next steps and end.
959
+
960
+ **If "Create [numbers]" or "Create all":**
961
+ For each selected suggestion, spawn a background agent:
962
+
963
+ ```
964
+ Agent(
965
+ prompt="/ace:map-walkthrough flow=\"{suggestion.flow}\" subsystem=\"{suggestion.subsystem}\" emphasis-frameworks=\"{suggestion.emphasis}\"
966
+
967
+ Execute the map-walkthrough workflow end-to-end.",
968
+ subagent_type="ace-wiki-mapper",
969
+ run_in_background=true,
970
+ description="Walkthrough: {short flow name}"
971
+ )
972
+ ```
973
+
974
+ **If "Custom":**
975
+ Ask the user for their flow description, subsystem, and optional emphasis-frameworks.
976
+ Spawn a background agent for that walkthrough too.
977
+
978
+ Wait for all walkthrough agents to complete.
979
+
980
+ Display:
981
+ ```
982
+ + [N] walkthrough(s) created.
983
+ [For each: path and line count]
984
+ ```
985
+
986
+ Stage and commit walkthrough files:
987
+ ```bash
988
+ git add .docs/wiki/subsystems/*/walkthroughs/
989
+ git commit -m "docs: add walkthroughs from map-story suggestions"
990
+ ```
991
+
992
+ **After walkthroughs (or if no suggestions):**
993
+
994
+ ```
995
+ Next > `/clear` first for a fresh context window, then:
996
+
997
+ /ace:map-story — document another story
998
+ /ace:map-walkthrough — create another walkthrough
999
+ /ace:map-subsystem [subsystem] — map or refresh an entire subsystem
1000
+ Review files in .docs/wiki/subsystems/
1001
+ ```
1002
+ </mode>
1003
+
1004
+ <!-- ── File Mode Report ───────────────────────────────────────── -->
1005
+
1006
+ <mode name="file">
1007
+ Return the agent's report directly to the calling workflow
1008
+ (map-subsystem step 8.7). Do NOT display banners or next steps —
1009
+ the calling workflow handles presentation.
1010
+ </mode>
1011
+
1012
+ </substep>
1013
+
1014
+ End workflow.
1015
+ </step>
1016
+
1017
+ </process>
1018
+
1019
+ <success_criteria>
1020
+ <criterion>Mode correctly detected from parameters</criterion>
1021
+ <criterion>subsystem_work map built correctly from either mode's inputs</criterion>
1022
+ <criterion>One agent spawned per subsystem (parallel when 2+)</criterion>
1023
+ <criterion>Each agent reads ALL source files for its subsystem (not just names)</criterion>
1024
+ <criterion>Each agent reads ALL existing wiki docs for its subsystem FULLY (not summaries, not titles — complete content)</criterion>
1025
+ <criterion>Each agent checks every existing doc before deciding create vs update</criterion>
1026
+ <criterion>No duplicate documentation created — agent merges into existing docs when topic overlaps</criterion>
1027
+ <criterion>No story-scoped or module-scoped documents created (all topic-scoped)</criterion>
1028
+ <criterion>Each document follows its template structure from the XML templates</criterion>
1029
+ <criterion>Updates ADD to existing docs rather than rewriting unchanged sections</criterion>
1030
+ <criterion>Code references use `file:Symbol` format (not line numbers)</criterion>
1031
+ <criterion>File trees use ASCII only (no Unicode box-drawing)</criterion>
1032
+ <criterion>Diagrams use mermaid (not ASCII art)</criterion>
1033
+ <criterion>Every systems/*.md doc has at least one mermaid sequenceDiagram (E2E flow is mandatory)</criterion>
1034
+ <criterion>Inline code only for interface/type contracts</criterion>
1035
+ <criterion>Related systems cross-referenced with markdown links</criterion>
1036
+ <criterion>Tech debt items integrated into relevant subsystem wiki docs (if provided)</criterion>
1037
+ <criterion>Tech debt index updated with new items and recalculated counts (if provided)</criterion>
1038
+ <criterion>Security scan passed (no secrets in generated docs)</criterion>
1039
+ <criterion>Clear structured report from each agent, merged into final report</criterion>
1040
+ <criterion>New subsystems detected by comparing subsystem_work against system-structure.md Subsystem Index (story mode only)</criterion>
1041
+ <criterion>User approval required before running map-subsystem on new subsystems</criterion>
1042
+ <criterion>New subsystems removed from subsystem_work after map-subsystem to prevent duplicate docs</criterion>
1043
+ <criterion>New subsystem mapping results included in final report</criterion>
1044
+ </success_criteria>
1045
+
1046
+ </workflow>