Repository navigation
feat: act on another machine's services from the CLI and MCP - #97
Merged
Merged
Conversation
PR 5 of remote machines (docs/remote-machines.md, "CLI" and "MCP"). The daemon already viewed and controlled other machines for the app; a terminal and an agent can now do the same. - `--machine` on `services status`, `logs`, `dev`, `stop` and `restart`. It resolves an exact id, then an exact name ignoring case, among the active machines; this machine's own id or name acts locally. A service must be unique on the target or come with `--project`. - `dev --machine` refuses every option but `--project`, `--env` and `--profile` before asking the daemon anything. - A control holds a watch open, since the daemon sends one only over an open session, and its first snapshot gives what the control expects. What that snapshot already refuses is not sent. - Human output on a terminal, JSON otherwise. A refusal says what the app says for its code and exits 2; an outcome that never came back prints the fresh state and exits 3; a run that failed exits 1. - `remote_inventory` and `remote_output_read` errors now carry their code on the management socket, so the CLI and agents see it. - MCP: `list_machines`, and `machine` on the six service tools; with it, `cwd` is ignored and `service_start` takes only service, project, env and profile. Refusals of controls and lost outcomes tell the agent what to do next.
A Codex review of the remote CLI and MCP found four ways a request could act on the wrong run or the wrong machine, or say less than the contract asks: - MCP tools without a `machine` argument ignored one and ran here, in the server's folder. They now refuse it before building or running anything. - A legacy run that had already stopped blocked a fresh start the target allowed. Only a live legacy run is refused before sending; otherwise the target's `controls` decide. - `logs --machine --follow` stopped when the service restarted. On `gone`, it now reads the service's current run from the target's snapshot and follows it from offset 0, and a restart racing the first read is read the same way. - A `conflict` printed only "B changed in the meantime." It now prints the service's fresh state with it, in text and JSON, still exits 2, and never resends the control. docs/remote-machines.md says `dev` on this machine's own id behaves as `dev --in-app`, and records the four behaviours above.
…and keep the watch through a conflict's report After a restart between the snapshot and the first read, `logs --machine` without a cursor tailed the new run, so a run longer than --lines lost its first lines although the note said it was read from the start. And the control's watch was dropped before the report fetched the fresh state, so a conflict's state could need a new handshake or go missing.
teo-goulois
added a commit
that referenced
this pull request
Nov 9, 2026
Brings in --machine for the CLI and MCP (#97). - docs/remote-machines.md: keeps #97's CLI output and MCP snapshot text and #98's pairing over SSH exceptions. - src/cli/machines.rs: machines() now takes the management client, so the SSH pairing passes ctx.mgmt_client. - The CLI's --machine end-to-end test holds a session between A and B and checks that both agree on the latest protocol (3, pair.saved, or later) for the whole run. The CLI and MCP code from #97 never checks the session version, so nothing else needed to change.
This was referenced Nov 9, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 5 of remote machines: the contract's "CLI" and "MCP" sections of
docs/remote-machines.md. The daemon already did the work for the app (#72, #81, #83, #84); this adds the CLI layer and the agent tools on top.CLI
--machine <name|id>onservices status,logs,dev,stopandrestart.devthen runs as--in-app, since the options--machineallows are exactly the ones--in-apptakes.--env; a name in two projects needs--projectand lists the matches.dev --machinerefuses a command after--,--detach,--in-app,--env-file,--confirm-profile,--domain,--replace,--no-maskingand the hidden launch flags, before asking the daemon (refused_argument, exit 2).remote_watchopen. Its first snapshot gives theexpect. A control the snapshot already refuses (percontrols, or a live legacy run, which the app relaunches after a confirmation) isn't sent. A legacy run that already stopped is only a record: the target'scontrolsdecide.remoteErrorMessage(no Rust copy existed to share), and exits 2.unknownis a progress line ("Outcome unknown. Checking B…").lostprints the fresh status and exits 3, as the contract says.conflictprints "B changed in the meantime." with the service's fresh state (statusin JSON), exits 2, and is never resent.failedexits 1.logs --machine: the last--lines,--cursor <runId>:<offset>, and-f. It prints the next cursor as locallogsdoes. When the service restarts (gone), during-for racing the first read, it reads the service's current run from the target's snapshot and goes on from offset 0.Daemon and client
remote_inventoryandremote_output_readerrors now carry theircodeon the management socket.DaemonConnectionError::Remote { code, message }, so targets' codes reach the CLI and agents.MCP
list_machinestool (machines --json).machineonlist_services,service_status,service_logs,service_start,service_stopandservice_restart, and on no other tool. With it,cwdis ignored. Any other tool givenmachinefails before building or running anything, instead of acting on this machine.list_servicesandservice_statusboth map toservices status --machine.service_startwithmachinefails onbackground,env_files,confirm_profile,command,domainandreplace, saying the target decides how its services start. It needsserviceand never creates a project.control_disabledandbackground_disabledadd a hint to ask the user to allow controls.lostadds a hint to checkservice_statusfirst.unslop.Docs
docs/README.md, as restructured by docs: rewrite the README as the front door, and fit the GitHub templates to an open-source project #89–docs: make the contributor docs and agent files accurate for 1.6.0 #91, which merged while this was in progress) get a "From a terminal or an agent" paragraph.docs/remote-machines.mdrecords the details above in "CLI" and "MCP".changes/remote-machines-from-the-cli-and-agents.md(type: new).Pairing over SSH (
docs/remote-cli-and-agent-pairing) is untouched. This branch starts frommain, not from that branch.Tests
lostwith fresh status and exit 3, failed exit 1, progress, snapshot pre-checks, cursors, and each MCP tool'smachineargument and refusals, includingcwdbeing ignored, every other tool refusingmachinewithout running, a stopped legacy run allowing a start, and aconflictwith its fresh state.src/daemon/remote/tests/cli.rs): the CLI layer against a real management socket served by viewer A's link, with B on the fake relay. Covers resolving, status, logs tail, cursor and follow to the end of the run, a follow that goes on with the run replacing a restarted one, a restart between the snapshot and the first read, a stop with its progress, and acontrol_disabledrefusal that sends nothing.tests/remote_cli.rs):dev --machinerefusals exit 2 with JSON.cargo fmt,cargo clippy -- -D warningsandcargo testpass.tests/app_bridge.rsfailed once on its known timing flake and passed on rerun.Devvariant needed#[allow(clippy::large_enum_variant)]on the clapCommandsenum.