@saeed42/worktree-worker 1.3.2 → 1.3.4

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/main.js +44 -20
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -13,9 +13,10 @@ var env = {
13
13
  PORT: parseInt(process.env.PORT || "8787", 10),
14
14
  NODE_ENV: process.env.NODE_ENV || "development",
15
15
  WORKER_TOKEN: process.env.WORKER_TOKEN || "",
16
- BASE_WORKSPACE_DIR: process.env.BASE_WORKSPACE_DIR || "/project/sandbox",
17
- WORKSPACES_ROOT: process.env.WORKSPACES_ROOT || "/project/workspaces",
18
- TRIALS_WORKSPACE_DIR: process.env.TRIALS_WORKSPACE_DIR || "/project/workspaces/trials",
16
+ // CRITICAL: Must be /project/sandbox to match trigger tasks and OpenCode
17
+ BASE_WORKSPACE_DIR: "/project/sandbox",
18
+ WORKSPACES_ROOT: "/project/workspaces",
19
+ TRIALS_WORKSPACE_DIR: "/project/workspaces/trials",
19
20
  DEFAULT_BRANCH: process.env.DEFAULT_BRANCH || "main",
20
21
  GIT_TIMEOUT_MS: parseInt(process.env.GIT_TIMEOUT_MS || "60000", 10),
21
22
  CLEANUP_AFTER_HOURS: parseInt(process.env.CLEANUP_AFTER_HOURS || "24", 10)
@@ -634,10 +635,26 @@ var RepoService = class {
634
635
  `Repository already initialized with different URL. Current: ${currentUrl}, Requested: ${requestedUrl}. Use force=true to re-initialize (this will delete all worktrees).`
635
636
  );
636
637
  }
637
- log.warn("Force re-init: cleaning worktrees and updating remote in-place");
638
+ log.warn("Force re-init: clearing contents and cloning fresh");
638
639
  await this.cleanAllWorktrees();
639
- const cleanUrl = options.repoUrl.replace(/^https:\/\/[^@]+@/, "https://");
640
- await gitService.exec(["remote", "set-url", "origin", cleanUrl], repoRoot);
640
+ const targetBranch = options.branch || env.DEFAULT_BRANCH;
641
+ try {
642
+ const items = await readdir(repoRoot);
643
+ for (const item of items) {
644
+ const itemPath = `${repoRoot}/${item}`;
645
+ await rm(itemPath, { recursive: true, force: true });
646
+ }
647
+ log.info("Cleared directory contents", { repoRoot, itemsRemoved: items.length });
648
+ } catch (clearError) {
649
+ log.error("Failed to clear directory contents", { error: clearError });
650
+ throw new AppError("Failed to clear directory contents", "GIT_ERROR", clearError);
651
+ }
652
+ log.info("Cloning repository fresh", { branch: targetBranch });
653
+ await gitService.cloneRepo(options.repoUrl, repoRoot, {
654
+ branch: targetBranch,
655
+ blobless: true,
656
+ githubToken: options.githubToken
657
+ });
641
658
  await gitService.exec(["config", "--local", "user.name", "origin-agent[bot]"], repoRoot);
642
659
  await gitService.exec([
643
660
  "config",
@@ -646,14 +663,9 @@ var RepoService = class {
646
663
  "origin-agent[bot]@users.noreply.github.com"
647
664
  ], repoRoot);
648
665
  await gitService.exec(["config", "--local", "safe.directory", repoRoot], repoRoot);
649
- const targetBranch = options.branch || env.DEFAULT_BRANCH;
650
- log.info("Fetching from new remote", { branch: targetBranch });
666
+ const cleanUrl = options.repoUrl.replace(/^https:\/\/[^@]+@/, "https://");
667
+ await gitService.exec(["remote", "set-url", "origin", cleanUrl], repoRoot);
651
668
  await gitService.fetch("origin", repoRoot, auth);
652
- try {
653
- await gitService.exec(["checkout", "-B", targetBranch, `origin/${targetBranch}`, "--force"], repoRoot);
654
- } catch {
655
- await gitService.exec(["checkout", "-B", targetBranch, "--force"], repoRoot);
656
- }
657
669
  await gitService.exec(["branch", `--set-upstream-to=origin/${targetBranch}`, targetBranch], repoRoot).catch(
658
670
  () => {
659
671
  }
@@ -661,7 +673,7 @@ var RepoService = class {
661
673
  const headSha2 = await gitService.getHeadSha(repoRoot);
662
674
  const branch2 = await gitService.getCurrentBranch(repoRoot);
663
675
  const remote2 = await gitService.getRemoteUrl("origin", repoRoot);
664
- log.info("Repository re-initialized in-place", { branch: branch2, headSha: headSha2 });
676
+ log.info("Repository cloned fresh", { branch: branch2, headSha: headSha2 });
665
677
  return { path: repoRoot, branch: branch2, headSha: headSha2, remote: remote2 };
666
678
  }
667
679
  const parentDir = repoRoot.split("/").slice(0, -1).join("/");
@@ -670,8 +682,23 @@ var RepoService = class {
670
682
  const dirExists = await stat2(repoRoot).then(() => true).catch(() => false);
671
683
  const branch = options.branch || env.DEFAULT_BRANCH;
672
684
  if (dirExists) {
673
- log.info("Directory exists, initializing git in-place", { branch });
674
- await gitService.exec(["init"], repoRoot);
685
+ log.info("Directory exists, clearing contents and cloning fresh", { branch });
686
+ try {
687
+ const items = await readdir(repoRoot);
688
+ for (const item of items) {
689
+ const itemPath = `${repoRoot}/${item}`;
690
+ await rm(itemPath, { recursive: true, force: true });
691
+ }
692
+ log.info("Cleared directory contents", { repoRoot, itemsRemoved: items.length });
693
+ } catch (clearError) {
694
+ log.error("Failed to clear directory contents", { error: clearError });
695
+ throw new AppError("Failed to clear directory contents", "GIT_ERROR", clearError);
696
+ }
697
+ await gitService.cloneRepo(options.repoUrl, repoRoot, {
698
+ branch,
699
+ blobless: true,
700
+ githubToken: options.githubToken
701
+ });
675
702
  await gitService.exec(["config", "--local", "user.name", "origin-agent[bot]"], repoRoot);
676
703
  await gitService.exec([
677
704
  "config",
@@ -681,11 +708,8 @@ var RepoService = class {
681
708
  ], repoRoot);
682
709
  await gitService.exec(["config", "--local", "safe.directory", repoRoot], repoRoot);
683
710
  const cleanUrl = options.repoUrl.replace(/^https:\/\/[^@]+@/, "https://");
684
- await gitService.exec(["remote", "add", "origin", cleanUrl], repoRoot).catch(async () => {
685
- await gitService.exec(["remote", "set-url", "origin", cleanUrl], repoRoot);
686
- });
711
+ await gitService.exec(["remote", "set-url", "origin", cleanUrl], repoRoot);
687
712
  await gitService.fetch("origin", repoRoot, auth);
688
- await gitService.exec(["checkout", "-B", branch, `origin/${branch}`, "--force"], repoRoot);
689
713
  await gitService.exec(["branch", `--set-upstream-to=origin/${branch}`, branch], repoRoot).catch(
690
714
  () => {
691
715
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saeed42/worktree-worker",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Git worktree management service for AI agent trials",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",