Skip to content

Run the Hook Launcher Before Trusting It and Read Short-Option Clusters Through One Helper - #4032

Merged
ptr727 merged 4 commits into
developfrom
burndown/1172-agent-safety-launcher-and-clusters
Nov 10, 2026
Merged

ptr727 merged 4 commits into
developfrom
burndown/1172-agent-safety-launcher-and-clusters

Conversation

@ptr727

@ptr727 ptr727 commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Closes on promotion: #1172, #3783

Summary

Two maintainer-approved agent-safety fixes, one in the installer and one in the write guard. Merging waits on the maintainer's go-ahead after reading this diff, since it edits host-setup/agent-safety/.

#1172: run the hook launcher before trusting it (approved Option 1)

  • install.py no longer picks the interpreter it writes into settings.json by presence on PATH. launcher_problem() runs each candidate with a probe that must print a token and its version, and refuses one below the 3.11 floor. Its stderr is kept in the reason. A stub that exits 0, such as a Windows app execution alias, prints neither, so it is refused.
  • hook_launcher() tries python3, then sys.executable, and returns the reasons each refused candidate failed. The install chooses the launcher before writing anything, prints each candidate it passed over, and installs nothing when none passes.
  • Each hook's self-test now runs under that launcher rather than sys.executable, so a pass also proves the launcher runs the hook.
  • --report runs the launcher each registration names in the <launcher> <path> shape, through registered_launcher(). So a host registered before this fix reports STALE once that launcher stops running. Any other command shape is not run.
  • install.sh reads its probe's output against the 3.11 floor rather than its exit status, and no longer discards the probe's stderr.

#3783: read short-option clusters through one helper (approved design "one shared helper, extended to separated values")

  • _cluster(word, values, optional) returns a cluster's letters before its first value-taking letter, and whether the value is the next word (only where that letter ends the word). _flags(sub, args) walks a subcommand's words through it, with _OPTION_VALUES holding each subcommand's value letters, optional-value letters, and value-taking long options.
  • _push_targets, _skips_hooks (commit and push), the in-place commit check, the primary-checkout clean reader, and the git branch rename check all read through it. So do the other cluster readers in the same file, per the one-primitive-per-class rule: the forced worktree remove, the checkout/switch force check, the rebase operand count, and the symbolic-ref write check. The old _commit_flags, _operands, _REBASE_VALUES, _CHECKOUT_FORCE_CHARS, and the inline regexes are gone. The guard is 2431 lines, under its 2500-line ceiling.
  • The clean reader now skips the value after -e and --exclude, attached or separated. So clean -fen, -fe.env, -f -e -n, and -f --exclude -n are read as forcing, as git reads them, and are denied in a primary checkout.
  • Commit's -S and -u, branch's -t, and rebase's -S take an attached value only, as git parses them. So commit -Snkey and commit -uno carry no -n, and branch -umain is not a rename. A rebase -x or symbolic-ref -m value is no longer counted as an operand, and symbolic-ref -qd is read as a delete. These changes deny less only where git itself reads no such flag.

Verification

  • gh-write-guard.py --selftest passes with new rows for each case above, including the in-place commit -Sa (allowed) and -aS (denied) and symbolic-ref -- HEAD refs/heads/develop (still a branch move). Against develop's guard the new rows fail for -Snkey, push -o --no-verify, branch -umain, branch -u -m, and the four clean exclude forms.
  • Each clean row was checked against git itself in a throwaway repository: the four exclude forms delete an untracked file and -f -e x -n keeps it.
  • test_install.py passes, with a new TestLauncher class covering a stub exiting 0, a stub failing with stderr, a version below the floor, a missing launcher, the fallback past a broken python3, no working candidate, an install refusing with nothing written, an install past a broken python3, and --report flagging a registered launcher that cannot run.
  • ruff format, ruff check, mypy, shellcheck, shfmt, the prose gate, and the eol check pass. tests/test_guard_size.py passes.

Local strict review

Three recorded agent-skill passes. The first raised four findings, the second two, and the third none. Each introduced finding was fixed on this branch.

Pre-existing findings, filed

🤖 Generated with Claude Code

ptr727 and others added 3 commits November 10, 2026 08:21
…rs Through One Helper

The agent-safety installer chose the interpreter it writes into settings.json by
presence on PATH, so a stub that runs no script could be registered and the
write guard would never run. Each candidate is now run with a probe that must
print a token and a version at the 3.11 floor. The install picks the launcher
before writing anything and runs each hook's self-test under it. --report runs
the launcher each registration names. install.sh reads its probe's output and
leaves stderr visible.

