* 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)
| 1232 | * warning — so it stays out of this path. |
| 1233 | */ |
| 1234 | private withWorktreeNotice(result: ToolResult, projectPath?: string): ToolResult { |
| 1235 | if (result.isError) return result; |
| 1236 | const mismatch = this.worktreeMismatchFor(projectPath); |
| 1237 | if (!mismatch) return result; |
| 1238 | |
| 1239 | const notice = worktreeMismatchNotice(mismatch); |
| 1240 | const [first, ...rest] = result.content; |
| 1241 | if (first && first.type === 'text') { |
| 1242 | return { ...result, content: [{ type: 'text', text: `${notice}\n\n${first.text}` }, ...rest] }; |
| 1243 | } |
| 1244 | return result; |
| 1245 | } |
| 1246 | |
| 1247 | /** |
| 1248 | * Annotate a successful read-tool result with per-file staleness — the |
no test coverage detected