From dfc2d40a51eebb1f66a4fa762d737eaf922cacf3 Mon Sep 17 00:00:00 2001 From: Devika Verma Date: Thu, 5 Nov 2026 13:54:37 +0530 Subject: [PATCH] fix(observability): a second small chart for everything but main work (T3-7) Main work is often 97% of the tokens, so summaries, the auto-approver and session titles were hairlines. Under the main chart, the same days without main work on their own scale, and a line saying a bar shows each part's tokens when pointed at. --- surfaces/gui/src/components/UsagePage.tsx | 62 ++++++++++++++++------- surfaces/gui/src/locales/en.json | 3 ++ surfaces/gui/src/locales/zh.json | 3 ++ surfaces/gui/src/obs3.test.ts | 13 +++++ surfaces/gui/src/obs3.ts | 10 ++++ surfaces/gui/src/styles.css | 1 + 6 files changed, 73 insertions(+), 19 deletions(-) diff --git a/surfaces/gui/src/components/UsagePage.tsx b/surfaces/gui/src/components/UsagePage.tsx index 8b7361ad..c6fd3a9d 100644 --- a/surfaces/gui/src/components/UsagePage.tsx +++ b/surfaces/gui/src/components/UsagePage.tsx @@ -23,6 +23,7 @@ import { comparable, hhmm, localDays, + overheadByDay, previousDays, purposeByDay, SERIES, @@ -168,6 +169,7 @@ export function UsageBody({ data, period, t, onOpenTurn }: { data: UsageData; pe const canCompare = comparable(data.total.kept_from, prevStart); const pct = canCompare && prev ? changePct(all?.total ?? 0, prev.total) : null; const chart = purposeByDay(days, data.dayPurpose.groups); + const overhead = overheadByDay(chart); const names = data.total.names || data.coworkers.names || {}; const turns = all?.turns ?? 0; const checked = all?.checked ?? 0; @@ -194,30 +196,22 @@ export function UsageBody({ data, period, t, onOpenTurn }: { data: UsageData; pe
{t("p3.usage.per_day")} -
- {chart.rows.map((r) => ( -
- {SERIES.map((s) => - r.values[s] ? ( - - ) : null, - )} -
- ))} -
- {days.length > 1 && ( -
- {days.map(([label, start]) => ( - {days.length <= 7 ? new Date(start).toLocaleDateString(undefined, { weekday: "short", day: "2-digit" }) : new Date(start).getDate()} - ))} -
- )} + +
{SERIES.filter((s) => chart.legend[s] > 0).map((s) => ( {t(`p3.series.${s}`)} {formatTokens(chart.legend[s])} ))}
+ {overhead && ( +
+ {t("p3.usage.overhead")} +
{t("p3.usage.overhead_sub", { tokens: formatTokens(overhead.max) })}
+ + +
+ )} +
{t("p3.usage.point_hint")}
{t("p3.usage.by_coworker")} @@ -294,6 +288,36 @@ export function UsageBody({ data, period, t, onOpenTurn }: { data: UsageData; pe ); } +type ChartRow = { label: string; values: Record; total: number }; + +function Bars({ rows, max, series, t, small, testid }: { rows: ChartRow[]; max: number; series: readonly string[]; t: T; small?: boolean; testid: string }) { + return ( +
+ {rows.map((r) => ( +
+ {series.map((s) => + r.values[s] ? ( + + ) : null, + )} +
+ ))} +
+ ); +} + +function DayLabels({ days }: { days: [string, number, number][] }) { + if (days.length <= 1) return null; + return ( +
+ {days.map(([label, start]) => ( + {days.length <= 7 ? new Date(start).toLocaleDateString(undefined, { weekday: "short", day: "2-digit" }) : new Date(start).getDate()} + ))} +
+ ); +} + function Tile({ label, value, sub, testid }: { label: string; value: string; sub: string; testid?: string }) { return (
diff --git a/surfaces/gui/src/locales/en.json b/surfaces/gui/src/locales/en.json index 5978fd88..44b11cfd 100644 --- a/surfaces/gui/src/locales/en.json +++ b/surfaces/gui/src/locales/en.json @@ -3935,6 +3935,9 @@ "not_checked_other": "{{count}} not checked yet", "median_sub": "waiting for you not counted", "per_day": "Tokens per day, by purpose", + "overhead": "Everything but main work", + "overhead_sub": "On its own scale: the tallest day is {{tokens}} tokens.", + "point_hint": "Point at a bar to see each part's tokens.", "by_coworker": "By coworker", "coworker": "Coworker", "automation": "(automation)", diff --git a/surfaces/gui/src/locales/zh.json b/surfaces/gui/src/locales/zh.json index e8f837c9..b1d24e1a 100644 --- a/surfaces/gui/src/locales/zh.json +++ b/surfaces/gui/src/locales/zh.json @@ -3876,6 +3876,9 @@ "not_checked_other": "{{count}} 个尚未检查", "median_sub": "不计等你的时间", "per_day": "每天的令牌,按用途", + "overhead": "主要工作以外的全部", + "overhead_sub": "单独的刻度:最高的一天为 {{tokens}} 令牌。", + "point_hint": "指向柱形可查看每一部分的令牌数。", "by_coworker": "按同事", "coworker": "同事", "automation": "(自动化)", diff --git a/surfaces/gui/src/obs3.test.ts b/surfaces/gui/src/obs3.test.ts index 7e02b18f..72cf372f 100644 --- a/surfaces/gui/src/obs3.test.ts +++ b/surfaces/gui/src/obs3.test.ts @@ -7,6 +7,7 @@ import { footerParts, healthTone, localDays, + overheadByDay, previousDays, purposeByDay, seriesOf, @@ -69,6 +70,18 @@ describe("tokens per day, by purpose", () => { expect(out.rows[1].total).toBe(7); expect(out.legend).toEqual({ main: 120, summary: 0, auto_approver: 7, title: 3, other: 0 }); }); + it("the second chart leaves main work out and has its own scale (T3-7)", () => { + const days: [string, number, number][] = [["d1", 0, 10], ["d2", 10, 20]]; + const g = (day: string, purpose: string, total: number) => ({ key: { day, purpose }, total }) as any; + const chart = purposeByDay(days, [g("d1", "main", 17_000_000), g("d1", "summary", 36_000), g("d2", "auto_approver", 457_000), g("d2", "title", 7_700)]); + const o = overheadByDay(chart)!; + expect(o.series).toEqual(["summary", "auto_approver", "title", "other"]); + expect(o.rows.map((r) => r.total)).toEqual([36_000, 464_700]); + expect(o.max).toBe(464_700); // not the 17M of main work + expect(o.rows[0].values.main).toBe(0); + // only main work: no second chart + expect(overheadByDay(purposeByDay(days, [g("d1", "main", 5)]))).toBeNull(); + }); }); describe("the Auto-approve strip", () => { diff --git a/surfaces/gui/src/obs3.ts b/surfaces/gui/src/obs3.ts index 6c9f79a3..b0619ce3 100644 --- a/surfaces/gui/src/obs3.ts +++ b/surfaces/gui/src/obs3.ts @@ -105,6 +105,16 @@ export function purposeByDay(days: DayBoundary[], groups: RollupGroup[]) { return { rows, legend, max: Math.max(1, ...rows.map((r) => r.total)) }; } +/** T3-7: the same days without main work, on their own scale, so summaries, the + * auto-approver and titles get a readable size (main work is often 95% or more). Null when + * the period has none of them. */ +export function overheadByDay(chart: ReturnType) { + const series = SERIES.filter((s) => s !== "main"); + const rows = chart.rows.map((r) => ({ ...r, values: { ...r.values, main: 0 }, total: r.total - r.values.main })); + const max = Math.max(0, ...rows.map((r) => r.total)); + return max > 0 ? { rows, max, series } : null; +} + // -- the Auto-approve strip (§7.3, M3-R5) ----------------------------------------------------- /** Under 10 checks a part is a count ("allowed 1"), from 10 a share ("allowed 72%"): "allowed * 100%" of one check says nothing. */ diff --git a/surfaces/gui/src/styles.css b/surfaces/gui/src/styles.css index ce359554..7c032c75 100644 --- a/surfaces/gui/src/styles.css +++ b/surfaces/gui/src/styles.css @@ -2620,6 +2620,7 @@ html[data-theme="dark"] { --bar-model:#4c8dff; --bar-tool:#3fb8ad; --bar-wait:#3 .p3-card { padding:12px 14px; min-width:0; } .p3-h { font-weight:500; font-size:var(--fs-ui); color:var(--ink); } .p3-bars { display:flex; align-items:flex-end; gap:3px; height:120px; margin-top:10px; border-bottom:1px solid var(--line); } +.p3-bars.small { height:56px; margin-top:6px; } /* T3-7 */ .p3-bar { flex:1; height:100%; display:flex; flex-direction:column-reverse; min-width:2px; } .p3-bar i { display:block; width:100%; } .p3-bar i:last-child { border-radius:3px 3px 0 0; }