Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Let users choose an icon for each loop (#1494)

Regan Bell6ae009eb54c7
diff --git a/docs/qa/loop-icons/inbox.png b/docs/qa/loop-icons/inbox.png
new file mode 100644
index 000000000..98b20a8ef
Binary files /dev/null and b/docs/qa/loop-icons/inbox.png differ
diff --git a/docs/qa/loop-icons/picker.png b/docs/qa/loop-icons/picker.png
new file mode 100644
index 000000000..0d804e5a3
Binary files /dev/null and b/docs/qa/loop-icons/picker.png differ
diff --git a/plugins/web-ui/src/inbox.ts b/plugins/web-ui/src/inbox.ts
index cdc26236d..83eb4dce0 100644
--- a/plugins/web-ui/src/inbox.ts
+++ b/plugins/web-ui/src/inbox.ts
@@ -1,3 +1,4 @@
+import { loopIcon } from "./loop-icon";
import {
ensureSentMail,
openSentEmail,
@@ -22,10 +23,8 @@ import {
ChevronDown,
ChevronRight,
Inbox as InboxGlyph,
- Mail,
MoreHorizontal,
Plus,
- Repeat,
RefreshCw,
Send,
Undo2,
@@ -47,7 +46,7 @@ import { listBackLink } from "./list-page";
import { registerPaneKind } from "./pane-kinds";
import { exitSplitIfActive, notifyPanesChanged } from "./split";
import { tip } from "./tooltip";
-import { brandName, icon, initials, relTime, slackMark, workingWave } from "./ui";
+import { brandName, icon, initials, relTime, workingWave } from "./ui";
export type InboxSource = "gmail" | "slack" | "generic";
@@ -167,13 +166,22 @@ export const inboxState = {
selected: [] as Array<{
id: string;
name: string;
+ icon?: string;
+ sources?: string[];
count: number;
source?: string;
cronId?: string;
syncCron?: InboxSyncCron | null;
ingestionActive?: boolean;
}>,
- available: [] as Array<{ id: string; name: string; selected: boolean }>,
+ available: [] as Array<{
+ id: string;
+ name: string;
+ icon?: string;
+ sources?: string[];
+ source?: string;
+ selected: boolean;
+ }>,
total: 0,
nextCursor: null as string | null,
picker: false,
@@ -990,10 +998,8 @@ function openDraftSession(e: MouseEvent, sessionId: string): void {
else window.location.assign(deepLinkPath(UI_BASE, "chats", sessionId));
}
-function sourceGlyph(source: InboxSource): SVGElement | TemplateResult {
- if (source === "gmail") return icon(Mail, 14);
- if (source === "slack") return slackMark(14);
- return icon(Repeat, 14);
+function sourceGlyph(item: InboxItem): TemplateResult {
+ return loopIcon(inboxState.selected.find((loop) => loop.id === item.loopId) ?? { source: item.source }, 14);
}
function fmtClock(ms: number): string {
@@ -1394,7 +1400,7 @@ function itemRowTpl(surface: InboxSurface, item: InboxItem): TemplateResult {
drawAll();
}}
>
- <span class="inbox-item-glyph">${sourceGlyph(item.source)}</span>
+ <span class="inbox-item-glyph">${sourceGlyph(item)}</span>
<span class="inbox-item-main">
<span class="inbox-item-top">
<span class="inbox-item-heading">${heading}</span>
@@ -1518,7 +1524,7 @@ function surfaceTpl(surface: InboxSurface): TemplateResult {
drawAll();
}}
>
- <span>${v.name}</span>${count > 0 ? html`<span class="inbox-chip-count">${count}</span>` : nothing}
+ ${v.id === "all" ? nothing : loopIcon(inboxState.selected.find((loop) => loop.id === v.id) ?? {})}<span>${v.name}</span>${count > 0 ? html`<span class="inbox-chip-count">${count}</span>` : nothing}
</button>`;
})}
${
@@ -1623,9 +1629,7 @@ function surfaceTpl(surface: InboxSurface): TemplateResult {
${setupLoops.map(
(loop) =>
html`<div class="inbox-setup-row">
- <span class="inbox-setup-icon" aria-hidden="true"
- >${loop.source === "gmail" ? icon(Mail, 17) : slackMark(17)}</span
- >
+ <span class="inbox-setup-icon" aria-hidden="true">${loopIcon(loop, 17)}</span>
<div class="inbox-setup-copy">
<span class="inbox-setup-title">${loop.name}</span
><span class="inbox-setup-description">Sync not set up</span>
@@ -1690,7 +1694,7 @@ function surfaceTpl(surface: InboxSurface): TemplateResult {
</button>
</div>
<p>Choose the Loops you want to review here.</p>
- ${inboxState.available.map((loop) => html`<label><input type="checkbox" .checked=${loop.selected} ?disabled=${inboxState.selectionBusy} @change=${() => void toggleSelection(loop.id)} /><span>${loop.name}</span><span>${loop.selected ? "Included" : "Add"}</span></label>`)}
+ ${inboxState.available.map((loop) => html`<label><input type="checkbox" .checked=${loop.selected} ?disabled=${inboxState.selectionBusy} @change=${() => void toggleSelection(loop.id)} />${loopIcon(loop)}<span>${loop.name}</span><span>${loop.selected ? "Included" : "Add"}</span></label>`)}
</section>`
: nothing
}
@@ -1733,7 +1737,7 @@ function itemPageTpl(item: InboxItem): TemplateResult {
<div class="inbox-item-head-copy">
${listBackLink("Inbox", closeInboxItem)}
<h1 class="pane-title">
- <span class="inbox-item-glyph">${sourceGlyph(item.source)}</span><span>${heading}</span>
+ <span class="inbox-item-glyph">${sourceGlyph(item)}</span><span>${heading}</span>
<span class="inbox-item-head-meta">
${participantsTpl(item)} ${itemSideMark(item, handled)}
<span class="inbox-item-time" title=${fmtClock(item.receivedAt)}>${relTime(item.receivedAt)}</span>
diff --git a/plugins/web-ui/src/loop-icon.ts b/plugins/web-ui/src/loop-icon.ts
new file mode 100644
index 000000000..07dc427ad
--- /dev/null
+++ b/plugins/web-ui/src/loop-icon.ts
@@ -0,0 +1,49 @@
+import { html, type TemplateResult } from "lit";
+import {
+ Repeat,
+ Mail,
+ Zap,
+ Code,
+ Bug,
+ Shield,
+ Calendar,
+ MessageSquare,
+ ChartNoAxesCombined,
+ CheckCircle2,
+ BookOpen,
+ Rocket,
+ Globe,
+ Heart,
+ Wrench,
+} from "lucide";
+import { icon, slackMark } from "./ui";
+
+export const LOOP_ICONS = [
+ { id: "repeat", label: "Loop", glyph: Repeat },
+ { id: "mail", label: "Email", glyph: Mail },
+ { id: "slack", label: "Slack", glyph: MessageSquare },
+ { id: "zap", label: "Lightning", glyph: Zap },
+ { id: "code", label: "Code", glyph: Code },
+ { id: "bug", label: "Bug", glyph: Bug },
+ { id: "shield", label: "Shield", glyph: Shield },
+ { id: "calendar", label: "Calendar", glyph: Calendar },
+ { id: "message", label: "Message", glyph: MessageSquare },
+ { id: "chart", label: "Chart", glyph: ChartNoAxesCombined },
+ { id: "check", label: "Check", glyph: CheckCircle2 },
+ { id: "book", label: "Book", glyph: BookOpen },
+ { id: "rocket", label: "Rocket", glyph: Rocket },
+ { id: "globe", label: "Globe", glyph: Globe },
+ { id: "heart", label: "Heart", glyph: Heart },
+ { id: "wrench", label: "Wrench", glyph: Wrench },
+];
+
+export function loopIcon(loop: { icon?: string; source?: string; sources?: string[] }, size = 16): TemplateResult {
+ const source = loop.source ?? loop.sources?.[0];
+ const fallback = ({ gmail: "mail", slack: "slack" } as Record<string, string>)[source ?? ""] ?? "repeat";
+ const choice =
+ LOOP_ICONS.find((entry) => entry.id === (loop.icon ?? fallback)) ??
+ LOOP_ICONS.find((entry) => entry.id === fallback)!;
+ return html`<span class="loop-icon" aria-hidden="true"
+ >${choice.id === "slack" ? slackMark(size) : icon(choice.glyph, size)}</span
+ >`;
+}
diff --git a/plugins/web-ui/src/loops.ts b/plugins/web-ui/src/loops.ts
index e78298ca9..4ab73335d 100644
--- a/plugins/web-ui/src/loops.ts
+++ b/plugins/web-ui/src/loops.ts
@@ -1,3 +1,4 @@
+import { LOOP_ICONS, loopIcon } from "./loop-icon";
import { html, nothing, render, type TemplateResult } from "lit";
import { CheckCircle2, CornerUpLeft, Pause, Play, Zap } from "lucide";
import { api } from "./core-bridge";
@@ -9,6 +10,7 @@ import { appState, can } from "./shell";
interface LoopView {
id: string;
name: string;
+ icon?: string;
purpose?: string;
playbook: string;
playbookVersion: number;
@@ -80,11 +82,13 @@ let loopsNotice = "";
let activeLoopId: string | null = null;
let activeDetail: LoopDetail | null = null;
let loopBusy = false;
+let iconPickerOpen = false;
let playbookDraft: string | null = null;
let returnDrafts = new Map<string, string>();
export function resetActiveLoop(): void {
activeLoopId = null;
+ iconPickerOpen = false;
ingestion = null;
ingestionKind = "";
createdSecret = "";
@@ -160,6 +164,16 @@ async function mutate(fn: () => Promise<unknown>): Promise<void> {
}
}
+async function setLoopIcon(loop: LoopView, value: string | null): Promise<void> {
+ await mutate(async () => {
+ await api(`/api/loops/${encodeURIComponent(loop.id)}`, { method: "PATCH", body: JSON.stringify({ icon: value }) });
+ iconPickerOpen = false;
+ const { refreshInbox } = await import("./inbox");
+ await refreshInbox({ silent: true });
+ });
+ loopsHost?.querySelector<HTMLElement>(".loop-icon-picker summary")?.focus();
+}
+
export function openLoop(id: string): void {
resetActiveLoop();
activeLoopId = id;
@@ -413,7 +427,39 @@ function detailTpl(detail: LoopDetail): TemplateResult {
void refreshLoops();
})}
<div class="list-page-head">
- <h1 class="pane-title">${loop.name}</h1>
+ <div class="loop-title">
+ <details
+ class="loop-icon-picker"
+ .open=${iconPickerOpen}
+ @toggle=${(event: Event) => {
+ iconPickerOpen = (event.currentTarget as HTMLDetailsElement).open;
+ }}
+ @keydown=${(event: KeyboardEvent) => {
+ if (event.key === "Escape") {
+ iconPickerOpen = false;
+ (event.currentTarget as HTMLDetailsElement).open = false;
+ (event.currentTarget as HTMLElement).querySelector("summary")?.focus();
+ }
+ }}
+ >
+ <summary aria-label=${`Change icon for ${loop.name}`} title="Change icon">${loopIcon(loop, 24)}</summary>
+ <div class="loop-icon-popover" role="group" aria-label="Loop icon">
+ <span class="loop-icon-heading">Choose an icon</span>
+ <div class="loop-icon-grid">
+ ${LOOP_ICONS.map((choice) => html`<button type="button" aria-label=${choice.label} title=${choice.label} aria-pressed=${loop.icon === choice.id ? "true" : "false"} ?disabled=${loopBusy} @click=${() => void setLoopIcon(loop, choice.id)}>${loopIcon({ icon: choice.id }, 20)}</button>`)}
+ </div>
+ <button
+ class="loop-icon-default"
+ type="button"
+ ?disabled=${loopBusy || !loop.icon}
+ @click=${() => void setLoopIcon(loop, null)}
+ >
+ ${loopIcon({ sources: loop.sources })}<span>Use default</span>
+ </button>
+ </div>
+ </details>
+ <h1 class="pane-title">${loop.name}</h1>
+ </div>
<div class="list-page-actions">
${healthBadge(loop)}
<button class="btn" type="button" ?disabled=${loopBusy} @click=${() => fireNow(loop)}>
@@ -516,7 +562,7 @@ function detailTpl(detail: LoopDetail): TemplateResult {
function loopRow(loop: LoopView): TemplateResult {
return html`
<button class="list-row loop-row" type="button" @click=${() => openLoop(loop.id)}>
- <span class="loop-row-name">${loop.name}</span>
+ ${loopIcon(loop, 18)}<span class="loop-row-name">${loop.name}</span>
${healthBadge(loop)}
<span class="loop-row-meta">last fire ${ago(loop.lastFiredAt)}</span>
</button>
diff --git a/plugins/web-ui/src/shell.css b/plugins/web-ui/src/shell.css
index fe1e1cc74..52dd9b656 100644
--- a/plugins/web-ui/src/shell.css
+++ b/plugins/web-ui/src/shell.css
@@ -12364,3 +12364,88 @@ body.app-edit-embed .custom-chat-shell.app-edit-chat > .chat-bottom-dock {
max-width: 520px;
margin-bottom: 12px;
}
+
+.loop-icon {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ flex: 0 0 auto;
+ color: inherit;
+ vertical-align: middle;
+}
+.loop-title {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ min-width: 0;
+}
+.loop-icon-picker {
+ position: relative;
+ flex: 0 0 auto;
+}
+.loop-icon-picker > summary {
+ display: flex;
+ padding: 9px;
+ border: 1px solid var(--border);
+ border-radius: 10px;
+ cursor: pointer;
+ list-style: none;
+}
+.loop-icon-picker > summary::-webkit-details-marker {
+ display: none;
+}
+.loop-icon-popover {
+ position: absolute;
+ top: calc(100% + 8px);
+ left: 0;
+ z-index: 20;
+ width: 236px;
+ padding: 14px;
+ border: 1px solid var(--border);
+ border-radius: 14px;
+ background: var(--popover);
+}
+.loop-icon-heading {
+ display: block;
+ margin-bottom: 12px;
+ font-size: 13px;
+ font-weight: 600;
+}
+.loop-icon-grid {
+ display: grid;
+ grid-template-columns: repeat(4, 1fr);
+ gap: 6px;
+}
+.loop-icon-grid button {
+ display: grid;
+ place-items: center;
+ height: 44px;
+ border: 1px solid transparent;
+ border-radius: 8px;
+ background: transparent;
+ color: inherit;
+ cursor: pointer;
+}
+.loop-icon-grid button:hover,
+.loop-icon-grid button[aria-pressed="true"] {
+ background: var(--accent);
+ border-color: var(--border);
+}
+.loop-icon-default {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 8px;
+ width: 100%;
+ margin-top: 12px;
+ padding: 9px;
+ border: 1px solid var(--border);
+ border-radius: 8px;
+ background: transparent;
+ color: inherit;
+ cursor: pointer;
+}
+.loop-icon-default:disabled {
+ opacity: 0.45;
+ cursor: default;
+}
diff --git a/src/api/agent-api-catalog.ts b/src/api/agent-api-catalog.ts
index a5773e0a8..04fb69a5b 100644
--- a/src/api/agent-api-catalog.ts
+++ b/src/api/agent-api-catalog.ts
@@ -246,7 +246,7 @@ const FAMILIES: AgentApiFamily[] = [
method: "POST",
path: "/v1/loops",
summary:
- 'create a loop — body {name, playbook, successCondition, shipActions: [{action, gate: "hold"|"auto"}], schedule?, destinationKey?, caps?, governor?: {maxConsecutiveFailedFires?, maxReturnRate?, returnRateMinDecisions?, maxQueueAgeMs?, maxQueueDepth?, staleFireMs?}, successChecks?, purpose?}; a schedule creates a bound child cron that fires the loop; setting an escalation destination requires a live human',
+ 'create a loop — body {name, icon?, playbook, successCondition, shipActions: [{action, gate: "hold"|"auto"}], schedule?, destinationKey?, caps?, governor?: {maxConsecutiveFailedFires?, maxReturnRate?, returnRateMinDecisions?, maxQueueAgeMs?, maxQueueDepth?, staleFireMs?}, successChecks?, purpose?}; a schedule creates a bound child cron that fires the loop; setting an escalation destination requires a live human',
},
{
method: "DELETE",
@@ -258,7 +258,7 @@ const FAMILIES: AgentApiFamily[] = [
method: "GET|PATCH|DELETE",
path: "/v1/loops/:id",
summary:
- "inspect a loop (items, held outputs, vitals), edit it (playbook edits are versioned; destinationKey sets escalation delivery and null clears it; state: enabled|paused clears or sets the pause; clearing quarantine or changing destination requires a live human), or delete it and its child cron",
+ "inspect a loop (items, held outputs, vitals), edit it (icon sets a named icon such as bug, rocket, mail, or slack; null restores the default; playbook edits are versioned; destinationKey sets escalation delivery and null clears it; state: enabled|paused clears or sets the pause; clearing quarantine or changing destination requires a live human), or delete it and its child cron",
},
{ method: "POST", path: "/v1/loops/:id/fire", summary: "fire a loop now (intake → work → judge → hold/ship)" },
{
diff --git a/src/api/routes/inbox.ts b/src/api/routes/inbox.ts
index 7ab9b479e..390a7c90f 100644
--- a/src/api/routes/inbox.ts
+++ b/src/api/routes/inbox.ts
@@ -105,6 +105,8 @@ async function inbox(ctx: ApiCtx): Promise<void> {
selected.map(async (loop) => ({
id: loop.id,
name: loop.name,
+ icon: loop.icon,
+ sources: loop.sources,
count: counts.get(loop.id) ?? 0,
state: loop.state,
cronId: loop.cronId,
@@ -113,7 +115,14 @@ async function inbox(ctx: ApiCtx): Promise<void> {
source: loop.surface?.startsWith("inbox:") ? loop.sources?.[0] : undefined,
})),
),
- available: available.map((loop) => ({ id: loop.id, name: loop.name, selected: selectedIds.includes(loop.id) })),
+ available: available.map((loop) => ({
+ id: loop.id,
+ name: loop.name,
+ icon: loop.icon,
+ sources: loop.sources,
+ source: loop.surface?.startsWith("inbox:") ? loop.sources?.[0] : undefined,
+ selected: selectedIds.includes(loop.id),
+ })),
migrationPending: !migrated,
total: [...counts.values()].reduce((sum, count) => sum + count, 0),
items: page.map((item) =>
diff --git a/src/api/routes/loops.ts b/src/api/routes/loops.ts
index 74848c58e..c7e81d65f 100644
--- a/src/api/routes/loops.ts
+++ b/src/api/routes/loops.ts
@@ -1,3 +1,4 @@
+import { validLoopIcon } from "../../loops/loop-store.ts";
import { boundLoopCron } from "../../loops/authority.ts";
import { unattendedGrantRefusal } from "../../cron/authority.ts";
import type { AdvisoryLock } from "../../persistence/advisory-lock.ts";
@@ -181,6 +182,11 @@ async function createLoop(ctx: ApiCtx): Promise<void> {
const acting = actingPrincipal(ctx);
if (!acting) return;
const b = isObj(ctx.body) ? ctx.body : {};
+ if (b.icon !== undefined && !validLoopIcon(b.icon))
+ return sendJson(ctx.res, 400, {
+ error: "bad_request",
+ message: "icon must be a lowercase icon name of at most 48 characters, or null for the default",
+ });
if (typeof b.name !== "string" || !b.name.trim())
return sendJson(ctx.res, 400, { error: "bad_request", message: "name required" });
if (typeof b.playbook !== "string" || !b.playbook.trim())
@@ -251,6 +257,7 @@ async function createLoop(ctx: ApiCtx): Promise<void> {
createdBy: acting.actorId,
ownerScopeId,
name: b.name,
+ ...(b.icon !== undefined ? { icon: b.icon as string | null } : {}),
playbook: b.playbook,
successCondition: b.successCondition,
shipActions,
@@ -331,6 +338,11 @@ async function patchLoop(ctx: ApiCtx): Promise<void> {
const { deps, loop, acting } = loaded;
if (!(await requireLoopAuthority(ctx, deps, loop))) return;
const b = isObj(ctx.body) ? ctx.body : {};
+ if (b.icon !== undefined && !validLoopIcon(b.icon))
+ return sendJson(ctx.res, 400, {
+ error: "bad_request",
+ message: "icon must be a lowercase icon name of at most 48 characters, or null for the default",
+ });
const patch: LoopPatch = {};
if (typeof b.playbook === "string" && b.playbook.trim()) {
patch.playbookEdit = {
@@ -359,6 +371,7 @@ async function patchLoop(ctx: ApiCtx): Promise<void> {
return sendJson(ctx.res, 400, { error: "bad_request", message: "state must be a string" });
}
Object.assign(patch, {
+ ...(b.icon !== undefined ? { icon: b.icon } : {}),
...(typeof b.name === "string" && b.name.trim() ? { name: b.name } : {}),
...(typeof b.purpose === "string" ? { purpose: b.purpose } : {}),
...(typeof b.successCondition === "string" && b.successCondition.trim()
diff --git a/src/loops/loop-store.ts b/src/loops/loop-store.ts
index a8bbf64a1..855d31970 100644
--- a/src/loops/loop-store.ts
+++ b/src/loops/loop-store.ts
@@ -20,6 +20,7 @@ import { hashId } from "../util/crypto.ts";
export interface CreateLoopInput extends CreateTriggerInput {
name: string;
+ icon?: string | null;
surface?: string;
sources?: string[];
playbook: string;
@@ -36,6 +37,7 @@ export interface CreateLoopInput extends CreateTriggerInput {
export interface LoopPatch {
name?: string;
+ icon?: string | null;
purpose?: string;
successCondition?: string;
successChecks?: string[];
@@ -78,6 +80,18 @@ export function isRunnable(loop: Loop): boolean {
return RUNNABLE_STATES.has(loop.state);
}
+export function validLoopIcon(value: unknown): value is string | null {
+ return (
+ value === null || (typeof value === "string" && value.length <= 48 && /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(value))
+ );
+}
+
+function normalizeIcon(value: string | null): string | undefined {
+ if (!validLoopIcon(value))
+ throw new Error("icon must be a lowercase icon name of at most 48 characters, or null for the default");
+ return value ?? undefined;
+}
+
function normalizeName(name: string): string {
const trimmed = name.trim().replace(/\s+/g, " ");
if (!trimmed) throw new Error("a loop needs a name");
@@ -131,6 +145,7 @@ export function createLoopStore(backing: DurableMap<Loop> = createMemoryMap<Loop
...buildTriggerBase(input, contentId, now),
...stateFields("enabled"),
name,
+ ...(input.icon !== undefined ? { icon: normalizeIcon(input.icon) } : {}),
playbook: input.playbook,
playbookVersion: 1,
playbookHistory: [{ version: 1, at: now, by: input.createdBy }],
@@ -164,6 +179,7 @@ export function createLoopStore(backing: DurableMap<Loop> = createMemoryMap<Loop
if (patch.restore !== undefined) return patch.restore;
const fields: Partial<Loop> = {};
let policyChanged = false;
+ if (patch.icon !== undefined) fields.icon = normalizeIcon(patch.icon);
if (patch.name !== undefined) fields.name = normalizeName(patch.name);
if (patch.purpose !== undefined) fields.purpose = patch.purpose;
if (patch.successCondition !== undefined) fields.successCondition = patch.successCondition;
diff --git a/src/types.ts b/src/types.ts
index 137a1e147..cc4d4299f 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -348,6 +348,7 @@ interface LoopPlaybookRevision {
export interface Loop extends TriggerBase {
name: string;
+ icon?: string;
purpose?: string;
surface?: string;
sources?: string[];
diff --git a/test/inbox-selection.test.ts b/test/inbox-selection.test.ts
index 9bde1626b..220be3e89 100644
--- a/test/inbox-selection.test.ts
+++ b/test/inbox-selection.test.ts
@@ -77,6 +77,8 @@ test("selection reuses original items, counts items, omits heavy fields, and enf
createdBy: "alice",
ownerScopeId: "personal:alice",
name: "QM error repairs",
+ icon: "bug",
+ sources: ["gmail"],
playbook: "Repair",
successCondition: "Fixed",
});
@@ -101,6 +103,10 @@ test("selection reuses original items, counts items, omits heavy fields, and enf
});
const selected = await w.call("PUT", { loopIds: [loop.id] });
assert.equal(selected.data.total, 1);
+ assert.equal(selected.data.selected[0].icon, "bug");
+ assert.deepEqual(selected.data.selected[0].sources, ["gmail"]);
+ assert.deepEqual(selected.data.available.find((entry: any) => entry.id === loop.id).sources, ["gmail"]);
+ assert.equal(selected.data.available.find((entry: any) => entry.id === loop.id).icon, "bug");
assert.equal(selected.data.items[0].id, item!.id);
assert.equal(selected.data.items[0].proposal, undefined);
const detail = await w.call("GET", null, `itemId=${item!.id}`);
diff --git a/test/loop-routes.test.ts b/test/loop-routes.test.ts
index ed9ba31e8..9f2efeaa2 100644
--- a/test/loop-routes.test.ts
+++ b/test/loop-routes.test.ts
@@ -787,3 +787,38 @@ test("a legacy inbox sync cron cannot be re-enabled through an autonomous Loop p
assert.equal((await call(deps, "PATCH", `/v1/loops/${loop.id}`, { state: "enabled" })).status, 200);
assert.equal((await deps.crons!.get(cron.id))?.enabled, true);
});
+
+test("loop icons can be set and reset by their owner, reject invalid input and retain authorization", async () => {
+ const deps = services();
+ const created = await call(deps, "POST", "/v1/loops", {
+ name: "Icons",
+ icon: "bug",
+ playbook: "Review",
+ successCondition: "Done",
+ shipActions: [],
+ });
+ assert.equal(created.status, 200);
+ const loop = (created.body as { loop: Loop }).loop;
+ assert.equal(loop.icon, "bug");
+ for (const icon of ["rocket", null]) {
+ const result = await call(deps, "PATCH", `/v1/loops/${loop.id}`, { icon });
+ assert.equal(result.status, 200);
+ assert.equal((result.body as { loop: Loop }).loop.icon, icon ?? undefined);
+ }
+ for (const icon of ["", "<svg>", "x".repeat(49), 7, {}]) {
+ assert.equal((await call(deps, "PATCH", `/v1/loops/${loop.id}`, { icon })).status, 400);
+ assert.equal(
+ (
+ await call(deps, "POST", "/v1/loops", {
+ name: "Invalid",
+ icon,
+ playbook: "Review",
+ successCondition: "Done",
+ shipActions: [],
+ })
+ ).status,
+ 400,
+ );
+ }
+ assert.equal((await call(deps, "PATCH", `/v1/loops/${loop.id}`, { icon: "shield" }, "mallory")).status, 403);
+});
diff --git a/test/loop-store.test.ts b/test/loop-store.test.ts
index d50cd95c4..a13227809 100644
--- a/test/loop-store.test.ts
+++ b/test/loop-store.test.ts
@@ -165,3 +165,18 @@ test("queue stats report depth and the age of the oldest waiting item", async ()
assert.equal(stats.queued, 2);
assert.equal(stats.oldestQueuedAgeMs, 60_000);
});
+
+test("loop icons persist and reset without changing identity or automation policy", async () => {
+ const store = createLoopStore();
+ const { loop } = await store.create({ ...base, icon: "bug" });
+ assert.equal((await store.get(loop.id))!.icon, "bug");
+ await store.update(loop.id, { icon: "rocket" });
+ const edited = (await store.get(loop.id))!;
+ assert.equal(edited.icon, "rocket");
+ assert.equal(edited.policyVersion, loop.policyVersion);
+ assert.equal(edited.playbookVersion, loop.playbookVersion);
+ assert.equal(edited.state, loop.state);
+ await store.update(loop.id, { icon: null });
+ assert.equal((await store.get(loop.id))!.icon, undefined);
+ assert.equal((await store.create(base)).loop.id, loop.id);
+});