From 01a1dec61894747108f905f83d1feee399d21748 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 5 Aug 2026 16:29:54 +0200 Subject: [PATCH] fix: port main fixes stranded by the v2 rewrite - Port thread pinning (#5312) into the orchestration-v2 command pipeline: thread.pin/unpin commands, thread.pinned/unpinned events, pinnedAt on the v2 thread state and projected shells, promotion semantics (pin clears settle/snooze, settle clears pin) matching the v1 decider, and client pin/unpin operations in the v2 dispatch style. - Port the regenerated-title context anchoring (#5365) into ThreadTitleRegenerationService: pin the first user message ahead of the retained tail when the digest is truncated. - Re-apply the right-panel controls positioning from #5260 to the v2 ChatView title bar controls. - Repair merge artifacts: committed conflict markers in BranchToolbar, duplicate capability keys, duplicate CommandPalette import, v1 turn naming in DiffPanel's focus-refresh effect, onSend signature merge. Co-Authored-By: Claude Fable 5 --- .../src/environment/ServerEnvironment.ts | 1 - .../src/orchestration-v2/Orchestrator.ts | 46 +++++- .../orchestration-v2/ProjectionMaintenance.ts | 2 + .../src/orchestration-v2/ProjectionStore.ts | 8 ++ .../ThreadTitleRegenerationService.test.ts | 23 ++- .../ThreadTitleRegenerationService.ts | 133 +++++++++++++----- .../testkit/OrchestratorScenario.ts | 2 + apps/web/src/components/BranchToolbar.tsx | 8 -- apps/web/src/components/ChatView.tsx | 13 +- apps/web/src/components/CommandPalette.tsx | 1 - apps/web/src/components/DiffPanel.tsx | 12 +- .../client-runtime/src/operations/commands.ts | 23 ++- packages/client-runtime/src/state/models.ts | 2 + .../src/state/orchestrationV2Projection.ts | 2 + packages/contracts/src/environment.ts | 3 - packages/contracts/src/orchestrationV2.ts | 19 +++ 16 files changed, 233 insertions(+), 65 deletions(-) diff --git a/apps/server/src/environment/ServerEnvironment.ts b/apps/server/src/environment/ServerEnvironment.ts index a2b84dad8b..f2037df7b8 100644 --- a/apps/server/src/environment/ServerEnvironment.ts +++ b/apps/server/src/environment/ServerEnvironment.ts @@ -153,7 +153,6 @@ export const make = Effect.gen(function* () { threadPinReorder: true, threadTitleRegeneration: true, threadVisitedTracking: true, - threadTitleRegeneration: true, ...(serverSelfUpdate === null ? {} : { serverSelfUpdate }), ...(serverSelfUpdate === "boot-service" ? { serverSelfUpdateProgress: true } : {}), }, diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 93e983e4fd..17ec6290fb 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -195,6 +195,8 @@ function commandThreadId(command: OrchestrationV2Command): ThreadId { case "thread.unsettle": case "thread.snooze": case "thread.unsnooze": + case "thread.pin": + case "thread.unpin": case "thread.visit": case "thread.mark-unread": case "thread.metadata.update": @@ -1342,6 +1344,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio | "thread.unsettle" | "thread.snooze" | "thread.unsnooze" + | "thread.pin" + | "thread.unpin" | "thread.visit" | "thread.mark-unread" | "thread.metadata.update" @@ -1401,7 +1405,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio (command.type === "thread.settle" || command.type === "thread.unsettle" || command.type === "thread.snooze" || - command.type === "thread.unsnooze") && + command.type === "thread.unsnooze" || + command.type === "thread.pin" || + command.type === "thread.unpin") && thread.archivedAt !== null ) { return yield* new OrchestratorDispatchError({ @@ -1514,11 +1520,16 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio updatedAt: now, }; case "thread.settle": { - const alreadySettled = thread.settledOverride === "settled" && thread.settledAt !== null; + // Settling is "I'm done with this": it clears a pin the same way it + // parks the thread (mirrors the v1 decider's settle/pin exclusion). + const wasPinned = thread.pinnedAt != null; + const alreadySettled = + thread.settledOverride === "settled" && thread.settledAt !== null && !wasPinned; return { ...thread, settledOverride: "settled", settledAt: alreadySettled ? thread.settledAt : now, + pinnedAt: null, updatedAt: alreadySettled ? thread.updatedAt : now, }; } @@ -1553,6 +1564,31 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio updatedAt: alreadyAwake ? thread.updatedAt : now, }; } + case "thread.pin": { + // Pinning is a promotion: it clears the parked states rather than + // silently outranking them — an explicit settle is un-settled and a + // snooze's return ticket is spent (the thread is on top NOW). + const alreadyPinned = thread.pinnedAt != null; + const promotes = thread.settledOverride === "settled" || thread.snoozedUntil != null; + return { + ...thread, + pinnedAt: alreadyPinned ? thread.pinnedAt : now, + settledOverride: + thread.settledOverride === "settled" ? "active" : thread.settledOverride, + settledAt: thread.settledOverride === "settled" ? null : thread.settledAt, + snoozedUntil: null, + snoozedAt: null, + updatedAt: alreadyPinned && !promotes ? thread.updatedAt : now, + }; + } + case "thread.unpin": { + const alreadyUnpinned = thread.pinnedAt == null; + return { + ...thread, + pinnedAt: null, + updatedAt: alreadyUnpinned ? thread.updatedAt : now, + }; + } // Visited tracking records read state only; it must not bump updatedAt, // otherwise viewing a thread would count as activity (and re-trigger the // clients that dispatch thread.visit whenever updatedAt advances). @@ -1620,6 +1656,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio return "thread.snoozed" as const; case "thread.unsnooze": return "thread.unsnoozed" as const; + case "thread.pin": + return "thread.pinned" as const; + case "thread.unpin": + return "thread.unpinned" as const; case "thread.visit": return "thread.visited" as const; case "thread.mark-unread": @@ -6650,6 +6690,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio case "thread.unsettle": case "thread.snooze": case "thread.unsnooze": + case "thread.pin": + case "thread.unpin": case "thread.visit": case "thread.mark-unread": case "thread.metadata.update": diff --git a/apps/server/src/orchestration-v2/ProjectionMaintenance.ts b/apps/server/src/orchestration-v2/ProjectionMaintenance.ts index ed72769ac2..8ec03f9117 100644 --- a/apps/server/src/orchestration-v2/ProjectionMaintenance.ts +++ b/apps/server/src/orchestration-v2/ProjectionMaintenance.ts @@ -230,6 +230,8 @@ export const layer: Layer.Layer< "thread.unsettled", "thread.snoozed", "thread.unsnoozed", + "thread.pinned", + "thread.unpinned", "thread.metadata-updated", "thread.runtime-mode-updated", "thread.interaction-mode-updated", diff --git a/apps/server/src/orchestration-v2/ProjectionStore.ts b/apps/server/src/orchestration-v2/ProjectionStore.ts index 29d59b08bd..783f338ed7 100644 --- a/apps/server/src/orchestration-v2/ProjectionStore.ts +++ b/apps/server/src/orchestration-v2/ProjectionStore.ts @@ -206,6 +206,8 @@ export function applyToProjection( case "thread.unsettled": case "thread.snoozed": case "thread.unsnoozed": + case "thread.pinned": + case "thread.unpinned": case "thread.metadata-updated": case "thread.runtime-mode-updated": case "thread.interaction-mode-updated": @@ -896,6 +898,7 @@ export function threadShellFromProjection( settledAt: projection.thread.settledAt, snoozedUntil: projection.thread.snoozedUntil ?? null, snoozedAt: projection.thread.snoozedAt ?? null, + pinnedAt: projection.thread.pinnedAt ?? null, lastVisitedAt: projection.thread.lastVisitedAt, titleRegeneration: projection.thread.titleRegeneration ?? null, deletedAt: projection.thread.deletedAt, @@ -1065,6 +1068,7 @@ function shellFromState(input: { settledAt: input.state.thread.settledAt, snoozedUntil: input.state.thread.snoozedUntil ?? null, snoozedAt: input.state.thread.snoozedAt ?? null, + pinnedAt: input.state.thread.pinnedAt ?? null, lastVisitedAt: input.state.thread.lastVisitedAt, titleRegeneration: input.state.thread.titleRegeneration ?? null, deletedAt: input.state.thread.deletedAt, @@ -1087,6 +1091,8 @@ export const layer: Layer.Layer = case "thread.unsettled": case "thread.snoozed": case "thread.unsnoozed": + case "thread.pinned": + case "thread.unpinned": case "thread.visited": case "thread.marked-unread": case "thread.metadata-updated": @@ -1886,6 +1892,8 @@ export const layer: Layer.Layer = event.type !== "thread.unsettled" && event.type !== "thread.snoozed" && event.type !== "thread.unsnoozed" && + event.type !== "thread.pinned" && + event.type !== "thread.unpinned" && event.type !== "thread.visited" && event.type !== "thread.marked-unread" && event.type !== "thread.metadata-updated" && diff --git a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts index c1f929db14..c7056ae72e 100644 --- a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts @@ -173,15 +173,26 @@ describe("formatThreadTitleContext", () => { ); }); - it("marks truncation once older content stops fitting the budget", () => { + it("pins the first user message ahead of the retained tail once content stops fitting", () => { const context = formatThreadTitleContext([ - { role: "user", text: `Ancient context that no longer fits ${"x".repeat(600)}` }, + { role: "user", text: `Ancient context that anchors the topic ${"x".repeat(600)}` }, { role: "assistant", text: "y".repeat(6_000) }, { role: "user", text: "z".repeat(1_500) }, ]); - assert.isTrue(context.message.startsWith("[Earlier content truncated]\n\n")); - assert.isFalse(context.message.includes("Ancient context")); - assert.isTrue(context.message.includes("ASSISTANT:")); + assert.isTrue(context.message.startsWith("USER:\nAncient context that anchors the topic")); + assert.isTrue(context.message.includes("[Earlier content truncated]\n\n")); + assert.isTrue(context.message.includes("y".repeat(100))); + }); + + it("truncates an oversized pinned first user message", () => { + const context = formatThreadTitleContext([ + { role: "user", text: `Topic anchor ${"a".repeat(4_000)}` }, + { role: "assistant", text: "y".repeat(9_000) }, + { role: "user", text: "z".repeat(1_500) }, + ]); + assert.isTrue(context.message.startsWith("USER:\nTopic anchor")); + assert.isTrue(context.message.includes("[First user message truncated]")); + assert.isTrue(context.message.includes("[Earlier content truncated]\n\n")); }); it("retains at most four attachments from the newest messages", () => { @@ -195,7 +206,7 @@ describe("formatThreadTitleContext", () => { ]); assert.deepEqual( context.attachments.map((entry) => entry.name), - ["c.png", "d.png", "e.png", "a.png"], + ["b.png", "c.png", "d.png", "e.png"], ); }); }); diff --git a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts index b955c160ce..c94f590054 100644 --- a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts +++ b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts @@ -20,62 +20,127 @@ import { ThreadManagementService } from "./ThreadManagementService.ts"; const MAX_REGENERATION_ATTACHMENTS = 4; const MAX_THREAD_TITLE_CONTEXT_CHARS = 8_000; +const MAX_FIRST_USER_TITLE_CONTEXT_CHARS = 2_000; const THREAD_TITLE_CONTEXT_TRUNCATION_MARKER = "[Earlier content truncated]\n\n"; +const FIRST_USER_CONTEXT_TRUNCATION_MARKER = "\n[First user message truncated]"; -/** - * Newest-first conversation digest for the title prompt: walk messages from - * the end, keep whole sections while they fit the char budget, and mark - * truncation once older content stops fitting. Ported from the v1 reactor's - * regeneration flow. - */ -export function formatThreadTitleContext( - messages: ReadonlyArray<{ - readonly role: "user" | "assistant" | "system"; - readonly text: string; - readonly attachments?: ReadonlyArray | undefined; - }>, +type ThreadTitleMessage = { + readonly role: "user" | "assistant" | "system"; + readonly text: string; + readonly attachments?: ReadonlyArray | undefined; +}; + +function formatThreadTitleSection(message: ThreadTitleMessage): string | undefined { + if (message.role === "system") { + return undefined; + } + const text = message.text.trim(); + const attachmentSummary = (message.attachments ?? []) + .map((attachment) => attachment.name) + .join(", "); + const contents = [ + ...(text.length > 0 ? [text] : []), + ...(attachmentSummary.length > 0 ? [`[Attachments: ${attachmentSummary}]`] : []), + ].join("\n"); + return contents.length > 0 ? `${message.role.toUpperCase()}:\n${contents}` : undefined; +} + +function limitFirstUserSection(section: string): string { + if (section.length <= MAX_FIRST_USER_TITLE_CONTEXT_CHARS) { + return section; + } + return `${section.slice( + 0, + MAX_FIRST_USER_TITLE_CONTEXT_CHARS - FIRST_USER_CONTEXT_TRUNCATION_MARKER.length, + )}${FIRST_USER_CONTEXT_TRUNCATION_MARKER}`; +} + +function collectRecentThreadTitleContext( + messages: ReadonlyArray, + maxChars: number, ): { - readonly message: string; + readonly context: string; readonly attachments: ReadonlyArray; + readonly truncated: boolean; } { let context = ""; let truncated = false; const retainedAttachments: Array = []; for (const message of messages.toReversed()) { - if (message.role === "system") { - continue; - } - const text = message.text.trim(); - const attachmentSummary = (message.attachments ?? []) - .map((attachment) => attachment.name) - .join(", "); - const contents = [ - ...(text.length > 0 ? [text] : []), - ...(attachmentSummary.length > 0 ? [`[Attachments: ${attachmentSummary}]`] : []), - ].join("\n"); - if (contents.length === 0) { + const section = formatThreadTitleSection(message); + if (section === undefined) { continue; } - const section = `${message.role.toUpperCase()}:\n${contents}`; const separator = context.length > 0 ? "\n\n" : ""; - const available = MAX_THREAD_TITLE_CONTEXT_CHARS - context.length - separator.length; + const available = maxChars - context.length - separator.length; if (section.length > available) { + if (available > 0) { + context = `${section.slice(-available)}${separator}${context}`; + retainedAttachments.unshift(...(message.attachments ?? [])); + } truncated = true; break; } context = `${section}${separator}${context}`; - for (const attachment of message.attachments ?? []) { - if (retainedAttachments.length < MAX_REGENERATION_ATTACHMENTS) { - retainedAttachments.push(attachment); - } - } + retainedAttachments.unshift(...(message.attachments ?? [])); } + return { context, attachments: retainedAttachments, truncated }; +} + +/** + * Conversation digest for the title prompt. Recent messages fill the budget + * newest-first; when the conversation no longer fits, the first user message + * is pinned ahead of the recent tail so regenerated titles stay anchored to + * what the thread is actually about. Mirrors the v1 reactor's flow (#5365). + */ +export function formatThreadTitleContext(messages: ReadonlyArray): { + readonly message: string; + readonly attachments: ReadonlyArray; +} { + const recent = collectRecentThreadTitleContext(messages, MAX_THREAD_TITLE_CONTEXT_CHARS); + if (!recent.truncated) { + return { + message: recent.context, + attachments: recent.attachments.slice(-MAX_REGENERATION_ATTACHMENTS), + }; + } + + const firstUserMessage = messages.find( + (message) => message.role === "user" && formatThreadTitleSection(message), + ); + const firstUserSection = firstUserMessage + ? formatThreadTitleSection(firstUserMessage) + : undefined; + if (!firstUserMessage || !firstUserSection) { + return { + message: `${THREAD_TITLE_CONTEXT_TRUNCATION_MARKER}${recent.context}`, + attachments: recent.attachments.slice(-MAX_REGENERATION_ATTACHMENTS), + }; + } + + const pinnedSection = limitFirstUserSection(firstUserSection); + const recentContextBudget = + MAX_THREAD_TITLE_CONTEXT_CHARS - + pinnedSection.length - + "\n\n".length - + THREAD_TITLE_CONTEXT_TRUNCATION_MARKER.length; + const retainedRecent = collectRecentThreadTitleContext(messages, recentContextBudget); + const pinnedAttachment = firstUserMessage.attachments?.[0]; + const recentAttachments = retainedRecent.attachments.filter( + (attachment) => attachment.id !== pinnedAttachment?.id, + ); + return { - message: truncated ? `${THREAD_TITLE_CONTEXT_TRUNCATION_MARKER}${context}` : context, - attachments: retainedAttachments, + message: `${pinnedSection}\n\n${THREAD_TITLE_CONTEXT_TRUNCATION_MARKER}${retainedRecent.context}`, + attachments: [ + ...(pinnedAttachment ? [pinnedAttachment] : []), + ...recentAttachments.slice( + -(MAX_REGENERATION_ATTACHMENTS - (pinnedAttachment === undefined ? 0 : 1)), + ), + ], }; } diff --git a/apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts b/apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts index 81d0c81a89..7d4c629824 100644 --- a/apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts +++ b/apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts @@ -105,6 +105,8 @@ function commandThreadIds(command: OrchestrationV2Command): ReadonlyArray -<<<<<<< HEAD {isMobile && showGitControls ? ( -======= -======= -
->>>>>>> 2152c2ebce (fix: reconcile rebase with latest main) - {isMobile ? ( ->>>>>>> 0c15987295 (fix: reconcile rebase with latest main) void }, + dispatchMode: ComposerDispatchMode = "auto", directAnnotation?: { annotation: PreviewAnnotationPayload; image: ComposerImageAttachment | null; }, - dispatchMode: ComposerDispatchMode = "auto", ) => { e?.preventDefault(); const notifyDirectAnnotationAttached = () => { @@ -6075,7 +6075,7 @@ function ChatViewContent(props: ChatViewProps) { configuredUrls={configuredPreviewUrls} visible onSendAnnotation={(annotation, image) => { - void onSend(undefined, { annotation, image }); + void onSend(undefined, "auto", { annotation, image }); }} /> @@ -6235,7 +6235,14 @@ function ChatViewContent(props: ChatViewProps) {
); const panelLayoutControls = ( -
+
{rightPanelOpen && !shouldUsePlanSidebarSheet ? ( (null); const lastCompletedTurnRefreshRef = useRef<{ readonly threadKey: string | null; - readonly turnId: TurnId | null; + readonly runId: RunId | null; } | null>(null); const routeThreadRef = useParams({ @@ -276,7 +276,7 @@ export default function DiffPanel({ : primaryBranchDiffPreview; const refreshBranchDiffPreview = branchDiffPreview.refresh; const canRefreshGitDiff = - isGitRepo && selectedTurnId === null && activeThread != null && activeCwd != null; + isGitRepo && selectedRunId === null && activeThread != null && activeCwd != null; const activeThreadRefreshKey = routeThreadRef ? `${routeThreadRef.environmentId}:${routeThreadRef.threadId}` : null; @@ -291,7 +291,7 @@ export default function DiffPanel({ useEffect(() => { const current = { threadKey: activeThreadRefreshKey, - turnId: latestTurn?.turnId ?? null, + runId: latestTurn?.runId ?? null, }; const previous = lastCompletedTurnRefreshRef.current; if (!canRefreshGitDiff) { @@ -301,17 +301,17 @@ export default function DiffPanel({ lastCompletedTurnRefreshRef.current = current; return; } - if (previous.turnId === current.turnId) return; + if (previous.runId === current.runId) return; refreshBranchDiffPreview(); lastCompletedTurnRefreshRef.current = current; - }, [activeThreadRefreshKey, canRefreshGitDiff, latestTurn?.turnId, refreshBranchDiffPreview]); + }, [activeThreadRefreshKey, canRefreshGitDiff, latestTurn?.runId, refreshBranchDiffPreview]); const selectedGitSource = branchDiffPreview.data?.sources.find( (source) => source.kind === (selectedGitScope === "unstaged" ? "working-tree" : "branch-range"), ); const loadDiffFiles = useMemo(() => { const preview = branchDiffPreview.data; - if (selectedTurnId !== null || !activeThread || !preview || !selectedGitSource) { + if (selectedRunId !== null || !activeThread || !preview || !selectedGitSource) { return undefined; } diff --git a/packages/client-runtime/src/operations/commands.ts b/packages/client-runtime/src/operations/commands.ts index b652025c13..536cd00f69 100644 --- a/packages/client-runtime/src/operations/commands.ts +++ b/packages/client-runtime/src/operations/commands.ts @@ -77,6 +77,9 @@ export interface UnsettleThreadInput extends ThreadCommandInput { readonly reason: "user"; } +export type PinThreadInput = ThreadCommandInput; +export type UnpinThreadInput = ThreadCommandInput; + export interface SnoozeThreadInput extends ThreadCommandInput { readonly snoozedUntil: string; } @@ -340,7 +343,13 @@ export const createThread = Effect.fn("EnvironmentCommands.createThread")(functi }); function simpleThreadCommand( - type: "thread.delete" | "thread.archive" | "thread.unarchive" | "thread.settle", + type: + | "thread.delete" + | "thread.archive" + | "thread.unarchive" + | "thread.settle" + | "thread.pin" + | "thread.unpin", input: ThreadCommandInput, ) { return allocateCommandId(input).pipe( @@ -372,6 +381,18 @@ export const settleThread = Effect.fn("EnvironmentCommands.settleThread")(functi return yield* simpleThreadCommand("thread.settle", input); }); +export const pinThread = Effect.fn("EnvironmentCommands.pinThread")(function* ( + input: PinThreadInput, +) { + return yield* simpleThreadCommand("thread.pin", input); +}); + +export const unpinThread = Effect.fn("EnvironmentCommands.unpinThread")(function* ( + input: UnpinThreadInput, +) { + return yield* simpleThreadCommand("thread.unpin", input); +}); + export const unsettleThread = Effect.fn("EnvironmentCommands.unsettleThread")(function* ( input: UnsettleThreadInput, ) { diff --git a/packages/client-runtime/src/state/models.ts b/packages/client-runtime/src/state/models.ts index 78c2529d16..6060811568 100644 --- a/packages/client-runtime/src/state/models.ts +++ b/packages/client-runtime/src/state/models.ts @@ -95,6 +95,7 @@ export interface EnvironmentThreadShell { readonly settledAt: string | null; readonly snoozedUntil: string | null; readonly snoozedAt: string | null; + readonly pinnedAt: string | null; /** * Server-tracked visited watermark. `undefined` means the environment's * server predates visited tracking and clients should fall back to any @@ -197,6 +198,7 @@ export function presentThreadShell( settledAt: nullableIso(thread.settledAt), snoozedUntil: nullableIso(thread.snoozedUntil ?? null), snoozedAt: nullableIso(thread.snoozedAt ?? null), + pinnedAt: nullableIso(thread.pinnedAt ?? null), ...(thread.lastVisitedAt === undefined ? {} : { lastVisitedAt: nullableIso(thread.lastVisitedAt) }), diff --git a/packages/client-runtime/src/state/orchestrationV2Projection.ts b/packages/client-runtime/src/state/orchestrationV2Projection.ts index 22ce61f313..8ca83a590f 100644 --- a/packages/client-runtime/src/state/orchestrationV2Projection.ts +++ b/packages/client-runtime/src/state/orchestrationV2Projection.ts @@ -112,6 +112,8 @@ export function applyOrchestrationV2ProjectionEvent( case "thread.unsettled": case "thread.snoozed": case "thread.unsnoozed": + case "thread.pinned": + case "thread.unpinned": case "thread.metadata-updated": case "thread.runtime-mode-updated": case "thread.interaction-mode-updated": diff --git a/packages/contracts/src/environment.ts b/packages/contracts/src/environment.ts index 51dd302457..5749b92ec6 100644 --- a/packages/contracts/src/environment.ts +++ b/packages/contracts/src/environment.ts @@ -72,9 +72,6 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({ threadSettlement: clients keep their local visited state against servers that lack this. */ threadVisitedTracking: Schema.optionalKey(Schema.Boolean), - /** Server understands regenerateTitle on thread.meta.update. Absent on - older servers, so clients hide the action instead of sending it. */ - threadTitleRegeneration: Schema.optionalKey(Schema.Boolean), /** The update path clients should offer for this server. Absent on servers that must be relaunched manually (dev checkouts, Windows foreground runs, pre-update servers). */ diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index 906ba2b4a9..dba88aee2d 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -324,6 +324,7 @@ export const OrchestrationV2AppThread = Schema.Struct({ ), snoozedUntil: Schema.optional(Schema.NullOr(Schema.DateTimeUtc)), snoozedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtc)), + pinnedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtc)), lastVisitedAt: Schema.NullOr(Schema.DateTimeUtc).pipe( Schema.withDecodingDefault(Effect.succeed(null)), ), @@ -1079,6 +1080,8 @@ export const OrchestrationV2DomainEvent = Schema.Union([ "thread.unsettled", "thread.snoozed", "thread.unsnoozed", + "thread.pinned", + "thread.unpinned", "thread.visited", "thread.marked-unread", "thread.metadata-updated", @@ -1272,6 +1275,8 @@ export const OrchestrationV2ThreadShell = Schema.Struct({ settledAt: Schema.NullOr(Schema.DateTimeUtc), snoozedUntil: Schema.optional(Schema.NullOr(Schema.DateTimeUtc)), snoozedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtc)), + /** Omitted by servers that predate thread pinning. */ + pinnedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtc)), /** * Omitted by servers that predate server-side visited tracking; clients fall * back to their local visited state when the field is absent. @@ -1360,6 +1365,7 @@ export const OrchestrationV2AppThreadJson = OrchestrationV2AppThread.mapFields(( ), snoozedUntil: Schema.optional(Schema.NullOr(Schema.DateTimeUtcFromString)), snoozedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtcFromString)), + pinnedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtcFromString)), lastVisitedAt: Schema.NullOr(Schema.DateTimeUtcFromString).pipe( Schema.withDecodingDefault(Effect.succeed(null)), ), @@ -1742,6 +1748,7 @@ export const OrchestrationV2ThreadShellJson = OrchestrationV2ThreadShell.mapFiel settledAt: Schema.NullOr(Schema.DateTimeUtcFromString), snoozedUntil: Schema.optional(Schema.NullOr(Schema.DateTimeUtcFromString)), snoozedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtcFromString)), + pinnedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtcFromString)), lastVisitedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtcFromString)), deletedAt: Schema.NullOr(Schema.DateTimeUtcFromString), })); @@ -1785,6 +1792,8 @@ export const OrchestrationV2DomainEventJson = Schema.Union([ "thread.unsettled", "thread.snoozed", "thread.unsnoozed", + "thread.pinned", + "thread.unpinned", "thread.visited", "thread.marked-unread", "thread.metadata-updated", @@ -1957,6 +1966,16 @@ export const OrchestrationV2Command = Schema.Union([ threadId: ThreadId, reason: Schema.Literal("user"), }), + Schema.Struct({ + type: Schema.Literal("thread.pin"), + commandId: CommandId, + threadId: ThreadId, + }), + Schema.Struct({ + type: Schema.Literal("thread.unpin"), + commandId: CommandId, + threadId: ThreadId, + }), Schema.Struct({ type: Schema.Literal("thread.visit"), commandId: CommandId,