@spunto/design-system 0.38.0 → 0.40.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 +6 -1
- package/package.json +1 -1
- package/src/components/tasks/index.ts +1 -1
- package/src/components/tasks/new-task-dialog.tsx +57 -4
- package/src/components/tasks/tasks.test.tsx +69 -0
- package/src/components/workers/index.ts +2 -0
- package/src/components/workers/worker-card.tsx +29 -7
package/README.md
CHANGED
|
@@ -230,6 +230,11 @@ 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.
|
|
233
238
|
- **Its bricks, exported individually** because the table view assembles them
|
|
234
239
|
differently: `WorkerStatusDot`/`WorkerStatusPill` (+`resolveWorkerStatus`,
|
|
235
240
|
`workerStatusConfig`), `SetupProgress` (+`setupProgress`, `phaseLabel`,
|
|
@@ -323,7 +328,7 @@ review. Every surface that shows one:
|
|
|
323
328
|
- **`TaskDetails`** (`sidebar` | `sheet`) with **`TaskMachine`**, **`TaskBoot`**,
|
|
324
329
|
`TaskSessionUsage`, `TaskPullRequest`, `TaskCommandLog` — the facts about a task, in
|
|
325
330
|
one order, instead of two hand-kept copies.
|
|
326
|
-
- **`NewTaskDialog`** — delegating: prompt, files, title, base branch, model.
|
|
331
|
+
- **`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
332
|
- Vocabulary and helpers: `TaskStateBadge`, `taskStateConfig`, `useElapsed`,
|
|
328
333
|
`AgentMarkdown`, `useAttachmentDraft`/`prepareFile`/`TaskFiles` (files, RFC 0022),
|
|
329
334
|
`runStats`/`toolVerb`/`toolSubject`, `bootSteps`, `indexTasksByWorker`.
|
package/package.json
CHANGED
|
@@ -30,7 +30,7 @@ export type { TaskConversationListProps } from "./conversation-list"
|
|
|
30
30
|
export { TaskWorkerChip, WorkerTaskChip, indexTasksByWorker } from "./worker-link"
|
|
31
31
|
export type { WorkerTask } from "./worker-link"
|
|
32
32
|
export { NewTaskDialog } from "./new-task-dialog"
|
|
33
|
-
export type { NewTaskDialogProps, NewTaskModelGroup, NewTaskValue } from "./new-task-dialog"
|
|
33
|
+
export type { NewTaskCustomField, NewTaskDialogProps, NewTaskModelGroup, NewTaskValue } from "./new-task-dialog"
|
|
34
34
|
|
|
35
35
|
// ── The cockpit ─────────────────────────────────────────────────────────────────────────────
|
|
36
36
|
export { TaskCockpit, TaskPanelTabs } from "./task-cockpit"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
// Delegating work, as a form: what to do and where to start.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// Delegating work, as a form: what to do and where to start. The task allocates its own machine;
|
|
4
|
+
// what an app wants asked on top of that (which machine, how big…) comes in as `fields`, free
|
|
5
|
+
// fields it draws itself and reads back in `NewTaskValue.fields`.
|
|
6
6
|
//
|
|
7
7
|
// Presentational like the rest of `/tasks`: the lists it offers (projects, branches, models) come
|
|
8
8
|
// in as props, the value goes out through `onSubmit`, and `submitting`/`error` come back down. The
|
|
@@ -41,6 +41,36 @@ export interface NewTaskValue {
|
|
|
41
41
|
model?: string
|
|
42
42
|
/** Prepared in the browser — `data` is base64, ready for a JSON body. */
|
|
43
43
|
files: DraftFile[]
|
|
44
|
+
/**
|
|
45
|
+
* The app's own fields (`NewTaskDialogProps.fields`), by id: what was picked, else the field's
|
|
46
|
+
* `defaultValue`. A field with neither is absent.
|
|
47
|
+
*/
|
|
48
|
+
fields?: Record<string, unknown>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A field the app adds to the form — a machine size, a deadline, a label… — drawn below the
|
|
53
|
+
* package's own, with the same label and hint. The form owns its value like any of its fields:
|
|
54
|
+
* reset every time it opens, sent with the rest. `render` draws the control from `value` and
|
|
55
|
+
* reports changes through `onChange`, with any component of the package (Select, Input…).
|
|
56
|
+
*/
|
|
57
|
+
export interface NewTaskCustomField {
|
|
58
|
+
/** Key in `NewTaskValue.fields`. */
|
|
59
|
+
id: string
|
|
60
|
+
label: string
|
|
61
|
+
/** Shown after the label, muted ("— optional"). */
|
|
62
|
+
labelHint?: string
|
|
63
|
+
/** One line under the control, like the package's own fields. */
|
|
64
|
+
hint?: ReactNode
|
|
65
|
+
/**
|
|
66
|
+
* The value until someone picks one — and the value sent if nobody does. Read at render, not
|
|
67
|
+
* copied at open: options that arrive after the form opened (a request still in flight) still
|
|
68
|
+
* get their default.
|
|
69
|
+
*/
|
|
70
|
+
defaultValue?: unknown
|
|
71
|
+
/** Delegate stays disabled while it has no value (`undefined`, `null` or `""`). */
|
|
72
|
+
required?: boolean
|
|
73
|
+
render: (value: unknown, onChange: (value: unknown) => void) => ReactNode
|
|
44
74
|
}
|
|
45
75
|
|
|
46
76
|
/** A harness and the models it knows — the suggestions under "Model". */
|
|
@@ -70,6 +100,8 @@ export interface NewTaskDialogProps {
|
|
|
70
100
|
modelGroups?: NewTaskModelGroup[]
|
|
71
101
|
/** The project's default model, shown as the placeholder so a blank field says what it means. */
|
|
72
102
|
defaultModel?: string | null
|
|
103
|
+
/** The app's own fields, in this order, after the package's (see `NewTaskCustomField`). */
|
|
104
|
+
fields?: NewTaskCustomField[]
|
|
73
105
|
|
|
74
106
|
onSubmit: (value: NewTaskValue) => void
|
|
75
107
|
submitting?: boolean
|
|
@@ -88,6 +120,7 @@ export function NewTaskDialog({
|
|
|
88
120
|
defaultBranch = null,
|
|
89
121
|
modelGroups = [],
|
|
90
122
|
defaultModel = null,
|
|
123
|
+
fields = [],
|
|
91
124
|
onSubmit,
|
|
92
125
|
submitting = false,
|
|
93
126
|
error = null,
|
|
@@ -99,6 +132,11 @@ export function NewTaskDialog({
|
|
|
99
132
|
const [baseBranch, setBaseBranch] = useState("")
|
|
100
133
|
const [model, setModel] = useState("")
|
|
101
134
|
const [projectId, setProjectId] = useState("")
|
|
135
|
+
// Only what was picked: a field nobody touched reads its (current) `defaultValue`.
|
|
136
|
+
const [picked, setPicked] = useState<Record<string, unknown>>({})
|
|
137
|
+
const fieldValue = (f: NewTaskCustomField) => (f.id in picked ? picked[f.id] : f.defaultValue)
|
|
138
|
+
const isEmpty = (v: unknown) => v === undefined || v === null || v === ""
|
|
139
|
+
const missingRequired = fields.some((f) => f.required && isEmpty(fieldValue(f)))
|
|
102
140
|
// What the work starts from — a screenshot of the bug, a mockup, a spec (RFC 0022).
|
|
103
141
|
const draft = useAttachmentDraft()
|
|
104
142
|
|
|
@@ -111,6 +149,7 @@ export function NewTaskDialog({
|
|
|
111
149
|
setBaseBranch("")
|
|
112
150
|
setModel("")
|
|
113
151
|
setProjectId("")
|
|
152
|
+
setPicked({})
|
|
114
153
|
draft.clear()
|
|
115
154
|
}
|
|
116
155
|
if (openProp === undefined) setLocalOpen(next)
|
|
@@ -121,6 +160,8 @@ export function NewTaskDialog({
|
|
|
121
160
|
e.preventDefault()
|
|
122
161
|
if (asksProject && !projectId) return
|
|
123
162
|
if (!prompt.trim()) return
|
|
163
|
+
if (missingRequired) return
|
|
164
|
+
const values = Object.fromEntries(fields.map((f) => [f.id, fieldValue(f)] as const).filter(([, v]) => !isEmpty(v)))
|
|
124
165
|
onSubmit({
|
|
125
166
|
...(asksProject ? { projectId } : {}),
|
|
126
167
|
prompt: prompt.trim(),
|
|
@@ -128,6 +169,7 @@ export function NewTaskDialog({
|
|
|
128
169
|
...(baseBranch.trim() ? { baseBranch: baseBranch.trim() } : {}),
|
|
129
170
|
...(model.trim() ? { model: model.trim() } : {}),
|
|
130
171
|
files: draft.files,
|
|
172
|
+
...(Object.keys(values).length > 0 ? { fields: values } : {}),
|
|
131
173
|
})
|
|
132
174
|
}
|
|
133
175
|
|
|
@@ -283,13 +325,24 @@ export function NewTaskDialog({
|
|
|
283
325
|
</p>
|
|
284
326
|
</div>
|
|
285
327
|
|
|
328
|
+
{fields.map((f) => (
|
|
329
|
+
<div key={f.id} className="flex flex-col gap-1.5" data-slot="new-task-field" data-field={f.id}>
|
|
330
|
+
<Label>
|
|
331
|
+
{f.label}
|
|
332
|
+
{f.labelHint && <span className="font-normal text-muted-foreground/70"> — {f.labelHint}</span>}
|
|
333
|
+
</Label>
|
|
334
|
+
{f.render(fieldValue(f), (v) => setPicked((prev) => ({ ...prev, [f.id]: v })))}
|
|
335
|
+
{f.hint && <p className="text-[11px] text-muted-foreground">{f.hint}</p>}
|
|
336
|
+
</div>
|
|
337
|
+
))}
|
|
338
|
+
|
|
286
339
|
{error && <p className="text-xs text-destructive">{error}</p>}
|
|
287
340
|
|
|
288
341
|
<DialogFooter>
|
|
289
342
|
<Button type="button" variant="outline" size="sm" onClick={() => handleOpen(false)}>
|
|
290
343
|
Cancel
|
|
291
344
|
</Button>
|
|
292
|
-
<Button type="submit" size="sm" className="gap-1.5" disabled={submitting || (asksProject && !projectId) || !prompt.trim()}>
|
|
345
|
+
<Button type="submit" size="sm" className="gap-1.5" disabled={submitting || (asksProject && !projectId) || !prompt.trim() || missingRequired}>
|
|
293
346
|
<SparklesIcon className="h-3.5 w-3.5" />
|
|
294
347
|
{submitting ? "Delegating…" : "Delegate"}
|
|
295
348
|
</Button>
|
|
@@ -13,6 +13,7 @@ import { renderInlineMarkdown } from "./agent-markdown"
|
|
|
13
13
|
import { emptyCommandTerminalState, planCommandTerminalWrites } from "./command-terminal"
|
|
14
14
|
import { TaskComposer } from "./composer"
|
|
15
15
|
import { TaskBoot, bootSteps } from "./machine"
|
|
16
|
+
import { NewTaskDialog, type NewTaskCustomField } from "./new-task-dialog"
|
|
16
17
|
import { formatCost, formatTokens } from "./session-usage"
|
|
17
18
|
import { TaskCockpit } from "./task-cockpit"
|
|
18
19
|
import { TaskDetails } from "./task-details"
|
|
@@ -22,6 +23,7 @@ import { TaskTitle } from "./task-title"
|
|
|
22
23
|
import { runStats, toolSubject, toolVerb, type ToolRun } from "./tool-stack"
|
|
23
24
|
import type { TaskCommand, TaskEvent, TaskItem } from "./types"
|
|
24
25
|
import { indexTasksByWorker } from "./worker-link"
|
|
26
|
+
import { WorkerCard } from "../workers/worker-card"
|
|
25
27
|
|
|
26
28
|
const ev = (seq: number, type: string, payload: Record<string, unknown>, ts = `2026-09-24T10:00:${String(seq).padStart(2, "0")}Z`): TaskEvent => ({
|
|
27
29
|
seq,
|
|
@@ -191,6 +193,22 @@ describe("worker ↔ task", () => {
|
|
|
191
193
|
expect(index.get("w1")).toMatchObject({ task: { id: "live" }, live: true })
|
|
192
194
|
expect(index.get("w2")).toMatchObject({ task: { id: "other" }, live: false })
|
|
193
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("keeps the task line when the caller replaces the footer, and draws none without a task", () => {
|
|
205
|
+
const entry = indexTasksByWorker([task({ title: "Ship the card", workerId: "w1" })]).get("w1")!
|
|
206
|
+
const { rerender } = render(<WorkerCard worker={{ id: "w1" }} task={{ entry, href: "/t" }} footer={<button>IDE</button>} />)
|
|
207
|
+
expect(screen.getByText("Ship the card")).toBeTruthy()
|
|
208
|
+
expect(screen.getByRole("button", { name: "IDE" })).toBeTruthy()
|
|
209
|
+
rerender(<WorkerCard worker={{ id: "w1" }} href="/w/w1" />)
|
|
210
|
+
expect(screen.queryByText("Task")).toBeNull()
|
|
211
|
+
})
|
|
194
212
|
})
|
|
195
213
|
|
|
196
214
|
describe("formatters", () => {
|
|
@@ -394,3 +412,54 @@ describe("TaskDetails", () => {
|
|
|
394
412
|
await waitFor(() => expect(screen.getByTitle("Copied")).toBeTruthy())
|
|
395
413
|
})
|
|
396
414
|
})
|
|
415
|
+
|
|
416
|
+
describe("NewTaskDialog — the app's own fields", () => {
|
|
417
|
+
const size = (over: Partial<NewTaskCustomField> = {}): NewTaskCustomField => ({
|
|
418
|
+
id: "size",
|
|
419
|
+
label: "Machine",
|
|
420
|
+
hint: "Billed per second.",
|
|
421
|
+
defaultValue: "default",
|
|
422
|
+
render: (value, onChange) => (
|
|
423
|
+
<select aria-label="Machine" value={String(value ?? "")} onChange={(e) => onChange(e.target.value)}>
|
|
424
|
+
<option value="">—</option>
|
|
425
|
+
<option value="default">8 GB</option>
|
|
426
|
+
<option value="large">16 GB</option>
|
|
427
|
+
</select>
|
|
428
|
+
),
|
|
429
|
+
...over,
|
|
430
|
+
})
|
|
431
|
+
const fill = () => fireEvent.change(screen.getByPlaceholderText(/What the agent should do/), { target: { value: "Fix it" } })
|
|
432
|
+
const delegate = () => screen.getByRole("button", { name: /Delegate/ })
|
|
433
|
+
|
|
434
|
+
it("draws them with their label and hint, and sends their default when nobody picks", () => {
|
|
435
|
+
const onSubmit = vi.fn()
|
|
436
|
+
render(<NewTaskDialog open trigger={null} fields={[size()]} onSubmit={onSubmit} />)
|
|
437
|
+
expect(screen.getByText("Machine")).toBeTruthy()
|
|
438
|
+
expect(screen.getByText("Billed per second.")).toBeTruthy()
|
|
439
|
+
fill()
|
|
440
|
+
fireEvent.click(delegate())
|
|
441
|
+
expect(onSubmit.mock.calls[0]![0]).toMatchObject({ prompt: "Fix it", fields: { size: "default" } })
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
it("sends what was picked, and a default that arrives after the form opened", () => {
|
|
445
|
+
const onSubmit = vi.fn()
|
|
446
|
+
const { rerender } = render(<NewTaskDialog open trigger={null} fields={[size({ defaultValue: undefined })]} onSubmit={onSubmit} />)
|
|
447
|
+
rerender(<NewTaskDialog open trigger={null} fields={[size({ defaultValue: "large" })]} onSubmit={onSubmit} />)
|
|
448
|
+
fill()
|
|
449
|
+
fireEvent.click(delegate())
|
|
450
|
+
expect(onSubmit.mock.calls[0]![0].fields).toEqual({ size: "large" })
|
|
451
|
+
fireEvent.change(screen.getByLabelText("Machine"), { target: { value: "default" } })
|
|
452
|
+
fireEvent.click(delegate())
|
|
453
|
+
expect(onSubmit.mock.calls[1]![0].fields).toEqual({ size: "default" })
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
it("a required field left empty keeps Delegate off; an empty optional one is left out", () => {
|
|
457
|
+
const onSubmit = vi.fn()
|
|
458
|
+
const { rerender } = render(<NewTaskDialog open trigger={null} fields={[size({ defaultValue: undefined, required: true })]} onSubmit={onSubmit} />)
|
|
459
|
+
fill()
|
|
460
|
+
expect((delegate() as HTMLButtonElement).disabled).toBe(true)
|
|
461
|
+
rerender(<NewTaskDialog open trigger={null} fields={[size({ defaultValue: undefined })]} onSubmit={onSubmit} />)
|
|
462
|
+
fireEvent.click(delegate())
|
|
463
|
+
expect(onSubmit.mock.calls[0]![0].fields).toBeUndefined()
|
|
464
|
+
})
|
|
465
|
+
})
|
|
@@ -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>
|