refactor: extract process management utilities for cross-platform support

Consolidate process lifecycle management (kill, check alive) into a new
utility module with proper Windows/Unix handling, replacing scattered
process.kill() calls with consistent async APIs.
This commit is contained in:
weishu
2025-12-26 16:12:03 +08:00
parent eee7a249fa
commit 702072e9ba
13 changed files with 152 additions and 80 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
import { spawn } from 'node:child_process';
import { logger } from '@/ui/logger';
import { restoreTerminalState } from '@/ui/terminalState';
import { killProcessByChildProcess } from '@/utils/process';
/**
* Filter out 'resume' subcommand which is managed internally by hapi.
@@ -76,7 +77,7 @@ export async function codexLocal(opts: {
if (child.exitCode === null && !child.killed) {
logger.debug('[CodexLocal] Abort timeout reached, sending SIGKILL');
try {
child.kill('SIGKILL');
void killProcessByChildProcess(child, true);
} catch (error) {
logger.debug('[CodexLocal] Failed to send SIGKILL:', error);
}