feat: add the worker-thread code runtime (dsh-code-runtime-worker)

The shipped backend of the code-execution seam, per the Code Mode RFC's
worker-thread section: one fresh Node worker per run, executing the
model's TypeScript after a host-side type-strip (wrapped in an
async-function shell so top-level return/await parse, sliced back out
position-preserved), bindings bridged over the message port under
hostile-peer rules (own-property name lookup, at-most-once replies,
post-settlement drops, null-prototype namespaces), logs streamed eagerly
with an in-band truncation marker, and two independent budgets — measured
event-loop busy time (computeMs) plus a never-pausing wall ceiling
(maxWallMs) — funneling into worker.terminate(). env: {} and execArgv: []
keep the isolate hermetic; disposal aborts in-flight runs and awaits
worker exits.

The worker entry loads unbuilt via Node's native type stripping
(src/worker.ts, erasable-only) and ships built as a sibling tsdown bundle
(lib/worker.js); tests/built-lib.e2e.ts pins the built load path under
plain node and joins the built-artifact smoke gate. Unit suites cover the
bootstrap in-process (fake port) and the runtime over real workers,
per-file 100%.
This commit is contained in:
Tianyi Cui
2026-07-08 11:00:06 +08:00
parent 15a3431913
commit 583704ac1d
26 changed files with 1486 additions and 9 deletions

View File

@@ -105,11 +105,26 @@ const dshBinPackageFiles = [
'src',
] as const
// Packages that ship a worker-thread entry as a sibling runtime bundle
// (lib/worker.js, its own tsdown entry): the bootstrap is loaded via
// `new Worker(new URL('./worker.js', import.meta.url))`, so it cannot live
// inside the index bundle and must be published alongside it.
const workerEntryPackages = new Set(['@deepseek-ai/dsh-code-runtime-worker'])
const dshWorkerPackageFiles = [
'lib/index.js',
'lib/worker.js',
'lib/types/**/*.d.ts',
'lib/types/**/*.d.ts.map',
'src',
] as const
function sameStringList(actual: readonly string[] | undefined, expected: readonly string[]): boolean {
return !!actual && actual.length === expected.length && actual.every((value, index) => value === expected[index])
}
function expectedDshPackageFiles(manifest: PackageManifest): readonly string[] {
if (manifest.name && workerEntryPackages.has(manifest.name)) return dshWorkerPackageFiles
return manifest.bin ? dshBinPackageFiles : dshPackageFiles
}

View File

@@ -154,7 +154,7 @@ const SERVICE_ROLES: ServiceRole[] = [
pkg: 'code-runtime',
title: 'Code-execution seam',
mode: 'seam',
implementations: [],
implementations: ['code-runtime-worker'],
consumers: [],
note: 'Runs one model-written program against host-provided async bindings; backends differ by substrate and language (the Code Mode RFC specifies the worker-thread backend and the tool-registry consumer).',
},

View File

@@ -310,6 +310,7 @@ function builtBinSmokeGate(): Gate {
'vitest.e2e.config.ts',
'packages/ui/stdio-agent/tests/built-bin.e2e.ts',
'packages/ui/acp-agent/tests/built-bin.e2e.ts',
'packages/code-runtime/code-runtime-worker/tests/built-lib.e2e.ts',
], {
label: 'built-bin smoke',
needs: ['build'],