@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 { Resources as ProtocolResources, TerminalLine, TerminalTextRun, TerminalTextStyle } from "@noldova/terminal.protocol";
|
|
9
10
|
import { Resources } from "../resources.js";
|
|
10
11
|
export class TerminalLineReader {
|
|
@@ -31,7 +32,7 @@ export class TerminalLineReader {
|
|
|
31
32
|
let style = 0;
|
|
32
33
|
for (let x = 0; x < end; x++) {
|
|
33
34
|
const cell = line.getCell(x, this.cell);
|
|
34
|
-
if (cell
|
|
35
|
+
if (Object.isUndefined(cell) || cell.getWidth() === 0)
|
|
35
36
|
continue;
|
|
36
37
|
const chars = cell.getChars() || Resources.blankCell;
|
|
37
38
|
const isPlain = cell.isAttributeDefault();
|
|
@@ -63,7 +64,7 @@ export class TerminalLineReader {
|
|
|
63
64
|
return end;
|
|
64
65
|
}
|
|
65
66
|
isBlank(cell) {
|
|
66
|
-
return cell
|
|
67
|
+
return !Object.isUndefined(cell) && ((cell.getCode() === 0 && cell.isAttributeDefault()) || (cell.getChars().trim().length === 0 && cell.isBgDefault() &&
|
|
67
68
|
!cell.isInverse() && !cell.isUnderline() && !cell.isStrikethrough() && !cell.isOverline()));
|
|
68
69
|
}
|
|
69
70
|
static foregroundOf(cell) {
|
|
@@ -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, TerminalInputStart, TerminalRunOutput } from "@noldova/terminal.protocol";
|
|
9
10
|
import { SerializeAddon } from "@xterm/addon-serialize";
|
|
10
11
|
import { MirrorLine } from "../models/mirror-line.js";
|
|
@@ -74,7 +75,7 @@ export class TerminalMirror {
|
|
|
74
75
|
this.terminal.write("", () => {
|
|
75
76
|
const start = this.inputStart;
|
|
76
77
|
const buffer = this.terminal.buffer.active;
|
|
77
|
-
if (start
|
|
78
|
+
if (!Object.isUndefined(start) && !start.isDisposed && buffer.baseY + buffer.cursorY === start.line)
|
|
78
79
|
this.rightPrompt = buffer.cursorX;
|
|
79
80
|
});
|
|
80
81
|
}
|
|
@@ -93,11 +94,11 @@ export class TerminalMirror {
|
|
|
93
94
|
return new Promise(resolve => this.terminal.write("", () => {
|
|
94
95
|
const buffer = this.terminal.buffer.normal;
|
|
95
96
|
const cursor = buffer.baseY + buffer.cursorY;
|
|
96
|
-
const index = at
|
|
97
|
-
const marker = index
|
|
97
|
+
const index = Object.isNull(at) ? cursor : at.index;
|
|
98
|
+
const marker = Object.isNull(index) || this.terminal.buffer.active.type !== Resources.normalBufferType ? undefined
|
|
98
99
|
: this.terminal.registerMarker(index - cursor);
|
|
99
100
|
const line = new MirrorLine(at?.number ?? this.removedLines + cursor, marker);
|
|
100
|
-
if (marker
|
|
101
|
+
if (!Object.isUndefined(marker)) {
|
|
101
102
|
this.anchors.set(line, marker);
|
|
102
103
|
marker.onDispose(() => this.anchors.delete(line));
|
|
103
104
|
}
|
|
@@ -114,12 +115,12 @@ export class TerminalMirror {
|
|
|
114
115
|
}
|
|
115
116
|
readInput() {
|
|
116
117
|
const start = this.inputStart;
|
|
117
|
-
if (start
|
|
118
|
+
if (Object.isUndefined(start) || start.isDisposed)
|
|
118
119
|
return null;
|
|
119
120
|
const buffer = this.terminal.buffer.normal;
|
|
120
121
|
let text = "";
|
|
121
122
|
let line = buffer.getLine(start.line);
|
|
122
|
-
for (let index = start.line; line
|
|
123
|
+
for (let index = start.line; !Object.isUndefined(line); index++) {
|
|
123
124
|
const next = buffer.getLine(index + 1);
|
|
124
125
|
const continues = next?.isWrapped === true;
|
|
125
126
|
const end = index === start.line && !continues ? this.findRightPrompt(line) : undefined;
|
|
@@ -133,13 +134,13 @@ export class TerminalMirror {
|
|
|
133
134
|
}
|
|
134
135
|
findRightPrompt(line) {
|
|
135
136
|
const column = this.rightPrompt;
|
|
136
|
-
return column
|
|
137
|
+
return !Object.isNull(column) && column > this.inputColumn && line.translateToString(false, column - 1, column).trim().length === 0 ? column : undefined;
|
|
137
138
|
}
|
|
138
139
|
readInputStart() {
|
|
139
140
|
const buffer = this.terminal.buffer.active;
|
|
140
141
|
const start = this.inputStart;
|
|
141
142
|
const cursor = buffer.baseY + buffer.cursorY;
|
|
142
|
-
if (start
|
|
143
|
+
if (Object.isUndefined(start) || start.isDisposed || buffer.type !== Resources.normalBufferType || start.line > cursor)
|
|
143
144
|
return null;
|
|
144
145
|
return new TerminalInputStart(cursor - start.line, this.inputColumn, this.rightPrompt);
|
|
145
146
|
}
|
|
@@ -151,7 +152,7 @@ export class TerminalMirror {
|
|
|
151
152
|
first++;
|
|
152
153
|
const lines = [];
|
|
153
154
|
let line = buffer.getLine(first - this.removedLines);
|
|
154
|
-
for (let number = first; number < last && line
|
|
155
|
+
for (let number = first; number < last && !Object.isUndefined(line); number++) {
|
|
155
156
|
const next = buffer.getLine(number + 1 - this.removedLines);
|
|
156
157
|
lines.push(this.reader.read(line, next?.isWrapped === true));
|
|
157
158
|
line = next;
|
|
@@ -167,7 +168,7 @@ export class TerminalMirror {
|
|
|
167
168
|
this.terminal.resize(size.columns, size.rows);
|
|
168
169
|
const excess = buffer.baseY - Resources.scrollback;
|
|
169
170
|
let line = buffer.getLine(0);
|
|
170
|
-
for (let y = 0; y < excess && line
|
|
171
|
+
for (let y = 0; y < excess && !Object.isUndefined(line); y++) {
|
|
171
172
|
const next = buffer.getLine(y + 1);
|
|
172
173
|
this.store(this.reader.read(line, next?.isWrapped === true));
|
|
173
174
|
line = next;
|
|
@@ -178,14 +179,14 @@ export class TerminalMirror {
|
|
|
178
179
|
anchor.renumber(this.removedLines + marker.line);
|
|
179
180
|
}
|
|
180
181
|
capture() {
|
|
181
|
-
if (this.oldestMarker?.isDisposed === true && this.oldest
|
|
182
|
+
if (this.oldestMarker?.isDisposed === true && !Object.isNull(this.oldest))
|
|
182
183
|
this.store(this.oldest);
|
|
183
184
|
this.releaseOldest();
|
|
184
185
|
const buffer = this.terminal.buffer.normal;
|
|
185
186
|
if (buffer.baseY === Resources.scrollback) {
|
|
186
187
|
this.oldestMarker = this.terminal.registerMarker(-buffer.baseY - buffer.cursorY) ?? null;
|
|
187
188
|
const line = buffer.getLine(0);
|
|
188
|
-
if (this.oldestMarker
|
|
189
|
+
if (!Object.isNull(this.oldestMarker) && !Object.isUndefined(line))
|
|
189
190
|
this.oldest = this.reader.read(line, buffer.getLine(1)?.isWrapped === true);
|
|
190
191
|
}
|
|
191
192
|
}
|
|
@@ -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 { EndedBy, Resources as ProtocolResources, TerminalAttachment, TerminalCommandEnded, TerminalCwd, TerminalExit, TerminalExited, TerminalInputEdge, TerminalInputMark, TerminalOutput, TerminalPaneReference, TerminalReference, TerminalShellKind, TerminalSize, TerminalSummary, TerminalTitle } from "@noldova/terminal.protocol";
|
|
9
10
|
import { MarkKind } from "../enums/mark-kind.js";
|
|
10
11
|
import { ShellMark } from "../models/shell-mark.js";
|
|
@@ -60,8 +61,8 @@ export class TerminalSession {
|
|
|
60
61
|
this.shellId = shellId;
|
|
61
62
|
this.size = size;
|
|
62
63
|
this.windowsPty = windowsPty;
|
|
63
|
-
this.scanner = nonce
|
|
64
|
-
this.hasIntegration = nonce
|
|
64
|
+
this.scanner = Object.isNull(nonce) ? null : new MarkScanner(nonce);
|
|
65
|
+
this.hasIntegration = !Object.isNull(nonce);
|
|
65
66
|
this.listener = listener;
|
|
66
67
|
this.text = new OutputLog(textLimit);
|
|
67
68
|
this.text.subscribe(t => {
|
|
@@ -82,7 +83,7 @@ export class TerminalSession {
|
|
|
82
83
|
onResume: () => this.terminal.resume(),
|
|
83
84
|
onStalled: t => this.listener.onDetached(new TerminalPaneReference(this.sessionId, t))
|
|
84
85
|
});
|
|
85
|
-
this.wakeup = windowsPty
|
|
86
|
+
this.wakeup = !Object.isNull(windowsPty) && shellKind === TerminalShellKind.Bash ? new ResizeWakeup(t => this.terminal.write(t)) : null;
|
|
86
87
|
this.terminal = this.startTerminal(process);
|
|
87
88
|
}
|
|
88
89
|
get pid() {
|
|
@@ -128,7 +129,7 @@ export class TerminalSession {
|
|
|
128
129
|
return this.restartOffsets[run] ?? null;
|
|
129
130
|
}
|
|
130
131
|
get hasExited() {
|
|
131
|
-
return this.exit
|
|
132
|
+
return !Object.isNull(this.exit);
|
|
132
133
|
}
|
|
133
134
|
get receivedLength() {
|
|
134
135
|
return this.receivedOffset;
|
|
@@ -136,7 +137,7 @@ export class TerminalSession {
|
|
|
136
137
|
write(data, isKey = true) {
|
|
137
138
|
if (isKey)
|
|
138
139
|
this.options.cancel();
|
|
139
|
-
this.
|
|
140
|
+
this.beforeInput();
|
|
140
141
|
for (let lines = data.replace(Resources.bracketedPastes, "").split(Resources.lineBreaks).length - 1; lines > 0; lines--)
|
|
141
142
|
this.commands.enterLine();
|
|
142
143
|
this.terminal.write(data);
|
|
@@ -156,12 +157,12 @@ export class TerminalSession {
|
|
|
156
157
|
return true;
|
|
157
158
|
}
|
|
158
159
|
async askOptionsAsync(keys) {
|
|
159
|
-
if (!this.hasIntegration || !this.commands.hasOptionsBinding || !this.commands.isWaitingAtPrompt || this.commands.runningCommand
|
|
160
|
-
|| this.exit
|
|
160
|
+
if (!this.hasIntegration || !this.commands.hasOptionsBinding || !this.commands.isWaitingAtPrompt || !Object.isNull(this.commands.runningCommand)
|
|
161
|
+
|| !Object.isNull(this.exit))
|
|
161
162
|
return ShellOptionsReply.none;
|
|
162
163
|
const reply = this.options.askAsync(this.hasAnsweredOptions ? Resources.optionsMilliseconds
|
|
163
164
|
: Resources.firstOptionsMilliseconds);
|
|
164
|
-
this.
|
|
165
|
+
this.beforeInput();
|
|
165
166
|
this.terminal.write(keys);
|
|
166
167
|
const answered = await reply;
|
|
167
168
|
if (answered.isTimedOut)
|
|
@@ -173,7 +174,7 @@ export class TerminalSession {
|
|
|
173
174
|
}
|
|
174
175
|
readPromptLine() {
|
|
175
176
|
const promptEnd = this.commands.promptEndOffset;
|
|
176
|
-
if (promptEnd
|
|
177
|
+
if (Object.isNull(promptEnd) || !Object.isNull(this.commands.runningCommand))
|
|
177
178
|
return null;
|
|
178
179
|
return this.text.readSince(promptEnd).text.trim();
|
|
179
180
|
}
|
|
@@ -189,13 +190,13 @@ export class TerminalSession {
|
|
|
189
190
|
async attachAsync(paneId, commands) {
|
|
190
191
|
const snapshot = await this.mirror.snapshotAsync();
|
|
191
192
|
this.flow.attach(paneId, snapshot.offset);
|
|
192
|
-
if (this.exit
|
|
193
|
+
if (Object.isNull(this.exit))
|
|
193
194
|
this.redraw();
|
|
194
195
|
return new TerminalAttachment(this.sessionId, snapshot.snapshot, snapshot.pending, snapshot.offset, this.size, this.mirror.title, this.cwd, this.exit, this.windowsPty, this.history.stored, snapshot.input, this.marksInput ? commands : [], this.shellKind);
|
|
195
196
|
}
|
|
196
197
|
anchorRunAsync() {
|
|
197
198
|
const prompt = this.promptLine;
|
|
198
|
-
return prompt
|
|
199
|
+
return Object.isNull(prompt) ? this.mirror.anchorAsync(null) : prompt.then(t => this.mirror.anchorAsync(t));
|
|
199
200
|
}
|
|
200
201
|
readRunLinesAsync(start, end, maximum) {
|
|
201
202
|
return this.mirror.readLinesAsync(start, end, maximum);
|
|
@@ -224,8 +225,8 @@ export class TerminalSession {
|
|
|
224
225
|
this.terminal = this.startTerminal(process);
|
|
225
226
|
if (this.flow.isPaused)
|
|
226
227
|
this.terminal.pause();
|
|
227
|
-
this.scanner = nonce
|
|
228
|
-
this.hasIntegration = nonce
|
|
228
|
+
this.scanner = Object.isNull(nonce) ? null : new MarkScanner(nonce);
|
|
229
|
+
this.hasIntegration = !Object.isNull(nonce);
|
|
229
230
|
this.commands = this.trackCommands();
|
|
230
231
|
this.options.reset();
|
|
231
232
|
this.hasAnsweredOptions = false;
|
|
@@ -258,20 +259,19 @@ export class TerminalSession {
|
|
|
258
259
|
}
|
|
259
260
|
receive(data) {
|
|
260
261
|
const marks = this.scanner?.scan(data, this.receivedOffset) ?? [];
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return edge === null ? [] : [new TerminalInputMark(t.offset - this.receivedOffset, edge)];
|
|
262
|
+
this.batcher.append(data, marks.flatMap(t => {
|
|
263
|
+
const edge = this.readInputEdge(t);
|
|
264
|
+
return Object.isNull(edge) ? [] : [new TerminalInputMark(t.offset - this.receivedOffset, edge)];
|
|
265
265
|
}));
|
|
266
266
|
this.flow.produce(data.length);
|
|
267
267
|
let position = 0;
|
|
268
268
|
let mirrored = 0;
|
|
269
|
-
for (const
|
|
269
|
+
for (const mark of marks) {
|
|
270
270
|
const end = mark.offset - this.receivedOffset;
|
|
271
271
|
this.text.append(data.slice(position, end));
|
|
272
272
|
position = end;
|
|
273
|
-
const edge =
|
|
274
|
-
if (mark.kind === MarkKind.PromptStart || edge
|
|
273
|
+
const edge = this.readInputEdge(mark);
|
|
274
|
+
if (mark.kind === MarkKind.PromptStart || !Object.isNull(edge)) {
|
|
275
275
|
this.mirror.write(data.slice(mirrored, end));
|
|
276
276
|
mirrored = end;
|
|
277
277
|
}
|
|
@@ -323,12 +323,12 @@ export class TerminalSession {
|
|
|
323
323
|
this.settleTypedLines(mark);
|
|
324
324
|
if (mark.kind === MarkKind.CommandEnd) {
|
|
325
325
|
const exitCode = this.commands.lastCommand?.exitCode ?? null;
|
|
326
|
-
this.listener.onCommandEnded(new TerminalCommandEnded(this.sessionId, exitCode
|
|
326
|
+
this.listener.onCommandEnded(new TerminalCommandEnded(this.sessionId, !Object.isNull(exitCode) && exitCode >= ProtocolResources.minimumExitCode && exitCode <= ProtocolResources.maximumExitCode ? exitCode : null));
|
|
327
327
|
}
|
|
328
328
|
else if (mark.kind === MarkKind.PromptStart)
|
|
329
329
|
this.listener.onPromptStarted(new TerminalReference(this.sessionId));
|
|
330
330
|
const cwd = this.commands.cwd;
|
|
331
|
-
if (cwd
|
|
331
|
+
if (Object.isNull(cwd) || cwd === this.reportedCwd || cwd.trim().length === 0 || cwd.length > ProtocolResources.maximumPathLength)
|
|
332
332
|
return;
|
|
333
333
|
this.reportedCwd = cwd;
|
|
334
334
|
this.listener.onCwdChanged(new TerminalCwd(this.sessionId, cwd));
|
|
@@ -337,7 +337,7 @@ export class TerminalSession {
|
|
|
337
337
|
const command = mark.kind === MarkKind.OutputStart ? this.commands.runningCommand
|
|
338
338
|
: mark.kind === MarkKind.CommandEnd ? this.commands.lastCommand : null;
|
|
339
339
|
for (const line of this.typedLines) {
|
|
340
|
-
if (command
|
|
340
|
+
if (!Object.isNull(command))
|
|
341
341
|
line.command = command;
|
|
342
342
|
else if (mark.kind === MarkKind.PromptStart)
|
|
343
343
|
line.prompt(mark.offset);
|
|
@@ -355,8 +355,12 @@ export class TerminalSession {
|
|
|
355
355
|
if (this.terminal === terminal)
|
|
356
356
|
this.end(t);
|
|
357
357
|
},
|
|
358
|
-
onResizeUnasked: () => this.listener.onResizeUnasked(this.sessionId)
|
|
359
|
-
|
|
358
|
+
onResizeUnasked: () => this.listener.onResizeUnasked(this.sessionId),
|
|
359
|
+
onReleasingKeys: () => {
|
|
360
|
+
if (this.terminal === terminal)
|
|
361
|
+
this.wakeup?.beforeInput();
|
|
362
|
+
}
|
|
363
|
+
}, !Object.isNull(this.windowsPty));
|
|
360
364
|
return terminal;
|
|
361
365
|
}
|
|
362
366
|
end(exitCode) {
|
|
@@ -374,6 +378,10 @@ export class TerminalSession {
|
|
|
374
378
|
this.terminal.resize(this.size);
|
|
375
379
|
this.watchResize();
|
|
376
380
|
}
|
|
381
|
+
beforeInput() {
|
|
382
|
+
if (!this.terminal.isHoldingKeys)
|
|
383
|
+
this.wakeup?.beforeInput();
|
|
384
|
+
}
|
|
377
385
|
watchResize() {
|
|
378
386
|
if (this.commands.isWaitingAtPrompt)
|
|
379
387
|
this.wakeup?.watch();
|
|
@@ -382,10 +390,13 @@ export class TerminalSession {
|
|
|
382
390
|
}
|
|
383
391
|
endInput(startsCommand, command) {
|
|
384
392
|
void this.mirror.endInput().then(t => {
|
|
385
|
-
if (startsCommand && t
|
|
393
|
+
if (startsCommand && !Object.isNull(t))
|
|
386
394
|
this.listener.onCommandStarted(TerminalSession.toCommand(command) ?? t);
|
|
387
395
|
}).catch((error) => this.listener.onFailed(this.sessionId, FailureText.read(error)));
|
|
388
396
|
}
|
|
397
|
+
readInputEdge(mark) {
|
|
398
|
+
return this.marksInput ? TerminalSession.toInputEdge(mark.kind) : null;
|
|
399
|
+
}
|
|
389
400
|
static toCommand(value) {
|
|
390
401
|
if (value?.startsWith(Resources.commandProperty) !== true)
|
|
391
402
|
return null;
|
|
@@ -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 { ArgumentException } from "@noldova/context.exceptions";
|
|
10
11
|
import { JsonException, JsonReader } from "@noldova/context.json";
|
|
@@ -19,10 +20,10 @@ export class VisualStudioReader {
|
|
|
19
20
|
constructor(runner, fileSystem, programFilesX86) {
|
|
20
21
|
this.runner = runner;
|
|
21
22
|
this.fileSystem = fileSystem;
|
|
22
|
-
this.vswhere = programFilesX86
|
|
23
|
+
this.vswhere = Object.isUndefined(programFilesX86) || programFilesX86.length === 0 ? null : path.win32.join(programFilesX86, ...Resources.vswherePath);
|
|
23
24
|
}
|
|
24
25
|
async readAsync() {
|
|
25
|
-
if (this.vswhere
|
|
26
|
+
if (Object.isNull(this.vswhere) || !await this.fileSystem.isFileAsync(this.vswhere))
|
|
26
27
|
return [];
|
|
27
28
|
let output;
|
|
28
29
|
try {
|
|
@@ -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 { CommandExitedException } from "../exceptions/command-exited.exception.js";
|
|
10
11
|
import { EnvironmentKeyUnreadableException } from "../exceptions/environment-key-unreadable.exception.js";
|
|
@@ -29,7 +30,7 @@ export class WindowsEnvironment {
|
|
|
29
30
|
this.environment = environment;
|
|
30
31
|
this.tools = tools;
|
|
31
32
|
this.log = log;
|
|
32
|
-
this.reg = systemRoot
|
|
33
|
+
this.reg = Object.isUndefined(systemRoot) || systemRoot.length === 0 ? null : path.win32.join(systemRoot, ...Resources.regPath);
|
|
33
34
|
}
|
|
34
35
|
start() {
|
|
35
36
|
void this.readAsync();
|
|
@@ -37,7 +38,7 @@ export class WindowsEnvironment {
|
|
|
37
38
|
readAsync() {
|
|
38
39
|
if (this.ended)
|
|
39
40
|
return Promise.resolve(this.environment);
|
|
40
|
-
if (this.reading
|
|
41
|
+
if (Object.isNull(this.reading)) {
|
|
41
42
|
const reading = Promise.race([this.readNowAsync(), this.ending.promise.then(() => this.environment)]);
|
|
42
43
|
this.reading = reading;
|
|
43
44
|
void reading.then(() => {
|
|
@@ -56,10 +57,10 @@ export class WindowsEnvironment {
|
|
|
56
57
|
async readNowAsync() {
|
|
57
58
|
try {
|
|
58
59
|
const reg = this.reg;
|
|
59
|
-
if (reg
|
|
60
|
+
if (Object.isNull(reg))
|
|
60
61
|
throw new SystemRootMissingException();
|
|
61
62
|
const folder = await this.prepareFolderAsync();
|
|
62
|
-
if (folder
|
|
63
|
+
if (Object.isNull(folder) || this.ended)
|
|
63
64
|
return this.environment;
|
|
64
65
|
const read = ++this.readCount;
|
|
65
66
|
try {
|
|
@@ -81,7 +82,7 @@ export class WindowsEnvironment {
|
|
|
81
82
|
}
|
|
82
83
|
async prepareFolderAsync() {
|
|
83
84
|
const folder = await this.ensureFolderAsync();
|
|
84
|
-
if (folder
|
|
85
|
+
if (Object.isNull(folder) || await this.tools.reader.isFolderAsync(folder))
|
|
85
86
|
return folder;
|
|
86
87
|
this.folder = null;
|
|
87
88
|
return await this.ensureFolderAsync();
|
|
@@ -117,7 +118,7 @@ export class WindowsEnvironment {
|
|
|
117
118
|
await this.exportAsync(reg, key, file);
|
|
118
119
|
}
|
|
119
120
|
catch (error) {
|
|
120
|
-
if (!(error instanceof CommandExitedException) || error.exitCode
|
|
121
|
+
if (!(error instanceof CommandExitedException) || Object.isNull(error.exitCode))
|
|
121
122
|
throw new EnvironmentKeyUnreadableException(key, error);
|
|
122
123
|
const isPresent = await this.isPresentAsync(reg, key).catch(() => {
|
|
123
124
|
throw new EnvironmentKeyUnreadableException(key, error);
|
|
@@ -137,7 +138,7 @@ export class WindowsEnvironment {
|
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
const bytes = await this.tools.reader.readBytesOrNullAsync(file);
|
|
140
|
-
if (bytes
|
|
141
|
+
if (Object.isNull(bytes))
|
|
141
142
|
throw new EnvironmentExportInvalidException();
|
|
142
143
|
return RegistryExport.parse(new TextDecoder(Resources.registryExportUtf16Label).decode(bytes));
|
|
143
144
|
}
|
|
@@ -155,7 +156,7 @@ export class WindowsEnvironment {
|
|
|
155
156
|
return true;
|
|
156
157
|
}
|
|
157
158
|
catch (error) {
|
|
158
|
-
if (error instanceof CommandExitedException && error.exitCode
|
|
159
|
+
if (error instanceof CommandExitedException && !Object.isNull(error.exitCode))
|
|
159
160
|
return false;
|
|
160
161
|
throw error;
|
|
161
162
|
}
|
|
@@ -173,12 +174,12 @@ export class WindowsEnvironment {
|
|
|
173
174
|
static build(environment, machine, user) {
|
|
174
175
|
const variables = new Map();
|
|
175
176
|
for (const [name, value] of Object.entries(environment)) {
|
|
176
|
-
if (value
|
|
177
|
+
if (!Object.isUndefined(value))
|
|
177
178
|
variables.set(name.toUpperCase(), new EnvironmentVariable(name, value));
|
|
178
179
|
}
|
|
179
180
|
const machinePath = WindowsEnvironment.apply(variables, machine);
|
|
180
181
|
const userPath = WindowsEnvironment.apply(variables, user);
|
|
181
|
-
if (machinePath
|
|
182
|
+
if (!Object.isUndefined(machinePath) && !Object.isUndefined(userPath))
|
|
182
183
|
variables.set(Resources.pathVariable, new EnvironmentVariable(machinePath.name, `${machinePath.value}${path.win32.delimiter}${userPath.value}`));
|
|
183
184
|
return Object.fromEntries([...variables.values()].map(t => [t.name, t.value]));
|
|
184
185
|
}
|
|
@@ -205,7 +206,7 @@ export class WindowsEnvironment {
|
|
|
205
206
|
if (end === -1)
|
|
206
207
|
return text + value.slice(index);
|
|
207
208
|
const variable = variables.get(value.slice(start + 1, end).toUpperCase());
|
|
208
|
-
if (variable
|
|
209
|
+
if (Object.isUndefined(variable)) {
|
|
209
210
|
text += value.slice(index, end);
|
|
210
211
|
index = end;
|
|
211
212
|
}
|
|
@@ -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 { CommandVariableNotSetException } from "../exceptions/command-variable-not-set.exception.js";
|
|
10
11
|
import { Resources } from "../resources.js";
|
|
@@ -16,7 +17,7 @@ export class WindowsFolderAccess {
|
|
|
16
17
|
this.systemRoot = systemRoot;
|
|
17
18
|
}
|
|
18
19
|
async restrictAsync(folder) {
|
|
19
|
-
if (this.systemRoot
|
|
20
|
+
if (Object.isUndefined(this.systemRoot) || this.systemRoot.length === 0)
|
|
20
21
|
throw new CommandVariableNotSetException(Resources.icaclsFile, Resources.systemRootVariable);
|
|
21
22
|
await this.runner.runAsync(path.win32.join(this.systemRoot, ...Resources.icaclsPath), [folder, ...Resources.privateFolderGrants], Resources.folderAccessMilliseconds);
|
|
22
23
|
}
|
|
@@ -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 { CommandFailedException } from "../exceptions/command-failed.exception.js";
|
|
10
11
|
import { WslDistributionsUnreadableException } from "../exceptions/wsl-distributions-unreadable.exception.js";
|
|
@@ -36,7 +37,7 @@ export class WslDistributionReader {
|
|
|
36
37
|
const others = [];
|
|
37
38
|
for (const line of lines) {
|
|
38
39
|
const [name, flag, ...rest] = line.split(Resources.wslDistributionReaderFieldSeparator);
|
|
39
|
-
if (name
|
|
40
|
+
if (Object.isUndefined(name) || name.length === 0 || !Resources.base64Pattern.test(name) || rest.length > 0 ||
|
|
40
41
|
(flag !== Resources.wslDefaultFlag && flag !== Resources.wslOtherFlag))
|
|
41
42
|
throw new WslDistributionsUnreadableException();
|
|
42
43
|
(flag === Resources.wslDefaultFlag ? defaults : others).push(Buffer.from(name, Resources.base64Encoding).toString(Resources.utf8Encoding));
|
|
@@ -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 { isAbsolute } from "node:path";
|
|
9
10
|
import { ArgumentException } from "@noldova/context.exceptions";
|
|
10
11
|
import { ArgumentValidator, Resources as ProtocolResources } from "@noldova/terminal.protocol";
|
|
@@ -16,7 +17,7 @@ export class AgentTerminalOpening {
|
|
|
16
17
|
owner;
|
|
17
18
|
constructor(ownerSessionId, shellId, cwd, owner = null) {
|
|
18
19
|
ArgumentValidator.requireIdentifier(Resources.agentTerminalOpeningOwnerSessionIdField, ownerSessionId);
|
|
19
|
-
if (shellId
|
|
20
|
+
if (!Object.isNull(shellId))
|
|
20
21
|
ArgumentValidator.requireIdentifier(Resources.agentTerminalOpeningShellIdField, shellId);
|
|
21
22
|
ArgumentValidator.requireNonBlank(Resources.cwdField, cwd, ProtocolResources.maximumPathLength);
|
|
22
23
|
if (!isAbsolute(cwd))
|
|
@@ -10,9 +10,12 @@ import { Resources } from "../../resources.js";
|
|
|
10
10
|
export class OutputChunk {
|
|
11
11
|
text;
|
|
12
12
|
endOffset;
|
|
13
|
-
|
|
13
|
+
trimmedCharacters;
|
|
14
|
+
constructor(text, endOffset, trimmedCharacters = 0) {
|
|
14
15
|
ArgumentValidator.requireIntegerInRange(Resources.outputChunkEndOffsetField, endOffset, 0, ProtocolResources.maximumOffset);
|
|
16
|
+
ArgumentValidator.requireIntegerInRange(Resources.outputChunkTrimmedCharactersField, trimmedCharacters, 0, ProtocolResources.maximumOffset);
|
|
15
17
|
this.text = text;
|
|
16
18
|
this.endOffset = endOffset;
|
|
19
|
+
this.trimmedCharacters = trimmedCharacters;
|
|
17
20
|
}
|
|
18
21
|
}
|
|
@@ -5,22 +5,28 @@
|
|
|
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 { ArgumentValidator } from "@noldova/terminal.protocol";
|
|
8
|
+
import { ArgumentValidator, Resources as ProtocolResources } from "@noldova/terminal.protocol";
|
|
9
9
|
import { Resources } from "../../resources.js";
|
|
10
10
|
export class OutputExcerpt {
|
|
11
11
|
text;
|
|
12
12
|
omittedCharacters;
|
|
13
|
-
constructor(output, maximumCharacters) {
|
|
13
|
+
constructor(output, maximumCharacters, trimmedCharacters = 0) {
|
|
14
14
|
ArgumentValidator.requireIntegerInRange(Resources.outputExcerptMaximumCharactersField, maximumCharacters, 1, Resources.maximumToolOutputCharacters);
|
|
15
|
+
ArgumentValidator.requireIntegerInRange(Resources.outputExcerptTrimmedCharactersField, trimmedCharacters, 0, ProtocolResources.maximumOffset);
|
|
16
|
+
const trimmed = trimmedCharacters === 0 ? "" : Resources.formatOmittedCharacters(trimmedCharacters);
|
|
15
17
|
if (output.length <= maximumCharacters) {
|
|
16
|
-
this.text = output;
|
|
17
|
-
this.omittedCharacters =
|
|
18
|
+
this.text = trimmed + output;
|
|
19
|
+
this.omittedCharacters = trimmedCharacters;
|
|
18
20
|
return;
|
|
19
21
|
}
|
|
20
22
|
const head = OutputExcerpt.trimHead(output.slice(0, Math.ceil(maximumCharacters / 2)));
|
|
21
23
|
const tail = OutputExcerpt.trimTail(output.slice(output.length - Math.floor(maximumCharacters / 2)));
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
+
const between = output.length - head.length - tail.length;
|
|
25
|
+
this.omittedCharacters = trimmedCharacters + between;
|
|
26
|
+
this.text = trimmed + head + Resources.formatOmittedCharacters(between) + tail;
|
|
27
|
+
}
|
|
28
|
+
static of(chunk, maximumCharacters) {
|
|
29
|
+
return new OutputExcerpt(chunk.text, maximumCharacters, chunk.trimmedCharacters);
|
|
24
30
|
}
|
|
25
31
|
static trimHead(head) {
|
|
26
32
|
return Resources.outputExcerptHighSurrogates.test(head) ? head.slice(0, -1) : head;
|
|
@@ -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 { ArgumentValidator, ProtocolReader, Resources as ProtocolResources } from "@noldova/terminal.protocol";
|
|
9
10
|
import { Resources } from "../../resources.js";
|
|
10
11
|
export class TerminalOpenInput {
|
|
@@ -19,9 +20,9 @@ export class TerminalOpenInput {
|
|
|
19
20
|
shellId;
|
|
20
21
|
explanation;
|
|
21
22
|
constructor(shellId, explanation) {
|
|
22
|
-
if (shellId
|
|
23
|
+
if (!Object.isNull(shellId))
|
|
23
24
|
ArgumentValidator.requireIdentifier(Resources.shellField, shellId);
|
|
24
|
-
if (explanation
|
|
25
|
+
if (!Object.isNull(explanation))
|
|
25
26
|
ArgumentValidator.requireMaximumLength(Resources.explanationField, explanation, Resources.maximumExplanationLength);
|
|
26
27
|
this.shellId = shellId;
|
|
27
28
|
this.explanation = explanation;
|
|
@@ -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 { CommandStatus } from "../enums/command-status.js";
|
|
10
11
|
import { RunMethod } from "../enums/run-method.js";
|
|
@@ -44,21 +45,21 @@ export class TerminalOutputReport {
|
|
|
44
45
|
this.cwd = cwd;
|
|
45
46
|
}
|
|
46
47
|
toResult(note = "") {
|
|
47
|
-
const status = this.command
|
|
48
|
-
const exitCode = this.command
|
|
48
|
+
const status = Object.isNull(this.command) ? null : this.command.status;
|
|
49
|
+
const exitCode = Object.isNull(this.command) ? null : this.command.exitCode;
|
|
49
50
|
const isAwaitingSecret = this.access.terminal.isAwaitingSecret;
|
|
50
51
|
return ToolResults.create(this.excerpt.text + Resources.formatCommandSummary(status, exitCode, this.cwd, isAwaitingSecret) + note, {
|
|
51
52
|
[Resources.terminalIdField]: this.access.terminal.id,
|
|
52
53
|
[Resources.titleField]: this.access.terminal.title,
|
|
53
54
|
[Resources.nameField]: this.access.terminal.name,
|
|
54
55
|
[Resources.shellNameField]: this.access.terminal.shellName,
|
|
55
|
-
[Resources.terminalOutputReportMethodField]: this.command
|
|
56
|
+
[Resources.terminalOutputReportMethodField]: Object.isNull(this.command) ? null : this.command.method,
|
|
56
57
|
[Resources.terminalOutputReportStatusField]: status,
|
|
57
58
|
[Resources.terminalOutputReportExitCodeField]: exitCode,
|
|
58
59
|
[Resources.cwdField]: this.cwd,
|
|
59
60
|
[Resources.terminalOutputReportOutputField]: this.excerpt.text,
|
|
60
61
|
[Resources.terminalOutputReportOmittedCharactersField]: this.excerpt.omittedCharacters,
|
|
61
|
-
[Resources.terminalOutputReportLogFileField]: this.command
|
|
62
|
+
[Resources.terminalOutputReportLogFileField]: Object.isNull(this.command) ? null : this.command.logFile,
|
|
62
63
|
[Resources.terminalOutputReportIsAwaitingSecretField]: isAwaitingSecret
|
|
63
64
|
}, this.access.origin);
|
|
64
65
|
}
|
|
@@ -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 { ArgumentValidator, ProtocolReader, Resources as ProtocolResources } from "@noldova/terminal.protocol";
|
|
9
10
|
import { Resources } from "../../resources.js";
|
|
10
11
|
import { CommandLine } from "./command-line.js";
|
|
@@ -30,7 +31,7 @@ export class TerminalRunInput {
|
|
|
30
31
|
maximumCharacters;
|
|
31
32
|
constructor(terminalId, command, explanation, yieldMilliseconds, timeoutMilliseconds, maximumCharacters) {
|
|
32
33
|
ArgumentValidator.requireIdentifier(Resources.terminalIdField, terminalId);
|
|
33
|
-
if (explanation
|
|
34
|
+
if (!Object.isNull(explanation))
|
|
34
35
|
ArgumentValidator.requireMaximumLength(Resources.explanationField, explanation, Resources.maximumExplanationLength);
|
|
35
36
|
ArgumentValidator.requireIntegerInRange(Resources.terminalRunInputYieldMsField, yieldMilliseconds, Resources.minimumYieldMilliseconds, Resources.maximumCallMilliseconds);
|
|
36
37
|
ArgumentValidator.requireIntegerInRange(Resources.terminalRunInputTimeoutMsField, timeoutMilliseconds, 0, ProtocolResources.maximumOffset);
|
|
@@ -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 { ArgumentValidator, ProtocolReader, Resources as ProtocolResources } from "@noldova/terminal.protocol";
|
|
9
10
|
import { Resources } from "../../resources.js";
|
|
10
11
|
export class TerminalTargetInput {
|
|
@@ -21,7 +22,7 @@ export class TerminalTargetInput {
|
|
|
21
22
|
explanation;
|
|
22
23
|
constructor(terminalId, explanation) {
|
|
23
24
|
ArgumentValidator.requireIdentifier(Resources.terminalIdField, terminalId);
|
|
24
|
-
if (explanation
|
|
25
|
+
if (!Object.isNull(explanation))
|
|
25
26
|
ArgumentValidator.requireMaximumLength(Resources.explanationField, explanation, Resources.maximumExplanationLength);
|
|
26
27
|
this.terminalId = terminalId;
|
|
27
28
|
this.explanation = explanation;
|
|
@@ -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 { ArgumentValidator, ProtocolReader, Resources as ProtocolResources } from "@noldova/terminal.protocol";
|
|
9
10
|
import { Resources } from "../../resources.js";
|
|
10
11
|
import { KeySequence } from "./key-sequence.js";
|
|
@@ -24,7 +25,7 @@ export class TerminalWriteInput {
|
|
|
24
25
|
explanation;
|
|
25
26
|
constructor(terminalId, keys, explanation) {
|
|
26
27
|
ArgumentValidator.requireIdentifier(Resources.terminalIdField, terminalId);
|
|
27
|
-
if (explanation
|
|
28
|
+
if (!Object.isNull(explanation))
|
|
28
29
|
ArgumentValidator.requireMaximumLength(Resources.explanationField, explanation, Resources.maximumExplanationLength);
|
|
29
30
|
this.terminalId = terminalId;
|
|
30
31
|
this.keys = keys;
|