claude-code-workflow 7.2.29 → 7.2.30

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 (124) hide show
  1. package/.ccw/workflows/cli-templates/schemas/plan-overview-base-schema.json +2 -2
  2. package/.ccw/workflows/cli-templates/schemas/task-schema.json +14 -7
  3. package/.claude/agents/action-planning-agent.md +7 -4
  4. package/.claude/agents/cli-explore-agent.md +77 -63
  5. package/.claude/agents/cli-lite-planning-agent.md +11 -10
  6. package/.claude/agents/issue-plan-agent.md +421 -426
  7. package/.claude/commands/workflow/spec/setup.md +1 -1
  8. package/.claude/skills/ccw-chain/SKILL.md +119 -0
  9. package/.claude/skills/ccw-chain/chains/ccw-cycle.json +21 -0
  10. package/.claude/skills/ccw-chain/chains/ccw-exploration.json +47 -0
  11. package/.claude/skills/ccw-chain/chains/ccw-issue.json +33 -0
  12. package/.claude/skills/ccw-chain/chains/ccw-lightweight.json +57 -0
  13. package/.claude/skills/ccw-chain/chains/ccw-main.json +52 -0
  14. package/.claude/skills/ccw-chain/chains/ccw-standard.json +39 -0
  15. package/.claude/skills/ccw-chain/chains/ccw-team.json +10 -0
  16. package/.claude/skills/ccw-chain/chains/ccw-with-file.json +31 -0
  17. package/.claude/skills/ccw-chain/phases/analyze-with-file.md +788 -0
  18. package/.claude/skills/ccw-chain/phases/brainstorm/SKILL.md +408 -0
  19. package/.claude/skills/ccw-chain/phases/brainstorm/phases/01-mode-routing.md +207 -0
  20. package/.claude/skills/ccw-chain/phases/brainstorm/phases/02-artifacts.md +567 -0
  21. package/.claude/skills/ccw-chain/phases/brainstorm/phases/03-role-analysis.md +748 -0
  22. package/.claude/skills/ccw-chain/phases/brainstorm/phases/04-synthesis.md +827 -0
  23. package/.claude/skills/ccw-chain/phases/brainstorm-with-file.md +482 -0
  24. package/.claude/skills/ccw-chain/phases/collaborative-plan-with-file.md +639 -0
  25. package/.claude/skills/ccw-chain/phases/debug-with-file.md +656 -0
  26. package/.claude/skills/ccw-chain/phases/integration-test-cycle.md +936 -0
  27. package/.claude/skills/ccw-chain/phases/issue-convert-to-plan.md +720 -0
  28. package/.claude/skills/ccw-chain/phases/issue-discover.md +483 -0
  29. package/.claude/skills/ccw-chain/phases/issue-execute.md +629 -0
  30. package/.claude/skills/ccw-chain/phases/issue-from-brainstorm.md +382 -0
  31. package/.claude/skills/ccw-chain/phases/issue-plan.md +343 -0
  32. package/.claude/skills/ccw-chain/phases/issue-queue.md +464 -0
  33. package/.claude/skills/ccw-chain/phases/refactor-cycle.md +852 -0
  34. package/.claude/skills/ccw-chain/phases/review-cycle/SKILL.md +132 -0
  35. package/.claude/skills/ccw-chain/phases/review-cycle/phases/review-fix.md +760 -0
  36. package/.claude/skills/ccw-chain/phases/review-cycle/phases/review-module.md +764 -0
  37. package/.claude/skills/ccw-chain/phases/review-cycle/phases/review-session.md +775 -0
  38. package/.claude/skills/ccw-chain/phases/roadmap-with-file.md +544 -0
  39. package/.claude/skills/ccw-chain/phases/spec-generator/SKILL.md +338 -0
  40. package/.claude/skills/ccw-chain/phases/spec-generator/phases/01-5-requirement-clarification.md +404 -0
  41. package/.claude/skills/ccw-chain/phases/spec-generator/phases/01-discovery.md +257 -0
  42. package/.claude/skills/ccw-chain/phases/spec-generator/phases/02-product-brief.md +274 -0
  43. package/.claude/skills/ccw-chain/phases/spec-generator/phases/03-requirements.md +184 -0
  44. package/.claude/skills/ccw-chain/phases/spec-generator/phases/04-architecture.md +248 -0
  45. package/.claude/skills/ccw-chain/phases/spec-generator/phases/05-epics-stories.md +178 -0
  46. package/.claude/skills/ccw-chain/phases/spec-generator/phases/06-5-auto-fix.md +144 -0
  47. package/.claude/skills/ccw-chain/phases/spec-generator/phases/06-readiness-check.md +480 -0
  48. package/.claude/skills/ccw-chain/phases/team-planex.md +123 -0
  49. package/.claude/skills/ccw-chain/phases/ui-design-explore-auto.md +678 -0
  50. package/.claude/skills/ccw-chain/phases/unified-execute-with-file.md +870 -0
  51. package/.claude/skills/ccw-chain/phases/workflow-execute/SKILL.md +625 -0
  52. package/.claude/skills/ccw-chain/phases/workflow-execute/phases/06-review.md +215 -0
  53. package/.claude/skills/ccw-chain/phases/workflow-lite-plan.md +616 -0
  54. package/.claude/skills/ccw-chain/phases/workflow-multi-cli-plan.md +424 -0
  55. package/.claude/skills/ccw-chain/phases/workflow-plan/SKILL.md +466 -0
  56. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/01-session-discovery.md +99 -0
  57. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/02-context-gathering.md +338 -0
  58. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/03-conflict-resolution.md +422 -0
  59. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/04-task-generation.md +440 -0
  60. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/05-plan-verify.md +395 -0
  61. package/.claude/skills/ccw-chain/phases/workflow-plan/phases/06-replan.md +594 -0
  62. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/SKILL.md +527 -0
  63. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/01-session-discovery.md +57 -0
  64. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/02-context-gathering.md +407 -0
  65. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/03-test-coverage-analysis.md +172 -0
  66. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/04-conflict-resolution.md +426 -0
  67. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/05-tdd-task-generation.md +473 -0
  68. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/06-tdd-structure-validation.md +189 -0
  69. package/.claude/skills/ccw-chain/phases/workflow-tdd-plan/phases/07-tdd-verify.md +635 -0
  70. package/.claude/skills/ccw-chain/phases/workflow-test-fix/SKILL.md +482 -0
  71. package/.claude/skills/ccw-chain/phases/workflow-test-fix/phases/01-session-start.md +60 -0
  72. package/.claude/skills/ccw-chain/phases/workflow-test-fix/phases/02-test-context-gather.md +493 -0
  73. package/.claude/skills/ccw-chain/phases/workflow-test-fix/phases/03-test-concept-enhanced.md +150 -0
  74. package/.claude/skills/ccw-chain/phases/workflow-test-fix/phases/04-test-task-generate.md +346 -0
  75. package/.claude/skills/ccw-chain/phases/workflow-test-fix/phases/05-test-cycle-execute.md +538 -0
  76. package/.claude/skills/ccw-chain/specs/auto-mode.md +47 -0
  77. package/.claude/skills/ccw-chain/specs/intent-patterns.md +60 -0
  78. package/.claude/skills/chain-loader/SKILL.md +78 -0
  79. package/.claude/skills/chain-loader/phases/01-analyze-skill.md +53 -0
  80. package/.claude/skills/chain-loader/phases/02-design-graph.md +73 -0
  81. package/.claude/skills/chain-loader/phases/03-generate-validate.md +75 -0
  82. package/.claude/skills/chain-loader/specs/chain-schema.md +99 -0
  83. package/.claude/skills/chain-loader/specs/design-patterns.md +99 -0
  84. package/.claude/skills/chain-loader/templates/chain-json.md +63 -0
  85. package/.claude/skills/review-cycle/phases/review-module.md +764 -764
  86. package/.claude/skills/review-cycle/phases/review-session.md +775 -775
  87. package/.claude/skills/workflow-multi-cli-plan/SKILL.md +2 -2
  88. package/.claude/skills/workflow-plan/phases/03-conflict-resolution.md +422 -422
  89. package/.claude/skills/workflow-plan/phases/05-plan-verify.md +395 -395
  90. package/.claude/skills/workflow-tdd-plan/phases/02-context-gathering.md +407 -407
  91. package/.claude/skills/workflow-tdd-plan/phases/04-conflict-resolution.md +426 -426
  92. package/.claude/skills/workflow-test-fix/phases/02-test-context-gather.md +493 -493
  93. package/README.md +14 -0
  94. package/ccw/dist/core/routes/litellm-api-routes.d.ts.map +1 -1
  95. package/ccw/dist/core/routes/litellm-api-routes.js +0 -23
  96. package/ccw/dist/core/routes/litellm-api-routes.js.map +1 -1
  97. package/ccw/dist/tools/chain-loader.d.ts +10 -0
  98. package/ccw/dist/tools/chain-loader.d.ts.map +1 -0
  99. package/ccw/dist/tools/chain-loader.js +642 -0
  100. package/ccw/dist/tools/chain-loader.js.map +1 -0
  101. package/ccw/dist/tools/index.d.ts.map +1 -1
  102. package/ccw/dist/tools/index.js +2 -0
  103. package/ccw/dist/tools/index.js.map +1 -1
  104. package/ccw/dist/tools/json-builder.js +20 -0
  105. package/ccw/dist/tools/json-builder.js.map +1 -1
  106. package/ccw/dist/types/chain-types.d.ts +72 -0
  107. package/ccw/dist/types/chain-types.d.ts.map +1 -0
  108. package/ccw/dist/types/chain-types.js +5 -0
  109. package/ccw/dist/types/chain-types.js.map +1 -0
  110. package/ccw/scripts/prepublish-clean.mjs +0 -1
  111. package/package.json +1 -3
  112. package/ccw-litellm/README.md +0 -180
  113. package/ccw-litellm/pyproject.toml +0 -35
  114. package/ccw-litellm/src/ccw_litellm/__init__.py +0 -47
  115. package/ccw-litellm/src/ccw_litellm/cli.py +0 -108
  116. package/ccw-litellm/src/ccw_litellm/clients/__init__.py +0 -12
  117. package/ccw-litellm/src/ccw_litellm/clients/litellm_embedder.py +0 -270
  118. package/ccw-litellm/src/ccw_litellm/clients/litellm_llm.py +0 -198
  119. package/ccw-litellm/src/ccw_litellm/config/__init__.py +0 -22
  120. package/ccw-litellm/src/ccw_litellm/config/loader.py +0 -343
  121. package/ccw-litellm/src/ccw_litellm/config/models.py +0 -162
  122. package/ccw-litellm/src/ccw_litellm/interfaces/__init__.py +0 -14
  123. package/ccw-litellm/src/ccw_litellm/interfaces/embedder.py +0 -52
  124. package/ccw-litellm/src/ccw_litellm/interfaces/llm.py +0 -45
