@anhth2/spec-driven-dev-plugin 0.8.0 → 0.9.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 (93) hide show
  1. package/ARCHITECTURE.md +6 -2
  2. package/commands/debug.md +152 -0
  3. package/commands/debug.tmpl +16 -0
  4. package/commands/define-product.md +57 -0
  5. package/commands/fix-bug.md +153 -0
  6. package/commands/fix-bug.tmpl +17 -0
  7. package/commands/generate-bdd.md +277 -13
  8. package/commands/generate-bdd.tmpl +220 -13
  9. package/commands/generate-code.md +154 -2
  10. package/commands/generate-code.tmpl +97 -2
  11. package/commands/generate-design-spec.md +57 -0
  12. package/commands/generate-prd.md +114 -20
  13. package/commands/generate-prd.tmpl +57 -20
  14. package/commands/generate-spec-manifest.md +57 -0
  15. package/commands/generate-tech-docs.md +79 -1
  16. package/commands/generate-tech-docs.tmpl +22 -1
  17. package/commands/generate-tests.md +57 -0
  18. package/commands/learn.md +554 -0
  19. package/commands/learn.tmpl +63 -0
  20. package/commands/propose-scenario.md +521 -0
  21. package/commands/propose-scenario.tmpl +109 -0
  22. package/commands/refine-prd.md +66 -1
  23. package/commands/refine-prd.tmpl +9 -1
  24. package/commands/report-bug.md +543 -0
  25. package/commands/report-bug.tmpl +131 -0
  26. package/commands/review-code.md +153 -0
  27. package/commands/review-code.tmpl +17 -0
  28. package/commands/review-context.md +65 -0
  29. package/commands/review-context.tmpl +8 -0
  30. package/commands/review-tech-docs.md +146 -4
  31. package/commands/review-tech-docs.tmpl +89 -4
  32. package/commands/run-tests.md +82 -0
  33. package/commands/run-tests.tmpl +25 -0
  34. package/commands/setup-ai-first.md +15 -5
  35. package/commands/setup-ai-first.tmpl +10 -5
  36. package/commands/smoke-test.md +57 -0
  37. package/commands/sync.md +405 -0
  38. package/commands/sync.tmpl +345 -0
  39. package/commands/update-framework.md +211 -0
  40. package/commands/update-framework.tmpl +151 -0
  41. package/commands/validate-traces.md +115 -2
  42. package/commands/validate-traces.tmpl +58 -2
  43. package/core/FRAMEWORK_VERSION +1 -1
  44. package/core/commands/debug.md +152 -0
  45. package/core/commands/define-product.md +57 -0
  46. package/core/commands/fix-bug.md +153 -0
  47. package/core/commands/generate-bdd.md +277 -13
  48. package/core/commands/generate-code.md +154 -2
  49. package/core/commands/generate-design-spec.md +57 -0
  50. package/core/commands/generate-prd.md +114 -20
  51. package/core/commands/generate-spec-manifest.md +57 -0
  52. package/core/commands/generate-tech-docs.md +79 -1
  53. package/core/commands/generate-tests.md +57 -0
  54. package/core/commands/learn.md +554 -0
  55. package/core/commands/propose-scenario.md +521 -0
  56. package/core/commands/refine-prd.md +66 -1
  57. package/core/commands/report-bug.md +543 -0
  58. package/core/commands/review-code.md +153 -0
  59. package/core/commands/review-context.md +65 -0
  60. package/core/commands/review-tech-docs.md +146 -4
  61. package/core/commands/run-tests.md +82 -0
  62. package/core/commands/setup-ai-first.md +15 -5
  63. package/core/commands/smoke-test.md +57 -0
  64. package/core/commands/sync.md +405 -0
  65. package/core/commands/update-framework.md +211 -0
  66. package/core/commands/validate-traces.md +115 -2
  67. package/core/skills/code/SKILL.md +62 -0
  68. package/core/skills/debug/SKILL.md +67 -0
  69. package/core/skills/design-spec/SKILL.md +57 -0
  70. package/core/skills/discovery/SKILL.md +57 -0
  71. package/core/skills/prd/SKILL.md +10 -0
  72. package/core/skills/setup-ai-first/SKILL.md +5 -0
  73. package/core/skills/spec/SKILL.md +10 -0
  74. package/core/skills/test/SKILL.md +119 -0
  75. package/core/steps/capture-lesson.md +79 -0
  76. package/core/steps/context-loader.md +52 -0
  77. package/core/steps/report-footer.md +5 -0
  78. package/core/templates/prd.template.md +35 -20
  79. package/core/templates/project-context.yaml +11 -0
  80. package/package.json +9 -2
  81. package/skills/code/SKILL.md +62 -0
  82. package/skills/debug/SKILL.md +67 -0
  83. package/skills/design-spec/SKILL.md +57 -0
  84. package/skills/discovery/SKILL.md +57 -0
  85. package/skills/prd/SKILL.md +10 -0
  86. package/skills/setup-ai-first/SKILL.md +5 -0
  87. package/skills/spec/SKILL.md +10 -0
  88. package/skills/test/SKILL.md +119 -0
  89. package/steps/capture-lesson.md +79 -0
  90. package/steps/context-loader.md +52 -0
  91. package/steps/report-footer.md +5 -0
  92. package/templates/prd.template.md +35 -20
  93. package/templates/project-context.yaml +11 -0
