@spunto/design-system 0.38.0 → 0.39.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
@@ -323,7 +323,7 @@ review. Every surface that shows one:
323
323
  - **`TaskDetails`** (`sidebar` | `sheet`) with **`TaskMachine`**, **`TaskBoot`**,
324
324
  `TaskSessionUsage`, `TaskPullRequest`, `TaskCommandLog` — the facts about a task, in
325
325
  one order, instead of two hand-kept copies.
326
- - **`NewTaskDialog`** — delegating: prompt, files, title, base branch, model.
326
+ - **`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
327
  - Vocabulary and helpers: `TaskStateBadge`, `taskStateConfig`, `useElapsed`,
328
328
  `AgentMarkdown`, `useAttachmentDraft`/`prepareFile`/`TaskFiles` (files, RFC 0022),
329
329
  `runStats`/`toolVerb`/`toolSubject`, `bootSteps`, `indexTasksByWorker`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spunto/design-system",
3
- "version": "0.38.0",
3
+ "version": "0.39.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",
@@ -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. No machine to pick — the task
4
- // allocates its own worker (a recycled one when the pool has a free machine), which is the whole
5
- // point of the object.
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"
@@ -394,3 +395,54 @@ describe("TaskDetails", () => {
394
395
  await waitFor(() => expect(screen.getByTitle("Copied")).toBeTruthy())
395
396
  })
396
397
  })
398
+
399
+ describe("NewTaskDialog — the app's own fields", () => {
400
+ const size = (over: Partial<NewTaskCustomField> = {}): NewTaskCustomField => ({
401
+ id: "size",
402
+ label: "Machine",
403
+ hint: "Billed per second.",
404
+ defaultValue: "default",
405
+ render: (value, onChange) => (
406
+ <select aria-label="Machine" value={String(value ?? "")} onChange={(e) => onChange(e.target.value)}>
407
+ <option value="">—</option>
408
+ <option value="default">8 GB</option>
409
+ <option value="large">16 GB</option>
410
+ </select>
411
+ ),
412
+ ...over,
413
+ })
414
+ const fill = () => fireEvent.change(screen.getByPlaceholderText(/What the agent should do/), { target: { value: "Fix it" } })
415
+ const delegate = () => screen.getByRole("button", { name: /Delegate/ })
416
+
417
+ it("draws them with their label and hint, and sends their default when nobody picks", () => {
418
+ const onSubmit = vi.fn()
419
+ render(<NewTaskDialog open trigger={null} fields={[size()]} onSubmit={onSubmit} />)
420
+ expect(screen.getByText("Machine")).toBeTruthy()
421
+ expect(screen.getByText("Billed per second.")).toBeTruthy()
422
+ fill()
423
+ fireEvent.click(delegate())
424
+ expect(onSubmit.mock.calls[0]![0]).toMatchObject({ prompt: "Fix it", fields: { size: "default" } })
425
+ })
426
+
427
+ it("sends what was picked, and a default that arrives after the form opened", () => {
428
+ const onSubmit = vi.fn()
429
+ const { rerender } = render(<NewTaskDialog open trigger={null} fields={[size({ defaultValue: undefined })]} onSubmit={onSubmit} />)
430
+ rerender(<NewTaskDialog open trigger={null} fields={[size({ defaultValue: "large" })]} onSubmit={onSubmit} />)
431
+ fill()
432
+ fireEvent.click(delegate())
433
+ expect(onSubmit.mock.calls[0]![0].fields).toEqual({ size: "large" })
434
+ fireEvent.change(screen.getByLabelText("Machine"), { target: { value: "default" } })
435
+ fireEvent.click(delegate())
436
+ expect(onSubmit.mock.calls[1]![0].fields).toEqual({ size: "default" })
437
+ })
438
+
439
+ it("a required field left empty keeps Delegate off; an empty optional one is left out", () => {
440
+ const onSubmit = vi.fn()
441
+ const { rerender } = render(<NewTaskDialog open trigger={null} fields={[size({ defaultValue: undefined, required: true })]} onSubmit={onSubmit} />)
442
+ fill()
443
+ expect((delegate() as HTMLButtonElement).disabled).toBe(true)
444
+ rerender(<NewTaskDialog open trigger={null} fields={[size({ defaultValue: undefined })]} onSubmit={onSubmit} />)
445
+ fireEvent.click(delegate())
446
+ expect(onSubmit.mock.calls[0]![0].fields).toBeUndefined()
447
+ })
448
+ })