source dump of claude code
at main 98 lines 4.6 kB view raw
1import { feature } from 'bun:bundle' 2import { ASK_USER_QUESTION_TOOL_NAME } from '../../tools/AskUserQuestionTool/prompt.js' 3import { ENTER_PLAN_MODE_TOOL_NAME } from '../../tools/EnterPlanModeTool/constants.js' 4import { EXIT_PLAN_MODE_TOOL_NAME } from '../../tools/ExitPlanModeTool/constants.js' 5import { FILE_READ_TOOL_NAME } from '../../tools/FileReadTool/prompt.js' 6import { GLOB_TOOL_NAME } from '../../tools/GlobTool/prompt.js' 7import { GREP_TOOL_NAME } from '../../tools/GrepTool/prompt.js' 8import { LIST_MCP_RESOURCES_TOOL_NAME } from '../../tools/ListMcpResourcesTool/prompt.js' 9import { LSP_TOOL_NAME } from '../../tools/LSPTool/prompt.js' 10import { SEND_MESSAGE_TOOL_NAME } from '../../tools/SendMessageTool/constants.js' 11import { SLEEP_TOOL_NAME } from '../../tools/SleepTool/prompt.js' 12import { TASK_CREATE_TOOL_NAME } from '../../tools/TaskCreateTool/constants.js' 13import { TASK_GET_TOOL_NAME } from '../../tools/TaskGetTool/constants.js' 14import { TASK_LIST_TOOL_NAME } from '../../tools/TaskListTool/constants.js' 15import { TASK_OUTPUT_TOOL_NAME } from '../../tools/TaskOutputTool/constants.js' 16import { TASK_STOP_TOOL_NAME } from '../../tools/TaskStopTool/prompt.js' 17import { TASK_UPDATE_TOOL_NAME } from '../../tools/TaskUpdateTool/constants.js' 18import { TEAM_CREATE_TOOL_NAME } from '../../tools/TeamCreateTool/constants.js' 19import { TEAM_DELETE_TOOL_NAME } from '../../tools/TeamDeleteTool/constants.js' 20import { TODO_WRITE_TOOL_NAME } from '../../tools/TodoWriteTool/constants.js' 21import { TOOL_SEARCH_TOOL_NAME } from '../../tools/ToolSearchTool/prompt.js' 22import { YOLO_CLASSIFIER_TOOL_NAME } from './yoloClassifier.js' 23 24// Ant-only tool names: conditional require so Bun can DCE these in external builds. 25// Gates mirror tools.ts. Keeps the tool name strings out of cli.js. 26/* eslint-disable @typescript-eslint/no-require-imports */ 27const TERMINAL_CAPTURE_TOOL_NAME = feature('TERMINAL_PANEL') 28 ? ( 29 require('../../tools/TerminalCaptureTool/prompt.js') as typeof import('../../tools/TerminalCaptureTool/prompt.js') 30 ).TERMINAL_CAPTURE_TOOL_NAME 31 : null 32const OVERFLOW_TEST_TOOL_NAME = feature('OVERFLOW_TEST_TOOL') 33 ? ( 34 require('../../tools/OverflowTestTool/OverflowTestTool.js') as typeof import('../../tools/OverflowTestTool/OverflowTestTool.js') 35 ).OVERFLOW_TEST_TOOL_NAME 36 : null 37const VERIFY_PLAN_EXECUTION_TOOL_NAME = 38 process.env.USER_TYPE === 'ant' 39 ? ( 40 require('../../tools/VerifyPlanExecutionTool/constants.js') as typeof import('../../tools/VerifyPlanExecutionTool/constants.js') 41 ).VERIFY_PLAN_EXECUTION_TOOL_NAME 42 : null 43const WORKFLOW_TOOL_NAME = feature('WORKFLOW_SCRIPTS') 44 ? ( 45 require('../../tools/WorkflowTool/constants.js') as typeof import('../../tools/WorkflowTool/constants.js') 46 ).WORKFLOW_TOOL_NAME 47 : null 48/* eslint-enable @typescript-eslint/no-require-imports */ 49 50/** 51 * Tools that are safe and don't need any classifier checking. 52 * Used by the auto mode classifier to skip unnecessary API calls. 53 * Does NOT include write/edit tools — those are handled by the 54 * acceptEdits fast path (allowed in CWD, classified outside CWD). 55 */ 56const SAFE_YOLO_ALLOWLISTED_TOOLS = new Set([ 57 // Read-only file operations 58 FILE_READ_TOOL_NAME, 59 // Search / read-only 60 GREP_TOOL_NAME, 61 GLOB_TOOL_NAME, 62 LSP_TOOL_NAME, 63 TOOL_SEARCH_TOOL_NAME, 64 LIST_MCP_RESOURCES_TOOL_NAME, 65 'ReadMcpResourceTool', // no exported constant 66 // Task management (metadata only) 67 TODO_WRITE_TOOL_NAME, 68 TASK_CREATE_TOOL_NAME, 69 TASK_GET_TOOL_NAME, 70 TASK_UPDATE_TOOL_NAME, 71 TASK_LIST_TOOL_NAME, 72 TASK_STOP_TOOL_NAME, 73 TASK_OUTPUT_TOOL_NAME, 74 // Plan mode / UI 75 ASK_USER_QUESTION_TOOL_NAME, 76 ENTER_PLAN_MODE_TOOL_NAME, 77 EXIT_PLAN_MODE_TOOL_NAME, 78 // Swarm coordination (internal mailbox/team state only — teammates have 79 // their own permission checks, so no actual security bypass). 80 TEAM_CREATE_TOOL_NAME, 81 // Agent cleanup 82 TEAM_DELETE_TOOL_NAME, 83 SEND_MESSAGE_TOOL_NAME, 84 // Workflow orchestration — subagents go through canUseTool individually 85 ...(WORKFLOW_TOOL_NAME ? [WORKFLOW_TOOL_NAME] : []), 86 // Misc safe 87 SLEEP_TOOL_NAME, 88 // Ant-only safe tools (gates mirror tools.ts) 89 ...(TERMINAL_CAPTURE_TOOL_NAME ? [TERMINAL_CAPTURE_TOOL_NAME] : []), 90 ...(OVERFLOW_TEST_TOOL_NAME ? [OVERFLOW_TEST_TOOL_NAME] : []), 91 ...(VERIFY_PLAN_EXECUTION_TOOL_NAME ? [VERIFY_PLAN_EXECUTION_TOOL_NAME] : []), 92 // Internal classifier tool 93 YOLO_CLASSIFIER_TOOL_NAME, 94]) 95 96export function isAutoModeAllowlistedTool(toolName: string): boolean { 97 return SAFE_YOLO_ALLOWLISTED_TOOLS.has(toolName) 98}