SuperAPIAI Directory

pi-steering-hooks

github.com · AI agents

pi-steering-hooks is a deterministic tool-call guardrail designed for the pi agent. By intercepting calls before tool execution, it enforces rules via hooks rather than relying on prompts. It has zero token cost and is 100% reliable, can block operations such as bash, write, and edit that violate rules, and provides a structured escape mechanism and override annotations for legitimate scenarios. The tool also includes file-writing guardrails that guide the agent to use write/edit tools that show diffs and go through the LSP, rather than invisible bash commands; it supports configuring rules and disabling rules via steering.json, and can set non-overridable rules. It is suitable for development scenarios that require strict constraints on agent behavior.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)

About this tool

pi-steering-hooks is an open-source project that provides deterministic tool-call guardrails for the pi agent. Its core idea is: prompt-based rules (such as "never force push") work most of the time, while steering hooks work every time. Hooks intercept before a tool call is executed, deterministically block violations, and provide an override escape channel when the agent has a legitimate reason. This project is inspired by "Strands Agents: Steering Accuracy Beats Prompts".

Main capabilities

The project's main capabilities include:

  • Evaluate rules on every bash, write, and edit call; if a rule matches, block the call and return the reason to the agent; the agent adjusts its approach after seeing the block message.
  • Override mechanism: when a rule triggers, the agent can try retrying with an override annotation # steering-override: <rule> — <reason> . Overrides are allowed through but are logged to the session for auditing. Rules marked as noOverride: true (such as no-rm-rf-slash) cannot be overridden.
  • File-writing guardrails (new in version 0.3.0): guide the agent to use the write and edit tools (which show diffs and go through the LSP), rather than writing files invisibly via bash commands. File-writing rules have two structural escape channels to avoid blocking legitimate generation pipelines:
    • Script mode: write tools/refactor.py or scripts/gen.sh, then run it. Writes by the child process are not checked.
    • Temporary directory: redirecting to /tmp/、/dev/、dist/、build/、generated/、out/、reports/、coverage/、target/、.cache/ is always allowed.
    • In addition, there is the standard per-command override mechanism (# steering-override: <rule> — <reason>) for one-off situations.

Usage

  • The extension registers a tool_call hook. The hook evaluates whether a rule matches the tool input.
  • Configure rules or disable default rules via steering.json . Configuration file locations are checked in order (first found wins): ./steering.jsonat the project root, then the global ~/.pi/agent/steering.json.
  • If you do not want to use the default rules, you can disable them via steering.json .
  • Rules can use regular expressions (pattern) or a test function (test) form; the two are mutually exclusive. If a rule has both or neither,compileRule throws an error.buildRules throws at the first malformed rule;buildRuleSet skips it and returns { rules, errors }, which is what the extension uses.readConfig returns parse errors instead of logging them. Function-form rules can only be added in code and cannot be added from steering.json Add (because it is JSON).
  • Programmatic API: the package exports its internal components so that other extensions can build on it.

Configuration and fault tolerance

  • A broken configuration never prevents pi from starting. Files that are not valid JSON are skipped, and the next location (or the default rules) is used. Rules with invalid regular expressions, that have neither pattern nor test are skipped;rules or disable not being an array is ignored, so a string form of disable does not disable any rules. All other rules still apply. Each problem is displayed as a notification at session startup. In non-interactive TUI (print, json, and RPC modes), it is also printed to stderr.
  • If a rule throws an exception during evaluation, it is treated as a non-match and reported in the same way, once per rule per session.

heredoc handling

The project specifically points out the importance of heredoc-stripping: a simple if x > 80: scan of a python3 - <<'EOF' ... EOF containing > would incorrectly treat a Python comparison as a shell redirection to a file named 80: . The exported stripHeredocBodies helper function removes the heredoc body before the metacharacter scan (keeping the opening line, which often contains a real shell redirection). The same logic applies to stripQuotedStrings, used to handle grep '>' file -style false positives. This regression case is already covered in index.test.ts to prevent it from happening again.

Applicable scenarios and limitations

This project is suitable for development scenarios where you want to strictly constrain the tool-call behavior of the pi agent, especially when you need to prevent dangerous commands (such as force push, rm -rf /) or guide the way files are written. It achieves deterministic enforcement through hooks, consumes no tokens, and avoids prompt drift. In terms of limitations: rules can only intercept bash, write, and edit calls; function rules are limited to code additions; the configuration file must be in the specified location; and it is not applicable to projects that are not pi agents.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools