agile-context-engineering 0.3.0 → 0.5.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 (139) hide show
  1. package/.claude-plugin/marketplace.json +18 -0
  2. package/.claude-plugin/plugin.json +10 -0
  3. package/CHANGELOG.md +7 -1
  4. package/LICENSE +51 -51
  5. package/README.md +330 -318
  6. package/agents/ace-code-discovery-analyst.md +245 -245
  7. package/agents/ace-code-integration-analyst.md +248 -248
  8. package/agents/ace-code-reviewer.md +375 -375
  9. package/agents/ace-product-owner.md +365 -361
  10. package/agents/ace-project-researcher.md +606 -606
  11. package/agents/ace-research-synthesizer.md +228 -228
  12. package/agents/ace-technical-application-architect.md +315 -315
  13. package/agents/ace-wiki-mapper.md +449 -445
  14. package/bin/install.js +605 -195
  15. package/hooks/ace-check-update.js +71 -62
  16. package/hooks/ace-statusline.js +107 -89
  17. package/hooks/hooks.json +14 -0
  18. package/package.json +7 -5
  19. package/shared/lib/ace-core.js +361 -0
  20. package/shared/lib/ace-core.test.js +308 -0
  21. package/shared/lib/ace-github.js +753 -0
  22. package/shared/lib/ace-story.js +400 -0
  23. package/shared/lib/ace-story.test.js +250 -0
  24. package/{agile-context-engineering → shared}/utils/questioning.xml +110 -110
  25. package/{agile-context-engineering → shared}/utils/ui-formatting.md +299 -299
  26. package/{commands/ace/execute-story.md → skills/execute-story/SKILL.md} +116 -138
  27. package/skills/execute-story/script.js +291 -0
  28. package/skills/execute-story/script.test.js +261 -0
  29. package/{agile-context-engineering/templates/product/story.xml → skills/execute-story/story-template.xml} +451 -451
  30. package/skills/execute-story/walkthrough-template.xml +255 -0
  31. package/{agile-context-engineering/workflows/execute-story.xml → skills/execute-story/workflow.xml} +1221 -1219
  32. package/skills/help/SKILL.md +71 -0
  33. package/skills/help/script.js +315 -0
  34. package/skills/help/script.test.js +183 -0
  35. package/{agile-context-engineering/workflows/help.xml → skills/help/workflow.xml} +544 -533
  36. package/{commands/ace/init-coding-standards.md → skills/init-coding-standards/SKILL.md} +91 -83
  37. package/{agile-context-engineering/templates/wiki/coding-standards.xml → skills/init-coding-standards/coding-standards-template.xml} +531 -531
  38. package/skills/init-coding-standards/script.js +50 -0
  39. package/skills/init-coding-standards/script.test.js +70 -0
  40. package/{agile-context-engineering/workflows/init-coding-standards.xml → skills/init-coding-standards/workflow.xml} +381 -386
  41. package/skills/map-cross-cutting/SKILL.md +126 -0
  42. package/{agile-context-engineering/templates/wiki → skills/map-cross-cutting}/system-cross-cutting.xml +197 -197
  43. package/skills/map-cross-cutting/workflow.xml +330 -0
  44. package/skills/map-guide/SKILL.md +126 -0
  45. package/{agile-context-engineering/templates/wiki → skills/map-guide}/guide.xml +137 -137
  46. package/skills/map-guide/workflow.xml +320 -0
  47. package/skills/map-pattern/SKILL.md +125 -0
  48. package/{agile-context-engineering/templates/wiki → skills/map-pattern}/pattern.xml +159 -159
  49. package/skills/map-pattern/workflow.xml +331 -0
  50. package/{commands/ace/map-story.md → skills/map-story/SKILL.md} +180 -165
  51. package/{agile-context-engineering/templates/wiki → skills/map-story/templates}/decizions.xml +115 -115
  52. package/skills/map-story/templates/guide.xml +137 -0
  53. package/skills/map-story/templates/pattern.xml +159 -0
  54. package/skills/map-story/templates/system-cross-cutting.xml +197 -0
  55. package/{agile-context-engineering/templates/wiki → skills/map-story/templates}/system.xml +381 -381
  56. package/{agile-context-engineering/templates/wiki → skills/map-story/templates}/tech-debt-index.xml +125 -125
  57. package/{agile-context-engineering/templates/wiki → skills/map-story/templates}/walkthrough.xml +255 -255
  58. package/{agile-context-engineering/workflows/map-story.xml → skills/map-story/workflow.xml} +1046 -1046
  59. package/{commands/ace/map-subsystem.md → skills/map-subsystem/SKILL.md} +155 -140
  60. package/skills/map-subsystem/script.js +51 -0
  61. package/skills/map-subsystem/script.test.js +68 -0
  62. package/skills/map-subsystem/templates/decizions.xml +115 -0
  63. package/skills/map-subsystem/templates/guide.xml +137 -0
  64. package/{agile-context-engineering/templates/wiki → skills/map-subsystem/templates}/module-discovery.xml +174 -174
  65. package/skills/map-subsystem/templates/pattern.xml +159 -0
  66. package/{agile-context-engineering/templates/wiki → skills/map-subsystem/templates}/subsystem-architecture.xml +343 -343
  67. package/{agile-context-engineering/templates/wiki → skills/map-subsystem/templates}/subsystem-structure.xml +234 -234
  68. package/skills/map-subsystem/templates/system-cross-cutting.xml +197 -0
  69. package/skills/map-subsystem/templates/system.xml +381 -0
  70. package/skills/map-subsystem/templates/walkthrough.xml +255 -0
  71. package/{agile-context-engineering/workflows/map-subsystem.xml → skills/map-subsystem/workflow.xml} +1173 -1178
  72. package/skills/map-sys-doc/SKILL.md +125 -0
  73. package/skills/map-sys-doc/system.xml +381 -0
  74. package/skills/map-sys-doc/workflow.xml +336 -0
  75. package/{commands/ace/map-system.md → skills/map-system/SKILL.md} +103 -92
  76. package/skills/map-system/script.js +75 -0
  77. package/skills/map-system/script.test.js +73 -0
  78. package/{agile-context-engineering/templates/wiki → skills/map-system/templates}/system-architecture.xml +254 -254
  79. package/{agile-context-engineering/templates/wiki → skills/map-system/templates}/system-structure.xml +177 -177
  80. package/{agile-context-engineering/templates/wiki → skills/map-system/templates}/testing-framework.xml +283 -283
  81. package/{agile-context-engineering/templates/wiki → skills/map-system/templates}/wiki-readme.xml +296 -296
  82. package/{agile-context-engineering/workflows/map-system.xml → skills/map-system/workflow.xml} +667 -672
  83. package/{commands/ace/map-walkthrough.md → skills/map-walkthrough/SKILL.md} +140 -127
  84. package/skills/map-walkthrough/walkthrough.xml +255 -0
  85. package/{agile-context-engineering/workflows/map-walkthrough.xml → skills/map-walkthrough/workflow.xml} +457 -457
  86. package/{commands/ace/plan-backlog.md → skills/plan-backlog/SKILL.md} +93 -83
  87. package/{agile-context-engineering/templates/product/product-backlog.xml → skills/plan-backlog/product-backlog-template.xml} +231 -231
  88. package/skills/plan-backlog/script.js +121 -0
  89. package/skills/plan-backlog/script.test.js +83 -0
  90. package/{agile-context-engineering/workflows/plan-backlog.xml → skills/plan-backlog/workflow.xml} +1348 -1356
  91. package/{commands/ace/plan-feature.md → skills/plan-feature/SKILL.md} +99 -89
  92. package/{agile-context-engineering/templates/product/feature.xml → skills/plan-feature/feature-template.xml} +361 -361
  93. package/skills/plan-feature/script.js +131 -0
  94. package/skills/plan-feature/script.test.js +80 -0
  95. package/{agile-context-engineering/workflows/plan-feature.xml → skills/plan-feature/workflow.xml} +1487 -1495
  96. package/{commands/ace/plan-product-vision.md → skills/plan-product-vision/SKILL.md} +91 -81
  97. package/{agile-context-engineering/templates/product/product-vision.xml → skills/plan-product-vision/product-vision-template.xml} +227 -227
  98. package/skills/plan-product-vision/script.js +51 -0
  99. package/skills/plan-product-vision/script.test.js +69 -0
  100. package/{agile-context-engineering/workflows/plan-product-vision.xml → skills/plan-product-vision/workflow.xml} +337 -342
  101. package/{commands/ace/plan-story.md → skills/plan-story/SKILL.md} +139 -159
  102. package/skills/plan-story/script.js +295 -0
  103. package/skills/plan-story/script.test.js +240 -0
  104. package/skills/plan-story/story-template.xml +458 -0
  105. package/{agile-context-engineering/workflows/plan-story.xml → skills/plan-story/workflow.xml} +1301 -944
  106. package/{commands/ace/research-external-solution.md → skills/research-external-solution/SKILL.md} +120 -138
  107. package/{agile-context-engineering/templates/product/external-solution.xml → skills/research-external-solution/external-solution-template.xml} +832 -832
  108. package/skills/research-external-solution/script.js +229 -0
  109. package/skills/research-external-solution/script.test.js +134 -0
  110. package/{agile-context-engineering/workflows/research-external-solution.xml → skills/research-external-solution/workflow.xml} +657 -659
  111. package/{commands/ace/research-integration-solution.md → skills/research-integration-solution/SKILL.md} +121 -135
  112. package/{agile-context-engineering/templates/product/story-integration-solution.xml → skills/research-integration-solution/integration-solution-template.xml} +1015 -1015
  113. package/skills/research-integration-solution/script.js +223 -0
  114. package/skills/research-integration-solution/script.test.js +134 -0
  115. package/{agile-context-engineering/workflows/research-integration-solution.xml → skills/research-integration-solution/workflow.xml} +711 -713
  116. package/{commands/ace/research-story-wiki.md → skills/research-story-wiki/SKILL.md} +101 -116
  117. package/skills/research-story-wiki/script.js +223 -0
  118. package/skills/research-story-wiki/script.test.js +138 -0
  119. package/{agile-context-engineering/templates/product/story-wiki.xml → skills/research-story-wiki/story-wiki-template.xml} +194 -194
  120. package/{agile-context-engineering/workflows/research-story-wiki.xml → skills/research-story-wiki/workflow.xml} +473 -475
  121. package/{commands/ace/research-technical-solution.md → skills/research-technical-solution/SKILL.md} +131 -147
  122. package/skills/research-technical-solution/script.js +223 -0
  123. package/skills/research-technical-solution/script.test.js +134 -0
  124. package/{agile-context-engineering/templates/product/story-technical-solution.xml → skills/research-technical-solution/technical-solution-template.xml} +1025 -1025
  125. package/{agile-context-engineering/workflows/research-technical-solution.xml → skills/research-technical-solution/workflow.xml} +761 -763
  126. package/{commands/ace/review-story.md → skills/review-story/SKILL.md} +99 -109
  127. package/skills/review-story/script.js +249 -0
  128. package/skills/review-story/script.test.js +169 -0
  129. package/skills/review-story/story-template.xml +451 -0
  130. package/{agile-context-engineering/workflows/review-story.xml → skills/review-story/workflow.xml} +279 -281
  131. package/{commands/ace/update.md → skills/update/SKILL.md} +65 -56
  132. package/{agile-context-engineering/workflows/update.xml → skills/update/workflow.xml} +33 -18
  133. package/agile-context-engineering/src/ace-tools.js +0 -2881
  134. package/agile-context-engineering/src/ace-tools.test.js +0 -1089
  135. package/agile-context-engineering/templates/_command.md +0 -54
  136. package/agile-context-engineering/templates/_workflow.xml +0 -17
  137. package/agile-context-engineering/templates/config.json +0 -0
  138. package/agile-context-engineering/templates/product/integration-solution.xml +0 -0
  139. package/commands/ace/help.md +0 -93
