replicas-engine 0.1.1187 → 0.1.1189

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.
@@ -8,9 +8,9 @@ import {
8
8
  listRunningCodexModels,
9
9
  restartCodexAspHost,
10
10
  restartCodexAspHostIfRunning
11
- } from "./chunk-RKL75ZH6.js";
11
+ } from "./chunk-NRFMMDOT.js";
12
12
  import "./chunk-VXPWAQR2.js";
13
- import "./chunk-JWABRKQK.js";
13
+ import "./chunk-QPVTETVI.js";
14
14
  import "./chunk-R6I3LT27.js";
15
15
  import "./chunk-UZSNFLDQ.js";
16
16
  import "./chunk-4T2K6OBK.js";
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  AppServerProcess,
16
16
  buildCodexAgentEnv
17
- } from "./chunk-JWABRKQK.js";
17
+ } from "./chunk-QPVTETVI.js";
18
18
  import {
19
19
  SUBPROCESS_MAX_BUFFER,
20
20
  execFileAsync
@@ -291,7 +291,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
291
291
  await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
292
292
  await this.applyCredentialsResponse(data);
293
293
  setAgentCredentialSnapshot("codex", data);
294
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-BSMKPH5N.js");
294
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-IY4BPGYV.js");
295
295
  await restartCodexAspHostIfRunning2();
296
296
  });
297
297
  await this.start(true);
@@ -313,7 +313,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
313
313
  const accountChanged = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex?.credentialId !== data.credentialId;
314
314
  await this.applyCredentialsResponse(data);
315
315
  if (restartOnChange && (accountChanged || CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index]))) {
316
- const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-BSMKPH5N.js");
316
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-IY4BPGYV.js");
317
317
  await restartCodexAspHostIfRunning2();
318
318
  }
319
319
  setAgentCredentialSnapshot("codex", data);
@@ -1837,10 +1837,18 @@ async function buildTurnInput(request) {
1837
1837
  }));
1838
1838
  return { input, tempImagePaths };
1839
1839
  }
