dsh-deep-ptc-mode 1.5.0 → 1.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.1 — 2026-11-04
4
+
5
+ - Follow the official modules instead of naming them. The shell, job and question wrappers no longer import `@deepseek-ai/dsh-tool-bash`, `dsh-tool-pwsh`, `dsh-tool-jobs` or `dsh-tool-ask-user`: each derived row carries the module name and options of the official row it replaces (`upstream`, `options`), and the wrapper loads that module through the installed runtime's module graph with the official plugin's own `inject` and `Config`. A renamed or replaced official tool is followed rather than breaking the mount.
6
+ - Read the shell executors from the base deployment declaration (`@deepseek-ai/dsh-base/cordis.patch.yml`, rows `bash-sandbox` and `pwsh-sandbox`), including their official options; only the foreground cap is added. The WSL/Zsh executor extends the official bash executor class named there instead of importing `dsh-bash-local`/`dsh-bash-sandbox`.
7
+ - Fall back to the official shell rows when the chosen environment cannot be mapped: no official shell tool row, no declared executor, or an official bash executor whose API WSL/Zsh can no longer extend (probed before the preset is published). The reachability guard still applies; the preset never publishes rows that cannot mount.
8
+ - Keep `lib/base-snapshot.json` as the executor fallback beside `lib/preset.json`; `npm run sync:snapshot` regenerates both. Drop the official tool and executor packages from `peerDependencies` and add `@deepseek-ai/dsh-base`.
9
+ - `scripts/check-preset.cjs` also resolves the official modules the wrappers name. The runtime checks (`check-reachability.mjs`, `check-host.cjs`) now also run on `0.2.2-rc.1`, whose tool batches go through a selected executor and whose preset registry requires the agent registry.
10
+
11
+ ## 1.6.0 — 2026-11-04
12
+
13
+ - Derive the preset from the PTC preset the installed Harness declares (`@deepseek-ai/dsh-web-app/presets/ptc.patch.yml`) instead of freezing a copy. Official rows, settings and additions are inherited; Deep PTC still replaces only its persona, execution environment, reachability guard, and the official job/question wrappers.
14
+ - Fix the failure after the DSH `0.2.2-rc.1` update: the frozen 1.5.0 snapshot still named the `@deepseek-ai/dsh-tool-subagent-control/list-agents` subpath, which `0.2.2-rc.1` removed, so the preset could not mount and existing Deep PTC sessions were reported as unusable. Sessions were never migrated or rewritten; they open again once the preset mounts.
15
+ - Keep `lib/preset.json` only as a fallback snapshot and refresh it to `0.2.2-rc.1`; `npm run sync:snapshot` regenerates it from the installed declaration.
16
+ - Declare every imported host package in `peerDependencies`, including `@deepseek-ai/dsh-web-app`: the host only routes a linked plugin's bare specifier to the installation when the name is peer-declared, so without it a `link:` install silently fell back to the snapshot. `npm run check` now fails if a peer is missing.
17
+ - Match official rows recursively (persona, shell/executor rows, job and question rows may move into a group) and accept only a declaration whose id is `ptc`. Tests cover nested groups, a non-PTC declaration, and the peer-declaration guard.
18
+ - `compatibility.json` now records the checked upstream release plus fixture hash; `scripts/check.mjs` verifies inheritance invariants and fallback/dedaration parity instead of exact-snapshot equality.
19
+ - Add derivation tests for future compositions (unknown rows, reordering, missing shell or wrapped rows) and `scripts/check-preset.cjs`, a live-runtime check that every derived row resolves through the installed module graph.
20
+
3
21
  ## 1.5.0 — 2026-10-31
4
22
 
5
23
  - Enforce reachability in code. Foreground shell commands move to background jobs after `foregroundSeconds` (default 30, configurable 5–600); a larger requested timeout is capped. Commands still run; only the wait ends.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Deep PTC mode
2
2
 
3
- [中文](README.zh.md) · MIT · **1.5.0**
3
+ [中文](README.zh.md) · MIT · **1.6.1**
4
4
 
5
5
  A DeepSeek Harness agent preset with exactly the built-in PTC tool surface and a different way of working: the model uses its full capability, stays interruptible while work runs, asks for approval only when a task is long, asks you instead of guessing, and runs commands in the environment you choose.
6
6
 
@@ -77,10 +77,10 @@ A prompt changes the model's working tendency, not the real token limit or billi
77
77
  Requires Node `>=24` and DSH `>=0.2.1-rc.5`. Windows desktop rc.5 was used for real WSL/PowerShell command checks. macOS/Zsh configuration, argv and tool mounting were checked; native macOS execution has not been verified on this Windows host.
78
78
 
79
79
  ```js
80
- plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.5.0" })
80
+ plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.6.1" })
81
81
  // Or from a local checkout or archive:
82
82
  plugin_manager({ action: "install_bundle", target: "C:\\path\\to\\dsh-deep-ptc-mode" })
83
- // Or target: "C:\\path\\to\\dsh-deep-ptc-mode-1.5.0.tgz"
83
+ // Or target: "C:\\path\\to\\dsh-deep-ptc-mode-1.6.1.tgz"
84
84
  ```
85
85
 
86
86
  Repository locator: `github:lishize20040802-rgb/dsh-deep-ptc-mode`. It installs content actually published there; a local upgrade does not publish to GitHub or npm.
@@ -100,22 +100,24 @@ Prefer the UI, which uses revisioned, atomic Host form writes.
100
100
 
101
101
  ## Compatibility and development
102
102
 
103
- The rc.5 PTC template has 23 top-level rows. The template differs only in persona; runtime composition replaces the two platform-switched shell tools with one isolated execution group. Planning, compaction, pruning, web and delegation settings stay intact.
103
+ Deep PTC is composed at load time from the PTC preset the installed Harness declares (`@deepseek-ai/dsh-web-app/presets/ptc.patch.yml`). Every official row is inherited as-is; Deep PTC replaces only its persona text, swaps the two platform-switched shell tools for one isolated execution group, adds the reachability guard, and wraps the official job and question tools. The wrappers and the execution group never name an official module themselves: they load the module the official row names (and the shell executors the base deployment declares in `@deepseek-ai/dsh-base/cordis.patch.yml`), with the official options. An official PTC change therefore reaches this mode without a plugin release, and a removed or renamed upstream module cannot leave a stale row behind. When the chosen execution environment cannot be mapped onto the official rows, those rows are kept and the change is logged. If the declaration cannot be resolved, read or parsed, the bundled `lib/preset.json` snapshot is used as a fallback and the fallback is logged.
104
104
 
105
- Version 1.3.0 adds Host/browser code and is no longer persona-only. `compatibility.json` records the verified upstream and fixture hash. The engines range is an installation floor, not proof that every future release was tested.
105
+ Because the declarations are resolved through the host runtime, every host package the plugin imports statically is declared in `peerDependencies` — including `@deepseek-ai/dsh-web-app`. The host routes those names to the installation for a linked plugin; `npm run check` fails if one is missing, which is what keeps a `link:` installation on the live declaration instead of silently using the fallback snapshot. `compatibility.json` records the upstream release the checked fixture was taken from and its hash; `npm run check` verifies that the bundled fallback still derives the same preset as that fixture and that the inheritance invariants hold. The engines range is an installation floor, not proof that every future release was tested, so run `npm run check:upstream -- <path>` against a new release before trusting it.
106
106
 
107
107
  ```sh
108
108
  npm ci
109
109
  npm run check
110
110
  npm test
111
111
  npm run check:upstream -- /path/to/the/new/upstream/ptc.patch.yml
112
+ npm run sync:snapshot # refresh lib/preset.json and lib/base-snapshot.json from the installed declarations
113
+ PTC_RUNTIME_MODULES=/path/to/dsh/node_modules node scripts/check-preset.cjs # loader-level row resolution on a real runtime
112
114
  PTC_RUNTIME_MODULES=/path/to/dsh/node_modules node scripts/check-reachability.mjs # interruptible waits on a real runtime
113
115
  npm pack
114
116
  ```
115
117
 
116
- The checker parses `!!js` as data, compares nested upstream settings and fails on drift requiring review. Tests cover platforms, argv boundaries, confined WSL refusal, atomic settings writes and stale revisions, plus preset replacement and cleanup. Real-task evaluations should measure successful completion, unnecessary questions, scope expansion, background-work collection and latency.
118
+ The checker parses `!!js` as data and asserts the derivation invariants: every official row survives unchanged except the persona, the shell rows and the two wrapped tools (including when the official preset nests them in a group); row ids stay unique; derivation is deterministic across nine platform/environment pairs. Tests cover future compositions as well (unknown rows, reordered rows, removed shell or wrapped rows), plus platforms, argv boundaries, confined WSL refusal, atomic settings writes and stale revisions. Real-task evaluations should measure successful completion, unnecessary questions, scope expansion, background-work collection and latency.
117
119
 
