replicas-engine 0.1.364 → 0.1.366

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 +50 -5
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -295,7 +295,7 @@ var WORKSPACE_SIZES = ["small", "large"];
295
295
  var INVALID_WORKSPACE_SIZE_ERROR = `Invalid size: must be one of ${WORKSPACE_SIZES.join(", ")}`;
296
296
 
297
297
  // ../shared/src/e2b.ts
298
- var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-06-28-v2";
298
+ var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-06-29-v1";
299
299
 
300
300
  // ../shared/src/runtime-env.ts
301
301
  function parsePosixEnvFile(content) {
@@ -7691,7 +7691,7 @@ var AspClient = class {
7691
7691
  // src/managers/codex-asp/app-server-process.ts
7692
7692
  var DEFAULT_CODEX_BINARY = "codex";
7693
7693
  var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
7694
- var ENGINE_PACKAGE_VERSION = "0.1.364";
7694
+ var ENGINE_PACKAGE_VERSION = "0.1.366";
7695
7695
  var INITIALIZE_METHOD = "initialize";
7696
7696
  var INITIALIZED_NOTIFICATION = "initialized";
7697
7697
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -8500,6 +8500,7 @@ var TranscriptUpdateCoalescer = class {
8500
8500
  };
8501
8501
 
8502
8502
  // src/managers/codex-asp/codex-asp-manager.ts
8503
+ var GOAL_TURN_CONTINUATION_GRACE_MS = 5e3;
8503
8504
  var CODEX_SLASH_COMMANDS_CACHE_MS = 3e4;
8504
8505
  function skillToSlashCommand(skill) {
8505
8506
  if (!skill.enabled) return null;
@@ -8844,9 +8845,9 @@ var CodexAspManager = class extends CodingAgentManager {
8844
8845
  );
8845
8846
  this.recordGoalChange(response.goal, true);
8846
8847
  return { turn: null, tempImagePaths: [] };
8847
- });
8848
+ }, { waitForActiveGoal: true });
8848
8849
  }
