I recommend adopting Option C (Hybrid) as the architectural target, implemented in two phases.
Implement Option A behavior using the Option C data model.
- Mechanism: When a user assigns a Repository/Worktree to a
SessionGroup, propagate thatWorktreeIdto theSessionMetaof every agent in that group. - Result: All agents share the same directory and branch.
- User Experience: "I assign this team to feature-branch-x."
Expose the existing per-agent WorktreeId in the UI for advanced scenarios.
- Mechanism: Allow power users to override the
WorktreeIdfor specific agents (e.g., "Reviewer Agent" checks outmainwhile "Coder Agent" is onfeature-branch). - User Experience: "I want this specific agent to look at a different version of the code."
- Future-Proofing (Why not A):
SessionMetaalready hasWorktreeId. Hardcoding a singleWorktreeIdonSessionGroupwould restrict us later. By using the per-session field (even if they all point to the same ID initially), we keep the architecture flexible for free. - Complexity Management (Why not B): Forcing per-agent worktrees now creates massive complexity (merging, disk space, synchronization). Shared worktrees are sufficient for 90% of current use cases (collaborative coding, pair programming).
- Correct Abstraction: A "Team" usually works on a "Project" (Repo/Branch). It is the natural default. Divergence is an exception.
-
Update
CreateMultiAgentGroupAsync:- Accept an optional
repoIdandworktreeId. - If provided, assign
WorktreeIdto theSessionMetaof the Orchestrator and all Workers. - Ensure the
SessionGroupalso stores theRepoIdfor context.
- Accept an optional
-
Update
RepoManager.LinkSessionToWorktree:- Ensure it can handle multiple sessions linking to the same worktree (currently it has a single
SessionNamefield, which might be a limitation if strict 1:1 mapping is enforced). Crucial Check:WorktreeInfo.SessionNameis a single string. This needs to change to support multiple sessions (or be ignored for multi-agent groups).
- Ensure it can handle multiple sessions linking to the same worktree (currently it has a single
- Orchestrator Mode: The Orchestrator agent typically plans and delegates. Sharing a worktree means the Orchestrator sees the exact state the workers are producing in real-time. This is generally beneficial for immediate feedback loops.
- OrchestratorReflect Mode: In this mode, the system might benefit from an "isolation sandbox" where a worker tries a change in a separate worktree, runs tests, and only merges if successful. This is a strong argument for Option C (Hybrid) in the long term. A shared worktree (Option A) risks breaking the build for the whole team during experimental changes.
- Recommendation: Start with shared worktrees for simplicity. For advanced reflection cycles that require safe experimentation, leverage the Option C capability later to spawn ephemeral worktrees for specific worker tasks.
WorktreeInfo currently has public string? SessionName { get; set; }.
- Issue: This implies 1 worktree = 1 session.
- Fix: For Phase 1, treat
SessionNameas the "Primary/Owner" session (e.g., the Orchestrator). The UI should rely onSessionMeta.WorktreeIdto find all sessions associated with a worktree, rather than relying on the back-pointer inWorktreeInfo.