* 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)
| 1202 | * warning — so it stays out of this path. |
| 1203 | */ |
| 1204 | private withWorktreeNotice(result: ToolResult, projectPath?: string): ToolResult { |
| 1205 | if (result.isError) return result; |
| 1206 | const mismatch = this.worktreeMismatchFor(projectPath); |
| 1207 | if (!mismatch) return result; |
| 1208 | |
| 1209 | const notice = worktreeMismatchNotice(mismatch); |
| 1210 | const [first, ...rest] = result.content; |
| 1211 | if (first && first.type === 'text') { |
| 1212 | return { ...result, content: [{ type: 'text', text: `${notice}\n\n${first.text}` }, ...rest] }; |
| 1213 | } |
| 1214 | return result; |
| 1215 | } |
| 1216 | |
| 1217 | /** |
| 1218 | * Annotate a successful read-tool result with per-file staleness — the |
no test coverage detected