@noldova/terminal 0.0.7 → 0.0.9

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.
Files changed (80) hide show
  1. package/README.md +1 -1
  2. package/module.json +2 -2
  3. package/package.json +10 -8
  4. package/src/exceptions/stored-lines-damaged.exception.js +2 -1
  5. package/src/models/hosted-terminal.js +4 -3
  6. package/src/models/integration-script.js +15 -0
  7. package/src/models/mark-introducer.js +15 -0
  8. package/src/models/mark-terminator.js +15 -0
  9. package/src/models/mirror-line.js +2 -1
  10. package/src/models/one-shot-launch.js +2 -1
  11. package/src/models/output-span.js +15 -0
  12. package/src/models/shell-candidate.js +21 -0
  13. package/src/models/shell-mark.js +2 -1
  14. package/src/models/taken-segment.js +15 -0
  15. package/src/models/terminal-folder-key.js +15 -0
  16. package/src/models/terminal-opening.js +2 -1
  17. package/src/models/tracked-command.js +2 -1
  18. package/src/models/typed-line.js +2 -1
  19. package/src/models/wsl-launcher.js +15 -0
  20. package/src/resources.js +7 -3
  21. package/src/runtime-part.js +2 -1
  22. package/src/services/agent-terminal.js +4 -3
  23. package/src/services/agent-terminals.js +3 -2
  24. package/src/services/bounded-reads.js +7 -5
  25. package/src/services/change-signal.js +5 -4
  26. package/src/services/command-tracker.js +5 -4
  27. package/src/services/completion-source.js +27 -23
  28. package/src/services/context-pty-process.js +3 -2
  29. package/src/services/context-pty-spawner.js +2 -1
  30. package/src/services/deferred-pty-process.js +7 -8
  31. package/src/services/escape-sequence-tracker.js +2 -1
  32. package/src/services/failure-text.js +2 -1
  33. package/src/services/flow-controller.js +5 -4
  34. package/src/services/latest-environment.js +2 -1
  35. package/src/services/mac-environment.js +3 -2
  36. package/src/services/mark-scanner.js +22 -14
  37. package/src/services/one-shot-command.js +3 -2
  38. package/src/services/output-batcher.js +2 -1
  39. package/src/services/output-log.js +4 -1
  40. package/src/services/powershell-binding.js +7 -6
  41. package/src/services/pseudo-terminal.js +2 -1
  42. package/src/services/registry-export.js +3 -2
  43. package/src/services/resize-wakeup.js +2 -1
  44. package/src/services/saved-terminals.js +2 -1
  45. package/src/services/shared-reads.js +3 -2
  46. package/src/services/shell-command.js +14 -15
  47. package/src/services/shell-integration.js +24 -22
  48. package/src/services/shell-locator.js +25 -22
  49. package/src/services/shell-words.js +3 -2
  50. package/src/services/system-requirements.js +9 -9
  51. package/src/services/terminal-audience.js +10 -9
  52. package/src/services/terminal-history-folder.js +5 -4
  53. package/src/services/terminal-history-segment.js +2 -1
  54. package/src/services/terminal-history.js +14 -12
  55. package/src/services/terminal-host.js +106 -103
  56. package/src/services/terminal-line-reader.js +3 -2
  57. package/src/services/terminal-mirror.js +13 -12
  58. package/src/services/terminal-session.js +21 -21
  59. package/src/services/visual-studio.reader.js +3 -2
  60. package/src/services/windows-environment.js +12 -11
  61. package/src/services/windows-folder-access.js +2 -1
  62. package/src/services/wsl-distribution.reader.js +2 -1
  63. package/src/tools/models/agent-terminal-opening.js +2 -1
  64. package/src/tools/models/output-chunk.js +4 -1
  65. package/src/tools/models/output-excerpt.js +12 -6
  66. package/src/tools/models/terminal-open-input.js +3 -2
  67. package/src/tools/models/terminal-output-report.js +5 -4
  68. package/src/tools/models/terminal-run-input.js +2 -1
  69. package/src/tools/models/terminal-target-input.js +2 -1
  70. package/src/tools/models/terminal-write-input.js +2 -1
  71. package/src/tools/models/tool-call-context.js +4 -3
  72. package/src/tools/services/permission-details.js +3 -2
  73. package/src/tools/services/permission-gate.js +2 -1
  74. package/src/tools/services/terminal-access-policy.js +8 -7
  75. package/src/tools/services/terminal-interrupt-tool.js +2 -1
  76. package/src/tools/services/terminal-read-tool.js +3 -2
  77. package/src/tools/services/terminal-run-tool.js +6 -5
  78. package/src/tools/services/terminal-text-escaper.js +2 -1
  79. package/src/tools/services/terminal-tool.js +2 -1
  80. 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 === undefined || cell.getWidth() === 0)
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 !== undefined && ((cell.getCode() === 0 && cell.isAttributeDefault()) || (cell.getChars().trim().length === 0 && cell.isBgDefault() &&
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 !== undefined && !start.isDisposed && buffer.baseY + buffer.cursorY === start.line)
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 === null ? cursor : at.index;
97
- const marker = index === null || this.terminal.buffer.active.type !== Resources.normalBufferType ? undefined
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 !== undefined) {
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 === undefined || start.isDisposed)
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 !== undefined; index++) {
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 !== null && column > this.inputColumn && line.translateToString(false, column - 1, column).trim().length === 0 ? column : undefined;
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 === undefined || start.isDisposed || buffer.type !== Resources.normalBufferType || start.line > cursor)
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 !== undefined; number++) {
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 !== undefined; y++) {
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 !== null)
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 !== null && line !== undefined)
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 === null ? null : new MarkScanner(nonce);
64
- this.hasIntegration = nonce !== null;
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 !== null && shellKind === TerminalShellKind.Bash ? new ResizeWakeup(t => this.terminal.write(t)) : null;
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 !== null;
132
+ return !Object.isNull(this.exit);
132
133
  }
