refactor(main): split main.ts into focused runtime modules (#123)

This commit is contained in:
2026-06-12 17:35:46 -07:00
committed by GitHub
parent 94a65416ae
commit 33e767458f
32 changed files with 3582 additions and 2003 deletions
+8
View File
@@ -1,4 +1,5 @@
import type { BackgroundStatsServerState } from './main/runtime/stats-daemon';
import { verifyBackgroundStatsServerIdentity } from './main/runtime/stats-daemon';
import type { StatsCliCommandResponse } from './main/runtime/stats-cli-command';
export type StatsDaemonControlAction = 'start' | 'stop';
@@ -22,6 +23,7 @@ export function createRunStatsDaemonControlHandler(deps: {
readState: () => BackgroundStatsServerState | null;
removeState: () => void;
isProcessAlive: (pid: number) => boolean;
verifyProcessIdentity?: (pid: number, startedAtMs: number) => boolean;
resolveUrl: (state: Pick<BackgroundStatsServerState, 'port'>) => string;
spawnDaemon: (options: SpawnStatsDaemonOptions) => Promise<number> | number;
waitForDaemonResponse: (responsePath: string) => Promise<StatsCliCommandResponse>;
@@ -81,6 +83,12 @@ export function createRunStatsDaemonControlHandler(deps: {
writeResponseSafe(args.responsePath, { ok: true });
return 0;
}
const verifyProcessIdentity = deps.verifyProcessIdentity ?? verifyBackgroundStatsServerIdentity;
if (!verifyProcessIdentity(state.pid, state.startedAtMs)) {
deps.removeState();
writeResponseSafe(args.responsePath, { ok: true });
return 0;
}
deps.killProcess(state.pid, 'SIGTERM');
const deadline = Date.now() + 2_000;