Feature request: Structured policy API for security hooks (PreToolUse)
Feature request: Structured policy API for security hooks (PreToolUse)
Context
Security hooks (e.g. the local permission hook, Aegis) decide allow/deny by parsing the command string received from the runtime. Documented on 2026-08-29:
| Command | Actual intent | Hook verdict | Failure mode |
|---|---|---|---|
printf '...' >> ~/.bashrc |
legitimate append | blocked ("dangerous pattern") | false positive: judged on shape, not effect |
python3 aegis-mode.py status |
read-only status query | blocked | false positive: the string contains a protected path but never modifies it |
cmd1 && cmd2 chains |
two operations | approved | false negative: chaining decomposes the command out of reach of the analysis |
Net effect: friction on safe commands AND a bypass on compound commands — the worst of both worlds for a security layer.
Problem or Gap
Hooks receive a raw command string. Substring matching cannot distinguish "mentions a protected path" from "writes to a protected path", and it cannot see the individual operations of a &&/||/; chain. Policy decisions therefore produce both false positives and false negatives.
Proposal
- Structured call representation: PreToolUse hooks receive a structured representation of the call instead of a string — the tool invoked, typed arguments, and for shell commands the decomposed operations (each segment of a chain presented as a distinct, individually analyzable operation).
- Structured decision object: the hook returns
{action: allow|deny|ask, reason, scope}instead of an exit code/string —scopeallowing the decision to target a single operation of a chain. - Queryable audit trail: every decision (allow/deny/ask) is logged in a queryable audit trail: timestamp, concerned call, triggering rule, verdict.
Prior art (open source): deepseek-harness monorepo 0.1.2-alpha.1, packages/guard/command-policy/ — a declarative policy engine.
Impact
- Fewer false positives: verdicts on operation semantics instead of substrings.
- No cheap bypass: each chain operation is individually analyzed.
- Auditability: decisions are recorded with their rule and reason, queryable after the fact.
Acceptance criteria
- A PreToolUse hook receives the decomposed operations of a
&&chain (one entry per operation, typed arguments). - The hook decision is consumed by the runtime as a structured object; an
askon a single operation of a chain only gates that operation. - Every decision is queryable in the audit trail (command, rule, verdict, timestamp).
- The two 2026-08-29 false positives (
printf >> ~/.bashrc,python3 aegis-mode.py status) are no longer blocked by substring matching. - Commands that cannot be safely decomposed (complex quoting/substitutions) fall back conservatively to
askon the whole command. - A malformed hook decision falls back to the safe default (
ask) and logs the error. - Hooks for tools without a structured representation receive the current string fallback (no crash).
The false-positive/false-negative table here is exactly the failure mode addressed natively (not via hooks) in #4115: the exec-policy layer evaluates the parsed AST per command segment rather than the command string — cmd1 && cmd2 produces two segments, protected-path writes are matched on argv tokens not substring shape, and unanalyzable segments fail conservative. The .rules format (prefix_rule/network_rule over managed/user/project layers) is effectively a structured policy API for commands. See #4114.