@anhth2/spec-driven-dev-plugin 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/ARCHITECTURE.md +243 -0
  2. package/bin/build.js +230 -0
  3. package/bin/index.js +311 -0
  4. package/commands/debug.md +374 -0
  5. package/commands/debug.tmpl +77 -0
  6. package/commands/define-product.md +451 -0
  7. package/commands/define-product.tmpl +154 -0
  8. package/commands/fix-bug.md +379 -0
  9. package/commands/fix-bug.tmpl +82 -0
  10. package/commands/generate-bdd.md +591 -0
  11. package/commands/generate-bdd.tmpl +294 -0
  12. package/commands/generate-code.md +395 -0
  13. package/commands/generate-code.tmpl +98 -0
  14. package/commands/generate-prd.md +488 -0
  15. package/commands/generate-prd.tmpl +191 -0
  16. package/commands/generate-tech-docs.md +362 -0
  17. package/commands/generate-tech-docs.tmpl +65 -0
  18. package/commands/generate-tests.md +377 -0
  19. package/commands/generate-tests.tmpl +80 -0
  20. package/commands/refine-prd.md +408 -0
  21. package/commands/refine-prd.tmpl +111 -0
  22. package/commands/review-code.md +354 -0
  23. package/commands/review-code.tmpl +57 -0
  24. package/commands/review-context.md +646 -0
  25. package/commands/review-context.tmpl +349 -0
  26. package/commands/review-tech-docs.md +518 -0
  27. package/commands/review-tech-docs.tmpl +221 -0
  28. package/commands/run-tests.md +343 -0
  29. package/commands/run-tests.tmpl +46 -0
  30. package/commands/setup-ai-first.md +278 -0
  31. package/commands/setup-ai-first.tmpl +197 -0
  32. package/commands/smoke-test.md +366 -0
  33. package/commands/smoke-test.tmpl +69 -0
  34. package/commands/validate-traces.md +529 -0
  35. package/commands/validate-traces.tmpl +232 -0
  36. package/core/FRAMEWORK_VERSION +1 -0
  37. package/core/commands/debug.md +374 -0
  38. package/core/commands/define-product.md +451 -0
  39. package/core/commands/fix-bug.md +379 -0
  40. package/core/commands/generate-bdd.md +591 -0
  41. package/core/commands/generate-code.md +395 -0
  42. package/core/commands/generate-prd.md +488 -0
  43. package/core/commands/generate-tech-docs.md +362 -0
  44. package/core/commands/generate-tests.md +377 -0
  45. package/core/commands/refine-prd.md +408 -0
  46. package/core/commands/review-code.md +354 -0
  47. package/core/commands/review-context.md +646 -0
  48. package/core/commands/review-tech-docs.md +518 -0
  49. package/core/commands/run-tests.md +343 -0
  50. package/core/commands/setup-ai-first.md +278 -0
  51. package/core/commands/smoke-test.md +366 -0
  52. package/core/commands/validate-traces.md +529 -0
  53. package/core/hooks/data-guard.js +141 -0
  54. package/core/hooks/settings.json +18 -0
  55. package/core/modules/angular/architecture-snippets/component-patterns.md +187 -0
  56. package/core/modules/angular/module.yaml +6 -0
  57. package/core/modules/angular/stack-profile.yaml +38 -0
  58. package/core/modules/context-engineering/architecture-snippets/context-design.md +119 -0
  59. package/core/modules/context-engineering/module.yaml +9 -0
  60. package/core/modules/context-engineering/stack-profile.yaml +61 -0
  61. package/core/modules/dotnet/architecture-snippets/clean-arch.md +160 -0
  62. package/core/modules/dotnet/module.yaml +6 -0
  63. package/core/modules/dotnet/stack-profile.yaml +50 -0
  64. package/core/modules/golang/architecture-snippets/domain-layout.md +283 -0
  65. package/core/modules/golang/module.yaml +6 -0
  66. package/core/modules/golang/stack-profile.yaml +40 -0
  67. package/core/modules/java-spring/architecture-snippets/layered-arch.md +201 -0
  68. package/core/modules/java-spring/module.yaml +15 -0
  69. package/core/modules/java-spring/stack-profile.yaml +28 -0
  70. package/core/modules/nextjs/architecture-snippets/app-router-patterns.md +269 -0
  71. package/core/modules/nextjs/module.yaml +14 -0
  72. package/core/modules/nextjs/stack-profile.yaml +74 -0
  73. package/core/modules/php-laravel/architecture-snippets/service-repository.md +302 -0
  74. package/core/modules/php-laravel/module.yaml +15 -0
  75. package/core/modules/php-laravel/stack-profile.yaml +56 -0
  76. package/core/modules/react/architecture-snippets/hooks-query-patterns.md +254 -0
  77. package/core/modules/react/module.yaml +14 -0
  78. package/core/modules/react/stack-profile.yaml +63 -0
  79. package/core/rules/data-protection.md +80 -0
  80. package/core/rules/workflow.md +44 -0
  81. package/core/skills/code/SKILL.md +526 -0
  82. package/core/skills/debug/SKILL.md +584 -0
  83. package/core/skills/discovery/SKILL.md +363 -0
  84. package/core/skills/prd/SKILL.md +456 -0
  85. package/core/skills/setup-ai-first/SKILL.md +160 -0
  86. package/core/skills/spec/SKILL.md +361 -0
  87. package/core/skills/test/SKILL.md +862 -0
  88. package/core/steps/context-loader.md +163 -0
  89. package/core/steps/gate.md +81 -0
  90. package/core/steps/report-footer.md +53 -0
  91. package/core/steps/spawn-agent.md +123 -0
  92. package/core/templates/architecture.template.md +113 -0
  93. package/core/templates/feature.template +259 -0
  94. package/core/templates/platform-guide.template.md +145 -0
  95. package/core/templates/prd.template.md +312 -0
  96. package/core/templates/product-definition.template.md +168 -0
  97. package/core/templates/project-context.yaml +78 -0
  98. package/hooks/data-guard.js +141 -0
  99. package/hooks/settings.json +18 -0
  100. package/modules/angular/architecture-snippets/component-patterns.md +187 -0
  101. package/modules/angular/module.yaml +6 -0
  102. package/modules/angular/stack-profile.yaml +38 -0
  103. package/modules/context-engineering/architecture-snippets/context-design.md +119 -0
  104. package/modules/context-engineering/module.yaml +9 -0
  105. package/modules/context-engineering/stack-profile.yaml +61 -0
  106. package/modules/dotnet/architecture-snippets/clean-arch.md +160 -0
  107. package/modules/dotnet/module.yaml +6 -0
  108. package/modules/dotnet/stack-profile.yaml +50 -0
  109. package/modules/golang/architecture-snippets/domain-layout.md +283 -0
  110. package/modules/golang/module.yaml +6 -0
  111. package/modules/golang/stack-profile.yaml +40 -0
  112. package/modules/java-spring/architecture-snippets/layered-arch.md +201 -0
  113. package/modules/java-spring/module.yaml +15 -0
  114. package/modules/java-spring/stack-profile.yaml +28 -0
  115. package/modules/nextjs/architecture-snippets/app-router-patterns.md +269 -0
  116. package/modules/nextjs/module.yaml +14 -0
  117. package/modules/nextjs/stack-profile.yaml +74 -0
  118. package/modules/php-laravel/architecture-snippets/service-repository.md +302 -0
  119. package/modules/php-laravel/module.yaml +15 -0
  120. package/modules/php-laravel/stack-profile.yaml +56 -0
  121. package/modules/react/architecture-snippets/hooks-query-patterns.md +254 -0
  122. package/modules/react/module.yaml +14 -0
  123. package/modules/react/stack-profile.yaml +63 -0
  124. package/package.json +42 -0
  125. package/rules/data-protection.md +80 -0
  126. package/rules/workflow.md +44 -0
  127. package/scripts/init.sh +49 -0
  128. package/scripts/upgrade.sh +94 -0
  129. package/skills/code/SKILL.md +526 -0
  130. package/skills/code/SKILL.tmpl +176 -0
  131. package/skills/debug/SKILL.md +584 -0
  132. package/skills/debug/SKILL.tmpl +262 -0
  133. package/skills/discovery/SKILL.md +363 -0
  134. package/skills/discovery/SKILL.tmpl +147 -0
  135. package/skills/prd/SKILL.md +456 -0
  136. package/skills/prd/SKILL.tmpl +188 -0
  137. package/skills/setup-ai-first/SKILL.md +160 -0
  138. package/skills/setup-ai-first/SKILL.tmpl +107 -0
  139. package/skills/spec/SKILL.md +361 -0
  140. package/skills/spec/SKILL.tmpl +174 -0
  141. package/skills/test/SKILL.md +862 -0
  142. package/skills/test/SKILL.tmpl +296 -0
  143. package/steps/context-loader.md +163 -0
  144. package/steps/gate.md +81 -0
  145. package/steps/report-footer.md +53 -0
  146. package/steps/spawn-agent.md +123 -0
  147. package/templates/architecture.template.md +113 -0
  148. package/templates/feature.template +259 -0
  149. package/templates/platform-guide.template.md +145 -0
  150. package/templates/prd.template.md +312 -0
  151. package/templates/product-definition.template.md +168 -0
  152. package/templates/project-context.yaml +78 -0
