dsh-deep-ptc-mode 1.7.3 → 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/lib/shells.mjs ADDED
@@ -0,0 +1,114 @@
1
+ // Filesystem probe for shell executables. Callers supply exists/where; this module never spawns.
2
+
3
+ export const AUTO_SHELL = '';
4
+
5
+ const BASH_CANDIDATES = ['/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash', '/opt/homebrew/bin/bash'];
6
+ const ZSH_CANDIDATES = ['/bin/zsh', '/usr/bin/zsh', '/usr/local/bin/zsh', '/opt/homebrew/bin/zsh'];
7
+
8
+ function pathKey(filePath, platform) {
9
+ if (platform === 'win32') return String(filePath).replace(/[\\/]+/gu, '\\').toLowerCase();
10
+ return String(filePath).replace(/\/+/gu, '/');
11
+ }
12
+
13
+ function rootKey(root, platform) {
14
+ return pathKey(String(root).replace(/[\\/]+$/gu, ''), platform);
15
+ }
16
+
17
+ function winJoin(root, tail) {
18
+ return `${String(root).replace(/[\\/]+$/gu, '')}\\${tail}`;
19
+ }
20
+
21
+ function located(where, name) {
22
+ try {
23
+ const found = where(name);
24
+ if (!Array.isArray(found)) return [];
25
+ return found.filter(item => typeof item === 'string' && item.length > 0);
26
+ } catch {
27
+ return [];
28
+ }
29
+ }
30
+
31
+ function addShell(shells, seen, platform, exists, filePath, label, family) {
32
+ if (typeof filePath !== 'string' || filePath.length === 0) return;
33
+ const key = pathKey(filePath, platform);
34
+ if (seen.has(key) || !exists(filePath)) return;
35
+ seen.add(key);
36
+ shells.push({ id: `path:${filePath}`, label, path: filePath, family });
37
+ }
38
+
39
+ function bashLabel(filePath, platform) {
40
+ return platform === 'darwin' && filePath === '/bin/bash' ? 'bash (system)' : 'bash';
41
+ }
42
+
43
+ function zshLabel(filePath) {
44
+ return filePath === '/bin/zsh' ? 'zsh (system)' : 'zsh';
45
+ }
46
+
47
+ function envPath(env, key, fallback) {
48
+ const value = env?.[key];
49
+ return typeof value === 'string' && value !== '' ? value : fallback;
50
+ }
51
+
52
+ export function discoverShells({ platform, env = {}, exists, where }) {
53
+ const shells = [];
54
+ const seen = new Set();
55
+ const add = (filePath, label, family) => addShell(shells, seen, platform, exists, filePath, label, family);
56
+
57
+ if (platform === 'win32') {
58
+ const systemRoot = envPath(env, 'SystemRoot', 'C:\\Windows');
59
+ const programFiles = envPath(env, 'ProgramFiles', 'C:\\Program Files');
60
+ add(winJoin(systemRoot, 'System32\\WindowsPowerShell\\v1.0\\powershell.exe'), 'Windows PowerShell 5.1', 'powershell');
61
+ const roots = [programFiles];
62
+ const programW6432 = env?.ProgramW6432;
63
+ if (typeof programW6432 === 'string' && programW6432 !== '' && rootKey(programW6432, platform) !== rootKey(programFiles, platform)) {
64
+ roots.push(programW6432);
65
+ }
66
+ for (const root of roots) {
67
+ add(winJoin(root, 'PowerShell\\7\\pwsh.exe'), 'PowerShell 7', 'powershell');
68
+ add(winJoin(root, 'PowerShell\\7-preview\\pwsh.exe'), 'PowerShell 7 Preview', 'powershell');
69
+ }
70
+ for (const name of ['pwsh.exe', 'pwsh']) {
71
+ for (const filePath of located(where, name)) add(filePath, 'PowerShell (pwsh)', 'powershell');
72
+ }
73
+ return shells;
74
+ }
75
+
76
+ if (platform === 'darwin' || platform === 'linux') {
77
+ for (const filePath of BASH_CANDIDATES) add(filePath, bashLabel(filePath, platform), 'bash');
78
+ for (const filePath of located(where, 'bash')) add(filePath, bashLabel(filePath, platform), 'bash');
79
+ for (const filePath of ZSH_CANDIDATES) add(filePath, zshLabel(filePath), 'zsh');
80
+ for (const filePath of located(where, 'zsh')) add(filePath, zshLabel(filePath), 'zsh');
81
+ }
82
+ return shells;
83
+ }
84
+
85
+ export function resolveShellExecutable(value, { family, discovered, exists }) {
86
+ if (value === undefined || value === '' || value === 'auto') return AUTO_SHELL;
87
+ if (!Array.isArray(discovered)) return '';
88
+ for (const item of discovered) {
89
+ if (item?.family !== family || (item.id !== value && item.path !== value)) continue;
90
+ if (typeof item.path !== 'string' || exists(item.path) === false) return '';
91
+ return item.path;
92
+ }
93
+ return '';
94
+ }
95
+
96
+ function fileNameIs(filePath, name) {
97
+ const normalized = String(filePath).replace(/[\\/]+/gu, '/');
98
+ const slash = normalized.lastIndexOf('/');
99
+ const base = slash === -1 ? normalized : normalized.slice(slash + 1);
100
+ return base.toLowerCase() === name;
101
+ }
102
+
103
+ export function shellNote({ family, executable }) {
104
+ if (typeof executable !== 'string' || executable === '') return '';
105
+ if (family === 'powershell' && fileNameIs(executable, 'powershell.exe')) {
106
+ return `Windows PowerShell 5.1 at ${executable} uses Windows PowerShell syntax, not PowerShell 7.`;
107
+ }
108
+ if (family === 'powershell' && fileNameIs(executable, 'pwsh.exe')) {
109
+ return `PowerShell 7+ at ${executable} uses pwsh syntax.`;
110
+ }
111
+ if (family === 'bash') return `The bash tool uses ${executable} with bash -c.`;
112
+ if (family === 'zsh') return `The zsh tool uses ${executable} with zsh -lc.`;
113
+ return '';
114
+ }
File without changes
package/lib/terminal.mjs CHANGED
File without changes
File without changes
File without changes
@@ -1,4 +1,5 @@
1
1
  import { DIRECTORY_TOOL, blankState, toolSchema, searchCatalog } from './tool-catalog.mjs';