1840
- async function buildTurnStartParams(threadId, request, serviceTier) {
1840
+ async function buildTurnStartParams(threadId, request, serviceTier, unreadRequests) {
1841
1841
  const effort = toReasoningEffort(request.thinkingLevel);
1842
1842
  const model = request.model ?? DEFAULT_MODEL;
1843
- const { input, tempImagePaths } = await buildTurnInput(request);
1843
+ const built = [];
1844
+ try {
1845
+ for (const turn of [...unreadRequests, request]) built.push(await buildTurnInput(turn));
1846
+ } catch (error) {
1847
+ await removeTempImageFiles(built.flatMap((turn) => turn.tempImagePaths));
1848
+ throw error;
1849
+ }
1850
+ const input = built.flatMap((turn) => turn.input);
1851
+ const tempImagePaths = built.flatMap((turn) => turn.tempImagePaths);
1844
1852
  const { mothershipInstructions } = splitMothershipInstructions(request.customInstructions);
1845
1853
  return {
1846
1854
  params: {
@@ -240,7 +240,7 @@ function getCodexModelProvider(method) {
240
240
  if (method === "foundry") return "azure";
241
241
  return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
242
242
  }
243
- var ENGINE_PACKAGE_VERSION = "0.1.1187";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.1189";
244
244
  var INITIALIZE_METHOD = "initialize";
245
245
  var INITIALIZED_NOTIFICATION = "initialized";
246
246
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  AspClient
6
- } from "./chunk-JWABRKQK.js";
6
+ } from "./chunk-QPVTETVI.js";
7
7
  import {
8
8
  ASTER_BASE_URL,
9
9
  ASTER_PROVIDER,
@@ -13,11 +13,11 @@ import {
13
13
  recoverCompletedTurn,
14
14
  spawnMuseMsp,
15
15
  startMuseSession
16
- } from "./chunk-3N6KIWSW.js";
16
+ } from "./chunk-W5ERK2HR.js";
17
17
  import {
18
18
  AppServerProcess,
19
19
  buildCodexAgentEnv
20
- } from "./chunk-JWABRKQK.js";
20
+ } from "./chunk-QPVTETVI.js";
21
21
  import "./chunk-R6I3LT27.js";
22
22
  import {
23
23
  AGENT,
package/dist/src/index.js CHANGED
@@ -64,7 +64,7 @@ import {
64
64
  spawnMuseMsp,
65
65
  startMuseSession,
66
66
  uuidV7
67
- } from "./chunk-3N6KIWSW.js";
67
+ } from "./chunk-W5ERK2HR.js";
68
68
  import {
69
69
  publishedPullRequestUrls
70
70
  } from "./chunk-NIT22CZW.js";
@@ -139,7 +139,7 @@ import {
139
139
  timestampFromSeconds,
140
140
  upsertCredentialFileLines,
141
141
  writeSecureCredentialFile
142
- } from "./chunk-RKL75ZH6.js";
142
+ } from "./chunk-NRFMMDOT.js";
143
143
  import {
144
144
  ENGINE_ENV,
145
145
  monolithRequest,
@@ -151,7 +151,7 @@ import {
151
151
  } from "./chunk-VXPWAQR2.js";
152
152
  import {
153
153
  getCodexModelProvider
154
- } from "./chunk-JWABRKQK.js";
154
+ } from "./chunk-QPVTETVI.js";
155
155
  import {
156
156
  SUBPROCESS_MAX_BUFFER,
157
157
  execAsync,
@@ -9630,6 +9630,7 @@ var EnvironmentDetailsService = class {
9630
9630
  details.supportsClaudeGoals = true;
9631
9631
  details.supportsGoalUpdates = true;
9632
9632
  details.supportsQueuedMessageEditing = true;
9633
+ details.supportsQueueEvents = true;
9633
9634
  details.supportsChatForking = true;
9634
9635
  details.supportsChatForkMessage = true;
9635
9636
  details.supportsDeferredChatForking = true;
@@ -10614,6 +10615,7 @@ function insertChronologically(existing, additions) {
10614
10615
 
10615
10616
  // src/managers/claude-manager.ts
10616
10617
  import {
10618
+ getSessionMessages,
10617
10619
  query
10618
10620
  } from "@anthropic-ai/claude-agent-sdk";
10619
10621
  import { randomUUID as randomUUID4 } from "crypto";
@@ -11158,6 +11160,7 @@ var MessageQueueService = class {
11158
11160
  processMessage;
11159
11161
  onProcessingChanged;
11160
11162
  onMessageStarted;
11163
+ onQueueChanged;
11161
11164
  acceptanceByMessage = /* @__PURE__ */ new WeakMap();
11162
11165
  // A withdrawal mark implies the entry was present when its acceptance
11163
11166
  // rejected; intentional removals (remove, clear, drain, steer) can never
@@ -11168,10 +11171,12 @@ var MessageQueueService = class {
11168
11171
  activeTurn = null;
11169
11172
  constructor(processMessage, onProcessingChanged = () => {
11170
11173
  }, onMessageStarted = async () => {
11174
+ }, onQueueChanged = () => {
11171
11175
  }) {
11172
11176
  this.processMessage = processMessage;
11173
11177
  this.onProcessingChanged = onProcessingChanged;
11174
11178
  this.onMessageStarted = onMessageStarted;
11179
+ this.onQueueChanged = onQueueChanged;
11175
11180
  }
11176
11181
  generateMessageId() {
11177
11182
  return `msg_${Date.now()}_${++this.messageIdCounter}`;
@@ -11209,6 +11214,7 @@ var MessageQueueService = class {
11209
11214
  if (!this.queue.includes(tail) && this.queueCancellationVersion === cancellationVersion && this.acceptanceWithdrawals.delete(tail)) {
11210
11215
  this.queue.push(tail);
11211
11216
  }
11217
+ this.onQueueChanged();
11212
11218
  });
11213
11219
  this.acceptanceByMessage.set(tail, acceptance);
11214
11220
  await acceptance;
@@ -11225,6 +11231,7 @@ var MessageQueueService = class {
11225
11231
  };
11226
11232
  if (this.processing) {
11227
11233
  this.queue.push(queuedMessage);
11234
+ this.onQueueChanged();
11228
11235
  const response2 = {
11229
11236
  queued: true,
11230
11237
  messageId,
@@ -11235,6 +11242,7 @@ var MessageQueueService = class {
11235
11242
  if (index !== -1) {
11236
11243
  this.queue.splice(index, 1);
11237
11244
  this.acceptanceWithdrawals.add(queuedMessage);
11245
+ this.onQueueChanged();
11238
11246
  }
11239
11247
  throw error;
11240
11248
  });
@@ -11264,6 +11272,7 @@ var MessageQueueService = class {
11264
11272
  this.activeTurn = turn;
11265
11273
  this.processing = true;
11266
11274
  this.onProcessingChanged(true);
11275
+ this.onQueueChanged();
11267
11276
  try {
11268
11277
  while (true) {
11269
11278
  const acceptance = this.acceptanceByMessage.get(queuedMessage);
@@ -11284,6 +11293,7 @@ var MessageQueueService = class {
11284
11293
  this.processing = false;
11285
11294
  if (this.queue.length === 0) {
11286
11295
  this.onProcessingChanged(false);
11296
+ this.onQueueChanged();
11287
11297
  }
11288
11298
  await this.processNextInQueue();
11289
11299
  }
@@ -11304,6 +11314,7 @@ var MessageQueueService = class {
11304
11314
  const drained = this.queue;
11305
11315
  this.queueCancellationVersion++;
11306
11316
  this.queue = [];
11317
+ this.onQueueChanged();
11307
11318
  return drained;
11308
11319
  }
11309
11320
  cancelActiveTurn() {
@@ -11319,17 +11330,20 @@ var MessageQueueService = class {
11319
11330
  const queuedMessage = this.queue.find((item) => item.id === messageId);
11320
11331
  if (!queuedMessage) return false;
11321
11332
  queuedMessage.message = message;
11333
+ this.onQueueChanged();
11322
11334
  return true;
11323
11335
  }
11324
11336
  takeFromQueue(messageId) {
11325
11337
  const index = this.queue.findIndex((m) => m.id === messageId);
11326
11338
  if (index === -1) return null;
11327
11339
  const [message] = this.queue.splice(index, 1);
11340
+ this.onQueueChanged();
11328
11341
  return { message, index };
11329
11342
  }
11330
11343
  restoreToQueue(message, index) {
11331
11344
  const clamped = Math.max(0, Math.min(index, this.queue.length));
11332
11345
  this.queue.splice(clamped, 0, message);
11346
+ this.onQueueChanged();
11333
11347
  }
11334
11348
  resumeIfIdle() {
11335
11349
  if (this.processing || this.queue.length === 0) return;
@@ -11348,6 +11362,7 @@ var MessageQueueService = class {
11348
11362
  if (index === clamped) return true;
11349
11363
  const [item] = this.queue.splice(index, 1);
11350
11364
  this.queue.splice(clamped, 0, item);
11365
+ this.onQueueChanged();
11351
11366
  return true;
11352
11367
  }
11353
11368
  /**
@@ -11357,6 +11372,7 @@ var MessageQueueService = class {
11357
11372
  this.queueCancellationVersion++;
11358
11373
  this.queue = [];
11359
11374
  this.processing = false;
11375
+ this.onQueueChanged();
11360
11376
  }
11361
11377
  };
11362
11378
 
@@ -11392,6 +11408,7 @@ var CodingAgentManager = class {
11392
11408
  hostOnTurnComplete;
11393
11409
  onProcessingChanged;
11394
11410
  onMessageStarted;
11411
+ onQueueChanged;
11395
11412
  onModelSwitched;
11396
11413
  authFallback;
11397
11414
  subagentMcpChatId;
@@ -11399,7 +11416,11 @@ var CodingAgentManager = class {
11399
11416
  usesAutoCompactTokens;
11400
11417
  autoCompactTokens = null;
11401
11418
  unreadSteers = /* @__PURE__ */ new Map();
11419
+ steersInFlight = /* @__PURE__ */ new Map();
11402
11420
  lastSenderKey;
11421
+ // Unset until this process sends a turn, so a restart can't mistake the first one for a change.
11422
+ sentTurn = false;
11423
+ lastCustomInstructions;
11403
11424
  onLastSenderKeyChanged;
11404
11425
  constructor(options) {
11405
11426
  this.workingDirectory = options.workingDirectory ?? ENGINE_ENV.WORKSPACE_ROOT;
@@ -11420,6 +11441,8 @@ var CodingAgentManager = class {
11420
11441
  });
11421
11442
  this.onMessageStarted = options.onMessageStarted ?? (async () => {
11422
11443
  });
11444
+ this.onQueueChanged = options.onQueueChanged ?? (() => {
11445
+ });
11423
11446
  this.onModelSwitched = options.onModelSwitched ?? (async () => {
11424
11447
  });
11425
11448
  this.lastSenderKey = options.lastSenderKey ?? null;
@@ -11489,16 +11512,28 @@ var CodingAgentManager = class {
11489
11512
  this.messageQueue = new MessageQueueService(
11490
11513
  async (request, signal) => {
11491
11514
  await Promise.all([this.refreshSubagentMcp(), this.refreshAutoCompactTokens()]);
11492
- if (signal.aborted) return;
11493
11515
  const { request: delivered, senderKey } = this.withSenderLine(request);
11516
+ const stopped = signal.aborted;
11517
+ if (stopped && !await this.keepStoppedRequest(delivered)) return;
11494
11518
  await this.saveLastSenderKey(senderKey);
11495
- await processMessage(delivered, signal);
11519
+ if (stopped) return;
11520
+ const instructionsChanged = this.sentTurn && this.lastCustomInstructions !== request.customInstructions && !request.goalMode && !request.message.trimStart().startsWith("/");
11521
+ this.sentTurn = true;
11522
+ this.lastCustomInstructions = request.customInstructions;
11523
+ const note = wrapInTag("Your instructions changed since your previous turn. Earlier turns followed the old version: follow the current instructions from here on, and leave earlier replies as they are.", REPLICAS_INSTRUCTIONS_TAG);
11524
+ await processMessage(instructionsChanged ? { ...delivered, message: `${delivered.message}
11525
+
11526
+ ${note}` } : delivered, signal);
11496
11527
  },
11497
11528
  this.onProcessingChanged,
11498
- this.onMessageStarted
11529
+ this.onMessageStarted,
11530
+ this.onQueueChanged
11499
11531
  );
11500
11532
  this.initialized = this.initialize();
11501
11533
  }
11534
+ async keepStoppedRequest(_request) {
11535
+ return false;
11536
+ }
11502
11537
  // Integration turns (Slack, GitHub, Linear) carry no sender fields and name their sender in the text, so they reset the key.
11503
11538
  withSenderLine(request) {
11504
11539
  if (request.goalMode || request.message.trimStart().startsWith("/")) return { request, senderKey: this.lastSenderKey };
@@ -11547,6 +11582,7 @@ ${request.message}` }, senderKey };
11547
11582
  const queuedMessages = this.messageQueue.drainQueue();
11548
11583
  const unreadSteers = [...this.unreadSteers.values()];
11549
11584
  this.unreadSteers.clear();
11585
+ this.onQueueChanged();
11550
11586
  this.messageQueue.cancelActiveTurn();
11551
11587
  const isProcessing = this.isProcessing() || (this.hasActiveBackgroundTasks?.() ?? false);
11552
11588
  if (isProcessing) {
@@ -11554,6 +11590,7 @@ ${request.message}` }, senderKey };
11554
11590
  await this.interruptActiveTurn();
11555
11591
  } catch (error) {
11556
11592
  for (const steer of unreadSteers) this.unreadSteers.set(steer.message.id, steer);
11593
+ this.onQueueChanged();
11557
11594
  this.restoreQueuedMessages(queuedMessages.map((message, index) => ({ message, index })));
11558
11595
  throw error;
11559
11596
  }
@@ -11590,7 +11627,7 @@ ${request.message}` }, senderKey };
11590
11627
  getQueue() {
11591
11628
  return [
11592
11629
  ...[...this.unreadSteers.values()].map(({ message, steeredAt }) => ({ ...toQueuedMessageInfo(message), steeredAt })),
11593
- ...this.messageQueue.getQueue().map(toQueuedMessageInfo)
11630
+ ...[...this.steersInFlight.values(), ...this.messageQueue.getQueue()].map(toQueuedMessageInfo)
11594
11631
  ];
11595
11632
  }
11596
11633
  async removeFromQueue(messageId, persistRemoval) {
@@ -11637,6 +11674,7 @@ ${request.message}` }, senderKey };
11637
11674
  if (!taken) {
11638
11675
  return { success: false, queue: this.getQueue() };
11639
11676
  }
11677
+ this.steersInFlight.set(messageId, taken.message);
11640
11678
  let steered = false;
11641
11679
  const { request: withSender, senderKey } = this.withSenderLine(taken.message);
11642
11680
  const note = wrapInTag("You received this message while working. The chat folds everything before your last message of this turn, so that message must answer it too, even if you already did earlier.", REPLICAS_INSTRUCTIONS_TAG);
@@ -11649,8 +11687,13 @@ ${note}` };
11649
11687
  } catch (error) {
11650
11688
  console.error("[CodingAgentManager] steerRequest threw, keeping message queued:", error);
11651
11689
  }
11652
- if (steered) this.unreadSteers.set(messageId, { message: taken.message, delivered, steeredAt: (/* @__PURE__ */ new Date()).toISOString() });
11653
- else this.restoreQueuedMessages([{ message: taken.message, index: 0 }]);
11690
+ this.steersInFlight.delete(messageId);
11691
+ if (steered) {
11692
+ this.unreadSteers.set(messageId, { message: taken.message, delivered, steeredAt: (/* @__PURE__ */ new Date()).toISOString() });
11693
+ this.onQueueChanged();
11694
+ } else {
11695
+ this.restoreQueuedMessages([{ message: taken.message, index: 0 }]);
11696
+ }
11654
11697
  return { success: steered, queue: this.getQueue() };
11655
11698
  }
11656
11699
  async sendNow(messageId) {
@@ -11678,6 +11721,7 @@ ${note}` };
11678
11721
  requeueUnreadSteers() {
11679
11722
  const steers = [...this.unreadSteers.values()].map(({ message }) => message);
11680
11723
  this.unreadSteers.clear();
11724
+ this.onQueueChanged();
11681
11725
  this.restoreQueuedMessages(steers.map((message) => ({ message, index: 0 })));
11682
11726
  if (steers.length > 0) {
11683
11727
  this.saveLastSenderKey(null).catch((error) => {
@@ -11687,7 +11731,7 @@ ${note}` };
11687
11731
  }
11688
11732
  markSteerRead(messageId) {
11689
11733
  const steer = this.unreadSteers.get(messageId);
11690
- this.unreadSteers.delete(messageId);
11734
+ if (this.unreadSteers.delete(messageId)) this.onQueueChanged();
11691
11735
  return steer?.delivered ?? this.messageQueue.takeFromQueue(messageId)?.message;
11692
11736
  }
11693
11737
  canDeliverSteersNow() {
@@ -12650,6 +12694,8 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
12650
12694
  pendingInterrupt = false;
12651
12695
  // Claude Code writes a started prompt to the session transcript even when the turn then fails, so a retry must not resend it.
12652
12696
  turnPromptRecorded = false;
12697
+ // Claude Code never sees a prompt stopped before it started, so it is sent again with the next message.
12698
+ unreadPrompt = null;
12653
12699
  backgroundTasks = new ClaudeBackgroundTasks();
12654
12700
  backgroundRecoveryAttempted = false;
12655
12701
  // Ultracode workflow child agents never reach the SDK stream (forwardSubagentText
@@ -12696,6 +12742,19 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
12696
12742
  await this.abortAllPendingToolInputs();
12697
12743
  await this.tearDownSession(true);
12698
12744
  }
12745
+ // Stop can tear a session down before its command_lifecycle event is read, so the transcript decides.
12746
+ async dropRecordedUnreadPrompt() {
12747
+ const unread = this.unreadPrompt;
12748
+ if (unread && this.sessionId && (await getSessionMessages(this.sessionId, { dir: this.workingDirectory })).some(({ uuid }) => uuid === unread.uuid)) {
12749
+ this.unreadPrompt = null;
12750
+ }
12751
+ }
12752
+ async keepStoppedRequest(request) {
12753
+ await this.dropRecordedUnreadPrompt();
12754
+ const { uuid, message } = await this.buildUserMessage(request);
12755
+ this.unreadPrompt = { uuid, content: [...this.unreadPrompt?.content ?? [], ...message.content] };
12756
+ return true;
12757
+ }
12699
12758
  canDeliverSteersNow() {
12700
12759
  return this.activeQuery !== null && this.backgroundTasks.foreground.size > 0;
12701
12760
  }
@@ -13232,23 +13291,32 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13232
13291
  if (!promptStream || !activeQuery) {
13233
13292
  throw new Error("Claude session unavailable after ensureSession");
13234
13293
  }
13294
+ await this.dropRecordedUnreadPrompt();
13295
+ const prompt = goalCommand ? [{ type: "text", text: `/goal ${goalObjective ?? "clear"}` }] : userMessage.message.content;
13296
+ const content = [...this.unreadPrompt?.content ?? [], ...prompt];
13235
13297
  if (this.pendingInterrupt || options.signal?.aborted) {
13236
13298
  this.pendingInterrupt = false;
13299
+ this.unreadPrompt = { uuid: userMessage.uuid, content };
13237
13300
  return;
13238
13301
  }
13239
13302
  this.turnPromptRecorded = false;
13240
- await new Promise((resolve7, reject) => {
13241
- const steers = options.steers ?? /* @__PURE__ */ new Map();
13242
- this.pendingTurn = {
13243
- resolve: resolve7,
13244
- reject,
13245
- sawActivity: false,
13246
- steers,
13247
- userMessageUuids: /* @__PURE__ */ new Set([userMessage.uuid, ...steers.keys()])
13248
- };
13249
- promptStream.push(goalCommand ? { ...userMessage, message: { role: "user", content: `/goal ${goalObjective ?? "clear"}` } } : userMessage);
13250
- for (const { userMessage: steer } of steers.values()) promptStream.push({ ...steer, priority: "next" });
13251
- });
13303
+ try {
13304
+ await new Promise((resolve7, reject) => {
13305
+ const steers = options.steers ?? /* @__PURE__ */ new Map();
13306
+ this.pendingTurn = {
13307
+ resolve: resolve7,
13308
+ reject,
13309
+ sawActivity: false,
13310
+ steers,
13311
+ userMessageUuids: /* @__PURE__ */ new Set([userMessage.uuid, ...steers.keys()])
13312
+ };
13313
+ promptStream.push({ ...userMessage, message: { role: "user", content } });
13314
+ for (const { userMessage: steer } of steers.values()) promptStream.push({ ...steer, priority: "next" });
13315
+ });
13316
+ } finally {
13317
+ if (this.turnPromptRecorded) this.unreadPrompt = null;
13318
+ else if (options.signal?.aborted) this.unreadPrompt = { uuid: userMessage.uuid, content };
13319
+ }
13252
13320
  }
13253
13321
  async buildUserMessage({ message, images }) {
13254
13322
  const content = [
@@ -13349,7 +13417,9 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
13349
13417
  const systemPrompt = {
13350
13418
  type: "preset",
13351
13419
  preset: "claude_code",
13352
- append: combinedInstructions
13420
+ append: combinedInstructions,
13421
+ // A recorded prompt ignores a new append on resume, so edited instructions would never apply.
13422
+ snapshot: false
13353
13423
  };
13354
13424
  const shared = await this.buildSharedQueryOptions();
13355
13425
  const interactiveAllowed = enableInteractiveTools && resolvedPermissionMode === "plan";
@@ -14100,6 +14170,8 @@ var CodexAspManager = class extends CodingAgentManager {
14100
14170
  slashCommandsCache = null;
14101
14171
  slashCommandsRequest = null;
14102
14172
  steeredTempImagePaths = [];
14173
+ // Codex never sees a message stopped before its turn started, so it is sent again with the next one.
14174
+ unreadRequests = [];
14103
14175
  compacting = false;
14104
14176
  steerLock = new AsyncLock();
14105
14177
  onCodexTurnStarted;
@@ -14145,6 +14217,11 @@ var CodexAspManager = class extends CodingAgentManager {
14145
14217
  }
14146
14218
  return super.interrupt(persistRemoval);
14147
14219
  }
14220
+ async keepStoppedRequest(request) {
14221
+ if (isCompactCommand(request.message) || getGoalCommand(request.message, request.goalMode)) return false;
14222
+ this.unreadRequests.push(request);
14223
+ return true;
14224
+ }
14148
14225
  async interruptActiveTurn() {
14149
14226
  if (!this.currentThreadId || !this.activeTurnId) {
14150
14227
  return;
@@ -14460,7 +14537,10 @@ var CodexAspManager = class extends CodingAgentManager {
14460
14537
  const threadId = await this.ensureThread(host, request, developerInstructions);
14461
14538
  const serviceTier = await this.resolveRequestedServiceTier(host, request);
14462
14539
  await this.applyThreadServiceTier(host, threadId, serviceTier);
14463
- if (signal.aborted) return;
14540
+ if (signal.aborted) {
14541
+ await this.keepStoppedRequest(request);
14542
+ return;
14543
+ }
14464
14544
  const runTurn = options.runTurn ?? ((aspHost, aspThreadId) => this.runTurn(aspHost, aspThreadId, request, serviceTier, signal));
14465
14545
  let completedTurn;
14466
14546
  try {
@@ -14499,6 +14579,12 @@ var CodexAspManager = class extends CodingAgentManager {
14499
14579
  );
14500
14580
  this.currentThreadId = response.thread.id;
14501
14581
  this.activeServiceTier = response.serviceTier;
14582
+ if (this.attachedClient === host.client && developerInstructions && developerInstructions !== this.attachedDeveloperInstructions) {
14583
+ await host.client.request(THREAD_INJECT_ITEMS_METHOD, {
14584
+ threadId: this.currentThreadId,
14585
+ items: [{ type: "message", role: "developer", content: [{ type: "input_text", text: developerInstructions }] }]
14586
+ });
14587
+ }
14502
14588
  this.attachedClient = host.client;
14503
14589
  this.attachedModel = requestedModel;
14504
14590
  this.attachedDeveloperInstructions = developerInstructions ?? null;
@@ -14594,17 +14680,28 @@ ${text.slice(-24e3)}`
14594
14680
  }
14595
14681
  }
14596
14682
  async runTurn(host, threadId, request, serviceTier, signal) {
14597
- const { params, tempImagePaths } = await buildTurnStartParams(threadId, request, serviceTier);
14683
+ const { params, tempImagePaths } = await buildTurnStartParams(threadId, request, serviceTier, this.unreadRequests).catch((error) => {
14684
+ this.unreadRequests = this.unreadRequests.map((unread) => ({ ...unread, images: void 0 }));
14685
+ throw error;
14686
+ });
14598
14687
  return this.observeTurn(host, threadId, request, signal, async () => {
14599
14688
  const turnStartResponse = await host.client.request(
14600
14689
  TURN_START_METHOD,
14601
14690
  params
14602
14691
  );
14692
+ this.unreadRequests = [];
14603
14693
  return { turn: turnStartResponse.turn, tempImagePaths };
14604
14694
  });
14605
14695
  }
14606
14696
  async runGoalTurn(host, threadId, request, objective, signal) {
14607
14697
  const { mothershipInstructions } = splitMothershipInstructions(request.customInstructions);
14698
+ const unreadContent = await Promise.all(this.unreadRequests.map(async (unread) => [
14699
+ { type: "input_text", text: unread.message },
14700
+ ...(await normalizeImages(unread.images ?? [])).map((image) => ({ type: "input_image", image_url: `data:${image.source.media_type};base64,${image.source.data}` }))
14701
+ ])).catch((error) => {
14702
+ this.unreadRequests = this.unreadRequests.map((unread) => ({ ...unread, images: void 0 }));
14703
+ throw error;
14704
+ });
14608
14705
  return this.observeTurn(host, threadId, request, signal, async () => {
14609
14706
  if (mothershipInstructions) {
14610
14707
  await host.client.request(THREAD_INJECT_ITEMS_METHOD, {
@@ -14612,6 +14709,13 @@ ${text.slice(-24e3)}`
14612
14709
  items: [{ type: "message", role: "developer", content: [{ type: "input_text", text: wrapInTag(mothershipInstructions, MOTHERSHIP_INSTRUCTIONS_TAG) }] }]
14613
14710
  });
14614
14711
  }
14712
+ if (unreadContent.length > 0) {
14713
+ await host.client.request(THREAD_INJECT_ITEMS_METHOD, {
14714
+ threadId,
14715
+ items: [{ type: "message", role: "user", content: unreadContent.flat() }]
14716
+ });
14717
+ this.unreadRequests = [];
14718
+ }
14615
14719
  const response = await host.client.request(
14616
14720
  THREAD_GOAL_SET_METHOD,
14617
14721
  { threadId, objective, status: "active" }
@@ -59898,6 +60002,17 @@ var ChatService = class {
59898
60002
  queue: chat.provider.getQueue()
59899
60003
  };
59900
60004
  }
60005
+ publishQueueIfChanged(chatId) {
60006
+ const chat = this.getRuntimeChat(chatId);
60007
+ if (!chat) return;
60008
+ const payload = this.getChatQueue(chatId);
60009
+ const serialized = JSON.stringify(payload);
60010
+ if (serialized === chat.publishedQueue) return;
60011
+ chat.publishedQueue = serialized;
60012
+ this.publish({ type: "chat.queue.changed", payload }).catch((error) => {
60013
+ console.error("[ChatService] Failed to publish chat queue:", { chatId, error });
60014
+ });
60015
+ }
59901
60016
  async forgetPendingMessages(chat, messageIds) {
59902
60017
  if (messageIds.length === 0) return;
59903
60018
  const removed = new Set(messageIds);
@@ -59984,6 +60099,7 @@ var ChatService = class {
59984
60099
  const result = await chat.provider.steerFromQueue(messageId);
59985
60100
  if (result.success) {
59986
60101
  chat.pendingMessageIds = chat.pendingMessageIds.filter((pendingMessageId) => pendingMessageId !== messageId);
60102
+ this.publishQueueIfChanged(chatId);
59987
60103
  }
59988
60104
  return result;
59989
60105
  }
@@ -59992,6 +60108,7 @@ var ChatService = class {
59992
60108
  const result = await chat.provider.sendNow(messageId);
59993
60109
  if (result.success && !result.queue.some(({ id, steeredAt }) => id === messageId && !steeredAt)) {
59994
60110
  chat.pendingMessageIds = chat.pendingMessageIds.filter((pendingMessageId) => pendingMessageId !== messageId);
60111
+ this.publishQueueIfChanged(chatId);
59995
60112
  }
59996
60113
  return result;
59997
60114
  }
@@ -60372,6 +60489,7 @@ var ChatService = class {
60372
60489
  if (processing) return;
60373
60490
  this.handleProcessingStopped(persisted.id);
60374
60491
  };
60492
+ const onQueueChanged = () => queueMicrotask(() => this.publishQueueIfChanged(persisted.id));
60375
60493
  const fallbackContext = () => {
60376
60494
  const chat = this.chats.get(persisted.id);
60377
60495
  return {
@@ -60405,6 +60523,7 @@ var ChatService = class {
60405
60523
  onEvent: onProviderEvent,
60406
60524
  onProcessingChanged,
60407
60525
  onMessageStarted,
60526
+ onQueueChanged,
60408
60527
  onUsageUpdate: onProviderUsage,
60409
60528
  fallbackContext,
60410
60529
  chatId: persisted.id,
@@ -60456,6 +60575,7 @@ var ChatService = class {
60456
60575
  turnRequest: null,
60457
60576
  turnAnswer: null,
60458
60577
  turnCompletion: null,
60578
+ publishedQueue: null,
60459
60579
  idleReleaseTimer: null,
60460
60580
  release: null,
60461
60581
  errorNotificationTargets: /* @__PURE__ */ new Map(),
@@ -60799,6 +60919,10 @@ var ChatService = class {
60799
60919
  ...input
60800
60920
  };
60801
60921
  const chatId = "chat" in event.payload && event.payload.chat ? event.payload.chat.id : "chatId" in event.payload ? event.payload.chatId : void 0;
60922
+ if (event.type === "chat.queue.changed") {
60923
+ await eventService.publish(event);
60924
+ return;
60925
+ }
60802
60926
  const chat = chatId ? this.chats.get(chatId) : void 0;
60803
60927
  if (chat) {
60804
60928
  chat.historyVersion = event.id;
@@ -60807,6 +60931,7 @@ var ChatService = class {
60807
60931
  }
60808
60932
  }
60809
60933
  await eventService.publish(event);
60934
+ if (chatId) this.publishQueueIfChanged(chatId);
60810
60935
  }
60811
60936
  async observeCurrentBranches(chat) {
60812
60937
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.1187",
3
+ "version": "0.1.1189",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",