118
- Main files: `cordis.patch.yml` is the settings entry; `lib/index.mjs` manages revisions; `lib/model.mjs` builds isolated execution configurations; `lib/executor.mjs` adapts WSL/Zsh; `lib/terminal.mjs` wraps the official Bash/PowerShell tools with interruptible waits and provides the Zsh tool; `lib/jobs-tool.mjs` and `lib/ask-user.mjs` wrap the official job and question tools; `lib/guard.mjs`, `lib/rules.mjs`, `lib/sleep-lint.mjs` and `lib/reachable.mjs` implement the pause/polling guard and interruptible waits; `lib/client.js` owns the bilingual settings card; `lib/preset.json` contains the persona and official PTC template.
120
+ Main files: `cordis.patch.yml` is the settings entry; `lib/index.mjs` manages revisions; `lib/model.mjs` builds isolated execution configurations; `lib/executor.mjs` extends the official bash executor for WSL/Zsh; `lib/terminal.mjs` runs the official shell tool the declaration names, with interruptible waits and the Zsh dialect; `lib/jobs-tool.mjs` and `lib/ask-user.mjs` run the official job and question tools the declaration names; `lib/host.mjs` resolves those official modules through the installed runtime; `lib/guard.mjs`, `lib/rules.mjs`, `lib/sleep-lint.mjs` and `lib/reachable.mjs` implement the pause/polling guard and interruptible waits; `lib/client.js` owns the bilingual settings card; `lib/upstream.mjs` locates and parses the installed PTC declaration; `lib/preset.json` holds the persona and the fallback snapshot used only when that declaration is unavailable.
119
121
 
120
122
  Uninstall with `plugin_manager` action `remove_bundle`, target `dsh-deep-ptc-mode`. Local link installations depend on their source directory: uninstall before deleting it.
121
123
 
package/README.zh.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 深度 PTC 模式
2
2
 
3
- [English](README.md) · MIT · 当前版本:**1.5.0**
3
+ [English](README.md) · MIT · 当前版本:**1.6.1**
4
4
 
5
5
  DeepSeek Harness 的 Agent 模式(preset),工具面与内置 PTC 完全一致,只换掉「工作方式」:让模型把能力用满、全程可被打断、按任务大小决定要不要你批准、拿不准就问你,并且自己选命令在哪个环境里跑。
6
6
 
@@ -79,10 +79,10 @@ WSL 命令使用 Linux/POSIX 语法;文件工具和 `workdir` 仍用 Windows
79
79
  本地目录或构建产物可通过插件管理器安装:
80
80
 
81
81
  ```js
82
- plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.5.0" })
82
+ plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.6.1" })
83
83
  // 也可从本地目录或安装包安装:
84
84
  plugin_manager({ action: "install_bundle", target: "C:\\path\\to\\dsh-deep-ptc-mode" })
85
- // 或 target: "C:\\path\\to\\dsh-deep-ptc-mode-1.5.0.tgz"
85
+ // 或 target: "C:\\path\\to\\dsh-deep-ptc-mode-1.6.1.tgz"
86
86
  ```
87
87
 
88
88
  GitHub 地址:`github:lishize20040802-rgb/dsh-deep-ptc-mode`。该地址安装远端实际内容;本地升级不会自动发布到 GitHub/npm。
@@ -102,32 +102,36 @@ GitHub 地址:`github:lishize20040802-rgb/dsh-deep-ptc-mode`。该地址安装
102
102
 
103
103
  ## 兼容性与维护
104
104
 
105
- 1.3.0 将上游 rc.5 的 23 项 PTC 配置保存为 `lib/preset.json`。除 persona 外,模板与该上游一致;运行时仅将两个互斥 shell 工具替换为一个带 `shell` 隔离的执行组。计划模式、压缩、裁剪、网页与子代理等其他配置保持一致。
105
+ Deep PTC 在加载时依据已安装 Harness 声明的 PTC 预设(`@deepseek-ai/dsh-web-app/presets/ptc.patch.yml`)现场组合:官方行原样继承,仅替换 persona 文本、把两个互斥 shell 工具换成一个带 `shell` 隔离的执行组、加入可达性守卫,并包装官方 job 与提问工具。包装层和执行组自身不写死任何官方模块名:加载的都是官方行里写的模块(shell 执行器取自基础部署声明 `@deepseek-ai/dsh-base/cordis.patch.yml`),并沿用官方配置。官方怎么改 PTC,本模式无需发版即可继承;官方改名或删除的模块也不会留下失效行。所选执行环境无法对应到官方行时,保留官方 shell 行并在日志中说明。只有在该声明无法解析、读取或解析失败时,才退回内置的 `lib/preset.json` 快照,并在日志中说明。
106
106
 
107
- 本版增加了必要的宿主/浏览器代码,不再是仅靠 persona 的声明式插件。`compatibility.json` 记录已验证上游和 fixture 哈希;`engines` 是安装下限,不能证明之后所有宿主都经过测试。
107
+ 官方声明通过宿主运行时解析,因此插件静态引用的宿主包都必须声明在 `peerDependencies` 中(包括 `@deepseek-ai/dsh-web-app`):对 `link:` 本地安装,宿主只有看到 peer 声明才会把这些包名路由到已安装运行时。漏声明时 `npm run check` 会失败——这正是避免本地安装静默退回快照的关键。`compatibility.json` 记录 fixture 所取自的上游版本及其哈希;`npm run check` 会验证内置回退快照与 fixture 仍组合出同一预设,并检查继承不变量。`engines` 是安装下限,不能证明之后所有宿主都经过测试,遇到新版本先用 `npm run check:upstream -- <path>` 复核。
108
108
 
109
109
  ```sh
110
110
  npm ci
111
111
  npm run check
112
112
  npm test
113
113
  npm run check:upstream -- /path/to/ptc.patch.yml
114
+ npm run sync:snapshot # 从已安装声明刷新 lib/preset.json 与 lib/base-snapshot.json 回退快照
115
+ PTC_RUNTIME_MODULES=/path/to/dsh/node_modules node scripts/check-preset.cjs # 用真实运行时检查每行模块可解析
114
116
  PTC_RUNTIME_MODULES=/path/to/dsh/node_modules node scripts/check-reachability.mjs # 用真实运行时验证可打断等待
115
117
  npm pack
116
118
  ```
117
119
 
118
- 检查器不会执行 YAML 的 `!!js`;比较官方插件结构、plan mode 和压缩等嵌套配置,发现差异即失败并要求复核。测试覆盖平台选择、命令边界、受限 WSL 拒绝、设置表单原子保存及并发版本约束,以及 preset 版本更换与清理。真实任务评测仍应记录成功率、无必要提问、范围控制、后台收尾和耗时。
120
+ 检查器把 `!!js` 当数据解析,并断言派生不变量:除 persona、shell 行与两个包装行外,官方行必须原样保留(官方把它们嵌进 group 时也同样处理);行 id 唯一;九种平台/环境组合下派生结果确定。测试同时覆盖未来可能出现的组合变化(新增未知行、调整行顺序、删除 shell 行或包装行),以及平台选择、命令边界、受限 WSL 拒绝、设置表单原子保存及并发版本约束。真实任务评测仍应记录成功率、无必要提问、范围控制、后台收尾和耗时。
119
121
 
120
122
  ## 文件和卸载
121
123
 
122
124
  - `cordis.patch.yml`:宿主设置入口。
123
125
  - `lib/index.mjs`:配置 schema、preset 注册和版本切换。
124
- - `lib/model.mjs`:平台选择、参数、隔离配置和环境说明。
125
- - `lib/executor.mjs`:复用官方进程/沙箱语义的 WSL/Zsh 执行器。
126
- - `lib/terminal.mjs`:复用官方 Bash/PowerShell 终端工具,等待可被用户消息打断,并提供 Zsh 方言与工具名。
127
- - `lib/jobs-tool.mjs`、`lib/ask-user.mjs`:官方 job 工具与提问工具的包装,等待可被用户消息打断。
126
+ - `lib/model.mjs`:平台选择、参数、隔离配置和环境说明,以及从官方声明派生 preset。
127
+ - `lib/executor.mjs`:继承基础部署声明里的官方 bash 执行器,实现 WSL/Zsh。
128
+ - `lib/terminal.mjs`:运行官方声明指定的 shell 工具,等待可被用户消息打断,并提供 Zsh 方言与工具名。
129
+ - `lib/jobs-tool.mjs`、`lib/ask-user.mjs`:运行官方声明指定的 job 工具与提问工具,等待可被用户消息打断。
130
+ - `lib/host.mjs`:通过已安装运行时解析这些官方模块。
128
131
  - `lib/guard.mjs`、`lib/rules.mjs`、`lib/sleep-lint.mjs`、`lib/reachable.mjs`:拒绝长暂停与轮询的工具守卫,以及可打断等待的实现。
