replicas-engine 0.1.1183 → 0.1.1185

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.
package/README.md CHANGED
@@ -103,9 +103,7 @@ Token refresh managers may later overwrite credential files in place:
103
103
 
104
104
  Engine persistence locations:
105
105
 
106
- - `~/.replicas/engine/chats.json`
107
- - `~/.replicas/engine/events.jsonl`
108
- - `~/.replicas/engine-state.json`
106
+ - `/var/lib/replicas/engine/` (`REPLICAS_ENGINE_STATE_DIR` overrides `/var/lib/replicas`): `chats.json`, `events.jsonl`, `engine-state.json`, and chat histories
109
107
  - `~/.replicas/startHooks.log`
110
108
  - Canvas read locations (for `/canvas` endpoints):
111
109
  - `~/.claude/plans` (where Claude Code writes its plans)
@@ -8,12 +8,12 @@ import {
8
8
  listRunningCodexModels,
9
9
  restartCodexAspHost,
10
10
  restartCodexAspHostIfRunning
11
- } from "./chunk-6TR2W5B3.js";
12
- import "./chunk-OKE4RCRY.js";
13
- import "./chunk-RB33U66A.js";
14
- import "./chunk-2AG3DWDX.js";
11
+ } from "./chunk-4ZGWVW57.js";
12
+ import "./chunk-5LUEYBGK.js";
13
+ import "./chunk-BWK6AIHV.js";
14
+ import "./chunk-DK47O5WV.js";
15
15
  import "./chunk-UZSNFLDQ.js";
16
- import "./chunk-AGNQDFJU.js";
16
+ import "./chunk-MRLYA3JT.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-OKE4RCRY.js";
8
+ } from "./chunk-5LUEYBGK.js";
9
9
  import {
10
10
  extractCommandProtectionCommandText,
11
11
  findCommandProtectionGitLookups,
12
12
  findGitCommitSignals,
13
13
  findPrMergeSignals,
14
14
  parseCommandProtectionRequest
15
- } from "./chunk-AGNQDFJU.js";
15
+ } from "./chunk-MRLYA3JT.js";
16
16
 
17
17
  // src/services/command-protection-service.ts
18
18
  import { readFile, stat } from "fs/promises";
@@ -10,15 +10,15 @@ import {
10
10
  resolveDiffBase,
11
11
  runGitCommand,
12
12
  setAgentCredentialSnapshot
13
- } from "./chunk-OKE4RCRY.js";
13
+ } from "./chunk-5LUEYBGK.js";
14
14
  import {
15
15
  AppServerProcess,
16
16
  buildCodexAgentEnv
17
- } from "./chunk-RB33U66A.js";
17
+ } from "./chunk-BWK6AIHV.js";
18
18
  import {
19
19
  SUBPROCESS_MAX_BUFFER,
20
20
  execFileAsync
21
- } from "./chunk-2AG3DWDX.js";
21
+ } from "./chunk-DK47O5WV.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-AGNQDFJU.js";
58
+ } from "./chunk-MRLYA3JT.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-Y5PB7ROJ.js");
294
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-ZLG2O2IB.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-Y5PB7ROJ.js");
316
+ const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-ZLG2O2IB.js");
317
317
  await restartCodexAspHostIfRunning2();
318
318
  }
319
319
  setAgentCredentialSnapshot("codex", data);
@@ -430,18 +430,37 @@ import { existsSync as existsSync3, readFileSync } from "fs";
430
430
  // src/git/service.ts
431
431
  import { readdir, readFile as readFile3, stat } from "fs/promises";
432
432
  import { spawn } from "child_process";
433
- import { isAbsolute, join as join3 } from "path";
433
+ import { isAbsolute, join as join4 } from "path";
434
434
 
435
435
  // src/utils/state.ts
436
436
  import { readFile as readFile2, mkdir as mkdir2 } from "fs/promises";
437
437
  import { existsSync } from "fs";
438
- import { join as join2 } from "path";
439
- import { homedir } from "os";
438
+ import { join as join3 } from "path";
439
+
440
+ // src/services/chat/history-paths.ts
441
+ import { join } from "path";
442
+ var ENGINE_DIR = join(process.env.REPLICAS_ENGINE_STATE_DIR ?? "/var/lib/replicas", "engine");
443
+ var CHATS_FILE = join(ENGINE_DIR, "chats.json");
444
+ var CLAUDE_HISTORY_DIR = join(ENGINE_DIR, "claude-histories");
445
+ var CODEX_HISTORY_DIR = join(ENGINE_DIR, "codex-histories");
446
+ var CURSOR_HISTORY_DIR = join(ENGINE_DIR, "cursor-histories");
447
+ var OPENCODE_HISTORY_DIR = join(ENGINE_DIR, "opencode-histories");
448
+ var PI_HISTORY_DIR = join(ENGINE_DIR, "pi-histories");
449
+ var MUSE_HISTORY_DIR = join(ENGINE_DIR, "muse-histories");
450
+ var FORKS_DIR = join(ENGINE_DIR, "forks");
451
+ var HISTORY_DIR_BY_PROVIDER = {
452
+ claude: CLAUDE_HISTORY_DIR,
453
+ codex: CODEX_HISTORY_DIR,
454
+ cursor: CURSOR_HISTORY_DIR,
455
+ muse: MUSE_HISTORY_DIR,
456
+ opencode: OPENCODE_HISTORY_DIR,
457
+ pi: PI_HISTORY_DIR
458
+ };
440
459
 
