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,659 +1,657 @@
1
- <workflow>
2
-
3
- <purpose>
4
- Perform COMPREHENSIVE, IN-DEPTH, CODE-LEVEL analysis of how a specific story
5
- is implemented in an external reference system. Load the story requirements, validate
6
- the external codebase, optionally load external documentation, then execute exhaustive
7
- code analysis following the template's analysis-process phases. Write the analysis to
8
- external-analysis.md in the story's artifact directory.
9
-
10
- Produces `.ace/artifacts/product/<id-epic_name>/<id-feature_name>/<id-story_name>/external-analysis.md`
11
- — a comprehensive code-level analysis with algorithms, patterns, formulas, and
12
- implementation details extracted verbatim from the external system's code.
13
-
14
- This is pass 3 of the story specification pipeline (see story.xml composition).
15
- All output is written ONLY to the analysis file — no GitHub updates, no modifications
16
- to the story file.
17
-
18
- This workflow is executed by the `ace-code-discovery-analyst` agent
19
- (spawned via `subagent_type="ace-code-discovery-analyst"`).
20
- </purpose>
21
-
22
- <mandatory-context>
23
- Read all files referenced by the invoking command's execution-context before starting.
24
- Also read any document or text passed as parameter ($ARGUMENTS) in the invoking command.
25
- </mandatory-context>
26
-
27
- <process>
28
-
29
- <!-- ══════════════════════════════════════════════════════════════════ -->
30
- <!-- STEP 1: SETUP -->
31
- <!-- ══════════════════════════════════════════════════════════════════ -->
32
-
33
- <step name="setup" order="1">
34
- **MANDATORY FIRST STEP — Execute environment detection and story initialization:**
35
-
36
- ```bash
37
- INIT=$(node ~/.claude/agile-context-engineering/src/ace-tools.js init research-story {story_param})
38
- ```
39
-
40
- This single call validates the story parameter, extracts metadata/requirements/wiki
41
- references, computes all paths and slugs, and checks artifact existence.
42
-
43
- Parse INIT JSON for:
44
- - **Environment**: `has_git`, `has_gh_cli`, `github_project`, `analyst_model`
45
- - **Story validation**: `story_valid`, `story_error`, `story_source`
46
- - **Story metadata**: `story` (id, title, status, size), `feature` (id, title), `epic` (id, title)
47
- - **Requirements**: `user_story`, `description`, `acceptance_criteria_count`
48
- - **Paths**: `paths.*` (story_dir, story_file, external_analysis_file, feature_dir, feature_file, etc.)
49
- - **Artifacts**: `has_external_analysis`, `has_integration_analysis`, `has_feature_file`
50
-
51
- Display stage banner:
52
-
53
- ```
54
- ╔══════════════════════════════════════════════════╗
55
- ║ ACE > Research External Solution ║
56
- ╚══════════════════════════════════════════════════╝
57
- ```
58
-
59
- **If `has_git` is false:** Initialize git:
60
- ```bash
61
- git init
62
- ```
63
-
64
- **If `INIT.story_valid` is false:**
65
- Display error using `INIT.story_error` and exit.
66
- </step>
67
-
68
- <!-- ══════════════════════════════════════════════════════════════════ -->
69
- <!-- STEP 2: VALIDATE & LOAD STORY -->
70
- <!-- ══════════════════════════════════════════════════════════════════ -->
71
-
72
- <step name="validate-story" order="2">
73
-
74
- **Story validation, parsing, and path computation were completed by
75
- `init research-story` in step 1.** All metadata, requirements, and
76
- paths are available in the INIT JSON.
77
-
78
- Read the story file content for analysis context:
79
-
80
- **If `INIT.story_source` is `file`:**
81
- Read the file at `INIT.paths.story_file`. Store as STORY_CONTENT.
82
-
83
- **If `INIT.story_source` is `github-url` or `issue-number`:**
84
- Fetch the issue body using INIT's GitHub project context:
85
- ```bash
86
- GH_STORY=$(gh issue view {issue_number} --repo {INIT.github_project.owner}/{INIT.github_project.repo} --json body -q .body)
87
- ```
88
- Store as STORY_CONTENT.
89
-
90
- The story's User Story, Description, and Acceptance Criteria define
91
- WHAT functionality to analyze in the external codebase. These are the
92
- requirements — do NOT seek requirements from other sources.
93
- Wiki references from `INIT.wiki_references` may inform exploration.
94
-
95
- <!-- ── 2b: Read parent feature document ───────────────────────── -->
96
-
97
- **If `INIT.has_feature_file` is true:**
98
- Read the feature document at `INIT.paths.feature_file` and extract:
99
- - Feature description and scope
100
- - List of all stories in the feature (IDs, titles, descriptions)
101
- - Dependencies between stories
102
- - Shared components or services mentioned
103
- This informs the "Story Integration Within Feature" section.
104
-
105
- **If `INIT.has_feature_file` is false:**
106
- Proceed without the analysis can still be done without feature context.
107
-
108
- <!-- ── 2c: Display ───────────────────────────────────────────────── -->
109
-
110
- Set pre-computed paths from INIT:
111
- - `STORY_FILE = INIT.paths.story_file`
112
- - `STORY_DIR = INIT.paths.story_dir`
113
-
114
- Display:
115
- ```
116
- i Story loaded: {INIT.story.id} — {INIT.story.title}
117
- Feature: {INIT.feature.id} {INIT.feature.title}
118
- Epic: {INIT.epic.id} — {INIT.epic.title}
119
- Requirements: {INIT.acceptance_criteria_count} acceptance criteria scenarios
120
- ```
121
- </step>
122
-
123
- <!-- ══════════════════════════════════════════════════════════════════ -->
124
- <!-- STEP 3: VALIDATE EXTERNAL CODEBASE -->
125
- <!-- ══════════════════════════════════════════════════════════════════ -->
126
-
127
- <step name="validate-external-codebase" order="3">
128
-
129
- Parse the `external-codebase` parameter from $ARGUMENTS.
130
-
131
- <!-- ── 3a: Local path ────────────────────────────────────────────── -->
132
-
133
- **If local path:**
134
-
135
- Confirm folder exists and contains source code:
136
- ```bash
137
- ls {external_codebase_path}/
138
- ```
139
-
140
- **If not valid:** Display error and exit:
141
- ```
142
- x External codebase not found: {external_codebase_path}
143
- Provide a valid local path to a source code directory
144
- or a GitHub repository URL.
145
- ```
146
-
147
- Set `EXTERNAL_CODEBASE_PATH = {external_codebase_path}`
148
-
149
- <!-- ── 3b: GitHub URL ────────────────────────────────────────────── -->
150
-
151
- **If GitHub URL:**
152
-
153
- Verify repository accessibility:
154
- ```bash
155
- gh repo view {repo_identifier} --json name,url 2>/dev/null
156
- ```
157
-
158
- **If not accessible:** Display error and exit:
159
- ```
160
- x External repository not accessible: {repo_url}
161
- Verify the URL is correct and the repository is public
162
- or you have access.
163
- ```
164
-
165
- Set `EXTERNAL_CODEBASE_PATH = {resolved path or URL}`
166
-
167
- <!-- ── 3c: Display ───────────────────────────────────────────────── -->
168
-
169
- Display:
170
- ```
171
- i External codebase: {EXTERNAL_CODEBASE_PATH}
172
- ```
173
- </step>
174
-
175
- <!-- ══════════════════════════════════════════════════════════════════ -->
176
- <!-- STEP 4: LOAD EXTERNAL DOCS (OPTIONAL) -->
177
- <!-- ══════════════════════════════════════════════════════════════════ -->
178
-
179
- <step name="load-external-docs" order="4">
180
-
181
- Parse the `external-docs` parameter from $ARGUMENTS.
182
-
183
- <!-- ── 4a: Not provided ──────────────────────────────────────────── -->
184
-
185
- **If not provided:**
186
-
187
- Check if context7 MCP server is available (check if `mcp__context7__resolve-library-id`
188
- or similar context7 tools are available in the current tool set).
189
-
190
- **If context7 available:**
191
- Set `USE_CONTEXT7 = true`
192
- Display:
193
- ```
194
- i No external docs provided.
195
- context7 MCP server detected — will use it for library documentation.
196
- ```
197
-
198
- **If context7 not available:**
199
- Set `USE_CONTEXT7 = false`
200
- Display:
201
- ```
202
- i No external docs provided. Analysis will rely on code exploration.
203
- TIP: Provide external-docs= for richer analysis,
204
- or install context7 MCP server for automatic library docs.
205
- ```
206
-
207
- <!-- ── 4b: Provided as weblink ───────────────────────────────────── -->
208
-
209
- **If provided as weblink:**
210
-
211
- Verify URL accessibility (attempt a fetch or HEAD request).
212
-
213
- **If not accessible:** Display warning (non-fatal):
214
- ```
215
- ! External docs URL not accessible: {url}
216
- Continuing without external docs.
217
- ```
218
-
219
- **If accessible:**
220
- Store as `EXTERNAL_DOCS_URL = {url}`
221
- Display:
222
- ```
223
- i External docs: {url}
224
- ```
225
-
226
- <!-- ── 4c: Provided as filepath ──────────────────────────────────── -->
227
-
228
- **If provided as filepath:**
229
-
230
- Verify file exists:
231
- ```bash
232
- DOCS_EXISTS=$(node ~/.claude/agile-context-engineering/src/ace-tools.js verify-path-exists {filepath} --raw)
233
- ```
234
-
235
- **If not exists:** Display warning (non-fatal):
236
- ```
237
- ! External docs file not found: {filepath}
238
- Continuing without external docs.
239
- ```
240
-
241
- **If exists:** Read the file. Store as `EXTERNAL_DOCS_CONTENT`.
242
- Display:
243
- ```
244
- i External docs: {filepath}
245
- ```
246
- </step>
247
-
248
- <!-- ══════════════════════════════════════════════════════════════════ -->
249
- <!-- STEP 5: RESOLVE OUTPUT PATH -->
250
- <!-- ══════════════════════════════════════════════════════════════════ -->
251
-
252
- <step name="resolve-output-path" order="5">
253
-
254
- **Paths were pre-computed by `init research-story` in step 1.**
255
-
256
- Set from INIT JSON:
257
- - `STORY_DIR = INIT.paths.story_dir`
258
- - `OUTPUT_FILE = INIT.paths.external_analysis_file`
259
-
260
- Ensure directory exists:
261
- ```bash
262
- mkdir -p {STORY_DIR}
263
- ```
264
-
265
- Display:
266
- ```
267
- i Output: {OUTPUT_FILE}
268
- ```
269
- </step>
270
-
271
- <!-- ══════════════════════════════════════════════════════════════════ -->
272
- <!-- STEP 6: CHECK EXISTING ANALYSIS -->
273
- <!-- ══════════════════════════════════════════════════════════════════ -->
274
-
275
- <step name="check-existing" order="6">
276
-
277
- **If `INIT.has_external_analysis` is true:**
278
-
279
- Use AskUserQuestion:
280
- - header: "Existing"
281
- - question: "An external analysis already exists at `{OUTPUT_FILE}`. What would you like to do?"
282
- - options:
283
- - "Overwrite" — Discard and create a new analysis from scratch
284
- - "Skip" Keep the current analysis as-is
285
-
286
- **If "Overwrite":** Continue to step 7.
287
- **If "Skip":** Display message and exit workflow:
288
- ```
289
- i Keeping existing analysis. No changes made.
290
- ```
291
-
292
- **If not exists:** Continue to step 7.
293
- </step>
294
-
295
- <!-- ══════════════════════════════════════════════════════════════════ -->
296
- <!-- STEP 7: EXECUTE ANALYSIS -->
297
- <!-- ══════════════════════════════════════════════════════════════════ -->
298
-
299
- <step name="execute-analysis" order="7">
300
-
301
- Display:
302
- ```
303
- ┌──────────────────────────────────────────────────┐
304
- │ ACE > Research External Solution > Analysis │
305
- └──────────────────────────────────────────────────┘
306
-
307
- i Starting deep code-level analysis.
308
- Reading 30+ files and tracing execution paths
309
- 5+ levels deep. This may take several minutes.
310
- ```
311
-
312
- **Execute the complete analysis following the template's `<analysis-process>` section.**
313
- The template (`external-solution.xml`) defines 3 mandatory phases with 16 total items.
314
- You ARE the code-discovery-analystperform the analysis directly.
315
-
316
- <!-- ── 7a: Phase 1 Initial Discovery (3 mandatory items) ───────── -->
317
-
318
- **Phase 1: Initial Discovery**
319
-
320
- 1. **[MANDATORY] Understand the story requirements:**
321
- - Re-read STORY_CONTENT thoroughly — User Story, Description, all AC scenarios
322
- - These define WHAT functionality to analyze in the external codebase
323
- - Extract the key behaviors, algorithms, and patterns to look for
324
- - If parent feature document was loaded (step 2c), understand:
325
- - The broader feature context
326
- - What other stories exist and how they relate
327
- - Dependencies and shared components between stories
328
-
329
- 2. **[MANDATORY] Explore available documentation:**
330
- - **external-docs** (if EXTERNAL_DOCS_URL or EXTERNAL_DOCS_CONTENT set):
331
- Review for implementation context, API documentation, architecture overview.
332
- If URL: use WebFetch to retrieve content.
333
- Use documentation to guide code exploration.
334
- - **context7 MCP server** (if USE_CONTEXT7 is true — PREFERRED):
335
- Use `mcp__context7__resolve-library-id` to find the library,
336
- then `mcp__context7__get-library-docs` to fetch relevant docs.
337
- **ALWAYS prefer context7** when the external system is a known library/framework.
338
- - If neither available: rely entirely on code exploration.
339
-
340
- 3. **[MANDATORY] Locate the implementation:**
341
- - Find where the story's functionality is implemented in `EXTERNAL_CODEBASE_PATH`
342
- - Start with likely entry points: exports, public APIs, event handlers
343
- - Use Grep/Glob to find relevant files by keywords from the story
344
- - Read README files and documentation in the external codebase for structural guidance
345
- - Build an initial map of involved files before deep diving
346
-
347
- <!-- ── 7b: Phase 2 Deep Implementation Analysis (9 mandatory items) ── -->
348
-
349
- **Phase 2: Deep Implementation Analysis ALL 9 items MANDATORY, skip NONE:**
350
-
351
- 1. **[MANDATORY] Complete Entry Points & Triggers Identification (CRITICAL):**
352
- Document ALL entry points into the story functionality:
353
- - **User Action Triggers**: button clicks, form submissions, keyboard shortcuts
354
- - **API Entry Points**: REST endpoints, GraphQL mutations, RPC calls
355
- - **Event-Based Triggers**: WebSocket messages, system events, pub/sub messages
356
- - **Scheduled/Automated Triggers**: cron jobs, timers, intervals
357
- - **External System Triggers**: webhooks, callbacks, integrations
358
- For EACH entry point document:
359
- ```typescript
360
- // Entry Point Type: [User Action/API/Event/etc.]
361
- // File: src/path/file.ts:45-60
362
- // Trigger: [Exact trigger description]
363
- // Parameters: [List all parameters with types]
364
- // Example usage: [Show actual usage example]
365
- ```
366
-
367
- 2. **[MANDATORY] Complete Code Path Mapping:**
368
- - Follow EVERY code path from entry to completion
369
- - Include ALL branches, conditionals, and edge cases
370
- - Document every file, class, method, and function involved
371
- - Track all data transformations and state changes
372
- - Minimum call depth: 5+ levels
373
-
374
- 3. **[MANDATORY] Story-Specific File Tree:**
375
- - Document ONLY files involved in this story (NOT entire codebase)
376
- - Categorize as: CORE, SUPPORT, CONFIG, TEST
377
- - Include line counts and one-line purpose for each file
378
- - Include total file count and line count at bottom
379
-
380
- 4. **[MANDATORY] Constants & Configuration Extraction:**
381
- - Extract ALL constants and configuration values used by the story
382
- - Include ACTUAL values from code, NOT placeholders
383
- - Group by category: performance limits, business thresholds, magic numbers
384
- - Always include source file path and line numbers
385
-
386
- 5. **[MANDATORY] Algorithm & Formula Documentation:**
387
- For each calculation or algorithm found:
388
- - **Purpose**: What it calculates/achieves
389
- - **Formula**: Exact mathematical formula or logic
390
- - **Implementation**: Code snippet showing implementation
391
- - **Example**: Sample input/output with explanation
392
- - **Edge Cases**: How they handle special cases
393
-
394
- 6. **[MANDATORY] Comprehensive Flow Diagram:**
395
- Create a detailed Mermaid sequence diagram showing:
396
- - Complete execution flow with ALL branches
397
- - Actual method names and parameters (NOT generic names)
398
- - Data flow between components
399
- - State changes and side effects
400
- - Error handling paths
401
-
402
- 7. **[MANDATORY] Test Patterns Extraction:**
403
- - Extract actual test cases from the external system
404
- - Include test code snippets with assertions
405
- - Document test scenarios covered
406
- - Note edge cases tested
407
- - Extract test data patterns
408
- - Identify mocking strategies used
409
-
410
- 8. **[MANDATORY] Performance Considerations:**
411
- - Caching strategies used
412
- - Algorithm optimizations
413
- - Throttling/debouncing patterns
414
- - Memory management techniques
415
- - Batch processing approaches
416
- Include code references for each optimization.
417
-
418
- 9. **[MANDATORY] Validation & Security:**
419
- - Input validation rules with actual validation code
420
- - Data sanitization methods
421
- - Security checks implemented
422
- - Error boundaries
423
- Include actual code snippets showing validation logic.
424
-
425
- <!-- ── 7c: Phase 3 Pattern & Architecture Analysis (4 mandatory items) ── -->
426
-
427
- **Phase 3: Pattern & Architecture Analysis — ALL 4 items MANDATORY:**
428
-
429
- 1. **[MANDATORY] Design Patterns Identified:**
430
- - Document all design patterns used (Strategy, Observer, Factory, etc.)
431
- - Explain WHY they chose each pattern
432
- - Include code examples of pattern implementation
433
- - Note patterns shared with other parts of the system
434
- - Identify if patterns enable component integration/communication
435
-
436
- 2. **[MANDATORY] Component Lifecycle:**
437
- - Initialization sequence
438
- - State management approach
439
- - Cleanup/disposal mechanisms
440
- - Memory management considerations
441
-
442
- 3. **[MANDATORY] Performance Optimizations:**
443
- - Caching strategies
444
- - Algorithm optimizations
445
- - Rendering optimizations (if applicable)
446
- - Data structure choices for performance
447
-
448
- 4. **[MANDATORY] Error Handling & Edge Cases:**
449
- - How they handle errors at each architectural level
450
- - Validation approaches
451
- - Fallback mechanisms
452
- - Boundary conditions
453
-
454
- **CRITICAL REQUIREMENTS:**
455
- - **NO ASSUMPTIONS**: Only document what you actually find in the code
456
- - **STORY SCOPE ONLY**: Focus exclusively on code paths related to the story
457
- - **COMPLETE COVERAGE**: Every file and method involved must be documented
458
- - **EXACT IMPLEMENTATIONS**: Include actual code snippets, not descriptions
459
- - **FORMULAS & CALCULATIONS**: Extract and explain ALL mathematical operations
460
- - **METRICS**: Minimum 30+ files read, 50+ code references, 5+ call depth
461
- </step>
462
-
463
- <!-- ══════════════════════════════════════════════════════════════════ -->
464
- <!-- STEP 8: WRITE OUTPUT -->
465
- <!-- ══════════════════════════════════════════════════════════════════ -->
466
-
467
- <step name="write-output" order="8">
468
-
469
- Write the complete analysis to `{OUTPUT_FILE}` following the template's
470
- `<output-format>` section exactly. Include ALL sections:
471
-
472
- 1. Header (repository, version, story, date, metrics)
473
- 2. Implementation Overview
474
- 3. Entry Points & Triggers (categorized by type)
475
- 4. Story-Specific File Tree
476
- 5. Constants & Configuration
477
- 6. Core Implementation (Algorithms, Data Flow with Mermaid diagram, Key Components)
478
- 7. Code Examples
479
- 8. Test Patterns
480
- 9. Validation & Security
481
- 10. Performance Optimizations
482
- 11. Architecture Decisions (Design Patterns, Lifecycle, Error Handling)
483
- 12. Story Integration Within Feature
484
- 13. Lessons for Our Implementation
485
- 14. Complete File Reference
486
-
487
- Use the Write tool to create the file. Include all findings from step 7.
488
-
489
- This is NOT a summary — it is a COMPLETE CODE EXTRACTION. Every section
490
- must contain actual code snippets, file paths with line numbers, and
491
- concrete implementation details.
492
-
493
- Display:
494
- ```
495
- + Analysis written to {OUTPUT_FILE}
496
- ```
497
- </step>
498
-
499
- <!-- ══════════════════════════════════════════════════════════════════ -->
500
- <!-- STEP 9: VALIDATION -->
501
- <!-- ══════════════════════════════════════════════════════════════════ -->
502
-
503
- <step name="validation" order="9">
504
-
505
- Read the output file and verify against the validation checklist
506
- defined in the template (external-solution.xml):
507
-
508
- **File Creation Requirements:**
509
- - [ ] Analysis file created at {OUTPUT_FILE}
510
- - [ ] Story directory exists
511
- - [ ] File contains all required sections from template
512
-
513
- **Content Requirements Core Analysis:**
514
- - [ ] CRITICAL: No assumptions analysis reflects 100% accurate code, no guessing
515
- - [ ] Complete Entry Points & Triggers section with ALL trigger types
516
- - [ ] Story-Specific File Tree showing ONLY files involved in story
517
- - [ ] Constants & Configuration section with actual values
518
- - [ ] Mermaid sequence diagram showing complete data flow
519
- - [ ] All algorithms and formulas extracted with explanations
520
- - [ ] Code examples included from external implementation
521
- - [ ] Architecture patterns identified and documented
522
-
523
- **Content Requirements Enhanced Sections:**
524
- - [ ] Test Patterns section with actual test code
525
- - [ ] Validation & Security section with validation rules
526
- - [ ] Performance Optimizations documented
527
- - [ ] Story Integration Within Feature section completed
528
- - [ ] Complete File Reference with file roles
529
-
530
- **Analysis Quality Requirements:**
531
- - [ ] All entry points categorized (User/API/Event/External)
532
- - [ ] Complete code path mapping documented (5+ levels deep)
533
- - [ ] Error handling approaches analyzed
534
- - [ ] No assumptions made — only documented what was found in code
535
- - [ ] Lessons for our implementation clearly stated
536
-
537
- **Metrics Requirements:**
538
- - [ ] Minimum 30+ files read for the story
539
- - [ ] Minimum 50+ code references documented
540
- - [ ] Minimum 5+ call depth traced
541
- - [ ] All metrics reported in output header
542
-
543
- **Total: 23 mandatory checklist items**
544
-
545
- If the output is incomplete or missing sections, go back and fill in
546
- the missing content before proceeding.
547
-
548
- Display:
549
- ```
550
- {check_mark} Analysis validated. {passed}/{total} checks passed.
551
- ```
552
- </step>
553
-
554
- <!-- ══════════════════════════════════════════════════════════════════ -->
555
- <!-- STEP 10: REVIEW AND APPROVE -->
556
- <!-- ══════════════════════════════════════════════════════════════════ -->
557
-
558
- <step name="review" order="10">
559
-
560
- Display a summary of the analysis:
561
- ```
562
- Analysis Summary:
563
- ────────
564
- Files analyzed: {N} | Code references: {M} | Call depth: {D}
565
- Sections: {count}/14 | Checklist: {passed}/23
566
- ```
567
-
568
- Use AskUserQuestion:
569
- - header: "Analysis"
570
- - question: "External analysis written to `{OUTPUT_FILE}`. Review the file in your editor does the analysis look comprehensive?"
571
- - options:
572
- - "Approve" — Looks good, commit it
573
- - "Refine" — Some sections need more depth
574
- - "Skip commit" — Keep the file but don't commit yet
575
-
576
- **If "Approve":**
577
- Continue to step 11.
578
-
579
- **If "Refine":**
580
- - Ask what sections need more depth or what's missing
581
- - Go back to the relevant analysis phase, read more code, and update OUTPUT_FILE
582
- - Re-run validation (step 9)
583
- - Present for review again
584
-
585
- **If "Skip commit":**
586
- Display completion without commit:
587
- ```
588
- ╔══════════════════════════════════════════════════╗
589
- ║ ACE > External Analysis Complete (uncommitted) ║
590
- ║ {Story ID} "{Story Title}" ║
591
- ╚══════════════════════════════════════════════════╝
592
-
593
- i Analysis written to {OUTPUT_FILE}
594
- File not committed — commit manually when ready.
595
- ```
596
- Exit workflow.
597
- </step>
598
-
599
- <!-- ══════════════════════════════════════════════════════════════════ -->
600
- <!-- STEP 11: COMMIT -->
601
- <!-- ══════════════════════════════════════════════════════════════════ -->
602
-
603
- <step name="commit" order="11">
604
-
605
- Stage and commit the analysis file:
606
-
607
- ```bash
608
- git add {OUTPUT_FILE}
609
- ```
610
-
611
- ```bash
612
- git commit -m "docs: external analysis for {Story ID} — {Story Title}"
613
- ```
614
-
615
- Display completion:
616
-
617
- ```
618
- ╔══════════════════════════════════════════════════╗
619
- ║ ACE > External Analysis Complete ║
620
- ║ {Story ID} "{Story Title}" ║
621
- ╚══════════════════════════════════════════════════╝
622
-
623
- + {OUTPUT_FILE} committed.
624
-
625
- Metrics:
626
- ────────
627
- Files analyzed: {N} | Code references: {M} | Call depth: {D}
628
-
629
- i External analysis complete. This artifact will be consumed
630
- by the technical solution (pass 5) when running plan-story.
631
-
632
- Next > Continue with story refinement:
633
- - Integration analysis (pass 4)
634
- - Technical solution (pass 5)
635
- > /ace:research-external-solution story=... external-codebase=...
636
- Analyze another story's external implementation.
637
- ```
638
- </step>
639
-
640
- </process>
641
-
642
- <success_criteria>
643
- - Story loaded and requirements extracted (User Story, Description, Acceptance Criteria)
644
- - Parent feature document loaded for broader context (if available)
645
- - External codebase validated and accessible (local path or GitHub URL)
646
- - External docs loaded if provided, or context7 used if available
647
- - Output path resolved from story context
648
- - All 3 analysis phases executed directly (16 mandatory items completed)
649
- - Analysis file written with ALL template sections populated
650
- - NO assumptions made all findings backed by actual code references
651
- - Minimum metrics met: 30+ files read, 50+ code references, 5+ call depth
652
- - Mermaid sequence diagram included in the analysis
653
- - All 23 validation checklist items verified
654
- - User reviewed and approved the analysis
655
- - Document committed with appropriate message
656
- - No modifications made to the story file or GitHub issues
657
- </success_criteria>
658
-
659
- </workflow>
1
+ <workflow>
2
+
3
+ <purpose>
4
+ Perform COMPREHENSIVE, IN-DEPTH, CODE-LEVEL analysis of how a specific story
5
+ is implemented in an external reference system. Load the story requirements, validate
6
+ the external codebase, optionally load external documentation, then execute exhaustive
7
+ code analysis following the template's analysis-process phases. Write the analysis to
8
+ external-analysis.md in the story's artifact directory.
9
+
10
+ Produces `.ace/artifacts/product/<id-epic_name>/<id-feature_name>/<id-story_name>/external-analysis.md`
11
+ — a comprehensive code-level analysis with algorithms, patterns, formulas, and
12
+ implementation details extracted verbatim from the external system's code.
13
+
14
+ This is pass 3 of the story specification pipeline (see story.xml composition).
15
+ All output is written ONLY to the analysis file — no GitHub updates, no modifications
16
+ to the story file.
17
+
18
+ This workflow is executed by the `ace-code-discovery-analyst` agent
19
+ (spawned via `subagent_type="ace-code-discovery-analyst"`).
20
+ </purpose>
21
+
22
+ <mandatory-context>
23
+ All supporting resource files are auto-loaded in the skill prompt above. Do NOT re-read them.
24
+ Also read any document or text passed as parameter ($ARGUMENTS) in the invoking command.
25
+ </mandatory-context>
26
+
27
+ <process>
28
+
29
+ <!-- ══════════════════════════════════════════════════════════════════ -->
30
+ <!-- STEP 1: SETUP -->
31
+ <!-- ══════════════════════════════════════════════════════════════════ -->
32
+
33
+ <step name="setup" order="1">
34
+ **MANDATORY FIRST STEP — Execute environment detection and story initialization:**
35
+
36
+ INIT is available from the preprocessed Environment Context above — do NOT re-run init.
37
+
38
+ This preprocessing validated the story parameter, extracted metadata/requirements/wiki
39
+ references, computed all paths and slugs, and checked artifact existence.
40
+
41
+ Parse INIT JSON for:
42
+ - **Environment**: `has_git`, `has_gh_cli`, `github_project`, `analyst_model`
43
+ - **Story validation**: `story_valid`, `story_error`, `story_source`
44
+ - **Story metadata**: `story` (id, title, status, size), `feature` (id, title), `epic` (id, title)
45
+ - **Requirements**: `user_story`, `description`, `acceptance_criteria_count`
46
+ - **Paths**: `paths.*` (story_dir, story_file, external_analysis_file, feature_dir, feature_file, etc.)
47
+ - **Artifacts**: `has_external_analysis`, `has_integration_analysis`, `has_feature_file`
48
+
49
+ Display stage banner:
50
+
51
+ ```
52
+ ╔══════════════════════════════════════════════════╗
53
+ ║ ACE > Research External Solution ║
54
+ ╚══════════════════════════════════════════════════╝
55
+ ```
56
+
57
+ **If `has_git` is false:** Initialize git:
58
+ ```bash
59
+ git init
60
+ ```
61
+
62
+ **If `INIT.story_valid` is false:**
63
+ Display error using `INIT.story_error` and exit.
64
+ </step>
65
+
66
+ <!-- ══════════════════════════════════════════════════════════════════ -->
67
+ <!-- STEP 2: VALIDATE & LOAD STORY -->
68
+ <!-- ══════════════════════════════════════════════════════════════════ -->
69
+
70
+ <step name="validate-story" order="2">
71
+
72
+ **Story validation, parsing, and path computation were completed by
73
+ `init research-story` in step 1.** All metadata, requirements, and
74
+ paths are available in the INIT JSON.
75
+
76
+ Read the story file content for analysis context:
77
+
78
+ **If `INIT.story_source` is `file`:**
79
+ Read the file at `INIT.paths.story_file`. Store as STORY_CONTENT.
80
+
81
+ **If `INIT.story_source` is `github-url` or `issue-number`:**
82
+ Fetch the issue body using INIT's GitHub project context:
83
+ ```bash
84
+ GH_STORY=$(gh issue view {issue_number} --repo {INIT.github_project.owner}/{INIT.github_project.repo} --json body -q .body)
85
+ ```
86
+ Store as STORY_CONTENT.
87
+
88
+ The story's User Story, Description, and Acceptance Criteria define
89
+ WHAT functionality to analyze in the external codebase. These are the
90
+ requirements do NOT seek requirements from other sources.
91
+ Wiki references from `INIT.wiki_references` may inform exploration.
92
+
93
+ <!-- ── 2b: Read parent feature document ───────────────────────── -->
94
+
95
+ **If `INIT.has_feature_file` is true:**
96
+ Read the feature document at `INIT.paths.feature_file` and extract:
97
+ - Feature description and scope
98
+ - List of all stories in the feature (IDs, titles, descriptions)
99
+ - Dependencies between stories
100
+ - Shared components or services mentioned
101
+ This informs the "Story Integration Within Feature" section.
102
+
103
+ **If `INIT.has_feature_file` is false:**
104
+ Proceed without — the analysis can still be done without feature context.
105
+
106
+ <!-- ── 2c: Display ───────────────────────────────────────────────── -->
107
+
108
+ Set pre-computed paths from INIT:
109
+ - `STORY_FILE = INIT.paths.story_file`
110
+ - `STORY_DIR = INIT.paths.story_dir`
111
+
112
+ Display:
113
+ ```
114
+ i Story loaded: {INIT.story.id} — {INIT.story.title}
115
+ Feature: {INIT.feature.id} — {INIT.feature.title}
116
+ Epic: {INIT.epic.id} — {INIT.epic.title}
117
+ Requirements: {INIT.acceptance_criteria_count} acceptance criteria scenarios
118
+ ```
119
+ </step>
120
+
121
+ <!-- ══════════════════════════════════════════════════════════════════ -->
122
+ <!-- STEP 3: VALIDATE EXTERNAL CODEBASE -->
123
+ <!-- ══════════════════════════════════════════════════════════════════ -->
124
+
125
+ <step name="validate-external-codebase" order="3">
126
+
127
+ Parse the `external-codebase` parameter from $ARGUMENTS.
128
+
129
+ <!-- ── 3a: Local path ────────────────────────────────────────────── -->
130
+
131
+ **If local path:**
132
+
133
+ Confirm folder exists and contains source code:
134
+ ```bash
135
+ ls {external_codebase_path}/
136
+ ```
137
+
138
+ **If not valid:** Display error and exit:
139
+ ```
140
+ x External codebase not found: {external_codebase_path}
141
+ Provide a valid local path to a source code directory
142
+ or a GitHub repository URL.
143
+ ```
144
+
145
+ Set `EXTERNAL_CODEBASE_PATH = {external_codebase_path}`
146
+
147
+ <!-- ── 3b: GitHub URL ────────────────────────────────────────────── -->
148
+
149
+ **If GitHub URL:**
150
+
151
+ Verify repository accessibility:
152
+ ```bash
153
+ gh repo view {repo_identifier} --json name,url 2>/dev/null
154
+ ```
155
+
156
+ **If not accessible:** Display error and exit:
157
+ ```
158
+ x External repository not accessible: {repo_url}
159
+ Verify the URL is correct and the repository is public
160
+ or you have access.
161
+ ```
162
+
163
+ Set `EXTERNAL_CODEBASE_PATH = {resolved path or URL}`
164
+
165
+ <!-- ── 3c: Display ───────────────────────────────────────────────── -->
166
+
167
+ Display:
168
+ ```
169
+ i External codebase: {EXTERNAL_CODEBASE_PATH}
170
+ ```
171
+ </step>
172
+
173
+ <!-- ══════════════════════════════════════════════════════════════════ -->
174
+ <!-- STEP 4: LOAD EXTERNAL DOCS (OPTIONAL) -->
175
+ <!-- ══════════════════════════════════════════════════════════════════ -->
176
+
177
+ <step name="load-external-docs" order="4">
178
+
179
+ Parse the `external-docs` parameter from $ARGUMENTS.
180
+
181
+ <!-- ── 4a: Not provided ──────────────────────────────────────────── -->
182
+
183
+ **If not provided:**
184
+
185
+ Check if context7 MCP server is available (check if `mcp__context7__resolve-library-id`
186
+ or similar context7 tools are available in the current tool set).
187
+
188
+ **If context7 available:**
189
+ Set `USE_CONTEXT7 = true`
190
+ Display:
191
+ ```
192
+ i No external docs provided.
193
+ context7 MCP server detected — will use it for library documentation.
194
+ ```
195
+
196
+ **If context7 not available:**
197
+ Set `USE_CONTEXT7 = false`
198
+ Display:
199
+ ```
200
+ i No external docs provided. Analysis will rely on code exploration.
201
+ TIP: Provide external-docs= for richer analysis,
202
+ or install context7 MCP server for automatic library docs.
203
+ ```
204
+
205
+ <!-- ── 4b: Provided as weblink ───────────────────────────────────── -->
206
+
207
+ **If provided as weblink:**
208
+
209
+ Verify URL accessibility (attempt a fetch or HEAD request).
210
+
211
+ **If not accessible:** Display warning (non-fatal):
212
+ ```
213
+ ! External docs URL not accessible: {url}
214
+ Continuing without external docs.
215
+ ```
216
+
217
+ **If accessible:**
218
+ Store as `EXTERNAL_DOCS_URL = {url}`
219
+ Display:
220
+ ```
221
+ i External docs: {url}
222
+ ```
223
+
224
+ <!-- ── 4c: Provided as filepath ──────────────────────────────────── -->
225
+
226
+ **If provided as filepath:**
227
+
228
+ Verify file exists:
229
+ ```bash
230
+ DOCS_EXISTS=$(node "${CLAUDE_SKILL_DIR}/script.js" verify-path-exists {filepath} --raw)
231
+ ```
232
+
233
+ **If not exists:** Display warning (non-fatal):
234
+ ```
235
+ ! External docs file not found: {filepath}
236
+ Continuing without external docs.
237
+ ```
238
+
239
+ **If exists:** Read the file. Store as `EXTERNAL_DOCS_CONTENT`.
240
+ Display:
241
+ ```
242
+ i External docs: {filepath}
243
+ ```
244
+ </step>
245
+
246
+ <!-- ══════════════════════════════════════════════════════════════════ -->
247
+ <!-- STEP 5: RESOLVE OUTPUT PATH -->
248
+ <!-- ══════════════════════════════════════════════════════════════════ -->
249
+
250
+ <step name="resolve-output-path" order="5">
251
+
252
+ **Paths were pre-computed by `init research-story` in step 1.**
253
+
254
+ Set from INIT JSON:
255
+ - `STORY_DIR = INIT.paths.story_dir`
256
+ - `OUTPUT_FILE = INIT.paths.external_analysis_file`
257
+
258
+ Ensure directory exists:
259
+ ```bash
260
+ mkdir -p {STORY_DIR}
261
+ ```
262
+
263
+ Display:
264
+ ```
265
+ i Output: {OUTPUT_FILE}
266
+ ```
267
+ </step>
268
+
269
+ <!-- ══════════════════════════════════════════════════════════════════ -->
270
+ <!-- STEP 6: CHECK EXISTING ANALYSIS -->
271
+ <!-- ══════════════════════════════════════════════════════════════════ -->
272
+
273
+ <step name="check-existing" order="6">
274
+
275
+ **If `INIT.has_external_analysis` is true:**
276
+
277
+ Use AskUserQuestion:
278
+ - header: "Existing"
279
+ - question: "An external analysis already exists at `{OUTPUT_FILE}`. What would you like to do?"
280
+ - options:
281
+ - "Overwrite" Discard and create a new analysis from scratch
282
+ - "Skip" — Keep the current analysis as-is
283
+
284
+ **If "Overwrite":** Continue to step 7.
285
+ **If "Skip":** Display message and exit workflow:
286
+ ```
287
+ i Keeping existing analysis. No changes made.
288
+ ```
289
+
290
+ **If not exists:** Continue to step 7.
291
+ </step>
292
+
293
+ <!-- ══════════════════════════════════════════════════════════════════ -->
294
+ <!-- STEP 7: EXECUTE ANALYSIS -->
295
+ <!-- ══════════════════════════════════════════════════════════════════ -->
296
+
297
+ <step name="execute-analysis" order="7">
298
+
299
+ Display:
300
+ ```
301
+ ┌──────────────────────────────────────────────────┐
302
+ │ ACE > Research External Solution > Analysis │
303
+ └──────────────────────────────────────────────────┘
304
+
305
+ i Starting deep code-level analysis.
306
+ Reading 30+ files and tracing execution paths
307
+ 5+ levels deep. This may take several minutes.
308
+ ```
309
+
310
+ **Execute the complete analysis following the template's `<analysis-process>` section.**
311
+ The template (`external-solution.xml`) defines 3 mandatory phases with 16 total items.
312
+ You ARE the code-discovery-analyst perform the analysis directly.
313
+
314
+ <!-- ── 7a: Phase 1 Initial Discovery (3 mandatory items) ───────── -->
315
+
316
+ **Phase 1: Initial Discovery**
317
+
318
+ 1. **[MANDATORY] Understand the story requirements:**
319
+ - Re-read STORY_CONTENT thoroughly — User Story, Description, all AC scenarios
320
+ - These define WHAT functionality to analyze in the external codebase
321
+ - Extract the key behaviors, algorithms, and patterns to look for
322
+ - If parent feature document was loaded (step 2c), understand:
323
+ - The broader feature context
324
+ - What other stories exist and how they relate
325
+ - Dependencies and shared components between stories
326
+
327
+ 2. **[MANDATORY] Explore available documentation:**
328
+ - **external-docs** (if EXTERNAL_DOCS_URL or EXTERNAL_DOCS_CONTENT set):
329
+ Review for implementation context, API documentation, architecture overview.
330
+ If URL: use WebFetch to retrieve content.
331
+ Use documentation to guide code exploration.
332
+ - **context7 MCP server** (if USE_CONTEXT7 is true — PREFERRED):
333
+ Use `mcp__context7__resolve-library-id` to find the library,
334
+ then `mcp__context7__get-library-docs` to fetch relevant docs.
335
+ **ALWAYS prefer context7** when the external system is a known library/framework.
336
+ - If neither available: rely entirely on code exploration.
337
+
338
+ 3. **[MANDATORY] Locate the implementation:**
339
+ - Find where the story's functionality is implemented in `EXTERNAL_CODEBASE_PATH`
340
+ - Start with likely entry points: exports, public APIs, event handlers
341
+ - Use Grep/Glob to find relevant files by keywords from the story
342
+ - Read README files and documentation in the external codebase for structural guidance
343
+ - Build an initial map of involved files before deep diving
344
+
345
+ <!-- ── 7b: Phase 2 Deep Implementation Analysis (9 mandatory items) ── -->
346
+
347
+ **Phase 2: Deep Implementation Analysis — ALL 9 items MANDATORY, skip NONE:**
348
+
349
+ 1. **[MANDATORY] Complete Entry Points & Triggers Identification (CRITICAL):**
350
+ Document ALL entry points into the story functionality:
351
+ - **User Action Triggers**: button clicks, form submissions, keyboard shortcuts
352
+ - **API Entry Points**: REST endpoints, GraphQL mutations, RPC calls
353
+ - **Event-Based Triggers**: WebSocket messages, system events, pub/sub messages
354
+ - **Scheduled/Automated Triggers**: cron jobs, timers, intervals
355
+ - **External System Triggers**: webhooks, callbacks, integrations
356
+ For EACH entry point document:
357
+ ```typescript
358
+ // Entry Point Type: [User Action/API/Event/etc.]
359
+ // File: src/path/file.ts:45-60
360
+ // Trigger: [Exact trigger description]
361
+ // Parameters: [List all parameters with types]
362
+ // Example usage: [Show actual usage example]
363
+ ```
364
+
365
+ 2. **[MANDATORY] Complete Code Path Mapping:**
366
+ - Follow EVERY code path from entry to completion
367
+ - Include ALL branches, conditionals, and edge cases
368
+ - Document every file, class, method, and function involved
369
+ - Track all data transformations and state changes
370
+ - Minimum call depth: 5+ levels
371
+
372
+ 3. **[MANDATORY] Story-Specific File Tree:**
373
+ - Document ONLY files involved in this story (NOT entire codebase)
374
+ - Categorize as: CORE, SUPPORT, CONFIG, TEST
375
+ - Include line counts and one-line purpose for each file
376
+ - Include total file count and line count at bottom
377
+
378
+ 4. **[MANDATORY] Constants & Configuration Extraction:**
379
+ - Extract ALL constants and configuration values used by the story
380
+ - Include ACTUAL values from code, NOT placeholders
381
+ - Group by category: performance limits, business thresholds, magic numbers
382
+ - Always include source file path and line numbers
383
+
384
+ 5. **[MANDATORY] Algorithm & Formula Documentation:**
385
+ For each calculation or algorithm found:
386
+ - **Purpose**: What it calculates/achieves
387
+ - **Formula**: Exact mathematical formula or logic
388
+ - **Implementation**: Code snippet showing implementation
389
+ - **Example**: Sample input/output with explanation
390
+ - **Edge Cases**: How they handle special cases
391
+
392
+ 6. **[MANDATORY] Comprehensive Flow Diagram:**
393
+ Create a detailed Mermaid sequence diagram showing:
394
+ - Complete execution flow with ALL branches
395
+ - Actual method names and parameters (NOT generic names)
396
+ - Data flow between components
397
+ - State changes and side effects
398
+ - Error handling paths
399
+
400
+ 7. **[MANDATORY] Test Patterns Extraction:**
401
+ - Extract actual test cases from the external system
402
+ - Include test code snippets with assertions
403
+ - Document test scenarios covered
404
+ - Note edge cases tested
405
+ - Extract test data patterns
406
+ - Identify mocking strategies used
407
+
408
+ 8. **[MANDATORY] Performance Considerations:**
409
+ - Caching strategies used
410
+ - Algorithm optimizations
411
+ - Throttling/debouncing patterns
412
+ - Memory management techniques
413
+ - Batch processing approaches
414
+ Include code references for each optimization.
415
+
416
+ 9. **[MANDATORY] Validation & Security:**
417
+ - Input validation rules with actual validation code
418
+ - Data sanitization methods
419
+ - Security checks implemented
420
+ - Error boundaries
421
+ Include actual code snippets showing validation logic.
422
+
423
+ <!-- ── 7c: Phase 3 Pattern & Architecture Analysis (4 mandatory items) ── -->
424
+
425
+ **Phase 3: Pattern & Architecture Analysis — ALL 4 items MANDATORY:**
426
+
427
+ 1. **[MANDATORY] Design Patterns Identified:**
428
+ - Document all design patterns used (Strategy, Observer, Factory, etc.)
429
+ - Explain WHY they chose each pattern
430
+ - Include code examples of pattern implementation
431
+ - Note patterns shared with other parts of the system
432
+ - Identify if patterns enable component integration/communication
433
+
434
+ 2. **[MANDATORY] Component Lifecycle:**
435
+ - Initialization sequence
436
+ - State management approach
437
+ - Cleanup/disposal mechanisms
438
+ - Memory management considerations
439
+
440
+ 3. **[MANDATORY] Performance Optimizations:**
441
+ - Caching strategies
442
+ - Algorithm optimizations
443
+ - Rendering optimizations (if applicable)
444
+ - Data structure choices for performance
445
+
446
+ 4. **[MANDATORY] Error Handling & Edge Cases:**
447
+ - How they handle errors at each architectural level
448
+ - Validation approaches
449
+ - Fallback mechanisms
450
+ - Boundary conditions
451
+
452
+ **CRITICAL REQUIREMENTS:**
453
+ - **NO ASSUMPTIONS**: Only document what you actually find in the code
454
+ - **STORY SCOPE ONLY**: Focus exclusively on code paths related to the story
455
+ - **COMPLETE COVERAGE**: Every file and method involved must be documented
456
+ - **EXACT IMPLEMENTATIONS**: Include actual code snippets, not descriptions
457
+ - **FORMULAS & CALCULATIONS**: Extract and explain ALL mathematical operations
458
+ - **METRICS**: Minimum 30+ files read, 50+ code references, 5+ call depth
459
+ </step>
460
+
461
+ <!-- ══════════════════════════════════════════════════════════════════ -->
462
+ <!-- STEP 8: WRITE OUTPUT -->
463
+ <!-- ══════════════════════════════════════════════════════════════════ -->
464
+
465
+ <step name="write-output" order="8">
466
+
467
+ Write the complete analysis to `{OUTPUT_FILE}` following the template's
468
+ `<output-format>` section exactly. Include ALL sections:
469
+
470
+ 1. Header (repository, version, story, date, metrics)
471
+ 2. Implementation Overview
472
+ 3. Entry Points & Triggers (categorized by type)
473
+ 4. Story-Specific File Tree
474
+ 5. Constants & Configuration
475
+ 6. Core Implementation (Algorithms, Data Flow with Mermaid diagram, Key Components)
476
+ 7. Code Examples
477
+ 8. Test Patterns
478
+ 9. Validation & Security
479
+ 10. Performance Optimizations
480
+ 11. Architecture Decisions (Design Patterns, Lifecycle, Error Handling)
481
+ 12. Story Integration Within Feature
482
+ 13. Lessons for Our Implementation
483
+ 14. Complete File Reference
484
+
485
+ Use the Write tool to create the file. Include all findings from step 7.
486
+
487
+ This is NOT a summary it is a COMPLETE CODE EXTRACTION. Every section
488
+ must contain actual code snippets, file paths with line numbers, and
489
+ concrete implementation details.
490
+
491
+ Display:
492
+ ```
493
+ + Analysis written to {OUTPUT_FILE}
494
+ ```
495
+ </step>
496
+
497
+ <!-- ══════════════════════════════════════════════════════════════════ -->
498
+ <!-- STEP 9: VALIDATION -->
499
+ <!-- ══════════════════════════════════════════════════════════════════ -->
500
+
501
+ <step name="validation" order="9">
502
+
503
+ Read the output file and verify against the validation checklist
504
+ defined in the template (external-solution.xml):
505
+
506
+ **File Creation Requirements:**
507
+ - [ ] Analysis file created at {OUTPUT_FILE}
508
+ - [ ] Story directory exists
509
+ - [ ] File contains all required sections from template
510
+
511
+ **Content Requirements Core Analysis:**
512
+ - [ ] CRITICAL: No assumptions — analysis reflects 100% accurate code, no guessing
513
+ - [ ] Complete Entry Points & Triggers section with ALL trigger types
514
+ - [ ] Story-Specific File Tree showing ONLY files involved in story
515
+ - [ ] Constants & Configuration section with actual values
516
+ - [ ] Mermaid sequence diagram showing complete data flow
517
+ - [ ] All algorithms and formulas extracted with explanations
518
+ - [ ] Code examples included from external implementation
519
+ - [ ] Architecture patterns identified and documented
520
+
521
+ **Content Requirements Enhanced Sections:**
522
+ - [ ] Test Patterns section with actual test code
523
+ - [ ] Validation & Security section with validation rules
524
+ - [ ] Performance Optimizations documented
525
+ - [ ] Story Integration Within Feature section completed
526
+ - [ ] Complete File Reference with file roles
527
+
528
+ **Analysis Quality Requirements:**
529
+ - [ ] All entry points categorized (User/API/Event/External)
530
+ - [ ] Complete code path mapping documented (5+ levels deep)
531
+ - [ ] Error handling approaches analyzed
532
+ - [ ] No assumptions made only documented what was found in code
533
+ - [ ] Lessons for our implementation clearly stated
534
+
535
+ **Metrics Requirements:**
536
+ - [ ] Minimum 30+ files read for the story
537
+ - [ ] Minimum 50+ code references documented
538
+ - [ ] Minimum 5+ call depth traced
539
+ - [ ] All metrics reported in output header
540
+
541
+ **Total: 23 mandatory checklist items**
542
+
543
+ If the output is incomplete or missing sections, go back and fill in
544
+ the missing content before proceeding.
545
+
546
+ Display:
547
+ ```
548
+ {check_mark} Analysis validated. {passed}/{total} checks passed.
549
+ ```
550
+ </step>
551
+
552
+ <!-- ══════════════════════════════════════════════════════════════════ -->
553
+ <!-- STEP 10: REVIEW AND APPROVE -->
554
+ <!-- ══════════════════════════════════════════════════════════════════ -->
555
+
556
+ <step name="review" order="10">
557
+
558
+ Display a summary of the analysis:
559
+ ```
560
+ Analysis Summary:
561
+ ────────
562
+ Files analyzed: {N} | Code references: {M} | Call depth: {D}
563
+ Sections: {count}/14 | Checklist: {passed}/23
564
+ ```
565
+
566
+ Use AskUserQuestion:
567
+ - header: "Analysis"
568
+ - question: "External analysis written to `{OUTPUT_FILE}`. Review the file in your editor — does the analysis look comprehensive?"
569
+ - options:
570
+ - "Approve"Looks good, commit it
571
+ - "Refine" — Some sections need more depth
572
+ - "Skip commit" — Keep the file but don't commit yet
573
+
574
+ **If "Approve":**
575
+ Continue to step 11.
576
+
577
+ **If "Refine":**
578
+ - Ask what sections need more depth or what's missing
579
+ - Go back to the relevant analysis phase, read more code, and update OUTPUT_FILE
580
+ - Re-run validation (step 9)
581
+ - Present for review again
582
+
583
+ **If "Skip commit":**
584
+ Display completion without commit:
585
+ ```
586
+ ╔══════════════════════════════════════════════════╗
587
+ ║ ACE > External Analysis Complete (uncommitted) ║
588
+ ║ {Story ID} "{Story Title}" ║
589
+ ╚══════════════════════════════════════════════════╝
590
+
591
+ i Analysis written to {OUTPUT_FILE}
592
+ File not committed — commit manually when ready.
593
+ ```
594
+ Exit workflow.
595
+ </step>
596
+
597
+ <!-- ══════════════════════════════════════════════════════════════════ -->
598
+ <!-- STEP 11: COMMIT -->
599
+ <!-- ══════════════════════════════════════════════════════════════════ -->
600
+
601
+ <step name="commit" order="11">
602
+
603
+ Stage and commit the analysis file:
604
+
605
+ ```bash
606
+ git add {OUTPUT_FILE}
607
+ ```
608
+
609
+ ```bash
610
+ git commit -m "docs: external analysis for {Story ID} — {Story Title}"
611
+ ```
612
+
613
+ Display completion:
614
+
615
+ ```
616
+ ╔══════════════════════════════════════════════════╗
617
+ ║ ACE > External Analysis Complete ║
618
+ ║ {Story ID} "{Story Title}" ║
619
+ ╚══════════════════════════════════════════════════╝
620
+
621
+ + {OUTPUT_FILE} committed.
622
+
623
+ Metrics:
624
+ ────────
625
+ Files analyzed: {N} | Code references: {M} | Call depth: {D}
626
+
627
+ i External analysis complete. This artifact will be consumed
628
+ by the technical solution (pass 5) when running plan-story.
629
+
630
+ Next > Continue with story refinement:
631
+ - Integration analysis (pass 4)
632
+ - Technical solution (pass 5)
633
+ > /ace:research-external-solution story=... external-codebase=...
634
+ Analyze another story's external implementation.
635
+ ```
636
+ </step>
637
+
638
+ </process>
639
+
640
+ <success_criteria>
641
+ - Story loaded and requirements extracted (User Story, Description, Acceptance Criteria)
642
+ - Parent feature document loaded for broader context (if available)
643
+ - External codebase validated and accessible (local path or GitHub URL)
644
+ - External docs loaded if provided, or context7 used if available
645
+ - Output path resolved from story context
646
+ - All 3 analysis phases executed directly (16 mandatory items completed)
647
+ - Analysis file written with ALL template sections populated
648
+ - NO assumptions made all findings backed by actual code references
649
+ - Minimum metrics met: 30+ files read, 50+ code references, 5+ call depth
650
+ - Mermaid sequence diagram included in the analysis
651
+ - All 23 validation checklist items verified
652
+ - User reviewed and approved the analysis
653
+ - Document committed with appropriate message
654
+ - No modifications made to the story file or GitHub issues
655
+ </success_criteria>
656
+
657
+ </workflow>