@qlairoslabs/acp-client 0.3.2 → 0.3.3

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/README.md CHANGED
@@ -263,9 +263,14 @@ agents route their shell commands through `terminal/create` and read/write files
263
263
  event, so `content` entries of type `terminal` come with `output`, `truncated` and
264
264
  `exitStatus` filled in.
265
265
 
266
- Commands run as child processes of your app, with your environment. To opt out — letting
267
- the agent fall back to its own implementation — turn the capability off, which also stops
268
- us advertising it:
266
+ Commands run as child processes of your app, with your environment. When the agent sends
267
+ `args`, they are spawned exactly as given; when it sends none, `command` is treated as a
268
+ shell line and run through `bash` (or `/bin/sh`), because that is how agents use it —
269
+ `claude-code-acp` puts its whole Bash command line, redirections and all, in `command`.
270
+ Set `ACP_TERMINAL_SHELL` to choose a different shell.
271
+
272
+ To opt out — letting the agent fall back to its own implementation — turn the capability
273
+ off, which also stops us advertising it:
269
274
 
270
275
  ```ts
271
276
  new AcpClient({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlairoslabs/acp-client",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Embeddable Agent Client Protocol (ACP) client library with degraded PTY fallback.",
5
5
  "type": "module",
6
6
  "module": "src/index.ts",
package/src/terminals.ts CHANGED
@@ -68,6 +68,39 @@ interface Entry {
68
68
  */
69
69
  const DRAIN_GRACE_MS = 250;
70
70
 
71
+ /**
72
+ * The shell used when the agent hands us a command LINE.
73
+ *
74
+ * NOT `$SHELL`: that is the user's INTERACTIVE shell, which may be fish or nushell, and
75
+ * agents generate bash/POSIX syntax — `printf x >&2` is a syntax error in fish. Prefer
76
+ * bash, because agents write bashisms (`[[ ]]`, arrays) and `/bin/sh` is dash on Debian
77
+ * and Ubuntu, where those fail. Fall back to `/bin/sh`, which always exists.
78
+ */
79
+ const SHELL = process.env.ACP_TERMINAL_SHELL || Bun.which("bash") || "/bin/sh";
80
+
81
+ /**
82
+ * Turn a `terminal/create` request into an argv.
83
+ *
84
+ * The spec is ambiguous — "The command to execute" plus an optional "Array of command
85
+ * arguments" — and agents read it both ways. `claude-code-acp` puts its ENTIRE Bash command
86
+ * line in `command` and sends no `args` at all, so spawning `command` as an executable path
87
+ * failed every shell tool call it made: `Executable not found in $PATH: "printf 'ran' >
88
+ * shell.txt"`. Redirections, pipes and `&&` were unreachable, and so was a plain command
89
+ * that merely carried its own arguments.
90
+ *
91
+ * So: with `args`, the agent has already done the splitting and its arguments are final —
92
+ * spawn directly, because re-splitting would turn one argument containing a space into two.
93
+ * Without them, `command` is a line for a shell. The two readings never overlap, and for a
94
+ * bare program name they agree (`sh -c "ls"` and spawning `ls` do the same thing).
95
+ *
96
+ * The cost: a command line is subject to word splitting, so an agent sending an unquoted
97
+ * executable path containing spaces and no `args` would break. That shape is much rarer
98
+ * than the one this fixes, and quoting it here would corrupt every genuine command line.
99
+ */
100
+ function toArgv(params: CreateTerminalParams): string[] {
101
+ return params.args?.length ? [params.command, ...params.args] : [SHELL, "-c", params.command];
102
+ }
103
+
71
104
  export class TerminalRegistry {
72
105
  private readonly terminals = new Map<string, Entry>();
73
106
  private seq = 0;
@@ -86,7 +119,7 @@ export class TerminalRegistry {
86
119
  };
87
120
  for (const v of params.env ?? []) env[v.name] = v.value;
88
121
 
89
- const proc = Bun.spawn([params.command, ...(params.args ?? [])], {
122
+ const proc = Bun.spawn(toArgv(params), {
90
123
  cwd: params.cwd ?? this.options.cwd,
91
124
  env,
92
125
  stdin: "ignore",