Skip to content

Commit c2b9bec

Browse files
MendixMauclaude
andauthored
verify-module and look hook fixes; HARNESS rows from verify evidence (#501)
Fixes #446. - Look hook: cwd-safe (`cd "${CLAUDE_PROJECT_DIR:-$PWD}"`), failures logged once to .claude/loop/look/hook.log instead of hidden by `|| true`; installer rewrites the old form and removes duplicates; doctor flags it. - verify-module.sh: page-less module reports journeys SKIPPED (N/A); FAULT names *.test.sh; one e2e-harness dependency probe (playwright + axe-core) with dependents SKIPPED; coverage budget 1200 s; watchdogs no longer hold stdout open; summary.tsv ends with a verdict row. - coverage-preflight.sh: phantom pass scoped per BRD (16.1 s -> 4.2 s on a 12-BRD bench); false PHANTOMs for cross-folder and .id-named BRDs are gone. - Progress report / build-plan-status: a HARNESS verify-module row is promoted to built only on a clean, fresh summary plus a ui-review stating N of N with proof screenshots; otherwise it is flagged, done-drift style. Review: independently reviewed at b03506c and again at 9bc45b7 / 07c2ef4. The merge of master (#497) resolved only CHANGELOG.md. All eight scoped fixtures pass on the head (progress-harness-verify 7/7, verify-module-446 7/7, coverage-phantom-scope 2/2, look-hook-cwd 7/7, install-claude-permissions 77/77, doctor-stale-hooks 7/7, report-normalize-two-tree 9/9, progress-report 101/101); the new cases fail on the previous head and on master. A HARNESS close row is promoted only when its summary reached a CLEAN verdict row with no FAULT, FINDING or flag-SKIPPED rows, is newer than the BUILD-LOG rows and done- files of its dependsOn scripts (walked with cycle protection), and its newest ui-review states N of N with N PROOF-OF-LOOK screenshots of at least 10 KB, the look obligation's artifact judged slightly more strictly; otherwise the row is flagged. No summary.tsv reader collides with the verdict row in a way that changes an outcome. The phantom-pass aggregation hides no real phantom. No mxcli or mxbuild calls added; build-plan-status --html costs about 60 ms more (import of progress-report.py). check-pr-discipline, check-scripts and check-portability clean; client grep 0. Follow-ups filed separately. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VJgWP5vEoAsNsJYqCDMGNw
1 parent 9f3948c commit c2b9bec

19 files changed

Lines changed: 889 additions & 66 deletions

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Sections dated before 2026-09-19 predate the cycle and stay as they are. Named m
1919

2020
## Unreleased
2121

22+
- fix(look hook, verify-module, coverage): **the look hook records from any cwd, and `verify-module.sh` loses four instrument faults** (#446). (a) The PostToolUse(Read) hook was `bash bin/look-ledger.sh seen || true`: from any cwd but the project root (a subagent in a private copy, a shell in `app/javasource`) it exited 127 and `|| true` hid it (field: 30 pages owed, 1 seen). `install-claude-permissions.sh` now writes it to `cd "$CLAUDE_PROJECT_DIR"` first; a missing script or failed run goes to stderr, and is logged once to `.claude/loop/look/hook.log` when that can be written. The installer (and `sync-project.sh`'s hook repair) rewrites the old form in place and removes duplicate look hooks, so one remains; `doctor.sh` flags any look hook not in the root-resolving form. (b) A module with 0 pages in the page scope reports journeys N/A instead of a FAULT (`page-scope.sh` now runs before the runtime rungs; same mxcli calls) — jopterhorst (comment on #446); a missing journey JSON names any `tests/<module>*.test.sh` that exist in another shape; missing e2e dependencies (playwright, axe-core, probed from `JOURNEY_RUNNER`/`MONKEY_JS`/`DESIGN_AUDIT_JS`'s folders) are one FAULT row with the one fix (`npm install playwright axe-core && npx playwright install chromium`), journeys and monkey SKIPPED as dependents of playwright, the design audit static-only; the coverage rung's budget is 1200 s (was 300); `summary.tsv` ends with a `verdict` row (CLEAN / FINDINGS / INCOMPLETE), absent when a run was cut short (`report-normalize.js` skips it); and `coverage-preflight.sh`'s PHANTOM CLAIM pass gives each BRD only the claims it can resolve (12-BRD bench: 16.1 s to 4.2 s), with identical verdicts except that false PHANTOMs for BRDs in another source folder or named only by `.id` are gone (exit can drop 1→0). Found while proving it: every rung's watchdog `sleep` kept the script's stdout open, so `verify-module.sh | tee` waited up to 30 minutes after the verdict; the watchdogs now drop fds 3/4 and take their sleep with them. **Behaviour change to check in your project:** a page-less module's `summary.tsv` has `journeys SKIPPED (N/A: ...)` and the run can exit 0; missing e2e dependencies add an `e2e harness dependency` FAULT row and SKIPPED journeys/monkey rows; `summary.tsv` gains a last `verdict` row; `coverage-preflight.sh` can exit 0 where it exited 1 (the false PHANTOMs above); `.claude/settings.json`'s look hook command changes. Fixtures: `test-look-hook-cwd.sh`, `test-verify-module-446.sh`, `test-coverage-phantom-scope.sh`. — MendixMau (field 2026-10-17), jopterhorst (page-less modules)
23+
- fix(progress-report): **a HARNESS row that runs `verify-module.sh <Module>` is read from evidence as well as from State.** The agent ran the module-close pass and never edited State, so the row stayed "not built". The row's Pass is a clean summary AND LOOK + CONFIRM, so the report promotes it only on both: the summary reached its `verdict` row with no FAULT, no FINDING and nothing SKIPPED but the look and N/A rows (a `--quick`/`--skip-*` run does not count), it is newer than every BUILD-LOG row and `done-` file of the scripts the row depends on, and the module's newest `design/ui-reviews/ui-review-*.html` (the `look` obligation's artifact) says N of N with N PROOF-OF-LOOK screenshots on disk. Then the row shows `built (verified <date>, LOOK n/n)`, counted built and flagged against State. Short of that it keeps the State count and is flagged, as done-drift is: `verify clean <date> — LOOK + CONFIRM owed`, `verify stale (summary <date>, N execs since)`, or, for State built, `built? no verify summary` / not clean. Other rows keep the State rule; `progress-report.py` holds the one rule and `build-plan-status.sh` imports it; no extra script runs and no git calls (the LOOK report's VALID AT staleness stays gate-check's). **Behaviour change to check in your project:** the progress report can show a HARNESS row as built while its State cell says not built, and flags HARNESS rows whose State says built without the evidence. Fixture: `test-progress-harness-verify.sh`. — MendixMau (review 2026-10-21)
2224
- fix(lint): **`lint-gate.sh` says when to take the first baseline, a rise opens with a one-line-per-rule summary, and `Lint gate: hard` is an opt-in exit 1** (#496, split from #443). With no baseline, the gate said only "run --update-baseline", and nothing said when the first one should be taken; it now says to take it right after the scaffold, with the user, and shows the command (the `iterative-build-loop.md` refusal table gains the same row). In the field run behind #443 about 90% of runs rose, and each rule's header was buried between its findings; a FAIL now opens with `rule sev base -> now (+N) K new`, one line per rule, then the per-rule detail (still at most 3 findings, all of them in `.claude/loop/lint-last.json`). `Lint gate: hard` in `PROJECT.md` makes `exec.sh` exit 1 on a LINT ROSE instead of 4 (write still kept; env `MXTK_LINT_GATE=soft|hard` wins, and `doctor.sh --fix-property-sets` passes soft so a kept repair is not read as failed). **Behaviour change to check in your project:** the FAIL block's layout changed: the `rule sev N -> M (+K)` lines are now the summary at the top, each followed by `K new`, and the detail headers read ` RULE:`. `exec.sh`'s own parse reads each rule once either way; a project script that grepped the old interleaved block should be checked. — MendixMau (field 2026-10-17, via #443)
2325
- fix(exec): **a pre-exec `mxcli check` refusal now records its reason in the BUILD-LOG row, and the preflight STOP table gains rows 29-32** (#445). The 🚫 row said only "mxcli check failed pre-exec", so the reason for 3 field refusals was lost (the issue suspects MDL-PAGEARG01, in mxcli since about v0.19); exec.sh now keeps the output of the one check run it already makes, still printed live, and appends `; check: <first error line>` (rule id first, ANSI and CR stripped, pipes escaped, cut at 160 bytes on a UTF-8 boundary). New STOP rows: a constant in a nanoflow (CE0117), `dynamicimage` on the React client (CE0582), a data-view attribute binding across 2+ associations (CE1613), a widget `show page` argument with no context object or besides it (MDL-PAGEARG01). Golden input: two real mxcli v0.26.0 check captures (mxcli's own PAGEARG01 test and a parse error), not the field output. BUG-70 notes that v0.26.0 `check` now refuses its shape. Test: `tests/wave2/test-exec-check-refusal.sh` — MendixMau (field 2026-10-17)
2426
- fix(exec): **`exec.sh` exit codes now mean what they say (#443, #448).** A clean build with a lint rise exited 1 like a failed gate, and an UNVERIFIED gate exited 0 like a pass: in one field build 57 of 58 clean builds exited 1, agents learned to ignore 1, and 10 UNVERIFIED runs read as success. Now `0` applied and gate passed · `1` not applied or rolled back (and PARTIAL, whatever mxcli exited) · `2` usage, nothing touched · `4` applied, gate passed, lint only (LINT ROSE/BLIND; last line `gate passed, lint only`) · `5` applied, UNVERIFIED (also `ALLOW_UNVERIFIED=1`). An mxbuild exit 1/3 whose errors file holds only a generic deploy-stage message (`Compilation of the app bundle failed.`, `An error occurred while ...`) and no model problem is retried once, like an empty one, but not again by the gate when the baseline's retry already failed with the same text; a version mismatch still is not. No extra mxbuild on the happy path (2); worst case 3. Defined in the `exec.sh` header, mirrored in `iterative-build-loop.md`; `doctor.sh --fix-property-sets` reads 4 as kept, `sync-project.sh` names the fix for a hand-edited copy; `test-exec-gate-retry.sh` F–L pin it. **Behaviour change to check in your project:** a wrapper that tests exec.sh's exit code now sees 4 for a lint-only rise (was 1) and 5 for UNVERIFIED (was 0); a PARTIAL run never exits 4 or 5. — MendixMau (field 2026-10-17)

‎bin/doctor.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,9 @@ if [ -n "$PROJECT_DIR" ]; then
12611261
HOOK_GAP=""
12621262
grep -qF 'bin/session-check.sh' "$PSET" 2>/dev/null || HOOK_GAP="session-check (SessionStart)"
12631263
grep -qF 'bin/look-ledger.sh seen' "$PSET" 2>/dev/null || HOOK_GAP="${HOOK_GAP:+$HOOK_GAP and }look-ledger seen (PostToolUse Read)"
1264+
# #446: the pre-2026-10-21 relative form records nothing from any cwd but the project root.
1265+
# Any look hook not in the root-resolving form (one JSON string per line, so per-line is exact).
1266+
grep -F 'look-ledger.sh seen' "$PSET" 2>/dev/null | grep -vqF 'CLAUDE_PROJECT_DIR' && HOOK_GAP="${HOOK_GAP:+$HOOK_GAP and }look-ledger seen run from the project root (a look hook that does not cd to \$CLAUDE_PROJECT_DIR first records nothing from any other cwd)"
12641267
if [ -n "$HOOK_GAP" ] && [ -f "$PROJECT_DIR/.mxtk/no-hook-repair" ]; then
12651268
ok "hook gap ($HOOK_GAP) accepted: .mxtk/no-hook-repair is set"
12661269
elif [ -n "$HOOK_GAP" ]; then

‎bin/install-claude-permissions.sh‎

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
# that says at the top of every session whether the model on disk is verified, whether the
4848
# mxbuild gate can run here, and whether the installed guard scripts are stale. It never blocks.
4949
#
50-
# THE SECOND HOOK (2026-10-02): `bash bin/look-ledger.sh seen || true` on PostToolUse, matcher
51-
# `Read`. Two unattended builds built every page and never opened a screenshot of one; nothing
50+
# THE SECOND HOOK (2026-10-02): `bin/look-ledger.sh seen`, run from $CLAUDE_PROJECT_DIR (#446,
51+
# see LOOK_HOOK below), on PostToolUse, matcher `Read`. Two unattended builds built every page and never opened a screenshot of one; nothing
5252
# could tell, because the only record of a LOOK was a report nobody had to write. This hook
5353
# writes one ledger row per image the agent actually opens, and gate-check.sh's Stage 5 check
5454
# joins it against the pages bin/exec.sh built. It ignores every non-image Read, never blocks,
55-
# and exits 0 even when look-ledger.sh is not installed yet.
55+
# and exits 0 even when look-ledger.sh is not installed yet (it logs that once).
5656
#
5757
# MERGE PATTERN reused from bin/install-claude-hooks.sh (~line 112-206): Python via
5858
# lib/portable.sh's require_py, a timestamped backup before any write, and a merge that keeps
@@ -241,10 +241,17 @@ if [ "$PROFILE" = full ]; then
241241
fi
242242

243243
SESSION_HOOK="bash bin/session-check.sh || true"
244-
LOOK_HOOK="bash bin/look-ledger.sh seen || true"
245-
# event <TAB> matcher ("" = none) <TAB> command, one hook per line.
244+
# The look hook runs from the project root, not from the cwd of whoever did the Read (#446). The
245+
# old form, `bash bin/look-ledger.sh seen || true`, exited 127 from any other cwd (a subagent in
246+
# a private copy, a shell in app/javasource) and `|| true` hid it: 30 pages owed, 1 seen.
247+
# Claude Code sets $CLAUDE_PROJECT_DIR for every hook; PROJECT_ROOT is $PWD after the cd, so a
248+
# Windows-form value reaches look-ledger.sh as Git Bash spells it. A missing script or a failed
249+
# run is logged ONCE per distinct message to .claude/loop/look/hook.log and printed to stderr.
250+
LOOK_HOOK='d="${CLAUDE_PROJECT_DIR:-$PWD}"; l="$d/.claude/loop/look/hook.log"; w() { grep -qsF "$1" "$l" && return 0; if [ -d "$d/.claude" ] && mkdir -p "${l%/*}" && printf "%s\t%s\n" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$1" >> "$l"; then echo "look hook: $1 (logged once to $l)" >&2; else echo "look hook: $1" >&2; fi; }; if [ -f "$d/bin/look-ledger.sh" ]; then (cd "$d" && PROJECT_ROOT="$PWD" bash bin/look-ledger.sh seen) || w "bin/look-ledger.sh seen failed (exit $?)"; else w "no bin/look-ledger.sh under $d"; fi; exit 0'
251+
LOOK_HOOK_OLD="bash bin/look-ledger.sh seen || true"
252+
# event <TAB> matcher ("" = none) <TAB> command [<TAB> older form this replaces in place], one per line.
246253
HOOKS="SessionStart $SESSION_HOOK
247-
PostToolUse Read $LOOK_HOOK"
254+
PostToolUse Read $LOOK_HOOK $LOOK_HOOK_OLD"
248255

249256
require_py
250257

@@ -260,7 +267,13 @@ settings_path, sidecar_path, mode, hooks_arg, n_allow, n_deny, *rest = sys.argv[
260267
n_allow, n_deny = int(n_allow), int(n_deny)
261268
entries, deny_entries, ask_entries = rest[:n_allow], rest[n_allow:n_allow + n_deny], rest[n_allow + n_deny:]
262269
# (event, matcher, command) per line; matcher "" means the group carries no matcher.
263-
hook_specs = [tuple(l.split("\t", 2)) for l in hooks_arg.splitlines() if l.strip()]
270+
hook_specs, legacy = [], {}
271+
for l in hooks_arg.splitlines():
272+
if l.strip():
273+
f = l.split("\t", 3)
274+
hook_specs.append(tuple(f[:3]))
275+
if len(f) > 3 and f[3]:
276+
legacy[f[2]] = f[3]
264277
265278
266279
def hook_present(d, spec):
@@ -274,6 +287,17 @@ def hook_present(d, spec):
274287
return False
275288
276289
290+
def extra_copies(d, spec):
291+
"""Look hooks beyond the one wanted: the older form, or a second copy of the current one."""
292+
ev, matcher, cmd = spec
293+
old = legacy.get(cmd)
294+
if not old:
295+
return 0
296+
hs = [h for grp in d.get("hooks", {}).get(ev, []) or [] if (grp.get("matcher") or "") == matcher
297+
for h in grp.get("hooks", []) or [] if h.get("command") in (cmd, old)]
298+
return max(len(hs) - 1, 0) if any(h.get("command") == cmd for h in hs) else 0
299+
300+
277301
def hook_label(spec):
278302
ev, matcher, cmd = spec
279303
return "hooks.%s%s: %s" % (ev, "[%s]" % matcher if matcher else "", cmd)
@@ -319,7 +343,7 @@ if mode == "check":
319343
missing = [e for e in entries if e not in allow]
320344
missing_deny = [e for e in deny_entries if e not in deny]
321345
missing_ask = [e for e in ask_entries if e not in d.get("permissions", {}).get("ask", [])]
322-
missing_hooks = [h for h in hook_specs if not hook_present(d, h)]
346+
missing_hooks = [h for h in hook_specs if not hook_present(d, h) or extra_copies(d, h)]
323347
if missing or missing_deny or missing_ask or missing_hooks:
324348
print("Missing entries in %s:" % settings_path)
325349
for m in missing:
@@ -365,11 +389,12 @@ if mode == "uninstall":
365389
d["permissions"]["ask"] = [e for e in perms["ask"] if e not in added_ask]
366390
for spec in hook_specs:
367391
ev, _m, cmd = spec
368-
if cmd not in added_hooks or "hooks" not in d or ev not in d["hooks"]:
392+
mine = {c for c in (cmd, legacy.get(cmd)) if c and c in added_hooks}
393+
if not mine or "hooks" not in d or ev not in d["hooks"]:
369394
continue
370395
groups = d["hooks"].get(ev, []) or []
371396
for grp in groups:
372-
grp["hooks"] = [h for h in grp.get("hooks", []) if h.get("command") != cmd]
397+
grp["hooks"] = [h for h in grp.get("hooks", []) if h.get("command") not in mine]
373398
d["hooks"][ev] = [g for g in groups if g.get("hooks")]
374399
if not d["hooks"][ev]:
375400
del d["hooks"][ev]
@@ -442,14 +467,45 @@ if ask_entries or "ask" in perms:
442467
newly_asked = [e for e in ask_entries if e not in ask]
443468
ask.extend(newly_asked)
444469
445-
new_hooks = []
470+
new_hooks, replaced = [], []
446471
for spec in hook_specs:
447472
if hook_present(d, spec):
473+
# Already current: drop any older form and any second copy beside it, so one look hook
474+
# runs per Read (an earlier install could leave the old form next to the new one).
475+
ev, matcher, cmd = spec
476+
if extra_copies(d, spec):
477+
seen = False
478+
groups = d["hooks"][ev]
479+
for grp in groups:
480+
if (grp.get("matcher") or "") != matcher:
481+
continue
482+
keep = []
483+
for h in grp.get("hooks", []) or []:
484+
c = h.get("command")
485+
if c == legacy.get(cmd) or (c == cmd and seen):
486+
if c != cmd:
487+
replaced.append(c)
488+
continue
489+
seen = seen or c == cmd
490+
keep.append(h)
491+
grp["hooks"] = keep
492+
d["hooks"][ev] = [g for g in groups if g.get("hooks")]
493+
new_hooks.append(spec)
448494
continue
449495
ev, matcher, cmd = spec
450-
grp = {"matcher": matcher} if matcher else {}
451-
grp["hooks"] = [{"type": "command", "command": cmd}]
452-
d.setdefault("hooks", {}).setdefault(ev, []).append(grp)
496+
old_cmd = legacy.get(cmd)
497+
# The older form of this hook, written by an earlier run: rewrite it in place, so the project
498+
# keeps one look hook rather than gaining a second that writes a duplicate row from the root.
499+
olds = [h for grp in d.get("hooks", {}).get(ev, []) or [] if (grp.get("matcher") or "") == matcher
500+
for h in grp.get("hooks", []) or [] if old_cmd and h.get("command") == old_cmd]
501+
if olds:
502+
for h in olds:
503+
h["command"] = cmd
504+
replaced.append(old_cmd)
505+
else:
506+
grp = {"matcher": matcher} if matcher else {}
507+
grp["hooks"] = [{"type": "command", "command": cmd}]
508+
d.setdefault("hooks", {}).setdefault(ev, []).append(grp)
453509
new_hooks.append(spec)
454510
455511
if HOOKS_ONLY and not new_hooks:
@@ -477,6 +533,7 @@ if newly_added or newly_denied or newly_asked or new_hooks or pruned:
477533
added_deny.update(newly_denied)
478534
added_ask.update(newly_asked)
479535
added_hooks.update(h[2] for h in new_hooks)
536+
added_hooks.difference_update(replaced)
480537
side = {"allow": sorted(added), "deny": sorted(added_deny)}
481538
if added_ask:
482539
side["ask"] = sorted(added_ask)
@@ -495,6 +552,8 @@ if newly_added or newly_denied or newly_asked or new_hooks or pruned:
495552
print(" - " + e)
496553
for h in new_hooks:
497554
print(" + " + hook_label(h))
555+
for c in replaced:
556+
print(" - hook (older form, replaced or removed): " + c)
498557
else:
499558
print("All permission entries already present in %s -- nothing to do" % settings_path)
500559
PY

0 commit comments

Comments
 (0)