@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
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
The terminal module for apps on [Noldova Desktop](https://github.com/noldova-com/desktop): terminal panes over real shells, and agent tools that run commands through permission requests.
|
|
4
4
|
It holds the module's `module.json`, `menus.json` and `settings.json`, and its runtime part, which starts the shells in Noldova Desktop's pseudo-terminals, keeps a headless mirror of each terminal and registers the agent tools.
|
|
5
5
|
|
|
6
|
-
It exports `./runtime`, the runtime part,
|
|
6
|
+
It exports `./runtime`, the runtime part, `./window`, which re-exports the published API of the window part, [`@noldova/terminal.window`](https://github.com/noldova-com/terminal/tree/main/src/noldova.terminal.window), and `./menus.json`, the module's menus.
|
|
7
7
|
It pins that package and [`@noldova/terminal.protocol`](https://github.com/noldova-com/terminal/tree/main/src/noldova.terminal.protocol) at its own version.
|
|
8
8
|
|
|
9
9
|
An app installs it pinned exactly and lists it in `desktop.modules`, as [documents/INTEGRATION.md](https://github.com/noldova-com/terminal/blob/main/documents/INTEGRATION.md) says.
|
package/module.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "terminal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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.17 <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.8",
|
|
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",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"types": "./src/api/window.d.ts",
|
|
23
23
|
"default": "./src/api/window.js"
|
|
24
24
|
},
|
|
25
|
+
"./menus.json": "./menus.json",
|
|
25
26
|
"./package.json": "./package.json"
|
|
26
27
|
},
|
|
27
28
|
"files": [
|
|
@@ -36,17 +37,18 @@
|
|
|
36
37
|
"registry": "https://registry.npmjs.org/"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@noldova/terminal.protocol": "0.0.
|
|
40
|
-
"@noldova/terminal.window": "0.0.
|
|
40
|
+
"@noldova/terminal.protocol": "0.0.8",
|
|
41
|
+
"@noldova/terminal.window": "0.0.8",
|
|
41
42
|
"@xterm/addon-serialize": "0.14.0",
|
|
42
43
|
"@xterm/headless": "6.0.0",
|
|
43
44
|
"node-pty": "1.2.0-beta.15"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
|
-
"@noldova/desktop.protocol": ">=0.0.
|
|
47
|
-
"@noldova/desktop.runtime": ">=0.0.
|
|
47
|
+
"@noldova/desktop.protocol": ">=0.0.17 <0.1.0",
|
|
48
|
+
"@noldova/desktop.runtime": ">=0.0.17 <0.1.0",
|
|
49
|
+
"@noldova/context.core": ">=0.0.12 <0.1.0",
|
|
48
50
|
"@noldova/context.exceptions": ">=0.0.12 <0.1.0",
|
|
49
51
|
"@noldova/context.json": ">=0.0.12 <0.1.0"
|
|
50
52
|
},
|
|
51
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "6f07ee91e7a7874b8c5564180f3c4aef8686984a"
|
|
52
54
|
}
|
|
@@ -5,11 +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 { ExceptionOptions } from "@noldova/context.exceptions";
|
|
9
10
|
import { Resources } from "../resources.js";
|
|
10
11
|
import { TerminalException } from "./terminal.exception.js";
|
|
11
12
|
export class StoredLinesDamagedException extends TerminalException {
|
|
12
13
|
constructor(cause) {
|
|
13
|
-
super(Resources.storedLinesDamaged, cause
|
|
14
|
+
super(Resources.storedLinesDamaged, Object.isUndefined(cause) ? undefined : new ExceptionOptions(cause));
|
|
14
15
|
}
|
|
15
16
|
}
|
|
@@ -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 { TerminalOpening } from "./terminal-opening.js";
|
|
10
11
|
export class HostedTerminal {
|
|
@@ -28,6 +29,7 @@ export class HostedTerminal {
|
|
|
28
29
|
keyCount = 0;
|
|
29
30
|
inputReceivedLength = null;
|
|
30
31
|
inputTime = 0;
|
|
32
|
+
typedTime = 0;
|
|
31
33
|
inputPrompt = null;
|
|
32
34
|
inputCommandMarks = 0;
|
|
33
35
|
restarts = Promise.resolve();
|
|
@@ -75,30 +77,33 @@ export class HostedTerminal {
|
|
|
75
77
|
get hasRecentInput() {
|
|
76
78
|
return Date.now() - this.inputTime < Resources.echoSettleMilliseconds;
|
|
77
79
|
}
|
|
80
|
+
get hasRecentTyping() {
|
|
81
|
+
return Date.now() - this.typedTime < Resources.echoSettleMilliseconds;
|
|
82
|
+
}
|
|
78
83
|
get hasUnreadInput() {
|
|
79
84
|
const commands = this.session.commands;
|
|
80
85
|
const prompt = commands.promptIdentity;
|
|
81
|
-
return this.hasRecentInput && (this.inputPrompt
|
|
86
|
+
return this.hasRecentInput && (Object.isNull(this.inputPrompt) || Object.isNull(prompt) || prompt === this.inputPrompt
|
|
82
87
|
|| commands.commandMarks === this.inputCommandMarks);
|
|
83
88
|
}
|
|
84
89
|
get isFree() {
|
|
85
|
-
return this.ownerSessionId
|
|
90
|
+
return Object.isNull(this.ownerSessionId) && !this.session.hasExited && !this.isRestarting && Object.isNull(this.pendingCommand)
|
|
86
91
|
&& this.session.commands.hasMarks && !this.hasUnreadInput && this.session.readPromptLine() === "";
|
|
87
92
|
}
|
|
88
93
|
get isDrawingPrompt() {
|
|
89
|
-
return this.ownerSessionId
|
|
94
|
+
return Object.isNull(this.ownerSessionId) && !this.session.hasExited && !this.isRestarting && Object.isNull(this.pendingCommand)
|
|
90
95
|
&& this.session.commands.isDrawingPrompt;
|
|
91
96
|
}
|
|
92
|
-
recordInput(isReply = false, data = "") {
|
|
97
|
+
recordInput(isReply = false, data = "", isAgent = false) {
|
|
93
98
|
this.inputReceivedLength = this.session.receivedLength;
|
|
94
99
|
if (isReply)
|
|
95
100
|
return;
|
|
96
101
|
const commands = this.session.commands;
|
|
97
|
-
this.record(commands.isWaitingAtPrompt && !HostedTerminal.hasTextAfterLineBreak(data) ? commands.promptIdentity : null);
|
|
102
|
+
this.record(commands.isWaitingAtPrompt && !HostedTerminal.hasTextAfterLineBreak(data) ? commands.promptIdentity : null, isAgent);
|
|
98
103
|
}
|
|
99
104
|
recordRunInput() {
|
|
100
105
|
this.inputReceivedLength = this.session.receivedLength;
|
|
101
|
-
this.record(this.typedEnds === 1 ? this.session.commands.promptIdentity : null);
|
|
106
|
+
this.record(this.typedEnds === 1 ? this.session.commands.promptIdentity : null, false);
|
|
102
107
|
}
|
|
103
108
|
addRun(runId, startLine) {
|
|
104
109
|
this.runs.set(runId, startLine);
|
|
@@ -126,9 +131,11 @@ export class HostedTerminal {
|
|
|
126
131
|
isReachedBy(connection, isApp) {
|
|
127
132
|
return this.opening.isReachedBy(connection, isApp);
|
|
128
133
|
}
|
|
129
|
-
record(prompt) {
|
|
134
|
+
record(prompt, isAgent) {
|
|
130
135
|
this.inputCount++;
|
|
131
136
|
this.inputTime = Date.now();
|
|
137
|
+
if (!isAgent)
|
|
138
|
+
this.typedTime = this.inputTime;
|
|
132
139
|
this.inputPrompt = prompt;
|
|
133
140
|
this.inputCommandMarks = this.session.commands.commandMarks;
|
|
134
141
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 IntegrationScript {
|
|
9
|
+
fileName;
|
|
10
|
+
text;
|
|
11
|
+
constructor(fileName, text) {
|
|
12
|
+
this.fileName = fileName;
|
|
13
|
+
this.text = text;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 MarkIntroducer {
|
|
9
|
+
start;
|
|
10
|
+
text;
|
|
11
|
+
constructor(start, text) {
|
|
12
|
+
this.start = start;
|
|
13
|
+
this.text = text;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 MarkTerminator {
|
|
9
|
+
payloadEnd;
|
|
10
|
+
end;
|
|
11
|
+
constructor(payloadEnd, end) {
|
|
12
|
+
this.payloadEnd = payloadEnd;
|
|
13
|
+
this.end = end;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -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 MirrorLine {
|
|
9
10
|
currentNumber;
|
|
10
11
|
marker;
|
|
@@ -16,7 +17,7 @@ export class MirrorLine {
|
|
|
16
17
|
return this.currentNumber;
|
|
17
18
|
}
|
|
18
19
|
get index() {
|
|
19
|
-
return this.marker
|
|
20
|
+
return Object.isUndefined(this.marker) || this.marker.isDisposed ? null : this.marker.line;
|
|
20
21
|
}
|
|
21
22
|
renumber(number) {
|
|
22
23
|
this.currentNumber = number;
|
|
@@ -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 OneShotLaunch {
|
|
10
11
|
file;
|
|
@@ -16,7 +17,7 @@ export class OneShotLaunch {
|
|
|
16
17
|
this.environment = environment;
|
|
17
18
|
}
|
|
18
19
|
get commandLine() {
|
|
19
|
-
if (
|
|
20
|
+
if (!Object.isString(this.args))
|
|
20
21
|
return [this.file, ...this.args].map(t => OneShotLaunch.quote(t)).join(Resources.oneShotLaunchArgumentSeparator);
|
|
21
22
|
let line = this.args;
|
|
22
23
|
for (const [name, value] of Object.entries(this.environment))
|
|
@@ -0,0 +1,15 @@
|
|
|
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 OutputSpan {
|
|
9
|
+
start;
|
|
10
|
+
end;
|
|
11
|
+
constructor(start, end) {
|
|
12
|
+
this.start = start;
|
|
13
|
+
this.end = end;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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 ShellCandidate {
|
|
9
|
+
id;
|
|
10
|
+
name;
|
|
11
|
+
kind;
|
|
12
|
+
files;
|
|
13
|
+
args;
|
|
14
|
+
constructor(id, name, kind, files, args) {
|
|
15
|
+
this.id = id;
|
|
16
|
+
this.name = name;
|
|
17
|
+
this.kind = kind;
|
|
18
|
+
this.files = files;
|
|
19
|
+
this.args = args;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/models/shell-mark.js
CHANGED
|
@@ -5,12 +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
|
export class ShellMark {
|
|
9
10
|
kind;
|
|
10
11
|
value;
|
|
11
12
|
offset;
|
|
12
13
|
values;
|
|
13
|
-
constructor(kind, value, offset, values = value
|
|
14
|
+
constructor(kind, value, offset, values = Object.isNull(value) ? [] : [value]) {
|
|
14
15
|
this.kind = kind;
|
|
15
16
|
this.value = value;
|
|
16
17
|
this.offset = offset;
|
|
@@ -0,0 +1,15 @@
|
|
|
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 TakenSegment {
|
|
9
|
+
segment;
|
|
10
|
+
buffer;
|
|
11
|
+
constructor(segment, buffer) {
|
|
12
|
+
this.segment = segment;
|
|
13
|
+
this.buffer = buffer;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 TerminalFolderKey {
|
|
9
|
+
folder;
|
|
10
|
+
key;
|
|
11
|
+
constructor(folder, key) {
|
|
12
|
+
this.folder = folder;
|
|
13
|
+
this.key = key;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -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 TerminalOpening {
|
|
9
10
|
owner;
|
|
10
11
|
connection;
|
|
@@ -13,6 +14,6 @@ export class TerminalOpening {
|
|
|
13
14
|
this.connection = connection;
|
|
14
15
|
}
|
|
15
16
|
isReachedBy(connection, isApp) {
|
|
16
|
-
return this.connection
|
|
17
|
+
return Object.isNull(this.connection) ? !Object.isNull(this.owner) && isApp : this.connection === connection;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -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 TrackedCommand {
|
|
9
10
|
outputStart;
|
|
10
11
|
hasOutputStart;
|
|
@@ -16,7 +17,7 @@ export class TrackedCommand {
|
|
|
16
17
|
this.hasOutputStart = hasOutputStart;
|
|
17
18
|
}
|
|
18
19
|
get hasEnded() {
|
|
19
|
-
return this.outputEnd
|
|
20
|
+
return !Object.isNull(this.outputEnd);
|
|
20
21
|
}
|
|
21
22
|
end(outputEnd, exitCode, cwd) {
|
|
22
23
|
this.outputEnd = outputEnd;
|
package/src/models/typed-line.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
|
export class TypedLine {
|
|
10
11
|
echo;
|
|
@@ -18,7 +19,7 @@ export class TypedLine {
|
|
|
18
19
|
this.echo = TypedLine.compact(text.slice(Math.max(text.lastIndexOf(Resources.lineFeed), text.lastIndexOf(Resources.enterKey)) + 1));
|
|
19
20
|
}
|
|
20
21
|
get isOpen() {
|
|
21
|
-
return this.command
|
|
22
|
+
return Object.isNull(this.command) && Object.isNull(this.endOffset);
|
|
22
23
|
}
|
|
23
24
|
read(text) {
|
|
24
25
|
const lines = text.split(Resources.lineFeed);
|
|
@@ -0,0 +1,15 @@
|
|
|
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 WslLauncher {
|
|
9
|
+
file;
|
|
10
|
+
reader;
|
|
11
|
+
constructor(file, reader) {
|
|
12
|
+
this.file = file;
|
|
13
|
+
this.reader = reader;
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/resources.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 as ProtocolResources, TerminalShellKind } from "@noldova/terminal.protocol";
|
|
9
10
|
import { MarkKind } from "./enums/mark-kind.js";
|
|
10
11
|
import { SystemRequirement } from "./enums/system-requirement.js";
|
|
@@ -142,7 +143,8 @@ export class Resources {
|
|
|
142
143
|
static windowsPlatform = "win32";
|
|
143
144
|
static linuxPlatform = "linux";
|
|
144
145
|
static minimumWindowsBuild = 17_763;
|
|
145
|
-
static
|
|
146
|
+
static minimumGlibcMajor = 2;
|
|
147
|
+
static minimumGlibcMinor = 28;
|
|
146
148
|
static macPlatform = "darwin";
|
|
147
149
|
static languageVariable = "LANG";
|
|
148
150
|
static characterTypeVariable = "LC_CTYPE";
|
|
@@ -712,7 +714,7 @@ exit 0
|
|
|
712
714
|
return `The terminal module has no method ${method}.`;
|
|
713
715
|
}
|
|
714
716
|
static formatShellLeftRunning(sessionId, pid) {
|
|
715
|
-
return `The shell of terminal ${sessionId}${pid
|
|
717
|
+
return `The shell of terminal ${sessionId}${Object.isNull(pid) ? "" : `, process ${pid}`}, or a process it started, did not end in time.`;
|
|
716
718
|
}
|
|
717
719
|
static formatTerminalHistoryFile(sessionId, index) {
|
|
718
720
|
return `${sessionId}-${index}.jsonl`;
|
|
@@ -748,7 +750,7 @@ exit 0
|
|
|
748
750
|
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.`;
|
|
749
751
|
}
|
|
750
752
|
static formatLateShellLeftRunning(pid) {
|
|
751
|
-
return `A shell that started as the terminals ended${pid
|
|
753
|
+
return `A shell that started as the terminals ended${Object.isNull(pid) ? "" : `, process ${pid}`}, or a process it started, did not end in time.`;
|
|
752
754
|
}
|
|
753
755
|
static formatLogFailed(path, message) {
|
|
754
756
|
return `The log file ${path} stopped taking output: ${message}`;
|
|
@@ -1716,9 +1718,11 @@ fi
|
|
|
1716
1718
|
static agentTerminalOpeningOwnerSessionIdField = "ownerSessionId";
|
|
1717
1719
|
static agentTerminalOpeningShellIdField = "shellId";
|
|
1718
1720
|
static outputChunkEndOffsetField = "endOffset";
|
|
1721
|
+
static outputChunkTrimmedCharactersField = "trimmedCharacters";
|
|
1719
1722
|
static outputExcerptHighSurrogates = /[\ud800-\udbff]$/;
|
|
1720
1723
|
static outputExcerptLowSurrogates = /^[\udc00-\udfff]/;
|
|
1721
1724
|
static outputExcerptMaximumCharactersField = "maximumCharacters";
|
|
1725
|
+
static outputExcerptTrimmedCharactersField = "trimmedCharacters";
|
|
1722
1726
|
static formatPermissionAskAction(action) {
|
|
1723
1727
|
return `${Resources.moduleId}.${action}`;
|
|
1724
1728
|
}
|
package/src/runtime-part.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 { homedir, release, tmpdir } from "node:os";
|
|
9
10
|
import { TerminalNames } from "@noldova/terminal.protocol";
|
|
10
11
|
import { UnsupportedSystemException } from "./exceptions/unsupported-system.exception.js";
|
|
@@ -39,7 +40,7 @@ export class RuntimePart {
|
|
|
39
40
|
environment = null;
|
|
40
41
|
async activateAsync(context) {
|
|
41
42
|
const shortfall = SystemRequirements.findShortfall(process.platform, release(), process.report.getReport());
|
|
42
|
-
if (shortfall
|
|
43
|
+
if (!Object.isNull(shortfall)) {
|
|
43
44
|
const error = new UnsupportedSystemException(shortfall.requirement, shortfall.found);
|
|
44
45
|
context.log.write(error.message);
|
|
45
46
|
throw error;
|
|
@@ -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 { TerminalPrompt } from "../models/terminal-prompt.js";
|
|
10
11
|
import { Resources } from "../resources.js";
|
|
@@ -69,11 +70,11 @@ export class AgentTerminal {
|
|
|
69
70
|
return this.isRunning && !this.session.commands.isAtPrompt && this.session.text.isAwaitingSecret;
|
|
70
71
|
}
|
|
71
72
|
get hasPendingLine() {
|
|
72
|
-
return this.hosted.
|
|
73
|
+
return this.hosted.hasRecentTyping || (this.hasShellIntegration && (this.session.readPromptLine() ?? "").length > 0);
|
|
73
74
|
}
|
|
74
75
|
get hasUnechoedInput() {
|
|
75
76
|
const received = this.hosted.inputReceivedLength;
|
|
76
|
-
if (received
|
|
77
|
+
if (Object.isNull(received) || !this.hosted.hasRecentInput)
|
|
77
78
|
return false;
|
|
78
79
|
return !this.hasShellIntegration || this.hosted.hasUnreadInput;
|
|
79
80
|
}
|
|
@@ -117,7 +118,7 @@ export class AgentTerminal {
|
|
|
117
118
|
return this.session.changes.waitUntilAsync(() => this.session.hasExited || this.session.text.endOffset > offset, timeoutMilliseconds, signal);
|
|
118
119
|
}
|
|
119
120
|
async waitForIntegrationAsync(signal) {
|
|
120
|
-
const isReady = () => !this.session.hasIntegration || this.session.hasExited || this.session.commands.promptEndOffset
|
|
121
|
+
const isReady = () => !this.session.hasIntegration || this.session.hasExited || !Object.isNull(this.session.commands.promptEndOffset);
|
|
121
122
|
await this.session.waitForStartAsync(() => isReady() || this.session.commands.isLoaded, signal);
|
|
122
123
|
if (this.session.commands.isLoaded)
|
|
123
124
|
await this.session.changes.waitUntilAsync(isReady, Resources.shellStartMilliseconds, signal);
|
|
@@ -125,11 +126,13 @@ export class AgentTerminal {
|
|
|
125
126
|
send(data) {
|
|
126
127
|
if (this.oneShot?.isRunning === true)
|
|
127
128
|
this.oneShot.write(data);
|
|
128
|
-
else
|
|
129
|
+
else {
|
|
130
|
+
this.hosted.recordInput(false, data, true);
|
|
129
131
|
this.session.write(data);
|
|
132
|
+
}
|
|
130
133
|
}
|
|
131
134
|
openLogFile() {
|
|
132
|
-
if (this.logFile
|
|
135
|
+
if (Object.isUndefined(this.logFile)) {
|
|
133
136
|
const logFile = new LogFile(this.writer, path.join(this.logFolder, this.id + Resources.logFileExtension), this.log);
|
|
134
137
|
this.session.text.subscribe(t => logFile.append(t));
|
|
135
138
|
this.logFile = logFile;
|
|
@@ -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 as ProtocolResources, TerminalSize } from "@noldova/terminal.protocol";
|
|
9
10
|
import { Resources } from "../resources.js";
|
|
10
11
|
import { AgentTerminal } from "./agent-terminal.js";
|
|
@@ -30,7 +31,7 @@ export class AgentTerminals {
|
|
|
30
31
|
}
|
|
31
32
|
find(id) {
|
|
32
33
|
const hosted = this.host.findTerminal(id);
|
|
33
|
-
return hosted
|
|
34
|
+
return Object.isUndefined(hosted) ? undefined : this.wrap(hosted);
|
|
34
35
|
}
|
|
35
36
|
async openAsync(opening, signal) {
|
|
36
37
|
const size = new TerminalSize(Resources.agentColumns, Resources.agentRows);
|
|
@@ -46,7 +47,7 @@ export class AgentTerminals {
|
|
|
46
47
|
}
|
|
47
48
|
wrap(hosted) {
|
|
48
49
|
let terminal = this.terminals.get(hosted.session.sessionId);
|
|
49
|
-
if (terminal
|
|
50
|
+
if (Object.isUndefined(terminal)) {
|
|
50
51
|
terminal = new AgentTerminal(hosted, this.host, this.writer, this.logFolder, this.log);
|
|
51
52
|
this.terminals.set(hosted.session.sessionId, terminal);
|
|
52
53
|
}
|
|
@@ -5,7 +5,9 @@
|
|
|
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";
|
|
10
|
+
const CUT_SHORT = Symbol();
|
|
9
11
|
export class BoundedReads {
|
|
10
12
|
reader;
|
|
11
13
|
expiry = Promise.withResolvers();
|
|
@@ -52,13 +54,13 @@ export class BoundedReads {
|
|
|
52
54
|
const shared = read(this.stopping.signal);
|
|
53
55
|
this.pending.add(shared);
|
|
54
56
|
const tracked = shared.finally(() => this.pending.delete(shared));
|
|
55
|
-
const answer = await Promise.race([tracked.
|
|
57
|
+
const answer = await Promise.race([tracked.catch((error) => {
|
|
56
58
|
if (error instanceof ReadDroppedException)
|
|
57
|
-
return
|
|
59
|
+
return CUT_SHORT;
|
|
58
60
|
throw error;
|
|
59
|
-
}), this.expiry.promise.then(() =>
|
|
60
|
-
if (answer !==
|
|
61
|
-
return answer
|
|
61
|
+
}), this.expiry.promise.then(() => CUT_SHORT)]);
|
|
62
|
+
if (answer !== CUT_SHORT)
|
|
63
|
+
return answer;
|
|
62
64
|
this.hasCutShort = true;
|
|
63
65
|
return late;
|
|
64
66
|
}
|
|
@@ -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 ChangeSignal {
|
|
10
11
|
waiters = [];
|
|
@@ -13,9 +14,9 @@ export class ChangeSignal {
|
|
|
13
14
|
waiter();
|
|
14
15
|
}
|
|
15
16
|
async waitUntilAsync(condition, timeoutMilliseconds, signal) {
|
|
16
|
-
const deadline = timeoutMilliseconds
|
|
17
|
-
while (!condition() && !signal.aborted && (deadline
|
|
18
|
-
await this.waitAsync(deadline
|
|
17
|
+
const deadline = Object.isNull(timeoutMilliseconds) ? null : Date.now() + timeoutMilliseconds;
|
|
18
|
+
while (!condition() && !signal.aborted && (Object.isNull(deadline) || Date.now() < deadline))
|
|
19
|
+
await this.waitAsync(Object.isNull(deadline) ? null : deadline - Date.now(), signal);
|
|
19
20
|
}
|
|
20
21
|
waitAsync(timeoutMilliseconds, signal) {
|
|
21
22
|
return new Promise(resolve => {
|
|
@@ -25,7 +26,7 @@ export class ChangeSignal {
|
|
|
25
26
|
this.waiters = this.waiters.filter(t => t !== done);
|
|
26
27
|
resolve();
|
|
27
28
|
};
|
|
28
|
-
const timer = timeoutMilliseconds
|
|
29
|
+
const timer = Object.isNull(timeoutMilliseconds) ? undefined : setTimeout(done, timeoutMilliseconds);
|
|
29
30
|
signal.addEventListener(Resources.abortEvent, done);
|
|
30
31
|
this.waiters.push(done);
|
|
31
32
|
});
|
|
@@ -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 { addAbortListener } from "node:events";
|
|
8
9
|
import path from "node:path";
|
|
9
10
|
import { ProcessRequest, ProcessStartException } from "@noldova/desktop.runtime";
|
|
10
11
|
import { CommandExitedException } from "../exceptions/command-exited.exception.js";
|
|
@@ -28,11 +29,11 @@ export class CommandRunner {
|
|
|
28
29
|
const answer = Promise.withResolvers();
|
|
29
30
|
const late = setTimeout(() => answer.reject(new CommandTimedOutException(name, timeoutMilliseconds)), timeoutMilliseconds);
|
|
30
31
|
const ending = setTimeout(() => stopping.abort(), Math.max(timeoutMilliseconds, endMilliseconds));
|
|
31
|
-
const
|
|
32
|
+
const ended = this.readAsync(name, request, stopping, timeoutMilliseconds, () => clearTimeout(late)).then(answer.resolve, answer.reject)
|
|
33
|
+
.finally(() => {
|
|
32
34
|
clearTimeout(late);
|
|
33
35
|
clearTimeout(ending);
|
|
34
|
-
};
|
|
35
|
-
const ended = this.readAsync(name, request, stopping, timeoutMilliseconds, stopTimers).then(answer.resolve, answer.reject).finally(stopTimers);
|
|
36
|
+
});
|
|
36
37
|
return new CommandRun(answer.promise, ended);
|
|
37
38
|
}
|
|
38
39
|
async readAsync(name, request, stopping, timeoutMilliseconds, exited) {
|
|
@@ -47,6 +48,10 @@ export class CommandRunner {
|
|
|
47
48
|
throw error;
|
|
48
49
|
throw new CommandNotStartedException(name, error);
|
|
49
50
|
}
|
|
51
|
+
addAbortListener(stopping.signal, () => {
|
|
52
|
+
process.output.destroy();
|
|
53
|
+
process.errors.destroy();
|
|
54
|
+
});
|
|
50
55
|
let isTooLong = false;
|
|
51
56
|
let output = "";
|
|
52
57
|
process.output.setEncoding(Resources.utf8Encoding);
|
|
@@ -64,7 +69,8 @@ export class CommandRunner {
|
|
|
64
69
|
});
|
|
65
70
|
const closed = new Promise(resolve => process.output.once(Resources.closeEvent, () => resolve()));
|
|
66
71
|
const errorsClosed = new Promise(resolve => process.errors.once(Resources.closeEvent, () => resolve()));
|
|
67
|
-
const
|
|
72
|
+
const exit = await process.exited.finally(exited);
|
|
73
|
+
await Promise.all([closed, errorsClosed]);
|
|
68
74
|
if (isTooLong)
|
|
69
75
|
throw new CommandOutputTooLongException(name, Resources.maximumCommandOutputLength);
|
|
70
76
|
if (stopping.signal.aborted)
|