feat(ptc-runtime-node): default executionMode to persistent-in-memory with the scoped REPL

This commit is contained in:
imccyu committed 2026-11-20 01:58:55 +08:00
1 parent 0d36b3179e
commit c6b8146b51
27 files changed
+126 -56

No files matched your search

@@ -9,8 +9,8 @@
en: 66ac3d7ce7eb8e15
zh: abb9d41b71900bbf
/agent-note-sandboxed-node-execution-for-ptc/decision:
en: d6b9c22603a4f933
zh: f324b91830078d9a
en: 3dac0013b3577b16
zh: 066e9b55fc3f457e
/agent-note-sandboxed-node-execution-for-ptc/decision/resolved-inputs-and-policy:
en: e544f1a5b7f5b0ec
zh: 3195e0008313a5c6
@@ -18,8 +18,8 @@
en: a8897bae00f5f674
zh: 2c959353c5a885a4
/agent-note-sandboxed-node-execution-for-ptc/decision/resource-limits:
en: 3f1d8a30f6d48243
zh: faa7c01d7c959893
en: 9fc1a3c6e06ab156
zh: 7fcf818c3411eff4
/agent-note-sandboxed-node-execution-for-ptc/alternatives-considered:
en: 8ffcc2b32a2243d7
zh: 81d48d38947abc76
@@ -12,7 +12,7 @@ The [PTC foundation](../feature/2026-06-15-ptc.md) remains responsible for regis
## Decision
`dsh-ptc-runtime-node` in its default `per-call` mode runs each program in one fresh Node process. The host resolves execution choices, confines the launch through the same `ctx.sandbox` provider as Bash, and gives process lifetime to `ctx.subprocess`. The child evaluates erasable TypeScript with direct Node APIs, an empty model environment and host-provided asynchronous bindings. No worker or persistent kernel remains after a per-call execution.
`dsh-ptc-runtime-node` in its `per-call` mode runs each program in one fresh Node process. The host resolves execution choices, confines the launch through the same `ctx.sandbox` provider as Bash, and gives process lifetime to `ctx.subprocess`. The child evaluates erasable TypeScript with direct Node APIs, an empty model environment and host-provided asynchronous bindings. No worker or persistent kernel remains after a per-call execution.
The host preserves `ELECTRON_RUN_AS_NODE` for child startup; the bootstrap removes it from the native environment before evaluation, and model-visible `process.env` stays empty. Nested Electron launches require their own explicit Node-mode selection. Desktop uses Electron as its Node executable; removing this selector launches Electron's application path instead of the PTC bootstrap. Sandbox permission changes cannot repair that launch mismatch. The macOS Desktop regression uses real Electron to verify binding writes, direct workspace writes, and rejection of writes outside the workspace under restricted policy. It requires an installed Electron binary; ordinary runtime tests cover environment filtering without that dependency.
@@ -32,7 +32,7 @@ For temporary executions, program completion, timeout, cancellation and protocol
The default elapsed deadline is 120 seconds, capped at 600 seconds by default. Trusted service consumers may request `timeoutMs: null` to disable this timer; [workflow sandbox reuse](2026-09-13-workflow-ptc-sandbox-reuse.md) owns that caller-controlled lifetime. Omitted and numeric requests, including model-facing `run_code`, retain the numeric defaults and caps. An enabled deadline includes runtime setup and nested tool or approval waits. V8 old-generation memory, serialized outer output and control traffic have separate configured bounds. The heap limit excludes native allocations and descendant memory, and elapsed time is not a process-tree CPU budget.
The opt-in [in-memory execution mode](2026-09-23-best-effort-persistent-ptc.md) retains disposable memory under the same file policy; [retained-process permissions](2026-10-08-persistent-ptc-sandbox.md) govern policy changes and temporary escalation.
The default [in-memory execution mode](2026-09-23-best-effort-persistent-ptc.md) retains disposable memory under the same file policy; [retained-process permissions](2026-10-08-persistent-ptc-sandbox.md) govern policy changes and temporary escalation.
## Alternatives considered
@@ -12,7 +12,7 @@ Node worker 隔离 JavaScript 状态,但不应用调用 Session 的 OS 沙箱
## 决策
`dsh-ptc-runtime-node` 的默认 `per-call` 模式在一个全新 Node 进程中运行每个程序。Host 解析执行选择,通过与 Bash 相同的 `ctx.sandbox` 提供方约束启动,并将进程生命周期交给 `ctx.subprocess`。子进程以直接 Node API、空模型环境和 Host 提供的异步绑定求值可擦除 TypeScript。逐次执行结束后不保留 worker 或持久内核。
`dsh-ptc-runtime-node` 的 `per-call` 模式在一个全新 Node 进程中运行每个程序。Host 解析执行选择,通过与 Bash 相同的 `ctx.sandbox` 提供方约束启动,并将进程生命周期交给 `ctx.subprocess`。子进程以直接 Node API、空模型环境和 Host 提供的异步绑定求值可擦除 TypeScript。逐次执行结束后不保留 worker 或持久内核。
Host 在子进程启动时保留 `ELECTRON_RUN_AS_NODE`;bootstrap 在求值前将其从原生环境中删除,模型可见的 `process.env` 仍为空。嵌套启动 Electron 需要自行显式选择 Node 模式。桌面端使用 Electron 作为 Node 可执行文件;删除此选择变量会启动 Electron 应用路径,而不是 PTC bootstrap。更改沙箱权限无法修复这一启动模式不匹配。macOS 桌面端回归测试使用真实 Electron 验证绑定写入、直接工作区写入以及受限策略对工作区外写入的拒绝。该测试需要已安装的 Electron 二进制文件;普通运行时测试无需此依赖即可覆盖环境过滤。
@@ -32,7 +32,7 @@ Host 在子进程启动时保留 `ELECTRON_RUN_AS_NODE`;bootstrap 在求值前
默认经过时间截止为 120 秒,默认上限为 600 秒。可信服务消费方可以请求 `timeoutMs: null` 来禁用该定时器;[工作流沙箱复用](2026-09-13-workflow-ptc-sandbox-reuse.zh.md)负责这种由调用方控制的生命周期。省略 timeout 或使用数值的请求(包括面向模型的 `run_code`)保留数值默认值与上限。启用的截止包括运行时准备以及嵌套工具或审批等待。V8 老生代内存、序列化外层输出与控制通信具有独立配置的上限。堆限制不包含原生分配和后代内存,经过时间也不是进程树 CPU 预算。
显式启用的[内存保留执行模式](2026-09-23-best-effort-persistent-ptc.zh.md)在相同文件策略下保留可丢弃内存;[常驻进程权限](2026-10-08-persistent-ptc-sandbox.zh.md)负责策略切换和临时提权。
默认的[内存保留执行模式](2026-09-23-best-effort-persistent-ptc.zh.md)在相同文件策略下保留可丢弃内存;[常驻进程权限](2026-10-08-persistent-ptc-sandbox.zh.md)负责策略切换和临时提权。
## 考虑过的替代方案
@@ -9,8 +9,8 @@
en: e42db40b879fdbf4
zh: 6017da9c4da17835
/agent-note-node-ptc-execution-modes-and-in-memory-state/decision:
en: 13a72b9728d25394
zh: 1f44510fe93836dc
en: 2d5306e76dc8170a
zh: eab993b4d2f3acf0
/agent-note-node-ptc-execution-modes-and-in-memory-state/alternatives-considered:
en: 396157a9fc293198
zh: a061f05b4423e26f
@@ -10,7 +10,7 @@ Interactive automation retains application objects, imported modules and helper
## Decision
The existing `@deepseek-ai/dsh-ptc-runtime-node` plugin selects its execution mode through `executionMode`. The default `per-call` mode starts a fresh process under the configured file policy. Opt-in `persistent-in-memory` mode keeps a Node REPL process per explicit, object-identity state owner. Both modes provide the same `ctx.ptcRuntime` service. PTC uses the live Agent as owner and awaits release during its context disposal. Changing the configuration reloads the provider and releases its processes. The [sandboxed Node decision](2026-09-11-sandboxed-node-ptc-runtime.md) owns per-call confinement; the [PTC foundation](../feature/2026-06-15-ptc.md) owns tool dispatch and logged model requests.
The existing `@deepseek-ai/dsh-ptc-runtime-node` plugin selects its execution mode through `executionMode`. The `per-call` mode starts a fresh process under the configured file policy. The default `persistent-in-memory` mode keeps a Node REPL process per explicit, object-identity state owner. Both modes provide the same `ctx.ptcRuntime` service. PTC uses the live Agent as owner and awaits release during its context disposal. Changing the configuration reloads the provider and releases its processes. The [sandboxed Node decision](2026-09-11-sandboxed-node-ptc-runtime.md) owns per-call confinement; the [PTC foundation](../feature/2026-06-15-ptc.md) owns tool dispatch and logged model requests.
The `per-call` and `persistent-in-memory` names describe their fixed state-retention policies: one invocation or across invocations until the process or owner ends. The [Script evaluation decision](2026-10-20-ptc-script-evaluation-and-retention.md) extends these modes with independently configured syntax and retention. `durable` names the deferred ability to save and restore execution state across restarts. It is not an accepted configuration value: a future implementation must define its recovery point, recoverable values and external-resource handling before exposing that mode. The [retained-process permission decision](2026-10-08-persistent-ptc-sandbox.md) owns confinement, policy changes and temporary escalation.
@@ -10,7 +10,7 @@ Status: implemented
## 决策
现有 `@deepseek-ai/dsh-ptc-runtime-node` 插件通过 `executionMode` 选择执行模式。默认的 `per-call` 模式按配置的文件策略启动新进程。显式启用的 `persistent-in-memory` 模式为每个以对象身份标识的状态所有者保留一个 Node REPL 进程。两种模式都提供同一个 `ctx.ptcRuntime` 服务。PTC 使用存活的 Agent 作为所有者,在其上下文销毁时等待释放。修改配置会重载提供方并释放其进程。[Node 沙箱决策](2026-09-11-sandboxed-node-ptc-runtime.zh.md)负责逐次执行的文件约束,[PTC 基础决策](../feature/2026-06-15-ptc.zh.md)负责工具分派与模型请求日志。
现有 `@deepseek-ai/dsh-ptc-runtime-node` 插件通过 `executionMode` 选择执行模式。`per-call` 模式按配置的文件策略启动新进程。默认的 `persistent-in-memory` 模式为每个以对象身份标识的状态所有者保留一个 Node REPL 进程。两种模式都提供同一个 `ctx.ptcRuntime` 服务。PTC 使用存活的 Agent 作为所有者,在其上下文销毁时等待释放。修改配置会重载提供方并释放其进程。[Node 沙箱决策](2026-09-11-sandboxed-node-ptc-runtime.zh.md)负责逐次执行的文件约束,[PTC 基础决策](../feature/2026-06-15-ptc.zh.md)负责工具分派与模型请求日志。
`per-call` 和 `persistent-in-memory` 名称描述各自固定的状态保留策略:只保留一次调用,或跨调用保留至进程或所有者结束。[Script 求值决策](2026-10-20-ptc-script-evaluation-and-retention.zh.md)在这两种模式之外增加独立配置的语法与保留方式。`durable` 用于命名未来跨重启保存与恢复执行状态的能力。它不是可接受的配置值:实现必须先明确恢复点、可恢复的值以及外部资源的处理方式,才能公开这个模式。[常驻进程权限决策](2026-10-08-persistent-ptc-sandbox.zh.md)负责文件约束、权限切换与临时提权。
@@ -12,8 +12,8 @@
en: a9124b9053b16a12
zh: 7d4005cbca138015
/agent-note-cua-programs-outside-the-ptc-preset/alternatives-considered:
en: b5d8e00cbe4b53ae
zh: 4ef81611150a8d75
en: a549b92ccdf837df
zh: e012821576eb54e2
/agent-note-cua-programs-outside-the-ptc-preset/consequences:
en: 22f25d54373ba06b
zh: ee335578caaf1ab3
@@ -22,7 +22,7 @@ This partially supersedes the exclusion of a CUA program entry in [native CUA ob
**A CUA-specific evaluator** duplicates execution lifecycle policy. Reusing the PTC factory and runtime keeps cancellation, limits, sandboxing, and result handling with their existing owners.
**The profile's shared runtime** couples CUA state to unrelated PTC and workflow settings. Its default per-call mode cannot retain objects. A separate CUA runtime preserves the profile's chosen execution mode.
**The profile's shared runtime** couples CUA state to unrelated PTC and workflow settings. A per-call mode selected there cannot retain objects. A separate CUA runtime preserves the profile's chosen execution mode.
**Global registration of both tool forms** exposes a program runner inside PTC programs and exposes raw CUA calls to other presets. Selecting one form per Agent keeps each mode's intended tool list. Binding every session tool inside `cua_run_code` would duplicate ordinary direct calls and their declarations.
@@ -22,7 +22,7 @@ CUA 在隔离运行时首次接纳运行前,通过 `registerEnvironmentInitial
**CUA 专用求值器**会重复实现执行生命周期策略。复用 PTC 工厂和运行时,使取消、限制、沙箱和结果处理继续由现有实现负责。
**profile 的共享运行时**会使 CUA 状态依赖无关的 PTC 和工作流设置。其默认逐次调用模式无法保留对象。独立的 CUA 运行时保留 profile 选定的执行模式。
**profile 的共享运行时**会使 CUA 状态依赖无关的 PTC 和工作流设置。在那里选择的逐次调用模式无法保留对象。独立的 CUA 运行时保留 profile 选定的执行模式。
**全局注册两种工具形态**会在 PTC 程序中暴露另一个程序执行器,并向其他 preset 暴露原始 CUA 调用。按 Agent 选择一种形态,可以保留各模式预期的工具列表。在 `cua_run_code` 内绑定所有会话工具,会重复普通的直接调用及其声明。
+2 -2
View File
@@ -40,7 +40,7 @@ it('disables unsupported bundles, shows the Host restriction, and refuses direct
const runtimeId = () => [...scaffold.ctx.loader.entries()].find(entry => entry.options.id === 'ptc-runtime')?.fiber?.uid
const beforeRuntime = runtimeId()
expect(beforeRuntime).toBeTypeOf('number')
expect(scaffold.ctx.ptcRuntime.programFormat).toBe('function-body')
expect(scaffold.ctx.ptcRuntime.programFormat).toBe('scoped-repl')
const names = [name]
await page.locator('[data-plugin-panel]').getByRole('button', { name: '更多', exact: true }).click()
const cua = page.locator('[data-plugin-package="@deepseek-ai/dsh-cua-bundle"]')
@@ -58,6 +58,6 @@ it('disables unsupported bundles, shows the Host restriction, and refuses direct
}
expect(await readFile(manifest, 'utf8')).toBe(before)
expect(runtimeId()).toBe(beforeRuntime)
expect(scaffold.ctx.ptcRuntime.programFormat).toBe('function-body')
expect(scaffold.ctx.ptcRuntime.programFormat).toBe('scoped-repl')
expect(scaffold.ctx.get('computerUse')).toBeUndefined()
})
+1 -1
View File
@@ -3160,7 +3160,7 @@ export interface Config {
export interface Config {
/** Worker invocation in the subprocess world; omitted selects the local carrier. */
launch?: LaunchConfig
/** per-call uses fresh async function bodies; vm-script uses VM contexts; persistent-in-memory retains a REPL per owner. */
/** persistent-in-memory, the default, retains a REPL per owner; per-call uses fresh async function bodies; vm-script uses VM contexts. */
executionMode?: 'per-call' | 'persistent-in-memory' | 'vm-script'
/** Retain a Script process and context per stateOwner; only supported with executionMode: vm-script. */
scriptPersistence?: boolean
+1 -1
View File
@@ -3162,7 +3162,7 @@ export interface Config {
export interface Config {
/** Worker invocation in the subprocess world; omitted selects the local carrier. */
launch?: LaunchConfig
/** per-call uses fresh async function bodies; vm-script uses VM contexts; persistent-in-memory retains a REPL per owner. */
/** persistent-in-memory, the default, retains a REPL per owner; per-call uses fresh async function bodies; vm-script uses VM contexts. */
executionMode?: 'per-call' | 'persistent-in-memory' | 'vm-script'
/** Retain a Script process and context per stateOwner; only supported with executionMode: vm-script. */
scriptPersistence?: boolean
+2 -2
View File
@@ -72,8 +72,8 @@
en: 8c8643ef46fd075f
zh: 8c8643ef46fd075f
/tool-schema-catalog/deepseek-ai-dsh-tool-executor-ptc/run-code:
en: 93d8526bbc4936d2
zh: 963af83582d289c5
en: 839345c3b7a0414d
zh: 906c029c30394562
/tool-schema-catalog/deepseek-ai-dsh-plan-mode:
en: b500b530845e26a9
zh: b500b530845e26a9
+2 -2
View File
@@ -612,7 +612,7 @@ ask_user_question keeps the original blocking behavior by default; set `mode: ti
### `run_code`
Execute a TypeScript program against the available tools. Takes two required arguments: `code`, the BODY of an async function (erasable syntax only; top-level `await` and `return` work), and `description`, a short summary of what the program does. Call tools as `await tools.name(args)` per the declarations in the system prompt. Show selected text and images with inspect(...values). The program is the body of an async TypeScript function; only erasable syntax is accepted, with no enum or namespaces. Type annotations are advisory. Top-level await and return are supported. Use inspect(...values) to display output. Do not use console. Use the raw form of a template literal only for short text whose backslashes must stay exactly as written, such as a regular expression; write other text, in particular file contents and commands, as ordinary strings. Write file contents as an array of quoted strings, one line each, joined with newlines; never as one template literal. Each call runs in a fresh Node process. Node APIs are available through await import(...). Relative paths use the supplied working directory; process.env starts empty. Direct filesystem access follows this execution's sandbox policy. Each program starts in the Session's current directory. Running programs keep their initial directory. A sandbox escalation approves this complete program for one execution only. Nested tools retain their own policies and approvals. Request wider access only after evidence of a denial. Earlier effects may already have completed: inspect them before explicitly retrying. Programs are never replayed automatically.
Execute a TypeScript program against the available tools. Takes two required arguments: `code`, the program to execute, and `description`, a short summary of what the program does. Call tools as `await tools.name(args)` per the declarations in the system prompt. Show selected text and images with inspect(...values). The program contains TypeScript REPL statements; only erasable syntax is accepted, with no enum or namespaces. Type annotations are advisory. Top-level declarations and await are supported; top-level return is not supported. Use inspect(...values) to display output. Do not use console. Use the raw form of a template literal only for short text whose backslashes must stay exactly as written, such as a regular expression; write other text, in particular file contents and commands, as ordinary strings. Write file contents as an array of quoted strings, one line each, joined with newlines; never as one template literal. The program runs in strict mode: assigning an undeclared name throws, so use globalThis for intentional globals; eval and new Function are unavailable. Variables, functions, and imported modules remain in memory for this Agent across calls. Each call runs one program in its own top-level scope. Its top-level let, const, var, class, and function declarations, and the names it received from earlier programs, are copied into the top-level scope of later programs: later programs receive copies of these variables, not references to them, so an object they hold is still shared. In one program, either use a copied name or declare it again; do not declare a name and also use its copied value. Assigning to a copied name, even one declared with const, changes only this program's copy, which later programs receive. Do not declare var inside blocks; a block-level var changes which value later programs copy. Functions and still-running code from earlier programs keep the values they captured, and assignments they make later are not copied; keep shared mutable state in objects. If a program fails before a declaration of an existing name finishes, later programs keep that name's earlier value. Use await import(...) for modules; require and module are unavailable. Relative import specifiers resolve from the working directory of this environment's first program, while process.cwd() and relative file paths follow each program's working directory. Direct filesystem access follows the environment's launch-time sandbox policy; process.env starts empty. Timeout and cancellation results say whether retained variables were preserved or cleared. Restart, sandbox changes, or process failure clears them. Recreate missing variables and resources; conversation history does not restore state. Earlier mutations and tool effects are not rolled back. Approved sandbox escalations use a fresh environment and discard its variables afterward. Await tools and cleanup before the program ends; unfinished tools reject. After completion, timeout, or cancellation, new tool calls are rejected and captured output is discarded; background work may still change state. Await child-process completion before the program ends; raw output belongs to the active evaluation. Each program starts in the Session's current directory. Running programs keep their initial directory. A sandbox escalation approves this complete program for one execution only. Nested tools retain their own policies and approvals. Request wider access only after evidence of a denial. Earlier effects may already have completed: inspect them before explicitly retrying. Programs are never replayed automatically.
```json
{
@@ -620,7 +620,7 @@ Execute a TypeScript program against the available tools. Takes two required arg
"properties": {
"code": {
"type": "string",
"description": "The program: the body of an async TypeScript function."
"description": "The TypeScript program to execute, following this tool's execution instructions."
},
"description": {
"type": "string",
+2 -2
View File
@@ -616,7 +616,7 @@ ask_user_question 默认保持原有阻塞行为;设置 `mode: timed` 后才
### `run_code`
针对可用工具执行 TypeScript 程序。接受两个必填参数:`code`,异步函数的函数体(仅限可擦除语法,支持顶层 `await` 和 `return`);以及 `description`,简要说明程序做什么。请按系统提示词中的声明,以 `await tools.name(args)` 调用工具。使用 inspect(...values) 展示选定的文本和图片。程序是异步 TypeScript 函数的函数体,只接受可擦除语法,不支持 enum 或 namespace。类型标注只作提示。支持顶层 await 和 return。使用 inspect(...values) 展示输出。不要使用 console。模板字面量的 raw 形式只用于反斜杠必须原样保留的短文本,例如正则表达式;其他文本,尤其是文件内容和命令,用普通字符串书写。文件内容写成引号字符串数组,每行一个元素,用换行符拼接;不要写成一个模板字面量。每次调用在新的 Node 进程中运行,可通过 await import(...) 使用 Node API。相对路径以传入的工作目录为准;process.env 初始为空。直接文件系统访问遵循本次执行的沙箱策略。每个程序从 Session 的当前目录启动,运行中保留初始目录。沙箱提权只为本次完整程序执行授权。嵌套工具保留自身策略与审批。只有在获得拒绝证据后才请求更宽访问。先前效果可能已经发生,请在显式重试前检查。程序不会自动重放。
针对可用工具执行 TypeScript 程序。接受两个必填参数:`code`,要执行的程序;以及 `description`,简要说明程序做什么。请按系统提示词中的声明,以 `await tools.name(args)` 调用工具。使用 inspect(...values) 展示选定的文本和图片。程序由 TypeScript REPL 语句组成,只接受可擦除语法,不支持 enum 或 namespace。类型标注只作提示。支持顶层声明和 await;不支持顶层 return。使用 inspect(...values) 展示输出。不要使用 console。模板字面量的 raw 形式只用于反斜杠必须原样保留的短文本,例如正则表达式;其他文本,尤其是文件内容和命令,用普通字符串书写。文件内容写成引号字符串数组,每行一个元素,用换行符拼接;不要写成一个模板字面量。程序在严格模式下运行:给未声明的名字赋值会抛错,有意设置全局变量请使用 globalThis;eval 和 new Function 不可用。变量、函数和导入的模块在本 Agent 的多次调用之间保留在内存中。每次调用在自己的顶层作用域中运行一个程序。它的顶层 let、const、var、class 和 function 声明,以及它从之前程序收到的名字,会拷贝到之后程序的顶层作用域:之后的程序收到的是这些变量的拷贝而不是引用,因此它们持有的对象仍然共享。同一个程序里,要么使用拷贝来的名字,要么重新声明它;不要既声明一个名字又使用它拷贝来的值。给拷贝来的名字赋值,即使它是用 const 声明的,也只改变本程序的拷贝,之后的程序会收到这个拷贝。不要在块内声明 var;块级 var 会改变之后程序拷贝到的值。之前程序中的函数和仍在运行的代码保留它们捕获的值,它们之后的赋值不会被拷贝;共享的可变状态请放在对象中。如果程序在重新声明已有名字的声明完成前失败,之后的程序保留该名字原先的值。使用 await import(...) 加载模块;require 和 module 不可用。相对导入说明符按本环境第一个程序的工作目录解析,而 process.cwd() 和相对文件路径跟随每个程序的工作目录。直接文件系统访问遵循环境启动时的沙箱策略;process.env 初始为空。超时和取消结果会说明保留的变量是被保留还是被清除。重启、沙箱变更或进程失败会清除它们。请重新创建缺失的变量和资源;对话历史不会恢复状态。之前的修改和工具效果不会回滚。获批的沙箱提权使用全新环境,之后丢弃其中的变量。请在程序结束前等待工具调用和清理完成;未完成的工具调用会被拒绝。完成、超时或取消后,新的工具调用会被拒绝,捕获的输出会被丢弃;后台工作仍可能改变状态。请在程序结束前等待子进程完成;原始输出归属于当前执行。每个程序从 Session 的当前目录启动,运行中保留初始目录。沙箱提权只为本次完整程序执行授权。嵌套工具保留自身策略与审批。只有在获得拒绝证据后才请求更宽访问。先前效果可能已经发生,请在显式重试前检查。程序不会自动重放。
```json
{
@@ -624,7 +624,7 @@ ask_user_question 默认保持原有阻塞行为;设置 `mode: timed` 后才
"properties": {
"code": {
"type": "string",
"description": "The program: the body of an async TypeScript function."
"description": "The TypeScript program to execute, following this tool's execution instructions."
},
"description": {
"type": "string",
@@ -0,0 +1,16 @@
# Bilingual-pair consistency record for guide.md (docs/i18n/README.md): per heading
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
# After editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-rc.5/ptc-default-scoped-repl/guide.md
/:
en: 3af3cc4793ec67d9
zh: a9d8ce0a8546631c
/node-ptc-runs-the-scoped-repl-by-default:
en: 5a90a2b4a5bab5c8
zh: f838c916dd69ede4
/node-ptc-runs-the-scoped-repl-by-default/change:
en: be41401640bcd00e
zh: 97637a3404b2fb60
/node-ptc-runs-the-scoped-repl-by-default/migration:
en: febb7a0bdf248d61
zh: 6a971b47c9c07a7c
@@ -0,0 +1,27 @@
---
kind: upgrade-guide
description: "Node PTC defaults to persistent-in-memory execution with the scoped REPL instead of per-call function bodies."
---
# Node PTC runs the scoped REPL by default
English | [中文](guide.zh.md)
## Change
`@deepseek-ai/dsh-ptc-runtime-node` previously defaulted `executionMode` to `per-call`: each `run_code` program was an async function body in a fresh Node process, with top-level `return` and no state between calls. The default is now `persistent-in-memory`, which with the default `replScoped` runs the scoped REPL and reports program format `scoped-repl`. Each live Agent keeps one Node process whose top-level bindings carry into later calls; top-level `return` is rejected, and the last top-level expression statement is the completion value. The model guidance describes the new syntax.
This affects every `ptc-runtime` entry that omits `executionMode`, including the default profile's PTC mode, workflow-ptc scripts that run on that runtime, and direct runtime consumers that mount the provider without configuration. Entries that set `executionMode` explicitly are unchanged. For profiles that omit it, the Computer Use detail page reports the shared PTC runtime as already persistent and its **Use persistent mode** action is disabled.
## Migration
1. To keep function bodies in fresh processes, set the mode in `$DSH_HOME/profiles/<profile>/cordis.patch.yml`. The patch replaces the entry's whole `config`, so copy its existing fields into it:
```yaml
- id: ptc-runtime
config:
executionMode: per-call
```
2. Programs written for the scoped REPL replace a final `return value` with a final `value` expression statement and use `await import(...)` instead of `require`.
3. Restart the profile, run `var probe = 1` in one call and `inspect(typeof probe)` in the next call of the same Session. The scoped REPL prints `number`; `per-call` prints `undefined`.
@@ -0,0 +1,27 @@
---
kind: upgrade-guide
description: "Node PTC 默认使用 persistent-in-memory 执行和 scoped REPL,不再默认使用 per-call 函数体。"
---
# Node PTC 默认运行 scoped REPL
[English](guide.md) | 中文
## 变更
`@deepseek-ai/dsh-ptc-runtime-node` 原先的 `executionMode` 默认值是 `per-call`:每个 `run_code` 程序是在新 Node 进程中运行的 async 函数体,可以使用顶层 `return`,调用之间不保留状态。现在默认值是 `persistent-in-memory`,在默认 `replScoped` 下运行 scoped REPL,并报告程序格式 `scoped-repl`。每个存活的 Agent 保留一个 Node 进程,顶层绑定带到之后的调用;顶层 `return` 会被拒绝,最后一条顶层表达式语句是完成值。模型说明描述了新语法。
受影响的是所有省略 `executionMode` 的 `ptc-runtime` 条目,包括默认 profile 的 PTC 模式、在该运行时上运行的 workflow-ptc 脚本,以及不带配置挂载该提供方的直接运行时使用方。显式设置了 `executionMode` 的条目不变。对于省略该项的 profile,Computer Use 详情页显示共享 PTC 运行时已是持久模式,「设为持久化」按钮不可用。
## 迁移
1. 如果要继续在新进程中运行函数体,在 `$DSH_HOME/profiles/<profile>/cordis.patch.yml` 中设置执行方式。patch 会替换该条目的整个 `config`,所以要把条目已有的字段一并写进去:
```yaml
- id: ptc-runtime
config:
executionMode: per-call
```
2. 为 scoped REPL 编写的程序,把末尾的 `return value` 改为末尾的 `value` 表达式语句,并用 `await import(...)` 代替 `require`。
3. 重启 profile,在同一会话中先运行 `var probe = 1`,再在下一次调用中运行 `inspect(typeof probe)`。scoped REPL 输出 `number`;`per-call` 输出 `undefined`。
@@ -60,8 +60,8 @@
en: f4703836365dc3d4
zh: a09ff48a6550fd69
/deepseek-ai-dsh-tool-executor-ptc/known-limitations-and-deferred-work:
en: 0159ba9c4dda070f
zh: 9be2f81d398868a1
en: 872e593c876f4057
zh: a197742ee74eefa6
/deepseek-ai-dsh-tool-executor-ptc/known-limitations-and-deferred-work/dev-note:
en: e67f633dc6fe7773
zh: 3bb0c20c93f16f98
+1 -1
View File
@@ -163,7 +163,7 @@ These constraints apply to the host integration and accepted calls.
- **No built-in reset control** — the shipped Loader plugin does not expose its executor instance through a service, GUI control or SDK endpoint. Hosts needing reset must mount and retain `PtcExecutor` in their own composition; that integration owns retries after a failed reset.
- **PTC mode uses TypeScript, and presentation is per agent rather than per tool** — PTC execution requires `ctx.ptcRuntime.language === 'typescript'`; within one agent no tool can be native-only while another is ptc-only.
- **PTC mode intermediate values are execution-local and unbounded by bytes** — they cannot be reconstructed from session replay and may exhaust process or worker memory; only the outer `run_code` output has the worker's configurable hard cap.
- **State depends on the runtime**: the default backend starts fresh; Node `persistent-in-memory` execution and Script mode with `scriptPersistence: true` retain memory per live Agent. Agent disposal awaits release. Restart and execution failures can clear memory; model-visible guidance explains how to recreate missing variables. Programs and results remain in the Session log, without serializing live objects.
- **State depends on the runtime**: Node `per-call` execution starts fresh; the default Node `persistent-in-memory` execution and Script mode with `scriptPersistence: true` retain memory per live Agent. Agent disposal awaits release. Restart and execution failures can clear memory; model-visible guidance explains how to recreate missing variables. Programs and results remain in the Session log, without serializing live objects.
<a id="dev-note"></a>
### Dev Note
+1 -1
View File
@@ -163,7 +163,7 @@ Error: code run failed (abort): run_code exceeded its limit of 2048 tool calls (
- **没有内置重置控件**:自带的 Loader 插件不通过服务、GUI 控件或 SDK 端点暴露执行器实例。需要重置的宿主必须在自己的组合中挂载并保留 `PtcExecutor`,该集成负责失败后的重试。
- **PTC mode 使用 TypeScript,且呈现方式按 agent 而非按工具**:PTC 执行要求 `ctx.ptcRuntime.language === 'typescript'`;同一个 agent 内不能让一个工具仅使用 Native,而另一个仅使用 PTC。
- **PTC mode 中间值只存在于执行局部,且没有字节上限**:它们无法从会话回放重建,并可能耗尽进程或 worker 内存;只有外层 `run_code` 输出受 worker 可配置的硬上限约束。
- **状态由运行时决定**:默认后端每次重新开始;Node 的 `persistent-in-memory` 执行和启用 `scriptPersistence: true` 的 Script 模式按存活 Agent 保留内存。Agent 销毁时等待环境释放。重启与执行失败可能清除内存;模型说明会指导重新创建缺失变量。程序与结果仍写入 Session 日志,不序列化运行中的对象。
- **状态由运行时决定**:Node 的 `per-call` 执行每次重新开始;默认的 Node `persistent-in-memory` 执行和启用 `scriptPersistence: true` 的 Script 模式按存活 Agent 保留内存。Agent 销毁时等待环境释放。重启与执行失败可能清除内存;模型说明会指导重新创建缺失变量。程序与结果仍写入 Session 日志,不序列化运行中的对象。
<a id="dev-note"></a>
### 开发备注
@@ -9,8 +9,8 @@
en: 7e1a8657a212c70b
zh: afb7a8c6a3afd718
/deepseek-ai-dsh-ptc-runtime-node/summary:
en: 7f80d74a7f87eb05
zh: 6aa31b97ac920ca6
en: e3350a3c7cde1663
zh: 2850eec5715e6f80
/deepseek-ai-dsh-ptc-runtime-node/table-of-contents:
en: d152484eb41ac6b4
zh: 725b47765ee8f30b
@@ -18,14 +18,14 @@
en: 70e83ccdf8159a10
zh: 8282f1da5e844426
/deepseek-ai-dsh-ptc-runtime-node/use-this-package/configuration:
en: 2be5e2e5d17c7c7f
zh: 4de138d85dea1614
en: b49a23785fd80315
zh: 1167b2face1e1028
/deepseek-ai-dsh-ptc-runtime-node/use-this-package/execution-and-results:
en: e4c2a44c600693e9
zh: d4690975a3f95b14
/deepseek-ai-dsh-ptc-runtime-node/use-this-package/in-memory-modes:
en: d5814e14a6b8cf9f
zh: 40968df6610e9d7f
en: 6751521701e314dd
zh: 9e6c2b179f728414
/deepseek-ai-dsh-ptc-runtime-node/use-this-package/deadlines-and-cancellation:
en: d383ec7aeab8afec
zh: 7c9c49e205fbbcd8
@@ -57,8 +57,8 @@
en: 40294c1c31b74824
zh: d91e7b78c0619c7e
/deepseek-ai-dsh-ptc-runtime-node/known-limitations-and-deferred-work:
en: 66d2a67411aecb34
zh: 9ccb065e98f432b5
en: 1a4f709bbd6fdecf
zh: 5c60630d18220015
/deepseek-ai-dsh-ptc-runtime-node/known-limitations-and-deferred-work/dev-note:
en: 6373aba4e08f7205
zh: 2a8c33d1f2839df4
@@ -9,7 +9,7 @@ English | [中文](README.zh.md)
## Summary
Execute model-written TypeScript with host-provided async functions. The default `per-call` mode runs async function bodies in fresh Node processes; `vm-script` supports top-level await and optionally retains a context per Agent with `scriptPersistence`. Opt-in `persistent-in-memory` retains a REPL per Agent. 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.
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.
## Table of Contents
@@ -36,7 +36,7 @@ Configure the provider row after its required services are available:
```yaml
- name: '@deepseek-ai/dsh-ptc-runtime-node'
config:
executionMode: per-call
executionMode: persistent-in-memory
timeoutMs: 120000
maxTimeoutMs: 600000
maxOutputBytes: 67108864
@@ -49,7 +49,7 @@ Configure the provider row after its required services are available:
| Field | Default | Meaning |
|---|---|---|
| `executionMode` | `per-call` | `per-call` runs async function bodies in fresh processes; `vm-script` evaluates Scripts; `persistent-in-memory` retains a confined REPL per owner |
| `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 |
| `scriptPersistence` | `false` | With `executionMode: vm-script`, reuse a process and context per owner; `true` with another mode rejects at load |
| `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 |
| `timeoutMs` | `120,000` | Default elapsed execution deadline, including nested tool and approval waits |
@@ -102,12 +102,12 @@ Set `executionMode: vm-script` to evaluate erasable TypeScript through `node:vm`
<a id="persistent-repl"></a>
### In-memory modes
The `persistent-in-memory` mode and Script mode with `scriptPersistence: true` retain state per owner. To retain a REPL, set `executionMode: persistent-in-memory` on the existing `@deepseek-ai/dsh-ptc-runtime-node` plugin; it 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. Enable it deliberately with a profile patch:
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:
```yaml
- id: ptc-runtime
config:
executionMode: persistent-in-memory
executionMode: per-call
```
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`.
@@ -247,7 +247,7 @@ These limits qualify the execution guarantees and retained output.
- **Confinement inherits the selected backend's limits** — full and partial enforcement are reported separately; sandbox policy and managed-process containment are distinct guarantees.
- **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.
- **Cleanup inherits subprocess observability** — escaped descendants on a fallback platform may remain outside the managed range; see the subprocess provider's stated limits.
- **Default execution is one-shot** — retained state requires `persistent-in-memory` mode or Script mode with `scriptPersistence: true`; no mode offers a yield/wait API.
- **`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.
- **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.
- **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.
- **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.
@@ -9,7 +9,7 @@ kind: "package-reference"
## 概述
执行模型编写的 TypeScript,并提供宿主异步函数。默认的 `per-call` 模式在全新 Node 进程中运行异步函数体;`vm-script` 支持顶层 await,并可通过 `scriptPersistence` 为每个 Agent 保留 context。显式启用的 `persistent-in-memory` 为每个 Agent 保留 REPL。所有模式都在进程启动时应用文件沙箱策略,返回捕获日志、无损 JSON 或结构化失败。执行时限、输出上限和 V8 堆上限约束运行。未确认的停止请求与单次执行完成后清理受管进程范围;约束不可用时执行失败。
执行模型编写的 TypeScript,并提供宿主异步函数。默认的 `persistent-in-memory` 模式为每个 Agent 保留 scoped REPL;`per-call` 在全新 Node 进程中运行异步函数体;`vm-script` 支持顶层 await,并可通过 `scriptPersistence` 为每个 Agent 保留 context。所有模式都在进程启动时应用文件沙箱策略,返回捕获日志、无损 JSON 或结构化失败。执行时限、输出上限和 V8 堆上限约束运行。未确认的停止请求与单次执行完成后清理受管进程范围;约束不可用时执行失败。
## 目录
@@ -36,7 +36,7 @@ kind: "package-reference"
```yaml
- name: '@deepseek-ai/dsh-ptc-runtime-node'
config:
executionMode: per-call
executionMode: persistent-in-memory
timeoutMs: 120000
maxTimeoutMs: 600000
maxOutputBytes: 67108864
@@ -49,7 +49,7 @@ kind: "package-reference"
| 字段 | 默认值 | 含义 |
|---|---|---|
| `executionMode` | `per-call` | `per-call` 在全新进程中运行异步函数体;`vm-script` 求值 Script;`persistent-in-memory` 为每个所有者保留受限 REPL |
| `executionMode` | `persistent-in-memory` | `persistent-in-memory` 为每个所有者保留受限 REPL;`per-call` 在全新进程中运行异步函数体;`vm-script` 求值 Script |
| `scriptPersistence` | `false` | 在 `executionMode: vm-script` 下,为每个所有者复用进程与 context;其他模式下设为 `true` 会在加载时拒绝 |
| `replScoped` | `persistent-in-memory` 下为 `true`,其他模式下为 `false` | 在 `executionMode: persistent-in-memory` 下,按 scoped REPL 语句执行,每次调用拿到之前顶层绑定的拷贝;设为 `false` 时使用 Node 的 REPL 求值器,其他模式下设为 `true` 会在加载时拒绝 |
| `timeoutMs` | `120,000` | 默认经过时间截止,包括嵌套工具与审批等待 |
@@ -102,12 +102,12 @@ profile 编辑器可从 `@deepseek-ai/dsh-ptc-runtime-node/configuration` 导入
<a id="persistent-repl"></a>
### 内存保留模式
`persistent-in-memory` 模式和启用 `scriptPersistence: true` 的 Script 模式都按所有者保留状态。要保留 REPL,在现有 `@deepseek-ai/dsh-ptc-runtime-node` 插件上设置 `executionMode: persistent-in-memory`;默认运行 scoped REPL,设置 `replScoped: false` 时使用 Node 的 REPL 求值器。所有模式都需要 `fs`、`subprocess`、`sandbox` 和 `sandboxPolicy`,并在进程启动时应用文件沙箱策略。通过配置档补丁显式启用:
`persistent-in-memory` 模式和启用 `scriptPersistence: true` 的 Script 模式都按所有者保留状态。`persistent-in-memory` 是 `executionMode` 的默认值,运行 scoped REPL,设置 `replScoped: false` 时使用 Node 的 REPL 求值器。所有模式都需要 `fs`、`subprocess`、`sandbox` 和 `sandboxPolicy`,并在进程启动时应用文件沙箱策略。如果要改为在全新进程中运行函数体,通过配置档补丁选择 `per-call`:
```yaml
- id: ptc-runtime
config:
executionMode: persistent-in-memory
executionMode: per-call
```
保存补丁,在使用 PTC 工具展示的配置中通过 `dsh headless --patch <path>` 加载。`per-call` 模式和 `scriptPersistence: false` 的 Script 模式不跨调用保留程序内存。修改配置会重载提供方并释放其执行资源。单文件打包宿主默认使用内嵌载体;宿主在每次执行中发送所选的程序格式和保留标志,因此内嵌的 `process.js` bootstrap 同时服务单次执行和保留执行。远端脚本部署使用 `node-script` 启动方式,并将 `launch.bootstrapPath` 指向本包构建出的 `persistent-process.js`。
@@ -247,7 +247,7 @@ AsyncFunction 和 Node REPL 共用同步 `registerHooks` 和以 symbol 为键的
- **约束继承所选后端的限制**——完整与部分强制能力分开报告;沙箱策略与受管进程约束是不同保证。
- **堆上限不是进程树内存限制**——原生分配与后代进程内存不属于 V8 老生代上限。不提供进程树 CPU 计量器。
- **清理继承子进程的可观测范围**——使用 fallback 的平台上,逃逸的后代可能仍在受管范围之外;参见子进程提供方声明的限制。
- **默认执行是一次性的**:保留状态需要设置 `persistent-in-memory` 模式,或在 Script 模式下启用 `scriptPersistence: true`;所有模式都不提供 yield/wait API。
- **`per-call` 执行是一次性的**:保留状态需要使用默认的 `persistent-in-memory` 模式,或在 Script 模式下启用 `scriptPersistence: true`;所有模式都不提供 yield/wait API。
- **await 转换放宽声明语义**——转换后程序的顶层 `let`、`const` 和 `class` 绑定可修改,且在执行前初始化为 `undefined`,不再具有原生暂时性死区。执行到函数声明时才会为其设置保留的全局变量;没有初始化器的 `var` 声明会将其绑定重置为 `undefined`。直接 eval 中的声明仅在本次求值内有效。不接受顶层 `using` 声明;可释放绑定需放在块内。运行时堆栈位置指向转换后的源码。无需转换即可编译的脚本保持原生语义。
- **原生词法初始化失败可能占用名称**——顶层 `let`、`const` 或 `class` 的初始化器在完成绑定初始化前抛错时,该名称会在保留的 Script context 中持续处于未初始化状态。读取、赋值和重新声明都会失败;应使用新名称,或释放并重新创建环境。
- **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)列出完整行为。
@@ -8,7 +8,7 @@ import { resolvePersistentExecution } from './configuration.ts'
export interface Config {
/** Worker invocation in the subprocess world; omitted selects the local carrier. */
launch?: LaunchConfig
/** per-call uses fresh async function bodies; vm-script uses VM contexts; persistent-in-memory retains a REPL per owner. */
/** persistent-in-memory, the default, retains a REPL per owner; per-call uses fresh async function bodies; vm-script uses VM contexts. */
executionMode?: 'per-call' | 'persistent-in-memory' | 'vm-script'
/** Retain a Script process and context per stateOwner; only supported with executionMode: vm-script. */
scriptPersistence?: boolean
@@ -39,7 +39,7 @@ export interface Config {
export type ResolvedConfig = Required<Config>
/** Loader defaults for the Node PTC provider. */
export const NodeConfig: z<Config> = z.object({
executionMode: z.union([z.const('per-call'), z.const('persistent-in-memory'), z.const('vm-script')]).default('per-call'),
executionMode: z.union([z.const('per-call'), z.const('persistent-in-memory'), z.const('vm-script')]).default('persistent-in-memory'),
scriptPersistence: z.boolean().default(false),
replScoped: z.boolean(),
timeoutMs: z.number().default(120_000),
@@ -8,7 +8,7 @@ const SCOPED_REPL_BY_DEFAULT: boolean = true
/**
* Select retained Node execution while preserving Script and scoped REPL syntax.
* @param programFormat - Effective syntax; omission uses the Node provider's default function-body syntax.
* @param programFormat - Effective syntax; omission selects function bodies.
* @returns All three settings to merge into the profile atomically, replacing stale values; function bodies and REPL statements
* switch to `persistent-in-memory` with `SCOPED_REPL_BY_DEFAULT`, which is also the default when `replScoped` is omitted.
*/
@@ -58,10 +58,10 @@ it.each(['per-call', 'persistent-in-memory'] as const)('rejects Script retention
})
// The only ptc-runtime-node mode test that omits executionMode; it pins the provider default.
it('selects per-call function bodies when executionMode is omitted', async () => {
it('selects the retained scoped REPL when executionMode is omitted', async () => {
const { runtime } = await mountConfiguredRuntime(new Context(), {})
expect(runtime.retainsState).toBe(false)
expect(runtime.programFormat).toBe('function-body')
expect(runtime.retainsState).toBe(true)
expect(runtime.programFormat).toBe('scoped-repl')
})
// The only ptc-runtime-node mode test that omits replScoped; it pins SCOPED_REPL_BY_DEFAULT from configuration.ts.