Resolve the right workspace key for CLI commands in a project directory
Merged
WI
4mo ago+720+720+012345678901234567890123456789-41-41-01234567890123456789
Summary
Fixes the class of bug where agent-relay fleet nodes (and other SDK-backed commands) showed the wrong roster because they resolved the machine-global active workspace key instead of the workspace the current directory's broker actually joined. Three related changes:
--wkshorthand for--workspace-keyon every SDK-backed command (fleet nodes,workspace,integration,webhook, …) and onup/node up. It's folded intoworkspaceKeyby apreActionhook so all downstream readers see one canonical option; an explicit--workspace-keystill wins. (Commander v12 can't alias two long flags to one attribute, hence the fold.)uprecords the workspace it joins.agent-relay upwrites the workspace key it joined — passed via--workspace-key/--wkor auto-minted — into the project data dir (.agentworkforce/relay/workspace-key.json, git-excluded,0o600, same posture asconnection.json). SDK-backed commands run in that directory resolve that key ahead of the global active workspace, sofleet nodes/node …reflect the broker's real workspace. An explicit--workspace-key/--wkorRELAY_WORKSPACE_KEY/RELAY_API_KEYstill overrides it.- Precedence:
flag→RELAY_WORKSPACE_KEY/RELAY_API_KEY→ project broker key (this CWD) → global active store.
- Precedence:
fleet nodeswarns when the key was inferred from that project record. The note goes to stderr (stdout JSON stays clean), so a stale broker workspace is explainable rather than silent.resolveWorkspaceKeyWithSourcewas added to report the resolution source (flag | env | project | store).
Resolution stays synchronous — no async refactor across the command surface — and keeps working after the broker stops.
Test Plan
- Tests added/updated
--wkfold on SDK commands (fleet.test.ts) and onup/node up(core.test.ts), incl. explicit-flag-wins.- Project-key store round-trip, malformed/blank handling,
0o600(project-workspace-key.test.ts). resolveWorkspaceKey/resolveWorkspaceKeyWithSourceprecedence + source reporting (sdk-client.test.ts).fleet nodeswarn-on-project-source / no-warn-on-explicit-key (fleet.test.ts).
- Manual testing completed — logic is unit-covered; a full run against a live Relaycast workspace wasn't possible from this environment.
Note: one unrelated suite (node-definition-loader.test.ts) fails identically on main in a fresh clone (jiti importing an example needs the workspace packages built); it's not touched here.
Screenshots
N/A — CLI flag + stderr note.
🤖 Generated with Claude Code
Generated by Claude Code