@agent-chat/mention-watcher 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/dist/watch.js +50 -18
  2. package/package.json +1 -1
package/dist/watch.js CHANGED
@@ -59,26 +59,51 @@ function syncMcpToken(workspaceDir, mcpServerName) {
59
59
  }
60
60
  }
61
61
  function resolveShellPath() {
62
- const shell = process.env.SHELL || "/bin/zsh";
63
- const attempts = [
64
- `${shell} -i -c 'echo $PATH'`,
65
- // interactive (sources .zshrc, nvm)
66
- `${shell} -l -c 'echo $PATH'`
67
- // login (sources .zprofile)
68
- ];
69
- for (const cmd of attempts) {
62
+ const parts = new Set((process.env.PATH || "").split(":").filter(Boolean));
63
+ const nvmDir = process.env.NVM_DIR || path.join(os.homedir(), ".nvm");
64
+ const nvmNodeDir = path.join(nvmDir, "versions", "node");
65
+ if (fs.existsSync(nvmNodeDir)) {
70
66
  try {
71
- const raw = execSync(cmd, {
72
- encoding: "utf8",
73
- timeout: 4e3,
74
- stdio: ["ignore", "pipe", "ignore"]
75
- });
76
- const pathLine = raw.split("\n").map((l) => l.trim()).find((l) => l.startsWith("/") && l.includes(":"));
77
- if (pathLine) return pathLine;
67
+ for (const v of fs.readdirSync(nvmNodeDir)) {
68
+ const bin = path.join(nvmNodeDir, v, "bin");
69
+ if (fs.existsSync(bin)) parts.add(bin);
70
+ }
78
71
  } catch {
79
72
  }
80
73
  }
81
- return process.env.PATH || "";
74
+ try {
75
+ const shell = process.env.SHELL || "/bin/zsh";
76
+ const nvmSh = path.join(nvmDir, "nvm.sh");
77
+ const raw = execSync(
78
+ `${shell} -c 'source "${nvmSh}" 2>/dev/null; echo $PATH'`,
79
+ { encoding: "utf8", timeout: 4e3 }
80
+ ).trim();
81
+ for (const p of raw.split(":").filter(Boolean)) parts.add(p);
82
+ } catch {
83
+ }
84
+ for (const p of ["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"]) {
85
+ parts.add(p);
86
+ }
87
+ return [...parts].join(":");
88
+ }
89
+ function findExecutable(cmd, searchPath) {
90
+ if (path.isAbsolute(cmd)) {
91
+ try {
92
+ fs.accessSync(cmd, fs.constants.X_OK);
93
+ return cmd;
94
+ } catch {
95
+ return null;
96
+ }
97
+ }
98
+ for (const dir of searchPath.split(":").filter(Boolean)) {
99
+ const full = path.join(dir, cmd);
100
+ try {
101
+ fs.accessSync(full, fs.constants.X_OK);
102
+ return full;
103
+ } catch {
104
+ }
105
+ }
106
+ return null;
82
107
  }
83
108
  var _WORKSPACE = process.env.WORKSPACE_DIR ?? process.cwd();
84
109
  {
@@ -223,9 +248,14 @@ async function main() {
223
248
  `);
224
249
  const shellPath = resolveShellPath();
225
250
  const spawnEnv = { ...process.env, PATH: shellPath };
251
+ const resolvedCmd = findExecutable(COMMAND, shellPath) ?? COMMAND;
252
+ if (resolvedCmd !== COMMAND) {
253
+ process.stderr.write(`[mention-watcher] Resolved "${COMMAND}" \u2192 ${resolvedCmd}
254
+ `);
255
+ }
226
256
  let proc;
227
257
  try {
228
- proc = pty.spawn(COMMAND, CMD_ARGS, {
258
+ proc = pty.spawn(resolvedCmd, CMD_ARGS, {
229
259
  name: "xterm-256color",
230
260
  cols,
231
261
  rows,
@@ -235,7 +265,9 @@ async function main() {
235
265
  } catch (err) {
236
266
  process.stderr.write(`[mention-watcher] Failed to spawn "${COMMAND}": ${err.message}
237
267
  `);
238
- process.stderr.write(` Run "which ${COMMAND}" in your terminal to check it is installed.
268
+ process.stderr.write(` Run "which ${COMMAND}" in your terminal to confirm it is installed.
269
+ `);
270
+ process.stderr.write(` Searched PATH: ${shellPath}
239
271
  `);
240
272
  process.exit(1);
241
273
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-chat/mention-watcher",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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": {