@groupby/ai-dev 0.4.2 → 0.5.1

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,320 @@
1
+ ---
2
+ name: tdd-implement
3
+ description: Use when the user invokes `/tdd-implement` (or asks to "implement this plan", "TDD this plan", "build the plan"). Reads an approved plan file from `.claude/artifacts/` (typically a `*-plan.md` produced by /draft-plan), creates a feature branch, implements the plan phase-by-phase using strict TDD (failing tests first, then green), commits each phase locally, then squashes into one commit on user approval. Updates the plan file with implementation-details and post-mortem sections (after approval). Never pushes, never creates a PR. Only runs when explicitly invoked — do NOT auto-trigger on the words "implement" or "TDD".
4
+ ---
5
+
6
+ # tdd-implement
7
+
8
+ Implement an approved plan with strict, phase-bound TDD. Produce a single
9
+ squashed commit on a feature branch. Update the plan doc with what
10
+ happened. Stop before push.
11
+
12
+ ## Inputs
13
+
14
+ - **Plan file** — typically `.claude/artifacts/{KEY}_{slug}-plan.md`. The
15
+ user may pass it explicitly or by ticket key (`/tdd-implement S4R-10559`).
16
+ - **If no argument is given:** list all `*-plan.md` files in
17
+ `.claude/artifacts/` with last-modified dates and ask which to implement.
18
+ - **If no matching plan exists,** stop and tell the user to run
19
+ `/draft-plan` first. Do not invent a plan.
20
+
21
+ ## Workflow
22
+
23
+ ### 1. Read the plan end-to-end
24
+
25
+ Read the entire plan file. Pay attention to:
26
+
27
+ - **Goal** and **Approach** — the chosen direction.
28
+ - **Affected areas** — files / modules to change or conform to.
29
+ - **Sequencing** — the phases. This drives the TDD loop.
30
+ - **Test strategy** — which test surfaces to extend.
31
+ - **Risks & open questions** — flag any unresolved blockers.
32
+ - **Decisions during planning** — constraints baked in.
33
+
34
+ If any Risk or Open Question is unresolved and would block implementation,
35
+ stop and surface it to the user before doing anything else.
36
+
37
+ ### 2. Load repo conventions and architecture
38
+
39
+ Before writing any test or code, read these if they exist:
40
+
41
+ - `docs/conventions.md` — code style, testing approach, API/migration
42
+ rules, commit conventions.
43
+ - `docs/architecture.md` — package layout, domain model, cross-cutting
44
+ concerns.
45
+
46
+ If neither file exists, fall back to:
47
+
48
+ - `CLAUDE.md` / `AGENTS.md` at the repo root.
49
+ - The plan file alone.
50
+ - Top-level `README.md`.
51
+
52
+ State explicitly to the user which sources informed the implementation.
53
+ Skipping this step is the most common reason produced code does not match
54
+ the repo.
55
+
56
+ ### 3. Pre-flight
57
+
58
+ #### 3a. Detect the default branch
59
+
60
+ Do **not** assume `main`. Detect dynamically:
61
+
62
+ 1. Try `git symbolic-ref --short refs/remotes/origin/HEAD` → strip the
63
+ `origin/` prefix.
64
+ 2. If that fails, try `git config init.defaultBranch`.
65
+ 3. If both fail, list local branches and ask the user which is the
66
+ default.
67
+
68
+ Confirm the detected name with the user once before using it
69
+ (`"Default branch detected as 'main' — correct?"`). Use this value
70
+ everywhere `main` appears below.
71
+
72
+ #### 3b. Working tree and current branch
73
+
74
+ - Run `git status`. If there are uncommitted changes, stop and ask the
75
+ user how to proceed (stash / commit / abort).
76
+ - Run `git rev-parse --abbrev-ref HEAD`. If `HEAD` is **not** the default
77
+ branch, ask:
78
+ > *"You're currently on branch `{current}`. Branch from `{default}`
79
+ > (recommended) or from `{current}`?"*
80
+
81
+ #### 3c. Resume check
82
+
83
+ The user may be re-running `/tdd-implement` after an interrupted session.
84
+ Check whether a branch matching the conventional name already exists:
85
+
86
+ - Derive ticket key from the plan filename and the default branch name
87
+ `{KEY}-{slug}`.
88
+ - If `git rev-parse --verify {KEY}-{slug}` succeeds, **the branch
89
+ already exists**. Inspect its commit log:
90
+ - If it has commits matching `{KEY}: phase {N}…`, ask:
91
+ > *"Branch `{KEY}-{slug}` already exists with phases 1–{N} committed.
92
+ > Resume from phase {N+1}, restart from scratch, or cancel?"*
93
+ - On `resume`: check out the branch, skip ahead to phase {N+1} in the
94
+ phase loop.
95
+ - On `restart`: ask for confirmation, then delete the branch
96
+ (`git branch -D`) and re-create it. **Confirm before deleting.**
97
+ - On `cancel`: stop.
98
+ - If the branch does not exist, proceed.
99
+
100
+ #### 3d. Create the branch (if not resuming)
101
+
102
+ - Default branch name: `{KEY}-{slug}` where `{slug}` is from the plan
103
+ filename (e.g. `S4R-10559-ai-adoption-runbook`).
104
+ - Ask:
105
+ > *"Branch name `{KEY}-{slug}` look good, or do you want a different name?"*
106
+ - Create and check out the branch from the previously-confirmed base
107
+ (the default branch, or the user's chosen base from step 3b).
108
+
109
+ ### 4. Phase loop (strict TDD per phase)
110
+
111
+ For each phase in the plan's Sequencing section, in order:
112
+
113
+ #### 4a. Write failing tests for this phase
114
+
115
+ - Add tests covering the behavior in scope for this phase. Follow the
116
+ conventions in `docs/conventions.md` (testing section).
117
+ - Run the test suite and confirm the new tests **fail for the right
118
+ reason** (compile error or assertion failure that maps to missing
119
+ behavior, not a setup mistake).
120
+ - Commit locally:
121
+
122
+ ```text
123
+ {KEY}: phase {N} tests — <short phase title>
124
+ ```
125
+
126
+ #### 4b. Implement until green
127
+
128
+ - Make the minimum changes that turn the failing tests green.
129
+ - Follow conventions in `docs/conventions.md` and patterns in
130
+ `docs/architecture.md`.
131
+ - Run the full test suite. All tests (new and pre-existing) must pass
132
+ before this phase is considered complete.
133
+ - Refactor if needed; tests must stay green.
134
+ - Commit locally:
135
+
136
+ ```text
137
+ {KEY}: phase {N} — <short phase title>
138
+ ```
139
+
140
+ #### 4c. Move to next phase
141
+
142
+ Repeat 4a/4b until all phases are complete.
143
+
144
+ ### 5. Discovery triage during implementation
145
+
146
+ Discoveries happen. Classify each one and act accordingly:
147
+
148
+ - **Trivial** — typo, missing import, obvious local refactor, name clash
149
+ with no design implication. Resolve silently. Mention briefly in the
150
+ implementation-details section at the end.
151
+ - **Plan-affecting** — a new touch point not in the plan, a wrong file
152
+ path in the plan, a missing test surface, a sequencing change.
153
+ **Pause.** Tell the user what was found, propose how to adjust the
154
+ approach, wait for approval before proceeding. Capture the resolution
155
+ for the post-mortem.
156
+ - **Spec-affecting** — an acceptance criterion cannot be met as written,
157
+ ambiguity in the spec surfaces, scope appears to expand. **Stop.**
158
+ Do not proceed without explicit user direction. The plan may need to
159
+ be revised via `/draft-plan` again, or the spec may need to be
160
+ revisited. Capture the issue for the post-mortem.
161
+
162
+ When in doubt between trivial and plan-affecting, treat it as
163
+ plan-affecting and ask. Silent drift from the plan is the failure mode
164
+ to avoid.
165
+
166
+ ### 6. Verification gate
167
+
168
+ Before claiming implementation is complete, run the project's full check.
169
+ Detect the right command — do **not** assume Gradle:
170
+
171
+ 1. If `docs/conventions.md` or `CLAUDE.md` specifies a "full check" command,
172
+ use it.
173
+ 2. Otherwise detect from repo files (first match wins):
174
+ - `./gradlew` exists → `./gradlew check`
175
+ - `pom.xml` exists → `mvn verify`
176
+ - `package.json` exists → `npm test` (or `pnpm test` / `yarn test`
177
+ if the matching lockfile is present)
178
+ - `Cargo.toml` exists → `cargo test`
179
+ - `go.mod` exists → `go test ./...`
180
+ - `pyproject.toml` / `setup.py` / `tox.ini` exists → `pytest` (or
181
+ `tox`, or `python -m unittest` — pick the one the repo's CI uses
182
+ if visible)
183
+ 3. If none of the above matches, ask the user which command to run.
184
+
185
+ Capture and quote the actual command output in your message to the user.
186
+ Do not claim "passing" without evidence.
187
+
188
+ If anything fails, fix and re-run. If a failure is environmental (Docker
189
+ not running, port in use, missing tool), surface it — don't paper over.
190
+
191
+ ### 7. Propose plan update (NOT yet written)
192
+
193
+ Once verification passes, draft the two new sections in chat (do not yet
194
+ write to file):
195
+
196
+ ```markdown
197
+ ## Implementation Details
198
+
199
+ <What was actually built, file by file or area by area. Include:
200
+ - Files added / modified / removed (high-level — no line ranges).
201
+ - Deviations from the plan and why (link to discovery triage if any).
202
+ - Any trivial discoveries that didn't warrant pausing.
203
+ - Final test surface — what was added, what passed.
204
+ - Commands run to verify (the detected verification command, etc.) with results.>
205
+
206
+ ## Post-Mortem
207
+
208
+ <Reflective notes for the team. Include:
209
+ - What surprised you (good or bad).
210
+ - What the plan got right; what the plan missed.
211
+ - Patterns / conventions that should be documented (suggest, don't write).
212
+ - Follow-ups worth doing in a future ticket (suggest, don't open them).
213
+ - Anything worth promoting into `docs/decisions.md` (suggest, don't
214
+ write — decisions are append-only and human-curated even when the
215
+ /docs-init skill adds them).>
216
+ ```
217
+
218
+ Present both sections in chat. Ask:
219
+ > *"Approve these sections to be appended to the plan file? Reply
220
+ > `approve` to write them, or tell me what to change. Once written I
221
+ > will offer to squash the implementation commits."*
222
+
223
+ ### 8. Write the plan update on approval
224
+
225
+ - Append both sections verbatim to the plan file. Do **not** rewrite
226
+ prior sections.
227
+ - Preserve the existing `> **Scope:**`-style header if the plan has one.
228
+ - The plan file is gitignored (`.claude/artifacts/` is excluded), so this
229
+ edit produces no commit. Mention this so the user knows the change is
230
+ local-only.
231
+
232
+ ### 9. Squash and finish
233
+
234
+ Ask the user:
235
+ > *"Squash the {N} phase commits into a single `{KEY}: <plan headline>`
236
+ > commit, or keep the per-phase history? Reply `squash` (default) or
237
+ > `keep`."*
238
+
239
+ On `squash`:
240
+
241
+ 1. Identify the branch base via `git merge-base HEAD {default-branch}`,
242
+ using the default-branch name detected in step 3a.
243
+ 2. `git reset --soft <branch-base>` — collapses all phase commits into
244
+ the working stage.
245
+ 3. Create one fresh commit:
246
+
247
+ ```text
248
+ {KEY}: <plan headline>
249
+
250
+ <2-4 line terse summary of what changed. No bullet lists, no auto-
251
+ generated file inventories, no boilerplate footer.>
252
+ ```
253
+
254
+ 4. Show the final commit (`git log -1 --stat`) so the user can review.
255
+
256
+ On `keep`: leave the per-phase history intact.
257
+
258
+ ### 10. Stop
259
+
260
+ After the squash (or after the `keep` choice), the skill is done. Print
261
+ a single closing line:
262
+
263
+ > *"Branch `{branch}` is ready. Plan file updated at `<path>`. Push and
264
+ > open a PR when you're ready — I will not do that automatically."*
265
+
266
+ Do **not**:
267
+
268
+ - `git push` (even with `--dry-run`).
269
+ - Create a PR via `gh` or any other tool.
270
+ - Open follow-up tickets.
271
+ - Edit `docs/decisions.md`, `docs/operations.md`, or any doc the
272
+ post-mortem suggested updating — those are user actions.
273
+ - Start another implementation cycle ("want me to do the follow-ups now?").
274
+
275
+ ## Hard rules
276
+
277
+ - **Never assume the default branch is `main`.** Detect it in step 3a and
278
+ confirm with the user before using it.
279
+ - **Strict TDD per phase, never per-skill batch.** Tests first, green
280
+ before moving on. Do not write tests for phase N+1 before phase N is
281
+ green.
282
+ - **Every commit message starts with `{KEY}:`.** Per the repo convention
283
+ in `docs/conventions.md`.
284
+ - **Never push, never create a PR.** These are user actions only.
285
+ - **Never bypass verification.** The detected verification command (step 6)
286
+ must pass before the implementation is declared complete. No
287
+ `--no-verify`, no skipped tests, no commented-out failing assertions.
288
+ - **Never modify the spec file or prior plan sections.** Plan updates
289
+ are appended (Implementation Details + Post-Mortem). Specs are
290
+ audit records.
291
+ - **Never auto-act on post-mortem suggestions.** Suggestions are for the
292
+ user. The skill does not open tickets, write decisions entries, or
293
+ update docs based on the post-mortem.
294
+ - **Squash via `git reset --soft`, not interactive rebase.** No editor,
295
+ no risk of dropping commits.
296
+ - **Do not start implementation without an approved branch name.** Even
297
+ if the user invoked the skill, confirm the branch name once before
298
+ creating it.
299
+
300
+ ## Common mistakes
301
+
302
+ - Treating "/tdd-implement" invocation as authorization to skip the
303
+ branch-name confirmation.
304
+ - Hardcoding `main` instead of detecting the default branch. Some repos
305
+ use `master`, `develop`, or `trunk`.
306
+ - Skipping `docs/conventions.md` and `docs/architecture.md` in step 2.
307
+ Plans reference them; they are not duplicated in the plan.
308
+ - Re-creating an existing branch on resume without asking. Phases
309
+ already committed there are user work.
310
+ - Writing all tests up-front across all phases. Phase-bound is the rule.
311
+ - Resolving a plan-affecting discovery silently because it "seemed
312
+ small". Silent drift compounds — ask.
313
+ - Claiming verification passed without quoting the actual command output.
314
+ - Pushing or opening a PR on the user's behalf.
315
+ - Editing `docs/` based on post-mortem suggestions. The skill suggests,
316
+ the user acts.
317
+ - Squashing without showing the final commit and message for review.
318
+ - Forgetting the `{KEY}:` prefix on per-phase commits because "they'll
319
+ be squashed anyway." If the user picks `keep`, those commits become
320
+ history.