Skip to content

[Deferred] Extract shared helper for agent panel creation (DRY agent.open + onStartAgent) #55

@Cheezeiii365

Description

@Cheezeiii365

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions