@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.
- package/README.md +1 -1
- package/module.json +2 -2
- package/package.json +10 -8
- package/src/exceptions/stored-lines-damaged.exception.js +2 -1
- package/src/models/hosted-terminal.js +4 -3
- package/src/models/integration-script.js +15 -0
- package/src/models/mark-introducer.js +15 -0
- package/src/models/mark-terminator.js +15 -0
- package/src/models/mirror-line.js +2 -1
- package/src/models/one-shot-launch.js +2 -1
- package/src/models/output-span.js +15 -0
- package/src/models/shell-candidate.js +21 -0
- package/src/models/shell-mark.js +2 -1
- package/src/models/taken-segment.js +15 -0
- package/src/models/terminal-folder-key.js +15 -0
- package/src/models/terminal-opening.js +2 -1
- package/src/models/tracked-command.js +2 -1
- package/src/models/typed-line.js +2 -1
- package/src/models/wsl-launcher.js +15 -0
- package/src/resources.js +7 -3
- package/src/runtime-part.js +2 -1
- package/src/services/agent-terminal.js +4 -3
- package/src/services/agent-terminals.js +3 -2
- package/src/services/bounded-reads.js +7 -5
- package/src/services/change-signal.js +5 -4
- package/src/services/command-tracker.js +5 -4
- package/src/services/completion-source.js +27 -23
- package/src/services/context-pty-process.js +3 -2
- package/src/services/context-pty-spawner.js +2 -1
- package/src/services/deferred-pty-process.js +7 -8
- package/src/services/escape-sequence-tracker.js +2 -1
- package/src/services/failure-text.js +2 -1
- package/src/services/flow-controller.js +5 -4
- package/src/services/latest-environment.js +2 -1
- package/src/services/mac-environment.js +3 -2
- package/src/services/mark-scanner.js +22 -14
- package/src/services/one-shot-command.js +3 -2
- package/src/services/output-batcher.js +2 -1
- package/src/services/output-log.js +4 -1
- package/src/services/powershell-binding.js +7 -6
- package/src/services/pseudo-terminal.js +2 -1
- package/src/services/registry-export.js +3 -2
- package/src/services/resize-wakeup.js +2 -1
- package/src/services/saved-terminals.js +2 -1
- package/src/services/shared-reads.js +3 -2
- package/src/services/shell-command.js +14 -15
- package/src/services/shell-integration.js +24 -22
- package/src/services/shell-locator.js +25 -22
- package/src/services/shell-words.js +3 -2
- package/src/services/system-requirements.js +9 -9
- package/src/services/terminal-audience.js +10 -9
- package/src/services/terminal-history-folder.js +5 -4
- package/src/services/terminal-history-segment.js +2 -1
- package/src/services/terminal-history.js +14 -12
- package/src/services/terminal-host.js +106 -103
- package/src/services/terminal-line-reader.js +3 -2
- package/src/services/terminal-mirror.js +13 -12
- package/src/services/terminal-session.js +21 -21
- package/src/services/visual-studio.reader.js +3 -2
- package/src/services/windows-environment.js +12 -11
- package/src/services/windows-folder-access.js +2 -1
- package/src/services/wsl-distribution.reader.js +2 -1
- package/src/tools/models/agent-terminal-opening.js +2 -1
- package/src/tools/models/output-chunk.js +4 -1
- package/src/tools/models/output-excerpt.js +12 -6
- package/src/tools/models/terminal-open-input.js +3 -2
- package/src/tools/models/terminal-output-report.js +5 -4
- package/src/tools/models/terminal-run-input.js +2 -1
- package/src/tools/models/terminal-target-input.js +2 -1
- package/src/tools/models/terminal-write-input.js +2 -1
- package/src/tools/models/tool-call-context.js +4 -3
- package/src/tools/services/permission-details.js +3 -2
- package/src/tools/services/permission-gate.js +2 -1
- package/src/tools/services/terminal-access-policy.js +8 -7
- package/src/tools/services/terminal-interrupt-tool.js +2 -1
- package/src/tools/services/terminal-read-tool.js +3 -2
- package/src/tools/services/terminal-run-tool.js +6 -5
- package/src/tools/services/terminal-text-escaper.js +2 -1
- package/src/tools/services/terminal-tool.js +2 -1
- 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 { 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
|
|
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
|
|
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
|
|
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
|
|
20
|
+
const access = Object.isUndefined(terminal) ? null
|
|
20
21
|
: TerminalAccessPolicy.accessTo(terminal, context, this.ownerOf(context));
|
|
21
|
-
if (access
|
|
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
|
|
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
|
|
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
|
|
41
|
+
const now = Object.isUndefined(terminal) ? null
|
|
41
42
|
: TerminalAccessPolicy.accessTo(terminal, context, this.ownerOf(context));
|
|
42
|
-
if (now
|
|
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
|
|
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
|
|
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
|
|
49
|
-
const report = new TerminalOutputReport(access, cursor.command,
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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),
|