mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-21 07:45:52 +00:00
* feat: 新增 cloud-artifacts 包(Cloudflare Worker HTML artifact 托管)
POST /upload 鉴权上传 HTML 到 R2 返回 hash URL,GET /<7d|30d>/<id>.html
由 Worker 代理读取并直出 text/html。R2 lifecycle rule 自动 7/30 天删除。
独立服务,不被主 CLI 引用(类似 packages/remote-control-server/ 定位)。
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* docs: 完善 cloud-artifacts 文档并统一出口域名
- CLAUDE.md 加 cloud-artifacts 到 Workspace Packages 表和新增 HTML Artifact Hosting 段落
- docs.json 注册 cloud-artifacts 到运行模式 group
- README 加 Quickstart、架构图(含 Deno Deploy 代理层)、Security Considerations、Troubleshooting
- 统一出口域名为 https://cloud-artifacts.claude-code-best.win(wrangler.toml PUBLIC_URL、test.sh 默认 WORKER_URL、所有文档示例)
- test.sh expect() 加 [via body] fallback:经 Deno Deploy 代理(status 抹平为 200)时按 body 的 error 字段断言
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* docs: 修正 CLAUDE.md cloud-artifacts 引用死链
之前指向不存在的 docs/features/cloud-artifacts.md(用户未注册到 docs.json),
改为指向已存在的 packages/cloud-artifacts/README.md,并补充生产出口域名
与 Deno Deploy status 抹平副作用的说明。
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* chore: 同步 cloud-artifacts 测试默认 TOKEN 到新值
用户已通过 wrangler secret put 把生产 TOKEN 改为 claude-code-best,
test.sh 的默认值(之前用旧 token 作 fallback)和注释示例同步更新。
现在直接 bash scripts/test.sh 即可跑通(无需显式传 TOKEN)。
src/index.ts 不依赖具体 token 值(只读 env.TOKEN 做比较),
wrangler.toml 不含 secret,README/.dev.vars.example 用 <your-token>
占位符故无需改。
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* docs: add artifacts feature implementation plan
* feat(artifact): add cloud-artifacts config with token/URL defaults
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* feat(artifact): add HTTP client with body-error parsing
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* feat(artifact): add tool name, description, and prompt
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* feat(artifact): add buildTool definition with file validation
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* test(artifact): add end-to-end tool tests for upload/error paths
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* feat(artifact): export ArtifactTool from builtin-tools barrel
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* feat(artifact): register ArtifactTool in tools list
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* feat(artifact): add /use-artifacts bundled skill
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* feat(artifact): add extractArtifacts message scanner
Scans Message[] for artifact tool_use/tool_result pairs, parses URL/id/expires
from the upload response string, and returns ArtifactInfo[] newest-first.
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* fix(artifact): scanner type narrowing and url regex
- Use double assertion (`as unknown as Record<string, unknown>`) at lines 30
and 90 to fix TS2352 per project convention
- Tighten URL_REGEX to avoid capturing trailing punctuation (parens,
quotes, commas) when URL is embedded in text
- Add test case for array-form tool_result content path
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* feat(artifact): add ArtifactsMenu Ink component
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* feat(artifact): add /artifacts slash command entry
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* feat(artifact): register /artifacts command
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* fix(artifact): use setClipboard instead of pbcopy for cross-platform support
* fix(artifact): drop userFacingName override so display matches /artifacts
* fix(rcs): add resJson helper to resolve strict mode type errors in tests
Hono Response.json() returns Promise<unknown> under strict TypeScript,
causing 121 TS errors across middleware and routes test files.
Co-Authored-By: glm-5-turbo <zai-org@claude-code-best.win>
* fix(cloud-artifacts): add type stubs so tsc passes without worker-configuration.d.ts
The wrangler-generated worker-configuration.d.ts is gitignored, causing CI to
fail with missing ExportedHandler/Env/R2Bucket types. This file provides minimal
stubs for all Cloudflare Workers types used by the artifact upload Worker.
Co-Authored-By: glm-5-turbo <zai-org@claude-code-best.win>
* fix(query): shallow-copy messages before stripping toolUseResult
Previously the per-query cleanup mutated messagesForQuery entries in
place via `delete msg.toolUseResult`. Those entries are references
shared with mutableMessages (UI state), so the delete stripped the
field from the live message object. The next query can start within
milliseconds of tool_result creation — before the React UI commit
lands — so UserToolSuccessMessage's `!message.toolUseResult` check
returned null and tool.renderToolResultMessage was never called,
leaving tool-result rows blank.
Map to a stripped copy instead so mutableMessages keeps the original
for the UI. Downstream API transformations (applyToolResultBudget,
snip, microcompact) already build new arrays via .map(), so they
compose cleanly with this copy.
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* feat(artifact): show uploaded URL inline below ExecuteExtraTool
Deferred tools (shouldDefer: true) are invoked via SearchExtraTools →
ExecuteExtraTool, so their tool_result rows used to render blank —
the UI looked up ExecuteExtraTool, which had no renderToolResultMessage,
and returned null. Add a generic delegation in ExecuteTool that forwards
renderToolResultMessage to the inner tool when it defines one, unwrapping
the { result, tool_name } envelope and the params from the input shape.
All 28 deferred tools can now render their own UI by defining
renderToolResultMessage.
For ArtifactTool specifically, render the uploaded URL as an OSC 8
hyperlink (Link component) in warning color so it's visually prominent,
with the expiry timestamp on a second line and a separate error branch.
Also add `error: z.string().optional()` to outputSchema — zod's default
strip mode was dropping the field, so error states never reached the UI.
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
* fix(cloud-artifacts): make Env stubs actually take effect in CI
The previous stub file (2e29e362) wrapped `interface Env` in
`declare global { ... }`, but the file has no top-level import/export so
it's a script, not a module. TS2669 forbids `declare global` in scripts,
and in .d.ts files that error is silently swallowed — so the Env stubs
were never merged into the global scope. Locally typecheck passed only
because worker-configuration.d.ts (gitignored) provided Env separately;
in CI / fresh clones, `BUCKET`, `MAX_BYTES`, `DEFAULT_TTL_DAYS`,
`PUBLIC_URL` were all missing on Env.
Drop the wrapper. Top-level `interface Env` in a script .d.ts is already
global ambient and merges with worker-configuration.d.ts via interface
declaration merging, so both environments typecheck cleanly.
Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
---------
Co-authored-by: glm-5.2 <zai-org@claude-code-best.win>
423 lines
20 KiB
TypeScript
423 lines
20 KiB
TypeScript
// biome-ignore-all assist/source/organizeImports: ANT-ONLY import markers must not be reordered
|
|
import { toolMatchesName, type Tool, type Tools } from './Tool.js'
|
|
import { AgentTool } from '@claude-code-best/builtin-tools/tools/AgentTool/AgentTool.js'
|
|
import { SkillTool } from '@claude-code-best/builtin-tools/tools/SkillTool/SkillTool.js'
|
|
import { BashTool } from '@claude-code-best/builtin-tools/tools/BashTool/BashTool.js'
|
|
import { FileEditTool } from '@claude-code-best/builtin-tools/tools/FileEditTool/FileEditTool.js'
|
|
import { FileReadTool } from '@claude-code-best/builtin-tools/tools/FileReadTool/FileReadTool.js'
|
|
import { FileWriteTool } from '@claude-code-best/builtin-tools/tools/FileWriteTool/FileWriteTool.js'
|
|
import { GlobTool } from '@claude-code-best/builtin-tools/tools/GlobTool/GlobTool.js'
|
|
import { NotebookEditTool } from '@claude-code-best/builtin-tools/tools/NotebookEditTool/NotebookEditTool.js'
|
|
import { WebFetchTool } from '@claude-code-best/builtin-tools/tools/WebFetchTool/WebFetchTool.js'
|
|
import { TaskStopTool } from '@claude-code-best/builtin-tools/tools/TaskStopTool/TaskStopTool.js'
|
|
import { BriefTool } from '@claude-code-best/builtin-tools/tools/BriefTool/BriefTool.js'
|
|
// Dead code elimination: conditional import for ant-only tools
|
|
/* eslint-disable custom-rules/no-process-env-top-level, @typescript-eslint/no-require-imports */
|
|
const REPLTool =
|
|
process.env.USER_TYPE === 'ant'
|
|
? require('@claude-code-best/builtin-tools/tools/REPLTool/REPLTool.js')
|
|
.REPLTool
|
|
: null
|
|
const SuggestBackgroundPRTool =
|
|
process.env.USER_TYPE === 'ant'
|
|
? require('@claude-code-best/builtin-tools/tools/SuggestBackgroundPRTool/SuggestBackgroundPRTool.js')
|
|
.SuggestBackgroundPRTool
|
|
: null
|
|
const SleepTool =
|
|
feature('PROACTIVE') || feature('KAIROS')
|
|
? require('@claude-code-best/builtin-tools/tools/SleepTool/SleepTool.js')
|
|
.SleepTool
|
|
: null
|
|
const cronTools = [
|
|
require('@claude-code-best/builtin-tools/tools/ScheduleCronTool/CronCreateTool.js')
|
|
.CronCreateTool,
|
|
require('@claude-code-best/builtin-tools/tools/ScheduleCronTool/CronDeleteTool.js')
|
|
.CronDeleteTool,
|
|
require('@claude-code-best/builtin-tools/tools/ScheduleCronTool/CronListTool.js')
|
|
.CronListTool,
|
|
]
|
|
const RemoteTriggerTool = feature('AGENT_TRIGGERS_REMOTE')
|
|
? require('@claude-code-best/builtin-tools/tools/RemoteTriggerTool/RemoteTriggerTool.js')
|
|
.RemoteTriggerTool
|
|
: null
|
|
const MonitorTool = feature('MONITOR_TOOL')
|
|
? require('@claude-code-best/builtin-tools/tools/MonitorTool/MonitorTool.js')
|
|
.MonitorTool
|
|
: null
|
|
const SendUserFileTool = feature('KAIROS')
|
|
? require('@claude-code-best/builtin-tools/tools/SendUserFileTool/SendUserFileTool.js')
|
|
.SendUserFileTool
|
|
: null
|
|
const PushNotificationTool =
|
|
feature('KAIROS') || feature('KAIROS_PUSH_NOTIFICATION')
|
|
? require('@claude-code-best/builtin-tools/tools/PushNotificationTool/PushNotificationTool.js')
|
|
.PushNotificationTool
|
|
: null
|
|
const SubscribePRTool = feature('KAIROS_GITHUB_WEBHOOKS')
|
|
? require('@claude-code-best/builtin-tools/tools/SubscribePRTool/SubscribePRTool.js')
|
|
.SubscribePRTool
|
|
: null
|
|
/* eslint-enable custom-rules/no-process-env-top-level, @typescript-eslint/no-require-imports */
|
|
import { TaskOutputTool } from '@claude-code-best/builtin-tools/tools/TaskOutputTool/TaskOutputTool.js'
|
|
import { WebSearchTool } from '@claude-code-best/builtin-tools/tools/WebSearchTool/WebSearchTool.js'
|
|
import { TodoWriteTool } from '@claude-code-best/builtin-tools/tools/TodoWriteTool/TodoWriteTool.js'
|
|
import { ExitPlanModeV2Tool } from '@claude-code-best/builtin-tools/tools/ExitPlanModeTool/ExitPlanModeV2Tool.js'
|
|
import { ArtifactTool } from '@claude-code-best/builtin-tools/tools/ArtifactTool/ArtifactTool.js'
|
|
import { TestingPermissionTool } from '@claude-code-best/builtin-tools/tools/testing/TestingPermissionTool.js'
|
|
import { GrepTool } from '@claude-code-best/builtin-tools/tools/GrepTool/GrepTool.js'
|
|
import { TungstenTool } from '@claude-code-best/builtin-tools/tools/TungstenTool/TungstenTool.js'
|
|
// Lazy require to break circular dependency: tools.ts -> TeamCreateTool/TeamDeleteTool -> ... -> tools.ts
|
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
const getTeamCreateTool = () =>
|
|
require('@claude-code-best/builtin-tools/tools/TeamCreateTool/TeamCreateTool.js')
|
|
.TeamCreateTool as typeof import('@claude-code-best/builtin-tools/tools/TeamCreateTool/TeamCreateTool.js').TeamCreateTool
|
|
const getTeamDeleteTool = () =>
|
|
require('@claude-code-best/builtin-tools/tools/TeamDeleteTool/TeamDeleteTool.js')
|
|
.TeamDeleteTool as typeof import('@claude-code-best/builtin-tools/tools/TeamDeleteTool/TeamDeleteTool.js').TeamDeleteTool
|
|
const getSendMessageTool = () =>
|
|
require('@claude-code-best/builtin-tools/tools/SendMessageTool/SendMessageTool.js')
|
|
.SendMessageTool as typeof import('@claude-code-best/builtin-tools/tools/SendMessageTool/SendMessageTool.js').SendMessageTool
|
|
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
import { AskUserQuestionTool } from '@claude-code-best/builtin-tools/tools/AskUserQuestionTool/AskUserQuestionTool.js'
|
|
import { LSPTool } from '@claude-code-best/builtin-tools/tools/LSPTool/LSPTool.js'
|
|
import { ListMcpResourcesTool } from '@claude-code-best/builtin-tools/tools/ListMcpResourcesTool/ListMcpResourcesTool.js'
|
|
import { ReadMcpResourceTool } from '@claude-code-best/builtin-tools/tools/ReadMcpResourceTool/ReadMcpResourceTool.js'
|
|
import { SearchExtraToolsTool } from '@claude-code-best/builtin-tools/tools/SearchExtraToolsTool/SearchExtraToolsTool.js'
|
|
import { ExecuteTool } from '@claude-code-best/builtin-tools/tools/ExecuteTool/ExecuteTool.js'
|
|
import { EnterPlanModeTool } from '@claude-code-best/builtin-tools/tools/EnterPlanModeTool/EnterPlanModeTool.js'
|
|
import { EnterWorktreeTool } from '@claude-code-best/builtin-tools/tools/EnterWorktreeTool/EnterWorktreeTool.js'
|
|
import { ExitWorktreeTool } from '@claude-code-best/builtin-tools/tools/ExitWorktreeTool/ExitWorktreeTool.js'
|
|
import { ConfigTool } from '@claude-code-best/builtin-tools/tools/ConfigTool/ConfigTool.js'
|
|
const GoalTool = feature('GOAL')
|
|
? require('@claude-code-best/builtin-tools/tools/GoalTool/GoalTool.js')
|
|
.GoalTool
|
|
: null
|
|
import { LocalMemoryRecallTool } from '@claude-code-best/builtin-tools/tools/LocalMemoryRecallTool/LocalMemoryRecallTool.js'
|
|
import { VaultHttpFetchTool } from '@claude-code-best/builtin-tools/tools/VaultHttpFetchTool/VaultHttpFetchTool.js'
|
|
import { TaskCreateTool } from '@claude-code-best/builtin-tools/tools/TaskCreateTool/TaskCreateTool.js'
|
|
import { TaskGetTool } from '@claude-code-best/builtin-tools/tools/TaskGetTool/TaskGetTool.js'
|
|
import { TaskUpdateTool } from '@claude-code-best/builtin-tools/tools/TaskUpdateTool/TaskUpdateTool.js'
|
|
import { TaskListTool } from '@claude-code-best/builtin-tools/tools/TaskListTool/TaskListTool.js'
|
|
import uniqBy from 'lodash-es/uniqBy.js'
|
|
import { isSearchExtraToolsEnabledOptimistic } from './utils/searchExtraTools.js'
|
|
import { isTodoV2Enabled } from './utils/tasks.js'
|
|
// Dead code elimination: conditional import for CLAUDE_CODE_VERIFY_PLAN
|
|
/* eslint-disable custom-rules/no-process-env-top-level, @typescript-eslint/no-require-imports */
|
|
const VerifyPlanExecutionTool =
|
|
process.env.CLAUDE_CODE_VERIFY_PLAN === 'true'
|
|
? require('@claude-code-best/builtin-tools/tools/VerifyPlanExecutionTool/VerifyPlanExecutionTool.js')
|
|
.VerifyPlanExecutionTool
|
|
: null
|
|
/* eslint-enable custom-rules/no-process-env-top-level, @typescript-eslint/no-require-imports */
|
|
import { SYNTHETIC_OUTPUT_TOOL_NAME } from '@claude-code-best/builtin-tools/tools/SyntheticOutputTool/SyntheticOutputTool.js'
|
|
export {
|
|
ALL_AGENT_DISALLOWED_TOOLS,
|
|
CUSTOM_AGENT_DISALLOWED_TOOLS,
|
|
ASYNC_AGENT_ALLOWED_TOOLS,
|
|
COORDINATOR_MODE_ALLOWED_TOOLS,
|
|
} from './constants/tools.js'
|
|
import { feature } from 'bun:bundle'
|
|
// Dead code elimination: conditional import for OVERFLOW_TEST_TOOL
|
|
/* eslint-disable custom-rules/no-process-env-top-level, @typescript-eslint/no-require-imports */
|
|
const OverflowTestTool = feature('OVERFLOW_TEST_TOOL')
|
|
? require('@claude-code-best/builtin-tools/tools/OverflowTestTool/OverflowTestTool.js')
|
|
.OverflowTestTool
|
|
: null
|
|
const CtxInspectTool = feature('CONTEXT_COLLAPSE')
|
|
? require('@claude-code-best/builtin-tools/tools/CtxInspectTool/CtxInspectTool.js')
|
|
.CtxInspectTool
|
|
: null
|
|
const TerminalCaptureTool = feature('TERMINAL_PANEL')
|
|
? require('@claude-code-best/builtin-tools/tools/TerminalCaptureTool/TerminalCaptureTool.js')
|
|
.TerminalCaptureTool
|
|
: null
|
|
const WebBrowserTool = feature('WEB_BROWSER_TOOL')
|
|
? require('@claude-code-best/builtin-tools/tools/WebBrowserTool/WebBrowserTool.js')
|
|
.WebBrowserTool
|
|
: null
|
|
const coordinatorModeModule = feature('COORDINATOR_MODE')
|
|
? (require('./coordinator/coordinatorMode.js') as typeof import('./coordinator/coordinatorMode.js'))
|
|
: null
|
|
const SnipTool = feature('HISTORY_SNIP')
|
|
? require('@claude-code-best/builtin-tools/tools/SnipTool/SnipTool.js')
|
|
.SnipTool
|
|
: null
|
|
const DiscoverSkillsTool = feature('EXPERIMENTAL_SKILL_SEARCH')
|
|
? require('@claude-code-best/builtin-tools/tools/DiscoverSkillsTool/DiscoverSkillsTool.js')
|
|
.DiscoverSkillsTool
|
|
: null
|
|
const ReviewArtifactTool = feature('REVIEW_ARTIFACT')
|
|
? require('@claude-code-best/builtin-tools/tools/ReviewArtifactTool/ReviewArtifactTool.js')
|
|
.ReviewArtifactTool
|
|
: null
|
|
const ListPeersTool = feature('UDS_INBOX')
|
|
? require('@claude-code-best/builtin-tools/tools/ListPeersTool/ListPeersTool.js')
|
|
.ListPeersTool
|
|
: null
|
|
const WorkflowTool = feature('WORKFLOW_SCRIPTS')
|
|
? require('./workflow/wiring.js').createWorkflowToolCore()
|
|
: null
|
|
/* eslint-enable custom-rules/no-process-env-top-level, @typescript-eslint/no-require-imports */
|
|
import type { ToolPermissionContext } from './Tool.js'
|
|
import { getDenyRuleForTool } from './utils/permissions/permissions.js'
|
|
import { hasEmbeddedSearchTools } from './utils/embeddedTools.js'
|
|
import { isEnvTruthy } from './utils/envUtils.js'
|
|
import { isPowerShellToolEnabled } from './utils/shell/shellToolUtils.js'
|
|
import { isAgentSwarmsEnabled } from './utils/agentSwarmsEnabled.js'
|
|
import { isWorktreeModeEnabled } from './utils/worktreeModeEnabled.js'
|
|
import {
|
|
REPL_TOOL_NAME,
|
|
REPL_ONLY_TOOLS,
|
|
isReplModeEnabled,
|
|
} from '@claude-code-best/builtin-tools/tools/REPLTool/constants.js'
|
|
export { REPL_ONLY_TOOLS }
|
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
const getPowerShellTool = () => {
|
|
if (!isPowerShellToolEnabled()) return null
|
|
return (
|
|
require('@claude-code-best/builtin-tools/tools/PowerShellTool/PowerShellTool.js') as typeof import('@claude-code-best/builtin-tools/tools/PowerShellTool/PowerShellTool.js')
|
|
).PowerShellTool
|
|
}
|
|
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
|
|
/**
|
|
* Predefined tool presets that can be used with --tools flag
|
|
*/
|
|
export const TOOL_PRESETS = ['default'] as const
|
|
|
|
export type ToolPreset = (typeof TOOL_PRESETS)[number]
|
|
|
|
export function parseToolPreset(preset: string): ToolPreset | null {
|
|
const presetString = preset.toLowerCase()
|
|
if (!TOOL_PRESETS.includes(presetString as ToolPreset)) {
|
|
return null
|
|
}
|
|
return presetString as ToolPreset
|
|
}
|
|
|
|
/**
|
|
* Get the list of tool names for a given preset
|
|
* Filters out tools that are disabled via isEnabled() check
|
|
* @param preset The preset name
|
|
* @returns Array of tool names
|
|
*/
|
|
export function getToolsForDefaultPreset(): string[] {
|
|
const tools = getAllBaseTools()
|
|
const isEnabled = tools.map(tool => tool.isEnabled())
|
|
return tools.filter((_, i) => isEnabled[i]).map(tool => tool.name)
|
|
}
|
|
|
|
/**
|
|
* Get the complete exhaustive list of all tools that could be available
|
|
* in the current environment (respecting process.env flags).
|
|
* This is the source of truth for ALL tools.
|
|
*/
|
|
/**
|
|
* NOTE: This MUST stay in sync with https://console.statsig.com/4aF3Ewatb6xPVpCwxb5nA3/dynamic_configs/claude_code_global_system_caching, in order to cache the system prompt across users.
|
|
*/
|
|
export function getAllBaseTools(): Tools {
|
|
return [
|
|
AgentTool,
|
|
TaskOutputTool,
|
|
BashTool,
|
|
// Ant-native builds have bfs/ugrep embedded in the bun binary (same ARGV0
|
|
// trick as ripgrep). When available, find/grep in Claude's shell are aliased
|
|
// to these fast tools, so the dedicated Glob/Grep tools are unnecessary.
|
|
...(hasEmbeddedSearchTools() ? [] : [GlobTool, GrepTool]),
|
|
ExitPlanModeV2Tool,
|
|
FileReadTool,
|
|
FileEditTool,
|
|
FileWriteTool,
|
|
NotebookEditTool,
|
|
ArtifactTool,
|
|
WebFetchTool,
|
|
TodoWriteTool,
|
|
WebSearchTool,
|
|
TaskStopTool,
|
|
AskUserQuestionTool,
|
|
SkillTool,
|
|
EnterPlanModeTool,
|
|
LocalMemoryRecallTool,
|
|
VaultHttpFetchTool,
|
|
...(process.env.USER_TYPE === 'ant' ? [ConfigTool] : []),
|
|
...(GoalTool ? [GoalTool] : []),
|
|
...(process.env.USER_TYPE === 'ant' ? [TungstenTool] : []),
|
|
...(SuggestBackgroundPRTool ? [SuggestBackgroundPRTool] : []),
|
|
...(WebBrowserTool ? [WebBrowserTool] : []),
|
|
...(isTodoV2Enabled()
|
|
? [TaskCreateTool, TaskGetTool, TaskUpdateTool, TaskListTool]
|
|
: []),
|
|
...(OverflowTestTool ? [OverflowTestTool] : []),
|
|
...(CtxInspectTool ? [CtxInspectTool] : []),
|
|
...(TerminalCaptureTool ? [TerminalCaptureTool] : []),
|
|
...(isEnvTruthy(process.env.ENABLE_LSP_TOOL) ? [LSPTool] : []),
|
|
...(isWorktreeModeEnabled() ? [EnterWorktreeTool, ExitWorktreeTool] : []),
|
|
getSendMessageTool(),
|
|
...(ListPeersTool ? [ListPeersTool] : []),
|
|
getTeamCreateTool(),
|
|
getTeamDeleteTool(),
|
|
...(VerifyPlanExecutionTool ? [VerifyPlanExecutionTool] : []),
|
|
...(process.env.USER_TYPE === 'ant' && REPLTool ? [REPLTool] : []),
|
|
...(WorkflowTool ? [WorkflowTool] : []),
|
|
...(SleepTool ? [SleepTool] : []),
|
|
...cronTools,
|
|
...(RemoteTriggerTool ? [RemoteTriggerTool] : []),
|
|
...(MonitorTool ? [MonitorTool] : []),
|
|
BriefTool,
|
|
...(SendUserFileTool ? [SendUserFileTool] : []),
|
|
...(PushNotificationTool ? [PushNotificationTool] : []),
|
|
...(SubscribePRTool ? [SubscribePRTool] : []),
|
|
...(ReviewArtifactTool ? [ReviewArtifactTool] : []),
|
|
...(getPowerShellTool() ? [getPowerShellTool()] : []),
|
|
...(SnipTool ? [SnipTool] : []),
|
|
...(DiscoverSkillsTool ? [DiscoverSkillsTool] : []),
|
|
...(process.env.NODE_ENV === 'test' ? [TestingPermissionTool] : []),
|
|
ListMcpResourcesTool,
|
|
ReadMcpResourceTool,
|
|
// Include SearchExtraToolsTool when tool search might be enabled (optimistic check)
|
|
// The actual decision to defer tools happens at request time in claude.ts
|
|
...(isSearchExtraToolsEnabledOptimistic() ? [SearchExtraToolsTool] : []),
|
|
// ExecuteExtraTool (ExecuteTool) is a first-class tool — always available, not deferred.
|
|
// Models use it to invoke deferred tools discovered via SearchExtraTools.
|
|
ExecuteTool,
|
|
]
|
|
}
|
|
|
|
/**
|
|
* Filters out tools that are blanket-denied by the permission context.
|
|
* A tool is filtered out if there's a deny rule matching its name with no
|
|
* ruleContent (i.e., a blanket deny for that tool).
|
|
*
|
|
* Uses the same matcher as the runtime permission check (step 1a), so MCP
|
|
* server-prefix rules like `mcp__server` strip all tools from that server
|
|
* before the model sees them — not just at call time.
|
|
*/
|
|
export function filterToolsByDenyRules<
|
|
T extends {
|
|
name: string
|
|
mcpInfo?: { serverName: string; toolName: string }
|
|
},
|
|
>(tools: readonly T[], permissionContext: ToolPermissionContext): T[] {
|
|
return tools.filter(tool => !getDenyRuleForTool(permissionContext, tool))
|
|
}
|
|
|
|
export const getTools = (permissionContext: ToolPermissionContext): Tools => {
|
|
// Simple mode: only Bash, Read, and Edit tools
|
|
if (isEnvTruthy(process.env.CLAUDE_CODE_SIMPLE)) {
|
|
// --bare + REPL mode: REPL wraps Bash/Read/Edit/etc inside the VM, so
|
|
// return REPL instead of the raw primitives. Matches the non-bare path
|
|
// below which also hides REPL_ONLY_TOOLS when REPL is enabled.
|
|
if (isReplModeEnabled() && REPLTool) {
|
|
const replSimple: Tool[] = [REPLTool]
|
|
if (
|
|
feature('COORDINATOR_MODE') &&
|
|
coordinatorModeModule?.isCoordinatorMode()
|
|
) {
|
|
replSimple.push(TaskStopTool, getSendMessageTool())
|
|
}
|
|
return filterToolsByDenyRules(replSimple, permissionContext)
|
|
}
|
|
const simpleTools: Tool[] = [BashTool, FileReadTool, FileEditTool]
|
|
// When coordinator mode is also active, include AgentTool and TaskStopTool
|
|
// so the coordinator gets Task+TaskStop (via useMergedTools filtering) and
|
|
// workers get Bash/Read/Edit (via filterToolsForAgent filtering).
|
|
if (
|
|
feature('COORDINATOR_MODE') &&
|
|
coordinatorModeModule?.isCoordinatorMode()
|
|
) {
|
|
simpleTools.push(AgentTool, TaskStopTool, getSendMessageTool())
|
|
}
|
|
return filterToolsByDenyRules(simpleTools, permissionContext)
|
|
}
|
|
|
|
// Get all base tools and filter out special tools that get added conditionally
|
|
const specialTools = new Set([
|
|
ListMcpResourcesTool.name,
|
|
ReadMcpResourceTool.name,
|
|
SYNTHETIC_OUTPUT_TOOL_NAME,
|
|
])
|
|
|
|
const tools = getAllBaseTools().filter(tool => !specialTools.has(tool.name))
|
|
|
|
// Filter out tools that are denied by the deny rules
|
|
let allowedTools = filterToolsByDenyRules(tools, permissionContext)
|
|
|
|
// When REPL mode is enabled, hide primitive tools from direct use.
|
|
// They're still accessible inside REPL via the VM context.
|
|
if (isReplModeEnabled()) {
|
|
const replEnabled = allowedTools.some(tool =>
|
|
toolMatchesName(tool, REPL_TOOL_NAME),
|
|
)
|
|
if (replEnabled) {
|
|
allowedTools = allowedTools.filter(
|
|
tool => !REPL_ONLY_TOOLS.has(tool.name),
|
|
)
|
|
}
|
|
}
|
|
|
|
const isEnabled = allowedTools.map(_ => _.isEnabled())
|
|
return allowedTools.filter((_, i) => isEnabled[i])
|
|
}
|
|
|
|
/**
|
|
* Assemble the full tool pool for a given permission context and MCP tools.
|
|
*
|
|
* This is the single source of truth for combining built-in tools with MCP tools.
|
|
* Both REPL.tsx (via useMergedTools hook) and runAgent.ts (for coordinator workers)
|
|
* use this function to ensure consistent tool pool assembly.
|
|
*
|
|
* The function:
|
|
* 1. Gets built-in tools via getTools() (respects mode filtering)
|
|
* 2. Filters MCP tools by deny rules
|
|
* 3. Deduplicates by tool name (built-in tools take precedence)
|
|
*
|
|
* @param permissionContext - Permission context for filtering built-in tools
|
|
* @param mcpTools - MCP tools from appState.mcp.tools
|
|
* @returns Combined, deduplicated array of built-in and MCP tools
|
|
*/
|
|
export function assembleToolPool(
|
|
permissionContext: ToolPermissionContext,
|
|
mcpTools: Tools,
|
|
): Tools {
|
|
const builtInTools = getTools(permissionContext)
|
|
|
|
// Filter out MCP tools that are in the deny list
|
|
const allowedMcpTools = filterToolsByDenyRules(mcpTools, permissionContext)
|
|
|
|
// Sort each partition for prompt-cache stability, keeping built-ins as a
|
|
// contiguous prefix. The server's claude_code_system_cache_policy places a
|
|
// global cache breakpoint after the last prefix-matched built-in tool; a flat
|
|
// sort would interleave MCP tools into built-ins and invalidate all downstream
|
|
// cache keys whenever an MCP tool sorts between existing built-ins. uniqBy
|
|
// preserves insertion order, so built-ins win on name conflict.
|
|
// Avoid Array.toSorted (Node 20+) — we support Node 18. builtInTools is
|
|
// readonly so copy-then-sort; allowedMcpTools is a fresh .filter() result.
|
|
const byName = (a: Tool, b: Tool) => a.name.localeCompare(b.name)
|
|
return uniqBy(
|
|
[...builtInTools].sort(byName).concat(allowedMcpTools.sort(byName)),
|
|
'name',
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Get all tools including both built-in tools and MCP tools.
|
|
*
|
|
* This is the preferred function when you need the complete tools list for:
|
|
* - Tool search threshold calculations (isSearchExtraToolsEnabled)
|
|
* - Token counting that includes MCP tools
|
|
* - Any context where MCP tools should be considered
|
|
*
|
|
* Use getTools() only when you specifically need just built-in tools.
|
|
*
|
|
* @param permissionContext - Permission context for filtering built-in tools
|
|
* @param mcpTools - MCP tools from appState.mcp.tools
|
|
* @returns Combined array of built-in and MCP tools
|
|
*/
|
|
export function getMergedTools(
|
|
permissionContext: ToolPermissionContext,
|
|
mcpTools: Tools,
|
|
): Tools {
|
|
const builtInTools = getTools(permissionContext)
|
|
return [...builtInTools, ...mcpTools]
|
|
}
|