tdd-claude-code 0.2.0 → 0.4.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.
package/README.md CHANGED
@@ -27,7 +27,10 @@ npx tdd-claude-code --local # this project only
27
27
  You use `/tdd:*` commands for everything. Never touch `/gsd:*` directly.
28
28
 
29
29
  ```
30
- /tdd:new-project Describe your idea, get test infrastructure
30
+ /tdd:new-project New project from scratch
31
+ OR
32
+ /tdd:init Add TDD to existing codebase
33
+ /tdd:coverage Analyze gaps, write retro tests (optional)
31
34
 
32
35
  /tdd:discuss 1 Shape how phase 1 gets built
33
36
  /tdd:plan 1 Create task plans
@@ -55,6 +58,8 @@ You run one command. Tests get written before code. Automatically.
55
58
  | Command | What It Does |
56
59
  |---------|--------------|
57
60
  | `/tdd:new-project` | Start project with test infrastructure |
61
+ | `/tdd:init` | Add TDD to existing codebase |
62
+ | `/tdd:coverage` | Analyze gaps, write tests for existing code |
58
63
  | `/tdd:discuss [N]` | Capture implementation preferences |
59
64
  | `/tdd:plan [N]` | Create task plans |
60
65
  | `/tdd:build <N>` | **Write tests → implement → verify** |
package/bin/install.js CHANGED
@@ -26,10 +26,12 @@ ${c.cyan} ████████╗██████╗ ██████
26
26
  ╚═╝ ╚═════╝ ╚═════╝${c.reset}
27
27
  `;
28
28
 
29
- const VERSION = '0.2.0';
29
+ const VERSION = '0.4.0';
30
30
 
