Skip to content

feat: opt-in process hooks at the tool boundary (PreToolUse/PostToolUse, default OFF) #110

Closed

Description

@ajianaz

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: PreToolUse and PostToolUse for 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 — reuse subprocess.rs discipline (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 execute is 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions