@spunto/design-system 0.71.0 → 0.73.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spunto/design-system",
3
- "version": "0.71.0",
3
+ "version": "0.73.0",
4
4
  "description": "Spunto's shared design system — green tokens (conservatory + sprout), color constants, and UI primitives.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -7,10 +7,27 @@
7
7
  // other block uses.
8
8
 
9
9
  import { useState, type ReactNode } from "react"
10
- import { CheckIcon, CopyIcon, ExternalLinkIcon } from "lucide-react"
10
+ import { CheckIcon, CopyIcon, ExternalLinkIcon, Loader2Icon } from "lucide-react"
11
11
 
12
12
  import { cn } from "../../utils"
13
- import type { TaskAppTile, TaskAppTileFact, TaskAppTileItem, TaskAppTileList, TaskAppTileMeter, TaskAppTileTone } from "./types"
13
+ import {
14
+ AlertDialog,
15
+ AlertDialogClose,
16
+ AlertDialogContent,
17
+ AlertDialogDescription,
18
+ AlertDialogFooter,
19
+ AlertDialogHeader,
20
+ AlertDialogTitle,
21
+ AlertDialogTrigger,
22
+ } from "../alert-dialog"
23
+ import { Button } from "../button"
24
+ import type { TaskAppTile, TaskAppTileAction, TaskAppTileFact, TaskAppTileItem, TaskAppTileList, TaskAppTileMeter, TaskAppTileTone } from "./types"
25
+
26
+ /**
27
+ * Runs one of a row's buttons. Rejects with what to tell the reader — the app's own refusal
28
+ * (« Required status check is expected ») — and the confirmation stays open to say it.
29
+ */
30
+ export type TaskAppTileActionHandler = (item: TaskAppTileItem, action: TaskAppTileAction) => Promise<void>
14
31
 
15
32
  const TONE_TEXT: Record<TaskAppTileTone, string> = {
16
33
  neutral: "text-muted-foreground",
@@ -168,26 +185,91 @@ function ItemBody({ item }: { item: TaskAppTileItem }) {
168
185
  )
169
186
  }
170
187
 
188
+ /**
189
+ * One button of a row, and the confirmation in front of it — always one: what it does happens
190
+ * outside Spunto (a merge on GitHub), and a button one pixel from « open the PR » is easy to hit.
191
+ * The dialog stays until the app answers, and says why when it refuses.
192
+ */
193
+ function ItemAction({ item, action, onAction }: { item: TaskAppTileItem; action: TaskAppTileAction; onAction: TaskAppTileActionHandler }) {
194
+ const [open, setOpen] = useState(false)
195
+ const [busy, setBusy] = useState(false)
196
+ const [error, setError] = useState<string | null>(null)
197
+ const danger = action.tone === "danger"
198
+
199
+ const run = async () => {
200
+ setBusy(true)
201
+ setError(null)
202
+ try {
203
+ await onAction(item, action)
204
+ setOpen(false)
205
+ } catch (err) {
206
+ setError(err instanceof Error ? err.message : String(err))
207
+ } finally {
208
+ setBusy(false)
209
+ }
210
+ }
211
+
212
+ return (
213
+ <AlertDialog
214
+ open={open}
215
+ onOpenChange={(next) => {
216
+ if (busy) return
217
+ setOpen(next)
218
+ if (!next) setError(null)
219
+ }}
220
+ >
221
+ <AlertDialogTrigger render={<Button size="xs" variant={danger ? "destructive" : "outline"} />}>{action.label}</AlertDialogTrigger>
222
+ <AlertDialogContent>
223
+ <AlertDialogHeader>
224
+ <AlertDialogTitle>{action.confirm.title}</AlertDialogTitle>
225
+ {action.confirm.body && <AlertDialogDescription>{action.confirm.body}</AlertDialogDescription>}
226
+ </AlertDialogHeader>
227
+ {error && (
228
+ <p role="alert" className="rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
229
+ {error}
230
+ </p>
231
+ )}
232
+ <AlertDialogFooter>
233
+ <AlertDialogClose render={<Button variant="outline" size="sm" disabled={busy} />}>Cancel</AlertDialogClose>
234
+ <Button size="sm" variant={danger ? "destructive" : "default"} disabled={busy} onClick={run}>
235
+ {busy && <Loader2Icon className="animate-spin" />}
236
+ {action.confirm.label ?? action.label}
237
+ </Button>
238
+ </AlertDialogFooter>
239
+ </AlertDialogContent>
240
+ </AlertDialog>
241
+ )
242
+ }
243
+
171
244
  /**
172
245
  * The rows of one app's block. A row with a `url` is a card that opens it — the same card as the
173
246
  * branch's own pull request; a row without one (an MCP server) is a compact line: name, then state.
247
+ * A row's buttons (`actions`) sit under its card, outside the link, and only with an `onAction`:
248
+ * a reader that cannot run them is not shown them.
174
249
  */
