export const DEV_RELOAD_EXISTING_ARG = '--metoyou-dev-reload-existing'; export type SecondInstanceAction = 'reload-existing' | 'focus'; export interface SecondInstanceInput { argv: string[]; devSingleInstanceExitCode: number | null; } /** * A dev launch always carries `--metoyou-dev-reload-existing`, so the running * instance reloads in place. It must never answer by relaunching itself: the * successor inherits the same argument and asks for the single-instance lock * while the dying parent still holds it, so the refused successor fires * `second-instance` again and the pair respawns forever. */ export function resolveSecondInstanceAction(input: SecondInstanceInput): SecondInstanceAction { const isDevelopmentLaunch = input.devSingleInstanceExitCode != null; return isDevelopmentLaunch && input.argv.includes(DEV_RELOAD_EXISTING_ARG) ? 'reload-existing' : 'focus'; }