Build account restart plans from the accepting store snapshot

This commit is contained in:
Jinjing
2026-11-13 19:14:30 -08:00
parent e078b493b9
commit c0ecf892ef
9 changed files with 32 additions and 32 deletions
@@ -0,0 +1,5 @@
export const CLIENT_PLATFORM: NodeJS.Platform = navigator.userAgent.includes('Windows')
? 'win32'
: navigator.userAgent.includes('Mac')
? 'darwin'
: 'linux'
@@ -158,7 +158,7 @@ async function executeDetachedCodexPaneRestart(
return
}
const { worktreeId, tab, leafId } = located
const startup = buildPaneAccountRestartStartup(agent, {
const startup = buildPaneAccountRestartStartup(state, agent, {
worktreeId,
tabId: tab.id,
leafId,
@@ -9,15 +9,16 @@ export function usePaneAccountRestartStartup({
worktreeId
}: Pick<TerminalPaneCloseController, 'tabId' | 'worktreeId'>) {
const buildAccountRestartStartup = useCallback(
(agent: AccountRestartAgent, leafId: string) =>
buildPaneAccountRestartStartup(agent, {
(agent: AccountRestartAgent, leafId: string) => {
const state = useAppStore.getState()
return buildPaneAccountRestartStartup(state, agent, {
tabId,
worktreeId,
leafId,
shellOverride: useAppStore
.getState()
.tabsByWorktree[worktreeId]?.find((tab) => tab.id === tabId)?.shellOverride
}),
shellOverride: state.tabsByWorktree[worktreeId]?.find((tab) => tab.id === tabId)
?.shellOverride
})
},
[tabId, worktreeId]
)
return { buildAccountRestartStartup }
@@ -49,7 +49,7 @@ function seedAgentStatus(entry: Partial<AgentStatusEntry> | null): void {
}
function build(): AgentAccountRestartStartup {
const startup = buildPaneAccountRestartStartup('codex', {
const startup = buildPaneAccountRestartStartup(useAppStore.getState(), 'codex', {
tabId: TAB_ID,
leafId: LEAF_ID,
worktreeId: WORKTREE_ID
@@ -127,7 +127,7 @@ describe('buildPaneAccountRestartStartup for Claude', () => {
}
})
expect(buildPaneAccountRestartStartup('claude', pane)).toBeNull()
expect(buildPaneAccountRestartStartup(useAppStore.getState(), 'claude', pane)).toBeNull()
})
it.each([
@@ -170,7 +170,7 @@ describe('buildPaneAccountRestartStartup for Claude', () => {
}
})
expect(buildPaneAccountRestartStartup('claude', pane)?.command).toBe(
expect(buildPaneAccountRestartStartup(useAppStore.getState(), 'claude', pane)?.command).toBe(
`${prefix}claude '--resume' '${SESSION_ID}'`
)
} finally {
@@ -1,5 +1,4 @@
import { getConnectionIdFromState } from '@/lib/workspace/ownership/connection-owner-resolution'
import { useAppStore } from '@/store/index'
import { buildAgentResumeStartupPlan } from '../../../../../shared/agent-launch/startup/tui-agent-resume-startup'
import {
resolveRuntimeHostReportedPlatform,
@@ -50,10 +49,10 @@ export type AgentAccountRestartResumeInput = {
} | null
export function captureAgentAccountRestartResumeInput(
state: AppState,
agent: AccountRestartAgent,
args: AccountRestartPane
): AgentAccountRestartResumeInput {
const state = useAppStore.getState()
const paneKey = makePaneKey(args.tabId, args.leafId)
const entry = state.agentStatusByPaneKey[paneKey]
const sleeping = state.sleepingAgentSessionsByPaneKey[paneKey]
@@ -76,12 +75,13 @@ export function captureAgentAccountRestartResumeInput(
/** Capture before teardown; retry a build error using the same conversation inputs. */
export function resolveAgentAccountRestartResumeStartup(
state: AppState,
agent: AccountRestartAgent,
args: AccountRestartPane,
input?: AgentAccountRestartResumeInput
): AgentAccountRestartStartup | null {
const state = useAppStore.getState()
const captured = input === undefined ? captureAgentAccountRestartResumeInput(agent, args) : input
const captured =
input === undefined ? captureAgentAccountRestartResumeInput(state, agent, args) : input
if (!captured) {
return null
}
@@ -131,11 +131,12 @@ export function resolveAgentAccountRestartResumeStartup(
/** Account-switch startup: Codex can relaunch fresh; Claude requires its recorded conversation. */
export function buildPaneAccountRestartStartup(
state: AppState,
agent: AccountRestartAgent,
args: AccountRestartPane,
input?: AgentAccountRestartResumeInput
): AgentAccountRestartStartup | null {
const resume = resolveAgentAccountRestartResumeStartup(agent, args, input)
const resume = resolveAgentAccountRestartResumeStartup(state, agent, args, input)
if (input && !resume) {
throw new Error('terminal_account_restart_resume_unavailable')
}
@@ -144,21 +145,17 @@ export function buildPaneAccountRestartStartup(
if (
agent === 'claude' &&
sessionId &&
isSessionHeldByAnotherPane(
useAppStore.getState(),
makePaneKey(args.tabId, args.leafId),
sessionId
)
isSessionHeldByAnotherPane(state, makePaneKey(args.tabId, args.leafId), sessionId)
) {
return null
}
return resume ?? (agent === 'codex' ? buildCodexAccountRestartStartup(args) : null)
return resume ?? (agent === 'codex' ? buildCodexAccountRestartStartup(state, args) : null)
}
export function buildCodexAccountRestartStartup(
state: AppState,
args: AccountRestartTarget
): AgentAccountRestartStartup {
const state = useAppStore.getState()
const target = resolveAccountRestartLaunchTarget(
state,
args,
@@ -214,7 +214,7 @@ function scanPane(
if (isClaudePaneOnAccount(folder, args.toAccountId, args.host)) {
return null
}
const resumable = resolveAgentAccountRestartResumeStartup('claude', {
const resumable = resolveAgentAccountRestartResumeStartup(useAppStore.getState(), 'claude', {
tabId: pane.tabId,
leafId: pane.leafId,
worktreeId: pane.worktreeId,
@@ -1,4 +1,4 @@
import { CLIENT_PLATFORM } from '@/lib/workspace/creation/new-workspace'
import { CLIENT_PLATFORM } from '@/app-shell/platform/client-platform'
import { REMOTE_RUNTIME_PTY_HONOURS_TAB_SHELL_OVERRIDE } from '@/components/terminal-pane/pty-transport/remote-runtime/remote-runtime-pty-shell'
import { parseExecutionHostId } from '../../../../../shared/execution-host'
import { lastVerifiedRuntimeStatus } from '../../../../../shared/remote-runtime/host-status/runtime-host-status'
@@ -14,11 +14,7 @@ import type { WorkspaceLinkedItem as FolderWorkspaceLinkedTask } from '../../../
import { slugifyForWorkspaceName } from '../../../../../shared/workspace-name'
import { createNonSecureContextUuid as createBrowserUuid } from '../../../../../shared/non-secure-context-uuid'
export const CLIENT_PLATFORM: NodeJS.Platform = navigator.userAgent.includes('Windows')
? 'win32'
: navigator.userAgent.includes('Mac')
? 'darwin'
: 'linux'
export { CLIENT_PLATFORM } from '../../../app-shell/platform/client-platform'
export type LinkedWorkItemSummary = Omit<FolderWorkspaceLinkedTask, 'provider'> & {
provider?: FolderWorkspaceLinkedTask['provider']
@@ -50,12 +50,13 @@ export function createCodexAccountRestartActions(
let error: string | undefined
try {
if (pane.leafId) {
startupInput = captureAgentAccountRestartResumeInput('codex', {
startupInput = captureAgentAccountRestartResumeInput(s, 'codex', {
...pane,
leafId: pane.leafId
})
startup = structuredClone(
buildPaneAccountRestartStartup(
s,
'codex',
{ ...pane, leafId: pane.leafId },
startupInput
@@ -221,9 +222,9 @@ export function createCodexAccountRestartActions(
}
const input = request.leafId
? request.startupInput
: captureAgentAccountRestartResumeInput('codex', { ...pane, leafId: pane.leafId })
: captureAgentAccountRestartResumeInput(s, 'codex', { ...pane, leafId: pane.leafId })
const startup = structuredClone(
buildPaneAccountRestartStartup('codex', { ...pane, leafId: pane.leafId }, input)
buildPaneAccountRestartStartup(s, 'codex', { ...pane, leafId: pane.leafId }, input)
)
if (!startup) {
return s