1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
<script lang="ts">
import type { ComputerEntry, WorkspaceEntry } from "@dispatch/wire";
import { untrack } from "svelte";
import type { WorkspaceStore } from "../store.svelte";
import { relativeTime } from "../logic/view-model";
import { workspacePath } from "../logic/route";
import ComputerSelect from "../../computer/ui/ComputerSelect.svelte";
let {
ws,
store,
onNavigate,
computers,
hasActive,
}: {
ws: WorkspaceEntry;
store: WorkspaceStore;
onNavigate: (path: string) => void;
/** Discovered computers (`GET /computers`), for the default-computer dropdown. */
computers: readonly ComputerEntry[];
/**
* Optional port: returns whether the workspace has at least one active
* (generating / queued) conversation — drives a loading-dots indicator on
* the card. Wired by the composition root to the app store's
* `workspaceHasActiveConversations`. Absent → no indicator (e.g. tests).
*/
hasActive?: (workspaceId: string) => boolean;
} = $props();
// Whether at least one conversation in this workspace is currently active
// (generating). Reactive: the composition-root port reads the app store's
// reactive tab set + lifecycle statuses, so this re-derives on change.
const active = $derived(hasActive?.(ws.id) ?? false);
// ── Title: double-click to rename inline ──────────────────────────────────
let editingTitle = $state(false);
let titleDraft = $state("");
let titleInput = $state<HTMLInputElement | undefined>();
let titleError = $state<string | null>(null);
function startEditTitle(): void {
titleDraft = ws.title;
titleError = null;
editingTitle = true;
queueMicrotask(() => titleInput?.focus());
}
async function saveTitle(): Promise<void> {
if (!editingTitle) return;
const title = titleDraft.trim();
editingTitle = false;
if (title === "" || title === ws.title) return;
const result = await store.rename(ws.id, title);
if (!result.ok) titleError = result.error;
}
function cancelTitle(): void {
editingTitle = false;
titleError = null;
}
// ── Default cwd: inline input ─────────────────────────────────────────────
let cwdDraft = $state(untrack(() => ws.defaultCwd ?? ""));
// Reseed when the backend value changes (e.g., after a save or an external
// refresh). Mid-edit (same value) does NOT re-run, so typing is never clobbered.
$effect(() => {
cwdDraft = ws.defaultCwd ?? "";
});
const cwdDirty = $derived(cwdDraft.trim() !== (ws.defaultCwd ?? ""));
let savingCwd = $state(false);
let cwdError = $state<string | null>(null);
async function saveCwd(): Promise<void> {
if (!cwdDirty || savingCwd) return;
savingCwd = true;
cwdError = null;
const cwd = cwdDraft.trim();
const result = await store.setDefaultCwd(ws.id, cwd === "" ? null : cwd);
savingCwd = false;
if (!result.ok) cwdError = result.error;
}
// ── Default computer: dropdown (Local / discovered SSH aliases) ────────────
let savingComputer = $state(false);
let computerError = $state<string | null>(null);
async function saveComputer(computerId: string | null): Promise<void> {
if (savingComputer) return;
// No-op when unchanged (the select only fires on a real change, but guard).
if (computerId === (ws.defaultComputerId ?? null)) return;
savingComputer = true;
computerError = null;
const result = await store.setDefaultComputer(ws.id, computerId);
savingComputer = false;
if (!result.ok) computerError = result.error;
}
// ── Star (concurrency priority) ──────────────────────────────────────────────
let savingStar = $state(false);
let starError = $state<string | null>(null);
async function toggleStar(): Promise<void> {
if (savingStar) return;
savingStar = true;
starError = null;
try {
// Optimistic: the store flips `starred` immediately and re-sorts; revert
// on error is handled there. We read `ws.starred` for the target value.
const result = await store.setStarred(ws.id, !ws.starred);
if (!result.ok) starError = result.error;
} catch (err) {
// A throw (e.g. a rejected effect) — surface it; the store already
// reverted the optimistic flip if it got far enough to apply it.
starError = err instanceof Error ? err.message : "Star toggle failed";
} finally {
savingStar = false;
}
}
// ── Delete ─────────────────────────────────────────────────────────────────
let deleting = $state(false);
async function handleDelete(): Promise<void> {
if (
!window.confirm(
`Delete workspace "${ws.title}"? Its conversations will be closed and moved to "default".`,
)
) {
return;
}
deleting = true;
await store.remove(ws.id);
deleting = false;
}
</script>
<li class="flex flex-col gap-2 rounded-box border border-primary bg-primary/10 p-3">
<div class="flex items-center gap-2">
{#if editingTitle}
<input
bind:this={titleInput}
bind:value={titleDraft}
class="input input-bordered input-sm flex-1"
aria-label="Workspace title"
onkeydown={(e) => {
if (e.key === "Enter") saveTitle();
else if (e.key === "Escape") cancelTitle();
}}
onblur={saveTitle}
/>
{:else}
<!-- svelte-ignore a11y_no_static_element_interactions, a11y_click_events_have_key_events -->
<span
class="flex-1 cursor-default truncate font-semibold"
title="Double-click to rename"
ondblclick={startEditTitle}>{ws.title}</span
>
{/if}
{#if active}
<span
class="loading loading-dots loading-xs shrink-0 text-primary"
aria-label="Workspace has active conversations"
title="A conversation in this workspace is generating"></span
>
{/if}
<span class="font-mono text-xs opacity-50">/{ws.id}</span>
<button
type="button"
class="btn btn-ghost btn-xs px-1"
disabled={savingStar}
aria-pressed={ws.starred}
aria-label={ws.starred ? "Unstar workspace" : "Star workspace"}
title={ws.starred
? "Starred — its agents get concurrency priority. Click to unstar."
: "Star this workspace to give its agents concurrency priority."}
onclick={toggleStar}
>
{#if savingStar}
<span class="loading loading-spinner loading-xs"></span>
{:else if ws.starred}
<span class="text-warning" aria-hidden="true">★</span>
{:else}
<span class="opacity-40" aria-hidden="true">☆</span>
{/if}
</button>
<span class="ml-auto text-xs opacity-50">
{ws.conversationCount}
{ws.conversationCount === 1 ? "conversation" : "conversations"}
· {relativeTime(ws.lastActivityAt, Date.now())}
</span>
<button
type="button"
class="btn btn-ghost btn-xs"
disabled={deleting}
title="Delete workspace"
aria-label="Delete workspace"
onclick={handleDelete}
>
{#if deleting}
<span class="loading loading-spinner loading-xs"></span>
{:else}
✕
{/if}
</button>
</div>
{#if titleError}
<p class="text-xs text-error">{titleError}</p>
{/if}
{#if starError}
<p class="text-xs text-error">{starError}</p>
{/if}
<div class="flex items-center gap-2">
<span class="w-8 shrink-0 text-xs opacity-60">cwd</span>
<input
type="text"
class="input input-bordered input-sm flex-1 font-mono text-xs"
placeholder="inherits the server default"
bind:value={cwdDraft}
aria-label="Default working directory"
onkeydown={(e) => {
if (e.key === "Enter") saveCwd();
}}
/>
<button
type="button"
class="btn btn-primary btn-xs"
disabled={!cwdDirty || savingCwd}
onclick={saveCwd}
>
{#if savingCwd}
<span class="loading loading-spinner loading-xs"></span>
{:else}
Set
{/if}
</button>
</div>
<div class="flex items-center gap-2">
<span class="w-8 shrink-0 text-xs opacity-60">ssh</span>
<ComputerSelect
value={ws.defaultComputerId}
{computers}
disabled={savingComputer}
onSelect={saveComputer}
/>
{#if savingComputer}
<span class="loading loading-spinner loading-xs shrink-0"></span>
{/if}
</div>
<div class="flex justify-start">
<a
class="btn"
href={workspacePath(ws.id)}
onclick={(e) => {
e.preventDefault();
onNavigate(workspacePath(ws.id));
}}
>
Open
</a>
</div>
{#if cwdError}
<p class="text-xs text-error">{cwdError}</p>
{:else if !cwdDirty && !ws.defaultCwd}
<p class="text-xs opacity-50">No default cwd set — conversations inherit the server default.</p>
{/if}
{#if computerError}
<p class="text-xs text-error">{computerError}</p>
{:else if !ws.defaultComputerId}
<p class="text-xs opacity-50">No default computer — conversations run locally (no SSH).</p>
{/if}
</li>
|