* 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)
| 2886 | * warning — so it stays out of this path. |
| 2887 | */ |
| 2888 | private withWorktreeNotice(result: ToolResult, projectPath?: string): ToolResult { |
| 2889 | if (result.isError) return result; |
| 2890 | const mismatch = this.worktreeMismatchFor(projectPath); |
| 2891 | if (!mismatch) return result; |
| 2892 | |
| 2893 | const notice = worktreeMismatchNotice(mismatch); |
| 2894 | const [first, ...rest] = result.content; |
| 2895 | if (first && first.type === 'text') { |
| 2896 | return { ...result, content: [{ type: 'text', text: `${notice}\n\n${first.text}` }, ...rest] }; |
| 2897 | } |
| 2898 | return result; |
| 2899 | } |
| 2900 | |
| 2901 | /** |
| 2902 | * Annotate a successful read-tool result with per-file staleness — the |
no test coverage detected