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

Method renderStaleNodeSection

src/mcp/tools.ts:6299–6340  ·  view source on GitHub ↗

* codegraph_node render for a symbol whose file changed on disk after the * last index sync (issue #1474). The indexed line range is no longer * trustworthy, so no slice is emitted: a small file gets its full CURRENT * source (Read-parity — sufficiency preserved, the agent still doesn't nee

(cg: CodeGraph, node: Node, includeCode: boolean)

Source from the content-addressed store, hash-verified

6297 * possibly shifted.
6298 */
6299 private renderStaleNodeSection(cg: CodeGraph, node: Node, includeCode: boolean): string {
6300 const lines: string[] = [
6301 `**${node.name}** (${node.kind})`,
6302 '',
6303 `**Location:** ${node.filePath}${node.startLine ? `:${node.startLine}` : ''} — ⚠ as of the last index sync; the file has changed on disk since, so this line may be shifted`,
6304 ];
6305 if (node.signature) {
6306 lines.push(`**Signature:** \`${node.signature}\``);
6307 }
6308 lines.push('');
6309 let embedded = false;
6310 if (includeCode) {
6311 try {
6312 const absPath = validatePathWithinRoot(cg.getProjectRoot(), node.filePath);
6313 if (absPath && existsSync(absPath) && !isConfigLeafNode(node)) {
6314 const content = readFileSync(absPath, 'utf-8');
6315 const body = content.replace(/\n+$/, '');
6316 if (
6317 body.length <= ToolHandler.STALE_WHOLE_FILE_MAX_CHARS &&
6318 body.split('\n').length <= ToolHandler.STALE_WHOLE_FILE_MAX_LINES
6319 ) {
6320 lines.push(
6321 `> ⚠ \`${node.filePath}\` changed on disk after it was last indexed, so the indexed line range for this symbol may no longer match. Showing the file's full CURRENT source instead (Read-parity — treat it as already Read):`,
6322 '',
6323 '```' + (node.language || ''),
6324 numberSourceLines(body, 1),
6325 '```',
6326 );
6327 embedded = true;
6328 }
6329 }
6330 } catch {
6331 /* fall through to the notice */
6332 }
6333 }
6334 if (!embedded) {
6335 lines.push(
6336 `> ⚠ \`${node.filePath}\` changed on disk after it was last indexed — the indexed line range for this symbol no longer reliably matches, so its body is omitted rather than risk showing a different symbol's code. For current content, call codegraph_node with \`file: "${node.filePath}"\` (no symbol; \`offset\`/\`limit\` narrow it like Read), or Read the file. The change is picked up automatically on that project's next index sync.`,
6337 );
6338 }
6339 return lines.join('\n') + this.formatTrail(cg, node);
6340 }
6341
6342 /**
6343 * Build the "trail" for a symbol: its direct callees (what it calls) and

Callers 1

renderNodeSectionMethod · 0.95

Calls 6

formatTrailMethod · 0.95
validatePathWithinRootFunction · 0.90
isConfigLeafNodeFunction · 0.90
numberSourceLinesFunction · 0.85
getProjectRootMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected