llmtop 0.1.5 → 0.1.6

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.
Files changed (141) hide show
  1. package/README.md +70 -67
  2. package/dashboard/dist/assets/be-vietnam-pro-latin-400-normal-PpnXBOrz.woff2 +0 -0
  3. package/dashboard/dist/assets/be-vietnam-pro-latin-500-normal-B6LVzGNe.woff2 +0 -0
  4. package/dashboard/dist/assets/be-vietnam-pro-latin-600-normal-BZDkUTrt.woff2 +0 -0
  5. package/dashboard/dist/assets/be-vietnam-pro-latin-700-normal-DlW1Zbsh.woff2 +0 -0
  6. package/dashboard/dist/assets/be-vietnam-pro-latin-800-normal-BpHZASpI.woff2 +0 -0
  7. package/dashboard/dist/assets/be-vietnam-pro-latin-ext-400-normal-CiZNW1ec.woff2 +0 -0
  8. package/dashboard/dist/assets/be-vietnam-pro-latin-ext-500-normal-h0Fp6aX0.woff2 +0 -0
  9. package/dashboard/dist/assets/be-vietnam-pro-latin-ext-600-normal-BNd8euf0.woff2 +0 -0
  10. package/dashboard/dist/assets/be-vietnam-pro-latin-ext-700-normal-C8_gqRu2.woff2 +0 -0
  11. package/dashboard/dist/assets/be-vietnam-pro-latin-ext-800-normal-GEpNgheG.woff2 +0 -0
  12. package/dashboard/dist/assets/be-vietnam-pro-vietnamese-400-normal-CRcqvyg1.woff2 +0 -0
  13. package/dashboard/dist/assets/be-vietnam-pro-vietnamese-500-normal-DREgrEoJ.woff2 +0 -0
  14. package/dashboard/dist/assets/be-vietnam-pro-vietnamese-600-normal-nyU-ZL2p.woff2 +0 -0
  15. package/dashboard/dist/assets/be-vietnam-pro-vietnamese-700-normal-Csr0PCuG.woff2 +0 -0
  16. package/dashboard/dist/assets/be-vietnam-pro-vietnamese-800-normal-D4LFh2W4.woff2 +0 -0
  17. package/dashboard/dist/assets/index-C6JlgSDz.js +9 -0
  18. package/dashboard/dist/assets/index-CeDllzpB.css +1 -0
  19. package/dashboard/dist/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  20. package/dashboard/dist/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  21. package/dashboard/dist/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  22. package/dashboard/dist/index.html +2 -2
  23. package/dashboard/src/App.tsx +224 -88
  24. package/dashboard/src/controls/DateRange.tsx +3 -3
  25. package/dashboard/src/controls/Search.tsx +2 -2
  26. package/dashboard/src/controls/popover.tsx +24 -4
  27. package/dashboard/src/format.ts +1 -1
  28. package/dashboard/src/i18n.tsx +32 -4
  29. package/dashboard/src/main.tsx +11 -2
  30. package/dashboard/src/model.ts +1 -1
  31. package/dashboard/src/overview-flow.css +24 -0
  32. package/dashboard/src/overviewFlow.tsx +76 -0
  33. package/dashboard/src/sessionDetail.test.ts +19 -0
  34. package/dashboard/src/sessionScope.tsx +28 -0
  35. package/dashboard/src/shell/ConsoleFilters.tsx +203 -0
  36. package/dashboard/src/shell/Header.tsx +29 -0
  37. package/dashboard/src/shell/MobileSheet.tsx +29 -0
  38. package/dashboard/src/shell/Palette.tsx +114 -0
  39. package/dashboard/src/shell/Settings.tsx +37 -0
  40. package/dashboard/src/shell/SpecialStates.tsx +145 -0
  41. package/dashboard/src/shell/preferences.ts +71 -0
  42. package/dashboard/src/shell/styleColors.ts +5 -0
  43. package/dashboard/src/shell/useShortcuts.ts +67 -0
  44. package/dashboard/src/state.test.ts +9 -0
  45. package/dashboard/src/state.ts +13 -2
  46. package/dashboard/src/styles/commands.css +61 -0
  47. package/dashboard/src/styles/console.css +149 -0
  48. package/dashboard/src/styles/donut.css +83 -0
  49. package/dashboard/src/styles/fonts/be-vietnam-pro-LICENSE +93 -0
  50. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-400-normal.woff2 +0 -0
  51. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-500-normal.woff2 +0 -0
  52. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-600-normal.woff2 +0 -0
  53. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-700-normal.woff2 +0 -0
  54. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-800-normal.woff2 +0 -0
  55. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-400-normal.woff2 +0 -0
  56. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-500-normal.woff2 +0 -0
  57. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-600-normal.woff2 +0 -0
  58. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-700-normal.woff2 +0 -0
  59. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-800-normal.woff2 +0 -0
  60. package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-400-normal.woff2 +0 -0
  61. package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-500-normal.woff2 +0 -0
  62. package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-600-normal.woff2 +0 -0
  63. package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-700-normal.woff2 +0 -0
  64. package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-800-normal.woff2 +0 -0
  65. package/dashboard/src/styles/fonts/jetbrains-mono-LICENSE +93 -0
  66. package/dashboard/src/styles/fonts/jetbrains-mono-latin-ext-wght-normal.woff2 +0 -0
  67. package/dashboard/src/styles/fonts/jetbrains-mono-latin-wght-normal.woff2 +0 -0
  68. package/dashboard/src/styles/fonts/jetbrains-mono-vietnamese-wght-normal.woff2 +0 -0
  69. package/dashboard/src/styles/fonts.css +240 -0
  70. package/dashboard/src/styles/shell.css +151 -0
  71. package/dashboard/src/styles/states.css +32 -0
  72. package/dashboard/src/styles/tokens.css +159 -0
  73. package/dashboard/src/styles.css +13 -44
  74. package/dashboard/src/tip.ts +3 -1
  75. package/dashboard/src/treemap.ts +3 -0
  76. package/dashboard/src/ui.tsx +21 -32
  77. package/dashboard/src/views/Breakdown.tsx +46 -0
  78. package/dashboard/src/views/SessionDetail.tsx +67 -0
  79. package/dashboard/src/views/breakdown.css +33 -0
  80. package/dashboard/src/views/{Activity.tsx → classic/Activity.tsx} +31 -50
  81. package/dashboard/src/views/classic/Context.tsx +140 -0
  82. package/dashboard/src/views/{Models.tsx → classic/Models.tsx} +18 -35
  83. package/dashboard/src/views/classic/Overview.tsx +80 -0
  84. package/dashboard/src/views/classic/Projects.tsx +98 -0
  85. package/dashboard/src/views/{Sessions.tsx → classic/Sessions.tsx} +14 -17
  86. package/dashboard/src/views/{Subagents.tsx → classic/Subagents.tsx} +10 -34
  87. package/dashboard/src/views/console/Activity.tsx +241 -0
  88. package/dashboard/src/views/console/ConsoleBoot.tsx +73 -0
  89. package/dashboard/src/views/console/Context.tsx +162 -0
  90. package/dashboard/src/views/console/Models.tsx +187 -0
  91. package/dashboard/src/views/console/Overview.tsx +91 -0
  92. package/dashboard/src/views/console/Projects.tsx +6 -0
  93. package/dashboard/src/views/console/ProviderMeters.tsx +35 -0
  94. package/dashboard/src/views/console/Sessions.tsx +6 -0
  95. package/dashboard/src/views/console/Subagents.tsx +137 -0
  96. package/dashboard/src/views/console/activity-context.css +92 -0
  97. package/dashboard/src/views/console/console-boot.css +137 -0
  98. package/dashboard/src/views/console/modelVisuals.tsx +29 -0
  99. package/dashboard/src/views/console/models-subagents.css +203 -0
  100. package/dashboard/src/views/donut/Activity.tsx +247 -0
  101. package/dashboard/src/views/donut/Context.tsx +169 -0
  102. package/dashboard/src/views/donut/DonutBoot.tsx +68 -0
  103. package/dashboard/src/views/donut/Models.tsx +58 -0
  104. package/dashboard/src/views/donut/Overview.tsx +49 -0
  105. package/dashboard/src/views/donut/Projects.tsx +6 -0
  106. package/dashboard/src/views/donut/Ring.tsx +30 -0
  107. package/dashboard/src/views/donut/Sessions.tsx +6 -0
  108. package/dashboard/src/views/donut/Subagents.tsx +131 -0
  109. package/dashboard/src/views/donut/activity-context.css +154 -0
  110. package/dashboard/src/views/donut/donut-boot.css +165 -0
  111. package/dashboard/src/views/donut/models-subagents.css +157 -0
  112. package/dashboard/src/views/records/Projects.tsx +140 -0
  113. package/dashboard/src/views/records/Sessions.tsx +125 -0
  114. package/dashboard/src/views/records/records.css +119 -0
  115. package/dashboard/src/views/session-detail.css +44 -0
  116. package/dashboard/src/vm/activity.ts +72 -0
  117. package/dashboard/src/vm/colors.ts +57 -0
  118. package/dashboard/src/vm/context.ts +81 -0
  119. package/dashboard/src/vm/filterChoices.ts +27 -0
  120. package/dashboard/src/vm/models.ts +50 -0
  121. package/dashboard/src/vm/overview.ts +46 -0
  122. package/dashboard/src/vm/palette.ts +63 -0
  123. package/dashboard/src/vm/projects.ts +63 -0
  124. package/dashboard/src/vm/providerBreakdown.ts +19 -0
  125. package/dashboard/src/vm/sessionDetail.ts +16 -0
  126. package/dashboard/src/vm/sessions.ts +36 -0
  127. package/dashboard/src/vm/specialStates.ts +64 -0
  128. package/dashboard/src/vm/subagents.ts +36 -0
  129. package/dashboard/src/vm.test.ts +183 -0
  130. package/package.json +1 -1
  131. package/src/dashboard.mjs +4 -1
  132. package/dashboard/dist/assets/index-Ba0kF2tG.js +0 -9
  133. package/dashboard/dist/assets/index-NQzaBVIY.css +0 -1
  134. package/dashboard/dist/assets/montserrat-cyrillic-ext-wght-normal-CO5hGrJv.woff2 +0 -0
  135. package/dashboard/dist/assets/montserrat-cyrillic-wght-normal-EAA9jha_.woff2 +0 -0
  136. package/dashboard/dist/assets/roboto-mono-cyrillic-ext-wght-normal-BUDPrIko.woff2 +0 -0
  137. package/dashboard/dist/assets/roboto-mono-cyrillic-wght-normal-HUlVHixE.woff2 +0 -0
  138. package/dashboard/dist/assets/roboto-mono-greek-wght-normal-BJJTbwTT.woff2 +0 -0
  139. package/dashboard/src/views/Context.tsx +0 -183
  140. package/dashboard/src/views/Overview.tsx +0 -83
  141. package/dashboard/src/views/Projects.tsx +0 -116
