Hook 参考doc/{zh,en}/design/plugins/hooks.md

Hook:协议、顺序与合并

状态:2026-11-16。已实现:第 1–7 节的全部内容(pkg/plugin/hooks.go、hookpoints.go、rewrite.go;internal/bundle/hooks.go、hookroles.go、hookpoints.go、shared.go;internal/host/engine/hookpoint.go、hooks.go

状态:2026-11-16。已实现:第 1–7 节的全部内容(pkg/plugin/hooks.go、hookpoints.go、rewrite.go;internal/bundle/hooks.go、hookroles.go、hookpoints.go、shared.go;internal/host/engine/hookpoint.go、hooks.go、guards.go、rewrite.go、steps.go、observe.go;internal/host/observed;测试 TestHooksMergeAndAsk、TestHooksRunAtOnceAndDedup、TestContextAndStopEvents、TestReviewAndPreCompact、TestFailureAndObserveHooks、TestP2Hooks、TestRewriteFromUpdatedInput、TestHookEventNeedsItsRole、TestHookBudget、TestOperatorLayerGatesFirst、TestGatesRunInParallel、TestHookPluginsRunInUsesOrder、TestRewriteChain、TestRewriteVoidsAnEarlierApproval、TestToolNarrowingAndModelGuards、TestObserverReceivesCommittedFacts、TestStepCheck、TestCommandHooks)。第 8 节对比其他 Agent;第 9 节列出不支持的内容;第 10 节映射 DSH 插件。插件作者通过本文了解 hook 收到什么、可以回答什么、以什么顺序运行。更完整的扩展面见扩展点;插件形态见插件设计。顺序、层级和较新 hook 点的设计见 Hook 模型。

1. 两类 Hook 点

类型声明位置实现方式契约
代码角色plugin.yaml 中的 roles:Go 接口(builtin 插件)或 JSON-RPC 方法(process 插件,任意语言)pkg/plugin/roles.go、pkg/plugin/extensions.go、pkg/plugin/rpc/methods.go
命令 hookmanifest 插件 plugin.yaml 中的 hooks:一个从 stdin 读取 JSON、在 stdout 回答的命令,使用 Claude Code 的协议pkg/plugin/hooks.go;由 internal/bundle/hooks.go 运行,由 internal/bundle/hookroles.go 映射到角色

充当 hook 的代码角色:

角色方法(JSON-RPC)时机能力
guardguard/check每次工具调用前拒绝,或要求人工审批
guardguard/check_inputRuntime 看到输入之前拒绝本次 run
guardguard/check_result每个工具结果之后扣留结果或附加注释
guardguard/check_completion最终回答时(Agent 或子 Agent),包括在续写上限处被截断或被供应商过滤器停止的回答(2026-12-05):这两种回答可被扣下,不能退回继续工作要求继续工作
guard(可选接口 Rewriter)guard/rewrite每次工具调用的 gate 阶段之前替换参数(需要 grants: [rewrite],ADR 0005)或拒绝调用
guard(可选接口 ToolNarrower)guard/filter_toolsrun 列出其工具时从 run 中移除工具(绝不增加)
guard(可选接口 ModelGuard)guard/before_model、guard/after_model每次模型调用前后拒绝调用;改写其消息或回复文本(需要 rewrite 授权)
guard(可选接口 StepGuard)guard/check_step一批工具调用结算之后、下一次模型调用之前;Runtime 通过 host/check_step 询问添加上下文,或停止 run
contextcontext/getrun 开始时一次添加参考条目
reviewerreviewer/review需要审批的调用,且有 grants: [review]批准、拒绝或升级给人
observerobserver/observe、observer/before_compact某个事实提交之后(第 7 节);会话压缩之前只读;列出总结必须保留的事实
compactorcompactor/compact会话压缩时写出总结
context_processorprocessor/process组装历史时返回类型化编辑

命令 hook 是不写代码的代码角色:每个事件恰好填充一个角色,bundle 适配器通过运行命令实现该角色的方法。

2. 事件及其填充的角色

事件线上名称(hook_event_name)角色运行时机匹配对象
pre_toolPreToolUseguard每次工具调用前,在 Agent 自身规则之后工具名
post_toolPostToolUseguard每个工具结果之后、模型看到之前工具名
user_inputUserPromptSubmitguardRuntime 看到输入之前—
stopStopguardAgent 给出最终回答时—
subagent_stopSubagentStopguard被委派的子 Agent 给出最终回答时—
session_startSessionStartcontext会话第一次 run 开始时—
pre_compactPreCompactobserver会话压缩之前(自动或 /compact)—
permission_requestPermissionRequestreviewer调用需要审批时,在询问人之前工具名
post_tool_failurePostToolUseFailureguard工具调用失败之后,代替 post_tool工具名
session_endSessionEndobserver会话关闭之后(事实 session.closed)—
post_compactPostCompactobserver会话压缩之后(事实 compaction.done)—
notificationNotificationobserver向人展示问题时(事实 question.asked)—
tool_selectionBeforeToolSelectionguardrun 列出其工具时—
before_modelBeforeModelguardrun 的每次模型调用之前,包括生成总结的调用—
after_modelAfterModelguard每个模型回复完成之后—
after_tool_batchPostToolBatchguard一批工具调用结算之后、下一次模型调用之前—

线上名称沿用 Claude Code,BeforeToolSelection、BeforeModel 和 AfterModel 除外,它们沿用 Gemini CLI。导入器会转换 Claude Code 的 PreToolUse、PostToolUse、PostToolUseFailure、UserPromptSubmit、Stop、SubagentStop、SessionStart、SessionEnd、PreCompact、PostCompact、Notification 和 PermissionRequest。

校验。 manifest 必须声明其每个 hook 事件所填充的角色,否则加载失败,报错 manifest <name>: <event> hooks need the <role> role。每个 hook 需要已知事件和命令,match 必须能编译,on_error 只能是 deny 或 ignore。导入器会为其转换的事件补上对应角色。

3. 声明

yaml
1name: release-policy
2execution: manifest
3roles: [guard, context, reviewer]
4hooks:
5  - {event: pre_tool, match: "bash|write", command: [python3, "${PLUGIN_ROOT}/pre.py"], timeout: 30s}
6  - {event: session_start, command: [python3, "${PLUGIN_ROOT}/brief.py"]}
7  - {event: permission_request, match: deploy, command: [python3, "${PLUGIN_ROOT}/approve.py"], on_error: ignore}
字段含义
event第 2 节中的一个事件
match用于 pre_tool、post_tool、post_tool_failure、permission_request。为空或 * 匹配所有工具;其他值是对完整工具名的正则表达式,不区分大小写(bash|write)。其他事件忽略此字段
command参数列表,不经 shell 运行;展开 ${PLUGIN_ROOT}、${PLUGIN_DATA} 和 ${option.KEY}
timeoutGo 时长;默认 10s
on_errordeny(默认)或 ignore,见第 6 节

工具名是模型看到的名字:内置工具用其名字(bash、read),MCP 工具为 <instance>__<tool>。Claude Code 的匹配写法如 mcp__memory__.* 不会匹配它们,需要按实例 id 改写。

环境。 工作目录是实例的数据目录(PLUGIN_DATA),因此命令在其运行处写下的内容(日志、规则文件)不会改动已审批的插件文件(飞书 #243);命令开头的 ./ 指插件自己的文件。命令收到 PLUGIN_ROOT、PLUGIN_DATA、CLAUDE_PLUGIN_ROOT、CLAUDE_PLUGIN_DATA、CLAUDE_PROJECT_DIR(插件目录)、每个选项的 CLAUDE_PLUGIN_OPTION_<KEY>,以及 MCP server 同样获得的少量白名单环境变量。policy.mcp_commands 限制可运行的可执行文件。

4. 载荷与回答

每个载荷都包含:

字段值
hook_event_name线上名称
session_idrun 所属会话(ss_…);run 没有会话时为 run id
run_id本次 run
transcript_path总是 "":会话日志不是脚本可读的文件
cwd工作目录,即实例的数据目录
permission_mode总是 "default"

hook 有以下几种回答方式:

回答含义
退出码 0,stdout 为空或不是 JSON无意见
退出码 0,stdout 为 JSON按下文解读
退出码 2阻止;stderr 是原因(为空时为 blocked by a <event> hook)
其他退出码、超时,或 stdout 以 { 开头但不是合法 JSON失败(第 6 节)

读取的 JSON 字段:decision: "block" 与 reason;hookSpecificOutput.permissionDecision 取 deny / ask / allow,以及 permissionDecisionReason;hookSpecificOutput.additionalContext;对于 permission_request,hookSpecificOutput.decision.behavior 取 allow / deny,以及 message;hookSpecificOutput.updatedInput(pre_tool)、allowedTools(tool_selection)、updatedMessages(before_model)和 updatedResponse(after_model)。同一插件内按 manifest 顺序最后一个改写生效。其他字段被忽略。

4.1 各事件

事件自有载荷字段阻止 / 拒绝要求审批允许additionalContext
pre_tooltool_name、tool_input、tool_use_id调用被拒绝;原因发给模型调用需要人工审批;原因发给审批人无意见(不能放宽其他决定);有 rewrite 授权时,updatedInput 替换参数作为该调用结果的注释
post_tool同 pre_tool,另加 tool_response: {content, is_error}原因作为注释附加(结果不被扣留)——作为结果的注释
user_inputpromptrun 被拒绝(input.denied)同样拒绝:没有可审批的调用—本次 run 的上下文条目(需要 context 角色):参考材料,来自运维层时为指令
stopprompt、last_assistant_message、stop_hook_active(第 2 轮起为 true)原因被反馈,Agent 继续工作按阻止处理——
subagent_stop同 stop,另加 agent_type(子 Agent 名称)同 stop,作用于子 Agent按阻止处理——
session_startsource:startup(首个会话或停顿之后)或 clear(/new 之后)———本次 run 的上下文条目:参考材料,来自运维层时为指令
pre_compacttrigger:auto 或 manual;custom_instructions: ""不可能:压缩总会进行——每一行是总结必须保留的事实
permission_requesttool_name、tool_input、tool_use_id拒绝,如同 reviewer—批准,如同 reviewer—
post_tool_failuretool_name、tool_input、tool_use_id、error(失败结果的文本)原因作为注释附加——作为结果的注释
session_endreason:idle、reset 或其他关闭原因回答被忽略——被忽略
post_compacttrigger:auto回答被忽略——被忽略
notificationmessage(问题的提示语;实例没有 grants: [conversation] 时为空,P11)、notification_type:permission_prompt(审批)或 elicitation_dialog回答被忽略——被忽略
tool_selectiontools:run 将看到的工具名——allowedTools 列出本插件允许的工具;不在所有列表中的工具被移除—
before_modelpurpose、messages(请求)模型调用被拒绝(model.denied_by_policy)按阻止处理有 rewrite 授权时,updatedMessages 替换消息—
after_modelpurpose、response: {content, tool_calls, stop_reason}(tool_calls 为名称)回复被拒绝(model.denied_by_policy)按阻止处理有 rewrite 授权时,updatedResponse 替换文本—
after_tool_batchtool_calls: [{tool_name, tool_use_id, is_error}],子 Agent 时另加 agent_typerun 以该原因停止按阻止处理—在模型下一次调用前展示给它

stop 与 subagent_stop 的反馈每个回答最多两轮(MaxChecks,plugins/agent/loop.go)。当 pre_tool hook 改写了参数时,同样的 hook 会在 gate 阶段基于最终参数再运行一次;没有改变时,gate 复用第一次的运行结果。

4.2 示例

json
1// pre_tool,stdin
2{"hook_event_name":"PreToolUse","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","tool_name":"bash","tool_input":{"command":"kubectl apply -f prod.yaml"},"tool_use_id":"tc_3b8e01d2aa"}
3// stdout:要求人工审批
4{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"ask","permissionDecisionReason":"applies to production","additionalContext":"prod changes need a ticket id"}}
json
1// post_tool,stdin
2{"hook_event_name":"PostToolUse","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","tool_name":"read","tool_input":{"path":"go.mod"},"tool_use_id":"tc_51aa0c9e12","tool_response":{"content":"module example.com/app","is_error":false}}
3// stdout
4{"hookSpecificOutput":{"hookEventName":"PostToolUse","additionalContext":"go.mod is generated; edit tools.go instead"}}
json
1// user_input,stdin
2{"hook_event_name":"UserPromptSubmit","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","prompt":"deploy v2.3 to prod"}
3// stdout:拒绝
4{"decision":"block","reason":"deploys are frozen until Monday"}
json
1// stop,stdin
2{"hook_event_name":"Stop","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","prompt":"summarize the incident","last_assistant_message":"The outage was caused by…","stop_hook_active":false}
3// stdout:要求继续工作
4{"decision":"block","reason":"add a line with the incident ticket"}
json
1// subagent_stop,stdin
2{"hook_event_name":"SubagentStop","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","prompt":"find the failing test","last_assistant_message":"TestLogin fails","stop_hook_active":false,"agent_type":"explorer"}
3// stdout:接受
4{}
json
1// session_start,stdin
2{"hook_event_name":"SessionStart","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","source":"startup"}
3// stdout
4{"hookSpecificOutput":{"hookEventName":"SessionStart","additionalContext":"On-call this week: Li Wei"}}
json
1// pre_compact,stdin
2{"hook_event_name":"PreCompact","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","trigger":"manual","custom_instructions":""}
3// stdout:两条需要保留的事实
4{"hookSpecificOutput":{"hookEventName":"PreCompact","additionalContext":"Release branch is release/2.3\nTicket OPS-4411 is open"}}
json
1// permission_request,stdin
2{"hook_event_name":"PermissionRequest","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","tool_name":"deploy","tool_input":{"env":"staging"},"tool_use_id":"tc_9d02e7b4c1"}
3// stdout:批准
4{"hookSpecificOutput":{"hookEventName":"PermissionRequest","decision":{"behavior":"allow"}}}
json
1// pre_tool,stdin(改写)
2{"hook_event_name":"PreToolUse","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","tool_name":"write","tool_input":{"path":"/etc/hosts","content":"x"},"tool_use_id":"tc_77e0a1c2b9"}
3// stdout:改写(需要 grants: [rewrite])
4{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow","updatedInput":{"path":"workspace/hosts","content":"x"}}}
json
1// post_tool_failure,stdin
2{"hook_event_name":"PostToolUseFailure","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","tool_name":"bash","tool_input":{"command":"go test ./..."},"tool_use_id":"tc_2c90d1e4f0","error":"exit status 1"}
3// stdout
4{"hookSpecificOutput":{"hookEventName":"PostToolUseFailure","additionalContext":"run make generate before the tests"}}
json
1// session_end,stdin
2{"hook_event_name":"SessionEnd","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","reason":"idle"}
3// stdout:被忽略
4{}
json
1// post_compact,stdin
2{"hook_event_name":"PostCompact","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","trigger":"auto"}
3// stdout:被忽略
4{}
json
1// notification,stdin
2{"hook_event_name":"Notification","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","message":"Allow deploy with {\"env\":\"prod\"}?","notification_type":"permission_prompt"}
3// stdout:被忽略
4{}
json
1// tool_selection,stdin
2{"hook_event_name":"BeforeToolSelection","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","tools":["read","grep","bash","write"]}
3// stdout:此处不允许 shell 和写入
4{"hookSpecificOutput":{"hookEventName":"BeforeToolSelection","allowedTools":["read","grep"]}}
json
1// before_model,stdin
2{"hook_event_name":"BeforeModel","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","purpose":"","messages":[{"role":"user","content":"my token is sk-123"}]}
3// stdout:脱敏(需要 grants: [rewrite])
4{"hookSpecificOutput":{"hookEventName":"BeforeModel","updatedMessages":[{"role":"user","content":"my token is [redacted]"}]}}
json
1// after_model,stdin
2{"hook_event_name":"AfterModel","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","purpose":"","response":{"content":"Done.","tool_calls":null,"stop_reason":"end_turn"}}
3// stdout:改写文本(需要 grants: [rewrite])
4{"hookSpecificOutput":{"hookEventName":"AfterModel","updatedResponse":"Done. (reviewed)"}}
json
1// after_tool_batch,stdin
2{"hook_event_name":"PostToolBatch","session_id":"ss_7f2a","run_id":"rn_91c4","transcript_path":"","cwd":"/plugins/release-policy","permission_mode":"default","tool_calls":[{"tool_name":"write","tool_use_id":"tc_5a1f9e0b37","is_error":false}]}
3// stdout:给下一次模型调用的上下文;{"decision":"block","reason":"…"} 会停止 run
4{"hookSpecificOutput":{"hookEventName":"PostToolBatch","additionalContext":"run the tests before the next edit"}}

5. 顺序与合并(规范)

同一实例内。 该事件中匹配的所有 hook 同时运行,输入相同;不会因为另一个阻止而跳过。相同的 hook(事件、匹配器、展开后的命令和选项都相同)只运行一次,对同一输入询问的多个实例之间也是如此(internal/bundle/shared.go)。它们的回答按 manifest 顺序合并:

  • ◆裁决:deny(阻止)> ask > allow > 无意见。最严格的胜出。
  • ◆原因:保留最严格裁决的原因,按顺序以 "; " 连接。
  • ◆additionalContext:每个 hook 的都保留,按 hook 顺序以换行连接。

跨实例:两层(Hook 模型第 3 节)。先是运维层,即 Host 配置中 policy.hooks 列出的实例,每个 Runtime 无论是否使用它们都会询问;然后是 Runtime 层,即 Runtime 的 uses 中的实例(工具调用时为调用链中每个实例的 uses),各询问一次。policy.hooks_only: true 只询问运维层。同一层内的实例同时被询问;回答按声明顺序合并(先 policy.hooks 顺序,再 uses 顺序)。对于 gate(guard、输入 guard、reviewer),一层拒绝即结束该点位,不再询问下一层。运维层提供的上下文作为指令到达模型(<orq:operator>);Runtime 层的上下文仍是参考材料(<orq:reference>)。

点位合并
Guard(check)任一拒绝即拒绝;收集所有 ask,调用需要最严格审批人的审批;没有任何东西能放宽拒绝
结果 guard任一扣留即扣留;注释按顺序追加
输入 guard任一拒绝或 ask 都拒绝本次 run
完成 guard收集全部反馈
Reviewer(仅限已授权)任一拒绝即拒绝;批准需要所有 reviewer 都批准;其他情况交给人
Context provider条目按 uses 顺序
Compactor按配置顺序尝试;第一个成功者胜出
Context processor按 uses 顺序应用
Observer、before_compact相互独立;收集需要保留的事实
改写者(guard/rewrite)链式而非并行:先 Runtime 层,按 uses 顺序(调用链中每个实例),最后是运维层,每个都基于上一个的参数;只有拥有 grants: [rewrite] 的实例能改变参数;之后对最终参数做 schema 检查、gate 和审批(ADR 0005)
工具过滤器(guard/filter_tools)run 保留所有过滤器都允许的工具(交集);过滤器不能增加工具
模型 guard(guard/before_model、after_model)与改写者相同的链式顺序;任一拒绝即拒绝调用;改写需要授权
步骤 guard(guard/check_step)上下文按声明顺序收集;任一停止即停止 run

没有优先级字段。 由于每种合并都是最严格者胜出或全部收集,顺序永远不会改变裁决,只决定注释和上下文的先后,权限来自层。Claude Code、Codex、Kimi 和 Crush 同样并行运行匹配的 hook;审查的十个 Agent 中有九个没有优先级字段(审查)。

6. 超时与失败

超时。 每个 hook 有自己的 timeout(默认 10 s)。Host 对每个实例的角色调用设置的上限,取 Host 自身默认值与该实例此事件中最长 hook 超时加一秒两者中的较大者(hookBudget,internal/host/engine/guards.go),因此声明的超时总能生效;hook 同时运行,所以以最长的为准。policy.hook_budget(默认 60 s)限制整个 hook 点位。

角色调用Host 默认值
context/get(session_start)5 s
guard/check(pre_tool)5 s
guard/check_input、check_result、check_completion10 s
reviewer/review(permission_request)30 s
observer/before_compact(pre_compact)30 s
guard/rewrite(pre_tool 改写)5 s
guard/filter_tools、before_model、after_model、check_step10 s
observer/observe(session_end、post_compact、notification)2 min

失败。 无法启动、以 0 或 2 以外的退出码退出、超时,或输出非法 JSON 的 hook 即为失败:

  • ◆on_error: deny(默认):视为阻止,原因指明该 hook(the pre_tool hook 2 of release-policy could not run)。原生 hook 失败即关闭。
  • ◆on_error: ignore:视为无意见;失败会记录日志(hook.failed)。

从 Claude Code 或 Codex 包导入的 hook 使用 ignore,与这些工具中失败的 hook 不阻止的行为一致。

角色调用整体失败时遵循该角色的规则:guard 拒绝,输入 guard 拒绝 run,结果 guard 扣留,完成检查被跳过,reviewer 升级,context 被省略,observer 重试;改写者和模型 guard 拒绝调用(失败即关闭);工具过滤器和步骤 guard 被跳过并记录日志。在插件内部,on_error: deny 的 after_tool_batch hook 失败时视为阻止,因此会停止 run。

7. Hook 输出去向

输出到达暂存位置
pre_tool 阻止模型,作为被拒绝调用的结果—
pre_tool 上下文(未阻止)该调用结果的注释bundle 内存,以 run 与调用为键,直到结果出现;最多暂存 256 条
post_tool 上下文与阻止原因结果的注释—
user_input 上下文本次 run 的上下文条目:<orq:reference>,来自运维层时为 <orq:operator>bundle 内存,以 run 为键,由 context/get 读取;插件没有 context 角色时永远不会被读取
session_start 上下文会话首次 run 的上下文条目,与 user_input 相同—
stop / subagent_stop 阻止要求继续工作的反馈—
pre_compact 上下文各行总结必须保留的事实—
permission_request 裁决审批—
pre_tool 的 updatedInput(rewrite 授权)调用实际使用的参数;模型看到的结果末尾附注释,指明谁改了参数账本保留模型给出的参数;最终参数写入日志(tool.rewritten)
post_tool_failure 上下文与阻止原因失败结果的注释—
session_end、post_compact、notification 的回答不去任何地方:这些 hook 只观察—
tool_selection 的 allowedToolsrun 的工具列表;调用被移除的工具会被拒绝(Tool … is not available in this task.)Host 中该 run 的内存
before_model / after_model 阻止模型调用以 model.denied_by_policy 失败,run 随之失败—
before_model 的 updatedMessages、after_model 的 updatedResponse发出的请求,或 Runtime 得到的回复—
after_tool_batch 上下文下一次模型调用之前:<orq:reminder kind="step">,来自运维层时为 <orq:operator>run 的 checkpoint
after_tool_batch 阻止run 结束,显示 已按运维策略停止:<原因>(英文为 Stopped by the operator's policy: <reason>)—

已观察事实。 session_end、post_compact 和 notification 由 observer 管道运行。Host 在提交某个事实的同一事务中把它追加到 observed_events 日志(internal/host/observed):run.finished、session.opened、session.closed、tool.finished、question.asked、question.settled、compaction.done、delivery.sent、delivery.failed(pkg/plugin/decisions.go)。每个 observer 从自己的持久游标(observer_cursors.seq)读取日志,因此每个事实至少收到一次,且按顺序;新的 observer 从日志末尾开始。observer 看到使用它的 Runtime 的事实;policy.hooks 中的 observer 看到所有 Runtime 的事实。两种情况下都只看到其 scope(以及 works_with、所有者)覆盖的 run 的事实,与它的其他调用一致;不属于任何 run 的 user.forgotten 不受此限(飞书 #383)。session.closed 事实与其 session.opened 指向同一个人,因此覆盖其一的 scope 也覆盖另一个(飞书 #400)。observer 忽略它不使用的类型。

8. 与其他 Agent 对比

Claude CodeCodexDSH(hooks-claude-code 基于 hook-protocol)Orquelo
事件30 个PreToolUse、PostToolUse、UserPromptSubmit、Stop、PermissionRequest 等(见 Codex 源码评审)7 个:SessionStart、UserPromptSubmit、PreToolUse、PostToolUse、Stop、SubagentStart、SubagentStop16 个(第 2 节)
Handler 类型command、http、prompt、agent、mcp_toolcommand;executor hook 调用 MCP 工具仅 command仅 command
顺序并行,相同 handler 去重未评审串行,配置顺序插件内和层内并行;先运维层,再 Runtime 层;相同 hook 只运行一次;改写按链式顺序
合并deny 胜出未评审deny > ask > allow;上下文按顺序;第一个 continue:false 生效deny > ask > allow;上下文按顺序
失败不阻止(退出码 ≠ 2)未评审不阻止按 hook:deny(默认)或 ignore;导入的 hook 为 ignore
默认超时600 s未评审600 s10 s,Host 上限随之增长
改写参数updatedInputPreToolUse 可修改参数解析但不生效pre_tool 的 updatedInput,仅限拥有 grants: [rewrite] 的实例;确定的链式顺序,之后对最终参数做 schema 检查、gate 和审批(ADR 0005)
Shell是是通过其 shell 执行器否;导入时拒绝需要 shell 的命令

来源:兼容性与 Codex 评审;2026-11-16 从 deepseek-ai/deepseek-harness master 读取的 DSH hook-protocol 与 hooks-claude-code README。

9. 不支持的内容

项目原因
updatedMCPToolOutput不读取。updatedToolOutput 已实现:拥有 grants: [rewrite] 的实例的 post_tool 或 post_tool_failure hook 替换结果文本(字符串,或带 content 的对象);改写按链式进行,先 Runtime 层后运维层,在结果 guard 之前;改写者失败则扣留结果;模型会被告知谁改了结果(guard/rewrite_result,ADR 0005)
http、prompt、agent、mcp_tool 类型的 hookHTTP 或模型驱动的检查应是具有 guard 或 reviewer 角色的 process 插件;导入器会略去它们并给出说明
continue: false、stopReason、systemMessage、suppressOutputhook 不能在 run 层面停止;取消 run 是人或操作员的动作
PreCompact 否决否决压缩会导致上下文溢出;hook 只能列出需要保留的事实
从 session_end、post_compact 或 notification 阻止它们在事实提交之后由 observer 管道运行;其回答被忽略
其他 Claude Code 事件(Setup、InstructionsLoaded、UserPromptExpansion、MessageDisplay、PostToolBatch、PermissionDenied、TaskCreated、TaskCompleted、StopFailure、TeammateIdle、ConfigChange、CwdChanged、FileChanged、WorktreeCreate、WorktreeRemove、Elicitation、ElicitationResult、SubagentStart)导入器略去并给出说明(after_tool_batch 只能原生声明:其线上名称与 PostToolBatch 相同,但导入器不映射它)。已提交的事实通过已观察事实(第 7 节)到达 observer 插件
可读的对话记录transcript_path 为空;需要历史的 hook 应是调用 host/session_entries 的 process 插件

10. DSH 插件到 v2 的映射

DSH 插件作用v2 路径状态
hooks-claude-code、hooks-codex、hook-protocol运行现有 hooks.json 命令 hook导入该包(orquelo plugin install);hook 成为 manifest 插件的命令 hook已实现
mcp-client、mcp-manager连接并管理 MCP servermanifest 插件的 mcp_servers;orquelo plugins -c 显示每个 server 的状态已实现
mcp-resourcesMCP resourcesresources 与 prompts部分实现(B8;internal/bundle/resources.go、prompts.go)
skill、skill-filesystem、skill-office来自目录的技能;办公文档技能manifest 插件的 skills:(Agent Skills 布局);办公技能作为技能安装,其工具来自 localenv 或工具插件已实现(技能);不提供办公工具
guard/repeat-tool-reminder重复工具调用提醒Agent 内的循环防护(plugins/agent/loopguard)已实现
guard/timeout-policy按工具的时间限制实例的 call_timeout;Host 的 run 超时已实现
browser-use-*通过 MCP 或原生驱动控制浏览器经由 shell 驱动 agent-browser CLI 及其自带指南;由 agent-browser 插件声明(P87 S6)。@playwright/mcp 之类的 MCP server 也可作为 manifest 插件运行;单个 run 独占浏览器为 B17已实现;独占未实现
computer-use-*、cua-*桌面控制声明 platforms: [darwin] 的工具插件未实现
subagent、tool-subagent-oar委派给子 Agentdelegate 工具与 Agent 配置中的 subagents(P8)已实现(配置定义);插件提供的 Agent 未实现(B13)
plugin-market-bundle从插件索引安装orquelo plugin install,来源可为内置清单(catalog)中的名称、本地目录、git+URL#commit 或带 sha256 的 https 归档已实现;无索引或市场
web-fetch-http、tool-web受限的 HTTP 抓取工具webfetch builtin 插件(主机白名单、具名连接)已实现
session-persistence-jsonl会话日志存储Host 的会话存储(P49);不是插件角色已实现(在 Host 中)
todo、plan、goal任务列表与计划Agent 的内置 todo 工具todo 已实现;plan 与 goal 未实现
schedule、jobs、workflow定时 run、后台作业、工作流带 Pending 轮询的长工具;localenv 中的后台 shell 作业;调度器或工作流应是 trigger 或 runtime 插件作业已实现;调度与工作流未实现