* 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)
| 2844 | * warning — so it stays out of this path. |
| 2845 | */ |
| 2846 | private withWorktreeNotice(result: ToolResult, projectPath?: string): ToolResult { |
| 2847 | if (result.isError) return result; |
| 2848 | const mismatch = this.worktreeMismatchFor(projectPath); |
| 2849 | if (!mismatch) return result; |
| 2850 | |
| 2851 | const notice = worktreeMismatchNotice(mismatch); |
| 2852 | const [first, ...rest] = result.content; |
| 2853 | if (first && first.type === 'text') { |
| 2854 | return { ...result, content: [{ type: 'text', text: `${notice}\n\n${first.text}` }, ...rest] }; |
| 2855 | } |
| 2856 | return result; |
| 2857 | } |
| 2858 | |
| 2859 | /** |
| 2860 | * Annotate a successful read-tool result with per-file staleness — the |
no test coverage detected