dsh-deep-ptc-mode 1.7.4 → 1.8.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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.8.0 — 2026-11-07
4
+
5
+ - 会话级 preset 身份兼容,两次尝试:不限制预设名称的外部插件拿原生 `deep-ptc`(第一层,直接可用);限制预设名称、列表里没有 `deep-ptc` 的插件拿基座 `ptc`(第二层,对包含 `ptc` 的列表必定通过)。显式支持 `deep-ptc` 的插件也拿原生。宿主内部(子代理 header、定时任务、注册表自身)保持精确 id,不影响继承与调度。
6
+ - 兼容层在插件本体内实现(`lib/preset-compat.mjs`),随插件启动安装:不需要改 DSH,也不需要给外部插件写逐插件配置。判定先看调用方插件是否限制预设名称:不限制就返回原生,限制就立即返回基座。宿主没有拒绝回调,因此两次尝试在返回前按调用方决定,不做运行时重试。
7
+ - 普通 PTC 与其他预设原样返回;官方 PTC 预设没有被替换。新增设置:`presetCompat`(默认开)、`presetFallback`(默认 `ptc`)、`presetSupport`(按包名覆盖 `native` / `base`)。
8
+ - 修复调用方识别:跳过 Cordis 服务代理插入的 `Object.apply` 帧,否则真实插件会被当成宿主、dsh-ops 门控被误关。
9
+ - 创造模式/插件实验台安全:加载只读 `agentPresets.list/readDocument`,不调用 `composedPreset`(测试保证);实验台挂入深 PTC 会话的创造模式行若只认 `cordis`,第二层返回 `cordis`,认 `ptc` 的仍返回 `ptc`;普通创造模式会话(`cordis`)原样不变。
10
+
11
+ - Session-scoped preset identity compatibility as two attempts: an external plugin that does not limit preset names receives the native `deep-ptc` (layer 1, usable as-is); a plugin that limits preset names and does not list `deep-ptc` receives the base `ptc` (layer 2, guaranteed for an allowlist that includes `ptc`). A plugin that explicitly supports `deep-ptc` also receives the native id. Host internals (subagent child headers, scheduled session creation, the registry itself) keep the exact id, so inheritance and scheduling are unaffected.
12
+ - Implemented inside the plugin (`lib/preset-compat.mjs`) and installed at plugin startup: no DSH change and no per-plugin configuration. The decision first checks whether the calling plugin limits preset names: no limit keeps the native id; a limit falls back immediately. The host offers no rejection callback, so both attempts are decided per caller before returning, with no runtime retry.
13
+ - Normal PTC and other presets are returned unchanged; the official PTC preset is not replaced. New settings: `presetCompat` (on by default), `presetFallback` (default `ptc`), `presetSupport` (per-package `native` / `base` override).
14
+ - Caller detection now skips the `Object.apply` frame inserted by the Cordis service proxy; before this, a real plugin looked like the host and dsh-ops stayed inert.
15
+ - Creative mode and the plugin lab stay safe: loading reads `agentPresets.list/readDocument` only and never calls `composedPreset` (covered by a test). A creative row mounted into a Deep PTC session that accepts only `cordis` receives `cordis`; one that accepts `ptc` still receives `ptc`. A normal creative session (preset `cordis`) is unchanged.
16
+
3
17
  ## 1.7.4 — 2026-11-07
4
18
 
5
19
  - 支持当前桌面端 DSH RC `>=0.2.2-rc.1`。只声明支持 RC,不支持 alpha。
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # Deep PTC mode
2
2
 
3
- [中文](README.zh.md) · MIT · **1.7.4**
3
+ [中文](README.zh.md) · MIT · **1.8.0**
4
4
 
5
5
  [1.7.3 实测汇总 / Test summary](TEST_REPORT.md)
6
6
  **Let plugins cooperate. Keep current official PTC tools as the fallback. Stay interruptible while work runs.**
7
7
 
8
8
  Deep PTC is a DeepSeek Harness agent preset built for a plugin ecosystem. It first looks for a suitable tool among the available external plugins, then continues with the running host’s dynamically discovered official PTC capability when no enhancement fits or a provider fails. Multiple plugins can contribute different parts of a task, each using its own schemas, discovery and result contracts. Deep PTC adds no task tools of its own.
