@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 path from "node:path";
9
10
  import { Resources as ProtocolResources, TerminalCompletion, TerminalCompletionItem, TerminalCompletionKind, TerminalMissingCommands, TerminalShellKind } from "@noldova/terminal.protocol";
10
11
  import { CommandFailedException } from "../exceptions/command-failed.exception.js";
@@ -70,13 +71,13 @@ export class CompletionSource {
70
71
  return new TerminalCompletion(completion.replaceFrom, items.slice(0, ProtocolResources.maximumCompletionItems));
71
72
  }
72
73
  async findMissingAsync(key, shell, prompt, kind, folder, names, shellNames, environment) {
73
- if (kind === TerminalShellKind.PowerShell || !Resources.completedShellKinds.includes(kind) || shellNames === null || this.stuck.includes(key))
74
+ if (kind === TerminalShellKind.PowerShell || !Resources.completedShellKinds.includes(kind) || Object.isNull(shellNames) || this.stuck.includes(key))
74
75
  return new TerminalMissingCommands([]);
75
76
  const takesBareNames = this.isWindows && kind === TerminalShellKind.Bash;
76
77
  const search = JSON.stringify([kind, this.readVariable(environment, Resources.pathVariable),
77
78
  this.readVariable(environment, Resources.pathExtensionsVariable)]);
78
79
  const last = this.listed.get(shell);
79
- const listed = last !== undefined && last.prompt === prompt && last.search === search ? last.commands : null;
80
+ const listed = !Object.isUndefined(last) && last.prompt === prompt && last.search === search ? last.commands : null;
80
81
  return this.readAsync(key, async (reads) => {
81
82
  const commands = listed ?? (await this.listCommandsAsync(reads, [], environment, takesBareNames)).map(t => t.value);
82
83
  if (reads.wasCutShort)
@@ -92,7 +93,7 @@ export class CompletionSource {
92
93
  });
93
94
  }
94
95
  async findMissingPowerShellAsync(shell, program, names, shellNames, environment) {
95
- if (shellNames === null) {
96
+ if (Object.isNull(shellNames)) {
96
97
  const reason = shell.isPathReset ? Resources.powerShellLookupPathReset : shell.isModulePathReset ? Resources.powerShellLookupModulePathReset
97
98
  : shell.isNamesReset ? Resources.powerShellLookupNamesTooLong : Resources.powerShellLookupNamesUnreported;
98
99
  if (this.skipped.get(shell) !== reason)
@@ -104,11 +105,11 @@ export class CompletionSource {
104
105
  const variables = await this.toLongModulePathsAsync(Object.fromEntries([Resources.pathVariable,
105
106
  Resources.pathExtensionsVariable, Resources.modulePathVariable].flatMap(t => {
106
107
  const value = this.readVariable(environment, this.isWindows ? t.toUpperCase() : t);
107
- return value === undefined ? [] : [[t, value]];
108
+ return Object.isUndefined(value) ? [] : [[t, value]];
108
109
  })));
109
110
  const search = JSON.stringify([program, variables]);
110
111
  const last = this.looked.get(shell);
111
- const answers = last !== undefined && last.shellNames === shellNames && last.search === search ? last.answers : new Map();
112
+ const answers = !Object.isUndefined(last) && last.shellNames === shellNames && last.search === search ? last.answers : new Map();
112
113
  this.looked.set(shell, new PowerShellLookup(shellNames, search, answers));
113
114
  const known = new Set([...shellNames].map(t => t.toLowerCase()));
114
115
  const asked = [...new Set(names)].filter(t => !this.isPath(t) && Resources.powerShellLookupNamePattern.test(t)
@@ -142,7 +143,7 @@ export class CompletionSource {
142
143
  }
143
144
  async dropFoldersAsync(reads, kind, folder, environment, names) {
144
145
  const workFolder = this.toLocalFolder(folder, kind, environment);
145
- if (workFolder === null)
146
+ if (Object.isNull(workFolder))
146
147
  return names;
147
148
  const folders = new Set((await reads.readEntriesAsync(workFolder)).filter(t => t.isFolder)
148
149
  .map(t => this.isWindows ? t.name.toLowerCase() : t.name));
@@ -176,9 +177,12 @@ export class CompletionSource {
176
177
  .filter(t => (ignoresCase ? t.value.toLowerCase() : t.value).startsWith(prefix));
177
178
  const items = [...new Map(candidates.map(t => [t.value, t])).values()]
178
179
  .sort((a, b) => a.label.localeCompare(b.label, Resources.sortLocale))
179
- .map((t) => [ShellWords.write(t.value, shellLine.quote, isPowerShell, t.closesQuote, escapesWildcards && (t.kind === TerminalCompletionKind.File || t.kind === TerminalCompletionKind.Folder), keepsHome), t])
180
- .filter(([t]) => t.length <= ProtocolResources.maximumPathLength && !ProtocolResources.controlCharacters.test(t))
181
- .map(([text, t]) => new TerminalCompletionItem(text, t.label, t.kind));
180
+ .flatMap(t => {
181
+ const text = ShellWords.write(t.value, shellLine.quote, isPowerShell, t.closesQuote, escapesWildcards && (t.kind === TerminalCompletionKind.File || t.kind === TerminalCompletionKind.Folder), keepsHome);
182
+ return text.length <= ProtocolResources.maximumPathLength && !ProtocolResources.controlCharacters.test(text)
183
+ ? [new TerminalCompletionItem(text, t.label, t.kind)]
184
+ : [];
185
+ });
182
186
  return new TerminalCompletion(shellLine.start, items.slice(0, ProtocolResources.maximumCompletionItems));
183
187
  }
184
188
  listAsync(reads, kind, builtins, shellLine, folder, environment, expandsHome) {
@@ -187,17 +191,17 @@ export class CompletionSource {
187
191
  return this.listCommandsAsync(reads, builtins, environment);
188
192
  const temporaryFolder = this.readVariable(environment, Resources.temporaryFolderVariable) ?? null;
189
193
  const workFolder = this.toLocalPath(folder, kind, temporaryFolder);
190
- if (workFolder !== null && words.length === Resources.subcommandWordCount && words[0] === Resources.gitCommand && Resources.gitBranchCommands.some(t => shellLine.words[1] === t))
194
+ if (!Object.isNull(workFolder) && words.length === Resources.subcommandWordCount && words[0] === Resources.gitCommand && Resources.gitBranchCommands.some(t => shellLine.words[1] === t))
191
195
  return this.listBranchesAsync(reads, workFolder, environment);
192
- if (workFolder !== null && words.length === Resources.subcommandWordCount && words[0] === Resources.npmCommand && Resources.npmRunCommands.some(t => shellLine.words[1] === t))
196
+ if (!Object.isNull(workFolder) && words.length === Resources.subcommandWordCount && words[0] === Resources.npmCommand && Resources.npmRunCommands.some(t => shellLine.words[1] === t))
193
197
  return this.listScriptsAsync(reads, workFolder);
194
198
  return this.listPathsAsync(reads, kind, shellLine.value, workFolder, expandsHome, temporaryFolder);
195
199
  }
196
200
  async listPathsAsync(reads, kind, value, workFolder, expandsHome, temporaryFolder) {
197
201
  const end = Math.max(value.lastIndexOf(Resources.posixSeparator), this.isWindows ? value.lastIndexOf(Resources.windowsSeparator) : -1);
198
202
  const typedFolder = value.slice(0, end + 1);
199
- const folder = workFolder === null ? null : this.toFolder(kind, typedFolder, workFolder, expandsHome, temporaryFolder);
200
- if (folder === null)
203
+ const folder = Object.isNull(workFolder) ? null : this.toFolder(kind, typedFolder, workFolder, expandsHome, temporaryFolder);
204
+ if (Object.isNull(folder))
201
205
  return [];
202
206
  const separator = end >= 0 ? value.charAt(end)
203
207
  : this.isWindows && kind === TerminalShellKind.PowerShell ? Resources.windowsSeparator : Resources.posixSeparator;
@@ -217,14 +221,14 @@ export class CompletionSource {
217
221
  const names = [...builtins];
218
222
  for (const entry of entries.flat()) {
219
223
  const extension = this.paths.extname(entry.name).toLowerCase();
220
- if (!entry.isFolder && (extensions === null || extensions.includes(extension) || takesBareNames && extension === ""))
221
- names.push(extensions === null ? entry.name : entry.name.slice(0, entry.name.length - extension.length));
224
+ if (!entry.isFolder && (Object.isNull(extensions) || extensions.includes(extension) || takesBareNames && extension === ""))
225
+ names.push(Object.isNull(extensions) ? entry.name : entry.name.slice(0, entry.name.length - extension.length));
222
226
  }
223
227
  return names.map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Command, true));
224
228
  }
225
229
  async listBranchesAsync(reads, folder, environment) {
226
230
  const git = await this.findProgramAsync(reads, this.isWindows ? Resources.gitExecutableFile : Resources.gitCommand, environment);
227
- if (git === null)
231
+ if (Object.isNull(git))
228
232
  return [];
229
233
  let output;
230
234
  try {
@@ -245,11 +249,11 @@ export class CompletionSource {
245
249
  async listScriptsAsync(reads, folder) {
246
250
  let current = folder;
247
251
  let text = await reads.readTextOrNullAsync(this.paths.join(current, Resources.packageFile));
248
- while (text === null && this.paths.dirname(current) !== current) {
252
+ while (Object.isNull(text) && this.paths.dirname(current) !== current) {
249
253
  current = this.paths.dirname(current);
250
254
  text = await reads.readTextOrNullAsync(this.paths.join(current, Resources.packageFile));
251
255
  }
252
- if (text === null)
256
+ if (Object.isNull(text))
253
257
  return [];
254
258
  let parsed;
255
259
  try {
@@ -260,10 +264,10 @@ export class CompletionSource {
260
264
  throw error;
261
265
  return [];
262
266
  }
263
- if (typeof parsed !== "object" || parsed === null || !(Resources.packageScriptsField in parsed))
267
+ if (!Object.isObject(parsed) || !(Resources.packageScriptsField in parsed))
264
268
  return [];
265
269
  const scripts = parsed[Resources.packageScriptsField];
266
- if (typeof scripts !== "object" || scripts === null || Array.isArray(scripts))
270
+ if (!Object.isObject(scripts) || Array.isArray(scripts))
267
271
  return [];
268
272
  return Object.keys(scripts).map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Script, true));
269
273
  }
@@ -280,7 +284,7 @@ export class CompletionSource {
280
284
  }
281
285
  async toLongModulePathsAsync(variables) {
282
286
  const modulePath = variables[Resources.modulePathVariable];
283
- if (!this.isWindows || modulePath === undefined || !modulePath.includes(Resources.shortNameMark))
287
+ if (!this.isWindows || Object.isUndefined(modulePath) || !modulePath.includes(Resources.shortNameMark))
284
288
  return variables;
285
289
  const reads = new BoundedReads(this.shared, Resources.completionReadMilliseconds);
286
290
  try {
@@ -297,13 +301,13 @@ export class CompletionSource {
297
301
  }
298
302
  toFolder(kind, typedFolder, workFolder, expandsHome, temporaryFolder) {
299
303
  const folder = expandsHome && this.isHome(typedFolder) ? this.paths.join(this.homeFolder, typedFolder.slice(Resources.homePrefix.length)) : this.toLocalPath(typedFolder, kind, temporaryFolder);
300
- return folder === null ? null : this.paths.resolve(workFolder, folder);
304
+ return Object.isNull(folder) ? null : this.paths.resolve(workFolder, folder);
301
305
  }
302
306
  toLocalPath(value, kind, temporaryFolder) {
303
307
  if (!this.isWindows || kind !== TerminalShellKind.Bash || !value.startsWith(Resources.posixSeparator))
304
308
  return value;
305
309
  const temporary = Resources.gitBashTemporaryFolder;
306
- if (temporaryFolder !== null && path.win32.isAbsolute(temporaryFolder)
310
+ if (!Object.isNull(temporaryFolder) && path.win32.isAbsolute(temporaryFolder)
307
311
  && (value === temporary || value.startsWith(`${temporary}${Resources.posixSeparator}`)))
308
312
  return path.win32.join(temporaryFolder, value.slice(temporary.length));
309
313
  if (!Resources.gitBashDrivePath.test(value))
@@ -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 { constants } from "node:os";
9
10
  export class ContextPtyProcess {
10
11
  terminal;
@@ -28,7 +29,7 @@ export class ContextPtyProcess {
28
29
  isHolding = false;
29
30
  else
30
31
  queueMicrotask(() => {
31
- for (let text = early.shift(); text !== undefined; text = early.shift())
32
+ for (let text = early.shift(); !Object.isUndefined(text); text = early.shift())
32
33
  if (isListening)
33
34
  try {
34
35
  listener(text);
@@ -74,6 +75,6 @@ export class ContextPtyProcess {
74
75
  return this.terminal.stopAsync();
75
76
  }
76
77
  static toEvent(exit) {
77
- return exit.signal === null ? { exitCode: exit.code ?? undefined } : { exitCode: undefined, signal: constants.signals[exit.signal] };
78
+ return Object.isNull(exit.signal) ? { exitCode: exit.code ?? undefined } : { exitCode: undefined, signal: constants.signals[exit.signal] };
78
79
  }
79
80
  }
@@ -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 { PseudoTerminalRequest } from "@noldova/desktop.runtime";
9
10
  import { ContextPtyProcess } from "./context-pty-process.js";
10
11
  export class ContextPtySpawner {
@@ -17,7 +18,7 @@ export class ContextPtySpawner {
17
18
  async spawnAsync(file, args, folder, columns, rows, environment, inheritCursor) {
18
19
  this.library ??= import("node-pty");
19
20
  const library = await this.library;
20
- const request = typeof args === "string"
21
+ const request = Object.isString(args)
21
22
  ? new PseudoTerminalRequest(library, file, [], folder, columns, rows, environment, { inheritCursor, commandLine: args })
22
23
  : new PseudoTerminalRequest(library, file, args, folder, columns, rows, environment, { inheritCursor });
23
24
  const terminal = await this.context.startPseudoTerminalAsync(request);
@@ -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 DeferredPtyProcess {
9
10
  dataListeners = new Set();
10
11
  exitListeners = new Set();
@@ -24,7 +25,7 @@ export class DeferredPtyProcess {
24
25
  this.starting = undefined;
25
26
  }
26
27
  get hasStarted() {
27
- return this.starting !== undefined;
28
+ return !Object.isUndefined(this.starting);
28
29
  }
29
30
  get pid() {
30
31
  return this.process?.pid ?? null;
@@ -43,10 +44,7 @@ export class DeferredPtyProcess {
43
44
  resize(columns, rows) {
44
45
  this.columns = columns;
45
46
  this.rows = rows;
46
- if (this.process === undefined)
47
- this.start();
48
- else
49
- this.process.resize(columns, rows);
47
+ this.process?.resize(columns, rows);
50
48
  }
51
49
  pause() {
52
50
  this.isPaused = true;
@@ -62,15 +60,16 @@ export class DeferredPtyProcess {
62
60
  async endAsync() {
63
61
  this.isEnded = true;
64
62
  await this.starting;
65
- if (this.process !== undefined)
63
+ if (!Object.isUndefined(this.process))
66
64
  return this.process.endAsync();
67
65
  this.exit({ exitCode: undefined });
68
66
  return true;
69
67
  }
70
68
  start() {
71
- if (this.starting !== undefined || this.isEnded)
69
+ if (!Object.isUndefined(this.starting) || this.isEnded)
72
70
  return;
73
- const [columns, rows] = [this.columns, this.rows];
71
+ const columns = this.columns;
72
+ const rows = this.rows;
74
73
  this.starting = this.startProcessAsync(columns, rows).then(process => {
75
74
  process.onData(t => {
76
75
  for (const listener of this.dataListeners)
@@ -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 { EscapeState } from "../enums/escape-state.js";
9
10
  import { Resources } from "../resources.js";
10
11
  export class EscapeSequenceTracker {
@@ -34,7 +35,7 @@ export class EscapeSequenceTracker {
34
35
  }
35
36
  findNext(data, start) {
36
37
  const search = EscapeSequenceTracker.searchOf(this.state);
37
- if (search === null)
38
+ if (Object.isNull(search))
38
39
  return start;
39
40
  search.lastIndex = start;
40
41
  return search.exec(data)?.index ?? data.length;
@@ -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 { Resources } from "../resources.js";
9
10
  export class FailureText {
10
11
  static read(error) {
11
12
  if (!(error instanceof Error))
12
13
  return String(error);
13
- return error.cause === undefined ? error.message : Resources.formatFailureWithCause(error.message, FailureText.read(error.cause));
14
+ return Object.isUndefined(error.cause) ? error.message : Resources.formatFailureWithCause(error.message, FailureText.read(error.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 { PaneProgress } from "../models/pane-progress.js";
9
10
  import { Resources } from "../resources.js";
10
11
  export class FlowController {
@@ -40,21 +41,21 @@ export class FlowController {
40
41
  }
41
42
  acknowledge(paneId, offset) {
42
43
  const pane = this.panes.get(paneId);
43
- if (pane === undefined)
44
+ if (Object.isUndefined(pane))
44
45
  return;
45
46
  pane.offset = Math.max(pane.offset, Math.min(offset, this.producedOffset));
46
47
  this.update();
47
48
  }
48
49
  setVisible(paneId, isVisible) {
49
50
  const pane = this.panes.get(paneId);
50
- if (pane === undefined)
51
+ if (Object.isUndefined(pane))
51
52
  return;
52
53
  pane.isVisible = isVisible;
53
54
  this.update();
54
55
  }
55
56
  detach(paneId) {
56
57
  const pane = this.panes.get(paneId);
57
- if (pane === undefined)
58
+ if (Object.isUndefined(pane))
58
59
  return false;
59
60
  FlowController.stopStallTimer(pane);
60
61
  this.panes.delete(paneId);
@@ -94,7 +95,7 @@ export class FlowController {
94
95
  this.listener.onStalled(paneId);
95
96
  }
96
97
  static stopStallTimer(pane) {
97
- if (pane.stallTimer === null)
98
+ if (Object.isNull(pane.stallTimer))
98
99
  return;
99
100
  clearTimeout(pane.stallTimer);
100
101
  pane.stallTimer = 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
  export class LatestEnvironment {
9
10
  source;
10
11
  inherited;
@@ -17,7 +18,7 @@ export class LatestEnvironment {
17
18
  }
18
19
  async readAsync() {
19
20
  const environment = await this.source.readAsync();
20
- if (environment === null)
21
+ if (Object.isNull(environment))
21
22
  return this.inherited;
22
23
  this.latest = environment;
23
24
  return environment;
@@ -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 { posix } from "node:path";
9
10
  import { Resources } from "../resources.js";
10
11
  import { FileSystemReader } from "./file-system.reader.js";
@@ -63,8 +64,8 @@ export class MacEnvironment {
63
64
  }
64
65
  async withUtf8LocaleAsync(locale) {
65
66
  const maximized = new Intl.Locale(locale).maximize();
66
- const name = maximized.region === undefined ? null : Resources.formatUtf8Locale(maximized.language, maximized.region);
67
- return name !== null && await this.hasLocaleAsync(name)
67
+ const name = Object.isUndefined(maximized.region) ? null : Resources.formatUtf8Locale(maximized.language, maximized.region);
68
+ return !Object.isNull(name) && await this.hasLocaleAsync(name)
68
69
  ? { ...this.environment, [Resources.languageVariable]: name }
69
70
  : { ...this.environment, [Resources.characterTypeVariable]: Resources.utf8Locale };
70
71
  }
@@ -5,7 +5,10 @@
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 { MarkKind } from "../enums/mark-kind.js";
10
+ import { MarkIntroducer } from "../models/mark-introducer.js";
11
+ import { MarkTerminator } from "../models/mark-terminator.js";
9
12
  import { ShellMark } from "../models/shell-mark.js";
10
13
  import { Resources } from "../resources.js";
11
14
  const INTRODUCERS = [Resources.markIntroducer, Resources.eightBitMarkIntroducer];
@@ -25,13 +28,16 @@ export class MarkScanner {
25
28
  this.carry = "";
26
29
  let index = 0;
27
30
  while (index < text.length) {
28
- const [start, introducer] = MarkScanner.findIntroducer(text, index);
31
+ const introducer = MarkScanner.findIntroducer(text, index);
32
+ const start = introducer.start;
29
33
  if (start < 0) {
30
34
  this.carry = MarkScanner.toIntroducerPrefix(text, index);
31
35
  break;
32
36
  }
33
- const payloadStart = start + introducer.length;
34
- const [payloadEnd, end] = MarkScanner.findTerminator(text, payloadStart);
37
+ const payloadStart = start + introducer.text.length;
38
+ const terminator = MarkScanner.findTerminator(text, payloadStart);
39
+ const payloadEnd = terminator.payloadEnd;
40
+ const end = terminator.end;
35
41
  if (payloadEnd < 0) {
36
42
  this.carry = text.length - start <= Resources.maximumMarkLength ? text.slice(start) : MarkScanner.toIntroducerPrefix(text, payloadStart);
37
43
  break;
@@ -45,7 +51,7 @@ export class MarkScanner {
45
51
  continue;
46
52
  }
47
53
  const mark = this.parse(text.slice(payloadStart, payloadEnd), textOffset + end);
48
- if (mark !== null)
54
+ if (!Object.isNull(mark))
49
55
  marks.push(mark);
50
56
  index = end;
51
57
  }
@@ -54,7 +60,7 @@ export class MarkScanner {
54
60
  parse(payload, offset) {
55
61
  const [kindText, nonce, ...values] = payload.replace(Resources.markScannerIgnoredControl, "").split(Resources.markScannerFieldSeparator);
56
62
  const kind = Resources.markKindLetters.get(String(kindText));
57
- if (kind === undefined || nonce !== this.nonce)
63
+ if (Object.isUndefined(kind) || nonce !== this.nonce)
58
64
  return null;
59
65
  const fields = values.map(t => t.replace(Resources.markScannerEscapedCharacter, (_, code) => String.fromCharCode(Number.parseInt(code, Resources.hexadecimalRadix))));
60
66
  return new ShellMark(kind, fields.length === 0 ? null : fields.join(Resources.markScannerFieldSeparator), offset, fields);
@@ -62,24 +68,26 @@ export class MarkScanner {
62
68
  static findTerminator(text, from) {
63
69
  for (let index = from; index < text.length; index++) {
64
70
  const terminator = TERMINATORS.find(t => text.startsWith(t, index));
65
- if (terminator !== undefined)
66
- return [index, index + terminator.length];
71
+ if (!Object.isUndefined(terminator))
72
+ return new MarkTerminator(index, index + terminator.length);
67
73
  if (CANCELS.some(t => text.startsWith(t, index)))
68
- return [index, -1];
74
+ return new MarkTerminator(index, -1);
69
75
  if (!text.startsWith(Resources.escape, index))
70
76
  continue;
71
77
  if (index + Resources.escape.length === text.length)
72
- return [-1, -1];
73
- return text.startsWith(Resources.stringTerminator, index) ? [index, index + Resources.stringTerminator.length] : [index, -1];
78
+ return new MarkTerminator(-1, -1);
79
+ return text.startsWith(Resources.stringTerminator, index)
80
+ ? new MarkTerminator(index, index + Resources.stringTerminator.length)
81
+ : new MarkTerminator(index, -1);
74
82
  }
75
- return [-1, -1];
83
+ return new MarkTerminator(-1, -1);
76
84
  }
77
85
  static findIntroducer(text, from) {
78
- let found = [-1, ""];
86
+ let found = new MarkIntroducer(-1, "");
79
87
  for (const introducer of INTRODUCERS) {
80
88
  const start = text.indexOf(introducer, from);
81
- if (start >= 0 && (found[0] < 0 || start < found[0]))
82
- found = [start, introducer];
89
+ if (start >= 0 && (found.start < 0 || start < found.start))
90
+ found = new MarkIntroducer(start, introducer);
83
91
  }
84
92
  return found;
85
93
  }
@@ -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 { TerminalShellKind, TerminalSize } from "@noldova/terminal.protocol";
10
11
  import { OneShotLaunch } from "../models/one-shot-launch.js";
@@ -62,7 +63,7 @@ export class OneShotCommand {
62
63
  }
63
64
  async endAsync() {
64
65
  await this.started;
65
- if (this.terminal !== null && !this.hasEnded)
66
+ if (!Object.isNull(this.terminal) && !this.hasEnded)
66
67
  await this.terminal.endAsync();
67
68
  }
68
69
  interrupt() {
@@ -80,7 +81,7 @@ export class OneShotCommand {
80
81
  return OneShotCommand.toCmdLaunch(shell, command);
81
82
  case Resources.pwshExecutable:
82
83
  case Resources.windowsPowerShellExecutable:
83
- return new OneShotLaunch(shell.file, [...Resources.powerShellOneShotArguments, shell.startCommand === null ? command : `${shell.startCommand}${Resources.lineFeed}${command}`]);
84
+ return new OneShotLaunch(shell.file, [...Resources.powerShellOneShotArguments, Object.isNull(shell.startCommand) ? command : `${shell.startCommand}${Resources.lineFeed}${command}`]);
84
85
  default:
85
86
  return new OneShotLaunch(shell.file, [...Resources.posixOneShotArguments, command]);
86
87
  }
@@ -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 { TerminalInputMark } from "@noldova/terminal.protocol";
9
10
  import { Resources } from "../resources.js";
10
11
  export class OutputBatcher {
@@ -49,7 +50,7 @@ export class OutputBatcher {
49
50
  this.cancelTimer();
50
51
  }
51
52
  cancelTimer() {
52
- if (this.timer === null)
53
+ if (Object.isNull(this.timer))
53
54
  return;
54
55
  clearTimeout(this.timer);
55
56
  this.timer = null;
@@ -41,7 +41,10 @@ export class OutputLog {
41
41
  return this.text.slice(Math.max(start - this.startOffset, 0), Math.max(end - this.startOffset, 0));
42
42
  }
43
43
  readSince(offset) {
44
- return new OutputChunk(this.readRange(offset, this.endOffset), this.endOffset);
44
+ return this.readChunk(offset, this.endOffset);
45
+ }
46
+ readChunk(start, end) {
47
+ return new OutputChunk(this.readRange(start, end), end, Math.max(Math.min(this.startOffset, end) - start, 0));
45
48
  }
46
49
  subscribe(listener) {
47
50
  this.listeners.add(listener);
@@ -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 PowerShellBinding {
10
11
  isWindows;
@@ -13,11 +14,11 @@ export class PowerShellBinding {
13
14
  }
14
15
  bindsWildcardPath(words) {
15
16
  const [command, ...rest] = words.map(t => t.toLowerCase());
16
- if (command === undefined)
17
+ if (Object.isUndefined(command))
17
18
  return false;
18
19
  const cmdlet = Resources.powerShellPathCmdlets
19
20
  .find(t => t.names.includes(command) || (this.isWindows && t.windowsAliases.includes(command)));
20
- if (cmdlet === undefined)
21
+ if (Object.isUndefined(cmdlet))
21
22
  return false;
22
23
  const parameters = [...cmdlet.parameters, ...Resources.powerShellCommonParameters];
23
24
  const named = [];
@@ -25,7 +26,7 @@ export class PowerShellBinding {
25
26
  let positional = 0;
26
27
  let ended = false;
27
28
  for (const word of rest) {
28
- if (pending !== null) {
29
+ if (!Object.isNull(pending)) {
29
30
  named.push(pending.slot);
30
31
  pending = null;
31
32
  continue;
@@ -43,19 +44,19 @@ export class PowerShellBinding {
43
44
  const fixed = this.matches(parameters, name);
44
45
  const found = fixed.length > 0 ? fixed : this.matches(cmdlet.dynamicParameters, name);
45
46
  const parameter = found.length === 1 ? found.at(0) : undefined;
46
- if (parameter === undefined)
47
+ if (Object.isUndefined(parameter))
47
48
  return false;
48
49
  if (separator >= 0 || parameter.isSwitch)
49
50
  named.push(parameter.slot);
50
51
  else
51
52
  pending = parameter;
52
53
  }
53
- if (pending !== null)
54
+ if (!Object.isNull(pending))
54
55
  return pending.name === Resources.powerShellPathParameter;
55
56
  return cmdlet.positions.filter(t => !named.includes(t)).at(positional) === Resources.powerShellPathParameter;
56
57
  }
57
58
  matches(parameters, name) {
58
59
  const exact = parameters.find(t => t.name === name || t.aliases.includes(name));
59
- return exact !== undefined ? [exact] : parameters.filter(t => [t.name, ...t.aliases].some(n => n.startsWith(name)));
60
+ return !Object.isUndefined(exact) ? [exact] : parameters.filter(t => [t.name, ...t.aliases].some(n => n.startsWith(name)));
60
61
  }
61
62
  }
@@ -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 PseudoTerminal {
10
11
  process;
@@ -116,6 +117,6 @@ export class PseudoTerminal {
116
117
  this.write(key);
117
118
  }
118
119
  static toExitCode(event) {
119
- return event.signal === undefined || event.signal === 0 ? event.exitCode ?? null : null;
120
+ return Object.isUndefined(event.signal) || event.signal === 0 ? event.exitCode ?? null : null;
120
121
  }
121
122
  }
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { EnvironmentExportInvalidException } from "../exceptions/environment-export-invalid.exception.js";
9
10
  import { RegistryValue } from "../models/registry-value.js";
10
11
  import { Resources } from "../resources.js";
@@ -58,7 +59,7 @@ export class RegistryExport {
58
59
  this.index++;
59
60
  for (;;) {
60
61
  const character = this.text[this.index];
61
- if (character === undefined)
62
+ if (Object.isUndefined(character))
62
63
  throw new EnvironmentExportInvalidException();
63
64
  if (character === Resources.registryExportQuote) {
64
65
  this.index++;
@@ -66,7 +67,7 @@ export class RegistryExport {
66
67
  }
67
68
  if (character === Resources.registryExportEscape) {
68
69
  const escaped = this.text[this.index + 1];
69
- if (escaped === undefined)
70
+ if (Object.isUndefined(escaped))
70
71
  throw new EnvironmentExportInvalidException();
71
72
  value += escaped;
72
73
  this.index += 2;
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { Resources } from "../resources.js";
9
10
  export class ResizeWakeup {
10
11
  write;
@@ -18,7 +19,7 @@ export class ResizeWakeup {
18
19
  this.output = "";
19
20
  }
20
21
  receive(data) {
21
- if (this.output === null)
22
+ if (Object.isNull(this.output))
22
23
  return;
23
24
  this.output += data;
24
25
  if (Resources.escapesOnly.test(this.output))
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { Migration } from "@noldova/desktop.runtime";
9
10
  import { SavedTerminal } from "../models/saved-terminal.js";
10
11
  import { Resources } from "../resources.js";
@@ -24,7 +25,7 @@ export class SavedTerminals {
24
25
  }
25
26
  list() {
26
27
  return this.database.readAll(Resources.savedTerminalsListQuery)
27
- .map(t => new SavedTerminal(String(t[Resources.savedTerminalsSessionIdColumn]), String(t[Resources.savedTerminalsShellIdColumn]), String(t[Resources.savedTerminalsFolderColumn]), Number(t[Resources.savedTerminalsIsPanelTerminalColumn]) === 1, t[Resources.savedTerminalsOwnerColumn] === null ? null : String(t[Resources.savedTerminalsOwnerColumn]), Number(t[Resources.savedTerminalsOpensTabColumn]) === 1, t[Resources.savedTerminalsNameColumn] === null ? null : String(t[Resources.savedTerminalsNameColumn])));
28
+ .map(t => new SavedTerminal(String(t[Resources.savedTerminalsSessionIdColumn]), String(t[Resources.savedTerminalsShellIdColumn]), String(t[Resources.savedTerminalsFolderColumn]), Number(t[Resources.savedTerminalsIsPanelTerminalColumn]) === 1, Object.isNull(t[Resources.savedTerminalsOwnerColumn]) ? null : String(t[Resources.savedTerminalsOwnerColumn]), Number(t[Resources.savedTerminalsOpensTabColumn]) === 1, Object.isNull(t[Resources.savedTerminalsNameColumn]) ? null : String(t[Resources.savedTerminalsNameColumn])));
28
29
  }
29
30
  save(terminal) {
30
31
  this.write(t => Resources.formatSavedTerminalUnwritable(terminal.sessionId, t), () => this.database.run(Resources.savedTerminalsSaveStatement, terminal.sessionId, terminal.shellId, terminal.folder, terminal.isPanelTerminal ? 1 : 0, terminal.owner, terminal.opensTab ? 1 : 0));