@noldova/terminal 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) 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 +14 -7
  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 +8 -5
  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-runner.js +10 -4
  27. package/src/services/command-tracker.js +5 -4
  28. package/src/services/completion-source.js +27 -23
  29. package/src/services/context-pty-process.js +3 -2
  30. package/src/services/context-pty-spawner.js +2 -1
  31. package/src/services/deferred-pty-process.js +7 -5
  32. package/src/services/escape-sequence-tracker.js +2 -1
  33. package/src/services/failure-text.js +2 -1
  34. package/src/services/flow-controller.js +5 -4
  35. package/src/services/latest-environment.js +2 -1
  36. package/src/services/mac-environment.js +3 -2
  37. package/src/services/mark-scanner.js +22 -14
  38. package/src/services/one-shot-command.js +3 -2
  39. package/src/services/output-batcher.js +2 -1
  40. package/src/services/output-log.js +4 -1
  41. package/src/services/powershell-binding.js +7 -6
  42. package/src/services/pseudo-terminal.js +7 -1
  43. package/src/services/registry-export.js +3 -2
  44. package/src/services/resize-wakeup.js +2 -1
  45. package/src/services/saved-terminals.js +2 -1
  46. package/src/services/shared-reads.js +3 -2
  47. package/src/services/shell-command.js +14 -15
  48. package/src/services/shell-integration.js +24 -22
  49. package/src/services/shell-locator.js +25 -22
  50. package/src/services/shell-words.js +3 -2
  51. package/src/services/system-requirements.js +9 -9
  52. package/src/services/terminal-audience.js +10 -9
  53. package/src/services/terminal-history-folder.js +5 -4
  54. package/src/services/terminal-history-segment.js +2 -1
  55. package/src/services/terminal-history.js +14 -12
  56. package/src/services/terminal-host.js +104 -101
  57. package/src/services/terminal-line-reader.js +3 -2
  58. package/src/services/terminal-mirror.js +13 -12
  59. package/src/services/terminal-session.js +37 -26
  60. package/src/services/visual-studio.reader.js +3 -2
  61. package/src/services/windows-environment.js +12 -11
  62. package/src/services/windows-folder-access.js +2 -1
  63. package/src/services/wsl-distribution.reader.js +2 -1
  64. package/src/tools/models/agent-terminal-opening.js +2 -1
  65. package/src/tools/models/output-chunk.js +4 -1
  66. package/src/tools/models/output-excerpt.js +12 -6
  67. package/src/tools/models/terminal-open-input.js +3 -2
  68. package/src/tools/models/terminal-output-report.js +5 -4
  69. package/src/tools/models/terminal-run-input.js +2 -1
  70. package/src/tools/models/terminal-target-input.js +2 -1
  71. package/src/tools/models/terminal-write-input.js +2 -1
  72. package/src/tools/models/tool-call-context.js +4 -3
  73. package/src/tools/services/permission-details.js +3 -2
  74. package/src/tools/services/permission-gate.js +2 -1
  75. package/src/tools/services/terminal-access-policy.js +8 -7
  76. package/src/tools/services/terminal-interrupt-tool.js +2 -1
  77. package/src/tools/services/terminal-read-tool.js +3 -2
  78. package/src/tools/services/terminal-run-tool.js +6 -5
  79. package/src/tools/services/terminal-text-escaper.js +2 -1
  80. package/src/tools/services/terminal-tool.js +2 -1
  81. 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 { isAbsolute, relative, sep } from "node:path";
9
10
  import { ArgumentException } from "@noldova/context.exceptions";
10
11
  import { ArgumentValidator, ProtocolReader, Resources as ProtocolResources } from "@noldova/terminal.protocol";
