@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 { ReadDroppedException } from "../exceptions/read-dropped.exception.js";
9
10
  import { SharedRead } from "../models/shared-read.js";
10
11
  import { Resources } from "../resources.js";
@@ -39,7 +40,7 @@ export class SharedReads {
39
40
  if (signal.aborted)
40
41
  return Promise.reject(new ReadDroppedException());
41
42
  let shared = running.get(path);
42
- if (shared === undefined) {
43
+ if (Object.isUndefined(shared)) {
43
44
  const created = new SharedRead(read);
44
45
  const settled = () => void running.delete(path);
45
46
  void created.promise.then(settled, settled);
@@ -55,7 +56,7 @@ export class SharedReads {
55
56
  startWaiting() {
56
57
  while (this.running < Resources.completionConcurrentReads) {
57
58
  const next = this.waiting.values().next().value;
58
- if (next === undefined)
59
+ if (Object.isUndefined(next))
59
60
  return;
60
61
  this.waiting.delete(next);
61
62
  this.running++;
@@ -5,10 +5,11 @@
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";
9
+ import { OutputSpan } from "../models/output-span.js";
8
10
  import { Resources } from "../resources.js";
9
11
  import { CommandStatus } from "../tools/enums/command-status.js";
10
12
  import { RunMethod } from "../tools/enums/run-method.js";
11
- import { OutputChunk } from "../tools/models/output-chunk.js";
12
13
  export class ShellCommand {
13
14
  session;
14
15
  line;
@@ -33,31 +34,31 @@ export class ShellCommand {
33
34
  }
34
35
  }
35
36
  get status() {
36
- if (this.givenUp !== null)
37
+ if (!Object.isNull(this.givenUp))
37
38
  return CommandStatus.Killed;
38
- if (this.tracked?.hasEnded === true || this.unmarkedEnd !== null)
39
+ if (this.tracked?.hasEnded === true || !Object.isNull(this.unmarkedEnd))
39
40
  return this.isKilled ? CommandStatus.Killed : CommandStatus.Exited;
40
- if (this.restartEnd !== null || this.session.hasExited)
41
+ if (!Object.isNull(this.restartEnd) || this.session.hasExited)
41
42
  return CommandStatus.Killed;
42
43
  return this.session.text.isAwaitingSecret ? CommandStatus.AwaitingInput : CommandStatus.Running;
43
44
  }
44
45
  get exitCode() {
45
- return this.givenUp === null ? this.tracked?.exitCode ?? null : null;
46
+ return Object.isNull(this.givenUp) ? this.tracked?.exitCode ?? null : null;
46
47
  }
47
48
  get cwd() {
48
- return this.givenUp === null ? this.tracked?.cwd ?? null : null;
49
+ return Object.isNull(this.givenUp) ? this.tracked?.cwd ?? null : null;
49
50
  }
50
51
  get hasEnded() {
51
- return this.givenUp !== null || this.tracked?.hasEnded === true || this.unmarkedEnd !== null || this.restartEnd !== null || this.session.hasExited;
52
+ return !Object.isNull(this.givenUp) || this.tracked?.hasEnded === true || !Object.isNull(this.unmarkedEnd) || !Object.isNull(this.restartEnd) || this.session.hasExited;
52
53
  }
53
54
  get outputStart() {
54
- if (this.givenUp !== null)
55
- return this.givenUp[0];
55
+ if (!Object.isNull(this.givenUp))
56
+ return this.givenUp.start;
56
57
  const tracked = this.tracked;
57
58
  return tracked?.hasOutputStart === true ? tracked.outputStart : this.line.startOffset;
58
59
  }
59
60
  get outputEnd() {
60
- return this.givenUp?.[1] ?? this.tracked?.outputEnd ?? this.unmarkedEnd ?? this.restartEnd ?? this.session.text.endOffset;
61
+ return this.givenUp?.end ?? this.tracked?.outputEnd ?? this.unmarkedEnd ?? this.restartEnd ?? this.session.text.endOffset;
61
62
  }
62
63
  get restartEnd() {
63
64
  return this.session.endOfRun(this.run);
@@ -69,12 +70,10 @@ export class ShellCommand {
69
70
  return this.line.command;
70
71
  }
71
72
  readSince(offset) {
72
- const start = this.outputStart;
73
- const end = this.outputEnd;
74
- return new OutputChunk(this.session.text.readRange(start + offset, end), end - start);
73
+ return this.session.text.readChunk(Math.max(offset, this.outputStart), this.outputEnd);
75
74
  }
76
75
  waitForOutputAsync(offset, timeoutMilliseconds, signal) {
77
- return this.session.changes.waitUntilAsync(() => this.hasEnded || this.outputEnd > this.outputStart + offset, timeoutMilliseconds, signal);
76
+ return this.session.changes.waitUntilAsync(() => this.hasEnded || this.outputEnd > Math.max(offset, this.outputStart), timeoutMilliseconds, signal);
78
77
  }
79
78
  waitForEndAsync(timeoutMilliseconds, signal) {
80
79
  return this.session.changes.waitUntilAsync(() => this.hasEnded, timeoutMilliseconds, signal);
@@ -87,7 +86,7 @@ export class ShellCommand {
87
86
  setTimeout(() => {
88
87
  if (this.hasEnded)
89
88
  return;
90
- this.givenUp = [this.outputStart, this.outputEnd];
89
+ this.givenUp = new OutputSpan(this.outputStart, this.outputEnd);
91
90
  this.session.changes.notify();
92
91
  }, Resources.graceMilliseconds).unref();
93
92
  return true;
@@ -5,10 +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 { randomBytes } from "node:crypto";
9
10
  import path from "node:path";
10
11
  import { Resources as ProtocolResources } from "@noldova/terminal.protocol";
11
12
  import { ShellFamily } from "../enums/shell-family.js";
13
+ import { IntegrationScript } from "../models/integration-script.js";
12
14
  import { ShellLaunch } from "../models/shell-launch.js";
13
15
  import { Resources } from "../resources.js";
14
16
  import { FailureText } from "./failure-text.js";
@@ -36,7 +38,7 @@ export class ShellIntegration {
36
38
  }
37
39
  watch(process, launch) {
38
40
  const { nonce, nonceFile } = launch;
39
- if (nonce === null || nonceFile === null)
41
+ if (Object.isNull(nonce) || Object.isNull(nonceFile))
40
42
  return;
41
43
  const remove = () => {
42
44
  data.dispose();
@@ -50,7 +52,7 @@ export class ShellIntegration {
50
52
  const exit = process.onExit(() => remove());
51
53
  }
52
54
  async removeNonceFileAsync(nonceFile) {
53
- if (nonceFile === null)
55
+ if (Object.isNull(nonceFile))
54
56
  return;
55
57
  try {
56
58
  await this.writer.removeFileAsync(nonceFile);
@@ -62,7 +64,7 @@ export class ShellIntegration {
62
64
  async disposeAsync() {
63
65
  const folder = this.folder;
64
66
  this.folder = null;
65
- if (folder !== null)
67
+ if (!Object.isNull(folder))
66
68
  await this.writer.removeFolderAsync(await folder);
67
69
  }
68
70
  isSuggesting() {
@@ -91,16 +93,16 @@ export class ShellIntegration {
91
93
  if (family === ShellFamily.PowerShell)
92
94
  await this.makeSharedMemoryFolderAsync(environment);
93
95
  const folder = await this.writeScriptsOrNullAsync();
94
- const nonceFile = folder === null ? null : await this.writeNonceOrNullAsync(folder, nonce);
95
- if (folder === null || nonceFile === null)
96
+ const nonceFile = Object.isNull(folder) ? null : await this.writeNonceOrNullAsync(folder, nonce);
97
+ if (Object.isNull(folder) || Object.isNull(nonceFile))
96
98
  return ShellIntegration.toPlainLaunch(shell, family);
97
- const noteVariables = note === null ? {} : { [Resources.noteVariable]: note };
99
+ const noteVariables = Object.isNull(note) ? {} : { [Resources.noteVariable]: note };
98
100
  if (family === ShellFamily.PowerShell)
99
101
  return new ShellLaunch(shell.file, [...shell.args, ...Resources.powerShellIntegrationArguments, ShellIntegration.encode([Resources.shellIntegrationPowerShellNonce, Resources.shellIntegrationPowerShellNote, Resources.shellIntegrationPowerShellProfiles, shell.startCommand,
100
- Resources.shellIntegrationPowerShellScript].filter(t => t !== null).join(Resources.lineFeed))], {
102
+ Resources.shellIntegrationPowerShellScript].filter(t => !Object.isNull(t)).join(Resources.lineFeed))], {
101
103
  [Resources.nonceFileVariable]: nonceFile,
102
104
  ...noteVariables
103
- }, nonce, nonceFile, note !== null);
105
+ }, nonce, nonceFile, !Object.isNull(note));
104
106
  if (family === ShellFamily.Bash) {
105
107
  const bashScript = path.join(folder, Resources.bashScriptFile).replaceAll(Resources.windowsSeparator, Resources.posixSeparator);
106
108
  const isLogin = shell.args.some(t => Resources.loginArguments.includes(t));
@@ -108,19 +110,19 @@ export class ShellIntegration {
108
110
  [Resources.nonceFileVariable]: nonceFile.replaceAll(Resources.windowsSeparator, Resources.posixSeparator),
109
111
  ...(isLogin ? { [Resources.loginVariable]: Resources.shellIntegrationLoginValue } : {}),
110
112
  ...noteVariables
111
- }, nonce, nonceFile, note !== null);
113
+ }, nonce, nonceFile, !Object.isNull(note));
112
114
  }
113
115
  const userFolder = environment[Resources.zdotdirVariable];
114
116
  return new ShellLaunch(shell.file, shell.args, {
115
117
  [Resources.nonceFileVariable]: nonceFile,
116
118
  [Resources.zdotdirVariable]: folder,
117
- ...(userFolder === undefined ? {} : { [Resources.userZdotdirVariable]: userFolder }),
119
+ ...(Object.isUndefined(userFolder) ? {} : { [Resources.userZdotdirVariable]: userFolder }),
118
120
  ...noteVariables
119
- }, nonce, nonceFile, note !== null);
121
+ }, nonce, nonceFile, !Object.isNull(note));
120
122
  }
121
123
  makeSharedMemoryFolderAsync(environment) {
122
124
  const runtimeFolder = environment[Resources.runtimeFolderVariable];
123
- if (this.platform !== Resources.linuxPlatform || runtimeFolder === undefined || !path.posix.isAbsolute(runtimeFolder))
125
+ if (this.platform !== Resources.linuxPlatform || Object.isUndefined(runtimeFolder) || !path.posix.isAbsolute(runtimeFolder))
124
126
  return Promise.resolve();
125
127
  const dotnetFolder = path.posix.join(runtimeFolder, Resources.dotnetFolder);
126
128
  const folder = path.posix.join(dotnetFolder, Resources.dotnetSharedMemoryFolder);
@@ -163,14 +165,14 @@ export class ShellIntegration {
163
165
  const folder = await this.writer.createPrivateFolderAsync(path.join(this.temporaryFolder, Resources.integrationFolderPrefix));
164
166
  try {
165
167
  await this.access?.restrictAsync(folder);
166
- for (const [name, text] of [
167
- [Resources.bashScriptFile, Resources.shellIntegrationBashScript],
168
- [Resources.zshEnvironmentFile, Resources.shellIntegrationZshEnvironment],
169
- [Resources.zshProfileFile, Resources.shellIntegrationZshProfile],
170
- [Resources.zshInteractiveFile, Resources.shellIntegrationZshInteractive],
171
- [Resources.zshLoginFile, Resources.shellIntegrationZshLogin]
168
+ for (const script of [
169
+ new IntegrationScript(Resources.bashScriptFile, Resources.shellIntegrationBashScript),
170
+ new IntegrationScript(Resources.zshEnvironmentFile, Resources.shellIntegrationZshEnvironment),
171
+ new IntegrationScript(Resources.zshProfileFile, Resources.shellIntegrationZshProfile),
172
+ new IntegrationScript(Resources.zshInteractiveFile, Resources.shellIntegrationZshInteractive),
173
+ new IntegrationScript(Resources.zshLoginFile, Resources.shellIntegrationZshLogin)
172
174
  ])
173
- await this.writer.writeTextAsync(path.join(folder, name), text);
175
+ await this.writer.writeTextAsync(path.join(folder, script.fileName), script.text);
174
176
  }
175
177
  catch (error) {
176
178
  await this.writer.removeFolderAsync(folder)
@@ -181,18 +183,18 @@ export class ShellIntegration {
181
183
  }
182
184
  static toCommandPromptLaunch(shell, note) {
183
185
  const [first, ...start] = shell.args;
184
- if (note === null || (first !== undefined && first.toLowerCase() !== Resources.keepOpenArgument))
186
+ if (Object.isNull(note) || (!Object.isUndefined(first) && first.toLowerCase() !== Resources.keepOpenArgument))
185
187
  return new ShellLaunch(shell.file, shell.args, {}, null);
186
188
  return new ShellLaunch(shell.file, Resources.formatCmdNoteLine(shell.file, Resources.noteVariable, Resources.formatCmdStart(start)), { [Resources.noteVariable]: note.slice(0, note.length - Resources.noteLineBreak.length) }, null, null, true);
187
189
  }
188
190
  static toPlainLaunch(shell, family) {
189
- if (family !== ShellFamily.PowerShell || shell.startCommand === null)
191
+ if (family !== ShellFamily.PowerShell || Object.isNull(shell.startCommand))
190
192
  return new ShellLaunch(shell.file, shell.args, {}, null);
191
193
  return new ShellLaunch(shell.file, [...shell.args, ...Resources.powerShellArguments, ShellIntegration.encode(shell.startCommand)], {}, null);
192
194
  }
193
195
  static toPowerShellLoginLaunch(launch) {
194
196
  const [first, ...rest] = [launch.args].flat();
195
- if (first === undefined || !ShellIntegration.isPowerShellLogin(first))
197
+ if (Object.isUndefined(first) || !ShellIntegration.isPowerShellLogin(first))
196
198
  return launch;
197
199
  return new ShellLaunch(Resources.powerShellLoginShell, [...Resources.powerShellLoginShellArguments, launch.file, ...rest], { ...launch.environment, [Resources.powerShellLoginCheckedVariable]: Resources.powerShellLoginCheckedValue }, launch.nonce, launch.nonceFile, launch.printsNote);
198
200
  }
@@ -5,10 +5,13 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { userInfo } from "node:os";
9
10
  import path from "node:path";
10
11
  import { TerminalShellKind } from "@noldova/terminal.protocol";
11
12
  import { Shell } from "../models/shell.js";
13
+ import { ShellCandidate } from "../models/shell-candidate.js";
14
+ import { WslLauncher } from "../models/wsl-launcher.js";
12
15
  import { Resources } from "../resources.js";
13
16
  import { FailureText } from "./failure-text.js";
14
17
  import { VisualStudioReader } from "./visual-studio.reader.js";
@@ -32,15 +35,15 @@ export class ShellLocator {
32
35
  this.userShell = userShell;
33
36
  this.fileSystem = fileSystem;
34
37
  this.log = log;
35
- this.wsl = systemRoot === undefined || systemRoot.length === 0
38
+ this.wsl = Object.isUndefined(systemRoot) || systemRoot.length === 0
36
39
  ? null
37
- : { file: path.win32.join(systemRoot, ...Resources.wslPath), reader: new WslDistributionReader(runner, systemRoot) };
40
+ : new WslLauncher(path.win32.join(systemRoot, ...Resources.wslPath), new WslDistributionReader(runner, systemRoot));
38
41
  this.visualStudioReader = new VisualStudioReader(runner, fileSystem, environment[Resources.programFilesX86Variable]);
39
42
  }
40
43
  static readUserShell() {
41
44
  try {
42
45
  const shell = userInfo().shell;
43
- return shell === null || shell.trim().length === 0 ? null : shell;
46
+ return Object.isNull(shell) || shell.trim().length === 0 ? null : shell;
44
47
  }
45
48
  catch (error) {
46
49
  if (error instanceof Error && "code" in error && error.code === Resources.systemErrorCode)
@@ -55,11 +58,11 @@ export class ShellLocator {
55
58
  return [...installed, ...await this.locateListedAsync(installed)];
56
59
  }
57
60
  async findAsync(shellId) {
58
- const isMatch = (shell) => shellId === null ? shell.isDefault : shell.id === shellId;
61
+ const isMatch = (shell) => Object.isNull(shellId) ? shell.isDefault : shell.id === shellId;
59
62
  if (this.platform !== Resources.windowsPlatform)
60
63
  return (await this.locateOnUnixAsync()).find(isMatch);
61
64
  const installed = await this.locateOnWindowsAsync();
62
- return installed.find(isMatch) ?? (shellId === null ? undefined : (await this.locateListedAsync(installed)).find(isMatch));
65
+ return installed.find(isMatch) ?? (Object.isNull(shellId) ? undefined : (await this.locateListedAsync(installed)).find(isMatch));
63
66
  }
64
67
  async findKindAsync(kinds) {
65
68
  const isMatch = (shell) => kinds.includes(shell.kind);
@@ -80,20 +83,20 @@ export class ShellLocator {
80
83
  ...await this.findGitOnSearchPathAsync(searchPath)
81
84
  ];
82
85
  const candidates = [
83
- [Resources.pwshId, Resources.pwshName, TerminalShellKind.PowerShell, [
84
- ...ShellLocator.joinIfSet(programFiles, [...Resources.pwshFolder, Resources.pwshFile]),
85
- ...searchPath.map(t => path.win32.join(t, Resources.pwshFile)),
86
- ...ShellLocator.joinIfSet(localAppData, [...Resources.appAliasFolder, Resources.pwshFile])
87
- ], []],
88
- [Resources.windowsPowerShellId, Resources.windowsPowerShellName, TerminalShellKind.PowerShell, ShellLocator.joinIfSet(systemRoot, Resources.windowsPowerShellPath), []],
89
- [Resources.cmdId, Resources.cmdName, TerminalShellKind.CommandPrompt, ShellLocator.joinIfSet(systemRoot, Resources.cmdPath), []],
90
- [Resources.gitBashId, Resources.gitBashName, TerminalShellKind.Bash, gitFolders.map(t => path.win32.join(t, ...Resources.gitBashFile)), Resources.gitBashArguments]
86
+ new ShellCandidate(Resources.pwshId, Resources.pwshName, TerminalShellKind.PowerShell, [
87
+ ...ShellLocator.joinIfSet(programFiles, [...Resources.pwshFolder, Resources.pwshFile]),
88
+ ...searchPath.map(t => path.win32.join(t, Resources.pwshFile)),
89
+ ...ShellLocator.joinIfSet(localAppData, [...Resources.appAliasFolder, Resources.pwshFile])
90
+ ], []),
91
+ new ShellCandidate(Resources.windowsPowerShellId, Resources.windowsPowerShellName, TerminalShellKind.PowerShell, ShellLocator.joinIfSet(systemRoot, Resources.windowsPowerShellPath), []),
92
+ new ShellCandidate(Resources.cmdId, Resources.cmdName, TerminalShellKind.CommandPrompt, ShellLocator.joinIfSet(systemRoot, Resources.cmdPath), []),
93
+ new ShellCandidate(Resources.gitBashId, Resources.gitBashName, TerminalShellKind.Bash, gitFolders.map(t => path.win32.join(t, ...Resources.gitBashFile)), Resources.gitBashArguments)
91
94
  ];
92
95
  const shells = [];
93
- for (const [id, name, kind, files, args] of candidates) {
94
- const file = await this.findFileAsync(files);
95
- if (file !== null)
96
- shells.push(new Shell(id, name, kind, file, args, shells.length === 0));
96
+ for (const candidate of candidates) {
97
+ const file = await this.findFileAsync(candidate.files);
98
+ if (!Object.isNull(file))
99
+ shells.push(new Shell(candidate.id, candidate.name, candidate.kind, file, candidate.args, shells.length === 0));
97
100
  }
98
101
  return shells;
99
102
  }
@@ -103,7 +106,7 @@ export class ShellLocator {
103
106
  .map(t => t.trim())
104
107
  .filter(t => t.startsWith(Resources.posixRoot) && !Resources.nonShellNames.includes(path.posix.basename(t)));
105
108
  const preferred = this.userShell ?? this.environment[Resources.shellVariable];
106
- const files = preferred === undefined ? listed : [preferred, ...listed];
109
+ const files = Object.isUndefined(preferred) ? listed : [preferred, ...listed];
107
110
  const args = [Resources.loginArgument];
108
111
  const shells = [];
109
112
  for (const file of files) {
@@ -129,15 +132,15 @@ export class ShellLocator {
129
132
  const architecture = Resources.developerArchitectures.get(this.architecture) ?? this.architecture;
130
133
  const id = Resources.developerIdPrefix + installation.instanceId;
131
134
  const shells = [];
132
- if (commandPrompt !== undefined && await this.fileSystem.isFileAsync(script))
135
+ if (!Object.isUndefined(commandPrompt) && await this.fileSystem.isFileAsync(script))
133
136
  shells.push(new Shell(id + Resources.developerCommandSuffix, Resources.formatDeveloperCommandPromptName(installation.name), TerminalShellKind.CommandPrompt, commandPrompt.file, [Resources.keepOpenArgument, script, Resources.noStartFolderArgument, ...Resources.formatDeveloperArchitectureArguments(architecture)], false));
134
- if (powerShell !== undefined && await this.fileSystem.isFileAsync(module))
137
+ if (!Object.isUndefined(powerShell) && await this.fileSystem.isFileAsync(module))
135
138
  shells.push(new Shell(id + Resources.developerPowerShellSuffix, Resources.formatDeveloperPowerShellName(installation.name), TerminalShellKind.PowerShell, powerShell.file, [], false, Resources.formatDeveloperPowerShellCommand(module, installation.path, architecture)));
136
139
  return shells;
137
140
  }
138
141
  async locateWslShellsAsync() {
139
142
  const wsl = this.wsl;
140
- if (wsl === null)
143
+ if (Object.isNull(wsl))
141
144
  return [];
142
145
  this.distributions ??= wsl.reader.readAsync().catch((error) => {
143
146
  this.distributions = null;
@@ -172,6 +175,6 @@ export class ShellLocator {
172
175
  return folders;
173
176
  }
174
177
  static joinIfSet(folder, names) {
175
- return folder === undefined || folder.length === 0 ? [] : [path.win32.join(folder, ...names)];
178
+ return Object.isUndefined(folder) || folder.length === 0 ? [] : [path.win32.join(folder, ...names)];
176
179
  }
177
180
  }
@@ -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 { ShellLine } from "../models/shell-line.js";
9
10
  import { Resources } from "../resources.js";
10
11
  export class ShellWords {
@@ -36,7 +37,7 @@ export class ShellWords {
36
37
  }
37
38
  if (character === escape && index + 1 < text.length) {
38
39
  const next = text.charAt(index + 1);
39
- if (quote === null || isPowerShell || Resources.posixQuotedEscapes.includes(next)) {
40
+ if (Object.isNull(quote) || isPowerShell || Resources.posixQuotedEscapes.includes(next)) {
40
41
  value += next;
41
42
  index++;
42
43
  }
@@ -70,7 +71,7 @@ export class ShellWords {
70
71
  static write(value, quote, isPowerShell, closesQuote, escapesWildcards, keepsHome) {
71
72
  const literal = isPowerShell && escapesWildcards ? value.replace(Resources.powerShellWildcards, Resources.shellWordsPowerShellEscapeReplacement) : value;
72
73
  const quoted = quote ?? (isPowerShell && (literal !== value || Resources.powerShellSpecial.test(value)) ? Resources.singleQuote : null);
73
- if (quoted === null)
74
+ if (Object.isNull(quoted))
74
75
  return isPowerShell ? literal : `${!keepsHome && value.startsWith(Resources.homeWord) ? Resources.posixEscape : ""}${value.replace(Resources.posixSpecial, Resources.shellWordsPosixEscapeReplacement)}`;
75
76
  const body = quoted === Resources.singleQuote
76
77
  ? literal.replaceAll(Resources.singleQuote, isPowerShell ? Resources.shellWordsPowerShellQuotedSingleQuote : Resources.shellWordsPosixQuotedSingleQuote)
@@ -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 { SystemRequirement } from "../enums/system-requirement.js";
9
10
  import { SystemShortfall } from "../models/system-shortfall.js";
10
11
  import { Resources } from "../resources.js";
@@ -12,35 +13,34 @@ export class SystemRequirements {
12
13
  static findShortfall(platform, osRelease, report) {
13
14
  if (platform === Resources.windowsPlatform) {
14
15
  const build = SystemRequirements.readWindowsBuild(osRelease);
15
- if (build === null)
16
+ if (Object.isNull(build))
16
17
  return new SystemShortfall(SystemRequirement.WindowsBuild, osRelease);
17
18
  return build < Resources.minimumWindowsBuild ? new SystemShortfall(SystemRequirement.WindowsBuild, String(build)) : null;
18
19
  }
19
20
  if (platform === Resources.linuxPlatform) {
20
21
  const version = SystemRequirements.readGlibcVersion(report);
21
- return version !== null && SystemRequirements.isBelowGlibcMinimum(version) ? new SystemShortfall(SystemRequirement.Glibc, version) : null;
22
+ return !Object.isNull(version) && SystemRequirements.isBelowGlibcMinimum(version) ? new SystemShortfall(SystemRequirement.Glibc, version) : null;
22
23
  }
23
24
  return null;
24
25
  }
25
26
  static readWindowsBuild(osRelease) {
26
27
  const match = Resources.systemRequirementsWindowsBuild.exec(osRelease);
27
- return match === null ? null : Number(match[1]);
28
+ return Object.isNull(match) ? null : Number(match[1]);
28
29
  }
29
30
  static readGlibcVersion(report) {
30
- if (typeof report !== "object" || report === null || !(Resources.reportHeaderField in report))
31
+ if (!Object.isObject(report) || !(Resources.reportHeaderField in report))
31
32
  return null;
32
33
  const header = report[Resources.reportHeaderField];
33
- if (typeof header !== "object" || header === null || !(Resources.reportGlibcVersionField in header))
34
+ if (!Object.isObject(header) || !(Resources.reportGlibcVersionField in header))
34
35
  return null;
35
36
  const version = header[Resources.reportGlibcVersionField];
36
- return typeof version === "string" ? version : null;
37
+ return Object.isString(version) ? version : null;
37
38
  }
38
39
  static isBelowGlibcMinimum(version) {
39
40
  const match = Resources.systemRequirementsGlibcVersion.exec(version);
40
- if (match === null)
41
+ if (Object.isNull(match))
41
42
  return false;
42
- const [minimumMajor, minimumMinor] = Resources.minimumGlibcVersion;
43
43
  const major = Number(match[1]);
44
- return major < minimumMajor || (major === minimumMajor && Number(match[2]) < minimumMinor);
44
+ return major < Resources.minimumGlibcMajor || (major === Resources.minimumGlibcMajor && Number(match[2]) < Resources.minimumGlibcMinor);
45
45
  }
46
46
  }
@@ -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 TerminalAudience {
9
10
  windows = new Map();
10
11
  apps = new Set();
@@ -12,17 +13,17 @@ export class TerminalAudience {
12
13
  hiddenWindows = new Map();
13
14
  see(client) {
14
15
  let windows = this.windows.get(client.connection);
15
- if (windows === undefined) {
16
+ if (Object.isUndefined(windows)) {
16
17
  windows = new Set();
17
18
  this.windows.set(client.connection, windows);
18
19
  if (client.isApp)
19
20
  this.apps.add(client.connection);
20
21
  }
21
- if (client.window !== null)
22
+ if (!Object.isNull(client.window))
22
23
  windows.add(client.window);
23
24
  }
24
25
  forget(connection, window) {
25
- if (window !== null) {
26
+ if (!Object.isNull(window)) {
26
27
  this.windows.get(connection)?.delete(window);
27
28
  this.shownOwners.get(connection)?.delete(window);
28
29
  this.hiddenWindows.get(connection)?.delete(window);
@@ -34,10 +35,10 @@ export class TerminalAudience {
34
35
  return this.apps.delete(connection);
35
36
  }
36
37
  show(client, owner, isHidden) {
37
- if (client.window === null)
38
+ if (Object.isNull(client.window))
38
39
  return;
39
40
  let hidden = this.hiddenWindows.get(client.connection);
40
- if (hidden === undefined) {
41
+ if (Object.isUndefined(hidden)) {
41
42
  hidden = new Set();
42
43
  this.hiddenWindows.set(client.connection, hidden);
43
44
  }
@@ -46,11 +47,11 @@ export class TerminalAudience {
46
47
  else
47
48
  hidden.delete(client.window);
48
49
  let owners = this.shownOwners.get(client.connection);
49
- if (owners === undefined) {
50
+ if (Object.isUndefined(owners)) {
50
51
  owners = new Map();
51
52
  this.shownOwners.set(client.connection, owners);
52
53
  }
53
- if (owner === null)
54
+ if (Object.isNull(owner))
54
55
  owners.delete(client.window);
55
56
  else
56
57
  owners.set(client.window, owner);
@@ -62,10 +63,10 @@ export class TerminalAudience {
62
63
  return false;
63
64
  }
64
65
  isOpen(client) {
65
- return client.window === null ? this.windows.has(client.connection) : this.windows.get(client.connection)?.has(client.window) === true;
66
+ return Object.isNull(client.window) ? this.windows.has(client.connection) : this.windows.get(client.connection)?.has(client.window) === true;
66
67
  }
67
68
  isHidden(client) {
68
- return client.window !== null && this.hiddenWindows.get(client.connection)?.has(client.window) === true;
69
+ return !Object.isNull(client.window) && this.hiddenWindows.get(client.connection)?.has(client.window) === true;
69
70
  }
70
71
  isApp(connection) {
71
72
  return this.apps.has(connection);
@@ -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 { TerminalHistoryPaths } from "../models/terminal-history-paths.js";
10
11
  import { Resources } from "../resources.js";
@@ -37,7 +38,7 @@ export class TerminalHistoryFolder {
37
38
  this.folder = null;
38
39
  throw error;
39
40
  }
40
- if (folder === null) {
41
+ if (Object.isNull(folder)) {
41
42
  this.folder = null;
42
43
  return null;
43
44
  }
@@ -46,7 +47,7 @@ export class TerminalHistoryFolder {
46
47
  async removeAsync() {
47
48
  const creating = this.folder;
48
49
  this.folder = null;
49
- if (creating === null)
50
+ if (Object.isNull(creating))
50
51
  return;
51
52
  let folder;
52
53
  try {
@@ -56,7 +57,7 @@ export class TerminalHistoryFolder {
56
57
  this.log.write(Resources.formatTerminalHistoryCreateFailed(FailureText.read(error)));
57
58
  return;
58
59
  }
59
- if (folder !== null)
60
+ if (!Object.isNull(folder))
60
61
  await this.removeFolderAsync(folder);
61
62
  }
62
63
  async createAsync() {
@@ -75,7 +76,7 @@ export class TerminalHistoryFolder {
75
76
  async removeLeftoversAsync() {
76
77
  for (const name of await this.reader.readFolderNamesAsync(this.temporaryFolder)) {
77
78
  const pid = TerminalHistoryFolder.toPid(name);
78
- if (pid !== null && pid !== this.pid && !this.signaller.isRunning(pid))
79
+ if (!Object.isNull(pid) && pid !== this.pid && !this.signaller.isRunning(pid))
79
80
  await this.removeFolderAsync(path.join(this.temporaryFolder, name));
80
81
  }
81
82
  }
@@ -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 { open, rm } from "node:fs/promises";
9
10
  import { JsonException } from "@noldova/context.json";
10
11
  import { TerminalLine } from "@noldova/terminal.protocol";
@@ -84,7 +85,7 @@ export class TerminalHistorySegment {
84
85
  return lines;
85
86
  }
86
87
  async closeAsync() {
87
- if (this.handle !== null)
88
+ if (!Object.isNull(this.handle))
88
89
  await this.handle.close();
89
90
  this.handle = null;
90
91
  }
@@ -5,8 +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 { TerminalLinePage, TerminalLineRange } from "@noldova/terminal.protocol";
9
10
  import { StoredLinesUnwritableException } from "../exceptions/stored-lines-unwritable.exception.js";
11
+ import { TakenSegment } from "../models/taken-segment.js";
10
12
  import { Resources } from "../resources.js";
11
13
  import { TerminalHistorySegment } from "./terminal-history-segment.js";
12
14
  export class TerminalHistory {
@@ -24,12 +26,12 @@ export class TerminalHistory {
24
26
  this.paths = paths;
25
27
  this.segmentLimit = Math.floor(limit / 2);
26
28
  this.onWritten = onWritten;
27
- this.newer = paths === null ? null : new TerminalHistorySegment(paths.first, 0);
28
- if (paths === null)
29
+ this.newer = Object.isNull(paths) ? null : new TerminalHistorySegment(paths.first, 0);
30
+ if (Object.isNull(paths))
29
31
  this.fail(null);
30
32
  }
31
33
  get stored() {
32
- if (this.newer === null)
34
+ if (Object.isNull(this.newer))
33
35
  return new TerminalLineRange(0, 0, 0);
34
36
  return new TerminalLineRange(this.older?.first ?? this.newer.first, this.newer.end, this.dropped);
35
37
  }
@@ -37,7 +39,7 @@ export class TerminalHistory {
37
39
  return this.unwritten;
38
40
  }
39
41
  append(line) {
40
- if (this.paths === null || this.newer === null || this.failure !== null || this.isClosed)
42
+ if (Object.isNull(this.paths) || Object.isNull(this.newer) || !Object.isNull(this.failure) || this.isClosed)
41
43
  return;
42
44
  const text = `${JSON.stringify(line.toJson())}${Resources.lineFeed}`;
43
45
  const bytes = Buffer.byteLength(text, Resources.utf8Encoding);
@@ -50,7 +52,7 @@ export class TerminalHistory {
50
52
  this.unwritten += bytes;
51
53
  }
52
54
  clear() {
53
- if (this.isClosed || this.paths === null || this.newer === null)
55
+ if (this.isClosed || Object.isNull(this.paths) || Object.isNull(this.newer))
54
56
  return;
55
57
  const end = this.newer.end;
56
58
  for (const segment of this.segments)
@@ -71,11 +73,11 @@ export class TerminalHistory {
71
73
  return (await Promise.allSettled(removals)).filter(t => t.status === "rejected").map(t => t.reason);
72
74
  }
73
75
  get segments() {
74
- return [this.older, this.newer].filter(t => t !== null);
76
+ return [this.older, this.newer].filter(t => !Object.isNull(t));
75
77
  }
76
78
  rotate(paths, newer) {
77
- const path = this.older === null ? paths.second : this.older.path;
78
- if (this.older !== null) {
79
+ const path = Object.isNull(this.older) ? paths.second : this.older.path;
80
+ if (!Object.isNull(this.older)) {
79
81
  this.dropped += this.older.end - this.older.first;
80
82
  this.discard(this.older, false);
81
83
  }
@@ -113,10 +115,10 @@ export class TerminalHistory {
113
115
  async readPageAsync(start, limit) {
114
116
  const stored = this.stored;
115
117
  const segments = this.segments;
116
- const pending = segments.map(t => [t, t.take()]);
117
- for (const [segment, buffer] of pending)
118
- await this.storeAsync(segment, buffer);
119
- if (this.failure !== null)
118
+ const pending = segments.map(t => new TakenSegment(t, t.take()));
119
+ for (const taken of pending)
120
+ await this.storeAsync(taken.segment, taken.buffer);
121
+ if (!Object.isNull(this.failure))
120
122
  throw this.failure;
121
123
  const first = Math.min(Math.max(start, stored.start), stored.end);
122
124
  const last = Math.min(first + limit, stored.end);