forked from bchanot/claude
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
|
||||
- Decisions `status: proposed` older than 90 days → propose
|
||||
`status: deprecated` (no follow-up).
|
||||
- Decisions whose body contains "superseded by <ID>" but Index row still
|
||||
says `accepted` → propose Index row fix to
|
||||
`superseded by <that-ID>`.
|
||||
- Decisions whose body names a successor ("superseded by <ID>",
|
||||
"Supersedes [[<ID>]]" on the newer one) but whose current status
|
||||
(`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
|
||||
days (grep `git log --since=30.days --grep=<keyword>`) → propose
|
||||
`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`
|
||||
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
|
||||
|
||||
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>
|
||||
→ mark: status: deprecated (no follow-up after 90 days)
|
||||
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]
|
||||
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]
|
||||
BDR-902 — body 612 words, filler density 7.2% → ~380 expected (-38%)
|
||||
|
||||
[D. Index drift]
|
||||
(none)
|
||||
|
||||
Approve per category? (all / a / b / c / d / edit <ID> / skip)
|
||||
Approve per category? (all / a / b / c / edit <ID> / skip)
|
||||
```
|
||||
|
||||
Wait for user input. Default = nothing applied.
|
||||
@@ -149,18 +141,22 @@ Wait for user input. Default = nothing applied.
|
||||
## STEP 3 — APPLY APPROVED CHANGES
|
||||
|
||||
Order: safe → destructive.
|
||||
Registry writes follow `lib/capitalize-commit.md` § WRITE (single writer).
|
||||
|
||||
1. **Index drift fixes** — no body changes. Backfill missing rows, mark
|
||||
orphans.
|
||||
2. **Status flag updates** — Index row status field only. Body untouched.
|
||||
3. **Merges** — write new merged entry (next-free ID); source IDs marked
|
||||
`status: superseded by <new-ID>` in Index (body kept verbatim for
|
||||
history). Merged body:
|
||||
1. **Status flag updates** — `bash "$HOME/.claude/lib/memory.sh" status <ID>
|
||||
"<word> …"` appends a dated status line (text starts with a status word:
|
||||
`deprecated, no follow-up after 90 days`); the body above stays verbatim.
|
||||
2. **Merges** — write the merged body to a scratch file, then
|
||||
`bash "$HOME/.claude/lib/memory.sh" add <kind> --title "<title>"
|
||||
--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).
|
||||
- Caveman pass on prose during merge.
|
||||
- Keeps frontmatter fields: id (new), date (today), title, status
|
||||
(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:
|
||||
- **NEGATION GUARD (deterministic, overrides every rule below):** never
|
||||
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 IDs (BDR-XXX, LRN-XXX, commit hashes) verbatim.
|
||||
|
||||
After each write, regenerate Index from body when rows changed.
|
||||
|
||||
## STEP 4 — VERIFY
|
||||
|
||||
```bash
|
||||
# Filename → ID-prefix map. Hard-mapped because filenames don't share
|
||||
# their first 3 chars with the prefix (decisions → BDR, not DEC).
|
||||
# A prior version derived the prefix via `basename | cut -c1-3`, which never
|
||||
# matched any heading and made verify a no-op (false-clean signal).
|
||||
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
|
||||
# Structure: heading shape + unique IDs + no open fence (v2 registries; a
|
||||
# v1 one is named and skipped). Same verify the writer runs after every add.
|
||||
bash "$HOME/.claude/lib/memory.sh" check .claude/memory \
|
||||
|| echo "CHECK FAILED: fix the lines above before certifying"
|
||||
|
||||
# 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
|
||||
@@ -271,7 +241,7 @@ PRUNE COMPLETE
|
||||
journal.md : 88 → 62 lines (-30%)
|
||||
evals.md : no candidates
|
||||
|
||||
INDEX SANITY: OK
|
||||
CHECK: OK
|
||||
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 |
|
||||
| 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. |
|
||||
| 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). |
|
||||
| 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
|
||||
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
|
||||
subagent finds → add the fixture and its counter to the "Common
|
||||
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": 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)"
|
||||
fi
|
||||
|
||||
# ---- RED-6: STEP 4 verify must not false-orphan a title-less heading --------
|
||||
S6="$SANDBOX/red6"; mkdir -p "$S6/.claude/memory"
|
||||
cp "$HERE/fixtures/red6-orphan/.claude/memory/decisions.md" \
|
||||
# ---- RED-6: STEP 4 verify runs memory.sh check (duplicate ID caught) --------
|
||||
# v2 registries carry no Index; the structural verify is `memory.sh check`
|
||||
# (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"
|
||||
extract_block "STEP 4" > "$S6/step4.sh"
|
||||
out="$( cd "$S6" && bash step4.sh 2>/dev/null )"
|
||||
if printf '%s\n' "$out" | grep -qE '^ORPHAN INDEX: BDR-009'; then
|
||||
red 6 "verify emits FALSE 'ORPHAN INDEX: BDR-009' (body exists; trailing-space bug)"
|
||||
out="$( cd "$S6" && HOME="$S6/home" bash step4.sh 2>&1 )"
|
||||
if printf '%s\n' "$out" | grep -qE 'duplicate BDR-009'; then
|
||||
green 6 "verify runs memory.sh check and names the duplicate BDR-009"
|
||||
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
|
||||
|
||||
# ---- RED-7: STEP 2 plan example must use FICTIONAL ids, never live registry ids
|
||||
|
||||
Reference in new issue
Block a user