forked from bchanot/claude
feat(memory): memory-commit refuses a staged in-place edit or new culprit in a v2 registry (rc 6, unstaged); rc 5/6 documented
This commit is contained in:
1 parent
803a34b89a
commit
f6d29bae93
3 files changed
+40
-1
No files matched your search
@@ -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.
|
||||
|
||||
`<mem_hash>` is the MEMORY commit (the one that ADDS the entries). It is NOT
|
||||
the code-commit hash that capitalize anchored INSIDE the entries
|
||||
|
||||
+14
-1
@@ -7,7 +7,8 @@
|
||||
# happens to be dirty or staged is NEVER embarked.
|
||||
#
|
||||
# Usage (CLI):
|
||||
# memory-commit.sh commit "<message>" # surgical commit; exit 0 ok/no-op, 3 unsafe state
|
||||
# memory-commit.sh commit "<message>" # 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
|
||||
|
||||
@@ -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 ]
|
||||
Reference in new issue
Block a user