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
The bot at work: pixel scene while a reply is coming (0.9.7) (#562)
Oleksandr Ivanchenko855342257b38
diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsxindex 2687aadf..4dcf91d6 100644--- a/frontend/src/components/ChatView.tsx+++ b/frontend/src/components/ChatView.tsx@@ -11,6 +11,7 @@ import { TrialWaitsCard } from './SkillsPanel';import { agentSenderLabel } from '../agentConnections';import { ArrowDown, ArrowUp, AtSign, Paperclip, Sparkles, ChevronDown, ChevronRight, Copy, Check, ChevronLeft, Users, Square, Settings2, Folder, GitBranch, Pencil, Pin, Monitor, CircleSlash } from 'lucide-react';import { ModernAvatar } from './ModernAvatar';+import { WorkingAvatar } from './WorkingAvatar';import { BotHome } from './BotHome';import { ChatHome, answerTarget, goodAt, recipientsOf } from '../botHome';import { moodNoticed } from '../kwantMood';@@ -2181,14 +2182,17 @@ export const ChatView: React.FC<ChatViewProps> = ({{/* On a phone the strip says "working" and "waiting": no skeleton, no "Paused on…" bubble. */}{(!phone || queued || streamingText) && (- <div className="p-4 sm:p-5 min-h-[3.5rem] rounded-2xl rounded-tl-sm bg-zinc-900/60 text-zinc-200 border border-zinc-800/80 text-sm leading-relaxed shadow-sm w-full">+ <div className="p-4 sm:p-5 min-h-[3.5rem] rounded-2xl rounded-tl-sm bg-zinc-900/60 text-zinc-200 border border-zinc-800/80 text-sm leading-relaxed shadow-sm w-full" data-live-bubble-body="">{queued ? (<p className="text-zinc-300" role="status">{queued.position ? <strong className="font-medium text-zinc-100">#{queued.position} in line.</strong> : <strong className="font-medium text-zinc-100">In line.</strong>}{' '}{queuedText(queued.reason, queued.slots)}</p>) : streamingText ? (- <MarkdownRenderer content={hideStreamingDecisions(stripDiscussionMarkers(streamingText))} isStreaming={true} />+ /* The scene's 62 px holds under the first words (kw-wa-hold), so the bubble does not jump; they fade in once. */+ <div className="kw-wa-in kw-wa-hold">+ <MarkdownRenderer content={hideStreamingDecisions(stripDiscussionMarkers(streamingText))} isStreaming={true} />+ </div>) : awaitingAnswer ? (<p className="text-zinc-400" role="status">{awaitingBrowser@@ -2200,11 +2204,13 @@ export const ChatView: React.FC<ChatViewProps> = ({Paused on the approval below. Allow or deny it there; this reply carries on from it.</p>) : (- <div className="space-y-2.5 py-1" role="status" aria-label="Waiting for the first words">- <div className="kws-skel h-3 w-11/12 rounded-full bg-zinc-700/60" />- <div className="kws-skel h-3 w-9/12 rounded-full bg-zinc-700/60" style={{ animationDelay: '120ms' }} />- <div className="kws-skel h-3 w-6/12 rounded-full bg-zinc-700/60" style={{ animationDelay: '240ms' }} />- </div>+ <WorkingAvatar+ name={+ discussionState?.inProgress && discussionState.currentSpeaker+ ? discussionState.currentSpeaker+ : streamingSpeakerName || title+ }+ />)}</div>)}diff --git a/frontend/src/components/ModernAvatar.tsx b/frontend/src/components/ModernAvatar.tsxindex cae25c6d..61ace9d0 100644--- a/frontend/src/components/ModernAvatar.tsx+++ b/frontend/src/components/ModernAvatar.tsx@@ -35,7 +35,7 @@ type Accessory =| 'mortarboard' | 'star' | 'bowtie' | 'cap' | 'sunhat' | 'toque' | 'headband'| 'partyhat' | 'hardhat' | 'flower' | 'none';-interface Creature {+export interface Creature {body: string;shade: string;light: string;@@ -333,6 +333,13 @@ function renderCreature(c: Creature) {];}+/** The bot's creature, resolved exactly as ModernAvatar resolves it, for scenes that draw the bot outside its frame. */+export function useCreatureFor(role: string | undefined, name: string, kwantId?: string): Creature {+ useSyncExternalStore(subscribeBotLooks, botLooksRev, botLooksRev);+ return pickCreature(avatarStyleFor(role, kwantId, name, isStyleId) ?? 'default', name);+}+export { renderCreature };+export const ModernAvatar: React.FC<ModernAvatarProps> = ({role,name = '',diff --git a/frontend/src/components/WorkingAvatar.tsx b/frontend/src/components/WorkingAvatar.tsxnew file mode 100644index 00000000..d8a7525d--- /dev/null+++ b/frontend/src/components/WorkingAvatar.tsx@@ -0,0 +1,48 @@+import React from 'react';+import { useCreatureFor, renderCreature } from './ModernAvatar';++// The bot at work (working-avatar/design.md §3): one inline SVG on a 36×18 cell grid, drawn at 3 px a cell.+// Every motion is a CSS keyframe in stream.css (.kw-wa-*); the resting state is the reduced-motion still frame.+const KEYS = [17, 19, 21, 23, 25, 27, 29, 31];+const PLUS: Array<[number, number]> = [[18, 1], [17, 2], [19, 2], [18, 3]];+const TIPS: Array<[number, number]> = [[18, 0], [16, 2], [20, 2], [18, 4]];+const LINES: Array<[number, number]> = [[8, 11], [10, 9], [12, 6]]; // [y, width], x = 19++export const WorkingAvatar: React.FC<{ name: string }> = ({ name }) => {+ // Same role and name as the row's avatar, so the bot at the laptop is the bot in the portrait.+ const c = useCreatureFor(name, name);+ const label = `${name} is working on the answer`;+ return (+ <div className="kw-wa" role="status" aria-label={label} data-working-avatar="">+ <svg className="kw-wa-scene" viewBox="0 0 36 18" width={108} height={54} aria-hidden="true" focusable="false">+ <rect x={1} y={17} width={35} height={1} fill="var(--kw-wa-ground)" />+ <g transform="translate(-5 -2)">+ <g className="kw-wa-bob">{renderCreature(c).filter((r) => r.key !== 'shadow')}</g>+ </g>+ <rect x={14} y={16} width={22} height={1} fill="var(--kw-wa-edge)" />+ <rect x={15} y={15} width={20} height={1} fill="var(--kw-wa-deck)" />+ {KEYS.map((x) => <rect key={x} x={x} y={15} width={1} height={1} fill="var(--kw-wa-key)" />)}+ <rect x={17} y={6} width={16} height={9} fill="var(--kw-wa-lid)" />+ <rect x={17} y={6} width={16} height={1} fill="var(--kw-wa-rim)" />+ <rect x={17} y={7} width={1} height={8} fill="var(--kw-wa-rim)" />+ <rect x={18} y={7} width={14} height={7} fill="var(--kw-wa-screen)" />+ {LINES.map(([y, w], i) => (+ <rect key={y} className={`kw-wa-l kw-wa-l${i + 1}`} x={19} y={y} width={w} height={1} fill="var(--kw-wa-type)" />+ ))}+ <g className="kw-wa-paw"><rect x={13} y={14} width={3} height={1} fill={c.body} data-paw="" /></g>+ <g className="kw-wa-spark">+ {TIPS.map(([x, y]) => <rect key={`t${x}-${y}`} className="kw-wa-s3" x={x} y={y} width={1} height={1} fill="var(--kw-wa-spark)" />)}+ {PLUS.map(([x, y]) => <rect key={`p${x}-${y}`} className="kw-wa-s2" x={x} y={y} width={1} height={1} fill="var(--kw-wa-spark)" />)}+ <rect className="kw-wa-s1" x={18} y={2} width={1} height={1} fill="var(--kw-wa-spark-core)" />+ </g>+ </svg>+ <p className="kw-wa-text" aria-hidden="true">+ <span className="kw-wa-name">{name}</span> is working on it+ <span className="kw-wa-dots">+ <span className="kw-mood-dot">.</span><span className="kw-mood-dot kw-mood-dot-1">.</span><span className="kw-mood-dot kw-mood-dot-2">.</span>+ </span>+ </p>+ <span className="sr-only">{label}</span>+ </div>+ );+};diff --git a/frontend/src/styles/stream.css b/frontend/src/styles/stream.cssindex c59eba43..1634b824 100644--- a/frontend/src/styles/stream.css+++ b/frontend/src/styles/stream.css@@ -207,3 +207,123 @@@media (prefers-reduced-motion: reduce) {.kw-viewer-in { animation: none; }}++/* The bot at work (Mira, autonomy/working-avatar/design.md). Transform and opacity only; one inline SVG; no JS+ timers. The resting state of every element IS the reduced-motion still frame: lines full, paw down, spark hidden. */+:root {+ --kw-wa-ground: #261d4a;+ --kw-wa-lid: #4a3f8a;+ --kw-wa-rim: #6d5fc0;+ --kw-wa-screen: #0d0a1f;+ --kw-wa-type: #b8adff;+ --kw-wa-deck: #5a5383;+ --kw-wa-key: #8d87b8;+ --kw-wa-edge: #3f3868;+ --kw-wa-spark: #e1d6ff;+ --kw-wa-spark-core: #ffffff;+ --kw-wa-text: #9a94c4;+ --kw-wa-name: #ecebfa;+}+/* Light values, for when the app gets a light theme (it is dark only today). */+[data-theme="light"] {+ --kw-wa-ground: #e3e0f5;+ --kw-wa-rim: #6d5fc0;+ --kw-wa-screen: #15112e;+ --kw-wa-deck: #bcb7de;+ --kw-wa-key: #8d87b8;+ --kw-wa-edge: #9a94c4;+ --kw-wa-spark: #9d8fff;+ --kw-wa-spark-core: #6c58e0;+ --kw-wa-text: #5a5383;+ --kw-wa-name: #1d1840;+}++/* The bubble body keeps this height while the reply is live, so the first words land without a jump. */+.kw-wa-hold { min-height: 62px; }++.kw-wa {+ display: flex;+ align-items: center;+ gap: 16px;+ height: 62px;+ animation: kw-wa-in 150ms var(--kw-ease, cubic-bezier(0.2, 0.7, 0.2, 1)) both;+}+.kw-wa[hidden] { display: none; }+.kw-wa-scene { flex: none; display: block; width: 108px; height: 54px; shape-rendering: crispEdges; image-rendering: pixelated; }+.kw-wa-text {+ margin: 0;+ min-width: 0;+ font-size: 14px;+ line-height: 22px;+ color: var(--kw-wa-text);+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+}+.kw-wa-name { color: var(--kw-wa-name); font-weight: 500; }+.kw-wa-dots { display: inline-block; width: 1.1em; }++/* The first words fade in over the place the scene held. */+@keyframes kw-wa-in { from { opacity: 0; } to { opacity: 1; } }+.kw-wa-in { animation: kw-wa-in 150ms var(--kw-ease, cubic-bezier(0.2, 0.7, 0.2, 1)) both; }++/* 1. The bot bobs 1 px (a third of a cell) twice per 2.4 s loop. */+@keyframes kw-wa-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-0.3333px); } }+.kw-wa-bob { animation: kw-wa-bob 1.2s ease-in-out infinite; }++/* 2. The screen types three lines left to right, one cell per step, holds, then clears. */+.kw-wa-l { transform-box: fill-box; transform-origin: left center; }+@keyframes kw-wa-l1 {+ 0% { transform: scaleX(0); opacity: 1; }+ 6% { transform: scaleX(0); animation-timing-function: steps(11, end); }+ 28% { transform: scaleX(1); }+ 88% { transform: scaleX(1); opacity: 1; animation-timing-function: step-end; }+ 89%, 100% { transform: scaleX(1); opacity: 0; }+}+@keyframes kw-wa-l2 {+ 0% { transform: scaleX(0); opacity: 1; }+ 33% { transform: scaleX(0); animation-timing-function: steps(9, end); }+ 49% { transform: scaleX(1); }+ 88% { transform: scaleX(1); opacity: 1; animation-timing-function: step-end; }+ 89%, 100% { transform: scaleX(1); opacity: 0; }+}+@keyframes kw-wa-l3 {+ 0% { transform: scaleX(0); opacity: 1; }+ 54% { transform: scaleX(0); animation-timing-function: steps(6, end); }+ 64% { transform: scaleX(1); }+ 88% { transform: scaleX(1); opacity: 1; animation-timing-function: step-end; }+ 89%, 100% { transform: scaleX(1); opacity: 0; }+}+.kw-wa-l1 { animation: kw-wa-l1 2.4s linear infinite; }+.kw-wa-l2 { animation: kw-wa-l2 2.4s linear infinite; }+.kw-wa-l3 { animation: kw-wa-l3 2.4s linear infinite; }++/* 3. The paw taps a key (up one cell) while a line types, and rests while the screen holds. */+@keyframes kw-wa-paw {+ 0% { transform: translateY(0); }+ 8% { transform: translateY(-1px); } 11% { transform: translateY(0); }+ 14% { transform: translateY(-1px); } 17% { transform: translateY(0); }+ 20% { transform: translateY(-1px); } 23% { transform: translateY(0); }+ 25% { transform: translateY(-1px); } 28% { transform: translateY(0); }+ 35% { transform: translateY(-1px); } 38% { transform: translateY(0); }+ 42% { transform: translateY(-1px); } 45% { transform: translateY(0); }+ 56% { transform: translateY(-1px); } 59% { transform: translateY(0); }+ 61% { transform: translateY(-1px); } 63%, 100% { transform: translateY(0); }+}+.kw-wa-paw { animation: kw-wa-paw 2.4s step-end infinite; }++/* 4. A spark pops above its head when line 3 is done, every third loop (7.2 s): centre, then the plus+ at +60 ms, the tips at +120 ms, held, then a 160 ms fade. Hidden at rest. */+.kw-wa-spark rect { opacity: 0; }+@keyframes kw-wa-s1 { 0%, 21.4% { opacity: 0; } 21.41%, 29.6% { opacity: 1; } 31.8%, 100% { opacity: 0; } }+@keyframes kw-wa-s2 { 0%, 22.23% { opacity: 0; } 22.24%, 29.6% { opacity: 1; } 31.8%, 100% { opacity: 0; } }+@keyframes kw-wa-s3 { 0%, 23.06% { opacity: 0; } 23.07%, 29.6% { opacity: 1; } 31.8%, 100% { opacity: 0; } }+.kw-wa-s1 { animation: kw-wa-s1 7.2s linear infinite; }+.kw-wa-s2 { animation: kw-wa-s2 7.2s linear infinite; }+.kw-wa-s3 { animation: kw-wa-s3 7.2s linear infinite; }++/* Reduced motion: the resting frame. Lines full, paw down, no spark, no bob, dots still ("…"). */+@media (prefers-reduced-motion: reduce) {+ .kw-wa, .kw-wa-in, .kw-wa-scene *, .kw-wa-dots > * { animation: none !important; }+ .kw-wa-dots > * { opacity: 0.8; }+}diff --git a/frontend/tests/liveBubble.test.mjs b/frontend/tests/liveBubble.test.mjsindex c6c0945c..fd977bc8 100644--- a/frontend/tests/liveBubble.test.mjs+++ b/frontend/tests/liveBubble.test.mjs@@ -33,11 +33,11 @@ test('words, the queue and questions win over the approval line', () => {assert.equal(w.liveBubble({ live, awaitingAnswer: true, awaitingBrowser: true }), 'browser');});-test('ChatView draws the approval line before it falls back to the skeleton', () => {+test('ChatView draws the approval line before it falls back to the bot at work', () => {const chat = readFileSync(new URL('../src/components/ChatView.tsx', import.meta.url), 'utf8');const line = chat.indexOf("bubble === 'approval' ? (");- const skel = chat.indexOf('aria-label="Waiting for the first words"');- assert.ok(line > 0 && skel > line, 'the approval branch comes before the skeleton');+ const skel = chat.indexOf('<WorkingAvatar');+ assert.ok(line > 0 && skel > line, 'the approval branch comes before the bot at work');assert.match(chat, /Paused on the approval below\. Allow or deny it there; this reply carries on from it\./);assert.match(chat, /bubble === 'approval' \? 'Waiting for your OK'/);});diff --git a/frontend/tests/workingAvatar.test.mjs b/frontend/tests/workingAvatar.test.mjsnew file mode 100644index 00000000..40a84509--- /dev/null+++ b/frontend/tests/workingAvatar.test.mjs@@ -0,0 +1,92 @@+// The bot at work (autonomy/working-avatar/design.md §10): the scene that stands in the live bubble before the first words.+import assert from 'node:assert/strict';+import test from 'node:test';+import { readFileSync } from 'node:fs';+import { loadBundled } from './bundle.mjs';++const ui = await loadBundled(`+ import React from 'react';+ import { renderToStaticMarkup } from 'react-dom/server.browser';+ import { WorkingAvatar } from './src/components/WorkingAvatar';+ export const scene = (name) => renderToStaticMarkup(React.createElement(WorkingAvatar, { name }));+`);+const scene = ui.scene;+const read = (p) => readFileSync(new URL(`../${p}`, import.meta.url), 'utf8');+const css = read('src/styles/stream.css');+const tsx = read('src/components/WorkingAvatar.tsx');+const chat = read('src/components/ChatView.tsx');++const body = (html) => html.match(/<rect x="7" y="9" width="12" height="7" fill="([^"]+)"/)?.[1];+const paw = (html) => html.match(/<rect x="13" y="14" width="3" height="1" fill="([^"]+)" data-paw=""/)?.[1];++test('the wrapper is the status with the full label; the scene and the visible line are hidden from screen readers', () => {+ const html = scene('Builder');+ assert.match(html, /^<div class="kw-wa" role="status" aria-label="Builder is working on the answer"/);+ assert.match(html, /<svg class="kw-wa-scene"[^>]*aria-hidden="true"[^>]*focusable="false"/);+ assert.match(html, /<p class="kw-wa-text" aria-hidden="true"><span class="kw-wa-name">Builder<\/span> is working on it<span class="kw-wa-dots">/);+ assert.match(html, /<span class="sr-only">Builder is working on the answer<\/span><\/div>$/);+ assert.doesNotMatch(html, /tabindex|<a |<button|<input/, 'nothing inside takes focus');+ assert.equal((html.match(/class="kw-mood-dot/g) ?? []).length, 3, 'three dots on the mood glyph timing');+});++test('the bot is the real creature, without its ground shadow, and the paw wears its body colour', () => {+ const html = scene('Builder');+ assert.ok(body(html), 'the creature body is drawn');+ assert.equal(paw(html), body(html));+ assert.doesNotMatch(html, /fill="#261d4a"/, 'the portrait shadow is dropped');+ assert.match(html, /<g transform="translate\(-5 -2\)"><g class="kw-wa-bob">/, 'translate outside, bob inside');+});++test('a different speaker draws a different bot (team discussions follow the current speaker)', () => {+ const names = ['Builder', 'Writer', 'Designer', 'Director', 'Scout', 'Atlas', 'Quill', 'Echo'];+ const bodies = new Set(names.map((n) => body(scene(n))));+ assert.ok(bodies.size > 1, 'speakers do not all share one colour');+ for (const n of names) assert.equal(paw(scene(n)), body(scene(n)), `${n}: paw = body`);+ assert.match(chat, /<WorkingAvatar\s+name=\{\s+discussionState\?\.inProgress && discussionState\.currentSpeaker\s+\? discussionState\.currentSpeaker\s+: streamingSpeakerName \|\| title\s+\}/);+});++test('the scene replaces the grey lines; the first words keep its height and fade in once', () => {+ assert.doesNotMatch(chat, /kws-skel|Waiting for the first words/);+ assert.match(chat, /<div className="kw-wa-in kw-wa-hold">\s+<MarkdownRenderer content=\{hideStreamingDecisions\(stripDiscussionMarkers\(streamingText\)\)\} isStreaming=\{true\} \/>/);+ assert.match(css, /\.kw-wa-hold \{ min-height: 62px; \}/);+ assert.match(css, /\.kw-wa \{[^}]*height: 62px;/);+ assert.match(css, /\.kw-wa-scene \{[^}]*flex: none;[^}]*height: 54px;/);+});++test('queued and paused bubbles keep their text and do not hold the scene height', () => {+ for (const s of [+ 'Paused on the browser step above. Do it in the browser panel and press Done; this reply carries on from it.',+ 'Paused on the question above. Answer it there; this reply carries on from it.',+ 'Paused on the approval below. Allow or deny it there; this reply carries on from it.',+ ]) assert.ok(chat.includes(s), s);+ assert.equal((chat.match(/kw-wa-hold/g) ?? []).length, 2, 'only the first-words wrapper (and its comment) name the hold');+ assert.match(chat, /\{\(!phone \|\| queued \|\| streamingText\) && \(/, 'phones keep the strip, no bubble');+});++test('motion is CSS keyframes on transform and opacity only, no JS timers, a 2.4 s loop', () => {+ assert.doesNotMatch(tsx, /setTimeout|setInterval|requestAnimationFrame|useEffect|canvas/);+ const frames = [...css.matchAll(/@keyframes (kw-wa-[\w-]+) \{([\s\S]*?)\n?\}\n/g)];+ assert.ok(frames.length >= 8, `found ${frames.length} keyframes`);+ for (const [, name, b] of frames) {+ const props = [...b.matchAll(/([a-z-]+)\s*:/g)].map((m) => m[1]).filter((p) => p !== 'animation-timing-function');+ for (const p of props) assert.ok(p === 'transform' || p === 'opacity', `${name} animates ${p}`);+ }+ for (const m of css.matchAll(/\.kw-wa-(?:bob|l1|l2|l3|paw) \{ animation: [\w-]+ ([\d.]+)s/g)) assert.ok(Number(m[1]) <= 2.4, m[0]);+});++test('reduced motion stops every animation and leaves the still frame (lines shown, spark hidden, dots "…")', () => {+ const rm = css.match(/@media \(prefers-reduced-motion: reduce\) \{\s+\.kw-wa, \.kw-wa-in, \.kw-wa-scene \*, \.kw-wa-dots > \* \{ animation: none !important; \}\s+\.kw-wa-dots > \* \{ opacity: 0\.8; \}\s+\}/);+ assert.ok(rm, 'reduced-motion block covers the wrapper, the fade, every scene part and the dots');+ assert.match(css, /\.kw-wa-spark rect \{ opacity: 0; \}/);+ const html = scene('Writer');+ for (const w of [11, 9, 6]) assert.match(html, new RegExp(`class="kw-wa-l kw-wa-l\\d" x="19" y="\\d+" width="${w}"`), `line of ${w} cells drawn at rest`);+});++test('light theme tokens exist for every dark token', () => {+ const dark = css.match(/:root \{([^}]*--kw-wa-[^}]*)\}/)[1];+ const light = css.match(/\[data-theme="light"\] \{([^}]*--kw-wa-[^}]*)\}/)[1];+ const keys = (b) => [...b.matchAll(/(--kw-wa-[\w-]+):/g)].map((m) => m[1]);+ for (const k of ['--kw-wa-ground', '--kw-wa-screen', '--kw-wa-deck', '--kw-wa-edge', '--kw-wa-spark', '--kw-wa-spark-core', '--kw-wa-text', '--kw-wa-name']) {+ assert.ok(keys(dark).includes(k) && keys(light).includes(k), k);+ }+});