feat(code-runtime): execute Node programs through confined processes

This commit is contained in:
Tianyi Cui committed 2026-09-12 15:03:01 +08:00
1 parent f95f7ec8dc
commit 75ed8da3e0
54 files changed
+1933 -2277

No files matched your search

@@ -1,14 +1,13 @@
/**
* Versionless, structured-clone wire protocol between co-shipped host and worker code. The host
* treats inbound traffic as hostile because model code can forge `parentPort` messages; the
* worker trusts host replies.
* JSON message vocabulary carried by the bounded process channel. The host validates every
* message because model code can write directly to the inherited descriptor.
* @module @deepseek-ai/dsh-code-runtime-node/src/protocol
*/
import type { WorkerJsonWire } from './worker-json.ts'
import type { CodeJsonWire } from './json-wire.ts'
/** What the host hands the worker at spawn, via `workerData`. */
export interface WorkerBootData {
/** What the host hands the program at spawn, after the readiness handshake. */
export interface ProgramBootData {
/** The type-stripped (plain JS) program body. */
code: string
/** Binding namespaces to materialize; functions themselves stay host-side. */
@@ -21,32 +20,32 @@ export interface WorkerBootData {
maxOutputBytes: number
}
/** Worker → host: one bridged binding call. */
/** Program → host: one bridged binding call. */
interface CallMessage {
type: 'call'
/** Worker-issued correlation id; the host answers each id at most once and ignores duplicates. */
/** Program-issued correlation id; the host answers each id at most once and ignores duplicates. */
id: number
/** The namespace global the call targets. */
global: string
/** The function name within the namespace. */
name: string
/** The single argument as a flat lossless-JSON wire value. */
args: WorkerJsonWire
args: CodeJsonWire
}
/** Worker → host: captured text, streamed eagerly so output survives a mid-run termination (timeout, abort, OOM). */
/** Program → host: captured text, streamed eagerly so output survives a mid-run termination (timeout, abort, OOM). */
interface LogMessage {
type: 'log'
text: string
}
/** Worker → host: worker-side capture or completion measurement exceeded the outer cap. */
/** Program → host: program-side capture or completion measurement exceeded the outer cap. */
interface OutputLimitMessage {
type: 'output-limit'
}
/**
* Worker → host: the program settled. `error` carries a program exception,
* Program → host: the program settled. `error` carries a program exception,
* invalid completion, or output overflow (budgets, aborts, and substrate death
* are observed host-side). `value` is present only on a clean completion that
* produced one, as a flat wire value already lossless and admitted against
@@ -55,14 +54,14 @@ interface OutputLimitMessage {
*/
export interface DoneMessage {
type: 'done'
value?: WorkerJsonWire
value?: CodeJsonWire
error?: { kind: 'exception' | 'invalid-output' | 'output-limit'; message: string }
}
/** Every message the worker sends. */
export type WorkerToHost = CallMessage | LogMessage | OutputLimitMessage | DoneMessage
/** Every message the program sends. */
export type ProgramToHost = CallMessage | LogMessage | OutputLimitMessage | DoneMessage
/** Host → worker: the answer to one {@link CallMessage}. */
/** Host → program: the answer to one {@link CallMessage}. */
export type ReplyMessage =
| { type: 'reply'; id: number; ok: true; value: WorkerJsonWire }
| { type: 'reply'; id: number; ok: true; value: CodeJsonWire }
| { type: 'reply'; id: number; ok: false; message: string }