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
Steps: one row per answer, the card folds into its command (28s) (#811)
Oleksandr Ivanchenko76bcab63e7b5
diff --git a/frontend/src/activity.ts b/frontend/src/activity.tsindex e18a8d0d..d459ded4 100644--- a/frontend/src/activity.ts+++ b/frontend/src/activity.ts@@ -121,6 +121,59 @@ export function readDenials(steps: ActivityStep[]): ActivityStep[] {export const isOpenStep = (s: ActivityStep) => s.status === 'running' || s.status === 'waiting';+/** The answer a settled approval card gave, as its command row says it (28s). */+export type CardAnswer = 'ok' | 'declined' | 'unanswered';+/** 28s: the command row's chip for the answer its folded card gave. */+export const ANSWER_LABEL: Record<CardAnswer, string> = { ok: 'You said OK', declined: 'You said no', unanswered: 'Not approved in time' };++/** Which tool steps a settled card of each answer can stand for: the command it let run, or the one it held. */+const answeredBy: Record<CardAnswer, (s: ActivityStep) => boolean> = {+ declined: (s) => s.status === 'declined',+ unanswered: (s) => s.status === 'unanswered',+ ok: (s) => s.status !== 'declined' && s.status !== 'unanswered' && s.status !== 'waiting',+};++export interface FoldedSteps {+ /** The rows Details draws: `steps` without the approval steps that folded into their command row. */+ rows: ActivityStep[];+ /** Command step id → the answer its card gave. */+ answers: Map<string, CardAnswer>;+ /** Folded approval step id → the command step id that now carries it (so a link to the card lands on its row). */+ foldedInto: Map<string, string>;+}++/**+ * 28s one-row-per-answer: Details says each answer once. A settled approval step (OK, no, not answered in time)+ * pairs with the nearest tool step of the same tool, in either order, the way `readDenials` pairs (each card at+ * most one step, each step at most one card); the approval row is hidden and the command row carries the answer.+ * A card with no such command row (kwnt held the call, nothing ran, or it is still open) stays its own row.+ * Draw time only: saved steps, `activitySummary` and follow-through read the steps as they are.+ */+export function foldAnswers(steps: readonly ActivityStep[]): FoldedSteps {+ const answers = new Map<string, CardAnswer>();+ const foldedInto = new Map<string, string>();+ const used = new Set<number>();+ steps.forEach((card, ci) => {+ if (card.kind !== 'approval' || !card.tool || !(card.status in answeredBy)) return;+ const fits = answeredBy[card.status as CardAnswer];+ // Nearest by place; on a tie (one before, one after), the one that started closest in time to the card.+ const gap = (i: number) => [Math.abs(i - ci), Math.abs(Date.parse(steps[i].started_at) - Date.parse(card.started_at)) || 0] as const;+ let best = -1;+ steps.forEach((s, i) => {+ if (s.kind !== 'tool' || s.tool !== card.tool || used.has(i) || !fits(s)) return;+ if (best < 0) return void (best = i);+ const [a, b] = [gap(i), gap(best)];+ if (a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])) best = i;+ });+ if (best < 0) return;+ used.add(best);+ answers.set(steps[best].id, card.status as CardAnswer);+ foldedInto.set(card.id, steps[best].id);+ });+ if (!foldedInto.size) return { rows: steps as ActivityStep[], answers, foldedInto };+ return { rows: steps.filter((s) => !foldedInto.has(s.id)), answers, foldedInto };+}+/*** 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@@ -262,7 +315,7 @@ export function statusLabel(s: ActivityStep): string {case 'failed':return 'Failed';case 'declined':- return s.kind === 'approval' ? 'Denied' : 'You said no';+ return 'You said no';case 'stopped':return 'Stopped';case 'unanswered':diff --git a/frontend/src/components/ActivityList.tsx b/frontend/src/components/ActivityList.tsxindex 80a1da91..096c9e25 100644--- a/frontend/src/components/ActivityList.tsx+++ b/frontend/src/components/ActivityList.tsx@@ -1,10 +1,13 @@-import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';+import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';import { Brain, Check, ChevronRight, CircleDashed, CircleSlash, Hand, Info, ListTree, Loader2, ShieldQuestion, TimerOff, X } from 'lucide-react';import {+ ANSWER_LABEL,ActivityStep,+ CardAnswer,LiveActivity,SavedActivity,activitySummary,+ foldAnswers,formatDuration,isOpenStep,plainTitle,@@ -113,7 +116,31 @@ const STEP_MARK: Partial<Record<ActivityStep['status'], string>> = {declined: 'text-zinc-300 border-zinc-500/40',};-const StepRow: React.FC<{ step: ActivityStep; live?: LiveActivity; now: number; listId: string; opened?: boolean }> = ({ step, live, now, listId, opened = false }) => {+/**+ * The row's chip, and words only a screen reader hears. 28s: a command row whose card folded into it carries the+ * card's answer: "You said no" (grey) or "Not approved in time" (amber) as its chip. "You said OK" has no chip+ * (Mira: too loud on a reply of many approved calls); it is read after the title instead. A command that then+ * failed keeps "Failed" and reads its answer after it. A human step the person said no to has no chip (its title+ * says "You said no: …"), nor does a card that said no on its own row (its title says so too).+ */+function stepMark(step: ActivityStep, answer: CardAnswer | undefined): { chip: { text: string; cls: string; kind: string } | null; also?: string } {+ const shown = shownStatus(step);+ if (answer === 'ok' && shown !== 'failed') return { chip: null, also: ANSWER_LABEL.ok };+ if (answer && shown !== 'failed') return { chip: { text: ANSWER_LABEL[answer], cls: STEP_MARK[answer]!, kind: answer } };+ const also = answer ? ANSWER_LABEL[answer] : undefined;+ if (step.status === 'declined' && (step.kind === 'approval' || step.kind === 'human_step')) return { chip: null, also };+ const cls = STEP_MARK[shown];+ return { chip: cls ? { text: statusLabel(step), cls, kind: shown } : null, also };+}++const StepRow: React.FC<{ step: ActivityStep; live?: LiveActivity; now: number; listId: string; opened?: boolean; answer?: CardAnswer }> = ({+ step,+ live,+ now,+ listId,+ opened = false,+ answer,+}) => {const time = stepTime(step, now);const running = step.kind === 'thinking' && step.status === 'running';const text = step.kind === 'thinking' ? thinkingText(step, live) : '';@@ -135,17 +162,22 @@ const StepRow: React.FC<{ step: ActivityStep; live?: LiveActivity; now: number;// 26d: a step that failed or wasn't approved in time says so in words, not only by its icon, even when a later// step worked. The icon's label already names it for screen readers, so the mark is hidden from them.// The approval row keeps its icon only: the mark belongs on the command the person said no to.- const shown = shownStatus(step);- const mark = step.status === 'declined' && step.kind === 'approval' ? undefined : STEP_MARK[shown];+ const { chip: mark, also } = stepMark(step, answer);const head = (<><StatusIcon step={step} /><span className={`min-w-0 flex-1 break-words ${step.status === 'stopped' ? 'text-zinc-400' : waiting ? 'text-amber-100' : 'text-zinc-200'}`}>{step.kind === 'thinking' ? (running ? 'Thinking…' : 'Thought') : <Title text={readableStepTitle(step.title, step.outcome ?? step.status)} />}</span>+ {also && <span className="sr-only">{also}</span>}{mark && (- <span aria-hidden="true" data-step-mark={shown} className={`flex-shrink-0 rounded border px-1 text-[10px] leading-4 font-medium ${mark}`}>- {statusLabel(step)}+ <span+ aria-hidden="true"+ data-step-mark={mark.kind}+ className={`flex-shrink-0 rounded border px-1 text-[10px] leading-4 font-medium ${mark.cls}`}+ data-answer={answer}+ >+ {mark.text}</span>)}{time && <span className="flex-shrink-0 font-mono text-[10px] text-zinc-400 tabular-nums">{time}</span>}@@ -205,10 +237,13 @@ const StepRow: React.FC<{ step: ActivityStep; live?: LiveActivity; now: number;const Steps: React.FC<{ steps: ActivityStep[]; live?: LiveActivity; dropped?: number; id: string; openStep?: string | null }> = ({ steps, live, dropped = 0, id, openStep = null }) => {const now = useNow(steps.some(isOpenStep));+ // 28s: one row per answer. A settled card folds into its command row; draw time only.+ const { rows, answers, foldedInto } = useMemo(() => foldAnswers(steps), [steps]);+ const opened = openStep ? foldedInto.get(openStep) ?? openStep : null;return (<ol id={id} aria-label="Steps" className="divide-y divide-zinc-700/40">- {steps.map((s) => (- <StepRow key={s.id} step={s} live={live} now={now} listId={id} opened={s.id === openStep} />+ {rows.map((s) => (+ <StepRow key={s.id} step={s} live={live} now={now} listId={id} opened={s.id === opened} answer={answers.get(s.id)} />))}{dropped > 0 && (<li className="px-3 py-1.5 text-xs text-zinc-400">@@ -362,10 +397,11 @@ export const SavedActivityList: React.FC<{}, [openRequest, focusStep]);useEffect(() => {if (!openRequest || !focusStep) return;- const el = document.getElementById(`${listId}-${focusStep}`);+ // 28s: a card that folded into its command row is focused there.+ const el = document.getElementById(`${listId}-${foldAnswers(activity.steps).foldedInto.get(focusStep) ?? focusStep}`);el?.focus({ preventScroll: true });el?.scrollIntoView({ block: 'nearest', behavior: window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth' });- }, [openRequest, focusStep, listId, open]);+ }, [openRequest, focusStep, listId, open, activity.steps]);const failed = activity.steps.some((s) => s.status === 'failed');const unanswered = activity.steps.some((s) => s.status === 'unanswered');return (diff --git a/frontend/tests/activity.test.mjs b/frontend/tests/activity.test.mjsindex 15c715c4..7b059f46 100644--- a/frontend/tests/activity.test.mjs+++ b/frontend/tests/activity.test.mjs@@ -68,7 +68,7 @@ test('durations and the summary line', () => {assert.equal(a.activitySummary({ steps, dropped: 10 }), 'Worked 0:41 · 12 steps · 1 failed');assert.equal(a.activitySummary({ steps: [steps[0]], dropped: 0 }), 'Worked 0:10 · 1 step');assert.equal(a.plainTitle('Running `ls`'), 'Running ls');- assert.equal(a.statusLabel(step({ kind: 'approval', status: 'declined' })), 'Denied');+ assert.equal(a.statusLabel(step({ kind: 'approval', status: 'declined' })), 'You said no');});test('live list: steps, mono command, waits announced, reduced motion', () => {@@ -232,11 +232,12 @@ test('28a: the summary says "you said no to 1", never "failed", for a plain Denyconst html = ui.saved({ activity: { steps, dropped: 0 }, idBase: 'r1' });assert.doesNotMatch(html, /text-rose/);assert.match(html, /you said no to 1/);- // The command row says "You said no" in words (a neutral mark, Mira); the approval row keeps "Denied", no mark+ // The command row says "You said no" in words (a neutral mark, Mira); 28s: so does the approval row's label, and+ // in Details the card folds into the command row, so the answer shows onceassert.equal(a.statusLabel(steps[0]), 'You said no');- assert.equal(a.statusLabel(steps[1]), 'Denied');+ assert.equal(a.statusLabel(steps[1]), 'You said no');const open = ui.saved({ activity: { steps, dropped: 0 }, idBase: 'r1', defaultOpen: true });- const marks = [...open.matchAll(/data-step-mark="declined" class="([^"]*)">([^<]*)</g)];+ const marks = [...open.matchAll(/data-step-mark="declined" class="([^"]*)"[^>]*>([^<]*)</g)];assert.equal(marks.length, 1, 'one mark: on the command, not the approval row');assert.equal(marks[0][2], 'You said no');assert.match(marks[0][1], /text-zinc-300 border-zinc-500\/40/);diff --git a/frontend/tests/oneRowPerAnswer.test.mjs b/frontend/tests/oneRowPerAnswer.test.mjsnew file mode 100644index 00000000..4832b1c5--- /dev/null+++ b/frontend/tests/oneRowPerAnswer.test.mjs@@ -0,0 +1,144 @@+// 28s (autonomy/one-row-per-answer/brief.md): in Details, a settled approval card folds into the command row of the+// same tool it answered (nearest, paired the way readDenials pairs), and that row carries the answer as its chip.+// Draw time only: saved steps and the summary line stay the same. Tests marked "fails on 5411bbd7" fail there.+process.env.TZ = 'UTC';+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(`+ import React from 'react';+ import { renderToStaticMarkup } from 'react-dom/server.browser';+ import { SavedActivityList } from './src/components/ActivityList';+ export { parseActivityMeta, statusLabel, activitySummary } from './src/activity';+ export const steps = (props) => renderToStaticMarkup(React.createElement(SavedActivityList, props));+`);++const at = (min) => new Date(Date.parse('2026-11-17T18:00:00Z') + min * 60000).toISOString();+const AP = 'Waiting for your approval: Running a command';+const ap = (id, status, t, tool = 'Bash', detail) => ({ id, kind: 'approval', status, title: AP, tool, started_at: at(t), ended_at: at(t + 0.2), duration_ms: 12000, ...(detail ? { detail } : {}) });+const tool = (id, status, title, t, detail, name = 'Bash') => ({ id, kind: 'tool', status, title, tool: name, started_at: at(t), ended_at: at(t + 0.5), duration_ms: 30000, ...(detail ? { detail } : {}) });+// `status` is the server's human-step status; parseStep reads it into status + outcome.+const hs = (id, status) => ({ id, kind: 'human_step', status, title: 'Waiting for you: Sign in to tiktok.com in the browser panel.', tool: 'ask_human', ref_id: `h-${id}`, started_at: at(0), ended_at: at(1), duration_ms: 60000 });+const LATE = 'Waited 5 minutes for your answer; nothing ran';+const parse = (raw) => m.parseActivityMeta({ activity: { steps: raw, dropped: 0 } });+const open = (activity) => m.steps({ activity, idBase: 'r1', defaultOpen: true });+const rowIds = (html) => [...html.matchAll(/<li id="r1-steps-([^"]+)"/g)].map((x) => x[1]);+const row = (html, id) => {+ const start = html.indexOf(`id="r1-steps-${id}"`);+ assert.ok(start >= 0, `row ${id}`);+ return html.slice(start, html.indexOf('</li>', start));+};+const chip = (r) => {+ const c = r.match(/<span( aria-hidden="true")? data-step-mark="([^"]+)" class="([^"]*)"[^>]*>([^<]+)</);+ return c && { hidden: !!c[1], mark: c[2], cls: c[3], text: c[4] };+};+const GREY = /text-zinc-300 border-zinc-500\/40/;+const AMBER = /text-amber-300 border-amber-500\/30/;++// The 28h rig's reply: allowed, denied (old saved shape, command above its card) and unanswered.+const RIG = () =>+ parse([+ ap('tk1', 'ok', 0),+ tool('t1', 'ok', 'Running `npm run build`', 0.2),+ tool('t2', 'failed', 'Running `rm -rf dist/old`', 1, 'The user denied this tool call.'),+ ap('tk2', 'declined', 1.01),+ tool('t3', 'unanswered', 'Running `git push origin main`', 2, LATE),+ ap('tk3', 'unanswered', 2.01, 'Bash', LATE),+ ]);++test('Deny: one row, the command, with the grey "You said no" chip (fails on 5411bbd7)', () => {+ const html = open(RIG());+ assert.ok(!rowIds(html).includes('tk2'), 'the card row folds away');+ const c = chip(row(html, 't2'));+ assert.equal(c.text, 'You said no');+ assert.match(c.cls, GREY);+ assert.match(row(html, 't2'), /aria-label="You said no"/);+ assert.doesNotMatch(html.replace(row(html, 't2'), ''), /You said no/, 'said on one row, not twice');+});++test('Allow: one row, the command, no visible chip; "You said OK" is read after the title (fails on 5411bbd7)', () => {+ const html = open(RIG());+ assert.ok(!rowIds(html).includes('tk1'));+ const r = row(html, 't1');+ assert.equal(chip(r), null, 'no visible chip (Mira 28s fix 1)');+ assert.doesNotMatch(r, /data-step-mark="ok"/);+ assert.match(r, /<span class="sr-only">You said OK<\/span>/);+ assert.match(r, /aria-label="Done"/);+});++test('unanswered with a command row: one amber row "Not approved in time" (fails on 5411bbd7)', () => {+ const html = open(RIG());+ assert.deepEqual(rowIds(html), ['t1', 't2', 't3']);+ const c = chip(row(html, 't3'));+ assert.equal(c.text, 'Not approved in time');+ assert.match(c.cls, AMBER);+});++test('unanswered with no command row: the card stays its own row, as before', () => {+ const html = open(parse([ap('tk3', 'unanswered', 2, 'Bash', LATE), tool('r1', 'ok', 'Reading `notes.md`', 3, undefined, 'Read')]));+ assert.deepEqual(rowIds(html), ['tk3', 'r1']);+ const c = chip(row(html, 'tk3'));+ assert.equal(c.text, 'Not approved in time');+ assert.match(c.cls, AMBER);+ assert.equal(chip(row(html, 'r1')), null, 'a call of another tool takes no answer');+});++test('a declined card with no command row stays, no chip, and its icon says "You said no", not "Denied" (fails on 5411bbd7)', () => {+ const html = open(parse([ap('tk2', 'declined', 1)]));+ assert.deepEqual(rowIds(html), ['tk2']);+ assert.equal(chip(row(html, 'tk2')), null);+ assert.match(row(html, 'tk2'), /aria-label="You said no"/);+ assert.doesNotMatch(html, /Denied/);+ assert.match(html, /You said no: running a command/i);+});++test('two calls of the same tool, one allowed and one denied: each command row gets its own answer (fails on 5411bbd7)', () => {+ const steps = parse([+ tool('a1', 'ok', 'Running `ls dist`', 0),+ ap('c1', 'ok', 0.01),+ tool('a2', 'failed', 'Running `rm -rf dist`', 1, 'The user denied this tool call.'),+ ap('c2', 'declined', 1.01),+ ]);+ const html = open(steps);+ assert.deepEqual(rowIds(html), ['a1', 'a2']);+ assert.equal(chip(row(html, 'a1')), null);+ assert.match(row(html, 'a1'), /sr-only">You said OK</);+ assert.equal(chip(row(html, 'a2')).text, 'You said no');+});++test('an allowed call that then failed keeps "Failed" as its chip, and the answer is read after it (fails on 5411bbd7)', () => {+ const html = open(parse([ap('c1', 'ok', 0), tool('a1', 'failed', 'Running `npm test`', 0.1, 'exit 1')]));+ assert.deepEqual(rowIds(html), ['a1']);+ const r = row(html, 'a1');+ assert.equal(chip(r).text, 'Failed');+ assert.match(r, /<span class="sr-only">You said OK<\/span>/);+});++test('an open card stays its own row; an approved call still running reads "You said OK" (fails on 5411bbd7)', () => {+ const waiting = open(parse([tool('a1', 'running', 'Running `npm ci`', 0), ap('c1', 'waiting', 0.01)]));+ assert.deepEqual(rowIds(waiting), ['a1', 'c1']);+ const running = open(parse([ap('c1', 'ok', 0), tool('a1', 'running', 'Running `npm ci`', 0.1)]));+ assert.deepEqual(rowIds(running), ['a1']);+ assert.match(row(running, 'a1'), /sr-only">You said OK</);+});++test('a declined human step has no chip: its title already says "You said no" (fails on 5411bbd7)', () => {+ const html = open(parse([hs('h1', 'declined'), hs('h2', 'timed_out')]));+ const r = row(html, 'h1');+ assert.equal(chip(r), null);+ assert.match(r, /aria-label="You said no"/);+ assert.match(r, /You said no: /);+ assert.equal(chip(row(html, 'h2')).text, 'Not done in time', '28n stays');+});++test('saved steps and the summary line are unchanged by the fold', () => {+ const steps = RIG();+ assert.equal(steps.steps.length, 6);+ assert.deepEqual(steps.steps.map((s) => s.status), ['ok', 'ok', 'declined', 'declined', 'unanswered', 'unanswered']);+ const html = open(steps);+ assert.match(html, new RegExp(m.activitySummary(steps).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')));+ assert.equal(m.activitySummary(steps), m.activitySummary(RIG()));+});diff --git a/frontend/tests/timedOutStepSaysSo.test.mjs b/frontend/tests/timedOutStepSaysSo.test.mjsindex dd7a6214..fd142214 100644--- a/frontend/tests/timedOutStepSaysSo.test.mjs+++ b/frontend/tests/timedOutStepSaysSo.test.mjs@@ -51,7 +51,7 @@ test('Details: timed out gets the timer icon and the amber "Not done in time" chassert.deepEqual(t, { label: 'Not done in time', mark: 'unanswered', chip: 'Not done in time', timer: true, check: false, amberChip: true });});-test('guard: done and resolved_auto keep ✓ Done, declined and stopped as before', () => {+test('guard: done and resolved_auto keep ✓ Done, declined and stopped as before (28s: declined has no chip)', () => {const a = parse([hs('s0', 'done'), hs('s1', 'resolved_auto'), hs('s2', 'declined'), hs('s4', 'stopped')]);const html = m.steps({ activity: a, idBase: 'r1', defaultOpen: true });for (const id of ['s0', 's1']) {@@ -61,7 +61,8 @@ test('guard: done and resolved_auto keep ✓ Done, declined and stopped as beforassert.equal(r.mark, null, id);}assert.equal(look(row(html, 's2')).label, 'You said no');- assert.equal(look(row(html, 's2')).chip, 'You said no');+ // 28s (Mira's follow-up 2): a declined human step drops its chip; its title says "You said no: …"+ assert.equal(look(row(html, 's2')).chip, null);assert.equal(look(row(html, 's4')).label, 'Stopped');assert.equal(look(row(html, 's4')).mark, null);});