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.

0.9.0 S-A: show a low-tier must_not_change breach in the task view (#514)

Oleksandr Ivanchenko2e0e0d7351d4
diff --git a/frontend/src/components/MissionBoardView.tsx b/frontend/src/components/MissionBoardView.tsx
index 56e5e22e..55336559 100644
--- a/frontend/src/components/MissionBoardView.tsx
+++ b/frontend/src/components/MissionBoardView.tsx
@@ -122,6 +122,8 @@ import {
actionsFor,
ago,
buildReceipt,
+ scopeWarnings,
+ type ScopeWarning,
cardStatus,
checkKindLabel,
checksText,
@@ -1320,7 +1322,11 @@ export const EvidenceReceipt: React.FC<{
names: Record<string, string>;
busy?: boolean;
onApproveCheck?: (c: Check) => void;
-}> = ({ receipt, names, busy = false, onApproveCheck }) => (
+ /** Paths a small task changed though its contract said they must not; it was still approved. */
+ scopeWarnings?: ScopeWarning[];
+ /** The bot that owns the task, for the scope warning. */
+ owner?: string | null;
+}> = ({ receipt, names, busy = false, onApproveCheck, scopeWarnings = [], owner }) => (
<section aria-labelledby="receipt-h" className="space-y-3" data-receipt>
<h4 id="receipt-h" tabIndex={-1} className="flex items-center focus:outline-none gap-1.5 text-xs font-semibold text-zinc-200">
<ShieldCheck size={14} className="text-emerald-400" aria-hidden="true" /> Evidence receipt
@@ -1332,6 +1338,18 @@ export const EvidenceReceipt: React.FC<{
{receipt.verifiedBy.check.finished_at ? ` ${ago(receipt.verifiedBy.check.finished_at)}` : ''}.
</p>
)}
+ {scopeWarnings.length > 0 && (
+ <ul className="space-y-1.5" aria-label="Changed paths it must not change" data-scope-warnings>
+ {scopeWarnings.map((w) => (
+ <li key={w.id} className="flex items-start gap-1.5 px-3 py-2 rounded-lg border border-amber-500/30 bg-amber-500/10 text-xs text-amber-200 break-words" data-scope-warning>
+ <AlertTriangle size={13} className="mt-0.5 shrink-0" aria-hidden="true" />
+ <span className="min-w-0">
+ {owner || 'The bot'} changed <code className="break-all">{w.path}</code>, which this task said must not change. It was still approved because the task is small.
+ </span>
+ </li>
+ ))}
+ </ul>
+ )}
{receipt.waitingOnYou && (
<p className="px-3 py-2 rounded-lg border border-amber-500/30 bg-amber-500/10 text-xs text-amber-200" data-waiting-on-you>
Not verified yet. {receipt.waitingOnYou}. A check a bot adds runs and counts only after you allow it below.
@@ -2063,6 +2081,8 @@ export const TaskDetailBody: React.FC<{
canResolveRisks?: boolean;
onResolveRisk?: (r: Risk, resolution: RiskResolution) => void;
onOpenAuditCard?: (w: AuditWaiting) => void;
+ /** Low-tier scope findings from the newest verdict (scopeWarnings). */
+ scopeWarnings?: ScopeWarning[];
}> = ({
detail,
names,
@@ -2094,6 +2114,7 @@ export const TaskDetailBody: React.FC<{
canResolveRisks = true,
onResolveRisk,
onOpenAuditCard,
+ scopeWarnings = [],
}) => {
const t = detail.task;
const shownNotice = noticeFor(notice, t.state);
@@ -2483,7 +2504,7 @@ export const TaskDetailBody: React.FC<{
</section>
)}
- <EvidenceReceipt receipt={receipt} names={names} busy={busy} onApproveCheck={onApproveCheck} />
+ <EvidenceReceipt receipt={receipt} names={names} busy={busy} onApproveCheck={onApproveCheck} scopeWarnings={scopeWarnings} owner={owner} />
<RestoreSection task={t} api={restoreApi} titleOf={(id) => tasksById[id]?.title} now={now} onRestored={onRestored} onError={onRestoreError} />
@@ -3106,6 +3127,7 @@ export const MissionBoardPage: React.FC<{
const [scanning, setScanning] = useState(false);
// Swarm Auditor: the open task's audits, the card it waits on, and the board's badge counts.
const [risks, setRisks] = useState<TaskRisks | null>(null);
+ const [scopeWarns, setScopeWarns] = useState<ScopeWarning[]>([]);
const [waitingCard, setWaitingCard] = useState<AuditWaiting | null>(null);
const [riskCounts, setRiskCounts] = useState<Record<string, number>>({});
const [canResolveRisks, setCanResolveRisks] = useState(true);
@@ -3186,6 +3208,10 @@ export const MissionBoardPage: React.FC<{
missionsApi.workflowChanges('proposed', id).then((cs) => alive.current && openIdRef.current === id && setChanges(cs), () => {});
} else setChanges([]);
loadRisks(id);
+ missionsApi.verdicts(id).then(
+ (v) => alive.current && openIdRef.current === id && setScopeWarns(scopeWarnings(v)),
+ () => alive.current && openIdRef.current === id && setScopeWarns([]),
+ );
} catch (e) {
if (alive.current && openIdRef.current === id) setDetailError(failMsg(e));
}
@@ -3272,6 +3298,7 @@ export const MissionBoardPage: React.FC<{
setFailures([]);
setChanges([]);
setRisks(null);
+ setScopeWarns([]);
setWaitingCard(null);
setDetailError(null);
setDetailNotice(null);
@@ -3862,6 +3889,7 @@ export const MissionBoardPage: React.FC<{
onRestored={restored}
onRestoreError={restoreError}
risks={risks}
+ scopeWarnings={scopeWarns}
auditWaiting={waitingCard}
canResolveRisks={canResolveRisks}
onResolveRisk={resolveRisk}
diff --git a/frontend/src/missions.ts b/frontend/src/missions.ts
index dc948344..6dd8f260 100644
--- a/frontend/src/missions.ts
+++ b/frontend/src/missions.ts
@@ -1860,6 +1860,8 @@ export const missionsApi = {
cancelAutofix: (id: string, aid: string) => call<AutofixAttempt>(`/api/tasks/${enc(id)}/autofix/${enc(aid)}/cancel`, 'POST', {}),
workflowChanges: (status: WorkflowChangeStatus = 'proposed', taskId?: string) =>
call<WorkflowChange[]>(`/api/workflow-changes?status=${status}${taskId ? `&task_id=${enc(taskId)}` : ''}`),
+ /** The verifier's verdicts on this task, newest first (raw: read them with scopeWarnings). */
+ verdicts: (id: string) => call<{ verdicts?: unknown }>(`/api/tasks/${enc(id)}/verdicts`).then((r) => r.verdicts),
/** Swarm Auditor: the task's audits and their risks. */
risks: (id: string) => call<TaskRisks>(`/api/tasks/${enc(id)}/risks`),
/** The space's unresolved risks, for the board's badges. */
@@ -2333,3 +2335,32 @@ export function flushOnPageLeave(
doc.removeEventListener('visibilitychange', onHide);
};
}
+
+/** A path a small (low-tier) task changed although its contract said it must not, and the task was still approved. */
+export interface ScopeWarning {
+ id: string;
+ path: string;
+}
+
+const SCOPE_PREFIX = 'Changed a path it must not change: ';
+
+/**
+ * The scope findings of the newest verdict when it is a low-tier pass: the server records each
+ * changed must_not_change path as one medium `scope` finding ("Changed a path it must not change:
+ * <path>") and still approves the task. Anything else, or data of another shape, gives [].
+ */
+export function scopeWarnings(verdicts: unknown): ScopeWarning[] {
+ if (!Array.isArray(verdicts) || verdicts.length === 0) return [];
+ const v = verdicts[0] as Record<string, unknown> | null;
+ if (!v || typeof v !== 'object' || v.risk_tier !== 'low' || v.verdict !== 'pass' || v.overturned_at || !Array.isArray(v.findings)) return [];
+ const out: ScopeWarning[] = [];
+ for (const f of v.findings as Record<string, unknown>[]) {
+ if (!f || typeof f !== 'object') continue;
+ const kind = f.step ?? f.kind;
+ if (kind !== 'scope' || f.severity !== 'medium' || typeof f.text !== 'string' || !f.text.startsWith(SCOPE_PREFIX)) continue;
+ const path = f.text.slice(SCOPE_PREFIX.length).trim();
+ if (!path || out.some((w) => w.path === path)) continue;
+ out.push({ id: typeof f.id === 'string' && f.id ? f.id : path, path });
+ }
+ return out;
+}
diff --git a/frontend/tests/missionScopeWarning.test.mjs b/frontend/tests/missionScopeWarning.test.mjs
new file mode 100644
index 00000000..15885b6a
--- /dev/null
+++ b/frontend/tests/missionScopeWarning.test.mjs
@@ -0,0 +1,71 @@
+// 0.9.0 S-A: a small (low-tier) task that changed a must_not_change path is still approved, and the
+// verifier records it as a medium `scope` finding. The task view shows one amber line per such path,
+// next to the receipt's "Checked by" lines, and nothing otherwise.
+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(`export * from './src/missions';`);
+const ui = await loadBundled(`
+ import React from 'react';
+ import { renderToStaticMarkup } from 'react-dom/server.browser';
+ import { TaskDetailBody } from './src/components/MissionBoardView';
+ export const detail = (p) => renderToStaticMarkup(React.createElement(TaskDetailBody, p));
+`);
+
+const NOW = Date.parse('2026-11-11T12:00:00Z');
+const noop = () => {};
+const names = { k_lin: 'Lin' };
+const task = (over = {}) => ({
+ id: 't1', space_id: 's1', mission_id: 'm1', mission_title: 'Docs', title: 'Fix the README typo',
+ acceptance: 'README says kwant.', state: 'verified', priority: 1,
+ owner_kwant_id: 'k_lin', owner_name: 'Lin', suggested_kwant_id: null, budget_tokens: 50000, spent_tokens: 1200,
+ attempts: 1, max_attempts: 3, blocked_reason: null, source_kind: 'mission', source_id: 'm1',
+ channel_id: 'c1', direct_kwant_id: null, thread_id: null, created_by: 'k_lin',
+ created_at: '2026-11-11T09:00:00Z', updated_at: '2026-11-11T11:00:00Z', finished_at: '2026-11-11T11:00:00Z',
+ depends_on: [], waiting_on: [], claim: null, needs_you: [],
+ checks_summary: { status: 'passed', passed: 1, failed: 0, total: 1 },
+ ...over,
+});
+const finding = (path, over = {}) => ({ id: 'f1', step: 'scope', severity: 'medium', text: `Changed a path it must not change: ${path}`, repro: `diff of ${path}`, ...over });
+const verdict = (over = {}) => ({ id: 'v1', task_id: 't1', verdict: 'pass', risk_tier: 'low', findings: [], overturned_at: null, created_at: '2026-11-11T11:00:00Z', ...over });
+const render = (warnings) =>
+ ui.detail({ detail: { task: task(), checks: [], evidence: [], events: [] }, names, now: NOW, onAction: noop, onApproveCheck: noop, scopeWarnings: warnings });
+
+test('scopeWarnings: one per changed must_not_change path on a low-tier pass', () => {
+ const v = verdict({ findings: [finding('docs/api.md'), { id: 'f2', step: 'reproduce', severity: 'medium', text: 'flaky' }, finding('src/db/missions.rs', { id: 'f3' }), finding('docs/api.md', { id: 'f4' })] });
+ assert.deepEqual(m.scopeWarnings([v]), [{ id: 'f1', path: 'docs/api.md' }, { id: 'f3', path: 'src/db/missions.rs' }]);
+});
+
+test('scopeWarnings: only the newest verdict, and nothing for other tiers, verdicts or shapes', () => {
+ const hit = verdict({ findings: [finding('docs/api.md')] });
+ assert.deepEqual(m.scopeWarnings([verdict(), hit]), [], 'newest verdict comes first and has none');
+ assert.deepEqual(m.scopeWarnings([verdict({ risk_tier: 'medium', findings: [finding('a')] })]), []);
+ assert.deepEqual(m.scopeWarnings([verdict({ verdict: 'needs_you', findings: [finding('a')] })]), []);
+ assert.deepEqual(m.scopeWarnings([verdict({ overturned_at: '2026-11-11T11:30:00Z', findings: [finding('a')] })]), []);
+ assert.deepEqual(m.scopeWarnings([verdict({ findings: [finding('a', { severity: 'high' })] })]), []);
+ for (const bad of [undefined, null, {}, [], [null], [verdict({ findings: 'x' })], [verdict({ findings: [null, { step: 'scope', severity: 'medium', text: 3 }] })]]) {
+ assert.deepEqual(m.scopeWarnings(bad), []);
+ }
+});
+
+test('task view: one amber line per scope finding, naming the bot and the path', () => {
+ const html = render([{ id: 'f1', path: 'docs/api.md' }, { id: 'f3', path: 'src/db/missions.rs' }]);
+ const lines = html.match(/data-scope-warning(?!s)/g) ?? [];
+ assert.equal(lines.length, 2);
+ assert.match(html, /Lin changed <code[^>]*>docs\/api\.md<\/code>, which this task said must not change\. It was still approved because the task is small\./);
+ assert.match(html, /Lin changed <code[^>]*>src\/db\/missions\.rs<\/code>/);
+ assert.match(html, /aria-label="Changed paths it must not change"/);
+ assert.ok(html.indexOf('data-scope-warnings') > html.indexOf('data-receipt'), 'sits in the receipt');
+});
+
+test('task view: nothing when there is no scope finding; paths are text, never HTML', () => {
+ assert.doesNotMatch(render([]), /data-scope-warning/);
+ assert.doesNotMatch(render(undefined), /data-scope-warning/);
+ const html = render([{ id: 'f1', path: '<img src=x>' }]);
+ assert.doesNotMatch(html, /<img/);
+ assert.match(html, /&lt;img src=x&gt;/);
+ assert.doesNotMatch(html, /\p{Extended_Pictographic}/u);
+});