Skip to content

Commit 68635a0

Browse files
thomas-manginclaude
andcommitted
chore(ai): replace learned numbering pipeline with counter file
The old method scanned 719+ files via glob+grep+sort+head every time a learned summary was created. Replace with plan/learned/.counter holding the next available number. Commit scripts read it, use it, bump it. Added make ze-learned-counter for recovery, collision guard in commit scripts, and updated all skill/rule references. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1eddce9 commit 68635a0

8 files changed

Lines changed: 53 additions & 26 deletions

File tree

‎.claude/rules/planning.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,19 @@ The lifecycle is: `in-progress` -> Review Gate clean -> write learned summary ->
3838
All three happen in `/ze-implement` step 15, in one commit script the user runs once.
3939
Leaving a completed spec in `plan/` causes every future session to count it as open work.
4040

41+
**The commit script IS the final deliverable.** The user runs it and considers the work
42+
finished. They will not come back to ask for a "close the spec" step. Therefore:
43+
- Learned summary, LEARNED-INDEX update, and `git rm plan/<spec>` MUST be in the same
44+
script that commits the implementation code.
45+
- Never present the implementation commit first and closure "as a next step."
46+
- Never split into two scripts or two commits.
47+
- If the script is missing any of these, the step is incomplete. Go back and include them.
48+
4149
| Banned | Why |
4250
|--------|-----|
4351
| "I'll close it later" | Later never comes. Other sessions see it as in-progress. |
4452
| "The user will handle it" | The user asked us to implement. Closure is part of implementation. |
4553
| "It's just a status change" | A spec in `plan/` with status `done` is worse than `in-progress` -- it is invisible to `/ze-status` staleness checks but still occupies the spec list. |
54+
| "Run the commit, then I'll prepare closure" | The user will not ask. One script, one run, done. |
4655

4756
`/ze-status` flags in-progress specs with clean Review Gates as "completed but not closed."

‎Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,12 @@ ze-spec-status:
675675
ze-spec-status-json:
676676
@go run scripts/status/spec_status.go --json
677677

678+
# Rebuild plan/learned/.counter from directory contents (recovery)
679+
ze-learned-counter:
680+
@n=$$(ls plan/learned/[0-9]*.md 2>/dev/null | sed 's/.*\///' | grep -oE '^[0-9]+' | sort -rn | head -1); \
681+
echo $$(( $${n:-0} + 1 )) > plan/learned/.counter; \
682+
echo "plan/learned/.counter set to $$(cat plan/learned/.counter)"
683+
678684
# ─── Inventory ──────────────────────────────────────────────────────────
679685

680686
# Generate project inventory (plugins, YANG, RPCs, tests, packages)

‎ai/rules/git-safety.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ cross-commit. Package add + commit into a single user-triggered script.
1616
4. `chmod +x` every script you hand the user (commit, delete, helper) at creation. User runs it directly (`./tmp/...`), not via `bash`.
1717
5. Never end an output line with `.`, `,`, `:`, or `)` directly after a path/URL/command -- users copy-paste; trailing punctuation breaks it. Put path on its own line or follow with a space.
1818
6. Report what was done and what is left. User decides when to commit.
19+
7. Before writing a commit script, read `.gitignore` and never `git add` ignored paths. Key ignored paths: `CLAUDE.md`, `AGENTS.md`, `.claude/skills/`, `.codex/skills/`, `.agents/skills/`, `tmp/`, `/bin/`. Only add canonical sources (e.g., `ai/skills/`, `ai/INSTRUCTIONS.md`).
1920

2021
`git commit`/`git add` inside the script is fine -- the ban is on
2122
direct AI tool invocations, not on what the script does when the user
@@ -35,6 +36,7 @@ git commit -F tmp/commit-msg-<SESSION>-a.txt
3536
# Commit B (optional; e.g., spec-preservation)
3637
git rm plan/spec-<name>.md
3738
git add plan/learned/NNN-<name>.md
39+
git add plan/learned/.counter # bumped to NNN+1
3840
git commit -F tmp/commit-msg-<SESSION>-b.txt
3941
```
4042

@@ -115,7 +117,8 @@ loops. Wait for completion.
115117

116118
```
117119
[ ] 3. Spec completion gate (if driven by a plan/ spec):
118-
[ ] Learned summary written to plan/learned/NNN-<name>.md
120+
[ ] Learned summary written to plan/learned/NNN-<name>.md (NNN from .counter)
121+
[ ] plan/learned/.counter bumped to NNN+1
119122
[ ] Spec file staged for deletion (git rm)
120123
Not done -> STOP.
121124
[ ] 4. Executive Summary Report (rules/planning.md). What was done, what is left.

