claude-bridge-cli 2.0.0 → 2.0.2

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.
Files changed (2) hide show
  1. package/lib/bridge.js +56 -6
  2. package/package.json +1 -1
package/lib/bridge.js CHANGED
@@ -290,15 +290,44 @@ const INTERNAL_USER_PATTERNS = [
290
290
  function extractUserText(content) {
291
291
  // Only extract type:"text" parts. tool_result records don't have a text
292
292
  // part so they return empty string and get filtered out.
293
- if (typeof content === "string") return content;
294
- if (Array.isArray(content)) {
293
+ let raw = "";
294
+ if (typeof content === "string") raw = content;
295
+ else if (Array.isArray(content)) {
295
296
  for (const part of content) {
296
297
  if (part && typeof part === "object" && part.type === "text") {
297
- return part.text || "";
298
+ raw = part.text || "";
299
+ break;
298
300
  }
299
301
  }
300
302
  }
301
- return "";
303
+ return resolveAtFileRefs(raw);
304
+ }
305
+
306
+ // When the bridge sends a multi-line prompt to claude on Windows it writes
307
+ // the prompt to a temp file and passes "@C:\...\claude-prompt-NNN.txt" as
308
+ // the -p arg. claude records that literal @path in the session JSONL as
309
+ // the user message. When we read the session back we want to show the
310
+ // actual content, not the path — otherwise history looks like a wall of
311
+ // temp-file paths. If the file still exists on disk, inline its contents;
312
+ // otherwise leave the @path alone so the user at least sees something.
313
+ function resolveAtFileRefs(text) {
314
+ if (!text || typeof text !== "string") return text;
315
+ // Match a leading @<path> that points at a claude-prompt-*.txt temp file.
316
+ // Restrict to the temp-file pattern we generate ourselves — never inline
317
+ // arbitrary user-typed @file references (which are a real Claude Code
318
+ // feature that should remain as-is).
319
+ const trimmed = text.trim();
320
+ if (!trimmed.startsWith("@")) return text;
321
+ const m = trimmed.match(/^@(.+?claude-prompt-\d+-[a-z0-9]+\.txt)\s*$/i);
322
+ if (!m) return text;
323
+ const filePath = m[1];
324
+ try {
325
+ if (fs.existsSync(filePath)) {
326
+ const body = fs.readFileSync(filePath, "utf8");
327
+ if (body && body.length) return body;
328
+ }
329
+ } catch {}
330
+ return text;
302
331
  }
303
332
 
304
333
  function shouldSkipUserText(text) {
@@ -349,7 +378,26 @@ function getSessionMessages(sessionId) {
349
378
  }
350
379
  } catch {}
351
380
  }
352
- return { session_id: sessionId, messages, in_progress: running.has(sessionId) };
381
+ // Match the Python bridge's shape so the app's reconnect/resume loader can
382
+ // detect completion. Without `status` (and end-of-turn markers on the
383
+ // trailing assistant), the loader never finalizes — it shows "still working"
384
+ // forever even though Claude is done (the stuck-loader bug on this bridge).
385
+ const inProgress = running.has(sessionId);
386
+ const last_event_ts = messages.length ? (messages[messages.length - 1].timestamp || null) : null;
387
+ if (!inProgress && messages.length) {
388
+ const last = messages[messages.length - 1];
389
+ if (last.role === "assistant" && last.text) {
390
+ last.stop_reason = "end_turn";
391
+ last.final_text = last.text;
392
+ }
393
+ }
394
+ return {
395
+ session_id: sessionId,
396
+ messages,
397
+ in_progress: inProgress,
398
+ status: inProgress ? "in_progress" : "complete",
399
+ last_event_ts,
400
+ };
353
401
  }
354
402
  return { error: "session not found" };
355
403
  }
@@ -404,7 +452,7 @@ function renameSession(sessionId, title) {
404
452
 
405
453
  // ── Run claude -p ──
406
454
 
407
- function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_tools }) {
455
+ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_tools, model }) {
408
456
  return new Promise((resolve) => {
409
457
  let finalPrompt = prompt;
410
458
  if (images && images.length) {
@@ -468,6 +516,8 @@ function askClaude(config, { prompt, session_id, images, cwd, plan_mode, allow_t
468
516
  }
469
517
  }
470
518
  if (plan_mode) args.push("--plan");
519
+ // Optional model override from the extension's model picker (alias or id).
520
+ if (model && String(model).trim()) args.push("--model", String(model).trim());
471
521
 
472
522
  const bin = isCmdShim ? process.env.COMSPEC || "cmd.exe" : config.claudeBin;
473
523
  const fullArgs = isCmdShim ? ["/c", config.claudeBin, ...args] : args;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-bridge-cli",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Use Claude Code from your browser. Runs a local server that connects your browser tools to the Claude CLI.",
5
5
  "main": "lib/bridge.js",
6
6
  "bin": {