From 6b0bb19e914a3bbaeca198ac1627d698c3a13a76 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Thu, 25 Jun 2026 17:09:57 +0900 Subject: feat(computer): SSH computer selection + status + workspace default (handoff #2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirrors the cwd/workspace UI for the SSH-computer feature: - New feature library src/features/computer/: - logic/view-model.ts (pure): viewComputer/viewComputerStatus/viewTestResult/ summarizeComputers/formatHost/knownHostLabel + state->badge for the 4 ComputerStatusResponse states + SaveComputer/LoadComputerStatus/ TestComputer/LoadComputers ports. 20 view-model tests. - ui/ComputerField.svelte: per-conversation selector (dropdown + connection-status badge + Test-connection, polling the selected alias). - ui/ComputerSelect.svelte: reusable Local/computers dropdown, shared with the workspace default-computer control. - AppStore: computerId state + refreshComputer (at every focus site, parallel to refreshCwd) + setComputer (PUT /conversations/:id/computer, null=clear) + global computers catalog (GET /computers on boot, like models) + computerStatus(alias) + testComputer(alias). chat.send UNCHANGED (resolved server-side like cwd). - App.svelte: ComputerField in the Model sidebar view next to CwdField; adapted ports wrap the store. - workspaces: setDefaultComputer on WorkspaceHttp+WorkspaceStore (PUT /workspaces/:id/default-computer); default-computer selector in WorkspaceCard (reuses ComputerSelect); router passes store.computers through. - Re-mirrored .dispatch/transport-contract.reference.md (Computers section + ChatRequest.computerId); updated .dispatch/wire.reference.md (Computer/ ComputerEntry/defaultComputerId + the provider-retry divergence note from handoff #1); GLOSSARY + backend-handoff.md (handoff #2, §2e). Transparency invariant: the computer is USER-facing only (a tool-execution target, never part of the model prompt); the agent never sees it. Verify: 795/795 tests green; biome clean; vite build succeeds; 0 typecheck errors from the computer feature. (11 pre-existing svelte-check errors remain from the open §2d provider-retry divergence — backend feature/ssh-support still lacks TurnProviderRetryEvent; not from this feature.) --- src/features/workspaces/adapter/http.ts | 23 ++++++++++++++ src/features/workspaces/logic/view-model.test.ts | 1 + src/features/workspaces/store.svelte.ts | 8 +++++ src/features/workspaces/ui/WorkspaceCard.svelte | 40 +++++++++++++++++++++++- src/features/workspaces/ui/WorkspaceCard.test.ts | 23 ++++++++++---- src/features/workspaces/ui/WorkspacesHome.svelte | 10 ++++-- 6 files changed, 96 insertions(+), 9 deletions(-) (limited to 'src/features/workspaces') diff --git a/src/features/workspaces/adapter/http.ts b/src/features/workspaces/adapter/http.ts index 97fc2e2..6ebfee1 100644 --- a/src/features/workspaces/adapter/http.ts +++ b/src/features/workspaces/adapter/http.ts @@ -1,6 +1,7 @@ import type { DeleteWorkspaceResponse, EnsureWorkspaceRequest, + SetWorkspaceDefaultComputerRequest, SetWorkspaceDefaultCwdRequest, SetWorkspaceTitleRequest, Workspace, @@ -23,6 +24,7 @@ import type { * - `GET /workspaces/:id` (404 → null) → get * - `PUT /workspaces/:id/title` → rename * - `PUT /workspaces/:id/default-cwd` → set/clear default cwd + * - `PUT /workspaces/:id/default-computer` → set/clear default computer (SSH handoff #2) * - `DELETE /workspaces/:id` (409 for "default") → delete */ export type WorkspaceResult = @@ -35,6 +37,7 @@ export interface WorkspaceHttp { get(id: string): Promise; setTitle(id: string, title: string): Promise>; setDefaultCwd(id: string, defaultCwd: string | null): Promise>; + setDefaultComputer(id: string, computerId: string | null): Promise>; delete(id: string): Promise>; } @@ -118,6 +121,26 @@ export function createWorkspaceHttp(httpBase: string, fetchImpl: typeof fetch): } }, + async setDefaultComputer(id, computerId): Promise> { + try { + const res = await fetchImpl( + `${httpBase}/workspaces/${encodeURIComponent(id)}/default-computer`, + { + method: "PUT", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ computerId } satisfies SetWorkspaceDefaultComputerRequest), + }, + ); + if (!res.ok) return { ok: false, error: await errText(res) }; + return { ok: true, value: (await res.json()) as WorkspaceResponse }; + } catch (err) { + return { + ok: false, + error: err instanceof Error ? err.message : "Set default computer failed", + }; + } + }, + async delete(id): Promise> { try { const res = await fetchImpl(`${httpBase}/workspaces/${encodeURIComponent(id)}`, { diff --git a/src/features/workspaces/logic/view-model.test.ts b/src/features/workspaces/logic/view-model.test.ts index 52f7025..a4ed19c 100644 --- a/src/features/workspaces/logic/view-model.test.ts +++ b/src/features/workspaces/logic/view-model.test.ts @@ -36,6 +36,7 @@ describe("pageTitle", () => { id, title, defaultCwd: null, + defaultComputerId: null, createdAt: 0, lastActivityAt: 0, conversationCount: 0, diff --git a/src/features/workspaces/store.svelte.ts b/src/features/workspaces/store.svelte.ts index 0f662dc..0cf4ce2 100644 --- a/src/features/workspaces/store.svelte.ts +++ b/src/features/workspaces/store.svelte.ts @@ -21,6 +21,8 @@ export interface WorkspaceStore { rename(id: string, title: string): Promise>; /** Set/clear a workspace's default cwd. */ setDefaultCwd(id: string, defaultCwd: string | null): Promise>; + /** Set/clear a workspace's default computer (SSH `Host` alias; null = local). */ + setDefaultComputer(id: string, computerId: string | null): Promise>; /** Delete a workspace (closes its conversations, reassigns to "default"). */ remove(id: string): Promise>; } @@ -71,6 +73,12 @@ export function createWorkspaceStore(http: WorkspaceHttp): WorkspaceStore { return result; }, + async setDefaultComputer(id, computerId): Promise> { + const result = await http.setDefaultComputer(id, computerId); + if (result.ok) void this.refresh(); + return result; + }, + async remove(id): Promise> { const result = await http.delete(id); if (result.ok) void this.refresh(); diff --git a/src/features/workspaces/ui/WorkspaceCard.svelte b/src/features/workspaces/ui/WorkspaceCard.svelte index 6348bb9..4f846bf 100644 --- a/src/features/workspaces/ui/WorkspaceCard.svelte +++ b/src/features/workspaces/ui/WorkspaceCard.svelte @@ -1,18 +1,22 @@