For agentic workers: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox syntax for tracking; completed items are marked
- [x].Status 2026-06-08: Implemented. Final focused tests, CLI typecheck, explicit build, and prompt-trajectory e2e passed. Final trajectory evidence 是本地
tools/prompt-trajectory/out/下的两组记录(未入库):P-12 outer requesttest20260608-213225与 internal requestfinal3。 Full CLI lint/test still have unrelated pre-existing failures documented in the final implementation report.
Goal: 把 ZCode WebSearch 从主请求 direct provider-native web_search 切换为 client tool + internal side request 形态:外层暴露普通 WebSearch client tool,handler 内部发起只包含 provider-native web_search 的 model request,并把结果作为普通 tool result 回灌给主模型。
Architecture: 主模型请求只看到 WebSearch function tool;web_search 只在 WebSearch handler 的内部 side request 中出现。Runtime registry、permission、scheduler、hooks、tool parts、history 和 nested usage 都按普通 client-side tool 路径处理 WebSearch;adapter 的 provider-native helper 映射继续保留,但只服务内部 request。
Tech Stack: TypeScript, Zod, Vercel AI SDK tool helpers, Vitest, prompt-trajectory, ZCode core runtime/tool registry/adapter contracts.
用户已明确要求“不要帮我自动提交,除非我主动要求了”。执行本 plan 时:
git commit,除非用户在当轮明确要求提交。git add 之前先征询用户;默认只保留 working tree diff。apps/zcode-cli/docs/design/v2/tool/13-websearch.mdapps/zcode-cli/docs/design/v2/tool/00-tool-change-chain.mdapps/zcode-cli/packages/core/src/tool/handlers/websearch.tsapps/zcode-cli/packages/core/src/tool/handlers/websearch-results.tsapps/zcode-cli/packages/core/src/tool/handlers/websearch-support.tsapps/zcode-cli/packages/core/src/runtime/methods/config.tsapps/zcode-cli/packages/contracts/src/tools/websearch.tsapps/zcode-cli/packages/adapters/src/model/tool-transform.ts| ID | Decision |
|---|---|
| WS-D1 | 外层 provider-visible tool name 是 WebSearch,不是 web_search。 |
| WS-D2 | 外层 WebSearch 是 client-side tool,必须进入 ToolExecutor、permission、scheduler、hooks、tool part persistence 和 tool result history。 |
| WS-D3 | 内部 side request 的唯一 tool 是 provider-native web_search,由 adapter 映射到 Anthropic provider 的 native web search helper。 |
| WS-D4 | 外层 public schema 使用 snake_case domain 字段:query、allowed_domains、blocked_domains。 |
| WS-D5 | 只保留当前 Anthropic provider-native web_search 实际消费的 maxUses public 可选调参字段,并透传到内部 provider-native args;searchContextSize 不再暴露,避免形成 no-op contract。 |
| WS-D6 | web_search 可以作为 legacy allowlist alias 映射到 WebSearch,但不得出现在外层 provider-visible tools[].name。 |
| WS-D7 | Provider capability gate 优先在 runtime tool projection 做;handler assertion 继续作为第二道 fail-closed 防线。 |
| WS-D8 | runtime 只有在能解析 model connection,且 providerKind === "anthropic"、baseURL host 为 bigmodel.cn / z.ai / deepseek.com 或其子域时才暴露 WebSearch;无法解析时 fail-closed。 |
| WS-D9 | 先不实现内部 request 的 streaming progress;内部 request 保持 generateText,只保证 request shape 与 tool result 格式。 |
| WS-D10 | 不恢复 BigModel Web Search REST API、DuckDuckGo HTML fallback、numResults、safeSearch。 |
| File | Responsibility in this change |
|---|---|
apps/zcode-cli/docs/design/v2/tool/13-websearch.md |
正式 spec,从 direct provider-native 改为 public wrapper + internal native side request。 |
apps/zcode-cli/docs/design/v2/tool/00-tool-change-chain.md |
更新 provider-native/server-side checklist,说明 WebSearch 采用 side request 形态。 |
apps/zcode-cli/docs/design/v2/tool/README.md |
Tool matrix 改为 WebSearch client-side wrapper。 |
apps/zcode-cli/docs/design/v2/model/http-proxy.md |
说明 WebSearch 内部 model request 跟随 provider transport/proxy。 |
apps/zcode-cli/docs/design/v2/compact/plan.md |
WebSearch 有本地 tool result budget。 |
apps/zcode-cli/docs/design/v2/loop/system-prompt-contract.md |
WebSearch 不再是主请求 provider-native tool。 |
apps/zcode-cli/docs/design/v2/loop/architecture.md |
read-only/concurrent tool 调度说明加入 WebSearch。 |
apps/zcode-cli/docs/design/v2/tui-network-status-panel.md |
WebSearch handler 内部 model request 的 network status 说明。 |
apps/zcode-cli/packages/contracts/src/tools/websearch.ts |
拆 public schema、内部 provider-native args、client contract。 |
apps/zcode-cli/packages/core/src/tool/handlers/websearch.ts |
normalize public snake_case input;内部发起 provider-native web_search request。 |
apps/zcode-cli/packages/core/src/tool/handlers/websearch-results.ts |
tool result text、sources reminder、typed result extraction。 |
apps/zcode-cli/packages/core/src/tool/handlers/websearch-support.ts |
导出 provider support predicate,供 runtime projection 和 handler 共用。 |
apps/zcode-cli/packages/core/src/tool/handlers/index.ts |
注册 webSearchToolEntry。 |
apps/zcode-cli/packages/core/src/runtime/agent-runtime.ts |
保存 modelConnectionPort;allowlist alias normalize;注册/过滤 WebSearch。 |
apps/zcode-cli/packages/core/src/runtime/internal.ts |
AgentRuntimeInternal 增加 modelConnectionPort?: ModelConnectionPort。 |
apps/zcode-cli/packages/core/src/runtime/methods/config.ts |
删除 direct append web_search,getTools() 返回过滤后的 registry contracts。 |
apps/zcode-cli/packages/core/src/tool/scheduler.ts |
READ_ONLY_TOOLS 加回 WebSearch。 |
apps/zcode-cli/packages/core/src/permission/service.ts |
isReadOnlyTool() 加回 WebSearch。 |
apps/zcode-cli/packages/adapters/src/model/tool-transform.ts |
保持 provider-native helper 映射;确认 public WebSearch 不进 provider-native branch。 |
apps/zcode-cli/packages/core/tests/websearch.test.ts |
主红绿测试:schema、registry、runtime projection、handler side request。 |
apps/zcode-cli/packages/core/tests/main-tool-pool.test.ts |
主请求 tool list 从 web_search 改为 WebSearch。 |
apps/zcode-cli/packages/core/tests/subagent-explore.test.ts |
Explore child tool list 从 web_search 改为 WebSearch。 |
apps/zcode-cli/packages/core/tests/scheduler.test.ts |
WebSearch read-only/concurrent scheduling coverage。 |
apps/zcode-cli/packages/adapters/tests/websearch.test.ts |
provider-native mapping 改为内部 web_search contract 语义。 |
apps/zcode-cli/packages/adapters/tests/runner.test.ts |
保持内部 native request body / providerExecuted normalization coverage。 |
apps/zcode-cli/tools/prompt-trajectory/testcases/* |
增加或更新 WebSearch request-body fixtures。 |
每个 phase 完成后停止给用户 review:
Files:
apps/zcode-cli/docs/design/v2/tool/13-websearch.mdapps/zcode-cli/docs/design/v2/tool/00-tool-change-chain.mdapps/zcode-cli/packages/core/tests/websearch.test.tsapps/zcode-cli/packages/core/tests/main-tool-pool.test.tsapps/zcode-cli/packages/core/tests/subagent-explore.test.tsModify: apps/zcode-cli/packages/adapters/tests/websearch.test.ts
[x] Step 0.1: Rewrite the WebSearch spec
Replace 13-websearch.md with a spec whose top-level conclusion states:
# WebSearch Wrapper Tool
## 结论
`WebSearch` 是主模型可见的普通 client-side tool。模型调用 `WebSearch`
后,ZCode 在 tool handler 内部发起一个只包含 provider-native `web_search`
的 model request。内部 request 返回后,ZCode 把 links/sources 格式化为
普通 tool result,回灌给主模型继续生成最终答案。
主模型请求不得直接暴露 provider-native `web_search`。
In 00-tool-change-chain.md, replace the WebSearch direct exposure paragraph with:
WebSearch 当前目标采用 side request 形态:主 loop 注册普通 `WebSearch`
client-side tool;`web_search` provider-native contract 只在 `WebSearch`
handler 内部 request 中出现。外层 `WebSearch` 必须完整经过 ToolExecutor、
permission、hook、scheduler、事件、resultBudget 和 tool result history。
In apps/zcode-cli/packages/core/tests/websearch.test.ts, change the schema test to:
it("exposes WebSearch schema without unsupported provider-native no-op options", () => {
const properties = WebSearchInputJsonSchema.properties as Record<string, unknown>;
expect(properties.query).toBeDefined();
expect(properties.allowed_domains).toBeDefined();
expect(properties.blocked_domains).toBeDefined();
expect(properties.allowedDomains).toBeUndefined();
expect(properties.blockedDomains).toBeUndefined();
expect(properties.maxUses).toBeDefined();
expect(properties.searchContextSize).toBeUndefined();
expect(properties.numResults).toBeUndefined();
expect(properties.safeSearch).toBeUndefined();
});
In apps/zcode-cli/packages/core/tests/websearch.test.ts, replace the unregistered/direct-native assertions with:
it("registers WebSearch as a client-side built-in tool", () => {
const registry = createToolRegistry();
registerBuiltInTools(registry, { includeAgent: true });
expect(registry.has("WebSearch")).toBe(true);
expect(registry.has("web_search")).toBe(false);
expect(registry.toContracts()).toContainEqual(
expect.objectContaining({
executionMode: "client",
name: "WebSearch",
providerNative: undefined,
}),
);
});
it("does not add direct provider-native web_search to main model contracts", () => {
const runtime = createRuntime("runtime-websearch-client-wrapper");
const tools = runtime.getTools();
expect(runtime.getToolRegistry().has("WebSearch")).toBe(true);
expect(tools).toContainEqual(
expect.objectContaining({
executionMode: "client",
name: "WebSearch",
providerNative: undefined,
}),
);
expect(tools.some((tool) => tool.name === "web_search")).toBe(false);
});
Add this focused test to websearch.test.ts:
it("runs an internal provider-native web_search request from the WebSearch handler", async () => {
const sessionId = createSessionId("runtime-websearch-handler-side-request");
const eventStore = createTestSessionEventStore();
const requests: any[] = [];
const runtime = new AgentRuntime(sessionId, { modelRef }, {
eventStore,
modelAdapter: {
async generateText(request: any) {
requests.push(request);
if (request.metadata?.querySource === "web_search_tool") {
return {
finishReason: "stop",
model: request.model,
providerMetadata: undefined,
text: "Search summary",
toolResults: [
{
id: "server_search_1",
name: "web_search",
output: [{ type: "web_search_result", title: "Example", url: "https://example.com" }],
providerExecuted: true,
},
],
sources: [{ sourceType: "url", title: "Example", url: "https://example.com" }],
usage: {
inputTokens: 5,
outputTokens: 7,
totalTokens: 12,
serverToolUse: { webSearchRequests: 1 },
},
};
}
return {
finishReason: "tool-calls",
model: request.model,
providerMetadata: undefined,
text: "",
toolCalls: [
{
id: "call_websearch",
name: "WebSearch",
input: { query: "latest zcode", allowed_domains: ["example.com"] },
},
],
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
};
},
resolveConnection() {
return {
providerId: "deepseek",
providerKind: "anthropic",
baseURL: "https://api.deepseek.com/anthropic",
};
},
} as never,
});
await runtime.executeTurn("Search current ZCode info");
const innerRequest = requests.find((request) => request.metadata?.querySource === "web_search_tool");
expect(innerRequest).toBeDefined();
expect(innerRequest.messages).toEqual([
{ role: "system", content: "You are an assistant for performing a web search tool use." },
{ role: "user", content: "Perform a web search for the query: latest zcode" },
]);
expect(innerRequest.tools.map((tool: any) => tool.name)).toEqual(["web_search"]);
expect(innerRequest.tools[0]).toMatchObject({
executionMode: "providerNative",
providerNative: expect.objectContaining({
logicalName: "WebSearch",
providerToolName: "web_search",
args: expect.objectContaining({
allowedDomains: ["example.com"],
maxUses: 8,
}),
}),
});
expect(innerRequest.tools[0].providerNative.args).not.toHaveProperty("searchContextSize");
expect(innerRequest.toolChoice).toBeUndefined();
});
Add the overload used above:
function createRuntime(
sessionId: string,
config: ConstructorParameters<typeof AgentRuntime>[1] = {},
deps: Partial<ConstructorParameters<typeof AgentRuntime>[2]> = {},
): AgentRuntime {
return new AgentRuntime(
createSessionId(sessionId),
{
modelRef,
...config,
},
{
eventStore: createTestSessionEventStore(),
...deps,
},
);
}
Run:
pnpm --filter @zcode/core exec vitest run tests/websearch.test.ts tests/main-tool-pool.test.ts tests/subagent-explore.test.ts
pnpm --filter @zcode/adapters exec vitest run tests/websearch.test.ts
Expected: FAIL with old direct provider-native behavior:
allowedDomains.WebSearch.web_search.WebSearch is not registered.Files:
apps/zcode-cli/packages/contracts/src/tools/websearch.tsapps/zcode-cli/packages/core/src/tool/handlers/websearch.tsapps/zcode-cli/packages/core/src/tool/handlers/websearch-results.tsModify: apps/zcode-cli/packages/core/tests/websearch.test.ts
[x] Step 1.1: Replace public input schema with snake_case
In websearch.ts contracts, use this shape:
export const WebSearchInputSchema = z
.object({
query: z.string().min(2).describe("The search query to use"),
allowed_domains: z
.array(DomainSchema)
.max(20)
.optional()
.describe("Only include search results from these domains"),
blocked_domains: z
.array(DomainSchema)
.max(20)
.optional()
.describe("Never include search results from these domains"),
})
.strict()
.refine((input) => !(input.allowed_domains?.length && input.blocked_domains?.length), {
message: "allowed_domains and blocked_domains cannot both be specified",
path: ["blocked_domains"],
});
In the same file, add:
export interface WebSearchProviderNativeArgs {
allowedDomains?: string[];
blockedDomains?: string[];
maxUses?: number;
}
export function toWebSearchProviderNativeArgs(
input: WebSearchInput,
defaults: { maxUses: number },
): WebSearchProviderNativeArgs {
return {
allowedDomains: input.allowed_domains,
blockedDomains: input.blocked_domains,
maxUses: input.maxUses ?? defaults.maxUses,
};
}
Change WEBSEARCH_TOOL_CONTRACT to:
export const WEBSEARCH_TOOL_CONTRACT: ToolContractDeclaration = {
capability: "web_search",
executionMode: "client",
inputSchema: WebSearchInputJsonSchema,
outputSchema: WebSearchOutputJsonSchema,
permission: {
permission: "websearch",
reason: "WebSearch performs read-only provider-native web searches through an internal model request",
riskLevel: "low",
sideEffectScope: "network",
needsApproval: false,
patternSources: ["toolName", "input", "network"],
denyPriority: "beforeAsk",
},
resultBudget: {
maxInlineBytes: 10_000,
maxModelBytes: 20_000,
strategy: "truncate",
preview: {
maxLines: 30,
direction: "head",
},
},
timeout: {
defaultMs: 60_000,
maxMs: 120_000,
allowCallOverride: true,
},
cancellation: {
supported: true,
cleanup: "bestEffort",
userVisibleMessage: "WebSearch was cancelled",
},
trace: {
required: true,
propagateToAdapters: true,
recordInput: "full",
recordOutput: "summary",
},
};
Do not include providerNative on WEBSEARCH_TOOL_CONTRACT.
In apps/zcode-cli/packages/core/src/tool/handlers/websearch.ts, import toWebSearchProviderNativeArgs and change the provider-native contract args:
providerNative: {
...WEBSEARCH_PROVIDER_NATIVE_SPEC,
args: toWebSearchProviderNativeArgs(input, {
maxUses: DEFAULT_MAX_USES,
}),
},
Replace handler reads:
input.allowedDomains
input.blockedDomains
with:
input.allowed_domains
input.blocked_domains
The handler should still pass provider-native camelCase args to the adapter through toWebSearchProviderNativeArgs(...).
Run:
pnpm --filter @zcode/core exec vitest run tests/websearch.test.ts
Expected: schema tests pass; registry/projection tests still fail until Phase 2.
Files:
apps/zcode-cli/packages/core/src/tool/handlers/index.tsapps/zcode-cli/packages/core/src/runtime/agent-runtime.tsapps/zcode-cli/packages/core/src/runtime/internal.tsapps/zcode-cli/packages/core/src/runtime/methods/config.tsapps/zcode-cli/packages/core/src/tool/handlers/websearch-support.tsapps/zcode-cli/packages/core/tests/websearch.test.tsapps/zcode-cli/packages/core/tests/main-tool-pool.test.tsModify: apps/zcode-cli/packages/core/tests/subagent-explore.test.ts
[x] Step 2.1: Register the client tool
In handlers/index.ts add:
import { webSearchToolEntry } from "./websearch.js";
and include it in builtInTools after webFetchToolEntry:
webFetchToolEntry,
webSearchToolEntry,
todoReadToolEntry,
In agent-runtime.ts, add:
function normalizeBuiltInToolAllowlist(
allowlist: readonly string[] | undefined,
): readonly string[] | undefined {
return allowlist?.map((toolName) => (toolName === "web_search" ? "WebSearch" : toolName));
}
Then call it in resolveBuiltInToolAllowlist(...):
const normalizedAllowlist = normalizeBuiltInToolAllowlist(config.toolAllowlist);
if (config.toolset !== "explore") {
return normalizedAllowlist;
}
if (!normalizedAllowlist) {
return EXPLORE_AGENT_ALLOWED_TOOLS;
}
return normalizedAllowlist.filter((toolName) => EXPLORE_AGENT_ALLOWED_TOOL_SET.has(toolName));
In agent-runtime.ts, add a private field:
private modelConnectionPort?: ModelConnectionPort;
Set it in the constructor before creating the executor:
this.modelConnectionPort =
deps.modelConnectionPort ?? (deps.modelAdapter as ModelConnectionPort | undefined);
Pass this.modelConnectionPort into createToolExecutor(...):
modelConnectionPort: this.modelConnectionPort,
In runtime/internal.ts, import ModelConnectionPort and add:
modelConnectionPort?: ModelConnectionPort;
In websearch-support.ts, export:
export function supportsProviderNativeWebSearch(
connection: Pick<ModelConnectionInfo, "baseURL" | "providerKind">,
): boolean {
return (
connection.providerKind === "anthropic" &&
isWebSearchCapableBaseURL(connection.baseURL)
);
}
Then simplify assertProviderSupportsWebSearch(...):
if (!supportsProviderNativeWebSearch(connection)) {
throw createCoreError(
CoreErrorType.ConfigurationError,
"Current provider/model does not support native WebSearch",
{ context: { toolCallId, toolName: WEBSEARCH_TOOL_NAME }, recoverable: true },
);
}
In runtime/methods/config.ts, remove:
WEBSEARCH_PROVIDER_NATIVE_SPEC
WEBSEARCH_TOOL_CONTRACT
WEBSEARCH_PUBLIC_TOOL_NAME
WEBSEARCH_PROVIDER_TOOL_NAME
withRuntimeProviderNativeTools(...)
shouldExposeProviderNativeWebSearch(...)
createProviderNativeWebSearchContract(...)
Replace getTools() with registry contracts plus capability filter:
export function getTools(this: AgentRuntimeInternal): ModelToolContract[] {
if (this.cachedTools === null) {
this.cachedTools = filterRuntimeVisibleTools.call(this, this.registry.toContracts());
}
return this.cachedTools;
}
Add:
function filterRuntimeVisibleTools(
this: AgentRuntimeInternal,
tools: ModelToolContract[],
): ModelToolContract[] {
return tools.filter((tool) => {
if (tool.name !== "WebSearch") return true;
return shouldExposeWebSearch.call(this);
});
}
function shouldExposeWebSearch(this: AgentRuntimeInternal): boolean {
if (!this.modelConnectionPort) return true;
try {
const connection = this.modelConnectionPort.resolveConnection(this.defaultModelRef);
return supportsProviderNativeWebSearch(connection);
} catch {
return true;
}
}
Import supportsProviderNativeWebSearch from ../../tool/handlers/websearch-support.js.
In main-tool-pool.test.ts, change:
expect(toolNames).toContain("web_search");
expect(toolNames).not.toContain("WebSearch");
to:
expect(toolNames).toContain("WebSearch");
expect(toolNames).not.toContain("web_search");
In subagent-explore.test.ts, change expected child tools from:
"web_search",
to:
"WebSearch",
Run:
pnpm --filter @zcode/core exec vitest run tests/websearch.test.ts tests/main-tool-pool.test.ts tests/subagent-explore.test.ts
Expected: registry/projection tests pass; handler result formatting tests may still fail until Phase 3.
Files:
apps/zcode-cli/packages/core/src/tool/handlers/websearch.tsapps/zcode-cli/packages/core/src/tool/handlers/websearch-results.tsapps/zcode-cli/packages/core/tests/websearch.test.tsModify: apps/zcode-cli/packages/adapters/tests/runner.test.ts
[x] Step 3.1: Ensure inner request is side-request only
Confirm websearch.ts handler request keeps this exact shape:
const result = await modelPort.generateText({
model: {
...modelRef,
role: modelRef.role ?? ModelRole.Main,
},
messages: [
{
role: "system",
content: "You are an assistant for performing a web search tool use.",
},
{
role: "user",
content: `Perform a web search for the query: ${input.query}`,
},
],
tools: [createProviderNativeWebSearchContract(input)],
// BigModel 的 Anthropic 兼容端点会拒绝 named forced web_search tool_choice(1210)。
// 这里保持自动选择,依靠单工具请求和 prompt 触发 provider-native 搜索。
maxOutputTokens: 4096,
abortSignal: context.abortSignal,
metadata: {
traceId: context.traceId,
sessionId: context.sessionId,
turnId: context.turnId,
toolCallId: context.toolCallId,
toolName: WEBSEARCH_TOOL_NAME,
querySource: "web_search_tool",
},
statusSink: createToolModelStatusSink(context),
traceContext: webSearchTraceFromContext(context),
});
In websearch-results.ts, change the final reminder to:
lines.push(
"",
"REMINDER: You MUST include the sources above in your response to the user using markdown hyperlinks.",
);
Extend collectResults(...) so it handles typed wrapper objects:
if (Array.isArray(value.content)) {
return value.content.flatMap((item) => collectResults(item));
}
Keep existing direct url extraction so both Anthropic provider typed results and OpenAI provider source-like results work.
In websearch.test.ts, add:
it("formats WebSearch tool results with markdown sources reminder", () => {
const text = webSearchToolEntry.formatModelContent?.({
query: "latest zcode",
results: [{ title: "Example", url: "https://example.com" }],
sources: [],
durationMs: 10,
webSearchRequests: 1,
modelUsage: {
inputTokens: 5,
outputTokens: 7,
totalTokens: 12,
serverToolUse: { webSearchRequests: 1 },
},
});
expect(String(text)).toContain('Web search results for query: "latest zcode"');
expect(String(text)).toContain("- [Example](https://example.com)");
expect(String(text)).toContain("markdown hyperlinks");
});
Run:
pnpm --filter @zcode/core exec vitest run tests/websearch.test.ts
pnpm --filter @zcode/adapters exec vitest run tests/runner.test.ts
Expected: WebSearch handler side request, formatter, providerExecuted normalization, and nested usage extraction pass.
Files:
apps/zcode-cli/packages/core/src/tool/scheduler.tsapps/zcode-cli/packages/core/src/permission/service.tsapps/zcode-cli/packages/core/tests/scheduler.test.tsModify: apps/zcode-cli/packages/core/tests/websearch.test.ts
[x] Step 4.1: Add WebSearch to read-only scheduler set
In scheduler.ts, change:
export const READ_ONLY_TOOLS = new Set([
"Read",
"Glob",
"Grep",
"WebSearch",
"WebFetch",
"TodoRead",
"TodoWrite",
"AskUserQuestion",
"Agent",
"Skill",
]);
In permission/service.ts, change isReadOnlyTool(...) to include:
"WebSearch",
Remove the old Chinese temporary-debug comments that said WebSearch does not enter local scheduling.
In websearch.test.ts, extend the handler side request test after executeTurn(...):
const storedEvents = await eventStore.getEvents(sessionId);
expect(
storedEvents.some(
(event: any) =>
event.type === SessionEventType.ToolCallResult &&
event.payload?.toolName === "WebSearch",
),
).toBe(true);
Run:
pnpm --filter @zcode/core exec vitest run tests/websearch.test.ts tests/scheduler.test.ts
Expected: WebSearch is treated as read-only/concurrent safe and produces ordinary tool lifecycle events.
Files:
apps/zcode-cli/packages/adapters/tests/websearch.test.tsapps/zcode-cli/packages/adapters/tests/runner.test.tsapps/zcode-cli/tools/prompt-trajectory/testcases/p12-tool-surface/main-and-explore/expect.jsonapps/zcode-cli/tools/prompt-trajectory/testcases/websearch-client-tool/fixture.jsonCreate: apps/zcode-cli/tools/prompt-trajectory/testcases/websearch-client-tool/expect.json
[x] Step 5.1: Rename adapter test helper to internal native contract
In adapters/tests/websearch.test.ts, change helper contract name to web_search:
function createInternalWebSearchContract(args?: Record<string, unknown>): ModelToolContract {
return {
name: "web_search",
capability: "web_search",
description: "Provider-native web search used internally by WebSearch",
executionMode: "providerNative",
inputSchema: WEBSEARCH_TOOL_CONTRACT.inputSchema,
outputSchema: WEBSEARCH_TOOL_CONTRACT.outputSchema,
providerNative: {
...WEBSEARCH_PROVIDER_NATIVE_SPEC,
args,
},
};
}
Then update provider-native expectations from tools?.WebSearch to:
expect(tools?.web_search).toMatchObject({
id: "anthropic.web_search_20260209",
type: "provider",
});
Keep the existing public client tool test:
expect(tools?.WebSearch).not.toMatchObject({
id: "anthropic.web_search_20260209",
type: "provider",
});
In runner.test.ts, keep tests that verify provider request bodies can contain private web_search, but rename descriptions to say internal native request:
it("keeps internal web_search for allowlisted Anthropic-compatible side requests", async () => {
...
});
In p12-tool-surface/main-and-explore/expect.json, change parent/explore expectations to no longer exclude WebSearch as out of scope. Expected final shape:
{
"expected": {
"parentTools": {
"contains": ["Agent", "WebSearch"],
"doesNotContain": ["Glob", "Grep", "GoalRead", "web_search"]
},
"exploreChildTools": {
"contains": ["Read", "Bash", "Glob", "Grep", "WebSearch"],
"doesNotContain": ["Agent", "Skill", "Write", "Edit", "ApplyPatch", "GoalRead", "web_search"]
}
}
}
Create apps/zcode-cli/tools/prompt-trajectory/testcases/websearch-client-tool/fixture.json:
{
"name": "websearch-client-tool",
"description": "WebSearch should be exposed as a public function tool in outer requests; provider-native web_search should only appear in the internal web_search_tool request.",
"turns": [
{
"user": "Search the web for current ZCode WebSearch behavior and cite sources."
}
],
"runtime": {
"mode": "build",
"workingDirectory": "/tmp/zcode-websearch-client-tool"
}
}
Create expect.json:
{
"description": "Inspect derived request bodies. The main turn exposes WebSearch and not web_search. The internal web_search_tool request exposes only web_search.",
"expected": {
"mainTurnTools": {
"contains": ["WebSearch"],
"doesNotContain": ["web_search"]
},
"internalWebSearchTools": {
"containsOnly": ["web_search"]
}
}
}
If prompt-trajectory cannot force a WebSearch tool call without live provider behavior, keep this testcase as a manual inspection fixture and rely on focused handler tests for the internal request.
Run:
pnpm --filter @zcode/adapters exec vitest run tests/websearch.test.ts tests/runner.test.ts
pnpm --filter @zcode/bootstrap^... build
pnpm --filter @zcode/bootstrap build
pnpm --filter @zcode/prompt-trajectory run:testcases -- --cases testcases/p12-tool-surface --out-root out/websearch-client-tool-p12
Expected:
web_search contracts to native helpers.WebSearch stays a regular function tool.WebSearch, not web_search.Files:
apps/zcode-cli/docs/design/v2/tool/README.mdapps/zcode-cli/docs/design/v2/model/http-proxy.mdapps/zcode-cli/docs/design/v2/compact/plan.mdapps/zcode-cli/docs/design/v2/loop/system-prompt-contract.mdapps/zcode-cli/docs/design/v2/loop/architecture.mdModify: apps/zcode-cli/docs/design/v2/tui-network-status-panel.md
[x] Step 6.1: Replace stale direct-provider-native wording
Run:
rg -n "direct provider-native|主请求.*provider-native|provider-native `web_search`|不注册本地 handler|不进入本地调度|ToolExecutor 不执行搜索" apps/zcode-cli/docs -g '*.md'
For every WebSearch hit, update wording to:
WebSearch is a public client-side wrapper tool. Its handler sends an internal model request whose only provider-native tool is `web_search`.
Keep docs that describe generic provider-native behavior or adapter internals if they are not claiming main-turn direct exposure.
Run:
pnpm --filter @zcode/core exec vitest run \
tests/websearch.test.ts \
tests/main-tool-pool.test.ts \
tests/subagent-explore.test.ts \
tests/scheduler.test.ts
pnpm --filter @zcode/adapters exec vitest run \
tests/websearch.test.ts \
tests/runner.test.ts
Expected: PASS.
Run:
CI=true pnpm typecheck
CI=true pnpm lint
Expected:
pnpm lint should exit 0. Existing warnings may remain if oxlint reports warnings without nonzero exit.pnpm typecheck may fail on the current baseline @zcode/shared export/type errors unrelated to WebSearch. If it fails, capture the first 20 error lines and confirm none reference files touched by this WebSearch implementation.
[x] Step 6.4: Manual runtime check
Status: current environment did not run a live external-provider smoke test because no throwaway native-search provider credentials were configured for this review pass. The runtime-equivalent check was completed with focused runtime tests plus prompt-trajectory recordings:
packages/core/tests/websearch.test.ts covers ToolCallStarted /
ToolCallResult, querySource: "web_search_tool", automatic internal
tool choice, provider-native args, and nested serverToolUse.webSearchRequests.test20260608-213225(未入库)
confirms outer main/Explore request bodies expose WebSearch and not
web_search.final3(未入库)confirms the
internal web_search_tool request exposes only web_search and the final
outer request receives a formatted WebSearch tool result.If a disposable real provider key is available, rerun this as a final smoke check with a provider that supports native web search and confirm:
tools[] includes WebSearch.tools[] does not include web_search.WebSearch pending/running/completed.querySource: "web_search_tool".tools[] contains only web_search.serverToolUse.webSearchRequests.WebSearch.web_search never appears in outer main/explore tools[].web_search and does not set toolChoice.query, allowed_domains, blocked_domains, maxUses.allowedDomains, blockedDomains, searchContextSize, numResults, safeSearch are not public provider-visible fields.WebSearch is read-only, concurrent safe, low-risk, no approval by default.WebSearch triggers normal ToolExecutor lifecycle and tool result replay.