@softure-ai/skills 0.2.1 → 0.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 (50) hide show
  1. package/README.md +4 -0
  2. package/WORKFLOW.md +6 -2
  3. package/package.json +1 -1
  4. package/skills/softure-archive/SKILL.md +76 -24
  5. package/skills/softure-archive/references/example-archive.md +106 -0
  6. package/skills/softure-code-review/SKILL.md +68 -18
  7. package/skills/softure-code-review/references/example-review.md +108 -0
  8. package/skills/softure-frame/SKILL.md +129 -40
  9. package/skills/softure-frame/references/diagnostic-lens.md +85 -0
  10. package/skills/softure-frame/references/examples.md +111 -0
  11. package/skills/softure-frame/references/pushback.md +38 -0
  12. package/skills/softure-impl-review/SKILL.md +138 -76
  13. package/skills/softure-impl-review/references/example-review.md +127 -0
  14. package/skills/softure-impl-review/references/rubric.md +120 -0
  15. package/skills/softure-impl-review/references/triage.md +124 -0
  16. package/skills/softure-implement/SKILL.md +116 -49
  17. package/skills/softure-implement/references/phase-commit.md +214 -0
  18. package/skills/softure-implement/references/worked-example.md +201 -0
  19. package/skills/softure-init/SKILL.md +57 -41
  20. package/skills/softure-init/references/example.md +96 -0
  21. package/skills/softure-init/references/templates.md +73 -0
  22. package/skills/softure-lesson/SKILL.md +47 -19
  23. package/skills/softure-lesson/references/examples.md +65 -0
  24. package/skills/softure-new/SKILL.md +100 -43
  25. package/skills/softure-new/references/example-change.md +149 -0
  26. package/skills/softure-new/references/placement.md +60 -0
  27. package/skills/softure-plan/SKILL.md +182 -50
  28. package/skills/softure-plan/references/plan-example.md +206 -0
  29. package/skills/softure-plan/references/progress-format.md +56 -2
  30. package/skills/softure-plan/references/questioning.md +162 -0
  31. package/skills/softure-plan-review/SKILL.md +211 -83
  32. package/skills/softure-plan-review/references/lenses.md +121 -0
  33. package/skills/softure-plan-review/references/review-example.md +184 -0
  34. package/skills/softure-prd/SKILL.md +130 -71
  35. package/skills/softure-prd/references/example-prd.md +233 -0
  36. package/skills/softure-prd/references/leak-lint.md +43 -0
  37. package/skills/softure-prd/references/prd-template.md +219 -0
  38. package/skills/softure-research/SKILL.md +73 -33
  39. package/skills/softure-research/references/example-research.md +106 -0
  40. package/skills/softure-research/references/fan-out.md +61 -0
  41. package/skills/softure-roadmap/SKILL.md +211 -65
  42. package/skills/softure-roadmap/references/example-roadmap.md +203 -0
  43. package/skills/softure-roadmap/references/interview.md +132 -0
  44. package/skills/softure-roadmap/references/slicing.md +118 -0
  45. package/skills/softure-rule-review/SKILL.md +83 -19
  46. package/skills/softure-rule-review/references/example-report.md +73 -0
  47. package/skills/softure-rule-review/references/scorecard.md +129 -0
  48. package/skills/softure-shape/SKILL.md +163 -53
  49. package/skills/softure-shape/references/example-shape-notes.md +192 -0
  50. package/skills/softure-shape/references/question-bank.md +248 -0
@@ -2,10 +2,13 @@
2
2
  name: softure-plan
3
3
  description: >
4
4
  Turn research into an executable, phased plan: context/changes/<id>/plan.md with an
5
- explicit approach, thin verifiable phases (each TDD or test-after, with files, steps
6
- and done-when criteria) and a canonical ## Progress section. Use after softure-research
5
+ explicit approach, key decisions, thin verifiable phases (each TDD or test-after, with
6
+ files, intent and contract per step, and done-when criteria) and a canonical ## Progress
7
+ section. Interviews the user one question at a time with a recommended answer, confirms
8
+ the phase outline, and can refine or re-plan an existing plan. Use after softure-research
7
9
  (or softure-frame) and before implementation. Triggers: "plan the change", "write the
8
- plan", "/softure-plan", "break it into phases".
10
+ plan", "/softure-plan", "break it into phases", "re-plan the remaining phases",
11
+ "refine the plan".
9
12
  argument-hint: "<change-id> [--auto]"
10
13
  allowed-tools:
11
14
  - Read
@@ -24,69 +27,161 @@ A plan answers *how*. After this step, implementation is execution: no design de
24
27
  open questions, no "figure it out later". If a phase cannot be described concretely, research
25
28
  is not finished.
26
29
 
