@noldova/terminal 0.0.6 → 0.0.8
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 +1 -1
- package/module.json +2 -2
- package/package.json +8 -6
- package/src/exceptions/stored-lines-damaged.exception.js +2 -1
- package/src/models/hosted-terminal.js +14 -7
- package/src/models/integration-script.js +15 -0
- package/src/models/mark-introducer.js +15 -0
- package/src/models/mark-terminator.js +15 -0
- package/src/models/mirror-line.js +2 -1
- package/src/models/one-shot-launch.js +2 -1
- package/src/models/output-span.js +15 -0
- package/src/models/shell-candidate.js +21 -0
- package/src/models/shell-mark.js +2 -1
- package/src/models/taken-segment.js +15 -0
- package/src/models/terminal-folder-key.js +15 -0
- package/src/models/terminal-opening.js +2 -1
- package/src/models/tracked-command.js +2 -1
- package/src/models/typed-line.js +2 -1
- package/src/models/wsl-launcher.js +15 -0
- package/src/resources.js +7 -3
- package/src/runtime-part.js +2 -1
- package/src/services/agent-terminal.js +8 -5
- package/src/services/agent-terminals.js +3 -2
- package/src/services/bounded-reads.js +7 -5
- package/src/services/change-signal.js +5 -4
- package/src/services/command-runner.js +10 -4
- package/src/services/command-tracker.js +5 -4
- package/src/services/completion-source.js +27 -23
- package/src/services/context-pty-process.js +3 -2
- package/src/services/context-pty-spawner.js +2 -1
- package/src/services/deferred-pty-process.js +7 -5
- package/src/services/escape-sequence-tracker.js +2 -1
- package/src/services/failure-text.js +2 -1
- package/src/services/flow-controller.js +5 -4
- package/src/services/latest-environment.js +2 -1
- package/src/services/mac-environment.js +3 -2
- package/src/services/mark-scanner.js +22 -14
- package/src/services/one-shot-command.js +3 -2
- package/src/services/output-batcher.js +2 -1
- package/src/services/output-log.js +4 -1
- package/src/services/powershell-binding.js +7 -6
- package/src/services/pseudo-terminal.js +7 -1
- package/src/services/registry-export.js +3 -2
- package/src/services/resize-wakeup.js +2 -1
- package/src/services/saved-terminals.js +2 -1
- package/src/services/shared-reads.js +3 -2
- package/src/services/shell-command.js +14 -15
- package/src/services/shell-integration.js +24 -22
- package/src/services/shell-locator.js +25 -22
- package/src/services/shell-words.js +3 -2
- package/src/services/system-requirements.js +9 -9
- package/src/services/terminal-audience.js +10 -9
- package/src/services/terminal-history-folder.js +5 -4
- package/src/services/terminal-history-segment.js +2 -1
- package/src/services/terminal-history.js +14 -12
- package/src/services/terminal-host.js +104 -101
- package/src/services/terminal-line-reader.js +3 -2
- package/src/services/terminal-mirror.js +13 -12
- package/src/services/terminal-session.js +37 -26
- package/src/services/visual-studio.reader.js +3 -2
- package/src/services/windows-environment.js +12 -11
- package/src/services/windows-folder-access.js +2 -1
- package/src/services/wsl-distribution.reader.js +2 -1
- package/src/tools/models/agent-terminal-opening.js +2 -1
- package/src/tools/models/output-chunk.js +4 -1
- package/src/tools/models/output-excerpt.js +12 -6
- package/src/tools/models/terminal-open-input.js +3 -2
- package/src/tools/models/terminal-output-report.js +5 -4
- package/src/tools/models/terminal-run-input.js +2 -1
- package/src/tools/models/terminal-target-input.js +2 -1
- package/src/tools/models/terminal-write-input.js +2 -1
- package/src/tools/models/tool-call-context.js +4 -3
- package/src/tools/services/permission-details.js +3 -2
- package/src/tools/services/permission-gate.js +2 -1
- package/src/tools/services/terminal-access-policy.js +8 -7
- package/src/tools/services/terminal-interrupt-tool.js +2 -1
- package/src/tools/services/terminal-read-tool.js +3 -2
- package/src/tools/services/terminal-run-tool.js +6 -5
- package/src/tools/services/terminal-text-escaper.js +2 -1
- package/src/tools/services/terminal-tool.js +2 -1
- package/src/tools/services/terminal-write-tool.js +2 -1
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { EnvironmentExportInvalidException } from "../exceptions/environment-export-invalid.exception.js";
|
|
9
10
|
import { RegistryValue } from "../models/registry-value.js";
|
|
10
11
|
import { Resources } from "../resources.js";
|
|
@@ -58,7 +59,7 @@ export class RegistryExport {
|
|
|
58
59
|
this.index++;
|
|
59
60
|
for (;;) {
|
|
60
61
|
const character = this.text[this.index];
|
|
61
|
-
if (character
|
|
62
|
+
if (Object.isUndefined(character))
|
|
62
63
|
throw new EnvironmentExportInvalidException();
|
|
63
64
|
if (character === Resources.registryExportQuote) {
|
|
64
65
|
this.index++;
|
|
@@ -66,7 +67,7 @@ export class RegistryExport {
|
|
|
66
67
|
}
|
|
67
68
|
if (character === Resources.registryExportEscape) {
|
|
68
69
|
const escaped = this.text[this.index + 1];
|
|
69
|
-
if (escaped
|
|
70
|
+
if (Object.isUndefined(escaped))
|
|
70
71
|
throw new EnvironmentExportInvalidException();
|
|
71
72
|
value += escaped;
|
|
72
73
|
this.index += 2;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { Resources } from "../resources.js";
|
|
9
10
|
export class ResizeWakeup {
|
|
10
11
|
write;
|
|
@@ -18,7 +19,7 @@ export class ResizeWakeup {
|
|
|
18
19
|
this.output = "";
|
|
19
20
|
}
|
|
20
21
|
receive(data) {
|
|
21
|
-
if (this.output
|
|
22
|
+
if (Object.isNull(this.output))
|
|
22
23
|
return;
|
|
23
24
|
this.output += data;
|
|
24
25
|
if (Resources.escapesOnly.test(this.output))
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { Migration } from "@noldova/desktop.runtime";
|
|
9
10
|
import { SavedTerminal } from "../models/saved-terminal.js";
|
|
10
11
|
import { Resources } from "../resources.js";
|
|
@@ -24,7 +25,7 @@ export class SavedTerminals {
|
|
|
24
25
|
}
|
|
25
26
|
list() {
|
|
26
27
|
return this.database.readAll(Resources.savedTerminalsListQuery)
|
|
27
|
-
.map(t => new SavedTerminal(String(t[Resources.savedTerminalsSessionIdColumn]), String(t[Resources.savedTerminalsShellIdColumn]), String(t[Resources.savedTerminalsFolderColumn]), Number(t[Resources.savedTerminalsIsPanelTerminalColumn]) === 1, t[Resources.savedTerminalsOwnerColumn]
|
|
28
|
+
.map(t => new SavedTerminal(String(t[Resources.savedTerminalsSessionIdColumn]), String(t[Resources.savedTerminalsShellIdColumn]), String(t[Resources.savedTerminalsFolderColumn]), Number(t[Resources.savedTerminalsIsPanelTerminalColumn]) === 1, Object.isNull(t[Resources.savedTerminalsOwnerColumn]) ? null : String(t[Resources.savedTerminalsOwnerColumn]), Number(t[Resources.savedTerminalsOpensTabColumn]) === 1, Object.isNull(t[Resources.savedTerminalsNameColumn]) ? null : String(t[Resources.savedTerminalsNameColumn])));
|
|
28
29
|
}
|
|
29
30
|
save(terminal) {
|
|
30
31
|
this.write(t => Resources.formatSavedTerminalUnwritable(terminal.sessionId, t), () => this.database.run(Resources.savedTerminalsSaveStatement, terminal.sessionId, terminal.shellId, terminal.folder, terminal.isPanelTerminal ? 1 : 0, terminal.owner, terminal.opensTab ? 1 : 0));
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { ReadDroppedException } from "../exceptions/read-dropped.exception.js";
|
|
9
10
|
import { SharedRead } from "../models/shared-read.js";
|
|
10
11
|
import { Resources } from "../resources.js";
|
|
@@ -39,7 +40,7 @@ export class SharedReads {
|
|
|
39
40
|
if (signal.aborted)
|
|
40
41
|
return Promise.reject(new ReadDroppedException());
|
|
41
42
|
let shared = running.get(path);
|
|
42
|
-
if (shared
|
|
43
|
+
if (Object.isUndefined(shared)) {
|
|
43
44
|
const created = new SharedRead(read);
|
|
44
45
|
const settled = () => void running.delete(path);
|
|
45
46
|
void created.promise.then(settled, settled);
|
|
@@ -55,7 +56,7 @@ export class SharedReads {
|
|
|
55
56
|
startWaiting() {
|
|
56
57
|
while (this.running < Resources.completionConcurrentReads) {
|
|
57
58
|
const next = this.waiting.values().next().value;
|
|
58
|
-
if (next
|
|
59
|
+
if (Object.isUndefined(next))
|
|
59
60
|
return;
|
|
60
61
|
this.waiting.delete(next);
|
|
61
62
|
this.running++;
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import { OutputSpan } from "../models/output-span.js";
|
|
8
10
|
import { Resources } from "../resources.js";
|
|
9
11
|
import { CommandStatus } from "../tools/enums/command-status.js";
|
|
10
12
|
import { RunMethod } from "../tools/enums/run-method.js";
|
|
11
|
-
import { OutputChunk } from "../tools/models/output-chunk.js";
|
|
12
13
|
export class ShellCommand {
|
|
13
14
|
session;
|
|
14
15
|
line;
|
|
@@ -33,31 +34,31 @@ export class ShellCommand {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
get status() {
|
|
36
|
-
if (this.givenUp
|
|
37
|
+
if (!Object.isNull(this.givenUp))
|
|
37
38
|
return CommandStatus.Killed;
|
|
38
|
-
if (this.tracked?.hasEnded === true || this.unmarkedEnd
|
|
39
|
+
if (this.tracked?.hasEnded === true || !Object.isNull(this.unmarkedEnd))
|
|
39
40
|
return this.isKilled ? CommandStatus.Killed : CommandStatus.Exited;
|
|
40
|
-
if (this.restartEnd
|
|
41
|
+
if (!Object.isNull(this.restartEnd) || this.session.hasExited)
|
|
41
42
|
return CommandStatus.Killed;
|
|
42
43
|
return this.session.text.isAwaitingSecret ? CommandStatus.AwaitingInput : CommandStatus.Running;
|
|
43
44
|
}
|
|
44
45
|
get exitCode() {
|
|
45
|
-
return this.givenUp
|
|
46
|
+
return Object.isNull(this.givenUp) ? this.tracked?.exitCode ?? null : null;
|
|
46
47
|
}
|
|
47
48
|
get cwd() {
|
|
48
|
-
return this.givenUp
|
|
49
|
+
return Object.isNull(this.givenUp) ? this.tracked?.cwd ?? null : null;
|
|
49
50
|
}
|
|
50
51
|
get hasEnded() {
|
|
51
|
-
return this.givenUp
|
|
52
|
+
return !Object.isNull(this.givenUp) || this.tracked?.hasEnded === true || !Object.isNull(this.unmarkedEnd) || !Object.isNull(this.restartEnd) || this.session.hasExited;
|
|
52
53
|
}
|
|
53
54
|
get outputStart() {
|
|
54
|
-
if (this.givenUp
|
|
55
|
-
return this.givenUp
|
|
55
|
+
if (!Object.isNull(this.givenUp))
|
|
56
|
+
return this.givenUp.start;
|
|
56
57
|
const tracked = this.tracked;
|
|
57
58
|
return tracked?.hasOutputStart === true ? tracked.outputStart : this.line.startOffset;
|
|
58
59
|
}
|
|
59
60
|
get outputEnd() {
|
|
60
|
-
return this.givenUp?.
|
|
61
|
+
return this.givenUp?.end ?? this.tracked?.outputEnd ?? this.unmarkedEnd ?? this.restartEnd ?? this.session.text.endOffset;
|
|
61
62
|
}
|
|
62
63
|
get restartEnd() {
|
|
63
64
|
return this.session.endOfRun(this.run);
|
|
@@ -69,12 +70,10 @@ export class ShellCommand {
|
|
|
69
70
|
return this.line.command;
|
|
70
71
|
}
|
|
71
72
|
readSince(offset) {
|
|
72
|
-
|
|
73
|
-
const end = this.outputEnd;
|
|
74
|
-
return new OutputChunk(this.session.text.readRange(start + offset, end), end - start);
|
|
73
|
+
return this.session.text.readChunk(Math.max(offset, this.outputStart), this.outputEnd);
|
|
75
74
|
}
|
|
76
75
|
waitForOutputAsync(offset, timeoutMilliseconds, signal) {
|
|
77
|
-
return this.session.changes.waitUntilAsync(() => this.hasEnded || this.outputEnd > this.outputStart
|
|
76
|
+
return this.session.changes.waitUntilAsync(() => this.hasEnded || this.outputEnd > Math.max(offset, this.outputStart), timeoutMilliseconds, signal);
|
|
78
77
|
}
|
|
79
78
|
waitForEndAsync(timeoutMilliseconds, signal) {
|
|
80
79
|
return this.session.changes.waitUntilAsync(() => this.hasEnded, timeoutMilliseconds, signal);
|
|
@@ -87,7 +86,7 @@ export class ShellCommand {
|
|
|
87
86
|
setTimeout(() => {
|
|
88
87
|
if (this.hasEnded)
|
|
89
88
|
return;
|
|
90
|
-
this.givenUp =
|
|
89
|
+
this.givenUp = new OutputSpan(this.outputStart, this.outputEnd);
|
|
91
90
|
this.session.changes.notify();
|
|
92
91
|
}, Resources.graceMilliseconds).unref();
|
|
93
92
|
return true;
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { randomBytes } from "node:crypto";
|
|
9
10
|
import path from "node:path";
|
|
10
11
|
import { Resources as ProtocolResources } from "@noldova/terminal.protocol";
|
|
11
12
|
import { ShellFamily } from "../enums/shell-family.js";
|
|
13
|
+
import { IntegrationScript } from "../models/integration-script.js";
|
|
12
14
|
import { ShellLaunch } from "../models/shell-launch.js";
|
|
13
15
|
import { Resources } from "../resources.js";
|
|
14
16
|
import { FailureText } from "./failure-text.js";
|
|
@@ -36,7 +38,7 @@ export class ShellIntegration {
|
|
|
36
38
|
}
|
|
37
39
|
watch(process, launch) {
|
|
38
40
|
const { nonce, nonceFile } = launch;
|
|
39
|
-
if (nonce
|
|
41
|
+
if (Object.isNull(nonce) || Object.isNull(nonceFile))
|
|
40
42
|
return;
|
|
41
43
|
const remove = () => {
|
|
42
44
|
data.dispose();
|
|
@@ -50,7 +52,7 @@ export class ShellIntegration {
|
|
|
50
52
|
const exit = process.onExit(() => remove());
|
|
51
53
|
}
|
|
52
54
|
async removeNonceFileAsync(nonceFile) {
|
|
53
|
-
if (nonceFile
|
|
55
|
+
if (Object.isNull(nonceFile))
|
|
54
56
|
return;
|
|
55
57
|
try {
|
|
56
58
|
await this.writer.removeFileAsync(nonceFile);
|
|
@@ -62,7 +64,7 @@ export class ShellIntegration {
|
|
|
62
64
|
async disposeAsync() {
|
|
63
65
|
const folder = this.folder;
|
|
64
66
|
this.folder = null;
|
|
65
|
-
if (folder
|
|
67
|
+
if (!Object.isNull(folder))
|
|
66
68
|
await this.writer.removeFolderAsync(await folder);
|
|
67
69
|
}
|
|
68
70
|
isSuggesting() {
|
|
@@ -91,16 +93,16 @@ export class ShellIntegration {
|
|
|
91
93
|
if (family === ShellFamily.PowerShell)
|
|
92
94
|
await this.makeSharedMemoryFolderAsync(environment);
|
|
93
95
|
const folder = await this.writeScriptsOrNullAsync();
|
|
94
|
-
const nonceFile = folder
|
|
95
|
-
if (folder
|
|
96
|
+
const nonceFile = Object.isNull(folder) ? null : await this.writeNonceOrNullAsync(folder, nonce);
|
|
97
|
+
if (Object.isNull(folder) || Object.isNull(nonceFile))
|
|
96
98
|
return ShellIntegration.toPlainLaunch(shell, family);
|
|
97
|
-
const noteVariables = note
|
|
99
|
+
const noteVariables = Object.isNull(note) ? {} : { [Resources.noteVariable]: note };
|
|
98
100
|
if (family === ShellFamily.PowerShell)
|
|
99
101
|
return new ShellLaunch(shell.file, [...shell.args, ...Resources.powerShellIntegrationArguments, ShellIntegration.encode([Resources.shellIntegrationPowerShellNonce, Resources.shellIntegrationPowerShellNote, Resources.shellIntegrationPowerShellProfiles, shell.startCommand,
|
|
100
|
-
Resources.shellIntegrationPowerShellScript].filter(t => t
|
|
102
|
+
Resources.shellIntegrationPowerShellScript].filter(t => !Object.isNull(t)).join(Resources.lineFeed))], {
|
|
101
103
|
[Resources.nonceFileVariable]: nonceFile,
|
|
102
104
|
...noteVariables
|
|
103
|
-
}, nonce, nonceFile, note
|
|
105
|
+
}, nonce, nonceFile, !Object.isNull(note));
|
|
104
106
|
if (family === ShellFamily.Bash) {
|
|
105
107
|
const bashScript = path.join(folder, Resources.bashScriptFile).replaceAll(Resources.windowsSeparator, Resources.posixSeparator);
|
|
106
108
|
const isLogin = shell.args.some(t => Resources.loginArguments.includes(t));
|
|
@@ -108,19 +110,19 @@ export class ShellIntegration {
|
|
|
108
110
|
[Resources.nonceFileVariable]: nonceFile.replaceAll(Resources.windowsSeparator, Resources.posixSeparator),
|
|
109
111
|
...(isLogin ? { [Resources.loginVariable]: Resources.shellIntegrationLoginValue } : {}),
|
|
110
112
|
...noteVariables
|
|
111
|
-
}, nonce, nonceFile, note
|
|
113
|
+
}, nonce, nonceFile, !Object.isNull(note));
|
|
112
114
|
}
|
|
113
115
|
const userFolder = environment[Resources.zdotdirVariable];
|
|
114
116
|
return new ShellLaunch(shell.file, shell.args, {
|
|
115
117
|
[Resources.nonceFileVariable]: nonceFile,
|
|
116
118
|
[Resources.zdotdirVariable]: folder,
|
|
117
|
-
...(userFolder
|
|
119
|
+
...(Object.isUndefined(userFolder) ? {} : { [Resources.userZdotdirVariable]: userFolder }),
|
|
118
120
|
...noteVariables
|
|
119
|
-
}, nonce, nonceFile, note
|
|
121
|
+
}, nonce, nonceFile, !Object.isNull(note));
|
|
120
122
|
}
|
|
121
123
|
makeSharedMemoryFolderAsync(environment) {
|
|
122
124
|
const runtimeFolder = environment[Resources.runtimeFolderVariable];
|
|
123
|
-
if (this.platform !== Resources.linuxPlatform || runtimeFolder
|
|
125
|
+
if (this.platform !== Resources.linuxPlatform || Object.isUndefined(runtimeFolder) || !path.posix.isAbsolute(runtimeFolder))
|
|
124
126
|
return Promise.resolve();
|
|
125
127
|
const dotnetFolder = path.posix.join(runtimeFolder, Resources.dotnetFolder);
|
|
126
128
|
const folder = path.posix.join(dotnetFolder, Resources.dotnetSharedMemoryFolder);
|
|
@@ -163,14 +165,14 @@ export class ShellIntegration {
|
|
|
163
165
|
const folder = await this.writer.createPrivateFolderAsync(path.join(this.temporaryFolder, Resources.integrationFolderPrefix));
|
|
164
166
|
try {
|
|
165
167
|
await this.access?.restrictAsync(folder);
|
|
166
|
-
for (const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
168
|
+
for (const script of [
|
|
169
|
+
new IntegrationScript(Resources.bashScriptFile, Resources.shellIntegrationBashScript),
|
|
170
|
+
new IntegrationScript(Resources.zshEnvironmentFile, Resources.shellIntegrationZshEnvironment),
|
|
171
|
+
new IntegrationScript(Resources.zshProfileFile, Resources.shellIntegrationZshProfile),
|
|
172
|
+
new IntegrationScript(Resources.zshInteractiveFile, Resources.shellIntegrationZshInteractive),
|
|
173
|
+
new IntegrationScript(Resources.zshLoginFile, Resources.shellIntegrationZshLogin)
|
|
172
174
|
])
|
|
173
|
-
await this.writer.writeTextAsync(path.join(folder,
|
|
175
|
+
await this.writer.writeTextAsync(path.join(folder, script.fileName), script.text);
|
|
174
176
|
}
|
|
175
177
|
catch (error) {
|
|
176
178
|
await this.writer.removeFolderAsync(folder)
|
|
@@ -181,18 +183,18 @@ export class ShellIntegration {
|
|
|
181
183
|
}
|
|
182
184
|
static toCommandPromptLaunch(shell, note) {
|
|
183
185
|
const [first, ...start] = shell.args;
|
|
184
|
-
if (note
|
|
186
|
+
if (Object.isNull(note) || (!Object.isUndefined(first) && first.toLowerCase() !== Resources.keepOpenArgument))
|
|
185
187
|
return new ShellLaunch(shell.file, shell.args, {}, null);
|
|
186
188
|
return new ShellLaunch(shell.file, Resources.formatCmdNoteLine(shell.file, Resources.noteVariable, Resources.formatCmdStart(start)), { [Resources.noteVariable]: note.slice(0, note.length - Resources.noteLineBreak.length) }, null, null, true);
|
|
187
189
|
}
|
|
188
190
|
static toPlainLaunch(shell, family) {
|
|
189
|
-
if (family !== ShellFamily.PowerShell || shell.startCommand
|
|
191
|
+
if (family !== ShellFamily.PowerShell || Object.isNull(shell.startCommand))
|
|
190
192
|
return new ShellLaunch(shell.file, shell.args, {}, null);
|
|
191
193
|
return new ShellLaunch(shell.file, [...shell.args, ...Resources.powerShellArguments, ShellIntegration.encode(shell.startCommand)], {}, null);
|
|
192
194
|
}
|
|
193
195
|
static toPowerShellLoginLaunch(launch) {
|
|
194
196
|
const [first, ...rest] = [launch.args].flat();
|
|
195
|
-
if (first
|
|
197
|
+
if (Object.isUndefined(first) || !ShellIntegration.isPowerShellLogin(first))
|
|
196
198
|
return launch;
|
|
197
199
|
return new ShellLaunch(Resources.powerShellLoginShell, [...Resources.powerShellLoginShellArguments, launch.file, ...rest], { ...launch.environment, [Resources.powerShellLoginCheckedVariable]: Resources.powerShellLoginCheckedValue }, launch.nonce, launch.nonceFile, launch.printsNote);
|
|
198
200
|
}
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { userInfo } from "node:os";
|
|
9
10
|
import path from "node:path";
|
|
10
11
|
import { TerminalShellKind } from "@noldova/terminal.protocol";
|
|
11
12
|
import { Shell } from "../models/shell.js";
|
|
13
|
+
import { ShellCandidate } from "../models/shell-candidate.js";
|
|
14
|
+
import { WslLauncher } from "../models/wsl-launcher.js";
|
|
12
15
|
import { Resources } from "../resources.js";
|
|
13
16
|
import { FailureText } from "./failure-text.js";
|
|
14
17
|
import { VisualStudioReader } from "./visual-studio.reader.js";
|
|
@@ -32,15 +35,15 @@ export class ShellLocator {
|
|
|
32
35
|
this.userShell = userShell;
|
|
33
36
|
this.fileSystem = fileSystem;
|
|
34
37
|
this.log = log;
|
|
35
|
-
this.wsl = systemRoot
|
|
38
|
+
this.wsl = Object.isUndefined(systemRoot) || systemRoot.length === 0
|
|
36
39
|
? null
|
|
37
|
-
:
|
|
40
|
+
: new WslLauncher(path.win32.join(systemRoot, ...Resources.wslPath), new WslDistributionReader(runner, systemRoot));
|
|
38
41
|
this.visualStudioReader = new VisualStudioReader(runner, fileSystem, environment[Resources.programFilesX86Variable]);
|
|
39
42
|
}
|
|
40
43
|
static readUserShell() {
|
|
41
44
|
try {
|
|
42
45
|
const shell = userInfo().shell;
|
|
43
|
-
return shell
|
|
46
|
+
return Object.isNull(shell) || shell.trim().length === 0 ? null : shell;
|
|
44
47
|
}
|
|
45
48
|
catch (error) {
|
|
46
49
|
if (error instanceof Error && "code" in error && error.code === Resources.systemErrorCode)
|
|
@@ -55,11 +58,11 @@ export class ShellLocator {
|
|
|
55
58
|
return [...installed, ...await this.locateListedAsync(installed)];
|
|
56
59
|
}
|
|
57
60
|
async findAsync(shellId) {
|
|
58
|
-
const isMatch = (shell) => shellId
|
|
61
|
+
const isMatch = (shell) => Object.isNull(shellId) ? shell.isDefault : shell.id === shellId;
|
|
59
62
|
if (this.platform !== Resources.windowsPlatform)
|
|
60
63
|
return (await this.locateOnUnixAsync()).find(isMatch);
|
|
61
64
|
const installed = await this.locateOnWindowsAsync();
|
|
62
|
-
return installed.find(isMatch) ?? (shellId
|
|
65
|
+
return installed.find(isMatch) ?? (Object.isNull(shellId) ? undefined : (await this.locateListedAsync(installed)).find(isMatch));
|
|
63
66
|
}
|
|
64
67
|
async findKindAsync(kinds) {
|
|
65
68
|
const isMatch = (shell) => kinds.includes(shell.kind);
|
|
@@ -80,20 +83,20 @@ export class ShellLocator {
|
|
|
80
83
|
...await this.findGitOnSearchPathAsync(searchPath)
|
|
81
84
|
];
|
|
82
85
|
const candidates = [
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
new ShellCandidate(Resources.pwshId, Resources.pwshName, TerminalShellKind.PowerShell, [
|
|
87
|
+
...ShellLocator.joinIfSet(programFiles, [...Resources.pwshFolder, Resources.pwshFile]),
|
|
88
|
+
...searchPath.map(t => path.win32.join(t, Resources.pwshFile)),
|
|
89
|
+
...ShellLocator.joinIfSet(localAppData, [...Resources.appAliasFolder, Resources.pwshFile])
|
|
90
|
+
], []),
|
|
91
|
+
new ShellCandidate(Resources.windowsPowerShellId, Resources.windowsPowerShellName, TerminalShellKind.PowerShell, ShellLocator.joinIfSet(systemRoot, Resources.windowsPowerShellPath), []),
|
|
92
|
+
new ShellCandidate(Resources.cmdId, Resources.cmdName, TerminalShellKind.CommandPrompt, ShellLocator.joinIfSet(systemRoot, Resources.cmdPath), []),
|
|
93
|
+
new ShellCandidate(Resources.gitBashId, Resources.gitBashName, TerminalShellKind.Bash, gitFolders.map(t => path.win32.join(t, ...Resources.gitBashFile)), Resources.gitBashArguments)
|
|
91
94
|
];
|
|
92
95
|
const shells = [];
|
|
93
|
-
for (const
|
|
94
|
-
const file = await this.findFileAsync(files);
|
|
95
|
-
if (file
|
|
96
|
-
shells.push(new Shell(id, name, kind, file, args, shells.length === 0));
|
|
96
|
+
for (const candidate of candidates) {
|
|
97
|
+
const file = await this.findFileAsync(candidate.files);
|
|
98
|
+
if (!Object.isNull(file))
|
|
99
|
+
shells.push(new Shell(candidate.id, candidate.name, candidate.kind, file, candidate.args, shells.length === 0));
|
|
97
100
|
}
|
|
98
101
|
return shells;
|
|
99
102
|
}
|
|
@@ -103,7 +106,7 @@ export class ShellLocator {
|
|
|
103
106
|
.map(t => t.trim())
|
|
104
107
|
.filter(t => t.startsWith(Resources.posixRoot) && !Resources.nonShellNames.includes(path.posix.basename(t)));
|
|
105
108
|
const preferred = this.userShell ?? this.environment[Resources.shellVariable];
|
|
106
|
-
const files = preferred
|
|
109
|
+
const files = Object.isUndefined(preferred) ? listed : [preferred, ...listed];
|
|
107
110
|
const args = [Resources.loginArgument];
|
|
108
111
|
const shells = [];
|
|
109
112
|
for (const file of files) {
|
|
@@ -129,15 +132,15 @@ export class ShellLocator {
|
|
|
129
132
|
const architecture = Resources.developerArchitectures.get(this.architecture) ?? this.architecture;
|
|
130
133
|
const id = Resources.developerIdPrefix + installation.instanceId;
|
|
131
134
|
const shells = [];
|
|
132
|
-
if (commandPrompt
|
|
135
|
+
if (!Object.isUndefined(commandPrompt) && await this.fileSystem.isFileAsync(script))
|
|
133
136
|
shells.push(new Shell(id + Resources.developerCommandSuffix, Resources.formatDeveloperCommandPromptName(installation.name), TerminalShellKind.CommandPrompt, commandPrompt.file, [Resources.keepOpenArgument, script, Resources.noStartFolderArgument, ...Resources.formatDeveloperArchitectureArguments(architecture)], false));
|
|
134
|
-
if (powerShell
|
|
137
|
+
if (!Object.isUndefined(powerShell) && await this.fileSystem.isFileAsync(module))
|
|
135
138
|
shells.push(new Shell(id + Resources.developerPowerShellSuffix, Resources.formatDeveloperPowerShellName(installation.name), TerminalShellKind.PowerShell, powerShell.file, [], false, Resources.formatDeveloperPowerShellCommand(module, installation.path, architecture)));
|
|
136
139
|
return shells;
|
|
137
140
|
}
|
|
138
141
|
async locateWslShellsAsync() {
|
|
139
142
|
const wsl = this.wsl;
|
|
140
|
-
if (wsl
|
|
143
|
+
if (Object.isNull(wsl))
|
|
141
144
|
return [];
|
|
142
145
|
this.distributions ??= wsl.reader.readAsync().catch((error) => {
|
|
143
146
|
this.distributions = null;
|
|
@@ -172,6 +175,6 @@ export class ShellLocator {
|
|
|
172
175
|
return folders;
|
|
173
176
|
}
|
|
174
177
|
static joinIfSet(folder, names) {
|
|
175
|
-
return folder
|
|
178
|
+
return Object.isUndefined(folder) || folder.length === 0 ? [] : [path.win32.join(folder, ...names)];
|
|
176
179
|
}
|
|
177
180
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { ShellLine } from "../models/shell-line.js";
|
|
9
10
|
import { Resources } from "../resources.js";
|
|
10
11
|
export class ShellWords {
|
|
@@ -36,7 +37,7 @@ export class ShellWords {
|
|
|
36
37
|
}
|
|
37
38
|
if (character === escape && index + 1 < text.length) {
|
|
38
39
|
const next = text.charAt(index + 1);
|
|
39
|
-
if (quote
|
|
40
|
+
if (Object.isNull(quote) || isPowerShell || Resources.posixQuotedEscapes.includes(next)) {
|
|
40
41
|
value += next;
|
|
41
42
|
index++;
|
|
42
43
|
}
|
|
@@ -70,7 +71,7 @@ export class ShellWords {
|
|
|
70
71
|
static write(value, quote, isPowerShell, closesQuote, escapesWildcards, keepsHome) {
|
|
71
72
|
const literal = isPowerShell && escapesWildcards ? value.replace(Resources.powerShellWildcards, Resources.shellWordsPowerShellEscapeReplacement) : value;
|
|
72
73
|
const quoted = quote ?? (isPowerShell && (literal !== value || Resources.powerShellSpecial.test(value)) ? Resources.singleQuote : null);
|
|
73
|
-
if (quoted
|
|
74
|
+
if (Object.isNull(quoted))
|
|
74
75
|
return isPowerShell ? literal : `${!keepsHome && value.startsWith(Resources.homeWord) ? Resources.posixEscape : ""}${value.replace(Resources.posixSpecial, Resources.shellWordsPosixEscapeReplacement)}`;
|
|
75
76
|
const body = quoted === Resources.singleQuote
|
|
76
77
|
? literal.replaceAll(Resources.singleQuote, isPowerShell ? Resources.shellWordsPowerShellQuotedSingleQuote : Resources.shellWordsPosixQuotedSingleQuote)
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { SystemRequirement } from "../enums/system-requirement.js";
|
|
9
10
|
import { SystemShortfall } from "../models/system-shortfall.js";
|
|
10
11
|
import { Resources } from "../resources.js";
|
|
@@ -12,35 +13,34 @@ export class SystemRequirements {
|
|
|
12
13
|
static findShortfall(platform, osRelease, report) {
|
|
13
14
|
if (platform === Resources.windowsPlatform) {
|
|
14
15
|
const build = SystemRequirements.readWindowsBuild(osRelease);
|
|
15
|
-
if (build
|
|
16
|
+
if (Object.isNull(build))
|
|
16
17
|
return new SystemShortfall(SystemRequirement.WindowsBuild, osRelease);
|
|
17
18
|
return build < Resources.minimumWindowsBuild ? new SystemShortfall(SystemRequirement.WindowsBuild, String(build)) : null;
|
|
18
19
|
}
|
|
19
20
|
if (platform === Resources.linuxPlatform) {
|
|
20
21
|
const version = SystemRequirements.readGlibcVersion(report);
|
|
21
|
-
return version
|
|
22
|
+
return !Object.isNull(version) && SystemRequirements.isBelowGlibcMinimum(version) ? new SystemShortfall(SystemRequirement.Glibc, version) : null;
|
|
22
23
|
}
|
|
23
24
|
return null;
|
|
24
25
|
}
|
|
25
26
|
static readWindowsBuild(osRelease) {
|
|
26
27
|
const match = Resources.systemRequirementsWindowsBuild.exec(osRelease);
|
|
27
|
-
return match
|
|
28
|
+
return Object.isNull(match) ? null : Number(match[1]);
|
|
28
29
|
}
|
|
29
30
|
static readGlibcVersion(report) {
|
|
30
|
-
if (
|
|
31
|
+
if (!Object.isObject(report) || !(Resources.reportHeaderField in report))
|
|
31
32
|
return null;
|
|
32
33
|
const header = report[Resources.reportHeaderField];
|
|
33
|
-
if (
|
|
34
|
+
if (!Object.isObject(header) || !(Resources.reportGlibcVersionField in header))
|
|
34
35
|
return null;
|
|
35
36
|
const version = header[Resources.reportGlibcVersionField];
|
|
36
|
-
return
|
|
37
|
+
return Object.isString(version) ? version : null;
|
|
37
38
|
}
|
|
38
39
|
static isBelowGlibcMinimum(version) {
|
|
39
40
|
const match = Resources.systemRequirementsGlibcVersion.exec(version);
|
|
40
|
-
if (match
|
|
41
|
+
if (Object.isNull(match))
|
|
41
42
|
return false;
|
|
42
|
-
const [minimumMajor, minimumMinor] = Resources.minimumGlibcVersion;
|
|
43
43
|
const major = Number(match[1]);
|
|
44
|
-
return major <
|
|
44
|
+
return major < Resources.minimumGlibcMajor || (major === Resources.minimumGlibcMajor && Number(match[2]) < Resources.minimumGlibcMinor);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
export class TerminalAudience {
|
|
9
10
|
windows = new Map();
|
|
10
11
|
apps = new Set();
|
|
@@ -12,17 +13,17 @@ export class TerminalAudience {
|
|
|
12
13
|
hiddenWindows = new Map();
|
|
13
14
|
see(client) {
|
|
14
15
|
let windows = this.windows.get(client.connection);
|
|
15
|
-
if (windows
|
|
16
|
+
if (Object.isUndefined(windows)) {
|
|
16
17
|
windows = new Set();
|
|
17
18
|
this.windows.set(client.connection, windows);
|
|
18
19
|
if (client.isApp)
|
|
19
20
|
this.apps.add(client.connection);
|
|
20
21
|
}
|
|
21
|
-
if (client.window
|
|
22
|
+
if (!Object.isNull(client.window))
|
|
22
23
|
windows.add(client.window);
|
|
23
24
|
}
|
|
24
25
|
forget(connection, window) {
|
|
25
|
-
if (window
|
|
26
|
+
if (!Object.isNull(window)) {
|
|
26
27
|
this.windows.get(connection)?.delete(window);
|
|
27
28
|
this.shownOwners.get(connection)?.delete(window);
|
|
28
29
|
this.hiddenWindows.get(connection)?.delete(window);
|
|
@@ -34,10 +35,10 @@ export class TerminalAudience {
|
|
|
34
35
|
return this.apps.delete(connection);
|
|
35
36
|
}
|
|
36
37
|
show(client, owner, isHidden) {
|
|
37
|
-
if (client.window
|
|
38
|
+
if (Object.isNull(client.window))
|
|
38
39
|
return;
|
|
39
40
|
let hidden = this.hiddenWindows.get(client.connection);
|
|
40
|
-
if (hidden
|
|
41
|
+
if (Object.isUndefined(hidden)) {
|
|
41
42
|
hidden = new Set();
|
|
42
43
|
this.hiddenWindows.set(client.connection, hidden);
|
|
43
44
|
}
|
|
@@ -46,11 +47,11 @@ export class TerminalAudience {
|
|
|
46
47
|
else
|
|
47
48
|
hidden.delete(client.window);
|
|
48
49
|
let owners = this.shownOwners.get(client.connection);
|
|
49
|
-
if (owners
|
|
50
|
+
if (Object.isUndefined(owners)) {
|
|
50
51
|
owners = new Map();
|
|
51
52
|
this.shownOwners.set(client.connection, owners);
|
|
52
53
|
}
|
|
53
|
-
if (owner
|
|
54
|
+
if (Object.isNull(owner))
|
|
54
55
|
owners.delete(client.window);
|
|
55
56
|
else
|
|
56
57
|
owners.set(client.window, owner);
|
|
@@ -62,10 +63,10 @@ export class TerminalAudience {
|
|
|
62
63
|
return false;
|
|
63
64
|
}
|
|
64
65
|
isOpen(client) {
|
|
65
|
-
return client.window
|
|
66
|
+
return Object.isNull(client.window) ? this.windows.has(client.connection) : this.windows.get(client.connection)?.has(client.window) === true;
|
|
66
67
|
}
|
|
67
68
|
isHidden(client) {
|
|
68
|
-
return client.window
|
|
69
|
+
return !Object.isNull(client.window) && this.hiddenWindows.get(client.connection)?.has(client.window) === true;
|
|
69
70
|
}
|
|
70
71
|
isApp(connection) {
|
|
71
72
|
return this.apps.has(connection);
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import path from "node:path";
|
|
9
10
|
import { TerminalHistoryPaths } from "../models/terminal-history-paths.js";
|
|
10
11
|
import { Resources } from "../resources.js";
|
|
@@ -37,7 +38,7 @@ export class TerminalHistoryFolder {
|
|
|
37
38
|
this.folder = null;
|
|
38
39
|
throw error;
|
|
39
40
|
}
|
|
40
|
-
if (folder
|
|
41
|
+
if (Object.isNull(folder)) {
|
|
41
42
|
this.folder = null;
|
|
42
43
|
return null;
|
|
43
44
|
}
|
|
@@ -46,7 +47,7 @@ export class TerminalHistoryFolder {
|
|
|
46
47
|
async removeAsync() {
|
|
47
48
|
const creating = this.folder;
|
|
48
49
|
this.folder = null;
|
|
49
|
-
if (creating
|
|
50
|
+
if (Object.isNull(creating))
|
|
50
51
|
return;
|
|
51
52
|
let folder;
|
|
52
53
|
try {
|
|
@@ -56,7 +57,7 @@ export class TerminalHistoryFolder {
|
|
|
56
57
|
this.log.write(Resources.formatTerminalHistoryCreateFailed(FailureText.read(error)));
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
59
|
-
if (folder
|
|
60
|
+
if (!Object.isNull(folder))
|
|
60
61
|
await this.removeFolderAsync(folder);
|
|
61
62
|
}
|
|
62
63
|
async createAsync() {
|
|
@@ -75,7 +76,7 @@ export class TerminalHistoryFolder {
|
|
|
75
76
|
async removeLeftoversAsync() {
|
|
76
77
|
for (const name of await this.reader.readFolderNamesAsync(this.temporaryFolder)) {
|
|
77
78
|
const pid = TerminalHistoryFolder.toPid(name);
|
|
78
|
-
if (pid
|
|
79
|
+
if (!Object.isNull(pid) && pid !== this.pid && !this.signaller.isRunning(pid))
|
|
79
80
|
await this.removeFolderAsync(path.join(this.temporaryFolder, name));
|
|
80
81
|
}
|
|
81
82
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { open, rm } from "node:fs/promises";
|
|
9
10
|
import { JsonException } from "@noldova/context.json";
|
|
10
11
|
import { TerminalLine } from "@noldova/terminal.protocol";
|
|
@@ -84,7 +85,7 @@ export class TerminalHistorySegment {
|
|
|
84
85
|
return lines;
|
|
85
86
|
}
|
|
86
87
|
async closeAsync() {
|
|
87
|
-
if (this.handle
|
|
88
|
+
if (!Object.isNull(this.handle))
|
|
88
89
|
await this.handle.close();
|
|
89
90
|
this.handle = null;
|
|
90
91
|
}
|