129
132
  - `lib/client.js`:中英文设置卡片。
130
- - `lib/preset.json`:persona 和上游 PTC 模板。
133
+ - `lib/upstream.mjs`:定位并解析已安装的 PTC 声明。
134
+ - `lib/preset.json`:persona,以及仅在声明不可用时的回退快照。
131
135
  - `test/`、`scripts/check.mjs`、`compatibility.json`:回归与上游差异检查。
132
136
 
133
137
  卸载使用插件管理器的 `remove_bundle`,目标为 `dsh-deep-ptc-mode`。本地 link 安装直接依赖源目录,应先卸载再删除目录。
@@ -1,5 +1,6 @@
1
1
  {
2
- "verifiedUpstream": "0.2.1-rc.5",
2
+ "mode": "derived",
3
3
  "source": "@deepseek-ai/dsh-web-app/presets/ptc.patch.yml",
4
- "sha256": "9e355c947bf61c3d2fe9bf3214b386f83c0d99d37579ce22576d4b82cb6e1a2c"
4
+ "verifiedUpstream": "0.2.2-rc.1",
5
+ "snapshotSha256": "ce02148b1fd575cc93071744180468cd305bdcd50dbfdd3b9b0605c5281d283d"
5
6
  }
package/lib/ask-user.mjs CHANGED
@@ -1,13 +1,21 @@
1
- import { Config, apply as applyAskUser, inject } from '@deepseek-ai/dsh-tool-ask-user';
1
+ import z from '@deepseek-ai/schemastery';
2
2
  import { adaptContext } from './adapt.mjs';
3
+ import { applyOfficial } from './host.mjs';
3
4
  import { steerableQuestions, steeringWatch } from './reachable.mjs';
4
5
 
5
6
  export const name = 'deep-ptc-tool-ask-user';
6
- export { Config, inject };
7
+ export const inject = [];
8
+ export const Config = z.object({
9
+ // The official question tool module and its options, as the installed PTC declaration names them.
10
+ upstream: z.string().required(),
11
+ options: z.any(),
12
+ });
7
13
 
8
14
  // The official question tool. In timed mode a question the user leaves unanswered becomes pending,
9
15
  // and a message the user writes instead ends the wait early.
