the claude code sourcemaps leaked march 31
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 126 lines 4.1 kB view raw
1import { feature } from 'bun:bundle' 2import { z } from 'zod/v4' 3import { 4 getAllowedChannels, 5 handlePlanModeTransition, 6} from '../../bootstrap/state.js' 7import type { Tool } from '../../Tool.js' 8import { buildTool, type ToolDef } from '../../Tool.js' 9import { lazySchema } from '../../utils/lazySchema.js' 10import { applyPermissionUpdate } from '../../utils/permissions/PermissionUpdate.js' 11import { prepareContextForPlanMode } from '../../utils/permissions/permissionSetup.js' 12import { isPlanModeInterviewPhaseEnabled } from '../../utils/planModeV2.js' 13import { ENTER_PLAN_MODE_TOOL_NAME } from './constants.js' 14import { getEnterPlanModeToolPrompt } from './prompt.js' 15import { 16 renderToolResultMessage, 17 renderToolUseMessage, 18 renderToolUseRejectedMessage, 19} from './UI.js' 20 21const inputSchema = lazySchema(() => 22 z.strictObject({ 23 // No parameters needed 24 }), 25) 26type InputSchema = ReturnType<typeof inputSchema> 27 28const outputSchema = lazySchema(() => 29 z.object({ 30 message: z.string().describe('Confirmation that plan mode was entered'), 31 }), 32) 33type OutputSchema = ReturnType<typeof outputSchema> 34export type Output = z.infer<OutputSchema> 35 36export const EnterPlanModeTool: Tool<InputSchema, Output> = buildTool({ 37 name: ENTER_PLAN_MODE_TOOL_NAME, 38 searchHint: 'switch to plan mode to design an approach before coding', 39 maxResultSizeChars: 100_000, 40 async description() { 41 return 'Requests permission to enter plan mode for complex tasks requiring exploration and design' 42 }, 43 async prompt() { 44 return getEnterPlanModeToolPrompt() 45 }, 46 get inputSchema(): InputSchema { 47 return inputSchema() 48 }, 49 get outputSchema(): OutputSchema { 50 return outputSchema() 51 }, 52 userFacingName() { 53 return '' 54 }, 55 shouldDefer: true, 56 isEnabled() { 57 // When --channels is active, ExitPlanMode is disabled (its approval 58 // dialog needs the terminal). Disable entry too so plan mode isn't a 59 // trap the model can enter but never leave. 60 if ( 61 (feature('KAIROS') || feature('KAIROS_CHANNELS')) && 62 getAllowedChannels().length > 0 63 ) { 64 return false 65 } 66 return true 67 }, 68 isConcurrencySafe() { 69 return true 70 }, 71 isReadOnly() { 72 return true 73 }, 74 renderToolUseMessage, 75 renderToolResultMessage, 76 renderToolUseRejectedMessage, 77 async call(_input, context) { 78 if (context.agentId) { 79 throw new Error('EnterPlanMode tool cannot be used in agent contexts') 80 } 81 82 const appState = context.getAppState() 83 handlePlanModeTransition(appState.toolPermissionContext.mode, 'plan') 84 85 // Update the permission mode to 'plan'. prepareContextForPlanMode runs 86 // the classifier activation side effects when the user's defaultMode is 87 // 'auto' — see permissionSetup.ts for the full lifecycle. 88 context.setAppState(prev => ({ 89 ...prev, 90 toolPermissionContext: applyPermissionUpdate( 91 prepareContextForPlanMode(prev.toolPermissionContext), 92 { type: 'setMode', mode: 'plan', destination: 'session' }, 93 ), 94 })) 95 96 return { 97 data: { 98 message: 99 'Entered plan mode. You should now focus on exploring the codebase and designing an implementation approach.', 100 }, 101 } 102 }, 103 mapToolResultToToolResultBlockParam({ message }, toolUseID) { 104 const instructions = isPlanModeInterviewPhaseEnabled() 105 ? `${message} 106 107DO NOT write or edit any files except the plan file. Detailed workflow instructions will follow.` 108 : `${message} 109 110In plan mode, you should: 1111. Thoroughly explore the codebase to understand existing patterns 1122. Identify similar features and architectural approaches 1133. Consider multiple approaches and their trade-offs 1144. Use AskUserQuestion if you need to clarify the approach 1155. Design a concrete implementation strategy 1166. When ready, use ExitPlanMode to present your plan for approval 117 118Remember: DO NOT write or edit any files yet. This is a read-only exploration and planning phase.` 119 120 return { 121 type: 'tool_result', 122 content: instructions, 123 tool_use_id: toolUseID, 124 } 125 }, 126} satisfies ToolDef<InputSchema, Output>)