dsh-bash-terminal-ts 0.6.1 → 0.6.2

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