Repository navigation
feat: opt-in process hooks at the tool boundary (PreToolUse/PostToolUse, default OFF) - #113
Merged
Merged
Conversation
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
Cora-caught MAJOR: the post-hook snapshot sat outside the ReadOnly guard, so with hooks wired every read_file call spawned the post-hook processes — contradicting the documented zero-overhead contract for ReadOnly tools. Gate the snapshot on risk and keep both notify calls on the snapshot.
ajianaz
force-pushed
the
feat/tool-hooks
branch
from
September 22, 2026 10:45
184c29d to
37d0100
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What (description of the change)
Adds opt-in process hooks at the tool boundary (pattern reference: ZCode's hook surface, Apache-2.0 — pattern only, simplified to a deny-only v0 contract):
--on-pretool <cmd>/--on-posttool <cmd>(global, repeatable, default OFF — no flags = zero behavioral or performance change).{"event":"pretool"|"posttool","tool":...,"input":...,"ok":...}); exit code 2 = DENY (pre-hooks only: the call settles as a durablepre-hook denialerror and the loop replans — same replan shape as an approval denial); any other non-zero exit / timeout / spawn failure is a logged NON-BLOCKING hook failure. argv execution only, 5s default timeout, 32 KiB stdout cap — built on the existingrun_with_timeout_stdindiscipline.ToolRegistry(shell-tools-gated moduletole_core::hooks); the turn loop consults them after the approval gate (pre) and around execute (post, observe-only). The resume/replay path keeps its approval-freshness semantics unchanged.Deferred on purpose: Stop-hook
continue:true(extra model steps), workspace hook trust/manifest digests, hook output → model context injection.Why (the problem you're solving)
Closes #110. Tole's approval policy is compile-time: anything an owner wants gated beyond the built-in risk tiers (org rules, SIEM logging, project-specific prohibitions) required a code change. A tiny process-hook surface buys policy injection at the same trust boundary as the existing Approver trait — default OFF, deny-only, auditable through the durable log.
Testing (how you verified this works)
event/tool/input/okreach the hook). Script-file hooks per the documented v0 contract.--no-default-features(mobile) profile builds and tests green (hooks module is shell-tools-gated like the subprocess helper it uses); clippy clean.--on-pretool guard.sh(exit 2) +--allow run_command, an echo mission settles with a durable{"error":"pre-hook denial","detail":"run_command: denied by pretool hook: echo-command-forbidden-by-guard"}and the command never executes; the identical control run without hooks completes (CHAIN-OK).