claude-bridge-cli 1.1.4 → 1.2.0
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 -12
- package/package.json +1 -1
package/lib/bridge.js
CHANGED
|
@@ -339,23 +339,32 @@ 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 isCmdShim = isWin && config.claudeBin.endsWith(".cmd");
|
|
344
|
+
|
|
345
|
+
// Write prompt to temp file — avoids Windows 8K arg limit and stdin
|
|
346
|
+
// piping issues through cmd.exe. Works on all platforms.
|
|
347
|
+
const tmpFile = path.join(os.tmpdir(), `claude-prompt-${Date.now()}-${Math.random().toString(36).slice(2)}.txt`);
|
|
348
|
+
fs.writeFileSync(tmpFile, finalPrompt, "utf8");
|
|
349
|
+
|
|
350
|
+
const args = ["-p", `@${tmpFile}`, "--output-format", "json"];
|
|
351
|
+
if (session_id) {
|
|
352
|
+
const sessionExists = scanSessionFiles().some(s => s.id === session_id);
|
|
353
|
+
args.push(sessionExists ? "--resume" : "--session-id", session_id);
|
|
354
|
+
}
|
|
344
355
|
if (plan_mode) args.push("--plan");
|
|
345
356
|
|
|
346
|
-
const
|
|
347
|
-
const
|
|
357
|
+
const bin = isCmdShim ? process.env.COMSPEC || "cmd.exe" : config.claudeBin;
|
|
358
|
+
const fullArgs = isCmdShim ? ["/c", config.claudeBin, ...args] : args;
|
|
359
|
+
|
|
360
|
+
const proc = spawn(bin, fullArgs, {
|
|
348
361
|
cwd: cwd || config.cwd,
|
|
349
362
|
timeout: config.timeout,
|
|
350
363
|
env: { ...process.env },
|
|
351
|
-
stdio: ["
|
|
352
|
-
|
|
353
|
-
shell: isWin,
|
|
364
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
365
|
+
windowsHide: true,
|
|
354
366
|
});
|
|
355
367
|
|
|
356
|
-
proc.stdin.write(finalPrompt);
|
|
357
|
-
proc.stdin.end();
|
|
358
|
-
|
|
359
368
|
let stdout = "", stderr = "";
|
|
360
369
|
proc.stdout.on("data", (d) => { stdout += d; });
|
|
361
370
|
proc.stderr.on("data", (d) => { stderr += d; });
|
|
@@ -363,6 +372,7 @@ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_t
|
|
|
363
372
|
if (session_id) running.set(session_id, proc);
|
|
364
373
|
|
|
365
374
|
proc.on("close", (code) => {
|
|
375
|
+
try { fs.unlinkSync(tmpFile); } catch {}
|
|
366
376
|
if (session_id) running.delete(session_id);
|
|
367
377
|
try {
|
|
368
378
|
const result = JSON.parse(stdout);
|
|
@@ -389,6 +399,7 @@ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_t
|
|
|
389
399
|
});
|
|
390
400
|
|
|
391
401
|
proc.on("error", (err) => {
|
|
402
|
+
try { fs.unlinkSync(tmpFile); } catch {}
|
|
392
403
|
if (session_id) running.delete(session_id);
|
|
393
404
|
resolve({ error: err.message });
|
|
394
405
|
});
|
|
@@ -400,8 +411,12 @@ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_t
|
|
|
400
411
|
function stopSession(sessionId) {
|
|
401
412
|
const proc = running.get(sessionId);
|
|
402
413
|
if (!proc) return { stopped: false, reason: "not_running" };
|
|
403
|
-
|
|
404
|
-
|
|
414
|
+
if (process.platform === "win32" && proc.pid) {
|
|
415
|
+
try { execSync(`taskkill /f /t /pid ${proc.pid}`, { stdio: "ignore" }); } catch {}
|
|
416
|
+
} else {
|
|
417
|
+
try { proc.kill("SIGINT"); } catch {}
|
|
418
|
+
setTimeout(() => { try { proc.kill("SIGTERM"); } catch {} }, 3000);
|
|
419
|
+
}
|
|
405
420
|
running.delete(sessionId);
|
|
406
421
|
return { stopped: true };
|
|
407
422
|
}
|
package/package.json
CHANGED