@noldova/terminal 0.0.16 → 0.0.18

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 (52) hide show
  1. package/module.json +2 -2
  2. package/package.json +9 -9
  3. package/src/enums/mark-kind.js +1 -0
  4. package/src/enums/shell-family.js +1 -0
  5. package/src/exceptions/command-exited.exception.js +2 -1
  6. package/src/models/hosted-terminal.js +20 -9
  7. package/src/models/one-shot-launch.js +7 -4
  8. package/src/models/right-prompt-span.js +14 -0
  9. package/src/models/terminal-prompt.js +5 -5
  10. package/src/models/typed-line.js +2 -2
  11. package/src/resources.js +271 -13
  12. package/src/runtime-part.js +1 -1
  13. package/src/services/agent-terminal.js +7 -5
  14. package/src/services/command-describer.js +35 -33
  15. package/src/services/command-runner.js +5 -3
  16. package/src/services/command-tracker.js +17 -2
  17. package/src/services/completion-source.js +62 -30
  18. package/src/services/escape-sequence-tracker.js +1 -1
  19. package/src/services/escape-stripper.js +10 -7
  20. package/src/services/file-system.reader.js +2 -1
  21. package/src/services/fish-shell-adapter.js +90 -0
  22. package/src/services/folder-change-line.js +2 -0
  23. package/src/services/line-process.js +3 -2
  24. package/src/services/log-file.js +4 -3
  25. package/src/services/mac-environment.js +5 -2
  26. package/src/services/mark-scanner.js +5 -5
  27. package/src/services/output-batcher.js +1 -1
  28. package/src/services/output-log.js +2 -1
  29. package/src/services/posix-shell-adapter.js +3 -2
  30. package/src/services/printed-text.js +3 -2
  31. package/src/services/pseudo-terminal.js +1 -1
  32. package/src/services/registry-export.js +5 -5
  33. package/src/services/resize-wakeup.js +1 -1
  34. package/src/services/saved-terminals.js +2 -1
  35. package/src/services/shell-adapters.js +3 -1
  36. package/src/services/shell-command.js +7 -2
  37. package/src/services/shell-integration.js +32 -14
  38. package/src/services/shell-locator.js +27 -13
  39. package/src/services/shell-words.js +5 -5
  40. package/src/services/terminal-history-segment.js +1 -1
  41. package/src/services/terminal-host.js +166 -45
  42. package/src/services/terminal-line-reader.js +9 -3
  43. package/src/services/terminal-mirror.js +12 -11
  44. package/src/services/terminal-session.js +24 -8
  45. package/src/services/wsl-distribution.reader.js +5 -2
  46. package/src/services/wsl-shell-adapter.js +6 -2
  47. package/src/tools/models/output-excerpt.js +2 -1
  48. package/src/tools/models/terminal-output-report.js +4 -2
  49. package/src/tools/models/tool-call-context.js +2 -1
  50. package/src/tools/services/terminal-access-policy.js +4 -2
  51. package/src/tools/services/terminal-text-escaper.js +4 -2
  52. package/src/tools/services/terminal-write-tool.js +5 -3
@@ -27,7 +27,7 @@ export class WslDistributionReader {
27
27
  throw new WslDistributionsUnreadableException(error);
28
28
  throw error;
29
29
  }
30
- return WslDistributionReader.parse(output.replace(Resources.wslDistributionReaderByteOrderMark, ""));
30
+ return WslDistributionReader.parse(output.replace(Resources.wslDistributionReaderByteOrderMark, String.empty));
31
31
  }
