Skip to content

Commit e9d6e3b

Browse files
fix: preserve legacy project icon wire compatibility
1 parent 59b473f commit e9d6e3b

4 files changed

Lines changed: 118 additions & 13 deletions

File tree

‎apps/server/src/orchestration/Layers/ProjectionPipeline.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4376,7 +4376,9 @@ engineLayer("OrchestrationProjectionPipeline via engine dispatch", (it) => {
43764376
const saved = yield* sql<{
43774377
readonly icon: string | null;
43784378
}>`SELECT project_icon_json AS icon FROM projection_projects WHERE project_id = ${projectId}`;
4379-
assert.deepEqual(saved, [{ icon: '{"kind":"monogram","text":"T3","color":"violet"}' }]);
4379+
assert.deepEqual(saved, [
4380+
{ icon: '{"kind":"lucide","name":"folder-code","color":"violet","monogramText":"T3"}' },
4381+
]);
43804382
const persisted = yield* sql<{ readonly icon: string }>`
43814383
SELECT json_extract(payload_json, '$.projectIcon') AS icon FROM orchestration_events
43824384
WHERE command_id = ${CommandId.make("cmd-monogram-save")}

‎apps/server/src/persistence/Layers/OrchestrationEventStore.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
OrchestrationEventMetadata,
1010
OrchestrationEventType,
1111
ProjectId,
12+
ProjectIconOverride,
1213
ThreadId,
1314
} from "@t3tools/contracts";
1415
import * as SqlClient from "effect/unstable/sql/SqlClient";
@@ -29,6 +30,7 @@ import {
2930
type OrchestrationEventStoreShape,
3031
} from "../Services/OrchestrationEventStore.ts";
3132

33+
const encodeProjectIcon = Schema.encodeSync(ProjectIconOverride);
3234
const decodeEvent = Schema.decodeUnknownEffect(OrchestrationEvent);
3335
const UnknownFromJsonString = Schema.fromJsonString(Schema.Unknown);
3436
const EventMetadataFromJsonString = Schema.fromJsonString(OrchestrationEventMetadata);
@@ -263,7 +265,10 @@ const makeEventStore = Effect.gen(function* () {
263265
actorKind: inferActorKind(event),
264266
occurredAt: event.occurredAt,
265267
commandId: event.commandId,
266-
payloadJson: event.payload,
268+
payloadJson:
269+
"projectIcon" in event.payload && event.payload.projectIcon
270+
? { ...event.payload, projectIcon: encodeProjectIcon(event.payload.projectIcon) }
271+
: event.payload,
267272
metadataJson: event.metadata,
268273
}).pipe(
269274
Effect.mapError(

‎packages/contracts/src/orchestration.test.ts‎

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
OrchestrationLatestTurn,
2020
ProjectCreatedPayload,
2121
ProjectMetaUpdatedPayload,
22+
OrchestrationProjectShell,
2223
OrchestrationProposedPlan,
2324
OrchestrationSession,
2425
OrchestrationThread,
@@ -1557,22 +1558,88 @@ it("isProviderSendTurnSupportedImageMimeType accepts raster formats and rejects
15571558
const decodeProjectIcon = Schema.decodeUnknownEffect(ProjectIconOverride);
15581559
const encodeProjectIcon = Schema.encodeEffect(ProjectIconOverride);
15591560

1560-
it.effect("ignores legacy monogram fields and preserves standalone icon variants", () =>
1561+
// Pre-monogram clients reject unknown variants; nightly clients additionally validate monogram.
1562+
const decodeOldIcon = Schema.decodeUnknownEffect(
1563+
Schema.Union([
1564+
Schema.Struct({ kind: Schema.Literal("lucide"), name: Schema.String, color: Schema.String }),
1565+
Schema.Struct({ kind: Schema.Literal("emoji"), emoji: Schema.String }),
1566+
]),
1567+
);
1568+
const decodeNightlyIcon = Schema.decodeUnknownEffect(
1569+
Schema.Union([
1570+
Schema.Struct({
1571+
kind: Schema.Literal("lucide"),
1572+
name: Schema.String,
1573+
color: Schema.String,
1574+
// Fail if this field is ever sent; old validators must never see the new text.
1575+
monogram: Schema.optional(Schema.Never),
1576+
}),
1577+
Schema.Struct({ kind: Schema.Literal("emoji"), emoji: Schema.String }),
1578+
]),
1579+
);
1580+
1581+
it.effect("sends monograms as fallback icons that old and nightly clients can decode", () =>
15611582
Effect.gen(function* () {
15621583
const fallback = { kind: "lucide", name: "folder-code", color: "violet" } as const;
1563-
for (const monogram of ["T3", "", { invalid: true }]) {
1564-
const decoded = yield* decodeProjectIcon({ ...fallback, monogram });
1565-
assert.deepEqual(decoded, fallback);
1566-
assert.deepEqual(yield* encodeProjectIcon(decoded), fallback);
1584+
for (const text of ["T3", "क्ष्म", "e\u0301"]) {
1585+
const monogram = { kind: "monogram", text, color: "violet" } as const;
1586+
const wire = yield* encodeProjectIcon(monogram);
1587+
assert.deepEqual(wire, { ...fallback, monogramText: text });
1588+
assert.deepEqual(yield* decodeOldIcon(wire), fallback);
1589+
assert.deepEqual(yield* decodeNightlyIcon(wire), fallback);
1590+
assert.deepEqual(yield* decodeProjectIcon(wire), monogram);
1591+
assert.deepEqual(yield* decodeProjectIcon(monogram), monogram);
1592+
assert.deepEqual(yield* decodeProjectIcon({ ...fallback, monogram: text }), monogram);
15671593
}
15681594
for (const icon of [
1569-
{ kind: "monogram", text: "T3", color: "violet" },
15701595
{ kind: "lucide", name: "alarm-clock", color: "blue" },
15711596
{ kind: "emoji", emoji: "🚀" },
15721597
] as const) {
1573-
const decoded = yield* decodeProjectIcon(icon);
1574-
assert.deepEqual(decoded, icon);
1575-
assert.deepEqual(yield* encodeProjectIcon(decoded), icon);
1598+
assert.deepEqual(yield* decodeProjectIcon(icon), icon);
1599+
assert.deepEqual(yield* encodeProjectIcon(icon), icon);
15761600
}
15771601
}),
15781602
);
1603+
1604+
const encodeProjectShell = Schema.encodeEffect(OrchestrationProjectShell);
1605+
const encodeClientCommand = Schema.encodeEffect(ClientOrchestrationCommand);
1606+
const decodeLegacyShell = Schema.decodeUnknownEffect(
1607+
Schema.Struct({
1608+
...OrchestrationProjectShell.fields,
1609+
projectIcon: Schema.optional(
1610+
Schema.NullOr(
1611+
Schema.Struct({
1612+
kind: Schema.Literal("lucide"),
1613+
name: Schema.String,
1614+
color: Schema.String,
1615+
}),
1616+
),
1617+
),
1618+
}),
1619+
);
1620+
1621+
it.effect("encodes compatible icons inside snapshots and client commands", () =>
1622+
Effect.gen(function* () {
1623+
const projectIcon = { kind: "monogram", text: "क्ष्म", color: "violet" } as const;
1624+
const shell = yield* encodeProjectShell({
1625+
id: ProjectId.make("monogram"),
1626+
title: "Monogram",
1627+
workspaceRoot: "/tmp/monogram",
1628+
defaultModelSelection: null,
1629+
scripts: [],
1630+
projectIcon,
1631+
createdAt: "2026-01-01T00:00:00.000Z",
1632+
updatedAt: "2026-01-01T00:00:00.000Z",
1633+
});
1634+
const fallback = { kind: "lucide", name: "folder-code", color: "violet" } as const;
1635+
assert.deepEqual((yield* decodeLegacyShell(shell)).projectIcon, fallback);
1636+
const command = yield* encodeClientCommand({
1637+
type: "project.meta.update",
1638+
projectId: ProjectId.make("monogram"),
1639+
commandId: CommandId.make("monogram"),
1640+
projectIcon,
1641+
});
1642+
if (command.type !== "project.meta.update") throw new Error("Unexpected command");
1643+
assert.deepEqual(yield* decodeNightlyIcon(command.projectIcon), fallback);
1644+
}),
1645+
);

‎packages/contracts/src/orchestration.ts‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,42 @@ const ProjectMonogramIcon = Schema.Struct({
479479
text: ProjectMonogramText,
480480
color: ProjectIconColor,
481481
});
482+
const ProjectIcon = Schema.Union([ProjectLucideIcon, ProjectEmojiIcon, ProjectMonogramIcon]);
483+
const ProjectLucideIconWire = Schema.Struct({
484+
...ProjectLucideIcon.fields,
485+
monogramText: Schema.optional(ProjectMonogramText),
486+
monogram: Schema.optional(ProjectMonogramText),
487+
});
488+
489+
// Older peers only know lucide/emoji. Keep monograms out of their validated
490+
// `monogram` field too: old grapheme counters can reject otherwise valid text.
482491
export const ProjectIconOverride = Schema.Union([
483-
ProjectLucideIcon,
492+
ProjectLucideIconWire,
484493
ProjectEmojiIcon,
485494
ProjectMonogramIcon,
486-
]);
495+
]).pipe(
496+
Schema.decodeTo(
497+
ProjectIcon,
498+
SchemaTransformation.transform({
499+
decode: (icon): typeof ProjectIcon.Type => {
500+
if (icon.kind !== "lucide") return icon;
501+
const text = icon.monogramText ?? icon.monogram;
502+
return text === undefined
503+
? { kind: "lucide", name: icon.name, color: icon.color }
504+
: { kind: "monogram", text, color: icon.color };
505+
},
506+
encode: (icon) =>
507+
icon.kind === "monogram"
508+
? {
509+
kind: "lucide" as const,
510+
name: "folder-code",
511+
color: icon.color,
512+
monogramText: icon.text,
513+
}
514+
: icon,
515+
}),
516+
),
517+
);
487518
export type ProjectIconOverride = typeof ProjectIconOverride.Type;
488519

489520
export const OrchestrationProject = Schema.Struct({

0 commit comments

Comments
 (0)