| 3247 | |
| 3248 | Note: LSP servers must be configured for the file type. If no server is available, an error will be returned.`;var fHK;var ZHK=y(()=>{x7();fHK=B6(()=>{let q=L.strictObject({operation:L.literal("goToDefinition"),filePath:L.string().describe("The absolute or relative path to the file"),line:L.number().int().positive().describe("The line number (1-based, as shown in editors)"),character:L.number().int().positive().describe("The character offset (1-based, as shown in editors)")}),K=L.strictObject({operation:L.literal("findReferences"),filePath:L.string().describe("The absolute or relative path to the file"),line:L.number().int().positive().describe("The line number (1-based, as shown in editors)"),character:L.number().int().positive().describe("The character offset (1-based, as shown in editors)")}),_=L.strictObject({operation:L.literal("hover"),filePath:L.string().describe("The absolute or relative path to the file"),line:L.number().int().positive().describe("The line number (1-based, as shown in editors)"),character:L.number().int().positive().describe("The character offset (1-based, as shown in editors)")}),z=L.strictObject({operation:L.literal("documentSymbol"),filePath:L.string().describe("The absolute or relative path to the file"),line:L.number().int().positive().describe("The line number (1-based, as shown in editors)"),character:L.number().int().positive().describe("The character offset (1-based, as shown in editors)")}),Y=L.strictObject({operation:L.literal("workspaceSymbol"),filePath:L.string().describe("The absolute or relative path to the file"),line:L.number().int().positive().describe("The line number (1-based, as shown in editors)"),character:L.number().int().positive().describe("The character offset (1-based, as shown in editors)")}),$=L.strictObject({operation:L.literal("goToImplementation"),filePath:L.string().describe("The absolute or relative path to the file"),line:L.number().int().positive().describe("The line number (1-based, as shown in editors)"),character:L.number().int().positive().describe("The character offset (1-based, as shown in editors)")}),A=L.strictObject({operation:L.literal("prepareCallHierarchy"),filePath:L.string().describe("The absolute or relative path to the file"),line:L.number().int().positive().describe("The line number (1-based, as shown in editors)"),character:L.number().int().positive().describe("The character offset (1-based, as shown in editors)")}),O=L.strictObject({operation:L.literal("incomingCalls"),filePath:L.string().describe("The absolute or relative path to the file"),line:L.number().int().positive().describe("The line number (1-based, as shown in editors)"),character:L.number().int().positive().describe("The character offset (1-based, as shown in editors)")}),w=L.strictObject({operation:L.literal("outgoingCalls"),filePath:L.string().describe("The absolute or relative path to the file"),line:L.number().int().positive().describe("The line number (1-based, as shown in editors)"),character:L.number().int().positive().describe("The character offset (1-based, as shown in editors)")});return L.discriminatedUnion("operation",[q,K,_,z,Y,$,A,O,w])})});function THK(q,K,_){try{let z=X8(),Y=lq(q),{buffer:$,bytesRead:A}=z.readSync(Y,{length:GHK}),w=$.toString("utf-8",0,A).split(` |
| 3249 | `);if(K<0||K>=w.length)return null;if(A===GHK&&K===w.length-1)return null;let j=w[K];if(!j||_<0||_>=j.length)return null;let H=/[\w$'!]+|[+\-*/%&|^~<>=]+/g,J;while((J=H.exec(j))!==null){let M=J.index,X=M+J[0].length;if(_>=M&&_<X){let P=J[0];return d5(P,30)}}return null}catch(z){if(z instanceof Error)N(`Symbol extraction failed for ${q}:${K}:${_}: ${z.message}`,{level:"warn"});return null}}var GHK=65536;var vHK=y(()=>{_8();U7();e7();dz()});function a1Y(q){let K=z6(24),{operation:_,resultCount:z,fileCount:Y,content:$,verbose:A}=q,O;if(K[0]!==_)O=o1Y[_]||{singular:"result",plural:"results"},K[0]=_,K[1]=O;else O=K[1];let w=O,j=z===1?w.singular:w.plural,H;if(K[2]!==j||K[3]!==w.special||K[4]!==_||K[5]!==z)H=_==="hover"&&z>0&&w.special?EM.default.createElement(k,null,"Hover info ",w.special):EM.default.createElement(k,null,"Found ",EM.default.createElement(k,{bold:!0},z," "),j),K[2]=j,K[3]=w.special,K[4]=_,K[5]=z,K[6]=H;else H=K[6];let J=H,M;if(K[7]!==Y)M=Y>1?EM.default.createElement(k,null," ","across ",EM.default.createElement(k,{bold:!0},Y," "),"files"):null,K[7]=Y,K[8]=M;else M=K[8];let X=M;if(A){let D;if(K[9]===Symbol.for("react.memo_cache_sentinel"))D=EM.default.createElement(k,{dimColor:!0}," ⎿ "),K[9]=D;else D=K[9];let f;if(K[10]!==J||K[11]!==X)f=EM.default.createElement(u,{flexDirection:"row"},EM.default.createElement(k,null,D,J,X)),K[10]=J,K[11]=X,K[12]=f;else f=K[12];let G;if(K[13]!==$)G=EM.default.createElement(u,{marginLeft:5},EM.default.createElement(k,null,$)),K[13]=$,K[14]=G;else G=K[14];let Z;if(K[15]!==f||K[16]!==G)Z=EM.default.createElement(u,{flexDirection:"column"},f,G),K[15]=f,K[16]=G,K[17]=Z;else Z=K[17];return Z}let P;if(K[18]!==z)P=z>0&&EM.default.createElement(K2,null),K[18]=z,K[19]=P;else P=K[19];let W;if(K[20]!==J||K[21]!==X||K[22]!==P)W=EM.default.createElement(s8,{height:1},EM.default.createElement(k,null,J,X," ",P)),K[20]=J,K[21]=X,K[22]=P,K[23]=W;else W=K[23];return W}function kHK(){return"LSP"}function VHK(q,{verbose:K}){if(!q.operation)return null;let _=[];if((q.operation==="goToDefinition"||q.operation==="findReferences"||q.operation==="hover"||q.operation==="goToImplementation")&&q.filePath&&q.line!==void 0&&q.character!==void 0){let z=THK(q.filePath,q.line-1,q.character-1),Y=K?q.filePath:_3(q.filePath);if(z)_.push(`operation: "${q.operation}"`),_.push(`symbol: "${z}"`),_.push(`in: "${Y}"`);else _.push(`operation: "${q.operation}"`),_.push(`file: "${Y}"`),_.push(`position: ${q.line}:${q.character}`);return _.join(", ")}if(_.push(`operation: "${q.operation}"`),q.filePath){let z=K?q.filePath:_3(q.filePath);_.push(`file: "${z}"`)}return _.join(", ")}function NHK(q,{verbose:K}){if(!K&&typeof q==="string"&&o4(q,"tool_use_error"))return EM.default.createElement(s8,null,EM.default.createElement(k,{color:"error"},"LSP operation failed"));return EM.default.createElement(Y2,{result:q,verbose:K})}function yHK(q,K,{verbose:_}){if(q.resultCount!==void 0&&q.fileCount!==void 0)return EM.default.createElement(a1Y,{operation:q.operation,resultCount:q.resultCount,fileCount:q.fileCount,content:q.result,verbose:_});return EM.default.createElement(s8,null,EM.default.createElement(k,null,q.result))}var EM,o1Y;var EHK=y(()=>{q8();rv();bN();gK();s6();bK();i1();vHK();EM=O6(D6(),1),o1Y={goToDefinition:{singular:"definition",plural:"definitions"},findReferences:{singular:"reference",plural:"references"},documentSymbol:{singular:"symbol",plural:"symbols"},workspaceSymbol:{singular:"symbol",plural:"symbols"},hover:{singular:"hover info",plural:"hover info",special:"available"},goToImplementation:{singular:"implementation",plural:"implementations"},prepareCallHierarchy:{singular:"call item",plural:"call items"},incomingCalls:{singular:"caller",plural:"callers"},outgoingCalls:{singular:"callee",plural:"callees"}}});import{open as s1Y}from"fs/promises";import*as de1 from"path";import{pathToFileURL as t1Y}from"url";function _7Y(q,K){let _=t1Y(K).href,z={line:q.line-1,character:q.character-1};switch(q.operation){case"goToDefinition":return{method:"textDocument/definition",params:{textDocument:{uri:_},position:z}};case"findReferences":return{method:"textDocument/references",params:{textDocument:{uri:_},position:z,context:{includeDeclaration:!0}}};case"hover":return{method:"textDocument/hover",params:{textDocument:{uri:_},position:z}};case"documentSymbol":return{method:"textDocument/documentSymbol",params:{textDocument:{uri:_}}};case"workspaceSymbol":return{method:"workspace/symbol",params:{query:""}};case"goToImplementation":return{method:"textDocument/implementation",params:{textDocument:{uri:_},position:z}};case"prepareCallHierarchy":return{method:"textDocument/prepareCallHierarchy",params:{textDocument:{uri:_},position:z}};case"incomingCalls":return{method:"textDocument/prepareCallHierarchy",params:{textDocument:{uri:_},position:z}};case"outgoingCalls":return{method:"textDocument/prepareCallHierarchy",params:{textDocument:{uri:_},position:z}}}}function RHK(q){let K=q.length;for(let _ of q)if(_.children&&_.children.length>0)K+=RHK(_.children);return K}function Vm8(q){return new Set(q.map((K)=>K.uri)).size}function z7Y(q){let K=q.replace(/^file:\/\//,"");if(/^\/[A-Za-z]:/.test(K))K=K.slice(1);try{K=decodeURIComponent(K)}catch{}return K}async function LHK(q,K){if(q.length===0)return q;let _=new Map;for(let A of q)if(A.uri&&!_.has(A.uri))_.set(A.uri,z7Y(A.uri));let z=cJ(_.values());if(z.length===0)return q;let Y=new Set,$=50;for(let A=0;A<z.length;A+=$){let O=z.slice(A,A+$),w=await S7("git",["check-ignore",...O],{cwd:K,preserveOutputOnError:!1,timeout:5000});if(w.code===0&&w.stdout)for(let j of w.stdout.split(` |
| 3250 | `)){let H=j.trim();if(H)Y.add(H)}}if(Y.size===0)return q;return q.filter((A)=>{let O=_.get(A.uri);return!O||!Y.has(O)})}function Y7Y(q){return"targetUri"in q}function Nm8(q){if(Y7Y(q))return{uri:q.targetUri,range:q.targetSelectionRange||q.targetRange};return q}function $7Y(q,K,_){switch(q){case"goToDefinition":{let Y=(Array.isArray(K)?K:K?[K]:[]).map(Nm8),$=Y.filter((O)=>!O||!O.uri);if($.length>0)H6(Error(`LSP server returned ${$.length} location(s) with undefined URI for goToDefinition on ${_}. This indicates malformed data from the LSP server.`));let A=Y.filter((O)=>O&&O.uri);return{formatted:Fe1(K,_),resultCount:A.length,fileCount:Vm8(A)}}case"findReferences":{let z=K||[],Y=z.filter((A)=>!A||!A.uri);if(Y.length>0)H6(Error(`LSP server returned ${Y.length} location(s) with undefined URI for findReferences on ${_}. This indicates malformed data from the LSP server.`));let $=z.filter((A)=>A&&A.uri);return{formatted:jHK(K,_),resultCount:$.length,fileCount:Vm8($)}}case"hover":return{formatted:HHK(K,_),resultCount:K?1:0,fileCount:K?1:0};case"documentSymbol":{let z=K||[],$=z.length>0&&z[0]&&"range"in z[0]?RHK(z):z.length;return{formatted:MHK(K,_),resultCount:$,fileCount:z.length>0?1:0}}case"workspaceSymbol":{let z=K||[],Y=z.filter((O)=>!O||!O.location||!O.location.uri);if(Y.length>0)H6(Error(`LSP server returned ${Y.length} symbol(s) with undefined location URI for workspaceSymbol on ${_}. This indicates malformed data from the LSP server.`));let $=z.filter((O)=>O&&O.location&&O.location.uri),A=$.map((O)=>O.location);return{formatted:Ue1(K,_),resultCount:$.length,fileCount:Vm8(A)}}case"goToImplementation":{let Y=(Array.isArray(K)?K:K?[K]:[]).map(Nm8),$=Y.filter((O)=>!O||!O.uri);if($.length>0)H6(Error(`LSP server returned ${$.length} location(s) with undefined URI for goToImplementation on ${_}. This indicates malformed data from the LSP server.`));let A=Y.filter((O)=>O&&O.uri);return{formatted:Fe1(K,_),resultCount:A.length,fileCount:Vm8(A)}}case"prepareCallHierarchy":{let z=K||[];return{formatted:XHK(K,_),resultCount:z.length,fileCount:z.length>0?A7Y(z):0}}case"incomingCalls":{let z=K||[];return{formatted:PHK(K,_),resultCount:z.length,fileCount:z.length>0?O7Y(z):0}}case"outgoingCalls":{let z=K||[];return{formatted:WHK(K,_),resultCount:z.length,fileCount:z.length>0?w7Y(z):0}}}}function A7Y(q){let K=q.map((_)=>_.uri).filter((_)=>_);return new Set(K).size}function O7Y(q){let K=q.map((_)=>_.from?.uri).filter((_)=>_);return new Set(K).size}function w7Y(q){let K=q.map((_)=>_.to?.uri).filter((_)=>_);return new Set(K).size}var e1Y=1e7,q7Y,K7Y,ce1;var hHK=y(()=>{x7();uQ();Bq();I7();_8();y8();XK();e7();E8();dz();Tz();DHK();ZHK();EHK();q7Y=B6(()=>L.strictObject({operation:L.enum(["goToDefinition","findReferences","hover","documentSymbol","workspaceSymbol","goToImplementation","prepareCallHierarchy","incomingCalls","outgoingCalls"]).describe("The LSP operation to perform"),filePath:L.string().describe("The absolute or relative path to the file"),line:L.number().int().positive().describe("The line number (1-based, as shown in editors)"),character:L.number().int().positive().describe("The character offset (1-based, as shown in editors)")})),K7Y=B6(()=>L.object({operation:L.enum(["goToDefinition","findReferences","hover","documentSymbol","workspaceSymbol","goToImplementation","prepareCallHierarchy","incomingCalls","outgoingCalls"]).describe("The LSP operation that was performed"),result:L.string().describe("The formatted result of the LSP operation"),filePath:L.string().describe("The file path the operation was performed on"),resultCount:L.number().int().nonnegative().optional().describe("Number of results (definitions, references, symbols)"),fileCount:L.number().int().nonnegative().optional().describe("Number of files containing results")})),ce1=sq({name:S88,searchHint:"code intelligence (definitions, references, symbols, hover)",maxResultSizeChars:1e5,isLsp:!0,async description(){return Qe1},userFacingName:kHK,shouldDefer:!0,isEnabled(){return h_K()},get inputSchema(){return q7Y()},get outputSchema(){return K7Y()},isConcurrencySafe(){return!0},isReadOnly(){return!0},getPath({filePath:q}){return lq(q)},async validateInput(q){let K=fHK().safeParse(q);if(!K.success)return{result:!1,message:`Invalid input: ${K.error.message}`,errorCode:3};let _=X8(),z=lq(q.filePath);if(z.startsWith("\\\\")||z.startsWith("//"))return{result:!0};let Y;try{Y=await _.stat(z)}catch($){if(_7($))return{result:!1,message:`File does not exist: ${q.filePath}`,errorCode:1};let A=x1($);return H6(Error(`Failed to access file stats for LSP operation on ${q.filePath}: ${A.message}`)),{result:!1,message:`Cannot access file: ${q.filePath}. ${A.message}`,errorCode:4}}if(!Y.isFile())return{result:!1,message:`Path is not a file: ${q.filePath}`,errorCode:2};return{result:!0}},async checkPermissions(q,K){let _=K.getAppState();return RK6(ce1,q,_.toolPermissionContext)},async prompt(){return Qe1},renderToolUseMessage:VHK,renderToolUseErrorMessage:NHK,renderToolResultMessage:yHK,async call(q,K){let _=lq(q.filePath),z=Z8();if(WL6().status==="pending")await S_K();let $=Ma();if(!$)return H6(Error("LSP server manager not initialized when tool was called")),{data:{operation:q.operation,result:"LSP server manager not initialized. This may indicate a startup issue.",filePath:q.filePath}};let{method:A,params:O}=_7Y(q,_);try{if(!$.isFileOpen(_)){let X=await s1Y(_,"r");try{let P=await X.stat();if(P.size>e1Y)return{data:{operation:q.operation,result:`File too large for LSP analysis (${Math.ceil(P.size/1e6)}MB exceeds 10MB limit)`,filePath:q.filePath}};let W=await X.readFile({encoding:"utf-8"});await $.openFile(_,W)}finally{await X.close()}}let w=await $.sendRequest(_,A,O);if(w===void 0)return N(`No LSP server available for file type ${de1.extname(_)} for operation ${q.operation} on file ${q.filePath}`),{data:{operation:q.operation,result:`No LSP server available for file type: ${de1.extname(_)}`,filePath:q.filePath}};if(q.operation==="incomingCalls"||q.operation==="outgoingCalls"){let X=w;if(!X||X.length===0)return{data:{operation:q.operation,result:"No call hierarchy item found at this position",filePath:q.filePath,resultCount:0,fileCount:0}};let P=q.operation==="incomingCalls"?"callHierarchy/incomingCalls":"callHierarchy/outgoingCalls";if(w=await $.sendRequest(_,P,{item:X[0]}),w===void 0)N(`LSP server returned undefined for ${P} on ${q.filePath}`)}if(w&&Array.isArray(w)&&(q.operation==="findReferences"||q.operation==="goToDefinition"||q.operation==="goToImplementation"||q.operation==="workspaceSymbol"))if(q.operation==="workspaceSymbol"){let X=w,P=X.filter((f)=>f?.location?.uri).map((f)=>f.location),W=await LHK(P,z),D=new Set(W.map((f)=>f.uri));w=X.filter((f)=>!f?.location?.uri||D.has(f.location.uri))}else{let X=w.map(Nm8),P=await LHK(X,z),W=new Set(P.map((D)=>D.uri));w=w.filter((D)=>{let f=Nm8(D);return!f.uri||W.has(f.uri)})}let{formatted:j,resultCount:H,fileCount:J}=$7Y(q.operation,w,z);return{data:{operation:q.operation,result:j,filePath:q.filePath,resultCount:H,fileCount:J}}}catch(w){let H=x1(w).message;return H6(Error(`LSP tool request failed for ${q.operation} on ${q.filePath}: ${H}`)),{data:{operation:q.operation,result:`Error performing ${q.operation}: ${H}`,filePath:q.filePath}}}},mapToolResultToToolResultBlockParam(q,K){return{tool_use_id:K,type:"tool_result",content:q.result}}})});function SHK(){if(process.env.CLAUDE_CODE_PLAN_V2_AGENT_COUNT){let _=parseInt(process.env.CLAUDE_CODE_PLAN_V2_AGENT_COUNT,10);if(!isNaN(_)&&_>0&&_<=10)return _}let q=yK(),K=qF();if(q==="max"&&K==="default_claude_max_20x")return 3;if(q==="enterprise"||q==="team")return 3;return 1}function CHK(){if(process.env.CLAUDE_CODE_PLAN_V2_EXPLORE_AGENT_COUNT){let q=parseInt(process.env.CLAUDE_CODE_PLAN_V2_EXPLORE_AGENT_COUNT,10);if(!isNaN(q)&&q>0&&q<=10)return q}return 3}function l2(){let q=process.env.CLAUDE_CODE_PLAN_MODE_INTERVIEW_PHASE;if(i6(q))return!0;if(k_(q))return!1;return g8("tengu_plan_mode_interview_phase",!1)}function ym8(){let q=g8("tengu_pewter_ledger",null);if(q==="trim"||q==="cut"||q==="cap")return q;return null}var pK6=y(()=>{o1();G7();m8()});function H7Y(){let q=l2()?"":j7Y;return`Use this tool proactively when you're about to start a non-trivial implementation task. Getting user sign-off on your approach before writing code prevents wasted effort and ensures alignment. This tool transitions you into plan mode where you can explore the codebase and design an implementation approach for user approval. |
| 3251 | |
| 3252 | ## When to Use This Tool |
| 3253 | |
| 3254 | **Prefer using EnterPlanMode** for implementation tasks unless they're simple. Use it when ANY of these conditions apply: |
| 3255 | |
| 3256 | 1. **New Feature Implementation**: Adding meaningful new functionality |
| 3257 | - Example: "Add a logout button" - where should it go? What should happen on click? |
| 3258 | - Example: "Add form validation" - what rules? What error messages? |
| 3259 | |
| 3260 | 2. **Multiple Valid Approaches**: The task can be solved in several different ways |
| 3261 | - Example: "Add caching to the API" - could use Redis, in-memory, file-based, etc. |
| 3262 | - Example: "Improve performance" - many optimization strategies possible |
| 3263 | |
| 3264 | 3. **Code Modifications**: Changes that affect existing behavior or structure |
| 3265 | - Example: "Update the login flow" - what exactly should change? |
| 3266 | - Example: "Refactor this component" - what's the target architecture? |
| 3267 | |
| 3268 | 4. **Architectural Decisions**: The task requires choosing between patterns or technologies |
| 3269 | - Example: "Add real-time updates" - WebSockets vs SSE vs polling |
| 3270 | - Example: "Implement state management" - Redux vs Context vs custom solution |
| 3271 | |
| 3272 | 5. **Multi-File Changes**: The task will likely touch more than 2-3 files |
| 3273 | - Example: "Refactor the authentication system" |
| 3274 | - Example: "Add a new API endpoint with tests" |
| 3275 | |
| 3276 | 6. **Unclear Requirements**: You need to explore before understanding the full scope |
| 3277 | - Example: "Make the app faster" - need to profile and identify bottlenecks |
| 3278 | - Example: "Fix the bug in checkout" - need to investigate root cause |
| 3279 | |
| 3280 | 7. **User Preferences Matter**: The implementation could reasonably go multiple ways |
| 3281 | - If you would use ${a$} to clarify the approach, use EnterPlanMode instead |
| 3282 | - Plan mode lets you explore first, then present options with context |
| 3283 | |
| 3284 | ## When NOT to Use This Tool |
| 3285 | |
| 3286 | Only skip EnterPlanMode for simple tasks: |
| 3287 | - Single-line or few-line fixes (typos, obvious bugs, small tweaks) |
| 3288 | - Adding a single function with clear requirements |
| 3289 | - Tasks where the user has given very specific, detailed instructions |
| 3290 | - Pure research/exploration tasks (use the Agent tool with explore agent instead) |
| 3291 | |
| 3292 | ${q}## Examples |
| 3293 | |
| 3294 | ### GOOD - Use EnterPlanMode: |
| 3295 | User: "Add user authentication to the app" |
| 3296 | - Requires architectural decisions (session vs JWT, where to store tokens, middleware structure) |
| 3297 | |
| 3298 | User: "Optimize the database queries" |
| 3299 | - Multiple approaches possible, need to profile first, significant impact |
| 3300 | |
| 3301 | User: "Implement dark mode" |
| 3302 | - Architectural decision on theme system, affects many components |
| 3303 | |
| 3304 | User: "Add a delete button to the user profile" |
| 3305 | - Seems simple but involves: where to place it, confirmation dialog, API call, error handling, state updates |
| 3306 | |