9
9
 
10
+ Deep PTC 1.8.0 adds **session-scoped preset identity**: an external plugin that does not restrict preset names sees the native `deep-ptc`, a plugin that restricts them gets the base `ptc` (or `cordis` for a creative-mode row mounted by the plugin lab), and host internals keep the exact id. Normal PTC and creative sessions are untouched.
11
+
10
12
  The same working rules remain: use the model's capability thoroughly, move long commands into managed background jobs, respond to your messages while work runs, plan by task size, clarify intent, and execute in your selected WSL / PowerShell / Zsh / Bash environment.
11
13
 
12
14
  ## A mode for “everything is a plugin”
@@ -127,6 +129,19 @@ External plugins are discovered from what they actually register. Tools and work
127
129
 
128
130
  Phone screen control was not clicked on a device for this release. The guarantee above is the SDK membership, the quarantine rule, and the composer failure path.
129
131
 
132
+ ## 1.8.0: session-scoped preset identity
133
+
134
+ External plugins often treat an agent-preset id as a capability switch (dsh-ops recognises only minimal/standard/ptc/cordis). Deep PTC registers `deep-ptc`. 1.8.0 makes two attempts inside the plugin:
135
+
136
+ - **Layer 1 (native)**: an external plugin that does not limit preset names receives `deep-ptc` and works as-is; a plugin that explicitly declares support for `deep-ptc` also receives the native id.
137
+ - **Layer 2 (base)**: a plugin that limits preset names and does not list `deep-ptc` receives `ptc`. For an allowlist that includes `ptc` (dsh-ops), this layer is guaranteed; if the list does not contain `ptc` either, neither attempt matches (such a plugin does not support PTC at all).
138
+ - Host calls that must stay exact (subagent child headers, scheduled session creation, the registry itself) always receive `deep-ptc`, so inheritance and scheduling are unaffected.
139
+ - A normal PTC session already returns `ptc`; every other preset is returned unchanged. The official PTC preset is not replaced, and DSH is not modified.
140
+ - Creative mode and the plugin lab: loading reads the host roster and documents only, never `composedPreset`. A creative row mounted into a Deep PTC session that accepts only `cordis` gets `cordis`; a normal creative session is unchanged.
141
+ - Both attempts are decided before returning: the host provides no rejection callback, so the layer inspects the calling plugin's own package to see whether it limits preset names. No limit keeps the native id; a limit falls back immediately. Settings: `presetCompat`, `presetFallback`, `presetSupport`.
142
+
143
+ Limitation: this wraps the host's `agentPresets.composedPreset` instance and depends on its internal signature, so re-check after a DSH upgrade. The per-package probe is heuristic; dynamically assembled ids may not be recognised.
144
+
130
145
  ## Working contract
131
146
 
132
147
  - Spend the budget on the work: the persona states that the model works at DeepSeek with an unlimited token budget in this mode, so it does not skip reads, searches, commands or checks to save tokens. Guardrails forbid padding, and compaction, pruning and subagents keep each request inside its finite context window.
@@ -143,10 +158,10 @@ A prompt changes the model's working tendency, not the real token limit or billi
143
158
  Requires Node `>=24` and DSH RC `>=0.2.2-rc.1` (the installed desktop). Alpha builds are not supported. 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.
144
159
 
145
160
  ```js
146
- plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.7.4" })
161
+ plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.8.0" })
147
162
  // Or from a local checkout or archive:
148
163
  plugin_manager({ action: "install_bundle", target: "C:\\path\\to\\dsh-deep-ptc-mode" })
149
- // Or target: "C:\\path\\to\\dsh-deep-ptc-mode-1.7.4.tgz"
164
+ // Or target: "C:\\path\\to\\dsh-deep-ptc-mode-1.8.0.tgz"
150
165
  ```
151
166
 
152
167
  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.
package/README.zh.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # 深度 PTC 模式
2
2
 
3
- [English](README.md) · MIT · 当前版本:**1.7.4**
3
+ [English](README.md) · MIT · 当前版本:**1.8.0**
4
4
 
5
5
  [1.7.3 实测汇总 / Test summary](TEST_REPORT.md)
