diff --git a/.claude/tasks/contracts/2026-10-27-memory-v2-write-2030.md b/.claude/tasks/contracts/2026-10-27-memory-v2-write-2030.md index 41fa4c6..8231fe5 100644 --- a/.claude/tasks/contracts/2026-10-27-memory-v2-write-2030.md +++ b/.claude/tasks/contracts/2026-10-27-memory-v2-write-2030.md @@ -18,7 +18,7 @@ Phase 4a of the context mod queue (BDR-125), TODO.md "Phase 4a, memory v2 write 5. `memory.sh check [--staged]` validates: heading shape, ID uniqueness, v2 marker present, no `## Index` block in a v2 file; `--staged` also refuses a removed line inside an existing entry. It runs inside `add` and in `make test`; the generated pre-commit hook is untouched. 6. One shared status parser (lib function used by memory.sh and lib/reconcile.sh): candidates are the entry's own header `[tag]` and labelled status lines only (never a free word in prose); the last candidate in document order wins. `reconcile_blk_open` on a fixture holding BLK-032..034 as written today returns none of them; the existing run-reconcile T1/T2 stay green. 7. The four `## Index` blocks of this repo's registries are removed in one deterministic step; every status or supersession that lived only in an Index row is first materialized as a status line in the entry body (oracle: parser(body) == former Index status for every such row); heading count unchanged. -8. Per-file v2 marker: every registry of this repo and every `templates/memory/*.md` carries it; a file without it is v1: the writer still appends, `check` reports it, and the per-project session banner warns `registry v1`. +8. Per-file v2 marker: every registry of this repo and the four registry templates `templates/memory/{decisions,learnings,blockers,evals}.md` carry it (journal is not a registry: no marker); a file without it is v1: the writer still appends, `check` reports it, and the per-project session banner warns `registry v1`. 9. Citers patched in the same branch: capitalize, close, prune-memory (§ D removed, STEP 3 status carrier = `memory.sh status`, STEP 4 verify = `memory.sh check`), CAPITALIZE steps of feat/bugfix/hotfix/ship-feature/commit-change, init-project, lib/capitalize-commit.md (rc 5 documented), lib/analyze-before-plan.md, lib/reconcile.sh, templates/memory, onboard; doctrine-citers census green. 10. CLAUDE.global.md "Memory registries": writes go only through `lib/memory.sh`; the "Registries load every session" premise replaced; the heading and the bold label `Always English, always caveman` kept (census); file line count not above today's 333. 11. Dropped, must NOT appear: Meta line, 434-entry backfill, scope/critical labels, triggers field, English validator. diff --git a/docs/superpowers/plans/2026-10-27-memory-v2-write.md b/docs/superpowers/plans/2026-10-27-memory-v2-write.md index f781f24..681873e 100644 --- a/docs/superpowers/plans/2026-10-27-memory-v2-write.md +++ b/docs/superpowers/plans/2026-10-27-memory-v2-write.md @@ -2,89 +2,93 @@ > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. -**Goal:** `lib/memory.sh` becomes the only writer of `.claude/memory` registries, one status parser serves memory.sh and reconcile, this repo's registries move to v2 (no `## Index`), every citer writes through the lib. +**Goal:** `lib/memory.sh` becomes the only writer of `.claude/memory` registries, one status parser and one classifier serve memory.sh and reconcile on v2 registries, this repo's registries move to v2 (no `## Index`), every citer writes through the lib. -**Architecture:** One sourceable bash lib on the `lib/project-rules.sh` skeleton (`-C `, verbs, rc 2 + named reason). The awk status parser lives once in `_MEM_AWK` and is shared by `index`, `upgrade` and `lib/reconcile.sh`. Writers serialize through a noclobber lock file in the git common dir. `memory-commit.sh` runs `check --staged` as the chokepoint. +**Architecture:** One sourceable bash lib on the `lib/project-rules.sh` skeleton (`-C `, verbs, rc 2 + named reason). The awk parser lives once in `_MEM_AWK` and is shared by `index`, `upgrade` and `lib/reconcile.sh` (v2 files). Writers serialize through a noclobber lock file in the git common dir. `memory-commit.sh` runs `check --staged` as the chokepoint. Revision r2 (2026-10-28) after a 3-lens challenge: FATAL(2) simplicity, CONCERNS(5) robustness, FATAL(6) correctness, every BLOCKER and MAJOR closed below. -**Tech Stack:** bash 5, POSIX awk (no gawk-only features, no `{n}` intervals), git. Tests via `make test`. +**Tech Stack:** bash 5, POSIX awk (no gawk-only features, no `{n}` intervals, no byte-count slicing around `—`), git. Tests via `make test`. **Spec:** `docs/superpowers/specs/2026-10-27-memory-v2-write-design.md` (user-approved 2026-10-27). Contract: `.claude/tasks/contracts/2026-10-27-memory-v2-write-2030.md`. -**Reference implementation (proven before this plan was written):** `docs/superpowers/plans/memory-v2-write/` holds `memory.sh`, `memory.test.sh` and `blockers-v2-status.md`. They were run in a mock repo: suite `PASS=72 FAIL=0` five runs in a row, shellcheck clean, no line over 80 chars; `upgrade` on a copy of this repo's live registries is oracle-green, `check`-green, idempotent, and its diff passes `check --staged`. Task 1 copies them; do not rewrite them. +**Reference implementation (proven r2):** `docs/superpowers/plans/memory-v2-write/` holds `memory.sh`, `memory.test.sh`, `blockers-v2-status.md`, `blockers-v1-dialects.md`. Proven in a mock repo: suite `PASS=97 FAIL=0` five runs in a row and under `LC_ALL=C`, shellcheck clean, no `# shellcheck disable`, no line over 80 chars. `upgrade` on a copy of this repo's live registries: oracle-green, `check`-green, idempotent, its diff `--staged`-green, 26 statuses and 129 dates materialized, one Index status dropped and named (BDR-012). Task 2 and Task 3 code below was applied to a `git clone --shared` of this repo and run through `make test`. Task 1 copies the files; do not rewrite them. ## Global Constraints - Branch `feature/memory-v2-write` (already started, spec at cdc0a47). Never switch, never merge, never push by hand (hooks push). -- Our code: functions ≤ 25 logic lines (an embedded awk program counts as one statement), ≤ 5 locals, ≤ 5 params, lines ≤ 80 chars in `lib/*.sh`. +- Our code: functions ≤ 25 logic lines (see Deviations for awk programs), ≤ 5 locals, ≤ 5 params, lines ≤ 80 chars in `lib/memory.sh`. - No `# shellcheck disable` anywhere in the diff (floor guard, LRN-234). `# shellcheck source=/dev/null` directives are allowed. - `/usr/bin/grep` pinned in libs (`MEM_GREP`, LRN-074); no `grep -q` reading a pipe under pipefail (LRN-189); no `sed -i`, `stat -c`, `realpath -m`, `grep -P` (portability census, BDR-110). - No recursive delete through a variable except the existing `trap 'rm -rf "$FIX"' EXIT` mktemp pattern. - Hermetic tests run through `make test [suite=…]` only. -- Census-cited strings stay byte-identical: every `CLAUDE.md "Memory registries" (Always English, always caveman)` citation, the CLAUDE.global.md heading `## Memory registries (\`.claude/memory/\`)` and the bold label `**Always English, always caveman**` (doctrine-citers, LRN-166). Single-line fixed strings: do not rewrap a line that holds one. +- Census-cited strings stay byte-identical: every `CLAUDE.md "Memory registries" (Always English, always caveman)` citation, the CLAUDE.global.md heading `## Memory registries (\`.claude/memory/\`)` and the bold label `**Always English, always caveman**` (doctrine-citers, LRN-166). Do not rewrap a line that holds one. - CLAUDE.global.md line count must not exceed 333 after the edit. - Worked examples use fictional 9xx IDs (LRN-073). - Entry text written to registries is English caveman (BDR-009). -## Deviations from the spec (found while proving the reference) +## Deviations from the spec (named for the human gate) -- Lock = a file created under bash noclobber, not a `mkdir` dir: uutils `mkdir` 0.10 on this host is not atomic (5 concurrent adds lost 2-4 entries). Same path (`/memory.lock`), same 30 s steal. -- `journal` takes no `--date` flag: `MEMORY_DATE` already pins the date for tests; YAGNI. -- `upgrade` writes an Index status into the body only when the body has none, or when the Index says superseded/deprecated and the body does not. Otherwise the body wins: the Index is the stale copy (BDR-012: Index accepted, body shipped). Status words rank in `_MEM_WORDS` order with `open` last, measured on the live registries: identical verdicts to today's reconcile on every blocker except BLK-032..034. +1. **Lock** = a file created under bash noclobber (`open(O_EXCL)`), not a `mkdir` dir: uutils `mkdir` 0.10 on this host is not atomic (5 concurrent adds lost 2-4 entries). Same path, same 30 s steal; the steal renames the stale lock to a private name before removing it, never `rm` on the shared path. Released by an INT/TERM/HUP trap (an interrupted `add` also restores its backup), not an EXIT trap: a sourced lib must not own the caller's EXIT. +2. **`journal` takes no `--date`**: `MEMORY_DATE` already pins the date for tests. +3. **`upgrade` body wins**: an Index status reaches the body only when the body has none, or when the Index says superseded/deprecated and the body does not. Every other conflicting Index status is dropped and named on stderr (`memory: BDR-012: kept body shipped, dropped Index accepted`, the only one on this repo). +4. **Status word**: a lib-written `**Status (YYYY-MM-DD…)**:` line reads its leading word (`status` requires the text to start with one: "open, reopened by abc"); other labelled lines rank words in `_MEM_WORDS` order, `open` last ("accepted. check OPEN" = accepted). A heading candidate is its `[tag]` only, never the title. +5. **One classifier on v2, the lexical reader kept on v1**: on a v2 registry reconcile classifies by word (`memory_closed`: resolved | superseded | deprecated); `accepted` on a blocker stays open. On a v1 registry reconcile keeps today's lexical reader verbatim: the strict parser, measured on copies of all 13 other projects' blockers, changed the open set of 4 (config `— RESOLVED` title suffix, game `date: … · status:`, zenquality and angelscar356 `**Statut** :`); with the v1 branch the 13 sets are identical to today. +6. **Heading dialects**: `mem_key` accepts `## ID` followed by any non-alphanumeric char (` — `, ` - `, ` | `), so `status` and `--supersedes` work on v1 hyphen and pipe files. The em-dash shape check is v2-only. `upgrade` refuses a non-em-dash file (`heading dialect " - ": not upgraded`) and a file without frontmatter; the banner says `memory.sh check`, never promises an upgrade. +7. **Journal template** carries no `format: 2`: journal.md is not a registry (`check` excludes it). Contract criterion 8 says "every `templates/memory/*.md`": the four registry templates. +8. **awk programs**: an embedded awk program counts as one statement toward the 25-logic-line limit (`_mem_upgrade_text`, `_mem_upgrade_oracle`, `_mem_index_rows` hold 20-30 awk lines). Splitting them would scatter one parser across files. ## Review Focus -1. **Concurrent writers.** Two sessions capitalizing at once must get two IDs; a lock that is not atomic loses entries silently. Found while proving the reference: `mkdir` from uutils coreutils 0.10 (this host) is NOT atomic, two concurrent `mkdir` both succeed; the lock uses bash noclobber (`open(O_EXCL)`). T6e/T6f are the flip test (they were red with the mkdir lock). -2. **Status words in prose.** A Solution line saying "fail-open" or "`data:` OPEN" must never reopen a resolved blocker; "accepted. Behavioral check OPEN" must read accepted. Covered by T10b/c/e and run-reconcile T8. -3. **Index-only facts lost at upgrade.** 13 BDR statuses, 2 BDR + 2 BLK + 12 LRN supersessions and ~130 dates live only in Index rows today; a stale Index status (BDR-012 says accepted, body says shipped) must NOT overwrite the body. The upgrade oracle refuses on any loss; T9e pins the stale case. -4. **v1 projects keep working.** 13 other repos on this machine run this lib through `~/.claude/lib`; a v1 registry is written leniently, `check` never fails on it, `--staged` ignores it, memory-commit keeps committing it. T7e/f and the memory-commit v1 test pin this. -5. **The chokepoint must not block the upgrade commit itself.** Removing the Index (lines before the first entry) and inserting Date/Status lines are not "removed lines inside an entry". Proven on the live copy; Task 7 commits it through memory-commit.sh. +1. **Concurrent writers.** The noclobber lock is proven by T6e/T6f (red with the mkdir lock on this host). An interrupted add restores its backup and frees the lock. +2. **Status words in prose and titles.** "fail-open", "`data:` OPEN", a title saying "DNS resolved", "open again, not resolved by abc": T10b/c/h/i and run-reconcile T8a/b. +3. **Index-only facts at upgrade.** 13 BDR statuses, BDR-038 + BLK-019/020 + 12 LRN supersessions, 129 dates; a stale Index (BDR-012) never overwrites the body and is named. BLK-019/020 must read closed after Task 7 (superseded). +4. **v1 projects keep working.** 13 other repos run this lib through `~/.claude/lib`: v1 writes are lenient, `check` never fails on v1, `--staged` ignores v1, reconcile on v1 is byte-for-byte today's reader (Deviation 5), `status` works on hyphen and pipe headings (T10m-o). +5. **The chokepoint never blocks a legitimate commit.** Only NEW culprits count (a duplicate a merge left behind blocks neither `add` nor a staged append: T7i-k); the upgrade commit passes (Index lines sit above the first entry); a refused commit leaves nothing staged. --- -### Task 1: lib/memory.sh, its suite and the parser fixture +### Task 1: lib/memory.sh, its suite and the parser fixtures **Files:** - Create: `lib/memory.sh` (copy of `docs/superpowers/plans/memory-v2-write/memory.sh`) -- Create: `lib/tests/memory.test.sh` (copy of `docs/superpowers/plans/memory-v2-write/memory.test.sh`) -- Create: `lib/tests/fixtures/blockers-v2-status.md` (copy of `docs/superpowers/plans/memory-v2-write/blockers-v2-status.md`) +- Create: `lib/tests/memory.test.sh` (copy of `…/memory.test.sh`) +- Create: `lib/tests/fixtures/blockers-v2-status.md` (copy of `…/blockers-v2-status.md`) +- Create: `lib/tests/fixtures/blockers-v1-dialects.md` (copy of `…/blockers-v1-dialects.md`; used by Task 2) -**Interfaces:** -- Produces (sourceable, used by Tasks 2-7): `memory_entry_status ` (winning candidate line, rc 1 if none), `memory_status_word ` (status word or first 40 chars), `memory_check [--staged] []` (rc 2 on a culprit), `memory_add`, `memory_status`, `memory_journal`, `memory_index`, `memory_upgrade`. CLI: `bash lib/memory.sh [-C dir] add|status|journal|index|check|upgrade …`. Env: `MEMORY_DATE`, `MEM_GREP`, `MEM_LOCK_TRIES`. +**Interfaces (produced, used by Tasks 2-7):** `memory_entry_status ` (winning candidate: `[tag]` or the labelled line; rc 1 if none), `memory_status_word ` (status word or first 40 chars), `memory_closed ` (rc 0 for resolved | superseded | deprecated), `memory_is_v2 `, `_mem_names` (the four registry basenames, from `_MEM_TABLE`), `memory_check [--staged] []`, `memory_add`, `memory_status`, `memory_journal`, `memory_index`, `memory_upgrade`. CLI: `bash lib/memory.sh [-C dir] add|status|journal|index|check|upgrade …`. Env: `MEMORY_DATE`, `MEM_GREP`, `MEM_LOCK_TRIES`. -- [ ] **Step 1: Copy the three files** +- [ ] **Step 1: Copy the four files** ```bash cp docs/superpowers/plans/memory-v2-write/memory.sh lib/memory.sh cp docs/superpowers/plans/memory-v2-write/memory.test.sh lib/tests/memory.test.sh cp docs/superpowers/plans/memory-v2-write/blockers-v2-status.md lib/tests/fixtures/blockers-v2-status.md +cp docs/superpowers/plans/memory-v2-write/blockers-v1-dialects.md lib/tests/fixtures/blockers-v1-dialects.md chmod +x lib/memory.sh lib/tests/memory.test.sh ``` - [ ] **Step 2: Run the suite and the static checks** -Run: `make test suite=lib/tests/memory.test.sh` → expected last lines `PASS=72 FAIL=0` and `all suites green`. Run it three times (the race test T6e must be stable). +Run: `make test suite=lib/tests/memory.test.sh` three times → each ends `PASS=97 FAIL=0` and `all suites green` (T6e race must be stable). Run: `shellcheck lib/memory.sh lib/tests/memory.test.sh && awk 'length > 80' lib/memory.sh` → no output after shellcheck. Run: `make test suite=lib/tests/portability-census.test.sh` → green. - [ ] **Step 3: Commit** ```bash -git add lib/memory.sh lib/tests/memory.test.sh lib/tests/fixtures/blockers-v2-status.md +git add lib/memory.sh lib/tests/memory.test.sh lib/tests/fixtures/blockers-v2-status.md lib/tests/fixtures/blockers-v1-dialects.md git commit -m "feat(memory): lib/memory.sh single registry writer — add/status/journal/index/check/upgrade, shared status parser, noclobber lock" ``` --- -### Task 2: reconcile reads status through the shared parser +### Task 2: reconcile reads v2 status through the shared parser and classifier **Files:** -- Modify: `lib/reconcile.sh:57-67` (`reconcile_blk_current_status`) and its header comment `:8-12` -- Modify: `lib/tests/run-reconcile.sh` (new T8 block before the final summary line) +- Modify: `lib/reconcile.sh` (source line after `RECONCILE_GREP=`; `reconcile_blk_current_status` and `reconcile_blk_open` with their comments) +- Modify: `lib/tests/run-reconcile.sh` (T8 block before the final summary line) - Modify: `skills/reconcile/SKILL.md:25` -**Interfaces:** -- Consumes: `memory_entry_status` from Task 1. -- Produces: `reconcile_blk_current_status ` unchanged signature, now prints the winning candidate line (empty when none). +**Interfaces:** consumes `memory_is_v2`, `memory_entry_status`, `memory_status_word`, `memory_closed`. `reconcile_blk_current_status` and `reconcile_blk_open` keep their signatures. - [ ] **Step 1: Write the failing test** — insert before the `echo; echo "================ $pass GREEN` line of `lib/tests/run-reconcile.sh`: @@ -92,70 +96,84 @@ git commit -m "feat(memory): lib/memory.sh single registry writer — add/status echo; echo "=== T8 shared parser — header [tag] + labelled lines, prose never (BLK-032..034) ===" v2="$FIX/blockers-v2-status.md" open_v2=$(reconcile_blk_open "$v2" | cut -f1 | sort | tr '\n' ' ') -if [ "$open_v2" = "BLK-041 BLK-042 " ]; then ok "T8a open = {041,042}: 032..034, 008, 040 read resolved/accepted"; else no "T8a open = [$open_v2], expected {041,042}"; fi +if [ "$open_v2" = "BLK-040 BLK-041 BLK-042 BLK-043 BLK-044 " ]; then ok "T8a open = {040..044}: 032..034 and 008 closed, accepted stays open"; else no "T8a open = [$open_v2], expected {040,041,042,043,044}"; fi case "$(reconcile_blk_current_status "$v2" BLK-034)" in - *'[resolved]'*) ok "T8b BLK-034 status = its own header tag";; + '[resolved]') ok "T8b BLK-034 status = its own header tag, title never read";; *) no "T8b BLK-034 read from prose (fail-open), not the header tag";; esac +v1d="$FIX/blockers-v1-dialects.md" +open_v1=$(reconcile_blk_open "$v1d" | cut -f1 | tr '\n' ' ') +if [ "$open_v1" = "BLK-002 " ]; then ok "T8c v1 hyphen and pipe headings still parsed"; else no "T8c v1 dialects open = [$open_v1], expected {002}"; fi ``` -- [ ] **Step 2: Run it, expect red** +- [ ] **Step 2: Run, expect red** — `make test suite=lib/tests/run-reconcile.sh` → T8a and T8b red (today: 032..034 open, BLK-034 read from prose). -Run: `make test suite=lib/tests/run-reconcile.sh` → `RED ✗ T8a open = [BLK-032 BLK-033 BLK-034 BLK-040 BLK-041 BLK-042 ]…` (exact list may differ; it must be red). - -- [ ] **Step 3: Delegate the parser** — in `lib/reconcile.sh`, after the `RECONCILE_GREP=` line add: +- [ ] **Step 3: Implement** — in `lib/reconcile.sh`, right after the `RECONCILE_GREP=…` line add: ```bash -# the status parser is shared with lib/memory.sh (BDR-125 phase 4a) +# the status parser and classifier are shared with lib/memory.sh (BDR-125 4a) # shellcheck source=/dev/null . "$(dirname "${BASH_SOURCE[0]}")/memory.sh" ``` -and replace the whole `reconcile_blk_current_status` function and the two comment lines above it with: +Replace everything from the comment `# --- registry status: LAST status-bearing line wins …` through the closing `}` of `reconcile_blk_open` by: ```bash # --- registry status: LAST candidate wins (the BLK-008 trap A fell into) --- -# $1 blockers file, $2 id. Echoes the winning status line: the entry's own -# header `[tag]` or a labelled body line (lib/memory.sh); a status word in -# prose is never read (the BLK-032..034 false-open). Empty when none. +# $1 blockers file, $2 id. A v2 registry (lib/memory.sh): the entry's own +# header `[tag]` or a labelled body line, never a status word in prose or in +# the title (the BLK-032..034 false-open). A v1 registry keeps the lexical +# reader below: its dialects (title suffix `— RESOLVED`, `date: … · status:`, +# `**Statut** :`) carry status where the strict parser cannot see it. reconcile_blk_current_status() { - memory_entry_status "$1" "$2" + if memory_is_v2 "$1"; then memory_entry_status "$1" "$2"; return; fi + # v1: drop ALL `## BLK-` header lines first: the range is inclusive of the + # NEXT entry's header, and a sibling header may carry a status word. + sed -n "/^## ${2} /,/^## BLK-/p" "$1" \ + | "$RECONCILE_GREP" -v '^## BLK-' \ + | "$RECONCILE_GREP" -iE 'status|RESOLVED|REVERTED|upstream|resolved|[^a-z]open' \ + | tail -1 +} +# blockers whose CURRENT status does not close them → "idstatus". +# v2: memory_closed (resolved | superseded | deprecated); v1: the substring. +reconcile_blk_open() { + local id st v2="" + memory_is_v2 "$1" && v2=1 + for id in $(reconcile_enumerate_ids "$1" BLK); do + st=$(reconcile_blk_current_status "$1" "$id") + if [ -n "$v2" ]; then + memory_closed "$(memory_status_word "$st")" && continue + else + case "$st" in *RESOLVED*|*resolved*) continue ;; esac + fi + printf '%s\t%s\n' "$id" "$st" + done } ``` -In the header comment, insert one line right after line 12 (`# preaches — the recursive-coherence test (run-reconcile.sh T1) reds if this is broken.`): -`# v2 registries carry no Index at all (lib/memory.sh); v1 ones still may.` +Header comment: insert one line right after line 12 (`# preaches — the recursive-coherence test (run-reconcile.sh T1) reds if this is broken.`): `# v2 registries carry no Index at all (lib/memory.sh); v1 ones still may.` -- [ ] **Step 4: Run, expect green** +- [ ] **Step 4: Run, expect green** — `make test suite=lib/tests/run-reconcile.sh` → `28 GREEN / 0 RED` (T1-T7 unchanged, T8a/b/c green). `make test suite=lib/tests/run-review-guards.sh` → green (G4: T8 reads fixtures only). -Run: `make test suite=lib/tests/run-reconcile.sh` → `T8a`, `T8b` green, T1-T7 still green, `0 RED`. -Run: `make test suite=lib/tests/run-review-guards.sh` → green (G4: run-reconcile must not read `.claude/memory`; T8 reads the fixture). - -- [ ] **Step 5: Skill line** — `skills/reconcile/SKILL.md:25`, replace -`` (`reconcile_oracle_*`, `reconcile_blk_current_status` = last block wins) `` by -`` (`reconcile_oracle_*`, `reconcile_blk_current_status` = last candidate wins: header `[tag]` or a labelled status line, via `lib/memory.sh`) `` +- [ ] **Step 5: Skill line** — `skills/reconcile/SKILL.md:25`: replace `` (`reconcile_oracle_*`, `reconcile_blk_current_status` = last block wins) `` by `` (`reconcile_oracle_*`, `reconcile_blk_current_status` = last candidate wins: header `[tag]` or a labelled status line on a v2 registry via `lib/memory.sh`, today's lexical reader on v1) ``. - [ ] **Step 6: Commit** ```bash git add lib/reconcile.sh lib/tests/run-reconcile.sh skills/reconcile/SKILL.md -git commit -m "fix(reconcile): blocker status through the shared memory.sh parser — BLK-032..034 no longer false-open" +git commit -m "fix(reconcile): v2 blocker status through the shared memory.sh parser and classifier — BLK-032..034 no longer false-open; v1 reader unchanged" ``` --- -### Task 3: memory-commit.sh refuses a staged in-place edit (rc 6) +### Task 3: memory-commit.sh refuses a staged in-place edit or new culprit (rc 6) **Files:** -- Modify: `lib/memory-commit.sh` (header usage comment, `commit_memory` between `git add` and `git diff --cached --quiet`) -- Modify: `lib/tests/run-deterministic.sh` (two new tests before the summary) +- Modify: `lib/memory-commit.sh` (usage comment, `MC_MEMORY_SH`, `commit_memory` right after `git add`) +- Modify: `lib/tests/run-deterministic.sh` (block before the final `echo` + `printf 'RESULT: …'`) - Modify: `lib/capitalize-commit.md` (rc table) -**Interfaces:** -- Consumes: `bash lib/memory.sh check --staged .claude/memory`. -- Produces: `memory-commit.sh commit` rc 6 = check refused, nothing committed. - -- [ ] **Step 1: Write the failing tests** — read `lib/tests/run-deterministic.sh` first (helpers `new_repo`, `ok`, `ko`, `HELPER`); append before its final summary block: +- [ ] **Step 1: Write the failing tests** — insert right before the final `echo` / `printf 'RESULT: %d passed, %d failed\n' "$PASS" "$FAIL"` lines of `lib/tests/run-deterministic.sh`: ```bash echo "== check --staged chokepoint (v2 registry, phase 4a)" @@ -164,66 +182,62 @@ printf -- '---\nformat: 2\ntype: decisions_registry\nentry_prefix: BDR\n---\n\n# > "$d/.claude/memory/decisions.md" git -C "$d" add -A && git -C "$d" commit -qm v2 head_before=$(git -C "$d" rev-parse HEAD) -printf -- '---\nformat: 2\ntype: decisions_registry\nentry_prefix: BDR\n---\n\n## BDR-001 — rewritten (2026-10-27)\n- **Status**: accepted\n' \ - > "$d/.claude/memory/decisions.md" +sed 's/kept/rewritten/' "$d/.claude/memory/decisions.md" > "$d/x.tmp" \ + && cat "$d/x.tmp" > "$d/.claude/memory/decisions.md" out="$(cd "$d" && bash "$HELPER" commit "chore(memory): bad" 2>/dev/null)"; rc=$? -if [ "$rc" -eq 6 ] && [ -z "$out" ] && [ "$(git -C "$d" rev-parse HEAD)" = "$head_before" ]; then ok "in-place edit of a v2 entry → rc 6, nothing committed"; else ko "rc=$rc out=[$out] — in-place edit was committed or wrong rc"; fi +staged="$(git -C "$d" diff --cached --name-only)" +if [ "$rc" -eq 6 ] && [ -z "$out" ] && [ -z "$staged" ] && [ "$(git -C "$d" rev-parse HEAD)" = "$head_before" ]; then ok "in-place edit of a v2 entry → rc 6, nothing committed, nothing staged"; else ko "rc=$rc out=[$out] staged=[$staged] — in-place edit committed or left staged"; fi git -C "$d" checkout -q HEAD -- .claude/memory/decisions.md printf '\n## BDR-002 — added (2026-10-27)\nbody\n' >> "$d/.claude/memory/decisions.md" out="$(cd "$d" && bash "$HELPER" commit "chore(memory): BDR-002" 2>/dev/null)"; rc=$? if [ "$rc" -eq 0 ] && [ -n "$out" ]; then ok "append to a v2 registry → committed"; else ko "append refused rc=$rc"; fi ``` -(The existing tests write `baseline` registries with no frontmatter: v1, `check` skips them, they must stay green unchanged.) +(Existing tests write `baseline` registries with no frontmatter: v1, skipped by the check, unchanged and green.) -- [ ] **Step 2: Run, expect red** - -Run: `make test suite=lib/tests/run-deterministic.sh` → the rc 6 test fails (today rc 0, the edit is committed). +- [ ] **Step 2: Run, expect red** — `make test suite=lib/tests/run-deterministic.sh` → the rc 6 test fails (today rc 0, the edit is committed). - [ ] **Step 3: Implement** — in `lib/memory-commit.sh`: - - under `MC_PATHS=(...)` add: - -```bash -MC_MEMORY_SH="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)/memory.sh" -``` - + - after `MC_PATHS=(".claude/memory" ".claude/tasks")` add `MC_MEMORY_SH="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)/memory.sh"`; - in `commit_memory`, right after `git add -- "${changed[@]}"`, insert: ```bash - # Chokepoint (BDR-125 phase 4a): a staged v2 registry may only grow. An - # in-place rewrite of an existing entry is curation: /prune-memory, then - # /commit-change. v1 registries are skipped by the check. + # Chokepoint (BDR-125 phase 4a): a staged v2 registry may only grow and + # never gains a new culprit (duplicate ID, bad heading, open fence). v1 + # registries are skipped. Unstage on refusal so no later plain commit + # sweeps the refused change in. if [ -d .claude/memory ] \ && ! bash "$MC_MEMORY_SH" check --staged .claude/memory; then + git reset -q -- "${changed[@]}" echo "memory-commit: REFUSED — memory.sh check --staged failed (above);" \ - "NOTHING committed, the scoped paths stay staged." >&2 + "NOTHING committed, nothing left staged." >&2 return 6 fi ``` - - header usage line becomes `# memory-commit.sh commit "" # surgical commit; exit 0 ok/no-op, 3 unsafe state, 5 commit rejected, 6 check --staged refused` + - usage comment line becomes two lines: `# memory-commit.sh commit "" # surgical commit; exit 0 ok/no-op, 3 unsafe` / `# # state, 5 commit rejected, 6 check refused`. -- [ ] **Step 4: Run, expect green** +- [ ] **Step 4: Run, expect green** — `make test suite=lib/tests/run-deterministic.sh` → `RESULT: 18 passed, 0 failed`. -Run: `make test suite=lib/tests/run-deterministic.sh` → all green including the two new ones. - -- [ ] **Step 5: Document rc 5 and rc 6** — in `lib/capitalize-commit.md` step 3 "Report by (rc, mem_hash)", after the `rc 3` bullet add: +- [ ] **Step 5: Document rc 5 and rc 6** — `lib/capitalize-commit.md` step 3 "Report by (rc, mem_hash)", after the `rc 3` bullet: ``` - rc 5 → `git commit` rejected (hook, protected branch, signing); nothing committed, surface stderr. - - rc 6 → `memory.sh check --staged` refused: a staged - v2 registry rewrites an existing entry line - (only appends pass). Curation goes through - /prune-memory then /commit-change; surface - the culprit lines, never bypass the helper. + - rc 6 → `memory.sh check --staged` refused, nothing + committed, nothing left staged. Two causes, + named on stderr: a line removed inside an + existing v2 entry (only appends pass), or a NEW + culprit (duplicate ID, heading shape, open + fence). Fix the file, then commit the fix with + /commit-change; never bypass the helper. ``` - [ ] **Step 6: Commit** ```bash git add lib/memory-commit.sh lib/tests/run-deterministic.sh lib/capitalize-commit.md -git commit -m "feat(memory): memory-commit refuses a staged in-place edit of a v2 registry (rc 6); rc 5/6 documented" +git commit -m "feat(memory): memory-commit refuses a staged in-place edit or new culprit in a v2 registry (rc 6, unstaged); rc 5/6 documented" ``` --- @@ -231,10 +245,10 @@ git commit -m "feat(memory): memory-commit refuses a staged in-place edit of a v ### Task 4: v2 templates and the registry v1 banner line **Files:** -- Modify: `templates/memory/{decisions,learnings,blockers,evals}.md` -- Modify: `hooks/session-start.sh` (after the CLAUDE.global.md line-count guard, before `# Version check`) +- Modify: `templates/memory/{decisions,learnings,blockers,evals}.md` (journal.md unchanged, Deviation 7) +- Modify: `hooks/session-start.sh` (before `# Version check: compare local vs remote (non-blocking)`) - Modify: `lib/tests/memory.test.sh` (T13, before the final `echo "PASS=…"`) -- Modify: `agents/onboarder.md:126` (template description) +- Modify: `agents/onboarder.md:126` - [ ] **Step 1: Write the failing test** — insert before `echo "PASS=$pass FAIL=$fail"` in `lib/tests/memory.test.sh`: @@ -246,20 +260,15 @@ for t in decisions learnings blockers evals; do done banner() { (cd "$1" && SESSION_START_OFFLINE=1 bash "$ROOT/hooks/session-start.sh" \ /dev/null); } -check T13c-banner-v1 "$(banner "$FIX/v1-proj" | grep -c 'registry v1: 1 file')" 1 +check T13c-banner-v1 "$(banner "$FIX/v1h" | grep -c 'registry v1: 1 file(s) (memory.sh check)')" 1 check T13d-banner-v2 "$(banner "$FIX" | grep -c 'registry v1')" 0 ``` -and, just above it, the v1 fixture project: +(`$FIX/v1h` is the v1 pipe/hyphen project T10 built; `$FIX/.claude/memory` is v2. The hook resolves `memory.sh` next to itself, so the test exercises `$ROOT/lib/memory.sh`, never the installed copy.) -```bash -mkdir -p "$FIX/v1-proj/.claude/memory" -printf '# Decisions\n\n## BDR-001 - legacy\n' > "$FIX/v1-proj/.claude/memory/decisions.md" -``` +- [ ] **Step 2: Run, expect red** — `make test suite=lib/tests/memory.test.sh` → the ten T13 checks fail. -- [ ] **Step 2: Run, expect red** — `make test suite=lib/tests/memory.test.sh` → T13 checks fail. - -- [ ] **Step 3: Templates** — in each of the four templates: insert `format: 2` as line 2 (right after the opening `---`); delete the `## Index` heading, the blank line after it, the two table lines and the blank line after them; replace the `` comment by this shape (per file, adapt the kind, title word and body labels already in that template; the heading line is indented two spaces so no line starts with `## `): +- [ ] **Step 3: Templates** — in each of the four registry templates: insert `format: 2` as line 2 (right after the opening `---`); delete `## Index`, the blank line after it, the two table lines and the blank line after them; replace the `` comment by (shown for blockers; the heading line is indented two spaces so no line starts with `## `): ``` ``` -Kinds and labels: decisions → `decision`, ``, `[accepted]`, labels Decision / Why / Rejected alternatives / Reference; learnings → `learning`, `<abstract pattern>`, no status, labels Pattern / Context / Future application; evals → `eval`, `<output>`, `[keep]`, labels Output / Method / Anomalies / Action. `journal.md` template unchanged. +decisions → `decision`, `<title>`, `[accepted]`, labels Decision / Why / Rejected alternatives / Reference, later status `superseded by BDR-NNN`; learnings → `learning`, `<abstract pattern>`, no tag, labels Pattern / Context / Future application, no "Later status" line; evals → `eval`, `<output>`, `[keep]`, labels Output / Method / Anomalies / Action. -- [ ] **Step 4: Banner** — in `hooks/session-start.sh`, after the `fi` that closes the CLAUDE.global.md line-count guard, insert: +- [ ] **Step 4: Banner** — in `hooks/session-start.sh`, right before `# Version check: compare local vs remote (non-blocking)`: ```bash # Registry v1 (BDR-125 phase 4a): a project registry without `format: 2`. -if [ -n "$REPO_DIR" ] && [ -d .claude/memory ]; then - _v1=$(bash "$REPO_DIR/lib/memory.sh" check .claude/memory 2>&1 >/dev/null \ - | grep -c '^memory: v1: ' || true) +_mem_lib="$(dirname "${BASH_SOURCE[0]}")/../lib/memory.sh" +if [ -f "$_mem_lib" ] && [ -d .claude/memory ]; then + # shellcheck source=/dev/null + _v1=$(. "$_mem_lib"; n=0 + for f in $(_mem_names); do + f=".claude/memory/$f.md" + [ -f "$f" ] && ! memory_is_v2 "$f" && n=$((n + 1)) + done + echo "$n") if [ "${_v1:-0}" -gt 0 ]; then - _v1_line="registry v1: ${_v1} file(s), see memory.sh upgrade" - printf "│ ⚠️ %-44s│\n" "${_v1_line:0:44}" + printf "│ ⚠️ %-44s│\n" "registry v1: ${_v1} file(s) (memory.sh check)" fi - unset _v1 _v1_line + unset _v1 fi +unset _mem_lib ``` -- [ ] **Step 5: Onboarder line** — `agents/onboarder.md:126`, replace `(YAML schema + empty index + inline template comment)` by `(YAML schema with \`format: 2\` + inline template comment; no Index, entries go through \`lib/memory.sh\`)`. +- [ ] **Step 5: Onboarder line** — `agents/onboarder.md:126`: `(YAML schema + empty index + inline template comment)` → `(YAML schema with \`format: 2\` + inline template comment; no Index, entries go through \`lib/memory.sh\`)`. -- [ ] **Step 6: Run, expect green** — `make test suite=lib/tests/memory.test.sh` → `FAIL=0`; `make test suite=lib/tests/push-guard.test.sh` → green (banner unchanged for this repo, which is v1 until Task 7: if push-guard counts banner lines exactly, read its T44-T46 and confirm none breaks; the new line appears only in a project with a v1 registry). +- [ ] **Step 6: Run, expect green** — `make test suite=lib/tests/memory.test.sh` → `PASS=107 FAIL=0`. `make test suite=lib/tests/push-guard.test.sh` → green: its banner checks grep specific strings. From this task until Task 7 this repo's own banner shows `registry v1: 4 file(s) (memory.sh check)` (its registries are still v1); that is expected. - [ ] **Step 7: Commit** @@ -304,108 +319,73 @@ git commit -m "feat(memory): templates born v2 (format: 2, no Index); session ba --- -### Task 5: flows write through the lib (capitalize, CAPITALIZE steps, analyzer, doctrine) +### Task 5: flows write through the lib (one WRITE section, cited everywhere) -**Files (one edit each, exact text below):** -- `skills/capitalize/SKILL.md` STEP 2 (`:143`), STEP 4 items 1-4 (`:247-255`), STEP 5 (`:267-273`) -- `skills/feat/SKILL.md:248` -- `skills/bugfix/SKILL.md:275` -- `skills/hotfix/SKILL.md:234` (+ the two proposal bullets `:228-229` unchanged) -- `skills/ship-feature/SKILL.md:273-274` -- `skills/init-project/SKILL.md:301-303` -- `agents/commit-changer.md:220-223` -- `skills/onboard/SKILL.md` S7 (`:1181-1183`) -- `lib/analyze-before-plan.md:42-43` and `:100-102` -- `agents/analyzer.md:98-99` -- `CLAUDE.global.md` § Memory registries (two sentences) +**Files:** `lib/capitalize-commit.md` (new WRITE section), `skills/capitalize/SKILL.md` (STEP 2 `:143`, STEP 4 items 1-4, STEP 5 bullets, STEP 5B rc list), `skills/feat/SKILL.md:248`, `skills/bugfix/SKILL.md:275`, `skills/hotfix/SKILL.md:234`, `skills/ship-feature/SKILL.md:273-274`, `skills/init-project/SKILL.md:301-303`, `agents/commit-changer.md:220-223`, `skills/onboard/SKILL.md` S7, `lib/analyze-before-plan.md:42-43` and `:100-102`, `agents/analyzer.md:98-99`, `CLAUDE.global.md`. -The one canonical write instruction (W) used below: +- [ ] **Step 1: The one WRITE section** — in `lib/capitalize-commit.md`, insert before `## DO`: -> W = Write each approved entry's caveman body to a scratch file, then `bash "$HOME/.claude/lib/memory.sh" add <decision|learning|blocker|eval> --title "<title>" --body-file <file> [--status <status>]` (one call per entry; it allocates the ID and prints it; never Edit or append to a registry, there is no Index to update). A status change on an existing entry: `bash "$HOME/.claude/lib/memory.sh" status <ID> "<text>"`. The journal line: `bash "$HOME/.claude/lib/memory.sh" journal "<line>"`. +``` +## WRITE (before the commit) -- [ ] **Step 1: capitalize** +Registry entries and journal lines are written only by `lib/memory.sh`, +never by Edit or append; there is no `## Index` to update. + +- Entry: caveman body to a scratch file, then + `bash "$HOME/.claude/lib/memory.sh" [-C <project root>] add + <decision|learning|blocker|eval> --title "<title>" --body-file <file> + [--status <status>] [--supersedes <ID>]`. One call per entry; it + allocates the ID under a lock and prints it. A blocker body quotes ≥1 + error in backticks. `-C` when the cwd is not the project root. +- Status change on an existing entry: + `bash "$HOME/.claude/lib/memory.sh" status <ID> "<word> …"`, the text + starting with a status word (`resolved abc1234`, `open, reopened by …`, + `superseded by BDR-NNN`). +- Journal: `bash "$HOME/.claude/lib/memory.sh" journal "<line>"`. +- rc 2 names its reason (title chars, empty body, open code fence, unknown + ID): fix the input and re-run. +``` + +- [ ] **Step 2: capitalize** - `:143` `(Index + bodies)` → `(headings + bodies)`. - - STEP 4 items 1-4 (from `1. Read the target registry file.` through the Index-row item ending `match that file's header row).`) become: + - STEP 4 items 1-4 (from `1. Read the target registry file.` through `match that file's header row).`) → one item: `1. Write each approved entry per \`lib/capitalize-commit.md\` § WRITE (\`memory.sh add\`, one call each; a resolved blocker: \`memory.sh status <ID> "resolved <hash>"\`).` Old item 5 (caveman) stays, renumbered 2. + - STEP 5: the two bullets `- Heading exists → append a bullet.` / `- Missing → create …` → `- \`bash "$HOME/.claude/lib/memory.sh" journal "<line>"\` per bullet (it creates today's heading when missing).` + - STEP 5B step 3: after the `**rc 3**` bullet add `- **rc 5 / rc 6** → nothing committed; surface the helper's stderr; meaning and recovery in \`lib/capitalize-commit.md\` (rc 6: fix the registry, then /commit-change). STEP 6 says NOT committed.` -``` -1. Body to a scratch file, then `bash "$HOME/.claude/lib/memory.sh" add - <decision|learning|blocker|eval> --title "<title>" --body-file <file> - [--status <status>] [--supersedes <ID>]`: it allocates the next ID from - the headings under a lock, appends at the end, prints the ID. Never Edit - or append to a registry by hand; there is no Index to update. -2. A status change on an existing entry (a blocker now resolved): - `bash "$HOME/.claude/lib/memory.sh" status <ID> "<text>"`. -3. A refusal (rc 2) names its reason (title chars, empty body, a blocker - body without one backtick-quoted error): fix the input, re-run. -``` +- [ ] **Step 3: flow citations** (each a one-line replacement; the **Language rule** lines untouched): + - feat `:248` (`Always append a 1-line entry to today's heading in \`.claude/memory/journal.md\`.`) → `Approved entries and the always-written 1-line journal entry: per \`lib/capitalize-commit.md\` § WRITE (\`memory.sh add\` / \`memory.sh journal\`).` + - bugfix `:275` → `4. Write approved entries per \`lib/capitalize-commit.md\` § WRITE: a new blocker \`add blocker … --status resolved\`, an existing one now fixed \`status <BLK-ID> "resolved <hash>"\`, an LRN \`add learning …\` (no status); the journal line \`memory.sh journal\`.` + - hotfix `:234` → `Always append a 1-line journal entry (even trivial hotfix — journal is timeline, not signal) and any approved BLK/LRN per \`lib/capitalize-commit.md\` § WRITE.` + - ship-feature `:273-274` → `4. Write approved entries per \`lib/capitalize-commit.md\` § WRITE (\`memory.sh add\`, one call each; no Index to update).` / `5. Journal line: \`memory.sh journal\` (same section).` + - init-project `:301-303` → `3. Write approved entries to the registries bootstrapped at STEP 5 (in the root commit), and the journal line, per \`lib/capitalize-commit.md\` § WRITE.` + - commit-changer `:220-223` (Phase 4 item 2) → `2. Write each resolved entry and one journal line for the batch per \`$HOME/.claude/lib/capitalize-commit.md\` § WRITE (\`memory.sh -C <repo root> add …\`, \`memory.sh -C <repo root> journal …\`; no Index to update).` + - onboard S7: the source text spans a line break, `append to that` (end of the line starting `S7 — AFTER.`) + newline + `project's \`.claude/memory/journal.md\` under today's date:`. Replace the tail `append to that` / `project's \`.claude/memory/journal.md\` under today's date:` by `append to that` / `project's journal (\`bash "$HOME/.claude/lib/memory.sh" -C <ROOT> journal\`):` — same two-line wrap, the quoted line text after it unchanged. - Old item 5 (caveman) stays, renumbered 4. - - STEP 5: replace the two bullets `- Heading exists → append a bullet.` / `- Missing → create …` by `- \`bash "$HOME/.claude/lib/memory.sh" journal "<line>"\` (one call per bullet; it creates today's heading when missing).` - -- [ ] **Step 2: feat** `:248` (`Always append a 1-line entry to today's heading in \`.claude/memory/journal.md\`.`) → two lines, the **Language rule** line after them untouched: - -``` -Approved entries: caveman body to a scratch file, then `bash "$HOME/.claude/lib/memory.sh" add <decision|learning> --title "<title>" --body-file <file>` (one call each; it allocates the ID; never Edit a registry). - -Always append a 1-line entry: `bash "$HOME/.claude/lib/memory.sh" journal "<line>"`. -``` - -- [ ] **Step 3: bugfix** `:275` → `4. Write approved entries with \`bash "$HOME/.claude/lib/memory.sh" add <kind> --title … --body-file <file> --status resolved\` (one call each, it allocates the ID; an existing blocker now fixed: \`memory.sh status <ID> "resolved <hash>"\`). Journal line: \`bash "$HOME/.claude/lib/memory.sh" journal "<line>"\`.` - -- [ ] **Step 4: hotfix** `:234` → `Always append a 1-line entry with \`bash "$HOME/.claude/lib/memory.sh" journal "<line>"\` (even trivial hotfix — journal is timeline, not signal). A proposed BLK/LRN, once approved: \`bash "$HOME/.claude/lib/memory.sh" add <blocker|learning> --title … --body-file <file>\`.` - -- [ ] **Step 5: ship-feature** `:273-274` → -``` -4. Write approved entries with `bash "$HOME/.claude/lib/memory.sh" add <kind> --title "<title>" --body-file <file> [--status <s>]`, one call each (it allocates the ID; no Index to update). -5. Journal line: `bash "$HOME/.claude/lib/memory.sh" journal "<line>"`. -``` - -- [ ] **Step 6: init-project** `:301-303` → `3. Write approved entries to the registries bootstrapped at STEP 5 (in the root commit) with \`bash "$HOME/.claude/lib/memory.sh" add <kind> --title … --body-file <file>\`, one call each; journal line with \`bash "$HOME/.claude/lib/memory.sh" journal "<line>"\`.` - -- [ ] **Step 7: commit-changer** `:220-223` (item 2 of Phase 4) → -``` -2. Write each resolved entry with `bash "$HOME/.claude/lib/memory.sh" add - <decision|learning|blocker|eval> --title "<title>" --body-file <file>` - (one call each; it allocates the ID, no Index to update), then one - journal line for the batch: `bash "$HOME/.claude/lib/memory.sh" journal - "<summary>"`. -``` - -- [ ] **Step 8: onboard S7** — replace `append to that project's \`.claude/memory/journal.md\` under today's date:` by `append to that project's journal with \`bash "$HOME/.claude/lib/memory.sh" -C <ROOT> journal\`:` (the quoted line text after it unchanged). - -- [ ] **Step 9: analyze-before-plan + analyzer** +- [ ] **Step 4: analyze-before-plan + analyzer** - `lib/analyze-before-plan.md:42-43`: `Do NOT read the \`## Index\` table: it drifts (entries land in the body, the manual Index update lapses — measured 32-40% missing on a mature repo); headings cannot.` → `Do NOT read a \`## Index\` table (v1 registries may still carry one; it drifted 32-40% on a mature repo; v2 has none); headings cannot drift.` - - `:100-102`: `No write, no Index update, no memory mutation.` → `No write, no memory mutation.` and `Index backfill, if ever wanted, is \`/prune-memory\` passe D — never this snippet.` → `Registry writes go through \`lib/memory.sh\`, never this snippet.` + - `:100-102`: `No write, no Index update, no memory mutation.` → `No write, no memory mutation.`; `Index backfill, if ever wanted, is \`/prune-memory\` passe D — never this snippet.` → `Registry writes go through \`lib/memory.sh\`, never this snippet.` - `agents/analyzer.md:98-99`: `Index backfill or new entries are never your job` → `new entries or status lines are never your job (writes go through lib/memory.sh)`. -- [ ] **Step 10: CLAUDE.global.md** (line-neutral): - - `Append-only: never rewrite past entries; curation (merge, supersede,\ncompress) only via \`/prune-memory\`.` → `Append-only, written only through \`bash ~/.claude/lib/memory.sh\` (add,\nstatus, journal), never by Edit; curation only via \`/prune-memory\`.` - - `exact. Pattern \`[thing] [action] [reason]. [next step].\` Registries load\nevery session; caveman cuts ~40% of the tokens with no substance lost.` → `exact. Pattern \`[thing] [action] [reason]. [next step].\` Planning flows\nread the registries; caveman cuts ~40% of every read, no substance lost.` +- [ ] **Step 5: CLAUDE.global.md** (line-neutral): + - `Append-only: never rewrite past entries; curation (merge, supersede,` / `compress) only via \`/prune-memory\`.` → `Append-only, written only through \`bash ~/.claude/lib/memory.sh\` (add,` / `status, journal), never by Edit; curation only via \`/prune-memory\`.` + - `exact. Pattern \`[thing] [action] [reason]. [next step].\` Registries load` / `every session; caveman cuts ~40% of the tokens with no substance lost.` → `exact. Pattern \`[thing] [action] [reason]. [next step].\` Planning flows` / `read the registries; caveman cuts ~40% of every read, no substance lost.` -- [ ] **Step 11: Verify** -Run: `grep -rn 'Index' skills/capitalize/SKILL.md skills/feat/SKILL.md skills/bugfix/SKILL.md skills/hotfix/SKILL.md skills/ship-feature/SKILL.md skills/init-project/SKILL.md agents/commit-changer.md` → no line telling a writer to update an Index. -Run: `wc -l < CLAUDE.global.md` → ≤ 333. -Run: `make test suite=lib/tests/doctrine-citers.test.sh` and `make test suite=lib/tests/effort-routing.test.sh` → green (no rewrap of a census string; every `route(phase="apply") … memory-commit` line untouched). +- [ ] **Step 6: Verify** — `grep -rn 'Index' skills/capitalize/SKILL.md skills/feat/SKILL.md skills/bugfix/SKILL.md skills/hotfix/SKILL.md skills/ship-feature/SKILL.md skills/init-project/SKILL.md agents/commit-changer.md` → no line telling a writer to update an Index. `wc -l < CLAUDE.global.md` → ≤ 333. `make test suite=lib/tests/doctrine-citers.test.sh` and `make test suite=lib/tests/effort-routing.test.sh` → green. -- [ ] **Step 12: Commit** +- [ ] **Step 7: Commit** ```bash -git add skills/capitalize/SKILL.md skills/feat/SKILL.md skills/bugfix/SKILL.md skills/hotfix/SKILL.md skills/ship-feature/SKILL.md skills/init-project/SKILL.md agents/commit-changer.md skills/onboard/SKILL.md lib/analyze-before-plan.md agents/analyzer.md CLAUDE.global.md -git commit -m "docs(memory): every writer goes through lib/memory.sh; Index steps removed; doctrine names the single writer" +git add lib/capitalize-commit.md skills/capitalize/SKILL.md skills/feat/SKILL.md skills/bugfix/SKILL.md skills/hotfix/SKILL.md skills/ship-feature/SKILL.md skills/init-project/SKILL.md agents/commit-changer.md skills/onboard/SKILL.md lib/analyze-before-plan.md agents/analyzer.md CLAUDE.global.md +git commit -m "docs(memory): one WRITE section in capitalize-commit.md, every flow cites it; Index steps removed; doctrine names the single writer" ``` --- ### Task 6: /prune-memory on v2 (no § D, status through the lib, check as verify) -**Files:** -- Modify: `skills/prune-memory/SKILL.md` (`:83-85`, `:111-115`, `:130`, `:141-143`, `:153-158`, `:177`, STEP 4 block `:190-206`, report `:274`, failure row `:305`, `:322-323`) -- Modify: `skills/prune-memory/tests/run-deterministic.sh` (RED-6 rewritten) -- Create: `skills/prune-memory/tests/fixtures/red6-check/.claude/memory/decisions.md` -- Delete: `skills/prune-memory/tests/fixtures/red6-orphan/.claude/memory/decisions.md` (`git rm`) -- Modify: `skills/prune-memory/test-prompts.json` (id 1 `expected`) +**Files:** `skills/prune-memory/SKILL.md` (§ A `:83-85`, § D `:111-115`, STEP 2 example, STEP 3 list, `:177`, STEP 4 block, report sample, failure row, `:322-323`), `skills/prune-memory/tests/run-deterministic.sh` (RED-6), new `skills/prune-memory/tests/fixtures/red6-check/.claude/memory/decisions.md`, `git rm` of `skills/prune-memory/tests/fixtures/red6-orphan/.claude/memory/decisions.md`, `skills/prune-memory/test-prompts.json` (id 1). -- [ ] **Step 1: Write the failing test** — replace the whole RED-6 block (from `# ---- RED-6:` through its closing `fi`) in `skills/prune-memory/tests/run-deterministic.sh` by: +- [ ] **Step 1: Write the failing test** — replace the whole RED-6 block (from `# ---- RED-6:` through its closing `fi`) by: ```bash # ---- RED-6: STEP 4 verify runs memory.sh check (duplicate ID caught) -------- @@ -425,7 +405,7 @@ else fi ``` -Create `skills/prune-memory/tests/fixtures/red6-check/.claude/memory/decisions.md`: +Fixture `skills/prune-memory/tests/fixtures/red6-check/.claude/memory/decisions.md`: ``` --- @@ -443,19 +423,20 @@ entry_prefix: BDR - **Status**: accepted ``` -`git rm -q skills/prune-memory/tests/fixtures/red6-orphan/.claude/memory/decisions.md`. In the suite header comment, `RED-2/RED-6 execute the REAL bash blocks` stays true. +`git rm -q skills/prune-memory/tests/fixtures/red6-orphan/.claude/memory/decisions.md`. - [ ] **Step 2: Run, expect red** — `make test suite=skills/prune-memory/tests/run-deterministic.sh` → `RED-6: RED`. - [ ] **Step 3: SKILL.md edits** - - § A bullet `:83-85`: `Decisions whose body contains "superseded by <ID>" but Index row still says \`accepted\` → propose Index row fix to \`superseded by <that-ID>\`.` → `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 \`accepted\` → propose \`memory.sh status <ID> "superseded by <that-ID>"\`.` - - Delete § D (`### D. Index drift` and its two bullets, `:111-115`). - - STEP 2 example: `→ fix Index: status = "superseded by BDR-903"` → `→ memory.sh status BDR-902 "superseded by BDR-903"`; delete the `[D. Index drift]` + `(none)` lines; `Approve per category? (all / a / b / c / d / edit <ID> / skip)` → `(all / a / b / c / edit <ID> / skip)`. - - STEP 3 list becomes: + - § A `:83-85` → `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 \`accepted\` → propose \`memory.sh status <ID> "superseded by <that-ID>"\`.` + - Delete § D (`### D. Index drift` and its two bullets). + - STEP 2 example: `→ fix Index: status = "superseded by BDR-903"` → `→ memory.sh status BDR-902 "superseded by BDR-903"`; delete `[D. Index drift]` + `(none)`; `(all / a / b / c / d / edit <ID> / skip)` → `(all / a / b / c / edit <ID> / skip)`. + - STEP 3 list (replacing items 1-3; old item 4 becomes 3, unchanged): ``` 1. **Status flag updates** — `bash "$HOME/.claude/lib/memory.sh" status <ID> - "<text>"` appends a dated status line; the body above stays verbatim. + "<word> …"` appends a dated status line (text starts with a status word: + `deprecated, no follow-up after 90 days`); the body above stays verbatim. 2. **Merges** — write the merged body to a scratch file, then `bash "$HOME/.claude/lib/memory.sh" add <kind> --title "<title>" --body-file <file> --supersedes <first source>` (next-free ID, forward @@ -463,23 +444,22 @@ entry_prefix: BDR `memory.sh status <ID> "superseded by <new-ID>"`. Source bodies stay verbatim for history. Merged body: ``` - followed by the existing merged-body sub-bullets (Reference lines, caveman pass, frontmatter fields) and the existing item 4 renumbered 3 (inline caveman compression, unchanged). Delete `After each write, regenerate Index from body when rows changed.` - - STEP 4 block: delete the `PREFIX_MAP` declaration, its comment and the `# All body entries have Index rows; no orphans` loop (through its `done`), and put in their place: + followed by the existing merged-body sub-bullets. Delete `After each write, regenerate Index from body when rows changed.` + - STEP 4 block: delete the `PREFIX_MAP` declaration, its comment and the `# All body entries have Index rows; no orphans` loop through its `done`; in their place: ```bash -# Structure: heading shape + unique IDs (v2 registries; a v1 one is named -# and skipped). Same verify the writer runs after every add. +# Structure: heading shape + unique IDs + no open fence (v2 registries; a +# v1 one is named and skipped). Same verify the writer runs after every add. bash "$HOME/.claude/lib/memory.sh" check .claude/memory \ || echo "CHECK FAILED: fix the lines above before certifying" ``` - - Report sample `INDEX SANITY: OK` → `CHECK: OK`. - - Failure table row `| Index sanity FAILED at STEP 4 | Print exact missing/orphan IDs. …` → `| \`memory.sh check\` FAILED at STEP 4 | Print its culprit lines. Do NOT auto-fix — user re-runs or hand-edits. |`. + - Report sample `INDEX SANITY: OK` → `CHECK: OK`; `NEXT: review \`git diff .claude/memory/\`, then \`/commit-change\`` unchanged (curation edits are removals: they never go through memory-commit's chokepoint). + - Failure row `| Index sanity FAILED at STEP 4 | …` → `| \`memory.sh check\` FAILED at STEP 4 | Print its culprit lines. Do NOT auto-fix — user re-runs or hand-edits. |`. - `:322-323` fixtures list `red6-orphan` → `red6-check`. - [ ] **Step 4: test-prompts.json** id 1 `expected` → `"Skill runs PRECHECK (refuses if working tree dirty on .claude/memory/), audits all 5 registries for A) obsolete/superseded entries B) similar merge candidates C) bloated prose, presents the per-registry PRUNE PLAN with category-level approval gate, applies only approved changes (status lines and merges through lib/memory.sh, never hard-delete), then runs memory.sh check and the fidelity census at STEP 4."` -- [ ] **Step 5: Run, expect green** — `make test suite=skills/prune-memory/tests/run-deterministic.sh` → RED-1..7 all GREEN (RED-5 still green: its journal-only sandbox has no registry, `check` prints nothing). -Run: `grep -n 'Index' skills/prune-memory/SKILL.md` → no writer step mentions an Index. +- [ ] **Step 5: Run, expect green** — `make test suite=skills/prune-memory/tests/run-deterministic.sh` → RED-1..7 GREEN (RED-5's journal-only sandbox has no registry, `check` prints nothing). `grep -n 'Index' skills/prune-memory/SKILL.md` → no writer step mentions an Index. - [ ] **Step 6: Commit** @@ -492,34 +472,42 @@ git commit -m "feat(prune-memory): v2 registries — § D dropped, status and me ### Task 7: upgrade this repo's registries (the one curation) -**Files:** -- Modify: `.claude/memory/{decisions,learnings,blockers,evals}.md` (by the lib only) +**Files:** `.claude/memory/{decisions,learnings,blockers,evals}.md` (by the lib only). `upgrade` already transforms on a temp copy and runs its oracle before replacing any file; the registries are tracked, so no dry run. -- [ ] **Step 1: Dry run on a copy** — - -```bash -d=$(mktemp -d); mkdir -p "$d/.claude/memory"; cp .claude/memory/*.md "$d/.claude/memory/" -bash lib/memory.sh -C "$d" upgrade && bash lib/memory.sh -C "$d" check && echo DRY-OK -``` -Expected: four `memory: upgraded …` lines, `DRY-OK`. - -- [ ] **Step 2: Upgrade in place and commit through the chokepoint** +- [ ] **Step 1: Upgrade in place and commit through the chokepoint** ```bash bash lib/memory.sh upgrade bash lib/memory.sh check && echo CHECK-OK -bash lib/memory.sh index blocker | grep -E 'BLK-03[234]' bash "$HOME/.claude/lib/memory-commit.sh" commit "chore(memory): registries v2 — Index removed, Index-only dates and statuses materialized (memory.sh upgrade)" ``` -Expected: `CHECK-OK`; BLK-032..034 rows read `resolved` with a date; memory-commit prints a hash (rc 0: the Index lines sit before the first entry, every other change is an insertion). +Expected: four `memory: upgraded …` lines and one stderr line `memory: BDR-012: kept body shipped, dropped Index accepted`; `CHECK-OK`; memory-commit prints a hash (Index lines sit above the first entry, every other change is an insertion). If `upgrade` returns rc 2: `git checkout -- .claude/memory`, report its stderr, stop. -- [ ] **Step 3: Verify the live facts** -Run: `make test suite=lib/tests/memory.test.sh` → T12 (live check) green. -Run: `bash -c '. lib/reconcile.sh; reconcile_blk_open .claude/memory/blockers.md | cut -f1 | tr "\n" " "'` → `BLK-001 BLK-003 BLK-017 BLK-018 BLK-021 BLK-022 BLK-029 ` (no 032..034). -Run: `grep -c '^## Index' .claude/memory/*.md` → 0 everywhere. +- [ ] **Step 2: Verify the live facts** +Run: `bash -c '. lib/reconcile.sh; reconcile_blk_open .claude/memory/blockers.md | cut -f1 | tr "\n" " "'` → exactly `BLK-001 BLK-003 BLK-017 BLK-018 BLK-021 BLK-022 BLK-029 ` (measured on an upgraded copy 2026-10-28: 032..034 resolved, 019/020 superseded = closed). +Run: `bash lib/memory.sh index blocker | grep -E 'BLK-0(19|20|32|33|34)'` → dates `2026-09-01 2026-09-02 2026-10-19 2026-10-21 2026-10-22`, statuses superseded, superseded, resolved ×3. +Run: `grep -c '^## Index' .claude/memory/*.md` → 0 everywhere; `make test suite=lib/tests/memory.test.sh` → T12 green; the session banner no longer shows `registry v1`. --- ## Final verification (main loop, after Task 7) -`make test` all suites green; `shellcheck lib/memory.sh lib/reconcile.sh lib/memory-commit.sh hooks/session-start.sh`; `bash lib/memory.sh check`; `git status --short` clean; no file outside this repo changed (`git -C <proj> status --short .claude/memory` empty for the projects listed in the spec § 2.4 note). +`make test` all suites green; `shellcheck lib/memory.sh lib/reconcile.sh lib/memory-commit.sh hooks/session-start.sh`; `bash lib/memory.sh check`; `git status --short` clean except the user-owned `settings.json`. No other project changed: `git -C <dir> status --short .claude/memory` empty, and `bash -c '. lib/reconcile.sh; reconcile_blk_open <dir>/.claude/memory/blockers.md'` equal to the pre-branch reader, for each of: + +``` +/home/bchanot/Documents/config +/home/bchanot/Documents/faunosteo +/home/bchanot/Documents/game +/home/bchanot/Documents/game-deploy +/home/bchanot/Documents/integration_alphalink +/home/bchanot/Documents/robin_petier +/home/bchanot/Documents/zenquality +/home/bchanot/repos/bchanot/angelscar356 +/home/bchanot/repos/bchanot/bchanot-cv +/home/bchanot/repos/bchanot/for_you +/home/bchanot/repos/bchanot/game-deploy +/home/bchanot/repos/bchanot/gitea-deploy +/home/bchanot/repos/bchanot/nuit-folle +/home/bchanot/repos/bchanot/trucks_at_work +``` +(pre-branch reader: `git show develop:lib/reconcile.sh > <tmp>` then source `<tmp>`; measured 2026-10-28 on copies: 13 of 13 distinct files identical.) diff --git a/docs/superpowers/plans/memory-v2-write/blockers-v1-dialects.md b/docs/superpowers/plans/memory-v2-write/blockers-v1-dialects.md new file mode 100644 index 0000000..55c6dac --- /dev/null +++ b/docs/superpowers/plans/memory-v2-write/blockers-v1-dialects.md @@ -0,0 +1,10 @@ +# Blockers + +## BLK-001 - hyphen dialect, resolved +- **Status**: resolved + +## BLK-002 | 2026-05-18 | pipe dialect, open +Status: open + +## BLK-003 | 2026-05-19 | pipe dialect, resolved +Status: resolved. diff --git a/docs/superpowers/plans/memory-v2-write/blockers-v2-status.md b/docs/superpowers/plans/memory-v2-write/blockers-v2-status.md index 095c611..632f424 100644 --- a/docs/superpowers/plans/memory-v2-write/blockers-v2-status.md +++ b/docs/superpowers/plans/memory-v2-write/blockers-v2-status.md @@ -47,3 +47,10 @@ entry_prefix: BLK ## BLK-042 — no status anywhere - **Solution**: fail-open guard, `data:` OPEN in prose. + +## BLK-043 — DNS resolved to stale IP after failover [open] (2026-10-28) +- **Friction**: `dig` answers the old address. + +## BLK-044 — reopened after a regression [resolved] (2026-10-28) +- **Cause**: `abc` reverted the fix. +- **Status (2026-10-28)**: open again, not resolved by abc diff --git a/docs/superpowers/plans/memory-v2-write/memory.sh b/docs/superpowers/plans/memory-v2-write/memory.sh index 85ac453..34d7135 100644 --- a/docs/superpowers/plans/memory-v2-write/memory.sh +++ b/docs/superpowers/plans/memory-v2-write/memory.sh @@ -6,25 +6,34 @@ # add <kind> --title <t> --body-file <f> [--status <s>] [--supersedes <ID>] # append one entry, next ID from the headings, under the # lock; the new ID is the only stdout line -# status <ID> <text> append `- **Status (<date>)**: <text>` to the entry +# status <ID> <text> append `- **Status (<date>)**: <text>` to the entry; +# <text> starts with a status word ("open, reopened by …") # journal <line> append `- <line>` under today's `## YYYY-MM-DD` # index [<kind>] ID | Date | Title | Status, from headings and bodies -# check [--staged] [<memory-dir>] heading shape, unique IDs, no Index in -# a v2 file (v1 reported, never failed); --staged: no line -# removed inside an existing entry of a staged v2 registry +# check [--staged] [<memory-dir>] heading shape, unique IDs, no Index, +# no open fence in a v2 file (v1 reported, never failed); +# --staged: only NEW culprits vs HEAD, no line removed +# inside an entry, no v2 registry deleted or downgraded # upgrade [<memory-dir>] v1 → v2: Index-only dates and statuses become # body lines, `format: 2`, `## Index` removed, oracle first # <kind> = decision | learning | blocker | eval. MEMORY_DATE overrides today. # Status of an entry: the last candidate wins. A candidate is the heading's # trailing `[tag]`, or a body line whose bold label names Status, Resolution, # Action, UPDATE or FINAL (v1: `Status:`), holding a status word. A word in -# prose is never one (the BLK-032..034 false-open). Words rank in -# _MEM_WORDS order, `open` last: "accepted, check OPEN" reads accepted. +# prose (title included) is never one (the BLK-032..034 false-open). A dated +# `**Status (YYYY-MM-DD…)**:` line reads its leading word; other lines rank +# words in _MEM_WORDS order, `open` last: "accepted, check OPEN" = accepted. +# Closed = resolved | superseded | deprecated (memory_closed). # Lock: <git-common-dir>/memory.lock created under noclobber (flock(1) is # absent on macOS), a lock older than 30 s is stolen. Registry headings -# are scanned outside ``` fences only. +# are scanned outside ``` fences only; free text reaches awk through +# ENVIRON, never `-v` (which expands backslash escapes). MEM_GREP="${MEM_GREP:-/usr/bin/grep}" +_MEM_TABLE='decision decisions BDR +learning learnings LRN +blocker blockers BLK +eval evals EVAL' _MEM_WORDS='resolved superseded deprecated upstream accepted implemented' _MEM_WORDS+=' shipped proposed keep correct deprecate open' _MEM_AWK=' @@ -33,43 +42,65 @@ function mem_word(s, t, i, n, w) { for (i = 1; i <= n; i++) if (t ~ ("(^|[^a-z])" w[i] "([^a-z]|$)")) return w[i] return "" } +function mem_lead(s, v, i, n, w) { + v = s; sub(/^[^:]*\*\*: */, "", v); v = tolower(v) + sub(/[^a-z].*$/, "", v); n = split(MEMW, w, " ") + for (i = 1; i <= n; i++) if (v == w[i]) return v + return "" } +function mem_lineword(s, w) { + if (s ~ /^- \*\*Status \([0-9]/ && (w = mem_lead(s)) != "") return w + return mem_word(s) } function mem_tag(line) { if (!match(line, /\[[^]]*\]( \([0-9-]+\))? *$/)) return "" - return mem_word(substr(line, RSTART)) } + if (mem_word(substr(line, RSTART)) == "") return "" + line = substr(line, RSTART); sub(/\].*$/, "]", line); return line } function mem_cand(line, lab) { if (line ~ /^- \*\*[^*]+\*\*/) { lab = line; sub(/^- \*\*/, "", lab); sub(/\*\*.*/, "", lab) - return tolower(lab) ~ /status|resolution|action|update|final/ \ - && mem_word(line) != "" } - return line ~ /^(- )?[Ss]tatus:/ && mem_word(line) != "" } -function mem_key(line, key) { - return line == "## " key || index(line, "## " key " — ") == 1 } + if (tolower(lab) !~ /status|resolution|action|update|final/) return "" + return mem_lineword(line) } + if (line ~ /^(- )?[Ss]tatus:/) return mem_word(line) + return "" } +function mem_key(line, key, c) { + if (index(line, "## " key) != 1) return 0 + c = substr(line, length(key) + 4, 1) + return c == "" || c !~ /[0-9A-Za-z]/ } +function mem_want(p, c, st, w) { + w = mem_word(c) + if (p == "EVAL" || w == "") return "" + if (p == "LRN") return c ~ /^superseded by/ ? c : "" + if (st == "" || (w ~ /^(superseded|deprecated)$/ && st != w)) return c + return "" } ' _mem_date() { printf '%s\n' "${MEMORY_DATE:-$(date +%F)}"; } -_mem_kind() { # <kind> → "<file> <PREFIX>", rc 2 when unknown - case "$1" in - decision) echo "decisions.md BDR" ;; - learning) echo "learnings.md LRN" ;; - blocker) echo "blockers.md BLK" ;; - eval) echo "evals.md EVAL" ;; - *) echo "memory: unknown kind: $1 (decision|learning|blocker|eval)" >&2 - return 2 ;; - esac +_mem_row() { # <column 1|2|3> <value> → "kind file PREFIX", rc 2 if none + awk -v c="$1" -v v="$2" '$c == v { print; f = 1; exit } + END { exit f ? 0 : 2 }' <<< "$_MEM_TABLE" +} + +_mem_names() { local k f p; while read -r k f p; do echo "$f"; done \ + <<< "$_MEM_TABLE"; } + +_mem_kind() { # <kind> → "<file>.md <PREFIX>", rc 2 when unknown + local row file prefix + row=$(_mem_row 1 "$1") || { + echo "memory: unknown kind: $1 (decision|learning|blocker|eval)" >&2 + return 2; } + read -r _ file prefix <<< "$row" + echo "$file.md $prefix" } _mem_id_file() { # <ID> → its registry path, rc 2 when the prefix is unknown - case "$1" in - BDR-[0-9]*) echo .claude/memory/decisions.md ;; - LRN-[0-9]*) echo .claude/memory/learnings.md ;; - BLK-[0-9]*) echo .claude/memory/blockers.md ;; - EVAL-[0-9]*) echo .claude/memory/evals.md ;; - *) echo "memory: not an entry ID: $1" >&2; return 2 ;; - esac + local row file + row=$(_mem_row 3 "${1%%-[0-9]*}") \ + || { echo "memory: not an entry ID: $1" >&2; return 2; } + read -r _ file _ <<< "$row" + echo ".claude/memory/$file.md" } -_mem_is_v2() { # <file> → rc 0 when the frontmatter carries `format: 2` +memory_is_v2() { # <file> → rc 0 when the frontmatter carries `format: 2` awk 'NR == 1 && $0 != "---" { exit } NR > 1 && $0 == "---" { exit } $0 == "format: 2" { v2 = 1; exit } @@ -77,7 +108,8 @@ _mem_is_v2() { # <file> → rc 0 when the frontmatter carries `format: 2` } _mem_has_id() { # <file> <ID> → rc 0 when a heading carries the ID - awk -v k="$2" "$_MEM_AWK"' + MEM_K="$2" awk "$_MEM_AWK"' + BEGIN { k = ENVIRON["MEM_K"] } /^```/ { fence = !fence; next } !fence && mem_key($0, k) { found = 1; exit } END { exit !found }' "$1" @@ -92,23 +124,32 @@ _mem_next_id() { # <file> <PREFIX> → max heading ID + 1, zero-padded END { printf "%s-%03d\n", p, m + 1 }' "$1" } -memory_entry_status() { # <file> <ID> → winning candidate line, rc 1 if none - awk -v k="$2" -v MEMW="$_MEM_WORDS" "$_MEM_AWK"' +memory_entry_status() { # <file> <ID> → the winning candidate, rc 1 if none + # a heading candidate prints its `[tag]` only, never the title + MEM_K="$2" awk -v MEMW="$_MEM_WORDS" "$_MEM_AWK"' + BEGIN { k = ENVIRON["MEM_K"] } /^```/ { fence = !fence; next } fence { next } /^## / { if (on) exit - if (mem_key($0, k)) { on = 1; if (mem_tag($0) != "") last = $0 } + if (mem_key($0, k)) { on = 1; t = mem_tag($0) + if (t != "") last = t } next } - on && mem_cand($0) { last = $0 } + on && mem_cand($0) != "" { last = $0 } END { if (last == "") exit 1; print last }' "$1" } memory_status_word() { # <line> → its status word, else its first 40 chars - awk -v MEMW="$_MEM_WORDS" "$_MEM_AWK"' - { w = mem_word($0); print (w != "" ? w : substr($0, 1, 40)) }' <<< "$1" + MEM_L="$1" awk -v MEMW="$_MEM_WORDS" "$_MEM_AWK"' + BEGIN { s = ENVIRON["MEM_L"]; w = mem_lineword(s) + print (w != "" ? w : substr(s, 1, 40)) }' } -_mem_lock_dir() { # → the lock path for the current repository +memory_closed() { # <status word> → rc 0 when it closes the entry + case "$1" in resolved|superseded|deprecated) return 0 ;; esac + return 1 +} + +_mem_lock_path() { # → the lock file for the current repository local d if d=$(git rev-parse --git-common-dir 2>/dev/null); then echo "$d/memory.lock"; return @@ -123,7 +164,10 @@ _mem_lock() { # <lock file> → rc 0 held, rc 2 after MEM_LOCK_TRIES waits until (set -C; date +%s > "$lock") 2>/dev/null; do now=$(date +%s); t=$(cat "$lock" 2>/dev/null) case "$t" in ''|*[!0-9]*) t=$now ;; esac # holder still writing it - if [ $((now - t)) -gt 30 ]; then rm -f "$lock"; continue; fi + if [ $((now - t)) -gt 30 ]; then # steal: rename first, never rm shared + mv "$lock" "$lock.stale.$$" 2>/dev/null && rm -f "$lock.stale.$$" + continue + fi tries=$((tries + 1)) [ "$tries" -lt "${MEM_LOCK_TRIES:-50}" ] \ || { echo "memory: lock busy: $lock" >&2; return 2; } @@ -135,9 +179,11 @@ _mem_unlock() { rm -f "$1"; } _mem_locked() { # <fn> [args…] → run fn under the lock, its rc local lock rc - lock=$(_mem_lock_dir) + lock=$(_mem_lock_path) _mem_lock "$lock" || return 2 + trap '_mem_unlock "$lock"; exit 130' INT TERM HUP "$@"; rc=$? + trap - INT TERM HUP _mem_unlock "$lock" return "$rc" } @@ -151,7 +197,8 @@ _mem_one_line() { # <what> <text> → rc 2 when empty or multi-line _mem_insert() { # <file> <key> <line> → line ends the section, rc 1 if absent local tmp tmp=$(mktemp) || { echo "memory: no temp file" >&2; return 2; } - awk -v k="$2" -v ins="$3" "$_MEM_AWK"' + MEM_K="$2" MEM_INS="$3" awk "$_MEM_AWK"' + BEGIN { k = ENVIRON["MEM_K"]; ins = ENVIRON["MEM_INS"] } function flush( i) { print ins; for (i = 1; i <= n; i++) print buf[i] n = 0; done = 1 } /^```/ { fence = !fence } @@ -168,14 +215,28 @@ _mem_insert() { # <file> <key> <line> → line ends the section, rc 1 if absent rm -f "$tmp" } +_mem_status_text() { # <text> → rc 2 unless it starts with a status word + local w + w=$(tr '[:upper:]' '[:lower:]' <<< "${1%%[^A-Za-z]*}") + case " $_MEM_WORDS " in *" $w "*) [ -n "$w" ] && return 0 ;; esac + echo "memory: status text starts with a status word: $_MEM_WORDS" >&2 + return 2 +} + memory_status() { # <ID> <text> - local file + local file rc _mem_one_line "status text" "$2" || return 2 + _mem_status_text "$2" || return 2 file=$(_mem_id_file "$1") || return 2 - _mem_has_id "$file" "$1" \ - || { echo "memory: no entry $1 in $file" >&2; return 2; } - _mem_locked _mem_insert "$file" "$1" "- **Status ($(_mem_date))**: $2" \ - || { echo "memory: $1 status not written" >&2; return 2; } + [ -f "$file" ] || { echo "memory: no registry: $file" >&2; return 2; } + _mem_locked _mem_insert "$file" "$1" "- **Status ($(_mem_date))**: $2" + rc=$? + case "$rc" in + 0) return 0 ;; + 1) echo "memory: no entry $1 in $file" >&2 ;; + *) echo "memory: $1 status not written" >&2 ;; + esac + return 2 } _mem_journal_locked() { # <file> <date> <line> @@ -204,6 +265,8 @@ _mem_add_valid() { # <PREFIX> <title> <body-file> <status> <supersedes> [ "${#2}" -le 160 ] || { echo "memory: title over 160 chars" >&2; return 2; } case "$4" in *$'\n'*) _mem_one_line status "$4"; return 2 ;; esac [ -s "$3" ] || { echo "memory: empty or missing body: $3" >&2; return 2; } + awk '/^```/ { n++ } END { exit n % 2 }' "$3" \ + || { echo "memory: body leaves a code fence open" >&2; return 2; } if [ "$1" = BLK ] && ! "$MEM_GREP" -q '`' "$3"; then echo "memory: a blocker body quotes ≥1 error in backticks" >&2; return 2 fi @@ -222,18 +285,22 @@ _mem_entry_text() { # <title> <body-file> <status> <supersedes> → stdout } _mem_add_locked() { # <file> <PREFIX> <entry-file> <supersedes> - local id bak rc=0 - id=$(_mem_next_id "$1" "$2") + local f="$1" id bak rc=0 + id=$(_mem_next_id "$f" "$2") bak=$(mktemp) || { echo "memory: no temp file" >&2; return 2; } - cat "$1" > "$bak" - { printf '\n## %s — ' "$id"; cat "$3"; } >> "$1" || rc=2 + cat "$f" > "$bak" + trap 'cat "$bak" > "$f"; rm -f "$bak"; _mem_unlock "$(_mem_lock_path)" + exit 130' INT TERM HUP + { printf '\n## %s — ' "$id"; cat "$3"; } >> "$f" || rc=2 if [ "$rc" = 0 ] && [ -n "$4" ]; then - _mem_insert "$1" "$4" "- **Status ($(_mem_date))**: superseded by $id" \ + _mem_insert "$f" "$4" "- **Status ($(_mem_date))**: superseded by $id" \ || rc=2 fi - if [ "$rc" = 0 ] && _mem_is_v2 "$1"; then memory_check_file "$1" || rc=2; fi + if [ "$rc" = 0 ] && memory_is_v2 "$f"; then + memory_check_file "$f" "$bak" || rc=2 + fi if [ "$rc" != 0 ]; then - cat "$bak" > "$1"; echo "memory: add refused, $1 restored" >&2 + cat "$bak" > "$f"; echo "memory: add refused, $f restored" >&2 else echo "$id"; fi rm -f "$bak" return "$rc" @@ -247,7 +314,7 @@ memory_add() { # <kind> <title> <body-file> <status> <supersedes> [ -f "$file" ] || { echo "memory: no registry: $file" >&2; return 2; } [ -z "$5" ] || _mem_has_id "$file" "$5" \ || { echo "memory: no entry $5 in $file" >&2; return 2; } - _mem_is_v2 "$file" || echo "memory: v1 registry (no format: 2): $file" >&2 + memory_is_v2 "$file" || echo "memory: v1 registry (no format: 2): $file" >&2 entry=$(mktemp) || { echo "memory: no temp file" >&2; return 2; } _mem_entry_text "$2" "$3" "$4" "$5" > "$entry" _mem_locked _mem_add_locked "$file" "${spec#* }" "$entry" "$5"; rc=$? @@ -280,75 +347,109 @@ _mem_prefix() { # <file> → the frontmatter entry_prefix, rc 2 when none echo "$p" } -memory_check_file() { # <file> → rc 2 with each culprit line named - local p - p=$(_mem_prefix "$1") || return 2 - awk -v p="$p" -v f="$1" ' +_mem_culprits() { # <file> <PREFIX> → "<line>\t<reason>" per culprit + awk -v p="$2" ' /^```/ { fence = !fence; next } fence { next } - $0 == "## Index" { print f ":" NR ": ## Index in a v2 registry"; bad = 1 } + $0 == "## Index" { print NR "\t## Index in a v2 registry" } !match($0, "^## " p "-[0-9]") { next } !match($0, "^## " p "-[0-9][0-9][0-9]+ — .") { - print f ":" NR ": heading shape: " $0; bad = 1; next } - seen[$2]++ { print f ":" NR ": duplicate " $2; bad = 1 } - END { exit bad ? 2 : 0 }' "$1" | sed 's/^/memory: /' >&2 - return "${PIPESTATUS[0]}" + print NR "\theading shape: " $0; next } + seen[$2]++ { print NR "\tduplicate " $2 } + END { if (fence) print NR "\tcode fence open at end of file" }' "$1" } -_MEM_REGISTRIES='decisions learnings blockers evals' +memory_check_file() { # <file> [<reference>] [<name>] → rc 2 on a culprit + # with a reference, only culprits absent from it count (a duplicate a + # merge left behind never blocks the next append) + local p ref="${2:-/dev/null}" name="${3:-$1}" + p=$(_mem_prefix "$1") || return 2 + [ -s "$ref" ] || ref=/dev/null + awk -F'\t' -v f="$name" ' + FILENAME == ARGV[1] { old[$2]++; next } + old[$2]-- > 0 { next } + { print "memory: " f ":" $1 ": " $2; bad = 1 } + END { exit bad ? 2 : 0 }' \ + <(_mem_culprits "$ref" "$p") <(_mem_culprits "$1" "$p") >&2 +} memory_check() { # [--staged] [<memory-dir>] → rc 2 on any culprit local staged="" dir f rc=0 [ "${1:-}" = --staged ] && { staged=1; shift; } dir="${1:-.claude/memory}" - for f in $_MEM_REGISTRIES; do + for f in $(_mem_names); do f="$dir/$f.md" + if [ -n "$staged" ]; then _mem_check_staged "$f" || rc=2; continue; fi [ -f "$f" ] || continue - if ! _mem_is_v2 "$f"; then echo "memory: v1: $f" >&2; continue; fi + if ! memory_is_v2 "$f"; then echo "memory: v1: $f" >&2; continue; fi memory_check_file "$f" || rc=2 - [ -z "$staged" ] || _mem_check_staged "$f" || rc=2 done return "$rc" } -_mem_check_staged() { # <file> → rc 2 when a staged hunk removes an entry line - local first - git cat-file -e "HEAD:./$1" 2>/dev/null || return 0 - first=$(git show "HEAD:./$1" | awk '/^```/ { fence = !fence; next } - !fence && /^## (BDR|LRN|BLK|EVAL)-[0-9]/ { print NR; exit }') +_mem_blob() { # <rev:path> <out file> → rc 1 when the blob is absent + git cat-file -e "$1" 2>/dev/null && git show "$1" > "$2" +} + +_mem_check_staged() { # <file> → rc 2 on a new culprit or a lost v2 file + local h s rc=0 + h=$(mktemp) || { echo "memory: no temp file" >&2; return 2; } + s=$(mktemp) || { rm -f "$h"; echo "memory: no temp file" >&2; return 2; } + _mem_blob "HEAD:./$1" "$h" || : > "$h" + _mem_blob ":./$1" "$s" || : > "$s" + if [ -s "$h" ] && memory_is_v2 "$h" && ! { [ -s "$s" ] && memory_is_v2 "$s"; } + then + echo "memory: $1: staged deletion, emptying or loss of format: 2" >&2 + rc=2 + elif [ -s "$s" ] && memory_is_v2 "$s"; then + memory_check_file "$s" "$h" "$1" || rc=2 + _mem_removed_lines "$1" "$h" || rc=2 + fi + rm -f "$h" "$s" + return "$rc" +} + +_mem_removed_lines() { # <file> <HEAD copy> → rc 2 when a hunk removes an + local p first # entry line (an Index sits above the first entry) + [ -s "$2" ] || return 0 + p=$(_mem_prefix "$2" 2>/dev/null) || return 0 + first=$(awk -v p="$p" '/^```/ { fence = !fence; next } + !fence && match($0, "^## " p "-[0-9]") { print NR; exit }' "$2") [ -n "$first" ] || return 0 git diff --cached -U0 -- "$1" | awk -v first="$first" -v f="$1" ' /^@@ / { split($2, a, ","); start = substr(a[1], 2) + 0 cnt = (2 in a) ? a[2] + 0 : 1 if (cnt > 0 && start + cnt - 1 >= first) { print "memory: " f ": line " start " removed inside an entry" \ - " (curation: /prune-memory then /commit-change)" + " (fix it, then commit with /commit-change)" bad = 1 } } END { exit bad ? 2 : 0 }' >&2 } -_mem_index_rows() { # <file> <PREFIX> → "ID | date | title | word" rows +_mem_index_rows() { # <file> <PREFIX> → "| ID | date | title | word |" rows awk -v p="$2" -v MEMW="$_MEM_WORDS" "$_MEM_AWK"' function row() { if (id != "") print "| " id " | " d " | " t " | " s " |" } /^```/ { fence = !fence; next } fence { next } /^## / { row(); id = "" if (!match($0, "^## " p "-[0-9]+")) next - id = $2; t = $0; sub(/^## [^ ]+( — )?/, "", t); d = ""; s = mem_tag(t) + id = $2; t = $0; sub(/^## [^ ]+( — )?/, "", t); d = "" + s = mem_word(mem_tag(t)) if (match(t, / \([0-9-]+\) *$/)) { d = substr(t, RSTART + 2, RLENGTH - 3); t = substr(t, 1, RSTART - 1) } else if (match(t, / — [0-9][0-9][0-9][0-9]-[0-9-]+ *$/)) { - d = substr(t, RSTART + 5); t = substr(t, 1, RSTART - 1) } + d = substr(t, RSTART); t = substr(t, 1, RSTART - 1) + sub(/^ — /, "", d) } sub(/ \[[^]]*\] *$/, "", t); gsub(/\|/, "/", t); next } id == "" { next } d == "" && sub(/^- \*\*Date\*\*: */, "") { d = substr($0, 1, 10) } - mem_cand($0) { s = mem_word($0) } + (w = mem_cand($0)) != "" { s = w } END { row() }' "$1" } memory_index() { # [<kind>] → one table per registry - local kinds="decision learning blocker eval" k spec file - [ -z "${1:-}" ] || kinds="$1" + local kinds k spec file + kinds=${1:-$(awk '{ print $1 }' <<< "$_MEM_TABLE")} for k in $kinds; do spec=$(_mem_kind "$k") || return 2 file=".claude/memory/${spec% *}" @@ -370,21 +471,18 @@ _mem_index_table() { # <file> → "ID<TAB>date<TAB>last column" per Index row _mem_upgrade_text() { # <rows> <file> <PREFIX> → the v2 text on stdout awk -v p="$3" -v today="$(_mem_date)" -v MEMW="$_MEM_WORDS" "$_MEM_AWK"' - function need(i, c, w) { - c = col[i]; w = mem_word(c) - if (p == "EVAL" || w == "") return "" - if (p == "LRN") return c ~ /^superseded by/ ? c : "" - if (st[i] == "" || (w ~ /^(superseded|deprecated)$/ && st[i] != w)) - return c - return "" } - function flush( i, s) { - if (cur != "" && (s = need(cur)) != "") + function flush( i, s, w) { + w = mem_word(col[cur]) + if (cur != "" && (s = mem_want(p, col[cur], st[cur])) != "") print "- **Status (" today ", upgrade)**: " s + else if (cur != "" && w != "" && p !~ /^(LRN|EVAL)$/ && w != st[cur]) + print "memory: " cur ": kept body " st[cur] ", dropped Index " \ + col[cur] > "/dev/stderr" for (i = 1; i <= n; i++) print buf[i] n = 0 } - FNR == 1 { pass++ } - pass == 1 { split($0, r, "\t"); dt[r[1]] = r[2]; col[r[1]] = r[3]; next } - pass == 2 { split($0, r, / \| /); sub(/^\| /, "", r[1]) + FILENAME == ARGV[1] { split($0, r, "\t"); dt[r[1]] = r[2] + col[r[1]] = r[3]; next } + FILENAME == ARGV[2] { split($0, r, / \| /); sub(/^\| /, "", r[1]) sub(/ \|$/, "", r[4]); hd[r[1]] = r[2] != ""; st[r[1]] = r[4] next } FNR == 1 { print; print "format: 2"; next } @@ -411,27 +509,39 @@ _mem_upgrade_oracle() { # <old> <new> <PREFIX> <rows> → rc 2 on a lost fact o=$(_mem_index_rows "$1" "$3"); n=$(_mem_index_rows "$2" "$3") awk -F'\t' -v p="$3" -v MEMW="$_MEM_WORDS" "$_MEM_AWK"' function f(s, k) { split(s, a, / \| /); return a[k] } - FNR == 1 { pass++ } - pass == 1 { dt[$1] = $2; col[$1] = $3; next } + FILENAME == ARGV[1] { dt[$1] = $2; col[$1] = $3; next } { id = f($0, 1); sub(/^\| /, "", id) } - pass == 2 { old[id] = f($0, 4); sub(/ \|$/, "", old[id]); next } + FILENAME == ARGV[2] { old[id] = f($0, 4); sub(/ \|$/, "", old[id]); next } !(id in col) { next } - { d = f($0, 2); s = f($0, 4); sub(/ \|$/, "", s); w = mem_word(col[id]) - if (p == "LRN" && col[id] !~ /^superseded by/) w = "" - if (p == "EVAL") w = "" - want = (w ~ /^(superseded|deprecated)$/ || old[id] == "") ? w : old[id] + { d = f($0, 2); s = f($0, 4); sub(/ \|$/, "", s) + m = mem_want(p, col[id], old[id]) + want = m != "" ? mem_word(m) : old[id] if (dt[id] != "" && d == "") bad = bad " " id ":date" if (want != "" && s != want) bad = bad " " id ":" s "!=" want } END { if (bad != "") { print "memory: upgrade lost:" bad; exit 2 } }' \ "$4" <(printf '%s\n' "$o") <(printf '%s\n' "$n") >&2 } -_mem_upgrade_file() { # <file> → rc 0 upgraded or already v2, rc 2 refused - local p rows new rc=0 first +_mem_upgrade_ready() { # <file> → rc 0 upgradable, 1 already v2, 2 refused + local first p IFS= read -r first < "$1" [ "$first" = --- ] \ || { echo "memory: $1: no frontmatter, not upgraded" >&2; return 2; } - _mem_is_v2 "$1" && { echo "memory: $1 already v2" >&2; return 0; } + memory_is_v2 "$1" && { echo "memory: $1 already v2" >&2; return 1; } + p=$(_mem_prefix "$1") || return 2 + awk -v p="$p" '/^```/ { fence = !fence; next } + !fence && match($0, "^## " p "-[0-9]+") \ + && substr($0, RLENGTH + 1) !~ /^( — |$)/ { + print "memory: " FILENAME ": heading dialect \"" \ + substr($0, RLENGTH + 1, 3) "\": not upgraded"; bad = 1; exit } + END { exit bad ? 2 : 0 }' "$1" >&2 +} + +_mem_upgrade_file() { # <file> → rc 0 upgraded or already v2, rc 2 refused + local p rows new rc=0 + _mem_upgrade_ready "$1"; rc=$? + [ "$rc" = 1 ] && return 0 + [ "$rc" = 0 ] || return 2 p=$(_mem_prefix "$1") || return 2 rows=$(mktemp) || { echo "memory: no temp file" >&2; return 2; } new=$(mktemp) || { rm -f "$rows"; echo "memory: no temp file" >&2; return 2; } @@ -447,7 +557,7 @@ _mem_upgrade_file() { # <file> → rc 0 upgraded or already v2, rc 2 refused memory_upgrade() { # [<memory-dir>] → every template-born registry to v2 local dir="${1:-.claude/memory}" f rc=0 - for f in $_MEM_REGISTRIES; do + for f in $(_mem_names); do [ -f "$dir/$f.md" ] || continue _mem_upgrade_file "$dir/$f.md" || rc=2 done diff --git a/docs/superpowers/plans/memory-v2-write/memory.test.sh b/docs/superpowers/plans/memory-v2-write/memory.test.sh index a0b12b9..58a0743 100644 --- a/docs/superpowers/plans/memory-v2-write/memory.test.sh +++ b/docs/superpowers/plans/memory-v2-write/memory.test.sh @@ -5,7 +5,7 @@ # real check on this repo's registries. set -u ROOT="$(cd "$(dirname "$0")/../.." && pwd)" -MEM="${MEM_UNDER_TEST:-$ROOT/lib/memory.sh}" +MEM="$ROOT/lib/memory.sh" pass=0; fail=0 check() { if [ "$2" = "$3" ]; then pass=$((pass+1)); else fail=$((fail+1)); printf 'FAIL %s: got[%s] want[%s]\n' "$1" "$2" "$3"; fi; } @@ -59,6 +59,9 @@ check T2b-blocker-needs-backtick "$?" 2 check T2c-unchanged "$(cksum < "$B")" "$sum" bash "$MEM" add learning --title t --body-file plain.md >/dev/null check T2d-learning-without-backtick "$?" 0 +printf 'x\n```\nopen fence\n' > fence.md +bash "$MEM" add learning --title f --body-file fence.md 2>/dev/null +check T2e-open-fence-body "$?" 2 # T3 status: a dated line ends the entry, before the next heading's blank bash "$MEM" status BLK-001 'resolved abc1234' @@ -72,6 +75,11 @@ bash "$MEM" status BLK-404 x 2>/dev/null check T3e-unknown-id "$?" 2 bash "$MEM" status BLK-001 "$(printf 'a\nb')" 2>/dev/null check T3f-multi-line "$?" 2 +bash "$MEM" status BLK-001 'reopened by abc' 2>/dev/null +check T3g-needs-status-word "$?" 2 +bash "$MEM" status BLK-002 'open \b \n \| kept' +check T3h-backslash-verbatim "$(tail -1 "$B")" \ + '- **Status (2026-10-27)**: open \b \n \| kept' # T4 journal: appended under today, heading created once, old date untouched J=.claude/memory/journal.md @@ -82,6 +90,8 @@ check T4b-order "$(tail -2 "$J" | tr '\n' '|')" '- first|- second|' check T4c-old-kept "$(sed -n '/^## 2026-10-26$/,/^$/p' "$J" | grep -c '^- old$')" 1 bash "$MEM" journal "$(printf 'a\nb')" 2>/dev/null check T4d-multi-line "$?" 2 +bash "$MEM" journal 'grep \bword\b w/ \n' +check T4e-backslash-verbatim "$(tail -1 "$J")" '- grep \bword\b w/ \n' # T5 --supersedes: forward link on the new entry, status line on the old one L=.claude/memory/learnings.md @@ -134,6 +144,21 @@ mkdir v1 && printf '# Decisions\n\n## BDR-001 - legacy\n' > v1/decisions.md err=$(bash "$MEM" check v1 2>&1 >/dev/null); rc=$? check T7e-v1-rc "$rc" 0 check T7f-v1-named "$(printf '%s\n' "$err" | grep -c '^memory: v1: v1/decisions.md$')" 1 +printf '\n## BDR-006 — fenced\n```\nx\n' >> .claude/memory/decisions.md +err=$(bash "$MEM" check 2>&1 >/dev/null); rc=$? +check T7g-open-fence-rc "$rc" 2 +check T7h-open-fence-named "$(printf '%s\n' "$err" | grep -c 'fence open at end')" 1 +cat d.bak > .claude/memory/decisions.md +# a duplicate a merge left behind blocks neither add nor a staged append +printf '\n## BDR-005 — merged twice (2026-10-27)\nx\n' >> .claude/memory/decisions.md +check T7i-dup-still-adds "$(bash "$MEM" add decision --title after --body-file plain.md)" BDR-006 +check T7j-dup-still-reported "$(bash "$MEM" check >/dev/null 2>&1; echo $?)" 2 +git add -A && git commit -qm dup +bash "$MEM" add decision --title later --body-file plain.md >/dev/null +git add .claude/memory/decisions.md +check T7k-dup-staged-append "$(bash "$MEM" check --staged >/dev/null 2>&1; echo $?)" 0 +git reset -q +cat d.bak > .claude/memory/decisions.md # T8 check --staged: an append passes, a removed entry line is rc 2 git add -A && git commit -qm base @@ -148,6 +173,12 @@ err=$(bash "$MEM" check --staged 2>&1 >/dev/null); rc=$? check T8b-removed-line-rc "$rc" 2 check T8c-named "$(printf '%s\n' "$err" | grep -c 'removed inside an entry')" 1 git checkout -q HEAD -- "$B" +cp "$B" b.keep +sed '/^format: 2$/d' b.keep > "$B" && git add "$B" +check T8d-downgrade-refused "$(bash "$MEM" check --staged >/dev/null 2>&1; echo $?)" 2 +git rm -q --cached "$B" +check T8e-deletion-refused "$(bash "$MEM" check --staged >/dev/null 2>&1; echo $?)" 2 +git reset -q && cat b.keep > "$B" # T9 upgrade: Index-only dates and statuses become body lines, the marker # lands, the Index goes, headings untouched; idempotent; refusals keep the file @@ -168,6 +199,7 @@ entry_prefix: BDR | BDR-002 | 2026-01-02 | stale index | accepted | | BDR-003 | 2026-01-03 | gone | superseded by BDR-004 | | BDR-004 | 2026-01-04 | no status | accepted | +| BDR-005 | 2026-01-05 | suffix date | accepted | --- @@ -183,6 +215,9 @@ entry_prefix: BDR ## BDR-004 — no status body + +## BDR-005 — suffix date — 2026-01-05 +- **Status**: accepted EOF cat > .claude/memory/learnings.md <<'EOF' --- @@ -207,13 +242,17 @@ y EOF D=.claude/memory/decisions.md heads=$(grep '^## BDR-' "$D") -bash "$MEM" upgrade >/dev/null 2>&1 -check T9-rc "$?" 0 +err=$(bash "$MEM" upgrade 2>&1 >/dev/null); rc=$? +check T9-rc "$rc" 0 +check T9n-dropped-named "$(printf '%s\n' "$err" | grep -c '^memory: BDR-002: kept body shipped, dropped Index accepted$')" 1 check T9b-marker "$(sed -n 2p "$D")" 'format: 2' check T9c-no-index "$(grep -c '^## Index$\|^| BDR-' "$D")" 0 check T9d-headings-same "$(grep '^## BDR-' "$D")" "$heads" check T9e-index-out "$(bash "$MEM" index decision | sed -n '5,8p' | tr '\n' '#')" \ '| BDR-001 | 2026-01-01 | kept | accepted |#| BDR-002 | 2026-01-02 | stale index | shipped |#| BDR-003 | 2026-01-03 | gone | superseded |#| BDR-004 | 2026-01-04 | no status | accepted |#' +for loc in C en_US.UTF-8; do + check "T9r-suffix-date-$loc" "$(LC_ALL=$loc bash "$MEM" index decision | grep -c '^| BDR-005 | 2026-01-05 | suffix date | accepted |$')" 1 +done check T9f-lrn-superseded "$(bash "$MEM" index learning | grep -c '^| LRN-001 | 2026-02-01 | old | superseded |$')" 1 check T9g-lrn-applies-dropped "$(grep -c 'any shell' .claude/memory/learnings.md)" 0 check T9h-check-green "$(bash "$MEM" check; echo $?)" 0 @@ -245,6 +284,15 @@ printf '# Evals\n\n## EVAL-001 | 2026 | pipe dialect\n' > .claude/memory/evals.m bash "$MEM" upgrade >/dev/null 2>&1 check T9l-no-frontmatter-rc "$?" 2 check T9m-dialect-untouched "$(sed -n 1p .claude/memory/evals.md)" '# Evals' +printf -- '---\ntype: evals_registry\nentry_prefix: EVAL\n---\n\n## Index\n\n| ID | Date | Output | Action |\n|----|------|--------|--------|\n\n## EVAL-001 - hyphen dialect\nx\n' \ + > .claude/memory/evals.md +err=$(bash "$MEM" upgrade 2>&1 >/dev/null) +check T9o-hyphen-refused "$(printf '%s\n' "$err" | grep -c 'heading dialect " - ": not upgraded')" 1 +printf -- '---\ntype: evals_registry\nentry_prefix: EVAL\n---\n\n## Index\n\n| ID | Date | Output | Action |\n|----|------|--------|--------|\n\n## EVAL-001 — empty index (2026-04-01)\nx\n' \ + > .claude/memory/evals.md +bash "$MEM" upgrade >/dev/null 2>&1 +check T9p-empty-index-upgraded "$(sed -n 2p .claude/memory/evals.md)" 'format: 2' +check T9q-empty-index-heading "$(grep -c '^## EVAL-001 — empty index' .claude/memory/evals.md)" 1 cd "$FIX" || exit 1 # T10 parser: header tag and labelled lines only, last wins, open ranks last @@ -255,6 +303,22 @@ check T10c-fail-open-ignored "$(word st.md BLK-034)" resolved check T10d-final-wins "$(word st.md BLK-008)" resolved check T10e-accepted-before-open "$(word st.md BLK-040)" accepted check T10f-mid-title-bracket "$(word st.md BLK-041)" open +check T10h-title-prose-ignored "$(word st.md BLK-043)" open +check T10i-dated-lead-word "$(word st.md BLK-044)" open +# shellcheck source=/dev/null +check T10j-tag-only "$(. "$MEM"; memory_entry_status st.md BLK-043)" '[open]' +closed() { # <word> → yes when memory_closed accepts it + # shellcheck source=/dev/null + (. "$MEM"; memory_closed "$1") && echo yes || echo no; } +check T10k-closed "$(closed resolved)$(closed superseded)$(closed deprecated)" yesyesyes +check T10l-not-closed "$(closed accepted)$(closed open)$(closed upstream)" nonono +mkdir -p v1h/.claude/memory +printf '# Blockers\n\n## BLK-001 - hyphen\n- **Status**: resolved\n\n## BLK-002 | 2026-05-18 | pipe\nStatus: open\n' \ + > v1h/.claude/memory/blockers.md +check T10m-hyphen-dialect "$(word v1h/.claude/memory/blockers.md BLK-001)" resolved +check T10n-pipe-dialect "$(word v1h/.claude/memory/blockers.md BLK-002)" open +bash "$MEM" -C v1h status BLK-002 'resolved by abc' 2>/dev/null +check T10o-status-on-v1-pipe "$(word v1h/.claude/memory/blockers.md BLK-002)" resolved # shellcheck source=/dev/null (. "$MEM"; memory_entry_status st.md BLK-042) >/dev/null check T10g-no-candidate-rc "$?" 1