The write guard read short-option clusters several ways. One helper now cuts a
cluster at its first value-taking letter and says whether the next word is the
value, and the push, commit, clean, and branch-rename readers go through it. A
clean's -e and --exclude values, attached or separated, are no longer read as a
dry run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The forced worktree remove, the checkout and switch force check, the rebase
operand count, and the symbolic-ref write check now read through the same
helper, so a rebase -x or symbolic-ref -m value is no longer an operand. The
retired _operands helper and its value sets go with them. Self-test rows pin
commit -u, branch -t, and the rebase and symbolic-ref readings, and a unit test
pins an attached commit -S in the in-place check. The launcher probe drops a
branch only a forged token reached.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
git symbolic-ref reads the words after -- as its name and ref, so a write
spelled that way is a branch move again. The in-place -S pin moves into the
guard's own in-place case table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings November 10, 2026 16:36
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3430a01 and a984fa8.

Files selected for processing: 6

  • host-setup/agent-safety/README.md
  • host-setup/agent-safety/claude/README.md
  • host-setup/agent-safety/claude/gh-write-guard.py
  • host-setup/agent-safety/claude/install.py
  • host-setup/agent-safety/claude/install.sh
  • host-setup/agent-safety/claude/test_install.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ptr727

ptr727 commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 6818c267f1160063d7ea0684b7aa500f67442a02, the content this pull request carries at that commit against develop, and it recorded 0 findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Approval is blocked by an unresolved critical repository-targeting bug, additional launcher validation failures, and missing Windows coverage.

4 open issues
What changed in this PR

This pull request hardens agent-safety launcher installation and consolidates Git short-option parsing in the write guard.

Changes:

  • Validates Python launchers before installation, self-tests, and registration reporting.
  • Updates the shell installer and documentation for launcher probing and fallback behavior.
  • Centralizes option-cluster parsing across push, commit, clean, branch, rebase, checkout, and symbolic-ref checks.
  • Expands installer and guard regression coverage.
File Description
host-setup/​agent-safety/​README.md Documents the revised Git short-option and clean-command parsing behavior.
host-setup/​agent-safety/​claude/​test_install.py Adds coverage for launcher validation, fallback, installation, reporting, and registration behavior.
host-setup/​agent-safety/​claude/​README.md Documents validated launcher selection, fallback behavior, and stale registration reporting.
host-setup/​agent-safety/​claude/​install.sh Probes POSIX Python candidates against the required version floor before selecting an installer launcher.
host-setup/​agent-safety/​claude/​install.py Validates launchers, uses the selected launcher for self-tests, and checks registered hook launchers.
host-setup/​agent-safety/​claude/​gh-write-guard.py Centralizes short-option cluster parsing and updates guard decisions across affected Git commands.

Review effort: Lite

@ptr727

ptr727 commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head a984fa8637860e826bbd7a78334089ede4c78af3, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 15.00000% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.91%. Comparing base (b38e084) to head (a984fa8).
⚠️ Report is 129 commits behind head on develop.

Files with missing lines Patch % Lines
host-setup/agent-safety/claude/gh-write-guard.py 15.00% 34 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4032      +/-   ##
===========================================
- Coverage    81.60%   78.91%   -2.70%     
===========================================
  Files           26       37      +11     
  Lines         9070    12658    +3588     