6
6
  **让插件协作,让当前官方 PTC 工具兜底,让任务始终可沟通。**
7
7
 
8
8
  深度 PTC 是面向插件生态的 DeepSeek Harness Agent 模式(preset):优先在当前可用的外部插件中寻找同功能工具,没有合适能力或插件工具故障时,再用当前官方 PTC 的工具继续完成任务。多个插件可以分工完成同一个任务,各自保留原有参数、发现方式和结果契约;深度 PTC 本身不提供新的任务工具。
9
9
 
10
+ 1.8.0 增加**会话级预设身份兼容**:不限制预设名称的外部插件看到原生 `deep-ptc`,限制预设名称的插件拿到基座 `ptc`(实验台挂入的创造模式行可拿到 `cordis`),宿主内部保持精确 id。普通 PTC 会话与创造模式会话不受影响。
11
+
10
12
  原有的工作特点完整保留:把模型能力用满,长命令交给后台 job,运行中随时回应你的插话,按任务大小规划,意图不清先问,并在你选择的 WSL / PowerShell / Zsh / Bash 环境执行。
11
13
 
12
14
  ## 为「一切皆插件」的协作方式而设计
@@ -127,6 +129,19 @@ WSL 命令使用 Linux/POSIX 语法;文件工具和 `workdir` 仍用 Windows
127
129
 
128
130
  本版没有在真机上点过手机屏幕控制。上面保证的是 SDK 成员资格、隔离规则,以及界面投影失败时的退让。
129
131
 
132
+ ## 1.8.0:会话级 preset 身份兼容
133
+
134
+ 外部插件常把 agent preset id 当能力开关(例如 dsh-ops 只认 minimal/standard/ptc/cordis)。深度 PTC 注册的 id 是 `deep-ptc`。1.8.0 在插件内部做两次尝试:
135
+
136
+ - **第一层(原生)**:不限制预设名称的外部插件拿 `deep-ptc`,直接可用;显式声明支持 `deep-ptc` 的插件也拿原生。
137
+ - **第二层(基座)**:限制预设名称、且列表里没有 `deep-ptc` 的插件拿 `ptc`。对 dsh-ops 这类包含 `ptc` 的列表,这一层必定通过;如果列表连 `ptc` 都没有,两层都不匹配(它本来也不支持 PTC)。
138
+ - 宿主内部必须精确的调用(子代理 header、定时任务、注册表自身)始终拿 `deep-ptc`,不影响继承和调度。
139
+ - 普通 PTC 会话本来就返回 `ptc`,其他预设原样返回;官方 PTC 预设没有被替换,也没有改 DSH。
140
+ - 创造模式/插件实验台:加载只读宿主的预设清单和文档,不调用 `composedPreset`;实验台挂进深 PTC 会话的创造模式行若只认 `cordis`,第二层就返回 `cordis`,普通创造模式会话仍原样。
141
+ - 两次尝试都在返回之前决定:宿主不会在插件拒绝时回调,所以读取调用方插件自己的包,判断它是否限制预设名称;不限制就给原生,限制就立即给基座。设置里可用 `presetCompat`、`presetFallback`、`presetSupport` 调整。
142
+
143
+ 局限:这是对 `agentPresets.composedPreset` 的实例包装,依赖宿主内部方法签名;DSH 升级后需要复核。按包内容探测是启发式的,插件如果在代码里用动态拼接的 id,可能识别不到。
144
+
130
145
  ## 工作规则
131
146
 
132
147
  - **不为 token 省力:** 人设写明在深度求索工作、本模式 token 预算无限,按问题需要而不是成本决定读取、搜索、命令和验证的深度;同时禁止注水和啰嗦,单次上下文仍有限,靠压缩、裁剪和子代理控制。
@@ -145,10 +160,10 @@ WSL 命令使用 Linux/POSIX 语法;文件工具和 `workdir` 仍用 Windows
145
160
  本地目录或构建产物可通过插件管理器安装:
146
161
 
