* Cached git worktree/index mismatch for a tool call's effective project. * * The "effective project" is what the request targets: an explicit * `projectPath` arg, else the directory the server resolved its default * project from (`defaultProjectHint`), else cwd. Memoized per start path
(projectPath?: string)
| 1195 | * broken by this check. |
| 1196 | */ |
| 1197 | private worktreeMismatchFor(projectPath?: string): WorktreeIndexMismatch | null { |
| 1198 | const startPath = projectPath ?? this.defaultProjectHint ?? process.cwd(); |
| 1199 | |
| 1200 | // The verdict depends on BOTH the start path AND the index root it resolves |
| 1201 | // to, so the cache must be keyed on the pair. Resolve the index root first |
| 1202 | // (cheap — getCodeGraph re-walks to the nearest .codegraph/, no git), then |
| 1203 | // key on `(startPath, indexRoot)`. The moment that root changes — most |
| 1204 | // importantly when a git worktree gains its own index and the walk-up stops |
| 1205 | // there instead of at the parent checkout — the key changes and the verdict |
| 1206 | // is recomputed, instead of serving the stale "borrowed the parent's index" |
| 1207 | // warning for the server's whole lifetime. Keying on startPath alone pinned |
| 1208 | // that first verdict until restart (#926). |
| 1209 | let indexRoot: string; |
| 1210 | try { |
| 1211 | indexRoot = this.getCodeGraph(projectPath).getProjectRoot(); |
| 1212 | } catch { |
| 1213 | // No resolvable project (or any other resolution error) → nothing to warn. |
| 1214 | return null; |
| 1215 | } |
| 1216 | |
| 1217 | const cacheKey = `${startPath}\u0000${indexRoot}`; |
| 1218 | const cached = this.worktreeMismatchCache.get(cacheKey); |
| 1219 | if (cached !== undefined) return cached; |
| 1220 | |
| 1221 | const mismatch = detectWorktreeIndexMismatch(startPath, indexRoot); |
| 1222 | this.worktreeMismatchCache.set(cacheKey, mismatch); |
| 1223 | return mismatch; |
| 1224 | } |
| 1225 | |
| 1226 | /** |
| 1227 | * Prefix a successful read-tool result with a compact worktree-mismatch |
no test coverage detected