@wonderwhy-er/desktop-commander 0.3.2-alpha.3 → 0.3.2
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/command-manager.d.ts +4 -4
- package/dist/command-manager.js +58 -21
- package/dist/ui/config-editor/config-editor-runtime.js +80 -61
- package/dist/ui/file-preview/preview-runtime.js +226 -215
- package/dist/utils/brace-expansion.d.ts +6 -1
- package/dist/utils/brace-expansion.js +33 -12
- package/dist/utils/cmd-commands.d.ts +2 -2
- package/dist/utils/cmd-commands.js +57 -9
- package/dist/utils/command-reading.d.ts +17 -3
- package/dist/utils/command-reading.js +8 -1
- package/dist/utils/command-wrappers.d.ts +3 -3
- package/dist/utils/command-wrappers.js +37 -14
- package/dist/utils/inline-shells.d.ts +5 -2
- package/dist/utils/inline-shells.js +30 -10
- package/dist/utils/posix-commands.d.ts +5 -2
- package/dist/utils/posix-commands.js +68 -32
- package/dist/utils/posix-shell-capabilities.d.ts +8 -0
- package/dist/utils/posix-shell-capabilities.js +120 -0
- package/dist/utils/powershell-commands.d.ts +2 -1
- package/dist/utils/powershell-commands.js +54 -6
- package/dist/utils/shell-script-files.d.ts +5 -1
- package/dist/utils/shell-script-files.js +38 -19
- package/dist/utils/shell.d.ts +4 -3
- package/dist/utils/shell.js +9 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/bootstrap.js.map +0 -1
- package/dist/command-manager.js.map +0 -1
- package/dist/config-field-definitions.js.map +0 -1
- package/dist/config-manager.js.map +0 -1
- package/dist/config-recovery.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/custom-stdio.js.map +0 -1
- package/dist/error-handlers.js.map +0 -1
- package/dist/handlers/edit-search-handlers.js.map +0 -1
- package/dist/handlers/filesystem-handlers.js.map +0 -1
- package/dist/handlers/history-handlers.js.map +0 -1
- package/dist/handlers/index.js.map +0 -1
- package/dist/handlers/process-handlers.js.map +0 -1
- package/dist/handlers/search-answers.js.map +0 -1
- package/dist/handlers/search-handlers.js.map +0 -1
- package/dist/handlers/terminal-handlers.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/npm-scripts/remote.js.map +0 -1
- package/dist/npm-scripts/setup.js.map +0 -1
- package/dist/npm-scripts/uninstall.js.map +0 -1
- package/dist/npm-scripts/verify-ripgrep.js.map +0 -1
- package/dist/remote-device/desktop-commander-integration.js.map +0 -1
- package/dist/remote-device/device-authenticator.js.map +0 -1
- package/dist/remote-device/device.js.map +0 -1
- package/dist/remote-device/diagnostics/device-log.js.map +0 -1
- package/dist/remote-device/diagnostics/redact.js.map +0 -1
- package/dist/remote-device/diagnostics/report.js.map +0 -1
- package/dist/remote-device/diagnostics/upload.js.map +0 -1
- package/dist/remote-device/mqtt/config.js.map +0 -1
- package/dist/remote-device/mqtt/mqtt-enrollment.js.map +0 -1
- package/dist/remote-device/mqtt/mqtt-transport.js.map +0 -1
- package/dist/remote-device/realtime-health-telemetry.js.map +0 -1
- package/dist/remote-device/remote-channel.js.map +0 -1
- package/dist/remote-device/remote-utils.js.map +0 -1
- package/dist/remote-device/rollouts.js.map +0 -1
- package/dist/remote-device/transport-telemetry.js.map +0 -1
- package/dist/search-manager.js.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/terminal-manager.js.map +0 -1
- package/dist/tools/config.js.map +0 -1
- package/dist/tools/edit.js.map +0 -1
- package/dist/tools/feedback.js.map +0 -1
- package/dist/tools/filesystem.js.map +0 -1
- package/dist/tools/fuzzySearch.js.map +0 -1
- package/dist/tools/fuzzySearchCore.js.map +0 -1
- package/dist/tools/improved-process-tools.js.map +0 -1
- package/dist/tools/mime-types.js.map +0 -1
- package/dist/tools/pdf/extract-images.js.map +0 -1
- package/dist/tools/pdf/index.js.map +0 -1
- package/dist/tools/pdf/lib/pdf2md.js.map +0 -1
- package/dist/tools/pdf/manipulations.js.map +0 -1
- package/dist/tools/pdf/markdown.js.map +0 -1
- package/dist/tools/pdf/utils.js.map +0 -1
- package/dist/tools/process.js.map +0 -1
- package/dist/tools/prompts.js.map +0 -1
- package/dist/tools/schemas.js.map +0 -1
- package/dist/tools/usage.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/ui/config-editor/src/app.js.map +0 -1
- package/dist/ui/config-editor/src/array-modal.js.map +0 -1
- package/dist/ui/config-editor/src/main.js.map +0 -1
- package/dist/ui/contracts.js.map +0 -1
- package/dist/ui/file-preview/shared/preview-file-types.js.map +0 -1
- package/dist/ui/file-preview/src/app.js.map +0 -1
- package/dist/ui/file-preview/src/components/code-viewer.js.map +0 -1
- package/dist/ui/file-preview/src/components/highlighting.js.map +0 -1
- package/dist/ui/file-preview/src/components/html-renderer.js.map +0 -1
- package/dist/ui/file-preview/src/components/markdown-renderer.js.map +0 -1
- package/dist/ui/file-preview/src/directory-controller.js.map +0 -1
- package/dist/ui/file-preview/src/document-layout.js.map +0 -1
- package/dist/ui/file-preview/src/document-outline.js.map +0 -1
- package/dist/ui/file-preview/src/document-workspace.js.map +0 -1
- package/dist/ui/file-preview/src/file-type-handlers.js.map +0 -1
- package/dist/ui/file-preview/src/host/external-actions.js.map +0 -1
- package/dist/ui/file-preview/src/host/selection-context.js.map +0 -1
- package/dist/ui/file-preview/src/image-preview.js.map +0 -1
- package/dist/ui/file-preview/src/main.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/conflict-dialog.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/controller.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/editor.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/linking.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/outline.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/parser.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/preview.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/slugify.js.map +0 -1
- package/dist/ui/file-preview/src/markdown/utils.js.map +0 -1
- package/dist/ui/file-preview/src/model.js.map +0 -1
- package/dist/ui/file-preview/src/panel-actions.js.map +0 -1
- package/dist/ui/file-preview/src/path-utils.js.map +0 -1
- package/dist/ui/file-preview/src/payload-utils.js.map +0 -1
- package/dist/ui/file-preview/src/types.js.map +0 -1
- package/dist/ui/resources.js.map +0 -1
- package/dist/ui/shared/compact-row.js.map +0 -1
- package/dist/ui/shared/escape-html.js.map +0 -1
- package/dist/ui/shared/host-context.js.map +0 -1
- package/dist/ui/shared/tool-bridge.js.map +0 -1
- package/dist/ui/shared/tool-shell.js.map +0 -1
- package/dist/ui/shared/ui-event-tracker.js.map +0 -1
- package/dist/ui/shared/widget-state.js.map +0 -1
- package/dist/utils/ab-test.js.map +0 -1
- package/dist/utils/atomic-write.js.map +0 -1
- package/dist/utils/capture.js.map +0 -1
- package/dist/utils/dockerPrompt.js.map +0 -1
- package/dist/utils/exit-process.js.map +0 -1
- package/dist/utils/feature-flags.js.map +0 -1
- package/dist/utils/files/base.js.map +0 -1
- package/dist/utils/files/binary.js.map +0 -1
- package/dist/utils/files/docx.js.map +0 -1
- package/dist/utils/files/excel.js.map +0 -1
- package/dist/utils/files/factory.js.map +0 -1
- package/dist/utils/files/image.js.map +0 -1
- package/dist/utils/files/index.js.map +0 -1
- package/dist/utils/files/pdf.js.map +0 -1
- package/dist/utils/files/text.js.map +0 -1
- package/dist/utils/fuzzySearchLogger.js.map +0 -1
- package/dist/utils/internal-facts.js.map +0 -1
- package/dist/utils/lazy-package.js.map +0 -1
- package/dist/utils/lineEndingHandler.js.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/mcp-ui-ab-test.js.map +0 -1
- package/dist/utils/open-browser.js.map +0 -1
- package/dist/utils/process-detection.js.map +0 -1
- package/dist/utils/process-tree.js.map +0 -1
- package/dist/utils/rename.js.map +0 -1
- package/dist/utils/ripgrep-resolver.js.map +0 -1
- package/dist/utils/shell.js.map +0 -1
- package/dist/utils/system-info.js.map +0 -1
- package/dist/utils/terminal-timestamps.js.map +0 -1
- package/dist/utils/toolHistory.js.map +0 -1
- package/dist/utils/trackTools.js.map +0 -1
- package/dist/utils/unsupportedParams.js.map +0 -1
- package/dist/utils/usageTracker.js.map +0 -1
- package/dist/utils/welcome-onboarding.js.map +0 -1
- package/dist/utils/withTimeout.js.map +0 -1
- package/dist/version.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CommandReadOptions, type CommandReading } from './utils/command-reading.js';
|
|
2
2
|
/**
|
|
3
3
|
* The check's answer for one command.
|
|
4
4
|
* - allowed: no blocked program runs.
|
|
@@ -43,7 +43,7 @@ declare class CommandManager {
|
|
|
43
43
|
* bash reader, and where that can't parse fish's own syntax (for … end,
|
|
44
44
|
* echo (date)), as main reads it: by the names extractCommands() finds.
|
|
45
45
|
*/
|
|
46
|
-
readCommands(command: string, shell: string): Promise<CommandReading>;
|
|
46
|
+
readCommands(command: string, shell: string, options?: CommandReadOptions): Promise<CommandReading>;
|
|
47
47
|
/**
|
|
48
48
|
* The commands of a reading that run a program: the calls to the script's
|
|
49
49
|
* own functions are left out. A script can define a function with a
|
|
@@ -63,7 +63,7 @@ declare class CommandManager {
|
|
|
63
63
|
* - a program chosen only when the command runs: a name that is a variable
|
|
64
64
|
* or another command's output (& $tool), or eval and Invoke-Expression,
|
|
65
65
|
* which run text the command builds (eval "$CMD");
|
|
66
|
-
* - a script file given to a shell (bash deploy.sh): the commands in it
|
|
66
|
+
* - a script file given to a shell (bash deploy.sh, or forwarded by runuser): the commands in it
|
|
67
67
|
* aren't in the text. A file named only when the command runs ("$SCRIPT")
|
|
68
68
|
* counts as a program chosen at run time, named by the shell.
|
|
69
69
|
*/
|
|
@@ -90,7 +90,7 @@ declare class CommandManager {
|
|
|
90
90
|
* error or a missing PowerShell is allowed instead: nothing runs, and
|
|
91
91
|
* PowerShell or start_process answers.
|
|
92
92
|
*/
|
|
93
|
-
checkCommand(command: string, shell: string): Promise<CommandCheck>;
|
|
93
|
+
checkCommand(command: string, shell: string, options?: CommandReadOptions): Promise<CommandCheck>;
|
|
94
94
|
/**
|
|
95
95
|
* checkCommand() for a command, or for a command text in it: each text is
|
|
96
96
|
* checked once per command in each shell, however many readings give it.
|
package/dist/command-manager.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
import { configManager } from './config-manager.js';
|
|
3
4
|
import { capture } from "./utils/capture.js";
|
|
4
|
-
import { getShellType, isShellAvailable, programName } from './utils/shell.js';
|
|
5
|
+
import { getShellType, isShellAvailable, programName, resolveShellPath } from './utils/shell.js';
|
|
5
6
|
import { sameShellTexts, shellRuns } from './utils/inline-shells.js';
|
|
6
7
|
import { shellScriptFiles } from './utils/shell-script-files.js';
|
|
7
8
|
import { readPosixCommands } from './utils/posix-commands.js';
|
|
8
9
|
import { readPowerShellCommands } from './utils/powershell-commands.js';
|
|
9
10
|
import { readCmdCommands } from './utils/cmd-commands.js';
|
|
10
11
|
import { withStartedPrograms } from './utils/command-wrappers.js';
|
|
12
|
+
import { IncompleteArgumentsError, requireCompleteArguments } from './utils/command-reading.js';
|
|
11
13
|
class CommandManager {
|
|
12
14
|
getBaseCommand(command) {
|
|
13
15
|
return command.split(' ')[0].toLowerCase().trim();
|
|
@@ -224,14 +226,24 @@ class CommandManager {
|
|
|
224
226
|
* bash reader, and where that can't parse fish's own syntax (for … end,
|
|
225
227
|
* echo (date)), as main reads it: by the names extractCommands() finds.
|
|
226
228
|
*/
|
|
227
|
-
async readCommands(command, shell) {
|
|
229
|
+
async readCommands(command, shell, options = {}) {
|
|
228
230
|
switch (getShellType(shell)) {
|
|
229
231
|
case 'powershell':
|
|
230
232
|
return readPowerShellCommands(command, shell);
|
|
231
233
|
case 'cmd':
|
|
232
|
-
return readCmdCommands(command);
|
|
234
|
+
return readCmdCommands(command, options);
|
|
233
235
|
}
|
|
234
|
-
|
|
236
|
+
// Resolve the actual caller selection, not the adapter's anchored launch alias.
|
|
237
|
+
// Only filesystem identity is read here; unknown endpoints keep the legacy reading.
|
|
238
|
+
let selectedEndpoint;
|
|
239
|
+
const selected = resolveShellPath(shell);
|
|
240
|
+
if (selected !== null) {
|
|
241
|
+
try {
|
|
242
|
+
selectedEndpoint = fs.realpathSync(selected);
|
|
243
|
+
}
|
|
244
|
+
catch { /* Missing identity stays unsupported. */ }
|
|
245
|
+
}
|
|
246
|
+
const reading = await readPosixCommands(command, selectedEndpoint);
|
|
235
247
|
// fish's name, as getShellSpawnArgs() finds it
|
|
236
248
|
if (reading.parseError === undefined || !path.basename(shell).toLowerCase().includes('fish'))
|
|
237
249
|
return reading;
|
|
@@ -272,7 +284,7 @@ class CommandManager {
|
|
|
272
284
|
* - a program chosen only when the command runs: a name that is a variable
|
|
273
285
|
* or another command's output (& $tool), or eval and Invoke-Expression,
|
|
274
286
|
* which run text the command builds (eval "$CMD");
|
|
275
|
-
* - a script file given to a shell (bash deploy.sh): the commands in it
|
|
287
|
+
* - a script file given to a shell (bash deploy.sh, or forwarded by runuser): the commands in it
|
|
276
288
|
* aren't in the text. A file named only when the command runs ("$SCRIPT")
|
|
277
289
|
* counts as a program chosen at run time, named by the shell.
|
|
278
290
|
*/
|
|
@@ -283,8 +295,14 @@ class CommandManager {
|
|
|
283
295
|
unseen.push({ what: cmd.name, inFile: false });
|
|
284
296
|
continue;
|
|
285
297
|
}
|
|
286
|
-
|
|
287
|
-
|
|
298
|
+
const files = this.scriptFiles(cmd, shellType);
|
|
299
|
+
unseen.push(...files);
|
|
300
|
+
const run = shellRuns(cmd, shellType);
|
|
301
|
+
// A text-program shell can identify a script that the ordinary file reader does not handle.
|
|
302
|
+
if (files.length === 0 && run.shell !== undefined && typeof run.file === 'string') {
|
|
303
|
+
unseen.push({ what: run.file, inFile: true });
|
|
304
|
+
}
|
|
305
|
+
const unknown = sameShellTexts(cmd, shellType).file === null || run.file === null;
|
|
288
306
|
if (unknown && !unseen.some((item) => item.what === cmd.name && !item.inFile)) {
|
|
289
307
|
unseen.push({ what: cmd.name, inFile: false });
|
|
290
308
|
}
|
|
@@ -306,18 +324,23 @@ class CommandManager {
|
|
|
306
324
|
return file === null ? { what: cmd.name, inFile: false } : { what: file, inFile: true };
|
|
307
325
|
};
|
|
308
326
|
if (shellType === 'posix' && (program === 'source' || program === '.')) {
|
|
327
|
+
requireCompleteArguments(cmd);
|
|
309
328
|
return args[0] === undefined ? [] : [hidden(args[0])];
|
|
310
329
|
}
|
|
311
330
|
// PowerShell runs a .ps1 named as the command (./deploy.ps1, & ./deploy.ps1) as a script file
|
|
312
331
|
if (shellType === 'powershell' && /\.ps1$/i.test(cmd.name)) {
|
|
332
|
+
requireCompleteArguments(cmd);
|
|
313
333
|
return [hidden(cmd.name)];
|
|
314
334
|
}
|
|
315
335
|
// PowerShell text and file modes use the same host-option readings.
|
|
316
336
|
if (getShellType(cmd.name) === 'powershell') {
|
|
317
|
-
const file = shellRuns(cmd).file;
|
|
337
|
+
const file = shellRuns(cmd, shellType).file;
|
|
318
338
|
return file === undefined ? [] : [hidden(file)];
|
|
319
339
|
}
|
|
320
|
-
return shellScriptFiles(program, args
|
|
340
|
+
return shellScriptFiles(program, args, {
|
|
341
|
+
written: cmd.written.slice(1),
|
|
342
|
+
...(cmd.argumentError === undefined ? {} : { argumentError: cmd.argumentError }),
|
|
343
|
+
}).map(hidden);
|
|
321
344
|
}
|
|
322
345
|
/**
|
|
323
346
|
* The check's answer for `command` run by `shell`:
|
|
@@ -332,8 +355,8 @@ class CommandManager {
|
|
|
332
355
|
* error or a missing PowerShell is allowed instead: nothing runs, and
|
|
333
356
|
* PowerShell or start_process answers.
|
|
334
357
|
*/
|
|
335
|
-
checkCommand(command, shell) {
|
|
336
|
-
return this.checkText(command, shell, new Map());
|
|
358
|
+
checkCommand(command, shell, options = {}) {
|
|
359
|
+
return this.checkText(command, shell, new Map(), options);
|
|
337
360
|
}
|
|
338
361
|
/**
|
|
339
362
|
* checkCommand() for a command, or for a command text in it: each text is
|
|
@@ -341,16 +364,19 @@ class CommandManager {
|
|
|
341
364
|
* In pwsh $a pwsh $a … each text gives every later one again, so without
|
|
342
365
|
* this the work doubled with each pair.
|
|
343
366
|
*/
|
|
344
|
-
checkText(command, shell, checked) {
|
|
345
|
-
const
|
|
367
|
+
checkText(command, shell, checked, options) {
|
|
368
|
+
const optionsForShell = {
|
|
369
|
+
cmdDelayedExpansion: getShellType(shell) === 'cmd' ? options.cmdDelayedExpansion ?? 'unknown' : 'unknown',
|
|
370
|
+
};
|
|
371
|
+
const key = `${shell}\0${optionsForShell.cmdDelayedExpansion}\0${command}`;
|
|
346
372
|
let check = checked.get(key);
|
|
347
373
|
if (check === undefined) {
|
|
348
|
-
check = this.checkOnce(command, shell, checked);
|
|
374
|
+
check = this.checkOnce(command, shell, checked, optionsForShell);
|
|
349
375
|
checked.set(key, check);
|
|
350
376
|
}
|
|
351
377
|
return check;
|
|
352
378
|
}
|
|
353
|
-
async checkOnce(command, shell, checked) {
|
|
379
|
+
async checkOnce(command, shell, checked, options) {
|
|
354
380
|
try {
|
|
355
381
|
const config = await configManager.getConfig();
|
|
356
382
|
const blockedCommands = config.blockedCommands || [];
|
|
@@ -358,7 +384,8 @@ class CommandManager {
|
|
|
358
384
|
// PowerShell runs nothing when it isn't there or can't parse the command: it, or start_process, answers
|
|
359
385
|
if (shellType === 'powershell' && !isShellAvailable(shell))
|
|
360
386
|
return { verdict: 'allowed' };
|
|
361
|
-
const
|
|
387
|
+
const { cmdDelayedExpansion } = options;
|
|
388
|
+
const reading = await this.readCommands(command, shell, options);
|
|
362
389
|
// A parse error is the command's fault, not the server's, so it isn't logged or sent
|
|
363
390
|
if (reading.parseError !== undefined) {
|
|
364
391
|
return shellType === 'powershell'
|
|
@@ -381,20 +408,28 @@ class CommandManager {
|
|
|
381
408
|
let unreadable;
|
|
382
409
|
for (const found of running) {
|
|
383
410
|
unseen.push(...this.findUnseen([found], shellType));
|
|
384
|
-
const run = shellRuns(found);
|
|
411
|
+
const run = shellRuns(found, shellType);
|
|
385
412
|
const texts = [
|
|
386
|
-
...sameShellTexts(found, shellType).texts.map((text) => ({
|
|
413
|
+
...sameShellTexts(found, shellType).texts.map((text) => ({
|
|
414
|
+
text,
|
|
415
|
+
runs: shell,
|
|
416
|
+
cmdDelayedExpansion,
|
|
417
|
+
})),
|
|
387
418
|
// su -c's text runs in sh, runas's command line as cmd reads it
|
|
388
|
-
...run.texts.map((text) => ({
|
|
419
|
+
...run.texts.map((text) => ({
|
|
420
|
+
text,
|
|
421
|
+
runs: run.shell ?? found.name,
|
|
422
|
+
cmdDelayedExpansion: run.cmdDelayedExpansion ?? 'unknown',
|
|
423
|
+
})),
|
|
389
424
|
];
|
|
390
|
-
for (const { text, runs } of texts) {
|
|
425
|
+
for (const { text, runs, cmdDelayedExpansion: innerMode } of texts) {
|
|
391
426
|
// The shell that runs the command looks a PowerShell's name up itself, in its working folder
|
|
392
427
|
// too: one the check can't find is read by the PowerShell running the command, when that is one
|
|
393
428
|
const reader = getShellType(runs) !== 'powershell' ? runs
|
|
394
429
|
: [runs, shell].find((candidate) => getShellType(candidate) === 'powershell' && isShellAvailable(candidate));
|
|
395
430
|
const inner = reader === undefined
|
|
396
431
|
? { verdict: 'failed', reason: `${runs} isn't installed here, so the command given to it can't be read` }
|
|
397
|
-
: await this.checkText(text, reader, checked);
|
|
432
|
+
: await this.checkText(text, reader, checked, { cmdDelayedExpansion: innerMode });
|
|
398
433
|
if (inner.verdict === 'blocked')
|
|
399
434
|
return inner;
|
|
400
435
|
if (inner.verdict === 'failed')
|
|
@@ -408,6 +443,8 @@ class CommandManager {
|
|
|
408
443
|
return unseen.length > 0 ? { verdict: 'unseen', unseen } : { verdict: 'allowed' };
|
|
409
444
|
}
|
|
410
445
|
catch (error) {
|
|
446
|
+
if (error instanceof IncompleteArgumentsError)
|
|
447
|
+
return { verdict: 'failed', reason: error.message };
|
|
411
448
|
const reason = error instanceof Error ? error.message : String(error);
|
|
412
449
|
console.error('Error validating command:', error);
|
|
413
450
|
capture('server_validate_command_error', {
|