@@ -1,1178 +1,1173 @@
1
- <workflow>
2
-
3
- <purpose>
4
- Orchestrate subsystem wiki mapping: resolve the target subsystem, load system-wide context,
5
- determine which documents need creation or updates, spawn ace-wiki-mapper agents to produce
6
- them, run module discovery, and generate knowledge documentation via map-story.
7
-
8
- Produces documents in `.docs/wiki/subsystems/[subsystem-name]/`:
9
- - structure.md — physical file layout within the subsystem
10
- - architecture.md — L3 component view, flows, dependencies, data ownership
11
- - systems/*.md — domain system documentation (via map-story)
12
- - patterns/*.md — reusable implementation patterns (via map-story)
13
- - cross-cutting/*.md — concerns spanning multiple systems (via map-story)
14
- - guides/*.md — step-by-step recipes for common tasks (via map-story)
15
- - walkthroughs/*.md — deep tutorial-style flow explanations (via map-story)
16
- - decisions/*.md — architecture decision records (via map-story)
17
-
18
- Also produces `.ace/artifacts/subsystems/[subsystem-name]/module-discovery/module-discovery.md`.
19
-
20
- May also update `.docs/wiki/system-wide/system-structure.md` if this subsystem
21
- is not yet listed there, and `.docs/wiki/system-wide/system-architecture.md` if
22
- the subsystem is missing from the Subsystem Responsibility Matrix.
23
- </purpose>
24
-
25
- <mandatory-context>
26
- Read all files referenced by the invoking command's execution-context before starting.
27
- Also read any document or text passed as parameter ($ARGUMENTS) in the invoking command.
28
- </mandatory-context>
29
-
30
- <process>
31
-
32
- <!-- ══════════════════════════════════════════════════════════════════ -->
33
- <!-- STEP 1: SETUP -->
34
- <!-- ══════════════════════════════════════════════════════════════════ -->
35
-
36
- <step name="setup" order="1">
37
-
38
- <substep order="1.1" name="environment-detection">
39
- MANDATORY FIRST STEP — Execute environment detection before any user interaction:
40
-
41
- ```bash
42
- INIT=$(node ~/.claude/agile-context-engineering/src/ace-tools.js init map-subsystem)
43
- ```
44
-
45
- Parse JSON for: `mapper_model`, `commit_docs`, `is_brownfield`, `wiki_dir_exists`, `has_git`.
46
- </substep>
47
-
48
- <substep order="1.2" name="resolve-mapper-model">
49
- Resolve the mapper model for spawning agents:
50
-
51
- ```bash
52
- MAPPER_MODEL=$(node ~/.claude/agile-context-engineering/src/ace-tools.js resolve-model ace-wiki-mapper --raw)
53
- ```
54
- </substep>
55
-
56
- <substep order="1.3" name="display-banner">
57
- Display stage banner:
58
-
59
- ```
60
- ╔══════════════════════════════════════════════════╗
61
- ║ ACE > Map Subsystem ║
62
- ╚══════════════════════════════════════════════════╝
63
- ```
64
- </substep>
65
-
66
- <substep order="1.4" name="resolve-input">
67
- <variant condition="subsystem was NOT provided in $ARGUMENTS">
68
- List top-level directories to offer as options, then use AskUserQuestion:
69
- - header: "Subsystem"
70
- - question: "Which subsystem would you like to map? Provide the path (e.g., `src/api`) or its name."
71
- - options: (top 3 candidate paths from the codebase, plus a free-text prompt)
72
- </variant>
73
- </substep>
74
-
75
- Continue to step 2.
76
- </step>
77
-
78
- <!-- ══════════════════════════════════════════════════════════════════ -->
79
- <!-- STEP 2: LOAD SYSTEM-WIDE CONTEXT -->
80
- <!-- ══════════════════════════════════════════════════════════════════ -->
81
-
82
- <step name="load-context" order="2">
83
- Read system-wide documents for context before analyzing the subsystem.
84
- These orient the mapper agent and prevent repeating system-level content
85
- in the subsystem docs.
86
-
87
- <substep order="2.1" name="read-system-docs">
88
- Read (if they exist):
89
- <file-list>
90
- <file path=".docs/wiki/system-wide/system-structure.md" />
91
- <file path=".docs/wiki/system-wide/system-architecture.md" />
92
- </file-list>
93
- </substep>
94
-
95
- <substep order="2.2" name="check-subsystem-index">
96
- While reading `system-structure.md`, check whether the target subsystem is already
97
- listed in the Subsystem Index. Set `is_new_subsystem = true` if it is NOT found.
98
- </substep>
99
-
100
- <substep order="2.3" name="check-responsibility-matrix">
101
- While reading `system-architecture.md`, check whether the target subsystem appears
102
- in the Subsystem Responsibility Matrix. Set `is_missing_from_matrix = true` if it
103
- is NOT found.
104
-
105
- <variant condition="system-architecture.md does not exist">
106
- Set `is_missing_from_matrix = false` and note to the user that
107
- system-architecture.md should be created via `/ace:map-system`.
108
- </variant>
109
- </substep>
110
-
111
- Continue to step 3.
112
- </step>
113
-
114
- <!-- ══════════════════════════════════════════════════════════════════ -->
115
- <!-- STEP 3: RESOLVE SUBSYSTEM -->
116
- <!-- ══════════════════════════════════════════════════════════════════ -->
117
-
118
- <step name="resolve-subsystem" order="3">
119
-
120
- <substep order="3.1" name="normalize-input">
121
- Normalize the subsystem input to:
122
- <output-fields>
123
- <field name="subsystem_path">Relative path from project root (e.g., `src/api`)</field>
124
- <field name="subsystem_name">Slug for the wiki directory (e.g., `api`, `user-service`)</field>
125
- </output-fields>
126
- </substep>
127
-
128
- <substep order="3.2" name="validate-path">
129
- Validate that `subsystem_path` exists in the codebase.
130
-
131
- <variant condition="path not found">
132
- Use AskUserQuestion to clarify — list candidate paths matching the input.
133
- </variant>
134
-
135
- <variant condition="input is ambiguous (name matches multiple directories)">
136
- Use AskUserQuestion with the candidates as options.
137
- </variant>
138
- </substep>
139
-
140
- <substep order="3.3" name="set-output-dir">
141
- Determine wiki output directory: `.docs/wiki/subsystems/[subsystem_name]/`
142
- </substep>
143
-
144
- Continue to step 4.
145
- </step>
146
-
147
- <!-- ══════════════════════════════════════════════════════════════════ -->
148
- <!-- STEP 4: DOCUMENT TRIAGE -->
149
- <!-- Determine per-document action: create, update, recreate, or skip -->
150
- <!-- ══════════════════════════════════════════════════════════════════ -->
151
-
152
- <step name="document-triage" order="4">
153
-
154
- <substep order="4.1" name="check-existing">
155
- Check for existing documents in `.docs/wiki/subsystems/[subsystem_name]/`:
156
- <flags>
157
- <flag name="has_structure">Does `structure.md` exist?</flag>
158
- <flag name="has_architecture">Does `architecture.md` exist?</flag>
159
- </flags>
160
- </substep>
161
-
162
- <substep order="4.2" name="triage-structure">
163
- Evaluate structure.md:
164
-
165
- <variant condition="has_structure is false">
166
- Action: `create` — analyze subsystem and produce full document.
167
- </variant>
168
-
169
- <variant condition="has_structure is true">
170
- Use AskUserQuestion:
171
- - header: "Structure"
172
- - question: "Structure document already exists at `.docs/wiki/subsystems/[subsystem_name]/structure.md`. What would you like to do?"
173
- - options:
174
- - "Update" — Refresh the existing document with current codebase state
175
- - "Recreate" — Discard and rebuild from scratch
176
- - "Skip" — Keep the current document as-is
177
- Map user choice to action: `update`, `recreate`, or `skip`.
178
- </variant>
179
- </substep>
180
-
181
- <substep order="4.3" name="triage-architecture">
182
- Evaluate architecture.md:
183
-
184
- <variant condition="has_architecture is false">
185
- Action: `create` — analyze subsystem and produce full document.
186
- </variant>
187
-
188
- <variant condition="has_architecture is true">
189
- Use AskUserQuestion:
190
- - header: "Architecture"
191
- - question: "Architecture document already exists at `.docs/wiki/subsystems/[subsystem_name]/architecture.md`. What would you like to do?"
192
- - options:
193
- - "Update" — Refresh the existing document with current codebase state
194
- - "Recreate" — Discard and rebuild from scratch
195
- - "Skip" — Keep the current document as-is
196
- Map user choice to action: `update`, `recreate`, or `skip`.
197
- </variant>
198
- </substep>
199
-
200
- <substep order="4.4" name="batch-questions">
201
- IMPORTANT: Ask all questions that need asking in a SINGLE AskUserQuestion call
202
- where possible (up to 4 questions). If both documents exist, batch the questions.
203
-
204
- NEVER pass `answers` or `annotations` parameters in AskUserQuestion — only pass `questions`.
205
- The user must answer interactively. If the response comes back empty, re-ask.
206
- </substep>
207
-
208
- <substep order="4.5" name="display-action-plan">
209
- Display the action plan to the user:
210
-
211
- ```
212
- ┌──────────────────────────────────────────────────┐
213
- │ ACE > Map Subsystem > Action Plan │
214
- └──────────────────────────────────────────────────┘
215
-
216
- Subsystem [subsystem_name] ([subsystem_path])
217
- ──────────────────────────────────────────────────
218
- Document Action
219
- ─────────────────── ──────────────────────────
220
- structure.md [create/update/recreate/skip]
221
- architecture.md [create/update/recreate/skip]
222
- ```
223
-
224
- <variant condition="ALL actions are skip">
225
- Exit workflow with message:
226
- ```
227
- i All documents already exist and were skipped. Nothing to do.
228
-
229
- Next > `/clear` first for a fresh context window, then:
230
-
231
- /ace:map-subsystem [next-subsystem]
232
- Map another subsystem.
233
- ```
234
- </variant>
235
- </substep>
236
-
237
- Continue to step 5.
238
- </step>
239
-
240
- <!-- ══════════════════════════════════════════════════════════════════ -->
241
- <!-- STEP 5: CREATE DIRECTORY STRUCTURE -->
242
- <!-- ══════════════════════════════════════════════════════════════════ -->
243
-
244
- <step name="create-directory" order="5">
245
- Create the subsystem wiki directory if it doesn't exist:
246
-
247
- ```bash
248
- mkdir -p .docs/wiki/subsystems/[subsystem_name]
249
- ```
250
-
251
- Continue to step 6.
252
- </step>
253
-
254
- <!-- ══════════════════════════════════════════════════════════════════ -->
255
- <!-- STEP 6: SUBSYSTEM STRUCTURE -->
256
- <!-- ══════════════════════════════════════════════════════════════════ -->
257
-
258
- <step name="subsystem-structure" order="6">
259
- Skip this step if structure action is `skip`.
260
-
261
- NOTE: This step can run IN PARALLEL with step 7 (architecture) if both
262
- need agent work. Use `run_in_background=true` for both agents in steps 6 and 7,
263
- then collect results in step 8.
264
-
265
- <variant condition="action is create or recreate">
266
- Spawn ace-wiki-mapper agent:
267
-
268
- ```
269
- Task(
270
- prompt="Focus: subsystem-structure
271
-
272
- Analyze this subsystem and produce its structure document.
273
-
274
- **Subsystem path:** [subsystem_path]
275
- **Subsystem name:** [subsystem_name]
276
-
277
- **Template:** Read ~/.claude/agile-context-engineering/templates/wiki/subsystem-structure.xml
278
- **System context (if exists):** Read .docs/wiki/system-wide/system-structure.md
279
- **Output:** Write to .docs/wiki/subsystems/[subsystem_name]/structure.md
280
-
281
- <agent-instructions>
282
- <instruction order="1" name="explore">
283
- Explore every file and directory within [subsystem_path].
284
- </instruction>
285
- <instruction order="2" name="write-sections">
286
- Follow the template and produce:
287
- <checklist>
288
- <item>Subsystem overview (root path, one-line responsibility)</item>
289
- <item>Full directory layout (ASCII tree of ALL files and directories with purpose comments)</item>
290
- <item>Directory purposes (one entry per meaningful directory)</item>
291
- <item>Key file locations grouped by role: entry points, config, core logic, API, tests</item>
292
- <item>Naming conventions (if different from system-wide; otherwise reference system-structure.md)</item>
293
- <item>Where to add new code (specific paths for each code type)</item>
294
- <item>Special directories (generated, build output, migrations, etc.)</item>
295
- </checklist>
296
- </instruction>
297
- </agent-instructions>
298
-
299
- Return confirmation only — do NOT return document contents.",
300
- subagent_type="ace-wiki-mapper",
301
- model="{MAPPER_MODEL}",
302
- description="Map subsystem structure"
303
- )
304
- ```
305
- </variant>
306
-
307
- <variant condition="action is update">
308
- Spawn ace-wiki-mapper agent with existing content as context:
309
-
310
- ```
311
- Task(
312
- prompt="Focus: subsystem-structure
313
-
314
- UPDATE the existing structure document for this subsystem.
315
-
316
- **Subsystem path:** [subsystem_path]
317
- **Current document:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
318
- **Template:** Read ~/.claude/agile-context-engineering/templates/wiki/subsystem-structure.xml
319
-
320
- <agent-instructions>
321
- <instruction order="1" name="compare">
322
- Compare the current document against the actual codebase state.
323
- </instruction>
324
- <instruction order="2" name="update-sections">
325
- <checklist>
326
- <item>Update the directory tree for any new or removed files and directories</item>
327
- <item>Update key file locations if entry points or core files have changed</item>
328
- <item>Update 'Where to add new code' if new directories or patterns were introduced</item>
329
- <item>Remove entries for deleted directories or files</item>
330
- </checklist>
331
- </instruction>
332
- <instruction order="3" name="preserve">
333
- Preserve accurate content. Only change what is actually stale.
334
- </instruction>
335
- </agent-instructions>
336
-
337
- Write the updated file to .docs/wiki/subsystems/[subsystem_name]/structure.md
338
- Return confirmation only — do NOT return document contents.",
339
- subagent_type="ace-wiki-mapper",
340
- model="{MAPPER_MODEL}",
341
- description="Update subsystem structure"
342
- )
343
- ```
344
- </variant>
345
-
346
- Continue to step 7.
347
- </step>
348
-
349
- <!-- ══════════════════════════════════════════════════════════════════ -->
350
- <!-- STEP 7: SUBSYSTEM ARCHITECTURE -->
351
- <!-- ══════════════════════════════════════════════════════════════════ -->
352
-
353
- <step name="subsystem-architecture" order="7">
354
- Skip this step if architecture action is `skip`.
355
-
356
- <variant condition="action is create or recreate">
357
- Spawn ace-wiki-mapper agent:
358
-
359
- ```
360
- Task(
361
- prompt="Focus: subsystem-architecture
362
-
363
- Analyze this subsystem and produce its architecture document.
364
-
365
- **Subsystem path:** [subsystem_path]
366
- **Subsystem name:** [subsystem_name]
367
-
368
- **Template:** Read ~/.claude/agile-context-engineering/templates/wiki/subsystem-architecture.xml
369
- **System context (if exists):** Read .docs/wiki/system-wide/system-architecture.md
370
- **Structure doc (if exists):** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
371
- **Output:** Write to .docs/wiki/subsystems/[subsystem_name]/architecture.md
372
-
373
- <agent-instructions>
374
- <instruction order="1" name="analyze">
375
- Follow the template structure. Fill every section with real data from the subsystem.
376
- </instruction>
377
- <instruction order="2" name="write-sections">
378
- <checklist>
379
- <item>Subsystem context: one-line responsibility and system connections (inbound/outbound)</item>
380
- <item>L3 component diagram: internal layers (API -> Application -> Domain -> Infrastructure -> Data)</item>
381
- <item>Component responsibilities table with key file paths</item>
382
- <item>Key internal flows: 1-3 sequence diagrams for the core operations</item>
383
- <item>Dependency inventory: inbound callers, outbound dependencies with failure handling</item>
384
- <item>Data ownership: tables, schemas, topics this subsystem owns</item>
385
- <item>Subsystem architectural decisions</item>
386
- </checklist>
387
- </instruction>
388
- <instruction order="3" name="avoid-duplication">
389
- Do NOT repeat system-wide architecture content. Reference system-architecture.md where appropriate.
390
- </instruction>
391
- </agent-instructions>
392
-
393
- Return confirmation only — do NOT return document contents.",
394
- subagent_type="ace-wiki-mapper",
395
- model="{MAPPER_MODEL}",
396
- description="Map subsystem architecture"
397
- )
398
- ```
399
- </variant>
400
-
401
- <variant condition="action is update">
402
- Spawn ace-wiki-mapper agent with update instructions:
403
-
404
- ```
405
- Task(
406
- prompt="Focus: subsystem-architecture
407
-
408
- UPDATE the existing architecture document for this subsystem.
409
-
410
- **Subsystem path:** [subsystem_path]
411
- **Current document:** Read .docs/wiki/subsystems/[subsystem_name]/architecture.md
412
- **Template:** Read ~/.claude/agile-context-engineering/templates/wiki/subsystem-architecture.xml
413
- **System context (if exists):** Read .docs/wiki/system-wide/system-architecture.md
414
-
415
- <agent-instructions>
416
- <instruction order="1" name="compare">
417
- Compare against current codebase state. Check for:
418
- <checklist>
419
- <item>New or removed internal components?</item>
420
- <item>New inbound callers or outbound dependencies?</item>
421
- <item>Data ownership changes (new tables, schemas, topics)?</item>
422
- <item>Core internal flows changed shape?</item>
423
- <item>New subsystem-specific architectural decisions?</item>
424
- </checklist>
425
- </instruction>
426
- <instruction order="2" name="apply-updates">
427
- Update only stale sections. Preserve accurate content.
428
- </instruction>
429
- </agent-instructions>
430
-
431
- Write the updated file to .docs/wiki/subsystems/[subsystem_name]/architecture.md
432
- Return confirmation only — do NOT return document contents.",
433
- subagent_type="ace-wiki-mapper",
434
- model="{MAPPER_MODEL}",
435
- description="Update subsystem architecture"
436
- )
437
- ```
438
- </variant>
439
-
440
- Continue to step 8.
441
- </step>
442
-
443
- <!-- ══════════════════════════════════════════════════════════════════ -->
444
- <!-- STEP 8: COLLECT PARALLEL RESULTS -->
445
- <!-- ══════════════════════════════════════════════════════════════════ -->
446
-
447
- <step name="collect-parallel" order="8">
448
-
449
- <substep order="8.1" name="wait-for-agents">
450
- If steps 6 and 7 spawned background agents, wait for both to complete.
451
- Read each agent's output to collect confirmations.
452
- </substep>
453
-
454
- <substep order="8.2" name="handle-failures">
455
- If any agent failed, note the failure and inform the user.
456
- Do NOT re-attempt — let the user decide.
457
- </substep>
458
-
459
- Continue to step 9.
460
- </step>
461
-
462
- <!-- ══════════════════════════════════════════════════════════════════ -->
463
- <!-- STEP 9: UPDATE SYSTEM-WIDE STRUCTURE -->
464
- <!-- ══════════════════════════════════════════════════════════════════ -->
465
-
466
- <step name="update-system-wide" order="9">
467
- Execute all applicable sub-steps. Both agents can run IN PARALLEL if both are needed —
468
- use `run_in_background=true` and collect results before step 10.
469
-
470
- <substep order="9a" name="update-system-structure" condition="is_new_subsystem is true">
471
- Only execute if `is_new_subsystem` is true.
472
-
473
- <variant condition="system-structure.md does not exist">
474
- Skip 9a and note to the user that system-structure.md should be created via `/ace:map-system`.
475
- </variant>
476
-
477
- <variant condition="system-structure.md exists">
478
- ```
479
- Task(
480
- prompt="Focus: system-structure (partial update — add new subsystem entry)
481
-
482
- A new subsystem has just been documented. Add it to the system-wide structure document.
483
-
484
- **New subsystem:** [subsystem_name] at [subsystem_path]
485
- **Current document:** Read .docs/wiki/system-wide/system-structure.md
486
- **Newly created docs:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
487
- and .docs/wiki/subsystems/[subsystem_name]/architecture.md to infer responsibility.
488
-
489
- <agent-instructions>
490
- <instruction order="1" name="add-row">
491
- Add this subsystem to the Subsystem Index table with:
492
- <checklist>
493
- <item>Name, path, one-line responsibility (inferred from the subsystem code and its new docs)</item>
494
- <item>Wiki doc link: `.docs/wiki/subsystems/[subsystem_name]/`</item>
495
- </checklist>
496
- </instruction>
497
- <instruction order="2" name="preserve">
498
- Do NOT restructure or rewrite the existing document. Only add the new row.
499
- </instruction>
500
- </agent-instructions>
501
-
502
- Write the updated file to .docs/wiki/system-wide/system-structure.md
503
- Return confirmation only — do NOT return document contents.",
504
- subagent_type="ace-wiki-mapper",
505
- model="{MAPPER_MODEL}",
506
- description="Add subsystem to system structure"
507
- )
508
- ```
509
- </variant>
510
- </substep>
511
-
512
- <substep order="9b" name="update-system-architecture" condition="is_missing_from_matrix is true">
513
- Only execute if `is_missing_from_matrix` is true.
514
-
515
- ```
516
- Task(
517
- prompt="Focus: system-architecture (partial update — add subsystem to responsibility matrix)
518
-
519
- A subsystem has just been documented and is missing from the Subsystem Responsibility Matrix.
520
- Add it to the matrix in the system-wide architecture document.
521
-
522
- **Subsystem:** [subsystem_name] at [subsystem_path]
523
- **Current document:** Read .docs/wiki/system-wide/system-architecture.md
524
- **Subsystem docs:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
525
- and .docs/wiki/subsystems/[subsystem_name]/architecture.md to populate the row.
526
-
527
- <agent-instructions>
528
- <instruction order="1" name="add-matrix-row">
529
- Add one row to the Subsystem Responsibility Matrix table with:
530
- <checklist>
531
- <item>Subsystem name, one-line responsibility</item>
532
- <item>Data it owns</item>
533
- <item>Events/APIs it publishes</item>
534
- <item>Events/APIs it consumes</item>
535
- <item>Its tech stack</item>
536
- </checklist>
537
- </instruction>
538
- <instruction order="2" name="preserve">
539
- Do NOT restructure or rewrite any other part of the document. Only add the new row.
540
- </instruction>
541
- </agent-instructions>
542
-
543
- Write the updated file to .docs/wiki/system-wide/system-architecture.md
544
- Return confirmation only — do NOT return document contents.",
545
- subagent_type="ace-wiki-mapper",
546
- model="{MAPPER_MODEL}",
547
- description="Add subsystem to architecture matrix"
548
- )
549
- ```
550
- </substep>
551
-
552
- Continue to step 10.
553
- </step>
554
-
555
- <!-- ══════════════════════════════════════════════════════════════════ -->
556
- <!-- STEP 10: MODULE DISCOVERY -->
557
- <!-- ══════════════════════════════════════════════════════════════════ -->
558
-
559
- <step name="module-discovery" order="10">
560
- Discover the subsystem's documentation modules by reading the actual source code —
561
- NOT just the wiki docs. This step traces E2E flows, identifies patterns, and finds
562
- cross-cutting concerns by reading real implementation files.
563
-
564
- Uses THREE parallel discovery agents followed by ONE synthesis agent.
565
-
566
- <substep order="10.1" name="read-template">
567
- Read the module-discovery template first:
568
- `.claude/templates/module-discovery.xml`
569
- </substep>
570
-
571
- <substep order="10.2" name="create-artifacts-dir">
572
- Create artifacts directory:
573
-
574
- ```bash
575
- mkdir -p .ace/artifacts/subsystems/[subsystem_name]/module-discovery
576
- ```
577
- </substep>
578
-
579
- <substep order="10.3" name="launch-flow-discovery" parallel="true">
580
- Launch with run_in_background=true:
581
-
582
- ```
583
- Task(
584
- prompt="Focus: flow-discovery
585
-
586
- Discover the E2E domain flows in this subsystem by reading the actual source code.
587
- Do NOT rely on wiki docs alone — trace the code.
588
-
589
- **Subsystem path:** [subsystem_path]
590
- **Subsystem name:** [subsystem_name]
591
- **File inventory:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
592
-
593
- <agent-instructions>
594
- <instruction order="1" name="read-inventory">
595
- Read structure.md for the complete file inventory.
596
- </instruction>
597
- <instruction order="2" name="identify-entry-points">
598
- Identify ALL entry points: HTTP controllers, CLI handlers, event consumers,
599
- background jobs, gRPC services, scheduled tasks.
600
- </instruction>
601
- <instruction order="3" name="trace-flows">
602
- For EACH entry point, open and read the file — then trace its COMPLETE E2E flow:
603
- <checklist>
604
- <item>Follow all imports/dependencies downward layer by layer</item>
605
- <item>Collect every file that participates:
606
- entry point, DTO/viewmodel, mapper, service/use-case, domain entity,
607
- value objects, repository interface, repository implementation,
608
- DB scripts/migrations, constants/enums</item>
609
- <item>A domain model shared across flows belongs in ALL of them do NOT exclude it</item>
610
- <item>Read each file you encounter before moving on</item>
611
- </checklist>
612
- </instruction>
613
- <instruction order="4" name="group-systems">
614
- Group related entry points into one system when they share the same domain concern:
615
- CreateUser + GetUser + UpdateUser + DeleteUser = 'User Management' (not 4 systems)
616
- </instruction>
617
- </agent-instructions>
618
-
619
- Output to .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-flows.md:
620
-
621
- ```markdown
622
- # Flow Discovery: [subsystem_name]
623
-
624
- ## Systems Found
625
-
626
- | # | System Name | Entry Points | All Participating Files |
627
- |---|-------------|--------------|------------------------|
628
- | 1 | [name] | [entry file paths] | [ALL files in this E2E flow] |
629
- ```
630
-
631
- Return: count of systems found + list of any entry points you could not fully trace.",
632
- subagent_type="ace-wiki-mapper",
633
- model="{MAPPER_MODEL}",
634
- run_in_background=true,
635
- description="Discover E2E system flows"
636
- )
637
- ```
638
- </substep>
639
-
640
- <substep order="10.4" name="launch-pattern-discovery" parallel="true">
641
- Launch with run_in_background=true:
642
-
643
- ```
644
- Task(
645
- prompt="Focus: pattern-discovery
646
-
647
- Discover reusable implementation patterns in this subsystem by reading multiple
648
- similar files and comparing their structure.
649
-
650
- **Subsystem path:** [subsystem_path]
651
- **File inventory:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
652
-
653
- <agent-instructions>
654
- <instruction order="1" name="read-inventory">
655
- Read structure.md for the complete file inventory.
656
- </instruction>
657
- <instruction order="2" name="identify-groups">
658
- Identify groups of structurally similar files:
659
- repositories, mappers, handlers, command/query objects, factories, validators.
660
- </instruction>
661
- <instruction order="3" name="compare-files">
662
- Read 3+ files from each group.
663
- </instruction>
664
- <instruction order="4" name="classify-patterns">
665
- When files follow the same structural template, that is a pattern.
666
- Name the pattern by what it achieves, not by structural form.
667
-
668
- Examples of patterns to look for:
669
- <pattern-examples>
670
- <pattern>Repository Pattern (multiple repo implementations of one interface)</pattern>
671
- <pattern>CQRS Command/Query (separate handler per command/query)</pattern>
672
- <pattern>Template Method (abstract base class with overridable steps)</pattern>
673
- <pattern>Factory / Registry (lookup table for creating objects by type)</pattern>
674
- <pattern>Mapper Pattern (bidirectional DTO &lt;-&gt; domain conversion)</pattern>
675
- <pattern>Strategy Pattern (interchangeable algorithm implementations)</pattern>
676
- </pattern-examples>
677
- </instruction>
678
- </agent-instructions>
679
-
680
- Output to .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-patterns.md:
681
-
682
- ```markdown
683
- # Pattern Discovery: [subsystem_name]
684
-
685
- ## Patterns Found
686
-
687
- | # | Pattern Name | Representative Files (2-4 examples that demonstrate the pattern) |
688
- |---|--------------|------------------------------------------------------------------|
689
- | 1 | [name] | [2-4 file paths] |
690
- ```
691
-
692
- Return: count of patterns found.",
693
- subagent_type="ace-wiki-mapper",
694
- model="{MAPPER_MODEL}",
695
- run_in_background=true,
696
- description="Discover implementation patterns"
697
- )
698
- ```
699
- </substep>
700
-
701
- <substep order="10.5" name="launch-cross-cutting-discovery" parallel="true">
702
- Launch with run_in_background=true:
703
-
704
- ```
705
- Task(
706
- prompt="Focus: cross-cutting-discovery
707
-
708
- Discover cross-cutting concerns and common implementation tasks in this subsystem
709
- by reading shared infrastructure files.
710
-
711
- **Subsystem path:** [subsystem_path]
712
- **File inventory:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
713
- **Architecture doc:** .docs/wiki/subsystems/[subsystem_name]/architecture.md
714
-
715
- <agent-instructions>
716
- <instruction order="1" name="read-context">
717
- Read structure.md and architecture.md for context.
718
- </instruction>
719
- <instruction order="2" name="identify-shared-infra">
720
- Identify shared infrastructure that multiple domain flows depend on — then read it:
721
- <checklist>
722
- <item>DI container / service registration files</item>
723
- <item>Event bus, message broker, pub/sub infrastructure</item>
724
- <item>Cache / invalidation infrastructure</item>
725
- <item>Authentication / authorization middleware</item>
726
- <item>Shared abstract base classes</item>
727
- <item>Error handling and logging infrastructure</item>
728
- <item>Registry / factory lookup tables</item>
729
- </checklist>
730
- </instruction>
731
- <instruction order="3" name="assess-scope">
732
- For each shared infrastructure file, read it to understand its scope.
733
- </instruction>
734
- <instruction order="4" name="identify-guides">
735
- Identify guide candidates — common tasks a developer would repeat:
736
- <guide-derivation-rules>
737
- <rule source="Repository Pattern" guide="How to Add a New Repository" />
738
- <rule source="CRUD system exists" guide="How to Add a New CRUD Endpoint" />
739
- </guide-derivation-rules>
740
- </instruction>
741
- </agent-instructions>
742
-
743
- Output to .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-cross-cutting.md:
744
-
745
- ```markdown
746
- # Cross-Cutting Discovery: [subsystem_name]
747
-
748
- ## Cross-Cutting Concerns
749
-
750
- | # | Concern Name | Files |
751
- |---|--------------|-------|
752
- | 1 | [name] | [all files implementing this concern] |
753
-
754
- ## Guide Candidates
755
-
756
- | # | Guide Name | Reference Files |
757
- |---|------------|----------------|
758
- | 1 | [e.g., How to Add a New CRUD Endpoint] | [files demonstrating the recipe] |
759
- ```
760
-
761
- Return: count of cross-cutting concerns + count of guide candidates.",
762
- subagent_type="ace-wiki-mapper",
763
- model="{MAPPER_MODEL}",
764
- run_in_background=true,
765
- description="Discover cross-cutting concerns and guides"
766
- )
767
- ```
768
- </substep>
769
-
770
- <substep order="10.6" name="wait-for-discovery">
771
- Wait for all three discovery agents to complete.
772
- </substep>
773
-
774
- <substep order="10.7" name="doc-inventory" condition="existing-docs contains a directory">
775
- Only spawned if existing-docs contains a directory.
776
-
777
- Spawn a doc inventory agent to produce a compact index of the external docs.
778
- This runs BEFORE the synthesis agent so that synthesis has a lightweight
779
- inventory to work with instead of reading hundreds of files itself.
780
-
781
- ```
782
- Task(
783
- prompt="You are a documentation inventory agent. Produce a compact index of all
784
- documentation files in a directory so downstream agents can match docs to modules
785
- without reading every file themselves.
786
-
787
- **Documentation directory to scan:** [directory path from existing-docs]
788
- **Output file:** .ace/artifacts/subsystems/[subsystem_name]/module-discovery/existing-docs-inventory.md
789
-
790
- <agent-instructions>
791
- <instruction order="1" name="list-files">
792
- Recursively list ALL files in the directory down to every leaf subdirectory.
793
- Use Glob(pattern='**/*', path='[directory path]') to ensure no nesting level
794
- is missed. Do NOT use shallow ls or single-level globs.
795
- </instruction>
796
- <instruction order="2" name="determine-depth">
797
- Count total files to determine summary depth:
798
- <depth-rules>
799
- <rule range="up to 50 files" read-lines="30-50" summary-lines="up to 10" />
800
- <rule range="51-150 files" read-lines="20-30" summary-lines="up to 5" />
801
- <rule range="151-300 files" read-lines="15-20" summary-lines="up to 3" />
802
- <rule range="300+ files" read-lines="10" summary-lines="1-2" />
803
- </depth-rules>
804
- </instruction>
805
- <instruction order="3" name="read-and-summarize">
806
- For each file, read the adaptive number of lines determined above.
807
- </instruction>
808
- <instruction order="4" name="write-inventory">
809
- Write the inventory to the output file in this format:
810
-
811
- ```markdown
812
- # Existing Documentation Inventory
813
-
814
- Source directory: [directory path]
815
- Total files: [count]
816
- Summary depth: [lines per file based on count]
817
-
818
- ## [File Path]
819
- **Title:** [first heading or filename]
820
- **Summary:**
821
- [Adaptive-length summary: key topics, domain concepts, APIs/interfaces described,
822
- architectural decisions mentioned. Enough detail for a downstream agent to
823
- determine which code modules this doc is relevant to.]
824
-
825
- ## [Next File Path]
826
- ...
827
- ```
828
-
829
- Be thorough — every file must appear in the inventory.
830
- </instruction>
831
- </agent-instructions>
832
-
833
- Return: total file count.",
834
- subagent_type="ace-wiki-mapper",
835
- model="{MAPPER_MODEL}",
836
- description="Inventory existing docs"
837
- )
838
- ```
839
-
840
- Display to user:
841
- ```
842
- Existing docs inventory: [N] files indexed from [directory path]
843
- Saved to .ace/artifacts/subsystems/[subsystem_name]/module-discovery/existing-docs-inventory.md
844
- ```
845
- </substep>
846
-
847
- <substep order="10.8" name="synthesis" sequential="true">
848
- Synthesis Agent (sequential — runs after all above complete):
849
-
850
- ```
851
- Task(
852
- prompt="Focus: module-discovery synthesis
853
-
854
- Synthesize three discovery reports into the final module-discovery.md artifact.
855
-
856
- **Output template:** Read ~/.claude/agile-context-engineering/templates/wiki/module-discovery.xml
857
- **Discovery inputs (read all three):**
858
- - .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-flows.md (systems)
859
- - .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-patterns.md (patterns)
860
- - .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-cross-cutting.md (cross-cutting + guides)
861
- **File inventory:** .docs/wiki/subsystems/[subsystem_name]/structure.md
862
- **External docs inventory (if exists):** .ace/artifacts/subsystems/[subsystem_name]/module-discovery/existing-docs-inventory.md
863
-
864
- <agent-instructions>
865
- <instruction order="1" name="read-inputs">
866
- Read all three discovery inputs.
867
- </instruction>
868
- <instruction order="2" name="discover-existing-docs">
869
- Discover existing documentation:
870
- <checklist>
871
- <item>Scan the subsystem directory ([subsystem_path]) recursively for *.md files</item>
872
- <item>Also scan common doc locations: docs/, documentation/, .docs/</item>
873
- <item>If existing-docs-inventory.md exists, read it and INCLUDE all entries
874
- in the Existing Documentation Inventory table (these are external docs
875
- already indexed — do NOT re-scan the original directory)</item>
876
- <item>Read each locally-discovered doc's title and first few lines to understand its subject</item>
877
- <item>Build the Existing Documentation Inventory table (local + external combined)</item>
878
- </checklist>
879
- </instruction>
880
- <instruction order="3" name="merge-modules">
881
- Merge all discovery results into ONE flat Modules table:
882
- <checklist>
883
- <item>E2E flows from discovery-flows.md become modules</item>
884
- <item>Patterns from discovery-patterns.md become modules</item>
885
- <item>Cross-cutting concerns from discovery-cross-cutting.md become modules</item>
886
- <item>Do NOT categorize by type — map-story decides what docs to produce</item>
887
- </checklist>
888
- </instruction>
889
- <instruction order="4" name="curate-docs-to-modules">
890
- Curate docs to modules (populate the Relevant Docs column):
891
- <checklist>
892
- <item>Match each discovered doc to the module(s) whose domain it describes</item>
893
- <item>A doc can appear in multiple modules</item>
894
- <item>Architecture docs and READMEs are typically relevant to all flow modules</item>
895
- <item>Implementation docs match the module they describe</item>
896
- <item>Mark unmatched docs in the inventory table</item>
897
- </checklist>
898
- </instruction>
899
- <instruction order="5" name="file-coverage-check">
900
- File coverage check:
901
- <checklist>
902
- <item>Read structure.md for the complete file inventory</item>
903
- <item>Every non-trivial file must appear in at least one module</item>
904
- <item>List any uncovered files; create new modules for files with meaningful logic</item>
905
- <item>Exclude only: index re-exports, empty stubs, generated code, test files</item>
906
- </checklist>
907
- </instruction>
908
- <instruction order="6" name="preserve-overlaps">
909
- Preserve overlaps — files appearing in multiple modules are correct.
910
- </instruction>
911
- </agent-instructions>
912
-
913
- Write to .ace/artifacts/subsystems/[subsystem_name]/module-discovery/module-discovery.md
914
-
915
- Return: total module count + uncovered file count + existing docs found count.",
916
- subagent_type="ace-wiki-mapper",
917
- model="{MAPPER_MODEL}",
918
- description="Synthesize module discovery"
919
- )
920
- ```
921
- </substep>
922
-
923
- Continue to step 11.
924
- </step>
925
-
926
- <!-- ══════════════════════════════════════════════════════════════════ -->
927
- <!-- STEP 11: KNOWLEDGE DOCUMENTATION VIA MAP-STORY -->
928
- <!-- ══════════════════════════════════════════════════════════════════ -->
929
-
930
- <step name="knowledge-documentation" order="11">
931
- For each module row in module-discovery.md, spawn one ace-wiki-mapper agent
932
- that follows the map-story workflow in file mode.
933
-
934
- Run agents SEQUENTIALLY — wait for each to complete before starting the next.
935
- Sequential prevents write conflicts: map-story writes multiple doc files per call
936
- and two concurrent agents could clash on the same file.
937
-
938
- <substep order="11.1" name="read-module-discovery">
939
- Read .ace/artifacts/subsystems/[subsystem_name]/module-discovery/module-discovery.md.
940
-
941
- The file has one Modules table.
942
- Each row has: # | Module Name | Files | Relevant Docs
943
- </substep>
944
-
945
- <substep order="11.2" name="merge-existing-docs">
946
- If the `existing-docs` parameter was provided to map-subsystem,
947
- merge those entries (files and/or directories, as-is) with each row's Relevant Docs
948
- column.
949
-
950
- <merge-rules>
951
- <rule>For each module row, the final existing-docs list =
952
- (command-level existing-docs) + (row's Relevant Docs)</rule>
953
- <rule>Deduplicate any overlapping paths</rule>
954
- <rule>If both are empty, use `none`</rule>
955
- <rule>Do NOT expand directories here map-story handles directory resolution internally
956
- by spinning up a curation agent that selects only relevant docs</rule>
957
- </merge-rules>
958
-
959
- If existing-docs-inventory.md was produced in step 10, also pass its path to
960
- each map-story invocation so the curation agent can use the pre-built inventory
961
- instead of re-scanning the directory from scratch for every module.
962
- </substep>
963
-
964
- <substep order="11.3" name="iterate-modules">
965
- Iterate ALL rows (one at a time, sequential):
966
-
967
- ```
968
- Task(
969
- prompt="Load and follow the map-story workflow in file mode.
970
-
971
- **Workflow:** Read and follow ~/.claude/agile-context-engineering/workflows/map-story.xml
972
- **Mode:** file mode document existing code (no git diff)
973
-
974
- **Module name:** [Module Name from row]
975
- **Files to document:** [comma-separated file list from Files column]
976
- **Existing docs context:** [merged existing-docs: command-level + row Relevant Docs, deduplicated, or `none`]
977
- **Existing docs inventory:** [path to existing-docs-inventory.md if it was produced, or `none`]
978
- **Subsystem name:** [subsystem_name]
979
-
980
- **TEMPLATES Read ALL of these before writing ANY docs:**
981
- - System docs: .claude/templates/system.xml
982
- - Pattern docs: .claude/templates/pattern.xml
983
- - Cross-cutting docs: .claude/templates/system-cross-cutting.xml
984
- - Guide docs: .claude/templates/guide.xml
985
- - Decision docs: .claude/templates/decizions.xml
986
-
987
- <agent-instructions>
988
- <instruction order="1" name="read-source">
989
- Read ALL source files listed in Files. Understand the actual code classes,
990
- interfaces, patterns, state, flows, DI registrations, constants, error handling.
991
- </instruction>
992
-
993
- <instruction order="2" name="read-existing-docs">
994
- If Existing docs context is not `none`, read those documents FIRST —
995
- they contain prior knowledge, intent, and decisions about this module's domain.
996
- Use them as additional context when writing, but the actual source code is
997
- always the source of truth.
998
- </instruction>
999
-
1000
- <instruction order="3" name="read-wiki">
1001
- Read ALL existing wiki docs under .docs/wiki/subsystems/[subsystem_name]/ —
1002
- EVERY .md file, FULLY. Not titles. Not summaries. THE COMPLETE CONTENT.
1003
- Build a mental map of what is already documented so you do NOT create
1004
- duplicate documentation. This is MANDATORY.
1005
- </instruction>
1006
-
1007
- <instruction order="4" name="decide-docs">
1008
- You decide what docs to create or update — systems/, patterns/, cross-cutting/,
1009
- guides/, walkthroughs/, decisions/ based on what you find in the code files. One call may
1010
- produce multiple docs across different categories.
1011
- </instruction>
1012
-
1013
- <instruction order="5" name="update-vs-create">
1014
- When an existing doc already covers a topic, UPDATE it (add/expand sections).
1015
- Only CREATE new docs for genuinely new topics not covered anywhere.
1016
- </instruction>
1017
-
1018
- <instruction order="6" name="topic-scoped-only">
1019
- NEVER create a story-scoped or module-scoped document.
1020
- All docs are TOPIC-scoped — about the concern, not about the module.
1021
- </instruction>
1022
- </agent-instructions>
1023
-
1024
- Return: list of all docs created/updated with line counts.",
1025
- subagent_type="ace-wiki-mapper",
1026
- model="{MAPPER_MODEL}",
1027
- description="Document [module_name]"
1028
- )
1029
- ```
1030
-
1031
- Collect each agent's report before spawning the next.
1032
- </substep>
1033
-
1034
- <substep order="11.4" name="compile-report">
1035
- After all rows are processed, compile the full knowledge docs report.
1036
- </substep>
1037
-
1038
- Continue to step 12.
1039
- </step>
1040
-
1041
- <!-- ══════════════════════════════════════════════════════════════════ -->
1042
- <!-- STEP 12: VERIFY AND COMMIT -->
1043
- <!-- ══════════════════════════════════════════════════════════════════ -->
1044
-
1045
- <step name="verify-and-commit" order="12">
1046
-
1047
- <substep order="12.1" name="verify-documents">
1048
- Verify all expected documents exist and are non-empty.
1049
-
1050
- For each document where the action was NOT `skip`:
1051
- <verification-checks>
1052
- <check>File exists</check>
1053
- <check>File has content (>20 lines for create/update/recreate)</check>
1054
- </verification-checks>
1055
-
1056
- If any document is missing or empty, warn the user.
1057
- </substep>
1058
-
1059
- <substep order="12.2" name="security-scan">
1060
- Security scan before commit — use the Grep tool (NOT bash grep):
1061
-
1062
- ```
1063
- Grep(
1064
- 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)",
1065
- path=".docs/wiki/subsystems/[subsystem_name]/",
1066
- output_mode="content"
1067
- )
1068
- ```
1069
-
1070
- <variant condition="matches found">SECRETS_FOUND pause and alert user.</variant>
1071
- <variant condition="no matches">CLEAN.</variant>
1072
- </substep>
1073
-
1074
- <substep order="12.3" name="commit" condition="commit_docs is true">
1075
- Commit (if `commit_docs` is true):
1076
-
1077
- <stage-files>
1078
- <always>
1079
- ```bash
1080
- git add .docs/wiki/subsystems/[subsystem_name]/
1081
- ```
1082
- </always>
1083
-
1084
- <conditional condition="system-structure.md was updated in step 9a">
1085
- ```bash
1086
- git add .docs/wiki/system-wide/system-structure.md
1087
- ```
1088
- </conditional>
1089
-
1090
- <conditional condition="system-architecture.md was updated in step 9b">
1091
- ```bash
1092
- git add .docs/wiki/system-wide/system-architecture.md
1093
- ```
1094
- </conditional>
1095
-
1096
- <conditional condition="module-discovery artifacts were written in step 10">
1097
- ```bash
1098
- git add .ace/artifacts/subsystems/[subsystem_name]/module-discovery/
1099
- ```
1100
- </conditional>
1101
- </stage-files>
1102
-
1103
- ```bash
1104
- git commit -m "docs: map [subsystem_name] subsystem wiki and knowledge base"
1105
- ```
1106
- </substep>
1107
-
1108
- Continue to step 13.
1109
- </step>
1110
-
1111
- <!-- ══════════════════════════════════════════════════════════════════ -->
1112
- <!-- STEP 13: COMPLETION -->
1113
- <!-- ══════════════════════════════════════════════════════════════════ -->
1114
-
1115
- <step name="completion" order="13">
1116
- Display completion banner and next steps.
1117
-
1118
- ```
1119
- ╔══════════════════════════════════════════════════╗
1120
- ║ ACE > Subsystem Mapped ║
1121
- ╚══════════════════════════════════════════════════╝
1122
-
1123
- Subsystem: [subsystem_name] ([subsystem_path])
1124
-
1125
- Documents:
1126
- ──────────
1127
- [For each document, show action taken and line count]
1128
- + structure.md ([N] lines) [created/updated/recreated]
1129
- + architecture.md ([N] lines) — [created/updated/recreated]
1130
- - [document] skipped
1131
-
1132
- [If system-structure.md was updated in step 9a:]
1133
- ~ system-structure.md subsystem entry added
1134
-
1135
- [If system-architecture.md was updated in step 9b:]
1136
- ~ system-architecture.md subsystem responsibility matrix updated
1137
-
1138
- [If knowledge docs were produced in step 11:]
1139
- Knowledge Docs (.docs/wiki/subsystems/[subsystem_name]/):
1140
- ──────────────────────────────────────────────────────────
1141
- [For each doc written by map-story: show filename and line count]
1142
-
1143
- Next > `/clear` first for a fresh context window, then:
1144
-
1145
- /ace:map-subsystem [next-subsystem]
1146
- Map another subsystem.
1147
-
1148
- Also available (`/clear` first):
1149
- - /ace:map-system — Re-run to refresh system-wide documents
1150
- - /ace:init-coding-standards — Define coding standards
1151
- - Review files in .docs/wiki/subsystems/[subsystem_name]/
1152
- ```
1153
-
1154
- End workflow.
1155
- </step>
1156
-
1157
- </process>
1158
-
1159
- <success_criteria>
1160
- <criterion>Init function executed (environment detected, mapper model resolved)</criterion>
1161
- <criterion>Subsystem path resolved and validated against the codebase</criterion>
1162
- <criterion>System-wide docs read for context before analysis begins</criterion>
1163
- <criterion>Each document triaged independently (create/update/recreate/skip)</criterion>
1164
- <criterion>Agents spawned in parallel (structure + architecture) where possible</criterion>
1165
- <criterion>system-structure.md updated if this is a previously undocumented subsystem</criterion>
1166
- <criterion>system-architecture.md subsystem responsibility matrix updated if subsystem was missing</criterion>
1167
- <criterion>All created documents verified for content (non-empty, >20 lines)</criterion>
1168
- <criterion>Security scan passed (no secrets in generated docs)</criterion>
1169
- <criterion>Documents committed to .docs/wiki/subsystems/[subsystem_name]/</criterion>
1170
- <criterion>Module discovery completed; .ace/artifacts/subsystems/[subsystem_name]/module-discovery/module-discovery.md written</criterion>
1171
- <criterion>map-story called sequentially for each module row; all completed</criterion>
1172
- <criterion>Each map-story agent reads ALL existing wiki docs FULLY before writing (no duplication)</criterion>
1173
- <criterion>Knowledge docs written to .docs/wiki/subsystems/[subsystem_name]/</criterion>
1174
- <criterion>module-discovery.md staged and committed</criterion>
1175
- <criterion>User sees clear completion summary with next steps</criterion>
1176
- </success_criteria>
1177
-
1178
- </workflow>
1
+ <workflow>
2
+
3
+ <purpose>
4
+ Orchestrate subsystem wiki mapping: resolve the target subsystem, load system-wide context,
5
+ determine which documents need creation or updates, spawn ace-wiki-mapper agents to produce
6
+ them, run module discovery, and generate knowledge documentation via map-story.
7
+
8
+ Produces documents in `.docs/wiki/subsystems/[subsystem-name]/`:
9
+ - structure.md — physical file layout within the subsystem
10
+ - architecture.md — L3 component view, flows, dependencies, data ownership
11
+ - systems/*.md — domain system documentation (via map-story)
12
+ - patterns/*.md — reusable implementation patterns (via map-story)
13
+ - cross-cutting/*.md — concerns spanning multiple systems (via map-story)
14
+ - guides/*.md — step-by-step recipes for common tasks (via map-story)
15
+ - walkthroughs/*.md — deep tutorial-style flow explanations (via map-story)
16
+ - decisions/*.md — architecture decision records (via map-story)
17
+
18
+ Also produces `.ace/artifacts/subsystems/[subsystem-name]/module-discovery/module-discovery.md`.
19
+
20
+ May also update `.docs/wiki/system-wide/system-structure.md` if this subsystem
21
+ is not yet listed there, and `.docs/wiki/system-wide/system-architecture.md` if
22
+ the subsystem is missing from the Subsystem Responsibility Matrix.
23
+ </purpose>
24
+
25
+ <mandatory-context>
26
+ All supporting resource files are auto-loaded in the skill prompt above. Do NOT re-read them.
27
+ Also read any document or text passed as parameter ($ARGUMENTS) in the invoking command.
28
+ </mandatory-context>
29
+
30
+ <process>
31
+
32
+ <!-- ══════════════════════════════════════════════════════════════════ -->
33
+ <!-- STEP 1: SETUP -->
34
+ <!-- ══════════════════════════════════════════════════════════════════ -->
35
+
36
+ <step name="setup" order="1">
37
+
38
+ <substep order="1.1" name="environment-detection">
39
+ MANDATORY FIRST STEP — Execute environment detection before any user interaction:
40
+
41
+ ```bash
42
+ INIT is available from the preprocessed Environment Context above — do NOT re-run init.
43
+
44
+ Parse INIT JSON for: `mapper_model`, `commit_docs`, `is_brownfield`, `wiki_dir_exists`, `has_git`.
45
+ </substep>
46
+
47
+ <substep order="1.2" name="resolve-mapper-model">
48
+ MAPPER_MODEL is available from INIT.mapper_model — do NOT re-run resolve-model.
49
+ </substep>
50
+
51
+ <substep order="1.3" name="display-banner">
52
+ Display stage banner:
53
+
54
+ ```
55
+ ╔══════════════════════════════════════════════════╗
56
+ ║ ACE > Map Subsystem ║
57
+ ╚══════════════════════════════════════════════════╝
58
+ ```
59
+ </substep>
60
+
61
+ <substep order="1.4" name="resolve-input">
62
+ <variant condition="subsystem was NOT provided in $ARGUMENTS">
63
+ List top-level directories to offer as options, then use AskUserQuestion:
64
+ - header: "Subsystem"
65
+ - question: "Which subsystem would you like to map? Provide the path (e.g., `src/api`) or its name."
66
+ - options: (top 3 candidate paths from the codebase, plus a free-text prompt)
67
+ </variant>
68
+ </substep>
69
+
70
+ Continue to step 2.
71
+ </step>
72
+
73
+ <!-- ══════════════════════════════════════════════════════════════════ -->
74
+ <!-- STEP 2: LOAD SYSTEM-WIDE CONTEXT -->
75
+ <!-- ══════════════════════════════════════════════════════════════════ -->
76
+
77
+ <step name="load-context" order="2">
78
+ Read system-wide documents for context before analyzing the subsystem.
79
+ These orient the mapper agent and prevent repeating system-level content
80
+ in the subsystem docs.
81
+
82
+ <substep order="2.1" name="read-system-docs">
83
+ Read (if they exist):
84
+ <file-list>
85
+ <file path=".docs/wiki/system-wide/system-structure.md" />
86
+ <file path=".docs/wiki/system-wide/system-architecture.md" />
87
+ </file-list>
88
+ </substep>
89
+
90
+ <substep order="2.2" name="check-subsystem-index">
91
+ While reading `system-structure.md`, check whether the target subsystem is already
92
+ listed in the Subsystem Index. Set `is_new_subsystem = true` if it is NOT found.
93
+ </substep>
94
+
95
+ <substep order="2.3" name="check-responsibility-matrix">
96
+ While reading `system-architecture.md`, check whether the target subsystem appears
97
+ in the Subsystem Responsibility Matrix. Set `is_missing_from_matrix = true` if it
98
+ is NOT found.
99
+
100
+ <variant condition="system-architecture.md does not exist">
101
+ Set `is_missing_from_matrix = false` and note to the user that
102
+ system-architecture.md should be created via `/ace:map-system`.
103
+ </variant>
104
+ </substep>
105
+
106
+ Continue to step 3.
107
+ </step>
108
+
109
+ <!-- ══════════════════════════════════════════════════════════════════ -->
110
+ <!-- STEP 3: RESOLVE SUBSYSTEM -->
111
+ <!-- ══════════════════════════════════════════════════════════════════ -->
112
+
113
+ <step name="resolve-subsystem" order="3">
114
+
115
+ <substep order="3.1" name="normalize-input">
116
+ Normalize the subsystem input to:
117
+ <output-fields>
118
+ <field name="subsystem_path">Relative path from project root (e.g., `src/api`)</field>
119
+ <field name="subsystem_name">Slug for the wiki directory (e.g., `api`, `user-service`)</field>
120
+ </output-fields>
121
+ </substep>
122
+
123
+ <substep order="3.2" name="validate-path">
124
+ Validate that `subsystem_path` exists in the codebase.
125
+
126
+ <variant condition="path not found">
127
+ Use AskUserQuestion to clarify — list candidate paths matching the input.
128
+ </variant>
129
+
130
+ <variant condition="input is ambiguous (name matches multiple directories)">
131
+ Use AskUserQuestion with the candidates as options.
132
+ </variant>
133
+ </substep>
134
+
135
+ <substep order="3.3" name="set-output-dir">
136
+ Determine wiki output directory: `.docs/wiki/subsystems/[subsystem_name]/`
137
+ </substep>
138
+
139
+ Continue to step 4.
140
+ </step>
141
+
142
+ <!-- ══════════════════════════════════════════════════════════════════ -->
143
+ <!-- STEP 4: DOCUMENT TRIAGE -->
144
+ <!-- Determine per-document action: create, update, recreate, or skip -->
145
+ <!-- ══════════════════════════════════════════════════════════════════ -->
146
+
147
+ <step name="document-triage" order="4">
148
+
149
+ <substep order="4.1" name="check-existing">
150
+ Check for existing documents in `.docs/wiki/subsystems/[subsystem_name]/`:
151
+ <flags>
152
+ <flag name="has_structure">Does `structure.md` exist?</flag>
153
+ <flag name="has_architecture">Does `architecture.md` exist?</flag>
154
+ </flags>
155
+ </substep>
156
+
157
+ <substep order="4.2" name="triage-structure">
158
+ Evaluate structure.md:
159
+
160
+ <variant condition="has_structure is false">
161
+ Action: `create` — analyze subsystem and produce full document.
162
+ </variant>
163
+
164
+ <variant condition="has_structure is true">
165
+ Use AskUserQuestion:
166
+ - header: "Structure"
167
+ - question: "Structure document already exists at `.docs/wiki/subsystems/[subsystem_name]/structure.md`. What would you like to do?"
168
+ - options:
169
+ - "Update" Refresh the existing document with current codebase state
170
+ - "Recreate" — Discard and rebuild from scratch
171
+ - "Skip" — Keep the current document as-is
172
+ Map user choice to action: `update`, `recreate`, or `skip`.
173
+ </variant>
174
+ </substep>
175
+
176
+ <substep order="4.3" name="triage-architecture">
177
+ Evaluate architecture.md:
178
+
179
+ <variant condition="has_architecture is false">
180
+ Action: `create` — analyze subsystem and produce full document.
181
+ </variant>
182
+
183
+ <variant condition="has_architecture is true">
184
+ Use AskUserQuestion:
185
+ - header: "Architecture"
186
+ - question: "Architecture document already exists at `.docs/wiki/subsystems/[subsystem_name]/architecture.md`. What would you like to do?"
187
+ - options:
188
+ - "Update" Refresh the existing document with current codebase state
189
+ - "Recreate" — Discard and rebuild from scratch
190
+ - "Skip" — Keep the current document as-is
191
+ Map user choice to action: `update`, `recreate`, or `skip`.
192
+ </variant>
193
+ </substep>
194
+
195
+ <substep order="4.4" name="batch-questions">
196
+ IMPORTANT: Ask all questions that need asking in a SINGLE AskUserQuestion call
197
+ where possible (up to 4 questions). If both documents exist, batch the questions.
198
+
199
+ NEVER pass `answers` or `annotations` parameters in AskUserQuestion — only pass `questions`.
200
+ The user must answer interactively. If the response comes back empty, re-ask.
201
+ </substep>
202
+
203
+ <substep order="4.5" name="display-action-plan">
204
+ Display the action plan to the user:
205
+
206
+ ```
207
+ ┌──────────────────────────────────────────────────┐
208
+ │ ACE > Map Subsystem > Action Plan │
209
+ └──────────────────────────────────────────────────┘
210
+
211
+ Subsystem [subsystem_name] ([subsystem_path])
212
+ ──────────────────────────────────────────────────
213
+ Document Action
214
+ ─────────────────── ──────────────────────────
215
+ structure.md [create/update/recreate/skip]
216
+ architecture.md [create/update/recreate/skip]
217
+ ```
218
+
219
+ <variant condition="ALL actions are skip">
220
+ Exit workflow with message:
221
+ ```
222
+ i All documents already exist and were skipped. Nothing to do.
223
+
224
+ Next > `/clear` first for a fresh context window, then:
225
+
226
+ /ace:map-subsystem [next-subsystem]
227
+ Map another subsystem.
228
+ ```
229
+ </variant>
230
+ </substep>
231
+
232
+ Continue to step 5.
233
+ </step>
234
+
235
+ <!-- ══════════════════════════════════════════════════════════════════ -->
236
+ <!-- STEP 5: CREATE DIRECTORY STRUCTURE -->
237
+ <!-- ══════════════════════════════════════════════════════════════════ -->
238
+
239
+ <step name="create-directory" order="5">
240
+ Create the subsystem wiki directory if it doesn't exist:
241
+
242
+ ```bash
243
+ mkdir -p .docs/wiki/subsystems/[subsystem_name]
244
+ ```
245
+
246
+ Continue to step 6.
247
+ </step>
248
+
249
+ <!-- ══════════════════════════════════════════════════════════════════ -->
250
+ <!-- STEP 6: SUBSYSTEM STRUCTURE -->
251
+ <!-- ══════════════════════════════════════════════════════════════════ -->
252
+
253
+ <step name="subsystem-structure" order="6">
254
+ Skip this step if structure action is `skip`.
255
+
256
+ NOTE: This step can run IN PARALLEL with step 7 (architecture) if both
257
+ need agent work. Use `run_in_background=true` for both agents in steps 6 and 7,
258
+ then collect results in step 8.
259
+
260
+ <variant condition="action is create or recreate">
261
+ Spawn ace-wiki-mapper agent:
262
+
263
+ ```
264
+ Task(
265
+ prompt="Focus: subsystem-structure
266
+
267
+ Analyze this subsystem and produce its structure document.
268
+
269
+ **Subsystem path:** [subsystem_path]
270
+ **Subsystem name:** [subsystem_name]
271
+
272
+ **Template:** Read ${CLAUDE_SKILL_DIR}/templates/subsystem-structure.xml
273
+ **System context (if exists):** Read .docs/wiki/system-wide/system-structure.md
274
+ **Output:** Write to .docs/wiki/subsystems/[subsystem_name]/structure.md
275
+
276
+ <agent-instructions>
277
+ <instruction order="1" name="explore">
278
+ Explore every file and directory within [subsystem_path].
279
+ </instruction>
280
+ <instruction order="2" name="write-sections">
281
+ Follow the template and produce:
282
+ <checklist>
283
+ <item>Subsystem overview (root path, one-line responsibility)</item>
284
+ <item>Full directory layout (ASCII tree of ALL files and directories with purpose comments)</item>
285
+ <item>Directory purposes (one entry per meaningful directory)</item>
286
+ <item>Key file locations grouped by role: entry points, config, core logic, API, tests</item>
287
+ <item>Naming conventions (if different from system-wide; otherwise reference system-structure.md)</item>
288
+ <item>Where to add new code (specific paths for each code type)</item>
289
+ <item>Special directories (generated, build output, migrations, etc.)</item>
290
+ </checklist>
291
+ </instruction>
292
+ </agent-instructions>
293
+
294
+ Return confirmation only do NOT return document contents.",
295
+ subagent_type="ace-wiki-mapper",
296
+ model="{MAPPER_MODEL}",
297
+ description="Map subsystem structure"
298
+ )
299
+ ```
300
+ </variant>
301
+
302
+ <variant condition="action is update">
303
+ Spawn ace-wiki-mapper agent with existing content as context:
304
+
305
+ ```
306
+ Task(
307
+ prompt="Focus: subsystem-structure
308
+
309
+ UPDATE the existing structure document for this subsystem.
310
+
311
+ **Subsystem path:** [subsystem_path]
312
+ **Current document:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
313
+ **Template:** Read ${CLAUDE_SKILL_DIR}/templates/subsystem-structure.xml
314
+
315
+ <agent-instructions>
316
+ <instruction order="1" name="compare">
317
+ Compare the current document against the actual codebase state.
318
+ </instruction>
319
+ <instruction order="2" name="update-sections">
320
+ <checklist>
321
+ <item>Update the directory tree for any new or removed files and directories</item>
322
+ <item>Update key file locations if entry points or core files have changed</item>
323
+ <item>Update 'Where to add new code' if new directories or patterns were introduced</item>
324
+ <item>Remove entries for deleted directories or files</item>
325
+ </checklist>
326
+ </instruction>
327
+ <instruction order="3" name="preserve">
328
+ Preserve accurate content. Only change what is actually stale.
329
+ </instruction>
330
+ </agent-instructions>
331
+
332
+ Write the updated file to .docs/wiki/subsystems/[subsystem_name]/structure.md
333
+ Return confirmation only do NOT return document contents.",
334
+ subagent_type="ace-wiki-mapper",
335
+ model="{MAPPER_MODEL}",
336
+ description="Update subsystem structure"
337
+ )
338
+ ```
339
+ </variant>
340
+
341
+ Continue to step 7.
342
+ </step>
343
+
344
+ <!-- ══════════════════════════════════════════════════════════════════ -->
345
+ <!-- STEP 7: SUBSYSTEM ARCHITECTURE -->
346
+ <!-- ══════════════════════════════════════════════════════════════════ -->
347
+
348
+ <step name="subsystem-architecture" order="7">
349
+ Skip this step if architecture action is `skip`.
350
+
351
+ <variant condition="action is create or recreate">
352
+ Spawn ace-wiki-mapper agent:
353
+
354
+ ```
355
+ Task(
356
+ prompt="Focus: subsystem-architecture
357
+
358
+ Analyze this subsystem and produce its architecture document.
359
+
360
+ **Subsystem path:** [subsystem_path]
361
+ **Subsystem name:** [subsystem_name]
362
+
363
+ **Template:** Read ${CLAUDE_SKILL_DIR}/templates/subsystem-architecture.xml
364
+ **System context (if exists):** Read .docs/wiki/system-wide/system-architecture.md
365
+ **Structure doc (if exists):** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
366
+ **Output:** Write to .docs/wiki/subsystems/[subsystem_name]/architecture.md
367
+
368
+ <agent-instructions>
369
+ <instruction order="1" name="analyze">
370
+ Follow the template structure. Fill every section with real data from the subsystem.
371
+ </instruction>
372
+ <instruction order="2" name="write-sections">
373
+ <checklist>
374
+ <item>Subsystem context: one-line responsibility and system connections (inbound/outbound)</item>
375
+ <item>L3 component diagram: internal layers (API -> Application -> Domain -> Infrastructure -> Data)</item>
376
+ <item>Component responsibilities table with key file paths</item>
377
+ <item>Key internal flows: 1-3 sequence diagrams for the core operations</item>
378
+ <item>Dependency inventory: inbound callers, outbound dependencies with failure handling</item>
379
+ <item>Data ownership: tables, schemas, topics this subsystem owns</item>
380
+ <item>Subsystem architectural decisions</item>
381
+ </checklist>
382
+ </instruction>
383
+ <instruction order="3" name="avoid-duplication">
384
+ Do NOT repeat system-wide architecture content. Reference system-architecture.md where appropriate.
385
+ </instruction>
386
+ </agent-instructions>
387
+
388
+ Return confirmation only — do NOT return document contents.",
389
+ subagent_type="ace-wiki-mapper",
390
+ model="{MAPPER_MODEL}",
391
+ description="Map subsystem architecture"
392
+ )
393
+ ```
394
+ </variant>
395
+
396
+ <variant condition="action is update">
397
+ Spawn ace-wiki-mapper agent with update instructions:
398
+
399
+ ```
400
+ Task(
401
+ prompt="Focus: subsystem-architecture
402
+
403
+ UPDATE the existing architecture document for this subsystem.
404
+
405
+ **Subsystem path:** [subsystem_path]
406
+ **Current document:** Read .docs/wiki/subsystems/[subsystem_name]/architecture.md
407
+ **Template:** Read ${CLAUDE_SKILL_DIR}/templates/subsystem-architecture.xml
408
+ **System context (if exists):** Read .docs/wiki/system-wide/system-architecture.md
409
+
410
+ <agent-instructions>
411
+ <instruction order="1" name="compare">
412
+ Compare against current codebase state. Check for:
413
+ <checklist>
414
+ <item>New or removed internal components?</item>
415
+ <item>New inbound callers or outbound dependencies?</item>
416
+ <item>Data ownership changes (new tables, schemas, topics)?</item>
417
+ <item>Core internal flows changed shape?</item>
418
+ <item>New subsystem-specific architectural decisions?</item>
419
+ </checklist>
420
+ </instruction>
421
+ <instruction order="2" name="apply-updates">
422
+ Update only stale sections. Preserve accurate content.
423
+ </instruction>
424
+ </agent-instructions>
425
+
426
+ Write the updated file to .docs/wiki/subsystems/[subsystem_name]/architecture.md
427
+ Return confirmation only do NOT return document contents.",
428
+ subagent_type="ace-wiki-mapper",
429
+ model="{MAPPER_MODEL}",
430
+ description="Update subsystem architecture"
431
+ )
432
+ ```
433
+ </variant>
434
+
435
+ Continue to step 8.
436
+ </step>
437
+
438
+ <!-- ══════════════════════════════════════════════════════════════════ -->
439
+ <!-- STEP 8: COLLECT PARALLEL RESULTS -->
440
+ <!-- ══════════════════════════════════════════════════════════════════ -->
441
+
442
+ <step name="collect-parallel" order="8">
443
+
444
+ <substep order="8.1" name="wait-for-agents">
445
+ If steps 6 and 7 spawned background agents, wait for both to complete.
446
+ Read each agent's output to collect confirmations.
447
+ </substep>
448
+
449
+ <substep order="8.2" name="handle-failures">
450
+ If any agent failed, note the failure and inform the user.
451
+ Do NOT re-attempt let the user decide.
452
+ </substep>
453
+
454
+ Continue to step 9.
455
+ </step>
456
+
457
+ <!-- ══════════════════════════════════════════════════════════════════ -->
458
+ <!-- STEP 9: UPDATE SYSTEM-WIDE STRUCTURE -->
459
+ <!-- ══════════════════════════════════════════════════════════════════ -->
460
+
461
+ <step name="update-system-wide" order="9">
462
+ Execute all applicable sub-steps. Both agents can run IN PARALLEL if both are needed —
463
+ use `run_in_background=true` and collect results before step 10.
464
+
465
+ <substep order="9a" name="update-system-structure" condition="is_new_subsystem is true">
466
+ Only execute if `is_new_subsystem` is true.
467
+
468
+ <variant condition="system-structure.md does not exist">
469
+ Skip 9a and note to the user that system-structure.md should be created via `/ace:map-system`.
470
+ </variant>
471
+
472
+ <variant condition="system-structure.md exists">
473
+ ```
474
+ Task(
475
+ prompt="Focus: system-structure (partial update — add new subsystem entry)
476
+
477
+ A new subsystem has just been documented. Add it to the system-wide structure document.
478
+
479
+ **New subsystem:** [subsystem_name] at [subsystem_path]
480
+ **Current document:** Read .docs/wiki/system-wide/system-structure.md
481
+ **Newly created docs:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
482
+ and .docs/wiki/subsystems/[subsystem_name]/architecture.md to infer responsibility.
483
+
484
+ <agent-instructions>
485
+ <instruction order="1" name="add-row">
486
+ Add this subsystem to the Subsystem Index table with:
487
+ <checklist>
488
+ <item>Name, path, one-line responsibility (inferred from the subsystem code and its new docs)</item>
489
+ <item>Wiki doc link: `.docs/wiki/subsystems/[subsystem_name]/`</item>
490
+ </checklist>
491
+ </instruction>
492
+ <instruction order="2" name="preserve">
493
+ Do NOT restructure or rewrite the existing document. Only add the new row.
494
+ </instruction>
495
+ </agent-instructions>
496
+
497
+ Write the updated file to .docs/wiki/system-wide/system-structure.md
498
+ Return confirmation only do NOT return document contents.",
499
+ subagent_type="ace-wiki-mapper",
500
+ model="{MAPPER_MODEL}",
501
+ description="Add subsystem to system structure"
502
+ )
503
+ ```
504
+ </variant>
505
+ </substep>
506
+
507
+ <substep order="9b" name="update-system-architecture" condition="is_missing_from_matrix is true">
508
+ Only execute if `is_missing_from_matrix` is true.
509
+
510
+ ```
511
+ Task(
512
+ prompt="Focus: system-architecture (partial update — add subsystem to responsibility matrix)
513
+
514
+ A subsystem has just been documented and is missing from the Subsystem Responsibility Matrix.
515
+ Add it to the matrix in the system-wide architecture document.
516
+
517
+ **Subsystem:** [subsystem_name] at [subsystem_path]
518
+ **Current document:** Read .docs/wiki/system-wide/system-architecture.md
519
+ **Subsystem docs:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
520
+ and .docs/wiki/subsystems/[subsystem_name]/architecture.md to populate the row.
521
+
522
+ <agent-instructions>
523
+ <instruction order="1" name="add-matrix-row">
524
+ Add one row to the Subsystem Responsibility Matrix table with:
525
+ <checklist>
526
+ <item>Subsystem name, one-line responsibility</item>
527
+ <item>Data it owns</item>
528
+ <item>Events/APIs it publishes</item>
529
+ <item>Events/APIs it consumes</item>
530
+ <item>Its tech stack</item>
531
+ </checklist>
532
+ </instruction>
533
+ <instruction order="2" name="preserve">
534
+ Do NOT restructure or rewrite any other part of the document. Only add the new row.
535
+ </instruction>
536
+ </agent-instructions>
537
+
538
+ Write the updated file to .docs/wiki/system-wide/system-architecture.md
539
+ Return confirmation only do NOT return document contents.",
540
+ subagent_type="ace-wiki-mapper",
541
+ model="{MAPPER_MODEL}",
542
+ description="Add subsystem to architecture matrix"
543
+ )
544
+ ```
545
+ </substep>
546
+
547
+ Continue to step 10.
548
+ </step>
549
+
550
+ <!-- ══════════════════════════════════════════════════════════════════ -->
551
+ <!-- STEP 10: MODULE DISCOVERY -->
552
+ <!-- ══════════════════════════════════════════════════════════════════ -->
553
+
554
+ <step name="module-discovery" order="10">
555
+ Discover the subsystem's documentation modules by reading the actual source code —
556
+ NOT just the wiki docs. This step traces E2E flows, identifies patterns, and finds
557
+ cross-cutting concerns by reading real implementation files.
558
+
559
+ Uses THREE parallel discovery agents followed by ONE synthesis agent.
560
+
561
+ <substep order="10.1" name="read-template">
562
+ Read the module-discovery template first:
563
+ `${CLAUDE_SKILL_DIR}/templates/module-discovery.xml`
564
+ </substep>
565
+
566
+ <substep order="10.2" name="create-artifacts-dir">
567
+ Create artifacts directory:
568
+
569
+ ```bash
570
+ mkdir -p .ace/artifacts/subsystems/[subsystem_name]/module-discovery
571
+ ```
572
+ </substep>
573
+
574
+ <substep order="10.3" name="launch-flow-discovery" parallel="true">
575
+ Launch with run_in_background=true:
576
+
577
+ ```
578
+ Task(
579
+ prompt="Focus: flow-discovery
580
+
581
+ Discover the E2E domain flows in this subsystem by reading the actual source code.
582
+ Do NOT rely on wiki docs alone — trace the code.
583
+
584
+ **Subsystem path:** [subsystem_path]
585
+ **Subsystem name:** [subsystem_name]
586
+ **File inventory:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
587
+
588
+ <agent-instructions>
589
+ <instruction order="1" name="read-inventory">
590
+ Read structure.md for the complete file inventory.
591
+ </instruction>
592
+ <instruction order="2" name="identify-entry-points">
593
+ Identify ALL entry points: HTTP controllers, CLI handlers, event consumers,
594
+ background jobs, gRPC services, scheduled tasks.
595
+ </instruction>
596
+ <instruction order="3" name="trace-flows">
597
+ For EACH entry point, open and read the file — then trace its COMPLETE E2E flow:
598
+ <checklist>
599
+ <item>Follow all imports/dependencies downward layer by layer</item>
600
+ <item>Collect every file that participates:
601
+ entry point, DTO/viewmodel, mapper, service/use-case, domain entity,
602
+ value objects, repository interface, repository implementation,
603
+ DB scripts/migrations, constants/enums</item>
604
+ <item>A domain model shared across flows belongs in ALL of them — do NOT exclude it</item>
605
+ <item>Read each file you encounter before moving on</item>
606
+ </checklist>
607
+ </instruction>
608
+ <instruction order="4" name="group-systems">
609
+ Group related entry points into one system when they share the same domain concern:
610
+ CreateUser + GetUser + UpdateUser + DeleteUser = 'User Management' (not 4 systems)
611
+ </instruction>
612
+ </agent-instructions>
613
+
614
+ Output to .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-flows.md:
615
+
616
+ ```markdown
617
+ # Flow Discovery: [subsystem_name]
618
+
619
+ ## Systems Found
620
+
621
+ | # | System Name | Entry Points | All Participating Files |
622
+ |---|-------------|--------------|------------------------|
623
+ | 1 | [name] | [entry file paths] | [ALL files in this E2E flow] |
624
+ ```
625
+
626
+ Return: count of systems found + list of any entry points you could not fully trace.",
627
+ subagent_type="ace-wiki-mapper",
628
+ model="{MAPPER_MODEL}",
629
+ run_in_background=true,
630
+ description="Discover E2E system flows"
631
+ )
632
+ ```
633
+ </substep>
634
+
635
+ <substep order="10.4" name="launch-pattern-discovery" parallel="true">
636
+ Launch with run_in_background=true:
637
+
638
+ ```
639
+ Task(
640
+ prompt="Focus: pattern-discovery
641
+
642
+ Discover reusable implementation patterns in this subsystem by reading multiple
643
+ similar files and comparing their structure.
644
+
645
+ **Subsystem path:** [subsystem_path]
646
+ **File inventory:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
647
+
648
+ <agent-instructions>
649
+ <instruction order="1" name="read-inventory">
650
+ Read structure.md for the complete file inventory.
651
+ </instruction>
652
+ <instruction order="2" name="identify-groups">
653
+ Identify groups of structurally similar files:
654
+ repositories, mappers, handlers, command/query objects, factories, validators.
655
+ </instruction>
656
+ <instruction order="3" name="compare-files">
657
+ Read 3+ files from each group.
658
+ </instruction>
659
+ <instruction order="4" name="classify-patterns">
660
+ When files follow the same structural template, that is a pattern.
661
+ Name the pattern by what it achieves, not by structural form.
662
+
663
+ Examples of patterns to look for:
664
+ <pattern-examples>
665
+ <pattern>Repository Pattern (multiple repo implementations of one interface)</pattern>
666
+ <pattern>CQRS Command/Query (separate handler per command/query)</pattern>
667
+ <pattern>Template Method (abstract base class with overridable steps)</pattern>
668
+ <pattern>Factory / Registry (lookup table for creating objects by type)</pattern>
669
+ <pattern>Mapper Pattern (bidirectional DTO &lt;-&gt; domain conversion)</pattern>
670
+ <pattern>Strategy Pattern (interchangeable algorithm implementations)</pattern>
671
+ </pattern-examples>
672
+ </instruction>
673
+ </agent-instructions>
674
+
675
+ Output to .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-patterns.md:
676
+
677
+ ```markdown
678
+ # Pattern Discovery: [subsystem_name]
679
+
680
+ ## Patterns Found
681
+
682
+ | # | Pattern Name | Representative Files (2-4 examples that demonstrate the pattern) |
683
+ |---|--------------|------------------------------------------------------------------|
684
+ | 1 | [name] | [2-4 file paths] |
685
+ ```
686
+
687
+ Return: count of patterns found.",
688
+ subagent_type="ace-wiki-mapper",
689
+ model="{MAPPER_MODEL}",
690
+ run_in_background=true,
691
+ description="Discover implementation patterns"
692
+ )
693
+ ```
694
+ </substep>
695
+
696
+ <substep order="10.5" name="launch-cross-cutting-discovery" parallel="true">
697
+ Launch with run_in_background=true:
698
+
699
+ ```
700
+ Task(
701
+ prompt="Focus: cross-cutting-discovery
702
+
703
+ Discover cross-cutting concerns and common implementation tasks in this subsystem
704
+ by reading shared infrastructure files.
705
+
706
+ **Subsystem path:** [subsystem_path]
707
+ **File inventory:** Read .docs/wiki/subsystems/[subsystem_name]/structure.md
708
+ **Architecture doc:** .docs/wiki/subsystems/[subsystem_name]/architecture.md
709
+
710
+ <agent-instructions>
711
+ <instruction order="1" name="read-context">
712
+ Read structure.md and architecture.md for context.
713
+ </instruction>
714
+ <instruction order="2" name="identify-shared-infra">
715
+ Identify shared infrastructure that multiple domain flows depend on — then read it:
716
+ <checklist>
717
+ <item>DI container / service registration files</item>
718
+ <item>Event bus, message broker, pub/sub infrastructure</item>
719
+ <item>Cache / invalidation infrastructure</item>
720
+ <item>Authentication / authorization middleware</item>
721
+ <item>Shared abstract base classes</item>
722
+ <item>Error handling and logging infrastructure</item>
723
+ <item>Registry / factory lookup tables</item>
724
+ </checklist>
725
+ </instruction>
726
+ <instruction order="3" name="assess-scope">
727
+ For each shared infrastructure file, read it to understand its scope.
728
+ </instruction>
729
+ <instruction order="4" name="identify-guides">
730
+ Identify guide candidates — common tasks a developer would repeat:
731
+ <guide-derivation-rules>
732
+ <rule source="Repository Pattern" guide="How to Add a New Repository" />
733
+ <rule source="CRUD system exists" guide="How to Add a New CRUD Endpoint" />
734
+ </guide-derivation-rules>
735
+ </instruction>
736
+ </agent-instructions>
737
+
738
+ Output to .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-cross-cutting.md:
739
+
740
+ ```markdown
741
+ # Cross-Cutting Discovery: [subsystem_name]
742
+
743
+ ## Cross-Cutting Concerns
744
+
745
+ | # | Concern Name | Files |
746
+ |---|--------------|-------|
747
+ | 1 | [name] | [all files implementing this concern] |
748
+
749
+ ## Guide Candidates
750
+
751
+ | # | Guide Name | Reference Files |
752
+ |---|------------|----------------|
753
+ | 1 | [e.g., How to Add a New CRUD Endpoint] | [files demonstrating the recipe] |
754
+ ```
755
+
756
+ Return: count of cross-cutting concerns + count of guide candidates.",
757
+ subagent_type="ace-wiki-mapper",
758
+ model="{MAPPER_MODEL}",
759
+ run_in_background=true,
760
+ description="Discover cross-cutting concerns and guides"
761
+ )
762
+ ```
763
+ </substep>
764
+
765
+ <substep order="10.6" name="wait-for-discovery">
766
+ Wait for all three discovery agents to complete.
767
+ </substep>
768
+
769
+ <substep order="10.7" name="doc-inventory" condition="existing-docs contains a directory">
770
+ Only spawned if existing-docs contains a directory.
771
+
772
+ Spawn a doc inventory agent to produce a compact index of the external docs.
773
+ This runs BEFORE the synthesis agent so that synthesis has a lightweight
774
+ inventory to work with instead of reading hundreds of files itself.
775
+
776
+ ```
777
+ Task(
778
+ prompt="You are a documentation inventory agent. Produce a compact index of all
779
+ documentation files in a directory so downstream agents can match docs to modules
780
+ without reading every file themselves.
781
+
782
+ **Documentation directory to scan:** [directory path from existing-docs]
783
+ **Output file:** .ace/artifacts/subsystems/[subsystem_name]/module-discovery/existing-docs-inventory.md
784
+
785
+ <agent-instructions>
786
+ <instruction order="1" name="list-files">
787
+ Recursively list ALL files in the directory down to every leaf subdirectory.
788
+ Use Glob(pattern='**/*', path='[directory path]') to ensure no nesting level
789
+ is missed. Do NOT use shallow ls or single-level globs.
790
+ </instruction>
791
+ <instruction order="2" name="determine-depth">
792
+ Count total files to determine summary depth:
793
+ <depth-rules>
794
+ <rule range="up to 50 files" read-lines="30-50" summary-lines="up to 10" />
795
+ <rule range="51-150 files" read-lines="20-30" summary-lines="up to 5" />
796
+ <rule range="151-300 files" read-lines="15-20" summary-lines="up to 3" />
797
+ <rule range="300+ files" read-lines="10" summary-lines="1-2" />
798
+ </depth-rules>
799
+ </instruction>
800
+ <instruction order="3" name="read-and-summarize">
801
+ For each file, read the adaptive number of lines determined above.
802
+ </instruction>
803
+ <instruction order="4" name="write-inventory">
804
+ Write the inventory to the output file in this format:
805
+
806
+ ```markdown
807
+ # Existing Documentation Inventory
808
+
809
+ Source directory: [directory path]
810
+ Total files: [count]
811
+ Summary depth: [lines per file based on count]
812
+
813
+ ## [File Path]
814
+ **Title:** [first heading or filename]
815
+ **Summary:**
816
+ [Adaptive-length summary: key topics, domain concepts, APIs/interfaces described,
817
+ architectural decisions mentioned. Enough detail for a downstream agent to
818
+ determine which code modules this doc is relevant to.]
819
+
820
+ ## [Next File Path]
821
+ ...
822
+ ```
823
+
824
+ Be thorough — every file must appear in the inventory.
825
+ </instruction>
826
+ </agent-instructions>
827
+
828
+ Return: total file count.",
829
+ subagent_type="ace-wiki-mapper",
830
+ model="{MAPPER_MODEL}",
831
+ description="Inventory existing docs"
832
+ )
833
+ ```
834
+
835
+ Display to user:
836
+ ```
837
+ Existing docs inventory: [N] files indexed from [directory path]
838
+ Saved to .ace/artifacts/subsystems/[subsystem_name]/module-discovery/existing-docs-inventory.md
839
+ ```
840
+ </substep>
841
+
842
+ <substep order="10.8" name="synthesis" sequential="true">
843
+ Synthesis Agent (sequential — runs after all above complete):
844
+
845
+ ```
846
+ Task(
847
+ prompt="Focus: module-discovery synthesis
848
+
849
+ Synthesize three discovery reports into the final module-discovery.md artifact.
850
+
851
+ **Output template:** Read ${CLAUDE_SKILL_DIR}/templates/module-discovery.xml
852
+ **Discovery inputs (read all three):**
853
+ - .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-flows.md (systems)
854
+ - .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-patterns.md (patterns)
855
+ - .ace/artifacts/subsystems/[subsystem_name]/module-discovery/discovery-cross-cutting.md (cross-cutting + guides)
856
+ **File inventory:** .docs/wiki/subsystems/[subsystem_name]/structure.md
857
+ **External docs inventory (if exists):** .ace/artifacts/subsystems/[subsystem_name]/module-discovery/existing-docs-inventory.md
858
+
859
+ <agent-instructions>
860
+ <instruction order="1" name="read-inputs">
861
+ Read all three discovery inputs.
862
+ </instruction>
863
+ <instruction order="2" name="discover-existing-docs">
864
+ Discover existing documentation:
865
+ <checklist>
866
+ <item>Scan the subsystem directory ([subsystem_path]) recursively for *.md files</item>
867
+ <item>Also scan common doc locations: docs/, documentation/, .docs/</item>
868
+ <item>If existing-docs-inventory.md exists, read it and INCLUDE all entries
869
+ in the Existing Documentation Inventory table (these are external docs
870
+ already indexed — do NOT re-scan the original directory)</item>
871
+ <item>Read each locally-discovered doc's title and first few lines to understand its subject</item>
872
+ <item>Build the Existing Documentation Inventory table (local + external combined)</item>
873
+ </checklist>
874
+ </instruction>
875
+ <instruction order="3" name="merge-modules">
876
+ Merge all discovery results into ONE flat Modules table:
877
+ <checklist>
878
+ <item>E2E flows from discovery-flows.md become modules</item>
879
+ <item>Patterns from discovery-patterns.md become modules</item>
880
+ <item>Cross-cutting concerns from discovery-cross-cutting.md become modules</item>
881
+ <item>Do NOT categorize by type map-story decides what docs to produce</item>
882
+ </checklist>
883
+ </instruction>
884
+ <instruction order="4" name="curate-docs-to-modules">
885
+ Curate docs to modules (populate the Relevant Docs column):
886
+ <checklist>
887
+ <item>Match each discovered doc to the module(s) whose domain it describes</item>
888
+ <item>A doc can appear in multiple modules</item>
889
+ <item>Architecture docs and READMEs are typically relevant to all flow modules</item>
890
+ <item>Implementation docs match the module they describe</item>
891
+ <item>Mark unmatched docs in the inventory table</item>
892
+ </checklist>
893
+ </instruction>
894
+ <instruction order="5" name="file-coverage-check">
895
+ File coverage check:
896
+ <checklist>
897
+ <item>Read structure.md for the complete file inventory</item>
898
+ <item>Every non-trivial file must appear in at least one module</item>
899
+ <item>List any uncovered files; create new modules for files with meaningful logic</item>
900
+ <item>Exclude only: index re-exports, empty stubs, generated code, test files</item>
901
+ </checklist>
902
+ </instruction>
903
+ <instruction order="6" name="preserve-overlaps">
904
+ Preserve overlaps files appearing in multiple modules are correct.
905
+ </instruction>
906
+ </agent-instructions>
907
+
908
+ Write to .ace/artifacts/subsystems/[subsystem_name]/module-discovery/module-discovery.md
909
+
910
+ Return: total module count + uncovered file count + existing docs found count.",
911
+ subagent_type="ace-wiki-mapper",
912
+ model="{MAPPER_MODEL}",
913
+ description="Synthesize module discovery"
914
+ )
915
+ ```
916
+ </substep>
917
+
918
+ Continue to step 11.
919
+ </step>
920
+
921
+ <!-- ══════════════════════════════════════════════════════════════════ -->
922
+ <!-- STEP 11: KNOWLEDGE DOCUMENTATION VIA MAP-STORY -->
923
+ <!-- ══════════════════════════════════════════════════════════════════ -->
924
+
925
+ <step name="knowledge-documentation" order="11">
926
+ For each module row in module-discovery.md, spawn one ace-wiki-mapper agent
927
+ that follows the map-story workflow in file mode.
928
+
929
+ Run agents SEQUENTIALLY — wait for each to complete before starting the next.
930
+ Sequential prevents write conflicts: map-story writes multiple doc files per call
931
+ and two concurrent agents could clash on the same file.
932
+
933
+ <substep order="11.1" name="read-module-discovery">
934
+ Read .ace/artifacts/subsystems/[subsystem_name]/module-discovery/module-discovery.md.
935
+
936
+ The file has one Modules table.
937
+ Each row has: # | Module Name | Files | Relevant Docs
938
+ </substep>
939
+
940
+ <substep order="11.2" name="merge-existing-docs">
941
+ If the `existing-docs` parameter was provided to map-subsystem,
942
+ merge those entries (files and/or directories, as-is) with each row's Relevant Docs
943
+ column.
944
+
945
+ <merge-rules>
946
+ <rule>For each module row, the final existing-docs list =
947
+ (command-level existing-docs) + (row's Relevant Docs)</rule>
948
+ <rule>Deduplicate any overlapping paths</rule>
949
+ <rule>If both are empty, use `none`</rule>
950
+ <rule>Do NOT expand directories here — map-story handles directory resolution internally
951
+ by spinning up a curation agent that selects only relevant docs</rule>
952
+ </merge-rules>
953
+
954
+ If existing-docs-inventory.md was produced in step 10, also pass its path to
955
+ each map-story invocation so the curation agent can use the pre-built inventory
956
+ instead of re-scanning the directory from scratch for every module.
957
+ </substep>
958
+
959
+ <substep order="11.3" name="iterate-modules">
960
+ Iterate ALL rows (one at a time, sequential):
961
+
962
+ ```
963
+ Task(
964
+ prompt="Load and follow the map-story workflow in file mode.
965
+
966
+ **Workflow:** This agent should invoke /ace:map-story or follow the map-story skill workflow
967
+ **Mode:** file mode — document existing code (no git diff)
968
+
969
+ **Module name:** [Module Name from row]
970
+ **Files to document:** [comma-separated file list from Files column]
971
+ **Existing docs context:** [merged existing-docs: command-level + row Relevant Docs, deduplicated, or `none`]
972
+ **Existing docs inventory:** [path to existing-docs-inventory.md if it was produced, or `none`]
973
+ **Subsystem name:** [subsystem_name]
974
+
975
+ **TEMPLATES Read ALL of these before writing ANY docs:**
976
+ - System docs: ${CLAUDE_SKILL_DIR}/templates/system.xml
977
+ - Pattern docs: ${CLAUDE_SKILL_DIR}/templates/pattern.xml
978
+ - Cross-cutting docs: ${CLAUDE_SKILL_DIR}/templates/system-cross-cutting.xml
979
+ - Guide docs: ${CLAUDE_SKILL_DIR}/templates/guide.xml
980
+ - Decision docs: ${CLAUDE_SKILL_DIR}/templates/decizions.xml
981
+
982
+ <agent-instructions>
983
+ <instruction order="1" name="read-source">
984
+ Read ALL source files listed in Files. Understand the actual code — classes,
985
+ interfaces, patterns, state, flows, DI registrations, constants, error handling.
986
+ </instruction>
987
+
988
+ <instruction order="2" name="read-existing-docs">
989
+ If Existing docs context is not `none`, read those documents FIRST
990
+ they contain prior knowledge, intent, and decisions about this module's domain.
991
+ Use them as additional context when writing, but the actual source code is
992
+ always the source of truth.
993
+ </instruction>
994
+
995
+ <instruction order="3" name="read-wiki">
996
+ Read ALL existing wiki docs under .docs/wiki/subsystems/[subsystem_name]/
997
+ EVERY .md file, FULLY. Not titles. Not summaries. THE COMPLETE CONTENT.
998
+ Build a mental map of what is already documented so you do NOT create
999
+ duplicate documentation. This is MANDATORY.
1000
+ </instruction>
1001
+
1002
+ <instruction order="4" name="decide-docs">
1003
+ You decide what docs to create or update systems/, patterns/, cross-cutting/,
1004
+ guides/, walkthroughs/, decisions/ — based on what you find in the code files. One call may
1005
+ produce multiple docs across different categories.
1006
+ </instruction>
1007
+
1008
+ <instruction order="5" name="update-vs-create">
1009
+ When an existing doc already covers a topic, UPDATE it (add/expand sections).
1010
+ Only CREATE new docs for genuinely new topics not covered anywhere.
1011
+ </instruction>
1012
+
1013
+ <instruction order="6" name="topic-scoped-only">
1014
+ NEVER create a story-scoped or module-scoped document.
1015
+ All docs are TOPIC-scoped about the concern, not about the module.
1016
+ </instruction>
1017
+ </agent-instructions>
1018
+
1019
+ Return: list of all docs created/updated with line counts.",
1020
+ subagent_type="ace-wiki-mapper",
1021
+ model="{MAPPER_MODEL}",
1022
+ description="Document [module_name]"
1023
+ )
1024
+ ```
1025
+
1026
+ Collect each agent's report before spawning the next.
1027
+ </substep>
1028
+
1029
+ <substep order="11.4" name="compile-report">
1030
+ After all rows are processed, compile the full knowledge docs report.
1031
+ </substep>
1032
+
1033
+ Continue to step 12.
1034
+ </step>
1035
+
1036
+ <!-- ══════════════════════════════════════════════════════════════════ -->
1037
+ <!-- STEP 12: VERIFY AND COMMIT -->
1038
+ <!-- ══════════════════════════════════════════════════════════════════ -->
1039
+
1040
+ <step name="verify-and-commit" order="12">
1041
+
1042
+ <substep order="12.1" name="verify-documents">
1043
+ Verify all expected documents exist and are non-empty.
1044
+
1045
+ For each document where the action was NOT `skip`:
1046
+ <verification-checks>
1047
+ <check>File exists</check>
1048
+ <check>File has content (>20 lines for create/update/recreate)</check>
1049
+ </verification-checks>
1050
+
1051
+ If any document is missing or empty, warn the user.
1052
+ </substep>
1053
+
1054
+ <substep order="12.2" name="security-scan">
1055
+ Security scan before commit — use the Grep tool (NOT bash grep):
1056
+
1057
+ ```
1058
+ Grep(
1059
+ 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)",
1060
+ path=".docs/wiki/subsystems/[subsystem_name]/",
1061
+ output_mode="content"
1062
+ )
1063
+ ```
1064
+
1065
+ <variant condition="matches found">SECRETS_FOUND — pause and alert user.</variant>
1066
+ <variant condition="no matches">CLEAN.</variant>
1067
+ </substep>
1068
+
1069
+ <substep order="12.3" name="commit" condition="commit_docs is true">
1070
+ Commit (if `commit_docs` is true):
1071
+
1072
+ <stage-files>
1073
+ <always>
1074
+ ```bash
1075
+ git add .docs/wiki/subsystems/[subsystem_name]/
1076
+ ```
1077
+ </always>
1078
+
1079
+ <conditional condition="system-structure.md was updated in step 9a">
1080
+ ```bash
1081
+ git add .docs/wiki/system-wide/system-structure.md
1082
+ ```
1083
+ </conditional>
1084
+
1085
+ <conditional condition="system-architecture.md was updated in step 9b">
1086
+ ```bash
1087
+ git add .docs/wiki/system-wide/system-architecture.md
1088
+ ```
1089
+ </conditional>
1090
+
1091
+ <conditional condition="module-discovery artifacts were written in step 10">
1092
+ ```bash
1093
+ git add .ace/artifacts/subsystems/[subsystem_name]/module-discovery/
1094
+ ```
1095
+ </conditional>
1096
+ </stage-files>
1097
+
1098
+ ```bash
1099
+ git commit -m "docs: map [subsystem_name] subsystem wiki and knowledge base"
1100
+ ```
1101
+ </substep>
1102
+
1103
+ Continue to step 13.
1104
+ </step>
1105
+
1106
+ <!-- ══════════════════════════════════════════════════════════════════ -->
1107
+ <!-- STEP 13: COMPLETION -->
1108
+ <!-- ══════════════════════════════════════════════════════════════════ -->
1109
+
1110
+ <step name="completion" order="13">
1111
+ Display completion banner and next steps.
1112
+
1113
+ ```
1114
+ ╔══════════════════════════════════════════════════╗
1115
+ ║ ACE > Subsystem Mapped ║
1116
+ ╚══════════════════════════════════════════════════╝
1117
+
1118
+ Subsystem: [subsystem_name] ([subsystem_path])
1119
+
1120
+ Documents:
1121
+ ──────────
1122
+ [For each document, show action taken and line count]
1123
+ + structure.md ([N] lines) — [created/updated/recreated]
1124
+ + architecture.md ([N] lines) — [created/updated/recreated]
1125
+ - [document] skipped
1126
+
1127
+ [If system-structure.md was updated in step 9a:]
1128
+ ~ system-structure.md — subsystem entry added
1129
+
1130
+ [If system-architecture.md was updated in step 9b:]
1131
+ ~ system-architecture.md — subsystem responsibility matrix updated
1132
+
1133
+ [If knowledge docs were produced in step 11:]
1134
+ Knowledge Docs (.docs/wiki/subsystems/[subsystem_name]/):
1135
+ ──────────────────────────────────────────────────────────
1136
+ [For each doc written by map-story: show filename and line count]
1137
+
1138
+ Next > `/clear` first for a fresh context window, then:
1139
+
1140
+ /ace:map-subsystem [next-subsystem]
1141
+ Map another subsystem.
1142
+
1143
+ Also available (`/clear` first):
1144
+ - /ace:map-system — Re-run to refresh system-wide documents
1145
+ - /ace:init-coding-standards — Define coding standards
1146
+ - Review files in .docs/wiki/subsystems/[subsystem_name]/
1147
+ ```
1148
+
1149
+ End workflow.
1150
+ </step>
1151
+
1152
+ </process>
1153
+
1154
+ <success_criteria>
1155
+ <criterion>Init function executed (environment detected, mapper model resolved)</criterion>
1156
+ <criterion>Subsystem path resolved and validated against the codebase</criterion>
1157
+ <criterion>System-wide docs read for context before analysis begins</criterion>
1158
+ <criterion>Each document triaged independently (create/update/recreate/skip)</criterion>
1159
+ <criterion>Agents spawned in parallel (structure + architecture) where possible</criterion>
1160
+ <criterion>system-structure.md updated if this is a previously undocumented subsystem</criterion>
1161
+ <criterion>system-architecture.md subsystem responsibility matrix updated if subsystem was missing</criterion>
1162
+ <criterion>All created documents verified for content (non-empty, >20 lines)</criterion>
1163
+ <criterion>Security scan passed (no secrets in generated docs)</criterion>
1164
+ <criterion>Documents committed to .docs/wiki/subsystems/[subsystem_name]/</criterion>
1165
+ <criterion>Module discovery completed; .ace/artifacts/subsystems/[subsystem_name]/module-discovery/module-discovery.md written</criterion>
1166
+ <criterion>map-story called sequentially for each module row; all completed</criterion>
1167
+ <criterion>Each map-story agent reads ALL existing wiki docs FULLY before writing (no duplication)</criterion>
1168
+ <criterion>Knowledge docs written to .docs/wiki/subsystems/[subsystem_name]/</criterion>
1169
+ <criterion>module-discovery.md staged and committed</criterion>
1170
+ <criterion>User sees clear completion summary with next steps</criterion>
1171
+ </success_criteria>
1172
+
1173
+ </workflow>