/** * macOS malloc-stack-logging launch boundary. * * On macOS, an inherited `MallocStackLogging` / `MallocStackLoggingNoCompact` * environment variable (from an Xcode scheme's malloc diagnostics, Instruments, * `launchctl setenv`, or a debug-attached shell) makes libmalloc print * * MallocStackLogging: can't turn off malloc stack logging because it was not enabled. * * to the stderr of every TTY-attached process. Bun snapshots the spawn-default * environment at process startup — before any JS runs — so neither * `delete process.env.X` nor a real libc `unsetenv()` cleans the environment * that children inherit by default (verified on Bun 1.3.14). Inside the TUI, * every PTY-spawned child then repeats the warning straight into the rendered * frame and corrupts the display. * * The only way to hand children a clean startup snapshot is to start the primary * process with a clean environment. This module re-execs the exact invocation * once (darwin-only) with a `filterProcessEnv`-scrubbed environment and a * `GJC_MALLOC_ENV_REEXEC` loop guard, before any fast path or subprocess spawn. * The re-exec'd process — and therefore every downstream lane: `Bun.spawn` * defaults, `node:child_process`, the native PTY, the tmux owner, plugin * installs, and subagents — starts from a clean snapshot. * * The initial contaminated process's own libmalloc line is emitted by libc * before any JS runs and cannot be suppressed from inside the process; it * appears at most once per launch. A one-time actionable notice is written to * interactive stderr (outside the rendered frame) pointing at the permanent * `launchctl unsetenv` fix. */ /** Env vars that make macOS libmalloc write to a TTY when inherited. */ export declare const MACOS_MALLOC_ENV_VARS: readonly ["MallocStackLogging", "MallocStackLoggingNoCompact"]; /** Loop guard set on the scrubbed re-exec so it never re-execs itself again. */ export declare const MALLOC_ENV_REEXEC_GUARD = "GJC_MALLOC_ENV_REEXEC"; /** True when at least one macOS malloc-stack-logging var is present in `env`. */ export declare function hasMacOSMallocEnv(env: Record): boolean; /** * True iff we must re-exec to escape a contaminated macOS startup snapshot: * darwin, not already inside the scrubbed re-exec, and at least one malloc var * present. Off darwin or on the re-exec'd child this is always false, so the * common launch path pays only two cheap lookups. */ export declare function shouldReexecForMacOSMallocEnv(env: Record, platform: NodeJS.Platform): boolean; /** * Reconstruct the argv that re-runs the exact same program image. * * - Compiled single-file executable: argv[1] is the embedded virtual entry * (`/$bunfs/…` on POSIX, `B:\~BUN\…` on Windows), which must be dropped — the * executable re-embeds its own entry. Re-run `[exe, ...userArgs]`. * - Source / dev-link run: argv[1] is the on-disk script that must be passed * back to the interpreter. Re-run `[interpreter, script, ...userArgs]`. */ export declare function buildMallocReexecArgv(argv: readonly string[], execPath: string): string[]; /** One-time, human-actionable notice pointing at the permanent environment fix. */ export declare function formatMallocEnvNotice(): string; /** * Re-exec the current process once with a scrubbed environment and propagate the * child's exit code. Callers MUST gate this behind `shouldReexecForMacOSMallocEnv`. * * Returns the child exit code, or `null` if the re-exec could not be spawned (in * which case the caller falls back to running in the current, contaminated * process — degraded but functional; the native PTY boundary and * `filterProcessEnv` still keep managed children clean). */ export declare function reexecWithScrubbedMallocEnv(): Promise;