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
Still-open approval cards and the Loose ends owner setting
Pixel (kwant bot)971f9cc4a114
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex bf54813b..58d81036 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -18,7 +18,7 @@ import { AwayPage } from './components/AwayView';import { LooseEndsPage } from './components/LooseEndsView';import { ParallelPage } from './components/ParallelUniverseView';import { AlertTriangle, Bot, Check, HelpCircle, Inbox, KeyRound, ListChecks, Loader2, MessageSquare, Settings } from 'lucide-react';-import { ChatApproval, OpenChat, approvalFromEvent, approvalsForChat, approvalsFromAway, syncApprovals, upsertApproval, withoutApproval } from './approvals';+import { ChatApproval, OpenChat, approvalFromEvent, lateAnswerText, approvalsForChat, approvalsFromAway, syncApprovals, upsertApproval, withoutApproval } from './approvals';import type { AgentFormData } from './components/NewAgentModal';import { NewTeamModal } from './components/NewTeamModal';import { ManageTeamModal } from './components/ManageTeamModal';@@ -1160,8 +1160,14 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({});// 409/404: it lapsed meanwhile (turn ended, expired, answered elsewhere).if (res.ok || res.status === 409 || res.status === 404) {+ const card = pendingApprovals.find((a) => a.id === ticketId);dropApproval(ticketId);if (!res.ok) pushToast('This request expired', 'The bot is no longer waiting for this answer.');+ else if (card?.waiting && decision !== 'deny') {+ const bot = typeof card.details.kwant_name === 'string' ? card.details.kwant_name : null;+ const text = lateAnswerText(await res.json().catch(() => null), bot);+ if (text) pushToast('Card answered', text);+ }refreshAwayCount(300);} else if (res.status === 401) {// Person-only: the token dialog is open; the card stays so the person can answer again.diff --git a/frontend/src/approvals.ts b/frontend/src/approvals.tsindex 9b842d8b..5ad76d07 100644--- a/frontend/src/approvals.ts+++ b/frontend/src/approvals.ts@@ -30,7 +30,22 @@ export function approvalFromAway(item: AwayItem): ChatApproval {? { kwant_name: item.kwant_name, ...item.details }: { source: 'summary', tool, summary: item.summary, kwant_id: item.kwant_id, kwant_name: item.kwant_name };const link = item.link && (item.link.thread_id || item.link.channel_id || item.link.direct_kwant_id) ? item.link : null;- return { id: item.id, tool_name: tool, details, kwant_id: item.kwant_id || str(details.kwant_id), link };+ const approval: ChatApproval = { id: item.id, tool_name: tool, details, kwant_id: item.kwant_id || str(details.kwant_id), link };+ if (item.status === 'waiting') approval.waiting = true;+ return approval;+}++/**+ * What to tell the person after they answered a card. A late Allow on a still-open card starts+ * the bot again (`resumed: "new_turn"`); otherwise null (nothing worth saying).+ */+export function lateAnswerText(reply: unknown, bot: string | null): string | null {+ if (!reply || typeof reply !== 'object') return null;+ const r = reply as { resumed?: unknown; reason?: unknown };+ const who = bot ?? 'The bot';+ if (r.resumed === 'new_turn') return `Allowed. ${who} is picking the work back up.`;+ if (typeof r.reason === 'string' && r.reason) return `Allowed, but ${who} couldn't continue: ${r.reason}.`;+ return null;}/** The server's waiting approvals, newest first, as cards. */@@ -44,6 +59,9 @@ export function upsertApproval(list: ChatApproval[], next: ChatApproval): ChatApconst prev = list[i];const keepPrev = prev.details.source !== 'summary' && next.details.source === 'summary';const merged: ChatApproval = keepPrev ? { ...prev, link: next.link ?? prev.link } : { ...next, link: next.link ?? prev.link };+ // Whether the bot still waits on it comes from the newer copy (the server's, on a sync).+ if (next.waiting) merged.waiting = true;+ else delete merged.waiting;return list.map((a, j) => (j === i ? merged : a));}diff --git a/frontend/src/away.ts b/frontend/src/away.tsindex fa89896d..16438790 100644--- a/frontend/src/away.ts+++ b/frontend/src/away.ts@@ -76,7 +76,7 @@ export function windowLabel(since: string, now: number = Date.now()): string {return `Since you last looked, ${relativeTime(since, now)}`;}-export type Tone = 'amber' | 'emerald' | 'rose' | 'zinc';+export type Tone = 'amber' | 'emerald' | 'rose' | 'sky' | 'zinc';/** Short label and colour for an item's kind and status. */export function itemLabel(item: Pick<AwayItem, 'kind' | 'status'>): { label: string; tone: Tone } {@@ -84,7 +84,8 @@ export function itemLabel(item: Pick<AwayItem, 'kind' | 'status'>): { label: strcase 'question':return { label: 'Question', tone: 'amber' };case 'approval':- return { label: 'Needs approval', tone: 'amber' };+ // Its turn stopped waiting, but the card is open and a late Allow resumes the work.+ return item.status === 'waiting' ? { label: 'Still open', tone: 'sky' } : { label: 'Needs approval', tone: 'amber' };case 'routine_run':return item.status === 'ok' ? { label: 'Routine ran', tone: 'emerald' } : { label: 'Routine failed', tone: 'rose' };case 'delegation':diff --git a/frontend/src/components/AwayView.tsx b/frontend/src/components/AwayView.tsxindex 1aa5411a..4193fa71 100644--- a/frontend/src/components/AwayView.tsx+++ b/frontend/src/components/AwayView.tsx@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';import { AlertTriangle, CheckCircle2, ChevronLeft, Inbox, Loader2, RefreshCw } from 'lucide-react';import { ModernAvatar } from './ModernAvatar';import { ModernApprovalCard } from './ModernApprovalCard';-import { approvalFromAway } from '../approvals';+import { approvalFromAway, lateAnswerText } from '../approvals';import {AWAY_SECTIONS,ApprovalDecision,@@ -24,6 +24,7 @@ const TONES: Record<Tone, string> = {amber: 'border-amber-500/30 bg-amber-500/10 text-amber-200',emerald: 'border-emerald-500/30 bg-emerald-500/10 text-emerald-200',rose: 'border-rose-500/30 bg-rose-500/10 text-rose-200',+ sky: 'border-sky-500/30 bg-sky-500/10 text-sky-200',zinc: 'border-zinc-700 bg-zinc-800 text-zinc-300',};@@ -268,14 +269,16 @@ export const AwayPage: React.FC<AwayPageProps> = ({ since = null, onSince, onOpe};}, [load]);- const act = async (item: AwayItem, run: () => Promise<unknown>) => {+ const act = async (item: AwayItem, run: () => Promise<unknown>, denied = false) => {if (busy) return;setBusy(item.id);setNotice(null);try {- await run();+ const reply = await run();setData((d) => (d ? withoutItem(d, 'waiting', item.id) : d));- setNotice({ text: `Sent to ${item.kwant_name}: “${item.title}”`, error: false });+ const late = item.kind === 'approval' && !denied ? lateAnswerText(reply, item.kwant_name) : null;+ const done = denied ? 'Denied, nothing ran:' : late ?? `Sent to ${item.kwant_name}:`;+ setNotice({ text: `${done} “${item.title}”`, error: false });} catch (err) {const status = err instanceof AwayError ? err.status : 0;const text = actionErrorText(status, `Couldn't send it: ${err instanceof Error ? err.message : 'Something went wrong.'}`);@@ -309,7 +312,7 @@ export const AwayPage: React.FC<AwayPageProps> = ({ since = null, onSince, onOpeif (err instanceof AwayError && (err.status === 409 || err.status === 404)) onApprovalResolved?.(item.id);throw err;}- })+ }, decision === 'deny')}/>);diff --git a/frontend/src/components/LooseEndsView.tsx b/frontend/src/components/LooseEndsView.tsxindex 0c659efe..ecbd0497 100644--- a/frontend/src/components/LooseEndsView.tsx+++ b/frontend/src/components/LooseEndsView.tsx@@ -9,6 +9,7 @@ import {ExternalLink,FileText,GitBranch,+ Bot,Loader2,Mail,MessageSquare,@@ -32,6 +33,8 @@ import {ImapFields,LooseCase,LooseEndsError,+ LooseOwner,+ LooseOwnerChange,LooseSource,NewSource,Tone,@@ -47,6 +50,8 @@ import {isLoopbackHost,kindLabel,looseApi,+ ownerChange,+ ownerSummary,safeHref,shortDate,sourceLabel,@@ -607,6 +612,109 @@ export const LooseSources: React.FC<{);};+/** Which bot prepares drafts when a review or a letter deadline comes up, in this space. */+export const LooseOwnerView: React.FC<{+ owner: LooseOwner | null;+ bots: Array<{ id: string; name: string }>;+ error: string | null;+ busy: boolean;+ onChange: (next: LooseOwnerChange) => void;+}> = ({ owner, bots, error, busy, onChange }) => {+ const id = useId();+ const lead = owner && !owner.kwant_id ? owner.owner : null;+ return (+ <section aria-labelledby={`${id}-h`} className="space-y-2">+ <h3 id={`${id}-h`} className="text-[11px] font-semibold text-zinc-500 uppercase tracking-wider">+ Who prepares drafts+ </h3>+ {!owner ? (+ error ? (+ <p className="text-xs text-rose-300">Couldn’t load this setting: {error}</p>+ ) : (+ <p className="flex items-center gap-2 text-xs text-zinc-400">+ <Loader2 size={13} className="animate-spin motion-reduce:animate-none" aria-hidden="true" /> Loading…+ </p>+ )+ ) : (+ <div className="rounded-xl border border-zinc-800 bg-zinc-900/60 p-3 space-y-3" aria-busy={busy}>+ <label className="flex items-start gap-2.5 text-xs text-zinc-200 cursor-pointer">+ <input+ type="checkbox"+ checked={owner.enabled}+ disabled={busy}+ onChange={(e) => onChange(ownerChange(owner, { enabled: e.target.checked }))}+ className="mt-0.5 h-4 w-4 shrink-0 accent-sky-500"+ />+ <span>When a review finds loose ends or a letter deadline comes up, a bot starts preparing drafts and next steps.</span>+ </label>+ <div className="flex flex-wrap items-center gap-2 sm:pl-6">+ <Bot size={14} className="text-sky-400 shrink-0" aria-hidden="true" />+ <label htmlFor={`${id}-bot`} className="text-xs text-zinc-400">+ Bot+ </label>+ <select+ id={`${id}-bot`}+ value={owner.kwant_id ?? ''}+ disabled={busy || !owner.enabled}+ onChange={(e) => onChange(ownerChange(owner, { kwant_id: e.target.value || null }))}+ className={`${field} w-auto min-w-0 max-w-full flex-1 sm:flex-none sm:min-w-[14rem]`}+ >+ <option value="">{lead ? `The space lead (${lead.name})` : 'The space lead'}</option>+ {bots.map((b) => (+ <option key={b.id} value={b.id}>+ {b.name}+ </option>+ ))}+ </select>+ {busy && <Loader2 size={13} className="animate-spin motion-reduce:animate-none text-zinc-400" aria-label="Saving" />}+ </div>+ <p className={`text-[11px] sm:pl-6 ${owner.enabled ? 'text-zinc-400' : 'text-zinc-500'}`} data-owner-summary>+ {ownerSummary(owner)}+ </p>+ <div role="status" aria-live="polite">+ {error && <p className="text-xs text-rose-300 sm:pl-6">Couldn’t save: {error}</p>}+ </div>+ </div>+ )}+ </section>+ );+};++/** Loads and saves the owner setting for the current space. */+export const LooseOwnerSetting: React.FC = () => {+ const [owner, setOwner] = useState<LooseOwner | null>(null);+ const [bots, setBots] = useState<Array<{ id: string; name: string }>>([]);+ const [error, setError] = useState<string | null>(null);+ const [busy, setBusy] = useState(false);+ useEffect(() => {+ let cancelled = false;+ looseApi.owner().then(+ (o) => !cancelled && setOwner(o),+ (e) => !cancelled && setError(e instanceof Error ? e.message : 'something went wrong.'),+ );+ looseApi.bots().then(+ (list) => !cancelled && setBots(Array.isArray(list) ? list.map((k) => ({ id: k.id, name: k.name })) : []),+ () => undefined,+ );+ return () => {+ cancelled = true;+ };+ }, []);+ const save = async (next: LooseOwnerChange) => {+ if (busy) return;+ setBusy(true);+ setError(null);+ try {+ setOwner(await looseApi.setOwner(next));+ } catch (e) {+ setError(e instanceof Error ? e.message : 'something went wrong.');+ } finally {+ setBusy(false);+ }+ };+ return <LooseOwnerView owner={owner} bots={bots} error={error} busy={busy} onChange={save} />;+};+export interface LooseEndsViewProps {cases: LooseCase[] | null;loading: boolean;@@ -620,6 +728,8 @@ export interface LooseEndsViewProps {now?: number;nextReviewAt?: string | null;sources: React.ReactNode;+ /** "Who prepares drafts": the per-space owner setting. */+ owner?: React.ReactNode;onTab: (t: CaseTab) => void;onRefresh: () => void;onScan: () => void;@@ -644,6 +754,7 @@ export const LooseEndsView: React.FC<LooseEndsViewProps> = ({now = Date.now(),nextReviewAt = null,sources,+ owner = null,onTab,onRefresh,onScan,@@ -762,6 +873,7 @@ export const LooseEndsView: React.FC<LooseEndsViewProps> = ({</>)}+ {!needsToken && owner}{!needsToken && sources}</div></div>@@ -927,6 +1039,7 @@ export const LooseEndsPage: React.FC<{ onBack?: () => void; onOpenChat?: (kwantI)}onBack={onBack}+ owner={<LooseOwnerSetting />}sources={<LooseSources sources={sources} error={sourcesError} onChanged={() => (loadSources(), load())} />}/>);diff --git a/frontend/src/components/ModernApprovalCard.tsx b/frontend/src/components/ModernApprovalCard.tsxindex 4d6c7438..c136cfc9 100644--- a/frontend/src/components/ModernApprovalCard.tsx+++ b/frontend/src/components/ModernApprovalCard.tsx@@ -1,5 +1,5 @@import React from 'react';-import { ShieldAlert, Check, CheckCheck, X, Plug, FileText, Terminal } from 'lucide-react';+import { ShieldAlert, Check, CheckCheck, X, Plug, FileText, Terminal, Clock } from 'lucide-react';import { playSfx } from '../audio/chiptune';import { formatArgs, humanizeToolName, parseMcpToolName } from '../mcp';@@ -7,6 +7,11 @@ export interface PendingApproval {id: string;tool_name: string;details: Record<string, unknown>;+ /**+ * The bot's turn stopped waiting for this card (status `waiting`), but it's still open: Allow+ * starts the bot again to make that call, Deny closes it.+ */+ waiting?: boolean;}interface ModernApprovalCardProps {@@ -87,6 +92,10 @@ export const builtinView = (approval: PendingApproval) => {return { ...base, kind: 'other' as const, command: null, description: null, path: null, change: null, args: formatArgs(args) };};+/** The line under a still-open card's heading. */+export const waitingNote = (bot: string | null) =>+ `${bot ?? 'The bot'} stopped waiting for an answer and nothing ran. Allow starts it again to make this call; Deny closes the card.`;+export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({approval,onResolve,@@ -104,13 +113,29 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({const name = builtin?.kwant ?? summary?.kwant;const who = name ? <span className="font-medium text-zinc-100">{name}</span> : 'A bot';const perSession = !!builtin || !!summary?.builtin;+ const waiting = approval.waiting === true;+ const botName = name ?? mcp?.kwant ?? null;return (- <div className="my-3 border border-amber-500/30 bg-amber-950/20 rounded-xl p-4 text-zinc-100 max-w-2xl shadow-lg backdrop-blur-sm">- <div className="flex items-center gap-2 mb-2 text-amber-400 font-semibold text-xs tracking-wide">- <ShieldAlert size={16} />- <span>Action Approval Required</span>- </div>+ <div+ className={`my-3 border rounded-xl p-4 text-zinc-100 max-w-2xl shadow-lg backdrop-blur-sm ${+ waiting ? 'border-sky-500/30 bg-sky-950/20' : 'border-amber-500/30 bg-amber-950/20'+ }`}+ >+ {waiting ? (+ <div className="mb-2 space-y-1">+ <div className="flex items-center gap-2 text-sky-300 font-semibold text-xs tracking-wide">+ <Clock size={16} aria-hidden="true" />+ <span>Still open: you can still Allow</span>+ </div>+ <p className="text-[11px] text-zinc-400">{waitingNote(botName)}</p>+ </div>+ ) : (+ <div className="flex items-center gap-2 mb-2 text-amber-400 font-semibold text-xs tracking-wide">+ <ShieldAlert size={16} />+ <span>Action Approval Required</span>+ </div>+ )}{shell ? (<div className="bg-zinc-900/90 rounded-lg p-3 border border-zinc-800 text-xs space-y-2 mb-3">@@ -234,11 +259,12 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({className="flex items-center gap-1.5 px-3 py-1.5 min-h-[40px] sm:min-h-0 rounded-lg focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-400 text-xs font-medium text-white bg-emerald-600 hover:bg-emerald-500 transition-colors shadow-sm disabled:opacity-50 disabled:cursor-not-allowed"><Check size={14} />- <span>Allow Once</span>+ <span>{waiting ? 'Allow and continue' : 'Allow Once'}</span></button>- {/* Local shell approvals are never remembered, so only offer a one-off answer. */}- {!shell && (+ {/* Local shell approvals are never remembered, so only offer a one-off answer. A late+ answer only lets that one call run, so it gets no "always" either. */}+ {!shell && !waiting && (<buttontype="button"disabled={disabled}diff --git a/frontend/src/looseEnds.ts b/frontend/src/looseEnds.tsindex fee1f4f9..56c234c1 100644--- a/frontend/src/looseEnds.ts+++ b/frontend/src/looseEnds.ts@@ -249,6 +249,38 @@ export interface NewSource {secret: string;}+/**+ * Who gets a turn when a review picks cases or a letter deadline comes up (`/api/zombie/owner`,+ * per space). The bot only prepares drafts and next steps; nothing is sent without the person.+ */+export interface LooseOwner {+ enabled: boolean;+ /** The picked bot, or null for the space's lead. */+ kwant_id: string | null;+ daily_cap: number;+ /** The bot that would get the turn now (the pick or the lead), or null when there is none. */+ owner: { id: string; name: string } | null;+ used_today: number;+}+export type LooseOwnerChange = Pick<LooseOwner, 'enabled' | 'kwant_id' | 'daily_cap'>;++/** The PUT body for one change, keeping the rest as it is. */+export const ownerChange = (o: LooseOwner, change: Partial<LooseOwnerChange>): LooseOwnerChange => ({+ enabled: o.enabled,+ kwant_id: o.kwant_id,+ daily_cap: o.daily_cap,+ ...change,+});++/** The line under the setting: who, how often, and how much of today's cap is used. */+export function ownerSummary(o: LooseOwner): string {+ if (!o.enabled) return 'Off. Reviews and deadlines still notify you, but no bot starts on them.';+ if (!o.owner) return 'No bot to start: this space has no lead yet. Pick a bot below.';+ if (o.daily_cap === 0) return `${o.owner.name} is picked, but the daily limit is 0, so no turn starts.`;+ const used = Math.min(o.used_today, o.daily_cap);+ return `${o.owner.name} prepares drafts and next steps, up to ${o.daily_cap} ${o.daily_cap === 1 ? 'time' : 'times'} a day (${used} used today, UTC). Nothing is sent without you.`;+}+export const looseApi = {cases: () => call<{ cases: LooseCase[]; running: boolean }>('/api/zombie/cases'),act: (id: string, action: CaseAction, body?: unknown) => call<LooseCase>(`/api/zombie/cases/${enc(id)}/${action}`, 'POST', body ?? {}),@@ -259,6 +291,9 @@ export const looseApi = {testSource: (id: string) => call<{ ok: boolean; test: unknown }>(`/api/zombie/sources/${enc(id)}/test`, 'POST'),run: () => call<{ started: boolean }>('/api/zombie/run', 'POST', {}),status: () => call<{ running: boolean; next_review_at: string | null }>('/api/zombie/status'),+ owner: () => call<LooseOwner>('/api/zombie/owner'),+ setOwner: (o: LooseOwnerChange) => call<LooseOwner>('/api/zombie/owner', 'PUT', o),+ bots: () => call<Array<{ id: string; name: string }>>('/api/kwants'),};/** IMAP over plain text or with a self-signed certificate is only for a server on this computer. */diff --git a/frontend/tests/autonomyUi.test.mjs b/frontend/tests/autonomyUi.test.mjsnew file mode 100644index 00000000..09868701--- /dev/null+++ b/frontend/tests/autonomyUi.test.mjs@@ -0,0 +1,168 @@+// Autonomy UI: a card whose turn stopped waiting is still open (status `waiting`) and says so, and+// the per-space Loose ends owner setting (GET/PUT /api/zombie/owner).+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 { approvalFromAway, upsertApproval, syncApprovals, lateAnswerText } from './src/approvals';+ export { itemLabel } from './src/away';+ export { ownerChange, ownerSummary } from './src/looseEnds';+ import React from 'react';+ import { renderToStaticMarkup } from 'react-dom/server.browser';+ import { ModernApprovalCard } from './src/components/ModernApprovalCard';+ import { AwayView } from './src/components/AwayView';+ import { LooseOwnerView, LooseEndsView } from './src/components/LooseEndsView';+ export const card = (approval, extra = {}) => renderToStaticMarkup(React.createElement(ModernApprovalCard, { approval, onResolve: () => {}, ...extra }));+ export const away = (props) => renderToStaticMarkup(React.createElement(AwayView, props));+ export const owner = (props) => renderToStaticMarkup(React.createElement(LooseOwnerView, props));+ export const loose = (props) => renderToStaticMarkup(React.createElement(LooseEndsView, props));+ export { ModernApprovalCard, LooseOwnerView, React, renderToStaticMarkup };+`);++// Shaped like item() in src/server/away.rs for a row from away_waiting_approvals.+const awayItem = (status) => ({+ kind: 'approval', id: 'ap1', kwant_id: 'k1', kwant_name: 'Architect', title: 'Use Bash', summary: 'command: ls',+ status, timestamp: '2026-10-22T01:00:00Z', link: { thread_id: null, channel_id: null, direct_kwant_id: 'k1' },+ tool_name: 'Bash', details: { source: 'claude_builtin', tool: 'Bash', arguments: { command: 'ls build/' } },+});++test('a waiting away item becomes a still-open card; a pending one does not', () => {+ assert.equal(m.approvalFromAway(awayItem('waiting')).waiting, true);+ assert.equal(m.approvalFromAway(awayItem('pending')).waiting, undefined);+});++test('the server decides waiting: a live card turns waiting on sync, and back', () => {+ const live = { id: 'ap1', tool_name: 'Bash', details: { source: 'claude_builtin', tool: 'Bash', arguments: { command: 'ls build/' } }, kwant_id: 'k1', link: null };+ const synced = m.syncApprovals([live], [m.approvalFromAway(awayItem('waiting'))]);+ assert.equal(synced[0].waiting, true);+ const again = m.upsertApproval(synced, m.approvalFromAway(awayItem('pending')));+ assert.equal(again[0].waiting, undefined);+ // A summary-only server row keeps the live details but still takes the server's waiting flag.+ const summary = { ...m.approvalFromAway({ ...awayItem('waiting'), details: null }), waiting: true };+ const kept = m.upsertApproval([live], summary);+ assert.equal(kept[0].details.source, 'claude_builtin');+ assert.equal(kept[0].waiting, true);+});++test('a still-open card says so, keeps Allow and Deny, and drops Always', () => {+ const html = m.card({ ...m.approvalFromAway(awayItem('waiting')), details: { ...awayItem('waiting').details, kwant_name: 'Architect' } });+ assert.match(html, /Still open: you can still Allow/);+ assert.match(html, /Architect stopped waiting for an answer and nothing ran/);+ assert.match(html, /Allow and continue/);+ assert.match(html, />Deny</);+ assert.doesNotMatch(html, /Always/);+ assert.doesNotMatch(html, /Action Approval Required/);+ // A normal card is unchanged.+ const normal = m.card(m.approvalFromAway(awayItem('pending')));+ assert.match(normal, /Action Approval Required/);+ assert.match(normal, /Always this session/);+ assert.doesNotMatch(normal, /Still open/);+});++test('Allow and Deny on a still-open card answer with allow_once and deny', () => {+ const calls = [];+ const el = m.ModernApprovalCard({ approval: { ...m.approvalFromAway(awayItem('waiting')) }, onResolve: (id, d) => calls.push([id, d]) });+ const buttons = [];+ const walk = (n) => {+ if (!n || typeof n !== 'object') return;+ if (Array.isArray(n)) return n.forEach(walk);+ if (n.type === 'button') buttons.push(n);+ walk(n.props?.children);+ };+ walk(el);+ assert.equal(buttons.length, 2);+ for (const b of buttons) b.props.onClick();+ assert.deepEqual(calls, [['ap1', 'deny'], ['ap1', 'allow_once']]);+ // Disabled while sending: no answer goes out.+ const busy = [];+ const el2 = m.ModernApprovalCard({ approval: m.approvalFromAway(awayItem('waiting')), disabled: true, onResolve: (...a) => busy.push(a) });+ const b2 = [];+ const walk2 = (n) => { if (!n || typeof n !== 'object') return; if (Array.isArray(n)) return n.forEach(walk2); if (n.type === 'button') b2.push(n); walk2(n.props?.children); };+ walk2(el2);+ b2.forEach((b) => b.props.onClick());+ assert.equal(busy.length, 0);+});++test('the away list labels a still-open card and renders it', () => {+ assert.deepEqual(m.itemLabel({ kind: 'approval', status: 'waiting' }), { label: 'Still open', tone: 'sky' });+ assert.deepEqual(m.itemLabel({ kind: 'approval', status: 'pending' }), { label: 'Needs approval', tone: 'amber' });+ const data = { since: '2026-10-22T00:00:00Z', waiting: [awayItem('waiting')], finished: [], failed: [], unseen: { total: 1, waiting: 1, finished: 0, failed: 0 } };+ const html = m.away({ data, loading: false, error: null, onRefresh() {}, onOpen() {}, onAnswer() {}, onResolve() {} });+ assert.match(html, /Still open/);+ assert.match(html, /Allow and continue/);+});++test('after a late Allow the person hears the bot picks it back up', () => {+ assert.equal(m.lateAnswerText({ resumed: 'new_turn', status: 'allowed_once' }, 'Architect'), 'Allowed. Architect is picking the work back up.');+ assert.equal(m.lateAnswerText({ resumed: false, reason: 'the bot no longer exists' }, null), "Allowed, but The bot couldn't continue: the bot no longer exists.");+ assert.equal(m.lateAnswerText({ resolved: true, status: 'allowed_once' }, 'Architect'), null);+ assert.equal(m.lateAnswerText(null, 'Architect'), null);+});++// Shaped like owner_view in src/server/zombie_routes.rs.+const ownerRow = (over = {}) => ({ enabled: true, kwant_id: null, daily_cap: 3, owner: { id: 'k1', name: 'Architect' }, used_today: 1, ...over });++test('owner summary covers on, off, no lead, a 0 cap and a used-up cap', () => {+ assert.equal(m.ownerSummary(ownerRow()), 'Architect prepares drafts and next steps, up to 3 times a day (1 used today, UTC). Nothing is sent without you.');+ assert.match(m.ownerSummary(ownerRow({ enabled: false })), /^Off\. Reviews and deadlines still notify you/);+ assert.match(m.ownerSummary(ownerRow({ owner: null })), /no lead yet/);+ assert.match(m.ownerSummary(ownerRow({ daily_cap: 0 })), /daily limit is 0/);+ assert.match(m.ownerSummary(ownerRow({ daily_cap: 1, used_today: 4 })), /up to 1 time a day \(1 used today/);+});++test('a change keeps the other fields for the PUT body', () => {+ assert.deepEqual(m.ownerChange(ownerRow({ kwant_id: 'k2' }), { enabled: false }), { enabled: false, kwant_id: 'k2', daily_cap: 3 });+ assert.deepEqual(m.ownerChange(ownerRow(), { kwant_id: 'k2' }), { enabled: true, kwant_id: 'k2', daily_cap: 3 });+});++test('the owner setting shows the toggle, the lead by name, the bots and the cap', () => {+ const bots = [{ id: 'k1', name: 'Architect' }, { id: 'k2', name: 'Writer' }];+ const html = m.owner({ owner: ownerRow(), bots, error: null, busy: false, onChange() {} });+ assert.match(html, /Who prepares drafts/);+ assert.match(html, /<input type="checkbox"[^>]*checked=""/);+ assert.match(html, /The space lead \(Architect\)/);+ assert.match(html, />Writer</);+ assert.match(html, /up to 3 times a day/);+ // Off: the bot picker is disabled.+ const off = m.owner({ owner: ownerRow({ enabled: false }), bots, error: null, busy: false, onChange() {} });+ assert.match(off, /<select[^>]*disabled=""/);+ // Loading, load error and save error.+ assert.match(m.owner({ owner: null, bots: [], error: null, busy: false, onChange() {} }), /Loading/);+ assert.match(m.owner({ owner: null, bots: [], error: 'HTTP 500', busy: false, onChange() {} }), /Couldn’t load this setting: HTTP 500/);+ assert.match(m.owner({ owner: ownerRow(), bots, error: 'the owner must be a bot in this space', busy: false, onChange() {} }), /Couldn’t save: the owner must be a bot/);+});++test('the toggle and picker send the whole setting', () => {+ // Render through a wrapper that keeps the element tree, then call its handlers.+ let tree = null;+ const sent = [];+ const Capture = (props) => (tree = m.LooseOwnerView(props));+ m.renderToStaticMarkup(m.React.createElement(Capture, { owner: ownerRow({ kwant_id: 'k2' }), bots: [{ id: 'k2', name: 'Writer' }], error: null, busy: false, onChange: (b) => sent.push(b) }));+ const found = [];+ const walk = (n) => { if (!n || typeof n !== 'object') return; if (Array.isArray(n)) return n.forEach(walk); if (n.type === 'input' || n.type === 'select') found.push(n); walk(n.props?.children); };+ walk(tree);+ const [box, select] = found;+ box.props.onChange({ target: { checked: false } });+ select.props.onChange({ target: { value: '' } });+ select.props.onChange({ target: { value: 'k2' } });+ assert.deepEqual(sent, [+ { enabled: false, kwant_id: 'k2', daily_cap: 3 },+ { enabled: true, kwant_id: null, daily_cap: 3 },+ { enabled: true, kwant_id: 'k2', daily_cap: 3 },+ ]);+ // Busy: both controls are disabled while saving.+ m.renderToStaticMarkup(m.React.createElement(Capture, { owner: ownerRow(), bots: [], error: null, busy: true, onChange() {} }));+ found.length = 0;+ walk(tree);+ assert.ok(found.every((n) => n.props.disabled === true));+});++test('the Loose ends page shows the owner slot only once the person is confirmed', () => {+ const slot = m.React.createElement('div', { 'data-owner-slot': '1' }, 'OWNER');+ const base = { cases: [], loading: false, running: false, error: null, tab: 'open', sources: null, onTab() {}, onRefresh() {}, onScan() {}, onAction() {}, owner: slot };+ assert.match(m.loose(base), /data-owner-slot/);+ assert.doesNotMatch(m.loose({ ...base, needsToken: true }), /data-owner-slot/);+});