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 payment says why, and offers no Always

Pixel (kwant bot)7c2e40c143d4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 17282f4f..3fabd55e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
money or accounts are better kept on "Ask" or "Ask only when risky". Nothing changes until you press
Turn off approvals; Cancel (or Escape) keeps the current setting. While approvals are off, a note next
to the setting keeps saying so.
+- **Approvals: payment cards say why.** A card for something that looks like a payment says so and
+ why ("This looks like a payment: …"), and offers only Allow Once and Deny: allowing a payment covers
+ that one payment, so there is no "Always" button on it. Other cards are unchanged.
- **Mission board: AutoFix, change approvals and restore.** A failed task shows why it failed in plain
words, what AutoFix plans, its tries and what retries cost, with Retry now and Don't retry. Proposed
changes to a check, the acceptance or a routine appear in Needs you with before and after, and only
diff --git a/frontend/src/components/ModernApprovalCard.tsx b/frontend/src/components/ModernApprovalCard.tsx
index bb406713..6cf5e4bb 100644
--- a/frontend/src/components/ModernApprovalCard.tsx
+++ b/frontend/src/components/ModernApprovalCard.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { ShieldAlert, Check, CheckCheck, X, Plug, FileText, Terminal, Clock } from 'lucide-react';
+import { ShieldAlert, Check, CheckCheck, X, Plug, FileText, Terminal, Clock, CreditCard } from 'lucide-react';
import { playSfx } from '../audio/chiptune';
import { formatArgs, humanizeToolName, parseMcpToolName } from '../mcp';
@@ -92,6 +92,16 @@ export const builtinView = (approval: PendingApproval) => {
return { ...base, kind: 'other' as const, command: null, description: null, path: null, change: null, args: formatArgs(args) };
};
+/**
+ * Why the server's payment floor (src/mcp/payment_floor.rs) asked, or null for a card that isn't
+ * a payment. A payment always asks, and allowing it covers that one call.
+ */
+export const paymentReason = (approval: PendingApproval) => {
+ const why = approval.details?.payment_reason;
+ if (typeof why !== 'string') return null;
+ return why.trim().replace(/[.\s]+$/, '') || 'it looks like paying';
+};
+
/** The line under a still-open card's heading. */
export const waitingNote = (bot: string | null) =>
`${bot ?? 'The bot'} stopped waiting for an answer and nothing ran. Allow starts it again to make this call; Deny closes the card.`;
@@ -115,6 +125,7 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({
const perSession = !!builtin || !!summary?.builtin;
const waiting = approval.waiting === true;
const botName = name ?? mcp?.kwant ?? null;
+ const payment = paymentReason(approval);
return (
<div
@@ -137,6 +148,18 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({
</div>
)}
+ {payment && (
+ <div role="note" className="flex items-start gap-2 mb-2 rounded-lg border border-rose-500/30 bg-rose-950/30 px-3 py-2 text-xs">
+ <CreditCard size={14} className="mt-0.5 shrink-0 text-rose-300" aria-hidden="true" />
+ <div className="min-w-0 space-y-0.5">
+ <p className="text-rose-100 break-words">
+ <span className="font-semibold">This looks like a payment:</span> {payment}.
+ </p>
+ <p className="text-[11px] text-zinc-400">Payments always ask you, even with approvals off. Allowing covers this one payment.</p>
+ </div>
+ </div>
+ )}
+
{shell ? (
<div className="bg-zinc-900/90 rounded-lg p-3 border border-zinc-800 text-xs space-y-2 mb-3">
<p className="text-zinc-300">A bot wants to run a command on your computer.</p>
@@ -263,8 +286,9 @@ export const ModernApprovalCard: React.FC<ModernApprovalCardProps> = ({
</button>
{/* Local shell approvals are never remembered, so only offer a one-off answer. A late
- answer only lets that one call run, so it gets no "always" either. */}
- {!shell && !waiting && (
+ answer only lets that one call run, and a payment always asks again, so neither gets
+ an "always" either. */}
+ {!shell && !waiting && !payment && (
<button
type="button"
disabled={disabled}
diff --git a/frontend/tests/approvalCard.test.mjs b/frontend/tests/approvalCard.test.mjs
index 695be3a0..f6896115 100644
--- a/frontend/tests/approvalCard.test.mjs
+++ b/frontend/tests/approvalCard.test.mjs
@@ -54,3 +54,67 @@ test('a normal ticket keeps the raw details and Always Allow', () => {
assert.match(html, /Always Allow/);
assert.doesNotMatch(html, /run a command on your computer/);
});
+
+// Shaped like BrokerApprover::classified and approve_local_shell_in with the payment floor (#110).
+const stripeTicket = (extra = {}) => ({
+ id: 'p1',
+ tool_name: 'mcp__composio__COMPOSIO_MULTI_EXECUTE_TOOL',
+ details: {
+ source: 'mcp',
+ server: 'composio',
+ tool: 'COMPOSIO_MULTI_EXECUTE_TOOL',
+ kwant_name: 'Ledger',
+ arguments: { tools: [{ tool_slug: 'STRIPE_CREATE_PAYMENT_INTENT', arguments: { amount: 1200 } }] },
+ payment_reason: 'composio STRIPE_CREATE_PAYMENT_INTENT is a write action of Stripe, a money app',
+ ...extra,
+ },
+});
+
+test('a payment card says why it is a payment and offers only Allow Once and Deny', () => {
+ const html = render(stripeTicket());
+ assert.match(html, /This looks like a payment:<\/span> composio STRIPE_CREATE_PAYMENT_INTENT is a write action of Stripe, a money app\./);
+ assert.match(html, /Payments always ask you, even with approvals off/);
+ assert.match(html, /Allow Once/);
+ assert.match(html, /Deny/);
+ assert.doesNotMatch(html, /Always Allow|Always this session/);
+ assert.match(html, /role="note"/);
+});
+
+test('a payment shown as a Claude tool card also drops Always this session', () => {
+ const html = render({
+ id: 'p2',
+ tool_name: 'Bash',
+ details: { source: 'claude_builtin', tool: 'Bash', arguments: { command: 'stripe charges create --amount 1' }, payment_reason: 'stripe CLI changes something.' },
+ });
+ assert.match(html, /This looks like a payment:<\/span> stripe CLI changes something\./, 'one full stop, not two');
+ assert.doesNotMatch(html, /Always this session|Always Allow/);
+});
+
+test('a payment by local shell keeps its command and shows the reason', () => {
+ const t = shellTicket('curl -X POST https://api.stripe.com/v1/charges');
+ t.details.payment_reason = 'POST to a payment host (api.stripe.com)';
+ const html = render(t);
+ assert.match(html, /This looks like a payment:<\/span> POST to a payment host \(api.stripe.com\)\./);
+ assert.match(html, /run a command on your computer/);
+ assert.doesNotMatch(html, /Always Allow/);
+});
+
+test('cards without payment_reason are unchanged: no payment line, Always buttons as before', () => {
+ for (const t of [
+ { id: 'n2', tool_name: 'write_file', details: { path: '/tmp/a.txt' } },
+ { id: 'n3', tool_name: 'Bash', details: { source: 'claude_builtin', tool: 'Bash', arguments: { command: 'ls' } } },
+ stripeTicket({ payment_reason: undefined }),
+ stripeTicket({ payment_reason: 42 }),
+ ]) {
+ const html = render(t);
+ assert.doesNotMatch(html, /looks like a payment|role="note"/, t.id);
+ assert.match(html, /Always Allow|Always this session/, t.id);
+ }
+});
+
+test('a still-open payment card keeps the reason and offers no always', () => {
+ const html = render({ ...stripeTicket(), waiting: true });
+ assert.match(html, /This looks like a payment/);
+ assert.match(html, /Allow and continue/);
+ assert.doesNotMatch(html, /Always/);
+});