feat(workspace): headless `workspace` commands and a non-interactive `link`

Merged
SA
2mo ago
+1179-39

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 workspace subcommands are thin wrappers over Manage.status / refresh / sync / unlink — the same code the TUI menu and the serve routes run. status resolves through the service when there is no cached row, so a fresh clone reports its server-side link.
  • link --workspace matches by numeric id first, then by exact name (case-insensitive); an unknown name lists the available workspaces, an ambiguous one lists the ids. --create defaults to the repo name.
  • Replacing an existing link (and unlink without 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: 0 ok, 1 failed, 2 request to change (not signed in, missing --yes, ambiguous name), 3 project 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 name altimate-code workspace sync alongside the TUI menu.
  • Docs: usage/cli.md command 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):

CommandResultExit
workspace status (unlinked)"This project is not linked to a workspace."3
link (no flags, no TTY)unchanged TTY error1
link --workspace 35linked0
workspace status --jsonlinked, memory and skills-synced fields0
link --workspace 35 again"Already linked … nothing changed."0
link --create … while linked, no --yesrefused, names --yes2
link --workspace no-such-namelists available workspaces1
workspace sync"Sent 0, already in the workspace 0."0
workspace refreshskills up to date, memory reload noted0
workspace unlink (no TTY, no --yes)refused, names --yes2
workspace unlink --yesunlinked0
workspace statusnot linked3
workspace status with the pilot offhidden stub's opt-in message1

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=1 pilot; the subcommands reuse the same manage code as the TUI menu and serve routes.
  • link --workspace matches numeric id first, then exact name (case-insensitive); unknown names list available workspaces, ambiguous ones list ids. --create defaults 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 — or unlink without 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 later workspace sync accepts 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 reports account-changed after 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: 0 ok, 1 failed, 2 request to change (not signed in, missing --yes, ambiguous name), 3 project not linked. Every subcommand resolves the link first: a confirmed "not linked" is 3, but an unreachable service is 1, never "not linked". With --json, ok is true exactly when the exit is 0.
  • sync refuses a link never confirmed on this machine (exit 2, pointing at link --workspace <id>) and one the service could not confirm just now (exit 1); an unlink that leaves workspace skills behind exits 1, and unlink touches nothing when the service says the project is not linked. status flags 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 sync alongside the TUI menu.
  • --shared is 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 listMeta and snapshot members #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.