How runmaestro/maestro works
Purpose and Entry Points
Maestro is a cross-platform desktop orchestrator for multiple local/remote AI coding-agent sessions, automation, project worktrees, and remote control. Its primary Electron entry is src/main/index.ts; the React desktop renderer starts at src/renderer/main.tsx and composes src/renderer/App.tsx. Headless automation is exposed through the CLI at src/cli/index.ts; src/maestro-p/index.ts is a companion process-oriented interface.
Runtime Topology and Boundaries
The application separates Electron main-process authority from an untrusted renderer. Main owns windows, filesystem, agent subprocesses, persistence, IPC, local web services, and privileged integrations; renderer owns interactive UI/state. Preload bridges expose constrained APIs between them: src/main/preload/index.ts, src/main/ipc/handlers/index.ts, and src/renderer/services/ipcWrapper.ts. Shared contracts and domain types live in src/shared/, notably src/shared/agent-run/types.ts and src/shared/cue-pipeline-types.ts.
Agent Session Execution
Agent definitions, discovery, capabilities, spawn choices, and usage sampling are centralized in src/main/agents/definitions.ts, src/main/agents/detector.ts, and src/main/agents/capabilities.ts. The process layer launches local PTY/child processes, OpenCode servers, or SSH commands and normalizes lifecycle streams through src/main/process-manager/ProcessManager.ts, src/main/process-manager/runners/SshCommandRunner.ts, and src/main/parsers/parser-factory.ts. Output, errors, session IDs, token usage, and exits are forwarded to UI/state through src/main/process-listeners/index.ts.
Desktop Session Workspace
The renderer presents concurrently managed AI, terminal, browser, and file tabs. Session lifecycle and execution coordination are concentrated in src/renderer/hooks/agent/useAgentExecution.ts, src/renderer/hooks/session/useSessionLifecycle.ts, and src/renderer/stores/sessionStore.ts. The principal workspace composition is src/renderer/components/AppShell.tsx, src/renderer/components/MainPanel/MainPanel.tsx, and src/renderer/components/TabBar/TabBar.tsx. Provider session persistence/import is implemented in src/main/storage/claude-session-storage.ts, src/main/storage/codex-session-storage.ts, and src/main/storage/opencode-session-storage.ts.
Auto Run, Campaigns, and Worktrees
Auto Run executes markdown/playbook tasks or goal-driven work in fresh/resumed agent sessions, with recovery and event capture. Main-process capture/recovery is in src/main/agent-run/capture-service.ts, src/main/agent-run/recover-runs.ts, and src/main/agent-run/producers.ts; UI control is rooted in src/renderer/components/AutoRun/AutoRun.tsx. Shared campaign and run contracts sit in src/shared/campaign/types.ts and src/shared/agent-run/lifecycle.ts. Git worktrees provide isolation for parallel agent work; worktree workflows are surfaced via src/renderer/hooks/batch/useWorktreeManager.ts.
Cue Automation and Orchestration
Cue is a durable pipeline engine with YAML-configured graphs, trigger sources, fan-in/fan-out handling, queued runs, recovery, and agent/shell/notification executors. Its core control path is src/main/cue/cue-engine.ts, src/main/cue/cue-dispatch-service.ts, and src/main/cue/cue-run-manager.ts. Trigger adapters include filesystem, schedule, GitHub polling, heartbeat, and task scanning under src/main/cue/triggers/. The visual graph editor serializes between UI graph state and pipeline YAML through src/renderer/components/CuePipelineEditor/CuePipelineEditor.tsx and src/renderer/components/CuePipelineEditor/utils/pipelineToYaml.ts.
Extensions, Remote Access, and External Services
The plugin platform verifies identity/signatures, gates permissions and network egress, and runs extensions in sandbox/background/panel hosts: src/main/plugins/plugin-manager.ts, src/main/plugins/plugin-sandbox-host.ts, and src/shared/plugins/permissions.ts. A built-in HTTP/WebSocket server enables mobile/remote control via src/main/web-server/WebServer.ts, src/main/web-server/routes/wsRoute.ts, and src/web/hooks/useWebSocket.ts; remote tunneling is managed by src/main/tunnel-manager.ts. External dependencies are locally installed AI CLIs (Claude Code, Codex, OpenCode, Factory Droid, Copilot CLI, Qwen, Oh My Pi), SSH/Git, optional GitHub polling/CLI, Cloudflare tunneling, and WakaTime/Sentry integrations.
Persistence and Observability
Application settings and migrations use main-process stores in src/main/stores/index.ts. Durable analytics, usage, and lifecycle data are handled by src/main/stats/stats-db.ts, src/main/stats/session-lifecycle.ts, and src/main/stats/token-usage/token-usage-accessor.ts. These feed the renderer’s usage dashboard and operational views rather than being the execution source of truth.
Main entry points: index.ts Electron main · ProcessManager.ts Process manager · cue-engine.ts Cue pipeline engine · useAgentExecution.ts Session coordination
Components 23
Entry points
- Electron main · Owns desktop authority and privileged services.
src/main/index.ts - React renderer
src/renderer/main.tsx - Headless CLI
src/cli/index.ts - Process interface
src/maestro-p/index.ts
Desktop boundary
- Preload & IPC · Constrained API boundary between renderer and main.
src/main/preload/index.ts - IPC wrapper
src/renderer/services/ipcWrapper.ts - Session workspace · Composes tabs and concurrent agent, terminal, browser, and file views.
src/renderer/components/AppShell.tsx - Session coordination · Coordinates session lifecycle and agent execution.
src/renderer/hooks/agent/useAgentExecution.ts - Shared contracts · Cross-runtime agent-run, cue, and campaign types.
src/shared/agent-run/types.ts
Agent execution
- Agent catalog · Selects installed agents, capabilities, and spawn options.
src/main/agents/definitions.ts - Process manager · Launches PTY, child-process, OpenCode, and SSH executions.
src/main/process-manager/ProcessManager.ts - Process event streams · Forwards output, errors, usage, and exits to UI state.
src/main/process-listeners/index.ts - AI CLIs, SSH & Git
- Provider session storage · Persists and imports Claude, Codex, and OpenCode sessions.
src/main/storage/claude-session-storage.ts
Automation
- Auto Run · Runs playbook or goal work with capture and recovery.
src/main/agent-run/capture-service.ts - Cue pipeline engine · Dispatches queued YAML pipeline runs and recovery.
src/main/cue/cue-engine.ts - Cue triggers · Filesystem, schedule, GitHub, heartbeat, and task sources.
src/main/cue/triggers/cue-trigger-source-registry.ts - Cue graph editor · Serializes visual pipeline graphs to YAML.
src/renderer/components/CuePipelineEditor/CuePipelineEditor.tsx
Extensions & remote
- Plugin platform · Verifies plugins and gates permissions, hosts, and egress.
src/main/plugins/plugin-manager.ts - Remote control server · Serves mobile and remote-control connections.
src/main/web-server/WebServer.ts - Tunnel manager
src/main/tunnel-manager.ts
Other components
- Settings & migrations
src/main/stores/index.ts - Usage & lifecycle analytics · Operational data feeds dashboard views, not execution control.
src/main/stats/stats-db.ts
Connections 28
- React renderer → Session workspace: renders
- Session workspace → Session coordination: coordinates sessions
- Session coordination → IPC wrapper: invokes
- IPC wrapper → Preload & IPC: bridges
- Preload & IPC → Electron main: IPC handlers
- Electron main → Agent catalog: owns
- Agent catalog → Process manager: selects runner
- Process manager → AI CLIs, SSH & Git: launches
- Process manager → Process event streams: emits lifecycle
- Process event streams → Session coordination: updates UI
- Process manager → Provider session storage: persists sessions
- Electron main → Auto Run: hosts
- Auto Run → Process manager: creates or resumes runs
- Electron main → Cue pipeline engine: hosts
- Cue triggers → Cue pipeline engine: start runs
- Cue pipeline engine → Process manager: executes agent or shell stages
- Cue graph editor → Cue pipeline engine: edits pipeline YAML
- Electron main → Plugin platform: hosts
- Electron main → Remote control server: hosts
- Tunnel manager → Remote control server: exposes
- Electron main → Settings & migrations: reads settings
- Process event streams → Usage & lifecycle analytics: records usage
- Usage & lifecycle analytics → Session workspace: dashboard data
- Shared contracts → Session coordination: types
- Shared contracts → Auto Run: run contracts
- Shared contracts → Cue pipeline engine: pipeline contracts
- Headless CLI → Auto Run: headless automation
- Process interface → Process manager: process control