feat: Add agent session branching
💡 Change Scope
- [ ] Small Change: Fast feedback, localized UI/logic, low-risk.
- [x] Large Change: New feature, cross-boundary logic, runtime-risk (persistence, IPC, lifecycle, recovery).
📝 What Does This PR Do?
Adds an Agent header action to branch from an existing verified resumable agent session into a new Agent node. The branch uses the source Agent's verified resumeSessionId, preserves the source Agent and task primary binding, and supports mounted Space launch routing through the existing resume path.
This PR intentionally does not include manual canvas edges or fork-edge visualization; those will be handled separately.
🏗️ Large Change Spec (Required if "Large Change" is checked)
1. Context & Business Logic
Agent nodes already support resume/reload and session switching. This change adds a Branch session action for Agent nodes with a verified resumable session, creating a sibling Agent node that resumes from the same context instead of mutating the source node.
2. State Ownership & Invariants
- Renderer canvas state owns node creation and space membership.
- Agent lifecycle orchestration owns launching the new branch through the existing
resumelaunch path. - Invariants:
- Branching never kills or mutates the source Agent session.
- A task-linked source Agent keeps the task's primary
linkedAgentNodeIdunchanged. - Branch launch uses
mode: 'resume'with the verified sourceresumeSessionId. - Mounted Spaces continue to route launch through the mount-aware launch path.
3. Verification Plan & Regression Layer
Regression coverage is at the renderer/canvas integration-unit layer:
- Branch creates a new resumed Agent and keeps the source/task binding unchanged.
- Placement failure does not kill the empty placeholder session or launch anything.
- Mounted Spaces route branch launch through the mount control surface.
- Branch button is disabled until the current resume session is verified.
- Closing a branched Agent that inherited
taskIddoes not unlink the task's original Agent.
✅ Delivery & Compliance Checklist
- [x] My code passes the ultimate gatekeeper:
pnpm pre-commitis completely green. - [x] I have signed the CLA if required (see
CLA.md). - [x] I have included new tests to lock down the behavior (or explicitly stated why it's untestable).
- [x] I have strictly adhered to the
DEVELOPMENT.mdarchitectural boundaries. - [x] I have attached a screenshot or screen recording (if this touches the UI).
- [x] I have updated the documentation accordingly (if adding a feature or changing a contract).
📸 Screenshots / Visual Evidence
No screenshot attached yet. Local verification performed by installing the built app and testing the Branch button manually; maintainer-facing visual evidence can be uploaded in the PR UI if requested.
Verification run locally
- [x]
pnpm test -- --run tests/unit/contexts/workspaceCanvas.agentBranch.spec.tsx tests/unit/contexts/workspaceCanvas.agentBranchMounted.spec.tsx tests/unit/contexts/workspaceCanvas.taskAgentSessionRecord.spec.tsx— 3 files / 6 tests passed - [x]
pnpm check - [x]
pnpm lint— 0 warnings / 0 errors - [x]
pnpm line-check:staged
🤖 Generated with Claude Code