Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
UI: Insights measures on the board (C, #184)
Pixel (kwant bot)4387b3355251
diff --git a/frontend/src/components/MissionBoardView.tsx b/frontend/src/components/MissionBoardView.tsxindex e5f2f9f3..9251a943 100644--- a/frontend/src/components/MissionBoardView.tsx+++ b/frontend/src/components/MissionBoardView.tsx@@ -139,6 +139,7 @@ import {eventText,formatBytes,formatTokens,+ measuresView,groupByColumn,missionStatusLabel,missionsApi,@@ -454,6 +455,75 @@ export const InsightsStrip: React.FC<{);};+/**+ * Phase C measures: verified tasks per active week over 8 weeks, and what one verified result cost.+ * Renders nothing on a server that doesn't send them. An unknown cost is never shown as $0.+ */+export const MeasuresPanel: React.FC<{ insights: Insights | null; timeZone?: string }> = ({ insights, timeZone }) => {+ const headId = useId();+ const v = measuresView(insights, timeZone);+ if (!v) return null;+ return (+ <section aria-labelledby={headId} className={`${card} px-3 py-2.5`} data-measures>+ <h3 id={headId} className="sr-only">+ Measures+ </h3>+ <div className="grid gap-3 sm:grid-cols-[minmax(0,10rem)_minmax(0,1fr)_minmax(0,12rem)] sm:items-end">+ <dl className="min-w-0" data-measure="per-week">+ <dt className="text-[11px] text-zinc-400">Verified per active week</dt>+ <dd className="text-lg font-semibold tabular-nums text-emerald-300">{v.headline}</dd>+ <dd className="text-[10px] text-zinc-400">{v.headlineSub}</dd>+ </dl>++ <figure className="min-w-0" data-measure="trend">+ <ol+ className="flex h-14 items-end gap-1"+ aria-label={`Verified tasks per week, oldest first: ${v.trendText}`}+ data-weeks={v.weeks.length}+ >+ {v.weeks.map((w, n) => (+ <li key={n} className="flex h-full flex-1 flex-col justify-end" title={w.text} data-week={w.verified} data-active={w.active}>+ <span className="sr-only">{w.text}</span>+ <span+ aria-hidden="true"+ className={`block w-full rounded-sm ${+ w.verified > 0+ ? n === v.weeks.length - 1+ ? 'bg-emerald-400'+ : 'bg-emerald-500/60'+ : w.active+ ? 'bg-zinc-600'+ : 'border-t border-dashed border-zinc-700'+ }`}+ style={{ height: w.verified > 0 ? `${Math.max(8, Math.round(w.height * 100))}%` : w.active ? '2px' : '0' }}+ />+ </li>+ ))}+ </ol>+ <figcaption className="mt-1 flex justify-between text-[10px] text-zinc-500" aria-hidden="true">+ <span>8 weeks ago</span>+ <span>This week</span>+ </figcaption>+ </figure>++ <dl className="min-w-0" data-measure="cost">+ <dt className="text-[11px] text-zinc-400">Cost per verified result</dt>+ <dd className={`text-lg font-semibold tabular-nums ${/^[<$]/.test(v.cost) ? 'text-zinc-100' : 'text-zinc-400'}`} data-cost={v.cost}>+ {v.cost}+ </dd>+ <dd className="text-[10px] text-zinc-400">{v.costSub}</dd>+ {v.costWarning && (+ <dd className="mt-0.5 flex items-start gap-1 text-[10px] text-amber-300" data-cost-warning>+ <AlertTriangle size={11} className="mt-px shrink-0" aria-hidden="true" />+ <span>{v.costWarning}</span>+ </dd>+ )}+ </dl>+ </div>+ </section>+ );+};+// ---------- Missions ----------export const MissionSummary: React.FC<{@@ -2644,6 +2714,7 @@ export const MissionBoardView: React.FC<MissionBoardViewProps> = ({{liveShown && <LiveStrip bots={liveShown} teams={teams} workingCards={workingCards} now={now} onOpen={onOpenLive} />}<InsightsStrip insights={insights} needsYou={needsYouCount(tasks)} />+ <MeasuresPanel insights={insights} /><FactsLedger names={names} taskTitles={taskTitles} onOpenTask={openTaskById} now={now} /><TierRequests names={names} now={now} />diff --git a/frontend/src/missions.ts b/frontend/src/missions.tsindex b1cef367..0edf237b 100644--- a/frontend/src/missions.ts+++ b/frontend/src/missions.ts@@ -585,6 +585,108 @@ export function formatTokens(n: number): string {}const trim = (x: number) => (Math.abs(x) >= 100 ? String(Math.round(x)) : x.toFixed(1).replace(/\.0$/, ''));+/** A dollar amount as people read it: "$0.33", "$12", "<$0.01". Null stays null, never "$0". */+export function usdText(n: number | null | undefined): string | null {+ if (typeof n !== 'number' || !Number.isFinite(n) || n < 0) return null;+ if (n === 0) return '$0.00';+ if (n < 0.01) return '<$0.01';+ if (n < 100) return `$${n.toFixed(2)}`;+ return `$${Math.round(n).toLocaleString('en-US')}`;+}++export interface WeekBar {+ /** "Oct 25" for the week's last day. */+ label: string;+ verified: number;+ active: boolean;+ /** 0–1 against the busiest week. */+ height: number;+ /** One line for screen readers and the tooltip. */+ text: string;+}++export interface MeasuresView {+ /** Verified per active week, one decimal, or "—" with no active week. */+ headline: string;+ headlineSub: string;+ weeks: WeekBar[];+ /** "$0.33", "Not reported" (cost unknown) or "—" (nothing settled). */+ cost: string;+ costSub: string;+ /** Set when some settled runs reported no cost: what the figure is based on instead. */+ costWarning: string | null;+ /** The bars for one summary line, e.g. "0, 0, 1, 3, 0, 2, 4, 2". */+ trendText: string;+}++const plural = (n: number, one: string, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;++/** The day a rolling week ends on, as "Oct 25". The last week ends now, so it reads "This week". */+export function weekLabel(endIso: string, last: boolean, timeZone?: string): string {+ if (last) return 'This week';+ const d = new Date(endIso);+ if (Number.isNaN(d.getTime())) return '';+ // The week runs up to `end`, exclusive: label it with its last whole day.+ const day = new Date(d.getTime() - 1);+ return `Week to ${day.toLocaleDateString('en-US', { month: 'short', day: 'numeric', ...(timeZone ? { timeZone } : {}) })}`;+}++/**+ * The Phase C measures (verified per active week and cost per verified result), or null on a server+ * that doesn't send them, so the board looks as before.+ */+export function measuresView(i: Insights | null | undefined, timeZone?: string): MeasuresView | null {+ if (!i || !Array.isArray(i.verified_weekly) || i.verified_weekly.length === 0) return null;+ const weeks = i.verified_weekly;+ const max = Math.max(1, ...weeks.map((w) => w.verified));+ const bars: WeekBar[] = weeks.map((w, n) => {+ const label = weekLabel(w.end, n === weeks.length - 1, timeZone);+ const text = `${label}: ${w.verified} verified${w.active ? '' : ', no activity'}`;+ return { label, verified: w.verified, active: w.active, height: w.verified / max, text };+ });+ const active = i.active_weeks ?? weeks.filter((w) => w.active).length;+ const per = i.verified_per_active_week;+ const headline = typeof per === 'number' && active > 0 ? per.toFixed(1).replace(/\.0$/, '') : '—';+ const headlineSub =+ active > 0+ ? `Average over ${plural(active, 'active week')} of the last ${weeks.length}`+ : `No task activity in the last ${weeks.length} weeks yet`;++ const settled = i.settled_7d ?? 0;+ const unpriced = i.unpriced_7d ?? 0;+ const verified = i.verified_observed_7d ?? i.verified_7d;+ // The divisor of the per-result cost: verified tasks that reported one.+ const priced = i.verified_priced_7d ?? verified;+ const perCost = usdText(i.cost_per_verified_7d_usd);+ const total = usdText(i.cost_7d_usd);+ let cost: string;+ let costSub: string;+ if (perCost) {+ cost = perCost;+ costSub = `${total ?? '$0.00'} over ${plural(settled, 'settled task')} this week, failed runs included`;+ } else if (settled === 0) {+ cost = '—';+ costSub = 'No tasks settled this week';+ } else if (total && verified === 0) {+ // Money went out but nothing was verified: there's no "per result" to show, so show what it cost.+ cost = '—';+ costSub = `${total} spent on ${plural(settled, 'settled task')} with nothing verified yet`;+ } else if (total) {+ // Some runs reported a cost, but none of the verified ones did: no honest per-result figure.+ cost = 'Not reported';+ costSub = `None of the ${plural(verified, 'verified result')} reported a cost; ${total} came from other runs`;+ } else {+ cost = 'Not reported';+ costSub = `None of the ${plural(settled, 'settled task')} this week reported a cost`;+ }+ // With runs missing a cost, the figure is an estimate from the priced ones: say what it rests on.+ const costWarning =+ unpriced > 0 && perCost+ ? `Based on ${plural(priced, 'verified result')} that reported a cost; ${plural(unpriced, 'run')} reported none.`+ : null;+ return { headline, headlineSub, weeks: bars, cost, costSub, costWarning, trendText: weeks.map((w) => w.verified).join(', ') };+}+/** "12.4k of 50k tokens"; "64.9k tokens used" when there's no limit (budget 0). */export function costText(spent: number, budget: number): string {return budget > 0 ? `${formatTokens(spent)} of ${formatTokens(budget)} tokens` : `${formatTokens(spent)} tokens used`;diff --git a/frontend/tests/measures.test.mjs b/frontend/tests/measures.test.mjsnew file mode 100644index 00000000..da6bafb1--- /dev/null+++ b/frontend/tests/measures.test.mjs@@ -0,0 +1,140 @@+// Phase C measures (docs/mission-control.md §6, "Measures (Phase C)"): verified tasks per active+// week over 8 rolling weeks, and cost per verified result. An unknown cost is never shown as $0, and+// a server without the measures shows the board as before.+import assert from 'node:assert/strict';+import test from 'node:test';+import { loadBundled } from './bundle.mjs';++globalThis.localStorage ??= { getItem: () => null, setItem: () => {}, removeItem: () => {} };++const m = await loadBundled(`export * from './src/missions';`);+const ui = await loadBundled(`+ import React from 'react';+ import { renderToStaticMarkup } from 'react-dom/server.browser';+ import { MeasuresPanel } from './src/components/MissionBoardView';+ export const panel = (p) => renderToStaticMarkup(React.createElement(MeasuresPanel, { timeZone: 'UTC', ...p }));+`);++const text = (html) => html.replace(/<[^>]+>/g, ' ').replace(/'|'/g, "'").replace(/"/g, '"').replace(/&/g, '&').replace(/</g, '<').replace(/\s+/g, ' ').trim();++const DAY = 86_400_000;+const NOW = Date.parse('2026-11-01T00:00:00Z');+const weeks = (counts, active = counts.map((n) => n > 0)) =>+ counts.map((verified, i) => ({+ start: new Date(NOW - (counts.length - i) * 7 * DAY).toISOString(),+ end: new Date(NOW - (counts.length - 1 - i) * 7 * DAY).toISOString(),+ verified,+ active: active[i],+ }));+const base = { verified_7d: 2, false_success_7d: 0, needs_you_now: 0, blocked_now: 0, interventions_7d: 0, tokens_7d: 0, tokens_per_verified_7d: null };+const insights = (over = {}) => ({+ ...base,+ verified_weekly: weeks([0, 0, 1, 3, 0, 0, 4, 2], [false, false, true, true, true, false, true, true]),+ active_weeks: 5,+ verified_per_active_week: 2.0,+ cost_7d_usd: 0.65,+ cost_per_verified_7d_usd: 0.325,+ verified_observed_7d: 2,+ verified_priced_7d: 2,+ settled_7d: 4,+ unpriced_7d: 0,+ ...over,+});++test('an older server without the measures shows nothing new', () => {+ assert.equal(m.measuresView(base), null);+ assert.equal(m.measuresView(null), null);+ assert.equal(m.measuresView({ ...base, verified_weekly: [] }), null);+ assert.equal(ui.panel({ insights: base }), '');+ assert.equal(ui.panel({ insights: null }), '');+});++test('dollar amounts read the way people write them, and unknown stays unknown', () => {+ assert.equal(m.usdText(0.325), '$0.33');+ assert.equal(m.usdText(0.004), '<$0.01');+ assert.equal(m.usdText(0), '$0.00');+ assert.equal(m.usdText(12), '$12.00');+ assert.equal(m.usdText(1234.5), '$1,235');+ assert.equal(m.usdText(null), null);+ assert.equal(m.usdText(undefined), null);+ assert.equal(m.usdText(Number.NaN), null);+ assert.equal(m.usdText(-1), null);+});++test('the headline is verified per active week, with the 8-week trend oldest first', () => {+ const html = ui.panel({ insights: insights() });+ const t = text(html);+ assert.match(t, /Verified per active week 2 Average over 5 active weeks of the last 8/);+ assert.equal((html.match(/data-week=/g) ?? []).length, 8);+ assert.match(html, /aria-label="Verified tasks per week, oldest first: 0, 0, 1, 3, 0, 0, 4, 2"/);+ // Every bar has its own words for screen readers, and the last one is this week.+ assert.match(t, /This week: 2 verified/);+ assert.match(t, /Week to Oct 24: 4 verified/);+ assert.match(t, /Week to Sep 12: 0 verified, no activity/);+ // The busiest week is full height; an active empty week is a thin line, an inactive one dashed.+ assert.match(html, /data-week="4"[^>]*>.*?height:100%/);+ assert.match(html, /data-week="0" data-active="true"[^>]*>.*?height:2px/);+ assert.match(html, /data-week="0" data-active="false"[^>]*>.*?border-dashed/);+});++test('cost per verified result shows dollars, the total, and that failed runs are included', () => {+ const t = text(ui.panel({ insights: insights() }));+ assert.match(t, /Cost per verified result \$0\.33 \$0\.65 over 4 settled tasks this week, failed runs included/);+ assert.doesNotMatch(t, /didn’t report/);+});++test('runs without a reported cost are called out with what the figure rests on, never counted as $0', () => {+ // Lin's API: cost_7d_usd / verified_priced_7d. 2 of 3 verified results reported a cost.+ const one = ui.panel({ insights: insights({ verified_observed_7d: 3, verified_priced_7d: 2, unpriced_7d: 1 }) });+ assert.match(one, /data-cost="\$0\.33"/);+ assert.match(text(one), /Based on 2 verified results that reported a cost; 1 run reported none\./);+ assert.match(one, /data-cost-warning/);+ assert.doesNotMatch(text(one), /real figure is higher/);+ const three = text(ui.panel({ insights: insights({ verified_priced_7d: 1, unpriced_7d: 3 }) }));+ assert.match(three, /Based on 1 verified result that reported a cost; 3 runs reported none\./);++ // Nothing reported a cost at all: "Not reported", not $0.00.+ const none = ui.panel({ insights: insights({ cost_7d_usd: null, cost_per_verified_7d_usd: null, verified_priced_7d: 0, unpriced_7d: 4 }) });+ assert.match(none, /data-cost="Not reported"/);+ assert.match(text(none), /None of the 4 settled tasks this week reported a cost/);+ assert.doesNotMatch(text(none), /\$0/);+ assert.doesNotMatch(none, /data-cost-warning/);+});++test('failed runs reported a cost but no verified result did: no per-result figure, and no $0', () => {+ const html = ui.panel({ insights: insights({ cost_7d_usd: 0.4, cost_per_verified_7d_usd: null, verified_priced_7d: 0, unpriced_7d: 2 }) });+ assert.match(html, /data-cost="Not reported"/);+ assert.match(text(html), /None of the 2 verified results reported a cost; \$0\.40 came from other runs/);+ assert.doesNotMatch(html, /data-cost="\$/);+});++test('money spent with nothing verified shows what was spent, not a per-result price', () => {+ const html = ui.panel({ insights: insights({ verified_observed_7d: 0, verified_7d: 0, cost_7d_usd: 0.15, cost_per_verified_7d_usd: null, settled_7d: 1 }) });+ assert.match(html, /data-cost="—"/);+ assert.match(text(html), /\$0\.15 spent on 1 settled task with nothing verified yet/);+});++test('a new space: no activity yet, no settled tasks, and a flat trend', () => {+ const html = ui.panel({+ insights: insights({+ verified_7d: 0,+ verified_weekly: weeks([0, 0, 0, 0, 0, 0, 0, 0]),+ active_weeks: 0,+ verified_per_active_week: null,+ cost_7d_usd: null,+ cost_per_verified_7d_usd: null,+ verified_observed_7d: 0,+ settled_7d: 0,+ unpriced_7d: 0,+ }),+ });+ const t = text(html);+ assert.match(t, /Verified per active week — No task activity in the last 8 weeks yet/);+ assert.match(t, /Cost per verified result — No tasks settled this week/);+ assert.doesNotMatch(t, /\$/);+});++test('the board shows the measures under the week strip', async () => {+ const src = await import('node:fs').then((fs) => fs.readFileSync(new URL('../src/components/MissionBoardView.tsx', import.meta.url), 'utf8'));+ assert.match(src, /<InsightsStrip [^>]*\/>\s*<MeasuresPanel insights=\{insights\} \/>/);+});