From f93546ded1568b29adc04fa713d963be6a0452f7 Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 8 Nov 2026 19:20:26 +0100 Subject: [PATCH] =?UTF-8?q?chore(memory):=20BDR-140=20+=20LRN-267,=20LRN-2?= =?UTF-8?q?68=20=E2=80=94=20ship=20memory=20feedback=204d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/memory/decisions.md | 10 ++++++++++ .claude/memory/journal.md | 3 +++ .claude/memory/learnings.md | 12 ++++++++++++ .claude/tasks/TODO.md | 5 +++-- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.claude/memory/decisions.md b/.claude/memory/decisions.md index a972187..27bb778 100644 --- a/.claude/memory/decisions.md +++ b/.claude/memory/decisions.md @@ -1512,3 +1512,13 @@ Supersedes [[BDR-030]]. - **Why**: `.claude/**` let project config read by every session (rules, settings) land on protected base unreviewed; `--name-only` printed only rename destination → `git mv .claude/rules/x .claude/tasks/x` hid deletion. Allowlist = exactly side-car paths skills commit (memory-commit, deploy-commit, /tour audits): no skill flow taxed. Develop history: 1 commit (858e7a7, `.claude/settings.json`) would now need branch. - **Alternatives rejected**: keep `.claude/**` (BDR-045 status quo, leak stays); also exempt `.claude/settings.json` (user picked no: config = reviewed change); size/heuristic narrowing (BDR-045 (D), fuzzy). - **Residual**: hook fails open if `git diff --cached` errors (pre-existing; Gitea protection backstop). Partly revises [[BDR-045]] (exemption narrowed, aiguillage unchanged). See [[LRN-084]]. + +## BDR-140 — Phase 4d memory feedback: offline reader, local labels, two gates, fixed thresholds, /memory-feedback [accepted] (2026-11-08) + +- **Date**: 2026-11-08 +- **Status**: accepted +- **Decision**: phase 4d feedback = offline reader, no runtime cited flag. Mod logs `cands` + `ms` on prompt records (4d.1). Bun reader `lib/memory-feedback/` (labels, metrics, thresholds, transcripts, reader CLI worksheet|apply|sample) joins `l:` log to transcript attachments; redacted text only in scratchpad worksheet; `~/.claude/memory-feedback/` (0700/0600) keeps labels.tsv (append-only + .bak, repo tag `basename#sha1[0:6]`), state.json (gate verdict first-reached times, closed flag), FEEDBACK.md. Two independent gates: prompt 20 labelled asks or 35 d; tool 10 or 35 d, one 35-d extension then closed. Thresholds r1 table in `thresholds.ts` only. Skill `/memory-feedback` (reflect row), user-invoked; banner reminder `lib/memory-feedback-remind.sh` (5+ d, store changed, silent when closed / recall off). Gate verdict recorded once (NEW line) as EVAL in this repo only (-C). +- **Why**: transcripts live 7 d (BDR-057) → weekly reminder, not raised retention; labels carry client repo names → local, never in git; log alone cannot show usefulness or misses → join + Claude labels + user spot check (LRN-168); tool channel ~3 records/14 d → own gate. +- **Alternatives rejected**: raise cleanupPeriodDays (reverses secret hygiene); cron job (machinery, background claude); labels committed (client names on Gitea); one joint gate (prompt waits on rare tool channel); Stop-hook cited flag (BDR-125). +- **Deviations from spec (user-gated 2026-11-07)**: reader in lib/ not mods/ (plugin validate/test scope); miss causes no-overlap|overlap only; labels.tsv without cited; noisy/promotion lines carry repo tag. +- **Reference**: feature/memory-feedback 21483dc..b44b19f; contract .claude/tasks/contracts/2026-11-06-memory-feedback-4d-1825.md. See [[BDR-125]], [[BDR-137]], [[BDR-100]]. diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index 53601b5..359d4f7 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -702,3 +702,6 @@ rules: - capitalize pre-compact: 2 learnings (hook never calls claude CLI; worktree ignored symlinks + diff3); TODO BLK-043 merge checked, Part B kept. 4c digest switch committed 4a7ce37. - 2026-11-06: BLK-043 Part B /hotfix 2f45452: session-digest suite stubs claude CLI (SD0 control, SD15 zero calls), 53/53 under TasksMax=256, security PASS (MEDIUM stub-first-on-PATH queued in TODO shortcut). 4c merge pending user. - 2026-11-06: 4c merged ddb04f4. /bugfix safety-residuals (bugfix/safety-residuals): 5 items 9b3961e d93f06c dc5f127 97c6afc c5bd0f8 + gate round 7ca6b18; plan r3 after 3 lenses + confirm (0 BLOCKER, 8 MAJOR folded); GATE 0 MET, verifier ECARTS(2) → CONFORME, security PASS x2. BLK-045, BDR-139, LRN-265/266. Merge on signal; 4d next. + +## 2026-11-08 +- 2026-11-08: 4d memory feedback built on feature/memory-feedback (8 tasks SDD; plan r1 FATAL(7) → r2 → confirm FATAL(4) → r3; final review I1 locals + I2 per-trigger n; gate 2 hardening x2: checkDir fail-closed, items.json validated, safe repo path). make test green, GATE 0 MET, security PASS 0 findings; live record zenquality cands 11 ms 1408. BDR-140, LRN-267/268. Merged on user signal before GATE 1; live run + verifier after. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index c8e1a47..047ac51 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -1978,3 +1978,15 @@ Rule: when editing a doctrine file under structure locks, grep the test's lock s - **Pattern**: before adding a guard rule for a new form, bench whether EXISTING rule already covers it. Claude Code permission `*` spans spaces: `Bash(rtk read */.env*)` already denies `rtk read -n sub/.env` (`*` = `-n sub`); only root-level target escaped → 2 rules, not 20. Bench row must test old rule on new cmd (proves need), not new rule alone (proves only match). Also gate on `sent` column = intended cmd (model may reorder args). Path allowlists over git output: `--name-only` lists rename destination only → use `--no-renames` so source path is checked. - **Context**: bugfix/safety-residuals 2026-11-06: plan r1 had 20 deny lines, simplicity + correctness lenses cut to 2; bench R3-R7 (results.tsv). Pre-commit allowlist c5bd0f8 T21f rename case. - **Future use**: every deny/ask addition (BDR-136 bench) and every path-based guard: (1) row with existing rule × new form first, (2) rename case in allowlist tests. + +## LRN-267 — Claude Code transcript join facts: -context toolUseID, blob replays, agent-.jsonl (2026-11-08) + +- **Pattern**: Claude Code transcript facts for joins: `tool.call` hook attachment `toolUseID` = `-context` (strip suffix before matching tool_use/tool_result); `api-request-blob` records replay earlier tool_result blocks → read only `assistant`/`user` records, dedupe tool_result by id; sub-agent transcript = `/subagents/agent-.jsonl` (same id mod logs in `agent`); `prompt.submit` additional context lands as `attachment.type hook_additional_context`, ~0.1-3 s after hook time; composer prompts carry `origin.kind human`. +- **Context**: phase 4d reader (lib/memory-feedback/transcripts.ts); r1 plan matched `toolUseID` verbatim → every tool item would join empty on real data, synthetic fixture passed. +- **Future use**: any transcript reader/bench: check these shapes on real files (field names only) before writing the join; fixture uses `-context` ids and a blob replay. + +## LRN-268 — Assumed fixtures pass their own tests; plan constraints must copy the user's limits verbatim (2026-11-08) + +- **Pattern**: fixture built from assumption passes its own test → BLOCKERs hide until a challenger reads real data or existing tests. 4d: `-context` toolUseID (real transcripts) and IR11 strict toEqual (existing kit test) both caught only by challenge passes, not by plan TDD. Second: plan "Global Constraints" must copy the user's global limits verbatim; 4d plan dropped "5 locals" → executors complied with the plan, final review flagged I1, extra fix round. +- **Context**: feature/memory-feedback 2026-11-06..08: r1 FATAL(7), r2 confirm FATAL(4), final review I1/I2, gate 2 three MEDIUM + one MEDIUM on re-scan. +- **Future use**: plan challenge brief asks correctness lens to verify fixture shapes against real data and to grep existing tests asserting changed records; writing-plans Global Constraints = paste CLAUDE.md limits line verbatim. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index 7b6a9bc..b057cfc 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -115,9 +115,10 @@ Shared rules for every phase: - **4b capture (mod).** Failure ledger: tool results with isError, deny or non-zero exit carrying a distinctive error line → normalized + verbatim + command, REDACTED at capture (rtk-rewrite redaction + gitleaks patterns), bounded ring per session in `$.store` (4 MiB cap), matched against the registry error index; unmatched = new failure modes. Milestones: feat/fix commit, `gitflow finish`, a suite red then green. `memory_pending` tool returns unmatched failures + milestones; /capitalize, /close and every CAPITALIZE step call it first; one context note at the next prompt after a milestone, never per turn, never at Stop. "Proactive capitalization" paragraph KEPT. Writing always = model draft + user approval + lib/memory.sh. - Built 2026-11-04 on feature/memory-capture (f1d4f9d..HEAD): mod `mods/memory`, kit 100+ cases, consumers wired, noise measured (NOISE.md); merged 2026-11-04 into develop (dfadf8a): GATE 0 MET, verifier criteria 1-15 met (9 proven live), security PASS ×4, BDR-137 - [x] shortcut (done in 4c, Task 1: the lexical reader is gone, statuses come from `memory.sh index`): `mods/memory/hooks/register.ts` `isSuperseded` is a lexical reader, not memory.sh's status parser; upgrade = share that parser when 4c needs it (final review M11) - - **4c read side (built 2026-11-05 on feature/memory-recall, merge pending).** Two channels only: intent recall at `prompt.submit` for classifier labels design/analysis or the first coding prompt after idle (BM25 top-30 over title + lesson + body → haiku keeps ≤3, bounded 3 s, fail open) and tool-error 4-gram match (PostToolUse; a classic hook is acceptable if the mod ledger is not needed). Session digest (open BLK via the status parser, actionable TODO, last journal line) in `hooks/session-start.sh` on `source: startup|compact|clear` (native matchers; the mod's `session.compact` only skips); a SubagentStart twin if sub-agents need it. Injection = ID + title + lesson line; superseded never injected; budget ~1.5k chars per turn; once per context. Deferred: Read path triggers, Bash command triggers, "critical → deny once", Tier 1, cross-repo scope=global index, `memory_search` tool. + - **4c read side (built 2026-11-05 on feature/memory-recall, merged 2026-11-06 ddb04f4).** Two channels only: intent recall at `prompt.submit` for classifier labels design/analysis or the first coding prompt after idle (BM25 top-30 over title + lesson + body → haiku keeps ≤3, bounded 3 s, fail open) and tool-error 4-gram match (PostToolUse; a classic hook is acceptable if the mod ledger is not needed). Session digest (open BLK via the status parser, actionable TODO, last journal line) in `hooks/session-start.sh` on `source: startup|compact|clear` (native matchers; the mod's `session.compact` only skips); a SubagentStart twin if sub-agents need it. Injection = ID + title + lesson line; superseded never injected; budget ~1.5k chars per turn; once per context. Deferred: Read path triggers, Bash command triggers, "critical → deny once", Tier 1, cross-repo scope=global index, `memory_search` tool. - 4c follow-up from the 4b live proof (2026-11-04): `memory_pending` lists milestones of the current session only, so a `/capitalize` run right after `/clear` misses the previous session's `fix:`/finish milestones (they stay in the store). Option: list earlier-session milestones marked `(earlier session)`. Doctrine (capitalize before /clear) covers the normal path. - - **4d feedback and promotion.** Plan r1 (draft, not challenged): `.claude/tasks/plans/2026-11-05-memory-feedback-4d-1834.md`. Log read 2026-11-05: 1 real record, no decision possible; it cannot show usefulness or misses alone and transcripts live 7 days. Order: 4d.1 log fields `cands` + `ms` → 4d.2 weekly reader (log × transcripts, labels.tsv) → 4d.3 gate (≥20 prompt + ≥10 tool injections, or 5 weeks) with thresholds fixed now → 4d.4 /prune-memory + BDR-100 promotion, conditional. Starts after the 4c merge; 4 open choices in the plan. + - **4d feedback (4d.1-4d.3 built 2026-11-08 on feature/memory-feedback, BDR-140, merge on signal).** Mod logs `cands`+`ms`; bun reader `lib/memory-feedback/`; `/memory-feedback` skill; banner reminder; two gates (prompt 20 or 35 d, tool 10 or 35 d +1 extension). Plan r3 `docs/superpowers/plans/2026-11-06-memory-feedback.md` (purged at finish; git keeps it), contract `.claude/tasks/contracts/2026-11-06-memory-feedback-4d-1825.md`. 4d.4 (/prune-memory step D, BDR-100 promotion) stays conditional: built only when a gate reports a noisy entry or a promotion candidate. + - [ ] 4d follow-ups (final review + task reviews 2026-11-08, non-blocking): transcript cache holds every parsed file per run (~1 GB at steady state: process per (root, session, agent) and drop); image prompts (array content) become `lost` (counted); no boundary tests for the threshold actions (3rd pick, late, tool, miss, noisy/promotion, idle tie-break), eviction note, torn count, toolItem; `replyAfter` hides `seen.add` in a filter; no `tsc` type check on lib/memory-feedback; labels.ts minors (fromLine checks column count only, readState accepts non-object JSON, .bak keeps one state, misleading error on an entry label with a cause). - [ ] shortcut: the injection log lives under `l:` store keys (about 28 KiB each, 200 records and 64 KiB at most); `sweepLogs` counts them with the `p:` keys and evicts the oldest log key (by its newest record, never the current root's) once the total nears the engine's 4 MiB store cap; upgrade = one global log key or a smaller per-root cap (`mods/memory/hooks/register.ts`). - [x] residual: the pre-existing `memory.sh check` call in `hooks/session-start.sh` is not time-bounded (the digest's `memory.sh index blocker` call is); upgrade = wrap it in `timeout 2`. Done 2026-11-06 d93f06c (SD16). - [x] BLK-043 hotfix merged 2026-11-06 (`bd5e661` main, `7e47bea` develop, back-merged into feature/memory-recall `3564e3e`, worktree removed).