* 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)
| 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); |
no test coverage detected