@spunto/design-system 0.62.0 → 0.63.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.62.0",
3
+ "version": "0.63.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",
@@ -0,0 +1,16 @@
1
+ import { describe, it, expect } from "vitest"
2
+ import { untilLabel } from "./app-tiles"
3
+
4
+ describe("untilLabel", () => {
5
+ const now = Date.parse("2026-10-31T00:00:00Z")
6
+ it("says how long until a window resets", () => {
7
+ expect(untilLabel("2026-10-31T00:20:00Z", now)).toBe("in 20m")
8
+ expect(untilLabel("2026-10-31T02:10:00Z", now)).toBe("in 2h 10m")
9
+ expect(untilLabel("2026-10-31T03:00:00Z", now)).toBe("in 3h")
10
+ expect(untilLabel("2026-11-03T12:00:00Z", now)).toBe("in 3d 12h")
11
+ })
12
+ it("says now once it has passed, and nothing for a date it cannot read", () => {
13
+ expect(untilLabel("2026-10-30T23:00:00Z", now)).toBe("now")
14
+ expect(untilLabel("soon", now)).toBeNull()
15
+ })
16
+ })
@@ -1,14 +1,16 @@
1
1
  "use client"
2
2
 
3
- // What an app installed in the organization says about the links a conversation shared (capability
4
- // `embed`, RFC 0053) — GitHub: each pull request, and where it stands. Drawn here, with our
5
- // components, from data the app returned: an app never sends markup, nor a color — it names a
6
- // tone, and the tone is painted with the status tokens every other block uses.
3
+ // What an app installed in the organization shows in a task's details (capability `embed`,
4
+ // RFC 0053) — GitHub: the pull requests the conversation shared; Claude Code: the session's quota,
5
+ // MCP servers, skills. Drawn here, with our components, from data the app returned: an app never
6
+ // sends markup, nor a color — it names a tone, and the tone is painted with the status tokens every
7
+ // other block uses.
7
8
 
8
- import { ExternalLinkIcon } from "lucide-react"
9
+ import { useState, type ReactNode } from "react"
10
+ import { CheckIcon, CopyIcon, ExternalLinkIcon } from "lucide-react"
9
11
 
10
12
  import { cn } from "../../utils"
11
- import type { TaskAppTileItem, TaskAppTileTone } from "./types"
13
+ import type { TaskAppTile, TaskAppTileFact, TaskAppTileItem, TaskAppTileList, TaskAppTileMeter, TaskAppTileTone } from "./types"
12
14
 
