@wonderwhy-er/desktop-commander 0.3.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/README.md +2 -0
- package/dist/bootstrap.js +7 -7
- package/dist/bootstrap.js.map +1 -0
- package/dist/command-manager.d.ts +98 -1
- package/dist/command-manager.js +200 -16
- package/dist/command-manager.js.map +1 -0
- package/dist/config-field-definitions.js.map +1 -0
- package/dist/config-manager.js.map +1 -0
- package/dist/config-recovery.js.map +1 -0
- package/dist/config.js.map +1 -0
- package/dist/custom-stdio.js.map +1 -0
- package/dist/error-handlers.js.map +1 -0
- package/dist/handlers/edit-search-handlers.js.map +1 -0
- package/dist/handlers/filesystem-handlers.js.map +1 -0
- package/dist/handlers/history-handlers.js.map +1 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/process-handlers.js.map +1 -0
- package/dist/handlers/search-answers.js.map +1 -0
- package/dist/handlers/search-handlers.js.map +1 -0
- package/dist/handlers/terminal-handlers.js.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/npm-scripts/remote.js +9 -7
- package/dist/npm-scripts/remote.js.map +1 -0
- package/dist/npm-scripts/setup.js.map +1 -0
- package/dist/npm-scripts/uninstall.js.map +1 -0
- package/dist/npm-scripts/verify-ripgrep.js.map +1 -0
- package/dist/remote-device/desktop-commander-integration.js +3 -1
- package/dist/remote-device/desktop-commander-integration.js.map +1 -0
- package/dist/remote-device/device-authenticator.js.map +1 -0
- package/dist/remote-device/device.d.ts +4 -3
- package/dist/remote-device/device.js +120 -33
- package/dist/remote-device/device.js.map +1 -0
- package/dist/remote-device/diagnostics/device-log.js.map +1 -0
- package/dist/remote-device/diagnostics/redact.js +30 -8
- package/dist/remote-device/diagnostics/redact.js.map +1 -0
- package/dist/remote-device/diagnostics/report.js +32 -14
- package/dist/remote-device/diagnostics/report.js.map +1 -0
- package/dist/remote-device/diagnostics/upload.d.ts +1 -1
- package/dist/remote-device/diagnostics/upload.js +3 -3
- package/dist/remote-device/diagnostics/upload.js.map +1 -0
- package/dist/remote-device/mqtt/config.d.ts +1 -0
- package/dist/remote-device/mqtt/config.js +3 -0
- package/dist/remote-device/mqtt/config.js.map +1 -0
- package/dist/remote-device/mqtt/mqtt-enrollment.d.ts +15 -0
- package/dist/remote-device/mqtt/mqtt-enrollment.js +293 -0
- package/dist/remote-device/mqtt/mqtt-enrollment.js.map +1 -0
- package/dist/remote-device/mqtt/mqtt-transport.d.ts +45 -0
- package/dist/remote-device/mqtt/mqtt-transport.js +276 -0
- package/dist/remote-device/mqtt/mqtt-transport.js.map +1 -0
- package/dist/remote-device/realtime-health-telemetry.js.map +1 -0
- package/dist/remote-device/remote-channel.d.ts +20 -3
- package/dist/remote-device/remote-channel.js +185 -21
- package/dist/remote-device/remote-channel.js.map +1 -0
- package/dist/remote-device/remote-utils.d.ts +3 -0
- package/dist/remote-device/remote-utils.js +20 -0
- package/dist/remote-device/remote-utils.js.map +1 -0
- package/dist/remote-device/rollouts.js.map +1 -0
- package/dist/remote-device/transport-telemetry.d.ts +1 -1
- package/dist/remote-device/transport-telemetry.js +8 -5
- package/dist/remote-device/transport-telemetry.js.map +1 -0
- package/dist/search-manager.js.map +1 -0
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -0
- package/dist/terminal-manager.js +4 -41
- package/dist/terminal-manager.js.map +1 -0
- package/dist/tools/config.js.map +1 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/feedback.js.map +1 -0
- package/dist/tools/filesystem.js.map +1 -0
- package/dist/tools/fuzzySearch.js.map +1 -0
- package/dist/tools/fuzzySearchCore.js.map +1 -0
- package/dist/tools/improved-process-tools.d.ts +2 -0
- package/dist/tools/improved-process-tools.js +69 -40
- package/dist/tools/improved-process-tools.js.map +1 -0
- package/dist/tools/mime-types.js.map +1 -0
- package/dist/tools/pdf/extract-images.js.map +1 -0
- package/dist/tools/pdf/index.js.map +1 -0
- package/dist/tools/pdf/lib/pdf2md.js.map +1 -0
- package/dist/tools/pdf/manipulations.js.map +1 -0
- package/dist/tools/pdf/markdown.d.ts +10 -38
- package/dist/tools/pdf/markdown.js +7 -3
- package/dist/tools/pdf/markdown.js.map +1 -0
- package/dist/tools/pdf/utils.js.map +1 -0
- package/dist/tools/process.js +10 -2
- package/dist/tools/process.js.map +1 -0
- package/dist/tools/prompts.js.map +1 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/tools/usage.js.map +1 -0
- package/dist/track-installation.js +2 -2
- package/dist/types.js.map +1 -0
- package/dist/ui/config-editor/config-editor-runtime.js +61 -80
- package/dist/ui/config-editor/src/app.js.map +1 -0
- package/dist/ui/config-editor/src/array-modal.js.map +1 -0
- package/dist/ui/config-editor/src/main.js.map +1 -0
- package/dist/ui/contracts.js.map +1 -0
- package/dist/ui/file-preview/preview-runtime.js +215 -226
- package/dist/ui/file-preview/shared/preview-file-types.js.map +1 -0
- package/dist/ui/file-preview/src/app.js.map +1 -0
- package/dist/ui/file-preview/src/components/code-viewer.js.map +1 -0
- package/dist/ui/file-preview/src/components/highlighting.js.map +1 -0
- package/dist/ui/file-preview/src/components/html-renderer.js.map +1 -0
- package/dist/ui/file-preview/src/components/markdown-renderer.js.map +1 -0
- package/dist/ui/file-preview/src/directory-controller.js.map +1 -0
- package/dist/ui/file-preview/src/document-layout.js.map +1 -0
- package/dist/ui/file-preview/src/document-outline.js.map +1 -0
- package/dist/ui/file-preview/src/document-workspace.js.map +1 -0
- package/dist/ui/file-preview/src/file-type-handlers.js.map +1 -0
- package/dist/ui/file-preview/src/host/external-actions.js.map +1 -0
- package/dist/ui/file-preview/src/host/selection-context.js.map +1 -0
- package/dist/ui/file-preview/src/image-preview.js.map +1 -0
- package/dist/ui/file-preview/src/main.js.map +1 -0
- package/dist/ui/file-preview/src/markdown/conflict-dialog.js.map +1 -0
- package/dist/ui/file-preview/src/markdown/controller.js.map +1 -0
- package/dist/ui/file-preview/src/markdown/editor.js.map +1 -0
- package/dist/ui/file-preview/src/markdown/linking.js.map +1 -0
- package/dist/ui/file-preview/src/markdown/outline.js.map +1 -0
- package/dist/ui/file-preview/src/markdown/parser.js.map +1 -0
- package/dist/ui/file-preview/src/markdown/preview.js.map +1 -0
- package/dist/ui/file-preview/src/markdown/slugify.js.map +1 -0
- package/dist/ui/file-preview/src/markdown/utils.js.map +1 -0
- package/dist/ui/file-preview/src/model.js.map +1 -0
- package/dist/ui/file-preview/src/panel-actions.js.map +1 -0
- package/dist/ui/file-preview/src/path-utils.js.map +1 -0
- package/dist/ui/file-preview/src/payload-utils.js.map +1 -0
- package/dist/ui/file-preview/src/types.js.map +1 -0
- package/dist/ui/resources.js.map +1 -0
- package/dist/ui/shared/compact-row.js.map +1 -0
- package/dist/ui/shared/escape-html.js.map +1 -0
- package/dist/ui/shared/host-context.js.map +1 -0
- package/dist/ui/shared/tool-bridge.js.map +1 -0
- package/dist/ui/shared/tool-shell.js.map +1 -0
- package/dist/ui/shared/ui-event-tracker.js.map +1 -0
- package/dist/ui/shared/widget-state.js.map +1 -0
- package/dist/utils/ab-test.js.map +1 -0
- package/dist/utils/atomic-write.js.map +1 -0
- package/dist/utils/brace-expansion.d.ts +25 -0
- package/dist/utils/brace-expansion.js +171 -0
- package/dist/utils/capture.d.ts +9 -3
- package/dist/utils/capture.js +29 -7
- package/dist/utils/capture.js.map +1 -0
- 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/dockerPrompt.js.map +1 -0
- package/dist/utils/exit-process.js.map +1 -0
- package/dist/utils/feature-flags.js.map +1 -0
- package/dist/utils/files/base.js.map +1 -0
- package/dist/utils/files/binary.js.map +1 -0
- package/dist/utils/files/docx.js.map +1 -0
- package/dist/utils/files/excel.js.map +1 -0
- package/dist/utils/files/factory.js.map +1 -0
- package/dist/utils/files/image.js.map +1 -0
- package/dist/utils/files/index.js.map +1 -0
- package/dist/utils/files/pdf.js.map +1 -0
- package/dist/utils/files/text.js.map +1 -0
- package/dist/utils/fuzzySearchLogger.js.map +1 -0
- package/dist/utils/inline-shells.d.ts +64 -0
- package/dist/utils/inline-shells.js +290 -0
- package/dist/utils/internal-facts.js.map +1 -0
- package/dist/utils/lazy-package.js.map +1 -0
- package/dist/utils/lineEndingHandler.js.map +1 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mcp-ui-ab-test.js.map +1 -0
- package/dist/utils/open-browser.js.map +1 -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-detection.js.map +1 -0
- package/dist/utils/process-tree.js +4 -4
- package/dist/utils/process-tree.js.map +1 -0
- package/dist/utils/rename.js.map +1 -0
- package/dist/utils/ripgrep-resolver.js.map +1 -0
- 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 +47 -0
- package/dist/utils/shell.js +119 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/system-info.d.ts +2 -0
- package/dist/utils/system-info.js +5 -1
- package/dist/utils/system-info.js.map +1 -0
- package/dist/utils/terminal-timestamps.js.map +1 -0
- package/dist/utils/threadpool-size.d.ts +36 -0
- package/dist/utils/threadpool-size.js +143 -0
- package/dist/utils/toolHistory.js.map +1 -0
- package/dist/utils/trackTools.js.map +1 -0
- package/dist/utils/unsupportedParams.js.map +1 -0
- package/dist/utils/usageTracker.js.map +1 -0
- package/dist/utils/welcome-onboarding.js.map +1 -0
- package/dist/utils/withTimeout.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -0
- package/package.json +15 -8
- 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 -38
- package/node_modules/@desktop-commander/telemetry-contract/transport.js +0 -164
- 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
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { parse, forEachChild } from 'unbash';
|
|
2
|
+
import { braceWords, quotedChars, unquotedChars, MAX_BRACE_WORDS } from './brace-expansion.js';
|
|
3
|
+
/**
|
|
4
|
+
* The command check's reader for POSIX shells (bash, zsh, sh, dash, ksh,
|
|
5
|
+
* fish), with unbash, a bash parser. It finds every command the shell would
|
|
6
|
+
* run, also on later lines and inside $( ), backticks, <( ), { } groups,
|
|
7
|
+
* subshells, functions and if, while, for and case bodies. Words inside
|
|
8
|
+
* quotes and heredoc bodies are text. A command name with a {a,b} brace
|
|
9
|
+
* expansion is the first word it expands to, so {sudo,ls} is sudo, and so is
|
|
10
|
+
* {$X,sudo} when $X is empty. zsh and
|
|
11
|
+
* the other shells are read as bash, which covers the commands they have in
|
|
12
|
+
* common.
|
|
13
|
+
*
|
|
14
|
+
* unbash doesn't stop at a syntax error: it returns what it could read and
|
|
15
|
+
* lists the errors, each on the script it found it in ($( ) and backticks
|
|
16
|
+
* are scripts of their own). Any error anywhere is a parse error here, so the
|
|
17
|
+
* check never decides on a command it read only in part.
|
|
18
|
+
*/
|
|
19
|
+
/** Word parts whose text is taken as written (a glob as its own text, not the files it matches) */
|
|
20
|
+
const STATIC_PARTS = new Set(['Literal', 'SingleQuoted', 'AnsiCQuoted', 'Glob']);
|
|
21
|
+
/** Word parts that bash drops when they are empty and unquoted ($X, ${X}, $(cmd)) */
|
|
22
|
+
const VANISHING_PARTS = new Set(['SimpleExpansion', 'ParameterExpansion', 'CommandExpansion']);
|
|
23
|
+
/** The commands that remove a function: unset -f, and zsh's unfunction, unhash -f and disable -f */
|
|
24
|
+
const FUNCTION_REMOVERS = new Set(['unset', 'unfunction', 'unhash', 'disable']);
|
|
25
|
+
/**
|
|
26
|
+
* Stand-ins for a piece known only at run time in a brace word's characters,
|
|
27
|
+
* so that braceWords keeps the words next to it ({$X,sudo} makes $X and sudo):
|
|
28
|
+
* one for a piece in VANISHING_PARTS, one for any other ("$X"). They start
|
|
29
|
+
* with a NUL, which no command text holds: Node starts no command that has one.
|
|
30
|
+
*/
|
|
31
|
+
const DROPPED_IF_EMPTY = '\0$';
|
|
32
|
+
const KEPT_IF_EMPTY = '\0"';
|
|
33
|
+
/**
|
|
34
|
+
* A word that brace expansion made and bash may drop: only pieces it drops
|
|
35
|
+
* when they are empty, and letters, digits or _ after one, which bash may read
|
|
36
|
+
* into a $X's name ({$X,su}do makes $Xdo)
|
|
37
|
+
*/
|
|
38
|
+
const MAY_VANISH = /^(?:\0\$\w*)+$/;
|
|
39
|
+
/**
|
|
40
|
+
* The commands that run, in this shell, code the reader doesn't read: eval and
|
|
41
|
+
* zsh's emulate -c (their words), trap and mapfile or readarray -C (later), .
|
|
42
|
+
* and source (a file), and alias (its value, where the name is used: an alias
|
|
43
|
+
* comes before a function)
|
|
44
|
+
*/
|
|
45
|
+
const CODE_RUNNERS = new Set(['eval', 'emulate', 'trap', 'mapfile', 'readarray', '.', 'source', 'alias']);
|
|
46
|
+
/** The words that run the next word as a command in this shell: builtin, command, and zsh's noglob and nocorrect */
|
|
47
|
+
const COMMAND_PREFIXES = new Set(['builtin', 'command', 'noglob', 'nocorrect']);
|
|
48
|
+
/**
|
|
49
|
+
* A word's value as bash reads it (quotes and escapes removed, $'…' decoded),
|
|
50
|
+
* or null when part of it is known only at run time: an expansion, a command's
|
|
51
|
+
* output, or a {a,b} brace expansion, which makes several words (the reader
|
|
52
|
+
* expands a command name's braces with braceWords).
|
|
53
|
+
*/
|
|
54
|
+
function wordValue(word) {
|
|
55
|
+
return (word.parts ?? []).every((part) => partValue(part) !== null) ? word.value : null;
|
|
56
|
+
}
|
|
57
|
+
/** One part's value as bash reads it, or null when it is known only at run time */
|
|
58
|
+
function partValue(part) {
|
|
59
|
+
if (part.type === 'DoubleQuoted' || part.type === 'LocaleString') {
|
|
60
|
+
if (!part.parts.every((inner) => inner.type === 'Literal'))
|
|
61
|
+
return null;
|
|
62
|
+
return part.parts.map((inner) => (inner.type === 'Literal' ? inner.value : '')).join('');
|
|
63
|
+
}
|
|
64
|
+
return STATIC_PARTS.has(part.type) && 'value' in part ? part.value : null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A word's characters for brace expansion. Only the braces unbash reads as an
|
|
68
|
+
* expansion are syntax. The rest of the word is text, and so are the quoted
|
|
69
|
+
* pieces inside the braces: {"a,b",c} gives a,b and c.
|
|
70
|
+
*/
|
|
71
|
+
function braceChars(word) {
|
|
72
|
+
const chars = [];
|
|
73
|
+
for (const part of word.parts ?? []) {
|
|
74
|
+
if (part.type !== 'BraceExpansion') {
|
|
75
|
+
chars.push(...partChars(part));
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
// The braces' text as written, except the quoted or expanded pieces inside, which are parts of their own
|
|
79
|
+
let at = part.pos;
|
|
80
|
+
for (const inner of part.parts ?? []) {
|
|
81
|
+
chars.push(...unquotedChars(part.text.slice(at - part.pos, inner.pos - part.pos)));
|
|
82
|
+
chars.push(...(inner.type === 'Literal' ? unquotedChars(inner.text) : partChars(inner)));
|
|
83
|
+
at = inner.end;
|
|
84
|
+
}
|
|
85
|
+
chars.push(...unquotedChars(part.text.slice(at - part.pos)));
|
|
86
|
+
}
|
|
87
|
+
return chars;
|
|
88
|
+
}
|
|
89
|
+
/** A part's characters, all text: its value, or a stand-in when it is known only at run time */
|
|
90
|
+
function partChars(part) {
|
|
91
|
+
const value = partValue(part);
|
|
92
|
+
if (value !== null)
|
|
93
|
+
return quotedChars(value);
|
|
94
|
+
return quotedChars(VANISHING_PARTS.has(part.type) ? DROPPED_IF_EMPTY : KEPT_IF_EMPTY);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The words bash makes from a word, each with its value (null when it is known
|
|
98
|
+
* only at run time) and whether bash may drop it, or null past braceWords' limits.
|
|
99
|
+
* A brace expansion makes several and bash drops the empty ones: {,sudo} ls
|
|
100
|
+
* runs sudo, {,} sudo runs sudo, and {$X,sudo} id runs sudo when $X is empty.
|
|
101
|
+
*/
|
|
102
|
+
function wordsMade(word) {
|
|
103
|
+
if (!word.parts?.some((part) => part.type === 'BraceExpansion')) {
|
|
104
|
+
return [{ value: wordValue(word), mayVanish: mayVanish(word) }];
|
|
105
|
+
}
|
|
106
|
+
const made = braceWords(braceChars(word));
|
|
107
|
+
return made && made.map((text) => ({ value: text.includes('\0') ? null : text, mayVanish: MAY_VANISH.test(text) }));
|
|
108
|
+
}
|
|
109
|
+
/** Whether bash may drop the word entirely, so that the next word is the command's name */
|
|
110
|
+
function mayVanish(word) {
|
|
111
|
+
const parts = word.parts ?? [];
|
|
112
|
+
return parts.length > 0 && parts.every((part) => VANISHING_PARTS.has(part.type));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Whether a command may remove the function `name`: one of FUNCTION_REMOVERS
|
|
116
|
+
* anywhere among the command's words (so also after builtin, command or
|
|
117
|
+
* eval), followed by the name or by a word known only at run time
|
|
118
|
+
*/
|
|
119
|
+
function mayRemoveFunction(command, name) {
|
|
120
|
+
const at = command.words.findIndex((word) => word !== null && FUNCTION_REMOVERS.has(word));
|
|
121
|
+
return at >= 0 && command.words.slice(at + 1).some((word) => word === null || word === name);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Whether a command may run code the reader doesn't read, which may remove any
|
|
125
|
+
* function: one of CODE_RUNNERS, also after COMMAND_PREFIXES (command -p eval),
|
|
126
|
+
* or a name known only at run time ($cmd may be unset or eval)
|
|
127
|
+
*/
|
|
128
|
+
function mayRunUnreadCode(command) {
|
|
129
|
+
const { words } = command;
|
|
130
|
+
let at = 0;
|
|
131
|
+
while (COMMAND_PREFIXES.has(words[at] ?? '')) {
|
|
132
|
+
at++;
|
|
133
|
+
while (words[at]?.startsWith('-'))
|
|
134
|
+
at++;
|
|
135
|
+
}
|
|
136
|
+
const name = words[at];
|
|
137
|
+
return name === null || (name !== undefined && CODE_RUNNERS.has(name));
|
|
138
|
+
}
|
|
139
|
+
/** Reads a command for a POSIX shell */
|
|
140
|
+
export async function readPosixCommands(command) {
|
|
141
|
+
const script = parse(command);
|
|
142
|
+
let parseError;
|
|
143
|
+
const commands = [];
|
|
144
|
+
// Positions inside backticks count from the backticks' own text, so a command
|
|
145
|
+
// there is given the start of the backticks around it
|
|
146
|
+
const visit = (node, backticksStart) => {
|
|
147
|
+
if (node.type === 'Script')
|
|
148
|
+
parseError ?? (parseError = node.errors?.[0]?.message);
|
|
149
|
+
if (node.type === 'Command' && node.name) {
|
|
150
|
+
const words = [node.name, ...node.args.filter((arg) => arg.type === 'Word')];
|
|
151
|
+
const values = words.map(wordValue);
|
|
152
|
+
// The name, and the next word too while the words before it may vanish ($EMPTY sudo ls runs sudo)
|
|
153
|
+
for (let i = 0; i < words.length; i++) {
|
|
154
|
+
const made = wordsMade(words[i]);
|
|
155
|
+
if (made === null) {
|
|
156
|
+
parseError ?? (parseError = `brace expansion makes more than ${MAX_BRACE_WORDS} words, or takes too long to read`);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
// Each word made is the name while the ones before it may vanish; those known only at run time all
|
|
160
|
+
// give the word's text as the name, so it is given once
|
|
161
|
+
const kept = made.findIndex((word) => !word.mayVanish);
|
|
162
|
+
const names = kept < 0 ? made : made.slice(0, kept + 1);
|
|
163
|
+
names.forEach((name, k) => {
|
|
164
|
+
if (name.value === null && names.findIndex((other) => other.value === null) < k)
|
|
165
|
+
return;
|
|
166
|
+
commands.push({
|
|
167
|
+
name: name.value ?? words[i].text,
|
|
168
|
+
words: [...made.slice(k).map((word) => word.value), ...values.slice(i + 1)],
|
|
169
|
+
written: [...made.slice(k).map(() => words[i].text), ...words.slice(i + 1).map((word) => word.text)],
|
|
170
|
+
// unbash's value of a word keeps the parts known only at run time as written
|
|
171
|
+
wordTexts: [...made.slice(k).map((word) => word.value ?? words[i].value), ...words.slice(i + 1).map((word) => word.value)],
|
|
172
|
+
start: backticksStart ?? (i === 0 ? node.pos : words[i].pos),
|
|
173
|
+
nameAtRunTime: name.value === null,
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
if (kept >= 0)
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const inBackticks = node.type === 'CommandExpansion' && node.text.startsWith('`');
|
|
181
|
+
const childBackticksStart = inBackticks ? backticksStart ?? node.pos : backticksStart;
|
|
182
|
+
forEachChild(node, (child) => visit(child, childBackticksStart));
|
|
183
|
+
};
|
|
184
|
+
visit(script, undefined);
|
|
185
|
+
if (parseError !== undefined)
|
|
186
|
+
return { commands: [], functions: [], parseError };
|
|
187
|
+
// Only the script's own statements (see CommandReading.functions), and none the
|
|
188
|
+
// text may remove: wherever the removal is written, it may run before a call,
|
|
189
|
+
// from a function's body. Code the reader doesn't read may remove any of them.
|
|
190
|
+
const functions = [];
|
|
191
|
+
const statements = commands.some(mayRunUnreadCode) ? [] : script.commands;
|
|
192
|
+
for (const statement of statements) {
|
|
193
|
+
if (statement.command.type !== 'Function' || statement.background)
|
|
194
|
+
continue;
|
|
195
|
+
const name = statement.command.name.value;
|
|
196
|
+
if (!commands.some((command) => mayRemoveFunction(command, name))) {
|
|
197
|
+
functions.push({ name, end: statement.command.end });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return { commands: commands.sort((a, b) => a.start - b.start), functions };
|
|
201
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { CommandReading } from './command-reading.js';
|
|
2
|
+
/**
|
|
3
|
+
* The command check's reader for PowerShell. No JavaScript parser reads
|
|
4
|
+
* PowerShell correctly (here-strings, @{ } tables, & $var), so a helper
|
|
5
|
+
* PowerShell process reads each command with PowerShell's own parser. It
|
|
6
|
+
* starts at the first PowerShell check, so nothing runs for users who never
|
|
7
|
+
* run PowerShell commands, and it is kept running: a check then takes a few
|
|
8
|
+
* milliseconds instead of PowerShell's start (about a second for Windows
|
|
9
|
+
* PowerShell). It is not a terminal session, so list_sessions never shows it.
|
|
10
|
+
* It starts as the PowerShell a command runs in starts: with the user's
|
|
11
|
+
* profile (start_process starts it without -NoProfile), without
|
|
12
|
+
* -NonInteractive, with -Login for PowerShell 7, and with the commands'
|
|
13
|
+
* environment. So a profile sets the same aliases for both. Only its working
|
|
14
|
+
* folder is its own (see start()).
|
|
15
|
+
*/
|
|
16
|
+
/** How long a check waits for a running helper's answer. A helper that doesn't answer is stopped, and the check fails. */
|
|
17
|
+
export declare const HELPER_TIMEOUT_MS = 5000;
|
|
18
|
+
/**
|
|
19
|
+
* How long the first check waits after a helper starts, PowerShell's start
|
|
20
|
+
* and the user's profile included: about a second for Windows PowerShell,
|
|
21
|
+
* longer on a busy machine or with a slow profile
|
|
22
|
+
*/
|
|
23
|
+
export declare const HELPER_START_TIMEOUT_MS = 15000;
|
|
24
|
+
/** One helper process for one PowerShell program, started at its first read and again after it ended */
|
|
25
|
+
export declare class PowerShellHelper {
|
|
26
|
+
private readonly program;
|
|
27
|
+
private readonly args;
|
|
28
|
+
private child;
|
|
29
|
+
private output;
|
|
30
|
+
private nextId;
|
|
31
|
+
private readonly pending;
|
|
32
|
+
private timer;
|
|
33
|
+
/** Whether the running helper process has answered yet: until then its start counts in the time limit */
|
|
34
|
+
private answered;
|
|
35
|
+
/** Made at each start and sent with every request; an answer has it, a line the profile printed doesn't */
|
|
36
|
+
private token;
|
|
37
|
+
/** args replace the helper's arguments, for a stand-in in tests */
|
|
38
|
+
constructor(program: string, args?: string[]);
|
|
39
|
+
/** The running helper's process id: undefined before the first read and after the process ended */
|
|
40
|
+
get pid(): number | undefined;
|
|
41
|
+
/** Reads one command. It rejects when the helper doesn't answer in time, can't start, or ends first. */
|
|
42
|
+
read(command: string): Promise<CommandReading>;
|
|
43
|
+
/** The time limit for the oldest waiting request: longer while the helper hasn't answered since it started */
|
|
44
|
+
private startTimeLimit;
|
|
45
|
+
/** Ends the helper process. The next read starts a new one. */
|
|
46
|
+
stop(): void;
|
|
47
|
+
private start;
|
|
48
|
+
private onOutput;
|
|
49
|
+
private onAnswer;
|
|
50
|
+
/** The helper process ended or failed to start: every waiting read fails, and the next read starts a new one */
|
|
51
|
+
private ended;
|
|
52
|
+
private fail;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Reads a command for a PowerShell shell ("powershell.exe", "pwsh" or a path),
|
|
56
|
+
* with the same program as the helper. checkCommand() has made sure it's there.
|
|
57
|
+
*/
|
|
58
|
+
export declare function readPowerShellCommands(command: string, shell: string): Promise<CommandReading>;
|
|
59
|
+
/** The process ids of the helpers running now, for tests */
|
|
60
|
+
export declare function runningPowerShellHelpers(): number[];
|