replicas-engine 0.1.543 → 0.1.545

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 +65 -11
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -702,7 +702,7 @@ var WORKSPACE_SIZES = ["small", "large"];
702
702
  var INVALID_WORKSPACE_SIZE_ERROR = `Invalid size: must be one of ${WORKSPACE_SIZES.join(", ")}`;
703
703
 
704
704
  // ../shared/src/e2b.ts
705
- var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-08-01-v3";
705
+ var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-08-02-v1";
706
706
 
707
707
  // ../shared/src/runtime-env.ts
708
708
  function shellQuotePosix(value) {
@@ -8811,7 +8811,43 @@ var CodexHistoryFile = class {
8811
8811
  }
8812
8812
  };
8813
8813
 
8814
+ // src/managers/claude-activity.ts
8815
+ function createClaudeSessionActivity() {
8816
+ return { state: "idle", observedAuthoritativeState: false };
8817
+ }
8818
+ function resetClaudeSessionActivity(activity) {
8819
+ activity.state = "idle";
8820
+ activity.observedAuthoritativeState = false;
8821
+ }
8822
+ function updateClaudeSessionActivity(activity, message) {
8823
+ if (message.type === "system" && message.subtype === "session_state_changed" && (message.state === "idle" || message.state === "running" || message.state === "requires_action")) {
8824
+ activity.state = message.state;
8825
+ activity.observedAuthoritativeState = true;
8826
+ return;
8827
+ }
8828
+ if (activity.observedAuthoritativeState) return;
8829
+ if (message.type === "system" && message.subtype === "init") {
8830
+ activity.state = "running";
8831
+ } else if (message.type === "result") {
8832
+ activity.state = "idle";
8833
+ }
8834
+ }
8835
+ function isClaudeSessionActive(activity) {
8836
+ return activity.state !== "idle";
8837
+ }
8838
+ function startClaudeSessionFallbackContinuation(activity) {
8839
+ if (activity.observedAuthoritativeState || activity.state !== "idle") return false;
8840
+ activity.state = "running";
8841
+ return true;
8842
+ }
8843
+ function expireClaudeSessionFallbackContinuation(activity) {
8844
+ if (activity.observedAuthoritativeState || activity.state === "idle") return false;
8845
+ activity.state = "idle";
8846
+ return true;
8847
+ }
8848
+
8814
8849
  // src/managers/claude-manager.ts