30
+ The plan tells the implementer **what to change and why**, not how to type it. It is written
31
+ for someone who was not in the conversation: they must understand every choice from the file
32
+ alone.
33
+
27
34
  ## Required inputs
28
35
 
29
36
  - `context/workflow.json`: if missing, run `softure-init` first.
30
37
  - `context/changes/<id>/change.md` with `status: preparing`. If the status is `new`, run
31
- `softure-research` first.
38
+ `softure-research` first. Other statuses: see "Existing plan" below.
32
39
  - `context/changes/<id>/research.md`: if missing, run `softure-research` first. If research has
33
40
  an **escalated** open question that is still unanswered, stop and surface it.
34
41
  - `frame.md`, when present. Its conclusions override change.md wording.
35
42
  - `context/foundation/lessons.md`, when present.
36
43
 
37
- ## Procedure
38
-
39
- 1. **Assess complexity.** Base it on research: affected surface, data changes, risk.
40
- State it as `small` (1 phase), `medium` (2–3) or `large` (4+). Large plans are a smell, so
41
- consider splitting the change and say so. In interactive mode, confirm the assessment in one
42
- question.
44
+ ## Resolve the input
45
+
46
+ - **No argument:** list `context/changes/*/change.md` with status `preparing` (and `planned`,
47
+ for refining), newest `updated` first, and ask which one. In `--auto` an id is mandatory:
48
+ stop and say so.
49
+ - **A path under `context/archive/`:** refuse. Say the change is archived and a new one is
50
+ opened with `softure-new`.
51
+ - **Existing plan.md**, by change.md status:
52
+ - `preparing`: an unfinished draft from an earlier session. Read it, continue where it
53
+ stops, and do not re-ask what it already decides.
54
+ - `planned` or `plan_reviewed`: **refine mode.** Read plan.md and `reviews/plan-review.md`
55
+ (if any), change only what the request or the review asks for, keep the structure and the
56
+ Progress numbering. Set the status back to `planned` so the change is reviewed again.
57
+ - `implementing`: **re-plan mode** (sent here by softure-implement or plan-review). Done
58
+ phases and their ticked Progress items stay untouched. Rewrite only the remaining phases.
59
+ Follow the mid-flight rules in `references/progress-format.md` (new items take the next
60
+ free number, obsolete items are marked dropped). Set the status to `planned`.
61
+ - `implemented` or later: do not touch the plan. Point to softure-impl-review or a new change.
43
62
 
44
- 2. **Probe the gaps.** Ask about ambiguities that change the plan. Ask **one question at a time**,
45
- at most about 10, and stop as soon as answers stop changing the plan. Each question offers 2–4
46
- options with the recommended one first, marked `(Recommended)`, and a one-line trade-off for
47
- each. Never ask what the code or research already answers.
63
+ ## Procedure
48
64
 
49
- 3. **Choose the approach.** Write 2–3 viable options. For each give a one-line description, its
65
+ 1. **Read everything yourself, fully, before asking or delegating.** change.md, research.md,
66
+ frame.md, lessons.md, workflow.json, and any earlier plan in `context/changes/` or
67
+ `context/archive/` that touched the same files. Research's current state and affected
68
+ surface are your codebase baseline: do not re-search what it already mapped. Lessons whose
69
+ "Applies to" matches are priors: they settle design pitfalls without a question.
70
+ Use read-only subagents only for **gaps** research left (for example, the exact call sites
71
+ of a function the plan will change). Give each a focused question with paths, ask for
72
+ `path:line` evidence, and check surprising answers against the code yourself.
73
+
74
+ 2. **Play back what you understood, then assess complexity.** In a few lines: what must be
75
+ true at the end, the two or three discoveries that shape the plan (with `path:line`), and
76
+ the edge cases you already see. Then state the complexity with its reasons (systems
77
+ touched, data changes, integration points, unknowns, test surface):
78
+ - `small`: 1 phase, a handful of files, follows an existing pattern;
79
+ - `medium`: 2-3 phases, design decisions with real trade-offs;
80
+ - `large`: 4+ phases, cross-cutting or data-heavy. This is a smell: propose splitting the
81
+ change and say where the cut would go.
82
+
83
+ Interactive: confirm in one question (Agree / It is bigger / It is smaller). `--auto`: take
84
+ your own assessment and record it.
85
+
86
+ 3. **Probe the gaps, one question at a time.** Ask only about ambiguities whose answer changes
87
+ the plan. Each question offers 2-4 concrete options, the recommended one first and marked
88
+ `(Recommended)`, each with one line of what it means, its strength and its trade-off. The
89
+ recommendation is grounded in research or the code, never a guess. Stop as soon as answers
90
+ stop changing the plan.
91
+ - **Budget** (a ceiling, not a quota): research only: small 2-4, medium 4-7, large 6-10.
92
+ Research plus frame: small 1-2, medium 2-4, large 4-6, and no questions about the
93
+ problem itself, because frame settled it.
94
+ - **Never ask** what change.md, research, frame or lessons already answer, implementation
95
+ details you can read from the code (patterns, error handling, test setup), or
96
+ preferences that do not change the plan.
97
+ - **Push back.** When the user corrects a fact, verify it in the code before accepting it;
98
+ if the code disagrees, show the evidence and ask again. When an answer contradicts
99
+ change.md Constraints or grows the scope, say so and offer: keep the scope, or record
100
+ the extension in change.md first. When the user picks a costlier option, state the cost
101
+ once, then follow their choice.
102
+ - Question categories, the budget table and worked examples:
103
+ read `references/questioning.md` when preparing the questions.
104
+
105
+ `--auto`: ask nothing. Take the recommended option for every question you would have asked
106
+ and record each as `- <question> → <choice> (<reason>)` under `## Decisions (auto)`.
107
+
108
+ 4. **Choose the approach.** Write 2-3 viable options. For each give a one-line description, its
50
109
  cost, its risk and its reversibility. Recommend one and say why.