175
- export function TaskAppTileItems({ items, className }: { items: TaskAppTileItem[]; className?: string }) {
250
+ export function TaskAppTileItems({ items, onAction, className }: { items: TaskAppTileItem[]; onAction?: TaskAppTileActionHandler; className?: string }) {
176
251
  if (items.length === 0) return null
177
252
  return (
178
253
  <ul className={cn("space-y-1.5", className)}>
179
254
  {items.map((item) =>
180
255
  item.url ? (
181
- <li key={item.url}>
256
+ <li key={item.url} className="rounded-md border border-border/60 bg-background/60 transition-colors hover:border-border">
182
257
  <a
183
258
  href={item.url}
184
259
  target="_blank"
185
260
  rel="noreferrer"
186
261
  title={item.url}
187
- className="group block rounded-md border border-border/60 bg-background/60 px-2.5 py-2 transition-colors hover:border-border hover:bg-muted/40"
262
+ className="group block rounded-md px-2.5 py-2 transition-colors hover:bg-muted/40"
188
263
  >
189
264
  <ItemBody item={item} />
190
265
  </a>
266
+ {onAction && item.actions && item.actions.length > 0 && (
267
+ <div className="flex flex-wrap items-center justify-end gap-1.5 border-t border-border/60 px-2.5 py-1.5">
268
+ {item.actions.map((action) => (
269
+ <ItemAction key={action.id} item={item} action={action} onAction={onAction} />
270
+ ))}
271
+ </div>
272
+ )}
191
273
  </li>
192
274
  ) : (
193
275
  <li key={`title:${item.title}`} className="flex min-w-0 items-center justify-between gap-2">
@@ -212,11 +294,11 @@ function Section({ children, divided }: { children: ReactNode; divided: boolean
212
294
  }
213
295
 
214
296
  /** One app's block, every section it sent, in the contract's order: meters, facts, items, lists. */
215
- export function TaskAppTileContent({ tile, className }: { tile: TaskAppTile; className?: string }) {
297
+ export function TaskAppTileContent({ tile, onAction, className }: { tile: TaskAppTile; onAction?: TaskAppTileActionHandler; className?: string }) {
216
298
  const sections: ReactNode[] = []
217
299
  if (tile.meters?.length) sections.push(tile.meters.map((m) => <Meter key={m.label} meter={m} />))
218
300
  if (tile.facts?.length) sections.push(<div className="space-y-1.5">{tile.facts.map((f) => <Fact key={f.label} fact={f} />)}</div>)
219
- if (tile.items?.length) sections.push(<TaskAppTileItems items={tile.items} />)
301
+ if (tile.items?.length) sections.push(<TaskAppTileItems items={tile.items} onAction={onAction} />)
220
302
  if (tile.lists?.length) sections.push(tile.lists.map((l) => <List key={l.label} list={l} />))
221
303
  if (sections.length === 0) return null
222
304
  return (
@@ -86,13 +86,13 @@ export type { TaskDiffPanelProps } from "./diff-panel"
86
86
  export { TaskTerminalPanel } from "./terminal-panel"
87
87
  export type { TaskTerminalPanelProps } from "./terminal-panel"
88
88
  export { TaskSharedFiles, TaskSharedLinks } from "./shared"
89
- export { TaskAppTileContent, TaskAppTileItems } from "./app-tiles"
89
+ export { TaskAppTileContent, TaskAppTileItems, type TaskAppTileActionHandler } from "./app-tiles"
90
90
  export { TaskSessionUsage, formatCost, formatTokens } from "./session-usage"
91
91
  export { TaskCommandLog } from "./command-log"
92
- export { TaskBoot, TaskMachine, bootSteps, workerLabel } from "./machine"
92
+ export { TaskBoot, TaskMachine, TaskMonitoring, bootSteps, workerLabel } from "./machine"
93
93
  export { TaskCommandTerminal, emptyCommandTerminalState, planCommandTerminalWrites } from "./command-terminal"
94
94
  export type { CommandTerminalState, TaskCommandTerminalProps } from "./command-terminal"
95
- export type { TaskBootLogs, TaskBootProps, TaskBootStep, TaskMachineProps, TaskMachineTask } from "./machine"
95
+ export type { TaskBootLogs, TaskBootProps, TaskBootStep, TaskMachineProps, TaskMachineTask, TaskMonitoringProps } from "./machine"
96
96
 
97
97
  export type {
98
98
  AttachmentUrl,
@@ -100,6 +100,7 @@ export type {
100
100
  TaskAppTile,
101
101
  TaskAppTileFact,
102
102
  TaskAppTileItem,
103
+ TaskAppTileAction,
103
104
  TaskAppTileList,
104
105
  TaskAppTileMeter,
105
106
  TaskAppTileTone,
@@ -2,13 +2,13 @@
2
2
 
3
3
  import { useState, type ReactNode } from "react"
4
4
  import {
5
+ ActivityIcon,
5
6
  ChevronRightIcon,
6
7
  Code2Icon,
7
8
  ExternalLinkIcon,
8
9
  GitBranchIcon,
9
10
  MoonIcon,
10
11
  ServerIcon,
11
- SparklesIcon,
12
12
  TerminalIcon,
13
13
  WifiOffIcon,
14
14
  } from "lucide-react"
@@ -43,8 +43,12 @@ import type { TaskCommand, TaskItem, TaskMachineNode, TaskMachinePort } from "./
43
43
  * agent thinking and an agent stuck in a test suite.
44
44
  *
45
45
  * Everything here is observed, never guessed: the worker row, its container-side setup status,
46
- * its live stats, and the task's own command history. Where the platform doesn't know (has the
47
- * pool recycled this machine since the task ended?) the component says so rather than implying.
46
+ * its live stats, and the task's own command history.
47
+ *
48
+ * Since every task gets a sandbox of its own (no pool to recycle from), this block only says which
49
+ * machine it is and what it serves: its name opens its own page (logs, terminal, files, the
50
+ * editor), and where it runs and how it is doing — CPU, memory, their history — is
51
+ * `TaskMonitoring`, the sidebar's last block.
48
52
  */
49
53
 
50
54
  /** The task fields the machine block and the boot panel read. */
@@ -56,44 +60,39 @@ export function workerLabel(worker: WorkerCardWorker): string {
56
60
  return worker.name?.trim() || (worker.index != null ? `Workspace #${worker.index}` : "Workspace")
57
61
  }
58
62
 
59
- /**
60
- * Did this task get a machine that already existed?
61
- *
62
- * The pool is the whole point — the first task of a project pays for an image build and a clone,
63
- * the tenth should not — and "recycled" vs "fresh" is exactly the difference between a boot of
64
- * seconds and one of minutes. Read from the timestamps rather than recorded: a worker older than
65
- * the task that took it was not created for it.
66
- */
67
- function recycled(task: TaskMachineTask, worker: WorkerCardWorker): boolean {
68
- if (!worker.createdAt) return false
69
- return new Date(worker.createdAt).getTime() < new Date(task.createdAt).getTime()
70
- }
71
-
72
63
  // ── The sidebar block ────────────────────────────────────────────────────────────────────────
73
64
 
74
65
  export interface TaskMachineProps {
75
66
  task: TaskMachineTask
76
67
  /** The worker row, as the app reads it. `null` → the task has no machine (yet). */
77
68
  worker: WorkerCardWorker | null | undefined
78
- /** The node it lives on. `online: false` draws "offline". */
79
- node?: TaskMachineNode | null
80
- /** Live container stats — pass them only while the task is live and the container up. */
81
- stats?: WorkerStats | null
82
69
  /**
83
70
  * Its ports (editor and SSH are filtered out): detected listening, and those the project declares
84
71
  * — green while something listens, greyed (no link) while nothing does. Declared ones show even
85
72
  * with the machine parked: the reader sees what the app will serve, and that it doesn't now.
86
73
  */
87
74
  ports?: TaskMachinePort[]
88
- /** The worker's own page (logs, terminal, files). */
75
+ /** The machine's own page (logs, terminal, files, the editor) — its name links there. */
89
76
  workerHref?: string
90
- /** The editor (code-server). Shown only while the container runs. */
91
- editorHref?: string
92
77
  portHref?: (port: number) => string | undefined
93
78
  render?: { link?: LinkRender }
79
+ /**
80
+ * @deprecated Since 0.72.0 — pass it to `TaskMonitoring` (the sidebar's Monitoring block). Still
81
+ * drawn here, as before, when given.
82
+ */
83
+ node?: TaskMachineNode | null
84
+ /**
85
+ * @deprecated Since 0.72.0 — pass it to `TaskMonitoring`. Still drawn here, as before, when given.
86
+ */
87
+ stats?: WorkerStats | null
88
+ /**
89
+ * @deprecated Since 0.72.0 — the machine's page (`workerHref`) opens the editor. Still drawn
90
+ * here ("Open the editor", while the machine runs) when given.
91
+ */
92
+ editorHref?: string
94
93
  }
95
94
 
96
- export function TaskMachine({ task, worker, node = null, stats = null, ports = [], workerHref, editorHref, portHref, render }: TaskMachineProps) {
95
+ export function TaskMachine({ task, worker, ports = [], workerHref, portHref, render, node, stats, editorHref }: TaskMachineProps) {
97
96
  const [showBreakdown, setShowBreakdown] = useState(false)
98
97
  const Link: LinkRender =
99
98
  render?.link ?? (({ href, className, children }) => <a href={href} className={className}>{children}</a>)
@@ -102,7 +101,7 @@ export function TaskMachine({ task, worker, node = null, stats = null, ports = [
102
101
  return (
103
102
  <p className="text-[11px] leading-relaxed text-muted-foreground">
104
103
  {task.state === "queued"
105
- ? "Looking for a machine — a free worker from the project's pool, or a fresh one."
104
+ ? "Starting a sandbox for this task."
106
105
  : "This task never got a machine."}
107
106
  </p>
108
107
  )
@@ -112,8 +111,8 @@ export function TaskMachine({ task, worker, node = null, stats = null, ports = [
112
111
  const setup = worker.setupStatus ?? null
113
112
  const running = worker.dockerState === "running"
114
113
  const startup = setupTotalMs(setup)
115
- // A terminal task no longer holds its worker: the next task may already be using it. Saying
116
- // "Running" without saying whose is how a cockpit lies quietly.
114
+ // A terminal task no longer holds its machine: accepted, its sandbox is destroyed; failed, it is
115
+ // stopped. What is drawn is the box's last known state, not a task still at work.
117
116
  const released = task.state === "done" || task.state === "failed"
118
117
  const parked = task.state === "in-review" && !running
119
118
  const label = workerLabel(worker)
@@ -132,32 +131,14 @@ export function TaskMachine({ task, worker, node = null, stats = null, ports = [
132
131
  <WorkerStatusPill status={status} label={status.settingUp ? phaseLabel(setup) : undefined} />
133
132
  </div>
134
133
 
135
- <div className="flex flex-wrap items-center gap-x-2 gap-y-1 text-[11px] text-muted-foreground">
136
- <span className="flex items-center gap-1">
137
- <ServerIcon className="h-3 w-3 shrink-0" />
138
- {node ? node.name : "node unknown"}
139
- </span>
140
- {node && !node.online && (
141
- <span className="flex items-center gap-1 text-orange-600 dark:text-orange-400">
142
- <WifiOffIcon className="h-3 w-3 shrink-0" />
143
- offline
144
- </span>
145
- )}
146
- <span aria-hidden>·</span>
147
- <span className="flex items-center gap-1">
148
- <SparklesIcon className="h-3 w-3 shrink-0" />
149
- {recycled(task, worker) ? "recycled from the pool" : "spawned for this task"}
150
- </span>
151
- </div>
134
+ {/* Deprecated props, kept so an app that still passes them sees no change (0.72.0). */}
135
+ {node && <MachinePlace node={node} />}
152
136
 
153
137
  {/* Not while the task is `queued`: the boot panel in the centre column is showing this very
154
138
  timeline, in full, and two copies of a cloning repository on one screen is one too many.
155
139
  It stays here for the rest — a parked machine restarting for a follow-up, say. */}
156
140
  {status.settingUp && task.state !== "queued" && <WorkerSetupTimeline status={setup} settingUp />}
157
141
 
158
- {/* `@container`, deliberately: ResourceBars decides to go two-up from its *nearest container
159
- ancestor*'s width, and outside a WorkerCard there is none — the bars would stay stacked
160
- for ever (docs/design-system.md § "une brique réutilisée hors de sa carte"). */}
161
142
  {stats && (
162
143
  <div className="@container">
163
144
  <ResourceBars stats={stats} />
@@ -168,38 +149,30 @@ export function TaskMachine({ task, worker, node = null, stats = null, ports = [
168
149
  <p className="flex items-start gap-1.5 rounded-md border border-border/60 bg-muted/30 px-2.5 py-2 text-[11px] leading-relaxed text-muted-foreground">
169
150
  <MoonIcon className="mt-0.5 h-3 w-3 shrink-0" />
170
151
  <span>
171
- Parked for review — stopped, disk kept as it was. Accepting or dropping the task
172
- releases it to the pool.
152
+ Parked for review — stopped, disk kept as it was, until the task is accepted or
153
+ dropped.
173
154
  </span>
174
155
  </p>
175
156
  )}
176
157
 
177
158
  {released && (
178
159
  <p className="text-[11px] leading-relaxed text-muted-foreground">
179
- This task is over, so the machine is back in the pool — what it runs now may belong to
180
- another task.
160
+ This task is over — its machine is no longer kept for it.
181
161
  </p>
182
162
  )}
183
163
 
184
- <div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]">
185
- {editorHref && running && (
186
- <a
187
- href={editorHref}
188
- target="_blank"
189
- rel="noreferrer"
190
- className="flex items-center gap-1 text-primary hover:underline"
191
- >
192
- <Code2Icon className="h-3 w-3 shrink-0" />
193
- Open the editor
194
- <ExternalLinkIcon className="h-3 w-3 shrink-0" />
195
- </a>
196
- )}
197
- {workerHref && (
198
- <Link href={workerHref} className="flex items-center gap-1 text-muted-foreground transition-colors hover:text-foreground">
199
- Logs, terminal, files →
200
- </Link>
201
- )}
202
- </div>
164
+ {editorHref && running && (
165
+ <a
166
+ href={editorHref}
167
+ target="_blank"
168
+ rel="noreferrer"
169
+ className="flex items-center gap-1 text-[11px] text-primary hover:underline"
170
+ >
171
+ <Code2Icon className="h-3 w-3 shrink-0" />
172
+ Open the editor
173
+ <ExternalLinkIcon className="h-3 w-3 shrink-0" />
174
+ </a>
175
+ )}
203
176
 
204
177
  {portHref && <MachinePorts ports={ports} running={running} portHref={portHref} />}
205
178
 
@@ -220,6 +193,68 @@ export function TaskMachine({ task, worker, node = null, stats = null, ports = [
220
193
  )
221
194
  }
222
195
 
196
+ /** Where the machine runs, and whether its agent is reachable. */
197
+ function MachinePlace({ node }: { node: TaskMachineNode }) {
198
+ return (
199
+ <div className="flex flex-wrap items-center gap-x-2 gap-y-1 text-[11px] text-muted-foreground">
200
+ <span className="flex items-center gap-1">
201
+ <ServerIcon className="h-3 w-3 shrink-0" />
202
+ {node.name}
203
+ </span>
204
+ {!node.online && (
205
+ <span className="flex items-center gap-1 text-orange-600 dark:text-orange-400">
206
+ <WifiOffIcon className="h-3 w-3 shrink-0" />
207
+ offline
208
+ </span>
209
+ )}
210
+ </div>
211
+ )
212
+ }
213
+
214
+ // ── The monitoring block ─────────────────────────────────────────────────────────────────────
215
+
216
+ export interface TaskMonitoringProps {
217
+ /** Where the machine runs ("Spunto Cloud", a node…). `online: false` draws "offline". */
218
+ node?: TaskMachineNode | null
219
+ /** Live container stats — pass them only while the task is live and the machine up. */
220
+ stats?: WorkerStats | null
221
+ /**
222
+ * Its history, drawn by the app (the package reads no metrics endpoint) — in the dashboard, the
223
+ * same charts as the sandbox's own page (`SandboxMetricsHistory`).
224
+ */
225
+ history?: ReactNode
226
+ }
227
+
228
+ /**
229
+ * How the task's machine is doing: the live CPU and memory bars, then their history.
230
+ *
231
+ * Its own block, last in the sidebar, rather than inside Machine: Machine is what a reader acts on
232
+ * (open its page, a port), this is what they glance at when the agent seems slow — charts in the
233
+ * middle of the links pushed the ports below the fold.
234
+ */
235
+ export function TaskMonitoring({ node = null, stats = null, history }: TaskMonitoringProps) {
236
+ return (
237
+ <div className="space-y-3">
238
+ {node && <MachinePlace node={node} />}
239
+ {!stats && !history && (
240
+ <p className="flex items-center gap-1.5 text-[11px] text-muted-foreground">
241
+ <ActivityIcon className="h-3 w-3 shrink-0" />
242
+ Nothing to measure — the machine is not running.
243
+ </p>
244
+ )}
245
+ {/* `@container`, deliberately: ResourceBars decides to go two-up from its *nearest container
246
+ ancestor*'s width, and outside a WorkerCard there is none — the bars would stay stacked
247
+ for ever (docs/design-system.md § "une brique réutilisée hors de sa carte"). */}
248
+ {stats && (
249
+ <div className="@container">
250
+ <ResourceBars stats={stats} />
251
+ </div>
252
+ )}
253
+ {history}
254
+ </div>
255
+ )
256
+ }
257
+
223
258
  // ── The boot panel, centre column ────────────────────────────────────────────────────────────
224
259
 
225
260
  export type TaskBootStep = {
@@ -265,9 +300,7 @@ export function bootSteps({
265
300
  key: "machine",
266
301
  label: "Machine",
267
302
  state: "done",
268
- detail: recycled(task, worker)
269
- ? `recycled from the pool · ${workerLabel(worker)}`
270
- : `spawned for this task · ${workerLabel(worker)}`,
303
+ detail: workerLabel(worker),
271
304
  }
272
305
  : {
273
306
  key: "machine",
@@ -275,7 +308,7 @@ export function bootSteps({
275
308
  // A queued task with no worker is being allocated one; a task that stopped here never got
276
309
  // one at all, and pretending it is still looking would be a lie with a spinner on it.
277
310
  state: task.state === "queued" ? "running" : "error",
278
- detail: task.state === "queued" ? "looking for a free worker, or spawning one…" : "never allocated",
311
+ detail: task.state === "queued" ? "starting a sandbox for this task…" : "never allocated",
279
312
  }
280
313
 
281
314
  // `ready` and nothing else: it is the platform's own definition of a usable machine (what
@@ -562,7 +595,7 @@ export function TaskBoot({ task, worker, commands, logs }: TaskBootProps) {
562
595
  <GitBranchIcon className="mt-0.5 h-3 w-3 shrink-0" />
563
596
  <span>
564
597
  {queued
565
- ? "The session appears here on its own as soon as the agent starts. Tasks of the same project share this pool of machines — the first one pays for the image build, the next ones reuse it."
598
+ ? "The session appears here on its own as soon as the agent starts."
566
599
  : "Nothing was streamed for this task. The sidebar has every command the platform ran."}
567
600
  </span>
568
601
  </p>
@@ -10,8 +10,9 @@
10
10
  //
11
11
  // Before, those were two hand-kept copies of the same list (a sidebar and a mobile sheet) that
12
12
  // had to agree on order and wording. The order is an argument, so it lives once: the machine first
13
- // — the one block always open, since it is what a reader acts on (open the editor, a port, its
14
- // logs) —, then what the session is spending, then did it land (the PR), then how it was set up.
13
+ // — the one block always open, since it is what a reader acts on (its page, a port) —, then what
14
+ // the session is spending, then did it land (the PR), then how it was set up, and last how the
15
+ // machine is doing (Monitoring: CPU and memory, live and over time).
15
16
  //
16
17
  // Every other block starts folded, and stays the way the reader leaves it: opening "Session" once
17
18
  // opens it in every conversation (`useBlockOpen`, this browser's `localStorage`).
@@ -20,12 +21,13 @@ import { createContext, useContext, useState, useSyncExternalStore, type ReactNo
20
21
  import { CheckIcon, ChevronRightIcon, CopyIcon, ExternalLinkIcon, GitBranchIcon, Loader2Icon, SlidersHorizontalIcon, XCircleIcon } from "lucide-react"
21
22
 
22
23
  import { cn, formatRelativeTime } from "../../utils"
24
+ import { Avatar, AvatarFallback, AvatarImage } from "../avatar"
23
25
  import { TaskCommandLog } from "./command-log"
24
26
  import { TaskSessionUsage } from "./session-usage"
25
27
  import { TaskSharedFiles, TaskSharedLinks } from "./shared"
26
28
  import { TaskAppTileContent } from "./app-tiles"
27
29
  import { isLiveTaskState, taskSpan } from "./task-state"
28
- import type { AttachmentUrl, TaskAppTile, TaskCommand, TaskItem, TaskPendingAction, TaskSessionUsageData, TaskSharedData } from "./types"
30
+ import type { AttachmentUrl, TaskAppTile, TaskAppTileAction, TaskAppTileItem, TaskCommand, TaskItem, TaskPendingAction, TaskSessionUsageData, TaskSharedData } from "./types"
29
31
 
30
32
  /** Set by `TaskCockpitMobile` around its sheet, so Drop can close it. @internal */
31
33
  export const TaskDetailsSheetContext = createContext<{ close: () => void } | null>(null)
@@ -51,9 +53,21 @@ export interface TaskDetailsProps {
51
53
  * integrations. Absent (or null for a tile) = no link.
52
54
  */
53
55
  appTileSettingsHref?: (tile: TaskAppTile) => string | null
56
+ /**
57
+ * Runs a button a block offers on one of its rows (GitHub: Merge, Close), after its confirmation.
58
+ * Rejects with the message to show. Absent → the buttons are not drawn.
59
+ */
60
+ onAppTileAction?: (tile: TaskAppTile, item: TaskAppTileItem, action: TaskAppTileAction) => Promise<void>
54
61
  attachmentUrl?: AttachmentUrl
62
+ /**
63
+ * The member who delegated the task — drawn in the header, avatar and name. Absent → just
64
+ * "Delegated …" (a task whose owner left the org, or an app that doesn't know).
65
+ */
66
+ delegatedBy?: { name: string; avatarUrl?: string | null } | null
55
67
  /** The Machine block's content — typically a `TaskMachine`. */
56
68
  machine?: ReactNode
69
+ /** The Monitoring block's content, last in the list — typically a `TaskMonitoring`. Absent → no block. */
70
+ monitoring?: ReactNode
57
71
  /** Every command the platform ran for the task, oldest first. */
58
72
  commands?: TaskCommand[]
59
73
  /** The project's `taskAgentProtocol` — only for a footnote. */
@@ -221,8 +235,11 @@ export function TaskDetails({
221
235
  shared,
222
236
  appTiles,
223
237
  appTileSettingsHref,
238
+ onAppTileAction,
224
239
  attachmentUrl,
240
+ delegatedBy,
225
241
  machine,
242
+ monitoring,
226
243
  commands = [],
227
244
  protocol = "none",
228
245
  onDrop,
@@ -234,15 +251,35 @@ export function TaskDetails({
234
251
  const links = task.links && task.links.length > 0 ? task.links : null
235
252
  const metadata = task.metadata && Object.keys(task.metadata).length > 0 ? Object.entries(task.metadata) : null
236
253
  const ran = task.completedAt ? taskSpan(task.startedAt ?? task.createdAt, task.completedAt) : null
254
+ // `baseBranch: null` is the project's default — saying so ("project default") on every task of a
255
+ // project with no branches was a fact with nothing in it. Only an explicit base is worth a line.
256
+ const facts = !!links || !!task.branch || !!task.baseBranch || !!task.outcomeUrl
237
257
 
238
258
  return (
239
259
  <div className={className}>
240
260
  <div className={cn("border-b", variant === "sidebar" ? "border-border/60 px-4 py-3" : "space-y-3 px-4 py-3")}>
241
- <p className="text-xs text-muted-foreground">
242
- Delegated {formatRelativeTime(task.createdAt)}
243
- {/* From `startedAt`, not `createdAt`: the wait for a worker is not run time. */}
244
- {ran && ` · ran ${ran}`}
245
- </p>
261
+ <div className="flex items-center gap-2 text-xs text-muted-foreground">
262
+ {delegatedBy && (
263
+ <Avatar size="xs" className="shrink-0">
264
+ {delegatedBy.avatarUrl && <AvatarImage src={delegatedBy.avatarUrl} alt="" />}
265
+ <AvatarFallback className="bg-primary/15 font-semibold text-primary">
266
+ {delegatedBy.name.slice(0, 2).toUpperCase()}
267
+ </AvatarFallback>
268
+ </Avatar>
269
+ )}
270
+ <p className="min-w-0">
271
+ {delegatedBy ? (
272
+ <>
273
+ <span className="font-medium text-foreground">{delegatedBy.name}</span> delegated{" "}
274
+ {formatRelativeTime(task.createdAt)}
275
+ </>
276
+ ) : (
277
+ <>Delegated {formatRelativeTime(task.createdAt)}</>
278
+ )}
279
+ {/* From `startedAt`, not `createdAt`: the wait for a machine is not run time. */}
280
+ {ran && ` · ran ${ran}`}
281
+ </p>
282
+ </div>
246
283
 
247
284
  {task.error && (
248
285
  <p
@@ -255,6 +292,7 @@ export function TaskDetails({
255
292
  </p>
256
293
  )}
257
294
 
295
+ {facts && (
258
296
  <div className={cn("grid grid-cols-2 gap-3", variant === "sidebar" && "mt-3")}>
259
297
  {/* First: where the work came from is what a reader arriving from a list asks before anything else. */}
260
298
  {links && (
@@ -290,9 +328,11 @@ export function TaskDetails({
290
328
  </Fact>
291
329
  </div>
292
330
  )}
293
- <Fact label="Base">
294
- <span className="font-mono text-muted-foreground">{task.baseBranch ?? "project default"}</span>
295
- </Fact>
331
+ {task.baseBranch && (
332
+ <Fact label="Base">
333
+ <span className="font-mono text-muted-foreground">{task.baseBranch}</span>
334
+ </Fact>
335
+ )}
296
336
  {task.outcomeUrl && (
297
337
  <Fact label="Result">
298
338
  <a href={task.outcomeUrl} target="_blank" rel="noreferrer" className="flex items-center gap-1 text-primary hover:underline">
@@ -302,9 +342,10 @@ export function TaskDetails({
302
342
  </Fact>
303
343
  )}
304
344
  </div>
345
+ )}
305
346
  </div>
306
347
 
307
- {/* First and always open: the machine is what a reader acts on — the editor, a port, its logs. */}
348
+ {/* First and always open: the machine is what a reader acts on — its page, a port. */}
308
349
  {machine && (
309
350
  <Block id="machine" variant={variant} title="Machine" pinned>
310
351
  {machine}
@@ -321,7 +362,7 @@ export function TaskDetails({
321
362
  from the task's agent app — Session's numbers stay ours, the same for every harness. */}
322
363
  {appTiles?.filter((tile) => tile.session).map((tile) => (
323
364
  <Block key={tile.appId} id={`app:${tile.appId}`} variant={variant} title={tile.title} hint={tile.appName === tile.title ? undefined : tile.appName}>
324
- <TaskAppTileContent tile={tile} />
365
+ <TaskAppTileContent tile={tile} onAction={onAppTileAction && ((item, action) => onAppTileAction(tile, item, action))} />
325
366
  <CustomizeLink tile={tile} href={appTileSettingsHref} />
326
367
  </Block>
327
368
  ))}
@@ -330,7 +371,7 @@ export function TaskDetails({
330
371
  it talked about, with where each one stands. */}
331
372
  {appTiles?.filter((tile) => !tile.session).map((tile) => (
332
373
  <Block key={tile.appId} id={`app:${tile.appId}`} variant={variant} title={tile.title} hint={tile.appName === tile.title ? undefined : tile.appName}>
333
- <TaskAppTileContent tile={tile} />
374
+ <TaskAppTileContent tile={tile} onAction={onAppTileAction && ((item, action) => onAppTileAction(tile, item, action))} />
334
375
  <CustomizeLink tile={tile} href={appTileSettingsHref} />
335
376
  </Block>
336
377
  ))}
@@ -395,6 +436,13 @@ export function TaskDetails({
395
436
  </Block>
396
437
  )}
397
438
 
439
+ {/* Last: CPU and memory, live and over time — glanced at when the agent seems slow, not acted on. */}
440
+ {monitoring && (
441
+ <Block id="monitoring" variant={variant} title="Monitoring">
442
+ {monitoring}
443
+ </Block>
444
+ )}
445
+
398
446
  {variant === "sheet" && onDrop && isLiveTaskState(task.state) && (
399
447
  <div className="px-4 py-4">
400
448
  <button
@@ -114,7 +114,7 @@ describe("boot steps", () => {
114
114
  it("an older task, branched by the platform: starts the session step once the branch is ready", () => {
115
115
  const worker = { id: "w1", name: "pool-1", state: "ready", dockerState: "running", createdAt: "2026-09-20T00:00:00Z" }
116
116
  const steps = bootSteps({ task: task({ state: "queued" }), worker, commands: [branchSetup("succeeded")] })
117
- expect(steps.find((s) => s.key === "machine")?.detail).toBe("recycled from the pool · pool-1")
117
+ expect(steps.find((s) => s.key === "machine")?.detail).toBe("pool-1")
118
118
  expect(steps.find((s) => s.key === "branch")?.state).toBe("done")
119
119
  expect(steps.find((s) => s.key === "session")?.state).toBe("running")
120
120
  })
@@ -495,7 +495,45 @@ describe("TaskCockpit panels", () => {
495
495
  })
496
496
  })
497
497
 
498
+ describe("TaskMachine deprecated props (0.72.0)", () => {
499
+ const worker = { id: "sbx1", name: "task-1", state: "ready", dockerState: "running" } as never
500
+ it("still draws node, stats and the editor link when an app passes them", () => {
501
+ render(
502
+ <TaskMachine
503
+ task={{ state: "running", createdAt: "2026-09-24T10:00:00Z" }}
504
+ worker={worker}
505
+ node={{ name: "hetzner-fsn1-2", online: true }}
506
+ stats={{ cpuPercent: 12, memUsageMb: 512 }}
507
+ editorHref="https://editor"
508
+ />,
509
+ )
510
+ expect(screen.getByText("hetzner-fsn1-2")).toBeTruthy()
511
+ expect(screen.getByText("CPU")).toBeTruthy()
512
+ expect(screen.getByText("Open the editor").closest("a")?.getAttribute("href")).toBe("https://editor")
513
+ })
514
+
515
+ it("draws none of them when they are not passed", () => {
516
+ render(<TaskMachine task={{ state: "running", createdAt: "2026-09-24T10:00:00Z" }} worker={worker} />)
517
+ expect(screen.queryByText("CPU")).toBeNull()
518
+ expect(screen.queryByText("Open the editor")).toBeNull()
519
+ })
520
+ })
521
+
498
522
  describe("TaskDetails", () => {
523
+ it("shows the base only when the task has an explicit one", () => {
524
+ const { rerender } = render(<TaskDetails task={task({ branch: undefined as never, baseBranch: null })} commands={[]} />)
525
+ expect(screen.queryByText("Base")).toBeNull()
526
+ expect(screen.queryByText("project default")).toBeNull()
527
+ rerender(<TaskDetails task={task({ baseBranch: "release/2.0" })} commands={[]} />)
528
+ expect(screen.getByText("release/2.0")).toBeTruthy()
529
+ })
530
+
531
+ it("names the member who delegated the task", () => {
532
+ render(<TaskDetails task={task()} delegatedBy={{ name: "Ada" }} commands={[]} />)
533
+ expect(screen.getByText("Ada")).toBeTruthy()
534
+ expect(screen.getByText(/delegated/)).toBeTruthy()
535
+ })
536
+
499
537
  it("puts the machine first and always open; every other block starts folded", () => {
500
538
  window.localStorage.clear()
501
539
  const { container } = render(
@@ -255,6 +255,17 @@ export interface TaskAppTileItem {
255
255
  subtitle?: string
256
256
  status?: { label: string; tone: TaskAppTileTone }
257
257
  badges?: { label: string; tone: TaskAppTileTone }[]
258
+ /** Buttons the app offers on this row — « Merge », « Close ». Drawn only with an `onAction`. */
259
+ actions?: TaskAppTileAction[]
260
+ }
261
+
262
+ /** A button on an app's row, always behind a confirmation drawn from `confirm`. */
263
+ export interface TaskAppTileAction {
264
+ id: string
265
+ label: string
266
+ /** `danger`: a destructive button, here and in the confirmation. */
267
+ tone?: TaskAppTileTone
268
+ confirm: { title: string; body?: string; label?: string }
258
269
  }
259
270
 
260
271
  /** « Claude Code → 2.1.310 ». `copy`: the value is something to paste (an id). */