147
162
  ```js
148
- plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.7.4" })
163
+ plugin_manager({ action: "install_bundle", target: "dsh-deep-ptc-mode@1.8.0" })
149
164
  // 也可从本地目录或安装包安装:
150
165
  plugin_manager({ action: "install_bundle", target: "C:\\path\\to\\dsh-deep-ptc-mode" })
151
- // 或 target: "C:\\path\\to\\dsh-deep-ptc-mode-1.7.4.tgz"
166
+ // 或 target: "C:\\path\\to\\dsh-deep-ptc-mode-1.8.0.tgz"
152
167
  ```
153
168
 
154
169
  GitHub 地址:`github:lishize20040802-rgb/dsh-deep-ptc-mode`。该地址安装远端实际内容;本地升级不会自动发布到 GitHub/npm。
package/TEST_REPORT.md CHANGED
File without changes
package/assets/icon.png CHANGED
File without changes
File without changes
package/cordis.patch.yml CHANGED
File without changes
package/lib/adapt.mjs CHANGED
File without changes
package/lib/ask-user.mjs CHANGED
File without changes
File without changes
package/lib/client.js CHANGED
File without changes
package/lib/creative.mjs CHANGED
File without changes
File without changes
package/lib/executor.mjs CHANGED
File without changes
package/lib/guard.mjs CHANGED
File without changes
package/lib/host.mjs CHANGED
File without changes
package/lib/index.mjs CHANGED
@@ -10,6 +10,7 @@ import { discoverShells, resolveShellExecutable, shellNote } from './shells.mjs'
10
10
  import { BASE_DECLARATION_SPECIFIER, creativePresetUrl, loadCreativePreset, loadCurrentPreset, officialPresetUrl, parseOfficialExecutors } from './upstream.mjs';
11
11
  import { importHost, pluginOf, resolveHost } from './host.mjs';
12
12
  import { presetLifecycle } from './lifecycle.mjs';
13
+ import { installPresetCompat } from './preset-compat.mjs';
13
14
 
