fix(6471): the end-of-turn shape check hears every definition a write made

The write hooks recorded at most 12 definitions per write (alphabetical,
so test functions were the ones dropped) and the post-Bash hook stopped
after 4 files, so the Stop hook never asked about the rest. The caps
bound the prior-art query; the written ledger now gets the full list,
up to 40 files per Bash call, while the query stays at 4 files x 12 names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 16:26:15 -04:00
co-authored by Claude Opus 5.5
parent db2427a3dc
commit 83cb6420e2
4 changed files with 54 additions and 11 deletions
+14 -8
View File
@@ -119,10 +119,11 @@ combined=""
n_files=0
while IFS= read -r rel_path; do
[ -n "${rel_path:-}" ] || continue
# A Bash call that rewrote many files is a refactor or a generator, not a
# shape being instantiated; four is enough to name what matters.
# Every changed file goes into the end-of-turn ledger, up to forty — a bound
# on this hook's run time, past which the call was a generator. The arms
# below speak for the first four only (see the check after the ledger).
n_files=$((n_files + 1))
[ "$n_files" -le 4 ] || break
[ "$n_files" -le 40 ] || break
file_path="$repo_root/$rel_path"
# The code just written: the ADDED lines of the uncommitted diff for a
@@ -136,14 +137,19 @@ while IFS= read -r rel_path; do
fresh="new"
fi
[ -n "$code" ] || continue
# `|| true` inside: an early-exiting `head` must not void its own output.
names=$(printf '%s' "$code" | grimoire_defs | sort -u | head -12 || true)
# What this write defined, for the end-of-turn question —
all_names=$(printf '%s' "$code" | grimoire_defs | sort -u || true)
# What this write defined, for the end-of-turn question: every definition,
# recorded before the arms below, which skip a write that defines nothing.
printf '%s\n' "$names" | grimoire_written_append "$safe_sid" "$rel_path" "$fresh" "$code"
printf '%s\n' "$all_names" | grimoire_written_append "$safe_sid" "$rel_path" "$fresh" "$code"
# Nothing DEFINED in what was written (prose, data, a call-site edit) →
# nothing to say; the arms are about shapes.
[ -n "$names" ] || continue
[ -n "$all_names" ] || continue
# A Bash call that rewrote many files is a refactor or a generator, not a
# shape being instantiated; four files and twelve names per file are enough
# for the arms to name what matters, and bound their git grep and URL.
[ "$n_files" -le 4 ] || continue
# `|| true` inside: an early-exiting `head` must not void its own output.
names=$(printf '%s\n' "$all_names" | head -12 || true)
local_lines=$(grimoire_local_dups "$repo_root" "$rel_path" <<< "$names") || local_lines=""
local_context=""