51
110
  - If a SOFTURE module covers the capability (research §SOFTURE modules), the module-based
52
- option is the default.
53
- - Re-implementing a covered capability needs an explicit reason.
54
-
55
- 4. **Slice into phases.** Each phase is a **thin, independently verifiable increment** that
56
- leaves the system working: green gates, deployable. Prefer vertical slices (data → logic →
57
- UI for one behaviour) over horizontal layers. For each phase write:
111
+ option is the default. Re-implementing a covered capability needs an explicit reason.
112
+ - Interactive: ask only when the choice genuinely matters and the code does not decide it.
113
+ When one option clearly wins, state it and why, and move on.
114
+ - Record every decision that shapes the plan in the **Key decisions** table, with its
115
+ source (change, research, frame, owner, plan), so a later reader sees what was settled
116
+ upstream and what was decided here.
117
+
118
+ 5. **Slice into phases and confirm the outline.** Each phase is a **thin, independently
119
+ verifiable increment** that leaves the system working: green gates, deployable. Prefer
120
+ vertical slices (data, logic and UI for one behaviour) over horizontal layers. Useful
121
+ orders *inside* a slice:
122
+ - data change: migration, data access, domain logic, entry point (route, action, job), UI;
123
+ - new behaviour: the rule as a pure function under test first, then the wiring;
124
+ - refactor: pin current behaviour with characterisation tests, change in small steps,
125
+ keep old callers working, remove the old path last.
126
+
127
+ Interactive: print the outline (one line per phase: what it delivers) and ask: Looks right
128
+ (Recommended) / Adjust / Merge phases (too granular) / Split phases (too coarse). `--auto`:
129
+ keep your outline.
130
+
131
+ 6. **Write each phase.**
58
132
  - **Discipline:**
59
133
  - `TDD` for logic with clear inputs and outputs (calculations, money, parsing, state
60
134
  machines, migrations with invariants, security rules);
61
135
  - `test-after` for UI wiring, copy and layout.
62
136
  - **Files:** the paths to create or modify, taken from research.
63
- - **Steps:** concrete and ordered. Name the functions, components, tables and commands.
64
- - **Done when:** criteria phrased so that someone else could check them. Split them into
65
- *Automated* (a command, a test, a query) and *Manual* (only a human can judge it, such as
66
- visual quality or tone).
137
+ - **Steps:** concrete and ordered. Each step names its file and states its **intent** (what
138
+ changes and why, in one or two sentences) and, when other steps depend on it, its
139
+ **contract** (signature, schema column, route, event, invariant). Name the functions,
140
+ components, tables and commands. **No code by default.** Add a short snippet only when the
141
+ change is non-obvious: a tricky query, an unusual API call, an ordering that looks wrong
142
+ but is not, a workaround for a known bug.
143
+ - **Tests:** the named cases, including empty, boundary and failure paths.
144
+ - **Done when:** criteria phrased so that someone else could check them, as plain bullets
145
+ (checkboxes live only in `## Progress`). Split them into *Automated* (a command, a test,
146
+ a query) and *Manual* (only a human can judge it, such as visual quality or tone).
67
147
  - The last automated criterion of every phase is "Gates green (typecheck, lint, test)", using
68
- the gates from `workflow.json`.
148
+ the gates from `workflow.json`. Never write the commands themselves into the plan from
149
+ memory: take them from `workflow.json`.
69
150
 
70
- 5. **Plan data safety.** For any schema or data change, include:
71
- - the migration;
72
- - its rollback path, or an explicit "forward-only, because…";
73
- - a backfill when needed;
151
+ 7. **Plan data safety.** For any schema or data change, include:
152
+ - the migration (in the `workflow.json` migrations folder, when configured);
153
+ - its rollback path, or an explicit "forward-only, because...";
154
+ - a backfill when needed, restartable when the table is large;
74
155
  - a criterion that reads real rows. A rendered UI never proves data was written.
