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.

30n approval-ring-again: a second "Go to the approval" rings the card again (#889)

Oleksandr Ivanchenko7976a7e8b475
diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsx
index 99f6e6cb..8c6818b9 100644
--- a/frontend/src/components/ChatView.tsx
+++ b/frontend/src/components/ChatView.tsx
@@ -1122,6 +1122,26 @@ export const ChatView: React.FC<ChatViewProps> = ({
// A search hit glows amber for 2.4 s; the original of a reply quote gets a violet ring for 1.6 s.
// 22i: a Needs-attention landing ('ask') is the same amber flash as search, tagged so tests tell them apart.
const [flashKind, setFlashKind] = useState<'search' | 'quote' | 'ask'>('search');
+ // 30n: a second "Go to the approval" (or search hit) on what is already flashing restarts the ring and its 2.4 s,
+ // like the quote jump: clear the flash, then set it again. Setting the same id again would change nothing. The
+ // second step waits for the cleared flash to commit, then two frames, so the browser draws a frame without
+ // kw-flash and the CSS animation starts over (rAFs queued at once can both run before React commits the null).
+ const [flashNext, setFlashNext] = useState<string | null>(null);
+ const restartFlash = (id: string, kind: 'search' | 'ask') => {
+ setFlashId(null);
+ setFlashKind(kind);
+ setFlashNext(id);
+ };
+ useEffect(() => {
+ if (!flashNext) return;
+ let f = requestAnimationFrame(() => {
+ f = requestAnimationFrame(() => {
+ setFlashId(flashNext);
+ setFlashNext(null);
+ });
+ });
+ return () => cancelAnimationFrame(f);
+ }, [flashNext]);
useEffect(() => {
if (!highlightMessageId) return;
// 0.8.1 F6: an approval's card (a notification names it), not a message
@@ -1134,8 +1154,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
// card's first choice does), never on Allow / Deny. A tap, an Inbox row or a notification leaves focus alone.
const from = document.activeElement;
if (from instanceof HTMLElement && stripSlotRef.current?.contains(from) && from.matches('[data-strip-action="decide"]:focus-visible')) card.focus({ preventScroll: true });
- setFlashKind(highlightRing ? 'ask' : 'search');
- setFlashId(highlightMessageId);
+ restartFlash(highlightMessageId, highlightRing ? 'ask' : 'search');
onHighlightDone?.();
return;
}
@@ -1151,8 +1170,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
if (!el) return;
const reduce = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
el.scrollIntoView({ block: 'center', behavior: reduce ? 'auto' : 'smooth' });
- setFlashKind(highlightRing ? 'ask' : 'search');
- setFlashId(highlightMessageId);
+ restartFlash(highlightMessageId, highlightRing ? 'ask' : 'search');
onHighlightDone?.();
}, [highlightMessageId, highlightRing, messages, openThoughts, onHighlightDone, pendingApprovals]);
useEffect(() => {
diff --git a/frontend/src/ring.ts b/frontend/src/ring.ts
deleted file mode 100644
index 8fd8c0da..00000000
--- a/frontend/src/ring.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-// 22i: the ring a Needs-attention row's landing gets (design.md §1): the search jump's amber `kw-flash`,
-// a 2.4 s glow that becomes a static outline under reduced motion, so the landing is shown either way.
-// ChatView rings messages through its own flash state; this is for cards outside the message list
-// (an approval card), which have no flash class of their own.
-
-export const RING_MS = 2400;
-
-/** Rings an element once with `kw-flash`, tagged `data-flash-kind="ask"` so tests can tell it from search. */
-export function ringElement(el: HTMLElement): void {
- el.classList.remove('kw-flash');
- void el.offsetWidth;
- el.classList.add('kw-flash');
- el.dataset.flashKind = 'ask';
- window.setTimeout(() => {
- el.classList.remove('kw-flash');
- delete el.dataset.flashKind;
- }, RING_MS);
-}
diff --git a/frontend/tests/approvalRingAgain.test.mjs b/frontend/tests/approvalRingAgain.test.mjs
new file mode 100644
index 00000000..bbaca13c
--- /dev/null
+++ b/frontend/tests/approvalRingAgain.test.mjs
@@ -0,0 +1,89 @@
+// 30n (brief: autonomy/approval-ring-again/brief.md; Mira's 30j design check, "Small things"): a second
+// "Go to the approval" while the card is still flashing must ring it again. Before, the second press set the same
+// flash id, React changed nothing, and the first 2.4 s ring just ran out, so the press looked like it did nothing.
+// Now the flash is cleared and set again (the quote jump's pattern): kw-flash goes off and back on, the 2.4 s starts
+// over, and #878's rule still holds: one .kw-flash element, the same wrapper and card, only kw-flash toggles.
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { JSDOM } from 'jsdom';
+import { loadBundled } from './bundle.mjs';
+
+const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/', pretendToBeVisual: true });
+const g = globalThis;
+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'Node', 'DOMParser', 'localStorage', 'sessionStorage', 'getComputedStyle', 'requestAnimationFrame', 'cancelAnimationFrame', 'MutationObserver']) {
+ if (k in dom.window) Object.defineProperty(g, k, { value: dom.window[k], configurable: true, writable: true });
+}
+g.IS_REACT_ACT_ENVIRONMENT = false;
+dom.window.HTMLElement.prototype.scrollIntoView = function () {};
+dom.window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {}, addListener() {}, removeListener() {} });
+if (!('ResizeObserver' in dom.window)) dom.window.ResizeObserver = class { observe() {} unobserve() {} disconnect() {} };
+g.ResizeObserver = dom.window.ResizeObserver;
+if (!g.CSS) g.CSS = { escape: (s) => String(s).replace(/["\\]/g, '\\$&') };
+
+const m = await loadBundled(`
+ export { default as React } from 'react';
+ export { createRoot } from 'react-dom/client';
+ export { flushSync } from 'react-dom';
+ export { ChatView } from './src/components/ChatView';
+`);
+
+const approval = { id: 'ap1', tool_name: 'execute_shell', details: { source: 'local_shell', tool: 'execute_shell', arguments: { command: 'curl -sI https://example.com', cwd: '/tmp' }, kwant_name: 'Mia' } };
+const messages = [
+ { id: 'u1', sender_role: 'user', sender_id: 'me', text: 'Check example.com', created_at: '2026-11-19T14:00:00Z', tokens_used: 0 },
+ { id: 'a1', sender_role: 'kwant', sender_id: 'Mia', text: 'Checking it now.', created_at: '2026-11-19T14:00:05Z', tokens_used: 0 },
+];
+const tick = (ms = 10) => new Promise((r) => setTimeout(r, ms));
+const until = async (f) => { for (let i = 0; i < 40 && !f(); i++) await tick(); return f(); };
+
+// ChatView as App drives it: a press sets highlightMessageId, and onHighlightDone clears it again.
+function mount() {
+ const host = document.createElement('div');
+ document.body.appendChild(host);
+ const root = m.createRoot(host);
+ let hl = null;
+ const render = () => root.render(m.React.createElement(m.ChatView, {
+ title: 'Mia', subtitle: '', messages, streamingText: '', streamingThinking: '', isStreaming: false,
+ pendingApprovals: [approval], onSendMessage() {}, onResolveApproval() {}, kwants: [], teams: [],
+ highlightMessageId: hl, highlightRing: hl != null, onHighlightDone: () => { hl = null; render(); },
+ }));
+ m.flushSync(render);
+ const press = () => { hl = 'ap1'; m.flushSync(render); };
+ return { host, press, done: () => { root.unmount(); host.remove(); } };
+}
+
+test('30n: a second "Go to the approval" during the 2.4 s flash rings the card again and starts a fresh 2.4 s', async () => {
+ const { host, press, done } = mount();
+ const card = host.querySelector('[data-approval-card="ap1"]');
+ const wrap = card.parentElement;
+ const idle = wrap.className;
+
+ press();
+ assert.ok(await until(() => wrap.classList.contains('kw-flash')), 'the first press flashes the card');
+ await tick(1200);
+ assert.ok(wrap.classList.contains('kw-flash'), 'still flashing 1.2 s in');
+
+ // Watch the wrapper's class: a fresh ring means kw-flash comes off and goes back on (a CSS animation only
+ // restarts that way); the same id set again leaves it untouched.
+ const seen = [];
+ const mo = new MutationObserver(() => seen.push(wrap.classList.contains('kw-flash')));
+ mo.observe(wrap, { attributes: true, attributeFilter: ['class'] });
+ press();
+ await until(() => seen.length >= 2 && wrap.classList.contains('kw-flash'));
+ mo.disconnect();
+ assert.deepEqual(seen, [false, true], `second press: kw-flash went ${JSON.stringify(seen)} (want off, then on again)`);
+
+ // #878's no-jump rule still holds after the restart.
+ assert.equal(host.querySelector('[data-approval-card="ap1"]'), card, 'same card element (no remount, 30a)');
+ assert.equal(card.parentElement, wrap, 'same wrapper element');
+ assert.equal(host.querySelectorAll('.kw-flash').length, 1, 'one amber ring');
+ assert.equal(wrap.className.replace(/\s*kw-flash\b/, ''), idle, 'only kw-flash toggles');
+ assert.equal(wrap.getAttribute('data-flash-kind'), 'ask');
+
+ // A fresh 2.4 s: the first ring would have ended at 2.4 s after the first press (1.2 s from here); it's still on.
+ await tick(1500);
+ assert.ok(wrap.classList.contains('kw-flash'), 'still flashing 2.7 s after the first press: the second press restarted the 2.4 s');
+ await tick(1100);
+ assert.equal(host.querySelectorAll('.kw-flash').length, 0, 'and it ends 2.4 s after the second press');
+ assert.equal(wrap.className, idle);
+ done();
+});
diff --git a/frontend/tests/askHere.test.mjs b/frontend/tests/askHere.test.mjs
index 458c199e..833b24aa 100644
--- a/frontend/tests/askHere.test.mjs
+++ b/frontend/tests/askHere.test.mjs
@@ -24,7 +24,6 @@ const m = await loadBundled(`
export { NeedsYouStrip } from './src/components/NeedsYouStrip';
export { Sidebar } from './src/components/Sidebar';
export { needsYouRows, attentionRows } from './src/chatsTab';
- export { ringElement } from './src/ring';
export { ModernApprovalCard } from './src/components/ModernApprovalCard';
`);
const h = m.React.createElement;
@@ -347,14 +346,6 @@ test('strip: a keyboard open focuses it; when the last ask closes, focus goes to
composer.remove();
});
-test('ring: a card outside the message list gets the amber kw-flash, tagged as an ask', () => {
- const el = document.createElement('div');
- document.body.append(el);
- m.ringElement(el);
- assert.ok(el.classList.contains('kw-flash'), 'kw-flash: a static outline under reduced motion, never nothing');
- assert.equal(el.dataset.flashKind, 'ask');
-});
-
// ---- the pinned row ----
const space = { id: 'spc_default', name: 'Binan', 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' };