10
- export function apply(ctx, config) {
16
+ export async function apply(ctx, config) {
11
17
  const watch = steeringWatch(ctx);
12
- applyAskUser(adaptContext(ctx, { userQuestions: questions => steerableQuestions(questions, watch) }), config);
18
+ await applyOfficial(ctx, config.upstream, config.options, child => adaptContext(child, {
19
+ userQuestions: questions => steerableQuestions(questions, watch),
20
+ }));
13
21
  }
@@ -0,0 +1,13 @@
1
+ {
2
+ "source": "@deepseek-ai/dsh-base/cordis.patch.yml",
3
+ "verifiedUpstream": "0.2.2-rc.1",
4
+ "bash": {
5
+ "name": "@deepseek-ai/dsh-bash-sandbox",
6
+ "config": {
7
+ "timeoutMs": 60000
8
+ }
9
+ },
10
+ "pwsh": {
11
+ "name": "@deepseek-ai/dsh-pwsh-sandbox"
12
+ }
13
+ }
package/lib/executor.mjs CHANGED
@@ -1,34 +1,41 @@
1
1
  import z from '@deepseek-ai/schemastery';
2
- import { LocalBashExecutor } from '@deepseek-ai/dsh-bash-local';
3
- import { SandboxBashExecutor } from '@deepseek-ai/dsh-bash-sandbox';
2
+ import { importHost, pluginOf } from './host.mjs';
4
3
  import { assertExecutionPolicy, shellArgv } from './model.mjs';
5
4
 
6
- // Uses the host's process handles, output retention, cancellation, jobs and sandbox.
7
- export default class MappedShellExecutor extends SandboxBashExecutor {
8
- static Config = z.object({
9
- environment: z.union(['wsl', 'zsh']).required(),
10
- wslDistribution: z.string().default(''),
11
- cwd: z.string().volatile(),
12
- timeoutMs: z.number().min(1).default(120000).volatile(),
13
- maxTimeoutMs: z.number().min(1).default(600000).volatile(),
14
- maxOutputBytes: z.number().min(1).default(64000).volatile(),
15
- maxSpillBytes: z.number().min(1).default(67108864).volatile(),
16
- graceMs: z.number().min(1).default(3000).volatile(),
17
- });
5
+ export const name = 'deep-ptc-mapped-executor';
6
+ export const inject = [];
7
+ export const Config = z.object({
8
+ environment: z.union(['wsl', 'zsh']).required(),
9
+ wslDistribution: z.string().default(''),
10
+ // The official bash executor module and its options, as the installed base declaration names them.
11
+ base: z.string().required(),
12
+ options: z.any(),
13
+ });
18
14
 
19
- async execute(spec) {
20
- assertExecutionPolicy(this.config.environment, spec.sandboxPolicy);
21
- if (spec.sandboxPolicy.mode !== 'danger-full-access') return super.execute(spec);
22
- const process = await LocalBashExecutor.prototype.executeArgv.call(this, spec,
23
- shellArgv(this.config.environment, spec, this.config.wslDistribution));
24
- return SandboxBashExecutor.decorateResult(process, result => ({
25
- ...result, sandbox: { mode: spec.sandboxPolicy.mode, denied: false },
26
- }));
27
- }
15
+ // Extend the official bash executor: its process handles, output retention, cancellation, jobs,
16
+ // sandbox and Config stay official; only the argv that starts the shell changes.
17
+ export function mappedExecutor(Base, environment, distribution = '') {
18
+ return class MappedShellExecutor extends Base {
19
+ async execute(spec) {
20
+ assertExecutionPolicy(environment, spec.sandboxPolicy);
21
+ if (spec.sandboxPolicy.mode !== 'danger-full-access') return super.execute(spec);
22
+ const process = await super.executeArgv(spec, shellArgv(environment, spec, distribution));
23
+ return Base.decorateResult(process, result => ({
24
+ ...result, sandbox: { mode: spec.sandboxPolicy.mode, denied: false },
25
+ }));
26
+ }
28
27
 
29
- confine(command, policy, signal) {
30
- assertExecutionPolicy(this.config.environment, policy);
31
- return this.ctx.sandbox.confine(shellArgv(this.config.environment,
32
- { command, workdir: policy.workspaceRoot }, this.config.wslDistribution), policy, signal);
33
- }
28
+ confine(command, policy, signal) {
29
+ assertExecutionPolicy(environment, policy);
30
+ return this.ctx.sandbox.confine(shellArgv(environment,
31
+ { command, workdir: policy.workspaceRoot }, distribution), policy, signal);
32
+ }
33
+ };
34
+ }
35
+
36
+ export async function apply(ctx, config) {
37
+ const Base = pluginOf(await importHost(config.base));
38
+ if (typeof Base !== 'function' || typeof Base.decorateResult !== 'function' || typeof Base.prototype.executeArgv !== 'function')
39
+ throw new Error(`${config.base} no longer exposes the executor API Deep PTC extends; choose PowerShell or native Bash`);
40
+ ctx.plugin(mappedExecutor(Base, config.environment, config.wslDistribution), config.options);
34
41
  }
package/lib/host.mjs ADDED
@@ -0,0 +1,65 @@
1
+ // Load host modules by the names the official declarations use. Nothing here names an official tool:
2
+ // callers pass the module name read from the installed Harness, so a rename or replacement upstream
3
+ // is followed instead of breaking a hard-coded import.
4
+ import { createRequire } from 'node:module';
5
+ import { pathToFileURL } from 'node:url';
6
+ import { OFFICIAL_PACKAGE } from './upstream.mjs';
7
+
8
+ function anchor() {
9
+ try {
10
+ return import.meta.resolve(`${OFFICIAL_PACKAGE}/package.json`);
11
+ } catch {
12
+ return undefined;
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Resolve a host module the way the installed runtime would.
18
+ * A linked installation only routes peer-declared names to the runtime, so a name the official
19
+ * declaration introduces later is resolved from the runtime's own package graph instead.
20
+ * @returns a URL, or undefined when the runtime does not provide the module.
21
+ */
22
+ export function resolveHost(specifier) {
23
+ try {
24
+ return import.meta.resolve(specifier);
25
+ } catch {
26
+ // Not routed for this plugin; ask the runtime's graph.
27
+ }
28
+ const from = anchor();
29
+ if (from === undefined) return undefined;
30
+ try {
31
+ return pathToFileURL(createRequire(from).resolve(specifier)).href;
32
+ } catch {
33
+ return undefined;
34
+ }
35
+ }
36
+
37
+ export async function importHost(specifier) {
38
+ const url = resolveHost(specifier);
39
+ if (url === undefined) throw new Error(`the installed Harness provides no module ${JSON.stringify(specifier)}`);
40
+ return import(url);
41
+ }
42
+
43
+ // The Cordis plugin a module exports: the namespace itself, or its default export.
44
+ export function pluginOf(namespace) {
45
+ if (typeof namespace?.apply === 'function') return namespace;
46
+ return namespace?.default ?? namespace;
47
+ }
48
+
49
+ /**
50
+ * Start the official plugin `upstream` with its own inject list and Config, giving its apply an
51
+ * adapted context. A plugin of another shape is started unadapted, so the official behaviour stays.
52
+ */
53
+ export async function applyOfficial(ctx, upstream, options, adapt) {
54
+ const plugin = pluginOf(await importHost(upstream));
55
+ if (typeof plugin?.apply !== 'function') {
56
+ ctx.logger.warn('Deep PTC: %s is not an apply-style plugin; loading it without Deep PTC wait handling', upstream);
57
+ return ctx.plugin(plugin, options);
58
+ }
59
+ return ctx.plugin({
60
+ name: plugin.name ?? upstream,
61
+ ...plugin.inject === undefined ? {} : { inject: plugin.inject },
62
+ ...plugin.Config === undefined ? {} : { Config: plugin.Config },
63
+ apply: (child, config) => plugin.apply(adapt(child), config),
64
+ }, options);
65
+ }
package/lib/index.mjs CHANGED
@@ -1,6 +1,10 @@
1
1
  import z from '@deepseek-ai/schemastery';
2
- import template from './preset.json' with { type: 'json' };
3
- import { availableEnvironments, configuredPreset, DEFAULT_FOREGROUND_SECONDS, normalizeDistribution } from './model.mjs';
2
+ import snapshot from './preset.json' with { type: 'json' };
3
+ import { readFileSync } from 'node:fs';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { availableEnvironments, BASE_SNAPSHOT, DEFAULT_FOREGROUND_SECONDS, deriveDeepPtc, normalizeDistribution, resolveEnvironment } from './model.mjs';
6
+ import { BASE_DECLARATION_SPECIFIER, loadOfficialPreset, parseOfficialExecutors } from './upstream.mjs';
7
+ import { importHost, pluginOf, resolveHost } from './host.mjs';
4
8
  import { presetLifecycle } from './lifecycle.mjs';
5
9
 
6
10
  export const name = 'deep-ptc-settings';
@@ -12,14 +16,81 @@ export const Config = z.object({
12
16
  hostPlatform: z.const(process.platform).default(process.platform).volatile(),
13
17
  });
14
18
 
19
+ function settingsOf(config) {
20
+ return {
21
+ environment: config.environment.get(),
22
+ wslDistribution: normalizeDistribution(config.wslDistribution.get()),
23
+ foregroundSeconds: config.foregroundSeconds.get(),
24
+ };
25
+ }
26
+
27
+ // The shell executors the installed Harness declares in its base deployment, by kind.
28
+ function officialExecutors(ctx) {
29
+ try {
30
+ const url = resolveHost(BASE_DECLARATION_SPECIFIER);
31
+ if (url === undefined) throw new Error(`cannot resolve ${BASE_DECLARATION_SPECIFIER}`);
32
+ const executors = parseOfficialExecutors(readFileSync(fileURLToPath(url), 'utf8'));
33
+ for (const kind of ['bash', 'pwsh']) if (executors[kind] === undefined)
34
+ ctx.logger.warn('Deep PTC: %s declares no %s executor; using the bundled snapshot entry', url, kind);
35
+ return { ...BASE_SNAPSHOT, ...executors };
36
+ } catch (error) {
37
+ ctx.logger.warn('Deep PTC: official executors unavailable (%s); using the bundled snapshot', error.message);
38
+ return BASE_SNAPSHOT;
39
+ }
40
+ }
41
+
42
+ // WSL and Zsh extend the official bash executor class. Probe it before choosing that path so an
43
+ // incompatible Harness falls back to the official shell rows instead of a preset that cannot mount.
44
+ async function canExtend(ctx, executor) {
45
+ try {
46
+ const Base = pluginOf(await importHost(executor.name));
47
+ if (typeof Base === 'function' && typeof Base.decorateResult === 'function'
48
+ && typeof Base.prototype.executeArgv === 'function') return true;
49
+ ctx.logger.warn('Deep PTC: %s no longer exposes the executor API WSL/Zsh extend', executor.name);
50
+ } catch (error) {
51
+ ctx.logger.warn('Deep PTC: cannot load %s (%s)', executor.name, error.message);
52
+ }
53
+ return false;
54
+ }
55
+
56
+ // Derive Deep PTC from the PTC preset the installed Harness declares, so an
57
+ // official change is inherited instead of leaving a stale frozen row behind.
58
+ // The bundled snapshot is only a fallback when the installed declaration
59
+ // cannot be read or cannot be composed.
60
+ async function buildPreset(ctx, config) {
61
+ const settings = settingsOf(config);
62
+ const executors = officialExecutors(ctx);
63
+ const environment = resolveEnvironment(settings.environment);
64
+ if (environment === 'wsl' || environment === 'zsh') settings.mappedExecutor = await canExtend(ctx, executors.bash);
65
+ settings.executors = executors;
66
+ let upstream = snapshot;
67
+ let source = 'bundled snapshot';
68
+ try {
69
+ const official = loadOfficialPreset();
70
+ upstream = official.preset;
71
+ source = official.source;
72
+ } catch (error) {
73
+ ctx.logger.warn('Deep PTC: official PTC preset unavailable (%s); deriving from the bundled snapshot', error.message);
74
+ }
75
+ try {
76
+ const { preset, report } = deriveDeepPtc(upstream, settings);
77
+ ctx.logger.info(
78
+ 'Deep PTC preset derived from %s: %d official rows; persona %s; environment %s; shell rows [%s]; wrapped [%s]; skipped [%s]',
79
+ source, report.upstreamRows, report.persona, report.environment,
80
+ report.replacedShellRows.join('; ') || '-', report.wrapped.join(', ') || '-', report.skipped.join('; ') || '-',
81
+ );
82
+ return preset;
83
+ } catch (error) {
84
+ if (upstream === snapshot) throw error;
85
+ ctx.logger.warn('Deep PTC: deriving from %s failed (%s); deriving from the bundled snapshot', source, error.message);
86
+ return deriveDeepPtc(snapshot, settings).preset;
87
+ }
88
+ }
89
+
15
90
  export async function apply(ctx, config) {
16
91
  const lifecycle = presetLifecycle(
17
92
  definition => ctx.agentPresets.register(definition),
18
- () => configuredPreset(template, {
19
- environment: config.environment.get(),
20
- wslDistribution: normalizeDistribution(config.wslDistribution.get()),
21
- foregroundSeconds: config.foregroundSeconds.get(),
22
- }),
93
+ () => buildPreset(ctx, config),
23
94
  error => ctx.logger.error('Deep PTC environment update failed: %s', error.message),
24
95
  );
25
96
  ctx.effect(() => () => lifecycle.dispose());
@@ -27,5 +98,7 @@ export async function apply(ctx, config) {
27
98
  ctx.inject(['settings'], child => {
28
99
  child.effect(() => child.settings.configure({ auto: false }, ctx.fiber));
29
100
  });
30
- await lifecycle.refresh();
101
+ // A failure to publish the preset is reported above; it must not take the
102
+ // settings service (or the rest of the profile) down with it.
103
+ await lifecycle.refresh().catch(() => {});
31
104
  }
package/lib/jobs-tool.mjs CHANGED
@@ -1,15 +1,21 @@
1
- import { Config, apply as applyJobs, inject } from '@deepseek-ai/dsh-tool-jobs';
1
+ import z from '@deepseek-ai/schemastery';
2
2
  import { adaptContext, registering } from './adapt.mjs';
3
+ import { applyOfficial } from './host.mjs';
3
4
  import { steerableJobs, steerableTool, steeringWatch } from './reachable.mjs';
4
5
 
5
6
  export const name = 'deep-ptc-tool-jobs';
6
- export { Config, inject };
7
+ export const inject = [];
8
+ export const Config = z.object({
9
+ // The official job tool module and its options, as the installed PTC declaration names them.
10
+ upstream: z.string().required(),
11
+ options: z.any(),
12
+ });
7
13
 
8
14
  // The official job tools, with job_output waits ending when the user sends a message.
9
- export function apply(ctx, config) {
15
+ export async function apply(ctx, config) {
10
16
  const watch = steeringWatch(ctx);
11
- applyJobs(adaptContext(ctx, {
17
+ await applyOfficial(ctx, config.upstream, config.options, child => adaptContext(child, {
12
18
  tools: tools => registering(tools, definition => definition.name === 'job_output' ? steerableTool(definition) : definition),
13
19
  jobs: jobs => steerableJobs(jobs, watch),
14
- }), config);
20
+ }));
15
21
  }
package/lib/lifecycle.mjs CHANGED
@@ -6,7 +6,7 @@ export function presetLifecycle(register, getDefinition, onError) {
6
6
  const refresh = () => {
7
7
  queue = queue.then(async () => {
8
8
  if (disposed) return;
9
- const definition = getDefinition(); // Validate before removing the last good definition.
9
+ const definition = await getDefinition(); // Validate before removing the last good definition.
10
10
  await unregister?.();
11
11
  unregister = undefined;
12
12
  if (disposed) return;
package/lib/model.mjs CHANGED
@@ -1,3 +1,14 @@
1
+ // Compose the Deep PTC agent preset from the official PTC preset that the
2
+ // installed Harness ships, replacing only the rows this plugin owns.
3
+ //
4
+ // The official declaration is the source of truth: rows it adds, renames or
5
+ // reconfigures are inherited as-is. Deep PTC then swaps in its persona, its
6
+ // selectable execution environment, its reachability guard, and wrappers for
7
+ // the official job and question tools. A change on the official side therefore
8
+ // never leaves a stale module name behind.
9
+ import snapshot from './preset.json' with { type: 'json' };
10
+ import baseSnapshot from './base-snapshot.json' with { type: 'json' };
11
+
1
12
  export const ENVIRONMENTS = ['auto', 'wsl', 'powershell', 'zsh', 'bash'];
2
13
 
3
14
  export function availableEnvironments(platform) {
@@ -58,53 +69,245 @@ export function normalizeForegroundSeconds(value = DEFAULT_FOREGROUND_SECONDS) {
58
69
  return value;
59
70
  }
60
71
 
61
- // Official rows Deep PTC replaces with wrappers of the same package, by row id.
72
+ /**
73
+ * Lookup hints for the official rows Deep PTC replaces with its execution group. Hints only find
74
+ * rows; the modules Deep PTC loads are always the ones the official rows (or the base declaration)
75
+ * name, so a renamed or replaced official module is followed rather than hard-coded.
76
+ */
77
+ export const SHELL_TOOLS = {
78
+ bash: { ids: ['tool-bash'], names: ['@deepseek-ai/dsh-tool-bash'] },
79
+ pwsh: { ids: ['tool-pwsh'], names: ['@deepseek-ai/dsh-tool-pwsh'] },
80
+ };
81
+ const SHELL_EXECUTOR_NAMES = [
82
+ '@deepseek-ai/dsh-bash-local',
83
+ '@deepseek-ai/dsh-bash-sandbox',
84
+ '@deepseek-ai/dsh-pwsh-local',
85
+ '@deepseek-ai/dsh-pwsh-sandbox',
86
+ ];
87
+ export const SHELL_ROWS = {
88
+ ids: [...SHELL_TOOLS.bash.ids, ...SHELL_TOOLS.pwsh.ids],
89
+ names: [...SHELL_TOOLS.bash.names, ...SHELL_TOOLS.pwsh.names, ...SHELL_EXECUTOR_NAMES],
90
+ };
91
+
92
+ /** Lookup hints for the official rows Deep PTC keeps but wraps, keyed by row id. */
62
93
  export const WRAPPED_ROWS = {
63
94
  'tool-jobs': '@deepseek-ai/dsh-tool-jobs',
64
95
  'tool-ask-user': '@deepseek-ai/dsh-tool-ask-user',
65
96
  };
66
97
 
67
- export function configuredPreset(template, options, platform = process.platform) {
98
+ /** Fallback executor declaration, used only when the installed base declaration cannot be read. */
99
+ export const BASE_SNAPSHOT = baseSnapshot;
100
+
101
+ const PERSONA_ROW = { ids: ['persona'], names: ['@deepseek-ai/dsh-persona'] };
102
+ const WRAP_TARGETS = [
103
+ {
104
+ key: 'tool-jobs',
105
+ replacement: 'dsh-deep-ptc-mode/jobs-tool',
106
+ options: milliseconds => ({ waitTimeoutMs: milliseconds, maxWaitTimeoutMs: milliseconds }),
107
+ },
108
+ {
109
+ key: 'tool-ask-user',
110
+ replacement: 'dsh-deep-ptc-mode/ask-user',
111
+ options: () => ({ mode: 'timed', timeout: QUESTION_SECONDS }),
112
+ },
113
+ ];
114
+
115
+ /** Identity and display text Deep PTC publishes, independent of the official preset. */
116
+ export const PRESET_META = {
117
+ id: 'deep-ptc',
118
+ name: typeof snapshot.name === 'string' && snapshot.name.length > 0 ? snapshot.name : '深度PTC模式',
119
+ order: typeof snapshot.order === 'number' ? snapshot.order : 5,
120
+ description: typeof snapshot.description === 'string' ? snapshot.description : '',
121
+ };
122
+
123
+ /** Persona text owned by this plugin, read from the bundled snapshot. */
124
+ export function personaFrom(template = snapshot) {
125
+ const rows = Array.isArray(template?.plugins) ? template.plugins : [];
126
+ const row = findRow(rows, PERSONA_ROW);
127
+ const config = row?.config;
128
+ if (!config || typeof config.prefix !== 'string' || typeof config.suffix !== 'string') {
129
+ throw new Error('bundled snapshot carries no Deep PTC persona');
130
+ }
131
+ return { prefix: config.prefix, suffix: config.suffix };
132
+ }
133
+
134
+ /** Visit every row depth-first, including rows nested in group configurations. */
135
+ export function walkRows(rows, visit) {
136
+ if (!Array.isArray(rows)) return;
137
+ for (let index = 0; index < rows.length; index += 1) {
138
+ const row = rows[index];
139
+ if (!row || typeof row !== 'object') continue;
140
+ visit(row, rows, index);
141
+ if (row.group === true && Array.isArray(row.config)) walkRows(row.config, visit);
142
+ }
143
+ }
144
+
145
+ /** Whether a row is one of the official shell/executor rows Deep PTC replaces. */
146
+ export function isShellRow(row) {
147
+ return row.group !== true && (SHELL_ROWS.names.includes(row.name) || SHELL_ROWS.ids.includes(row.id));
148
+ }
149
+
150
+ function findRow(rows, { ids = [], names = [] }) {
151
+ let found;
152
+ walkRows(rows, row => {
153
+ if (found !== undefined) return;
154
+ if (names.includes(row.name) || ids.includes(row.id)) found = row;
155
+ });
156
+ return found;
157
+ }
158
+
159
+ function rowIds(plugins, into = new Set()) {
160
+ walkRows(plugins, row => {
161
+ if (typeof row.id === 'string') into.add(row.id);
162
+ });
163
+ return into;
164
+ }
165
+
166
+ function uniqueRowId(plugins, preferred) {
167
+ const taken = rowIds(plugins);
168
+ if (!taken.has(preferred)) return preferred;
169
+ for (let suffix = 2; ; suffix += 1) {
170
+ const candidate = `${preferred}-${suffix}`;
171
+ if (!taken.has(candidate)) return candidate;
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Compose the Deep PTC preset from an official PTC declaration.
177
+ * @param upstream - Official preset configuration (`{ id, order, plugins }`).
178
+ * @param options - `environment`, `wslDistribution`, `foregroundSeconds`.
179
+ * @param platform - Host platform whose environment choices apply.
180
+ * @returns The Deep PTC preset plus a report of what was replaced, wrapped or skipped.
181
+ */
182
+ export function deriveDeepPtc(upstream, options = {}, platform = process.platform) {
183
+ if (!upstream || !Array.isArray(upstream.plugins) || upstream.plugins.length === 0) {
184
+ throw new Error('official PTC preset carries no plugin rows');
185
+ }
186
+ for (const row of upstream.plugins) {
187
+ if (!row || typeof row !== 'object' || typeof row.name !== 'string') {
188
+ throw new Error('official PTC preset has a malformed plugin row');
189
+ }
190
+ }
191
+
68
192
  const environment = resolveEnvironment(options.environment, platform);
69
193
  const distribution = normalizeDistribution(options.wslDistribution);
70
194
  const foregroundSeconds = normalizeForegroundSeconds(options.foregroundSeconds);
71
195
  const foregroundMs = foregroundSeconds * 1000;
72
- const preset = structuredClone(template);
73
- const first = preset.plugins.findIndex(row => row.id === 'tool-bash');
74
- if (first < 0 || preset.plugins[first + 1]?.id !== 'tool-pwsh') throw new Error('Upstream shell layout changed; review compatibility before loading');
75
- for (const [id, upstream] of Object.entries(WRAPPED_ROWS)) {
76
- const row = preset.plugins.find(candidate => candidate.id === id);
77
- if (row?.name !== upstream || row.config !== undefined) throw new Error(`Upstream ${id} row changed; review compatibility before loading`);
196
+ const plugins = structuredClone(upstream.plugins);
197
+ const report = {
198
+ upstreamId: typeof upstream.id === 'string' ? upstream.id : null,
199
+ upstreamRows: plugins.length,
200
+ persona: 'missing',
201
+ replacedShellRows: [],
202
+ wrapped: [],
203
+ skipped: [],
204
+ };
205
+
206
+ // Persona: keep the row and any official fields, replace only the text.
207
+ const personaText = personaFrom();
208
+ const persona = findRow(plugins, PERSONA_ROW);
209
+ if (persona === undefined) {
210
+ plugins.unshift({ id: uniqueRowId(plugins, 'persona'), name: '@deepseek-ai/dsh-persona', config: { ...personaText } });
211
+ report.persona = 'inserted';
212
+ } else {
213
+ persona.config = { ...(persona.config ?? {}), ...personaText };
214
+ report.persona = 'replaced';
215
+ }
216
+
217
+ // Execution environment: replace the official shell rows (wherever the official preset nests them)
218
+ // with the selectable execution group in the same place. The group runs the official shell tool
219
+ // and executor the installed Harness names; when they cannot be mapped, the official rows stay.
220
+ const kind = environment === 'powershell' ? 'pwsh' : 'bash';
221
+ const executors = { ...BASE_SNAPSHOT, ...(options.executors ?? {}) };
222
+ const tool = findRow(plugins, SHELL_TOOLS[kind]);
223
+ const official = executors[kind];
224
+ const mapped = environment === 'wsl' || environment === 'zsh';
225
+ const unusable = tool === undefined ? `the official PTC preset has no ${kind} tool row`
226
+ : typeof official?.name !== 'string' ? `the installed Harness declares no ${kind} executor`
227
+ : mapped && options.mappedExecutor === false ? `the official bash executor cannot be extended for ${environment}`
228
+ : undefined;
229
+ report.environment = unusable === undefined ? environment : 'official';
230
+ let anchorSiblings = plugins;
231
+ let anchorIndex;
232
+ const rows = [];
233
+ if (unusable !== undefined) {
234
+ report.skipped.push(`execution environment ${environment} (${unusable}; official shell rows kept)`);
235
+ const topLevelPersona = plugins.findIndex(row => row && row.group !== true
236
+ && (PERSONA_ROW.names.includes(row.name) || PERSONA_ROW.ids.includes(row.id)));
237
+ anchorIndex = topLevelPersona + 1;
238
+ } else {
239
+ const removed = [];
240
+ walkRows(plugins, (row, siblings, index) => {
241
+ if (isShellRow(row)) removed.push({ row, siblings, index });
242
+ });
243
+ report.replacedShellRows = removed.map(({ row }) => `${row.id ?? '?'} (${row.name})`);
244
+ anchorSiblings = removed[0].siblings;
245
+ const bySiblings = new Map();
246
+ for (const { siblings, index } of removed) {
247
+ if (!bySiblings.has(siblings)) bySiblings.set(siblings, []);
248
+ bySiblings.get(siblings).push(index);
249
+ }
250
+ anchorIndex = Math.min(...bySiblings.get(anchorSiblings));
251
+ for (const [siblings, indexes] of bySiblings) {
252
+ for (const index of [...indexes].sort((left, right) => right - left)) siblings.splice(index, 1);
253
+ }
254
+ // With background jobs available, the executor timeout only decides when a foreground command
255
+ // moves to the background; the official tools run such commands with onExpiry: none.
256
+ const executorOptions = { ...(official.config ?? {}), timeoutMs: foregroundMs, maxTimeoutMs: foregroundMs };
257
+ const executor = mapped
258
+ ? { id: 'executor', name: 'dsh-deep-ptc-mode/executor',
259
+ config: { environment, wslDistribution: distribution, base: official.name, options: executorOptions } }
260
+ : { id: 'executor', name: official.name, config: executorOptions };
261
+ const terminal = {
262
+ id: environment === 'zsh' ? 'tool-zsh' : tool.id ?? `tool-${kind}`,
263
+ name: 'dsh-deep-ptc-mode/terminal',
264
+ config: {
265
+ upstream: tool.name,
266
+ ...tool.config === undefined ? {} : { options: tool.config },
267
+ ...environment === 'zsh' ? { dialect: 'zsh' } : {},
268
+ },
269
+ };
270
+ rows.push({
271
+ id: uniqueRowId(plugins, 'execution'), name: 'cordis:group', group: true, isolate: { shell: true },
272
+ config: [executor, terminal, { id: 'execution-instructions', name: 'dsh-deep-ptc-mode/environment',
273
+ config: { environment, wslDistribution: distribution } }],
274
+ });
78
275
  }
79
- // With background jobs available, the executor timeout only decides when a foreground command moves
80
- // to the background; the official tools run such commands with onExpiry: none.
81
- const executor = {
82
- id: 'executor',
83
- name: environment === 'powershell' ? '@deepseek-ai/dsh-pwsh-sandbox'
84
- : environment === 'bash' ? '@deepseek-ai/dsh-bash-sandbox' : 'dsh-deep-ptc-mode/executor',
85
- config: {
86
- ...(environment === 'wsl' || environment === 'zsh' ? { environment, wslDistribution: distribution } : {}),
87
- timeoutMs: foregroundMs, maxTimeoutMs: foregroundMs,
276
+ rows.push({
277
+ id: uniqueRowId([...plugins, ...rows], 'reachability'),
278
+ name: 'dsh-deep-ptc-mode/guard', config: { foregroundSeconds },
279
+ });
280
+ anchorSiblings.splice(anchorIndex, 0, ...rows);
281
+
282
+ // Wrapped tools: the wrapper loads the module the official row names, with the official options
283
+ // plus the Deep PTC wait behaviour.
284
+ for (const target of WRAP_TARGETS) {
285
+ const row = findRow(plugins, { ids: [target.key], names: [WRAPPED_ROWS[target.key]] });
286
+ if (row === undefined) {
287
+ report.skipped.push(`${target.key} (no official row)`);
288
+ continue;
289
+ }
290
+ const upstreamName = row.name;
291
+ row.name = target.replacement;
292
+ row.config = { upstream: upstreamName, options: { ...(row.config ?? {}), ...target.options(foregroundMs) } };
293
+ report.wrapped.push(`${target.key} (${upstreamName})`);
294
+ }
295
+
296
+ const description = `${PRESET_META.description} 当前环境:${environment}${environment === 'wsl' && distribution ? ` (${distribution})` : ''}`;
297
+ return {
298
+ preset: {
299
+ ...upstream,
300
+ id: PRESET_META.id,
301
+ name: PRESET_META.name,
302
+ order: PRESET_META.order,
303
+ description,
304
+ plugins,
88
305
  },
306
+ report,
89
307
  };
90
- const terminal = {
91
- id: environment === 'zsh' ? 'tool-zsh' : environment === 'powershell' ? 'tool-pwsh' : 'tool-bash',
92
- name: 'dsh-deep-ptc-mode/terminal',
93
- config: { tool: environment === 'powershell' ? 'pwsh' : 'bash', ...(environment === 'zsh' ? { dialect: 'zsh' } : {}) },
94
- };
95
- preset.plugins.splice(first, 2, {
96
- id: 'execution', name: 'cordis:group', group: true, isolate: { shell: true },
97
- config: [executor, terminal, { id: 'execution-instructions', name: 'dsh-deep-ptc-mode/environment',
98
- config: { environment, wslDistribution: distribution } }],
99
- }, {
100
- id: 'reachability', name: 'dsh-deep-ptc-mode/guard', config: { foregroundSeconds },
101
- });
102
- Object.assign(preset.plugins.find(row => row.id === 'tool-jobs'), {
103
- name: 'dsh-deep-ptc-mode/jobs-tool', config: { waitTimeoutMs: foregroundMs, maxWaitTimeoutMs: foregroundMs },
104
- });
105
- Object.assign(preset.plugins.find(row => row.id === 'tool-ask-user'), {
106
- name: 'dsh-deep-ptc-mode/ask-user', config: { mode: 'timed', timeout: QUESTION_SECONDS },
107
- });
108
- preset.description = `${template.description} 当前环境:${environment}${environment === 'wsl' && distribution ? ` (${distribution})` : ''}`;
109
- return preset;
308
+ }
309
+
310
+ /** Backwards-compatible helper: the derived preset without the report. */
311
+ export function configuredPreset(template, options, platform = process.platform) {
312
+ return deriveDeepPtc(template, options, platform).preset;
110
313
  }
package/lib/preset.json CHANGED
@@ -37,7 +37,10 @@
37
37
  },
38
38
  {
39
39
  "id": "tool-fs",
40
- "name": "@deepseek-ai/dsh-tool-fs"
40
+ "name": "@deepseek-ai/dsh-tool-fs",
41
+ "config": {
42
+ "applyPatch": false
43
+ }
41
44
  },
42
45
  {
43
46
  "id": "tool-fs-search",
@@ -127,17 +130,14 @@
127
130
  "id": "tool-subagent-control",
128
131
  "name": "@deepseek-ai/dsh-tool-subagent-control"
129
132
  },
130
- {
131
- "id": "tool-subagent-list-agents",
132
- "name": "@deepseek-ai/dsh-tool-subagent-control/list-agents"
133
- },
134
133
  {
135
134
  "id": "tool-subagent",
136
135
  "name": "@deepseek-ai/dsh-tool-subagent",
137
136
  "config": {
138
137
  "provider": "spawn",
139
138
  "toolName": "subagent",
140
- "modelSelectionSettings": true
139
+ "modelSelection": true,
140
+ "modelDiscovery": true
141
141
  }
142
142
  },
143
143
  {
@@ -183,11 +183,8 @@
183
183
  }
184
184
  },
185
185
  {
186
- "id": "tool-presentation",
187
- "name": "@deepseek-ai/dsh-agent-tool-presentation",
188
- "config": {
189
- "mode": "ptc"
190
- }
186
+ "id": "tool-executor-ptc",
187
+ "name": "@deepseek-ai/dsh-tool-executor-ptc"
191
188
  },
192
189
  {
193
190
  "id": "present",
package/lib/terminal.mjs CHANGED
@@ -1,23 +1,24 @@
1
1
  import z from '@deepseek-ai/schemastery';
2
- import { apply as applyBash } from '@deepseek-ai/dsh-tool-bash';
3
- import { apply as applyPwsh } from '@deepseek-ai/dsh-tool-pwsh';
4
2
  import { adaptContext, registering } from './adapt.mjs';
3
+ import { applyOfficial } from './host.mjs';
5
4
  import { finishPromoted, steerableJobs, steerableTool, steeringWatch } from './reachable.mjs';
6
5
 
7
6
  export const name = 'deep-ptc-terminal';
8
- export const inject = ['tools', 'shell', 'systemPrompt', 'shellEnv', 'workingDirectory'];
7
+ export const inject = [];
9
8
  export const Config = z.object({
10
- tool: z.union(['bash', 'pwsh']).required(),
9
+ // The official shell tool module and its options, as the installed PTC declaration names them.
10
+ upstream: z.string().required(),
11
+ options: z.any(),
11
12
  dialect: z.union(['zsh']),
12
13
  });
13
14
 
14
- // Keep the official execution, jobs and approval implementation. Foreground waits yield to user
15
- // messages; the Zsh dialect only renames the bash tool's public face.
16
- export function apply(ctx, config) {
15
+ // Run the official shell tool with its own execution, jobs and approval implementation. Foreground
16
+ // waits yield to user messages; the Zsh dialect only renames the tool's public face.
17
+ export async function apply(ctx, config) {
17
18
  const watch = steeringWatch(ctx);
18
19
  const zsh = config.dialect === 'zsh';
19
20
  const dialect = text => zsh ? text.replace(/\bbash\b/gu, 'zsh').replace(/\bBash\b/gu, 'Zsh') : text;
20
- const adapted = adaptContext(ctx, {
21
+ await applyOfficial(ctx, config.upstream, config.options, child => adaptContext(child, {
21
22
  tools: tools => registering(tools, definition => steerableTool({
22
23
  ...definition,
23
24
  ...zsh ? { name: definition.name === 'bash' ? 'zsh' : definition.name, description: dialect(definition.description) } : {},
@@ -31,6 +32,5 @@ export function apply(ctx, config) {
31
32
  },
32
33
  }) : prompt,
33
34
  jobs: jobs => steerableJobs(jobs, watch),
34
- });
35
- (config.tool === 'pwsh' ? applyPwsh : applyBash)(adapted, {});
35
+ }));
36
36
  }
@@ -0,0 +1,198 @@
1
+ // Locate and parse the official PTC agent preset the installed dsh ships.
2
+ //
3
+ // Deep PTC derives its own preset from this declaration instead of freezing a
4
+ // copy: rows the official preset gains, renames or reconfigures are inherited,
5
+ // and the plugin only replaces the parts it actually owns (persona, execution
6
+ // environment, reachability guard, job/question wrappers).
7
+ import { createRequire } from 'node:module';
8
+ import { existsSync, readFileSync } from 'node:fs';
9
+ import { fileURLToPath, pathToFileURL } from 'node:url';
10
+ import { dirname, join, isAbsolute, resolve } from 'node:path';
11
+
12
+ export const OFFICIAL_PACKAGE = '@deepseek-ai/dsh-web-app';
13
+ const PACKAGE = OFFICIAL_PACKAGE;
14
+ const PRESET_PATH = 'presets/ptc.patch.yml';
15
+ /** Preset identity the plugin composes from. */
16
+ export const OFFICIAL_PRESET_ID = 'ptc';
17
+ /** Module specifier of the shipped declaration, resolvable through the host's runtime resolution. */
18
+ export const OFFICIAL_PRESET_SPECIFIER = `${PACKAGE}/${PRESET_PATH}`;
19
+ /** Diagnostics-only override, e.g. a snapshot path or a file URL. */
20
+ export const PRESET_PATH_ENV = 'DSH_DEEP_PTC_PRESET';
21
+
22
+ // The declaration is YAML, so the plugin needs js-yaml. In the desktop host
23
+ // the parser belongs to the installed runtime: load it through the runtime's
24
+ // module graph so a linked installation keeps working without its own
25
+ // node_modules. Peer-declaring the package (see package.json) is what lets the
26
+ // host route this bare specifier to the installation; the remaining strategies
27
+ // also cover a plain repository run and non-flat installs.
28
+ let yamlModule;
29
+ let yamlFailure;
30
+ function loadYaml() {
31
+ if (yamlModule !== undefined) return yamlModule;
32
+ try {
33
+ yamlModule = createRequire(import.meta.url)('js-yaml');
34
+ return yamlModule;
35
+ } catch (error) {
36
+ yamlFailure = error;
37
+ }
38
+ let packageFile;
39
+ try {
40
+ packageFile = fileURLToPath(import.meta.resolve(`${PACKAGE}/package.json`));
41
+ } catch (error) {
42
+ throw yamlFailure ?? error;
43
+ }
44
+ try {
45
+ yamlModule = createRequire(packageFile)('js-yaml');
46
+ return yamlModule;
47
+ } catch {
48
+ // The parser may be hoisted beside the runtime package instead.
49
+ }
50
+ let directory = dirname(packageFile);
51
+ while (true) {
52
+ const candidate = join(directory, 'node_modules', 'js-yaml', 'package.json');
53
+ if (existsSync(candidate)) {
54
+ yamlModule = createRequire(join(directory, 'node_modules', 'package.json'))('js-yaml');
55
+ return yamlModule;
56
+ }
57
+ const parent = dirname(directory);
58
+ if (parent === directory) break;
59
+ directory = parent;
60
+ }
61
+ throw yamlFailure;
62
+ }
63
+
64
+ /** YAML dialect of the Loader: `!!js` scalars stay expression nodes for the host to evaluate. */
65
+ export function presetSchema() {
66
+ const yaml = loadYaml();
67
+ const JsExpr = new yaml.Type('tag:yaml.org,2002:js', {
68
+ kind: 'scalar',
69
+ resolve: data => typeof data === 'string',
70
+ construct: data => ({ __jsExpr: data }),
71
+ });
72
+ return yaml.JSON_SCHEMA.extend(JsExpr);
73
+ }
74
+
75
+ /**
76
+ * Read the `ptc` agent-preset declaration out of a PTC patch document.
77
+ *
78
+ * The document is a list of patch layers; the declaration lives in an `insert`
79
+ * list. Future revisions may move it, so every layer is inspected, but only a
80
+ * declaration explicitly identified as `ptc` is accepted: composing Deep PTC
81
+ * from an unrelated preset would be worse than reporting the declaration
82
+ * missing.
83
+ * @param text - YAML source of the official PTC preset patch.
84
+ * @returns Parsed preset configuration (`{ id, order, plugins, ... }`).
85
+ */
86
+ export function parseOfficialPreset(text) {
87
+ const document = loadYaml().load(text, { schema: presetSchema() });
88
+ const layers = Array.isArray(document) ? document : [];
89
+ const inserted = [];
90
+ const collect = rows => {
91
+ if (!Array.isArray(rows)) return;
92
+ for (const row of rows) if (row && typeof row === 'object') inserted.push(row);
93
+ };
94
+ collect(layers);
95
+ for (const layer of layers) {
96
+ if (!layer || typeof layer !== 'object') continue;
97
+ collect(layer.insert);
98
+ }
99
+ const declarations = inserted
100
+ .map(row => row.config)
101
+ .filter(config => config && Array.isArray(config.plugins));
102
+ const preset = declarations.find(config => config.id === OFFICIAL_PRESET_ID);
103
+ if (!preset) {
104
+ const found = declarations.map(config => JSON.stringify(config.id ?? null)).join(', ');
105
+ throw new Error(`${OFFICIAL_PRESET_SPECIFIER} declares no agent preset with id "${OFFICIAL_PRESET_ID}"${found ? ` (found ${found})` : ''}`);
106
+ }
107
+ return preset;
108
+ }
109
+
110
+ /** Base deployment declaration that names the shell executors the Harness ships. */
111
+ export const BASE_DECLARATION_SPECIFIER = '@deepseek-ai/dsh-base/cordis.patch.yml';
112
+ const EXECUTOR_ROW_IDS = { bash: 'bash-sandbox', pwsh: 'pwsh-sandbox' };
113
+
114
+ /**
115
+ * Read the official bash and PowerShell executor rows out of the base deployment declaration.
116
+ * @param text - YAML source of `@deepseek-ai/dsh-base/cordis.patch.yml`.
117
+ * @returns `{ bash?, pwsh? }`, each `{ name, config? }` as the declaration states it.
118
+ */
119
+ export function parseOfficialExecutors(text) {
120
+ const document = loadYaml().load(text, { schema: presetSchema() });
121
+ const found = {};
122
+ const visit = rows => {
123
+ if (!Array.isArray(rows)) return;
124
+ for (const row of rows) {
125
+ if (!row || typeof row !== 'object') continue;
126
+ for (const [kind, id] of Object.entries(EXECUTOR_ROW_IDS)) {
127
+ if (row.id !== id || typeof row.name !== 'string' || found[kind] !== undefined) continue;
128
+ const config = row.config && typeof row.config === 'object' && !Array.isArray(row.config) ? row.config : undefined;
129
+ found[kind] = { name: row.name, ...config === undefined ? {} : { config } };
130
+ }
131
+ visit(row.insert);
132
+ if (Array.isArray(row.config)) visit(row.config);
133
+ }
134
+ };
135
+ visit(Array.isArray(document) ? document : []);
136
+ return found;
137
+ }
138
+
139
+ function tryResolve(specifier) {
140
+ try {
141
+ return import.meta.resolve(specifier);
142
+ } catch {
143
+ return undefined;
144
+ }
145
+ }
146
+
147
+ function packageFileUrl() {
148
+ const direct = tryResolve(OFFICIAL_PRESET_SPECIFIER);
149
+ if (direct !== undefined) return direct;
150
+ for (const specifier of [`${PACKAGE}/package.json`, PACKAGE]) {
151
+ const url = tryResolve(specifier);
152
+ if (url === undefined) continue;
153
+ try {
154
+ const file = fileURLToPath(url);
155
+ if (file.endsWith('package.json')) return pathToFileURL(join(dirname(file), PRESET_PATH)).href;
156
+ // A package-root export may point at any file; the declaration sits beside the package.
157
+ let dir = dirname(file);
158
+ while (dir !== dirname(dir)) {
159
+ if (dir.endsWith(PACKAGE) || dir.endsWith(PACKAGE.replace('/', '-'))) break;
160
+ dir = dirname(dir);
161
+ }
162
+ return pathToFileURL(join(dir, PRESET_PATH)).href;
163
+ } catch {
164
+ // Try the next strategy.
165
+ }
166
+ }
167
+ return undefined;
168
+ }
169
+
170
+ /**
171
+ * Resolve the installed declaration to a file URL.
172
+ * @returns `file:` URL, or `undefined` when the runtime exposes none.
173
+ */
174
+ export function officialPresetUrl() {
175
+ const override = process.env[PRESET_PATH_ENV]?.trim();
176
+ if (override) {
177
+ if (override.startsWith('file:')) return override;
178
+ return pathToFileURL(isAbsolute(override) ? override : resolve(override)).href;
179
+ }
180
+ return packageFileUrl();
181
+ }
182
+
183
+ /**
184
+ * Load the official PTC preset from the installed runtime.
185
+ * @param options - `presetPath` reads one explicit file (path or file URL) instead of the runtime declaration.
186
+ * @returns The parsed preset and where it came from.
187
+ */
188
+ export function loadOfficialPreset({ presetPath } = {}) {
189
+ const url = presetPath === undefined
190
+ ? officialPresetUrl()
191
+ : presetPath instanceof URL ? presetPath.href
192
+ : pathToFileURL(isAbsolute(presetPath) ? presetPath : resolve(presetPath)).href;
193
+ if (url === undefined) {
194
+ throw new Error(`cannot resolve ${OFFICIAL_PRESET_SPECIFIER}; set ${PRESET_PATH_ENV} to its path`);
195
+ }
196
+ const text = readFileSync(fileURLToPath(url), 'utf8');
197
+ return { preset: parseOfficialPreset(text), source: url };
198
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-deep-ptc-mode",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "Deep PTC mode for DeepSeek Harness: no token rationing, code-enforced no-sleep (long commands move to the background and user messages interrupt waits), plans by task size (approval only for long tasks), asks instead of guessing intent, and runs commands in WSL, PowerShell, Zsh or Bash.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -70,48 +70,22 @@
70
70
  "test": "node --test",
71
71
  "check": "node scripts/check.mjs",
72
72
  "check:upstream": "node scripts/check.mjs --upstream",
73
- "prepack": "npm run check && npm test"
74
- },
75
- "devDependencies": {
76
- "js-yaml": "4.3.2",
77
- "react": "18.3.1",
78
- "react-test-renderer": "18.3.1"
73
+ "prepack": "npm run check && npm test",
74
+ "sync:snapshot": "node scripts/sync-snapshot.mjs"
79
75
  },
80
76
  "peerDependencies": {
81
77
  "@deepseek-ai/schemastery": "^3.18.4",
82
- "@deepseek-ai/dsh-bash-local": ">=0.2.1-rc.5",
83
- "@deepseek-ai/dsh-bash-sandbox": ">=0.2.1-rc.5",
84
- "@deepseek-ai/dsh-tool-bash": ">=0.2.1-rc.5",
85
- "@deepseek-ai/dsh-tool-pwsh": ">=0.2.1-rc.5",
86
- "@deepseek-ai/dsh-tool-jobs": ">=0.2.1-rc.5",
87
- "@deepseek-ai/dsh-tool-ask-user": ">=0.2.1-rc.5",
88
78
  "@deepseek-ai/dsh-client-ui-renderer": ">=0.2.1-rc.5",
89
79
  "@deepseek-ai/dsh-client-ui-settings": ">=0.2.1-rc.5",
90
80
  "@deepseek-ai/dsh-client-ui-slots": ">=0.2.1-rc.5",
91
- "@deepseek-ai/dsh-client-locale": ">=0.2.1-rc.5"
81
+ "@deepseek-ai/dsh-client-locale": ">=0.2.1-rc.5",
82
+ "@deepseek-ai/dsh-web-app": ">=0.2.1-rc.5",
83
+ "@deepseek-ai/dsh-base": ">=0.2.1-rc.5"
92
84
  },
93
85
  "peerDependenciesMeta": {
94
86
  "@deepseek-ai/schemastery": {
95
87
  "optional": true
96
88
  },
97
- "@deepseek-ai/dsh-bash-local": {
98
- "optional": true
99
- },
100
- "@deepseek-ai/dsh-bash-sandbox": {
101
- "optional": true
102
- },
103
- "@deepseek-ai/dsh-tool-bash": {
104
- "optional": true
105
- },
106
- "@deepseek-ai/dsh-tool-pwsh": {
107
- "optional": true
108
- },
109
- "@deepseek-ai/dsh-tool-jobs": {
110
- "optional": true
111
- },
112
- "@deepseek-ai/dsh-tool-ask-user": {
113
- "optional": true
114
- },
115
89
  "@deepseek-ai/dsh-client-ui-renderer": {
116
90
  "optional": true
117
91
  },
@@ -123,6 +97,19 @@
123
97
  },
124
98
  "@deepseek-ai/dsh-client-locale": {
125
99
  "optional": true
100
+ },
101
+ "@deepseek-ai/dsh-web-app": {
102
+ "optional": true
103
+ },
104
+ "@deepseek-ai/dsh-base": {
105
+ "optional": true
126
106
  }
107
+ },
108
+ "dependencies": {
109
+ "js-yaml": "4.3.2"
110
+ },
111
+ "devDependencies": {
112
+ "react": "18.3.1",
113
+ "react-test-renderer": "18.3.1"
127
114
  }
128
115
  }