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.

29x deny-reason-on-command-row: the Deny reason shows on the folded command row (#857)

Oleksandr Ivanchenko882dfcf1b04f
diff --git a/frontend/src/activity.ts b/frontend/src/activity.ts
index 00bcb43a..7ec4e8ff 100644
--- a/frontend/src/activity.ts
+++ b/frontend/src/activity.ts
@@ -140,6 +140,11 @@ export interface FoldedSteps {
answers: Map<string, CardAnswer>;
/** Folded approval step id → the command step id that now carries it (so a link to the card lands on its row). */
foldedInto: Map<string, string>;
+ /**
+ * 29x: command step id → what the person said with their no: the folded card's detail when the card is `declined`
+ * and has one (the server sets it only for a heard reason, `You said why: “…”`). Its row shows it as a second line.
+ */
+ reasons: Map<string, string>;
}
/**
@@ -152,6 +157,7 @@ export interface FoldedSteps {
export function foldAnswers(steps: readonly ActivityStep[]): FoldedSteps {
const answers = new Map<string, CardAnswer>();
const foldedInto = new Map<string, string>();
+ const reasons = new Map<string, string>();
const used = new Set<number>();
steps.forEach((card, ci) => {
if (card.kind !== 'approval' || !card.tool || !(card.status in answeredBy)) return;
@@ -169,9 +175,10 @@ export function foldAnswers(steps: readonly ActivityStep[]): FoldedSteps {
used.add(best);
answers.set(steps[best].id, card.status as CardAnswer);
foldedInto.set(card.id, steps[best].id);
+ if (card.status === 'declined' && card.detail) reasons.set(steps[best].id, card.detail);
});
- if (!foldedInto.size) return { rows: steps as ActivityStep[], answers, foldedInto };
- return { rows: steps.filter((s) => !foldedInto.has(s.id)), answers, foldedInto };
+ if (!foldedInto.size) return { rows: steps as ActivityStep[], answers, foldedInto, reasons };
+ return { rows: steps.filter((s) => !foldedInto.has(s.id)), answers, foldedInto, reasons };
}
/**
diff --git a/frontend/src/components/ActivityList.tsx b/frontend/src/components/ActivityList.tsx
index aa44c4ea..f075224c 100644
--- a/frontend/src/components/ActivityList.tsx
+++ b/frontend/src/components/ActivityList.tsx
@@ -136,13 +136,14 @@ function stepMark(step: ActivityStep, answer: CardAnswer | undefined): { chip: {
return { chip: cls ? { text: statusLabel(step), cls, kind: shown } : null, also };
}
-const StepRow: React.FC<{ step: ActivityStep; live?: LiveActivity; now: number; listId: string; opened?: boolean; answer?: CardAnswer }> = ({
+const StepRow: React.FC<{ step: ActivityStep; live?: LiveActivity; now: number; listId: string; opened?: boolean; answer?: CardAnswer; reason?: string }> = ({
step,
live,
now,
listId,
opened = false,
answer,
+ reason,
}) => {
const time = stepTime(step, now);
const running = step.kind === 'thinking' && step.status === 'running';
@@ -162,6 +163,9 @@ const StepRow: React.FC<{ step: ActivityStep; live?: LiveActivity; now: number;
);
const waiting = step.status === 'waiting';
+ // 29x: the reason the person gave with their no, from the card folded into this row, is a second line under
+ // "You said no; nothing ran" in the same box. The saved detail stays as it is (readDenials matches it exactly).
+ const detail = reason ? (step.detail ? `${step.detail}\n${reason}` : reason) : step.detail;
// 26d: a step that failed or wasn't approved in time says so in words, not only by its icon, even when a later
// step worked. The icon's label already names it for screen readers, so the mark is hidden from them.
// The approval row keeps its icon only: the mark belongs on the command the person said no to.
@@ -216,7 +220,7 @@ const StepRow: React.FC<{ step: ActivityStep; live?: LiveActivity; now: number;
data-step-status={step.status}
className={`px-3 py-1.5 text-xs focus:outline-none focus-visible:bg-zinc-800/60 focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sky-400 ${waiting ? 'bg-amber-500/[0.06]' : ''}`}
>
- {step.detail ? (
+ {detail ? (
// 29e: on a touch phone the 44 px summary takes in the li's py-1.5 (-my-1.5 py-1.5), so a row with › is 44 px
// like the rows without, not 56, and its tap area stays 44 px. 29i: there its ring sits inside (-outline-offset-2,
// like the li's), so the list's overflow-hidden doesn't clip it and it doesn't cross an open row's output.
@@ -233,7 +237,7 @@ const StepRow: React.FC<{ step: ActivityStep; live?: LiveActivity; now: number;
step.status === 'declined' ? 'font-sans text-xs' : 'font-mono text-[11px]'
} ${step.status === 'failed' ? 'text-rose-200 bg-rose-950/30 border-rose-500/20' : 'text-zinc-300 bg-zinc-950/80 border-zinc-800'}`}
>
- <StepDetail text={step.detail} path={isFileStep(step)} />
+ <StepDetail text={detail} path={isFileStep(step) && !reason} />
</pre>
</details>
) : (
@@ -256,12 +260,12 @@ const StepDetail: React.FC<{ text: string; path: boolean }> = ({ text, path }) =
const Steps: React.FC<{ steps: ActivityStep[]; live?: LiveActivity; dropped?: number; id: string; openStep?: string | null }> = ({ steps, live, dropped = 0, id, openStep = null }) => {
const now = useNow(steps.some(isOpenStep));
// 28s: one row per answer. A settled card folds into its command row; draw time only.
- const { rows, answers, foldedInto } = useMemo(() => foldAnswers(steps), [steps]);
+ const { rows, answers, foldedInto, reasons } = useMemo(() => foldAnswers(steps), [steps]);
const opened = openStep ? foldedInto.get(openStep) ?? openStep : null;
return (
<ol id={id} aria-label="Steps" className="divide-y divide-zinc-700/40">
{rows.map((s) => (
- <StepRow key={s.id} step={s} live={live} now={now} listId={id} opened={s.id === opened} answer={answers.get(s.id)} />
+ <StepRow key={s.id} step={s} live={live} now={now} listId={id} opened={s.id === opened} answer={answers.get(s.id)} reason={reasons.get(s.id)} />
))}
{dropped > 0 && (
<li className="px-3 py-1.5 text-xs text-zinc-400">
diff --git a/frontend/tests/denyReasonOnCommandRow.test.mjs b/frontend/tests/denyReasonOnCommandRow.test.mjs
new file mode 100644
index 00000000..33893a49
--- /dev/null
+++ b/frontend/tests/denyReasonOnCommandRow.test.mjs
@@ -0,0 +1,103 @@
+// 29x (autonomy/deny-reason-on-command-row/brief.md): when a declined card folds into its command row (28s, case A:
+// the claude CLI), the reason the person typed with Deny (the card's detail, `You said why: “…”`, set by 29s) shows as
+// a second line under "You said no; nothing ran", in the same box. Nothing is carried for an OK or unanswered card, or
+// a declined card with no detail. Saved steps, the chip, the summary line and the counts stay as they were.
+// Tests marked "fails on b9cacde3" fail on main there.
+process.env.TZ = 'UTC';
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { loadBundled } from './bundle.mjs';
+
+globalThis.localStorage ??= { getItem: () => null, setItem: () => {}, removeItem: () => {} };
+
+const m = await loadBundled(`
+ import React from 'react';
+ import { renderToStaticMarkup } from 'react-dom/server.browser';
+ import { SavedActivityList } from './src/components/ActivityList';
+ export { parseActivityMeta, activitySummary, foldAnswers, DENIED_STEP_DETAIL } from './src/activity';
+ export const saved = (props) => renderToStaticMarkup(React.createElement(SavedActivityList, props));
+`);
+
+const at = (min) => new Date(Date.parse('2026-11-19T06:00:00Z') + min * 60000).toISOString();
+const AP = 'Waiting for your approval: Running a command';
+const ap = (id, status, t, detail) => ({ id, kind: 'approval', status, title: AP, tool: 'Bash', started_at: at(t), ended_at: at(t + 0.2), duration_ms: 21000, ...(detail ? { detail } : {}) });
+const tool = (id, status, title, t, detail) => ({ id, kind: 'tool', status, title, tool: 'Bash', started_at: at(t), ended_at: at(t + 0.5), duration_ms: 30000, ...(detail ? { detail } : {}) });
+const parse = (raw) => m.parseActivityMeta({ activity: { steps: raw, dropped: 0 } });
+const SHORT = 'You said why: “push without --force, it’s a shared branch”';
+const LONG = 'You said why: “' + 'Please keep the shared branch as it is; '.repeat(13).slice(0, 483) + '…”';
+const PUSH = 'Running `git push --force origin main`';
+const ADJ = 'Running `git push origin feature`';
+// Case A as the claude CLI leaves it (the failed denied step; readDenials reads it as the person's no) and as 28b saves it.
+const caseA = (reason, shape = 'cli') => [
+ shape === 'cli' ? tool('t1', 'failed', PUSH, 0, 'The user denied this tool call.') : tool('t1', 'declined', PUSH, 0, 'You said no; nothing ran'),
+ ap('k1', 'declined', 0.01, reason),
+ ap('k2', 'ok', 1),
+ tool('t2', 'ok', ADJ, 1.2),
+];
+const html = (raw) => m.saved({ activity: parse(raw), idBase: 'r1', defaultOpen: true });
+const box = (h, id) => {
+ const li = h.match(new RegExp(`<li id="r1-steps-${id}"[\\s\\S]*?</li>`));
+ assert.ok(li, `row ${id} drawn`);
+ const pre = li[0].match(/<pre class="([^"]*)">([\s\S]*?)<\/pre>/);
+ return { li: li[0], cls: pre?.[1], text: pre?.[2] };
+};
+const unescape = (s) => s.replace(/&quot;/g, '"').replace(/&#x27;/g, "'").replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
+
+for (const shape of ['cli', 'saved-28b'])
+ test(`case A (${shape}): the reason is the second line under "You said no; nothing ran", in the same box (fails on b9cacde3)`, () => {
+ const r = box(html(caseA(SHORT, shape)), 't1');
+ assert.equal(unescape(r.text), `You said no; nothing ran\n${SHORT}`);
+ assert.equal((r.li.match(/<pre/g) || []).length, 1, 'one box, not a second one');
+ for (const c of ['font-sans', 'text-xs', 'whitespace-pre-wrap', '[overflow-wrap:anywhere]', 'max-h-40', 'overflow-y-auto', 'text-zinc-300', 'bg-zinc-950/80', 'border-zinc-800'])
+ assert.ok(r.cls.split(' ').includes(c), `box keeps ${c}`);
+ assert.ok(!r.cls.includes('font-mono'), 'the no is a sentence, not mono');
+ });
+
+test('the collapsed row stays the same: chip "You said no", time, chevron; the reason is not in the summary', () => {
+ const withR = box(html(caseA(SHORT)), 't1');
+ const without = box(html(caseA(undefined)), 't1');
+ const summary = (li) => li.match(/<summary[\s\S]*?<\/summary>/)[0];
+ assert.equal(summary(withR.li), summary(without.li), 'summary markup identical with and without a reason');
+ assert.match(summary(withR.li), /data-step-mark="declined"[^>]*>You said no</);
+ assert.ok(!summary(withR.li).includes('You said why'));
+});
+
+test('a 500-char reason stays whole in the box, closing quote kept (fails on b9cacde3)', () => {
+ assert.equal(LONG.length, 500);
+ assert.ok(LONG.endsWith('…”'));
+ const r = box(html(caseA(LONG)), 't1');
+ assert.equal(unescape(r.text), `You said no; nothing ran\n${LONG}`);
+});
+
+test('a declined card with no detail adds nothing: the row reads exactly as today', () => {
+ const r = box(html(caseA(undefined)), 't1');
+ assert.equal(unescape(r.text), 'You said no; nothing ran');
+ assert.equal(m.foldAnswers(parse(caseA(undefined)).steps).reasons?.size ?? 0, 0);
+});
+
+test('OK and unanswered cards carry nothing onto their command rows', () => {
+ const LATE = 'Waited 5 minutes for your answer; nothing ran';
+ const raw = [ap('k1', 'ok', 0, 'You said why: “should never show”'), tool('t1', 'ok', ADJ, 0.2), tool('t3', 'unanswered', PUSH, 2, LATE), ap('k3', 'unanswered', 2.01, LATE)];
+ const f = m.foldAnswers(parse(raw).steps);
+ assert.equal(f.answers.size, 2, 'both cards folded');
+ assert.equal(f.reasons?.size ?? 0, 0);
+ const h = html(raw);
+ assert.ok(!h.includes('should never show'));
+ assert.equal(unescape(box(h, 't3').text), LATE);
+});
+
+test('foldAnswers maps the command step id to the declined card’s detail (fails on b9cacde3)', () => {
+ const f = m.foldAnswers(parse(caseA(SHORT)).steps);
+ assert.deepEqual([...f.reasons], [['t1', SHORT]]);
+});
+
+test('rows, the step count and "you said no to 1" are unchanged by a reason; saved steps untouched', () => {
+ const a = parse(caseA(SHORT));
+ const b = parse(caseA(undefined));
+ assert.equal(m.foldAnswers(a.steps).rows.length, m.foldAnswers(b.steps).rows.length);
+ assert.equal(m.foldAnswers(a.steps).rows.length, 2);
+ assert.equal(m.activitySummary(a), m.activitySummary(b));
+ assert.match(m.activitySummary(a), /2 steps · you said no to 1/);
+ assert.equal(a.steps.find((s) => s.id === 't1').detail, 'You said no; nothing ran', 'saved command detail as readDenials makes it');
+ assert.equal(a.steps.find((s) => s.id === 'k1').detail, SHORT, 'card detail kept');
+});