Repository navigation
refactor(hooks): shared shlex tokenizer + shared fail-closed guard; close 4 fail-opens - #41
Conversation
…lose 4 fail-opens Both gates on main detect git commands with an INVOKE regex whose option-value pattern [^\s]* cannot span a quoted arg with a space, so git -C "/has space" commit fails to match and the gate allows everything. Same regex, same fail-open, in both gates. DISCIPLINE BACKSTOPS, not security boundaries (every change is re-validated by a fresh pr-validator + GitHub branch protection). Replace the per-gate regex with one shared shlex tokenizer, zero fallbacks (operator-directed full simplification). - New shared .claude/hooks/gitcmd.py: git_invocations() tokenizes with shlex (posix, punctuation_chars) so a quoted spaced arg is one token, splits on shell separators so a compound command's args don't bleed into the next, and raises ValueError on an UNBALANCED/UNQUOTED quote. Also the shared fail-closed predicate mentions_subcommand() and the refspec pair is_force_refspec()/refspec_dst(): every predicate both gates need lives here ONCE -- the security-relevant fail-closed probe above all (R3). INVOKE deleted from both gates. -B so no __pycache__. - FAIL CLOSED on unparseable, NO fallback: what shlex cannot tokenize is an unbalanced/ unquoted quote (an apostrophe in a heredoc body, an unterminated quote) -- NOT a heredoc. A CLEAN heredoc tokenizes fine and is judged normally (git commit -F - <<EOF is ALLOWED on both main and this branch, not scanned for absence, as main documents). When a command genuinely cannot be tokenized and a git commit/push is plausibly present, block it with the accurate remedy (balance quotes; long message via -F file). - Positional scan_commit_args (commit): consumes the -m/-F value then classifies the rest, so post-message --no-verify/-n is caught and an attached -m"...trailer with an a..." is never a false flag. Unresolvable -C fails closed for a diff-checked tier. - pre-push-gate over the same parser, and force detection now catches a leading-+ refspec: `git push origin +feat/x` force-updates feat/x. main reads the + only while stripping the DESTINATION, so it blocked +main as a main-push but let +feat/x through. Force-push is forbidden on EVERY branch in every repo -- a real fail-open, now closed. vs origin/main, measured: 4 fail-opens closed (quoted-space -C; --no-verify after the message; a RUNTIME-tier commit on an unresolvable -C -- main already blocks the docs-tier case; a leading-+ force refspec to a non-main branch), 0 opened. Compound-arg bounding and clean-heredoc handling are UNCHANGED from main (both already correct) -- not claimed as fixes. In-tree test .claude/hooks/gate_test.py (new): drives both real gates over throwaway repos in its own mkdtemp trees and asserts gitcmd tokenization directly (clean heredoc TOKENIZES; apostrophe-in-body/unterminated quote -> ValueError; quoted-spaced -C is one token). 42 cases pass; the count is MEASURED by the assertion counter, never asserted as a literal. Restoring any of the four fail-opens fails a case here (R10 check-coverage). Known limitation (documented; its own immediate-next cutover): the hook fires before the command, so a compound 'git add && git commit' stages after the diff check reads the index. Separable -- this cutover's gate passes and proves its claim without the fix. Paired doctrine sweep: merged as plugins PR #19 (gitlink bumped to 3149fc9), adding the fail-closed clause and KEEPING the correct 'not scanned for absence' sentence (R1/R5). Assisted-by: Claude (fully tested and validated)
pr-validator — APPROVED ✅Fresh evaluator, independent of the author. I re-derived every verdict by execution; I inherited nothing from the PR body or from #40's fix table. Supersedes #40 (all six blocking findings independently re-verified as fixed). Change class: hook/workflow scripts ( #40's six blocking findings — each re-verified independently
Independent checks (not from the six)
Checklist
Decision: PASS. All six #40 findings are independently re-verified fixed; my own regression differential opens zero fail-opens and closes four; the gitlink bump and its ride-along doctrine changes are benign and gate-strengthening; the Assisted-by: Claude (analysed on a live system) |
…e shared tokenizer) Assisted-by: Claude (fully tested and validated)
…osed and recreated (2026.190.1835) `main` now gains exactly ONE commit per cutover, and a PR under review is UPDATED IN PLACE instead of being closed and recreated. Both follow from one change of merge method. The problem: the landing flow merged --rebase and required the author's cutover to be a single commit on feat/<slug>. Force-push is forbidden absolutely, so on a CHANGES-REQUESTED verdict there was no way to update the branch in place -- an amended commit diverges and can only be published by a force-push, and a second change commit would land on main as a second commit. The only remaining move was to close the PR and open a replacement, churning review history once per round (six times across PRs #36-#41 for one hook cutover). The fix -- atomicity is a property of main, not of the branch: - scripts/apply-branch-protection.sh enforces SQUASH-ONLY merge settings (allow_squash_merge=true, allow_rebase_merge=false, merge-commit off, delete-branch on) across all 11 repos. required_linear_history, enforce_admins, allow_force_pushes=false, allow_deletions=false and the required charly/claude-validation status context are UNCHANGED: this changes the merge METHOD only and weakens no gate. - The evaluator merges `gh pr merge --squash --delete-branch`, composing the squash message itself (subject + body + the author's Assisted-by trailer). The author's change, any review-round fix commits, and the merge-time version stamp fold into ONE commit on main. - On CHANGES REQUESTED the author appends a fix commit and pushes fast-forward; the status resets and the evaluator re-runs. Closing a PR is reserved for work that will not land at all. - The force-push ban is untouched and still absolute. `git commit --amend` on a PUSHED branch is now named explicitly as forbidden for the same reason. Paired doctrine sweep: plugins gitlink bumped 3149fc9 -> 1043577 (docs-only) -- the skill/agent side (git-workflow, agents, pr-validator) plus the merge-authority correction (authority is the superproject's committed permissions.allow pair; no autoMode key exists in any settings file). Independently validated by a fresh pr-validator (PR #42): bash -n clean; the changed verify predicate reports drift (exit 1) against pre-change settings and compliant (exit 0) after; every branch-protection invariant re-read live from the GitHub API on charly/plugins/distro-fedora and confirmed UNCHANGED; plugins 1043577 confirmed on plugins main and docs-only. Merge-time CalVer 2026.190.1835. Assisted-by: Claude (fully tested and validated)
…-free eval VM beds (#33) The superproject runtime half of #33 — the libvirt domain (and every per-domain resource: state dir, NVRAM, ssh key, seed ISO, ssh alias, ssh port, cloud-init instance-id) is keyed by the DEPLOY name (vmshared.VmDomainIdentity), not the shared kind:vm entity, with a per-deploy qcow2 overlay over a read-only entity base. Sibling beds sharing one entity via from: get distinct charly-<deploy> domains — collision-free by construction — so the long VM beds run CONCURRENTLY. - --domain flag on charly vm create/start/stop/destroy/console; destroy-by-domain. - Read side per-deploy (bedVmDomains / checkVmTarget / Runner.vmTargetName) so the libvirt:/spice: check verbs address charly-<deploy>. - Base-build FLOCK (acquireVmBuildLock) + content-signature idempotent skip-if-fresh makes the concurrent vm build <entity> preflight safe (RDD-proven; the concurrent roster never rewrites a base a live per-domain overlay backs onto). - Fixes the nested-child SSH-alias seam (deploykit.VmChildExecutor caller → 2-arg) the concurrent R10 caught. - R2 fold-ins: plugin-vm (14) + plugin-preempt (3) tabwriter-errcheck + dead-code lint cleanup. Submodule pointers: sdk → 2977d5c (v0.2026194.659, #35 merged); plugins → 55800b2 (v2026.194.0707, #41 merged). charly/go.mod require → v0.2026194.659. BREAKING CHANGE: deploykit.VmChildExecutor drops the *BundleNode param; the sole caller (charly/bundle_add_cmd.go) is updated here. R10: the FULL 4-bed concurrent eval-vm roster (fresh per-tree binary v2026.194.0736, all calver 2026.194.0741, simultaneous) — check-builder-vm PASS 9/210s, check-substrate PASS 9/187s, check-group PASS 5/263s (3-level group→vm→local), check-structkind PASS 5/265s (3-level structkind→vm→local); 4 distinct per-deploy domains + keys + seeds (validator-corroborated on disk), both deep-bed nested-member SSH seams GREEN, clean teardown (0 leftover domains). Validator re-ran gofmt/vet/build clean, golangci 0, go test green. Assisted-by: Claude (fully tested and validated)
Summary
Supersedes #40 (same cutover, all six blocking findings fixed). #40's branch was already
pushed and force-push is forbidden, so this lands as a fresh single-commit branch.
Replaces the
INVOKEregex in both PreToolUse gates with ONE sharedshlextokenizer(
.claude/hooks/gitcmd.py), zero fallbacks. These gates are discipline backstops, notsecurity boundaries — every change is re-validated by a fresh
pr-validator+ branch protection.Change class: hook scripts (
.claude/hooks/*) + CHANGELOG +pluginsgitlink bump.Gate: execute the changed scripts live. Tier:
fully tested and validated.Response to #40's six blocking findings
gate_test.py:131ranshutil.rmtree("/tmp")mkdtempparent; that parent is removed. Confirmed: this was the root cause of ENOENT harness-file losses I earlier misattributed to "a concurrent process" — an R1 violation on my part.gate_test.pyoutput below, unedited.gitcmd.mentions_subcommand()— the security-relevant predicate now has ONE definition (R3).git push origin +feat/xforce-pushed via plus-refspecgitcmd.is_force_refspec(); a leading+is force on every branch. 3 new cases.pluginsPR #19. Gitlink bumped to3149fc9.6+17+4+12expect().Also took the validator's R2 note: dropped the "pre-existing on `main`" framing from the
known-limitation paragraph; the separability claim carries it.
Fail-opens vs
origin/main— measured, not inheritedI re-measured each claim against
origin/mainrather than trusting #40's summary. One of#40's three claims was over-broad:
mainalready blocks the docs-tier unresolvable-C; it fails open only on the runtime tier. The CHANGELOG now says exactly that.Four fail-opens closed, zero opened: quoted-space
-C;--no-verifyafter the message;a runtime-tier commit on an unresolvable
-C; a leading-+force refspec to a non-mainbranch. Compound-arg bounding and clean-heredoc handling are UNCHANGED from
main(bothalready correct) — not claimed as fixes.
Check coverage (R10) — the new cases fail without the fix
Differential against the pre-fix push gate, harness sanity-checked (
--force-> rc=2):R10 evidence — verbatim
python3 .claude/hooks/gate_test.pyR0–R10
rmtree("/tmp")finding was RCA'd to root cause (dirname(mkdtemp(prefix="s p-"))==/tmp), not patched blind; it explains a real anomaly I had wrongly dismissed. The__pycache__/artifact was RCA'd too (written by the validator importinggate_test; neither the gates nor the test regenerate it — verified empirically).gitcmd.py: tokenizer and fail-closed predicate and refspec helpers.git grep 'feat/gate-doctrine'(bare) returns nothing; the retracted "a heredoc is blocked" phrase survives only insideCHANGELOG/self-correcting sentences (sanctioned historical context).git status+git stash listchecked before every tree action.Landing note:
git commit --amendwas denied by the classifier and explicitly authorized by the operator in the same turn before use. No force-push anywhere;6c73860remains intact onfeat/gate-accurate.Assisted-by: Claude (fully tested and validated)