@@ -0,0 +1,554 @@
1
+ # /learn — Record a Project Lesson (Guardrail)
2
+
3
+ Capture a mistake the AI keeps making so it is **not repeated**. The lesson is stored in this
4
+ project's lessons file and loaded into context at the start of every command.
5
+
6
+ Usage: `/learn {free-text}` — ideally phrased as "AI does X, should do Y".
7
+ Example: `/learn AI keeps calling the repository directly from controllers — it must go through the service layer`
8
+
9
+ > This is **project memory**, not model fine-tuning. The lesson becomes an active guardrail by
10
+ > being injected into context on every run (see context-loader Step 6.7).
11
+
12
+ ## Gate
13
+ # Gate — Universal Entry Procedure
14
+
15
+ Every command must execute this gate before proceeding with its specific logic.
16
+
17
+ ## Step 0 — Sub-Agent Mode Check
18
+
19
+ Before anything else, check if `$ARGUMENTS` is a JSON payload from an orchestrator:
20
+
21
+ 1. Attempt to parse `$ARGUMENTS` as JSON.
22
+ 2. If it parses successfully **and** contains `"_agent_mode": true`:
23
+ - **Skip Steps 1, 2, and 3 of this Gate entirely.**
24
+ - Set target file = `payload.target_file`
25
+ - Set loaded context = `payload.context` (do NOT run context-loader.md)
26
+ - Set UC scope = `payload.uc_id` (process only this UC)
27
+ - Set line range = `payload.uc_section` (read only that PRD section)
28
+ - Proceed directly to the command-specific logic.
29
+ 3. If `$ARGUMENTS` is not JSON or `_agent_mode` is absent → continue to Step 1 (normal mode).
30
+
31
+ ## Step 0-B — Model Check
32
+
33
+ *Skip this step if `_agent_mode: true` (sub-agent — orchestrator already validated).*
34
+
35
+ Complex generation and review commands require strong reasoning.
36
+ Using a smaller model risks missed edge cases, incomplete spec analysis, and architecture violations.
37
+
38
+ Display and wait for response:
39
+
40
+ ```
41
+ ⚙️ MODEL CHECK
42
+ ──────────────────────────────────────────────────────────────────
43
+ Recommended : claude-opus-4 (or latest Opus model)
44
+ Why needed : Spec analysis, architecture review, code generation
45
+ require deep reasoning. Smaller models miss edge cases.
46
+
47
+ To switch in Claude Code:
48
+ • Settings → Model → select "claude-opus"
49
+ • or: /model → choose claude-opus
50
+
51
+ Running on claude-opus?
52
+ Y — yes, on claude-opus → proceed
53
+ S — skip check (I accept lower quality risk with current model)
54
+ ──────────────────────────────────────────────────────────────────
55
+ ```
56
+
57
+ - "Y" → proceed to Step 1.
58
+ - "S" → proceed to Step 1 (user accepts risk, add ⚠️ to final report).
59
+ - "N" or anything else → **STOP.** Output: "Please switch to claude-opus, then re-run this command."
60
+
61
+ ## Step 1 — Resolve Target File
62
+
63
+ 1. If `$ARGUMENTS` is provided and points to an existing file → use it directly as the target.
64
+ 2. If `$ARGUMENTS` is a UC-ID, ticket ID, or partial name → search for matching files in the relevant directory.
65
+ 3. If `$ARGUMENTS` is empty or no match found:
66
+ - List files in the relevant directory for this command (e.g., `specs/prd/**/*.md` for PRD commands, `specs/bdd/**/*.feature` for BDD commands).
67
+ - Present the list to the user and ask: "Which file do you want to work with? (Enter number or filename)"
68
+ - Wait for user selection before continuing.
69
+
70
+ ## Step 2 — Execute Context Loader
71
+
72
+ Load all project context by following the procedure in `steps/context-loader.md`.
73
+ Store all loaded context in memory for use throughout this command session.
74
+
75
+ ## Step 3 — CHECKPOINT
76
+
77
+ After completing Steps 1 and 2, display a summary and wait for confirmation:
78
+
79
+ ```
80
+ CHECKPOINT
81
+ -----------
82
+ Target : {resolved file path}
83
+ Project : {project.name from project-context.yaml}
84
+ Tech stack : {language} / {framework}
85
+ Module : {module if set, else "not configured"}
86
+ Domains : {comma-separated domain list}
87
+
88
+ Proceed? (Y/N)
89
+ ```
90
+
91
+ Wait for explicit "Y" or "N" from the user before continuing.
92
+ - "Y" → proceed to the command-specific steps below.
93
+ - "N" → stop and ask what the user wants to change.
94
+
95
+
96
+ *Note: For this command — skip Gate Step 1 (no target file). The "target" is the lesson text in `$ARGUMENTS`. Run the model check and context loading, then proceed.*
97
+
98
+ ## Context
99
+ # Context Loader — Load All Project Context
100
+
101
+ Execute these steps in order. Store everything in memory for the duration of the command session.
102
+
103
+ **Priority guide (anti-lost-in-middle):**
104
+ - Steps 1–2 are PROJECT-CONFIG — loaded first, resolve all paths and metadata.
105
+ - Step 3 is CRITICAL — architecture + coding standards, the highest-priority facts for generation.
106
+ - Step 4 is SAFETY — data protection rules, enforced silently for the entire session.
107
+ - Steps 5–6 are DOMAIN KNOWLEDGE — terminology and entity definitions.
108
+ - Step 7 is the WORKING MEMORY RECAP — locks critical facts into the top of working memory.
109
+
110
+ ---
111
+
112
+ ## Step 1 — [PROJECT-CONFIG] Load project-context.yaml
113
+
114
+ Read `.agent/project-context.yaml`. Extract and store:
115
+
116
+ **Tech Stack:**
117
+ - `tech_stack.language` → active language (e.g., Java 17, TypeScript, C#, Go)
118
+ - `tech_stack.framework` → active framework (e.g., Spring Boot 3.2, Angular 17, .NET 8)
119
+ - `tech_stack.build_tool` → build tool (e.g., Maven, npm, dotnet, go)
120
+ - `tech_stack.test_framework` → test framework (e.g., JUnit 5 + Mockito, Jest, xUnit)
121
+ - `tech_stack.database` → database (e.g., PostgreSQL, MySQL, MongoDB)
122
+ - `tech_stack.module` → active module profile (e.g., java-spring, angular, dotnet, golang, context-engineering)
123
+
124
+ **Conventions:**
125
+ - `conventions.build_command` → how to compile/build
126
+ - `conventions.test_command` → how to run tests
127
+ - `conventions.service_run` → how to start the service
128
+ - `conventions.ticket_prefix` → ticket ID prefix (e.g., PROJ, FEAT, UC)
129
+
130
+ **Domains:**
131
+ - `domains` → list of active business domains
132
+
133
+ **Paths (if present):**
134
+ - `paths.specs_dir` → BDD specs root
135
+ - `paths.prd_dir` → PRD documents root
136
+ - `paths.refinement_dir` → findings/review output dir
137
+ - `paths.product_definitions_dir` → product definitions root
138
+ - `paths.domain_knowledge_dir` → domain knowledge root
139
+ - `paths.business_dictionary` → path to business-dictionary.md
140
+ - `paths.core_entities` → path to core-entities.md
141
+ - `paths.tech_docs_dir` → technical documentation root
142
+ - `paths.trace_dir` → trace state directory
143
+ - `paths.design_spec_dir` → Design Spec documents root (FE/App only)
144
+
145
+ If `paths` section is absent, use these defaults:
146
+ - `specs_dir` = `specs/bdd`
147
+ - `prd_dir` = `specs/prd`
148
+ - `refinement_dir` = `.agent/review`
149
+ - `product_definitions_dir` = `specs/product-definition`
150
+ - `domain_knowledge_dir` = `specs/domain-knowledge`
151
+ - `business_dictionary` = `specs/domain-knowledge/business-dictionary.md`
152
+ - `core_entities` = `specs/domain-knowledge/core-entities.md`
153
+ - `tech_docs_dir` = `specs/tech-docs`
154
+ - `trace_dir` = `.trace`
155
+ - `design_spec_dir` = `specs/design-spec`
156
+
157
+ If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
158
+
159
+ ---
160
+
161
+ ## Step 1.5 — [SERVICE ROUTING] Resolve service paths (umbrella mode)
162
+
163
+ *Skip this step entirely if `setup.mode` is not `"umbrella"` and `services` section is absent from project-context.yaml.*
164
+
165
+ If `services` section is present:
166
+
167
+ **1. Detect active domain** (in priority order):
168
+ - Read `@trace.domain` from target file frontmatter (if Gate loaded a target file)
169
+ - Extract from target file path: segment immediately after `prd_dir` base path
170
+ *(e.g., `specs/prd/user/FEAT-01.md` → domain = `user`)*
171
+ - If `$ARGUMENTS` contains a path, extract the segment after `prd_dir`
172
+
173
+ **2. Route to service** — if active domain matches a key in `services`:
174
+ - Override `paths.specs_dir` → `services.{domain}.specs_dir`
175
+ - Override `paths.tech_docs_dir` → `services.{domain}.tech_docs_dir`
176
+ - Store `active_service` = `services.{domain}.path`
177
+ - Store `active_service_module` = `services.{domain}.module`
178
+ - If service has its own `module` → use it as `active_module` (overrides `tech_stack.module`)
179
+
180
+ **3. Fallback** — if domain not detected or no matching service key:
181
+ - Keep default paths from Step 1
182
+ - Set `active_service = unresolved`
183
+
184
+ **4. Spec source auto-override** — if `setup.spec_source` is set AND the corresponding path was not already explicitly set in `paths:`:
185
+ - Override `paths.prd_dir` → `{spec_source}/specs/prd`
186
+ - Override `paths.design_spec_dir` → `{spec_source}/specs/design-spec`
187
+ - Override `paths.domain_knowledge_dir` → `{spec_source}/specs/domain-knowledge`
188
+ - Override `paths.business_dictionary` → `{spec_source}/specs/domain-knowledge/business-dictionary.md`
189
+ - Override `paths.core_entities` → `{spec_source}/specs/domain-knowledge/core-entities.md`
190
+ - Override `paths.bug_reports_dir` → `{spec_source}/feedback/bug-reports`
191
+ - Override `paths.bdd_proposals_dir` → `{spec_source}/feedback/bdd-proposals`
192
+
193
+ > **Why under `spec_source`:** tester feedback (`/report-bug`, `/propose-scenario`) must land in the **shared spec repo** so PO/Dev see it when they `/sync`. In single-service mode (no `spec_source`), these default to `feedback/bug-reports` and `feedback/bdd-proposals` at repo root — still shared, same repo.
194
+
195
+ ---
196
+
197
+ ## Step 1.6 — [SERVICE CONVENTIONS] Load service-specific conventions (umbrella mode)
198
+
199
+ *Skip this step entirely if `active_service` is `"unresolved"` or context is single-service mode.*
200
+
201
+ When `active_service` has been resolved to a real path in Step 1.5 (e.g., `user-service/`):
202
+
203
+ **1. Locate service config** — try in priority order:
204
+ - `{active_service}/.agent/project-context.yaml`
205
+ - `{active_service}/project-context.yaml`
206
+
207
+ **2. If found, override with service-specific values:**
208
+
209
+ | Variable | Source |
210
+ |----------|--------|
211
+ | `conventions.test_command` | service's `conventions.test_command` |
212
+ | `conventions.build_command` | service's `conventions.build_command` |
213
+ | `paths.trace_dir` | `{active_service}/{service paths.trace_dir}` — default: `{active_service}/.trace` |
214
+ | `paths.specs_dir` | `{active_service}/{service paths.specs_dir}` (if set in service config, else keep Step 1.5 override) |
215
+
216
+ **3. Store** `service_root = {active_service}` as the working directory anchor for all downstream commands:
217
+ - Shell commands (`/run-tests`, `/generate-tests`) run **from within** `service_root`
218
+ - File write operations (test files, trace TSVs) use paths **relative to** `service_root`
219
+
220
+ **4. If service config not found** — keep umbrella defaults, still set `service_root = {active_service}` (path anchor is always needed even without a config override).
221
+
222
+ ---
223
+
224
+ ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
225
+
226
+ If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
227
+ Merge framework-specific conventions (layer patterns, test patterns, naming rules) into the loaded context.
228
+ If the file does not exist → skip silently.
229
+
230
+ ---
231
+
232
+ ## Step 3 — [CRITICAL] Load CLAUDE.md
233
+
234
+ *This is the highest-priority context — it defines HOW to write code and documents for this project.*
235
+
236
+ Read `CLAUDE.md`. Extract and store:
237
+
238
+ - **§1 Project Overview** → project name, language, framework, build/test commands, domains
239
+ - **§2 Architecture** → layer order (e.g., Controller → Facade → Service → Repository), architectural rules
240
+ - **§3 Coding Standards** → naming conventions (classes, methods), response wrapper type, forbidden patterns
241
+ - **§5 Error Handling** → exception types, HTTP status code mapping, not-found exception class name
242
+ - **§7 Git Conventions** → branch naming pattern, commit message format
243
+
244
+ If `CLAUDE.md` does not exist → note it as missing and continue with project-context.yaml data only.
245
+
246
+ ---
247
+
248
+ ## Step 4 — [SAFETY] Load Data Protection Rules
249
+
250
+ Read `.agent/rules/data-protection.md` (or `rules/data-protection.md` from the framework installation).
251
+
252
+ Store the sensitive file patterns — you must **never** read, write, display, or reference content from files matching those patterns for the entire session.
253
+
254
+ If neither file exists → apply built-in defaults: never access `.env*`, `*.key`, `*.pem`, `*secret*`, `*password*`, `*credential*`.
255
+
256
+ ---
257
+
258
+ ## Step 5 — [DOMAIN] Load Business Dictionary (conditional)
259
+
260
+ Check if the business dictionary file exists (use `paths.business_dictionary` resolved in Step 1).
261
+
262
+ If it exists, read it and extract:
263
+ - **Canonical Terms** → complete list of approved terms and their definitions
264
+ - **Banned Terms** → complete list of banned terms and their canonical replacements
265
+ - **Status / Enum Registry** → allowed enum values per entity
266
+
267
+ Store the banned terms list for **active enforcement** throughout the command session:
268
+ - When generating any text (PRD, BDD, code comments, tech docs), verify no banned terms appear
269
+ - Replace banned terms with their canonical equivalents automatically
270
+
271
+ If the file does not exist → skip silently. Do not warn or block.
272
+
273
+ ---
274
+
275
+ ## Step 6 — [DOMAIN] Load Core Entities (conditional)
276
+
277
+ Check if the core entities file exists at `paths.core_entities` (resolved in Step 1).
278
+ Default path: `specs/domain-knowledge/core-entities.md`.
279
+
280
+ If it exists, read it and store:
281
+ - **Entity catalog** → for each entity: its name, purpose, owner service, key fields (name + type), business invariants, and relationships
282
+ - **Field name registry** → canonical field names to use in generated code and documents
283
+ - **Relationship map** → how entities relate to each other (1:N, N:N, embedded, etc.)
284
+
285
+ **How to use this catalog:**
286
+ - When generating code: use the field names, types, and relationships defined here — do NOT infer from existing code
287
+ - When generating PRD/BDD: reference entity names from this catalog for consistency
288
+ - When generating tech-docs: use this catalog as the source-of-truth for entity definitions
289
+
290
+ If the file does not exist → skip silently.
291
+
292
+ ---
293
+
294
+ ## Step 6.5 — [PLATFORM] Derive active_module and platform_type
295
+
296
+ Using `tech_stack.module` loaded in Step 1, derive and store two variables for use by all downstream commands:
297
+
298
+ ```
299
+ active_module = tech_stack.module (e.g. "java-spring", "react", "flutter")
300
+ ```
301
+
302
+ | `platform_type` | Modules |
303
+ |---|---|
304
+ | `backend` | `java-spring`, `golang`, `dotnet`, `php-laravel`, `context-engineering` |
305
+ | `web-frontend` | `react`, `nextjs`, `vue`, `nuxt`, `angular` |
306
+ | `mobile` | `flutter`, `react-native`, `ios-swiftui`, `android-compose` |
307
+
308
+ If `tech_stack.module` is blank or not recognized → set `platform_type = "unknown"` and flag as ⚠️ in the Step 7 recap.
309
+
310
+ These two variables (`active_module`, `platform_type`) are the canonical source for all branching logic in commands that need platform-specific behavior (generate-tests, debug, fix-bug, smoke-test).
311
+
312
+ ---
313
+
314
+ ## Step 6.7 — [GUARDRAILS] Load Project Lessons (conditional)
315
+
316
+ *Accumulated mistakes the AI must not repeat in this project. These are added over time via `/learn`
317
+ or accepted during `/review-code`, `/fix-bug`, `/debug`.*
318
+
319
+ Resolve the lessons file path:
320
+ - Use `paths.lessons_file` if set (may be service-overridden in umbrella mode, Step 1.6)
321
+ - Else default `specs/domain-knowledge/lessons-learned.md`
322
+ - In umbrella/service mode (when `service_root` is set), if `paths.lessons_file` is unset, default to `{service_root}/.agent/project-lessons.md`
323
+
324
+ If the file exists, read it and store ALL lessons as **ACTIVE GUARDRAILS** for the session:
325
+ - Treat each lesson's **Rule** as a hard constraint — same priority as CLAUDE.md coding standards (Step 3).
326
+ - Before generating or modifying any artifact (PRD, BDD, tech-doc, code, test), check the output against every lesson whose `category` matches the current command AND whose `scope` matches the target (domain / file).
327
+ - If a generated output would violate a lesson → correct it **before** presenting, and note which lesson (`L-NNN`) was applied.
328
+
329
+ If the file does not exist → skip silently (no lessons captured yet).
330
+
331
+ ---
332
+
333
+ ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
334
+
335
+ After loading all context, synthesize and output a compact summary block.
336
+ This recap ensures the most critical facts are stated at the END of context loading
337
+ (recency effect — freshest in working memory when the task begins).
338
+
339
+ Output exactly this block:
340
+ ```
341
+ [CTX LOADED]
342
+ Stack : {language} / {framework} / {database}
343
+ Platform : {active_module} ({platform_type})
344
+ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Service → Repository}
345
+ Ticket : {ticket_prefix}-
346
+ Dict : {loaded — N canonical terms, M banned terms | missing}
347
+ Entities : {loaded — EntityA, EntityB, EntityC | missing}
348
+ Lessons : {loaded — N guardrails | none yet}
349
+ Service : {active_service} ({active_service_module}) | single-service
350
+ Svc Root : {service_root} — conventions + trace_dir loaded from service config | —
351
+ Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
352
+ ```
353
+
354
+ If any CRITICAL file is missing (CLAUDE.md), flag it clearly so the user can decide whether to proceed.
355
+
356
+ ---
357
+
358
+ ## Context Load Complete
359
+
360
+ After completing all steps, you have loaded:
361
+ - Project identity, tech stack, module conventions
362
+ - Architecture rules and layer order ← **[CRITICAL — hold in working memory]**
363
+ - Coding standards and naming conventions ← **[CRITICAL — hold in working memory]**
364
+ - Data protection rules (sensitive file patterns to never access)
365
+ - Terminology rules with banned-term list ← **[DOMAIN — apply to every generated word]**
366
+ - Entity catalog (field names, types, invariants) ← **[DOMAIN — use for code generation]**
367
+ - All configured paths
368
+
369
+ Proceed to the next step of the calling command.
370
+
371
+
372
+ ---
373
+
374
+ ## Step 1 — Parse the Lesson
375
+
376
+ Read `$ARGUMENTS` as a free-text description.
377
+
378
+ Split it into a **mistake** (what the AI did wrong) and a **rule** (the imperative correction).
379
+ - If `$ARGUMENTS` is empty or too vague to split, ask the user briefly:
380
+ ```
381
+ Record a project lesson. Answer 2 things:
382
+ 1. What did the AI get wrong? (the mistake)
383
+ 2. What is the correct rule? (imperative — "Always…/Never…")
384
+ ```
385
+ - Infer `category` (code-gen | bdd | tech-docs | tests | prd | general) and `scope` (domain / file glob / all)
386
+ from the description. If ambiguous, confirm with the user in one line.
387
+
388
+ Show the parsed lesson and ask `Save this lesson? (Y/N)` before writing.
389
+
390
+ ## Step 2 — Capture
391
+
392
+ # Capture Lesson — Record a Recurring Mistake as a Guardrail
393
+
394
+ Reusable procedure to persist a "lesson" so the AI does not repeat a mistake in this project.
395
+ Used by `/learn` (manual) and offered by `/review-code`, `/fix-bug`, `/debug` (auto).
396
+
397
+ > **Project memory, not model training.** A lesson is plain text injected into context at the
398
+ > start of every command (context-loader Step 6.7). Functionally this stops the repeat — the AI
399
+ > sees the guardrail before it generates. No model weights change.
400
+
401
+ ## L1 — Resolve the lessons file
402
+
403
+ Resolve `lessons_path` in this order:
404
+ 1. `paths.lessons_file` from loaded context (may be service-overridden in umbrella mode, Step 1.6)
405
+ 2. Default `specs/domain-knowledge/lessons-learned.md` (single-service)
406
+ 3. In umbrella/service mode (when `service_root` is set) default `{service_root}/.agent/project-lessons.md`
407
+
408
+ ## L2 — Build the lesson
409
+
410
+ Gather these fields — from `$ARGUMENTS` (for `/learn`) or from the calling command's findings
411
+ (for `/review-code`, `/fix-bug`, `/debug`):
412
+
413
+ | Field | Meaning |
414
+ |-------|---------|
415
+ | `category` | one of: `code-gen` \| `bdd` \| `tech-docs` \| `tests` \| `prd` \| `general` |
416
+ | `title` | short phrase naming the mistake |
417
+ | `mistake` | concretely, what the AI did wrong |
418
+ | `rule` | imperative correction — "Always …" / "Never …" — testable, not vague |
419
+ | `scope` | where it applies: a domain, a file glob (e.g. `*Controller.*`), or `all` |
420
+ | `source` | how captured: `/learn` \| `/review-code {UC-ID}` \| `/fix-bug {TICKET}` \| `/debug` |
421
+
422
+ If `rule` is vague (e.g. "be careful"), rewrite it into a concrete, checkable instruction before saving.
423
+
424
+ ## L3 — De-duplicate
425
+
426
+ Read existing lessons in `lessons_path`. If one already covers the same mistake:
427
+ - **Refine** that entry (tighten the Rule, widen/narrow Scope, bump Date, append the new Source) — do NOT add a duplicate.
428
+
429
+ Otherwise assign the next id `L-{NNN}` = (highest existing number + 1), zero-padded to 3 digits.
430
+
431
+ ## L4 — Write
432
+
433
+ If `lessons_path` does not exist, create it with this header first:
434
+
435
+ ```markdown
436
+ # Project Lessons — Learned Guardrails
437
+
438
+ > Mistakes the AI must NOT repeat in this project. Loaded by context-loader at the start of
439
+ > every command and treated as hard constraints (same priority as CLAUDE.md coding standards).
440
+ > Add with /learn, or accept the prompt during /review-code, /fix-bug, /debug.
441
+ > Commit this file so the whole team shares the guardrails.
442
+
443
+ | Category | Applies to |
444
+ |----------|-----------|
445
+ | code-gen | /generate-code output |
446
+ | bdd | /generate-bdd output |
447
+ | tech-docs | /generate-tech-docs output |
448
+ | tests | /generate-tests output |
449
+ | prd | /generate-prd, /refine-prd output |
450
+ | general | every command |
451
+
452
+ ---
453
+ ```
454
+
455
+ Insert the new lesson directly under the `---` separator (**newest first**), in this exact shape:
456
+
457
+ ```markdown
458
+ ### L-{NNN} — [{category}] {title}
459
+ - **Date**: {today YYYY-MM-DD}
460
+ - **Scope**: {scope}
461
+ - **Mistake**: {mistake}
462
+ - **Rule**: {rule}
463
+ - **Source**: {source}
464
+
465
+ ```
466
+
467
+ ## L5 — Confirm
468
+
469
+ Print: `📝 Lesson {id} recorded → {lessons_path} ([{category}] {title})`
470
+ Then remind: `Commit {lessons_path} so the team shares this guardrail.`
471
+
472
+
473
+ ---
474
+
475
+ ## Output
476
+
477
+ # Report Footer — Standard Command Output Format
478
+
479
+ Every command report must end with this standard footer section.
480
+
481
+ ## Status Badge
482
+
483
+ Choose one based on outcome:
484
+ - `✅ Complete` — all steps succeeded, no issues found
485
+ - `❌ Failed` — command could not complete due to a blocking error
486
+ - `⚠️ Warnings` — completed with non-blocking issues that should be reviewed
487
+
488
+ ## Output Artifacts
489
+
490
+ List every file created or modified by this command:
491
+ ```
492
+ Output Artifacts:
493
+ {created|updated} {file-path} ({brief description})
494
+ {created|updated} {file-path} ({brief description})
495
+ ```
496
+
497
+ If no files were written (e.g., review or analysis commands) → write `Output Artifacts: none (read-only)`.
498
+
499
+ ## Next Command Suggestion
500
+
501
+ Suggest the logical next command based on workflow phase:
502
+
503
+ | Current command | Suggest next |
504
+ |-------------------------|-----------------------------------------------|
505
+ | /setup-ai-first | `/define-product` to start your first feature |
506
+ | /define-product | `/generate-prd {product-definition-file}` |
507
+ | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
508
+ | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
509
+ | /review-context (PRD) | FE/App: `/generate-design-spec {prd-file}` (then BDD after sign-off); BE: `/generate-bdd {prd-file}` directly; fix PRD if NEEDS_FIX |
510
+ | /generate-design-spec | Designer review → Figma links confirmed → PO + Designer sign-off → `/generate-bdd {prd-file}` |
511
+ | /generate-bdd | `/review-context {feature-file}` to verify coverage |
512
+ | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
513
+ | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
514
+ | /review-tech-docs | `/generate-code {feature-file}` if APPROVED; fix doc if NEEDS_FIX |
515
+ | /generate-code | First gen → `/review-code {UC-ID}`; re-gen → `/generate-tests {UC-ID}` |
516
+ | /generate-tests | `/run-tests {UC-ID}` |
517
+ | /run-tests (passing) | `/review-code {UC-ID}` |
518
+ | /run-tests (failing) | `/fix-bug {ticket-id}` or `/debug {error}` |
519
+ | /review-code | `/smoke-test {UC-ID}` or create PR |
520
+ | /smoke-test | Create PR and link to ticket |
521
+ | /validate-traces | DRIFT/UNTRACKED → `/generate-code {UC-ID}`; GAP → `/generate-tests {UC-ID}`; all OK → create PR |
522
+ | /fix-bug | Create PR and link to ticket |
523
+ | /debug | `/fix-bug {ticket-id}` if fix needed |
524
+ | /report-bug | Send to dev (`/fix-bug {BUG-ID}`); if coverage gap → `/propose-scenario {UC-ID}` |
525
+ | /propose-scenario | Notify PO/Dev to review the proposal in `feedback/bdd-proposals/` |
526
+ | /learn | Continue working — lesson applies on next command |
527
+ | /sync | `/validate-traces` for full coverage; act on any `📥 tester feedback` surfaced |
528
+ | /update-framework | Review `git diff .agent/`, commit; `/sync` for project content |
529
+
530
+ Format the footer as:
531
+ ```
532
+ ---
533
+ Status : {badge}
534
+ {Output Artifacts block}
535
+ Next : {suggested command with example arguments}
536
+ ```
537
+
538
+
539
+ ```
540
+ /learn — lesson recorded
541
+
542
+ 📝 {id} — [{category}] {title}
543
+ Rule : {rule}
544
+ Scope : {scope}
545
+ File : {lessons_path}
546
+
547
+ This guardrail is now loaded at the start of every command.
548
+ Commit {lessons_path} so your team shares it.
549
+
550
+ ---
551
+ Status : ✅ Complete
552
+ Output Artifacts: updated {lessons_path}
553
+ Next : continue working — the AI will respect this lesson from now on
554
+ ```
@@ -0,0 +1,63 @@
1
+ # /learn — Record a Project Lesson (Guardrail)
2
+
3
+ Capture a mistake the AI keeps making so it is **not repeated**. The lesson is stored in this
4
+ project's lessons file and loaded into context at the start of every command.
5
+
6
+ Usage: `/learn {free-text}` — ideally phrased as "AI does X, should do Y".
7
+ Example: `/learn AI keeps calling the repository directly from controllers — it must go through the service layer`
8
+
9
+ > This is **project memory**, not model fine-tuning. The lesson becomes an active guardrail by
10
+ > being injected into context on every run (see context-loader Step 6.7).
11
+
12
+ ## Gate
13
+ {{include:steps/gate.md}}
14
+
15
+ *Note: For this command — skip Gate Step 1 (no target file). The "target" is the lesson text in `$ARGUMENTS`. Run the model check and context loading, then proceed.*
16
+
17
+ ## Context
18
+ {{include:steps/context-loader.md}}
19
+
20
+ ---
21
+
22
+ ## Step 1 — Parse the Lesson
23
+
24
+ Read `$ARGUMENTS` as a free-text description.
25
+
26
+ Split it into a **mistake** (what the AI did wrong) and a **rule** (the imperative correction).
27
+ - If `$ARGUMENTS` is empty or too vague to split, ask the user briefly:
28
+ ```
29
+ Record a project lesson. Answer 2 things:
30
+ 1. What did the AI get wrong? (the mistake)
31
+ 2. What is the correct rule? (imperative — "Always…/Never…")
32
+ ```
33
+ - Infer `category` (code-gen | bdd | tech-docs | tests | prd | general) and `scope` (domain / file glob / all)
34
+ from the description. If ambiguous, confirm with the user in one line.
35
+
36
+ Show the parsed lesson and ask `Save this lesson? (Y/N)` before writing.
37
+
38
+ ## Step 2 — Capture
39
+
40
+ {{include:steps/capture-lesson.md}}
41
+
42
+ ---
43
+
44
+ ## Output
45
+
46
+ {{include:steps/report-footer.md}}
47
+
48
+ ```
49
+ /learn — lesson recorded
50
+
51
+ 📝 {id} — [{category}] {title}
52
+ Rule : {rule}
53
+ Scope : {scope}
54
+ File : {lessons_path}
55
+
56
+ This guardrail is now loaded at the start of every command.
57
+ Commit {lessons_path} so your team shares it.
58
+
59
+ ---
60
+ Status : ✅ Complete
61
+ Output Artifacts: updated {lessons_path}
62
+ Next : continue working — the AI will respect this lesson from now on
63
+ ```