Background
Deferred from branch command-registry-refactor.
Reviewer comment: onStartAgent in AppShell.tsx duplicates the agent panel creation flow from collectAgentCommands in agent.ts; consider a shared helper or invoking the agent command with worktree context.
What needs to be done
Extract a shared function (e.g. startAgentSession(...)) that encapsulates the common agent-panel-opening flow used by both agent.open (command palette) and onStartAgent (sidebar/worktree). The helper should handle:
- Resolving dockview API and workspace context
- Finding the editor panel for relative placement
- Reading
agent.backend setting and branching on CLI vs built-in
- Built-in
conversationCreate + error fallbacks
addPanel with consistent panel params
persistWorkspaceRuntime
The helper should accept optional worktree parameters (worktreePath, worktreeBranch, workspaceRoot) so the worktree sidebar entry point can pass branch-aware titles and metadata without duplicating the entire flow.
Why it was deferred
The feedback is valid — the duplication is structural and risks drift — but consolidating two integration points (command registration + AppShell) is better done as a focused follow-up PR to minimize regression surface on the worktree UI changes.
Affected area
- File(s):
packages/renderer/src/commands/agent.ts, packages/renderer/src/components/AppShell.tsx
- Component / module: Agent panel creation, command registry, worktree sidebar
Notes
agent.open is a command handler with no worktree in CommandContext, so "invoke the command" is not plug-and-play — the actionable path is extracting a helper, not dispatching agent.open directly.
- Open question: should the default
agent.open command also accept worktree metadata, or is worktree-only by design for the sidebar entry point?
Background
Deferred from branch
command-registry-refactor.Reviewer comment:
onStartAgentinAppShell.tsxduplicates the agent panel creation flow fromcollectAgentCommandsinagent.ts; consider a shared helper or invoking the agent command with worktree context.What needs to be done
Extract a shared function (e.g.
startAgentSession(...)) that encapsulates the common agent-panel-opening flow used by bothagent.open(command palette) andonStartAgent(sidebar/worktree). The helper should handle:agent.backendsetting and branching on CLI vs built-inconversationCreate+ error fallbacksaddPanelwith consistent panel paramspersistWorkspaceRuntimeThe helper should accept optional worktree parameters (
worktreePath,worktreeBranch,workspaceRoot) so the worktree sidebar entry point can pass branch-aware titles and metadata without duplicating the entire flow.Why it was deferred
The feedback is valid — the duplication is structural and risks drift — but consolidating two integration points (command registration + AppShell) is better done as a focused follow-up PR to minimize regression surface on the worktree UI changes.
Affected area
packages/renderer/src/commands/agent.ts,packages/renderer/src/components/AppShell.tsxNotes
agent.openis a command handler with no worktree inCommandContext, so "invoke the command" is not plug-and-play — the actionable path is extracting a helper, not dispatchingagent.opendirectly.agent.opencommand also accept worktree metadata, or is worktree-only by design for the sidebar entry point?