replicas-engine 0.1.244 → 0.1.246

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.
Files changed (2) hide show
  1. package/dist/src/index.js +77 -16
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -285,11 +285,19 @@ var SANDBOX_LIFECYCLE = {
285
285
  AUTO_DELETE_MINUTES: -1,
286
286
  SSH_TOKEN_EXPIRATION_MINUTES: 3 * 60
287
287
  };
288
+ var SANDBOX_PATHS = {
289
+ HOME_DIR: "/home/user",
290
+ WORKSPACES_DIR: "/home/user/workspaces",
291
+ REPLICAS_DIR: "/home/user/.replicas",
292
+ REPLICAS_FILES_DIR: "/home/user/.replicas/files",
293
+ REPOS_PREPARED_MARKER: "/home/user/.replicas/repos-prepared-for-engine-init",
294
+ REPLICAS_RUNTIME_ENV_FILE: "/home/user/.replicas/runtime-env.sh"
295
+ };
288
296
  var WORKSPACE_SIZES = ["small", "large"];
289
297
  var INVALID_WORKSPACE_SIZE_ERROR = `Invalid size: must be one of ${WORKSPACE_SIZES.join(", ")}`;
290
298
 
291
299
  // ../shared/src/e2b.ts
292
- var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-05-30-v5";
300
+ var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-05-30-v7";
293
301
 
294
302
  // ../shared/src/runtime-env.ts
