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

Method withWorktreeNotice

src/mcp/tools.ts:2820–2831  ·  view source on GitHub ↗

* Prefix a successful read-tool result with a compact worktree-mismatch * notice when the resolved index belongs to a different git working tree than * the caller's (issue #155). Without this, an agent in a nested worktree * silently trusts main-branch results. No-op on error results and wh

(result: ToolResult, projectPath?: string)

Source from the content-addressed store, hash-verified

2818 * warning — so it stays out of this path.
2819 */
2820 private withWorktreeNotice(result: ToolResult, projectPath?: string): ToolResult {
2821 if (result.isError) return result;
2822 const mismatch = this.worktreeMismatchFor(projectPath);
2823 if (!mismatch) return result;
2824
2825 const notice = worktreeMismatchNotice(mismatch);
2826 const [first, ...rest] = result.content;
2827 if (first && first.type === 'text') {
2828 return { ...result, content: [{ type: 'text', text: `${notice}\n\n${first.text}` }, ...rest] };
2829 }
2830 return result;
2831 }
2832
2833 /**
2834 * Annotate a successful read-tool result with per-file staleness — the

Callers 1

executeMethod · 0.95

Calls 2

worktreeMismatchForMethod · 0.95
worktreeMismatchNoticeFunction · 0.90

Tested by

no test coverage detected