teapot-coding-agent 0.35.3 → 0.35.5

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.
@@ -208,6 +208,42 @@ function shellEnv() {
208
208
  const { PWD: _pwd, ...rest } = process.env;
209
209
  return { ...rest, TERM: "dumb", GIT_PAGER: "cat", PAGER: "cat" };
210
210
  }
211
+ /**
212
+ * The shell to run a `bash` tool command in, per platform.
213
+ *
214
+ * Both call sites used to hardcode `/bin/bash`, so on Windows every `bash` tool invocation
215
+ * failed with ENOENT — the tool was entirely unavailable on a platform this package claims to
216
+ * support. Windows has no `/bin/bash`; `cmd.exe` is always present, and Git for Windows (which
217
+ * the CI runner has) provides `bash.exe` on PATH.
218
+ *
219
+ * Preference order on Windows: `%TEAPOT_SHELL%`, then `bash.exe` if it is on PATH, then
220
+ * `cmd.exe`. `bash.exe` first because teapot's tool prompts and most commands the model writes
221
+ * are POSIX (`&&`, `$VAR`, single quotes); a `cmd.exe` fallback keeps the tool working on a bare
222
+ * install rather than failing outright.
223
+ *
224
+ * POSIX is unchanged: `$SHELL`, else `/bin/bash`.
225
+ */
226
+ export function toolShellFor(platform, env, exists = existsSync) {
227
+ const override = env.TEAPOT_SHELL?.trim();
228
+ if (override)
229
+ return { file: override, args: (cmd) => ["-c", cmd] };
230
+ if (platform !== "win32") {
231
+ return { file: env.SHELL || "/bin/bash", args: (cmd) => ["-c", cmd] };
232
+ }
233
+ const pathVar = env.PATH ?? "";
234
+ const sep = pathVar.includes(";") ? ";" : ":";
235
+ const hasBash = pathVar
236
+ .split(sep)
237
+ .filter(Boolean)
238
+ .some((dir) => exists(dir.includes("\\") ? `${dir}\\bash.exe` : path.join(dir, "bash.exe")));
239
+ if (hasBash)
240
+ return { file: "bash", args: (cmd) => ["-c", cmd] };
241
+ return { file: env.COMSPEC || "cmd.exe", args: (cmd) => ["/d", "/s", "/c", cmd] };
242
+ }
243
+ /** the shell for THIS process — see `toolShellFor` for the rules and why they exist */
244
+ function toolShell() {
245
+ return toolShellFor(process.platform, process.env);
246
+ }
211
247
  /**
212
248
  * Human-readable elapsed-time suffix appended to a shell result so the MODEL
213
249
  * sees how long a command actually took (#26). Only the operator saw it — the
@@ -229,7 +265,8 @@ function startBackgroundShell(cmd, ctx) {
229
265
  const id = `bg${++bgSeq}`;
230
266
  // plain `-c`, not `-lc`: a login shell sources ~/.bash_profile, whose `cd`
231
267
  // would move background jobs out of the workspace (#34)
232
- const child = spawn("/bin/bash", ["-c", cmd], {
268
+ const shellSpec = toolShell();
269
+ const child = spawn(shellSpec.file, shellSpec.args(cmd), {
233
270
  cwd: ctx.cwd,
234
271
  detached: true,
235
272
  stdio: ["ignore", "pipe", "pipe"],
@@ -379,7 +416,8 @@ function runShell(cmd, ctx, timeoutMs) {
379
416
  // `bash -l` sources /etc/profile + ~/.bash_profile, either of which may
380
417
  // `cd` somewhere — which silently moved every later relative path out of
381
418
  // the workspace (#34). Plain `-c` starts in ctx.cwd and stays there.
382
- const child = spawn("/bin/bash", ["-c", cmd], {
419
+ const sh = toolShell();
420
+ const child = spawn(sh.file, sh.args(cmd), {
383
421
  cwd: ctx.cwd,
384
422
  detached: true, // own process group
385
423
  stdio: ["ignore", "pipe", "pipe"],
@@ -78,8 +78,22 @@ export function createTerminal(agentId, workspace, title) {
78
78
  if (live.length >= MAX_PER_AGENT) {
79
79
  return { ok: false, error: `too many terminals for this agent (max ${MAX_PER_AGENT})` };
80
80
  }
81
- const shell = process.env.SHELL || "/bin/bash";
82
- const hasScript = existsSync("/usr/bin/script");
81
+ /**
82
+ * The shell to run, per platform.
83
+ *
84
+ * `process.env.SHELL || "/bin/bash"` was the whole story, which on Windows spawns a path that
85
+ * does not exist — a terminal tab that opens and immediately dies, on a platform this package
86
+ * claims to support. Windows also has no `script` and no pty (see `hasScript` below), so it
87
+ * gets the plain-pipe path with `cmd.exe` (or `%COMSPEC%`), which is what the fallback branch
88
+ * was always for.
89
+ *
90
+ * `%TEAPOT_SHELL%` overrides on both platforms, so an operator who wants `pwsh` or a specific
91
+ * bash does not have to change their login shell.
92
+ */
93
+ const shell = process.env.TEAPOT_SHELL?.trim() ||
94
+ process.env.SHELL ||
95
+ (process.platform === "win32" ? process.env.COMSPEC || "cmd.exe" : "/bin/bash");
96
+ const hasScript = process.platform !== "win32" && existsSync("/usr/bin/script");
83
97
  // `script` reports a 0x0 winsize, so the shell falls back to these until a client resizes
84
98
  const env = { ...process.env, TERM: "xterm-256color", COLUMNS: "100", LINES: "30" };
85
99
  // `detached` puts the pty provider and the shell it forks into their OWN process group, so
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.35.3",
3
+ "version": "0.35.5",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",