133
134
  get receivedLength() {
134
135
  return this.receivedOffset;
@@ -156,8 +157,8 @@ 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 !== null
160
- || this.exit !== null)
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);
@@ -173,29 +174,28 @@ export class TerminalSession {
173
174
  }
174
175
  readPromptLine() {
175
176
  const promptEnd = this.commands.promptEndOffset;
176
- if (promptEnd === null || this.commands.runningCommand !== null)
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
  }
180
181
  resize(size) {
181
182
  if (size.equals(this.size))
182
- return false;
183
+ return;
183
184
  this.size = size;
184
185
  this.terminal.resize(size);
185
186
  this.watchResize();
186
187
  this.mirror.resize(size);
187
- return true;
188
188
  }
189
189
  async attachAsync(paneId, commands) {
190
190
  const snapshot = await this.mirror.snapshotAsync();
191
191
  this.flow.attach(paneId, snapshot.offset);
192
- if (this.exit === null)
192
+ if (Object.isNull(this.exit))
193
193
  this.redraw();
194
194
  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
195
  }
196
196
  anchorRunAsync() {
197
197
  const prompt = this.promptLine;
198
- return prompt === null ? this.mirror.anchorAsync(null) : prompt.then(t => this.mirror.anchorAsync(t));
198
+ return Object.isNull(prompt) ? this.mirror.anchorAsync(null) : prompt.then(t => this.mirror.anchorAsync(t));
199
199
  }
