@deepseek-ai/dsh-ptc-runtime-node 0.1.6-alpha.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/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +155 -0
- package/README.zh.md +155 -0
- package/lib/index.js +1178 -0
- package/lib/process.js +1136 -0
- package/lib/types/bindings.d.ts +8 -0
- package/lib/types/bootstrap.d.ts +143 -0
- package/lib/types/channel.d.ts +32 -0
- package/lib/types/environment.d.ts +4 -0
- package/lib/types/index.d.ts +55 -0
- package/lib/types/json-wire.d.ts +46 -0
- package/lib/types/launch.d.ts +17 -0
- package/lib/types/output-json.d.ts +26 -0
- package/lib/types/output-ledger.d.ts +18 -0
- package/lib/types/output-stream.d.ts +10 -0
- package/lib/types/process-entry.d.ts +2 -0
- package/lib/types/process.d.ts +19 -0
- package/lib/types/protocol.d.ts +75 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
|
2
|
+
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
|
+
# after editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm run verify-translation-pairing --write packages/ptc-runtime/ptc-runtime-node/README.md
|
|
5
|
+
README.md: f8f7b5535ba8ed1594b898d410df04e24f5dc8ef
|
|
6
|
+
README.zh.md: dd4e33e70f05ae3917f128e33bf26af5d1a915c4
|
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Run TypeScript programs in fresh Node processes with the session filesystem sandbox, managed cleanup, and configurable execution and output limits."
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @deepseek-ai/dsh-ptc-runtime-node
|
|
7
|
+
|
|
8
|
+
English | [中文](README.zh.md)
|
|
9
|
+
|
|
10
|
+
## Summary
|
|
11
|
+
|
|
12
|
+
Execute model-written TypeScript under the same platform sandbox policy as Bash, with host-provided functions available as async bindings. Each call starts a fresh Node process and returns captured logs, an exact JSON value, or a structured failure. Direct Node APIs remain available within the selected restrictions. Elapsed deadlines, output bounds and a V8 heap limit constrain execution; cancellation and completion terminate the managed process range. A requested restricted mode fails when its sandbox backend is unavailable.
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Use this package](#use-this-package)
|
|
17
|
+
- [Understand the implementation](#understand-the-implementation)
|
|
18
|
+
- [Further Exploration](#further-exploration)
|
|
19
|
+
- [Model Experience](#model-experience)
|
|
20
|
+
- [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
|
|
21
|
+
- [Dev Note](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## Use this package
|
|
27
|
+
|
|
28
|
+
Mount this provider in a composition that supplies `fs`, `subprocess`, `sandbox` and `sandboxPolicy`. PTC mode in `dsh-tools` supplies the calling Session's directory and standing policy; direct runtime consumers resolve those options before execution.
|
|
29
|
+
|
|
30
|
+
### Configuration
|
|
31
|
+
|
|
32
|
+
Configure the provider row after its required services are available:
|
|
33
|
+
|
|
34
|
+
```yaml
|
|
35
|
+
- name: '@deepseek-ai/dsh-ptc-runtime-node'
|
|
36
|
+
config:
|
|
37
|
+
timeoutMs: 120000
|
|
38
|
+
maxTimeoutMs: 600000
|
|
39
|
+
maxOutputBytes: 67108864
|
|
40
|
+
maxOldGenerationSizeMb: 512
|
|
41
|
+
maxMessageBytes: 134217728
|
|
42
|
+
maxPendingCalls: 128
|
|
43
|
+
graceMs: 3000
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Field | Default | Meaning |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| `timeoutMs` | `120,000` | Default elapsed execution deadline, including nested tool and approval waits |
|
|
49
|
+
| `maxTimeoutMs` | `600,000` | Elapsed deadline ceiling applied by the resolver |
|
|
50
|
+
| `maxOutputBytes` | `67,108,864` | Combined serialized logs and completion or diagnostic budget |
|
|
51
|
+
| `maxOldGenerationSizeMb` | `512` | V8 old-generation heap limit in MiB |
|
|
52
|
+
| `maxMessageBytes` | `134,217,728` | Limit for a control frame, outstanding argument bytes and queued control writes |
|
|
53
|
+
| `maxPendingCalls` | `128` | Maximum simultaneous host binding calls |
|
|
54
|
+
| `graceMs` | `3,000` | Managed termination and output-drain grace |
|
|
55
|
+
| `nodeExecutable` | Current Node executable | Executable resolved in the subprocess execution world |
|
|
56
|
+
| `bootstrapPath` | Package bootstrap | Optional absolute path to a preinstalled built bootstrap in that world |
|
|
57
|
+
|
|
58
|
+
The [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-ptc-runtime-node) defines accepted config fields. `resolve(request)` supplies cwd, the numeric or null deadline choice and the execution policy; `run(spec)` accepts those resolved inputs and does not fill missing values.
|
|
59
|
+
|
|
60
|
+
### Execution and results
|
|
61
|
+
|
|
62
|
+
Programs are async function bodies: top-level `await` and `return` work, and only erasable TypeScript is accepted. A successful call returns its lossless-JSON value as `result.value` and captured text as `result.logs`. `result.sandbox` reports the selected mode, observed denial and the backend's full or partial enforcement independently of the program outcome.
|
|
63
|
+
|
|
64
|
+
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.
|
|
65
|
+
|
|
66
|
+
### Deadlines and cancellation
|
|
67
|
+
|
|
68
|
+
The PTC consumer exposes per-call timeout and approved sandbox choices as described in [dsh-tools](../../core/tools/README.md#ptc-mode). The runtime's readonly `timeout` descriptor reports its effective default and maximum to that consumer. Its `executionInstructions` describes fresh Node state, direct Node APIs, the empty program environment and file policy in the model-visible schema.
|
|
69
|
+
|
|
70
|
+
Omitting `timeoutMs` uses the configured elapsed default; numeric requests are validated and capped. Service callers can explicitly pass `timeoutMs: null` to omit the elapsed timer, as the workflow adapter does; `run_code` continues to accept only positive numeric overrides. An enabled deadline covers runtime setup and execution, including time awaiting nested tools or approval. It is not a CPU meter. Timeout or cancellation stops a synchronous loop through the host's managed process owner; successful completion also cleans that managed range. The timer stops when an outcome is selected, before cleanup, so the returned call can take longer than its execution deadline while cleanup settles.
|
|
71
|
+
|
|
72
|
+
### Failures
|
|
73
|
+
|
|
74
|
+
Program parse errors and thrown exceptions are `exception`; deadline expiry is `timeout`; cancellation is `abort`; malformed or excessive control traffic is `protocol`; unavailable confinement is `sandbox-unavailable`; early process exit or failed managed cleanup is `worker-exit`. The substrate-independent failure name remains `worker-exit` for process providers. Lossy completions are `invalid-output`, and an oversized outer result is `output-limit`, retaining the fitting log prefix. Invalid or unsupported options and calls after disposal reject as caller misuse.
|
|
75
|
+
|
|
76
|
+
-----
|
|
77
|
+
|
|
78
|
+
<a id="understand-the-implementation"></a>
|
|
79
|
+
## Understand the implementation
|
|
80
|
+
|
|
81
|
+
<details>
|
|
82
|
+
<summary>Implementation internals — click to expand</summary>
|
|
83
|
+
|
|
84
|
+
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.
|
|
85
|
+
|
|
86
|
+
### Launch and control
|
|
87
|
+
|
|
88
|
+
The host strips erasable types, resolves the executable and bootstrap in the configured execution world, awaits argv confinement through `ctx.sandbox`, then spawns through `ctx.subprocess`. Cancellation is checked again after confinement, so a provider returning after cancellation cannot start the program. After adopting the inherited control channel, the child retains only executable-search, Windows system, and temporary paths in its OS environment and replaces the program-visible `process.env` with an empty dictionary. Windows ACL setup receives the parent's distinct `TEMP` and `TMP` values for shared grant locks, then replaces both with its private directory before starting the program. These native paths keep nested process creation and native temporary-file APIs functional. The heap limit uses Node argv or a provider-created `NODE_OPTIONS` value for packaged executables; ambient loader and inspector flags are discarded.
|
|
89
|
+
|
|
90
|
+
Length-framed JSON travels separately from stdout/stderr. The host bounds frames and queued writes, validates call identity and declared binding names before dispatch, and refuses invalid traffic. The child flushes its terminal frame and keeps the control channel open until the host closes it. After submitting that frame, it ignores later binding replies and sends no further program control messages. Output capture meters serialized logs plus the completion or diagnostic; fixed result-envelope fields and sandbox metadata are outside that ledger.
|
|
91
|
+
|
|
92
|
+
### Source and built bootstraps
|
|
93
|
+
|
|
94
|
+
Source execution loads an erasable-only bootstrap closure without relying on sibling built exports. Built execution uses the packaged `process.js` entry. An execution world that cannot map the host bootstrap requires a preinstalled compatible `bootstrapPath`; a host path is never assumed to name the same remote file.
|
|
95
|
+
|
|
96
|
+
### Source map
|
|
97
|
+
|
|
98
|
+
| File | Role |
|
|
99
|
+
|---|---|
|
|
100
|
+
| [`src/index.ts`](src/index.ts) | Configuration, resolution, policy, bindings and managed execution |
|
|
101
|
+
| [`src/launch.ts`](src/launch.ts) | Executable/bootstrap arguments and execution-world asset mapping |
|
|
102
|
+
| [`src/process.ts`](src/process.ts) | Child handshake, environment clearing and program lifecycle |
|
|
103
|
+
| [`src/bootstrap.ts`](src/bootstrap.ts) | Program evaluation, binding proxies and output capture |
|
|
104
|
+
| [`src/channel.ts`](src/channel.ts) | Framing, bounded writes and protocol failures |
|
|
105
|
+
| [`src/output-ledger.ts`](src/output-ledger.ts) | Host accounting for the outer result |
|
|
106
|
+
| — | No runtime invariant companion is published; framing and process cleanup are enforced across the process boundary rather than through independent same-process observations. |
|
|
107
|
+
|
|
108
|
+
</details>
|
|
109
|
+
|
|
110
|
+
-----
|
|
111
|
+
|
|
112
|
+
<a id="further-exploration"></a>
|
|
113
|
+
## Further Exploration
|
|
114
|
+
|
|
115
|
+
Read the service contract before using the provider directly; the decisions explain policy and consumer ownership.
|
|
116
|
+
|
|
117
|
+
- [PTC runtime service](../ptc-runtime/README.md) — requests, resolved specs and results.
|
|
118
|
+
- [Sandboxed Node decision](../../../.agents/notes/implemented/architecture/2026-09-11-sandboxed-node-ptc-runtime.md) — security, lifecycle and timeout tradeoffs.
|
|
119
|
+
- [PTC foundation](../../../.agents/notes/implemented/feature/2026-06-15-ptc.md) — registry presentation and nested tool dispatch.
|
|
120
|
+
- [Subprocess provider](../../subprocess/subprocess-local/README.md) — managed process ranges and platform limitations.
|
|
121
|
+
|
|
122
|
+
-----
|
|
123
|
+
|
|
124
|
+
<a id="model-experience"></a>
|
|
125
|
+
## Model Experience
|
|
126
|
+
|
|
127
|
+
Indirectly, through PTC mode in `dsh-tools` and `dsh-workflow-ptc`, which present program outcomes through their own tool results. Intermediate binding traffic stays outside model history; the outer result follows the ordinary tool spill policy.
|
|
128
|
+
|
|
129
|
+
#### KV Cache effect
|
|
130
|
+
|
|
131
|
+
No direct invalidation; the named consumer owns any request-prefix changes.
|
|
132
|
+
|
|
133
|
+
## Known Limitations and Deferred Work
|
|
134
|
+
|
|
135
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
136
|
+
|
|
137
|
+
These limits qualify the execution guarantees and retained output.
|
|
138
|
+
|
|
139
|
+
- **Confinement inherits the selected backend's limits** — full and partial enforcement are reported separately; sandbox policy and managed-process containment are distinct guarantees.
|
|
140
|
+
- **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.
|
|
141
|
+
- **Cleanup inherits subprocess observability** — escaped descendants on a fallback platform may remain outside the managed range; see the subprocess provider's stated limits.
|
|
142
|
+
- **Execution is one-shot** — no yield/wait API, live result stream or retained program state exists between calls.
|
|
143
|
+
- **Output caps reject rather than retain every byte** — spill can preserve only the bounded result delivered by this provider.
|
|
144
|
+
- **Bindings are bounded at transport admission** — control limits do not bound the memory a host binding allocates while producing its result.
|
|
145
|
+
- **The console shim has five methods** — `log`, `info`, `warn`, `error` and `debug`.
|
|
146
|
+
|
|
147
|
+
<a id="dev-note"></a>
|
|
148
|
+
### Dev Note
|
|
149
|
+
|
|
150
|
+
<details>
|
|
151
|
+
<summary>Working context for maintainers — click to expand</summary>
|
|
152
|
+
|
|
153
|
+
The [timeout discussion](../../../.agents/notes/implemented/architecture/2026-09-11-sandboxed-node-ptc-runtime.md#deferred-timeout-design) records open choices about yielding, total lifetime, approval wait accounting and process-tree CPU/RSS limits. Those choices do not alter numeric deadline defaults or the explicit no-deadline service option.
|
|
154
|
+
|
|
155
|
+
</details>
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "在全新 Node 进程中运行 TypeScript 程序,使用会话文件系统沙箱、受管清理以及可配置的执行与输出限制。"
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @deepseek-ai/dsh-ptc-runtime-node
|
|
7
|
+
|
|
8
|
+
[English](README.md) | 中文
|
|
9
|
+
|
|
10
|
+
## 概述
|
|
11
|
+
|
|
12
|
+
在与 Bash 相同的平台沙箱策略下执行模型编写的 TypeScript,并通过异步绑定调用 Host 提供的函数。每次调用启动一个全新的 Node 进程,返回捕获日志、精确 JSON 值或结构化失败。直接 Node API 在所选限制内仍可使用。经过时间截止、输出上限和 V8 堆限制约束执行;取消和完成都会终止受管进程范围。请求受限模式但沙箱后端不可用时,执行失败。
|
|
13
|
+
|
|
14
|
+
## 目录
|
|
15
|
+
|
|
16
|
+
- [使用本包](#use-this-package)
|
|
17
|
+
- [理解实现](#understand-the-implementation)
|
|
18
|
+
- [进一步探索](#further-exploration)
|
|
19
|
+
- [模型体验](#model-experience)
|
|
20
|
+
- [已知限制与延后工作](#known-limitations-and-deferred-work)
|
|
21
|
+
- [开发备注](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## 使用本包
|
|
27
|
+
|
|
28
|
+
在提供 `fs`、`subprocess`、`sandbox` 与 `sandboxPolicy` 的组合中挂载本提供方。`dsh-tools` 的 PTC 模式传入调用 Session 的目录和常设策略;直接运行时消费方在执行前解析这些选项。
|
|
29
|
+
|
|
30
|
+
### 配置
|
|
31
|
+
|
|
32
|
+
在所需服务可用后,配置提供方条目:
|
|
33
|
+
|
|
34
|
+
```yaml
|
|
35
|
+
- name: '@deepseek-ai/dsh-ptc-runtime-node'
|
|
36
|
+
config:
|
|
37
|
+
timeoutMs: 120000
|
|
38
|
+
maxTimeoutMs: 600000
|
|
39
|
+
maxOutputBytes: 67108864
|
|
40
|
+
maxOldGenerationSizeMb: 512
|
|
41
|
+
maxMessageBytes: 134217728
|
|
42
|
+
maxPendingCalls: 128
|
|
43
|
+
graceMs: 3000
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| 字段 | 默认值 | 含义 |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| `timeoutMs` | `120,000` | 默认经过时间截止,包括嵌套工具与审批等待 |
|
|
49
|
+
| `maxTimeoutMs` | `600,000` | 解析器应用的经过时间截止上限 |
|
|
50
|
+
| `maxOutputBytes` | `67,108,864` | 序列化日志与完成值或诊断的合计预算 |
|
|
51
|
+
| `maxOldGenerationSizeMb` | `512` | V8 老生代堆上限,单位 MiB |
|
|
52
|
+
| `maxMessageBytes` | `134,217,728` | 控制帧、未完成参数字节和排队控制写入的上限 |
|
|
53
|
+
| `maxPendingCalls` | `128` | 同时进行的 Host 绑定调用数量上限 |
|
|
54
|
+
| `graceMs` | `3,000` | 受管终止与输出排空宽限时间 |
|
|
55
|
+
| `nodeExecutable` | 当前 Node 可执行文件 | 在子进程执行世界中解析的可执行文件 |
|
|
56
|
+
| `bootstrapPath` | 包内 bootstrap | 该执行世界中预先安装的构建后 bootstrap 的可选绝对路径 |
|
|
57
|
+
|
|
58
|
+
[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-ptc-runtime-node)定义可接受的配置字段。`resolve(request)` 补全 cwd、数值或 null 截止选择与执行策略;`run(spec)` 接受这些已解析输入,不补缺省值。
|
|
59
|
+
|
|
60
|
+
### 执行与结果
|
|
61
|
+
|
|
62
|
+
程序是异步函数体:支持顶层 `await` 与 `return`,且只接受可擦除 TypeScript。成功调用以 `result.value` 返回无损 JSON 值,以 `result.logs` 返回捕获文本。`result.sandbox` 独立于程序结果报告所选模式、观察到的拒绝,以及后端完整或部分的强制能力。
|
|
63
|
+
|
|
64
|
+
直接文件系统、网络与子进程操作仍是 Node 操作,受所选 OS 沙箱约束。嵌套 Host 绑定通过控制通道调用;PTC 工具调用保留注册表的可见性、排序、日志和审批规则。运行程序不会改变 Session 的常设策略,也不会在拒绝后自动重放程序。
|
|
65
|
+
|
|
66
|
+
### 截止时间与取消
|
|
67
|
+
|
|
68
|
+
PTC 消费方按 [dsh-tools](../../core/tools/README.zh.md#ptc-mode) 的说明公开逐次超时与经审批的沙箱选择。运行时只读 `timeout` 描述符向该消费方报告有效默认值与上限。 其 `executionInstructions` 在面向模型的 schema 中说明全新 Node 状态、直接 Node API、空程序环境和文件策略。
|
|
69
|
+
|
|
70
|
+
省略 `timeoutMs` 使用配置的经过时间默认值;数值请求经过验证并封顶。服务调用方可以显式传入 `timeoutMs: null` 来省略经过时间定时器,工作流适配器即如此;`run_code` 仍只接受正数覆盖值。启用的截止覆盖运行时准备和执行,包括等待嵌套工具或审批的时间。它不是 CPU 计量器。超时或取消通过 Host 的受管进程所有者停止同步循环;成功完成也会清理该受管范围。选择结果后、清理前停止计时器,因此调用可能要在执行截止之后等待清理结算才返回。
|
|
71
|
+
|
|
72
|
+
### 失败
|
|
73
|
+
|
|
74
|
+
程序解析错误与抛出异常为 `exception`;截止到期为 `timeout`;取消为 `abort`;畸形或超量控制通信为 `protocol`;约束不可用为 `sandbox-unavailable`;进程提前退出或受管清理失败为 `worker-exit`。进程提供方保留与执行基底无关的失败名 `worker-exit`。有损完成值为 `invalid-output`,外层结果超限为 `output-limit`,并保留能容纳的日志前缀。无效或不支持的选项,以及资源释放后的调用,以调用方误用拒绝。
|
|
75
|
+
|
|
76
|
+
-----
|
|
77
|
+
|
|
78
|
+
<a id="understand-the-implementation"></a>
|
|
79
|
+
## 理解实现
|
|
80
|
+
|
|
81
|
+
<details>
|
|
82
|
+
<summary>实现内部——点击展开</summary>
|
|
83
|
+
|
|
84
|
+
Host 负责策略、截止时间、绑定查找和进程清理。子进程负责程序求值与绑定代理;即使使用预期的控制描述符,模型编写的代码仍是不可信对端。
|
|
85
|
+
|
|
86
|
+
### 启动与控制
|
|
87
|
+
|
|
88
|
+
Host 擦除可擦除类型,在配置的执行世界中解析可执行文件与 bootstrap,通过 `ctx.sandbox` 等待 argv 限制准备完成,再通过 `ctx.subprocess` 启动。限制准备完成后会再次检查取消状态,因此提供方在取消后返回也无法启动程序。接管继承的控制通道后,子进程在 OS 环境中只保留可执行文件搜索路径、Windows 系统路径和临时路径,并将程序可见的 `process.env` 替换为空字典。Windows ACL 初始化接收父进程各自的 `TEMP` 和 `TMP` 值以使用共享授权锁,然后在启动程序前将二者替换为私有目录。这些原生路径使嵌套进程创建和原生临时文件 API 仍可正常工作。堆上限通过 Node argv 或为打包可执行文件由提供方构造的 `NODE_OPTIONS` 值传递;环境中的加载器和调试器标志会被丢弃。
|
|
89
|
+
|
|
90
|
+
带长度分帧的 JSON 与 stdout/stderr 分开传输。Host 限制帧与排队写入,在分派前验证调用身份和已声明的绑定名,并拒绝无效通信。子进程刷新终态帧后仍保持控制通道打开,直到 Host 关闭通道。提交终态帧后,子进程忽略后续绑定回复,不再发送程序控制消息。输出捕获计量序列化日志加完成值或诊断;固定结果信封字段与沙箱元数据不计入该账本。
|
|
91
|
+
|
|
92
|
+
### 源代码与构建后 bootstrap
|
|
93
|
+
|
|
94
|
+
源代码执行加载仅含可擦除语法的 bootstrap 依赖,不依赖同级包的构建后导出。构建后执行使用包内 `process.js` 入口。无法映射 Host bootstrap 的执行世界需要预先安装兼容的 `bootstrapPath`;不会假设 Host 路径对应同一个远程文件。
|
|
95
|
+
|
|
96
|
+
### 源码索引
|
|
97
|
+
|
|
98
|
+
| 文件 | 职责 |
|
|
99
|
+
|---|---|
|
|
100
|
+
| [`src/index.ts`](src/index.ts) | 配置、解析、策略、绑定与受管执行 |
|
|
101
|
+
| [`src/launch.ts`](src/launch.ts) | 可执行文件/bootstrap 参数与执行世界资源映射 |
|
|
102
|
+
| [`src/process.ts`](src/process.ts) | 子进程握手、环境清空与程序生命周期 |
|
|
103
|
+
| [`src/bootstrap.ts`](src/bootstrap.ts) | 程序求值、绑定代理与输出捕获 |
|
|
104
|
+
| [`src/channel.ts`](src/channel.ts) | 分帧、有界写入与协议失败 |
|
|
105
|
+
| [`src/output-ledger.ts`](src/output-ledger.ts) | Host 外层结果计量 |
|
|
106
|
+
| — | 不发布运行时不变式配套模块;分帧与进程清理跨进程边界强制执行,不依靠同进程中的独立观测。 |
|
|
107
|
+
|
|
108
|
+
</details>
|
|
109
|
+
|
|
110
|
+
-----
|
|
111
|
+
|
|
112
|
+
<a id="further-exploration"></a>
|
|
113
|
+
## 进一步探索
|
|
114
|
+
|
|
115
|
+
直接使用提供方前先读服务约定;决策记录解释策略与消费方职责。
|
|
116
|
+
|
|
117
|
+
- [PTC 运行时服务](../ptc-runtime/README.zh.md)——请求、已解析 spec 与结果。
|
|
118
|
+
- [沙箱 Node 决策](../../../.agents/notes/implemented/architecture/2026-09-11-sandboxed-node-ptc-runtime.zh.md)——安全、生命周期与 timeout 取舍。
|
|
119
|
+
- [PTC 基础](../../../.agents/notes/implemented/feature/2026-06-15-ptc.zh.md)——注册表呈现与嵌套工具分派。
|
|
120
|
+
- [子进程提供方](../../subprocess/subprocess-local/README.zh.md)——受管进程范围与平台限制。
|
|
121
|
+
|
|
122
|
+
-----
|
|
123
|
+
|
|
124
|
+
<a id="model-experience"></a>
|
|
125
|
+
## 模型体验
|
|
126
|
+
|
|
127
|
+
通过 `dsh-tools` 的 PTC 模式与 `dsh-workflow-ptc` 间接提供;它们通过各自的工具结果呈现程序结果。中间绑定通信不进入模型历史;外层结果遵循普通工具溢出策略。
|
|
128
|
+
|
|
129
|
+
#### KV Cache effect
|
|
130
|
+
|
|
131
|
+
不直接失效;具名消费方负责请求前缀的任何变更。
|
|
132
|
+
|
|
133
|
+
## 已知限制与延后工作
|
|
134
|
+
|
|
135
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
136
|
+
|
|
137
|
+
这些限制界定执行保证与保留的输出。
|
|
138
|
+
|
|
139
|
+
- **约束继承所选后端的限制**——完整与部分强制能力分开报告;沙箱策略与受管进程约束是不同保证。
|
|
140
|
+
- **堆上限不是进程树内存限制**——原生分配与后代进程内存不属于 V8 老生代上限。不提供进程树 CPU 计量器。
|
|
141
|
+
- **清理继承子进程的可观测范围**——使用 fallback 的平台上,逃逸的后代可能仍在受管范围之外;参见子进程提供方声明的限制。
|
|
142
|
+
- **执行是一次性的**——没有 yield/wait API、实时结果流或跨调用保留的程序状态。
|
|
143
|
+
- **输出上限拒绝超量内容,而不保留每个字节**——溢出只能保存本提供方交付的有界结果。
|
|
144
|
+
- **绑定在传输接纳时受限**——控制限制不约束 Host 绑定生成结果期间分配的内存。
|
|
145
|
+
- **console shim 有五个方法**——`log`、`info`、`warn`、`error` 与 `debug`。
|
|
146
|
+
|
|
147
|
+
<a id="dev-note"></a>
|
|
148
|
+
### 开发备注
|
|
149
|
+
|
|
150
|
+
<details>
|
|
151
|
+
<summary>维护者工作上下文——点击展开</summary>
|
|
152
|
+
|
|
153
|
+
[timeout 讨论](../../../.agents/notes/implemented/architecture/2026-09-11-sandboxed-node-ptc-runtime.zh.md#deferred-timeout-design)记录 yield、总生命周期、审批等待计时和进程树 CPU/RSS 上限的开放选择。这些选择不改变数值截止的默认值或显式的不设截止服务选项。
|
|
154
|
+
|
|
155
|
+
</details>
|