@spunto/design-system 0.42.0 → 0.43.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.42.0",
3
+ "version": "0.43.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",
@@ -20,7 +20,7 @@ export type { ActionMenuProps, ActionMenuItem, ActionMenuEntry, ActionMenuLinkRe
20
20
  export { WorkerCockpit } from "./worker-cockpit"
21
21
  export type { WorkerCockpitAction, WorkerCockpitProps } from "./worker-cockpit"
22
22
 
23
- export { WorkerStatusDot, WorkerStatusPill, resolveWorkerStatus, workerStatusConfig } from "./worker-status"
23
+ export { IN_FLIGHT_STATUSES, WorkerStatusDot, WorkerStatusPill, inFlightMessage, resolveWorkerStatus, workerStatusConfig } from "./worker-status"
24
24
  export type { WorkerStatus, WorkerStatusConfig, WorkerStatusKey } from "./worker-status"
25
25
 
26
26
  export { SetupProgress, StepIndicator, phaseLabel, setupProgress, setupTotalMs } from "./setup-progress"
@@ -29,8 +29,8 @@ export type { SetupProgressProps, StepState } from "./setup-progress"
29
29
  export { WorkerSetupTimeline } from "./worker-setup-timeline"
30
30
  export { SetupWaterfall } from "./setup-waterfall"
31
31
 
32
- export { WorkerStatusHistory, statusHistorySpans } from "./worker-status-history"
33
- export type { WorkerStatusHistoryProps, WorkerStatusSpan } from "./worker-status-history"
32
+ export { WorkerStatusHistory, WorkerStatusHistoryTip, statusHistorySpans } from "./worker-status-history"
33
+ export type { WorkerStatusHistoryProps, WorkerStatusSpan, WorkerStatusHistoryTipProps } from "./worker-status-history"
34
34
 
35
35
  export { ResourceBars } from "./resource-bars"
36
36
  export type { ResourceBarsProps, WorkerStats } from "./resource-bars"
@@ -20,7 +20,9 @@ import { GitBranchChips, type GitRepoStatus } from "./git-branch-chips"
20
20
  import { ResourceBars, type WorkerStats } from "./resource-bars"
21
21
  import { SetupProgress, setupTotalMs } from "./setup-progress"
22
22
  import { TagChips } from "./tag-chips"
23
- import type { WorkerCardWorker, WorkerCreator } from "./types"
23
+ import type { WorkerCardWorker, WorkerCreator, WorkerStatusEvent } from "./types"
24
+ import { WorkerStatusHistoryTip } from "./worker-status-history"
25
+ import { Tooltip } from "../tooltip"
24
26
  import { WorkerStatusDot, WorkerStatusPill, resolveWorkerStatus } from "./worker-status"
25
27
 
26
28
  /** Renders the "View" affordance. A slot, so the package never imports `next/link`. */
@@ -113,6 +115,12 @@ export interface WorkerCardProps {
113
115
  * finished task is drawn muted: the machine is free. Absent → no line.
114
116
  */
115
117
  task?: { entry: WorkerTask; href: string }
118
+ /**
119
+ * Its status journal (`WorkerStatusEvent[]`, the same one `WorkerCockpit.statusHistory` takes):
120
+ * shown on hover (and focus) of the status pill, as `WorkerStatusHistoryTip` — the time spent in
121
+ * each state and the last stays. Omitted or empty → a plain pill.
122
+ */
123
+ statusHistory?: WorkerStatusEvent[]
116
124
  /** Replaces the default "View" footer entirely (extra buttons, an IDE link…). */
117
125
  footer?: ReactNode
118
126
  /** Label of the default footer button. */
@@ -160,6 +168,7 @@ export function WorkerCard({
160
168
  actions,
161
169
  task,
162
170
  footer,
171
+ statusHistory,
163
172
  viewLabel = "View",
164
173
  className,
165
174
  }: WorkerCardProps) {
@@ -211,7 +220,16 @@ export function WorkerCard({
211
220
  {/* A worker name is one unbreakable token ("spunto-fix-tunnel-42"):
212
221
  without the cap it pushes the card wider than its column. */}
213
222
  <span className="max-w-full truncate text-sm leading-none font-semibold">{title}</span>
214
- <WorkerStatusPill status={status} />
223
+ {statusHistory?.length ? (
224
+ // Its history on hover of its status, not as a band: the card stays what it is.
225
+ <Tooltip content={<WorkerStatusHistoryTip events={statusHistory} />} side="bottom" align="start">
226
+ <span tabIndex={0} data-slot="worker-status-history-trigger" className="inline-flex cursor-default rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring/40">
227
+ <WorkerStatusPill status={status} />
228
+ </span>
229
+ </Tooltip>
230
+ ) : (
231
+ <WorkerStatusPill status={status} />
232
+ )}
215
233
  {worker.projectVersion != null && (
216
234
  <span className="inline-flex items-center rounded-full border border-border bg-muted px-2 py-0.5 font-mono text-[10px] leading-none text-muted-foreground">
217
235
  v{worker.projectVersion}
@@ -26,6 +26,7 @@ import {
26
26
  LoaderIcon,
27
27
  Maximize2Icon,
28
28
  PanelRightOpenIcon,
29
+ PauseIcon,
29
30
  PlayIcon,
30
31
  RefreshCwIcon,
31
32
  SquareIcon,
@@ -47,7 +48,7 @@ import { TagChips } from "./tag-chips"
47
48
  import type { WorkerCockpitWorker, WorkerCreator, WorkerStatusEvent } from "./types"
48
49
  import { type LinkRender } from "./worker-card"
49
50
  import { WorkerSetupTimeline } from "./worker-setup-timeline"
50
- import { WorkerStatusDot, WorkerStatusPill, resolveWorkerStatus } from "./worker-status"
51
+ import { IN_FLIGHT_STATUSES, WorkerStatusDot, WorkerStatusPill, inFlightMessage, resolveWorkerStatus } from "./worker-status"
51
52
  import { WorkerStatusHistory } from "./worker-status-history"
52
53
  import { WorkerTaskHistory } from "../tasks/worker-link"
53
54
  import type { TaskItem } from "../tasks/types"
@@ -108,6 +109,12 @@ export interface WorkerCockpitProps {
108
109
 
109
110
  onStop?: () => void
110
111
  stopping?: boolean
112
+ /**
113
+ * "Pause", next to Stop: stopped with its memory kept (a sandbox in a microVM, RFC 0039 § 20).
114
+ * Omitted → no button. A worker in `paused` is offered "Resume" (`onStart`) rather than "Start".
115
+ */
116
+ onPause?: () => void
117
+ pausing?: boolean
111
118
  onStart?: () => void
112
119
  starting?: boolean
113
120
  onRebuild?: () => void
@@ -165,6 +172,7 @@ const BANNER_TONES = {
165
172
  offline: "border-orange-500/25 bg-orange-500/5 text-orange-600 dark:text-orange-400",
166
173
  warn: "border-amber-500/25 bg-amber-500/5 text-amber-600 dark:text-amber-400",
167
174
  error: "border-destructive/25 bg-destructive/5 text-destructive",
175
+ busy: "border-yellow-500/25 bg-yellow-500/5 text-yellow-700 dark:text-yellow-400",
168
176
  } as const
169
177
 
170
178
  function Banner({ tone, children }: { tone: keyof typeof BANNER_TONES; children: ReactNode }) {
@@ -208,6 +216,8 @@ export function WorkerCockpit({
208
216
  onRemoveTag,
209
217
  editorHref,
210
218
  onStop,
219
+ onPause,
220
+ pausing,
211
221
  stopping = false,
212
222
  onStart,
213
223
  starting = false,
@@ -236,8 +246,11 @@ export function WorkerCockpit({
236
246
 
237
247
  const status = resolveWorkerStatus(worker)
238
248
  const settled = status.running && !status.settingUp
239
- const isStopped = worker.dockerState === "stopped" || worker.dockerState === "exited"
249
+ const isPaused = status.key === "paused"
250
+ const isStopped = worker.dockerState === "stopped" || worker.dockerState === "exited" || isPaused
240
251
  const isDeleting = status.key === "deleting"
252
+ // Its memory being written, or on its way down: nothing else is offered meanwhile.
253
+ const inFlight = IN_FLIGHT_STATUSES.has(status.key)
241
254
  const hasContainer = worker.containerId != null
242
255
  const title = worker.name || (worker.index != null ? `Workspace #${worker.index}` : worker.id)
243
256
  const outdated =
@@ -279,6 +292,14 @@ export function WorkerCockpit({
279
292
  )}
280
293
  </Banner>
281
294
  )}
295
+ {inFlight && inFlightMessage[status.key] && (
296
+ <Banner tone="busy">
297
+ <span className="flex min-w-0 items-center gap-2">
298
+ <LoaderIcon className="h-3.5 w-3.5 shrink-0 animate-spin" />
299
+ {inFlightMessage[status.key]}
300
+ </span>
301
+ </Banner>
302
+ )}
282
303
  {nodeOnline === false && (
283
304
  <Banner tone="offline">
284
305
  <span className="flex min-w-0 items-center gap-2">
@@ -428,7 +449,7 @@ export function WorkerCockpit({
428
449
  {actions.map((a) => {
429
450
  const Icon = a.icon
430
451
  return (
431
- <button key={a.id} type="button" disabled={a.disabled || a.busy} onClick={a.onClick} className="flex w-full items-center gap-2 rounded-lg border border-border/50 bg-muted/20 px-3 py-2.5 text-xs text-foreground transition-colors hover:bg-muted/40 disabled:opacity-50">
452
+ <button key={a.id} type="button" disabled={a.disabled || a.busy || inFlight} onClick={a.onClick} className="flex w-full items-center gap-2 rounded-lg border border-border/50 bg-muted/20 px-3 py-2.5 text-xs text-foreground transition-colors hover:bg-muted/40 disabled:opacity-50">
432
453
  {a.busy ? <LoaderIcon className="h-3.5 w-3.5 animate-spin text-muted-foreground" /> : Icon ? <Icon className="h-3.5 w-3.5 text-muted-foreground" /> : null}
433
454
  <span className="font-medium">{a.label}</span>
434
455
  {a.hint && <span className="ml-auto text-[10px] text-muted-foreground/50">{a.hint}</span>}
@@ -436,14 +457,14 @@ export function WorkerCockpit({
436
457
  )
437
458
  })}
438
459
  {hasContainer && !status.settingUp && !isDeleting && onRebuild && (
439
- <button type="button" disabled={rebuilding} onClick={onRebuild} className="flex w-full items-center gap-2 rounded-lg border border-border/50 bg-muted/20 px-3 py-2.5 text-xs text-foreground transition-colors hover:bg-muted/40 disabled:opacity-50">
460
+ <button type="button" disabled={rebuilding || inFlight} onClick={onRebuild} className="flex w-full items-center gap-2 rounded-lg border border-border/50 bg-muted/20 px-3 py-2.5 text-xs text-foreground transition-colors hover:bg-muted/40 disabled:opacity-50">
440
461
  <RefreshCwIcon className={cn("h-3.5 w-3.5 text-muted-foreground", rebuilding && "animate-spin")} />
441
462
  <span className="font-medium">Rebuild container</span>
442
463
  <span className="ml-auto text-[10px] text-muted-foreground/50">keeps workspace</span>
443
464
  </button>
444
465
  )}
445
466
  {(hasContainer || isDeleting) && nodeOnline !== false && onDelete && (
446
- <button type="button" disabled={deleting || isDeleting} onClick={onDelete} className="flex w-full items-center gap-2 rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive transition-colors hover:bg-destructive/10 disabled:opacity-50">
467
+ <button type="button" disabled={deleting || inFlight} onClick={onDelete} className="flex w-full items-center gap-2 rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive transition-colors hover:bg-destructive/10 disabled:opacity-50">
447
468
  {isDeleting ? <LoaderIcon className="h-3.5 w-3.5 animate-spin" /> : <Trash2Icon className="h-3.5 w-3.5" />}
448
469
  <span className="font-medium">Delete workspace</span>
449
470
  <span className="ml-auto text-[10px] opacity-60">permanent</span>
@@ -527,14 +548,21 @@ export function WorkerCockpit({
527
548
  <Code2Icon className="h-3.5 w-3.5" />Open IDE<ExternalLinkIcon className="h-2.5 w-2.5 opacity-70" />
528
549
  </Link>
529
550
  )}
530
- {settled && onStop && (
531
- <Button variant="ghost" size="sm" className="h-8 gap-1.5 px-3 text-xs text-muted-foreground hover:bg-destructive/10 hover:text-destructive" disabled={stopping} onClick={onStop}>
551
+ {settled && onPause && (
552
+ <Button variant="ghost" size="sm" className="h-8 gap-1.5 px-3 text-xs text-muted-foreground" disabled={pausing || stopping} onClick={onPause}>
553
+ <PauseIcon className="h-3.5 w-3.5" />Pause
554
+ </Button>
555
+ )}
556
+ {/* A paused box can be stopped too: its memory dropped. */}
557
+ {(settled || isPaused) && onStop && (
558
+ <Button variant="ghost" size="sm" className="h-8 gap-1.5 px-3 text-xs text-muted-foreground hover:bg-destructive/10 hover:text-destructive" disabled={stopping || pausing} onClick={onStop}>
532
559
  <SquareIcon className="h-3.5 w-3.5" />Stop
533
560
  </Button>
534
561
  )}
535
562
  {(isStopped || worker.dockerState === "error") && nodeOnline !== false && onStart && (
536
563
  <Button variant="outline" size="sm" className="h-8 gap-1.5 px-3 text-xs" disabled={starting} onClick={onStart}>
537
- <PlayIcon className="h-3.5 w-3.5" />Start
564
+ <PlayIcon className="h-3.5 w-3.5" />
565
+ {isPaused ? "Resume" : "Start"}
538
566
  </Button>
539
567
  )}
540
568
  </div>
@@ -164,3 +164,44 @@ export function WorkerStatusHistory({ events, now, limit = 5, className }: Worke
164
164
  </div>
165
165
  )
166
166
  }
167
+
168
+ export interface WorkerStatusHistoryTipProps {
169
+ /** The journal, in any order. Empty → nothing is drawn. */
170
+ events: WorkerStatusEvent[]
171
+ now?: number | Date
172
+ /** Stays listed, newest first. */
173
+ recent?: number
174
+ }
175
+
176
+ /**
177
+ * The same journal, for a tooltip (`WorkerCard.statusHistory`, on hover of the status pill): the
178
+ * strip of time spent in each state, then the last stays, newest first. Drawn for the tooltip's
179
+ * inverted colours — the cockpit's `WorkerStatusHistory` has the reasons and the sources.
180
+ */
181
+ export function WorkerStatusHistoryTip({ events, now, recent = 6 }: WorkerStatusHistoryTipProps) {
182
+ const nowMs = now instanceof Date ? now.getTime() : (now ?? Date.now())
183
+ const spans = statusHistorySpans(events, nowMs)
184
+ if (!spans.length) return null
185
+ const total = spans.reduce((sum, s) => sum + s.duration, 0)
186
+ const newestFirst = [...spans].reverse()
187
+ const shown = newestFirst.slice(0, recent)
188
+ return (
189
+ <div data-slot="worker-status-history-tip" className="w-56 space-y-2 py-1">
190
+ <div className="flex h-1.5 gap-px overflow-hidden rounded-sm" aria-hidden>
191
+ {spans.map((s, i) => (
192
+ <span key={i} className={cn("min-w-[3px] basis-0", s.status.dotClass)} style={{ flexGrow: total > 0 ? s.duration : 1 }} />
193
+ ))}
194
+ </div>
195
+ <ol className="space-y-1">
196
+ {shown.map((s) => (
197
+ <li key={`${s.event.seq ?? ""}-${s.event.at}`} className={cn("flex items-center gap-1.5", !s.current && "opacity-75")}>
198
+ <WorkerStatusDot status={s.status} className="h-1.5 w-1.5" />
199
+ <span className="min-w-0 flex-1 truncate font-medium">{s.label}</span>
200
+ <span className="shrink-0 font-mono text-[10px] tabular-nums">{formatElapsed(s.duration)}</span>
201
+ </li>
202
+ ))}
203
+ </ol>
204
+ {newestFirst.length > shown.length && <p className="text-[10px] opacity-60">+ {newestFirst.length - shown.length} earlier</p>}
205
+ </div>
206
+ )
207
+ }
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "vitest"
2
- import { resolveWorkerStatus, workerStatusConfig } from "./worker-status"
2
+ import { IN_FLIGHT_STATUSES, resolveWorkerStatus, workerStatusConfig } from "./worker-status"
3
3
 
4
4
  describe("resolveWorkerStatus — le node injoignable", () => {
5
5
  it("ne prétend rien, et ne prétend surtout pas qu'un setup est en cours", () => {
@@ -85,3 +85,22 @@ describe("resolveWorkerStatus — la tolérance qui fait vivre la table", () =>
85
85
  }
86
86
  })
87
87
  })
88
+
89
+ describe("resolveWorkerStatus — pause, stop, snapshot (RFC 0039 § 20)", () => {
90
+ it("une boîte en pause n'est pas arrêtée : sa propre pastille, et rien ne tourne", () => {
91
+ const s = resolveWorkerStatus({ id: "s", state: "paused", dockerState: "stopped" })
92
+ expect(s).toMatchObject({ key: "paused", label: "Paused", running: false, settingUp: false })
93
+ })
94
+
95
+ it("pendant qu'elle écrit sa mémoire, elle n'est ni en marche ni en setup : en vol", () => {
96
+ for (const state of ["pausing", "snapshotting", "stopping"] as const) {
97
+ const s = resolveWorkerStatus({ id: "s", state })
98
+ expect(s.key).toBe(state)
99
+ expect(s.running).toBe(false)
100
+ expect(s.settingUp).toBe(false)
101
+ expect(IN_FLIGHT_STATUSES.has(s.key)).toBe(true)
102
+ }
103
+ expect(resolveWorkerStatus({ id: "s", state: "pausing" }).label).toBe("Pausing…")
104
+ expect(resolveWorkerStatus({ id: "s", state: "snapshotting" }).label).toBe("Snapshotting…")
105
+ })
106
+ })
@@ -39,6 +39,9 @@ export type WorkerStatusKey =
39
39
  | "pulling"
40
40
  | "stopping"
41
41
  | "deleting"
42
+ | "pausing"
43
+ | "paused"
44
+ | "snapshotting"
42
45
 
43
46
  export interface WorkerStatusConfig {
44
47
  label: string
@@ -101,6 +104,32 @@ export const workerStatusConfig: Record<WorkerStatusKey, WorkerStatusConfig> = {
101
104
  pulling: { ...BUSY, label: "Pulling image…" },
102
105
  stopping: { ...BUSY, label: "Stopping…" },
103
106
  deleting: { ...BUSY, label: "Deleting…" },
107
+ // A sandbox stopped with its memory (Spunto Cloud, RFC 0039 § 20): idle like a stopped one, but
108
+ // not the same promise — a start resumes it where it was, processes included. Blue, not grey:
109
+ // the one idle state that still holds something.
110
+ paused: {
111
+ label: "Paused",
112
+ dotClass: "bg-sky-500",
113
+ pillClass: "bg-sky-500/10 text-sky-700 dark:text-sky-400 border-sky-500/20",
114
+ accent: "border-l-sky-500",
115
+ },
116
+ // Its memory being written: nothing can be asked of it until then.
117
+ pausing: { ...BUSY, label: "Pausing…" },
118
+ snapshotting: { ...BUSY, label: "Snapshotting…" },
119
+ }
120
+
121
+ /**
122
+ * Statuses during which nothing can be asked of a worker or a sandbox: its memory is being written
123
+ * (`pausing`, `snapshotting`), or it is on its way down. A host greys its actions out on these.
124
+ */
125
+ export const IN_FLIGHT_STATUSES: ReadonlySet<WorkerStatusKey> = new Set(["pausing", "snapshotting", "stopping", "deleting"])
126
+
127
+ /** What a status in flight means for the reader, in one line — the cockpit's banner. */
128
+ export const inFlightMessage: Partial<Record<WorkerStatusKey, string>> = {
129
+ pausing: "Pausing — writing its memory to disk. Nothing else can be done until it is paused.",
130
+ snapshotting: "Snapshotting — frozen while its memory is written. It runs again once the snapshot is taken.",
131
+ stopping: "Stopping — shutting down. Its memory is not kept: the next start boots it.",
132
+ deleting: "Deleting…",
104
133
  }
105
134
 
106
135
  export interface WorkerStatus extends WorkerStatusConfig {
@@ -176,6 +205,10 @@ export function resolveWorkerStatus(worker: WorkerCardWorker): WorkerStatus {
176
205
 
177
206
  if (state === "deleting") return of("deleting")
178
207
  if (state === "stopping") return of("stopping")
208
+ if (state === "pausing") return of("pausing")
209
+ if (state === "paused") return of("paused")
210
+ // Frozen for a moment, not running for anyone who would act on it now (`running: false`).
211
+ if (state === "snapshotting") return of("snapshotting")
179
212
  // Le node est injoignable : on ne sait pas. Surtout pas `settingUp` — annoncer une progression
180
213
  // pour une machine qu'on ne voit plus est exactement ce que ce statut existe pour éviter.
181
214
  if (state === "unknown") return of("unknown")