200
200
  readRunLinesAsync(start, end, maximum) {
201
201
  return this.mirror.readLinesAsync(start, end, maximum);
@@ -224,8 +224,8 @@ export class TerminalSession {
224
224
  this.terminal = this.startTerminal(process);
225
225
  if (this.flow.isPaused)
226
226
  this.terminal.pause();
227
- this.scanner = nonce === null ? null : new MarkScanner(nonce);
228
- this.hasIntegration = nonce !== null;
227
+ this.scanner = Object.isNull(nonce) ? null : new MarkScanner(nonce);
228
+ this.hasIntegration = !Object.isNull(nonce);
229
229
  this.commands = this.trackCommands();
230
230
  this.options.reset();
231
231
  this.hasAnsweredOptions = false;
@@ -260,7 +260,7 @@ export class TerminalSession {
260
260
  const marks = this.scanner?.scan(data, this.receivedOffset) ?? [];
261
261
  this.batcher.append(data, marks.flatMap(t => {
262
262
  const edge = this.readInputEdge(t);
263
- return edge === null ? [] : [new TerminalInputMark(t.offset - this.receivedOffset, edge)];
263
+ return Object.isNull(edge) ? [] : [new TerminalInputMark(t.offset - this.receivedOffset, edge)];
264
264
  }));
265
265
  this.flow.produce(data.length);
266
266
  let position = 0;
@@ -270,7 +270,7 @@ export class TerminalSession {
270
270
  this.text.append(data.slice(position, end));
271
271
  position = end;
272
272
  const edge = this.readInputEdge(mark);
273
- if (mark.kind === MarkKind.PromptStart || edge !== null) {
273
+ if (mark.kind === MarkKind.PromptStart || !Object.isNull(edge)) {
274
274
  this.mirror.write(data.slice(mirrored, end));
275
275
  mirrored = end;
276
276
  }
@@ -322,12 +322,12 @@ export class TerminalSession {
322
322
  this.settleTypedLines(mark);
323
323
  if (mark.kind === MarkKind.CommandEnd) {
324
324
  const exitCode = this.commands.lastCommand?.exitCode ?? null;
325
- this.listener.onCommandEnded(new TerminalCommandEnded(this.sessionId, exitCode !== null && exitCode >= ProtocolResources.minimumExitCode && exitCode <= ProtocolResources.maximumExitCode ? exitCode : null));
325
+ this.listener.onCommandEnded(new TerminalCommandEnded(this.sessionId, !Object.isNull(exitCode) && exitCode >= ProtocolResources.minimumExitCode && exitCode <= ProtocolResources.maximumExitCode ? exitCode : null));
326
326
  }
327
327
  else if (mark.kind === MarkKind.PromptStart)
328
328
  this.listener.onPromptStarted(new TerminalReference(this.sessionId));
329
329
  const cwd = this.commands.cwd;
330
- if (cwd === null || cwd === this.reportedCwd || cwd.trim().length === 0 || cwd.length > ProtocolResources.maximumPathLength)
330
+ if (Object.isNull(cwd) || cwd === this.reportedCwd || cwd.trim().length === 0 || cwd.length > ProtocolResources.maximumPathLength)
331
331
  return;
332
332
  this.reportedCwd = cwd;
333
333
  this.listener.onCwdChanged(new TerminalCwd(this.sessionId, cwd));
@@ -336,7 +336,7 @@ export class TerminalSession {
336
336
  const command = mark.kind === MarkKind.OutputStart ? this.commands.runningCommand
337
337
  : mark.kind === MarkKind.CommandEnd ? this.commands.lastCommand : null;
338
338
  for (const line of this.typedLines) {
339
- if (command !== null)
339
+ if (!Object.isNull(command))
340
340
  line.command = command;
341
341
  else if (mark.kind === MarkKind.PromptStart)
342
342
  line.prompt(mark.offset);
@@ -359,7 +359,7 @@ export class TerminalSession {
359
359
  if (this.terminal === terminal)
360
360
  this.wakeup?.beforeInput();
361
361
  }
362
- }, this.windowsPty !== null);
362
+ }, !Object.isNull(this.windowsPty));
363
363
  return terminal;
364
364
  }
365
365
  end(exitCode) {
@@ -371,7 +371,7 @@ export class TerminalSession {
371
371
  this.changes.notify();
372
372
  }
373
373
  redraw() {
374
- if (this.size.rows < 2)
374
+ if (this.size.rows < 2 || Object.isNull(this.terminal.pid))
375
375
  return;
376
376
  this.terminal.resize(new TerminalSize(this.size.columns, this.size.rows - 1));
377
377
  this.terminal.resize(this.size);
@@ -389,7 +389,7 @@ export class TerminalSession {
389
389
  }
390
390
  endInput(startsCommand, command) {
391
391
  void this.mirror.endInput().then(t => {
392
- if (startsCommand && t !== null)
392
+ if (startsCommand && !Object.isNull(t))
393
393
  this.listener.onCommandStarted(TerminalSession.toCommand(command) ?? t);
394
394
  }).catch((error) => this.listener.onFailed(this.sessionId, FailureText.read(error)));
395
395
  }
@@ -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 === undefined || programFilesX86.length === 0 ? null : path.win32.join(programFilesX86, ...Resources.vswherePath);
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 === null || !await this.fileSystem.isFileAsync(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 === undefined || systemRoot.length === 0 ? null : path.win32.join(systemRoot, ...Resources.regPath);
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 === null) {
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 === null)
60
+ if (Object.isNull(reg))
60
61
  throw new SystemRootMissingException();
61
62
  const folder = await this.prepareFolderAsync();
62
- if (folder === null || this.ended)
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 === null || await this.tools.reader.isFolderAsync(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 === null)
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 === null)
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 !== null)
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 !== undefined)
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 !== undefined && userPath !== undefined)
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 === undefined) {
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 === undefined || this.systemRoot.length === 0)
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 === undefined || name.length === 0 || !Resources.base64Pattern.test(name) || rest.length > 0 ||
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 !== null)
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
- constructor(text, endOffset) {
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 = 0;
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
- this.omittedCharacters = output.length - head.length - tail.length;
23
- this.text = head + Resources.formatOmittedCharacters(this.omittedCharacters) + tail;
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 !== null)
23
+ if (!Object.isNull(shellId))
23
24
  ArgumentValidator.requireIdentifier(Resources.shellField, shellId);
