@linxiraos/pi-stats 1.4.6 → 1.4.7
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/CHANGELOG.md +11 -1
- package/README.md +18 -18
- package/dist/client/index.js +78 -78
- package/dist/types/chunked-insert.d.ts +32 -0
- package/dist/types/client/traces/SpanDrawer.d.ts +9 -3
- package/dist/types/client/traces/TimelineCanvas.d.ts +3 -1
- package/dist/types/client/traces/TraceView.d.ts +13 -0
- package/dist/types/client/traces/index.d.ts +5 -0
- package/dist/types/client/traces/trace-colors.d.ts +3 -1
- package/dist/types/client/ui/SearchInput.d.ts +2 -1
- package/dist/types/db.d.ts +5 -5
- package/dist/types/parser.d.ts +1 -1
- package/dist/types/port-conflict.d.ts +9 -3
- package/dist/types/server.d.ts +7 -3
- package/dist/types/shared-types.d.ts +3 -2
- package/dist/types/trace.d.ts +27 -1
- package/dist/types/types.d.ts +6 -1
- package/package.json +13 -7
- package/src/chunked-insert.ts +89 -0
- package/src/client/traces/SpanDrawer.tsx +56 -9
- package/src/client/traces/TimelineCanvas.tsx +13 -4
- package/src/client/traces/TraceView.tsx +171 -153
- package/src/client/traces/index.ts +5 -0
- package/src/client/traces/trace-colors.ts +14 -10
- package/src/client/ui/SearchInput.tsx +9 -1
- package/src/db.ts +201 -150
- package/src/parser.ts +14 -5
- package/src/port-conflict.ts +67 -30
- package/src/server.ts +39 -31
- package/src/shared-types.ts +3 -2
- package/src/trace.ts +119 -35
- package/src/types.ts +6 -1
|
@@ -13,7 +13,7 @@ import type { SessionTrace, TraceSpan, TraceSpanKind, TraceTrack } from "../type
|
|
|
13
13
|
import { Card, ChartSkeleton, PageHeader, QueryView, SearchInput, Segmented } from "../ui";
|
|
14
14
|
import { AggregatesPanel } from "./AggregatesPanel";
|
|
15
15
|
import { Minimap } from "./Minimap";
|
|
16
|
-
import { SpanDrawer } from "./SpanDrawer";
|
|
16
|
+
import { SpanDrawer, type TraceEntryLoader } from "./SpanDrawer";
|
|
17
17
|
import { SummaryStrip } from "./SummaryStrip";
|
|
18
18
|
import { TimelineCanvas, type TimelineViewport } from "./TimelineCanvas";
|
|
19
19
|
import { TranscriptList } from "./TranscriptList";
|
|
@@ -49,6 +49,56 @@ export function TraceView({ file, active, onBack }: TraceViewProps) {
|
|
|
49
49
|
// A previous session's trace must never render under this file's header.
|
|
50
50
|
const trace = query.stale ? null : query.data;
|
|
51
51
|
|
|
52
|
+
return (
|
|
53
|
+
<div className="stack traces-view">
|
|
54
|
+
<div>
|
|
55
|
+
<button type="button" className="btn" data-variant="ghost" data-size="sm" onClick={onBack}>
|
|
56
|
+
<ArrowLeft size={14} aria-hidden="true" />
|
|
57
|
+
Sessions
|
|
58
|
+
</button>
|
|
59
|
+
</div>
|
|
60
|
+
<PageHeader
|
|
61
|
+
title={<span className="traces-title truncate">{trace?.title ?? file.split("/").pop()}</span>}
|
|
62
|
+
description={trace?.cwd ? <span className="mono">{trace.cwd}</span> : undefined}
|
|
63
|
+
actions={
|
|
64
|
+
<button
|
|
65
|
+
type="button"
|
|
66
|
+
className="btn"
|
|
67
|
+
data-variant="ghost"
|
|
68
|
+
data-icon="true"
|
|
69
|
+
onClick={query.refetch}
|
|
70
|
+
aria-label="Refresh trace"
|
|
71
|
+
title="Refresh trace"
|
|
72
|
+
>
|
|
73
|
+
<RefreshCw size={14} className={query.refreshing ? "traces-spin" : undefined} />
|
|
74
|
+
</button>
|
|
75
|
+
}
|
|
76
|
+
/>
|
|
77
|
+
<QueryView query={{ ...query, data: trace }} skeleton={<ChartSkeleton height={420} />}>
|
|
78
|
+
{loaded => <SessionTraceView trace={loaded} />}
|
|
79
|
+
</QueryView>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Data and host integration supplied to the shared live/offline trace viewer. */
|
|
85
|
+
export interface SessionTraceViewProps {
|
|
86
|
+
trace: SessionTrace;
|
|
87
|
+
view?: "timeline" | "full";
|
|
88
|
+
loadEntry?: TraceEntryLoader;
|
|
89
|
+
/** Embedded viewers keep details inside their own layout, without a modal. */
|
|
90
|
+
embedded?: boolean;
|
|
91
|
+
onNavigate?: (trackId: string, entryId: string) => void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Data-driven viewer shared by the live route and self-contained HTML exports. */
|
|
95
|
+
export function SessionTraceView({
|
|
96
|
+
trace,
|
|
97
|
+
view = "full",
|
|
98
|
+
loadEntry,
|
|
99
|
+
embedded = false,
|
|
100
|
+
onNavigate,
|
|
101
|
+
}: SessionTraceViewProps) {
|
|
52
102
|
const [mode, setMode] = useState<AxisMode>("time");
|
|
53
103
|
const [compressIdle, setCompressIdle] = useState(true);
|
|
54
104
|
const [selection, setSelection] = useState<string | null>(null);
|
|
@@ -220,185 +270,153 @@ export function TraceView({ file, active, onBack }: TraceViewProps) {
|
|
|
220
270
|
);
|
|
221
271
|
const closeDrawer = useCallback(() => setDrawerOpen(false), []);
|
|
222
272
|
|
|
223
|
-
const traceStart = trace
|
|
224
|
-
|
|
225
|
-
const traceQuery = { ...query, data: trace };
|
|
273
|
+
const traceStart = trace.startedAt;
|
|
226
274
|
|
|
227
275
|
return (
|
|
228
|
-
<div className="stack traces-view">
|
|
229
|
-
<
|
|
230
|
-
|
|
231
|
-
<ArrowLeft size={14} aria-hidden="true" />
|
|
232
|
-
{t("trace.sessions")}
|
|
233
|
-
</button>
|
|
234
|
-
</div>
|
|
235
|
-
<PageHeader
|
|
236
|
-
title={<span className="traces-title truncate">{trace?.title ?? file.split("/").pop()}</span>}
|
|
237
|
-
description={trace?.cwd ? <span className="mono">{trace.cwd}</span> : undefined}
|
|
238
|
-
actions={
|
|
239
|
-
<button
|
|
240
|
-
type="button"
|
|
241
|
-
className="btn"
|
|
242
|
-
data-variant="ghost"
|
|
243
|
-
data-icon="true"
|
|
244
|
-
onClick={query.refetch}
|
|
245
|
-
aria-label={t("trace.refresh")}
|
|
246
|
-
title={t("trace.refresh")}
|
|
247
|
-
>
|
|
248
|
-
<RefreshCw size={14} className={query.refreshing ? "traces-spin" : undefined} />
|
|
249
|
-
</button>
|
|
250
|
-
}
|
|
251
|
-
/>
|
|
276
|
+
<div className="stack traces-view" data-view={view}>
|
|
277
|
+
{view === "full" && <SummaryStrip summary={trace.summary} />}
|
|
278
|
+
{allSpans.length === 0 && <p className="muted">No spans recorded in this session.</p>}
|
|
252
279
|
|
|
253
|
-
<
|
|
254
|
-
{
|
|
280
|
+
<Card
|
|
281
|
+
index={1}
|
|
282
|
+
title={t("trace.timeline")}
|
|
283
|
+
description={t("trace.timeline-hint")}
|
|
284
|
+
actions={
|
|
255
285
|
<>
|
|
256
|
-
<
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
286
|
+
<button
|
|
287
|
+
type="button"
|
|
288
|
+
className="btn"
|
|
289
|
+
data-variant="ghost"
|
|
290
|
+
data-size="sm"
|
|
291
|
+
onClick={() => collapseAll(false)}
|
|
292
|
+
>
|
|
293
|
+
{t("trace.expand-all")}
|
|
294
|
+
</button>
|
|
295
|
+
<button
|
|
296
|
+
type="button"
|
|
297
|
+
className="btn"
|
|
298
|
+
data-variant="ghost"
|
|
299
|
+
data-size="sm"
|
|
300
|
+
onClick={() => collapseAll(true)}
|
|
301
|
+
>
|
|
302
|
+
{t("trace.collapse-all")}
|
|
303
|
+
</button>
|
|
304
|
+
</>
|
|
305
|
+
}
|
|
306
|
+
>
|
|
307
|
+
<div className="stack">
|
|
308
|
+
<div className="traces-toolbar">
|
|
309
|
+
<Segmented
|
|
310
|
+
options={MODE_OPTIONS}
|
|
311
|
+
value={mode}
|
|
312
|
+
onChange={setMode}
|
|
313
|
+
size="sm"
|
|
314
|
+
aria-label={t("trace.axis-mode")}
|
|
315
|
+
/>
|
|
316
|
+
{mode === "time" && (
|
|
317
|
+
<label className="traces-check">
|
|
318
|
+
<input
|
|
319
|
+
type="checkbox"
|
|
320
|
+
checked={compressIdle}
|
|
321
|
+
onChange={event => setCompressIdle(event.target.checked)}
|
|
322
|
+
/>
|
|
323
|
+
{t("trace.compress-idle")}
|
|
324
|
+
</label>
|
|
325
|
+
)}
|
|
326
|
+
<div className="traces-search">
|
|
327
|
+
<SearchInput
|
|
328
|
+
value={search}
|
|
329
|
+
onChange={value => {
|
|
330
|
+
setSearch(value);
|
|
331
|
+
setMatchIndex(0);
|
|
332
|
+
}}
|
|
333
|
+
label={t("trace.search-placeholder")}
|
|
334
|
+
placeholder={t("trace.search-placeholder")}
|
|
335
|
+
width={200}
|
|
336
|
+
/>
|
|
337
|
+
{search.trim() && (
|
|
263
338
|
<>
|
|
339
|
+
<span className="num muted traces-match-count">
|
|
340
|
+
{matches.length === 0
|
|
341
|
+
? "0"
|
|
342
|
+
: `${(matchIndex % Math.max(matches.length, 1)) + 1}/${matches.length}`}
|
|
343
|
+
</span>
|
|
264
344
|
<button
|
|
265
345
|
type="button"
|
|
266
346
|
className="btn"
|
|
267
347
|
data-variant="ghost"
|
|
268
348
|
data-size="sm"
|
|
269
|
-
|
|
349
|
+
data-icon="true"
|
|
350
|
+
onClick={() => cycleMatch(-1)}
|
|
351
|
+
aria-label={t("trace.previous-match")}
|
|
352
|
+
disabled={matches.length === 0}
|
|
270
353
|
>
|
|
271
|
-
{
|
|
354
|
+
<ChevronLeft size={14} />
|
|
272
355
|
</button>
|
|
273
356
|
<button
|
|
274
357
|
type="button"
|
|
275
358
|
className="btn"
|
|
276
359
|
data-variant="ghost"
|
|
277
360
|
data-size="sm"
|
|
278
|
-
|
|
361
|
+
data-icon="true"
|
|
362
|
+
onClick={() => cycleMatch(1)}
|
|
363
|
+
aria-label={t("trace.next-match")}
|
|
364
|
+
disabled={matches.length === 0}
|
|
279
365
|
>
|
|
280
|
-
{
|
|
366
|
+
<ChevronRight size={14} />
|
|
281
367
|
</button>
|
|
282
368
|
</>
|
|
283
|
-
}
|
|
284
|
-
>
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}}
|
|
311
|
-
placeholder={t("trace.search-placeholder")}
|
|
312
|
-
width={200}
|
|
313
|
-
/>
|
|
314
|
-
{search.trim() && (
|
|
315
|
-
<>
|
|
316
|
-
<span className="num muted traces-match-count">
|
|
317
|
-
{matches.length === 0
|
|
318
|
-
? "0"
|
|
319
|
-
: `${(matchIndex % Math.max(matches.length, 1)) + 1}/${matches.length}`}
|
|
320
|
-
</span>
|
|
321
|
-
<button
|
|
322
|
-
type="button"
|
|
323
|
-
className="btn"
|
|
324
|
-
data-variant="ghost"
|
|
325
|
-
data-size="sm"
|
|
326
|
-
data-icon="true"
|
|
327
|
-
onClick={() => cycleMatch(-1)}
|
|
328
|
-
aria-label={t("trace.previous-match")}
|
|
329
|
-
disabled={matches.length === 0}
|
|
330
|
-
>
|
|
331
|
-
<ChevronLeft size={14} />
|
|
332
|
-
</button>
|
|
333
|
-
<button
|
|
334
|
-
type="button"
|
|
335
|
-
className="btn"
|
|
336
|
-
data-variant="ghost"
|
|
337
|
-
data-size="sm"
|
|
338
|
-
data-icon="true"
|
|
339
|
-
onClick={() => cycleMatch(1)}
|
|
340
|
-
aria-label={t("trace.next-match")}
|
|
341
|
-
disabled={matches.length === 0}
|
|
342
|
-
>
|
|
343
|
-
<ChevronRight size={14} />
|
|
344
|
-
</button>
|
|
345
|
-
</>
|
|
346
|
-
)}
|
|
347
|
-
</div>
|
|
348
|
-
<div className="traces-legend">
|
|
349
|
-
{LEGEND.map(item => (
|
|
350
|
-
<span key={item.kind} className="traces-legend-item">
|
|
351
|
-
<span
|
|
352
|
-
className="swatch"
|
|
353
|
-
style={{ background: `var(${CATEGORY_VARS[item.kind]})` }}
|
|
354
|
-
/>
|
|
355
|
-
{item.label}
|
|
356
|
-
</span>
|
|
357
|
-
))}
|
|
358
|
-
</div>
|
|
359
|
-
</div>
|
|
360
|
-
<Minimap
|
|
361
|
-
tracks={tracks}
|
|
362
|
-
scale={scale}
|
|
363
|
-
viewport={effectiveViewport}
|
|
364
|
-
onViewportChange={setViewport}
|
|
365
|
-
/>
|
|
366
|
-
<TimelineCanvas
|
|
367
|
-
tracks={tracks}
|
|
368
|
-
scale={scale}
|
|
369
|
-
viewport={effectiveViewport}
|
|
370
|
-
onViewportChange={setViewport}
|
|
371
|
-
selected={selected}
|
|
372
|
-
onSelect={selectAndOpen}
|
|
373
|
-
matchIds={matchIds}
|
|
374
|
-
collapsed={collapsed}
|
|
375
|
-
onToggleCollapse={toggleCollapse}
|
|
376
|
-
traceStart={traceStart}
|
|
377
|
-
/>
|
|
378
|
-
</div>
|
|
379
|
-
</Card>
|
|
380
|
-
|
|
381
|
-
<Card index={2} title={t("trace.transcript")} description={t("trace.transcript-description")} flush>
|
|
382
|
-
<TranscriptList
|
|
383
|
-
tracks={tracks}
|
|
384
|
-
selection={selection}
|
|
385
|
-
onSelect={openFromTranscript}
|
|
386
|
-
search={search}
|
|
387
|
-
matchIds={matchIds}
|
|
388
|
-
traceStart={traceStart}
|
|
389
|
-
/>
|
|
390
|
-
</Card>
|
|
391
|
-
<AggregatesPanel toolStats={loaded.summary.toolStats} index={3} />
|
|
392
|
-
</>
|
|
393
|
-
)}
|
|
394
|
-
</QueryView>
|
|
369
|
+
)}
|
|
370
|
+
</div>
|
|
371
|
+
<div className="traces-legend">
|
|
372
|
+
{LEGEND.map(item => (
|
|
373
|
+
<span key={item.kind} className="traces-legend-item">
|
|
374
|
+
<span className="swatch" style={{ background: `var(${CATEGORY_VARS[item.kind]})` }} />
|
|
375
|
+
{item.label}
|
|
376
|
+
</span>
|
|
377
|
+
))}
|
|
378
|
+
</div>
|
|
379
|
+
</div>
|
|
380
|
+
<Minimap tracks={tracks} scale={scale} viewport={effectiveViewport} onViewportChange={setViewport} />
|
|
381
|
+
<TimelineCanvas
|
|
382
|
+
tracks={tracks}
|
|
383
|
+
scale={scale}
|
|
384
|
+
viewport={effectiveViewport}
|
|
385
|
+
onViewportChange={setViewport}
|
|
386
|
+
selected={selected}
|
|
387
|
+
onSelect={selectAndOpen}
|
|
388
|
+
matchIds={matchIds}
|
|
389
|
+
collapsed={collapsed}
|
|
390
|
+
onToggleCollapse={toggleCollapse}
|
|
391
|
+
traceStart={traceStart}
|
|
392
|
+
autoFocus={!embedded}
|
|
393
|
+
/>
|
|
394
|
+
</div>
|
|
395
|
+
</Card>
|
|
395
396
|
|
|
396
397
|
<SpanDrawer
|
|
397
398
|
span={drawerOpen ? (selected?.span ?? null) : null}
|
|
398
399
|
track={selected?.track ?? null}
|
|
399
400
|
onClose={closeDrawer}
|
|
400
401
|
onOpenChildTrack={openChildTrack}
|
|
402
|
+
loadEntry={loadEntry}
|
|
403
|
+
inline={embedded}
|
|
404
|
+
onNavigate={onNavigate}
|
|
401
405
|
/>
|
|
406
|
+
|
|
407
|
+
{view === "full" && (
|
|
408
|
+
<Card index={2} title={t("trace.transcript")} description={t("trace.transcript-description")} flush>
|
|
409
|
+
<TranscriptList
|
|
410
|
+
tracks={tracks}
|
|
411
|
+
selection={selection}
|
|
412
|
+
onSelect={openFromTranscript}
|
|
413
|
+
search={search}
|
|
414
|
+
matchIds={matchIds}
|
|
415
|
+
traceStart={traceStart}
|
|
416
|
+
/>
|
|
417
|
+
</Card>
|
|
418
|
+
)}
|
|
419
|
+
{view === "full" && <AggregatesPanel toolStats={trace.summary.toolStats} index={3} />}
|
|
402
420
|
</div>
|
|
403
421
|
);
|
|
404
422
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Shared trace UI for live dashboards and embedded offline viewers. */
|
|
2
|
+
export type { SessionTrace } from "../types";
|
|
3
|
+
export type { TraceEntryLoader } from "./SpanDrawer";
|
|
4
|
+
export { SessionTraceView, type SessionTraceViewProps } from "./TraceView";
|
|
5
|
+
export { TraceThemeRoot } from "./trace-colors";
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* design tokens so canvas drawing follows the active theme.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { useEffect, useMemo, useState } from "react";
|
|
6
|
+
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
|
7
7
|
import type { TraceSpanKind } from "../types";
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
/** Embedded viewers resolve canvas colors from their scoped style root. */
|
|
10
|
+
export const TraceThemeRoot = createContext<HTMLElement | null>(null);
|
|
9
11
|
|
|
10
12
|
export interface TraceTheme {
|
|
11
13
|
/** Span fill per category. */
|
|
@@ -42,8 +44,8 @@ export const CATEGORY_VARS: Record<TraceSpanKind, string> = {
|
|
|
42
44
|
background: "--ink-4",
|
|
43
45
|
};
|
|
44
46
|
|
|
45
|
-
function readTheme(): TraceTheme {
|
|
46
|
-
const style = getComputedStyle(
|
|
47
|
+
function readTheme(root: HTMLElement): TraceTheme {
|
|
48
|
+
const style = getComputedStyle(root);
|
|
47
49
|
const v = (name: string, fallback: string) => style.getPropertyValue(name).trim() || fallback;
|
|
48
50
|
return {
|
|
49
51
|
category: {
|
|
@@ -69,16 +71,18 @@ function readTheme(): TraceTheme {
|
|
|
69
71
|
|
|
70
72
|
/**
|
|
71
73
|
* Current trace palette. Re-reads the tokens whenever the resolved theme
|
|
72
|
-
* changes
|
|
74
|
+
* changes, without loading the live dashboard's theme preference store.
|
|
73
75
|
*/
|
|
74
76
|
export function useTraceTheme(): TraceTheme {
|
|
75
|
-
const
|
|
77
|
+
const root = useContext(TraceThemeRoot) ?? document.documentElement;
|
|
76
78
|
const [attrVersion, setAttrVersion] = useState(0);
|
|
77
79
|
useEffect(() => {
|
|
78
80
|
const observer = new MutationObserver(() => setAttrVersion(n => n + 1));
|
|
79
|
-
|
|
81
|
+
const options = { attributes: true, attributeFilter: ["data-theme", "style", "class"] };
|
|
82
|
+
observer.observe(document.documentElement, options);
|
|
83
|
+
if (root !== document.documentElement) observer.observe(root, options);
|
|
80
84
|
return () => observer.disconnect();
|
|
81
|
-
}, []);
|
|
82
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies:
|
|
83
|
-
return useMemo(readTheme, [
|
|
85
|
+
}, [root]);
|
|
86
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: attrVersion triggers a CSS token re-read.
|
|
87
|
+
return useMemo(() => readTheme(root), [root, attrVersion]);
|
|
84
88
|
}
|
|
@@ -5,17 +5,25 @@ export interface SearchInputProps {
|
|
|
5
5
|
value: string;
|
|
6
6
|
onChange: (value: string) => void;
|
|
7
7
|
placeholder?: string;
|
|
8
|
+
label?: string;
|
|
8
9
|
width?: number;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
/** Text filter with a leading search glyph. */
|
|
12
|
-
export function SearchInput({
|
|
13
|
+
export function SearchInput({
|
|
14
|
+
value,
|
|
15
|
+
onChange,
|
|
16
|
+
placeholder = t("common.filter"),
|
|
17
|
+
label = "Filter",
|
|
18
|
+
width,
|
|
19
|
+
}: SearchInputProps) {
|
|
13
20
|
return (
|
|
14
21
|
<label className="search">
|
|
15
22
|
<Search size={14} />
|
|
16
23
|
<input
|
|
17
24
|
className="input"
|
|
18
25
|
type="search"
|
|
26
|
+
aria-label={label}
|
|
19
27
|
value={value}
|
|
20
28
|
placeholder={placeholder}
|
|
21
29
|
onChange={e => onChange(e.target.value)}
|