claude-bridge-cli 1.1.6 → 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 +29 -14
- package/package.json +1 -1
package/lib/bridge.js
CHANGED
|
@@ -340,29 +340,40 @@ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_t
|
|
|
340
340
|
}
|
|
341
341
|
|
|
342
342
|
const isWin = process.platform === "win32";
|
|
343
|
-
const
|
|
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"];
|
|
344
351
|
if (session_id) {
|
|
345
352
|
const sessionExists = scanSessionFiles().some(s => s.id === session_id);
|
|
346
353
|
args.push(sessionExists ? "--resume" : "--session-id", session_id);
|
|
347
354
|
}
|
|
348
355
|
if (plan_mode) args.push("--plan");
|
|
349
356
|
|
|
350
|
-
const bin =
|
|
351
|
-
const fullArgs =
|
|
357
|
+
const bin = isCmdShim ? process.env.COMSPEC || "cmd.exe" : config.claudeBin;
|
|
358
|
+
const fullArgs = isCmdShim ? ["/c", config.claudeBin, ...args] : args;
|
|
352
359
|
|
|
353
|
-
const
|
|
354
|
-
const proc = execFile(bin, fullArgs, {
|
|
360
|
+
const proc = spawn(bin, fullArgs, {
|
|
355
361
|
cwd: cwd || config.cwd,
|
|
356
362
|
timeout: config.timeout,
|
|
357
|
-
maxBuffer: 50 * 1024 * 1024,
|
|
358
363
|
env: { ...process.env },
|
|
364
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
359
365
|
windowsHide: true,
|
|
360
|
-
}
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
let stdout = "", stderr = "";
|
|
369
|
+
proc.stdout.on("data", (d) => { stdout += d; });
|
|
370
|
+
proc.stderr.on("data", (d) => { stderr += d; });
|
|
371
|
+
|
|
372
|
+
if (session_id) running.set(session_id, proc);
|
|
373
|
+
|
|
374
|
+
proc.on("close", (code) => {
|
|
375
|
+
try { fs.unlinkSync(tmpFile); } catch {}
|
|
361
376
|
if (session_id) running.delete(session_id);
|
|
362
|
-
if (err && !stdout) {
|
|
363
|
-
resolve({ error: stderr || err.message });
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
377
|
try {
|
|
367
378
|
const result = JSON.parse(stdout);
|
|
368
379
|
const sid = result.session_id || session_id || crypto.randomUUID();
|
|
@@ -379,15 +390,19 @@ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_t
|
|
|
379
390
|
context: result.context || null,
|
|
380
391
|
});
|
|
381
392
|
} catch {
|
|
382
|
-
if (stdout
|
|
393
|
+
if (stdout.trim()) {
|
|
383
394
|
resolve({ response: stdout.trim(), session_id: session_id || crypto.randomUUID() });
|
|
384
395
|
} else {
|
|
385
|
-
resolve({ error: stderr ||
|
|
396
|
+
resolve({ error: stderr.trim() || `claude exited with code ${code}` });
|
|
386
397
|
}
|
|
387
398
|
}
|
|
388
399
|
});
|
|
389
400
|
|
|
390
|
-
|
|
401
|
+
proc.on("error", (err) => {
|
|
402
|
+
try { fs.unlinkSync(tmpFile); } catch {}
|
|
403
|
+
if (session_id) running.delete(session_id);
|
|
404
|
+
resolve({ error: err.message });
|
|
405
|
+
});
|
|
391
406
|
});
|
|
392
407
|
}
|
|
393
408
|
|
package/package.json
CHANGED