8850
+ var CLAUDE_ACTIVITY_STATUS_EVENT_TYPE = "claude-activity-status";
8815
8851
  var PromptStream = class {
8816
8852
  queue = [];
8817
8853
  closed = false;
@@ -8900,6 +8936,7 @@ var COMMAND_PROTECTION_SAFE_TOOLS = /* @__PURE__ */ new Set([
8900
8936
  var CLAUDE_PARTIAL_MESSAGE_FLUSH_MS = 80;
8901
8937
  var CLAUDE_SLASH_COMMANDS_CACHE_MS = 6e4;
8902
8938
  var CLAUDE_SLASH_COMMANDS_DISCOVERY_TIMEOUT_MS = 3e4;
8939
+ var CLAUDE_BACKGROUND_CONTINUATION_GRACE_MS = 5e3;
8903
8940
  function supportsClaudeThinkingDisplay(model) {
8904
8941
  const normalized = (normalizeClaudeModel(model) ?? model).toLowerCase();
8905
8942
  return AGENT_MODELS.claude.includes(normalized) || /^claude-(?:opus|sonnet|haiku)-[4-9]/.test(normalized);
@@ -9040,7 +9077,8 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
9040
9077
  sessionLoop = null;
9041
9078
  sessionLinearForwarder = null;
9042
9079
  pendingTurn = null;
9043
- sdkTurnActive = false;
9080
+ sessionActivity = createClaudeSessionActivity();
9081
+ backgroundContinuationTimer = null;
9044
9082
  pendingInterrupt = false;
9045
9083
  activeBackgroundTasks = /* @__PURE__ */ new Set();
9046
9084
  partialMessageStreams = /* @__PURE__ */ new Map();
@@ -9097,7 +9135,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
9097
9135
  return this.authRetrying;
9098
9136
  }
9099
9137
  isProcessing() {
9100
- return super.isProcessing() || this.sdkTurnActive;
9138
+ return super.isProcessing() || isClaudeSessionActive(this.sessionActivity);
9101
9139
  }
9102
9140
  hasActiveBackgroundTasks() {
9103
9141
  return this.activeBackgroundTasks.size > 0;
@@ -9620,6 +9658,8 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
9620
9658
  this.activeSessionPermissionMode = resolvedPermissionMode;
9621
9659
  this.sessionLinearForwarder = new LinearEventForwarder(ENGINE_ENV.LINEAR_SESSION_ID);
9622
9660
  this.activeBackgroundTasks.clear();
9661
+ this.clearBackgroundContinuationTimer();
9662
+ resetClaudeSessionActivity(this.sessionActivity);
9623
9663
  this.sessionLoop = this.runSessionLoop(response).catch((err) => {
9624
9664
  console.error("[ClaudeManager] Session loop crashed:", err);
9625
9665
  });
@@ -9667,15 +9707,14 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
9667
9707
  if (this.pendingTurn && _ClaudeManager.isTurnActivity(msg)) {
9668
9708
  this.pendingTurn.sawActivity = true;
9669
9709
  }
9670
- if (msg.type === "system" && msg.subtype === "init") {
9671
- this.sdkTurnActive = true;
9672
- } else if (msg.type === "result") {
9673
- this.sdkTurnActive = false;
9710
+ if (msg.type === "result" || _ClaudeManager.isTurnActivity(msg) || msg.type === "system" && (msg.subtype === "init" || msg.subtype === "session_state_changed")) {
9711
+ this.clearBackgroundContinuationTimer();
9674
9712
  }
9713
+ updateClaudeSessionActivity(this.sessionActivity, msg);
9675
9714
  const hadActiveBackgroundTasks = this.activeBackgroundTasks.size > 0;
9676
9715
  _ClaudeManager.updateBackgroundTaskState(msg, this.activeBackgroundTasks);
9677
9716
  if (hadActiveBackgroundTasks && this.activeBackgroundTasks.size === 0) {
9678
- this.sdkTurnActive = true;
9717
+ this.startBackgroundContinuationGrace();
9679
9718
  }
9680
9719
  await this.handleMessage(msg);
9681
9720
  if (linearSessionId && this.sessionLinearForwarder) {
@@ -9722,7 +9761,8 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
9722
9761
  this.activeSessionPermissionMode = null;
9723
9762
  this.sessionLinearForwarder = null;
9724
9763
  this.sessionLoop = null;
9725
- this.sdkTurnActive = false;
9764
+ this.clearBackgroundContinuationTimer();
9765
+ resetClaudeSessionActivity(this.sessionActivity);
9726
9766
  this.activeBackgroundTasks.clear();
9727
9767
  for (const timer of this.partialMessageFlushTimers.values()) {
9728
9768
  clearTimeout(timer);
@@ -9744,6 +9784,20 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
9744
9784
  this.pendingInterrupt = false;
9745
9785
  pending.reject(err);
9746
9786
  }
9787
+ startBackgroundContinuationGrace() {
9788
+ this.clearBackgroundContinuationTimer();
9789
+ if (!startClaudeSessionFallbackContinuation(this.sessionActivity)) return;
9790
+ this.backgroundContinuationTimer = setTimeout(() => {
9791
+ this.backgroundContinuationTimer = null;
9792
+ if (this.activeBackgroundTasks.size > 0 || !expireClaudeSessionFallbackContinuation(this.sessionActivity)) return;
9793
+ this.emitSyntheticEvent(CLAUDE_ACTIVITY_STATUS_EVENT_TYPE, { state: "idle" });
9794
+ }, CLAUDE_BACKGROUND_CONTINUATION_GRACE_MS);
9795
+ }
9796
+ clearBackgroundContinuationTimer() {
9797
+ if (!this.backgroundContinuationTimer) return;
9798
+ clearTimeout(this.backgroundContinuationTimer);
9799
+ this.backgroundContinuationTimer = null;
9800
+ }
9747
9801
  async tearDownSession() {
9748
9802
  const query2 = this.activeQuery;
9749
9803
  const stream = this.activePromptStream;
@@ -10209,7 +10263,7 @@ var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
10209
10263
  var MIN_CODEX_CLI_VERSION = "0.144.6";
10210
10264
  var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
10211
10265
  var codexCliVersionEnsured = null;
10212
- var ENGINE_PACKAGE_VERSION = "0.1.543";
10266
+ var ENGINE_PACKAGE_VERSION = "0.1.545";
10213
10267
  var INITIALIZE_METHOD = "initialize";
10214
10268
  var INITIALIZED_NOTIFICATION = "initialized";
10215
10269
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -15771,7 +15825,7 @@ var ChatService = class {
15771
15825
  }
15772
15826
  }).catch(() => {
15773
15827
  });
15774
- if (event.type === "replicas-tool-input-request" || event.type === "replicas-tool-input-resolved" || event.type === "compaction-status" || event.type === AUTH_RETRY_STATUS_EVENT_TYPE || event.type === CHAT_GOAL_EVENT_TYPE || event.type === "claude-result" || event.type === "claude-system" && event.payload.subtype === "init") {
15828
+ if (event.type === "replicas-tool-input-request" || event.type === "replicas-tool-input-resolved" || event.type === "compaction-status" || event.type === AUTH_RETRY_STATUS_EVENT_TYPE || event.type === CHAT_GOAL_EVENT_TYPE || event.type === CLAUDE_ACTIVITY_STATUS_EVENT_TYPE || event.type === "claude-result" || event.type === "claude-system" && (event.payload.subtype === "init" || event.payload.subtype === "session_state_changed" || event.payload.subtype === "background_tasks_changed" || coerceBackgroundTaskPayload(event.payload) !== null)) {
15775
15829
  this.publish({
15776
15830
  type: "chat.updated",
15777
15831
  payload: { chat: this.toSummary(chat) }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.543",
3
+ "version": "0.1.545",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",