diff --git a/src/main/runtime/rpc/methods/client-ui-schemas.ts b/src/main/runtime/rpc/methods/client-ui-schemas.ts index 7265a1ee8..6b8862b1e 100644 --- a/src/main/runtime/rpc/methods/client-ui-schemas.ts +++ b/src/main/runtime/rpc/methods/client-ui-schemas.ts @@ -13,7 +13,9 @@ import { isTaskProvider } from '../../../../shared/task-providers' import { normalizeDisabledTuiAgents } from '../../../../shared/tui-agent-selection' import { normalizePRBotAuthorOverrides } from '../../../../shared/pr-bot-author-overrides' import { normalizeWorktreeCardProperties } from '../../../../shared/worktree-card-properties' -import type { TaskProvider } from '../../../../shared/types' +import type { PersistedUIState, TaskProvider } from '../../../../shared/types' +import { TaskResumeState } from './task-resume-state-schema' +import type { AssertNoMissingKeys } from './ui-state-schema-parity' const NullableString = z.string().nullable() const StringArray = z.array(z.string()) @@ -59,16 +61,6 @@ const WorkspaceStatusDefinition = z.object({ color: z.string().optional(), icon: z.string().optional() }) -const TaskResumeState = z - .object({ - githubMode: z.enum(['items', 'project']).optional(), - githubItemsPreset: z.string().nullable().optional(), - githubItemsQuery: z.string().optional(), - githubProjectHiddenFieldIdsByView: z.record(z.string(), z.array(z.string())).optional(), - linearPreset: z.enum(['assigned', 'created', 'all', 'completed']).optional(), - linearQuery: z.string().optional() - }) - .strict() const WorkspaceCleanupDismissal = z .object({ worktreeId: z.string(), @@ -173,6 +165,21 @@ export const UiUpdate = z .object({ lastActiveRepoId: NullableString.optional(), lastActiveWorktreeId: NullableString.optional(), + // Why: App.tsx persists this on every top-level view switch (#9002). Desktop + // hydration ignores it on 'sync' broadcasts, so accepting it cannot yank a + // paired window's current view — it only restores the view on next startup. + activeView: z + .enum([ + 'terminal', + 'settings', + 'tasks', + 'activity', + 'automations', + 'space', + 'skills', + 'mobile' + ]) + .optional(), sidebarWidth: z.number().finite().optional(), rightSidebarOpen: z.boolean().optional(), rightSidebarTab: z @@ -197,6 +204,9 @@ export const UiUpdate = z .optional(), hideDefaultBranchWorkspace: z.boolean().optional(), hideAutomationGeneratedWorkspaces: z.boolean().optional(), + // Why: rides App.tsx's debounced writer, so omitting it rejected that entire + // payload (sidebar widths, filters, agent acks) for every paired client. + showDotfilesByWorktree: z.record(z.string(), z.boolean()).optional(), hideCliCreatedWorkspaces: z.boolean().optional(), hideDetachedHeadWorkspaces: z.boolean().optional(), filterRepoIds: StringArray.optional(), @@ -253,6 +263,14 @@ export const UiUpdate = z _inlineAgentsDefaultedForAllUsers: z.boolean().optional(), trustedOrcaHooks: z.record(z.string(), z.unknown()).optional(), setupScriptPromptDismissedRepoIds: StringArray.optional(), + // Why: one-shot dismissals the renderer writes through ui.set; each was a + // whole-payload rejection for paired clients while unlisted. + setupGuideSidebarDismissed: z.boolean().optional(), + setupGuideBrowserMilestoneMigrated: z.boolean().optional(), + setupGuideBrowserMilestoneLegacyComplete: z.boolean().optional(), + browserImportHintHidden: z.boolean().optional(), + mobileEmulatorTabIntroDismissed: z.boolean().optional(), + mobileEmulatorAgentSetupDismissed: z.boolean().optional(), projectOrderManualDefaultNoticeDismissed: z.boolean().optional(), usagePercentageDisplayChangeNoticeDismissed: z.boolean().optional(), usageEmptyStateDismissed: z.boolean().optional(), @@ -273,3 +291,23 @@ export const UiUpdate = z }) .strict() .default({}) + +// Why: state only the main process ever writes (store.updateUI, star-nag's own +// IPC, window lifecycle). Clients never send these, so keeping them out of the +// strict schema is deliberate — but it must stay deliberate rather than +// forgotten, which is what the parity assertion below enforces. +type MainOwnedUIState = + | 'trayMinimizeNoticeShown' + | 'dashboardPopoutBounds' + | '_expandedWorktreeCardPropertiesDefaulted' + | 'starNagBaselineAgents' + | 'starNagAppVersion' + | 'starNagNextThreshold' + | 'starNagCompleted' + | 'starNagDeferredUntil' + | 'starNagAgentValueMomentAppVersion' +const _uiUpdateParity: AssertNoMissingKeys< + Omit, + z.infer +> = true +void _uiUpdateParity diff --git a/src/main/runtime/rpc/methods/client-ui.test.ts b/src/main/runtime/rpc/methods/client-ui.test.ts index 4accec2b0..03b0f6987 100644 --- a/src/main/runtime/rpc/methods/client-ui.test.ts +++ b/src/main/runtime/rpc/methods/client-ui.test.ts @@ -437,7 +437,16 @@ describe('client UI RPC methods', () => { githubItemsQuery: 'is:open', githubProjectHiddenFieldIdsByView: { 'project-1:view-1': ['field-1'] - } + }, + linearMode: 'projects', + linearContext: { + kind: 'project', + id: 'project-9', + workspaceId: 'workspace-1', + model: 'project' + }, + jiraPreset: 'assigned', + jiraQuery: 'ENG' }, workspaceCleanup: { dismissals: { @@ -479,7 +488,16 @@ describe('client UI RPC methods', () => { githubItemsQuery: 'is:open', githubProjectHiddenFieldIdsByView: { 'project-1:view-1': ['field-1'] - } + }, + linearMode: 'projects', + linearContext: { + kind: 'project', + id: 'project-9', + workspaceId: 'workspace-1', + model: 'project' + }, + jiraPreset: 'assigned', + jiraQuery: 'ENG' }, workspaceCleanup: { dismissals: { @@ -510,6 +528,80 @@ describe('client UI RPC methods', () => { expect(response).toMatchObject({ ok: true, result: { ui: updated } }) }) + // Why one case per field: the schema is strict, so a single unlisted key makes + // the dispatcher reject the ENTIRE ui.set payload with invalid_argument instead + // of stripping it. A combined payload would pass as soon as any one field were + // restored, hiding the rest of the drift. + it.each([ + ['taskResumeState.linearMode', { taskResumeState: { linearMode: 'projects' } }], + [ + 'taskResumeState.linearContext', + { + taskResumeState: { + linearContext: { kind: 'project', id: 'project-9', workspaceId: 'workspace-1' } + } + } + ], + ['taskResumeState.jiraPreset', { taskResumeState: { jiraPreset: 'assigned' } }], + ['taskResumeState.jiraQuery', { taskResumeState: { jiraQuery: 'ENG' } }], + ['activeView', { activeView: 'tasks' }], + ['showDotfilesByWorktree', { showDotfilesByWorktree: { 'repo::/worktree': true } }], + ['setupGuideSidebarDismissed', { setupGuideSidebarDismissed: true }], + ['setupGuideBrowserMilestoneMigrated', { setupGuideBrowserMilestoneMigrated: true }], + [ + 'setupGuideBrowserMilestoneLegacyComplete', + { setupGuideBrowserMilestoneLegacyComplete: true } + ], + ['browserImportHintHidden', { browserImportHintHidden: true }], + ['mobileEmulatorTabIntroDismissed', { mobileEmulatorTabIntroDismissed: true }], + ['mobileEmulatorAgentSetupDismissed', { mobileEmulatorAgentSetupDismissed: true }] + ])('accepts %s, which the renderer persists through ui.set', async (_label, payload) => { + const runtime = { + getRuntimeId: () => 'test-runtime', + updateUIState: vi.fn(() => getDefaultUIState()) + } as unknown as OrcaRuntimeService + const dispatcher = new RpcDispatcher({ runtime, methods: CLIENT_UI_METHODS }) + + const response = await dispatcher.dispatch(makeRequest('ui.set', payload)) + + expect(response).toMatchObject({ ok: true }) + expect(runtime.updateUIState).toHaveBeenCalledWith(payload) + }) + + it('accepts the whole debounced App writer payload', async () => { + const runtime = { + getRuntimeId: () => 'test-runtime', + updateUIState: vi.fn(() => getDefaultUIState()) + } as unknown as OrcaRuntimeService + const dispatcher = new RpcDispatcher({ runtime, methods: CLIENT_UI_METHODS }) + // Mirrors App.tsx's 150ms writer: one unlisted key here dropped every other + // preference in the same call for paired web/SSH/relay clients. + const payload = { + sidebarWidth: 280, + rightSidebarOpen: true, + rightSidebarTab: 'explorer', + rightSidebarExplorerView: 'files', + rightSidebarWidth: 320, + markdownTocPanelWidth: 200, + groupBy: 'repo', + sortBy: 'smart', + projectOrderBy: 'manual', + showActiveOnly: false, + hideSleepingWorkspaces: false, + showSleepingWorkspaces: true, + hideDefaultBranchWorkspace: false, + hideAutomationGeneratedWorkspaces: false, + showDotfilesByWorktree: { 'repo::/worktree': true }, + filterRepoIds: ['repo-1'], + acknowledgedAgentsByPaneKey: { 'pane-1': 123 } + } + + const response = await dispatcher.dispatch(makeRequest('ui.set', payload)) + + expect(response).toMatchObject({ ok: true }) + expect(runtime.updateUIState).toHaveBeenCalledWith(payload) + }) + it('records a feature interaction through the runtime host', async () => { const updated: PersistedUIState = { ...getDefaultUIState(), diff --git a/src/main/runtime/rpc/methods/task-resume-state-schema.ts b/src/main/runtime/rpc/methods/task-resume-state-schema.ts new file mode 100644 index 000000000..825248ac4 --- /dev/null +++ b/src/main/runtime/rpc/methods/task-resume-state-schema.ts @@ -0,0 +1,33 @@ +import { z } from 'zod' +import type { TaskResumeState as TaskResumeStateType } from '../../../../shared/types' +import type { AssertNoMissingKeys } from './ui-state-schema-parity' + +/** Tasks page-position state persisted through `ui.set`; mirrors `TaskResumeState`. */ +export const TaskResumeState = z + .object({ + githubMode: z.enum(['items', 'project']).optional(), + githubItemsPreset: z.string().nullable().optional(), + githubItemsQuery: z.string().optional(), + githubProjectHiddenFieldIdsByView: z.record(z.string(), z.array(z.string())).optional(), + linearMode: z.enum(['issues', 'projects', 'views']).optional(), + linearPreset: z.enum(['assigned', 'created', 'all', 'completed']).optional(), + linearQuery: z.string().optional(), + linearContext: z + .object({ + kind: z.enum(['project', 'view']), + id: z.string(), + workspaceId: z.string(), + model: z.enum(['issue', 'project']).optional() + }) + .strict() + .optional(), + jiraPreset: z.enum(['assigned', 'reported', 'all', 'done']).optional(), + jiraQuery: z.string().optional() + }) + .strict() + +const _taskResumeStateParity: AssertNoMissingKeys< + TaskResumeStateType, + z.infer +> = true +void _taskResumeStateParity diff --git a/src/main/runtime/rpc/methods/ui-state-schema-parity.ts b/src/main/runtime/rpc/methods/ui-state-schema-parity.ts new file mode 100644 index 000000000..5ed5e5d91 --- /dev/null +++ b/src/main/runtime/rpc/methods/ui-state-schema-parity.ts @@ -0,0 +1,14 @@ +/** + * The client-facing UI schemas are `.strict()`, so Zod rejects an unlisted key + * instead of stripping it — the dispatcher then fails the WHOLE `ui.set` payload + * with `invalid_argument`. A field added to `PersistedUIState`/`TaskResumeState` + * without a matching schema entry therefore silently breaks every paired + * web/mobile/relay client while desktop (schema-less `ui:set` IPC) stays green. + * + * Assigning `true` to this type turns that runtime drift into a typecheck error + * that names the missing key. + */ +export type AssertNoMissingKeys> = + Exclude extends never + ? true + : { missingFromSchema: Exclude }