@spunto/design-system 0.44.0 → 0.45.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/package.json
CHANGED
|
@@ -31,6 +31,8 @@ export { TaskWorkerChip, WorkerTaskChip, WorkerTaskHistory, indexTasksByWorker }
|
|
|
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"
|
|
34
|
+
export { NewTaskComposer, newTaskChipClassName } from "./new-task-composer"
|
|
35
|
+
export type { NewTaskComposerProps } from "./new-task-composer"
|
|
34
36
|
|
|
35
37
|
// ── The cockpit ─────────────────────────────────────────────────────────────────────────────
|
|
36
38
|
export { TaskCockpit, TaskPanelTabs } from "./task-cockpit"
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
// Delegating work, where the conversation is going to be.
|
|
4
|
+
//
|
|
5
|
+
// `NewTaskDialog` asks for a task in a form over the page; this asks for it in the place its
|
|
6
|
+
// session will stream: the empty transcript above, the box at the bottom — the same box, at the
|
|
7
|
+
// same spot, as the `TaskComposer` that answers the agent once it runs. Writing the first message
|
|
8
|
+
// and writing the next ones is one gesture, so it gets one shape: the words take the room, and
|
|
9
|
+
// where the work happens (project, base branch, model, the app's own fields — which machine…) is
|
|
10
|
+
// a row of chips under them, each showing what will be used if nobody touches it.
|
|
11
|
+
//
|
|
12
|
+
// The title is not asked: the task takes the name the agent gives the conversation, and the
|
|
13
|
+
// cockpit renames it in place afterwards (`TaskTitle`).
|
|
14
|
+
//
|
|
15
|
+
// Presentational like the rest of `/tasks`, with the dialog's contract: lists come in as props,
|
|
16
|
+
// the value goes out through `onSubmit` (a `NewTaskValue`, without `title`), `submitting`/`error`
|
|
17
|
+
// come back down. It fills its parent like `TaskCockpit`, so it can stand where a cockpit stands.
|
|
18
|
+
|
|
19
|
+
import { useState, type ReactNode } from "react"
|
|
20
|
+
import { ArrowLeftIcon, CornerDownLeftIcon, FolderIcon, GitBranchIcon, Loader2Icon, PackageIcon, SparklesIcon } from "lucide-react"
|
|
21
|
+
|
|
22
|
+
import { cn } from "../../utils"
|
|
23
|
+
import { Button } from "../button"
|
|
24
|
+
import { buttonVariants } from "../button-variants"
|
|
25
|
+
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxItem, ComboboxList, ComboboxSearch, ComboboxTrigger, ComboboxValue } from "../combobox"
|
|
26
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select"
|
|
27
|
+
import type { LinkRender } from "../workers/worker-card"
|
|
28
|
+
import type { NewTaskCustomField, NewTaskModelGroup, NewTaskValue } from "./new-task-dialog"
|
|
29
|
+
import { AttachFileButton, AttachmentDraftStrip, FileDropOverlay, useAttachmentDraft } from "./task-attachments"
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The look of an option under the box — a quiet pill that shows its value. Exported for the
|
|
33
|
+
* app's own `fields`: put it on a `SelectTrigger` (it overrides the field look) and the chip sits
|
|
34
|
+
* in the row like the package's own.
|
|
35
|
+
*/
|
|
36
|
+
export const newTaskChipClassName =
|
|
37
|
+
"h-7 w-auto max-w-60 gap-1.5 rounded-md border-transparent bg-muted/60 px-2 text-xs font-normal text-muted-foreground shadow-none hover:bg-muted hover:text-foreground data-[popup-open]:bg-muted data-[popup-open]:text-foreground [&_svg]:size-3.5 [&_svg]:shrink-0 dark:bg-muted/40"
|
|
38
|
+
|
|
39
|
+
export interface NewTaskComposerProps {
|
|
40
|
+
/** Pass the org's projects when no project is in scope: a chip then asks for one, and Delegate waits for it. */
|
|
41
|
+
projects?: { id: string; name: string }[]
|
|
42
|
+
/** Called when a project is picked, so the app can load that project's branches and default model. */
|
|
43
|
+
onProjectChange?: (projectId: string) => void
|
|
44
|
+
/** Branches common to the project's repositories. Any name typed is accepted too. */
|
|
45
|
+
branches?: string[]
|
|
46
|
+
defaultBranch?: string | null
|
|
47
|
+
modelGroups?: NewTaskModelGroup[]
|
|
48
|
+
/** The project's default model — what the chip says when nobody picked one. */
|
|
49
|
+
defaultModel?: string | null
|
|
50
|
+
/**
|
|
51
|
+
* The app's own fields, drawn as chips after the package's: `render` should draw a compact
|
|
52
|
+
* control (`newTaskChipClassName`); `label` and `hint` become its tooltip.
|
|
53
|
+
*/
|
|
54
|
+
fields?: NewTaskCustomField[]
|
|
55
|
+
/** Every pick of an app field, as it happens — for fields whose options depend on another one. */
|
|
56
|
+
onFieldChange?: (id: string, value: unknown) => void
|
|
57
|
+
|
|
58
|
+
onSubmit: (value: Omit<NewTaskValue, "title">) => void
|
|
59
|
+
submitting?: boolean
|
|
60
|
+
error?: string | null
|
|
61
|
+
|
|
62
|
+
/** Top bar title. @default "New task" */
|
|
63
|
+
title?: ReactNode
|
|
64
|
+
/** One line under the question in the empty transcript — where it will run, typically. */
|
|
65
|
+
description?: ReactNode
|
|
66
|
+
/** Back arrow in the top bar: a link… */
|
|
67
|
+
backHref?: string
|
|
68
|
+
/** …or a callback (a phone's one-pane list). */
|
|
69
|
+
onBack?: () => void
|
|
70
|
+
render?: { link?: LinkRender }
|
|
71
|
+
className?: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const defaultLink: LinkRender = ({ href, className, children }) => (
|
|
75
|
+
<a href={href} className={className}>
|
|
76
|
+
{children}
|
|
77
|
+
</a>
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
type ChipGroup = { id: string; heading?: string; items: { value: string; label?: string; meta?: string }[] }
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A chip whose value can be picked from a list *or* typed — a branch that is not pushed yet, a
|
|
84
|
+
* model id the presets do not know. What is typed is offered as the first row.
|
|
85
|
+
*/
|
|
86
|
+
function FreeTextChip({
|
|
87
|
+
label,
|
|
88
|
+
icon,
|
|
89
|
+
value,
|
|
90
|
+
onChange,
|
|
91
|
+
placeholder,
|
|
92
|
+
groups,
|
|
93
|
+
searchPlaceholder,
|
|
94
|
+
mono = false,
|
|
95
|
+
}: {
|
|
96
|
+
label: string
|
|
97
|
+
icon: ReactNode
|
|
98
|
+
value: string
|
|
99
|
+
onChange: (value: string) => void
|
|
100
|
+
/** What the chip says while `value` is empty: the default that will apply. */
|
|
101
|
+
placeholder: string
|
|
102
|
+
groups: ChipGroup[]
|
|
103
|
+
searchPlaceholder: string
|
|
104
|
+
mono?: boolean
|
|
105
|
+
}) {
|
|
106
|
+
const [query, setQuery] = useState("")
|
|
107
|
+
const typed = query.trim()
|
|
108
|
+
const known = groups.some((g) => g.items.some((i) => i.value === typed))
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<Combobox
|
|
112
|
+
value={value || null}
|
|
113
|
+
onValueChange={(next) => onChange((next as string | null) ?? "")}
|
|
114
|
+
onInputValueChange={(text, details) => {
|
|
115
|
+
if (details.reason === "input-change") setQuery(text)
|
|
116
|
+
}}
|
|
117
|
+
onOpenChange={(open) => {
|
|
118
|
+
if (!open) setQuery("")
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
<ComboboxTrigger aria-label={label} title={label} className={newTaskChipClassName}>
|
|
122
|
+
{icon}
|
|
123
|
+
<ComboboxValue placeholder={placeholder}>{value ? <span className={cn("truncate", mono && "font-mono")}>{value}</span> : null}</ComboboxValue>
|
|
124
|
+
</ComboboxTrigger>
|
|
125
|
+
<ComboboxContent className="w-72">
|
|
126
|
+
<ComboboxSearch placeholder={searchPlaceholder} />
|
|
127
|
+
<ComboboxList>
|
|
128
|
+
{typed && !known && (
|
|
129
|
+
<ComboboxItem value={typed} label={typed} icon={icon}>
|
|
130
|
+
Use <span className={cn(mono && "font-mono")}>“{typed}”</span>
|
|
131
|
+
</ComboboxItem>
|
|
132
|
+
)}
|
|
133
|
+
{value && !typed && (
|
|
134
|
+
<ComboboxItem value="" label="default" className="text-muted-foreground">
|
|
135
|
+
{placeholder}
|
|
136
|
+
</ComboboxItem>
|
|
137
|
+
)}
|
|
138
|
+
<ComboboxEmpty>Type a name to use it as is</ComboboxEmpty>
|
|
139
|
+
{groups.map((g) => (
|
|
140
|
+
<ComboboxGroup key={g.id} heading={g.heading}>
|
|
141
|
+
{g.items.map((i) => (
|
|
142
|
+
<ComboboxItem key={i.value} value={i.value} keywords={i.label ? [i.label] : []} meta={i.meta} className={cn(mono && "font-mono")}>
|
|
143
|
+
{i.value}
|
|
144
|
+
</ComboboxItem>
|
|
145
|
+
))}
|
|
146
|
+
</ComboboxGroup>
|
|
147
|
+
))}
|
|
148
|
+
</ComboboxList>
|
|
149
|
+
</ComboboxContent>
|
|
150
|
+
</Combobox>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function NewTaskComposer({
|
|
155
|
+
projects,
|
|
156
|
+
onProjectChange,
|
|
157
|
+
branches = [],
|
|
158
|
+
defaultBranch = null,
|
|
159
|
+
modelGroups = [],
|
|
160
|
+
defaultModel = null,
|
|
161
|
+
fields = [],
|
|
162
|
+
onFieldChange,
|
|
163
|
+
onSubmit,
|
|
164
|
+
submitting = false,
|
|
165
|
+
error = null,
|
|
166
|
+
title = "New task",
|
|
167
|
+
description,
|
|
168
|
+
backHref,
|
|
169
|
+
onBack,
|
|
170
|
+
render,
|
|
171
|
+
className,
|
|
172
|
+
}: NewTaskComposerProps) {
|
|
173
|
+
const [prompt, setPrompt] = useState("")
|
|
174
|
+
const [baseBranch, setBaseBranch] = useState("")
|
|
175
|
+
const [model, setModel] = useState("")
|
|
176
|
+
const [projectId, setProjectId] = useState("")
|
|
177
|
+
// Only what was picked: a field nobody touched reads its (current) `defaultValue`.
|
|
178
|
+
const [picked, setPicked] = useState<Record<string, unknown>>({})
|
|
179
|
+
const draft = useAttachmentDraft()
|
|
180
|
+
const Link = render?.link ?? defaultLink
|
|
181
|
+
|
|
182
|
+
const fieldValue = (f: NewTaskCustomField) => (f.id in picked ? picked[f.id] : f.defaultValue)
|
|
183
|
+
const isEmpty = (v: unknown) => v === undefined || v === null || v === ""
|
|
184
|
+
const missingRequired = fields.some((f) => f.required && isEmpty(fieldValue(f)))
|
|
185
|
+
const asksProject = projects !== undefined
|
|
186
|
+
const disabled = submitting || (asksProject && !projectId) || !prompt.trim() || missingRequired
|
|
187
|
+
|
|
188
|
+
// Why Delegate is off, said where the hint goes — a greyed-out button owes an answer.
|
|
189
|
+
const reason =
|
|
190
|
+
asksProject && !projectId
|
|
191
|
+
? "Pick a project first."
|
|
192
|
+
: missingRequired
|
|
193
|
+
? `Pick “${fields.find((f) => f.required && isEmpty(fieldValue(f)))!.label}” first.`
|
|
194
|
+
: null
|
|
195
|
+
|
|
196
|
+
function submit() {
|
|
197
|
+
if (disabled) return
|
|
198
|
+
const values = Object.fromEntries(fields.map((f) => [f.id, fieldValue(f)] as const).filter(([, v]) => !isEmpty(v)))
|
|
199
|
+
onSubmit({
|
|
200
|
+
...(asksProject ? { projectId } : {}),
|
|
201
|
+
prompt: prompt.trim(),
|
|
202
|
+
...(baseBranch.trim() ? { baseBranch: baseBranch.trim() } : {}),
|
|
203
|
+
...(model.trim() ? { model: model.trim() } : {}),
|
|
204
|
+
files: draft.files,
|
|
205
|
+
...(Object.keys(values).length > 0 ? { fields: values } : {}),
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const back = backHref ? (
|
|
210
|
+
<Link href={backHref} className={cn(buttonVariants({ variant: "ghost", size: "icon" }), "h-8 w-8 shrink-0")}>
|
|
211
|
+
<ArrowLeftIcon className="h-4 w-4" />
|
|
212
|
+
</Link>
|
|
213
|
+
) : onBack ? (
|
|
214
|
+
<Button variant="ghost" size="icon" className="h-8 w-8 shrink-0" onClick={onBack} aria-label="Back">
|
|
215
|
+
<ArrowLeftIcon className="h-4 w-4" />
|
|
216
|
+
</Button>
|
|
217
|
+
) : null
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<div className={cn("@container flex min-h-0 flex-1 flex-col overflow-hidden", className)} data-slot="new-task-composer">
|
|
221
|
+
{/* ── Top bar: the cockpit's, before there is a task to name ── */}
|
|
222
|
+
<div className="flex shrink-0 items-center gap-2 border-b border-border bg-card/60 px-4 py-2.5 backdrop-blur-sm @min-[48rem]:px-5">
|
|
223
|
+
{back && (
|
|
224
|
+
<>
|
|
225
|
+
{back}
|
|
226
|
+
<div className="h-4 w-px shrink-0 bg-border" />
|
|
227
|
+
</>
|
|
228
|
+
)}
|
|
229
|
+
<h1 className="truncate text-sm font-semibold">{title}</h1>
|
|
230
|
+
</div>
|
|
231
|
+
|
|
232
|
+
{/* ── The transcript, still empty ── */}
|
|
233
|
+
<div className="flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-6 py-8">
|
|
234
|
+
<div className="max-w-md text-center">
|
|
235
|
+
<div className="mx-auto flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary">
|
|
236
|
+
<SparklesIcon className="h-5 w-5" />
|
|
237
|
+
</div>
|
|
238
|
+
<p className="mt-3 text-base font-semibold">What should the agent do?</p>
|
|
239
|
+
<p className="mt-1 text-xs leading-relaxed text-muted-foreground">
|
|
240
|
+
{description ??
|
|
241
|
+
"It gets its own machine and its own branch. Its session streams right here as soon as it starts — answer it as it works."}
|
|
242
|
+
</p>
|
|
243
|
+
</div>
|
|
244
|
+
</div>
|
|
245
|
+
|
|
246
|
+
{/* ── The box: where `TaskComposer` will be ── */}
|
|
247
|
+
<div className="shrink-0 border-t border-border bg-card/40 px-3 py-3 @min-[40rem]:px-8">
|
|
248
|
+
<div className="mx-auto max-w-3xl">
|
|
249
|
+
{error && (
|
|
250
|
+
<p className="mb-2 rounded-md border border-destructive/25 bg-destructive/5 px-2.5 py-1.5 text-[11px] text-destructive">{error}</p>
|
|
251
|
+
)}
|
|
252
|
+
|
|
253
|
+
<div {...draft.dropZone} className="relative rounded-lg border bg-background transition-colors focus-within:border-primary/40">
|
|
254
|
+
{draft.draggingOver && <FileDropOverlay />}
|
|
255
|
+
<AttachmentDraftStrip draft={draft} />
|
|
256
|
+
<div className="flex items-start gap-1.5 pl-2 pt-2">
|
|
257
|
+
<AttachFileButton disabled={submitting} onFiles={(files: File[]) => void draft.add(files)} />
|
|
258
|
+
<div className="-ml-1 min-w-0 flex-1">
|
|
259
|
+
<textarea
|
|
260
|
+
value={prompt}
|
|
261
|
+
onChange={(e) => setPrompt(e.target.value)}
|
|
262
|
+
// Same keys as the reply box below a running task: it is the same box.
|
|
263
|
+
onKeyDown={(e) => {
|
|
264
|
+
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
265
|
+
e.preventDefault()
|
|
266
|
+
submit()
|
|
267
|
+
}
|
|
268
|
+
}}
|
|
269
|
+
onPaste={draft.onPaste}
|
|
270
|
+
disabled={submitting}
|
|
271
|
+
rows={3}
|
|
272
|
+
autoFocus
|
|
273
|
+
aria-label="Prompt"
|
|
274
|
+
placeholder="Describe the work as you would to a teammate. Paste or drop a screenshot, a PDF, a CSV…"
|
|
275
|
+
// `field-sizing` grows the box with the prompt, up to a third of the screen.
|
|
276
|
+
className="max-h-[35vh] min-h-[4.5rem] w-full resize-none bg-transparent px-3 py-2 text-base outline-none [field-sizing:content] placeholder:text-muted-foreground disabled:cursor-not-allowed @min-[40rem]:text-sm"
|
|
277
|
+
/>
|
|
278
|
+
</div>
|
|
279
|
+
</div>
|
|
280
|
+
|
|
281
|
+
{/* ── Where the work happens: what is used unless picked otherwise ── */}
|
|
282
|
+
<div className="flex flex-wrap items-center gap-1.5 border-t border-border/60 px-2 py-1.5">
|
|
283
|
+
{asksProject && (
|
|
284
|
+
<Select
|
|
285
|
+
value={projectId || null}
|
|
286
|
+
onValueChange={(value) => {
|
|
287
|
+
const next = (value as string | null) ?? ""
|
|
288
|
+
setProjectId(next)
|
|
289
|
+
// The branch list belongs to the previous project.
|
|
290
|
+
setBaseBranch("")
|
|
291
|
+
if (next) onProjectChange?.(next)
|
|
292
|
+
}}
|
|
293
|
+
>
|
|
294
|
+
<SelectTrigger
|
|
295
|
+
aria-label="Project"
|
|
296
|
+
title="Where the work happens: its repositories, its harness, its settings."
|
|
297
|
+
className={cn(newTaskChipClassName, !projectId && "bg-primary/10 text-primary hover:bg-primary/15 hover:text-primary")}
|
|
298
|
+
>
|
|
299
|
+
<FolderIcon />
|
|
300
|
+
<SelectValue>{(value: unknown) => projects.find((p) => p.id === value)?.name ?? "Pick a project"}</SelectValue>
|
|
301
|
+
</SelectTrigger>
|
|
302
|
+
<SelectContent>
|
|
303
|
+
{projects.map((p) => (
|
|
304
|
+
<SelectItem key={p.id} value={p.id}>
|
|
305
|
+
{p.name}
|
|
306
|
+
</SelectItem>
|
|
307
|
+
))}
|
|
308
|
+
</SelectContent>
|
|
309
|
+
</Select>
|
|
310
|
+
)}
|
|
311
|
+
|
|
312
|
+
<FreeTextChip
|
|
313
|
+
label="Base branch"
|
|
314
|
+
icon={<GitBranchIcon />}
|
|
315
|
+
value={baseBranch}
|
|
316
|
+
onChange={setBaseBranch}
|
|
317
|
+
placeholder={defaultBranch ?? "default branch"}
|
|
318
|
+
groups={[{ id: "branches", items: branches.map((b) => ({ value: b })) }]}
|
|
319
|
+
searchPlaceholder="Start from…"
|
|
320
|
+
/>
|
|
321
|
+
|
|
322
|
+
<FreeTextChip
|
|
323
|
+
label="Model"
|
|
324
|
+
icon={<PackageIcon />}
|
|
325
|
+
value={model}
|
|
326
|
+
onChange={setModel}
|
|
327
|
+
placeholder={defaultModel ?? "harness default"}
|
|
328
|
+
groups={modelGroups.map((g) => ({ id: g.id, heading: g.label, items: g.models.map((m) => ({ value: m.value, label: m.label, meta: m.label })) }))}
|
|
329
|
+
searchPlaceholder="Any model id your harness understands"
|
|
330
|
+
mono
|
|
331
|
+
/>
|
|
332
|
+
|
|
333
|
+
{fields.map((f) => (
|
|
334
|
+
<span
|
|
335
|
+
key={f.id}
|
|
336
|
+
className="inline-flex"
|
|
337
|
+
data-slot="new-task-field"
|
|
338
|
+
data-field={f.id}
|
|
339
|
+
title={[f.label, typeof f.hint === "string" ? f.hint : null].filter(Boolean).join(" — ")}
|
|
340
|
+
>
|
|
341
|
+
{f.render(fieldValue(f), (v) => {
|
|
342
|
+
setPicked((prev) => ({ ...prev, [f.id]: v }))
|
|
343
|
+
onFieldChange?.(f.id, v)
|
|
344
|
+
})}
|
|
345
|
+
</span>
|
|
346
|
+
))}
|
|
347
|
+
|
|
348
|
+
<div className="ml-auto flex items-center gap-2 pl-2">
|
|
349
|
+
<span className="hidden truncate text-[10px] text-muted-foreground @min-[36rem]:inline">
|
|
350
|
+
{reason ?? "Enter to delegate · Shift+Enter for a new line"}
|
|
351
|
+
</span>
|
|
352
|
+
<Button size="sm" className="h-7 gap-1.5 px-2.5 text-xs" disabled={disabled} onClick={submit}>
|
|
353
|
+
{submitting ? <Loader2Icon className="h-3 w-3 animate-spin" /> : <CornerDownLeftIcon className="h-3 w-3" />}
|
|
354
|
+
{submitting ? "Delegating…" : "Delegate"}
|
|
355
|
+
</Button>
|
|
356
|
+
</div>
|
|
357
|
+
</div>
|
|
358
|
+
</div>
|
|
359
|
+
</div>
|
|
360
|
+
</div>
|
|
361
|
+
</div>
|
|
362
|
+
)
|
|
363
|
+
}
|
|
@@ -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 { NewTaskComposer } from "./new-task-composer"
|
|
16
17
|
import { NewTaskDialog, type NewTaskCustomField } from "./new-task-dialog"
|
|
17
18
|
import { formatCost, formatTokens } from "./session-usage"
|
|
18
19
|
import { TaskCockpit } from "./task-cockpit"
|
|
@@ -488,3 +489,65 @@ describe("NewTaskDialog — the app's own fields", () => {
|
|
|
488
489
|
expect(onSubmit.mock.calls[0]![0].fields).toBeUndefined()
|
|
489
490
|
})
|
|
490
491
|
})
|
|
492
|
+
|
|
493
|
+
describe("NewTaskComposer — delegating where the conversation will be", () => {
|
|
494
|
+
const machine = (over: Partial<NewTaskCustomField> = {}): NewTaskCustomField => ({
|
|
495
|
+
id: "machine",
|
|
496
|
+
label: "Runs on",
|
|
497
|
+
defaultValue: "worker",
|
|
498
|
+
render: (value, onChange) => (
|
|
499
|
+
<select aria-label="Runs on" value={String(value ?? "")} onChange={(e) => onChange(e.target.value)}>
|
|
500
|
+
<option value="">—</option>
|
|
501
|
+
<option value="worker">Worker</option>
|
|
502
|
+
<option value="sandbox">Sandbox</option>
|
|
503
|
+
</select>
|
|
504
|
+
),
|
|
505
|
+
...over,
|
|
506
|
+
})
|
|
507
|
+
const prompt = () => screen.getByRole("textbox", { name: "Prompt" })
|
|
508
|
+
const delegate = () => screen.getByRole("button", { name: /Delegate/ }) as HTMLButtonElement
|
|
509
|
+
|
|
510
|
+
it("Enter delegates, Shift+Enter does not, and blank options are left out", () => {
|
|
511
|
+
const onSubmit = vi.fn()
|
|
512
|
+
render(<NewTaskComposer defaultBranch="main" defaultModel="claude-opus-5" onSubmit={onSubmit} />)
|
|
513
|
+
// The chips say what will be used when nobody picks.
|
|
514
|
+
expect(screen.getByText("main")).toBeTruthy()
|
|
515
|
+
expect(screen.getByText("claude-opus-5")).toBeTruthy()
|
|
516
|
+
fireEvent.change(prompt(), { target: { value: " Fix the login on Safari " } })
|
|
517
|
+
fireEvent.keyDown(prompt(), { key: "Enter", shiftKey: true })
|
|
518
|
+
expect(onSubmit).not.toHaveBeenCalled()
|
|
519
|
+
fireEvent.keyDown(prompt(), { key: "Enter" })
|
|
520
|
+
expect(onSubmit).toHaveBeenCalledTimes(1)
|
|
521
|
+
expect(onSubmit.mock.calls[0]![0]).toEqual({ prompt: "Fix the login on Safari", files: [] })
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
it("org-wide, Delegate waits for a project and says so", () => {
|
|
525
|
+
const onSubmit = vi.fn()
|
|
526
|
+
render(<NewTaskComposer projects={[{ id: "p1", name: "spunto" }]} onSubmit={onSubmit} />)
|
|
527
|
+
fireEvent.change(prompt(), { target: { value: "Fix it" } })
|
|
528
|
+
expect(delegate().disabled).toBe(true)
|
|
529
|
+
expect(screen.getByText("Pick a project first.")).toBeTruthy()
|
|
530
|
+
fireEvent.keyDown(prompt(), { key: "Enter" })
|
|
531
|
+
expect(onSubmit).not.toHaveBeenCalled()
|
|
532
|
+
})
|
|
533
|
+
|
|
534
|
+
it("sends the app's fields, and reports each pick as it happens", () => {
|
|
535
|
+
const onSubmit = vi.fn()
|
|
536
|
+
const onFieldChange = vi.fn()
|
|
537
|
+
render(<NewTaskComposer fields={[machine()]} onFieldChange={onFieldChange} onSubmit={onSubmit} />)
|
|
538
|
+
fireEvent.change(prompt(), { target: { value: "Fix it" } })
|
|
539
|
+
fireEvent.click(delegate())
|
|
540
|
+
expect(onSubmit.mock.calls[0]![0].fields).toEqual({ machine: "worker" })
|
|
541
|
+
fireEvent.change(screen.getByLabelText("Runs on"), { target: { value: "sandbox" } })
|
|
542
|
+
expect(onFieldChange).toHaveBeenCalledWith("machine", "sandbox")
|
|
543
|
+
fireEvent.click(delegate())
|
|
544
|
+
expect(onSubmit.mock.calls[1]![0].fields).toEqual({ machine: "sandbox" })
|
|
545
|
+
})
|
|
546
|
+
|
|
547
|
+
it("a required field left empty keeps Delegate off, and names it", () => {
|
|
548
|
+
render(<NewTaskComposer fields={[machine({ defaultValue: undefined, required: true })]} onSubmit={vi.fn()} />)
|
|
549
|
+
fireEvent.change(prompt(), { target: { value: "Fix it" } })
|
|
550
|
+
expect(delegate().disabled).toBe(true)
|
|
551
|
+
expect(screen.getByText("Pick “Runs on” first.")).toBeTruthy()
|
|
552
|
+
})
|
|
553
|
+
})
|