Repository navigation
Closed
Description
What (description of the change)
Add opt-in process hooks at the tool-call boundary (pattern reference: ZCode hooks/, Apache-2.0 — pattern only): owners can inject policy/observability without recompiling tole.
- v0 scope:
PreToolUseandPostToolUsefor Write-risk tools only (ReadOnly tools stay zero-overhead; Destructive keeps its interactive-only rule). CLI flags, repeatable:--on-pretool <command>/--on-posttool <command>; default OFF (no flags = byte-identical behavior). - Contract (mirrors the ZCode wire, simplified): the hook process receives ONE JSON object on stdin (
{"event":"pretool"|"posttool","tool":...,"input":...,"ok":...}), may print ONE JSON object to stdout; exit code 2 = deny (PreToolUse only → the call is settled as a durable denial, same shape as an approval denial); stdout that is non-JSON or a non-zero exit ≠ 2 is recorded as a hook FAILURE and does not block the call. argv execution only (no shell string), 5s timeout, 32 KiB output cap — reusesubprocess.rsdiscipline (run_with_timeout_stdin). - Turn-loop placement: approval gate → pre-hook (may deny) → execute → post-hook (observe). Denials land as durable error entries; hook invocations are visible in the session log (auditable).
- Deferred on purpose: Stop-hook
continue:true(extra model steps — loop-risk, needs its own budget design), workspace-level hook trust/manifest digests, hook output→model context injection.
Why (the problem you're solving)
Tole's approval policy is compile-time: anything an owner wants gated beyond the risk tiers (org-specific rules, logging to a SIEM, project-specific prohibitions) requires a code change. A tiny process-hook surface — default OFF, deny-only v0 — buys policy injection at the same trust boundary as the existing Approver trait without recompiles, and matches the fleet's existing gateway-hook experience.
Testing (how you verified this works)
- Unit: exit-2 pre-hook blocks execution AND the tool's
executeis never called (capture provider/tool witness); non-JSON stdout + non-2 non-zero exit recorded as failure without blocking; timeout path; ReadOnly tools never invoke hooks. - Live E2E: a deny-script for
run_command echo(exit 2) → tole mission settles with a durable denial and the command never runs; control run without flags unchanged. - Tier-1 green both feature profiles (hooks module is host-side, no new deps —
serde_json+ existing subprocess helper only).
Metadata
Metadata
Assignees
Labels
No labels
Activity
fix(turn): post-hooks fire for Write/Destructive only (#110)
fix(turn): post-hooks fire for Write/Destructive only (#110) (#113)
feat(harness): turn-end stop hooks (--on-turnend) — deterministic gat…
feat(sandbox): sandbox the on_turnend stop gates and fold in the #845 …
fix(sandbox): a stop gate that times out inside the sandbox is a deny…