@@ -21,17 +22,17 @@ export class ToolCallContext {
21
22
  if (!isAbsolute(folder))
22
23
  throw new ArgumentException(Resources.formatNotAbsolutePath(ProtocolResources.valueSubject), Resources.folderBinding);
23
24
  const shared = new Map(Object.entries(call.bindings)).get(Resources.sharedBinding);
24
- if (shared !== undefined && !Array.isArray(shared))
25
+ if (!Object.isUndefined(shared) && !Array.isArray(shared))
25
26
  throw new ArgumentException(Resources.formatBindingNotList(ProtocolResources.valueSubject), Resources.sharedBinding);
26
27
  const boundTerminalIds = [];
27
28
  for (const terminalId of shared ?? []) {
28
- if (typeof terminalId !== "string")
29
+ if (!Object.isString(terminalId))
29
30
  throw new ArgumentException(Resources.formatBindingNotList(ProtocolResources.valueSubject), Resources.sharedBinding);
30
31
  ArgumentValidator.requireIdentifier(Resources.sharedBinding, terminalId);
31
32
  boundTerminalIds.push(terminalId);
32
33
  }
33
34
  const owner = reader.readOptionalString(Resources.ownerBinding, ProtocolResources.maximumOwnerLength);
34
- if (owner !== undefined)
35
+ if (!Object.isUndefined(owner))
35
36
  ArgumentValidator.requireNonBlank(Resources.ownerBinding, owner, ProtocolResources.maximumOwnerLength);
36
37
  this.call = call;
37
38
  this.agentSessionId = call.session;
@@ -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 { PermissionDetailKind } from "@noldova/desktop.runtime";
9
10
  import { Resources } from "../../resources.js";
10
11
  import { TerminalTextEscaper } from "./terminal-text-escaper.js";
@@ -30,13 +31,13 @@ export class PermissionDetails {
30
31
  }
31
32
  static forFolder(folder, isInsideWorkingFolder) {
32
33
  return [
33
- folder === null
34
+ Object.isNull(folder)
34
35
  ? PermissionDetails.text(Resources.folderLabel, Resources.unknownFolder)
35
36
  : PermissionDetails.code(Resources.folderLabel, TerminalTextEscaper.escapeUnseen(folder)),
36
37
  PermissionDetails.yesNo(Resources.insideWorkingFolderLabel, isInsideWorkingFolder)
37
38
  ];
38
39
  }
39
40
  static forExplanation(explanation) {
40
- return explanation === null ? [] : [{ label: Resources.explanationLabel, kind: PermissionDetailKind.AgentText, value: explanation }];
41
+ return Object.isNull(explanation) ? [] : [{ label: Resources.explanationLabel, kind: PermissionDetailKind.AgentText, value: explanation }];
41
42
  }
42
43
  }
@@ -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 { PermissionDecision, ToolFailureCode } from "@noldova/desktop.runtime";
9
10
  import { Resources } from "../../resources.js";
10
11
  import { ToolFailures } from "./tool-failures.js";
@@ -24,7 +25,7 @@ export class PermissionGate {
24
25
  throw ToolFailures.create(ToolFailureCode.Refused, Resources.requestTooLargeCode, Resources.formatRequestTooLarge(ask.toolName));
25
26
  const outcome = await context.requestPermissionAsync(ask.request);
26
27
  const failure = PermissionGate.failures[outcome.decision];
27
- if (failure !== null)
28
+ if (!Object.isNull(failure))
28
29
  throw ToolFailures.create(failure, null, Resources.formatNotGranted(ask.toolName, outcome.decision));
29
30
  PermissionGate.requireOpenCall(ask, context);
30
31
  }
@@ -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 { ToolFailureCode } from "@noldova/desktop.runtime";
9
10
  import { Resources } from "../../resources.js";
10
11
  import { AgentTerminalAccess } from "../models/agent-terminal-access.js";
@@ -16,9 +17,9 @@ export class TerminalAccessPolicy {
16
17
  }
17
18
  resolve(terminalId, context) {
18
19
  const terminal = this.terminals.find(terminalId);
19
- const access = terminal === undefined ? null
20
+ const access = Object.isUndefined(terminal) ? null
20
21
  : TerminalAccessPolicy.accessTo(terminal, context, this.ownerOf(context));
21
- if (access === null)
22
+ if (Object.isNull(access))
22
23
  throw ToolFailures.create(ToolFailureCode.Refused, Resources.notFoundCode, Resources.formatTerminalNotFound(terminalId));
23
24
  return access;
24
25
  }
@@ -27,19 +28,19 @@ export class TerminalAccessPolicy {
27
28
  const sessionOwner = this.ownerOf(context);
28
29
  for (const terminal of this.terminals.list()) {
29
30
  const access = TerminalAccessPolicy.accessTo(terminal, context, sessionOwner);
30
- if (access !== null)
31
+ if (!Object.isNull(access))
31
32
  accesses.push(access);
32
33
  }
33
34
  return accesses;
34
35
  }
35
36
  listClosingWith(agentSessionId) {
36
- return this.terminals.list().filter(t => t.ownerSessionId === agentSessionId && t.owner === null);
37
+ return this.terminals.list().filter(t => t.ownerSessionId === agentSessionId && Object.isNull(t.owner));
37
38
  }
38
39
  requireStill(access, context) {
39
40
  const terminal = this.terminals.find(access.terminal.id);
40
- const now = terminal === undefined ? null
41
+ const now = Object.isUndefined(terminal) ? null
41
42
  : TerminalAccessPolicy.accessTo(terminal, context, this.ownerOf(context));
42
- if (now === null || now.isShared !== access.isShared)
43
+ if (Object.isNull(now) || now.isShared !== access.isShared)
43
44
  throw ToolFailures.create(ToolFailureCode.Stale, Resources.staleCode, Resources.formatTerminalStale(access.terminal.id));
44
45
  }
