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.

29r: Deny and Always allow keep each label on one line at 320 (#851)

Oleksandr Ivanchenko2bbf1bba360a
diff --git a/frontend/src/components/ModernApprovalCard.tsx b/frontend/src/components/ModernApprovalCard.tsx
index 80aad33e..95bffc1c 100644
--- a/frontend/src/components/ModernApprovalCard.tsx
+++ b/frontend/src/components/ModernApprovalCard.tsx
@@ -270,6 +270,9 @@ const ApprovalDetails: React.FC<{ phone?: boolean; children: React.ReactNode }>
const SECONDARY =
'inline-flex items-center justify-center gap-1.5 min-h-[44px] sm:min-h-[36px] px-3 rounded-lg border border-[#3f3868] bg-[#231d4b] text-sm font-medium text-[#ecebfa] hover:bg-[#2c2552] transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#b8adff] disabled:opacity-50 disabled:cursor-not-allowed';
+/** 29r: Deny and Always in their row: equal halves on a phone (basis 0, never narrower than the label); from sm their own width, filling the line only if the row wraps (the narrow Inbox list). */
+const ROW_FIT = 'flex-1 basis-0 sm:flex-auto';
+
/**
* 29p "Say why": a quiet button in the action row that opens a one-line field under it, with "Deny and tell
* <bot>". Its own component so the card itself keeps no state. Fragment children of the action row: the form
@@ -590,10 +593,13 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({
<Check size={16} aria-hidden="true" />
<span>{waiting ? 'Allow and continue' : 'Allow once'}</span>
</button>
- <div className={`grid gap-2 sm:flex ${offerAlways ? 'grid-cols-2' : 'grid-cols-1'}`}>
- <button type="button" disabled={disabled} onClick={() => handleDecision('deny')} className={SECONDARY}>
+ {/* 29r: labels never break. On a phone the two share the row in equal halves while both labels fit and
+ the second drops to its own full-width line when they don't (320 px, Away and the Inbox, "Always this
+ session"); no measuring, the wrap does it. From sm up both keep their own width, as before, and a wrapped one fills its line. */}
+ <div data-approval-deny-row="" className="flex flex-wrap gap-2">
+ <button type="button" disabled={disabled} onClick={() => handleDecision('deny')} className={`${SECONDARY} ${ROW_FIT}`}>
<X size={14} aria-hidden="true" />
- <span>Deny</span>
+ <span className="whitespace-nowrap">Deny</span>
</button>
{offerAlways && (
<button
@@ -601,10 +607,10 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({
disabled={disabled}
onClick={() => handleDecision('always_allow')}
title={perSession ? 'Allow this tool for this bot in this conversation' : mcp ? 'Allow this tool for this bot in this conversation, also after kwant restarts' : undefined}
- className={SECONDARY}
+ className={`${SECONDARY} ${ROW_FIT}`}
>
<CheckCheck size={14} aria-hidden="true" />
- <span>{perSession ? 'Always this session' : 'Always allow'}</span>
+ <span className="whitespace-nowrap">{perSession ? 'Always this session' : 'Always allow'}</span>
</button>
)}
</div>
diff --git a/frontend/tests/alwaysAllowFits.test.mjs b/frontend/tests/alwaysAllowFits.test.mjs
new file mode 100644
index 00000000..c99e7169
--- /dev/null
+++ b/frontend/tests/alwaysAllowFits.test.mjs
@@ -0,0 +1,50 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { JSDOM } from 'jsdom';
+import { loadBundled } from './bundle.mjs';
+
+// 29r: on a 320 px phone "Always allow" (and the longer "Always this session") broke onto two or three lines,
+// so the Deny / Always row read as more than two buttons. The labels now never wrap; the row itself wraps
+// instead (Deny and Always share it in equal halves while both labels fit, and the second drops to its own
+// full-width line when they don't). Measured widths: autonomy/always-allow-fits-320/impl.md.
+
+globalThis.localStorage ??= { getItem: () => null, setItem: () => {} };
+
+const m = await loadBundled(`
+ export { ModernApprovalCard } from './src/components/ModernApprovalCard';
+ export { renderToStaticMarkup } from 'react-dom/server.browser';
+ export { createElement } from 'react';
+`);
+
+const mcp = {
+ id: 'ap1',
+ tool_name: 'mcp__github__create_pull_request',
+ details: { source: 'mcp', server: 'github', tool: 'create_pull_request', kwant_name: 'TechLead', arguments: { repo: 'acme/site' } },
+};
+const builtin = {
+ id: 'ap2',
+ tool_name: 'Write',
+ details: { source: 'claude_builtin', tool: 'Write', kwant_name: 'TechLead', arguments: { file_path: '/home/me/notes.md', content: 'hi' } },
+};
+
+const row = (approval) => {
+ const html = m.renderToStaticMarkup(m.createElement(m.ModernApprovalCard, { approval, onResolve: () => {} }));
+ const doc = new JSDOM(html).window.document;
+ return doc.querySelector('[data-approval-deny-row]');
+};
+const cls = (el) => (el.getAttribute('class') ?? '').split(/\s+/);
+
+for (const [what, approval, label] of [['MCP', mcp, 'Always allow'], ['built-in', builtin, 'Always this session']]) {
+ test(`29r (${what}): "${label}" and Deny never break their label; the row wraps instead`, () => {
+ const r = row(approval);
+ assert.ok(r, 'the Deny / Always row is marked');
+ assert.ok(cls(r).includes('flex') && cls(r).includes('flex-wrap'), `row wraps: ${r.getAttribute('class')}`);
+ assert.ok(!cls(r).some((c) => c.startsWith('grid')), 'no fixed two-column grid that squeezes a label');
+ const buttons = [...r.querySelectorAll('button')];
+ assert.deepEqual(buttons.map((b) => b.textContent), ['Deny', label], 'same buttons, same order, same words');
+ for (const b of buttons) {
+ assert.ok(cls(b.querySelector('span')).includes('whitespace-nowrap'), `${b.textContent}: label stays on one line`);
+ for (const c of ['flex-1', 'basis-0', 'sm:flex-auto', 'min-h-[44px]']) assert.ok(cls(b).includes(c), `${b.textContent}: has ${c}`);
+ }
+ });
+}
diff --git a/frontend/tests/approvalCard.test.mjs b/frontend/tests/approvalCard.test.mjs
index 06044e8e..fe295ca0 100644
--- a/frontend/tests/approvalCard.test.mjs
+++ b/frontend/tests/approvalCard.test.mjs
@@ -230,6 +230,7 @@ test('a card from a turn kwant started offers no "always"; an ordinary card stil
assert.doesNotMatch(started, /Always this session|Always allow/);
assert.match(started, /Allow once/);
assert.match(started, />Deny</);
- assert.match(started, /grid-cols-1/);
+ // 29r: Deny is the only button in its row (it fills the row on its own).
+ assert.match(started, /data-approval-deny-row[^>]*>\s*<button[^>]*>(?:(?!<button)[\s\S])*?>Deny<\/span><\/button><\/div>/);
assert.doesNotMatch(render(startedTicket({ started_by: 'Watch' })), /Always this session|Always allow/);
});
diff --git a/frontend/tests/mobileCards.test.mjs b/frontend/tests/mobileCards.test.mjs
index ead6337a..9be3898f 100644
--- a/frontend/tests/mobileCards.test.mjs
+++ b/frontend/tests/mobileCards.test.mjs
@@ -100,7 +100,7 @@ test('approval card on a phone: header, one sentence, two key facts, details clo
assert.match(b[1].attrs, /bg-teal-300 hover:bg-teal-200 .*text-zinc-950/);
for (const x of b.slice(2)) assert.match(x.attrs, /min-h-\[44px\]/, x.label);
// Allow once is the only child of its row; Deny and Always allow share the next one.
- assert.match(html, /data-approval-actions[^>]*>\s*<button[^>]*data-approval-allow[\s\S]*?<\/button>\s*<div class="grid gap-2 sm:flex grid-cols-2">/);
+ assert.match(html, /data-approval-actions[^>]*>\s*<button[^>]*data-approval-allow[\s\S]*?<\/button>\s*<div data-approval-deny-row="" class="flex flex-wrap gap-2">\s*<button[^>]*>[\s\S]*?>Deny<\/span><\/button>\s*<button[^>]*>[\s\S]*?>Always allow<\/span><\/button><\/div>/);
});
test('approval card on desktop: details open, the JSON wraps between words, never break-all', () => {
@@ -120,7 +120,7 @@ test('a payment card offers no Always allow on a phone either: its second row is
const payment = pr({ details: { ...pr().details, payment_reason: 'stripe create payment is a money action' } });
const html = m.card({ approval: payment, onResolve: noop, phone: true });
assert.deepEqual(buttons(html).map((x) => x.label), ['Show details', 'Allow once', 'Deny', 'Say why']);
- assert.match(html, /<div class="grid gap-2 sm:flex grid-cols-1">/);
+ assert.match(html, /<div data-approval-deny-row="" class="flex flex-wrap gap-2">\s*<button[^>]*>(?:(?!<button)[\s\S])*?>Deny<\/span><\/button><\/div>/);
assert.doesNotMatch(html, /Always/);
});