Files
docker-agent/examples/tool_hook_phases.yaml
David Gageot a5dc872361 docs(hooks): update schema, docs and examples for hook phases
Update agent-schema.json with new hook fields (strict_output, guard
phase). Revise hooks documentation with phase ordering, compatibility
notes (no-op scripts must exit 0, on_error:block rejected on
non-blocking events, customized built-ins are distinct from automatic
defaults). Add tool_hook_phases.yaml example demonstrating the full
phase pipeline.
2026-09-09 15:23:39 +02:00

61 lines
2.4 KiB
YAML

# Requires python3 for the command hooks. Try with --yolo: the guard still runs.
agents:
root:
model: openai/gpt-5-mini
description: Separate input normalization, mandatory checks, and approval assistance
instruction: Help with shell commands. Respect tool policy rejections.
toolsets:
- type: shell
hooks:
tool_input_transform:
- matcher: shell
hooks:
- name: normalize whitespace
type: command
strict_output: true
on_error: block
command: |
python3 -c '
import json, sys
payload = json.load(sys.stdin)
command = payload["tool_input"].get("cmd", "")
print(json.dumps({"hook_specific_output": {
"updated_input": {"cmd": command.strip()}
}}))
'
tool_guard:
- matcher: shell
hooks:
- name: require confirmation for project commands
type: command
strict_output: true
timeout: 5
command: |
python3 -c '
import json, sys
payload = json.load(sys.stdin)
command = payload["tool_input"].get("cmd", "")
# Exact matches, not a shell-prefix allowlist.
decision = "allow" if command in ("pwd", "git status") else "ask"
print(json.dumps({"hook_specific_output": {
"permission_decision": decision,
"permission_decision_reason": "Review commands beyond the read-only allowlist",
"metadata": {"policy": "project command review"}
}}))
'
# This judge only runs when the guard falls through and safety mode asks.
# A guard's "ask" skips it; an "allow" here cannot undo a guard denial.
pre_tool_use:
- matcher: shell
hooks:
- name: approval assistant
type: model
model: openai/gpt-4o-mini
timeout: 15
schema: pre_tool_use_decision
prompt: |
Decide allow, ask, or deny for this tool call.
Allow only clearly read-only operations; ask when uncertain.
Tool: {{ .ToolName }}
Arguments: {{ .ToolInput | toJSON }}