MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / formatTrail

Method formatTrail

src/mcp/tools.ts:8670–8700  ·  view source on GitHub ↗

* Build the "trail" for a symbol: its direct callees (what it calls) and * callers (what calls it), each with file:line — so codegraph_node doubles as * the structural Grep→Read→expand primitive: a spot PLUS where to go next. * Capped to stay cheap. Walk the graph by calling codegraph_node

(cg: CodeGraph, node: Node)

Source from the content-addressed store, hash-verified

8668 * a signal (read that one hop) rather than a dead end.
8669 */
8670 private formatTrail(cg: CodeGraph, node: Node): string {
8671 const TRAIL_CAP = 12;
8672 /** Call-site lines shown per caller, so one busy caller can't crowd the trail. */
8673 const TRAIL_CALL_SITES = 3;
8674 const fmt = (row: CallSiteRow, where: string) => {
8675 const base = `${row.node.name} (${where})`;
8676 const synth = this.synthEdgeNote(row.edges[0]!);
8677 return synth ? `${base} [${synth}]` : base;
8678 };
8679 // A callee reads at its declaration, where following it leads. A caller
8680 // reads at the lines its calls sit on, every one a line to edit when this
8681 // symbol changes (#2909), and a symbol that calls itself is among its own
8682 // callers, once.
8683 const callees = cg.getCallSites(node.id, 'callees').filter((row) => !row.recursive);
8684 const callers = cg.getCallSites(node.id, 'callers');
8685 if (callees.length === 0 && callers.length === 0) return '';
8686 const callee = (row: CallSiteRow) => fmt(row, `${row.node.filePath}:${row.node.startLine}`);
8687 const caller = (row: CallSiteRow) => {
8688 const sites = callSiteLines(row.edges);
8689 const at = sites.length > 0 ? formatCallSiteLines(sites, TRAIL_CALL_SITES) : String(row.node.startLine);
8690 return fmt(row, `${row.node.filePath}:${at}${row.recursive ? ', calls itself' : ''}`);
8691 };
8692 const lines: string[] = ['', '**Trail — codegraph_node any of these to follow it (no Read needed)**'];
8693 if (callees.length > 0) {
8694 lines.push(`**Calls →** ${callees.slice(0, TRAIL_CAP).map(callee).join(', ')}${callees.length > TRAIL_CAP ? `, +${callees.length - TRAIL_CAP} more` : ''}`);
8695 }
8696 if (callers.length > 0) {
8697 lines.push(`**Called by ←** ${callers.slice(0, TRAIL_CAP).map(caller).join(', ')}${callers.length > TRAIL_CAP ? `, +${callers.length - TRAIL_CAP} more` : ''}`);
8698 }
8699 return lines.join('\n');
8700 }
8701
8702 /**
8703 * Handle codegraph_status

Callers 2

renderNodeSectionMethod · 0.95

Calls 4

pushMethod · 0.80
mapMethod · 0.80
getCallSitesMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected