@deepseek-ai/dsh-ptc-runtime-node 0.2.2-rc.5 → 0.2.3-alpha.2
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/README.i18n.yaml +24 -24
- package/README.md +49 -17
- package/README.zh.md +49 -17
- package/lib/configuration.js +15 -5
- package/lib/index.js +439 -148
- package/lib/persistent-process.js +683 -90
- package/lib/process.js +683 -90
- package/lib/types/bindings.d.ts +10 -5
- package/lib/types/bindings.d.ts.map +1 -1
- package/lib/types/bindings.js.map +1 -1
- package/lib/types/bootstrap.d.ts +42 -24
- package/lib/types/bootstrap.d.ts.map +1 -1
- package/lib/types/bootstrap.js.map +1 -1
- package/lib/types/config.d.ts +14 -2
- package/lib/types/config.d.ts.map +1 -1
- package/lib/types/config.js.map +1 -1
- package/lib/types/configuration.d.ts +5 -4
- package/lib/types/configuration.d.ts.map +1 -1
- package/lib/types/configuration.js.map +1 -1
- package/lib/types/environment.d.ts +13 -0
- package/lib/types/environment.d.ts.map +1 -1
- package/lib/types/environment.js.map +1 -1
- package/lib/types/evaluators/index.d.ts.map +1 -1
- package/lib/types/evaluators/index.js.map +1 -1
- package/lib/types/evaluators/scoped-repl-evaluator.d.ts +22 -0
- package/lib/types/evaluators/scoped-repl-evaluator.d.ts.map +1 -0
- package/lib/types/evaluators/scoped-repl-evaluator.js.map +1 -0
- package/lib/types/evaluators/scoped-repl.d.ts +130 -0
- package/lib/types/evaluators/scoped-repl.d.ts.map +1 -0
- package/lib/types/evaluators/scoped-repl.js.map +1 -0
- package/lib/types/evaluators/types.d.ts +3 -3
- package/lib/types/evaluators/types.d.ts.map +1 -1
- package/lib/types/evaluators/types.js.map +1 -1
- package/lib/types/execution.d.ts +3 -2
- package/lib/types/execution.d.ts.map +1 -1
- package/lib/types/execution.js.map +1 -1
- package/lib/types/index.d.ts +6 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/json-wire.d.ts +16 -4
- package/lib/types/json-wire.d.ts.map +1 -1
- package/lib/types/json-wire.js.map +1 -1
- package/lib/types/output-ledger.d.ts +10 -10
- package/lib/types/output-ledger.d.ts.map +1 -1
- package/lib/types/output-ledger.js.map +1 -1
- package/lib/types/process.d.ts +2 -0
- package/lib/types/process.d.ts.map +1 -1
- package/lib/types/process.js.map +1 -1
- package/lib/types/protocol.d.ts +31 -5
- package/lib/types/protocol.d.ts.map +1 -1
- package/lib/types/protocol.js.map +1 -1
- package/lib/types/worker.d.ts +6 -3
- package/lib/types/worker.d.ts.map +1 -1
- package/lib/types/worker.js.map +1 -1
- package/package.json +26 -24
- package/src/bindings.ts +33 -26
- package/src/bootstrap.ts +159 -57
- package/src/config.ts +21 -3
- package/src/configuration.ts +13 -6
- package/src/environment.ts +39 -0
- package/src/evaluators/index.ts +2 -0
- package/src/evaluators/scoped-repl-evaluator.ts +110 -0
- package/src/evaluators/scoped-repl.ts +339 -0
- package/src/evaluators/types.ts +3 -3
- package/src/execution.ts +37 -17
- package/src/imports/vm-modules.ts +1 -1
- package/src/index.ts +58 -13
- package/src/json-wire.ts +44 -8
- package/src/output-ledger.ts +42 -45
- package/src/process.ts +89 -18
- package/src/protocol.ts +37 -10
- package/src/worker.ts +75 -40
package/README.i18n.yaml
CHANGED
|
@@ -9,44 +9,44 @@
|
|
|
9
9
|
en: 7e1a8657a212c70b
|
|
10
10
|
zh: afb7a8c6a3afd718
|
|
11
11
|
/deepseek-ai-dsh-ptc-runtime-node/summary:
|
|
12
|
-
en:
|
|
13
|
-
zh:
|
|
12
|
+
en: e3350a3c7cde1663
|
|
13
|
+
zh: 2850eec5715e6f80
|
|
14
14
|
/deepseek-ai-dsh-ptc-runtime-node/table-of-contents:
|
|
15
15
|
en: d152484eb41ac6b4
|
|
16
16
|
zh: 725b47765ee8f30b
|
|
17
17
|
/deepseek-ai-dsh-ptc-runtime-node/use-this-package:
|
|
18
|
-
en:
|
|
19
|
-
zh:
|
|
18
|
+
en: 70e83ccdf8159a10
|
|
19
|
+
zh: 8282f1da5e844426
|
|
20
20
|
/deepseek-ai-dsh-ptc-runtime-node/use-this-package/configuration:
|
|
21
|
-
en:
|
|
22
|
-
zh:
|
|
21
|
+
en: b49a23785fd80315
|
|
22
|
+
zh: 1167b2face1e1028
|
|
23
23
|
/deepseek-ai-dsh-ptc-runtime-node/use-this-package/execution-and-results:
|
|
24
|
-
en:
|
|
25
|
-
zh:
|
|
24
|
+
en: e4c2a44c600693e9
|
|
25
|
+
zh: d4690975a3f95b14
|
|
26
26
|
/deepseek-ai-dsh-ptc-runtime-node/use-this-package/in-memory-modes:
|
|
27
|
-
en:
|
|
28
|
-
zh:
|
|
27
|
+
en: 6751521701e314dd
|
|
28
|
+
zh: 9e6c2b179f728414
|
|
29
29
|
/deepseek-ai-dsh-ptc-runtime-node/use-this-package/deadlines-and-cancellation:
|
|
30
30
|
en: d383ec7aeab8afec
|
|
31
31
|
zh: 7c9c49e205fbbcd8
|
|
32
32
|
/deepseek-ai-dsh-ptc-runtime-node/use-this-package/failures:
|
|
33
|
-
en:
|
|
34
|
-
zh:
|
|
33
|
+
en: e1bd21b71247a198
|
|
34
|
+
zh: f479995b244c6715
|
|
35
35
|
/deepseek-ai-dsh-ptc-runtime-node/understand-the-implementation:
|
|
36
|
-
en:
|
|
37
|
-
zh:
|
|
36
|
+
en: e8a08aa2481e7b3e
|
|
37
|
+
zh: eb1eed80b2bcc9b3
|
|
38
38
|
/deepseek-ai-dsh-ptc-runtime-node/understand-the-implementation/launch-and-control:
|
|
39
|
-
en:
|
|
40
|
-
zh:
|
|
39
|
+
en: 5c93014a885ed89e
|
|
40
|
+
zh: 21daedcd9de8cd7f
|
|
41
41
|
/deepseek-ai-dsh-ptc-runtime-node/understand-the-implementation/source-and-built-bootstraps:
|
|
42
|
-
en:
|
|
43
|
-
zh:
|
|
42
|
+
en: 20782961844b4192
|
|
43
|
+
zh: 2e7e592b38bf8449
|
|
44
44
|
/deepseek-ai-dsh-ptc-runtime-node/understand-the-implementation/runner-import-handling:
|
|
45
|
-
en:
|
|
46
|
-
zh:
|
|
45
|
+
en: ccde763016c0e039
|
|
46
|
+
zh: fd881e88391a9d90
|
|
47
47
|
/deepseek-ai-dsh-ptc-runtime-node/understand-the-implementation/source-map:
|
|
48
|
-
en:
|
|
49
|
-
zh:
|
|
48
|
+
en: 287412993ada4d41
|
|
49
|
+
zh: bb5ee33f715f32e5
|
|
50
50
|
/deepseek-ai-dsh-ptc-runtime-node/further-exploration:
|
|
51
51
|
en: ac2e2ae13d3f1394
|
|
52
52
|
zh: 5d08b9c658fcf83a
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
en: 40294c1c31b74824
|
|
58
58
|
zh: d91e7b78c0619c7e
|
|
59
59
|
/deepseek-ai-dsh-ptc-runtime-node/known-limitations-and-deferred-work:
|
|
60
|
-
en:
|
|
61
|
-
zh:
|
|
60
|
+
en: 1a4f709bbd6fdecf
|
|
61
|
+
zh: 5c60630d18220015
|
|
62
62
|
/deepseek-ai-dsh-ptc-runtime-node/known-limitations-and-deferred-work/dev-note:
|
|
63
63
|
en: 6373aba4e08f7205
|
|
64
64
|
zh: 2a8c33d1f2839df4
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ English | [中文](README.zh.md)
|
|
|
9
9
|
|
|
10
10
|
## Summary
|
|
11
11
|
|
|
12
|
-
Execute model-written TypeScript with host-provided async functions. The default `per-call`
|
|
12
|
+
Execute model-written TypeScript with host-provided async functions. The default `persistent-in-memory` mode retains a scoped REPL per Agent; `per-call` runs async function bodies in fresh Node processes; `vm-script` supports top-level await and optionally retains a context per Agent with `scriptPersistence`. All modes apply the file sandbox policy at process launch and return captured logs, lossless JSON, or structured failures. Elapsed deadlines, output bounds and a V8 heap limit constrain execution. Unacknowledged stops and one-shot completion clean up the managed process range; unavailable confinement fails execution.
|
|
13
13
|
|
|
14
14
|
## Table of Contents
|
|
15
15
|
|
|
@@ -27,6 +27,8 @@ Execute model-written TypeScript with host-provided async functions. The default
|
|
|
27
27
|
|
|
28
28
|
Mount this provider in a composition that supplies `fs`, `subprocess`, `sandbox` and `sandboxPolicy`. `dsh-tool-executor-ptc` supplies the calling Session's directory and standing policy; direct runtime consumers resolve those options before execution.
|
|
29
29
|
|
|
30
|
+
Programs display text, objects, and `Image` values through top-level `inspect(...values)`. One call can mix multiple texts and images, including images nested in arrays and objects. `Image.attachmentId` matches the attachment ID in the model's image description. `Image.path` names a stored attachment file readable in the execution environment; `width` and `height` describe that file’s pixels. Image descriptors share the `maxOutputBytes` budget with text.
|
|
31
|
+
|
|
30
32
|
### Configuration
|
|
31
33
|
|
|
32
34
|
Configure the provider row after its required services are available:
|
|
@@ -34,7 +36,7 @@ Configure the provider row after its required services are available:
|
|
|
34
36
|
```yaml
|
|
35
37
|
- name: '@deepseek-ai/dsh-ptc-runtime-node'
|
|
36
38
|
config:
|
|
37
|
-
executionMode:
|
|
39
|
+
executionMode: persistent-in-memory
|
|
38
40
|
timeoutMs: 120000
|
|
39
41
|
maxTimeoutMs: 600000
|
|
40
42
|
maxOutputBytes: 67108864
|
|
@@ -47,8 +49,9 @@ Configure the provider row after its required services are available:
|
|
|
47
49
|
|
|
48
50
|
| Field | Default | Meaning |
|
|
49
51
|
|---|---|---|
|
|
50
|
-
| `executionMode` | `
|
|
52
|
+
| `executionMode` | `persistent-in-memory` | `persistent-in-memory` retains a confined REPL per owner; `per-call` runs async function bodies in fresh processes; `vm-script` evaluates Scripts |
|
|
51
53
|
| `scriptPersistence` | `false` | With `executionMode: vm-script`, reuse a process and context per owner; `true` with another mode rejects at load |
|
|
54
|
+
| `replScoped` | `true` with `persistent-in-memory`, otherwise `false` | With `executionMode: persistent-in-memory`, run scoped REPL statements whose calls receive copies of earlier top-level bindings; `false` selects Node's REPL evaluator, and `true` with another mode rejects at load |
|
|
52
55
|
| `timeoutMs` | `120,000` | Default elapsed execution deadline, including nested tool and approval waits |
|
|
53
56
|
| `maxTimeoutMs` | `600,000` | Elapsed deadline ceiling applied by the resolver |
|
|
54
57
|
| `maxOutputBytes` | `67,108,864` | Combined serialized logs and completion or diagnostic budget |
|
|
@@ -61,15 +64,31 @@ Configure the provider row after its required services are available:
|
|
|
61
64
|
|
|
62
65
|
The [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-ptc-runtime-node) defines accepted config fields. `resolve(request)` defaults cwd to the sandbox policy workspace root and supplies the numeric or null deadline choice and execution policy; `run(spec)` accepts those resolved inputs and does not fill missing values.
|
|
63
66
|
|
|
64
|
-
Profile editors can import `resolvePersistentExecution` from `@deepseek-ai/dsh-ptc-runtime-node/configuration` to select retained execution from the effective program format. Merge
|
|
67
|
+
Profile editors can import `resolvePersistentExecution` from `@deepseek-ai/dsh-ptc-runtime-node/configuration` to select retained execution from the effective program format. Merge all three returned settings atomically: Script and scoped REPL keep their syntax, while function bodies and REPL statements switch to `persistent-in-memory` with its default `replScoped`, the scoped REPL.
|
|
65
68
|
|
|
66
69
|
### Execution and results
|
|
67
70
|
|
|
68
|
-
In `per-call` mode, programs are async function bodies: top-level `await` and `return` work, and only erasable TypeScript is accepted. Node globals remain available, and a function body may declare a local `process`, including `const process = await import("node:process")`. A successful call returns its lossless-JSON value as `result.value` and captured text as `result.
|
|
71
|
+
In `per-call` mode, programs are async function bodies: top-level `await` and `return` work, and only erasable TypeScript is accepted. Node globals remain available, and a function body may declare a local `process`, including `const process = await import("node:process")`. A successful call returns its lossless-JSON value as `result.value` and captured text and images as ordered `result.output` entries. `result.sandbox` reports the selected mode, observed denial and the backend's full or partial enforcement independently of the program outcome.
|
|
72
|
+
|
|
73
|
+
`inspect(...values)` uses binding-supplied text for an unchanged result passed directly as an argument. A host binding supplies this text through `PtcInspectableValue`; the program still receives the JSON object or array. Copies, selected fields, modified results, and results nested inside another value use ordinary formatting. The process owns the association with the original value and its initial snapshot; program properties do not carry it.
|
|
74
|
+
|
|
75
|
+
Non-empty binding-supplied text forms its own output group and does not join preceding string arguments with spaces. For `inspect('result:', result, 'done')`, the label is emitted with a newline, followed by the associated text; `done` starts a later group. Ordinary values within one group remain space-separated.
|
|
76
|
+
|
|
77
|
+
Inspectable data may contain host-issued Images. The provider preserves their program Image identities when capturing the inspection snapshot. Direct inspection of the unchanged container displays its supplied text; inspect an Image field explicitly to display that image.
|
|
78
|
+
|
|
79
|
+
For other values, `inspect(...values)` renders strings directly and uses Node's `util.inspect`, without depth, array-length or string-length preview limits. Undefined properties, Error objects and circular references remain visible. Registered Images are emitted directly or when Node's formatting reaches them in nested values, including Map entries, Set values and enumerable Symbol properties. Custom inspection methods determine which nested values are visited. Text and selected images follow argument order within the shared output budget. If object formatting throws, preceding inspected arguments remain visible. Each emitted text group ends in a newline; raw stream writes retain their original text.
|
|
80
|
+
|
|
81
|
+
All execution modes provide the complete native Node console, whose stdout and stderr writes enter the captured output. Model instructions say: "Use inspect(...values) to display output. Do not use console."
|
|
82
|
+
|
|
83
|
+
Model instructions also restrict raw template literals (`String.raw`) to short text whose backslashes must stay exactly as written, such as regular expressions. Other text, including file contents and commands, is requested as ordinary strings, and file contents as an array of quoted line strings joined with newlines.
|
|
84
|
+
|
|
85
|
+
Captured output stops at `maxOutputBytes`: the runtime keeps an ordered text and image prefix, drops subsequent output, and sets `outputTruncated: true`. Execution and awaited tool calls continue, including during initialization; existing deadlines, cancellation, memory and control-message limits still apply. Completion values and failure diagnostics take priority within the combined budget, so finalization may shorten the retained prefix. Required completion values remain lossless and fail with `output-limit` if they cannot fit; oversized diagnostics are truncated without changing the failure kind. Truncation alone neither fails execution nor clears retained variables.
|
|
86
|
+
|
|
87
|
+
`run_code` sets `discardCompletion: true`: function return values and final expression values are omitted without JSON serialization, while inspected output remains visible. Direct runtime consumers receive the usual lossless-JSON completion unless they set this option.
|
|
69
88
|
|
|
70
89
|
Direct filesystem, network and subprocess operations remain Node operations, subject to the selected OS sandbox. Nested host bindings cross the control channel; PTC tool calls retain the registry's visibility, ordering, logging and approval rules. Running a program does not change the Session's standing policy or automatically replay it after a denial.
|
|
71
90
|
|
|
72
|
-
Set `executionMode: vm-script` to evaluate erasable TypeScript through `node:vm` Script. Top-level declarations and `await` work, for example `var fs = await import("node:fs/promises"); await fs.readdir(".")`. Top-level `return` and static `import`/`export` are not supported. The runtime awaits the final expression
|
|
91
|
+
Set `executionMode: vm-script` to evaluate erasable TypeScript through `node:vm` Script. Top-level declarations and `await` work, for example `var fs = await import("node:fs/promises"); inspect(await fs.readdir("."))`. Top-level `return` and static `import`/`export` are not supported. The runtime awaits the final expression; its lossless JSON value is returned unless `discardCompletion` is enabled. Relative dynamic imports resolve from the supplied working directory. Script syntax is non-strict unless the program opts into strict mode; the context is not a security boundary, and Node access remains subject to the process sandbox.
|
|
73
92
|
|
|
74
93
|
`scriptPersistence: false` is the default: every call uses a fresh process and context, ignoring `stateOwner`. Set it to `true` to retain a context per owner under the lifecycle rules below. Top-level declarations, functions and object identities survive subsequent calls, including values initialized through top-level `await`. Function locals remain local. This option requires `executionMode: vm-script`; both settings accept the same syntax.
|
|
75
94
|
|
|
@@ -83,19 +102,25 @@ Set `executionMode: vm-script` to evaluate erasable TypeScript through `node:vm`
|
|
|
83
102
|
<a id="persistent-repl"></a>
|
|
84
103
|
### In-memory modes
|
|
85
104
|
|
|
86
|
-
The `persistent-in-memory` mode and Script mode with `scriptPersistence: true` retain state per owner.
|
|
105
|
+
The `persistent-in-memory` mode and Script mode with `scriptPersistence: true` retain state per owner. `persistent-in-memory` is the default `executionMode` and runs the scoped REPL unless `replScoped: false` selects Node's REPL evaluator. All modes require `fs`, `subprocess`, `sandbox` and `sandboxPolicy` and apply the file sandbox policy at process launch. To run function bodies in fresh processes instead, select `per-call` with a profile patch:
|
|
87
106
|
|
|
88
107
|
```yaml
|
|
89
108
|
- id: ptc-runtime
|
|
90
109
|
config:
|
|
91
|
-
executionMode:
|
|
110
|
+
executionMode: per-call
|
|
92
111
|
```
|
|
93
112
|
|
|
94
113
|
Save the patch and pass its path to `dsh headless --patch <path>` in a composition with PTC tool presentation. The `per-call` mode and Script mode with `scriptPersistence: false` retain no program memory between calls. Changing the configuration reloads the provider and releases its execution resources. Packaged single-executable hosts use their embedded carrier by default; the host sends the selected program format and retention flag with each evaluation, so the embedded `process.js` bootstrap serves both per-call and retained execution. Remote script deployments use a `node-script` launch with `launch.bootstrapPath` pointing to this package's built `persistent-process.js`.
|
|
95
114
|
|
|
96
|
-
In REPL mode, each live Agent keeps its own process and top-level variables, functions, and imported modules across `run_code` calls and turns. Use `await import(...)
|
|
115
|
+
In REPL mode, each live Agent keeps its own process and top-level variables, functions, and imported modules across `run_code` calls and turns. Use `await import(...)` and `inspect(...)`; top-level `return` is not supported. A leading `{ ... }` is a statement block and can contain top-level await and temporary declarations; parenthesize an object expression to return it. Retained functions and saved tool methods call the current evaluation's bindings. All tool calls must be awaited; callbacks from a completed evaluation cannot invoke tools in a later evaluation. With `replScoped: false`, assignments to undeclared names create retained globals under Node REPL’s non-strict evaluation, `_` and `_error` are ordinary retained globals without interactive REPL result setters, and Node REPL declaration rules apply, including errors on redeclaring existing `let`, `const`, or `class` names; assign to a mutable binding or choose a new name.
|
|
97
116
|
|
|
98
|
-
|
|
117
|
+
In `persistent-in-memory` mode, call `registerEnvironmentInitializer(program)` before the first run is admitted to install REPL source that executes once per new environment. The runtime installs current bindings first and evaluates initialization separately from the user program, sharing the first call's deadline, cancellation and output limits. It discards the completion value and includes printed output in the result. New owners, owner-less execution, release and process loss create environments that run initialization again; ordinary calls reuse initialized state. Assigning to an initialized global does not trigger initialization. Initialization lines do not shift user-program locations. Other modes reject registration.
|
|
118
|
+
|
|
119
|
+
Initialization errors, cancellation or timeout prevent the user program from starting and terminate the environment before returning. Earlier external effects remain. Once the Host accepts initialization, user-program failures follow the ordinary retained-state rules below. The [runtime service](../ptc-runtime/README.md#choose-a-backend) defines registration and asynchronous unregistration.
|
|
120
|
+
|
|
121
|
+
With `replScoped` omitted or `true`, `persistent-in-memory` reports program format `scoped-repl` and compiles each call as a separate strict VM Script in one retained context. Each call starts with copies of the top-level bindings left by earlier calls and may declare any of those names again with any keyword; functions and still-running code from earlier calls keep their own bindings, and assignments that earlier code makes after a call starts are not copied into it. Assigning to an earlier name without declaring it, including one declared with `const`, changes only the copy seen by that call and later calls. The last top-level expression statement is the completion and a Promise completion is not awaited; top-level `return` is rejected. `eval`, `new Function` and WebAssembly compilation in the program context are rejected. Programs load modules only with dynamic `import()`, whose relative specifiers resolve from the working directory of the environment's first call; `require`, `module` and built-in module globals are not provided. A `var` declared inside a block is a top-level name of its call and carries to later calls like any other `var`. A `var` redeclaration of an earlier name starts from the earlier value, so one that does not run, after a throw or in a branch that is not taken, keeps that value. Uncaught callback exceptions and unhandled rejections fail the evaluation that created the callback while it is active and are otherwise discarded, without ending the process; a callback that throws a frozen or non-extensible object still ends the process, as in Node REPL. The [scoped REPL decision](../../../.agents/notes/implemented/architecture/2026-11-09-retained-ptc-scoped-repl.md) records the complete behavior and its comparison with Node REPL.
|
|
122
|
+
|
|
123
|
+
Memory is best-effort and never saved to disk. Restart, Agent disposal, provider unload, protocol failure or process exit clears it. Missing variables raise normal reference errors; reacquire handles and recreate declarations. Exceptions in the active evaluation settle once and preserve earlier mutations. In REPL mode, exceptions from callbacks belonging to a completed evaluation are not reported in a later result. In Script mode, uncaught callback exceptions can terminate the retained process; await asynchronous work before completing an evaluation. The Session still records programs, tool dispatches and visible results; restoring a Session or forking an Agent starts with empty memory. Each evaluation resets the process working directory to its resolved cwd; program calls to `process.chdir()` do not persist across evaluations. Direct Node access follows the process launch policy. A retained owner cannot change mode, workspace root, or Session identity until its environment is released. Additional writable directories are fixed when the process starts: later grants and revocations apply only after release and recreation.
|
|
99
124
|
|
|
100
125
|
Service consumers pass an object as `stateOwner` to reuse its environment and await `release(owner)` when finished. Requests without an owner run in temporary processes. Their failures leave other owners' retained variables intact and do not report clearing them. Permission setters record the new mode synchronously. The runtime immediately invalidates affected processes and begins cancellation when the Session mode changes, including idle environments. The next program waits for their cleanup before starting; cleanup failure blocks that program and remains retryable. Permission-setting success does not mean old processes have finished stopping. A one-time approved escalation uses a separate environment and awaits its cleanup before returning; it cannot read the standing environment's variables or retain new declarations. Concurrent runs for one owner reject until execution and required cleanup complete; distinct owners may run concurrently. An idle environment has no expiration timer and keeps its process until release or failure. Raw stdout/stderr have no evaluation identity: bytes received during an evaluation share its output budget, even when written by an earlier child process; idle stdout is discarded and idle stderr retains only the bounded diagnostic tail. Await child-process completion before ending an evaluation. Process-exit diagnostics include the exit code and retained stderr tail; idle failures are written to the host logger. If process observation fails during cleanup, releasing the owner retries termination; new runs remain blocked until cleanup succeeds. Pipes that fail to drain after confirmed process exit produce a diagnostic but do not prevent releasing the environment.
|
|
101
126
|
|
|
@@ -109,7 +134,7 @@ Omitting `timeoutMs` uses the configured elapsed default; numeric requests are v
|
|
|
109
134
|
|
|
110
135
|
### Failures
|
|
111
136
|
|
|
112
|
-
Program parse errors and thrown exceptions are `exception`; deadline expiry is `timeout`; cancellation is `abort`; unparsable or oversized control traffic and invalid program messages are `protocol`; unavailable confinement is `sandbox-unavailable`; early process exit, lost control transport or failed managed cleanup is `worker-exit`. Control I/O failures retain the transport diagnostic alongside the observed process exit status. The substrate-independent failure name remains `worker-exit` for process providers.
|
|
137
|
+
Program parse errors and thrown exceptions are `exception`; deadline expiry is `timeout`; cancellation is `abort`; unparsable or oversized control traffic and invalid program messages are `protocol`; unavailable confinement is `sandbox-unavailable`; early process exit, lost control transport or failed managed cleanup is `worker-exit`. Control I/O failures retain the transport diagnostic alongside the observed process exit status. An output-suppression send that rejects while the evaluation and control channel remain active fails the run as `protocol`. Output drained during termination remains bounded locally without sending further suppression notifications. The substrate-independent failure name remains `worker-exit` for process providers. When completion capture is enabled, lossy values are `invalid-output`, and a completion that cannot fit even without captured output is `output-limit`. Neither failure clears retained variables. Diagnostic truncation preserves the failure kind. Invalid or unsupported options and calls after disposal reject as caller misuse.
|
|
113
138
|
|
|
114
139
|
-----
|
|
115
140
|
|
|
@@ -121,7 +146,7 @@ Program parse errors and thrown exceptions are `exception`; deadline expiry is `
|
|
|
121
146
|
|
|
122
147
|
The host owns policy, deadlines, binding lookup and process cleanup. The child owns program evaluation and binding proxies; model-written code is an untrusted peer even when its messages use the expected control descriptor.
|
|
123
148
|
|
|
124
|
-
`createExecution()` resolves the configured syntax, type erasure, model guidance and process lifetime once when the provider loads. The provider handles admission and cancellation. One execution owner creates temporary processes or reuses an enabled state owner's process; both use `ProgramWorker` for launch, deadlines, binding dispatch and cleanup. The shared child loop selects `createProgramEvaluator()` from the evaluation data; async-function, REPL and
|
|
149
|
+
`createExecution()` resolves the configured syntax, type erasure, model guidance and process lifetime once when the provider loads. The provider handles admission and cancellation. One execution owner creates temporary processes or reuses an enabled state owner's process; both use `ProgramWorker` for launch, deadlines, binding dispatch and cleanup. The child drops the experimental-feature warnings that the runtime itself triggers, for `vm.USE_MAIN_CONTEXT_DEFAULT_LOADER` and `stripTypeScriptTypes`, so they never enter program output; warnings that programs emit still print, and the host strips types without printing the `stripTypeScriptTypes` warning. The shared child loop selects `createProgramEvaluator()` from the evaluation data; async-function, REPL, Script and scoped REPL implementations expose globals, evaluation and cleanup independently of process lifetime. Initialization is awaited without adopting its completion value, followed by Host acknowledgement and the user program. The evaluator's completion callback settles the user program immediately; subsequent microtasks cannot log or invoke bindings. REPL diagnostics can also settle the active run. The scoped REPL evaluator also takes three creation options: `strict` (on), `codeGeneration` (off) and `finalExpression` (on). The runtime always passes their defaults, which the scoped REPL model guidance describes; the other values are kept by design for later configurations and tested in both states. Its redeclaration notice is likewise a reserved hook that prints nothing. The [scoped REPL decision](../../../.agents/notes/implemented/architecture/2026-11-09-retained-ptc-scoped-repl.md) records what each option changes.
|
|
125
150
|
|
|
126
151
|
### Launch and control
|
|
127
152
|
|
|
@@ -129,7 +154,7 @@ The host strips erasable types and, when starting a process, resolves the execut
|
|
|
129
154
|
|
|
130
155
|
Control traffic uses newline-delimited JSON on an inherited pipe separate from stdout/stderr. The RPC adapter bounds each message and queued native writes, rejects pending transport calls on closure, and runs no further methods after closure. Unsupported methods receive error replies. The host validates binding names and lossless JSON before dispatch.
|
|
131
156
|
|
|
132
|
-
The host calls the child's `run()` method over birpc on the ordered control pipe. Only one evaluation runs at a time; its asynchronous context prevents ended callbacks from starting new bindings or emitting captured output. RPC requests associate completions and binding replies with their callers. On timeout or cancellation, the host rejects new binding calls and late results, sends a one-way `revoke()` notification, and waits for the original `run()` response within `stopGraceMs`. Revocation rejects unfinished tool calls normally, allowing user `catch` and `finally` handlers to run. A validated response confirms settlement without changing the selected timeout or cancellation outcome. A missing, rejected or malformed response triggers termination. Callers must await settlement or fallback termination and cleanup before starting another evaluation. A blocked event loop cannot process revocation, so synchronous loops require process termination and lose retained state.
|
|
157
|
+
The host calls the child's `run()` method over birpc on the ordered control pipe. Only one evaluation runs at a time; its asynchronous context prevents ended callbacks from starting new bindings or emitting captured output. RPC requests associate completions and binding replies with their callers. A new environment completes initialization through the acknowledged `initialized()` RPC before user code starts; the Host accepts only while the first run remains active, and the child rechecks cancellation after the reply. On timeout or cancellation after initialization, the host rejects new binding calls and late results, sends a one-way `revoke()` notification, and waits for the original `run()` response within `stopGraceMs`. Revocation rejects unfinished tool calls normally, allowing user `catch` and `finally` handlers to run. A validated response confirms settlement without changing the selected timeout or cancellation outcome. A missing, rejected or malformed response triggers termination. Callers must await settlement or fallback termination and cleanup before starting another evaluation. A blocked event loop cannot process revocation, so synchronous loops require process termination and lose retained state.
|
|
133
158
|
|
|
134
159
|
Timers, arbitrary user-created Promises, I/O callbacks, Workers and child processes have no per-evaluation cancellation guarantee. Stop acknowledgment waits for the current evaluation to settle; it does not establish cleanup of those resources. Unmanaged asynchronous work may mutate retained globals after acknowledgment; captured output and completion from ended evaluations are ignored. Await required work before returning and use host reset when resources cannot be trusted.
|
|
135
160
|
|
|
@@ -139,12 +164,14 @@ Per-call completion leaves unfinished binding waits pending and stops binding ca
|
|
|
139
164
|
|
|
140
165
|
Source execution loads an erasable-only bootstrap closure without relying on sibling built exports; its evaluator modules and installed Acorn and birpc dependencies must be available in the execution world. Built script execution uses `process.js` for every mode; `persistent-process.js` delegates to the same loop with a REPL default for hosts that omit program syntax. Embedded carriers launch their private worker through `launch.executable` and carry the program format and retention flag in each evaluation. A remote script deployment supplies the matching `launch.bootstrapPath`. `resolveLaunch()` selects the local default during construction; an explicit remote invocation never depends on whether the client itself is packaged. A host path is never assumed to name the same remote file.
|
|
141
166
|
|
|
167
|
+
Custom `launch.bootstrapPath` deployments must use bootstrap protocol 5. `HostMethods.invoke` replies contain `{ value: flatWire, inspection?: string }`; the optional text is associated with the decoded object or array for direct inspection. Deploy the matching bootstrap with the host; the [inspection guide](../../../docs/upgrade-guide/v0.2.2-rc.3/ptc-tool-result-inspection/guide.md) covers binding replies and the [output-truncation guide](../../../docs/upgrade-guide/v0.2.2-rc.3/ptc-output-limit/guide.md) covers output suppression. Bootstraps announcing protocol 3 or 4 are rejected before program dispatch.
|
|
168
|
+
|
|
142
169
|
Source containing `await` is checked for top-level await before native compilation, which can otherwise treat `await` as an identifier. Acorn parses an async wrapper, and acorn-walk traverses it using Node's REPL visitors, declaration hoisting and character-position edits. Computed class-method keys are traversed while method bodies remain separate evaluations. The transform boxes the final expression; the evaluator unwraps and awaits its value. Source that needs no lowering uses native compilation; submissions without `await` retain native syntax diagnostics. Syntax errors preserve the parser message and available source location and caret, without compiler or transformer stack frames. Dynamic `import()` expressions remain native and use the compiling Script's `importModuleDynamically` option. Both private process bundles include Acorn, acorn-walk and birpc; source execution imports the installed packages.
|
|
143
170
|
|
|
144
171
|
<a id="runner-import-handling"></a>
|
|
145
172
|
### Runner import handling
|
|
146
173
|
|
|
147
|
-
Runner code can pass a `ProgramImportHandler` to `runNodeMain()` or `runPersistentMain()`. The handler belongs to the child process and is independent of execution syntax; it is not a serialized host binding or a plugin configuration field. VM Script accepts synchronous or asynchronous decisions; AsyncFunction and Node REPL require synchronous decisions and reject a returned Promise. `node-script` and embedded launches enable `--experimental-vm-modules`; independently started runners need that flag to intercept VM Script imports. AsyncFunction and REPL interception need no VM startup flag.
|
|
174
|
+
Runner code can pass a `ProgramImportHandler` to `runNodeMain()` or `runPersistentMain()`. The handler belongs to the child process and is independent of execution syntax; it is not a serialized host binding or a plugin configuration field. Scoped REPL programs use the VM Script handling for their dynamic imports. VM Script accepts synchronous or asynchronous decisions; AsyncFunction and Node REPL require synchronous decisions and reject a returned Promise. `node-script` and embedded launches enable `--experimental-vm-modules`; independently started runners need that flag to intercept VM Script and scoped REPL imports. AsyncFunction and Node REPL interception need no VM startup flag.
|
|
148
175
|
|
|
149
176
|
The handler receives each program's dynamic imports and, in VM Script, static and dynamic imports from VM-loaded ESM dependencies. Each request carries the specifier, import attributes and the importing file's absolute filename. Saved functions retain that filename even after cwd changes. The decisions are:
|
|
150
177
|
|
|
@@ -168,13 +195,15 @@ AsyncFunction and Node REPL share synchronous `registerHooks` and a symbol-keyed
|
|
|
168
195
|
| [`src/execution.ts`](src/execution.ts) | Mode selection, request resolution and temporary or retained process ownership |
|
|
169
196
|
| [`src/worker.ts`](src/worker.ts) | Shared process launch, evaluation deadlines and binding dispatch; `interruptEvaluation()` requests cooperative interruption, `terminate()` ends the process |
|
|
170
197
|
| [`src/persistent-process.ts`](src/persistent-process.ts) | Installed REPL-default entry delegating to the common child loop |
|
|
171
|
-
| [`src/evaluators/index.ts`](src/evaluators/index.ts) | Shared selection entry for the
|
|
198
|
+
| [`src/evaluators/index.ts`](src/evaluators/index.ts) | Shared selection entry for the four evaluators |
|
|
172
199
|
| [`src/imports/vm-modules.ts`](src/imports/vm-modules.ts) | Script import decisions, recursive ESM linking and native delegation |
|
|
173
200
|
| [`src/imports/module-hooks.ts`](src/imports/module-hooks.ts) | AsyncFunction and REPL hooks, evaluator attribution and export bridge |
|
|
174
201
|
| [`src/evaluators/async-function.ts`](src/evaluators/async-function.ts) | AsyncFunction: strict async function bodies |
|
|
175
202
|
| [`src/evaluators/repl.ts`](src/evaluators/repl.ts) | Node REPL: interactive declarations and retained context |
|
|
176
203
|
| [`src/evaluators/vm-script.ts`](src/evaluators/vm-script.ts) | VM Script: Node globals, declarations and Promise completion |
|
|
177
204
|
| [`src/evaluators/vm-script-await.ts`](src/evaluators/vm-script-await.ts) | VM Script top-level await lowering and retained declarations |
|
|
205
|
+
| [`src/evaluators/scoped-repl-evaluator.ts`](src/evaluators/scoped-repl-evaluator.ts) | Scoped REPL evaluator: context options, module globals and imports, completions and REPL-style asynchronous failures |
|
|
206
|
+
| [`src/evaluators/scoped-repl.ts`](src/evaluators/scoped-repl.ts) | Scoped REPL scope chain: bindings copied between programs, declaration scanning, source generation and Script compilation |
|
|
178
207
|
| [`src/output-stream.ts`](src/output-stream.ts) | Bounded stream capture and process-output draining |
|
|
179
208
|
| [`src/launch.ts`](src/launch.ts) | Executable/bootstrap arguments and execution-world asset mapping |
|
|
180
209
|
| [`src/process.ts`](src/process.ts) | Common child handshake, evaluator lifetime and binding RPC |
|
|
@@ -218,15 +247,18 @@ These limits qualify the execution guarantees and retained output.
|
|
|
218
247
|
- **Confinement inherits the selected backend's limits** — full and partial enforcement are reported separately; sandbox policy and managed-process containment are distinct guarantees.
|
|
219
248
|
- **The heap cap is not a process-tree memory limit** — native allocations and descendant memory are outside the V8 old-generation bound. No process-tree CPU meter is supplied.
|
|
220
249
|
- **Cleanup inherits subprocess observability** — escaped descendants on a fallback platform may remain outside the managed range; see the subprocess provider's stated limits.
|
|
221
|
-
-
|
|
250
|
+
- **`per-call` execution is one-shot** — retained state requires `persistent-in-memory`, the default, or Script mode with `scriptPersistence: true`; no mode offers a yield/wait API.
|
|
222
251
|
- **Await lowering relaxes declaration semantics** — in transformed programs, top-level `let`, `const`, and `class` bindings are mutable and initialized to `undefined` before execution; the native temporal dead zone does not apply. Function declarations populate retained globals when execution reaches them, and a `var` declaration without an initializer resets its binding to `undefined`. Direct-eval declarations stay within that evaluation. Top-level `using` declarations are rejected; put disposable bindings inside a block. Runtime stack locations refer to the transformed source. Scripts that compile without lowering keep native semantics.
|
|
223
252
|
- **Failed native lexical initialization can reserve a name** — if a top-level `let`, `const`, or `class` initializer throws before initializing its binding, that name remains uninitialized in the retained Script context. Reading, assigning or redeclaring it fails; use a new name or release and recreate the environment.
|
|
253
|
+
- **Scoped REPL copies values when a call starts** — with `replScoped` omitted or `true`, assignments that earlier code makes afterwards stay invisible to later calls, and a `let`, `const` or `class` redeclaration cannot read the earlier value of its own name. A `var` redeclaration starts from that value, so `var count = count + 1` adds to it, also after an earlier `let` or `const` of the same name. Relative `import()` specifiers keep resolving from the environment's first working directory after a later call changes directory; relative file access follows the current directory. The `codeGeneration` limit rejects only the program context's own `eval`, `Function` and WebAssembly compilation and is no isolation: main-realm functions copied into the context, such as `setTimeout.constructor`, still compile code. Columns after the inserted completion on the final expression's line shift right by 17, programs that start with `#!` or contain `__$binding_` anywhere are rejected, binding-global and error-class names containing that prefix fail before process launch, and a surviving function keeps every value copied into its call. The [scoped REPL decision](../../../.agents/notes/implemented/architecture/2026-11-09-retained-ptc-scoped-repl.md) lists the complete behavior.
|
|
224
254
|
- **Script values can cross realms** — binding results, binding rejection classes and imported modules can use constructors from outside the Script context. `instanceof Array` or `instanceof Error` can be false for those values; use `Array.isArray` and the declared binding error class.
|
|
225
255
|
- **In-memory environments retain one process per live owner** — idle owners keep their process and heap until explicit release, owner disposal or failure. Fan-out can retain many processes; idle expiration remains deferred.
|
|
226
256
|
- **Output caps reject rather than retain every byte** — spill can preserve only the bounded result delivered by this provider.
|
|
257
|
+
- **Formatting allocates before output accounting** — complete object and TypedArray formatting can require much more memory than the retained output. The output budget does not cap these temporary allocations; exhausting the configured heap can end the run with `worker-exit`.
|
|
258
|
+
- **Tool-result inspection retains extra data** — retaining an original tool result also retains its initial JSON snapshot and rendered text within the same heap budget; direct `inspect` compares the complete data.
|
|
227
259
|
- **Bindings are bounded at transport admission** — control limits do not bound the memory a host binding allocates while producing its result.
|
|
228
260
|
- **Preinstalled bootstraps require a compatible protocol revision** — readiness rejects a missing or mismatched revision before dispatching code. Upgrade `launch.bootstrapPath` with the host; the runtime does not install remote bootstrap updates.
|
|
229
|
-
- **
|
|
261
|
+
- **Image references live with the process** — every acquired image retains host metadata until the process terminates or its owner is released, including images that the program never displays. Long capture loops in retained environments accumulate these references.
|
|
230
262
|
|
|
231
263
|
<a id="dev-note"></a>
|
|
232
264
|
### Dev Note
|
package/README.zh.md
CHANGED
|
@@ -9,7 +9,7 @@ kind: "package-reference"
|
|
|
9
9
|
|
|
10
10
|
## 概述
|
|
11
11
|
|
|
12
|
-
执行模型编写的 TypeScript,并提供宿主异步函数。默认的 `per-call`
|
|
12
|
+
执行模型编写的 TypeScript,并提供宿主异步函数。默认的 `persistent-in-memory` 模式为每个 Agent 保留 scoped REPL;`per-call` 在全新 Node 进程中运行异步函数体;`vm-script` 支持顶层 await,并可通过 `scriptPersistence` 为每个 Agent 保留 context。所有模式都在进程启动时应用文件沙箱策略,返回捕获日志、无损 JSON 或结构化失败。执行时限、输出上限和 V8 堆上限约束运行。未确认的停止请求与单次执行完成后清理受管进程范围;约束不可用时执行失败。
|
|
13
13
|
|
|
14
14
|
## 目录
|
|
15
15
|
|
|
@@ -27,6 +27,8 @@ kind: "package-reference"
|
|
|
27
27
|
|
|
28
28
|
在提供 `fs`、`subprocess`、`sandbox` 和 `sandboxPolicy` 的组合中挂载本提供方。`dsh-tool-executor-ptc`传入调用 Session 的目录和常设策略;直接运行时消费方在执行前解析这些选项。
|
|
29
29
|
|
|
30
|
+
程序通过顶层 `inspect(...values)` 展示文本、对象与 `Image`;同一次调用可混合多段文本和多张图片,图片也可嵌入数组或对象。`Image.attachmentId` 与模型收到的图片说明中的附件 ID 一致。`Image.path` 是执行环境可读取的已存储附件文件,`width` 与 `height` 为该文件的像素尺寸。图片元数据与文本共用 `maxOutputBytes` 预算。
|
|
31
|
+
|
|
30
32
|
### 配置
|
|
31
33
|
|
|
32
34
|
在所需服务可用后,配置提供方条目:
|
|
@@ -34,7 +36,7 @@ kind: "package-reference"
|
|
|
34
36
|
```yaml
|
|
35
37
|
- name: '@deepseek-ai/dsh-ptc-runtime-node'
|
|
36
38
|
config:
|
|
37
|
-
executionMode:
|
|
39
|
+
executionMode: persistent-in-memory
|
|
38
40
|
timeoutMs: 120000
|
|
39
41
|
maxTimeoutMs: 600000
|
|
40
42
|
maxOutputBytes: 67108864
|
|
@@ -47,8 +49,9 @@ kind: "package-reference"
|
|
|
47
49
|
|
|
48
50
|
| 字段 | 默认值 | 含义 |
|
|
49
51
|
|---|---|---|
|
|
50
|
-
| `executionMode` | `
|
|
52
|
+
| `executionMode` | `persistent-in-memory` | `persistent-in-memory` 为每个所有者保留受限 REPL;`per-call` 在全新进程中运行异步函数体;`vm-script` 求值 Script |
|
|
51
53
|
| `scriptPersistence` | `false` | 在 `executionMode: vm-script` 下,为每个所有者复用进程与 context;其他模式下设为 `true` 会在加载时拒绝 |
|
|
54
|
+
| `replScoped` | `persistent-in-memory` 下为 `true`,其他模式下为 `false` | 在 `executionMode: persistent-in-memory` 下,按 scoped REPL 语句执行,每次调用拿到之前顶层绑定的拷贝;设为 `false` 时使用 Node 的 REPL 求值器,其他模式下设为 `true` 会在加载时拒绝 |
|
|
52
55
|
| `timeoutMs` | `120,000` | 默认经过时间截止,包括嵌套工具与审批等待 |
|
|
53
56
|
| `maxTimeoutMs` | `600,000` | 解析器应用的经过时间截止上限 |
|
|
54
57
|
| `maxOutputBytes` | `67,108,864` | 序列化日志与完成值或诊断的合计预算 |
|
|
@@ -61,15 +64,31 @@ kind: "package-reference"
|
|
|
61
64
|
|
|
62
65
|
[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-ptc-runtime-node)定义可接受的配置字段。`resolve(request)` 将 cwd 默认设为沙箱策略的工作区根目录,并补全数值或 null 截止选择与执行策略;`run(spec)` 接受这些已解析输入,不补缺省值。
|
|
63
66
|
|
|
64
|
-
profile 编辑器可从 `@deepseek-ai/dsh-ptc-runtime-node/configuration` 导入 `resolvePersistentExecution
|
|
67
|
+
profile 编辑器可从 `@deepseek-ai/dsh-ptc-runtime-node/configuration` 导入 `resolvePersistentExecution`,根据当前有效程序格式选择持久执行设置。返回的三个设置必须原子合入:Script 和 scoped REPL 保留原语法,函数体和 REPL 语句切换为使用默认 `replScoped` 的 `persistent-in-memory`,也就是 scoped REPL。
|
|
65
68
|
|
|
66
69
|
### 执行与结果
|
|
67
70
|
|
|
68
|
-
`per-call` 模式中的程序是异步函数体:支持顶层 `await` 与 `return`,且只接受可擦除 TypeScript。Node 全局变量仍然可用,函数体可声明局部 `process`,例如 `const process = await import("node:process")`。成功调用以 `result.value` 返回无损 JSON 值,以 `result.
|
|
71
|
+
`per-call` 模式中的程序是异步函数体:支持顶层 `await` 与 `return`,且只接受可擦除 TypeScript。Node 全局变量仍然可用,函数体可声明局部 `process`,例如 `const process = await import("node:process")`。成功调用以 `result.value` 返回无损 JSON 值,以 `result.output` 按顺序返回捕获的文本和图片。`result.sandbox` 独立于程序结果报告所选模式、观察到的拒绝,以及后端完整或部分的强制能力。
|
|
72
|
+
|
|
73
|
+
将未修改的原结果直接作为参数传给 `inspect(...values)` 时,会使用绑定附带的文本。宿主绑定通过 `PtcInspectableValue` 提供文本;程序仍收到 JSON 对象或数组。拷贝、选定字段、修改后的结果,以及嵌套在其他值中的结果,使用普通格式。进程保存原值、初始快照与展示文本的关联;程序对象的属性不携带该关联。
|
|
74
|
+
|
|
75
|
+
非空的绑定附带文本独占一个输出组,不与前面的字符串参数用空格拼接。执行 `inspect('result:', result, 'done')` 时,先输出标签并换行,再输出关联文本,`done` 另起后续输出组。同组普通值仍以空格分隔。
|
|
76
|
+
|
|
77
|
+
可展示的数据中可以包含宿主提供的 Image。提供方在生成展示快照时保留这些程序 Image 的身份。直接展示未修改的容器时只输出附带文本;显式展示 Image 字段时输出该图片。
|
|
78
|
+
|
|
79
|
+
对于其他值,`inspect(...values)` 直接渲染字符串,并使用 Node 的 `util.inspect` 格式化其他类型,不限制预览深度、数组项数或字符串长度。undefined 属性、Error 对象和循环引用均会展示。注册的 Image 可以直接输出,也可以在 Node 格式化嵌套值时输出,包括 Map 条目、Set 的值以及可枚举的 Symbol 属性。自定义 inspect 方法决定会访问哪些嵌套值。文本和所选图片在共享输出预算内遵循参数顺序。如果对象格式化抛错,此前 inspect 的参数仍然可见。每个文本输出组以换行结尾,原始流写入则保留实际文本。
|
|
80
|
+
|
|
81
|
+
所有执行模式都提供完整的 Node 原生 console,其 stdout 和 stderr 写入会进入捕获输出。模型指引要求:“使用 inspect(...values) 展示输出,不要使用 console。”
|
|
82
|
+
|
|
83
|
+
模型指引还要求:raw 模板字面量(`String.raw`)只用于反斜杠必须原样保留的短文本,例如正则表达式。其他文本,包括文件内容和命令,用普通字符串书写;文件内容写成逐行引号字符串组成的数组,再用换行符拼接。
|
|
84
|
+
|
|
85
|
+
捕获输出达到 `maxOutputBytes` 后,运行时保留有序的图文前缀,丢弃后续输出,并设置 `outputTruncated: true`。程序和等待中的工具调用继续执行,初始化期间也一样;原有截止时间、取消、内存和控制消息限制继续生效。完成值和失败诊断在组合预算内优先,因此最终结算可能缩短已保留的输出前缀。要求返回的完成值保持无损,无法容纳时以 `output-limit` 失败;过大的诊断会截断,但不改变失败类型。截断本身不会使执行失败或清空保留变量。
|
|
86
|
+
|
|
87
|
+
`run_code` 设置 `discardCompletion: true`:函数返回值和末尾表达式的值不经过 JSON 序列化,也不出现在结果中,显式 inspect 的输出仍然可见。直接调用运行时的消费方在未设置此选项时,仍可取得原有的无损 JSON 完成值。
|
|
69
88
|
|
|
70
89
|
直接文件系统、网络与子进程操作仍是 Node 操作,受所选 OS 沙箱约束。嵌套 Host 绑定通过控制通道调用;PTC 工具调用保留注册表的可见性、排序、日志和审批规则。运行程序不会改变 Session 的常设策略,也不会在拒绝后自动重放程序。
|
|
71
90
|
|
|
72
|
-
设置 `executionMode: vm-script`,即可通过 `node:vm` Script 求值可擦除 TypeScript。支持顶层声明和 `await`,例如 `var fs = await import("node:fs/promises"); await fs.readdir(".")`。不支持顶层 `return` 和静态 `import`/`export
|
|
91
|
+
设置 `executionMode: vm-script`,即可通过 `node:vm` Script 求值可擦除 TypeScript。支持顶层声明和 `await`,例如 `var fs = await import("node:fs/promises"); inspect(await fs.readdir("."))`。不支持顶层 `return` 和静态 `import`/`export`。运行时等待末尾表达式;未启用 `discardCompletion` 时,返回其无损 JSON 值。相对动态导入以传入的工作目录为基准解析。除非程序显式启用严格模式,否则 Script 使用非严格语法;context 不是安全边界,Node 访问仍受进程沙箱约束。
|
|
73
92
|
|
|
74
93
|
`scriptPersistence: false` 是默认值:每次调用都使用全新进程和 context,忽略 `stateOwner`。设为 `true` 后,运行时按下述生命周期规则为每个所有者保留 context。顶层声明、函数与对象身份可供后续调用使用,包括通过顶层 `await` 初始化的值。函数局部变量仍只在函数内有效。该选项要求 `executionMode: vm-script`;两种设置接受相同语法。
|
|
75
94
|
|
|
@@ -83,19 +102,25 @@ profile 编辑器可从 `@deepseek-ai/dsh-ptc-runtime-node/configuration` 导入
|
|
|
83
102
|
<a id="persistent-repl"></a>
|
|
84
103
|
### 内存保留模式
|
|
85
104
|
|
|
86
|
-
`persistent-in-memory` 模式和启用 `scriptPersistence: true` 的 Script
|
|
105
|
+
`persistent-in-memory` 模式和启用 `scriptPersistence: true` 的 Script 模式都按所有者保留状态。`persistent-in-memory` 是 `executionMode` 的默认值,运行 scoped REPL,设置 `replScoped: false` 时使用 Node 的 REPL 求值器。所有模式都需要 `fs`、`subprocess`、`sandbox` 和 `sandboxPolicy`,并在进程启动时应用文件沙箱策略。如果要改为在全新进程中运行函数体,通过配置档补丁选择 `per-call`:
|
|
87
106
|
|
|
88
107
|
```yaml
|
|
89
108
|
- id: ptc-runtime
|
|
90
109
|
config:
|
|
91
|
-
executionMode:
|
|
110
|
+
executionMode: per-call
|
|
92
111
|
```
|
|
93
112
|
|
|
94
113
|
保存补丁,在使用 PTC 工具展示的配置中通过 `dsh headless --patch <path>` 加载。`per-call` 模式和 `scriptPersistence: false` 的 Script 模式不跨调用保留程序内存。修改配置会重载提供方并释放其执行资源。单文件打包宿主默认使用内嵌载体;宿主在每次执行中发送所选的程序格式和保留标志,因此内嵌的 `process.js` bootstrap 同时服务单次执行和保留执行。远端脚本部署使用 `node-script` 启动方式,并将 `launch.bootstrapPath` 指向本包构建出的 `persistent-process.js`。
|
|
95
114
|
|
|
96
|
-
在 REPL 模式下,每个存活 Agent 保留独立进程,跨 `run_code` 调用和轮次保留顶层变量、函数及导入模块。使用 `await import(...)
|
|
115
|
+
在 REPL 模式下,每个存活 Agent 保留独立进程,跨 `run_code` 调用和轮次保留顶层变量、函数及导入模块。使用 `await import(...)` 和 `inspect(...)`;不支持顶层 `return`。开头的 `{ ... }` 按语句块执行,可以包含顶层 await 和临时声明;需要返回对象表达式时,用圆括号包裹。保留的函数和工具方法引用调用当前执行的绑定。必须等待所有工具调用;已完成执行的回调不能在后续执行中调用工具。设置 `replScoped: false` 时,Node REPL 使用非严格模式,给未声明的名称赋值会创建保留的全局变量;`_` 和 `_error` 是普通的保留全局变量,不使用交互式 REPL 的结果设置器;声明遵循 Node REPL 规则,包括重复声明已有 `let`、`const` 或 `class` 名称时报错,应给可变绑定赋值或选择新名称。
|
|
97
116
|
|
|
98
|
-
|
|
117
|
+
在 `persistent-in-memory` 模式下,于运行时首次接纳运行前调用 `registerEnvironmentInitializer(program)`,注册在每个新环境中只执行一次的 REPL 源码。运行时先安装本次绑定,再独立于用户程序求值初始化;二者共享首次调用的截止时间、取消和输出上限。初始化的完成值会被丢弃,打印输出加入结果。新所有者、无所有者执行,以及释放或进程丢失后的运行会创建新环境并再次执行初始化;普通调用复用已初始化的状态。给已初始化的全局变量赋值不会触发初始化。初始化行不会偏移用户程序的位置。其他模式会拒绝注册。
|
|
118
|
+
|
|
119
|
+
初始化期间的错误、取消或超时会阻止用户程序启动,并在返回前终止该环境。此前的外部效果仍然保留。Host 确认初始化完成后,用户程序失败遵循下方的普通状态保留规则。[运行时服务](../ptc-runtime/README.zh.md#choose-a-backend)定义注册和异步注销行为。
|
|
120
|
+
|
|
121
|
+
省略 `replScoped` 或设为 `true` 时,`persistent-in-memory` 报告程序格式 `scoped-repl`,每次调用编译成同一个保留 context 里独立的 strict VM Script。每次调用开始时拿到之前调用留下的顶层绑定的拷贝,可以用任意关键字再次声明这些名字;之前调用里的函数和仍在运行的代码保留各自的绑定,调用开始后之前的代码再赋的值不会拷进来。不声明、直接给之前的名字赋值,包括用 `const` 声明的名字,只改这次及之后调用看到的拷贝。最后一条顶层表达式语句是完成值,Promise 完成值不会被等待;顶层 `return` 会被拒绝。程序环境里的 `eval`、`new Function` 和 WebAssembly 编译会被拒绝。程序只能用动态 `import()` 加载模块,相对路径按这个环境第一次调用时的工作目录解析;不提供 `require`、`module` 和内置模块全局变量。块里声明的 `var` 算作这次调用的顶层名字,和其他 `var` 一样带到之后的调用。用 `var` 重新声明之前的名字时,这次的 `var` 从旧值开始,所以没执行到的声明(抛错之后或在没走到的分支里)保留旧值。未捕获的回调异常和未处理的 rejection,在创建回调的那次执行仍在运行时让它失败,否则被丢弃,不会结束进程;回调里抛出冻结或不可扩展的对象时,进程仍会结束,与 Node REPL 相同。[scoped REPL 决策](../../../.agents/notes/implemented/architecture/2026-11-09-retained-ptc-scoped-repl.zh.md)记录完整行为及其与 Node REPL 的对比。
|
|
122
|
+
|
|
123
|
+
内存按尽力保留处理,不保存到磁盘。重启、Agent 销毁、提供方卸载、协议失败或进程退出都会清除内存。缺失变量产生普通引用错误,模型需要重新获取句柄和创建声明。当前执行中的异常只结算一次,并保留此前发生的修改。在 REPL 模式下,已完成执行的回调抛出的异常不会在后续结果中报告。在 Script 模式下,未捕获的回调异常可能终止保留进程;结束执行前应等待异步工作完成。Session 仍记录程序、工具分派和可见结果;恢复 Session 或派生 Agent 时从空内存开始。每次执行都会将进程工作目录重置为本次解析的 cwd;程序中的 `process.chdir()` 不跨执行保留。直接 Node 访问遵循进程启动时的文件策略。保留状态的所有者必须先释放环境,才能更改权限模式、工作区根目录或 Session 身份。额外可写目录在进程启动时固定:之后的授权和撤销仅在释放并重新创建环境后生效。
|
|
99
124
|
|
|
100
125
|
服务消费者通过 `stateOwner` 对象复用环境,并在结束时等待 `release(owner)`。没有所有者的请求在临时进程中执行。此类执行失败不影响其他所有者保留的变量,也不报告清空了这些变量。权限设置同步记录新模式。Session 模式变化时,运行时立即禁止复用受影响的进程并开始取消,包括空闲环境。下一次程序执行前等待这些进程清理;清理失败会阻止本次程序启动,并允许重试。权限设置成功时,旧进程可能仍在停止过程中。单次获准的提权使用独立环境,返回前等待清理;该次执行无法访问原环境的变量,也不会保留新声明。执行及必要清理完成之前,同一所有者的并发调用会被拒绝;不同所有者可以并发。空闲环境没有过期计时器,进程保留到释放或失败为止。原始 stdout/stderr 不携带执行标识:执行期间收到的字节计入本次输出预算,包括较早启动的子进程此时写出的内容;空闲期间丢弃 stdout,只保留限额内的 stderr 诊断尾部。结束本次执行前,应等待子进程完成。进程退出诊断包含退出码和保留的 stderr 尾部;空闲期间的失败写入宿主日志。清理期间无法观测进程范围时,释放所有者会重试终止;清理成功前拒绝新执行。确认进程退出后仍未排空的管道会产生诊断,但不阻止释放环境。
|
|
101
126
|
|
|
@@ -109,7 +134,7 @@ PTC 消费方按 [dsh-tool-executor-ptc](../../core/tool-executor-ptc/README.zh.
|
|
|
109
134
|
|
|
110
135
|
### 失败
|
|
111
136
|
|
|
112
|
-
程序解析错误与抛出异常为 `exception`;截止到期为 `timeout`;取消为 `abort`;无法解析或超量的控制通信以及无效的程序消息为 `protocol`;约束不可用为 `sandbox-unavailable`;进程提前退出、控制通道丢失或受管清理失败为 `worker-exit`。控制通道 I/O
|
|
137
|
+
程序解析错误与抛出异常为 `exception`;截止到期为 `timeout`;取消为 `abort`;无法解析或超量的控制通信以及无效的程序消息为 `protocol`;约束不可用为 `sandbox-unavailable`;进程提前退出、控制通道丢失或受管清理失败为 `worker-exit`。控制通道 I/O 失败时,在观测到的进程退出状态之外保留通道诊断原因。若求值和控制通道仍然有效,发送输出抑制通知被拒绝会使本次运行以 `protocol` 失败。终止期间排空的输出仍在本地受预算限制,不再发送输出抑制通知。进程提供方保留与执行基底无关的失败名 `worker-exit`。捕获完成值时,有损值为 `invalid-output`,即使不保留捕获输出也无法容纳的完成值为 `output-limit`。这两种失败都不会清空保留变量。诊断截断保留原来的失败类型。无效或不支持的选项,以及资源释放后的调用,以调用方误用拒绝。
|
|
113
138
|
|
|
114
139
|
-----
|
|
115
140
|
|
|
@@ -121,7 +146,7 @@ PTC 消费方按 [dsh-tool-executor-ptc](../../core/tool-executor-ptc/README.zh.
|
|
|
121
146
|
|
|
122
147
|
Host 负责策略、截止时间、绑定查找和进程清理。子进程负责程序求值与绑定代理;即使使用预期的控制描述符,模型编写的代码仍是不可信对端。
|
|
123
148
|
|
|
124
|
-
`createExecution()` 在提供方加载时一次性确定配置对应的语法、类型擦除、模型指导和进程生命周期。提供方处理执行准入与取消。统一的执行所有者创建临时进程,或在启用状态保留时复用所有者的进程;二者都由 `ProgramWorker`
|
|
149
|
+
`createExecution()` 在提供方加载时一次性确定配置对应的语法、类型擦除、模型指导和进程生命周期。提供方处理执行准入与取消。统一的执行所有者创建临时进程,或在启用状态保留时复用所有者的进程;二者都由 `ProgramWorker` 负责启动、截止时间、绑定分派和清理。子进程会丢弃运行时自身触发的实验性功能警告(`vm.USE_MAIN_CONTEXT_DEFAULT_LOADER` 和 `stripTypeScriptTypes`),它们不会进入程序输出;程序自己发出的警告照常打印,宿主擦除类型时也不打印 `stripTypeScriptTypes` 警告。共用的子进程循环根据本次执行数据选择 `createProgramEvaluator()`;异步函数、REPL、Script 和 scoped REPL 实现提供全局变量、求值与清理操作,与进程生命周期独立。运行时等待初始化求值结束,不等待或展开其完成值;随后等待 Host 确认,再执行用户程序。求值器报告完成时立即结算用户程序;随后运行的微任务不能再输出内容或调用绑定。REPL 诊断也可以结算当前运行。scoped REPL 求值器还接受三个创建参数:`strict`(默认开)、`codeGeneration`(默认关)和 `finalExpression`(默认开)。运行时总是取默认值,scoped REPL 的模型说明描述的也是默认值;其他取值是设计上为以后的配置预留的,两种状态都有测试。重复声明通知同样是预留的钩子,不输出任何内容。[scoped REPL 决策](../../../.agents/notes/implemented/architecture/2026-11-09-retained-ptc-scoped-repl.zh.md)记录每个参数改变什么。
|
|
125
150
|
|
|
126
151
|
### 启动与控制
|
|
127
152
|
|
|
@@ -129,7 +154,7 @@ Host 擦除可擦除类型;需要启动进程时,在配置的执行世界中
|
|
|
129
154
|
|
|
130
155
|
控制通信使用继承管道上的逐行 JSON,与 stdout/stderr 分离。RPC 适配层限制每条消息和原生写入队列的大小,在通道关闭时拒绝待完成的传输调用,关闭后不再执行方法。不支持的方法会收到错误回复。Host 在分派前校验绑定名称和无损 JSON。
|
|
131
156
|
|
|
132
|
-
Host 通过有序控制管道上的 birpc 调用子进程的 `run()`。同一时间只运行一次执行,其异步上下文阻止已结束执行的回调发起新绑定或发送捕获输出。RPC
|
|
157
|
+
Host 通过有序控制管道上的 birpc 调用子进程的 `run()`。同一时间只运行一次执行,其异步上下文阻止已结束执行的回调发起新绑定或发送捕获输出。RPC 请求将执行完成结果和绑定回复关联到各自的调用方。新环境在用户代码启动前通过需要确认的 `initialized()` RPC 完成初始化;Host 仅在首次运行仍处于活动状态时接受该调用,子进程收到回复后再次检查取消状态。初始化完成后发生超时或取消时,Host 拒绝新绑定调用及迟到结果,发送单向 `revoke()` 通知,并在 `stopGraceMs` 内等待原 `run()` 响应。撤销会让未完成的工具调用正常抛错,允许用户的 `catch` 和 `finally` 运行。有效响应确认本次执行已结束,不改变已选定的超时或取消结果。未收到响应、请求被拒绝或响应格式无效时,终止进程。调用方必须等待执行结束,或兜底终止及清理完成后,才能开始下一次执行。阻塞的事件循环无法处理撤销,因此同步死循环需要终止进程并丢失保留状态。
|
|
133
158
|
|
|
134
159
|
定时器、任意用户创建的 Promise、I/O 回调、Worker 和子进程不承诺按执行取消。停止确认仅等待当前执行结束,不表示这些资源已清理。未受管异步工作在确认停止后仍可能修改保留的全局变量;已结束执行的捕获输出和完成通知会被忽略。返回前应等待必要工作完成,资源不可信时使用宿主重置。
|
|
135
160
|
|
|
@@ -139,12 +164,14 @@ Host 通过有序控制管道上的 birpc 调用子进程的 `run()`。同一时
|
|
|
139
164
|
|
|
140
165
|
源代码执行加载仅含可擦除语法的 bootstrap 依赖,不依赖同级包的构建后导出;执行世界中必须提供求值器模块和已安装的 Acorn 与 birpc 依赖。构建后脚本对所有模式使用 `process.js`;`persistent-process.js` 委托同一个循环,并为未指定程序语法的宿主提供 REPL 默认值。内嵌载体通过 `launch.executable` 启动私有 worker,并在每次执行中携带程序格式和保留标志。远端脚本部署提供对应的 `launch.bootstrapPath`。`resolveLaunch()` 在构造时选择本地默认值;显式的远端调用不依赖客户端自身是否打包。不会假设 Host 路径对应同一个远程文件。
|
|
141
166
|
|
|
167
|
+
自定义 `launch.bootstrapPath` 部署必须使用 bootstrap 协议 5。`HostMethods.invoke` 的回复包含 `{ value: flatWire, inspection?: string }`;可选文本与解码后的对象或数组关联,供直接展示使用。请与宿主一起部署匹配的 bootstrap;[展示指南](../../../docs/upgrade-guide/v0.2.2-rc.3/ptc-tool-result-inspection/guide.zh.md)说明绑定回复,[输出截断指南](../../../docs/upgrade-guide/v0.2.2-rc.3/ptc-output-limit/guide.zh.md)说明输出抑制。声明协议 3 或 4 的 bootstrap 会在程序分发前被拒绝。
|
|
168
|
+
|
|
142
169
|
包含 `await` 的源码会在原生编译前检查顶层 await,否则原生编译可能将 `await` 当作标识符。Acorn 解析包住源码的异步函数,acorn-walk 沿用 Node REPL 的 visitor、声明提升和按字符位置修改源码的方式进行遍历。类方法的计算属性名参与遍历,方法体仍独立求值。转换包装末尾表达式,求值器解包并等待其值。无需转换的源码使用原生编译;不含 `await` 的提交保留原生语法诊断。语法错误保留解析器消息、可用的源码位置与光标,不包含编译器或转换器的调用帧。动态 `import()` 表达式保持原生形式,使用编译该 Script 时的 `importModuleDynamically` 选项。两个私有进程 bundle 都包含 Acorn、acorn-walk 和 birpc;源码执行导入已安装的包。
|
|
143
170
|
|
|
144
171
|
<a id="runner-import-handling"></a>
|
|
145
172
|
### Runner 导入处理
|
|
146
173
|
|
|
147
|
-
Runner 代码可以向 `runNodeMain()` 或 `runPersistentMain()` 传入 `ProgramImportHandler`。handler 属于子进程,与执行语法无关;它不是序列化的 Host 绑定或插件配置字段。VM Script 接受同步或异步决策;AsyncFunction 和 Node REPL 要求同步决策,返回 Promise 时会被拒绝。`node-script` 和 embedded 启动方式启用 `--experimental-vm-modules`;独立启动的 runner 在拦截 VM Script 导入时需要该标志。AsyncFunction 和 REPL 导入拦截不需要 VM 启动标志。
|
|
174
|
+
Runner 代码可以向 `runNodeMain()` 或 `runPersistentMain()` 传入 `ProgramImportHandler`。handler 属于子进程,与执行语法无关;它不是序列化的 Host 绑定或插件配置字段。scoped REPL 程序的动态导入使用 VM Script 的处理方式。VM Script 接受同步或异步决策;AsyncFunction 和 Node REPL 要求同步决策,返回 Promise 时会被拒绝。`node-script` 和 embedded 启动方式启用 `--experimental-vm-modules`;独立启动的 runner 在拦截 VM Script 和 scoped REPL 导入时需要该标志。AsyncFunction 和 Node REPL 导入拦截不需要 VM 启动标志。
|
|
148
175
|
|
|
149
176
|
handler 接收程序的动态导入;在 VM Script 中,还接收 VM 加载的 ESM 依赖中的静态与动态导入。每个请求携带模块标识符、导入属性和实际导入文件的绝对文件名。即使 cwd 改变,保存的函数仍保留该文件名。可返回的决策包括:
|
|
150
177
|
|
|
@@ -168,13 +195,15 @@ AsyncFunction 和 Node REPL 共用同步 `registerHooks` 和以 symbol 为键的
|
|
|
168
195
|
| [`src/execution.ts`](src/execution.ts) | 模式选择、请求解析及临时或保留进程的所有权 |
|
|
169
196
|
| [`src/worker.ts`](src/worker.ts) | 共用的进程启动、执行截止与绑定分派;`interruptEvaluation()` 请求协作中断,`terminate()` 终止进程 |
|
|
170
197
|
| [`src/persistent-process.ts`](src/persistent-process.ts) | 默认使用 REPL 的已安装入口,委托共用子进程循环 |
|
|
171
|
-
| [`src/evaluators/index.ts`](src/evaluators/index.ts) |
|
|
198
|
+
| [`src/evaluators/index.ts`](src/evaluators/index.ts) | 四种求值器的统一选择入口 |
|
|
172
199
|
| [`src/imports/vm-modules.ts`](src/imports/vm-modules.ts) | Script 导入决策、递归 ESM 链接与原生加载委托 |
|
|
173
200
|
| [`src/imports/module-hooks.ts`](src/imports/module-hooks.ts) | AsyncFunction 和 REPL hook、求值器归属与导出桥接对象 |
|
|
174
201
|
| [`src/evaluators/async-function.ts`](src/evaluators/async-function.ts) | AsyncFunction:严格模式异步函数体 |
|
|
175
202
|
| [`src/evaluators/repl.ts`](src/evaluators/repl.ts) | Node REPL:交互式声明与保留的 context |
|
|
176
203
|
| [`src/evaluators/vm-script.ts`](src/evaluators/vm-script.ts) | VM Script:Node 全局变量、声明与 Promise 完成值 |
|
|
177
204
|
| [`src/evaluators/vm-script-await.ts`](src/evaluators/vm-script-await.ts) | VM Script 的顶层 await 转换与声明保留 |
|
|
205
|
+
| [`src/evaluators/scoped-repl-evaluator.ts`](src/evaluators/scoped-repl-evaluator.ts) | scoped REPL 求值器:执行环境选项、模块全局变量与 import、完成值和 REPL 式异步失败处理 |
|
|
206
|
+
| [`src/evaluators/scoped-repl.ts`](src/evaluators/scoped-repl.ts) | scoped REPL 作用域链:程序之间拷贝绑定、声明扫描、源码生成与 Script 编译 |
|
|
178
207
|
| [`src/output-stream.ts`](src/output-stream.ts) | 有界流捕获与进程输出排空 |
|
|
179
208
|
| [`src/launch.ts`](src/launch.ts) | 可执行文件/bootstrap 参数与执行世界资源映射 |
|
|
180
209
|
| [`src/process.ts`](src/process.ts) | 共用的子进程握手、求值器生命周期与绑定 RPC |
|
|
@@ -218,15 +247,18 @@ AsyncFunction 和 Node REPL 共用同步 `registerHooks` 和以 symbol 为键的
|
|
|
218
247
|
- **约束继承所选后端的限制**——完整与部分强制能力分开报告;沙箱策略与受管进程约束是不同保证。
|
|
219
248
|
- **堆上限不是进程树内存限制**——原生分配与后代进程内存不属于 V8 老生代上限。不提供进程树 CPU 计量器。
|
|
220
249
|
- **清理继承子进程的可观测范围**——使用 fallback 的平台上,逃逸的后代可能仍在受管范围之外;参见子进程提供方声明的限制。
|
|
221
|
-
-
|
|
250
|
+
- **`per-call` 执行是一次性的**:保留状态需要使用默认的 `persistent-in-memory` 模式,或在 Script 模式下启用 `scriptPersistence: true`;所有模式都不提供 yield/wait API。
|
|
222
251
|
- **await 转换放宽声明语义**——转换后程序的顶层 `let`、`const` 和 `class` 绑定可修改,且在执行前初始化为 `undefined`,不再具有原生暂时性死区。执行到函数声明时才会为其设置保留的全局变量;没有初始化器的 `var` 声明会将其绑定重置为 `undefined`。直接 eval 中的声明仅在本次求值内有效。不接受顶层 `using` 声明;可释放绑定需放在块内。运行时堆栈位置指向转换后的源码。无需转换即可编译的脚本保持原生语义。
|
|
223
252
|
- **原生词法初始化失败可能占用名称**——顶层 `let`、`const` 或 `class` 的初始化器在完成绑定初始化前抛错时,该名称会在保留的 Script context 中持续处于未初始化状态。读取、赋值和重新声明都会失败;应使用新名称,或释放并重新创建环境。
|
|
253
|
+
- **scoped REPL 在调用开始时拷贝值**——省略 `replScoped` 或设为 `true` 时,之前的代码之后再赋的值,后面的调用看不到;`let`、`const` 或 `class` 重新声明的初始化表达式读不到同名旧值;`var` 重新声明从旧值开始,所以 `var count = count + 1` 在旧值上加 1,之前是同名的 `let` 或 `const` 时也是这样。之后的调用换了目录,相对的 `import()` 仍按这个环境第一次的工作目录解析;读写文件的相对路径跟随当前目录。`codeGeneration` 限制只拒绝程序环境自己的 `eval`、`Function` 和 WebAssembly 编译,不构成隔离:复制进程序环境的主环境函数,例如 `setTimeout.constructor`,仍能编译代码。最后一条表达式所在行,插入完成值之后的列号右移 17;以 `#!` 开头或任何位置含 `__$binding_` 的程序会被拒绝;包含此前缀的 binding-global 和 error-class 名称会在启动进程前失败;存活的函数会留住它那次调用拷贝进来的所有值。[scoped REPL 决策](../../../.agents/notes/implemented/architecture/2026-11-09-retained-ptc-scoped-repl.zh.md)列出完整行为。
|
|
224
254
|
- **Script 值可能跨 realm**——绑定结果、绑定拒绝类和导入模块可能使用 Script context 之外的构造器。这些值的 `instanceof Array` 或 `instanceof Error` 可能为 false;应使用 `Array.isArray` 和声明的绑定错误类。
|
|
225
255
|
- **内存保留环境为每个存活所有者保留一个进程**——空闲所有者保留进程及堆内存,直到显式释放、所有者销毁或执行失败。并行创建多个所有者会保留多个进程;空闲过期机制留待后续处理。
|
|
226
256
|
- **输出上限拒绝超量内容,而不保留每个字节**——溢出只能保存本提供方交付的有界结果。
|
|
257
|
+
- **格式化先分配内存再核算输出**——完整格式化对象和 TypedArray 所需的内存可能远大于保留的输出。输出预算不限制这些临时分配;耗尽配置的堆上限可能以 `worker-exit` 结束执行。
|
|
258
|
+
- **工具结果展示保留额外数据**——保留原工具结果时,也会在同一堆预算内保留其初始 JSON 快照和渲染文本;直接 `inspect` 会比较完整数据。
|
|
227
259
|
- **绑定在传输接纳时受限**——控制限制不约束 Host 绑定生成结果期间分配的内存。
|
|
228
260
|
- **预装 bootstrap 需要兼容的协议版本**——就绪握手会在派发代码前拒绝缺失或不匹配的版本。请将 `launch.bootstrapPath` 与宿主一同升级;运行时不会安装远端 bootstrap 更新。
|
|
229
|
-
-
|
|
261
|
+
- **图片引用随进程保留**——每张已获取图片的宿主元数据保留到进程终止或所有者释放,包括程序尚未展示的图片。保留环境中的长截图循环会累积这些引用。
|
|
230
262
|
|
|
231
263
|
<a id="dev-note"></a>
|
|
232
264
|
### 开发备注
|
package/lib/configuration.js
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
import { assertNever } from "@deepseek-ai/dsh-util-values";
|
|
2
2
|
//#region lib/types/configuration.js
|
|
3
|
+
/** `replScoped` written for retained function bodies and REPL statements; the Node provider also uses it when `replScoped` is omitted. */
|
|
4
|
+
const SCOPED_REPL_BY_DEFAULT = true;
|
|
3
5
|
/**
|
|
4
|
-
* Select retained Node execution while preserving Script syntax.
|
|
5
|
-
* @param programFormat - Effective syntax; omission
|
|
6
|
-
* @returns
|
|
6
|
+
* Select retained Node execution while preserving Script and scoped REPL syntax.
|
|
7
|
+
* @param programFormat - Effective syntax; omission selects function bodies.
|
|
8
|
+
* @returns All three settings to merge into the profile atomically, replacing stale values; function bodies and REPL statements
|
|
9
|
+
* switch to `persistent-in-memory` with `SCOPED_REPL_BY_DEFAULT`, which is also the default when `replScoped` is omitted.
|
|
7
10
|
*/
|
|
8
11
|
function resolvePersistentExecution(programFormat = "function-body") {
|
|
9
12
|
switch (programFormat) {
|
|
10
13
|
case "script": return {
|
|
11
14
|
executionMode: "vm-script",
|
|
12
|
-
scriptPersistence: true
|
|
15
|
+
scriptPersistence: true,
|
|
16
|
+
replScoped: false
|
|
13
17
|
};
|
|
14
18
|
case "function-body":
|
|
15
19
|
case "repl": return {
|
|
16
20
|
executionMode: "persistent-in-memory",
|
|
17
|
-
scriptPersistence: false
|
|
21
|
+
scriptPersistence: false,
|
|
22
|
+
replScoped: SCOPED_REPL_BY_DEFAULT
|
|
23
|
+
};
|
|
24
|
+
case "scoped-repl": return {
|
|
25
|
+
executionMode: "persistent-in-memory",
|
|
26
|
+
scriptPersistence: false,
|
|
27
|
+
replScoped: true
|
|
18
28
|
};
|
|
19
29
|
/* v8 ignore next -- The runtime supplies the closed, typed program-format union. */
|
|
20
30
|
default: return assertNever(programFormat);
|