mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 00:05:51 +00:00
- 重命名 ExecuteTool → ExecuteExtraTool,作为一等工具始终可用 - ToolSearchTool 输出改为纯文本(区分 core/deferred),移除 tool_reference blocks - 移除 modelSupportsToolReference() 及相关 GrowthBook 配置 - 移除 API 侧 defer_loading 字段和 tool search beta header 注入 - 简化 system prompt(工具使用指南从 ~120 行压缩到 ~10 行) - extractDiscoveredToolNames 支持文本格式解析(向后兼容旧 session 的 tool_reference) - 更新 promptEngineeringAudit 测试以匹配简化后的 prompt 结构 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
66 lines
2.7 KiB
TypeScript
66 lines
2.7 KiB
TypeScript
import { getFeatureValue_CACHED_MAY_BE_STALE } from 'src/services/analytics/growthbook.js'
|
|
import type { Tool } from 'src/Tool.js'
|
|
import { CORE_TOOLS } from 'src/constants/tools.js'
|
|
|
|
export { TOOL_SEARCH_TOOL_NAME } from './constants.js'
|
|
|
|
import { TOOL_SEARCH_TOOL_NAME } from './constants.js'
|
|
|
|
const PROMPT_HEAD = `Search for deferred tools by name or keyword.
|
|
|
|
`
|
|
|
|
// Matches isDeferredToolsDeltaEnabled in toolSearch.ts (not imported —
|
|
// toolSearch.ts imports from this file). When enabled: tools announced
|
|
// via system-reminder attachments. When disabled: prepended
|
|
// <available-deferred-tools> block (pre-gate behavior).
|
|
function getToolLocationHint(): string {
|
|
const deltaEnabled =
|
|
process.env.USER_TYPE === 'ant' ||
|
|
getFeatureValue_CACHED_MAY_BE_STALE('tengu_glacier_2xr', false)
|
|
return deltaEnabled
|
|
? 'Deferred tools appear by name in <system-reminder> messages.'
|
|
: 'Deferred tools appear by name in <available-deferred-tools> messages.'
|
|
}
|
|
|
|
const PROMPT_TAIL = ` Returns matching tool names.
|
|
|
|
ExecuteExtraTool is a first-class tool that is always available — you do NOT need to search for it. After this search returns tool names, call ExecuteExtraTool directly with {"tool_name": "<returned_name>", "params": {...}} to invoke any deferred tool.
|
|
|
|
Query forms:
|
|
- "select:CronCreate,Snip" — fetch these exact tools by name
|
|
- "discover:schedule cron job" — pure discovery, returns tool info (name, description) without loading. Use when you want to understand available tools before deciding which to invoke.
|
|
- "notebook jupyter" — keyword search, up to max_results best matches
|
|
- "+slack send" — require "slack" in the name, rank by remaining terms`
|
|
|
|
/**
|
|
* Check if a tool should be deferred (requires ToolSearch to load).
|
|
* A tool is deferred if it is NOT in CORE_TOOLS and does NOT have alwaysLoad: true.
|
|
* Core tools are always loaded — never deferred.
|
|
* All other tools (non-core built-in + all MCP tools) are deferred
|
|
* and must be discovered via ToolSearchTool / ExecuteExtraTool.
|
|
*/
|
|
export function isDeferredTool(tool: Tool): boolean {
|
|
// Explicit opt-out via _meta['anthropic/alwaysLoad']
|
|
if (tool.alwaysLoad === true) return false
|
|
|
|
// Core tools are always loaded — never deferred
|
|
if (CORE_TOOLS.has(tool.name)) return false
|
|
|
|
// Everything else (non-core built-in + all MCP tools) is deferred
|
|
return true
|
|
}
|
|
|
|
/**
|
|
* Format one deferred-tool line for the <available-deferred-tools> user
|
|
* message. Search hints (tool.searchHint) are not rendered — the
|
|
* hints A/B (exp_xenhnnmn0smrx4, stopped Mar 21) showed no benefit.
|
|
*/
|
|
export function formatDeferredToolLine(tool: Tool): string {
|
|
return tool.name
|
|
}
|
|
|
|
export function getPrompt(): string {
|
|
return PROMPT_HEAD + getToolLocationHint() + PROMPT_TAIL
|
|
}
|