24
- if (explanation !== null)
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 === null ? null : this.command.status;
48
- const exitCode = this.command === null ? null : this.command.exitCode;
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 === null ? null : this.command.method,
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 === null ? null : this.command.logFile,
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 !== null)
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 !== null)
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 !== null)
28
+ if (!Object.isNull(explanation))
28
29
  ArgumentValidator.requireMaximumLength(Resources.explanationField, explanation, Resources.maximumExplanationLength);
29
30
  this.terminalId = terminalId;
30
31
  this.keys = keys;
@@ -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, relative, sep } from "node:path";
9
10
  import { ArgumentException } from "@noldova/context.exceptions";
10
11
  import { ArgumentValidator, ProtocolReader, Resources as ProtocolResources } from "@noldova/terminal.protocol";
@@ -21,17 +22,17 @@ export class ToolCallContext {
21
22
  if (!isAbsolute(folder))
22
23
  throw new ArgumentException(Resources.formatNotAbsolutePath(ProtocolResources.valueSubject), Resources.folderBinding);
23
24
  const shared = new Map(Object.entries(call.bindings)).get(Resources.sharedBinding);
24
- if (shared !== undefined && !Array.isArray(shared))
25
+ if (!Object.isUndefined(shared) && !Array.isArray(shared))
25
26
  throw new ArgumentException(Resources.formatBindingNotList(ProtocolResources.valueSubject), Resources.sharedBinding);
26
27
  const boundTerminalIds = [];
27
28
  for (const terminalId of shared ?? []) {
28
- if (typeof terminalId !== "string")
29
+ if (!Object.isString(terminalId))
29
30
  throw new ArgumentException(Resources.formatBindingNotList(ProtocolResources.valueSubject), Resources.sharedBinding);
30
31
  ArgumentValidator.requireIdentifier(Resources.sharedBinding, terminalId);
31
32
  boundTerminalIds.push(terminalId);
32
33
  }
33
34
  const owner = reader.readOptionalString(Resources.ownerBinding, ProtocolResources.maximumOwnerLength);
34
- if (owner !== undefined)
35
+ if (!Object.isUndefined(owner))
35
36
  ArgumentValidator.requireNonBlank(Resources.ownerBinding, owner, ProtocolResources.maximumOwnerLength);
36
37
  this.call = call;
37
38
  this.agentSessionId = call.session;