dsh-deep-ptc-mode 1.8.7 → 1.9.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 +46 -0
- package/README.md +36 -32
- package/README.zh.md +36 -32
- package/TEST_REPORT.md +3 -0
- package/lib/ask-user.mjs +6 -1
- package/lib/client.js +613 -575
- package/lib/environment.mjs +3 -0
- package/lib/executor.mjs +2 -47
- package/lib/index.mjs +40 -17
- package/lib/mapped-shell.mjs +39 -0
- package/lib/model.mjs +41 -7
- package/lib/official-names.mjs +34 -14
- package/lib/preset-compat.mjs +159 -69
- package/lib/preset-health.mjs +23 -0
- package/lib/preset.json +1 -1
- package/lib/reachable.mjs +20 -4
- package/lib/rules.mjs +4 -3
- package/lib/session-activity.mjs +192 -0
- package/lib/shells.mjs +51 -5
- package/lib/sleep-lint.mjs +37 -4
- package/lib/ssh.mjs +93 -0
- package/lib/tool-catalog.mjs +49 -15
- package/lib/tool-policy.mjs +78 -28
- package/lib/upstream.mjs +10 -5
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
package/lib/environment.mjs
CHANGED
|
@@ -6,10 +6,13 @@ export const Config = z.object({
|
|
|
6
6
|
environment: z.union(['wsl', 'powershell', 'zsh', 'bash']).required(),
|
|
7
7
|
wslDistribution: z.string().default(''),
|
|
8
8
|
shellNote: z.string().default(''),
|
|
9
|
+
// SSH guidance for this environment (lib/ssh.mjs); empty omits the section.
|
|
10
|
+
ssh: z.string().default(''),
|
|
9
11
|
});
|
|
10
12
|
export function apply(ctx, config) {
|
|
11
13
|
ctx.systemPrompt.section({
|
|
12
14
|
name: 'deep-ptc:execution-environment', order: 10190,
|
|
13
15
|
text: environmentText(config.environment, config.wslDistribution, config.shellNote),
|
|
14
16
|
});
|
|
17
|
+
if (config.ssh) ctx.systemPrompt.section({ name: 'deep-ptc:ssh', order: 10191, text: config.ssh });
|
|
15
18
|
}
|
package/lib/executor.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import z from '@deepseek-ai/schemastery';
|
|
2
2
|
import { importHost, pluginOf } from './host.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { extensible, mappedExecutor } from './mapped-shell.mjs';
|
|
4
4
|
|
|
5
5
|
export const name = 'deep-ptc-mapped-executor';
|
|
6
6
|
export const inject = [];
|
|
@@ -13,54 +13,9 @@ export const Config = z.object({
|
|
|
13
13
|
options: z.any(),
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
function argvOf(environment, spec, distribution, executable) {
|
|
17
|
-
return shellArgv(environment, spec, distribution, process.platform, executable);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Extend the official bash executor: its process handles, output retention, cancellation, jobs,
|
|
21
|
-
// sandbox and Config stay official; only the argv that starts the shell changes.
|
|
22
|
-
export function mappedExecutor(Base, environment, distribution = '', executable = '') {
|
|
23
|
-
const explicit = typeof executable === 'string' && executable !== '';
|
|
24
|
-
return class MappedShellExecutor extends Base {
|
|
25
|
-
async execute(spec) {
|
|
26
|
-
assertExecutionPolicy(environment, spec.sandboxPolicy);
|
|
27
|
-
if (spec.sandboxPolicy.mode !== 'danger-full-access') return super.execute(spec);
|
|
28
|
-
const process = await super.executeArgv(spec, argvOf(environment, spec, distribution, executable));
|
|
29
|
-
return Base.decorateResult(process, result => ({
|
|
30
|
-
...result, sandbox: { mode: spec.sandboxPolicy.mode, denied: false },
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Current sandboxes enter through run/start. Confined calls use confine, so the chosen
|
|
35
|
-
// binary stays inside the official sandbox. Full access keeps the same denial stamp as before.
|
|
36
|
-
async run(spec) {
|
|
37
|
-
if (!explicit || typeof super.run !== 'function') return super.run?.call(this, spec) ?? this.execute(spec);
|
|
38
|
-
assertExecutionPolicy(environment, spec.sandboxPolicy);
|
|
39
|
-
if (spec.sandboxPolicy?.mode !== 'danger-full-access') return super.run(spec);
|
|
40
|
-
if (typeof super.runArgv !== 'function') return this.execute(spec);
|
|
41
|
-
const result = await super.runArgv(spec, argvOf(environment, spec, distribution, executable));
|
|
42
|
-
return { ...result, sandbox: { mode: spec.sandboxPolicy.mode, denied: false } };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
start(spec) {
|
|
46
|
-
if (!explicit || typeof super.start !== 'function') return super.start?.call(this, spec);
|
|
47
|
-
assertExecutionPolicy(environment, spec.sandboxPolicy);
|
|
48
|
-
if (spec.sandboxPolicy?.mode !== 'danger-full-access') return super.start(spec);
|
|
49
|
-
if (typeof this.startArgv !== 'function') return super.start(spec);
|
|
50
|
-
return this.startArgv(spec, argvOf(environment, spec, distribution, executable));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
confine(command, policy, signal) {
|
|
54
|
-
assertExecutionPolicy(environment, policy);
|
|
55
|
-
return this.ctx.sandbox.confine(argvOf(environment,
|
|
56
|
-
{ command, workdir: policy.workspaceRoot }, distribution, executable), policy, signal);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
16
|
export async function apply(ctx, config) {
|
|
62
17
|
const Base = pluginOf(await importHost(config.base));
|
|
63
|
-
if (
|
|
18
|
+
if (!extensible(Base))
|
|
64
19
|
throw new Error(`${config.base} no longer exposes the executor API Deep PTC extends; choose PowerShell or native Bash`);
|
|
65
20
|
ctx.plugin(mappedExecutor(Base, config.environment, config.wslDistribution, config.shellExecutable), config.options);
|
|
66
21
|
}
|
package/lib/index.mjs
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import z from '@deepseek-ai/schemastery';
|
|
2
2
|
import snapshot from './preset.json' with { type: 'json' };
|
|
3
3
|
import { spawnSync } from 'node:child_process';
|
|
4
|
-
import {
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { CREATIVE_PRESET_ID } from './creative.mjs';
|
|
7
|
+
import { extensible } from './mapped-shell.mjs';
|
|
7
8
|
import { normalizePreferences } from './tool-policy.mjs';
|
|
8
9
|
import { availableEnvironments, BASE_SNAPSHOT, DEFAULT_FOREGROUND_SECONDS, deriveDeepPtc, normalizeDistribution, resolveEnvironment } from './model.mjs';
|
|
9
|
-
import { discoverShells, resolveShellExecutable, resolveWindowsBash, shellNote } from './shells.mjs';
|
|
10
|
+
import { discoverShells, probeExecutable, resolveShellExecutable, resolveWindowsBash, shellNote } from './shells.mjs';
|
|
10
11
|
import { BASE_DECLARATION_SPECIFIER, creativePresetUrl, loadCreativePreset, loadCurrentPreset, officialPresetUrl, parseOfficialExecutors } from './upstream.mjs';
|
|
11
12
|
import { importHost, pluginOf, resolveHost } from './host.mjs';
|
|
12
13
|
import { presetLifecycle } from './lifecycle.mjs';
|
|
13
14
|
import { installPresetCompat } from './preset-compat.mjs';
|
|
14
15
|
import { checkBeforeResolve } from './freshness.mjs';
|
|
16
|
+
import { classifyDiagnosis } from './preset-health.mjs';
|
|
17
|
+
import { applyActivity } from './session-activity.mjs';
|
|
18
|
+
import { findSshClient, readSshHosts, sshGuidance } from './ssh.mjs';
|
|
15
19
|
import { apply as applySkillContext } from './skill-context.mjs';
|
|
16
20
|
import { applyRoot as applyToolStateRoot } from './tool-state.mjs';
|
|
17
21
|
|
|
@@ -26,13 +30,17 @@ function whereExecutable(name) {
|
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
|
|
33
|
+
const executableExists = path => probeExecutable(path) !== undefined;
|
|
34
|
+
|
|
29
35
|
const discoveredShells = discoverShells({
|
|
30
36
|
platform: process.platform,
|
|
31
37
|
env: process.env,
|
|
32
|
-
|
|
38
|
+
probe: probeExecutable,
|
|
33
39
|
where: whereExecutable,
|
|
34
40
|
});
|
|
35
41
|
|
|
42
|
+
const sshClient = findSshClient({ exists: executableExists });
|
|
43
|
+
|
|
36
44
|
function shellFamily(environment) {
|
|
37
45
|
return environment === 'powershell' || environment === 'bash' || environment === 'zsh' ? environment : '';
|
|
38
46
|
}
|
|
@@ -48,6 +56,11 @@ export const Config = z.object({
|
|
|
48
56
|
shellChoices: z.array(z.object({
|
|
49
57
|
id: z.string(), label: z.string(), path: z.string(), family: z.string(),
|
|
50
58
|
})).default(discoveredShells).volatile(),
|
|
59
|
+
// Read-only facts for the client panel: the OpenSSH client and the configured host aliases.
|
|
60
|
+
sshClient: z.string().default(sshClient).volatile(),
|
|
61
|
+
sshHosts: z.array(z.object({
|
|
62
|
+
alias: z.string(), hostName: z.string().default(''), user: z.string().default(''), port: z.string().default(''),
|
|
63
|
+
})).default(readSshHosts().map(host => ({ hostName: '', user: '', port: '', ...host }))).volatile(),
|
|
51
64
|
foregroundSeconds: z.number().step(1).min(5).max(600).default(DEFAULT_FOREGROUND_SECONDS).volatile(),
|
|
52
65
|
toolCompatibility: z.boolean().default(true).volatile(),
|
|
53
66
|
toolPreferences: z.any().default([]).volatile(),
|
|
@@ -102,8 +115,7 @@ function officialExecutors(ctx) {
|
|
|
102
115
|
async function canExtend(ctx, executor) {
|
|
103
116
|
try {
|
|
104
117
|
const Base = pluginOf(await importHost(executor.name));
|
|
105
|
-
if (
|
|
106
|
-
&& typeof Base.prototype.executeArgv === 'function') return true;
|
|
118
|
+
if (extensible(Base)) return true;
|
|
107
119
|
ctx.logger.warn('Deep PTC: %s no longer exposes the executor API WSL/Zsh extend', executor.name);
|
|
108
120
|
} catch (error) {
|
|
109
121
|
ctx.logger.warn('Deep PTC: cannot load %s (%s)', executor.name, error.message);
|
|
@@ -115,17 +127,17 @@ async function canExtend(ctx, executor) {
|
|
|
115
127
|
// official change is inherited instead of leaving a stale frozen row behind.
|
|
116
128
|
// The bundled snapshot is only a fallback when the installed declaration
|
|
117
129
|
// cannot be read or cannot be composed.
|
|
118
|
-
async function buildPreset(ctx, config,
|
|
119
|
-
const
|
|
130
|
+
async function buildPreset(ctx, config, health) {
|
|
131
|
+
const safeMode = health.safeMode;
|
|
132
|
+
const settings = { ...settingsOf(ctx, config), safeMode, safeModeReason: health.reason };
|
|
120
133
|
const executors = officialExecutors(ctx);
|
|
121
134
|
const environment = resolveEnvironment(settings.environment);
|
|
122
135
|
const family = shellFamily(environment);
|
|
123
136
|
if (family) {
|
|
124
137
|
const requested = typeof settings.shellExecutable === 'string' ? settings.shellExecutable : '';
|
|
125
138
|
const windowsBash = process.platform === 'win32' && environment === 'bash';
|
|
126
|
-
const resolved = windowsBash ? resolveWindowsBash(requested,
|
|
127
|
-
|
|
128
|
-
}) : resolveShellExecutable(requested, { family, discovered: discoveredShells, exists: existsSync });
|
|
139
|
+
const resolved = windowsBash ? resolveWindowsBash(requested, executableExists)
|
|
140
|
+
: resolveShellExecutable(requested, { family, discovered: discoveredShells, exists: executableExists });
|
|
129
141
|
if (windowsBash && !resolved) {
|
|
130
142
|
ctx.logger.warn('Deep PTC: Windows Bash requires an available absolute path to bash.exe; retaining the official shell rows');
|
|
131
143
|
} else if (requested && requested !== 'auto' && !resolved) {
|
|
@@ -153,6 +165,7 @@ async function buildPreset(ctx, config, safeMode) {
|
|
|
153
165
|
}
|
|
154
166
|
}
|
|
155
167
|
settings.executors = executors;
|
|
168
|
+
settings.sshGuidance = sshGuidance({ environment, client: sshClient, hosts: readSshHosts() });
|
|
156
169
|
let upstream = snapshot;
|
|
157
170
|
let source = 'bundled snapshot';
|
|
158
171
|
try {
|
|
@@ -178,16 +191,19 @@ async function buildPreset(ctx, config, safeMode) {
|
|
|
178
191
|
}
|
|
179
192
|
|
|
180
193
|
export async function apply(ctx, config) {
|
|
181
|
-
|
|
194
|
+
// Safe mode holds until our settings or the upstream declarations change, or DSH restarts.
|
|
195
|
+
const health = { safeMode: false, reason: '' };
|
|
182
196
|
// The skill card is a profile-level session projection, not an agent-preset row:
|
|
183
197
|
// that keeps it available in existing Deep PTC sessions after an upgrade. Its
|
|
184
198
|
// command and pre-step paths are gated to deep-ptc sessions below.
|
|
185
199
|
await applySkillContext(ctx);
|
|
186
200
|
// The tool state and its reset command follow the same rule, so the side card works in idle sessions too.
|
|
187
201
|
await applyToolStateRoot(ctx);
|
|
202
|
+
// Output files and SSH connections per conversation, for the side panel.
|
|
203
|
+
await applyActivity(ctx);
|
|
188
204
|
const lifecycle = presetLifecycle(
|
|
189
205
|
definition => ctx.agentPresets.register(definition),
|
|
190
|
-
() => buildPreset(ctx, config,
|
|
206
|
+
() => buildPreset(ctx, config, health),
|
|
191
207
|
error => ctx.logger.error('Deep PTC environment update failed: %s', error.message),
|
|
192
208
|
);
|
|
193
209
|
ctx.effect(() => () => lifecycle.dispose());
|
|
@@ -204,12 +220,18 @@ export async function apply(ctx, config) {
|
|
|
204
220
|
});
|
|
205
221
|
ctx.effect(() => () => compat.dispose(), 'Deep PTC: session-scoped preset identity');
|
|
206
222
|
// A preset the host refuses to mount would leave its sessions unusable, so fall back to the official
|
|
207
|
-
// composition with the persona.
|
|
223
|
+
// composition with the persona. Only rows that failed count: a row still waiting for a service can
|
|
224
|
+
// come up by itself, and its absence costs that row's feature, not the preset. Not awaited: reading
|
|
225
|
+
// the diagnosis waits for the host tree.
|
|
208
226
|
const verify = async () => {
|
|
209
227
|
const row = (await ctx.agentPresets.compositionInventory?.())?.find(candidate => candidate.id === 'deep-ptc');
|
|
210
|
-
|
|
211
|
-
ctx.logger.
|
|
212
|
-
safeMode
|
|
228
|
+
const { failed, pending } = classifyDiagnosis(row?.broken);
|
|
229
|
+
if (pending.length > 0) ctx.logger.info('Deep PTC: rows waiting for host services, kept in the preset: %s', pending.join('; '));
|
|
230
|
+
if (health.safeMode || failed.length === 0) return;
|
|
231
|
+
const reason = failed.join('; ');
|
|
232
|
+
ctx.logger.warn('Deep PTC: preset cannot mount (%s); using safe mode until settings or upstream presets change', reason);
|
|
233
|
+
health.safeMode = true;
|
|
234
|
+
health.reason = reason;
|
|
213
235
|
await lifecycle.refresh();
|
|
214
236
|
};
|
|
215
237
|
const refreshed = () => lifecycle.refresh().then(() => { void verify().catch(() => {}); });
|
|
@@ -235,7 +257,8 @@ export async function apply(ctx, config) {
|
|
|
235
257
|
const current = await signature();
|
|
236
258
|
if (!active || current === previous) return;
|
|
237
259
|
previous = current;
|
|
238
|
-
safeMode = false;
|
|
260
|
+
health.safeMode = false;
|
|
261
|
+
health.reason = '';
|
|
239
262
|
await refreshed().catch(() => {});
|
|
240
263
|
} catch (error) {
|
|
241
264
|
ctx.logger.warn('Deep PTC: upstream detection failed (%s); retaining the active preset', error.message);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The WSL/Zsh/Bash shell as a subclass of the official bash executor. This module has no host
|
|
2
|
+
// dependency, so the class is testable against a stand-in base; executor.mjs mounts it.
|
|
3
|
+
import { assertExecutionPolicy, shellArgv } from './model.mjs';
|
|
4
|
+
|
|
5
|
+
function argvOf(environment, spec, distribution, executable) {
|
|
6
|
+
return shellArgv(environment, spec, distribution, process.platform, executable);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** The executor surface this module extends; an installation without it keeps the official shell rows. */
|
|
10
|
+
export function extensible(Base) {
|
|
11
|
+
return typeof Base === 'function' && typeof Base.decorateResult === 'function'
|
|
12
|
+
&& typeof Base.prototype?.executeArgv === 'function';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Extend the official bash executor: its process handles, output retention, cancellation, jobs,
|
|
16
|
+
// sandbox and Config stay official; only the argv that starts the shell changes. The class adds no
|
|
17
|
+
// method the official executor lacks, so the host sees the surface it expects.
|
|
18
|
+
export function mappedExecutor(Base, environment, distribution = '', executable = '') {
|
|
19
|
+
return class MappedShellExecutor extends Base {
|
|
20
|
+
// The single entry point of the official executor. Full access starts the chosen shell directly
|
|
21
|
+
// and stamps the result as the official executor would; a confined call takes the official path,
|
|
22
|
+
// which reaches confine() below.
|
|
23
|
+
async execute(spec) {
|
|
24
|
+
assertExecutionPolicy(environment, spec.sandboxPolicy);
|
|
25
|
+
if (spec.sandboxPolicy.mode !== 'danger-full-access') return super.execute(spec);
|
|
26
|
+
const handle = await super.executeArgv(spec, argvOf(environment, spec, distribution, executable));
|
|
27
|
+
return Base.decorateResult(handle, result => ({
|
|
28
|
+
...result, sandbox: { mode: spec.sandboxPolicy.mode, denied: false },
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The chosen shell stays inside the official sandbox.
|
|
33
|
+
confine(command, policy, signal) {
|
|
34
|
+
assertExecutionPolicy(environment, policy);
|
|
35
|
+
return this.ctx.sandbox.confine(argvOf(environment,
|
|
36
|
+
{ command, workdir: policy.workspaceRoot }, distribution, executable), policy, signal);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
package/lib/model.mjs
CHANGED
|
@@ -121,14 +121,46 @@ const WRAP_TARGETS = [
|
|
|
121
121
|
},
|
|
122
122
|
];
|
|
123
123
|
|
|
124
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* Identity Deep PTC publishes, independent of the official preset.
|
|
126
|
+
*
|
|
127
|
+
* The host shows a third-party preset's name and description as published, in every language,
|
|
128
|
+
* so both are language-neutral: the brand name and a status line. The client localizes them
|
|
129
|
+
* where it owns the presentation (see `presetStatus` in lib/client.js, which reads this format).
|
|
130
|
+
*/
|
|
125
131
|
export const PRESET_META = {
|
|
126
132
|
id: 'deep-ptc',
|
|
127
|
-
name:
|
|
133
|
+
name: 'Deep PTC',
|
|
128
134
|
order: typeof snapshot.order === 'number' ? snapshot.order : 5,
|
|
129
|
-
description: typeof snapshot.description === 'string' ? snapshot.description : '',
|
|
130
135
|
};
|
|
131
136
|
|
|
137
|
+
/** Separator between the brand and the status in the published description. */
|
|
138
|
+
export const STATUS_SEPARATOR = ' · ';
|
|
139
|
+
const ENVIRONMENT_LABELS = { wsl: 'WSL', powershell: 'PowerShell', zsh: 'Zsh', bash: 'Bash' };
|
|
140
|
+
const SAFE_MODE_LABEL = '安全模式 Safe mode';
|
|
141
|
+
const OFFICIAL_LABEL = '官方 Shell Official shell';
|
|
142
|
+
const REASON_LIMIT = 400;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The published description: `Deep PTC · <status>`.
|
|
146
|
+
* @param status - `{ kind: 'environment', environment, distribution? }`, `{ kind: 'official' }`
|
|
147
|
+
* or `{ kind: 'safe', reason? }`.
|
|
148
|
+
* @returns the description text.
|
|
149
|
+
*/
|
|
150
|
+
export function presetDescription(status) {
|
|
151
|
+
let text;
|
|
152
|
+
if (status.kind === 'safe') {
|
|
153
|
+
const reason = typeof status.reason === 'string' ? status.reason.replace(/\s+/gu, ' ').trim() : '';
|
|
154
|
+
text = reason ? `${SAFE_MODE_LABEL}: ${reason.length > REASON_LIMIT ? `${reason.slice(0, REASON_LIMIT - 1)}…` : reason}` : SAFE_MODE_LABEL;
|
|
155
|
+
} else if (status.kind === 'official') {
|
|
156
|
+
text = OFFICIAL_LABEL;
|
|
157
|
+
} else {
|
|
158
|
+
const label = ENVIRONMENT_LABELS[status.environment] ?? status.environment;
|
|
159
|
+
text = status.environment === 'wsl' && status.distribution ? `${label} (${status.distribution})` : label;
|
|
160
|
+
}
|
|
161
|
+
return `${PRESET_META.name}${STATUS_SEPARATOR}${text}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
132
164
|
/** Persona text owned by this plugin, read from the bundled snapshot. */
|
|
133
165
|
export function personaFrom(template = snapshot) {
|
|
134
166
|
const rows = Array.isArray(template?.plugins) ? template.plugins : [];
|
|
@@ -240,7 +272,7 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
240
272
|
report.environment = 'official';
|
|
241
273
|
report.skipped.push('safe mode: official composition with the Deep PTC persona');
|
|
242
274
|
return { preset: { ...upstream, id: PRESET_META.id, name: PRESET_META.name, order: PRESET_META.order,
|
|
243
|
-
description:
|
|
275
|
+
description: presetDescription({ kind: 'safe', reason: options.safeModeReason }), plugins }, report };
|
|
244
276
|
}
|
|
245
277
|
|
|
246
278
|
// Execution environment: replace the official shell rows (wherever the official preset nests them)
|
|
@@ -304,7 +336,8 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
304
336
|
id: uniqueRowId(plugins, 'execution'), name: 'cordis:group', group: true, isolate: { shell: true },
|
|
305
337
|
config: [executor, terminal, { id: 'execution-instructions', name: 'dsh-deep-ptc-mode/environment',
|
|
306
338
|
config: { environment, wslDistribution: distribution,
|
|
307
|
-
...typeof options.shellNote === 'string' && options.shellNote !== '' ? { shellNote: options.shellNote } : {}
|
|
339
|
+
...typeof options.shellNote === 'string' && options.shellNote !== '' ? { shellNote: options.shellNote } : {},
|
|
340
|
+
...typeof options.sshGuidance === 'string' && options.sshGuidance !== '' ? { ssh: options.sshGuidance } : {} } }],
|
|
308
341
|
});
|
|
309
342
|
}
|
|
310
343
|
rows.push({
|
|
@@ -350,8 +383,9 @@ export function deriveDeepPtc(upstream, options = {}, platform = process.platfor
|
|
|
350
383
|
report.pluginLab = additions.map(row => `${row.id} (${row.name})`);
|
|
351
384
|
}
|
|
352
385
|
|
|
353
|
-
const
|
|
354
|
-
|
|
386
|
+
const description = environment === 'bash' && platform === 'win32' && unusable !== undefined
|
|
387
|
+
? presetDescription({ kind: 'official' })
|
|
388
|
+
: presetDescription({ kind: 'environment', environment, distribution });
|
|
355
389
|
return {
|
|
356
390
|
preset: {
|
|
357
391
|
...upstream,
|
package/lib/official-names.mjs
CHANGED
|
@@ -11,7 +11,12 @@ export const OFFICIAL_SCOPE = '@deepseek-ai/';
|
|
|
11
11
|
const OWN_PACKAGE = 'dsh-deep-ptc-mode';
|
|
12
12
|
const REFRESH_MS = 1000;
|
|
13
13
|
const DECLARED = /(?:defineTool|tools\.register)\(\{\s*name:\s*(?:"([^"]+)"|'([^']+)'|([A-Za-z_$][\w$]*))/gu;
|
|
14
|
+
// `tools.register(helper("name", …))` and the `const helper = (name, …) => defineTool({ name: name` it calls.
|
|
15
|
+
const FACTORY_CALL = /tools\.register\(\s*([A-Za-z_$][\w$]*)\(\s*["']([^"']+)["']/gu;
|
|
16
|
+
const IDENTIFIER = String.raw`([A-Za-z_$][\w$]*)`;
|
|
14
17
|
const escapeRegExp = text => text.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
18
|
+
const factoryDefinition = helper => new RegExp(
|
|
19
|
+
String.raw`(?:const|let|var)\s+${escapeRegExp(helper)}\s*=\s*\(\s*${IDENTIFIER}[^)]*\)\s*=>\s*defineTool\(\{\s*name:\s*${IDENTIFIER}`, 'u');
|
|
15
20
|
|
|
16
21
|
function identifierValue(source, identifier) {
|
|
17
22
|
const id = escapeRegExp(identifier);
|
|
@@ -27,10 +32,9 @@ export function toolNamesInSource(source) {
|
|
|
27
32
|
if (name !== undefined) names.add(name);
|
|
28
33
|
}
|
|
29
34
|
// A local factory may pass its first argument directly to defineTool's name.
|
|
30
|
-
for(const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
if(factory && factory[1]===factory[2])names.add(call[2]);
|
|
35
|
+
for (const [, helper, name] of source.matchAll(FACTORY_CALL)) {
|
|
36
|
+
const [, parameter, nameArgument] = factoryDefinition(helper).exec(source) ?? [];
|
|
37
|
+
if (parameter !== undefined && parameter === nameArgument) names.add(name);
|
|
34
38
|
}
|
|
35
39
|
return names;
|
|
36
40
|
}
|
|
@@ -49,8 +53,14 @@ function installedSource(moduleName, base) {
|
|
|
49
53
|
const url = resolveHost(moduleName);
|
|
50
54
|
if (url !== undefined) file = fileURLToPath(url);
|
|
51
55
|
}
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
if (file === undefined) throw new Error(`cannot resolve ${moduleName}`);
|
|
57
|
+
const stat = statSync(file);
|
|
58
|
+
const stamp = `${file}:${stat.mtimeMs}:${stat.ctimeMs}:${stat.size}`;
|
|
59
|
+
let row = sourceCache.get(file);
|
|
60
|
+
if (row?.stamp !== stamp) {
|
|
61
|
+
row = { stamp, text: readFileSync(file, 'utf8') };
|
|
62
|
+
sourceCache.set(file, row);
|
|
63
|
+
}
|
|
54
64
|
return row;
|
|
55
65
|
}
|
|
56
66
|
|
|
@@ -64,15 +74,21 @@ function installedSource(moduleName, base) {
|
|
|
64
74
|
export function toolDirectory(getLoader, { modules = [], readSource = installedSource, base, refreshMs = REFRESH_MS } = {}) {
|
|
65
75
|
const scanned = new Map();
|
|
66
76
|
const namesIn = (moduleName, rowBase) => {
|
|
67
|
-
const key=moduleName
|
|
77
|
+
const key = `${moduleName}\0${rowBase ?? ''}`;
|
|
68
78
|
try {
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const stamp=typeof read==='string'?read:read
|
|
72
|
-
let cached=scanned.get(key);
|
|
73
|
-
if(
|
|
79
|
+
// A reader returns `{ stamp, text }`, or plain text that is its own stamp.
|
|
80
|
+
const read = readSource(moduleName, rowBase);
|
|
81
|
+
const { stamp, text } = typeof read === 'string' ? { stamp: read, text: read } : read;
|
|
82
|
+
let cached = scanned.get(key);
|
|
83
|
+
if (cached === undefined || cached.stamp !== stamp) {
|
|
84
|
+
cached = { stamp, names: toolNamesInSource(text) };
|
|
85
|
+
scanned.set(key, cached);
|
|
86
|
+
}
|
|
74
87
|
return cached.names;
|
|
75
|
-
} catch {
|
|
88
|
+
} catch {
|
|
89
|
+
scanned.delete(key);
|
|
90
|
+
return new Set();
|
|
91
|
+
}
|
|
76
92
|
};
|
|
77
93
|
let view;
|
|
78
94
|
let viewedAt = -Infinity;
|
|
@@ -109,7 +125,11 @@ export function toolDirectory(getLoader, { modules = [], readSource = installedS
|
|
|
109
125
|
return {
|
|
110
126
|
isOfficial: name => refresh().official.has(name),
|
|
111
127
|
providerOf: name => refresh().providers.get(name),
|
|
112
|
-
isExternal: name => {
|
|
128
|
+
isExternal: name => {
|
|
129
|
+
const { official, providers } = refresh();
|
|
130
|
+
const provider = providers.get(name);
|
|
131
|
+
return !!provider && !official.has(name) && !provider.startsWith(OFFICIAL_SCOPE);
|
|
132
|
+
},
|
|
113
133
|
namesOf: moduleName => namesIn(moduleName, base),
|
|
114
134
|
};
|
|
115
135
|
}
|