replicas-engine 0.1.1226 → 0.1.1230

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.
@@ -5,14 +5,14 @@ import {
5
5
  getOriginDefaultBranch,
6
6
  monolithRequest,
7
7
  runGitCommand
8
- } from "./chunk-MRAUGYDC.js";
8
+ } from "./chunk-WGRWQVPL.js";
9
9
  import {
10
10
  extractCommandProtectionCommandText,
11
11
  findCommandProtectionGitLookups,
12
12
  findGitCommitSignals,
13
13
  findPrMergeSignals,
14
14
  parseCommandProtectionRequest
15
- } from "./chunk-OPV7WB6E.js";
15
+ } from "./chunk-3EB5JBOB.js";
16
16
 
17
17
  // src/services/command-protection-service.ts
18
18
  import { readFile, stat } from "fs/promises";
@@ -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-OPV7WB6E.js";
6
+ } from "./chunk-3EB5JBOB.js";
7
7
 
8
8
  // src/utils/exec.ts
9
9
  import { exec, execFile } from "child_process";
@@ -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-LF7ND553.js";
6
+ } from "./chunk-JTL6OI2V.js";
7
7
  import {
8
8
  isVersionBelow
9
- } from "./chunk-OPV7WB6E.js";
9
+ } from "./chunk-3EB5JBOB.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.1226";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.1230";
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-ATHUSFGB.js";
6
+ } from "./chunk-NIJQQIK2.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-OPV7WB6E.js";
16
+ } from "./chunk-3EB5JBOB.js";
17
17
 
18
18
  // src/managers/codex-asp/notification-dispatch.ts
19
19
  var TURN_STARTED_METHOD = "turn/started";
@@ -10,15 +10,15 @@ import {
10
10
  resolveDiffBase,
11
11
  runGitCommand,
12
12
  setAgentCredentialSnapshot
13
- } from "./chunk-MRAUGYDC.js";
13
+ } from "./chunk-WGRWQVPL.js";
14
14
  import {
15
15
  AppServerProcess,
16
16
  buildCodexAgentEnv
17
- } from "./chunk-ATHUSFGB.js";
17
+ } from "./chunk-NIJQQIK2.js";
18
18
  import {
19
19
  SUBPROCESS_MAX_BUFFER,
20
20
  execFileAsync
21
- } from "./chunk-LF7ND553.js";
21
+ } from "./chunk-JTL6OI2V.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-OPV7WB6E.js";
58
+ } from "./chunk-3EB5JBOB.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-E47NGZRP.js");
294
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-S5VIUXGQ.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-E47NGZRP.js");
316
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-S5VIUXGQ.js");
317
317
  await restartCodexAspHostIfRunning2();
318
318
  }
319
319
  setAgentCredentialSnapshot("codex", data);
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  SUBPROCESS_MAX_BUFFER,
6
6
  execFileAsync
7
- } from "./chunk-LF7ND553.js";
7
+ } from "./chunk-JTL6OI2V.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-OPV7WB6E.js";
21
+ } from "./chunk-3EB5JBOB.js";
22
22
 
23
23
  // src/runtime-env-loader.ts
24
24
  import { readFileSync } from "fs";
@@ -5,7 +5,7 @@ import {
5
5
  extractCommandProtectionCommandText,
6
6
  isRecord,
7
7
  parseCodeHostPrUrl
8
- } from "./chunk-OPV7WB6E.js";
8
+ } from "./chunk-3EB5JBOB.js";
9
9
 
10
10
  // src/services/published-pull-request-urls.ts
11
11
  function publishedPullRequestUrls(result) {
@@ -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-47SSCZMG.js";
7
- import "./chunk-MRAUGYDC.js";
8
- import "./chunk-LF7ND553.js";
6
+ } from "./chunk-BQ7N4ZEE.js";
7
+ import "./chunk-WGRWQVPL.js";
8
+ import "./chunk-JTL6OI2V.js";
9
9
  import {
10
10
  isRecord
11
11
  } from "./chunk-UZSNFLDQ.js";
