@agent-chat/mention-watcher 0.1.2 → 0.1.8
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/watch.js +6 -58
- package/package.json +1 -1
package/dist/watch.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import * as fs from "fs";
|
|
5
5
|
import * as path from "path";
|
|
6
6
|
import * as os from "os";
|
|
7
|
-
import { execSync } from "child_process";
|
|
8
7
|
import * as pty from "node-pty";
|
|
9
8
|
import { WebSocket } from "ws";
|
|
10
9
|
function loadEnvFile(filePath) {
|
|
@@ -58,53 +57,6 @@ function syncMcpToken(workspaceDir, mcpServerName) {
|
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
function resolveShellPath() {
|
|
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)) {
|
|
66
|
-
try {
|
|
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
|
-
}
|
|
71
|
-
} catch {
|
|
72
|
-
}
|
|
73
|
-
}
|
|
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;
|
|
107
|
-
}
|
|
108
60
|
var _WORKSPACE = process.env.WORKSPACE_DIR ?? process.cwd();
|
|
109
61
|
{
|
|
110
62
|
const dirsToCheck = [.../* @__PURE__ */ new Set([process.cwd(), _WORKSPACE])];
|
|
@@ -246,28 +198,24 @@ async function main() {
|
|
|
246
198
|
`);
|
|
247
199
|
process.stderr.write(`[mention-watcher] Spawning: ${COMMAND} ${CMD_ARGS.join(" ")}
|
|
248
200
|
`);
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
process.stderr.write(`[mention-watcher] Resolved "${COMMAND}" \u2192 ${resolvedCmd}
|
|
201
|
+
const userShell = process.env.SHELL || "/bin/zsh";
|
|
202
|
+
const quotedArgs = [COMMAND, ...CMD_ARGS].map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
|
203
|
+
const shellCmd = `exec ${quotedArgs}`;
|
|
204
|
+
process.stderr.write(`[mention-watcher] Spawning via: ${userShell} -l -c "${shellCmd}"
|
|
254
205
|
`);
|
|
255
|
-
}
|
|
256
206
|
let proc;
|
|
257
207
|
try {
|
|
258
|
-
proc = pty.spawn(
|
|
208
|
+
proc = pty.spawn(userShell, ["-l", "-c", shellCmd], {
|
|
259
209
|
name: "xterm-256color",
|
|
260
210
|
cols,
|
|
261
211
|
rows,
|
|
262
212
|
cwd: WORKSPACE_DIR,
|
|
263
|
-
env:
|
|
213
|
+
env: process.env
|
|
264
214
|
});
|
|
265
215
|
} catch (err) {
|
|
266
216
|
process.stderr.write(`[mention-watcher] Failed to spawn "${COMMAND}": ${err.message}
|
|
267
217
|
`);
|
|
268
218
|
process.stderr.write(` Run "which ${COMMAND}" in your terminal to confirm it is installed.
|
|
269
|
-
`);
|
|
270
|
-
process.stderr.write(` Searched PATH: ${shellPath}
|
|
271
219
|
`);
|
|
272
220
|
process.exit(1);
|
|
273
221
|
}
|