An oh-my-pi extension that demonstrates tool_call blocking. It intercepts bash tool calls and returns { block: true, reason: "..." } when the command contains rm -rf / with normal whitespace, preventing the tool from executing.
What it demonstrates
pi.on("tool_call", ...)— pre-execution interceptionreturn { block: true, reason: "..." }— blocking contract- Regex guard on bash input (
/\brm\s+-rf\s+\//)
Install
cp -r . ~/.omp/agent/extensions/safety-hook
Restart omp. The hook is active for all sessions.
Or load once:
omp --extension ./safety-hook
How it works
flowchart TD %% Nodes Start([LLM calls bash tool]) --> RunHandlers[tool_call handlers run] RunHandlers --> Decision{command matches<br><code>/\brm\s+-rf\s+\//</code> ?} Decision -- yes --> Blocked[Block execution] Decision -- no --> Allowed[Execution continues normally] Blocked --> EndBlock([Return: <code>{ block: true, reason: '...' }</code> to LLM]) Allowed --> Execute[Tool executes] --> EndNormal([Success]) %% Styling style Decision fill:#f9f,stroke:#333,stroke-width:2px style Blocked fill:#ffcccb,stroke:#f00,stroke-width:2px style Allowed fill:#e1f5fe,stroke:#03a9f4,stroke-width:2px style Start fill:#e8f5e9,stroke:#4caf50,stroke-width:2px style EndBlock fill:#ffebee,stroke:#c62828,stroke-width:2px style EndNormal fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px
The reason text is what the LLM receives as the tool error, so it can understand why the call was rejected and try a different approach.