Maestro icon indicating copy to clipboard operation
Maestro copied to clipboard

CLI-IPC: WebSocket bridge for provider agents to trigger Maestro UI actions

Open pedramamini opened this issue 8 months ago • 3 comments

Problem

Provider agents running inside Maestro have no way to trigger UI-side actions in the desktop app. After an agent creates files, modifies the workspace, or generates auto-run documents, the user must manually refresh the file tree, open files, or configure auto-run. This creates friction in agentic workflows where the agent knows what it just changed but can't tell Maestro to reflect it.

Proposed Solution

Add a WebSocket-based IPC bridge between the CLI (maestro-cli) and the Electron app, enabling agents to issue commands like:

maestro-cli refresh-files          # Refresh the file tree panel
maestro-cli open-file <path>       # Open a file in a preview tab
maestro-cli refresh-auto-run       # Refresh the auto-run document list
maestro-cli auto-run <docs...>     # Configure and launch an auto-run
maestro-cli status                 # Check if Maestro is running
maestro-cli send <id> <msg> --tab  # Send + focus the agent's tab

Architecture

Electron starts → auto-starts web server → writes discovery file (cli-server.json)
CLI reads discovery file → connects WebSocket → sends commands
Electron shuts down → deletes discovery file

The existing Fastify + WebSocket server (src/main/web-server/) is reused. A discovery file (~/.config/maestro/cli-server.json) makes the server's random port and security token discoverable by the CLI.

Implementation Plan (4 Phases)

Full implementation documents attached as a gist with 4 phase files (20 tasks total):

CLI-IPC-01.md CLI-IPC-02.md CLI-IPC-03.md CLI-IPC-04.md

Phase Focus Tasks
01 Server discovery file + always-on CLI server 4
02 New WebSocket message types + renderer handlers 7
03 CLI WebSocket client + new CLI commands 7
04 Auto-run configuration command + system prompt integration 6

Phase Summary

Phase 01 — Creates src/shared/cli-server-discovery.ts (following cli-activity.ts pattern), auto-starts the web server on app launch, writes/deletes the discovery file on startup/shutdown.

Phase 02 — Adds 3 new WebSocket message types (open_file_tab, refresh_file_tree, refresh_auto_run_docs) across the 5-file callback chain: messageHandlers.ts → CallbackRegistry.ts → WebServer.ts → web-server-factory.ts → preload/process.ts. Wires renderer handlers via useRemoteIntegration.ts using CustomEvent dispatch to App.tsx.

Phase 03 — Creates MaestroClient WebSocket client (src/cli/services/maestro-client.ts) with connect(), sendCommand<T>(), and withMaestroClient() helper. Adds 4 new CLI commands: open-file, refresh-files, refresh-auto-run, status. Adds --tab flag to existing send command.

Phase 04 — Adds configure_auto_run WebSocket message type with launch/save-as-playbook support. Creates auto-run CLI command for configuring and launching auto-runs from the terminal. Updates maestro-system-prompt.md so agents know these commands exist.

What This Enables

Once implemented, the system prompt tells agents about these commands. An agent that just created 5 auto-run documents can:

maestro-cli refresh-auto-run          # UI immediately shows new docs
maestro-cli auto-run doc1.md --launch # Launch the auto-run

An agent that modified workspace files can:

maestro-cli refresh-files             # File tree updates without user action
maestro-cli open-file ./new-file.ts   # Opens it for the user to see

This is a stepping stone toward the full Agent SDK integration (#340) and complements Maestro Cue (#367) event-driven automation.

Related

  • #340 — Claude Agent SDK integration (hooks like PostToolUse would be the native equivalent)
  • #367 — Maestro Cue (event-driven automation, file.changed triggers)

pedramamini avatar Mar 04 '26 01:03 pedramamini

@pedramamini this should be closed as done right?

chr1syy avatar Mar 19 '26 06:03 chr1syy

This issue has been automatically marked as stale because it has had no activity for 60 days. It will be closed in 14 days if no further activity occurs. If it is still relevant, leave a comment or remove the stale label to keep it open. Thank you for your contributions.

github-actions[bot] avatar Jul 16 '26 02:07 github-actions[bot]

Thanks for writing this up in such detail - the phased plan made it straightforward to implement, and all four phases have since shipped. Verified against the current codebase:

Phase 01 - discovery file + always-on server

  • src/shared/cli-server-discovery.ts with writeCliServerInfo() / readCliServerInfo() / deleteCliServerInfo() / isCliServerRunning()
  • Written on server start (src/main/ipc/handlers/web.ts), deleted on shutdown (src/main/app-lifecycle/quit-handler.ts)

Phase 02 - WebSocket message types

  • open_file_tab, refresh_file_tree, refresh_auto_run_docs handled in src/main/web-server/handlers/messageHandlers.ts, wired through the callback chain to the renderer

Phase 03 - CLI client + commands

  • MaestroClient / withMaestroClient() in src/cli/services/maestro-client.ts
  • maestro-cli open-file, refresh-files, refresh-auto-run, status all present
  • --tab flag added to send

Phase 04 - auto-run configuration + prompt integration

  • configure_auto_run message type with --launch and --save-as (save-as-playbook) support
  • maestro-cli auto-run command, plus worktree support that went past the original plan
  • Commands documented for agents in src/prompts/_maestro-cli.md

The surface also grew beyond the original proposal since then - open-browser, open-terminal, notify toast / notify flash, and the profiling commands all ride the same bridge.

Closing this out as complete. Thanks again for the contribution!

pedramamini avatar Jul 25 '26 20:07 pedramamini