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
18f steps fold on reply: the steps card folds to one row once the reply starts (#676)
Oleksandr Ivanchenkod7878b70db45
diff --git a/frontend/perf/stream/README.md b/frontend/perf/stream/README.mdindex 694b0041..7d78b6c8 100644--- a/frontend/perf/stream/README.md+++ b/frontend/perf/stream/README.md@@ -9,6 +9,8 @@ The streamed reply (~9,000 characters) cycles through prose with a list and a qulist and a table. `window.__harness.finish()` lands it as the saved message.`window.__harness.stream(count, perSecond)` then sends a turn of `count` text tokens at `perSecond`, theway the server's events arrive.+`?steps=4` gives the turn four finished tool steps, sent by `window.__harness.tools()` before any words, and+`?page=1` makes the first one a browser visit so the browsed chip shows (18f). The landed reply keeps them.`run.mjs` serves the build, opens it in headless Chromium, runs the stream and prints one JSON line:diff --git a/frontend/perf/stream/main.tsx b/frontend/perf/stream/main.tsxindex 6d24d8ff..76eeaca6 100644--- a/frontend/perf/stream/main.tsx+++ b/frontend/perf/stream/main.tsx@@ -101,23 +101,56 @@ declare global {tokens: number;streamed: () => string;finish: () => void;+ tools: () => Promise<number>;};}}let streamed = '';+// 18f: ?steps=4 gives the turn that many finished tool steps before its words (`tools()`), and ?page=1 makes+// the first one a browser visit, so the browsed chip shows. The landed reply keeps them in meta.activity.+const STEPS = Number(q.get('steps') ?? 0);+const PAGE = q.get('page') === '1';+const turnSteps = Array.from({ length: STEPS }, (_, i) => ({+ id: `st${i}`,+ kind: 'tool',+ status: 'ok',+ title: PAGE && i === 0 ? 'Opening example.org' : `Reading \`src/file${i}.ts\``,+ tool: PAGE && i === 0 ? 'browser_open' : 'read_file',+ detail: PAGE && i === 0 ? 'https://example.org/pricing' : `src/file${i}.ts`,+ page_title: PAGE && i === 0 ? 'Pricing' : undefined,+ started_at: at(N + i),+ ended_at: at(N + i),+ duration_ms: 1200 + i * 300,+}));+let started = false;+const startTurn = () => {+ if (started) return;+ started = true;+ emit({ type: 'turn_started', kwant_id: 'k1', context_id: CTX, data: { turn_id: 't1', kwant_id: 'k1', context_id: CTX } });+};window.__harness = {tokens: tokens.length,ready: () => document.querySelectorAll('[data-message-id]').length >= Math.min(N, 20),streamed: () => streamed,// The reply lands (15a shots): the saved message joins the history and the turn completes.finish: () => {- messages.push({ id: 'm-final', sender_role: 'kwant', sender_id: 'Ada', text: streamed, results: null, channel_id: CTX, created_at: at(N), tokens_used: 400 });+ const meta = STEPS ? { activity: { steps: turnSteps, dropped: 0 } } : undefined;+ messages.push({ id: 'm-final', sender_role: 'kwant', sender_id: 'Ada', text: streamed, results: null, channel_id: CTX, created_at: at(N), tokens_used: 400, ...(meta ? { meta } : {}) });emit({ type: 'TurnComplete', kwant_id: 'k1', context_id: CTX, turn_id: 't1', data: { tokens: 400 } });},+ // The turn's ?steps= tool steps, one per 50 ms, before any words (18f). Resolves to how many were sent.+ tools: async () => {+ startTurn();+ for (const step of turnSteps) {+ emit({ type: 'activity', kwant_id: 'k1', context_id: CTX, turn_id: 't1', data: { step } });+ await new Promise((r) => setTimeout(r, 50));+ }+ return turnSteps.length;+ },// Sends `count` tokens at `perSecond`, on a timer, the way the server's events arrive.stream: (count, perSecond) =>new Promise((done) => {- emit({ type: 'turn_started', kwant_id: 'k1', context_id: CTX, data: { turn_id: 't1', kwant_id: 'k1', context_id: CTX } });+ startTurn();const t0 = performance.now();let sent = 0;const tick = () => {diff --git a/frontend/src/activity.ts b/frontend/src/activity.tsindex ae20c781..9cd264a6 100644--- a/frontend/src/activity.ts+++ b/frontend/src/activity.ts@@ -74,6 +74,15 @@ export function parseActivityMeta(raw: unknown): SavedActivity | null {export const isOpenStep = (s: ActivityStep) => s.status === 'running' || s.status === 'waiting';+/**+ * Whether the live steps card folds to one row (18f): once the reply has words, the row moves below the bubble,+ * into the landed action row's place, so landing moves nothing above the words. A step waiting for the person+ * keeps the full card open above the bubble: an ask never hides.+ */+export function foldLiveSteps({ writing, steps }: { writing: boolean; steps: readonly ActivityStep[] }): boolean {+ return writing && !steps.some((s) => s.status === 'waiting');+}+/** An `activity` event: replaces the step with the same id, else appends it. A new turn starts over. */export function applyActivity(prev: LiveActivity | undefined, turnId: string, step: ActivityStep): LiveActivity {const base = prev && prev.turnId === turnId ? prev : { turnId, steps: [], thinking: {} };diff --git a/frontend/src/components/ActivityList.tsx b/frontend/src/components/ActivityList.tsxindex 0433f5d8..a751d149 100644--- a/frontend/src/components/ActivityList.tsx+++ b/frontend/src/components/ActivityList.tsx@@ -191,12 +191,21 @@ const Steps: React.FC<{ steps: ActivityStep[]; live?: LiveActivity; dropped?: nu);};+/** The saved reply's steps row (and the live one once it folds, 18f): one class string, so both are the same height. */+export const STEPS_ROW_BUTTON =+ 'max-w-full min-w-0 flex items-center gap-2 px-3 py-1.5 rounded-xl text-xs text-zinc-400 hover:text-zinc-200 bg-zinc-900/70 hover:bg-zinc-800/70 border border-zinc-700/60 hover:border-zinc-600/80 transition-colors cursor-pointer focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400';+/** The list the steps row opens to. */+export const STEPS_ROW_LIST = 'mt-1.5 w-full max-w-2xl rounded-xl border border-zinc-700/60 bg-zinc-900/60 overflow-hidden shadow-[var(--kws-shadow)]';+/*** While the bot works: every step so far, newest last. `compact` (phone, 0.6.13 spec C2) folds it to* one 44 px row, "Steps · 2 ▸", that opens to the same list; the engine's note (what it can't show of* its thinking) moves behind an ⓘ in that row, since the working strip already says the bot works.+ * `folded` (once the reply has words, 18f) is rendered below the bubble: on desktop it draws the saved reply's+ * one row instead of the card, and on a phone the compact row keeps its look. Either way it sits where the landed+ * action row goes, so nothing above the words moves; opened, it stays open until the reply lands.*/-export const LiveActivityList: React.FC<{ live: LiveActivity; idBase: string; compact?: boolean; lead?: React.ReactNode }> = ({ live, idBase, compact = false, lead }) => {+export const LiveActivityList: React.FC<{ live: LiveActivity; idBase: string; compact?: boolean; folded?: boolean; lead?: React.ReactNode }> = ({ live, idBase, compact = false, folded = false, lead }) => {const { steps } = live;const [open, setOpen] = useState(false);const [noteOpen, setNoteOpen] = useState(false);@@ -215,7 +224,7 @@ export const LiveActivityList: React.FC<{ live: LiveActivity; idBase: string; coconst listId = `${idBase}-live`;const noteId = `${idBase}-note`;return (- <section aria-label="What the bot is doing" data-steps-compact="" className="mb-2 w-full max-w-2xl rounded-xl border border-zinc-700/60 bg-zinc-900/60 overflow-hidden">+ <section aria-label="What the bot is doing" data-steps-compact="" className={`${folded ? 'mt-1' : 'mb-2'} w-full max-w-2xl rounded-xl border border-zinc-700/60 bg-zinc-900/60 overflow-hidden`}>{lead && <div className="flex items-center min-h-[44px] px-2.5 border-b border-zinc-700/40">{lead}</div>}<div className="flex items-center"><button@@ -261,6 +270,30 @@ export const LiveActivityList: React.FC<{ live: LiveActivity; idBase: string; co</section>);}+ if (folded) {+ const listId = `${idBase}-live`;+ return (+ <section aria-label="What the bot is doing" data-steps-folded="" className="mt-2 max-w-full">+ <div className="flex max-w-full min-w-0 items-center gap-2">+ <button type="button" onClick={() => setOpen((o) => !o)} aria-expanded={open} aria-controls={open ? listId : undefined} className={STEPS_ROW_BUTTON}>+ <ListTree size={13} className="text-sky-400/80" aria-hidden="true" />+ {/* No time while running, as in the card */}+ <span className="truncate min-w-0">Working · {work} {work === 1 ? 'step' : 'steps'}</span>+ <ChevronRight size={13} className={`flex-shrink-0 text-zinc-400 transition-transform motion-reduce:transition-none ${open ? 'rotate-90' : ''}`} aria-hidden="true" />+ </button>+ {lead && <div className="min-w-0 shrink">{lead}</div>}+ </div>+ {announce}+ {open && (+ <div className={STEPS_ROW_LIST}>+ <div className="max-h-[22rem] overflow-y-auto">+ <Steps steps={steps} live={live} id={listId} />+ </div>+ </div>+ )}+ </section>+ );+ }return (<section aria-label="What the bot is doing" className="mb-2 w-full max-w-2xl rounded-xl border border-zinc-700/60 bg-zinc-900/60 overflow-hidden shadow-[var(--kws-shadow)]"><p className="flex items-center gap-1.5 px-3 pt-2 pb-1 text-[11px] font-medium uppercase tracking-wide text-zinc-400">@@ -292,14 +325,14 @@ export const SavedActivityList: React.FC<{ activity: SavedActivity; idBase: strionClick={() => setOpen((o) => !o)}aria-expanded={open}aria-controls={open ? listId : undefined}- className="max-w-full min-w-0 flex items-center gap-2 px-3 py-1.5 rounded-xl text-xs text-zinc-400 hover:text-zinc-200 bg-zinc-900/70 hover:bg-zinc-800/70 border border-zinc-700/60 hover:border-zinc-600/80 transition-colors cursor-pointer focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400"+ className={STEPS_ROW_BUTTON}><ListTree size={13} className={failed ? 'text-rose-300' : 'text-sky-400/80'} aria-hidden="true" /><span className="truncate min-w-0">{activitySummary(activity)}</span><ChevronRight size={13} className={`flex-shrink-0 text-zinc-400 transition-transform motion-reduce:transition-none ${open ? 'rotate-90' : ''}`} aria-hidden="true" /></button>{open && (- <div className="mt-1.5 w-full max-w-2xl rounded-xl border border-zinc-700/60 bg-zinc-900/60 overflow-hidden shadow-[var(--kws-shadow)]">+ <div className={STEPS_ROW_LIST}><Steps steps={activity.steps} dropped={activity.dropped} id={listId} />{children}</div>diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsxindex cec0793a..7f5fd50a 100644--- a/frontend/src/components/ChatView.tsx+++ b/frontend/src/components/ChatView.tsx@@ -38,7 +38,7 @@ import { QuestionMeta, foldedAnswerIds, parseMetaObject, parseQuestionMeta } froimport { fromTelegram, sentToTelegram } from '../telegram';import { AllowedFromTelegram, ViaTelegram } from './TelegramMarks';import { HumanStep, HumanStepMeta, parseHumanStepMeta } from '../humanSteps';-import { LiveActivity, hasThinkingText, parseActivityMeta } from '../activity';+import { LiveActivity, foldLiveSteps, hasThinkingText, parseActivityMeta } from '../activity';import { LiveActivityList, SavedActivityList } from './ActivityList';import { BrowsedChip } from './BrowsedChip';import { pagesOfReply, type ReplyPage } from '../browserPages';@@ -2196,6 +2196,23 @@ export const ChatView: React.FC<ChatViewProps> = ({requestAnimationFrame(() => checkMention(next, next.length));};+ // 18f: once the reply has words the steps fold (desktop: the saved reply's row; phone: the compact row as is) and+ // move below the bubble, into the landed action row's place, so landing moves nothing above the words.+ const stepsBelow = !!liveActivity && foldLiveSteps({ writing, steps: liveActivity.steps });+ const liveStepsList = liveActivity ? (+ <LiveActivityList+ live={liveActivity}+ idBase={`live-${liveActivity.turnId}`}+ compact={phone}+ folded={stepsBelow}+ lead={+ livePages.length > 0 ? (+ <BrowsedChip botName={liveSpeaker} steps={liveActivity.steps} live phone={phone} onOpen={() => openBrowserFor(null)} />+ ) : undefined+ }+ />+ ) : null;+// 14c: on a phone the header's icon buttons carry a small caption under the icon (no hover there,// so a title alone was never seen); from sm up they keep their inline word.const headLabel = (wide: string, short: string = wide) => (@@ -2532,18 +2549,7 @@ export const ChatView: React.FC<ChatViewProps> = ({{liveNote && <FailoverNote text={liveNote} />}- {liveActivity && (- <LiveActivityList- live={liveActivity}- idBase={`live-${liveActivity.turnId}`}- compact={phone}- lead={- livePages.length > 0 ? (- <BrowsedChip botName={liveSpeaker} steps={liveActivity.steps} live phone={phone} onOpen={() => openBrowserFor(null)} />- ) : undefined- }- />- )}+ {liveActivity && !stepsBelow && liveStepsList}{thinking && (<div className="mb-2 p-2.5 rounded-xl bg-violet-950/20 border border-violet-500/20 text-xs text-violet-300/90 flex items-center gap-2 animate-pulse motion-reduce:animate-none max-w-full">@@ -2586,6 +2592,9 @@ export const ChatView: React.FC<ChatViewProps> = ({</div>)}+ {/* 18f: once words stream, the steps row sits below the bubble, where the landed action row goes */}+ {liveActivity && stepsBelow && liveStepsList}+{!queued && <QueuedBeside items={queuedBeside} />}</div></div>diff --git a/frontend/tests/activity.test.mjs b/frontend/tests/activity.test.mjsindex 862768f0..398cc83b 100644--- a/frontend/tests/activity.test.mjs+++ b/frontend/tests/activity.test.mjs@@ -6,7 +6,9 @@ const a = await loadBundled(`export * from './src/activity';`);const ui = await loadBundled(`import React from 'react';import { renderToStaticMarkup } from 'react-dom/server.browser';- import { LiveActivityList, SavedActivityList } from './src/components/ActivityList';+ import { LiveActivityList, SavedActivityList, STEPS_ROW_BUTTON, STEPS_ROW_LIST } from './src/components/ActivityList';+ export { STEPS_ROW_BUTTON, STEPS_ROW_LIST };+ export const el = (t, p, c) => React.createElement(t, p, c);export const live = (props) => renderToStaticMarkup(React.createElement(LiveActivityList, props));export const saved = (props) => renderToStaticMarkup(React.createElement(SavedActivityList, props));`);@@ -120,3 +122,35 @@ test('a page opened mid-turn seeds the open step from /api/turns (ticket 4)', asassert.equal(a.seedActivity(undefined, 't1', { steps: [] }), null);assert.equal(a.seedActivity(undefined, 't1', 'nope'), null);});++test('18f: the live card folds once the reply has words, unless a step waits for the person', () => {+ const ok = [step({ status: 'ok' }), step({ id: 's2', status: 'running' })];+ assert.equal(a.foldLiveSteps({ writing: false, steps: ok }), false, 'tool phase: full card');+ assert.equal(a.foldLiveSteps({ writing: true, steps: ok }), true, 'text streams: one row');+ assert.equal(a.foldLiveSteps({ writing: true, steps: [...ok, step({ id: 'ap', kind: 'approval', status: 'waiting', title: 'Approve' })] }), false, 'an ask never hides');+ assert.equal(a.foldLiveSteps({ writing: true, steps: [] }), true);+});++test('18f: the folded row is the saved row: same button classes, same wrapper, no time, list opens to 22rem', () => {+ const steps = [step({ status: 'ok', duration_ms: 900 }), step({ id: 's2', status: 'ok' }), step({ id: 's3', status: 'running', title: 'Reading `a.ts`' })];+ const html = ui.live({ live: { turnId: 't', steps, thinking: {} }, idBase: 'x', folded: true, lead: ui.el('span', { 'data-chip': '' }, 'chip') });+ const saved = ui.saved({ activity: { steps, dropped: 0 }, idBase: 'm1' });+ const btn = (h) => h.match(/<button[^>]*class="([^"]+)"/)[1];+ assert.equal(btn(html), ui.STEPS_ROW_BUTTON);+ assert.equal(btn(saved), ui.STEPS_ROW_BUTTON);+ assert.match(html, /^<section aria-label="What the bot is doing" data-steps-folded="" class="mt-2 max-w-full">/, 'below the bubble, the landed action row\'s gap');+ assert.match(saved, /^<div class="mb-2 max-w-full">/);+ assert.match(html, />Working · 3 steps</);+ assert.doesNotMatch(html, /\d:\d\d/, 'no time while live');+ assert.match(html, /aria-expanded="false"/);+ assert.doesNotMatch(html, /a\.ts/, 'steps hidden until opened');+ assert.match(html, /<\/button><div class="min-w-0 shrink"><span data-chip="">chip<\/span><\/div>/, 'browsed chip inline after the button');+ assert.match(html, /role="status"/, 'the announcer stays');+ assert.match(ui.STEPS_ROW_LIST, /mt-1\.5/);+ // Folded with one step says "1 step"; not folded is the card as before.+ assert.match(ui.live({ live: { turnId: 't', steps: [steps[0]], thinking: {} }, idBase: 'x', folded: true }), />Working · 1 step</);+ assert.doesNotMatch(ui.live({ live: { turnId: 't', steps, thinking: {} }, idBase: 'x' }), /data-steps-folded/);+ // Phone: the compact row keeps its look; folded it sits below the bubble with the landed chip row's mt-1.+ assert.match(ui.live({ live: { turnId: 't', steps, thinking: {} }, idBase: 'x', compact: true, folded: true }), /^<section aria-label="What the bot is doing" data-steps-compact="" class="mt-1 w-full max-w-2xl/);+ assert.match(ui.live({ live: { turnId: 't', steps, thinking: {} }, idBase: 'x', compact: true }), /^<section aria-label="What the bot is doing" data-steps-compact="" class="mb-2 w-full max-w-2xl/);+});