feat(FN-1430): add worktree execution boundaries to prevent out-of-scope modifications

- Add worktree-aware path boundaries in agent factory to prevent cross-task contamination
- Sync core agent prompts with worktree boundary guidance for consistent enforcement
- Add boundary guidance to executor prompts so agents understand their scope
- Fix TypeScript types for worktree boundary wrapping
- Add comprehensive tests for boundary wrapping behavior
- Create changeset for @gsxdsm/fusion (minor)
This commit is contained in:
gsxdsm
2026-04-09 23:59:45 -07:00
parent 3fdc16bf5d
commit 03f010cf60
7 changed files with 528 additions and 2 deletions

View File

@@ -9265,3 +9265,74 @@ describe("detectReviewHandoffIntent", () => {
expect(detectReviewHandoffIntent("")).toBe(false);
});
});
describe("buildExecutionPrompt", () => {
it("includes worktree boundary guidance in the execution prompt", () => {
const task: any = {
id: "FN-TEST",
title: "Test task",
dependencies: [],
prompt: "# Test task\n## Steps\n- Step 1",
steps: [],
currentStep: 0,
attachments: [],
};
const prompt = buildExecutionPrompt(task, "/project");
expect(prompt).toContain("## Worktree Boundaries");
expect(prompt).toContain("isolated git worktree");
expect(prompt).toContain("All code changes must be made inside the current worktree directory");
});
it("mentions project memory exception in worktree boundary guidance", () => {
const task: any = {
id: "FN-TEST",
title: "Test task",
dependencies: [],
prompt: "# Test task\n## Steps\n- Step 1",
steps: [],
currentStep: 0,
attachments: [],
};
const prompt = buildExecutionPrompt(task, "/project");
expect(prompt).toContain(".fusion/memory.md");
expect(prompt).toContain("memory");
expect(prompt).toContain("durable");
});
it("mentions task attachments exception in worktree boundary guidance", () => {
const task: any = {
id: "FN-TEST",
title: "Test task",
dependencies: [],
prompt: "# Test task\n## Steps\n- Step 1",
steps: [],
currentStep: 0,
attachments: [],
};
const prompt = buildExecutionPrompt(task, "/project");
expect(prompt).toContain("attachments");
expect(prompt).toContain("context");
});
it("includes worktree boundary guidance regardless of review level", () => {
const task: any = {
id: "FN-TEST",
title: "Test task",
dependencies: [],
prompt: "# Test task\n## Review Level: 0\n## Steps\n- Step 1",
steps: [],
currentStep: 0,
attachments: [],
};
const prompt = buildExecutionPrompt(task, "/project");
expect(prompt).toContain("## Worktree Boundaries");
});
});