12
- import "./chunk-OPV7WB6E.js";
12
+ import "./chunk-3EB5JBOB.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-LE7CVJC2.js";
16
+ } from "./chunk-SOWKXPU3.js";
17
17
  import {
18
18
  AppServerProcess,
19
19
  buildCodexAgentEnv
20
- } from "./chunk-ATHUSFGB.js";
21
- import "./chunk-LF7ND553.js";
20
+ } from "./chunk-NIJQQIK2.js";
21
+ import "./chunk-JTL6OI2V.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-OPV7WB6E.js";
31
+ } from "./chunk-3EB5JBOB.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-47SSCZMG.js";
30
+ } from "./chunk-BQ7N4ZEE.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-LE7CVJC2.js";
67
+ } from "./chunk-SOWKXPU3.js";
68
68
  import {
69
69
  publishedPullRequestUrls
70
- } from "./chunk-K77ILXKH.js";
70
+ } from "./chunk-XTRKRSAA.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-R7MHJUBF.js";
143
+ } from "./chunk-ULD7MOPE.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-MRAUGYDC.js";
152
+ } from "./chunk-WGRWQVPL.js";
153
153
  import {
154
154
  getCodexModelProvider
155
- } from "./chunk-ATHUSFGB.js";
155
+ } from "./chunk-NIJQQIK2.js";
156
156
  import {
157
157
  SUBPROCESS_MAX_BUFFER,
158
158
  execAsync,
159
159
  execFileAsync
160
- } from "./chunk-LF7ND553.js";
160
+ } from "./chunk-JTL6OI2V.js";
161
161
  import {
162
162
  isRecord as isRecord2
163
163
  } from "./chunk-UZSNFLDQ.js";
