@essentialai/cogent-bridge-bundled 3.21.2 → 3.21.4

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/cogent-bridge.mjs +82 -7
  2. package/package.json +1 -1
package/cogent-bridge.mjs CHANGED
@@ -26389,8 +26389,8 @@ var init_stdio2 = __esm({
26389
26389
  // src/constants.ts
26390
26390
  import { createRequire } from "node:module";
26391
26391
  function resolveVersion() {
26392
- if ("3.21.2") {
26393
- return "3.21.2";
26392
+ if ("3.21.4") {
26393
+ return "3.21.4";
26394
26394
  }
26395
26395
  try {
26396
26396
  const require2 = createRequire(import.meta.url);
@@ -27214,7 +27214,42 @@ async function validateSession(sessionId, cwd) {
27214
27214
  );
27215
27215
  return hits.some(Boolean);
27216
27216
  }
27217
- function execClaude(sessionId, message, cwd, timeoutMs) {
27217
+ async function rootForSession(sessionId, cwd) {
27218
+ const rec = await readAgentSession(cwd, "cc");
27219
+ if (rec?.sessionId === sessionId && rec.root) {
27220
+ try {
27221
+ await fs8.stat(rec.transcriptPath);
27222
+ return path10.resolve(rec.root);
27223
+ } catch {
27224
+ }
27225
+ }
27226
+ const [roots, forms] = await Promise.all([
27227
+ claudeConfigRoots(),
27228
+ cwdForms(cwd)
27229
+ ]);
27230
+ for (const root of roots) {
27231
+ const hits = await Promise.all(
27232
+ forms.map(async (form) => {
27233
+ const file = path10.join(
27234
+ root,
27235
+ "projects",
27236
+ form.replace(/[^a-zA-Z0-9-]/g, "-"),
27237
+ `${sessionId}.jsonl`
27238
+ );
27239
+ try {
27240
+ await fs8.access(file);
27241
+ return true;
27242
+ } catch {
27243
+ return false;
27244
+ }
27245
+ })
27246
+ );
27247
+ if (hits.some(Boolean)) return root;
27248
+ }
27249
+ return null;
27250
+ }
27251
+ async function execClaude(sessionId, message, cwd, timeoutMs) {
27252
+ const resolvedRoot = await rootForSession(sessionId, cwd).catch(() => null);
27218
27253
  return new Promise((resolve) => {
27219
27254
  const config2 = getConfig();
27220
27255
  const effectiveTimeout = timeoutMs ?? config2.COGENT_TIMEOUT_MS;
@@ -27241,6 +27276,7 @@ function execClaude(sessionId, message, cwd, timeoutMs) {
27241
27276
  truncated
27242
27277
  ];
27243
27278
  const cleanEnv = buildResumeEnv(process.env, "CLAUDE", ["CLAUDE_CONFIG_DIR"]);
27279
+ if (resolvedRoot) cleanEnv.CLAUDE_CONFIG_DIR = resolvedRoot;
27244
27280
  cleanEnv.COGENT_CHECK_ON_STOP = "0";
27245
27281
  const child = spawn(config2.COGENT_CLAUDE_PATH, args, {
27246
27282
  cwd,
@@ -33206,7 +33242,41 @@ ${message}${formatAttachmentsBlock(attachments)}
33206
33242
  ---
33207
33243
  FYI ONLY \u2014 another agent addressed the whole channel. Take note for context, but do NOT reply and do NOT call any cogent_* tool in response. A human will drive any reply.`;
33208
33244
  }
33209
- var RELAY_STATUS, STATUS_MARKER_RE, AutoRelayService, autoRelay;
33245
+ function describeWakeFailure(exitCode, stderr) {
33246
+ const raw = (stderr ?? "").trim();
33247
+ if (!raw && exitCode !== 0) return "";
33248
+ const firstLine = raw.split("\n").map((l) => l.trim()).find(Boolean) ?? "";
33249
+ const missing = /No conversation found with session ID:?\s*(\S+)/i.exec(raw);
33250
+ if (missing) {
33251
+ return truncate(
33252
+ `claude could not find session ${missing[1]} in the config directory it searched \u2014 the agent's Claude state is probably outside ~/.claude. Upgrade the bridge (3.21.4+ passes the resolved config directory to the resume), or set CLAUDE_CONFIG_DIR.`
33253
+ );
33254
+ }
33255
+ if (/CLI_NOT_FOUND/.test(raw)) {
33256
+ return truncate(
33257
+ `the claude executable was not found \u2014 install Claude Code or set COGENT_CLAUDE_PATH.`
33258
+ );
33259
+ }
33260
+ const timedOut = /CLI_TIMEOUT: CLI subprocess timed out after (\d+)ms/.exec(raw);
33261
+ if (timedOut) {
33262
+ return truncate(
33263
+ `the resume timed out after ${timedOut[1]}ms (COGENT_TIMEOUT_MS) \u2014 the agent was still working, not idle.`
33264
+ );
33265
+ }
33266
+ if (firstLine) {
33267
+ const code = exitCode === null || exitCode === void 0 ? "?" : exitCode;
33268
+ return truncate(`claude exited ${code}: ${firstLine}`);
33269
+ }
33270
+ if (exitCode === 0) {
33271
+ return truncate(`the resume completed successfully but returned no text.`);
33272
+ }
33273
+ return "";
33274
+ }
33275
+ function truncate(s) {
33276
+ const flat = s.replace(/\s+/g, " ").trim();
33277
+ return flat.length > DIAGNOSTIC_MAX ? `${flat.slice(0, DIAGNOSTIC_MAX - 1)}\u2026` : flat;
33278
+ }
33279
+ var RELAY_STATUS, STATUS_MARKER_RE, DIAGNOSTIC_MAX, AutoRelayService, autoRelay;
33210
33280
  var init_auto_relay = __esm({
33211
33281
  "src/services/auto-relay.ts"() {
33212
33282
  "use strict";
@@ -33225,6 +33295,7 @@ var init_auto_relay = __esm({
33225
33295
  FAILED: "failed"
33226
33296
  };
33227
33297
  STATUS_MARKER_RE = /^\[cogent:(queued|processing|delivered|needs-manual|failed)\]/;
33298
+ DIAGNOSTIC_MAX = 220;
33228
33299
  AutoRelayService = class {
33229
33300
  localPeerId = null;
33230
33301
  localSessionId = null;
@@ -33863,7 +33934,9 @@ var init_auto_relay = __esm({
33863
33934
  }
33864
33935
  if (!replied) {
33865
33936
  await this._recordNoReplyFailure(msg, traceId, Date.now() - startMs, {
33866
- codexLiveSession: result.codexLiveSession === true
33937
+ codexLiveSession: result.codexLiveSession === true,
33938
+ exitCode: result.exitCode,
33939
+ stderr: result.stderr
33867
33940
  });
33868
33941
  }
33869
33942
  } catch (err) {
@@ -33871,7 +33944,9 @@ var init_auto_relay = __esm({
33871
33944
  this._trace(traceId, "failed", { threw: true, durationMs });
33872
33945
  logger.error(`Auto-relay: execRemote threw after ${durationMs}ms: ${err}`);
33873
33946
  if (!replied) {
33874
- await this._recordNoReplyFailure(msg, traceId, durationMs);
33947
+ await this._recordNoReplyFailure(msg, traceId, durationMs, {
33948
+ stderr: `EXEC_THREW: ${err}`
33949
+ });
33875
33950
  }
33876
33951
  }
33877
33952
  }
@@ -33887,7 +33962,7 @@ var init_auto_relay = __esm({
33887
33962
  */
33888
33963
  async _recordNoReplyFailure(msg, traceId, durationMs, opts) {
33889
33964
  const codexLive = opts?.codexLiveSession === true;
33890
- const message = codexLive ? `\u{1F4E8} Queued for "${this.localPeerId}": it's live in an interactive Codex session, so Cogent can't resume it in real time \u2014 it will see this at its next turn. For real-time replies, launch it via \`cogent-codex\` (COGENT_CODEX_WAKE=app-server). (trace ${traceId})` : `\u26A0\uFE0F Cogent could not capture a reply from "${this.localPeerId}" (it may have been busy, or the resume produced no output). Manual response required \u2014 the target agent must reply in its own session. (trace ${traceId})`;
33965
+ const message = codexLive ? `\u{1F4E8} Queued for "${this.localPeerId}": it's live in an interactive Codex session, so Cogent can't resume it in real time \u2014 it will see this at its next turn. For real-time replies, launch it via \`cogent-codex\` (COGENT_CODEX_WAKE=app-server). (trace ${traceId})` : `\u26A0\uFE0F Cogent could not capture a reply from "${this.localPeerId}". ${describeWakeFailure(opts?.exitCode, opts?.stderr) || "It may have been busy, or the resume produced no output."} Manual response required \u2014 the target agent must reply in its own session. (trace ${traceId})`;
33891
33966
  try {
33892
33967
  await getBackend().recordMessage({
33893
33968
  fromPeerId: this.localPeerId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@essentialai/cogent-bridge-bundled",
3
- "version": "3.21.2",
3
+ "version": "3.21.4",
4
4
  "description": "Zero-dependency, pre-bundled Cogent MCP bridge — a single self-contained file for fast cold `npx` startup (used by the Codex plugin, whose MCP startup window is short). Functionally identical to @essentialai/cogent-bridge; carries no npm dependencies so `npx` skips dependency install.",
5
5
  "type": "module",
6
6
  "bin": {