8849
- async observeTurn(host, threadId, request, startTurn) {
8850
+ async observeTurn(host, threadId, request, startTurn, options = {}) {
8850
8851
  let resolveCompleted;
8851
8852
  const completed = new Promise((resolve4) => {
8852
8853
  resolveCompleted = resolve4;
@@ -8859,6 +8860,10 @@ var CodexAspManager = class extends CodingAgentManager {
8859
8860
  void disposed.catch(() => {
8860
8861
  });
8861
8862
  let observedTurnId = null;
8863
+ const observedTurnIds = /* @__PURE__ */ new Set();
8864
+ let lastCompletedTurn = null;
8865
+ let completedResolved = false;
8866
+ let goalContinuationTimer = null;
8862
8867
  const completedItems = [];
8863
8868
  const agentMessageDeltas = /* @__PURE__ */ new Map();
8864
8869
  const linearSessionId = ENGINE_ENV.LINEAR_SESSION_ID;
@@ -8866,6 +8871,26 @@ var CodexAspManager = class extends CodingAgentManager {
8866
8871
  let tempImagePaths = [];
8867
8872
  const linearForwarder = new LinearEventForwarder(linearSessionId);
8868
8873
  const matchesTurn = (notificationThreadId, notificationTurnId) => notificationThreadId === threadId && (!observedTurnId || notificationTurnId === null || notificationTurnId === observedTurnId);
8874
+ const resolveIfGoalIdle = () => {
8875
+ if (!lastCompletedTurn || completedResolved) return;
8876
+ if (!options.waitForActiveGoal || this.currentGoal?.status !== "active") {
8877
+ if (goalContinuationTimer) {
8878
+ clearTimeout(goalContinuationTimer);
8879
+ goalContinuationTimer = null;
8880
+ }
8881
+ completedResolved = true;
8882
+ resolveCompleted(lastCompletedTurn);
8883
+ }
8884
+ };
8885
+ const scheduleGoalContinuationFallback = () => {
8886
+ if (!options.waitForActiveGoal || completedResolved || goalContinuationTimer) return;
8887
+ goalContinuationTimer = setTimeout(() => {
8888
+ goalContinuationTimer = null;
8889
+ if (!lastCompletedTurn || completedResolved) return;
8890
+ completedResolved = true;
8891
+ resolveCompleted(lastCompletedTurn);
8892
+ }, GOAL_TURN_CONTINUATION_GRACE_MS);
8893
+ };
8869
8894
  const handlers = {
8870
8895
  [ACCOUNT_RATE_LIMITS_UPDATED_METHOD]: (notification) => {
8871
8896
  this.handleRateLimits(notification.params.rateLimits);
@@ -8877,10 +8902,12 @@ var CodexAspManager = class extends CodingAgentManager {
8877
8902
  [THREAD_GOAL_UPDATED_METHOD]: (notification) => {
8878
8903
  if (notification.params.threadId !== threadId) return;
8879
8904
  this.recordGoalChange(notification.params.goal);
8905
+ resolveIfGoalIdle();
8880
8906
  },
8881
8907
  [THREAD_GOAL_CLEARED_METHOD]: (notification) => {
8882
8908
  if (notification.params.threadId !== threadId) return;
8883
8909
  this.recordGoalChange(null);
8910
+ resolveIfGoalIdle();
8884
8911
  },
8885
8912
  [THREAD_COMPACTED_METHOD]: (notification) => {
8886
8913
  if (!matchesTurn(notification.params.threadId, notification.params.turnId)) return;
@@ -8889,7 +8916,15 @@ var CodexAspManager = class extends CodingAgentManager {
8889
8916
  [TURN_STARTED_METHOD]: (notification) => {
8890
8917
  if (notification.params.threadId !== threadId) return;
8891
8918
  observedTurnId = notification.params.turn.id;
8919
+ observedTurnIds.add(notification.params.turn.id);
8892
8920
  this.activeTurnId = notification.params.turn.id;
8921
+ if (goalContinuationTimer) {
8922
+ clearTimeout(goalContinuationTimer);
8923
+ goalContinuationTimer = null;
8924
+ }
8925
+ lastCompletedTurn = null;
8926
+ completedItems.length = 0;
8927
+ agentMessageDeltas.clear();
8893
8928
  this.mergeTranscriptTurn(notification.params.threadId, notification.params.turn);
8894
8929
  this.emitTranscriptUpdated(notification.params.threadId, { immediate: true });
8895
8930
  linearForwarder.sendEvent(convertCodexAspNotification(notification, linearSessionId ?? ""));
@@ -8957,6 +8992,7 @@ var CodexAspManager = class extends CodingAgentManager {
8957
8992
  },
8958
8993
  [TURN_COMPLETED_METHOD]: (notification) => {
8959
8994
  if (notification.params.threadId !== threadId) return;
8995
+ if (!observedTurnIds.has(notification.params.turn.id)) return;
8960
8996
  observedTurnId = notification.params.turn.id;
8961
8997
  const turn = notification.params.turn;
8962
8998
  const items = turn.items.length > 0 ? [...turn.items] : [];
@@ -8981,7 +9017,12 @@ var CodexAspManager = class extends CodingAgentManager {
8981
9017
  const completedTurn = items.length > 0 ? { ...turn, items, itemsView: "full" } : turn;
8982
9018
  this.mergeTranscriptTurn(notification.params.threadId, completedTurn);
8983
9019
  this.emitTranscriptUpdated(notification.params.threadId, { immediate: true });
8984
- resolveCompleted(completedTurn);
9020
+ lastCompletedTurn = completedTurn;
9021
+ resolveIfGoalIdle();
9022
+ if (options.waitForActiveGoal && this.currentGoal?.status === "active") {
9023
+ void this.refreshThreadGoal(host, threadId).then(resolveIfGoalIdle).catch(() => {
9024
+ }).finally(scheduleGoalContinuationFallback);
9025
+ }
8985
9026
  }
8986
9027
  };
8987
9028
  const onNotification = (notification) => {
@@ -9007,6 +9048,7 @@ var CodexAspManager = class extends CodingAgentManager {
9007
9048
  tempImagePaths = started.tempImagePaths;
9008
9049
  if (started.turn) {
9009
9050
  observedTurnId = started.turn.id;
9051
+ observedTurnIds.add(started.turn.id);
9010
9052
  this.activeTurnId = started.turn.id;
9011
9053
  }
9012
9054
  const turn = await Promise.race([completed, disposed]);
@@ -9016,6 +9058,9 @@ var CodexAspManager = class extends CodingAgentManager {
9016
9058
  host.client.off("notification", onNotification);
9017
9059
  host.client.off("serverRequest", onServerRequest);
9018
9060
  host.client.off("dispose", onDispose);
9061
+ if (goalContinuationTimer) {
9062
+ clearTimeout(goalContinuationTimer);
9063
+ }
9019
9064
  this.transcriptUpdateCoalescer.flushPending();
9020
9065
  await removeTempImageFiles(tempImagePaths);
9021
9066
  if (host.client.isDisposed) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.364",
3
+ "version": "0.1.366",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",