From 7e87d7722dd6175fba0babc42074a595f28af2fb Mon Sep 17 00:00:00 2001 From: bchanot Date: Thu, 12 Nov 2026 20:30:45 +0100 Subject: [PATCH 1/4] feat(memory): idle recall needs 8 content words, recall keeps 2 picks Gate 1 (EVAL-058): idle 44 %, 3rd pick 35 %. --- mods/memory/hooks/register.test.ts | 75 +++++++++++++++++++++--------- mods/memory/hooks/register.ts | 10 ++-- 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/mods/memory/hooks/register.test.ts b/mods/memory/hooks/register.test.ts index cf0fc51..9486647 100644 --- a/mods/memory/hooks/register.test.ts +++ b/mods/memory/hooks/register.test.ts @@ -10,7 +10,7 @@ import { segments, suiteKeyOf, commitLabel, finishLabel, newState, switchOf, claim, onContextStart, resetContext, endContext, appendLog, loadLog, isLogRecord, RECALL_CAP, isTrigger, - MIN_CONTENT_WORDS, promptContext, + MIN_CONTENT_WORDS, IDLE_MIN_WORDS, triggerKind, promptContext, DESIGN_RULE, ANALYSIS_RULE, HAIKU, RERANK_MS, IDLE_MS, } from './register' import type { LogRecord } from './register' @@ -1988,7 +1988,7 @@ test('RB4: rerankPrompt is the literal prompt', () => { const cands = [mk('LRN-1', 'T one', 'Do a.'), mk('BLK-2', 'T two', '')] expect(rerankPrompt('fix the heredoc', cands)).toBe( 'Prompt: fix the heredoc\nCandidates:\nLRN-1 | T one | Do a.\n' + - 'BLK-2 | T two | \nAnswer with at most 3 candidate IDs that would ' + + 'BLK-2 | T two | \nAnswer with at most 2 candidate IDs that would ' + 'help with this prompt, comma separated, or none.') }) @@ -2317,6 +2317,8 @@ const REC_INDEX = rowsOut([['BLK-001', 'mod design'], const GO = 'on va concevoir la suite du mod memory recall' const DESIGN = 'design the mod suite and tests please' const NOTES = 'write notes about the mod now' +// 8 content words, no rule word: the shortest prompt an idle gap can ask on +const NOTES8 = 'write some notes about the mod behaviour during session' /** Boots the notes world with recall fixtures; the model picks BLK-001. */ async function bootRecall($: Engine, on: On, o: Opts = {}) { @@ -2358,7 +2360,7 @@ test('LO2: idle and keyword triggers are told apart', async ($, on) => { await start($) await say($, GO) await w.clock.advance(1860000) - await say($, NOTES) + await say($, NOTES8) await say($, DESIGN) expect((await askLog(w)).map(r => r[0])) .toEqual(['fresh', 'idle', 'keyword']) @@ -2497,14 +2499,23 @@ test('IR2 IR3: an ordinary prompt 1 min later is silent, 31 min asks', await start($) await say($, GO) await w.clock.advance(60000) - await say($, NOTES) + await say($, NOTES8) expect(w.asks).toHaveLength(1) expect(seen[1]).toBeUndefined() await w.clock.advance(1860000) - await say($, NOTES) + await say($, NOTES8) expect(w.asks).toHaveLength(2) }) +test('IR2b: a 5-word prompt after 31 min asks nothing', async ($, on) => { + const { w } = await bootRecall($, on) + await start($) + await say($, GO) + await w.clock.advance(1860000) + await say($, NOTES) + expect(w.asks).toHaveLength(1) +}) + test('IR4: slash, mid-turn, sdk and short prompts never ask', async ( $, on, ) => { @@ -2726,13 +2737,29 @@ test('isTrigger: rules, fresh, idle, slash and length', () => { expect(isTrigger(long, false, 0)).toBe(true) expect(isTrigger(SUITE, false, 0)).toBe(false) expect(isTrigger(SUITE, true, 0)).toBe(true) - expect(isTrigger(SUITE, false, IDLE_MS)).toBe(true) + expect(isTrigger(SUITE, false, IDLE_MS)).toBe(false) expect(isTrigger('/feat design the thing', true, IDLE_MS)).toBe(false) expect(isTrigger('design note', true, 0)).toBe(false) expect(isTrigger('un-design-ed thing here', false, 0)).toBe(false) expect(HAIKU).toBe('claude-haiku-5-5') }) +test('isTrigger: idle needs IDLE_MIN_WORDS content words', () => { + const seven = 'write some notes about mod behaviour during' + expect(IDLE_MIN_WORDS).toBe(8) + expect(MIN_CONTENT_WORDS).toBe(5) + expect(triggerKind(seven, false, IDLE_MS)).toBeUndefined() + expect(triggerKind(`${seven} session`, false, IDLE_MS)).toBe('idle') + expect(triggerKind(seven, false, IDLE_MS - 1)).toBeUndefined() + expect(triggerKind(seven, true, 0)).toBe('fresh') + expect(triggerKind('please review this module and the new tests', false, 0)) + .toBe('keyword') + // a rule word still fires on a short idle prompt, as a keyword + expect(triggerKind('please review this module and the new tests', + false, IDLE_MS)).toBe('keyword') + expect(triggerKind(`${NOTES8} and design`, false, IDLE_MS)).toBe('idle') +}) + test('isTrigger: fewer than five content words never triggers', () => { expect(MIN_CONTENT_WORDS).toBe(5) // 2-letter function words (finding I1) are no content @@ -2804,13 +2831,14 @@ test('SP1: an ordinary prompt resets the main key spent budget', async ( onContextStart(st, 's1') const [block] = await promptContext(api(), st, e('design alpha now, whole team')) - expect(block?.length).toBe(1160) // 14 header + 3 x (381 line + 1) - expect(st.spent.get('s1:main')).toBe(1160) + // 3 candidates, the answer lists 3, the cap keeps 2 + expect(block?.length).toBe(778) // 14 header + 2 x (381 line + 1) + expect(st.spent.get('s1:main')).toBe(778) expect(await promptContext(api(), st, e('nothing special at all'))) .toEqual([]) expect(st.spent.has('s1:main')).toBe(false) - // a 400-char line fits after the reset; 1160 + 400 > 1500 would not - expect(claim(st, 's1:main', ['KNOWN-1'], [400])).toEqual(['KNOWN-1']) + // an 800-char line fits after the reset; 778 + 800 > 1500 would not + expect(claim(st, 's1:main', ['KNOWN-1'], [800])).toEqual(['KNOWN-1']) }) test('SP2: a prompt without a known last prompt is not idle', async ( @@ -2820,7 +2848,7 @@ test('SP2: a prompt without a known last prompt is not idle', async ( w.proc = { stdout: REC_INDEX } const api = () => fakeApi(w) const st = switchedOn() - const e = { text: NOTES, origin: { kind: 'composer' } } + const e = { text: NOTES8, origin: { kind: 'composer' } } expect(await promptContext(api(), st, e)).toEqual([]) expect(w.asks).toEqual([]) expect(st.lastPrompt.get('s1')).toBe(1000) @@ -3001,22 +3029,27 @@ test('TE8: a failing known-line step returns the answer unchanged', expect(failuresOf(w)).toHaveLength(1) }) -test('TE9: a recall of ~1160 chars, an ordinary prompt, then a ~395 known ' + - 'line is injected', async ($, on) => { - const span = 'fatal: alpha cluster is down' - const known = entryText('BLK-004', 't'.repeat(89) + '4', 'Solution', - 'alpha '.repeat(50).slice(0, 279) + '.') + `seen: \`${span}\`\n` +test('TE9: a recall of 778 chars, two known lines of ~395: the second ' + + 'is refused until an ordinary prompt resets the budget', async ($, on) => { + const spans = ['fatal: alpha cluster is down', 'fatal: beta cluster is down'] + const known = (n: number) => entryText(`BLK-00${n}`, + 't'.repeat(89) + n, 'Solution', 'alpha '.repeat(50).slice(0, 279) + '.') + + `seen: \`${spans[n - 4]}\`\n` const { w, seen } = await bootNotes($, on, { files: { [BLK]: - [...[1, 2, 3].map(longEntry), known].join('\n') } }) - w.proc = { stdout: rowsOut([1, 2, 3, 4].map((n): [string, string] => + [...[1, 2, 3].map(longEntry), known(4), known(5)].join('\n') } }) + w.proc = { stdout: rowsOut([1, 2, 3, 4, 5].map((n): [string, string] => [`BLK-00${n}`, 't'.repeat(89) + n])) } w.model = { text: 'BLK-001, BLK-002, BLK-003' } await start($) await say($, 'design alpha now, whole team') - expect(seen[0]?.[0]?.length).toBe(1160) // 14 + 3 x (381 + 1) + expect(seen[0]?.[0]?.length).toBe(778) // 14 + 2 x (381 + 1) + const first = await failing($, w, EXIT1 + spans[0]) as + { context?: string[] } + expect(first.context?.[0]?.length).toBe(395) // 778 + 395 = 1173 + // 1173 + 395 > 1500: refused until the per-prompt reset + expect(await failing($, w, EXIT1 + spans[1])).toEqual(w.answer) await say($, 'nothing special at all') - const out = await failing($, w, EXIT1 + span) as { context?: string[] } - // 1160 + 395 > 1500: only the per-prompt reset lets it through + const out = await failing($, w, EXIT1 + spans[1]) as { context?: string[] } expect(out.context?.[0]?.length).toBe(395) }) diff --git a/mods/memory/hooks/register.ts b/mods/memory/hooks/register.ts index 3578a16..9972068 100644 --- a/mods/memory/hooks/register.ts +++ b/mods/memory/hooks/register.ts @@ -704,7 +704,7 @@ const MAX_QUERY = 2000 const MAX_DOC = 65536 const BM25_K1 = 1.2 const BM25_B = 0.75 -const MAX_PICKS = 3 +const MAX_PICKS = 2 /** Lowercase word runs (2-40 letters or digits) minus function words. */ export function tokensOf(text: string): string[] { @@ -1639,6 +1639,9 @@ export const ANALYSIS_RULE = wordRule( const MIN_PROMPT = 12 // code points // Measurement gate: fewer content words than this never asks for recall. export const MIN_CONTENT_WORDS = 5 +// Gate 1 (2026-11-12): idle precision was 44 % on short follow-ups, so an +// idle prompt needs more words than a fresh or keyword one. +export const IDLE_MIN_WORDS = 8 const MAX_CANDS = 30 const RERANK_FAILS = 3 // failed reranks in a row that pause it const RERANK_PAUSE_MS = 900000 @@ -1652,9 +1655,10 @@ export function triggerKind( if (text.startsWith('/') || Array.from(text).length < MIN_PROMPT) { return undefined } - if (tokensOf(text).length < MIN_CONTENT_WORDS) return undefined + const words = tokensOf(text).length + if (words < MIN_CONTENT_WORDS) return undefined if (fresh) return 'fresh' - if (idleMs >= IDLE_MS) return 'idle' + if (idleMs >= IDLE_MS && words >= IDLE_MIN_WORDS) return 'idle' const asked = cap(text, MAX_REGEX_INPUT) return DESIGN_RULE.test(asked) || ANALYSIS_RULE.test(asked) ? 'keyword' From 39f979068a048bfebec95974c0f9a27a7a932d45 Mon Sep 17 00:00:00 2001 From: bchanot Date: Thu, 12 Nov 2026 20:30:46 +0100 Subject: [PATCH 2/4] feat(prune-memory): step D, gate feedback noisy rewrite and BDR-100 promotion Reads FEEDBACK.md for this repo's tag; RED-10 runs the real block. --- skills/prune-memory/SKILL.md | 110 +++++++++++++- .../prune-memory/tests/run-deterministic.sh | 140 ++++++++++++++++-- 2 files changed, 239 insertions(+), 11 deletions(-) diff --git a/skills/prune-memory/SKILL.md b/skills/prune-memory/SKILL.md index e104837..58ea5f3 100644 --- a/skills/prune-memory/SKILL.md +++ b/skills/prune-memory/SKILL.md @@ -137,6 +137,84 @@ 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. Feedback — noisy and promotion (phase 4d.4) +The recall feedback gate (`/memory-feedback`) writes +`~/.claude/memory-feedback/FEEDBACK.md`. Its `Noisy:` and `Promotion +candidates:` lines list ` ` items; this run reads the ones +of the current repo only. The cutoffs live in +`lib/memory-feedback/thresholds.ts` (`T.noisyHits`, `T.promoteHits`, +`T.promoteSessions`): cite them, never restate a number. + +```bash +# Feedback rows for THIS repo. Rows: tagT, dateD, noisyID, +# promoteID, othertag; or one word: no-git-root, no-feedback-run. +# The tag is the reader's (lib/memory-feedback/labels.ts tagOf). +fb="$HOME/.claude/memory-feedback/FEEDBACK.md" +root=$(git rev-parse --show-toplevel 2>/dev/null) \ + || { echo "no-git-root"; exit 0; } +sum=$(printf '%s' "$root" | { sha1sum 2>/dev/null || shasum -a 1; } \ + | cut -c1-6) +tag="$(basename "$root")#$sum" +[ -f "$fb" ] || { echo "no-feedback-run"; exit 0; } +printf 'tag\t%s\n' "$tag" +printf 'date\t%s\n' "$(sed -n '1s/^.*(\([^)]*\)).*$/\1/p' "$fb")" +items() { # $1 = line prefix -> one " " item per line + sed -n "s/^$1: //p" "$fb" | tr -d '\r' | awk '{ n = split($0, a, ", ") + for (i = 1; i <= n; i++) if (a[i] != "none") print a[i] }' +} +rows() { # $1 = line prefix, $2 = row kind + items "$1" | while IFS= read -r it; do + id=${it##* } + case "$it" in + "$tag "*) [[ $id =~ ^(BDR|LRN|BLK)-[0-9]+$ ]] || continue + printf '%s\t%s\n' "$2" "$id" ;; + *) printf 'other\t%s\n' "${it% *}" ;; + esac + done +} +promoted() { # $1 = ID: rc 0 when its entry holds a "promoted to" line + awk -v id="$1" '$0 ~ "^## " id "( |$)" { e = 1; next } + /^## / { e = 0 } + e && /^- \*\*Status \(.*promoted to/ { f = 1 } + END { exit !f }' "$root"/.claude/memory/*.md 2>/dev/null +} +noisy_done() { # $1 = ID: rc 0 when a curation commit rewrote it + [ -n "$(git -C "$root" log -E --format=%s \ + --grep="noisy-rewrite $1([^0-9]|\$)" -- .claude/memory 2>/dev/null)" ] +} +{ rows Noisy noisy; rows 'Promotion candidates' promote; } | + while IFS=$'\t' read -r kind id; do + case "$kind" in + noisy) noisy_done "$id" || printf 'noisy\t%s\n' "$id" ;; + promote) promoted "$id" || printf 'promote\t%s\n' "$id" ;; + *) printf 'other\t%s\n' "$id" ;; + esac + done | awk '!seen[$0]++' +``` + +Rules: the lines are matched anchored and case-sensitive (`Noisy: `, +`Promotion candidates: `), the literal `none` is skipped, the Actions +section is never parsed. An item is ` `, the ID being its last +field; a `, ` inside a repo basename would split an item (accepted limit). +`other` rows name tags of other repos, for visibility only. A `promote` +row is dropped once its entry holds a `promoted to` status line; a `noisy` +row is dropped once a curation commit subject carries `noisy-rewrite ` +(STEP 3 item 4 names it). With a `$ARGUMENTS` filter, keep the rows whose ID +prefix belongs to a filtered registry. +- A `noisy` row → candidate: inline rewrite of the title and of the + lesson sentence, narrowed to the concrete trigger so BM25 and the + rerank stop picking it for unrelated prompts. The lesson sentence is the + one the recall line shows: the first sentence (up to 280 characters) of + the first labelled field, in the order BDR `Decision`; LRN `Apply`, + `Future application`, `Pattern`; BLK `Solution`, `Real cause`. A title + or sentence under the NEGATION GUARD (STEP 3.3) is skipped and reported + as a manual rewrite. Limit: the tool matcher reads the backtick spans + of the body, which this rewrite leaves alone. +- A `promote` row → a BDR-100 proposal: name the mechanism (rule line, + hook, guard, test) in STEP 2; the user decides. +- `no-feedback-run` → one line in STEP 2. No `noisy`/`promote` row (only + `tag`, `date`, `other`) → the `none for ` line. + ## STEP 2 — PRESENT PLAN ★ MANDATORY STOP Print one block per registry. Example: @@ -166,9 +244,23 @@ PRUNE PLAN — decisions.md (N entries → M after if approved) 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) +[D. Feedback — noisy rewrite / promotion] (run-level, repo , ) + LRN-905 — noisy: picked for unrelated prompts + → inline rewrite: title + lesson narrowed to the concrete + trigger, "" / "" + LRN-906 — promotion candidate (a mechanism, not a note) + → mechanism: , a separate /feat + → on accept: memory.sh status LRN-906 ", promoted + to " (implemented when the entry has no word) + +Approve per category? (all / a / b / c / d / edit / skip) ``` +D is one run-level block after the per-registry ones. No feedback file +prints `[D. Feedback] no feedback run (~/.claude/memory-feedback/FEEDBACK.md +absent)`; no row for this repo prints `[D. Feedback] none for `; +`no-git-root` prints `[D. Feedback] not in a git repo`. + 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 @@ -221,6 +313,15 @@ Registry writes follow `lib/capitalize-commit.md` § WRITE (single writer). - Short synonyms (`big` not `extensive`, `fix` not `implement a solution for`). - Keep code blocks, URLs, error messages, file paths VERBATIM. - Keep IDs (BDR-XXX, LRN-XXX, commit hashes) verbatim. +4. **Feedback (D)** — a noisy rewrite changes only the title TEXT (the + `## — `, the `[status]` tag and the `(date)` stay verbatim) and + the one lesson sentence of STEP 1.D, under the same NEGATION GUARD as + item 3; it is an inline edit under the curation commit, never a status + line. A promotion is one line: + `bash "$HOME/.claude/lib/memory.sh" status ", + promoted to "`, the current word from `memory.sh index ` + (`implemented` when none is readable), so a closed entry stays closed. + The mechanism itself is a separate /feat, named in the final report. ## STEP 4 — VERIFY @@ -233,7 +334,7 @@ bash "$HOME/.claude/lib/memory.sh" check .claude/memory \ # 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 # negation/permanent token COUNT drops within an entry vs HEAD -- immune to the -# line-sharing false positives a removed-line grep produces. The STEP 3.4 +# line-sharing false positives a removed-line grep produces. The STEP 3.3 # NEGATION GUARD keeps negation sentences verbatim; this proves none slipped. # Journal entries are date-keyed and legitimately collapse, so the journal is # restricted to {never,always,permanent} -- the markers the STEP 1.A safety @@ -297,6 +398,11 @@ CHECK: OK NEXT: review `git diff .claude/memory/`, then `/commit-change` ``` +After a noisy rewrite (D), the report also prints the exact commit subject +`chore(memory): noisy-rewrite [, …]` and says `/commit-change` +keeps it verbatim: STEP 1.D finds the rewrite again through that token. +After a promotion it names the mechanism to build as a separate `/feat`. + ## What NOT to prune - Journal entries < 30 days old. diff --git a/skills/prune-memory/tests/run-deterministic.sh b/skills/prune-memory/tests/run-deterministic.sh index f0b9c4e..f97edb3 100644 --- a/skills/prune-memory/tests/run-deterministic.sh +++ b/skills/prune-memory/tests/run-deterministic.sh @@ -1,8 +1,9 @@ #!/usr/bin/env bash -# Deterministic RED suite for /prune-memory — RED-1, RED-2, RED-5, RED-6, RED-7, RED-9. +# Deterministic RED suite for /prune-memory — RED-1, RED-2, RED-5, RED-6, +# RED-7, RED-9, RED-10. # Each MUST be red on the current (v1) skill. Pure mechanical oracles, -# no LLM. Faithful: RED-2/RED-6/RED-9 execute the REAL bash blocks extracted -# from SKILL.md (no copy that could drift). +# no LLM. Faithful: RED-2/RED-6/RED-9/RED-10 execute the REAL bash blocks +# extracted from SKILL.md (no copy that could drift). # # Sandbox only (mktemp). NEVER touches real registries or the repo. # Usage: bash run-deterministic.sh (exit 0 = all green, 1 = >=1 red) @@ -17,11 +18,11 @@ fail=0 red() { printf 'RED-%s: RED (skill defective, expected pre-GREEN) -- %s\n' "$1" "$2"; fail=1; } green() { printf 'RED-%s: GREEN (skill fixed) -- %s\n' "$1" "$2"; } -# Pull the real fenced ```bash block under a "## " from SKILL.md. +# Pull the real fenced ```bash block under a "#.. " from SKILL.md. # 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} @@ -114,10 +115,12 @@ printf '## BDR-901 — old idea [proposed] (2026-01-01)\n- **Context**: resolved 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-904 — x\ndate: 2026-01-01 · status: accepted\n\n' + printf '## BDR-905 — y\nStatus: closed.\n\n' + printf '## BDR-906 — z\nStatus: proposed\n' + printf -- '- **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" @@ -144,6 +147,125 @@ else red 9 "$msg9" fi +# ---- RED-10: STEP 1.D reads FEEDBACK.md for THIS repo's tag ----------------- +# Runs the shipped D block in a sandbox repo, HOME pinned to a sandbox dir +# holding .claude/memory-feedback/, like RED-9 (memory.sh by absolute path). +S10="$SANDBOX/red10"; H10="$SANDBOX/home10" +mkdir -p "$S10/.claude/memory" "$H10/.claude/memory-feedback" +git -C "$S10" init -q +printf -- '---\nformat: 2\n---\n# Blockers\n\n'\ +'## BLK-905 — x [resolved] (2026-01-01)\n- **Real cause**: y\n' \ + > "$S10/.claude/memory/blockers.md" +printf -- '---\nformat: 2\n---\n# Learnings\n\n'\ +'## LRN-906 — z (2026-01-01)\n- **Apply**: w\n' \ + > "$S10/.claude/memory/learnings.md" +git -C "$S10" add -A +git -C "$S10" -c user.email=t@t -c user.name=t commit -qm seed >/dev/null 2>&1 +ROOT10="$(git -C "$S10" rev-parse --show-toplevel)" +TAG10="$(basename "$ROOT10")#$(printf '%s' "$ROOT10" | sha1sum | cut -c1-6)" +FB10="$H10/.claude/memory-feedback/FEEDBACK.md" +extract_block "D. Feedback" > "$SANDBOX/step1d.sh" +run10() { ( cd "$S10" && HOME="$H10" bash "$SANDBOX/step1d.sh" 2>&1 ); } +feedback10() { # $1 = tag of the items, $2 = file + { + printf '# Memory feedback (2026-11-12)\n\nNoisy: none\n' + printf 'Noisy: %s LRN-905, other#abc123 BDR-001\n' "$1" + printf 'Promotion candidates: %s LRN-906, %s BLK-907\n\n' "$1" "$1" + printf 'Actions:\n- noisy: /prune-memory rewrites %s LRN-905\n' "$1" + } > "$2" +} +rows10() { printf '%s\n' "$1" | /usr/bin/grep -E '^(noisy|promote)'"$TAB"; } +msg10="" + +# (a) this repo's tag: both row kinds, header lines, the other tag named +feedback10 "$TAG10" "$FB10" +out10="$(run10)" +has9 "$out10" "tag${TAB}$TAG10" || msg10="a: tag header missing" +has9 "$out10" "date${TAB}2026-11-12" || msg10="${msg10:-a: date header missing}" +has9 "$out10" "noisy${TAB}LRN-905" || msg10="${msg10:-a: noisy row missing}" +has9 "$out10" "promote${TAB}LRN-906" \ + || msg10="${msg10:-a: promote LRN-906 missing}" +has9 "$out10" "promote${TAB}BLK-907" \ + || msg10="${msg10:-a: promote BLK-907 missing}" +has9 "$out10" "other${TAB}other#abc123" \ + || msg10="${msg10:-a: other row missing}" +[ "$(rows10 "$out10" | wc -l)" -eq 3 ] \ + || msg10="${msg10:-a: not exactly 3 rows}" + +# (a2) a malformed ID is skipped silently; a subdirectory run reads the +# same registries (root-relative) and gives the same 3 rows as (a) +mkdir -p "$S10/sub" +{ printf '# Memory feedback (2026-11-12)\n\n' + printf 'Noisy: %s LRN-905, %s BDR-1 (x\n' "$TAG10" "$TAG10" + printf 'Promotion candidates: %s LRN-906, %s BLK-907\n' "$TAG10" "$TAG10" +} > "$FB10" +out10="$(run10)" +printf '%s\n' "$out10" | /usr/bin/grep -q 'BDR-1' \ + && msg10="${msg10:-a2: malformed ID produced output}" +out10="$( cd "$S10/sub" && HOME="$H10" bash "$SANDBOX/step1d.sh" 2>&1 )" +[ "$(rows10 "$out10" | wc -l)" -eq 3 ] \ + || msg10="${msg10:-a2: subdir run: not 3 rows}" + +# (b) another tag only: no noisy/promote row, the tag named as other +feedback10 "zzz#000000" "$FB10" +out10="$(run10)" +[ -z "$(rows10 "$out10")" ] || msg10="${msg10:-b: a row for a foreign tag}" +has9 "$out10" "other${TAB}zzz#000000" || msg10="${msg10:-b: other row missing}" + +# (c) no FEEDBACK.md +rm -f "$FB10" +out10="$(run10)" +[ "$out10" = "no-feedback-run" ] || msg10="${msg10:-c: got: $out10}" + +# (d) the tag the block computes equals labels.ts tagOf (bun only) +if command -v bun >/dev/null 2>&1; then + labels10="$HERE/../../../lib/memory-feedback/labels.ts" + bun10="import { tagOf } from '$labels10'; " + bun10+="console.log(tagOf(process.argv[1]))" + tag10="$(bun -e "$bun10" "$ROOT10" 2>&1)" + feedback10 "$tag10" "$FB10" + out10="$(run10)" + has9 "$out10" "noisy${TAB}LRN-905" \ + || msg10="${msg10:-d: block tag differs from tagOf ($tag10 vs $TAG10)}" +else + echo "RED-10d: SKIP (bun absent, tagOf comparison not run)" +fi + +# (e) memory.sh status with ", promoted to": rc 0, the word stays, +# and the D block drops both promote rows +feedback10 "$TAG10" "$FB10" +for st in 'BLK-905|resolved, promoted to guard test' \ + 'LRN-906|implemented, promoted to hook'; do + ( cd "$S10" && HOME="$H10" bash "$HERE/../../../lib/memory.sh" \ + status "${st%%|*}" "${st#*|}" >/dev/null 2>&1 ) \ + || msg10="${msg10:-e: memory.sh status refused ${st%%|*}}" +done +idx10="$( cd "$S10" && HOME="$H10" bash "$HERE/../../../lib/memory.sh" \ + index blocker 2>&1 )" +printf '%s\n' "$idx10" | /usr/bin/grep -qE '^\| BLK-905 .*\| resolved \|$' \ + || msg10="${msg10:-e: BLK-905 word changed after the status line}" +out10="$(run10)" +printf '%s\n' "$out10" | /usr/bin/grep -qE "^promote${TAB}(LRN-906|BLK-905)" \ + && msg10="${msg10:-e: a promoted row survived}" +has9 "$out10" "promote${TAB}BLK-907" || msg10="${msg10:-e: BLK-907 row lost}" + +# (f) outside a git repo +out10="$( cd "$SANDBOX" && HOME="$H10" bash "$SANDBOX/step1d.sh" 2>&1 )" +[ "$out10" = "no-git-root" ] || msg10="${msg10:-f: got: $out10}" + +# (g) a curation commit subject carrying the token drops the noisy row +printf '\n' >> "$S10/.claude/memory/learnings.md" +git -C "$S10" add -A +git -C "$S10" -c user.email=t@t -c user.name=t \ + commit -qm 'chore(memory): noisy-rewrite LRN-905' >/dev/null 2>&1 +out10="$(run10)" +has9 "$out10" "noisy${TAB}LRN-905" && msg10="${msg10:-g: noisy row not dropped}" +if [ -z "$msg10" ]; then + green 10 "D block: tag match, foreign tag, absent file, drops, no-git-root" +else + red 10 "$msg10" +fi + echo "----" if [ "$fail" -eq 0 ]; then echo "SUITE: all GREEN" From 9e7a030895f9a4d05ea9288ced60f1791950ce8f Mon Sep 17 00:00:00 2001 From: bchanot Date: Thu, 12 Nov 2026 20:32:24 +0100 Subject: [PATCH 3/4] docs: recall idle 8 words and 2 picks, /prune-memory step D --- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- USAGE.md | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2748397..df33367 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ Format follows [Keep a Changelog](https://keepachangelog.com/) and this project ## [Unreleased] +### Added +- **/prune-memory feedback step (D)**: reads this repo's `Noisy:` and `Promotion candidates:` lines from `~/.claude/memory-feedback/FEEDBACK.md` (written by `/memory-feedback`). A noisy entry gets an inline rewrite of its title and lesson sentence, narrowed to its concrete trigger, committed as `chore(memory): noisy-rewrite `. A promotion candidate gets a mechanism proposal (rule line, hook, guard, test); on accept, a `, promoted to ` status line is recorded (a closed entry stays closed) and the mechanism is built in a separate `/feat`. Rows already rewritten or promoted are dropped. Cutoffs stay in `lib/memory-feedback/thresholds.ts`. + +### Changed +- **memory recall**: a prompt after 30 minutes idle now needs 8 content words, up from 5 (a context's first prompt or a design/analysis prompt still needs 5), and the haiku rerank keeps at most 2 entries, down from 3. Measured on the first feedback gate: idle precision 44 %, third pick 35 %. + ## [3.0.0] — 2026-11-12 ### Added diff --git a/README.md b/README.md index bbb1b2b..c208214 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ Limits: a main-loop switch re-reads cold the part of the context the target mode - Store: the plugin's `$.store`, keyed by project root: the 3 most recent sessions per project, 50 failures per session, 2 KiB per entry. Session keys (`p:`) are swept at 1 MiB; log keys (`l:`) hold about 28 KiB per project; both sit under the engine's 4 MiB cap for the whole store, and when the total nears it the oldest log key is evicted first (never the current project's). It survives `/clear`. The store is the plugin's JSON file under the Claude configuration directory (observed here as `~/.claude/plugins/store/memory_skills-dir-.json`, an engine layout, not fixed by this repo); delete it to wipe the captures. - Note: one context line, `memory: