feat(cli): add --broker-name override to agent-relay up#939
Conversation
The broker name is otherwise derived from the project directory basename, which means re-running `up` against a workspace that already has an agent with that name fails the relaycast handshake with `agent name '<name>' already exists`. The only existing workarounds were to rename the project directory or rotate the workspace key. Threads a `brokerName` option through `UpOptions`, `CoreDependencies.createRelay`, `createDefaultRelay`, and `createAgentRelayClient` into the SDK's `AgentRelayClient.spawn`, which already supported it. Also forwards `--broker-name` from background re-execs in `childUpArgsForDetachedStart` so programmatic callers (not just CLI users whose argv is preserved verbatim) get the override. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe PR adds a ChangesBroker name CLI option and propagation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/cli/commands/core.test.ts (1)
208-218: ⚡ Quick winAdd a detached-mode assertion for
--broker-nameforwarding.This new test covers stdio startup forwarding, but not the background/detached re-exec path. Please add (or extend an existing detached test) to assert
deps.spawnProcessincludes--broker-name <name>.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/cli/commands/core.test.ts` around lines 208 - 218, The detached/background re-exec path test is missing an assertion that the broker-name flag is forwarded; update the detached-mode test (the one that uses createHarness and inspects deps.spawnProcess) to assert that deps.spawnProcess was called with arguments containing '--broker-name' and the name 'relayfile-dev' (e.g., check the spawnProcess call args include '--broker-name', 'relayfile-dev') so the re-exec invocation forwards the flag just like the direct createRelay path tested by runCommand/createRelayMock.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/cli/commands/core.test.ts`:
- Around line 208-218: The detached/background re-exec path test is missing an
assertion that the broker-name flag is forwarded; update the detached-mode test
(the one that uses createHarness and inspects deps.spawnProcess) to assert that
deps.spawnProcess was called with arguments containing '--broker-name' and the
name 'relayfile-dev' (e.g., check the spawnProcess call args include
'--broker-name', 'relayfile-dev') so the re-exec invocation forwards the flag
just like the direct createRelay path tested by runCommand/createRelayMock.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7f72e929-1c68-4cb7-b436-45ecc9f79813
📒 Files selected for processing (4)
src/cli/commands/core.test.tssrc/cli/commands/core.tssrc/cli/lib/broker-lifecycle.tssrc/cli/lib/client-factory.ts
Summary
--broker-name <name>flag toagent-relay upthat overrides the broker/agent name (otherwise derived from the project directory basename).UpOptions→CoreDependencies.createRelay→createDefaultRelay→createAgentRelayClient→AgentRelayClient.spawn(the SDK already acceptedbrokerName).--broker-nameinchildUpArgsForDetachedStartso programmatic background callers — not just CLI users whose argv is preserved verbatim — see the override on the detached re-exec.Why
Re-running
agent-relay up --workspace-key ...against a workspace that already has an agent with the project's basename fails the relaycast handshake withagent name '<name>' already exists. The previous workarounds were renaming the project directory or rotating the workspace key — both heavy-handed. This gives a per-invocation override.Repro before:
After:
Test plan
npx vitest run src/cli/commands/core.test.ts -t "up"— 33 passed, includes a new positive test asserting--broker-name relayfile-devis forwarded tocreateRelay.🤖 Generated with Claude Code