‎ai/rules/planning.md‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,19 @@ If a spec describes work that is **already implemented**, run the full Completio
167167
[ ] 6. Critical Review (BLOCKING — rules/quality.md)
168168
[ ] 7. Review Mistake Log — check MEMORY.md, promote if seen before
169169
[ ] 7. Update spec — Implementation Summary, Documentation Updates, Deviations
170-
[ ] 7. Write learned summary: plan/learned/NNN-<name>.md (see plan/TEMPLATE.md for summary format)
170+
[ ] 7. Write learned summary: plan/learned/NNN-<name>.md (NNN from plan/learned/.counter; bump after)
171171
[ ] 7. Verify: `make ze-verify` + git status + git diff, no unintended changes
172172
[ ] 7. Executive Summary Report — present to user with what was done and what is left (including deferred).
173173
BLOCKING: learned summary (step 10) must exist. Name the file in the report.
174174
Do NOT ask to commit. The user will tell you when to commit.
175-
[ ] 7. Commit (when user says so) — TWO commits, in order:
176-
**Commit A:** code + tests + docs + completed spec (with filled audit/verification tables).
177-
This preserves the completed spec in git history for future review.
178-
**Commit B:** delete spec (`git rm plan/spec-<name>.md`) + add learned summary (`plan/learned/NNN-<name>.md`).
179-
The learned summary replaces the spec as the durable artifact.
180-
Disjoint systems (e.g., CLI and BGP encoding) get separate commit pairs.
175+
[ ] 7. Commit (when user says so) — ONE script, ONE commit, everything included:
176+
- `git add` all implementation files (code, tests, docs, schema)
177+
- `git add plan/learned/NNN-<name>.md` (learned summary)
178+
- `git rm plan/spec-<name>.md` (spec closure)
179+
- Bump `plan/learned/.counter` and `git add plan/learned/.counter`
180+
The user runs the script and the work is done. They will not come back for a
181+
second step. If spec closure or learned summary is missing, it never happens.
182+
Disjoint systems (e.g., CLI and BGP encoding) get separate commits.
181183
```
182184

183185
## Deferred Work (BLOCKING)
@@ -232,14 +234,9 @@ Every row must be answered Yes/No. Every Yes must name the file and what to add.
232234

233235
## Writing Learned Summaries
234236

235-
When a spec is complete, write a concise summary to `plan/learned/` using the next available number:
236-
237-
```bash
238-
LAST=$(for f in plan/learned/[0-9]*-*.md; do basename "$f" | cut -d- -f1; done 2>/dev/null | sort -n | tail -1)
239-
test -z "$LAST" && LAST=0
240-
NEXT=$(printf "%03d" $((LAST + 1)))
241-
# Write summary to plan/learned/${NEXT}-<name>.md (see TEMPLATE.md for format)
242-
```
237+
When a spec is complete, write a concise summary to `plan/learned/` using the next available number.
238+
`plan/learned/.counter` contains the next number. Read it, use it, bump it in the commit script.
239+
Recovery: `make ze-learned-counter`.
243240

244241
The summary (~25-35 lines) uses this fixed 5-section format:
245242

‎ai/skills/ze-implement.md‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,30 @@ See also: `/ze-audit` (check what exists first), `/ze-review-spec` (post-impl ve
7979
- If the spec has no Documentation Update Checklist, use `ai/rules/planning.md` "Documentation Update Checklist" as the reference and fill it for the spec.
8080
- Write the doc updates. Include them in the commit.
8181
15. **Close spec and present commit (BLOCKING -- do ALL of this BEFORE presenting the commit script):**
82-
The user expects that running the commit script completes ALL work. Nothing may be left
83-
over, deferred, or require a second script. Do everything below before showing the script.
82+
The user runs the commit script and considers the work FINISHED. They will not come back
83+
to ask "what's next" or "close the spec now." There is no step 16. The script is the
84+
final deliverable. Everything below MUST be in that single script.
85+
8486
a. Write the learned summary to `plan/learned/NNN-<spec-stem>.md` following `plan/learned/METHODOLOGY.md`.
85-
Number NNN = next unused number. To find it: `for f in plan/learned/[0-9]*.md; do basename "$f"; done | grep -oE '^[0-9]+' | sort -rn | head -1`
86-
then add 1. Use the extraction recipe: Context from Task + Current Behavior, Decisions from Key Design Decisions + annotations, Consequences from Design Insights + Limitations, Gotchas from Deviations + Mistake Log.
87+
Number NNN: read `plan/learned/.counter` (contains the next available number).
88+
Use the extraction recipe: Context from Task + Current Behavior, Decisions from Key Design Decisions + annotations, Consequences from Design Insights + Limitations, Gotchas from Deviations + Mistake Log.
8789
b. Update `ai/LEARNED-INDEX.md` if the summary contains a structural decision (not just task completion).
8890
c. Remove your line from `tmp/session/selected-spec`.
8991
d. List all changes made (files modified/created, tests added, docs updated, issues found and fixed).
9092
e. Prepare ONE commit script (`tmp/commit-SESSION.sh`) that does EVERYTHING in a single commit:
93+
- Guard: `if ls plan/learned/NNN-*.md 1>/dev/null 2>&1; then echo "ERROR: NNN already taken, re-read .counter"; exit 1; fi`
9194
- `git add` all implementation files (code, tests, docs, schema)
9295
- `git add plan/learned/NNN-<spec-stem>.md`
9396
- `git add ai/LEARNED-INDEX.md` (if updated)
9497
- `git rm plan/<spec-name>`
95-
- Commit message file with both the feature description and the spec closure
96-
f. Present the commit script to the user.
98+
- Bump `plan/learned/.counter` to NNN+1 and `git add plan/learned/.counter`
99+
- Commit message file with both the feature description AND the spec closure
100+
f. Present the commit script to the user. This is the end.
97101

98-
**Why one script, one commit:** the user runs the script and the work is done. No second
99-
script, no "now run this other thing", no leftover steps. If there are ANY remaining
100-
actions after the user runs the script, the step is not complete. Go back and include them.
102+
**Why one script, one commit, no follow-up:** the user will not ask for a second step.
103+
They will not remember that the spec needs closing. They will not prompt you for the
104+
learned summary. If closure is not in the script, it will never happen and the spec
105+
rots in `plan/` forever. Include everything. There is nothing after this step.
101106

102107
## Rules
103108

‎ai/skills/ze-progress.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ A spec is **done** only when stage 5 is complete. Stages 1 through 4 are checkpo
4343
- Are there uncommitted files in the spec scope (code, tests, docs, or the spec file itself)?
4444
- If uncommitted spec-scoped files remain: STAGE = 4. Go to step 9.
4545
8. **Stage 5 -- Commit B (closure):** Check:
46-
- Does `plan/learned/NNN-<spec-stem>.md` exist? Compute the next `NNN` from `ls plan/learned/ | sort | tail -1` if it does not.
46+
- Does `plan/learned/NNN-<spec-stem>.md` exist? If not, read `plan/learned/.counter` for the next NNN.
4747
- Is `plan/spec-<name>.md` still tracked by git (`git ls-files plan/spec-<name>.md`)?
4848
- If the learned summary is missing OR the spec file is still tracked: STAGE = 5. Go to step 9.
4949
- Otherwise: STAGE = done.

‎plan/learned/.counter‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
720

‎plan/learned/METHODOLOGY.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,10 @@ At spec completion, the Executive Summary (already BLOCKING before commit) maps
102102

103103
One additional step: scan Design Insights + Known Limitations for **Consequences** bullets not already covered by the Executive Summary mapping. This takes 30 seconds when context is fresh.
104104

105+
## Numbering
106+
107+
`plan/learned/.counter` contains the next available number. Read it, use it as NNN, then bump it (write NNN+1) and `git add plan/learned/.counter` in the commit script.
108+
109+
If `.counter` is missing or wrong, run `make ze-learned-counter` to rebuild it from the directory.
110+
105111
Write the summary to `plan/learned/NNN-<name>.md` instead of moving the full spec to `done/`.

0 commit comments

Comments
 (0)