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
Sidebar: bot status dots (Available, Working, Needs you, Queued, Can't run)
Pixel (kwant bot)a001b316d3d7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 01a56ee9..2fde12c5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).## Unreleased### Added+- **Bot status dots.** The dot on each bot's avatar in the sidebar now says what the bot is doing:+ green Available, a pulsing Working dot, amber Needs you, a hollow Queued ring, and grey Can't run.+ A bot with a running turn never shows green, in the open chat included, and hovering or a screen+ reader gives the status in words. The line under the name says "Working here" for the open chat.- **Truth Ledger, shadow mode (Mission Control Phase C1).** A new `truth_ledger` setting (off bydefault; `shadow`, or `on`, which behaves like shadow for now) lets you see every bot note as a factwith where it came from. Notes a bot wrote after reading a web page, a file or another tool, anddiff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex 7ed22b98..fc776848 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -47,6 +47,7 @@ import { playSfx } from './audio/chiptune';import { haptic, messageHaptic } from './haptics';import { Toasts, Toast } from './components/Toasts';import { clearAllTurns, resetTurns, turnEnded, turnStarted } from './kwantActivity';+import { botStatuses, busyLines } from './botStatus';import {ChatLoads,Delegation,@@ -2564,12 +2565,9 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({{pendingHere === 1 ? '1 skill to review' : `${pendingHere} skills to review`}</button>) : null;- // Sidebar: bots busy somewhere other than the open chat.- const busyKwants: Record<string, string> = {};- for (const t of Object.values(turns)) {- if (t.context_id === openCtx || busyKwants[t.kwant_id]) continue;- busyKwants[t.kwant_id] = `${t.state === 'queued' ? 'Waiting to work on' : browserTurns.has(t.turn_id) ? 'Needs you in the browser in' : awaitingTurns.has(t.turn_id) ? 'Asked you a question in' : 'Working on'} ${describeContext(t.context_id, t.kwant_id)}`;- }+ // Sidebar: what busy bots are doing, "here" for the open chat.+ const busyKwants = busyLines({ turns: Object.values(turns), openCtx, awaiting: awaitingTurns, browser: browserTurns, describe: describeContext });+ const botStatus = botStatuses({ turns: Object.values(turns), awaiting: awaitingTurns, needsYou: needsYouByKwant });// Delete is off while the bot runs anywhere, the open chat included.const workingKwants = new Set(Object.values(turns).map((t) => t.kwant_id));@@ -2785,6 +2783,7 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({isChannel={isChannel}selectedTeamId={selectedTeamId}busyKwants={busyKwants}+ botStatus={botStatus}needsYou={needsYouByKwant}onSelectKwant={handleSelectKwant}onSelectChannel={handleSelectChannel}diff --git a/frontend/src/botStatus.ts b/frontend/src/botStatus.tsnew file mode 100644index 00000000..bad2fec1--- /dev/null+++ b/frontend/src/botStatus.ts@@ -0,0 +1,87 @@+// One status per bot for the dot on its avatar: what it's doing right now, from its turns and whether+// anything can run. A bot with a running turn is never "Available", the open chat included.++export type BotStatus = 'needs_you' | 'working' | 'queued' | 'cant_run' | 'available';++export interface StatusTurn {+ turn_id: string;+ kwant_id: string;+ state: 'queued' | 'running';+ context_id?: string;+}++export interface StatusInputs {+ turns: Iterable<StatusTurn>;+ /** Running turns paused on a question or a browser step for the person. */+ awaiting?: ReadonlySet<string>;+ /** Open browser steps per bot. */+ needsYou?: Readonly<Record<string, number>>;+ /** false when no account works here; null or undefined while that is still unknown. */+ canRun?: boolean | null;+}++/** Highest first: the status a bot shows when several apply. */+export const STATUS_PRIORITY: readonly BotStatus[] = ['needs_you', 'working', 'queued', 'cant_run', 'available'];++export const STATUS_LABEL: Record<BotStatus, string> = {+ needs_you: 'Needs you',+ working: 'Working',+ queued: 'Queued',+ cant_run: "Can't run",+ available: 'Available',+};++const rank = (s: BotStatus) => STATUS_PRIORITY.indexOf(s);+const higher = (a: BotStatus | undefined, b: BotStatus): BotStatus => (a && rank(a) <= rank(b) ? a : b);++/** Status for every bot that has turns or open steps; bots not listed are idle. */+export function botStatuses({ turns, awaiting, needsYou = {} }: StatusInputs): Record<string, BotStatus> {+ const out: Record<string, BotStatus> = {};+ for (const t of turns) {+ if (!t?.kwant_id) continue;+ const s: BotStatus = t.state === 'queued' ? 'queued' : awaiting?.has(t.turn_id) ? 'needs_you' : 'working';+ out[t.kwant_id] = higher(out[t.kwant_id], s);+ }+ for (const [id, n] of Object.entries(needsYou)) if (n > 0) out[id] = 'needs_you';+ return out;+}++/** One bot's status: its turns first, then whether it can run at all. */+export function statusOf(kwantId: string, statuses: Readonly<Record<string, BotStatus>>, canRun?: boolean | null): BotStatus {+ return statuses[kwantId] ?? (canRun === false ? 'cant_run' : 'available');+}++/** Words for the avatar's tooltip and screen readers: "Editor · Working". */+export const statusText = (name: string | undefined, status: BotStatus): string =>+ name ? `${name} · ${STATUS_LABEL[status]}` : STATUS_LABEL[status];++/** The dot's classes; Working pulses unless the person asked for less motion. */+export const STATUS_DOT: Record<BotStatus, string> = {+ needs_you: 'bg-amber-400',+ working: 'bg-sky-400 animate-pulse motion-reduce:animate-none',+ queued: 'bg-zinc-950 border-2 border-zinc-400',+ cant_run: 'bg-zinc-600',+ available: 'bg-emerald-400',+};++/**+ * The line under each busy bot's name. Running beats queued so it agrees with the dot; other chats+ * come before the open one, which reads "here" instead of naming itself.+ */+export function busyLines({ turns, openCtx, awaiting, browser, describe }: {+ turns: Iterable<StatusTurn>;+ openCtx: string;+ awaiting?: ReadonlySet<string>;+ browser?: ReadonlySet<string>;+ describe: (contextId: string, kwantId: string) => string;+}): Record<string, string> {+ const out: Record<string, string> = {};+ const later = (t: StatusTurn) => (t.state === 'queued' ? 2 : 0) + (t.context_id === openCtx ? 1 : 0);+ for (const t of [...turns].sort((x, y) => later(x) - later(y))) {+ if (!t?.kwant_id || out[t.kwant_id]) continue;+ const what = t.state === 'queued' ? 'Waiting to work' : browser?.has(t.turn_id) ? 'Needs you in the browser' : awaiting?.has(t.turn_id) ? 'Asked you a question' : 'Working';+ out[t.kwant_id] =+ t.context_id === openCtx ? `${what} here` : `${what} ${t.state === 'queued' || what === 'Working' ? 'on' : 'in'} ${describe(t.context_id ?? '', t.kwant_id)}`;+ }+ return out;+}diff --git a/frontend/src/components/ModernAvatar.tsx b/frontend/src/components/ModernAvatar.tsxindex 68d641d9..6e1d1a01 100644--- a/frontend/src/components/ModernAvatar.tsx+++ b/frontend/src/components/ModernAvatar.tsx@@ -1,11 +1,13 @@import React, { useCallback, useSyncExternalStore } from 'react';import { isKwantWorking, subscribeKwant } from '../kwantActivity';+import { STATUS_DOT, STATUS_PRIORITY, statusText, type BotStatus } from '../botStatus';interface ModernAvatarProps {role?: string;name?: string;size?: number; // pixel diameter- isOnline?: boolean;+ /** Draws the status dot; a bot with a running turn shows Working even if this lags behind. */+ status?: BotStatus;className?: string;/** The kwant this avatar shows; it animates while that kwant is working on a turn. */kwantId?: string;@@ -327,11 +329,14 @@ export const ModernAvatar: React.FC<ModernAvatarProps> = ({role = 'default',name = '',size = 36,- isOnline,+ status,className = '',kwantId,}) => {const working = useKwantWorking(kwantId);+ // Never green (or idle grey) while a turn runs: the turn stream wins over a stale status.+ const shown = status && working && STATUS_PRIORITY.indexOf(status) > STATUS_PRIORITY.indexOf('working') ? 'working' : status;+ const label = shown ? statusText(name, shown) : name ? (working ? `${name} is working…` : name) : undefined;const creature = pickCreature(role, name);// At tiny sizes the frame would dominate, so zoom in on the creature aloneconst framed = size > 20;@@ -342,8 +347,9 @@ export const ModernAvatar: React.FC<ModernAvatarProps> = ({<divclassName={`kw-avatar relative inline-flex flex-shrink-0 select-none ${working ? 'kw-avatar-working' : ''} ${className}`}style={{ width: size, height: size }}- title={name ? (working ? `${name} is working…` : name) : undefined}+ title={label}data-working={working || undefined}+ data-status={shown}>{working && <span className="kw-avatar-ring" aria-hidden="true" />}<svg@@ -366,12 +372,11 @@ export const ModernAvatar: React.FC<ModernAvatarProps> = ({</g></svg>{working && <span className="kw-avatar-pip" aria-hidden="true" />}- {isOnline !== undefined && (- <span- className={`absolute bottom-0 right-0 w-2.5 h-2.5 rounded-full ring-2 ring-zinc-950 ${- isOnline ? 'bg-emerald-400' : 'bg-zinc-600'- }`}- />+ {shown && (+ <>+ <span className={`absolute bottom-0 right-0 w-2.5 h-2.5 rounded-full ring-2 ring-zinc-950 ${STATUS_DOT[shown]}`} aria-hidden="true" />+ <span className="sr-only">{label}</span>+ </>)}</div>);diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsxindex db4e0c74..0a087719 100644--- a/frontend/src/components/Sidebar.tsx+++ b/frontend/src/components/Sidebar.tsx@@ -4,6 +4,7 @@ import { ModernAvatar } from './ModernAvatar';import { playSfx } from '../audio/chiptune';import { badgeText } from '../away';import { canRunNow, isUsable, pickLabel } from '../engines';+import { STATUS_DOT, statusOf, statusText, type BotStatus } from '../botStatus';import { EnginesApi, useEngines } from '../useEngines';import { claudeNeedsSignIn } from '../claudeLogin';import { Space, spaceSummary } from '../spaces';@@ -78,8 +79,10 @@ export interface SidebarProps {selectedId: string;isChannel: boolean;selectedTeamId?: string | null;- /** Bots busy outside the open chat -> "Working on …", shown under their name. */+ /** What busy bots are doing ("Working on …", "Working here"), shown under their name. */busyKwants?: Record<string, string>;+ /** Busy bots' status for the avatar dot; bots not listed are Available (or Can't run). */+ botStatus?: Record<string, BotStatus>;/** Open browser steps per bot ("Needs you" pill). */needsYou?: Record<string, number>;onSelectKwant: (kwant: Kwant) => void;@@ -147,6 +150,7 @@ export const Sidebar: React.FC<SidebarProps> = ({isChannel,selectedTeamId,busyKwants = {},+ botStatus = {},needsYou = {},onSelectKwant,onSelectChannel,@@ -520,8 +524,8 @@ export const Sidebar: React.FC<SidebarProps> = ({<Hand size={11} /></span>)}- {busyKwants[k.id] && (- <span className="w-1.5 h-1.5 shrink-0 rounded-full bg-sky-400 animate-pulse motion-reduce:animate-none" aria-hidden="true" />+ {botStatus[k.id] && (+ <span className={`w-1.5 h-1.5 shrink-0 rounded-full ${STATUS_DOT[botStatus[k.id]].replace('border-2', 'border')}`} title={statusText(k.name, botStatus[k.id])} aria-hidden="true" />)}{phone ? (<>@@ -701,12 +705,12 @@ export const Sidebar: React.FC<SidebarProps> = ({: 'text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800/40'}`}>- <span className="shrink-0" title={canRun === false ? "Can't run yet: no account works here" : undefined}>+ <span className="shrink-0" title={statusOf(k.id, botStatus, canRun) === 'cant_run' ? "Can't run yet: no account works here" : undefined}><ModernAvatarrole={k.avatar_sprite}name={k.name}size={32}- isOnline={canRun !== false}+ status={statusOf(k.id, botStatus, canRun)}kwantId={k.id}/></span>diff --git a/frontend/tests/botStatus.test.mjs b/frontend/tests/botStatus.test.mjsnew file mode 100644index 00000000..43fdf6dd--- /dev/null+++ b/frontend/tests/botStatus.test.mjs@@ -0,0 +1,153 @@+// Bot status dots: one status per bot (Needs you > Working > Queued > Can't run > Available), and+// a bot with a running turn never shows the green Available dot, in the open chat included.+import assert from 'node:assert/strict';+import test from 'node:test';+import { JSDOM } from 'jsdom';+import { loadBundled } from './bundle.mjs';++const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/', pretendToBeVisual: true });+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'Node', 'Event', 'requestAnimationFrame', 'cancelAnimationFrame', 'getComputedStyle']) {+ if (!(k in dom.window)) continue;+ Object.defineProperty(globalThis, k, { value: dom.window[k], configurable: true, writable: true });+}++const s = await loadBundled(`+ import React from 'react';+ import { flushSync } from 'react-dom';+ import { createRoot } from 'react-dom/client';+ import { renderToStaticMarkup } from 'react-dom/server.browser';+ import { ModernAvatar } from './src/components/ModernAvatar';+ export * from './src/botStatus';+ export { turnStarted, turnEnded } from './src/kwantActivity';+ export const avatar = (p) => renderToStaticMarkup(React.createElement(ModernAvatar, p));+ // Mounted for real, so the avatar follows the live turn store.+ export const mount = (p) => {+ const host = document.createElement('div');+ document.body.appendChild(host);+ const root = createRoot(host);+ const render = (q) => flushSync(() => root.render(React.createElement(ModernAvatar, q)));+ render(p);+ return { host, render, flush: (fn) => flushSync(fn), unmount: () => root.unmount() };+ };+`);+const dotOf = (host) => host.querySelector('[data-status]')?.getAttribute('data-status');++const run = (turn_id, kwant_id, state = 'running') => ({ turn_id, kwant_id, state });++test('an idle bot that can run is Available, and Can\'t run when no account works', () => {+ const st = s.botStatuses({ turns: [] });+ assert.equal(s.statusOf('a', st, true), 'available');+ assert.equal(s.statusOf('a', st, null), 'available');+ assert.equal(s.statusOf('a', st, false), 'cant_run');+});++test('a running turn is Working, wherever it runs (the open chat included)', () => {+ // The helper has no notion of the open chat: every running turn counts.+ const st = s.botStatuses({ turns: [run('t1', 'editor')] });+ assert.equal(s.statusOf('editor', st, true), 'working');+});++test('a running turn beats Can\'t run', () => {+ const st = s.botStatuses({ turns: [run('t1', 'editor')] });+ assert.equal(s.statusOf('editor', st, false), 'working');+});++test('queued only is Queued; queued plus running is Working', () => {+ assert.equal(s.statusOf('a', s.botStatuses({ turns: [run('q', 'a', 'queued')] }), false), 'queued');+ const st = s.botStatuses({ turns: [run('q', 'a', 'queued'), run('r', 'a')] });+ assert.equal(st.a, 'working');+ // Order doesn't matter.+ assert.equal(s.botStatuses({ turns: [run('r', 'a'), run('q', 'a', 'queued')] }).a, 'working');+});++test('a turn waiting on the person is Needs you, and beats a running turn', () => {+ const awaiting = new Set(['ask']);+ assert.equal(s.botStatuses({ turns: [run('ask', 'a')], awaiting }).a, 'needs_you');+ assert.equal(s.botStatuses({ turns: [run('r', 'a'), run('ask', 'a')], awaiting }).a, 'needs_you');+ assert.equal(s.botStatuses({ turns: [run('ask', 'a'), run('r', 'a')], awaiting }).a, 'needs_you');+});++test('an open browser step is Needs you even without a tracked turn', () => {+ const st = s.botStatuses({ turns: [run('r', 'a')], needsYou: { a: 1, b: 2, c: 0 } });+ assert.equal(st.a, 'needs_you');+ assert.equal(st.b, 'needs_you');+ assert.equal(st.c, undefined);+});++test('priority order is Needs you > Working > Queued > Can\'t run > Available', () => {+ assert.deepEqual([...s.STATUS_PRIORITY], ['needs_you', 'working', 'queued', 'cant_run', 'available']);+});++test('only Available is green; Working pulses but respects reduced motion', () => {+ for (const k of s.STATUS_PRIORITY) assert.equal(s.STATUS_DOT[k].includes('emerald'), k === 'available', k);+ assert.match(s.STATUS_DOT.working, /animate-pulse/);+ assert.match(s.STATUS_DOT.working, /motion-reduce:animate-none/);+ assert.equal(s.statusText('Editor', 'working'), 'Editor · Working');+});++test('the avatar dot shows the status in words for tooltips and screen readers', () => {+ const html = s.avatar({ name: 'Editor', kwantId: 'ed', status: 'needs_you' });+ assert.match(html, /data-status="needs_you"/);+ assert.match(html, /title="Editor · Needs you"/);+ assert.match(html, /<span class="sr-only">Editor · Needs you<\/span>/);+ assert.match(html, /bg-amber-400/);+ assert.doesNotMatch(html, /emerald/);+});++test('the avatar never shows green while its bot has a running turn, even if the status lags', () => {+ for (const lagging of ['available', 'cant_run', 'queued']) {+ const m = s.mount({ name: 'Editor', kwantId: 'ed', status: lagging });+ assert.equal(dotOf(m.host), lagging, 'idle: shows what it was given');+ m.flush(() => s.turnStarted('ed', 'chat-1'));+ assert.equal(dotOf(m.host), 'working', `${lagging} + running turn`);+ assert.doesNotMatch(m.host.innerHTML, /emerald/);+ assert.equal(m.host.querySelector('.sr-only').textContent, 'Editor · Working');+ m.flush(() => s.turnEnded('ed', 'chat-1'));+ assert.equal(dotOf(m.host), lagging, 'turn over: back to the given status');+ m.unmount();+ }+});++test('Needs you still wins over a running turn on the avatar', () => {+ const m = s.mount({ name: 'Editor', kwantId: 'ed', status: 'needs_you' });+ m.flush(() => s.turnStarted('ed', 'chat-1'));+ assert.equal(dotOf(m.host), 'needs_you');+ m.flush(() => s.turnEnded('ed', 'chat-1'));+ m.unmount();+});++test('without a status the avatar draws no dot', () => {+ const html = s.avatar({ name: 'Editor', kwantId: 'ed' });+ assert.doesNotMatch(html, /data-status/);+ assert.doesNotMatch(html, /sr-only/);+});++const describe = (ctx) => ({ 'room-1': 'Engineering Room', 'th-1': 'Release notes' })[ctx] ?? 'another conversation';+const turn = (turn_id, kwant_id, context_id, state = 'running') => ({ turn_id, kwant_id, context_id, state });++test('the line under the name: other chats are named, the open chat says "here"', () => {+ const lines = s.busyLines({+ turns: [turn('a', 'ed', 'open'), turn('b', 'lin', 'room-1'), turn('c', 'rig', 'th-1', 'queued'), turn('d', 'ada', 'open', 'queued')],+ openCtx: 'open',+ describe,+ });+ assert.deepEqual(lines, { ed: 'Working here', lin: 'Working on Engineering Room', rig: 'Waiting to work on Release notes', ada: 'Waiting to work here' });+});++test('the line prefers running over queued, then other chats over the open one', () => {+ const t = [turn('q', 'ed', 'room-1', 'queued'), turn('r', 'ed', 'open')];+ assert.equal(s.busyLines({ turns: t, openCtx: 'open', describe }).ed, 'Working here');+ const u = [turn('r1', 'ed', 'open'), turn('r2', 'ed', 'room-1')];+ assert.equal(s.busyLines({ turns: u, openCtx: 'open', describe }).ed, 'Working on Engineering Room');+});++test('the line says when a bot waits on the person, here or elsewhere', () => {+ const lines = s.busyLines({+ turns: [turn('q1', 'ed', 'open'), turn('b1', 'lin', 'room-1'), turn('q2', 'rig', 'th-1')],+ openCtx: 'open',+ awaiting: new Set(['q1', 'b1', 'q2']),+ browser: new Set(['b1']),+ describe,+ });+ assert.deepEqual(lines, { ed: 'Asked you a question here', lin: 'Needs you in the browser in Engineering Room', rig: 'Asked you a question in Release notes' });+});