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

Method isFileStaleOnDisk

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

3054 * would needlessly push the agent back to Read.
3055 */
3056 private isFileStaleOnDisk(cg: CodeGraph, relPath: string, content?: string): boolean {
3057 let root: string;
3058 try {
3059 root = cg.getProjectRoot();
3060 } catch {
3061 return false;
3062 }
3063 const key = `${root}\0${relPath}`;
3064 const now = Date.now();
3065 const hit = this.driftCache.get(key);
3066 if (hit && now - hit.at < ToolHandler.DRIFT_TTL_MS) return hit.stale;
3067 // The check itself is shared with the CLI's read commands (#3260). A file
3068 // gone from disk isn't flagged here: the not-found paths answer for it.
3069 const stale = fileDrift(cg, relPath, content) === 'changed';
3070 this.driftCache.set(key, { at: now, stale });
3071 return stale;
3072 }
3073
3074 private answerResult(cg: CodeGraph, text: string, paths: Iterable<string>): ToolResult {
3075 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