@@ -322,7 +322,6 @@ import {
322
322
  isAgentChatSkillActivityRecord,
323
323
  isAgentChatTurnActivityRecord,
324
324
  isCanvasTextKind,
325
- isChatHistoryEvent,
326
325
  isChatMessageSender,
327
326
  isClaudeAuthErrorText,
328
327
  isClaudeResultError,
@@ -367,8 +366,9 @@ import {
367
366
  parseReplicasConfigString,
368
367
  percentage,
369
368
  raceWithTimeout,
370
- readJsonlAppended,
371
- readJsonlPage,
369
+ readChatHistoryAppended,
370
+ readChatHistoryPage,
371
+ readChatHistoryRecord,
372
372
  readOllamaAuthEnv,
373
373
  readOpenAICompatibleAuthEnv,
374
374
  readReplicasRuntimeEnv,
@@ -394,7 +394,7 @@ import {
394
394
  workspaceTokenRequestSchema,
395
395
  workspaceTokenResponseSchema,
396
396
  wrapInTag
397
- } from "./chunk-OPV7WB6E.js";
397
+ } from "./chunk-3EB5JBOB.js";
398
398
  import {
399
399
  cloneMcpConfig,
400
400
  ensureCompatibilityImports,
@@ -11680,6 +11680,9 @@ ${request.message}` }, senderKey };
11680
11680
  subagentMcpParentChatId() {
11681
11681
  return this.subagentMcpEnabledForTurn ? this.subagentMcpChatId : void 0;
11682
11682
  }
11683
+ getHistoryEnd() {
11684
+ return this.getHistorySink()?.historyEnd;
11685
+ }
11683
11686
  async persistHistoryEvent(event) {
11684
11687
  const history = this.getHistorySink();
11685
11688
  if (!history?.appendDurably) throw new Error("Chat history is unavailable");
@@ -12360,7 +12363,7 @@ function isNotFoundError(error) {
12360
12363
  }
12361
12364
 
12362
12365
  // src/managers/codex-asp/codex-history-file.ts
12363
- import { createReadStream } from "fs";
12366
+ import { createReadStream, statSync } from "fs";
12364
12367
  import { appendFile as appendFile2, open, rename } from "fs/promises";
12365
12368
  import { createInterface } from "readline";
12366
12369
  var MIGRATION_FLUSH_CHARS = 1 << 20;
@@ -12370,9 +12373,20 @@ function isMissingFile(error) {
12370
12373
  var CodexHistoryFile = class {
12371
12374
  constructor(filePath) {
12372
12375
  this.filePath = filePath;
12376
+ try {
12377
+ this.reservedSize = statSync(filePath).size;
12378
+ } catch (error) {
12379
+ if (!isMissingFile(error)) throw error;
12380
+ this.reservedSize = 0;
12381
+ }
12373
12382
  }
12374
12383
  filePath;
12375
12384
  writeLock = new AsyncLock();
12385
+ // Bytes the file holds once every queued append lands; unknown after a failed write or a rewrite.
12386
+ reservedSize;
12387
+ get historyEnd() {
12388
+ return this.reservedSize;
12389
+ }
12376
12390
  /** Best-effort ordered append; failures must not disrupt the turn. */
12377
12391
  append(event) {
12378
12392
  void this.appendDurably(event).catch((error) => {
@@ -12380,8 +12394,18 @@ var CodexHistoryFile = class {
12380
12394
  });
12381
12395
  }
12382
12396
  appendDurably(event) {
12383
- return this.writeLock.run(() => appendFile2(this.filePath, `${JSON.stringify(event)}
12384
- `));
12397
+ const reserved = `${JSON.stringify(event)}
12398
+ `;
12399
+ if (this.reservedSize !== void 0) this.reservedSize += Buffer.byteLength(reserved);
12400
+ return this.writeLock.run(() => {
12401
+ const line = `${JSON.stringify(event)}
12402
+ `;
12403
+ if (line !== reserved) this.reservedSize = void 0;
12404
+ return appendFile2(this.filePath, line);
12405
+ }).catch((error) => {
12406
+ this.reservedSize = void 0;
12407
+ throw error;
12408
+ });
12385
12409
  }
12386
12410
  async flush() {
12387
12411
  await this.writeLock.drain();
@@ -12399,6 +12423,7 @@ var CodexHistoryFile = class {
12399
12423
  return;
12400
12424
  }
12401
12425
  if (parseAgentEventJsonlLine(firstLine)?.type === CODEX_HISTORY_FORMAT_EVENT_TYPE) return;
12426
+ this.reservedSize = void 0;
12402
12427
  await this.writeLock.run(async () => {
12403
12428
  const events = await this.loadAll();
12404
12429
  const rewritten = `${this.filePath}.migrating`;
@@ -12469,31 +12494,44 @@ var CodexHistoryFile = class {
12469
12494
  const cursor = parseChatHistoryCursor(page2.beforeCursor);
12470
12495
  if (page2.beforeCursor !== void 0 && cursor?.mode !== "range") throw new RangeError("Invalid chat history cursor");
12471
12496
  if (cursor?.events === null) return { events: [], beforeCursor: null };
12497
+ const { limit } = page2;
12498
+ return await this.read(async (size, readRange) => {
12499
+ if (page2.afterCursor !== void 0 && cursor === void 0) {
12500
+ const appended = await readChatHistoryAppended({ size, after: page2.afterCursor, compact: page2.compact, readRange });
12501
+ if (appended) return { events: appended.items, afterCursor: appended.after, appendsAfter: page2.afterCursor };
12502
+ }
12503
+ const result = await readChatHistoryPage({
12504
+ size,
12505
+ limit,
12506
+ userTurns: page2.userTurns,
12507
+ compact: page2.compact,
12508
+ before: cursor?.events,
12509
+ readRange
12510
+ });
12511
+ return {
12512
+ events: result.items,
12513
+ beforeCursor: createChatHistoryCursor({ events: result.before, turns: null }),
12514
+ ...cursor === void 0 ? { afterCursor: String(size) } : {}
12515
+ };
12516
+ }) ?? { events: [], beforeCursor: null };
12517
+ }
12518
+ async readRecord(record3) {
12519
+ return await this.read((size, readRange) => readChatHistoryRecord({ size, record: record3, readRange })) ?? void 0;
12520
+ }
12521
+ async read(use) {
12472
12522
  let file;
12473
12523
  try {
12474
12524
  file = await open(this.filePath, "r");
12475
12525
  } catch (error) {
12476
- if (isMissingFile(error)) return { events: [], beforeCursor: null };
12526
+ if (isMissingFile(error)) return null;
12477
12527
  throw error;
12478
12528
  }
12479
12529
  try {
12480
- const size = (await file.stat()).size;
12481
- const readRange = async (startByte, endByte) => {
12530
+ return await use((await file.stat()).size, async (startByte, endByte) => {
12482
12531
  const bytes = Buffer.allocUnsafe(endByte - startByte);
12483
12532
  const { bytesRead } = await file.read(bytes, 0, bytes.length, startByte);
12484
12533
  return bytes.subarray(0, bytesRead);
12485
- };
12486
- const parse2 = (value) => isChatHistoryEvent(value) ? value : void 0;
12487
- if (page2.afterCursor !== void 0 && cursor === void 0) {
12488
- const appended = await readJsonlAppended({ size, after: page2.afterCursor, readRange, parse: parse2 });
12489
- if (appended) return { events: appended.items, afterCursor: appended.after, appendsAfter: page2.afterCursor };
12490
- }
12491
- const result = await readJsonlPage({ size, limit: page2.limit, before: cursor?.events, readRange, parse: parse2 });
12492
- return {
12493
- events: result.items,
12494
- beforeCursor: createChatHistoryCursor({ events: result.before, turns: null }),
12495
- ...cursor === void 0 ? { afterCursor: String(size) } : {}
12496
- };
12534
+ });
12497
12535
  } finally {
12498
12536
  await file.close();
12499
12537
  }
@@ -14146,11 +14184,13 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
14146
14184
  async recordEvent(event, replicasMessageId) {
14147
14185
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
14148
14186
  const restampAmbient = event.type === "system" && "task_id" in event && this.ambientTaskIds.has(event.task_id);
14187
+ const payload = { ...event };
14188
+ delete payload.tool_use_result;
14149
14189
  const jsonEvent = {
14150
14190
  timestamp,
14151
14191
  type: `claude-${event.type}`,
14152
14192
  payload: {
14153
- ...event,
14193
+ ...payload,
14154
14194
  ...restampAmbient ? { ambient: true } : {},
14155
14195
  ...replicasMessageId ? { [USER_MESSAGE_ID_PAYLOAD_KEY]: replicasMessageId } : {}
14156
14196
  }
@@ -14342,7 +14382,8 @@ var CodexAspManager = class extends CodingAgentManager {
14342
14382
  appendDurably: (event) => {
14343
14383
  if (!this.historyFile) throw new Error("Chat history is unavailable");
14344
14384
  return this.historyFile.appendDurably(event);
14345
- }
14385
+ },
14386
+ historyEnd: this.historyFile?.historyEnd
14346
14387
  };
14347
14388
  }
14348
14389
  async subagentMcpForTurn(enabled) {
@@ -14545,10 +14586,10 @@ var CodexAspManager = class extends CodingAgentManager {
14545
14586
  }
14546
14587
  recordUserMessageEvent(request, extraPayload = {}) {
14547
14588
  const images = imageContentToUserMessageImages(request.images);
14548
- this.recordCodexHistoryEvent("event_msg", this.createUserMessageHistoryPayload(request, {
14589
+ this.onEvent(this.recordCodexHistoryEvent("event_msg", this.createUserMessageHistoryPayload(request, {
14549
14590
  ...images ? { images } : {},
14550
14591
  ...extraPayload
14551
- }));
14592
+ })));
14552
14593
  }
14553
14594
  async processMessageInternal(request, signal) {
14554
14595
  let userMessageRecorded = false;
@@ -39184,7 +39225,7 @@ var StreamableHTTPClientTransport = class {
39184
39225
  };
39185
39226
 
39186
39227
  // ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/server-manager.ts
39187
- import { mkdirSync as mkdirSync3, statSync as statSync2 } from "fs";
39228
+ import { mkdirSync as mkdirSync3, statSync as statSync3 } from "fs";
39188
39229
  import { isDeepStrictEqual } from "util";
39189
39230
 
39190
39231
  // ../node_modules/.bun/@modelcontextprotocol+client@2.0.0/node_modules/@modelcontextprotocol/client/dist/stdio.mjs
@@ -39617,7 +39658,7 @@ async function probeMcpEndpoint(url3) {
39617
39658
  }
39618
39659
 
39619
39660
  // ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/npx-resolver.ts
39620
- import { existsSync as existsSync9, readFileSync as readFileSync2, realpathSync, readdirSync, statSync, writeFileSync as writeFileSync2, renameSync, mkdirSync as mkdirSync2, openSync, readSync, closeSync, unlinkSync } from "fs";
39661
+ import { existsSync as existsSync9, readFileSync as readFileSync2, realpathSync, readdirSync, statSync as statSync2, writeFileSync as writeFileSync2, renameSync, mkdirSync as mkdirSync2, openSync, readSync, closeSync, unlinkSync } from "fs";
39621
39662
  import { join as join15, dirname as dirname8, extname as extname2, resolve as resolve2, sep } from "path";
39622
39663
 
39623
39664
  // ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/abort.ts
@@ -40068,7 +40109,7 @@ function safeRealpath(path7) {
40068
40109
  }
40069
40110
  function safeStatMtime(path7) {
40070
40111
  try {
40071
- return statSync(path7).mtimeMs;
40112
+ return statSync2(path7).mtimeMs;
40072
40113
  } catch {
40073
40114
  return 0;
40074
40115
  }
@@ -44720,7 +44761,7 @@ var McpServerManager = class {
44720
44761
  let args = (definition.args ?? []).map((argument) => interpolateEnvVars(argument));
44721
44762
  const cwd = resolveConfigPath(definition.cwd) ?? this.defaultCwd;
44722
44763
  if (cwd !== void 0) {
44723
- const cwdStats = statSync2(cwd, { throwIfNoEntry: false });
44764
+ const cwdStats = statSync3(cwd, { throwIfNoEntry: false });
44724
44765
  if (!cwdStats) throw new Error(`MCP server "${name}" configured cwd does not exist: "${cwd}"`);
44725
44766
  if (!cwdStats.isDirectory()) throw new Error(`MCP server "${name}" configured cwd is not a directory: "${cwd}"`);
44726
44767
  }
@@ -60034,14 +60075,14 @@ ${decisions}` };
60034
60075
  };
