replicas-engine 0.1.1225 → 0.1.1226

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-UZ2QAPF2.js";
12
- import "./chunk-6ZM4T2RV.js";
13
- import "./chunk-UNNBJDIC.js";
14
- import "./chunk-4TXSP6DJ.js";
11
+ } from "./chunk-R7MHJUBF.js";
12
+ import "./chunk-MRAUGYDC.js";
13
+ import "./chunk-ATHUSFGB.js";
14
+ import "./chunk-LF7ND553.js";
15
15
  import "./chunk-UZSNFLDQ.js";
16
- import "./chunk-SE6ENDPR.js";
16
+ import "./chunk-OPV7WB6E.js";
17
17
  import "./chunk-VEQXQN22.js";
18
18
  export {
19
19
  CODEX_ULTRAFAST_SERVICE_TIER,
@@ -5,14 +5,14 @@ import {
5
5
  getOriginDefaultBranch,
6
6
  monolithRequest,
7
7
  runGitCommand
8
- } from "./chunk-6ZM4T2RV.js";
8
+ } from "./chunk-MRAUGYDC.js";
9
9
  import {
10
10
  extractCommandProtectionCommandText,
11
11
  findCommandProtectionGitLookups,
12
12
  findGitCommitSignals,
13
13
  findPrMergeSignals,
14
14
  parseCommandProtectionRequest
15
- } from "./chunk-SE6ENDPR.js";
15
+ } from "./chunk-OPV7WB6E.js";
16
16
 
17
17
  // src/services/command-protection-service.ts
18
18
  import { readFile, stat } from "fs/promises";
@@ -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-4TXSP6DJ.js";
6
+ } from "./chunk-LF7ND553.js";
7
7
  import {
8
8
  isVersionBelow
9
- } from "./chunk-SE6ENDPR.js";
9
+ } from "./chunk-OPV7WB6E.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.1225";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.1226";
244
244
  var INITIALIZE_METHOD = "initialize";
245
245
  var INITIALIZED_NOTIFICATION = "initialized";
246
246
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -5,7 +5,7 @@ import {
5
5
  extractCommandProtectionCommandText,
6
6
  isRecord,
7
7
  parseCodeHostPrUrl
8
- } from "./chunk-SE6ENDPR.js";
8
+ } from "./chunk-OPV7WB6E.js";
9
9
 
10
10
  // src/services/published-pull-request-urls.ts
11
11
  function publishedPullRequestUrls(result) {
@@ -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-UNNBJDIC.js";
6
+ } from "./chunk-ATHUSFGB.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-SE6ENDPR.js";
16
+ } from "./chunk-OPV7WB6E.js";
17
17
 
18
18
  // src/managers/codex-asp/notification-dispatch.ts
19
19
  var TURN_STARTED_METHOD = "turn/started";
@@ -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-SE6ENDPR.js";
6
+ } from "./chunk-OPV7WB6E.js";
7
7
 
8
8
  // src/utils/exec.ts
9
9
  import { exec, execFile } from "child_process";
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  SUBPROCESS_MAX_BUFFER,
6
6
  execFileAsync
7
- } from "./chunk-4TXSP6DJ.js";
7
+ } from "./chunk-LF7ND553.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-SE6ENDPR.js";
21
+ } from "./chunk-OPV7WB6E.js";
22
22
 
23
23
  // src/runtime-env-loader.ts
24
24
  import { readFileSync } from "fs";
@@ -1501,6 +1501,7 @@ var CONTEXT_USAGE_EVENT_TYPE = "context-usage";
1501
1501
  // ../shared/src/engine/v1.ts
1502
1502
  import { z as z4 } from "zod";
1503
1503
  var MERGED_MESSAGE_SEPARATOR = "\n\n<!-- replicas:merged -->\n\n";
1504
+ var ENGINE_STREAM_LAST_EVENT_ID_HEADER = "Last-Event-ID";
1504
1505
  var ENGINE_HEALTH_WAIT_HEADER = "X-Replicas-Health-Wait";
1505
1506
  var ENGINE_HEALTH_WAIT_QUERY_PARAM = "wait_ms";
1506
1507
  var ENGINE_HEALTH_MAX_WAIT_MS = 2e3;
