replicas-engine 0.1.507 → 0.1.509

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 +83 -2
  2. package/package.json +1 -1
package/dist/src/index.js CHANGED
@@ -611,7 +611,7 @@ var WORKSPACE_SIZES = ["small", "large"];
611
611
  var INVALID_WORKSPACE_SIZE_ERROR = `Invalid size: must be one of ${WORKSPACE_SIZES.join(", ")}`;
612
612
 
613
613
  // ../shared/src/e2b.ts
614
- var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-07-25-v9";
614
+ var E2B_TEMPLATE_NAME = "replicas-sandbox-2026-07-26-v2";
615
615
 
616
616
  // ../shared/src/runtime-env.ts
617
617
  function shellQuotePosix(value) {
@@ -727,6 +727,53 @@ function isGitHubUrl(url) {
727
727
  }
728
728
 
729
729
  // ../shared/src/urls.ts
730
+ var PR_URL_REGEX = /github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)/;
731
+ function parsePrUrl(url) {
732
+ const match = url.match(PR_URL_REGEX);
733
+ if (!match) return null;
734
+ const [, owner, repo, numberStr] = match;
735
+ const number = Number.parseInt(numberStr, 10);
736
+ if (!Number.isFinite(number)) return null;
737
+ return { owner, repo, number };
738
+ }
739
+ function parseCodeHostPrUrl(url) {
740
+ const github = parsePrUrl(url);
741
+ if (github) {
742
+ return {
743
+ ...github,
744
+ provider: "github",
745
+ host: "github.com",
746
+ repositoryPath: `${github.owner}/${github.repo}`,
747
+ repoUrl: `https://github.com/${github.owner}/${github.repo}`
748
+ };
749
+ }
750
+ let parsed;
751
+ try {
752
+ parsed = new URL(url);
753
+ } catch {
754
+ return null;
755
+ }
756
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
757
+ const segments = parsed.pathname.split("/").filter(Boolean);
758
+ const separatorIndex = segments.indexOf("-");
759
+ if (separatorIndex <= 0 || segments[separatorIndex + 1] !== "merge_requests") return null;
760
+ const number = Number.parseInt(segments[separatorIndex + 2] ?? "", 10);
761
+ if (!Number.isFinite(number)) return null;
762
+ const repositorySegments = decodePathSegments(segments.slice(0, separatorIndex));
763
+ const repo = repositorySegments[repositorySegments.length - 1];
764
+ const owner = repositorySegments[0];
765
+ if (!owner || !repo) return null;
766
+ const repositoryPath = repositorySegments.join("/");
767
+ return {
768
+ provider: "gitlab",
769
+ host: parsed.host.toLowerCase(),
770
+ owner,
771
+ repo,
772
+ number,
773
+ repositoryPath,
774
+ repoUrl: `${parsed.origin}/${repositoryPath}`
775
+ };
776
+ }
730
777
  function decodePathSegments(segments) {
731
778
  return segments.map((segment) => {
732
779
  try {
@@ -5794,6 +5841,11 @@ var GitHubTokenManager = class extends BaseRefreshManager {
5794
5841
  constructor() {
5795
5842
  super("GitHubTokenManager");
5796
5843
  }
5844
+ async refreshCredentials() {
5845
+ const config = this.getRuntimeConfig();
5846
+ if (!config) throw new Error("GitHub credential refresh is not configured");
5847
+ await this.doRefresh(config);
5848
+ }
5797
5849
  async doRefresh(_config) {
5798
5850
  console.log("[GitHubTokenManager] Refreshing GitHub token...");
5799
5851
  const response = await monolithRequest("/v1/engine/github/refresh-token");
@@ -9979,7 +10031,7 @@ var DEFAULT_CODEX_ARGS = ["app-server", "--listen", "stdio://"];
9979
10031
  var MIN_CODEX_CLI_VERSION = "0.144.6";
9980
10032
  var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
9981
10033
  var codexCliVersionEnsured = null;
9982
- var ENGINE_PACKAGE_VERSION = "0.1.507";
10034
+ var ENGINE_PACKAGE_VERSION = "0.1.509";
9983
10035
  var INITIALIZE_METHOD = "initialize";
9984
10036
  var INITIALIZED_NOTIFICATION = "initialized";
9985
10037
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -16229,6 +16281,9 @@ var writeTerminalSessionSchema = z7.object({
16229
16281
  generation: z7.number().int().nonnegative(),
16230
16282
  sequence: z7.number().int().nonnegative()
16231
16283
  });
16284
+ var mergePullRequestSchema = z7.object({
16285
+ prUrl: z7.string().url()
16286
+ });
16232
16287
  var sendMessageSchema = z7.object({
16233
16288
  messageId: z7.string().min(1).optional(),
16234
16289
  submittedAt: z7.string().datetime().optional(),
@@ -16635,6 +16690,32 @@ function createV1Routes(deps) {
16635
16690
  }
16636
16691
  return c.json(result);
16637
16692
  });
16693
+ app2.post("/pull-requests/merge", async (c) => {
16694
+ const body = mergePullRequestSchema.parse(await c.req.json());
16695
+ const parsed = parseCodeHostPrUrl(body.prUrl);
16696
+ if (parsed?.provider !== "github") {
16697
+ return c.json(jsonError("Only GitHub pull requests are supported"), 400);
16698
+ }
16699
+ const repository = (await gitService.listRepositories()).find(
16700
+ (repo) => repo.name.toLowerCase() === parsed.repo.toLowerCase()
16701
+ );
16702
+ if (!repository) {
16703
+ return c.json(jsonError("Pull request repository is not available in this workspace"), 404);
16704
+ }
16705
+ try {
16706
+ await githubTokenManager.refreshCredentials();
16707
+ await execFileAsync("gh", ["pr", "merge", body.prUrl, "--squash"], {
16708
+ cwd: repository.path,
16709
+ encoding: "utf-8",
16710
+ timeout: 12e4,
16711
+ maxBuffer: SUBPROCESS_MAX_BUFFER
16712
+ });
16713
+ return c.json({ success: true });
16714
+ } catch (error) {
16715
+ const detail = error && typeof error === "object" && "stderr" in error && typeof error.stderr === "string" ? error.stderr.trim() : error instanceof Error ? error.message : "GitHub CLI merge failed";
16716
+ return c.json(jsonError("Failed to merge pull request", detail), 409);
16717
+ }
16718
+ });
16638
16719
  app2.get("/terminal/sessions", (c) => {
16639
16720
  return c.json({ sessions: terminalService.list() });
16640
16721
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.507",
3
+ "version": "0.1.509",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",