75
156
 
76
- 6. **Write risks and rollback.** List what can fail in production and how to undo each phase.
157
+ 8. **Add critical details only when they exist.** Under `## Approach`, an optional
158
+ **Critical details** block holds what the implementer must know before touching the code
159
+ and cannot see from the paths: a non-obvious ordering or race, a time-zone or rounding rule,
160
+ a performance budget with a number, a state change whose obvious order is wrong. One to
161
+ three sentences each. No templated bullets: a plan without this block is not incomplete.
162
+
163
+ 9. **Write risks and rollback.** List what can fail in production and how to undo each phase.
77
164
 
78
- 7. **Remove open questions.** Search your draft for "TBD", "maybe", "or", "?" and "decide later".
79
- Resolve each one, or move it back to research as an escalation and stop.
165
+ 10. **Remove open questions.** Search your draft for "TBD", "maybe", "or", "?" and "decide
166
+ later". Resolve each one, or move it back to research as an escalation and stop.
80
167
 
81
- 8. **Write the Progress section** exactly per `references/progress-format.md`: one
82
- `### Phase N:` per `## Phase N:`, and every Done-when criterion as a numbered checkbox.
168
+ 11. **Write the Progress section** exactly per `references/progress-format.md`: one
169
+ `### Phase N:` per `## Phase N:`, and every Done-when criterion as a numbered checkbox.
83
170
 
84
- 9. **Write `plan.md`** in the `workflow.json` language, using the template below.
171
+ 12. **Write `plan.md`** in the `workflow.json` language, using the template below, then run the
172
+ quality checklist against it. A complete worked example (and a bad one, with why):
173
+ `references/plan-example.md`, read it before writing your first plan in a repo.
85
174
 
86
- 10. **Update `change.md`.** Set `status: planned` and update `updated`.
175
+ 13. **Update `change.md`.** Set `status: planned` and update `updated`.
87
176
 
88
- 11. **Report** the approach in one line, the number of phases, the riskiest phase, and the next
89
- step.
177
+ 14. **Report and iterate.** Give: the approach in one line, a phases-at-a-glance table
178
+ (`| Phase | Delivers | Key risk |`), the decisions taken, the riskiest phase, and the next
179
+ step. Interactive: ask what to adjust (phase scope, criteria precision, missing edge
180
+ cases, scope items) and apply the changes until the user is satisfied. `--auto`: no
181
+ iteration; report and hand off.
182
+
183
+ If the session gets long, write the draft to plan.md early (status stays `preparing`). A fresh
184
+ `softure-plan <id>` picks it up as a draft.
90
185
 
91
186
  ## Output template
92
187
 
@@ -96,17 +191,34 @@ is not finished.
96
191
  Input: change.md, research.md[, frame.md]. Complexity: <small|medium|large>.
97
192
 
98
193
  ## Goal
99
- <the outcome from change.md, made measurable>
194
+ <the outcome from change.md, made measurable: what a user can do, what is true in the data>
195
+
196
+ **Out of scope:** <what this change deliberately does not do, so phases cannot drift into it>
100
197
 
101
198
  ## Approach
102
- **Chosen:** <option> — <why>.
103
- Rejected: <option> — <one line>; <option> — <one line>.
199
+ **Starting point:** <how it works today, 2-4 lines from research, with path:line>
200
+
201
+ **Chosen:** <option> - <why>.
202
+ Rejected: <option> - <one line>; <option> - <one line>.
203
+
204
+ **Key decisions:**
205
+ | Decision | Choice | Why | Source |
206
+ | --- | --- | --- | --- |
207
+ | <area> | <choice> | <one sentence> | research / frame / owner / plan |
208
+
209
+ **Critical details:** <optional; only real constraints>
104
210
 
105
211
  ## Phase 1: <title>
106
212
  **Discipline:** TDD | test-after. **Files:** `a.ts`, `b.tsx`, `migrations/00NN_x.sql`
107
- 1. <step>
108
- 2. <step>
109
- **Done when:** <criteria, automated then manual>
213
+
214
+ 1. `path/a.ts`: <intent>. Contract: <signature / column / route>.
215
+ 2. `path/b.tsx`: <intent>.
216
+
217
+ **Tests:** <named cases>
218
+
219
+ **Done when:**
220
+ - Automated: <criterion>; Gates green (typecheck, lint, test).
221
+ - Manual: <criterion>.
110
222
 
111
223
  ## Phase 2: <title>
112
224
  ...
@@ -121,15 +233,24 @@ Rejected: <option> — <one line>; <option> — <one line>.
121
233
  <per references/progress-format.md>
