@agent-chat/mention-watcher 0.0.7 → 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 +35 -10
- 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) {
|
|
@@ -64,21 +66,33 @@ function detectWorkspaceDir() {
|
|
|
64
66
|
// older Claude Code format
|
|
65
67
|
path.join(".cursor", "mcp.json"),
|
|
66
68
|
// Cursor
|
|
67
|
-
".claude",
|
|
68
|
-
".cursor",
|
|
69
69
|
".git"
|
|
70
|
+
// git repo root
|
|
70
71
|
];
|
|
72
|
+
const home = os.homedir();
|
|
71
73
|
let dir = process.cwd();
|
|
72
74
|
while (true) {
|
|
73
75
|
for (const marker of markers) {
|
|
74
76
|
if (fs.existsSync(path.join(dir, marker))) return dir;
|
|
75
77
|
}
|
|
76
78
|
const parent = path.dirname(dir);
|
|
77
|
-
if (parent === dir) break;
|
|
79
|
+
if (parent === dir || dir === home) break;
|
|
78
80
|
dir = parent;
|
|
79
81
|
}
|
|
80
82
|
return process.cwd();
|
|
81
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
|
+
}
|
|
82
96
|
var _WORKSPACE = process.env.WORKSPACE_DIR ?? detectWorkspaceDir();
|
|
83
97
|
{
|
|
84
98
|
const dirsToCheck = [.../* @__PURE__ */ new Set([process.cwd(), _WORKSPACE])];
|
|
@@ -220,13 +234,24 @@ async function main() {
|
|
|
220
234
|
`);
|
|
221
235
|
process.stderr.write(`[mention-watcher] Spawning: ${COMMAND} ${CMD_ARGS.join(" ")}
|
|
222
236
|
`);
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
237
|
+
const shellPath = resolveShellPath();
|
|
238
|
+
const spawnEnv = { ...process.env, PATH: shellPath };
|
|
239
|
+
let proc;
|
|
240
|
+
try {
|
|
241
|
+
proc = pty.spawn(COMMAND, CMD_ARGS, {
|
|
242
|
+
name: "xterm-256color",
|
|
243
|
+
cols,
|
|
244
|
+
rows,
|
|
245
|
+
cwd: WORKSPACE_DIR,
|
|
246
|
+
env: spawnEnv
|
|
247
|
+
});
|
|
248
|
+
} catch (err) {
|
|
249
|
+
process.stderr.write(`[mention-watcher] Failed to spawn "${COMMAND}": ${err.message}
|
|
250
|
+
`);
|
|
251
|
+
process.stderr.write(` Run "which ${COMMAND}" in your terminal to check it is installed.
|
|
252
|
+
`);
|
|
253
|
+
process.exit(1);
|
|
254
|
+
}
|
|
230
255
|
proc.onData((data) => {
|
|
231
256
|
process.stdout.write(data);
|
|
232
257
|
lastOutputAt = Date.now();
|