refactor: extract session lifecycle management and mode switching to shared module

Consolidates duplicate cleanup, signal handling, and state management logic from
runClaude and runCodex into a reusable createRunnerLifecycle factory function.
Extracts mode switching handler and controlled user state updates into utilities.
Adds runLocalRemoteSession wrapper to handle session ready callbacks in loop base.
This commit is contained in:
weishu
2026-01-04 20:50:33 +08:00
parent 2e8d644945
commit c8325b921a
6 changed files with 243 additions and 219 deletions
+4 -7
View File
@@ -1,6 +1,6 @@
import { MessageQueue2 } from '@/utils/MessageQueue2';
import { logger } from '@/ui/logger';
import { runLocalRemoteLoop } from '@/agent/loopBase';
import { runLocalRemoteSession } from '@/agent/loopBase';
import { CodexSession } from './session';
import { codexLocalLauncher } from './codexLocalLauncher';
import { codexRemoteLauncher } from './codexRemoteLauncher';
@@ -48,15 +48,12 @@ export async function loop(opts: LoopOptions): Promise<void> {
permissionMode: opts.permissionMode ?? 'default'
});
if (opts.onSessionReady) {
opts.onSessionReady(session);
}
await runLocalRemoteLoop({
await runLocalRemoteSession({
session,
startingMode: opts.startingMode,
logTag: 'codex-loop',
runLocal: codexLocalLauncher,
runRemote: codexRemoteLauncher
runRemote: codexRemoteLauncher,
onSessionReady: opts.onSessionReady
});
}