@@ -0,0 +1,169 @@
1
+ import "./activity-context.css";
2
+ import { useState, type CSSProperties } from "react";
3
+ import { RelatedSessions } from "../../sessionScope.tsx";
4
+ import { ReplayNotes } from "../Breakdown.tsx";
5
+ import { useDash } from "../../dash.ts";
6
+ import { keep, type Fact } from "../../model.ts";
7
+ import { buildContextVM, round5, TAIL, type ContextVM, type ReplayScope } from "../../vm/context.ts";
8
+ import { Delta, Empty, Kpi, Stats, tip, type TipRow } from "../../ui.tsx";
9
+
10
+ // Whether the auto-compact window suits the sessions: how compactions went, what reading the context cost by its size, and
11
+ // the same requests replayed with compaction at other points.
12
+
13
+ export function Context({ F, list }: { F: Fact[]; list: string[] }) {
14
+ return F.length ? <ContextContent F={F} list={list} /> : <section className="card donut-panel"><Empty /></section>;
15
+ }
16
+
17
+ function ContextContent({ F, list }: { F: Fact[]; list: string[] }) {
18
+ const { M, filter, t, L, f } = useDash();
19
+ const [scope, setScope] = useState<ReplayScope>("all");
20
+ const data = buildContextVM(M, F, list, filter, scope);
21
+ const { total, current, prior, series } = data;
22
+ const compactionSessions = new Set(M.compactions.filter(keep(M, filter)).map((record) => record.s)).size;
23
+ const sessions = new Set(F.map((fact) => fact.s)).size;
24
+ return (
25
+ <div className="donut-view dac-view ctx">
26
+ <div className="donut-kpis dac-kpis">
27
+ <Kpi label={t("compactions")} value={f.int(current.count)} d={<Delta a={current.count} b={prior.count} side="none" />} series={series.count} />
28
+ <Kpi label={t("eachCosts")} value={data.compactions.count ? f.usd(data.compactions.sum + data.compactions.rb) : "—"}
29
+ d={data.compactions.count ? L.eachSplit(f.usd(data.compactions.sum), f.usd(data.compactions.rb)).join(" · ") : null} series={[]} />
30
+ <Kpi label={t("readingCtx")} value={f.pct(current.reading / (total || 1))}
31
+ d={<>{f.usd(current.reading)} · <Delta a={current.reading} b={prior.reading} side="none" /></>} series={series.reading} />
32
+ <Kpi label={t("ctxPerReq")} value={data.reading.reqs ? f.cmp(data.reading.ctx) : "—"} d={t("onAverage")} series={[]} />
33
+ <Kpi label={t("sessCompacted")} value={f.int(compactionSessions)} d={`${f.pct(compactionSessions / (sessions || 1))} · ${t("sess")}`} series={[]} />
34
+ </div>
35
+ <RelatedSessions F={F} scope="compaction" />
36
+ <Compactions data={data.compactions} currentCost={current.compacting} priorCost={prior.compacting} total={total} />
37
+ <Intervals data={data.compactions} />
38
+ <Reading data={data.reading} />
39
+ <Replay data={data.replay} scope={scope} setScope={setScope} />
40
+ </div>
41
+ );
42
+ }
43
+
44
+ // How compactions went: what each kept and left to work with, the wait, what one cost, the sessions that ended right after
45
+ // one, and the stretch from each to the next by its order in the session.
46
+ function Compactions({ data, currentCost, priorCost, total }: {
47
+ data: ContextVM["compactions"]; currentCost: number; priorCost: number | undefined; total: number;
48
+ }) {
49
+ const { t, L, f } = useDash();
50
+ const { parts: counts, fire, kept, wait, totalWait, soon } = data;
51
+ const parts = [[counts[0], L.nAuto], [counts[1], L.nManual], [counts[2], L.nInSubs]] as const;
52
+ const head = <header><h2>{t("compactions")}</h2><span className="hint">{parts.filter(([n]) => n).map(([n, l]) => l(f.int(n))).join(" · ")}</span></header>;
53
+ if (!data.count) return <section className="card donut-panel">{head}<Empty /></section>;
54
+ return (
55
+ <section className="card donut-panel">
56
+ {head}
57
+ {fire && kept && kept < fire ? <>
58
+ <div className="gauge dac-window">
59
+ <div className="track" aria-hidden="true"><i className="dac-kept" style={{ width: percent(kept, fire) }} /><i className="dac-room" style={{ flex: 1 }} /></div>
60
+ <div className="ticks"><span style={{ left: 0 }}>0</span><span style={{ left: "100%" }}>{L.compactsAt(f.cmp(fire))}</span></div>
61
+ </div>
62
+ <ul className="legend"><li><i className="dac-kept" />{t("keptAfter")}<b>{f.cmp(kept)}</b></li>
63
+ <li><i className="dac-room" />{t("roomToWork")}<b>{f.cmp(fire - kept)}</b></li></ul>
64
+ </> : null}
65
+ <Stats items={[
66
+ { label: t("wait"), value: wait !== null ? `${Math.round(wait / 1000)} s` : "—", sub: wait !== null ? L.inAll(f.dur(totalWait / 60000)) : undefined },
67
+ { label: t("compacting"), value: f.usd(currentCost), sub: <>{L.ofCost(f.pct(currentCost / (total || 1)))} · <Delta a={currentCost} b={priorCost} side="none" /></> },
68
+ { label: t("endedSoon"), value: f.int(soon), sub: L.endedWithin(TAIL) },
69
+ ]} />
70
+ </section>
71
+ );
72
+ }
73
+
74
+ function Intervals({ data }: { data: ContextVM["compactions"] }) {
75
+ const { t, L, f } = useDash();
76
+ return <section className="card donut-panel">
77
+ <header><h2>{t("inSession")}</h2></header>
78
+ {data.mainCount ? <div className="dac-table-wrap"><table className="donut-table dac-table">
79
+ <thead><tr><th scope="col">{t("inSession")}</th><th scope="col" className="num">{t("compactions")}</th>
80
+ <th scope="col" className="num">{t("keptCol")}</th><th scope="col" className="num">{t("reqsToNext")}</th>
81
+ <th scope="col" className="num">{t("turnsToNext")}</th></tr></thead>
82
+ <tbody>{data.intervals.map((g, k) => g.count ? <tr key={k}>
83
+ <th className="name" scope="row">{L.nth[k]}</th>
84
+ <td className="num" data-label={t("compactions")}>{f.int(g.count)}</td>
85
+ <td className="num" data-label={t("keptCol")}>{cell(g.kept, f.cmp)}</td>
86
+ <td className="num" data-label={t("reqsToNext")}>{cell(g.next, f.int)}</td>
87
+ <td className="num" data-label={t("turnsToNext")}>{cell(g.turns, f.int)}</td>
88
+ </tr> : null)}</tbody>
89
+ </table></div> : <Empty />}
90
+ </section>;
91
+ }
92
+ const cell = (v: number | null, fmt: (n: number) => string) => (v === null ? "—" : fmt(v));
93
+
94
+ // The cost of reading the context by the context each request carried: rows add up to the overview's cost of reading the
95
+ // context, a part the host charged with no request included.
96
+ function Reading({ data }: { data: ContextVM["reading"] }) {
97
+ const { t, L, f } = useDash();
98
+ const { E, n, b, q, cost, reqs, above, aboveQ, per, top, base, ctx } = data;
99
+ const head = <header><h2>{t("readingCtx")}</h2><span className="hint">{t("byCtx")}</span></header>;
100
+ if (!reqs) return <section className="card donut-panel">{head}<Empty /></section>;
101
+ const k = (v: number) => f.cmp(v).replace(/K$/, "");
102
+ const label = (j: number) => (j === 0 ? L.under(f.cmp(E[0])) : j === n - 1 ? L.andOver(f.cmp(E[n - 2])) : `${f.cmp(E[j - 1]).endsWith("K") && f.cmp(E[j]).endsWith("K") ? k(E[j - 1]) : f.cmp(E[j - 1])}–${f.cmp(E[j])}`);
103
+ const maxShare = Math.max(...q.map((value, j) => Math.max(value / reqs, b[j] / (cost || 1))));
104
+ return (
105
+ <section className="card donut-panel">
106
+ {head}
107
+ <Stats items={[
108
+ { label: t("ctxPerReq"), value: f.cmp(ctx), sub: t("onAverage") },
109
+ { label: L.above(f.cmp(300e3)), value: f.pct(cost ? above / cost : 0), sub: L.ofCostReqs(f.pct(aboveQ / reqs)) },
110
+ ...(top >= 0 && base >= 0 && top !== base && per[base] ? [{ label: L.perReqAt(label(top)), value: f.times(per[top] / per[base]), sub: L.whatAt(label(base)) }] : []),
111
+ ]} />
112
+ <div className="dac-reading">
113
+ <div className="dac-reading-graph">
114
+ {q.map((requests, j) => requests ? <div key={j} className="dac-reading-row">
115
+ <div className="dac-reading-bars" aria-hidden="true">
116
+ <i className="dac-req" style={{ "--share": percent(requests / reqs, maxShare) } as CSSProperties} />
117
+ <i className="dac-cost" style={{ "--share": percent(b[j] / (cost || 1), maxShare) } as CSSProperties} />
118
+ </div>
119
+ <b>{label(j)}</b>
120
+ <span className="num">{f.int(requests)} · {f.pct(requests / reqs)}</span>
121
+ <span className="num">{f.usd(b[j])} · {f.pct(b[j] / (cost || 1))}</span>
122
+ <span className="num"><small>{t("perReqCol")}</small> {f.usd3(per[j])}</span>
123
+ </div> : null)}
124
+ </div>
125
+ {b[n] >= cost * 0.005 ? <div className="dac-reading-total"><span>{t("noRequest")}</span><strong className="num">{f.usd(b[n])}</strong></div> : null}
126
+ <div className="dac-reading-total"><b>{t("all")}</b><span className="num">{f.int(reqs)} · {f.usd(cost)} · {f.usd3(cost / reqs)} {t("perReqCol")}</span></div>
127
+ </div>
128
+ <ul className="legend"><li><i className="dac-req" />{t("requests")}</li><li><i className="dac-cost" />{t("cost")}</li></ul>
129
+ </section>
130
+ );
131
+ }
132
+
133
+ // The main threads replayed with compaction at each point, against the point it fires at now. A point within NEAR of now
134
+ // gives way to it; when the models in the filter fire at different points now, now has a row of its own.
135
+ const percent = (value: number, total: number) => `${value / (total || 1) * 100}%`;
136
+
137
+ function Replay({ data, scope, setScope }: { data: ContextVM["replay"]; scope: ReplayScope; setScope: (scope: ReplayScope) => void }) {
138
+ const { t, f } = useDash();
139
+ const { hasRows, recorded, recordedCost, P, shown, one, levels, base, max } = data;
140
+ const kinds: [string, string][] = [["dac-cost", t("readingCtx")], ["dac-work", t("compacting")], ["dac-bad", t("rebuildIdle")]];
141
+ const name = (x: (typeof shown)[number]) => (x.now ? (one ? f.cmp(round5(one)) : levels.map((v) => f.cmp(round5(v))).join(" · ")) : f.cmp(x.at));
142
+ return (
143
+ <section className="card donut-panel">
144
+ <header>
145
+ <h2>{t("otherPoints")}</h2>
146
+ <div className="segs"><div className="seg" role="group">{(["all", "long"] as const).map((k) => <button key={k} aria-pressed={scope === k} onClick={() => setScope(k)}>{t(k === "all" ? "allSessions" : "long4")}</button>)}</div></div>
147
+ </header>
148
+ {hasRows ? <>
149
+ <ReplayNotes count={recorded} cost={recordedCost} />
150
+ <ul className="legend">{kinds.map(([c, n]) => <li key={c}><i className={c} />{n}</li>)}</ul>
151
+ <div className="dac-table-wrap"><table className="donut-table dac-table">
152
+ <thead><tr><th>{t("compactsAtCol")}</th><th className="num">{t("compactions")}</th><th className="num">{t("sessCompacted")}</th>{kinds.slice(0, 2).map(([c, n]) => <th key={c} className="num">{n}</th>)}<th /><th className="num">{t("estimatedCost")}</th>{base ? <th className="num">{t("againstNow")}</th> : null}</tr></thead>
153
+ <tbody>{shown.map((x) => {
154
+ const d = base ? x.total - base.total : 0;
155
+ const rowsTip: TipRow[] = kinds.map(([c, n], k) => [c, n, f.usd(x.parts[k])]);
156
+ return <tr key={`${x.j}`} className={x.now ? "now" : ""} data-tip={tip(`${t("compactsAtCol")} ${name(x)}`, rowsTip)}>
157
+ <th scope="row" className="lbl">{name(x)}{x.now ? <span className="chip">{t("now")}</span> : null}{!x.now && x.at === P.at(-1) ? <span className="sub">{t("byDefault")}</span> : null}</th>
158
+ <td className="num" data-label={t("compactions")}>{f.int(x.n)}</td><td className="num" data-label={t("sessCompacted")}>{f.int(x.sess)}</td>
159
+ {kinds.slice(0, 2).map(([c, n], k) => <td key={c} className="num" data-label={n}>{f.usd(x.parts[k])}</td>)}
160
+ <td className="dac-bar-cell" data-label={t("cost")}><div className="dac-inline-bar" style={{ width: `${(x.total / max) * 100}%` }}>{x.parts.map((v, k) => <i key={k} className={kinds[k][0]} style={{ flex: v }} />)}</div></td>
161
+ <td className="num" data-label={t("estimatedCost")}>{f.usd(x.total)}</td>
162
+ {base ? <td className="num" data-label={t("againstNow")}>{x.now ? "—" : <span className={d < 0 ? "better" : d > 0 ? "worse" : ""}>{d < 0 ? "−" : "+"}{f.usd(Math.abs(d))}</span>}</td> : null}
163
+ </tr>;
164
+ })}</tbody>
165
+ </table></div>
166
+ </> : <Empty />}
167
+ </section>
168
+ );
169
+ }
@@ -0,0 +1,68 @@
1
+ import type { ReactNode } from "react";
2
+ import type { Fmt } from "../../format.ts";
3
+ import type { Key } from "../../i18n.tsx";
4
+ import type { BootVM } from "../../vm/specialStates.ts";
5
+ import "./donut-boot.css";
6
+
7
+ const chips = ["bootChipFind", "bootChipRead", "bootChipTotal"] as const;
8
+ const activeStep = { loading: 0, find: 0, read: 1, finish: 2, error: -1 } as const;
9
+
10
+ export function DonutBoot({ brand, vm, retry, t, f, title }: {
11
+ brand: ReactNode; vm: BootVM; retry: () => void; t: (key: Key) => string; f: Fmt; title: string;
12
+ }) {
13
+ const { phase, reason, share, done, total, mb, mbTotal, status } = vm;
14
+ const failed = phase === "error";
15
+ const finding = phase === "loading" || phase === "find";
16
+ const step = activeStep[phase];
17
+
18
+ return (
19
+ <main className="donut-boot">
20
+ <div className="donut-boot-content">
21
+ {brand}
22
+ <div className="donut-boot-card" data-phase={phase} role={failed ? "alert" : "status"}
23
+ aria-live={failed ? undefined : "off"}>
24
+ <div className="donut-boot-ring">
25
+ <svg viewBox="0 0 200 200" role={failed ? undefined : "progressbar"}
26
+ aria-hidden={failed || undefined} aria-label={failed ? undefined : title}
27
+ aria-valuenow={failed || share === null ? undefined : share * 100}>
28
+ <circle className="donut-boot-track" cx="100" cy="100" r="80" />
29
+ <circle className="donut-boot-arc" cx="100" cy="100" r="80" pathLength="100"
30
+ data-wait={!failed && share === null ? "" : undefined}
31
+ strokeDasharray={failed || share === 1 ? undefined : `${share === null ? 22 : share * 100} 100`}
32
+ visibility={!failed && share === 0 ? "hidden" : undefined} />
33
+ </svg>
34
+ <div className="donut-boot-ring-text">
35
+ {failed ? <>
36
+ <span className="donut-boot-error-mark" aria-hidden="true">!</span>
37
+ {status ? <span className="donut-boot-count">HTTP {status}</span> : null}
38
+ </> : <>
39
+ <span className="donut-boot-label">{t(finding ? "bootFinding" : "transcripts")}</span>
40
+ <span className="donut-boot-percent">{share === null ? "…" : f.pct(share)}</span>
41
+ {phase === "finish" ? <span className="donut-boot-count">{t("bootTotalling")}</span>
42
+ : phase === "read" && done !== null && total !== null
43
+ ? <span className="donut-boot-count">{f.int(done)} / {f.int(total)}</span> : null}
44
+ </>}
45
+ </div>
46
+ </div>
47
+ <h1 aria-live={failed ? undefined : "polite"}>{title}</h1>
48
+ <ol className="donut-boot-steps">
49
+ {chips.map((chip, index) => (
50
+ <li key={chip}>
51
+ <span data-done={step > index || undefined} aria-current={step === index ? "step" : undefined}>
52
+ {step > index ? "✓ " : ""}{t(chip)}
53
+ </span>
54
+ </li>
55
+ ))}
56
+ </ol>
57
+ {phase === "read" && mb !== null && mbTotal !== null
58
+ ? <p className="donut-boot-bytes">{f.int(mb)} MB / {f.int(mbTotal)} MB</p> : null}
59
+ {phase === "find" && reason === "first" ? <p className="donut-boot-hint">{t("bootHint")}</p> : null}
60
+ {failed ? <>
61
+ <p className="donut-boot-help">{t("loadFailHelp")}</p>
62
+ <button type="button" className="donut-boot-retry" onClick={retry} aria-keyshortcuts="R">{t("retry")}</button>
63
+ </> : null}
64
+ </div>
65
+ </div>
66
+ </main>
67
+ );
68
+ }
@@ -0,0 +1,58 @@
1
+ import { useDash } from "../../dash.ts";
2
+ import type { Fact } from "../../model.ts";
3
+ import { useStyleColors } from "../../shell/styleColors.ts";
4
+ import { Empty } from "../../ui.tsx";
5
+ import { buildModelsVM } from "../../vm/models.ts";
6
+ import { Behaviors, Efforts, ModelFigures } from "../console/Models.tsx";
7
+ import { ModelBands, ModelDot } from "../console/modelVisuals.tsx";
8
+ import { Ring, RingValue } from "./Ring.tsx";
9
+ import "./models-subagents.css";
10
+
11
+ export function Models({ F }: { F: Fact[] }) {
12
+ const { M, t, f, set } = useDash();
13
+ const colors = useStyleColors();
14
+ const { all, providerCosts, per, behaviors, efforts } = buildModelsVM(M, F);
15
+ const providers = providerCosts.map(({ provider, cost, models }) => {
16
+ const name = M.providers[provider] ?? t("other");
17
+ const index = colors.providerNames.indexOf(name);
18
+ return { provider, label: name, color: colors.providers[index] ?? "--prov-unknown", value: cost, models };
19
+ });
20
+ const segments = M.providers.length > 1 ? providers : providers.flatMap(({ models }) =>
21
+ models.map(({ model, cost }) => ({ label: M.models[model], color: colors.models[model], value: cost })));
22
+ const modelLink = (m: number) => <button type="button" className="console-model-link" title={M.models[m]}
23
+ onClick={() => set({ view: "overview", model: M.models[m] })}><ModelDot color={colors.models[m]} /><span>{M.models[m]}</span></button>;
24
+
25
+ if (!providerCosts.length) return <section className="donut-panel"><Empty /></section>;
26
+ return (
27
+ <div className="donut-view donut-model-view">
28
+ <section className="donut-panel">
29
+ <header><h2>{t("whereMoney")}</h2></header>
30
+ <p className="hint breakdown-note">{t("shareTotalCost")}</p>
31
+ <div className="donut-model-summary">
32
+ <div className="donut-model-ring">
33
+ <Ring segments={segments}><RingValue value={f.usd(all.c)} /><small>{t("cost")}</small></Ring>
34
+ </div>
35
+ <div className="donut-model-providers">
36
+ {providers.map(({ provider, label, color, value, models }) => (
37
+ <div className="donut-model-provider" key={provider}>
38
+ <header><h3><ModelDot color={color} />{label}</h3><strong className="num">{f.usd(value)}</strong></header>
39
+ <ul>{models.map(({ model, cost }) => (
40
+ <li key={model}>
41
+ {modelLink(model)}
42
+ <ModelBands label={M.models[model]} model={M.models[model]} provider={M.providers[provider]}
43
+ bands={[{ share: all.c ? cost / all.c : 0, color: colors.models[model], label: t("cost"), value: f.usd(cost) }]} />
44
+ <span className="num">{f.usd(cost)}</span>
45
+ <small className="num">{f.pct(all.c ? cost / all.c : 0)}</small>
46
+ </li>
47
+ ))}</ul>
48
+ </div>
49
+ ))}
50
+ </div>
51
+ </div>
52
+ <ModelFigures rows={per} modelLink={modelLink} />
53
+ </section>
54
+ <Behaviors rows={behaviors} panelClass="donut-panel" />
55
+ <Efforts data={efforts} panelClass="donut-panel" />
56
+ </div>
57
+ );
58
+ }
@@ -0,0 +1,49 @@
1
+ import { useDash } from "../../dash.ts";
2
+ import type { Fact } from "../../model.ts";
3
+ import { useStyleColors } from "../../shell/styleColors.ts";
4
+ import { providerBreakdown } from "../../vm/providerBreakdown.ts";
5
+ import { Overview as SharedOverview } from "../console/Overview.tsx";
6
+ import { Ring, RingValue } from "./Ring.tsx";
7
+
8
+ export function Overview({ F, list }: { F: Fact[]; list: string[] }) {
9
+ return <SharedOverview F={F} list={list} breakdown={<ProviderRing F={F} />} />;
10
+ }
11
+
12
+ function ProviderRing({ F }: { F: Fact[] }) {
13
+ const { M, f, t } = useDash();
14
+ const colors = useStyleColors();
15
+ const { providers, total } = providerBreakdown(M, F);
16
+ const single = providers.length === 1;
17
+ const providerColor = (name: string) => colors.providers[colors.providerNames.indexOf(name)] ?? "--prov-unknown";
18
+ const segments = single ? providers.flatMap(({ models }) => models.map(([m, value]) => ({
19
+ label: M.models[m], color: colors.models[m], value,
20
+ }))) : providers.map(({ name, output: value }) => ({ label: name, color: providerColor(name), value }));
21
+ const leading = segments.reduce<typeof segments[number] | undefined>((best, segment) => (
22
+ !best || segment.value > best.value ? segment : best
23
+ ), undefined);
24
+
25
+ return (
26
+ <section className="donut-panel donut-provider-panel" aria-label={t("out")}>
27
+ <Ring segments={segments}>
28
+ {leading ? <><span>{leading.label}</span><RingValue value={f.pct(leading.value / (total || 1))} /></> : null}
29
+ </Ring>
30
+ <div className="donut-provider-legends">
31
+ <p>{t("providerOutputShare")}</p>
32
+ <div className="donut-provider-groups">
33
+ {providers.map(({ name, output, models }) => (
34
+ <section key={name}>
35
+ <h3>
36
+ <i aria-hidden="true" style={{ background: `var(${providerColor(name)})` }} />
37
+ <span>{name}</span><small className="num">{f.pct(output / (total || 1))}</small>
38
+ </h3>
39
+ <ul aria-label={t("modelBreakdown")}>{models.map(([model, value]) => (
40
+ <li key={model}><i aria-hidden="true" style={{ background: `var(${colors.models[model]})` }} /><span>{M.models[model]}</span>
41
+ <b className="num">{f.cmp(value)}</b><small className="num">{f.pct(value / (total || 1))}</small></li>
42
+ ))}</ul>
43
+ </section>
44
+ ))}
45
+ </div>
46
+ </div>
47
+ </section>
48
+ );
49
+ }
@@ -0,0 +1,6 @@
1
+ import type { Fact } from "../../model.ts";
2
+ import { Projects as RecordProjects } from "../records/Projects.tsx";
3
+
4
+ export function Projects({ F }: { F: Fact[] }) {
5
+ return <RecordProjects F={F} variant="donut" />;
6
+ }
@@ -0,0 +1,30 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ export type RingSegment = { label: string; color: string; value: number };
4
+
5
+ export function Ring({ segments, children }: { segments: RingSegment[]; children: ReactNode }) {
6
+ const total = segments.reduce((sum, segment) => sum + segment.value, 0);
7
+ let offset = 0;
8
+ return (
9
+ <div className="donut-ring">
10
+ <svg viewBox="0 0 100 100" aria-hidden="true">
11
+ <circle cx="50" cy="50" r="40" fill="none" stroke="var(--track)" strokeWidth="15" />
12
+ {segments.map(({ label, color, value }, index) => {
13
+ const length = total ? value / total * 100 : 0;
14
+ const start = offset;
15
+ offset += length;
16
+ return length > 0 ? <circle key={index} cx="50" cy="50" r="40" fill="none" pathLength="100"
17
+ transform="rotate(-90 50 50)" stroke={`var(${color})`} strokeWidth="15"
18
+ strokeDasharray={`${length} ${100 - length}`} strokeDashoffset={-start}><title>{label}</title></circle> : null;
19
+ })}
20
+ </svg>
21
+ <div className="donut-ring-summary">{children}</div>
22
+ </div>
23
+ );
24
+ }
25
+
26
+
27
+ export function RingValue({ value }: { value: string }) {
28
+ // The mono glyphs take about 0.6 em each. Leave space for the curved sides of the ring.
29
+ return <strong className="num" style={{ fontSize: `min(var(--ring-value-max, var(--fs-kpi-lead)), ${150 / value.length}cqi)` }}>{value}</strong>;
30
+ }
@@ -0,0 +1,6 @@
1
+ import type { Fact } from "../../model.ts";
2
+ import { Sessions as RecordSessions } from "../records/Sessions.tsx";
3
+
4
+ export function Sessions({ F }: { F: Fact[] }) {
5
+ return <RecordSessions F={F} variant="donut" />;
6
+ }
@@ -0,0 +1,131 @@
1
+ import { RelatedSessions } from "../../sessionScope.tsx";
2
+ import { useDash } from "../../dash.ts";
3
+ import type { Fact } from "../../model.ts";
4
+ import { useStyleColors } from "../../shell/styleColors.ts";
5
+ import { Empty } from "../../ui.tsx";
6
+ import { buildSubagentsVM } from "../../vm/subagents.ts";
7
+ import { effortColor, ModelBands, ModelDot } from "../console/modelVisuals.tsx";
8
+ import "./models-subagents.css";
9
+
10
+ export function Subagents({ F }: { F: Fact[] }) {
11
+ const { M, filter, t, L, f } = useDash();
12
+ const { models: colors } = useStyleColors();
13
+ const { all, per, subs, routes, types, subOut, models, subLv, moved, subCost, subRequests, lo, hi, same, ranked, subEff } = buildSubagentsVM(M, F, filter.model);
14
+ if (!per.length) return <section className="donut-panel"><Empty /></section>;
15
+ const count = subs.length;
16
+ const share = (value: number, total: number) => value / (total || 1);
17
+ const rankedEfforts = [
18
+ { label: t("belowMain"), value: lo, color: "--effort-1" },
19
+ { label: t("sameMain"), value: same, color: "--effort-2" },
20
+ { label: t("aboveMain"), value: hi, color: "--effort-4" },
21
+ ];
22
+ const kpis = [
23
+ { label: t("subs"), value: f.int(count) },
24
+ { label: t("subCost"), value: f.usd(subCost), detail: L.ofAllCost(f.pct(share(subCost, all.c))) },
25
+ { label: t("subRequests"), value: f.pct(share(subRequests, all.q)), detail: f.int(subRequests) },
26
+ { label: t("otherModel"), value: count ? f.pct(share(moved, count)) : "—", detail: count ? f.int(moved) : undefined },
27
+ { label: t("belowMain"), value: ranked ? f.pct(share(lo, ranked)) : "—", detail: ranked ? f.int(lo) : undefined },
28
+ ];
29
+ const split = (label: string, value: number, total: number, fmt: (n: number) => string, color: string) =>
30
+ <ModelBands label={label} bands={[
31
+ { label: t("mainThread"), share: share(total - value, total), color: "--req", value: fmt(total - value) },
32
+ { label: t("subs"), share: share(value, total), color, value: fmt(value) },
33
+ ]} />;
34
+
35
+ return (
36
+ <div className="donut-view donut-model-view">
37
+ <dl className="donut-sub-kpis">
38
+ {kpis.map(({ label, value, detail }) => (
39
+ <div key={label}>
40
+ <dt>{label}</dt><dd className="num">{value}</dd>
41
+ {detail && <small>{detail}</small>}
42
+ </div>
43
+ ))}
44
+ </dl>
45
+ <div className="donut-model-columns donut-sub-columns">
46
+ <section className="donut-panel">
47
+ <header><h2>{t("mainVsSub")}</h2><RelatedSessions F={F} scope="subagent" /><span className="hint">{t("cost")}</span></header>
48
+ <div className="donut-model-meter-list thread-share-grid">
49
+ {[
50
+ { label: t("cost"), value: subCost, total: all.c, fmt: f.usd, color: "--cost" },
51
+ { label: t("requests"), value: subRequests, total: all.q, fmt: f.int, color: "--req-weak" },
52
+ { label: t("out"), value: subOut, total: all.o, fmt: f.cmp, color: "--work" },
53
+ ].map(({ label, value, total, fmt, color }) => (
54
+ <div className="donut-model-meter-row" key={label}>
55
+ <span>{label}</span>{split(label, value, total, fmt, color)}
56
+ <span className="num">{fmt(total - value)} / {fmt(value)}</span>
57
+ </div>
58
+ ))}
59
+ <ul className="console-model-legend">
60
+ <li><ModelDot color="--req" />{t("mainThread")}</li><li><ModelDot color="--work" />{t("subs")}</li>
61
+ </ul>
62
+ {per.map((r) => <div className="donut-model-meter-row" key={r.m}>
63
+ <span title={r.n}>{r.n}</span>
64
+ {split(r.n, r.sub, r.tt.o, f.cmp, "--work")}
65
+ <span className="num">{f.cmp(r.tt.o)} · {f.pct(share(r.sub, r.tt.o))}</span>
66
+ </div>)}
67
+ </div>
68
+ </section>
69
+ <section className="donut-panel">
70
+ <header><h2>{t("subEffort")}</h2><span className="hint">{t("requests")}</span></header>
71
+ {ranked > 0 && <div className="donut-sub-effort-summary">
72
+ <ModelBands label={t("subEffort")} bands={rankedEfforts.map(({ label, value, color }) => ({
73
+ label, color, share: share(value, ranked), value: f.pct(share(value, ranked)),
74
+ }))} />
75
+ <ul>{rankedEfforts.map(({ label, value, color }) => (
76
+ <li key={label}><span><ModelDot color={color} />{label}</span><strong className="num">{f.pct(share(value, ranked))}</strong></li>
77
+ ))}</ul>
78
+ </div>}
79
+ {subEff.length ? <>
80
+ <ul className="console-model-legend">{subLv.map((e) => <li key={e}><ModelDot color={effortColor(e)} />{M.efforts[e]}</li>)}</ul>
81
+ <div className="donut-model-meter-list">
82
+ {subEff.map(({ n, m, c }) => {
83
+ const sum = c.reduce((a, b) => a + b, 0);
84
+ return <div className="donut-model-meter-row" key={m}>
85
+ <span title={n}>{n}</span>
86
+ <ModelBands label={n} bands={c.map((value, i) => ({
87
+ label: M.efforts[subLv[i]], share: share(value, sum), color: effortColor(subLv[i]),
88
+ value: `${f.int(value)} · ${f.pct(share(value, sum))}`,
89
+ }))} />
90
+ </div>;
91
+ })}
92
+ </div>
93
+ </> : <Empty />}
94
+ </section>
95
+ </div>
96
+ <div className="donut-model-columns">
97
+ <section className="donut-panel">
98
+ <header><h2>{t("routedTitle")}</h2><span className="hint">{f.int(count)} {t("subs")}</span></header>
99
+ {routes.length ? (
100
+ <ul className="donut-sub-routes">
101
+ {routes.flatMap(({ n, p, row }) => row.flatMap((value, m) => value ? (
102
+ <li key={`${p}-${m}`}>
103
+ <span title={n}><ModelDot color={colors[p]} />{n}</span><span aria-hidden="true">→</span>
104
+ <span title={M.models[m]}><ModelDot color={colors[m]} />{M.models[m]}</span>
105
+ <strong className="num" aria-label={L.spawnedOn(n, M.models[m]) + " " + f.int(value)}>{f.int(value)}</strong>
106
+ </li>
107
+ ) : []))}
108
+ </ul>
109
+ ) : <Empty />}
110
+ </section>
111
+ <section className="donut-panel">
112
+ <header><h2>{t("subTypes")}</h2></header>
113
+ <ul className="console-model-legend">{models.map((m) => <li key={m}><ModelDot color={colors[m]} />{M.models[m]}</li>)}</ul>
114
+ {types.length ? <table className="console-model-table">
115
+ <thead><tr>{[t("subs"), t("count"), t("ranOn"), t("out")].map((label, i) =>
116
+ <th key={label} scope="col" className={i % 2 ? "num" : undefined}>{label}</th>
117
+ )}</tr></thead>
118
+ <tbody>{types.map(({ n, count, mix, o }) => <tr key={n}>
119
+ <th scope="row" title={n}>{n}</th>
120
+ <td className="num" data-label={t("count")}>{f.int(count)}</td>
121
+ <td data-label={t("ranOn")}><ModelBands label={n} bands={mix.map((value, m) => ({
122
+ label: M.models[m], share: share(value, count), color: colors[m], value: f.int(value),
123
+ }))} /></td>
124
+ <td className="num" data-label={t("out")}>{f.cmp(o)}</td>
125
+ </tr>)}</tbody>
126
+ </table> : <Empty />}
127
+ </section>
128
+ </div>
129
+ </div>
130
+ );
131
+ }