// Next.js instrumentation hook: register() runs once when the server starts. // It says every app edit is its own undo point (manifest.mjs setUndoEveryMs), and // umtool arms ONE thing here, the durable queue's runner (lib/queue/runner.ts), // so the steps an agent queued (`umtool queue add`) run in the app -- the live // unit -- and survive the session that queued them. A step that was running // when the last process died is marked failed with its log, never re-run. // // Skipped on the Edge runtime (the runner is Node-only; every import is lazy // for that reason), when the process boots idle (ARCHILYZER_IDLE_BOOT, as the // editor's runners are), and unless queueRunnerEnabled says so: on under `next // start`, off under `next dev` unless UMTOOL_QUEUE_RUNNER=1. import { isIdleBoot } from "yt-dlp-transcript-common/lib/idleBoot"; export async function register() { if (process.env.NEXT_RUNTIME !== "nodejs") return; // WHAT EVERY CHILD INHERITS (lane network-exits, reviews 2-3): before anything // can spawn, NETWORK_EXIT_* credentials leave process.env and, once a // network policy exists, no child inherits a proxy variable // (common/lib/childEnvGuard.mjs; lib/childEnvGuard.gate.test.ts). try { const { setNetworkPolicySettingsFile } = await import("yt-dlp-transcript-common/lib/childEnvGuard.mjs"); const { getPaths } = await import("yt-dlp-transcript-common/lib/paths"); setNetworkPolicySettingsFile(getPaths().settingsFile); } catch (e) { // Nothing that runs before the exit may hand a child a credential. for (const k of Object.keys(process.env)) if (k.startsWith("NETWORK_EXIT_")) delete process.env[k]; // A guard that does not install is no boot (review 3 nit 4). console.error( `umtool refuses to start: the child environment guard (common/lib/childEnvGuard.mjs) did not install — ${ e instanceof Error ? e.message : String(e) }`, ); process.exit(1); } // ARCHILYZER_NO_NETWORK (common/lib/noNetwork.mjs) is the test harness's switch. A server booted with it reaches // no site at all, so it is said first and loudly: set by accident in a service unit, it must not pass for a // normal boot. try { const { announceNoNetwork, noNetwork, installNoNetworkGuard } = await import("yt-dlp-transcript-common/lib/noNetwork.mjs"); if (noNetwork()) { // Once per process: the guard says it too when it installs, whichever comes first. announceNoNetwork( "umtool: ARCHILYZER_NO_NETWORK=1 is set — this server refuses every non-loopback connection (no sync, download " + "or fetch reaches a site). Unset it in the unit unless this is a test server.", ); installNoNetworkGuard(); } } catch (e) { console.error(`umtool: ARCHILYZER_NO_NETWORK check failed: ${e instanceof Error ? e.message : String(e)}`); } // ONE UNDO STACK (umtool redesign L3): every edit made in the app is its own undo point (lib/report/manifest.mjs // autoSnapshot; a terminal keeps the two-minute throttle). A process global, not the environment: the steps // the app spawns (lib/jobs.ts) must keep the terminal's throttle. Set before anything else, idle boot included. try { const { setUndoEveryMs } = await import("./lib/report/manifest.mjs"); setUndoEveryMs(0); } catch (e) { console.error(`umtool: per-edit undo points not set: ${e instanceof Error ? e.message : String(e)}`); } if (isIdleBoot()) return; try { const { queueRunnerEnabled, startQueueRunner } = await import("./lib/queue/runner"); if (queueRunnerEnabled(process.env)) startQueueRunner(); } catch (e) { // A runner that cannot arm must not keep the app from serving; the queue's pages say it is not running. console.error(`umtool: the queue runner did not start: ${e instanceof Error ? e.message : String(e)}`); } }