feat(prune-memory): v2 registries — § D dropped, status and merges through memory.sh, STEP 4 verify = memory.sh check
This commit is contained in:
1 parent
f15c360b95
commit
c318ee6297
5 files changed
+49
-79
No files matched your search
@@ -80,9 +80,10 @@ age comparisons. Today's date is in the system context.
|
|||||||
### A. Obsolete — mark-superseded candidates
|
### A. Obsolete — mark-superseded candidates
|
||||||
- Decisions `status: proposed` older than 90 days → propose
|
- Decisions `status: proposed` older than 90 days → propose
|
||||||
`status: deprecated` (no follow-up).
|
`status: deprecated` (no follow-up).
|
||||||
- Decisions whose body contains "superseded by <ID>" but Index row still
|
- Decisions whose body names a successor ("superseded by <ID>",
|
||||||
says `accepted` → propose Index row fix to
|
"Supersedes [[<ID>]]" on the newer one) but whose current status
|
||||||
`superseded by <that-ID>`.
|
(`bash "$HOME/.claude/lib/memory.sh" index decision`) still reads
|
||||||
|
`accepted` → propose `memory.sh status <ID> "superseded by <that-ID>"`.
|
||||||
- Blockers `status: open` whose root cause matches a commit in last 30
|
- Blockers `status: open` whose root cause matches a commit in last 30
|
||||||
days (grep `git log --since=30.days --grep=<keyword>`) → propose
|
days (grep `git log --since=30.days --grep=<keyword>`) → propose
|
||||||
`status: resolved` with commit ref.
|
`status: resolved` with commit ref.
|
||||||
@@ -108,12 +109,6 @@ age comparisons. Today's date is in the system context.
|
|||||||
- Detect filler density: count `\b(the|a|an|just|really|basically|actually|simply)\b`
|
- Detect filler density: count `\b(the|a|an|just|really|basically|actually|simply)\b`
|
||||||
matches; if > 5% of word count → bloated.
|
matches; if > 5% of word count → bloated.
|
||||||
|
|
||||||
### D. Index drift
|
|
||||||
- Body `## (BDR|LRN|BLK|EVAL)-NNN` heading exists but no matching row
|
|
||||||
in `## Index` table → propose Index backfill.
|
|
||||||
- Index row exists but body entry missing → propose `status: deleted
|
|
||||||
(orphaned)` tombstone or removal of Index row (user decides).
|
|
||||||
|
|
||||||
## STEP 2 — PRESENT PLAN ★ MANDATORY STOP
|
## STEP 2 — PRESENT PLAN ★ MANDATORY STOP
|
||||||
|
|
||||||
Print one block per registry. Example:
|
Print one block per registry. Example:
|
||||||
@@ -127,7 +122,7 @@ PRUNE PLAN — decisions.md (N entries → M after if approved)
|
|||||||
BDR-901 — example proposed decision — status: proposed since <90+ days ago>
|
BDR-901 — example proposed decision — status: proposed since <90+ days ago>
|
||||||
→ mark: status: deprecated (no follow-up after 90 days)
|
→ mark: status: deprecated (no follow-up after 90 days)
|
||||||
BDR-902 — example decision — body says superseded by BDR-903
|
BDR-902 — example decision — body says superseded by BDR-903
|
||||||
→ fix Index: status = "superseded by BDR-903"
|
→ memory.sh status BDR-902 "superseded by BDR-903"
|
||||||
|
|
||||||
[B. Similar — merge]
|
[B. Similar — merge]
|
||||||
LRN-901 + LRN-902 — SAME concept (two notes on the identical bug)
|
LRN-901 + LRN-902 — SAME concept (two notes on the identical bug)
|
||||||
@@ -138,10 +133,7 @@ PRUNE PLAN — decisions.md (N entries → M after if approved)
|
|||||||
[C. Bloated — inline caveman rewrite]
|
[C. Bloated — inline caveman rewrite]
|
||||||
BDR-902 — body 612 words, filler density 7.2% → ~380 expected (-38%)
|
BDR-902 — body 612 words, filler density 7.2% → ~380 expected (-38%)
|
||||||
|
|
||||||
[D. Index drift]
|
Approve per category? (all / a / b / c / edit <ID> / skip)
|
||||||
(none)
|
|
||||||
|
|
||||||
Approve per category? (all / a / b / c / d / edit <ID> / skip)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Wait for user input. Default = nothing applied.
|
Wait for user input. Default = nothing applied.
|
||||||
@@ -149,18 +141,22 @@ Wait for user input. Default = nothing applied.
|
|||||||
## STEP 3 — APPLY APPROVED CHANGES
|
## STEP 3 — APPLY APPROVED CHANGES
|
||||||
|
|
||||||
Order: safe → destructive.
|
Order: safe → destructive.
|
||||||
|
Registry writes follow `lib/capitalize-commit.md` § WRITE (single writer).
|
||||||
|
|
||||||
1. **Index drift fixes** — no body changes. Backfill missing rows, mark
|
1. **Status flag updates** — `bash "$HOME/.claude/lib/memory.sh" status <ID>
|
||||||
orphans.
|
"<word> …"` appends a dated status line (text starts with a status word:
|
||||||
2. **Status flag updates** — Index row status field only. Body untouched.
|
`deprecated, no follow-up after 90 days`); the body above stays verbatim.
|
||||||
3. **Merges** — write new merged entry (next-free ID); source IDs marked
|
2. **Merges** — write the merged body to a scratch file, then
|
||||||
`status: superseded by <new-ID>` in Index (body kept verbatim for
|
`bash "$HOME/.claude/lib/memory.sh" add <kind> --title "<title>"
|
||||||
history). Merged body:
|
--body-file <file> --supersedes <first source>` (next-free ID, forward
|
||||||
|
link, the first source marked superseded); each other source:
|
||||||
|
`memory.sh status <ID> "superseded by <new-ID>"`. Source bodies stay
|
||||||
|
verbatim for history. Merged body:
|
||||||
- Preserves all `**Reference**:` lines (dedupe identical paths).
|
- Preserves all `**Reference**:` lines (dedupe identical paths).
|
||||||
- Caveman pass on prose during merge.
|
- Caveman pass on prose during merge.
|
||||||
- Keeps frontmatter fields: id (new), date (today), title, status
|
- Keeps frontmatter fields: id (new), date (today), title, status
|
||||||
(accepted), references (union).
|
(accepted), references (union).
|
||||||
4. **Inline caveman compression** — preserve frontmatter exactly (id,
|
3. **Inline caveman compression** — preserve frontmatter exactly (id,
|
||||||
date, title, status, references). Rewrite prose body to fragments:
|
date, title, status, references). Rewrite prose body to fragments:
|
||||||
- **NEGATION GUARD (deterministic, overrides every rule below):** never
|
- **NEGATION GUARD (deterministic, overrides every rule below):** never
|
||||||
rewrite a sentence containing a negation token (`not`, `never`, `no`,
|
rewrite a sentence containing a negation token (`not`, `never`, `no`,
|
||||||
@@ -174,39 +170,13 @@ Order: safe → destructive.
|
|||||||
- Keep code blocks, URLs, error messages, file paths VERBATIM.
|
- Keep code blocks, URLs, error messages, file paths VERBATIM.
|
||||||
- Keep IDs (BDR-XXX, LRN-XXX, commit hashes) verbatim.
|
- Keep IDs (BDR-XXX, LRN-XXX, commit hashes) verbatim.
|
||||||
|
|
||||||
After each write, regenerate Index from body when rows changed.
|
|
||||||
|
|
||||||
## STEP 4 — VERIFY
|
## STEP 4 — VERIFY
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Filename → ID-prefix map. Hard-mapped because filenames don't share
|
# Structure: heading shape + unique IDs + no open fence (v2 registries; a
|
||||||
# their first 3 chars with the prefix (decisions → BDR, not DEC).
|
# v1 one is named and skipped). Same verify the writer runs after every add.
|
||||||
# A prior version derived the prefix via `basename | cut -c1-3`, which never
|
bash "$HOME/.claude/lib/memory.sh" check .claude/memory \
|
||||||
# matched any heading and made verify a no-op (false-clean signal).
|
|| echo "CHECK FAILED: fix the lines above before certifying"
|
||||||
declare -A PREFIX_MAP=(
|
|
||||||
[decisions]=BDR
|
|
||||||
[learnings]=LRN
|
|
||||||
[blockers]=BLK
|
|
||||||
[evals]=EVAL
|
|
||||||
)
|
|
||||||
|
|
||||||
# All body entries have Index rows; no orphans
|
|
||||||
for fname in decisions learnings blockers evals; do
|
|
||||||
f=".claude/memory/${fname}.md"
|
|
||||||
[ -f "$f" ] || continue
|
|
||||||
prefix="${PREFIX_MAP[$fname]}"
|
|
||||||
|
|
||||||
/usr/bin/grep -oE "^## (${prefix})-[0-9]+" "$f" | while read marker; do
|
|
||||||
id="${marker##\#\# }"
|
|
||||||
/usr/bin/grep -q "^| ${id} " "$f" || echo "MISSING INDEX: $id in $f"
|
|
||||||
done
|
|
||||||
/usr/bin/grep -oE "^\| (${prefix})-[0-9]+ " "$f" | while read row; do
|
|
||||||
id=$(echo "$row" | awk '{print $2}')
|
|
||||||
# RED-6 fix: match id at a word boundary (space OR end-of-line) so a
|
|
||||||
# title-less heading "## BDR-009" is not flagged as a false orphan.
|
|
||||||
/usr/bin/grep -qE "^## ${id}( |\$)" "$f" || echo "ORPHAN INDEX: $id in $f"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
# RED-5 fidelity guard (count-based, per-entry x per-category). STEP 0 ensured
|
# RED-5 fidelity guard (count-based, per-entry x per-category). STEP 0 ensured
|
||||||
# a clean tree, so git HEAD is the pre-prune backup. Fails the run if any
|
# a clean tree, so git HEAD is the pre-prune backup. Fails the run if any
|
||||||
@@ -271,7 +241,7 @@ PRUNE COMPLETE
|
|||||||
journal.md : 88 → 62 lines (-30%)
|
journal.md : 88 → 62 lines (-30%)
|
||||||
evals.md : no candidates
|
evals.md : no candidates
|
||||||
|
|
||||||
INDEX SANITY: OK
|
CHECK: OK
|
||||||
NEXT: review `git diff .claude/memory/`, then `/commit-change`
|
NEXT: review `git diff .claude/memory/`, then `/commit-change`
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -302,7 +272,7 @@ NEXT: review `git diff .claude/memory/`, then `/commit-change`
|
|||||||
| Working tree dirty on registry files | STOP per PRECHECK; tell user to commit/stash first |
|
| Working tree dirty on registry files | STOP per PRECHECK; tell user to commit/stash first |
|
||||||
| User says `skip` at STEP 2 | Exit cleanly, no writes |
|
| User says `skip` at STEP 2 | Exit cleanly, no writes |
|
||||||
| Merge produces an entry > 600 words | Re-split — merge was too greedy. Re-prompt user to keep separate. |
|
| Merge produces an entry > 600 words | Re-split — merge was too greedy. Re-prompt user to keep separate. |
|
||||||
| Index sanity FAILED at STEP 4 | Print exact missing/orphan IDs. Do NOT auto-fix — user re-runs or hand-edits. |
|
| `memory.sh check` FAILED at STEP 4 | Print its culprit lines. Do NOT auto-fix — user re-runs or hand-edits. |
|
||||||
| Caveman compression result < 20% of original AND original had code blocks | Revert that entry's compression — flag as needing manual rewrite (likely stripped technical detail). |
|
| Caveman compression result < 20% of original AND original had code blocks | Revert that entry's compression — flag as needing manual rewrite (likely stripped technical detail). |
|
||||||
| Same file already compressed in same session | Skip C-category for that file; warn user that double-pass risks technical drift. |
|
| Same file already compressed in same session | Skip C-category for that file; warn user that double-pass risks technical drift. |
|
||||||
|
|
||||||
@@ -320,7 +290,7 @@ NEXT: review `git diff .claude/memory/`, then `/commit-change`
|
|||||||
|
|
||||||
Baseline RED scenarios were run and their counters are embedded: the
|
Baseline RED scenarios were run and their counters are embedded: the
|
||||||
RED-2/RED-5/RED-6 guards live in the body above, and `tests/` holds the
|
RED-2/RED-5/RED-6 guards live in the body above, and `tests/` holds the
|
||||||
fixtures (red3-negation, red4-journal, red6-orphan) plus
|
fixtures (red3-negation, red4-journal, red6-check) plus
|
||||||
`run-deterministic.sh` and `run-behavioral.md`. New rationalizations a
|
`run-deterministic.sh` and `run-behavioral.md`. New rationalizations a
|
||||||
subagent finds → add the fixture and its counter to the "Common
|
subagent finds → add the fixture and its counter to the "Common
|
||||||
mistakes" / "Failure paths" tables (`tests/BACKLOG.md` tracks candidates).
|
mistakes" / "Failure paths" tables (`tests/BACKLOG.md` tracks candidates).
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[
|
[
|
||||||
{"id": 1, "prompt": "prune memory — registres trop longs", "expected": "Skill runs PRECHECK (refuses if working tree dirty on .claude/memory/), audits all 5 registries for A) obsolete/superseded entries B) similar merge candidates C) bloated prose D) Index drift, presents the per-registry PRUNE PLAN with category-level approval gate, applies only approved changes (mark-superseded never hard-delete), then runs Index sanity verify at STEP 4."},
|
{"id": 1, "prompt": "prune memory — registres trop longs", "expected": "Skill runs PRECHECK (refuses if working tree dirty on .claude/memory/), audits all 5 registries for A) obsolete/superseded entries B) similar merge candidates C) bloated prose, presents the per-registry PRUNE PLAN with category-level approval gate, applies only approved changes (status lines and merges through lib/memory.sh, never hard-delete), then runs memory.sh check and the fidelity census at STEP 4."},
|
||||||
{"id": 2, "prompt": "/prune-memory decisions", "expected": "Skill filters audit to decisions.md only — leaves learnings/blockers/journal/evals untouched, presents plan for that single registry, and exits cleanly after applying approved changes with the same append-only + caveman rules."},
|
{"id": 2, "prompt": "/prune-memory decisions", "expected": "Skill filters audit to decisions.md only — leaves learnings/blockers/journal/evals untouched, presents plan for that single registry, and exits cleanly after applying approved changes with the same append-only + caveman rules."},
|
||||||
{"id": 3, "prompt": "compresse les memoires — mais j'ai des changements pas commités dans .claude/memory/", "expected": "STEP 0 PRECHECK detects dirty working tree on registry files and STOPS immediately: 'Commit or stash pending changes in .claude/memory/ first. Skill writes in-place. Git is the only backup.' — no writes, no plan."}
|
{"id": 3, "prompt": "compresse les memoires — mais j'ai des changements pas commités dans .claude/memory/", "expected": "STEP 0 PRECHECK detects dirty working tree on registry files and STOPS immediately: 'Commit or stash pending changes in .claude/memory/ first. Skill writes in-place. Git is the only backup.' — no writes, no plan."}
|
||||||
]
|
]
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
format: 2
|
||||||
|
type: decisions_registry
|
||||||
|
entry_prefix: BDR
|
||||||
|
---
|
||||||
|
|
||||||
|
# Decisions registry (BDR)
|
||||||
|
|
||||||
|
## BDR-009 — first (2026-06-01)
|
||||||
|
- **Status**: accepted
|
||||||
|
|
||||||
|
## BDR-009 — duplicate, the trap (2026-06-02)
|
||||||
|
- **Status**: accepted
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
# Decisions
|
|
||||||
|
|
||||||
## Index
|
|
||||||
|
|
||||||
| ID | status | date | title |
|
|
||||||
|----|--------|------|-------|
|
|
||||||
| BDR-009 | accepted | 2026-06-01 | titleless |
|
|
||||||
| BDR-010 | accepted | 2026-06-02 | has title |
|
|
||||||
|
|
||||||
## BDR-009
|
|
||||||
Body exists. Heading above has NO trailing space and NO title -- this is
|
|
||||||
the trap. STEP 4 loop-2 checks `^## BDR-009 ` (trailing space required)
|
|
||||||
and so reports a FALSE ORPHAN even though this body is right here.
|
|
||||||
|
|
||||||
## BDR-010 — Has title
|
|
||||||
Body exists. Control entry: heading has a title, so STEP 4 finds it and
|
|
||||||
does NOT false-orphan it. Proves the bug is specific to title-less headings.
|
|
||||||
@@ -71,16 +71,20 @@ else
|
|||||||
red 5 "STEP 4 certifies OK after a safety-critical line was deleted (no fidelity check)"
|
red 5 "STEP 4 certifies OK after a safety-critical line was deleted (no fidelity check)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---- RED-6: STEP 4 verify must not false-orphan a title-less heading --------
|
# ---- RED-6: STEP 4 verify runs memory.sh check (duplicate ID caught) --------
|
||||||
S6="$SANDBOX/red6"; mkdir -p "$S6/.claude/memory"
|
# v2 registries carry no Index; the structural verify is `memory.sh check`
|
||||||
cp "$HERE/fixtures/red6-orphan/.claude/memory/decisions.md" \
|
# (heading shape, unique IDs). HOME is pinned to a sandbox whose .claude/lib
|
||||||
|
# is this repo's lib, so the run never depends on the machine's ~/.claude.
|
||||||
|
S6="$SANDBOX/red6"; mkdir -p "$S6/.claude/memory" "$S6/home/.claude"
|
||||||
|
ln -s "$HERE/../../../lib" "$S6/home/.claude/lib"
|
||||||
|
cp "$HERE/fixtures/red6-check/.claude/memory/decisions.md" \
|
||||||
"$S6/.claude/memory/decisions.md"
|
"$S6/.claude/memory/decisions.md"
|
||||||
extract_block "STEP 4" > "$S6/step4.sh"
|
extract_block "STEP 4" > "$S6/step4.sh"
|
||||||
out="$( cd "$S6" && bash step4.sh 2>/dev/null )"
|
out="$( cd "$S6" && HOME="$S6/home" bash step4.sh 2>&1 )"
|
||||||
if printf '%s\n' "$out" | grep -qE '^ORPHAN INDEX: BDR-009'; then
|
if printf '%s\n' "$out" | grep -qE 'duplicate BDR-009'; then
|
||||||
red 6 "verify emits FALSE 'ORPHAN INDEX: BDR-009' (body exists; trailing-space bug)"
|
green 6 "verify runs memory.sh check and names the duplicate BDR-009"
|
||||||
else
|
else
|
||||||
green 6 "verify does not false-orphan the title-less heading"
|
red 6 "verify misses the duplicate BDR-009 (no memory.sh check in STEP 4)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---- RED-7: STEP 2 plan example must use FICTIONAL ids, never live registry ids
|
# ---- RED-7: STEP 2 plan example must use FICTIONAL ids, never live registry ids
|
||||||
|
|||||||
Reference in new issue
Block a user