* Handle codegraph_node
(args: Record<string, unknown>)
| 8067 | * Handle codegraph_node |
| 8068 | */ |
| 8069 | private async handleNode(args: Record<string, unknown>): Promise<ToolResult> { |
| 8070 | const cg = this.getCodeGraph(args.projectPath as string | undefined); |
| 8071 | // Default to false to minimize context usage |
| 8072 | const includeCode = args.includeCode === true; |
| 8073 | const fileHint = typeof args.file === 'string' && args.file.trim() ? args.file.trim() : undefined; |
| 8074 | const lineHint = typeof args.line === 'number' && args.line > 0 ? args.line : undefined; |
| 8075 | const offset = typeof args.offset === 'number' && args.offset > 0 ? Math.floor(args.offset) : undefined; |
| 8076 | const limit = typeof args.limit === 'number' && args.limit > 0 ? Math.floor(args.limit) : undefined; |
| 8077 | const symbolsOnly = args.symbolsOnly === true; |
| 8078 | const symbolRaw = typeof args.symbol === 'string' ? args.symbol.trim() : ''; |
| 8079 | |
| 8080 | // FILE READ MODE: a `file` with no `symbol` reads that file like the Read |
| 8081 | // tool — its current on-disk source with line numbers, narrowable with |
| 8082 | // `offset`/`limit` exactly as Read does — PLUS a one-line blast-radius |
| 8083 | // header (which files depend on it). `symbolsOnly` returns just the |
| 8084 | // structural map instead. Backed by the index: same bytes Read gives you. |
| 8085 | if (!symbolRaw && fileHint) { |
| 8086 | return this.handleFileView(cg, fileHint, { offset, limit, symbolsOnly }); |
| 8087 | } |
| 8088 | |
| 8089 | const symbol = this.validateString(args.symbol, 'symbol'); |
| 8090 | if (typeof symbol !== 'string') return symbol; |
| 8091 | |
| 8092 | let matches = this.findSymbolMatches(cg, symbol); |
| 8093 | if (matches.length === 0) { |
| 8094 | return this.textResult(`Symbol "${symbol}" not found in the codebase`); |
| 8095 | } |
| 8096 | |
| 8097 | // Disambiguate a heavily-overloaded name to a specific definition the caller |
| 8098 | // pinned by file/line (the `file:line` a trail or another tool showed it) — |
| 8099 | // so it can fetch e.g. `Harness::poll` at harness.rs:153 out of 50+ `poll`s |
| 8100 | // instead of Reading. file matches by path suffix/substring; line prefers the |
| 8101 | // def whose body contains it, else the nearest start. Only narrows (never |
| 8102 | // empties — if a hint matches nothing it's ignored). |
| 8103 | if (matches.length > 1 && (fileHint || lineHint !== undefined)) { |
| 8104 | const norm = (p: string) => p.replace(/\\/g, '/').toLowerCase(); |
| 8105 | let narrowed = matches; |
| 8106 | if (fileHint) { |
| 8107 | const fh = norm(fileHint); |
| 8108 | const byFile = narrowed.filter((n) => norm(n.filePath).endsWith(fh) || norm(n.filePath).includes(fh)); |
| 8109 | if (byFile.length > 0) narrowed = byFile; |
| 8110 | } |
| 8111 | if (lineHint !== undefined && narrowed.length > 1) { |
| 8112 | const containing = narrowed.filter((n) => n.startLine <= lineHint && (n.endLine ?? n.startLine) >= lineHint); |
| 8113 | narrowed = containing.length > 0 |
| 8114 | ? containing |
| 8115 | : [...narrowed].sort((a, b) => Math.abs(a.startLine - lineHint) - Math.abs(b.startLine - lineHint)).slice(0, 1); |
| 8116 | } |
| 8117 | if (narrowed.length > 0) matches = narrowed; |
| 8118 | } |
| 8119 | |
| 8120 | // Single definition — the common case. |
| 8121 | if (matches.length === 1) { |
| 8122 | return this.textResult(this.truncateOutput(await this.renderNodeSection(cg, matches[0]!, includeCode))); |
| 8123 | } |
| 8124 | |
| 8125 | // Multiple definitions share this name — overloads, or same-named methods on |
| 8126 | // different types (Alamofire `didCompleteTask`/`task`/`validate`, gin |
no test coverage detected