From f6d29bae9371739fc981b4656bbbb931b921628b Mon Sep 17 00:00:00 2001 From: bchanot Date: Wed, 28 Oct 2026 14:09:58 +0100 Subject: [PATCH] feat(memory): memory-commit refuses a staged in-place edit or new culprit in a v2 registry (rc 6, unstaged); rc 5/6 documented --- lib/capitalize-commit.md | 10 ++++++++++ lib/memory-commit.sh | 15 ++++++++++++++- lib/tests/run-deterministic.sh | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/capitalize-commit.md b/lib/capitalize-commit.md index c433631..b153530 100644 --- a/lib/capitalize-commit.md +++ b/lib/capitalize-commit.md @@ -48,6 +48,16 @@ tune it there. - rc 3 → unsafe git state (detached / merge in progress); memory stays in the working tree for a manual commit — surface the helper's stderr. + - rc 5 → `git commit` rejected (hook, protected branch, + signing); nothing committed, surface stderr. + - 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); 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. `` is the MEMORY commit (the one that ADDS the entries). It is NOT the code-commit hash that capitalize anchored INSIDE the entries diff --git a/lib/memory-commit.sh b/lib/memory-commit.sh index 1f55f59..728a1f5 100755 --- a/lib/memory-commit.sh +++ b/lib/memory-commit.sh @@ -7,7 +7,8 @@ # happens to be dirty or staged is NEVER embarked. # # Usage (CLI): -# memory-commit.sh commit "" # surgical commit; exit 0 ok/no-op, 3 unsafe state +# memory-commit.sh commit "" # surgical commit; exit 0 ok/no-op, 3 unsafe +# # state, 5 commit rejected, 6 check refused # # Output contract for `commit`: diagnostics go to stderr; on a real commit the # short hash of the MEMORY commit is the ONLY thing on stdout (empty on no-op or @@ -18,6 +19,7 @@ set -uo pipefail MC_PATHS=(".claude/memory" ".claude/tasks") +MC_MEMORY_SH="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)/memory.sh" _in_git_repo() { git rev-parse --git-dir >/dev/null 2>&1; } @@ -68,6 +70,17 @@ commit_memory() { # then commit ONLY those paths. The pathspec on `git commit` makes it a partial # commit: other staged files (dangling code) are not recorded. git add -- "${changed[@]}" + # 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, nothing left staged." >&2 + return 6 + fi if git diff --cached --quiet -- "${changed[@]}"; then echo "memory-commit: only ignored/no-op changes — no-op" >&2 return 0 diff --git a/lib/tests/run-deterministic.sh b/lib/tests/run-deterministic.sh index 1d1f9ff..17bf27e 100755 --- a/lib/tests/run-deterministic.sh +++ b/lib/tests/run-deterministic.sh @@ -155,6 +155,22 @@ if [ -z "$OUT" ]; then ok "stdout empty on rejection (no stale hash)"; else ko " if [ "$BEFORE" = "$AFTER" ]; then ok "HEAD unmoved"; else ko "HEAD moved despite rejection"; fi rm -rf "$R" +echo "== check --staged chokepoint (v2 registry, phase 4a)" +d="$(new_repo)" +printf -- '---\nformat: 2\ntype: decisions_registry\nentry_prefix: BDR\n---\n\n## BDR-001 — kept (2026-10-27)\n- **Status**: accepted\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) +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=$? +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 + echo printf 'RESULT: %d passed, %d failed\n' "$PASS" "$FAIL" [ "$FAIL" -eq 0 ]