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.

Audit model setting and readable task class labels (#137)

pixel-bot753d2a7bc21f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0374aa9a..5b182067 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -39,12 +39,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
Listed tools are shown, never granted. Versions of a skill can be rolled back.
`GET /api/skills/foundry`, `POST /api/skills/foundry/:cluster/draft`, `POST /api/skills/:id/replay`,
`POST /api/skills/:id/rollback`, `GET /api/skills/:id/foundry`. At most 2 drafts a day by default.
+- **Audit model in Settings.** With the auditor on, an **Audit model** picker sets which model audits
+ use: Fast (the default and cheapest), Balanced, Deep, or the same model as the bot. A value the
+ server rejects is flagged next to the picker in plain words.
### Changed
- **Audits run on the fast model by default.** The Swarm Auditor's challenge and rebuttal turns now use
the engine's cheap, fast model (for Claude, Haiku at medium effort) instead of the bot's default. The
new `auditor_model` setting picks `fast` (default), `balanced`, `deep`, or `bot` for the bot's usual
model.
+- **Kinds of work read as words.** The Performance section and Flight School show a task class such as
+ `code-review` as "Code review" instead of its raw name.
### Fixed
- **One approval card per audit challenge.** When the auditor's call was allowed but then refused for
diff --git a/frontend/src/auditor.ts b/frontend/src/auditor.ts
index 74c9f71c..1db55a17 100644
--- a/frontend/src/auditor.ts
+++ b/frontend/src/auditor.ts
@@ -157,22 +157,47 @@ export function auditCardPlace(w: AuditWaiting): { channelId: string | null; kwa
return { channelId: null, kwantId: l.direct_kwant_id ?? w.kwant_id, threadId: l.thread_id };
}
+export type AuditorModel = 'fast' | 'balanced' | 'deep' | 'bot';
+
export interface AuditorSettings {
auditor: 'on' | 'off';
auditor_daily_cap: number;
+ /** Absent on a server from before the setting: then it is neither shown nor saved. */
+ auditor_model?: AuditorModel;
}
export const DAILY_CAP_MIN = 1;
export const DAILY_CAP_MAX = 50;
export const DAILY_CAPS = [1, 2, 3, 5, 10, 20, 50];
-/** `auditor` and `auditor_daily_cap` from GET /api/settings; null on a server without the Auditor. */
+/** The model audit turns run on (`auditor_model`, §18). `fast` is the server default. */
+export const AUDITOR_MODELS: Array<{ value: AuditorModel; label: string }> = [
+ { value: 'fast', label: 'Fast' },
+ { value: 'balanced', label: 'Balanced' },
+ { value: 'deep', label: 'Deep' },
+ { value: 'bot', label: 'Same as the bot' },
+];
+export const MODEL_HINT = 'Fast is cheapest; audits never mark work passed or failed.';
+export const isAuditorModel = (v: unknown): v is AuditorModel => AUDITOR_MODELS.some((o) => o.value === v);
+
+/** A save error that is about the audit model, so it can show next to that control. */
+export const isAuditorModelError = (err: string | null | undefined): boolean => !!err && err.includes('auditor_model');
+/** What the picker says after that 400, instead of the server's field name. */
+export const MODEL_ERROR_TEXT = 'The server didn’t accept that audit model. Pick Fast, Balanced, Deep or Same as the bot.';
+
+/** `auditor`, `auditor_daily_cap` and `auditor_model` from GET /api/settings; null on a server without the Auditor. */
export function parseAuditorSettings(data: unknown): AuditorSettings | null {
if (!data || typeof data !== 'object') return null;
const d = data as Record<string, unknown>;
if (d.auditor !== 'on' && d.auditor !== 'off') return null;
const cap = typeof d.auditor_daily_cap === 'number' ? Math.max(DAILY_CAP_MIN, Math.min(DAILY_CAP_MAX, Math.round(d.auditor_daily_cap))) : 5;
- return { auditor: d.auditor, auditor_daily_cap: cap };
+ const out: AuditorSettings = { auditor: d.auditor, auditor_daily_cap: cap };
+ // An unknown value is kept as is: the picker shows it, and saving it back gets the server's 400.
+ if (typeof d.auditor_model === 'string' && d.auditor_model) out.auditor_model = d.auditor_model as AuditorModel;
+ return out;
}
+/** Label for a saved audit model, including one this app doesn't know. */
+export const auditorModelLabel = (m: string): string => AUDITOR_MODELS.find((o) => o.value === m)?.label ?? m;
+
/** What a resolve press says afterwards. */
export const riskResolvedText = (r: RiskResolution) => (r === 'resolved' ? 'Marked resolved. The task’s state doesn’t change.' : 'Dismissed. The task’s state doesn’t change.');
diff --git a/frontend/src/components/AuditorModelSetting.tsx b/frontend/src/components/AuditorModelSetting.tsx
new file mode 100644
index 00000000..36efdd89
--- /dev/null
+++ b/frontend/src/components/AuditorModelSetting.tsx
@@ -0,0 +1,37 @@
+import { AUDITOR_MODELS, AuditorModel, MODEL_HINT, auditorModelLabel, isAuditorModel } from '../auditor';
+
+/** Settings → the model audit turns run on (`auditor_model`, §18). A 400 about it shows right here. */
+export function AuditorModelSetting({ value, error, onChange }: { value: string; error: string | null; onChange: (m: AuditorModel) => void }) {
+ return (
+ <div className="mt-2" data-testid="auditor-model">
+ <div className="flex flex-wrap items-center gap-2">
+ <label htmlFor="auditor-model" className="text-[11px] text-zinc-300">
+ Audit model
+ </label>
+ <select
+ id="auditor-model"
+ value={value}
+ aria-describedby={error ? 'auditor-model-hint auditor-model-error' : 'auditor-model-hint'}
+ aria-invalid={error ? true : undefined}
+ onChange={(e) => onChange(e.target.value as AuditorModel)}
+ className={`bg-zinc-950 border rounded-lg px-2 py-1.5 text-xs text-zinc-100 focus:border-sky-500 focus:outline-none ${error ? 'border-rose-500/60' : 'border-zinc-800'}`}
+ >
+ {!isAuditorModel(value) && <option value={value}>{auditorModelLabel(value)}</option>}
+ {AUDITOR_MODELS.map((o) => (
+ <option key={o.value} value={o.value}>
+ {o.label}
+ </option>
+ ))}
+ </select>
+ </div>
+ <p id="auditor-model-hint" className="mt-1 text-[11px] text-zinc-500">
+ {MODEL_HINT}
+ </p>
+ {error && (
+ <p id="auditor-model-error" role="alert" className="mt-1 text-[11px] text-rose-400" data-testid="auditor-model-error">
+ {error}
+ </p>
+ )}
+ </div>
+ );
+}
diff --git a/frontend/src/components/MissionBoardView.tsx b/frontend/src/components/MissionBoardView.tsx
index ce55db5d..c3c1e5c9 100644
--- a/frontend/src/components/MissionBoardView.tsx
+++ b/frontend/src/components/MissionBoardView.tsx
@@ -526,7 +526,7 @@ export const TaskCard: React.FC<{
{t.state === 'verified' && flags.length > 0 && <Badge tone="emerald">Verified</Badge>}
{t.priority >= 2 && <Badge tone={t.priority >= 3 ? 'rose' : 'amber'}>{priorityLabel(t.priority)}</Badge>}
{showsTier(t) && t.owner_tier !== 'act' && (
- <span data-tier-badge={t.owner_tier} title={`Flight School: ${classLabel(t.task_class ?? DEFAULT_CLASS)} work at ${tierLabel(t.owner_tier)}`}>
+ <span data-tier-badge={t.owner_tier} title={`Flight School: ${classLabel(t.task_class ?? DEFAULT_CLASS).toLowerCase()} work at ${tierLabel(t.owner_tier)}`}>
<Badge tone="sky">{tierLabel(t.owner_tier)}</Badge>
</span>
)}
diff --git a/frontend/src/components/SettingsModal.tsx b/frontend/src/components/SettingsModal.tsx
index a5cbdef2..e66e1c11 100644
--- a/frontend/src/components/SettingsModal.tsx
+++ b/frontend/src/components/SettingsModal.tsx
@@ -1,5 +1,6 @@
import React, { useState, useEffect, useRef } from 'react';
-import { AuditorSettings, DAILY_CAPS, SETTING_HINT as AUDITOR_HINT, parseAuditorSettings } from '../auditor';
+import { AuditorSettings, DAILY_CAPS, SETTING_HINT as AUDITOR_HINT, isAuditorModelError, MODEL_ERROR_TEXT as AUDITOR_MODEL_ERROR, parseAuditorSettings } from '../auditor';
+import { AuditorModelSetting } from './AuditorModelSetting';
import { Key, Globe, X, Settings, Check, ChevronDown, ChevronRight, LogOut, Bell, AlertTriangle, Layers, Monitor, Volume2, VolumeX, Gauge, MapPin, Vibrate, VibrateOff, Sparkles, KanbanSquare } from 'lucide-react';
import { TURN_LIMITS, TurnLimitKey, limitError } from '../threads';
import { budgetError, budgetValue } from '../chainBudget';
@@ -257,6 +258,8 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, t
const [saving, setSaving] = useState(false);
const [saveSuccess, setSaveSuccess] = useState(false);
const [saveError, setSaveError] = useState<string | null>(null);
+ // A 400 about the audit model shows next to that picker, not only at the bottom.
+ const modelError = isAuditorModelError(saveError);
// null until loaded (or from a server without the setting), and then left out of the save
const [agentTools, setAgentTools] = useState<boolean | null>(null);
// Deciding and working ahead on their own; null on a server without these settings
@@ -954,6 +957,16 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, t
<span className="text-[11px] text-zinc-300">{auditor.auditor_daily_cap === 1 ? 'audit' : 'audits'} a day</span>
</div>
)}
+ {(auditor.auditor === 'on' || modelError) && auditor.auditor_model !== undefined && (
+ <AuditorModelSetting
+ value={auditor.auditor_model}
+ error={modelError ? AUDITOR_MODEL_ERROR : null}
+ onChange={(m) => {
+ setSaveError(null);
+ setAuditor((x) => (x ? { ...x, auditor_model: m } : x));
+ }}
+ />
+ )}
</SwitchRow>
)}
</fieldset>
diff --git a/frontend/src/flightSchool.ts b/frontend/src/flightSchool.ts
index c388d750..160380e6 100644
--- a/frontend/src/flightSchool.ts
+++ b/frontend/src/flightSchool.ts
@@ -72,11 +72,17 @@ export function fromText(from: string): string {
}
}
-export const classLabel = (c: string): string => (c === ANY_CLASS ? 'All work' : c === DEFAULT_CLASS ? 'General' : c);
+/** A task class as people read it: "code-review" → "Code review". */
+export const classLabel = (c: string): string => {
+ if (c === ANY_CLASS) return 'All work';
+ if (c === DEFAULT_CLASS) return 'General';
+ const words = c.replace(/[-_]+/g, ' ').replace(/\s+/g, ' ').trim();
+ return words ? words[0].toUpperCase() + words.slice(1) : c;
+};
/** One line for a tier change in the bot's history. */
export function capabilityEventText(e: Pick<CapabilityEvent, 'kind' | 'tier' | 'task_class'>): string {
- const where = e.task_class === ANY_CLASS ? 'all work' : classLabel(e.task_class);
+ const where = e.task_class === ANY_CLASS ? 'all work' : classLabel(e.task_class).toLowerCase();
const tier = tierLabel(e.tier);
switch (e.kind) {
case 'granted':
diff --git a/frontend/tests/auditorModel.test.mjs b/frontend/tests/auditorModel.test.mjs
new file mode 100644
index 00000000..b6d8c098
--- /dev/null
+++ b/frontend/tests/auditorModel.test.mjs
@@ -0,0 +1,109 @@
+// Settings → Audit model (docs/mission-control.md §18): next to the auditor switch, a picker for
+// `auditor_model` (fast by default, balanced, deep, or the bot's own model). It is saved through
+// /api/settings with the rest, a 400 about it shows next to the picker, and a server without the
+// setting shows no picker and gets nothing new in the save. Also: task classes read as words.
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { readFileSync } from 'node:fs';
+import { JSDOM } from 'jsdom';
+import { loadBundled } from './bundle.mjs';
+
+const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/', pretendToBeVisual: true });
+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'Node', 'Event', 'MouseEvent', 'requestAnimationFrame', 'cancelAnimationFrame', 'getComputedStyle', 'localStorage', 'sessionStorage']) {
+ if (!(k in dom.window)) continue;
+ Object.defineProperty(globalThis, k, { value: dom.window[k], configurable: true, writable: true });
+}
+
+const a = await loadBundled(`export * from './src/auditor';`);
+const fs = await loadBundled(`export { classLabel } from './src/flightSchool'; export { classText } from './src/performance';`);
+const ui = await loadBundled(`
+ import React from 'react';
+ import { flushSync } from 'react-dom';
+ import { AuditorModelSetting } from './src/components/AuditorModelSetting';
+ export { createRoot } from 'react-dom/client';
+ export { React, flushSync, AuditorModelSetting };
+`);
+
+const mount = (props) => {
+ const host = document.createElement('div');
+ document.body.appendChild(host);
+ const root = ui.createRoot(host);
+ ui.flushSync(() => root.render(ui.React.createElement(ui.AuditorModelSetting, props)));
+ return { host, root };
+};
+
+test('settings: auditor_model is read when the server sends it, and left out when it does not', () => {
+ assert.deepEqual(a.parseAuditorSettings({ auditor: 'on', auditor_daily_cap: 5, auditor_model: 'fast' }), { auditor: 'on', auditor_daily_cap: 5, auditor_model: 'fast' });
+ assert.deepEqual(a.parseAuditorSettings({ auditor: 'off', auditor_daily_cap: 5, auditor_model: 'bot' }).auditor_model, 'bot');
+ assert.equal('auditor_model' in a.parseAuditorSettings({ auditor: 'off', auditor_daily_cap: 5 }), false, 'older server: nothing new is saved');
+ assert.equal(a.parseAuditorSettings({ auditor: 'on', auditor_model: 'turbo' }).auditor_model, 'turbo', 'an unknown value is kept, not silently changed');
+});
+
+test('the picker lists fast, balanced, deep and "same as the bot", with the plain hint', () => {
+ const { host, root } = mount({ value: 'fast', error: null, onChange: () => {} });
+ const sel = host.querySelector('select#auditor-model');
+ assert.ok(sel);
+ assert.equal(host.querySelector('label[for="auditor-model"]').textContent, 'Audit model');
+ assert.deepEqual([...sel.options].map((o) => [o.value, o.textContent]), [
+ ['fast', 'Fast'],
+ ['balanced', 'Balanced'],
+ ['deep', 'Deep'],
+ ['bot', 'Same as the bot'],
+ ]);
+ assert.equal(sel.value, 'fast');
+ assert.equal(a.MODEL_HINT, 'Fast is cheapest; audits never mark work passed or failed.');
+ assert.match(host.textContent, /Fast is cheapest; audits never mark work passed or failed\./);
+ assert.equal(sel.getAttribute('aria-describedby'), 'auditor-model-hint');
+ assert.equal(host.querySelector('[role="alert"]'), null);
+ root.unmount();
+});
+
+test('choosing a model reports it; an unknown saved value still shows as the current choice', () => {
+ const picked = [];
+ const { host, root } = mount({ value: 'fast', error: null, onChange: (m) => picked.push(m) });
+ const sel = host.querySelector('select');
+ sel.value = 'deep';
+ sel.dispatchEvent(new window.Event('change', { bubbles: true }));
+ assert.deepEqual(picked, ['deep']);
+ root.unmount();
+ const odd = mount({ value: 'turbo', error: null, onChange: () => {} });
+ const s2 = odd.host.querySelector('select');
+ assert.equal(s2.value, 'turbo');
+ assert.equal(s2.options[0].textContent, 'turbo');
+ assert.equal(s2.options.length, 5);
+ odd.root.unmount();
+});
+
+test('a 400 about auditor_model shows inline, next to the picker', () => {
+ const msg = 'auditor_model must be fast, balanced, deep or bot (got turbo)';
+ assert.equal(a.isAuditorModelError(msg), true);
+ assert.equal(a.isAuditorModelError('auditor_daily_cap must be 1–50'), false);
+ assert.equal(a.isAuditorModelError(null), false);
+ assert.equal(a.MODEL_ERROR_TEXT, 'The server didn’t accept that audit model. Pick Fast, Balanced, Deep or Same as the bot.');
+ const { host, root } = mount({ value: 'turbo', error: a.MODEL_ERROR_TEXT, onChange: () => {} });
+ const alert = host.querySelector('[role="alert"]#auditor-model-error');
+ assert.ok(alert);
+ assert.equal(alert.textContent, a.MODEL_ERROR_TEXT, 'plain words, not the server’s field name');
+ const sel = host.querySelector('select');
+ assert.equal(sel.getAttribute('aria-invalid'), 'true');
+ assert.equal(sel.getAttribute('aria-describedby'), 'auditor-model-hint auditor-model-error');
+ root.unmount();
+});
+
+test('Settings wires the picker into the auditor switch and the save', () => {
+ const src = readFileSync(new URL('../src/components/SettingsModal.tsx', import.meta.url), 'utf8');
+ assert.match(src, /const modelError = isAuditorModelError\(saveError\)/);
+ assert.match(src, /\(auditor\.auditor === 'on' \|\| modelError\) && auditor\.auditor_model !== undefined && \(\s*<AuditorModelSetting/);
+ assert.match(src, /error=\{modelError \? AUDITOR_MODEL_ERROR : null\}/);
+ assert.match(src, /\.\.\.\(auditor \?\? \{\}\)/, 'auditor_model goes out with the other auditor settings');
+});
+
+test('task classes read as words: code-review → Code review', () => {
+ assert.equal(fs.classLabel('code-review'), 'Code review');
+ assert.equal(fs.classLabel('data_cleanup'), 'Data cleanup');
+ assert.equal(fs.classLabel('research'), 'Research');
+ assert.equal(fs.classLabel('general'), 'General');
+ assert.equal(fs.classLabel('*'), 'All work');
+ assert.equal(fs.classLabel('--'), '--', 'nothing readable left: keep the raw value');
+ assert.equal(fs.classText('code-review'), 'Code review', 'the Performance section uses the same label');
+});
diff --git a/frontend/tests/flightSchool.test.mjs b/frontend/tests/flightSchool.test.mjs
index 86758e87..508703c2 100644
--- a/frontend/tests/flightSchool.test.mjs
+++ b/frontend/tests/flightSchool.test.mjs
@@ -102,10 +102,10 @@ test('a bot’s tiers: each kind of work, where its tier comes from, one-click R
// Sandbox's hint matches the gate: read-only commands in the bot's own folder may run without a card.
assert.match(t, /Commands that can change things ask you; reading its own folder doesn’t\./);
assert.doesNotMatch(t, /everything else ask/);
- assert.match(t, /release Set for this kind of work/);
+ assert.match(t, /Release Set for this kind of work/);
// Revoke steps one tier down and says where to; Observe has nothing lower.
assert.match(html, /aria-label="Revoke all work to Observe"/);
- assert.match(html, /data-class="docs"[\s\S]*?aria-label="Revoke docs to Sandbox"/);
+ assert.match(html, /data-class="docs"[\s\S]*?aria-label="Revoke Docs to Sandbox"/);
assert.doesNotMatch(html, /Revoke release/);
assert.match(t, /You revoked release to Observe/);
assert.match(t, /pushed a tag/);
diff --git a/frontend/tests/performance.test.mjs b/frontend/tests/performance.test.mjs
index 94cd3b33..16bf0acd 100644
--- a/frontend/tests/performance.test.mjs
+++ b/frontend/tests/performance.test.mjs
@@ -143,7 +143,7 @@ test('filters reload with by, class, bot and since; choices stay listed after fi
const { host, root } = await mount(load);
assert.deepEqual(calls[0], { by: 'bot', since: '30d', class: undefined, bot: undefined });
const [cls, , since] = host.querySelectorAll('select');
- assert.deepEqual([...cls.options].map((o) => o.textContent), ['All kinds of work', 'General', 'research']);
+ assert.deepEqual([...cls.options].map((o) => o.textContent), ['All kinds of work', 'General', 'Research']);
const change = async (el, v) => {
el.value = v;
el.dispatchEvent(new window.Event('change', { bubbles: true }));