Skip to content

feat(hooks): judge heredocs, substitutions, loops, and redirections structurally - #175

Merged
furedea merged 1 commit into
mainfrom
feat/judge-shell-syntax-structurally
Oct 17, 2026
Merged

furedea merged 1 commit into
mainfrom
feat/judge-shell-syntax-structurally

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Since ADR-0034 deployed, 313 of 354 hook escalations were syntax: quoted heredocs fed to python3, command substitution, for loops, and redirections. All of these are contained by the sandbox.

  • Substitutions and clauses. Command, process, and arithmetic substitution, for/while/if/case clauses, and test clauses now parse. Every inner command is judged on its own by the allowlist, the forbidden rules, and the dangerous-Git guard: echo "$(rm -rf x)" is denied, and a force push inside a loop is denied. A substituted word is a run-time word.
  • Heredocs. A heredoc is standard input. A heredoc fed to a shell is parsed as a script. Only a shell heredoc whose text the shell computes, eval or sh -c of a computed script, and dollar-quoted words still ask.
  • Rules see command words only. Redirections no longer escalate, since the sandbox confines writes. Heredoc bodies are data, so forbidden-looking text inside a Python heredoc no longer trips the forbidden rules.
  • Interpreters. python, python3, and node are sandbox-contained programs that take any argument; uv run python and uv run --frozen python take any arguments. python -m pip stays denied.

Known gap, left for a follow-up: the forbidden patterns are unanchored, so a quoted argument that merely contains text such as a bulk staging command (for example a PR body passed with --body) is still denied. This PR body is passed with --body-file for that reason.

Closes #174

Verification

  • uv run --frozen pytest tests/agents: 1537 passed. New tests cover exposed inner commands, run-time substituted words, heredocs as standard input, shell heredocs parsed as scripts, computed scripts still asking, and denials inside substitutions, clauses, and shell heredocs.
  • ruff check, ruff format, ty check, and lefthook pre-commit passed.

🤖 Generated with Claude Code

…tructurally

Every command inside a substitution, clause, or shell heredoc is now judged on its own.

Quoted heredocs are standard input, and rules match command words, so redirections no longer ask.

Interpreters take any argument; only scripts a shell computes at run time still ask.

Closes #174

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@furedea
furedea merged commit 21cba5e into main Oct 17, 2026
11 checks passed
@furedea
furedea deleted the feat/judge-shell-syntax-structurally branch October 17, 2026 07:24
furedea added a commit that referenced this pull request Oct 17, 2026
Replaying the 151 Bash commands run after #175 gave 58 non-allow
verdicts. 56 of them were prompts for local commands that used a shell
variable or a form the precise allowlist did not list. This PR keeps
prompts for effects the sandbox cannot undo.

- **Local commands pass in any form.** The allowed guard now governs
only `gh`, `curl`, and `wget`, listed per rule under `programs`. Every
other command passes unless a forbidden rule or the dangerous-Git guard
denies it. This covers `git commit -S`, `git -C $W add`, `sed -i ''`,
`cat > $D/pr.md`, and unlisted subcommands of approved tools.
- **Run-time words in governed programs.** A run-time word counts as a
placeholder, so it passes only where any value would. `gh pr view $N`
and `gh api repos/o/$r/... --jq` (reads) pass. `gh api $E --method
DELETE` asks.
- **The Git guard asks about a run-time word only when it can hide a
denial.** That means a dynamic program or subcommand, an argument of a
verb judged by its options (push, reset, branch, switch, checkout,
restore, rm, mv, gc, `worktree remove`), or the repository an implicit
push reads its branch from. `git -C $W push origin topic`, `git -C $R
worktree add ... $W`, and `git commit -m "$MSG"` pass.
- **Parser fixes.**
- A lone `[` is no longer a glob, so `[ -d "$W" ]` is not a run-time
program.
- Parameter operations such as `${c:0:7}` parse. A substitution inside
`${x:-$(rm -rf y)}` is still denied.
- **Permissions.** `ln -s` moves to allow. `git stash drop` and `git
stash clear` stay ask, because recovering a dropped stash needs
dangling-commit archaeology. The plan had listed them as recoverable;
that was wrong.
- **ADR-0036** supersedes ADR-0034.

Closes #177

## Verification

- `uv run --frozen pytest tests`: 1459 passed. The 3 errors in
`tests/hermes/test_hermes_gateway.py` also occur on main.
- Replayed every Bash command from today's sessions (284) through the
new hooks: 273 allow and 7 deny. The 4 remaining asks are:
  - a run-time program (`$P -c ...`);
  - zsh-only `${(@f)...}`;
  - `git worktree remove $R-$w`;
  - `curl` to a remote host.
- The existing denials stay green: substitutions, clauses, shell
heredocs, force pushes, pushes to main, `--no-verify`, and `git add -A`.
- ruff, ty, and lefthook pre-commit passed.

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

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

Judge heredocs, command substitution, loops, and redirections structurally

1 participant