@@ -10123,6 +10124,7 @@ export {
10123
10124
  coerceChatGoalPayload,
10124
10125
  CONTEXT_USAGE_EVENT_TYPE,
10125
10126
  MERGED_MESSAGE_SEPARATOR,
10127
+ ENGINE_STREAM_LAST_EVENT_ID_HEADER,
10126
10128
  ENGINE_HEALTH_WAIT_HEADER,
10127
10129
  ENGINE_HEALTH_WAIT_QUERY_PARAM,
10128
10130
  ENGINE_HEALTH_MAX_WAIT_MS,
@@ -10,15 +10,15 @@ import {
10
10
  resolveDiffBase,
11
11
  runGitCommand,
12
12
  setAgentCredentialSnapshot
13
- } from "./chunk-6ZM4T2RV.js";
13
+ } from "./chunk-MRAUGYDC.js";
14
14
  import {
15
15
  AppServerProcess,
16
16
  buildCodexAgentEnv
17
- } from "./chunk-UNNBJDIC.js";
17
+ } from "./chunk-ATHUSFGB.js";
18
18
  import {
19
19
  SUBPROCESS_MAX_BUFFER,
20
20
  execFileAsync
21
- } from "./chunk-4TXSP6DJ.js";
21
+ } from "./chunk-LF7ND553.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-SE6ENDPR.js";
58
+ } from "./chunk-OPV7WB6E.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-HTNK63ET.js");
294
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-E47NGZRP.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-HTNK63ET.js");
316
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-E47NGZRP.js");
317
317
  await restartCodexAspHostIfRunning2();
318
318
  }
319
319
  setAgentCredentialSnapshot("codex", data);
@@ -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-XVG3AOGM.js";
7
- import "./chunk-6ZM4T2RV.js";
8
- import "./chunk-4TXSP6DJ.js";
6
+ } from "./chunk-47SSCZMG.js";
7
+ import "./chunk-MRAUGYDC.js";
8
+ import "./chunk-LF7ND553.js";
9
9
  import {
10
10
  isRecord
11
11
  } from "./chunk-UZSNFLDQ.js";
12
- import "./chunk-SE6ENDPR.js";
12
+ import "./chunk-OPV7WB6E.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-HOOI54LZ.js";
16
+ } from "./chunk-LE7CVJC2.js";
17
17
  import {
18
18
  AppServerProcess,
19
19
  buildCodexAgentEnv
20
- } from "./chunk-UNNBJDIC.js";
21
- import "./chunk-4TXSP6DJ.js";
20
+ } from "./chunk-ATHUSFGB.js";
21
+ import "./chunk-LF7ND553.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-SE6ENDPR.js";
31
+ } from "./chunk-OPV7WB6E.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-XVG3AOGM.js";
30
+ } from "./chunk-47SSCZMG.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-HOOI54LZ.js";
67
+ } from "./chunk-LE7CVJC2.js";
68
68
  import {
69
69
  publishedPullRequestUrls
70
- } from "./chunk-C2I3YQ5R.js";
70
+ } from "./chunk-K77ILXKH.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-UZ2QAPF2.js";
143
+ } from "./chunk-R7MHJUBF.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-6ZM4T2RV.js";
152
+ } from "./chunk-MRAUGYDC.js";
153
153
  import {
154
154
  getCodexModelProvider
155
- } from "./chunk-UNNBJDIC.js";
155
+ } from "./chunk-ATHUSFGB.js";
156
156
  import {
157
157
  SUBPROCESS_MAX_BUFFER,
158
158
  execAsync,
159
159
  execFileAsync
160
- } from "./chunk-4TXSP6DJ.js";
160
+ } from "./chunk-LF7ND553.js";
161
161
  import {
162
162
  isRecord as isRecord2
163
163
  } from "./chunk-UZSNFLDQ.js";
