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 681873e..a760082 100644
--- a/docs/superpowers/plans/2026-10-27-memory-v2-write.md
+++ b/docs/superpowers/plans/2026-10-27-memory-v2-write.md
@@ -4,13 +4,13 @@
**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 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.
+**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. Revision r3 (2026-10-28) after the confirmation round (CONCERNS(1) / CONCERNS(3) / CONCERNS(3), no BLOCKER): any-level ID allocation, open fence always refused, v1 status as a body line, one verified backup + trap for every writer, token lock with a serialized steal, exact journal key, staged-dir guard.
**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 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.
+**Reference implementation (proven r3):** `docs/superpowers/plans/memory-v2-write/` holds `memory.sh`, `memory.test.sh`, `blockers-v2-status.md`, `blockers-v1-dialects.md`. Proven on a `git clone --shared` of this repo through `make test`: suite `PASS=112 FAIL=0` five runs in a row and under `LC_ALL=C` (the 15 r3 checks T14* are red against the r2 lib, 12 of them), 12 concurrent writers starting from a stale lock: 0 overlaps, 12 distinct IDs, no lock left (3 rounds), 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, 3 and 4 code below was applied to that clone and run through `make test` (run-reconcile 28 GREEN / 1 RED where the red is T6c, the gitignored `skills/darwin-skill` absent from a clone; run-deterministic 18/18; memory suite with T13 122/122). `_mem_next_id` equals max heading ID + 1 on all 59 registries of the 15 repos on this machine (r2 gave BDR-001 / LRN-001 / BLK-001 on trucks_at_work's `###` registries: duplicates). Task 1 copies the files; do not rewrite them.
## Global Constraints
@@ -27,22 +27,23 @@
## Deviations from the spec (named for the human gate)
-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.
+1. **Lock and backup**: the lock is 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). It holds ` .` and is removed only by its owner's token. A lock older than 30 s, or seen empty on 10 consecutive tries (holder died between create and write), is stolen by one waiter at a time (`memory.lock.steal`, itself noclobber, age re-read under it). Every writer (`add`, `status`, `journal`, `upgrade`) runs on a backup of its file verified by `cmp` (rc 2 before any write if the copy is short), restored on failure or on INT/TERM/HUP; the caller's own traps are saved and put back. No EXIT trap: a sourced lib must not own the caller's EXIT. **Residuals for the gate:** (a) a holder alive but slower than 30 s loses the lock to a stealer and both write (its token no longer matches, so it never removes the new lock); (b) a stealer that dies holding `memory.lock.steal` makes the next waiter clear it once older than 30 s; two waiters doing that at the same moment can both enter the steal section. Both need a crash or a 30 s stall; a write lost that way shows as a `check` culprit (duplicate ID) or a missing entry, never silently in v2.
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.
+6. **Heading dialects**: `mem_key` accepts `## ID` followed by any non-alphanumeric char (` — `, ` - `, ` | `), so `status` and `--supersedes` work on v1 hyphen and pipe files. ID allocation reads every heading level, fenced or not (`### BDR-001` in trucks_at_work, a stray fence elsewhere), and a v1 add whose ID already sits in any heading is refused. `status` on a `###` registry stays rc 2 "no entry" (loud, not silent). A v1 `add --status s` writes `- **Status**: s` as the first body line instead of a heading tag: the v1 reconcile reader never reads the entry's own heading. 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.
+9. **`--staged` removal rule**: a removed line counts only from the first entry heading down (the spec said any `-` line). The Index sits above the first entry, so Task 7's upgrade commit goes through memory-commit like any memory commit; the diff runs with `-c diff.interHunkContext=0 --no-color --no-ext-diff --no-textconv` so user git config cannot fold or hide hunks. An open code fence always counts as a culprit, even when it predates the commit (it hides headings from allocation).
## Review Focus
-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.
+1. **Concurrent writers.** The noclobber lock is proven by T6e/T6f (red with the mkdir lock on this host) and T14i (12 writers from a stale lock). Unlock by token (T14g), empty-lock steal (T14h). Every writer restores its verified backup on failure or signal and frees the lock. Residuals named in Deviation 1.
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.
+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), except an open code fence, which always blocks until fixed (T14e/f); the upgrade commit passes (Index lines sit above the first entry); a refused commit leaves nothing staged.
---
@@ -54,7 +55,7 @@
- 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 (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`.
+**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 `, `memory_check [--staged] []` (prints `memory: v1: ` per v1 registry on stderr, the banner's input), `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 four files**
@@ -68,7 +69,7 @@ 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` three times → each ends `PASS=97 FAIL=0` and `all suites green` (T6e race must be stable).
+Run: `make test suite=lib/tests/memory.test.sh` three times → each ends `PASS=112 FAIL=0` and `all suites green` (T6e and T14i races 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.
@@ -86,7 +87,7 @@ git commit -m "feat(memory): lib/memory.sh single registry writer — add/status
**Files:**
- 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`
+- Modify: `skills/reconcile/SKILL.md:25` and `:54`
**Interfaces:** consumes `memory_is_v2`, `memory_entry_status`, `memory_status_word`, `memory_closed`. `reconcile_blk_current_status` and `reconcile_blk_open` keep their signatures.
@@ -104,6 +105,16 @@ 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
+v1w=$(mktemp -d)
+mkdir "$v1w/.claude" "$v1w/.claude/memory"
+printf '# Blockers\n' > "$v1w/.claude/memory/blockers.md"
+printf -- '- **Cause**: `x`\n' > "$v1w/b.md"
+bash "$REPO/memory.sh" -C "$v1w" add blocker --title fixed \
+ --body-file "$v1w/b.md" --status resolved >/dev/null 2>&1
+open_v1w=$(reconcile_blk_open "$v1w/.claude/memory/blockers.md" | cut -f1)
+if [ -z "$open_v1w" ]; then ok "T8d lib-written v1 blocker --status resolved reads closed"; else no "T8d lib-written v1 blocker reads open [$open_v1w]"; fi
+rm -f "$v1w/.claude/memory/blockers.md" "$v1w/b.md"
+rmdir "$v1w/.claude/memory" "$v1w/.claude" "$v1w"
```
- [ ] **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).
@@ -153,9 +164,9 @@ reconcile_blk_open() {
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** — `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).
+- [ ] **Step 4: Run, expect green** — `make test suite=lib/tests/run-reconcile.sh` → `29 GREEN / 0 RED` (T1-T7 unchanged, T8a/b/c/d green; T8d is red against the r2 lib, which put the status in the heading tag the v1 reader drops). `make test suite=lib/tests/run-review-guards.sh` → green (G4: T8 reads fixtures only).
-- [ ] **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 5: Skill lines** — `skills/reconcile/SKILL.md:54`: `→ 25/25,` → `→ 29/29,`. `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**
@@ -228,8 +239,9 @@ if [ "$rc" -eq 0 ] && [ -n "$out" ]; then ok "append to a v2 registry → commit
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
+ culprit (duplicate ID, heading shape); an open
+ code fence counts even when it predates the
+ commit. Fix the file, then commit the fix with
/commit-change; never bypass the helper.
```
@@ -259,14 +271,17 @@ for t in decisions learnings blockers evals; do
check "T13b-template-$t-no-index" "$(grep -c '^## Index$' "$ROOT/templates/memory/$t.md")" 0
done
banner() { (cd "$1" && SESSION_START_OFFLINE=1 bash "$ROOT/hooks/session-start.sh" \
- /dev/null); }
-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
+ /dev/null) | grep -c "${2:-registry v1}"; }
+check T13c-banner-v1-v2 "$(banner "$FIX/v1h" 'registry v1: 1 file(s) (memory.sh check)')/$(banner "$FIX")" 1/0
+cp "$FIX/v1h/.claude/memory/blockers.md" v1h.bak
+printf -- '---\nformat: 2\n---\n' > "$FIX/v1h/.claude/memory/blockers.md"
+check T13d-banner-flips-off "$(banner "$FIX/v1h")" 0
+cat v1h.bak > "$FIX/v1h/.claude/memory/blockers.md"
```
-(`$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.)
+(`$FIX/v1h` is the v1 pipe/hyphen project T10 built; `$FIX/.claude/memory` is v2. T13c reads both projects in one check (`1/0`), red until the banner exists; T13d turns the same v1 project v2 and expects the line gone. The hook resolves `memory.sh` next to itself, so the test exercises `$ROOT/lib/memory.sh`, never the installed copy.)
-- [ ] **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` → 9 checks red (the eight template checks and T13c); T13d is green before and after, it guards the flip-off once T13c is green.
- [ ] **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 `## `):
@@ -289,15 +304,11 @@ decisions → `decision`, ``, `[accepted]`, labels Decision / Why / Rejec
```bash
# Registry v1 (BDR-125 phase 4a): a project registry without `format: 2`.
+# The lib names each v1 registry on stderr (`memory: v1: `).
_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")
+ _v1=$(bash "$_mem_lib" check .claude/memory 2>&1 >/dev/null \
+ | grep -c '^memory: v1:' || true)
if [ "${_v1:-0}" -gt 0 ]; then
printf "│ ⚠️ %-44s│\n" "registry v1: ${_v1} file(s) (memory.sh check)"
fi
@@ -308,7 +319,7 @@ unset _mem_lib
- [ ] **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` → `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 6: Run, expect green** — `make test suite=lib/tests/memory.test.sh` → `PASS=122 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**
@@ -323,7 +334,7 @@ git commit -m "feat(memory): templates born v2 (format: 2, no Index); session ba
**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`.
-- [ ] **Step 1: The one WRITE section** — in `lib/capitalize-commit.md`, insert before `## DO`:
+- [ ] **Step 1: The one WRITE section** — in `lib/capitalize-commit.md`, first the intro: `Inline snippet. Include at the END of any dev flow's CAPITALIZE step, AFTER the` / `approved registry / journal / TODO entries are written. It commits ONLY the` → `Inline snippet for any dev flow's CAPITALIZE step: § WRITE says how the approved` / `registry and journal entries are written, then the rest commits ONLY the` (the two lines after it unchanged), and `decide WHAT to write are unchanged and run before this snippet. Only the COMMIT` / `of the already-approved entries is automated here.` → `decide WHAT to write are unchanged and run before this snippet; § WRITE then` / `writes them through lib/memory.sh and the COMMIT is automated here.`. Then insert before `## DO`:
```
## WRITE (before the commit)
@@ -342,8 +353,9 @@ never by Edit or append; there is no `## Index` to update.
starting with a status word (`resolved abc1234`, `open, reopened by …`,
`superseded by BDR-NNN`).
- Journal: `bash "$HOME/.claude/lib/memory.sh" journal ""`.
-- rc 2 names its reason (title chars, empty body, open code fence, unknown
- ID): fix the input and re-run.
+- rc 2 names its reason (title chars, empty body, a status not starting
+ with a status word, an open code fence in the body or the registry,
+ unknown ID, lock busy): fix the input and re-run.
```
- [ ] **Step 2: capitalize**
@@ -474,6 +486,8 @@ git commit -m "feat(prune-memory): v2 registries — § D dropped, status and me
**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 0: Clean memory precondition** — `git diff --quiet HEAD -- .claude/memory .claude/tasks || { echo "STOP: uncommitted memory or tasks; commit them first"; exit 1; }`. The rollback below and the memory-commit sweep both rely on it.
+
- [ ] **Step 1: Upgrade in place and commit through the chokepoint**
```bash
@@ -481,7 +495,7 @@ bash lib/memory.sh upgrade
bash lib/memory.sh check && echo CHECK-OK
bash "$HOME/.claude/lib/memory-commit.sh" commit "chore(memory): registries v2 — Index removed, Index-only dates and statuses materialized (memory.sh upgrade)"
```
-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.
+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: each file is already restored from its verified backup; `git checkout -- .claude/memory` (safe only after Step 0) puts any upgraded sibling back, report the stderr, stop.
- [ ] **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).
diff --git a/docs/superpowers/plans/memory-v2-write/memory.sh b/docs/superpowers/plans/memory-v2-write/memory.sh
index 34d7135..f45f232 100644
--- a/docs/superpowers/plans/memory-v2-write/memory.sh
+++ b/docs/superpowers/plans/memory-v2-write/memory.sh
@@ -25,9 +25,12 @@
# words in _MEM_WORDS order, `open` last: "accepted, check OPEN" = accepted.
# Closed = resolved | superseded | deprecated (memory_closed).
# Lock: /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; free text reaches awk through
-# ENVIRON, never `-v` (which expands backslash escapes).
+# absent on macOS), holding " "; released only by its token;
+# a lock older than 30 s (or seen empty 10 times) is stolen by one waiter
+# at a time (memory.lock.steal). Every writer runs on a verified backup
+# of its file, restored on failure or signal. Next ID = max over headings
+# of any level, fenced or not. Free text reaches awk through ENVIRON,
+# never `-v` (which expands backslash escapes).
MEM_GREP="${MEM_GREP:-/usr/bin/grep}"
_MEM_TABLE='decision decisions BDR
@@ -75,31 +78,36 @@ function mem_want(p, c, st, w) {
_mem_date() { printf '%s\n' "${MEMORY_DATE:-$(date +%F)}"; }
-_mem_row() { # → "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_table() { # [ ] → matching cells, rc 2 if none
+ # the one reader of _MEM_TABLE (1 kind, 2 registry basename, 3 prefix)
+ awk -v o="$1" -v c="${2:-0}" -v v="${3:-}" '
+ c == 0 || $c == v { print $o; f = 1 }
+ 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_names() { _mem_table 2; } # the four registry basenames
_mem_kind() { # → ".md ", rc 2 when unknown
- local row file prefix
- row=$(_mem_row 1 "$1") || {
+ local file
+ file=$(_mem_table 2 1 "$1") || {
echo "memory: unknown kind: $1 (decision|learning|blocker|eval)" >&2
return 2; }
- read -r _ file prefix <<< "$row"
- echo "$file.md $prefix"
+ echo "$file.md $(_mem_table 3 1 "$1")"
}
_mem_id_file() { # → its registry path, rc 2 when the prefix is unknown
- local row file
- row=$(_mem_row 3 "${1%%-[0-9]*}") \
+ local file
+ file=$(_mem_table 2 3 "${1%%-[0-9]*}") \
|| { echo "memory: not an entry ID: $1" >&2; return 2; }
- read -r _ file _ <<< "$row"
echo ".claude/memory/$file.md"
}
+_mem_prefix() { # → its prefix by basename, rc 2 if none
+ local base="${1##*/}"
+ _mem_table 3 2 "${base%.md}" \
+ || { echo "memory: $1: not a registry name" >&2; return 2; }
+}
+
memory_is_v2() { # → rc 0 when the frontmatter carries `format: 2`
awk 'NR == 1 && $0 != "---" { exit }
NR > 1 && $0 == "---" { exit }
@@ -116,14 +124,24 @@ _mem_has_id() { # → rc 0 when a heading carries the ID
}
_mem_next_id() { # → max heading ID + 1, zero-padded
+ # every heading level, fenced or not: a gap is harmless, a duplicate is
+ # not (trucks_at_work writes `### BDR-001`; a stray fence hides headings)
awk -v p="$2" '
- /^```/ { fence = !fence; next }
- !fence && match($0, "^## " p "-[0-9]+") {
- n = substr($0, length(p) + 5, RLENGTH - length(p) - 4) + 0
- if (n > m) m = n }
+ match($0, "^#+ *" p "-[0-9]+") {
+ n = substr($0, RSTART, RLENGTH); sub(/^#+ *[A-Z]+-/, "", n)
+ if (n + 0 > m) m = n + 0 }
END { printf "%s-%03d\n", p, m + 1 }' "$1"
}
+_mem_heading_has() { # → rc 0 when a heading of any level has it
+ awk -v id="$2" 'match($0, "^#+ *" id "([^0-9]|$)") { f = 1; exit }
+ END { exit !f }' "$1"
+}
+
+_mem_fence_open() { # → rc 0 when a ``` fence is left open
+ awk '/^```/ { n++ } END { exit !(n % 2) }' "$1"
+}
+
memory_entry_status() { # → 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"'
@@ -157,17 +175,32 @@ _mem_lock_path() { # → the lock file for the current repository
echo "${TMPDIR:-/tmp}/memory-$(pwd | cksum | cut -d' ' -f1).lock"
}
-_mem_lock() { # → rc 0 held, rc 2 after MEM_LOCK_TRIES waits
+_mem_stale() { # → rc 0 when stealable
+ local t="${1%% *}"
+ if [ -z "$1" ]; then [ "$2" -ge 10 ]; return; fi
+ case "$t" in ''|*[!0-9]*) return 1 ;; esac
+ [ $(( $(date +%s) - t )) -gt 30 ]
+}
+
+_mem_steal() { # → remove a stale lock; one stealer at a time
+ local g="$1.steal" seen
+ if ! (set -C; date +%s > "$g") 2>/dev/null; then
+ _mem_stale "$(cat "$g" 2>/dev/null) x" 0 && rm -f "$g" # dead stealer
+ return 0
+ fi
+ seen=$(cat "$1" 2>/dev/null)
+ _mem_stale "$seen" 10 && rm -f "$1" # age re-read under the guard
+ rm -f "$g"
+}
+
+_mem_lock() { # → rc 0 held, rc 2 after MEM_LOCK_TRIES
# noclobber = open(O_EXCL) by bash itself: mkdir is not atomic under
# uutils coreutils 0.10 (two concurrent mkdir both succeed)
- local lock="$1" tries=0 now t
- 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 # steal: rename first, never rm shared
- mv "$lock" "$lock.stale.$$" 2>/dev/null && rm -f "$lock.stale.$$"
- continue
- fi
+ local lock="$1" tries=0 empty=0 t
+ until (set -C; echo "$(date +%s) $2" > "$lock") 2>/dev/null; do
+ t=$(cat "$lock" 2>/dev/null)
+ if [ -z "$t" ]; then empty=$((empty + 1)); else empty=0; fi
+ if _mem_stale "$t" "$empty"; then _mem_steal "$lock"; continue; fi
tries=$((tries + 1))
[ "$tries" -lt "${MEM_LOCK_TRIES:-50}" ] \
|| { echo "memory: lock busy: $lock" >&2; return 2; }
@@ -175,16 +208,45 @@ _mem_lock() { # → rc 0 held, rc 2 after MEM_LOCK_TRIES waits
done
}
-_mem_unlock() { rm -f "$1"; }
+_mem_unlock() { # → remove the lock only when it is ours
+ [ "$(cut -d' ' -f2 < "$1" 2>/dev/null)" = "$2" ] && rm -f "$1"
+ return 0
+}
-_mem_locked() { # [args…] → run fn under the lock, its rc
- local lock rc
- 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"
+_mem_restore() { # → put the verified copy back if changed
+ [ -s "$1" ] || return 0
+ cmp -s "$1" "$2" && return 0
+ cat "$1" > "$2" && echo "memory: $2 restored" >&2
+}
+
+_mem_backed() { # [args…] → fn on a verified backup of ,
+ # restored when fn fails or a signal lands. Runs inside _mem_locked: the
+ # trap reads that frame's __mem_lock / __mem_tok (dynamic scope), and
+ # every name here is __-prefixed so fn's own locals never shadow it.
+ local __mem_bak __mem_file="$2" __mem_old __mem_rc
+ __mem_bak=$(mktemp) || { echo "memory: no temp file" >&2; return 2; }
+ if ! { cat "$2" > "$__mem_bak" && cmp -s "$2" "$__mem_bak"; }; then
+ rm -f "$__mem_bak"; echo "memory: backup of $2 failed, nothing written" >&2
+ return 2
+ fi
+ __mem_old=$(trap -p INT TERM HUP)
+ trap '_mem_restore "$__mem_bak" "$__mem_file"
+ _mem_unlock "$__mem_lock" "$__mem_tok"; exit 130' INT TERM HUP
+ "$@"; __mem_rc=$?
+ trap - INT TERM HUP; eval "$__mem_old"
+ [ "$__mem_rc" = 0 ] || _mem_restore "$__mem_bak" "$__mem_file"
+ rm -f "$__mem_bak"
+ return "$__mem_rc"
+}
+
+_mem_locked() { # [args…] → fn under the lock, its rc; fn's
+ local __mem_lock __mem_tok out rc # stdout is printed after the unlock
+ __mem_lock=$(_mem_lock_path); __mem_tok="$$.$RANDOM"
+ out=$(mktemp) || { echo "memory: no temp file" >&2; return 2; }
+ _mem_lock "$__mem_lock" "$__mem_tok" || { rm -f "$out"; return 2; }
+ _mem_backed "$@" > "$out"; rc=$?
+ _mem_unlock "$__mem_lock" "$__mem_tok"
+ cat "$out"; rm -f "$out"
return "$rc"
}
@@ -194,22 +256,26 @@ _mem_one_line() { # → rc 2 when empty or multi-line
esac
}
-_mem_insert() { # → line ends the section, rc 1 if absent
- local tmp
+_mem_insert() { # [exact] → line ends the section,
+ local tmp # rc 1 if absent; exact: the heading is `## ` alone
tmp=$(mktemp) || { echo "memory: no temp file" >&2; return 2; }
- MEM_K="$2" MEM_INS="$3" awk "$_MEM_AWK"'
- BEGIN { k = ENVIRON["MEM_K"]; ins = ENVIRON["MEM_INS"] }
+ MEM_K="$2" MEM_INS="$3" MEM_X="${4:-}" awk "$_MEM_AWK"'
+ BEGIN { k = ENVIRON["MEM_K"]; ins = ENVIRON["MEM_INS"]
+ x = ENVIRON["MEM_X"] != "" }
+ function hit(l) { return x ? l == "## " k : mem_key(l, k) }
function flush( i) { print ins; for (i = 1; i <= n; i++) print buf[i]
n = 0; done = 1 }
/^```/ { fence = !fence }
on && !fence && /^## / { flush(); on = 0 }
- !done && !on && !fence && mem_key($0, k) { on = 1; print; next }
+ !done && !on && !fence && hit($0) { on = 1; print; next }
on { if ($0 == "" || $0 == "---") { buf[++n] = $0; next }
for (i = 1; i <= n; i++) print buf[i]; n = 0; print; next }
{ print }
END { if (on) flush(); exit !done }' "$1" > "$tmp"
case $? in
- 0) cat "$tmp" > "$1" || { rm -f "$tmp"; return 2; } ;;
+ 0) cat "$tmp" > "$1" || {
+ echo "memory: write-back of $1 failed; full copy kept: $tmp" >&2
+ return 2; } ;;
*) rm -f "$tmp"; return 1 ;;
esac
rm -f "$tmp"
@@ -240,7 +306,7 @@ memory_status() { #
}
_mem_journal_locked() { #
- _mem_insert "$1" "$2" "$3"
+ _mem_insert "$1" "$2" "$3" exact
case $? in
1) printf '\n## %s\n%s\n' "$2" "$3" >> "$1" ;;
0) return 0 ;;
@@ -264,8 +330,9 @@ _mem_add_valid() { #
esac
[ "${#2}" -le 160 ] || { echo "memory: title over 160 chars" >&2; return 2; }
case "$4" in *$'\n'*) _mem_one_line status "$4"; return 2 ;; esac
+ [ -z "$4" ] || _mem_status_text "$4" || return 2
[ -s "$3" ] || { echo "memory: empty or missing body: $3" >&2; return 2; }
- awk '/^```/ { n++ } END { exit n % 2 }' "$3" \
+ ! _mem_fence_open "$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
@@ -275,48 +342,52 @@ _mem_add_valid() { #
esac
}
-_mem_entry_text() { # → stdout
- local tag=""
- [ -z "$3" ] || tag=" [$3]"
+_mem_entry_text() { #
+ local tag="" # v1: the status is a body line (the v1 reconcile reader
+ [ -z "$3" ] || [ -n "$5" ] || tag=" [$3]" # never reads the heading)
printf '%s%s (%s)\n' "$1" "$tag" "$(_mem_date)"
+ [ -z "$3" ] || [ -z "$5" ] || printf -- '- **Status**: %s\n' "$3"
awk '{ l[NR] = $0 } END { n = NR; while (n > 0 && l[n] == "") n--
for (i = 1; i <= n; i++) print l[i] }' "$2"
[ -z "$4" ] || printf 'Supersedes [[%s]].\n' "$4"
}
_mem_add_locked() { #
- local f="$1" id bak rc=0
+ local f="$1" id pre rc=0 # runs under _mem_locked: failure = restore
+ if _mem_fence_open "$f"; then
+ echo "memory: $f leaves a code fence open; fix it first" >&2; return 2
+ fi
id=$(_mem_next_id "$f" "$2")
- bak=$(mktemp) || { echo "memory: no temp file" >&2; return 2; }
- cat "$f" > "$bak"
- trap 'cat "$bak" > "$f"; rm -f "$bak"; _mem_unlock "$(_mem_lock_path)"
- exit 130' INT TERM HUP
+ if _mem_heading_has "$f" "$id"; then
+ echo "memory: $id already in a heading of $f" >&2; return 2
+ fi
+ pre=$(mktemp) || { echo "memory: no temp file" >&2; return 2; }
+ cat "$f" > "$pre"
{ printf '\n## %s — ' "$id"; cat "$3"; } >> "$f" || rc=2
if [ "$rc" = 0 ] && [ -n "$4" ]; then
_mem_insert "$f" "$4" "- **Status ($(_mem_date))**: superseded by $id" \
|| rc=2
fi
if [ "$rc" = 0 ] && memory_is_v2 "$f"; then
- memory_check_file "$f" "$bak" || rc=2
+ memory_check_file "$f" "$2" "$pre" || rc=2
fi
- if [ "$rc" != 0 ]; then
- cat "$bak" > "$f"; echo "memory: add refused, $f restored" >&2
- else echo "$id"; fi
- rm -f "$bak"
+ rm -f "$pre"
+ [ "$rc" = 0 ] && echo "$id"
return "$rc"
}
memory_add() { #
- local spec file entry rc
+ local spec file entry rc v1=""
spec=$(_mem_kind "$1") || return 2
file=".claude/memory/${spec% *}"
_mem_add_valid "${spec#* }" "$2" "$3" "$4" "$5" || return 2
[ -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; }
- memory_is_v2 "$file" || echo "memory: v1 registry (no format: 2): $file" >&2
+ memory_is_v2 "$file" || {
+ v1=1; 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_entry_text "$2" "$3" "$4" "$5" "$v1" > "$entry"
_mem_locked _mem_add_locked "$file" "${spec#* }" "$entry" "$5"; rc=$?
rm -f "$entry"
return "$rc"
@@ -339,14 +410,6 @@ _mem_add_cli() { # --title t --body-file f [--status s] [--supersedes I]
memory_add "$kind" "$title" "$body" "$st" "$sup"
}
-_mem_prefix() { # → the frontmatter entry_prefix, rc 2 when none
- local p
- p=$(awk 'NR > 1 && $0 == "---" { exit }
- sub(/^entry_prefix: /, "") { print; exit }' "$1")
- [ -n "$p" ] || { echo "memory: $1: no entry_prefix" >&2; return 2; }
- echo "$p"
-}
-
_mem_culprits() { # → "\t" per culprit
awk -v p="$2" '
/^```/ { fence = !fence; next }
@@ -359,15 +422,14 @@ _mem_culprits() { # → "\t" per culprit
END { if (fence) print NR "\tcode fence open at end of file" }' "$1"
}
-memory_check_file() { # [] [] → 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
+memory_check_file() { # [] [] → rc 2 on a
+ # culprit. With a reference only culprits absent from it count (a merge
+ # duplicate never blocks the next append); an open fence always counts
+ local p="$2" ref="${3:-/dev/null}" name="${4:-$1}"
[ -s "$ref" ] || ref=/dev/null
awk -F'\t' -v f="$name" '
FILENAME == ARGV[1] { old[$2]++; next }
- old[$2]-- > 0 { next }
+ $2 !~ /^code fence/ && 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
@@ -377,12 +439,16 @@ memory_check() { # [--staged] [] → rc 2 on any culprit
local staged="" dir f rc=0
[ "${1:-}" = --staged ] && { staged=1; shift; }
dir="${1:-.claude/memory}"
+ case "$staged:$dir" in 1:/*|1:..|1:../*|1:*/../*|1:*/..)
+ echo "memory: check --staged takes a repo-relative dir: $dir" >&2
+ return 2 ;;
+ esac
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 ! memory_is_v2 "$f"; then echo "memory: v1: $f" >&2; continue; fi
- memory_check_file "$f" || rc=2
+ memory_check_file "$f" "$(_mem_prefix "$f")" || rc=2
done
return "$rc"
}
@@ -402,7 +468,7 @@ _mem_check_staged() { # → rc 2 on a new culprit or a lost v2 file
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
+ memory_check_file "$s" "$(_mem_prefix "$1")" "$h" "$1" || rc=2
_mem_removed_lines "$1" "$h" || rc=2
fi
rm -f "$h" "$s"
@@ -412,11 +478,12 @@ _mem_check_staged() { # → rc 2 on a new culprit or a lost v2 file
_mem_removed_lines() { # → 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
+ p=$(_mem_prefix "$1" 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" '
+ git -c diff.interHunkContext=0 diff --cached --no-color --no-ext-diff \
+ --no-textconv -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) {
@@ -505,7 +572,7 @@ _mem_upgrade_oracle() { # → rc 2 on a lost fact
[ "$("$MEM_GREP" -E "^## $3-[0-9]" "$1")" \
= "$("$MEM_GREP" -E "^## $3-[0-9]" "$2")" ] \
|| { echo "memory: upgrade changed a heading: $1" >&2; return 2; }
- memory_check_file "$2" || return 2
+ memory_check_file "$2" "$3" || return 2
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] }
@@ -559,7 +626,7 @@ memory_upgrade() { # [] → every template-born registry to v2
local dir="${1:-.claude/memory}" f rc=0
for f in $(_mem_names); do
[ -f "$dir/$f.md" ] || continue
- _mem_upgrade_file "$dir/$f.md" || rc=2
+ _mem_locked _mem_upgrade_file "$dir/$f.md" || rc=2
done
return "$rc"
}
diff --git a/docs/superpowers/plans/memory-v2-write/memory.test.sh b/docs/superpowers/plans/memory-v2-write/memory.test.sh
index 58a0743..ea0aefe 100644
--- a/docs/superpowers/plans/memory-v2-write/memory.test.sh
+++ b/docs/superpowers/plans/memory-v2-write/memory.test.sh
@@ -330,6 +330,54 @@ check T11b-bad-dir "$?" 2
bash "$MEM" frobnicate 2>/dev/null
check T11c-usage "$?" 2
+# T14 r3: any-level ID allocation, open fence refused, v1 status as a body
+# line, token lock, empty-lock steal, journal exact key, --staged dir
+cd "$FIX" || exit 1
+mkdir -p h3/.claude/memory && cd h3 || exit 1
+printf '# Decisions\n\n### BDR-001 — a\nx\n\n### BDR-007 — b\ny\n' \
+ > .claude/memory/decisions.md
+check T14-h3-next "$(bash "$MEM" add decision --title c --body-file "$FIX/plain.md" 2>/dev/null)" BDR-008
+printf '# Blockers\n\n## BLK-001 - legacy\n- Status: open\n' \
+ > .claude/memory/blockers.md
+bash "$MEM" add blocker --title fixed --body-file "$FIX/body.md" \
+ --status resolved >/dev/null 2>&1
+check T14b-v1-no-tag "$(grep -c '^## BLK-002 — fixed (2026-10-27)$' .claude/memory/blockers.md)" 1
+check T14c-v1-status-line "$(sed -n '/^## BLK-002/{n;p;}' .claude/memory/blockers.md)" '- **Status**: resolved'
+bash "$MEM" add blocker --title t --body-file "$FIX/body.md" --status fixed 2>/dev/null
+check T14d-status-word-required "$?" 2
+cd "$FIX" || exit 1
+cp .claude/memory/evals.md e.bak
+printf '\n```\nunclosed\n' >> .claude/memory/evals.md
+sum=$(cksum < .claude/memory/evals.md)
+bash "$MEM" add eval --title t --body-file plain.md >/dev/null 2>&1
+check T14e-open-fence-refused "$?" 2
+check T14f-open-fence-untouched "$(cksum < .claude/memory/evals.md)" "$sum"
+cat e.bak > .claude/memory/evals.md
+lock="$(git rev-parse --git-common-dir)/memory.lock"
+echo "$(date +%s) someone.1" > "$lock"
+# shellcheck source=/dev/null
+(. "$MEM"; _mem_unlock "$lock" me.2)
+check T14g-foreign-token-kept "$(cut -d' ' -f2 "$lock")" someone.1
+: > "$lock"
+check T14h-empty-lock-stolen "$(bash "$MEM" add eval --title e --body-file plain.md)" EVAL-002
+echo "$(( $(date +%s) - 60 )) dead.1" > "$lock"
+for i in 1 2 3 4 5 6 7 8 9 10 11 12; do
+ bash "$MEM" add learning --title "r$i" --body-file plain.md > "lr$i" &
+done
+wait
+check T14i-twelve-distinct "$(cat lr1 lr2 lr3 lr4 lr5 lr6 lr7 lr8 lr9 lr10 lr11 lr12 | sort -u | wc -l | tr -d ' ')" 12
+check T14j-no-lock-left "$([ -e "$lock" ] || [ -e "$lock.steal" ] && echo left || echo none)" none
+check T14k-check-green "$(bash "$MEM" check; echo $?)" 0
+J=.claude/memory/journal.md
+printf '\n## 2026-10-28 (cont. 1) — legacy\n- kept\n' >> "$J"
+MEMORY_DATE=2026-10-28 bash "$MEM" journal 'new day'
+check T14l-cont-not-matched "$(grep -c '^## 2026-10-28$' "$J")" 1
+check T14m-cont-untouched "$(sed -n '/(cont. 1)/{n;p;}' "$J")" '- kept'
+bash "$MEM" check --staged /abs 2>/dev/null
+check T14n-staged-absolute "$?" 2
+bash "$MEM" status BLK-404 'open' 2>&1 >/dev/null | grep -c restored > rs
+check T14o-no-restore-noise "$(tr -d ' ' < rs)" 0
+
# T12 this repo's registries pass the check
check T12-live-check "$(bash "$MEM" -C "$ROOT" check >/dev/null 2>&1; echo $?)" 0