From 99f10b2a2641f51e03da344a7a8d869a90204ae7 Mon Sep 17 00:00:00 2001 From: bchanot Date: Thu, 12 Nov 2026 00:11:03 +0100 Subject: [PATCH] feat(prune-memory): read statuses through one classifier, v1 and v2 reconcile_status_classify generalizes the BLK classifier to a prefix; STEP 1 runs it on decisions and blockers, unreadable statuses are an info-only count. RED-9 runs the shipped block on v1 and v2 fixtures. --- lib/memory.sh | 3 +- lib/reconcile.sh | 37 +++++--- skills/prune-memory/SKILL.md | 94 ++++++++++++++----- .../prune-memory/tests/run-deterministic.sh | 48 +++++++++- 4 files changed, 145 insertions(+), 37 deletions(-) diff --git a/lib/memory.sh b/lib/memory.sh index 4076cba..54762ed 100755 --- a/lib/memory.sh +++ b/lib/memory.sh @@ -653,7 +653,8 @@ memory_legacy_status() { # [] → the v1 lexical status line | tail -1 return fi - RE="$_MEM_LEGACY_RE" END_RE="$end" awk -v id="$2" ' + # callers may widen the selector (reconcile: the decisions range) + RE="${MEM_LEGACY_RE:-$_MEM_LEGACY_RE}" END_RE="$end" awk -v id="$2" ' /^```/ { fence = !fence; next } !fence && $0 ~ ("^#+ *" id "( |$)") && on { next } !fence && $0 ~ ENVIRON["END_RE"] { on = 0 } diff --git a/lib/reconcile.sh b/lib/reconcile.sh index 47c88df..64fa211 100644 --- a/lib/reconcile.sh +++ b/lib/reconcile.sh @@ -31,8 +31,9 @@ # parser on v2, legacy lexical reader on v1 # reconcile_blk_open — blockers whose CURRENT status is not closed # (resolved | superseded | deprecated on v2) -# reconcile_blk_classify — blockers for a client deliverable: open +# reconcile_status_classify — entries of any prefix (BLK, BDR): open # (word) | unreadable, closed omitted +# reconcile_blk_classify — its BLK wrapper, for a client deliverable # reconcile_verdict — pure kernel: declared checkbox × real fact # → verdict # reconcile_deferrals — lexical deferral sweep (honest limit) @@ -49,6 +50,9 @@ RECONCILE_GREP="${RECONCILE_GREP:-/usr/bin/grep}" RECONCILE_DEFER_RE='[Dd]efer|[Ff]ollow-?up|[Oo]ut.of.scope|OUT-OF-SCOPE' RECONCILE_DEFER_RE+='|[Rr]econsider|[Rr]evisit|2e passage|won.t.do' RECONCILE_DEFER_RE+='|optional\)|one-line ticket' +# v1 decisions carry `**Statut** :` and `Superseded by …` lines the blocker +# selector skips; an unlabelled winner stays unreadable (_mem_v1_word) +RECONCILE_BDR_RE="$_MEM_LEGACY_RE|statut|superseded|deprecated" # --- recursive coherence: enumerate IDs from the BODY, never the ## Index --- # $1 registry file, $2 prefix (BDR|LRN|BLK|EVAL). Emits one id per line, unique. @@ -107,17 +111,25 @@ reconcile_blk_open() { printf '%s\t%s\n' "$id" "$st" done } -# blockers for a client deliverable → "idopen|unreadableword or -# line"; closed ones are omitted. A status no reader maps to exactly one -# known word is unreadable, never open (BDR-129, BDR-133): v2 strict word, -# v1 the single word of a status/statut label (_mem_v1_word: prose, mixed -# or negated lines give none). Entries under a heading the enumerator -# cannot see (`### BLK-`) are unreadable too. -reconcile_blk_classify() { +_reconcile_status() { # → the current status line + [ "$3" = BLK ] && { reconcile_blk_current_status "$1" "$2"; return; } + if memory_is_v2 "$1"; then memory_entry_status "$1" "$2"; return; fi + MEM_GREP="$RECONCILE_GREP" MEM_LEGACY_RE="$RECONCILE_BDR_RE" \ + memory_legacy_status "$1" "$2" "^##* *$3-[0-9]" +} +# entries of one prefix (BLK blockers, BDR decisions) → "idopen| +# unreadableword or line"; closed ones are omitted. A status no +# reader maps to exactly one known word is unreadable, never open +# (BDR-129, BDR-133): v2 strict word, v1 the single word of a +# status/statut label (_mem_v1_word: prose, mixed or negated lines give +# none). Entries under a heading the enumerator cannot see (`### BLK-`) +# are unreadable too. +# $1 file, $2 prefix. The status source: _reconcile_status. +reconcile_status_classify() { local id st w v2="" memory_is_v2 "$1" && v2=1 - for id in $(reconcile_enumerate_ids "$1" BLK); do - st=$(reconcile_blk_current_status "$1" "$id") + for id in $(reconcile_enumerate_ids "$1" "$2"); do + st=$(_reconcile_status "$1" "$id" "$2") if [ -n "$v2" ]; then w=$(memory_status_word "$st") else w=$(_mem_v1_word "$st"); fi [ -n "$st" ] || w="" @@ -128,11 +140,12 @@ reconcile_blk_classify() { esac printf '%s\tunreadable\t%s\n' "$id" "${st:0:80}" done - MEM_GREP="$RECONCILE_GREP" _mem_heading_ids "$1" BLK | sort -u \ - | comm -23 - <(reconcile_enumerate_ids "$1" BLK) \ + MEM_GREP="$RECONCILE_GREP" _mem_heading_ids "$1" "$2" | sort -u \ + | comm -23 - <(reconcile_enumerate_ids "$1" "$2") \ | while read -r id; do printf '%s\tunreadable\theading level\n' "$id"; done return 0 } +reconcile_blk_classify() { reconcile_status_classify "$1" BLK; } # --- pure reconciliation kernel: declared checkbox × real fact → verdict # (no git, fully testable) --- diff --git a/skills/prune-memory/SKILL.md b/skills/prune-memory/SKILL.md index 9c9f244..e104837 100644 --- a/skills/prune-memory/SKILL.md +++ b/skills/prune-memory/SKILL.md @@ -30,8 +30,8 @@ Operates on `.claude/memory/` in the current project (CWD). Curates the - **Git is the backup.** Skill writes in-place. PRECHECK refuses to run if working tree dirty on registry files. -- **Append-only friendly.** Marks entries `status: superseded by ` - or `status: deprecated` instead of deleting. Body of old entry stays +- **Append-only friendly.** Marks entries with a `superseded by ` or + `deprecated` status written by `memory.sh status` instead of deleting. Body of old entry stays for history. - **IDs stable.** Never renumber. Merges create a new ID; sources keep their ID with superseded status. @@ -74,19 +74,47 @@ on a branch; on a working branch it proceeds in place. Never `gitflow finish`. For each target registry (filter by `$ARGUMENTS` or all 5): +Current statuses come from one reader for decisions and blockers, run once: + +```bash +# Current statuses: one reader for decisions and blockers (BDR-129: +# strict word on v2, one status word on v1, never the ## Index, never a +# word in prose). Rows: IDopenword | IDunreadableline; +# closed entries (resolved, superseded, deprecated) are omitted. +for k in decisions:BDR blockers:BLK; do + f=".claude/memory/${k%%:*}.md" + [ -f "$f" ] || { echo "== $f: no-file"; continue; } + echo "== $f" + ( . "$HOME/.claude/lib/reconcile.sh" \ + && reconcile_status_classify "$f" "${k#*:}" ) \ + || echo "== $f: reader-unavailable" +done +``` + +These rows are the ONLY status source of STEP 1.A: a status word in an +entry's prose or title is never a status. With a `$ARGUMENTS` filter, use +only the rows of the filtered registries. `reader-unavailable` → no +status-based candidate for that registry this run (say so in STEP 2). +`unreadable` rows → the `[Status unreadable]` count line (STEP 2), never +an A candidate. + Read file. Classify candidates into A/B/C/D below. Use today's date for 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 word is `proposed` and whose date is older than 90 days + → propose `memory.sh status "deprecated, no follow-up after 90 + days"`. Date = the newer of the `memory.sh index decision` Date cell and + the date of the entry's last `- **Status (YYYY-MM-DD)**:` line; no date + → not a candidate (v1 dialect dates such as `| date |` headings or + `date: … ·` lines give none). - Decisions whose body names a successor ("superseded by ", - "Supersedes [[]]" on the newer one) but whose current status - (`bash "$HOME/.claude/lib/memory.sh" index decision`) still reads + "Supersedes [[]]" on the newer one) but whose word is still `accepted` → propose `memory.sh status "superseded by "`. -- Blockers `status: open` whose root cause matches a commit in last 30 - days (grep `git log --since=30.days --grep=`) → propose - `status: resolved` with commit ref. +- Blockers whose word is exactly `open` (never upstream, accepted or any + other word) whose root cause matches a commit in last 30 days (grep + `git log --since=30.days --grep=`) → propose + `memory.sh status "resolved "`. - Journal entries older than 180 days with zero cross-reference from later entries → propose collapse into 1-line month summary (`## YYYY-MM` heading replaces detail). @@ -119,23 +147,36 @@ PRUNE PLAN — decisions.md (N entries → M after if approved) worked example cannot PRIME a real prune. Apply the same shapes to real IDs.) [A. Obsolete — mark superseded] - BDR-901 — example proposed decision — status: proposed since <90+ days ago> - → mark: status: deprecated (no follow-up after 90 days) + BDR-901 — example proposed decision — word proposed, dated <90+ days ago> + → memory.sh status BDR-901 "deprecated, no follow-up after 90 days" BDR-902 — example decision — body says 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) - → propose: merge into NEW LRN-904 with both bodies appended + - caveman pass; sources marked status: superseded by LRN-904 + → propose: merge into NEW LRN-904 (learnings carry no status) with + both bodies appended + caveman pass; sources: + memory.sh status "superseded by LRN-904" (merge ONLY same-concept entries — complementary/different-angle stays split) [C. Bloated — inline caveman rewrite] BDR-902 — body 612 words, filler density 7.2% → ~380 expected (-38%) +[Status unreadable — info only, never applied, not part of "all"] + decisions.md: 3 (BDR-905, BDR-906, BDR-907) + → you give the word per ID: memory.sh status "" + Approve per category? (all / a / b / c / edit / skip) ``` +A [B] merge of decisions, blockers or evals names the merged entry's +status word on its line (default: the sources' common word; sources +differ → ask in `edit `). The count line folds IDs (first 10, then +`+N more`); the word always comes from the user, never from the entry +text. On a v1 file the status text carries one status word only (else it +stays unreadable). A row `heading level` needs its heading fixed to +`## ID` first (`memory.sh status` cannot reach it). + Wait for user input. Default = nothing applied. ## STEP 3 — APPLY APPROVED CHANGES @@ -151,13 +192,24 @@ Registry writes follow `lib/capitalize-commit.md` § WRITE (single writer). --body-file --supersedes ` (next-free ID, forward link, the first source marked superseded); each other source: `memory.sh status "superseded by "`. Source bodies stay - verbatim for history. Merged body: + verbatim for history. A STATUS LINE is any line of the entry that holds + (case-insensitive) `status`, `statut`, `resolved`, `reverted`, + `upstream`, `superseded`, `deprecated` or the word `open`, or a + `- **