opencode-usage-insights 0.3.0 → 0.3.1
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/dist/gui-experimental.cjs +3 -3
- package/dist/index.js +443 -260
- package/dist/index.js.map +8 -8
- package/dist/limits.d.ts +9 -0
- package/dist/panel-data.d.ts +48 -6
- package/dist/rpc.js +3 -2
- package/dist/rpc.js.map +4 -4
- package/dist/stats/aggregates.d.ts +4 -1
- package/dist/stats-worker.js +442 -259
- package/dist/stats-worker.js.map +7 -7
- package/dist/tui.js +418 -248
- package/dist/tui.js.map +5 -5
- package/docs/demo.md +1 -1
- package/docs/images/panel-cache.png +0 -0
- package/docs/images/panel-overview.png +0 -0
- package/docs/images/panel-providers.png +0 -0
- package/package.json +1 -1
package/dist/tui.js
CHANGED
|
@@ -353,6 +353,7 @@ function formatLine(stats, options) {
|
|
|
353
353
|
|
|
354
354
|
// src/limits.ts
|
|
355
355
|
var MAX_PANEL_WIDTH = 200;
|
|
356
|
+
var MAX_HISTORY_WIDTH = 120;
|
|
356
357
|
var MAX_TURNS = 50;
|
|
357
358
|
function clampPanelWidth(value) {
|
|
358
359
|
if (!Number.isFinite(value))
|
|
@@ -1226,15 +1227,6 @@ function truncateMiddle(value, width) {
|
|
|
1226
1227
|
const tail = width - 1 - head;
|
|
1227
1228
|
return `${clean.slice(0, head)}\u2026${clean.slice(clean.length - tail)}`;
|
|
1228
1229
|
}
|
|
1229
|
-
function tableWidths(width, layouts) {
|
|
1230
|
-
for (const layout of layouts) {
|
|
1231
|
-
const total = layout.reduce((sum, column) => sum + column, 0) + layout.length - 1;
|
|
1232
|
-
if (total <= width)
|
|
1233
|
-
return [...layout];
|
|
1234
|
-
}
|
|
1235
|
-
const last = layouts[layouts.length - 1];
|
|
1236
|
-
return last === undefined ? [] : [...last];
|
|
1237
|
-
}
|
|
1238
1230
|
function modelCell(modelID, variant, width) {
|
|
1239
1231
|
return truncateMiddle(variant === undefined ? modelID : `${modelID} ${variant}`, width);
|
|
1240
1232
|
}
|
|
@@ -1253,6 +1245,47 @@ function formatTableRow(cells, widths, aligns) {
|
|
|
1253
1245
|
}
|
|
1254
1246
|
return parts.join(" ");
|
|
1255
1247
|
}
|
|
1248
|
+
function fitTableColumns(columns, width) {
|
|
1249
|
+
const chosen = new Set;
|
|
1250
|
+
for (let index = 0;index < columns.length; index += 1) {
|
|
1251
|
+
if (columns[index].priority === undefined)
|
|
1252
|
+
chosen.add(index);
|
|
1253
|
+
}
|
|
1254
|
+
if (chosen.size === 0)
|
|
1255
|
+
return [];
|
|
1256
|
+
const total = () => {
|
|
1257
|
+
let sum = chosen.size - 1;
|
|
1258
|
+
for (const index of chosen)
|
|
1259
|
+
sum += columns[index].width;
|
|
1260
|
+
return sum;
|
|
1261
|
+
};
|
|
1262
|
+
const optional = columns.map((column, index) => ({ column, index })).filter((entry) => entry.column.priority !== undefined).sort((left, right) => left.column.priority - right.column.priority || left.index - right.index);
|
|
1263
|
+
for (const { column, index } of optional) {
|
|
1264
|
+
if (total() + column.width + 1 + (column.reserve ?? 0) <= width)
|
|
1265
|
+
chosen.add(index);
|
|
1266
|
+
}
|
|
1267
|
+
while (chosen.size > 1 && total() > width)
|
|
1268
|
+
chosen.delete(Math.max(...chosen));
|
|
1269
|
+
const widths = new Map;
|
|
1270
|
+
let room = width - total();
|
|
1271
|
+
for (let index = 0;index < columns.length && room > 0; index += 1) {
|
|
1272
|
+
if (!chosen.has(index))
|
|
1273
|
+
continue;
|
|
1274
|
+
const column = columns[index];
|
|
1275
|
+
const grow = Math.min(room, (column.max ?? column.width) - column.width);
|
|
1276
|
+
if (grow <= 0)
|
|
1277
|
+
continue;
|
|
1278
|
+
widths.set(index, column.width + grow);
|
|
1279
|
+
room -= grow;
|
|
1280
|
+
}
|
|
1281
|
+
return [...chosen].sort((left, right) => left - right).map((index) => ({ index, width: widths.get(index) ?? columns[index].width }));
|
|
1282
|
+
}
|
|
1283
|
+
function fitTable(columns, width) {
|
|
1284
|
+
return fitTableColumns(columns, width).map(({ index, width: fitted }) => {
|
|
1285
|
+
const column = columns[index];
|
|
1286
|
+
return { index, header: column.header, width: fitted, align: column.align ?? "left", cell: column.cell };
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1256
1289
|
function count(n, singular, plural = `${singular}s`) {
|
|
1257
1290
|
return `${formatCount(n)} ${n === 1 ? singular : plural}`;
|
|
1258
1291
|
}
|
|
@@ -1260,21 +1293,30 @@ function kvGrid(pairs, width) {
|
|
|
1260
1293
|
const lines = [];
|
|
1261
1294
|
const label = 11;
|
|
1262
1295
|
const column = Math.floor(width / 2);
|
|
1296
|
+
const pairLines = (pair) => {
|
|
1297
|
+
const text = `${padCell(pair[0], label)}${pair[1]}`;
|
|
1298
|
+
if (text.length <= width)
|
|
1299
|
+
return [text];
|
|
1300
|
+
return [padCell(pair[0], label), ` ${pair[1]}`].map((line) => truncate(line, width));
|
|
1301
|
+
};
|
|
1263
1302
|
for (let index = 0;index < pairs.length; index += 2) {
|
|
1264
1303
|
const left = pairs[index];
|
|
1265
1304
|
const right = pairs[index + 1];
|
|
1266
|
-
const leftText = `${padCell(left[0], label)}${left[1]}`;
|
|
1267
1305
|
if (right === undefined) {
|
|
1268
|
-
|
|
1306
|
+
for (const text of pairLines(left))
|
|
1307
|
+
lines.push({ text, tone: "base" });
|
|
1269
1308
|
continue;
|
|
1270
1309
|
}
|
|
1310
|
+
const leftText = `${padCell(left[0], label)}${left[1]}`;
|
|
1271
1311
|
const rightText = `${padCell(right[0], label)}${right[1]}`;
|
|
1272
1312
|
const gap = Math.max(2, column - leftText.length);
|
|
1273
1313
|
if (leftText.length + gap + rightText.length <= width) {
|
|
1274
1314
|
lines.push({ text: `${leftText}${" ".repeat(gap)}${rightText}`, tone: "base" });
|
|
1275
1315
|
} else {
|
|
1276
|
-
|
|
1277
|
-
|
|
1316
|
+
for (const text of pairLines(left))
|
|
1317
|
+
lines.push({ text, tone: "base" });
|
|
1318
|
+
for (const text of pairLines(right))
|
|
1319
|
+
lines.push({ text, tone: "base" });
|
|
1278
1320
|
}
|
|
1279
1321
|
}
|
|
1280
1322
|
return lines;
|
|
@@ -1525,14 +1567,16 @@ function overviewLines(data, width) {
|
|
|
1525
1567
|
const lines = [];
|
|
1526
1568
|
const estimates = data.estimates !== false;
|
|
1527
1569
|
lines.push({
|
|
1528
|
-
text: `${rangeLabel(data.range)} \xB7 ${count(data.usage.steps, "step")} \xB7 ${count(data.usage.sessions, "session")} \xB7 ${count(data.usage.prompts, "prompt")}`,
|
|
1570
|
+
text: truncate(`${rangeLabel(data.range)} \xB7 ${count(data.usage.steps, "step")} \xB7 ${count(data.usage.sessions, "session")} \xB7 ${count(data.usage.prompts, "prompt")}`, width),
|
|
1529
1571
|
tone: "muted"
|
|
1530
1572
|
});
|
|
1531
1573
|
lines.push(...kvGrid(buildOverviewPairs(data.usage, "all", estimates), width));
|
|
1532
1574
|
if (data.activity !== undefined && data.activity.length > 1) {
|
|
1533
|
-
const
|
|
1575
|
+
const suffix = ` ${count(data.activity.length, "bucket")}`;
|
|
1576
|
+
const bars = Math.max(4, width - "activity ".length - suffix.length);
|
|
1577
|
+
const series = reduceSeries(data.activity, bars);
|
|
1534
1578
|
lines.push({ text: "", tone: "muted" });
|
|
1535
|
-
lines.push({ text: `activity ${sparkline(series)}
|
|
1579
|
+
lines.push({ text: truncate(`activity ${sparkline(series)}${suffix}`, width), tone: "muted" });
|
|
1536
1580
|
}
|
|
1537
1581
|
if (data.session !== undefined) {
|
|
1538
1582
|
lines.push({ text: "", tone: "muted" });
|
|
@@ -1543,7 +1587,7 @@ function overviewLines(data, width) {
|
|
|
1543
1587
|
const cost = data.subagents.reduce((sum, row) => sum + row.cost, 0);
|
|
1544
1588
|
const listCost = data.subagents.reduce((sum, row) => sum + row.listCost, 0);
|
|
1545
1589
|
lines.push({
|
|
1546
|
-
text: ` subagents ${count(data.subagents.length, "session")} \xB7 ${count(steps, "step")} \xB7 ${formatSpend(cost, estimates ? listCost : 0)} (their own sessions)`,
|
|
1590
|
+
text: truncate(` subagents ${count(data.subagents.length, "session")} \xB7 ${count(steps, "step")} \xB7 ${formatSpend(cost, estimates ? listCost : 0)} (their own sessions)`, width),
|
|
1547
1591
|
tone: "muted"
|
|
1548
1592
|
});
|
|
1549
1593
|
}
|
|
@@ -1575,65 +1619,33 @@ function coveragePairs(coverage) {
|
|
|
1575
1619
|
]
|
|
1576
1620
|
];
|
|
1577
1621
|
}
|
|
1578
|
-
function modelColumns(width) {
|
|
1579
|
-
const layouts = [
|
|
1580
|
-
{ model: 30, steps: 6, prompt: 10, cached: 10, hit: 7, out: 9, cost: 9, spread: 24 },
|
|
1581
|
-
{ model: 26, steps: 6, prompt: 9, cached: 9, hit: 7, out: 8, cost: 8, spread: 20 },
|
|
1582
|
-
{ model: 20, steps: 6, prompt: 9, cached: 9, hit: 6, out: 8, cost: 8, spread: 0 },
|
|
1583
|
-
{ model: 18, steps: 5, prompt: 8, cached: 8, hit: 0, out: 7, cost: 8, spread: 0 },
|
|
1584
|
-
{ model: 14, steps: 5, prompt: 8, cached: 8, hit: 0, out: 7, cost: 0, spread: 0 }
|
|
1585
|
-
];
|
|
1586
|
-
for (const layout of layouts) {
|
|
1587
|
-
const total = Object.values(layout).reduce((sum, column) => sum + column, 0) + Object.values(layout).filter((column) => column > 0).length - 1;
|
|
1588
|
-
if (total <= width)
|
|
1589
|
-
return layout;
|
|
1590
|
-
}
|
|
1591
|
-
return layouts[layouts.length - 1];
|
|
1592
|
-
}
|
|
1593
1622
|
function modelsLines(rows, width, extras, limit = 40, estimates = true) {
|
|
1594
|
-
|
|
1595
|
-
const
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
header
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
if (columns.
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
header.push("providers");
|
|
1615
|
-
}
|
|
1616
|
-
const lines = [{ text: formatTableRow(header, widths, aligns), tone: HEADER_TONE }];
|
|
1623
|
+
let modelWidth = 14;
|
|
1624
|
+
const columns = fitTable([
|
|
1625
|
+
{ header: "model", width: 14, max: 36, cell: (row) => modelCell(row.modelID, row.variant, modelWidth) },
|
|
1626
|
+
{ header: "steps", width: 6, align: "right", cell: (row) => row.steps },
|
|
1627
|
+
{ header: "prompt", width: 7, max: 10, align: "right", cell: (row) => row.prompt },
|
|
1628
|
+
{ header: "cached", width: 7, max: 10, align: "right", cell: (row) => row.cached },
|
|
1629
|
+
{ header: "hit", width: 6, max: 7, priority: 2, reserve: 10, align: "right", cell: (row) => row.hit },
|
|
1630
|
+
{ header: "out", width: 7, max: 9, priority: 3, reserve: 10, align: "right", cell: (row) => row.output },
|
|
1631
|
+
{ header: "cost", width: 8, max: 9, priority: 1, align: "right", cell: (row) => row.cost },
|
|
1632
|
+
{ header: "providers", width: 18, max: 24, priority: 4, reserve: 22, cell: (row) => row.providers }
|
|
1633
|
+
], width);
|
|
1634
|
+
modelWidth = columns.find((column) => column.index === 0)?.width ?? 0;
|
|
1635
|
+
if (columns.length === 0)
|
|
1636
|
+
return [{ text: truncate("no room for a table at this width", width), tone: "muted" }];
|
|
1637
|
+
const lines = [
|
|
1638
|
+
{
|
|
1639
|
+
text: formatTableRow(columns.map((column) => column.header), columns.map((column) => column.width), columns.map((column) => column.align)),
|
|
1640
|
+
tone: HEADER_TONE
|
|
1641
|
+
}
|
|
1642
|
+
];
|
|
1617
1643
|
for (const model of rows.slice(0, limit)) {
|
|
1618
1644
|
const key = modelKey(model.modelID, model.variant);
|
|
1619
|
-
const name = modelCell(model.modelID, model.variant, columns.model);
|
|
1620
1645
|
const buckets = usageBuckets(model.totals);
|
|
1621
1646
|
const providers = unique(model.providers.map((provider) => provider.providerID));
|
|
1622
1647
|
const cache = extras?.cache?.get(key);
|
|
1623
1648
|
const switches = extras?.switches?.get(key);
|
|
1624
|
-
const cells = [name, formatCount(buckets.steps), formatTokens(buckets.prompt), formatTokens(buckets.cached)];
|
|
1625
|
-
if (columns.hit > 0)
|
|
1626
|
-
cells.push(formatPercent(cache?.hit ?? buckets.hit));
|
|
1627
|
-
cells.push(formatTokens(buckets.output));
|
|
1628
|
-
if (columns.cost > 0)
|
|
1629
|
-
cells.push(formatSpend(buckets.cost, estimates ? buckets.listCost : 0));
|
|
1630
|
-
if (columns.spread > 0)
|
|
1631
|
-
cells.push(providers.join(", "));
|
|
1632
|
-
lines.push({
|
|
1633
|
-
text: formatTableRow(cells, widths, aligns),
|
|
1634
|
-
tone: "base",
|
|
1635
|
-
row: { kind: "model", value: model.modelID, ...model.variant !== undefined ? { variant: model.variant } : {} }
|
|
1636
|
-
});
|
|
1637
1649
|
const details = [];
|
|
1638
1650
|
if (cache !== undefined)
|
|
1639
1651
|
details.push(`p50 hit ${formatPercent(cache.hitP50)}`);
|
|
@@ -1643,62 +1655,76 @@ function modelsLines(rows, width, extras, limit = 40, estimates = true) {
|
|
|
1643
1655
|
if (switches.cacheLost > 0)
|
|
1644
1656
|
details.push(`${formatTokens(switches.cacheLost)} lost on a switch`);
|
|
1645
1657
|
}
|
|
1646
|
-
|
|
1647
|
-
|
|
1658
|
+
const view = {
|
|
1659
|
+
modelID: model.modelID,
|
|
1660
|
+
variant: model.variant,
|
|
1661
|
+
steps: formatCount(buckets.steps),
|
|
1662
|
+
prompt: formatTokens(buckets.prompt),
|
|
1663
|
+
cached: formatTokens(buckets.cached),
|
|
1664
|
+
hit: formatPercent(cache?.hit ?? buckets.hit),
|
|
1665
|
+
output: formatTokens(buckets.output),
|
|
1666
|
+
cost: formatSpend(buckets.cost, estimates ? buckets.listCost : 0),
|
|
1667
|
+
providers: providers.join(", "),
|
|
1668
|
+
detail: details.join(" \xB7 ")
|
|
1669
|
+
};
|
|
1670
|
+
lines.push({
|
|
1671
|
+
text: formatTableRow(columns.map((column) => column.cell(view)), columns.map((column) => column.width), columns.map((column) => column.align)),
|
|
1672
|
+
tone: "base",
|
|
1673
|
+
row: { kind: "model", value: model.modelID, ...model.variant !== undefined ? { variant: model.variant } : {} }
|
|
1674
|
+
});
|
|
1675
|
+
if (view.detail !== "") {
|
|
1676
|
+
lines.push({ text: truncate(`${" ".repeat(modelWidth + 1)}${view.detail}`, width), tone: "muted" });
|
|
1648
1677
|
}
|
|
1649
1678
|
}
|
|
1650
1679
|
if (rows.length > limit)
|
|
1651
|
-
lines.push({ text: `\u2026 ${count(rows.length - limit, "more model")} \xB7 narrow the range or filter`, tone: "muted" });
|
|
1680
|
+
lines.push({ text: truncate(`\u2026 ${count(rows.length - limit, "more model")} \xB7 narrow the range or filter`, width), tone: "muted" });
|
|
1652
1681
|
if (rows.length === 0)
|
|
1653
|
-
lines.push({ text: "no usage recorded for this range", tone: "muted" });
|
|
1682
|
+
lines.push({ text: truncate("no usage recorded for this range", width), tone: "muted" });
|
|
1654
1683
|
return lines;
|
|
1655
1684
|
}
|
|
1656
1685
|
function unique(values) {
|
|
1657
1686
|
return [...new Set(values)];
|
|
1658
1687
|
}
|
|
1659
|
-
var tableWidth = (columns) => columns.reduce((sum, column) => sum + column.width, 0) + columns.length - 1;
|
|
1660
|
-
function fitColumns(columns, width) {
|
|
1661
|
-
const chosen = [...columns];
|
|
1662
|
-
while (chosen.length > 1 && tableWidth(chosen) > width) {
|
|
1663
|
-
const optional = [...chosen].reverse().findIndex((column) => column.optional === true);
|
|
1664
|
-
if (optional === -1)
|
|
1665
|
-
break;
|
|
1666
|
-
chosen.splice(chosen.length - 1 - optional, 1);
|
|
1667
|
-
}
|
|
1668
|
-
return chosen;
|
|
1669
|
-
}
|
|
1670
1688
|
function renderTable(rows, columns, width, options) {
|
|
1671
|
-
const chosen =
|
|
1689
|
+
const chosen = fitTableColumns(columns, width).map(({ index, width: fitted }) => {
|
|
1690
|
+
const column = columns[index];
|
|
1691
|
+
const align = column.align ?? "left";
|
|
1692
|
+
return { ...column, width: fitted, align };
|
|
1693
|
+
});
|
|
1694
|
+
if (chosen.length === 0)
|
|
1695
|
+
return [{ text: truncate(options.empty, width), tone: "muted" }];
|
|
1672
1696
|
const widths = chosen.map((column) => column.width);
|
|
1673
|
-
const aligns = chosen.map((column) => column.align
|
|
1674
|
-
const
|
|
1675
|
-
|
|
1697
|
+
const aligns = chosen.map((column) => column.align);
|
|
1698
|
+
const lines = [
|
|
1699
|
+
{ text: formatTableRow(chosen.map((column) => column.header), widths, aligns), tone: HEADER_TONE }
|
|
1700
|
+
];
|
|
1676
1701
|
if (rows.length === 0)
|
|
1677
|
-
lines.push({ text: options.empty, tone: "muted" });
|
|
1702
|
+
lines.push({ text: truncate(options.empty, width), tone: "muted" });
|
|
1678
1703
|
for (const row of rows.slice(0, options.limit)) {
|
|
1679
1704
|
const identity = options.row?.(row);
|
|
1680
1705
|
lines.push({
|
|
1681
|
-
text: formatTableRow(chosen.map((column) => column.cell(row)), widths,
|
|
1706
|
+
text: formatTableRow(chosen.map((column) => column.cell(row, column.width)), widths, aligns),
|
|
1682
1707
|
tone: options.tone?.(row) ?? "base",
|
|
1683
1708
|
...identity === undefined ? {} : { row: identity }
|
|
1684
1709
|
});
|
|
1685
1710
|
}
|
|
1686
|
-
if (rows.length > options.limit)
|
|
1687
|
-
lines.push({ text: `\u2026 ${count(rows.length - options.limit, "more row")}`, tone: "muted" });
|
|
1711
|
+
if (rows.length > options.limit) {
|
|
1712
|
+
lines.push({ text: truncate(`\u2026 ${count(rows.length - options.limit, "more row")}`, width), tone: "muted" });
|
|
1713
|
+
}
|
|
1688
1714
|
return lines;
|
|
1689
1715
|
}
|
|
1690
1716
|
function providerSummaryLines(rows, width, limit = 40, estimates = true) {
|
|
1691
1717
|
const lines = renderTable(rows, [
|
|
1692
|
-
{ header: "provider", width:
|
|
1693
|
-
{ header: "models", width:
|
|
1718
|
+
{ header: "provider", width: 14, max: 32, cell: (row, column) => truncate(row.provider ?? "\u2013 (unknown)", column) },
|
|
1719
|
+
{ header: "models", width: 6, align: "right", priority: 4, cell: (row) => formatCount(row.models.length) },
|
|
1694
1720
|
{ header: "steps", width: 6, align: "right", cell: (row) => formatCount(row.usage.steps) },
|
|
1695
|
-
{ header: "share", width: 6, align: "right",
|
|
1696
|
-
{ header: "prompt", width: 10, align: "right", cell: (row) => formatTokens(row.cache.prompt) },
|
|
1697
|
-
{ header: "cached", width: 10, align: "right", cell: (row) => formatTokens(row.cache.cached) },
|
|
1698
|
-
{ header: "hit", width: 7, align: "right",
|
|
1699
|
-
{ header: "tps p50", width: 8, align: "right",
|
|
1700
|
-
{ header: "wall", width:
|
|
1701
|
-
{ header: "cost", width: 9, align: "right",
|
|
1721
|
+
{ header: "share", width: 6, align: "right", priority: 3, cell: (row) => formatPercent(row.share, 0) },
|
|
1722
|
+
{ header: "prompt", width: 7, max: 10, align: "right", cell: (row) => formatTokens(row.cache.prompt) },
|
|
1723
|
+
{ header: "cached", width: 7, max: 10, align: "right", cell: (row) => formatTokens(row.cache.cached) },
|
|
1724
|
+
{ header: "hit", width: 6, max: 7, align: "right", priority: 2, cell: (row) => formatPercent(row.cache.hit) },
|
|
1725
|
+
{ header: "tps p50", width: 8, align: "right", priority: 5, cell: (row) => formatTps(row.tps) },
|
|
1726
|
+
{ header: "wall", width: 7, align: "right", priority: 6, cell: (row) => formatMs(row.wall) },
|
|
1727
|
+
{ header: "cost", width: 8, max: 9, align: "right", priority: 1, cell: (row) => formatSpend(row.usage.cost, estimates ? row.usage.listCost : 0) }
|
|
1702
1728
|
], width, {
|
|
1703
1729
|
limit,
|
|
1704
1730
|
empty: "no usage recorded for this range",
|
|
@@ -1709,16 +1735,16 @@ function providerSummaryLines(rows, width, limit = 40, estimates = true) {
|
|
|
1709
1735
|
}
|
|
1710
1736
|
function providerLines(rows, width, limit = 40, estimates = true) {
|
|
1711
1737
|
return renderTable(rows, [
|
|
1712
|
-
{ header: "model", width:
|
|
1713
|
-
{ header: "provider", width:
|
|
1738
|
+
{ header: "model", width: 24, max: 30, cell: (row, column) => modelCell(row.modelID, row.variant, column) },
|
|
1739
|
+
{ header: "provider", width: 12, max: 24, cell: (row, column) => truncate(row.provider ?? "\u2013 (unknown)", column) },
|
|
1714
1740
|
{ header: "steps", width: 6, align: "right", cell: (row) => formatCount(row.usage.steps) },
|
|
1715
|
-
{ header: "share", width: 6, align: "right",
|
|
1716
|
-
{ header: "prompt", width: 10, align: "right", cell: (row) => formatTokens(row.cache.prompt) },
|
|
1717
|
-
{ header: "cached", width: 10, align: "right", cell: (row) => formatTokens(row.cache.cached) },
|
|
1718
|
-
{ header: "hit", width: 7, align: "right",
|
|
1719
|
-
{ header: "tps p50", width: 8, align: "right",
|
|
1720
|
-
{ header: "wall", width:
|
|
1721
|
-
{ header: "cost", width: 9, align: "right",
|
|
1741
|
+
{ header: "share", width: 6, align: "right", priority: 5, cell: (row) => formatPercent(row.share, 0) },
|
|
1742
|
+
{ header: "prompt", width: 7, max: 10, align: "right", priority: 2, cell: (row) => formatTokens(row.cache.prompt) },
|
|
1743
|
+
{ header: "cached", width: 7, max: 10, align: "right", priority: 3, cell: (row) => formatTokens(row.cache.cached) },
|
|
1744
|
+
{ header: "hit", width: 6, max: 7, align: "right", priority: 4, cell: (row) => formatPercent(row.cache.hit) },
|
|
1745
|
+
{ header: "tps p50", width: 8, align: "right", priority: 6, cell: (row) => formatTps(row.tps) },
|
|
1746
|
+
{ header: "wall", width: 7, align: "right", priority: 7, cell: (row) => formatMs(row.wall) },
|
|
1747
|
+
{ header: "cost", width: 8, max: 9, align: "right", priority: 1, cell: (row) => formatSpend(row.usage.cost, estimates ? row.usage.listCost : 0) }
|
|
1722
1748
|
], width, {
|
|
1723
1749
|
limit,
|
|
1724
1750
|
empty: "no usage recorded for this range",
|
|
@@ -1728,80 +1754,126 @@ function providerLines(rows, width, limit = 40, estimates = true) {
|
|
|
1728
1754
|
}
|
|
1729
1755
|
function cacheLines(data, width) {
|
|
1730
1756
|
const lines = [];
|
|
1757
|
+
const push = (text, tone = "base") => {
|
|
1758
|
+
lines.push({ text: truncate(text, width), tone });
|
|
1759
|
+
};
|
|
1731
1760
|
const total = data.drops.reduce((sum, drop) => sum + drop.tokens, 0);
|
|
1732
|
-
|
|
1761
|
+
push(`reuse losses ${count(data.drops.length, "event")} \xB7 ${formatTokens(total)} tokens`, total > 0 ? "warning" : "base");
|
|
1733
1762
|
for (const reason of ["expired", "compaction", "unknown"]) {
|
|
1734
1763
|
const group = data.drops.filter((drop) => drop.reason === reason);
|
|
1735
1764
|
if (group.length === 0)
|
|
1736
1765
|
continue;
|
|
1737
1766
|
const tokens = group.reduce((sum, drop) => sum + drop.tokens, 0);
|
|
1738
|
-
|
|
1767
|
+
push(` ${padCell(reason, 11)}${formatCount(group.length)} \xB7 ${formatTokens(tokens)}`, reason === "expired" ? "warning" : "muted");
|
|
1739
1768
|
}
|
|
1740
1769
|
if (data.drops.length === 0)
|
|
1741
|
-
|
|
1770
|
+
push(" none: prompt cache held through every gap", "muted");
|
|
1742
1771
|
if (data.models !== undefined && data.models.length > 0) {
|
|
1743
1772
|
lines.push({ text: "", tone: "muted" });
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
}
|
|
1773
|
+
push("reuse by model", HEADER_TONE);
|
|
1774
|
+
let modelWidth = 12;
|
|
1775
|
+
const reuse = fitTable([
|
|
1776
|
+
{ header: "model", width: 12, max: 30, cell: (row) => modelCell(row.usage.modelID, row.usage.variant, modelWidth) },
|
|
1777
|
+
{ header: "steps", width: 6, align: "right", cell: (row) => formatCount(row.cache.steps) },
|
|
1778
|
+
{ header: "prompt", width: 7, max: 10, align: "right", cell: (row) => formatTokens(row.cache.prompt) },
|
|
1779
|
+
{ header: "cached", width: 7, max: 10, align: "right", cell: (row) => formatTokens(row.cache.cached) },
|
|
1780
|
+
{ header: "write", width: 6, max: 8, align: "right", priority: 1, cell: (row) => formatTokens(row.cache.cacheWrite) },
|
|
1781
|
+
{ header: "hit", width: 6, max: 7, align: "right", priority: 2, cell: (row) => formatPercent(row.cache.hit) },
|
|
1782
|
+
{ header: "hit p50", width: 7, max: 9, align: "right", priority: 3, cell: (row) => formatPercent(row.cache.hitP50) }
|
|
1783
|
+
], width);
|
|
1784
|
+
modelWidth = reuse.find((column) => column.index === 0)?.width ?? 0;
|
|
1785
|
+
if (reuse.length > 0) {
|
|
1786
|
+
lines.push({ text: formatTableRow(reuse.map((column) => column.header), reuse.map((column) => column.width), reuse.map((column) => column.align)), tone: "muted" });
|
|
1787
|
+
for (const row of data.models.slice(0, 10)) {
|
|
1788
|
+
lines.push({
|
|
1789
|
+
text: formatTableRow(reuse.map((column) => column.cell(row)), reuse.map((column) => column.width), reuse.map((column) => column.align)),
|
|
1790
|
+
tone: "base",
|
|
1791
|
+
row: { kind: "model", value: row.usage.modelID, ...row.usage.variant !== undefined ? { variant: row.usage.variant } : {} }
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1754
1794
|
}
|
|
1755
1795
|
}
|
|
1756
1796
|
if (data.gap !== undefined && data.gap.samples > 0) {
|
|
1757
1797
|
lines.push({ text: "", tone: "muted" });
|
|
1758
|
-
|
|
1759
|
-
const
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1798
|
+
push("cache survival against idle time", HEADER_TONE);
|
|
1799
|
+
const buckets = data.gap.buckets;
|
|
1800
|
+
const survival = fitTable([
|
|
1801
|
+
{ header: "gap", width: 8, max: 12, cell: (bucket) => bucket.label },
|
|
1802
|
+
{ header: "pairs", width: 6, align: "right", cell: (bucket) => formatCount(bucket.samples) },
|
|
1803
|
+
{ header: "kept", width: 7, align: "right", cell: (bucket) => formatPercent(bucket.retainedRatio, 0) },
|
|
1804
|
+
{ header: "drops", width: 7, align: "right", cell: (bucket) => formatCount(bucket.drops) },
|
|
1805
|
+
{ header: "lost", width: 8, align: "right", cell: (bucket) => formatTokens(bucket.lostTokens) }
|
|
1806
|
+
], width);
|
|
1807
|
+
if (survival.length > 0) {
|
|
1808
|
+
lines.push({ text: formatTableRow(survival.map((column) => column.header), survival.map((column) => column.width), survival.map((column) => column.align)), tone: "muted" });
|
|
1809
|
+
for (const bucket of buckets) {
|
|
1810
|
+
if (bucket.samples === 0)
|
|
1811
|
+
continue;
|
|
1812
|
+
lines.push({
|
|
1813
|
+
text: formatTableRow(survival.map((column) => column.cell(bucket)), survival.map((column) => column.width), survival.map((column) => column.align)),
|
|
1814
|
+
tone: bucket.drops > 0 ? "warning" : "base"
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1768
1817
|
}
|
|
1769
1818
|
if (data.gap.providers.length > 1) {
|
|
1770
1819
|
lines.push({ text: "", tone: "muted" });
|
|
1771
|
-
|
|
1772
|
-
const
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1820
|
+
push("reuse kept, by provider", HEADER_TONE);
|
|
1821
|
+
const providers = data.gap.providers;
|
|
1822
|
+
const reuse = fitTable([
|
|
1823
|
+
{ header: "provider", width: 12, max: 30, cell: (row) => row.provider },
|
|
1824
|
+
{ header: "pairs", width: 6, align: "right", cell: (row) => formatCount(row.samples) },
|
|
1825
|
+
{ header: "kept", width: 7, align: "right", cell: (row) => formatPercent(row.retainedRatio, 0) },
|
|
1826
|
+
{ header: "lost", width: 8, align: "right", cell: (row) => formatTokens(row.lostTokens) }
|
|
1827
|
+
], width);
|
|
1828
|
+
if (reuse.length > 0) {
|
|
1829
|
+
lines.push({ text: formatTableRow(reuse.map((column) => column.header), reuse.map((column) => column.width), reuse.map((column) => column.align)), tone: "muted" });
|
|
1830
|
+
for (const row of providers.slice(0, 8)) {
|
|
1831
|
+
lines.push({
|
|
1832
|
+
text: formatTableRow(reuse.map((column) => column.cell(row)), reuse.map((column) => column.width), reuse.map((column) => column.align)),
|
|
1833
|
+
tone: "base"
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1779
1836
|
}
|
|
1780
1837
|
}
|
|
1781
1838
|
}
|
|
1782
1839
|
lines.push({ text: "", tone: "muted" });
|
|
1783
|
-
|
|
1840
|
+
push("observed cache TTL bounds", HEADER_TONE);
|
|
1784
1841
|
if (data.evidence.length === 0) {
|
|
1785
|
-
|
|
1842
|
+
push(" no comparable step pairs yet", "muted");
|
|
1786
1843
|
} else {
|
|
1787
|
-
const
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1844
|
+
const evidence = fitTable([
|
|
1845
|
+
{ header: "model", width: 12, max: 44, cell: (row) => `${row.providerID}/${row.modelID}` },
|
|
1846
|
+
{ header: "hits up to", width: 10, align: "right", cell: (row) => formatGap(row.maxHitGapMs) },
|
|
1847
|
+
{ header: "drops from", width: 10, align: "right", cell: (row) => formatGap(row.minDropGapMs) },
|
|
1848
|
+
{ header: "samples", width: 7, align: "right", priority: 1, cell: (row) => formatCount(row.samples) }
|
|
1849
|
+
], width);
|
|
1850
|
+
if (evidence.length > 0) {
|
|
1851
|
+
lines.push({ text: formatTableRow(evidence.map((column) => column.header), evidence.map((column) => column.width), evidence.map((column) => column.align)), tone: "muted" });
|
|
1852
|
+
for (const row of data.evidence.slice(0, 10)) {
|
|
1853
|
+
lines.push({
|
|
1854
|
+
text: formatTableRow(evidence.map((column) => column.cell(row)), evidence.map((column) => column.width), evidence.map((column) => column.align)),
|
|
1855
|
+
tone: "base"
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1794
1858
|
}
|
|
1795
1859
|
}
|
|
1796
1860
|
if (data.drops.length > 0) {
|
|
1797
1861
|
lines.push({ text: "", tone: "muted" });
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1862
|
+
push("recent losses", HEADER_TONE);
|
|
1863
|
+
const losses = fitTable([
|
|
1864
|
+
{ header: "when", width: 8, cell: (drop) => new Date(drop.at).toLocaleTimeString("en-GB") },
|
|
1865
|
+
{ header: "provider/model", width: 14, max: 40, cell: (drop) => `${drop.providerID ?? ""}/${drop.modelID ?? ""}` },
|
|
1866
|
+
{ header: "tokens", width: 7, align: "right", cell: (drop) => `\u2212${formatTokens(drop.tokens)}` },
|
|
1867
|
+
{ header: "idle", width: 12, max: 24, priority: 1, cell: (drop) => `${formatGap(drop.gapMs)} idle \xB7 ${drop.reason}` }
|
|
1868
|
+
], width);
|
|
1869
|
+
if (losses.length > 0) {
|
|
1870
|
+
lines.push({ text: formatTableRow(losses.map((column) => column.header), losses.map((column) => column.width), losses.map((column) => column.align)), tone: "muted" });
|
|
1871
|
+
for (const drop of [...data.drops].sort((left, right) => right.at - left.at).slice(0, 8)) {
|
|
1872
|
+
lines.push({
|
|
1873
|
+
text: formatTableRow(losses.map((column) => column.cell(drop)), losses.map((column) => column.width), losses.map((column) => column.align)),
|
|
1874
|
+
tone: drop.reason === "expired" ? "warning" : "base"
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1805
1877
|
}
|
|
1806
1878
|
}
|
|
1807
1879
|
return lines;
|
|
@@ -1822,110 +1894,162 @@ function periodLines(rows, width, granularity, limit = 40, estimates = true, tot
|
|
|
1822
1894
|
}, { steps: 0, sessions: 0, input: 0, cached: 0, cacheWrite: 0, output: 0, reasoning: 0, cost: 0, listCost: 0 });
|
|
1823
1895
|
const overall = usageBuckets(totals);
|
|
1824
1896
|
lines.push({
|
|
1825
|
-
text: `${granularityLabel(granularity)} \xB7 ${count(rows.length, "period")} \xB7 ${count(totals.steps, "step")} \xB7 hit ${formatPercent(overall.hit)}`,
|
|
1897
|
+
text: truncate(`${granularityLabel(granularity)} \xB7 ${count(rows.length, "period")} \xB7 ${count(totals.steps, "step")} \xB7 hit ${formatPercent(overall.hit)}`, width),
|
|
1826
1898
|
tone: "muted"
|
|
1827
1899
|
});
|
|
1828
1900
|
if (rows.length > 1) {
|
|
1829
|
-
|
|
1830
|
-
lines.push({ text: `
|
|
1901
|
+
const bars = Math.max(4, width - 8);
|
|
1902
|
+
lines.push({ text: truncate(`steps ${sparkline(rows.map((row) => row.usage.steps), bars)}`, width), tone: "muted" });
|
|
1903
|
+
lines.push({ text: truncate(`cached ${sparkline(rows.map((row) => row.usage.cached), bars)}`, width), tone: "muted" });
|
|
1831
1904
|
lines.push({
|
|
1832
|
-
text: `cost ${sparkline(rows.map((row) => Math.round((estimates ? row.usage.cost + row.usage.listCost : row.usage.cost) * 1e4)))}`,
|
|
1905
|
+
text: truncate(`cost ${sparkline(rows.map((row) => Math.round((estimates ? row.usage.cost + row.usage.listCost : row.usage.cost) * 1e4)), bars)}`, width),
|
|
1833
1906
|
tone: "muted"
|
|
1834
1907
|
});
|
|
1835
1908
|
}
|
|
1836
|
-
const
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1909
|
+
const columns = fitTable([
|
|
1910
|
+
{ header: "period", width: 10, max: 24, cell: (row) => row.label },
|
|
1911
|
+
{ header: "steps", width: 6, align: "right", cell: (row) => row.steps },
|
|
1912
|
+
{ header: "sess", width: 6, align: "right", priority: 5, cell: (row) => row.sessions },
|
|
1913
|
+
{ header: "prompt", width: 7, max: 10, align: "right", priority: 1, cell: (row) => row.prompt },
|
|
1914
|
+
{ header: "cached", width: 7, max: 10, align: "right", priority: 2, cell: (row) => row.cached },
|
|
1915
|
+
{ header: "hit", width: 6, max: 7, align: "right", priority: 3, cell: (row) => row.hit },
|
|
1916
|
+
{ header: "out", width: 7, max: 9, align: "right", priority: 4, cell: (row) => row.output },
|
|
1917
|
+
{ header: "cost", width: 8, max: 9, align: "right", cell: (row) => row.cost }
|
|
1918
|
+
], width);
|
|
1919
|
+
if (columns.length === 0)
|
|
1920
|
+
return [...lines, { text: truncate("no room for a table at this width", width), tone: "muted" }];
|
|
1921
|
+
const header = formatTableRow(columns.map((column) => column.header), columns.map((column) => column.width), columns.map((column) => column.align));
|
|
1922
|
+
lines.push({ text: header, tone: HEADER_TONE });
|
|
1841
1923
|
const newest = [...rows].sort((left, right) => right.at - left.at).slice(0, limit);
|
|
1842
1924
|
for (const row of newest) {
|
|
1843
1925
|
const buckets = usageBuckets(row.usage);
|
|
1844
|
-
const
|
|
1845
|
-
row.label,
|
|
1846
|
-
formatCount(row.steps),
|
|
1847
|
-
|
|
1848
|
-
formatTokens(buckets.prompt),
|
|
1849
|
-
formatTokens(buckets.cached),
|
|
1850
|
-
formatPercent(buckets.hit, 0),
|
|
1851
|
-
formatTokens(buckets.output),
|
|
1852
|
-
formatSpend(buckets.cost, estimates ? buckets.listCost : 0)
|
|
1853
|
-
|
|
1854
|
-
lines.push({
|
|
1926
|
+
const view = {
|
|
1927
|
+
label: row.label,
|
|
1928
|
+
steps: formatCount(row.steps),
|
|
1929
|
+
sessions: formatCount(row.sessions),
|
|
1930
|
+
prompt: formatTokens(buckets.prompt),
|
|
1931
|
+
cached: formatTokens(buckets.cached),
|
|
1932
|
+
hit: formatPercent(buckets.hit, 0),
|
|
1933
|
+
output: formatTokens(buckets.output),
|
|
1934
|
+
cost: formatSpend(buckets.cost, estimates ? buckets.listCost : 0)
|
|
1935
|
+
};
|
|
1936
|
+
lines.push({
|
|
1937
|
+
text: formatTableRow(columns.map((column) => column.cell(view)), columns.map((column) => column.width), columns.map((column) => column.align)),
|
|
1938
|
+
tone: "base",
|
|
1939
|
+
row: { kind: "period", value: row.key }
|
|
1940
|
+
});
|
|
1855
1941
|
}
|
|
1856
1942
|
lines.push({ text: "", tone: "muted" });
|
|
1943
|
+
const total = {
|
|
1944
|
+
label: "total",
|
|
1945
|
+
steps: formatCount(totals.steps),
|
|
1946
|
+
sessions: formatCount(totalSessions ?? totals.sessions),
|
|
1947
|
+
prompt: formatTokens(overall.prompt),
|
|
1948
|
+
cached: formatTokens(overall.cached),
|
|
1949
|
+
hit: formatPercent(overall.hit, 0),
|
|
1950
|
+
output: formatTokens(overall.output),
|
|
1951
|
+
cost: formatSpend(overall.cost, estimates ? overall.listCost : 0)
|
|
1952
|
+
};
|
|
1857
1953
|
lines.push({
|
|
1858
|
-
text: formatTableRow(
|
|
1859
|
-
"total",
|
|
1860
|
-
formatCount(totals.steps),
|
|
1861
|
-
...withSessions ? [formatCount(totalSessions ?? totals.sessions)] : [],
|
|
1862
|
-
formatTokens(overall.prompt),
|
|
1863
|
-
formatTokens(overall.cached),
|
|
1864
|
-
formatPercent(overall.hit, 0),
|
|
1865
|
-
formatTokens(overall.output),
|
|
1866
|
-
formatSpend(overall.cost, estimates ? overall.listCost : 0)
|
|
1867
|
-
], widths, aligns),
|
|
1954
|
+
text: formatTableRow(columns.map((column) => column.cell(total)), columns.map((column) => column.width), columns.map((column) => column.align)),
|
|
1868
1955
|
tone: HEADER_TONE
|
|
1869
1956
|
});
|
|
1870
1957
|
if (rows.length === 0)
|
|
1871
|
-
lines.push({ text: "no usage recorded for this range", tone: "muted" });
|
|
1958
|
+
lines.push({ text: truncate("no usage recorded for this range", width), tone: "muted" });
|
|
1872
1959
|
return lines;
|
|
1873
1960
|
}
|
|
1961
|
+
function latencyMetric(label, values, width) {
|
|
1962
|
+
const prefix = padCell(label, 11);
|
|
1963
|
+
let text = `${prefix}${values[0] ?? "\u2013"}`;
|
|
1964
|
+
for (let index = 1;index < values.length; index += 1) {
|
|
1965
|
+
const next = `${text} \xB7 ${values[index]}`;
|
|
1966
|
+
if (next.length > width)
|
|
1967
|
+
break;
|
|
1968
|
+
text = next;
|
|
1969
|
+
}
|
|
1970
|
+
return text;
|
|
1971
|
+
}
|
|
1874
1972
|
function latencyLines(report, width, groups, limit = 12, estimates = true) {
|
|
1875
1973
|
const lines = [];
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1974
|
+
if (width >= 68) {
|
|
1975
|
+
lines.push({
|
|
1976
|
+
text: formatTableRow(["wall", "p50", formatMs(report.wall.p50), "p90", formatMs(report.wall.p90), "p99", formatMs(report.wall.p99), `n ${formatCount(report.wall.count)}`], [10, 4, 9, 4, 9, 4, 9, 12]),
|
|
1977
|
+
tone: "base"
|
|
1978
|
+
});
|
|
1979
|
+
lines.push({
|
|
1980
|
+
text: formatTableRow(["stream", "p50", formatMs(report.stream.p50), "p90", formatMs(report.stream.p90), "p99", formatMs(report.stream.p99)], [10, 4, 9, 4, 9, 4, 9]),
|
|
1981
|
+
tone: "base"
|
|
1982
|
+
});
|
|
1983
|
+
lines.push({
|
|
1984
|
+
text: formatTableRow(["throughput", "p50", formatTps(report.tps.p50), "p90", formatTps(report.tps.p90), "p99", formatTps(report.tps.p99)], [10, 4, 9, 4, 9, 4, 9]),
|
|
1985
|
+
tone: "base"
|
|
1986
|
+
});
|
|
1987
|
+
} else {
|
|
1988
|
+
lines.push({
|
|
1989
|
+
text: latencyMetric("wall", [`p50 ${formatMs(report.wall.p50)}`, `p90 ${formatMs(report.wall.p90)}`, `p99 ${formatMs(report.wall.p99)}`, `n ${formatCount(report.wall.count)}`], width),
|
|
1990
|
+
tone: "base"
|
|
1991
|
+
});
|
|
1992
|
+
lines.push({
|
|
1993
|
+
text: latencyMetric("stream", [`p50 ${formatMs(report.stream.p50)}`, `p90 ${formatMs(report.stream.p90)}`, `p99 ${formatMs(report.stream.p99)}`], width),
|
|
1994
|
+
tone: "base"
|
|
1995
|
+
});
|
|
1996
|
+
lines.push({
|
|
1997
|
+
text: latencyMetric("throughput", [`p50 ${formatTps(report.tps.p50)}`, `p90 ${formatTps(report.tps.p90)}`, `p99 ${formatTps(report.tps.p99)}`], width),
|
|
1998
|
+
tone: "base"
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
1888
2001
|
lines.push({ text: "", tone: "muted" });
|
|
1889
2002
|
lines.push({
|
|
1890
2003
|
text: truncate("wall = request to completed \xB7 stream = request to last chunk \xB7 throughput = output+reasoning tokens/s", width),
|
|
1891
2004
|
tone: "muted"
|
|
1892
2005
|
});
|
|
1893
2006
|
if (report.wall.count === 0)
|
|
1894
|
-
lines.push({ text: "no completed steps for this range", tone: "muted" });
|
|
2007
|
+
lines.push({ text: truncate("no completed steps for this range", width), tone: "muted" });
|
|
1895
2008
|
if (groups !== undefined && groups.length > 0) {
|
|
1896
2009
|
lines.push({ text: "", tone: "muted" });
|
|
1897
2010
|
lines.push({ text: "by group", tone: HEADER_TONE });
|
|
1898
|
-
const
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
2011
|
+
const columns = fitTable([
|
|
2012
|
+
{ header: "group", width: 8, max: 32, cell: (row) => row.label },
|
|
2013
|
+
{ header: "n", width: 4, align: "right", cell: (row) => formatCount(row.count) },
|
|
2014
|
+
{ header: "wall p50", width: 8, align: "right", cell: (row) => formatMs(row.wall.p50) },
|
|
2015
|
+
{ header: "wall p90", width: 8, max: 9, align: "right", priority: 1, cell: (row) => formatMs(row.wall.p90) },
|
|
2016
|
+
{ header: "stream", width: 6, max: 9, align: "right", priority: 2, cell: (row) => formatMs(row.stream.p50) },
|
|
2017
|
+
{ header: "tps p50", width: 8, max: 9, align: "right", cell: (row) => formatTps(row.tps.p50) },
|
|
2018
|
+
{ header: "tps p90", width: 8, max: 9, align: "right", priority: 3, cell: (row) => formatTps(row.tps.p90) },
|
|
2019
|
+
{ header: "cost", width: 8, max: 9, align: "right", cell: (row) => formatSpend(row.usage.cost, estimates ? row.usage.listCost : 0) }
|
|
2020
|
+
], width);
|
|
2021
|
+
if (columns.length > 0) {
|
|
2022
|
+
lines.push({ text: formatTableRow(columns.map((column) => column.header), columns.map((column) => column.width), columns.map((column) => column.align)), tone: "muted" });
|
|
2023
|
+
for (const row of groups.slice(0, limit)) {
|
|
2024
|
+
const thin = row.count < 5;
|
|
2025
|
+
lines.push({
|
|
2026
|
+
text: formatTableRow(columns.map((column) => column.cell(row)), columns.map((column) => column.width), columns.map((column) => column.align)),
|
|
2027
|
+
tone: thin ? "muted" : "base",
|
|
2028
|
+
row: { kind: "model", value: row.key }
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
1917
2031
|
}
|
|
1918
|
-
lines.push({ text: "n < 5 is dimmed: too few samples to compare", tone: "muted" });
|
|
2032
|
+
lines.push({ text: truncate("n < 5 is dimmed: too few samples to compare", width), tone: "muted" });
|
|
1919
2033
|
}
|
|
1920
2034
|
return lines;
|
|
1921
2035
|
}
|
|
1922
2036
|
function sessionsLines(rows, width, options) {
|
|
1923
2037
|
const limit = options?.limit ?? 20;
|
|
1924
2038
|
const estimates = options?.estimates !== false;
|
|
1925
|
-
const
|
|
1926
|
-
|
|
2039
|
+
const columns = fitTable([
|
|
2040
|
+
{ header: "title", width: 10, max: 48, cell: (row) => row.title },
|
|
2041
|
+
{ header: "steps", width: 6, align: "right", cell: (row) => row.steps },
|
|
2042
|
+
{ header: "prompt", width: 7, max: 10, align: "right", priority: 1, cell: (row) => row.prompt },
|
|
2043
|
+
{ header: "cached", width: 7, max: 10, align: "right", priority: 2, cell: (row) => row.cached },
|
|
2044
|
+
{ header: "hit", width: 6, max: 7, align: "right", priority: 3, cell: (row) => row.hit },
|
|
2045
|
+
{ header: "out", width: 7, max: 9, align: "right", priority: 4, cell: (row) => row.output },
|
|
2046
|
+
{ header: "cost", width: 8, max: 9, align: "right", cell: (row) => row.cost }
|
|
2047
|
+
], width);
|
|
1927
2048
|
const lines = [
|
|
1928
|
-
{
|
|
2049
|
+
{
|
|
2050
|
+
text: formatTableRow(columns.map((column) => column.header), columns.map((column) => column.width), columns.map((column) => column.align)),
|
|
2051
|
+
tone: HEADER_TONE
|
|
2052
|
+
}
|
|
1929
2053
|
];
|
|
1930
2054
|
const byID = new Map(rows.map((row) => [row.sessionID, row]));
|
|
1931
2055
|
const ordered = rows.filter((row) => row.parentID === undefined || !byID.has(row.parentID));
|
|
@@ -1933,18 +2057,18 @@ function sessionsLines(rows, width, options) {
|
|
|
1933
2057
|
const orderedAll = [...ordered, ...children];
|
|
1934
2058
|
for (const row of orderedAll.slice(0, limit)) {
|
|
1935
2059
|
const child = row.parentID !== undefined && byID.has(row.parentID);
|
|
1936
|
-
const title = truncate(row.title ?? row.sessionID, Math.max(8, widths[0] - (child ? 2 : 0)));
|
|
1937
2060
|
const buckets = usageBuckets(row);
|
|
2061
|
+
const view = {
|
|
2062
|
+
title: `${child ? "\u21B3 " : ""}${row.title ?? row.sessionID}`,
|
|
2063
|
+
steps: formatCount(buckets.steps),
|
|
2064
|
+
prompt: formatTokens(buckets.prompt),
|
|
2065
|
+
cached: formatTokens(buckets.cached),
|
|
2066
|
+
hit: formatPercent(buckets.hit, 0),
|
|
2067
|
+
output: formatTokens(buckets.output),
|
|
2068
|
+
cost: formatSpend(buckets.cost, estimates ? buckets.listCost : 0)
|
|
2069
|
+
};
|
|
1938
2070
|
lines.push({
|
|
1939
|
-
text: formatTableRow(
|
|
1940
|
-
`${child ? "\u21B3 " : ""}${title}`,
|
|
1941
|
-
formatCount(buckets.steps),
|
|
1942
|
-
formatTokens(buckets.prompt),
|
|
1943
|
-
formatTokens(buckets.cached),
|
|
1944
|
-
formatPercent(buckets.hit, 0),
|
|
1945
|
-
formatTokens(buckets.output),
|
|
1946
|
-
formatSpend(buckets.cost, estimates ? buckets.listCost : 0)
|
|
1947
|
-
], widths, aligns),
|
|
2071
|
+
text: formatTableRow(columns.map((column) => column.cell(view)), columns.map((column) => column.width), columns.map((column) => column.align)),
|
|
1948
2072
|
tone: child ? "muted" : "base",
|
|
1949
2073
|
row: { kind: "session", value: row.sessionID }
|
|
1950
2074
|
});
|
|
@@ -1959,14 +2083,14 @@ function sessionsLines(rows, width, options) {
|
|
|
1959
2083
|
const share = rows.reduce((sum, row) => sum + row.steps, 0);
|
|
1960
2084
|
lines.push({ text: "", tone: "muted" });
|
|
1961
2085
|
lines.push({
|
|
1962
|
-
text: `subagents ${formatCount(options.rollup.subagentSteps)} steps (${formatPercent(share > 0 ? options.rollup.subagentSteps / share : undefined)}) \xB7 ${formatSpend(options.rollup.subagentCost, estimates ? options.rollup.subagentListCost ?? 0 : 0)}`,
|
|
2086
|
+
text: truncate(`subagents ${formatCount(options.rollup.subagentSteps)} steps (${formatPercent(share > 0 ? options.rollup.subagentSteps / share : undefined)}) \xB7 ${formatSpend(options.rollup.subagentCost, estimates ? options.rollup.subagentListCost ?? 0 : 0)}`, width),
|
|
1963
2087
|
tone: "muted"
|
|
1964
2088
|
});
|
|
1965
2089
|
}
|
|
1966
2090
|
if (rows.length > limit)
|
|
1967
|
-
lines.push({ text: `\u2026 ${count(rows.length - limit, "more session")} \xB7 narrow the range`, tone: "muted" });
|
|
2091
|
+
lines.push({ text: truncate(`\u2026 ${count(rows.length - limit, "more session")} \xB7 narrow the range`, width), tone: "muted" });
|
|
1968
2092
|
if (rows.length === 0)
|
|
1969
|
-
lines.push({ text: "no sessions recorded for this range", tone: "muted" });
|
|
2093
|
+
lines.push({ text: truncate("no sessions recorded for this range", width), tone: "muted" });
|
|
1970
2094
|
return lines;
|
|
1971
2095
|
}
|
|
1972
2096
|
function dbLines(data, width) {
|
|
@@ -1974,16 +2098,16 @@ function dbLines(data, width) {
|
|
|
1974
2098
|
const size = (bytes) => `${(bytes / 1048576).toFixed(1)} MB`;
|
|
1975
2099
|
lines.push({ text: truncate(data.info.path, width), tone: "base" });
|
|
1976
2100
|
lines.push({
|
|
1977
|
-
text: `${size(data.info.bytes)}${data.info.walBytes === undefined ? "" : ` + ${size(data.info.walBytes)} wal`} \xB7 schema v${data.info.schemaVersion}`,
|
|
2101
|
+
text: truncate(`${size(data.info.bytes)}${data.info.walBytes === undefined ? "" : ` + ${size(data.info.walBytes)} wal`} \xB7 schema v${data.info.schemaVersion}`, width),
|
|
1978
2102
|
tone: "muted"
|
|
1979
2103
|
});
|
|
1980
2104
|
lines.push({ text: "", tone: "muted" });
|
|
1981
2105
|
lines.push({ text: "what it holds", tone: HEADER_TONE });
|
|
1982
2106
|
for (const table of data.info.tables) {
|
|
1983
|
-
lines.push({ text: ` ${padCell(table.name, 12)}${formatCount(table.rows)} rows`, tone: table.rows === 0 ? "muted" : "base" });
|
|
2107
|
+
lines.push({ text: truncate(` ${padCell(table.name, 12)}${formatCount(table.rows)} rows`, width), tone: table.rows === 0 ? "muted" : "base" });
|
|
1984
2108
|
}
|
|
1985
2109
|
lines.push({
|
|
1986
|
-
text: ` window ${data.info.firstAt === undefined ? "\u2013" : new Date(data.info.firstAt).toLocaleDateString("en-GB")} \u2192 ${data.info.lastAt === undefined ? "\u2013" : new Date(data.info.lastAt).toLocaleDateString("en-GB")}`,
|
|
2110
|
+
text: truncate(` window ${data.info.firstAt === undefined ? "\u2013" : new Date(data.info.firstAt).toLocaleDateString("en-GB")} \u2192 ${data.info.lastAt === undefined ? "\u2013" : new Date(data.info.lastAt).toLocaleDateString("en-GB")}`, width),
|
|
1987
2111
|
tone: "muted"
|
|
1988
2112
|
});
|
|
1989
2113
|
lines.push({ text: "", tone: "muted" });
|
|
@@ -1999,7 +2123,7 @@ function dbLines(data, width) {
|
|
|
1999
2123
|
tone: data.info.schemaVersion < 10 || data.info.unpriced > 0 ? "base" : "muted"
|
|
2000
2124
|
});
|
|
2001
2125
|
}
|
|
2002
|
-
const widths = [
|
|
2126
|
+
const widths = [9, 11, 10];
|
|
2003
2127
|
lines.push({ text: formatTableRow(["keep", "prunes", "older than"], widths, ["left", "right", "left"]), tone: "muted" });
|
|
2004
2128
|
for (const option of data.info.removable) {
|
|
2005
2129
|
const before = new Date(data.now - option.days * 24 * 60 * 60 * 1000).toLocaleDateString("en-GB");
|
|
@@ -2019,7 +2143,7 @@ function dbLines(data, width) {
|
|
|
2019
2143
|
});
|
|
2020
2144
|
if (data.busy === true) {
|
|
2021
2145
|
lines.push({ text: "", tone: "muted" });
|
|
2022
|
-
lines.push({ text: "the recorder is writing: try the vacuum again in a moment", tone: "warning" });
|
|
2146
|
+
lines.push({ text: truncate("the recorder is writing: try the vacuum again in a moment", width), tone: "warning" });
|
|
2023
2147
|
}
|
|
2024
2148
|
return lines;
|
|
2025
2149
|
}
|
|
@@ -2043,28 +2167,74 @@ function turnStats(turn) {
|
|
|
2043
2167
|
steps: turn.steps
|
|
2044
2168
|
};
|
|
2045
2169
|
}
|
|
2170
|
+
function compactTurnLine(stats, width, options) {
|
|
2171
|
+
const labels = { ...DEFAULT_LABELS, ...options?.labels };
|
|
2172
|
+
const fields = { ...DEFAULT_FIELDS, ...options?.fields };
|
|
2173
|
+
const estimates = options?.estimates !== false;
|
|
2174
|
+
const headParts = [];
|
|
2175
|
+
if (fields.clock && stats.endAt !== undefined)
|
|
2176
|
+
headParts.push(formatClock(stats.endAt));
|
|
2177
|
+
if (stats.providerID !== undefined) {
|
|
2178
|
+
let identity = stats.providerID;
|
|
2179
|
+
if (fields.model && stats.modelID !== undefined)
|
|
2180
|
+
identity += `/${stats.modelID}`;
|
|
2181
|
+
if (fields.variant && stats.variant)
|
|
2182
|
+
identity += ` ${stats.variant}`;
|
|
2183
|
+
headParts.push(identity);
|
|
2184
|
+
}
|
|
2185
|
+
let head = headParts.join(" ");
|
|
2186
|
+
const totals = options?.turnTotals === "sum" ? stats.totals : stats.latest;
|
|
2187
|
+
const display = displayTotals(totals);
|
|
2188
|
+
const money = fields.cost ? formatMoney(stats.totals.cost, estimates ? stats.totals.listCost : 0, labels.estimate) : undefined;
|
|
2189
|
+
const cost = money === undefined ? undefined : `${labels.cost} ${money}`.trim();
|
|
2190
|
+
const warning = fields.cacheExpiry && stats.cacheExpired ? `\u26A0 ${labels.cacheExpired} (\u2212${formatTokens(stats.cacheDropTokens)}${stats.drops.length > 1 ? ` \xD7${stats.drops.length}` : ""})` : undefined;
|
|
2191
|
+
let suffix = [warning, cost].filter((part) => part !== undefined).join(" \xB7 ");
|
|
2192
|
+
if (suffix !== "" && suffix.length + 3 > width)
|
|
2193
|
+
suffix = cost ?? suffix;
|
|
2194
|
+
head = truncate(head, Math.max(0, width - (suffix === "" ? 0 : suffix.length + 3)));
|
|
2195
|
+
if (!fields.turn || stats.totals.steps === 0)
|
|
2196
|
+
return [head, suffix].filter((part) => part !== "").join(" \xB7 ");
|
|
2197
|
+
const input = display.prompt === display.input ? `${labels.input} ${formatTokens(display.input)}` : `${labels.input} ${formatTokens(display.input)} (${formatTokens(display.prompt)})`;
|
|
2198
|
+
const volumes = [
|
|
2199
|
+
input,
|
|
2200
|
+
`${labels.cached} ${formatTokens(display.cached)}`,
|
|
2201
|
+
`${labels.output} ${formatTokens(display.output)}`,
|
|
2202
|
+
...fields.reasoning ? [`${labels.reasoning} ${formatTokens(display.reasoning)}`] : []
|
|
2203
|
+
];
|
|
2204
|
+
let numbers = "";
|
|
2205
|
+
for (const volume of volumes) {
|
|
2206
|
+
const next = numbers === "" ? volume : `${numbers}, ${volume}`;
|
|
2207
|
+
if ([head, next, suffix].filter((part) => part !== "").join(" \xB7 ").length > width)
|
|
2208
|
+
break;
|
|
2209
|
+
numbers = next;
|
|
2210
|
+
}
|
|
2211
|
+
return [head, numbers, suffix].filter((part) => part !== "").join(" \xB7 ");
|
|
2212
|
+
}
|
|
2046
2213
|
function turnsLines(rows, width, options) {
|
|
2047
2214
|
const lines = [];
|
|
2048
2215
|
const warning = rows.filter((turn) => turn.drops.length > 0).length;
|
|
2049
2216
|
lines.push({
|
|
2050
|
-
text: `${count(rows.length, "turn")} \xB7 newest first${warning > 0 ? ` \xB7 ${count(warning, "turn")} with a cache loss` : ""}`,
|
|
2217
|
+
text: truncate(`${count(rows.length, "turn")} \xB7 newest first${warning > 0 ? ` \xB7 ${count(warning, "turn")} with a cache loss` : ""}`, width),
|
|
2051
2218
|
tone: "muted"
|
|
2052
2219
|
});
|
|
2053
2220
|
const showSession = options?.sessionTitles !== undefined;
|
|
2054
2221
|
for (const turn of rows) {
|
|
2055
|
-
const
|
|
2222
|
+
const stats = turnStats(turn);
|
|
2223
|
+
const line = formatLine(stats, {
|
|
2056
2224
|
...options,
|
|
2057
2225
|
fields: { ...options?.fields, session: false }
|
|
2058
2226
|
});
|
|
2059
2227
|
const title = showSession ? `${truncate(options.sessionTitles.get(turn.sessionID) ?? turn.sessionID, 18)} ` : "";
|
|
2228
|
+
const available = Math.max(0, width - title.length);
|
|
2229
|
+
const text = `${title}${line.length <= available ? line : compactTurnLine(stats, available, { ...options, fields: { ...options?.fields, session: false } })}`;
|
|
2060
2230
|
lines.push({
|
|
2061
|
-
text: truncate(
|
|
2231
|
+
text: truncate(text, width),
|
|
2062
2232
|
tone: turn.drops.length > 0 || turn.providerChanged ? "warning" : "base",
|
|
2063
2233
|
row: { kind: "turn", value: turn.sessionID }
|
|
2064
2234
|
});
|
|
2065
2235
|
}
|
|
2066
2236
|
if (rows.length === 0)
|
|
2067
|
-
lines.push({ text: "no finished turns for this range", tone: "muted" });
|
|
2237
|
+
lines.push({ text: truncate("no finished turns for this range", width), tone: "muted" });
|
|
2068
2238
|
return lines;
|
|
2069
2239
|
}
|
|
2070
2240
|
function sessionSummaryLines(usage, budget = 34, estimates = true) {
|
|
@@ -2322,7 +2492,7 @@ var UsageInsights = Rpc.define({
|
|
|
2322
2492
|
properties: {
|
|
2323
2493
|
sessionID: { type: "string", maxLength: 200 },
|
|
2324
2494
|
limit: { type: "number", minimum: 1, maximum: MAX_TURNS },
|
|
2325
|
-
width: { type: "number", minimum: 20, maximum:
|
|
2495
|
+
width: { type: "number", minimum: 20, maximum: MAX_HISTORY_WIDTH }
|
|
2326
2496
|
},
|
|
2327
2497
|
required: ["sessionID", "limit", "width"],
|
|
2328
2498
|
additionalProperties: false
|
|
@@ -3621,4 +3791,4 @@ export {
|
|
|
3621
3791
|
tui_default as default
|
|
3622
3792
|
};
|
|
3623
3793
|
|
|
3624
|
-
//# debugId=
|
|
3794
|
+
//# debugId=42E094B28C9AC36E64756E2164756E21
|