replicas-engine 0.1.329 → 0.1.331

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/dist/src/index.js +54 -17
  2. package/package.json +2 -1
package/dist/src/index.js CHANGED
@@ -287,7 +287,7 @@ var WORKSPACE_SIZES = ["small", "large"];
287
287
  var INVALID_WORKSPACE_SIZE_ERROR = `Invalid size: must be one of ${WORKSPACE_SIZES.join(", ")}`;
288
288
 
289
289
  // ../shared/src/e2b.ts
290
- var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-06-19-v3";
290
+ var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-06-21-v1";
291
291
 
292
292
  // ../shared/src/runtime-env.ts
293
293
  function parsePosixEnvFile(content) {
@@ -6301,15 +6301,19 @@ var ClaudeAuthError = class extends Error {
6301
6301
  }
6302
6302
  };
6303
6303
  var ClaudeTransientTurnError = class extends Error {
6304
- constructor(message) {
6304
+ constructor(message, midTurn = false) {
6305
6305
  super(message);
6306
+ this.midTurn = midTurn;
6306
6307
  this.name = "ClaudeTransientTurnError";
6307
6308
  }
6309
+ midTurn;
6308
6310
  };
6309
6311
  var MAX_AUTH_RETRIES = 2;
6310
6312
  var MAX_TRANSIENT_RETRIES = 2;
6313
+ var MAX_MIDTURN_CONTINUE_RETRIES = 2;
6311
6314
  var TRANSIENT_RETRY_DELAYS_MS = [1e3, 2500];
6312
6315
  var CLAUDE_TRANSIENT_HTTP_STATUSES = [408, 500, 502, 503, 504, 529];
6316
+ var CLAUDE_MIDTURN_CONTINUE_PROMPT = "Your previous turn was interrupted by a transient network error before it could finish. Continue from exactly where you left off. Do not repeat any tool calls, commits, messages, or other actions you have already completed \u2014 first check what is already done, then do only the remaining work.";
6313
6317
  var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6314
6318
  historyFile;
6315
6319
  sessionId = null;
@@ -6479,10 +6483,12 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6479
6483
  let attempt = 0;
6480
6484
  let authRetries = 0;
6481
6485
  let transientRetries = 0;
6486
+ let midTurnContinues = 0;
6487
+ let currentRequest = request;
6482
6488
  try {
6483
6489
  while (true) {
6484
6490
  try {
6485
- await this.executeQuery(request, { skipUserMessageRecord: attempt > 0 });
6491
+ await this.executeQuery(currentRequest, { skipUserMessageRecord: attempt > 0 });
6486
6492
  return;
6487
6493
  } catch (error) {
6488
6494
  lastError = error;
@@ -6507,6 +6513,23 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6507
6513
  attempt++;
6508
6514
  continue;
6509
6515
  }
6516
+ if (error instanceof ClaudeTransientTurnError && error.midTurn) {
6517
+ if (midTurnContinues >= MAX_MIDTURN_CONTINUE_RETRIES) {
6518
+ await this.emitMidTurnExhaustedEvent(error);
6519
+ return;
6520
+ }
6521
+ midTurnContinues++;
6522
+ const delayMs = TRANSIENT_RETRY_DELAYS_MS[midTurnContinues - 1] ?? TRANSIENT_RETRY_DELAYS_MS[TRANSIENT_RETRY_DELAYS_MS.length - 1];
6523
+ console.warn(
6524
+ `[ClaudeManager] Mid-turn transient failure detected (attempt ${midTurnContinues}/${MAX_MIDTURN_CONTINUE_RETRIES}), resuming session and continuing in ${delayMs}ms...`,
6525
+ error
6526
+ );
6527
+ await this.tearDownSession();
6528
+ await new Promise((resolve4) => setTimeout(resolve4, delayMs));
6529
+ currentRequest = { ...request, message: CLAUDE_MIDTURN_CONTINUE_PROMPT, images: [] };
6530
+ attempt++;
6531
+ continue;
6532
+ }
6510
6533
  if (_ClaudeManager.isTransientTurnError(error) && transientRetries < MAX_TRANSIENT_RETRIES) {
6511
6534
  transientRetries++;
6512
6535
  const delayMs = TRANSIENT_RETRY_DELAYS_MS[transientRetries - 1] ?? TRANSIENT_RETRY_DELAYS_MS[TRANSIENT_RETRY_DELAYS_MS.length - 1];
@@ -6534,8 +6557,9 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6534
6557
  }
6535
6558
  }
6536
6559
  }
6537
- async emitAuthRetryExhaustedEvent(error) {
6538
- const detail = error instanceof Error ? error.message : String(error);
6560
+ // `errors` is the field the dashboard renders (see claude-parser); `result` is
6561
+ // only retained on the raw event for debugging. The user-facing message goes in `errors`.
6562
+ async emitTerminalErrorResult(result, errors, logLabel) {
6539
6563
  const event = {
6540
6564
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
6541
6565
  type: "claude-result",
@@ -6543,8 +6567,8 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6543
6567
  type: "result",
6544
6568
  subtype: "error_during_execution",
6545
6569
  is_error: true,
6546
- result: "Couldn't authenticate with Claude after multiple attempts. Check your credentials in Settings \u2192 Agents and try again.",
6547
- errors: [detail],
6570
+ result,
6571
+ errors,
6548
6572
  session_id: this.sessionId ?? "",
6549
6573
  parent_tool_use_id: null
6550
6574
  }
@@ -6552,10 +6576,26 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6552
6576
  try {
6553
6577
  await appendFile2(this.historyFile, JSON.stringify(event) + "\n", "utf-8");
6554
6578
  } catch (writeError) {
6555
- console.error("[ClaudeManager] Failed to record auth-retry-exhausted event:", writeError);
6579
+ console.error(`[ClaudeManager] Failed to record ${logLabel} event:`, writeError);
6556
6580
  }
6557
6581
  this.onEvent(event);
6558
6582
  }
6583
+ async emitAuthRetryExhaustedEvent(error) {
6584
+ const detail = error instanceof Error ? error.message : String(error);
6585
+ await this.emitTerminalErrorResult(
6586
+ detail,
6587
+ ["Couldn't authenticate with Claude after multiple attempts. Check your credentials in Settings \u2192 Agents and try again."],
6588
+ "auth-retry-exhausted"
6589
+ );
6590
+ }
6591
+ async emitMidTurnExhaustedEvent(error) {
6592
+ const detail = error instanceof Error ? error.message : String(error);
6593
+ await this.emitTerminalErrorResult(
6594
+ detail,
6595
+ ["The connection to Claude dropped mid-response and could not be resumed after multiple attempts."],
6596
+ "mid-turn-exhausted"
6597
+ );
6598
+ }
6559
6599
  async executeQuery(request, options = {}) {
6560
6600
  const {
6561
6601
  message,
@@ -6783,12 +6823,10 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6783
6823
  }
6784
6824
  return;
6785
6825
  }
6786
- const transientErrorMessage = _ClaudeManager.detectTransientTurnErrorInMessage(
6787
- msg,
6788
- this.pendingTurn?.sawActivity ?? false
6789
- );
6826
+ const transientErrorMessage = _ClaudeManager.detectTransientTurnErrorInMessage(msg);
6790
6827
  if (transientErrorMessage) {
6791
- this.failPendingTurn(new ClaudeTransientTurnError(transientErrorMessage));
6828
+ const sawActivity = this.pendingTurn?.sawActivity ?? false;
6829
+ this.failPendingTurn(new ClaudeTransientTurnError(transientErrorMessage, sawActivity));
6792
6830
  try {
6793
6831
  response.close();
6794
6832
  } catch (err) {
@@ -6820,7 +6858,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6820
6858
  } finally {
6821
6859
  this.sessionLinearForwarder?.flushThoughtAsResponse();
6822
6860
  const pending = this.pendingTurn;
6823
- const pendingError = loopError ? pending?.sawActivity && _ClaudeManager.isTransientTurnError(loopError) ? new Error("Claude session ended unexpectedly") : loopError : pending && !pending.sawActivity ? new ClaudeTransientTurnError("Claude session ended unexpectedly before producing a response") : new Error("Claude session ended unexpectedly");
6861
+ const pendingError = loopError ? pending?.sawActivity && _ClaudeManager.isTransientTurnError(loopError) ? new ClaudeTransientTurnError("Claude session ended unexpectedly mid-response", true) : loopError : pending && !pending.sawActivity ? new ClaudeTransientTurnError("Claude session ended unexpectedly before producing a response") : new Error("Claude session ended unexpectedly");
6824
6862
  this.failPendingTurn(pendingError);
6825
6863
  if (this.activeQuery === response) {
6826
6864
  this.clearSessionState();
@@ -6942,8 +6980,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
6942
6980
  static isTransientTurnErrorText(text) {
6943
6981
  return isTransientErrorText(text, { httpStatuses: CLAUDE_TRANSIENT_HTTP_STATUSES });
6944
6982
  }
6945
- static detectTransientTurnErrorInMessage(message, sawActivity) {
6946
- if (sawActivity) return null;
6983
+ static detectTransientTurnErrorInMessage(message) {
6947
6984
  if (message.type === "assistant" && "error" in message && typeof message.error === "string") {
6948
6985
  return _ClaudeManager.isTransientTurnErrorText(message.error) ? message.error : null;
6949
6986
  }
@@ -7302,7 +7339,7 @@ var AspClient = class {
7302
7339
  // src/managers/codex-asp/app-server-process.ts
7303
7340
  var DEFAULT_CODEX_BINARY = "codex";
7304
7341
  var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
7305
- var ENGINE_PACKAGE_VERSION = "0.1.329";
7342
+ var ENGINE_PACKAGE_VERSION = "0.1.331";
7306
7343
  var INITIALIZE_METHOD = "initialize";
7307
7344
  var INITIALIZED_NOTIFICATION = "initialized";
7308
7345
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.329",
3
+ "version": "0.1.331",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -31,6 +31,7 @@
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
33
  "@anthropic-ai/claude-agent-sdk": "0.3.168",
34
+ "@connectrpc/connect-node": "1.7.0",
34
35
  "@cursor/sdk": "1.0.19",
35
36
  "@hono/node-server": "^1.19.5",
36
37
  "hono": "^4.10.3",