@@ -0,0 +1,274 @@
1
+ # Phase 2: Product Brief
2
+
3
+ Generate a product brief through multi-perspective CLI analysis, establishing "what" and "why".
4
+
5
+ ## Objective
6
+
7
+ - Read Phase 1 outputs (spec-config.json, discovery-context.json)
8
+ - Launch 3 parallel CLI analyses from product, technical, and user perspectives
9
+ - Synthesize convergent themes and conflicting views
10
+ - Optionally refine with user input
11
+ - Generate product-brief.md using template
12
+
13
+ ## Input
14
+
15
+ - Dependency: `{workDir}/spec-config.json`
16
+ - Primary: `{workDir}/refined-requirements.json` (Phase 1.5 output, preferred over raw seed_analysis)
17
+ - Optional: `{workDir}/discovery-context.json`
18
+ - Config: `{workDir}/spec-config.json`
19
+ - Template: `templates/product-brief.md`
20
+
21
+ ## Execution Steps
22
+
23
+ ### Step 1: Load Phase 1 Context
24
+
25
+ ```javascript
26
+ const specConfig = JSON.parse(Read(`${workDir}/spec-config.json`));
27
+ const { seed_analysis, seed_input, has_codebase, depth, focus_areas } = specConfig;
28
+
29
+ // Load refined requirements (Phase 1.5 output) - preferred over raw seed_analysis
30
+ let refinedReqs = null;
31
+ try {
32
+ refinedReqs = JSON.parse(Read(`${workDir}/refined-requirements.json`));
33
+ } catch (e) {
34
+ // No refined requirements, fall back to seed_analysis
35
+ }
36
+
37
+ let discoveryContext = null;
38
+ if (has_codebase) {
39
+ try {
40
+ discoveryContext = JSON.parse(Read(`${workDir}/discovery-context.json`));
41
+ } catch (e) {
42
+ // No discovery context available, proceed without
43
+ }
44
+ }
45
+
46
+ // Build shared context string for CLI prompts
47
+ // Prefer refined requirements over raw seed_analysis
48
+ const problem = refinedReqs?.clarified_problem_statement || seed_analysis.problem_statement;
49
+ const users = refinedReqs?.confirmed_target_users?.map(u => u.name || u).join(', ')
50
+ || seed_analysis.target_users.join(', ');
51
+ const domain = refinedReqs?.confirmed_domain || seed_analysis.domain;
52
+ const constraints = refinedReqs?.boundary_conditions?.constraints?.join(', ')
53
+ || seed_analysis.constraints.join(', ');
54
+ const features = refinedReqs?.confirmed_features?.map(f => f.name).join(', ') || '';
55
+ const nfrs = refinedReqs?.non_functional_requirements?.map(n => `${n.type}: ${n.details}`).join('; ') || '';
56
+
57
+ const sharedContext = `
58
+ SEED: ${seed_input}
59
+ PROBLEM: ${problem}
60
+ TARGET USERS: ${users}
61
+ DOMAIN: ${domain}
62
+ CONSTRAINTS: ${constraints}
63
+ FOCUS AREAS: ${focus_areas.join(', ')}
64
+ ${features ? `CONFIRMED FEATURES: ${features}` : ''}
65
+ ${nfrs ? `NON-FUNCTIONAL REQUIREMENTS: ${nfrs}` : ''}
66
+ ${discoveryContext ? `
67
+ CODEBASE CONTEXT:
68
+ - Existing patterns: ${discoveryContext.existing_patterns?.slice(0,5).join(', ') || 'none'}
69
+ - Architecture constraints: ${discoveryContext.architecture_constraints?.slice(0,3).join(', ') || 'none'}
70
+ - Tech stack: ${JSON.stringify(discoveryContext.tech_stack || {})}
71
+ ` : ''}`;
72
+ ```
73
+
74
+ ### Step 2: Multi-CLI Parallel Analysis (3 perspectives)
75
+
76
+ Launch 3 CLI calls in parallel:
77
+
78
+ **Product Perspective (Gemini)**:
79
+ ```javascript
80
+ Bash({
81
+ command: `ccw cli -p "PURPOSE: Product analysis for specification - identify market fit, user value, and success criteria.
82
+ Success: Clear vision, measurable goals, competitive positioning.
83
+
84
+ ${sharedContext}
85
+
86
+ TASK:
87
+ - Define product vision (1-3 sentences, aspirational)
88
+ - Analyze market/competitive landscape
89
+ - Define 3-5 measurable success metrics
90
+ - Identify scope boundaries (in-scope vs out-of-scope)
91
+ - Assess user value proposition
92
+ - List assumptions that need validation
93
+
94
+ MODE: analysis
95
+ EXPECTED: Structured product analysis with: vision, goals with metrics, scope, competitive positioning, assumptions
96
+ CONSTRAINTS: Focus on 'what' and 'why', not 'how'
97
+ " --tool gemini --mode analysis`,
98
+ run_in_background: true
99
+ });
100
+ ```
101
+
102
+ **Technical Perspective (Codex)**:
103
+ ```javascript
104
+ Bash({
105
+ command: `ccw cli -p "PURPOSE: Technical feasibility analysis for specification - assess implementation viability and constraints.
106
+ Success: Clear technical constraints, integration complexity, technology recommendations.
107
+
108
+ ${sharedContext}
109
+
110
+ TASK:
111
+ - Assess technical feasibility of the core concept
112
+ - Identify technical constraints and blockers
113
+ - Evaluate integration complexity with existing systems
114
+ - Recommend technology approach (high-level)
115
+ - Identify technical risks and dependencies
116
+ - Estimate complexity: simple/moderate/complex
117
+
118
+ MODE: analysis
119
+ EXPECTED: Technical analysis with: feasibility assessment, constraints, integration complexity, tech recommendations, risks
120
+ CONSTRAINTS: Focus on feasibility and constraints, not detailed architecture
121
+ " --tool codex --mode analysis`,
122
+ run_in_background: true
123
+ });
124
+ ```
125
+
126
+ **User Perspective (Claude)**:
127
+ ```javascript
128
+ Bash({
129
+ command: `ccw cli -p "PURPOSE: User experience analysis for specification - understand user journeys, pain points, and UX considerations.
130
+ Success: Clear user personas, journey maps, UX requirements.
131
+
132
+ ${sharedContext}
133
+
134
+ TASK:
135
+ - Elaborate user personas with goals and frustrations
136
+ - Map primary user journey (happy path)
137
+ - Identify key pain points in current experience
138
+ - Define UX success criteria
139
+ - List accessibility and usability considerations
140
+ - Suggest interaction patterns
141
+
142
+ MODE: analysis
143
+ EXPECTED: User analysis with: personas, journey map, pain points, UX criteria, interaction recommendations
144
+ CONSTRAINTS: Focus on user needs and experience, not implementation
145
+ " --tool claude --mode analysis`,
146
+ run_in_background: true
147
+ });
148
+
149
+ // STOP: Wait for all 3 CLI results before continuing
150
+ ```
151
+
152
+ ### Step 3: Synthesize Perspectives
153
+
154
+ ```javascript
155
+ // After receiving all 3 CLI results:
156
+ // Extract convergent themes (all agree)
157
+ // Identify conflicting views (need resolution)
158
+ // Note unique contributions from each perspective
159
+
160
+ const synthesis = {
161
+ convergent_themes: [], // themes all 3 perspectives agree on
162
+ conflicts: [], // areas where perspectives differ
163
+ product_insights: [], // unique from product perspective
164
+ technical_insights: [], // unique from technical perspective
165
+ user_insights: [] // unique from user perspective
166
+ };
167
+ ```
168
+
169
+ ### Step 4: Interactive Refinement (Optional)
170
+
171
+ ```javascript
172
+ if (!autoMode) {
173
+ // Present synthesis summary to user
174
+ // AskUserQuestion with:
175
+ // - Confirm vision statement
176
+ // - Resolve any conflicts between perspectives
177
+ // - Adjust scope if needed
178
+ AskUserQuestion({
179
+ questions: [
180
+ {
181
+ question: "Review the synthesized product brief. Any adjustments needed?",
182
+ header: "Review",
183
+ multiSelect: false,
184
+ options: [
185
+ { label: "Looks good", description: "Proceed to PRD generation" },
186
+ { label: "Adjust scope", description: "Narrow or expand the scope" },
187
+ { label: "Revise vision", description: "Refine the vision statement" }
188
+ ]
189
+ }
190
+ ]
191
+ });
192
+ }
193
+ ```
194
+
195
+ ### Step 5: Generate product-brief.md
196
+
197
+ ```javascript
198
+ // Read template
199
+ const template = Read('templates/product-brief.md');
200
+
201
+ // Fill template with synthesized content
202
+ // Apply document-standards.md formatting rules
203
+ // Write with YAML frontmatter
204
+
205
+ const frontmatter = `---
206
+ session_id: ${specConfig.session_id}
207
+ phase: 2
208
+ document_type: product-brief
209
+ status: ${autoMode ? 'complete' : 'draft'}
210
+ generated_at: ${new Date().toISOString()}
211
+ stepsCompleted: ["load-context", "multi-cli-analysis", "synthesis", "generation"]
212
+ version: 1
213
+ dependencies:
214
+ - spec-config.json
215
+ ---`;
216
+
217
+ // Combine frontmatter + filled template content
218
+ Write(`${workDir}/product-brief.md`, `${frontmatter}\n\n${filledContent}`);
219
+
220
+ // Update spec-config.json
221
+ specConfig.phasesCompleted.push({
222
+ phase: 2,
223
+ name: "product-brief",
224
+ output_file: "product-brief.md",
225
+ completed_at: new Date().toISOString()
226
+ });
227
+ Write(`${workDir}/spec-config.json`, JSON.stringify(specConfig, null, 2));
228
+ ```
229
+
230
+ ### Step 5.5: Generate glossary.json
231
+
232
+ ```javascript
233
+ // Extract terminology from product brief and CLI analysis
234
+ // Generate structured glossary for cross-document consistency
235
+
236
+ const glossary = {
237
+ session_id: specConfig.session_id,
238
+ terms: [
239
+ // Extract from product brief content:
240
+ // - Key domain nouns from problem statement
241
+ // - User persona names
242
+ // - Technical terms from multi-perspective synthesis
243
+ // Each term should have:
244
+ // { term: "...", definition: "...", aliases: [], first_defined_in: "product-brief.md", category: "core|technical|business" }
245
+ ]
246
+ };
247
+
248
+ Write(`${workDir}/glossary.json`, JSON.stringify(glossary, null, 2));
249
+ ```
250
+
251
+ **Glossary Injection**: In all subsequent phase prompts, inject the following into the CONTEXT section:
252
+ ```
253
+ TERMINOLOGY GLOSSARY (use these terms consistently):
254
+ ${JSON.stringify(glossary.terms, null, 2)}
255
+ ```
256
+
257
+ ## Output
258
+
259
+ - **File**: `product-brief.md`
260
+ - **Format**: Markdown with YAML frontmatter
261
+
262
+ ## Quality Checklist
263
+
264
+ - [ ] Vision statement: clear, 1-3 sentences
265
+ - [ ] Problem statement: specific and measurable
266
+ - [ ] Target users: >= 1 persona with needs
267
+ - [ ] Goals: >= 2 with measurable metrics
268
+ - [ ] Scope: in-scope and out-of-scope defined
269
+ - [ ] Multi-perspective synthesis included
270
+ - [ ] YAML frontmatter valid
271
+
272
+ ## Next Phase
273
+
274
+ Proceed to [Phase 3: Requirements](03-requirements.md) with the generated product-brief.md.
@@ -0,0 +1,184 @@
1
+ # Phase 3: Requirements (PRD)
2
+
3
+ Generate a detailed Product Requirements Document with functional/non-functional requirements, acceptance criteria, and MoSCoW prioritization.
4
+
5
+ ## Objective
6
+
7
+ - Read product-brief.md and extract goals, scope, constraints
8
+ - Expand each goal into functional requirements with acceptance criteria
9
+ - Generate non-functional requirements
10
+ - Apply MoSCoW priority labels (user input or auto)
11
+ - Generate requirements.md using template
12
+
13
+ ## Input
14
+
15
+ - Dependency: `{workDir}/product-brief.md`
16
+ - Config: `{workDir}/spec-config.json`
17
+ - Template: `templates/requirements-prd.md` (directory structure: `_index.md` + `REQ-*.md` + `NFR-*.md`)
18
+
19
+ ## Execution Steps
20
+
21
+ ### Step 1: Load Phase 2 Context
22
+
23
+ ```javascript
24
+ const specConfig = JSON.parse(Read(`${workDir}/spec-config.json`));
25
+ const productBrief = Read(`${workDir}/product-brief.md`);
26
+
27
+ // Extract key sections from product brief
28
+ // - Goals & Success Metrics table
29
+ // - Scope (in-scope items)
30
+ // - Target Users (personas)
31
+ // - Constraints
32
+ // - Technical perspective insights
33
+ ```
34
+
35
+ ### Step 2: Requirements Expansion via Gemini CLI
36
+
37
+ ```javascript
38
+ Bash({
39
+ command: `ccw cli -p "PURPOSE: Generate detailed functional and non-functional requirements from product brief.
40
+ Success: Complete PRD with testable acceptance criteria for every requirement.
41
+
42
+ PRODUCT BRIEF CONTEXT:
43
+ ${productBrief}
44
+
45
+ TASK:
46
+ - For each goal in the product brief, generate 3-7 functional requirements
47
+ - Each requirement must have:
48
+ - Unique ID: REQ-NNN (zero-padded)
49
+ - Clear title
50
+ - Detailed description
51
+ - User story: As a [persona], I want [action] so that [benefit]
52
+ - 2-4 specific, testable acceptance criteria
53
+ - Generate non-functional requirements:
54
+ - Performance (response times, throughput)
55
+ - Security (authentication, authorization, data protection)
56
+ - Scalability (user load, data volume)
57
+ - Usability (accessibility, learnability)
58
+ - Assign initial MoSCoW priority based on:
59
+ - Must: Core functionality, cannot launch without
60
+ - Should: Important but has workaround
61
+ - Could: Nice-to-have, enhances experience
62
+ - Won't: Explicitly deferred
63
+ - Use RFC 2119 keywords (MUST, SHOULD, MAY, MUST NOT, SHOULD NOT) to define behavioral constraints for each requirement. Example: 'The system MUST return a 401 response within 100ms for invalid tokens.'
64
+ - For each core domain entity referenced in requirements, define its data model: fields, types, constraints, and relationships to other entities
65
+ - Maintain terminology consistency with the glossary below:
66
+ TERMINOLOGY GLOSSARY:
67
+ \${glossary ? JSON.stringify(glossary.terms, null, 2) : 'N/A - generate terms inline'}
68
+
69
+ MODE: analysis
70
+ EXPECTED: Structured requirements with: ID, title, description, user story, acceptance criteria, priority, traceability to goals
71
+ CONSTRAINTS: Every requirement must be specific enough to estimate and test. No vague requirements like 'system should be fast'.
72
+ " --tool gemini --mode analysis`,
73
+ run_in_background: true
74
+ });
75
+
76
+ // Wait for CLI result
77
+ ```
78
+
79
+ ### Step 3: User Priority Sorting (Interactive)
80
+
81
+ ```javascript
82
+ if (!autoMode) {
83
+ // Present requirements grouped by initial priority
84
+ // Allow user to adjust MoSCoW labels
85
+ AskUserQuestion({
86
+ questions: [
87
+ {
88
+ question: "Review the Must-Have requirements. Any that should be reprioritized?",
89
+ header: "Must-Have",
90
+ multiSelect: false,
91
+ options: [
92
+ { label: "All correct", description: "Must-have requirements are accurate" },
93
+ { label: "Too many", description: "Some should be Should/Could" },
94
+ { label: "Missing items", description: "Some Should requirements should be Must" }
95
+ ]
96
+ },
97
+ {
98
+ question: "What is the target MVP scope?",
99
+ header: "MVP Scope",
100
+ multiSelect: false,
101
+ options: [
102
+ { label: "Must-Have only (Recommended)", description: "MVP includes only Must requirements" },
103
+ { label: "Must + key Should", description: "Include critical Should items in MVP" },
104
+ { label: "Comprehensive", description: "Include all Must and Should" }
105
+ ]
106
+ }
107
+ ]
108
+ });
109
+ // Apply user adjustments to priorities
110
+ } else {
111
+ // Auto mode: accept CLI-suggested priorities as-is
112
+ }
113
+ ```
114
+
115
+ ### Step 4: Generate requirements/ directory
116
+
117
+ ```javascript
118
+ // Read template
119
+ const template = Read('templates/requirements-prd.md');
120
+
121
+ // Create requirements directory
122
+ Bash(`mkdir -p "${workDir}/requirements"`);
123
+
124
+ const status = autoMode ? 'complete' : 'draft';
125
+ const timestamp = new Date().toISOString();
126
+
127
+ // Parse CLI output into structured requirements
128
+ const funcReqs = parseFunctionalRequirements(cliOutput); // [{id, slug, title, priority, ...}]
129
+ const nfReqs = parseNonFunctionalRequirements(cliOutput); // [{id, type, slug, title, ...}]
130
+
131
+ // Step 4a: Write individual REQ-*.md files (one per functional requirement)
132
+ funcReqs.forEach(req => {
133
+ // Use REQ-NNN-{slug}.md template from templates/requirements-prd.md
134
+ // Fill: id, title, priority, description, user_story, acceptance_criteria, traces
135
+ Write(`${workDir}/requirements/REQ-${req.id}-${req.slug}.md`, reqContent);
136
+ });
137
+
138
+ // Step 4b: Write individual NFR-*.md files (one per non-functional requirement)
139
+ nfReqs.forEach(nfr => {
140
+ // Use NFR-{type}-NNN-{slug}.md template from templates/requirements-prd.md
141
+ // Fill: id, type, category, title, requirement, metric, target, traces
142
+ Write(`${workDir}/requirements/NFR-${nfr.type}-${nfr.id}-${nfr.slug}.md`, nfrContent);
143
+ });
144
+
145
+ // Step 4c: Write _index.md (summary + links to all individual files)
146
+ // Use _index.md template from templates/requirements-prd.md
147
+ // Fill: summary table, functional req links table, NFR links tables,
148
+ // data requirements, integration requirements, traceability matrix
149
+ Write(`${workDir}/requirements/_index.md`, indexContent);
150
+
151
+ // Update spec-config.json
152
+ specConfig.phasesCompleted.push({
153
+ phase: 3,
154
+ name: "requirements",
155
+ output_dir: "requirements/",
156
+ output_index: "requirements/_index.md",
157
+ file_count: funcReqs.length + nfReqs.length + 1,
158
+ completed_at: timestamp
159
+ });
160
+ Write(`${workDir}/spec-config.json`, JSON.stringify(specConfig, null, 2));
161
+ ```
162
+
163
+ ## Output
164
+
165
+ - **Directory**: `requirements/`
166
+ - `_index.md` — Summary, MoSCoW table, traceability matrix, links
167
+ - `REQ-NNN-{slug}.md` — Individual functional requirement (per requirement)
168
+ - `NFR-{type}-NNN-{slug}.md` — Individual non-functional requirement (per NFR)
169
+ - **Format**: Markdown with YAML frontmatter, cross-linked via relative paths
170
+
171
+ ## Quality Checklist
172
+
173
+ - [ ] Functional requirements: >= 3 with REQ-NNN IDs, each in own file
174
+ - [ ] Every requirement file has >= 1 acceptance criterion
175
+ - [ ] Every requirement has MoSCoW priority tag in frontmatter
176
+ - [ ] Non-functional requirements: >= 1, each in own file
177
+ - [ ] User stories present for Must-have requirements
178
+ - [ ] `_index.md` links to all individual requirement files
179
+ - [ ] Traceability links to product-brief.md goals
180
+ - [ ] All files have valid YAML frontmatter
181
+
182
+ ## Next Phase
183
+
184
+ Proceed to [Phase 4: Architecture](04-architecture.md) with the generated requirements.md.
@@ -0,0 +1,248 @@
1
+ # Phase 4: Architecture
2
+
3
+ Generate technical architecture decisions, component design, and technology selections based on requirements.
4
+
5
+ ## Objective
6
+
7
+ - Analyze requirements to identify core components and system architecture
8
+ - Generate Architecture Decision Records (ADRs) with alternatives
9
+ - Map architecture to existing codebase (if applicable)
10
+ - Challenge architecture via Codex CLI review
11
+ - Generate architecture.md using template
12
+
13
+ ## Input
14
+
15
+ - Dependency: `{workDir}/requirements/_index.md` (and individual `REQ-*.md` files)
16
+ - Reference: `{workDir}/product-brief.md`
17
+ - Optional: `{workDir}/discovery-context.json`
18
+ - Config: `{workDir}/spec-config.json`
19
+ - Template: `templates/architecture-doc.md`
20
+
21
+ ## Execution Steps
22
+
23
+ ### Step 1: Load Phase 2-3 Context
24
+
25
+ ```javascript
26
+ const specConfig = JSON.parse(Read(`${workDir}/spec-config.json`));
27
+ const productBrief = Read(`${workDir}/product-brief.md`);
28
+ const requirements = Read(`${workDir}/requirements.md`);
29
+
30
+ let discoveryContext = null;
31
+ if (specConfig.has_codebase) {
32
+ try {
33
+ discoveryContext = JSON.parse(Read(`${workDir}/discovery-context.json`));
34
+ } catch (e) { /* no context */ }
35
+ }
36
+
37
+ // Load glossary for terminology consistency
38
+ let glossary = null;
39
+ try {
40
+ glossary = JSON.parse(Read(`${workDir}/glossary.json`));
41
+ } catch (e) { /* proceed without */ }
42
+
43
+ // Load spec type profile for specialized sections
44
+ const specType = specConfig.spec_type || 'service';
45
+ let profile = null;
46
+ try {
47
+ profile = Read(`templates/profiles/${specType}-profile.md`);
48
+ } catch (e) { /* use base template only */ }
49
+ ```
50
+
51
+ ### Step 2: Architecture Analysis via Gemini CLI
52
+
53
+ ```javascript
54
+ Bash({
55
+ command: `ccw cli -p "PURPOSE: Generate technical architecture for the specified requirements.
56
+ Success: Complete component architecture, tech stack, and ADRs with justified decisions.
57
+
58
+ PRODUCT BRIEF (summary):
59
+ ${productBrief.slice(0, 3000)}
60
+
61
+ REQUIREMENTS:
62
+ ${requirements.slice(0, 5000)}
63
+
64
+ ${discoveryContext ? `EXISTING CODEBASE:
65
+ - Tech stack: ${JSON.stringify(discoveryContext.tech_stack || {})}
66
+ - Existing patterns: ${discoveryContext.existing_patterns?.slice(0,5).join('; ') || 'none'}
67
+ - Architecture constraints: ${discoveryContext.architecture_constraints?.slice(0,3).join('; ') || 'none'}
68
+ ` : ''}
69
+
70
+ TASK:
71
+ - Define system architecture style (monolith, microservices, serverless, etc.) with justification
72
+ - Identify core components and their responsibilities
73
+ - Create component interaction diagram (Mermaid graph TD format)
74
+ - Specify technology stack: languages, frameworks, databases, infrastructure
75
+ - Generate 2-4 Architecture Decision Records (ADRs):
76
+ - Each ADR: context, decision, 2-3 alternatives with pros/cons, consequences
77
+ - Focus on: data storage, API design, authentication, key technical choices
78
+ - Define data model: key entities and relationships (Mermaid erDiagram format)
79
+ - Identify security architecture: auth, authorization, data protection
80
+ - List API endpoints (high-level)
81
+ ${discoveryContext ? '- Map new components to existing codebase modules' : ''}
82
+ - For each core entity with a lifecycle, create an ASCII state machine diagram showing:
83
+ - All states and transitions
84
+ - Trigger events for each transition
85
+ - Side effects of transitions
86
+ - Error states and recovery paths
87
+ - Define a Configuration Model: list all configurable fields with name, type, default value, constraint, and description
88
+ - Define Error Handling strategy:
89
+ - Classify errors (transient/permanent/degraded)
90
+ - Per-component error behavior using RFC 2119 keywords
91
+ - Recovery mechanisms
92
+ - Define Observability requirements:
93
+ - Key metrics (name, type: counter/gauge/histogram, labels)
94
+ - Structured log format and key log events
95
+ - Health check endpoints
96
+ \${profile ? \`
97
+ SPEC TYPE PROFILE REQUIREMENTS (\${specType}):
98
+ \${profile}
99
+ \` : ''}
100
+ \${glossary ? \`
101
+ TERMINOLOGY GLOSSARY (use consistently):
102
+ \${JSON.stringify(glossary.terms, null, 2)}
103
+ \` : ''}
104
+
105
+ MODE: analysis
106
+ EXPECTED: Complete architecture with: style justification, component diagram, tech stack table, ADRs, data model, security controls, API overview
107
+ CONSTRAINTS: Architecture must support all Must-have requirements. Prefer proven technologies over cutting-edge.
108
+ " --tool gemini --mode analysis`,
109
+ run_in_background: true
110
+ });
111
+
112
+ // Wait for CLI result
113
+ ```
114
+
115
+ ### Step 3: Architecture Review via Codex CLI
116
+
117
+ ```javascript
118
+ // After receiving Gemini analysis, challenge it with Codex
119
+ Bash({
120
+ command: `ccw cli -p "PURPOSE: Critical review of proposed architecture - identify weaknesses and risks.
121
+ Success: Actionable feedback with specific concerns and improvement suggestions.
122
+
123
+ PROPOSED ARCHITECTURE:
124
+ ${geminiArchitectureOutput.slice(0, 5000)}
125
+
126
+ REQUIREMENTS CONTEXT:
127
+ ${requirements.slice(0, 2000)}
128
+
129
+ TASK:
130
+ - Challenge each ADR: are the alternatives truly the best options?
131
+ - Identify scalability bottlenecks in the component design
132
+ - Assess security gaps: authentication, authorization, data protection
133
+ - Evaluate technology choices: maturity, community support, fit
134
+ - Check for over-engineering or under-engineering
135
+ - Verify architecture covers all Must-have requirements
136
+ - Rate overall architecture quality: 1-5 with justification
137
+
138
+ MODE: analysis
139
+ EXPECTED: Architecture review with: per-ADR feedback, scalability concerns, security gaps, technology risks, quality rating
140
+ CONSTRAINTS: Be genuinely critical, not just validating. Focus on actionable improvements.
141
+ " --tool codex --mode analysis`,
142
+ run_in_background: true
143
+ });
144
+
145
+ // Wait for CLI result
146
+ ```
147
+
148
+ ### Step 4: Interactive ADR Decisions (Optional)
149
+
150
+ ```javascript
151
+ if (!autoMode) {
152
+ // Present ADRs with review feedback to user
153
+ // For each ADR where review raised concerns:
154
+ AskUserQuestion({
155
+ questions: [
156
+ {
157
+ question: "Architecture review raised concerns. How should we proceed?",
158
+ header: "ADR Review",
159
+ multiSelect: false,
160
+ options: [
161
+ { label: "Accept as-is", description: "Architecture is sound, proceed" },
162
+ { label: "Incorporate feedback", description: "Adjust ADRs based on review" },
163
+ { label: "Simplify", description: "Reduce complexity, fewer components" }
164
+ ]
165
+ }
166
+ ]
167
+ });
168
+ // Apply user decisions to architecture
169
+ }
170
+ ```
171
+
172
+ ### Step 5: Codebase Integration Mapping (Conditional)
173
+
174
+ ```javascript
175
+ if (specConfig.has_codebase && discoveryContext) {
176
+ // Map new architecture components to existing code
177
+ const integrationMapping = discoveryContext.relevant_files.map(f => ({
178
+ new_component: "...", // matched from architecture
179
+ existing_module: f.path,
180
+ integration_type: "Extend|Replace|New",
181
+ notes: f.rationale
182
+ }));
183
+ // Include in architecture document
184
+ }
185
+ ```
186
+
187
+ ### Step 6: Generate architecture/ directory
188
+
189
+ ```javascript
190
+ const template = Read('templates/architecture-doc.md');
191
+
192
+ // Create architecture directory
193
+ Bash(`mkdir -p "${workDir}/architecture"`);
194
+
195
+ const status = autoMode ? 'complete' : 'draft';
196
+ const timestamp = new Date().toISOString();
197
+
198
+ // Parse CLI outputs into structured ADRs
199
+ const adrs = parseADRs(geminiArchitectureOutput, codexReviewOutput); // [{id, slug, title, ...}]
200
+
201
+ // Step 6a: Write individual ADR-*.md files (one per decision)
202
+ adrs.forEach(adr => {
203
+ // Use ADR-NNN-{slug}.md template from templates/architecture-doc.md
204
+ // Fill: id, title, status, context, decision, alternatives, consequences, traces
205
+ Write(`${workDir}/architecture/ADR-${adr.id}-${adr.slug}.md`, adrContent);
206
+ });
207
+
208
+ // Step 6b: Write _index.md (overview + components + tech stack + links to ADRs)
209
+ // Use _index.md template from templates/architecture-doc.md
210
+ // Fill: system overview, component diagram, tech stack, ADR links table,
211
+ // data model, API design, security controls, infrastructure, codebase integration
212
+ Write(`${workDir}/architecture/_index.md`, indexContent);
213
+
214
+ // Update spec-config.json
215
+ specConfig.phasesCompleted.push({
216
+ phase: 4,
217
+ name: "architecture",
218
+ output_dir: "architecture/",
219
+ output_index: "architecture/_index.md",
220
+ file_count: adrs.length + 1,
221
+ completed_at: timestamp
222
+ });
223
+ Write(`${workDir}/spec-config.json`, JSON.stringify(specConfig, null, 2));
224
+ ```
225
+
226
+ ## Output
227
+
228
+ - **Directory**: `architecture/`
229
+ - `_index.md` — Overview, component diagram, tech stack, data model, security, links
230
+ - `ADR-NNN-{slug}.md` — Individual Architecture Decision Record (per ADR)
231
+ - **Format**: Markdown with YAML frontmatter, cross-linked to requirements via relative paths
232
+
233
+ ## Quality Checklist
234
+
235
+ - [ ] Component diagram present in `_index.md` (Mermaid or ASCII)
236
+ - [ ] Tech stack specified (languages, frameworks, key libraries)
237
+ - [ ] >= 1 ADR file with alternatives considered
238
+ - [ ] Each ADR file lists >= 2 options
239
+ - [ ] `_index.md` ADR table links to all individual ADR files
240
+ - [ ] Integration points identified
241
+ - [ ] Data model described
242
+ - [ ] Codebase mapping present (if has_codebase)
243
+ - [ ] All files have valid YAML frontmatter
244
+ - [ ] ADR files link back to requirement files
245
+
246
+ ## Next Phase
247
+
248
+ Proceed to [Phase 5: Epics & Stories](05-epics-stories.md) with the generated architecture.md.