441
460
  // src/utils/file.ts
442
461
  import { randomUUID } from "crypto";
443
462
  import { mkdir, readFile, rename, unlink, writeFile } from "fs/promises";
444
- import { dirname, join } from "path";
463
+ import { dirname, join as join2 } from "path";
445
464
 
446
465
  // src/utils/async-lock.ts
447
466
  var AsyncLock = class {
@@ -474,8 +493,8 @@ async function writeSecureCredentialFile(filePath, content, options) {
474
493
  await atomicWriteFile(filePath, content, { mode: 384 });
475
494
  }
476
495
  async function configureManagedGitCredentialHelper(homeDir) {
477
- const credentialsPath = join(homeDir, ".git-credentials");
478
- const helperPath = join(homeDir, GIT_CREDENTIAL_HELPER_FILENAME);
496
+ const credentialsPath = join2(homeDir, ".git-credentials");
497
+ const helperPath = join2(homeDir, GIT_CREDENTIAL_HELPER_FILENAME);
479
498
  await atomicWriteFile(helperPath, buildGitCredentialHelperScript(credentialsPath), { mode: 448 });
480
499
  await execFileAsync("git", ["config", "--global", "credential.helper", helperPath], {
481
500
  env: { ...process.env, HOME: homeDir }
@@ -511,8 +530,7 @@ function removeCredentialFileLines(filePath, shouldRemove) {
511
530
  }
512
531
 
513
532
  // src/utils/state.ts
514
- var STATE_DIR = join2(homedir(), ".replicas");
515
- var STATE_FILE = join2(STATE_DIR, "engine-state.json");
533
+ var STATE_FILE = join3(ENGINE_DIR, "engine-state.json");
516
534
  var DEFAULT_STATE = {
517
535
  repos: {},
518
536
  removedRepos: {}
@@ -520,7 +538,7 @@ var DEFAULT_STATE = {
520
538
  var stateWriteLock = new AsyncLock();
521
539
  async function updateEngineState(updater) {
522
540
  return stateWriteLock.run(async () => {
523
- await mkdir2(STATE_DIR, { recursive: true });
541
+ await mkdir2(ENGINE_DIR, { recursive: true });
524
542
  const currentState = await loadEngineState();
525
543
  const nextState = updater(currentState);
526
544
  await atomicWriteFile(STATE_FILE, JSON.stringify(nextState, null, 2));
@@ -659,13 +677,13 @@ var GitService = class {
659
677
  const repos = [];
660
678
  let complete = true;
661
679
  for (const entry of entries) {
662
- const fullPath = join3(root, entry);
680
+ const fullPath = join4(root, entry);
663
681
  try {
664
682
  const entryStat = await stat(fullPath);
665
683
  if (!entryStat.isDirectory()) {
666
684
  continue;
667
685
  }
668
- const hasGit = Boolean(await this.safeStat(join3(fullPath, ".git")));
686
+ const hasGit = Boolean(await this.safeStat(join4(fullPath, ".git")));
669
687
  if (!hasGit) {
670
688
  continue;
671
689
  }
@@ -686,8 +704,8 @@ var GitService = class {
686
704
  const removed = new Map(Object.entries(state.removedRepos));
687
705
  for (const repo of Object.values(state.repos)) {
688
706
  if (!isAbsolute(repo.name)) continue;
689
- const exists = Boolean(await this.safeStat(join3(repo.path, ".git")));
690
- const origin = exists ? (await readFile3(join3(repo.path, ".git", "config"), "utf-8").catch(() => "")).match(/\[remote "origin"\][^[]*?\burl\s*=\s*(\S+)/)?.[1] ?? null : null;
707
+ const exists = Boolean(await this.safeStat(join4(repo.path, ".git")));
708
+ const origin = exists ? (await readFile3(join4(repo.path, ".git", "config"), "utf-8").catch(() => "")).match(/\[remote "origin"\][^[]*?\burl\s*=\s*(\S+)/)?.[1] ?? null : null;
691
709
  const known = this.trackedCloneOrigins.has(repo.path) ? this.trackedCloneOrigins.get(repo.path) : origin;
692
710
  if (exists && origin === known) {
693
711
  this.trackedCloneOrigins.set(repo.path, origin);
@@ -711,7 +729,7 @@ var GitService = class {
711
729
  const commonDir = await runGitCommand(["rev-parse", "--path-format=absolute", "--git-common-dir"], worktree).catch(() => null);
712
730
  if (!commonDir) return false;
713
731
  const { repos } = await this.listTrackedRepositories();
714
- if (repos.some((repo) => repo.path === worktree || join3(repo.path, ".git") === commonDir)) return false;
732
+ if (repos.some((repo) => repo.path === worktree || join4(repo.path, ".git") === commonDir)) return false;
715
733
  const defaultBranch = await this.resolveDefaultBranch(worktree);
716
734
  await saveRepoState(worktree, {}, {
717
735
  name: worktree,
@@ -855,7 +873,7 @@ var GitService = class {
855
873
  for (let i = 0; i < paths.length; i += UNTRACKED_STAT_CONCURRENCY) {
856
874
  const batch = await Promise.all(paths.slice(i, i + UNTRACKED_STAT_CONCURRENCY).map(async (path2) => {
857
875
  try {
858
- return { path: path2, size: (await stat(join3(repoPath, path2))).size };
876
+ return { path: path2, size: (await stat(join4(repoPath, path2))).size };
859
877
  } catch {
860
878
  return null;
861
879
  }
@@ -935,7 +953,7 @@ Binary files /dev/null and ${quote(`b/${path2}`)} differ
935
953
  for (const { path: path2, tooLarge } of files) {
936
954
  if (tooLarge) continue;
937
955
  try {
938
- const contents = await readFile3(join3(repoPath, path2));
956
+ const contents = await readFile3(join4(repoPath, path2));
939
957
  if (contents.length === 0 || contents.includes(0)) {
940
958
  continue;
941
959
  }
@@ -1123,7 +1141,7 @@ Binary files /dev/null and ${quote(`b/${path2}`)} differ
1123
1141
  }
1124
1142
  async getGitLabAccessToken(host) {
1125
1143
  try {
1126
- const credentials = await readFile3(join3(ENGINE_ENV.HOME_DIR, ".git-credentials"), "utf-8");
1144
+ const credentials = await readFile3(join4(ENGINE_ENV.HOME_DIR, ".git-credentials"), "utf-8");
1127
1145
  for (const line of credentials.split("\n")) {
1128
1146
  const trimmed = line.trim();
1129
1147
  if (!trimmed) continue;
@@ -1202,8 +1220,8 @@ async function getAgentAdditionalDirectories() {
1202
1220
  // src/utils/image-utils.ts
1203
1221
  import { randomUUID as randomUUID2 } from "crypto";
1204
1222
  import { mkdir as mkdir3, unlink as unlink2, writeFile as writeFile2 } from "fs/promises";
1205
- import { homedir as homedir2 } from "os";
1206
- import { join as join4 } from "path";
1223
+ import { homedir } from "os";
1224
+ import { join as join5 } from "path";
1207
1225
  function isImageMediaType(value) {
1208
1226
  return IMAGE_MEDIA_TYPES.includes(value);
1209
1227
  }
@@ -1268,14 +1286,14 @@ async function normalizeImages(images) {
1268
1286
  }
1269
1287
  return normalized;
1270
1288
  }
1271
- async function saveNormalizedImagesToTempFiles(images, tempImageDir = join4(homedir2(), ".replicas", "codex", "temp-images")) {
1289
+ async function saveNormalizedImagesToTempFiles(images, tempImageDir = join5(homedir(), ".replicas", "codex", "temp-images")) {
1272
1290
  await mkdir3(tempImageDir, { recursive: true });
1273
1291
  const tempPaths = [];
1274
1292
  try {
1275
1293
  for (const image of images) {
1276
1294
  const ext = image.source.media_type.split("/")[1] || "png";
1277
1295
  const filename = `img_${randomUUID2()}.${ext}`;
1278
- const filepath = join4(tempImageDir, filename);
1296
+ const filepath = join5(tempImageDir, filename);
1279
1297
  await writeFile2(filepath, Buffer.from(image.source.data, "base64"));
1280
1298
  tempPaths.push(filepath);
1281
1299
  }
@@ -1352,14 +1370,14 @@ var CodexQuotaStatusTracker = class {
1352
1370
 
1353
1371
  // src/managers/subagent-mcp-config.ts
1354
1372
  import { existsSync as existsSync2 } from "fs";
1355
- import { dirname as dirname2, join as join5 } from "path";
1373
+ import { dirname as dirname2, join as join6 } from "path";
1356
1374
  import { fileURLToPath } from "url";
1357
1375
  import { createRequire } from "module";
1358
1376
  var SUBAGENT_MCP_TOOL_TIMEOUT_MS = 24 * 60 * 60 * 1e3 + 6e4;
1359
1377
  function subagentMcpProcessConfig(parentChatId) {
1360
1378
  const directory = dirname2(fileURLToPath(import.meta.url));
1361
- const builtEntry = join5(directory, "subagent-mcp.js");
1362
- const sourceEntry = join5(directory, "..", "subagent-mcp.ts");
1379
+ const builtEntry = join6(directory, "subagent-mcp.js");
1380
+ const sourceEntry = join6(directory, "..", "subagent-mcp.ts");
1363
1381
  const entry = existsSync2(builtEntry) ? builtEntry : sourceEntry;
1364
1382
  return {
1365
1383
  command: process.execPath,
@@ -1845,9 +1863,9 @@ async function buildTurnStartParams(threadId, request, serviceTier) {
1845
1863
  // src/managers/codex-asp/openai-compatible-model-catalog.ts
1846
1864
  import { writeFile as writeFile3 } from "fs/promises";
1847
1865
  import { tmpdir } from "os";
1848
- import { join as join6 } from "path";
1866
+ import { join as join7 } from "path";
1849
1867
  var CATALOG_TTL_MS = 6e4;
1850
- var CODEX_MODEL_CATALOG_PATH = join6(tmpdir(), "replicas-openai-compatible-model-catalog.json");
1868
+ var CODEX_MODEL_CATALOG_PATH = join7(tmpdir(), "replicas-openai-compatible-model-catalog.json");
1851
1869
  var cachedCatalog = null;
1852
1870
  async function writeCodexModelCatalog(modelsUrl) {
1853
1871
  const ollama = ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD === "ollama" ? readOllamaAuthEnv("codex", process.env) : null;
@@ -2003,6 +2021,15 @@ export {
2003
2021
  configureManagedGitCredentialHelper,
2004
2022
  upsertCredentialFileLines,
2005
2023
  removeCredentialFileLines,
2024
+ ENGINE_DIR,
2025
+ CHATS_FILE,
2026
+ CLAUDE_HISTORY_DIR,
2027
+ CODEX_HISTORY_DIR,
2028
+ CURSOR_HISTORY_DIR,
2029
+ OPENCODE_HISTORY_DIR,
2030
+ PI_HISTORY_DIR,
2031
+ FORKS_DIR,
2032
+ HISTORY_DIR_BY_PROVIDER,
2006
2033
  loadRepoState,
2007
2034
  saveRepoState,
2008
2035
  gitService,
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  SUBPROCESS_MAX_BUFFER,
6
6
  execFileAsync
7
- } from "./chunk-2AG3DWDX.js";
7
+ } from "./chunk-DK47O5WV.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-AGNQDFJU.js";
21
+ } from "./chunk-MRLYA3JT.js";
22
22
 
23
23
  // src/runtime-env-loader.ts
24
24
  import { readFileSync } from "fs";
@@ -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-2AG3DWDX.js";
6
+ } from "./chunk-DK47O5WV.js";
7
7
  import {
8
8
  isVersionBelow
9
- } from "./chunk-AGNQDFJU.js";
9
+ } from "./chunk-MRLYA3JT.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.1183";
243
+ var ENGINE_PACKAGE_VERSION = "0.1.1185";
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
  HOOK_EXEC_MAX_BUFFER_BYTES
6
- } from "./chunk-AGNQDFJU.js";
6
+ } from "./chunk-MRLYA3JT.js";
7
7
 
8
8
  // src/utils/exec.ts
9
9
  import { exec, execFile } from "child_process";
@@ -5,7 +5,7 @@ import {
5
5
  extractCommandProtectionCommandText,
6
6
  isRecord,
7
7
  parseCodeHostPrUrl
8
- } from "./chunk-AGNQDFJU.js";
8
+ } from "./chunk-MRLYA3JT.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-RB33U66A.js";
6
+ } from "./chunk-BWK6AIHV.js";
7
7
  import {
8
8
  ASTER_BASE_URL,
9
9
  ASTER_PROVIDER,
@@ -11,7 +11,7 @@ import {
11
11
  codexReasoningEffortForThinkingLevel,
12
12
  isRecord,
13
13
  readOllamaAuthEnv
14
- } from "./chunk-AGNQDFJU.js";
14
+ } from "./chunk-MRLYA3JT.js";
15
15
 
16
16
  // src/managers/codex-asp/notification-dispatch.ts
17
17
  var TURN_STARTED_METHOD = "turn/started";