From 4e1665997fb94bb1f9a06d5ce4141abbd2c1c1c1 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Sun, 8 Nov 2026 21:44:58 -0800 Subject: [PATCH] chore: exempt seam field-name constants from the layout-writer ratchet; drop dead setters (F4) The seam's SEAM_*_FIELDS lists name fields without writing them, so the ratchet skips them and the raised baseline row is gone (renderer total 569, main 571). setStructuredChatSleptAt and the two launch-directory setters lost their last callers to the batched companion write. Co-Authored-By: Claude Opus 5.5 (1M context) --- config/renderer-layout-writer-baseline.txt | 1 - .../check-layout-writer-ratchets.mjs | 21 ++++++++- ...uctured-chat-activity-status-live.test.tsx | 18 ++++++-- .../agent-status/structured-chat-slept-at.ts | 12 +---- .../structured-session-launch-directories.ts | 45 +------------------ 5 files changed, 39 insertions(+), 58 deletions(-) diff --git a/config/renderer-layout-writer-baseline.txt b/config/renderer-layout-writer-baseline.txt index 99f9a704d14..ab5f8339b03 100644 --- a/config/renderer-layout-writer-baseline.txt +++ b/config/renderer-layout-writer-baseline.txt @@ -45,7 +45,6 @@ 1 src/renderer/src/runtime/web-session-tabs-sync/inventory/web-runtime-session-snapshot.ts 3 src/renderer/src/runtime/web-session-tabs-sync/placement/web-session-client-owned-tab-placement.ts 2 src/renderer/src/runtime/web-session-tabs-sync/session-tabs-inventory-absence.ts -7 src/renderer/src/store/seam-record-fields.ts # names the transition seam's tracked fields once; no layout write 10 src/renderer/src/store/slices/browser/cleanup/browser-close-actions.ts 2 src/renderer/src/store/slices/browser/create-browser-slice.ts 1 src/renderer/src/store/slices/browser/hydration/browser-hydration-state.ts diff --git a/config/scripts/static-analysis/ratchets/renderer-state/check-layout-writer-ratchets.mjs b/config/scripts/static-analysis/ratchets/renderer-state/check-layout-writer-ratchets.mjs index 29b0247827e..009f48c981c 100644 --- a/config/scripts/static-analysis/ratchets/renderer-state/check-layout-writer-ratchets.mjs +++ b/config/scripts/static-analysis/ratchets/renderer-state/check-layout-writer-ratchets.mjs @@ -320,6 +320,24 @@ function isSameNameCopy(property, name) { return ts.isPropertyAccessExpression(value) && value.name.text === name } +// The transition seam names the fields it tracks in `const SEAM_*_FIELDS = [...] as const` lists; names, not writes. +function isSeamFieldNameConstant(literal) { + let list = literal.parent + if (!ts.isArrayLiteralExpression(list)) { + return false + } + let declaration = list.parent + while (ts.isAsExpression(declaration) || ts.isSatisfiesExpression(declaration)) { + declaration = declaration.parent + } + return ( + ts.isVariableDeclaration(declaration) && + ts.isIdentifier(declaration.name) && + /^SEAM_[A-Z_]+_FIELDS$/.test(declaration.name.text) && + (declaration.parent.flags & ts.NodeFlags.Const) !== 0 + ) +} + /** Layout writes in one file under one ratchet's rules. */ export function countLayoutWrites(sourceText, ratchet, fileName = 'file.tsx') { const names = [...ratchet.writerNames, ...ratchet.assignedFields] @@ -392,7 +410,8 @@ export function countLayoutWrites(sourceText, ratchet, fileName = 'file.tsx') { node.parent.expression.expression.text === 'Object' && node.parent.expression.name.text === 'hasOwn' ) && - !ts.isLiteralTypeNode(node.parent) + !ts.isLiteralTypeNode(node.parent) && + !isSeamFieldNameConstant(node) ) { count += 1 } diff --git a/src/renderer/src/components/sidebar/workspace-card/activity/structured-chat-activity-status-live.test.tsx b/src/renderer/src/components/sidebar/workspace-card/activity/structured-chat-activity-status-live.test.tsx index b38141f4ad9..ae65b41dda2 100644 --- a/src/renderer/src/components/sidebar/workspace-card/activity/structured-chat-activity-status-live.test.tsx +++ b/src/renderer/src/components/sidebar/workspace-card/activity/structured-chat-activity-status-live.test.tsx @@ -106,11 +106,23 @@ describe.each(['sidebar', 'parent picker', 'palette'])( expect(chatStatusLabels()).toEqual(['inactive']) const tab = useAppStore.getState().unifiedTabsByWorktree[TARGET_WORKTREE_ID][0] const paneKey = structuredAgentSessionPaneKey(tab.id, tab.entityId) - act(() => useAppStore.getState().setStructuredChatSleptAt(paneKey, undefined)) + act(() => + useAppStore + .getState() + .applyStructuredChatCompanionWrites([{ kind: 'slept-at', paneKey, sleptAt: undefined }]) + ) expect(chatStatusLabels()).toEqual(['active']) - act(() => useAppStore.getState().setStructuredChatSleptAt(paneKey, 1)) + act(() => + useAppStore + .getState() + .applyStructuredChatCompanionWrites([{ kind: 'slept-at', paneKey, sleptAt: 1 }]) + ) expect(chatStatusLabels()).toEqual(['inactive']) - act(() => useAppStore.getState().setStructuredChatSleptAt(paneKey, null)) + act(() => + useAppStore + .getState() + .applyStructuredChatCompanionWrites([{ kind: 'slept-at', paneKey, sleptAt: null }]) + ) expect(chatStatusLabels()).toEqual(['active']) const working: AgentStatusEntry = { paneKey, diff --git a/src/renderer/src/store/slices/agent-status/structured-chat-slept-at.ts b/src/renderer/src/store/slices/agent-status/structured-chat-slept-at.ts index ccb4b247673..885fa0aa8dd 100644 --- a/src/renderer/src/store/slices/agent-status/structured-chat-slept-at.ts +++ b/src/renderer/src/store/slices/agent-status/structured-chat-slept-at.ts @@ -10,7 +10,6 @@ export type StructuredChatSleptAtByPaneKey = Readonly void } const EMPTY_SLEPT_CHATS: StructuredChatSleptAtByPaneKey = Object.freeze({}) @@ -71,13 +70,6 @@ export const createStructuredChatSleptAtSlice: StateCreator< [], [], StructuredChatSleptAtSlice -> = (set) => ({ - structuredChatSleptAtByPaneKey: {}, - setStructuredChatSleptAt: (paneKey, sleptAt) => - set((state) => { - const next = withStructuredChatSleptAt(state.structuredChatSleptAtByPaneKey, paneKey, sleptAt) - return next === state.structuredChatSleptAtByPaneKey - ? state - : { structuredChatSleptAtByPaneKey: next } - }) +> = () => ({ + structuredChatSleptAtByPaneKey: {} }) diff --git a/src/renderer/src/store/slices/agent-status/structured-session-launch-directories.ts b/src/renderer/src/store/slices/agent-status/structured-session-launch-directories.ts index 023c0c71da9..f02196a209a 100644 --- a/src/renderer/src/store/slices/agent-status/structured-session-launch-directories.ts +++ b/src/renderer/src/store/slices/agent-status/structured-session-launch-directories.ts @@ -10,13 +10,6 @@ export type StructuredSessionLaunchDirectory = { /** Mirror host-pinned chat directories; absent uses workspace resolution except floating chats, which remain unknown until pinned. */ export type StructuredSessionLaunchDirectorySlice = { structuredSessionLaunchDirectoryByTabId: Record - setStructuredSessionLaunchDirectory: ( - tabId: string, - sessionId: string, - launchDirectory: string | undefined - ) => void - /** Only drops the entry while it still belongs to `sessionId`. */ - clearStructuredSessionLaunchDirectory: (tabId: string, sessionId: string) => void } type LaunchDirectoriesByTabId = Record @@ -50,45 +43,11 @@ export function withoutStructuredSessionLaunchDirectory( return byTabId[tabId]?.sessionId === sessionId ? withoutTab(byTabId, tabId) : byTabId } -function launchDirectoriesPatch( - state: AppState, - next: LaunchDirectoriesByTabId -): Partial | AppState { - return next === state.structuredSessionLaunchDirectoryByTabId - ? state - : { structuredSessionLaunchDirectoryByTabId: next } -} - export const createStructuredSessionLaunchDirectorySlice: StateCreator< AppState, [], [], StructuredSessionLaunchDirectorySlice -> = (set) => ({ - structuredSessionLaunchDirectoryByTabId: {}, - setStructuredSessionLaunchDirectory: (tabId, sessionId, launchDirectory) => { - set((state) => - launchDirectoriesPatch( - state, - withStructuredSessionLaunchDirectory( - state.structuredSessionLaunchDirectoryByTabId, - tabId, - sessionId, - launchDirectory - ) - ) - ) - }, - clearStructuredSessionLaunchDirectory: (tabId, sessionId) => { - set((state) => - launchDirectoriesPatch( - state, - withoutStructuredSessionLaunchDirectory( - state.structuredSessionLaunchDirectoryByTabId, - tabId, - sessionId - ) - ) - ) - } +> = () => ({ + structuredSessionLaunchDirectoryByTabId: {} })