13
15
  const TONE_TEXT: Record<TaskAppTileTone, string> = {
14
16
  neutral: "text-muted-foreground",
@@ -28,49 +30,202 @@ const TONE_CHIP: Record<TaskAppTileTone, string> = {
28
30
  muted: "bg-muted/60 text-muted-foreground border-border/60",
29
31
  }
30
32
 
31
- /** The rows of one app's block, one card each — the same card as the branch's own pull request. */
33
+ /** A meter's fill: the same ramp as the context meter of Session, so « filling up » reads the same. */
34
+ const TONE_BAR: Record<TaskAppTileTone, string> = {
35
+ neutral: "color-mix(in oklch, var(--ship) 80%, var(--build))",
36
+ info: "var(--info)",
37
+ success: "var(--success)",
38
+ warning: "var(--color-amber-500, #f59e0b)",
39
+ danger: "var(--destructive)",
40
+ muted: "var(--muted-foreground)",
41
+ }
42
+
43
+ /** « in 2h 10m », « in 3d » — a reset ahead, read against the reader's clock. */
44
+ export function untilLabel(iso: string, now = Date.now()): string | null {
45
+ const ms = Date.parse(iso) - now
46
+ if (!Number.isFinite(ms)) return null
47
+ if (ms <= 0) return "now"
48
+ const minutes = Math.ceil(ms / 60_000)
49
+ if (minutes < 60) return `in ${minutes}m`
50
+ const hours = Math.floor(minutes / 60)
51
+ if (hours < 24) return `in ${hours}h${minutes % 60 ? ` ${minutes % 60}m` : ""}`
52
+ const days = Math.floor(hours / 24)
53
+ return `in ${days}d${hours % 24 ? ` ${hours % 24}h` : ""}`
54
+ }
55
+
56
+ function Meter({ meter }: { meter: TaskAppTileMeter }) {
57
+ const tone = meter.tone ?? "neutral"
58
+ const pct = Math.round(meter.value * 100)
59
+ const until = meter.resetsAt ? untilLabel(meter.resetsAt) : null
60
+ return (
61
+ <div>
62
+ <div className="flex items-baseline justify-between gap-3">
63
+ <span className="text-[11px] text-muted-foreground">{meter.label}</span>
64
+ <span className={cn("font-mono text-[11px] tabular-nums", tone === "danger" && "font-semibold text-destructive", tone === "warning" && "font-semibold text-amber-600 dark:text-amber-400")}>
65
+ {pct}%
66
+ </span>
67
+ </div>
68
+ <div className="mt-1.5 h-1.5 w-full overflow-hidden rounded-full bg-muted">
69
+ <div className="h-full rounded-full transition-[width] duration-500" style={{ width: `${pct}%`, background: TONE_BAR[tone] }} />
70
+ </div>
71
+ {(meter.detail || until) && (
72
+ <p className="mt-1 text-[10px] text-muted-foreground">
73
+ {[meter.detail, until && `resets ${until}`].filter(Boolean).join(" · ")}
74
+ </p>
75
+ )}
76
+ </div>
77
+ )
78
+ }
79
+
80
+ function CopyValue({ value }: { value: string }) {
81
+ const [copied, setCopied] = useState(false)
82
+ return (
83
+ <button
84
+ type="button"
85
+ title={copied ? "Copied" : "Copy"}
86
+ aria-label="Copy"
87
+ onClick={() => {
88
+ navigator.clipboard?.writeText(value).then(() => {
89
+ setCopied(true)
90
+ setTimeout(() => setCopied(false), 1500)
91
+ })
92
+ }}
93
+ className="shrink-0 text-muted-foreground transition-colors hover:text-foreground"
94
+ >
95
+ {copied ? <CheckIcon className="h-3 w-3 text-success" /> : <CopyIcon className="h-3 w-3" />}
96
+ </button>
97
+ )
98
+ }
99
+
100
+ function Fact({ fact }: { fact: TaskAppTileFact }) {
101
+ return (
102
+ <div className="flex items-baseline justify-between gap-3">
103
+ <span className="shrink-0 text-[11px] text-muted-foreground">{fact.label}</span>
104
+ <span className={cn("flex min-w-0 items-center gap-1 font-mono text-[11px] tabular-nums", fact.tone && fact.tone !== "neutral" && TONE_TEXT[fact.tone])}>
105
+ <span className="truncate" title={fact.value}>
106
+ {fact.value}
107
+ </span>
108
+ {fact.copy && <CopyValue value={fact.value} />}
109
+ </span>
110
+ </div>
111
+ )
112
+ }
113
+
114
+ /** Rows shown before « Show all » — the column is glanced at, not read. */
115
+ const FOLDED_VALUES = 12
116
+
117
+ function List({ list }: { list: TaskAppTileList }) {
118
+ const [all, setAll] = useState(false)
119
+ const shown = all ? list.values : list.values.slice(0, FOLDED_VALUES)
120
+ return (
121
+ <div>
122
+ <p className="text-[11px] text-muted-foreground">
123
+ {list.label} <span className="font-mono tabular-nums">· {list.values.length}</span>
124
+ </p>
125
+ <div className="mt-1.5 flex flex-wrap gap-1">
126
+ {shown.map((value) => (
127
+ <span key={value} className="rounded-sm border border-border/60 bg-muted/40 px-1.5 py-px font-mono text-[10px] text-muted-foreground">
128
+ {value}
129
+ </span>
130
+ ))}
131
+ {list.values.length > FOLDED_VALUES && (
132
+ <button type="button" onClick={() => setAll((v) => !v)} className="px-1 text-[10px] text-muted-foreground hover:text-foreground">
133
+ {all ? "Show fewer" : `+${list.values.length - FOLDED_VALUES}`}
134
+ </button>
135
+ )}
136
+ </div>
137
+ </div>
138
+ )
139
+ }
140
+
141
+ function ItemBody({ item }: { item: TaskAppTileItem }) {
142
+ return (
143
+ <>
144
+ <div className="flex min-w-0 items-center gap-1.5">
145
+ {item.status && (
146
+ <span className={cn("inline-flex h-5 shrink-0 items-center rounded-sm border px-1.5 text-[10px] font-medium", TONE_CHIP[item.status.tone])}>
147
+ {item.status.label}
148
+ </span>
149
+ )}
150
+ {item.label && <span className="shrink-0 font-mono text-[11px] text-muted-foreground">{item.label}</span>}
151
+ {item.subtitle && <span className="min-w-0 truncate font-mono text-[10px] text-muted-foreground">{item.subtitle}</span>}
152
+ {item.url && (
153
+ <ExternalLinkIcon className="ml-auto h-3 w-3 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
154
+ )}
155
+ </div>
156
+ <p className="mt-1.5 line-clamp-2 text-xs leading-snug">{item.title}</p>
157
+ {item.badges && item.badges.length > 0 && (
158
+ <div className="mt-1.5 flex flex-wrap items-center gap-x-2.5 gap-y-1">
159
+ {item.badges.map((badge) => (
160
+ <span key={badge.label} className={cn("inline-flex items-center gap-1 text-[10px]", TONE_TEXT[badge.tone])}>
161
+ <span className="h-1.5 w-1.5 rounded-full bg-current" />
162
+ {badge.label}
163
+ </span>
164
+ ))}
165
+ </div>
166
+ )}
167
+ </>
168
+ )
169
+ }
170
+
171
+ /**
172
+ * The rows of one app's block. A row with a `url` is a card that opens it — the same card as the
173
+ * branch's own pull request; a row without one (an MCP server) is a compact line: name, then state.
174
+ */
32
175
  export function TaskAppTileItems({ items, className }: { items: TaskAppTileItem[]; className?: string }) {
33
176
  if (items.length === 0) return null
34
177
  return (
35
178
  <ul className={cn("space-y-1.5", className)}>
36
- {items.map((item) => (
37
- <li key={item.url}>
38
- <a
39
- href={item.url}
40
- target="_blank"
41
- rel="noreferrer"
42
- title={item.url}
43
- 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"
44
- >
45
- <div className="flex min-w-0 items-center gap-1.5">
46
- {item.status && (
47
- <span
48
- className={cn(
49
- "inline-flex h-5 shrink-0 items-center rounded-sm border px-1.5 text-[10px] font-medium",
50
- TONE_CHIP[item.status.tone],
51
- )}
52
- >
53
- {item.status.label}
54
- </span>
55
- )}
56
- {item.label && <span className="shrink-0 font-mono text-[11px] text-muted-foreground">{item.label}</span>}
57
- {item.subtitle && <span className="min-w-0 truncate font-mono text-[10px] text-muted-foreground">{item.subtitle}</span>}
58
- <ExternalLinkIcon className="ml-auto h-3 w-3 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
59
- </div>
60
- <p className="mt-1.5 line-clamp-2 text-xs leading-snug">{item.title}</p>
61
- {item.badges && item.badges.length > 0 && (
62
- <div className="mt-1.5 flex flex-wrap items-center gap-x-2.5 gap-y-1">
63
- {item.badges.map((badge) => (
64
- <span key={badge.label} className={cn("inline-flex items-center gap-1 text-[10px]", TONE_TEXT[badge.tone])}>
65
- <span className="h-1.5 w-1.5 rounded-full bg-current" />
66
- {badge.label}
67
- </span>
68
- ))}
69
- </div>
179
+ {items.map((item) =>
180
+ item.url ? (
181
+ <li key={item.url}>
182
+ <a
183
+ href={item.url}
184
+ target="_blank"
185
+ rel="noreferrer"
186
+ 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"
188
+ >
189
+ <ItemBody item={item} />
190
+ </a>
191
+ </li>
192
+ ) : (
193
+ <li key={`title:${item.title}`} className="flex min-w-0 items-center justify-between gap-2">
194
+ <span className="min-w-0 truncate font-mono text-[11px]">
195
+ {item.title}
196
+ {item.subtitle && <span className="ml-1.5 text-[10px] text-muted-foreground">{item.subtitle}</span>}
197
+ </span>
198
+ {item.status && (
199
+ <span className={cn("inline-flex h-5 shrink-0 items-center rounded-sm border px-1.5 text-[10px] font-medium", TONE_CHIP[item.status.tone])}>
200
+ {item.status.label}
201
+ </span>
70
202
  )}
71
- </a>
72
- </li>
73
- ))}
203
+ </li>
204
+ ),
205
+ )}
74
206
  </ul>
75
207
  )
76
208
  }
209
+
210
+ function Section({ children, divided }: { children: ReactNode; divided: boolean }) {
211
+ return <div className={cn("space-y-2", divided && "border-t border-border/60 pt-3")}>{children}</div>
212
+ }
213
+
214
+ /** 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 }) {
216
+ const sections: ReactNode[] = []
217
+ if (tile.meters?.length) sections.push(tile.meters.map((m) => <Meter key={m.label} meter={m} />))
218
+ 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} />)
220
+ if (tile.lists?.length) sections.push(tile.lists.map((l) => <List key={l.label} list={l} />))
221
+ if (sections.length === 0) return null
222
+ return (
223
+ <div className={cn("space-y-3", className)}>
224
+ {sections.map((section, i) => (
225
+ <Section key={i} divided={i > 0}>
226
+ {section}
227
+ </Section>
228
+ ))}
229
+ </div>
230
+ )
231
+ }
@@ -87,7 +87,7 @@ export { TaskTerminalPanel } from "./terminal-panel"
87
87
  export type { TaskTerminalPanelProps } from "./terminal-panel"
88
88
  export { TaskPullRequest } from "./pull-request"
89
89
  export { TaskSharedFiles, TaskSharedLinks } from "./shared"
90
- export { TaskAppTileItems } from "./app-tiles"
90
+ export { TaskAppTileContent, TaskAppTileItems } from "./app-tiles"
91
91
  export { TaskSessionUsage, formatCost, formatTokens } from "./session-usage"
92
92
  export { TaskCommandLog } from "./command-log"
93
93
  export { TaskBoot, TaskMachine, bootSteps, workerLabel } from "./machine"
@@ -99,7 +99,10 @@ export type {
99
99
  AttachmentUrl,
100
100
  DraftFile,
101
101
  TaskAppTile,
102
+ TaskAppTileFact,
102
103
  TaskAppTileItem,
104
+ TaskAppTileList,
105
+ TaskAppTileMeter,
103
106
  TaskAppTileTone,
104
107
  PendingMessage,
105
108
  TaskDraft,
@@ -21,7 +21,7 @@ import { TaskCommandLog } from "./command-log"
21
21
  import { TaskPullRequest } from "./pull-request"
22
22
  import { TaskSessionUsage } from "./session-usage"
23
23
  import { TaskSharedFiles, TaskSharedLinks } from "./shared"
24
- import { TaskAppTileItems } from "./app-tiles"
24
+ import { TaskAppTileContent } from "./app-tiles"
25
25
  import { isLiveTaskState, taskSpan } from "./task-state"
26
26
  import type { AttachmentUrl, TaskAppTile, TaskCommand, TaskItem, TaskPendingAction, TaskPullRequests, TaskSessionUsageData, TaskSharedData } from "./types"
27
27
 
@@ -227,6 +227,14 @@ export function TaskDetails({
227
227
  </Block>
228
228
  )}
229
229
 
230
+ {/* What only the harness knows about its session (its quota, its MCP servers, its skills…),
231
+ from the task's agent app — Session's numbers stay ours, the same for every harness. */}
232
+ {appTiles?.filter((tile) => tile.session).map((tile) => (
233
+ <Block key={tile.appId} variant={variant} title={tile.title} hint={tile.appName === tile.title ? undefined : tile.appName}>
234
+ <TaskAppTileContent tile={tile} />
235
+ </Block>
236
+ ))}
237
+
230
238
  {pullRequests?.supported && (
231
239
  <Block variant={variant} title="Pull request">
232
240
  <TaskPullRequest data={pullRequests} />
@@ -235,9 +243,9 @@ export function TaskDetails({
235
243
 
236
244
  {/* Right under the branch's own PR: what the org's apps make of the links the conversation
237
245
  shared — the other pull requests it talked about, with where each one stands. */}
238
- {appTiles?.map((tile) => (
239
- <Block key={tile.appId} variant={variant} title={tile.title} hint={tile.appName}>
240
- <TaskAppTileItems items={tile.items} />
246
+ {appTiles?.filter((tile) => !tile.session).map((tile) => (
247
+ <Block key={tile.appId} variant={variant} title={tile.title} hint={tile.appName === tile.title ? undefined : tile.appName}>
248
+ <TaskAppTileContent tile={tile} />
241
249
  </Block>
242
250
  ))}
243
251
 
@@ -265,9 +265,10 @@ export interface TaskSharedData {
265
265
  /** A meaning an app gives a status; the design system picks the color (RFC 0053). */
266
266
  export type TaskAppTileTone = "neutral" | "info" | "success" | "warning" | "danger" | "muted"
267
267
 
268
- /** One row of an app's block: a thing it recognized in a shared link, and where it stands. */
268
+ /** One row of an app's block: a thing it recognized (a shared link, a server…), and where it stands. */
269
269
  export interface TaskAppTileItem {
270
- url: string
270
+ /** Absent: a row that is not a link. */
271
+ url?: string
271
272
  title: string
272
273
  /** « #262 » */
273
274
  label?: string
@@ -277,13 +278,45 @@ export interface TaskAppTileItem {
277
278
  badges?: { label: string; tone: TaskAppTileTone }[]
278
279
  }
279
280
 
280
- /** What an app draws in a task's details (`GET .../tiles`, capability `embed`). */
281
+ /** « Claude Code → 2.1.310 ». `copy`: the value is something to paste (an id). */
282
+ export interface TaskAppTileFact {
283
+ label: string
284
+ value: string
285
+ tone?: TaskAppTileTone
286
+ copy?: boolean
287
+ }
288
+
289
+ /** How much of something is used — a quota window. `value` from 0 to 1. */
290
+ export interface TaskAppTileMeter {
291
+ label: string
292
+ value: number
293
+ tone?: TaskAppTileTone
294
+ detail?: string
295
+ /** When it starts again from zero (ISO) — drawn as « resets in 2h 10m ». */
296
+ resetsAt?: string
297
+ }
298
+
299
+ /** A named set of short names — the skills a session loaded. */
300
+ export interface TaskAppTileList {
301
+ label: string
302
+ values: string[]
303
+ }
304
+
305
+ /**
306
+ * What an app draws in a task's details (`GET .../tiles`, capability `embed`). Every section is
307
+ * optional and drawn in this order: meters, facts, items, lists.
308
+ */
281
309
  export interface TaskAppTile {
282
310
  appId: string
283
311
  appName: string
284
- /** The block's heading — « Pull requests ». */
312
+ /** The block's heading — « Pull requests », « Claude Code ». */
285
313
  title: string
286
- items: TaskAppTileItem[]
314
+ /** From the app running the task's session: drawn right under Session rather than with the others. */
315
+ session?: boolean
316
+ meters?: TaskAppTileMeter[]
317
+ facts?: TaskAppTileFact[]
318
+ items?: TaskAppTileItem[]
319
+ lists?: TaskAppTileList[]
287
320
  }
288
321
 
289
322
  // ── Machine ──────────────────────────────────────────────────────────────────────────────────