feat(cli): show active workspace via workspace current and list marker#126
feat(cli): show active workspace via workspace current and list marker#126khaliqgant merged 1 commit intomainfrom
workspace current and list marker#126Conversation
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@cmd/relayfile-cli/main.go`:
- Around line 2308-2311: The current code swallows parse/config errors from
loadWorkspaceCatalog() causing activeWorkspaceName and runWorkspaceCurrent to
return empty values and emit “no active workspace”; change the control flow so
loadWorkspaceCatalog() errors are propagated and surfaced: update
activeWorkspaceName to return an error (e.g., (string, *Catalog, error) or
similar) instead of converting catalog errors into empty strings, and update
runWorkspaceCurrent to check and return/log that error (rather than treating
empty values as “no active workspace”); apply the same change to the other
occurrence around the loadWorkspaceCatalog call (the block referenced at lines
~2332-2335) so all catalog-parse/config errors are reported correctly.
- Around line 2246-2256: The active marker logic compares the listed entry
(variable name) only against activeWorkspaceName(tokenValue), but remote admin
lists emit workspace IDs so the marker can be missed when Name != ID; update the
code that sets marker inside the emit closure (and the similar block at
2269-2271) to also fetch and compare the active workspace ID (e.g., call an
activeWorkspaceID(tokenValue) helper or change activeWorkspaceName to return
both id and name) and mark the entry when name equals either the active name or
the active ID; ensure you retrieve the active ID once before using the emit
closure to avoid repeated calls.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 70eb5ba6-fdd1-4815-b2ae-1764f79f0d04
📒 Files selected for processing (5)
.trajectories/completed/2026-05/traj_h99ldnvo1d26.json.trajectories/completed/2026-05/traj_h99ldnvo1d26.md.trajectories/index.jsoncmd/relayfile-cli/main.gocmd/relayfile-cli/main_test.go
| activeName, _ := activeWorkspaceName(tokenValue) | ||
| emit := func(name string) { | ||
| if *namesOnly || activeName == "" { | ||
| fmt.Fprintln(stdout, name) | ||
| return | ||
| } | ||
| marker := " " | ||
| if name == activeName { | ||
| marker = "* " | ||
| } | ||
| fmt.Fprintln(stdout, marker+name) |
There was a problem hiding this comment.
Active marker can be wrong when remote list entries are IDs.
activeWorkspaceName prefers catalog names, but remote admin listing emits workspace IDs. If Name != ID, the active workspace won’t get the * marker.
💡 Proposed fix
activeName, _ := activeWorkspaceName(tokenValue)
+ activeID := ""
+ if record, ok := workspaceRecordByName(activeName); ok {
+ activeID = strings.TrimSpace(record.ID)
+ }
emit := func(name string) {
if *namesOnly || activeName == "" {
fmt.Fprintln(stdout, name)
return
}
marker := " "
- if name == activeName {
+ if name == activeName || (activeID != "" && name == activeID) {
marker = "* "
}
fmt.Fprintln(stdout, marker+name)
}Also applies to: 2269-2271
🤖 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 `@cmd/relayfile-cli/main.go` around lines 2246 - 2256, The active marker logic
compares the listed entry (variable name) only against
activeWorkspaceName(tokenValue), but remote admin lists emit workspace IDs so
the marker can be missed when Name != ID; update the code that sets marker
inside the emit closure (and the similar block at 2269-2271) to also fetch and
compare the active workspace ID (e.g., call an activeWorkspaceID(tokenValue)
helper or change activeWorkspaceName to return both id and name) and mark the
entry when name equals either the active name or the active ID; ensure you
retrieve the active ID once before using the emit closure to avoid repeated
calls.
| catalog, err := loadWorkspaceCatalog() | ||
| if err != nil { | ||
| return "", "" | ||
| } |
There was a problem hiding this comment.
workspace current hides catalog parse errors as “no active workspace.”
When loadWorkspaceCatalog() fails, activeWorkspaceName returns empty values, and runWorkspaceCurrent emits a misleading “no active workspace” error instead of the real parse/config error.
💡 Proposed fix
-func activeWorkspaceName(token string) (string, string) {
+func activeWorkspaceName(token string) (string, string, error) {
...
catalog, err := loadWorkspaceCatalog()
if err != nil {
- return "", ""
+ return "", "", err
}
if name := strings.TrimSpace(catalog.Default); name != "" {
- return name, "default"
+ return name, "default", nil
}
- return "", ""
+ return "", "", nil
}
- name, source := activeWorkspaceName(tokenValue)
+ name, source, err := activeWorkspaceName(tokenValue)
+ if err != nil {
+ return err
+ }Also applies to: 2332-2335
🤖 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 `@cmd/relayfile-cli/main.go` around lines 2308 - 2311, The current code
swallows parse/config errors from loadWorkspaceCatalog() causing
activeWorkspaceName and runWorkspaceCurrent to return empty values and emit “no
active workspace”; change the control flow so loadWorkspaceCatalog() errors are
propagated and surfaced: update activeWorkspaceName to return an error (e.g.,
(string, *Catalog, error) or similar) instead of converting catalog errors into
empty strings, and update runWorkspaceCurrent to check and return/log that error
(rather than treating empty values as “no active workspace”); apply the same
change to the other occurrence around the loadWorkspaceCatalog call (the block
referenced at lines ~2332-2335) so all catalog-parse/config errors are reported
correctly.
Adds `relayfile workspace current` to print the workspace that
`resolveWorkspaceRecord("")` would pick — the same precedence used by
every CLI command that defaults to "the active workspace" (env
`RELAYFILE_WORKSPACE` > workspace id embedded in the token >
catalog `default`). `--verbose` reports the resolution source.
Also marks the active line in `relayfile workspace list` with a leading
`* `, padding inactive lines with two spaces (git-branch convention).
The marker is suppressed when no active workspace can be resolved, and
`--names-only` restores the legacy bare-name output for scripts that
parse the list.
Adds 4 new tests; updates 2 existing list tests for the marker contract.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4d6a6f8 to
4652eea
Compare
Summary
relayfile workspace currentsubcommand: prints the workspace the CLI defaults to when noWORKSPACEarg is passed (the sameresolveWorkspaceRecord("")precedence: envRELAYFILE_WORKSPACE→ workspace id in the token → catalogdefault).--verbosereports the source.relayfile workspace listnow marks the active line with a leading*(git-branch style), pads inactive lines with two spaces, and suppresses the marker when no active workspace can be resolved.relayfile workspace list --names-onlyrestores the legacy bare-name output for scripts that parse the list.Why
Today there's no first-class way to ask "which workspace is active?" — users have to
cat ~/.relayfile/workspaces.jsonor runrelayfile status(which actually contacts the server). Andworkspace listprints names with no indicator of which one any future command will use, so it's easy to lose track of whichdefaultyou're working against.Examples
Test plan
go test ./cmd/relayfile-cli/— full suite passesTestWorkspaceCurrentPrintsActiveWorkspace— default-from-catalog path with and without--verboseTestWorkspaceCurrentReportsEnvOverride— env beats catalog default and source string mentionsRELAYFILE_WORKSPACETestWorkspaceCurrentErrorsWhenNoneActive— exits non-zero with a fix-it message instead of printing an empty lineTestWorkspaceListNamesOnlyRestoresBareOutput—--names-onlyproduces unmarked outputworkspace listtests for the new marked default contract🤖 Generated with Claude Code