31
31
  const COMMANDS = [
32
32
  'new-project.md',
33
+ 'init.md',
34
+ 'coverage.md',
33
35
  'discuss.md',
34
36
  'plan.md',
35
37
  'build.md',
package/coverage.md ADDED
@@ -0,0 +1,155 @@
1
+ # /tdd:coverage - Analyze Test Coverage Gaps
2
+
3
+ Scan existing code, identify what's untested, and offer to write retrospective tests.
4
+
5
+ ## When to Use
6
+
7
+ - After `/tdd:init` to add tests to existing code
8
+ - Anytime you want to improve test coverage
9
+ - When joining a project to understand test gaps
10
+ - After "vibe coding" a feature without tests
11
+
12
+ ## Process
13
+
14
+ ### 1. Detect Test Framework
15
+
16
+ Identify the test setup:
17
+ - Framework: vitest, jest, pytest, go test, rspec, cargo test
18
+ - Test directory: `tests/`, `__tests__/`, `spec/`, etc.
19
+ - Test patterns: `*.test.ts`, `*_test.py`, etc.
20
+
21
+ If no test framework found, suggest running `/tdd:init` first.
22
+
23
+ ### 2. Scan Source Files
24
+
25
+ Identify all source files:
26
+ - `src/**/*`, `lib/**/*`, `app/**/*`, `pkg/**/*`
27
+ - Exclude: node_modules, vendor, dist, build, .git
28
+
29
+ Categorize by type:
30
+ - **API/Routes**: files handling HTTP endpoints
31
+ - **Services**: business logic modules
32
+ - **Components**: UI components (React, Vue, etc.)
33
+ - **Utils**: helper functions
34
+ - **Models**: data structures, schemas
35
+ - **Config**: configuration files (skip testing)
36
+
37
+ ### 3. Match Tests to Source
38
+
39
+ For each source file, look for corresponding test:
40
+ - `src/auth/login.ts` → `tests/auth/login.test.ts` or `src/auth/login.test.ts`
41
+ - `lib/utils.py` → `tests/test_utils.py` or `tests/utils_test.py`
42
+ - `pkg/api/handler.go` → `pkg/api/handler_test.go`
43
+
44
+ ### 4. Identify Critical Paths
45
+
46
+ Flag high-priority untested code:
47
+ - **Auth**: login, logout, session, token, password, oauth
48
+ - **Payments**: payment, billing, charge, subscription, stripe, checkout
49
+ - **Data mutations**: create, update, delete, save, remove
50
+ - **Security**: validate, sanitize, permission, role, access
51
+
52
+ ### 5. Present Coverage Analysis
53
+
54
+ ```
55
+ Test Coverage Analysis
56
+
57
+ Source files: 24
58
+ Test files: 8
59
+ Coverage: 33% (8/24 files have tests)
60
+
61
+ Tested:
62
+ ✓ src/utils/format.ts (src/utils/format.test.ts)
63
+ ✓ src/api/health.ts (tests/api/health.test.ts)
64
+ ... [list all]
65
+
66
+ Untested - Critical:
67
+ ✗ src/services/payment.ts - Stripe integration, checkout flow
68
+ ✗ src/api/auth.ts - login, session management
69
+ ✗ src/middleware/auth.ts - JWT validation
70
+
71
+ Untested - High Priority:
72
+ ✗ src/api/users.ts - user CRUD operations
73
+ ✗ src/services/email.ts - transactional emails
74
+
75
+ Untested - Standard:
76
+ ✗ src/utils/helpers.ts - utility functions
77
+ ✗ src/components/Header.tsx - navigation component
78
+ ... [list all]
79
+ ```
80
+
81
+ ### 6. Offer Retrospective Test Writing
82
+
83
+ Ask the user:
84
+
85
+ ```
86
+ Would you like to write tests for existing code?
87
+
88
+ 1) Yes - critical paths only (fastest)
89
+ 2) Yes - critical + high priority
90
+ 3) Yes - everything untested
91
+ 4) No - just wanted the report
92
+ ```
93
+
94
+ **If tests requested:**
95
+
96
+ Create `.planning/TEST-BACKLOG.md`:
97
+
98
+ ```markdown
99
+ # Test Backlog
100
+
101
+ Generated: [date]
102
+ Coverage before: 33% (8/24)
103
+
104
+ ## Critical (auth, payments, security)
105
+ - [ ] src/services/payment.ts - Stripe integration
106
+ - [ ] src/api/auth.ts - login/logout flows
107
+ - [ ] src/middleware/auth.ts - JWT validation
108
+
109
+ ## High Priority (data mutations, core logic)
110
+ - [ ] src/api/users.ts - CRUD operations
111
+ - [ ] src/services/email.ts - email sending
112
+
113
+ ## Standard (utils, components, helpers)
114
+ - [ ] src/utils/helpers.ts
115
+ - [ ] src/components/Header.tsx
116
+ ```
117
+
118
+ Then ask:
119
+ ```
120
+ Start writing tests now?
121
+
122
+ 1) Yes - begin with first critical item
123
+ 2) No - I'll run /tdd:build backlog later
124
+ ```
125
+
126
+ **If "Yes":**
127
+
128
+ For each file, write tests that capture current behavior:
129
+ 1. Read the source file
130
+ 2. Identify exported functions/classes
131
+ 3. Write tests for each public interface
132
+ 4. Run tests to verify they pass (code already exists)
133
+ 5. Mark item complete in backlog
134
+
135
+ ### 7. Report Summary
136
+
137
+ ```
138
+ Coverage analysis complete.
139
+
140
+ Before: 33% (8/24 files)
141
+ Backlog created: .planning/TEST-BACKLOG.md
142
+ - Critical: 3 files
143
+ - High priority: 2 files
144
+ - Standard: 11 files
145
+
146
+ Run /tdd:build backlog to start writing tests.
147
+ ```
148
+
149
+ ## Usage
150
+
151
+ ```
152
+ /tdd:coverage
153
+ ```
154
+
155
+ No arguments needed. Scans entire codebase.
package/help.md CHANGED
@@ -4,11 +4,18 @@ TDD-first workflow powered by GSD. You use `/tdd:*` for everything — tests hap
4
4
 
5
5
  ## Commands
6
6
 
7
- ### Core Workflow
7
+ ### Getting Started
8
8
 
9
9
  | Command | What It Does |
10
10
  |---------|--------------|
11
11
  | `/tdd:new-project` | Start new project with test infrastructure |
12
+ | `/tdd:init` | Add TDD to existing codebase |
13
+ | `/tdd:coverage` | Analyze gaps, write tests for existing code |
14
+
15
+ ### Core Workflow
16
+
17
+ | Command | What It Does |
18
+ |---------|--------------|
12
19
  | `/tdd:discuss [N]` | Capture implementation preferences for phase N |
13
20
  | `/tdd:plan [N]` | Research and create task plans for phase N |
14
21
  | `/tdd:build <N>` | **Write tests → implement → verify tests pass** |
@@ -38,7 +45,10 @@ TDD-first workflow powered by GSD. You use `/tdd:*` for everything — tests hap
38
45
  ## Workflow
39
46
 
40
47
  ```
41
- /tdd:new-project Describe your idea, set up project + tests
48
+ /tdd:new-project New project from scratch
49
+ OR
50
+ /tdd:init Existing codebase
51
+ /tdd:coverage Analyze gaps, write retro tests (optional)
42
52
 
43
53
  /tdd:discuss 1 Shape how phase 1 gets built
44
54
  /tdd:plan 1 Create task plans
@@ -81,6 +91,8 @@ TDD commands call GSD internally:
81
91
  | TDD Command | Calls |
82
92
  |-------------|-------|
83
93
  | `/tdd:new-project` | `/gsd:new-project` + test setup |
94
+ | `/tdd:init` | scan + test setup (no GSD call) |
95
+ | `/tdd:coverage` | scan + write tests (no GSD call) |
84
96
  | `/tdd:discuss` | `/gsd:discuss-phase` |
85
97
  | `/tdd:plan` | `/gsd:plan-phase` |
86
98
  | `/tdd:build` | write tests + `/gsd:execute-phase` |
package/init.md ADDED
@@ -0,0 +1,219 @@
1
+ # /tdd:init - Initialize TDD in Existing Project
2
+
3
+ Add TDD workflow to an existing codebase. Analyzes what you have, identifies gaps, and offers to write tests for existing code.
4
+
5
+ ## When to Use
6
+
7
+ - You have existing code without tests
8
+ - You have existing code with some tests
9
+ - You're joining a project mid-development
10
+ - You want to adopt TDD on a "vibe coded" project
11
+
12
+ This command will:
13
+ 1. Set up test infrastructure (if missing)
14
+ 2. **Analyze your existing code** to understand what it does
15
+ 3. **Identify untested modules** and critical paths
16
+ 4. **Ask if you want retrospective tests** written for existing code
17
+
18
+ For brand new projects with no code, use `/tdd:new-project` instead.
19
+
20
+ ## Process
21
+
22
+ ### 1. Scan for Existing Code
23
+
24
+ Check for source files:
25
+ - `src/`, `lib/`, `app/`, `pkg/`, or root-level code files
26
+ - `package.json`, `pyproject.toml`, `go.mod`, `Gemfile`, `Cargo.toml`
27
+
28
+ If no code found, suggest running `/tdd:new-project` instead.
29
+
30
+ ### 2. Detect Stack
31
+
32
+ | Indicator | Stack |
33
+ |-----------|-------|
34
+ | `package.json` + React/Next deps | Next.js / React |
35
+ | `package.json` (no framework) | Node.js |
36
+ | `pyproject.toml` / `requirements.txt` | Python |
37
+ | `go.mod` | Go |
38
+ | `Gemfile` | Ruby |
39
+ | `Cargo.toml` | Rust |
40
+
41
+ ### 3. Scan for Existing Tests
42
+
43
+ Look for test indicators:
44
+
45
+ **Directories:**
46
+ - `tests/`, `test/`, `__tests__/`, `spec/`
47
+
48
+ **Files:**
49
+ - `*_test.py`, `test_*.py`
50
+ - `*.test.ts`, `*.test.js`, `*.spec.ts`, `*.spec.js`
51
+ - `*_test.go`
52
+ - `*_spec.rb`
53
+
54
+ **Config files:**
55
+ - `vitest.config.*`, `jest.config.*`, `pytest.ini`, `pyproject.toml` [tool.pytest]
56
+ - `.rspec`, `spec/spec_helper.rb`
57
+
58
+ ### 4. Set Up Test Framework (if missing)
59
+
60
+ If no tests found, set up based on detected stack:
61
+
62
+ | Stack | Framework | Setup |
63
+ |-------|-----------|-------|
64
+ | Next.js / React | Vitest | `npm install -D vitest @testing-library/react` |
65
+ | Node.js | Vitest | `npm install -D vitest` |
66
+ | Python | pytest | `pip install pytest` or add to pyproject.toml |
67
+ | Go | go test | Built-in, no setup needed |
68
+ | Ruby | RSpec | `gem install rspec && rspec --init` |
69
+ | Rust | cargo test | Built-in, no setup needed |
70
+
71
+ Create config file and test directory structure.
72
+
73
+ Add test scripts to package.json / pyproject.toml / Makefile:
74
+ ```json
75
+ "scripts": {
76
+ "test": "vitest run",
77
+ "test:watch": "vitest"
78
+ }
79
+ ```
80
+
81
+ ### 5. If Tests Already Exist
82
+
83
+ - Skip framework setup
84
+ - Note existing test patterns for consistency
85
+ - Report: "Found existing test framework: [vitest/jest/pytest/etc]"
86
+ - Report: "Found X existing test files"
87
+
88
+ ### 6. Analyze Existing Code Structure
89
+
90
+ Scan the codebase and generate summary:
91
+ - Main directories and their purpose
92
+ - Key modules/components identified
93
+ - Entry points (main files, API routes, etc.)
94
+ - Dependencies and their roles
95
+
96
+ ### 7. Identify Untested Code
97
+
98
+ Compare source files against test files to identify:
99
+ - Modules/components with no corresponding tests
100
+ - Key functions that lack test coverage
101
+ - Critical paths (auth, payments, data mutations) without tests
102
+
103
+ Present findings:
104
+ ```
105
+ Code Coverage Analysis:
106
+
107
+ Tested:
108
+ ✓ src/auth/login.ts (tests/auth/login.test.ts)
109
+ ✓ src/utils/format.ts (tests/utils/format.test.ts)
110
+
111
+ Untested:
112
+ ✗ src/api/users.ts - CRUD operations, no tests
113
+ ✗ src/services/payment.ts - payment processing, no tests
114
+ ✗ src/components/Dashboard.tsx - main UI, no tests
115
+
116
+ Critical paths without tests: 2 (auth, payments)
117
+ ```
118
+
119
+ ### 8. Offer Retrospective Test Writing
120
+
121
+ Ask the user:
122
+
123
+ ```
124
+ Would you like to write tests for existing code?
125
+
126
+ 1) Yes - prioritize critical paths first
127
+ 2) Yes - write tests for everything
128
+ 3) No - only use TDD for new features going forward
129
+ ```
130
+
131
+ **If option 1 or 2 selected:**
132
+
133
+ Create `.planning/BACKLOG.md` with test tasks:
134
+
135
+ ```markdown
136
+ # Test Backlog
137
+
138
+ ## Critical (write first)
139
+ - [ ] src/services/payment.ts - payment processing logic
140
+ - [ ] src/api/auth.ts - authentication flows
141
+
142
+ ## High Priority
143
+ - [ ] src/api/users.ts - user CRUD operations
144
+ - [ ] src/middleware/validation.ts - input validation
145
+
146
+ ## Standard
147
+ - [ ] src/utils/helpers.ts - utility functions
148
+ - [ ] src/components/Dashboard.tsx - dashboard rendering
149
+ ```
150
+
151
+ Then ask:
152
+ ```
153
+ Start writing tests now, or save backlog for later?
154
+
155
+ 1) Start now - begin with critical paths
156
+ 2) Later - I'll run /tdd:build backlog when ready
157
+ ```
158
+
159
+ **If "Start now":** Begin writing tests for the first critical path item using Red-Green-Refactor (but code already exists, so focus on capturing current behavior).
160
+
161
+ ### 9. Create or Update PROJECT.md
162
+
163
+ If PROJECT.md doesn't exist, create it with:
164
+
165
+ ```markdown
166
+ # [Project Name]
167
+
168
+ ## Overview
169
+ [Inferred from code structure and README if present]
170
+
171
+ ## Tech Stack
172
+ - [Detected stack]
173
+ - [Key dependencies]
174
+
175
+ ## Project Structure
176
+ [Generated from scan]
177
+
178
+ ## Development Methodology: Test-Led Development
179
+
180
+ This project uses TDD. All new implementation follows Red -> Green -> Refactor:
181
+
182
+ 1. **Red**: Write failing tests that define expected behavior
183
+ 2. **Green**: Write minimum code to make tests pass
184
+ 3. **Refactor**: Clean up while keeping tests green
185
+
186
+ Tests are written BEFORE implementation, not after.
187
+
188
+ ## Test Framework
189
+ - Framework: [detected or installed]
190
+ - Run tests: `[test command]`
191
+ - Test directory: `[path]`
192
+ ```
193
+
194
+ If PROJECT.md exists, append the TDD section only.
195
+
196
+ ### 10. Report Summary
197
+
198
+ ```
199
+ TDD initialized for [project name]
200
+
201
+ Stack: [detected]
202
+ Test framework: [framework] (existing/newly configured)
203
+ Test directory: [path]
204
+ Existing tests: [count] files
205
+ Untested files: [count] identified
206
+
207
+ Next steps:
208
+ - Run /tdd:build backlog to write tests for existing code
209
+ - Run /tdd:discuss to plan new features with TDD
210
+ - Run /tdd:quick for ad-hoc tasks with tests
211
+ ```
212
+
213
+ ## Usage
214
+
215
+ ```
216
+ /tdd:init
217
+ ```
218
+
219
+ No arguments needed. Auto-detects everything.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tdd-claude-code",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "TDD workflow for Claude Code - wraps GSD",
5
5
  "bin": {
6
6
  "tdd-claude-code": "./bin/install.js"