feat: workspace moves carry Claude terminal sessions; Move submenu without a dialog

Merged
HA
4d ago
+2417-1076

Summary

This PR has two related changes to workspace moves (teleport):

  1. Claude sessions in terminals now move with the workspace. Before, only chat-pane sessions moved; a Claude Code TUI started in a terminal stayed on the old machine. Now it continues on the new machine in a terminal running claude --resume.
  2. Move submenu, no dialog. The right-click menu and the workspace header's ⋯ menu get one Move submenu: Cloud → environment and Another computer → computer. Picking a destination starts the move at once; the two move dialogs are removed.

Also: the API lets a cloud box call attachment.createUpload, so a cloud workspace can be the source of a terminal move.

How to review: commits are in order and each stands alone: API allowlist → host-service → desktop handoff → Move submenu.


Part 1: Claude terminal sessions move with the workspace

Why

teleport.prepareWorkspace collected only chat-runtime sessions. Terminal agents are tracked separately (TerminalAgentStore), so a Claude TUI in a terminal was left behind on every move.

How it works

  • Source host (prepareWorkspace): also lists live Claude terminal agents that have a session. A busy one blocks the move unless stopIfBusy, the same as chats. Each one is stopped before the snapshot push (its binding is marked disposed first, so the source pane does not auto-resume it), and its session file is uploaded as a transfer attachment (no chat row needed). A TUI that never wrote a session keeps running. The new output fields terminals and skippedTerminals are additive.
  • Destination host (new teleport.importTerminalSession): downloads the bundle, places the session file in the Claude config dir of the agent's account (paths rewritten by the existing Claude teleport provider), and starts claude --resume <id> through runAgentInWorkspace. The desktop's background-session adoption opens it as a pane. A repeated call for the same session returns the first terminal.
  • Recovery (new teleport.releaseTerminals): a terminal whose handoff fails is started again on the source, and its pane follows through the existing resumed lifecycle event. A failed pack or a failed prepare does the same by itself.
  • Desktop (handOffTerminals): after the destination exists, it imports each terminal. For a new cloud workspace it retries every 5 s for up to 10 minutes while the box starts, and gives up at once on answers that will not change (old host / missing procedure, PRECONDITION_FAILED, BAD_REQUEST). Terminals that did not arrive are listed in the move toast as " (terminal)".

Key decisions

DecisionChoiceRationale
Arrives asA terminal, not a chat paneSame surface the user had before the move
TransportTransfer attachment (attachment.createUpload → R2)No DB change; bytes do not cross the relay; the file sweep reclaims it after a day
When the source TUI stopsAt prepare, before the pushThe packed session is final; nothing goes on at the source
Who runs the handoffThe desktopMoves to a computer already run there; avoids new control-plane state
Move-abort ruleStill chats onlyA terminal that fails to upload is resumed at the source; it does not fail the whole move

Part 2: Move submenu without a dialog

What / How

  • New shared WorkspaceMoveMenu (_dashboard/components/WorkspaceMoveMenu/), used by DashboardSidebarWorkspaceContextMenu (context-menu primitives) and WorkspaceMoreMenu (dropdown primitives).
  • Move → Cloud lists only environments whose primary repository is the workspace's GitHub repository: useMoveWorkspaceToCloud refuses any other ("This environment opens X, not Y"), so those are not offered. The list loads only when the submenu opens. "Manage environments" opens Settings.
  • Move → Another computer lists computers: this computer first when the workspace is elsewhere, then online ones; offline ones are disabled.
  • Picking a destination starts the move (useStartWorkspaceMove). A cloud move uses the project's remembered machine size, or the default. Progress, cancel and retry stay in the move toast.
  • MoveWorkspaceDialog and both dialogs are deleted.

What goes away with the dialog

  • The warning text ("agents that are working stop first…") before a move starts.
  • Picking a machine size per move.
  • "Create environment" from the move flow ("Manage environments" covers it).

Manual QA Checklist

Move submenu

  • Local dev build, driven over CDP with real right-click / hover / click: Move → Cloud listed the seeded environments, and an earlier iteration of this change opened the right environment in the (now removed) dialog. Feature flags were overridden in the renderer and environments were seeded in the local DB, because the local PostHog key is a placeholder.
  • Final no-dialog version: Move → Cloud → environment starts a move and shows the toast (not run: the first step pushes a snapshot branch to the workspace's real GitHub remote)
  • Move → Another computer → computer starts a move; offline computers are disabled
  • Same submenu from the workspace header ⋯ menu
  • A workspace whose repository has no environment shows "No environments linked to this project."

Terminal sessions

  • Computer → cloud: a Claude TUI with a conversation reopens in the cloud workspace as a terminal on claude --resume, with its history
  • Cloud → computer, and computer → another computer
  • A busy TUI is stopped and still moves
  • A TUI that never got a message stays running on the source
  • Destination on an old host-service: the terminal restarts on the source and is named in the toast
  • The source pane follows the restarted terminal when a handoff fails

None of the terminal-session scenarios were run end to end.

Testing

  • bunx tsc --noEmit in packages/host-service: clean
  • bunx tsc --noEmit in apps/desktop: no errors in changed files (this worktree lacks generated routeTree.gen / file-icons manifest, which cause unrelated errors)
  • bun test in packages/host-service (src/teleport, src/trpc/router/teleport, src/workers, src/trpc/router/terminal-agents, src/terminal-agents): 187 pass
  • bun test in packages/trpc (src/lib/sandbox): 35 pass
  • bun test in apps/desktop for handOffTerminals: 2 pass
  • New tests: terminal-sessions.test.ts (which terminal bindings move), handOffTerminals.test.ts (a terminal that does not arrive restarts at the source; waits for a starting box)
  • bun run check:i18n and biome: pass. One new string ({title} (terminal)) and two menu labels, translated into every locale.

Compatibility

  • Host-service: two new procedures and two new optional output fields. A new desktop with an old source host sees no terminals and moves only chats; with an old destination host, importTerminalSession is missing, so the terminal restarts on the source.
  • API: attachment.createUpload added to SANDBOX_ALLOWED_PROCEDURES (additive). A box still resolves only files anchored to its own workspace. Until the API deploys, a cloud workspace's terminals stay behind and the rest of the move goes on.
  • No DB migration.

Known limitations

  • The desktop runs the terminal handoff. If it quits mid-move, or the source host restarts before a failed handoff is released, a stopped TUI is not restarted automatically (its conversation is still on disk).
  • Only Claude terminal agents move (the only teleport provider).
  • Session workspaces still show Move → Cloud, but have no GitHub remote, so the list is empty and a move could not succeed anyway.

Rollback

Revert the PR. No data changes. An uploaded transfer bundle is reclaimed by the file sweep after a day.


Summary by cubic

Workspace moves now transfer eligible Claude terminal sessions and use a Move submenu instead of destination dialogs. Busy terminals stay running on the first attempt; choose Try again to stop them and move them.

Terminal sessions

  • Terminals that cannot move are restarted on the source when possible; skipped or failed restarts are reported in the toast.

Move menu

  • Cloud destinations show only repository-linked environments, and offline computers are disabled.
  • Manage environments opens Settings; progress, cancel, and retry remain in the move toast.

Summary by CodeRabbit

  • New Features
    • Move workspaces to another computer or a cloud environment from a unified menu.
    • Eligible terminal sessions move with the workspace. Sessions that cannot be transferred remain available on the source, and progress and outcomes are reported.
    • Claude terminal sessions are supported for transfers.
  • Improvements
    • Destination choices indicate when computers are offline and show an empty state when no destinations are available.