/** * @file Open a URL in the platform's default browser. This lives under * process/, not url/ — url/ is strictly pure string operations and must stay * IO-free, whereas opening a URL spawns the OS opener, so it is a process * action. `pickOpenCommand` is a pure, exported mapping from platform to * opener binary: darwin uses `open`, win32 uses `start`, everything else uses * `xdg-open`. `openUrl` takes an injectable spawner so tests drive the launch * path without opening a real browser, mirroring the ai/exec * injectable-runner pattern; the default spawner shells out through * node:child_process, detached with stdio ignored so the opener outlives this * process and never blocks it. * `newWindow` opts into a NEW WINDOW instead of a tab. No platform opener can * ask for one, so that lane invokes a browser binary with `--new-window` * directly and falls back to the platform opener when no known browser is * present. It is opt-in, so every existing caller keeps the behavior it has. */ /** * Spawn options handed to an {@link OpenUrlSpawner}. `openUrl` computes these * from the platform so the spawner stays a thin pass-through to a child-process * spawn: detached and stdio-ignored so the opener outlives us, shell only on * win32 where `start` is a cmd.exe builtin rather than an executable. */ export interface OpenUrlSpawnOptions { readonly detached: boolean; readonly shell: boolean; readonly stdio: 'ignore'; } /** * The injectable launch primitive: spawn `command` with `args` under * `options`. The lib ships {@link defaultOpenUrlSpawner}; a test injects a stub * to assert the command and URL without launching anything. */ export type OpenUrlSpawner = (command: string, args: readonly string[], options: OpenUrlSpawnOptions) => void; /** * Browser binaries that accept `--new-window`, in the order to try them. * * The platform opener cannot ask for a window: `open`, `xdg-open`, and `start` * have no such switch, so a URL handed to them lands as a TAB in whatever * window happens to be frontmost. The flag belongs to the BROWSER, and a * running instance answers it through its own process singleton, so invoking * the binary directly opens a new window in the session the user is already * signed into. */ export declare const NEW_WINDOW_BROWSERS: Readonly>; /** * Points at a `--new-window` capable browser this table does not know about, * so an unusual install is not stuck with a tab. */ export declare const BROWSER_BINARY_ENV_VAR = "SOCKET_BROWSER_BINARY"; /** * Set by a suite that MOCKS the spawn injection point and wants to assert on * the opener's invocation. Without it a test run never spawns at all, which is * the safe default; with it the call proceeds into whatever the suite mocked. */ export declare const ALLOW_SPAWN_ENV_VAR = "SOCKET_OPEN_URL_ALLOW_SPAWN"; /** * The command and args that open `url`. Pure, so the choice between a browser * binary and the platform opener is testable without spawning anything. */ export declare function buildOpenUrlInvocation(url: string, options?: OpenUrlOptions | undefined): { args: string[]; command: string; newWindow: boolean; }; /** * The built-in launch spawner: shell out to the opener through * node:child_process, detached with stdio ignored, then unref so the opener * outlives this process. Best-effort — a failed spawn is swallowed because the * caller can still relay the URL by hand. */ export declare function defaultOpenUrlSpawner(command: string, args: readonly string[], options: OpenUrlSpawnOptions): void; /** * Open `url` in the platform's default browser. Resolves the opener via * {@link pickOpenCommand}, then hands the launch to the injectable spawner so * tests never touch a real browser. Fire-and-forget: it returns immediately and * does not wait for the opener. */ export declare function openUrl(url: string, options?: OpenUrlOptions | undefined): void; /** * The platform command that opens a URL in the default browser: `open` on * darwin, `start` on win32, `xdg-open` everywhere else. Pure and exported so * the per-platform choice is unit-testable without spawning anything. */ export declare function pickOpenCommand(platform: NodeJS.Platform): string; /** * Options for {@link openUrl}. `platform` is injectable so a test can exercise * every opener branch on one host; it defaults to `process.platform`. `spawn` * is the injectable launch point; it defaults to {@link defaultOpenUrlSpawner}. * * `newWindow` opts into a NEW WINDOW rather than a tab, which needs a browser * binary rather than the platform opener. It is opt-in so every existing caller * keeps the behavior it already has. `env` and `exists` back the browser * lookup (and the test-runner detection) and are injectable for the same * reason `platform` is. * * `skipUnderTestRunner` (default: `true`) makes {@link openUrl} a no-op when * {@link shouldSkipSpawn} detects a test runner and no `spawn` injection point * was injected, so a suite that reaches this module through layers of imports * can never pop a real browser window. Pass `false` to launch anyway. */ export interface OpenUrlOptions { readonly env?: Record | undefined; readonly exists?: ((filePath: string) => boolean) | undefined; readonly newWindow?: boolean | undefined; readonly platform?: NodeJS.Platform | undefined; readonly skipUnderTestRunner?: boolean | undefined; readonly spawn?: OpenUrlSpawner | undefined; } /** * The first `--new-window` capable browser present, or undefined when none is. * The env override wins outright, and an override naming a path that does not * exist resolves to nothing rather than quietly falling back to a different * browser than the one asked for. */ export declare function resolveNewWindowBrowser(options?: OpenUrlOptions | undefined): string | undefined; /** * True when the opener must NOT spawn: a test runner with no explicit opt-in. * Vitest sets `VITEST` in the worker and `NODE_ENV=test` covers the other * runners. Pure apart from the env read; exported for tests and for callers * that want the same detection around their own launch paths. */ export declare function shouldSkipSpawn(env?: Record): boolean;