Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ BitFun 不是只在本地运行的桌面应用:工作区、执行这一轮的

### Agent Hooks

- BitFun 实现的是 Codex Hook 契约,因此 <https://learn.chatgpt.com/docs/hooks> 是事件、载荷字段与决策结构的参考来源,不要另起炉灶。[`docs/features/agent-hooks.zh-CN.md`](docs/features/agent-hooks.zh-CN.md)([English](docs/features/agent-hooks.md))只覆盖 BitFun 特有部分 —— 文件位置、`app.hooks` 开关和差异表 —— 新增或消除差异时必须同步更新。
- BitFun 的原生用户 Hooks 实现 Codex Hook 契约,因此 <https://learn.chatgpt.com/docs/hooks> 是其事件、载荷字段与决策结构的参考来源,不要另起炉灶。[`docs/features/agent-hooks.zh-CN.md`](docs/features/agent-hooks.zh-CN.md)([English](docs/features/agent-hooks.md))只覆盖 BitFun 特有部分 —— 文件位置、`app.hooks` 开关和差异表 —— 新增或消除差异时必须同步更新。
- 可移植引擎(配置解析、载荷构造、进程执行、决策合并)位于 `bitfun-agent-runtime::native_hooks`。`bitfun-core::native_hooks` 负责配置发现、开关门控和按事件的分发辅助函数;各分发点调用这些辅助函数,不要就地执行 Hook。
- 有三类不同的东西共用 "hook" 一词:本文所述的原生用户 Hooks、内部编译期 `post_call_hooks`,以及其他 AI 应用的只读外部 Hook 目录(`external_hooks`)。三者必须保持区分
- 可执行 Hooks 可以来自原生用户配置、生态插件或 BitFun 内置实现(包括当前编译期 `post_call_hooks`)。这些来源保持各自的信任、配置、契约和执行策略语义,但可以统一注册到共享的 `HookRegistry`,并由 `AgentHookEngine` 调度。其他 AI 应用的外部 Hook 目录(`external_hooks`)仍只用于只读发现,不得进入可执行 Registry

## 架构

Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ existing installs working without manual repair.

### Agent hooks

- BitFun implements the Codex hook contract, so <https://learn.chatgpt.com/docs/hooks> is the reference for events, payload fields, and the decision schema. Do not fork that contract. [`docs/features/agent-hooks.md`](docs/features/agent-hooks.md) ([中文](docs/features/agent-hooks.zh-CN.md)) covers only the BitFun-specific parts — file locations, the `app.hooks` gates, and the deviations table — and must be updated whenever a deviation is added or closed.
- BitFun native user hooks implement the Codex hook contract, so <https://learn.chatgpt.com/docs/hooks> is the reference for their events, payload fields, and decision schema. Do not fork that contract. [`docs/features/agent-hooks.md`](docs/features/agent-hooks.md) ([中文](docs/features/agent-hooks.zh-CN.md)) covers only the BitFun-specific parts — file locations, the `app.hooks` gates, and the deviations table — and must be updated whenever a deviation is added or closed.
- The portable engine (settings parsing, payload construction, process execution, decision merging) lives in `bitfun-agent-runtime::native_hooks`. `bitfun-core::native_hooks` owns config discovery, gating, and per-event dispatch helpers; dispatch sites call those helpers instead of executing hooks inline.
- Three separate things share the word "hook": these native user hooks, the internal compiled-in `post_call_hooks`, and the read-only external hook catalog of other AI applications (`external_hooks`). Keep them separate.
- Executable hooks may come from native user configuration, ecosystem plugins, or BitFun built-ins (including the current compiled-in `post_call_hooks`). These sources keep distinct trust, configuration, contract, and execution-policy semantics, but may register through the shared `HookRegistry` and be dispatched by `AgentHookEngine`. The external hook catalog of other AI applications (`external_hooks`) remains read-only discovery data and must not enter the executable registry.

## Architecture

