fix(tools): collapse code-mode executor to run_code for model-direct calls

wireSchemas() already advertised only run_code under mode: 'code', but the
executor resolved every call through get(), which returns the full visible
map plus the reserved transport. A model could name a native tool directly
and bypass run_code entirely. Route the execution-path lookups through a
new private resolveExecution() that applies the mode collapse at the
operation boundary: model-direct calls under 'code' may only name run_code
(UNKNOWN_TOOL otherwise), while SDK sub-dispatches (parent token set) keep
every visible tool. get()/schemas() public semantics are unchanged.

The denial happens at createExecution, before the extensible policy
pipeline — pre-execute listeners, approval ask, and guards never observe
a call that is deterministically denied. A collapsed call honors the
pre-dispatch cancellation contract, routes aborted results through the
visible tool's finalizeContent, and captures the finalizer before
argument materialization.

Regenerated docs, catalogs, graphs, scoped events, re-recorded
translation pairs, and updated test assertions.

Fixes #1815
This commit is contained in:
Chinesezjc
2026-08-11 03:01:14 +08:00
parent 2aef2d83fa
commit 24dd48b133
10 changed files with 120 additions and 57 deletions

View File

@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/config-catalog.md
config-catalog.md: f84fdb17f29f9352cda77fc1901beba79a416c2f
config-catalog.zh.md: e7cfcff8d69c3a1efbe8426e25415783bc41f864
config-catalog.md: 6362022dd1b80e17997684574d9dc7f14372e23a
config-catalog.zh.md: 3fd335ee2b1ec6d1526f75ed9667f1d9286faafe

View File

@@ -2481,16 +2481,14 @@ Requires: `systemPrompt`
/** Plugin config: how the registered tools are presented to the model. */
export interface Config {
/**
* Model presentation for agents that declare none of their own. `native`
* (default) sends every visible schema; `code` sends only `run_code` plus a
* generated SDK prompt; `both` sends both forms. Code modes require a
* `ctx.codeRuntime` whose `language` has a registered SDK renderer
* (TypeScript or Python) and fail prompt assembly when it is absent or has
* no renderer. Under `code`, native names in `toolOrder` are invalid.
*
* One agent overrides this for itself with {@link ToolRegistry.presentAs},
* which is how an agent preset composes a Code Mode agent beside native
* ones in the same process.
* Model presentation. `native` (default) sends every visible schema; `code`
* sends only `run_code` plus a generated SDK prompt and collapses the
* executor to the same surface (a model-direct call may only name
* `run_code`; `run_code` SDK sub-dispatches keep every visible tool); `both`
* sends both forms. Code modes require a `ctx.codeRuntime` whose `language`
* has a registered SDK renderer (TypeScript or Python) and fail prompt
* assembly when it is absent or has no renderer. Under `code`, native names
* in `toolOrder` are invalid.
*/
mode?: ToolPresentationMode
/**

View File

@@ -2482,16 +2482,14 @@ export interface Config {
/** Plugin config: how the registered tools are presented to the model. */
export interface Config {
/**
* Model presentation for agents that declare none of their own. `native`
* (default) sends every visible schema; `code` sends only `run_code` plus a
* generated SDK prompt; `both` sends both forms. Code modes require a
* `ctx.codeRuntime` whose `language` has a registered SDK renderer
* (TypeScript or Python) and fail prompt assembly when it is absent or has
* no renderer. Under `code`, native names in `toolOrder` are invalid.
*
* One agent overrides this for itself with {@link ToolRegistry.presentAs},
* which is how an agent preset composes a Code Mode agent beside native
* ones in the same process.
* Model presentation. `native` (default) sends every visible schema; `code`
* sends only `run_code` plus a generated SDK prompt and collapses the
* executor to the same surface (a model-direct call may only name
* `run_code`; `run_code` SDK sub-dispatches keep every visible tool); `both`
* sends both forms. Code modes require a `ctx.codeRuntime` whose `language`
* has a registered SDK renderer (TypeScript or Python) and fail prompt
* assembly when it is absent or has no renderer. Under `code`, native names
* in `toolOrder` are invalid.
*/
mode?: ToolPresentationMode
/**

View File

@@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/subsystems/tools.md
tools.md: 4f0360f45e7ed4f3537bedeb0f370f8eb3472ab9
tools.zh.md: aa6c67c6379e4a9b9ab7bdc473f6294d063e3649
tools.md: fff43d587428ca4747cfd19ac5fccca08b4e048e
tools.zh.md: 4705edf81e56c81b237a69caa1c012ba12d67716

View File

@@ -571,7 +571,7 @@ async execute(exec: ToolExecutionInput): Promise<ToolExecutionResult>
Types: [ScopeKey](scope.md)
Source: [`packages/core/tools/src/index.ts:764`](../../packages/core/tools/src/index.ts)
Source: [`packages/core/tools/src/index.ts:762`](../../packages/core/tools/src/index.ts)
<a id="tools-events"></a>

View File

@@ -571,7 +571,7 @@ async execute(exec: ToolExecutionInput): Promise<ToolExecutionResult>
Types: [ScopeKey](scope.md)
Source: [`packages/core/tools/src/index.ts:764`](../../packages/core/tools/src/index.ts)
Source: [`packages/core/tools/src/index.ts:762`](../../packages/core/tools/src/index.ts)
<a id="tools-events"></a>