45
46
  ownerOf(context) {
@@ -48,7 +49,7 @@ export class TerminalAccessPolicy {
48
49
  static accessTo(terminal, context, sessionOwner) {
49
50
  if (terminal.ownerSessionId === context.agentSessionId)
50
51
  return new AgentTerminalAccess(terminal, false);
51
- if (terminal.ownerSessionId !== null && sessionOwner !== null && terminal.owner === sessionOwner)
52
+ if (!Object.isNull(terminal.ownerSessionId) && !Object.isNull(sessionOwner) && terminal.owner === sessionOwner)
52
53
  return new AgentTerminalAccess(terminal, false);
53
54
  if (context.isBound(terminal.id))
54
55
  return new AgentTerminalAccess(terminal, true);
@@ -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 { ToolRisk } from "@noldova/desktop.runtime";
9
10
  import { Resources } from "../../resources.js";
10
11
  import { PermissionAsk } from "../models/permission-ask.js";
@@ -47,7 +48,7 @@ export class TerminalInterruptTool extends TerminalTool {
47
48
  const prompt = access.terminal.readPrompt();
48
49
  await this.gate.requireGrantAsync(new PermissionAsk(Resources.interruptToolName, Resources.interruptAction, Resources.interruptTitle, ToolRisk.Medium, [
49
50
  ...PermissionDetails.forTerminal(access),
50
- ...PermissionDetails.forFolder(prompt.cwd, prompt.cwd !== null && context.isInsideWorkingFolder(prompt.cwd)),
51
+ ...PermissionDetails.forFolder(prompt.cwd, !Object.isNull(prompt.cwd) && context.isInsideWorkingFolder(prompt.cwd)),
51
52
  ...PermissionDetails.forExplanation(input.explanation)
52
53
  ], PermissionAsk.listSubject([access.terminal.id])), context);
53
54
  this.accessPolicy.requireStill(access, context);
@@ -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 { ToolRisk } from "@noldova/desktop.runtime";
9
10
  import { Resources } from "../../resources.js";
10
11
  import { OutputExcerpt } from "../models/output-excerpt.js";
@@ -45,8 +46,8 @@ export class TerminalReadTool extends TerminalTool {
45
46
  const cursor = this.cursors.find(context.agentSessionId, input.terminalId) ?? ReadCursor.forTerminal(access.terminal, 0);
46
47
  await cursor.source.waitForOutputAsync(cursor.offset, input.waitMilliseconds, context.signal);
47
48
  const chunk = cursor.source.readSince(cursor.offset);
48
- const cwd = cursor.command === null ? access.terminal.readPrompt().cwd : cursor.command.cwd;
49
- const report = new TerminalOutputReport(access, cursor.command, new OutputExcerpt(chunk.text, input.maximumCharacters), cwd);
49
+ const cwd = Object.isNull(cursor.command) ? access.terminal.readPrompt().cwd : cursor.command.cwd;
50
+ const report = new TerminalOutputReport(access, cursor.command, OutputExcerpt.of(chunk, input.maximumCharacters), cwd);
50
51
  if (context.signal.aborted)
51
52
  throw TerminalTool.failEndedCall(Resources.readToolName, cursor.command, report, context.signal);
52
53
  this.cursors.set(context.agentSessionId, input.terminalId, cursor.advancedTo(chunk.endOffset));
@@ -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 { ToolFailureCode, ToolRisk } from "@noldova/desktop.runtime";
9
10
  import { Resources } from "../../resources.js";
10
11
  import { OutputExcerpt } from "../models/output-excerpt.js";
@@ -53,25 +54,25 @@ export class TerminalRunTool extends TerminalTool {
53
54
  await command.waitForEndAsync(input.yieldMilliseconds, context.signal);
54
55
  const chunk = command.readSince(0);
55
56
  this.cursors.set(context.agentSessionId, input.terminalId, ReadCursor.forCommand(command, context.signal.aborted ? 0 : chunk.endOffset));
56
- const report = new TerminalOutputReport(access, command, new OutputExcerpt(chunk.text, input.maximumCharacters), command.cwd);
57
+ const report = new TerminalOutputReport(access, command, OutputExcerpt.of(chunk, input.maximumCharacters), command.cwd);
57
58
  if (context.signal.aborted)
58
59
  throw TerminalTool.failEndedCall(Resources.runToolName, command, report, context.signal);
59
60
  return report.toResult();
60
61
  }
61
62
  static readOneShotLine(terminal, command) {
62
63
  const line = terminal.readOneShotLine(command.text);
63
- return line === null ? null : TerminalTextEscaper.escapeHidden(line);
64
+ return Object.isNull(line) ? null : TerminalTextEscaper.escapeHidden(line);
64
65
  }
65
66
  static askFor(input, access, prompt, context) {
66
67
  const oneShotLine = TerminalRunTool.readOneShotLine(access.terminal, input.command);
67
- const folder = oneShotLine === null ? prompt.cwd : access.terminal.startFolder;
68
+ const folder = Object.isNull(oneShotLine) ? prompt.cwd : access.terminal.startFolder;
68
69
  return new PermissionAsk(Resources.runToolName, Resources.runAction, Resources.runTitle, ToolRisk.High, [
69
70
  ...PermissionDetails.forTerminal(access),
70
71
  ...PermissionDetails.forShell(access),
71
- ...PermissionDetails.forFolder(folder, folder !== null && context.isInsideWorkingFolder(folder)),
72
+ ...PermissionDetails.forFolder(folder, !Object.isNull(folder) && context.isInsideWorkingFolder(folder)),
72
73
  PermissionDetails.code(Resources.commandLabel, input.command.display),
73
74
  PermissionDetails.yesNo(Resources.hiddenCharactersLabel, input.command.hasHiddenCharacters),
74
- oneShotLine === null ? PermissionDetails.text(Resources.methodLabel, Resources.inShellMethod) : PermissionDetails.code(Resources.oneShotLineLabel, oneShotLine),
75
+ Object.isNull(oneShotLine) ? PermissionDetails.text(Resources.methodLabel, Resources.inShellMethod) : PermissionDetails.code(Resources.oneShotLineLabel, oneShotLine),
75
76
  ...PermissionDetails.forExplanation(input.explanation)
76
77
  ], PermissionAsk.hashSubject([access.terminal.id, folder, input.command.text]));
77
78
  }
@@ -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 TerminalTextEscaper {
10
11
  static hasControls(text) {
@@ -27,7 +28,7 @@ export class TerminalTextEscaper {
27
28
  }
28
29
  static escapeCharacter(character) {
29
30
  const name = Resources.terminalTextEscaperNamed.get(character);
30
- if (name !== undefined)
31
+ if (!Object.isUndefined(name))
31
32
  return name;
32
33
  if (TerminalTextEscaper.hasControls(character) || TerminalTextEscaper.hasHiddenCharacters(character))
33
34
  return TerminalTextEscaper.formatCodePoint(character);
@@ -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 { ArgumentException } from "@noldova/context.exceptions";
9
10
  import { JsonException } from "@noldova/context.json";
10
11
  import { ToolFailureCode } from "@noldova/desktop.runtime";
@@ -30,7 +31,7 @@ export class TerminalTool {
30
31
  }
31
32
  }
32
33
  static failEndedCall(action, command, report, signal) {
33
- if (command !== null && AbortReasonReader.interruptsCommand(signal) && command.interrupt())
34
+ if (!Object.isNull(command) && AbortReasonReader.interruptsCommand(signal) && command.interrupt())
34
35
  return ToolFailures.forEndedCall(signal, Resources.formatInterruptedWithOutput(action), report.toResult(Resources.interruptedNote));
35
36
  return ToolFailures.forEndedCall(signal, Resources.formatEndedWithOutput(action), report.toResult());
36
37
  }
@@ -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 { ToolFailureCode, ToolRisk } from "@noldova/desktop.runtime";
9
10
  import { Resources } from "../../resources.js";
10
11
  import { PermissionAsk } from "../models/permission-ask.js";
@@ -75,7 +76,7 @@ export class TerminalWriteTool extends TerminalTool {
75
76
  return new PermissionAsk(Resources.writeToolName, Resources.writeAction, Resources.writeTitle, ToolRisk.High, [
76
77
  ...PermissionDetails.forTerminal(access),
77
78
  ...PermissionDetails.forShell(access),
78
- ...PermissionDetails.forFolder(prompt.cwd, prompt.cwd !== null && context.isInsideWorkingFolder(prompt.cwd)),
79
+ ...PermissionDetails.forFolder(prompt.cwd, !Object.isNull(prompt.cwd) && context.isInsideWorkingFolder(prompt.cwd)),
79
80
  PermissionDetails.yesNo(Resources.atPromptLabel, prompt.isIdle),
80
81
  PermissionDetails.code(Resources.keysLabel, input.keys.display),
81
82
  PermissionDetails.yesNo(Resources.hiddenCharactersLabel, input.keys.hasHiddenCharacters),