60035
60076
  return await chat.provider.enqueueMessage(
60036
60077
  request,
60037
- (result, acceptedMessage) => this.handleMessageAccepted(
60078
+ (result, acceptedMessage) => this.withUnpublishedHistory(chat, () => this.handleMessageAccepted(
60038
60079
  chatId,
60039
60080
  chat,
60040
60081
  request,
60041
60082
  acceptedMessage,
60042
60083
  result,
60043
60084
  typedMessage
60044
- )
60085
+ ))
60045
60086
  );
60046
60087
  } catch (error) {
60047
60088
  if (seenBeforeSend) this.forkSourceSeenBlocks.set(chatId, seenBeforeSend);
@@ -60266,6 +60307,16 @@ ${decisions}` };
60266
60307
  queue: chat.provider.getQueue()
60267
60308
  };
60268
60309
  }
60310
+ async withUnpublishedHistory(chat, run) {
60311
+ const start = chat.provider.getHistoryEnd();
60312
+ if (start === void 0) return run();
60313
+ chat.unpublishedHistoryStarts.push(start);
60314
+ try {
60315
+ return await run();
60316
+ } finally {
60317
+ chat.unpublishedHistoryStarts.splice(chat.unpublishedHistoryStarts.indexOf(start), 1);
60318
+ }
60319
+ }
60269
60320
  publishQueueIfChanged(chatId) {
60270
60321
  const chat = this.getRuntimeChat(chatId);
60271
60322
  if (!chat) return;
@@ -60279,33 +60330,35 @@ ${decisions}` };
60279
60330
  }
