feat(cua): expose persistent code tool outside PTC mode

This commit is contained in:
turtle1999 committed 2026-11-09 15:53:22 +08:00
1 parent e29a8f57c5
commit b9966a12a6
128 files changed
+3018 -338

No files matched your search

@@ -15,8 +15,8 @@
en: d152484eb41ac6b4
zh: 09388d293f9be9cb
/deepseek-ai-dsh-experimental-ptc-runtime-python/use-this-package:
en: 4695160db934a010
zh: 90dcd69e2aab43b3
en: fdb59e2f485452fc
zh: d763020d1626d3c2
/deepseek-ai-dsh-experimental-ptc-runtime-python/use-this-package/what-you-get:
en: ca7b9cc958069c7f
zh: 8a4ac72d02ad76eb
@@ -27,7 +27,7 @@ Run model-generated Python in a fresh CPython 3.10+ process on macOS or Linux un
Choose this published experimental package only in an explicit composition. Register `PythonPtcRuntime` beside `dsh-tools`; `run(resolve(request))` executes each program in a fresh CPython 3.10+ subprocess, resolving with `result.value` on success and `result.error` on failure (the orthogonal `PtcRunFailure.kind` taxonomy classifies parse failures, thrown exceptions, invalid completions, output overflows, budget expiry, aborts, unavailable confinement, and substrate death). It rejects only for caller misuse, such as malformed bindings, unresolved execution options, or a call after disposal. Configuration is rejected at load: a non-Unix platform; an explicit `pythonBin` that is not an executable regular file or a bare name that does not resolve on `PATH`; a non-CPython, pre-3.10, or probe-failing interpreter; a non-positive or non-integer budget; a `maxLogBytes` below the truncation-marker floor (64); a timer value `setTimeout` would clamp; a budget larger than the effective fd-3 frame cap (lowered when the host heap cannot safely parse a near-cap frame); or an `addressSpaceMb`/output-budget pair whose worst-case peak would breach `RLIMIT_AS`.
The composition must supply `sandbox` and `sandboxPolicy` for this local execution host. `resolve(request)` accepts an explicit `sandboxPolicy` or resolves the shared deployment policy, and defaults `cwd` to that policy's workspace root. PTC mode supplies the calling Session's policy and directory. The configured `maxWallMs` remains the execution deadline; explicit `timeoutMs` overrides are unsupported.
The composition must supply `sandbox` and `sandboxPolicy` for this local execution host. `resolve(request)` accepts an explicit `sandboxPolicy` or resolves the shared deployment policy, and defaults `cwd` to that policy's workspace root. PTC mode supplies the calling Session's policy and directory. The configured `maxWallMs` remains the execution deadline; explicit `timeoutMs` overrides and `initialization` source are unsupported and reject during resolution.
`read-only` and `workspace-write` execute through the configured sandbox provider; `danger-full-access` explicitly bypasses confinement. `result.sandbox` reports the mode, observed denial, and the backend's full or partial enforcement separately from the program outcome. The [sandbox service](../../sandbox/sandbox/README.md) defines the file restrictions and backend limits; these modes do not restrict network access or arbitrary file reads.
@@ -27,7 +27,7 @@ kind: "package-reference"
仅在显式组合中选择这个已发布的实验包。将 `PythonPtcRuntime` 与 `dsh-tools` 一起注册后,`run(resolve(request))` 会在全新的 CPython 3.10+ 子进程中执行每个程序;成功时以 `result.value` resolve,失败时以 `result.error` resolve(正交的 `PtcRunFailure.kind` 分类涵盖解析失败、抛出异常、无效完成值、输出溢出、预算到期、中止、约束不可用与执行基底终止)。仅有调用方误用会 reject,例如 binding 不合法、执行选项未解析,或在 dispose 后调用。配置在加载期拒绝:非 Unix 平台;不是可执行普通文件的显式 `pythonBin`,或无法在 `PATH` 上解析的裸名;非 CPython、低于 3.10 或探测失败的解释器;非正或非整数预算;低于截断标记下限(64)的 `maxLogBytes`;会被 `setTimeout` 截断的定时器值;超过有效 fd-3 帧上限的预算(宿主堆无法安全解析接近上限的帧时,该上限会降低);或最坏峰值会突破 `RLIMIT_AS` 的 `addressSpaceMb`/输出预算组合。
组合必须为此本地执行宿主提供 `sandbox` 和 `sandboxPolicy`。`resolve(request)` 接受显式 `sandboxPolicy`,或解析共享部署策略,并将 `cwd` 默认设为该策略的工作区根目录。PTC mode 提供调用 Session 的策略和目录。配置的 `maxWallMs` 仍是执行截止时间;不支持显式 `timeoutMs` 覆盖。
组合必须为此本地执行宿主提供 `sandbox` 和 `sandboxPolicy`。`resolve(request)` 接受显式 `sandboxPolicy`,或解析共享部署策略,并将 `cwd` 默认设为该策略的工作区根目录。PTC mode 提供调用 Session 的策略和目录。配置的 `maxWallMs` 仍是执行截止时间;不支持显式 `timeoutMs` 覆盖和 `initialization` 源码,解析时会拒绝。
`read-only` 和 `workspace-write` 通过配置的沙箱提供方执行;`danger-full-access` 显式绕过约束。`result.sandbox` 独立于程序结果报告模式、观察到的拒绝,以及后端的完整或部分强制能力。[沙箱服务](../../sandbox/sandbox/README.zh.md)定义文件限制与后端局限;这些模式不限制网络访问或任意文件读取。
@@ -972,12 +972,13 @@ export class PythonPtcRuntime extends PtcRuntime {
/**
* Resolve authority, directory, and the configured wall deadline.
* @param request - Program inputs and optional resolved sandbox authority; timeout overrides are unsupported.
* @param request - Program inputs and optional resolved sandbox authority.
* @returns Complete inputs for the provider's run method.
* @throws When a requested timeout is unsupported, cwd is relative, or the provider is disposed.
* @throws When initialization or a timeout override is supplied, cwd is relative, or the provider is disposed.
*/
resolve(request: PtcRunRequest): PtcRunSpec {
if (this.disposed) throw new Error('dsh-ptc-runtime-python: resolve() after disposal')
if (request.initialization !== undefined) throw new Error('dsh-ptc-runtime-python: initialization is unsupported')
if (request.timeoutMs !== undefined) throw new Error('dsh-ptc-runtime-python: per-call timeout is unsupported')
const sandboxPolicy = request.sandboxPolicy ?? this.ctx.sandboxPolicy.resolve()
const cwd = request.cwd ?? sandboxPolicy.workspaceRoot
@@ -991,6 +992,7 @@ export class PythonPtcRuntime extends PtcRuntime {
* @returns Captured output, confinement facts, and the program outcome.
*/
async run(request: PtcRunSpec): Promise<PtcRunResult> {
if (request.initialization !== undefined) throw new Error('dsh-ptc-runtime-python: initialization is unsupported')
if (request.sandboxPolicy === undefined) throw new Error('dsh-ptc-runtime-python: run requires a resolved sandbox policy')
if (request.timeoutMs !== this.config.maxWallMs) throw new Error('dsh-ptc-runtime-python: unsupported execution timeout')
if (!isAbsolute(request.cwd)) throw new Error('dsh-ptc-runtime-python: cwd must be absolute')
@@ -88,12 +88,15 @@ describe('PythonPtcRuntime — seam descriptors and misuse', () => {
expect(() => runtime.resolve({ ...request, cwd: 'relative' })).toThrow('cwd must be absolute')
expect(() => runtime.resolve({ ...request, timeoutMs: 1 })).toThrow('per-call timeout is unsupported')
expect(() => runtime.resolve({ ...request, timeoutMs: null })).toThrow('per-call timeout is unsupported')
expect(() => runtime.resolve({ ...request, initialization: '' })).toThrow('initialization is unsupported')
expect(() => runtime.resolve({ ...request, initialization: 'helper = {}' })).toThrow('initialization is unsupported')
const sandboxPolicy = { mode: 'danger-full-access' as const, workspaceRoot: cwd }
expect(runtime.resolve({ ...request, sandboxPolicy }).sandboxPolicy).toBe(sandboxPolicy)
await expect(runtime.run({ ...request, cwd, timeoutMs: 30_000 })).rejects.toThrow('run requires a resolved sandbox policy')
await expect(runtime.run({ ...spec, cwd: 'relative' })).rejects.toThrow('cwd must be absolute')
await expect(runtime.run({ ...spec, timeoutMs: 1 })).rejects.toThrow('unsupported execution timeout')
await expect(runtime.run({ ...spec, timeoutMs: null })).rejects.toThrow('unsupported execution timeout')
await expect(runtime.run({ ...spec, initialization: '' })).rejects.toThrow('initialization is unsupported')
const result = await runtime.run(runtime.resolve({ ...request, cwd, program: 'import os\nreturn os.getcwd()' }))
expect(result.error).toBeUndefined()
expect(result.value).toBe(realpathSync(cwd))