Skip to content

Commit 5b1b01d

Browse files
committed
feat(ui): custom session icons with agent-drawable SVG and nav-parity pinned rows
1 parent 74880cb commit 5b1b01d

40 files changed

Lines changed: 1143 additions & 10 deletions

‎packages/gateway-protocol/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./clawhub-trust-error-details.js";
2+
export * from "./session-icon.js";
23
export * from "./terminal-validators.js";
34
export {
45
validateApprovalGetResult,

‎packages/gateway-protocol/src/schema/sessions.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ export const SessionsPatchParamsSchema = closedObject({
364364
label: Type.Optional(Type.Union([SessionLabelString, Type.Null()])),
365365
/** User-defined organization bucket ("category", not chat-group); null clears it. */
366366
category: Type.Optional(Type.Union([SessionLabelString, Type.Null()])),
367+
icon: Type.Optional(
368+
Type.Union([NonEmptyString, Type.Null()], {
369+
description: "Sidebar icon: one emoji, name:<id>, or svg:<svg ...>...</svg>.",
370+
}),
371+
),
367372
archived: Type.Optional(Type.Boolean()),
368373
pinned: Type.Optional(Type.Boolean()),
369374
unread: Type.Optional(
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, expect, it } from "vitest";
2+
import { normalizeSessionIconInput, parseSessionIcon } from "./session-icon.js";
3+
4+
describe("session icons", () => {
5+
it("parses named and single-grapheme emoji forms", () => {
6+
expect(parseSessionIcon("name:lobster")).toEqual({ kind: "named", name: "lobster" });
7+
expect(parseSessionIcon("🦞")).toEqual({ kind: "emoji", emoji: "🦞" });
8+
expect(parseSessionIcon("👩🏽‍💻")).toEqual({ kind: "emoji", emoji: "👩🏽‍💻" });
9+
expect(parseSessionIcon("name:Nope")).toBeNull();
10+
expect(parseSessionIcon("🦞🚀")).toBeNull();
11+
expect(parseSessionIcon("A")).toBeNull();
12+
});
13+
14+
it("trims inputs and canonicalizes safe SVG markup", () => {
15+
expect(
16+
normalizeSessionIconInput(
17+
" svg:<svg viewBox='0 0 24 24'><g transform='translate(1 2)'><path d='M1 2' fill='currentColor'/></g></svg> ",
18+
),
19+
).toEqual({
20+
ok: true,
21+
value:
22+
'svg:<svg viewBox="0 0 24 24"><g transform="translate(1 2)"><path d="M1 2" fill="currentColor"/></g></svg>',
23+
});
24+
});
25+
26+
it.each([
27+
"svg:<svg><script>alert(1)</script></svg>",
28+
'svg:<svg onload="alert(1)"></svg>',
29+
'svg:<svg xmlns:xlink="http://www.w3.org/1999/xlink"><path xlink:href="#x"/></svg>',
30+
'svg:<svg><path fill="url(#paint)"/></svg>',
31+
"svg:<!DOCTYPE svg><svg></svg>",
32+
"svg:<svg></svg><svg></svg>",
33+
'svg:<svg><use href="#x"/></svg>',
34+
'svg:<svg><path style="fill:red"/></svg>',
35+
])("rejects hostile SVG: %s", (value) => {
36+
expect(normalizeSessionIconInput(value).ok).toBe(false);
37+
});
38+
39+
it("rejects SVG icons over 4096 bytes", () => {
40+
const value = `svg:<svg><title>${"x".repeat(4096)}</title></svg>`;
41+
expect(normalizeSessionIconInput(value)).toMatchObject({ ok: false });
42+
});
43+
});

0 commit comments

Comments
 (0)