60280
60331
  async forgetPendingMessages(chat, messageIds) {
60281
60332
  if (messageIds.length === 0) return;
60282
- const removed = new Set(messageIds);
60283
- const event = {
60284
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
60285
- type: QUEUED_MESSAGE_REMOVED_EVENT_TYPE,
60286
- payload: { [REMOVED_MESSAGE_IDS_PAYLOAD_KEY]: [...removed] }
60287
- };
60288
- await chat.provider.persistHistoryEvent(event);
60289
- chat.persisted.removedMessageIds = [.../* @__PURE__ */ new Set([...chat.persisted.removedMessageIds ?? [], ...removed])].slice(-MAX_REMOVED_MESSAGE_IDS);
60290
- chat.pendingMessageIds = chat.pendingMessageIds.filter((messageId) => !removed.has(messageId));
60291
- this.forkSourceSeenBlocks.delete(chat.persisted.id);
60292
- for (const messageId of removed) {
60293
- chat.acceptedUserEvents.delete(messageId);
60294
- chat.errorNotificationTargets.delete(messageId);
60295
- }
60296
- await this.persistAllChats().catch((error) => {
60297
- console.error("[ChatService] Failed to persist queued-message removals:", error);
60298
- });
60299
- await this.publish({
60300
- type: "chat.turn.delta",
60301
- payload: { chatId: chat.persisted.id, event }
60302
- }).catch((error) => {
60303
- console.error("[ChatService] Failed to publish queued-message removals:", error);
60304
- });
60305
- this.publish({
60306
- type: "chat.updated",
60307
- payload: { chat: this.toSummary(chat) }
60308
- }).catch(() => {
60333
+ await this.withUnpublishedHistory(chat, async () => {
60334
+ const removed = new Set(messageIds);
60335
+ const event = {
60336
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
60337
+ type: QUEUED_MESSAGE_REMOVED_EVENT_TYPE,
60338
+ payload: { [REMOVED_MESSAGE_IDS_PAYLOAD_KEY]: [...removed] }
60339
+ };
60340
+ await chat.provider.persistHistoryEvent(event);
60341
+ chat.persisted.removedMessageIds = [.../* @__PURE__ */ new Set([...chat.persisted.removedMessageIds ?? [], ...removed])].slice(-MAX_REMOVED_MESSAGE_IDS);
60342
+ chat.pendingMessageIds = chat.pendingMessageIds.filter((messageId) => !removed.has(messageId));
60343
+ this.forkSourceSeenBlocks.delete(chat.persisted.id);
60344
+ for (const messageId of removed) {
60345
+ chat.acceptedUserEvents.delete(messageId);
60346
+ chat.errorNotificationTargets.delete(messageId);
60347
+ }
60348
+ await this.persistAllChats().catch((error) => {
60349
+ console.error("[ChatService] Failed to persist queued-message removals:", error);
60350
+ });
60351
+ await this.publish({
60352
+ type: "chat.turn.delta",
60353
+ payload: { chatId: chat.persisted.id, event }
60354
+ }).catch((error) => {
60355
+ console.error("[ChatService] Failed to publish queued-message removals:", error);
60356
+ });
60357
+ this.publish({
60358
+ type: "chat.updated",
60359
+ payload: { chat: this.toSummary(chat) }
60360
+ }).catch(() => {
60361
+ });
60309
60362
  });
60310
60363
  }
60311
60364
  async removeFromQueue(chatId, messageId) {
@@ -60624,6 +60677,9 @@ ${note}`;
60624
60677
  chat.activeErrorNotificationTargets = [];
60625
60678
  return true;
60626
60679
  }
60680
+ async getChatHistoryRecord(chatId, record3) {
60681
+ return new CodexHistoryFile(this.historyPath(this.requireChat(chatId).persisted)).readRecord(record3);
60682
+ }
60627
60683
  async getChatHistory(chatId, page2 = {}) {
60628
60684
  const chat = this.requireChat(chatId);
60629
60685
  const versionBeforeRead = this.toSummary(chat).historyVersion;
@@ -60902,6 +60958,7 @@ ${note}`;
60902
60958
  turnCompletion: null,
60903
60959
  publishedQueue: null,
60904
60960
  idleReleaseTimer: null,
60961
+ unpublishedHistoryStarts: [],
60905
60962
  live: false,
60906
60963
  release: null,
60907
60964
  errorNotificationTargets: /* @__PURE__ */ new Map(),
@@ -61260,6 +61317,10 @@ ${note}`;
61260
61317
  return;
61261
61318
  }
61262
61319
  const chat = chatId ? this.chats.get(chatId) : void 0;
61320
+ if (chat && event.type === "chat.turn.delta") {
61321
+ const historyEnd = chat.provider.getHistoryEnd();
61322
+ if (historyEnd !== void 0) event.payload.historyEnd = Math.min(historyEnd, ...chat.unpublishedHistoryStarts);
61323
+ }
61263
61324
  if (chat) {
61264
61325
  chat.historyVersion = event.id;
61265
61326
  if (event.type === "chat.created" || event.type === "chat.updated") {
@@ -62644,6 +62705,18 @@ function createV1Routes(deps) {
62644
62705
  }
62645
62706
  return loadChatHistory(c, c.req.param("chatId"), page2, "Failed to load chat history page", 500);
62646
62707
  });
62708
+ app2.get("/chats/:chatId/history/record", async (c) => {
62709
+ const record3 = { offset: Number(c.req.query("offset")), length: Number(c.req.query("length")) };
62710
+ try {
62711
+ const event = await deps.chatService.getChatHistoryRecord(c.req.param("chatId"), record3);
62712
+ return event ? c.json({ event }) : c.json(jsonError("Failed to load chat history record", "not a record of this chat"), 404);
62713
+ } catch (error) {
62714
+ return c.json(jsonError(
62715
+ "Failed to load chat history record",
62716
+ error instanceof Error ? error.message : "Unknown error"
62717
+ ), error instanceof ChatNotFoundError ? 404 : 500);
62718
+ }
62719
+ });
62647
62720
  app2.get("/chats/:chatId/slash-commands", async (c) => {
62648
62721
  try {
62649
62722
  const response = await deps.chatService.listSlashCommands(c.req.param("chatId"));
@@ -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-K77ILXKH.js";
6
+ } from "./chunk-XTRKRSAA.js";
7
7
  import {
8
8
  isRecord
9
9
  } from "./chunk-UZSNFLDQ.js";
10
10
  import {
11
11
  shouldRefreshPullRequests
12
- } from "./chunk-OPV7WB6E.js";
12
+ } from "./chunk-3EB5JBOB.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-OPV7WB6E.js";
12
+ } from "./chunk-3EB5JBOB.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.1226",
3
+ "version": "0.1.1230",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",