Files
rea/src/hopper/HopperProcessDiagnostic.ts
T
069308bbe6 fix(hopper): preserve startup failures and recover denied launches
Preserve the primary Hopper startup failure and launcher diagnostics while retaining resources when cleanup cannot be confirmed. Reauthenticate matching external application sessions before document cleanup, keep the Python bridge available for bounded reconnects, and expose the provider-owned Hopper startup deadline.

Real headless Linux Hopper semantic analysis and 65 focused configuration, handshake, cleanup, and bridge tests passed. macOS authorization/crash causes and saved-HOP behavior require their own real-provider verification.

Refs #1808

Co-authored-by: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-11 22:35:01 +08:00

40 lines
1.6 KiB
TypeScript

import {
hopperStartupFailure,
type HopperStartupFailureDiagnostic,
} from "../domain/hopperStartupFailure.js";
import type { ProviderProcessDiagnostic } from "../process/ProviderProcess.js";
import { parseLinuxPrivateDisplayDiagnostic } from "./LinuxPrivateDisplayDiagnostic.js";
import type { HopperLauncherOutcome } from "../domain/hopperErrors.js";
/**
* Hopper's native helper sends activate before its open-document Apple event.
* Recognize its explicit authorization rejection. The launcher must separately
* establish that caller arguments could not alter the generated AppleScript.
* Other script errors, signals, and incomplete output leave ownership unknown.
*/
export const nativeHopperLaunchWasDenied = (
outcome: HopperLauncherOutcome | undefined,
): outcome is HopperLauncherOutcome =>
outcome !== undefined &&
outcome.exit_code === 2 &&
outcome.signal === null &&
outcome.output_closed &&
!outcome.diagnostic_truncated &&
/^Cannot launch Hopper!\r?\nNot authorized to send Apple events to [^\r\n]+\.\r?\n?$/u.test(
outcome.stderr.text,
);
/** Extract only a matching Linux adapter failure record. */
export const hopperLauncherFailureDiagnostic = (
event: Extract<ProviderProcessDiagnostic, { readonly type: "exit" }>,
): HopperStartupFailureDiagnostic | undefined => {
const parsed = parseLinuxPrivateDisplayDiagnostic(event.snapshot.stderr.text);
if (!parsed.ok) return undefined;
const expected = hopperStartupFailure(event.code)?.code;
return parsed.value.operation === "launch" &&
parsed.value.status === "error" &&
parsed.value.failure_code === expected
? parsed.value
: undefined;
};