@chatpanel/bridge 0.11.22 → 0.11.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatpanel/bridge",
3
- "version": "0.11.22",
3
+ "version": "0.11.24",
4
4
  "type": "module",
5
5
  "description": "Local bridge that exposes the AI coding agents installed on your machine — Claude Code (CLI), Codex (CLI), and Antigravity CLI (formerly Gemini CLI, which remains available for business/enterprise) — to the ChatPanel Chrome extension over a localhost SSE endpoint. Bring your own agent.",
6
6
  "keywords": [
@@ -23,6 +23,7 @@ import { buildCliPrompt } from './prompt.js';
23
23
  import { summarizeCliError } from '../cli-errors.js';
24
24
  import { killOnAbort } from '../proc.js';
25
25
  import { pushExtraArgs, FORBIDDEN } from './args.js';
26
+ import { relayTimeoutMax } from '../relay-timeout.js';
26
27
  import { displayPath, resolveWorkdir } from '../workdir.js';
27
28
  import { connectorsFor } from '../connectors.js';
28
29
 
@@ -435,7 +436,11 @@ export async function chat({ messages, system, options, images }, emit, { signal
435
436
  // Never let caller-supplied extras re-open the read-only boundary the mode flags
436
437
  // above establish (shared sanitizer — see args.js).
437
438
  pushExtraArgs(args, options.extraArgs, FORBIDDEN.claude, emit);
438
- const run = runClaude({ prompt, args, cwd, env: options.runEnv || null, emit, signal });
439
+ // The CLI's own MCP tool timeout matches the relay's longest tool (a team run's budget), or
440
+ // Claude Code gives up on the call before the bridge does. The user's own setting wins.
441
+ const mcpEnv = mcpConfig && !process.env.MCP_TOOL_TIMEOUT ? { MCP_TOOL_TIMEOUT: String(relayTimeoutMax(options.mcp?.specs)) } : null;
442
+ const runEnv = mcpEnv || options.runEnv ? { ...(options.runEnv || {}), ...(mcpEnv || {}) } : null;
443
+ const run = runClaude({ prompt, args, cwd, env: runEnv, emit, signal });
439
444
  if (run === null) {
440
445
  cleanup(); // SDK fallback doesn't take images yet
441
446
  return sdkChat({ messages, system, options }, emit, { signal });
@@ -21,6 +21,7 @@ import { existsSync, mkdirSync, symlinkSync, readFileSync } from 'node:fs';
21
21
  import os from 'node:os';
22
22
  import path from 'node:path';
23
23
  import { findAgentBin, selfMcpStdio, resolveCommand } from '../env.js';
24
+ import { relayTimeoutMax } from '../relay-timeout.js';
24
25
  import { buildCliPrompt } from './prompt.js';
25
26
  import { pushExtraArgs, FORBIDDEN } from './args.js';
26
27
  import { resolveWorkdir } from '../workdir.js';
@@ -117,7 +118,8 @@ export function codexMcpConfigArgs(mcp) {
117
118
  '-c',
118
119
  `mcp_servers.${name}.startup_timeout_sec=30`,
119
120
  '-c',
120
- `mcp_servers.${name}.tool_timeout_sec=120`,
121
+ // Matches the relay's longest tool (a team run's budget) — see relay-timeout.js.
122
+ `mcp_servers.${name}.tool_timeout_sec=${Math.ceil(relayTimeoutMax(mcp.specs) / 1000)}`,
121
123
  ];
122
124
  const toolNames = [...new Set((mcp.specs || []).map((s) => s?.name).filter(Boolean))];
123
125
  if (toolNames.length) {
@@ -242,7 +244,7 @@ function runCodex({ args, cwd, env, prompt, outFile, emit, signal }) {
242
244
  /* no message file */
243
245
  }
244
246
  unlink(outFile).catch(() => {});
245
- resolve({ code, stderr, text, streamed, policyBlocked: !!evState.policyBlocked });
247
+ resolve({ code, stderr, text, streamed, said: !!evState.saidAny, policyBlocked: !!evState.policyBlocked });
246
248
  });
247
249
 
248
250
  child.stdin.write(prompt);
@@ -332,7 +334,8 @@ export async function chat({ messages, system, options, images }, emit, { signal
332
334
 
333
335
  if (signal?.aborted) return; // Stop pressed — end quietly, no error
334
336
  if (result.code !== 0) throw new Error(summarizeCliError('Codex', result.code, result.stderr, '', { agentId: 'codex' }));
335
- emit({ type: 'delta', text: result.text || '(no output)' });
337
+ // Said already, message by message (forwardEvent); the file is the fallback, not a repeat.
338
+ if (!result.said) emit({ type: 'delta', text: result.text || '(no output)' });
336
339
  emit({ type: 'done', text: '' });
337
340
  } finally {
338
341
  cleanupImages();
@@ -346,7 +349,7 @@ export async function chat({ messages, system, options, images }, emit, { signal
346
349
  // command_execution: { id, command, aggregated_output, exit_code, status }
347
350
  // reasoning: { id, text } (only some models/efforts emit it)
348
351
  // file_change: { id, changes:[{path}] }
349
- // agent_message: { id, text } (the answer — read from -o outFile at close)
352
+ // agent_message: { id, text } (the answer, a delta per message; -o outFile is the fallback)
350
353
  // web_search: { id, query, action:{ type, query?, url? } } (codex-cli 0.154)
351
354
  // mcp_tool_call: { id, server, tool, arguments, result?, error?, status }
352
355
  // todo_list: { id, items:[{ text, completed }] }
@@ -356,6 +359,23 @@ export function forwardEvent(ev, emit, state = { started: new Set(), reasoned: n
356
359
  const itype = item.type || '';
357
360
  const completed = t === 'item.completed' || item.status === 'completed' || item.status === 'failed';
358
361
 
362
+ // THE ANSWER, AS IT IS WRITTEN. `codex exec --json` streams no tokens: each agent_message
363
+ // arrives whole, and a turn that thinks, runs a command and then concludes writes TWO of
364
+ // them. Reading only `-o outFile` at close kept the LAST one and showed it once the process
365
+ // had exited — the first sentence was lost and the panel sat blank for the whole run. Each
366
+ // message is a delta the moment it completes; the close reads the file only when nothing
367
+ // was said this way (an older codex, or a run that ended before its message).
368
+ if (itype === 'agent_message' && completed) {
369
+ const id = item.id || `msg_${state.n++}`;
370
+ const text = String(item.text || '');
371
+ if (text && !state.said?.has(id)) {
372
+ (state.said ||= new Set()).add(id);
373
+ emit({ type: 'delta', text: `${state.saidAny ? '\n\n' : ''}${text}` });
374
+ state.saidAny = true;
375
+ }
376
+ return;
377
+ }
378
+
359
379
  if (itype === 'command_execution' || (!itype && t.includes('command'))) {
360
380
  const id = item.id || `cmd_${state.n++}`;
361
381
  if (!state.started.has(id)) {
@@ -0,0 +1,21 @@
1
+ // How long a relayed tool call may take — one rule for the relay and for the CLIs' own
2
+ // MCP timeouts, so neither gives up before the other.
3
+ //
4
+ // A spec may declare `timeoutMs` (additive to the /chat contract — older extensions send
5
+ // none and keep the two-minute default): a team run declares its budget plus the merge. Before
6
+ // this, a 300 s team hit the relay's flat 120 s, Claude Code was handed "tool call timed out"
7
+ // while the extension was still working, and ran the team a SECOND time; the first run's
8
+ // result then had nowhere to go.
9
+ export const RELAY_TIMEOUT_DEFAULT_MS = 120_000;
10
+ export const RELAY_TIMEOUT_MAX_MS = 60 * 60_000;
11
+
12
+ /** The relay's timeout for one tool of a session. */
13
+ export function relayTimeoutFor(specs, name) {
14
+ const declared = Number((specs || []).find((s) => s?.name === name)?.timeoutMs) || 0;
15
+ return Math.min(RELAY_TIMEOUT_MAX_MS, Math.max(RELAY_TIMEOUT_DEFAULT_MS, declared));
16
+ }
17
+
18
+ /** The longest any tool of a session may take — what a CLI's own MCP tool timeout is set to. */
19
+ export function relayTimeoutMax(specs) {
20
+ return Math.max(RELAY_TIMEOUT_DEFAULT_MS, ...(specs || []).map((s) => relayTimeoutFor(specs, s?.name)));
21
+ }
package/src/server.js CHANGED
@@ -47,6 +47,7 @@ import * as custom from './engines/custom.js';
47
47
  import { installService, uninstallService, serviceStatus, restartService } from './service.js';
48
48
  import { skillIndex, listRecords, readRecord, readPackageFile, skillsHealth, quarantinedSkills } from './skills.js';
49
49
  import { capabilityToolSpecs, runCapabilityTool } from './mcp-capabilities.js';
50
+ import { relayTimeoutFor } from './relay-timeout.js';
50
51
  import { DEFAULT_WORKSPACE, isDefaultWorkdir, resolveWorkdir, writeScopeNote } from './workdir.js';
51
52
  import { gitState, gitDelta } from './scm.js';
52
53
  import { listConnections, putConnection, removeConnection, runEnvFor, testConnection, secretBackend } from './connections.js';
@@ -78,7 +79,7 @@ import {
78
79
  // Hardcoded (not read from package.json) so it survives Bun's single-file
79
80
  // --compile, where package.json isn't on a readable FS. CI fails the publish if
80
81
  // this drifts from package.json, so the two can't silently diverge.
81
- const VERSION = '0.11.22';
82
+ const VERSION = '0.11.24';
82
83
  const HOST = process.env.CHATPANEL_BRIDGE_HOST || '127.0.0.1';
83
84
  const PORT = Number(process.env.CHATPANEL_BRIDGE_PORT) || 4319;
84
85
 
@@ -141,7 +142,7 @@ function relayToolCall(session, name, input) {
141
142
  const timer = setTimeout(() => {
142
143
  session.pending.delete(id);
143
144
  reject(new Error('tool call timed out'));
144
- }, 120_000);
145
+ }, relayTimeoutFor(session.specs, name)); // a team run declares its budget; see relay-timeout.js
145
146
  session.pending.set(id, {
146
147
  resolve: (result) => { clearTimeout(timer); resolve(toMcpContent(result)); },
147
148
  reject: (e) => { clearTimeout(timer); reject(e); },