@agent-chat/mention-watcher 0.1.10 → 0.1.11

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.
Files changed (2) hide show
  1. package/dist/watch.js +52 -8
  2. package/package.json +1 -1
package/dist/watch.js CHANGED
@@ -103,13 +103,54 @@ function buildPtyEnv(env) {
103
103
  out[k] = v;
104
104
  }
105
105
  if (!out.PATH && typeof env.PATH === "string") out.PATH = env.PATH;
106
+ if (!out.PATH && typeof env.Path === "string") out.PATH = env.Path;
106
107
  if (!out.HOME && typeof env.HOME === "string") out.HOME = env.HOME;
107
108
  if (!out.SHELL && typeof env.SHELL === "string") out.SHELL = env.SHELL;
108
109
  if (!out.TERM) out.TERM = "xterm-256color";
109
110
  return out;
110
111
  }
112
+ function escapePosixArg(arg) {
113
+ return `'${arg.replace(/'/g, "'\\''")}'`;
114
+ }
115
+ function escapeCmdArg(arg) {
116
+ if (arg.length === 0) return '""';
117
+ if (/[\s"]/g.test(arg)) return `"${arg.replace(/"/g, '\\"')}"`;
118
+ return arg;
119
+ }
120
+ function buildCommandLine(command, args, platform) {
121
+ if (platform === "win32") {
122
+ return [command, ...args].map(escapeCmdArg).join(" ");
123
+ }
124
+ return [command, ...args].map(escapePosixArg).join(" ");
125
+ }
126
+ function getShellFallbackPlan(command, args, env) {
127
+ if (process.platform === "win32") {
128
+ const cmd = env.ComSpec || process.env.ComSpec || "cmd.exe";
129
+ const shellCmd2 = buildCommandLine(command, args, "win32");
130
+ return {
131
+ shell: cmd,
132
+ argv: ["/d", "/s", "/c", shellCmd2],
133
+ display: `${cmd} /d /s /c "${shellCmd2}"`
134
+ };
135
+ }
136
+ const userShell = env.SHELL || process.env.SHELL || "/bin/zsh";
137
+ const shellCmd = `exec ${buildCommandLine(command, args, process.platform)}`;
138
+ return {
139
+ shell: userShell,
140
+ argv: ["-lc", shellCmd],
141
+ display: `${userShell} -lc "${shellCmd}"`
142
+ };
143
+ }
144
+ function hasScriptPtySupport() {
145
+ if (process.platform === "win32") return false;
146
+ return fs.existsSync("/usr/bin/script") || fs.existsSync("/bin/script");
147
+ }
111
148
  function spawnViaScriptPty(command, args, cwd, env) {
112
- const child = spawn("script", ["-q", "/dev/null", command, ...args], {
149
+ if (!hasScriptPtySupport()) {
150
+ throw new Error("script command is not available on this platform");
151
+ }
152
+ const scriptArgs = process.platform === "darwin" ? ["-q", "/dev/null", command, ...args] : ["-q", "-c", buildCommandLine(command, args, process.platform), "/dev/null"];
153
+ const child = spawn("script", scriptArgs, {
113
154
  cwd,
114
155
  env,
115
156
  stdio: ["pipe", "pipe", "pipe"]
@@ -139,7 +180,12 @@ function spawnViaScriptPty(command, args, cwd, env) {
139
180
  };
140
181
  }
141
182
  function spawnWithoutPty(command, args, cwd, env) {
142
- const child = spawn(command, args, { cwd, env, stdio: ["pipe", "pipe", "pipe"] });
183
+ const child = spawn(command, args, {
184
+ cwd,
185
+ env,
186
+ stdio: ["pipe", "pipe", "pipe"],
187
+ shell: process.platform === "win32"
188
+ });
143
189
  return {
144
190
  mode: "plain",
145
191
  write(data) {
@@ -339,21 +385,19 @@ async function main() {
339
385
  `);
340
386
  process.exit(1);
341
387
  }
342
- const userShell = process.env.SHELL || "/bin/zsh";
343
- const quotedArgs = [COMMAND, ...CMD_ARGS].map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
344
- const shellCmd = `exec ${quotedArgs}`;
388
+ const shellPlan = getShellFallbackPlan(COMMAND, CMD_ARGS, ptyEnv);
345
389
  process.stderr.write(
346
- `[mention-watcher] Direct spawn failed, retry via shell: ${userShell} -lc "${shellCmd}"
390
+ `[mention-watcher] Direct spawn failed, retry via shell: ${shellPlan.display}
347
391
  `
348
392
  );
349
393
  try {
350
- const p = pty.spawn(userShell, ["-lc", shellCmd], spawnOptions);
394
+ const p = pty.spawn(shellPlan.shell, shellPlan.argv, spawnOptions);
351
395
  proc = { ...p, mode: "pty" };
352
396
  } catch (shellErr) {
353
397
  const shellMsg = String(shellErr?.message ?? shellErr);
354
398
  process.stderr.write(`[mention-watcher] Shell fallback failed: ${shellMsg}
355
399
  `);
356
- process.stderr.write("[mention-watcher] Falling back to script PTY mode\n");
400
+ process.stderr.write("[mention-watcher] Falling back to script PTY mode (if available)\n");
357
401
  try {
358
402
  proc = spawnViaScriptPty(COMMAND, CMD_ARGS, WORKSPACE_DIR, ptyEnv);
359
403
  } catch (scriptErr) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-chat/mention-watcher",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "PTY wrapper that pushes @mentions from agent-chat into Claude Code (or any LLM CLI)",
5
5
  "type": "module",
6
6
  "bin": {