feat(cli): distinguish cross-node agents from missing agents on attach 404
Summary
Closes requirement #3 of relay#1449 (clear, distinct failure when agent is on another node vs. not found at all). Phase 1 of 2.
- Before:
agent-relay node agent attach remote-workeron a machine where the agent is running onfinn-miniproducesError: no agent named 'remote-worker'— byte-identical to a typo. The prior proof lane (relay-1449-proof-0810) confirmed 9/9 cross-node attempts hash to the same stderr as a nonexistent-name control. - After: The same command produces
Error: agent 'remote-worker' is registered on node 'finn-mini'; cross-node attach is not yet supported — run \agent-relay node agent attach remote-worker` on that machine`
What changed
fleet-hint.ts(new): best-effort workspace-registry lookup. On 404, callsrelay.agents.get(name)→ readsmetadata.fleet.nodeId→ looks up the human-readable node name viarelay.nodes.list(). All errors swallowed; returnsnullon any failure so the caller falls back to the original message. Injectable factory param keeps it testable without network.attach.ts: added optionalfleetHint?(name) => Promise<string|null>toAttachSnapshotDeps. On 404, awaits the hint and builds an enhanced message; falls through tono agent named 'X'when hint is null or absent.attach-view.ts,attach-drive.ts,attach-passthrough.ts: wiredresolveFleetHintas the defaultfleetHintdep; threaded it throughcaptureAndRenderSnapshotcalls.captureInitialSnapshotinattach.ts: threadsfleetHintfrom its own deps to therendercall so drive/passthrough also get the better message via this code path.
Test plan
-
fleet-hint.test.ts— 9 new unit tests covering: no fleet metadata, agent not in registry, node found bynodeId, node found byid, node roster throws (raw-ID fallback), no matching node (raw-ID fallback),createRelaythrows (no credentials), null metadata -
attach.test.ts— 2 new tests: fleet hint upgrades the message;nullhint preserves original message - Mutation test: replacing
deps.fleetHint ? await deps.fleetHint(agentName) : nullwithnullcauses the cross-node test to fail — confirms tests bite - 279 total tests pass across all 5 affected test files
Phase 2 (Cloud-owned, pending)
The existing cloud terminal-streaming mechanism (cloud/ARCHITECTURE.md:133-176) — broker on 0.0.0.0:9800, HMAC-derived API key, signed 24h preview URL, existing WS protocol — is the right transport for cross-node attach on Daytona fleet nodes. Cloud needs a new endpoint:
POST /workspaces/{wid}/fleet-nodes/{nodeId}/agents/{name}/attach
→ { execUrl: string, apiKey: string, ttl: number }
Relay CLI adds --node <nodeId> to the attach command, calls this endpoint, and substitutes the returned execUrl for the local broker URL. Mode preservation (view/drive/passthrough) is automatic — same WS protocol. The endpoint returns 503 when the node is unreachable (distinct from 404 = agent not present on that node). Physical fleet nodes (barry, finn-mini, sf-mini) are a Phase 3 problem — no signed-URL mechanism exists for boxes without a Daytona-style preview-URL API.
🤖 Generated with Claude Code