Skip to content

feat(hooks): escalate unrecognized command forms to a prompt - #159

Merged
furedea merged 11 commits into
mainfrom
feat/escalate-unrecognized-command-forms
Oct 15, 2026
Merged

furedea merged 11 commits into
mainfrom
feat/escalate-unrecognized-command-forms

Conversation

@furedea

@furedea furedea commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Reduces the friction the agent harness adds to ordinary Git delivery (add, commit, push, PR creation) without widening any hard denial.

  • Precise command rules are matched against whole shell segments (grep --null-data). This closes a bypass where a newline inside a quoted argument could satisfy an anchored rule by itself, and lets multi-line quoted commit messages match.
  • git commit accepts any number of -m arguments in single or double quotes, mixed, for amended commits too.
  • An allow-prefixed command in an unlisted form, or a command the static inspection cannot decode, now returns permissionDecision: ask instead of exit 2. Deny prefixes, forbidden patterns, dangerous Git operations, secret policies, and invalid policy files still exit 2. The Codex, Devin, Hermes, and pi adapters harden the ask into a denial because their hooks cannot prompt. Escalations are audited with the governed prefix as detail.
  • $HOME, ${HOME}, and a leading ~ are resolved statically in shell inspection; every other expansion still requires review.
  • The verification scope check treats TMPDIR, CLAUDE_TMPDIR, and CLAUDE_CODE_TMPDIR as in scope and asks, instead of denying, for other out-of-worktree targets. A missing or corrupt registration is still denied.
  • git commit * and git push * run outside the Claude sandbox: inside it, SSH signing can neither read the key nor reach the agent socket, and the gh credential helper cannot read its configuration. The command hooks, the dangerous-Git guard, and the permission rules still govern both commands.
  • The git-workflow skill states the canonical commit command form, ADR-0033 records the decision, and ls-lint ignores *-workspace directories.

Closes #158

Verification

  • uv run --frozen pytest tests/agents: 1438 passed before the docs and settings commits; the subsets those commits touch (Claude settings, skill layout, sandbox escape, hook generation) passed afterwards.
  • uv run --frozen ruff check, ruff format --check, and ty check are clean.
  • lefthook pre-commit and commitlint passed on every commit.
  • Shared verify entry point (verification_session.py verify): the latest run reports 1544 passed, full suite. An earlier run had 3 errors in tests/hermes/test_hermes_gateway.py, whose nix build fixture asserts an empty stderr while Nix warns that the Git tree is dirty; that came from uncommitted changes that predate this branch and is unrelated to this change.
  • Manual check after home-manager switch, in an interactive Claude Code session: cat README.md > /dev/null (an allowed prefix in an unlisted form) showed a permission prompt and ran after approval, so a hook ask takes precedence over a matching allow rule in auto mode. "$HOME/.claude/hooks/verification_session.py" status <record> passed the hook, and a Write into the session scratchpad passed the scope check.
  • Not yet confirmed: that the git commit * and git push * sandbox exclusions take effect. A standalone git commit in the session that was running during the switch still failed to sign, so the exclusions appear to need a new session; check in a fresh one.

Departures from the plan

  • The commits on this branch are unsigned (git -c commit.gpgsign=false) and the pushes needed the sandbox disabled for those commands, which is what the sandbox exclusions above fix for future sessions.

🤖 Generated with Claude Code

furedea and others added 8 commits October 15, 2026 11:44
Line-based grep let a newline inside a quoted argument satisfy an anchored rule by itself.

It also hid every multi-line commit message from the rules. Match one NUL-free record instead.

Refs #158

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Git ignores *-workspace directories as agent-local state, but ls-lint still scanned them.

Pre-commit then failed on files the repository does not own.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The rule accepted one double-quoted message or repeated single-quoted ones, nothing else.

Accept any number of -m arguments in either quoting style, for amended commits as well.

Refs #158

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Every parameter expansion was refused, so the documented verification command was uninspectable.

Accept a plain HOME expansion and a leading tilde; every other expansion still requires review.

Refs #158

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Unlisted forms of allow-prefixed commands and uninspectable commands were refused outright.

Return an ask decision for those cases instead.

Exit 2 remains for deny prefixes, forbidden patterns, dangerous Git, and invalid policy files.

Provider adapters that cannot prompt harden the ask into a denial.

Escalations are audited with the governed prefix as a label.

Refs #158

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The scope check denied the session scratch directory and every cd into a sibling repository.

Treat TMPDIR and the Claude temp directories as in scope, and ask for other outside targets.

A missing or corrupt registration is still denied.

Refs #158

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… decision

commits.md names the one commit form the hooks accept without review.

ADR-0033 records why mismatches now reach the user instead of being refused.

Refs #158

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Inside the sandbox, git can neither read the signing key nor reach the SSH agent socket.

Every agent commit therefore failed, or had to be made unsigned.

The command hooks and permission rules still govern the commit itself.

Refs #158

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 15, 2026 03:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

furedea and others added 2 commits October 15, 2026 13:51
…r works

