* Handle codegraph_node
(args: Record<string, unknown>)
| 8522 | * Handle codegraph_node |
| 8523 | */ |
| 8524 | private async handleNode(args: Record<string, unknown>): Promise<ToolResult> { |
| 8525 | const cg = this.getCodeGraph(args.projectPath as string | undefined); |
| 8526 | // Default to false to minimize context usage |
| 8527 | const includeCode = args.includeCode === true; |
| 8528 | const fileHint = typeof args.file === 'string' && args.file.trim() ? args.file.trim() : undefined; |
| 8529 | const lineHint = typeof args.line === 'number' && args.line > 0 ? args.line : undefined; |
| 8530 | const offset = typeof args.offset === 'number' && args.offset > 0 ? Math.floor(args.offset) : undefined; |
| 8531 | const limit = typeof args.limit === 'number' && args.limit > 0 ? Math.floor(args.limit) : undefined; |
| 8532 | const symbolsOnly = args.symbolsOnly === true; |
| 8533 | const symbolRaw = typeof args.symbol === 'string' ? args.symbol.trim() : ''; |
| 8534 | |
| 8535 | // FILE READ MODE: a `file` with no `symbol` reads that file like the Read |
| 8536 | // tool — its current on-disk source with line numbers, narrowable with |
| 8537 | // `offset`/`limit` exactly as Read does — PLUS a one-line blast-radius |
| 8538 | // header (which files depend on it). `symbolsOnly` returns just the |
| 8539 | // structural map instead. Backed by the index: same bytes Read gives you. |
| 8540 | if (!symbolRaw && fileHint) { |
| 8541 | return this.handleFileView(cg, fileHint, { offset, limit, symbolsOnly }); |
| 8542 | } |
| 8543 | |
| 8544 | const symbol = this.validateString(args.symbol, 'symbol'); |
| 8545 | if (typeof symbol !== 'string') return symbol; |
| 8546 | |
| 8547 | let matches = this.findSymbolMatches(cg, symbol); |
| 8548 | if (matches.length === 0) { |
| 8549 | return this.textResult(`Symbol "${symbol}" not found in the codebase`); |
| 8550 | } |
| 8551 | |
| 8552 | // Disambiguate a heavily-overloaded name to a specific definition the caller |
| 8553 | // pinned by file/line (the `file:line` a trail or another tool showed it) — |
| 8554 | // so it can fetch e.g. `Harness::poll` at harness.rs:153 out of 50+ `poll`s |
| 8555 | // instead of Reading. file matches by path suffix/substring; line prefers the |
| 8556 | // def whose body contains it, else the nearest start. Only narrows (never |
| 8557 | // empties — if a hint matches nothing it's ignored). |
| 8558 | if (matches.length > 1 && (fileHint || lineHint !== undefined)) { |
| 8559 | const norm = (p: string) => p.replace(/\\/g, '/').toLowerCase(); |
| 8560 | let narrowed = matches; |
| 8561 | if (fileHint) { |
| 8562 | const fh = norm(fileHint); |
| 8563 | const byFile = narrowed.filter((n) => norm(n.filePath).endsWith(fh) || norm(n.filePath).includes(fh)); |
| 8564 | if (byFile.length > 0) narrowed = byFile; |
| 8565 | } |
| 8566 | if (lineHint !== undefined && narrowed.length > 1) { |
| 8567 | const containing = narrowed.filter((n) => n.startLine <= lineHint && (n.endLine ?? n.startLine) >= lineHint); |
| 8568 | narrowed = containing.length > 0 |
| 8569 | ? containing |
| 8570 | : [...narrowed].sort((a, b) => Math.abs(a.startLine - lineHint) - Math.abs(b.startLine - lineHint)).slice(0, 1); |
| 8571 | } |
| 8572 | if (narrowed.length > 0) matches = narrowed; |
| 8573 | } |
| 8574 | |
| 8575 | // Single definition — the common case. |
| 8576 | if (matches.length === 1) { |
| 8577 | return this.textResult(this.truncateOutput(await this.renderNodeSection(cg, matches[0]!, includeCode))); |
| 8578 | } |
| 8579 | |
| 8580 | // Multiple definitions share this name — overloads, or same-named methods on |
| 8581 | // different types (Alamofire `didCompleteTask`/`task`/`validate`, gin |
no test coverage detected