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.

Approval cards: a reloaded payment keeps its reason and offers no Always

pixel-botf2ab90b5c37b
diff --git a/frontend/src/approvals.ts b/frontend/src/approvals.ts
index 5ad76d07..1de535bc 100644
--- a/frontend/src/approvals.ts
+++ b/frontend/src/approvals.ts
@@ -29,6 +29,8 @@ export function approvalFromAway(item: AwayItem): ChatApproval {
const details: Record<string, unknown> = hasDetails
? { kwant_name: item.kwant_name, ...item.details }
: { source: 'summary', tool, summary: item.summary, kwant_id: item.kwant_id, kwant_name: item.kwant_name };
+ // A payment keeps its reason (and so loses its Always button) whichever form the server sent.
+ if (str(item.payment_reason) && details.payment_reason === undefined) details.payment_reason = item.payment_reason;
const link = item.link && (item.link.thread_id || item.link.channel_id || item.link.direct_kwant_id) ? item.link : null;
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;
diff --git a/frontend/src/away.ts b/frontend/src/away.ts
index 16438790..4791e3e1 100644
--- a/frontend/src/away.ts
+++ b/frontend/src/away.ts
@@ -26,6 +26,8 @@ export interface AwayItem {
/** Approvals only, from servers that send them: the tool and the card's details. */
tool_name?: string;
details?: Record<string, unknown>;
+ /** Approvals only: set when the payment floor asked, also on servers that send no details. */
+ payment_reason?: string;
}
export interface AwayCounts {
diff --git a/frontend/tests/approvalCard.test.mjs b/frontend/tests/approvalCard.test.mjs
index f6896115..1fc0cf2a 100644
--- a/frontend/tests/approvalCard.test.mjs
+++ b/frontend/tests/approvalCard.test.mjs
@@ -118,3 +118,18 @@ test('a still-open payment card keeps the reason and offers no always', () => {
assert.match(html, /Allow and continue/);
assert.doesNotMatch(html, /Always/);
});
+
+test('a payment card in its summary form (after a reload) shows the reason and no always', () => {
+ const html = render({
+ id: 'p3',
+ tool_name: 'Bash',
+ details: { source: 'summary', tool: 'Bash', summary: 'command: stripe charges create', kwant_name: 'Ledger', payment_reason: 'stripe CLI changes something' },
+ });
+ assert.match(html, /Ledger<\/span> wants to use <span[^>]*>Bash<\/span>/);
+ assert.match(html, /This looks like a payment:<\/span> stripe CLI changes something\./);
+ assert.match(html, /Allow Once/);
+ assert.doesNotMatch(html, /Always this session|Always Allow/);
+ // The same summary card without a reason still offers Always this session.
+ const plain = render({ id: 'n4', tool_name: 'Bash', details: { source: 'summary', tool: 'Bash', summary: 'command: ls' } });
+ assert.match(plain, /Always this session/);
+});
diff --git a/frontend/tests/approvals.test.mjs b/frontend/tests/approvals.test.mjs
index 28b31b88..b2364973 100644
--- a/frontend/tests/approvals.test.mjs
+++ b/frontend/tests/approvals.test.mjs
@@ -99,3 +99,25 @@ test('live and loaded lists merge: answered ones drop, live details beat a summa
// Two asks at once both show.
assert.equal(a.upsertApproval([live], fresh).length, 2);
});
+
+test('a reloaded payment keeps its reason in every form the server sends, so no Always button', () => {
+ const reason = 'POST to a payment host (api.stripe.com)';
+ const forms = [
+ bashItem({ details: { ...bashItem().details, payment_reason: reason } }),
+ bashItem({ tool_name: undefined, details: undefined, payment_reason: reason }),
+ ];
+ for (const item of forms) {
+ const card = a.approvalFromAway(item);
+ assert.equal(card.details.payment_reason, reason);
+ const html = ui.away({
+ data: awayResp([item]), loading: false, error: null, busy: null, notice: null,
+ onRefresh: () => {}, onOpen: () => {}, onAnswer: () => {}, onResolve: () => {},
+ });
+ assert.match(html, /This looks like a payment:<\/span> POST to a payment host \(api.stripe.com\)\./);
+ assert.doesNotMatch(html, /Always this session|Always Allow/);
+ }
+ // An old summary item without a reason is unchanged.
+ const plain = a.approvalFromAway(bashItem({ tool_name: undefined, details: undefined }));
+ assert.equal(plain.details.source, 'summary');
+ assert.equal('payment_reason' in plain.details, false);
+});