@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,163 @@
1
+ # Context Loader — Load All Project Context
2
+
3
+ Execute these steps in order. Store everything in memory for the duration of the command session.
4
+
5
+ **Priority guide (anti-lost-in-middle):**
6
+ - Steps 1–2 are PROJECT-CONFIG — loaded first, resolve all paths and metadata.
7
+ - Step 3 is CRITICAL — architecture + coding standards, the highest-priority facts for generation.
8
+ - Step 4 is SAFETY — data protection rules, enforced silently for the entire session.
9
+ - Steps 5–6 are DOMAIN KNOWLEDGE — terminology and entity definitions.
10
+ - Step 7 is the WORKING MEMORY RECAP — locks critical facts into the top of working memory.
11
+
12
+ ---
13
+
14
+ ## Step 1 — [PROJECT-CONFIG] Load project-context.yaml
15
+
16
+ Read `.agent/project-context.yaml`. Extract and store:
17
+
18
+ **Tech Stack:**
19
+ - `tech_stack.language` → active language (e.g., Java 17, TypeScript, C#, Go)
20
+ - `tech_stack.framework` → active framework (e.g., Spring Boot 3.2, Angular 17, .NET 8)
21
+ - `tech_stack.build_tool` → build tool (e.g., Maven, npm, dotnet, go)
22
+ - `tech_stack.test_framework` → test framework (e.g., JUnit 5 + Mockito, Jest, xUnit)
23
+ - `tech_stack.database` → database (e.g., PostgreSQL, MySQL, MongoDB)
24
+ - `tech_stack.module` → active module profile (e.g., java-spring, angular, dotnet, golang, context-engineering)
25
+
26
+ **Conventions:**
27
+ - `conventions.build_command` → how to compile/build
28
+ - `conventions.test_command` → how to run tests
29
+ - `conventions.service_run` → how to start the service
30
+ - `conventions.ticket_prefix` → ticket ID prefix (e.g., PROJ, FEAT, UC)
31
+
32
+ **Domains:**
33
+ - `domains` → list of active business domains
34
+
35
+ **Paths (if present):**
36
+ - `paths.specs_dir` → BDD specs root
37
+ - `paths.prd_dir` → PRD documents root
38
+ - `paths.refinement_dir` → findings/review output dir
39
+ - `paths.product_definitions_dir` → product definitions root
40
+ - `paths.domain_knowledge_dir` → domain knowledge root
41
+ - `paths.business_dictionary` → path to business-dictionary.md
42
+ - `paths.core_entities` → path to core-entities.md
43
+ - `paths.tech_docs_dir` → technical documentation root
44
+ - `paths.trace_dir` → trace state directory
45
+
46
+ If `paths` section is absent, use these defaults:
47
+ - `specs_dir` = `specs/bdd`
48
+ - `prd_dir` = `specs/prd`
49
+ - `refinement_dir` = `.agent/review`
50
+ - `product_definitions_dir` = `specs/product-definition`
51
+ - `domain_knowledge_dir` = `specs/domain-knowledge`
52
+ - `business_dictionary` = `specs/domain-knowledge/business-dictionary.md`
53
+ - `core_entities` = `specs/domain-knowledge/core-entities.md`
54
+ - `tech_docs_dir` = `tech-docs`
55
+ - `trace_dir` = `.trace`
56
+
57
+ If `tech_stack.module` is set, also load `.agent/modules/{module}/stack-profile.yaml` if it exists.
58
+
59
+ ---
60
+
61
+ ## Step 2 — [PROJECT-CONFIG] Load module stack profile (conditional)
62
+
63
+ If `tech_stack.module` is set, read `.agent/modules/{module}/stack-profile.yaml`.
64
+ Merge framework-specific conventions (layer patterns, test patterns, naming rules) into the loaded context.
65
+ If the file does not exist → skip silently.
66
+
67
+ ---
68
+
69
+ ## Step 3 — [CRITICAL] Load CLAUDE.md
70
+
71
+ *This is the highest-priority context — it defines HOW to write code and documents for this project.*
72
+
73
+ Read `CLAUDE.md`. Extract and store:
74
+
75
+ - **§1 Project Overview** → project name, language, framework, build/test commands, domains
76
+ - **§2 Architecture** → layer order (e.g., Controller → Facade → Service → Repository), architectural rules
77
+ - **§3 Coding Standards** → naming conventions (classes, methods), response wrapper type, forbidden patterns
78
+ - **§5 Error Handling** → exception types, HTTP status code mapping, not-found exception class name
79
+ - **§7 Git Conventions** → branch naming pattern, commit message format
80
+
81
+ If `CLAUDE.md` does not exist → note it as missing and continue with project-context.yaml data only.
82
+
83
+ ---
84
+
85
+ ## Step 4 — [SAFETY] Load Data Protection Rules
86
+
87
+ Read `.agent/rules/data-protection.md` (or `rules/data-protection.md` from the framework installation).
88
+
89
+ Store the sensitive file patterns — you must **never** read, write, display, or reference content from files matching those patterns for the entire session.
90
+
91
+ If neither file exists → apply built-in defaults: never access `.env*`, `*.key`, `*.pem`, `*secret*`, `*password*`, `*credential*`.
92
+
93
+ ---
94
+
95
+ ## Step 5 — [DOMAIN] Load Business Dictionary (conditional)
96
+
97
+ Check if the business dictionary file exists (use `paths.business_dictionary` resolved in Step 1).
98
+
99
+ If it exists, read it and extract:
100
+ - **Canonical Terms** → complete list of approved terms and their definitions
101
+ - **Banned Terms** → complete list of banned terms and their canonical replacements
102
+ - **Status / Enum Registry** → allowed enum values per entity
103
+
104
+ Store the banned terms list for **active enforcement** throughout the command session:
105
+ - When generating any text (PRD, BDD, code comments, tech docs), verify no banned terms appear
106
+ - Replace banned terms with their canonical equivalents automatically
107
+
108
+ If the file does not exist → skip silently. Do not warn or block.
109
+
110
+ ---
111
+
112
+ ## Step 6 — [DOMAIN] Load Core Entities (conditional)
113
+
114
+ Check if the core entities file exists at `paths.core_entities` (resolved in Step 1).
115
+ Default path: `specs/domain-knowledge/core-entities.md`.
116
+
117
+ If it exists, read it and store:
118
+ - **Entity catalog** → for each entity: its name, purpose, owner service, key fields (name + type), business invariants, and relationships
119
+ - **Field name registry** → canonical field names to use in generated code and documents
120
+ - **Relationship map** → how entities relate to each other (1:N, N:N, embedded, etc.)
121
+
122
+ **How to use this catalog:**
123
+ - When generating code: use the field names, types, and relationships defined here — do NOT infer from existing code
124
+ - When generating PRD/BDD: reference entity names from this catalog for consistency
125
+ - When generating tech-docs: use this catalog as the source-of-truth for entity definitions
126
+
127
+ If the file does not exist → skip silently.
128
+
129
+ ---
130
+
131
+ ## Step 7 — [RECAP] Working Memory Recap (anti-lost-in-middle)
132
+
133
+ After loading all context, synthesize and output a compact summary block.
134
+ This recap ensures the most critical facts are stated at the END of context loading
135
+ (recency effect — freshest in working memory when the task begins).
136
+
137
+ Output exactly this block:
138
+ ```
139
+ [CTX LOADED]
140
+ Stack : {language} / {framework} / {database}
141
+ Layers : {layer order from CLAUDE.md §2, e.g., Controller → Facade → Service → Repository}
142
+ Ticket : {ticket_prefix}-
143
+ Dict : {loaded — N canonical terms, M banned terms | missing}
144
+ Entities : {loaded — EntityA, EntityB, EntityC | missing}
145
+ Status : {FULL | PARTIAL — missing: CLAUDE.md / business-dict / core-entities | MINIMAL}
146
+ ```
147
+
148
+ If any CRITICAL file is missing (CLAUDE.md), flag it clearly so the user can decide whether to proceed.
149
+
150
+ ---
151
+
152
+ ## Context Load Complete
153
+
154
+ After completing all steps, you have loaded:
155
+ - Project identity, tech stack, module conventions
156
+ - Architecture rules and layer order ← **[CRITICAL — hold in working memory]**
157
+ - Coding standards and naming conventions ← **[CRITICAL — hold in working memory]**
158
+ - Data protection rules (sensitive file patterns to never access)
159
+ - Terminology rules with banned-term list ← **[DOMAIN — apply to every generated word]**
160
+ - Entity catalog (field names, types, invariants) ← **[DOMAIN — use for code generation]**
161
+ - All configured paths
162
+
163
+ Proceed to the next step of the calling command.
@@ -0,0 +1,81 @@
1
+ # Gate — Universal Entry Procedure
2
+
3
+ Every command must execute this gate before proceeding with its specific logic.
4
+
5
+ ## Step 0 — Sub-Agent Mode Check
6
+
7
+ Before anything else, check if `$ARGUMENTS` is a JSON payload from an orchestrator:
8
+
9
+ 1. Attempt to parse `$ARGUMENTS` as JSON.
10
+ 2. If it parses successfully **and** contains `"_agent_mode": true`:
11
+ - **Skip Steps 1, 2, and 3 of this Gate entirely.**
12
+ - Set target file = `payload.target_file`
13
+ - Set loaded context = `payload.context` (do NOT run context-loader.md)
14
+ - Set UC scope = `payload.uc_id` (process only this UC)
15
+ - Set line range = `payload.uc_section` (read only that PRD section)
16
+ - Proceed directly to the command-specific logic.
17
+ 3. If `$ARGUMENTS` is not JSON or `_agent_mode` is absent → continue to Step 1 (normal mode).
18
+
19
+ ## Step 0-B — Model Check
20
+
21
+ *Skip this step if `_agent_mode: true` (sub-agent — orchestrator already validated).*
22
+
23
+ Complex generation and review commands require strong reasoning.
24
+ Using a smaller model risks missed edge cases, incomplete spec analysis, and architecture violations.
25
+
26
+ Display and wait for response:
27
+
28
+ ```
29
+ ⚙️ MODEL CHECK
30
+ ──────────────────────────────────────────────────────────────────
31
+ Recommended : claude-opus-4-5 (or claude-opus-4)
32
+ Why needed : Spec analysis, architecture review, code generation
33
+ require deep reasoning. Smaller models miss edge cases.
34
+
35
+ To switch in Claude Code:
36
+ • Settings → Model → select "claude-opus"
37
+ • or: /model → choose claude-opus
38
+
39
+ Running on claude-opus?
40
+ Y — yes, on claude-opus → proceed
41
+ S — skip check (I accept lower quality risk with current model)
42
+ ──────────────────────────────────────────────────────────────────
43
+ ```
44
+
45
+ - "Y" → proceed to Step 1.
46
+ - "S" → proceed to Step 1 (user accepts risk, add ⚠️ to final report).
47
+ - "N" or anything else → **STOP.** Output: "Please switch to claude-opus, then re-run this command."
48
+
49
+ ## Step 1 — Resolve Target File
50
+
51
+ 1. If `$ARGUMENTS` is provided and points to an existing file → use it directly as the target.
52
+ 2. If `$ARGUMENTS` is a UC-ID, ticket ID, or partial name → search for matching files in the relevant directory.
53
+ 3. If `$ARGUMENTS` is empty or no match found:
54
+ - List files in the relevant directory for this command (e.g., `specs/prd/**/*.md` for PRD commands, `specs/bdd/**/*.feature` for BDD commands).
55
+ - Present the list to the user and ask: "Which file do you want to work with? (Enter number or filename)"
56
+ - Wait for user selection before continuing.
57
+
58
+ ## Step 2 — Execute Context Loader
59
+
60
+ Load all project context by following the procedure in `steps/context-loader.md`.
61
+ Store all loaded context in memory for use throughout this command session.
62
+
63
+ ## Step 3 — CHECKPOINT
64
+
65
+ After completing Steps 1 and 2, display a summary and wait for confirmation:
66
+
67
+ ```
68
+ CHECKPOINT
69
+ -----------
70
+ Target : {resolved file path}
71
+ Project : {project.name from project-context.yaml}
72
+ Tech stack : {language} / {framework}
73
+ Module : {module if set, else "not configured"}
74
+ Domains : {comma-separated domain list}
75
+
76
+ Proceed? (Y/N)
77
+ ```
78
+
79
+ Wait for explicit "Y" or "N" from the user before continuing.
80
+ - "Y" → proceed to the command-specific steps below.
81
+ - "N" → stop and ask what the user wants to change.
@@ -0,0 +1,53 @@
1
+ # Report Footer — Standard Command Output Format
2
+
3
+ Every command report must end with this standard footer section.
4
+
5
+ ## Status Badge
6
+
7
+ Choose one based on outcome:
8
+ - `✅ Complete` — all steps succeeded, no issues found
9
+ - `❌ Failed` — command could not complete due to a blocking error
10
+ - `⚠️ Warnings` — completed with non-blocking issues that should be reviewed
11
+
12
+ ## Output Artifacts
13
+
14
+ List every file created or modified by this command:
15
+ ```
16
+ Output Artifacts:
17
+ {created|updated} {file-path} ({brief description})
18
+ {created|updated} {file-path} ({brief description})
19
+ ```
20
+
21
+ If no files were written (e.g., review or analysis commands) → write `Output Artifacts: none (read-only)`.
22
+
23
+ ## Next Command Suggestion
24
+
25
+ Suggest the logical next command based on workflow phase:
26
+
27
+ | Current command | Suggest next |
28
+ |-------------------------|-----------------------------------------------|
29
+ | /define-product | `/generate-prd {product-definition-file}` |
30
+ | /generate-prd | `/refine-prd {prd-file}` then `/review-context {prd-file}` |
31
+ | /refine-prd | Open Review Board → update PRD → `/review-context {prd-file}` |
32
+ | /review-context (PRD) | `/generate-bdd {prd-file}` if APPROVED; fix PRD if NEEDS_FIX |
33
+ | /generate-bdd | `/review-context {feature-file}` to verify coverage |
34
+ | /review-context (BDD) | `/generate-tech-docs {UC-ID}` if APPROVED; regenerate if NEEDS_FIX |
35
+ | /generate-tech-docs | `/review-tech-docs {tech-design-file}` |
36
+ | /review-tech-docs | `/generate-code {feature-file}` if APPROVED; fix doc if NEEDS_FIX |
37
+ | /generate-code | `/generate-tests {UC-ID}` |
38
+ | /generate-tests | `/run-tests {UC-ID}` |
39
+ | /run-tests (passing) | `/review-code {UC-ID}` |
40
+ | /run-tests (failing) | `/fix-bug {ticket-id}` or `/debug {error}` |
41
+ | /review-code | `/smoke-test {UC-ID}` or create PR |
42
+ | /smoke-test | Create PR and link to ticket |
43
+ | /validate-traces | `/generate-code {UC-ID}` for gaps |
44
+ | /fix-bug | Create PR and link to ticket |
45
+ | /debug | `/fix-bug {ticket-id}` if fix needed |
46
+
47
+ Format the footer as:
48
+ ```
49
+ ---
50
+ Status : {badge}
51
+ {Output Artifacts block}
52
+ Next : {suggested command with example arguments}
53
+ ```
@@ -0,0 +1,123 @@
1
+ # Sub-Agent Orchestration Pattern
2
+
3
+ Used by heavy commands when the target exceeds the complexity threshold.
4
+ The main session becomes a **lightweight orchestrator** — it only coordinates.
5
+ Each unit of work runs in its own sub-agent with a fresh context window.
6
+
7
+ ---
8
+
9
+ ## Complexity Thresholds
10
+
11
+ | Signal | Threshold | Action |
12
+ |--------|-----------|--------|
13
+ | UC count in PRD | > 3 UCs | spawn 1 agent per UC |
14
+ | PRD length | > 300 lines | spawn agents regardless of UC count |
15
+
16
+ If **either** threshold is exceeded → switch to orchestration mode.
17
+
18
+ ---
19
+
20
+ ## Orchestrator Steps (main session)
21
+
22
+ ### Step A — Build slim context
23
+
24
+ Extract only what sub-agents need — do NOT pass full CLAUDE.md or full business-dictionary:
25
+
26
+ ```json
27
+ {
28
+ "project_name": "{project.name}",
29
+ "tech_stack": {
30
+ "language": "{tech_stack.language}",
31
+ "framework": "{tech_stack.framework}",
32
+ "build_tool": "{tech_stack.build_tool}",
33
+ "test_framework": "{tech_stack.test_framework}",
34
+ "database": "{tech_stack.database}",
35
+ "module": "{tech_stack.module}"
36
+ },
37
+ "conventions": {
38
+ "build_command": "{conventions.build_command}",
39
+ "commit_format": "{conventions.commit_format}"
40
+ },
41
+ "paths": {
42
+ "specs_dir": "{paths.specs_dir}",
43
+ "prd_dir": "{paths.prd_dir}",
44
+ "trace_dir": "{paths.trace_dir}",
45
+ "tech_docs_dir": "{paths.tech_docs_dir}"
46
+ },
47
+ "architecture_summary": "<3-5 bullet points: layer order + key rules only>",
48
+ "domains": ["{domain1}", "{domain2}"],
49
+ "banned_terms": ["{term1}", "{term2}"]
50
+ }
51
+ ```
52
+
53
+ ### Step B — Extract UC list
54
+
55
+ Scan the target PRD for `#### {TICKET-ID}-UC{N}:` headings.
56
+ Build list: `[ { uc_id, uc_name, line_start, line_end } ]`
57
+
58
+ ### Step C — Announce plan
59
+
60
+ ```
61
+ High complexity detected — {N} UCs / {L} lines in {prd_file}
62
+ Spawning {N} sub-agents (1 per UC)...
63
+ Agent 1 → {TICKET-ID}-UC1: {UC name}
64
+ Agent 2 → {TICKET-ID}-UC2: {UC name}
65
+ ...
66
+ ```
67
+
68
+ ### Step D — Spawn one sub-agent per UC
69
+
70
+ Build payload and invoke Agent tool for each UC:
71
+
72
+ ```json
73
+ {
74
+ "_agent_mode": true,
75
+ "command": "{generate-bdd | generate-code | generate-tests}",
76
+ "uc_id": "{TICKET-ID}-UC{N}",
77
+ "target_file": "{absolute path to PRD or feature file}",
78
+ "uc_section": { "line_start": {N}, "line_end": {N} },
79
+ "context": { "<slim context from Step A>" }
80
+ }
81
+ ```
82
+
83
+ Serialize this JSON and pass as `$ARGUMENTS` when invoking the sub-agent command.
84
+
85
+ ### Step E — Collect and merge results
86
+
87
+ Each sub-agent returns:
88
+ ```json
89
+ {
90
+ "uc_id": "{TICKET-ID}-UC{N}",
91
+ "files_created": ["path/to/file1", "path/to/file2"],
92
+ "status": "success | error",
93
+ "errors": []
94
+ }
95
+ ```
96
+
97
+ Merge into a single report (follow report-footer.md format).
98
+ If any sub-agent errors → list them clearly and suggest re-run for that UC only.
99
+
100
+ ---
101
+
102
+ ## Sub-Agent Entry Point (called commands)
103
+
104
+ When `gate.md Step 0` detects `_agent_mode: true`:
105
+
106
+ 1. Parse full payload from `$ARGUMENTS`
107
+ 2. **Skip context-loader.md** — use `payload.context` directly
108
+ 3. **Scope to `payload.uc_id` only** — do not process other UCs in the file
109
+ 4. Read only the PRD section between `payload.uc_section.line_start` and `line_end`
110
+ 5. Execute the command's normal logic for this single UC
111
+ 6. Return structured result JSON (Step E format above)
112
+
113
+ ---
114
+
115
+ ## Context Window Savings
116
+
117
+ | Mode | What loads per session |
118
+ |------|------------------------|
119
+ | Single session (≤ 3 UC) | Full context + full PRD + all UCs |
120
+ | Orchestrator | Slim context + UC headings only |
121
+ | Each sub-agent | Slim context + **1 UC section only** |
122
+
123
+ The larger the PRD, the bigger the saving per sub-agent.
@@ -0,0 +1,113 @@
1
+ # §1. Project Overview
2
+
3
+ Project : {{PROJECT_NAME}}
4
+ Language : {{LANGUAGE}} # e.g., Java 17 / TypeScript / C# / Go
5
+ Framework : {{FRAMEWORK}} # e.g., Spring Boot 3.2 / Angular 17 / .NET 8
6
+ Build : {{BUILD_COMMAND}} # e.g., mvn clean install -DskipTests / dotnet build / ng build
7
+ Test : {{TEST_COMMAND}} # e.g., mvn test / dotnet test / ng test
8
+ Domains : {{COMMA_SEPARATED_DOMAINS}}
9
+
10
+ # §2. Architecture
11
+
12
+ style: "{{ARCH_STYLE}}" # e.g., Layered / Clean / Hexagonal / Component-based
13
+
14
+ layers: "{{LAYER_STACK}}"
15
+ # Examples:
16
+ # Java/Spring: Controller → Facade → Service → Repository
17
+ # .NET Clean: Presentation → Application → Domain → Infrastructure
18
+ # Angular: Component → Service → HTTP Client → Backend API
19
+ # Go: Handler → UseCase → Repository → Domain
20
+
21
+ rules:
22
+ - "{{ARCH_RULE_1}}" # e.g., Controllers must not contain business logic
23
+ - "{{ARCH_RULE_2}}" # e.g., Services own transaction boundaries
24
+ - "{{ARCH_RULE_3}}" # e.g., Repositories must not call services
25
+
26
+ # Layer dependency direction (inner layers must not depend on outer):
27
+ # {{OUTER_LAYER}} → {{MIDDLE_LAYER}} → {{INNER_LAYER}}
28
+
29
+ # §3. Coding Standards
30
+
31
+ naming:
32
+ classes: "{{CLASS_NAMING}}" # e.g., PascalCase / PascalCase+Suffix
33
+ methods: "{{METHOD_NAMING}}" # e.g., camelCase / PascalCase
34
+ packages: "{{PACKAGE_NAMING}}" # e.g., lowercase / lowercase.snake_case
35
+ files: "{{FILE_NAMING}}" # e.g., PascalCase.java / kebab-case.ts
36
+
37
+ patterns:
38
+ response_wrapper: "{{RESPONSE_WRAPPER}}" # e.g., ApiResponse<T> / Result<T> / IActionResult
39
+ mapping: "{{MAPPING_LIBRARY}}" # e.g., MapStruct / AutoMapper / manual
40
+ exception_base: "{{BASE_EXCEPTION}}" # e.g., ResourceNotFoundException / DomainException
41
+
42
+ forbidden:
43
+ - "Magic numbers — use named constants"
44
+ - "Debug print statements in production code"
45
+ - "{{PROJECT_SPECIFIC_FORBIDDEN_PATTERN}}"
46
+
47
+ # §4. API Conventions
48
+
49
+ versioning: "{{API_VERSIONING}}" # e.g., /v1/ prefix / header-based / query param
50
+ auth: "{{AUTH_MECHANISM}}" # e.g., JWT Bearer / OAuth2 / API Key
51
+
52
+ http_status:
53
+ get_list: 200 # paginated or full list
54
+ get_single: 200
55
+ create: 201
56
+ update: 200
57
+ delete: 204
58
+ bad_request: 400
59
+ unauthorized: 401
60
+ forbidden: 403
61
+ not_found: 404
62
+ server_error: 500
63
+
64
+ error_response_format: |
65
+ {
66
+ "code": "ERROR_CODE",
67
+ "message": "Human readable message",
68
+ "details": {} // optional field-level errors
69
+ }
70
+
71
+ # §5. Error Handling
72
+
73
+ not_found_exception: "{{NOT_FOUND_EXCEPTION_CLASS}}" # e.g., ResourceNotFoundException
74
+ validation_exception: "{{VALIDATION_EXCEPTION_CLASS}}" # e.g., ValidationException
75
+ domain_exception: "{{DOMAIN_EXCEPTION_CLASS}}" # e.g., DomainException / BusinessRuleViolationException
76
+
77
+ global_handler: "{{GLOBAL_EXCEPTION_HANDLER}}" # e.g., @ControllerAdvice / ExceptionHandlerMiddleware
78
+
79
+ rules:
80
+ - "Never swallow exceptions silently"
81
+ - "Log at error level with full stack trace for 5xx"
82
+ - "{{PROJECT_SPECIFIC_ERROR_RULE}}"
83
+
84
+ # §6. Testing Standards
85
+
86
+ unit_test_framework: "{{UNIT_TEST_FW}}" # e.g., JUnit 5 + Mockito / xUnit + Moq / Jest
87
+ integration_test_framework: "{{IT_TEST_FW}}" # e.g., Spring Boot Test / WebApplicationFactory
88
+
89
+ coverage_targets:
90
+ unit: "{{UNIT_COVERAGE_PCT}}%" # e.g., 80%
91
+ integration: "{{IT_COVERAGE_PCT}}%" # e.g., key flows covered
92
+
93
+ naming_pattern: "{{TEST_METHOD_NAMING}}" # e.g., methodName_whenCondition_shouldExpectation
94
+
95
+ rules:
96
+ - "Unit tests mock direct dependencies only"
97
+ - "Integration tests cover happy path + main error paths"
98
+ - "Every scenario in .feature must have a corresponding test"
99
+
100
+ # §7. Git Conventions
101
+
102
+ branch_feature: "feature/{{TICKET_PREFIX}}-{N}-{slug}"
103
+ branch_fix: "fix/{{TICKET_PREFIX}}-{N}-{slug}"
104
+ branch_chore: "chore/{slug}"
105
+
106
+ commit_feature: "feat({{TICKET_PREFIX}}-{N}): {description}"
107
+ commit_fix: "fix({{TICKET_PREFIX}}-{N}): {description}"
108
+ commit_chore: "chore: {description}"
109
+ commit_docs: "docs: {description}"
110
+
111
+ pr_title: "{{TICKET_PREFIX}}-{N}: {feature name}"
112
+ pr_requires_review: true
113
+ pr_branch_protection: "{{BASE_BRANCH}}" # e.g., main / develop