@spunto/design-system 0.39.0 → 0.41.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 +10 -1
- package/package.json +1 -1
- package/src/components/tasks/index.ts +1 -1
- package/src/components/tasks/tasks.test.tsx +43 -1
- package/src/components/tasks/worker-link.tsx +92 -3
- package/src/components/workers/index.ts +2 -0
- package/src/components/workers/worker-card.tsx +29 -7
- package/src/components/workers/worker-cockpit.tsx +22 -0
package/README.md
CHANGED
|
@@ -230,6 +230,15 @@ opinions a dashboard doesn't want, so it gets an entry too.
|
|
|
230
230
|
same Base UI markup to do it. `actions` stays as the escape hatch (a submenu, a
|
|
231
231
|
checkbox item) and wins over `menu` when both are given; `render.menuLink` is
|
|
232
232
|
the link slot for an entry with an `href`.
|
|
233
|
+
- **The task on the machine is a prop too.** `task={{ entry, href }}` — `entry`
|
|
234
|
+
from `indexTasksByWorker` (`/tasks`) — draws a "Task" line at the top of the
|
|
235
|
+
footer, above View (or above a custom `footer`), muted once the task is over.
|
|
236
|
+
Before 0.40.0 the dashboard did it through `footer` and redrew the View button
|
|
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.
|
|
233
242
|
- **Its bricks, exported individually** because the table view assembles them
|
|
234
243
|
differently: `WorkerStatusDot`/`WorkerStatusPill` (+`resolveWorkerStatus`,
|
|
235
244
|
`workerStatusConfig`), `SetupProgress` (+`setupProgress`, `phaseLabel`,
|
|
@@ -326,7 +335,7 @@ review. Every surface that shows one:
|
|
|
326
335
|
- **`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`.
|
|
327
336
|
- Vocabulary and helpers: `TaskStateBadge`, `taskStateConfig`, `useElapsed`,
|
|
328
337
|
`AgentMarkdown`, `useAttachmentDraft`/`prepareFile`/`TaskFiles` (files, RFC 0022),
|
|
329
|
-
`runStats`/`toolVerb`/`toolSubject`, `bootSteps`, `indexTasksByWorker`.
|
|
338
|
+
`runStats`/`toolVerb`/`toolSubject`, `bootSteps`, `indexTasksByWorker`, `WorkerTaskHistory`.
|
|
330
339
|
|
|
331
340
|
Same rules as `/workers`: nothing fetches, types are structural and lax
|
|
332
341
|
(`TaskItem`, `TaskEvent`, `TaskDiff`…), links go through `render.link`.
|
package/package.json
CHANGED
|
@@ -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,8 @@ 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
|
+
import { WorkerCard } from "../workers/worker-card"
|
|
26
27
|
|
|
27
28
|
const ev = (seq: number, type: string, payload: Record<string, unknown>, ts = `2026-09-24T10:00:${String(seq).padStart(2, "0")}Z`): TaskEvent => ({
|
|
28
29
|
seq,
|
|
@@ -192,6 +193,47 @@ describe("worker ↔ task", () => {
|
|
|
192
193
|
expect(index.get("w1")).toMatchObject({ task: { id: "live" }, live: true })
|
|
193
194
|
expect(index.get("w2")).toMatchObject({ task: { id: "other" }, live: false })
|
|
194
195
|
})
|
|
196
|
+
|
|
197
|
+
it("draws the task on a worker card above its View button", () => {
|
|
198
|
+
const entry = indexTasksByWorker([task({ id: "t9", title: "Ship the card", workerId: "w1" })]).get("w1")!
|
|
199
|
+
render(<WorkerCard worker={{ id: "w1", name: "box" }} href="/w/w1" task={{ entry, href: "/t/t9" }} />)
|
|
200
|
+
expect(screen.getByRole("link", { name: /Ship the card/ }).getAttribute("href")).toBe("/t/t9")
|
|
201
|
+
expect(screen.getByRole("link", { name: /View/ }).getAttribute("href")).toBe("/w/w1")
|
|
202
|
+
})
|
|
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
|
+
|
|
229
|
+
it("keeps the task line when the caller replaces the footer, and draws none without a task", () => {
|
|
230
|
+
const entry = indexTasksByWorker([task({ title: "Ship the card", workerId: "w1" })]).get("w1")!
|
|
231
|
+
const { rerender } = render(<WorkerCard worker={{ id: "w1" }} task={{ entry, href: "/t" }} footer={<button>IDE</button>} />)
|
|
232
|
+
expect(screen.getByText("Ship the card")).toBeTruthy()
|
|
233
|
+
expect(screen.getByRole("button", { name: "IDE" })).toBeTruthy()
|
|
234
|
+
rerender(<WorkerCard worker={{ id: "w1" }} href="/w/w1" />)
|
|
235
|
+
expect(screen.queryByText("Task")).toBeNull()
|
|
236
|
+
})
|
|
195
237
|
})
|
|
196
238
|
|
|
197
239
|
describe("formatters", () => {
|
|
@@ -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 {
|
|
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
|
+
}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
export { WorkerCard } from "./worker-card"
|
|
10
10
|
export type { WorkerCardProps, LinkRender } from "./worker-card"
|
|
11
|
+
// The card's `task` prop carries one of these — see `indexTasksByWorker` in `/tasks`.
|
|
12
|
+
export type { WorkerTask } from "../tasks/worker-link"
|
|
11
13
|
|
|
12
14
|
// The card's `menu` prop is a list of these. Re-exported here (they also ship
|
|
13
15
|
// from the root entry) so an app can type its worker menu without importing the
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from "lucide-react"
|
|
13
13
|
|
|
14
14
|
import { cn, formatDuration, formatRelativeTime } from "../../utils"
|
|
15
|
+
import { WorkerTaskChip, type WorkerTask } from "../tasks/worker-link"
|
|
15
16
|
import { ActionMenu, type ActionMenuEntry, type ActionMenuLinkRender } from "../action-menu"
|
|
16
17
|
import { buttonVariants } from "../button-variants"
|
|
17
18
|
import { CreatorAvatar } from "./creator-avatar"
|
|
@@ -104,6 +105,14 @@ export interface WorkerCardProps {
|
|
|
104
105
|
* item, a dialog opened from an entry). Takes precedence over `menu`.
|
|
105
106
|
*/
|
|
106
107
|
actions?: ReactNode
|
|
108
|
+
/**
|
|
109
|
+
* The task that holds this machine, or the last one that ran on it — typically
|
|
110
|
+
* `indexTasksByWorker(tasks).get(worker.id)` (`@spunto/design-system/tasks`).
|
|
111
|
+
* Drawn as a "Task" line at the top of the footer, above the View button (or
|
|
112
|
+
* above `footer`), so naming the task never means redrawing the footer. A
|
|
113
|
+
* finished task is drawn muted: the machine is free. Absent → no line.
|
|
114
|
+
*/
|
|
115
|
+
task?: { entry: WorkerTask; href: string }
|
|
107
116
|
/** Replaces the default "View" footer entirely (extra buttons, an IDE link…). */
|
|
108
117
|
footer?: ReactNode
|
|
109
118
|
/** Label of the default footer button. */
|
|
@@ -149,6 +158,7 @@ export function WorkerCard({
|
|
|
149
158
|
onDismissError,
|
|
150
159
|
menu,
|
|
151
160
|
actions,
|
|
161
|
+
task,
|
|
152
162
|
footer,
|
|
153
163
|
viewLabel = "View",
|
|
154
164
|
className,
|
|
@@ -318,14 +328,26 @@ export function WorkerCard({
|
|
|
318
328
|
</Banner>
|
|
319
329
|
)}
|
|
320
330
|
|
|
321
|
-
{(footer
|
|
322
|
-
<div className="mt-auto border-t border-border/50 bg-muted/20 px-3 py-2">
|
|
323
|
-
{
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
331
|
+
{(task || footer || href) && (
|
|
332
|
+
<div className="mt-auto flex flex-col gap-2 border-t border-border/50 bg-muted/20 px-3 py-2">
|
|
333
|
+
{/* « Sur quoi cette machine travaille » — la même paire que la colonne
|
|
334
|
+
Task du tableau, vue depuis la carte. Dans le pied plutôt que dans
|
|
335
|
+
les bandes du dessus : c'est un lien vers ailleurs, comme View. */}
|
|
336
|
+
{task && (
|
|
337
|
+
<div className="flex min-w-0 items-center gap-2">
|
|
338
|
+
<span className="shrink-0 text-[10px] font-semibold tracking-wider text-muted-foreground/60 uppercase">
|
|
339
|
+
Task
|
|
340
|
+
</span>
|
|
341
|
+
<WorkerTaskChip entry={task.entry} href={task.href} render={{ link: render?.link }} />
|
|
342
|
+
</div>
|
|
328
343
|
)}
|
|
344
|
+
{footer ??
|
|
345
|
+
(href && (
|
|
346
|
+
<Link href={href} className={cn(buttonVariants({ variant: "default", size: "sm" }), "h-7 w-full gap-1.5 text-xs")}>
|
|
347
|
+
{viewLabel}
|
|
348
|
+
<ChevronRightIcon className="h-3.5 w-3.5" />
|
|
349
|
+
</Link>
|
|
350
|
+
))}
|
|
329
351
|
</div>
|
|
330
352
|
)}
|
|
331
353
|
</div>
|
|
@@ -49,6 +49,8 @@ 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
|
|
|
@@ -111,6 +113,15 @@ export interface WorkerCockpitProps {
|
|
|
111
113
|
*/
|
|
112
114
|
statusHistory?: WorkerStatusEvent[]
|
|
113
115
|
|
|
116
|
+
/**
|
|
117
|
+
* The tasks that ran on this workspace — the project's list can be passed as is, the panel keeps
|
|
118
|
+
* those whose `workerId` is this worker. Drawn as a "Tasks" section: the live one as a card on
|
|
119
|
+
* top, then the history, most recent first. Absent, or none ran here → no section.
|
|
120
|
+
*/
|
|
121
|
+
tasks?: TaskItem[]
|
|
122
|
+
/** Task → its page. Required for the section to render. */
|
|
123
|
+
taskHref?: (task: TaskItem) => string
|
|
124
|
+
|
|
114
125
|
/** A failed mutation, typically. */
|
|
115
126
|
error?: string | null
|
|
116
127
|
onDismissError?: () => void
|
|
@@ -188,6 +199,8 @@ export function WorkerCockpit({
|
|
|
188
199
|
deleting = false,
|
|
189
200
|
onCopySsh,
|
|
190
201
|
statusHistory,
|
|
202
|
+
tasks,
|
|
203
|
+
taskHref,
|
|
191
204
|
error,
|
|
192
205
|
onDismissError,
|
|
193
206
|
activeTab,
|
|
@@ -232,6 +245,7 @@ export function WorkerCockpit({
|
|
|
232
245
|
}
|
|
233
246
|
|
|
234
247
|
const showActions = !!((settled && onCopySsh) || (hasContainer && !status.settingUp && !isDeleting && onRebuild) || ((hasContainer || isDeleting) && nodeOnline !== false && onDelete))
|
|
248
|
+
const hasTasks = !!taskHref && !!tasks?.some((t) => t.workerId === worker.id)
|
|
235
249
|
const showTags = (worker.tags?.length ?? 0) > 0 || !!onAddTag
|
|
236
250
|
|
|
237
251
|
const controlPanel = (
|
|
@@ -268,6 +282,14 @@ export function WorkerCockpit({
|
|
|
268
282
|
</Banner>
|
|
269
283
|
)}
|
|
270
284
|
|
|
285
|
+
{/* Before Setup: on a task's machine, the work it is doing is the first thing to read. */}
|
|
286
|
+
{hasTasks && (
|
|
287
|
+
<div>
|
|
288
|
+
<SectionLabel>Tasks</SectionLabel>
|
|
289
|
+
<WorkerTaskHistory workerId={worker.id} tasks={tasks!} href={taskHref!} render={{ link: render?.link }} />
|
|
290
|
+
</div>
|
|
291
|
+
)}
|
|
292
|
+
|
|
271
293
|
{(status.settingUp || worker.setupStatus) && (
|
|
272
294
|
<div className="space-y-2">
|
|
273
295
|
<SectionLabel>Setup</SectionLabel>
|