feat(workspace): headless `workspace` commands and a non-interactive `link`
Issue for this PR
No tracking issue. Gap found while dogfooding workspaces: there is no way to link a project, or see or change its workspace state, from a script, a devcontainer postCreateCommand or CI.
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
altimate-code link refused to run without a TTY, and Refresh / Sync / Unlink / status existed only in the TUI /workspace menu (Refresh and Sync also over serve). When link reported unsynced memory, all it could say was "Run /workspace → Sync in the TUI".
New, behind the same ALTIMATE_WORKSPACE=1 pilot gate as link (off, a hidden stub explains how to opt in):
altimate-code workspace status [--json] [--directory]
altimate-code workspace refresh [--json] [--directory]
altimate-code workspace sync [--json] [--directory]
altimate-code workspace unlink [--yes] [--json] [--directory]
altimate-code link --workspace <name|id> | --create [name] [--yes]
- The
workspacesubcommands are thin wrappers overManage.status / refresh / sync / unlink— the same code the TUI menu and theserveroutes run.statusresolves through the service when there is no cached row, so a fresh clone reports its server-side link. link --workspacematches by numeric id first, then by exact name (case-insensitive); an unknown name lists the available workspaces, an ambiguous one lists the ids.--createdefaults to the repo name.- Replacing an existing link (and
unlinkwithout a terminal) requires--yes. Unlike the interactive picker, a failed "which workspace is this linked to" pre-check stops instead of retrying a conflict as a re-link. - Exit codes:
0ok,1failed,2request to change (not signed in, missing--yes, ambiguous name),3project not linked. - Without a terminal, link's spinners print plain lines instead of redrawing every frame onto one line of a CI log.
link's unsynced-memory hints now namealtimate-code workspace syncalongside the TUI menu.- Docs:
usage/cli.mdcommand table and Workspaces section.
Not included: --shared for --create. The create-and-bind endpoint (CreateAndBindRequest) has no privacy field and CLI creates are always private, so this needs a backend change first; until then a workspace can be shared from the web app.
How did you verify your code works?
End to end with a binary built from this branch against a live tenant, in a scratch repo with a unique remote, linking to an existing test workspace (no workspaces created):
| Command | Result | Exit |
|---|---|---|
workspace status (unlinked) | "This project is not linked to a workspace." | 3 |
link (no flags, no TTY) | unchanged TTY error | 1 |
link --workspace 35 | linked | 0 |
workspace status --json | linked, memory and skills-synced fields | 0 |
link --workspace 35 again | "Already linked … nothing changed." | 0 |
link --create … while linked, no --yes | refused, names --yes | 2 |
link --workspace no-such-name | lists available workspaces | 1 |
workspace sync | "Sent 0, already in the workspace 0." | 0 |
workspace refresh | skills up to date, memory reload noted | 0 |
workspace unlink (no TTY, no --yes) | refused, names --yes | 2 |
workspace unlink --yes | unlinked | 0 |
workspace status | not linked | 3 |
workspace status with the pilot off | hidden stub's opt-in message | 1 |
The run surfaced the spinner-frame noise in non-TTY output, fixed here and re-verified.
Tests: test/cli/workspace-command.test.ts (status / sync / refresh wording and exit codes, unknown-vs-zero, ago boundaries, --workspace matching by id, name, ambiguity); link-seed-message and workspace-pilot suites pass. Typecheck and marker guard clean. Full suite: 14,379 pass, 8 fail — 6 are MCP tests reading the developer's real ~/.claude.json (#1386), and 2 server HttpApi tests (httpapi-workspace, httpapi-error-middleware) that fail only in the full run; both files pass in isolation on this branch and on main (13/13).
Screenshots / recordings
N/A — CLI text output (table above).
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
🤖 Generated with Claude Code
https://claude.ai/code/session_018fJ3X7pcGT4R9yzjsJnqsV
Summary by cubic
Adds headless workspace status|refresh|sync|unlink subcommands and non-interactive link --workspace/--create flags so scripts, devcontainers, and CI can manage a project's workspace state without the TUI.
- All gated behind the existing
ALTIMATE_WORKSPACE=1pilot; the subcommands reuse the same manage code as the TUI menu andserveroutes. link --workspacematches numeric id first, then exact name (case-insensitive); unknown names list available workspaces, ambiguous ones list ids.--createdefaults to the repo name, is a no-op when the project is already linked to that name, and refuses an existing namesake unless--allow-duplicate. Replacing an existing link — orunlinkwithout a terminal — requires--yes; headless create never opens a browser. Linking or creating for the workspace already linked confirms the link on this machine so a laterworkspace syncaccepts it; the confirmation runs as the captured credential and is judged by the approved row this call wrote, matched by timestamp so an earlier approval never vouches for a later refused write, not the seed outcome (the seed also reportsaccount-changedafter a successful write, when only its memory pass was skipped), and a refused or failed record exits 1 instead of reporting the link confirmed. The pre-check, list, bind, and confirm all run under one captured credential so an account switch cannot mix tenants.- Exit codes:
0ok,1failed,2request to change (not signed in, missing--yes, ambiguous name),3project not linked. Every subcommand resolves the link first: a confirmed "not linked" is3, but an unreachable service is1, never "not linked". With--json,okis true exactly when the exit is0. syncrefuses a link never confirmed on this machine (exit2, pointing atlink --workspace <id>) and one the service could not confirm just now (exit1); an unlink that leaves workspace skills behind exits1, and unlink touches nothing when the service says the project is not linked.statusflags a link found only on the service, notes when a "not linked" answer came from the recent-miss cache, and distinguishes unreadable memory from "off". Workspace names have control characters stripped when printed.- Without a TTY, link's spinners print plain lines instead of redrawing frames, and unsynced-memory hints now name
altimate-code workspace syncalongside the TUI menu. --sharedis not included: the create-and-bind endpoint has no privacy field, so CLI-created workspaces stay private until shared from the web app.- The trace-context test's MCP stub gains the
listMetaandsnapshotmembers #1308 added, fixing the pre-push typecheck.
Summary by CodeRabbit
- New Features
- Added workspace commands to check status, refresh skills, sync memory, and unlink a project, with JSON output and project-directory selection.
- Added noninteractive workspace linking by name or ID, plus workspace creation. Confirmation options control relinking and duplicate-name handling.
- Bug Fixes
- Prevented memory syncing through unconfirmed or stale workspace links and clarified when local memory status is unreadable.
- Documentation
- Documented workspace commands, linking and creation options, confirmation rules, and exit codes.