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/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>