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.

30a approval-one-pointer: one pointer and one landing place for a waiting approval (#869)

Oleksandr Ivanchenkodd43ffe1c755
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 5baf7aef..8346e1dc 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -161,7 +161,7 @@ import {
turnsAwaitingAnswer,
} from './questions';
import { AwayError, AwayItem, affectsAway, awayApi, resolveBody } from './away';
-import { asksHere, closedId, onlyLiveApproval, isHandOff, dismissKind, dropClosed, loadAskWindow, openTarget as askOpenTarget, resendTarget, retryRoute, switchFor, type AskAction, type Here } from './askHere';
+import { asksHere, closedId, onlyLiveApproval, stripHasLiveApproval, isHandOff, dismissKind, dropClosed, loadAskWindow, openTarget as askOpenTarget, resendTarget, retryRoute, switchFor, type AskAction, type Here } from './askHere';
import { NeedsYouStrip } from './components/NeedsYouStrip';
import { chainBudgetApi } from './chainBudget';
import { needsYouRows, attentionRows } from './chatsTab';
@@ -4633,6 +4633,7 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
needsYouStrip={needsYouStrip}
needsYouOpen={asks.length > 0}
stripOnlyApproval={onlyLiveApproval(asks)}
+ stripHasApproval={stripHasLiveApproval(asks)}
subHeader={subHeader}
threadLine={isPhone && threadBarProps ? <ThreadPicker {...threadBarProps} /> : undefined}
notice={
diff --git a/frontend/src/askHere.ts b/frontend/src/askHere.ts
index bc133698..36a14b59 100644
--- a/frontend/src/askHere.ts
+++ b/frontend/src/askHere.ts
@@ -351,3 +351,18 @@ export const onlyLiveApproval = (asks: Parameters<typeof askAction>[0][]): boole
export const stripStepsAside = (s: { strip: boolean; onlyApproval: boolean; cardInView: boolean; followingCard: boolean }): boolean =>
s.strip && s.onlyApproval && (s.cardInView || s.followingCard);
+
+/**
+ * 30a (Mira's 29w design check, small thing b): the strip offers "Go to the approval" for a live approval of this
+ * chat. `asks` are already this chat's (asksHere), so another chat's ask never counts.
+ */
+export const stripHasLiveApproval = (asks: Parameters<typeof askAction>[0][]): boolean =>
+ asks.some((a) => a.kind === 'approval' && askAction(a) === 'decide');
+
+/**
+ * 30a: whether ChatView shows its "↓ Approval waiting" pill. It shows while a waiting card's buttons are off screen,
+ * except when something else already points at that card: on a phone the working line's "Answer ↑" (0.8.1 F6), and
+ * now the Needs-you strip's "Go to the approval", just as "Answer ↑" steps aside for the strip. One pointer per card.
+ */
+export const approvalPillShows = (s: { offscreen: boolean; waiting: number; phoneAnswerUp: boolean; stripHasApproval: boolean }): boolean =>
+ s.offscreen && s.waiting > 0 && !s.phoneAnswerUp && !s.stripHasApproval;
diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsx
index 4b89389e..fda98568 100644
--- a/frontend/src/components/ChatView.tsx
+++ b/frontend/src/components/ChatView.tsx
@@ -109,7 +109,7 @@ import { ideaBlockedLine, ideaLength } from '../ideaShell';
import { JarIcon } from './JarIcon';
import { consultedNames, hideStreamingDecisions, messageDecisions, parseWorkAhead } from '../decideFirst';
import { approvalScrollAction, fullyVisible, isNearBottom, nextFollowing } from '../approvalVisibility';
-import { stripStepsAside } from '../askHere';
+import { approvalPillShows, stripStepsAside } from '../askHere';
import { DecidingLine, DecisionChips, WorkAheadBody } from './Proactive';
import { RouteChoiceMeta, parseRouteChoiceMeta, questionsOfReplies } from '../routeChoice';
import { SmartActionsSlot } from './results/SmartActions';
@@ -356,6 +356,8 @@ export interface ChatViewProps {
needsYouOpen?: boolean;
/** 29w: the strip's only ask is this chat's live approval, so it steps aside while that card's buttons are on screen. */
stripOnlyApproval?: boolean;
+ /** 30a: the strip offers "Go to the approval" for a live approval here, so the "Approval waiting" pill steps aside. */
+ stripHasApproval?: boolean;
onHighlightDone?: () => void;
/** Set while `messages` is an older window (a search hit beyond the latest page). */
viewingHistory?: boolean;
@@ -641,6 +643,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
needsYouStrip,
needsYouOpen,
stripOnlyApproval = false,
+ stripHasApproval = false,
onContinueFrom,
threadKind,
continuedFrom,
@@ -1017,9 +1020,14 @@ export const ChatView: React.FC<ChatViewProps> = ({
const cards = scrollRef.current?.querySelectorAll<HTMLElement>('[data-approval-card]');
const card = cards?.[cards.length - 1];
if (!card) return;
+ // 30a: started from the keyboard (the pill or "Answer ↑" had keyboard focus), focus lands on the card itself,
+ // never on Allow / Deny, so a second Enter can't approve. A tap or click never moves focus.
+ const from = document.activeElement;
+ const keyboard = from instanceof HTMLButtonElement && from.matches(':focus-visible');
const reduce = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
card.scrollIntoView({ block: 'end', behavior: reduce ? 'auto' : 'smooth' });
setApprovalOffscreen(false);
+ if (keyboard) card.focus({ preventScroll: true });
};
// 29w: the Needs-you strip steps aside while its one ask is the live approval whose buttons are on screen.
const stripAside = stripStepsAside({ strip: !!needsYouStrip, onlyApproval: stripOnlyApproval, cardInView: approvalCardInView, followingCard });
@@ -1122,6 +1130,10 @@ export const ChatView: React.FC<ChatViewProps> = ({
if (!card) return;
const reduce = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
card.scrollIntoView({ block: 'center', behavior: reduce ? 'auto' : 'smooth' });
+ // 30a: the strip's "Go to the approval" pressed from the keyboard lands focus on the card (as the question
+ // 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 });
if (highlightRing) ringElement(card);
setFlashKind(highlightRing ? 'ask' : 'search');
setFlashId(highlightMessageId);
@@ -2718,16 +2730,14 @@ export const ChatView: React.FC<ChatViewProps> = ({
{prepush}
{/* Pending Security Approval Ticket */}
- {pendingApprovals.map((approval) =>
- // 0.8.1 F6: a notification's tap lands on this card and flashes it
- flashId === approval.id ? (
- <div key={approval.id} className="rounded-xl kw-flash">
- <ModernApprovalCard approval={approval} onResolve={onResolveApproval} />
- </div>
- ) : (
- <ModernApprovalCard key={approval.id} approval={approval} onResolve={onResolveApproval} />
- ),
- )}
+ {pendingApprovals.map((approval) => (
+ // 0.8.1 F6: a notification's tap lands on this card and flashes it. 30a: the wrapper is always there
+ // (display: contents when not flashing), so the flash never remounts the card: focus that "Go to the
+ // approval" put on it stays, and so does a half-typed Deny reason.
+ <div key={approval.id} className={flashId === approval.id ? 'rounded-xl kw-flash' : 'contents'}>
+ <ModernApprovalCard approval={approval} onResolve={onResolveApproval} />
+ </div>
+ ))}
</div>
{/* Suggested prompts for who is in this chat: one swipeable row on phones */}
@@ -2810,7 +2820,8 @@ export const ChatView: React.FC<ChatViewProps> = ({
)}
{/* On a phone the strip's "Answer ↑" stands in for this pill while the bot waits on the card. */}
- {approvalOffscreen && pendingApprovals.length > 0 && !(phone && stripWaitsOn === 'approval') && (
+ {/* 30a: one pointer per card: it also steps aside while the Needs-you strip offers "Go to the approval". */}
+ {approvalPillShows({ offscreen: approvalOffscreen, waiting: pendingApprovals.length, phoneAnswerUp: phone && stripWaitsOn === 'approval', stripHasApproval }) && (
<div role="status" className="max-w-4xl mx-auto mb-2 flex justify-center">
<button
type="button"
diff --git a/frontend/src/components/ModernApprovalCard.tsx b/frontend/src/components/ModernApprovalCard.tsx
index 95bffc1c..a61de7de 100644
--- a/frontend/src/components/ModernApprovalCard.tsx
+++ b/frontend/src/components/ModernApprovalCard.tsx
@@ -478,9 +478,14 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({
return (
+ // 30a: the landing place for "Go to the approval" from the keyboard: focusable only from script (no tab stop),
+ // named by its own heading and ask, so a screen reader reads the ask and the next Tab reaches Deny / Allow.
<div
data-approval-card={approval.id}
- className={`my-3 border rounded-xl p-3 sm:p-4 text-zinc-100 max-w-2xl shadow-lg backdrop-blur-sm ${
+ role="group"
+ aria-labelledby={`apc-${approval.id}-h apc-${approval.id}-s`}
+ tabIndex={-1}
+ className={`kw-focus my-3 border rounded-xl p-3 sm: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'
}`}
>
@@ -491,7 +496,7 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({
>
{waiting ? <Clock size={16} /> : <ShieldAlert size={16} />}
</span>
- <h3 className="min-w-0 flex-1 text-[15px] leading-5 font-semibold text-zinc-50">{waiting ? 'Still open: you can still allow' : 'Approval needed'}</h3>
+ <h3 id={`apc-${approval.id}-h`} className="min-w-0 flex-1 text-[15px] leading-5 font-semibold text-zinc-50">{waiting ? 'Still open: you can still allow' : 'Approval needed'}</h3>
{time && (
<time dateTime={approval.asked_at} className="shrink-0 text-xs leading-4 text-[#a39dcc] tabular-nums">
{time}
@@ -500,7 +505,7 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({
</div>
{waiting && <p className="mt-1.5 text-xs leading-[18px] text-zinc-400">{waitingNote(botName)}</p>}
- <p className="mt-2.5 text-base leading-6 text-zinc-200 break-words" data-approval-summary="">
+ <p id={`apc-${approval.id}-s`} className="mt-2.5 text-base leading-6 text-zinc-200 break-words" data-approval-summary="">
{bot} wants to {what}
</p>
{startedBy && (
diff --git a/frontend/src/components/dev/ProdFloorCard.tsx b/frontend/src/components/dev/ProdFloorCard.tsx
index 89a763b1..6090b229 100644
--- a/frontend/src/components/dev/ProdFloorCard.tsx
+++ b/frontend/src/components/dev/ProdFloorCard.tsx
@@ -256,7 +256,9 @@ export const ProdFloorCard: React.FC<ProdFloorCardProps> = ({
data-floor-case={view.case}
role="group"
aria-labelledby={headingId}
- className="dv-floor my-3 max-w-2xl rounded-xl text-zinc-100 shadow-lg backdrop-blur-sm"
+ // 30a: "Go to the approval" from the keyboard lands here (no tab stop of its own).
+ tabIndex={-1}
+ className="dv-floor kw-focus my-3 max-w-2xl rounded-xl text-zinc-100 shadow-lg backdrop-blur-sm"
>
{/* The hazard tape is .dv-floor::before (4 px, only on the floor card). */}
<div className="p-3 sm:px-4 sm:pb-4 sm:pt-3.5">
diff --git a/frontend/tests/askHere.test.mjs b/frontend/tests/askHere.test.mjs
index 901b538d..7ddef15d 100644
--- a/frontend/tests/askHere.test.mjs
+++ b/frontend/tests/askHere.test.mjs
@@ -25,6 +25,7 @@ const m = await loadBundled(`
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;
const noop = () => {};
@@ -667,3 +668,73 @@ test('29w: while the chat follows the bottom with the card in it, the strip stay
assert.equal(m.stripStepsAside({ ...base, strip: false, cardInView: true, followingCard: true }), false);
assert.equal(m.stripStepsAside({ ...base, onlyApproval: false, cardInView: true, followingCard: true }), false);
});
+
+// 30a (brief: autonomy/approval-one-pointer/brief.md; Mira's 29w design check, small things a and b).
+// b: one pointer per card. The "↓ Approval waiting" pill steps aside while the Needs-you strip offers
+// "↑ Go to the approval" for this chat's live approval, as the working line's "Answer ↑" already does.
+test('30a: the "Approval waiting" pill steps aside while the strip offers Go to the approval', () => {
+ assert.equal(typeof m.approvalPillShows, 'function');
+ const base = { offscreen: true, waiting: 1, phoneAnswerUp: false, stripHasApproval: false };
+ // No strip about it: the pill shows while the card's buttons are off screen (old 22i / 0.8.1 F6 behaviour).
+ assert.equal(m.approvalPillShows(base), true);
+ assert.equal(m.approvalPillShows({ ...base, waiting: 2 }), true);
+ // b-1440: the strip says "Go to the approval": the pill steps aside (it pointed the other way at the same card).
+ assert.equal(m.approvalPillShows({ ...base, stripHasApproval: true }), false);
+ // Phone: "Answer ↑" stands in for it, as before.
+ assert.equal(m.approvalPillShows({ ...base, phoneAnswerUp: true }), false);
+ // Buttons in view, or nothing waiting: no pill.
+ assert.equal(m.approvalPillShows({ ...base, offscreen: false }), false);
+ assert.equal(m.approvalPillShows({ ...base, waiting: 0 }), false);
+ // Which strips count: a live approval of this chat, alone or with other asks. A question alone, a run-out
+ // approval (its Ask again is a different action) or no asks leave the pill where it was.
+ const q = { id: 'q1', kind: 'question', kwant_id: 'k1', title: 'Which folder?', timestamp: '2026-11-19T09:01:00Z' };
+ const ranOut = { id: 's1', kind: 'stopped', kwant_id: 'k1', title: 'Approval ran out', retry: { type: 'approval', approval_id: 'ap0' }, timestamp: '2026-11-19T09:00:00Z' };
+ assert.equal(m.stripHasLiveApproval([live]), true);
+ assert.equal(m.stripHasLiveApproval([q, live]), true);
+ assert.equal(m.stripHasLiveApproval([q]), false);
+ assert.equal(m.stripHasLiveApproval([ranOut]), false);
+ assert.equal(m.stripHasLiveApproval([{ ...live, action: 'ask_again' }]), false);
+ assert.equal(m.stripHasLiveApproval([]), false);
+});
+
+// a: the approval card is the landing place: script-focusable only, named by its own heading and ask (no new copy).
+test('30a: the approval card can take focus without a tab stop, and is named by its heading and ask', () => {
+ 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 html = m.renderToStaticMarkup(h(m.ModernApprovalCard, { approval, onResolve: noop }));
+ const d = new DOMParser().parseFromString(`<body>${html}</body>`, 'text/html');
+ const card = d.querySelector('[data-approval-card="ap1"]');
+ assert.equal(card.getAttribute('tabindex'), '-1');
+ assert.equal(card.getAttribute('role'), 'group');
+ const name = card.getAttribute('aria-labelledby').split(' ').map((id) => d.getElementById(id)?.textContent.trim());
+ assert.equal(name.length, 2);
+ assert.equal(name[0], 'Approval needed');
+ assert.equal(name[1], d.querySelector('[data-approval-summary]').textContent.trim());
+ assert.match(name[1], /wants to/);
+ // Allow / Deny stay ordinary tab stops after the card (no tabindex games on them).
+ for (const b of card.querySelectorAll('[data-approval-actions] button')) assert.equal(b.getAttribute('tabindex'), null);
+});
+
+test('30a: keyboard "Go to the approval" (strip, pill, Answer ↑) focuses the card, never Allow / Deny; a tap moves nothing', () => {
+ const app = readFileSync(new URL('../src/App.tsx', import.meta.url), 'utf8');
+ const chat = readFileSync(new URL('../src/components/ChatView.tsx', import.meta.url), 'utf8');
+ const floor = readFileSync(new URL('../src/components/dev/ProdFloorCard.tsx', import.meta.url), 'utf8');
+ assert.match(app, /stripHasApproval=\{stripHasLiveApproval\(asks\)\}/);
+ // The pill's show rule is the helper (one pointer per card).
+ assert.match(chat, /\{approvalPillShows\(\{ offscreen: approvalOffscreen, waiting: pendingApprovals\.length, phoneAnswerUp: phone && stripWaitsOn === 'approval', stripHasApproval \}\) && \(/);
+ // Pill and "Answer ↑" go through showApproval: focus the card only when a button had keyboard focus.
+ const show = chat.slice(chat.indexOf('const showApproval = () =>'), chat.indexOf('const stripAside ='));
+ assert.match(show, /const keyboard = from instanceof HTMLButtonElement && from\.matches\(':focus-visible'\);/);
+ assert.match(show, /if \(keyboard\) card\.focus\(\{ preventScroll: true \}\);/);
+ // The strip's Go to goes through the highlight effect: only its own decide button with keyboard focus moves it.
+ const hl = chat.slice(chat.indexOf('// 0.8.1 F6: an approval\'s card'), chat.indexOf('if (!messages.some((m) => m.id === highlightMessageId)) return;'));
+ assert.match(hl, /stripSlotRef\.current\?\.contains\(from\) && from\.matches\('\[data-strip-action="decide"\]:focus-visible'\)\) card\.focus\(\{ preventScroll: true \}\)/);
+ // Never Allow / Deny: nothing in these paths queries the card's buttons to focus them.
+ assert.doesNotMatch(show + hl, /data-approval-actions|button.*\.focus\(/);
+ // The 29w hand-off to the composer still only runs when focus was lost (body) or is still in the hidden strip.
+ assert.match(chat, /if \(!a \|\| a === document\.body \|\| stripSlotRef\.current\?\.contains\(a\)\) textareaRef\.current\?\.focus\(\{ preventScroll: true \}\);/);
+ // The flash wrapper is always there, so flashing the card on landing doesn't remount it (and drop its focus).
+ assert.match(chat, /<div key=\{approval\.id\} className=\{flashId === approval\.id \? 'rounded-xl kw-flash' : 'contents'\}>\n\s*<ModernApprovalCard approval=\{approval\} onResolve=\{onResolveApproval\} \/>\n\s*<\/div>/);
+ assert.doesNotMatch(chat, /<ModernApprovalCard key=\{approval\.id\}/);
+ // The dev production-floor card is a landing place too.
+ assert.match(floor, /data-approval-card=\{id\}[\s\S]{0,400}tabIndex=\{-1\}/);
+});