dsh-bash-terminal-ts 0.2.6 → 0.4.1

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/lib/index.d.ts CHANGED
@@ -1,201 +1,201 @@
1
- import type { BashTerminalContext, ExecAgent, JobsRegistry, JsonSchemaNode, ResolvedPaths, SandboxFacts, SandboxPolicy, ShellId, ToolRunContext } from "./dsh-types.js";
2
- /** Stable Cordis plugin name. */
3
- export declare const name = "bash-terminal";
4
- /** Services required before the tool can register. */
5
- export declare const inject: string[];
6
- /** The terminal backends this tool exposes, in catalog order. */
7
- export declare const SHELLS: readonly ["powershell", "gitbash", "msys2", "wsl"];
8
- /** The backend used when the caller does not name one. */
9
- export declare const DEFAULT_SHELL: ShellId;
10
- /** Settings namespace backing the user-chosen default terminal. */
11
- export declare const SETTINGS_NAMESPACE = "bash-terminal";
12
- /** Static shape of the runtime configuration schema. */
13
- export interface ConfigValues {
14
- defaultShell: string;
15
- timeoutMs: number;
16
- maxTimeoutMs: number;
17
- pwshPath: string;
18
- gitBashPath: string;
19
- msys2Path: string;
20
- wslPath: string;
21
- }
22
- /** Runtime configuration schema. */
23
- export declare const Config: import("./dsh.js").SchemasterySchema;
24
- declare function candidateExists(candidate: string): boolean;
25
- /** Well-known PowerShell install locations plus PATH entries, newest first. */
26
- export declare function candidatePwshPaths(env?: NodeJS.ProcessEnv): string[];
27
- /**
28
- * Git for Windows locations, then PATH bash.exe entries EXCLUDING the
29
- * System32 launcher (c:\\windows\\system32\\bash.exe is the WSL
30
- * forwarder, not a Git Bash shell).
31
- */
32
- export declare function candidateGitBashPaths(env?: NodeJS.ProcessEnv): string[];
33
- /**
34
- * MSYS2 locations, in preference order: the real `bash.exe` under usr\bin first,
35
- * then bin\bash.exe, and `msys2.exe` dead last.
36
- *
37
- * msys2.exe is NOT a usable backend for piped execution: it is the console-
38
- * allocating Cygwin launcher, so a spawn with piped stdio returns exit 0 with
39
- * zero bytes on both stdout and stderr (measured on MSYS2 with bash 5.3.15).
40
- * Keeping it in the list only as a last-resort fallback preserves the path the
41
- * config docs reference, but a working bash.exe always wins.
42
- *
43
- * MSYS2 uses the same Cygwin/MSYS2 runtime as Git Bash, so it cannot run under
44
- * the DSH Windows ACL restricted-token sandbox.
45
- */
46
- export declare function candidateMsys2Paths(env?: NodeJS.ProcessEnv): string[];
47
- export declare function defaultWslPath(env?: NodeJS.ProcessEnv): string;
48
- /** Executable paths, possibly undefined when a backend is not installed. */
49
- export type { ResolvedPaths };
50
- type PathConfig = Partial<Pick<ConfigValues, "pwshPath" | "gitBashPath" | "msys2Path" | "wslPath">>;
51
- export declare function resolveAllPaths(config?: PathConfig, env?: NodeJS.ProcessEnv): ResolvedPaths;
52
- export declare function buildArgv(shell: string, command: string, paths: ResolvedPaths, distro?: string): Array<string | undefined>;
53
- /**
54
- * Merge the DSH_* environment over the process environment. For WSL, only
55
- * variables explicitly listed in WSLENV cross the boundary, so every DSH_* key is
56
- * appended to it (WSLENV is a `:` separated VAR[/flag] list).
57
- *
58
- * WSLENV usually already exists for reasons unrelated to us -- Windows Terminal
59
- * exports e.g. `WT_SESSION:WT_PROFILE_ID:` -- so the list is layered rather than
60
- * rebuilt, or those entries would be silently dropped from every WSL call.
61
- * Callers that spawn through a seam which replaces the parent environment
62
- * wholesale (the PTY path) must pass the inherited value explicitly.
63
- *
64
- * @param inheritedWslenv - the WSLENV the child would otherwise inherit.
65
- */
66
- export declare function buildEnv(shell: string, dshEnv?: Record<string, string>, inheritedWslenv?: string | undefined): Record<string, string | undefined>;
67
- export interface SpawnResolution {
68
- command: string;
69
- workdir: string;
70
- timeoutMs: number;
71
- stdoutMaxBytes: number;
72
- stdin?: string;
73
- }
74
- declare function spawnSpec(resolved: SpawnResolution, argv: string[], env: Record<string, string | undefined>, signal: AbortSignal): {
75
- readonly argv: string[];
76
- readonly cwd: string;
77
- readonly stdio: {
78
- readonly stdin: "ignore" | {
79
- data: string;
80
- };
81
- readonly stdout: {
82
- maxBytes: number;
83
- spill: {
84
- maxBytes: number;
85
- };
86
- };
87
- readonly stderr: {
88
- maxBytes: number;
89
- spill: {
90
- maxBytes: number;
91
- };
92
- };
93
- };
94
- readonly graceMs: 3000;
95
- readonly signal: AbortSignal;
96
- readonly env: Record<string, string | undefined>;
97
- };
98
- interface StreamOutput {
99
- text: string;
100
- truncated: boolean;
101
- spillPath?: string;
102
- }
103
- export interface ForegroundOutcome {
104
- exitCode: number | null;
105
- signal: string | null;
106
- timedOut: boolean;
107
- aborted: boolean;
108
- timeoutMs: number;
109
- stdout: StreamOutput;
110
- stderr: StreamOutput;
111
- }
112
- declare function runForeground(ctx: BashTerminalContext, argv: string[], resolved: SpawnResolution, env: Record<string, string | undefined>, signal: AbortSignal, timeoutMs: number): Promise<ForegroundOutcome>;
113
- export interface ProcessRead {
114
- delta: string;
115
- lossy: boolean;
116
- stdoutSpillPath?: string;
117
- stderrSpillPath?: string;
118
- }
119
- interface BackgroundProc {
120
- status: "running" | "killed" | "completed";
121
- exitCode: number | null;
122
- signal: string | null;
123
- done: Promise<void>;
124
- readOutput(): ProcessRead;
125
- kill(): boolean;
126
- }
127
- declare function startBackground(ctx: BashTerminalContext, argv: string[], resolved: SpawnResolution, env: Record<string, string | undefined>, signal: AbortSignal): BackgroundProc;
128
- declare function processOutcome(proc: BackgroundProc): {
129
- status: string;
130
- detail: string;
131
- };
132
- export interface RenderedResult {
133
- stdout: StreamOutput;
134
- stderr: StreamOutput;
135
- exitCode: number | null;
136
- signal: string | null;
137
- timedOut: boolean;
138
- timeoutMs: number;
139
- }
140
- export declare function renderResult(result: RenderedResult): string;
141
- /** Model-facing lead sentence for each backend. The user's default terminal is
142
- * stated up front so the model never has to guess which syntax applies. */
143
- export declare const SHELL_DESCRIPTIONS: Record<ShellId, string>;
144
- /**
145
- * Render the model-facing tool description for one backend. The backend is
146
- * whatever the user chose in Settings -> General -> Default terminal; the
147
- * description names it explicitly so the model writes the right syntax.
148
- * @param backgroundEnabled - advertise `run_in_background` controls.
149
- * @param shell - active backend; unknown values fall back to the default.
150
- */
151
- export declare function toolDescription(backgroundEnabled: boolean, shell?: string): string;
152
- /** The shell tool's arguments after runtime validation. */
153
- export type ValidatedShellArgs = {
154
- command: string;
155
- description: string;
156
- timeoutMs?: number;
157
- distro?: string;
158
- sandbox_permissions?: string;
159
- justification?: string;
160
- workdir?: string;
161
- run_in_background?: boolean;
162
- stdin?: string;
163
- };
164
- export declare function validateArgs(args: Record<string, unknown>): ValidatedShellArgs;
165
- declare function resolveWorkdir(modelWorkdir: string | undefined, exec: ToolRunContext): string | undefined;
166
- export interface ForegroundResult {
167
- kind: "foreground";
168
- exitCode: number | null;
169
- signal: string | null;
170
- timedOut: boolean;
171
- aborted: boolean;
172
- timeoutMs: number;
173
- stdout: StreamOutput;
174
- stderr: StreamOutput;
175
- sandbox?: SandboxFacts;
176
- }
177
- export interface BackgroundResult {
178
- kind: "background";
179
- jobId: string;
180
- }
181
- export type ShellToolResult = ForegroundResult | BackgroundResult;
182
- export declare function apply(ctx: BashTerminalContext, config?: Partial<ConfigValues>): void;
183
- export declare const internals: {
184
- candidateExists: typeof candidateExists;
185
- resolveAllPaths: typeof resolveAllPaths;
186
- resolveWorkdir: typeof resolveWorkdir;
187
- renderResult: typeof renderResult;
188
- processOutcome: typeof processOutcome;
189
- startBackground: typeof startBackground;
190
- runForeground: typeof runForeground;
191
- spawnSpec: typeof spawnSpec;
192
- buildEnv: typeof buildEnv;
193
- buildArgv: typeof buildArgv;
194
- validateArgs: typeof validateArgs;
195
- toolDescription: typeof toolDescription;
196
- SHELL_DESCRIPTIONS: Record<ShellId, string>;
197
- DEFAULT_TIMEOUT_MS: number;
198
- MAX_TIMEOUT_MS: number;
199
- DEFAULT_MAX_OUTPUT_BYTES: number;
200
- };
201
- export type { ExecAgent, JobsRegistry, JsonSchemaNode, SandboxFacts, SandboxPolicy, ShellId, ToolRunContext };
1
+ import type { BashTerminalContext, ExecAgent, JobsRegistry, JsonSchemaNode, ResolvedPaths, SandboxFacts, SandboxPolicy, ShellId, ToolRunContext } from "./dsh-types.js";
2
+ /** Stable Cordis plugin name. */
3
+ export declare const name = "bash-terminal";
4
+ /** Services required before the tool can register. */
5
+ export declare const inject: string[];
6
+ /** The terminal backends this tool exposes, in catalog order. */
7
+ export declare const SHELLS: readonly ["powershell", "gitbash", "msys2", "wsl"];
8
+ /** The backend used when the caller does not name one. */
9
+ export declare const DEFAULT_SHELL: ShellId;
10
+ /** Settings namespace backing the user-chosen default terminal. */
11
+ export declare const SETTINGS_NAMESPACE = "bash-terminal";
12
+ /** Static shape of the runtime configuration schema. */
13
+ export interface ConfigValues {
14
+ defaultShell: string;
15
+ timeoutMs: number;
16
+ maxTimeoutMs: number;
17
+ pwshPath: string;
18
+ gitBashPath: string;
19
+ msys2Path: string;
20
+ wslPath: string;
21
+ }
22
+ /** Runtime configuration schema. */
23
+ export declare const Config: import("./dsh.js").SchemasterySchema;
24
+ declare function candidateExists(candidate: string): boolean;
25
+ /** Well-known PowerShell install locations plus PATH entries, newest first. */
26
+ export declare function candidatePwshPaths(env?: NodeJS.ProcessEnv): string[];
27
+ /**
28
+ * Git for Windows locations, then PATH bash.exe entries EXCLUDING the
29
+ * System32 launcher (c:\\windows\\system32\\bash.exe is the WSL
30
+ * forwarder, not a Git Bash shell).
31
+ */
32
+ export declare function candidateGitBashPaths(env?: NodeJS.ProcessEnv): string[];
33
+ /**
34
+ * MSYS2 locations, in preference order: the real `bash.exe` under usr\bin first,
35
+ * then bin\bash.exe, and `msys2.exe` dead last.
36
+ *
37
+ * msys2.exe is NOT a usable backend for piped execution: it is the console-
38
+ * allocating Cygwin launcher, so a spawn with piped stdio returns exit 0 with
39
+ * zero bytes on both stdout and stderr (measured on MSYS2 with bash 5.3.15).
40
+ * Keeping it in the list only as a last-resort fallback preserves the path the
41
+ * config docs reference, but a working bash.exe always wins.
42
+ *
43
+ * MSYS2 uses the same Cygwin/MSYS2 runtime as Git Bash, so it cannot run under
44
+ * the DSH Windows ACL restricted-token sandbox.
45
+ */
46
+ export declare function candidateMsys2Paths(env?: NodeJS.ProcessEnv): string[];
47
+ export declare function defaultWslPath(env?: NodeJS.ProcessEnv): string;
48
+ /** Executable paths, possibly undefined when a backend is not installed. */
49
+ export type { ResolvedPaths };
50
+ type PathConfig = Partial<Pick<ConfigValues, "pwshPath" | "gitBashPath" | "msys2Path" | "wslPath">>;
51
+ export declare function resolveAllPaths(config?: PathConfig, env?: NodeJS.ProcessEnv): ResolvedPaths;
52
+ export declare function buildArgv(shell: string, command: string, paths: ResolvedPaths, distro?: string): Array<string | undefined>;
53
+ /**
54
+ * Merge the DSH_* environment over the process environment. For WSL, only
55
+ * variables explicitly listed in WSLENV cross the boundary, so every DSH_* key is
56
+ * appended to it (WSLENV is a `:` separated VAR[/flag] list).
57
+ *
58
+ * WSLENV usually already exists for reasons unrelated to us -- Windows Terminal
59
+ * exports e.g. `WT_SESSION:WT_PROFILE_ID:` -- so the list is layered rather than
60
+ * rebuilt, or those entries would be silently dropped from every WSL call.
61
+ * Callers that spawn through a seam which replaces the parent environment
62
+ * wholesale (the PTY path) must pass the inherited value explicitly.
63
+ *
64
+ * @param inheritedWslenv - the WSLENV the child would otherwise inherit.
65
+ */
66
+ export declare function buildEnv(shell: string, dshEnv?: Record<string, string>, inheritedWslenv?: string | undefined): Record<string, string | undefined>;
67
+ export interface SpawnResolution {
68
+ command: string;
69
+ workdir: string;
70
+ timeoutMs: number;
71
+ stdoutMaxBytes: number;
72
+ stdin?: string;
73
+ }
74
+ declare function spawnSpec(resolved: SpawnResolution, argv: string[], env: Record<string, string | undefined>, signal: AbortSignal): {
75
+ readonly argv: string[];
76
+ readonly cwd: string;
77
+ readonly stdio: {
78
+ readonly stdin: "ignore" | {
79
+ data: string;
80
+ };
81
+ readonly stdout: {
82
+ maxBytes: number;
83
+ spill: {
84
+ maxBytes: number;
85
+ };
86
+ };
87
+ readonly stderr: {
88
+ maxBytes: number;
89
+ spill: {
90
+ maxBytes: number;
91
+ };
92
+ };
93
+ };
94
+ readonly graceMs: 3000;
95
+ readonly signal: AbortSignal;
96
+ readonly env: Record<string, string | undefined>;
97
+ };
98
+ interface StreamOutput {
99
+ text: string;
100
+ truncated: boolean;
101
+ spillPath?: string;
102
+ }
103
+ export interface ForegroundOutcome {
104
+ exitCode: number | null;
105
+ signal: string | null;
106
+ timedOut: boolean;
107
+ aborted: boolean;
108
+ timeoutMs: number;
109
+ stdout: StreamOutput;
110
+ stderr: StreamOutput;
111
+ }
112
+ declare function runForeground(ctx: BashTerminalContext, argv: string[], resolved: SpawnResolution, env: Record<string, string | undefined>, signal: AbortSignal, timeoutMs: number): Promise<ForegroundOutcome>;
113
+ export interface ProcessRead {
114
+ delta: string;
115
+ lossy: boolean;
116
+ stdoutSpillPath?: string;
117
+ stderrSpillPath?: string;
118
+ }
119
+ interface BackgroundProc {
120
+ status: "running" | "killed" | "completed";
121
+ exitCode: number | null;
122
+ signal: string | null;
123
+ done: Promise<void>;
124
+ readOutput(): ProcessRead;
125
+ kill(): boolean;
126
+ }
127
+ declare function startBackground(ctx: BashTerminalContext, argv: string[], resolved: SpawnResolution, env: Record<string, string | undefined>, signal: AbortSignal): BackgroundProc;
128
+ declare function processOutcome(proc: BackgroundProc): {
129
+ status: string;
130
+ detail: string;
131
+ };
132
+ export interface RenderedResult {
133
+ stdout: StreamOutput;
134
+ stderr: StreamOutput;
135
+ exitCode: number | null;
136
+ signal: string | null;
137
+ timedOut: boolean;
138
+ timeoutMs: number;
139
+ }
140
+ export declare function renderResult(result: RenderedResult): string;
141
+ /** Model-facing lead sentence for each backend. The user's default terminal is
142
+ * stated up front so the model never has to guess which syntax applies. */
143
+ export declare const SHELL_DESCRIPTIONS: Record<ShellId, string>;
144
+ /**
145
+ * Render the model-facing tool description for one backend. The backend is
146
+ * whatever the user chose in Settings -> General -> Default terminal; the
147
+ * description names it explicitly so the model writes the right syntax.
148
+ * @param backgroundEnabled - advertise `run_in_background` controls.
149
+ * @param shell - active backend; unknown values fall back to the default.
150
+ */
151
+ export declare function toolDescription(backgroundEnabled: boolean, shell?: string): string;
152
+ /** The shell tool's arguments after runtime validation. */
153
+ export type ValidatedShellArgs = {
154
+ command: string;
155
+ description: string;
156
+ timeoutMs?: number;
157
+ distro?: string;
158
+ sandbox_permissions?: string;
159
+ justification?: string;
160
+ workdir?: string;
161
+ run_in_background?: boolean;
162
+ stdin?: string;
163
+ };
164
+ export declare function validateArgs(args: Record<string, unknown>): ValidatedShellArgs;
165
+ declare function resolveWorkdir(modelWorkdir: string | undefined, exec: ToolRunContext): string | undefined;
166
+ export interface ForegroundResult {
167
+ kind: "foreground";
168
+ exitCode: number | null;
169
+ signal: string | null;
170
+ timedOut: boolean;
171
+ aborted: boolean;
172
+ timeoutMs: number;
173
+ stdout: StreamOutput;
174
+ stderr: StreamOutput;
175
+ sandbox?: SandboxFacts;
176
+ }
177
+ export interface BackgroundResult {
178
+ kind: "background";
179
+ jobId: string;
180
+ }
181
+ export type ShellToolResult = ForegroundResult | BackgroundResult;
182
+ export declare function apply(ctx: BashTerminalContext, config?: Partial<ConfigValues>): void;
183
+ export declare const internals: {
184
+ candidateExists: typeof candidateExists;
185
+ resolveAllPaths: typeof resolveAllPaths;
186
+ resolveWorkdir: typeof resolveWorkdir;
187
+ renderResult: typeof renderResult;
188
+ processOutcome: typeof processOutcome;
189
+ startBackground: typeof startBackground;
190
+ runForeground: typeof runForeground;
191
+ spawnSpec: typeof spawnSpec;
192
+ buildEnv: typeof buildEnv;
193
+ buildArgv: typeof buildArgv;
194
+ validateArgs: typeof validateArgs;
195
+ toolDescription: typeof toolDescription;
196
+ SHELL_DESCRIPTIONS: Record<ShellId, string>;
197
+ DEFAULT_TIMEOUT_MS: number;
198
+ MAX_TIMEOUT_MS: number;
199
+ DEFAULT_MAX_OUTPUT_BYTES: number;
200
+ };
201
+ export type { ExecAgent, JobsRegistry, JsonSchemaNode, SandboxFacts, SandboxPolicy, ShellId, ToolRunContext };