* 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)
| 1165 | * broken by this check. |
| 1166 | */ |
| 1167 | private worktreeMismatchFor(projectPath?: string): WorktreeIndexMismatch | null { |
| 1168 | const startPath = projectPath ?? this.defaultProjectHint ?? process.cwd(); |
| 1169 | |
| 1170 | // The verdict depends on BOTH the start path AND the index root it resolves |
| 1171 | // to, so the cache must be keyed on the pair. Resolve the index root first |
| 1172 | // (cheap — getCodeGraph re-walks to the nearest .codegraph/, no git), then |
| 1173 | // key on `(startPath, indexRoot)`. The moment that root changes — most |
| 1174 | // importantly when a git worktree gains its own index and the walk-up stops |
| 1175 | // there instead of at the parent checkout — the key changes and the verdict |
| 1176 | // is recomputed, instead of serving the stale "borrowed the parent's index" |
| 1177 | // warning for the server's whole lifetime. Keying on startPath alone pinned |
| 1178 | // that first verdict until restart (#926). |
| 1179 | let indexRoot: string; |
| 1180 | try { |
| 1181 | indexRoot = this.getCodeGraph(projectPath).getProjectRoot(); |
| 1182 | } catch { |
| 1183 | // No resolvable project (or any other resolution error) → nothing to warn. |
| 1184 | return null; |
| 1185 | } |
| 1186 | |
| 1187 | const cacheKey = `${startPath}\u0000${indexRoot}`; |
| 1188 | const cached = this.worktreeMismatchCache.get(cacheKey); |
| 1189 | if (cached !== undefined) return cached; |
| 1190 | |
| 1191 | const mismatch = detectWorktreeIndexMismatch(startPath, indexRoot); |
| 1192 | this.worktreeMismatchCache.set(cacheKey, mismatch); |
| 1193 | return mismatch; |
| 1194 | } |
| 1195 | |
| 1196 | /** |
| 1197 | * Prefix a successful read-tool result with a compact worktree-mismatch |
no test coverage detected