32
32
  static parse(output) {
33
33
  const lines = output.split(Resources.wslDistributionReaderLineBreak).filter(t => t.length > 0);
@@ -37,7 +37,10 @@ export class WslDistributionReader {
37
37
  const others = [];
38
38
  for (const line of lines) {
39
39
  const [name, flag, ...rest] = line.split(Resources.wslDistributionReaderFieldSeparator);
40
- if (Object.isUndefined(name) || name.length === 0 || !Resources.base64Pattern.test(name) || rest.length > 0 ||
40
+ if (Object.isUndefined(name) ||
41
+ name.length === 0 ||
42
+ !Resources.base64Pattern.test(name) ||
43
+ rest.length > 0 ||
41
44
  (flag !== Resources.wslDefaultFlag && flag !== Resources.wslOtherFlag))
42
45
  throw new WslDistributionsUnreadableException();
43
46
  (flag === Resources.wslDefaultFlag ? defaults : others).push(Buffer.from(name, Resources.base64Encoding).toString(Resources.utf8Encoding));
@@ -47,10 +47,14 @@ export class WslShellAdapter {
47
47
  return value.includes(Resources.windowsSeparator) ? null : `${this.share}${value.replaceAll(Resources.posixSeparator, Resources.windowsSeparator)}`;
48
48
  }
49
49
  readSearchFolders(value) {
50
- return value.split(path.posix.delimiter).filter(t => path.posix.isAbsolute(t) && !t.includes(Resources.windowsSeparator)).map(t => `${this.share}${t.replaceAll(Resources.posixSeparator, Resources.windowsSeparator)}`);
50
+ return value
51
+ .split(path.posix.delimiter)
52
+ .filter(t => path.posix.isAbsolute(t) && !t.includes(Resources.windowsSeparator))
53
+ .map(t => `${this.share}${t.replaceAll(Resources.posixSeparator, Resources.windowsSeparator)}`);
51
54
  }
52
55
  toProgramCall(file, args) {
53
- return new ProgramCall(this.launcher, [Resources.wslDistributionArgument, this.distribution, Resources.wslExecArgument, ...[file, ...args].map(t => this.toShellPath(t))]);
56
+ return new ProgramCall(this.launcher, [Resources.wslDistributionArgument, this.distribution, Resources.wslExecArgument, ...[file, ...args]
57
+ .map(t => this.toShellPath(t))]);
54
58
  }
55
59
  toShellPath(value) {
56
60
  if (!value.toLowerCase().startsWith(`${this.share.toLowerCase()}${Resources.windowsSeparator}`))
@@ -5,6 +5,7 @@
5
5
  * This source code is licensed under the license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ import "@noldova/context.core";
8
9
  import { ArgumentValidator, Resources as ProtocolResources } from "@noldova/terminal.protocol";
9
10
  import { Resources } from "../../resources.js";
10
11
  export class OutputExcerpt {
@@ -13,7 +14,7 @@ export class OutputExcerpt {
13
14
  constructor(output, maximumCharacters, trimmedCharacters = 0) {
14
15
  ArgumentValidator.requireIntegerInRange(Resources.outputExcerptMaximumCharactersField, maximumCharacters, 1, Resources.maximumToolOutputCharacters);
15
16
  ArgumentValidator.requireIntegerInRange(Resources.outputExcerptTrimmedCharactersField, trimmedCharacters, 0, ProtocolResources.maximumOffset);
16
- const trimmed = trimmedCharacters === 0 ? "" : Resources.formatOmittedCharacters(trimmedCharacters);
17
+ const trimmed = trimmedCharacters === 0 ? String.empty : Resources.formatOmittedCharacters(trimmedCharacters);
17
18
  if (output.length <= maximumCharacters) {
18
19
  this.text = trimmed + output;
19
20
  this.omittedCharacters = trimmedCharacters;
@@ -15,7 +15,7 @@ export class TerminalOutputReport {
15
15
  type: Resources.jsonObjectType,
16
16
  additionalProperties: false,
17
17
  required: [
18
- Resources.terminalIdField, Resources.titleField, Resources.nameField, Resources.shellNameField, Resources.terminalOutputReportMethodField, Resources.terminalOutputReportStatusField,
18
+ Resources.terminalIdField, Resources.titleField, Resources.nameField, Resources.shellNameField, Resources.shellField, Resources.terminalOutputReportMethodField, Resources.terminalOutputReportStatusField,
19
19
  Resources.terminalOutputReportExitCodeField, Resources.cwdField, Resources.terminalOutputReportOutputField,
20
20
  Resources.terminalOutputReportOmittedCharactersField, Resources.terminalOutputReportLogFileField, Resources.terminalOutputReportIsAwaitingSecretField
21
21
  ],
@@ -24,6 +24,7 @@ export class TerminalOutputReport {
24
24
  [Resources.titleField]: { type: Resources.jsonStringType },
25
25
  [Resources.nameField]: { type: [Resources.jsonStringType, Resources.jsonNullType], description: Resources.nameFieldDescription },
26
26
  [Resources.shellNameField]: { type: Resources.jsonStringType, description: Resources.shellNameFieldDescription },
27
+ [Resources.shellField]: { type: Resources.jsonStringType, description: Resources.shellIdFieldDescription },
27
28
  [Resources.terminalOutputReportMethodField]: { type: [Resources.jsonStringType, Resources.jsonNullType], enum: [...Object.values(RunMethod), null], description: Resources.methodFieldDescription },
28
29
  [Resources.terminalOutputReportStatusField]: { type: [Resources.jsonStringType, Resources.jsonNullType], enum: [...Object.values(CommandStatus), null], description: Resources.statusFieldDescription },
29
30
  [Resources.terminalOutputReportExitCodeField]: { type: [Resources.jsonIntegerType, Resources.jsonNullType] },
@@ -44,7 +45,7 @@ export class TerminalOutputReport {
44
45
  this.excerpt = excerpt;
45
46
  this.cwd = cwd;
46
47
  }
47
- toResult(note = "") {
48
+ toResult(note = String.empty) {
48
49
  const status = Object.isNull(this.command) ? null : this.command.status;
49
50
  const exitCode = Object.isNull(this.command) ? null : this.command.exitCode;
50
51
  const isAwaitingSecret = this.access.terminal.isAwaitingSecret;
@@ -53,6 +54,7 @@ export class TerminalOutputReport {
53
54
  [Resources.titleField]: this.access.terminal.title,
54
55
  [Resources.nameField]: this.access.terminal.name,
55
56
  [Resources.shellNameField]: this.access.terminal.shellName,
57
+ [Resources.shellField]: this.access.terminal.shellId,
56
58
  [Resources.terminalOutputReportMethodField]: Object.isNull(this.command) ? null : this.command.method,
57
59
  [Resources.terminalOutputReportStatusField]: status,
58
60
  [Resources.terminalOutputReportExitCodeField]: exitCode,
@@ -57,6 +57,7 @@ export class ToolCallContext {
57
57
  }
58
58
  isInsideWorkingFolder(folder) {
59
59
  const path = relative(this.workingFolder, folder);
60
- return path === "" || (path !== Resources.toolCallContextParentFolder && !path.startsWith(`${Resources.toolCallContextParentFolder}${sep}`) && !isAbsolute(path));
60
+ return path === String.empty ||
61
+ (path !== Resources.toolCallContextParentFolder && !path.startsWith(`${Resources.toolCallContextParentFolder}${sep}`) && !isAbsolute(path));
61
62
  }
62
63
  }
@@ -17,7 +17,8 @@ export class TerminalAccessPolicy {
17
17
  }
18
18
  resolve(terminalId, context) {
19
19
  const terminal = this.terminals.find(terminalId);
20
- const access = Object.isUndefined(terminal) ? null
20
+ const access = Object.isUndefined(terminal)
21
+ ? null
21
22
  : TerminalAccessPolicy.accessTo(terminal, context, this.ownerOf(context));
22
23
  if (Object.isNull(access))
23
24
  throw ToolFailures.create(ToolFailureCode.Refused, Resources.notFoundCode, Resources.formatTerminalNotFound(terminalId));
@@ -38,7 +39,8 @@ export class TerminalAccessPolicy {
38
39
  }
39
40
  requireStill(access, context) {
40
41
  const terminal = this.terminals.find(access.terminal.id);
41
- const now = Object.isUndefined(terminal) ? null
42
+ const now = Object.isUndefined(terminal)
43
+ ? null
42
44
  : TerminalAccessPolicy.accessTo(terminal, context, this.ownerOf(context));
43
45
  if (Object.isNull(now) || now.isShared !== access.isShared)
44
46
  throw ToolFailures.create(ToolFailureCode.Stale, Resources.staleCode, Resources.formatTerminalStale(access.terminal.id));
@@ -15,7 +15,7 @@ export class TerminalTextEscaper {
15
15
  return Resources.terminalTextEscaperHiddenCharacters.test(text);
16
16
  }
17
17
  static escape(text) {
18
- let escaped = "";
18
+ let escaped = String.empty;
19
19
  for (const character of text)
20
20
  escaped += TerminalTextEscaper.escapeCharacter(character);
21
21
  return escaped;
@@ -35,7 +35,9 @@ export class TerminalTextEscaper {
35
35
  return character;
36
36
  }
37
37
  static formatCodePoint(character) {
38
- return Resources.formatTerminalTextEscaperCodePoint(Number(character.codePointAt(0)).toString(Resources.hexadecimalRadix).toUpperCase()
38
+ return Resources.formatTerminalTextEscaperCodePoint(Number(character.codePointAt(0))
39
+ .toString(Resources.hexadecimalRadix)
40
+ .toUpperCase()
39
41
  .padStart(Resources.terminalTextEscaperCodePointDigits, Resources.terminalTextEscaperCodePointPad));
40
42
  }
41
43
  }
@@ -24,12 +24,13 @@ export class TerminalWriteTool extends TerminalTool {
24
24
  outputSchema: {
25
25
  type: Resources.jsonObjectType,
26
26
  additionalProperties: false,
27
- required: [Resources.terminalIdField, Resources.titleField, Resources.nameField, Resources.shellNameField],
27
+ required: [Resources.terminalIdField, Resources.titleField, Resources.nameField, Resources.shellNameField, Resources.shellField],
28
28
  properties: {
29
29
  [Resources.terminalIdField]: { type: Resources.jsonStringType },
30
30
  [Resources.titleField]: { type: Resources.jsonStringType },
31
31
  [Resources.nameField]: { type: [Resources.jsonStringType, Resources.jsonNullType], description: Resources.nameFieldDescription },
32
- [Resources.shellNameField]: { type: Resources.jsonStringType, description: Resources.shellNameFieldDescription }
32
+ [Resources.shellNameField]: { type: Resources.jsonStringType, description: Resources.shellNameFieldDescription },
33
+ [Resources.shellField]: { type: Resources.jsonStringType, description: Resources.shellIdFieldDescription }
33
34
  }
34
35
  },
35
36
  hints: { isReadOnly: false, isDestructive: true, isOpenWorld: true },
@@ -61,7 +62,8 @@ export class TerminalWriteTool extends TerminalTool {
61
62
  [Resources.terminalIdField]: input.terminalId,
62
63
  [Resources.titleField]: access.terminal.title,
63
64
  [Resources.nameField]: access.terminal.name,
64
- [Resources.shellNameField]: access.terminal.shellName
65
+ [Resources.shellNameField]: access.terminal.shellName,
66
+ [Resources.shellField]: access.terminal.shellId
65
67
  }, access.origin);
66
68
  }
67
69
  static refuseSecret(access) {