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

Method worktreeMismatchFor

src/mcp/tools.ts:2809–2836  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

2807 * broken by this check.
2808 */
2809 private worktreeMismatchFor(projectPath?: string): WorktreeIndexMismatch | null {
2810 const startPath = projectPath ?? this.defaultProjectHint ?? process.cwd();
2811
2812 // The verdict depends on BOTH the start path AND the index root it resolves
2813 // to, so the cache must be keyed on the pair. Resolve the index root first
2814 // (cheap — getCodeGraph re-walks to the nearest .codegraph/, no git), then
2815 // key on `(startPath, indexRoot)`. The moment that root changes — most
2816 // importantly when a git worktree gains its own index and the walk-up stops
2817 // there instead of at the parent checkout — the key changes and the verdict
2818 // is recomputed, instead of serving the stale "borrowed the parent's index"
2819 // warning for the server's whole lifetime. Keying on startPath alone pinned
2820 // that first verdict until restart (#926).
2821 let indexRoot: string;
2822 try {
2823 indexRoot = this.getCodeGraph(projectPath).getProjectRoot();
2824 } catch {
2825 // No resolvable project (or any other resolution error) → nothing to warn.
2826 return null;
2827 }
2828
2829 const cacheKey = `${startPath}\u0000${indexRoot}`;
2830 const cached = this.worktreeMismatchCache.get(cacheKey);
2831 if (cached !== undefined) return cached;
2832
2833 const mismatch = detectWorktreeIndexMismatch(startPath, indexRoot);
2834 this.worktreeMismatchCache.set(cacheKey, mismatch);
2835 return mismatch;
2836 }
2837
2838 /**
2839 * Prefix a successful read-tool result with a compact worktree-mismatch

Callers 2

withWorktreeNoticeMethod · 0.95
handleStatusMethod · 0.95

Calls 5

getCodeGraphMethod · 0.95
getProjectRootMethod · 0.65
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected