dsh-deep-ptc-mode 1.5.0 → 1.6.0
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 +10 -0
- package/README.md +6 -4
- package/README.zh.md +8 -5
- package/compatibility.json +3 -2
- package/lib/index.mjs +45 -8
- package/lib/model.mjs +207 -23
- package/lib/preset.json +8 -11
- package/lib/upstream.mjs +169 -0
- package/package.json +15 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.6.0 — 2026-11-04
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
- 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.
|
|
7
|
+
- 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.
|
|
8
|
+
- 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.
|
|
9
|
+
- 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.
|
|
10
|
+
- `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.
|
|
11
|
+
- 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.
|
|
12
|
+
|
|
3
13
|
## 1.5.0 — 2026-10-31
|
|
4
14
|
|
|
5
15
|
- 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
|
@@ -100,22 +100,24 @@ Prefer the UI, which uses revisioned, atomic Host form writes.
|
|
|
100
100
|
|
|
101
101
|
## Compatibility and development
|
|
102
102
|
|
|
103
|
-
|
|
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. 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. 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
|
-
|
|
105
|
+
Because the declaration is resolved through the host runtime, every host package the plugin imports 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 from the installed declaration
|
|
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,
|
|
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`
|
|
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` 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/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
|
@@ -102,32 +102,35 @@ GitHub 地址:`github:lishize20040802-rgb/dsh-deep-ptc-mode`。该地址安装
|
|
|
102
102
|
|
|
103
103
|
## 兼容性与维护
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
Deep PTC 在加载时依据已安装 Harness 声明的 PTC 预设(`@deepseek-ai/dsh-web-app/presets/ptc.patch.yml`)现场组合:官方行原样继承,仅替换 persona 文本、把两个互斥 shell 工具换成一个带 `shell` 隔离的执行组、加入可达性守卫,并包装官方 job 与提问工具。官方怎么改 PTC,本模式无需发版即可继承;官方改名或删除的模块也不会留下失效行。只有在该声明无法解析、读取或解析失败时,才退回内置的 `lib/preset.json` 快照,并在日志中说明。
|
|
106
106
|
|
|
107
|
-
|
|
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 回退快照
|
|
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
|
-
|
|
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
|
|
126
|
+
- `lib/model.mjs`:平台选择、参数、隔离配置和环境说明,以及从官方声明派生 preset。
|
|
125
127
|
- `lib/executor.mjs`:复用官方进程/沙箱语义的 WSL/Zsh 执行器。
|
|
126
128
|
- `lib/terminal.mjs`:复用官方 Bash/PowerShell 终端工具,等待可被用户消息打断,并提供 Zsh 方言与工具名。
|
|
127
129
|
- `lib/jobs-tool.mjs`、`lib/ask-user.mjs`:官方 job 工具与提问工具的包装,等待可被用户消息打断。
|
|
128
130
|
- `lib/guard.mjs`、`lib/rules.mjs`、`lib/sleep-lint.mjs`、`lib/reachable.mjs`:拒绝长暂停与轮询的工具守卫,以及可打断等待的实现。
|
|
129
131
|
- `lib/client.js`:中英文设置卡片。
|
|
130
|
-
- `lib/
|
|
132
|
+
- `lib/upstream.mjs`:定位并解析已安装的 PTC 声明。
|
|
133
|
+
- `lib/preset.json`:persona,以及仅在声明不可用时的回退快照。
|
|
131
134
|
- `test/`、`scripts/check.mjs`、`compatibility.json`:回归与上游差异检查。
|
|
132
135
|
|
|
133
136
|
卸载使用插件管理器的 `remove_bundle`,目标为 `dsh-deep-ptc-mode`。本地 link 安装直接依赖源目录,应先卸载再删除目录。
|
package/compatibility.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"mode": "derived",
|
|
3
3
|
"source": "@deepseek-ai/dsh-web-app/presets/ptc.patch.yml",
|
|
4
|
-
"
|
|
4
|
+
"verifiedUpstream": "0.2.2-rc.1",
|
|
5
|
+
"snapshotSha256": "ce02148b1fd575cc93071744180468cd305bdcd50dbfdd3b9b0605c5281d283d"
|
|
5
6
|
}
|
package/lib/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import z from '@deepseek-ai/schemastery';
|
|
2
|
-
import
|
|
3
|
-
import { availableEnvironments,
|
|
2
|
+
import snapshot from './preset.json' with { type: 'json' };
|
|
3
|
+
import { availableEnvironments, DEFAULT_FOREGROUND_SECONDS, deriveDeepPtc, normalizeDistribution } from './model.mjs';
|
|
4
|
+
import { loadOfficialPreset } from './upstream.mjs';
|
|
4
5
|
import { presetLifecycle } from './lifecycle.mjs';
|
|
5
6
|
|
|
6
7
|
export const name = 'deep-ptc-settings';
|
|
@@ -12,14 +13,48 @@ export const Config = z.object({
|
|
|
12
13
|
hostPlatform: z.const(process.platform).default(process.platform).volatile(),
|
|
13
14
|
});
|
|
14
15
|
|
|
16
|
+
function settingsOf(config) {
|
|
17
|
+
return {
|
|
18
|
+
environment: config.environment.get(),
|
|
19
|
+
wslDistribution: normalizeDistribution(config.wslDistribution.get()),
|
|
20
|
+
foregroundSeconds: config.foregroundSeconds.get(),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Derive Deep PTC from the PTC preset the installed Harness declares, so an
|
|
25
|
+
// official change is inherited instead of leaving a stale frozen row behind.
|
|
26
|
+
// The bundled snapshot is only a fallback when the installed declaration
|
|
27
|
+
// cannot be read or cannot be composed.
|
|
28
|
+
function buildPreset(ctx, config) {
|
|
29
|
+
const settings = settingsOf(config);
|
|
30
|
+
let upstream = snapshot;
|
|
31
|
+
let source = 'bundled snapshot';
|
|
32
|
+
try {
|
|
33
|
+
const official = loadOfficialPreset();
|
|
34
|
+
upstream = official.preset;
|
|
35
|
+
source = official.source;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
ctx.logger.warn('Deep PTC: official PTC preset unavailable (%s); deriving from the bundled snapshot', error.message);
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const { preset, report } = deriveDeepPtc(upstream, settings);
|
|
41
|
+
ctx.logger.info(
|
|
42
|
+
'Deep PTC preset derived from %s: %d official rows; persona %s; shell rows [%s]; wrapped [%s]; skipped [%s]',
|
|
43
|
+
source, report.upstreamRows, report.persona,
|
|
44
|
+
report.replacedShellRows.join('; ') || '-', report.wrapped.join(', ') || '-', report.skipped.join('; ') || '-',
|
|
45
|
+
);
|
|
46
|
+
return preset;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (upstream === snapshot) throw error;
|
|
49
|
+
ctx.logger.warn('Deep PTC: deriving from %s failed (%s); deriving from the bundled snapshot', source, error.message);
|
|
50
|
+
return deriveDeepPtc(snapshot, settings).preset;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
15
54
|
export async function apply(ctx, config) {
|
|
16
55
|
const lifecycle = presetLifecycle(
|
|
17
56
|
definition => ctx.agentPresets.register(definition),
|
|
18
|
-
() =>
|
|
19
|
-
environment: config.environment.get(),
|
|
20
|
-
wslDistribution: normalizeDistribution(config.wslDistribution.get()),
|
|
21
|
-
foregroundSeconds: config.foregroundSeconds.get(),
|
|
22
|
-
}),
|
|
57
|
+
() => buildPreset(ctx, config),
|
|
23
58
|
error => ctx.logger.error('Deep PTC environment update failed: %s', error.message),
|
|
24
59
|
);
|
|
25
60
|
ctx.effect(() => () => lifecycle.dispose());
|
|
@@ -27,5 +62,7 @@ export async function apply(ctx, config) {
|
|
|
27
62
|
ctx.inject(['settings'], child => {
|
|
28
63
|
child.effect(() => child.settings.configure({ auto: false }, ctx.fiber));
|
|
29
64
|
});
|
|
30
|
-
|
|
65
|
+
// A failure to publish the preset is reported above; it must not take the
|
|
66
|
+
// settings service (or the rest of the profile) down with it.
|
|
67
|
+
await lifecycle.refresh().catch(() => {});
|
|
31
68
|
}
|
package/lib/model.mjs
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
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
|
+
|
|
1
11
|
export const ENVIRONMENTS = ['auto', 'wsl', 'powershell', 'zsh', 'bash'];
|
|
2
12
|
|
|
3
13
|
export function availableEnvironments(platform) {
|
|
@@ -58,26 +68,174 @@ export function normalizeForegroundSeconds(value = DEFAULT_FOREGROUND_SECONDS) {
|
|
|
58
68
|
return value;
|
|
59
69
|
}
|
|
60
70
|
|
|
61
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Official rows Deep PTC replaces: the shell tools and the executors that back
|
|
73
|
+
* them. Matched by id first, then by module name; the traversal is recursive so
|
|
74
|
+
* a future official preset may nest them in a group.
|
|
75
|
+
*/
|
|
76
|
+
export const SHELL_ROWS = {
|
|
77
|
+
ids: ['tool-bash', 'tool-pwsh'],
|
|
78
|
+
names: [
|
|
79
|
+
'@deepseek-ai/dsh-tool-bash',
|
|
80
|
+
'@deepseek-ai/dsh-tool-pwsh',
|
|
81
|
+
'@deepseek-ai/dsh-bash-local',
|
|
82
|
+
'@deepseek-ai/dsh-bash-sandbox',
|
|
83
|
+
'@deepseek-ai/dsh-pwsh-sandbox',
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** Official rows Deep PTC keeps but wraps, keyed for diagnostics. */
|
|
62
88
|
export const WRAPPED_ROWS = {
|
|
63
89
|
'tool-jobs': '@deepseek-ai/dsh-tool-jobs',
|
|
64
90
|
'tool-ask-user': '@deepseek-ai/dsh-tool-ask-user',
|
|
65
91
|
};
|
|
66
92
|
|
|
67
|
-
|
|
93
|
+
const PERSONA_ROW = { ids: ['persona'], names: ['@deepseek-ai/dsh-persona'] };
|
|
94
|
+
const WRAP_TARGETS = [
|
|
95
|
+
{
|
|
96
|
+
key: 'tool-jobs',
|
|
97
|
+
upstream: '@deepseek-ai/dsh-tool-jobs',
|
|
98
|
+
replacement: 'dsh-deep-ptc-mode/jobs-tool',
|
|
99
|
+
config: milliseconds => ({ waitTimeoutMs: milliseconds, maxWaitTimeoutMs: milliseconds }),
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
key: 'tool-ask-user',
|
|
103
|
+
upstream: '@deepseek-ai/dsh-tool-ask-user',
|
|
104
|
+
replacement: 'dsh-deep-ptc-mode/ask-user',
|
|
105
|
+
config: () => ({ mode: 'timed', timeout: QUESTION_SECONDS }),
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
/** Identity and display text Deep PTC publishes, independent of the official preset. */
|
|
110
|
+
export const PRESET_META = {
|
|
111
|
+
id: 'deep-ptc',
|
|
112
|
+
name: typeof snapshot.name === 'string' && snapshot.name.length > 0 ? snapshot.name : '深度PTC模式',
|
|
113
|
+
order: typeof snapshot.order === 'number' ? snapshot.order : 5,
|
|
114
|
+
description: typeof snapshot.description === 'string' ? snapshot.description : '',
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** Persona text owned by this plugin, read from the bundled snapshot. */
|
|
118
|
+
export function personaFrom(template = snapshot) {
|
|
119
|
+
const rows = Array.isArray(template?.plugins) ? template.plugins : [];
|
|
120
|
+
const row = findRow(rows, PERSONA_ROW);
|
|
121
|
+
const config = row?.config;
|
|
122
|
+
if (!config || typeof config.prefix !== 'string' || typeof config.suffix !== 'string') {
|
|
123
|
+
throw new Error('bundled snapshot carries no Deep PTC persona');
|
|
124
|
+
}
|
|
125
|
+
return { prefix: config.prefix, suffix: config.suffix };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Visit every row depth-first, including rows nested in group configurations. */
|
|
129
|
+
export function walkRows(rows, visit) {
|
|
130
|
+
if (!Array.isArray(rows)) return;
|
|
131
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
132
|
+
const row = rows[index];
|
|
133
|
+
if (!row || typeof row !== 'object') continue;
|
|
134
|
+
visit(row, rows, index);
|
|
135
|
+
if (row.group === true && Array.isArray(row.config)) walkRows(row.config, visit);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Whether a row is one of the official shell/executor rows Deep PTC replaces. */
|
|
140
|
+
export function isShellRow(row) {
|
|
141
|
+
return row.group !== true && (SHELL_ROWS.names.includes(row.name) || SHELL_ROWS.ids.includes(row.id));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function findRow(rows, { ids = [], names = [] }) {
|
|
145
|
+
let found;
|
|
146
|
+
walkRows(rows, row => {
|
|
147
|
+
if (found !== undefined) return;
|
|
148
|
+
if (names.includes(row.name) || ids.includes(row.id)) found = row;
|
|
149
|
+
});
|
|
150
|
+
return found;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function rowIds(plugins, into = new Set()) {
|
|
154
|
+
walkRows(plugins, row => {
|
|
155
|
+
if (typeof row.id === 'string') into.add(row.id);
|
|
156
|
+
});
|
|
157
|
+
return into;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function uniqueRowId(plugins, preferred) {
|
|
161
|
+
const taken = rowIds(plugins);
|
|
162
|
+
if (!taken.has(preferred)) return preferred;
|
|
163
|
+
for (let suffix = 2; ; suffix += 1) {
|
|
164
|
+
const candidate = `${preferred}-${suffix}`;
|
|
165
|
+
if (!taken.has(candidate)) return candidate;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Compose the Deep PTC preset from an official PTC declaration.
|
|
171
|
+
* @param upstream - Official preset configuration (`{ id, order, plugins }`).
|
|
172
|
+
* @param options - `environment`, `wslDistribution`, `foregroundSeconds`.
|
|
173
|
+
* @param platform - Host platform whose environment choices apply.
|
|
174
|
+
* @returns The Deep PTC preset plus a report of what was replaced, wrapped or skipped.
|
|
175
|
+
*/
|
|
176
|
+
export function deriveDeepPtc(upstream, options = {}, platform = process.platform) {
|
|
177
|
+
if (!upstream || !Array.isArray(upstream.plugins) || upstream.plugins.length === 0) {
|
|
178
|
+
throw new Error('official PTC preset carries no plugin rows');
|
|
179
|
+
}
|
|
180
|
+
for (const row of upstream.plugins) {
|
|
181
|
+
if (!row || typeof row !== 'object' || typeof row.name !== 'string') {
|
|
182
|
+
throw new Error('official PTC preset has a malformed plugin row');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
68
186
|
const environment = resolveEnvironment(options.environment, platform);
|
|
69
187
|
const distribution = normalizeDistribution(options.wslDistribution);
|
|
70
188
|
const foregroundSeconds = normalizeForegroundSeconds(options.foregroundSeconds);
|
|
71
189
|
const foregroundMs = foregroundSeconds * 1000;
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
190
|
+
const plugins = structuredClone(upstream.plugins);
|
|
191
|
+
const report = {
|
|
192
|
+
upstreamId: typeof upstream.id === 'string' ? upstream.id : null,
|
|
193
|
+
upstreamRows: plugins.length,
|
|
194
|
+
persona: 'missing',
|
|
195
|
+
replacedShellRows: [],
|
|
196
|
+
wrapped: [],
|
|
197
|
+
skipped: [],
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// Persona: keep the row and any official fields, replace only the text.
|
|
201
|
+
const personaText = personaFrom();
|
|
202
|
+
const persona = findRow(plugins, PERSONA_ROW);
|
|
203
|
+
if (persona === undefined) {
|
|
204
|
+
plugins.unshift({ id: uniqueRowId(plugins, 'persona'), name: '@deepseek-ai/dsh-persona', config: { ...personaText } });
|
|
205
|
+
report.persona = 'inserted';
|
|
206
|
+
} else {
|
|
207
|
+
persona.config = { ...(persona.config ?? {}), ...personaText };
|
|
208
|
+
report.persona = 'replaced';
|
|
78
209
|
}
|
|
79
|
-
|
|
80
|
-
//
|
|
210
|
+
|
|
211
|
+
// Execution environment: remove the official shell rows (wherever the
|
|
212
|
+
// official preset nests them) and put the selectable execution group in the
|
|
213
|
+
// same place.
|
|
214
|
+
const removed = [];
|
|
215
|
+
walkRows(plugins, (row, siblings, index) => {
|
|
216
|
+
if (isShellRow(row)) removed.push({ row, siblings, index });
|
|
217
|
+
});
|
|
218
|
+
report.replacedShellRows = removed.map(({ row }) => `${row.id ?? '?'} (${row.name})`);
|
|
219
|
+
let anchorSiblings = plugins;
|
|
220
|
+
let anchorIndex;
|
|
221
|
+
if (removed.length > 0) {
|
|
222
|
+
anchorSiblings = removed[0].siblings;
|
|
223
|
+
const bySiblings = new Map();
|
|
224
|
+
for (const { siblings, index } of removed) {
|
|
225
|
+
if (!bySiblings.has(siblings)) bySiblings.set(siblings, []);
|
|
226
|
+
bySiblings.get(siblings).push(index);
|
|
227
|
+
}
|
|
228
|
+
anchorIndex = Math.min(...bySiblings.get(anchorSiblings));
|
|
229
|
+
for (const [siblings, indexes] of bySiblings) {
|
|
230
|
+
for (const index of [...indexes].sort((left, right) => right - left)) siblings.splice(index, 1);
|
|
231
|
+
}
|
|
232
|
+
} else {
|
|
233
|
+
report.skipped.push('official shell rows');
|
|
234
|
+
const topLevelPersona = plugins.findIndex(row => row && row.group !== true
|
|
235
|
+
&& (PERSONA_ROW.names.includes(row.name) || PERSONA_ROW.ids.includes(row.id)));
|
|
236
|
+
anchorIndex = topLevelPersona + 1;
|
|
237
|
+
}
|
|
238
|
+
|
|
81
239
|
const executor = {
|
|
82
240
|
id: 'executor',
|
|
83
241
|
name: environment === 'powershell' ? '@deepseek-ai/dsh-pwsh-sandbox'
|
|
@@ -92,19 +250,45 @@ export function configuredPreset(template, options, platform = process.platform)
|
|
|
92
250
|
name: 'dsh-deep-ptc-mode/terminal',
|
|
93
251
|
config: { tool: environment === 'powershell' ? 'pwsh' : 'bash', ...(environment === 'zsh' ? { dialect: 'zsh' } : {}) },
|
|
94
252
|
};
|
|
95
|
-
|
|
96
|
-
id: 'execution', name: 'cordis:group', group: true, isolate: { shell: true },
|
|
253
|
+
const execution = {
|
|
254
|
+
id: uniqueRowId(plugins, 'execution'), name: 'cordis:group', group: true, isolate: { shell: true },
|
|
97
255
|
config: [executor, terminal, { id: 'execution-instructions', name: 'dsh-deep-ptc-mode/environment',
|
|
98
256
|
config: { environment, wslDistribution: distribution } }],
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
257
|
+
};
|
|
258
|
+
const guard = {
|
|
259
|
+
id: uniqueRowId([...plugins, execution], 'reachability'),
|
|
260
|
+
name: 'dsh-deep-ptc-mode/guard', config: { foregroundSeconds },
|
|
261
|
+
};
|
|
262
|
+
anchorSiblings.splice(anchorIndex, 0, execution, guard);
|
|
263
|
+
|
|
264
|
+
// Wrapped tools: keep the official plugin's own configuration, add the
|
|
265
|
+
// Deep PTC wait behaviour on top.
|
|
266
|
+
for (const target of WRAP_TARGETS) {
|
|
267
|
+
const row = findRow(plugins, { ids: [target.key], names: [target.upstream] });
|
|
268
|
+
if (row === undefined) {
|
|
269
|
+
report.skipped.push(`${target.key} (${target.upstream})`);
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
row.name = target.replacement;
|
|
273
|
+
row.config = { ...(row.config ?? {}), ...target.config(foregroundMs) };
|
|
274
|
+
report.wrapped.push(target.key);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const description = `${PRESET_META.description} 当前环境:${environment}${environment === 'wsl' && distribution ? ` (${distribution})` : ''}`;
|
|
278
|
+
return {
|
|
279
|
+
preset: {
|
|
280
|
+
...upstream,
|
|
281
|
+
id: PRESET_META.id,
|
|
282
|
+
name: PRESET_META.name,
|
|
283
|
+
order: PRESET_META.order,
|
|
284
|
+
description,
|
|
285
|
+
plugins,
|
|
286
|
+
},
|
|
287
|
+
report,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Backwards-compatible helper: the derived preset without the report. */
|
|
292
|
+
export function configuredPreset(template, options, platform = process.platform) {
|
|
293
|
+
return deriveDeepPtc(template, options, platform).preset;
|
|
110
294
|
}
|
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
|
-
"
|
|
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-
|
|
187
|
-
"name": "@deepseek-ai/dsh-
|
|
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/upstream.mjs
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
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
|
+
function tryResolve(specifier) {
|
|
111
|
+
try {
|
|
112
|
+
return import.meta.resolve(specifier);
|
|
113
|
+
} catch {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function packageFileUrl() {
|
|
119
|
+
const direct = tryResolve(OFFICIAL_PRESET_SPECIFIER);
|
|
120
|
+
if (direct !== undefined) return direct;
|
|
121
|
+
for (const specifier of [`${PACKAGE}/package.json`, PACKAGE]) {
|
|
122
|
+
const url = tryResolve(specifier);
|
|
123
|
+
if (url === undefined) continue;
|
|
124
|
+
try {
|
|
125
|
+
const file = fileURLToPath(url);
|
|
126
|
+
if (file.endsWith('package.json')) return pathToFileURL(join(dirname(file), PRESET_PATH)).href;
|
|
127
|
+
// A package-root export may point at any file; the declaration sits beside the package.
|
|
128
|
+
let dir = dirname(file);
|
|
129
|
+
while (dir !== dirname(dir)) {
|
|
130
|
+
if (dir.endsWith(PACKAGE) || dir.endsWith(PACKAGE.replace('/', '-'))) break;
|
|
131
|
+
dir = dirname(dir);
|
|
132
|
+
}
|
|
133
|
+
return pathToFileURL(join(dir, PRESET_PATH)).href;
|
|
134
|
+
} catch {
|
|
135
|
+
// Try the next strategy.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Resolve the installed declaration to a file URL.
|
|
143
|
+
* @returns `file:` URL, or `undefined` when the runtime exposes none.
|
|
144
|
+
*/
|
|
145
|
+
export function officialPresetUrl() {
|
|
146
|
+
const override = process.env[PRESET_PATH_ENV]?.trim();
|
|
147
|
+
if (override) {
|
|
148
|
+
if (override.startsWith('file:')) return override;
|
|
149
|
+
return pathToFileURL(isAbsolute(override) ? override : resolve(override)).href;
|
|
150
|
+
}
|
|
151
|
+
return packageFileUrl();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Load the official PTC preset from the installed runtime.
|
|
156
|
+
* @param options - `presetPath` reads one explicit file (path or file URL) instead of the runtime declaration.
|
|
157
|
+
* @returns The parsed preset and where it came from.
|
|
158
|
+
*/
|
|
159
|
+
export function loadOfficialPreset({ presetPath } = {}) {
|
|
160
|
+
const url = presetPath === undefined
|
|
161
|
+
? officialPresetUrl()
|
|
162
|
+
: presetPath instanceof URL ? presetPath.href
|
|
163
|
+
: pathToFileURL(isAbsolute(presetPath) ? presetPath : resolve(presetPath)).href;
|
|
164
|
+
if (url === undefined) {
|
|
165
|
+
throw new Error(`cannot resolve ${OFFICIAL_PRESET_SPECIFIER}; set ${PRESET_PATH_ENV} to its path`);
|
|
166
|
+
}
|
|
167
|
+
const text = readFileSync(fileURLToPath(url), 'utf8');
|
|
168
|
+
return { preset: parseOfficialPreset(text), source: url };
|
|
169
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-deep-ptc-mode",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
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,12 +70,8 @@
|
|
|
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",
|
|
@@ -88,7 +84,8 @@
|
|
|
88
84
|
"@deepseek-ai/dsh-client-ui-renderer": ">=0.2.1-rc.5",
|
|
89
85
|
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.1-rc.5",
|
|
90
86
|
"@deepseek-ai/dsh-client-ui-slots": ">=0.2.1-rc.5",
|
|
91
|
-
"@deepseek-ai/dsh-client-locale": ">=0.2.1-rc.5"
|
|
87
|
+
"@deepseek-ai/dsh-client-locale": ">=0.2.1-rc.5",
|
|
88
|
+
"@deepseek-ai/dsh-web-app": ">=0.2.1-rc.5"
|
|
92
89
|
},
|
|
93
90
|
"peerDependenciesMeta": {
|
|
94
91
|
"@deepseek-ai/schemastery": {
|
|
@@ -123,6 +120,16 @@
|
|
|
123
120
|
},
|
|
124
121
|
"@deepseek-ai/dsh-client-locale": {
|
|
125
122
|
"optional": true
|
|
123
|
+
},
|
|
124
|
+
"@deepseek-ai/dsh-web-app": {
|
|
125
|
+
"optional": true
|
|
126
126
|
}
|
|
127
|
+
},
|
|
128
|
+
"dependencies": {
|
|
129
|
+
"js-yaml": "4.3.2"
|
|
130
|
+
},
|
|
131
|
+
"devDependencies": {
|
|
132
|
+
"react": "18.3.1",
|
|
133
|
+
"react-test-renderer": "18.3.1"
|
|
127
134
|
}
|
|
128
135
|
}
|