122
234
  ```
123
235
 
236
+ `## Goal`, `## Approach`, `## Phase N:`, `## Risks and rollback`, `## Decisions (auto)` and
237
+ `## Progress` are the fixed headings from WORKFLOW.md §6. Everything else is a bold label inside
238
+ them, never an extra `##` heading.
239
+
124
240
  ## Status transitions
125
241
 
126
- - `preparing` → `planned`.
242
+ - `preparing` → `planned` (new plan).
243
+ - `plan_reviewed` → `planned` (refine mode: the change is reviewed again).
244
+ - `implementing` → `planned` (re-plan mode: the remaining phases are reviewed before
245
+ implementation resumes at the first open Automated item).
127
246
 
128
247
  ## `--auto`
129
248
 
130
- - Skip confirmations. Take the recommended option for every probing question and record it under
131
- `## Decisions (auto)` as `- <question> → <choice> (<reason>)`.
249
+ - Skip every confirmation (complexity, approach, outline, final iteration). Take the
250
+ recommended option for every probing question and record it under `## Decisions (auto)` as
251
+ `- <question> → <choice> (<reason>)`.
132
252
  - Prefer the smallest reversible approach. Prefer TDD whenever the discipline is in doubt.
253
+ - Never stop to ask for an id: without one, stop and report.
133
254
  - Stop and escalate when the only viable approach contradicts change.md Constraints, requires a
134
255
  destructive data operation, or needs an owner-only decision.
135
256
 
@@ -137,11 +258,17 @@ Rejected: <option> — <one line>; <option> — <one line>.
137
258
 
138
259
  - [ ] Every phase leaves the system green and deployable.
139
260
  - [ ] Every criterion is checkable by someone who did not write it.
140
- - [ ] Every phase states its discipline and lists its files.
261
+ - [ ] Every phase states its discipline, lists its files and names its test cases.
262
+ - [ ] Every step names a file and an intent; contracts are stated where other steps depend on
263
+ them; code appears only where it is non-obvious.
141
264
  - [ ] Data changes have migration, rollback (or a justified forward-only) and a real-data check.
142
265
  - [ ] The SOFTURE module verdict from research is honoured, or overridden with a reason.
266
+ - [ ] Every capability promised in `## Goal` has a phase that builds it, and nothing listed as
267
+ out of scope appears in a phase.
268
+ - [ ] The Key decisions table names a source for every decision.
143
269
  - [ ] The plan contains no open questions.
144
- - [ ] `## Progress` matches the phases one-to-one and follows the reference format.
270
+ - [ ] Phase blocks have no checkboxes; `## Progress` matches the phases one-to-one and follows
271
+ the reference format.
145
272
 
146
273
  ## Anti-patterns
147
274
 
@@ -149,7 +276,12 @@ Rejected: <option> — <one line>; <option> — <one line>.
149
276
  the end.
150
277
  - Criteria like "works correctly" or "looks good". Say what is measured and how.
151
278
  - A plan that re-decides what research already established, or ignores a relevant lesson.
279
+ - Asking the user what the code, research or frame already answers; padding the interview to
280
+ reach a number.
281
+ - Accepting a user's factual correction without checking the code.
152
282
  - Hiding design work in a step ("figure out the caching strategy").
283
+ - Pre-writing the code: pages of snippets for routine edits that follow an existing pattern.
284
+ - A filled-in "Critical details" block full of generic advice ("use memoization").
153
285
  - More than about 6 phases without proposing to split the change.
154
286
 
155
287
  ## Handoff
