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,832 +1,832 @@
1
- <external-solution>
2
-
3
- <purpose>
4
- Template for `.ace/artifacts/product/&lt;id-epic_name&gt;/&lt;id-feature_name&gt;/&lt;id-story_name&gt;/external-analysis.md` —
5
- a COMPREHENSIVE, IN-DEPTH, CODE-LEVEL analysis of how a specific story's functionality
6
- is implemented in an external reference system (industry-standard codebase).
7
-
8
- This is pass 3 of the story specification pipeline (see story.xml composition).
9
- It produces a separate artifact in the story directory — NOT appended to the story file.
10
- The analysis is consumed by pass 5 (technical solution) as input for designing
11
- our own implementation.
12
-
13
- This is NOT a high-level overview. It is a DEEP DIVE into:
14
- - EXACT code implementations with line-by-line analysis
15
- - COMPLETE algorithms and formulas extracted verbatim from code
16
- - ALL design patterns with actual code examples
17
- - EVERY file, function, and constant involved in the story
18
- - FULL execution paths traced 5+ levels deep minimum
19
-
20
- The analysis ensures our implementation:
21
- - Follows established patterns and best practices (with code proof)
22
- - Uses exact algorithms and formulas (copied from their code)
23
- - Maintains compatibility with industry standards (matching their APIs)
24
-
25
- This document does NOT modify the story file. It lives as a separate artifact
26
- in the story directory. Only the technical solution (pass 5) consumes it.
27
- </purpose>
28
-
29
- <output-format>
30
-
31
- <section name="header">
32
- # External Implementation Analysis: [Story Name]
33
-
34
- ## Repository Analyzed
35
- - **Source**: [Repository name/URL]
36
- - **Version/Commit**: [Specific version or commit hash analyzed]
37
- - **Story/Use Case**: [Description of story functionality analyzed]
38
- - **Analysis Date**: [Current date]
39
- - **Metrics**: Files read: [X] | Code references: [Y] | Call depth: [Z]
40
- </section>
41
-
42
- <section name="implementation-overview">
43
- ## Implementation Overview
44
-
45
- [COMPREHENSIVE, DETAILED analysis of EXACTLY how the external system implements
46
- this story's functionality. Describe the overall approach, architecture, and
47
- key implementation decisions. This is a holistic view of the implementation
48
- with complete code paths.
49
-
50
- This is NOT a summary — it is a complete technical description of the
51
- implementation approach, covering how the components work together to
52
- deliver the functionality described in the story's acceptance criteria.]
53
- </section>
54
-
55
- <section name="entry-points">
56
- ## Entry Points &amp; Triggers
57
-
58
- &lt;!-- Document ALL entry points into the story functionality.
59
- For EACH entry point include:
60
- - Entry Point Type: [User Action/API/Event/Scheduled/External]
61
- - File: src/path/file.ts:line-range
62
- - Trigger: exact trigger description
63
- - Parameters: list all parameters with types
64
- - Example usage: show actual usage example from the code
65
-
66
- Format each entry point as:
67
- ```typescript
68
- // Entry Point Type: [User Action/API/Event/etc.]
69
- // File: src/path/file.ts:45-60
70
- // Trigger: [Exact trigger description]
71
- // Parameters: [List all parameters with types]
72
- // Example usage: [Show actual usage example]
73
- ```
74
-
75
- Omit any category that has no entry points for this story. --&gt;
76
-
77
- ### User Action Triggers
78
- [Button clicks, form submissions, keyboard shortcuts — with code references and line numbers]
79
-
80
- ### API Entry Points
81
- [REST endpoints, GraphQL mutations, RPC calls — with code references and line numbers]
82
-
83
- ### Event-Based Triggers
84
- [WebSocket messages, system events, pub/sub messages — with code references and line numbers]
85
-
86
- ### Scheduled / Automated Triggers
87
- [Cron jobs, timers, intervals — with code references and line numbers]
88
-
89
- ### External System Triggers
90
- [Webhooks, callbacks, integrations — with code references and line numbers]
91
- </section>
92
-
93
- <section name="file-tree">
94
- ## Story-Specific File Tree
95
-
96
- &lt;!-- Document ONLY files involved in this story. NOT the entire codebase.
97
- Categorize files by role: CORE, SUPPORT, CONFIG, TEST.
98
- Include file size (line count) and one-line purpose.
99
-
100
- Example:
101
- ```
102
- chart-container/
103
- ├── entry-points/ [CORE]
104
- │ ├── ChartWidget.ts (150 lines) - User interaction entry point
105
- │ └── ChartAPI.ts (200 lines) - Public API entry point
106
- ├── core-logic/ [CORE]
107
- │ ├── ChartModel.ts (300 lines) - Chart state management
108
- │ └── LayoutManager.ts (250 lines) - Layout calculations
109
- ├── models/ [SUPPORT]
110
- │ └── ChartOptions.ts (100 lines) - Configuration types
111
- ├── utilities/ [SUPPORT]
112
- │ └── SizeHelpers.ts (80 lines) - Size calculation helpers
113
- ├── config/ [CONFIG]
114
- │ └── Defaults.ts (50 lines) - Default configuration
115
- └── tests/ [TEST]
116
- ├── chart.test.ts (200 lines) - Unit tests
117
- └── chart.integration.test.ts (150 lines) - Integration tests
118
-
119
- Total: X files, Y lines of code specific to this story
120
- ``` --&gt;
121
-
122
- ```
123
- [story-specific file tree here]
124
- ```
125
- </section>
126
-
127
- <section name="constants">
128
- ## Constants &amp; Configuration
129
-
130
- &lt;!-- Extract ALL constants and configuration values used by the story.
131
- Include actual values from code, NOT placeholders.
132
- Group by category: performance limits, business thresholds, magic numbers.
133
- Always include the source file path and line numbers.
134
-
135
- Example:
136
- ```typescript
137
- // From src/config/defaults.ts:10-50
138
- export const CHART_DEFAULTS = {
139
- // Performance limits
140
- MAX_BARS: 10000,
141
- BATCH_SIZE: 100,
142
- THROTTLE_MS: 16,
143
-
144
- // Rendering thresholds
145
- MIN_PIXEL_RATIO: 1,
146
- MAX_PIXEL_RATIO: 4,
147
-
148
- // Sizing constants
149
- DEFAULT_WIDTH: 600,
150
- DEFAULT_HEIGHT: 300
151
- };
152
- ``` --&gt;
153
-
154
- ```typescript
155
- // From [file:line-range]
156
- [Actual constants extracted from external codebase]
157
- ```
158
- </section>
159
-
160
- <section name="core-implementation">
161
- ## Core Implementation
162
-
163
- ### Algorithms &amp; Calculations
164
-
165
- &lt;!-- For EACH algorithm or calculation found, document:
166
- - Purpose: What it calculates/achieves
167
- - Formula: Exact mathematical formula or logic
168
- - Implementation: Code snippet showing implementation
169
- - Example: Sample input/output with explanation
170
- - Edge Cases: How they handle special cases --&gt;
171
-
172
- #### [Algorithm/Formula Name]
173
-
174
- **Purpose**: [What it calculates/achieves]
175
-
176
- **Formula**:
177
- ```
178
- [Exact mathematical formula or logical expression]
179
- ```
180
-
181
- **Implementation**:
182
- ```typescript
183
- // From src/path/file.ts:line-range
184
- [Actual code extracted from their implementation with inline comments]
185
- ```
186
-
187
- **Example**:
188
- - Input: [sample input values]
189
- - Output: [expected output]
190
- - Explanation: [how the algorithm produces this result]
191
-
192
- **Edge Cases**:
193
- - [How they handle edge case 1]
194
- - [How they handle edge case 2]
195
-
196
- &lt;!-- Repeat for each algorithm/calculation found --&gt;
197
-
198
- ### Data Flow
199
-
200
- &lt;!-- MANDATORY Mermaid sequence diagram showing:
201
- - Complete execution flow with ALL branches
202
- - Actual method names and parameters
203
- - Data flow between components
204
- - State changes and side effects
205
- - Error handling paths
206
-
207
- The diagram must use ACTUAL method names from the code,
208
- not generic placeholders. --&gt;
209
-
210
- ```mermaid
211
- sequenceDiagram
212
- participant User
213
- participant Controller
214
- participant Service
215
- participant DataStore
216
-
217
- User->>Controller: triggerAction(params)
218
- Controller->>Service: processRequest(data)
219
- Service->>DataStore: query(criteria)
220
- DataStore-->>Service: results
221
- Service-->>Controller: processedData
222
- Controller-->>User: response
223
- ```
224
-
225
- ### Key Components
226
-
227
- &lt;!-- Detailed breakdown of each component involved in the story.
228
- For each component include:
229
- - File path with line range
230
- - Purpose (what this component does in the story)
231
- - Public API (methods/properties exposed)
232
- - Internal Logic (key implementation details)
233
- - Dependencies (other components it depends on) --&gt;
234
-
235
- #### [Component Name]
236
-
237
- - **File**: [path:line-range]
238
- - **Purpose**: [what this component does in the context of this story]
239
- - **Public API**:
240
- - `methodName(params): returnType` — [description]
241
- - **Internal Logic**: [key implementation details with code references]
242
- - **Dependencies**: [other components it depends on]
243
- </section>
244
-
245
- <section name="code-examples">
246
- ## Code Examples
247
-
248
- &lt;!-- Actual code extracted from external implementation.
249
- Include inline comments explaining the logic.
250
- Group by algorithm/feature/component.
251
- Always include source file path and line numbers. --&gt;
252
-
253
- ### [Algorithm/Feature Name]
254
-
255
- ```typescript
256
- // From src/path/file.ts:line-range
257
- // [Explanation of what this code does and why]
258
- [Actual code from external implementation]
259
- ```
260
-
261
- &lt;!-- Repeat for each significant code example --&gt;
262
- </section>
263
-
264
- <section name="test-patterns">
265
- ## Test Patterns
266
-
267
- &lt;!-- Extract test cases from the external system.
268
- Include actual test code with assertions.
269
- Document test scenarios, edge cases, mocking strategies.
270
-
271
- Example:
272
- ```typescript
273
- // From tests/chart.test.ts:50-80
274
- describe('ChartContainer', () => {
275
- it('should initialize with default dimensions', () => {
276
- const chart = createChart(container);
277
- expect(chart.width()).toBe(DEFAULT_WIDTH);
278
- expect(chart.height()).toBe(DEFAULT_HEIGHT);
279
- });
280
-
281
- it('should handle resize events', () => {
282
- const chart = createChart(container);
283
- chart.resize(800, 600);
284
- expect(chart.width()).toBe(800);
285
- });
286
- });
287
- ``` --&gt;
288
-
289
- ```typescript
290
- // From [test file:line-range]
291
- [Actual test code from external system]
292
- ```
293
-
294
- ### Test Scenarios Covered
295
- - [Scenario 1 — what it tests and why]
296
- - [Scenario 2 — what it tests and why]
297
-
298
- ### Edge Cases Tested
299
- - [Edge case 1 — how it's tested]
300
-
301
- ### Mocking Strategies
302
- - [What they mock and how — with code examples if notable]
303
- </section>
304
-
305
- <section name="validation-security">
306
- ## Validation &amp; Security
307
-
308
- &lt;!-- Extract validation and security measures.
309
- Include actual validation code with rules.
310
-
311
- Example:
312
- ```typescript
313
- // From src/validators/options.ts:20-45
314
- function validateOptions(options: ChartOptions): void {
315
- if (options.width <= 0) {
316
- throw new Error('Width must be positive');
317
- }
318
- if (options.height <= 0) {
319
- throw new Error('Height must be positive');
320
- }
321
- }
322
- ``` --&gt;
323
-
324
- ```typescript
325
- // From [file:line-range]
326
- [Actual validation/security code from external system]
327
- ```
328
-
329
- ### Input Validation Rules
330
- - [Rule 1 — what is validated, how, and error behavior]
331
- - [Rule 2 — what is validated, how, and error behavior]
332
-
333
- ### Security Measures
334
- - [Measure 1 — what security check is performed]
335
-
336
- ### Error Handling Patterns
337
- - [Pattern 1 — how errors are caught, propagated, and displayed]
338
- </section>
339
-
340
- <section name="performance">
341
- ## Performance Optimizations
342
-
343
- &lt;!-- Document specific optimizations found in the code.
344
- Include code references for each optimization. --&gt;
345
-
346
- ### Caching Strategies
347
- - [What is cached, how, when invalidated — with code references]
348
-
349
- ### Algorithm Optimizations
350
- - [Optimization 1 — what it does, why, with code reference]
351
-
352
- ### Resource Management
353
- - [How they manage memory, connections, handles — with code references]
354
-
355
- ### Throttling / Debouncing
356
- - [Patterns used for rate limiting — with code references]
357
-
358
- ### Batch Processing
359
- - [How they handle bulk operations — with code references]
360
- </section>
361
-
362
- <section name="architecture-decisions">
363
- ## Architecture Decisions
364
-
365
- &lt;!-- Why they made specific architectural choices for this story's functionality.
366
- Each decision should include code examples showing the pattern. --&gt;
367
-
368
- ### Design Patterns Identified
369
-
370
- &lt;!-- Document all design patterns used (Strategy, Observer, Factory, etc.)
371
- For EACH pattern:
372
- - Where it's used (file/component)
373
- - Why they chose it
374
- - Code example showing the pattern implementation
375
- - Whether it's shared with other parts of the system --&gt;
376
-
377
- #### [Pattern Name]
378
- - **Where**: [File/component where pattern is used]
379
- - **Why**: [Why this pattern was chosen for this functionality]
380
- - **Implementation**:
381
- ```typescript
382
- // From [file:line-range]
383
- [Code example showing the pattern]
384
- ```
385
- - **Shared**: [Whether other components also use this pattern]
386
-
387
- ### Component Lifecycle
388
- - **Initialization**: [sequence — with code references]
389
- - **State Management**: [approach — with code references]
390
- - **Cleanup/Disposal**: [mechanisms — with code references]
391
- - **Memory Management**: [considerations — with code references]
392
-
393
- ### Error Handling &amp; Edge Cases
394
- - [How they handle errors at each architectural level]
395
- - [Validation approaches with code references]
396
- - [Fallback mechanisms]
397
- - [Boundary conditions and how they're handled]
398
- </section>
399
-
400
- <section name="story-integration">
401
- ## Story Integration Within Feature
402
-
403
- &lt;!-- How this story's functionality relates to other stories in the feature.
404
- This section helps understand boundaries and integration points. --&gt;
405
-
406
- ### Dependencies on Other Stories
407
- &lt;!-- List stories this depends on and what it needs from them.
408
- Based on both the external system analysis and the parent feature document. --&gt;
409
- - [Story ID — what this story needs from it]
410
-
411
- ### Provided to Other Stories
412
- &lt;!-- List what this story provides that other stories consume. --&gt;
413
- - [Story ID — what this story provides to it]
414
-
415
- ### Shared Components
416
- &lt;!-- Components/services used across multiple stories in the feature. --&gt;
417
- - [Component — which stories share it and how]
418
-
419
- ### Integration Points
420
- &lt;!-- How this story connects with other stories in the feature.
421
- APIs, events, data flows, shared state. --&gt;
422
- - [Integration point — how stories communicate]
423
- </section>
424
-
425
- <section name="lessons">
426
- ## Lessons for Our Implementation
427
-
428
- &lt;!-- Key takeaways specific to implementing this story.
429
- This is the most actionable section — it directly guides our implementation.
430
-
431
- Cover:
432
- - How to ensure compatibility with other stories in the feature
433
- - Shared patterns to maintain consistency across stories
434
- - Integration considerations for feature completeness
435
- - Algorithms and formulas to reuse
436
- - Pitfalls to avoid based on the external system's approach
437
- - Performance strategies worth adopting --&gt;
438
-
439
- - [Key insight 1 — how it impacts our design]
440
- - [Key insight 2 — algorithms to use or adapt]
441
- - [Key insight 3 — patterns to follow]
442
- - [Key insight 4 — compatibility considerations]
443
- - [Key insight 5 — performance strategies to adopt]
444
- </section>
445
-
446
- <section name="file-reference">
447
- ## Complete File Reference
448
-
449
- &lt;!-- Detailed list of ALL files involved with their specific roles in the story.
450
- Include file path, line count, and role description.
451
- This serves as a quick reference index for all analyzed code. --&gt;
452
-
453
- | File | Lines | Role |
454
- |------|-------|------|
455
- | [src/path/file.ts] | [N] | [Role in this story's functionality] |
456
-
457
- &lt;!-- Example:
458
- | File | Lines | Role |
459
- |------|-------|------|
460
- | src/chart/ChartWidget.ts | 450 | Main chart widget, user interaction entry point |
461
- | src/chart/ChartModel.ts | 320 | Chart state management and data model |
462
- | src/chart/LayoutManager.ts | 280 | Layout calculations and resize handling |
463
- | src/config/defaults.ts | 60 | Default configuration constants |
464
- | tests/chart.test.ts | 200 | Unit tests for chart functionality |
465
- --&gt;
466
- </section>
467
-
468
- </output-format>
469
-
470
- <analysis-process>
471
-
472
- &lt;!-- This section defines the analysis methodology that the code-discovery-analyst
473
- agent must follow. It mirrors the workflow steps but provides detailed
474
- instructions for each analysis phase.
475
-
476
- MANDATORY COMPLETION REQUIREMENTS:
477
- - Phase 1: ALL 3 items (Initial Discovery) — MANDATORY
478
- - Phase 2: ALL 9 items (Deep Implementation Analysis) — MANDATORY
479
- - Phase 3: ALL 4 items (Pattern &amp; Architecture Analysis) — MANDATORY
480
- - Total: 16 mandatory analysis items — SKIP NONE --&gt;
481
-
482
- <phase name="initial-discovery" order="1">
483
- &lt;!-- ALL 3 items are MANDATORY --&gt;
484
-
485
- <item name="understand-story" mandatory="true">
486
- **[MANDATORY] Understand the use case described in the story:**
487
- - If story is a file path: Read the markdown file directly
488
- - If story is GitHub URL/number: Use GitHub CLI (`gh issue view`)
489
- - Fully understand what functionality needs to be analyzed
490
- - Extract the key behaviors, algorithms, and patterns to look for
491
- - The story's acceptance criteria define the SCOPE of the analysis
492
- - **Requirements come from the story** — do NOT seek requirements
493
- from other sources. The story IS the source of truth.
494
- - If a parent feature document is available, read it to understand:
495
- - The broader feature context
496
- - What other stories exist and how they relate
497
- - Dependencies and shared components between stories
498
- </item>
499
-
500
- <item name="explore-docs" mandatory="true">
501
- **[MANDATORY] Explore available documentation:**
502
- - **external-docs** (if provided):
503
- - Review for implementation context, API documentation, architecture overview
504
- - Use this to guide your code exploration
505
- - **context7 MCP server** (if installed — PREFERRED):
506
- - Query for relevant library/framework documentation
507
- - Use `mcp__context7__resolve-library-id` to find the library
508
- - Use `mcp__context7__get-library-docs` to fetch relevant docs
509
- - Get up-to-date API references and usage patterns
510
- - **ALWAYS prefer context7** over manual doc fetching when the external
511
- system is a known library/framework
512
- - If neither available: rely entirely on code exploration
513
- </item>
514
-
515
- <item name="locate-implementation" mandatory="true">
516
- **[MANDATORY] Locate the implementation in the external codebase:**
517
- - Find where the story's functionality is implemented
518
- - Start with likely entry points: exports, public APIs, event handlers
519
- - Use grep/glob to find relevant files by keywords from the story
520
- - Build an initial map of involved files before deep diving
521
- - Read README files and documentation in the external codebase
522
- for structural guidance
523
- </item>
524
- </phase>
525
-
526
- <phase name="deep-implementation" order="2">
527
- &lt;!-- ALL 9 items are MANDATORY — skip NONE --&gt;
528
-
529
- <item name="entry-points" mandatory="true">
530
- **[MANDATORY] Complete Entry Points &amp; Triggers Identification (CRITICAL):**
531
- Document ALL entry points into the story functionality:
532
- - **User Action Triggers**: Button clicks, form submissions, keyboard shortcuts
533
- - **API Entry Points**: REST endpoints, GraphQL mutations, RPC calls
534
- - **Event-Based Triggers**: WebSocket messages, system events, pub/sub messages
535
- - **Scheduled/Automated Triggers**: Cron jobs, timers, intervals
536
- - **External System Triggers**: Webhooks, callbacks, integrations
537
-
538
- For EACH entry point document:
539
- ```typescript
540
- // Entry Point Type: [User Action/API/Event/etc.]
541
- // File: src/path/file.ts:45-60
542
- // Trigger: [Exact trigger description]
543
- // Parameters: [List all parameters with types]
544
- // Example usage: [Show actual usage example]
545
- ```
546
- </item>
547
-
548
- <item name="code-paths" mandatory="true">
549
- **[MANDATORY] Complete Code Path Mapping:**
550
- - Follow EVERY code path from entry to completion
551
- - Include ALL branches, conditionals, and edge cases
552
- - Document every file, class, method, and function involved
553
- - Track all data transformations and state changes
554
- - Minimum call depth: 5+ levels
555
- </item>
556
-
557
- <item name="file-tree" mandatory="true">
558
- **[MANDATORY] Story-Specific File Tree:**
559
- Document ONLY files involved in this story (NOT the entire codebase).
560
- Categorize as: CORE, SUPPORT, CONFIG, TEST.
561
- Include line counts and one-line purpose for each file.
562
- Include total file count and line count at the bottom.
563
- </item>
564
-
565
- <item name="constants" mandatory="true">
566
- **[MANDATORY] Constants &amp; Configuration Extraction:**
567
- Extract ALL constants and configuration values used by the story.
568
- Include ACTUAL values from code, NOT placeholders.
569
- Group by category: performance limits, business thresholds, magic numbers.
570
- Always include source file path and line numbers.
571
- </item>
572
-
573
- <item name="algorithms" mandatory="true">
574
- **[MANDATORY] Algorithm &amp; Formula Documentation:**
575
- For each calculation or algorithm found:
576
- - **Purpose**: What it calculates/achieves
577
- - **Formula**: Exact mathematical formula or logic
578
- - **Implementation**: Code snippet showing implementation
579
- - **Example**: Sample input/output with explanation
580
- - **Edge Cases**: How they handle special cases
581
- </item>
582
-
583
- <item name="flow-diagram" mandatory="true">
584
- **[MANDATORY] Comprehensive Flow Diagram:**
585
- Create a detailed Mermaid sequence diagram showing:
586
- - Complete execution flow with ALL branches
587
- - Actual method names and parameters (NOT generic names)
588
- - Data flow between components
589
- - State changes and side effects
590
- - Error handling paths
591
- This diagram is MANDATORY, not optional.
592
- </item>
593
-
594
- <item name="test-patterns" mandatory="true">
595
- **[MANDATORY] Test Patterns Extraction:**
596
- Extract test cases from the external system:
597
- - Include actual test code snippets with assertions
598
- - Document test scenarios covered
599
- - Note edge cases tested
600
- - Extract test data patterns
601
- - Identify mocking strategies used
602
- </item>
603
-
604
- <item name="performance" mandatory="true">
605
- **[MANDATORY] Performance Considerations:**
606
- Document any performance optimizations found:
607
- - Caching strategies used
608
- - Algorithm optimizations
609
- - Throttling/debouncing patterns
610
- - Memory management techniques
611
- - Batch processing approaches
612
- Include code references for each optimization.
613
- </item>
614
-
615
- <item name="validation-security" mandatory="true">
616
- **[MANDATORY] Validation &amp; Security:**
617
- Extract validation and security measures:
618
- - Input validation rules with actual validation code
619
- - Data sanitization methods
620
- - Security checks implemented
621
- - Error boundaries
622
- Include actual code snippets showing validation logic.
623
- </item>
624
- </phase>
625
-
626
- <phase name="pattern-architecture" order="3">
627
- &lt;!-- ALL 4 items are MANDATORY --&gt;
628
-
629
- <item name="design-patterns" mandatory="true">
630
- **[MANDATORY] Design Patterns Identified:**
631
- - Document all design patterns used (Strategy, Observer, Factory, etc.)
632
- - Explain WHY they chose each pattern
633
- - Include code examples of pattern implementation
634
- - Note patterns shared with other parts of the system
635
- - Identify if patterns enable component integration/communication
636
- </item>
637
-
638
- <item name="lifecycle" mandatory="true">
639
- **[MANDATORY] Component Lifecycle:**
640
- - Initialization sequence
641
- - State management approach
642
- - Cleanup/disposal mechanisms
643
- - Memory management considerations
644
- </item>
645
-
646
- <item name="optimizations" mandatory="true">
647
- **[MANDATORY] Performance Optimizations:**
648
- - Caching strategies
649
- - Algorithm optimizations
650
- - Rendering optimizations (if applicable)
651
- - Data structure choices for performance
652
- </item>
653
-
654
- <item name="error-handling" mandatory="true">
655
- **[MANDATORY] Error Handling &amp; Edge Cases:**
656
- - How they handle errors at each architectural level
657
- - Validation approaches
658
- - Fallback mechanisms
659
- - Boundary conditions
660
- </item>
661
- </phase>
662
-
663
- </analysis-process>
664
-
665
- <validation-checklist>
666
- &lt;!-- Mark each item as complete before finishing.
667
- Total: 23 mandatory items — DO NOT PROCEED until ALL are verified.
668
-
669
- COMMON MISTAKE PREVENTION:
670
- - Story-Specific File Tree must show ONLY files involved in the story, not entire codebase
671
- - Entry Points must be categorized by type (User/API/Event/External)
672
- - Constants must include actual values from code, not placeholders
673
- - Test Patterns must show actual test code from external system
674
- - The Mermaid diagram is MANDATORY, not optional
675
- - Extract ACTUAL code and formulas, not descriptions
676
- - Document file paths and line numbers for ALL references --&gt;
677
-
678
- <category name="file-creation">
679
- <check>[MANDATORY] Analysis file created at story-directory/external-analysis.md</check>
680
- <check>[MANDATORY] Story directory created if it didn't exist</check>
681
- <check>[MANDATORY] File contains all required sections from template</check>
682
- </category>
683
-
684
- <category name="core-analysis">
685
- <check>[MANDATORY &amp; CRITICAL] No assumptions — analysis reflects 100% accurate code, no guessing</check>
686
- <check>[MANDATORY] Complete Entry Points &amp; Triggers section with ALL trigger types</check>
687
- <check>[MANDATORY] Story-Specific File Tree showing ONLY files involved in story</check>
688
- <check>[MANDATORY] Constants &amp; Configuration section with actual values</check>
689
- <check>[MANDATORY] Mermaid sequence diagram showing complete data flow</check>
690
- <check>[MANDATORY] All algorithms and formulas extracted with explanations</check>
691
- <check>[MANDATORY] Code examples included from external implementation</check>
692
- <check>[MANDATORY] Architecture patterns identified and documented</check>
693
- </category>
694
-
695
- <category name="enhanced-sections">
696
- <check>[MANDATORY] Test Patterns section with actual test code</check>
697
- <check>[MANDATORY] Validation &amp; Security section with validation rules</check>
698
- <check>[MANDATORY] Performance Optimizations documented</check>
699
- <check>[MANDATORY] Story Integration Within Feature section completed</check>
700
- <check>[MANDATORY] Complete File Reference with file roles</check>
701
- </category>
702
-
703
- <category name="quality">
704
- <check>[MANDATORY] All entry points categorized (User/API/Event/External)</check>
705
- <check>[MANDATORY] Complete code path mapping documented (5+ levels deep)</check>
706
- <check>[MANDATORY] Error handling approaches analyzed</check>
707
- <check>[MANDATORY] No assumptions made — only documented what was found in code</check>
708
- <check>[MANDATORY] Lessons for our implementation clearly stated</check>
709
- </category>
710
-
711
- <category name="metrics">
712
- <check>[MANDATORY] Minimum 30+ files read for the story</check>
713
- <check>[MANDATORY] Minimum 50+ code references documented</check>
714
- <check>[MANDATORY] Minimum 5+ call depth traced</check>
715
- <check>[MANDATORY] All metrics reported in output header</check>
716
- </category>
717
- </validation-checklist>
718
-
719
- <guidelines>
720
-
721
- <guideline name="accuracy-first">
722
- NO ASSUMPTIONS are tolerated. The analysis must reflect 100% accurate code.
723
- Only document what you actually find in the code. Never infer behavior
724
- that isn't explicitly implemented. Every claim must be traceable to
725
- actual code references with file paths and line numbers.
726
- </guideline>
727
-
728
- <guideline name="story-scope">
729
- Focus exclusively on code paths related to the story.
730
- Do NOT document the entire external codebase — only files, functions,
731
- and constants that are directly involved in implementing the story's
732
- functionality as defined by its acceptance criteria.
733
- </guideline>
734
-
735
- <guideline name="code-level-depth">
736
- This is a DEEP TECHNICAL ANALYSIS, not a summary:
737
- - EVERY LINE OF CODE related to the story must be analyzed
738
- - ACTUAL CODE SNIPPETS must be included, not descriptions
739
- - EXACT FORMULAS AND ALGORITHMS must be extracted verbatim
740
- - COMPLETE FILE PATHS WITH LINE NUMBERS for every reference
741
- - NO HIGH-LEVEL SUMMARIES — only detailed, code-level analysis
742
-
743
- This output will be used as the PRIMARY TECHNICAL REFERENCE for
744
- implementing this story. Without complete code-level detail, the
745
- analysis is USELESS.
746
- </guideline>
747
-
748
- <guideline name="thoroughness">
749
- THOROUGH &amp; COMPREHENSIVE: Cover every aspect of the implementation.
750
- 100% SUBSTANTIVE: Only include relevant, actionable information.
751
- TAKE ALL TIME NEEDED: Read EVERY line of relevant code.
752
- ACCURACY IS PARAMOUNT: This will guide our own implementation.
753
- </guideline>
754
-
755
- <guideline name="minimum-metrics">
756
- Every analysis must meet these minimum metrics:
757
- - 30+ files read for the story
758
- - 50+ code references documented
759
- - 5+ call depth traced
760
- All metrics must be reported in the output header.
761
- </guideline>
762
-
763
- <guideline name="mermaid-required">
764
- The Mermaid sequence diagram is MANDATORY, not optional.
765
- It must show complete execution flow with actual method names
766
- (from the code, not generic placeholders), all branches,
767
- data flow between components, state changes, and error handling paths.
768
- GitHub renders Mermaid natively in markdown files.
769
- </guideline>
770
-
771
- <guideline name="context7-preference">
772
- When the external system is a known library or framework,
773
- PREFER using the context7 MCP server (if installed) to fetch
774
- up-to-date documentation. This provides more accurate and
775
- current information than static docs.
776
- Use `mcp__context7__resolve-library-id` to find the library,
777
- then `mcp__context7__get-library-docs` to fetch relevant documentation.
778
- </guideline>
779
-
780
- <guideline name="requirements-from-story">
781
- Requirements for the analysis come from the story document.
782
- The story's User Story, Description, and Acceptance Criteria
783
- define WHAT to analyze in the external codebase.
784
- Do NOT seek requirements from other sources — the story IS
785
- the source of truth for what functionality to analyze.
786
- </guideline>
787
-
788
- <guideline name="github-compatibility">
789
- The analysis document must render cleanly in GitHub markdown viewers.
790
- - Mermaid diagrams are supported via ```mermaid fenced code blocks
791
- - Use markdown tables (no HTML tables)
792
- - No custom CSS or HTML styling
793
- - Code blocks with language hints for syntax highlighting
794
- </guideline>
795
-
796
- <guideline name="common-mistakes">
797
- Common mistakes to avoid:
798
- - Story-Specific File Tree must show ONLY files involved in the story, not entire codebase
799
- - Entry Points must be categorized by type (User/API/Event/External)
800
- - Constants must include actual values from code, not placeholders
801
- - Test Patterns must show actual test code from external system
802
- - Extract ACTUAL code and formulas, not descriptions of code
803
- - Document file paths and line numbers for ALL references
804
- - Do not mix story-level analysis with feature-level analysis
805
- </guideline>
806
-
807
- </guidelines>
808
-
809
- <evolution>
810
-
811
- **Creation (research-external-solution — pass 3):**
812
- This is pass 3 of the story specification pipeline.
813
- A single run produces the complete external-analysis.md document.
814
- All sections must be filled, all metrics met, all checklist items verified.
815
-
816
- **Consumption (story-technical-solution — pass 5):**
817
- The external-analysis.md is consumed as input by pass 5 (technical solution).
818
- The technical solution uses insights from this analysis to design our
819
- own implementation approach — algorithms, patterns, architecture decisions.
820
-
821
- **Re-analysis (exception, not norm):**
822
- Only when the story scope changes significantly or the external system
823
- version changes. Re-running overwrites the existing analysis.
824
-
825
- **This analysis does NOT modify the story file.**
826
- It lives as a separate artifact in the story directory.
827
- The story.xml template has no sections that reference this analysis directly.
828
- Only the technical solution (pass 5) consumes it.
829
-
830
- </evolution>
831
-
832
- </external-solution>
1
+ <external-solution>
2
+
3
+ <purpose>
4
+ Template for `.ace/artifacts/product/&lt;id-epic_name&gt;/&lt;id-feature_name&gt;/&lt;id-story_name&gt;/external-analysis.md` —
5
+ a COMPREHENSIVE, IN-DEPTH, CODE-LEVEL analysis of how a specific story's functionality
6
+ is implemented in an external reference system (industry-standard codebase).
7
+
8
+ This is pass 3 of the story specification pipeline (see story.xml composition).
9
+ It produces a separate artifact in the story directory — NOT appended to the story file.
10
+ The analysis is consumed by pass 5 (technical solution) as input for designing
11
+ our own implementation.
12
+
13
+ This is NOT a high-level overview. It is a DEEP DIVE into:
14
+ - EXACT code implementations with line-by-line analysis
15
+ - COMPLETE algorithms and formulas extracted verbatim from code
16
+ - ALL design patterns with actual code examples
17
+ - EVERY file, function, and constant involved in the story
18
+ - FULL execution paths traced 5+ levels deep minimum
19
+
20
+ The analysis ensures our implementation:
21
+ - Follows established patterns and best practices (with code proof)
22
+ - Uses exact algorithms and formulas (copied from their code)
23
+ - Maintains compatibility with industry standards (matching their APIs)
24
+
25
+ This document does NOT modify the story file. It lives as a separate artifact
26
+ in the story directory. Only the technical solution (pass 5) consumes it.
27
+ </purpose>
28
+
29
+ <output-format>
30
+
31
+ <section name="header">
32
+ # External Implementation Analysis: [Story Name]
33
+
34
+ ## Repository Analyzed
35
+ - **Source**: [Repository name/URL]
36
+ - **Version/Commit**: [Specific version or commit hash analyzed]
37
+ - **Story/Use Case**: [Description of story functionality analyzed]
38
+ - **Analysis Date**: [Current date]
39
+ - **Metrics**: Files read: [X] | Code references: [Y] | Call depth: [Z]
40
+ </section>
41
+
42
+ <section name="implementation-overview">
43
+ ## Implementation Overview
44
+
45
+ [COMPREHENSIVE, DETAILED analysis of EXACTLY how the external system implements
46
+ this story's functionality. Describe the overall approach, architecture, and
47
+ key implementation decisions. This is a holistic view of the implementation
48
+ with complete code paths.
49
+
50
+ This is NOT a summary — it is a complete technical description of the
51
+ implementation approach, covering how the components work together to
52
+ deliver the functionality described in the story's acceptance criteria.]
53
+ </section>
54
+
55
+ <section name="entry-points">
56
+ ## Entry Points &amp; Triggers
57
+
58
+ &lt;!-- Document ALL entry points into the story functionality.
59
+ For EACH entry point include:
60
+ - Entry Point Type: [User Action/API/Event/Scheduled/External]
61
+ - File: src/path/file.ts:line-range
62
+ - Trigger: exact trigger description
63
+ - Parameters: list all parameters with types
64
+ - Example usage: show actual usage example from the code
65
+
66
+ Format each entry point as:
67
+ ```typescript
68
+ // Entry Point Type: [User Action/API/Event/etc.]
69
+ // File: src/path/file.ts:45-60
70
+ // Trigger: [Exact trigger description]
71
+ // Parameters: [List all parameters with types]
72
+ // Example usage: [Show actual usage example]
73
+ ```
74
+
75
+ Omit any category that has no entry points for this story. --&gt;
76
+
77
+ ### User Action Triggers
78
+ [Button clicks, form submissions, keyboard shortcuts — with code references and line numbers]
79
+
80
+ ### API Entry Points
81
+ [REST endpoints, GraphQL mutations, RPC calls — with code references and line numbers]
82
+
83
+ ### Event-Based Triggers
84
+ [WebSocket messages, system events, pub/sub messages — with code references and line numbers]
85
+
86
+ ### Scheduled / Automated Triggers
87
+ [Cron jobs, timers, intervals — with code references and line numbers]
88
+
89
+ ### External System Triggers
90
+ [Webhooks, callbacks, integrations — with code references and line numbers]
91
+ </section>
92
+
93
+ <section name="file-tree">
94
+ ## Story-Specific File Tree
95
+
96
+ &lt;!-- Document ONLY files involved in this story. NOT the entire codebase.
97
+ Categorize files by role: CORE, SUPPORT, CONFIG, TEST.
98
+ Include file size (line count) and one-line purpose.
99
+
100
+ Example:
101
+ ```
102
+ chart-container/
103
+ ├── entry-points/ [CORE]
104
+ │ ├── ChartWidget.ts (150 lines) - User interaction entry point
105
+ │ └── ChartAPI.ts (200 lines) - Public API entry point
106
+ ├── core-logic/ [CORE]
107
+ │ ├── ChartModel.ts (300 lines) - Chart state management
108
+ │ └── LayoutManager.ts (250 lines) - Layout calculations
109
+ ├── models/ [SUPPORT]
110
+ │ └── ChartOptions.ts (100 lines) - Configuration types
111
+ ├── utilities/ [SUPPORT]
112
+ │ └── SizeHelpers.ts (80 lines) - Size calculation helpers
113
+ ├── config/ [CONFIG]
114
+ │ └── Defaults.ts (50 lines) - Default configuration
115
+ └── tests/ [TEST]
116
+ ├── chart.test.ts (200 lines) - Unit tests
117
+ └── chart.integration.test.ts (150 lines) - Integration tests
118
+
119
+ Total: X files, Y lines of code specific to this story
120
+ ``` --&gt;
121
+
122
+ ```
123
+ [story-specific file tree here]
124
+ ```
125
+ </section>
126
+
127
+ <section name="constants">
128
+ ## Constants &amp; Configuration
129
+
130
+ &lt;!-- Extract ALL constants and configuration values used by the story.
131
+ Include actual values from code, NOT placeholders.
132
+ Group by category: performance limits, business thresholds, magic numbers.
133
+ Always include the source file path and line numbers.
134
+
135
+ Example:
136
+ ```typescript
137
+ // From src/config/defaults.ts:10-50
138
+ export const CHART_DEFAULTS = {
139
+ // Performance limits
140
+ MAX_BARS: 10000,
141
+ BATCH_SIZE: 100,
142
+ THROTTLE_MS: 16,
143
+
144
+ // Rendering thresholds
145
+ MIN_PIXEL_RATIO: 1,
146
+ MAX_PIXEL_RATIO: 4,
147
+
148
+ // Sizing constants
149
+ DEFAULT_WIDTH: 600,
150
+ DEFAULT_HEIGHT: 300
151
+ };
152
+ ``` --&gt;
153
+
154
+ ```typescript
155
+ // From [file:line-range]
156
+ [Actual constants extracted from external codebase]
157
+ ```
158
+ </section>
159
+
160
+ <section name="core-implementation">
161
+ ## Core Implementation
162
+
163
+ ### Algorithms &amp; Calculations
164
+
165
+ &lt;!-- For EACH algorithm or calculation found, document:
166
+ - Purpose: What it calculates/achieves
167
+ - Formula: Exact mathematical formula or logic
168
+ - Implementation: Code snippet showing implementation
169
+ - Example: Sample input/output with explanation
170
+ - Edge Cases: How they handle special cases --&gt;
171
+
172
+ #### [Algorithm/Formula Name]
173
+
174
+ **Purpose**: [What it calculates/achieves]
175
+
176
+ **Formula**:
177
+ ```
178
+ [Exact mathematical formula or logical expression]
179
+ ```
180
+
181
+ **Implementation**:
182
+ ```typescript
183
+ // From src/path/file.ts:line-range
184
+ [Actual code extracted from their implementation with inline comments]
185
+ ```
186
+
187
+ **Example**:
188
+ - Input: [sample input values]
189
+ - Output: [expected output]
190
+ - Explanation: [how the algorithm produces this result]
191
+
192
+ **Edge Cases**:
193
+ - [How they handle edge case 1]
194
+ - [How they handle edge case 2]
195
+
196
+ &lt;!-- Repeat for each algorithm/calculation found --&gt;
197
+
198
+ ### Data Flow
199
+
200
+ &lt;!-- MANDATORY Mermaid sequence diagram showing:
201
+ - Complete execution flow with ALL branches
202
+ - Actual method names and parameters
203
+ - Data flow between components
204
+ - State changes and side effects
205
+ - Error handling paths
206
+
207
+ The diagram must use ACTUAL method names from the code,
208
+ not generic placeholders. --&gt;
209
+
210
+ ```mermaid
211
+ sequenceDiagram
212
+ participant User
213
+ participant Controller
214
+ participant Service
215
+ participant DataStore
216
+
217
+ User->>Controller: triggerAction(params)
218
+ Controller->>Service: processRequest(data)
219
+ Service->>DataStore: query(criteria)
220
+ DataStore-->>Service: results
221
+ Service-->>Controller: processedData
222
+ Controller-->>User: response
223
+ ```
224
+
225
+ ### Key Components
226
+
227
+ &lt;!-- Detailed breakdown of each component involved in the story.
228
+ For each component include:
229
+ - File path with line range
230
+ - Purpose (what this component does in the story)
231
+ - Public API (methods/properties exposed)
232
+ - Internal Logic (key implementation details)
233
+ - Dependencies (other components it depends on) --&gt;
234
+
235
+ #### [Component Name]
236
+
237
+ - **File**: [path:line-range]
238
+ - **Purpose**: [what this component does in the context of this story]
239
+ - **Public API**:
240
+ - `methodName(params): returnType` — [description]
241
+ - **Internal Logic**: [key implementation details with code references]
242
+ - **Dependencies**: [other components it depends on]
243
+ </section>
244
+
245
+ <section name="code-examples">
246
+ ## Code Examples
247
+
248
+ &lt;!-- Actual code extracted from external implementation.
249
+ Include inline comments explaining the logic.
250
+ Group by algorithm/feature/component.
251
+ Always include source file path and line numbers. --&gt;
252
+
253
+ ### [Algorithm/Feature Name]
254
+
255
+ ```typescript
256
+ // From src/path/file.ts:line-range
257
+ // [Explanation of what this code does and why]
258
+ [Actual code from external implementation]
259
+ ```
260
+
261
+ &lt;!-- Repeat for each significant code example --&gt;
262
+ </section>
263
+
264
+ <section name="test-patterns">
265
+ ## Test Patterns
266
+
267
+ &lt;!-- Extract test cases from the external system.
268
+ Include actual test code with assertions.
269
+ Document test scenarios, edge cases, mocking strategies.
270
+
271
+ Example:
272
+ ```typescript
273
+ // From tests/chart.test.ts:50-80
274
+ describe('ChartContainer', () => {
275
+ it('should initialize with default dimensions', () => {
276
+ const chart = createChart(container);
277
+ expect(chart.width()).toBe(DEFAULT_WIDTH);
278
+ expect(chart.height()).toBe(DEFAULT_HEIGHT);
279
+ });
280
+
281
+ it('should handle resize events', () => {
282
+ const chart = createChart(container);
283
+ chart.resize(800, 600);
284
+ expect(chart.width()).toBe(800);
285
+ });
286
+ });
287
+ ``` --&gt;
288
+
289
+ ```typescript
290
+ // From [test file:line-range]
291
+ [Actual test code from external system]
292
+ ```
293
+
294
+ ### Test Scenarios Covered
295
+ - [Scenario 1 — what it tests and why]
296
+ - [Scenario 2 — what it tests and why]
297
+
298
+ ### Edge Cases Tested
299
+ - [Edge case 1 — how it's tested]
300
+
301
+ ### Mocking Strategies
302
+ - [What they mock and how — with code examples if notable]
303
+ </section>
304
+
305
+ <section name="validation-security">
306
+ ## Validation &amp; Security
307
+
308
+ &lt;!-- Extract validation and security measures.
309
+ Include actual validation code with rules.
310
+
311
+ Example:
312
+ ```typescript
313
+ // From src/validators/options.ts:20-45
314
+ function validateOptions(options: ChartOptions): void {
315
+ if (options.width <= 0) {
316
+ throw new Error('Width must be positive');
317
+ }
318
+ if (options.height <= 0) {
319
+ throw new Error('Height must be positive');
320
+ }
321
+ }
322
+ ``` --&gt;
323
+
324
+ ```typescript
325
+ // From [file:line-range]
326
+ [Actual validation/security code from external system]
327
+ ```
328
+
329
+ ### Input Validation Rules
330
+ - [Rule 1 — what is validated, how, and error behavior]
331
+ - [Rule 2 — what is validated, how, and error behavior]
332
+
333
+ ### Security Measures
334
+ - [Measure 1 — what security check is performed]
335
+
336
+ ### Error Handling Patterns
337
+ - [Pattern 1 — how errors are caught, propagated, and displayed]
338
+ </section>
339
+
340
+ <section name="performance">
341
+ ## Performance Optimizations
342
+
343
+ &lt;!-- Document specific optimizations found in the code.
344
+ Include code references for each optimization. --&gt;
345
+
346
+ ### Caching Strategies
347
+ - [What is cached, how, when invalidated — with code references]
348
+
349
+ ### Algorithm Optimizations
350
+ - [Optimization 1 — what it does, why, with code reference]
351
+
352
+ ### Resource Management
353
+ - [How they manage memory, connections, handles — with code references]
354
+
355
+ ### Throttling / Debouncing
356
+ - [Patterns used for rate limiting — with code references]
357
+
358
+ ### Batch Processing
359
+ - [How they handle bulk operations — with code references]
360
+ </section>
361
+
362
+ <section name="architecture-decisions">
363
+ ## Architecture Decisions
364
+
365
+ &lt;!-- Why they made specific architectural choices for this story's functionality.
366
+ Each decision should include code examples showing the pattern. --&gt;
367
+
368
+ ### Design Patterns Identified
369
+
370
+ &lt;!-- Document all design patterns used (Strategy, Observer, Factory, etc.)
371
+ For EACH pattern:
372
+ - Where it's used (file/component)
373
+ - Why they chose it
374
+ - Code example showing the pattern implementation
375
+ - Whether it's shared with other parts of the system --&gt;
376
+
377
+ #### [Pattern Name]
378
+ - **Where**: [File/component where pattern is used]
379
+ - **Why**: [Why this pattern was chosen for this functionality]
380
+ - **Implementation**:
381
+ ```typescript
382
+ // From [file:line-range]
383
+ [Code example showing the pattern]
384
+ ```
385
+ - **Shared**: [Whether other components also use this pattern]
386
+
387
+ ### Component Lifecycle
388
+ - **Initialization**: [sequence — with code references]
389
+ - **State Management**: [approach — with code references]
390
+ - **Cleanup/Disposal**: [mechanisms — with code references]
391
+ - **Memory Management**: [considerations — with code references]
392
+
393
+ ### Error Handling &amp; Edge Cases
394
+ - [How they handle errors at each architectural level]
395
+ - [Validation approaches with code references]
396
+ - [Fallback mechanisms]
397
+ - [Boundary conditions and how they're handled]
398
+ </section>
399
+
400
+ <section name="story-integration">
401
+ ## Story Integration Within Feature
402
+
403
+ &lt;!-- How this story's functionality relates to other stories in the feature.
404
+ This section helps understand boundaries and integration points. --&gt;
405
+
406
+ ### Dependencies on Other Stories
407
+ &lt;!-- List stories this depends on and what it needs from them.
408
+ Based on both the external system analysis and the parent feature document. --&gt;
409
+ - [Story ID — what this story needs from it]
410
+
411
+ ### Provided to Other Stories
412
+ &lt;!-- List what this story provides that other stories consume. --&gt;
413
+ - [Story ID — what this story provides to it]
414
+
415
+ ### Shared Components
416
+ &lt;!-- Components/services used across multiple stories in the feature. --&gt;
417
+ - [Component — which stories share it and how]
418
+
419
+ ### Integration Points
420
+ &lt;!-- How this story connects with other stories in the feature.
421
+ APIs, events, data flows, shared state. --&gt;
422
+ - [Integration point — how stories communicate]
423
+ </section>
424
+
425
+ <section name="lessons">
426
+ ## Lessons for Our Implementation
427
+
428
+ &lt;!-- Key takeaways specific to implementing this story.
429
+ This is the most actionable section — it directly guides our implementation.
430
+
431
+ Cover:
432
+ - How to ensure compatibility with other stories in the feature
433
+ - Shared patterns to maintain consistency across stories
434
+ - Integration considerations for feature completeness
435
+ - Algorithms and formulas to reuse
436
+ - Pitfalls to avoid based on the external system's approach
437
+ - Performance strategies worth adopting --&gt;
438
+
439
+ - [Key insight 1 — how it impacts our design]
440
+ - [Key insight 2 — algorithms to use or adapt]
441
+ - [Key insight 3 — patterns to follow]
442
+ - [Key insight 4 — compatibility considerations]
443
+ - [Key insight 5 — performance strategies to adopt]
444
+ </section>
445
+
446
+ <section name="file-reference">
447
+ ## Complete File Reference
448
+
449
+ &lt;!-- Detailed list of ALL files involved with their specific roles in the story.
450
+ Include file path, line count, and role description.
451
+ This serves as a quick reference index for all analyzed code. --&gt;
452
+
453
+ | File | Lines | Role |
454
+ |------|-------|------|
455
+ | [src/path/file.ts] | [N] | [Role in this story's functionality] |
456
+
457
+ &lt;!-- Example:
458
+ | File | Lines | Role |
459
+ |------|-------|------|
460
+ | src/chart/ChartWidget.ts | 450 | Main chart widget, user interaction entry point |
461
+ | src/chart/ChartModel.ts | 320 | Chart state management and data model |
462
+ | src/chart/LayoutManager.ts | 280 | Layout calculations and resize handling |
463
+ | src/config/defaults.ts | 60 | Default configuration constants |
464
+ | tests/chart.test.ts | 200 | Unit tests for chart functionality |
465
+ --&gt;
466
+ </section>
467
+
468
+ </output-format>
469
+
470
+ <analysis-process>
471
+
472
+ &lt;!-- This section defines the analysis methodology that the code-discovery-analyst
473
+ agent must follow. It mirrors the workflow steps but provides detailed
474
+ instructions for each analysis phase.
475
+
476
+ MANDATORY COMPLETION REQUIREMENTS:
477
+ - Phase 1: ALL 3 items (Initial Discovery) — MANDATORY
478
+ - Phase 2: ALL 9 items (Deep Implementation Analysis) — MANDATORY
479
+ - Phase 3: ALL 4 items (Pattern &amp; Architecture Analysis) — MANDATORY
480
+ - Total: 16 mandatory analysis items — SKIP NONE --&gt;
481
+
482
+ <phase name="initial-discovery" order="1">
483
+ &lt;!-- ALL 3 items are MANDATORY --&gt;
484
+
485
+ <item name="understand-story" mandatory="true">
486
+ **[MANDATORY] Understand the use case described in the story:**
487
+ - If story is a file path: Read the markdown file directly
488
+ - If story is GitHub URL/number: Use GitHub CLI (`gh issue view`)
489
+ - Fully understand what functionality needs to be analyzed
490
+ - Extract the key behaviors, algorithms, and patterns to look for
491
+ - The story's acceptance criteria define the SCOPE of the analysis
492
+ - **Requirements come from the story** — do NOT seek requirements
493
+ from other sources. The story IS the source of truth.
494
+ - If a parent feature document is available, read it to understand:
495
+ - The broader feature context
496
+ - What other stories exist and how they relate
497
+ - Dependencies and shared components between stories
498
+ </item>
499
+
500
+ <item name="explore-docs" mandatory="true">
501
+ **[MANDATORY] Explore available documentation:**
502
+ - **external-docs** (if provided):
503
+ - Review for implementation context, API documentation, architecture overview
504
+ - Use this to guide your code exploration
505
+ - **context7 MCP server** (if installed — PREFERRED):
506
+ - Query for relevant library/framework documentation
507
+ - Use `mcp__context7__resolve-library-id` to find the library
508
+ - Use `mcp__context7__get-library-docs` to fetch relevant docs
509
+ - Get up-to-date API references and usage patterns
510
+ - **ALWAYS prefer context7** over manual doc fetching when the external
511
+ system is a known library/framework
512
+ - If neither available: rely entirely on code exploration
513
+ </item>
514
+
515
+ <item name="locate-implementation" mandatory="true">
516
+ **[MANDATORY] Locate the implementation in the external codebase:**
517
+ - Find where the story's functionality is implemented
518
+ - Start with likely entry points: exports, public APIs, event handlers
519
+ - Use grep/glob to find relevant files by keywords from the story
520
+ - Build an initial map of involved files before deep diving
521
+ - Read README files and documentation in the external codebase
522
+ for structural guidance
523
+ </item>
524
+ </phase>
525
+
526
+ <phase name="deep-implementation" order="2">
527
+ &lt;!-- ALL 9 items are MANDATORY — skip NONE --&gt;
528
+
529
+ <item name="entry-points" mandatory="true">
530
+ **[MANDATORY] Complete Entry Points &amp; Triggers Identification (CRITICAL):**
531
+ Document ALL entry points into the story functionality:
532
+ - **User Action Triggers**: Button clicks, form submissions, keyboard shortcuts
533
+ - **API Entry Points**: REST endpoints, GraphQL mutations, RPC calls
534
+ - **Event-Based Triggers**: WebSocket messages, system events, pub/sub messages
535
+ - **Scheduled/Automated Triggers**: Cron jobs, timers, intervals
536
+ - **External System Triggers**: Webhooks, callbacks, integrations
537
+
538
+ For EACH entry point document:
539
+ ```typescript
540
+ // Entry Point Type: [User Action/API/Event/etc.]
541
+ // File: src/path/file.ts:45-60
542
+ // Trigger: [Exact trigger description]
543
+ // Parameters: [List all parameters with types]
544
+ // Example usage: [Show actual usage example]
545
+ ```
546
+ </item>
547
+
548
+ <item name="code-paths" mandatory="true">
549
+ **[MANDATORY] Complete Code Path Mapping:**
550
+ - Follow EVERY code path from entry to completion
551
+ - Include ALL branches, conditionals, and edge cases
552
+ - Document every file, class, method, and function involved
553
+ - Track all data transformations and state changes
554
+ - Minimum call depth: 5+ levels
555
+ </item>
556
+
557
+ <item name="file-tree" mandatory="true">
558
+ **[MANDATORY] Story-Specific File Tree:**
559
+ Document ONLY files involved in this story (NOT the entire codebase).
560
+ Categorize as: CORE, SUPPORT, CONFIG, TEST.
561
+ Include line counts and one-line purpose for each file.
562
+ Include total file count and line count at the bottom.
563
+ </item>
564
+
565
+ <item name="constants" mandatory="true">
566
+ **[MANDATORY] Constants &amp; Configuration Extraction:**
567
+ Extract ALL constants and configuration values used by the story.
568
+ Include ACTUAL values from code, NOT placeholders.
569
+ Group by category: performance limits, business thresholds, magic numbers.
570
+ Always include source file path and line numbers.
571
+ </item>
572
+
573
+ <item name="algorithms" mandatory="true">
574
+ **[MANDATORY] Algorithm &amp; Formula Documentation:**
575
+ For each calculation or algorithm found:
576
+ - **Purpose**: What it calculates/achieves
577
+ - **Formula**: Exact mathematical formula or logic
578
+ - **Implementation**: Code snippet showing implementation
579
+ - **Example**: Sample input/output with explanation
580
+ - **Edge Cases**: How they handle special cases
581
+ </item>
582
+
583
+ <item name="flow-diagram" mandatory="true">
584
+ **[MANDATORY] Comprehensive Flow Diagram:**
585
+ Create a detailed Mermaid sequence diagram showing:
586
+ - Complete execution flow with ALL branches
587
+ - Actual method names and parameters (NOT generic names)
588
+ - Data flow between components
589
+ - State changes and side effects
590
+ - Error handling paths
591
+ This diagram is MANDATORY, not optional.
592
+ </item>
593
+
594
+ <item name="test-patterns" mandatory="true">
595
+ **[MANDATORY] Test Patterns Extraction:**
596
+ Extract test cases from the external system:
597
+ - Include actual test code snippets with assertions
598
+ - Document test scenarios covered
599
+ - Note edge cases tested
600
+ - Extract test data patterns
601
+ - Identify mocking strategies used
602
+ </item>
603
+
604
+ <item name="performance" mandatory="true">
605
+ **[MANDATORY] Performance Considerations:**
606
+ Document any performance optimizations found:
607
+ - Caching strategies used
608
+ - Algorithm optimizations
609
+ - Throttling/debouncing patterns
610
+ - Memory management techniques
611
+ - Batch processing approaches
612
+ Include code references for each optimization.
613
+ </item>
614
+
615
+ <item name="validation-security" mandatory="true">
616
+ **[MANDATORY] Validation &amp; Security:**
617
+ Extract validation and security measures:
618
+ - Input validation rules with actual validation code
619
+ - Data sanitization methods
620
+ - Security checks implemented
621
+ - Error boundaries
622
+ Include actual code snippets showing validation logic.
623
+ </item>
624
+ </phase>
625
+
626
+ <phase name="pattern-architecture" order="3">
627
+ &lt;!-- ALL 4 items are MANDATORY --&gt;
628
+
629
+ <item name="design-patterns" mandatory="true">
630
+ **[MANDATORY] Design Patterns Identified:**
631
+ - Document all design patterns used (Strategy, Observer, Factory, etc.)
632
+ - Explain WHY they chose each pattern
633
+ - Include code examples of pattern implementation
634
+ - Note patterns shared with other parts of the system
635
+ - Identify if patterns enable component integration/communication
636
+ </item>
637
+
638
+ <item name="lifecycle" mandatory="true">
639
+ **[MANDATORY] Component Lifecycle:**
640
+ - Initialization sequence
641
+ - State management approach
642
+ - Cleanup/disposal mechanisms
643
+ - Memory management considerations
644
+ </item>
645
+
646
+ <item name="optimizations" mandatory="true">
647
+ **[MANDATORY] Performance Optimizations:**
648
+ - Caching strategies
649
+ - Algorithm optimizations
650
+ - Rendering optimizations (if applicable)
651
+ - Data structure choices for performance
652
+ </item>
653
+
654
+ <item name="error-handling" mandatory="true">
655
+ **[MANDATORY] Error Handling &amp; Edge Cases:**
656
+ - How they handle errors at each architectural level
657
+ - Validation approaches
658
+ - Fallback mechanisms
659
+ - Boundary conditions
660
+ </item>
661
+ </phase>
662
+
663
+ </analysis-process>
664
+
665
+ <validation-checklist>
666
+ &lt;!-- Mark each item as complete before finishing.
667
+ Total: 23 mandatory items — DO NOT PROCEED until ALL are verified.
668
+
669
+ COMMON MISTAKE PREVENTION:
670
+ - Story-Specific File Tree must show ONLY files involved in the story, not entire codebase
671
+ - Entry Points must be categorized by type (User/API/Event/External)
672
+ - Constants must include actual values from code, not placeholders
673
+ - Test Patterns must show actual test code from external system
674
+ - The Mermaid diagram is MANDATORY, not optional
675
+ - Extract ACTUAL code and formulas, not descriptions
676
+ - Document file paths and line numbers for ALL references --&gt;
677
+
678
+ <category name="file-creation">
679
+ <check>[MANDATORY] Analysis file created at story-directory/external-analysis.md</check>
680
+ <check>[MANDATORY] Story directory created if it didn't exist</check>
681
+ <check>[MANDATORY] File contains all required sections from template</check>
682
+ </category>
683
+
684
+ <category name="core-analysis">
685
+ <check>[MANDATORY &amp; CRITICAL] No assumptions — analysis reflects 100% accurate code, no guessing</check>
686
+ <check>[MANDATORY] Complete Entry Points &amp; Triggers section with ALL trigger types</check>
687
+ <check>[MANDATORY] Story-Specific File Tree showing ONLY files involved in story</check>
688
+ <check>[MANDATORY] Constants &amp; Configuration section with actual values</check>
689
+ <check>[MANDATORY] Mermaid sequence diagram showing complete data flow</check>
690
+ <check>[MANDATORY] All algorithms and formulas extracted with explanations</check>
691
+ <check>[MANDATORY] Code examples included from external implementation</check>
692
+ <check>[MANDATORY] Architecture patterns identified and documented</check>
693
+ </category>
694
+
695
+ <category name="enhanced-sections">
696
+ <check>[MANDATORY] Test Patterns section with actual test code</check>
697
+ <check>[MANDATORY] Validation &amp; Security section with validation rules</check>
698
+ <check>[MANDATORY] Performance Optimizations documented</check>
699
+ <check>[MANDATORY] Story Integration Within Feature section completed</check>
700
+ <check>[MANDATORY] Complete File Reference with file roles</check>
701
+ </category>
702
+
703
+ <category name="quality">
704
+ <check>[MANDATORY] All entry points categorized (User/API/Event/External)</check>
705
+ <check>[MANDATORY] Complete code path mapping documented (5+ levels deep)</check>
706
+ <check>[MANDATORY] Error handling approaches analyzed</check>
707
+ <check>[MANDATORY] No assumptions made — only documented what was found in code</check>
708
+ <check>[MANDATORY] Lessons for our implementation clearly stated</check>
709
+ </category>
710
+
711
+ <category name="metrics">
712
+ <check>[MANDATORY] Minimum 30+ files read for the story</check>
713
+ <check>[MANDATORY] Minimum 50+ code references documented</check>
714
+ <check>[MANDATORY] Minimum 5+ call depth traced</check>
715
+ <check>[MANDATORY] All metrics reported in output header</check>
716
+ </category>
717
+ </validation-checklist>
718
+
719
+ <guidelines>
720
+
721
+ <guideline name="accuracy-first">
722
+ NO ASSUMPTIONS are tolerated. The analysis must reflect 100% accurate code.
723
+ Only document what you actually find in the code. Never infer behavior
724
+ that isn't explicitly implemented. Every claim must be traceable to
725
+ actual code references with file paths and line numbers.
726
+ </guideline>
727
+
728
+ <guideline name="story-scope">
729
+ Focus exclusively on code paths related to the story.
730
+ Do NOT document the entire external codebase — only files, functions,
731
+ and constants that are directly involved in implementing the story's
732
+ functionality as defined by its acceptance criteria.
733
+ </guideline>
734
+
735
+ <guideline name="code-level-depth">
736
+ This is a DEEP TECHNICAL ANALYSIS, not a summary:
737
+ - EVERY LINE OF CODE related to the story must be analyzed
738
+ - ACTUAL CODE SNIPPETS must be included, not descriptions
739
+ - EXACT FORMULAS AND ALGORITHMS must be extracted verbatim
740
+ - COMPLETE FILE PATHS WITH LINE NUMBERS for every reference
741
+ - NO HIGH-LEVEL SUMMARIES — only detailed, code-level analysis
742
+
743
+ This output will be used as the PRIMARY TECHNICAL REFERENCE for
744
+ implementing this story. Without complete code-level detail, the
745
+ analysis is USELESS.
746
+ </guideline>
747
+
748
+ <guideline name="thoroughness">
749
+ THOROUGH &amp; COMPREHENSIVE: Cover every aspect of the implementation.
750
+ 100% SUBSTANTIVE: Only include relevant, actionable information.
751
+ TAKE ALL TIME NEEDED: Read EVERY line of relevant code.
752
+ ACCURACY IS PARAMOUNT: This will guide our own implementation.
753
+ </guideline>
754
+
755
+ <guideline name="minimum-metrics">
756
+ Every analysis must meet these minimum metrics:
757
+ - 30+ files read for the story
758
+ - 50+ code references documented
759
+ - 5+ call depth traced
760
+ All metrics must be reported in the output header.
761
+ </guideline>
762
+
763
+ <guideline name="mermaid-required">
764
+ The Mermaid sequence diagram is MANDATORY, not optional.
765
+ It must show complete execution flow with actual method names
766
+ (from the code, not generic placeholders), all branches,
767
+ data flow between components, state changes, and error handling paths.
768
+ GitHub renders Mermaid natively in markdown files.
769
+ </guideline>
770
+
771
+ <guideline name="context7-preference">
772
+ When the external system is a known library or framework,
773
+ PREFER using the context7 MCP server (if installed) to fetch
774
+ up-to-date documentation. This provides more accurate and
775
+ current information than static docs.
776
+ Use `mcp__context7__resolve-library-id` to find the library,
777
+ then `mcp__context7__get-library-docs` to fetch relevant documentation.
778
+ </guideline>
779
+
780
+ <guideline name="requirements-from-story">
781
+ Requirements for the analysis come from the story document.
782
+ The story's User Story, Description, and Acceptance Criteria
783
+ define WHAT to analyze in the external codebase.
784
+ Do NOT seek requirements from other sources — the story IS
785
+ the source of truth for what functionality to analyze.
786
+ </guideline>
787
+
788
+ <guideline name="github-compatibility">
789
+ The analysis document must render cleanly in GitHub markdown viewers.
790
+ - Mermaid diagrams are supported via ```mermaid fenced code blocks
791
+ - Use markdown tables (no HTML tables)
792
+ - No custom CSS or HTML styling
793
+ - Code blocks with language hints for syntax highlighting
794
+ </guideline>
795
+
796
+ <guideline name="common-mistakes">
797
+ Common mistakes to avoid:
798
+ - Story-Specific File Tree must show ONLY files involved in the story, not entire codebase
799
+ - Entry Points must be categorized by type (User/API/Event/External)
800
+ - Constants must include actual values from code, not placeholders
801
+ - Test Patterns must show actual test code from external system
802
+ - Extract ACTUAL code and formulas, not descriptions of code
803
+ - Document file paths and line numbers for ALL references
804
+ - Do not mix story-level analysis with feature-level analysis
805
+ </guideline>
806
+
807
+ </guidelines>
808
+
809
+ <evolution>
810
+
811
+ **Creation (research-external-solution — pass 3):**
812
+ This is pass 3 of the story specification pipeline.
813
+ A single run produces the complete external-analysis.md document.
814
+ All sections must be filled, all metrics met, all checklist items verified.
815
+
816
+ **Consumption (story-technical-solution — pass 5):**
817
+ The external-analysis.md is consumed as input by pass 5 (technical solution).
818
+ The technical solution uses insights from this analysis to design our
819
+ own implementation approach — algorithms, patterns, architecture decisions.
820
+
821
+ **Re-analysis (exception, not norm):**
822
+ Only when the story scope changes significantly or the external system
823
+ version changes. Re-running overwrites the existing analysis.
824
+
825
+ **This analysis does NOT modify the story file.**
826
+ It lives as a separate artifact in the story directory.
827
+ The story.xml template has no sections that reference this analysis directly.
828
+ Only the technical solution (pass 5) consumes it.
829
+
830
+ </evolution>
831
+
832
+ </external-solution>