@agent-chat/mention-watcher 0.0.8 → 0.0.9
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 +20 -5
- package/package.json +1 -1
package/dist/watch.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import * as fs from "fs";
|
|
5
5
|
import * as path from "path";
|
|
6
|
+
import * as os from "os";
|
|
7
|
+
import { execSync } from "child_process";
|
|
6
8
|
import * as pty from "node-pty";
|
|
7
9
|
import { WebSocket } from "ws";
|
|
8
10
|
function loadEnvFile(filePath) {
|
|
@@ -67,17 +69,30 @@ function detectWorkspaceDir() {
|
|
|
67
69
|
".git"
|
|
68
70
|
// git repo root
|
|
69
71
|
];
|
|
72
|
+
const home = os.homedir();
|
|
70
73
|
let dir = process.cwd();
|
|
71
74
|
while (true) {
|
|
72
75
|
for (const marker of markers) {
|
|
73
76
|
if (fs.existsSync(path.join(dir, marker))) return dir;
|
|
74
77
|
}
|
|
75
78
|
const parent = path.dirname(dir);
|
|
76
|
-
if (parent === dir) break;
|
|
79
|
+
if (parent === dir || dir === home) break;
|
|
77
80
|
dir = parent;
|
|
78
81
|
}
|
|
79
82
|
return process.cwd();
|
|
80
83
|
}
|
|
84
|
+
function resolveShellPath() {
|
|
85
|
+
try {
|
|
86
|
+
const shell = process.env.SHELL || "/bin/zsh";
|
|
87
|
+
const result = execSync(`${shell} -l -c 'echo $PATH'`, {
|
|
88
|
+
encoding: "utf8",
|
|
89
|
+
timeout: 3e3
|
|
90
|
+
}).trim();
|
|
91
|
+
if (result) return result;
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
return process.env.PATH || "";
|
|
95
|
+
}
|
|
81
96
|
var _WORKSPACE = process.env.WORKSPACE_DIR ?? detectWorkspaceDir();
|
|
82
97
|
{
|
|
83
98
|
const dirsToCheck = [.../* @__PURE__ */ new Set([process.cwd(), _WORKSPACE])];
|
|
@@ -219,6 +234,8 @@ async function main() {
|
|
|
219
234
|
`);
|
|
220
235
|
process.stderr.write(`[mention-watcher] Spawning: ${COMMAND} ${CMD_ARGS.join(" ")}
|
|
221
236
|
`);
|
|
237
|
+
const shellPath = resolveShellPath();
|
|
238
|
+
const spawnEnv = { ...process.env, PATH: shellPath };
|
|
222
239
|
let proc;
|
|
223
240
|
try {
|
|
224
241
|
proc = pty.spawn(COMMAND, CMD_ARGS, {
|
|
@@ -226,14 +243,12 @@ async function main() {
|
|
|
226
243
|
cols,
|
|
227
244
|
rows,
|
|
228
245
|
cwd: WORKSPACE_DIR,
|
|
229
|
-
env:
|
|
246
|
+
env: spawnEnv
|
|
230
247
|
});
|
|
231
248
|
} catch (err) {
|
|
232
249
|
process.stderr.write(`[mention-watcher] Failed to spawn "${COMMAND}": ${err.message}
|
|
233
250
|
`);
|
|
234
|
-
process.stderr.write(`
|
|
235
|
-
`);
|
|
236
|
-
process.stderr.write(` Current PATH: ${process.env.PATH}
|
|
251
|
+
process.stderr.write(` Run "which ${COMMAND}" in your terminal to check it is installed.
|
|
237
252
|
`);
|
|
238
253
|
process.exit(1);
|
|
239
254
|
}
|