@@ -212,6 +212,7 @@ import {
212
212
  ENGINE_HEALTH_WAIT_QUERY_PARAM,
213
213
  ENGINE_SEND_MESSAGE_FAILED_ERROR,
214
214
  ENGINE_SLEEP_PATH,
215
+ ENGINE_STREAM_LAST_EVENT_ID_HEADER,
215
216
  ENVIRONMENT_HOOK_RUN_LOG_LIMIT,
216
217
  GITHUB_CREDENTIAL_REFRESH_PATH,
217
218
  GITLAB_CREDENTIAL_REFRESH_PATH,
@@ -393,7 +394,7 @@ import {
393
394
  workspaceTokenRequestSchema,
394
395
  workspaceTokenResponseSchema,
395
396
  wrapInTag
396
- } from "./chunk-SE6ENDPR.js";
397
+ } from "./chunk-OPV7WB6E.js";
397
398
  import {
398
399
  cloneMcpConfig,
399
400
  ensureCompatibilityImports,
@@ -10300,32 +10301,97 @@ import { mkdir as mkdir5 } from "fs/promises";
10300
10301
  import { join as join6 } from "path";
10301
10302
  import { randomUUID as randomUUID2 } from "crypto";
10302
10303
  var EVENTS_FILE = join6(ENGINE_DIR, "events.jsonl");
10304
+ var MAX_REPLAY_EVENTS = 2e3;
10305
+ var MAX_REPLAY_CHARS = 4 * 1024 * 1024;
10306
+ function partialKey(event) {
10307
+ if (event.type !== "chat.turn.delta") return null;
10308
+ const { type } = event.payload.event;
10309
+ if (type !== CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE && type !== CODEX_ITEM_PARTIAL_EVENT_TYPE) return null;
10310
+ const streamId = getEventStreamId(event.payload.event);
10311
+ return streamId ? `${event.payload.chatId}:${type}:${streamId}` : null;
10312
+ }
10303
10313
  var EventService = class {
10304
- subscribers = /* @__PURE__ */ new Map();
10314
+ subscribers = /* @__PURE__ */ new Set();
10305
10315
  writer = new StreamWriter();
10316
+ epoch = randomUUID2();
10317
+ seq = 0;
10318
+ replay = [];
10319
+ replayChars = 0;
10320
+ // Newest seq dropped for space: a client that last saw an older seq cannot resume.
10321
+ replayFloor = 0;
10322
+ latestPartials = /* @__PURE__ */ new Map();
10306
10323
  async initialize() {
10307
10324
  await mkdir5(ENGINE_DIR, { recursive: true });
10308
10325
  this.writer.open(EVENTS_FILE);
10309
10326
  }
10310
- subscribe(subscriber) {
10311
- const id = randomUUID2();
10312
- this.subscribers.set(id, subscriber);
10327
+ subscribe(subscriber, lastEventId) {
10328
+ const separator = lastEventId?.lastIndexOf(":") ?? -1;
10329
+ const after = lastEventId ? Number(lastEventId.slice(separator + 1)) : Number.NaN;
10330
+ const resumed = separator > 0 && lastEventId?.slice(0, separator) === this.epoch && Number.isSafeInteger(after) && after >= this.replayFloor && after <= this.seq;
10331
+ const opened = {
10332
+ id: randomUUID2(),
10333
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
10334
+ type: "engine.stream.opened",
10335
+ payload: { epoch: this.epoch, seq: this.seq, resumed }
10336
+ };
10337
+ subscriber(`id: ${this.epoch}:${resumed ? after : this.seq}
10338
+ event: ${opened.type}
10339
+ data: ${JSON.stringify(opened)}
10340
+
10341
+ `);
10342
+ if (resumed) {
10343
+ for (const entry of this.replay) {
10344
+ if (entry.seq > after) subscriber(entry.frame);
10345
+ }
10346
+ }
10347
+ this.subscribers.add(subscriber);
10313
10348
  return () => {
10314
- this.subscribers.delete(id);
10349
+ this.subscribers.delete(subscriber);
10315
10350
  };
10316
10351
  }
10317
10352
  getSubscriberCount() {
10318
10353
  return this.subscribers.size;
10319
10354
  }
10320
10355
  async publish(event) {
10321
- this.writer.write(JSON.stringify(event) + "\n");
10322
- for (const subscriber of this.subscribers.values()) {
10356
+ const seq = ++this.seq;
10357
+ const data = JSON.stringify({ ...event, seq });
10358
+ this.writer.write(data + "\n");
10359
+ const entry = { seq, frame: `id: ${this.epoch}:${seq}
10360
+ event: ${event.type}
10361
+ data: ${data}
10362
+
10363
+ `, partialKey: partialKey(event) };
10364
+ this.remember(entry);
10365
+ for (const subscriber of this.subscribers) {
10323
10366
  try {
10324
- subscriber(event);
10367
+ subscriber(entry.frame);
10325
10368
  } catch {
10326
10369
  }
10327
10370
  }
10328
10371
  }
10372
+ // A newer partial carries the whole message so far, so only the latest one per message is replayed.
10373
+ remember(entry) {
10374
+ if (entry.partialKey) {
10375
+ const superseded = this.latestPartials.get(entry.partialKey);
10376
+ if (superseded) {
10377
+ const index = this.replay.indexOf(superseded);
10378
+ if (index !== -1) {
10379
+ this.replay.splice(index, 1);
10380
+ this.replayChars -= superseded.frame.length;
10381
+ }
10382
+ }
10383
+ this.latestPartials.set(entry.partialKey, entry);
10384
+ }
10385
+ this.replay.push(entry);
10386
+ this.replayChars += entry.frame.length;
10387
+ while (this.replay.length > MAX_REPLAY_EVENTS || this.replayChars > MAX_REPLAY_CHARS && this.replay.length > 1) {
10388
+ const evicted = this.replay.shift();
10389
+ if (!evicted) break;
10390
+ this.replayChars -= evicted.frame.length;
10391
+ this.replayFloor = evicted.seq;
10392
+ if (evicted.partialKey && this.latestPartials.get(evicted.partialKey) === evicted) this.latestPartials.delete(evicted.partialKey);
10393
+ }
10394
+ }
10329
10395
  };
10330
10396
  var eventService = new EventService();
10331
10397
 
@@ -62100,7 +62166,7 @@ import { randomUUID as randomUUID11 } from "crypto";
62100
62166
  import { existsSync as existsSync17 } from "fs";
62101
62167
  import { spawn as spawn6 } from "node-pty";
62102
62168
  import { z as z3 } from "zod";
62103
- var MAX_REPLAY_CHARS = 1024 * 1024;
62169
+ var MAX_REPLAY_CHARS2 = 1024 * 1024;
62104
62170
  var MAX_TERMINAL_SESSIONS = 8;
62105
62171
  var MAX_PENDING_INPUT = 64;
62106
62172
  var terminalSizeSchema = z3.object({
@@ -62151,7 +62217,7 @@ var TerminalService = class {
62151
62217
  };
62152
62218
  this.sessions.set(id, session);
62153
62219
  pty.onData((data) => {
62154
- session.replay = (session.replay + data).slice(-MAX_REPLAY_CHARS);
62220
+ session.replay = (session.replay + data).slice(-MAX_REPLAY_CHARS2);
62155
62221
  for (const subscriber of session.subscribers) subscriber(data);
62156
62222
  });
62157
62223
  pty.onExit(({ exitCode }) => {
@@ -62160,7 +62226,7 @@ var TerminalService = class {
62160
62226
  const data = `\r
62161
62227
  \x1B[2m[Process exited with code ${exitCode}]\x1B[0m\r
62162
62228
  `;
62163
- session.replay = (session.replay + data).slice(-MAX_REPLAY_CHARS);
62229
+ session.replay = (session.replay + data).slice(-MAX_REPLAY_CHARS2);
62164
62230
  for (const subscriber of session.subscribers) subscriber(data);
62165
62231
  });
62166
62232
  return createSuccessResult(this.publicSession(session));
@@ -62331,8 +62397,9 @@ function createV1Routes(deps) {
62331
62397
  ), status);
62332
62398
  }
62333
62399
  };
62334
- app2.get("/events", async () => {
62400
+ app2.get("/events", async (c) => {
62335
62401
  const encoder2 = new TextEncoder();
62402
+ const lastEventId = c.req.header(ENGINE_STREAM_LAST_EVENT_ID_HEADER);
62336
62403
  let unsubscribe = null;
62337
62404
  let heartbeat = null;
62338
62405
  const cleanup = () => {
@@ -62356,20 +62423,10 @@ function createV1Routes(deps) {
62356
62423
  return false;
62357
62424
  }
62358
62425
  };
62359
- const writeEvent = (event) => {
62360
- if (!safeEnqueue(`id: ${event.id}
62361
- `)) return;
62362
- if (!safeEnqueue(`event: ${event.type}
62363
- `)) return;
62364
- safeEnqueue(`data: ${JSON.stringify(event)}
62365
-
62366
- `);
62367
- };
62368
- unsubscribe = eventService.subscribe(writeEvent);
62426
+ unsubscribe = eventService.subscribe(safeEnqueue, lastEventId);
62369
62427
  heartbeat = setInterval(() => {
62370
62428
  safeEnqueue(": ping\n\n");
62371
62429
  }, 15e3);
62372
- safeEnqueue(": connected\n\n");
62373
62430
  },
62374
62431
  cancel: () => {
62375
62432
  cleanup();
@@ -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-C2I3YQ5R.js";
6
+ } from "./chunk-K77ILXKH.js";
7
7
  import {
8
8
  isRecord
9
9
  } from "./chunk-UZSNFLDQ.js";
10
10
  import {
11
11
  shouldRefreshPullRequests
12
- } from "./chunk-SE6ENDPR.js";
12
+ } from "./chunk-OPV7WB6E.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-SE6ENDPR.js";
12
+ } from "./chunk-OPV7WB6E.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.1225",
3
+ "version": "0.1.1226",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",