@crewpilot/agent 1.0.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.
@@ -0,0 +1,270 @@
1
+ # Feature Builder
2
+
3
+ > **Pillar**: Engineer | **ID**: `engineer-feature-builder`
4
+
5
+ ## Purpose
6
+
7
+ The **primary entry point** for implementation requests. Handles everything from "add a loading spinner" to "build a notification system" by auto-classifying complexity and scaling ceremony accordingly. Infers what it can, confirms briefly, asks only when genuinely ambiguous.
8
+
9
+ ## Activation Triggers
10
+
11
+ - "build this feature", "implement", "scaffold", "create a new"
12
+ - "add functionality", "develop", "code this up"
13
+ - "can you implement", "make this work", "add X to Y"
14
+ - After `architecture-planner` defines a milestone to implement
15
+
16
+ ## Methodology
17
+
18
+ ### Process Flow
19
+
20
+ ```dot
21
+ digraph feature_builder {
22
+ rankdir=TB;
23
+ node [shape=box];
24
+
25
+ triage [label="Phase 0\nComplexity Triage\n(universal entry point)", shape=diamond, style=filled, fillcolor="#ffffcc"];
26
+ trivial [label="Trivial\nJust build it"];
27
+ simple [label="Simple\nState approach → build"];
28
+ moderate_route [label="Route to\nautopilot-worker\n(monolith)", shape=hexagon, style=filled, fillcolor="#cce5ff"];
29
+ complex_route [label="Route to\nautopilot-worker\n(full ceremony)", shape=hexagon, style=filled, fillcolor="#cce5ff"];
30
+ user_skip [label="User says\n'just build it'", shape=diamond];
31
+ clarify [label="Phase 1\nRequirement Clarification"];
32
+ plan [label="Phase 2\nImplementation Plan"];
33
+ scaffold [label="Phase 3\nScaffold"];
34
+ implement [label="Phase 4\nImplement"];
35
+ escalate [label="Mid-build escalation\n'this is bigger than expected'", shape=diamond, style=filled, fillcolor="#ffe0cc"];
36
+ verify [label="Phase 5\nVerify", shape=diamond, style=filled, fillcolor="#ccffcc"];
37
+ done [label="Done + Hints", shape=doublecircle];
38
+ fix [label="Fix Issues"];
39
+
40
+ triage -> trivial [label="1 file\nclear intent"];
41
+ triage -> simple [label="1-3 files\nobvious pattern"];
42
+ triage -> moderate_route [label="3-10 files\nmulti-concern"];
43
+ triage -> complex_route [label="10+ files\nnew system"];
44
+ triage -> trivial [label="user overrides\n'just do it'", style=dashed];
45
+ moderate_route -> user_skip [label="user says\nskip ceremony"];
46
+ user_skip -> clarify [label="yes"];
47
+ complex_route -> user_skip [label="user says\nskip ceremony"];
48
+ trivial -> implement;
49
+ simple -> implement;
50
+ clarify -> plan;
51
+ plan -> scaffold;
52
+ scaffold -> implement;
53
+ implement -> escalate [label="discovers more\ncomplexity"];
54
+ escalate -> moderate_route [label="user agrees\nto escalate"];
55
+ escalate -> implement [label="user says\ncontinue"];
56
+ implement -> verify;
57
+ verify -> done [label="all checks pass"];
58
+ verify -> fix [label="tests/lint fail"];
59
+ fix -> verify;
60
+ }
61
+ ```
62
+
63
+ ### Phase 0 — Complexity Triage
64
+
65
+ **This is the universal entry point for all implementation requests.** Before anything else, scan the codebase and classify the request. Announce the routing decision in one line so the user knows what's happening.
66
+
67
+ #### Override Rules
68
+ - If the user explicitly says "autopilot", "full pipeline", "end to end" → route directly to `autopilot-worker`, skip triage.
69
+ - If the user provides a board issue number ("#42") → route to `autopilot-worker` (issue already has structure).
70
+ - If the user says "just do it", "skip ceremony", "don't overthink it" → stay in feature-builder regardless of complexity.
71
+
72
+ #### Routing Signals
73
+
74
+ | Signal | How to Detect | Weight |
75
+ |---|---|---|
76
+ | **Files likely touched** | Scan codebase for probable touch points | 1 = trivial, 1-3 = simple, 3-10 = moderate, 10+ = complex |
77
+ | **Ambiguity** | Is the request specific or open-ended? | Clear = lower, vague = higher |
78
+ | **Architectural impact** | Isolated module or cross-cutting? | Isolated = lower, new system = higher |
79
+ | **Existing patterns** | Follows known pattern or novel? | Known = lower, novel = higher |
80
+ | **External dependencies** | New packages, services, APIs? | None = lower, new deps = higher |
81
+ | **Keywords** | "system", "architecture", "service", "pipeline", "integration" | Push toward complex |
82
+ | **Board context** | Issue has `needs-design` or `needs-architecture` label? | → complex |
83
+
84
+ #### Tier Assignment & Routing
85
+
86
+ #### Trivial (1 file, clear intent, < 30 min)
87
+ > Examples: "add a loading spinner", "fix the typo in the header", "make the button blue"
88
+
89
+ **Route: feature-builder (this skill) — skip to Phase 4.**
90
+
91
+ - **Do not ask questions.** Just implement.
92
+ - Announce: *"Small change — implementing directly."*
93
+ - Skip Phases 1-3. Go directly to Phase 4 (Implement) → Phase 5 (Verify).
94
+
95
+ #### Simple (1-3 files, well-understood pattern)
96
+ > Examples: "add input validation to the signup form", "add a 404 page"
97
+
98
+ **Route: feature-builder (this skill) — Phase 1 brief → Phase 4.**
99
+
100
+ - State your approach in 2-3 sentences. Include which files you'll touch.
101
+ - Ask **at most 1** clarifying question — only if there's genuine ambiguity.
102
+ - Skip Phase 3 (Scaffold).
103
+
104
+ #### Moderate (3-10 files, some ambiguity, multi-concern)
105
+ > Examples: "add pagination to all API endpoints", "implement role-based access"
106
+
107
+ **Route: autopilot-worker (board tracking + plan approval + review pipeline).**
108
+
109
+ Announce:
110
+ > *"This touches ~{N} files across {concerns}. I'd like to route this to the full pipeline — I'll first confirm the task details with you, create a board issue, plan the work, and get your approval before building. [Say 'just build it' to skip the pipeline.]"*
111
+
112
+ - If user says "just build it" → stay in feature-builder, run Phases 1-5 with inferred acceptance criteria.
113
+ - Otherwise → hand off to `autopilot-worker` with the request context. The worker will confirm the task before creating a board issue.
114
+
115
+ #### Complex (10+ files, new system, architectural decisions)
116
+ > Examples: "build a notification system with email + webhooks", "add multi-tenancy"
117
+
118
+ **Route: autopilot-worker (full ceremony with design/architecture phases).**
119
+
120
+ Announce:
121
+ > *"This is a significant change — new {system/component} touching {N} areas. Routing to full autopilot with design phase. [Say 'just build it' to skip ceremony and I'll use my best judgment.]"*
122
+
123
+ - If user says "just build it" → stay in feature-builder, proceed with best-judgment approach, note assumptions explicitly.
124
+ - Otherwise → hand off to `autopilot-worker`. If the request signals design needs, suggest adding `needs-design` or `needs-architecture` labels to trigger those phases.
125
+
126
+ **The golden rule: Infer first, confirm second, ask last.**
127
+ - Can you infer acceptance criteria? → Generate them, show briefly inline.
128
+ - Can you infer the approach from codebase patterns? → State it, proceed.
129
+ - Is there genuine ambiguity with divergent outcomes? → Ask ONE question.
130
+ - Never block on info the agent can figure out from the codebase.
131
+
132
+ ### Phase 1 — Requirement Clarification
133
+ *(Skipped for trivial tier. Brief for simple tier. Full for moderate/complex.)*
134
+
135
+ 1. Restate the feature in one sentence
136
+ 2. **Generate** acceptance criteria from the request + codebase context — show them inline, don't ask the user to write them:
137
+ > *"Based on your request and the codebase, here's what 'done' looks like: [criteria]. Sound right?"*
138
+ 3. List inputs, outputs, and side effects
139
+ 4. Scan existing codebase for related code: similar features, shared patterns, reusable utilities
140
+ 5. Ask ONE clarifying question if genuinely ambiguous. Otherwise, proceed.
141
+
142
+ ### Phase 2 — Implementation Plan
143
+ 1. List files to create/modify (with specific changes per file)
144
+ 2. Identify the dependency order — what must be built first
145
+ 3. Flag external dependencies that need installing
146
+ 4. Determine if existing patterns should be followed or if this is a new pattern
147
+
148
+ Present as an ordered task list:
149
+ ```
150
+ 1. [ ] Create {file} — {purpose}
151
+ 2. [ ] Modify {file} — {what changes}
152
+ 3. [ ] Add tests in {file} — {what to test}
153
+ ```
154
+
155
+ ### Phase 3 — Scaffold
156
+ 1. Create file skeletons with proper structure (exports, imports, type signatures)
157
+ 2. Add TODO comments at implementation points
158
+ 3. Follow existing project conventions (naming, file organization, import style)
159
+ 4. If `scaffold_tests` is enabled in config, create test file skeletons alongside
160
+
161
+ ### Phase 4 — Implement
162
+ 1. Fill in implementation file by file, following the dependency order
163
+ 2. Each function: write the signature → implement core logic → handle edge cases → add error handling
164
+ 3. Use existing utilities — do NOT reinvent what already exists in the codebase
165
+ 4. Keep functions focused — if a function grows beyond ~25 lines, consider splitting
166
+
167
+ **Mid-build escalation check:** During implementation, if you discover the task is significantly larger than estimated:
168
+ - Touching more files than expected (e.g., triaged as simple but now touching 6+ files)
169
+ - Encountering architectural decisions that weren't apparent upfront
170
+ - Realizing the change has cross-cutting impact (auth, DB schema, public APIs)
171
+
172
+ Then **pause and offer escalation:**
173
+ > *"This is more involved than expected — I'm now touching {N} files and there's {concern}. Want me to switch to the full pipeline with board tracking, a proper plan, and review? Or should I continue as-is?"*
174
+
175
+ - If user says **"switch"** / **"escalate"** → hand off to `autopilot-worker` with: what's been discovered so far (files examined, patterns found, partial understanding). The worker enters at Phase 2 (planning) with this context.
176
+ - If user says **"continue"** → proceed with implementation, but note the scope change in the final output.
177
+
178
+ ### Phase 5 — Verify
179
+
180
+ <HARD-GATE>
181
+ Do NOT declare the feature complete until all verification checks pass.
182
+ Do NOT skip test execution, lint checks, or the self-review against acceptance criteria.
183
+ If any check fails, fix it before proceeding.
184
+ </HARD-GATE>
185
+
186
+ 1. Run existing tests to ensure nothing broke
187
+ 2. Run the new tests
188
+ 3. Check for TypeScript/lint errors
189
+ 4. Self-review: does this implementation match the acceptance criteria?
190
+
191
+ ## Tools Required
192
+
193
+ - `codebase` — Understand existing structure, find reusable code
194
+ - `terminal` — Install dependencies, run tests, run linters
195
+ - `findTestFiles` — Locate existing test patterns
196
+ - `catalyst_metrics_coverage` — Verify coverage after implementation
197
+
198
+ ## Output Format
199
+
200
+ ```
201
+ ## [Catalyst → Feature Builder]
202
+
203
+ ### Feature: {name}
204
+ **Acceptance criteria**: {list}
205
+
206
+ ### Plan
207
+ {ordered task list}
208
+
209
+ ### Changes Made
210
+ | File | Action | Description |
211
+ |---|---|---|
212
+ | {path} | Created/Modified | {what} |
213
+
214
+ ### Verification
215
+ - Tests: {pass/fail count}
216
+ - Lint: {clean/issues}
217
+ - Coverage: {%}
218
+ ```
219
+
220
+ ## Chains To
221
+
222
+ - `autopilot-worker` — Phase 0 routes moderate/complex tasks to the full pipeline; Phase 4 escalates mid-build if complexity grows
223
+ - `solution-design` — When Phase 0 detects complex tier and user wants design exploration
224
+ - `architecture-planner` — When Phase 0 detects complex tier with architectural impact
225
+ - `test-first` — If TDD enforcement is strict, chains BEFORE implementation
226
+ - `change-management` — Commit the completed feature
227
+ - `doc-governance` — Update docs if the feature changes public APIs
228
+
229
+ ## Capability Hints
230
+
231
+ After completing work, append **one** contextual hint to the response based on what the user just did. Show each hint **at most once per session**. Place it after the main output, never before. Keep it to one line.
232
+
233
+ | Context | Hint |
234
+ |---|---|
235
+ | User said "implement X" without a board issue | 💡 *I can also track this as a board issue and manage the full lifecycle — say "autopilot" next time.* |
236
+ | Code was implemented but not committed | 💡 *I can generate conventional commits and split multi-concern changes — say "commit this".* |
237
+ | Implementation touched public APIs or config | 💡 *I can check if your docs are out of sync with the code — say "check docs".* |
238
+ | Bug was fixed | 💡 *I can run a systematic root cause analysis to find the real cause, not just the symptom — say "debug this" next time.* |
239
+ | Tests were not written (no test framework or user declined) | 💡 *I can enforce TDD — write failing tests first, then implement — say "test first" next time.* |
240
+ | Complex feature completed | 💡 *I can run code quality, security scan, and deploy readiness checks — say "review this" or "ready to deploy?".* |
241
+ | First interaction in session | 💡 *I'm Catalyst — I can plan, build, test, review, and ship code end-to-end. Say "autopilot" for the full pipeline, or just tell me what to build.* |
242
+
243
+ **Rules:**
244
+ - One hint per response, max. Never stack multiple hints.
245
+ - Do the work first, hint after. Hints never block or delay the output.
246
+ - Include the activation phrase so the user knows what to say.
247
+ - If the user has already used the hinted feature in this session, skip the hint.
248
+
249
+ ## Anti-Patterns
250
+
251
+ - Do NOT start coding before scanning existing patterns
252
+ - Do NOT create utilities that already exist in the codebase
253
+ - Do NOT skip the verification phase
254
+ - Do NOT implement everything in one massive file
255
+ - Do NOT add features beyond what was requested
256
+
257
+ ## No Placeholders
258
+
259
+ Every step in a plan and every file produced must contain real, working content. The following are **plan failures** — never write them:
260
+
261
+ | Forbidden Pattern | Why It Fails |
262
+ |---|---|
263
+ | "TBD", "TODO", "implement later" | Defers work that should be done now |
264
+ | "Add appropriate error handling" | Vague — specify which errors and how to handle them |
265
+ | "Add validation" | Which inputs? What rules? What error messages? |
266
+ | "Handle edge cases" | Name the edge cases or don't mention them |
267
+ | "Write tests for the above" | Show the actual test code |
268
+ | "Similar to Task N" | Repeat the code — the reader may not have Task N context |
269
+ | Steps without code blocks | If a step changes code, show the code |
270
+ | References to undefined types/functions | Every symbol must be defined in a task |
@@ -0,0 +1,150 @@
1
+ # Root Cause Analysis
2
+
3
+ > **Pillar**: Engineer | **ID**: `engineer-root-cause-analysis`
4
+
5
+ ## Purpose
6
+
7
+ Systematic debugging that finds the actual root cause, not just the symptom. Uses a structured hypothesis-test-eliminate approach with a maximum attempt budget to prevent rabbit holes.
8
+
9
+ ## Activation Triggers
10
+
11
+ - "debug this", "fix this error", "why is this crashing", "investigate"
12
+ - "root cause", "not working", "broken", "unexpected behavior"
13
+ - Any error message, stack trace, or unexpected output
14
+
15
+ ## Methodology
16
+
17
+ ### Process Flow
18
+
19
+ ```dot
20
+ digraph root_cause_analysis {
21
+ rankdir=TB;
22
+ node [shape=box];
23
+
24
+ symptoms [label="Phase 1\nSymptom Collection"];
25
+ hypotheses [label="Phase 2\nHypothesis Generation\n(2-3 ranked)"];
26
+ eliminate [label="Phase 3\nSystematic Elimination", shape=diamond];
27
+ root_cause [label="Phase 4\nRoot Cause Identified"];
28
+ fix [label="Phase 5\nFix Implementation"];
29
+ prevent [label="Phase 6\nPrevention", shape=doublecircle];
30
+ escalate [label="Escalate to Human", shape=octagon, style=filled, fillcolor="#ff9999"];
31
+
32
+ symptoms -> hypotheses;
33
+ hypotheses -> eliminate;
34
+ eliminate -> root_cause [label="confirmed"];
35
+ eliminate -> hypotheses [label="all eliminated\nrefine"];
36
+ eliminate -> escalate [label="max_attempts\nreached"];
37
+ root_cause -> fix;
38
+ fix -> prevent;
39
+ }
40
+ ```
41
+
42
+ ### Phase 1 — Symptom Collection
43
+ 1. Gather all available evidence:
44
+ - Error message / stack trace
45
+ - Steps to reproduce
46
+ - When it started (recent changes?)
47
+ - Environment details (dev/staging/prod, OS, runtime version)
48
+ 2. Reproduce the issue if possible (run the failing code/test)
49
+ 3. Check git log for recent changes to affected files
50
+
51
+ ### Phase 2 — Hypothesis Generation
52
+ Generate 2-3 ranked hypotheses:
53
+
54
+ | # | Hypothesis | Likelihood | Evidence | How to Test |
55
+ |---|---|---|---|---|
56
+ | H1 | {most likely cause} | High | {what points here} | {test strategy} |
57
+ | H2 | {alternative cause} | Medium | {what points here} | {test strategy} |
58
+ | H3 | {edge case cause} | Low | {what points here} | {test strategy} |
59
+
60
+ ### Phase 3 — Systematic Elimination
61
+ For each hypothesis (highest likelihood first):
62
+ 1. **Test**: Run the specific validation (add logging, modify input, check state)
63
+ 2. **Observe**: What happened? Does it confirm or eliminate?
64
+ 3. **Record**: Document result before moving to next hypothesis
65
+ 4. **Refine**: If partially confirmed, narrow the hypothesis
66
+
67
+ Track progress:
68
+ ```
69
+ Attempt 1/5: Testing H1 — {result} → {confirmed/eliminated/narrowed}
70
+ Attempt 2/5: Testing H2 — {result} → {confirmed/eliminated/narrowed}
71
+ ```
72
+
73
+ Stop at `max_attempts` from config (default: 5). If root cause not found, report what was eliminated and recommend next steps.
74
+
75
+ ### Phase 4 — Root Cause Identification
76
+ When found:
77
+ 1. State the root cause in one sentence
78
+ 2. Explain the causal chain: trigger → intermediate effects → symptom
79
+ 3. Explain WHY the code was vulnerable to this (design gap, missing validation, etc.)
80
+
81
+ ### Phase 5 — Fix Implementation
82
+
83
+ <HARD-GATE>
84
+ Do NOT implement a fix until the root cause has been identified in Phase 4.
85
+ Do NOT fix symptoms — the fix MUST address the root cause.
86
+ If the root cause is still unknown after max_attempts, escalate to human instead of guessing.
87
+ </HARD-GATE>
88
+
89
+ 1. Implement the minimal fix
90
+ 2. Add a regression test that fails without the fix
91
+ 3. Run the full test suite to verify no regressions
92
+ 4. If the fix reveals a systemic issue, note it for `pattern-detection`
93
+
94
+ ### Phase 6 — Prevention
95
+ 1. Identify what would have caught this earlier (better tests, type safety, validation)
96
+ 2. Suggest ONE concrete prevention measure
97
+
98
+ ## Tools Required
99
+
100
+ - `codebase` — Read failing code, trace call chains
101
+ - `terminal` — Run code, execute tests, check logs
102
+ - `catalyst_git_log` — Check recent changes
103
+ - `catalyst_git_diff` — Compare working vs. broken state
104
+
105
+ ## Output Format
106
+
107
+ ```
108
+ ## [Catalyst → Root Cause Analysis]
109
+
110
+ ### Symptom
111
+ {error/behavior description}
112
+
113
+ ### Investigation
114
+ {hypothesis table}
115
+
116
+ ### Elimination Log
117
+ {attempt-by-attempt results}
118
+
119
+ ### Root Cause
120
+ **{one sentence}**
121
+
122
+ Causal chain:
123
+ {trigger} → {intermediate} → {symptom}
124
+
125
+ **Design gap**: {why code was vulnerable}
126
+
127
+ ### Fix
128
+ {code change with explanation}
129
+
130
+ ### Regression Test
131
+ {test that validates the fix}
132
+
133
+ ### Prevention
134
+ {one concrete measure}
135
+ ```
136
+
137
+ ## Chains To
138
+
139
+ - `test-first` — Write the regression test
140
+ - `code-quality` — Review the fix for quality
141
+ - `pattern-detection` — If this reveals a systemic issue
142
+ - `knowledge-base` — Store the root cause for future reference
143
+
144
+ ## Anti-Patterns
145
+
146
+ - Do NOT guess the fix without testing hypotheses
147
+ - Do NOT exceed max_attempts — report what you know and escalate
148
+ - Do NOT fix the symptom without finding the root cause
149
+ - Do NOT skip the regression test
150
+ - Do NOT modify code while investigating (observe first, fix after)
@@ -0,0 +1,148 @@
1
+ # Test First
2
+
3
+ > **Pillar**: Engineer | **ID**: `engineer-test-first`
4
+
5
+ ## Purpose
6
+
7
+ Test-Driven Development enforcement. Write tests before implementation, use tests as specification, achieve meaningful coverage — not vanity metrics.
8
+
9
+ ## Activation Triggers
10
+
11
+ - "write tests", "TDD", "test first", "unit test", "test coverage"
12
+ - "add test cases", "what should I test"
13
+ - Automatically chained before `feature-builder` when enforcement is `strict`
14
+
15
+ ## Methodology
16
+
17
+ ### Process Flow
18
+
19
+ ```dot
20
+ digraph test_first {
21
+ rankdir=LR;
22
+ node [shape=box];
23
+
24
+ strategy [label="Phase 1\nTest Strategy"];
25
+ design [label="Phase 2\nTest Case Design"];
26
+ red [label="Phase 3\nRED\nWrite Failing Tests", style=filled, fillcolor="#ffcccc"];
27
+ green [label="Phase 4\nGREEN\nMinimal Implementation", style=filled, fillcolor="#ccffcc"];
28
+ refactor [label="Phase 5\nREFACTOR\nClean Up", style=filled, fillcolor="#ccccff"];
29
+ coverage [label="Phase 6\nCoverage Check"];
30
+ next [label="Next behavior", shape=ellipse];
31
+
32
+ strategy -> design;
33
+ design -> red;
34
+ red -> red [label="test passes\nimmediately?\nfix test"];
35
+ red -> green [label="test fails\ncorrectly"];
36
+ green -> green [label="test still fails?\nfix code"];
37
+ green -> refactor [label="all pass"];
38
+ refactor -> green [label="test broke?\nfix"];
39
+ refactor -> coverage;
40
+ coverage -> next [label="more behaviors"];
41
+ next -> red;
42
+ }
43
+ ```
44
+
45
+ ### Phase 1 — Test Strategy
46
+ 1. Identify what's being tested: function, class, API endpoint, workflow
47
+ 2. Determine test type needed:
48
+ - **Unit**: Isolated function/method behavior
49
+ - **Integration**: Component interactions, API calls, DB queries
50
+ - **E2E**: Full user journey (only when explicitly requested)
51
+ 3. Follow existing test patterns in the project (framework, naming, file location)
52
+ 4. Locate the test runner config and understand the test command
53
+
54
+ ### Phase 2 — Test Case Design
55
+ For each function/component, design test cases across:
56
+
57
+ | Category | Examples |
58
+ |---|---|
59
+ | **Happy path** | Valid inputs producing expected outputs |
60
+ | **Edge cases** | Empty inputs, boundary values, single element, max size |
61
+ | **Error cases** | Invalid inputs, null/undefined, malformed data |
62
+ | **State transitions** | Before/after, concurrent access, cleanup |
63
+
64
+ Present as a test plan:
65
+ ```
66
+ describe('{subject}')
67
+ ✓ should {expected behavior} when {condition}
68
+ ✓ should {expected behavior} when {edge case}
69
+ ✗ should throw/return error when {invalid condition}
70
+ ```
71
+
72
+ ### Phase 3 — Red (Write Failing Tests)
73
+
74
+ <HARD-GATE>
75
+ Do NOT write any production/implementation code until failing tests exist.
76
+ If you find yourself writing implementation first, STOP, delete it, and write the test.
77
+ Tests MUST fail before any implementation begins. No exceptions.
78
+ </HARD-GATE>
79
+
80
+ 1. Write the test cases with proper assertions
81
+ 2. Use descriptive test names that read as specifications
82
+ 3. Set up fixtures/mocks using the project's existing patterns
83
+ 4. Run the tests — they MUST fail (red phase)
84
+ 5. If tests pass immediately, they're not testing new behavior
85
+
86
+ ### Phase 4 — Green (Minimal Implementation)
87
+ 1. Write the minimum code to make tests pass
88
+ 2. No optimization, no elegance — just make it work
89
+ 3. Run tests — all must pass
90
+
91
+ ### Phase 5 — Refactor
92
+ 1. Clean up the implementation while tests stay green
93
+ 2. Remove duplication
94
+ 3. Improve naming
95
+ 4. Extract helpers if needed
96
+ 5. Run tests after each refactor step
97
+
98
+ ### Phase 6 — Coverage Check
99
+ 1. Run coverage tool
100
+ 2. Check against `min_coverage` from config (default: 80%)
101
+ 3. Identify uncovered branches — add tests only for meaningful gaps
102
+ 4. Do NOT chase 100% — test behavior, not lines
103
+
104
+ ## Tools Required
105
+
106
+ - `codebase` — Find existing test patterns, test config
107
+ - `findTestFiles` — Locate related test files
108
+ - `terminal` — Run tests, run coverage
109
+ - `catalyst_metrics_coverage` — Get coverage report
110
+
111
+ ## Output Format
112
+
113
+ ```
114
+ ## [Catalyst → Test First]
115
+
116
+ ### Test Strategy
117
+ - Type: {unit/integration/e2e}
118
+ - Framework: {detected framework}
119
+ - Test file: {path}
120
+
121
+ ### Test Plan
122
+ {describe/it outline}
123
+
124
+ ### Results
125
+ | Phase | Status |
126
+ |---|---|
127
+ | Red (failing tests) | {N} tests written, all fail ✓ |
128
+ | Green (passing) | All {N} pass ✓ |
129
+ | Refactor | Clean, tests still pass ✓ |
130
+ | Coverage | {%} (target: {min_coverage}%) |
131
+
132
+ ### Tests Written
133
+ {list of test files created/modified}
134
+ ```
135
+
136
+ ## Chains To
137
+
138
+ - `feature-builder` — After tests are written, implement the feature
139
+ - `code-quality` — Review the implementation after TDD cycle
140
+ - `change-management` — Commit the TDD cycle
141
+
142
+ ## Anti-Patterns
143
+
144
+ - Do NOT write tests after implementation and call it TDD
145
+ - Do NOT mock everything — test real behavior where feasible
146
+ - Do NOT write tests that test the framework instead of your code
147
+ - Do NOT skip the red phase — every test must fail first
148
+ - Do NOT chase coverage numbers with meaningless assertions