@hy-sde-org/dsh-code-runtime-kernels 0.1.0-rc.8
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/LICENSE +32 -0
- package/README.md +85 -0
- package/README.zh.md +85 -0
- package/cordis.patch.yml +34 -0
- package/dist/core/invariant.d.ts +16 -0
- package/dist/core/invariant.d.ts.map +1 -0
- package/dist/core/invariant.js +23 -0
- package/dist/core/invariant.js.map +1 -0
- package/dist/core/kernel.d.ts +133 -0
- package/dist/core/kernel.d.ts.map +1 -0
- package/dist/core/kernel.js +565 -0
- package/dist/core/kernel.js.map +1 -0
- package/dist/core/protocol.d.ts +115 -0
- package/dist/core/protocol.d.ts.map +1 -0
- package/dist/core/protocol.js +12 -0
- package/dist/core/protocol.js.map +1 -0
- package/dist/core/session.d.ts +49 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +153 -0
- package/dist/core/session.js.map +1 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +478 -0
- package/dist/index.js.map +1 -0
- package/dist/nodejs/runner.d.ts +26 -0
- package/dist/nodejs/runner.d.ts.map +1 -0
- package/dist/nodejs/runner.js +298 -0
- package/dist/nodejs/runner.js.map +1 -0
- package/dist/python/runner.d.ts +26 -0
- package/dist/python/runner.d.ts.map +1 -0
- package/dist/python/runner.js +615 -0
- package/dist/python/runner.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The spawned Node.js kernel runner. One `node <this-file>` subprocess is one
|
|
3
|
+
* persistent kernel: it owns the wire-protocol peers described in
|
|
4
|
+
* `protocol.ts`, a persistent `state` object (plus the process-global object)
|
|
5
|
+
* that survives every run of the session, and a per-run evaluation cell with
|
|
6
|
+
* async-function-body semantics — top-level `await` and `return` work exactly
|
|
7
|
+
* like the worker-thread backend, and bindings are materialized as ordinary
|
|
8
|
+
* globals whose members bridge `call`/`reply` frames to the host.
|
|
9
|
+
*
|
|
10
|
+
* This file must stay self-contained (Node builtins only, no imports of other package
|
|
11
|
+
* sources): tsc emits it as ESM under the package output and development tests
|
|
12
|
+
* spawn the raw source directly (Node 22.18+/24+ runs erasable TypeScript).
|
|
13
|
+
*
|
|
14
|
+
* Persistence contract (mirrors the Python provider's user namespace):
|
|
15
|
+
* - `state` is a long-lived object exposed to every program; mutations
|
|
16
|
+
* survive until the session resets or the kernel exits.
|
|
17
|
+
* - sloppy-mode assignments like `x = 41` land on the process global and
|
|
18
|
+
* persist; `globalThis` itself persists.
|
|
19
|
+
* - `const`/`let`/`var`/`function`/`class` declared at cell top level are
|
|
20
|
+
* scoped to that cell (async-function body), exactly like a Node REPL
|
|
21
|
+
* line that uses top-level `await` — use `state` or the global object to
|
|
22
|
+
* persist values.
|
|
23
|
+
* @module @deepseek-ai/dsh-code-runtime-nodejs/src/runner
|
|
24
|
+
*/
|
|
25
|
+
import { format } from 'node:util';
|
|
26
|
+
/** Global-object accessor for program-scope globals keyed by identifier. */
|
|
27
|
+
const g = globalThis;
|
|
28
|
+
/** The original stdout sink, captured before suppression of program writes. */
|
|
29
|
+
const rawStdout = process.stdout;
|
|
30
|
+
const rawWrite = rawStdout.write.bind(rawStdout);
|
|
31
|
+
/** Emit one protocol frame (a single JSON line on stdout), untouched by the cap. */
|
|
32
|
+
function emit(frame) {
|
|
33
|
+
rawWrite(`${JSON.stringify(frame)}\n`);
|
|
34
|
+
}
|
|
35
|
+
// --- persistent kernel state -------------------------------------------------
|
|
36
|
+
/** Program-visible persistent state (survives every run in this kernel). */
|
|
37
|
+
const state = {};
|
|
38
|
+
let executionCount = 0;
|
|
39
|
+
let active = null;
|
|
40
|
+
/** Emit a `log` frame into the active run's ledger; stray output is dropped. */
|
|
41
|
+
function logFrame(text, stream) {
|
|
42
|
+
if (active === null)
|
|
43
|
+
return;
|
|
44
|
+
emit({ type: 'log', id: active.id, text, stream });
|
|
45
|
+
}
|
|
46
|
+
/** Patch the program's output surfaces into ordered per-run log frames. */
|
|
47
|
+
function installOutputCapture() {
|
|
48
|
+
console.log = (...args) => { logFrame(format(...args) + '\n', 'stdout'); };
|
|
49
|
+
console.info = (...args) => { logFrame(format(...args) + '\n', 'stdout'); };
|
|
50
|
+
console.warn = (...args) => { logFrame(format(...args) + '\n', 'stderr'); };
|
|
51
|
+
console.error = (...args) => { logFrame(format(...args) + '\n', 'stderr'); };
|
|
52
|
+
console.debug = console.warn;
|
|
53
|
+
process.stderr.write = (chunk) => { logFrame(String(chunk), 'stderr'); return true; };
|
|
54
|
+
}
|
|
55
|
+
/** Render an unknown thrown value as a short error line. */
|
|
56
|
+
function messageOf(error) {
|
|
57
|
+
return error instanceof Error ? error.message : String(error);
|
|
58
|
+
}
|
|
59
|
+
/** Round-trip a completion through strict JSON; mirrors the Python lossless check. */
|
|
60
|
+
function losslessValue(value) {
|
|
61
|
+
try {
|
|
62
|
+
return { ok: true, value: JSON.parse(JSON.stringify(value)) };
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return { ok: false };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// --- tool bindings -----------------------------------------------------------
|
|
69
|
+
let nextCallSeq = 0;
|
|
70
|
+
/** Wrap one callable member into an async bridge that awaits a host reply. */
|
|
71
|
+
function makeCallable(run, gname, name, errorClass) {
|
|
72
|
+
return async (args) => {
|
|
73
|
+
const seq = ++nextCallSeq;
|
|
74
|
+
const pending = new Promise((resolve, reject) => {
|
|
75
|
+
run.calls.set(seq, { resolve, reject });
|
|
76
|
+
emit({ type: 'call', id: run.id, seq, global: gname, name, args });
|
|
77
|
+
});
|
|
78
|
+
let value;
|
|
79
|
+
try {
|
|
80
|
+
value = await pending;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
const message = messageOf(error);
|
|
84
|
+
const nameForMember = errorClass !== undefined
|
|
85
|
+
? error.__dshMember ?? name
|
|
86
|
+
: undefined;
|
|
87
|
+
const rejection = errorClass !== undefined
|
|
88
|
+
? new g[errorClass.name](message)
|
|
89
|
+
: new Error(message);
|
|
90
|
+
if (errorClass !== undefined) {
|
|
91
|
+
Object.assign(rejection, { [errorClass.memberNameProperty]: nameForMember });
|
|
92
|
+
}
|
|
93
|
+
throw rejection;
|
|
94
|
+
}
|
|
95
|
+
return value;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// --- cell execution ----------------------------------------------------------
|
|
99
|
+
function materializeNamespaces(run, namespaces) {
|
|
100
|
+
for (const descriptor of namespaces) {
|
|
101
|
+
const previous = g[descriptor.global];
|
|
102
|
+
run.restores.push([descriptor.global, previous]);
|
|
103
|
+
const record = {};
|
|
104
|
+
for (const name of descriptor.names) {
|
|
105
|
+
record[name] = makeCallable(run, descriptor.global, name, descriptor.errorClass);
|
|
106
|
+
}
|
|
107
|
+
g[descriptor.global] = record;
|
|
108
|
+
if (descriptor.errorClass !== undefined) {
|
|
109
|
+
const errorClassName = descriptor.errorClass.name;
|
|
110
|
+
const previousClass = g[errorClassName];
|
|
111
|
+
run.restores.push([errorClassName, previousClass]);
|
|
112
|
+
g[errorClassName] = class extends Error {
|
|
113
|
+
constructor(message) {
|
|
114
|
+
super(message);
|
|
115
|
+
this.name = errorClassName;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
// The anonymous class has an empty `.name`; reflect the descriptor so
|
|
119
|
+
// both `err.constructor.name` and `instanceof` read the real name.
|
|
120
|
+
Object.defineProperty(g[errorClassName], 'name', { value: errorClassName });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function restoreGlobals(run) {
|
|
125
|
+
for (const [name, previous] of run.restores) {
|
|
126
|
+
if (previous === undefined)
|
|
127
|
+
Reflect.deleteProperty(g, name);
|
|
128
|
+
else
|
|
129
|
+
g[name] = previous;
|
|
130
|
+
}
|
|
131
|
+
run.restores.length = 0;
|
|
132
|
+
}
|
|
133
|
+
/** The sentinel error that cancels a cell on SIGINT. */
|
|
134
|
+
const INTERRUPTED = new Error('run interrupted by SIGINT');
|
|
135
|
+
INTERRUPTED.name = 'INTERRUPTED';
|
|
136
|
+
/** Run one cell against this run's namespaces; settle the run when it finishes. */
|
|
137
|
+
async function runCell(code, run, namespaces) {
|
|
138
|
+
materializeNamespaces(run, namespaces);
|
|
139
|
+
const interrupted = new Promise((_resolve, reject) => { run.interrupt = () => { reject(INTERRUPTED); }; });
|
|
140
|
+
// Concatenation (not a template literal): the code is hostile user input and
|
|
141
|
+
// may contain backticks or `${...}` without breaking the wrapper. This is the
|
|
142
|
+
// kernel's core act — evaluation of model-written cells in a fresh wrapper.
|
|
143
|
+
// Construction can itself throw (a cell with invalid JavaScript syntax);
|
|
144
|
+
// that is a program error, not a reason to lose the kernel, so it settles
|
|
145
|
+
// the run instead of letting the exception escape and kill the runner.
|
|
146
|
+
// eslint-disable-next-line typescript/no-implied-eval -- persistent eval kernel by design
|
|
147
|
+
let done = false;
|
|
148
|
+
const finish = (frame) => {
|
|
149
|
+
if (done)
|
|
150
|
+
return;
|
|
151
|
+
done = true;
|
|
152
|
+
emit(frame);
|
|
153
|
+
};
|
|
154
|
+
let program;
|
|
155
|
+
try {
|
|
156
|
+
program = new Function('return (async () => {\n' + code + '\n})()');
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
const message = messageOf(error);
|
|
160
|
+
emit({ type: 'error', id: run.id, ename: 'SyntaxError', evalue: message, traceback: [] });
|
|
161
|
+
finish({ type: 'done', id: run.id, status: 'error', executionCount: ++executionCount, message });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
const promise = program.call(globalThis);
|
|
166
|
+
const value = await Promise.race([promise, interrupted]);
|
|
167
|
+
if (value === undefined) {
|
|
168
|
+
// No completion value: `undefined` is the worker backend's convention for
|
|
169
|
+
// a program that did not `return` anything, and the seam's value is optional.
|
|
170
|
+
finish({ type: 'done', id: run.id, status: 'ok', executionCount: ++executionCount });
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const serialized = losslessValue(value);
|
|
174
|
+
if (!serialized.ok) {
|
|
175
|
+
finish({ type: 'done', id: run.id, status: 'error', executionCount: ++executionCount, invalidOutput: true, message: 'program completion must be lossless JSON' });
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
finish({ type: 'done', id: run.id, status: 'ok', executionCount: ++executionCount, value: serialized.value });
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
if (error === INTERRUPTED) {
|
|
182
|
+
finish({ type: 'done', id: run.id, status: 'error', cancelled: true, executionCount: ++executionCount });
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const message = messageOf(error);
|
|
186
|
+
const stack = error instanceof Error && typeof error.stack === 'string' ? error.stack.split('\n') : [];
|
|
187
|
+
const ename = error instanceof Error ? error.name : 'Error';
|
|
188
|
+
emit({ type: 'error', id: run.id, ename, evalue: message, traceback: stack });
|
|
189
|
+
finish({ type: 'done', id: run.id, status: 'error', executionCount: ++executionCount, message });
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
restoreGlobals(run);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// --- wire loop ---------------------------------------------------------------
|
|
196
|
+
let readBuffer = '';
|
|
197
|
+
process.stdin.setEncoding('utf8');
|
|
198
|
+
process.stdin.on('data', (chunk) => {
|
|
199
|
+
readBuffer += chunk;
|
|
200
|
+
for (;;) {
|
|
201
|
+
const nl = readBuffer.indexOf('\n');
|
|
202
|
+
if (nl < 0)
|
|
203
|
+
break;
|
|
204
|
+
const line = readBuffer.slice(0, nl);
|
|
205
|
+
readBuffer = readBuffer.slice(nl + 1);
|
|
206
|
+
if (!line.trim())
|
|
207
|
+
continue;
|
|
208
|
+
let message;
|
|
209
|
+
try {
|
|
210
|
+
message = JSON.parse(line);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
void handleMessage(message);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
async function handleMessage(raw) {
|
|
219
|
+
if (raw === null || typeof raw !== 'object')
|
|
220
|
+
return;
|
|
221
|
+
const message = raw;
|
|
222
|
+
switch (message.type) {
|
|
223
|
+
case 'exec':
|
|
224
|
+
await handleExec(message);
|
|
225
|
+
break;
|
|
226
|
+
case 'reply':
|
|
227
|
+
handleReply(message);
|
|
228
|
+
break;
|
|
229
|
+
case 'exit':
|
|
230
|
+
process.exit(0);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function handleReply(message) {
|
|
234
|
+
if (active === null)
|
|
235
|
+
return;
|
|
236
|
+
const call = active.calls.get(message.seq);
|
|
237
|
+
if (call === undefined)
|
|
238
|
+
return;
|
|
239
|
+
active.calls.delete(message.seq);
|
|
240
|
+
if (message.ok)
|
|
241
|
+
call.resolve(message.value);
|
|
242
|
+
else {
|
|
243
|
+
const error = Object.assign(new Error(message.message ?? 'binding failed'), { __dshMember: message.name });
|
|
244
|
+
call.reject(error);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async function handleExec(message) {
|
|
248
|
+
if (typeof message.id !== 'string' || message.id.length === 0)
|
|
249
|
+
return;
|
|
250
|
+
if (typeof message.code !== 'string') {
|
|
251
|
+
emit({ type: 'error', id: message.id, ename: 'ProtocolError', evalue: 'code must be a string', traceback: [] });
|
|
252
|
+
emit({ type: 'done', id: message.id, status: 'error', executionCount: ++executionCount, message: 'code must be a string' });
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (typeof message.cwd === 'string') {
|
|
256
|
+
try {
|
|
257
|
+
process.chdir(message.cwd);
|
|
258
|
+
}
|
|
259
|
+
catch { /* keep previous cwd */ }
|
|
260
|
+
}
|
|
261
|
+
if (message.env !== undefined && typeof message.env === 'object') {
|
|
262
|
+
for (const [key, value] of Object.entries(message.env)) {
|
|
263
|
+
if (typeof value === 'string')
|
|
264
|
+
process.env[key] = value;
|
|
265
|
+
else
|
|
266
|
+
Reflect.deleteProperty(process.env, key);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const namespaces = Array.isArray(message.namespaces) ? message.namespaces : [];
|
|
270
|
+
const run = {
|
|
271
|
+
id: message.id,
|
|
272
|
+
calls: new Map(),
|
|
273
|
+
interrupt: () => { },
|
|
274
|
+
restores: [],
|
|
275
|
+
};
|
|
276
|
+
active = run;
|
|
277
|
+
emit({ type: 'started', id: run.id });
|
|
278
|
+
await runCell(message.code, run, namespaces);
|
|
279
|
+
// The run settled (normally, failed, or interrupted); a cancelled cell's
|
|
280
|
+
// ghost keeps evaluating in the background, so later runs must not see it.
|
|
281
|
+
if (active === run)
|
|
282
|
+
active = null;
|
|
283
|
+
}
|
|
284
|
+
// --- signals -----------------------------------------------------------------
|
|
285
|
+
/** SIGINT cancels the active run. A busy synchronous cell blocks the event
|
|
286
|
+
* loop here, so the host's escalation ladder (SIGTERM then SIGKILL) is what
|
|
287
|
+
* actually stops it — the same outcome, owned by the host. */
|
|
288
|
+
process.on('SIGINT', () => {
|
|
289
|
+
if (active !== null)
|
|
290
|
+
active.interrupt();
|
|
291
|
+
});
|
|
292
|
+
// --- boot --------------------------------------------------------------------
|
|
293
|
+
// The program cells evaluate through `new Function` in the process global
|
|
294
|
+
// scope; the persistent `state` object is exposed there so runs can share it.
|
|
295
|
+
g.state = state;
|
|
296
|
+
installOutputCapture();
|
|
297
|
+
emit({ type: 'ready', pid: process.pid });
|
|
298
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/nodejs/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAyBH,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAElC,4EAA4E;AAC5E,MAAM,CAAC,GAA4B,UAAgD,CAAA;AAEnF,+EAA+E;AAC/E,MAAM,SAAS,GAAuB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AAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAC/C,CAAC;IACH,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAA;IAC9E,MAAM,GAAG,GAAc;QACrB,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,KAAK,EAAE,IAAI,GAAG,EAAE;QAChB,SAAS,EAAE,GAAG,EAAE,GAA8B,CAAC;QAC/C,QAAQ,EAAE,EAAE;KACb,CAAA;IACD,MAAM,GAAG,GAAG,CAAA;IACZ,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;IACrC,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,UAAU,CAAC,CAAA;IAC5C,yEAAyE;IACzE,2EAA2E;IAC3E,IAAI,MAAM,KAAK,GAAG;QAAE,MAAM,GAAG,IAAI,CAAA;AACnC,CAAC;AAED,gFAAgF;AAEhF;;+DAE+D;AAC/D,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;IACxB,IAAI,MAAM,KAAK,IAAI;QAAE,MAAM,CAAC,SAAS,EAAE,CAAA;AACzC,CAAC,CAAC,CAAA;AAEF,gFAAgF;AAEhF,0EAA0E;AAC1E,8EAA8E;AAC9E,CAAC,CAAC,KAAK,GAAG,KAAK,CAAA;AACf,oBAAoB,EAAE,CAAA;AACtB,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The persistent Python kernel embedded as source. One long-lived `python3`
|
|
3
|
+
* subprocess runs this script; the host and it speak NDJSON over stdio. The
|
|
4
|
+
* script is deliberately SELF-CONTAINED (standard library only) so no
|
|
5
|
+
* virtualenv, package install, or site customization is needed to run model
|
|
6
|
+
* code against a persistent namespace and event loop.
|
|
7
|
+
*
|
|
8
|
+
* Wire protocol (one JSON object per line):
|
|
9
|
+
* - host -> kernel: `{"type":"exec","id":str,"code":str,"namespaces":[...],"cwd"?,"env"?}`,
|
|
10
|
+
* `{"type":"reply","id":str,"seq":int,"ok":bool,"value"?|"message"}`,
|
|
11
|
+
* `{"type":"exit"}`
|
|
12
|
+
* - kernel -> host: `{"type":"ready","pid":int}`, then per exec:
|
|
13
|
+
* `{"type":"started","id"}`, `{"type":"log","id","text","stream"?}`,
|
|
14
|
+
* `{"type":"call","id","seq":int,"global","name","args"}`,
|
|
15
|
+
* `{"type":"error","id","ename","evalue","traceback":[]}`,
|
|
16
|
+
* `{"type":"done","id","status":"ok"|"error","value"?,"executionCount":int,"cancelled":bool}`
|
|
17
|
+
*
|
|
18
|
+
* The runner is a persistent kernel: `user_ns` and one asyncio event loop
|
|
19
|
+
* survive across cells, so top-level `await` interleaves and assignments
|
|
20
|
+
* persist; tool bindings are bridged through wire frames that the host
|
|
21
|
+
* resolves against the CURRENT run's namespaces.
|
|
22
|
+
*
|
|
23
|
+
* @module @deepseek-ai/dsh-code-runtime-python/src/runner
|
|
24
|
+
*/
|
|
25
|
+
export declare const PYTHON_RUNNER: string;
|
|
26
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/python/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,eAAO,MAAM,aAAa,QA6kBzB,CAAA"}
|