replicas-engine 0.1.1220 → 0.1.1221

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,12 +8,12 @@ import {
8
8
  listRunningCodexModels,
9
9
  restartCodexAspHost,
10
10
  restartCodexAspHostIfRunning
11
- } from "./chunk-RTSUD5HU.js";
12
- import "./chunk-PS53BWCZ.js";
13
- import "./chunk-TB5U2PLS.js";
14
- import "./chunk-WOQM2PPJ.js";
11
+ } from "./chunk-LO42IHKY.js";
12
+ import "./chunk-KQWDACDY.js";
13
+ import "./chunk-BF4B3STE.js";
14
+ import "./chunk-XMAORHV5.js";
15
15
  import "./chunk-UZSNFLDQ.js";
16
- import "./chunk-ATDZVO6Z.js";
16
+ import "./chunk-VJTB4BFU.js";
17
17
  import "./chunk-VEQXQN22.js";
18
18
  export {
19
19
  CODEX_ULTRAFAST_SERVICE_TIER,
@@ -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-TB5U2PLS.js";
6
+ } from "./chunk-BF4B3STE.js";
7
7
  import {
8
8
  ASTER_BASE_URL,
9
9
  ASTER_PROVIDER,
@@ -13,7 +13,7 @@ import {
13
13
  isRecord,
14
14
  readOllamaAuthEnv,
15
15
  readOpenAICompatibleAuthEnv
16
- } from "./chunk-ATDZVO6Z.js";
16
+ } from "./chunk-VJTB4BFU.js";
17
17
 
18
18
  // src/managers/codex-asp/notification-dispatch.ts
19
19
  var TURN_STARTED_METHOD = "turn/started";
@@ -3,10 +3,10 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  execFileAsync
6
- } from "./chunk-WOQM2PPJ.js";
6
+ } from "./chunk-XMAORHV5.js";
7
7
  import {
8
8
  isVersionBelow
9
- } from "./chunk-ATDZVO6Z.js";
9
+ } from "./chunk-VJTB4BFU.js";
10
10
 
11
11
  // src/utils/codex-agent-env.ts
12
12
  function buildCodexAgentEnv(source = process.env) {
@@ -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.1220";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.1221";
244
244
  var INITIALIZE_METHOD = "initialize";
245
245
  var INITIALIZED_NOTIFICATION = "initialized";
246
246
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  SUBPROCESS_MAX_BUFFER,
6
6
  execFileAsync
7
- } from "./chunk-WOQM2PPJ.js";
7
+ } from "./chunk-XMAORHV5.js";
8
8
  import {
9
9
  isRecord as isRecord2
10
10
  } from "./chunk-UZSNFLDQ.js";
@@ -18,7 +18,7 @@ import {
18
18
  isValidAgentProvider,
19
19
  parsePosixEnvFile,
20
20
  readReplicasRuntimeEnv
21
- } from "./chunk-ATDZVO6Z.js";
21
+ } from "./chunk-VJTB4BFU.js";
22
22
 
23
23
  // src/runtime-env-loader.ts
24
24
  import { readFileSync } from "fs";
@@ -10,15 +10,15 @@ import {
10
10
  resolveDiffBase,
11
11
  runGitCommand,
12
12
  setAgentCredentialSnapshot
13
- } from "./chunk-PS53BWCZ.js";
13
+ } from "./chunk-KQWDACDY.js";
14
14
  import {
15
15
  AppServerProcess,
16
16
  buildCodexAgentEnv
17
- } from "./chunk-TB5U2PLS.js";
17
+ } from "./chunk-BF4B3STE.js";
18
18
  import {
19
19
  SUBPROCESS_MAX_BUFFER,
20
20
  execFileAsync
21
- } from "./chunk-WOQM2PPJ.js";
21
+ } from "./chunk-XMAORHV5.js";
22
22
  import {
23
23
  isRecord
24
24
  } from "./chunk-UZSNFLDQ.js";