===========================================
+ Hits          7402     9989    +2587     
- Misses        1668     2669    +1001     
Flag Coverage Δ
python-3.13 78.91% <15.00%> (-2.70%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727

ptr727 commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@ptr727

ptr727 commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

/review

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ptr727
ptr727 merged commit 4673434 into develop Nov 10, 2026
13 checks passed
@ptr727
ptr727 deleted the burndown/1172-agent-safety-launcher-and-clusters branch November 10, 2026 17:41
ptr727 added a commit that referenced this pull request Nov 10, 2026
…Status (#4041)

## Summary

Fixes two of the three P1 findings raised on promotion PR #4039 against
the agent-safety launcher probe that #4032 added. Each fix fails closed,
and each comes with a test built on constructed input that fails against
the code on `develop`.

- `host-setup/agent-safety/claude/install.py:498` (`launcher_problem`):
a probe that printed the token followed by a non-numeric version, such
as `agent-safety-launcher 3a 11`, raised `ValueError` and aborted the
install or `--report`. That output is now a refusal, so
`hook_launcher()` moves on to the next candidate.
- `host-setup/agent-safety/claude/install.sh:16`: the wrapper ignored
the probe's exit status, so a stub that printed `ok` and exited 3 was
handed `install.py`. The output is now captured with an `&&` status
check before it is compared. The exposure was narrower than the finding
states, because `install.py`'s own `hook_launcher()` already re-probes
the hook launcher and checks its return code. What was at stake is only
which interpreter runs `install.py`.

## Deferred finding

- `host-setup/agent-safety/claude/install.py:530`
(`registered_launcher`) is deferred to #4040, on the maintainer's
decision. For the double-quoted shape `hook_command()` writes, the
finding is wrong: POSIX `shlex.split` keeps single backslashes, so a
quoted `C:\...` launcher splits intact. A UNC launcher loses one of its
leading backslashes inside double quotes, and a bare, unquoted
hand-written path loses all of them. Whether either of those is a defect
depends on which shell runs a hook on native Windows. Under Git Bash the
POSIX split matches what actually runs, and under cmd.exe it does not.
#4040 settles the executor before the split changes.

## Tests

New cases in `TestLauncher` in
`host-setup/agent-safety/claude/test_install.py`:

- `test_a_malformed_version_is_refused_and_the_next_candidate_tried`:
before the fix it raised `ValueError: invalid literal for int() with
base 10: '3a'`.
- `test_install_sh_passes_over_a_python_that_prints_ok_and_fails`: runs
`install.sh --help` with a `python3` stub that prints `ok` and exits 3,
placed ahead of a working `python`. Before the fix the wrapper exits 3.

`python3 -m unittest test_install` runs 196 tests, all OK. `shellcheck
install.sh`, `ruff check`, and `ruff format --check` are clean.

## Local review findings, declined

- The local pass judged both fixes over-hardening, saying only a stub
written for a test reaches the non-integer branch or prints `ok` while
failing. Declined: both are P1 findings verified real on #4039 with
constructed inputs, the maintainer kept them, and each fix fails closed
in a few lines.

A later local pass found that the new `install.sh` test's skip condition
carried a redundant `os.name` check. That is fixed in this PR.

## Pre-existing findings, not filed

- `host-setup/agent-safety/claude/install.ps1`, the Windows twin of
`install.sh`, which this PR does not touch, chooses `py -3` or `python3`
without running a version probe. A `python3` app execution alias would
be picked and would then fail loudly through `exit $LASTEXITCODE` rather
than fall through to the next candidate. `install.py` still enforces the
3.11 floor on its own.

Closes on promotion: none

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved installation checks for Python launchers. Invalid version
information and checks that fail despite printing a success message are
now rejected, allowing the installer to try another candidate and avoid
creating an incomplete installation.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
ptr727 added a commit that referenced this pull request Nov 10, 2026
…tall on Release, Cleanup and Handoff Fixes (#4039)

## Summary

Promotes burndown round 1 of the attended run of 2026-11-10 from
`develop` to `main`.

- #4035: the prose gate builds its HTML span without slicing
markdown-it-py's pattern, and the gate, `backlog_metrics.py`, and the
test requirements pin `markdown-it-py` exactly. That ends the import
crash 4.3.0 caused on every pull request.
- #4032: the agent-safety installer probes each hook launcher before
choosing one and installs nothing when none runs. The write guard reads
every short-option cluster through one table-driven helper. Merged on
the maintainer's go-ahead after reading the diff.
- #4029: `merge-and-release` installs the updated host-safety kit in its
release step, guarded against rolling a kit back. Where a promotion is
already merged under a release scope, it reads the publisher's runs
before asking.
- #4030: `pr_cleanup.py` names every git-ignored entry a worktree
removal deletes before it removes the tree.
- #4034: a handoff comment that only quotes a round mark is no longer
read as an archived round. `blocked` stays on while a new decision
waits, a default handoff pick is confirmed, and a track's final round is
written before `close`.

## Closes

Fixes #4033
Fixes #3935
Fixes #1172
Fixes #3783
Fixes #3897
Fixes #4019
Fixes #4009
Fixes #4013
Fixes #3679
Fixes #4018
Fixes #3914
Fixes #3841
Fixes #4017
Fixes #4010
Fixes #3791
Fixes #3795

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants