mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
Move parking assignment invalidation into the store observer
This commit is contained in:
+2
-17
@@ -78,25 +78,10 @@ export function useTerminalTabColdParking(args: {
|
||||
} = args
|
||||
const parkingInputs = useTerminalParkingWorkspaceInputs(worktreeId)
|
||||
const parkingInputRevision = parkingInputs.revision
|
||||
const assignmentProjection = useRef(assignments)
|
||||
if (assignmentProjection.current !== assignments) {
|
||||
const previous = assignmentProjection.current
|
||||
if (
|
||||
previous.size !== assignments.size ||
|
||||
[...assignments].some(([id, assignment]) => {
|
||||
const before = previous.get(id)
|
||||
return (
|
||||
before?.groupId !== assignment.groupId ||
|
||||
before.isActiveInGroup !== assignment.isActiveInGroup
|
||||
)
|
||||
})
|
||||
) {
|
||||
assignmentProjection.current = assignments
|
||||
}
|
||||
}
|
||||
const terminalParkingTabsDependency = coldParkTerminalPanes ? parkingInputRevision : terminalTabs
|
||||
// Accepted assignment changes already advance the workspace revision; renders do not own park clocks.
|
||||
const terminalParkingAssignmentsDependency = coldParkTerminalPanes
|
||||
? assignmentProjection.current
|
||||
? parkingInputRevision
|
||||
: assignments
|
||||
const pendingStartupByTabId = usePendingStartupParkPresence(terminalTabs)
|
||||
const terminalParkingEnabled = useAppStore(
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import type { TerminalTab } from '../../../../shared/workspace-layout/terminal-tab-types'
|
||||
import type { Tab, TabGroup } from '../../../../shared/tab-types'
|
||||
import type { AppState } from '../types'
|
||||
|
||||
export function sameTerminalParkingTab(
|
||||
previous: TerminalTab | undefined,
|
||||
next: TerminalTab
|
||||
): boolean {
|
||||
return (
|
||||
previous !== undefined &&
|
||||
previous.id === next.id &&
|
||||
previous.worktreeId === next.worktreeId &&
|
||||
previous.ptyId === next.ptyId &&
|
||||
previous.pendingActivationSpawn === next.pendingActivationSpawn &&
|
||||
previous.generation === next.generation &&
|
||||
previous.startupCwd === next.startupCwd &&
|
||||
previous.launchAgent === next.launchAgent
|
||||
)
|
||||
}
|
||||
|
||||
export function sameTerminalParkingTitleSlots(
|
||||
previous: AppState['runtimePaneTitlesByTabId'][string] | undefined,
|
||||
next: AppState['runtimePaneTitlesByTabId'][string] | undefined
|
||||
): boolean {
|
||||
if (previous === next) {
|
||||
return true
|
||||
}
|
||||
const before = Object.keys(previous ?? {})
|
||||
const after = Object.keys(next ?? {})
|
||||
return before.length === after.length && before.every((key) => key in (next ?? {}))
|
||||
}
|
||||
|
||||
export function sameTerminalParkingAssignments(
|
||||
previous: readonly Tab[],
|
||||
next: readonly Tab[],
|
||||
groups: readonly TabGroup[]
|
||||
): boolean {
|
||||
const before = new Map<string, Tab>()
|
||||
const after = new Map<string, Tab>()
|
||||
for (const tab of previous) {
|
||||
if (tab.contentType === 'terminal') {
|
||||
before.set(tab.entityId, tab)
|
||||
}
|
||||
}
|
||||
for (const tab of next) {
|
||||
if (tab.contentType === 'terminal') {
|
||||
after.set(tab.entityId, tab)
|
||||
}
|
||||
}
|
||||
if (before.size !== after.size) {
|
||||
return false
|
||||
}
|
||||
const activeTabByGroupId = new Map(groups.map((group) => [group.id, group.activeTabId]))
|
||||
for (const [tabId, tab] of after) {
|
||||
const previousTab = before.get(tabId)
|
||||
if (
|
||||
!previousTab ||
|
||||
previousTab.groupId !== tab.groupId ||
|
||||
(activeTabByGroupId.get(previousTab.groupId) === previousTab.id) !==
|
||||
(activeTabByGroupId.get(tab.groupId) === tab.id)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -6,8 +6,12 @@ import {
|
||||
retireParkedTerminalTab
|
||||
} from '@/components/terminal-pane/parking/output-watchers/terminal-parked-watcher-registry'
|
||||
import type { AppState } from '../types'
|
||||
import type { TerminalTab } from '../../../../shared/workspace-layout/terminal-tab-types'
|
||||
import { readRecordChanges } from '@/store/keyed-record-change-reads'
|
||||
import {
|
||||
sameTerminalParkingTab,
|
||||
sameTerminalParkingTitleSlots,
|
||||
sameTerminalParkingAssignments
|
||||
} from './terminal-parking-input-equality'
|
||||
import { sleepingAgentRecordIndex } from './sleeping-agent-record-index'
|
||||
import {
|
||||
getTerminalTab,
|
||||
@@ -39,31 +43,6 @@ const ptyIdsByTabId = new Map<string, Set<string>>()
|
||||
const tabIdsByEnvironmentId = new Map<string, Set<string>>()
|
||||
let accepted: AppState | null = null
|
||||
|
||||
function sameParkingTab(previous: TerminalTab | undefined, next: TerminalTab): boolean {
|
||||
return (
|
||||
previous !== undefined &&
|
||||
previous.id === next.id &&
|
||||
previous.worktreeId === next.worktreeId &&
|
||||
previous.ptyId === next.ptyId &&
|
||||
previous.pendingActivationSpawn === next.pendingActivationSpawn &&
|
||||
previous.generation === next.generation &&
|
||||
previous.startupCwd === next.startupCwd &&
|
||||
previous.launchAgent === next.launchAgent
|
||||
)
|
||||
}
|
||||
|
||||
function sameTitleSlots(
|
||||
previous: AppState['runtimePaneTitlesByTabId'][string] | undefined,
|
||||
next: AppState['runtimePaneTitlesByTabId'][string] | undefined
|
||||
): boolean {
|
||||
if (previous === next) {
|
||||
return true
|
||||
}
|
||||
const before = Object.keys(previous ?? {})
|
||||
const after = Object.keys(next ?? {})
|
||||
return before.length === after.length && before.every((key) => key in (next ?? {}))
|
||||
}
|
||||
|
||||
function diffUnknownParkingRecordKeys(
|
||||
previous: Readonly<Record<string, unknown>>,
|
||||
next: Readonly<Record<string, unknown>>
|
||||
@@ -148,7 +127,7 @@ export function acceptTerminalParkingInputs(state: AppState): ReadonlySet<string
|
||||
const after = state.tabsByWorktree[id] ?? []
|
||||
if (
|
||||
before.length === after.length &&
|
||||
after.every((tab, index) => sameParkingTab(before[index], tab))
|
||||
after.every((tab, index) => sameTerminalParkingTab(before[index], tab))
|
||||
) {
|
||||
continue
|
||||
}
|
||||
@@ -174,6 +153,23 @@ export function acceptTerminalParkingInputs(state: AppState): ReadonlySet<string
|
||||
}
|
||||
}
|
||||
}
|
||||
if (previous?.unifiedTabsByWorktree !== state.unifiedTabsByWorktree) {
|
||||
const before = previous?.unifiedTabsByWorktree
|
||||
const after = state.unifiedTabsByWorktree
|
||||
for (const id of before ? diffUnknownParkingRecordKeys(before, after) : Object.keys(after)) {
|
||||
if (
|
||||
!dirty.has(id) &&
|
||||
before?.[id] !== after[id] &&
|
||||
!sameTerminalParkingAssignments(
|
||||
before?.[id] ?? [],
|
||||
after[id] ?? [],
|
||||
state.groupsByWorktree[id] ?? []
|
||||
)
|
||||
) {
|
||||
dirty.add(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const field of SEAM_PARKING_TAB_FIELDS) {
|
||||
const before = previous?.[field]
|
||||
const after = state[field]
|
||||
@@ -186,7 +182,7 @@ export function acceptTerminalParkingInputs(state: AppState): ReadonlySet<string
|
||||
}
|
||||
if (
|
||||
field === 'runtimePaneTitlesByTabId' &&
|
||||
sameTitleSlots(
|
||||
sameTerminalParkingTitleSlots(
|
||||
previous?.runtimePaneTitlesByTabId[tabId],
|
||||
state.runtimePaneTitlesByTabId[tabId]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user