@wonderwhy-er/desktop-commander 0.3.2-alpha.1 → 0.3.2-alpha.3
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/dist/bootstrap.js +7 -7
- package/dist/command-manager.d.ts +98 -1
- package/dist/command-manager.js +200 -16
- package/dist/remote-device/desktop-commander-integration.js +3 -1
- package/dist/remote-device/diagnostics/redact.js +30 -8
- package/dist/remote-device/diagnostics/report.js +30 -13
- package/dist/remote-device/mqtt/mqtt-enrollment.js +1 -1
- package/dist/remote-device/mqtt/mqtt-transport.js +2 -2
- package/dist/remote-device/remote-channel.d.ts +1 -1
- package/dist/remote-device/remote-channel.js +1 -1
- package/dist/remote-device/transport-telemetry.js +5 -4
- package/dist/server.js +2 -0
- package/dist/terminal-manager.js +4 -6
- package/dist/tools/improved-process-tools.d.ts +2 -0
- package/dist/tools/improved-process-tools.js +68 -40
- package/dist/tools/pdf/markdown.js +7 -3
- package/dist/tools/process.js +10 -2
- package/dist/track-installation.js +2 -2
- package/dist/ui/file-preview/preview-runtime.js +145 -138
- package/dist/utils/brace-expansion.d.ts +25 -0
- package/dist/utils/brace-expansion.js +171 -0
- package/dist/utils/capture.d.ts +8 -2
- package/dist/utils/capture.js +1 -1
- package/dist/utils/cmd-commands.d.ts +3 -0
- package/dist/utils/cmd-commands.js +322 -0
- package/dist/utils/command-reading.d.ts +78 -0
- package/dist/utils/command-reading.js +7 -0
- package/dist/utils/command-wrappers.d.ts +45 -0
- package/dist/utils/command-wrappers.js +941 -0
- package/dist/utils/inline-shells.d.ts +64 -0
- package/dist/utils/inline-shells.js +290 -0
- package/dist/utils/posix-commands.d.ts +3 -0
- package/dist/utils/posix-commands.js +201 -0
- package/dist/utils/powershell-commands.d.ts +60 -0
- package/dist/utils/powershell-commands.js +420 -0
- package/dist/utils/process-tree.js +4 -4
- package/dist/utils/shell-script-files.d.ts +4 -0
- package/dist/utils/shell-script-files.js +121 -0
- package/dist/utils/shell.d.ts +36 -0
- package/dist/utils/shell.js +69 -0
- package/dist/utils/system-info.d.ts +2 -0
- package/dist/utils/system-info.js +5 -1
- package/dist/utils/threadpool-size.d.ts +36 -0
- package/dist/utils/threadpool-size.js +143 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +11 -9
- package/node_modules/@desktop-commander/telemetry-contract/README.md +0 -56
- package/node_modules/@desktop-commander/telemetry-contract/package.json +0 -32
- package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +0 -39
- package/node_modules/@desktop-commander/telemetry-contract/transport.js +0 -167
- package/vendor/telemetry-contract/README.md +0 -56
- package/vendor/telemetry-contract/package.json +0 -32
- package/vendor/telemetry-contract/transport.d.ts +0 -38
- package/vendor/telemetry-contract/transport.js +0 -164
- package/vendor/telemetry-contract/transport.test.js +0 -39
package/dist/terminal-manager.js
CHANGED
|
@@ -3,7 +3,7 @@ import { DEFAULT_COMMAND_TIMEOUT, MAX_PROCESS_WAIT_MS } from './config.js';
|
|
|
3
3
|
import { configManager } from './config-manager.js';
|
|
4
4
|
import { capture } from "./utils/capture.js";
|
|
5
5
|
import { analyzeProcessState, STATE_DETECTION_TAIL_CHARS } from './utils/process-detection.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getCommandShell, getShellEnvironment, getShellSpawnArgs } from './utils/shell.js';
|
|
7
7
|
import { terminateProcessTree } from './utils/process-tree.js';
|
|
8
8
|
const OUTPUT_STREAMS = ['stdout', 'stderr'];
|
|
9
9
|
function newStreamTails() {
|
|
@@ -69,7 +69,7 @@ export class TerminalManager {
|
|
|
69
69
|
// If there's an error getting the config, fall back to the default shell
|
|
70
70
|
}
|
|
71
71
|
// Get the shell from config if not specified
|
|
72
|
-
const shellToUse = shell
|
|
72
|
+
const shellToUse = getCommandShell(shell, config.defaultShell);
|
|
73
73
|
const waitLimit = getProcessWaitLimit(timeoutMs, maxWaitMs);
|
|
74
74
|
// For REPL interactions, we need to ensure stdin, stdout, and stderr are properly configured
|
|
75
75
|
// Note: No special stdio options needed here, Node.js handles pipes by default
|
|
@@ -82,10 +82,8 @@ export class TerminalManager {
|
|
|
82
82
|
// Get the appropriate spawn configuration for the shell, with login flags where appropriate
|
|
83
83
|
const spawnConfig = getShellSpawnArgs(shellToUse, enhancedCommand);
|
|
84
84
|
const spawnOptions = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
TERM: 'xterm-256color' // Better terminal compatibility
|
|
88
|
-
},
|
|
85
|
+
// PATHEXT and ProgramData repaired on Windows; TERM for better terminal compatibility.
|
|
86
|
+
env: getShellEnvironment(),
|
|
89
87
|
windowsHide: true // Prevent visible console windows on Windows
|
|
90
88
|
};
|
|
91
89
|
// Add shell option if needed (for unknown shells)
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ServerResult } from '../types.js';
|
|
2
|
+
/** The answer when some processes of a session could not be ended */
|
|
3
|
+
export declare function terminationFailedResult(pid: number): ServerResult;
|
|
2
4
|
/**
|
|
3
5
|
* Start a new process (renamed from execute_command)
|
|
4
6
|
* Includes early detection of process waiting for input
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { terminalManager, MAX_BUFFERED_OUTPUT_CHARS, getProcessWaitLimit } from '../terminal-manager.js';
|
|
1
|
+
import { terminalManager, MAX_BUFFERED_OUTPUT_CHARS, getProcessWaitLimit, } from '../terminal-manager.js';
|
|
2
2
|
import { commandManager } from '../command-manager.js';
|
|
3
3
|
import { StartProcessArgsSchema, ReadProcessOutputArgsSchema, InteractWithProcessArgsSchema, ForceTerminateArgsSchema } from './schemas.js';
|
|
4
4
|
import { capture } from "../utils/capture.js";
|
|
5
5
|
import { analyzeProcessState, cleanProcessOutput, formatProcessStateMessage } from '../utils/process-detection.js';
|
|
6
6
|
import { configManager } from '../config-manager.js';
|
|
7
|
-
import { getCommandEnvironment,
|
|
7
|
+
import { getCommandEnvironment, getCommandShell } from '../utils/shell.js';
|
|
8
8
|
import { terminateProcessTree } from '../utils/process-tree.js';
|
|
9
9
|
import { MAX_PROCESS_WAIT_MS } from '../config.js';
|
|
10
10
|
import { spawn } from 'child_process';
|
|
@@ -21,7 +21,7 @@ let virtualPidCounter = -1000; // Use negative PIDs for virtual sessions
|
|
|
21
21
|
/** How long a node:local script's output pipes may stay open after its timeout ended its tree */
|
|
22
22
|
const PIPES_CLOSE_WAIT_MS = 1000;
|
|
23
23
|
/** The answer when some processes of a session could not be ended */
|
|
24
|
-
function terminationFailedResult(pid) {
|
|
24
|
+
export function terminationFailedResult(pid) {
|
|
25
25
|
return {
|
|
26
26
|
content: [{ type: "text", text: `Error: Could not terminate every process of session ${pid}; some may still be running` }],
|
|
27
27
|
isError: true,
|
|
@@ -131,37 +131,61 @@ export async function startProcess(args, maxWaitMs = MAX_PROCESS_WAIT_MS) {
|
|
|
131
131
|
isError: true,
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
|
+
captureProcessCommand(parsed.data.command);
|
|
135
|
+
// The shell that runs the command, worked out before the check so the
|
|
136
|
+
// check reads the command with that shell's grammar
|
|
137
|
+
const config = await configManager.getConfig();
|
|
138
|
+
const shellUsed = getCommandShell(parsed.data.shell, config.defaultShell);
|
|
139
|
+
const check = await commandManager.checkCommand(parsed.data.command, shellUsed);
|
|
140
|
+
if (commandManager.isRefused(check)) {
|
|
141
|
+
const text = check.verdict === 'blocked'
|
|
142
|
+
? `Error: Command not allowed: "${check.name}" is in the blockedCommands setting.`
|
|
143
|
+
: `Error: Command not allowed: the check for blocked commands failed (${check.reason}), so nothing was run.`;
|
|
144
|
+
return {
|
|
145
|
+
content: [{ type: "text", text }],
|
|
146
|
+
isError: true,
|
|
147
|
+
structuredContent: { blocked: true, command: parsed.data.command },
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const commandToRun = parsed.data.command;
|
|
151
|
+
if (commandToRun.trim() === 'node:local') {
|
|
152
|
+
return startNodeSession(parsed.data.timeout_ms);
|
|
153
|
+
}
|
|
154
|
+
const result = await terminalManager.executeCommand(commandToRun, parsed.data.timeout_ms, shellUsed, parsed.data.verbose_timing || false, maxWaitMs);
|
|
155
|
+
if (result.pid === -1) {
|
|
156
|
+
return {
|
|
157
|
+
content: [{ type: "text", text: result.output }],
|
|
158
|
+
isError: true,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const unseenMessage = check.verdict === 'unseen' ? unseenNotes(check.unseen) : '';
|
|
162
|
+
return startedProcessResult(result, shellUsed, unseenMessage);
|
|
163
|
+
}
|
|
164
|
+
/** Fall back to base-name telemetry when detailed extraction fails; validation remains separate. */
|
|
165
|
+
function captureProcessCommand(command) {
|
|
134
166
|
try {
|
|
135
167
|
// Each command's first word as typed, so telemetry replaces a path whole
|
|
136
168
|
// (the base name alone would send the last part of it)
|
|
137
|
-
const commands = commandManager.extractCommands(
|
|
169
|
+
const commands = commandManager.extractCommands(command, true).join(', ');
|
|
138
170
|
capture('server_start_process', {
|
|
139
|
-
command: commandManager.getBaseCommand(
|
|
171
|
+
command: commandManager.getBaseCommand(command),
|
|
140
172
|
commands: commands
|
|
141
173
|
});
|
|
142
174
|
}
|
|
143
175
|
catch (error) {
|
|
144
176
|
capture('server_start_process', {
|
|
145
|
-
command: commandManager.getBaseCommand(
|
|
177
|
+
command: commandManager.getBaseCommand(command)
|
|
146
178
|
});
|
|
147
179
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
// Handle node:local - runs Node.js code directly on MCP server
|
|
158
|
-
if (commandToRun.trim() === 'node:local') {
|
|
159
|
-
const virtualPid = virtualPidCounter--;
|
|
160
|
-
virtualNodeSessions.set(virtualPid, { timeout_ms: parsed.data.timeout_ms || 30000 });
|
|
161
|
-
return {
|
|
162
|
-
content: [{
|
|
163
|
-
type: "text",
|
|
164
|
-
text: `Node.js session started with PID ${virtualPid} (MCP server execution)
|
|
180
|
+
}
|
|
181
|
+
/** Virtual PIDs retain the same interaction/termination routing without spawning an OS process. */
|
|
182
|
+
function startNodeSession(timeoutMs) {
|
|
183
|
+
const virtualPid = virtualPidCounter--;
|
|
184
|
+
virtualNodeSessions.set(virtualPid, { timeout_ms: timeoutMs || 30000 });
|
|
185
|
+
return {
|
|
186
|
+
content: [{
|
|
187
|
+
type: "text",
|
|
188
|
+
text: `Node.js session started with PID ${virtualPid} (MCP server execution)
|
|
165
189
|
|
|
166
190
|
IMPORTANT: Each interact_with_process call runs as a FRESH script.
|
|
167
191
|
State is NOT preserved between calls. Include ALL code in ONE call:
|
|
@@ -172,22 +196,12 @@ export async function startProcess(args, maxWaitMs = MAX_PROCESS_WAIT_MS) {
|
|
|
172
196
|
- All Node.js built-ins: fs, path, http, crypto, etc.
|
|
173
197
|
|
|
174
198
|
🔄 Ready for code - send complete self-contained script via interact_with_process.`
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const config = await configManager.getConfig();
|
|
182
|
-
shellUsed = config.defaultShell || getDefaultShell();
|
|
183
|
-
}
|
|
184
|
-
const result = await terminalManager.executeCommand(commandToRun, parsed.data.timeout_ms, shellUsed, parsed.data.verbose_timing || false, maxWaitMs);
|
|
185
|
-
if (result.pid === -1) {
|
|
186
|
-
return {
|
|
187
|
-
content: [{ type: "text", text: result.output }],
|
|
188
|
-
isError: true,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
199
|
+
}],
|
|
200
|
+
structuredContent: { pid: virtualPid, status: 'waiting_for_input' },
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/** Text and structured facts must describe the same observed process state. */
|
|
204
|
+
function startedProcessResult(result, shellUsed, unseenMessage) {
|
|
191
205
|
// Whether the process is waiting for input, as detected when the wait ended
|
|
192
206
|
const { processState } = result;
|
|
193
207
|
let statusMessage = '';
|
|
@@ -208,7 +222,8 @@ export async function startProcess(args, maxWaitMs = MAX_PROCESS_WAIT_MS) {
|
|
|
208
222
|
return {
|
|
209
223
|
content: [{
|
|
210
224
|
type: "text",
|
|
211
|
-
text: `Process started with PID ${result.pid} (shell: ${shellUsed})\nInitial output:\n
|
|
225
|
+
text: `Process started with PID ${result.pid} (shell: ${shellUsed})\nInitial output:\n`
|
|
226
|
+
+ `${result.output}${statusMessage}${timingMessage}${unseenMessage}`
|
|
212
227
|
}],
|
|
213
228
|
structuredContent: {
|
|
214
229
|
pid: result.pid,
|
|
@@ -218,6 +233,19 @@ export async function startProcess(args, maxWaitMs = MAX_PROCESS_WAIT_MS) {
|
|
|
218
233
|
},
|
|
219
234
|
};
|
|
220
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* The notes at the end of the answer when the command ran but the check
|
|
238
|
+
* couldn't see every program it runs: one chosen only when the command runs
|
|
239
|
+
* (eval "$CMD", & $tool), or the commands in a script file (bash deploy.sh).
|
|
240
|
+
*/
|
|
241
|
+
function unseenNotes(unseen) {
|
|
242
|
+
const notes = unseen.map(({ what, inFile }) => inFile
|
|
243
|
+
? `Note: the blocklist could not check the commands in ${what}, `
|
|
244
|
+
+ 'because they are in that file, not in this command.'
|
|
245
|
+
: `Note: the blocklist could not check the program this command runs (${what}), `
|
|
246
|
+
+ 'because it is only known when the command runs.');
|
|
247
|
+
return `\n\n${notes.join('\n')}`;
|
|
248
|
+
}
|
|
221
249
|
/**
|
|
222
250
|
* Machine-readable process state for structuredContent, mirroring the
|
|
223
251
|
* status line shown in the text response.
|
|
@@ -9,6 +9,7 @@ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'pat
|
|
|
9
9
|
import { pdf2md } from './lib/pdf2md.js';
|
|
10
10
|
import { CONFIG_FILE } from '../../config.js';
|
|
11
11
|
import { LazyPackage } from '../../utils/lazy-package.js';
|
|
12
|
+
import { isDockerImage } from '../../utils/system-info.js';
|
|
12
13
|
const isUrl = (source) => source.startsWith('http://') || source.startsWith('https://');
|
|
13
14
|
// Cached Chrome path to avoid repeated lookups
|
|
14
15
|
let cachedChromePath = null; // null = not checked yet
|
|
@@ -580,6 +581,7 @@ async function installChrome() {
|
|
|
580
581
|
/**
|
|
581
582
|
* Find or install Chrome for PDF generation
|
|
582
583
|
* Priority: 1. Puppeteer cache, 2. System Chrome, 3. Install Chrome
|
|
584
|
+
* (in Desktop Commander's Docker image the system's Chromium comes first)
|
|
583
585
|
* Results are cached to avoid repeated lookups
|
|
584
586
|
*/
|
|
585
587
|
async function getChromePath() {
|
|
@@ -593,8 +595,9 @@ async function getChromePath() {
|
|
|
593
595
|
}
|
|
594
596
|
// Start the check
|
|
595
597
|
chromeCheckPromise = (async () => {
|
|
596
|
-
// 1. Check puppeteer cache first (exact compatible version)
|
|
597
|
-
|
|
598
|
+
// 1. Check puppeteer cache first (exact compatible version). Not in the Docker image: the
|
|
599
|
+
// Chrome Puppeteer downloads can't start on Alpine, and the image has its own Chromium
|
|
600
|
+
const cachedChrome = isDockerImage() ? undefined : findPuppeteerChrome();
|
|
598
601
|
if (cachedChrome) {
|
|
599
602
|
await pruneOldPuppeteerChromeBuilds(cachedChrome.executablePath);
|
|
600
603
|
cachedChromePath = cachedChrome.executablePath;
|
|
@@ -703,7 +706,8 @@ export async function parseMarkdownToPdf(markdown, options = {}) {
|
|
|
703
706
|
// Chrome runs on the render's own profile whatever the caller asked for
|
|
704
707
|
// (launch_options.args is dropped by resolveRender; userDataDir is overridden here)
|
|
705
708
|
userDataDir: undefined,
|
|
706
|
-
|
|
709
|
+
// In the Docker image Chromium can't start its sandbox (and as root refuses to start without one); the container keeps it apart
|
|
710
|
+
args: [profile.arg, ...(isDockerImage() ? ['--no-sandbox'] : [])],
|
|
707
711
|
});
|
|
708
712
|
await browser.setCookie({ ...server.cookie, domain: 'localhost', path: '/', httpOnly: true });
|
|
709
713
|
// The config mdToPdf() would build, on our server's port
|
package/dist/tools/process.js
CHANGED
|
@@ -4,6 +4,8 @@ import os from 'os';
|
|
|
4
4
|
import { KillProcessArgsSchema } from './schemas.js';
|
|
5
5
|
import { resolveProgramPath } from '../utils/shell.js';
|
|
6
6
|
import { terminatePid } from '../utils/process-tree.js';
|
|
7
|
+
import { terminalManager } from '../terminal-manager.js';
|
|
8
|
+
import { terminationFailedResult } from './improved-process-tools.js';
|
|
7
9
|
const execFileAsync = promisify(execFile);
|
|
8
10
|
/**
|
|
9
11
|
* Parse `tasklist /FO CSV /NH` output (#662). Fields per row, all quoted:
|
|
@@ -74,11 +76,17 @@ export async function killProcess(args) {
|
|
|
74
76
|
isError: true,
|
|
75
77
|
};
|
|
76
78
|
}
|
|
79
|
+
const pid = parsed.data.pid;
|
|
80
|
+
// A start_process session ends with every process its command started, as with force_terminate
|
|
81
|
+
const outcome = await terminalManager.forceTerminate(pid);
|
|
82
|
+
if (outcome === 'failed')
|
|
83
|
+
return terminationFailedResult(pid);
|
|
77
84
|
try {
|
|
78
85
|
// Returns once the process is gone, so a success means it no longer runs
|
|
79
|
-
|
|
86
|
+
if (outcome === 'not_found')
|
|
87
|
+
await terminatePid(pid);
|
|
80
88
|
return {
|
|
81
|
-
content: [{ type: "text", text: `Successfully terminated process ${
|
|
89
|
+
content: [{ type: "text", text: `Successfully terminated process ${pid}` }],
|
|
82
90
|
};
|
|
83
91
|
}
|
|
84
92
|
catch (error) {
|
|
@@ -234,7 +234,7 @@ async function detectInstallationSource() {
|
|
|
234
234
|
return {
|
|
235
235
|
source: 'docker',
|
|
236
236
|
details: {
|
|
237
|
-
container_id: process.env.HOSTNAME
|
|
237
|
+
container_id: process.env.HOSTNAME ? process.env.HOSTNAME.substring(0, 8) + '...' : 'unknown'
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
240
|
}
|
|
@@ -246,7 +246,7 @@ async function detectInstallationSource() {
|
|
|
246
246
|
return {
|
|
247
247
|
source: 'docker',
|
|
248
248
|
details: {
|
|
249
|
-
container_id: process.env.HOSTNAME
|
|
249
|
+
container_id: process.env.HOSTNAME ? process.env.HOSTNAME.substring(0, 8) + '...' : 'unknown'
|
|
250
250
|
}
|
|
251
251
|
};
|
|
252
252
|
}
|