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

Method renderStaleNodeSection

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

8891 * possibly shifted.
8892 */
8893 private renderStaleNodeSection(cg: CodeGraph, node: Node, includeCode: boolean): string {
8894 const lines: string[] = [
8895 `**${node.name}** (${node.kind})`,
8896 '',
8897 `**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`,
8898 ];
8899 if (node.signature) {
8900 lines.push(`**Signature:** \`${node.signature}\``);
8901 }
8902 lines.push('');
8903 let embedded = false;
8904 if (includeCode) {
8905 try {
8906 const absPath = validatePathWithinRoot(cg.getProjectRoot(), node.filePath);
8907 if (absPath && existsSync(absPath) && !isConfigLeafNode(node)) {
8908 const content = readFileSync(absPath, 'utf-8');
8909 const body = content.replace(/\n+$/, '');
8910 if (
8911 body.length <= ToolHandler.STALE_WHOLE_FILE_MAX_CHARS &&
8912 body.split('\n').length <= ToolHandler.STALE_WHOLE_FILE_MAX_LINES
8913 ) {
8914 lines.push(
8915 `> ⚠ \`${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):`,
8916 '',
8917 '```' + (node.language || ''),
8918 numberSourceLines(body, 1),
8919 '```',
8920 );
8921 embedded = true;
8922 }
8923 }
8924 } catch {
8925 /* fall through to the notice */
8926 }
8927 }
8928 if (!embedded) {
8929 lines.push(
8930 `> ⚠ \`${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.`,
8931 );
8932 }
8933 return lines.join('\n') + this.formatTrail(cg, node);
8934 }
8935
8936 /**
8937 * Build the "trail" for a symbol: its direct callees (what it calls) and

Callers 1

renderNodeSectionMethod · 0.95

Calls 7

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

Tested by

no test coverage detected