@noldova/terminal 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +1 -1
  2. package/module.json +2 -2
  3. package/package.json +8 -6
  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 -5
  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 +104 -101
  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 +19 -18
  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
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  The terminal module for apps on [Noldova Desktop](https://github.com/noldova-com/desktop): terminal panes over real shells, and agent tools that run commands through permission requests.
4
4
  It holds the module's `module.json`, `menus.json` and `settings.json`, and its runtime part, which starts the shells in Noldova Desktop's pseudo-terminals, keeps a headless mirror of each terminal and registers the agent tools.
5
5
 
6
- It exports `./runtime`, the runtime part, and `./window`, which re-exports the published API of the window part, [`@noldova/terminal.window`](https://github.com/noldova-com/terminal/tree/main/src/noldova.terminal.window).
6
+ It exports `./runtime`, the runtime part, `./window`, which re-exports the published API of the window part, [`@noldova/terminal.window`](https://github.com/noldova-com/terminal/tree/main/src/noldova.terminal.window), and `./menus.json`, the module's menus.
7
7
  It pins that package and [`@noldova/terminal.protocol`](https://github.com/noldova-com/terminal/tree/main/src/noldova.terminal.protocol) at its own version.
8
8
 
9
9
  An app installs it pinned exactly and lists it in `desktop.modules`, as [documents/INTEGRATION.md](https://github.com/noldova-com/terminal/blob/main/documents/INTEGRATION.md) says.
package/module.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "id": "terminal",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "displayName": "Terminal",
5
5
  "description": "Runs shells in terminal panes, and lets AI agents run commands in them through permission requests.",
6
6
  "parts": ["runtime", "window"],
7
7
  "pseudoTerminals": true,
8
8
  "dependencies": {},
9
- "noldovaDesktop": ">=0.0.13 <0.1.0",
9
+ "noldovaDesktop": ">=0.0.17 <0.1.0",
10
10
  "contributes": {
11
11
  "methods": [
12
12
  "terminal.shells", "terminal.open", "terminal.close", "terminal.restart", "terminal.sessions", "terminal.attach", "terminal.input", "terminal.resize",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noldova/terminal",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "The terminal module for apps on Noldova Desktop: terminal panes over real shells, and agent tools that run commands through permission requests.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,6 +22,7 @@
22
22
  "types": "./src/api/window.d.ts",
23
23
  "default": "./src/api/window.js"
24
24
  },
25
+ "./menus.json": "./menus.json",
25
26
  "./package.json": "./package.json"
26
27
  },
27
28
  "files": [
@@ -36,17 +37,18 @@
36
37
  "registry": "https://registry.npmjs.org/"
37
38
  },
38
39
  "dependencies": {
39
- "@noldova/terminal.protocol": "0.0.7",
40
- "@noldova/terminal.window": "0.0.7",
40
+ "@noldova/terminal.protocol": "0.0.8",
41
+ "@noldova/terminal.window": "0.0.8",
41
42
  "@xterm/addon-serialize": "0.14.0",
42
43
  "@xterm/headless": "6.0.0",
43
44
  "node-pty": "1.2.0-beta.15"
44
45
  },
45
46
  "peerDependencies": {
46
- "@noldova/desktop.protocol": ">=0.0.13 <0.1.0",
47
- "@noldova/desktop.runtime": ">=0.0.13 <0.1.0",
47
+ "@noldova/desktop.protocol": ">=0.0.17 <0.1.0",
48
+ "@noldova/desktop.runtime": ">=0.0.17 <0.1.0",
49
+ "@noldova/context.core": ">=0.0.12 <0.1.0",
48
50
  "@noldova/context.exceptions": ">=0.0.12 <0.1.0",
49
51
  "@noldova/context.json": ">=0.0.12 <0.1.0"
50
52
  },
51
- "gitHead": "c47cd5c1e4ab96359a68fcdf36f6e80c246e81b4"
53
+ "gitHead": "6f07ee91e7a7874b8c5564180f3c4aef8686984a"
52
54
  }
@@ -5,11 +5,12 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { ExceptionOptions } from "@noldova/context.exceptions";
9
10
  import { Resources } from "../resources.js";
10
11
  import { TerminalException } from "./terminal.exception.js";
11
12
  export class StoredLinesDamagedException extends TerminalException {
12
13
  constructor(cause) {
13
- super(Resources.storedLinesDamaged, cause === undefined ? undefined : new ExceptionOptions(cause));
14
+ super(Resources.storedLinesDamaged, Object.isUndefined(cause) ? undefined : new ExceptionOptions(cause));
14
15
  }
15
16
  }
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { Resources } from "../resources.js";
9
10
  import { TerminalOpening } from "./terminal-opening.js";
10
11
  export class HostedTerminal {
@@ -82,15 +83,15 @@ export class HostedTerminal {
82
83
  get hasUnreadInput() {
83
84
  const commands = this.session.commands;
84
85
  const prompt = commands.promptIdentity;
85
- return this.hasRecentInput && (this.inputPrompt === null || prompt === null || prompt === this.inputPrompt
86
+ return this.hasRecentInput && (Object.isNull(this.inputPrompt) || Object.isNull(prompt) || prompt === this.inputPrompt
86
87
  || commands.commandMarks === this.inputCommandMarks);
87
88
  }
88
89
  get isFree() {
89
- return this.ownerSessionId === null && !this.session.hasExited && !this.isRestarting && this.pendingCommand === null
90
+ return Object.isNull(this.ownerSessionId) && !this.session.hasExited && !this.isRestarting && Object.isNull(this.pendingCommand)
90
91
  && this.session.commands.hasMarks && !this.hasUnreadInput && this.session.readPromptLine() === "";
91
92
  }
92
93
  get isDrawingPrompt() {
93
- return this.ownerSessionId === null && !this.session.hasExited && !this.isRestarting && this.pendingCommand === null
94
+ return Object.isNull(this.ownerSessionId) && !this.session.hasExited && !this.isRestarting && Object.isNull(this.pendingCommand)
94
95
  && this.session.commands.isDrawingPrompt;
95
96
  }
96
97
  recordInput(isReply = false, data = "", isAgent = false) {
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class IntegrationScript {
9
+ fileName;
10
+ text;
11
+ constructor(fileName, text) {
12
+ this.fileName = fileName;
13
+ this.text = text;
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class MarkIntroducer {
9
+ start;
10
+ text;
11
+ constructor(start, text) {
12
+ this.start = start;
13
+ this.text = text;
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class MarkTerminator {
9
+ payloadEnd;
10
+ end;
11
+ constructor(payloadEnd, end) {
12
+ this.payloadEnd = payloadEnd;
13
+ this.end = end;
14
+ }
15
+ }
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  export class MirrorLine {
9
10
  currentNumber;
10
11
  marker;
@@ -16,7 +17,7 @@ export class MirrorLine {
16
17
  return this.currentNumber;
17
18
  }
18
19
  get index() {
19
- return this.marker === undefined || this.marker.isDisposed ? null : this.marker.line;
20
+ return Object.isUndefined(this.marker) || this.marker.isDisposed ? null : this.marker.line;
20
21
  }
21
22
  renumber(number) {
22
23
  this.currentNumber = number;
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { Resources } from "../resources.js";
9
10
  export class OneShotLaunch {
10
11
  file;
@@ -16,7 +17,7 @@ export class OneShotLaunch {
16
17
  this.environment = environment;
17
18
  }
18
19
  get commandLine() {
19
- if (typeof this.args !== "string")
20
+ if (!Object.isString(this.args))
20
21
  return [this.file, ...this.args].map(t => OneShotLaunch.quote(t)).join(Resources.oneShotLaunchArgumentSeparator);
21
22
  let line = this.args;
22
23
  for (const [name, value] of Object.entries(this.environment))
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class OutputSpan {
9
+ start;
10
+ end;
11
+ constructor(start, end) {
12
+ this.start = start;
13
+ this.end = end;
14
+ }
15
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class ShellCandidate {
9
+ id;
10
+ name;
11
+ kind;
12
+ files;
13
+ args;
14
+ constructor(id, name, kind, files, args) {
15
+ this.id = id;
16
+ this.name = name;
17
+ this.kind = kind;
18
+ this.files = files;
19
+ this.args = args;
20
+ }
21
+ }
@@ -5,12 +5,13 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  export class ShellMark {
9
10
  kind;
10
11
  value;
11
12
  offset;
12
13
  values;
13
- constructor(kind, value, offset, values = value === null ? [] : [value]) {
14
+ constructor(kind, value, offset, values = Object.isNull(value) ? [] : [value]) {
14
15
  this.kind = kind;
15
16
  this.value = value;
16
17
  this.offset = offset;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class TakenSegment {
9
+ segment;
10
+ buffer;
11
+ constructor(segment, buffer) {
12
+ this.segment = segment;
13
+ this.buffer = buffer;
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class TerminalFolderKey {
9
+ folder;
10
+ key;
11
+ constructor(folder, key) {
12
+ this.folder = folder;
13
+ this.key = key;
14
+ }
15
+ }
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  export class TerminalOpening {
9
10
  owner;
10
11
  connection;
@@ -13,6 +14,6 @@ export class TerminalOpening {
13
14
  this.connection = connection;
14
15
  }
15
16
  isReachedBy(connection, isApp) {
16
- return this.connection === null ? this.owner !== null && isApp : this.connection === connection;
17
+ return Object.isNull(this.connection) ? !Object.isNull(this.owner) && isApp : this.connection === connection;
17
18
  }
18
19
  }
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  export class TrackedCommand {
9
10
  outputStart;
10
11
  hasOutputStart;
@@ -16,7 +17,7 @@ export class TrackedCommand {
16
17
  this.hasOutputStart = hasOutputStart;
17
18
  }
18
19
  get hasEnded() {
19
- return this.outputEnd !== null;
20
+ return !Object.isNull(this.outputEnd);
20
21
  }
21
22
  end(outputEnd, exitCode, cwd) {
22
23
  this.outputEnd = outputEnd;
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { Resources } from "../resources.js";
9
10
  export class TypedLine {
10
11
  echo;
@@ -18,7 +19,7 @@ export class TypedLine {
18
19
  this.echo = TypedLine.compact(text.slice(Math.max(text.lastIndexOf(Resources.lineFeed), text.lastIndexOf(Resources.enterKey)) + 1));
19
20
  }
20
21
  get isOpen() {
21
- return this.command === null && this.endOffset === null;
22
+ return Object.isNull(this.command) && Object.isNull(this.endOffset);
22
23
  }
23
24
  read(text) {
24
25
  const lines = text.split(Resources.lineFeed);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class WslLauncher {
9
+ file;
10
+ reader;
11
+ constructor(file, reader) {
12
+ this.file = file;
13
+ this.reader = reader;
14
+ }
15
+ }
package/src/resources.js CHANGED
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { Resources as ProtocolResources, TerminalShellKind } from "@noldova/terminal.protocol";
9
10
  import { MarkKind } from "./enums/mark-kind.js";
10
11
  import { SystemRequirement } from "./enums/system-requirement.js";
@@ -142,7 +143,8 @@ export class Resources {
142
143
  static windowsPlatform = "win32";
143
144
  static linuxPlatform = "linux";
144
145
  static minimumWindowsBuild = 17_763;
145
- static minimumGlibcVersion = [2, 28];
146
+ static minimumGlibcMajor = 2;
147
+ static minimumGlibcMinor = 28;
146
148
  static macPlatform = "darwin";
147
149
  static languageVariable = "LANG";
148
150
  static characterTypeVariable = "LC_CTYPE";
@@ -712,7 +714,7 @@ exit 0
712
714
  return `The terminal module has no method ${method}.`;
713
715
  }
714
716
  static formatShellLeftRunning(sessionId, pid) {
715
- return `The shell of terminal ${sessionId}${pid === null ? "" : `, process ${pid}`}, or a process it started, did not end in time.`;
717
+ return `The shell of terminal ${sessionId}${Object.isNull(pid) ? "" : `, process ${pid}`}, or a process it started, did not end in time.`;
716
718
  }
717
719
  static formatTerminalHistoryFile(sessionId, index) {
718
720
  return `${sessionId}-${index}.jsonl`;
@@ -748,7 +750,7 @@ exit 0
748
750
  return `ConPTY sent terminal ${sessionId} no cursor request within ${String(Resources.cursorAnswerMilliseconds)} ms of a resize, so the keys typed meanwhile went on without one.`;
749
751
  }
750
752
  static formatLateShellLeftRunning(pid) {
751
- return `A shell that started as the terminals ended${pid === null ? "" : `, process ${pid}`}, or a process it started, did not end in time.`;
753
+ return `A shell that started as the terminals ended${Object.isNull(pid) ? "" : `, process ${pid}`}, or a process it started, did not end in time.`;
752
754
  }
753
755
  static formatLogFailed(path, message) {
754
756
  return `The log file ${path} stopped taking output: ${message}`;
@@ -1716,9 +1718,11 @@ fi
1716
1718
  static agentTerminalOpeningOwnerSessionIdField = "ownerSessionId";
1717
1719
  static agentTerminalOpeningShellIdField = "shellId";
1718
1720
  static outputChunkEndOffsetField = "endOffset";
1721
+ static outputChunkTrimmedCharactersField = "trimmedCharacters";
1719
1722
  static outputExcerptHighSurrogates = /[\ud800-\udbff]$/;
1720
1723
  static outputExcerptLowSurrogates = /^[\udc00-\udfff]/;
1721
1724
  static outputExcerptMaximumCharactersField = "maximumCharacters";
1725
+ static outputExcerptTrimmedCharactersField = "trimmedCharacters";
1722
1726
  static formatPermissionAskAction(action) {
1723
1727
  return `${Resources.moduleId}.${action}`;
1724
1728
  }
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { homedir, release, tmpdir } from "node:os";
9
10
  import { TerminalNames } from "@noldova/terminal.protocol";
10
11
  import { UnsupportedSystemException } from "./exceptions/unsupported-system.exception.js";
@@ -39,7 +40,7 @@ export class RuntimePart {
39
40
  environment = null;
40
41
  async activateAsync(context) {
41
42
  const shortfall = SystemRequirements.findShortfall(process.platform, release(), process.report.getReport());
42
- if (shortfall !== null) {
43
+ if (!Object.isNull(shortfall)) {
43
44
  const error = new UnsupportedSystemException(shortfall.requirement, shortfall.found);
44
45
  context.log.write(error.message);
45
46
  throw error;
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import path from "node:path";
9
10
  import { TerminalPrompt } from "../models/terminal-prompt.js";
10
11
  import { Resources } from "../resources.js";
@@ -73,7 +74,7 @@ export class AgentTerminal {
73
74
  }
74
75
  get hasUnechoedInput() {
75
76
  const received = this.hosted.inputReceivedLength;
76
- if (received === null || !this.hosted.hasRecentInput)
77
+ if (Object.isNull(received) || !this.hosted.hasRecentInput)
77
78
  return false;
78
79
  return !this.hasShellIntegration || this.hosted.hasUnreadInput;
79
80
  }
@@ -117,7 +118,7 @@ export class AgentTerminal {
117
118
  return this.session.changes.waitUntilAsync(() => this.session.hasExited || this.session.text.endOffset > offset, timeoutMilliseconds, signal);
118
119
  }
119
120
  async waitForIntegrationAsync(signal) {
120
- const isReady = () => !this.session.hasIntegration || this.session.hasExited || this.session.commands.promptEndOffset !== null;
121
+ const isReady = () => !this.session.hasIntegration || this.session.hasExited || !Object.isNull(this.session.commands.promptEndOffset);
121
122
  await this.session.waitForStartAsync(() => isReady() || this.session.commands.isLoaded, signal);
122
123
  if (this.session.commands.isLoaded)
123
124
  await this.session.changes.waitUntilAsync(isReady, Resources.shellStartMilliseconds, signal);
@@ -131,7 +132,7 @@ export class AgentTerminal {
131
132
  }
132
133
  }
133
134
  openLogFile() {
134
- if (this.logFile === undefined) {
135
+ if (Object.isUndefined(this.logFile)) {
135
136
  const logFile = new LogFile(this.writer, path.join(this.logFolder, this.id + Resources.logFileExtension), this.log);
136
137
  this.session.text.subscribe(t => logFile.append(t));
137
138
  this.logFile = logFile;
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { Resources as ProtocolResources, TerminalSize } from "@noldova/terminal.protocol";
9
10
  import { Resources } from "../resources.js";
10
11
  import { AgentTerminal } from "./agent-terminal.js";
@@ -30,7 +31,7 @@ export class AgentTerminals {
30
31
  }
31
32
  find(id) {
32
33
  const hosted = this.host.findTerminal(id);
33
- return hosted === undefined ? undefined : this.wrap(hosted);
34
+ return Object.isUndefined(hosted) ? undefined : this.wrap(hosted);
34
35
  }
35
36
  async openAsync(opening, signal) {
36
37
  const size = new TerminalSize(Resources.agentColumns, Resources.agentRows);
@@ -46,7 +47,7 @@ export class AgentTerminals {
46
47
  }
47
48
  wrap(hosted) {
48
49
  let terminal = this.terminals.get(hosted.session.sessionId);
49
- if (terminal === undefined) {
50
+ if (Object.isUndefined(terminal)) {
50
51
  terminal = new AgentTerminal(hosted, this.host, this.writer, this.logFolder, this.log);
51
52
  this.terminals.set(hosted.session.sessionId, terminal);
52
53
  }
@@ -5,7 +5,9 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { ReadDroppedException } from "../exceptions/read-dropped.exception.js";
10
+ const CUT_SHORT = Symbol();
9
11
  export class BoundedReads {
10
12
  reader;
11
13
  expiry = Promise.withResolvers();
@@ -52,13 +54,13 @@ export class BoundedReads {
52
54
  const shared = read(this.stopping.signal);
53
55
  this.pending.add(shared);
54
56
  const tracked = shared.finally(() => this.pending.delete(shared));
55
- const answer = await Promise.race([tracked.then(t => ({ value: t }), (error) => {
57
+ const answer = await Promise.race([tracked.catch((error) => {
56
58
  if (error instanceof ReadDroppedException)
57
- return null;
59
+ return CUT_SHORT;
58
60
  throw error;
59
- }), this.expiry.promise.then(() => null)]);
60
- if (answer !== null)
61
- return answer.value;
61
+ }), this.expiry.promise.then(() => CUT_SHORT)]);
62
+ if (answer !== CUT_SHORT)
63
+ return answer;
62
64
  this.hasCutShort = true;
63
65
  return late;
64
66
  }
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { Resources } from "../resources.js";
9
10
  export class ChangeSignal {
10
11
  waiters = [];
@@ -13,9 +14,9 @@ export class ChangeSignal {
13
14
  waiter();
14
15
  }
15
16
  async waitUntilAsync(condition, timeoutMilliseconds, signal) {
16
- const deadline = timeoutMilliseconds === null ? null : Date.now() + timeoutMilliseconds;
17
- while (!condition() && !signal.aborted && (deadline === null || Date.now() < deadline))
18
- await this.waitAsync(deadline === null ? null : deadline - Date.now(), signal);
17
+ const deadline = Object.isNull(timeoutMilliseconds) ? null : Date.now() + timeoutMilliseconds;
18
+ while (!condition() && !signal.aborted && (Object.isNull(deadline) || Date.now() < deadline))
19
+ await this.waitAsync(Object.isNull(deadline) ? null : deadline - Date.now(), signal);
19
20
  }
20
21
  waitAsync(timeoutMilliseconds, signal) {
21
22
  return new Promise(resolve => {
@@ -25,7 +26,7 @@ export class ChangeSignal {
25
26
  this.waiters = this.waiters.filter(t => t !== done);
26
27
  resolve();
27
28
  };
28
- const timer = timeoutMilliseconds === null ? undefined : setTimeout(done, timeoutMilliseconds);
29
+ const timer = Object.isNull(timeoutMilliseconds) ? undefined : setTimeout(done, timeoutMilliseconds);
29
30
  signal.addEventListener(Resources.abortEvent, done);
30
31
  this.waiters.push(done);
31
32
  });
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { MarkKind } from "../enums/mark-kind.js";
9
10
  import { TrackedCommand } from "../models/tracked-command.js";
10
11
  import { Resources } from "../resources.js";
@@ -133,9 +134,9 @@ export class CommandTracker {
133
134
  endPrompt(offset) {
134
135
  const from = this.canRedraw ? this.lineOffset : this.redrawFrom;
135
136
  const drawn = this.canRedraw ? CommandTracker.lastLine(this.promptText) : this.promptText;
136
- if (from === null || drawn === null || CommandTracker.drawing(this.read(from, offset)) !== drawn) {
137
+ if (Object.isNull(from) || Object.isNull(drawn) || CommandTracker.drawing(this.read(from, offset)) !== drawn) {
137
138
  this.promptOffset = offset;
138
- this.promptText = this.promptStart === null ? null : CommandTracker.drawing(this.read(this.promptStart, offset));
139
+ this.promptText = Object.isNull(this.promptStart) ? null : CommandTracker.drawing(this.read(this.promptStart, offset));
139
140
  }
140
141
  this.lineOffset = offset;
141
142
  this.promptStart = null;
@@ -149,7 +150,7 @@ export class CommandTracker {
149
150
  return text.length > 1 && text.startsWith(Resources.lineFeed) ? text.slice(1) : text;
150
151
  }
151
152
  static lastLine(text) {
152
- return text === null ? null : text.slice(text.lastIndexOf(Resources.lineFeed) + 1);
153
+ return Object.isNull(text) ? null : text.slice(text.lastIndexOf(Resources.lineFeed) + 1);
153
154
  }
154
155
  stopRedraws() {
155
156
  this.canRedraw = false;
@@ -157,7 +158,7 @@ export class CommandTracker {
157
158
  }
158
159
  end(mark) {
159
160
  const command = this.current ?? new TrackedCommand(this.lineOffset ?? mark.offset, false);
160
- const exitCode = mark.value !== null && Resources.commandTrackerExitCode.test(mark.value) ? Number.parseInt(mark.value, Resources.decimalRadix) : null;
161
+ const exitCode = !Object.isNull(mark.value) && Resources.commandTrackerExitCode.test(mark.value) ? Number.parseInt(mark.value, Resources.decimalRadix) : null;
161
162
  command.end(mark.offset, exitCode, this.cwd);
162
163
  this.isAtPrompt = false;
163
164
  this.current = null;