@@ -0,0 +1,206 @@
1
+ # Worked example: a plan, good and bad
2
+
3
+ Read this before writing a plan in a repo for the first time, or when unsure how concrete a
4
+ step or a criterion should be. The domain is a small invoicing tool (TypeScript, Postgres, a
5
+ job scheduler, server actions). Paths and names are illustrative. The commands come from
6
+ `context/workflow.json`; the plan never spells them out itself.
7
+
8
+ The plan below is the version *after* softure-plan-review. The review that produced it is in
9
+ `softure-plan-review/references/review-example.md`.
10
+
11
+ ## Good: `overdue-invoice-reminders`
12
+
13
+ ```markdown
14
+ # Plan: overdue-invoice-reminders
15
+
16
+ Input: change.md, research.md. Complexity: medium.
17
+
18
+ ## Goal
19
+ Every unpaid or partially paid invoice receives exactly one reminder email three days after
20
+ its due date, unless its client has reminders switched off. "Exactly one" holds when the job
21
+ runs twice, runs late, or two instances run at once.
22
+
23
+ **Out of scope:** second and later reminders; SMS; reminder wording per client; a reminder
24
+ history screen (backlog: `context/backlog/invoicing.md`).
25
+
26
+ ## Approach
27
+ **Starting point:** invoices carry `due_on date` and `paid_cents` (`src/db/schema.ts:120-141`);
28
+ nothing records a reminder. The scheduler runs `src/jobs/*.ts` every 15 minutes
29
+ (`src/jobs/registry.ts:8`). Receipts already go through the SOFTURE mail module
30
+ (`softure.config.ts:22`).
31
+
32
+ **Chosen:** a scheduled job that selects eligible invoices and claims each one with a
33
+ conditional update before sending - one row, one claim, one email.
34
+ Rejected: send on invoice view (no view, no reminder); a queue per invoice created at issue
35
+ time (needs a queue we do not run, and re-dating an invoice would leave stale entries).
36
+
37
+ **Key decisions:**
38
+ | Decision | Choice | Why | Source |
39
+ | --- | --- | --- | --- |
40
+ | Partially paid invoices | included, remaining amount shown | dashboard already treats them as overdue | owner |
41
+ | Reference time zone | the account's `time_zone` | due dates are local business dates | research |
42
+ | Duplicate protection | `UPDATE ... WHERE reminder_sent_at IS NULL RETURNING id` | works across instances without a lock table | plan |
43
+ | Mail | SOFTURE mail module | covered, already configured | research |
44
+ | Failed send | release the claim, retry on the next run | a lost reminder is worse than a late one | owner |
45
+
46
+ **Critical details:** claim first, send second, release on failure. Sending first and marking
47
+ afterwards double-sends whenever two instances overlap, and the scheduler does overlap during
48
+ deploys (research §Risks).
49
+
50
+ ## Phase 1: Reminder state and eligibility rule
51
+ **Discipline:** TDD. **Files:** `drizzle/0042_invoice_reminders.sql`, `src/db/schema.ts`,
52
+ `src/invoices/reminders.ts`, `src/invoices/reminders.test.ts`
53
+
54
+ 1. `drizzle/0042_invoice_reminders.sql`: add `invoices.reminder_sent_at timestamptz null` and
55
+ `clients.reminders_enabled boolean not null default true`. Forward-only, because both are
56
+ additive; rollback is dropping the two columns, no data depends on them yet.
57
+ 2. `src/db/schema.ts`: mirror both columns.
58
+ 3. `src/invoices/reminders.ts`: `findInvoicesDueForReminder(db, now): Promise<InvoiceId[]>`.
59
+ Intent: one query that is the single definition of "due for a reminder". Contract: returns
60
+ ids where `due_on + 3 days <= local date of now in the account's zone`, remaining amount
61
+ > 0, `reminder_sent_at is null`, client `reminders_enabled`.
62
+
63
+ **Tests:** due exactly 3 days ago (selected); 2 days ago (not); fully paid (not); partially
64
+ paid (selected); already reminded (not); client switched off (not); account in a zone where
65
+ `now` is still the previous day (not); no invoices (empty list).
66
+
67
+ **Done when:**
68
+ - Automated: the eight cases above pass in `src/invoices/reminders.test.ts`; the migration
69
+ applies on a copy of the dev database and both columns exist with the stated defaults;
70
+ Gates green (typecheck, lint, test).
71
+
72
+ ## Phase 2: Sending job, safe to run twice
73
+ **Discipline:** TDD. **Files:** `src/jobs/send-invoice-reminders.ts`,
74
+ `src/jobs/send-invoice-reminders.test.ts`, `src/jobs/registry.ts`,
75
+ `src/mail/templates/invoice-reminder.ts`, `messages/en.ts`
76
+
77
+ 1. `src/jobs/send-invoice-reminders.ts`: for each id from `findInvoicesDueForReminder`, claim
78
+ with `UPDATE invoices SET reminder_sent_at = now() WHERE id = $1 AND reminder_sent_at IS
79
+ NULL RETURNING id`; send only when a row came back; on a send failure, set
80
+ `reminder_sent_at` back to null and log the invoice id and the error.
81
+ 2. `src/mail/templates/invoice-reminder.ts`: subject and body with invoice number, remaining
82
+ amount and payment link; copy lives in `messages/en.ts`.
83
+ 3. `src/jobs/registry.ts`: register the job on the existing 15-minute schedule.
84
+
85
+ **Tests:** two concurrent runs over the same invoice send one email; a failed send leaves
86
+ `reminder_sent_at` null and the next run sends; an empty selection sends nothing.
87
+
88
+ **Done when:**
89
+ - Automated: the three cases above pass; after one run against the dev database,
90
+ `select count(*) from invoices where reminder_sent_at is not null` equals the eligible
91
+ count taken before the run, and a second run sends 0; Gates green (typecheck, lint, test).
92
+ - Manual: the reminder email reads correctly in a real inbox, amount and link included.
93
+
94
+ ## Phase 3: Per-client switch
95
+ **Discipline:** test-after. **Files:** `src/app/clients/[id]/settings-form.tsx`,
96
+ `src/app/clients/[id]/actions.ts`, `messages/en.ts`, `e2e/client-reminders.spec.ts`
97
+
98
+ 1. `src/app/clients/[id]/actions.ts`: `setRemindersEnabled` server action; checks the user
99
+ owns the client, not just that a session exists.
100
+ 2. `src/app/clients/[id]/settings-form.tsx`: a labelled toggle bound to the action, with the
101
+ pending state of the existing form controls.
102
+
103
+ **Tests:** e2e: switching off reminders for a client, then running the job, sends nothing for
104
+ that client's overdue invoice; a user without access to the client gets 403 from the action.
105
+
106
+ **Done when:**
107
+ - Automated: the e2e spec passes; the action rejects a foreign client id; Gates green
108
+ (typecheck, lint, test).
109
+ - Manual: the toggle reads clearly in the settings screen at phone width.
110
+
111
+ ## Risks and rollback
112
+ - Mail provider outage → claims are released, reminders go out on the next run; nothing lost.
113
+ - A bug in the eligibility rule mass-sends → the job is gated by its registry entry: removing
114
+ it (one-line revert of phase 2) stops sending immediately; `reminder_sent_at` shows who got
115
+ one.
116
+ - Revert per phase: phase 3 and 2 by reverting their commits; phase 1 by a down migration that
117
+ drops the two columns.
118
+
119
+ ## Progress
120
+
121
+ > `- [ ]` pending, `- [x]` done. A phase ends with ` — <commit sha>` on its done items. Never rename items.
122
+
123
+ ### Phase 1: Reminder state and eligibility rule
124
+
125
+ #### Automated
126
+ - [ ] 1.1 Eight eligibility cases pass in `src/invoices/reminders.test.ts`
127
+ - [ ] 1.2 Migration 0042 applies on a dev copy; both columns exist with their defaults
128
+ - [ ] 1.3 Gates green (typecheck, lint, test)
129
+
130
+ ### Phase 2: Sending job, safe to run twice
131
+
132
+ #### Automated
133
+ - [ ] 2.1 Concurrent runs send one email; failed send releases the claim; empty selection sends nothing
134
+ - [ ] 2.2 Dev run: reminded count equals the eligible count before the run; second run sends 0
135
+ - [ ] 2.3 Gates green (typecheck, lint, test)
136
+
137
+ #### Manual
138
+ - [ ] 2.4 Reminder email reads correctly in a real inbox, amount and link included
139
+
140
+ ### Phase 3: Per-client switch
141
+
142
+ #### Automated
143
+ - [ ] 3.1 E2E: switched-off client gets no reminder after a job run
144
+ - [ ] 3.2 `setRemindersEnabled` rejects a client the user does not own
145
+ - [ ] 3.3 Gates green (typecheck, lint, test)
146
+
147
+ #### Manual
148
+ - [ ] 3.4 Toggle reads clearly in client settings at phone width
149
+ ```
150
+
151
+ What makes it good:
152
+
153
+ - The goal is measurable and names the hard case ("exactly one", even under overlap).
154
+ - Every key decision has a source; the owner's two answers are visible without the transcript.
155
+ - Each phase is a working slice: after phase 1 nothing is sent yet, but the rule is proven and
156
+ the data is ready; after phase 2 reminders work for everyone; phase 3 adds the opt-out.
157
+ - The one piece of SQL in the plan is there because its exact shape is the whole safety
158
+ argument. Everything else is intent and contract.
159
+ - Criteria read real rows, not the UI.
160
+
161
+ ## Bad: the same change, planned badly
162
+
163
+ ```markdown
164
+ # Plan: overdue-invoice-reminders
165
+
166
+ ## Goal
167
+ Add invoice reminders.
168
+
169
+ ## Approach
170
+ We will add reminders using a job. Email provider: TBD (maybe the mail module or SMTP).
171
+
172
+ ## Phase 1: Database
173
+ - [ ] Add the needed columns.
174
+
175
+ ## Phase 2: Backend
176
+ - [ ] Implement the reminder logic and handle errors properly.
177
+ ```ts
178
+ export async function sendReminders() {
179
+ const invoices = await db.select().from(invoicesTable);
180
+ for (const invoice of invoices) { ... 60 more lines ... }
181
+ }
182
+ ```
183
+
184
+ ## Phase 3: Frontend
185
+ - [ ] Add a toggle. Make sure it looks good.
186
+
187
+ ## Progress
188
+ - [ ] Phase 1
189
+ - [ ] Phase 2
190
+ - [ ] Phase 3
191
+ ```
192
+
193
+ Why it is bad:
194
+
195
+ - **Goal is an activity**, not an outcome. Nobody can tell when it is done, and "exactly once"
196
+ is never stated, so the double-send race is never planned for.
197
+ - **An open question** ("TBD", "maybe") moves a design decision into implementation, and ignores
198
+ the module research found.
199
+ - **Horizontal phases**: after phase 1 and phase 2 nothing a user can see works, and the
200
+ pieces meet for the first time in phase 3.
201
+ - **Unverifiable criteria**: "needed columns", "handle errors properly", "looks good".
202
+ - **Code dump** for a routine loop, while the one thing that needed precision (the claim
203
+ query) is missing.
204
+ - **No files, no discipline, no tests, no data safety, no rollback.**
205
+ - **Checkboxes in phase blocks** and a Progress section that does not follow the format, so
206
+ softure-implement cannot find a resume point.
@@ -47,7 +47,39 @@ to report progress. It must stay machine-friendly.
47
47
  not block the next phase. They are listed for the owner at the end.
48
48
  9. Never delete or rename an item after implementation starts. When the plan changes
49
49
  mid-flight, add new items with the next free number and mark obsolete ones
50
- `- [x] ~~1.4 old text~~ — dropped: <reason>`.
50
+ `- [x] ~~1.4 old text~~ — dropped: <reason>`. Numbers are never reused, so gaps are fine.
51
+ Before implementation starts (plan and plan review), items may still be renumbered.
52
+ 10. Within a phase, boxes may be ticked as each criterion is checked; the SHA is appended to all
53
+ of them at once after the phase commit. A ticked item without a SHA in the phase being
54
+ worked on is a valid intermediate state, not drift.
55
+ 11. Checkboxes appear **only** here. The `## Phase N:` blocks above list their Done-when
56
+ criteria as plain `- ` bullets, and every one of them has exactly one item here.
57
+
58
+ ## What does not belong in Progress
59
+
60
+ - Nested checkboxes. One criterion is one line; sub-steps belong in the phase block.
61
+ - Estimates, owners, due dates.
62
+ - Prose between phases or groups. The section is headings and items only, because tools parse it.
63
+ - Status markers or completion banners. The status lives in change.md frontmatter; completion
64
+ is derived from the boxes.
65
+
66
+ ## Deriving state (for skills and scripts that read Progress)
67
+
68
+ - **Resume point:** the first `- [ ]` under an `#### Automated` heading.
69
+ - **Current phase:** the phase that holds the resume point, or the last phase when there is none.
70
+ - **Completion:** ticked items divided by all items, dropped items counted as ticked.
71
+ - **Open owner checks:** every `- [ ]` under `#### Manual`. They go to the roadmap's
72
+ `## Owner decisions and checks` at archive time.
73
+
74
+ Drift between change.md and Progress, worth reporting wherever it is noticed:
75
+
76
+ | change.md status | Progress shows | Likely meaning |
77
+ | --- | --- | --- |
78
+ | `planned` or `plan_reviewed` | a ticked item without a SHA | work started without moving the status (ticked items with SHAs are normal after a re-plan) |
79
+ | `implementing` | nothing ticked | the status moved, no work was recorded |
80
+ | `implementing` | every Automated item ticked | the status should be `implemented` |
81
+ | `implemented` | an open Automated item | a phase was skipped or a box was never ticked |
82
+ | any | a ticked item without a SHA in a phase that is not the current one | a phase was committed without its bookkeeping |
51
83
 
52
84
  ## Example (one phase done, one in flight)
53
85
 
@@ -76,4 +108,26 @@ to report progress. It must stay machine-friendly.
76
108
  - [ ] 2.4 Owner confirms the pending state feels responsive on a slow network
77
109
  ```
78
110
 
79
- Resume point here: item 2.2.
111
+ Resume point here: item 2.2. Item 2.1 is ticked without a SHA because phase 2 is not committed
112
+ yet. Item 2.4 stays open for the owner and does not block phase 3.
113
+
114
+ ## Example: a re-plan in the middle of phase 2
115
+
116
+ Research for the remaining work showed that the E2E check belongs to a later phase, and a new
117
+ criterion appeared. Nothing is renamed or renumbered:
118
+
119
+ ```markdown
120
+ ### Phase 2: Every long action uses it
121
+
122
+ #### Automated
123
+ - [x] 2.1 All server-action forms pass `isPending` from `useFormStatus`
124
+ - [x] ~~2.2 E2E: clicking "Recalculate" shows the pending state within 100 ms~~ — dropped: moved to phase 3
125
+ - [ ] 2.5 Disabled buttons expose `aria-disabled` while pending
126
+ - [ ] 2.3 Gates green (typecheck, lint, test)
127
+
128
+ #### Manual
129
+ - [ ] 2.4 Owner confirms the pending state feels responsive on a slow network
130
+ ```
131
+
132
+ The gates item keeps its number and stays last. The new item takes the next free number (2.5,
133
+ because 2.4 is the manual item).