diff --git a/src/engines/SessionCore/core/atoms/actions.simulatorPreview.ts b/src/engines/SessionCore/core/atoms/actions.simulatorPreview.ts index 0d4b3fff9d..df14ebd11e 100644 --- a/src/engines/SessionCore/core/atoms/actions.simulatorPreview.ts +++ b/src/engines/SessionCore/core/atoms/actions.simulatorPreview.ts @@ -6,6 +6,7 @@ * the authoritative Rust snapshot arrives. Extracted from actions.ts. */ import { isLiveRuntimeResourceEvent } from "../runningEventGate"; +import { getFallbackSimulatorEventFilterCategory } from "../simulatorEventFilterCategory"; import type { SessionEvent, SimulatorEventPreview } from "../types"; /** @@ -34,33 +35,6 @@ export function isSimulatorVisibleApprox(event: SessionEvent): boolean { ); } -function getSimulatorFilterCategory( - event: SessionEvent -): SimulatorEventPreview["filterCategory"] { - if (event.source === "user") return "key_interactions"; - if ( - event.uiCanonical === "edit_file" || - event.uiCanonical === "delete_file" - ) { - return "file_changes"; - } - if (event.command || event.uiCanonical === "run_shell") { - return "terminal_events"; - } - if ( - event.uiCanonical === "read_file" || - event.uiCanonical === "list_dir" || - event.uiCanonical === "code_search" || - event.uiCanonical === "glob" || - event.uiCanonical === "find_files" || - event.uiCanonical === "search" - ) { - return "explore"; - } - if (event.filePath) return "file_changes"; - return "other"; -} - function buildSimulatorPreview(event: SessionEvent): SimulatorEventPreview { return { id: event.id, @@ -74,7 +48,7 @@ function buildSimulatorPreview(event: SessionEvent): SimulatorEventPreview { displayStatus: event.displayStatus, displayVariant: event.displayVariant, activityStatus: event.activityStatus, - filterCategory: getSimulatorFilterCategory(event), + filterCategory: getFallbackSimulatorEventFilterCategory(event), threadId: event.threadId, processId: event.processId, callId: event.callId, diff --git a/src/engines/SessionCore/core/simulatorEventFilterCategory.ts b/src/engines/SessionCore/core/simulatorEventFilterCategory.ts new file mode 100644 index 0000000000..e224681bd0 --- /dev/null +++ b/src/engines/SessionCore/core/simulatorEventFilterCategory.ts @@ -0,0 +1,42 @@ +import type { SessionEvent, SimulatorEventFilterValue } from "./types"; + +export const SIMULATOR_EVENT_FILTER_VALUES = [ + "key_interactions", + "file_changes", + "terminal_events", + "explore", + "other", +] as const satisfies readonly SimulatorEventFilterValue[]; + +/** + * Canonical fallback category used by every local simulator preview path. + * The backend-projected category remains authoritative once its snapshot + * arrives; this function keeps optimistic and materialized local previews in + * lockstep until then. + */ +export function getFallbackSimulatorEventFilterCategory( + event: SessionEvent +): SimulatorEventFilterValue { + if (event.source === "user") return "key_interactions"; + if ( + event.uiCanonical === "edit_file" || + event.uiCanonical === "delete_file" + ) { + return "file_changes"; + } + if (event.command || event.uiCanonical === "run_shell") { + return "terminal_events"; + } + if ( + event.uiCanonical === "read_file" || + event.uiCanonical === "list_dir" || + event.uiCanonical === "code_search" || + event.uiCanonical === "glob" || + event.uiCanonical === "find_files" || + event.uiCanonical === "search" + ) { + return "explore"; + } + if (event.filePath) return "file_changes"; + return "other"; +} diff --git a/src/engines/SessionCore/core/store/snapshotMaterialization.simulatorPreview.ts b/src/engines/SessionCore/core/store/snapshotMaterialization.simulatorPreview.ts index 6d9a3161f2..fe998c289d 100644 --- a/src/engines/SessionCore/core/store/snapshotMaterialization.simulatorPreview.ts +++ b/src/engines/SessionCore/core/store/snapshotMaterialization.simulatorPreview.ts @@ -7,40 +7,10 @@ * objects are cached by event object identity so events untouched by a * delta reuse their preview across materializations. */ -import type { - SessionEvent, - SimulatorEventFilterValue, - SimulatorEventPreview, -} from "../types"; +import { getFallbackSimulatorEventFilterCategory } from "../simulatorEventFilterCategory"; +import type { SessionEvent, SimulatorEventPreview } from "../types"; import type { NormalizedSnapshotCache } from "./EventStoreProxyTypes"; -function getFallbackFilterCategory( - event: SessionEvent -): SimulatorEventFilterValue { - if (event.source === "user") return "key_interactions"; - if ( - event.uiCanonical === "edit_file" || - event.uiCanonical === "delete_file" - ) { - return "file_changes"; - } - if (event.command || event.uiCanonical === "run_shell") { - return "terminal_events"; - } - if ( - event.uiCanonical === "read_file" || - event.uiCanonical === "list_dir" || - event.uiCanonical === "code_search" || - event.uiCanonical === "glob" || - event.uiCanonical === "find_files" || - event.uiCanonical === "search" - ) { - return "explore"; - } - if (event.filePath) return "file_changes"; - return "other"; -} - function buildSimulatorEventPreview( event: SessionEvent ): SimulatorEventPreview { @@ -56,7 +26,7 @@ function buildSimulatorEventPreview( displayStatus: event.displayStatus, displayVariant: event.displayVariant, activityStatus: event.activityStatus, - filterCategory: getFallbackFilterCategory(event), + filterCategory: getFallbackSimulatorEventFilterCategory(event), threadId: event.threadId, processId: event.processId, callId: event.callId, diff --git a/src/engines/SessionCore/derived/simulatorEventFilters.ts b/src/engines/SessionCore/derived/simulatorEventFilters.ts index 3a96841ae9..4bca6c5c41 100644 --- a/src/engines/SessionCore/derived/simulatorEventFilters.ts +++ b/src/engines/SessionCore/derived/simulatorEventFilters.ts @@ -1,46 +1,15 @@ import type { - SessionEvent, SimulatorEventFilterValue, SimulatorEventPreview, } from "../core/types"; -export const SIMULATOR_EVENT_FILTER_VALUES = [ - "key_interactions", - "file_changes", - "terminal_events", - "explore", - "other", -] as const satisfies readonly SimulatorEventFilterValue[]; +export { + SIMULATOR_EVENT_FILTER_VALUES, + getFallbackSimulatorEventFilterCategory, +} from "../core/simulatorEventFilterCategory"; export type { SimulatorEventFilterValue }; -export function getFallbackSimulatorEventFilterCategory( - event: SessionEvent -): SimulatorEventFilterValue { - if (event.source === "user") return "key_interactions"; - if ( - event.uiCanonical === "edit_file" || - event.uiCanonical === "delete_file" - ) { - return "file_changes"; - } - if (event.command || event.uiCanonical === "run_shell") { - return "terminal_events"; - } - if ( - event.uiCanonical === "read_file" || - event.uiCanonical === "list_dir" || - event.uiCanonical === "code_search" || - event.uiCanonical === "glob" || - event.uiCanonical === "find_files" || - event.uiCanonical === "search" - ) { - return "explore"; - } - if (event.filePath) return "file_changes"; - return "other"; -} - export function isSimulatorEventVisibleForFilters( preview: SimulatorEventPreview, selectedFilters: readonly SimulatorEventFilterValue[]