295
303
  function parsePosixEnvFile(content) {
@@ -1823,6 +1831,18 @@ function normalizeCodexAspTranscriptStatus(status, failed = false) {
1823
1831
  if (status === "completed") return "completed";
1824
1832
  return "in_progress";
1825
1833
  }
1834
+ function imageContentToUserMessageImages(images) {
1835
+ const userImages = [];
1836
+ for (const image of images ?? []) {
1837
+ if (image.source.type !== "base64" || image.source.data.length === 0) continue;
1838
+ userImages.push({
1839
+ type: "image",
1840
+ mediaType: image.source.media_type,
1841
+ data: image.source.data
1842
+ });
1843
+ }
1844
+ return userImages.length > 0 ? userImages : void 0;
1845
+ }
1826
1846
  function isCodexAspTranscript(value) {
1827
1847
  if (!isRecord(value)) return false;
1828
1848
  return typeof value.threadId === "string" && typeof value.updatedAt === "string" && Array.isArray(value.turns);
@@ -2625,7 +2645,7 @@ var codexTokenManager = new CodexTokenManager();
2625
2645
 
2626
2646
  // src/git/service.ts
2627
2647
  import { readdir, stat } from "fs/promises";
2628
- import { existsSync as existsSync2 } from "fs";
2648
+ import { existsSync as existsSync2, unlinkSync } from "fs";
2629
2649
  import { execFileSync as execFileSync2, spawnSync } from "child_process";
2630
2650
  import { join as join5 } from "path";
2631
2651
 
@@ -2907,6 +2927,7 @@ var GitService = class {
2907
2927
  };
2908
2928
  }
2909
2929
  const repos = await this.listRepositories();
2930
+ const skipNetworkRefresh = this.consumeReposPreparedMarker();
2910
2931
  if (repos.length === 0) {
2911
2932
  return {
2912
2933
  success: true,
@@ -2931,7 +2952,9 @@ var GitService = class {
2931
2952
  };
2932
2953
  const persistedState = await loadRepoState(repo.name);
2933
2954
  const persistedBranch = persistedState?.currentBranch;
2934
- runGitCommand(["fetch", "--all", "--prune", `--filter=${GIT_PARTIAL_CLONE_FILTER}`], repo.path);
2955
+ if (!skipNetworkRefresh) {
2956
+ runGitCommand(["fetch", "--all", "--prune", `--filter=${GIT_PARTIAL_CLONE_FILTER}`], repo.path);
2957
+ }
2935
2958
  if (persistedBranch && branchExists(persistedBranch, repo.path)) {
2936
2959
  const currentBranch = getCurrentBranch(repo.path);
2937
2960
  if (currentBranch !== persistedBranch) {
@@ -2946,9 +2969,11 @@ var GitService = class {
2946
2969
  continue;
2947
2970
  }
2948
2971
  runGitCommand(["checkout", repo.defaultBranch], repo.path);
2949
- try {
2950
- runGitCommand(["pull", "--rebase", "--autostash"], repo.path);
2951
- } catch {
2972
+ if (!skipNetworkRefresh) {
2973
+ try {
2974
+ runGitCommand(["pull", "--rebase", "--autostash"], repo.path);
2975
+ } catch {
2976
+ }
2952
2977
  }
2953
2978
  const branchName = this.findAvailableBranchName(workspaceName, repo.path);
2954
2979
  runGitCommand(["checkout", "-b", branchName], repo.path);
@@ -2976,6 +3001,18 @@ var GitService = class {
2976
3001
  error: failed.length > 0 ? `Git init failed for ${failed.length} repo(s)` : void 0
2977
3002
  };
2978
3003
  }
3004
+ consumeReposPreparedMarker() {
3005
+ const markerPath = SANDBOX_PATHS.REPOS_PREPARED_MARKER;
3006
+ if (!existsSync2(markerPath)) {
3007
+ return false;
3008
+ }
3009
+ try {
3010
+ unlinkSync(markerPath);
3011
+ } catch {
3012
+ return false;
3013
+ }
3014
+ return true;
3015
+ }
2979
3016
  getGitDiffStats(repoPath, defaultBranch) {
2980
3017
  try {
2981
3018
  const diffBase = this.getDiffBase(repoPath, defaultBranch);
@@ -4118,7 +4155,7 @@ async function registerDesktopPreview() {
4118
4155
  }
4119
4156
 
4120
4157
  // src/services/chat/chat-service.ts
4121
- import { existsSync as existsSync7 } from "fs";
4158
+ import { existsSync as existsSync8 } from "fs";
4122
4159
  import { appendFile as appendFile5, copyFile, mkdir as mkdir11, readFile as readFile8, rename as rename2, rm } from "fs/promises";
4123
4160
  import { homedir as homedir13 } from "os";
4124
4161
  import { join as join15 } from "path";
@@ -6102,7 +6139,7 @@ var AspClient = class {
6102
6139
  // src/managers/codex-asp/app-server-process.ts
6103
6140
  var DEFAULT_CODEX_BINARY = "codex";
6104
6141
  var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
6105
- var ENGINE_PACKAGE_VERSION = "0.1.244";
6142
+ var ENGINE_PACKAGE_VERSION = "0.1.246";
6106
6143
  var INITIALIZE_METHOD = "initialize";
6107
6144
  var INITIALIZED_NOTIFICATION = "initialized";
6108
6145
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -6369,6 +6406,8 @@ function isCodexAuthError(error) {
6369
6406
  }
6370
6407
 
6371
6408
  // src/managers/codex-asp/mappers.ts
6409
+ import { existsSync as existsSync6, readFileSync as readFileSync3 } from "fs";
6410
+ var localImageCache = /* @__PURE__ */ new Map();
6372
6411
  var DEFAULT_MODEL = DEFAULT_CODEX_MODEL;
6373
6412
  var THREAD_START_METHOD = "thread/start";
6374
6413
  var THREAD_RESUME_METHOD = "thread/resume";
@@ -6441,6 +6480,22 @@ function transcriptItemsForTurn(turn) {
6441
6480
  const otherItems = turn.items.filter((item) => item.type !== "userMessage");
6442
6481
  return [...userItems, ...otherItems];
6443
6482
  }
6483
+ function userImageForLocalPath(path4) {
6484
+ const cached = localImageCache.get(path4);
6485
+ if (cached) return cached;
6486
+ if (!existsSync6(path4)) return null;
6487
+ const image = {
6488
+ type: "image",
6489
+ mediaType: inferMediaType(path4),
6490
+ data: readFileSync3(path4).toString("base64")
6491
+ };
6492
+ if (image.data.length > 0) localImageCache.set(path4, image);
6493
+ return image;
6494
+ }
6495
+ function userImagesForInput(input) {
6496
+ const images = input.filter((item) => item.type === "localImage").map((item) => userImageForLocalPath(item.path)).filter((image) => image !== null && image.data.length > 0);
6497
+ return images.length > 0 ? images : void 0;
6498
+ }
6444
6499
  function itemToTranscriptItem(item, timestamp, status) {
6445
6500
  if (item.type === "userMessage") {
6446
6501
  const content = item.content.filter((input) => input.type === "text").map((input) => input.text).join("\n");
@@ -6448,6 +6503,7 @@ function itemToTranscriptItem(item, timestamp, status) {
6448
6503
  type: "userMessage",
6449
6504
  id: item.id,
6450
6505
  content,
6506
+ images: userImagesForInput(item.content),
6451
6507
  timestamp
6452
6508
  };
6453
6509
  }
@@ -6707,6 +6763,7 @@ function mergeCodexAspTranscriptItem(current, candidate) {
6707
6763
  ...current,
6708
6764
  ...candidate,
6709
6765
  id: current.id,
6766
+ ...current.type === "userMessage" && candidate.type === "userMessage" && !candidate.images && current.images ? { images: current.images } : {},
6710
6767
  timestamp: current.timestamp,
6711
6768
  sequence: current.sequence ?? candidate.sequence
6712
6769
  };
@@ -7002,9 +7059,11 @@ var CodexAspManager = class extends CodingAgentManager {
7002
7059
  const recordUserMessage = (extraPayload = {}) => {
7003
7060
  if (userMessageRecorded) return;
7004
7061
  userMessageRecorded = true;
7062
+ const images = imageContentToUserMessageImages(request.images);
7005
7063
  this.recordHistoryEvent("event_msg", {
7006
7064
  type: "user_message",
7007
7065
  message: request.message,
7066
+ ...images ? { images } : {},
7008
7067
  ...extraPayload
7009
7068
  });
7010
7069
  };
@@ -7615,7 +7674,7 @@ var CodexAspManager = class extends CodingAgentManager {
7615
7674
  // src/managers/codex-manager.ts
7616
7675
  import { Codex } from "@openai/codex-sdk";
7617
7676
  import { readdir as readdir3, stat as stat2, writeFile as writeFile6, mkdir as mkdir10, readFile as readFile7 } from "fs/promises";
7618
- import { existsSync as existsSync6 } from "fs";
7677
+ import { existsSync as existsSync7 } from "fs";
7619
7678
  import { join as join14 } from "path";
7620
7679
  import { homedir as homedir12 } from "os";
7621
7680
  import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
@@ -7700,7 +7759,7 @@ var CodexManager = class extends CodingAgentManager {
7700
7759
  const codexDir = join14(homedir12(), ".codex");
7701
7760
  await mkdir10(codexDir, { recursive: true });
7702
7761
  let config = {};
7703
- if (existsSync6(CODEX_CONFIG_PATH)) {
7762
+ if (existsSync7(CODEX_CONFIG_PATH)) {
7704
7763
  try {
7705
7764
  const existingContent = await readFile7(CODEX_CONFIG_PATH, "utf-8");
7706
7765
  const parsed = parseToml(existingContent);
@@ -8629,7 +8688,7 @@ function isChatMessageSender(value) {
8629
8688
  return typeof value.senderUserId === "string" && typeof value.senderEmail === "string" && typeof value.recordedAt === "string";
8630
8689
  }
8631
8690
  function isCodexAvailable() {
8632
- return existsSync7(CODEX_AUTH_PATH2) || Boolean(ENGINE_ENV.OPENAI_API_KEY);
8691
+ return existsSync8(CODEX_AUTH_PATH2) || Boolean(ENGINE_ENV.OPENAI_API_KEY);
8633
8692
  }
8634
8693
  function isSameAcceptedUserEvent(event, acceptedEvent) {
8635
8694
  if (areSameUserMessageEvents(event, acceptedEvent)) return true;
@@ -8688,7 +8747,8 @@ function parsePersistedChatsContent(content) {
8688
8747
  function corruptChatsFilePath() {
8689
8748
  return `${CHATS_FILE}.corrupt-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}`;
8690
8749
  }
8691
- function createUserMessageEvent(message, messageId) {
8750
+ function createUserMessageEvent(message, messageId, images) {
8751
+ const eventImages = imageContentToUserMessageImages(images);
8692
8752
  return {
8693
8753
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
8694
8754
  type: "event_msg",
@@ -8696,7 +8756,8 @@ function createUserMessageEvent(message, messageId) {
8696
8756
  type: "user_message",
8697
8757
  message,
8698
8758
  source: ACCEPTED_USER_MESSAGE_SOURCE,
8699
- [USER_MESSAGE_ID_PAYLOAD_KEY]: messageId
8759
+ [USER_MESSAGE_ID_PAYLOAD_KEY]: messageId,
8760
+ ...eventImages ? { images: eventImages } : {}
8700
8761
  }
8701
8762
  };
8702
8763
  }
@@ -8778,7 +8839,7 @@ var ChatService = class {
8778
8839
  async sendMessage(chatId, request) {
8779
8840
  const chat = this.requireChat(chatId);
8780
8841
  const result = await chat.provider.enqueueMessage(request);
8781
- const acceptedEvent = createUserMessageEvent(request.message, result.messageId);
8842
+ const acceptedEvent = createUserMessageEvent(request.message, result.messageId, request.images);
8782
8843
  chat.pendingMessageIds.push(result.messageId);
8783
8844
  chat.acceptedUserEvents.set(result.messageId, acceptedEvent);
8784
8845
  this.touch(chat);
@@ -9598,7 +9659,7 @@ var planService = new PlanService();
9598
9659
  // src/services/warm-hooks-service.ts
9599
9660
  import { spawn as spawn3 } from "child_process";
9600
9661
  import { readFile as readFile12 } from "fs/promises";
9601
- import { existsSync as existsSync8 } from "fs";
9662
+ import { existsSync as existsSync9 } from "fs";
9602
9663
  import { join as join19 } from "path";
9603
9664
 
9604
9665
  // src/services/warm-hook-logs-service.ts
@@ -9720,7 +9781,7 @@ var warmHookLogsService = new WarmHookLogsService();
9720
9781
  async function readRepoWarmHook(repoPath) {
9721
9782
  for (const filename of REPLICAS_CONFIG_FILENAMES) {
9722
9783
  const configPath = join19(repoPath, filename);
9723
- if (!existsSync8(configPath)) {
9784
+ if (!existsSync9(configPath)) {
9724
9785
  continue;
9725
9786
  }
9726
9787
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.244",
3
+ "version": "0.1.246",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",