返回 CodeWhale
tools.ts
根目录 / web / lib / content / tools.ts
1 import type { CapabilityClaim, CapabilityContext } from "../capabilities";
2 import { showsReleasedText, sourcePlacement } from "../docs-release";
3 import { FEATURE_CATALOGUE, type Feature } from "../features";
4 import type { LocalizedText } from "./vocabulary";
5
6 export interface ToolRow {
7 name: string;
8 detail: LocalizedText;
9 until?: CapabilityClaim;
10 capability?: CapabilityClaim;
11 }
12
13 export const EAGER_SET_CLAIM = { feature: "present-handoff" } as const;
14
15 export const TOOLS_COPY = {
16 metaTitle: { en: "Built-in tools · Codewhale Docs", zh: "内置工具 · Codewhale 文档" },
17 metaDescription: { en: "Core tools, on-demand discovery, and tool names in saved transcripts.", zh: "核心工具、按需发现,以及已保存会话记录中的工具名称。" },
18 title: { en: "Built-in tools", zh: "内置工具" },
19 lead: { en: "In the published release, every session starts with thirteen native tools for reading, editing, running commands, and delegating, plus tool_search. Codewhale loads specialized tools only when a task needs them, and your mode and approval setting still apply to all of them.", zh: "在已发布版本中,每个会话一开始就带着十三个原生工具,用于阅读、修改、运行命令和委派任务,外加 tool_search。专用工具只在任务需要时才加载,而你的模式和审批设置对所有工具都同样有效。" },
20 leadSource: { en: "Every session starts with twelve native tools for reading, editing, running commands, and delegating, plus one discovery tool: execute_tools in code mode, or tool_search where code mode is off or not offered.", zh: "每个会话一开始就带着十二个原生工具,用于阅读、修改、运行命令和委派任务,外加一个发现工具:代码模式下是 execute_tools,代码模式关闭或不提供时是 tool_search。" },
21 reference: { en: "Tool contract and design rationale", zh: "工具约定与设计说明" },
22 rows: [
23 { name: "read", detail: { en: "path · offset? · limit?", zh: "path · offset? · limit?" } },
24 { name: "write", detail: { en: "path · content", zh: "path · content" } },
25 { name: "edit", detail: { en: "path · edits", zh: "path · edits" } },
26 { name: "list_dir", detail: { en: "List a workspace directory.", zh: "列出工作区目录。" } },
27 { name: "file_search", detail: { en: "Find workspace files by name, path, or glob pattern.", zh: "按文件名、路径或 glob 通配模式查找工作区文件。" } },
28 { name: "bash", detail: { en: "command · timeout?", zh: "command · timeout?" } },
29 { name: "agent", detail: { en: "Delegate work to child agents.", zh: "把工作委派给子 Agent。" } },
30 { name: "todo_write", detail: { en: "Replace the task list with content and status entries.", zh: "用包含内容与状态的条目替换任务列表。" } },
31 { name: "create_goal · get_goal · update_goal", detail: { en: "Create, inspect and update the active goal.", zh: "创建、查看与更新当前目标。" } },
32 { name: "task_shell_wait", detail: { en: "Poll or stop a background shell task by task_id.", zh: "按 task_id 轮询或停止后台 shell 任务。" } },
33 { name: "load_skill", detail: { en: "Load a skill by exact name, or pass query to search the catalogue.", zh: "按确切名称加载技能,或传入 query 搜索技能目录。" } },
34 { name: "tool_search", detail: { en: "Discover policy-allowed tools. Each child has its own search and activation cache.", zh: "发现策略允许的工具。每个子 Agent 拥有独立的搜索与激活缓存。" } },
35 { name: "workflow", detail: { en: "Plan, run and inspect multi-agent phases with dependencies and completion checks.", zh: "规划、运行并查看带依赖与完成检查的多智能体阶段。" }, until: EAGER_SET_CLAIM },
36 { name: "Git · Run · tasks · remember · Web · MCP · plugins", detail: { en: "Deferred: loaded by tool_search only when policy permits.", zh: "延迟加载:仅在策略允许时由 tool_search 加载。" }, until: EAGER_SET_CLAIM },
37 { name: "grep_files", detail: { en: "Find matching content in workspace files.", zh: "查找工作区文件中匹配的内容。" }, capability: EAGER_SET_CLAIM },
38 { name: "present", detail: { en: "Hand off 1–32 existing files with SHA-256 receipts; read-only.", zh: "以 SHA-256 回执交付 1–32 个现有文件;只读。" }, capability: EAGER_SET_CLAIM },
39 { name: "workflow · context_archive_search · Git · Run · tasks · remember · Web · MCP · plugins", detail: { en: "Deferred: discovered inside execute_tools (or loaded by tool_search where offered) only when policy permits. context_archive_search searches and reads compacted history, with credentials masked.", zh: "延迟加载:仅在策略允许时可在 execute_tools 内发现(或在提供 tool_search 的表面上由其加载)。context_archive_search 用于搜索并读取被压缩替换的历史内容,凭据会被遮蔽。" }, capability: EAGER_SET_CLAIM },
40 { name: "16 names / 32 KiB", detail: { en: "Conversation toolbox cache; independent per child and revalidated every turn.", zh: "会话工具箱缓存;每个子 Agent 独立,每轮重新校验。" } },
41 { name: "Web search/fetch", detail: { en: "Scout and Reviewer children can discover these without gaining mutation or arbitrary network authority.", zh: "侦察与审查子 Agent 可发现这些工具,但不会因此获得写入或任意网络权限。" } },
42 { name: "MCP", detail: { en: "mcp_<server>_<tool> — registered from ~/.codewhale/mcp.json.", zh: "mcp_<server>_<tool>——从 ~/.codewhale/mcp.json 注册。" } },
43 ],
44 compatibilityTitle: { en: "Saved transcripts and protocol clients", zh: "已保存的会话记录与协议客户端" },
45 lspTitle: { en: "Read language-server diagnostics", zh: "读取语言服务器诊断" },
46 lspBody: { en: "After file edits, LSP diagnostics can report errors to the agent. Add a custom server by file extension under [lsp.custom]; install the server executable separately.", zh: "文件修改后,LSP 诊断可向智能体报告错误。通过 [lsp.custom] 按扩展名添加自定义服务器;服务器可执行文件需要单独安装。" },
47 lspDocs: { en: "PHP and custom LSP server setup", zh: "PHP 与自定义 LSP 服务器设置" },
48 compatibility: { en: "Protocol clients can call read_file, write_file and edit_file by name. Model catalogs use read, write and edit. Saved transcripts keep their original tool names.", zh: "协议客户端可以按名称调用 read_file、write_file 和 edit_file。模型工具目录使用 read、write 和 edit。已保存的会话记录会保留原有的工具名称。" },
49 } satisfies {
50 metaTitle: LocalizedText;
51 metaDescription: LocalizedText;
52 title: LocalizedText;
53 lead: LocalizedText;
54 reference: LocalizedText;
55 leadSource: LocalizedText;
56 rows: ToolRow[];
57 compatibilityTitle: LocalizedText;
58 lspTitle: LocalizedText;
59 lspBody: LocalizedText;
60 lspDocs: LocalizedText;
61 compatibility: LocalizedText;
62 };
63
64 export function toolRowsFor(context: CapabilityContext, features: readonly Feature[] = FEATURE_CATALOGUE.features): { body: ToolRow[]; source: ToolRow[]; released: boolean } {
65 const placement = (row: ToolRow) => (row.capability ? sourcePlacement(row.capability, context, features) : "body");
66 return {
67 body: TOOLS_COPY.rows.filter((row) => (row.capability ? placement(row) === "body" : showsReleasedText(row.until, context, features))),
68 source: TOOLS_COPY.rows.filter((row) => row.capability && placement(row) === "source"),
69 released: showsReleasedText(EAGER_SET_CLAIM, context, features),
70 };
71 }
72
72 lines TYPESCRIPT