@@ -0,0 +1,232 @@
1
+ # /validate-traces — Traceability Coverage Matrix
2
+
3
+ Read-only check of coverage between specs, code, and tests — including PRD version drift.
4
+
5
+ ## Gate
6
+ {{include:steps/gate.md}}
7
+
8
+ *Note: For this command, the target in Step 1 is a domain name or specific UC-ID from `$ARGUMENTS`. There is no single file to resolve — the command scans multiple directories.*
9
+
10
+ ## Context
11
+ {{include:steps/context-loader.md}}
12
+
13
+ ---
14
+
15
+ ## Process
16
+
17
+ ### Step 1 — Load TSV data
18
+
19
+ Read all `{paths.trace_dir}/{UC-ID}.tsv` files matching the target domain (or all domains if no domain filter).
20
+ Each file gives the persisted trace state for that UC.
21
+
22
+ ### Step 2 — Reconcile with current `.feature` files
23
+
24
+ For each `.tsv` row, read the corresponding `.feature` file and get the **current** `@trace.sc_version` for that SC.
25
+ If the `.feature` SC version differs from the `.tsv` `spec_ver` → update `spec_ver` in memory (will be written back).
26
+
27
+ Also detect SCs present in `.feature` but missing from `.tsv` → add as new rows with `status: UNTRACKED`.
28
+
29
+ ### Step 3 — Compute `status` per scenario
30
+
31
+ Apply rules in priority order:
32
+
33
+ | Rule | Status | Condition |
34
+ |------|--------|-----------|
35
+ | 1 | `UNTRACKED` | `implemented_by == —` (no code generated yet) |
36
+ | 2 | `GAP` | `implemented_by != —` AND (`test_count == —` OR `test_count == 0`) |
37
+ | 3 | `DRIFT` | `spec_ver != gen_ver` (scenario updated since last codegen) |
38
+ | 4 | `OK` | all of: `spec_ver == gen_ver`, `implemented_by != —`, `test_count > 0` |
39
+
40
+ ### Step 4 — PRD version drift check
41
+
42
+ For each UC, compare:
43
+ - Current PRD `| **Version** |` from `{paths.prd_dir}/{domain}/{slug}.md`
44
+ - `prd_version` stored in `.tsv` (version at time of BDD generation)
45
+ - `@trace.prd_version` in the code files implementing that UC
46
+
47
+ If any layer is behind current PRD version → flag `PRD_DRIFT` and extract changelog entries since that version.
48
+
49
+ ### Step 5 — Tech-doc revision drift check
50
+
51
+ For each UC that has a tech-doc, compare:
52
+ - Current `@trace.revision` in `{paths.tech_docs_dir}/{domain}/{UC-ID}-tech-design.md`
53
+ - `tech_doc_revision` stored in `.tsv` (revision at time of codegen)
54
+
55
+ If code was generated from an older revision → flag `TECHDOC_DRIFT`.
56
+
57
+ ### Step 6 — Write status back to TSV
58
+
59
+ For each `.tsv` file processed: write updated `spec_ver`, `status`, `last_updated` back to disk.
60
+
61
+ ### Step 7 — Compute dashboard aggregates
62
+
63
+ ```
64
+ total_prds = count distinct PRD files in {paths.prd_dir}/{domain}/
65
+ approved_prds = PRDs with | Status | approved
66
+ total_ucs = count distinct UC-IDs across all .tsv files
67
+ approved_ucs = UCs with uc_status == approved
68
+ total_scs = total rows across all .tsv files
69
+ code_coverage = rows where implemented_by != — / total_scs
70
+ test_coverage = rows where test_count > 0 / total_scs
71
+ drift_count = rows where status == DRIFT
72
+ untracked_count = rows where status == UNTRACKED
73
+ gap_count = rows where status == GAP
74
+ tech_docs_count = count .md files in {paths.tech_docs_dir}/{domain}/
75
+ ```
76
+
77
+ ### Step 8 — Write JSON report
78
+
79
+ Write `.trace/trace-report.json` (overwrite if exists). This file is the single source of truth for web dashboards — it contains the full snapshot at the time `/validate-traces` was last run.
80
+
81
+ Schema:
82
+
83
+ ```json
84
+ {
85
+ "generated_at": "<ISO-8601 timestamp>",
86
+ "domain": "<domain argument, or 'all' if no filter>",
87
+ "summary": {
88
+ "total_prds": 0,
89
+ "approved_prds": 0,
90
+ "total_ucs": 0,
91
+ "approved_ucs": 0,
92
+ "draft_ucs": 0,
93
+ "total_scs": 0,
94
+ "coded_scs": 0,
95
+ "tested_scs": 0,
96
+ "code_coverage_pct": 0,
97
+ "test_coverage_pct": 0,
98
+ "drift_count": 0,
99
+ "gap_count": 0,
100
+ "untracked_count": 0,
101
+ "tech_docs_count": 0
102
+ },
103
+ "prds": [
104
+ {
105
+ "prd_id": "<e.g. PAY>",
106
+ "prd_status": "approved | draft | other",
107
+ "total_scs": 0,
108
+ "coded_scs": 0,
109
+ "tested_scs": 0,
110
+ "drift_count": 0,
111
+ "gap_count": 0,
112
+ "untracked_count": 0,
113
+ "ucs": [
114
+ {
115
+ "uc_id": "<e.g. PAY-UC01>",
116
+ "uc_status": "approved | draft | other",
117
+ "scenarios": [
118
+ {
119
+ "sc_id": "<e.g. PAY-UC01-SC1>",
120
+ "sc_title": "<title>",
121
+ "spec_ver": "<current version from .feature>",
122
+ "gen_ver": "<version at codegen time>",
123
+ "implemented_by": "<ClassName.method or null>",
124
+ "test_count": 0,
125
+ "test_classes": ["<TestClass1>", "<TestClass2>"],
126
+ "prd_version": "<prd version when BDD was generated>",
127
+ "bdd_version": "<bdd version when code was generated>",
128
+ "tech_doc_revision": 0,
129
+ "status": "OK | DRIFT | GAP | UNTRACKED",
130
+ "last_updated": "<YYYY-MM-DD>"
131
+ }
132
+ ]
133
+ }
134
+ ]
135
+ }
136
+ ],
137
+ "issues": {
138
+ "drift": [
139
+ {
140
+ "sc_id": "<SC-ID>",
141
+ "sc_title": "<title>",
142
+ "spec_ver": "<current>",
143
+ "gen_ver": "<at codegen>",
144
+ "fix": "/generate-code <UC-ID>"
145
+ }
146
+ ],
147
+ "gap": [
148
+ {
149
+ "sc_id": "<SC-ID>",
150
+ "sc_title": "<title>",
151
+ "implemented_by": "<method>",
152
+ "fix": "/generate-tests <UC-ID>"
153
+ }
154
+ ],
155
+ "untracked": [
156
+ {
157
+ "sc_id": "<SC-ID>",
158
+ "sc_title": "<title>",
159
+ "fix": "/generate-code <UC-ID>"
160
+ }
161
+ ],
162
+ "prd_version_drift": [
163
+ {
164
+ "uc_id": "<UC-ID>",
165
+ "code_prd_version": "<version in code tag>",
166
+ "current_prd_version": "<version in PRD file>",
167
+ "changelog_since": ["<v1.1: ...>", "<v1.2: ...>"],
168
+ "fix": "/generate-bdd <prd-file> then /generate-code <UC-ID>"
169
+ }
170
+ ],
171
+ "techdoc_drift": [
172
+ {
173
+ "uc_id": "<UC-ID>",
174
+ "code_revision": 0,
175
+ "current_revision": 0,
176
+ "fix": "/generate-code <UC-ID>"
177
+ }
178
+ ]
179
+ }
180
+ }
181
+ ```
182
+
183
+ **Rules:**
184
+ - `implemented_by`: use `null` (not `"—"`) in JSON when no value
185
+ - `test_count`: use integer `0` (not `"—"`) when no tests
186
+ - `test_classes`: use `[]` (not `"—"`) when no test classes
187
+ - `tech_doc_revision`: use integer; `0` if not yet generated
188
+ - `code_coverage_pct` / `test_coverage_pct`: round to nearest integer (0–100)
189
+ - Always write to `.trace/trace-report.json` regardless of domain filter — if a domain filter was applied, include only those PRDs in `prds[]` but note the domain in the `domain` field
190
+
191
+ ## Output
192
+
193
+ {{include:steps/report-footer.md}}
194
+
195
+ ```
196
+ /validate-traces — {domain}
197
+
198
+ 📄 .trace/trace-report.json ← updated
199
+
200
+ ┌─────────────────────────────────────────────────────────────────────────────────────┐
201
+ │ PRDs Use Cases Scenarios Code Cov. Test Cov. Drift Untracked Gap │
202
+ │ {N} {N} {N} {N}% {N}% {N} {N} {N} │
203
+ │ {A} appr {A} appr {X}/{T} SCs {X}/{T} SCs │
204
+ └─────────────────────────────────────────────────────────────────────────────────────┘
205
+
206
+ | UC-ID | SC | Title (truncated) | Spec | Gen | Code | Tests | Status |
207
+ |-------------|------|------------------------------|-------|-------|----------------------|----------------|----------|
208
+ | {UC}-UC1 | SC1 | {title...} | v1.0 | v1.0 | ✅ {Controller.fn} | ✅ 10 tests | OK |
209
+ | {UC}-UC1 | SC2 | {title...} | v1.1 | v1.0 | ✅ {Controller.fn} | ✅ 3 tests | DRIFT |
210
+ | {UC}-UC1 | SC6 | {title...} | v1.0 | — | — | — | UNTRACKED|
211
+ | {UC}-UC2 | SC1 | {title...} | v1.0 | v1.0 | ✅ {Controller.fn} | — | GAP |
212
+
213
+ Drift Detail:
214
+ {UC}-UC1-SC2 — spec v1.1 but code generated from v1.0
215
+ → Re-run: /generate-code {UC-ID}
216
+
217
+ PRD Version Drift:
218
+ {UC}-UC2 — code at PRD v1.0, PRD now at v1.2
219
+ Changes since v1.0:
220
+ v1.1: {changelog entry}
221
+ v1.2: {changelog entry}
222
+ → /generate-bdd {prd-file} then /generate-code {UC-ID}
223
+
224
+ Tech-Doc Revision Drift:
225
+ {UC}-UC3 — code generated from tech-doc revision 2, now at revision 4
226
+ → Review tech-doc changes then /generate-code {UC-ID}
227
+
228
+ Recommendations:
229
+ - /generate-code {UC-ID} for DRIFT and UNTRACKED scenarios
230
+ - /generate-tests {UC-ID} for GAP (missing tests)
231
+ - /generate-bdd {prd-file} for PRD version drift
232
+ ```
@@ -0,0 +1 @@
1
+ 0.5.0
@@ -0,0 +1,374 @@
1
+ # /debug — Quick Debug Analysis
2
+
3
+ Use for: IDE errors, test failures, strange behavior, or "why does this code do X?"
4
+ Different from `/fix-bug`: analysis only, no full workflow, no ticket needed.
5
+
6
+ ## Gate
7
+ # Gate — Universal Entry Procedure
8
+
9
+ Every command must execute this gate before proceeding with its specific logic.
10
+
11
+ ## Step 0 — Sub-Agent Mode Check
12
+
13
+ Before anything else, check if `$ARGUMENTS` is a JSON payload from an orchestrator:
14
+
15
+ 1. Attempt to parse `$ARGUMENTS` as JSON.
16
+ 2. If it parses successfully **and** contains `"_agent_mode": true`:
17
+ - **Skip Steps 1, 2, and 3 of this Gate entirely.**
18
+ - Set target file = `payload.target_file`
19
+ - Set loaded context = `payload.context` (do NOT run context-loader.md)
20
+ - Set UC scope = `payload.uc_id` (process only this UC)
21
+ - Set line range = `payload.uc_section` (read only that PRD section)
22
+ - Proceed directly to the command-specific logic.
23
+ 3. If `$ARGUMENTS` is not JSON or `_agent_mode` is absent → continue to Step 1 (normal mode).
24
+
25
+ ## Step 0-B — Model Check
26
+
27
+ *Skip this step if `_agent_mode: true` (sub-agent — orchestrator already validated).*
28
+
29
+ Complex generation and review commands require strong reasoning.
30
+ Using a smaller model risks missed edge cases, incomplete spec analysis, and architecture violations.
31
+
32
+ Display and wait for response:
33
+
34
+ ```
35
+ ⚙️ MODEL CHECK
36
+ ──────────────────────────────────────────────────────────────────
37
+ Recommended : claude-opus-4-5 (or claude-opus-4)
38
+ Why needed : Spec analysis, architecture review, code generation
39
+ require deep reasoning. Smaller models miss edge cases.
40
+
41
+ To switch in Claude Code:
42
+ • Settings → Model → select "claude-opus"
43
+ • or: /model → choose claude-opus
44
+
45
+ Running on claude-opus?
46
+ Y — yes, on claude-opus → proceed
47
+ S — skip check (I accept lower quality risk with current model)
48
+ ──────────────────────────────────────────────────────────────────
49
+ ```
50
+
51
+ - "Y" → proceed to Step 1.
52
+ - "S" → proceed to Step 1 (user accepts risk, add ⚠️ to final report).
53
+ - "N" or anything else → **STOP.** Output: "Please switch to claude-opus, then re-run this command."
54
+
55
+ ## Step 1 — Resolve Target File
56
+
57
+ 1. If `$ARGUMENTS` is provided and points to an existing file → use it directly as the target.
58
+ 2. If `$ARGUMENTS` is a UC-ID, ticket ID, or partial name → search for matching files in the relevant directory.
59
+ 3. If `$ARGUMENTS` is empty or no match found:
60
+ - List files in the relevant directory for this command (e.g., `specs/prd/**/*.md` for PRD commands, `specs/bdd/**/*.feature` for BDD commands).
61
+ - Present the list to the user and ask: "Which file do you want to work with? (Enter number or filename)"
62
+ - Wait for user selection before continuing.
63
+
64
+ ## Step 2 — Execute Context Loader
65
+
66
+ Load all project context by following the procedure in `steps/context-loader.md`.
67
+ Store all loaded context in memory for use throughout this command session.
68
+
69
+ ## Step 3 — CHECKPOINT
70
+
71
+ After completing Steps 1 and 2, display a summary and wait for confirmation:
72
+
73
+ ```
74
+ CHECKPOINT
75
+ -----------
76
+ Target : {resolved file path}
77
+ Project : {project.name from project-context.yaml}
78
+ Tech stack : {language} / {framework}
79
+ Module : {module if set, else "not configured"}
80
+ Domains : {comma-separated domain list}
81
+
82
+ Proceed? (Y/N)
83
+ ```
84
+
85
+ Wait for explicit "Y" or "N" from the user before continuing.
86
+ - "Y" → proceed to the command-specific steps below.
87
+ - "N" → stop and ask what the user wants to change.
88
+
89
+
90
+ *Note: For this command, the target in Step 1 is user-provided input (stack trace, test failure output, file path + description, or code question). No file discovery needed — go straight to context loading.*
91
+
92
+ ## Context
93
+ # Context Loader — Load All Project Context
94
+
95
+ Execute these steps in order. Store everything in memory for the duration of the command session.
96
+
97
+ **Priority guide (anti-lost-in-middle):**
98
+ - Steps 1–2 are PROJECT-CONFIG — loaded first, resolve all paths and metadata.
99
+ - Step 3 is CRITICAL — architecture + coding standards, the highest-priority facts for generation.
100
+ - Step 4 is SAFETY — data protection rules, enforced silently for the entire session.
101
+ - Steps 5–6 are DOMAIN KNOWLEDGE — terminology and entity definitions.
102
+ - Step 7 is the WORKING MEMORY RECAP — locks critical facts into the top of working memory.
103
+
104
+ ---
105
+
106
+ ## Step 1 — [PROJECT-CONFIG] Load project-context.yaml
107
+
108
+ Read `.agent/project-context.yaml`. Extract and store:
109
+
110
+ **Tech Stack:**
111
+ - `tech_stack.language` → active language (e.g., Java 17, TypeScript, C#, Go)
112
+ - `tech_stack.framework` → active framework (e.g., Spring Boot 3.2, Angular 17, .NET 8)
113
+ - `tech_stack.build_tool` → build tool (e.g., Maven, npm, dotnet, go)
114
+ - `tech_stack.test_framework` → test framework (e.g., JUnit 5 + Mockito, Jest, xUnit)
115
+ - `tech_stack.database` → database (e.g., PostgreSQL, MySQL, MongoDB)
116
+ - `tech_stack.module` → active module profile (e.g., java-spring, angular, dotnet, golang, context-engineering)
117
+
118
+ **Conventions:**
119
+ - `conventions.build_command` → how to compile/build
120
+ - `conventions.test_command` → how to run tests
121
+ - `conventions.service_run` → how to start the service
122
+ - `conventions.ticket_prefix` → ticket ID prefix (e.g., PROJ, FEAT, UC)
123
+
124
+ **Domains:**
125
+ - `domains` → list of active business domains
126
+
127
+ **Paths (if present):**
128
+ - `paths.specs_dir` → BDD specs root
129
+ - `paths.prd_dir` → PRD documents root
130
+ - `paths.refinement_dir` → findings/review output dir
131
+ - `paths.product_definitions_dir` → product definitions root
132
+ - `paths.domain_knowledge_dir` → domain knowledge root
133
+ - `paths.business_dictionary` → path to business-dictionary.md
134
+ - `paths.core_entities` → path to core-entities.md
135
+ - `paths.tech_docs_dir` → technical documentation root
136
+ - `paths.trace_dir` → trace state directory
137
+
138
+ If `paths` section is absent, use these defaults:
139
+ - `specs_dir` = `specs/bdd`
140
+ - `prd_dir` = `specs/prd`
141
+ - `refinement_dir` = `.agent/review`
142
+ - `product_definitions_dir` = `specs/product-definition`
143
+ - `domain_knowledge_dir` = `specs/domain-knowledge`
144
+ - `business_dictionary` = `specs/domain-knowledge/business-dictionary.md`
145
+ - `core_entities` = `specs/domain-knowledge/core-entities.md`
146
+ - `tech_docs_dir` = `tech-docs`
147
+ - `trace_dir` = `.trace`
148
+
149
+ If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
150
+
151
+ ---
152
+
153
+ ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
154
+
155
+ If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
156
+ Merge framework-specific conventions (layer patterns, test patterns, naming rules) into the loaded context.
157
+ If the file does not exist → skip silently.
158
+
159
+ ---
160
+
161
+ ## Step 3 — [CRITICAL] Load CLAUDE.md
162
+
163
+ *This is the highest-priority context — it defines HOW to write code and documents for this project.*
164
+
165
+ Read `CLAUDE.md`. Extract and store:
166
+
167
+ - **§1 Project Overview** → project name, language, framework, build/test commands, domains
168
+ - **§2 Architecture** → layer order (e.g., Controller → Facade → Service → Repository), architectural rules
169
+ - **§3 Coding Standards** → naming conventions (classes, methods), response wrapper type, forbidden patterns
170
+ - **§5 Error Handling** → exception types, HTTP status code mapping, not-found exception class name
171
+ - **§7 Git Conventions** → branch naming pattern, commit message format
172
+
173
+ If `CLAUDE.md` does not exist → note it as missing and continue with project-context.yaml data only.
174
+
175
+ ---
176
+
177
+ ## Step 4 — [SAFETY] Load Data Protection Rules
178
+
179
+ Read `.agent/rules/data-protection.md` (or `rules/data-protection.md` from the framework installation).
180
+
181
+ Store the sensitive file patterns — you must **never** read, write, display, or reference content from files matching those patterns for the entire session.
182
+
183
+ If neither file exists → apply built-in defaults: never access `.env*`, `*.key`, `*.pem`, `*secret*`, `*password*`, `*credential*`.
184
+
185
+ ---
186
+
187
+ ## Step 5 — [DOMAIN] Load Business Dictionary (conditional)
188
+
189
+ Check if the business dictionary file exists (use `paths.business_dictionary` resolved in Step 1).
190
+
191
+ If it exists, read it and extract:
192
+ - **Canonical Terms** → complete list of approved terms and their definitions
193
+ - **Banned Terms** → complete list of banned terms and their canonical replacements
194
+ - **Status / Enum Registry** → allowed enum values per entity
195
+
196
+ Store the banned terms list for **active enforcement** throughout the command session:
197
+ - When generating any text (PRD, BDD, code comments, tech docs), verify no banned terms appear
198
+ - Replace banned terms with their canonical equivalents automatically
199
+
200
+ If the file does not exist → skip silently. Do not warn or block.
201
+
202
+ ---
203
+
204
+ ## Step 6 — [DOMAIN] Load Core Entities (conditional)
205
+
206
+ Check if the core entities file exists at `paths.core_entities` (resolved in Step 1).
207
+ Default path: `specs/domain-knowledge/core-entities.md`.
208
+
209
+ If it exists, read it and store:
210
+ - **Entity catalog** → for each entity: its name, purpose, owner service, key fields (name + type), business invariants, and relationships
211
+ - **Field name registry** → canonical field names to use in generated code and documents
212
+ - **Relationship map** → how entities relate to each other (1:N, N:N, embedded, etc.)
213
+
214
+ **How to use this catalog:**
215
+ - When generating code: use the field names, types, and relationships defined here — do NOT infer from existing code
216
+ - When generating PRD/BDD: reference entity names from this catalog for consistency
217
+ - When generating tech-docs: use this catalog as the source-of-truth for entity definitions
218
+
219
+ If the file does not exist → skip silently.
220
+
221
+ ---
222
+
223
+ ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
224
+
225
+ After loading all context, synthesize and output a compact summary block.
226
+ This recap ensures the most critical facts are stated at the END of context loading
227
+ (recency effect — freshest in working memory when the task begins).
228
+
229
+ Output exactly this block:
230
+ ```
231
+ [CTX LOADED]
232
+ Stack : {language} / {framework} / {database}
233
+ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Service → Repository}
234
+ Ticket : {ticket_prefix}-
235
+ Dict : {loaded — N canonical terms, M banned terms | missing}
236
+ Entities : {loaded — EntityA, EntityB, EntityC | missing}
237
+ Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
238
+ ```
239
+
240
+ If any CRITICAL file is missing (CLAUDE.md), flag it clearly so the user can decide whether to proceed.
241
+
242
+ ---
243
+
244
+ ## Context Load Complete
245
+
246
+ After completing all steps, you have loaded:
247
+ - Project identity, tech stack, module conventions
248
+ - Architecture rules and layer order ← **[CRITICAL — hold in working memory]**
249
+ - Coding standards and naming conventions ← **[CRITICAL — hold in working memory]**
250
+ - Data protection rules (sensitive file patterns to never access)
251
+ - Terminology rules with banned-term list ← **[DOMAIN — apply to every generated word]**
252
+ - Entity catalog (field names, types, invariants) ← **[DOMAIN — use for code generation]**
253
+ - All configured paths
254
+
255
+ Proceed to the next step of the calling command.
256
+
257
+
258
+ ---
259
+
260
+ ## Input — Paste one of:
261
+ 1. Stack trace / error log
262
+ 2. Test failure output
263
+ 3. File path + description of unexpected behavior
264
+ 4. A specific question about a code snippet
265
+
266
+ ## Stack Trace Analysis
267
+ Read from **bottom up** — `Caused by:` is the real root cause:
268
+ ```
269
+ Caused by: {RealException} ← start here
270
+ at {class}.{method}({file}:{line})
271
+ ```
272
+
273
+ ## Common Error Patterns
274
+
275
+ | Error | Likely Cause | Fix Direction |
276
+ |-------|-------------|---------------|
277
+ | NullPointerException | Null object access; Optional not handled | Check Optional.orElseThrow, null guards |
278
+ | ClassCastException | Wrong type assumption | Check type at assignment/return |
279
+ | OutOfMemoryError | Loading too much data | Add pagination |
280
+ | StackOverflowError | Infinite recursion | Find recursive call with no base case |
281
+ | Connection refused | Dependency not running | Check config URLs |
282
+ | 401 Unauthorized | Token expired, wrong config | Verify token, check auth config |
283
+ | 403 Forbidden | Wrong role | Check auth annotations |
284
+ | DB constraint violation | Duplicate key, null in NOT NULL | Check data and constraints |
285
+ | Serialization error | Circular reference | Check DTO/mapper config |
286
+ | Test assertion mismatch | Wrong mock or wrong expected | Re-read mock setup |
287
+
288
+ ## Test Failure Analysis
289
+ ```
290
+ Expected: {value}
291
+ Actual : {value}
292
+ at {test}.{method}(line {N})
293
+ ```
294
+ 1. What is the gap? 2. Is mock setup correct? 3. Is assertion logically correct?
295
+
296
+ ## Output
297
+
298
+ # Report Footer — Standard Command Output Format
299
+
300
+ Every command report must end with this standard footer section.
301
+
302
+ ## Status Badge
303
+
304
+ Choose one based on outcome:
305
+ - `✅ Complete` — all steps succeeded, no issues found
306
+ - `❌ Failed` — command could not complete due to a blocking error
307
+ - `⚠️ Warnings` — completed with non-blocking issues that should be reviewed
308
+
309
+ ## Output Artifacts
310
+
311
+ List every file created or modified by this command:
312
+ ```
313
+ Output Artifacts:
314
+ {created|updated} {file-path} ({brief description})
315
+ {created|updated} {file-path} ({brief description})
316
+ ```
317
+
318
+ If no files were written (e.g., review or analysis commands) → write `Output Artifacts: none (read-only)`.
319
+
320
+ ## Next Command Suggestion
321
+
322
+ Suggest the logical next command based on workflow phase:
323
+
324
+ | Current command | Suggest next |
325
+ |-------------------------|-----------------------------------------------|
326
+ | /define-product | `/generate-prd {product-definition-file}` |
327
+ | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
328
+ | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
329
+ | /review-context (PRD) | `/generate-bdd {prd-file}` if APPROVED; fix PRD if NEEDS_FIX |
330
+ | /generate-bdd | `/review-context {feature-file}` to verify coverage |
331
+ | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
332
+ | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
333
+ | /review-tech-docs | `/generate-code {feature-file}` if APPROVED; fix doc if NEEDS_FIX |
334
+ | /generate-code | `/generate-tests {UC-ID}` |
335
+ | /generate-tests | `/run-tests {UC-ID}` |
336
+ | /run-tests (passing) | `/review-code {UC-ID}` |
337
+ | /run-tests (failing) | `/fix-bug {ticket-id}` or `/debug {error}` |
338
+ | /review-code | `/smoke-test {UC-ID}` or create PR |
339
+ | /smoke-test | Create PR and link to ticket |
340
+ | /validate-traces | `/generate-code {UC-ID}` for gaps |
341
+ | /fix-bug | Create PR and link to ticket |
342
+ | /debug | `/fix-bug {ticket-id}` if fix needed |
343
+
344
+ Format the footer as:
345
+ ```
346
+ ---
347
+ Status : {badge}
348
+ {Output Artifacts block}
349
+ Next : {suggested command with example arguments}
350
+ ```
351
+
352
+
353
+ ```
354
+ /debug Analysis
355
+
356
+ ## Error
357
+ {description}
358
+
359
+ ## Root Cause
360
+ {technical explanation}
361
+
362
+ ## Location
363
+ File: {path} | Line: {N} | Layer: {Controller/Service/Repository/Test}
364
+
365
+ ## Suggested Fix
366
+ {specific code change}
367
+
368
+ ## Related Rule
369
+ See CLAUDE.md §{section}
370
+
371
+ ## Next Step
372
+ - To fully fix → /fix-bug {TICKET_ID}
373
+ - Just needed analysis → done
374
+ ```