refactor: give project monograms their own icon variant (#11993)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-09-15 17:06:56 -07:00
1 parent b12c92f695
commit 7a368fe7c4
9 files changed
+215 -98

No files matched your search

@@ -4371,14 +4371,19 @@ engineLayer("OrchestrationProjectionPipeline via engine dispatch", (it) => {
type: "project.meta.update",
commandId: CommandId.make("cmd-monogram-save"),
projectId,
projectIcon: { kind: "lucide", name: "folder-code", color: "violet", monogram: "T3" },
projectIcon: { kind: "monogram", text: "T3", color: "violet" },
});
const saved = yield* sql<{
readonly icon: string | null;
}>`SELECT project_icon_json AS icon FROM projection_projects WHERE project_id = ${projectId}`;
assert.deepEqual(saved, [
{ icon: '{"kind":"lucide","name":"folder-code","color":"violet","monogram":"T3"}' },
{ icon: '{"kind":"lucide","name":"folder-code","color":"violet","monogramText":"T3"}' },
]);
const persisted = yield* sql<{ readonly icon: string }>`
SELECT json_extract(payload_json, '$.projectIcon') AS icon FROM orchestration_events
WHERE command_id = ${CommandId.make("cmd-monogram-save")}
`;
assert.deepEqual(persisted, saved);
yield* engine.dispatch({
type: "project.meta.update",
commandId: CommandId.make("cmd-monogram-clear"),
@@ -248,6 +248,35 @@ it.layer(NodeServices.layer)("decider project scripts", (it) => {
name: "alarm-clock",
color: "violet",
});
for (const text of ["T3", "e\u0301", "किखि", "क्ष्म", "\u1100\u1161\u11a8"]) {
const monogram = { kind: "monogram", text, color: "violet" } as const;
const result = yield* decideOrchestrationCommand({
command: {
type: "project.meta.update",
commandId: CommandId.make("cmd-monogram"),
projectId: asProjectId("project-favicon"),
projectIcon: monogram,
},
readModel,
});
const updated = Array.isArray(result) ? result[0] : result;
expect(updated.payload).toMatchObject({ projectIcon: monogram });
}
for (const text of ["ABC", "किखिगि"]) {
const failure = yield* Effect.flip(
decideOrchestrationCommand({
command: {
type: "project.meta.update",
commandId: CommandId.make("cmd-monogram-invalid"),
projectId: asProjectId("project-favicon"),
projectIcon: { kind: "monogram", text, color: "violet" },
},
readModel,
}),
);
expect(failure).toMatchObject({ _tag: "OrchestrationCommandInvariantError" });
}
}),
);
+11
View File
@@ -47,6 +47,8 @@ import {
import { projectEvent } from "./projector.ts";
import { threadHasQueuedTurnStart } from "./ThreadSettlementPolicy.ts";
const monogramSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
const isScriptRunCommand = Schema.is(SCRIPT_RUN_COMMAND_PATTERN);
const nowIso = Effect.map(DateTime.now, DateTime.formatIso);
@@ -264,6 +266,15 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
command,
projectId: command.projectId,
});
if (
command.projectIcon?.kind === "monogram" &&
Array.from(monogramSegmenter.segment(command.projectIcon.text)).length > 2
) {
return yield* new OrchestrationCommandInvariantError({
commandType: command.type,
detail: "Project monograms must contain at most two characters.",
});
}
if (command.scripts !== undefined) {
// Persisted IDs predate shortcut validation. Let users edit or remove them
// without allowing another invalid ID to enter the project.
@@ -9,6 +9,7 @@ import {
OrchestrationEventMetadata,
OrchestrationEventType,
ProjectId,
ProjectIconOverride,
ThreadId,
} from "@t3tools/contracts";
import * as SqlClient from "effect/unstable/sql/SqlClient";
@@ -29,6 +30,7 @@ import {
type OrchestrationEventStoreShape,
} from "../Services/OrchestrationEventStore.ts";
const encodeProjectIcon = Schema.encodeSync(ProjectIconOverride);
const decodeEvent = Schema.decodeUnknownEffect(OrchestrationEvent);
const UnknownFromJsonString = Schema.fromJsonString(Schema.Unknown);
const EventMetadataFromJsonString = Schema.fromJsonString(OrchestrationEventMetadata);
@@ -263,7 +265,10 @@ const makeEventStore = Effect.gen(function* () {
actorKind: inferActorKind(event),
occurredAt: event.occurredAt,
commandId: event.commandId,
payloadJson: event.payload,
payloadJson:
"projectIcon" in event.payload && event.payload.projectIcon
? { ...event.payload, projectIcon: encodeProjectIcon(event.payload.projectIcon) }
: event.payload,
metadataJson: event.metadata,
}).pipe(
Effect.mapError(
+2 -2
View File
@@ -43,10 +43,10 @@ export function ProjectFavicon(input: {
faviconPath: project.faviconPath,
}),
);
if (project.projectIcon?.kind === "lucide" && project.projectIcon.monogram) {
if (project.projectIcon?.kind === "monogram") {
return (
<ProjectMonogram
text={project.projectIcon.monogram}
text={project.projectIcon.text}
color={project.projectIcon.color}
className={input.className}
/>
@@ -54,9 +54,7 @@ export function ProjectIconPickerDialog({
readonly onSelect: (icon: ProjectIconOverride) => void;
}) {
const automatic = deriveProjectIdentity(projectName);
const [mode, setMode] = useState<ProjectIconOverride["kind"] | "monogram">(
current?.kind === "lucide" && current.monogram ? "monogram" : (current?.kind ?? "lucide"),
);
const [mode, setMode] = useState<ProjectIconOverride["kind"]>(current?.kind ?? "lucide");
const [iconName, setIconName] = useState<IconName>(
current?.kind === "lucide" ? (current.name as IconName) : DEFAULT_ICON,
);
@@ -64,7 +62,7 @@ export function ProjectIconPickerDialog({
current && current.kind !== "emoji" ? current.color : automatic.color,
);
const [letters, setLetters] = useState(
current?.kind === "lucide" && current.monogram ? current.monogram : automatic.monogram,
current?.kind === "monogram" ? current.text : automatic.monogram,
);
const [emoji, setEmoji] = useState(current?.kind === "emoji" ? current.emoji : "💻");
const [query, setQuery] = useState("");
@@ -73,14 +71,10 @@ export function ProjectIconPickerDialog({
useEffect(() => {
if (open && !previousOpenRef.current) {
setMode(
current?.kind === "lucide" && current.monogram ? "monogram" : (current?.kind ?? "lucide"),
);
setMode(current?.kind ?? "lucide");
setIconName(current?.kind === "lucide" ? (current.name as IconName) : DEFAULT_ICON);
setColor(current && current.kind !== "emoji" ? current.color : automatic.color);
setLetters(
current?.kind === "lucide" && current.monogram ? current.monogram : automatic.monogram,
);
setLetters(current?.kind === "monogram" ? current.text : automatic.monogram);
setEmoji(current?.kind === "emoji" ? current.emoji : "💻");
setQuery("");
setCustomEmoji("");
@@ -96,7 +90,7 @@ export function ProjectIconPickerDialog({
if (mode === "monogram" && !validMonogram) return;
onSelect(
mode === "monogram"
? { kind: "lucide", name: DEFAULT_ICON, monogram, color }
? { kind: "monogram", text: monogram, color }
: mode === "lucide"
? { kind: "lucide", name: iconName, color }
: { kind: "emoji", emoji },
@@ -435,10 +435,12 @@ function ProjectDetail({
title="Project icon"
description={
projectIcon?.kind === "lucide"
? `${projectIcon.monogram ?? projectIcon.name} · ${projectIcon.color}`
: projectIcon?.kind === "emoji"
? projectIcon.emoji
: (faviconPath ?? "Automatic")
? `${projectIcon.name} · ${projectIcon.color}`
: projectIcon?.kind === "monogram"
? `${projectIcon.text} · ${projectIcon.color}`
: projectIcon?.kind === "emoji"
? projectIcon.emoji
: (faviconPath ?? "Automatic")
}
resetAction={
group.memberProjects.some(
+99 -42
View File
@@ -5,6 +5,7 @@ import * as Schema from "effect/Schema";
import { CommandId, ProjectId, ThreadId } from "./baseSchemas.ts";
import {
ProjectIconOverride,
DEFAULT_PROVIDER_INTERACTION_MODE,
DEFAULT_RUNTIME_MODE,
type ChatImageAttachment,
@@ -17,9 +18,8 @@ import {
OrchestrationGetTurnDiffInput,
OrchestrationLatestTurn,
ProjectCreatedPayload,
OrchestrationProjectShell,
ProjectIconColor,
ProjectMetaUpdatedPayload,
OrchestrationProjectShell,
OrchestrationProposedPlan,
OrchestrationSession,
OrchestrationThread,
@@ -42,18 +42,6 @@ import { ProviderInstanceId } from "./providerInstance.ts";
const decodeTurnDiffInput = Schema.decodeUnknownEffect(OrchestrationGetTurnDiffInput);
const decodeFullThreadDiffInput = Schema.decodeUnknownEffect(OrchestrationGetFullThreadDiffInput);
const decodeThreadTurnDiff = Schema.decodeUnknownEffect(ThreadTurnDiff);
// The icon shape understood by clients released before monograms.
const legacyProjectIcon = Schema.Union([
Schema.Struct({ kind: Schema.Literal("lucide"), name: Schema.String, color: ProjectIconColor }),
Schema.Struct({ kind: Schema.Literal("emoji"), emoji: Schema.String }),
]);
const decodeLegacyProjectShell = Schema.decodeUnknownEffect(
Schema.Struct({
...OrchestrationProjectShell.fields,
projectIcon: Schema.optional(Schema.NullOr(legacyProjectIcon)),
}),
);
const encodeProjectShell = Schema.encodeEffect(OrchestrationProjectShell);
const decodeProjectCreateCommand = Schema.decodeUnknownEffect(ProjectCreateCommand);
const decodeProjectCreatedPayload = Schema.decodeUnknownEffect(ProjectCreatedPayload);
const decodeProjectMetaUpdatedPayload = Schema.decodeUnknownEffect(ProjectMetaUpdatedPayload);
@@ -1508,31 +1496,13 @@ it.effect("project icon overrides accept Lucide icons, colors, and emoji", () =>
}),
);
it.effect("older clients decode monogram projects as their fallback icon", () =>
Effect.gen(function* () {
const encoded = yield* encodeProjectShell({
id: ProjectId.make("project-monogram"),
title: "Monogram",
workspaceRoot: "/tmp/monogram",
defaultModelSelection: null,
scripts: [],
createdAt: "2026-01-01T00:00:00.000Z",
updatedAt: "2026-01-01T00:00:00.000Z",
projectIcon: { kind: "lucide", name: "folder-code", color: "violet", monogram: "T3" },
});
const decoded = yield* decodeLegacyProjectShell(encoded);
assert.deepEqual(decoded.projectIcon, { kind: "lucide", name: "folder-code", color: "violet" });
}),
);
it.effect("project monograms validate text and palette colors", () =>
Effect.gen(function* () {
for (const text of ["A", "T3", "É", "文書", "कि", "किखि", "e\u0301"]) {
const projectIcon = {
kind: "lucide",
name: "folder-code",
kind: "monogram",
color: "violet",
monogram: text,
text,
} as const;
const command = yield* decodeOrchestrationCommand({
type: "project.meta.update",
@@ -1542,16 +1512,14 @@ it.effect("project monograms validate text and palette colors", () =>
});
assert.strictEqual(command.type, "project.meta.update");
if (command.type === "project.meta.update")
assert.deepEqual(command.projectIcon, projectIcon);
assert.deepEqual(command.projectIcon, { kind: "monogram", text, color: "violet" });
}
for (const projectIcon of [
{ kind: "lucide", name: "folder-code", monogram: "", color: "blue" },
{ kind: "lucide", name: "folder-code", monogram: "ABC", color: "blue" },
{ kind: "lucide", name: "folder-code", monogram: "किखिगि", color: "blue" },
{ kind: "lucide", name: "folder-code", monogram: "\u0301", color: "blue" },
{ kind: "lucide", name: "folder-code", monogram: "A B", color: "blue" },
{ kind: "lucide", name: "folder-code", monogram: "🚀", color: "blue" },
{ kind: "lucide", name: "folder-code", monogram: "T3", color: "ultraviolet" },
{ kind: "monogram", text: "", color: "blue" },
{ kind: "monogram", text: "\u0301", color: "blue" },
{ kind: "monogram", text: "A B", color: "blue" },
{ kind: "monogram", text: "🚀", color: "blue" },
{ kind: "monogram", text: "T3", color: "ultraviolet" },
]) {
const result = yield* Effect.exit(
decodeOrchestrationCommand({
@@ -1586,3 +1554,92 @@ it("isProviderSendTurnSupportedImageMimeType accepts raster formats and rejects
assert.strictEqual(isProviderSendTurnSupportedImageMimeType("IMAGE/JPEG"), true);
assert.strictEqual(isProviderSendTurnSupportedImageMimeType("image/svg+xml"), false);
});
const decodeProjectIcon = Schema.decodeUnknownEffect(ProjectIconOverride);
const encodeProjectIcon = Schema.encodeEffect(ProjectIconOverride);
// Pre-monogram clients reject unknown variants; nightly clients additionally validate monogram.
const decodeOldIcon = Schema.decodeUnknownEffect(
Schema.Union([
Schema.Struct({ kind: Schema.Literal("lucide"), name: Schema.String, color: Schema.String }),
Schema.Struct({ kind: Schema.Literal("emoji"), emoji: Schema.String }),
]),
);
const decodeNightlyIcon = Schema.decodeUnknownEffect(
Schema.Union([
Schema.Struct({
kind: Schema.Literal("lucide"),
name: Schema.String,
color: Schema.String,
// Fail if this field is ever sent; old validators must never see the new text.
monogram: Schema.optional(Schema.Never),
}),
Schema.Struct({ kind: Schema.Literal("emoji"), emoji: Schema.String }),
]),
);
it.effect("sends monograms as fallback icons that old and nightly clients can decode", () =>
Effect.gen(function* () {
const fallback = { kind: "lucide", name: "folder-code", color: "violet" } as const;
for (const text of ["T3", "क्ष्म", "e\u0301"]) {
const monogram = { kind: "monogram", text, color: "violet" } as const;
const wire = yield* encodeProjectIcon(monogram);
assert.deepEqual(wire, { ...fallback, monogramText: text });
assert.deepEqual(yield* decodeOldIcon(wire), fallback);
assert.deepEqual(yield* decodeNightlyIcon(wire), fallback);
assert.deepEqual(yield* decodeProjectIcon(wire), monogram);
assert.deepEqual(yield* decodeProjectIcon(monogram), monogram);
assert.deepEqual(yield* decodeProjectIcon({ ...fallback, monogram: text }), monogram);
}
for (const icon of [
{ kind: "lucide", name: "alarm-clock", color: "blue" },
{ kind: "emoji", emoji: "🚀" },
] as const) {
assert.deepEqual(yield* decodeProjectIcon(icon), icon);
assert.deepEqual(yield* encodeProjectIcon(icon), icon);
}
}),
);
const encodeProjectShell = Schema.encodeEffect(OrchestrationProjectShell);
const encodeClientCommand = Schema.encodeEffect(ClientOrchestrationCommand);
const decodeLegacyShell = Schema.decodeUnknownEffect(
Schema.Struct({
...OrchestrationProjectShell.fields,
projectIcon: Schema.optional(
Schema.NullOr(
Schema.Struct({
kind: Schema.Literal("lucide"),
name: Schema.String,
color: Schema.String,
}),
),
),
}),
);
it.effect("encodes compatible icons inside snapshots and client commands", () =>
Effect.gen(function* () {
const projectIcon = { kind: "monogram", text: "क्ष्म", color: "violet" } as const;
const shell = yield* encodeProjectShell({
id: ProjectId.make("monogram"),
title: "Monogram",
workspaceRoot: "/tmp/monogram",
defaultModelSelection: null,
scripts: [],
projectIcon,
createdAt: "2026-01-01T00:00:00.000Z",
updatedAt: "2026-01-01T00:00:00.000Z",
});
const fallback = { kind: "lucide", name: "folder-code", color: "violet" } as const;
assert.deepEqual((yield* decodeLegacyShell(shell)).projectIcon, fallback);
const command = yield* encodeClientCommand({
type: "project.meta.update",
projectId: ProjectId.make("monogram"),
commandId: CommandId.make("monogram"),
projectIcon,
});
if (command.type !== "project.meta.update") throw new Error("Unexpected command");
assert.deepEqual(yield* decodeNightlyIcon(command.projectIcon), fallback);
}),
);
+50 -36
View File
@@ -459,48 +459,62 @@ const ProjectLucideIconName = TrimmedNonEmptyString.check(
const ProjectEmoji = TrimmedNonEmptyString.check(Schema.isMaxLength(32));
// Hermes (the Android/iOS JS runtime) has no Intl.Segmenter, and this module
// loads at app startup, so `new Intl.Segmenter()` crashes mobile on launch.
// Count grapheme clusters with a small approximation instead: a code point
// continues the current cluster when it is a combining mark, joiner,
// variation selector, or emoji modifier, or follows a ZWJ. This must stay
// runtime-independent (not `typeof Intl.Segmenter` feature detection) so the
// shared contract validates identically on server, web, and mobile.
const GRAPHEME_CONTINUATION = /[\p{M}\u200c\u200d\ufe0f\u{1F3FB}-\u{1F3FF}]/u;
const countGraphemes = (text: string): number => {
let clusters = 0;
let prevJoiner = false;
for (const char of text) {
if (clusters > 0 && (prevJoiner || GRAPHEME_CONTINUATION.test(char))) {
prevJoiner = char === "\u200d";
continue;
}
clusters += 1;
prevJoiner = char === "\u200d";
}
return clusters;
};
// Grapheme-count validation belongs to the server command boundary, not snapshot decoding.
export const ProjectMonogramText = TrimmedNonEmptyString.check(
Schema.isMaxLength(32),
Schema.isPattern(/^[\p{L}\p{N}][\p{L}\p{N}\p{M}\u200c\u200d]*$/u),
Schema.makeFilter((text) => countGraphemes(text) <= 2),
);
const ProjectLucideIcon = Schema.Struct({
kind: Schema.Literal("lucide"),
name: ProjectLucideIconName,
color: ProjectIconColor,
});
const ProjectEmojiIcon = Schema.Struct({
kind: Schema.Literal("emoji"),
emoji: ProjectEmoji,
});
const ProjectMonogramIcon = Schema.Struct({
kind: Schema.Literal("monogram"),
text: ProjectMonogramText,
color: ProjectIconColor,
});
const ProjectIcon = Schema.Union([ProjectLucideIcon, ProjectEmojiIcon, ProjectMonogramIcon]);
const ProjectLucideIconWire = Schema.Struct({
...ProjectLucideIcon.fields,
monogramText: Schema.optional(ProjectMonogramText),
monogram: Schema.optional(ProjectMonogramText),
});
// Older peers only know lucide/emoji. Keep monograms out of their validated
// `monogram` field too: old grapheme counters can reject otherwise valid text.
export const ProjectIconOverride = Schema.Union([
Schema.Struct({
kind: Schema.Literal("lucide"),
name: ProjectLucideIconName,
color: ProjectIconColor,
// Older clients ignore this field and render the named Lucide icon instead.
monogram: Schema.optional(ProjectMonogramText),
}),
Schema.Struct({
kind: Schema.Literal("emoji"),
emoji: ProjectEmoji,
}),
]);
ProjectLucideIconWire,
ProjectEmojiIcon,
ProjectMonogramIcon,
]).pipe(
Schema.decodeTo(
ProjectIcon,
SchemaTransformation.transform({
decode: (icon): typeof ProjectIcon.Type => {
if (icon.kind !== "lucide") return icon;
const text = icon.monogramText ?? icon.monogram;
return text === undefined
? { kind: "lucide", name: icon.name, color: icon.color }
: { kind: "monogram", text, color: icon.color };
},
encode: (icon) =>
icon.kind === "monogram"
? {
kind: "lucide" as const,
name: "folder-code",
color: icon.color,
monogramText: icon.text,
}
: icon,
}),
),
);
export type ProjectIconOverride = typeof ProjectIconOverride.Type;
export const OrchestrationProject = Schema.Struct({