diff --git a/.crumb b/.crumb index 7c1c2a5f0..d19f4dc90 100644 --- a/.crumb +++ b/.crumb @@ -46,7 +46,7 @@ "children": [ { "digest": "fb7cc6e608fdbe68a9735a1313285782b9717ff12bde17343f8ce635de3644f6", - "last_commit": "190ff89", + "last_commit": "80ca5d4", "name": "calibration", "purpose": "Directory calibration. Purpose not yet described by a human." }, @@ -58,25 +58,25 @@ }, { "digest": "536f7b8db9a92a1f586bad4379d47544a30d1b8e83c2d799c18e66cf8660c9ae", - "last_commit": "30bb116", + "last_commit": "80ca5d4", "name": "doctrine", "purpose": "Directory doctrine. Purpose not yet described by a human." }, { "digest": "378566048adb168d897e24a62f089c1f95b1d9d11aef3ecfd1f64bbdc58a2089", - "last_commit": "4cc3bdd", + "last_commit": "3b53f25", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, { "digest": "69cbb8ef13ccce47ccc21f159e95f1eac58679319e2cc25937065f95c4eb9207", - "last_commit": "ae8c7c5", + "last_commit": "80ca5d4", "name": "polyglot", "purpose": "Directory polyglot. Purpose not yet described by a human." }, { "digest": "8178197a3e956890d6194e5b4fcc0e0b5c4ec67b0749f0d257f2ed17c8ca7465", - "last_commit": "559f6e5", + "last_commit": "80ca5d4", "name": "research", "purpose": "Directory research. Purpose not yet described by a human." }, @@ -93,27 +93,27 @@ "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "5c465ad44056e49d963f427da8ef88b891c4f95090abb04b8a40751ff028eae3", - "last_commit": "4cc3bdd", + "digest": "3afb8a86231a7f5421eda8f4b1fa501b283145fa0f46b25c98fc74b298b9cf8c", + "last_commit": "703e09c", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { - "digest": "ff24f7b12ceb0448c4da80d43e8ff249a3176ad3b374c3c27cc71e537ba66a00", - "last_commit": "a9ef42a", + "digest": "8d09b39d6d457128ffa8b3a3e3a8bc16cb619d952dd8db04dc3fc3cda7d38890", + "last_commit": "97d1b9a", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:6e4c10e98a24e177b403755373de9139b340df926b312d67e767be214f0fdea3", - "compiled_at": "2026-10-08T12:58:13Z", + "children_root": "sha256:8cf37dbda3b1c5aa496d1da2f1d3d172691dd9fc95ea8c1932b77e8df4be8902", + "compiled_at": "2026-10-08T13:06:11Z", "compiler": "crumb-compile/1", - "digest": "sha256:e4b256cedeff4dd02cd72ee72cc1811fb2df1769af20c41e1b114e278b4c675b", + "digest": "sha256:6afdffeffc9588037d004a285e0319d44a0cf07eabe0acee7f89d982e6490dbf", "evidence_files": 4818, "evidence_root": "sha256:07642731585ad396c5d9b566a4b8df7807018f494d322dffce41bd04fb51e553", "files": 6814, - "generated_at_commit": "4cc3bdda4ace926eb2a9a976551dc525279c53b8", - "source_tree": "sha256:2bb342e0e9207eb04acb943d2fbfeb18921d5e3f74c9dda77bb55feeee1aae5c" + "generated_at_commit": "703e09c0cc8c973c93bc262912eef015ee4fc127", + "source_tree": "sha256:50a9676659b281a33686aacdc19a35e9ad04b981105b35fe726f670c42c4f660" }, "owner_lane": "", "provenance": { diff --git a/tests/.crumb b/tests/.crumb index 7ae431343..b5dec00c2 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -110,25 +110,25 @@ "children": [ { "digest": "e7498eca87fe5ca8dc27d92f2d99be0de3e4c804711f9d8cba5bb1e47ca95f74", - "last_commit": "28911be", + "last_commit": "80ca5d4", "name": "algebra", "purpose": "Directory tests/algebra. Purpose not yet described by a human." }, { "digest": "d484ca176e9932b098df5664d01bdd679c78f5b89f4d15a77eb30f43d235f570", - "last_commit": "834ee93", + "last_commit": "80ca5d4", "name": "ans", "purpose": "Tests 1-10 for ANS (docs/ans/INERTIAL_ALIGNMENT_SPEC_V1.md): freeze/digest, hostile reference mu" }, { "digest": "bd7114b42f99c7e51741abdf24329d20713c73a332bd5f349e04384fd0241e91", - "last_commit": "e722877", + "last_commit": "80ca5d4", "name": "brownian", "purpose": "Directory tests/brownian. Purpose not yet described by a human." }, { "digest": "1cbe9561b87b394e200f67996ce1407c377025d07ad033b27cdd542625e277d4", - "last_commit": "30bb116", + "last_commit": "80ca5d4", "name": "canonicalization", "purpose": "Directory tests/canonicalization. Purpose not yet described by a human." }, @@ -140,97 +140,97 @@ }, { "digest": "47683e6a56ca8e14ee526004b2a90dd08498507e8d4b0b42c3d85d22afb07d28", - "last_commit": "28b8793", + "last_commit": "80ca5d4", "name": "constraints", "purpose": "Directory tests/constraints. Purpose not yet described by a human." }, { "digest": "95b2041562face1ba7baa6c57456bf07d77a0f44e093b989ec18f559064e22d9", - "last_commit": "49abb02", + "last_commit": "80ca5d4", "name": "crumbline", "purpose": "Directory tests/crumbline. Purpose not yet described by a human." }, { "digest": "d57833fb3f63ef6475cf25e2e16319d818a0a407b825d5b4c5cbdd3cc0e06492", - "last_commit": "00f54b6", + "last_commit": "80ca5d4", "name": "dual_experiment", "purpose": "Tests for the DUAL applicability experiment: determinism (same seed, byte-identical results dige" }, { "digest": "fb0a9296a93d065d5e016ad0a950fc6b9691f8ddca12ad0111cee2e35791cdb4", - "last_commit": "c819b37", + "last_commit": "80ca5d4", "name": "effect", "purpose": "Directory tests/effect. Purpose not yet described by a human." }, { "digest": "bc2473da101ba5a74c32021a9d27ecb2007897f07a9689ba50ccc99b9030bf0c", - "last_commit": "1a147e4", + "last_commit": "80ca5d4", "name": "estimation", "purpose": "Directory tests/estimation. Purpose not yet described by a human." }, { "digest": "de2bc4e310a257dbd21cc5c9624641b137b1b4487d8876cb52469aea2af5b904", - "last_commit": "3108fc2", + "last_commit": "80ca5d4", "name": "fabric", "purpose": "Directory tests/fabric. Purpose not yet described by a human." }, { "digest": "90418926706f827aafd72938aee1dea89222cb5e465fba06a8df5a83253e0412", - "last_commit": "28b8793", + "last_commit": "80ca5d4", "name": "identity", "purpose": "Directory tests/identity. Purpose not yet described by a human." }, { "digest": "c653c851c8934ce9ac4eabaa32a9df65d858c9ac7a556e76b265b1ee81494443", - "last_commit": "4f55f45", + "last_commit": "80ca5d4", "name": "language", "purpose": "Directory tests/language. Purpose not yet described by a human." }, { "digest": "e485aa0a00f0a588e22d55caa704db8581a5da1b53080b311086e6edd38f6044", - "last_commit": "30bb116", + "last_commit": "80ca5d4", "name": "malformed", "purpose": "Directory tests/malformed. Purpose not yet described by a human." }, { "digest": "adba9b5ea1c000db36078fca7d1bfef0b2769b73c8fb474024d9409bd48bdbc1", - "last_commit": "40d1ea3", + "last_commit": "80ca5d4", "name": "numeric_native", "purpose": "Simulated M16 driver for numeric resource-lifecycle tests. No device execution or numeric parity" }, { "digest": "cbeed5ed9e19195b442f1bde9cac95f066d4b7037b48f73859573d469240c664", - "last_commit": "4cc3bdd", + "last_commit": "3b53f25", "name": "osh", "purpose": "osh lexer host driver, vendored aien-protocols PR#16 draft vectors (5ae5292)" }, { "digest": "a4d320b3203650a28c43ea954957d8902d1cc25cbdc8aecd15628c01a92f68f8", - "last_commit": "d550b70", + "last_commit": "80ca5d4", "name": "path", "purpose": "Directory tests/path. Purpose not yet described by a human." }, { "digest": "1fd5f914f326a1a51fc343ab633ac411e86bea22beee718b1460db066807f292", - "last_commit": "8a2e268", + "last_commit": "80ca5d4", "name": "physics0", "purpose": "PD-0 gates: world self-test, oracle calibration, learner L0/L1/NULL, mutations, OSC differential" }, { "digest": "4619a90a957e77cd3d5680132ab4d1a5ef65f43419ddcc089743ca5b7a7719ee", - "last_commit": "8f8babe", + "last_commit": "80ca5d4", "name": "polyglot", "purpose": "Directory tests/polyglot. Purpose not yet described by a human." }, { "digest": "16bea65aa50f0b3ab8b90cb286de048639fa8e635ff84e517e138c6f9f26a059", - "last_commit": "3c82389", + "last_commit": "80ca5d4", "name": "program", "purpose": "Directory tests/program. Purpose not yet described by a human." }, { "digest": "ba0c09f67d12b5d7de906129bdbe2f6e0a228e1a34236ecc4b779c523cb2061e", - "last_commit": "6fdc4c3", + "last_commit": "80ca5d4", "name": "r16_inventory", "purpose": "Directory tests/r16_inventory. Purpose not yet described by a human." }, @@ -242,19 +242,19 @@ }, { "digest": "25cabf47d18353539db28146434d246a2f81bf9c323471566451aca56806f279", - "last_commit": "44d8c06", + "last_commit": "80ca5d4", "name": "r16_surface", "purpose": "Directory tests/r16_surface. Purpose not yet described by a human." }, { "digest": "9106f2ea57e8f453322f0a988b61cfcbd06631573c9ff32a777903d27d7741e1", - "last_commit": "40d1ea3", + "last_commit": "80ca5d4", "name": "realize", "purpose": "Directory tests/realize. Purpose not yet described by a human." }, { "digest": "381184e79b26920b256dd4a774fb11f17a92afa8ceda4813eada241bac4163a9", - "last_commit": "30bb116", + "last_commit": "80ca5d4", "name": "relations", "purpose": "Directory tests/relations. Purpose not yet described by a human." }, @@ -266,38 +266,38 @@ }, { "digest": "b1311025a3bfd8dd7b5e07b1adf1d7ece502a15200f7207f515334f7083b8315", - "last_commit": "5ae192a", + "last_commit": "80ca5d4", "name": "searchtrace", "purpose": "Directory tests/searchtrace. Purpose not yet described by a human." }, { "digest": "3ecf636e2923038708cafa062895b8d8f2664dc1865cdff38575911eaa9f1b2d", - "last_commit": "54826a3", + "last_commit": "80ca5d4", "name": "train", "purpose": "Directory tests/train. Purpose not yet described by a human." }, { "digest": "75d5e576c38a0497a55e9f5ee79550cb94f9b75008f3e4e126312802704b3f86", - "last_commit": "2564f57", + "last_commit": "80ca5d4", "name": "turing", "purpose": "Directory tests/turing. Purpose not yet described by a human." }, { "digest": "3f19e3034ff999211cb13ab8995ca6c38d0d8e1f5bfbbbd621caaa08412d3f1f", - "last_commit": "fed4f07", + "last_commit": "80ca5d4", "name": "visor", "purpose": "Directory tests/visor. Purpose not yet described by a human." } ], "children_root": "sha256:25307df070b72d8ae2c65989d733e08286e87634d467b89541273dcfa16e6817", - "compiled_at": "2026-10-08T12:58:13Z", + "compiled_at": "2026-10-08T13:06:11Z", "compiler": "crumb-compile/1", - "digest": "sha256:5c465ad44056e49d963f427da8ef88b891c4f95090abb04b8a40751ff028eae3", + "digest": "sha256:3afb8a86231a7f5421eda8f4b1fa501b283145fa0f46b25c98fc74b298b9cf8c", "evidence_files": 11, "evidence_root": "sha256:d5c1bceb4d57ef0eb42797c58801b5926509711614c3e38bb7105b6efa3942f2", "files": 941, - "generated_at_commit": "4cc3bdda4ace926eb2a9a976551dc525279c53b8", - "source_tree": "sha256:6e7e567b937b92a5e24042e965e2e7809692725bea4de0d51e9345c9e6391b6c" + "generated_at_commit": "703e09c0cc8c973c93bc262912eef015ee4fc127", + "source_tree": "sha256:1394a8e2227a2bf9a719ed41b6dba5e19d5296f61d7ee4aea65b02d2646b7887" }, "owner_lane": "", "provenance": { diff --git a/tests/quietlock/run.sh b/tests/quietlock/run.sh index 24cb5aa94..b12d4f209 100755 --- a/tests/quietlock/run.sh +++ b/tests/quietlock/run.sh @@ -447,6 +447,98 @@ expect_block "echo lanes.sh queue X d y; make" # H10i `lanes.sh flush` is not a build word: the hook lets it start; the forge itself then waits for a # clear flag before every job (I9). Mutation killed: treating flush as heavy would stall the forge. expect_allow 'lanes.sh flush' +# H11 script runs and test programs (2026-10-08 GB10 hold overlaps: `bash scripts/test-linked-compose.sh`, +# which runs cargo test inside, a directly-run test binary). While someone else holds: a script whose +# text runs a build/test/QEMU program is blocked however it is started (shell + file, ./path, source, +# behind a wrapper, quoted path, one script calling another), and test programs are blocked by name. +# Mutations killed: no script content scan (H11a-H11i); content scan without comment/quote stripping +# (H11 allowed harmless.sh); no name rule for test scripts / target/*/deps / tests/ (H11j-H11o); +# no recursion into called scripts (H11h); no cwd resolution (H11c); refusal without the holder (H11a). +SD=$T/scripts-h11 +mkdir -p "$SD/sub" +printf '#!/bin/sh\nset -e\nfor t in a b; do\n cargo test "$@" -- --test-threads=1 2>&1 | tee -a log\ndone\n' > "$SD/heavy.sh" +printf '#!/bin/sh\n# runs the heavy one\nbash %s/heavy.sh "$@"\n' "$SD" > "$SD/outer.sh" +printf '#!/bin/bash\ntimeout 60 qemu-system-aarch64 -M virt -nographic\n' > "$SD/qemu.sh" +printf '#!/bin/sh\ncd x && make -j8 all\n' > "$SD/mk.sh" +printf "#!/bin/sh\n# make sure the notes exist; don't run make here\necho \"make test later\" >> notes.md\nprintf 'cargo build\\\\n' > todo.txt\ngrep -c make notes.md\n" > "$SD/harmless.sh" +cp "$SD/heavy.sh" "$SD/sub/run-it.sh" +printf '#!/bin/sh\nbash run-it.sh "$@"\n' > "$SD/sub/outer-rel.sh" +chmod +x "$SD"/*.sh "$SD/sub/run-it.sh" +cwd_json() { jq -n --arg c "$1" --arg d "$2" '{tool_name:"Bash",cwd:$d,tool_input:{command:$c}}'; } +reset; live_flag +h11_block() { # $1 name, $2 command, [$3 cwd] + if [ -n "${3:-}" ]; then hookrun "$(cwd_json "$2" "$3")"; else hookrun "$(bash_json "$2")"; fi; rc=$? + check "H11 blocked ($1): $2" '[ $rc = 2 ] && grep -q QUIETLOCK_REFUSED "$T/hookerr" && grep -q "holder=.OTHER quietlock test" "$T/hookerr"' +} +h11_allow() { + if [ -n "${3:-}" ]; then hookrun "$(cwd_json "$2" "$3")"; else hookrun "$(bash_json "$2")"; fi; rc=$? + check "H11 allowed ($1): $2" '[ $rc = 0 ]' +} +h11_block a "bash $SD/heavy.sh" +h11_block a "sh $SD/heavy.sh --nocapture" +h11_block b "$SD/heavy.sh" +h11_block c "./heavy.sh" "$SD" +h11_block c "bash sub/run-it.sh" "$SD" +h11_block d "cd $SD && bash heavy.sh" +h11_block e "timeout 600 bash $SD/heavy.sh" +h11_block e "nohup bash $SD/heavy.sh > log 2>&1 &" +h11_block f "source $SD/heavy.sh" +h11_block f ". $SD/heavy.sh" +h11_block g "bash \"$SD/heavy.sh\"" +h11_block h "bash $SD/outer.sh" +h11_block i "bash $SD/qemu.sh" +h11_block i "sh $SD/mk.sh" +h11_block j "bash scripts/test-linked-compose.sh /a /b /c" "$T" +h11_block j "cd ~/w/sc && bash scripts/test-linked-compose.sh" "$T" +h11_block k "./target/release/deps/aien_daemon-0123abcd --include-ignored" "$T" +h11_block k "target/aarch64-unknown-linux-gnu/debug/deps/x-1" "$T" +h11_block l "tests/quietlock/run.sh" "$T" +h11_block l "sh tests/run.sh" "$T" +h11_block m "./build/store_test" "$T" +h11_block n "timeout 900 ./target/release/deps/m19-77aa" "$T" +h11_block o "bash scripts/run_tests.sh" "$T" +h11_allow p "bash $SD/harmless.sh" +h11_allow p "$SD/harmless.sh" +h11_allow q "cat $SD/heavy.sh" +h11_allow q "grep -n cargo $SD/heavy.sh tests/x.txt" +h11_allow q "sed -n 1,5p scripts/test-linked-compose.sh" "$T" +h11_allow q "ls target/release/deps/ tests/" +h11_allow q "git diff -- tests/ scripts/test-x.sh" +h11_allow v "git diff origin/main...pr -- crates ':!**/tests/**' | grep x" +h11_allow v "cmp <(git show origin/main:specs/keys/k) ~/w/native/tests/fixtures/keys/k" +h11_allow v "X=\$(cd a && pwd)/tests/runtime/m.c; cat \$X" +h11_allow v "cat \${HOME}/w/tests/notes.txt" +# Review of #345: a wrapper's later words are not all programs; only the wrapped command is. +h11_allow x "timeout 5 cat tests/a.txt" +h11_allow x "sudo -u bob cat tests/a.txt" +h11_allow x "nice -n5 grep x tests/a.txt" +h11_allow x "env GIT_PAGER=cat git diff tests/a.txt" +h11_allow x "xargs -0 cat tests/a.txt" +h11_allow x "watch -n 2 cat tests/a.txt" +h11_allow x "nohup sleep 1 > tests/out.log 2>&1 &" +h11_block y "sudo -u bob ./target/release/deps/x-1" "$T" +h11_block y "timeout -s KILL 60 bash $SD/heavy.sh" +h11_block y "taskset -c 0-3 nice -n 5 tests/run.sh" "$T" +h11_block z "bash < $SD/heavy.sh" +h11_block z "bash -s <$SD/heavy.sh" +h11_block z "cargo -q test --release" +h11_block z "cargo +nightly test" +h11_block z "timeout 900 \$PY bench/tools/test_runner_offline.py" "$T" +h11_block z "python3 -u tests/test_x.py" "$T" +h11_block z "python3 -m pytest -q" "$T" +h11_allow z "perl -0777 -pi -e s/a/b/ tests/x.rs bench/tools/test_y.py" "$T" +h11_allow z "python3 -c pass tests/test_x.py" "$T" +h11_allow z "python3 tools/report.py tests/a.txt" "$T" +h11_allow z "timeout 5 \$PY tools/report.py" "$T" +h11_block z "bash $SD/sub/outer-rel.sh" "$T" +h11_block w "bash \${HOME}/w/scripts/test-x.sh" +h11_allow r "bash -n $SD/heavy.sh" +h11_allow s "quietlock hold --owner me --minutes 5 -- bash $SD/heavy.sh" +h11_allow t "QUIETLOCK_HOLD=qOTHER-1-0 bash $SD/heavy.sh" +h11_allow t "QUIETLOCK_HOLD=qOTHER-1-0 ./target/release/deps/x-1" "$T" +reset +h11_allow u "bash $SD/heavy.sh" +h11_allow u "./target/release/deps/x-1" "$T" fi diff --git a/tools/.crumb b/tools/.crumb index a1d587066..37971293a 100644 --- a/tools/.crumb +++ b/tools/.crumb @@ -26,19 +26,19 @@ "children": [ { "digest": "9cd3943087595dd868914a23a9fef7bebda3d78b773762c287ac4b7a6c2e2f40", - "last_commit": "05ed1a1", + "last_commit": "80ca5d4", "name": "argus", "purpose": "Directory tools/argus. Purpose not yet described by a human." }, { "digest": "1ccbb2bd2ac34a90fdd96376bcca759d4a2c0262ac43aa41839c0cc6e48f0693", - "last_commit": "e722877", + "last_commit": "80ca5d4", "name": "brownian", "purpose": "Directory tools/brownian. Purpose not yet described by a human." }, { "digest": "64fe22fe57fab7e61e65cb7652e73dbde613c260cb8677b05d8b98a067231e83", - "last_commit": "00f54b6", + "last_commit": "80ca5d4", "name": "dual_experiment", "purpose": "Runner for the DUAL applicability experiment: runs the pre-registered campaign and writes result" }, @@ -50,20 +50,20 @@ }, { "digest": "98d1f4d802b90006977d73b14acb92971927f2cf5bdf05d8dc5653a1b10fcf1b", - "last_commit": "ae1dd00", + "last_commit": "80ca5d4", "name": "turing_verify_indep", "purpose": "Directory tools/turing_verify_indep. Purpose not yet described by a human." } ], "children_root": "sha256:8a042dc49a250f0d1b7ae1358fc70bf7bdc9eff651a5ff7c9ee41fd49d329041", - "compiled_at": "2026-10-06T18:54:05Z", + "compiled_at": "2026-10-08T12:58:10Z", "compiler": "crumb-compile/1", - "digest": "sha256:ff24f7b12ceb0448c4da80d43e8ff249a3176ad3b374c3c27cc71e537ba66a00", + "digest": "sha256:8d09b39d6d457128ffa8b3a3e3a8bc16cb619d952dd8db04dc3fc3cda7d38890", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 137, - "generated_at_commit": "a76a010c6414378b1f6abc8020837ae094ebe7ed", - "source_tree": "sha256:3d545c18e409b44f2cc8d0d4d8fabfe622fbb3872c93a9bc7e457458747a6d1d" + "generated_at_commit": "97d1b9a512a72ff766b832361d178eb3e87f97a9", + "source_tree": "sha256:415cebf26d234547c66bcecfa540b9d3cfc1f419628124b2270b5248ead4aeab" }, "owner_lane": "", "provenance": { diff --git a/tools/quietlock/README.md b/tools/quietlock/README.md index e8b49850d..17269e599 100644 --- a/tools/quietlock/README.md +++ b/tools/quietlock/README.md @@ -7,7 +7,7 @@ The quiet flag (`~/workspace/.spark-quiet`) says "one heavy run owns the machine - **scripts**: run them as `quietlock run -- ` (refused with exit 75 while someone else holds) or own the machine with `quietlock hold --owner ID --minutes N -- `. - **lanes.sh queue/flush/forge**: once wired as described below. -**The `mk/` gate is the real lock.** It decides with `quietlock check`, never by matching command text. `quiet-guard.sh` in this folder is **advisory only**: a courtesy filter for Claude Code tool calls that pattern-matches command text and can be fooled (quoted or escaped command names, `eval` of built strings, a script that runs make inside). Anything it misses in omega is still refused by the `mk/` gate. For repos without such a gate (aienos, cargo, QEMU runs), the hook is the only guard until their entry points call `quietlock run`. +**The `mk/` gate is the real lock.** It decides with `quietlock check`, never by matching command text. `quiet-guard.sh` in this folder is **advisory only**: a courtesy filter for Claude Code tool calls that pattern-matches command text and can be fooled (quoted or escaped command names, `eval` of built strings, a script path held in a variable). Since 2026-10-08 it also reads the scripts a command runs (`bash x.sh`, `./x.sh`, `source x.sh`, up to 3 levels deep) and blocks test programs by name (`target/**/deps/*`, `tests/*`, `test-*.sh`). It cannot stop work already running when a hold starts: long suites should call `quietlock check` between stages. Also not caught: script paths held in a variable or containing spaces or globs (`bash "$X"`, `bash *.sh`), `cat x.sh | bash`, `find -exec`, loops over a deps folder (`for f in target/*/deps/*; do $f; done`), and `cd target/release/deps && ./foo`. Interpreters (`python3`, `node`, `perl`, `ruby`, `$PY`) are blocked only for a test-named file or `-m pytest|unittest`; an inline program (`perl -pi -e`, `python3 -c`) treats its files as data. Anything it misses in omega is still refused by the `mk/` gate. For repos without such a gate (aienos, cargo, QEMU runs), the hook is the only guard until their entry points call `quietlock run`. ## Commands and exit codes | Command | Meaning | diff --git a/tools/quietlock/quiet-guard.sh b/tools/quietlock/quiet-guard.sh index 5d658ac0e..ee1eac9c6 100755 --- a/tools/quietlock/quiet-guard.sh +++ b/tools/quietlock/quiet-guard.sh @@ -3,7 +3,10 @@ # (Claude Code PreToolUse hook). The queen installs it; nothing here edits ~/.claude. # # ADVISORY ONLY. This hook is a courtesy filter; it can be fooled (quoted or -# escaped command names, `eval` of built strings, scripts that run make inside). The REAL lock is enforced at actual +# escaped command names, `eval` of built strings, a script path held in a variable, +# programs that start builds without a shell script). It cannot stop work that +# is ALREADY RUNNING when a hold starts (a background suite launched before the +# hold): long suites must call `quietlock check` between stages themselves. The REAL lock is enforced at actual # entry points: mk/quiet.mk (every omega make goal runs `quietlock check`), # scripts run under `quietlock run --` / `quietlock hold`, and lanes.sh # queue/flush/forge once wired to quietlock. Those never use text matching. @@ -27,6 +30,15 @@ # parsing. For sh/bash/dash/zsh/ksh with any -c cluster (-c, -lc), # the command text, quoted or not, is checked. So `echo "make test" >> x.md`, # `sed -i 's/make/x/' a.md` and heredocs into handoff notes are never blocked. +# - Scripts and test programs (2026-10-08, three overlaps during a GB10 hold): a +# script the command runs (`bash|sh FILE`, `./FILE` or any path at command +# position, `source FILE`, a path after a wrapper) is read, comments dropped, +# and scanned by the same rules, following the scripts it runs up to 3 levels. +# Relative paths resolve against the tool call's cwd, `cd DIR` in the same +# command and the calling script's folder. Test programs are blocked by name: +# target/**/deps/, tests/, test-*/*_test(s) files run by path, +# test-*.sh / *_test(s).sh / run_tests*.sh. `bash -n FILE` (syntax only) runs +# nothing. The refusal names the holder (from `quietlock check`). # Needs: POSIX sh, awk, sed, grep, jq; quietlock on PATH or $QUIETLOCK_BIN. input=$(cat) tool=$(printf '%s' "$input" | jq -r '.tool_name // ""' 2>/dev/null) @@ -59,69 +71,190 @@ if [ -n "$allow" ] && printf "%s" "$cmd" | grep -Eq -- "$allow"; then echo "quiet-guard: allowed by the flag allow line (DEPRECATED, use quietlock hold)" >&2; exit 0 fi -# Strip heredoc bodies, collect `-c '...'` / `-c "..."` texts, strip quoted text. -body=$(printf '%s\n' "$cmd" | awk ' +# The working directory of the tool call (relative script paths resolve against it). +cwd=$(printf '%s' "$input" | jq -r '.cwd // ""' 2>/dev/null) +[ -n "$cwd" ] || cwd=$PWD + +# scan_text DEPTH BASEDIR... (text on stdin): print what makes the text heavy, or nothing. +# Same rules for a typed command and for the text of a script it runs (2026-10-08: a script +# that runs cargo test inside, started as `bash scripts/x.sh`, passed the command-word check). +scan_text() { + _depth=$1; shift + # Strip heredoc bodies, collect `-c '...'` / `-c "..."` texts, strip quoted text. + # Comments are dropped only in script files (depth > 1): in a typed command a "#" may sit + # inside an unbalanced quote, and the command-word check never needed it. + _body=$(awk -v nocomment=$((_depth > 1)) ' function delim(s, d) { d = s; sub(/.*<<-?[ \t]*/, "", d); sub(/[ \t;|&].*/, "", d); gsub(/["\047\\]/, "", d); return d } stop != "" { t = $0; if (strip) sub(/^\t+/, "", t); if (t == stop) stop = ""; next } + nocomment && /^[ \t]*#/ { next } { print } /<<-?[ \t]*["\047]?[A-Za-z_][A-Za-z0-9_]*/ && $0 !~ /<<c flag cluster (sh -c, bash -lc, dash -xc ...) is a + # command: collect it. Only after a shell name, so `grep -c "make" notes.md` stays allowed. + _inner=$(printf '%s\n' "$_body" | tr '\n' '\001' \ + | grep -a -o -E -e "(^|[^A-Za-z0-9_])(sh|bash|dash|zsh|ksh)( +-[A-Za-z]+)* +-[A-Za-z]*c[A-Za-z]* +'[^']*'" \ + -e '(^|[^A-Za-z0-9_])(sh|bash|dash|zsh|ksh)( +-[A-Za-z]+)* +-[A-Za-z]*c[A-Za-z]* +"[^"]*"' \ + | sed -e "s/^[^'\"]*.//" -e 's/.$//' | tr '\001' '\n') + # A quoted single word holding a slash is a path ("$HOME/x/run.sh"): keep it, unquoted. + _scan=$( { printf '%s\n' "$_body" | unquote_paths | strip_quotes; printf '%s\n' "$_inner" | unquote_paths | strip_quotes; } \ + | if [ "$_depth" -gt 1 ]; then sed -E 's/(^|[[:space:]])#.*$/\1/'; else cat; fi) + _out=$(printf '%s\n' "$_scan" | awk "$AWK_HEAVY") + _h=$(printf '%s\n' "$_out" | grep -v -E '^(SCRIPT|CD) ' | head -1) + if [ -n "$_h" ]; then printf '%s\n' "$_h"; return; fi + [ "$_depth" -lt 3 ] || return + _cds=$(printf '%s\n' "$_out" | sed -n 's/^CD //p') + printf '%s\n' "$_out" | sed -n 's/^SCRIPT //p' | head -20 | while IFS= read -r _w; do + _f=$(resolve "$_w" "$@" $_cds) || continue + _h=$(scan_text $((_depth + 1)) "$(dirname "$_f")" "$@" < "$_f") + if [ -n "$_h" ]; then + case $_h in *" (in script "*) printf '%s\n' "$_h";; *) printf '%s (in script %s)\n' "$_h" "$_f";; esac + break + fi + done +} +# Flatten newlines to \001 while stripping, so quotes may span lines; then restore. strip_quotes() { tr '\n' '\001' | sed -e "s/'[^']*'//g" -e 's/"[^"]*"//g' | tr '\001' '\n'; } -# Quoted text after a shell's -c flag cluster (sh -c, bash -lc, dash -xc ...) is a -# command: collect it. Only after a shell name, so `grep -c "make" notes.md` stays allowed. -inner=$(printf '%s\n' "$body" | tr '\n' '\001' \ - | grep -a -o -E -e "(^|[^A-Za-z0-9_])(sh|bash|dash|zsh|ksh)( +-[A-Za-z]+)* +-[A-Za-z]*c[A-Za-z]* +'[^']*'" \ - -e '(^|[^A-Za-z0-9_])(sh|bash|dash|zsh|ksh)( +-[A-Za-z]+)* +-[A-Za-z]*c[A-Za-z]* +"[^"]*"' \ - | sed -e "s/^[^'\"]*.//" -e 's/.$//' | tr '\001' '\n') -scan=$( { printf '%s\n' "$body" | strip_quotes; printf '%s\n' "$inner" | strip_quotes; } ) +unquote_paths() { sed -E -e "s#'([A-Za-z0-9_.~\${}+@%=,-]*/[A-Za-z0-9_./~\${}+@%=,-]*)'#\\1#g" -e "s#\"([A-Za-z0-9_.~\${}+@%=,-]*/[A-Za-z0-9_./~\${}+@%=,-]*)\"#\\1#g"; } +# resolve WORD BASEDIR...: print the readable script file WORD names (absolute, or relative to one +# of the base dirs), or fail. A script is a regular text file starting with #! or named *.sh/*.bash, +# under 1 MiB. ~ and $HOME / ${HOME} are expanded; any other $ makes the word unresolvable. +resolve() { + _w=$1; shift + case $_w in "~/"*) _w=$HOME/${_w#\~/};; "\$HOME/"*) _w=$HOME/${_w#\$HOME/};; "\${HOME}/"*) _w=$HOME/${_w#\$\{HOME\}/};; esac + case $_w in *'$'*|'') return 1;; esac + case $_w in /*) set -- "$_w";; *) _r=$_w; _l=""; for _b in "$@"; do + case $_b in "~/"*) _b=$HOME/${_b#\~/};; /*) ;; *) _b=$cwd/$_b;; esac; _l="$_l +$_b/$_r"; done; set -- $(printf '%s\n' "$_l" | sed '/^$/d');; + esac + for _p in "$@"; do + [ -f "$_p" ] && [ -r "$_p" ] || continue + [ "$(wc -c < "$_p")" -le 1048576 ] || continue + case $_p in *.sh|*.bash) printf '%s\n' "$_p"; return 0;; esac + [ "$(head -c 2 "$_p")" = '#!' ] && { printf '%s\n' "$_p"; return 0; } + done + return 1 +} # Per shell segment: skip VAR=value words and shell keywords; the next word is the command. -# - Known wrapper (env sudo nice ...): block if ANY later word is heavy (no per-option parsing). +# - Known wrapper (env sudo nice ...): block if ANY later word is heavy (no per-option parsing); +# a later shell word is handled like a shell at command position; a later word with a slash is +# a script to look into. # - Shell (sh bash dash zsh ksh) with a -c cluster: the next unquoted word is a command. -heavy=$(printf '%s\n' "$scan" | awk ' +# A shell with a file argument runs that file: blocked by name (test program) or looked into +# (SCRIPT line); -n (syntax check only) runs nothing. +# - source / . FILE: the file is looked into. +# - A command word with a slash runs that file: blocked by name or looked into. +# - `cd DIR` segments are printed (CD lines) so `cd d && bash x.sh` finds d/x.sh. +# Test programs by name: target/**/deps/, tests/ or test-*/ *_test(s) files run by path, +# and test-*.sh / *_test(s).sh / run_tests*.sh scripts. +AWK_HEAVY=' BEGIN { wrap = " env sudo doas nice ionice nohup setsid time timeout stdbuf taskset chrt xargs exec command builtin eval watch " kw = " if then elif else fi do done while until for in case esac ! { } " shells = " sh bash dash zsh ksh " + interps = " python python3 node perl ruby " + } + function interpargs(k, m, j) { # w[k] is an interpreter (python3, $PY ...): its test file or test module + for (j = k + 1; j <= m; j++) { + if (w[j] == "-m" && w[j+1] ~ /^(pytest|unittest)$/) return w[k] " -m " w[j+1] + if (w[j] ~ /^-[A-Za-z0-9.]*[ecE]/) return "" # inline program (perl -pi -e, python3 -c): files are data + if (w[j] ~ /^[-<>0-9]/) continue + return testname(w[j]) ? w[j] " (test program, run by " w[k] ")" : "" + } + return "" } + function isinterp(c) { return index(interps, " " base(c) " ") || c ~ /^\$[A-Za-z_]/ } function base(s) { sub(/.*\//, "", s); return s } - function isheavy(c, nxt, b) { + function isheavy(c, nxt, notest, b) { b = base(c) if (b ~ /^(make|gmake|cmake|ninja|ctest|gcc|g\+\+|clang|clang\+\+|cc|rustc|verify_all\.sh|est_load.*|run_gate.*|run_.*gates\.sh)$/ || b ~ /^qemu-system/) return c - if (b == "cargo" && nxt ~ /^(build|test|run|bench|clippy)$/) return c " " nxt + if (b == "cargo" && nxt ~ /^(build|test|run|bench|clippy|nextest)$/) return c " " nxt if (c ~ /^\.\/test[-_a-z0-9]*$/) return c + if (!notest && testname(c)) return c " (test program)" + return "" + } + function testname(c, b) { # a test program or test script, by name + b = base(c) + if (c ~ /(^|\/)target\/(.*\/)?deps\/[^\/]+$/) return 1 + if (b ~ /^(test[-_].*|.*[-_]tests?|run[-_]?tests.*)\.(sh|bash|py)$/) return 1 + if (index(c, "/") && (c ~ /(^|\/)tests?\/[^\/]/ || b ~ /^tests?[-_]/ || b ~ /[-_]tests?$/)) return 1 + return 0 + } + function shellargs(k, m, j, h) { # w[k] is a shell; return heavy text or "" (prints SCRIPT) + for (j = k + 1; j <= m; j++) { + if (w[j] ~ /^-[A-Za-z]*c[A-Za-z]*$/) { h = isheavy(w[j+1], w[j+2]); return h == "" ? "" : h " (in " base(w[k]) " " w[j] ")" } + if (w[j] ~ /^-[A-Za-z]*n[A-Za-z]*$/) return "" + if (w[j] ~ /^[-+]o$/) { j++; continue } + if (w[j] ~ /^[-+]/) continue + if (w[j] == "<") { if (w[j+1] != "") print "SCRIPT " w[j+1]; return "" } # bash < FILE runs FILE + if (w[j] ~ /^<[^<]/) { print "SCRIPT " substr(w[j], 2); return "" } + if (w[j] ~ /^[0-9]*[<>]/) { if (w[j] ~ /^[0-9]*[<>]+&?$/) j++; continue } + if (testname(w[j])) return w[j] " (test script, run by " base(w[k]) ")" + print "SCRIPT " w[j]; return "" + } return "" } { - gsub(/\$\(|`|\(|\)|\{|\}|&&|\|\||[;&|!]/, "\n") + # Text after ")" or "}" is not a command position for the new file rules (X=$(cd a)/tests/f, + # cmp <(...) tests/f, ${HOME}/tests/f): such segments start with \002 and get only the + # command-word check the hook always had. + s = $0 # ${NAME} -> $NAME first, so its "}" does not end a command + while (match(s, /\$\{[A-Za-z_][A-Za-z0-9_]*\}/)) s = substr(s, 1, RSTART) substr(s, RSTART + 2, RLENGTH - 3) substr(s, RSTART + RLENGTH) + $0 = s + gsub(/[)}]/, "\n\002") + gsub(/\$\(|`|\(|\{|&&|\|\||[;&|!]/, "\n") n = split($0, seg, "\n") for (i = 1; i <= n; i++) { + closed = (substr(seg[i], 1, 1) == "\002"); if (closed) seg[i] = substr(seg[i], 2) m = split(seg[i], w, /[ \t]+/); k = 1 + # cargo -q test, cargo +nightly test: the subcommand is the first word that is not an option. + for (q = 1; q < m; q++) if (base(w[q]) == "cargo") { r = q + 1; while (r <= m && w[r] ~ /^[-+]/) r++; if (r > q + 1 && r <= m) w[q+1] = w[r] } while (k <= m && (w[k] == "" || w[k] ~ /^[A-Za-z_][A-Za-z0-9_]*=/ || index(kw, " " w[k] " "))) k++ if (k > m) continue + if (closed) { h = isheavy(w[k], w[k+1], 1); if (h != "") { print h; exit }; continue } h = isheavy(w[k], w[k+1]); if (h != "") { print h; exit } b = base(w[k]) if ((b == "command" || b == "type" || b == "which") && w[k+1] ~ /^-[vVp]*$/) continue # lookup, not a run + if (b == "cd" && w[k+1] != "" && w[k+1] !~ /^-/) { print "CD " w[k+1]; continue } + if (b == "source" || b == ".") { if (w[k+1] != "") print "SCRIPT " w[k+1]; continue } if (index(wrap, " " b " ")) { - for (j = k + 1; j <= m; j++) { h = isheavy(w[j], w[j+1]); if (h != "") { print h " (after " b ")"; exit } } - } else if (index(shells, " " b " ")) { - for (j = k + 1; j < m; j++) if (w[j] ~ /^-[A-Za-z]*c[A-Za-z]*$/) { - h = isheavy(w[j+1], w[j+2]); if (h != "") { print h " (in " b " " w[j] ")"; exit } - break + # Any later heavy word blocks (as always). The file rules apply only to the wrapped + # command itself: the first word that is not an option, an option argument, a + # number (timeout 60, taskset 0-3), VAR=value, another wrapper or a redirect, so + # `timeout 5 cat tests/a.txt` and `nohup x > tests/out.log` stay allowed. + found = 0; skip = 0 + for (j = k + 1; j <= m; j++) { + h = isheavy(w[j], w[j+1], 1); if (h != "") { print h " (after " b ")"; exit } + if (found) continue + if (skip) { skip = 0; continue } # an option argument or redirect target (still checked above) + if (w[j] ~ /^[0-9]*[<>]/) { if (w[j] ~ /^[0-9]*[<>]+&?$/) skip = 1; continue } + if (w[j] ~ /^-/) { if (w[j] ~ /^-[ugncskIPLdp]$/) skip = 1; continue } + if (w[j] ~ /^[0-9][0-9a-fx.,:-]*[smhd]?$/ || w[j] ~ /^[A-Za-z_][A-Za-z0-9_]*=/ || index(wrap, " " base(w[j]) " ")) continue + found = 1 + if (index(shells, " " base(w[j]) " ")) { h = shellargs(j, m); if (h != "") { print h " (after " b ")"; exit }; continue } + if (isinterp(w[j])) { h = interpargs(j, m); if (h != "") { print h " (after " b ")"; exit }; continue } + if (testname(w[j])) { print w[j] " (test program) (after " b ")"; exit } + if (index(w[j], "/")) print "SCRIPT " w[j] } + } else if (index(shells, " " b " ")) { + h = shellargs(k, m); if (h != "") { print h; exit } + } else if (isinterp(w[k])) { + h = interpargs(k, m); if (h != "") { print h; exit } + } else if (index(w[k], "/")) { + print "SCRIPT " w[k] } } - }') + }' +heavy=$(printf '%s\n' "$cmd" | scan_text 1 "$cwd") [ -n "$heavy" ] || exit 0 -echo "QUIETLOCK_REFUSED BLOCKED by quiet-guard: '$heavy' is a build/test command and the Spark quiet flag is held. $msg Do code-only work or wait. The holder runs its commands under 'quietlock hold' (or prefixes QUIETLOCK_HOLD=)." >&2 +echo "QUIETLOCK_REFUSED BLOCKED by quiet-guard: '$heavy' is a build/test command and the Spark quiet flag is held by someone else. $msg Do code-only work or wait. The holder runs its commands under 'quietlock hold' (or prefixes QUIETLOCK_HOLD=)." >&2 exit 2