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.
This commit is contained in:
bchanot committed 2026-11-12 00:11:03 +01:00
1 parent 7d35a3e26a
commit 99f10b2a26
4 files changed
+145 -37

No files matched your search

+2 -1
View File
@@ -653,7 +653,8 @@ memory_legacy_status() { # <file> <ID> [<end>] → 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 }
+25 -12
View File
@@ -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 → "id<TAB>open|unreadable<TAB>word 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() { # <file> <ID> <PREFIX> → 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) → "id<TAB>open|
# unreadable<TAB>word 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) ---
+73 -21
View File
@@ -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 <new-ID>`
or `status: deprecated` instead of deleting. Body of old entry stays
- **Append-only friendly.** Marks entries with a `superseded by <ID>` 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: ID<TAB>open<TAB>word | ID<TAB>unreadable<TAB>line;
# 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 <ID> "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 <ID>",
"Supersedes [[<ID>]]" on the newer one) but whose current status
(`bash "$HOME/.claude/lib/memory.sh" index decision`) still reads
"Supersedes [[<ID>]]" on the newer one) but whose word is still
`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.
- 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=<keyword>`) → propose
`memory.sh status <ID> "resolved <commit>"`.
- 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 <ID> "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 <ID> "<word>"
Approve per category? (all / a / b / c / edit <ID> / 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 <ID>`). 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 <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:
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
`- **<label>**:` line whose label holds status/resolution/action/
update/final. Add `--status <word>` (decisions, blockers, evals; the
word shown on the [B] line; learnings none). 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).
3. **Inline caveman compression** — preserve frontmatter exactly (id,
date, title, status, references). Rewrite prose body to fragments:
- Drops the sources' labelled status lines (`- **Status…**:`, `Status:`
/ `statut` lines, `- **Resolution|Action|Update|Final…**:`). The new
entry's status is the `--status` word (v2: heading tag; v1: a
`- **Status**:` body line, and a later prose STATUS LINE can make it
unreadable: it then shows in the count line).
- `memory.sh add` writes the heading (new ID, title, date) and the
status; the body keeps the union of `**Reference**:` lines.
3. **Inline caveman compression** — keep VERBATIM the heading line, every
`- **Label**:` key and every STATUS LINE; rewrite only the other prose
to fragments:
- **NEGATION GUARD (deterministic, overrides every rule below):** never
rewrite a sentence containing a negation token (`not`, `never`, `no`,
`cannot`, or any `*n't` contraction). Keep such sentences VERBATIM —
@@ -249,7 +301,7 @@ NEXT: review `git diff .claude/memory/`, then `/commit-change`
- Journal entries < 30 days old.
- Decisions / learnings with commit references < 14 days old.
- Entries the user marked `status: accepted` in the current session.
- Entries whose status the user set this session.
- The current session's just-capitalized entries (read `journal.md`
tail to identify them).
@@ -257,8 +309,8 @@ NEXT: review `git diff .claude/memory/`, then `/commit-change`
| Mistake | Fix |
|---------|-----|
| Renumbering IDs after a merge | IDs are stable. Sources keep their ID + `status: superseded`. New merged entry gets next-free ID. |
| Hard-deleting "obsolete" entries | Forbidden by append-only rule. Use `status: deprecated`. Body stays. |
| Renumbering IDs after a merge | IDs are stable. Sources keep their ID + a `superseded by <ID>` status. New merged entry gets next-free ID. |
| Hard-deleting "obsolete" entries | Forbidden by append-only rule. Use a `deprecated` status (`memory.sh status`). Body stays. |
| Compressing code blocks / URLs / error messages | Caveman compression touches PROSE only. Code, URLs, IDs, error quotes stay verbatim. |
| Running on a dirty working tree | PRECHECK blocks this. Commit first. |
| Compressing the current session's journal entry | Excluded by "What NOT to prune" — current session capitalization is still useful. |
+45 -3
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Deterministic RED suite for /prune-memory — RED-1, RED-2, RED-5, RED-6, RED-7.
# Deterministic RED suite for /prune-memory — RED-1, RED-2, RED-5, RED-6, RED-7, RED-9.
# Each MUST be red on the current (v1) skill. Pure mechanical oracles,
# no LLM. Faithful: RED-2/RED-6 execute the REAL bash blocks extracted
# no LLM. Faithful: RED-2/RED-6/RED-9 execute the REAL bash blocks extracted
# from SKILL.md (no copy that could drift).
#
# Sandbox only (mktemp). NEVER touches real registries or the repo.
@@ -21,7 +21,7 @@ green() { printf 'RED-%s: GREEN (skill fixed) -- %s\n' "$1" "$2"; }
# Verified by the extract-check before the suite was written.
extract_block() {
awk -v h="$1" '
$0 ~ "^## " h {f=1}
$0 ~ "^## " h "( |$)" {f=1}
f && /^```bash/ {c=1; next}
f && /^```/ && c {c=0; f=0; next}
c {print}
@@ -102,6 +102,48 @@ else
green 7 "STEP 2 example uses only fictional (9xx) ids"
fi
# ---- RED-9: STEP 1 reads statuses through the classifier (v1 + v2) ---------
# Runs the shipped STEP 1 block (LRN-276) on sandbox registries written with
# printf; HOME pinned like RED-6. Rows asserted whole-line, fixed string.
TAB=$'\t'
S9A="$SANDBOX/red9a"; S9B="$SANDBOX/red9b"
mkdir -p "$S9A/.claude/memory" "$S9B/.claude/memory"
printf -- '---\nformat: 2\n---\n# Decisions\n\n' > "$S9A/.claude/memory/decisions.md"
printf '## BDR-901 — old idea [proposed] (2026-01-01)\n- **Context**: resolved later\n\n' \
>> "$S9A/.claude/memory/decisions.md"
printf '## BDR-902 — kept [accepted] (2026-02-01)\n- **Status (2026-03-01)**: superseded by BDR-903\n' \
>> "$S9A/.claude/memory/decisions.md"
printf '## BLK-903 — c\n- **Status**: upstream\n' > "$S9A/.claude/memory/blockers.md"
printf '## BDR-904 — x\ndate: 2026-01-01 · status: accepted\n\n' > "$S9B/.claude/memory/decisions.md"
printf '## BDR-905 — y\nStatus: closed.\n\n' >> "$S9B/.claude/memory/decisions.md"
printf '## BDR-906 — z\nStatus: proposed\n- **Statut** : accepted (2026-05-01)\n\n' \
>> "$S9B/.claude/memory/decisions.md"
printf '## BDR-907 — w\n- Status: proposed\nSuperseded by BDR-911 (2026-05-01).\n' \
>> "$S9B/.claude/memory/decisions.md"
extract_block "STEP 1" > "$SANDBOX/step1.sh"
mkdir -p "$SANDBOX/home9/.claude"; ln -s "$HERE/../../../lib" "$SANDBOX/home9/.claude/lib"
out9a="$( cd "$S9A" && HOME="$SANDBOX/home9" bash "$SANDBOX/step1.sh" 2>&1 )"
out9b="$( cd "$S9B" && HOME="$SANDBOX/home9" bash "$SANDBOX/step1.sh" 2>&1 )"
msg9=""
has9() { printf '%s\n' "$1" | /usr/bin/grep -qxF "$2"; }
has9 "$out9a" "BDR-901${TAB}open${TAB}proposed" || msg9="v2 BDR-901 row missing"
printf '%s\n' "$out9a" | /usr/bin/grep -qF "BDR-902${TAB}" \
&& msg9="${msg9:-v2 BDR-902 listed after superseded}"
has9 "$out9a" "BLK-903${TAB}open${TAB}upstream" || msg9="${msg9:-BLK-903 row missing}"
has9 "$out9b" "BDR-904${TAB}open${TAB}accepted" || msg9="${msg9:-v1 BDR-904 row missing}"
printf '%s\n' "$out9b" | /usr/bin/grep -qF "BDR-905${TAB}unreadable${TAB}" \
|| msg9="${msg9:-v1 BDR-905 not unreadable}"
has9 "$out9b" "BDR-906${TAB}open${TAB}accepted" || msg9="${msg9:-v1 BDR-906 row missing}"
printf '%s\n' "$out9b" | /usr/bin/grep -qF "BDR-907${TAB}open${TAB}" \
&& msg9="${msg9:-v1 BDR-907 listed open}"
[ "$(/usr/bin/grep -c 'status: ' "$SKILL")" = 0 ] || msg9="${msg9:-SKILL.md keeps a raw status: line}"
[ "$(/usr/bin/grep -c 'frontmatter' "$SKILL")" = 0 ] || msg9="${msg9:-SKILL.md keeps frontmatter wording}"
if [ -z "$msg9" ]; then
green 9 "STEP 1 block classifies v1 + v2 statuses, SKILL.md has no raw status wording"
else
red 9 "$msg9"
fi
echo "----"
if [ "$fail" -eq 0 ]; then
echo "SUITE: all GREEN"