@mario.andreschak/mcp-bash 3.42.1 → 3.44.0

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/dist/tools.d.ts CHANGED
@@ -2,6 +2,8 @@ import { type ChildProcess } from 'node:child_process';
2
2
  import { type IPty } from '@lydell/node-pty';
3
3
  import type { Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
4
4
  export declare const BASH_TERMINAL_APP_URI = "ui://bash/terminal";
5
+ /** Test seam for the public timeout contract; not used by the runtime. */
6
+ export declare function _resolveCommandTimeoutMsForTests(value: unknown): number | undefined;
5
7
  type EffectiveShell = 'pwsh' | 'powershell' | 'bash' | 'cmd' | 'sh';
6
8
  export interface BashToolProgress {
7
9
  progress: number;
@@ -11,6 +13,28 @@ export interface BashExecutionContext {
11
13
  signal?: AbortSignal;
12
14
  onProgress?: (progress: BashToolProgress) => void | Promise<void>;
13
15
  }
16
+ export interface ShellInfoShellEntry {
17
+ shell: string;
18
+ available: boolean;
19
+ path: string | null;
20
+ }
21
+ export interface ShellInfoBinaryEntry {
22
+ name: string;
23
+ found: boolean;
24
+ path: string | null;
25
+ /** Windows Store app-execution alias stub: present on PATH but not runnable. */
26
+ alias?: boolean;
27
+ }
28
+ export interface ShellInfoPayload {
29
+ platform: NodeJS.Platform;
30
+ defaultShell: EffectiveShell;
31
+ defaultShellPath: string | null;
32
+ shells: ShellInfoShellEntry[];
33
+ binaries: ShellInfoBinaryEntry[];
34
+ notes: string[];
35
+ }
36
+ /** Describe the shells and interpreters actually available on this machine. */
37
+ export declare function collectShellInfo(): ShellInfoPayload;
14
38
  /** Test-only: forget cached shell-executable lookups. */
15
39
  export declare function _resetBashShellCacheForTests(): void;
16
40
  interface BashSession {
@@ -22,12 +46,24 @@ interface BashSession {
22
46
  child: ChildProcess;
23
47
  output: string;
24
48
  truncated: boolean;
49
+ /** Characters that arrived on stderr (logging volume, not failure). */
50
+ stderrChars?: number;
25
51
  running: boolean;
26
52
  exitCode: number | null;
27
53
  startedAt: number;
28
54
  endedAt?: number;
29
55
  cancelEscalation?: () => void;
30
56
  reapTimer?: NodeJS.Timeout;
57
+ /** Preflight found a command head that cannot be resolved on PATH. */
58
+ missingExecutableWarning?: boolean;
59
+ /**
60
+ * Explicit opt-in to surviving owner release (issue #413). Default false: a
61
+ * session outliving its run must be a deliberate choice, not the accident that
62
+ * made every `start` a permanent process.
63
+ */
64
+ detached?: boolean;
65
+ /** Last output/read/write — drives idle expiry. */
66
+ lastActivityAt: number;
31
67
  }
32
68
  interface TerminalSession {
33
69
  id: string;
@@ -43,15 +79,92 @@ interface TerminalSession {
43
79
  startedAt: number;
44
80
  endedAt?: number;
45
81
  reapTimer?: NodeJS.Timeout;
82
+ /** Explicit opt-in to surviving owner release (issue #413). */
83
+ detached?: boolean;
84
+ /** Last output/read/write — drives idle expiry. */
85
+ lastActivityAt: number;
46
86
  }
47
87
  declare global {
48
88
  var __flujo_bash_sessions: Map<string, BashSession> | undefined;
49
89
  var __flujo_terminal_sessions: Map<string, TerminalSession> | undefined;
50
90
  var __flujo_bash_foreground_children: Set<ChildProcess> | undefined;
51
91
  var __flujo_bash_cleanup_registered: boolean | undefined;
92
+ var __flujo_bash_sweep_timer: NodeJS.Timeout | undefined;
52
93
  }
53
- /** Kill every live session's process tree — used on FLUJO process exit. */
94
+ export interface OwnerReleaseResult {
95
+ ownerScope: string;
96
+ /** Background session ids that were killed. */
97
+ killedSessions: string[];
98
+ /** PTY session ids that were closed. */
99
+ closedTerminals: string[];
100
+ /** Sessions deliberately left alive because they opted into `detached`. */
101
+ retainedDetached: string[];
102
+ }
103
+ /**
104
+ * Atomically remove and terminate every NON-DETACHED session of one owner.
105
+ *
106
+ * Called when the owning FLUJO run reaches a terminal state. Removing the map
107
+ * entry BEFORE killing means a concurrent release (or a second call from a retry
108
+ * path) cannot observe the same session twice, so the operation is idempotent -
109
+ * repeated releases of the same scope are a no-op instead of a double kill
110
+ * against a possibly-recycled pid.
111
+ */
112
+ export declare function releaseOwnerScope(ownerScope: string): OwnerReleaseResult;
113
+ /**
114
+ * Expire live sessions that exceeded the idle timeout or the absolute lifetime.
115
+ *
116
+ * Detached sessions are exempt from IDLE expiry (being idle is often the point of
117
+ * a detached watcher) but NOT from the absolute lifetime ceiling - otherwise
118
+ * `detached` would be an unbounded leak with extra steps.
119
+ */
120
+ export declare function expireStaleSessions(now?: number): string[];
121
+ /** Bounded per-session diagnostics: identity/state only, never output. */
122
+ export declare function bashSessionDiagnostics(): {
123
+ liveSessions: number;
124
+ maxLiveSessions: number;
125
+ sessions: Array<{
126
+ sessionId: string;
127
+ type: 'background' | 'terminal';
128
+ ownerScope: string;
129
+ running: boolean;
130
+ detached: boolean;
131
+ ageMs: number;
132
+ idleMs: number;
133
+ }>;
134
+ };
135
+ /**
136
+ * Kill every live session's process tree - used on Bash server shutdown and on
137
+ * FLUJO process exit.
138
+ *
139
+ * Idempotent and DETACHED-INCLUSIVE: a detached session survives owner release,
140
+ * but nothing survives the death of the server that owns its pipes. Timers are
141
+ * cleared too, so a repeated call cannot leave a handle keeping the event loop
142
+ * alive after "shutdown".
143
+ */
54
144
  export declare function shutdownBashSessions(): void;
145
+ export declare function wrapPowerShellCommand(command: string): string;
146
+ /** `chcp 65001` forces UTF-8 output for cmd.exe children (issue #364). */
147
+ export declare function wrapCmdCommand(command: string): string;
148
+ export interface OutputAppender {
149
+ (chunk: string): void;
150
+ /** Total characters ever appended, including any omitted middle. */
151
+ totalChars: () => number;
152
+ /** Characters dropped from the middle because of the cap. */
153
+ droppedChars: () => number;
154
+ }
155
+ /** True when the command relies on POSIX `&&` / `||` statement chaining. */
156
+ export declare function commandUsesPosixChaining(command: string): boolean;
157
+ export declare function detectDialectMismatch(command: string, shell: EffectiveShell, isAvailable?: (name: string) => boolean): string[];
158
+ /** Commands that typically hang forever waiting on a pager or interactive prompt. */
159
+ export declare function detectInteractiveHangRisk(command: string): string[];
160
+ export type OutputEncodingMode = 'utf8' | 'utf16le' | 'auto';
161
+ /**
162
+ * Decode child output deterministically (issue #364). Windows tooling happily
163
+ * writes UTF-16LE (e.g. PowerShell redirection into a log) which the default
164
+ * UTF-8 decode turns into NUL-riddled mojibake. `auto` sniffs a BOM or a high
165
+ * NUL ratio in the first chunk and then stays with that choice.
166
+ */
167
+ export declare function createStreamDecoder(mode?: OutputEncodingMode): (chunk: Buffer | string) => string;
55
168
  export declare function bashToolDefinitions(): Tool[];
56
169
  export declare function bashCallTool(toolName: string, args: Record<string, unknown>, callerNodeId?: string, ownerScope?: string, context?: BashExecutionContext): Promise<CallToolResult>;
57
170
  /** Test-only: force-kill and clear all sessions. */