Skip to content

armgit / kwant

Public Imported from GitHub
0

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.

Sidebar says "Needs you" only for real asks; Inbox count folds a routine run once (30z) (#907)

Oleksandr Ivanchenko5a16e1d4b0e0
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 8346e1dc..6e235243 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -60,7 +60,8 @@ import { RouteChoiceCard } from './components/RouteChoiceCard';
import { RouteChoiceMeta, applyRouteChoice, correctRoute, isAskingReply, rerouteTargetsFor, resolveRouteChoice } from './routeChoice';
import type { RoutineFocus } from './components/RoutinesPanel';
import { InboxNew } from './components/InboxNew';
-import { inboxBadge, isReview, type InboxItem } from './api/inbox';
+import { isReview, type InboxItem } from './api/inbox';
+import { inboxCount as foldedInboxCount } from './doneAway';
import { batchItems, inboxNav, loadInbox, openItem, useInbox } from './inboxStore';
import { LooseEndsPage } from './components/LooseEndsView';
import { MissionBoardPage } from './components/MissionBoardView';
@@ -631,7 +632,8 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
const [awayCount, setAwayCount] = useState(0);
// 0.9.0 V1: the Inbox store (GET /api/inbox, or /api/away before the server has it).
const inboxState = useInbox();
- const inboxCount = inboxBadge(inboxState.data, { unseen: { total: awayCount } }, prepushWaiting);
+ // 30z: a routine run folded into its review item counts once (doneAway.inboxCount).
+ const inboxCount = useMemo(() => foldedInboxCount(inboxState.data, { unseen: { total: awayCount } }, prepushWaiting), [inboxState.data, awayCount, prepushWaiting]);
const reviewItems: InboxItem[] = inboxState.data ? [...inboxState.data.items, ...batchItems(inboxState.data)].filter(isReview) : [];
// "Needs you" nudges (attention.ts): what waits on the person, the pill, and the "Show nudges" setting.
const [awayWaiting, setAwayWaiting] = useState(0);
diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsx
index 48f3e5c5..dd140fda 100644
--- a/frontend/src/components/Sidebar.tsx
+++ b/frontend/src/components/Sidebar.tsx
@@ -240,31 +240,42 @@ export function botGroups(teams: Team[], kwants: Kwant[]): Array<{ team: Team |
export const PINNED_MAX = 5;
/**
- * H5 desktop: "Needs you · n" (14c: the phone's name too), ranks 1–4 above Channels. Gone when empty. The count is announced
- * politely, at most once per 10 s, from a live region holding only the heading's words.
+ * H5 desktop: ranks 1–4 pinned above Channels. Gone when empty. 30z: the heading says "Needs you · n" (14c: the phone's
+ * name too) in amber with a hand only for real asks (rank 1–2); with only things to review or read it is a calm
+ * "New · n" with the Inbox icon. The words are announced politely, at most once per 10 s, from a live region holding
+ * only the heading's words.
*/
const NeedsAttention: React.FC<{ rows: AttentionRow<Kwant>[]; row: (a: AttentionRow<Kwant>) => React.ReactNode; onOpenInbox?: () => void }> = ({ rows, row, onOpenInbox }) => {
const n = rows.length;
- const [said, setSaid] = useState(n);
+ const asks = rows.filter((a) => a.rank <= 2).length;
+ const label = asks > 0 ? NEEDS_YOU_LABEL : 'New';
+ const count = asks > 0 ? asks : n;
+ const words = `${label}, ${count}`;
+ const [said, setSaid] = useState(words);
const lastSaid = React.useRef(0);
useEffect(() => {
- if (n === said) return;
+ if (words === said) return;
const wait = Math.max(0, lastSaid.current + 10_000 - Date.now());
const t = setTimeout(() => {
lastSaid.current = Date.now();
- setSaid(n);
+ setSaid(words);
}, wait);
return () => clearTimeout(t);
- }, [n, said]);
+ }, [words, said]);
const more = n - PINNED_MAX;
return (
<section data-needs-attention aria-labelledby="needs-attention-head" className="rounded-xl border border-hairline bg-white/[0.015] my-1.5 pb-1.5">
- <h2 id="needs-attention-head" className="px-2 pt-1.5 pb-1 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-[0.06em] text-amber-300" aria-label={`${NEEDS_YOU_LABEL}, ${n}`}>
- <Hand size={12} aria-hidden="true" />
- <span aria-hidden="true">{NEEDS_YOU_LABEL} · {n}</span>
+ <h2
+ id="needs-attention-head"
+ data-needs-attention-head={asks > 0 ? 'asks' : 'new'}
+ className={`px-2 pt-1.5 pb-1 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-[0.06em] ${asks > 0 ? 'text-amber-300' : 'text-zinc-400'}`}
+ aria-label={words}
+ >
+ {asks > 0 ? <Hand size={12} aria-hidden="true" /> : <Inbox size={12} aria-hidden="true" />}
+ <span aria-hidden="true">{label} · {count}</span>
</h2>
<span className="sr-only" aria-live="polite" data-needs-attention-live>
- {said !== n || lastSaid.current ? `${NEEDS_YOU_LABEL}, ${said}` : ''}
+ {said !== words || lastSaid.current ? said : ''}
</span>
<div className="space-y-0.5 px-0.5">
{rows.slice(0, PINNED_MAX).map((a) => (
diff --git a/frontend/src/doneAway.ts b/frontend/src/doneAway.ts
index 6195c149..5c2e2ae7 100644
--- a/frontend/src/doneAway.ts
+++ b/frontend/src/doneAway.ts
@@ -7,7 +7,7 @@
import { parseActivityMeta, plainTitle } from './activity';
import { readableStepTitle } from './toolLabel';
import type { DoneTrailStep, InboxGroup, InboxItem, InboxResponse, ReviewItem, TeamMember } from './api/inbox';
-import { isReview } from './api/inbox';
+import { inboxBadge, isReview } from './api/inbox';
import { type Routine, type RoutineRun, type Schedule, WEEKDAYS, monthDaysText } from './continuity';
import { parseMetaObject } from './questions';
import { relativeTime } from './away';
@@ -102,6 +102,18 @@ export function sectionItems(r: Pick<InboxResponse, 'items'>): Sections {
};
}
+/**
+ * 30z: the one Inbox count (sidebar, Inbox page, phone tab bar). The server's badge counts a routine's finished run
+ * once as unseen and again as its review item; the list folds that run into the review (`runFor`), so the count
+ * folds it too: one finished routine run reads 1, not 2.
+ */
+export function inboxCount(inbox: Pick<InboxResponse, 'items' | 'counts'> | null | undefined, away: { unseen: { total: number } } | null | undefined, prepushWaiting = 0): number {
+ const badge = inboxBadge(inbox, away, prepushWaiting);
+ if (!inbox?.items?.length) return badge;
+ const folded = Object.values(sectionItems(inbox).runFor).filter((r) => r.unread).length;
+ return Math.max(0, badge - folded);
+}
+
/** The row's first line before the bot's name: "Routine" for a routine's work, else nothing. */
export const rowKicker = (i: InboxItem): string | null => (isRoutineItem(i) ? 'Routine' : null);
diff --git a/frontend/tests/attentionOrder.test.mjs b/frontend/tests/attentionOrder.test.mjs
index 99bbea3a..b436c45f 100644
--- a/frontend/tests/attentionOrder.test.mjs
+++ b/frontend/tests/attentionOrder.test.mjs
@@ -88,12 +88,12 @@ const render = (over = {}) => m.renderToStaticMarkup(React.createElement(m.Sideb
}));
const doc = (html) => new DOMParser().parseFromString(`<body>${html}</body>`, 'text/html');
-test('desktop: pinned "Needs you · 4" above Channels, copies with "Also listed in @core"', () => {
+test('desktop: pinned "Needs you · 3" (asks only) above Channels, copies with "Also listed in @core"', () => {
const d = doc(render());
const block = d.querySelector('[data-needs-attention]');
assert.ok(block);
- assert.equal(block.querySelector('h2').getAttribute('aria-label'), 'Needs you, 4');
- assert.match(block.querySelector('h2').textContent, /Needs you · 4/);
+ assert.equal(block.querySelector('h2').getAttribute('aria-label'), 'Needs you, 3', '30z: only the asks (ranks 1–2) count');
+ assert.match(block.querySelector('h2').textContent, /Needs you · 3/);
assert.match(block.querySelector('h2').getAttribute('class'), /text-amber-300/);
const pins = [...block.querySelectorAll('[data-pin-row]')];
assert.deepEqual(pins.map((p) => p.getAttribute('data-pin-row')), ['lin', 'pix', 'jun', 'iri']);
diff --git a/frontend/tests/needsYouOnlyRealAsks.test.mjs b/frontend/tests/needsYouOnlyRealAsks.test.mjs
new file mode 100644
index 00000000..96754147
--- /dev/null
+++ b/frontend/tests/needsYouOnlyRealAsks.test.mjs
@@ -0,0 +1,98 @@
+// 30z (autonomy/needs-you-only-real-asks/brief.md, Mira's ux-pass-0931 fix #2): one finished routine run must not
+// cry wolf. The sidebar's pinned heading says amber "Needs you · n" with a hand only for real asks (ranks 1–2);
+// with only rank 3–4 rows it is a calm zinc "New · n" with the Inbox icon. The Inbox count folds a routine's run
+// into its review item, as the list does, so the run counts once. Every test here fails on main bd7b7f0b.
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { readFileSync } from 'node:fs';
+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', 'DOMParser', 'localStorage', 'sessionStorage', 'getComputedStyle']) {
+ if (k in dom.window) Object.defineProperty(globalThis, k, { value: dom.window[k], configurable: true, writable: true });
+}
+
+const m = await loadBundled(`
+ export { default as React } from 'react';
+ export { renderToStaticMarkup } from 'react-dom/server.browser';
+ export { Sidebar } from './src/components/Sidebar';
+ export { inboxCount, sectionItems } from './src/doneAway';
+`);
+const { React } = m;
+const noop = () => {};
+const NOW = Date.parse('2026-11-20T06:00:00Z');
+const at = (min) => new Date(NOW - min * 60_000).toISOString();
+const space = { id: 'spc_default', name: 'Trailhead', icon: '💼', color: '#f59e0b', sort: 0, is_default: true, archived_at: null,
+ created_at: '', general_channel_id: null, counts: { bots: 0, ready_accounts: 0, unread: 0 }, approvals: 'on' };
+const bot = (id, name) => ({ id, name, title: 'Role', persona_prompt: '', avatar_sprite: 'mouse', driver_type: 'claude', preferred_model: '' });
+const kwants = [bot('lin', 'Lin'), bot('pix', 'Pixel'), bot('iri', 'Iris')];
+const away = (kind, kwant_id, over = {}) => ({ kind, id: `${kind}-${kwant_id}`, kwant_id, kwant_name: kwant_id, title: 'Morning note', summary: '',
+ status: 'completed', timestamp: at(3), link: { thread_id: null, channel_id: null, direct_kwant_id: kwant_id }, ...over });
+const render = (attention) => m.renderToStaticMarkup(React.createElement(m.Sidebar, {
+ space, spaces: [space], onSwitchSpace: noop, onCreateSpace: noop, onOpenSpaceSettings: noop, onOpenArchived: noop, onOpenSearch: noop,
+ kwants, channels: [{ id: 'c1', name: 'general', space_id: 'spc_default' }], teams: [], selectedId: null, isChannel: false,
+ onSelectKwant: noop, onSelectChannel: noop, onSelectTeam: noop, onSummonKwant: noop, onCreateTeam: noop, onOpenInbox: noop, onOpenNeedsYou: noop,
+ busyKwants: {}, botStatus: {}, attention,
+}));
+const head = (attention) => new DOMParser().parseFromString(`<body>${render(attention)}</body>`, 'text/html').querySelector('[data-needs-attention] h2');
+
+const review = { kwant: kwants[0], rank: 3, line: 'To review: Routine: Morning note', item: away('delegation', 'lin') };
+const finished = { kwant: kwants[2], rank: 4, line: 'Finished: legend', item: away('delegation', 'iri') };
+const ask = { kwant: kwants[1], rank: 1, line: 'Wants your OK', item: away('approval', 'pix', { status: 'waiting' }) };
+
+test('only rank 3–4 pinned: a calm zinc "New · n" with the Inbox icon, no hand, no amber', () => {
+ const h = head([review]);
+ assert.ok(h, 'the block still shows its row');
+ assert.equal(h.textContent, 'New · 1');
+ assert.equal(h.getAttribute('aria-label'), 'New, 1');
+ assert.match(h.getAttribute('class'), /text-zinc-400/);
+ assert.doesNotMatch(h.getAttribute('class'), /amber/);
+ assert.ok(h.querySelector('svg.lucide-inbox'), 'Inbox icon');
+ assert.equal(h.querySelector('svg.lucide-hand'), null, 'no hand');
+ assert.equal(head([review, finished]).textContent, 'New · 2');
+});
+
+test('one real ask turns it amber "Needs you · 1" with the hand; the count is the asks, the rows stay', () => {
+ const html = render([ask, review, finished]);
+ const d = new DOMParser().parseFromString(`<body>${html}</body>`, 'text/html');
+ const h = d.querySelector('[data-needs-attention] h2');
+ assert.equal(h.textContent, 'Needs you · 1');
+ assert.equal(h.getAttribute('aria-label'), 'Needs you, 1');
+ assert.match(h.getAttribute('class'), /text-amber-300/);
+ assert.ok(h.querySelector('svg.lucide-hand'));
+ assert.equal(h.querySelector('svg.lucide-inbox'), null);
+ assert.equal(d.querySelectorAll('[data-pin-row]').length, 3, 'all three rows still pinned');
+ // A failed or stuck bot (rank 2) is a real ask too
+ assert.equal(head([{ ...review, rank: 2, line: 'Failed: crawl' }]).textContent, 'Needs you · 1');
+});
+
+// The Inbox after Run now on a read-only routine: its review item and the run it folds. The server's badge is
+// unseen_total (1: the run) + review_listed (1) = 2.
+const rev = { kind: 'review', id: 'rev-1', task_id: 'task-1', kwant_id: 'lin', kwant_name: 'Lin', title: 'Routine: Morning note', summary: '', status: 'pending',
+ group: 'to_review', timestamp: at(2), unread: true, link: {}, held_actions: [] };
+const run = { kind: 'routine_run', id: 'run-1', kwant_id: 'lin', kwant_name: 'Lin', title: 'Morning note', summary: '', status: 'completed',
+ group: 'finished', timestamp: at(3), unread: true, link: {} };
+const approval = { kind: 'approval', id: 'ap-1', kwant_id: 'pix', kwant_name: 'Pixel', title: 'Run a command', summary: '', status: 'waiting',
+ group: 'waiting_on_you', timestamp: at(1), unread: true, link: {} };
+const inbox = (items, badge) => ({ items, counts: { badge } });
+
+test('Inbox count: a routine run folded into its review item counts once (1, not 2); a real approval adds 1', () => {
+ assert.equal(m.sectionItems(inbox([rev, run], 2)).runFor['rev-1'].id, 'run-1', 'the list folds the run');
+ assert.equal(m.inboxCount(inbox([rev, run], 2), { unseen: { total: 1 } }), 1);
+ assert.equal(m.inboxCount(inbox([approval, rev, run], 3), { unseen: { total: 2 } }), 2);
+ // Once the run is read it is no longer in unseen_total, so nothing more comes off
+ assert.equal(m.inboxCount(inbox([rev, { ...run, unread: false }], 1), { unseen: { total: 0 } }), 1);
+ // A run with no review item is not folded and keeps counting
+ assert.equal(m.inboxCount(inbox([run], 1), { unseen: { total: 1 } }), 1);
+ // Before the first fetch: today's fallback
+ assert.equal(m.inboxCount(null, { unseen: { total: 3 } }, 1), 4);
+ assert.equal(m.inboxCount(inbox([rev, run], 0), null), 0, 'never below 0');
+});
+
+test('App feeds the folded count to the sidebar, the Inbox page and the phone tab bar', () => {
+ const src = readFileSync(new URL('../src/App.tsx', import.meta.url), 'utf8');
+ assert.match(src, /const inboxCount = useMemo\(\(\) => foldedInboxCount\(inboxState\.data,/);
+ assert.doesNotMatch(src, /const inboxCount = inboxBadge\(/);
+ for (const use of [/inboxCount=\{inboxCount\}/, /count=\{inboxCount\}/, /badge: inboxCount/]) assert.match(src, use);
+});