@@ -55,7 +55,7 @@ import {
55
55
  resolveOpenAICompatibleModelsUrl,
56
56
  splitMothershipInstructions,
57
57
  withTimeout
58
- } from "./chunk-ATDZVO6Z.js";
58
+ } from "./chunk-VJTB4BFU.js";
59
59
 
60
60
  // src/managers/codex-token-manager.ts
61
61
  import { promises as fs } from "fs";
@@ -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-H5B2JRUI.js");
294
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-MTMDV3HK.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-H5B2JRUI.js");
316
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-MTMDV3HK.js");
317
317
  await restartCodexAspHostIfRunning2();
318
318
  }
319
319
  setAgentCredentialSnapshot("codex", data);
@@ -5,14 +5,14 @@ import {
5
5
  getOriginDefaultBranch,
6
6
  monolithRequest,
7
7
  runGitCommand
8
- } from "./chunk-PS53BWCZ.js";
8
+ } from "./chunk-KQWDACDY.js";
9
9
  import {
10
10
  extractCommandProtectionCommandText,
11
11
  findCommandProtectionGitLookups,
12
12
  findGitCommitSignals,
13
13
  findPrMergeSignals,
14
14
  parseCommandProtectionRequest
15
- } from "./chunk-ATDZVO6Z.js";
15
+ } from "./chunk-VJTB4BFU.js";
16
16
 
17
17
  // src/services/command-protection-service.ts
18
18
  import { readFile, stat } from "fs/promises";
@@ -5,7 +5,7 @@ import {
5
5
  extractCommandProtectionCommandText,
6
6
  isRecord,
7
7
  parseCodeHostPrUrl
8
- } from "./chunk-ATDZVO6Z.js";
8
+ } from "./chunk-VJTB4BFU.js";
9
9
 
10
10
  // src/services/published-pull-request-urls.ts
11
11
  function publishedPullRequestUrls(result) {
@@ -5925,7 +5925,18 @@ function collectCodexTurns(events) {
5925
5925
  }
5926
5926
  return turns;
5927
5927
  }
