@noldova/terminal 0.0.11 → 0.0.12
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/module.json +3 -3
- package/package.json +6 -6
- package/src/api/window.d.ts +30 -0
- package/src/api/window.js +1 -1
- package/src/models/completion-candidate.js +8 -1
- package/src/models/describe-group.js +11 -0
- package/src/models/known-description.js +18 -0
- package/src/models/tool-command.js +15 -0
- package/src/models/tool-word.js +15 -0
- package/src/resources.js +237 -0
- package/src/runtime-part.js +2 -1
- package/src/services/command-describer.js +133 -0
- package/src/services/command-tracker.js +3 -0
- package/src/services/completion-source.js +27 -3
- package/src/services/posix-shell-adapter.js +3 -1
- package/src/services/powershell-shell-adapter.js +1 -0
- package/src/services/pseudo-terminal.js +9 -3
- package/src/services/shell-adapters.js +2 -2
- package/src/services/terminal-host.js +23 -8
- package/src/services/terminal-session.js +12 -3
package/module.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "terminal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
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.
|
|
9
|
+
"noldovaDesktop": ">=0.0.29 <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",
|
|
13
13
|
"terminal.ack", "terminal.visibility", "terminal.detach", "terminal.lines", "terminal.restore", "terminal.closeOwner", "terminal.launch",
|
|
14
14
|
"terminal.run", "terminal.runOutput", "terminal.windowStarted", "terminal.showOwner", "terminal.rename",
|
|
15
|
-
"terminal.complete", "terminal.findCommands", "terminal.write", "terminal.changeFolder"
|
|
15
|
+
"terminal.complete", "terminal.findCommands", "terminal.describe", "terminal.write", "terminal.changeFolder"
|
|
16
16
|
],
|
|
17
17
|
"events": [
|
|
18
18
|
"terminal.output", "terminal.exited", "terminal.restarted", "terminal.titleChanged", "terminal.cwdChanged", "terminal.detached",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/terminal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
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",
|
|
@@ -37,18 +37,18 @@
|
|
|
37
37
|
"registry": "https://registry.npmjs.org/"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@noldova/terminal.protocol": "0.0.
|
|
41
|
-
"@noldova/terminal.window": "0.0.
|
|
40
|
+
"@noldova/terminal.protocol": "0.0.12",
|
|
41
|
+
"@noldova/terminal.window": "0.0.12",
|
|
42
42
|
"@xterm/addon-serialize": "0.14.0",
|
|
43
43
|
"@xterm/headless": "6.0.0",
|
|
44
44
|
"node-pty": "1.2.0-beta.15"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@noldova/desktop.protocol": ">=0.0.
|
|
48
|
-
"@noldova/desktop.runtime": ">=0.0.
|
|
47
|
+
"@noldova/desktop.protocol": ">=0.0.29 <0.1.0",
|
|
48
|
+
"@noldova/desktop.runtime": ">=0.0.29 <0.1.0",
|
|
49
49
|
"@noldova/context.core": ">=0.0.18 <0.1.0",
|
|
50
50
|
"@noldova/context.exceptions": ">=0.0.18 <0.1.0",
|
|
51
51
|
"@noldova/context.json": ">=0.0.18 <0.1.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "78f6600e1848b0ee2bde8fb510f0df54ba5f0eec"
|
|
54
54
|
}
|
package/src/api/window.d.ts
CHANGED
|
@@ -58,6 +58,36 @@ export { TerminalWindowException } from "@noldova/terminal.window";
|
|
|
58
58
|
*/
|
|
59
59
|
export { StartFolderProvidedException } from "@noldova/terminal.window";
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* What Toggle Terminal does in a window whose app shows a terminal of its own, from `@noldova/terminal.window`.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import type { IWindowPartContext } from "@noldova/desktop.window";
|
|
67
|
+
* import { TerminalToggle } from "@noldova/terminal/window";
|
|
68
|
+
*
|
|
69
|
+
* export function provideLineToggle(context: IWindowPartContext, line: HTMLElement): () => void {
|
|
70
|
+
* return TerminalToggle.provide(context, () => {
|
|
71
|
+
* line.focus();
|
|
72
|
+
* return true;
|
|
73
|
+
* });
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export { TerminalToggle } from "@noldova/terminal.window";
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Thrown when a window that already has a toggle provider is given another, from `@noldova/terminal.window`.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { ToggleProvidedException } from "@noldova/terminal/window";
|
|
85
|
+
*
|
|
86
|
+
* console.log(new ToggleProvidedException().name);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export { ToggleProvidedException } from "@noldova/terminal.window";
|
|
90
|
+
|
|
61
91
|
/**
|
|
62
92
|
* What an app ties a window's terminals to, such as its chats, from `@noldova/terminal.window`.
|
|
63
93
|
*
|
package/src/api/window.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
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
|
-
export { EmbeddedRowsRefusedException, EmbeddedTerminal, LaunchArgumentRefusedException, LaunchedTab, LaunchedTerminal, LaunchFolderMissingException, LaunchPartInactiveException, LaunchRowsRefusedException, LaunchRowsWithoutTabException, LaunchTitleRefusedException, OwnersProvidedException, RunArgumentRefusedException, RunLinesRefusedException, RunPartInactiveException, RunShellKindsMissingException, StartFolderProvidedException, TerminalEnd, TerminalLaunch, TerminalLauncher, TerminalLaunchRefusedException, TerminalEndedException, TerminalFolderNotFollowedException, TerminalFolderRefusedException, TerminalNotActiveException, TerminalLine, TerminalListener, TerminalOwners, TerminalRun, TerminalRunBusy, TerminalRunEnd, TerminalRunNotFoundException, TerminalRunNotTypedException, TerminalRunOutcome, TerminalRunOutput, TerminalRunRefusedException, TerminalRunTarget, TerminalShellKind, TerminalStartFolder, TerminalTextRun, TerminalTextStyle, TerminalWindowException, TerminalWithoutTabException, windowPart } from "@noldova/terminal.window";
|
|
8
|
+
export { EmbeddedRowsRefusedException, EmbeddedTerminal, LaunchArgumentRefusedException, LaunchedTab, LaunchedTerminal, LaunchFolderMissingException, LaunchPartInactiveException, LaunchRowsRefusedException, LaunchRowsWithoutTabException, LaunchTitleRefusedException, OwnersProvidedException, RunArgumentRefusedException, RunLinesRefusedException, RunPartInactiveException, RunShellKindsMissingException, StartFolderProvidedException, TerminalEnd, TerminalLaunch, TerminalLauncher, TerminalLaunchRefusedException, TerminalEndedException, TerminalFolderNotFollowedException, TerminalFolderRefusedException, TerminalNotActiveException, TerminalLine, TerminalListener, TerminalOwners, TerminalRun, TerminalRunBusy, TerminalRunEnd, TerminalRunNotFoundException, TerminalRunNotTypedException, TerminalRunOutcome, TerminalRunOutput, TerminalRunRefusedException, TerminalRunTarget, TerminalShellKind, TerminalStartFolder, TerminalTextRun, TerminalTextStyle, TerminalToggle, TerminalWindowException, TerminalWithoutTabException, ToggleProvidedException, windowPart } from "@noldova/terminal.window";
|
|
@@ -10,10 +10,17 @@ export class CompletionCandidate {
|
|
|
10
10
|
label;
|
|
11
11
|
kind;
|
|
12
12
|
closesQuote;
|
|
13
|
-
|
|
13
|
+
description;
|
|
14
|
+
rank;
|
|
15
|
+
constructor(value, label, kind, closesQuote, description = null, rank = 0) {
|
|
14
16
|
this.value = value;
|
|
15
17
|
this.label = label;
|
|
16
18
|
this.kind = kind;
|
|
17
19
|
this.closesQuote = closesQuote;
|
|
20
|
+
this.description = description;
|
|
21
|
+
this.rank = rank;
|
|
22
|
+
}
|
|
23
|
+
ranked(rank) {
|
|
24
|
+
return new CompletionCandidate(this.value, this.label, this.kind, this.closesQuote, this.description, rank);
|
|
18
25
|
}
|
|
19
26
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 DescribeGroup {
|
|
9
|
+
names = [];
|
|
10
|
+
answer = Promise.withResolvers();
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
import { Resources } from "../resources.js";
|
|
9
|
+
export class KnownDescription {
|
|
10
|
+
description;
|
|
11
|
+
failedAt = null;
|
|
12
|
+
constructor(description) {
|
|
13
|
+
this.description = description;
|
|
14
|
+
}
|
|
15
|
+
isFresh(now) {
|
|
16
|
+
return Object.isNull(this.failedAt) || now - this.failedAt < Resources.describeRetryMilliseconds;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -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 ToolCommand {
|
|
9
|
+
name;
|
|
10
|
+
words;
|
|
11
|
+
constructor(name, words) {
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.words = words;
|
|
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 ToolWord {
|
|
9
|
+
name;
|
|
10
|
+
description;
|
|
11
|
+
constructor(name, description) {
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.description = description;
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/resources.js
CHANGED
|
@@ -11,6 +11,8 @@ import { MarkKind } from "./enums/mark-kind.js";
|
|
|
11
11
|
import { SystemRequirement } from "./enums/system-requirement.js";
|
|
12
12
|
import { PowerShellCmdlet } from "./models/powershell-cmdlet.js";
|
|
13
13
|
import { PowerShellParameter } from "./models/powershell-parameter.js";
|
|
14
|
+
import { ToolCommand } from "./models/tool-command.js";
|
|
15
|
+
import { ToolWord } from "./models/tool-word.js";
|
|
14
16
|
export class Resources {
|
|
15
17
|
static highWatermark = 1_048_576;
|
|
16
18
|
static lowWatermark = 262_144;
|
|
@@ -24,6 +26,7 @@ export class Resources {
|
|
|
24
26
|
static promptDrawWaitMilliseconds = 10_000;
|
|
25
27
|
static foregroundPollMilliseconds = 50;
|
|
26
28
|
static cursorAnswerMilliseconds = 500;
|
|
29
|
+
static cursorRequestFrameMilliseconds = 100;
|
|
27
30
|
static maximumKeptRuns = 100;
|
|
28
31
|
static scrollback = 1_000;
|
|
29
32
|
static terminalHistoryFlags = "w+";
|
|
@@ -76,6 +79,8 @@ export class Resources {
|
|
|
76
79
|
static windowsPathListSeparator = ";";
|
|
77
80
|
static optionsProperty = "Options=";
|
|
78
81
|
static optionsBound = "1";
|
|
82
|
+
static folderKeysProperty = "FolderKeys=";
|
|
83
|
+
static folderKeysBound = "1";
|
|
79
84
|
static autocdName = "*/";
|
|
80
85
|
static suffixAliasNameStart = "*.";
|
|
81
86
|
static suffixStart = ".";
|
|
@@ -301,12 +306,69 @@ export class Resources {
|
|
|
301
306
|
static npmCommand = "npm";
|
|
302
307
|
static npmRunCommands = ["run", "run-script"];
|
|
303
308
|
static packageFile = "package.json";
|
|
309
|
+
static toolCommands = [
|
|
310
|
+
new ToolCommand("npm", [
|
|
311
|
+
new ToolWord("install", "Install a package and the packages it depends on"), new ToolWord("ci", "Install exactly what package-lock.json locks"),
|
|
312
|
+
new ToolWord("run", "Run a script from package.json"), new ToolWord("test", "Run the test script"), new ToolWord("start", "Run the start script"),
|
|
313
|
+
new ToolWord("stop", "Run the stop script"), new ToolWord("restart", "Run the restart script"), new ToolWord("exec", "Run a command from a package"),
|
|
314
|
+
new ToolWord("uninstall", "Remove a package"), new ToolWord("update", "Update packages to the newest versions their ranges allow"),
|
|
315
|
+
new ToolWord("outdated", "List packages with newer versions"), new ToolWord("ls", "List installed packages"),
|
|
316
|
+
new ToolWord("audit", "Check packages for known vulnerabilities"), new ToolWord("init", "Create a package.json"),
|
|
317
|
+
new ToolWord("pack", "Pack the package into an archive"), new ToolWord("publish", "Publish the package to the registry"),
|
|
318
|
+
new ToolWord("version", "Change the package's version"), new ToolWord("view", "Show a package's registry details"),
|
|
319
|
+
new ToolWord("link", "Link a package folder in place of an installed one"), new ToolWord("prune", "Remove packages nothing depends on"),
|
|
320
|
+
new ToolWord("dedupe", "Reduce duplicate packages"), new ToolWord("rebuild", "Rebuild installed packages"), new ToolWord("cache", "Manage the package cache"),
|
|
321
|
+
new ToolWord("config", "Manage npm's settings"), new ToolWord("explain", "Explain why a package is installed"),
|
|
322
|
+
new ToolWord("search", "Search the registry"), new ToolWord("login", "Sign in to the registry"), new ToolWord("logout", "Sign out of the registry"),
|
|
323
|
+
new ToolWord("whoami", "Show the signed-in user"), new ToolWord("doctor", "Check npm's environment"), new ToolWord("help", "Show npm's help")
|
|
324
|
+
]),
|
|
325
|
+
new ToolCommand("git", [
|
|
326
|
+
new ToolWord("status", "Show the working tree's state"), new ToolWord("add", "Stage changes for the next commit"),
|
|
327
|
+
new ToolWord("commit", "Record the staged changes"), new ToolWord("push", "Send commits to a remote"), new ToolWord("pull", "Fetch and merge from a remote"),
|
|
328
|
+
new ToolWord("fetch", "Download from a remote without merging"), new ToolWord("checkout", "Switch branches or restore files"),
|
|
329
|
+
new ToolWord("switch", "Switch branches"), new ToolWord("branch", "List, create or delete branches"), new ToolWord("merge", "Join another branch into this one"),
|
|
330
|
+
new ToolWord("rebase", "Reapply commits on top of another base"), new ToolWord("log", "Show the commit history"), new ToolWord("diff", "Show changes"),
|
|
331
|
+
new ToolWord("show", "Show a commit or another object"), new ToolWord("restore", "Restore files in the working tree"),
|
|
332
|
+
new ToolWord("reset", "Move the branch to another commit"), new ToolWord("revert", "Record a commit that undoes another"),
|
|
333
|
+
new ToolWord("stash", "Set changes aside"), new ToolWord("tag", "List, create or delete tags"), new ToolWord("remote", "Manage remotes"),
|
|
334
|
+
new ToolWord("clone", "Copy a repository"), new ToolWord("init", "Create a repository"), new ToolWord("cherry-pick", "Apply another commit's changes"),
|
|
335
|
+
new ToolWord("blame", "Show who changed each line"), new ToolWord("clean", "Remove untracked files"), new ToolWord("rm", "Remove files from the index"),
|
|
336
|
+
new ToolWord("mv", "Move or rename a file"), new ToolWord("grep", "Search tracked files"), new ToolWord("bisect", "Find the commit that brought a bug"),
|
|
337
|
+
new ToolWord("reflog", "Show where references have been"), new ToolWord("worktree", "Manage more working trees"), new ToolWord("config", "Manage git's settings")
|
|
338
|
+
]),
|
|
339
|
+
new ToolCommand("dotnet", [
|
|
340
|
+
new ToolWord("build", "Build a project"), new ToolWord("run", "Build and run a project"), new ToolWord("test", "Run a project's tests"),
|
|
341
|
+
new ToolWord("new", "Create a project from a template"), new ToolWord("restore", "Restore a project's dependencies"), new ToolWord("publish", "Publish a project for deployment"),
|
|
342
|
+
new ToolWord("pack", "Pack a project into a NuGet package"), new ToolWord("clean", "Remove a project's build output"), new ToolWord("add", "Add a package or reference"),
|
|
343
|
+
new ToolWord("remove", "Remove a package or reference"), new ToolWord("list", "List a project's packages or references"), new ToolWord("sln", "Manage a solution's projects"),
|
|
344
|
+
new ToolWord("format", "Format code to its style settings"), new ToolWord("watch", "Rebuild and rerun on file changes"), new ToolWord("tool", "Manage .NET tools"),
|
|
345
|
+
new ToolWord("workload", "Manage optional workloads"), new ToolWord("nuget", "Run NuGet commands")
|
|
346
|
+
]),
|
|
347
|
+
new ToolCommand("docker", [
|
|
348
|
+
new ToolWord("run", "Create and start a container"), new ToolWord("ps", "List containers"), new ToolWord("build", "Build an image"),
|
|
349
|
+
new ToolWord("images", "List images"), new ToolWord("pull", "Download an image"), new ToolWord("push", "Upload an image"),
|
|
350
|
+
new ToolWord("exec", "Run a command in a running container"), new ToolWord("logs", "Show a container's logs"), new ToolWord("start", "Start a container"),
|
|
351
|
+
new ToolWord("stop", "Stop a container"), new ToolWord("restart", "Restart a container"), new ToolWord("rm", "Remove a container"),
|
|
352
|
+
new ToolWord("rmi", "Remove an image"), new ToolWord("compose", "Run multi-container applications"), new ToolWord("inspect", "Show an object's details"),
|
|
353
|
+
new ToolWord("cp", "Copy files to or from a container"), new ToolWord("kill", "Kill a running container"), new ToolWord("tag", "Name an image"),
|
|
354
|
+
new ToolWord("network", "Manage networks"), new ToolWord("volume", "Manage volumes"), new ToolWord("system", "Manage Docker itself"),
|
|
355
|
+
new ToolWord("login", "Sign in to a registry"), new ToolWord("logout", "Sign out of a registry")
|
|
356
|
+
])
|
|
357
|
+
];
|
|
358
|
+
static nodeScriptExtensions = [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts"];
|
|
359
|
+
static nodeCommand = "node";
|
|
360
|
+
static npxCommand = "npx";
|
|
361
|
+
static packageBinFolder = ["node_modules", ".bin"];
|
|
362
|
+
static packageBinExtension = /\.(?:cmd|ps1)$/iu;
|
|
304
363
|
static completionCommandMilliseconds = 2_000;
|
|
305
364
|
static completionReadMilliseconds = 1_000;
|
|
306
365
|
static runFolderReadMilliseconds = 1_000;
|
|
307
366
|
static completionConcurrentReads = 2;
|
|
308
367
|
static powerShellOptionsKeys = "\u001b[24~o";
|
|
309
368
|
static zshOptionsKeys = "\u001b[24;7~";
|
|
369
|
+
static powerShellFolderKeys = "\u001b[24~d";
|
|
370
|
+
static zshFolderKeys = "\u001b[23;7~";
|
|
371
|
+
static folderEncoding = "hex";
|
|
310
372
|
static optionsMilliseconds = 500;
|
|
311
373
|
static firstOptionsMilliseconds = 3_500;
|
|
312
374
|
static powerShellLookupMilliseconds = 10_000;
|
|
@@ -316,6 +378,35 @@ export class Resources {
|
|
|
316
378
|
static powerShellLookupModulePathReset = "the session's PSModulePath was reset";
|
|
317
379
|
static powerShellLookupNamesTooLong = "the shell's last list of its names was too long to send";
|
|
318
380
|
static powerShellLookupNamesUnreported = "the shell has sent no list of its names yet";
|
|
381
|
+
static describeMilliseconds = 10_000;
|
|
382
|
+
static maximumDescribedLength = 200;
|
|
383
|
+
static describedNamePattern = /^[\p{L}\p{N}._+@%:,][\p{L}\p{N}._+@%:,-]*$/u;
|
|
384
|
+
static describedSeparator = "\t";
|
|
385
|
+
static whatisScript = "whatis \"$@\" 2>/dev/null; exit 0";
|
|
386
|
+
static whatisScriptName = "describe";
|
|
387
|
+
static whatisDash = /\s+-\s+/u;
|
|
388
|
+
static whatisEntry = /^\s*([^\s(]+)\s*\(([^)]*)\)/u;
|
|
389
|
+
static whatisEntrySeparator = ",";
|
|
390
|
+
static whatisSections = ["1", "8", "6"];
|
|
391
|
+
static whatisRuns = 4;
|
|
392
|
+
static whatisNamesPerRun = 6;
|
|
393
|
+
static describeRetryMilliseconds = 300_000;
|
|
394
|
+
static zshNoStartupArgument = "-f";
|
|
395
|
+
static bashStartupVariable = "BASH_ENV";
|
|
396
|
+
static formatDescribeFailed(count, message) {
|
|
397
|
+
return `The lookup of ${count} ${count === 1 ? "command's description" : "commands' descriptions"} gave up, so they show none: ${message}`;
|
|
398
|
+
}
|
|
399
|
+
static formatPowerShellDescribeScript(names) {
|
|
400
|
+
return `$ErrorActionPreference = 'SilentlyContinue'
|
|
401
|
+
$names = @(${names.map(t => `'${t}'`).join(", ")})
|
|
402
|
+
for ($index = 0; $index -lt $names.Count; $index++) {
|
|
403
|
+
$command = Get-Command -Name $names[$index] | Select-Object -First 1
|
|
404
|
+
if ($command.CommandType -eq 'Alias') { $command = $command.ResolvedCommand }
|
|
405
|
+
if (-not $command) { continue }
|
|
406
|
+
$text = if ($command.CommandType -eq 'Application') { $command.FileVersionInfo.FileDescription } else { (Get-Help -Name $command.Name).Synopsis }
|
|
407
|
+
if ($text -and -not ([string]$text).Trim().StartsWith($command.Name, [StringComparison]::OrdinalIgnoreCase)) { [string]$index + [char]9 + ([string]$text -replace '[\r\n]+', ' ') }
|
|
408
|
+
}`;
|
|
409
|
+
}
|
|
319
410
|
static powerShellLookupNamePattern = /^[\p{L}\p{N}._+@%:,-]+$/u;
|
|
320
411
|
static powerShellImplicitVerb = "Get-";
|
|
321
412
|
static powerShellBuiltins = [
|
|
@@ -325,6 +416,59 @@ export class Resources {
|
|
|
325
416
|
"Select-String", "Set-Content", "Set-Location", "Sort-Object", "Split-Path", "Start-Process", "Stop-Process", "Test-Path", "Where-Object",
|
|
326
417
|
"Write-Host", "Write-Output", "cat", "cd", "cls", "copy", "del", "dir", "echo", "exit", "ls", "md", "move", "pwd", "ren", "rm", "type"
|
|
327
418
|
];
|
|
419
|
+
static powerShellDescriptions = new Map([
|
|
420
|
+
["clear-host", "Clear the screen"],
|
|
421
|
+
["copy-item", "Copy files, folders or other items"],
|
|
422
|
+
["foreach-object", "Run a script block for each object in the pipeline"],
|
|
423
|
+
["get-childitem", "List the files and folders in a location"],
|
|
424
|
+
["get-command", "List the commands PowerShell can run"],
|
|
425
|
+
["get-content", "Read the content of a file"],
|
|
426
|
+
["get-date", "Get the current date and time"],
|
|
427
|
+
["get-help", "Show help about a command or a topic"],
|
|
428
|
+
["get-item", "Get the file, folder or other item at a path"],
|
|
429
|
+
["get-location", "Show the current folder"],
|
|
430
|
+
["get-module", "List the modules loaded or available"],
|
|
431
|
+
["get-process", "List the running processes"],
|
|
432
|
+
["import-module", "Load a module into the session"],
|
|
433
|
+
["invoke-restmethod", "Send a web request and read the response as data"],
|
|
434
|
+
["invoke-webrequest", "Send a web request and get the response"],
|
|
435
|
+
["join-path", "Join a path and a child path into one path"],
|
|
436
|
+
["measure-object", "Count objects or measure their properties"],
|
|
437
|
+
["move-item", "Move or rename files, folders or other items"],
|
|
438
|
+
["new-item", "Create a file, folder or other item"],
|
|
439
|
+
["out-file", "Write the output to a file"],
|
|
440
|
+
["pop-location", "Go back to the folder last saved by Push-Location"],
|
|
441
|
+
["push-location", "Save the current folder and go to another"],
|
|
442
|
+
["remove-item", "Delete files, folders or other items"],
|
|
443
|
+
["rename-item", "Rename an item"],
|
|
444
|
+
["resolve-path", "Resolve wildcards in a path to full paths"],
|
|
445
|
+
["select-object", "Pick properties or objects from the pipeline"],
|
|
446
|
+
["select-string", "Find text in strings or files"],
|
|
447
|
+
["set-content", "Write content to a file, replacing what it held"],
|
|
448
|
+
["set-location", "Change the current folder"],
|
|
449
|
+
["sort-object", "Sort objects by their property values"],
|
|
450
|
+
["split-path", "Get part of a path, such as its parent folder or file name"],
|
|
451
|
+
["start-process", "Start a program or open a file"],
|
|
452
|
+
["stop-process", "Stop running processes"],
|
|
453
|
+
["test-path", "Check whether a path exists"],
|
|
454
|
+
["where-object", "Keep the objects that match a condition"],
|
|
455
|
+
["write-host", "Write text to the screen"],
|
|
456
|
+
["write-output", "Send objects down the pipeline"],
|
|
457
|
+
["cat", "Read the content of a file"],
|
|
458
|
+
["cd", "Change the current folder"],
|
|
459
|
+
["cls", "Clear the screen"],
|
|
460
|
+
["copy", "Copy files, folders or other items"],
|
|
461
|
+
["del", "Delete files, folders or other items"],
|
|
462
|
+
["dir", "List the files and folders in a location"],
|
|
463
|
+
["echo", "Send objects down the pipeline"],
|
|
464
|
+
["ls", "List the files and folders in a location"],
|
|
465
|
+
["move", "Move or rename files, folders or other items"],
|
|
466
|
+
["pwd", "Show the current folder"],
|
|
467
|
+
["ren", "Rename an item"],
|
|
468
|
+
["rm", "Delete files, folders or other items"],
|
|
469
|
+
["type", "Read the content of a file"],
|
|
470
|
+
["md", "Create a folder"]
|
|
471
|
+
]);
|
|
328
472
|
static programFilesVariable = "ProgramFiles";
|
|
329
473
|
static programFilesX86Variable = "ProgramFiles(x86)";
|
|
330
474
|
static localAppDataVariable = "LOCALAPPDATA";
|
|
@@ -350,6 +494,7 @@ export class Resources {
|
|
|
350
494
|
static windowsPowerShellName = "Windows PowerShell";
|
|
351
495
|
static windowsPowerShellPath = ["System32", "WindowsPowerShell", "v1.0", "powershell.exe"];
|
|
352
496
|
static cmdId = "cmd";
|
|
497
|
+
static resizeQuietShellIds = [Resources.windowsPowerShellId, Resources.pwshId, Resources.cmdId];
|
|
353
498
|
static cmdName = "Command Prompt";
|
|
354
499
|
static cmdPath = ["System32", "cmd.exe"];
|
|
355
500
|
static gitBashId = "git-bash";
|
|
@@ -1371,6 +1516,10 @@ Remove-Variable -Name __NoldovaProfile -Scope Global -ErrorAction SilentlyContin
|
|
|
1371
1516
|
$Global:__NoldovaOptionsSent = $Global:__NoldovaOptions
|
|
1372
1517
|
$marks += __NoldovaMark 'P' "${Resources.optionsProperty}$(if ($Global:__NoldovaOptions) { '${Resources.optionsBound}' } else { '0' })"
|
|
1373
1518
|
}
|
|
1519
|
+
if ($Global:__NoldovaFolderKeys -ne $Global:__NoldovaFolderKeysSent) {
|
|
1520
|
+
$Global:__NoldovaFolderKeysSent = $Global:__NoldovaFolderKeys
|
|
1521
|
+
$marks += __NoldovaMark 'P' "${Resources.folderKeysProperty}$(if ($Global:__NoldovaFolderKeys) { '${Resources.folderKeysBound}' } else { '0' })"
|
|
1522
|
+
}
|
|
1374
1523
|
$Global:__NoldovaHistoryId = $historyId
|
|
1375
1524
|
$Global:__NoldovaHasPrompted = $true
|
|
1376
1525
|
$text = (& $Global:__NoldovaPrompt) -join ''
|
|
@@ -1423,15 +1572,59 @@ Remove-Variable -Name __NoldovaProfile -Scope Global -ErrorAction SilentlyContin
|
|
|
1423
1572
|
[Console]::Write("$mark$([char] 0x07)")
|
|
1424
1573
|
}
|
|
1425
1574
|
|
|
1575
|
+
# The hidden folder binding reads the folder as UTF-8 in hex digits up to Enter, which nothing shows, moves there and draws the prompt
|
|
1576
|
+
# again, so no command, history entry or echoed line comes of it. Any other key ends it where it is. The keys come from PSReadLine's own
|
|
1577
|
+
# queue, which its reading thread fills, as Console's would race it for them.
|
|
1578
|
+
function Global:__NoldovaChangeFolder {
|
|
1579
|
+
$hex = ''
|
|
1580
|
+
while ($true) {
|
|
1581
|
+
$char = $Global:__NoldovaReadKey.Invoke($null, $null).KeyChar
|
|
1582
|
+
if ([int] $char -in 10, 13) {
|
|
1583
|
+
break
|
|
1584
|
+
}
|
|
1585
|
+
if ("$char" -cnotmatch '^[0-9a-f]$') {
|
|
1586
|
+
return
|
|
1587
|
+
}
|
|
1588
|
+
$hex += $char
|
|
1589
|
+
}
|
|
1590
|
+
try {
|
|
1591
|
+
$bytes = [byte[]] -split ($hex -replace '..', '0x$& ')
|
|
1592
|
+
Set-Location -LiteralPath ([Text.Encoding]::UTF8.GetString($bytes)) -ErrorAction Stop
|
|
1593
|
+
}
|
|
1594
|
+
catch {
|
|
1595
|
+
}
|
|
1596
|
+
# PSReadLine draws the prompt again through Console, in the console's code page, which would turn the folder's name in the prompt and its
|
|
1597
|
+
# mark into a best fit; the shell draws it through the host, in Unicode.
|
|
1598
|
+
$encoding = [Console]::OutputEncoding
|
|
1599
|
+
try {
|
|
1600
|
+
[Console]::OutputEncoding = New-Object Text.UTF8Encoding $false
|
|
1601
|
+
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
|
|
1602
|
+
}
|
|
1603
|
+
finally {
|
|
1604
|
+
[Console]::OutputEncoding = $encoding
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1426
1608
|
# Only where PSReadLine reads the line, and not where a profile bound F12 or a chord starting with it, which the chord would take over; each
|
|
1427
1609
|
# prompt reports whether it is in place.
|
|
1428
1610
|
$Global:__NoldovaOptions = $false
|
|
1429
1611
|
$Global:__NoldovaOptionsSent = $false
|
|
1612
|
+
$Global:__NoldovaFolderKeys = $false
|
|
1613
|
+
$Global:__NoldovaFolderKeysSent = $false
|
|
1614
|
+
$Global:__NoldovaReadKey = $null
|
|
1430
1615
|
if (Get-Command -Name Set-PSReadLineKeyHandler -ErrorAction SilentlyContinue) {
|
|
1431
1616
|
try {
|
|
1432
1617
|
if (-not (Get-PSReadLineKeyHandler -Bound | Where-Object { $_.Key -eq 'F12' -or $_.Key -like 'F12,*' })) {
|
|
1433
1618
|
Set-PSReadLineKeyHandler -Chord 'F12,o' -ScriptBlock { __NoldovaOptions } -ErrorAction Stop
|
|
1434
1619
|
$Global:__NoldovaOptions = $true
|
|
1620
|
+
# The folder binding reads keys through PSReadLine's own reader, which ConstrainedLanguage refuses and a version without it lacks.
|
|
1621
|
+
if ($ExecutionContext.SessionState.LanguageMode -eq 'FullLanguage') {
|
|
1622
|
+
$Global:__NoldovaReadKey = [Microsoft.PowerShell.PSConsoleReadLine].GetMethod('ReadKey', [Reflection.BindingFlags] 'NonPublic, Static', $null, [Type[]] @(), $null)
|
|
1623
|
+
}
|
|
1624
|
+
if ($null -ne $Global:__NoldovaReadKey) {
|
|
1625
|
+
Set-PSReadLineKeyHandler -Chord 'F12,d' -ScriptBlock { __NoldovaChangeFolder } -ErrorAction Stop
|
|
1626
|
+
$Global:__NoldovaFolderKeys = $true
|
|
1627
|
+
}
|
|
1435
1628
|
}
|
|
1436
1629
|
}
|
|
1437
1630
|
catch {
|
|
@@ -1588,6 +1781,14 @@ if [[ -n "\${__noldova_nonce_read-}" && -z "\${__noldova_nonce-}" ]]; then
|
|
|
1588
1781
|
__noldova_options_sent="$options"
|
|
1589
1782
|
__noldova_mark P "${Resources.optionsProperty}$options"
|
|
1590
1783
|
fi
|
|
1784
|
+
builtin local folder_keys=0
|
|
1785
|
+
if [[ -o zle ]] && (( \${+widgets[__noldova_change_folder]} )); then
|
|
1786
|
+
folder_keys=${Resources.folderKeysBound}
|
|
1787
|
+
fi
|
|
1788
|
+
if [[ "$folder_keys" != "\${__noldova_folder_keys_sent-0}" ]]; then
|
|
1789
|
+
__noldova_folder_keys_sent="$folder_keys"
|
|
1790
|
+
__noldova_mark P "${Resources.folderKeysProperty}$folder_keys"
|
|
1791
|
+
fi
|
|
1591
1792
|
__noldova_escape "$PWD" escaped
|
|
1592
1793
|
__noldova_mark P "Cwd=$escaped"
|
|
1593
1794
|
if (( __noldova_in_command )); then
|
|
@@ -1676,6 +1877,28 @@ if [[ -n "\${__noldova_nonce_read-}" && -z "\${__noldova_nonce-}" ]]; then
|
|
|
1676
1877
|
builtin printf '%s\\007' "$mark"
|
|
1677
1878
|
}
|
|
1678
1879
|
|
|
1880
|
+
# The hidden folder binding reads the folder as UTF-8 in hex digits up to Enter, which nothing shows, moves there, runs the prompt hooks and
|
|
1881
|
+
# draws the prompt again, so no command, history entry or echoed line comes of it. Any other key ends it where it is.
|
|
1882
|
+
__noldova_change_folder() {
|
|
1883
|
+
builtin setopt local_options no_xtrace extended_glob
|
|
1884
|
+
builtin local hex= key folder hook
|
|
1885
|
+
while :; do
|
|
1886
|
+
builtin read -k 1 key || builtin return 0
|
|
1887
|
+
[[ "$key" == $'\\r' || "$key" == $'\\n' ]] && builtin break
|
|
1888
|
+
[[ "$key" == [0-9a-f] ]] || builtin return 0
|
|
1889
|
+
hex+="$key"
|
|
1890
|
+
done
|
|
1891
|
+
builtin printf -v folder '%b' "\${hex//(#m)??/\\\\x$MATCH}"
|
|
1892
|
+
builtin cd -- "$folder" 2>/dev/null
|
|
1893
|
+
if (( \${+functions[precmd]} )); then
|
|
1894
|
+
precmd
|
|
1895
|
+
fi
|
|
1896
|
+
for hook in $precmd_functions; do
|
|
1897
|
+
"$hook"
|
|
1898
|
+
done
|
|
1899
|
+
builtin zle reset-prompt
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1679
1902
|
# Not where the person's startup files bound Ctrl+Alt+F12 in one of the keymaps, which the binding would take over.
|
|
1680
1903
|
if [[ -o zle ]]; then
|
|
1681
1904
|
__noldova_options_free=1
|
|
@@ -1691,6 +1914,20 @@ if [[ -n "\${__noldova_nonce_read-}" && -z "\${__noldova_nonce-}" ]]; then
|
|
|
1691
1914
|
fi
|
|
1692
1915
|
builtin unset __noldova_keymap __noldova_options_free
|
|
1693
1916
|
fi
|
|
1917
|
+
# The folder binding is Ctrl+Alt+F11, on the same terms.
|
|
1918
|
+
if [[ -o zle ]]; then
|
|
1919
|
+
__noldova_folder_free=1
|
|
1920
|
+
for __noldova_keymap in emacs viins vicmd; do
|
|
1921
|
+
[[ "$(builtin bindkey -M "$__noldova_keymap" '\\e[23;7~' 2>/dev/null)" == *' undefined-key' ]] || __noldova_folder_free=0
|
|
1922
|
+
done
|
|
1923
|
+
if (( __noldova_folder_free )); then
|
|
1924
|
+
builtin zle -N __noldova_change_folder
|
|
1925
|
+
for __noldova_keymap in emacs viins vicmd; do
|
|
1926
|
+
builtin bindkey -M "$__noldova_keymap" '\\e[23;7~' __noldova_change_folder
|
|
1927
|
+
done
|
|
1928
|
+
fi
|
|
1929
|
+
builtin unset __noldova_keymap __noldova_folder_free
|
|
1930
|
+
fi
|
|
1694
1931
|
|
|
1695
1932
|
precmd_functions=(__noldova_capture $precmd_functions __noldova_precmd)
|
|
1696
1933
|
preexec_functions+=(__noldova_preexec)
|
package/src/runtime-part.js
CHANGED
|
@@ -14,6 +14,7 @@ import { RequestClient } from "./models/request-client.js";
|
|
|
14
14
|
import { TerminalEvents } from "./models/terminal-events.js";
|
|
15
15
|
import { Resources } from "./resources.js";
|
|
16
16
|
import { AgentTerminals } from "./services/agent-terminals.js";
|
|
17
|
+
import { CommandDescriber } from "./services/command-describer.js";
|
|
17
18
|
import { CommandRunner } from "./services/command-runner.js";
|
|
18
19
|
import { CompletionSource } from "./services/completion-source.js";
|
|
19
20
|
import { ContextPtySpawner } from "./services/context-pty-spawner.js";
|
|
@@ -54,7 +55,7 @@ export class RuntimePart {
|
|
|
54
55
|
environment.start();
|
|
55
56
|
try {
|
|
56
57
|
const events = new TerminalEvents(context.declareEvent(TerminalNames.outputEvent), context.declareEvent(TerminalNames.exitedEvent), context.declareEvent(TerminalNames.restartedEvent), context.declareEvent(TerminalNames.titleChangedEvent), context.declareEvent(TerminalNames.cwdChangedEvent), context.declareEvent(TerminalNames.detachedEvent), context.declareEvent(TerminalNames.closedEvent), context.declareEvent(TerminalNames.openedEvent), context.declareEvent(TerminalNames.launchCommandEndedEvent), context.declareEvent(TerminalNames.runOpenedEvent), context.declareEvent(TerminalNames.runEndedEvent), context.declareEvent(TerminalNames.renamedEvent), context.declareEvent(TerminalNames.commandAddedEvent), context.declareEvent(TerminalNames.commandStartedEvent), context.declareEvent(TerminalNames.outputStartedEvent), context.declareEvent(TerminalNames.outputPrintedEvent), context.declareEvent(TerminalNames.commandEndedEvent), context.declareEvent(TerminalNames.promptStartedEvent), context.declareEvent(TerminalNames.screenChangedEvent));
|
|
57
|
-
const host = new TerminalHost(new ContextPtySpawner(context), reader, new ShellIntegration(writer, tmpdir(), context.log, access, context.settings, process.platform), new TerminalHistoryFolder(writer, reader, signaller, tmpdir(), process.pid, context.log, access), new ShellLocator(process.platform, process.arch, process.env, ShellLocator.readUserShell(), reader, runner, context.log), process.platform, release(), new LatestEnvironment(environment, process.env), homedir(), context.log, events, new SavedTerminals(context.database, context.log), new CompletionSource(reader, runner, process.platform, homedir(), context.log));
|
|
58
|
+
const host = new TerminalHost(new ContextPtySpawner(context), reader, new ShellIntegration(writer, tmpdir(), context.log, access, context.settings, process.platform), new TerminalHistoryFolder(writer, reader, signaller, tmpdir(), process.pid, context.log, access), new ShellLocator(process.platform, process.arch, process.env, ShellLocator.readUserShell(), reader, runner, context.log), process.platform, release(), new LatestEnvironment(environment, process.env), homedir(), context.log, events, new SavedTerminals(context.database, context.log), new CompletionSource(reader, runner, process.platform, homedir(), context.log), new CommandDescriber(runner, context.log));
|
|
58
59
|
for (const name of TerminalNames.methods)
|
|
59
60
|
context.registerMethod(name, { handleAsync: t => host.handleAsync(name, t.payload, RequestClient.fromContext(t)) });
|
|
60
61
|
context.onClientClosed(t => host.closeConnectionAsync(t.connection, t.window));
|
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
import { TerminalCommandDescription, TerminalCommandDescriptions, TerminalShellKind } from "@noldova/terminal.protocol";
|
|
9
|
+
import { CommandFailedException } from "../exceptions/command-failed.exception.js";
|
|
10
|
+
import { DescribeGroup } from "../models/describe-group.js";
|
|
11
|
+
import { KnownDescription } from "../models/known-description.js";
|
|
12
|
+
import { Resources } from "../resources.js";
|
|
13
|
+
export class CommandDescriber {
|
|
14
|
+
runner;
|
|
15
|
+
log;
|
|
16
|
+
known = new Map();
|
|
17
|
+
constructor(runner, log) {
|
|
18
|
+
this.runner = runner;
|
|
19
|
+
this.log = log;
|
|
20
|
+
}
|
|
21
|
+
async describeAsync(kind, program, names, environment) {
|
|
22
|
+
const asked = [...new Set(names)].filter(t => Resources.describedNamePattern.test(t));
|
|
23
|
+
const isPowerShell = kind === TerminalShellKind.PowerShell;
|
|
24
|
+
if (!isPowerShell && kind !== TerminalShellKind.Bash && kind !== TerminalShellKind.Zsh)
|
|
25
|
+
return new TerminalCommandDescriptions([]);
|
|
26
|
+
const perRun = isPowerShell ? Number.POSITIVE_INFINITY : Resources.whatisNamesPerRun;
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
const groups = [];
|
|
29
|
+
const describe = name => {
|
|
30
|
+
const own = isPowerShell ? Resources.powerShellDescriptions.get(name.toLowerCase()) : undefined;
|
|
31
|
+
if (!Object.isUndefined(own))
|
|
32
|
+
return Promise.resolve(own);
|
|
33
|
+
const key = JSON.stringify([kind, program, isPowerShell ? name.toLowerCase() : name]);
|
|
34
|
+
const known = this.known.get(key);
|
|
35
|
+
if (!Object.isUndefined(known) && known.isFresh(now))
|
|
36
|
+
return known.description;
|
|
37
|
+
let group = groups.at(-1);
|
|
38
|
+
if (Object.isUndefined(group) || group.names.length === perRun) {
|
|
39
|
+
group = new DescribeGroup();
|
|
40
|
+
groups.push(group);
|
|
41
|
+
}
|
|
42
|
+
group.names.push(name);
|
|
43
|
+
const entry = new KnownDescription(group.answer.promise.then(t => {
|
|
44
|
+
if (!Object.isNull(t))
|
|
45
|
+
return t.get(name) ?? null;
|
|
46
|
+
entry.failedAt = Date.now();
|
|
47
|
+
return null;
|
|
48
|
+
}, (error) => {
|
|
49
|
+
this.known.delete(key);
|
|
50
|
+
throw error;
|
|
51
|
+
}));
|
|
52
|
+
this.known.set(key, entry);
|
|
53
|
+
return entry.description;
|
|
54
|
+
};
|
|
55
|
+
const pending = asked.map(async (name) => {
|
|
56
|
+
const description = await describe(name);
|
|
57
|
+
return Object.isNull(description) ? null : new TerminalCommandDescription(name, description);
|
|
58
|
+
});
|
|
59
|
+
const shellEnvironment = Object.fromEntries(Object.entries(environment)
|
|
60
|
+
.filter(([t]) => t !== Resources.bashStartupVariable));
|
|
61
|
+
for (let lane = 0; lane < Resources.whatisRuns; lane++)
|
|
62
|
+
void this.runAsync(groups.filter((_t, i) => i % Resources.whatisRuns === lane), kind, program, shellEnvironment);
|
|
63
|
+
const items = await Promise.all(pending);
|
|
64
|
+
return new TerminalCommandDescriptions(items.flatMap(t => Object.isNull(t) ? [] : [t]));
|
|
65
|
+
}
|
|
66
|
+
async runAsync(groups, kind, program, environment) {
|
|
67
|
+
for (const group of groups) {
|
|
68
|
+
try {
|
|
69
|
+
group.answer.resolve(await this.lookUpAsync(kind, program, group.names, environment));
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
group.answer.reject(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async lookUpAsync(kind, program, names, environment) {
|
|
77
|
+
try {
|
|
78
|
+
if (kind === TerminalShellKind.PowerShell) {
|
|
79
|
+
const output = await this.runner.runAsync(program, [...Resources.environmentReadArguments,
|
|
80
|
+
Buffer.from(Resources.formatPowerShellDescribeScript(names), Resources.utf16Encoding).toString(Resources.base64Encoding)], Resources.describeMilliseconds, environment);
|
|
81
|
+
return CommandDescriber.readPowerShell(output, names);
|
|
82
|
+
}
|
|
83
|
+
const output = await this.runner.runAsync(program, [...kind === TerminalShellKind.Zsh ? [Resources.zshNoStartupArgument] : [],
|
|
84
|
+
...Resources.posixOneShotArguments, Resources.whatisScript, Resources.whatisScriptName, ...names], Resources.describeMilliseconds, environment);
|
|
85
|
+
return CommandDescriber.readWhatis(output, names);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (!(error instanceof CommandFailedException))
|
|
89
|
+
throw error;
|
|
90
|
+
this.log.write(Resources.formatDescribeFailed(names.length, error.message));
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
static readPowerShell(output, names) {
|
|
95
|
+
const found = new Map();
|
|
96
|
+
for (const line of output.split(Resources.lineBreaks)) {
|
|
97
|
+
const tab = line.indexOf(Resources.describedSeparator);
|
|
98
|
+
const index = Number(line.slice(0, tab));
|
|
99
|
+
const name = names[index];
|
|
100
|
+
const description = tab > 0 ? CommandDescriber.toLine(line.slice(tab + 1)) : null;
|
|
101
|
+
if (!Object.isUndefined(name) && !Object.isNull(description))
|
|
102
|
+
found.set(name, description);
|
|
103
|
+
}
|
|
104
|
+
return found;
|
|
105
|
+
}
|
|
106
|
+
static readWhatis(output, names) {
|
|
107
|
+
const asked = new Set(names);
|
|
108
|
+
const found = new Map();
|
|
109
|
+
const ranks = new Map();
|
|
110
|
+
for (const line of output.split(Resources.lineBreaks)) {
|
|
111
|
+
const dash = Resources.whatisDash.exec(line);
|
|
112
|
+
const description = Object.isNull(dash) ? null : CommandDescriber.toLine(line.slice(dash.index + dash[0].length));
|
|
113
|
+
if (Object.isNull(dash) || Object.isNull(description))
|
|
114
|
+
continue;
|
|
115
|
+
for (const [index, entry] of line.slice(0, dash.index).split(Resources.whatisEntrySeparator).entries()) {
|
|
116
|
+
const page = Resources.whatisEntry.exec(entry);
|
|
117
|
+
const name = page?.[1] ?? "";
|
|
118
|
+
const section = page?.[2] ?? "";
|
|
119
|
+
const rank = Resources.whatisSections.findIndex(t => section.startsWith(t));
|
|
120
|
+
const order = (rank < 0 ? Resources.whatisSections.length : rank) * 2 + (index === 0 ? 0 : 1);
|
|
121
|
+
if (asked.has(name) && order < (ranks.get(name) ?? Number.POSITIVE_INFINITY)) {
|
|
122
|
+
found.set(name, description);
|
|
123
|
+
ranks.set(name, order);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return found;
|
|
128
|
+
}
|
|
129
|
+
static toLine(text) {
|
|
130
|
+
const line = text.replace(Resources.controlCharacters, " ").replace(Resources.whitespaceRuns, " ").trim();
|
|
131
|
+
return line.length === 0 ? null : [...line].slice(0, Resources.maximumDescribedLength).join("");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -33,6 +33,7 @@ export class CommandTracker {
|
|
|
33
33
|
isNamesReset = false;
|
|
34
34
|
builtins = null;
|
|
35
35
|
hasOptionsBinding = false;
|
|
36
|
+
hasFolderBinding = false;
|
|
36
37
|
isLoaded = false;
|
|
37
38
|
lastCommand = null;
|
|
38
39
|
prompts = 0;
|
|
@@ -128,6 +129,8 @@ export class CommandTracker {
|
|
|
128
129
|
this.builtins = null;
|
|
129
130
|
else if (mark.value?.startsWith(Resources.optionsProperty) === true)
|
|
130
131
|
this.hasOptionsBinding = mark.value.slice(Resources.optionsProperty.length) === Resources.optionsBound;
|
|
132
|
+
else if (mark.value?.startsWith(Resources.folderKeysProperty) === true)
|
|
133
|
+
this.hasFolderBinding = mark.value.slice(Resources.folderKeysProperty.length) === Resources.folderKeysBound;
|
|
131
134
|
break;
|
|
132
135
|
}
|
|
133
136
|
}
|
|
@@ -179,11 +179,11 @@ export class CompletionSource {
|
|
|
179
179
|
const candidates = (await this.listAsync(reads, shell, builtins, shellLine, folder, environment, expandsHome))
|
|
180
180
|
.filter(t => (ignoresCase ? t.value.toLowerCase() : t.value).startsWith(prefix));
|
|
181
181
|
const items = [...new Map(candidates.map(t => [t.value, t])).values()]
|
|
182
|
-
.sort((a, b) => a.label.localeCompare(b.label, Resources.sortLocale))
|
|
182
|
+
.sort((a, b) => a.rank - b.rank || a.label.localeCompare(b.label, Resources.sortLocale))
|
|
183
183
|
.flatMap(t => {
|
|
184
184
|
const text = shell.writeWord(t.value, shellLine.quote, t.closesQuote, escapesWildcards && (t.kind === TerminalCompletionKind.File || t.kind === TerminalCompletionKind.Folder), keepsHome);
|
|
185
185
|
return text.length <= ProtocolResources.maximumPathLength && !ProtocolResources.controlCharacters.test(text)
|
|
186
|
-
? [new TerminalCompletionItem(text, t.label, t.kind)]
|
|
186
|
+
? [new TerminalCompletionItem(text, t.label, t.kind, t.description)]
|
|
187
187
|
: [];
|
|
188
188
|
});
|
|
189
189
|
return new TerminalCompletion(shellLine.start, items.slice(0, ProtocolResources.maximumCompletionItems));
|
|
@@ -198,7 +198,31 @@ export class CompletionSource {
|
|
|
198
198
|
return this.listBranchesAsync(reads, workFolder, environment);
|
|
199
199
|
if (!Object.isNull(workFolder) && words.length === Resources.subcommandWordCount && words[0] === Resources.npmCommand && Resources.npmRunCommands.some(t => shellLine.words[1] === t))
|
|
200
200
|
return this.listScriptsAsync(reads, workFolder);
|
|
201
|
-
|
|
201
|
+
const paths = this.listPathsAsync(reads, shell, shellLine.value, workFolder, expandsHome, temporaryFolder);
|
|
202
|
+
const command = words.length === 1 ? words[0] : undefined;
|
|
203
|
+
if (Object.isUndefined(command) || this.isPath(shellLine.value))
|
|
204
|
+
return paths;
|
|
205
|
+
return this.listToolWordsAsync(reads, command, workFolder, paths);
|
|
206
|
+
}
|
|
207
|
+
async listToolWordsAsync(reads, command, workFolder, paths) {
|
|
208
|
+
const tool = Resources.toolCommands.find(t => t.name === command);
|
|
209
|
+
if (!Object.isUndefined(tool))
|
|
210
|
+
return [...tool.words.map(t => new CompletionCandidate(t.name, t.name, TerminalCompletionKind.Command, true, t.description)), ...(await paths).map(t => t.ranked(1))];
|
|
211
|
+
if (command === Resources.nodeCommand)
|
|
212
|
+
return (await paths).map(t => t.kind === TerminalCompletionKind.File && Resources.nodeScriptExtensions.includes(this.paths.extname(t.label).toLowerCase()) ? t : t.ranked(1));
|
|
213
|
+
if (command === Resources.npxCommand && !Object.isNull(workFolder))
|
|
214
|
+
return [...await this.listPackageBinsAsync(reads, workFolder), ...(await paths).map(t => t.ranked(1))];
|
|
215
|
+
return paths;
|
|
216
|
+
}
|
|
217
|
+
async listPackageBinsAsync(reads, folder) {
|
|
218
|
+
let current = folder;
|
|
219
|
+
for (;;) {
|
|
220
|
+
const entries = await reads.readEntriesAsync(this.paths.join(current, ...Resources.packageBinFolder));
|
|
221
|
+
const names = [...new Set(entries.filter(t => !t.isFolder).map(t => this.isWindows ? t.name.replace(Resources.packageBinExtension, "") : t.name))];
|
|
222
|
+
if (names.length > 0 || this.paths.dirname(current) === current)
|
|
223
|
+
return names.map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Command, true));
|
|
224
|
+
current = this.paths.dirname(current);
|
|
225
|
+
}
|
|
202
226
|
}
|
|
203
227
|
async listPathsAsync(reads, shell, value, workFolder, expandsHome, temporaryFolder) {
|
|
204
228
|
const end = Math.max(value.lastIndexOf(Resources.posixSeparator), this.isWindows ? value.lastIndexOf(Resources.windowsSeparator) : -1);
|
|
@@ -14,11 +14,13 @@ export class PosixShellAdapter {
|
|
|
14
14
|
separator = Resources.posixSeparator;
|
|
15
15
|
takesBareNames;
|
|
16
16
|
optionsKeys;
|
|
17
|
+
folderKeys;
|
|
17
18
|
looksUpMissing = false;
|
|
18
19
|
isGitBash;
|
|
19
|
-
constructor(isWindows, optionsKeys, isBash) {
|
|
20
|
+
constructor(isWindows, optionsKeys, folderKeys, isBash) {
|
|
20
21
|
this.ignoresCase = isWindows;
|
|
21
22
|
this.optionsKeys = optionsKeys;
|
|
23
|
+
this.folderKeys = folderKeys;
|
|
22
24
|
this.isGitBash = isWindows && isBash;
|
|
23
25
|
this.takesBareNames = this.isGitBash;
|
|
24
26
|
}
|
|
@@ -11,18 +11,22 @@ export class PseudoTerminal {
|
|
|
11
11
|
process;
|
|
12
12
|
listener;
|
|
13
13
|
isConPty;
|
|
14
|
+
asksAfterResize;
|
|
14
15
|
heldKeys = [];
|
|
15
16
|
hasExited = false;
|
|
16
17
|
isEnding = false;
|
|
17
18
|
openRequests = 0;
|
|
18
19
|
isResizeAsking = false;
|
|
20
|
+
isRequestShared = false;
|
|
21
|
+
requestTime = Number.NEGATIVE_INFINITY;
|
|
19
22
|
hasOutput = false;
|
|
20
23
|
outputEnd = "";
|
|
21
24
|
answerLimit = undefined;
|
|
22
|
-
constructor(process, listener, isConPty = false) {
|
|
25
|
+
constructor(process, listener, isConPty = false, asksAfterResize = isConPty) {
|
|
23
26
|
this.process = process;
|
|
24
27
|
this.listener = listener;
|
|
25
28
|
this.isConPty = isConPty;
|
|
29
|
+
this.asksAfterResize = isConPty && asksAfterResize;
|
|
26
30
|
this.process.onData(t => {
|
|
27
31
|
this.hasOutput = true;
|
|
28
32
|
if (this.isConPty)
|
|
@@ -65,9 +69,10 @@ export class PseudoTerminal {
|
|
|
65
69
|
if (this.hasExited)
|
|
66
70
|
return;
|
|
67
71
|
this.process.resize(size.columns, size.rows);
|
|
68
|
-
if (!this.
|
|
72
|
+
if (!this.asksAfterResize || !this.hasOutput || this.isResizeAsking)
|
|
69
73
|
return;
|
|
70
74
|
this.isResizeAsking = true;
|
|
75
|
+
this.isRequestShared = Date.now() - this.requestTime < Resources.cursorRequestFrameMilliseconds;
|
|
71
76
|
this.openRequests++;
|
|
72
77
|
this.limitAnswers();
|
|
73
78
|
}
|
|
@@ -93,6 +98,7 @@ export class PseudoTerminal {
|
|
|
93
98
|
this.outputEnd = text.slice(1 - Resources.cursorRequest.length);
|
|
94
99
|
if (requests === 0)
|
|
95
100
|
return;
|
|
101
|
+
this.requestTime = Date.now();
|
|
96
102
|
this.limitAnswers();
|
|
97
103
|
this.openRequests += this.isResizeAsking ? requests - 1 : requests;
|
|
98
104
|
this.isResizeAsking = false;
|
|
@@ -102,7 +108,7 @@ export class PseudoTerminal {
|
|
|
102
108
|
this.answerLimit = setTimeout(() => this.releaseUnanswered(), Resources.cursorAnswerMilliseconds);
|
|
103
109
|
}
|
|
104
110
|
releaseUnanswered() {
|
|
105
|
-
if (this.isResizeAsking)
|
|
111
|
+
if (this.isResizeAsking && !this.isRequestShared)
|
|
106
112
|
this.listener.onResizeUnasked?.();
|
|
107
113
|
this.releaseKeys();
|
|
108
114
|
}
|
|
@@ -15,8 +15,8 @@ export class ShellAdapters {
|
|
|
15
15
|
constructor(isWindows) {
|
|
16
16
|
this.adapters = new Map([
|
|
17
17
|
[TerminalShellKind.PowerShell, new PowerShellShellAdapter(isWindows)],
|
|
18
|
-
[TerminalShellKind.Bash, new PosixShellAdapter(isWindows, null, true)],
|
|
19
|
-
[TerminalShellKind.Zsh, new PosixShellAdapter(isWindows, Resources.zshOptionsKeys, false)]
|
|
18
|
+
[TerminalShellKind.Bash, new PosixShellAdapter(isWindows, null, null, true)],
|
|
19
|
+
[TerminalShellKind.Zsh, new PosixShellAdapter(isWindows, Resources.zshOptionsKeys, Resources.zshFolderKeys, false)]
|
|
20
20
|
]);
|
|
21
21
|
}
|
|
22
22
|
of(kind) {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import "@noldova/context.core";
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
10
|
import { ArgumentException } from "@noldova/context.exceptions";
|
|
11
|
-
import { EndedBy, Resources as ProtocolResources, TerminalAckParams, TerminalChangeFolderParams, TerminalCommandAdded, TerminalCommandEnded, TerminalCompleteParams, TerminalCompletion, TerminalExit, TerminalExited, TerminalFindCommandsParams, TerminalFolderChanged, TerminalInputParams, TerminalLaunched, TerminalLaunchParams, TerminalLinesParams, TerminalName, TerminalNames, TerminalOpenParams, TerminalOwnerReference, TerminalPaneReference, TerminalReference, TerminalResizeParams, TerminalRestartParams, TerminalRestoreParams, TerminalRunBusy, TerminalRunEnded, TerminalRunEndedBy, TerminalRunOutcome, TerminalRunOutputParams, TerminalRunParams, TerminalRunResult, TerminalSessions, TerminalShellKind, TerminalShells, TerminalShowOwnerParams, TerminalSize, TerminalVisibilityParams, TerminalWriteParams, WindowsPty } from "@noldova/terminal.protocol";
|
|
11
|
+
import { EndedBy, Resources as ProtocolResources, TerminalAckParams, TerminalChangeFolderParams, TerminalCommandAdded, TerminalCommandEnded, TerminalCompleteParams, TerminalCompletion, TerminalDescribeParams, TerminalExit, TerminalExited, TerminalFindCommandsParams, TerminalFolderChanged, TerminalInputParams, TerminalLaunched, TerminalLaunchParams, TerminalLinesParams, TerminalName, TerminalNames, TerminalOpenParams, TerminalOwnerReference, TerminalPaneReference, TerminalReference, TerminalResizeParams, TerminalRestartParams, TerminalRestoreParams, TerminalRunBusy, TerminalRunEnded, TerminalRunEndedBy, TerminalRunOutcome, TerminalRunOutputParams, TerminalRunParams, TerminalRunResult, TerminalSessions, TerminalShellKind, TerminalShells, TerminalShowOwnerParams, TerminalSize, TerminalVisibilityParams, TerminalWriteParams, WindowsPty } from "@noldova/terminal.protocol";
|
|
12
12
|
import { AgentTerminalRestartException } from "../exceptions/agent-terminal-restart.exception.js";
|
|
13
13
|
import { SystemRequirement } from "../enums/system-requirement.js";
|
|
14
14
|
import { ConnectionClosingException } from "../exceptions/connection-closing.exception.js";
|
|
@@ -48,6 +48,7 @@ export class TerminalHost {
|
|
|
48
48
|
events;
|
|
49
49
|
saved;
|
|
50
50
|
completions;
|
|
51
|
+
describer;
|
|
51
52
|
folderKeys = new WeakMap();
|
|
52
53
|
realFolderReads = new Map();
|
|
53
54
|
sessions = new Map();
|
|
@@ -63,7 +64,7 @@ export class TerminalHost {
|
|
|
63
64
|
appCloses = new Set();
|
|
64
65
|
closings = new Map();
|
|
65
66
|
closingConnections = new Set();
|
|
66
|
-
constructor(spawner, fileSystem, integration, historyFolder, locator, platform, osRelease, environment, homeFolder, log, events, saved, completions) {
|
|
67
|
+
constructor(spawner, fileSystem, integration, historyFolder, locator, platform, osRelease, environment, homeFolder, log, events, saved, completions, describer) {
|
|
67
68
|
this.spawner = spawner;
|
|
68
69
|
this.fileSystem = fileSystem;
|
|
69
70
|
this.integration = integration;
|
|
@@ -82,6 +83,7 @@ export class TerminalHost {
|
|
|
82
83
|
this.events = events;
|
|
83
84
|
this.saved = saved;
|
|
84
85
|
this.completions = completions;
|
|
86
|
+
this.describer = describer;
|
|
85
87
|
}
|
|
86
88
|
async handleAsync(method, payload, client) {
|
|
87
89
|
this.audience.see(client);
|
|
@@ -144,6 +146,8 @@ export class TerminalHost {
|
|
|
144
146
|
return (await this.completeAsync(TerminalCompleteParams.fromJson(payload), client)).toJson();
|
|
145
147
|
case TerminalNames.findCommandsMethod:
|
|
146
148
|
return (await this.findCommandsAsync(TerminalFindCommandsParams.fromJson(payload), client)).toJson();
|
|
149
|
+
case TerminalNames.describeMethod:
|
|
150
|
+
return (await this.describeAsync(TerminalDescribeParams.fromJson(payload), client)).toJson();
|
|
147
151
|
case TerminalNames.windowStartedMethod:
|
|
148
152
|
if (!Object.isNull(client.window)) {
|
|
149
153
|
this.detachLeftPanes(t => t.connection === client.connection && t.window === client.window && t.page !== client.page);
|
|
@@ -421,9 +425,9 @@ export class TerminalHost {
|
|
|
421
425
|
if (t !== TerminalRunOutcome.Typed || !terminal.session.commands.hasMarks || Object.isNull(terminal.session.commands.promptEndOffset) || terminal.keyCount !== 0)
|
|
422
426
|
this.endLaunchCommand(terminal, null);
|
|
423
427
|
}).catch((error) => this.log.write(Resources.formatLaunchCommandFailed(terminal.session.sessionId, FailureText.read(error))));
|
|
424
|
-
return new TerminalLaunched(terminal.session.sessionId, null, terminal.shell.kind);
|
|
428
|
+
return new TerminalLaunched(terminal.session.sessionId, null, terminal.shell.kind, terminal.session.hasIntegration);
|
|
425
429
|
}
|
|
426
|
-
async typeCommandAsync(terminal, command, isPaste = false, waitsForFit = false, readRefusal = () => null) {
|
|
430
|
+
async typeCommandAsync(terminal, command, isPaste = false, waitsForFit = false, readRefusal = () => null, folderKeys = null) {
|
|
427
431
|
const session = terminal.session;
|
|
428
432
|
const typed = isPaste ? command.replace(Resources.leadingBlankLines, "") : command;
|
|
429
433
|
const pending = new AbortController();
|
|
@@ -456,7 +460,9 @@ export class TerminalHost {
|
|
|
456
460
|
: isPaste && ((waitsForFit ? terminal.keyCount !== keyCount : terminal.inputCount !== inputCount) || !Object.isNull(session.commands.promptEndOffset) && session.readPromptLine() !== "") ? TerminalRunOutcome.Input
|
|
457
461
|
: isPaste && !isBracketed && typed.includes(Resources.tabKey) ? TerminalRunOutcome.Tab
|
|
458
462
|
: readRefusal() ?? TerminalRunOutcome.Typed;
|
|
459
|
-
if (outcome === TerminalRunOutcome.Typed)
|
|
463
|
+
if (outcome === TerminalRunOutcome.Typed && !Object.isNull(folderKeys))
|
|
464
|
+
session.sendFolder(folderKeys, command);
|
|
465
|
+
else if (outcome === TerminalRunOutcome.Typed) {
|
|
460
466
|
const text = isPaste ? TerminalHost.toPaste(typed, isBracketed) : `${command}${Resources.enterKey}`;
|
|
461
467
|
terminal.typedEnds = isBracketed || !isPaste ? 1 : text.split(Resources.enterKey).length - 1;
|
|
462
468
|
terminal.paste = isBracketed ? typed.replace(Resources.whitespace, "") : "";
|
|
@@ -881,6 +887,10 @@ export class TerminalHost {
|
|
|
881
887
|
? this.completions.findMissingPowerShellAsync(terminal.session.commands, terminal.shell.file, params.names, shellNames, environment)
|
|
882
888
|
: this.completions.findMissingAsync(params.sessionId, terminal.session.commands, terminal.session.prompts, terminal.shell.kind, terminal.session.cwd ?? terminal.folder, params.names, shellNames, environment);
|
|
883
889
|
}
|
|
890
|
+
async describeAsync(params, client) {
|
|
891
|
+
const terminal = this.findHosted(params.sessionId, client);
|
|
892
|
+
return await this.describer.describeAsync(terminal.shell.kind, terminal.shell.file, params.names, this.readCompletionEnvironment(terminal));
|
|
893
|
+
}
|
|
884
894
|
readCompletionEnvironment(terminal) {
|
|
885
895
|
const replaced = {};
|
|
886
896
|
if (!Object.isNull(terminal.session.shellPath))
|
|
@@ -1010,7 +1020,9 @@ export class TerminalHost {
|
|
|
1010
1020
|
return new TerminalFolderChanged(null, true);
|
|
1011
1021
|
if (!Object.isNull(terminal.pendingCommand) || !Object.isNull(session.commands.runningCommand))
|
|
1012
1022
|
return new TerminalFolderChanged(null, true, TerminalRunOutcome.Busy);
|
|
1013
|
-
const
|
|
1023
|
+
const folderKeys = session.commands.hasFolderBinding ? this.completions.adapterOf(terminal.shell.kind)?.folderKeys ?? null : null;
|
|
1024
|
+
const before = session.cwd;
|
|
1025
|
+
const outcome = await this.typeCommandAsync(terminal, Object.isNull(folderKeys) ? line : params.folder, false, false, () => TerminalHost.readMoveRefusal(terminal), folderKeys);
|
|
1014
1026
|
if (outcome === TerminalRunOutcome.NoShell)
|
|
1015
1027
|
return new TerminalFolderChanged(null, false);
|
|
1016
1028
|
if (outcome === TerminalRunOutcome.Busy || outcome === TerminalRunOutcome.Input)
|
|
@@ -1018,11 +1030,14 @@ export class TerminalHost {
|
|
|
1018
1030
|
if (outcome !== TerminalRunOutcome.Typed)
|
|
1019
1031
|
throw new SessionNotFoundException(params.sessionId);
|
|
1020
1032
|
const typedAt = session.text.endOffset;
|
|
1021
|
-
const
|
|
1033
|
+
const prompts = session.prompts;
|
|
1034
|
+
const isMoved = () => Object.isNull(folderKeys) ? (session.commands.promptEndOffset ?? typedAt) > typedAt
|
|
1035
|
+
: session.prompts > prompts && !Object.isNull(session.commands.promptEndOffset);
|
|
1022
1036
|
await session.changes.waitUntilAsync(() => session.hasExited || this.sessions.get(params.sessionId) !== terminal || isMoved(), Resources.folderChangeWaitMilliseconds, new AbortController().signal);
|
|
1023
1037
|
if (session.hasExited || this.sessions.get(params.sessionId) !== terminal)
|
|
1024
1038
|
throw new SessionNotFoundException(params.sessionId);
|
|
1025
|
-
|
|
1039
|
+
const isChanged = Object.isNull(folderKeys) ? session.commands.lastCommand?.exitCode === 0 : session.cwd !== before || session.cwd === params.folder;
|
|
1040
|
+
return new TerminalFolderChanged(isMoved() && isChanged ? session.cwd : null, true);
|
|
1026
1041
|
}
|
|
1027
1042
|
static readMoveRefusal(terminal) {
|
|
1028
1043
|
const commands = terminal.session.commands;
|
|
@@ -57,6 +57,7 @@ export class TerminalSession {
|
|
|
57
57
|
text;
|
|
58
58
|
changes = new ChangeSignal();
|
|
59
59
|
hasIntegration;
|
|
60
|
+
hasPrompted = false;
|
|
60
61
|
promptLine = null;
|
|
61
62
|
constructor(sessionId, shellId, size, process, nonce, windowsPty, historyPaths, storedLimit, listener, textLimit, shellKind, marksInput) {
|
|
62
63
|
this.sessionId = sessionId;
|
|
@@ -149,6 +150,11 @@ export class TerminalSession {
|
|
|
149
150
|
}
|
|
150
151
|
this.terminal.write(data);
|
|
151
152
|
}
|
|
153
|
+
sendFolder(keys, folder) {
|
|
154
|
+
this.options.cancel();
|
|
155
|
+
this.beforeInput();
|
|
156
|
+
this.terminal.write(`${keys}${Buffer.from(folder).toString(Resources.folderEncoding)}${Resources.enterKey}`);
|
|
157
|
+
}
|
|
152
158
|
typeLine(text) {
|
|
153
159
|
const line = new TypedLine(this.text.endOffset, text);
|
|
154
160
|
this.typedLines.add(line);
|
|
@@ -233,6 +239,7 @@ export class TerminalSession {
|
|
|
233
239
|
this.terminal.pause();
|
|
234
240
|
this.scanner = Object.isNull(nonce) ? null : new MarkScanner(nonce);
|
|
235
241
|
this.hasIntegration = !Object.isNull(nonce);
|
|
242
|
+
this.hasPrompted = false;
|
|
236
243
|
this.commands = this.trackCommands();
|
|
237
244
|
this.options.reset();
|
|
238
245
|
this.hasAnsweredOptions = false;
|
|
@@ -251,7 +258,7 @@ export class TerminalSession {
|
|
|
251
258
|
this.insert(TerminalSession.toNote(text));
|
|
252
259
|
}
|
|
253
260
|
toSummary(folder, isAgentTerminal, isPanelTerminal, owner, opensTab, name, shellName) {
|
|
254
|
-
return new TerminalSummary(this.sessionId, this.shellId, folder, this.mirror.title, this.exit, isAgentTerminal, isPanelTerminal, owner, opensTab, name, shellName, this.shellKind);
|
|
261
|
+
return new TerminalSummary(this.sessionId, this.shellId, folder, this.mirror.title, this.exit, isAgentTerminal, isPanelTerminal, owner, opensTab, name, shellName, this.shellKind, this.hasIntegration, this.hasPrompted);
|
|
255
262
|
}
|
|
256
263
|
disposeAsync() {
|
|
257
264
|
this.disposal.abort();
|
|
@@ -353,8 +360,10 @@ export class TerminalSession {
|
|
|
353
360
|
const exitCode = this.commands.lastCommand?.exitCode ?? null;
|
|
354
361
|
this.listener.onCommandEnded(new TerminalCommandEnded(this.sessionId, !Object.isNull(exitCode) && exitCode >= ProtocolResources.minimumExitCode && exitCode <= ProtocolResources.maximumExitCode ? exitCode : null));
|
|
355
362
|
}
|
|
356
|
-
else if (mark.kind === MarkKind.PromptStart)
|
|
363
|
+
else if (mark.kind === MarkKind.PromptStart) {
|
|
364
|
+
this.hasPrompted = true;
|
|
357
365
|
this.listener.onPromptStarted(new TerminalReference(this.sessionId));
|
|
366
|
+
}
|
|
358
367
|
const cwd = this.commands.cwd;
|
|
359
368
|
if (Object.isNull(cwd) || cwd === this.reportedCwd || cwd.trim().length === 0 || cwd.length > ProtocolResources.maximumPathLength)
|
|
360
369
|
return;
|
|
@@ -388,7 +397,7 @@ export class TerminalSession {
|
|
|
388
397
|
if (this.terminal === terminal)
|
|
389
398
|
this.wakeup?.beforeInput();
|
|
390
399
|
}
|
|
391
|
-
}, !Object.isNull(this.windowsPty));
|
|
400
|
+
}, !Object.isNull(this.windowsPty), !Resources.resizeQuietShellIds.includes(this.shellId));
|
|
392
401
|
return terminal;
|
|
393
402
|
}
|
|
394
403
|
end(exitCode) {
|