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

Method isFileStaleOnDisk

src/mcp/tools.ts:2939–2955  ·  view source on GitHub ↗

* On-disk drift check for a single indexed file (issue #1474). The code * renderers slice CURRENT bytes at INDEXED line ranges; when the file * changed after its last index sync those ranges can point at a DIFFERENT * symbol's code — served under the requested name with `isError: false`.

(cg: CodeGraph, relPath: string, content?: string)

Source from the content-addressed store, hash-verified

2937 * would needlessly push the agent back to Read.
2938 */
2939 private isFileStaleOnDisk(cg: CodeGraph, relPath: string, content?: string): boolean {
2940 let root: string;
2941 try {
2942 root = cg.getProjectRoot();
2943 } catch {
2944 return false;
2945 }
2946 const key = `${root}\0${relPath}`;
2947 const now = Date.now();
2948 const hit = this.driftCache.get(key);
2949 if (hit && now - hit.at < ToolHandler.DRIFT_TTL_MS) return hit.stale;
2950 // The check itself is shared with the CLI's read commands (#3260). A file
2951 // gone from disk isn't flagged here: the not-found paths answer for it.
2952 const stale = fileDrift(cg, relPath, content) === 'changed';
2953 this.driftCache.set(key, { at: now, stale });
2954 return stale;
2955 }
2956
2957 private answerResult(cg: CodeGraph, text: string, paths: Iterable<string>): ToolResult {
2958 const result = this.textResult(text);

Callers 4

handleExploreMethod · 0.95
readFileMethod · 0.95
renderNodeSectionMethod · 0.95

Calls 4

fileDriftFunction · 0.90
getProjectRootMethod · 0.65
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected