export type CapabilityId = | 'files.read' | 'files.write' | 'shell' | 'web.search' | 'web.fetch' | 'web.browser' | 'network.download' | 'computer.use' | 'ask' | 'advisor' | 'subagent' | 'delivery' | 'media' | 'memory' | 'code.intelligence' | 'background.process' | 'files.trash' | 'task.management' | 'skill.invoke' | 'worktree.session' | 'terminal.capture' | 'context.optimize'; export type ToolBudgetClass = 'core' | 'task' | 'auxiliary'; const TOOL_CAPABILITIES: Readonly> = Object.freeze({ Read: 'files.read', Glob: 'files.read', Grep: 'files.read', Snip: 'files.read', Edit: 'files.write', MultiEdit: 'files.write', Write: 'files.write', ApplyPatch: 'files.write', Bash: 'shell', PowerShell: 'shell', TaskOutput: 'background.process', TaskStop: 'background.process', Trash: 'files.trash', TaskCreate: 'task.management', TaskGet: 'task.management', TaskUpdate: 'task.management', TaskList: 'task.management', Schedule: 'task.management', Skill: 'skill.invoke', SearchSkills: 'skill.invoke', EnterWorktree: 'worktree.session', ExitWorktree: 'worktree.session', TerminalCapture: 'terminal.capture', LSP: 'code.intelligence', NotebookEdit: 'files.write', WebSearch: 'web.search', WebFetch: 'web.fetch', WebBrowser: 'web.browser', BrowserBatch: 'web.browser', BrowserCDP: 'web.browser', Download: 'network.download', ComputerUse: 'computer.use', AskUserQuestion: 'ask', Advisor: 'advisor', Agent: 'subagent', AgentMessage: 'subagent', AgentList: 'subagent', AgentWait: 'subagent', AgentInterrupt: 'subagent', AgentFollowup: 'subagent', AgentReport: 'subagent', AgentResolve: 'subagent', PresentResult: 'delivery', GenerateImage: 'media', GenerateSpeech: 'media', RecallMemory: 'memory', RememberMemory: 'memory', UpdateMemory: 'memory', ListMemories: 'memory', ForgetMemory: 'memory', SetPersona: 'memory', ClearPersona: 'memory', ConfirmMemory: 'memory', ReviewMemories: 'memory', SearchConversations: 'memory', MemoryMaintenance: 'memory', OptimizeConversation: 'context.optimize', }); const CORE_TOOLS = new Set([ 'Read', 'Glob', 'Grep', 'Edit', 'MultiEdit', 'Write', 'ApplyPatch', 'NotebookEdit', 'Bash', ]); const AUXILIARY_TOOLS = new Set([ 'Advisor', 'Agent', 'AgentMessage', 'AgentList', 'AgentWait', 'AgentInterrupt', 'AgentFollowup', 'OptimizeConversation', ]); export function budgetClassForToolName(name: string): ToolBudgetClass { if (CORE_TOOLS.has(name)) return 'core'; if (AUXILIARY_TOOLS.has(name)) return 'auxiliary'; return 'task'; } export function capabilityForToolName(name: string): CapabilityId | undefined { return TOOL_CAPABILITIES[name]; } /** Shared effect semantics, not an authorization decision. Housekeeping and stop * controls must not be mistaken for starting production work. Tools remain the * source of truth for dynamic read-only actions. */ export function toolEffectFor(name: string, isReadOnly: boolean): 'none' | 'bookkeeping' | 'execution' | 'delivery' { const capability = capabilityForToolName(name); if (capability === 'delivery') return 'delivery'; if (isReadOnly) return 'none'; if (capability === 'task.management' || capability === 'memory' || capability === 'background.process' || ['AgentInterrupt', 'AgentResolve', 'AgentReport'].includes(name)) return 'bookkeeping'; return 'execution'; } export function isMemoryToolName(name: string): boolean { return capabilityForToolName(name) === 'memory'; } export function assertCapabilityRegistry(toolNames: readonly string[]): void { const missing = toolNames.filter((name) => !capabilityForToolName(name)); if (missing.length > 0) throw new Error(`工具缺少 capability 声明:${missing.join(', ')}`); }