5928
+ var turnMessages = /* @__PURE__ */ new WeakMap();
5928
5929
  function messagesForCodexTurn(turn) {
5930
+ const [first] = turn.items;
5931
+ const cached = first ? turnMessages.get(first) : void 0;
5932
+ if (cached && cached.turn.id === turn.id && cached.turn.status === turn.status && cached.turn.completedAt === turn.completedAt && cached.turn.error === turn.error && cached.turn.items.length === turn.items.length && cached.turn.items.every((item, index) => item === turn.items[index])) {
5933
+ return cached.messages;
5934
+ }
5935
+ const messages = codexTurnMessages(turn);
5936
+ if (first) turnMessages.set(first, { turn, messages });
5937
+ return messages;
5938
+ }
5939
+ function codexTurnMessages(turn) {
5929
5940
  const items = turn.items.map((item, index) => ({ item, index })).sort((a, b) => parseTimestampMs(a.item.timestamp) - parseTimestampMs(b.item.timestamp) || a.index - b.index).map(({ item }) => item);
5930
5941
  const reasoning = items.filter(
5931
5942
  (item) => item.type === "reasoning" && item.text.trim().length > 0
@@ -6188,16 +6199,14 @@ function takeRecordedPrompt(prompts, echo, turnIndex) {
6188
6199
  function parseCodexEvents(events) {
6189
6200
  const messages = [];
6190
6201
  const turns = collectCodexTurns(events);
6191
- const turnInsertions = [];
6202
+ const turnInsertions = /* @__PURE__ */ new Map();
6192
6203
  const pendingCommands = /* @__PURE__ */ new Map();
6193
6204
  const pendingToolCalls = /* @__PURE__ */ new Map();
6194
6205
  const pendingPatches = /* @__PURE__ */ new Map();
6195
6206
  events.forEach((event, eventIndex) => {
6196
6207
  const turnId = codexItemFromEvent(event)?.turnId ?? codexTurnFromEvent(event)?.turnId;
6197
6208
  if (turnId !== void 0) {
6198
- if (!turnInsertions.some((insertion) => insertion.turnId === turnId)) {
6199
- turnInsertions.push({ index: messages.length, turnId });
6200
- }
6209
+ if (!turnInsertions.has(turnId)) turnInsertions.set(turnId, messages.length);
6201
6210
  return;
6202
6211
  }
6203
6212
  if (event.type === "codex-asp-error") {
@@ -6377,7 +6386,7 @@ function parseCodexEvents(events) {
6377
6386
  recordedPrompts.set(content, prompts);
6378
6387
  });
6379
6388
  const claimedPrompts = /* @__PURE__ */ new Set();
6380
- for (const { index, turnId } of turnInsertions.reverse()) {
6389
+ for (const [turnId, index] of [...turnInsertions].reverse()) {
6381
6390
  const turn = turns.get(turnId);
6382
6391
  if (!turn) continue;
6383
6392
  const kept = [];
@@ -7053,12 +7062,9 @@ function parseStringField(value) {
7053
7062
  return trimmed ? trimmed : null;
7054
7063
  }
7055
7064
  function parseCreateResultTaskId(resultText) {
7056
- try {
7057
- const parsed = JSON.parse(resultText);
7058
- if (isRecord(parsed) && isRecord(parsed.task)) {
7059
- return parseStringField(parsed.task.id);
7060
- }
7061
- } catch {
7065
+ const parsed = resultText.trimStart().startsWith("{") ? safeJsonParse(resultText, null) : null;
7066
+ if (isRecord(parsed) && isRecord(parsed.task)) {
7067
+ return parseStringField(parsed.task.id);
7062
7068
  }
7063
7069
  return resultText.match(/\bTask\s+#?([A-Za-z0-9_-]+)\s+created\b/i)?.[1] ?? null;
7064
7070
  }
@@ -7110,10 +7116,10 @@ var TaskAccumulator = class {
7110
7116
  }
7111
7117
  return false;
7112
7118
  }
7113
- processCreateResult(toolUseId, resultText) {
7119
+ processCreateResult(toolUseId, content) {
7114
7120
  const pending = this.tasksByCreateToolUseId.get(toolUseId);
7115
7121
  if (!pending) return false;
7116
- const taskId = parseCreateResultTaskId(resultText);
7122
+ const taskId = parseCreateResultTaskId(extractToolResultText(content, ""));
7117
7123
  if (!taskId) return false;
7118
7124
  this.tasksByTaskId.set(taskId, pending);
7119
7125
  this.tasksByCreateToolUseId.delete(toolUseId);
@@ -7135,7 +7141,7 @@ var TaskAccumulator = class {
7135
7141
  return this.processToolUse(block.name, block.id, toAccumulatorInput(block.input));
7136
7142
  }
7137
7143
  if (block.type === "tool_result" && typeof block.tool_use_id === "string") {
7138
- return this.processCreateResult(block.tool_use_id, extractToolResultText(block.content, ""));
7144
+ return this.processCreateResult(block.tool_use_id, block.content);
7139
7145
  }
7140
7146
  return false;
7141
7147
  }
@@ -7145,7 +7151,18 @@ var TaskAccumulator = class {
7145
7151
  var ABORTED_TERMINAL_REASONS = /* @__PURE__ */ new Set(["aborted_streaming", "aborted_tools"]);
7146
7152
  var COMMAND_TOOL_NAMES = /* @__PURE__ */ new Set(["Bash", "bash", "shell"]);
7147
7153
  var FILE_TOOL_NAMES = /* @__PURE__ */ new Set(["Write", "Edit"]);
7148
- function fileOrCommandMessage(toolName, toolUseId, input, timestamp) {
7154
+ var toolMessageTemplates = /* @__PURE__ */ new WeakMap();
7155
+ var toolResults = /* @__PURE__ */ new WeakMap();
7156
+ function fileOrCommandMessage(block, timestamp) {
7157
+ let template = toolMessageTemplates.get(block);
7158
+ if (!template) {
7159
+ const input = typeof block.input === "string" ? safeJsonParse(block.input, {}) : block.input ?? {};
7160
+ template = toolMessageTemplate(block.name ?? "", block.id ?? "", input);
7161
+ toolMessageTemplates.set(block, template);
7162
+ }
7163
+ return { ...template, timestamp };
7164
+ }
7165
+ function toolMessageTemplate(toolName, toolUseId, input) {
7149
7166
  if (COMMAND_TOOL_NAMES.has(toolName)) {
7150
7167
  const command = typeof input.command === "string" ? input.command : "";
7151
7168
  const skillNames = skillNamesFromCommand(command);
@@ -7155,8 +7172,7 @@ function fileOrCommandMessage(toolName, toolUseId, input, timestamp) {
7155
7172
  command,
7156
7173
  ...skillNames.length > 0 ? { skillNames } : {},
7157
7174
  output: "",
7158
- status: "in_progress",
7159
- timestamp
7175
+ status: "in_progress"
7160
7176
  };
7161
7177
  }
7162
7178
  const filePath = typeof input.file_path === "string" ? input.file_path : "";
@@ -7184,28 +7200,41 @@ function fileOrCommandMessage(toolName, toolUseId, input, timestamp) {
7184
7200
  id: `patch-${toolUseId}`,
7185
7201
  type: "patch",
7186
7202
  operations: [{ action: toolName === "Write" ? "add" : "update", path: filePath, diff }],
7187
- status: "in_progress",
7188
- timestamp
7203
+ status: "in_progress"
7189
7204
  };
7190
7205
  }
7191
- function createSubagentMessage(messageIndex, timestamp, fields) {
7192
- const { id = `subagent-${timestamp}-${messageIndex}`, ...message2 } = fields;
7193
- return { id, type: "subagent", ...message2, timestamp };
7206
+ function createSubagentMessage(timestamp, fields) {
7207
+ return { id: `subagent-${fields.toolUseId}`, type: "subagent", ...fields, timestamp };
7194
7208
  }
7195
- function collectNestedEvents(events, toolUseId) {
7196
- return events.filter((e) => e.payload.parent_tool_use_id === toolUseId).map(({ timestamp, type, payload }) => ({ timestamp, type, payload }));
7209
+ function groupNestedEvents(events) {
7210
+ const nested = /* @__PURE__ */ new Map();
7211
+ for (const { timestamp, type, payload } of events) {
7212
+ const parent = payload.parent_tool_use_id;
7213
+ if (typeof parent !== "string") continue;
7214
+ const siblings = nested.get(parent);
7215
+ if (siblings) siblings.push({ timestamp, type, payload });
7216
+ else nested.set(parent, [{ timestamp, type, payload }]);
7217
+ }
7218
+ return nested;
7197
7219
  }
7198
- function readToolResult(event) {
7199
- if (event.type !== "claude-user") return void 0;
7220
+ function extractToolResult(event) {
7200
7221
  const toolResult = normalizeContentBlocks(event.payload.message?.content).find((c) => c.type === "tool_result");
7201
7222
  if (!toolResult?.tool_use_id) return void 0;
7223
+ const output = extractToolResultText(toolResult.content);
7224
+ const exitCode = output.match(/exit code:?\s*(\d+)/i)?.[1];
7202
7225
  return {
7203
7226
  toolResult,
7204
7227
  toolUseId: toolResult.tool_use_id,
7205
- output: extractToolResultText(toolResult.content),
7228
+ output,
7229
+ exitCode: exitCode === void 0 ? void 0 : parseInt(exitCode, 10),
7206
7230
  status: toolResult.is_error ? "failed" : "completed"
7207
7231
  };
7208
7232
  }
7233
+ function readToolResult(event) {
7234
+ if (event.type !== "claude-user") return void 0;
7235
+ if (!toolResults.has(event)) toolResults.set(event, extractToolResult(event));
7236
+ return toolResults.get(event);
7237
+ }
7209
7238
  function coerceClaudeResultPayload(payload) {
7210
7239
  return {
7211
7240
  is_error: typeof payload.is_error === "boolean" ? payload.is_error : void 0,
@@ -7262,6 +7291,8 @@ function parseClaudeEvents(events, parentToolUseId) {
7262
7291
  });
7263
7292
  };
7264
7293
  const taskAccumulator = new TaskAccumulator();
7294
+ let nestedEventsByParent;
7295
+ const collectNestedEvents = (toolUseId) => (nestedEventsByParent ??= groupNestedEvents(events)).get(toolUseId) ?? [];
7265
7296
  const todoItems = /* @__PURE__ */ new WeakMap();
7266
7297
  const taskSnapshot = () => taskAccumulator.getTasks().map((task) => {
7267
7298
  const item = todoItems.get(task) ?? { text: task.subject, completed: task.status === "completed", itemStatus: task.status };
@@ -7456,8 +7487,8 @@ function parseClaudeEvents(events, parentToolUseId) {
7456
7487
  });
7457
7488
  if (toolName === "Task" || toolName === "Agent") {
7458
7489
  const inputObj = typeof toolInput === "string" ? safeJsonParse(toolInput, {}) : toolInput;
7459
- const nestedEvents = collectNestedEvents(events, toolUseId);
7460
- messages.push(createSubagentMessage(messages.length, event.timestamp, {
7490
+ const nestedEvents = collectNestedEvents(toolUseId);
7491
+ messages.push(createSubagentMessage(event.timestamp, {
7461
7492
  toolUseId,
7462
7493
  description: inputObj.description || "Subagent Task",
7463
7494
  prompt: inputObj.prompt || "",
@@ -7467,14 +7498,13 @@ function parseClaudeEvents(events, parentToolUseId) {
7467
7498
  nestedEvents
7468
7499
  }));
7469
7500
  } else if (COMMAND_TOOL_NAMES.has(toolName) || FILE_TOOL_NAMES.has(toolName)) {
7470
- const inputObj = typeof toolInput === "string" ? safeJsonParse(toolInput, {}) : toolInput;
7471
- messages.push(fileOrCommandMessage(toolName, toolUseId, inputObj, event.timestamp));
7501
+ messages.push(fileOrCommandMessage(block, event.timestamp));
7472
7502
  } else if (toolName === "TaskCreate" || toolName === "TaskUpdate" || toolName === "TaskList") {
7473
7503
  taskAccumulator.processContentBlock(block);
7474
7504
  const snapshot = taskSnapshot();
7475
7505
  if (snapshot.length > 0) {
7476
7506
  messages.push({
7477
- id: `todo-${event.timestamp}-${messages.length}`,
7507
+ id: `todo-${toolUseId}`,
7478
7508
  type: "todo_list",
7479
7509
  items: snapshot,
7480
7510
  status: "completed",
@@ -7485,7 +7515,7 @@ function parseClaudeEvents(events, parentToolUseId) {
7485
7515
  const inputObj = typeof toolInput === "string" ? safeJsonParse(toolInput, {}) : toolInput;
7486
7516
  const query = inputObj.query || "";
7487
7517
  messages.push({
7488
- id: `search-${event.timestamp}-${messages.length}`,
7518
+ id: `search-${toolUseId}`,
7489
7519
  type: "web_search",
7490
7520
  query,
7491
7521
  status: "in_progress",
@@ -7503,7 +7533,7 @@ function parseClaudeEvents(events, parentToolUseId) {
7503
7533
  });
7504
7534
  } else {
7505
7535
  messages.push(createCallDisplayMessage({
7506
- id: `toolcall-${event.timestamp}-${messages.length}`,
7536
+ id: `toolcall-${toolUseId}`,
7507
7537
  server: "claude",
7508
7538
  tool: toolName,
7509
7539
  input: toolInput,
@@ -7554,10 +7584,8 @@ function parseClaudeEvents(events, parentToolUseId) {
7554
7584
  for (const workflowAgent of payload.workflowAgents ?? []) {
7555
7585
  const existingWorkflowAgent = workflowAgentMessageMap.get(workflowAgent.agentId);
7556
7586
  const nextWorkflowAgent = createSubagentMessage(
7557
- messages.length,
7558
7587
  existingWorkflowAgent?.timestamp ?? event.timestamp,
7559
7588
  {
7560
- id: existingWorkflowAgent?.id,
7561
7589
  toolUseId: workflowAgent.agentId,
7562
7590
  description: workflowAgent.label,
7563
7591
  prompt: workflowAgent.promptPreview ?? existingWorkflowAgent?.prompt ?? "",
@@ -7565,7 +7593,7 @@ function parseClaudeEvents(events, parentToolUseId) {
7565
7593
  model: workflowAgent.model ?? existingWorkflowAgent?.model,
7566
7594
  status: workflowAgent.state === "done" ? "completed" : workflowAgent.state === "error" ? "failed" : "in_progress",
7567
7595
  output: workflowAgent.resultPreview ?? workflowAgent.lastToolSummary ?? existingWorkflowAgent?.output,
7568
- nestedEvents: existingWorkflowAgent?.nestedEvents ?? collectNestedEvents(events, workflowAgent.agentId)
7596
+ nestedEvents: existingWorkflowAgent?.nestedEvents ?? collectNestedEvents(workflowAgent.agentId)
7569
7597
  }
7570
7598
  );
7571
7599
  workflowAgentMessageMap.set(workflowAgent.agentId, upsertDisplayMessage(messages, nextWorkflowAgent));
@@ -7573,7 +7601,7 @@ function parseClaudeEvents(events, parentToolUseId) {
7573
7601
  const existing = taskMessageMap.get(payload.taskId);
7574
7602
  const nextStatus = payload.subtype === "task_notification" ? normalizeBackgroundTaskStatus(payload.status) : payload.subtype === "task_updated" && payload.patch?.status !== void 0 ? normalizeBackgroundTaskStatus(payload.patch?.status) : existing?.status ?? "in_progress";
7575
7603
  const nextMessage = {
7576
- id: existing?.id ?? `task-${event.timestamp}-${messages.length}`,
7604
+ id: `task-${payload.taskId}`,
7577
7605
  type: "background_task",
7578
7606
  taskId: payload.taskId,
7579
7607
  toolUseId: payload.toolUseId ?? existing?.toolUseId,
@@ -7630,7 +7658,7 @@ function parseClaudeEvents(events, parentToolUseId) {
7630
7658
  for (const [streamId, { tool, timestamp }] of streamingTools) {
7631
7659
  if (toolCallMap.has(tool.id) || supersededStreamIds.has(streamId)) continue;
7632
7660
  if (!COMMAND_TOOL_NAMES.has(tool.name) && !FILE_TOOL_NAMES.has(tool.name)) continue;
7633
- messages.push(fileOrCommandMessage(tool.name, tool.id, "filePath" in tool ? { file_path: tool.filePath } : { command: tool.command }, timestamp));
7661
+ messages.push(fileOrCommandMessage({ type: "tool_use", id: tool.id, name: tool.name, input: "filePath" in tool ? { file_path: tool.filePath } : { command: tool.command } }, timestamp));
7634
7662
  }
7635
7663
  filteredEvents.forEach((event) => {
7636
7664
  const result = readToolResult(event);
@@ -7647,12 +7675,7 @@ function parseClaudeEvents(events, parentToolUseId) {
7647
7675
  if (message2.type === "command") {
7648
7676
  message2.output = resultContent;
7649
7677
  message2.status = status;
7650
- const exitCodeMatch = resultContent.match(/exit code:?\s*(\d+)/i);
7651
- if (exitCodeMatch) {
7652
- message2.exitCode = parseInt(exitCodeMatch[1], 10);
7653
- } else {
7654
- message2.exitCode = isError ? 1 : 0;
7655
- }
7678
+ message2.exitCode = result.exitCode ?? (isError ? 1 : 0);
7656
7679
  } else if (message2.type === "patch") {
7657
7680
  message2.status = status;
7658
7681
  } else if (message2.type === "web_search") {
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  HOOK_EXEC_MAX_BUFFER_BYTES
6
- } from "./chunk-ATDZVO6Z.js";
6
+ } from "./chunk-VJTB4BFU.js";
7
7
 
8
8
  // src/utils/exec.ts
9
9
  import { exec, execFile } from "child_process";
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  evaluateCommandProtection
6
- } from "./chunk-VWJQDAPO.js";
7
- import "./chunk-PS53BWCZ.js";
8
- import "./chunk-WOQM2PPJ.js";
6
+ } from "./chunk-PVGN5NZQ.js";
7
+ import "./chunk-KQWDACDY.js";
8
+ import "./chunk-XMAORHV5.js";
9
9
  import {
10
10
  isRecord
11
11
  } from "./chunk-UZSNFLDQ.js";
12
- import "./chunk-ATDZVO6Z.js";
12
+ import "./chunk-VJTB4BFU.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/command-protection-hook.ts
@@ -13,12 +13,12 @@ import {
13
13
  recoverCompletedTurn,
14
14
  spawnMuseMsp,
15
15
  startMuseSession
16
- } from "./chunk-AQYJVDBQ.js";
16
+ } from "./chunk-3M2EIHTB.js";
17
17
  import {
18
18
  AppServerProcess,
19
19
  buildCodexAgentEnv
20
- } from "./chunk-TB5U2PLS.js";
21
- import "./chunk-WOQM2PPJ.js";
20
+ } from "./chunk-BF4B3STE.js";
21
+ import "./chunk-XMAORHV5.js";
22
22
  import {
23
23
  AGENT,
24
24
  OPENCODE_GO_PROVIDER,
@@ -28,7 +28,7 @@ import {
28
28
  headlessAgentUsagePath,
29
29
  isRecord,
30
30
  withTimeout
31
- } from "./chunk-ATDZVO6Z.js";
31
+ } from "./chunk-VJTB4BFU.js";
32
32
  import "./chunk-VEQXQN22.js";
33
33
 
34
34
  // src/headless-agent.ts
package/dist/src/index.js CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  evaluateCommandProtection,
28
28
  extractToolCommand,
29
29
  reportCommandProtectionBlock
30
- } from "./chunk-VWJQDAPO.js";
30
+ } from "./chunk-PVGN5NZQ.js";
31
31
  import {
32
32
  ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
33
33
  AGENT_MESSAGE_DELTA_METHOD,
@@ -64,10 +64,10 @@ import {
64
64
  spawnMuseMsp,
65
65
  startMuseSession,
66
66
  uuidV7
67
- } from "./chunk-AQYJVDBQ.js";
67
+ } from "./chunk-3M2EIHTB.js";
68
68
  import {
69
69
  publishedPullRequestUrls
70
- } from "./chunk-43FGSQ6T.js";
70
+ } from "./chunk-SUSXUDD3.js";
71
71
  import {
72
72
  ACCOUNT_RATE_LIMITS_READ_METHOD,
73
73
  AsyncLock,
@@ -140,7 +140,7 @@ import {
140
140
  timestampFromSeconds,
141
141
  upsertCredentialFileLines,
142
142
  writeSecureCredentialFile
143
- } from "./chunk-RTSUD5HU.js";
143
+ } from "./chunk-LO42IHKY.js";
144
144
  import {
145
145
  ENGINE_ENV,
146
146
  monolithRequest,
@@ -149,15 +149,15 @@ import {
149
149
  reloadEngineEnv,
150
150
  resolveDiffBase,
151
151
  setAgentCredentialSnapshot
152
- } from "./chunk-PS53BWCZ.js";
152
+ } from "./chunk-KQWDACDY.js";
153
153
  import {
154
154
  getCodexModelProvider
155
- } from "./chunk-TB5U2PLS.js";
155
+ } from "./chunk-BF4B3STE.js";
156
156
  import {
157
157
  SUBPROCESS_MAX_BUFFER,
158
158
  execAsync,
159
159
  execFileAsync
160
- } from "./chunk-WOQM2PPJ.js";
160
+ } from "./chunk-XMAORHV5.js";
161
161
  import {
162
162
  isRecord as isRecord2
163
163
  } from "./chunk-UZSNFLDQ.js";
@@ -393,7 +393,7 @@ import {
393
393
  workspaceTokenRequestSchema,
394
394
  workspaceTokenResponseSchema,
395
395
  wrapInTag
396
- } from "./chunk-ATDZVO6Z.js";
396
+ } from "./chunk-VJTB4BFU.js";
397
397
  import {
398
398
  cloneMcpConfig,
399
399
  ensureCompatibilityImports,
@@ -10560,6 +10560,16 @@ function findDuplicatePosition(index, event) {
10560
10560
  return match;
10561
10561
  }
10562
10562
  function mergeWorkspaceChatHistoryEvents(primary, supplemental, removedMessageIds = []) {
10563
+ const [flush] = supplemental;
10564
+ const flushStreamId = supplemental.length === 1 && removedMessageIds.length === 0 ? getEventStreamId(flush) : null;
10565
+ if (flushStreamId !== null && getUserMessageId(flush) === null && getComparableUserMessage(flush) === null) {
10566
+ const slot = primary.findIndex((event) => getEventStreamId(event) === flushStreamId);
10567
+ if (slot !== -1 && !primary.some((event) => event.type === QUEUED_MESSAGE_REMOVED_EVENT_TYPE)) {
10568
+ const merged2 = [...primary];
10569
+ merged2[slot] = flush;
10570
+ return merged2;
10571
+ }
10572
+ }
10563
10573
  const removed = new Set(removedMessageIds);
10564
10574
  for (const events of [primary, supplemental]) {
10565
10575
  for (const event of events) {
@@ -10601,7 +10611,7 @@ function mergeWorkspaceChatHistoryEvents(primary, supplemental, removedMessageId
10601
10611
  list[position] = null;
10602
10612
  unindexEvent(listIndex, previous, position);
10603
10613
  addEvent(event);
10604
- } else if (getEventStreamId(event) !== null || messageId !== null && messageId === getUserMessageId(previous)) {
10614
+ } else if ((getEventStreamId(event) !== null || messageId !== null && messageId === getUserMessageId(previous)) && workspaceChatEventSignals(event).json !== workspaceChatEventSignals(previous).json) {
10605
10615
  list[position] = event;
10606
10616
  unindexEvent(listIndex, previous, position);
10607
10617
  indexMergedEvent(listIndex, event, position);
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  publishedPullRequestUrls
6
- } from "./chunk-43FGSQ6T.js";
6
+ } from "./chunk-SUSXUDD3.js";
7
7
  import {
8
8
  isRecord
9
9
  } from "./chunk-UZSNFLDQ.js";
10
10
  import {
11
11
  shouldRefreshPullRequests
12
- } from "./chunk-ATDZVO6Z.js";
12
+ } from "./chunk-VJTB4BFU.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/services/post-tool-pr-notifier.ts
@@ -9,7 +9,7 @@ import {
9
9
  spawnSubagentRequestSchema,
10
10
  subagentResponseSchema,
11
11
  waitSubagentRequestSchema
12
- } from "./chunk-ATDZVO6Z.js";
12
+ } from "./chunk-VJTB4BFU.js";
13
13
  import "./chunk-VEQXQN22.js";
14
14
 
15
15
  // src/subagent-mcp.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.1220",
3
+ "version": "0.1.1221",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",