@noldova/terminal 0.0.16 → 0.0.18
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/module.json +2 -2
- package/package.json +9 -9
- package/src/enums/mark-kind.js +1 -0
- package/src/enums/shell-family.js +1 -0
- package/src/exceptions/command-exited.exception.js +2 -1
- package/src/models/hosted-terminal.js +20 -9
- package/src/models/one-shot-launch.js +7 -4
- package/src/models/right-prompt-span.js +14 -0
- package/src/models/terminal-prompt.js +5 -5
- package/src/models/typed-line.js +2 -2
- package/src/resources.js +271 -13
- package/src/runtime-part.js +1 -1
- package/src/services/agent-terminal.js +7 -5
- package/src/services/command-describer.js +35 -33
- package/src/services/command-runner.js +5 -3
- package/src/services/command-tracker.js +17 -2
- package/src/services/completion-source.js +62 -30
- package/src/services/escape-sequence-tracker.js +1 -1
- package/src/services/escape-stripper.js +10 -7
- package/src/services/file-system.reader.js +2 -1
- package/src/services/fish-shell-adapter.js +90 -0
- package/src/services/folder-change-line.js +2 -0
- package/src/services/line-process.js +3 -2
- package/src/services/log-file.js +4 -3
- package/src/services/mac-environment.js +5 -2
- package/src/services/mark-scanner.js +5 -5
- package/src/services/output-batcher.js +1 -1
- package/src/services/output-log.js +2 -1
- package/src/services/posix-shell-adapter.js +3 -2
- package/src/services/printed-text.js +3 -2
- package/src/services/pseudo-terminal.js +1 -1
- package/src/services/registry-export.js +5 -5
- package/src/services/resize-wakeup.js +1 -1
- package/src/services/saved-terminals.js +2 -1
- package/src/services/shell-adapters.js +3 -1
- package/src/services/shell-command.js +7 -2
- package/src/services/shell-integration.js +32 -14
- package/src/services/shell-locator.js +27 -13
- package/src/services/shell-words.js +5 -5
- package/src/services/terminal-history-segment.js +1 -1
- package/src/services/terminal-host.js +166 -45
- package/src/services/terminal-line-reader.js +9 -3
- package/src/services/terminal-mirror.js +12 -11
- package/src/services/terminal-session.js +24 -8
- package/src/services/wsl-distribution.reader.js +5 -2
- package/src/services/wsl-shell-adapter.js +6 -2
- package/src/tools/models/output-excerpt.js +2 -1
- package/src/tools/models/terminal-output-report.js +4 -2
- package/src/tools/models/tool-call-context.js +2 -1
- package/src/tools/services/terminal-access-policy.js +4 -2
- package/src/tools/services/terminal-text-escaper.js +4 -2
- package/src/tools/services/terminal-write-tool.js +5 -3
package/module.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "terminal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"displayName": "Terminal",
|
|
5
5
|
"description": "Runs shells in terminal panes, and lets AI agents run commands in them through permission requests.",
|
|
6
6
|
"parts": ["runtime", "window"],
|
|
7
7
|
"pseudoTerminals": true,
|
|
8
8
|
"dependencies": {},
|
|
9
|
-
"noldovaDesktop": ">=0.0.
|
|
9
|
+
"noldovaDesktop": ">=0.0.36 <0.1.0",
|
|
10
10
|
"contributes": {
|
|
11
11
|
"methods": [
|
|
12
12
|
"terminal.shells", "terminal.open", "terminal.close", "terminal.restart", "terminal.sessions", "terminal.attach", "terminal.input", "terminal.resize",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/terminal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "The terminal module for apps on Noldova Desktop: terminal panes over real shells, and agent tools that run commands through permission requests.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,18 +37,18 @@
|
|
|
37
37
|
"registry": "https://registry.npmjs.org/"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@noldova/terminal.protocol": "0.0.
|
|
41
|
-
"@noldova/terminal.window": "0.0.
|
|
40
|
+
"@noldova/terminal.protocol": "0.0.18",
|
|
41
|
+
"@noldova/terminal.window": "0.0.18",
|
|
42
42
|
"@xterm/addon-serialize": "0.14.0",
|
|
43
43
|
"@xterm/headless": "6.0.0",
|
|
44
44
|
"node-pty": "1.2.0-beta.15"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@noldova/desktop.protocol": ">=0.0.
|
|
48
|
-
"@noldova/desktop.runtime": ">=0.0.
|
|
49
|
-
"@noldova/context.core": ">=0.0.
|
|
50
|
-
"@noldova/context.exceptions": ">=0.0.
|
|
51
|
-
"@noldova/context.json": ">=0.0.
|
|
47
|
+
"@noldova/desktop.protocol": ">=0.0.36 <0.1.0",
|
|
48
|
+
"@noldova/desktop.runtime": ">=0.0.36 <0.1.0",
|
|
49
|
+
"@noldova/context.core": ">=0.0.20 <0.1.0",
|
|
50
|
+
"@noldova/context.exceptions": ">=0.0.20 <0.1.0",
|
|
51
|
+
"@noldova/context.json": ">=0.0.20 <0.1.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "1a1346cfe20c4335e58fccc58eb2c7b5889fcc91"
|
|
54
54
|
}
|
package/src/enums/mark-kind.js
CHANGED
|
@@ -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
|
import { CommandFailedException } from "./command-failed.exception.js";
|
|
10
11
|
export class CommandExitedException extends CommandFailedException {
|
|
@@ -12,7 +13,7 @@ export class CommandExitedException extends CommandFailedException {
|
|
|
12
13
|
exitCode;
|
|
13
14
|
signal;
|
|
14
15
|
errorText;
|
|
15
|
-
constructor(command, exit, errorText =
|
|
16
|
+
constructor(command, exit, errorText = String.empty) {
|
|
16
17
|
const text = errorText.replace(Resources.whitespaceRuns, " ").trim();
|
|
17
18
|
super(Resources.formatCommandExited(command, exit.code, exit.signal, text));
|
|
18
19
|
this.command = command;
|
|
@@ -48,7 +48,7 @@ export class HostedTerminal {
|
|
|
48
48
|
isRunStarting = false;
|
|
49
49
|
waitingRun = null;
|
|
50
50
|
typedEnds = 1;
|
|
51
|
-
paste =
|
|
51
|
+
paste = String.empty;
|
|
52
52
|
constructor(session, shell, folder, ownerSessionId, isPanelTerminal, owner, connection, environment = null) {
|
|
53
53
|
this.session = session;
|
|
54
54
|
this.shell = shell;
|
|
@@ -84,18 +84,29 @@ export class HostedTerminal {
|
|
|
84
84
|
get hasUnreadInput() {
|
|
85
85
|
const commands = this.session.commands;
|
|
86
86
|
const prompt = commands.promptIdentity;
|
|
87
|
-
return this.hasRecentInput &&
|
|
88
|
-
|
|
87
|
+
return this.hasRecentInput &&
|
|
88
|
+
(Object.isNull(this.inputPrompt) ||
|
|
89
|
+
Object.isNull(prompt) ||
|
|
90
|
+
prompt === this.inputPrompt ||
|
|
91
|
+
commands.commandMarks === this.inputCommandMarks);
|
|
89
92
|
}
|
|
90
93
|
get isFree() {
|
|
91
|
-
return Object.isNull(this.ownerSessionId) &&
|
|
92
|
-
|
|
94
|
+
return Object.isNull(this.ownerSessionId) &&
|
|
95
|
+
!this.session.hasExited &&
|
|
96
|
+
!this.isRestarting &&
|
|
97
|
+
Object.isNull(this.pendingCommand) &&
|
|
98
|
+
this.session.commands.hasMarks &&
|
|
99
|
+
!this.hasUnreadInput &&
|
|
100
|
+
this.session.readPromptLine() === String.empty;
|
|
93
101
|
}
|
|
94
102
|
get isDrawingPrompt() {
|
|
95
|
-
return Object.isNull(this.ownerSessionId) &&
|
|
96
|
-
|
|
103
|
+
return Object.isNull(this.ownerSessionId) &&
|
|
104
|
+
!this.session.hasExited &&
|
|
105
|
+
!this.isRestarting &&
|
|
106
|
+
Object.isNull(this.pendingCommand) &&
|
|
107
|
+
this.session.commands.isDrawingPrompt;
|
|
97
108
|
}
|
|
98
|
-
recordInput(isReply = false, data =
|
|
109
|
+
recordInput(isReply = false, data = String.empty, isAgent = false) {
|
|
99
110
|
this.inputReceivedLength = this.session.receivedLength;
|
|
100
111
|
if (isReply)
|
|
101
112
|
return;
|
|
@@ -141,7 +152,7 @@ export class HostedTerminal {
|
|
|
141
152
|
this.inputCommandMarks = this.session.commands.commandMarks;
|
|
142
153
|
}
|
|
143
154
|
static hasTextAfterLineBreak(data) {
|
|
144
|
-
return data.replace(Resources.bracketedPastes,
|
|
155
|
+
return data.replace(Resources.bracketedPastes, String.empty).split(Resources.lineBreaks).slice(1).some(t => t !== String.empty);
|
|
145
156
|
}
|
|
146
157
|
forgetRun(runId, start) {
|
|
147
158
|
void start.then(t => t.dispose(), () => undefined);
|
|
@@ -25,9 +25,11 @@ export class OneShotLaunch {
|
|
|
25
25
|
return Resources.formatOneShotLaunchCommandLine(OneShotLaunch.quote(this.file), line);
|
|
26
26
|
}
|
|
27
27
|
static quote(argument) {
|
|
28
|
-
const isQuoted = argument ===
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const isQuoted = argument === String.empty ||
|
|
29
|
+
(Resources.oneShotLaunchArgumentBreak.test(argument) &&
|
|
30
|
+
argument.length > 1 &&
|
|
31
|
+
!(argument.startsWith(Resources.doubleQuote) && argument.endsWith(Resources.doubleQuote)));
|
|
32
|
+
let quoted = isQuoted ? Resources.doubleQuote : String.empty;
|
|
31
33
|
let backslashes = 0;
|
|
32
34
|
for (const unit of argument) {
|
|
33
35
|
if (unit === Resources.backslash)
|
|
@@ -37,7 +39,8 @@ export class OneShotLaunch {
|
|
|
37
39
|
backslashes = 0;
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
|
-
return isQuoted
|
|
42
|
+
return isQuoted
|
|
43
|
+
? `${quoted}${Resources.backslash.repeat(backslashes * 2)}${Resources.doubleQuote}`
|
|
41
44
|
: quoted + Resources.backslash.repeat(backslashes);
|
|
42
45
|
}
|
|
43
46
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class RightPromptSpan {
|
|
9
|
+
start;
|
|
10
|
+
end = null;
|
|
11
|
+
constructor(start) {
|
|
12
|
+
this.start = start;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -19,10 +19,10 @@ export class TerminalPrompt {
|
|
|
19
19
|
this.inputCount = inputCount;
|
|
20
20
|
}
|
|
21
21
|
equals(other) {
|
|
22
|
-
return other.isIdle === this.isIdle
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
return other.isIdle === this.isIdle &&
|
|
23
|
+
other.cwd === this.cwd &&
|
|
24
|
+
other.promptOffset === this.promptOffset &&
|
|
25
|
+
other.isAwaitingSecret === this.isAwaitingSecret &&
|
|
26
|
+
other.inputCount === this.inputCount;
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/models/typed-line.js
CHANGED
|
@@ -9,7 +9,7 @@ import "@noldova/context.core";
|
|
|
9
9
|
import { Resources } from "../resources.js";
|
|
10
10
|
export class TypedLine {
|
|
11
11
|
echo;
|
|
12
|
-
tail =
|
|
12
|
+
tail = String.empty;
|
|
13
13
|
isEchoed = false;
|
|
14
14
|
startOffset;
|
|
15
15
|
command = null;
|
|
@@ -36,6 +36,6 @@ export class TypedLine {
|
|
|
36
36
|
this.endOffset = offset;
|
|
37
37
|
}
|
|
38
38
|
static compact(text) {
|
|
39
|
-
return text.replace(Resources.whiteSpace,
|
|
39
|
+
return text.replace(Resources.whiteSpace, String.empty);
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/resources.js
CHANGED
|
@@ -25,6 +25,7 @@ export class Resources {
|
|
|
25
25
|
static runInterruptWaitMilliseconds = 2_000;
|
|
26
26
|
static promptDrawWaitMilliseconds = 10_000;
|
|
27
27
|
static foregroundPollMilliseconds = 50;
|
|
28
|
+
static foregroundWorkPollMilliseconds = 1_000;
|
|
28
29
|
static cursorAnswerMilliseconds = 500;
|
|
29
30
|
static cursorRequestFrameMilliseconds = 100;
|
|
30
31
|
static maximumKeptRuns = 100;
|
|
@@ -57,7 +58,7 @@ export class Resources {
|
|
|
57
58
|
static maximumMarkLength = 20_480;
|
|
58
59
|
static markKindLetters = new Map([
|
|
59
60
|
["A", MarkKind.PromptStart], ["B", MarkKind.PromptEnd], ["C", MarkKind.OutputStart], ["D", MarkKind.CommandEnd], ["P", MarkKind.Property],
|
|
60
|
-
["R", MarkKind.RightPrompt], ["F", MarkKind.ContinuationEnd], ["O", MarkKind.Options], ["L", MarkKind.Loaded]
|
|
61
|
+
["R", MarkKind.RightPrompt], ["E", MarkKind.RightPromptEnd], ["F", MarkKind.ContinuationEnd], ["O", MarkKind.Options], ["L", MarkKind.Loaded]
|
|
61
62
|
]);
|
|
62
63
|
static cwdProperty = "Cwd=";
|
|
63
64
|
static pathProperty = "Path=";
|
|
@@ -193,6 +194,13 @@ export class Resources {
|
|
|
193
194
|
static posixQuotedEscapes = "\"\\$`";
|
|
194
195
|
static posixSpecial = /[\s"'\\$`|&;<>()*?[\]{}!#]/gu;
|
|
195
196
|
static posixQuotedSpecial = /["\\$`]/gu;
|
|
197
|
+
static fishCommandBreaks = "|;&(";
|
|
198
|
+
static fishCommandKeywords = ["and", "or", "not", "if", "else", "while", "begin", "command", "builtin", "exec", "time"];
|
|
199
|
+
static fishSingleQuotedEscapes = "'\\";
|
|
200
|
+
static fishDoubleQuotedEscapes = "\"\\$";
|
|
201
|
+
static fishSpecial = /[\s"'\\$|&;<>()*?{}#]/gu;
|
|
202
|
+
static fishSingleQuotedSpecial = /['\\]/gu;
|
|
203
|
+
static fishDoubleQuotedSpecial = /["\\$]/gu;
|
|
196
204
|
static powerShellSpecial = /[\s'"`$|&;(){}@,<>#]/u;
|
|
197
205
|
static powerShellQuotedSpecial = /["`$]/gu;
|
|
198
206
|
static powerShellWildcards = /[[\]*?`]/gu;
|
|
@@ -372,6 +380,7 @@ export class Resources {
|
|
|
372
380
|
static powerShellFolderKeys = "\u001b[24~d";
|
|
373
381
|
static zshFolderKeys = "\u001b[23;7~";
|
|
374
382
|
static folderEncoding = "hex";
|
|
383
|
+
static fishOptionsKeys = "\u001b[24;7~";
|
|
375
384
|
static optionsMilliseconds = 500;
|
|
376
385
|
static firstOptionsMilliseconds = 3_500;
|
|
377
386
|
static powerShellLookupMilliseconds = 10_000;
|
|
@@ -395,7 +404,12 @@ export class Resources {
|
|
|
395
404
|
static whatisNamesPerRun = 6;
|
|
396
405
|
static describeRetryMilliseconds = 300_000;
|
|
397
406
|
static zshNoStartupArgument = "-f";
|
|
407
|
+
static describeShellProgram = "/bin/sh";
|
|
398
408
|
static bashStartupVariable = "BASH_ENV";
|
|
409
|
+
static formatRunningCommand(command, terminal) {
|
|
410
|
+
const line = (command ?? String.empty).split(Resources.lineBreaks).find(t => t.trim() !== String.empty)?.trim();
|
|
411
|
+
return Object.isUndefined(line) ? `A command is running in ${terminal}.` : `${line} is running in ${terminal}.`;
|
|
412
|
+
}
|
|
399
413
|
static formatDescribeFailed(count, message) {
|
|
400
414
|
return `The lookup of ${count} ${count === 1 ? "command's description" : "commands' descriptions"} gave up, so they show none: ${message}`;
|
|
401
415
|
}
|
|
@@ -485,7 +499,7 @@ for ($index = 0; $index -lt $names.Count; $index++) {
|
|
|
485
499
|
static aclRemovalArguments = ["-N"];
|
|
486
500
|
static folderAccessMilliseconds = 10_000;
|
|
487
501
|
static shellsFile = "/etc/shells";
|
|
488
|
-
static
|
|
502
|
+
static systemShellFile = "/bin/sh";
|
|
489
503
|
static unixShellKinds = new Map([
|
|
490
504
|
["bash", TerminalShellKind.Bash], ["zsh", TerminalShellKind.Zsh], ["fish", TerminalShellKind.Fish], ["pwsh", TerminalShellKind.PowerShell]
|
|
491
505
|
]);
|
|
@@ -532,7 +546,8 @@ for ($index = 0; $index -lt $names.Count; $index++) {
|
|
|
532
546
|
" $key.Close()",
|
|
533
547
|
"}",
|
|
534
548
|
"[Console]::Out.WriteLine('End')"
|
|
535
|
-
]
|
|
549
|
+
]
|
|
550
|
+
.join("\n");
|
|
536
551
|
static base64Pattern = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u;
|
|
537
552
|
static vswherePath = ["Microsoft Visual Studio", "Installer", "vswhere.exe"];
|
|
538
553
|
static vswhereArguments = ["-products", "*", "-prerelease", "-utf8", "-format", "json"];
|
|
@@ -633,6 +648,7 @@ for ($index = 0; $index -lt $names.Count; $index++) {
|
|
|
633
648
|
static timeoutFieldDescription = "Ends the command after this many milliseconds; 0, the default, means never.";
|
|
634
649
|
static waitFieldDescription = `How long to wait for new output when there is none yet, up to ${Resources.maximumCallMilliseconds} milliseconds; a longer wait is clamped, and 0 returns at once.`;
|
|
635
650
|
static maxCharsFieldDescription = `The most characters of output to return, up to ${Resources.maximumToolOutputCharacters}; a larger number is clamped. Longer output keeps its start and end and says how much it left out.`;
|
|
651
|
+
static shellIdFieldDescription = "The terminal's shell id, such as bash, zsh, pwsh or cmd, as terminal_open and terminal_list report it.";
|
|
636
652
|
static shellFieldDescription = "The shell's id, such as bash, zsh, pwsh or cmd. The default shell when absent.";
|
|
637
653
|
static statusFieldDescription = "The command's status, or null when the output isn't from a command this session ran.";
|
|
638
654
|
static methodFieldDescription = "InShell when the command ran at the terminal's prompt, OneShot when it ran in a new shell process of its own, or null when the output isn't from a command.";
|
|
@@ -670,6 +686,7 @@ if [ -n "\${NOLDOVA_TERMINAL_NOTE-}" ]; then printf '%s' "$NOLDOVA_TERMINAL_NOTE
|
|
|
670
686
|
unset NOLDOVA_TERMINAL_NONCE_FILE NOLDOVA_TERMINAL_LOGIN NOLDOVA_TERMINAL_NOTE
|
|
671
687
|
exec "$s" -l`;
|
|
672
688
|
static zshExecutable = "zsh";
|
|
689
|
+
static fishExecutable = "fish";
|
|
673
690
|
static pwshExecutable = "pwsh";
|
|
674
691
|
static windowsPowerShellExecutable = "powershell";
|
|
675
692
|
static nonceFileVariable = "NOLDOVA_TERMINAL_NONCE_FILE";
|
|
@@ -683,6 +700,12 @@ exec "$s" -l`;
|
|
|
683
700
|
static dotnetSharedMemoryFolder = "shm";
|
|
684
701
|
static dotnetSharedMemoryFolderMode = 0o700;
|
|
685
702
|
static bashScriptFile = "noldova.bash";
|
|
703
|
+
static fishScriptFolder = ["fish", "vendor_conf.d"];
|
|
704
|
+
static fishScriptFile = "noldova.fish";
|
|
705
|
+
static dataFoldersVariable = "XDG_DATA_DIRS";
|
|
706
|
+
static userDataFoldersVariable = "NOLDOVA_TERMINAL_DATA_DIRS";
|
|
707
|
+
static defaultDataFolders = "/usr/local/share:/usr/share";
|
|
708
|
+
static integrationFolderMode = 0o700;
|
|
686
709
|
static nonceFilePrefix = "nonce-";
|
|
687
710
|
static nonceFileNameBytes = 16;
|
|
688
711
|
static zshEnvironmentFile = ".zshenv";
|
|
@@ -804,7 +827,7 @@ exit 0
|
|
|
804
827
|
}
|
|
805
828
|
static formatCommandExited(name, exitCode, signal, errorText) {
|
|
806
829
|
const exited = `${name} exited with ${String(exitCode ?? signal)}`;
|
|
807
|
-
return errorText ===
|
|
830
|
+
return errorText === String.empty ? `${exited}.` : `${exited}: ${errorText}`;
|
|
808
831
|
}
|
|
809
832
|
static formatEnvironmentKeyUnread(key) {
|
|
810
833
|
return `The key ${key} could not be read.`;
|
|
@@ -888,7 +911,7 @@ exit 0
|
|
|
888
911
|
return `The terminal module has no method ${method}.`;
|
|
889
912
|
}
|
|
890
913
|
static formatShellLeftRunning(sessionId, pid) {
|
|
891
|
-
return `The shell of terminal ${sessionId}${Object.isNull(pid) ?
|
|
914
|
+
return `The shell of terminal ${sessionId}${Object.isNull(pid) ? String.empty : `, process ${pid}`}, or a process it started, did not end in time.`;
|
|
892
915
|
}
|
|
893
916
|
static formatTerminalHistoryFile(sessionId, index) {
|
|
894
917
|
return `${sessionId}-${index}.jsonl`;
|
|
@@ -923,11 +946,14 @@ exit 0
|
|
|
923
946
|
static formatStartedCommandUnread(sessionId, message) {
|
|
924
947
|
return `The command started in terminal ${sessionId} could not be kept: ${message}`;
|
|
925
948
|
}
|
|
949
|
+
static formatForegroundUnread(sessionId, message) {
|
|
950
|
+
return `The program running in terminal ${sessionId} could not be read: ${message}`;
|
|
951
|
+
}
|
|
926
952
|
static formatResizeUnasked(sessionId) {
|
|
927
953
|
return `ConPTY sent terminal ${sessionId} no cursor request within ${String(Resources.cursorAnswerMilliseconds)} ms of a resize, so the keys typed meanwhile went on without one.`;
|
|
928
954
|
}
|
|
929
955
|
static formatLateShellLeftRunning(pid) {
|
|
930
|
-
return `A shell that started as the terminals ended${Object.isNull(pid) ?
|
|
956
|
+
return `A shell that started as the terminals ended${Object.isNull(pid) ? String.empty : `, process ${pid}`}, or a process it started, did not end in time.`;
|
|
931
957
|
}
|
|
932
958
|
static formatLogFailed(path, message) {
|
|
933
959
|
return `The log file ${path} stopped taking output: ${message}`;
|
|
@@ -951,7 +977,7 @@ exit 0
|
|
|
951
977
|
return start.map(t => (Resources.cmdQuotedArgumentPattern.test(t) ? `"${t}"` : t)).join(" ");
|
|
952
978
|
}
|
|
953
979
|
static formatCmdNoteLine(commandPrompt, name, start) {
|
|
954
|
-
return `/s /k ""${commandPrompt}" /d /v:on /s /c "echo(^!${name}^!"& set "${name}="${start ===
|
|
980
|
+
return `/s /k ""${commandPrompt}" /d /v:on /s /c "echo(^!${name}^!"& set "${name}="${start === String.empty ? String.empty : ` & ${start}`}"`;
|
|
955
981
|
}
|
|
956
982
|
static formatOneShotFailed(message) {
|
|
957
983
|
return `The command could not start: ${message}`;
|
|
@@ -1024,8 +1050,8 @@ exit 0
|
|
|
1024
1050
|
return `Terminal ${terminalId} waits for a password or another secret. Only the person types it; ask them to.`;
|
|
1025
1051
|
}
|
|
1026
1052
|
static formatLineInUse(terminalId) {
|
|
1027
|
-
return `Terminal ${terminalId} has text on its line, or the person just typed in it, so the keys would join their line and nothing was sent. `
|
|
1028
|
-
|
|
1053
|
+
return `Terminal ${terminalId} has text on its line, or the person just typed in it, so the keys would join their line and nothing was sent. ` +
|
|
1054
|
+
"Read it with terminal_read, and write once its line is empty.";
|
|
1029
1055
|
}
|
|
1030
1056
|
static formatCloseOutcomeUncertain(terminalId) {
|
|
1031
1057
|
return `The call ended while terminal ${terminalId} closed. terminal_list shows whether it's still open.`;
|
|
@@ -1034,7 +1060,7 @@ exit 0
|
|
|
1034
1060
|
return `\n[… characters left out: ${count}; the log file keeps the output up to ${Resources.maximumLogFileLength} characters, and says where it stops …]\n`;
|
|
1035
1061
|
}
|
|
1036
1062
|
static formatCommandSummary(status, exitCode, cwd, isAwaitingSecret) {
|
|
1037
|
-
const secret = isAwaitingSecret ? " The terminal waits for a password or another secret: only the person types it, so ask them to." :
|
|
1063
|
+
const secret = isAwaitingSecret ? " The terminal waits for a password or another secret: only the person types it, so ask them to." : String.empty;
|
|
1038
1064
|
return `\n\n[Status: ${status ?? "no command"}. Exit code: ${exitCode ?? "none"}. Working folder: ${cwd ?? "unknown"}.${secret}]`;
|
|
1039
1065
|
}
|
|
1040
1066
|
static formatTerminalOpened(terminalId, shellId, cwd) {
|
|
@@ -1749,8 +1775,9 @@ if [[ -n "\${__noldova_nonce_read-}" && -z "\${__noldova_nonce-}" ]]; then
|
|
|
1749
1775
|
__noldova_prompt_start="$(__noldova_mark A)"
|
|
1750
1776
|
__noldova_prompt_end="$(__noldova_mark B)"
|
|
1751
1777
|
__noldova_right_prompt="$(__noldova_mark R)"
|
|
1778
|
+
__noldova_right_prompt_end="$(__noldova_mark E)"
|
|
1752
1779
|
__noldova_continuation="$(__noldova_mark F)"
|
|
1753
|
-
builtin typeset +x __noldova_prompt_start __noldova_prompt_end __noldova_right_prompt __noldova_continuation
|
|
1780
|
+
builtin typeset +x __noldova_prompt_start __noldova_prompt_end __noldova_right_prompt __noldova_right_prompt_end __noldova_continuation
|
|
1754
1781
|
|
|
1755
1782
|
__noldova_capture() {
|
|
1756
1783
|
__noldova_status=$?
|
|
@@ -1842,10 +1869,11 @@ if [[ -n "\${__noldova_nonce_read-}" && -z "\${__noldova_nonce-}" ]]; then
|
|
|
1842
1869
|
PS2="$PS2%{$__noldova_continuation%}"
|
|
1843
1870
|
fi
|
|
1844
1871
|
builtin typeset -g +x PS2
|
|
1845
|
-
# A right prompt starts with its own mark, so the terminal knows where the person's line ends on the prompt's row
|
|
1872
|
+
# A right prompt starts with its own mark, so the terminal knows where the person's line ends on the prompt's row, and ends with
|
|
1873
|
+
# another, so its text isn't read as typed.
|
|
1846
1874
|
if [[ -n "$RPROMPT" ]]; then
|
|
1847
1875
|
if [[ "$RPROMPT" != *"$__noldova_right_prompt"* ]]; then
|
|
1848
|
-
RPROMPT="%{$__noldova_right_prompt%}$RPROMPT"
|
|
1876
|
+
RPROMPT="%{$__noldova_right_prompt%}$RPROMPT%{$__noldova_right_prompt_end%}"
|
|
1849
1877
|
fi
|
|
1850
1878
|
builtin typeset -g +x RPROMPT
|
|
1851
1879
|
fi
|
|
@@ -1976,6 +2004,236 @@ if [[ -n "$__noldova_had_zdotdir" || "$ZDOTDIR" != "$HOME" ]]; then
|
|
|
1976
2004
|
else
|
|
1977
2005
|
builtin unset ZDOTDIR
|
|
1978
2006
|
fi
|
|
2007
|
+
`;
|
|
2008
|
+
static shellIntegrationFishScript = `# The terminal module's shell integration for fish, which fish reads from vendor_conf.d in the folder the runtime put first in XDG_DATA_DIRS,
|
|
2009
|
+
# before the person's config.fish. It never changes the person's files.
|
|
2010
|
+
# XDG_DATA_DIRS goes back to what the shell started with first, so no program the shell starts finds this folder.
|
|
2011
|
+
if set -q NOLDOVA_TERMINAL_DATA_DIRS
|
|
2012
|
+
if test -n "$NOLDOVA_TERMINAL_DATA_DIRS"
|
|
2013
|
+
set -gx XDG_DATA_DIRS $NOLDOVA_TERMINAL_DATA_DIRS
|
|
2014
|
+
else
|
|
2015
|
+
set -e XDG_DATA_DIRS
|
|
2016
|
+
end
|
|
2017
|
+
set -e NOLDOVA_TERMINAL_DATA_DIRS
|
|
2018
|
+
end
|
|
2019
|
+
# The nonce's file is read, emptied and removed before the person's startup files run, so no program the shell starts later finds it.
|
|
2020
|
+
if set -q NOLDOVA_TERMINAL_NONCE_FILE
|
|
2021
|
+
read -l __noldova_nonce_read <$NOLDOVA_TERMINAL_NONCE_FILE
|
|
2022
|
+
printf '' >$NOLDOVA_TERMINAL_NONCE_FILE
|
|
2023
|
+
command rm -f -- $NOLDOVA_TERMINAL_NONCE_FILE
|
|
2024
|
+
set -e NOLDOVA_TERMINAL_NONCE_FILE
|
|
2025
|
+
if test -n "$__noldova_nonce_read"; and status is-interactive; and not set -q __noldova_nonce
|
|
2026
|
+
# Nothing that holds the nonce is exported.
|
|
2027
|
+
set -g __noldova_nonce $__noldova_nonce_read
|
|
2028
|
+
end
|
|
2029
|
+
end
|
|
2030
|
+
if set -q __noldova_nonce; and not set -q __noldova_loaded
|
|
2031
|
+
set -g __noldova_loaded 1
|
|
2032
|
+
# The loaded mark, before the person's startup files, tells the runtime the integration runs, so it waits for the first prompt however
|
|
2033
|
+
# long they take.
|
|
2034
|
+
printf '\\e]6973;L;%s\\a' $__noldova_nonce
|
|
2035
|
+
# The terminal's note, written as it is before the person's startup files, so it stays the terminal's first lines.
|
|
2036
|
+
if set -q NOLDOVA_TERMINAL_NOTE
|
|
2037
|
+
printf '%s' $NOLDOVA_TERMINAL_NOTE
|
|
2038
|
+
set -e NOLDOVA_TERMINAL_NOTE
|
|
2039
|
+
end
|
|
2040
|
+
set -g __noldova_in_command 0
|
|
2041
|
+
set -g __noldova_status 0
|
|
2042
|
+
set -g __noldova_path_sent
|
|
2043
|
+
set -g __noldova_names_sent
|
|
2044
|
+
set -g __noldova_builtins_sent 0
|
|
2045
|
+
set -g __noldova_options_sent 0
|
|
2046
|
+
|
|
2047
|
+
function __noldova_mark
|
|
2048
|
+
if set -q argv[2]
|
|
2049
|
+
printf '\\e]6973;%s;%s;%s\\a' $argv[1] $__noldova_nonce $argv[2]
|
|
2050
|
+
else
|
|
2051
|
+
printf '\\e]6973;%s;%s\\a' $argv[1] $__noldova_nonce
|
|
2052
|
+
end
|
|
2053
|
+
end
|
|
2054
|
+
|
|
2055
|
+
# The control characters a value escapes, other than the line feed, which goes first: the C0 controls but NUL, which a fish string never
|
|
2056
|
+
# holds, DEL, and the C1 controls, U+0080 to U+009F, at whose U+009C a mark would end.
|
|
2057
|
+
set -g __noldova_control_codes (seq 1 9) (seq 11 31) 127 (seq 128 159)
|
|
2058
|
+
set -g __noldova_controls
|
|
2059
|
+
for __noldova_code in $__noldova_control_codes
|
|
2060
|
+
if test $__noldova_code -lt 128
|
|
2061
|
+
set -a __noldova_controls (printf (printf '\\\\\\\\x%02x' $__noldova_code))
|
|
2062
|
+
else
|
|
2063
|
+
set -a __noldova_controls (printf (printf '\\\\\\\\u%04x' $__noldova_code))
|
|
2064
|
+
end
|
|
2065
|
+
end
|
|
2066
|
+
set -e __noldova_code
|
|
2067
|
+
|
|
2068
|
+
# A value escapes the controls, the separator and the backslash as \\xHH, which the runtime decodes; a value with none of them skips the
|
|
2069
|
+
# walk. It prints the escaped value, which a command substitution runs in the shell's own process.
|
|
2070
|
+
function __noldova_escape
|
|
2071
|
+
set -l value $argv[1]
|
|
2072
|
+
if not string match -qr '[\\x01-\\x1f;\\\\\\\\\\x7f-\\x9f]' -- $value
|
|
2073
|
+
printf '%s' $value
|
|
2074
|
+
return
|
|
2075
|
+
end
|
|
2076
|
+
set value (string replace -a -- '\\\\' '\\\\x5c' $value | string collect)
|
|
2077
|
+
set value (string replace -a -- \\n '\\\\x0a' $value | string collect)
|
|
2078
|
+
set value (string replace -a -- ';' '\\\\x3b' $value | string collect)
|
|
2079
|
+
for index in (seq (count $__noldova_controls))
|
|
2080
|
+
set value (string replace -a -- $__noldova_controls[$index] (printf '\\\\\\\\x%02x' $__noldova_control_codes[$index]) $value | string collect)
|
|
2081
|
+
end
|
|
2082
|
+
printf '%s' $value
|
|
2083
|
+
end
|
|
2084
|
+
|
|
2085
|
+
# A value longer than the limit, in UTF-16 code units, which fish counts as one for each character, sends the reset alone.
|
|
2086
|
+
function __noldova_capped_mark --argument-names value limit property reset
|
|
2087
|
+
if test (string length -- "$value") -gt $limit
|
|
2088
|
+
__noldova_mark P $reset
|
|
2089
|
+
return
|
|
2090
|
+
end
|
|
2091
|
+
set -l escaped (__noldova_escape $value)
|
|
2092
|
+
if test (string length -- (string replace -ra '[\\x{10000}-\\x{10ffff}]' '..' -- "$escaped")) -gt $limit
|
|
2093
|
+
__noldova_mark P $reset
|
|
2094
|
+
else
|
|
2095
|
+
__noldova_mark P "$property$escaped"
|
|
2096
|
+
end
|
|
2097
|
+
end
|
|
2098
|
+
|
|
2099
|
+
# Copies the person's function to the body the wrapper calls, unless the function already is the wrapper; a function that doesn't exist
|
|
2100
|
+
# gets an empty body.
|
|
2101
|
+
function __noldova_unwrapped --argument-names name body
|
|
2102
|
+
if functions -q $name; and string match -q "*$body*" -- (functions $name | string collect)
|
|
2103
|
+
return 1
|
|
2104
|
+
end
|
|
2105
|
+
functions -e $body
|
|
2106
|
+
if functions -q $name
|
|
2107
|
+
functions -c $name $body
|
|
2108
|
+
else
|
|
2109
|
+
function $body
|
|
2110
|
+
end
|
|
2111
|
+
end
|
|
2112
|
+
end
|
|
2113
|
+
|
|
2114
|
+
function __noldova_return
|
|
2115
|
+
return $argv[1]
|
|
2116
|
+
end
|
|
2117
|
+
|
|
2118
|
+
function __noldova_prompt --on-event fish_prompt
|
|
2119
|
+
set -l path (string join : -- $PATH)
|
|
2120
|
+
if test "$path" != "$__noldova_path_sent"
|
|
2121
|
+
set -g __noldova_path_sent $path
|
|
2122
|
+
__noldova_capped_mark "$path" ${Resources.maximumPathValueLength} ${Resources.pathProperty} ${Resources.pathReset}
|
|
2123
|
+
end
|
|
2124
|
+
if test $__noldova_builtins_sent = 0
|
|
2125
|
+
set -g __noldova_builtins_sent 1
|
|
2126
|
+
set -l builtins (string join ' ' -- (builtin -n))
|
|
2127
|
+
__noldova_capped_mark "$builtins" ${Resources.maximumNamesValueLength} ${Resources.builtinsProperty} ${Resources.builtinsReset}
|
|
2128
|
+
end
|
|
2129
|
+
# The person's functions, aliases among them, and abbreviations; fish lists no function starting with _.
|
|
2130
|
+
set -l names (string join ' ' -- (functions -n) (abbr --list))
|
|
2131
|
+
if test "$names" != "$__noldova_names_sent"
|
|
2132
|
+
set -g __noldova_names_sent $names
|
|
2133
|
+
__noldova_capped_mark "$names" ${Resources.maximumNamesValueLength} ${Resources.namesProperty} ${Resources.namesReset}
|
|
2134
|
+
end
|
|
2135
|
+
__noldova_bind
|
|
2136
|
+
set -l options 0
|
|
2137
|
+
if test (__noldova_bound_count) -eq 2
|
|
2138
|
+
set options ${Resources.optionsBound}
|
|
2139
|
+
end
|
|
2140
|
+
if test $options != $__noldova_options_sent
|
|
2141
|
+
set -g __noldova_options_sent $options
|
|
2142
|
+
__noldova_mark P "${Resources.optionsProperty}$options"
|
|
2143
|
+
end
|
|
2144
|
+
__noldova_mark P "${Resources.cwdProperty}"(__noldova_escape $PWD)
|
|
2145
|
+
if test $__noldova_in_command = 1
|
|
2146
|
+
set -g __noldova_in_command 0
|
|
2147
|
+
__noldova_mark D $__noldova_status
|
|
2148
|
+
end
|
|
2149
|
+
# The prompt's start mark comes first in the mode prompt, which fish draws before the left prompt, so the person's prompt keeps the last
|
|
2150
|
+
# command's status; the end mark comes after the left prompt, and a right prompt starts and ends with its own. Each is put back at the next
|
|
2151
|
+
# prompt when the person's files or a theme defined the function again.
|
|
2152
|
+
if __noldova_unwrapped fish_mode_prompt __noldova_mode_prompt
|
|
2153
|
+
function fish_mode_prompt
|
|
2154
|
+
__noldova_mark A
|
|
2155
|
+
__noldova_mode_prompt $argv
|
|
2156
|
+
end
|
|
2157
|
+
end
|
|
2158
|
+
if __noldova_unwrapped fish_prompt __noldova_left_prompt
|
|
2159
|
+
function fish_prompt
|
|
2160
|
+
__noldova_left_prompt $argv
|
|
2161
|
+
__noldova_mark B
|
|
2162
|
+
end
|
|
2163
|
+
end
|
|
2164
|
+
# A right prompt keeps the last command's status, though not each of a pipeline's, and ends with its own mark, so its text isn't read
|
|
2165
|
+
# as typed.
|
|
2166
|
+
if functions -q fish_right_prompt; and __noldova_unwrapped fish_right_prompt __noldova_right_prompt
|
|
2167
|
+
function fish_right_prompt
|
|
2168
|
+
set -l last $status
|
|
2169
|
+
__noldova_mark R
|
|
2170
|
+
__noldova_return $last
|
|
2171
|
+
__noldova_right_prompt $argv
|
|
2172
|
+
__noldova_mark E
|
|
2173
|
+
end
|
|
2174
|
+
end
|
|
2175
|
+
end
|
|
2176
|
+
|
|
2177
|
+
# The command's mark gives its first line as typed, at most 4,096 characters; an empty line runs no command.
|
|
2178
|
+
function __noldova_preexec --on-event fish_preexec
|
|
2179
|
+
set -l typed (string split -m1 \\n -- $argv[1])[1]
|
|
2180
|
+
if test -z (string trim -- "$typed")
|
|
2181
|
+
return
|
|
2182
|
+
end
|
|
2183
|
+
set -g __noldova_in_command 1
|
|
2184
|
+
__noldova_mark C "${Resources.commandProperty}"(__noldova_escape (string sub -l 4096 -- $typed))
|
|
2185
|
+
end
|
|
2186
|
+
|
|
2187
|
+
# The command's status goes out with its end mark at the next prompt, after the folder it left the shell in.
|
|
2188
|
+
function __noldova_postexec --on-event fish_postexec
|
|
2189
|
+
set -g __noldova_status $status
|
|
2190
|
+
end
|
|
2191
|
+
|
|
2192
|
+
# The hidden completion binding runs fish's own completion for the line up to the cursor and answers in an options mark with those that
|
|
2193
|
+
# start with -, which shows nothing and changes neither the line nor the history. A completion that gives none still sends the mark.
|
|
2194
|
+
function __noldova_list_options
|
|
2195
|
+
set -l mark (printf '\\e]6973;O;%s' $__noldova_nonce)
|
|
2196
|
+
set -l count 0
|
|
2197
|
+
set -l typed (commandline -cp | string collect)
|
|
2198
|
+
for line in (complete -C "$typed")
|
|
2199
|
+
set -l option (string split -m1 \\t -- $line)[1]
|
|
2200
|
+
string match -q -- '-*' $option; or continue
|
|
2201
|
+
test $count -lt ${ProtocolResources.maximumCompletionItems}; or break
|
|
2202
|
+
set -l field (__noldova_escape $option)
|
|
2203
|
+
test (math (string length -- "$mark") + (string length -- "$field")) -lt ${Resources.maximumPathValueLength}; or break
|
|
2204
|
+
set mark "$mark;$field"
|
|
2205
|
+
set count (math $count + 1)
|
|
2206
|
+
end
|
|
2207
|
+
printf '%s\\a' $mark
|
|
2208
|
+
end
|
|
2209
|
+
|
|
2210
|
+
# Ctrl+Alt+F12, which fish 4 names and fish 3 reads as its escape sequence, in the modes the person's bindings use.
|
|
2211
|
+
if string match -qr '^[0-3]\\.' -- $version
|
|
2212
|
+
set -g __noldova_options_key \\e\\[24\\;7~
|
|
2213
|
+
else
|
|
2214
|
+
set -g __noldova_options_key ctrl-alt-f12
|
|
2215
|
+
end
|
|
2216
|
+
|
|
2217
|
+
function __noldova_bound_count
|
|
2218
|
+
set -l count 0
|
|
2219
|
+
for mode in default insert
|
|
2220
|
+
if string match -q '*__noldova_list_options*' -- (bind -M $mode $__noldova_options_key 2>/dev/null | string collect)
|
|
2221
|
+
set count (math $count + 1)
|
|
2222
|
+
end
|
|
2223
|
+
end
|
|
2224
|
+
echo $count
|
|
2225
|
+
end
|
|
2226
|
+
|
|
2227
|
+
# Not where the person bound the key, which the binding would take over; it binds again after the person's key bindings were set again,
|
|
2228
|
+
# as fish_vi_key_bindings erases every binding.
|
|
2229
|
+
function __noldova_bind
|
|
2230
|
+
for mode in default insert
|
|
2231
|
+
if not bind -M $mode $__noldova_options_key >/dev/null 2>&1
|
|
2232
|
+
bind -M $mode $__noldova_options_key __noldova_list_options
|
|
2233
|
+
end
|
|
2234
|
+
end
|
|
2235
|
+
end
|
|
2236
|
+
end
|
|
1979
2237
|
`;
|
|
1980
2238
|
static shellWordsPowerShellEscapeReplacement = "`$&";
|
|
1981
2239
|
static shellWordsPosixEscapeReplacement = "\\$&";
|
package/src/runtime-part.js
CHANGED
|
@@ -57,7 +57,7 @@ export class RuntimePart {
|
|
|
57
57
|
historyFolder.start();
|
|
58
58
|
try {
|
|
59
59
|
const events = new TerminalEvents(context.declareEvent(TerminalNames.outputEvent), context.declareEvent(TerminalNames.exitedEvent), context.declareEvent(TerminalNames.restartedEvent), context.declareEvent(TerminalNames.titleChangedEvent), context.declareEvent(TerminalNames.cwdChangedEvent), context.declareEvent(TerminalNames.detachedEvent), context.declareEvent(TerminalNames.closedEvent), context.declareEvent(TerminalNames.openedEvent), context.declareEvent(TerminalNames.launchCommandEndedEvent), context.declareEvent(TerminalNames.runOpenedEvent), context.declareEvent(TerminalNames.runEndedEvent), context.declareEvent(TerminalNames.renamedEvent), context.declareEvent(TerminalNames.commandAddedEvent), context.declareEvent(TerminalNames.commandStartedEvent), context.declareEvent(TerminalNames.outputStartedEvent), context.declareEvent(TerminalNames.outputPrintedEvent), context.declareEvent(TerminalNames.commandEndedEvent), context.declareEvent(TerminalNames.promptStartedEvent), context.declareEvent(TerminalNames.screenChangedEvent));
|
|
60
|
-
const host = new TerminalHost(new ContextPtySpawner(context), reader, new ShellIntegration(writer, tmpdir(), context.log, access, context.settings, process.platform), historyFolder, new ShellLocator(process.platform, process.arch, process.env, ShellLocator.readUserShell(), reader, runner, context.log), process.platform, release(), new LatestEnvironment(environment, process.env), homedir(), context.log, events, new SavedTerminals(context.database, context.log), new CompletionSource(reader, runner, process.platform, homedir(), context.log), new CommandDescriber(runner, context.log));
|
|
60
|
+
const host = new TerminalHost(new ContextPtySpawner(context), reader, new ShellIntegration(writer, tmpdir(), context.log, access, context.settings, process.platform), historyFolder, new ShellLocator(process.platform, process.arch, process.env, ShellLocator.readUserShell(), reader, runner, context.log), process.platform, release(), new LatestEnvironment(environment, process.env), homedir(), context.log, events, new SavedTerminals(context.database, context.log), new CompletionSource(reader, runner, process.platform, homedir(), context.log), new CommandDescriber(runner, context.log), context);
|
|
61
61
|
for (const name of TerminalNames.methods)
|
|
62
62
|
context.registerMethod(name, { handleAsync: t => host.handleAsync(name, t.payload, RequestClient.fromContext(t)) });
|
|
63
63
|
context.onClientClosed(t => host.closeConnectionAsync(t.connection, t.window));
|