14
15
  function whereExecutable(name) {
15
16
  try {
@@ -48,6 +49,10 @@ export const Config = z.object({
48
49
  toolPreferences: z.any().default([]).volatile(),
49
50
  compactToolCatalog: z.boolean().default(true).volatile(),
50
51
  hostPlatform: z.const(process.platform).default(process.platform).volatile(),
52
+ // Session-scoped preset identity compatibility (native id first, base fallback).
53
+ presetCompat: z.boolean().default(true).volatile(),
54
+ presetFallback: z.string().default('ptc').volatile(),
55
+ presetSupport: z.any().default({}).volatile(),
51
56
  });
52
57
 
53
58
  // Tool preferences are advice for the model, so a malformed list must not cost the preset.
@@ -169,6 +174,18 @@ export async function apply(ctx, config) {
169
174
  error => ctx.logger.error('Deep PTC environment update failed: %s', error.message),
170
175
  );
171
176
  ctx.effect(() => () => lifecycle.dispose());
177
+ // Session-scoped preset identity: report the native deep-ptc id first; an external
178
+ // consumer that does not declare support for it gets the base preset id instead.
179
+ const compat = installPresetCompat(ctx, () => {
180
+ if (config.presetCompat.get() === false) return { enabled: false };
181
+ let support = {};
182
+ try {
183
+ const raw = config.presetSupport.get();
184
+ if (raw && typeof raw === 'object' && !Array.isArray(raw)) support = raw;
185
+ } catch { /* keep the empty override list */ }
186
+ return { enabled: true, nativeIds: ['deep-ptc'], fallback: config.presetFallback.get() || 'ptc', support };
187
+ });
188
+ ctx.effect(() => () => compat.dispose(), 'Deep PTC: session-scoped preset identity');
172
189
  // A preset the host refuses to mount would leave its sessions unusable, so fall back to the official
173
190
  // composition with the persona. Not awaited: reading the diagnosis waits for the host tree.
174
191
  const verify = async () => {
package/lib/jobs-tool.mjs CHANGED
File without changes
package/lib/lab.mjs CHANGED
File without changes
package/lib/lifecycle.mjs CHANGED
File without changes
package/lib/model.mjs CHANGED
File without changes
File without changes
@@ -0,0 +1,283 @@
1
+ // Deep PTC owns a session-scoped preset identity compatibility layer.
2
+ //
3
+ // Two attempts for a session's identity:
4
+ // 1. native deep-ptc -- the plugin may pass if it does not limit preset names;
5
+ // 2. base ptc -- a plugin that limits preset names to the built-in ids passes here.
6
+ //
7
+ // Each external plugin is asked once, so the layer is chosen before returning: inspect
8
+ // the calling plugin's own package. A package that does not gate on preset ids, or
9
+ // that declares deep-ptc, gets the native id. A package that gates on preset ids but
10
+ // does not declare deep-ptc gets the base id immediately. The second layer is the one
11
+ // that is guaranteed to pass for a plugin whose allowlist includes ptc (dsh-ops maps
12
+ // minimal/standard/ptc/cordis). A plugin that excludes ptc can pass neither.
13
+ //
14
+ // Why not retry at runtime: composedPreset() returns one string and the host gives no
15
+ // rejection callback; a plugin whose gate misses simply stays inert. So the two
16
+ // attempts are resolved per caller before the value is returned.
17
+ //
18
+ // Host internals that must keep the exact identity (subagent child headers, scheduled
19
+ // session creation, the registry itself) are recognised from the immediate frames.
20
+ import { appendFileSync, readFileSync, readdirSync, statSync } from 'node:fs';
21
+ import { dirname, join, parse } from 'node:path';
22
+ import { fileURLToPath } from 'node:url';
23
+
24
+ export const name = 'deep-ptc-preset-compat';
25
+ export const inject = ['agentPresets'];
26
+
27
+ const PATCH_MARK = Symbol.for('dsh-deep-ptc-mode.preset-compat.patch');
28
+ const HOST_CALLERS = /(?:dsh-subagent|dsh-tool-schedule|dsh-agent-preset-registry)/u;
29
+ const SELF = 'preset-compat.mjs';
30
+ const CODE_EXTENSIONS = ['.mjs', '.cjs', '.js', '.mts', '.cts', '.ts'];
31
+ const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', 'docs', 'test', 'tests']);
32
+ const MAX_FILES = 800;
33
+ const MAX_FILE_BYTES = 1024 * 1024;
34
+ const MAX_TOTAL_BYTES = 8 * 1024 * 1024;
35
+ const LOG = 'C:/Users/13987/.dsh/tmp/deep-ptc-preset-compat.log';
36
+
37
+ const packageCache = new Map();
38
+ const callerCache = new Map();
39
+ const logged = new Set();
40
+
41
+ function log(line) {
42
+ try { appendFileSync(LOG, line + '\n'); } catch { /* diagnostics only */ }
43
+ }
44
+
45
+ function fileOf(value) {
46
+ try {
47
+ const file = value.startsWith('file:') ? fileURLToPath(value) : value;
48
+ // fileURLToPath yields /C:/... under a POSIX runtime and C:\... on Windows.
49
+ return /^\/[A-Za-z]:[\\/]/u.test(file) ? file.slice(1) : file;
50
+ } catch { return ''; }
51
+ }
52
+
53
+ function isCodeFile(name) {
54
+ return CODE_EXTENSIONS.some(extension => name.endsWith(extension));
55
+ }
56
+
57
+ function isNumber(text) {
58
+ return text.length > 0 && Number.isFinite(Number(text)) && /^[0-9]+$/u.test(text);
59
+ }
60
+
61
+ /** First stack frame outside this module, as an absolute file path. */
62
+ export function callerFile(stack) {
63
+ for (const raw of String(stack ?? '').split('\n').slice(1)) {
64
+ if (raw.includes(SELF)) continue;
65
+ // Cordis service proxies insert one infrastructure frame (Object.apply in the
66
+ // host's cordis package) between this wrapper and the real caller. Skip it so
67
+ // the caller's own package, not the proxy, decides the layer.
68
+ if (raw.includes('@deepseek-ai/cordis/')) continue;
69
+ let text = raw.trim();
70
+ if (text.startsWith('at ')) text = text.slice(3).trim();
71
+ if (text.startsWith('async ')) text = text.slice(6).trim();
72
+ const open = text.lastIndexOf('(');
73
+ if (open !== -1 && text.endsWith(')')) text = text.slice(open + 1, -1);
74
+ const parts = text.split(':');
75
+ if (parts.length < 3) continue;
76
+ const col = parts.pop();
77
+ const line = parts.pop();
78
+ if (!isNumber(line) || !isNumber(col)) continue;
79
+ const file = fileOf(parts.join(':'));
80
+ if (file) return file;
81
+ }
82
+ return '';
83
+ }
84
+
85
+ /** Nearest ancestor package.json carrying a name. */
86
+ export function packageOf(file) {
87
+ let dir = dirname(file);
88
+ const { root } = parse(dir);
89
+ for (let depth = 0; depth < 12 && dir && dir !== root; depth++) {
90
+ try {
91
+ const manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
92
+ if (manifest && typeof manifest.name === 'string') return { root: dir, name: manifest.name };
93
+ } catch { /* keep walking */ }
94
+ const parent = dirname(dir);
95
+ if (parent === dir) break;
96
+ dir = parent;
97
+ }
98
+ return undefined;
99
+ }
100
+
101
+ const GATE_MARKERS = [
102
+ 'MODE_PRESET',
103
+ "=== 'ptc'", '=== "ptc"', "!== 'ptc'", '!== "ptc"',
104
+ "=== 'standard'", '=== "standard"', "=== 'cordis'", '=== "cordis"',
105
+ "=== 'minimal'", '=== "minimal"',
106
+ "case 'ptc'", 'case "ptc"',
107
+ ".includes('ptc')", '.includes("ptc")',
108
+ ];
109
+
110
+ const CREATIVE_PRESET_ID = 'cordis';
111
+ const KNOWN_PRESET_IDS = ['deep-ptc', CREATIVE_PRESET_ID, 'ptc', 'standard', 'minimal'];
112
+
113
+ function presetRestricted(text) {
114
+ return GATE_MARKERS.some(marker => text.includes(marker));
115
+ }
116
+
117
+ /** Quoted preset ids this code mentions; the base id a restricted plugin accepts. */
118
+ function acceptedPresetIds(text) {
119
+ const found = [];
120
+ for (const id of KNOWN_PRESET_IDS) {
121
+ if (text.includes("'" + id + "'") || text.includes('"' + id + '"')) found.push(id);
122
+ }
123
+ return found;
124
+ }
125
+
126
+ /**
127
+ * Probe one plugin package for the two identity layers. Bounded and cached.
128
+ * @param root - package root.
129
+ * @param nativeId - the native preset id, normally deep-ptc.
130
+ * @returns declares: the package knows the native id; restricted: the package gates on preset ids.
131
+ */
132
+ export function packageProbe(root, nativeId) {
133
+ const key = root + '|' + nativeId;
134
+ if (packageCache.has(key)) return packageCache.get(key);
135
+ let files = 0;
136
+ let bytes = 0;
137
+ const result = { declares: false, restricted: false, accepts: [] };
138
+ const accepts = new Set();
139
+ const visit = directory => {
140
+ if (result.declares || files >= MAX_FILES || bytes >= MAX_TOTAL_BYTES) return;
141
+ let entries;
142
+ try { entries = readdirSync(directory, { withFileTypes: true }); } catch { return; }
143
+ for (const entry of entries) {
144
+ if (result.declares || files >= MAX_FILES || bytes >= MAX_TOTAL_BYTES) return;
145
+ if (entry.name.startsWith('.')) continue;
146
+ const full = join(directory, entry.name);
147
+ if (entry.isDirectory()) {
148
+ if (!SKIP_DIRS.has(entry.name)) visit(full);
149
+ continue;
150
+ }
151
+ if (!entry.isFile() || !isCodeFile(entry.name)) continue;
152
+ let size = 0;
153
+ try { size = statSync(full).size; } catch { continue; }
154
+ if (size <= 0 || size > MAX_FILE_BYTES) continue;
155
+ let text;
156
+ try { text = readFileSync(full, 'utf8'); } catch { continue; }
157
+ if (text.includes(nativeId)) result.declares = true;
158
+ if (presetRestricted(text)) result.restricted = true;
159
+ for (const id of acceptedPresetIds(text)) accepts.add(id);
160
+ files += 1;
161
+ bytes += size;
162
+ }
163
+ };
164
+ visit(root);
165
+ result.accepts = [...accepts];
166
+ packageCache.set(key, result);
167
+ return result;
168
+ }
169
+
170
+ /**
171
+ * Resolve the identity one external consumer should see.
172
+ * @param exact - the live composed preset id.
173
+ * @param options - enabled, nativeIds, fallback, creativeFallback and support overrides.
174
+ * @param info - host flag, package name and declaration probe result.
175
+ * @returns the id to report.
176
+ */
177
+ export function decidePresetId(exact, options = {}, info = {}) {
178
+ const nativeIds = Array.isArray(options.nativeIds) && options.nativeIds.length > 0
179
+ ? options.nativeIds : ['deep-ptc'];
180
+ if (typeof exact !== 'string' || !nativeIds.includes(exact)) return exact;
181
+ if (options.enabled === false) return exact;
182
+ if (info.host === true) return exact;
183
+ const support = options.support && typeof options.support === 'object' && !Array.isArray(options.support)
184
+ ? options.support : {};
185
+ const override = info.packageName === undefined ? undefined : support[info.packageName];
186
+ if (override === 'native') return exact;
187
+ const fallback = options.fallback || 'ptc';
188
+ if (override === 'base') return fallback;
189
+ // Layer 1: a plugin that does not limit preset names, or that declares the native
190
+ // id itself, keeps deep-ptc.
191
+ if (info.declares === true) return exact;
192
+ if (info.restricted !== true) return exact;
193
+ // Layer 2: a plugin that limits preset names gets a base id. ptc is the normal
194
+ // base; a creative-mode row mounted by the plugin lab may accept only cordis,
195
+ // so use the id its own code actually mentions.
196
+ const accepts = Array.isArray(info.accepts) ? info.accepts : [];
197
+ if (accepts.includes(fallback)) return fallback;
198
+ if (accepts.includes(CREATIVE_PRESET_ID)) return CREATIVE_PRESET_ID;
199
+ return fallback;
200
+ }
201
+
202
+ /** Inspect one call: host frame, or the calling plugin package and its declaration. */
203
+ export function inspectCaller(stack, nativeId) {
204
+ const head = String(stack ?? '').split('\n').slice(0, 4).join('\n');
205
+ if (HOST_CALLERS.test(head)) return { host: true };
206
+ const file = callerFile(stack);
207
+ if (!file) return { host: true };
208
+ if (file.includes('app.asar')) return { host: true };
209
+ if (callerCache.has(file)) return callerCache.get(file);
210
+ const pkg = packageOf(file);
211
+ if (pkg === undefined) return { host: true };
212
+ if (pkg.name.startsWith('@deepseek-ai/')) return { host: true };
213
+ const probe = packageProbe(pkg.root, nativeId);
214
+ const info = { host: false, packageName: pkg.name, packageRoot: pkg.root, declares: probe.declares, restricted: probe.restricted, accepts: probe.accepts };
215
+ callerCache.set(file, info);
216
+ return info;
217
+ }
218
+
219
+ function logDecision(info, id) {
220
+ if (!info || typeof info.packageName !== 'string') return;
221
+ const key = info.packageName + '|' + id;
222
+ if (logged.has(key)) return;
223
+ logged.add(key);
224
+ log('decision ' + new Date().toISOString() + ' ' + info.packageName + ' -> ' + id + (info.declares ? ' (declares native)' : info.restricted ? ' (preset restricted -> ' + id + ')' : ' (unrestricted -> native)'));
225
+ }
226
+
227
+ /**
228
+ * Install the identity layer on the live registry. Idempotent: a second mount
229
+ * (plugin startup plus an explicit compatibility row) keeps the first owner and
230
+ * becomes a no-op.
231
+ * @param ctx - plugin context carrying agentPresets.
232
+ * @param options - options object or a getter returning one.
233
+ * @returns owner handle; dispose() restores the unpatched method.
234
+ */
235
+ export function installPresetCompat(ctx, options) {
236
+ const registry = ctx?.agentPresets;
237
+ const current = registry?.composedPreset;
238
+ if (typeof current !== 'function') {
239
+ log('skip ' + new Date().toISOString() + ': agentPresets.composedPreset unavailable');
240
+ return { active: false, owner: false, dispose() {} };
241
+ }
242
+ if (current[PATCH_MARK] === true) return { active: true, owner: false, dispose() {} };
243
+ const hadOwn = Object.hasOwn(registry, 'composedPreset');
244
+ const original = current;
245
+ const patched = function composedPreset(agentCtx) {
246
+ const exact = original.call(registry, agentCtx);
247
+ const now = typeof options === 'function' ? options() : options;
248
+ if (!now || now.enabled === false) return exact;
249
+ const nativeIds = Array.isArray(now.nativeIds) && now.nativeIds.length > 0 ? now.nativeIds : ['deep-ptc'];
250
+ if (typeof exact !== 'string' || !nativeIds.includes(exact)) return exact;
251
+ // A failed probe means 'does not declare the native id', so the consumer still
252
+ // receives the usable base id instead of losing the plugin surface.
253
+ let info = { host: false, declares: false, restricted: true };
254
+ try { info = inspectCaller(new Error().stack ?? '', nativeIds[0]); } catch (error) { log('inspect-error ' + error.message); }
255
+ const id = decidePresetId(exact, now, info);
256
+ logDecision(info, id);
257
+ return id;
258
+ };
259
+ Object.defineProperty(patched, PATCH_MARK, { value: true });
260
+ Object.defineProperty(registry, 'composedPreset', { value: patched, configurable: true, writable: true });
261
+ log('installed ' + new Date().toISOString());
262
+ return {
263
+ active: true,
264
+ owner: true,
265
+ dispose() {
266
+ if (registry.composedPreset !== patched) return;
267
+ if (hadOwn) Object.defineProperty(registry, 'composedPreset', { value: original, configurable: true, writable: true });
268
+ else delete registry.composedPreset;
269
+ log('disposed ' + new Date().toISOString());
270
+ },
271
+ };
272
+ }
273
+
274
+ // Compatibility row entry: mount the same layer explicitly (idempotent).
275
+ export function apply(ctx, config) {
276
+ const compat = installPresetCompat(ctx, {
277
+ enabled: true,
278
+ nativeIds: ['deep-ptc'],
279
+ fallback: config?.fallback ?? 'ptc',
280
+ support: config?.support && typeof config.support === 'object' ? config.support : {},
281
+ });
282
+ ctx.effect(() => () => compat.dispose(), 'Deep PTC: preset identity compatibility');
283
+ }
package/lib/preset.json CHANGED
File without changes
package/lib/reachable.mjs CHANGED
File without changes
package/lib/resident.mjs CHANGED
File without changes
package/lib/rules.mjs CHANGED
File without changes
package/lib/shells.mjs CHANGED
File without changes
File without changes
package/lib/terminal.mjs CHANGED
File without changes
File without changes
File without changes
File without changes
package/lib/upstream.mjs CHANGED
File without changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-deep-ptc-mode",
3
- "version": "1.7.4",
4
- "description": "Lightweight adaptive Deep PTC: live host presets, plugin cooperation and interruptible jobs. / 轻量自适配深度 PTC:动态宿主预设、插件协作与官方兜底、后台可插话。",
3
+ "version": "1.8.0",
4
+ "description": "Lightweight adaptive Deep PTC: session-scoped preset identity (native deep-ptc, base ptc, creative cordis fallback), live host presets, plugin cooperation and interruptible jobs. / 轻量自适配深度 PTC:会话级预设身份兼容(原生 deep-ptc、基座 ptc、创造模式 cordis 兜底)、动态宿主预设、插件协作与后台可插话。",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "dsh-plugin",
@@ -13,6 +13,9 @@
13
13
  "clarification",
14
14
  "background-jobs",
15
15
  "plugin-compatibility",
16
+ "preset-compatibility",
17
+ "dsh-ops",
18
+ "creative-mode",
16
19
  "tool-cooperation",
17
20
  "official-ptc-fallback"
18
21
  ],
@@ -68,6 +71,7 @@
68
71
  "./ask-user": "./lib/ask-user.mjs",
69
72
  "./guard": "./lib/guard.mjs",
70
73
  "./tool-compatibility": "./lib/tool-compatibility.mjs",
74
+ "./preset-compat": "./lib/preset-compat.mjs",
71
75
  "./environment": "./lib/environment.mjs",
72
76
  "./lab": "./lib/lab.mjs",
73
77
  "./client": "./lib/client.js",