From 0b6443011d5c54d59864b79aebfa0963d9065178 Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 25 Oct 2026 01:46:01 +0200 Subject: [PATCH] chore(memory): routing guard, listing budget, phase order; BDR-125 amendment 5 --- .claude/memory/decisions.md | 1 + .claude/memory/journal.md | 3 +++ .claude/tasks/TODO.md | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.claude/memory/decisions.md b/.claude/memory/decisions.md index 1f05e5b..8f0a9a7 100644 --- a/.claude/memory/decisions.md +++ b/.claude/memory/decisions.md @@ -1501,4 +1501,5 @@ Branch feature/user-writing-web-rules, UNMERGED (human gate). - **Amendment 2 (2026-10-24, user: full memory redesign allowed)**: phase 4 = memory v2 (write + capture + read + feedback), measured on 434 entries: capture is the weak link (5/7 real errors of 2026-10-23 had no entry), not search; haiku rerank of lexical top-30 = 14/22 vs BM25 9/22 on real FR prompts; error 4-gram match exact (429 → BLK-030/031). Storage: augment in place + Meta line + generated Index + single writer `lib/memory.sh` + pre-commit validator (Edit-level guard rejected: real writes go through Bash/python). One-file-per-entry rejected for now (44 citers + 8 project migrations for concurrency/history gains a validator+backfill mostly match). Registry guard moved from phase 2 to 4a; 4a needs no mod. - **Amendment 3 (2026-10-24, challenge of phase 1)**: phase 1 = native context diet, no mod. Proven: `paths:` rules load on Read (not on Write of a new file), `autoMemoryEnabled: false` drops the auto-memory section, classic SessionStart/UserPromptSubmit hooks inject context, instruction files reload on compaction natively. Each section goes to the carrier matching its trigger (path rule, hook, skill body, setting, or compression once enforced by 4a/phase 2). Same ~4.4k gain, no mod code, works with mod off. Mod marker subtraction kept only as fallback if a native carrier fails a canary. Fingerprint moves to phase 3. - **Amendment 4 (2026-10-25, challenge of phase 2 + profile facts + user answers)**: phase 2: phrase-list merge gate rejected (3 lenses FATAL: false allows/denies, breaks BDR-068 ritual + release sub-agent) → `$.ui.ask` confirmation dialog per branch (user pick), named exceptions, prefilter before `.catch`, hard_deny extended; commit limit → `commit-msg` git hook (CLAUDECODE-gated); code limits → classic PostToolUse on added lines, 80 cols only; G2 removed (BLK-022). Phase 5 = native packs: per-project `.claude/settings.local.json` `enabledPlugins` and per-conversation `claude --settings` proven concurrent (same and different projects); skills-dir plugins obey; plugin skills keep short names; plugin agents need prefix → agents stay global (user); global profile mode deleted (user); 11 profiles kept as pack compositions (user); detection proposes once (user); off pack mid-skill → propose + `/reload-plugins` (spike). User-scope MCP not switchable per project → MCP into packs. +- **Amendment 5 (2026-10-25, routing verification + user picks)**: routing probe bench (`.claude/tasks/plans/2026-10-25-routing-probe/`): fresh sessions route explicit intents right (init-project, close, bugfix, reconcile, commit-change, cso), but a small feature ask was coded inline and history shows 11/21 code-writing bug/feature turns inline. User: always through a skill → phase 2 routing guard (main-loop code write outside a skill run denied; docs, `.claude/**`, sub-agents, in-skill writes free; ceiling bullet rewritten model-agnostic). Interviewer: by design inline in /init-project (C1 routed right), unused only because no new project in the window. Listing: 46/124 skills name-only; `SLASH_COMMAND_TOOL_CHAR_BUDGET=60000` → 0 name-only (+~17k chars); raise after packs (user). Order: 0 → 4a → 1 → 5 → 2 → 3 → 4b-4d (user). diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index de51ba7..29054e0 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -645,3 +645,6 @@ rules: - /reconcile TODO (chore/todo-reconcile): 2190 → ~200 lines. Done history pre-10-08 dropped (git archive), 46 open → 35 grouped (actionable, release 3.0.0, docs, user, blocked, live checks, optional, parked, known limits). Done: P16, P43, Linux run, Makefile help; obsolete: effort-pins items, fable live check; 5 hidden prose follow-ups lifted. BLK-018 status line: decide at 3.0.0. Engine gap: `reconcile_blk_open` ignores header `[resolved]` tag (BLK-032..034 false open). - Rules check (user: facts not guesses): fresh `claude -p` in empty dir quoted always-on rules + global CLAUDE.md verbatim, negative control ABSENT; path-scoped web-security/rest-api ABSENT before, present after Read of src/api/user.ts. /hotfix settings deny: `* :*` and `* -v /:*` mixed forms never match (proven RAN), `Write(...)` deny never blocks Write tool, `Edit(...)` does; added `-v /:/*` + ` :**` (proven DENIED), additive per T41/T42 lock. Gate 429 on Fable twice (LRN-224). make test green, auditor PASS. - Context-mod research (user: move doctrine into mods): probe mod proved prompt.context/compose/section/submit/attachment + tool.call context levers; /context 30.2k always-on. BDR-125 supersedes BDR-031, phases 0-4 planned as future /ship-feature. + +## 2026-10-25 +- Context-mod plan hardened: phase 2 challenged (3 lenses FATAL) → $.ui.ask merge gate, commit-msg git hook, added-lines 80-col hook, G2 out; phase 5 = native packs, per-project settings.local + per-conversation --settings proven concurrent; routing probe: explicit intents route right, small feature coded inline, 11/21 history code turns inline → routing guard (user: always via skill); 46/124 skills name-only, budget env fixes it (after packs). Order 0 → 4a → 1 → 5 → 2 → 3 → 4b-4d. Side: faunosteo TODO has stale follow-ups (ZodError msg gone since R4.7, SVG sanitiser done since R5.5): run /reconcile there. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index b711710..0cd2915 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -3,7 +3,7 @@ ## Open (reconciled 2026-10-23, /reconcile) Done history before 2026-10-08 removed 2026-10-23 (git keeps it: `git log -p -- .claude/tasks/TODO.md`); decisions live in `.claude/memory/`. -### Context mod queue (BDR-125): one /ship-feature per phase, order (user 2026-10-24): 0 → 4a → 1 → 2 → 3 → 4b-4d → 5 +### Context mod queue (BDR-125): one /ship-feature per phase, order (user 2026-10-25): 0 → 4a → 1 → 5 → 2 → 3 → 4b-4d Shared rules for every phase: - Baseline first: `claude -p "/context"` at repo root (2026-10-23: 30.2k always-on = memory files 11.6k, skills 10k, agents 2.6k, system 2.5k, MCP instr 2.2k, tools 1.1k). Same measure after; the delta is a phase criterion. - Proof bench: `.claude/tasks/plans/2026-10-24-context-mod-probe/` (canary per lever + negative control, fresh `claude -p --plugin-dir`). Every lever a phase uses is re-proved there before code, every "to verify" below becomes a canary criterion. @@ -42,6 +42,7 @@ Shared rules for every phase: - [ ] **Phase 2, guards** (redesigned 2026-10-25 after a 3-lens challenge: correctness FATAL(10), robustness FATAL(13), simplicity FATAL(6); plan `.claude/tasks/plans/2026-10-24-context-mod-phase2.md`) - Killed by the challenge: the phrase-list merge gate (false allows: "don't merge it yet", "should we merge it?", pasted text, skill bodies in the transcript; false denies: a plain "oui"; it blocked the BDR-068 /close auto-finish and the release-executor sub-agent finish; "ship it" contradicts the doctrine); G2 destructive guard (BLK-022: the content is withheld, not the language; stays a user-driven task with its two listed options); whole-file code-limit reports (measured 1498 lines > 80 cols across 92 files, lib/gitflow.sh 81: over-fires, LRN-091); parsing commit text from Bash (heredoc `-m "$(cat <<'EOF' …)"`, `-F`, `-C`); registry format (in 4a). - Merge gate (user pick 2026-10-25: confirmation dialog). Mod `tool.call` on Bash|Monitor matching `gitflow.sh finish`, `gitflow_finish`, or `git merge` while develop/main is checked out → `$.ui.ask("Merge → ?")`, one per branch, single use; dismissed, rejected, `-p`, or no surface → deny with reason "confirm at the terminal, then re-run". Named exceptions: BDR-068 ritual (this turn's prompt.submit command is capitalize or close, `gitflow.sh start chore ` seen this session, diff touches only `.claude/**`); release path in a decision table (verify that `$.ui.ask` works for a sub-agent's tool.call; else /release-candidate runs finish inline, BLK-018 option b). Cheap synchronous prefilter before the `.catch` deny, so a guard bug never denies every Bash call. Banner or doctor line when the guard is not live. settings.json hard_deny names mod refusals and the mod disarm paths (`mods//` sources, `~/.claude/.json` `"enabled": false`, `enabledPlugins` `@skills-dir`, dev-copy shadow). The finish prose stays until canaries pass across sessions. This is the first piece of the context mod. + - Routing guard (user pick 2026-10-25: "always through a skill"). Measured: "j'aimerais que doctor.sh affiche la version de rtk" was coded inline with no skill (routing probe L3); history 2026-09-23 → 10-24: 10 code-writing bug/feature turns went through a skill, 11 coded inline (long pasted faunosteo briefs). Mod `tool.call` on Edit/Write/NotebookEdit of a code file by the MAIN loop (no `agentId`) while no skill run is active (model-router run slot or a `skill.prompt` seen this turn for feat/bugfix/hotfix/ship-feature/refactor/code-clean/tour…) → deny with reason "route through /hotfix (≤2 files, obvious), /feat, /bugfix or /ship-feature". Free: docs (.md), `.claude/**`, sub-agents (executors), any write inside a skill run. Doctrine follows in the same change: the ceiling bullet becomes "the main loop writes no code outside a skill run, whatever the model". Proof: routing bench `.claude/tasks/plans/2026-10-25-routing-probe/` cases (L3 must now enter a skill), long-brief replay in a clone, false-deny fixtures (doc edits, executor edits, in-skill edits). - Commit message: `commit-msg` git hook emitted by the gitflow hook generator (global core.hooksPath, T10 drift test), active only when `CLAUDECODE=1`, words counted with trailers excluded, limit read from lib/commit-message.md (one place), exemption only on deterministic convention files (commit template, .gitmessage, commitlint config). A failure is a git error to fix by shortening, not a permission refusal. - Code limits: classic PostToolUse hook, added lines only (Edit new_string, Write content), our code only (`lib/code-origin.sh` on the edited file's repo), 80 columns only, at most 5 reports, once per file per turn, `additionalContext`, never a deny. Function length deferred (or the project's own linter rule). - Proof: an evasion matrix per rule (quoting, cd and -C, bash -c, heredoc, Monitor, sub-agent, non-composer turn); false-allow fixtures for the gate (negation, question, paste); the /close ritual still finishes; the release decision table is tested; destructive commands are never run live (plugin test with stubs only). @@ -77,6 +78,7 @@ Shared rules for every phase: - Profile = `lib/profiles/.profile` → generated `~/.claude/profiles/.json` (`{"enabledPlugins": {...}}`). Per project: `profile.sh set ` writes `enabledPlugins` into the cwd project's `.claude/settings.local.json` (never user scope; gitignore line checked). Per conversation: launcher `claude --settings ~/.claude/profiles/.json` (shell function or `make` helper, named with the user), wins over the project default for that conversation only. - Detection: session-start hook reads the fingerprint (stack, web public vs app, supabase, messaging, graph; from phase 3, or a minimal shell version here) when the project has no profile and proposes one in one line; writing it needs the user's yes. - Pack needed mid-skill: orchestrators' existing gates (lib/design-gate.md + design-tool-gate.sh, lib/plugin-gate.md) check the required packs; off → propose enabling for this conversation/project + `/reload-plugins`; spike that a settings change + `/reload-plugins` loads the pack mid-session. + - Listing budget (user pick 2026-10-25: after the packs): measured 124 skills listed, 46 name-only at the default budget (incl. tour, seo, web-validate, status, profile, plugin-check, review, qa, spec, test-driven-development); `SLASH_COMMAND_TOOL_CHAR_BUDGET=60000` → 0 name-only, listing 30k → 47k chars (~+5.7k tokens). Once packs shrink the listing, set the budget in settings.json `env` to the smallest value that leaves 0 name-only in the full profile (measured with the ctxprobe bench), and record the cost. - Spikes listed: nested skills in a pack, `/reload-plugins` after a settings change, claude.ai connectors per project (interactive session only), user-scope MCP moved into packs (higgsfield first). - Proof: two concurrent conversations in one project and two projects, canaries prove different listings, MCP and hooks per pack; `/context` per profile; old global toggling gone and nothing references `skills-disabled/`. - Cleanup: `lib/profile.sh` symlink toggling + `skills-disabled/` (24 entries), user-scope plugin toggling in `set|apply|reset`, Makefile `profile*` targets rewired, `/profile` skill rewritten for packs, plugin-gate prose tied to global toggling, banner hint "/plugin-check before starting a new project", doctor profile checks, profile tests rewritten; `lib/profiles/*.profile` stay as the definitions.