dsh-deep-ptc-mode 1.7.2 → 1.7.4
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 +105 -71
- package/README.md +204 -174
- package/README.zh.md +219 -189
- package/TEST_REPORT.md +33 -0
- package/lib/ask-user.mjs +2 -1
- package/lib/client.js +59 -9
- package/lib/creative.mjs +127 -0
- package/lib/environment.mjs +2 -1
- package/lib/executor.mjs +31 -6
- package/lib/guard.mjs +2 -1
- package/lib/host.mjs +25 -17
- package/lib/index.mjs +105 -11
- package/lib/jobs-tool.mjs +2 -1
- package/lib/lab.mjs +13 -0
- package/lib/model.mjs +47 -21
- package/lib/official-names.mjs +115 -0
- package/lib/resident.mjs +27 -0
- package/lib/rules.mjs +5 -5
- package/lib/shells.mjs +114 -0
- package/lib/sleep-lint.mjs +391 -41
- package/lib/tool-catalog.mjs +1 -1
- package/lib/tool-compatibility.mjs +29 -11
- package/lib/tool-policy.mjs +250 -184
- package/lib/upstream.mjs +94 -1
- package/package.json +127 -125
- package/lib/official-tools.mjs +0 -8
package/lib/model.mjs
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// never leaves a stale module name behind.
|
|
9
9
|
import snapshot from './preset.json' with { type: 'json' };
|
|
10
10
|
import baseSnapshot from './base-snapshot.json' with { type: 'json' };
|
|
11
|
+
import { creativeAdditions } from './creative.mjs';
|
|
11
12
|
import { normalizePreferences } from './tool-policy.mjs';
|
|
12
13
|
|
|
13
14
|
export const ENVIRONMENTS = ['auto', 'wsl', 'powershell', 'zsh', 'bash'];
|
|
@@ -34,14 +35,16 @@ export function normalizeDistribution(value = '') {
|
|
|
34
35
|
return distribution;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export function shellArgv(environment, spec, distribution = '', platform = process.platform) {
|
|
38
|
+
export function shellArgv(environment, spec, distribution = '', platform = process.platform, executable = '') {
|
|
38
39
|
if (environment === 'wsl') {
|
|
39
40
|
if (platform !== 'win32') throw new Error('WSL requires a Windows host');
|
|
40
41
|
const distro = normalizeDistribution(distribution);
|
|
41
42
|
return ['wsl.exe', ...(distro ? ['--distribution', distro] : []),
|
|
42
43
|
'--cd', spec.workdir, '--exec', 'bash', '-lc', spec.command];
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
+
const binary = typeof executable === 'string' ? executable : '';
|
|
46
|
+
if (environment === 'zsh') return [binary || (platform === 'darwin' ? '/bin/zsh' : 'zsh'), '-lc', spec.command];
|
|
47
|
+
if (environment === 'bash' && binary) return [binary, '-c', spec.command];
|
|
45
48
|
throw new Error(`No mapped executor for ${environment}`);
|
|
46
49
|
}
|
|
47
50
|
|
|
@@ -51,7 +54,7 @@ export function assertExecutionPolicy(environment, policy) {
|
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
export function environmentText(environment, distribution = '') {
|
|
57
|
+
export function environmentText(environment, distribution = '', note = '') {
|
|
55
58
|
const descriptions = {
|
|
56
59
|
wsl: `Execution environment: WSL Bash${distribution ? ` (${distribution})` : ' (Windows default distribution)'}. The bash tool runs POSIX source via wsl.exe and bash -lc. File tools and the tool workdir use Windows host paths; Linux paths belong inside command source. WSL is available only in danger-full-access; a confined call fails without execution. Never silently fall back to PowerShell or another distribution.`,
|
|
57
60
|
powershell: 'Execution environment: native Windows PowerShell. Use the pwsh tool and PowerShell syntax, native Windows paths and $env:NAME. This selection takes precedence over older workspace guidance that assumed WSL. The configured sandbox and approval policy still apply.',
|
|
@@ -59,7 +62,7 @@ export function environmentText(environment, distribution = '') {
|
|
|
59
62
|
bash: 'Execution environment: native Bash on macOS/Linux. Use the bash tool with Bash/POSIX command source and native host paths. This is not WSL. The configured sandbox and approval policy still apply.',
|
|
60
63
|
};
|
|
61
64
|
if (!descriptions[environment]) throw new Error(`Unknown environment ${environment}`);
|
|
62
|
-
return descriptions[environment];
|
|
65
|
+
return typeof note === 'string' && note !== '' ? `${descriptions[environment]}\n${note}` : descriptions[environment];
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
export const DEFAULT_FOREGROUND_SECONDS = 30;
|
|
@@ -148,11 +151,15 @@ export function isShellRow(row) {
|
|
|
148
151
|
return row.group !== true && (SHELL_ROWS.names.includes(row.name) || SHELL_ROWS.ids.includes(row.id));
|
|
149
152
|
}
|
|
150
153
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
// The desktop already mounts this host service. Copying it into the session would start a second one.
|
|
155
|
+
function isHostRunner(row) {
|
|
156
|
+
return row?.id === 'dynamicCordisRunner'
|
|
157
|
+
|| (typeof row?.name === 'string' && row.name.includes('cordis-host-runner'));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function chosenExecutable(environment, value) {
|
|
161
|
+
if (environment !== 'powershell' && environment !== 'bash' && environment !== 'zsh') return '';
|
|
162
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
156
163
|
}
|
|
157
164
|
|
|
158
165
|
function findRow(rows, { ids = [], names = [] }) {
|
|
@@ -223,6 +230,14 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
223
230
|
report.persona = 'replaced';
|
|
224
231
|
}
|
|
225
232
|
|
|
233
|
+
// Safe mode is the official composition plus the persona, for a host where the rest cannot mount.
|
|
234
|
+
if (options.safeMode === true) {
|
|
235
|
+
report.environment = 'official';
|
|
236
|
+
report.skipped.push('safe mode: official composition with the Deep PTC persona');
|
|
237
|
+
return { preset: { ...upstream, id: PRESET_META.id, name: PRESET_META.name, order: PRESET_META.order,
|
|
238
|
+
description: `${PRESET_META.description} 当前为安全模式`, plugins }, report };
|
|
239
|
+
}
|
|
240
|
+
|
|
226
241
|
// Execution environment: replace the official shell rows (wherever the official preset nests them)
|
|
227
242
|
// with the selectable execution group in the same place. The group runs the official shell tool
|
|
228
243
|
// and executor the installed Harness names; when they cannot be mapped, the official rows stay.
|
|
@@ -230,7 +245,8 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
230
245
|
const executors = { ...BASE_SNAPSHOT, ...(options.executors ?? {}) };
|
|
231
246
|
const tool = findRow(plugins, SHELL_TOOLS[kind]);
|
|
232
247
|
const official = executors[kind];
|
|
233
|
-
const
|
|
248
|
+
const shellPath = chosenExecutable(environment, options.shellExecutable);
|
|
249
|
+
const mapped = environment === 'wsl' || environment === 'zsh' || (environment === 'bash' && shellPath !== '');
|
|
234
250
|
const unusable = tool === undefined ? `the official PTC preset has no ${kind} tool row`
|
|
235
251
|
: typeof official?.name !== 'string' ? `the installed Harness declares no ${kind} executor`
|
|
236
252
|
: mapped && options.mappedExecutor === false ? `the official bash executor cannot be extended for ${environment}`
|
|
@@ -263,9 +279,11 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
263
279
|
// With background jobs available, the executor timeout only decides when a foreground command
|
|
264
280
|
// moves to the background; the official tools run such commands with onExpiry: none.
|
|
265
281
|
const executorOptions = { ...(official.config ?? {}), timeoutMs: foregroundMs, maxTimeoutMs: foregroundMs };
|
|
282
|
+
if (environment === 'powershell' && shellPath) executorOptions.pwshPath = shellPath;
|
|
266
283
|
const executor = mapped
|
|
267
284
|
? { id: 'executor', name: 'dsh-deep-ptc-mode/executor',
|
|
268
|
-
config: { environment, wslDistribution: distribution, base: official.name, options: executorOptions
|
|
285
|
+
config: { environment, wslDistribution: distribution, base: official.name, options: executorOptions,
|
|
286
|
+
...shellPath ? { shellExecutable: shellPath } : {} } }
|
|
269
287
|
: { id: 'executor', name: official.name, config: executorOptions };
|
|
270
288
|
const terminal = {
|
|
271
289
|
id: environment === 'zsh' ? 'tool-zsh' : tool.id ?? `tool-${kind}`,
|
|
@@ -279,7 +297,8 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
279
297
|
rows.push({
|
|
280
298
|
id: uniqueRowId(plugins, 'execution'), name: 'cordis:group', group: true, isolate: { shell: true },
|
|
281
299
|
config: [executor, terminal, { id: 'execution-instructions', name: 'dsh-deep-ptc-mode/environment',
|
|
282
|
-
config: { environment, wslDistribution: distribution
|
|
300
|
+
config: { environment, wslDistribution: distribution,
|
|
301
|
+
...typeof options.shellNote === 'string' && options.shellNote !== '' ? { shellNote: options.shellNote } : {} } }],
|
|
283
302
|
});
|
|
284
303
|
}
|
|
285
304
|
rows.push({
|
|
@@ -298,26 +317,33 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
298
317
|
}
|
|
299
318
|
const upstreamName = row.name;
|
|
300
319
|
row.name = target.replacement;
|
|
301
|
-
row.config = { upstream: upstreamName,
|
|
320
|
+
row.config = { upstream: upstreamName, ...row.config === undefined ? {} : { options: row.config }, overrides: target.options(foregroundMs) };
|
|
302
321
|
report.wrapped.push(`${target.key} (${upstreamName})`);
|
|
303
322
|
}
|
|
304
323
|
|
|
305
|
-
//
|
|
306
|
-
|
|
307
|
-
walkRows(plugins, row => {
|
|
308
|
-
if (
|
|
309
|
-
|
|
310
|
-
row.name = 'dsh-deep-ptc-mode/official-tools';
|
|
311
|
-
row.config = { upstream: upstreamName, ...row.config === undefined ? {} : { options: row.config } };
|
|
324
|
+
// Official rows stay exactly as declared. Tool discovery learns their tools from these module names.
|
|
325
|
+
const officialModules = [];
|
|
326
|
+
walkRows(upstream.plugins, row => {
|
|
327
|
+
if (row.group === true || typeof row.name !== 'string' || row.disabled === true) return;
|
|
328
|
+
officialModules.push({ name: row.name, ...typeof row.config?.toolName === 'string' ? { toolName: row.config.toolName } : {} });
|
|
312
329
|
});
|
|
313
330
|
plugins.push({
|
|
314
331
|
id: uniqueRowId(plugins, 'tool-compatibility'), name: 'dsh-deep-ptc-mode/tool-compatibility',
|
|
315
332
|
config: { enabled: options.toolCompatibility !== false, preferences: toolPreferences,
|
|
316
|
-
compact: options.compactToolCatalog !== false,
|
|
333
|
+
compact: options.compactToolCatalog !== false, officialModules,
|
|
317
334
|
sdkProvider: findRow(upstream.plugins, {ids:['tool-executor-ptc'],names:['@deepseek-ai/dsh-tool-executor-ptc']})?.name ?? '@deepseek-ai/dsh-tool-executor-ptc',
|
|
318
335
|
skillProvider: findRow(upstream.plugins, {ids:['tool-skill'],names:['@deepseek-ai/dsh-tool-skill']})?.name ?? '@deepseek-ai/dsh-tool-skill' },
|
|
319
336
|
});
|
|
320
337
|
|
|
338
|
+
if (options.pluginLab === true) {
|
|
339
|
+
const additions = creativeAdditions(options.creativePlugins, plugins, {
|
|
340
|
+
root: typeof options.creativeRoot === 'string' ? options.creativeRoot : '',
|
|
341
|
+
}).filter(row => !isHostRunner(row));
|
|
342
|
+
plugins.push(...additions);
|
|
343
|
+
plugins.push({ id: uniqueRowId(plugins, 'plugin-lab'), name: 'dsh-deep-ptc-mode/lab' });
|
|
344
|
+
report.pluginLab = additions.map(row => `${row.id} (${row.name})`);
|
|
345
|
+
}
|
|
346
|
+
|
|
321
347
|
const description = `${PRESET_META.description} 当前环境:${environment}${environment === 'wsl' && distribution ? ` (${distribution})` : ''}`;
|
|
322
348
|
return {
|
|
323
349
|
preset: {
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Name the tools each composed plugin declares. The host records no owner for a registration, so this
|
|
2
|
+
// reads the installed source of the loader's rows and the preset's official rows. Reading follows every
|
|
3
|
+
// Harness and plugin update without running a module, and a name that cannot be read only stays an
|
|
4
|
+
// unattributed external tool.
|
|
5
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { resolveHost } from './host.mjs';
|
|
9
|
+
|
|
10
|
+
export const OFFICIAL_SCOPE = '@deepseek-ai/';
|
|
11
|
+
const OWN_PACKAGE = 'dsh-deep-ptc-mode';
|
|
12
|
+
const REFRESH_MS = 1000;
|
|
13
|
+
const DECLARED = /(?:defineTool|tools\.register)\(\{\s*name:\s*(?:"([^"]+)"|'([^']+)'|([A-Za-z_$][\w$]*))/gu;
|
|
14
|
+
const escapeRegExp = text => text.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
15
|
+
|
|
16
|
+
function identifierValue(source, identifier) {
|
|
17
|
+
const id = escapeRegExp(identifier);
|
|
18
|
+
// `const NAME = "x"`, or a configurable name with its default: `toolName: z.string().default("x")`.
|
|
19
|
+
return new RegExp(`\\b(?:const|let|var)\\s+${id}\\s*=\\s*["']([^"']+)["']`, 'u').exec(source)?.[1]
|
|
20
|
+
?? new RegExp(`\\b${id}\\b[^\\n;]*?(?:\\.default\\(|\\?\\?\\s*)["']([^"']+)["']`, 'u').exec(source)?.[1];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function toolNamesInSource(source) {
|
|
24
|
+
const names = new Set();
|
|
25
|
+
for (const match of source.matchAll(DECLARED)) {
|
|
26
|
+
const name = match[1] ?? match[2] ?? identifierValue(source, match[3]);
|
|
27
|
+
if (name !== undefined) names.add(name);
|
|
28
|
+
}
|
|
29
|
+
// A local factory may pass its first argument directly to defineTool's name.
|
|
30
|
+
for(const call of source.matchAll(/tools\.register\(\s*([A-Za-z_$][\w$]*)\(\s*["']([^"']+)["']/gu)){
|
|
31
|
+
const helper=escapeRegExp(call[1]);
|
|
32
|
+
const factory=new RegExp('(?:const|let|var)\\s+'+helper+'\\s*=\\s*\\(\\s*([A-Za-z_$][\\w$]*)[^)]*\\)\\s*=>\\s*defineTool\\(\\{\\s*name:\\s*([A-Za-z_$][\\w$]*)','u').exec(source);
|
|
33
|
+
if(factory && factory[1]===factory[2])names.add(call[2]);
|
|
34
|
+
}
|
|
35
|
+
return names;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const sourceCache = new Map();
|
|
39
|
+
function installedSource(moduleName, base) {
|
|
40
|
+
let file;
|
|
41
|
+
if (base !== undefined) {
|
|
42
|
+
try {
|
|
43
|
+
file = createRequire(base).resolve(moduleName);
|
|
44
|
+
} catch {
|
|
45
|
+
// Not installed beside this tree; the runtime's own graph may still hold it.
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (file === undefined) {
|
|
49
|
+
const url = resolveHost(moduleName);
|
|
50
|
+
if (url !== undefined) file = fileURLToPath(url);
|
|
51
|
+
}
|
|
52
|
+
const stat=statSync(file); const stamp=`${file}:${stat.mtimeMs}:${stat.ctimeMs}:${stat.size}`;
|
|
53
|
+
let row=sourceCache.get(file); if(row?.stamp!==stamp){row={stamp,text:readFileSync(file,'utf8')};sourceCache.set(file,row);}
|
|
54
|
+
return row;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Attribute tool names to the modules that declare them.
|
|
59
|
+
* @param getLoader - current root loader, whose rows hold the profile's tools.
|
|
60
|
+
* @param modules - the preset's official rows, `{ name, toolName? }`, which the root loader does not list.
|
|
61
|
+
* @param readSource - source reader, replaced in tests.
|
|
62
|
+
* @param base - resolution base for `modules`.
|
|
63
|
+
*/
|
|
64
|
+
export function toolDirectory(getLoader, { modules = [], readSource = installedSource, base, refreshMs = REFRESH_MS } = {}) {
|
|
65
|
+
const scanned = new Map();
|
|
66
|
+
const namesIn = (moduleName, rowBase) => {
|
|
67
|
+
const key=moduleName+'\0'+String(rowBase ?? '');
|
|
68
|
+
try {
|
|
69
|
+
const read=readSource(moduleName,rowBase);
|
|
70
|
+
const text=typeof read==='string'?read:read.text;
|
|
71
|
+
const stamp=typeof read==='string'?read:read.stamp;
|
|
72
|
+
let cached=scanned.get(key);
|
|
73
|
+
if(!cached || cached.stamp!==stamp){cached={stamp,names:toolNamesInSource(text)};scanned.set(key,cached);}
|
|
74
|
+
return cached.names;
|
|
75
|
+
} catch { scanned.delete(key);return new Set(); }
|
|
76
|
+
};
|
|
77
|
+
let view;
|
|
78
|
+
let viewedAt = -Infinity;
|
|
79
|
+
const refresh = () => {
|
|
80
|
+
if (view !== undefined && Date.now() - viewedAt < refreshMs) return view;
|
|
81
|
+
const official = new Set();
|
|
82
|
+
const providers = new Map();
|
|
83
|
+
const add = (name, moduleName, isOfficial) => {
|
|
84
|
+
if (isOfficial) official.add(name);
|
|
85
|
+
if (isOfficial || !providers.has(name)) providers.set(name, moduleName);
|
|
86
|
+
};
|
|
87
|
+
let entries = [];
|
|
88
|
+
try {
|
|
89
|
+
entries = [...getLoader()?.entries?.() ?? []];
|
|
90
|
+
} catch {
|
|
91
|
+
// Attribution is optional; without rows every tool simply stays unattributed.
|
|
92
|
+
}
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
const moduleName = entry.options?.name;
|
|
95
|
+
if (entry.disabled || typeof moduleName !== 'string' || moduleName.startsWith('cordis:') || moduleName.startsWith(OWN_PACKAGE)) continue;
|
|
96
|
+
const isOfficial = moduleName.startsWith(OFFICIAL_SCOPE);
|
|
97
|
+
for (const name of namesIn(moduleName, entry.parent?.tree?.ctx?.baseUrl)) add(name, moduleName, isOfficial);
|
|
98
|
+
// Tools named by their row's configuration, such as the subagent tools.
|
|
99
|
+
if (typeof entry.options.config?.toolName === 'string') add(entry.options.config.toolName, moduleName, isOfficial);
|
|
100
|
+
}
|
|
101
|
+
for (const { name: moduleName, toolName } of modules) {
|
|
102
|
+
for (const name of namesIn(moduleName, base)) add(name, moduleName, true);
|
|
103
|
+
if (typeof toolName === 'string') add(toolName, moduleName, true);
|
|
104
|
+
}
|
|
105
|
+
view = { official, providers };
|
|
106
|
+
viewedAt = Date.now();
|
|
107
|
+
return view;
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
isOfficial: name => refresh().official.has(name),
|
|
111
|
+
providerOf: name => refresh().providers.get(name),
|
|
112
|
+
isExternal: name => { const view=refresh(); const provider=view.providers.get(name); return !!provider && !view.official.has(name) && !provider.startsWith(OFFICIAL_SCOPE); },
|
|
113
|
+
namesOf: moduleName => namesIn(moduleName, base),
|
|
114
|
+
};
|
|
115
|
+
}
|
package/lib/resident.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Which external tools stay in the initial PTC SDK and are never quarantined.
|
|
2
|
+
// Any plugin can opt in with `resident: true`. Screen-control tools are recognised
|
|
3
|
+
// from their own definition or provider string, not from a pinned package list.
|
|
4
|
+
|
|
5
|
+
const SCREEN_NAMES = new Set(['intent', 'collect', 'tap_xy']);
|
|
6
|
+
const PROVIDER_MARK = /dsh-go|screen-control|computer-use|phone-control/iu;
|
|
7
|
+
|
|
8
|
+
function presentationOf(definition) {
|
|
9
|
+
const presentation = definition.presentationMeta ?? definition.presentation;
|
|
10
|
+
return presentation && typeof presentation === 'object' ? presentation : undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {object | null | undefined} definition live tool definition
|
|
15
|
+
* @param {string} [provider] module or plugin that declared it
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
18
|
+
export function staysResident(definition, provider = '') {
|
|
19
|
+
if (!definition || typeof definition !== 'object') return false;
|
|
20
|
+
if (definition.resident === true || definition.deepPtc?.resident === true) return true;
|
|
21
|
+
const presentation = presentationOf(definition);
|
|
22
|
+
if (presentation && Object.prototype.hasOwnProperty.call(presentation, 'dsh-go/view')) return true;
|
|
23
|
+
const name = typeof definition.name === 'string' ? definition.name : '';
|
|
24
|
+
if (SCREEN_NAMES.has(name) || name.startsWith('screen_')) return true;
|
|
25
|
+
const owner = `${provider}\n${typeof definition.deepPtc?.provider === 'string' ? definition.deepPtc.provider : ''}`;
|
|
26
|
+
return PROVIDER_MARK.test(owner);
|
|
27
|
+
}
|
package/lib/rules.mjs
CHANGED
|
@@ -10,12 +10,12 @@ export function reachabilityText(config) {
|
|
|
10
10
|
|
|
11
11
|
- A foreground command still running after ${config.foregroundSeconds} s, or still running when the user sends a message, moves to a background job by itself. A command reported as moved to the background after only a few seconds means a user message is waiting: finish the current step quickly and answer it.
|
|
12
12
|
- job_output waits end as soon as the user sends a message, and waiting again while that message is unread is refused.
|
|
13
|
-
- Pauses longer than ${MAX_PAUSE_SECONDS} s are refused: sleep or Start-Sleep in foreground
|
|
13
|
+
- Pauses longer than ${MAX_PAUSE_SECONDS} s are refused: a real sleep or Start-Sleep command in the foreground, and a timer the program awaits in run_code. Text in strings, comments and arguments does not count. Polling one running job more than ${config.maxPollsPerProgram} times in one run_code program is refused.
|
|
14
14
|
- ask_user_question waits at most ${config.maxQuestionSeconds} s (timeout is in seconds; -1 is refused). An unanswered question becomes pending, the user can still answer it, and a message the user writes instead ends the wait.`;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// Returns the denial reason for one tool execution, or undefined to allow it.
|
|
18
|
-
export function reachabilityGuard(config, jobsOf = () => undefined) {
|
|
18
|
+
export function reachabilityGuard(config, jobsOf = () => undefined, languageOf = () => undefined) {
|
|
19
19
|
const polls = new Map();
|
|
20
20
|
const countPoll = (rootCallId, jobId) => {
|
|
21
21
|
const key = `${rootCallId}\u0000${jobId}`;
|
|
@@ -28,13 +28,13 @@ export function reachabilityGuard(config, jobsOf = () => undefined) {
|
|
|
28
28
|
return exec => {
|
|
29
29
|
const args = exec.arguments ?? {};
|
|
30
30
|
if (SHELL_TOOLS.has(exec.name) && args.run_in_background !== true && typeof args.command === 'string') {
|
|
31
|
-
const seconds = shellPauseSeconds(args.command);
|
|
31
|
+
const seconds = shellPauseSeconds(args.command, exec.name === 'pwsh' ? 'powershell' : 'posix');
|
|
32
32
|
if (seconds > MAX_PAUSE_SECONDS)
|
|
33
33
|
return `Deep PTC refuses a ${seconds === Infinity ? 'endless' : `${seconds} s`} foreground pause. ${LATER}`;
|
|
34
34
|
}
|
|
35
35
|
if (exec.name === 'run_code' && typeof args.code === 'string') {
|
|
36
|
-
const issue = programPauseIssue(args.code);
|
|
37
|
-
if (issue) return `Deep PTC refuses run_code programs that wait (${issue}; pauses up to ${MAX_PAUSE_SECONDS} s are allowed
|
|
36
|
+
const issue = programPauseIssue(args.code, languageOf());
|
|
37
|
+
if (issue) return `Deep PTC refuses run_code programs that wait (${issue}; pauses up to ${MAX_PAUSE_SECONDS} s are allowed). ${LATER}`;
|
|
38
38
|
}
|
|
39
39
|
if (exec.name === 'job_output') {
|
|
40
40
|
if (args.wait === true && steeringPending(exec.agent))
|
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
|
+
}
|