replicas-engine 0.1.309 → 0.1.312

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 +53 -48
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -14,21 +14,6 @@ function isRecord(value) {
14
14
  return typeof value === "object" && value !== null && !Array.isArray(value);
15
15
  }
16
16
 
17
- // ../shared/src/result.ts
18
- function createSuccessResult(data) {
19
- return { ok: true, data };
20
- }
21
- function createErrorResult(error) {
22
- return {
23
- ok: false,
24
- error: {
25
- message: error.message,
26
- code: error.code,
27
- details: error.details
28
- }
29
- };
30
- }
31
-
32
17
  // ../shared/src/agent.ts
33
18
  var CODEX_REASONING_EFFORT_BY_THINKING_LEVEL = {
34
19
  low: "low",
@@ -302,7 +287,7 @@ var WORKSPACE_SIZES = ["small", "large"];
302
287
  var INVALID_WORKSPACE_SIZE_ERROR = `Invalid size: must be one of ${WORKSPACE_SIZES.join(", ")}`;
303
288
 
304
289
  // ../shared/src/e2b.ts
305
- var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-06-13-v5";
290
+ var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-06-13-v8";
306
291
 
307
292
  // ../shared/src/runtime-env.ts
308
293
  function parsePosixEnvFile(content) {
@@ -2925,6 +2910,32 @@ function upsertCredentialFileLines(filePath, hosts, lines) {
2925
2910
  credentialFileQueue = task.catch(() => void 0);
2926
2911
  return task;
2927
2912
  }
2913
+ function removeCredentialFileLines(filePath, shouldRemove) {
2914
+ const task = credentialFileQueue.then(async () => {
2915
+ let existing = [];
2916
+ try {
2917
+ existing = (await readFile(filePath, "utf-8")).split("\n").filter(Boolean);
2918
+ } catch {
2919
+ return;
2920
+ }
2921
+ const kept = existing.filter((line) => !shouldRemove(line));
2922
+ await writeSecureCredentialFile(filePath, [...kept, ""].join("\n"));
2923
+ });
2924
+ credentialFileQueue = task.catch(() => void 0);
2925
+ return task;
2926
+ }
2927
+
2928
+ // src/utils/git-identity.ts
2929
+ async function updateGitIdentity(identity, tag) {
2930
+ try {
2931
+ const [nameArgs, emailArgs] = gitIdentityConfigCommands(identity);
2932
+ await execFileAsync("git", nameArgs);
2933
+ await execFileAsync("git", emailArgs);
2934
+ console.log(`[${tag}] Updated git identity to ${identity.name} <${identity.email}>`);
2935
+ } catch (error) {
2936
+ console.error(`[${tag}] Failed to update git identity:`, error);
2937
+ }
2938
+ }
2928
2939
 
2929
2940
  // src/managers/github-token-manager.ts
2930
2941
  var GitHubTokenManager = class extends BaseRefreshManager {
@@ -2935,6 +2946,9 @@ var GitHubTokenManager = class extends BaseRefreshManager {
2935
2946
  console.log("[GitHubTokenManager] Refreshing GitHub token...");
2936
2947
  const response = await monolithRequest("/v1/engine/github/refresh-token");
2937
2948
  if (!response.ok) {
2949
+ if (response.status === 403) {
2950
+ await this.clearGitHubCredentials();
2951
+ }
2938
2952
  const errorText = await response.text();
2939
2953
  throw new Error(`Token refresh failed: ${response.status} ${errorText}`);
2940
2954
  }
@@ -2944,7 +2958,7 @@ var GitHubTokenManager = class extends BaseRefreshManager {
2944
2958
  await this.updateGitCredentials(ghToken);
2945
2959
  await this.updateGhHostsFile(ghToken, ghUsername);
2946
2960
  if (data.gitIdentity) {
2947
- await this.updateGitIdentity(data.gitIdentity);
2961
+ await updateGitIdentity(data.gitIdentity, "GitHubTokenManager");
2948
2962
  }
2949
2963
  if (data.userToken) {
2950
2964
  console.log(`[GitHubTokenManager] Token refreshed with user token for PR attribution, installation token expires at ${data.expiresAt}, user token expires at ${data.userToken.expiresAt}`);
@@ -2977,15 +2991,12 @@ var GitHubTokenManager = class extends BaseRefreshManager {
2977
2991
  console.error("[GitHubTokenManager] Failed to update gh hosts file:", error);
2978
2992
  }
2979
2993
  }
2980
- async updateGitIdentity(identity) {
2981
- try {
2982
- const [nameArgs, emailArgs] = gitIdentityConfigCommands(identity);
2983
- await execFileAsync("git", nameArgs);
2984
- await execFileAsync("git", emailArgs);
2985
- console.log(`[GitHubTokenManager] Updated git identity to ${identity.name} <${identity.email}>`);
2986
- } catch (error) {
2987
- console.error("[GitHubTokenManager] Failed to update git identity:", error);
2988
- }
2994
+ async clearGitHubCredentials() {
2995
+ const credentialsPath = path.join(ENGINE_ENV.HOME_DIR, ".git-credentials");
2996
+ await removeCredentialFileLines(
2997
+ credentialsPath,
2998
+ (line) => line.endsWith("@github.com")
2999
+ );
2989
3000
  }
2990
3001
  };
2991
3002
  var githubTokenManager = new GitHubTokenManager();
@@ -2997,12 +3008,16 @@ var GitLabTokenManager = class extends BaseRefreshManager {
2997
3008
  super("GitLabTokenManager");
2998
3009
  }
2999
3010
  async doRefresh(_config) {
3000
- const result = await this.fetchRefresh();
3001
- if (!result.ok) {
3002
- throw new Error(`Token refresh failed: ${result.error.message}`);
3011
+ const response = await monolithRequest("/v1/engine/gitlab/refresh-token");
3012
+ if (!response.ok) {
3013
+ if (response.status === 403) {
3014
+ await this.clearGitLabCredentials();
3015
+ }
3016
+ throw new Error(`Token refresh failed: ${response.status} ${await response.text()}`);
3003
3017
  }
3004
- const data = result.data;
3018
+ const data = await response.json();
3005
3019
  if (!data.token) {
3020
+ await this.clearGitLabCredentials(data.hosts);
3006
3021
  console.log(`[GitLabTokenManager] No GitLab token to install: ${data.reason}`);
3007
3022
  return;
3008
3023
  }
@@ -3015,25 +3030,15 @@ var GitLabTokenManager = class extends BaseRefreshManager {
3015
3030
  );
3016
3031
  console.log(`[GitLabTokenManager] Updated ${credentialsPath} for ${hosts.join(", ")}`);
3017
3032
  if (data.gitIdentity) {
3018
- await this.updateGitIdentity(data.gitIdentity);
3033
+ await updateGitIdentity(data.gitIdentity, "GitLabTokenManager");
3019
3034
  }
3020
3035
  }
3021
- async fetchRefresh() {
3022
- const response = await monolithRequest("/v1/engine/gitlab/refresh-token");
3023
- if (!response.ok) {
3024
- return createErrorResult({ message: `${response.status} ${await response.text()}` });
3025
- }
3026
- return createSuccessResult(await response.json());
3027
- }
3028
- async updateGitIdentity(identity) {
3029
- try {
3030
- const [nameArgs, emailArgs] = gitIdentityConfigCommands(identity);
3031
- await execFileAsync("git", nameArgs);
3032
- await execFileAsync("git", emailArgs);
3033
- console.log(`[GitLabTokenManager] Updated git identity to ${identity.name} <${identity.email}>`);
3034
- } catch (error) {
3035
- console.error("[GitLabTokenManager] Failed to update git identity:", error);
3036
- }
3036
+ async clearGitLabCredentials(hosts = []) {
3037
+ const credentialsPath = path2.join(ENGINE_ENV.HOME_DIR, ".git-credentials");
3038
+ await removeCredentialFileLines(
3039
+ credentialsPath,
3040
+ (line) => line.startsWith("https://oauth2:") && (hosts.length === 0 || hosts.some((host) => line.endsWith(`@${host}`)))
3041
+ );
3037
3042
  }
3038
3043
  };
3039
3044
  var gitlabTokenManager = new GitLabTokenManager();
@@ -6846,7 +6851,7 @@ var AspClient = class {
6846
6851
  // src/managers/codex-asp/app-server-process.ts
6847
6852
  var DEFAULT_CODEX_BINARY = "codex";
6848
6853
  var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
6849
- var ENGINE_PACKAGE_VERSION = "0.1.309";
6854
+ var ENGINE_PACKAGE_VERSION = "0.1.312";
6850
6855
  var INITIALIZE_METHOD = "initialize";
6851
6856
  var INITIALIZED_NOTIFICATION = "initialized";
6852
6857
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.309",
3
+ "version": "0.1.312",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",