@spunto/design-system 0.48.0 → 0.50.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/README.md +1 -32
- package/package.json +1 -5
- package/src/components/tasks/composer.tsx +11 -5
- package/src/components/tasks/event-stream.tsx +182 -16
- package/src/components/tasks/index.ts +1 -1
- package/src/components/tasks/task-state.tsx +1 -1
- package/src/components/tasks/tasks.test.tsx +59 -0
- package/src/components/observability/analytics.ts +0 -153
- package/src/components/observability/index.ts +0 -39
- package/src/components/observability/latency.ts +0 -47
- package/src/components/observability/log-lines.tsx +0 -120
- package/src/components/observability/observability.test.tsx +0 -255
- package/src/components/observability/span-waterfall.tsx +0 -493
- package/src/components/observability/trace-filters.tsx +0 -213
- package/src/components/observability/trace-list.tsx +0 -193
- package/src/components/observability/traces-overview.tsx +0 -284
- package/src/components/observability/types.ts +0 -29
package/README.md
CHANGED
|
@@ -188,7 +188,7 @@ const nextConfig = { transpilePackages: ["@spunto/design-system"] }
|
|
|
188
188
|
provider is also the umbrella that mounts the tooltip delay group and the overlay
|
|
189
189
|
portal container the dialogs/selects render into.
|
|
190
190
|
|
|
191
|
-
## Domain components — `/workers`, `/devcontainer`, `/projects`, `/tasks
|
|
191
|
+
## Domain components — `/workers`, `/devcontainer`, `/projects`, `/tasks`
|
|
192
192
|
|
|
193
193
|
Everything above is domain-free: a `Button` knows nothing about Spunto. Components
|
|
194
194
|
that **do** know a Spunto concept live behind their own entry point, so the root
|
|
@@ -202,7 +202,6 @@ import { WorkerCard } from "@spunto/design-system/workers"
|
|
|
202
202
|
import { ImageCard, FeatureCard, ExtensionCard } from "@spunto/design-system/devcontainer" // domain
|
|
203
203
|
import { ProjectForm, ProjectPanel } from "@spunto/design-system/projects" // domain
|
|
204
204
|
import { TaskList, TaskCockpit, TaskEventStream } from "@spunto/design-system/tasks" // domain
|
|
205
|
-
import { SpanWaterfall, TracesOverview } from "@spunto/design-system/observability" // domain
|
|
206
205
|
import { Section, ProductHeader } from "@spunto/design-system/marketing" // not a domain — see below
|
|
207
206
|
```
|
|
208
207
|
|
|
@@ -343,36 +342,6 @@ review. Every surface that shows one:
|
|
|
343
342
|
Same rules as `/workers`: nothing fetches, types are structural and lax
|
|
344
343
|
(`TaskItem`, `TaskEvent`, `TaskDiff`…), links go through `render.link`.
|
|
345
344
|
|
|
346
|
-
### `@spunto/design-system/observability`
|
|
347
|
-
|
|
348
|
-
Traces — what an OpenTelemetry backend hands back, drawn. Every surface that shows one:
|
|
349
|
-
|
|
350
|
-
- **`SpanWaterfall`** — a trace as a tree of spans on a shared time axis (children under
|
|
351
|
-
their parent, not the backend's start-time order), colour by nature (http → build, db →
|
|
352
|
-
ship, agent RPC / job → run, error → destructive), attributes of the clicked span. Any
|
|
353
|
-
span with children folds (chevron, Collapse/Expand all, ←/→; a folded row shows `+N`, red
|
|
354
|
-
when an error is hidden under it; `defaultCollapsedDepth`, or controlled
|
|
355
|
-
`collapsedSpanIds`). Hand it `logs` and a Logs section appears underneath, linked by the
|
|
356
|
-
span id the logger stamped: a line selects its span, unfolding its ancestors if needed.
|
|
357
|
-
`SpanWaterfallSkeleton` for the fetch.
|
|
358
|
-
- **`TraceList`** — one row per request (method, route, latency bar, when), or
|
|
359
|
-
`variant="compact"` for root spans that aren't necessarily HTTP. **`TraceFiltersBar`** next
|
|
360
|
-
to it: window and min latency are meant for the backend query, status / method / route are
|
|
361
|
-
applied client-side by `filterTraces`; `traceFilterOptions` derives the select options.
|
|
362
|
-
- **`TracesOverview`** — stat tiles, requests and p95 over time, per-service cards
|
|
363
|
-
(`showServices`), slowest routes. **`TraceRouteDetail`** — one route's stats and example
|
|
364
|
-
traces. Both are *derived* from the traces they're handed, so a list and its dashboard
|
|
365
|
-
can't disagree and no aggregation endpoint is needed.
|
|
366
|
-
- **`LogLines`** — log records with severity and trace/span ids: under a waterfall
|
|
367
|
-
(`origin`, `onSelectSpan`) or as a service's feed (`onOpenTrace`).
|
|
368
|
-
- Pure helpers: `computeStats`, `byRoute`, `byService`, `timeBuckets`, `exampleTraces`,
|
|
369
|
-
`percentile`, `methodOf`/`routeOf`, `orderSpans`, `spanColor`; and **one** latency scale —
|
|
370
|
-
`formatLatency` (sub-millisecond precise), `latencyTone`/`latencyColor`/`latencyTextClass`.
|
|
371
|
-
|
|
372
|
-
Same rules as `/workers`: nothing fetches (no URL, no query client — the org's traces view,
|
|
373
|
-
a deployment's Observability tab and the admin each pass their own data), types are
|
|
374
|
-
structural and lax (`TraceItem`, `TraceSpan`, `TelemetryLogLine`).
|
|
375
|
-
|
|
376
345
|
### `@spunto/design-system/projects`
|
|
377
346
|
|
|
378
347
|
- **`ProjectForm`** — the whole "compose a dev environment" screen: identity,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spunto/design-system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.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",
|
|
@@ -45,10 +45,6 @@
|
|
|
45
45
|
"types": "./src/components/tasks/index.ts",
|
|
46
46
|
"import": "./src/components/tasks/index.ts"
|
|
47
47
|
},
|
|
48
|
-
"./observability": {
|
|
49
|
-
"types": "./src/components/observability/index.ts",
|
|
50
|
-
"import": "./src/components/observability/index.ts"
|
|
51
|
-
},
|
|
52
48
|
"./projects": {
|
|
53
49
|
"types": "./src/components/projects/index.ts",
|
|
54
50
|
"import": "./src/components/projects/index.ts"
|
|
@@ -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
|
-
|
|
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 ||
|
|
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={
|
|
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
|
-
(
|
|
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={
|
|
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
|
-
|
|
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="
|
|
379
|
-
<div className="rounded-lg border border-
|
|
380
|
-
<p className="whitespace-pre-wrap break-words text-sm leading-6
|
|
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
|
|
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
|
-
}
|
|
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")
|
|
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: "
|
|
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
|
+
})
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
// Client-side aggregations over a set of traces. Everything is derived from the list a backend
|
|
2
|
-
// already returned, so a list and its dashboard stay driven by exactly the same filters — and the
|
|
3
|
-
// dashboard never needs an endpoint of its own. Pure functions: no Date.now() unless defaulted.
|
|
4
|
-
|
|
5
|
-
import type { TraceItem } from "./types"
|
|
6
|
-
|
|
7
|
-
const METHODS = ["GET", "POST", "PATCH", "PUT", "DELETE", "HEAD", "OPTIONS"]
|
|
8
|
-
|
|
9
|
-
/** HTTP method of a root span name ("GET /x" → "GET"), "—" when it isn't one. */
|
|
10
|
-
export function methodOf(name: string): string {
|
|
11
|
-
const m = name.split(" ")[0]
|
|
12
|
-
return METHODS.includes(m) ? m : "—"
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Route template of a root span name ("GET /x" → "/x"); non-HTTP names come back whole. */
|
|
16
|
-
export function routeOf(name: string): string {
|
|
17
|
-
const m = name.split(" ")[0]
|
|
18
|
-
return METHODS.includes(m) ? name.slice(m.length + 1) || name : name
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Percentile, linear interpolation, over an ascending-sorted array. */
|
|
22
|
-
export function percentile(sortedAsc: number[], p: number): number {
|
|
23
|
-
if (sortedAsc.length === 0) return 0
|
|
24
|
-
if (sortedAsc.length === 1) return sortedAsc[0]
|
|
25
|
-
const idx = (p / 100) * (sortedAsc.length - 1)
|
|
26
|
-
const lo = Math.floor(idx)
|
|
27
|
-
const hi = Math.ceil(idx)
|
|
28
|
-
if (lo === hi) return sortedAsc[lo]
|
|
29
|
-
return sortedAsc[lo] + (sortedAsc[hi] - sortedAsc[lo]) * (idx - lo)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface TraceStats {
|
|
33
|
-
count: number
|
|
34
|
-
errorCount: number
|
|
35
|
-
errorRate: number
|
|
36
|
-
p50: number
|
|
37
|
-
p95: number
|
|
38
|
-
p99: number
|
|
39
|
-
max: number
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function computeStats(traces: TraceItem[]): TraceStats {
|
|
43
|
-
const durations = traces.map((t) => t.durationMs).sort((a, b) => a - b)
|
|
44
|
-
const errorCount = traces.filter((t) => t.error).length
|
|
45
|
-
return {
|
|
46
|
-
count: traces.length,
|
|
47
|
-
errorCount,
|
|
48
|
-
errorRate: traces.length ? errorCount / traces.length : 0,
|
|
49
|
-
p50: percentile(durations, 50),
|
|
50
|
-
p95: percentile(durations, 95),
|
|
51
|
-
p99: percentile(durations, 99),
|
|
52
|
-
max: durations.length ? durations[durations.length - 1] : 0,
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function groupBy(traces: TraceItem[], key: (t: TraceItem) => string): Map<string, TraceItem[]> {
|
|
57
|
-
const groups = new Map<string, TraceItem[]>()
|
|
58
|
-
for (const t of traces) {
|
|
59
|
-
const k = key(t)
|
|
60
|
-
const arr = groups.get(k)
|
|
61
|
-
if (arr) arr.push(t)
|
|
62
|
-
else groups.set(k, [t])
|
|
63
|
-
}
|
|
64
|
-
return groups
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface RouteStat {
|
|
68
|
-
/** Full root span name ("GET /api/orgs/:orgId/…") — the grouping key. */
|
|
69
|
-
name: string
|
|
70
|
-
route: string
|
|
71
|
-
method: string
|
|
72
|
-
count: number
|
|
73
|
-
p50: number
|
|
74
|
-
p95: number
|
|
75
|
-
p99: number
|
|
76
|
-
errorRate: number
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Per route (method + template), slowest p95 first. */
|
|
80
|
-
export function byRoute(traces: TraceItem[]): RouteStat[] {
|
|
81
|
-
const rows: RouteStat[] = []
|
|
82
|
-
for (const [name, items] of groupBy(traces, (t) => t.name)) {
|
|
83
|
-
const s = computeStats(items)
|
|
84
|
-
rows.push({ name, route: routeOf(name), method: methodOf(name), count: s.count, p50: s.p50, p95: s.p95, p99: s.p99, errorRate: s.errorRate })
|
|
85
|
-
}
|
|
86
|
-
return rows.sort((a, b) => b.p95 - a.p95)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface ServiceStat {
|
|
90
|
-
service: string
|
|
91
|
-
count: number
|
|
92
|
-
errorRate: number
|
|
93
|
-
p95: number
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Per emitting service, busiest first. A trace without a service lands in "(unknown)". */
|
|
97
|
-
export function byService(traces: TraceItem[]): ServiceStat[] {
|
|
98
|
-
const rows: ServiceStat[] = []
|
|
99
|
-
for (const [service, items] of groupBy(traces, (t) => t.service || "(unknown)")) {
|
|
100
|
-
const s = computeStats(items)
|
|
101
|
-
rows.push({ service, count: s.count, errorRate: s.errorRate, p95: s.p95 })
|
|
102
|
-
}
|
|
103
|
-
return rows.sort((a, b) => b.count - a.count)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export interface TimeBucket {
|
|
107
|
-
start: number
|
|
108
|
-
total: number
|
|
109
|
-
errors: number
|
|
110
|
-
p95: number
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Splits the traces into `bucketCount` equal intervals over the last `lookbackMinutes`, ending at
|
|
115
|
-
* `now`. A trace outside the window is clamped into the first/last bucket rather than dropped:
|
|
116
|
-
* the list next to the chart shows it, so the chart must count it.
|
|
117
|
-
*/
|
|
118
|
-
export function timeBuckets(
|
|
119
|
-
traces: TraceItem[],
|
|
120
|
-
lookbackMinutes: number,
|
|
121
|
-
bucketCount = 24,
|
|
122
|
-
now: number = Date.now()
|
|
123
|
-
): TimeBucket[] {
|
|
124
|
-
const windowMs = lookbackMinutes * 60_000
|
|
125
|
-
const start = now - windowMs
|
|
126
|
-
const size = windowMs / bucketCount
|
|
127
|
-
const buckets = Array.from({ length: bucketCount }, (_, i) => ({ start: start + i * size, items: [] as TraceItem[] }))
|
|
128
|
-
for (const t of traces) {
|
|
129
|
-
const i = Math.min(bucketCount - 1, Math.max(0, Math.floor((t.startTimeMs - start) / size)))
|
|
130
|
-
buckets[i].items.push(t)
|
|
131
|
-
}
|
|
132
|
-
return buckets.map((b) => {
|
|
133
|
-
const s = computeStats(b.items)
|
|
134
|
-
return { start: b.start, total: s.count, errors: s.errorCount, p95: s.p95 }
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Up to `limit` example traces for a set: errors first, then the slowest, then the most recent,
|
|
140
|
-
* de-duplicated. What a route's detail shows to click into.
|
|
141
|
-
*/
|
|
142
|
-
export function exampleTraces(traces: TraceItem[], limit = 12): TraceItem[] {
|
|
143
|
-
const slowest = [...traces].sort((a, b) => b.durationMs - a.durationMs).slice(0, Math.ceil(limit / 2))
|
|
144
|
-
const recent = [...traces].sort((a, b) => b.startTimeMs - a.startTimeMs).slice(0, Math.ceil(limit / 2))
|
|
145
|
-
const seen = new Set<string>()
|
|
146
|
-
return [...traces.filter((t) => t.error), ...slowest, ...recent]
|
|
147
|
-
.filter((t) => {
|
|
148
|
-
if (seen.has(t.traceId)) return false
|
|
149
|
-
seen.add(t.traceId)
|
|
150
|
-
return true
|
|
151
|
-
})
|
|
152
|
-
.slice(0, limit)
|
|
153
|
-
}
|