@groupby/ai-dev 0.5.14 → 0.5.15

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,278 @@
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 `.ai/tasks/{KEY}/plan.md`, 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. Appends a `## Deviations` and `## Post-Mortem` section to the local (gitignored) plan file. 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. This is **Step 4** of the AI-assisted
10
+ development workflow.
11
+
12
+ ## Inputs
13
+
14
+ - **Plan file** — `.ai/tasks/{KEY}/plan.md`. The user may pass it explicitly
15
+ or by ticket key (`/tdd-implement S4R-10559`).
16
+ - **If no argument is given:** list all `plan.md` files in `.ai/tasks/*/`
17
+ with last-modified dates and ask which to implement.
18
+ - **If no plan.md exists** (no argument given and none found under
19
+ `.ai/tasks/*/`, or an explicit key/path was given but the file is missing):
20
+ do **not** guess or fabricate a plan, and do **not** implement anything
21
+ without one. Ask the user for a plan-file path, a ticket key, or to run
22
+ `/draft-plan` first — then stop and wait for the user's answer. This
23
+ approval gate is never skipped: implementation only proceeds against an
24
+ approved `plan.md`.
25
+
26
+ ## Workflow
27
+
28
+ ### 1. Read the plan end-to-end
29
+
30
+ Read the entire plan file. Pay attention to:
31
+
32
+ - **Goal** and **Approach** — the chosen direction.
33
+ - **Affected areas** — files / modules to change or conform to.
34
+ - **Sequencing** — the phases. This drives the TDD loop.
35
+ - **Test strategy** — which test surfaces to extend.
36
+ - **Risks & open questions** — flag any unresolved blockers.
37
+ - **Decisions during planning** — constraints baked in.
38
+
39
+ If any Risk or Open Question is unresolved and would block implementation,
40
+ stop and surface it to the user before doing anything else.
41
+
42
+ ### 2. Load repo conventions and code-generation skills
43
+
44
+ Before writing any test or code, load these in order:
45
+
46
+ 1. Apply the `arch-context` skill to load baseline code conventions and any
47
+ additional architecture docs the plan's change types require (it owns the
48
+ Doc Routing Table and the conditional on whether `docs/architecture/`
49
+ exists in this repo).
50
+ 2. Load the `javascript` skill, then the `typescript` skill.
51
+ 3. Load the `react` skill (if `.tsx` files are involved).
52
+ 4. Load the `styled-components` skill (if `.styles.ts` files are involved).
53
+ 5. `.ai/patterns.md` (if it exists — check for relevant past solutions).
54
+
55
+ State explicitly to the user which sources informed the implementation.
56
+
57
+ ### 3. Pre-flight
58
+
59
+ #### 3a. Detect the default branch
60
+
61
+ Do **not** assume `main`. Detect dynamically:
62
+
63
+ 1. Try `git symbolic-ref --short refs/remotes/origin/HEAD` → strip `origin/`.
64
+ 2. If that fails, try `git config init.defaultBranch`.
65
+ 3. If both fail, ask the user.
66
+
67
+ Confirm with the user once before using it.
68
+
69
+ #### 3b. Working tree and current branch
70
+
71
+ - `git status`. If uncommitted changes, stop and ask (stash / commit / abort).
72
+ - Check current branch. If not on the expected feature branch, ask how to
73
+ proceed.
74
+
75
+ #### 3c. Branch check
76
+
77
+ The branch should already exist (created at workflow Step 2, after spec).
78
+ Check for `<type>/{KEY}-{slug}`:
79
+
80
+ - If the branch exists and is checked out — continue.
81
+ - If the branch exists but is not checked out — switch to it.
82
+ - If the branch does NOT exist — create it. Derive type from the Jira issue
83
+ type in `.ai/tasks/{KEY}/spec.md` (read it if present — do not fabricate
84
+ one if it's missing; ask the user for the issue type instead):
85
+ - Bug → `fix/`
86
+ - Story/Task → `feature/`
87
+ - Spike/Chore → `chore/`
88
+ - Or ask the user.
89
+ - Use the slug from `.ai/tasks/{KEY}/spec.md` metadata, if present; otherwise
90
+ ask the user for the slug.
91
+ - Confirm branch name with user before creating.
92
+
93
+ #### 3d. Resume check
94
+
95
+ If the branch already has implementation commits (matching
96
+ `<type>(<scope>): phase N`), ask:
97
+
98
+ > *"Branch has phases 1–{N} committed. Resume from phase {N+1}, restart,
99
+ > or cancel?"*
100
+
101
+ ### 4. Phase loop (strict TDD per phase)
102
+
103
+ For each phase in the plan's Sequencing section, in order:
104
+
105
+ #### 4a. Write failing tests for this phase
106
+
107
+ - Add tests covering the behavior in scope for this phase.
108
+ - Tests go in `test/unit/` and/or `test/integration/` (NOT co-located with src).
109
+ - Use custom `render()` from `test-utils.tsx` for component tests.
110
+ - Follow conventions from `docs/architecture/11-testing-strategy/`, if present.
111
+ - Run the tests for this phase's surface: `yarn test:unit` and/or
112
+ `yarn test:integration` (whichever surfaces the phase touches).
113
+ - Confirm new tests **fail for the right reason**.
114
+ - Commit:
115
+ ```
116
+ test(<scope>): phase {N} tests — <short phase title> ({KEY})
117
+ ```
118
+
119
+ #### 4b. Implement until green
120
+
121
+ - Make the minimum changes that turn the failing tests green.
122
+ - Follow loaded code-generation skills and architecture conventions.
123
+ - All user-visible strings through `useLocalization()` / FormatJS.
124
+ - Styled-components in `.styles.ts` with PascalCase exports.
125
+ - Redux state via `useAppSelector` / `useAppDispatch`.
126
+ - Path aliases: `@/` for imports from `src/`.
127
+ - Run `yarn test` — this runs the **full** unit + integration suite, not just
128
+ this phase's tests, so it also guards against regressions in earlier phases.
129
+ - All tests (new and pre-existing) must pass.
130
+ - Refactor if needed; tests must stay green.
131
+ - Lint and typecheck run only at the final verification gate (step 6),
132
+ not per phase.
133
+ - Commit:
134
+ ```
135
+ <type>(<scope>): phase {N} — <short phase title> ({KEY})
136
+ ```
137
+ Where `<type>` matches the branch type (feat/fix/chore).
138
+
139
+ #### 4c. Move to next phase
140
+
141
+ Repeat 4a/4b until all phases are complete.
142
+
143
+ ### 5. Discovery triage during implementation
144
+
145
+ | Category | Action |
146
+ |----------|--------|
147
+ | **Trivial** — typo, missing import, name clash | Fix silently. Note in the plan's `## Deviations` section. |
148
+ | **Plan-affecting** — new touch point, wrong path, sequencing change | **Pause.** Tell user. Propose adjustment. Wait for approval. Append a `## Revision` section to `plan.md`, using the format defined in the `draft-plan` skill's "Plan Revision" section (Trigger / Change / Impact / Approved by). |
149
+ | **Spec-affecting** — AC cannot be met, scope expands | **Stop.** Do not proceed without user direction. May need `/draft-plan` revision. |
150
+
151
+ When in doubt → treat as plan-affecting and ask.
152
+
153
+ ### 6. User checkpoint
154
+
155
+ After all phases are complete and verification passes, show:
156
+
157
+ - Files changed (`git diff --stat` from branch base)
158
+ - Verification output (lint + typecheck + test — all green)
159
+ - Summary: what was done per phase
160
+
161
+ User options:
162
+ - `[ok]` → proceed to AI review (next workflow step)
163
+ - `[check]` → user inspects manually, then `[ok]` / `[fix X]` / `[rethink]`
164
+ - `[fix X]` → agent fixes, re-runs verification, shows result again
165
+
166
+ ### 7. Append Deviations + Post-Mortem to the plan
167
+
168
+ Once the user accepts the checkpoint (`[ok]`), append two short sections to the
169
+ **end** of `plan.md`. Append verbatim — never rewrite earlier sections.
170
+
171
+ ```markdown
172
+ ## Deviations
173
+
174
+ <Only what was actually done outside or beyond the plan: unplanned touch
175
+ points, corrected file paths, scope adjustments, trivial discoveries that
176
+ changed nothing structurally. If nothing diverged, write "None".>
177
+
178
+ ## Post-Mortem
179
+
180
+ <A brief reflection for reviewers: what the plan got right, what it missed,
181
+ gotchas worth remembering. Keep it to a few bullets.>
182
+ ```
183
+
184
+ - The `.ai/` folder is gitignored, so this edit produces **no commit** — it is
185
+ local-only and reaches the team later through the PR body (`/draft-pr` embeds
186
+ the plan under a `<details>` block).
187
+ - There is **no** separate `history.md` — the plan is the single record.
188
+ - If a `## Revision` section was added during implementation (step 5), leave it
189
+ in place; `## Deviations` complements it (Revision = approved mid-flight plan
190
+ change, in the `draft-plan` skill's format; Deviations = what actually
191
+ happened).
192
+
193
+ ### 8. Squash (on user request, typically after review)
194
+
195
+ When the user is ready (usually after `/pr-review` passes):
196
+
197
+ > *"Squash the {N} phase commits into one? Reply `squash` or `keep`."*
198
+
199
+ On `squash`:
200
+
201
+ 1. `git merge-base HEAD {default-branch}` → find branch point.
202
+ 2. `git reset --soft <branch-base>` → collapse all commits.
203
+ 3. Create one commit:
204
+ ```
205
+ <type>(<scope>): <plan headline> ({KEY})
206
+
207
+ <2-4 line summary of what changed.>
208
+ ```
209
+ 4. Show `git log -1 --stat` for review.
210
+
211
+ On `keep`: leave per-phase history intact.
212
+
213
+ ### 9. Stop
214
+
215
+ After squash (or keep), print:
216
+
217
+ > *"Implementation complete. Run `/pr-review` for the next step, or
218
+ > `/draft-pr` if review is already done."*
219
+
220
+ Do **not**:
221
+ - `git push`
222
+ - Create a PR
223
+ - Open follow-up tickets
224
+ - Edit docs based on discoveries (suggest in the plan's Post-Mortem, don't write)
225
+
226
+ ## Verification gate
227
+
228
+ Run once after **all phases are complete** (before step 6 user checkpoint):
229
+
230
+ ```bash
231
+ yarn lint && yarn typecheck && yarn test
232
+ ```
233
+
234
+ This runs:
235
+ - ESLint (Airbnb + TypeScript + React hooks + sonarjs + FormatJS)
236
+ - TypeScript compiler (`tsc --noEmit`)
237
+ - Unit tests (Jest + Testing Library)
238
+ - Integration tests (Jest)
239
+
240
+ All three must pass before declaring the implementation complete. This is a
241
+ **final gate only** — per-phase checks run `yarn test` alone (step 4b), which
242
+ already covers both unit and integration tests; lint and typecheck are
243
+ deferred to this final gate.
244
+ No `--no-verify`, no skipped tests, no commented-out assertions.
245
+
246
+ **TDD watch mode:** For interactive development, recommend `yarn tdd` (runs
247
+ unit + integration in parallel watch mode).
248
+
249
+ ## Hard rules
250
+
251
+ - **Branch format:** `<type>/{KEY}-{slug}` — never bare KEY, never missing type prefix.
252
+ - **Commit format:** `<type>(<scope>): <description> ({KEY})` — key in parentheses at end.
253
+ - **Strict TDD per phase.** Tests first, green before moving on.
254
+ - **Never push, never create a PR.**
255
+ - **Never implement without an approved `plan.md`.** If none can be found, ask
256
+ the user — do not fabricate one and do not proceed without it.
257
+ - **Never bypass verification.** Full `yarn lint && yarn typecheck && yarn test` must pass.
258
+ - **Never modify the spec file.**
259
+ - **Plan revisions are appended, not overwritten.**
260
+ - **Squash via `git reset --soft`, not interactive rebase.**
261
+ - **User checkpoint before declaring done.** Agent waits for explicit go-ahead.
262
+ - **Load code-generation skills before writing code.** Do not rely on memory.
263
+
264
+ ## Common mistakes
265
+
266
+ - Hardcoding `main` instead of detecting the default branch.
267
+ - Creating branch as `{KEY}-{slug}` without the type prefix.
268
+ - Writing commits as `{KEY}: ...` instead of `<type>(<scope>): ... ({KEY})`.
269
+ - Running only `yarn test` without lint and typecheck.
270
+ - Placing tests next to source files instead of in `test/unit/` or `test/integration/`.
271
+ - Using raw CSS or inline styles instead of styled-components.
272
+ - Using raw strings in JSX instead of FormatJS i18n.
273
+ - Skipping the user checkpoint and jumping to squash.
274
+ - Writing all tests up-front across all phases instead of phase-by-phase.
275
+ - Silently resolving plan-affecting discoveries.
276
+ - Pushing or opening a PR.
277
+ - Implementing against a guessed or fabricated plan instead of asking the user
278
+ when no `plan.md` can be found.