@spunto/design-system 0.48.0 → 0.49.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.48.0",
3
+ "version": "0.49.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",
@@ -112,13 +112,17 @@ export function TaskComposer({
112
112
  ? "No session id was captured for this task, so there is nothing to resume."
113
113
  : null
114
114
 
115
- const disabled = reason !== null || pending
115
+ // A reply on its way does not close the box: it is already held by Spunto (queued, then
116
+ // delivered once the session is back), so the box stays as it was and only Send waits — the
117
+ // next message can be written meanwhile. Greying it all out read as having lost the connection.
118
+ const disabled = reason !== null
119
+ const sendDisabled = disabled || pending
116
120
 
117
121
  function submit() {
118
122
  const text = prompt.trim()
119
123
  // Words are still required with an attachment: "look at this" is a turn, a bare file is a
120
124
  // riddle — and the harness is handed a path, so something has to say what to do with it.
121
- if (!text || disabled) return
125
+ if (!text || sendDisabled) return
122
126
  onSubmit(text, draft.files)
123
127
  setPrompt("")
124
128
  // `release`, not `clear`: the cockpit is now drawing these very thumbnails under the pending
@@ -195,7 +199,7 @@ export function TaskComposer({
195
199
  <button
196
200
  type="button"
197
201
  onClick={submit}
198
- disabled={disabled || !prompt.trim()}
202
+ disabled={sendDisabled || !prompt.trim()}
199
203
  aria-label="Send"
200
204
  className="flex h-10 w-10 shrink-0 touch-manipulation items-center justify-center rounded-full bg-primary text-primary-foreground transition-transform active:scale-95 disabled:opacity-40"
201
205
  >
@@ -229,7 +233,9 @@ export function TaskComposer({
229
233
  <div className="flex items-center gap-2 border-t border-border/60 px-2 py-1.5">
230
234
  <span className="mr-auto truncate text-[10px] text-muted-foreground">
231
235
  {reason ??
232
- (interactive
236
+ (pending
237
+ ? "Your message is queued — Spunto delivers it as soon as the session is ready. Send the next one then."
238
+ : interactive
233
239
  ? // Both paths are real and the composer cannot know which one it will take:
234
240
  // the session is usually still listening, and is resumed if it has exited.
235
241
  "Goes to the live session — or resumes it if it has exited."
@@ -246,7 +252,7 @@ export function TaskComposer({
246
252
  Stop
247
253
  </Button>
248
254
  )}
249
- <Button size="sm" className="h-7 gap-1.5 px-2.5 text-xs" disabled={disabled || !prompt.trim()} onClick={submit}>
255
+ <Button size="sm" className="h-7 gap-1.5 px-2.5 text-xs" disabled={sendDisabled || !prompt.trim()} onClick={submit}>
250
256
  {pending ? <Loader2Icon className="h-3 w-3 animate-spin" /> : <CornerDownLeftIcon className="h-3 w-3" />}
251
257
  Send
252
258
  </Button>
@@ -7,6 +7,7 @@ import {
7
7
  BrainIcon,
8
8
  CheckIcon,
9
9
  ChevronRightIcon,
10
+ CircleAlertIcon,
10
11
  CircleDotIcon,
11
12
  CircleIcon,
12
13
  FlagIcon,
@@ -63,9 +64,27 @@ import type { AttachmentUrl, PendingMessage, TaskEvent } from "./types"
63
64
  const str = (v: unknown): string => (typeof v === "string" ? v : "")
64
65
  const bool = (v: unknown): boolean => v === true
65
66
 
67
+ /**
68
+ * Where a queued reply stands on its way to the session — read off the events that follow it.
69
+ *
70
+ * A reply to a task whose session is not listening (its machine parked, its process gone) is
71
+ * stored by Spunto at once (`message` with `queued: true`) and delivered by a job that may first
72
+ * have to wake the machine: a minute, for a sandbox. The platform writes the steps into the stream
73
+ * (`machine.wake` starting/awake, `reply.failed`), and the harness's own `session.started` is the
74
+ * delivery. Derived here, never stored: the stream is append-only and already says it all.
75
+ */
76
+ export interface ReplyDelivery {
77
+ status: "queued" | "waking" | "resuming" | "delivered" | "failed"
78
+ /** `sandbox` | `worker`, once a wake has said so. */
79
+ machineKind?: string
80
+ wakeStartedAt?: string
81
+ wakeMs?: number
82
+ error?: string
83
+ }
84
+
66
85
  type Item =
67
86
  /** `hideSummary` — see `useTimeline`: the end-of-session result is often the last message again. */
68
- | { kind: "event"; event: TaskEvent; hideSummary?: boolean }
87
+ | { kind: "event"; event: TaskEvent; hideSummary?: boolean; delivery?: ReplyDelivery }
69
88
  | { kind: "tool"; entry: ToolCall }
70
89
  /** A chain of machinery, folded — see `tool-stack.tsx`. */
71
90
  | { kind: "run"; run: ToolRun }
@@ -286,7 +305,95 @@ function EventTime({ ts }: { ts: TaskEvent["ts"] }) {
286
305
  )
287
306
  }
288
307
 
289
- function MessageEntry({ event, attachmentUrl }: { event: TaskEvent; attachmentUrl: AttachmentUrl }) {
308
+ /** "sandbox"/"worker" → what to call it in a sentence. */
309
+ function machineNoun(kind: string | undefined): string {
310
+ return kind === "worker" ? "worker" : kind === "sandbox" ? "sandbox" : "machine"
311
+ }
312
+
313
+ function seconds(ms: number | undefined): string | null {
314
+ if (typeof ms !== "number" || !Number.isFinite(ms) || ms < 0) return null
315
+ return ms < 1000 ? "under a second" : `${Math.round(ms / 1000)} s`
316
+ }
317
+
318
+ function StepLine({ state, children }: { state: "done" | "active" | "failed"; children: ReactNode }) {
319
+ return (
320
+ <li className="flex items-start gap-2 text-[11px] leading-5">
321
+ <span className="mt-1 shrink-0">
322
+ {state === "done" ? (
323
+ <CheckIcon className="h-3 w-3 text-green-600 dark:text-green-500" />
324
+ ) : state === "failed" ? (
325
+ <CircleAlertIcon className="h-3 w-3 text-destructive" />
326
+ ) : (
327
+ <Loader2Icon className="h-3 w-3 animate-spin text-primary" />
328
+ )}
329
+ </span>
330
+ <span className={cn(state === "active" ? "text-foreground" : state === "failed" ? "text-destructive" : "text-muted-foreground")}>
331
+ {children}
332
+ </span>
333
+ </li>
334
+ )
335
+ }
336
+
337
+ /**
338
+ * Under a queued reply: sent, held by Spunto, and where it is on its way — the machine waking,
339
+ * then the session resuming — the same steps, in the same place, a first start shows. Once
340
+ * delivered it folds to one muted line; the reader no longer needs the steps, only that it arrived.
341
+ */
342
+ function DeliveryTracker({ delivery, live, ts }: { delivery: ReplyDelivery; live: boolean; ts: string }) {
343
+ const noun = machineNoun(delivery.machineKind)
344
+ const waking = useElapsed(delivery.status === "waking" ? delivery.wakeStartedAt : null)
345
+ const waited = useElapsed(delivery.status === "queued" || delivery.status === "resuming" ? ts : null)
346
+ const woke = seconds(delivery.wakeMs)
347
+
348
+ if (delivery.status === "delivered") {
349
+ return (
350
+ <p className="mt-1 flex items-center gap-1 text-[10px] text-muted-foreground" data-slot="reply-delivery" data-status="delivered">
351
+ <CheckIcon className="h-3 w-3 text-green-600 dark:text-green-500" />
352
+ Delivered{woke ? ` · the ${noun} woke in ${woke}` : ""}
353
+ </p>
354
+ )
355
+ }
356
+ // A task that moved on (dropped, accepted) without the reply ever starting a turn.
357
+ const failed = delivery.status === "failed" || !live
358
+ return (
359
+ <ul
360
+ className="mt-1.5 space-y-0.5 rounded-md border border-border/70 bg-card/60 px-2.5 py-1.5"
361
+ data-slot="reply-delivery"
362
+ data-status={failed ? "failed" : delivery.status}
363
+ >
364
+ <StepLine state="done">Sent — queued on Spunto</StepLine>
365
+ {delivery.wakeStartedAt && (
366
+ <StepLine state={delivery.status === "waking" && !failed ? "active" : delivery.status === "waking" ? "failed" : "done"}>
367
+ {delivery.status === "waking"
368
+ ? `Waking the ${noun}…${waking ? ` ${waking}` : ""}`
369
+ : `The ${noun} is awake${woke ? ` · ${woke}` : ""}`}
370
+ </StepLine>
371
+ )}
372
+ {failed ? (
373
+ <StepLine state="failed">Not delivered{delivery.error ? ` — ${delivery.error}` : ""}</StepLine>
374
+ ) : (
375
+ delivery.status !== "waking" && (
376
+ <StepLine state="active">
377
+ {delivery.status === "resuming" ? "Resuming the session…" : "Waiting for the session — delivered as soon as it is ready"}
378
+ {waited ? ` ${waited}` : ""}
379
+ </StepLine>
380
+ )
381
+ )}
382
+ </ul>
383
+ )
384
+ }
385
+
386
+ function MessageEntry({
387
+ event,
388
+ attachmentUrl,
389
+ delivery,
390
+ live = true,
391
+ }: {
392
+ event: TaskEvent
393
+ attachmentUrl: AttachmentUrl
394
+ delivery?: ReplyDelivery
395
+ live?: boolean
396
+ }) {
290
397
  // What *you* said, set apart from what the agent said. Without this the timeline reads as one
291
398
  // voice — and a harness does not echo its own stdin, so these lines exist only because the
292
399
  // platform wrote them down (see `appendPlatformEvent`).
@@ -312,6 +419,7 @@ function MessageEntry({ event, attachmentUrl }: { event: TaskEvent; attachmentUr
312
419
  {bool(event.payload.truncated) && (
313
420
  <p className="mt-1 text-[10px] text-muted-foreground">Clipped to the 8 KiB kept per field.</p>
314
421
  )}
422
+ {delivery && <DeliveryTracker delivery={delivery} live={live} ts={event.ts} />}
315
423
  <EventTime ts={event.ts} />
316
424
  </Entry>
317
425
  )
@@ -372,26 +480,30 @@ function ReopenedEntry({ event }: { event: TaskEvent }) {
372
480
  )
373
481
  }
374
482
 
483
+ /**
484
+ * Your message, between the click and its own event. Drawn as what it is — a message of yours,
485
+ * on its way — and not dashed and greyed: that read as being offline, on a reply that can take a
486
+ * minute to start because the machine is waking (the stored message then takes over, with its
487
+ * `DeliveryTracker`).
488
+ */
375
489
  function PendingEntry({ text, previews = [] }: { text: string; previews?: string[] }) {
376
490
  return (
377
491
  <Entry>
378
- <Marker icon={<UserIcon className="h-3 w-3" />} tone="muted" />
379
- <div className="rounded-lg border border-dashed bg-muted/30 px-3 py-2">
380
- <p className="whitespace-pre-wrap break-words text-sm leading-6 text-muted-foreground">
381
- {renderInlineMarkdown(text, "pending")}
382
- </p>
492
+ <Marker icon={<UserIcon className="h-3 w-3" />} tone="primary" />
493
+ <div className="rounded-lg border border-primary/25 bg-primary/[0.06] px-3 py-2">
494
+ <p className="whitespace-pre-wrap break-words text-sm leading-6">{renderInlineMarkdown(text, "pending")}</p>
383
495
  {previews.length > 0 && (
384
496
  <div className="mt-2 flex flex-wrap gap-2">
385
497
  {previews.map((src) => (
386
- <img key={src} src={src} alt="" className="max-h-24 rounded-md border opacity-70" />
498
+ <img key={src} src={src} alt="" className="max-h-24 rounded-md border" />
387
499
  ))}
388
500
  </div>
389
501
  )}
390
- <p className="mt-1 flex items-center gap-1.5 text-[10px] text-muted-foreground">
391
- <span className="h-1 w-1 animate-pulse rounded-full bg-muted-foreground" />
392
- sending…
393
- </p>
394
502
  </div>
503
+ <p className="mt-1 flex items-center gap-1 text-[10px] text-muted-foreground" data-slot="reply-sending">
504
+ <Loader2Icon className="h-3 w-3 animate-spin" />
505
+ Sending…
506
+ </p>
395
507
  </Entry>
396
508
  )
397
509
  }
@@ -428,13 +540,64 @@ const RUN_THRESHOLD = 2
428
540
  * happens here — the stored stream stays flat.
429
541
  */
430
542
  function useTimeline(events: TaskEvent[]) {
431
- return useMemo(() => {
543
+ return useMemo(() => foldTimeline(events), [events])
544
+ }
545
+
546
+ /** `useTimeline`'s fold, pure — exported for the tests (jsdom cannot lay the list out). */
547
+ export function foldTimeline(events: TaskEvent[]) {
548
+ {
432
549
  const flat: Item[] = []
433
550
  const byCallId = new Map<string, ToolCall>()
434
551
  const raw: TaskEvent[] = []
435
552
  let lastMessage = ""
553
+ // The queued reply whose way to the session the events below are still telling.
554
+ let tracking: ReplyDelivery | null = null
436
555
 
437
556
  for (const event of events) {
557
+ // ── A queued reply, and its way to the session ──
558
+ if (event.type === "machine.wake" || event.type === "reply.failed") {
559
+ // Steps of a delivery, drawn under the message they are about rather than as rows. One
560
+ // with no queued message before it (a wake by hand, an older stream) has nothing to add
561
+ // that the machine panel does not already say.
562
+ if (tracking && event.type === "reply.failed") {
563
+ tracking.status = "failed"
564
+ tracking.error = str(event.payload.error) || undefined
565
+ tracking = null
566
+ } else if (tracking && str(event.payload.phase) === "starting") {
567
+ tracking.status = "waking"
568
+ tracking.machineKind = str(event.payload.kind) || undefined
569
+ tracking.wakeStartedAt = event.ts
570
+ } else if (tracking && str(event.payload.phase) === "awake") {
571
+ tracking.status = "resuming"
572
+ tracking.machineKind ??= str(event.payload.kind) || undefined
573
+ tracking.wakeStartedAt ??= event.ts
574
+ tracking.wakeMs = typeof event.payload.ms === "number" ? event.payload.ms : undefined
575
+ }
576
+ continue
577
+ }
578
+ if (event.type === "session.started" && tracking) {
579
+ tracking.status = "delivered"
580
+ tracking = null
581
+ }
582
+ if (event.type === "message" && str(event.payload.role) === "user") {
583
+ tracking = null
584
+ if (bool(event.payload.queued)) {
585
+ const delivery: ReplyDelivery = { status: "queued" }
586
+ flat.push({ kind: "event", event, delivery })
587
+ tracking = delivery
588
+ continue
589
+ }
590
+ }
591
+ // A turn the harness played without calling the model (flagged by the platform, `empty`):
592
+ // Claude Code reporting orphaned background tasks as it resumes. « Session finished » with
593
+ // nothing in it, an instant after a reply, read as the task having ended — so neither it
594
+ // nor the start it closes is drawn.
595
+ if (event.type === "session.ended" && bool(event.payload.empty)) {
596
+ const last = flat[flat.length - 1]
597
+ if (last?.kind === "event" && last.event.type === "session.started") flat.pop()
598
+ continue
599
+ }
600
+
438
601
  if (
439
602
  event.type === "raw" ||
440
603
  event.type === "usage" ||
@@ -527,7 +690,7 @@ function useTimeline(events: TaskEvent[]) {
527
690
  }
528
691
 
529
692
  return { items, raw, calls }
530
- }, [events])
693
+ }
531
694
  }
532
695
 
533
696
 
@@ -551,10 +714,12 @@ function Row({
551
714
  row,
552
715
  attachmentUrl,
553
716
  onOpenStack,
717
+ live,
554
718
  }: {
555
719
  row: Row
556
720
  attachmentUrl: AttachmentUrl
557
721
  onOpenStack: (seq: number) => void
722
+ live: boolean
558
723
  }) {
559
724
  if (row.kind === "pending") return <PendingEntry text={row.text} previews={row.previews} />
560
725
  if (row.kind === "working") return <WorkingEntry />
@@ -564,7 +729,8 @@ function Row({
564
729
  return <ToolEntry entry={row.entry} attachmentUrl={attachmentUrl} onOpenStack={onOpenStack} />
565
730
  if (row.event.type === "thinking") return <ThinkingEntry event={row.event} />
566
731
  if (row.event.type === "plan") return <PlanEntry event={row.event} />
567
- if (row.event.type === "message") return <MessageEntry event={row.event} attachmentUrl={attachmentUrl} />
732
+ if (row.event.type === "message")
733
+ return <MessageEntry event={row.event} attachmentUrl={attachmentUrl} delivery={row.delivery} live={live} />
568
734
  if (row.event.type === "session.reopened") return <ReopenedEntry event={row.event} />
569
735
  return <BoundaryEntry event={row.event} hideSummary={row.hideSummary} />
570
736
  }
@@ -892,7 +1058,7 @@ export function TaskEventStream({
892
1058
  className="absolute left-0 top-0 w-full"
893
1059
  style={{ transform: `translateY(${virtualRow.start}px)` }}
894
1060
  >
895
- <Row row={rows[virtualRow.index]} attachmentUrl={attachmentUrl} onOpenStack={openStack} />
1061
+ <Row row={rows[virtualRow.index]} attachmentUrl={attachmentUrl} onOpenStack={openStack} live={live} />
896
1062
  </div>
897
1063
  ))}
898
1064
  </div>
@@ -47,7 +47,7 @@ export type { TaskDetailsProps } from "./task-details"
47
47
 
48
48
  // ── The conversation ────────────────────────────────────────────────────────────────────────
49
49
  export { TaskEventStream } from "./event-stream"
50
- export type { TaskEventStreamProps } from "./event-stream"
50
+ export type { ReplyDelivery, TaskEventStreamProps } from "./event-stream"
51
51
  export { TaskComposer } from "./composer"
52
52
  export type { TaskComposerProps } from "./composer"
53
53
  export { AgentMarkdown, renderInlineMarkdown } from "./agent-markdown"
@@ -70,7 +70,7 @@ export const taskPendingActionConfig: Record<TaskPendingAction, { label: string;
70
70
  className: "bg-destructive/10 text-destructive border-destructive/30",
71
71
  textClass: "text-destructive",
72
72
  },
73
- replying: { label: "Sending", className: "bg-primary/10 text-primary border-primary/30", textClass: "text-primary" },
73
+ replying: { label: "Resuming", className: "bg-primary/10 text-primary border-primary/30", textClass: "text-primary" },
74
74
  }
75
75
 
76
76
  /** Lax lookup: an unknown state reads as `queued` (neutral) instead of throwing. */
@@ -12,6 +12,7 @@ import { render, screen, fireEvent, waitFor } from "@testing-library/react"
12
12
  import { renderInlineMarkdown } from "./agent-markdown"
13
13
  import { emptyCommandTerminalState, planCommandTerminalWrites } from "./command-terminal"
14
14
  import { TaskComposer } from "./composer"
15
+ import { foldTimeline } from "./event-stream"
15
16
  import { TaskBoot, bootSteps } from "./machine"
16
17
  import { NewTaskComposer } from "./new-task-composer"
17
18
  import { clearTaskDraft, readTaskDraft } from "./prompt-draft"
@@ -610,3 +611,61 @@ describe("NewTaskComposer — delegating where the conversation will be", () =>
610
611
  expect(screen.getByText("Pick “Runs on” first.")).toBeTruthy()
611
612
  })
612
613
  })
614
+
615
+ describe("a queued reply", () => {
616
+ const delivery = (events: TaskEvent[]) =>
617
+ foldTimeline(events).items.flatMap((i) => (i.kind === "event" && i.delivery ? [{ seq: i.event.seq, ...i.delivery }] : []))
618
+ const queued = ev(10, "message", { role: "user", text: "Rebase on main", queued: true })
619
+
620
+ it("is queued until something happens, then follows the machine waking and the session resuming", () => {
621
+ expect(delivery([queued])).toEqual([{ seq: 10, status: "queued" }])
622
+ const starting = ev(11, "machine.wake", { phase: "starting", kind: "sandbox", from: "stopped" })
623
+ expect(delivery([queued, starting])[0]).toMatchObject({ status: "waking", machineKind: "sandbox", wakeStartedAt: starting.ts })
624
+ const awake = ev(12, "machine.wake", { phase: "awake", kind: "sandbox", ms: 54_000 })
625
+ expect(delivery([queued, starting, awake])[0]).toMatchObject({ status: "resuming", wakeMs: 54_000 })
626
+ const started = ev(13, "session.started", { sessionId: "s1" })
627
+ expect(delivery([queued, starting, awake, started])[0]).toMatchObject({ status: "delivered", wakeMs: 54_000 })
628
+ })
629
+
630
+ it("says why it was not delivered", () => {
631
+ expect(delivery([queued, ev(11, "reply.failed", { error: "Branch check failed" })])[0]).toMatchObject({
632
+ status: "failed",
633
+ error: "Branch check failed",
634
+ })
635
+ })
636
+
637
+ it("draws the wake steps under the message, not as rows of their own", () => {
638
+ const { items } = foldTimeline([queued, ev(11, "machine.wake", { phase: "starting", kind: "worker" })])
639
+ expect(items).toHaveLength(1)
640
+ })
641
+
642
+ it("leaves a message delivered live alone", () => {
643
+ expect(delivery([ev(10, "message", { role: "user", text: "Also the footer" })])).toEqual([])
644
+ })
645
+ })
646
+
647
+ describe("an empty turn", () => {
648
+ it("is not drawn — neither its end nor the start it closes", () => {
649
+ const { items } = foldTimeline([
650
+ ev(1, "message", { role: "user", text: "Carry on", queued: true }),
651
+ ev(2, "session.started", { sessionId: "s1" }),
652
+ ev(3, "usage", { scope: "session", turns: 0 }),
653
+ ev(4, "session.ended", { status: "succeeded", summary: "", empty: true }),
654
+ ev(5, "session.started", { sessionId: "s1" }),
655
+ ev(6, "message", { role: "assistant", text: "Rebasing now." }),
656
+ ])
657
+ const types = items.map((i) => (i.kind === "event" ? i.event.seq : i.kind))
658
+ expect(types).toEqual([1, 5, 6])
659
+ })
660
+ })
661
+
662
+ describe("the composer while a reply is on its way", () => {
663
+ it("keeps the box writable and holds Send", () => {
664
+ render(<TaskComposer state="in-review" canResume protocol="claude-stream" pending onSubmit={() => {}} />)
665
+ const box = screen.getByRole("textbox") as HTMLTextAreaElement
666
+ expect(box.disabled).toBe(false)
667
+ fireEvent.change(box, { target: { value: "and the footer too" } })
668
+ expect((screen.getByRole("button", { name: /send/i }) as HTMLButtonElement).disabled).toBe(true)
669
+ expect(screen.getByText(/your message is queued/i)).toBeTruthy()
670
+ })
671
+ })