@spunto/design-system 0.40.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -235,6 +235,13 @@ opinions a dashboard doesn't want, so it gets an entry too.
235
235
  footer, above View (or above a custom `footer`), muted once the task is over.
236
236
  Before 0.40.0 the dashboard did it through `footer` and redrew the View button
237
237
  by hand.
238
+ - **`WorkerCockpit`** takes `tasks` + `taskHref` (since 0.41.0): a "Tasks" section
239
+ at the top of its panel, drawn by `WorkerTaskHistory` (`/tasks`) — the live task
240
+ as a card, then every other task that ran on the workspace, most recent first.
241
+ The project's task list can be passed as is; the panel keeps this worker's.
242
+ - **`WorkerCockpit`** takes `actions` (since 0.42.0): the host's own actions
243
+ (`{ id, label, icon?, hint?, onClick, busy?, disabled? }`), drawn like Rebuild at the
244
+ top of the Actions section — a sandbox's "Create snapshot" and "Fork".
238
245
  - **Its bricks, exported individually** because the table view assembles them
239
246
  differently: `WorkerStatusDot`/`WorkerStatusPill` (+`resolveWorkerStatus`,
240
247
  `workerStatusConfig`), `SetupProgress` (+`setupProgress`, `phaseLabel`,
@@ -331,7 +338,7 @@ review. Every surface that shows one:
331
338
  - **`NewTaskDialog`** — delegating: prompt, files, title, base branch, model, plus the app's own `fields` (`NewTaskCustomField`: label, hint, `defaultValue`, `required`, `render(value, onChange)`), read back in `value.fields`.
332
339
  - Vocabulary and helpers: `TaskStateBadge`, `taskStateConfig`, `useElapsed`,
333
340
  `AgentMarkdown`, `useAttachmentDraft`/`prepareFile`/`TaskFiles` (files, RFC 0022),
334
- `runStats`/`toolVerb`/`toolSubject`, `bootSteps`, `indexTasksByWorker`.
341
+ `runStats`/`toolVerb`/`toolSubject`, `bootSteps`, `indexTasksByWorker`, `WorkerTaskHistory`.
335
342
 
336
343
  Same rules as `/workers`: nothing fetches, types are structural and lax
337
344
  (`TaskItem`, `TaskEvent`, `TaskDiff`…), links go through `render.link`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spunto/design-system",
3
- "version": "0.40.0",
3
+ "version": "0.42.0",
4
4
  "description": "Spunto's shared design system — warm/flame tokens, color constants, and UI primitives.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@ export { TaskList } from "./task-list"
27
27
  export type { TaskListProps } from "./task-list"
28
28
  export { TaskConversationList, TaskConversationPlaceholder } from "./conversation-list"
29
29
  export type { TaskConversationListProps } from "./conversation-list"
30
- export { TaskWorkerChip, WorkerTaskChip, indexTasksByWorker } from "./worker-link"
30
+ export { TaskWorkerChip, WorkerTaskChip, WorkerTaskHistory, indexTasksByWorker } from "./worker-link"
31
31
  export type { WorkerTask } from "./worker-link"
32
32
  export { NewTaskDialog } from "./new-task-dialog"
33
33
  export type { NewTaskCustomField, NewTaskDialogProps, NewTaskModelGroup, NewTaskValue } from "./new-task-dialog"
@@ -22,7 +22,7 @@ import { taskSpan } from "./task-state"
22
22
  import { TaskTitle } from "./task-title"
23
23
  import { runStats, toolSubject, toolVerb, type ToolRun } from "./tool-stack"
24
24
  import type { TaskCommand, TaskEvent, TaskItem } from "./types"
25
- import { indexTasksByWorker } from "./worker-link"
25
+ import { WorkerTaskHistory, indexTasksByWorker } from "./worker-link"
26
26
  import { WorkerCard } from "../workers/worker-card"
27
27
 
28
28
  const ev = (seq: number, type: string, payload: Record<string, unknown>, ts = `2026-09-24T10:00:${String(seq).padStart(2, "0")}Z`): TaskEvent => ({
@@ -201,6 +201,31 @@ describe("worker ↔ task", () => {
201
201
  expect(screen.getByRole("link", { name: /View/ }).getAttribute("href")).toBe("/w/w1")
202
202
  })
203
203
 
204
+ it("lists a workspace's tasks: the live one on top, the rest as history, others left out", () => {
205
+ const tasks = [
206
+ task({ id: "a", title: "Old one", state: "done", workerId: "w1", lastActivityAt: "2026-09-24T08:00:00Z" }),
207
+ task({ id: "b", title: "Live one", state: "running", workerId: "w1", lastActivityAt: "2026-09-24T09:00:00Z" }),
208
+ task({ id: "c", title: "Elsewhere", state: "running", workerId: "w2" }),
209
+ ]
210
+ render(<WorkerTaskHistory workerId="w1" tasks={tasks} href={(t) => `/t/${t.id}`} />)
211
+ const links = screen.getAllByRole("link").map((a) => a.getAttribute("href"))
212
+ expect(links).toEqual(["/t/b", "/t/a"])
213
+ expect(screen.queryByText("Elsewhere")).toBeNull()
214
+ expect(screen.queryByText("No task holds this workspace.")).toBeNull()
215
+ })
216
+
217
+ it("says no task holds the machine, and folds a long history", () => {
218
+ const tasks = Array.from({ length: 7 }, (_, i) =>
219
+ task({ id: `t${i}`, title: `Task ${i}`, state: "done", workerId: "w1", lastActivityAt: `2026-09-2${i}T10:00:00Z` }),
220
+ )
221
+ render(<WorkerTaskHistory workerId="w1" tasks={tasks} href={(t) => `/t/${t.id}`} limit={5} />)
222
+ expect(screen.getByText("No task holds this workspace.")).toBeTruthy()
223
+ expect(screen.getAllByRole("link")).toHaveLength(5)
224
+ expect(screen.getAllByRole("link")[0].getAttribute("href")).toBe("/t/t6")
225
+ fireEvent.click(screen.getByText("Show all 7"))
226
+ expect(screen.getAllByRole("link")).toHaveLength(7)
227
+ })
228
+
204
229
  it("keeps the task line when the caller replaces the footer, and draws none without a task", () => {
205
230
  const entry = indexTasksByWorker([task({ title: "Ship the card", workerId: "w1" })]).get("w1")!
206
231
  const { rerender } = render(<WorkerCard worker={{ id: "w1" }} task={{ entry, href: "/t" }} footer={<button>IDE</button>} />)
@@ -7,13 +7,14 @@
7
7
  // (workspaces, tasks) are one story told twice rather than two lists to correlate by hand. Both
8
8
  // directions are resolved from the two lists the page already holds: no extra round trip.
9
9
 
10
- import { ServerIcon } from "lucide-react"
10
+ import { useState } from "react"
11
+ import { GitBranchIcon, ServerIcon } from "lucide-react"
11
12
 
12
- import { cn } from "../../utils"
13
+ import { cn, formatRelativeTime } from "../../utils"
13
14
  import type { WorkerCardWorker } from "../workers/types"
14
15
  import type { LinkRender } from "../workers/worker-card"
15
16
  import { WorkerStatusDot, resolveWorkerStatus } from "../workers/worker-status"
16
- import { isLiveTaskState, taskStateStyle } from "./task-state"
17
+ import { TaskStateBadge, isLiveTaskState, taskStateStyle } from "./task-state"
17
18
  import { workerLabel } from "./machine"
18
19
  import type { TaskItem } from "./types"
19
20
 
@@ -124,3 +125,91 @@ export function TaskWorkerChip({
124
125
  </span>
125
126
  )
126
127
  }
128
+
129
+ /**
130
+ * Every task that ran on one workspace, for the worker page: the one holding the machine on top,
131
+ * as a card, then the rest as history, most recent first.
132
+ *
133
+ * Takes the tasks the caller already has and keeps those whose `workerId` is this worker — so a
134
+ * project's task list can be passed as is. The pick on top is `indexTasksByWorker`'s: a live task
135
+ * wins; when none is, no card claims the machine and the most recent task leads the history.
136
+ */
137
+ export function WorkerTaskHistory({
138
+ workerId,
139
+ tasks,
140
+ href,
141
+ render,
142
+ limit = 5,
143
+ className,
144
+ }: {
145
+ workerId: string
146
+ tasks: TaskItem[]
147
+ href: (task: TaskItem) => string
148
+ render?: { link?: LinkRender }
149
+ /** Rows of history shown before "Show all". */
150
+ limit?: number
151
+ className?: string
152
+ }) {
153
+ const [expanded, setExpanded] = useState(false)
154
+ const Link = render?.link ?? defaultLink
155
+ const mine = tasks.filter((t) => t.workerId === workerId)
156
+ const entry = indexTasksByWorker(mine).get(workerId)
157
+ if (!entry) return null
158
+
159
+ const at = (t: TaskItem) => t.lastActivityAt ?? t.createdAt
160
+ const current = entry.live ? entry.task : null
161
+ const history = mine
162
+ .filter((t) => t !== current)
163
+ .sort((a, b) => new Date(at(b)).getTime() - new Date(at(a)).getTime())
164
+ const shown = expanded ? history : history.slice(0, limit)
165
+
166
+ return (
167
+ <div className={cn("space-y-2", className)}>
168
+ {current ? (
169
+ <Link
170
+ href={href(current)}
171
+ className="block rounded-lg border border-border/50 bg-muted/20 px-3 py-2.5 transition-colors hover:bg-muted/40"
172
+ >
173
+ <div className="flex items-center justify-between gap-2">
174
+ <TaskStateBadge state={current.state} pendingAction={current.pendingAction} pendingSince={current.pendingSince} />
175
+ <span className="shrink-0 text-[10px] text-muted-foreground/60">{formatRelativeTime(at(current))}</span>
176
+ </div>
177
+ <p className="mt-1.5 line-clamp-2 text-xs font-medium text-foreground">{current.title}</p>
178
+ {current.branch && (
179
+ <div className="mt-1 flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground">
180
+ <GitBranchIcon className="h-3 w-3 shrink-0" />
181
+ <span className="truncate font-mono">{current.branch}</span>
182
+ </div>
183
+ )}
184
+ </Link>
185
+ ) : (
186
+ <p className="text-[11px] text-muted-foreground">No task holds this workspace.</p>
187
+ )}
188
+
189
+ {history.length > 0 && (
190
+ <div className="divide-y divide-border/40 rounded-lg border border-border/50 bg-muted/10">
191
+ {shown.map((t) => (
192
+ <Link
193
+ key={t.id}
194
+ href={href(t)}
195
+ className="flex min-w-0 items-center gap-2 px-3 py-1.5 text-muted-foreground transition-colors hover:bg-muted/30 hover:text-foreground"
196
+ >
197
+ <span title={taskStateStyle(t.state).label} className={cn("h-1.5 w-1.5 shrink-0 rounded-full", taskStateStyle(t.state).dotClass)} />
198
+ <span className="min-w-0 flex-1 truncate text-[11px]">{t.title}</span>
199
+ <span className="shrink-0 text-[10px] text-muted-foreground/60">{formatRelativeTime(at(t))}</span>
200
+ </Link>
201
+ ))}
202
+ {history.length > limit && (
203
+ <button
204
+ type="button"
205
+ onClick={() => setExpanded((v) => !v)}
206
+ className="w-full cursor-pointer px-3 py-1.5 text-left text-[11px] text-muted-foreground transition-colors hover:text-foreground"
207
+ >
208
+ {expanded ? "Show less" : `Show all ${history.length}`}
209
+ </button>
210
+ )}
211
+ </div>
212
+ )}
213
+ </div>
214
+ )
215
+ }
@@ -18,7 +18,7 @@ export { ActionMenu } from "../action-menu"
18
18
  export type { ActionMenuProps, ActionMenuItem, ActionMenuEntry, ActionMenuLinkRender } from "../action-menu"
19
19
 
20
20
  export { WorkerCockpit } from "./worker-cockpit"
21
- export type { WorkerCockpitProps } from "./worker-cockpit"
21
+ export type { WorkerCockpitAction, WorkerCockpitProps } from "./worker-cockpit"
22
22
 
23
23
  export { WorkerStatusDot, WorkerStatusPill, resolveWorkerStatus, workerStatusConfig } from "./worker-status"
24
24
  export type { WorkerStatus, WorkerStatusConfig, WorkerStatusKey } from "./worker-status"
@@ -49,9 +49,22 @@ import { type LinkRender } from "./worker-card"
49
49
  import { WorkerSetupTimeline } from "./worker-setup-timeline"
50
50
  import { WorkerStatusDot, WorkerStatusPill, resolveWorkerStatus } from "./worker-status"
51
51
  import { WorkerStatusHistory } from "./worker-status-history"
52
+ import { WorkerTaskHistory } from "../tasks/worker-link"
53
+ import type { TaskItem } from "../tasks/types"
52
54
 
53
55
  type CockpitTab = "logs" | "terminal"
54
56
 
57
+ export interface WorkerCockpitAction {
58
+ id: string
59
+ label: string
60
+ icon?: ComponentType<{ className?: string }>
61
+ hint?: string
62
+ onClick: () => void
63
+ /** In flight: the button is disabled and its icon spins. */
64
+ busy?: boolean
65
+ disabled?: boolean
66
+ }
67
+
55
68
  export interface WorkerCockpitProps {
56
69
  worker: WorkerCockpitWorker
57
70
  /** Above the worker name, e.g. "my-project /". Omitted → no breadcrumb. */
@@ -105,12 +118,28 @@ export interface WorkerCockpitProps {
105
118
  /** Fetches the one-shot SSH command; the cockpit copies it to the clipboard and owns the button's own idle/loading/copied state. */
106
119
  onCopySsh?: () => Promise<string>
107
120
 
121
+ /**
122
+ * More of the worker's own actions, drawn like Rebuild in the Actions section — before it, in this
123
+ * order. What a host offers beyond the built-in ones (a sandbox's "Create snapshot", "Fork"…).
124
+ * `hint`: the muted words on the right. Shown whatever the worker's state: pass only what applies now.
125
+ */
126
+ actions?: WorkerCockpitAction[]
127
+
108
128
  /**
109
129
  * The worker's status transitions, as journaled by the control plane. Omitted or empty → no
110
130
  * History section. The current stay is measured up to `now` at render time.
111
131
  */
112
132
  statusHistory?: WorkerStatusEvent[]
113
133
 
134
+ /**
135
+ * The tasks that ran on this workspace — the project's list can be passed as is, the panel keeps
136
+ * those whose `workerId` is this worker. Drawn as a "Tasks" section: the live one as a card on
137
+ * top, then the history, most recent first. Absent, or none ran here → no section.
138
+ */
139
+ tasks?: TaskItem[]
140
+ /** Task → its page. Required for the section to render. */
141
+ taskHref?: (task: TaskItem) => string
142
+
114
143
  /** A failed mutation, typically. */
115
144
  error?: string | null
116
145
  onDismissError?: () => void
@@ -187,7 +216,10 @@ export function WorkerCockpit({
187
216
  onDelete,
188
217
  deleting = false,
189
218
  onCopySsh,
219
+ actions = [],
190
220
  statusHistory,
221
+ tasks,
222
+ taskHref,
191
223
  error,
192
224
  onDismissError,
193
225
  activeTab,
@@ -231,7 +263,8 @@ export function WorkerCockpit({
231
263
  }
232
264
  }
233
265
 
234
- const showActions = !!((settled && onCopySsh) || (hasContainer && !status.settingUp && !isDeleting && onRebuild) || ((hasContainer || isDeleting) && nodeOnline !== false && onDelete))
266
+ const showActions = !!(actions.length > 0 || (settled && onCopySsh) || (hasContainer && !status.settingUp && !isDeleting && onRebuild) || ((hasContainer || isDeleting) && nodeOnline !== false && onDelete))
267
+ const hasTasks = !!taskHref && !!tasks?.some((t) => t.workerId === worker.id)
235
268
  const showTags = (worker.tags?.length ?? 0) > 0 || !!onAddTag
236
269
 
237
270
  const controlPanel = (
@@ -268,6 +301,14 @@ export function WorkerCockpit({
268
301
  </Banner>
269
302
  )}
270
303
 
304
+ {/* Before Setup: on a task's machine, the work it is doing is the first thing to read. */}
305
+ {hasTasks && (
306
+ <div>
307
+ <SectionLabel>Tasks</SectionLabel>
308
+ <WorkerTaskHistory workerId={worker.id} tasks={tasks!} href={taskHref!} render={{ link: render?.link }} />
309
+ </div>
310
+ )}
311
+
271
312
  {(status.settingUp || worker.setupStatus) && (
272
313
  <div className="space-y-2">
273
314
  <SectionLabel>Setup</SectionLabel>
@@ -384,6 +425,16 @@ export function WorkerCockpit({
384
425
  <span className="text-[10px] text-muted-foreground/50">5 min token</span>
385
426
  </button>
386
427
  )}
428
+ {actions.map((a) => {
429
+ const Icon = a.icon
430
+ return (
431
+ <button key={a.id} type="button" disabled={a.disabled || a.busy} onClick={a.onClick} className="flex w-full items-center gap-2 rounded-lg border border-border/50 bg-muted/20 px-3 py-2.5 text-xs text-foreground transition-colors hover:bg-muted/40 disabled:opacity-50">
432
+ {a.busy ? <LoaderIcon className="h-3.5 w-3.5 animate-spin text-muted-foreground" /> : Icon ? <Icon className="h-3.5 w-3.5 text-muted-foreground" /> : null}
433
+ <span className="font-medium">{a.label}</span>
434
+ {a.hint && <span className="ml-auto text-[10px] text-muted-foreground/50">{a.hint}</span>}
435
+ </button>
436
+ )
437
+ })}
387
438
  {hasContainer && !status.settingUp && !isDeleting && onRebuild && (
388
439
  <button type="button" disabled={rebuilding} onClick={onRebuild} className="flex w-full items-center gap-2 rounded-lg border border-border/50 bg-muted/20 px-3 py-2.5 text-xs text-foreground transition-colors hover:bg-muted/40 disabled:opacity-50">
389
440
  <RefreshCwIcon className={cn("h-3.5 w-3.5 text-muted-foreground", rebuilding && "animate-spin")} />