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

Method formatTrail

src/mcp/tools.ts:8945–8975  ·  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

8943 * a signal (read that one hop) rather than a dead end.
8944 */
8945 private formatTrail(cg: CodeGraph, node: Node): string {
8946 const TRAIL_CAP = 12;
8947 /** Call-site lines shown per caller, so one busy caller can't crowd the trail. */
8948 const TRAIL_CALL_SITES = 3;
8949 const fmt = (row: CallSiteRow, where: string) => {
8950 const base = `${row.node.name} (${where})`;
8951 const synth = this.synthEdgeNote(row.edges[0]!);
8952 return synth ? `${base} [${synth}]` : base;
8953 };
8954 // A callee reads at its declaration, where following it leads. A caller
8955 // reads at the lines its calls sit on, every one a line to edit when this
8956 // symbol changes (#2909), and a symbol that calls itself is among its own
8957 // callers, once.
8958 const callees = cg.getCallSites(node.id, 'callees').filter((row) => !row.recursive);
8959 const callers = cg.getCallSites(node.id, 'callers');
8960 if (callees.length === 0 && callers.length === 0) return '';
8961 const callee = (row: CallSiteRow) => fmt(row, `${row.node.filePath}:${row.node.startLine}`);
8962 const caller = (row: CallSiteRow) => {
8963 const sites = callSiteLines(row.edges);
8964 const at = sites.length > 0 ? formatCallSiteLines(sites, TRAIL_CALL_SITES) : String(row.node.startLine);
8965 return fmt(row, `${row.node.filePath}:${at}${row.recursive ? ', calls itself' : ''}`);
8966 };
8967 const lines: string[] = ['', '**Trail — codegraph_node any of these to follow it (no Read needed)**'];
8968 if (callees.length > 0) {
8969 lines.push(`**Calls →** ${callees.slice(0, TRAIL_CAP).map(callee).join(', ')}${callees.length > TRAIL_CAP ? `, +${callees.length - TRAIL_CAP} more` : ''}`);
8970 }
8971 if (callers.length > 0) {
8972 lines.push(`**Called by ←** ${callers.slice(0, TRAIL_CAP).map(caller).join(', ')}${callers.length > TRAIL_CAP ? `, +${callers.length - TRAIL_CAP} more` : ''}`);
8973 }
8974 return lines.join('\n');
8975 }
8976
8977 /**
8978 * 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