@harness-engineering/cli 1.2.0 → 1.3.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 (52) hide show
  1. package/dist/bin/harness.js +1 -1
  2. package/dist/{chunk-IXT3KLVN.js → chunk-APYEWOCR.js} +355 -19
  3. package/dist/index.js +1 -1
  4. package/package.json +6 -4
  5. package/dist/agents/commands/claude-code/harness/add-component.md +0 -34
  6. package/dist/agents/commands/claude-code/harness/align-documentation.md +0 -33
  7. package/dist/agents/commands/claude-code/harness/architecture-advisor.md +0 -41
  8. package/dist/agents/commands/claude-code/harness/brainstorming.md +0 -42
  9. package/dist/agents/commands/claude-code/harness/check-mechanical-constraints.md +0 -32
  10. package/dist/agents/commands/claude-code/harness/cleanup-dead-code.md +0 -33
  11. package/dist/agents/commands/claude-code/harness/code-review.md +0 -33
  12. package/dist/agents/commands/claude-code/harness/debugging.md +0 -43
  13. package/dist/agents/commands/claude-code/harness/detect-doc-drift.md +0 -32
  14. package/dist/agents/commands/claude-code/harness/diagnostics.md +0 -43
  15. package/dist/agents/commands/claude-code/harness/enforce-architecture.md +0 -32
  16. package/dist/agents/commands/claude-code/harness/execution.md +0 -43
  17. package/dist/agents/commands/claude-code/harness/git-workflow.md +0 -32
  18. package/dist/agents/commands/claude-code/harness/initialize-project.md +0 -33
  19. package/dist/agents/commands/claude-code/harness/onboarding.md +0 -32
  20. package/dist/agents/commands/claude-code/harness/parallel-agents.md +0 -35
  21. package/dist/agents/commands/claude-code/harness/planning.md +0 -41
  22. package/dist/agents/commands/claude-code/harness/pre-commit-review.md +0 -38
  23. package/dist/agents/commands/claude-code/harness/refactoring.md +0 -35
  24. package/dist/agents/commands/claude-code/harness/skill-authoring.md +0 -35
  25. package/dist/agents/commands/claude-code/harness/state-management.md +0 -35
  26. package/dist/agents/commands/claude-code/harness/tdd.md +0 -42
  27. package/dist/agents/commands/claude-code/harness/validate-context-engineering.md +0 -32
  28. package/dist/agents/commands/claude-code/harness/verification.md +0 -38
  29. package/dist/agents/commands/gemini-cli/harness/add-component.toml +0 -240
  30. package/dist/agents/commands/gemini-cli/harness/align-documentation.toml +0 -238
  31. package/dist/agents/commands/gemini-cli/harness/architecture-advisor.toml +0 -469
  32. package/dist/agents/commands/gemini-cli/harness/brainstorming.toml +0 -326
  33. package/dist/agents/commands/gemini-cli/harness/check-mechanical-constraints.toml +0 -249
  34. package/dist/agents/commands/gemini-cli/harness/cleanup-dead-code.toml +0 -258
  35. package/dist/agents/commands/gemini-cli/harness/code-review.toml +0 -461
  36. package/dist/agents/commands/gemini-cli/harness/debugging.toml +0 -436
  37. package/dist/agents/commands/gemini-cli/harness/detect-doc-drift.toml +0 -215
  38. package/dist/agents/commands/gemini-cli/harness/diagnostics.toml +0 -401
  39. package/dist/agents/commands/gemini-cli/harness/enforce-architecture.toml +0 -222
  40. package/dist/agents/commands/gemini-cli/harness/execution.toml +0 -381
  41. package/dist/agents/commands/gemini-cli/harness/git-workflow.toml +0 -325
  42. package/dist/agents/commands/gemini-cli/harness/initialize-project.toml +0 -257
  43. package/dist/agents/commands/gemini-cli/harness/onboarding.toml +0 -316
  44. package/dist/agents/commands/gemini-cli/harness/parallel-agents.toml +0 -221
  45. package/dist/agents/commands/gemini-cli/harness/planning.toml +0 -405
  46. package/dist/agents/commands/gemini-cli/harness/pre-commit-review.toml +0 -294
  47. package/dist/agents/commands/gemini-cli/harness/refactoring.toml +0 -209
  48. package/dist/agents/commands/gemini-cli/harness/skill-authoring.toml +0 -350
  49. package/dist/agents/commands/gemini-cli/harness/state-management.toml +0 -354
  50. package/dist/agents/commands/gemini-cli/harness/tdd.toml +0 -247
  51. package/dist/agents/commands/gemini-cli/harness/validate-context-engineering.toml +0 -186
  52. package/dist/agents/commands/gemini-cli/harness/verification.toml +0 -334
@@ -1,354 +0,0 @@
1
- # Generated by harness generate-slash-commands. Do not edit.
2
- description = "Manage persistent session state across harness agent sessions"
3
- prompt = """
4
- <context>
5
- Cognitive mode: meticulous-implementer
6
- Type: flexible
7
- State: persistent (files: .harness/state.json)
8
- </context>
9
-
10
- <objective>
11
- Manage persistent session state across harness agent sessions
12
- </objective>
13
-
14
- <execution_context>
15
- --- SKILL.md (agents/skills/claude-code/harness-state-management/SKILL.md) ---
16
- # Harness State Management
17
-
18
- > Manage persistent state across agent sessions so that context, decisions, progress, and learnings survive context resets. Load state at session start, track position and decisions throughout, and save state for the next session.
19
-
20
- ## When to Use
21
-
22
- - At the start of every session that continues previous work (load state)
23
- - When completing a task, phase, or milestone (update progress)
24
- - When making a decision that future sessions need to know about (record decision)
25
- - When discovering something non-obvious that would be lost on context reset (capture learning)
26
- - When hitting a blocker that cannot be resolved in the current session (log blocker)
27
- - At the end of every session (save state)
28
- - NOT for storing code — code belongs in git commits, not state files
29
- - NOT for storing large outputs or logs — state should be concise and navigable
30
- - NOT as a replacement for a plan document — plans live in `docs/`, state tracks progress through plans
31
-
32
- ## Process
33
-
34
- ### Phase 1: LOAD — Restore Context from Previous Sessions
35
-
36
- 1. **Read `.harness/state.json`.** This is the primary state file. It contains:
37
- - Current position (phase, task, step)
38
- - Progress map (which tasks are complete, in progress, or blocked)
39
- - Decisions made in previous sessions (date, what, why)
40
- - Blockers encountered and their status
41
- - Last session summary
42
-
43
- 2. **Run `harness state show`** to get a formatted view of current state. This is equivalent to reading the JSON but formatted for readability.
44
-
45
- 3. **Read `.harness/learnings.md`.** This is the append-only knowledge base. Scan for:
46
- - Recent learnings (last 2-3 sessions) — these are most likely still relevant
47
- - Gotchas and warnings — these prevent repeating mistakes
48
- - Decisions with rationale — these explain why things are the way they are
49
-
50
- 4. **Read `.harness/failures.md` if exists.** Scan for active anti-patterns and dead ends.
51
-
52
- 5. **Read `.harness/handoff.json` if exists.** Structured context from last skill.
53
-
54
- 6. **Check `.harness/archive/` for historical failure logs.**
55
-
56
- 7. **If no state exists,** this is a fresh start. Create `.harness/state.json` with initial structure:
57
-
58
- ```json
59
- {
60
- "schemaVersion": 1,
61
- "position": { "phase": "start", "task": null },
62
- "progress": {},
63
- "decisions": [],
64
- "blockers": [],
65
- "lastSession": { "date": null, "summary": null }
66
- }
67
- ```
68
-
69
- 8. **Announce the loaded context.** Briefly summarize: "Resuming from [position]. [N] tasks complete. [N] blockers. Key learnings: [summary]." This confirms the state was loaded and gives the human visibility.
70
-
71
- ### Phase 2: TRACK — Maintain State During the Session
72
-
73
- 1. **Update position when moving between phases or tasks.** Every time work shifts to a new task or phase, update `position` in state:
74
-
75
- ```json
76
- "position": { "phase": "execute", "task": "Task 3", "step": "writing tests" }
77
- ```
78
-
79
- 2. **Record decisions when they are made.** Decisions are choices that affect future work. Record them immediately — do not wait until the end of the session:
80
-
81
- ```json
82
- "decisions": [
83
- {
84
- "date": "2026-03-14",
85
- "what": "Use WebSocket instead of SSE for real-time notifications",
86
- "why": "SSE does not support bidirectional communication, which Task 5 requires"
87
- }
88
- ]
89
- ```
90
-
91
- 3. **Log blockers when encountered.** A blocker is anything that prevents the current task from completing:
92
-
93
- ```json
94
- "blockers": [
95
- {
96
- "date": "2026-03-14",
97
- "task": "Task 4",
98
- "description": "Payment gateway API returns 403 — API key may be expired",
99
- "status": "open"
100
- }
101
- ]
102
- ```
103
-
104
- 4. **Update progress after each completed task:**
105
-
106
- ```json
107
- "progress": {
108
- "Task 1": "complete",
109
- "Task 2": "complete",
110
- "Task 3": "in_progress",
111
- "Task 4": "blocked"
112
- }
113
- ```
114
-
115
- 5. **Keep state concise.** State is not a log. Each field should contain the current status, not a history of all changes. History belongs in `.harness/learnings.md` and git commits.
116
-
117
- ### Phase 3: LEARN — Capture Knowledge for Future Sessions
118
-
119
- 1. **Identify learnings as they happen.** A learning is anything that:
120
- - Was surprising or non-obvious
121
- - Took significant effort to figure out
122
- - Would cause repeated wasted time if forgotten
123
- - Represents a decision that needs rationale preserved
124
-
125
- 2. **Capture learnings with `harness state learn`:**
126
-
127
- ```bash
128
- harness state learn "Date comparison needs UTC normalization — use Date.now() not new Date()"
129
- ```
130
-
131
- This appends to `.harness/learnings.md` with a timestamp.
132
-
133
- 3. **Or append directly to `.harness/learnings.md`** with structured format:
134
-
135
- ```markdown
136
- ## 2026-03-14 — Task 3: Notification Expiry
137
-
138
- - [learning]: PostgreSQL's `now()` returns timestamp with timezone, but our
139
- application uses UTC epoch milliseconds. Always convert before comparing.
140
- - [gotcha]: The notifications table has a unique constraint on (userId, type).
141
- Use upsert (ON CONFLICT DO UPDATE) instead of plain INSERT.
142
- - [decision]: Chose to store expiry as epoch milliseconds rather than
143
- ISO timestamp for consistency with the rest of the codebase.
144
- ```
145
-
146
- 4. **Learnings are append-only.** Never edit or delete previous learnings. They are a chronological record. Even if a learning turns out to be wrong, append a correction rather than modifying the original.
147
-
148
- 5. **What belongs in learnings vs. git commits:**
149
- - **Learnings:** Context, rationale, gotchas, decisions, warnings — things that explain _why_ and _what to watch out for_
150
- - **Git commits:** Code changes, what was done — things that explain _what_ changed
151
- - Example: The commit says "feat: add UTC normalization to date comparison." The learning says "Date comparison needs UTC normalization because PostgreSQL returns timezone-aware timestamps but our app uses epoch milliseconds."
152
-
153
- ### Phase 4: SAVE — Persist State for Next Session
154
-
155
- 1. **Update `.harness/state.json`** with final position, progress, and session summary:
156
-
157
- ```json
158
- {
159
- "schemaVersion": 1,
160
- "position": { "phase": "execute", "task": "Task 4" },
161
- "progress": {
162
- "Task 1": "complete",
163
- "Task 2": "complete",
164
- "Task 3": "complete"
165
- },
166
- "decisions": [ ... ],
167
- "blockers": [ ... ],
168
- "lastSession": {
169
- "date": "2026-03-14",
170
- "summary": "Completed Tasks 2-3. Task 3 required UTC date normalization (see learnings). Starting Task 4 next session."
171
- }
172
- }
173
- ```
174
-
175
- 2. **Verify learnings were captured.** Review `.harness/learnings.md` — were all non-obvious discoveries recorded? If something was tricky during the session, it should be in learnings.
176
-
177
- 3. **Decide whether to commit state files.** State files (`.harness/state.json`, `.harness/learnings.md`) should be committed to git so other team members and agents can access them. Commit state updates separately from code changes so they do not clutter code diffs.
178
-
179
- ### Building Institutional Knowledge Over Time
180
-
181
- The `.harness/learnings.md` file grows over the lifetime of the project. It becomes a valuable resource:
182
-
183
- - **Week 1:** A few gotchas about the development environment and initial setup decisions.
184
- - **Month 1:** Patterns emerge — recurring issues, architectural decisions with rationale, team conventions that were established through experience.
185
- - **Month 6:** New team members read learnings and avoid months of rediscovery. The file captures knowledge that no single person holds.
186
- - **Year 1:** Learnings are the project's institutional memory. They explain why the architecture looks the way it does, why certain patterns were adopted, and what was tried and abandoned.
187
-
188
- Treat learnings as a first-class project artifact. They are as valuable as tests and documentation.
189
-
190
- ### Archival Workflow
191
-
192
- - **Archive failures:** Move `failures.md` to `.harness/archive/` at milestone boundaries.
193
- - **Do NOT archive learnings** — permanent. Learnings accumulate for the lifetime of the project.
194
- - **Do NOT archive state** — git handles history. The current `state.json` is always the source of truth.
195
- - **Handoff is ephemeral** — overwritten by each skill. No archival needed.
196
-
197
- ## Harness Integration
198
-
199
- - **`harness state show`** — Display current state in a formatted, readable view. Use at session start to quickly orient.
200
- - **`harness state reset`** — Reset state to initial values. Use when starting a completely new effort and old state is no longer relevant. Use with caution — this discards progress tracking.
201
- - **`harness state learn "<message>"`** — Append a learning to `.harness/learnings.md` with automatic timestamp formatting.
202
- - **`.harness/state.json`** — Primary state file. Read at session start, updated throughout, saved at session end.
203
- - **`.harness/learnings.md`** — Append-only knowledge base. Read at session start for context, appended to when discoveries are made.
204
- - **`.harness/failures.md`** — Active anti-patterns. Read at session start to avoid known dead ends.
205
- - **`.harness/handoff.json`** — Structured context from last skill. Read at session start for immediate context.
206
- - **`.harness/trace.md`** — Optional reasoning trace. Useful for debugging agent behavior across sessions.
207
- - **`.harness/archive/`** — Archived failure logs. Check for historical context when encountering recurring issues.
208
-
209
- ## Success Criteria
210
-
211
- - State is loaded at the start of every session that continues previous work
212
- - Position is updated whenever the current phase or task changes
213
- - Decisions are recorded with date, what, and why — immediately when made, not deferred
214
- - Blockers are logged with task reference, description, and status
215
- - Progress is updated after each completed task
216
- - Learnings are captured for every non-obvious discovery during the session
217
- - `.harness/learnings.md` entries follow the structured format (date, task, tagged items)
218
- - Learnings are append-only — no edits or deletions of previous entries
219
- - State is saved before session end with an accurate session summary
220
- - State files are committed to git separately from code changes
221
-
222
- ## Examples
223
-
224
- ### Example: Starting a New Session (Resuming Work)
225
-
226
- **LOAD:**
227
-
228
- ```
229
- Run: harness state show
230
- Output:
231
- Position: execute / Task 3 (writing tests)
232
- Progress: Task 1 complete, Task 2 complete
233
- Blockers: none
234
- Last session: 2026-03-13 — "Completed Tasks 1-2. Task 2 required
235
- adding a new index on notifications.userId for query performance."
236
-
237
- Read: .harness/learnings.md
238
- Most recent:
239
- - [gotcha]: notifications table needs index on userId — queries
240
- were timing out without it
241
- - [decision]: used partial index (WHERE deleted_at IS NULL) to
242
- avoid indexing soft-deleted rows
243
-
244
- Summary: "Resuming from Task 3 (writing tests). Tasks 1-2 complete.
245
- Note: notifications table has a partial index on userId — see learnings."
246
- ```
247
-
248
- ### Example: Recording a Decision Mid-Session
249
-
250
- ```
251
- Context: Implementing Task 4, need to choose between polling and WebSocket.
252
-
253
- Record decision:
254
- date: "2026-03-14"
255
- what: "Use WebSocket for real-time notification delivery"
256
- why: "Polling would require 1-second intervals for acceptable latency,
257
- which creates too much load. WebSocket gives instant delivery with
258
- one persistent connection per client."
259
-
260
- Capture learning:
261
- harness state learn "WebSocket chosen over polling for notifications.
262
- Polling at 1s intervals = ~86k requests/day per client. WebSocket =
263
- 1 persistent connection. See Task 4 decision in state."
264
- ```
265
-
266
- ### Example: Ending a Session
267
-
268
- **SAVE:**
269
-
270
- ```
271
- Update .harness/state.json:
272
- {
273
- "schemaVersion": 1,
274
- "position": { "phase": "execute", "task": "Task 5" },
275
- "progress": {
276
- "Task 1": "complete",
277
- "Task 2": "complete",
278
- "Task 3": "complete",
279
- "Task 4": "complete"
280
- },
281
- "decisions": [
282
- {
283
- "date": "2026-03-14",
284
- "what": "Use WebSocket for real-time notification delivery",
285
- "why": "Polling creates too much load at acceptable latency intervals"
286
- }
287
- ],
288
- "blockers": [],
289
- "lastSession": {
290
- "date": "2026-03-14",
291
- "summary": "Completed Tasks 3-4. Task 3 added expiry logic with UTC normalization. Task 4 implemented WebSocket delivery (chose over polling — see decisions). Starting Task 5 (UI integration) next session."
292
- }
293
- }
294
-
295
- Verify: .harness/learnings.md has entries for UTC normalization and WebSocket decision.
296
- Commit: git add .harness/ && git commit -m "chore: update harness state after Tasks 3-4"
297
- ```
298
-
299
- ### Example: What Belongs Where
300
-
301
- | Information | Where It Goes | Why |
302
- | ----------------------------------------------------- | ------------------------------- | ---------------------------------------------------- |
303
- | "Added WebSocket handler in src/ws/" | Git commit message | Describes what changed in code |
304
- | "Chose WebSocket over polling because..." | `.harness/state.json` decisions | Records the choice and rationale for future sessions |
305
- | "WebSocket requires sticky sessions in load balancer" | `.harness/learnings.md` | Non-obvious operational concern future sessions need |
306
- | "Task 4 complete" | `.harness/state.json` progress | Tracks execution position |
307
- | "The WebSocket library auto-reconnects by default" | `.harness/learnings.md` | Gotcha that saves future debugging time |
308
- | "Tried approach X, failed because Y" | `.harness/failures.md` | Active anti-pattern to avoid repeating |
309
- | "Completed Tasks 1-3, Task 4 pending" | `.harness/handoff.json` | Structured context for next skill |
310
- | "[PREPARE 10:30] Loaded 3 failures" | `.harness/trace.md` | Reasoning trace for debugging agent behavior |
311
-
312
-
313
- --- skill.yaml (agents/skills/claude-code/harness-state-management/skill.yaml) ---
314
- name: harness-state-management
315
- version: "1.0.0"
316
- description: Manage persistent session state across harness agent sessions
317
- cognitive_mode: meticulous-implementer
318
- triggers:
319
- - manual
320
- platforms:
321
- - claude-code
322
- - gemini-cli
323
- tools:
324
- - Bash
325
- - Read
326
- - Write
327
- - Edit
328
- - Glob
329
- cli:
330
- command: harness skill run harness-state-management
331
- args:
332
- - name: path
333
- description: Project root path
334
- required: false
335
- mcp:
336
- tool: run_skill
337
- input:
338
- skill: harness-state-management
339
- path: string
340
- type: flexible
341
- state:
342
- persistent: true
343
- files:
344
- - .harness/state.json
345
- depends_on: []
346
-
347
- </execution_context>
348
-
349
- <process>
350
- 1. Try: invoke mcp__harness__run_skill with skill: "harness-state-management"
351
- 2. If MCP unavailable: follow the SKILL.md workflow provided above directly
352
- 3. Pass through any arguments provided by the user
353
- </process>
354
- """
@@ -1,247 +0,0 @@
1
- # Generated by harness generate-slash-commands. Do not edit.
2
- description = "Test-driven development integrated with harness validation"
3
- prompt = """
4
- <context>
5
- Cognitive mode: meticulous-implementer
6
- Type: rigid
7
- </context>
8
-
9
- <objective>
10
- Test-driven development integrated with harness validation
11
-
12
- Phases:
13
- - red: Write failing test
14
- - green: Implement minimal code to pass
15
- - refactor: Clean up while keeping tests green (optional)
16
- - validate: Run harness checks
17
- </objective>
18
-
19
- <execution_context>
20
- --- SKILL.md (agents/skills/claude-code/harness-tdd/SKILL.md) ---
21
- # Harness TDD
22
-
23
- > Red-green-refactor cycle integrated with harness validation. No production code exists without a failing test first.
24
-
25
- ## When to Use
26
-
27
- - Implementing any new feature, function, module, or component
28
- - Fixing any bug (write a test that reproduces the bug first)
29
- - Adding behavior to existing code
30
- - When `on_new_feature` or `on_bug_fix` triggers fire
31
- - NOT when doing pure refactoring with existing test coverage (use harness-refactoring instead)
32
- - NOT when writing documentation, configuration, or non-behavioral files
33
- - NOT when spiking/prototyping (but convert spikes to TDD before merging)
34
-
35
- ## Process
36
-
37
- ### Iron Law
38
-
39
- **No production code may exist without a failing test that demanded its creation.**
40
-
41
- If you find yourself writing production code first, STOP. Delete it. Write the test first. This is not a guideline — it is a hard constraint.
42
-
43
- ### Phase 1: RED — Write a Failing Test
44
-
45
- 1. **Identify the smallest behavior to test.** One assertion per test. One behavior per cycle. If you are testing two things, split into two cycles.
46
-
47
- 2. **Write the test file or add to the appropriate test file.** Follow the project's existing test conventions (file naming, framework, location).
48
-
49
- 3. **Write ONE minimal test** that asserts the expected behavior. The test should:
50
- - Have a clear, descriptive name that states what behavior is expected
51
- - Set up only the minimal fixtures needed
52
- - Make a single assertion about the expected outcome
53
- - NOT test implementation details — test observable behavior
54
-
55
- 4. **Run the test suite.** Use the project's test runner (e.g., `npx vitest run path/to/test`, `npm test`, `pytest`).
56
-
57
- 5. **MANDATORY: Watch the test FAIL.** Read the failure message. Confirm it fails for the RIGHT reason — the behavior is not yet implemented, not because the test is broken. If the test passes, either the behavior already exists (skip this cycle) or the test is wrong (fix the test).
58
-
59
- 6. **Record the failure.** Note the test name and failure reason. This is your contract for the GREEN phase.
60
-
61
- ### Phase 2: GREEN — Write the Simplest Code to Pass
62
-
63
- 1. **Write the MINIMUM production code** that makes the failing test pass. Do not write code for future tests. Do not add error handling you have not tested. Do not generalize.
64
-
65
- 2. **Resist the urge to write "good" code.** The GREEN phase is about correctness, not elegance. Hardcoded values are acceptable if they pass the test. Duplication is acceptable. You will clean up in REFACTOR.
66
-
67
- 3. **Run the FULL test suite** (not just the new test). All tests must pass.
68
-
69
- 4. **MANDATORY: Watch the test PASS.** Read the output. Confirm all tests are green. If any test fails, fix the production code (not the tests) until all pass.
70
-
71
- 5. **Do not proceed to REFACTOR if any test is red.** Fix first.
72
-
73
- ### Phase 3: REFACTOR — Clean Up While Green
74
-
75
- 1. **With all tests passing,** look for opportunities to improve:
76
- - Remove duplication (DRY)
77
- - Extract methods or functions for clarity
78
- - Rename for better readability
79
- - Simplify conditionals
80
- - Improve structure without changing behavior
81
-
82
- 2. **Run the full test suite after EVERY change.** If a test breaks during refactoring, undo the last change immediately. Refactoring must not change behavior.
83
-
84
- 3. **Keep refactoring steps small.** One rename, one extraction, one simplification at a time. Run tests between each.
85
-
86
- 4. **If no refactoring is needed, skip this phase.** Not every cycle requires cleanup.
87
-
88
- ### Phase 4: VALIDATE — Run Harness Checks
89
-
90
- 1. **Run `harness check-deps`** to verify dependency boundaries are respected. New code must not introduce forbidden imports or layer violations.
91
-
92
- 2. **Run `harness validate`** to verify the full project health. This catches architectural drift, documentation gaps, and constraint violations.
93
-
94
- 3. **If either check fails,** fix the issue before committing. The fix may require another RED-GREEN-REFACTOR cycle if it involves behavioral changes.
95
-
96
- 4. **Commit the cycle.** Each RED-GREEN-REFACTOR-VALIDATE cycle produces one atomic commit. The commit message references what behavior was added (not "add test" — describe the behavior).
97
-
98
- ### Cycle Rhythm
99
-
100
- Repeat the 4 phases for each new behavior. A typical feature requires 3-10 cycles. Each cycle should take 2-15 minutes. If a cycle takes longer than 15 minutes, the step is too large — break it down.
101
-
102
- **Ordering within a feature:**
103
-
104
- 1. Start with the happy path (simplest success case)
105
- 2. Add edge cases one at a time
106
- 3. Add error handling cases
107
- 4. Add integration points last
108
-
109
- ## Harness Integration
110
-
111
- - **`harness check-deps`** — Run in VALIDATE phase after each cycle. Catches forbidden imports and layer boundary violations introduced by new code.
112
- - **`harness validate`** — Run in VALIDATE phase after each cycle. Full project health check including architecture, documentation, and constraints.
113
- - **`harness cleanup`** — Run periodically (every 3-5 cycles) to detect entropy accumulation. Address any issues before they compound.
114
- - **Test runner** — Use the project's configured test runner. Harness does not prescribe a test framework but the test must actually execute and report results.
115
-
116
- ## Success Criteria
117
-
118
- - Every production function/method has at least one corresponding test
119
- - Every test was observed to fail before the production code was written
120
- - Every test was observed to pass after the production code was written
121
- - `harness check-deps` passes after each cycle
122
- - `harness validate` passes after each cycle
123
- - Each cycle is an atomic commit with a descriptive message
124
- - No test tests implementation details (only observable behavior)
125
- - No production code exists that was not demanded by a failing test
126
-
127
- ## Examples
128
-
129
- ### Example: Adding a `calculateTotal` function
130
-
131
- **RED:**
132
-
133
- ```typescript
134
- // cart.test.ts
135
- it('calculates total for items with quantity and price', () => {
136
- const items = [
137
- { name: 'Widget', price: 10, quantity: 2 },
138
- { name: 'Gadget', price: 25, quantity: 1 },
139
- ];
140
- expect(calculateTotal(items)).toBe(45);
141
- });
142
- ```
143
-
144
- Run tests. Observe: `ReferenceError: calculateTotal is not defined`. Correct failure — function does not exist yet.
145
-
146
- **GREEN:**
147
-
148
- ```typescript
149
- // cart.ts
150
- export function calculateTotal(items: Array<{ price: number; quantity: number }>): number {
151
- return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
152
- }
153
- ```
154
-
155
- Run tests. Observe: all tests pass.
156
-
157
- **REFACTOR:** No refactoring needed for this simple function. Skip.
158
-
159
- **VALIDATE:**
160
-
161
- ```bash
162
- harness check-deps # Pass
163
- harness validate # Pass
164
- git add cart.ts cart.test.ts
165
- git commit -m "feat(cart): calculate total from item price and quantity"
166
- ```
167
-
168
- **Next cycle (RED):** Write a test for empty array input. Watch it fail (or pass — if it passes, the behavior is already handled). Continue.
169
-
170
- ## Gates
171
-
172
- These are hard stops. Violating any gate means the process has broken down.
173
-
174
- - **Code before test = delete it.** If production code is written before a failing test exists, delete the production code and start the cycle correctly.
175
- - **Must watch fail.** If you did not observe the test fail with the correct failure reason, the RED phase is incomplete. Do not proceed to GREEN.
176
- - **Must watch pass.** If you did not observe all tests pass after writing production code, the GREEN phase is incomplete. Do not proceed to REFACTOR.
177
- - **No skipping VALIDATE.** Every cycle must end with `harness check-deps` and `harness validate`. Skipping creates architectural debt that compounds.
178
- - **No multi-behavior tests.** One test, one assertion, one behavior. Tests that assert multiple unrelated things must be split.
179
- - **No "I'll write tests later."** There is no later. The test comes first or the code does not get written.
180
-
181
- ## Escalation
182
-
183
- - **After 3 failed attempts to make a test pass:** Stop coding. The design may be wrong. Re-examine the interface, the test assumptions, or the architecture. Consider whether the feature needs a different approach. Consult the plan or spec.
184
- - **When a test cannot be written without complex mocking:** This is a design smell. The code under test has too many dependencies. Refactor the existing code to be more testable before proceeding, or reconsider the abstraction boundary.
185
- - **When harness checks repeatedly fail:** The new code may be violating architectural constraints intentionally. Escalate to the human to decide whether to update the constraints or change the approach.
186
- - **When the cycle is taking more than 15 minutes:** The step is too large. Break the current behavior into smaller sub-behaviors and test each one separately.
187
- - **When you are unsure what to test next:** Review the spec or plan. If no spec exists, use the harness-brainstorming skill to clarify requirements before writing more tests.
188
-
189
-
190
- --- skill.yaml (agents/skills/claude-code/harness-tdd/skill.yaml) ---
191
- name: harness-tdd
192
- version: "1.0.0"
193
- description: Test-driven development integrated with harness validation
194
- cognitive_mode: meticulous-implementer
195
- triggers:
196
- - manual
197
- - on_new_feature
198
- - on_bug_fix
199
- platforms:
200
- - claude-code
201
- - gemini-cli
202
- tools:
203
- - Bash
204
- - Read
205
- - Write
206
- - Edit
207
- - Glob
208
- - Grep
209
- cli:
210
- command: harness skill run harness-tdd
211
- args:
212
- - name: path
213
- description: Project root path
214
- required: false
215
- mcp:
216
- tool: run_skill
217
- input:
218
- skill: harness-tdd
219
- path: string
220
- type: rigid
221
- phases:
222
- - name: red
223
- description: Write failing test
224
- required: true
225
- - name: green
226
- description: Implement minimal code to pass
227
- required: true
228
- - name: refactor
229
- description: Clean up while keeping tests green
230
- required: false
231
- - name: validate
232
- description: Run harness checks
233
- required: true
234
- state:
235
- persistent: false
236
- files: []
237
- depends_on:
238
- - harness-verification
239
-
240
- </execution_context>
241
-
242
- <process>
243
- 1. Try: invoke mcp__harness__run_skill with skill: "harness-tdd"
244
- 2. If MCP unavailable: follow the SKILL.md workflow provided above directly
245
- 3. Pass through any arguments provided by the user
246
- </process>
247
- """