* 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)
| 1765 | * warning — so it stays out of this path. |
| 1766 | */ |
| 1767 | private withWorktreeNotice(result: ToolResult, projectPath?: string): ToolResult { |
| 1768 | if (result.isError) return result; |
| 1769 | const mismatch = this.worktreeMismatchFor(projectPath); |
| 1770 | if (!mismatch) return result; |
| 1771 | |
| 1772 | const notice = worktreeMismatchNotice(mismatch); |
| 1773 | const [first, ...rest] = result.content; |
| 1774 | if (first && first.type === 'text') { |
| 1775 | return { ...result, content: [{ type: 'text', text: `${notice}\n\n${first.text}` }, ...rest] }; |
| 1776 | } |
| 1777 | return result; |
| 1778 | } |
| 1779 | |
| 1780 | /** |
| 1781 | * Annotate a successful read-tool result with per-file staleness — the |
no test coverage detected