@oh-my-pi/omp-stats 18.16.0 → 18.17.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/CHANGELOG.md +7 -0
- package/dist/client/index.css +1 -1
- package/dist/client/index.js +102 -99
- package/dist/types/client/api.d.ts +4 -1
- package/dist/types/client/app/nav.d.ts +1 -1
- package/dist/types/client/charts/Chart.d.ts +16 -8
- package/dist/types/client/charts/DotWhisker.d.ts +50 -0
- package/dist/types/client/charts/Sparkline.d.ts +1 -1
- package/dist/types/client/charts/Waterfall.d.ts +26 -0
- package/dist/types/client/charts/index.d.ts +2 -0
- package/dist/types/client/charts/types.d.ts +8 -2
- package/dist/types/client/routes/SpotlightRoute.d.ts +7 -0
- package/dist/types/client/routes/index.d.ts +1 -0
- package/dist/types/client/spotlight/Compounding.d.ts +8 -0
- package/dist/types/client/spotlight/Coverage.d.ts +6 -0
- package/dist/types/client/spotlight/Economics.d.ts +10 -0
- package/dist/types/client/spotlight/FetchBack.d.ts +9 -0
- package/dist/types/client/spotlight/Hero.d.ts +12 -0
- package/dist/types/client/spotlight/Overhead.d.ts +6 -0
- package/dist/types/client/spotlight/Ranking.d.ts +6 -0
- package/dist/types/client/spotlight/ResultsFeed.d.ts +6 -0
- package/dist/types/client/spotlight/Savings.d.ts +10 -0
- package/dist/types/client/spotlight/ShareTrend.d.ts +8 -0
- package/dist/types/client/spotlight/Steps.d.ts +6 -0
- package/dist/types/client/spotlight/TimeCost.d.ts +6 -0
- package/dist/types/client/spotlight/chips.d.ts +16 -0
- package/dist/types/client/spotlight/meta.d.ts +64 -0
- package/dist/types/db.d.ts +26 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/parser.d.ts +4 -0
- package/dist/types/rollup.d.ts +22 -1
- package/dist/types/shared-types.d.ts +419 -0
- package/dist/types/spotlight-aggregator.d.ts +189 -0
- package/dist/types/spotlight-bootstrap.d.ts +32 -0
- package/dist/types/spotlight-ingest.d.ts +258 -0
- package/dist/types/spotlight-measures.d.ts +51 -0
- package/package.json +5 -5
- package/src/aggregator.ts +3 -1
- package/src/client/App.tsx +3 -0
- package/src/client/api.ts +21 -0
- package/src/client/app/nav.ts +4 -1
- package/src/client/charts/Chart.tsx +105 -22
- package/src/client/charts/DotWhisker.tsx +149 -0
- package/src/client/charts/Sparkline.tsx +3 -2
- package/src/client/charts/Waterfall.tsx +86 -0
- package/src/client/charts/index.ts +2 -0
- package/src/client/charts/types.ts +9 -2
- package/src/client/react-css.d.ts +1 -1
- package/src/client/routes/SpotlightRoute.tsx +138 -0
- package/src/client/routes/index.ts +1 -0
- package/src/client/spotlight/Compounding.tsx +222 -0
- package/src/client/spotlight/Coverage.tsx +96 -0
- package/src/client/spotlight/Economics.tsx +167 -0
- package/src/client/spotlight/FetchBack.tsx +222 -0
- package/src/client/spotlight/Hero.tsx +177 -0
- package/src/client/spotlight/Overhead.tsx +135 -0
- package/src/client/spotlight/Ranking.tsx +248 -0
- package/src/client/spotlight/ResultsFeed.tsx +354 -0
- package/src/client/spotlight/Savings.tsx +355 -0
- package/src/client/spotlight/ShareTrend.tsx +103 -0
- package/src/client/spotlight/Steps.tsx +225 -0
- package/src/client/spotlight/TimeCost.tsx +64 -0
- package/src/client/spotlight/chips.tsx +63 -0
- package/src/client/spotlight/meta.ts +206 -0
- package/src/client/spotlight/spotlight.css +1387 -0
- package/src/client/styles.css +289 -1
- package/src/db.ts +480 -2
- package/src/index.ts +10 -1
- package/src/live.ts +21 -9
- package/src/parser.ts +44 -8
- package/src/rollup.ts +203 -10
- package/src/server.ts +42 -0
- package/src/shared-types.ts +453 -0
- package/src/spotlight-aggregator.ts +1738 -0
- package/src/spotlight-bootstrap.ts +110 -0
- package/src/spotlight-ingest.ts +981 -0
- package/src/spotlight-measures.ts +667 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { CornerDownRight, Scissors } from "lucide-react";
|
|
2
|
+
import { useCallback, useMemo, useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
formatCompact,
|
|
5
|
+
formatCost,
|
|
6
|
+
formatDurationMs,
|
|
7
|
+
formatElapsed,
|
|
8
|
+
formatInteger,
|
|
9
|
+
formatRelativeTime,
|
|
10
|
+
formatTimestamp,
|
|
11
|
+
} from "../data/formatters";
|
|
12
|
+
import type { SpotlightRecoveryKind, SpotlightResultRow } from "../types";
|
|
13
|
+
import { Badge, Card, type Column, Drawer, KeyValues, Table } from "../ui";
|
|
14
|
+
import { KindBadge } from "./chips";
|
|
15
|
+
import { formatSignedCompact, RECOVERY_KIND, RECOVERY_KINDS, toolIcon } from "./meta";
|
|
16
|
+
|
|
17
|
+
function rowKey(row: SpotlightResultRow): string {
|
|
18
|
+
return `${row.sessionFile}\u0000${row.toolCallId}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function NetCell({ value }: { value: number }) {
|
|
22
|
+
return (
|
|
23
|
+
<span className={value < 0 ? "num tone-bad" : value > 0 ? "num tone-ok" : "num"}>
|
|
24
|
+
{formatSignedCompact(value)}
|
|
25
|
+
</span>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Plain → out with a bar of what survived the cut (would have, when held out). */
|
|
30
|
+
function ShrinkCell({ row }: { row: SpotlightResultRow }) {
|
|
31
|
+
const { plainTokens, outTokens } = row;
|
|
32
|
+
const kept = plainTokens > 0 ? Math.min(1, outTokens / plainTokens) : 1;
|
|
33
|
+
return (
|
|
34
|
+
<div
|
|
35
|
+
className="spot-shrink"
|
|
36
|
+
data-holdout={row.holdout}
|
|
37
|
+
title={`plain would show ${formatInteger(plainTokens)} tokens, the cut ${row.holdout ? "would show" : "showed"} ${formatInteger(outTokens)} (shaping read ${formatInteger(row.inTokens)})`}
|
|
38
|
+
>
|
|
39
|
+
<span className="num">
|
|
40
|
+
{formatCompact(plainTokens)}
|
|
41
|
+
<span className="dim"> → </span>
|
|
42
|
+
{formatCompact(outTokens)}
|
|
43
|
+
</span>
|
|
44
|
+
<span className="spot-shrink-bar" aria-hidden="true">
|
|
45
|
+
<span className="spot-shrink-kept" style={{ width: `${kept * 100}%` }} />
|
|
46
|
+
</span>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function kindCounts(row: SpotlightResultRow): [SpotlightRecoveryKind, number][] {
|
|
52
|
+
const counts = new Map<SpotlightRecoveryKind, number>();
|
|
53
|
+
for (const r of row.recoveries) counts.set(r.kind, (counts.get(r.kind) ?? 0) + 1);
|
|
54
|
+
return RECOVERY_KINDS.flatMap(kind => {
|
|
55
|
+
const count = counts.get(kind);
|
|
56
|
+
return count ? [[kind, count]] : [];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const COLUMNS: Column<SpotlightResultRow>[] = [
|
|
61
|
+
{
|
|
62
|
+
key: "target",
|
|
63
|
+
header: "Result",
|
|
64
|
+
width: "40%",
|
|
65
|
+
sort: row => row.timestamp,
|
|
66
|
+
render: row => {
|
|
67
|
+
const Icon = toolIcon(row.tool);
|
|
68
|
+
return (
|
|
69
|
+
<div className="spot-result">
|
|
70
|
+
<span className="spot-tool" title={row.tool}>
|
|
71
|
+
<Icon size={14} aria-hidden="true" />
|
|
72
|
+
<span className="sr-only">{row.tool}</span>
|
|
73
|
+
</span>
|
|
74
|
+
<div className="stack spot-result-text">
|
|
75
|
+
<span className="spot-target truncate" title={row.target}>
|
|
76
|
+
{row.target}
|
|
77
|
+
</span>
|
|
78
|
+
<span className="row spot-result-meta">
|
|
79
|
+
{row.holdout && <HoldoutBadge />}
|
|
80
|
+
{row.scoreFree && <ScoreFreeBadge />}
|
|
81
|
+
<span className="dim" title={formatTimestamp(row.timestamp)}>
|
|
82
|
+
{formatRelativeTime(row.timestamp)}
|
|
83
|
+
</span>
|
|
84
|
+
</span>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
key: "shrink",
|
|
92
|
+
header: "Plain → out",
|
|
93
|
+
align: "right",
|
|
94
|
+
sort: row => (row.plainTokens > 0 ? row.outTokens / row.plainTokens : 1),
|
|
95
|
+
title: "What pi would have shown unshaped (plain) for the call, and what the cut showed; the bar is the share that survived",
|
|
96
|
+
render: row => <ShrinkCell row={row} />,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
key: "saved",
|
|
100
|
+
header: "Saved",
|
|
101
|
+
align: "right",
|
|
102
|
+
sort: row => row.savedTokens,
|
|
103
|
+
render: row =>
|
|
104
|
+
row.holdout ? (
|
|
105
|
+
<span className="spot-would-save" title="Held out: what the cut would have saved">
|
|
106
|
+
<span className="dim">would save </span>
|
|
107
|
+
<span className="num">{formatSignedCompact(row.savedTokens)}</span>
|
|
108
|
+
</span>
|
|
109
|
+
) : (
|
|
110
|
+
<span className="num">{formatSignedCompact(row.savedTokens)}</span>
|
|
111
|
+
),
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
key: "hidden",
|
|
115
|
+
header: "Hidden lines",
|
|
116
|
+
align: "right",
|
|
117
|
+
sort: row => row.hiddenLines,
|
|
118
|
+
render: row =>
|
|
119
|
+
row.hiddenLines > 0 ? (
|
|
120
|
+
<span className="num">{formatInteger(row.hiddenLines)}</span>
|
|
121
|
+
) : (
|
|
122
|
+
<span className="dim">–</span>
|
|
123
|
+
),
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
key: "recoveries",
|
|
127
|
+
header: "Fetched back",
|
|
128
|
+
sort: row => row.recoveries.length,
|
|
129
|
+
render: row => {
|
|
130
|
+
const counts = kindCounts(row);
|
|
131
|
+
return counts.length === 0 ? (
|
|
132
|
+
<span className="dim" title="Nothing fetched back">
|
|
133
|
+
–
|
|
134
|
+
</span>
|
|
135
|
+
) : (
|
|
136
|
+
<span className="row spot-kinds">
|
|
137
|
+
{counts.map(([kind, count]) => (
|
|
138
|
+
<KindBadge key={kind} kind={kind} count={count} />
|
|
139
|
+
))}
|
|
140
|
+
</span>
|
|
141
|
+
);
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
key: "net",
|
|
146
|
+
header: "Net",
|
|
147
|
+
align: "right",
|
|
148
|
+
sort: row => row.netTokens,
|
|
149
|
+
title: "Saved tokens minus the tokens of the calls that fetched hidden output back",
|
|
150
|
+
render: row =>
|
|
151
|
+
row.holdout ? (
|
|
152
|
+
<span className="dim" title="Held out: the model saw the whole result, so nothing was saved">
|
|
153
|
+
–
|
|
154
|
+
</span>
|
|
155
|
+
) : (
|
|
156
|
+
<NetCell value={row.netTokens} />
|
|
157
|
+
),
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
function HoldoutBadge() {
|
|
162
|
+
return (
|
|
163
|
+
<span title="Held out at random: the model saw the original, unshortened result">
|
|
164
|
+
<Badge>held out</Badge>
|
|
165
|
+
</span>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function ScoreFreeBadge() {
|
|
170
|
+
return (
|
|
171
|
+
<span title="A random coin skipped Spotlight: the no-score fallback rules made this cut">
|
|
172
|
+
<Badge>score-free</Badge>
|
|
173
|
+
</span>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The 60 newest shortened results; a row opens its recovery timeline. */
|
|
178
|
+
export function ResultsFeed({ rows, stale }: { rows: readonly SpotlightResultRow[]; stale: boolean }) {
|
|
179
|
+
const [selected, setSelected] = useState<string | null>(null);
|
|
180
|
+
const close = useCallback(() => setSelected(null), []);
|
|
181
|
+
const current = useMemo(() => rows.find(row => rowKey(row) === selected) ?? null, [rows, selected]);
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<>
|
|
185
|
+
<Card
|
|
186
|
+
index={6}
|
|
187
|
+
title="Recent results"
|
|
188
|
+
description="The newest shortened and held-out tool results and what the agent fetched back"
|
|
189
|
+
flush
|
|
190
|
+
stale={stale}
|
|
191
|
+
footer="Saved is what plain would have shown minus what the cut showed (the would-be cut for held-out ones, which save nothing); recovery tokens are the recovery calls' results (chars ÷ 4 when no exact count exists)."
|
|
192
|
+
>
|
|
193
|
+
<Table
|
|
194
|
+
rows={rows}
|
|
195
|
+
rowKey={rowKey}
|
|
196
|
+
columns={COLUMNS}
|
|
197
|
+
onRowClick={row => setSelected(rowKey(row))}
|
|
198
|
+
selectedKey={selected}
|
|
199
|
+
limit={15}
|
|
200
|
+
empty={<div className="empty">No shortened or held-out results in this range.</div>}
|
|
201
|
+
/>
|
|
202
|
+
</Card>
|
|
203
|
+
<RecoveryDrawer row={current} onClose={close} />
|
|
204
|
+
</>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function RecoveryDrawer({ row, onClose }: { row: SpotlightResultRow | null; onClose: () => void }) {
|
|
209
|
+
if (row === null) return null;
|
|
210
|
+
const Icon = toolIcon(row.tool);
|
|
211
|
+
const recovered = row.savedTokens - row.netTokens;
|
|
212
|
+
return (
|
|
213
|
+
<Drawer
|
|
214
|
+
open
|
|
215
|
+
onClose={onClose}
|
|
216
|
+
width={600}
|
|
217
|
+
title={
|
|
218
|
+
<span className="spot-drawer-title" title={row.target}>
|
|
219
|
+
{row.target}
|
|
220
|
+
</span>
|
|
221
|
+
}
|
|
222
|
+
subtitle={
|
|
223
|
+
<span className="row spot-drawer-subtitle">
|
|
224
|
+
<Icon size={13} aria-hidden="true" />
|
|
225
|
+
{row.tool}
|
|
226
|
+
{row.holdout && <HoldoutBadge />}
|
|
227
|
+
{row.scoreFree && <ScoreFreeBadge />}
|
|
228
|
+
<span>{formatTimestamp(row.timestamp)}</span>
|
|
229
|
+
</span>
|
|
230
|
+
}
|
|
231
|
+
>
|
|
232
|
+
<div className="spot-drawer-summary">
|
|
233
|
+
<div>
|
|
234
|
+
<div className="spot-eyebrow">{row.holdout ? "Would save" : "Saved"}</div>
|
|
235
|
+
<div className="spot-drawer-figure num">{formatSignedCompact(row.savedTokens)}</div>
|
|
236
|
+
</div>
|
|
237
|
+
<div>
|
|
238
|
+
<div className="spot-eyebrow">Fetched back</div>
|
|
239
|
+
<div className={recovered > 0 ? "spot-drawer-figure num tone-warn" : "spot-drawer-figure num"}>
|
|
240
|
+
{formatCompact(recovered)}
|
|
241
|
+
</div>
|
|
242
|
+
</div>
|
|
243
|
+
<div>
|
|
244
|
+
<div className="spot-eyebrow">Net</div>
|
|
245
|
+
{row.holdout ? (
|
|
246
|
+
<div className="spot-drawer-figure dim" title="Held out: the model saw the whole result">
|
|
247
|
+
–
|
|
248
|
+
</div>
|
|
249
|
+
) : (
|
|
250
|
+
<div
|
|
251
|
+
className={
|
|
252
|
+
row.netTokens < 0 ? "spot-drawer-figure num tone-bad" : "spot-drawer-figure num tone-ok"
|
|
253
|
+
}
|
|
254
|
+
>
|
|
255
|
+
{formatSignedCompact(row.netTokens)}
|
|
256
|
+
</div>
|
|
257
|
+
)}
|
|
258
|
+
</div>
|
|
259
|
+
</div>
|
|
260
|
+
|
|
261
|
+
<KeyValues
|
|
262
|
+
items={[
|
|
263
|
+
{ key: "plain", label: "Plain would show", value: formatInteger(row.plainTokens) },
|
|
264
|
+
{ key: "out", label: "Tokens out", value: formatInteger(row.outTokens) },
|
|
265
|
+
{ key: "in", label: "Full output read", value: formatInteger(row.inTokens) },
|
|
266
|
+
{
|
|
267
|
+
key: "hidden",
|
|
268
|
+
label: row.holdout ? "Lines it would hide" : "Hidden lines",
|
|
269
|
+
value: formatInteger(row.hiddenLines),
|
|
270
|
+
},
|
|
271
|
+
{ key: "steps", label: "Steps", value: row.steps.length > 0 ? row.steps.join(" → ") : "–" },
|
|
272
|
+
{ key: "cost", label: "Spotlight cost", value: formatCost(row.spotlightUsd) },
|
|
273
|
+
{ key: "ms", label: "Shaping time", value: formatDurationMs(row.shapeMs) },
|
|
274
|
+
]}
|
|
275
|
+
/>
|
|
276
|
+
|
|
277
|
+
<div>
|
|
278
|
+
<div className="section-label">Call</div>
|
|
279
|
+
<pre className="code-block spot-drawer-call">{row.target}</pre>
|
|
280
|
+
</div>
|
|
281
|
+
|
|
282
|
+
<div>
|
|
283
|
+
<div className="section-label">Recovery timeline</div>
|
|
284
|
+
<ol className="spot-timeline">
|
|
285
|
+
<li className="spot-timeline-item" data-kind={row.holdout ? "holdout" : "cut"}>
|
|
286
|
+
<span className="spot-timeline-node" aria-hidden="true">
|
|
287
|
+
<Scissors size={12} />
|
|
288
|
+
</span>
|
|
289
|
+
<div className="spot-timeline-body">
|
|
290
|
+
<div className="row spot-timeline-head">
|
|
291
|
+
<span className="cell-primary">
|
|
292
|
+
{row.holdout ? "Held out: the model saw the original" : "Shortened"}
|
|
293
|
+
</span>
|
|
294
|
+
<span className="dim num">
|
|
295
|
+
{row.holdout && "would be "}
|
|
296
|
+
{formatCompact(row.plainTokens)} → {formatCompact(row.outTokens)} tokens
|
|
297
|
+
{row.hiddenLines > 0 && `, ${formatInteger(row.hiddenLines)} lines hidden`}
|
|
298
|
+
</span>
|
|
299
|
+
</div>
|
|
300
|
+
</div>
|
|
301
|
+
</li>
|
|
302
|
+
{row.recoveries.map(r => (
|
|
303
|
+
<li
|
|
304
|
+
key={r.toolCallId}
|
|
305
|
+
className="spot-timeline-item"
|
|
306
|
+
data-kind={r.kind}
|
|
307
|
+
style={{ "--kind": RECOVERY_KIND[r.kind].color }}
|
|
308
|
+
>
|
|
309
|
+
<span className="spot-timeline-node" aria-hidden="true">
|
|
310
|
+
<CornerDownRight size={12} />
|
|
311
|
+
</span>
|
|
312
|
+
<div className="spot-timeline-body">
|
|
313
|
+
<div className="row spot-timeline-head">
|
|
314
|
+
<KindBadge kind={r.kind} />
|
|
315
|
+
{r.turn && <Badge tone="warn">extra turn</Badge>}
|
|
316
|
+
<span className="spot-timeline-spacer" />
|
|
317
|
+
<span className="num tone-warn">+{formatCompact(r.tokens)}</span>
|
|
318
|
+
</div>
|
|
319
|
+
<code className="spot-timeline-target" title={r.target}>
|
|
320
|
+
<span className="dim">{r.tool} </span>
|
|
321
|
+
{r.target}
|
|
322
|
+
</code>
|
|
323
|
+
<div className="micro">
|
|
324
|
+
{r.after === 0
|
|
325
|
+
? "The next call"
|
|
326
|
+
: `${formatInteger(r.after)} ${r.after === 1 ? "call" : "calls"} later`}
|
|
327
|
+
{` · ${formatElapsed(Math.max(0, r.timestamp - row.timestamp))} after the cut`}
|
|
328
|
+
</div>
|
|
329
|
+
</div>
|
|
330
|
+
</li>
|
|
331
|
+
))}
|
|
332
|
+
<li className="spot-timeline-item" data-kind="net">
|
|
333
|
+
<span className="spot-timeline-node" aria-hidden="true" />
|
|
334
|
+
<div className="spot-timeline-body">
|
|
335
|
+
<div className="row spot-timeline-head">
|
|
336
|
+
<span className="cell-primary">
|
|
337
|
+
{row.holdout
|
|
338
|
+
? row.recoveries.length === 0
|
|
339
|
+
? "Nothing fetched back"
|
|
340
|
+
: "Fetched more although it saw everything"
|
|
341
|
+
: row.recoveries.length === 0
|
|
342
|
+
? "Nothing fetched back: the full saving stands"
|
|
343
|
+
: "Net"}
|
|
344
|
+
</span>
|
|
345
|
+
<span className="spot-timeline-spacer" />
|
|
346
|
+
{row.holdout ? <span className="dim">saves nothing</span> : <NetCell value={row.netTokens} />}
|
|
347
|
+
</div>
|
|
348
|
+
</div>
|
|
349
|
+
</li>
|
|
350
|
+
</ol>
|
|
351
|
+
</div>
|
|
352
|
+
</Drawer>
|
|
353
|
+
);
|
|
354
|
+
}
|