2
+ import { staysResident } from './resident.mjs';
2
3
  const officialDefinitions = new WeakMap();
3
4
  const validName = name => typeof name === 'string' && name.length > 0 && name.length <= 256 && !/[\u0000-\u001f]/u.test(name);
4
5
  const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
@@ -97,8 +98,10 @@ export function createCompatibilityState(tools, preferences = [], storage = {},
97
98
  const declaredExternal = def => typeof def?.deepPtc?.provider === 'string' && !def.deepPtc.provider.startsWith('@deepseek-ai/');
98
99
  const official = def => !!def && (isOfficialTool(def) || (!declaredExternal(def) && directory.isOfficial?.(def.name) === true));
99
100
  const external = def => !!def && !official(def) && (typeof def.deepPtc?.provider === 'string' || directory.isExternal?.(def.name) === true || (typeof directory.providerOf?.(def.name) === 'string' && !directory.providerOf(def.name).startsWith('@deepseek-ai/')));
101
+ const resident = def => staysResident(def, directory.providerOf?.(def?.name) ?? '');
100
102
  const protectedName = (agent, name) => {
101
103
  const def = tools.get(name, agent);
104
+ if (def && resident(def)) return true;
102
105
  return def ? !external(def) : directory.isOfficial?.(name) === true;
103
106
  };
104
107
  const usableState = agent => {
@@ -123,7 +126,7 @@ export function createCompatibilityState(tools, preferences = [], storage = {},
123
126
  observe(exec, result) {
124
127
  const call = calls.get(exec);
125
128
  // No definition means the name never belonged to a plugin, so there is nothing to quarantine.
126
- if (!call?.definition || call.official || exec.name === DIRECTORY_TOOL || exec.name === 'run_code') return;
129
+ if (!call?.definition || call.official || resident(call.definition) || exec.name === DIRECTORY_TOOL || exec.name === 'run_code') return;
127
130
  const row = entry(exec.agent);
128
131
  if (!row || call.epoch !== row.state.epoch || blocked(exec.agent, exec.name)) return;
129
132
  const outcome = classifyToolOutcome(exec, result);
@@ -155,7 +158,7 @@ export function createCompatibilityState(tools, preferences = [], storage = {},
155
158
  const row = entry(agent);
156
159
  const excluded = new Set(usableState(agent).blocked.map(item => item.name));
157
160
  return definitions(agent, toolSet).filter(def => !excluded.has(def.name)
158
- && (!compact || !external(def) || def.name === DIRECTORY_TOOL || row?.selected.has(def.name)));
161
+ && (!compact || !external(def) || def.name === DIRECTORY_TOOL || row?.selected.has(def.name) || resident(def)));
159
162
  },
160
163
  search(agent, args, toolSet) {
161
164
  const excluded = new Set(usableState(agent).blocked.map(item => item.name));
package/lib/upstream.mjs CHANGED
@@ -5,9 +5,10 @@
5
5
  // and the plugin only replaces the parts it actually owns (persona, execution
6
6
  // environment, reachability guard, job/question wrappers).
7
7
  import { createRequire } from 'node:module';
8
- import { existsSync, readFileSync } from 'node:fs';
8
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
9
9
  import { fileURLToPath, pathToFileURL } from 'node:url';
10
10
  import { dirname, join, isAbsolute, resolve } from 'node:path';
11
+ import { CREATIVE_PRESET_ID, selectCreativePreset } from './creative.mjs';
11
12
 
12
13
  export const OFFICIAL_PACKAGE = '@deepseek-ai/dsh-web-app';
13
14
  const PACKAGE = OFFICIAL_PACKAGE;
@@ -197,6 +198,85 @@ export function loadOfficialPreset({ presetPath } = {}) {
197
198
  return { preset: parseOfficialPreset(text), source: url };
198
199
  }
199
200
 
201
+ function pluginRows(value) {
202
+ return Array.isArray(value) && value.length > 0
203
+ && value.every(row => row && typeof row === 'object' && typeof row.name === 'string');
204
+ }
205
+
206
+ /** A creative-mode composition list, or the creative preset inside a patch document. */
207
+ export function parseCreativeDocument(text) {
208
+ const document = loadYaml().load(text, { schema: presetSchema() });
209
+ if (pluginRows(document)) return document;
210
+ const layers = Array.isArray(document) ? document : [];
211
+ const inserted = [];
212
+ const collect = rows => {
213
+ if (!Array.isArray(rows)) return;
214
+ for (const row of rows) if (row && typeof row === 'object') inserted.push(row);
215
+ };
216
+ collect(layers);
217
+ for (const layer of layers) collect(layer?.insert);
218
+ const presets = inserted.map(row => row.config).filter(config => config && pluginRows(config.plugins));
219
+ const preset = presets.find(config => config.id === CREATIVE_PRESET_ID || config.name === '创造模式');
220
+ if (!preset) throw new Error('installed creative preset has no composition');
221
+ return preset.plugins;
222
+ }
223
+
224
+ function compositionRoot(path) {
225
+ if (typeof path !== 'string' || path === '') return '';
226
+ try {
227
+ return dirname(path.startsWith('file:') ? fileURLToPath(path) : path);
228
+ } catch {
229
+ return '';
230
+ }
231
+ }
232
+
233
+ /**
234
+ * File URL of the shipped creative preset.
235
+ * The directory id is the same kind of key as `ptc`. The composition filename is whatever
236
+ * that directory actually contains, so an official rename of the file still resolves.
237
+ */
238
+ export function creativePresetUrl() {
239
+ const pkg = tryResolve('@deepseek-ai/dsh-agent-presets/package.json');
240
+ if (pkg === undefined) return undefined;
241
+ const dir = join(dirname(fileURLToPath(pkg)), 'presets', CREATIVE_PRESET_ID);
242
+ if (!existsSync(dir)) return undefined;
243
+ let names = [];
244
+ try { names = readdirSync(dir).filter(name => name.endsWith('.yml') || name.endsWith('.yaml')); } catch { return undefined; }
245
+ const named = names.find(name => name.startsWith('agent.')) ?? names[0];
246
+ return named === undefined ? undefined : pathToFileURL(join(dir, named)).href;
247
+ }
248
+
249
+ /**
250
+ * Read the creative preset the running host publishes.
251
+ * Module names come from that document. An unreadable preset throws so the caller can keep PTC only.
252
+ */
253
+ export async function loadCreativePreset(registry) {
254
+ let roster = [];
255
+ if (typeof registry?.list === 'function') {
256
+ try { roster = await registry.list(); } catch { roster = []; }
257
+ }
258
+ const selected = selectCreativePreset(roster);
259
+ if (!process.env[PRESET_PATH_ENV]?.trim() && selected && typeof registry?.readDocument === 'function') {
260
+ const document = await registry.readDocument(selected.id);
261
+ return {
262
+ plugins: parseCreativeDocument(document.content),
263
+ root: compositionRoot(selected.path),
264
+ source: `agentPresets.readDocument(${selected.id})`,
265
+ };
266
+ }
267
+ if (typeof selected?.path === 'string' && selected.path !== '' && existsSync(selected.path.startsWith('file:') ? fileURLToPath(selected.path) : selected.path)) {
268
+ const file = selected.path.startsWith('file:') ? fileURLToPath(selected.path) : selected.path;
269
+ return { plugins: parseCreativeDocument(readFileSync(file, 'utf8')), root: dirname(file), source: file };
270
+ }
271
+ const url = creativePresetUrl();
272
+ if (url === undefined) throw new Error('creative preset is not installed');
273
+ return {
274
+ plugins: parseCreativeDocument(readFileSync(fileURLToPath(url), 'utf8')),
275
+ root: dirname(fileURLToPath(url)),
276
+ source: url,
277
+ };
278
+ }
279
+
200
280
  /** Prefer the running host's public preset registry, including its live composition. */
201
281
  export async function loadCurrentPreset(registry) {
202
282
  if (!process.env[PRESET_PATH_ENV]?.trim() && typeof registry?.readDocument === 'function') {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-deep-ptc-mode",
3
- "version": "1.7.3",
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,7 +71,9 @@
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",
76
+ "./lab": "./lib/lab.mjs",
72
77
  "./client": "./lib/client.js",
73
78
  "./package.json": "./package.json"
74
79
  },