Inside the sandbox the gh credential helper cannot read its configuration, so every push failed.

The dangerous-Git guard and the permission rules still govern what may be pushed.

Refs #158

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Compound commands run inside the sandbox, where signing cannot reach the key or the agent.

The credential helper cannot read its configuration there either, so pushes fail the same way.

Refs #158

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@furedea
furedea force-pushed the feat/escalate-unrecognized-command-forms branch from ff7dd16 to 869ce52 Compare October 15, 2026 04:56
The sandbox docs keep cd, git -C, pipes, redirections, and chains inside the sandbox regardless.

Name them all so commit and push are issued in the one shape that signs and authenticates.

Refs #158

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@furedea
furedea merged commit 434de2f into main Oct 15, 2026
11 checks passed
@furedea
furedea deleted the feat/escalate-unrecognized-command-forms branch October 15, 2026 05:12
furedea added a commit that referenced this pull request Oct 15, 2026
## Summary

Makes the OS sandbox the safety boundary for ordinary commands and asks
only for effects that escape it or cannot be undone. Audit evidence from
one afternoon after #159: 94 hook escalations, 82 of them "syntax" (a
glob, `$VAR`, `$(...)`, or heredoc anywhere in the call), the rest
`grep`/`rg`/`cat` arguments that merely contained `\` or `$` inside
quotes; script execution prompted on every call.

- **Run-time words are reported, not refused.** The shell inspection now
marks a glob or a parameter other than `$HOME` as dynamic and keeps its
source text instead of raising. Command, process, and arithmetic
substitution, heredocs, and dollar-quoted strings are still refused.
- **Read-only programs are judged structurally.** `rg`, `grep`, `cat`,
`ls`, `find`, `jq`, and the other programs listed in
`allowed_commands.json` may take any literal, glob, or variable argument
as long as no redirection writes a file (`/dev/null` and fd duplication
are fine). `rg -n "def \w+" agents`, `rg foo *.py`, and `cat $FILE` are
allowed; `rg foo > out.txt` still asks.
- **Any other program with a run-time argument asks**, including `git
push $FLAGS`, `cd $DIR`, and a dynamic program name. A literal deny
prefix such as `rm -rf $DIR` still denies, and the forbidden hook no
longer escalates; escalation is the allowed hook's job.
- **Sandbox-contained execution and edits move from ask to allow:**
`python3`, `python`, `node`, `uv run python`, `uv run --frozen python`
(scripts, `-c`/`-e`, and a short module list), `sed -i`, `perl -i`,
`tee`, `truncate`. `python -m pip` is denied like `pip`. `uvx`, `npx`,
`pnpm dlx`, `bunx`, dependency changes, `rm`, merges, publishing, and
the sandbox escape still ask.
- **Trivial builtins** (`echo`, `printf`, `pwd`, `date`, `true`,
`false`, `test`, `basename`, `dirname`, `realpath`, `readlink`, `seq`)
are allowed so they no longer reach the classifier.
- A `cd` or `git -C` to a run-time directory asks in the verification
scope check instead of resolving a literal `$DIR` path.
- ADR-0034 records the decision and supersedes ADR-0031; the README
paragraph is updated.

Closes #162

## Verification

- `uv run --frozen pytest tests/agents`: 1492 passed.
- `uv run --frozen ruff check`, `ruff format --check`, and `ty check`
are clean; lefthook pre-commit and commitlint passed on both commits.
- The Codex execpolicy rows for `uv run python` and `sed -i` now expect
`allow`; `uvx` and `npx` rows expect `prompt`.
- Live check after `home-manager switch`: run `rg -n "def \w+" agents`
and `python3 -c 'print(1)'` in a new session and confirm neither
prompts; run `rg foo > out.txt` and confirm it asks.

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

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
@furedea-agent furedea-agent Bot mentioned this pull request Nov 12, 2026
1 task done
furedea added a commit that referenced this pull request Nov 12, 2026
agent-config 0.1.2(`3b3d9c5`)を取り込みます.#74 のモデル判定まわりの残りがすべて入ります.

| 取り込む変更(furedea/agent-config) | 中身 |
| --- | --- |
| #172 | 「ルールの見本のフォルダ」の判定を 1 か所にまとめる |
| #173 | jev-lint の子プロセスに `GIT_LITERAL_PATHSPECS=1` を渡す(#159) |
| #174 | 時間に頼らないタイムアウトのテスト(#171) |
| #175,#178 | Go と Rust のルールの穴と,境目の見本(#164) |
| #180 | 読み取り専用の GraphQL の問い合わせのあとに `jq` を付けてよくする |
| #177 | Stop のテストの行を,ランナーごとに 1 つの件数にまとめる(Rust は `312 passed` のように合計する)
|

- [x] `darwin-rebuild switch` で反映済み

ほかのセッションが main の古い `flake.lock` で反映すると,これらが取り消されます.早めにマージします.

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

---------

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Escalate unrecognized command forms to a prompt and accept ordinary commit messages

2 participants