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

Method formatTrail

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

4258 * a signal (read that one hop) rather than a dead end.
4259 */
4260 private formatTrail(cg: CodeGraph, node: Node): string {
4261 const TRAIL_CAP = 12;
4262 const fmt = (e: { node: Node; edge: Edge }) => {
4263 const base = `${e.node.name} (${e.node.filePath}:${e.node.startLine})`;
4264 const synth = this.synthEdgeNote(e.edge);
4265 return synth ? `${base} [${synth.compact}]` : base;
4266 };
4267 const collect = (edges: Array<{ node: Node; edge: Edge }>): Array<{ node: Node; edge: Edge }> => {
4268 const seen = new Set<string>([node.id]);
4269 const out: Array<{ node: Node; edge: Edge }> = [];
4270 for (const e of edges) {
4271 if (seen.has(e.node.id)) continue;
4272 seen.add(e.node.id);
4273 out.push(e);
4274 }
4275 return out;
4276 };
4277 const callees = collect(cg.getCallees(node.id));
4278 const callers = collect(cg.getCallers(node.id));
4279 if (callees.length === 0 && callers.length === 0) return '';
4280 const lines: string[] = ['', '**Trail — codegraph_node any of these to follow it (no Read needed)**'];
4281 if (callees.length > 0) {
4282 lines.push(`**Calls →** ${callees.slice(0, TRAIL_CAP).map(fmt).join(', ')}${callees.length > TRAIL_CAP ? `, +${callees.length - TRAIL_CAP} more` : ''}`);
4283 }
4284 if (callers.length > 0) {
4285 lines.push(`**Called by ←** ${callers.slice(0, TRAIL_CAP).map(fmt).join(', ')}${callers.length > TRAIL_CAP ? `, +${callers.length - TRAIL_CAP} more` : ''}`);
4286 }
4287 return lines.join('\n');
4288 }
4289
4290 /**
4291 * Handle codegraph_status

Callers 2

renderNodeSectionMethod · 0.95

Calls 4

collectFunction · 0.85
getCalleesMethod · 0.45
getCallersMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected