claude-bridge-cli 1.1.4 → 1.1.6
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/lib/bridge.js +27 -27
- package/package.json +1 -1
package/lib/bridge.js
CHANGED
|
@@ -339,31 +339,30 @@ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_t
|
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
-
const
|
|
343
|
-
|
|
342
|
+
const isWin = process.platform === "win32";
|
|
343
|
+
const args = ["-p", finalPrompt, "--output-format", "json"];
|
|
344
|
+
if (session_id) {
|
|
345
|
+
const sessionExists = scanSessionFiles().some(s => s.id === session_id);
|
|
346
|
+
args.push(sessionExists ? "--resume" : "--session-id", session_id);
|
|
347
|
+
}
|
|
344
348
|
if (plan_mode) args.push("--plan");
|
|
345
349
|
|
|
346
|
-
const
|
|
347
|
-
const
|
|
350
|
+
const bin = isWin && config.claudeBin.endsWith(".cmd") ? process.env.COMSPEC || "cmd.exe" : config.claudeBin;
|
|
351
|
+
const fullArgs = isWin && config.claudeBin.endsWith(".cmd") ? ["/c", config.claudeBin, ...args] : args;
|
|
352
|
+
|
|
353
|
+
const { execFile } = require("node:child_process");
|
|
354
|
+
const proc = execFile(bin, fullArgs, {
|
|
348
355
|
cwd: cwd || config.cwd,
|
|
349
356
|
timeout: config.timeout,
|
|
357
|
+
maxBuffer: 50 * 1024 * 1024,
|
|
350
358
|
env: { ...process.env },
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
shell: isWin,
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
proc.stdin.write(finalPrompt);
|
|
357
|
-
proc.stdin.end();
|
|
358
|
-
|
|
359
|
-
let stdout = "", stderr = "";
|
|
360
|
-
proc.stdout.on("data", (d) => { stdout += d; });
|
|
361
|
-
proc.stderr.on("data", (d) => { stderr += d; });
|
|
362
|
-
|
|
363
|
-
if (session_id) running.set(session_id, proc);
|
|
364
|
-
|
|
365
|
-
proc.on("close", (code) => {
|
|
359
|
+
windowsHide: true,
|
|
360
|
+
}, (err, stdout, stderr) => {
|
|
366
361
|
if (session_id) running.delete(session_id);
|
|
362
|
+
if (err && !stdout) {
|
|
363
|
+
resolve({ error: stderr || err.message });
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
367
366
|
try {
|
|
368
367
|
const result = JSON.parse(stdout);
|
|
369
368
|
const sid = result.session_id || session_id || crypto.randomUUID();
|
|
@@ -380,18 +379,15 @@ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_t
|
|
|
380
379
|
context: result.context || null,
|
|
381
380
|
});
|
|
382
381
|
} catch {
|
|
383
|
-
if (stdout.trim()) {
|
|
382
|
+
if (stdout && stdout.trim()) {
|
|
384
383
|
resolve({ response: stdout.trim(), session_id: session_id || crypto.randomUUID() });
|
|
385
384
|
} else {
|
|
386
|
-
resolve({ error: stderr
|
|
385
|
+
resolve({ error: stderr || "unknown error" });
|
|
387
386
|
}
|
|
388
387
|
}
|
|
389
388
|
});
|
|
390
389
|
|
|
391
|
-
|
|
392
|
-
if (session_id) running.delete(session_id);
|
|
393
|
-
resolve({ error: err.message });
|
|
394
|
-
});
|
|
390
|
+
if (session_id) running.set(session_id, proc);
|
|
395
391
|
});
|
|
396
392
|
}
|
|
397
393
|
|
|
@@ -400,8 +396,12 @@ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_t
|
|
|
400
396
|
function stopSession(sessionId) {
|
|
401
397
|
const proc = running.get(sessionId);
|
|
402
398
|
if (!proc) return { stopped: false, reason: "not_running" };
|
|
403
|
-
|
|
404
|
-
|
|
399
|
+
if (process.platform === "win32" && proc.pid) {
|
|
400
|
+
try { execSync(`taskkill /f /t /pid ${proc.pid}`, { stdio: "ignore" }); } catch {}
|
|
401
|
+
} else {
|
|
402
|
+
try { proc.kill("SIGINT"); } catch {}
|
|
403
|
+
setTimeout(() => { try { proc.kill("SIGTERM"); } catch {} }, 3000);
|
|
404
|
+
}
|
|
405
405
|
running.delete(sessionId);
|
|
406
406
|
return { stopped: true };
|
|
407
407
|
}
|
package/package.json
CHANGED