Expand Down
12 changes: 12 additions & 0 deletions scripts/core-boundaries/rules/source/public-api-rules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ export const opencodeAdapterPublicApiEntries = [
'load_opencode_package_adapter',
'bitfun-core managed plugin composition root and DefaultPluginRuntimeClient integration tests',
),
opencodeAdapterEntry(
'load_opencode_config_snapshot',
'bitfun-core live Plugin Host composition root and OpenCode config snapshot contract tests',
),
opencodeAdapterEntry(
'OpenCodeConfigSnapshot',
'bitfun-core live Plugin Host config input and OpenCode config snapshot contract tests',
),
opencodeAdapterEntry(
'OpenCodeConfigSnapshotError',
'bitfun-core live Plugin Host config validation and OpenCode config snapshot contract tests',
),
opencodeAdapterEntry(
'OpenCodeCommandProvider',
'bitfun-core external source composition root and OpenCode command adapter tests',
Expand Down
77 changes: 20 additions & 57 deletions scripts/core-boundaries/rules/source/required-rules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1760,54 +1760,24 @@ export const requiredContentRules = [
],
},
{
path: 'src/crates/execution/agent-runtime/src/post_call_hooks.rs',
reason:
'agent-runtime must own portable hook registry and post-call routing decisions while concrete hook execution stays in the owning runtime',
path: 'src/crates/execution/agent-runtime/src/native_hooks/kind.rs',
reason: 'agent-runtime must own portable hook kind contracts',
patterns: [
{
regex: /\bpub enum RuntimeHookKind\b/,
message: 'missing runtime hook kind contract',
},
{
regex: /\bpub enum RuntimeHookErrorPolicy\b/,
message: 'missing runtime hook error policy contract',
},
{
regex: /\bpub struct RuntimeHookPlan\b/,
message: 'missing runtime hook plan contract',
},
{
regex: /\bpub struct RuntimeHookRegistry\b/,
message: 'missing runtime hook registry contract',
},
{
regex: /\btimeout_millis\b/,
message: 'missing runtime hook timeout contract',
},
{
regex: /\bDuplicateHookId\b/,
message: 'missing runtime hook duplicate-id guard',
},
{
regex: /\bEmptyHookId\b/,
message: 'missing runtime hook empty-id guard',
},
{
regex: /\bInvalidTimeoutMillis\b/,
message: 'missing runtime hook non-zero-timeout guard',
},
{
regex: /\bpub const fn successful_tool_post_call_hooks\b/,
message: 'missing successful tool post-call hook routing decision',
},
{
regex: /\bpub trait SuccessfulToolPostCallHookExecutor\b/,
message: 'missing successful tool post-call hook executor contract',
},
{
regex: /\bpub fn run_successful_tool_post_call_hooks\b/,
message: 'missing successful tool post-call hook executor runner',
},
{ regex: /\bpub enum RuntimeHookKind\b/, message: 'missing runtime hook kind contract' },
{ regex: /\bSuccessfulToolPostCall\b/, message: 'missing successful tool post-call hook kind' },
],
},
{
path: 'src/crates/execution/agent-runtime/src/native_hooks/registry.rs',
reason: 'agent-runtime must own portable hook registry and validation contracts',
patterns: [
{ regex: /\bpub enum RuntimeHookErrorPolicy\b/, message: 'missing runtime hook error policy contract' },
{ regex: /\bpub struct RuntimeHookPlan\b/, message: 'missing runtime hook plan contract' },
{ regex: /\bpub struct RuntimeHookRegistry\b/, message: 'missing runtime hook registry contract' },
{ regex: /\btimeout_millis\b/, message: 'missing runtime hook timeout contract' },
{ regex: /\bDuplicateHookId\b/, message: 'missing runtime hook duplicate-id guard' },
{ regex: /\bEmptyHookId\b/, message: 'missing runtime hook empty-id guard' },
{ regex: /\bInvalidTimeoutMillis\b/, message: 'missing runtime hook non-zero-timeout guard' },
],
},
{
Expand All @@ -1816,11 +1786,11 @@ export const requiredContentRules = [
'agent-runtime post-call hook owner must keep behavior-equivalence contracts for successful tool-call hook routing',
patterns: [
{
regex: /\bsuccessful_tool_call_routes_to_shared_context_measurement_hook\b/,
regex: /\bsuccessful_tool_call_uses_stable_builtin_registration_id\b/,
message: 'missing successful tool post-call hook routing regression',
},
{
regex: /\bruntime_hook_registry_preserves_order_timeout_and_error_policy\b/,
regex: /\bruntime_hook_registry_preserves_source_order_timeout_and_error_policy\b/,
message: 'missing runtime hook order/timeout/error-policy regression',
},
{
Expand Down Expand Up @@ -2702,14 +2672,7 @@ export const requiredContentRules = [
reason:
'core post-call hooks must delegate portable hook routing to agent-runtime while retaining concrete hook execution',
patterns: [
{
regex: /\brun_successful_tool_post_call_hooks\b/,
message: 'missing post-call hook executor runner delegation',
},
{
regex: /\bSuccessfulToolPostCallHookExecutor\b/,
message: 'missing post-call hook executor implementation',
},
{ regex: /\bdispatch_successful_tool_post_call\b/, message: 'missing post-call hook dispatch delegation' },
],
},
{
Expand Down
16 changes: 8 additions & 8 deletions scripts/core-boundaries/self-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ export function runManifestParserSelfTest({
).map((entry) => entry.symbol);
if (
opencodeAdapterPublicApiSymbols.join(',') !==
'load_opencode_package_adapter,OpenCodeCommandProvider,OpenCodeCommandProviderOptions,OpenCodeConfiguredSkillRoot,OpenCodeSkillRootProvider,OpenCodeSkillRootProviderOptions,OpenCodeToolProvider,OpenCodeToolProviderOptions,OpenCodeSubagentProvider,OpenCodeSubagentProviderOptions,OpenCodeMcpProvider,OpenCodeMcpProviderOptions,OpenCodeHookProvider,OpenCodeHookProviderOptions,OpenCodeWorkspaceReferenceProvider,OpenCodeWorkspaceReferenceProviderOptions,load_opencode_user_instructions,OpenCodeInstructionSourceOptions'
'load_opencode_package_adapter,load_opencode_config_snapshot,OpenCodeConfigSnapshot,OpenCodeConfigSnapshotError,OpenCodeCommandProvider,OpenCodeCommandProviderOptions,OpenCodeConfiguredSkillRoot,OpenCodeSkillRootProvider,OpenCodeSkillRootProviderOptions,OpenCodeToolProvider,OpenCodeToolProviderOptions,OpenCodeSubagentProvider,OpenCodeSubagentProviderOptions,OpenCodeMcpProvider,OpenCodeMcpProviderOptions,OpenCodeHookProvider,OpenCodeHookProviderOptions,OpenCodeWorkspaceReferenceProvider,OpenCodeWorkspaceReferenceProviderOptions,load_opencode_user_instructions,OpenCodeInstructionSourceOptions'
) {
throw new Error(
'OpenCode adapter public API budget must stay limited to the reviewed package factory and capability-specific command, configured Skill root, tool, subagent, MCP, static Hook, workspace Reference, and user Instruction providers',
Expand Down Expand Up @@ -2818,24 +2818,24 @@ export function runManifestParserSelfTest({
],
},
{
path: 'src/crates/execution/agent-runtime/src/post_call_hooks.rs',
path: 'src/crates/execution/agent-runtime/src/native_hooks/kind.rs',
contracts: ['RuntimeHookKind', 'SuccessfulToolPostCall'],
},
{
path: 'src/crates/execution/agent-runtime/src/native_hooks/registry.rs',
contracts: [
'RuntimeHookKind',
'RuntimeHookErrorPolicy',
'RuntimeHookPlan',
'RuntimeHookRegistry',
'EmptyHookId',
'InvalidTimeoutMillis',
'successful_tool_post_call_hooks',
'SuccessfulToolPostCallHookExecutor',
'run_successful_tool_post_call_hooks',
],
},
{
path: 'src/crates/execution/agent-runtime/tests/agent_interaction_contracts/post_call_hook_contracts.rs',
contracts: [
'successful_tool_call_routes_to_shared_context_measurement_hook',
'runtime_hook_registry_preserves_order_timeout_and_error_policy',
'successful_tool_call_uses_stable_builtin_registration_id',
'runtime_hook_registry_preserves_source_order_timeout_and_error_policy',
'runtime_hook_registry_rejects_duplicate_ids',
'runtime_hook_registry_rejects_unstable_ids_and_zero_timeouts',
],
Expand Down
Loading