@asm-agent/coding-agent 0.8.8 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +2 -7
- package/dist/asm-agent-runtime/src/__pycache__/asm_cm_driver.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/__pycache__/phase76_address_head.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__init__.py +1 -1
- package/dist/asm-agent-runtime/src/rlm/__pycache__/__init__.cpython-312.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/__init__.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/bash.cpython-312.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/bash.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/mcp.cpython-312.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/mcp_base.cpython-312.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/repl.cpython-312.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/repl.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/__pycache__/skill.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/src/rlm/bash.py +94 -31
- package/dist/asm-agent-runtime/src/rlm/repl.md +3 -3
- package/dist/asm-agent-runtime/src/rlm/repl.py +46 -45
- package/dist/asm-agent-runtime/test/__pycache__/test_bash.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/test/__pycache__/test_repl.cpython-313.pyc +0 -0
- package/dist/asm-agent-runtime/test/test_bash.py +74 -19
- package/dist/asm-agent-runtime/test/test_repl.py +67 -3
- package/dist/asm-agent-runtime/uv.lock +446 -155
- package/dist/bundle/{anthropic-OFECORE7.js → anthropic-2VRH36LG.js} +2 -2
- package/dist/bundle/{azure-openai-responses-AOVTLR6N.js → azure-openai-responses-COYWHJPT.js} +2 -2
- package/dist/bundle/{bundled-modules-JQCJDEIY.js → bundled-modules-YKMFOFDW.js} +3 -3
- package/dist/bundle/{chunk-JC2TT4MZ.js → chunk-JBR32RCG.js} +4943 -1917
- package/dist/bundle/{chunk-M67RGWDQ.js → chunk-US4QGESM.js} +43 -44
- package/dist/bundle/{chunk-A65OM3TZ.js → chunk-V3BASDCN.js} +1 -1
- package/dist/bundle/{chunk-7TB7CGPV.js → chunk-YL37EJB6.js} +978 -1821
- package/dist/bundle/{cli-main-FNHDQGQD.js → cli-main-D7CFAHKG.js} +3 -3
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/{google-RVJL6RIQ.js → google-CSTXROSV.js} +1 -1
- package/dist/bundle/{google-vertex-EZTRRRH6.js → google-vertex-MEAR43KB.js} +1 -1
- package/dist/bundle/{main-IYXIIAJN.js → main-NKNJEUDP.js} +3 -3
- package/dist/bundle/{mistral-FSGKSMA7.js → mistral-VAF7JADB.js} +1 -1
- package/dist/bundle/{openai-codex-responses-VM5Y564D.js → openai-codex-responses-RWZ6P4I3.js} +2 -2
- package/dist/bundle/{openai-completions-X46FOQDN.js → openai-completions-CFB3BOTU.js} +3 -3
- package/dist/bundle/{openai-responses-SOQNEPBE.js → openai-responses-4OPGGCBI.js} +2 -2
- package/dist/config.d.ts +0 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -3
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-config.d.ts +1 -2
- package/dist/core/agent-session-config.d.ts.map +1 -1
- package/dist/core/agent-session-config.js +0 -3
- package/dist/core/agent-session-config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +0 -8
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +0 -2
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +0 -22
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +8 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +100 -22
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/kernel/bootstrap.d.ts.map +1 -1
- package/dist/core/kernel/bootstrap.js +1 -1
- package/dist/core/kernel/bootstrap.js.map +1 -1
- package/dist/core/kernel/repl-manager.d.ts +32 -8
- package/dist/core/kernel/repl-manager.d.ts.map +1 -1
- package/dist/core/kernel/repl-manager.js +401 -102
- package/dist/core/kernel/repl-manager.js.map +1 -1
- package/dist/core/kernel/shared.d.ts +11 -7
- package/dist/core/kernel/shared.d.ts.map +1 -1
- package/dist/core/kernel/shared.js +2 -5
- package/dist/core/kernel/shared.js.map +1 -1
- package/dist/core/mcp/mcp-manager.d.ts +4 -2
- package/dist/core/mcp/mcp-manager.d.ts.map +1 -1
- package/dist/core/mcp/mcp-manager.js +9 -7
- package/dist/core/mcp/mcp-manager.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +1 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/prime-inference-auth.d.ts +0 -9
- package/dist/core/prime-inference-auth.d.ts.map +1 -1
- package/dist/core/prime-inference-auth.js +0 -50
- package/dist/core/prime-inference-auth.js.map +1 -1
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +0 -1
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/session-manager.d.ts +0 -4
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +0 -22
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -16
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +13 -43
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +0 -5
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tools/acp-mcp.d.ts +6 -0
- package/dist/core/tools/acp-mcp.d.ts.map +1 -0
- package/dist/core/tools/acp-mcp.js +86 -0
- package/dist/core/tools/acp-mcp.js.map +1 -0
- package/dist/core/tools/index.d.ts +1 -0
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ipython.d.ts.map +1 -1
- package/dist/core/tools/ipython.js +9 -4
- package/dist/core/tools/ipython.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -11
- package/dist/main.js.map +1 -1
- package/dist/modes/acp/acp-mode.d.ts.map +1 -1
- package/dist/modes/acp/acp-mode.js +1 -1
- package/dist/modes/acp/acp-mode.js.map +1 -1
- package/dist/modes/agent-connection/daemon-agent-connection.d.ts +0 -2
- package/dist/modes/agent-connection/daemon-agent-connection.d.ts.map +1 -1
- package/dist/modes/agent-connection/daemon-agent-connection.js +0 -2
- package/dist/modes/agent-connection/daemon-agent-connection.js.map +1 -1
- package/dist/modes/agents-view/agents-view-mode.d.ts.map +1 -1
- package/dist/modes/agents-view/agents-view-mode.js +0 -19
- package/dist/modes/agents-view/agents-view-mode.js.map +1 -1
- package/dist/modes/daemon/daemon-mode.d.ts +1 -10
- package/dist/modes/daemon/daemon-mode.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-mode.js +134 -274
- package/dist/modes/daemon/daemon-mode.js.map +1 -1
- package/dist/modes/daemon/daemon-protocol.d.ts +11 -5
- package/dist/modes/daemon/daemon-protocol.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-protocol.js +6 -8
- package/dist/modes/daemon/daemon-protocol.js.map +1 -1
- package/dist/modes/daemon/daemon-supervisor.d.ts +0 -3
- package/dist/modes/daemon/daemon-supervisor.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-supervisor.js +18 -52
- package/dist/modes/daemon/daemon-supervisor.js.map +1 -1
- package/dist/modes/daemon/daemon-worker-protocol.d.ts +1 -6
- package/dist/modes/daemon/daemon-worker-protocol.d.ts.map +1 -1
- package/dist/modes/daemon/daemon-worker-protocol.js +0 -2
- package/dist/modes/daemon/daemon-worker-protocol.js.map +1 -1
- package/dist/modes/interactive/auth-flows.d.ts +0 -2
- package/dist/modes/interactive/auth-flows.d.ts.map +1 -1
- package/dist/modes/interactive/auth-flows.js +1 -101
- package/dist/modes/interactive/auth-flows.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +6 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +13 -3
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +2 -2
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts +12 -0
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
- package/dist/modes/interactive/components/mermaid.js +63 -0
- package/dist/modes/interactive/components/mermaid.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +10 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/feature-hints.d.ts.map +1 -1
- package/dist/modes/interactive/feature-hints.js +0 -4
- package/dist/modes/interactive/feature-hints.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -7
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +23 -279
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +1 -1
- package/dist/utils/version-check.js.map +1 -1
- package/docs/settings.md +1 -31
- package/docs/usage.md +1 -4
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/gpt-6-astra.models.json +24 -0
- package/package.json +6 -5
- package/dist/core/agent-traces.d.ts +0 -130
- package/dist/core/agent-traces.d.ts.map +0 -1
- package/dist/core/agent-traces.js +0 -746
- package/dist/core/agent-traces.js.map +0 -1
- package/dist/core/telemetry.d.ts +0 -92
- package/dist/core/telemetry.d.ts.map +0 -1
- package/dist/core/telemetry.js +0 -633
- package/dist/core/telemetry.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repl-manager.js","sourceRoot":"","sources":["../../../src/core/kernel/repl-manager.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,iFAA+E;AAC/E,uFAAuF;AACvF,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACnG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EACN,0BAA0B,EAC1B,uBAAuB,EACvB,cAAc,EACd,6BAA6B,EAC7B,wBAAwB,EACxB,4BAA4B,EAC5B,iBAAiB,EAGjB,YAAY,EACZ,+BAA+B,EAC/B,yBAAyB,EACzB,QAAQ,EACR,qBAAqB,EACrB,iCAAiC,EACjC,yBAAyB,EACzB,0BAA0B,EAE1B,6BAA6B,EAK7B,WAAW,EACX,yBAAyB,EACzB,oCAAoC,EACpC,sBAAsB,EACtB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,2BAA2B,EAC3B,6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UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;YAC1D,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC5C,CAAC;QAAC,MAAM,CAAC;YACR,4DAA4D;QAC7D,CAAC;gBAAS,CAAC;YACV,IAAI,KAAK;gBAAE,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAC1C,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC3C,CAAC;IAAA,CACD;IAED,+EAA+E;IAC/E,WAAW,GAAS;QACnB,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC;QACxB,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAAA,CACxB;IAED,IAAI,SAAS,GAAY;QACxB,OAAO,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC;IAAA,CAChC;CACD","sourcesContent":["// Kernel client for the REPL runtime: the kernel is a JSON-lines subprocess\n// (`python -m rlm.repl`) — requests on stdin, events on stdout, stderr kept as\n// a diagnostics tail. The protocol is documented in asm-agent-runtime/src/rlm/repl.md.\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport { v4 as uuid } from \"uuid\";\nimport { reapKernelOrphanProcesses, recordOrphanProcessState } from \"../orphan-process-journal.js\";\nimport { ensureKernelPython } from \"./bootstrap.js\";\nimport {\n\tAGENT_MESSAGE_DISPLAY_MIME,\n\tATTACHMENT_DISPLAY_MIME,\n\tcreateDeferred,\n\tcreateKernelStartupAbortError,\n\tDEFAULT_MAX_OUTPUT_CHARS,\n\tDEFAULT_SNAPSHOT_DEBOUNCE_MS,\n\tDIFF_DISPLAY_MIME,\n\ttype ExecuteOptions,\n\ttype ExecuteResult,\n\terrorMessage,\n\tHOST_REQUEST_DISPOSE_TIMEOUT_MS,\n\tinstallSignalHandlersOnce,\n\tisRecord,\n\tKERNEL_ABORT_GRACE_MS,\n\tKERNEL_BUSY_INTERRUPT_INTERVAL_MS,\n\tKERNEL_BUSY_REUSE_WAIT_MS,\n\tKERNEL_SHUTDOWN_TIMEOUT_MS,\n\ttype KernelAttachment,\n\tKernelBusyAfterInterruptError,\n\ttype KernelDiffDisplay,\n\ttype KernelManagerOptions,\n\ttype KernelSentAgentMessage,\n\ttype KernelStartOptions,\n\tliveKernels,\n\tMAX_ATTACHMENT_DATA_CHARS,\n\tMAX_LATE_SENT_AGENT_MESSAGE_HANDLERS,\n\tparseAttachmentDisplay,\n\tparseDiffDisplay,\n\tparseSentAgentMessage,\n\traceStartupWithAbort,\n\tSNAPSHOT_DISPOSE_TIMEOUT_MS,\n\tSNAPSHOT_EXECUTION_TIMEOUT_MS,\n} from \"./shared.js\";\nimport {\n\tDEFAULT_SNAPSHOT_MAX_BYTES,\n\tDEFAULT_SNAPSHOT_MAX_VARIABLE_BYTES,\n\ttype RestoreResult,\n\ttype SnapshotResult,\n} from \"./state-snapshot.js\";\n\nconst REPL_PROTOCOL_VERSION = 2;\nconst READY_TIMEOUT_MS = 30_000;\n// Runtime-minted host-request ids never repeat; the bound only guards a\n// misbehaving runtime from growing the dedup set forever.\nconst MAX_HANDLED_HOST_REQUEST_IDS = 1024;\n// Cap for unattributed background output buffered between and during cells.\nconst MAX_BACKGROUND_OUTPUT_CHARS = 64 * 1024;\n\n/** ExecuteResult plus the raw fields of the request's `done` event (state ops). */\ninterface InternalExecuteResult extends ExecuteResult {\n\tdoneFields?: Record<string, unknown>;\n}\n\ninterface ActiveExecution {\n\trequestId: string;\n\t/** Source of the cell currently executing; surfaced to rlm.run spawns. */\n\tcode: string;\n\tstarted: number;\n\tmaxChars: number;\n\topts: ExecuteOptions;\n\tstdout: string;\n\tstderr: string;\n\tstdoutTruncated: boolean;\n\tstderrTruncated: boolean;\n\tresult?: string;\n\tdiffs: KernelDiffDisplay[];\n\tattachments: KernelAttachment[];\n\tsentAgentMessages: KernelSentAgentMessage[];\n\t/** Stream text without this execution's id: user threads, other cells' leftovers, raw fd writes. */\n\tbackgroundOutput: string;\n\tbackgroundOutputTruncated: boolean;\n\terror?: ExecuteResult[\"error\"];\n\tstatus: ExecuteResult[\"status\"];\n\tdoneFields?: Record<string, unknown>;\n\tsettled: boolean;\n\tresolve: (result: InternalExecuteResult) => void;\n\treject: (error: Error) => void;\n}\n\nfunction asStringArray(value: unknown): string[] {\n\treturn Array.isArray(value) ? value.filter((v): v is string => typeof v === \"string\") : [];\n}\n\nfunction asReasonArray(value: unknown): { name: string; reason: string }[] {\n\tif (!Array.isArray(value)) return [];\n\treturn value.flatMap((entry) => {\n\t\tif (isRecord(entry) && typeof entry.name === \"string\") {\n\t\t\treturn [{ name: entry.name, reason: typeof entry.reason === \"string\" ? entry.reason : \"\" }];\n\t\t}\n\t\treturn [];\n\t});\n}\n\nexport class ReplKernelManager {\n\tprivate readonly options: Pick<\n\t\tKernelManagerOptions,\n\t\t\"python\" | \"cwd\" | \"env\" | \"sessionId\" | \"hostHandlers\" | \"pythonSkills\" | \"snapshot\"\n\t>;\n\tprivate readonly handledHostRequestIds = new Set<string>();\n\tprivate child?: ChildProcess;\n\tprivate readyDeferred?: ReturnType<typeof createDeferred<number>>;\n\tprivate kernelStderr = \"\";\n\t/** Serializes execute() calls — the runtime runs one request at a time. */\n\tprivate executionQueue: Promise<unknown> = Promise.resolve();\n\tprivate activeExecution?: ActiveExecution;\n\tprivate readonly activeExecutionIdleWaiters = new Set<() => void>();\n\tprivate readonly lateSentAgentMessageHandlers = new Map<string, (message: KernelSentAgentMessage) => void>();\n\t/** Resolvers for done events outside the active execution (the shutdown reply). */\n\tprivate readonly pendingDoneWaiters = new Map<string, () => void>();\n\t// Source of the most recently started cell, retained after it finishes so\n\t// rlm.run spawns from detached asyncio tasks (cell already idle) can still\n\t// attribute their spawning program.\n\tprivate lastCellCode?: string;\n\t/** Unattributed stream text that arrived between cells; surfaced on the next execution. */\n\tprivate pendingBackgroundOutput = \"\";\n\tprivate pendingBackgroundOutputTruncated = false;\n\tprivate readonly inFlightHostRequests = new Set<Promise<void>>();\n\tprivate state: \"idle\" | \"starting\" | \"running\" | \"shutdown\" = \"idle\";\n\t/** Bumped by every teardown so a stale in-flight doStart can never touch a newer kernel. */\n\tprivate startGeneration = 0;\n\t/** Generation whose graceful shutdown() owns the teardown, so the exit handler must not run it. */\n\tprivate gracefulShutdownGeneration?: number;\n\t/** Memoized so concurrent callers all await the same in-flight startup. */\n\tprivate startPromise?: Promise<void>;\n\t/** Pending debounced auto-snapshot, if one has been scheduled. */\n\tprivate snapshotTimer?: ReturnType<typeof globalThis.setTimeout>;\n\n\tconstructor(options: KernelManagerOptions) {\n\t\tthis.options = {\n\t\t\tpython: options.python,\n\t\t\tcwd: options.cwd,\n\t\t\tenv: options.env,\n\t\t\tsessionId: options.sessionId,\n\t\t\thostHandlers: options.hostHandlers,\n\t\t\tpythonSkills: options.pythonSkills,\n\t\t\tsnapshot: options.snapshot,\n\t\t};\n\t}\n\n\tget ownerSessionId(): string | undefined {\n\t\treturn this.options.sessionId;\n\t}\n\n\tprivate appendKernelDiagnostic(message: string): void {\n\t\tthis.kernelStderr += `[kernel] ${message.endsWith(\"\\n\") ? message : `${message}\\n`}`;\n\t}\n\n\tasync start(options: KernelStartOptions = {}): Promise<void> {\n\t\tif (options.signal?.aborted) {\n\t\t\tthrow createKernelStartupAbortError();\n\t\t}\n\t\tif (!this.startPromise) {\n\t\t\tconst startPromise = this.doStart({ onBootstrapProgress: options.onBootstrapProgress }).catch((error) => {\n\t\t\t\t// Only clear our own memoization: a stale start must not evict a newer one.\n\t\t\t\tif (this.startPromise === startPromise) this.startPromise = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\tthis.startPromise = startPromise;\n\t\t}\n\t\treturn raceStartupWithAbort(this.startPromise, options.signal);\n\t}\n\n\tprivate async doStart(startOptions: KernelStartOptions): Promise<void> {\n\t\tif (this.state !== \"idle\") return;\n\t\tconst generation = ++this.startGeneration;\n\t\tthis.state = \"starting\";\n\t\tinstallSignalHandlersOnce();\n\t\t// Tracked from the moment startup begins so session cleanup and signal\n\t\t// handlers can dispose a kernel that is still booting.\n\t\tliveKernels.add(this);\n\n\t\tlet python: string;\n\t\ttry {\n\t\t\tpython =\n\t\t\t\tthis.options.python ??\n\t\t\t\t(await ensureKernelPython({\n\t\t\t\t\tpythonSkills: this.options.pythonSkills,\n\t\t\t\t\tonProgress: startOptions.onBootstrapProgress,\n\t\t\t\t}));\n\t\t\tif (this.startStale(generation)) throw new Error(\"Kernel start superseded\");\n\t\t\tthis.options.python = python;\n\t\t} catch (error) {\n\t\t\tif (this.startStale(generation)) throw error; // never touch a newer start's state\n\t\t\tliveKernels.delete(this);\n\t\t\tif ((this.state as string) !== \"shutdown\") this.state = \"idle\";\n\t\t\tthrow error;\n\t\t}\n\n\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\tthrow new Error(\"Kernel was disposed during startup\");\n\t\t}\n\n\t\tconst child = spawn(python, [\"-m\", \"rlm.repl\"], {\n\t\t\tcwd: this.options.cwd,\n\t\t\t// bash.py journals its process groups under this pid so the host can\n\t\t\t// reap them if the runtime dies without running its shutdown hook.\n\t\t\tenv: {\n\t\t\t\t...process.env,\n\t\t\t\t...this.options.env,\n\t\t\t\tASM_AGENT_KERNEL_OWNER_PID: String(process.pid),\n\t\t\t},\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tthis.child = child;\n\t\tif (child.pid !== undefined) recordOrphanProcessState(child.pid, true);\n\t\tthis.readyDeferred = createDeferred<number>();\n\t\tthis.wireChild(child);\n\n\t\ttry {\n\t\t\tconst protocol = await this.waitForReady(child);\n\t\t\tif (this.startStale(generation)) throw new Error(\"Kernel start superseded\");\n\t\t\tif (protocol !== REPL_PROTOCOL_VERSION) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Kernel runtime speaks protocol ${protocol}, expected ${REPL_PROTOCOL_VERSION}. ` +\n\t\t\t\t\t\t\"Update asm-agent-runtime in the kernel Python (ASM_AGENT_KERNEL_PYTHON) to match this asm-agent.\",\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (this.startStale(generation)) throw e; // never tear down a newer start's kernel\n\t\t\tconst canRetryStartup = (this.state as string) !== \"shutdown\";\n\t\t\t// Only the call that performed the cleanup may resurrect to idle; a\n\t\t\t// concurrent kill()/teardown owns the state otherwise.\n\t\t\tif ((await this.shutdown()) && canRetryStartup) this.state = \"idle\";\n\t\t\tthrow e;\n\t\t}\n\n\t\tthis.state = \"running\";\n\t}\n\n\t/** True when a teardown (or newer start) superseded the start that captured `generation`. */\n\tprivate startStale(generation: number): boolean {\n\t\treturn generation !== this.startGeneration;\n\t}\n\n\tprivate wireChild(child: ChildProcess): void {\n\t\tconst decoder = new StringDecoder(\"utf8\");\n\t\tlet buffered = \"\";\n\t\tchild.stdout?.on(\"data\", (buf: Buffer) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tbuffered += decoder.write(buf);\n\t\t\tlet newline = buffered.indexOf(\"\\n\");\n\t\t\twhile (newline !== -1) {\n\t\t\t\tconst line = buffered.slice(0, newline);\n\t\t\t\tbuffered = buffered.slice(newline + 1);\n\t\t\t\tnewline = buffered.indexOf(\"\\n\");\n\t\t\t\tif (!line.trim()) continue;\n\t\t\t\tlet event: unknown;\n\t\t\t\ttry {\n\t\t\t\t\tevent = JSON.parse(line);\n\t\t\t\t} catch {\n\t\t\t\t\tthis.appendKernelDiagnostic(`unparseable protocol line: ${line.slice(0, 200)}`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (isRecord(event)) this.handleEvent(event);\n\t\t\t}\n\t\t});\n\n\t\tchild.stderr?.on(\"data\", (buf: Buffer) => {\n\t\t\tthis.kernelStderr += buf.toString();\n\t\t});\n\n\t\tchild.on(\"error\", (err) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tthis.appendKernelDiagnostic(`spawn error: ${err.message}`);\n\t\t\tthis.state = \"shutdown\";\n\t\t\tliveKernels.delete(this);\n\t\t\t// Fail a pending start() promptly instead of letting it ride out the\n\t\t\t// ready timeout. cleanupResources clears readyDeferred, so reject first;\n\t\t\t// a late error after ready resolved is a no-op on the settled promise.\n\t\t\tthis.readyDeferred?.reject(err);\n\t\t\tthis.cleanupResources();\n\t\t});\n\n\t\tchild.on(\"exit\", (code, signal) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tif (this.state !== \"shutdown\") {\n\t\t\t\tthis.appendKernelDiagnostic(`unexpected exit code=${code} signal=${signal}`);\n\t\t\t}\n\t\t\tthis.state = \"shutdown\";\n\t\t\tliveKernels.delete(this);\n\t\t\t// This exit is part of an in-flight graceful shutdown(): that call owns the\n\t\t\t// teardown and runs cleanupResources itself. Cleaning up here would bump the\n\t\t\t// generation and misread the owning shutdown as superseded.\n\t\t\tif (this.gracefulShutdownGeneration === this.startGeneration) return;\n\t\t\tthis.cleanupResources();\n\t\t});\n\t}\n\n\tprivate async waitForReady(child: ChildProcess): Promise<number> {\n\t\tconst ready = this.readyDeferred;\n\t\tif (!ready) throw new Error(\"Kernel ready state is missing\");\n\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tlet onExit: (() => void) | undefined;\n\t\ttry {\n\t\t\treturn await new Promise<number>((resolve, reject) => {\n\t\t\t\tready.promise.then(resolve, reject);\n\t\t\t\tonExit = () => {\n\t\t\t\t\tconst tail = this.kernelStderr.slice(-1024);\n\t\t\t\t\treject(new Error(`Kernel exited before ready. stderr:\\n${tail || \"(empty)\"}`));\n\t\t\t\t};\n\t\t\t\tif (child.exitCode !== null || child.signalCode !== null) {\n\t\t\t\t\tonExit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tchild.once(\"exit\", onExit);\n\t\t\t\ttimeout = globalThis.setTimeout(() => {\n\t\t\t\t\tconst tail = this.kernelStderr.slice(-1024);\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Kernel did not become ready within ${READY_TIMEOUT_MS}ms. stderr tail:\\n${tail || \"(empty)\"}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}, READY_TIMEOUT_MS);\n\t\t\t\ttimeout.unref?.();\n\t\t\t});\n\t\t} finally {\n\t\t\tif (timeout) globalThis.clearTimeout(timeout);\n\t\t\tif (onExit) child.removeListener(\"exit\", onExit);\n\t\t}\n\t}\n\n\t/** Write one JSON-lines request frame; resolves when the OS accepted the bytes. */\n\tprivate writeLine(request: Record<string, unknown>): Promise<void> {\n\t\tconst stdin = this.child?.stdin;\n\t\tif (!stdin || stdin.destroyed) {\n\t\t\treturn Promise.reject(new Error(\"Kernel stdin is not connected\"));\n\t\t}\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tstdin.write(`${JSON.stringify(request)}\\n`, (error) => {\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolve();\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate handleEvent(event: Record<string, unknown>): void {\n\t\tconst type = event.event;\n\t\tif (type === \"ready\") {\n\t\t\tthis.readyDeferred?.resolve(typeof event.protocol === \"number\" ? event.protocol : -1);\n\t\t\treturn;\n\t\t}\n\t\tif (type === \"host_request\") {\n\t\t\tif (typeof event.id === \"string\") this.startHostRequest(event.id, event.data);\n\t\t\treturn;\n\t\t}\n\n\t\tconst id = typeof event.id === \"string\" ? event.id : undefined;\n\t\tconst execution = this.activeExecution;\n\t\tif (!execution || id !== execution.requestId) {\n\t\t\tif (type === \"display\" && isRecord(event.data)) {\n\t\t\t\tthis.dispatchLateSentAgentMessage(id, event.data[AGENT_MESSAGE_DISPLAY_MIME]);\n\t\t\t} else if (type === \"stdout\" || type === \"stderr\") {\n\t\t\t\t// Unowned output (null id, or another cell's id): never merge it into\n\t\t\t\t// the active cell's streams; buffer it as background output instead.\n\t\t\t\tthis.appendBackgroundOutput(typeof event.text === \"string\" ? event.text : \"\");\n\t\t\t} else if (type === \"done\" && id) {\n\t\t\t\tconst waiter = this.pendingDoneWaiters.get(id);\n\t\t\t\tthis.pendingDoneWaiters.delete(id);\n\t\t\t\twaiter?.();\n\t\t\t} else if (type === \"error\" && id === undefined) {\n\t\t\t\tthis.appendKernelDiagnostic(`protocol error: ${String(event.evalue ?? \"\")}`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (execution.settled && type === \"display\" && isRecord(event.data)) {\n\t\t\tif (this.dispatchLateSentAgentMessage(id, event.data[AGENT_MESSAGE_DISPLAY_MIME])) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (type === \"stdout\" || type === \"stderr\") {\n\t\t\tconst text = typeof event.text === \"string\" ? event.text : \"\";\n\t\t\tif (type === \"stdout\") {\n\t\t\t\tif (execution.stdout.length < execution.maxChars) {\n\t\t\t\t\texecution.stdout += text;\n\t\t\t\t\tif (execution.stdout.length > execution.maxChars) {\n\t\t\t\t\t\texecution.stdout = execution.stdout.slice(0, execution.maxChars);\n\t\t\t\t\t\texecution.stdoutTruncated = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (execution.stderr.length < execution.maxChars) {\n\t\t\t\t\texecution.stderr += text;\n\t\t\t\t\tif (execution.stderr.length > execution.maxChars) {\n\t\t\t\t\t\texecution.stderr = execution.stderr.slice(0, execution.maxChars);\n\t\t\t\t\t\texecution.stderrTruncated = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\texecution.opts.onStream?.(text, type);\n\t\t} else if (type === \"result\") {\n\t\t\tif (typeof event.text === \"string\") execution.result = event.text;\n\t\t} else if (type === \"display\") {\n\t\t\tconst data = isRecord(event.data) ? event.data : {};\n\t\t\tconst diff = parseDiffDisplay(data[DIFF_DISPLAY_MIME]);\n\t\t\tif (diff) execution.diffs.push(diff);\n\t\t\tconst attachment = parseAttachmentDisplay(data[ATTACHMENT_DISPLAY_MIME]);\n\t\t\tif (attachment === \"oversized\") {\n\t\t\t\texecution.stderr += `${execution.stderr ? \"\\n\" : \"\"}attachment dropped: exceeds ${MAX_ATTACHMENT_DATA_CHARS} base64 chars`;\n\t\t\t\texecution.status = \"error\";\n\t\t\t} else if (attachment) {\n\t\t\t\texecution.attachments.push(attachment);\n\t\t\t}\n\t\t\tconst sentAgentMessage = parseSentAgentMessage(data[AGENT_MESSAGE_DISPLAY_MIME]);\n\t\t\tif (sentAgentMessage) execution.sentAgentMessages.push(sentAgentMessage);\n\t\t} else if (type === \"error\") {\n\t\t\texecution.error = {\n\t\t\t\tename: typeof event.ename === \"string\" ? event.ename : \"Error\",\n\t\t\t\tevalue: typeof event.evalue === \"string\" ? event.evalue : \"\",\n\t\t\t\ttraceback: asStringArray(event.traceback),\n\t\t\t};\n\t\t\texecution.status = \"error\";\n\t\t} else if (type === \"done\") {\n\t\t\texecution.doneFields = event;\n\t\t\tif (event.status !== \"ok\" && execution.status === \"ok\") {\n\t\t\t\texecution.status = \"error\";\n\t\t\t\t// State requests report failures as a done reason without an error event.\n\t\t\t\tif (!execution.error && typeof event.reason === \"string\") {\n\t\t\t\t\texecution.error = { ename: \"KernelError\", evalue: event.reason, traceback: [] };\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.finishActiveExecution(execution);\n\t\t}\n\t}\n\n\tasync execute(code: string, opts: ExecuteOptions = {}): Promise<ExecuteResult> {\n\t\tconst result = await this.enqueueExecute(code, opts);\n\t\t// Refresh the on-disk snapshot after real work so a later resume (or a\n\t\t// crash before graceful shutdown) revives the most recent namespace.\n\t\tif (result.status === \"ok\") {\n\t\t\tthis.scheduleSnapshot();\n\t\t}\n\t\treturn result;\n\t}\n\n\t/** Queue and run a cell, serializing against all other executions. */\n\tprivate async enqueueExecute(\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\texecutionTimeoutMs?: number,\n\t): Promise<InternalExecuteResult> {\n\t\treturn this.enqueueRequest({ type: \"execute\", code }, code, opts, executionTimeoutMs);\n\t}\n\n\t/** Queue one protocol request (execute or state op) behind every other request. */\n\tprivate async enqueueRequest(\n\t\trequestFields: Record<string, unknown> & { type: string },\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\texecutionTimeoutMs?: number,\n\t): Promise<InternalExecuteResult> {\n\t\tif (opts.signal?.aborted) {\n\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: 0 };\n\t\t}\n\t\tawait this.start({ signal: opts.signal });\n\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t}\n\n\t\tconst prev = this.executionQueue;\n\t\tlet resolveNext: () => void = () => {};\n\t\tthis.executionQueue = new Promise<void>((r) => {\n\t\t\tresolveNext = r;\n\t\t});\n\t\tawait prev;\n\n\t\tconst started = Date.now();\n\t\tlet executionTimeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\ttry {\n\t\t\tawait this.waitForActiveExecutionToClearForReuse(opts.signal);\n\t\t\tif (opts.signal?.aborted) {\n\t\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: Date.now() - started };\n\t\t\t}\n\t\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t\t}\n\t\t\tif (executionTimeoutMs === undefined) {\n\t\t\t\treturn await this.executeInner(requestFields, code, opts, started);\n\t\t\t}\n\n\t\t\tconst controller = new AbortController();\n\t\t\texecutionTimeout = globalThis.setTimeout(() => controller.abort(), executionTimeoutMs);\n\t\t\texecutionTimeout.unref?.();\n\t\t\tconst signal = opts.signal ? AbortSignal.any([opts.signal, controller.signal]) : controller.signal;\n\t\t\treturn await this.executeInner(requestFields, code, { ...opts, signal }, started);\n\t\t} finally {\n\t\t\tif (executionTimeout) globalThis.clearTimeout(executionTimeout);\n\t\t\tresolveNext();\n\t\t}\n\t}\n\n\tprivate async executeInner(\n\t\trequestFields: Record<string, unknown> & { type: string },\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\tstarted: number,\n\t): Promise<InternalExecuteResult> {\n\t\tconst maxChars = opts.maxOutputChars ?? DEFAULT_MAX_OUTPUT_CHARS;\n\t\tconst requestId = uuid();\n\n\t\tif (opts.signal?.aborted) {\n\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: Date.now() - started };\n\t\t}\n\t\tif (this.activeExecution) {\n\t\t\tthrow new Error(\"Kernel already has an active execution\");\n\t\t}\n\n\t\tconst result = createDeferred<InternalExecuteResult>();\n\t\tconst execution: ActiveExecution = {\n\t\t\trequestId,\n\t\t\tcode,\n\t\t\tstarted,\n\t\t\tmaxChars,\n\t\t\topts,\n\t\t\tstdout: \"\",\n\t\t\tstderr: \"\",\n\t\t\tstdoutTruncated: false,\n\t\t\tstderrTruncated: false,\n\t\t\tdiffs: [],\n\t\t\tattachments: [],\n\t\t\tsentAgentMessages: [],\n\t\t\tbackgroundOutput: this.pendingBackgroundOutput,\n\t\t\tbackgroundOutputTruncated: this.pendingBackgroundOutputTruncated,\n\t\t\tstatus: \"ok\",\n\t\t\tsettled: false,\n\t\t\tresolve: result.resolve,\n\t\t\treject: result.reject,\n\t\t};\n\t\tthis.pendingBackgroundOutput = \"\";\n\t\tthis.pendingBackgroundOutputTruncated = false;\n\t\tlet abortTimer: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tconst clearAbortTimer = () => {\n\t\t\tif (abortTimer) {\n\t\t\t\tglobalThis.clearTimeout(abortTimer);\n\t\t\t\tabortTimer = undefined;\n\t\t\t}\n\t\t};\n\t\tconst forceAbort = () => {\n\t\t\tif (this.activeExecution !== execution) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\texecution.status = \"aborted\";\n\t\t\t// The execution stays active until its done event arrives; clearing it\n\t\t\t// early would let a new cell race the interrupted one (see busy-after-interrupt).\n\t\t\tthis.resolveExecution(execution, { clearActive: false });\n\t\t};\n\t\tconst onAbort = () => {\n\t\t\tvoid this.interrupt().catch(() => undefined);\n\t\t\tclearAbortTimer();\n\t\t\tabortTimer = globalThis.setTimeout(forceAbort, KERNEL_ABORT_GRACE_MS);\n\t\t\tif (abortTimer && typeof abortTimer === \"object\" && \"unref\" in abortTimer) {\n\t\t\t\tabortTimer.unref();\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tthis.activeExecution = execution;\n\t\t\topts.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tif (opts.signal?.aborted) {\n\t\t\t\tonAbort();\n\t\t\t}\n\t\t\tif (!opts.internal) {\n\t\t\t\tthis.lastCellCode = code;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst sendPromise = this.writeLine({ ...requestFields, id: requestId });\n\t\t\t\tsendPromise.catch(() => undefined);\n\t\t\t\tawait Promise.race([sendPromise, result.promise.then(() => undefined)]);\n\t\t\t\tif (this.activeExecution === execution && execution.status !== \"aborted\") {\n\t\t\t\t\tawait sendPromise;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (this.activeExecution === execution) {\n\t\t\t\t\tthis.activeExecution = undefined;\n\t\t\t\t}\n\t\t\t\tthrow error instanceof Error ? error : new Error(String(error));\n\t\t\t}\n\t\t\treturn await result.promise;\n\t\t} finally {\n\t\t\tclearAbortTimer();\n\t\t\topts.signal?.removeEventListener(\"abort\", onAbort);\n\t\t}\n\t}\n\n\tprivate appendBackgroundOutput(text: string): void {\n\t\tif (!text) return;\n\t\tconst execution = this.activeExecution;\n\t\tif (execution) {\n\t\t\tif (execution.backgroundOutput.length >= MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\t\texecution.backgroundOutputTruncated = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\texecution.backgroundOutput += text;\n\t\t\tif (execution.backgroundOutput.length > MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\t\texecution.backgroundOutput = execution.backgroundOutput.slice(0, MAX_BACKGROUND_OUTPUT_CHARS);\n\t\t\t\texecution.backgroundOutputTruncated = true;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (this.pendingBackgroundOutput.length >= MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\tthis.pendingBackgroundOutputTruncated = true;\n\t\t\treturn;\n\t\t}\n\t\tthis.pendingBackgroundOutput += text;\n\t\tif (this.pendingBackgroundOutput.length > MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\tthis.pendingBackgroundOutput = this.pendingBackgroundOutput.slice(0, MAX_BACKGROUND_OUTPUT_CHARS);\n\t\t\tthis.pendingBackgroundOutputTruncated = true;\n\t\t}\n\t}\n\n\tprivate finishActiveExecution(execution: ActiveExecution): void {\n\t\tif (this.activeExecution !== execution) {\n\t\t\treturn;\n\t\t}\n\t\tthis.resolveExecution(execution, { clearActive: true });\n\t}\n\n\tprivate resolveExecution(execution: ActiveExecution, options: { clearActive: boolean }): void {\n\t\tconst didClearActive = options.clearActive && this.activeExecution === execution;\n\t\tif (options.clearActive && this.activeExecution === execution) {\n\t\t\tthis.activeExecution = undefined;\n\t\t}\n\t\tif (!execution.settled) {\n\t\t\texecution.settled = true;\n\t\t\tif (execution.opts.onLateSentAgentMessage) {\n\t\t\t\tthis.registerLateSentAgentMessageHandler(execution.requestId, execution.opts.onLateSentAgentMessage);\n\t\t\t}\n\n\t\t\tlet stdout = execution.stdout;\n\t\t\tlet stderr = execution.stderr;\n\t\t\tlet result = execution.result;\n\t\t\tlet status = execution.status;\n\t\t\tif (execution.stdoutTruncated) stdout += `\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\tif (execution.stderrTruncated) stderr += `\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\tif (result !== undefined && result.length > execution.maxChars) {\n\t\t\t\tresult = `${result.slice(0, execution.maxChars)}\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\t}\n\n\t\t\tif (execution.opts.signal?.aborted) status = \"aborted\";\n\n\t\t\tlet backgroundOutput = execution.backgroundOutput;\n\t\t\tif (execution.backgroundOutputTruncated) {\n\t\t\t\tbackgroundOutput += `\\n[... background output truncated at ${MAX_BACKGROUND_OUTPUT_CHARS} chars ...]`;\n\t\t\t}\n\n\t\t\texecution.resolve({\n\t\t\t\tstdout,\n\t\t\t\tstderr,\n\t\t\t\tresult,\n\t\t\t\tdiffs: execution.diffs.length > 0 ? execution.diffs : undefined,\n\t\t\t\tattachments: execution.attachments.length > 0 ? execution.attachments : undefined,\n\t\t\t\tsentAgentMessages: execution.sentAgentMessages.length > 0 ? execution.sentAgentMessages : undefined,\n\t\t\t\tbackgroundOutput: backgroundOutput.length > 0 ? backgroundOutput : undefined,\n\t\t\t\terror: execution.error,\n\t\t\t\tstatus,\n\t\t\t\tdurationMs: Date.now() - execution.started,\n\t\t\t\tdoneFields: execution.doneFields,\n\t\t\t});\n\t\t}\n\t\tif (didClearActive) {\n\t\t\tthis.notifyActiveExecutionIdle();\n\t\t}\n\t}\n\n\tprivate dispatchLateSentAgentMessage(requestId: string | undefined, value: unknown): boolean {\n\t\tconst sentAgentMessage = parseSentAgentMessage(value);\n\t\tif (!sentAgentMessage || !requestId) {\n\t\t\treturn false;\n\t\t}\n\t\tconst handler = this.lateSentAgentMessageHandlers.get(requestId);\n\t\tif (!handler) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.lateSentAgentMessageHandlers.delete(requestId);\n\t\tthis.lateSentAgentMessageHandlers.set(requestId, handler);\n\t\thandler(sentAgentMessage);\n\t\treturn true;\n\t}\n\n\tprivate registerLateSentAgentMessageHandler(\n\t\trequestId: string,\n\t\thandler: (message: KernelSentAgentMessage) => void,\n\t): void {\n\t\tthis.lateSentAgentMessageHandlers.set(requestId, handler);\n\t\twhile (this.lateSentAgentMessageHandlers.size > MAX_LATE_SENT_AGENT_MESSAGE_HANDLERS) {\n\t\t\tconst oldestRequestId = this.lateSentAgentMessageHandlers.keys().next().value;\n\t\t\tif (oldestRequestId === undefined) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.lateSentAgentMessageHandlers.delete(oldestRequestId);\n\t\t}\n\t}\n\n\tprivate rejectActiveExecution(error: Error): void {\n\t\tconst execution = this.activeExecution;\n\t\tif (!execution) {\n\t\t\treturn;\n\t\t}\n\t\tthis.activeExecution = undefined;\n\t\texecution.reject(error);\n\t\tthis.notifyActiveExecutionIdle();\n\t}\n\n\tprivate notifyActiveExecutionIdle(): void {\n\t\tfor (const resolve of this.activeExecutionIdleWaiters) {\n\t\t\tresolve();\n\t\t}\n\t\tthis.activeExecutionIdleWaiters.clear();\n\t}\n\n\tprivate waitForActiveExecutionToClear(signal: AbortSignal | undefined, timeoutMs: number): Promise<boolean> {\n\t\tif (!this.activeExecution) {\n\t\t\treturn Promise.resolve(true);\n\t\t}\n\t\treturn new Promise<boolean>((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\t\tconst finish = (cleared: boolean) => {\n\t\t\t\tif (settled) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tsettled = true;\n\t\t\t\tif (timeout) {\n\t\t\t\t\tglobalThis.clearTimeout(timeout);\n\t\t\t\t}\n\t\t\t\tthis.activeExecutionIdleWaiters.delete(onIdle);\n\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(cleared);\n\t\t\t};\n\t\t\tconst onIdle = () => finish(true);\n\t\t\tconst onAbort = () => finish(false);\n\t\t\tthis.activeExecutionIdleWaiters.add(onIdle);\n\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\ttimeout = globalThis.setTimeout(() => finish(false), timeoutMs);\n\t\t\tif (timeout && typeof timeout === \"object\" && \"unref\" in timeout) {\n\t\t\t\ttimeout.unref();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async waitForActiveExecutionToClearForReuse(signal?: AbortSignal): Promise<void> {\n\t\tconst started = Date.now();\n\t\twhile (this.activeExecution && Date.now() - started < KERNEL_BUSY_REUSE_WAIT_MS) {\n\t\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t\t}\n\t\t\tvoid this.interrupt().catch(() => undefined);\n\t\t\tconst remaining = KERNEL_BUSY_REUSE_WAIT_MS - (Date.now() - started);\n\t\t\tconst cleared = await this.waitForActiveExecutionToClear(\n\t\t\t\tsignal,\n\t\t\t\tMath.max(1, Math.min(KERNEL_BUSY_INTERRUPT_INTERVAL_MS, remaining)),\n\t\t\t);\n\t\t\tif (cleared || signal?.aborted) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (this.activeExecution) {\n\t\t\tthrow new KernelBusyAfterInterruptError();\n\t\t}\n\t}\n\n\tprivate startHostRequest(requestId: string, data: unknown): void {\n\t\tif (this.handledHostRequestIds.has(requestId)) {\n\t\t\treturn;\n\t\t}\n\t\tthis.handledHostRequestIds.add(requestId);\n\t\twhile (this.handledHostRequestIds.size > MAX_HANDLED_HOST_REQUEST_IDS) {\n\t\t\tconst oldest = this.handledHostRequestIds.values().next().value;\n\t\t\tif (oldest === undefined) break;\n\t\t\tthis.handledHostRequestIds.delete(oldest);\n\t\t}\n\n\t\tconst task = (async () => {\n\t\t\ttry {\n\t\t\t\tconst result = await this.handleHostRequest(data);\n\t\t\t\ttry {\n\t\t\t\t\tawait this.writeLine({ type: \"host_reply\", id: requestId, data: { status: \"ok\", ...result } });\n\t\t\t\t} catch (replyError) {\n\t\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t\t`failed to send host request ok reply for ${requestId}: ${errorMessage(replyError)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.appendKernelDiagnostic(`host request failed for ${requestId}: ${errorMessage(error)}`);\n\t\t\t\ttry {\n\t\t\t\t\tawait this.writeLine({\n\t\t\t\t\t\ttype: \"host_reply\",\n\t\t\t\t\t\tid: requestId,\n\t\t\t\t\t\tdata: { status: \"error\", error: errorMessage(error) },\n\t\t\t\t\t});\n\t\t\t\t} catch (replyError) {\n\t\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t\t`failed to send host request error reply for ${requestId}: ${errorMessage(replyError)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t})();\n\t\tthis.inFlightHostRequests.add(task);\n\t\tvoid task.finally(() => {\n\t\t\tthis.inFlightHostRequests.delete(task);\n\t\t});\n\t}\n\n\tprivate async handleHostRequest(data: unknown): Promise<Record<string, unknown>> {\n\t\tif (!isRecord(data)) {\n\t\t\tthrow new Error(\"host request payload must be an object\");\n\t\t}\n\t\tif (typeof data.type !== \"string\" || data.type.length === 0) {\n\t\t\tthrow new Error(\"host request payload must have a string type\");\n\t\t}\n\n\t\tconst handler = this.options.hostHandlers?.[data.type];\n\t\tif (!handler) {\n\t\t\tthrow new Error(`host request type \"${data.type}\" is not available in this session`);\n\t\t}\n\t\t// Tag the request with the cell that triggered it. A blocking call is still\n\t\t// the in-flight execution; detached spawns (asyncio.create_task) fire after\n\t\t// the scheduling cell goes idle, so fall back to that last cell's source.\n\t\tconst cellSourceCode = this.activeExecution?.code ?? this.lastCellCode;\n\t\treturn handler({ ...data, cellSourceCode });\n\t}\n\n\tprivate async interrupt(): Promise<void> {\n\t\tconst requestId = this.activeExecution?.requestId;\n\t\tif (!requestId) return;\n\t\tawait this.writeLine({ type: \"interrupt\", id: requestId });\n\t}\n\n\tprivate cleanupResources(killSignal: NodeJS.Signals = \"SIGTERM\"): void {\n\t\tthis.startGeneration++; // any teardown invalidates in-flight starts\n\t\tthis.clearSnapshotTimer();\n\t\tthis.lateSentAgentMessageHandlers.clear();\n\t\tthis.pendingDoneWaiters.clear();\n\t\t// Stale pre-teardown background output must not surface after a restart.\n\t\tthis.pendingBackgroundOutput = \"\";\n\t\tthis.pendingBackgroundOutputTruncated = false;\n\t\tthis.rejectActiveExecution(new Error(\"Kernel has been shut down\"));\n\t\tconst child = this.child;\n\t\tthis.child = undefined;\n\t\tthis.readyDeferred = undefined;\n\t\tif (child) {\n\t\t\tchild.stdin?.destroy();\n\t\t\tchild.stdout?.destroy();\n\t\t\tchild.stderr?.destroy();\n\t\t\tconst pid = child.pid;\n\t\t\tlet signaled = false;\n\t\t\ttry {\n\t\t\t\tsignaled = child.kill(killSignal);\n\t\t\t} catch {\n\t\t\t\t// The kernel has already exited.\n\t\t\t}\n\t\t\t// Inactive only when the signal proved the pid still named our un-reaped child.\n\t\t\tif (pid !== undefined && signaled) recordOrphanProcessState(pid, false);\n\t\t\t// A killed/crashed kernel cannot run its own shutdown hook, so the host\n\t\t\t// reaps the bash() process groups it journaled under this kernel pid.\n\t\t\tif (pid !== undefined) reapKernelOrphanProcesses(pid);\n\t\t}\n\t\tthis.startPromise = undefined;\n\t}\n\n\tprivate async waitForKernelExit(): Promise<void> {\n\t\tconst child = this.child;\n\t\tif (!child) return;\n\t\tif (child.exitCode !== null || child.signalCode !== null) return;\n\t\tawait new Promise<void>((resolve) => child.once(\"exit\", () => resolve()));\n\t}\n\n\tprivate async waitForHostRequestsToSettle(tasks: Promise<void>[], timeoutMs: number): Promise<void> {\n\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tconst timeoutPromise = new Promise<\"timeout\">((resolve) => {\n\t\t\ttimeout = globalThis.setTimeout(() => resolve(\"timeout\"), timeoutMs);\n\t\t\tif (timeout && typeof timeout === \"object\" && \"unref\" in timeout) {\n\t\t\t\ttimeout.unref();\n\t\t\t}\n\t\t});\n\n\t\tconst result = await Promise.race([Promise.allSettled(tasks).then(() => \"settled\" as const), timeoutPromise]);\n\t\tif (timeout) {\n\t\t\tglobalThis.clearTimeout(timeout);\n\t\t}\n\t\tif (result === \"timeout\") {\n\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t`timed out waiting ${timeoutMs}ms for ${tasks.length} host request task(s) during dispose`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Resolves true when this call performed the cleanup (false: a concurrent teardown won). */\n\tasync shutdown(opts: { snapshot?: boolean } = {}): Promise<boolean> {\n\t\tif (this.state === \"shutdown\") {\n\t\t\tliveKernels.delete(this);\n\t\t\tthis.cleanupResources();\n\t\t\treturn true;\n\t\t}\n\t\t// Captured before any await: teardowns and newer starts bump the counter.\n\t\tconst generation = this.startGeneration;\n\t\t// Best-effort final flush (bounded) before teardown — used by signal handlers\n\t\t// so a SIGINT/SIGTERM exit doesn't lose work the debounced snapshot hasn't saved.\n\t\tif (opts.snapshot) {\n\t\t\tawait this.flushSnapshotForDispose();\n\t\t\tif (this.startStale(generation)) return false; // superseded mid-flush: the newer owner already cleaned this kernel\n\t\t}\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\t// Claim the teardown: our own child's exit handler must not run cleanupResources\n\t\t// (which bumps the generation and would misread this call as superseded). A\n\t\t// concurrent kill()/dispose() still bumps the generation and supersedes us.\n\t\tthis.gracefulShutdownGeneration = generation;\n\n\t\tlet shutdownTimer: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tlet doneWaiterId: string | undefined;\n\t\tlet performedCleanup = false;\n\t\tconst shutdownDeadline = new Promise<never>((_resolve, reject) => {\n\t\t\tshutdownTimer = globalThis.setTimeout(\n\t\t\t\t() => reject(new Error(`Kernel did not shut down within ${KERNEL_SHUTDOWN_TIMEOUT_MS}ms`)),\n\t\t\t\tKERNEL_SHUTDOWN_TIMEOUT_MS,\n\t\t\t);\n\t\t\tshutdownTimer.unref?.();\n\t\t});\n\t\ttry {\n\t\t\tif (this.child?.stdin && !this.child.stdin.destroyed) {\n\t\t\t\tconst requestId = uuid();\n\t\t\t\tdoneWaiterId = requestId;\n\t\t\t\tconst doneReply = new Promise<void>((resolve) => {\n\t\t\t\t\tthis.pendingDoneWaiters.set(requestId, resolve);\n\t\t\t\t});\n\t\t\t\tconst send = this.writeLine({ type: \"shutdown\", id: requestId });\n\t\t\t\tsend.catch(() => undefined);\n\t\t\t\t// A kernel that exits without delivering its shutdown done must not stall the deadline.\n\t\t\t\tconst kernelExit = this.waitForKernelExit();\n\t\t\t\tconst gracefulReply = Promise.all([send, doneReply]);\n\t\t\t\t// Abandoned by the race, a late send failure must not reject unhandled.\n\t\t\t\tgracefulReply.catch(() => undefined);\n\t\t\t\tawait Promise.race([gracefulReply, kernelExit, shutdownDeadline]);\n\t\t\t\tawait Promise.race([kernelExit, shutdownDeadline]);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t`graceful shutdown failed (killing instead): ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t} finally {\n\t\t\tif (shutdownTimer) globalThis.clearTimeout(shutdownTimer);\n\t\t\tif (doneWaiterId) this.pendingDoneWaiters.delete(doneWaiterId);\n\t\t\tif (this.gracefulShutdownGeneration === generation) this.gracefulShutdownGeneration = undefined;\n\t\t\t// A superseded shutdown must not tear down the newer start's kernel. Ownership is decided\n\t\t\t// here, before cleanupResources bumps the generation and would misread this call as superseded.\n\t\t\tif (!this.startStale(generation)) {\n\t\t\t\tthis.cleanupResources();\n\t\t\t\tperformedCleanup = true;\n\t\t\t}\n\t\t}\n\n\t\treturn performedCleanup;\n\t}\n\n\tasync restart(): Promise<void> {\n\t\tconst prev = this.executionQueue;\n\t\tlet resolveNext: () => void = () => {};\n\t\tthis.executionQueue = new Promise<void>((r) => {\n\t\t\tresolveNext = r;\n\t\t});\n\t\tawait prev;\n\n\t\ttry {\n\t\t\tconst performedCleanup = await this.shutdown();\n\t\t\tif (!performedCleanup) return;\n\t\t\tthis.state = \"idle\";\n\t\t\tthis.kernelStderr = \"\";\n\t\t\tawait this.start();\n\t\t} finally {\n\t\t\tresolveNext();\n\t\t}\n\t}\n\n\tasync kill(): Promise<void> {\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.cleanupResources(\"SIGKILL\");\n\t}\n\n\t/**\n\t * Serialize the user namespace to disk (best-effort, per-variable). No-op when\n\t * the kernel isn't running or no snapshot target was configured. Never throws.\n\t */\n\tasync snapshotState(): Promise<SnapshotResult | null> {\n\t\treturn this.captureSnapshot();\n\t}\n\n\t/** Persist the namespace, then remove variables above the per-variable cap. */\n\tasync pruneOversizedVariables(): Promise<SnapshotResult | null> {\n\t\treturn this.captureSnapshot({ executionTimeoutMs: SNAPSHOT_EXECUTION_TIMEOUT_MS, pruneOversized: true });\n\t}\n\n\tprivate async captureSnapshot(\n\t\toptions: { executionTimeoutMs?: number; pruneOversized?: boolean } = {},\n\t): Promise<SnapshotResult | null> {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg || !this.isRunning) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest(\n\t\t\t\t{\n\t\t\t\t\ttype: \"snapshot\",\n\t\t\t\t\tpath: cfg.path,\n\t\t\t\t\tmanifest_path: cfg.manifestPath,\n\t\t\t\t\tmax_bytes: cfg.maxBytes ?? DEFAULT_SNAPSHOT_MAX_BYTES,\n\t\t\t\t\tmax_variable_bytes: cfg.maxVariableBytes ?? DEFAULT_SNAPSHOT_MAX_VARIABLE_BYTES,\n\t\t\t\t\tprune_oversized: options.pruneOversized ?? false,\n\t\t\t\t},\n\t\t\t\t\"\",\n\t\t\t\t{ internal: true },\n\t\t\t\toptions.executionTimeoutMs,\n\t\t\t);\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t`state snapshot ${r.status === \"aborted\" ? \"timed out\" : \"failed\"}: ${r.error?.evalue ?? r.stderr}`,\n\t\t\t\t);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst pruned = asStringArray(r.doneFields.pruned);\n\t\t\treturn {\n\t\t\t\tsaved: asStringArray(r.doneFields.saved),\n\t\t\t\tskipped: asReasonArray(r.doneFields.skipped),\n\t\t\t\tpruned: pruned.length > 0 ? pruned : undefined,\n\t\t\t\tbytes: typeof r.doneFields.bytes === \"number\" ? r.doneFields.bytes : 0,\n\t\t\t\tpath: cfg.path,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`state snapshot error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Revive a previously snapshotted namespace into the kernel. Call right after\n\t * start() and before the runtime bootstrap, which then refreshes live handles\n\t * (rlm, skills) over anything restored. Never throws.\n\t */\n\tasync restoreState(): Promise<RestoreResult | null> {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest({ type: \"restore\", path: cfg.path }, \"\", { internal: true });\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(`state restore failed: ${r.error?.evalue ?? r.stderr}`);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\trestored: asStringArray(r.doneFields.restored),\n\t\t\t\tfailed: asReasonArray(r.doneFields.failed),\n\t\t\t\tpath: cfg.path,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`state restore error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/** Live user-defined top-level names, or null if the kernel isn't running. Never throws. */\n\tasync listNamespaceNames(signal?: AbortSignal): Promise<string[] | null> {\n\t\tif (!this.isRunning) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest({ type: \"list_names\" }, \"\", { internal: true, signal });\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(`namespace listing failed: ${r.error?.evalue ?? r.stderr}`);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn asStringArray(r.doneFields.names);\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`namespace listing error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tprivate scheduleSnapshot(): void {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg) return;\n\t\tif (this.snapshotTimer) clearTimeout(this.snapshotTimer);\n\t\tthis.snapshotTimer = globalThis.setTimeout(() => {\n\t\t\tthis.snapshotTimer = undefined;\n\t\t\tvoid this.captureSnapshot({ executionTimeoutMs: SNAPSHOT_EXECUTION_TIMEOUT_MS });\n\t\t}, cfg.debounceMs ?? DEFAULT_SNAPSHOT_DEBOUNCE_MS);\n\t\tif (this.snapshotTimer && typeof this.snapshotTimer === \"object\" && \"unref\" in this.snapshotTimer) {\n\t\t\tthis.snapshotTimer.unref();\n\t\t}\n\t}\n\n\tprivate clearSnapshotTimer(): void {\n\t\tif (this.snapshotTimer) {\n\t\t\tclearTimeout(this.snapshotTimer);\n\t\t\tthis.snapshotTimer = undefined;\n\t\t}\n\t}\n\n\t/** Best-effort final snapshot before a graceful dispose, bounded by a timeout. */\n\tprivate async flushSnapshotForDispose(): Promise<void> {\n\t\tif (!this.options.snapshot || !this.isRunning) return;\n\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tconst guard = new Promise<void>((resolve) => {\n\t\t\ttimeout = globalThis.setTimeout(resolve, SNAPSHOT_DISPOSE_TIMEOUT_MS);\n\t\t\tif (timeout && typeof timeout === \"object\" && \"unref\" in timeout) timeout.unref();\n\t\t});\n\t\ttry {\n\t\t\tawait Promise.race([this.snapshotState().then(() => undefined), guard]);\n\t\t} finally {\n\t\t\tif (timeout) clearTimeout(timeout);\n\t\t}\n\t}\n\n\t/** Graceful cleanup. Waits briefly for in-flight host request handlers before killing the child. */\n\tdispose(): Promise<void> {\n\t\treturn (async () => {\n\t\t\t// Captured before any await: teardowns and newer starts bump the counter.\n\t\t\tconst generation = this.startGeneration;\n\t\t\t// Final namespace flush while the kernel is still live (session end / reload).\n\t\t\tawait this.flushSnapshotForDispose();\n\t\t\tif (this.startStale(generation)) return; // superseded mid-flush: the newer owner already cleaned this kernel\n\t\t\tthis.state = \"shutdown\";\n\t\t\tliveKernels.delete(this);\n\t\t\t// Claim the teardown so the child's exit handler does not run\n\t\t\t// cleanupResources mid-dispose (same contract as shutdown()).\n\t\t\tthis.gracefulShutdownGeneration = generation;\n\t\t\tconst inFlightHostRequests = [...this.inFlightHostRequests];\n\t\t\ttry {\n\t\t\t\tif (inFlightHostRequests.length > 0) {\n\t\t\t\t\tawait this.waitForHostRequestsToSettle(inFlightHostRequests, HOST_REQUEST_DISPOSE_TIMEOUT_MS);\n\t\t\t\t}\n\t\t\t\tif (!this.startStale(generation)) {\n\t\t\t\t\t// Bounded protocol shutdown first: the runtime's shutdown branch\n\t\t\t\t\t// closes MCP servers and kills live bash() process groups, which\n\t\t\t\t\t// a bare hard-kill would leak until the orphan reaper runs.\n\t\t\t\t\tawait this.requestProtocolShutdown(KERNEL_SHUTDOWN_TIMEOUT_MS);\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tif (this.gracefulShutdownGeneration === generation) this.gracefulShutdownGeneration = undefined;\n\t\t\t\tif (!this.startStale(generation)) this.cleanupResources(); // else: superseded, the newer owner already cleaned\n\t\t\t}\n\t\t})();\n\t}\n\n\t/** Best-effort bounded protocol shutdown; the caller's hard kill remains the backstop. */\n\tprivate async requestProtocolShutdown(timeoutMs: number): Promise<void> {\n\t\tconst stdin = this.child?.stdin;\n\t\tif (!stdin || stdin.destroyed) return;\n\t\tconst requestId = uuid();\n\t\tlet timer: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\ttry {\n\t\t\tconst doneReply = new Promise<void>((resolve) => {\n\t\t\t\tthis.pendingDoneWaiters.set(requestId, resolve);\n\t\t\t});\n\t\t\tconst send = this.writeLine({ type: \"shutdown\", id: requestId });\n\t\t\tsend.catch(() => undefined);\n\t\t\tconst kernelExit = this.waitForKernelExit();\n\t\t\tconst deadline = new Promise<void>((resolve) => {\n\t\t\t\ttimer = globalThis.setTimeout(resolve, timeoutMs);\n\t\t\t\ttimer.unref?.();\n\t\t\t});\n\t\t\tconst gracefulReply = Promise.all([send, doneReply]).then(() => undefined);\n\t\t\tgracefulReply.catch(() => undefined);\n\t\t\tawait Promise.race([gracefulReply, kernelExit, deadline]);\n\t\t\tawait Promise.race([kernelExit, deadline]);\n\t\t} catch {\n\t\t\t// Best-effort: cleanupResources still hard-kills the child.\n\t\t} finally {\n\t\t\tif (timer) globalThis.clearTimeout(timer);\n\t\t\tthis.pendingDoneWaiters.delete(requestId);\n\t\t}\n\t}\n\n\t/** Synchronous best-effort cleanup. Safe to call from `process.on('exit')`. */\n\tdisposeSync(): void {\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.cleanupResources();\n\t}\n\n\tget isRunning(): boolean {\n\t\treturn this.state === \"running\";\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"repl-manager.js","sourceRoot":"","sources":["../../../src/core/kernel/repl-manager.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,iFAA+E;AAC/E,uFAAuF;AACvF,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACnG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EACN,0BAA0B,EAC1B,uBAAuB,EACvB,cAAc,EACd,6BAA6B,EAC7B,wBAAwB,EACxB,4BAA4B,EAC5B,iBAAiB,EAGjB,YAAY,EACZ,gCAAgC,EAChC,yBAAyB,EACzB,QAAQ,EACR,qBAAqB,EACrB,iCAAiC,EACjC,yBAAyB,EACzB,0BAA0B,EAE1B,6BAA6B,EAM7B,WAAW,EACX,yBAAyB,EACzB,oCAAoC,EACpC,sBAAsB,EACtB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,6BAA6B,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,0BAA0B,EAC1B,mCAAmC,GAGnC,MAAM,qBAAqB,CAAC;AAE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xB,OAAO,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC;IAAA,CAChC;CACD","sourcesContent":["// Kernel client for the REPL runtime: the kernel is a JSON-lines subprocess\n// (`python -m rlm.repl`) — requests on stdin, events on stdout, stderr kept as\n// a diagnostics tail. The protocol is documented in asm-agent-runtime/src/rlm/repl.md.\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport { v4 as uuid } from \"uuid\";\nimport { reapKernelOrphanProcesses, recordOrphanProcessState } from \"../orphan-process-journal.js\";\nimport { ensureKernelPython } from \"./bootstrap.js\";\nimport {\n\tAGENT_MESSAGE_DISPLAY_MIME,\n\tATTACHMENT_DISPLAY_MIME,\n\tcreateDeferred,\n\tcreateKernelStartupAbortError,\n\tDEFAULT_MAX_OUTPUT_CHARS,\n\tDEFAULT_SNAPSHOT_DEBOUNCE_MS,\n\tDIFF_DISPLAY_MIME,\n\ttype ExecuteOptions,\n\ttype ExecuteResult,\n\terrorMessage,\n\tHOST_REQUEST_SHUTDOWN_TIMEOUT_MS,\n\tinstallSignalHandlersOnce,\n\tisRecord,\n\tKERNEL_ABORT_GRACE_MS,\n\tKERNEL_BUSY_INTERRUPT_INTERVAL_MS,\n\tKERNEL_BUSY_REUSE_WAIT_MS,\n\tKERNEL_SHUTDOWN_TIMEOUT_MS,\n\ttype KernelAttachment,\n\tKernelBusyAfterInterruptError,\n\ttype KernelDiffDisplay,\n\ttype KernelManagerOptions,\n\ttype KernelSentAgentMessage,\n\ttype KernelShutdownOptions,\n\ttype KernelStartOptions,\n\tliveKernels,\n\tMAX_ATTACHMENT_DATA_CHARS,\n\tMAX_LATE_SENT_AGENT_MESSAGE_HANDLERS,\n\tparseAttachmentDisplay,\n\tparseDiffDisplay,\n\tparseSentAgentMessage,\n\traceStartupWithAbort,\n\tSNAPSHOT_EXECUTION_TIMEOUT_MS,\n} from \"./shared.js\";\nimport {\n\tDEFAULT_SNAPSHOT_MAX_BYTES,\n\tDEFAULT_SNAPSHOT_MAX_VARIABLE_BYTES,\n\ttype RestoreResult,\n\ttype SnapshotResult,\n} from \"./state-snapshot.js\";\n\nconst REPL_PROTOCOL_VERSION = 3;\nconst READY_TIMEOUT_MS = 30_000;\nconst REPAIR_STEP_TIMEOUT_MS = 30_000;\n// Runtime-minted host-request ids never repeat; the bound only guards a\n// misbehaving runtime from growing the dedup set forever.\nconst MAX_HANDLED_HOST_REQUEST_IDS = 1024;\n// Cap for unattributed background output buffered between and during cells.\nconst MAX_BACKGROUND_OUTPUT_CHARS = 64 * 1024;\n\n/** ExecuteResult plus the raw fields of the request's `done` event (state ops). */\ninterface InternalExecuteResult extends ExecuteResult {\n\tdoneFields?: Record<string, unknown>;\n}\n\ninterface ActiveExecution {\n\trequestId: string;\n\t/** Source of the cell currently executing; surfaced to rlm.run spawns. */\n\tcode: string;\n\tstarted: number;\n\tmaxChars: number;\n\topts: ExecuteOptions;\n\tstdout: string;\n\tstderr: string;\n\tstdoutTruncated: boolean;\n\tstderrTruncated: boolean;\n\tresult?: string;\n\tdiffs: KernelDiffDisplay[];\n\tattachments: KernelAttachment[];\n\tsentAgentMessages: KernelSentAgentMessage[];\n\t/** Stream text without this execution's id: user threads, other cells' leftovers, raw fd writes. */\n\tbackgroundOutput: string;\n\tbackgroundOutputTruncated: boolean;\n\terror?: ExecuteResult[\"error\"];\n\tstatus: ExecuteResult[\"status\"];\n\tdoneFields?: Record<string, unknown>;\n\tsettled: boolean;\n\tresolve: (result: InternalExecuteResult) => void;\n\treject: (error: Error) => void;\n}\n\n// Complete event vocabulary of protocol version 2 (see asm-agent-runtime/src/rlm/repl.md).\n// The version handshake is exact, so an unknown kind is corruption, not a newer runtime.\nconst PROTOCOL_EVENT_KINDS = new Set([\n\t\"ready\",\n\t\"stdout\",\n\t\"stderr\",\n\t\"result\",\n\t\"display\",\n\t\"host_request\",\n\t\"error\",\n\t\"done\",\n]);\n\n/**\n * Reason a JSON object still isn't a valid protocol frame, or undefined.\n * `done` and `host_request` route strictly by non-empty string id (the runtime\n * mints uuid hex ids and echoes the host's uuids); silently dropping an id-less\n * one would leave the awaiting request unsettled forever.\n */\nfunction invalidProtocolFrameReason(event: Record<string, unknown>): string | undefined {\n\tif (typeof event.event !== \"string\" || !PROTOCOL_EVENT_KINDS.has(event.event)) {\n\t\treturn \"unknown protocol event\";\n\t}\n\tif (\n\t\t(event.event === \"done\" || event.event === \"host_request\") &&\n\t\t(typeof event.id !== \"string\" || event.id === \"\")\n\t) {\n\t\treturn `${event.event} frame without id`;\n\t}\n\treturn undefined;\n}\n\nfunction asStringArray(value: unknown): string[] {\n\treturn Array.isArray(value) ? value.filter((v): v is string => typeof v === \"string\") : [];\n}\n\nfunction asReasonArray(value: unknown): { name: string; reason: string }[] {\n\tif (!Array.isArray(value)) return [];\n\treturn value.flatMap((entry) => {\n\t\tif (isRecord(entry) && typeof entry.name === \"string\") {\n\t\t\treturn [{ name: entry.name, reason: typeof entry.reason === \"string\" ? entry.reason : \"\" }];\n\t\t}\n\t\treturn [];\n\t});\n}\n\nexport class ReplKernelManager {\n\tprivate readonly options: Pick<\n\t\tKernelManagerOptions,\n\t\t\"python\" | \"cwd\" | \"env\" | \"sessionId\" | \"hostHandlers\" | \"pythonSkills\" | \"snapshot\" | \"bootstrapCode\"\n\t>;\n\tprivate readonly handledHostRequestIds = new Set<string>();\n\tprivate child?: ChildProcess;\n\tprivate readyDeferred?: ReturnType<typeof createDeferred<number>>;\n\tprivate kernelStderr = \"\";\n\t/** Serializes execute() calls — the runtime runs one request at a time. */\n\tprivate executionQueue: Promise<unknown> = Promise.resolve();\n\tprivate activeExecution?: ActiveExecution;\n\tprivate readonly activeExecutionIdleWaiters = new Set<() => void>();\n\tprivate readonly lateSentAgentMessageHandlers = new Map<string, (message: KernelSentAgentMessage) => void>();\n\t/** Resolvers for done events outside the active execution (the shutdown reply). */\n\tprivate readonly pendingDoneWaiters = new Map<string, () => void>();\n\t// Source of the most recently started cell, retained after it finishes so\n\t// rlm.run spawns from detached asyncio tasks (cell already idle) can still\n\t// attribute their spawning program.\n\tprivate lastCellCode?: string;\n\t/** Unattributed stream text that arrived between cells; surfaced on the next execution. */\n\tprivate pendingBackgroundOutput = \"\";\n\tprivate pendingBackgroundOutputTruncated = false;\n\tprivate readonly inFlightHostRequests = new Set<Promise<void>>();\n\tprivate state: \"idle\" | \"starting\" | \"running\" | \"shutdown\" = \"idle\";\n\t/** Bumped by every teardown so a stale in-flight doStart can never touch a newer kernel. */\n\tprivate startGeneration = 0;\n\t/** Generation whose graceful shutdown() owns the teardown, so the exit handler must not run it. */\n\tprivate gracefulShutdownGeneration?: number;\n\tprivate gracefulShutdownPromise?: Promise<boolean>;\n\t/** Memoized so concurrent callers all await the same in-flight startup. */\n\tprivate startPromise?: Promise<void>;\n\t/** Pending debounced auto-snapshot, if one has been scheduled. */\n\tprivate snapshotTimer?: ReturnType<typeof globalThis.setTimeout>;\n\t/** While the final dispose snapshot is flushing, new external executions are rejected. */\n\tprivate flushingSnapshotForDispose = false;\n\t/** In-flight final snapshot flush; concurrent teardowns join it instead of re-flushing. */\n\tprivate snapshotFlushForDispose?: Promise<void>;\n\t/** Repairs a child whose dedicated protocol stream emitted an invalid frame. */\n\tprivate protocolRepairPromise?: Promise<void>;\n\tprivate protocolRepairOwner?: { superseded: boolean };\n\t/** Corruption seen while still \"starting\" (e.g. ready and garbage in one chunk) fails that start. */\n\tprivate startupProtocolError?: Error;\n\t/** A repair discarded its kernel: the next fresh start must re-run the runtime bootstrap. */\n\tprivate pendingRebootstrap = false;\n\t/** Restore the saved namespace on that fresh start too (false when the snapshot itself is the declared culprit). */\n\tprivate pendingRestore = false;\n\tprivate rebootstrapPromise?: Promise<boolean>;\n\tprivate teardownInFlight = 0;\n\n\tconstructor(options: KernelManagerOptions) {\n\t\tthis.options = {\n\t\t\tpython: options.python,\n\t\t\tcwd: options.cwd,\n\t\t\tenv: options.env,\n\t\t\tsessionId: options.sessionId,\n\t\t\thostHandlers: options.hostHandlers,\n\t\t\tpythonSkills: options.pythonSkills,\n\t\t\tsnapshot: options.snapshot,\n\t\t\tbootstrapCode: options.bootstrapCode,\n\t\t};\n\t}\n\n\tget ownerSessionId(): string | undefined {\n\t\treturn this.options.sessionId;\n\t}\n\n\tprivate appendKernelDiagnostic(message: string): void {\n\t\tthis.kernelStderr += `[kernel] ${message.endsWith(\"\\n\") ? message : `${message}\\n`}`;\n\t}\n\n\tasync start(options: KernelStartOptions = {}): Promise<void> {\n\t\tif (options.signal?.aborted) {\n\t\t\tthrow createKernelStartupAbortError();\n\t\t}\n\t\tif (!this.startPromise) {\n\t\t\tconst startPromise = this.doStart({ onBootstrapProgress: options.onBootstrapProgress }).catch((error) => {\n\t\t\t\t// Only clear our own memoization: a stale start must not evict a newer one.\n\t\t\t\tif (this.startPromise === startPromise) this.startPromise = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\tthis.startPromise = startPromise;\n\t\t}\n\t\treturn raceStartupWithAbort(this.startPromise, options.signal);\n\t}\n\n\tprivate async doStart(startOptions: KernelStartOptions): Promise<void> {\n\t\tif (this.state !== \"idle\") return;\n\t\tconst generation = ++this.startGeneration;\n\t\tthis.state = \"starting\";\n\t\tinstallSignalHandlersOnce();\n\t\t// Tracked from the moment startup begins so session cleanup and signal\n\t\t// handlers can dispose a kernel that is still booting.\n\t\tliveKernels.add(this);\n\n\t\tlet python: string;\n\t\ttry {\n\t\t\tpython =\n\t\t\t\tthis.options.python ??\n\t\t\t\t(await ensureKernelPython({\n\t\t\t\t\tpythonSkills: this.options.pythonSkills,\n\t\t\t\t\tonProgress: startOptions.onBootstrapProgress,\n\t\t\t\t}));\n\t\t\tif (this.startStale(generation)) throw new Error(\"Kernel start superseded\");\n\t\t\tthis.options.python = python;\n\t\t} catch (error) {\n\t\t\tif (this.startStale(generation)) throw error; // never touch a newer start's state\n\t\t\tliveKernels.delete(this);\n\t\t\tif ((this.state as string) !== \"shutdown\") this.state = \"idle\";\n\t\t\tthrow error;\n\t\t}\n\n\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\tthrow new Error(\"Kernel was disposed during startup\");\n\t\t}\n\n\t\tconst child = spawn(python, [\"-m\", \"rlm.repl\"], {\n\t\t\tcwd: this.options.cwd,\n\t\t\t// bash.py journals its process groups under this pid so the host can\n\t\t\t// reap them if the runtime dies without running its shutdown hook.\n\t\t\tenv: {\n\t\t\t\t...process.env,\n\t\t\t\t...this.options.env,\n\t\t\t\tASM_AGENT_KERNEL_OWNER_PID: String(process.pid),\n\t\t\t},\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tthis.child = child;\n\t\tif (child.pid !== undefined) recordOrphanProcessState(child.pid, true);\n\t\tthis.readyDeferred = createDeferred<number>();\n\t\tthis.startupProtocolError = undefined;\n\t\tthis.wireChild(child);\n\n\t\ttry {\n\t\t\tconst protocol = await this.waitForReady(child);\n\t\t\tif (this.startStale(generation)) throw new Error(\"Kernel start superseded\");\n\t\t\t// Ready and a corrupt frame can share one stdout chunk: ready resolved the\n\t\t\t// deferred synchronously before the corruption was parsed, so the rejection\n\t\t\t// in failProtocolFrame was a no-op. Never mark such a child running.\n\t\t\tif (this.startupProtocolError) throw this.startupProtocolError;\n\t\t\tif (protocol !== REPL_PROTOCOL_VERSION) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Kernel runtime speaks protocol ${protocol}, expected ${REPL_PROTOCOL_VERSION}. ` +\n\t\t\t\t\t\t\"Update asm-agent-runtime in the kernel Python (ASM_AGENT_KERNEL_PYTHON) to match this asm-agent.\",\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tif (this.startStale(generation)) throw e; // never tear down a newer start's kernel\n\t\t\tconst canRetryStartup = (this.state as string) !== \"shutdown\";\n\t\t\t// Only the call that performed the cleanup may resurrect to idle; a\n\t\t\t// concurrent kill()/teardown owns the state otherwise.\n\t\t\tif ((await this.shutdown()) && canRetryStartup) this.state = \"idle\";\n\t\t\tthrow e;\n\t\t}\n\n\t\tthis.state = \"running\";\n\t}\n\n\t/** True when a teardown (or newer start) superseded the start that captured `generation`. */\n\tprivate startStale(generation: number): boolean {\n\t\treturn generation !== this.startGeneration;\n\t}\n\n\tprivate wireChild(child: ChildProcess): void {\n\t\tconst decoder = new StringDecoder(\"utf8\");\n\t\tlet buffered = \"\";\n\t\tchild.stdout?.on(\"data\", (buf: Buffer) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tbuffered += decoder.write(buf);\n\t\t\tlet newline = buffered.indexOf(\"\\n\");\n\t\t\twhile (newline !== -1) {\n\t\t\t\tconst line = buffered.slice(0, newline);\n\t\t\t\tbuffered = buffered.slice(newline + 1);\n\t\t\t\tnewline = buffered.indexOf(\"\\n\");\n\t\t\t\tif (!line.trim()) continue;\n\t\t\t\tlet event: unknown;\n\t\t\t\ttry {\n\t\t\t\t\tevent = JSON.parse(line);\n\t\t\t\t} catch {\n\t\t\t\t\tthis.failProtocolFrame(child, `unparseable protocol line: ${line.slice(0, 200)}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!isRecord(event)) {\n\t\t\t\t\tthis.failProtocolFrame(child, `non-object protocol line: ${line.slice(0, 200)}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst invalidReason = invalidProtocolFrameReason(event);\n\t\t\t\tif (invalidReason) {\n\t\t\t\t\tthis.failProtocolFrame(child, `${invalidReason}: ${line.slice(0, 200)}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.handleEvent(event);\n\t\t\t}\n\t\t});\n\n\t\tchild.stderr?.on(\"data\", (buf: Buffer) => {\n\t\t\tthis.kernelStderr += buf.toString();\n\t\t});\n\n\t\tchild.on(\"error\", (err) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tthis.appendKernelDiagnostic(`spawn error: ${err.message}`);\n\t\t\tthis.state = \"shutdown\";\n\t\t\tliveKernels.delete(this);\n\t\t\t// Fail a pending start() promptly instead of letting it ride out the\n\t\t\t// ready timeout. cleanupResources clears readyDeferred, so reject first;\n\t\t\t// a late error after ready resolved is a no-op on the settled promise.\n\t\t\tthis.readyDeferred?.reject(err);\n\t\t\tthis.cleanupResources();\n\t\t});\n\n\t\tchild.on(\"exit\", (code, signal) => {\n\t\t\tif (this.child !== child) return;\n\t\t\tif (this.state !== \"shutdown\") {\n\t\t\t\tthis.appendKernelDiagnostic(`unexpected exit code=${code} signal=${signal}`);\n\t\t\t}\n\t\t\tthis.state = \"shutdown\";\n\t\t\tliveKernels.delete(this);\n\t\t\t// This exit is part of an in-flight graceful shutdown(): that call owns the\n\t\t\t// teardown and runs cleanupResources itself. Cleaning up here would bump the\n\t\t\t// generation and misread the owning shutdown as superseded.\n\t\t\tif (this.gracefulShutdownGeneration === this.startGeneration) return;\n\t\t\tthis.cleanupResources();\n\t\t});\n\t}\n\n\tprivate failProtocolFrame(child: ChildProcess, diagnostic: string): void {\n\t\tif (this.child !== child) return;\n\t\tthis.appendKernelDiagnostic(diagnostic);\n\t\tconst error = new Error(`Kernel protocol error: ${diagnostic}`);\n\t\tif (this.state === \"starting\") this.startupProtocolError = error;\n\t\tthis.readyDeferred?.reject(error);\n\t\tthis.rejectActiveExecution(error);\n\t\tif (this.teardownInFlight > 0 || this.state !== \"running\") return;\n\n\t\tif (this.protocolRepairOwner) {\n\t\t\t// A repair's own replacement child corrupted: discard it instead of respawn-looping.\n\t\t\tthis.appendKernelDiagnostic(\"replacement kernel corrupted during protocol repair; giving up\");\n\t\t\tthis.protocolRepairOwner.superseded = true;\n\t\t\t// performRestore clears pendingRestore, so it still being set means the\n\t\t\t// corruption struck at or before the restore phase: the snapshot stays\n\t\t\t// the prime suspect (ambiguous attribution, loop-safe — retrying it\n\t\t\t// would re-trigger the corruption). Corruption strictly after a\n\t\t\t// successful restore never implicates the snapshot; keeping the flag\n\t\t\t// costs at most one bounded restore per later attempt.\n\t\t\tconst snapshotSuspect = this.pendingRestore;\n\t\t\tthis.killChildToIdle();\n\t\t\tif (snapshotSuspect) this.pendingRestore = false;\n\t\t\treturn;\n\t\t}\n\t\tconst owner = { superseded: false };\n\t\tthis.protocolRepairOwner = owner;\n\t\tconst repair = this.repairProtocolChild(child, owner);\n\t\tthis.protocolRepairPromise = repair;\n\t\tvoid repair.then(\n\t\t\t() => {\n\t\t\t\tif (this.protocolRepairPromise === repair) this.protocolRepairPromise = undefined;\n\t\t\t\tif (this.protocolRepairOwner === owner) this.protocolRepairOwner = undefined;\n\t\t\t},\n\t\t\t(repairError) => {\n\t\t\t\tthis.appendKernelDiagnostic(`protocol repair failed: ${errorMessage(repairError)}`);\n\t\t\t\tif (this.protocolRepairPromise === repair) this.protocolRepairPromise = undefined;\n\t\t\t\tif (this.protocolRepairOwner === owner) this.protocolRepairOwner = undefined;\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate async repairProtocolChild(child: ChildProcess, owner: { superseded: boolean }): Promise<void> {\n\t\tif (this.child !== child || this.state === \"shutdown\") return;\n\t\tthis.killChildToIdle();\n\n\t\tconst start = this.start();\n\t\tconst generation = this.startGeneration;\n\t\ttry {\n\t\t\tawait start;\n\t\t} catch (error) {\n\t\t\tthis.finishFailedProtocolRepair(owner, error);\n\t\t\treturn;\n\t\t}\n\t\tif (this.startStale(generation) || (this.state as string) !== \"running\") {\n\t\t\tthis.finishFailedProtocolRepair(owner);\n\t\t\treturn;\n\t\t}\n\n\t\tconst restored = await this.performRestore(true);\n\t\tif (this.startStale(generation) || (this.state as string) !== \"running\") {\n\t\t\tthis.finishFailedProtocolRepair(owner);\n\t\t\treturn;\n\t\t}\n\t\tif (this.options.snapshot && restored === null) {\n\t\t\tif (owner.superseded || this.protocolRepairOwner !== owner) return;\n\t\t\tthis.appendKernelDiagnostic(\"protocol repair restore failed; discarding replacement kernel\");\n\t\t\tthis.killChildToIdle();\n\t\t\t// The snapshot is the declared culprit; the lazy path must not retry it.\n\t\t\tthis.pendingRestore = false;\n\t\t\treturn;\n\t\t}\n\n\t\t// Restore revives only the user namespace; live handles (rlm, bash, skills)\n\t\t// come from the runtime bootstrap, so a repaired kernel must re-run it.\n\t\tif (!this.options.bootstrapCode) return;\n\t\tconst bootstrapped = await this.bootstrapRepairedKernel(this.options.bootstrapCode);\n\t\tif (this.startStale(generation) || (this.state as string) !== \"running\") {\n\t\t\tthis.finishFailedProtocolRepair(owner);\n\t\t\treturn;\n\t\t}\n\t\tif (!bootstrapped) {\n\t\t\tif (owner.superseded || this.protocolRepairOwner !== owner) return;\n\t\t\tthis.appendKernelDiagnostic(\"protocol repair bootstrap failed; discarding replacement kernel\");\n\t\t\tthis.killChildToIdle();\n\t\t}\n\t}\n\n\t/** Bounded bootstrap of a repaired kernel; false when it failed. Never throws. */\n\tprivate async bootstrapRepairedKernel(code: string): Promise<boolean> {\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest(\n\t\t\t\t{ type: \"execute\", code },\n\t\t\t\tcode,\n\t\t\t\t{ internal: true, protocolRepair: true },\n\t\t\t\tREPAIR_STEP_TIMEOUT_MS,\n\t\t\t);\n\t\t\tif (r.status !== \"ok\") {\n\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t`protocol repair bootstrap ${r.status === \"aborted\" ? \"timed out\" : \"failed\"}: ${r.error?.evalue ?? r.stderr}`,\n\t\t\t\t);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.pendingRebootstrap = false;\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`protocol repair bootstrap error: ${errorMessage(error)}`);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * A fresh kernel started after a discarded repair has none of the runtime\n\t * bootstrap's live handles (rlm, bash, skills) and an empty namespace:\n\t * reprovision (restore, then bootstrap) before any user request. A failed\n\t * re-bootstrap discards the kernel again instead of serving user code on an\n\t * unprovisioned namespace.\n\t */\n\tprivate async ensureKernelRebootstrapped(signal?: AbortSignal): Promise<void> {\n\t\tconst code = this.options.bootstrapCode;\n\t\tconst needsRestore = Boolean(this.options.snapshot) && this.pendingRestore;\n\t\tconst needsBootstrap = Boolean(code) && this.pendingRebootstrap;\n\t\t// An in-flight repair owns its kernel's restore/bootstrap sequence, and\n\t\t// a teardown's final snapshot must never trigger reprovisioning.\n\t\tif (\n\t\t\t(!needsRestore && !needsBootstrap) ||\n\t\t\tthis.protocolRepairPromise ||\n\t\t\tthis.teardownInFlight > 0 ||\n\t\t\tthis.state !== \"running\"\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tlet task = this.rebootstrapPromise;\n\t\tif (!task) {\n\t\t\tconst started = this.reprovisionFreshKernel(code);\n\t\t\ttask = started;\n\t\t\tthis.rebootstrapPromise = started;\n\t\t\tvoid started.finally(() => {\n\t\t\t\tif (this.rebootstrapPromise === started) this.rebootstrapPromise = undefined;\n\t\t\t});\n\t\t}\n\t\t// An aborted request never executes, so it may skip the wait; race the\n\t\t// signal like waitForProtocolRepair does instead of riding out the\n\t\t// bootstrap bound after a mid-wait abort.\n\t\tif (signal) {\n\t\t\tif (signal.aborted) return;\n\t\t\tlet onAbort: () => void = () => {};\n\t\t\tconst aborted = new Promise<void>((resolve) => {\n\t\t\t\tonAbort = resolve;\n\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tawait Promise.race([task, aborted]);\n\t\t\t} finally {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t\tif (signal.aborted) return;\n\t\t}\n\t\tconst ok = await task; // bounded by REPAIR_STEP_TIMEOUT_MS\n\t\tif (!ok) throw new Error(\"Kernel bootstrap failed after protocol repair\");\n\t}\n\n\t/** Restore (one-shot, best-effort) then bootstrap the lazily started fresh kernel. */\n\tprivate async reprovisionFreshKernel(code: string | undefined): Promise<boolean> {\n\t\tif (this.options.snapshot && this.pendingRestore) {\n\t\t\tawait this.performRestore(true); // clears pendingRestore on success\n\t\t\t// Corrupted during the restore: the spawned repair owns the kernel now.\n\t\t\tif (this.protocolRepairPromise || this.state !== \"running\") return false;\n\t\t\t// One attempt per discard: a clean restore failure falls back to an\n\t\t\t// empty namespace (ordinary startup semantics), never a retry loop.\n\t\t\tthis.pendingRestore = false;\n\t\t}\n\t\tif (!code || !this.pendingRebootstrap) return true;\n\t\tconst ok = await this.bootstrapRepairedKernel(code);\n\t\tif (!ok && this.state === \"running\") this.killChildToIdle();\n\t\treturn ok;\n\t}\n\n\t/** Kill the current child and settle at clean idle, so the next start spawns fresh. */\n\tprivate killChildToIdle(): void {\n\t\t// The discarded kernel carried the runtime bootstrap and (possibly) the\n\t\t// restored namespace; a lazily started replacement must reprovision both.\n\t\tthis.pendingRebootstrap = true;\n\t\tthis.pendingRestore = true;\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.cleanupResources(\"SIGKILL\");\n\t\tthis.state = \"idle\";\n\t}\n\n\tprivate finishFailedProtocolRepair(owner: { superseded: boolean }, error?: unknown): void {\n\t\tif (error) this.appendKernelDiagnostic(`protocol repair start failed: ${errorMessage(error)}`);\n\t\tif (owner.superseded || this.protocolRepairOwner !== owner) return;\n\t\tif (this.state === \"shutdown\") this.state = \"idle\";\n\t}\n\n\tprivate supersedeProtocolRepair(): void {\n\t\tif (this.protocolRepairOwner) this.protocolRepairOwner.superseded = true;\n\t}\n\n\t/** Wait until no protocol repair is pending; resolves early when the signal aborts. */\n\tprivate async waitForProtocolRepair(signal?: AbortSignal): Promise<void> {\n\t\twhile (this.protocolRepairPromise && !signal?.aborted) {\n\t\t\tconst repair = this.protocolRepairPromise;\n\t\t\tif (!signal) {\n\t\t\t\tawait repair;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet onAbort: () => void = () => {};\n\t\t\tconst aborted = new Promise<void>((resolve) => {\n\t\t\t\tonAbort = resolve;\n\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tawait Promise.race([repair, aborted]);\n\t\t\t} finally {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async waitForReady(child: ChildProcess): Promise<number> {\n\t\tconst ready = this.readyDeferred;\n\t\tif (!ready) throw new Error(\"Kernel ready state is missing\");\n\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tlet onExit: (() => void) | undefined;\n\t\ttry {\n\t\t\treturn await new Promise<number>((resolve, reject) => {\n\t\t\t\tready.promise.then(resolve, reject);\n\t\t\t\tonExit = () => {\n\t\t\t\t\tconst tail = this.kernelStderr.slice(-1024);\n\t\t\t\t\treject(new Error(`Kernel exited before ready. stderr:\\n${tail || \"(empty)\"}`));\n\t\t\t\t};\n\t\t\t\tif (child.exitCode !== null || child.signalCode !== null) {\n\t\t\t\t\tonExit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tchild.once(\"exit\", onExit);\n\t\t\t\ttimeout = globalThis.setTimeout(() => {\n\t\t\t\t\tconst tail = this.kernelStderr.slice(-1024);\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`Kernel did not become ready within ${READY_TIMEOUT_MS}ms. stderr tail:\\n${tail || \"(empty)\"}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}, READY_TIMEOUT_MS);\n\t\t\t\ttimeout.unref?.();\n\t\t\t});\n\t\t} finally {\n\t\t\tif (timeout) globalThis.clearTimeout(timeout);\n\t\t\tif (onExit) child.removeListener(\"exit\", onExit);\n\t\t}\n\t}\n\n\t/** Write one JSON-lines request frame; resolves when the OS accepted the bytes. */\n\tprivate writeLine(request: Record<string, unknown>): Promise<void> {\n\t\tconst stdin = this.child?.stdin;\n\t\tif (!stdin || stdin.destroyed) {\n\t\t\treturn Promise.reject(new Error(\"Kernel stdin is not connected\"));\n\t\t}\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tstdin.write(`${JSON.stringify(request)}\\n`, (error) => {\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolve();\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate handleEvent(event: Record<string, unknown>): void {\n\t\tconst type = event.event;\n\t\tif (type === \"ready\") {\n\t\t\tthis.readyDeferred?.resolve(typeof event.protocol === \"number\" ? event.protocol : -1);\n\t\t\treturn;\n\t\t}\n\t\tif (type === \"host_request\") {\n\t\t\tif (typeof event.id === \"string\") this.startHostRequest(event.id, event.data);\n\t\t\treturn;\n\t\t}\n\n\t\tconst id = typeof event.id === \"string\" ? event.id : undefined;\n\t\tconst execution = this.activeExecution;\n\t\tif (!execution || id !== execution.requestId) {\n\t\t\tif (type === \"display\" && isRecord(event.data)) {\n\t\t\t\tthis.dispatchLateSentAgentMessage(id, event.data[AGENT_MESSAGE_DISPLAY_MIME]);\n\t\t\t} else if (type === \"stdout\" || type === \"stderr\") {\n\t\t\t\t// Unowned output (null id, or another cell's id): never merge it into\n\t\t\t\t// the active cell's streams; buffer it as background output instead.\n\t\t\t\tthis.appendBackgroundOutput(typeof event.text === \"string\" ? event.text : \"\");\n\t\t\t} else if (type === \"done\" && id) {\n\t\t\t\tconst waiter = this.pendingDoneWaiters.get(id);\n\t\t\t\tthis.pendingDoneWaiters.delete(id);\n\t\t\t\twaiter?.();\n\t\t\t} else if (type === \"error\" && id === undefined) {\n\t\t\t\tthis.appendKernelDiagnostic(`protocol error: ${String(event.evalue ?? \"\")}`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (execution.settled && type === \"display\" && isRecord(event.data)) {\n\t\t\tif (this.dispatchLateSentAgentMessage(id, event.data[AGENT_MESSAGE_DISPLAY_MIME])) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (type === \"stdout\" || type === \"stderr\") {\n\t\t\tconst text = typeof event.text === \"string\" ? event.text : \"\";\n\t\t\tif (type === \"stdout\") {\n\t\t\t\tif (execution.stdout.length < execution.maxChars) {\n\t\t\t\t\texecution.stdout += text;\n\t\t\t\t\tif (execution.stdout.length > execution.maxChars) {\n\t\t\t\t\t\texecution.stdout = execution.stdout.slice(0, execution.maxChars);\n\t\t\t\t\t\texecution.stdoutTruncated = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (execution.stderr.length < execution.maxChars) {\n\t\t\t\t\texecution.stderr += text;\n\t\t\t\t\tif (execution.stderr.length > execution.maxChars) {\n\t\t\t\t\t\texecution.stderr = execution.stderr.slice(0, execution.maxChars);\n\t\t\t\t\t\texecution.stderrTruncated = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\texecution.opts.onStream?.(text, type);\n\t\t} else if (type === \"result\") {\n\t\t\tif (typeof event.text === \"string\") execution.result = event.text;\n\t\t} else if (type === \"display\") {\n\t\t\tconst data = isRecord(event.data) ? event.data : {};\n\t\t\tconst diff = parseDiffDisplay(data[DIFF_DISPLAY_MIME]);\n\t\t\tif (diff) execution.diffs.push(diff);\n\t\t\tconst attachment = parseAttachmentDisplay(data[ATTACHMENT_DISPLAY_MIME]);\n\t\t\tif (attachment === \"oversized\") {\n\t\t\t\texecution.stderr += `${execution.stderr ? \"\\n\" : \"\"}attachment dropped: exceeds ${MAX_ATTACHMENT_DATA_CHARS} base64 chars`;\n\t\t\t\texecution.status = \"error\";\n\t\t\t} else if (attachment) {\n\t\t\t\texecution.attachments.push(attachment);\n\t\t\t}\n\t\t\tconst sentAgentMessage = parseSentAgentMessage(data[AGENT_MESSAGE_DISPLAY_MIME]);\n\t\t\tif (sentAgentMessage) execution.sentAgentMessages.push(sentAgentMessage);\n\t\t} else if (type === \"error\") {\n\t\t\texecution.error = {\n\t\t\t\tename: typeof event.ename === \"string\" ? event.ename : \"Error\",\n\t\t\t\tevalue: typeof event.evalue === \"string\" ? event.evalue : \"\",\n\t\t\t\ttraceback: asStringArray(event.traceback),\n\t\t\t};\n\t\t\texecution.status = \"error\";\n\t\t} else if (type === \"done\") {\n\t\t\texecution.doneFields = event;\n\t\t\tif (event.status !== \"ok\" && execution.status === \"ok\") {\n\t\t\t\texecution.status = \"error\";\n\t\t\t\t// State requests report failures as a done reason without an error event.\n\t\t\t\tif (!execution.error && typeof event.reason === \"string\") {\n\t\t\t\t\texecution.error = { ename: \"KernelError\", evalue: event.reason, traceback: [] };\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.finishActiveExecution(execution);\n\t\t}\n\t}\n\n\tasync execute(code: string, opts: ExecuteOptions = {}): Promise<ExecuteResult> {\n\t\tawait this.waitForProtocolRepair(opts.signal);\n\t\tconst result = await this.enqueueExecute(code, opts);\n\t\t// Refresh the on-disk snapshot after real work so a later resume (or a\n\t\t// crash before graceful shutdown) revives the most recent namespace.\n\t\tif (result.status === \"ok\") {\n\t\t\tthis.scheduleSnapshot();\n\t\t}\n\t\treturn result;\n\t}\n\n\t/** Queue and run a cell, serializing against all other executions. */\n\tprivate async enqueueExecute(\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\texecutionTimeoutMs?: number,\n\t): Promise<InternalExecuteResult> {\n\t\treturn this.enqueueRequest({ type: \"execute\", code }, code, opts, executionTimeoutMs);\n\t}\n\n\t/** Queue one protocol request (execute or state op) behind every other request. */\n\tprivate async enqueueRequest(\n\t\trequestFields: Record<string, unknown> & { type: string },\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\texecutionTimeoutMs?: number,\n\t): Promise<InternalExecuteResult> {\n\t\tif (opts.signal?.aborted) {\n\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: 0 };\n\t\t}\n\t\tawait this.start({ signal: opts.signal });\n\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t}\n\t\tif (this.flushingSnapshotForDispose && !opts.internal) {\n\t\t\tthrow new Error(\"Kernel is shutting down\");\n\t\t}\n\t\tif (!opts.protocolRepair) await this.ensureKernelRebootstrapped(opts.signal);\n\t\t// Aborted while waiting on the re-bootstrap: settle now instead of parking\n\t\t// on the queue slot behind the still-running bootstrap.\n\t\tif (opts.signal?.aborted) {\n\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: 0 };\n\t\t}\n\t\t// Re-check: a final flush may have started while this request awaited the\n\t\t// lazy re-bootstrap; admitting it now would splice it between the flush's\n\t\t// captured queue and the final snapshot, unbounding the teardown.\n\t\tif (this.flushingSnapshotForDispose && !opts.internal) {\n\t\t\tthrow new Error(\"Kernel is shutting down\");\n\t\t}\n\n\t\tconst prev = this.executionQueue;\n\t\tlet resolveNext: () => void = () => {};\n\t\tthis.executionQueue = new Promise<void>((r) => {\n\t\t\tresolveNext = r;\n\t\t});\n\t\tawait prev;\n\n\t\tconst started = Date.now();\n\t\tlet executionTimeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\ttry {\n\t\t\tawait this.waitForActiveExecutionToClearForReuse(opts.signal);\n\t\t\tif (opts.signal?.aborted) {\n\t\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: Date.now() - started };\n\t\t\t}\n\t\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t\t}\n\t\t\t// A repair started while this request was queued or busy-waiting: release\n\t\t\t// the slot so the repair's own restore can run, then requeue behind it.\n\t\t\tif (this.protocolRepairPromise && !opts.protocolRepair) {\n\t\t\t\tresolveNext();\n\t\t\t\tawait this.waitForProtocolRepair(opts.signal);\n\t\t\t\treturn this.enqueueRequest(requestFields, code, opts, executionTimeoutMs);\n\t\t\t}\n\t\t\tif (executionTimeoutMs === undefined) {\n\t\t\t\treturn await this.executeInner(requestFields, code, opts, started);\n\t\t\t}\n\n\t\t\tconst controller = new AbortController();\n\t\t\texecutionTimeout = globalThis.setTimeout(() => controller.abort(), executionTimeoutMs);\n\t\t\texecutionTimeout.unref?.();\n\t\t\tconst signal = opts.signal ? AbortSignal.any([opts.signal, controller.signal]) : controller.signal;\n\t\t\treturn await this.executeInner(requestFields, code, { ...opts, signal }, started);\n\t\t} finally {\n\t\t\tif (executionTimeout) globalThis.clearTimeout(executionTimeout);\n\t\t\tresolveNext();\n\t\t}\n\t}\n\n\tprivate async executeInner(\n\t\trequestFields: Record<string, unknown> & { type: string },\n\t\tcode: string,\n\t\topts: ExecuteOptions,\n\t\tstarted: number,\n\t): Promise<InternalExecuteResult> {\n\t\tconst maxChars = opts.maxOutputChars ?? DEFAULT_MAX_OUTPUT_CHARS;\n\t\tconst requestId = uuid();\n\n\t\tif (opts.signal?.aborted) {\n\t\t\treturn { stdout: \"\", stderr: \"\", status: \"aborted\", durationMs: Date.now() - started };\n\t\t}\n\t\tif (this.activeExecution) {\n\t\t\tthrow new Error(\"Kernel already has an active execution\");\n\t\t}\n\n\t\tconst result = createDeferred<InternalExecuteResult>();\n\t\tconst execution: ActiveExecution = {\n\t\t\trequestId,\n\t\t\tcode,\n\t\t\tstarted,\n\t\t\tmaxChars,\n\t\t\topts,\n\t\t\tstdout: \"\",\n\t\t\tstderr: \"\",\n\t\t\tstdoutTruncated: false,\n\t\t\tstderrTruncated: false,\n\t\t\tdiffs: [],\n\t\t\tattachments: [],\n\t\t\tsentAgentMessages: [],\n\t\t\tbackgroundOutput: this.pendingBackgroundOutput,\n\t\t\tbackgroundOutputTruncated: this.pendingBackgroundOutputTruncated,\n\t\t\tstatus: \"ok\",\n\t\t\tsettled: false,\n\t\t\tresolve: result.resolve,\n\t\t\treject: result.reject,\n\t\t};\n\t\tthis.pendingBackgroundOutput = \"\";\n\t\tthis.pendingBackgroundOutputTruncated = false;\n\t\tlet abortTimer: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tconst clearAbortTimer = () => {\n\t\t\tif (abortTimer) {\n\t\t\t\tglobalThis.clearTimeout(abortTimer);\n\t\t\t\tabortTimer = undefined;\n\t\t\t}\n\t\t};\n\t\tconst forceAbort = () => {\n\t\t\tif (this.activeExecution !== execution) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\texecution.status = \"aborted\";\n\t\t\t// The execution stays active until its done event arrives; clearing it\n\t\t\t// early would let a new cell race the interrupted one (see busy-after-interrupt).\n\t\t\tthis.resolveExecution(execution, { clearActive: false });\n\t\t};\n\t\tconst onAbort = () => {\n\t\t\tvoid this.interrupt().catch(() => undefined);\n\t\t\tclearAbortTimer();\n\t\t\tabortTimer = globalThis.setTimeout(forceAbort, KERNEL_ABORT_GRACE_MS);\n\t\t\tif (abortTimer && typeof abortTimer === \"object\" && \"unref\" in abortTimer) {\n\t\t\t\tabortTimer.unref();\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tthis.activeExecution = execution;\n\t\t\topts.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tif (opts.signal?.aborted) {\n\t\t\t\tonAbort();\n\t\t\t}\n\t\t\tif (!opts.internal) {\n\t\t\t\tthis.lastCellCode = code;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst sendPromise = this.writeLine({ ...requestFields, id: requestId });\n\t\t\t\tsendPromise.catch(() => undefined);\n\t\t\t\tawait Promise.race([sendPromise, result.promise.then(() => undefined)]);\n\t\t\t\tif (this.activeExecution === execution && execution.status !== \"aborted\") {\n\t\t\t\t\tawait sendPromise;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (this.activeExecution === execution) {\n\t\t\t\t\tthis.activeExecution = undefined;\n\t\t\t\t}\n\t\t\t\tthrow error instanceof Error ? error : new Error(String(error));\n\t\t\t}\n\t\t\treturn await result.promise;\n\t\t} finally {\n\t\t\tclearAbortTimer();\n\t\t\topts.signal?.removeEventListener(\"abort\", onAbort);\n\t\t}\n\t}\n\n\tprivate appendBackgroundOutput(text: string): void {\n\t\tif (!text) return;\n\t\tconst execution = this.activeExecution;\n\t\tif (execution) {\n\t\t\tif (execution.backgroundOutput.length >= MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\t\texecution.backgroundOutputTruncated = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\texecution.backgroundOutput += text;\n\t\t\tif (execution.backgroundOutput.length > MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\t\texecution.backgroundOutput = execution.backgroundOutput.slice(0, MAX_BACKGROUND_OUTPUT_CHARS);\n\t\t\t\texecution.backgroundOutputTruncated = true;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (this.pendingBackgroundOutput.length >= MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\tthis.pendingBackgroundOutputTruncated = true;\n\t\t\treturn;\n\t\t}\n\t\tthis.pendingBackgroundOutput += text;\n\t\tif (this.pendingBackgroundOutput.length > MAX_BACKGROUND_OUTPUT_CHARS) {\n\t\t\tthis.pendingBackgroundOutput = this.pendingBackgroundOutput.slice(0, MAX_BACKGROUND_OUTPUT_CHARS);\n\t\t\tthis.pendingBackgroundOutputTruncated = true;\n\t\t}\n\t}\n\n\tprivate finishActiveExecution(execution: ActiveExecution): void {\n\t\tif (this.activeExecution !== execution) {\n\t\t\treturn;\n\t\t}\n\t\tthis.resolveExecution(execution, { clearActive: true });\n\t}\n\n\tprivate resolveExecution(execution: ActiveExecution, options: { clearActive: boolean }): void {\n\t\tconst didClearActive = options.clearActive && this.activeExecution === execution;\n\t\tif (options.clearActive && this.activeExecution === execution) {\n\t\t\tthis.activeExecution = undefined;\n\t\t}\n\t\tif (!execution.settled) {\n\t\t\texecution.settled = true;\n\t\t\tif (execution.opts.onLateSentAgentMessage) {\n\t\t\t\tthis.registerLateSentAgentMessageHandler(execution.requestId, execution.opts.onLateSentAgentMessage);\n\t\t\t}\n\n\t\t\tlet stdout = execution.stdout;\n\t\t\tlet stderr = execution.stderr;\n\t\t\tlet result = execution.result;\n\t\t\tlet status = execution.status;\n\t\t\tif (execution.stdoutTruncated) stdout += `\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\tif (execution.stderrTruncated) stderr += `\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\tif (result !== undefined && result.length > execution.maxChars) {\n\t\t\t\tresult = `${result.slice(0, execution.maxChars)}\\n[... output truncated at ${execution.maxChars} chars ...]`;\n\t\t\t}\n\n\t\t\tif (execution.opts.signal?.aborted) status = \"aborted\";\n\n\t\t\tlet backgroundOutput = execution.backgroundOutput;\n\t\t\tif (execution.backgroundOutputTruncated) {\n\t\t\t\tbackgroundOutput += `\\n[... background output truncated at ${MAX_BACKGROUND_OUTPUT_CHARS} chars ...]`;\n\t\t\t}\n\n\t\t\texecution.resolve({\n\t\t\t\tstdout,\n\t\t\t\tstderr,\n\t\t\t\tresult,\n\t\t\t\tdiffs: execution.diffs.length > 0 ? execution.diffs : undefined,\n\t\t\t\tattachments: execution.attachments.length > 0 ? execution.attachments : undefined,\n\t\t\t\tsentAgentMessages: execution.sentAgentMessages.length > 0 ? execution.sentAgentMessages : undefined,\n\t\t\t\tbackgroundOutput: backgroundOutput.length > 0 ? backgroundOutput : undefined,\n\t\t\t\terror: execution.error,\n\t\t\t\tstatus,\n\t\t\t\tdurationMs: Date.now() - execution.started,\n\t\t\t\tdoneFields: execution.doneFields,\n\t\t\t});\n\t\t}\n\t\tif (didClearActive) {\n\t\t\tthis.notifyActiveExecutionIdle();\n\t\t}\n\t}\n\n\tprivate dispatchLateSentAgentMessage(requestId: string | undefined, value: unknown): boolean {\n\t\tconst sentAgentMessage = parseSentAgentMessage(value);\n\t\tif (!sentAgentMessage || !requestId) {\n\t\t\treturn false;\n\t\t}\n\t\tconst handler = this.lateSentAgentMessageHandlers.get(requestId);\n\t\tif (!handler) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.lateSentAgentMessageHandlers.delete(requestId);\n\t\tthis.lateSentAgentMessageHandlers.set(requestId, handler);\n\t\thandler(sentAgentMessage);\n\t\treturn true;\n\t}\n\n\tprivate registerLateSentAgentMessageHandler(\n\t\trequestId: string,\n\t\thandler: (message: KernelSentAgentMessage) => void,\n\t): void {\n\t\tthis.lateSentAgentMessageHandlers.set(requestId, handler);\n\t\twhile (this.lateSentAgentMessageHandlers.size > MAX_LATE_SENT_AGENT_MESSAGE_HANDLERS) {\n\t\t\tconst oldestRequestId = this.lateSentAgentMessageHandlers.keys().next().value;\n\t\t\tif (oldestRequestId === undefined) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tthis.lateSentAgentMessageHandlers.delete(oldestRequestId);\n\t\t}\n\t}\n\n\tprivate rejectActiveExecution(error: Error): void {\n\t\tconst execution = this.activeExecution;\n\t\tif (!execution) {\n\t\t\treturn;\n\t\t}\n\t\tthis.activeExecution = undefined;\n\t\texecution.reject(error);\n\t\tthis.notifyActiveExecutionIdle();\n\t}\n\n\tprivate notifyActiveExecutionIdle(): void {\n\t\tfor (const resolve of this.activeExecutionIdleWaiters) {\n\t\t\tresolve();\n\t\t}\n\t\tthis.activeExecutionIdleWaiters.clear();\n\t}\n\n\tprivate waitForActiveExecutionToClear(signal: AbortSignal | undefined, timeoutMs: number): Promise<boolean> {\n\t\tif (!this.activeExecution) {\n\t\t\treturn Promise.resolve(true);\n\t\t}\n\t\treturn new Promise<boolean>((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\t\tconst finish = (cleared: boolean) => {\n\t\t\t\tif (settled) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tsettled = true;\n\t\t\t\tif (timeout) {\n\t\t\t\t\tglobalThis.clearTimeout(timeout);\n\t\t\t\t}\n\t\t\t\tthis.activeExecutionIdleWaiters.delete(onIdle);\n\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(cleared);\n\t\t\t};\n\t\t\tconst onIdle = () => finish(true);\n\t\t\tconst onAbort = () => finish(false);\n\t\t\tthis.activeExecutionIdleWaiters.add(onIdle);\n\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\ttimeout = globalThis.setTimeout(() => finish(false), timeoutMs);\n\t\t\tif (timeout && typeof timeout === \"object\" && \"unref\" in timeout) {\n\t\t\t\ttimeout.unref();\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate async waitForActiveExecutionToClearForReuse(signal?: AbortSignal): Promise<void> {\n\t\tconst started = Date.now();\n\t\twhile (this.activeExecution && Date.now() - started < KERNEL_BUSY_REUSE_WAIT_MS) {\n\t\t\tif ((this.state as string) === \"shutdown\") {\n\t\t\t\tthrow new Error(\"Kernel has been shut down\");\n\t\t\t}\n\t\t\tvoid this.interrupt().catch(() => undefined);\n\t\t\tconst remaining = KERNEL_BUSY_REUSE_WAIT_MS - (Date.now() - started);\n\t\t\tconst cleared = await this.waitForActiveExecutionToClear(\n\t\t\t\tsignal,\n\t\t\t\tMath.max(1, Math.min(KERNEL_BUSY_INTERRUPT_INTERVAL_MS, remaining)),\n\t\t\t);\n\t\t\tif (cleared || signal?.aborted) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (this.activeExecution) {\n\t\t\tthrow new KernelBusyAfterInterruptError();\n\t\t}\n\t}\n\n\tprivate startHostRequest(requestId: string, data: unknown): void {\n\t\tif (this.handledHostRequestIds.has(requestId)) {\n\t\t\treturn;\n\t\t}\n\t\tthis.handledHostRequestIds.add(requestId);\n\t\twhile (this.handledHostRequestIds.size > MAX_HANDLED_HOST_REQUEST_IDS) {\n\t\t\tconst oldest = this.handledHostRequestIds.values().next().value;\n\t\t\tif (oldest === undefined) break;\n\t\t\tthis.handledHostRequestIds.delete(oldest);\n\t\t}\n\n\t\tconst task = (async () => {\n\t\t\ttry {\n\t\t\t\tconst result = await this.handleHostRequest(data);\n\t\t\t\ttry {\n\t\t\t\t\tawait this.writeLine({ type: \"host_reply\", id: requestId, data: { status: \"ok\", result } });\n\t\t\t\t} catch (replyError) {\n\t\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t\t`failed to send host request ok reply for ${requestId}: ${errorMessage(replyError)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthis.appendKernelDiagnostic(`host request failed for ${requestId}: ${errorMessage(error)}`);\n\t\t\t\ttry {\n\t\t\t\t\tawait this.writeLine({\n\t\t\t\t\t\ttype: \"host_reply\",\n\t\t\t\t\t\tid: requestId,\n\t\t\t\t\t\tdata: { status: \"error\", error: errorMessage(error) },\n\t\t\t\t\t});\n\t\t\t\t} catch (replyError) {\n\t\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t\t`failed to send host request error reply for ${requestId}: ${errorMessage(replyError)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t})();\n\t\tthis.inFlightHostRequests.add(task);\n\t\tvoid task.finally(() => {\n\t\t\tthis.inFlightHostRequests.delete(task);\n\t\t});\n\t}\n\n\tprivate async handleHostRequest(data: unknown): Promise<Record<string, unknown>> {\n\t\tif (!isRecord(data)) {\n\t\t\tthrow new Error(\"host request payload must be an object\");\n\t\t}\n\t\tif (typeof data.type !== \"string\" || data.type.length === 0) {\n\t\t\tthrow new Error(\"host request payload must have a string type\");\n\t\t}\n\n\t\tconst handler = this.options.hostHandlers?.[data.type];\n\t\tif (!handler) {\n\t\t\tthrow new Error(`host request type \"${data.type}\" is not available in this session`);\n\t\t}\n\t\t// Tag the request with the cell that triggered it. A blocking call is still\n\t\t// the in-flight execution; detached spawns (asyncio.create_task) fire after\n\t\t// the scheduling cell goes idle, so fall back to that last cell's source.\n\t\tconst cellSourceCode = this.activeExecution?.code ?? this.lastCellCode;\n\t\treturn handler({ ...data, cellSourceCode });\n\t}\n\n\tprivate async interrupt(): Promise<void> {\n\t\tconst requestId = this.activeExecution?.requestId;\n\t\tif (!requestId) return;\n\t\tawait this.writeLine({ type: \"interrupt\", id: requestId });\n\t}\n\n\tprivate cleanupResources(killSignal: NodeJS.Signals = \"SIGTERM\"): void {\n\t\tthis.startGeneration++; // any teardown invalidates in-flight starts\n\t\tthis.clearSnapshotTimer();\n\t\tthis.lateSentAgentMessageHandlers.clear();\n\t\tthis.pendingDoneWaiters.clear();\n\t\t// Stale pre-teardown background output must not surface after a restart.\n\t\tthis.pendingBackgroundOutput = \"\";\n\t\tthis.pendingBackgroundOutputTruncated = false;\n\t\tthis.rejectActiveExecution(new Error(\"Kernel has been shut down\"));\n\t\tconst child = this.child;\n\t\tthis.child = undefined;\n\t\tthis.readyDeferred = undefined;\n\t\tif (child) {\n\t\t\tchild.stdin?.destroy();\n\t\t\tchild.stdout?.destroy();\n\t\t\tchild.stderr?.destroy();\n\t\t\tconst pid = child.pid;\n\t\t\tlet signaled = false;\n\t\t\ttry {\n\t\t\t\tsignaled = child.kill(killSignal);\n\t\t\t} catch {\n\t\t\t\t// The kernel has already exited.\n\t\t\t}\n\t\t\t// Inactive only when the signal proved the pid still named our un-reaped child.\n\t\t\tif (pid !== undefined && signaled) recordOrphanProcessState(pid, false);\n\t\t\t// A killed/crashed kernel cannot run its own shutdown hook, so the host\n\t\t\t// reaps the bash() process groups it journaled under this kernel pid.\n\t\t\tif (pid !== undefined) reapKernelOrphanProcesses(pid);\n\t\t}\n\t\tthis.startPromise = undefined;\n\t}\n\n\tprivate async waitForKernelExit(): Promise<void> {\n\t\tconst child = this.child;\n\t\tif (!child) return;\n\t\tif (child.exitCode !== null || child.signalCode !== null) return;\n\t\tawait new Promise<void>((resolve) => child.once(\"exit\", () => resolve()));\n\t}\n\n\tprivate async waitForHostRequestsToSettle(tasks: Promise<void>[], timeoutMs: number): Promise<void> {\n\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tconst timeoutPromise = new Promise<\"timeout\">((resolve) => {\n\t\t\ttimeout = globalThis.setTimeout(() => resolve(\"timeout\"), timeoutMs);\n\t\t\tif (timeout && typeof timeout === \"object\" && \"unref\" in timeout) {\n\t\t\t\ttimeout.unref();\n\t\t\t}\n\t\t});\n\n\t\tconst result = await Promise.race([Promise.allSettled(tasks).then(() => \"settled\" as const), timeoutPromise]);\n\t\tif (timeout) {\n\t\t\tglobalThis.clearTimeout(timeout);\n\t\t}\n\t\tif (result === \"timeout\") {\n\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t`timed out waiting ${timeoutMs}ms for ${tasks.length} host request task(s) during shutdown`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Resolves true when this call performed the cleanup (false: a concurrent teardown won; a joiner's options are ignored - the first caller's policy wins). */\n\tasync shutdown(opts: KernelShutdownOptions = {}): Promise<boolean> {\n\t\tconst inFlightShutdown = this.gracefulShutdownPromise;\n\t\tif (inFlightShutdown) {\n\t\t\tawait inFlightShutdown;\n\t\t\treturn false;\n\t\t}\n\n\t\tthis.teardownInFlight++;\n\t\tthis.supersedeProtocolRepair();\n\t\tconst operation = this.performShutdown(opts);\n\t\tthis.gracefulShutdownPromise = operation;\n\t\ttry {\n\t\t\treturn await operation;\n\t\t} finally {\n\t\t\tthis.teardownInFlight--;\n\t\t\tif (this.gracefulShutdownPromise === operation) this.gracefulShutdownPromise = undefined;\n\t\t}\n\t}\n\n\tprivate async performShutdown(opts: KernelShutdownOptions): Promise<boolean> {\n\t\tif (this.state === \"shutdown\") {\n\t\t\tliveKernels.delete(this);\n\t\t\tif (this.gracefulShutdownGeneration === this.startGeneration) return false;\n\t\t\tthis.cleanupResources();\n\t\t\treturn true;\n\t\t}\n\t\t// Captured before any await: teardowns and newer starts bump the counter.\n\t\tconst generation = this.startGeneration;\n\t\tif (opts.snapshot) {\n\t\t\tawait this.flushSnapshotForDispose();\n\t\t\tif (this.startStale(generation)) return false;\n\t\t}\n\t\t// Protocol shutdown first: the runtime closes MCP servers and kills live bash() process groups a bare hard-kill would leak.\n\t\tconst protocolShutdownAvailable = this.state === \"running\";\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.gracefulShutdownGeneration = generation;\n\n\t\tlet shutdownTimer: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\tlet doneWaiterId: string | undefined;\n\t\tlet performedCleanup = false;\n\t\ttry {\n\t\t\tif (opts.drainHostRequests) {\n\t\t\t\tconst inFlightHostRequests = [...this.inFlightHostRequests];\n\t\t\t\tif (inFlightHostRequests.length > 0) {\n\t\t\t\t\tawait this.waitForHostRequestsToSettle(inFlightHostRequests, HOST_REQUEST_SHUTDOWN_TIMEOUT_MS);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (\n\t\t\t\tprotocolShutdownAvailable &&\n\t\t\t\t!this.startStale(generation) &&\n\t\t\t\tthis.child?.stdin &&\n\t\t\t\t!this.child.stdin.destroyed\n\t\t\t) {\n\t\t\t\tconst requestId = uuid();\n\t\t\t\tdoneWaiterId = requestId;\n\t\t\t\tconst doneReply = new Promise<void>((resolve) => {\n\t\t\t\t\tthis.pendingDoneWaiters.set(requestId, resolve);\n\t\t\t\t});\n\t\t\t\tconst shutdownDeadline = new Promise<never>((_resolve, reject) => {\n\t\t\t\t\tshutdownTimer = globalThis.setTimeout(\n\t\t\t\t\t\t() => reject(new Error(`Kernel did not shut down within ${KERNEL_SHUTDOWN_TIMEOUT_MS}ms`)),\n\t\t\t\t\t\tKERNEL_SHUTDOWN_TIMEOUT_MS,\n\t\t\t\t\t);\n\t\t\t\t\tshutdownTimer.unref?.();\n\t\t\t\t});\n\t\t\t\tconst send = this.writeLine({ type: \"shutdown\", id: requestId });\n\t\t\t\tsend.catch(() => undefined);\n\t\t\t\tconst kernelExit = this.waitForKernelExit();\n\t\t\t\tconst gracefulReply = Promise.all([send, doneReply]);\n\t\t\t\tgracefulReply.catch(() => undefined);\n\t\t\t\tawait Promise.race([gracefulReply, kernelExit, shutdownDeadline]);\n\t\t\t\tawait Promise.race([kernelExit, shutdownDeadline]);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t`graceful shutdown failed (killing instead): ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t} finally {\n\t\t\tif (shutdownTimer) globalThis.clearTimeout(shutdownTimer);\n\t\t\tif (doneWaiterId) this.pendingDoneWaiters.delete(doneWaiterId);\n\t\t\tif (this.gracefulShutdownGeneration === generation) this.gracefulShutdownGeneration = undefined;\n\t\t\tif (!this.startStale(generation)) {\n\t\t\t\tthis.cleanupResources();\n\t\t\t\tperformedCleanup = true;\n\t\t\t}\n\t\t}\n\n\t\treturn performedCleanup;\n\t}\n\n\tasync restart(): Promise<void> {\n\t\t// A final dispose flush owns the queue tail. Taking a slot now and joining\n\t\t// the in-flight shutdown would deadlock: the flush's snapshot waits on our\n\t\t// slot while we wait on the flush's shutdown.\n\t\tif (this.flushingSnapshotForDispose) {\n\t\t\tthrow new Error(\"Kernel is shutting down\");\n\t\t}\n\t\tconst prev = this.executionQueue;\n\t\tlet resolveNext: () => void = () => {};\n\t\tthis.executionQueue = new Promise<void>((r) => {\n\t\t\tresolveNext = r;\n\t\t});\n\t\tawait prev;\n\n\t\ttry {\n\t\t\tconst performedCleanup = await this.shutdown();\n\t\t\tif (!performedCleanup) return;\n\t\t\tthis.state = \"idle\";\n\t\t\tthis.kernelStderr = \"\";\n\t\t\tawait this.start();\n\t\t} finally {\n\t\t\tresolveNext();\n\t\t}\n\t}\n\n\tasync kill(): Promise<void> {\n\t\tthis.supersedeProtocolRepair();\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.cleanupResources(\"SIGKILL\");\n\t}\n\n\t/**\n\t * Serialize the user namespace to disk (best-effort, per-variable). No-op when\n\t * the kernel isn't running or no snapshot target was configured. Never throws.\n\t */\n\tasync snapshotState(): Promise<SnapshotResult | null> {\n\t\treturn this.captureSnapshot();\n\t}\n\n\t/** Persist the namespace, then remove variables above the per-variable cap. */\n\tasync pruneOversizedVariables(): Promise<SnapshotResult | null> {\n\t\treturn this.captureSnapshot({ executionTimeoutMs: SNAPSHOT_EXECUTION_TIMEOUT_MS, pruneOversized: true });\n\t}\n\n\tprivate async captureSnapshot(\n\t\toptions: { executionTimeoutMs?: number; pruneOversized?: boolean } = {},\n\t): Promise<SnapshotResult | null> {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg || !this.isRunning) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest(\n\t\t\t\t{\n\t\t\t\t\ttype: \"snapshot\",\n\t\t\t\t\tpath: cfg.path,\n\t\t\t\t\tmanifest_path: cfg.manifestPath,\n\t\t\t\t\tmax_bytes: cfg.maxBytes ?? DEFAULT_SNAPSHOT_MAX_BYTES,\n\t\t\t\t\tmax_variable_bytes: cfg.maxVariableBytes ?? DEFAULT_SNAPSHOT_MAX_VARIABLE_BYTES,\n\t\t\t\t\tprune_oversized: options.pruneOversized ?? false,\n\t\t\t\t},\n\t\t\t\t\"\",\n\t\t\t\t{ internal: true },\n\t\t\t\toptions.executionTimeoutMs,\n\t\t\t);\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t`state snapshot ${r.status === \"aborted\" ? \"timed out\" : \"failed\"}: ${r.error?.evalue ?? r.stderr}`,\n\t\t\t\t);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst pruned = asStringArray(r.doneFields.pruned);\n\t\t\treturn {\n\t\t\t\tsaved: asStringArray(r.doneFields.saved),\n\t\t\t\tskipped: asReasonArray(r.doneFields.skipped),\n\t\t\t\tpruned: pruned.length > 0 ? pruned : undefined,\n\t\t\t\tbytes: typeof r.doneFields.bytes === \"number\" ? r.doneFields.bytes : 0,\n\t\t\t\tpath: cfg.path,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`state snapshot error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Revive a previously snapshotted namespace into the kernel. Call right after\n\t * start() and before the runtime bootstrap, which then refreshes live handles\n\t * (rlm, skills) over anything restored. Never throws.\n\t */\n\tasync restoreState(): Promise<RestoreResult | null> {\n\t\treturn this.performRestore(false);\n\t}\n\n\t/** Repair restores bypass the repair gate and are bounded so a stalled kernel cannot wedge it. */\n\tprivate async performRestore(protocolRepair: boolean): Promise<RestoreResult | null> {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest(\n\t\t\t\t{ type: \"restore\", path: cfg.path },\n\t\t\t\t\"\",\n\t\t\t\t{ internal: true, protocolRepair },\n\t\t\t\tprotocolRepair ? REPAIR_STEP_TIMEOUT_MS : undefined,\n\t\t\t);\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(\n\t\t\t\t\t`state restore ${r.status === \"aborted\" ? \"timed out\" : \"failed\"}: ${r.error?.evalue ?? r.stderr}`,\n\t\t\t\t);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tthis.pendingRestore = false;\n\t\t\treturn {\n\t\t\t\trestored: asStringArray(r.doneFields.restored),\n\t\t\t\tfailed: asReasonArray(r.doneFields.failed),\n\t\t\t\tpath: cfg.path,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`state restore error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/** Live user-defined top-level names, or null if the kernel isn't running. Never throws. */\n\tasync listNamespaceNames(signal?: AbortSignal): Promise<string[] | null> {\n\t\tif (!this.isRunning) return null;\n\t\ttry {\n\t\t\tconst r = await this.enqueueRequest({ type: \"list_names\" }, \"\", { internal: true, signal });\n\t\t\tif (r.status !== \"ok\" || !r.doneFields) {\n\t\t\t\tthis.appendKernelDiagnostic(`namespace listing failed: ${r.error?.evalue ?? r.stderr}`);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn asStringArray(r.doneFields.names);\n\t\t} catch (error) {\n\t\t\tthis.appendKernelDiagnostic(`namespace listing error: ${errorMessage(error)}`);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tprivate scheduleSnapshot(): void {\n\t\tconst cfg = this.options.snapshot;\n\t\tif (!cfg) return;\n\t\tif (this.snapshotTimer) clearTimeout(this.snapshotTimer);\n\t\tthis.snapshotTimer = globalThis.setTimeout(() => {\n\t\t\tthis.snapshotTimer = undefined;\n\t\t\tvoid this.captureSnapshot({ executionTimeoutMs: SNAPSHOT_EXECUTION_TIMEOUT_MS });\n\t\t}, cfg.debounceMs ?? DEFAULT_SNAPSHOT_DEBOUNCE_MS);\n\t\tif (this.snapshotTimer && typeof this.snapshotTimer === \"object\" && \"unref\" in this.snapshotTimer) {\n\t\t\tthis.snapshotTimer.unref();\n\t\t}\n\t}\n\n\tprivate clearSnapshotTimer(): void {\n\t\tif (this.snapshotTimer) {\n\t\t\tclearTimeout(this.snapshotTimer);\n\t\t\tthis.snapshotTimer = undefined;\n\t\t}\n\t}\n\n\tprivate flushSnapshotForDispose(): Promise<void> {\n\t\t// Concurrent teardowns (dispose vs a signal-handler shutdown) join one flush:\n\t\t// a second flusher would clear the execution guard while the first is still\n\t\t// snapshotting and enqueue a duplicate final snapshot behind it.\n\t\tthis.snapshotFlushForDispose ??= this.runSnapshotFlushForDispose().finally(() => {\n\t\t\tthis.snapshotFlushForDispose = undefined;\n\t\t});\n\t\treturn this.snapshotFlushForDispose;\n\t}\n\n\tprivate async runSnapshotFlushForDispose(): Promise<void> {\n\t\tif (!this.options.snapshot || !this.isRunning) return;\n\t\t// A kernel that never restored the saved namespace must not overwrite it:\n\t\t// the on-disk snapshot is strictly fresher than this namespace.\n\t\tif (this.pendingRestore) return;\n\t\t// Block new external executions so none can splice ahead of the final snapshot and stall dispose.\n\t\tthis.flushingSnapshotForDispose = true;\n\t\ttry {\n\t\t\tconst pendingExecutions = this.executionQueue;\n\t\t\tif (this.activeExecution) void this.interrupt().catch(() => undefined);\n\t\t\tlet timeout: ReturnType<typeof globalThis.setTimeout> | undefined;\n\t\t\tconst queueSettled = await Promise.race([\n\t\t\t\tpendingExecutions.then(() => true),\n\t\t\t\tnew Promise<false>((resolve) => {\n\t\t\t\t\ttimeout = globalThis.setTimeout(() => resolve(false), SNAPSHOT_EXECUTION_TIMEOUT_MS);\n\t\t\t\t\ttimeout.unref?.();\n\t\t\t\t}),\n\t\t\t]);\n\t\t\tif (timeout) globalThis.clearTimeout(timeout);\n\t\t\tif (!queueSettled) return;\n\t\t\tawait this.captureSnapshot({ executionTimeoutMs: SNAPSHOT_EXECUTION_TIMEOUT_MS });\n\t\t} finally {\n\t\t\t// Reset: a superseding start() can revive this kernel for new work.\n\t\t\tthis.flushingSnapshotForDispose = false;\n\t\t}\n\t}\n\n\t/** Synchronous best-effort cleanup. Safe to call from `process.on('exit')`. */\n\tdisposeSync(): void {\n\t\tthis.supersedeProtocolRepair();\n\t\tthis.state = \"shutdown\";\n\t\tliveKernels.delete(this);\n\t\tthis.cleanupResources();\n\t}\n\n\tget isRunning(): boolean {\n\t\treturn this.state === \"running\";\n\t}\n}\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { KernelBootstrapProgressHandler, KernelPythonSkill } from "./bootstrap.js";
|
|
2
2
|
import type { RestoreResult, SnapshotResult } from "./state-snapshot.js";
|
|
3
3
|
export declare const DEFAULT_MAX_OUTPUT_CHARS = 65536;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const HOST_REQUEST_SHUTDOWN_TIMEOUT_MS = 5000;
|
|
5
5
|
export declare const KERNEL_SHUTDOWN_TIMEOUT_MS = 5000;
|
|
6
6
|
export declare const DEFAULT_SNAPSHOT_DEBOUNCE_MS = 1500;
|
|
7
|
-
export declare const SNAPSHOT_DISPOSE_TIMEOUT_MS = 5000;
|
|
8
7
|
export declare const SNAPSHOT_EXECUTION_TIMEOUT_MS = 5000;
|
|
9
8
|
export declare const KERNEL_ABORT_GRACE_MS = 1000;
|
|
10
9
|
export declare const KERNEL_BUSY_REUSE_WAIT_MS = 5000;
|
|
@@ -15,7 +14,7 @@ export declare class KernelBusyAfterInterruptError extends Error {
|
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
16
|
* Handles one typed request from Python code running in the kernel.
|
|
18
|
-
* The returned record is
|
|
17
|
+
* The returned record is delivered verbatim to the Python caller.
|
|
19
18
|
*
|
|
20
19
|
* The unary form is the dispatcher and registration contract; context-aware
|
|
21
20
|
* handlers are declared separately below.
|
|
@@ -71,6 +70,8 @@ export interface KernelManagerOptions {
|
|
|
71
70
|
pythonSkills?: readonly KernelPythonSkill[];
|
|
72
71
|
/** Persist/revive the user namespace across kernel restarts and session resume. */
|
|
73
72
|
snapshot?: KernelSnapshotConfig;
|
|
73
|
+
/** Runtime bootstrap re-run on a protocol-repaired kernel so live handles (rlm, bash, skills) exist again. */
|
|
74
|
+
bootstrapCode?: string;
|
|
74
75
|
}
|
|
75
76
|
export interface KernelStartOptions {
|
|
76
77
|
onBootstrapProgress?: KernelBootstrapProgressHandler;
|
|
@@ -85,6 +86,8 @@ export interface ExecuteOptions {
|
|
|
85
86
|
maxOutputChars?: number;
|
|
86
87
|
/** Synthetic host cell (snapshot/restore/list); excluded from lastCellCode attribution. */
|
|
87
88
|
internal?: boolean;
|
|
89
|
+
/** The protocol repair's own restore; exempt from waiting on the repair it belongs to. */
|
|
90
|
+
protocolRepair?: boolean;
|
|
88
91
|
}
|
|
89
92
|
/** MIME tag the `edit` skill emits diff payloads under. */
|
|
90
93
|
export declare const DIFF_DISPLAY_MIME = "application/vnd.asm-agent.diff+json";
|
|
@@ -167,18 +170,19 @@ export interface Deferred<T> {
|
|
|
167
170
|
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
168
171
|
export declare function errorMessage(error: unknown): string;
|
|
169
172
|
export declare function createDeferred<T>(): Deferred<T>;
|
|
173
|
+
export interface KernelShutdownOptions {
|
|
174
|
+
snapshot?: boolean;
|
|
175
|
+
drainHostRequests?: boolean;
|
|
176
|
+
}
|
|
170
177
|
/** Public surface every kernel client exposes to the provisioner and session layer. */
|
|
171
178
|
export interface KernelClient {
|
|
172
179
|
readonly ownerSessionId: string | undefined;
|
|
173
180
|
readonly isRunning: boolean;
|
|
174
181
|
start(options?: KernelStartOptions): Promise<void>;
|
|
175
182
|
execute(code: string, opts?: ExecuteOptions): Promise<ExecuteResult>;
|
|
176
|
-
shutdown(opts?:
|
|
177
|
-
snapshot?: boolean;
|
|
178
|
-
}): Promise<boolean>;
|
|
183
|
+
shutdown(opts?: KernelShutdownOptions): Promise<boolean>;
|
|
179
184
|
restart(): Promise<void>;
|
|
180
185
|
kill(): Promise<void>;
|
|
181
|
-
dispose(): Promise<void>;
|
|
182
186
|
disposeSync(): void;
|
|
183
187
|
snapshotState(): Promise<SnapshotResult | null>;
|
|
184
188
|
pruneOversizedVariables(): Promise<SnapshotResult | null>;
|