@ricsam/r5d-worker 0.0.62 → 0.0.64

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/dist/cjs/main.cjs CHANGED
@@ -1032,6 +1032,19 @@ function checkoutVisibleBranch(input) {
1032
1032
  }
1033
1033
  runGit(["checkout", "--no-recurse-submodules", "-B", input.branchName], { cwd: input.branchPath });
1034
1034
  }
1035
+ function reconcileRewrittenCanonicalHistory(input) {
1036
+ const remoteRef = `refs/remotes/origin/${input.branchName}`;
1037
+ if (!tryGit(["rev-parse", "--verify", "HEAD"], { cwd: input.branchPath })) return;
1038
+ if (!tryGit(["show-ref", "--verify", "--quiet", remoteRef], { cwd: input.branchPath })) return;
1039
+ if (tryGit(["merge-base", "HEAD", remoteRef], { cwd: input.branchPath })) return;
1040
+ if (hasWorktreeChanges(input.branchPath)) return;
1041
+ const localTree = runGit(["rev-parse", "HEAD^{tree}"], { cwd: input.branchPath });
1042
+ const remoteTree = runGit(["rev-parse", `${remoteRef}^{tree}`], { cwd: input.branchPath });
1043
+ if (localTree !== remoteTree) return;
1044
+ const previousHead = runGit(["rev-parse", "HEAD"], { cwd: input.branchPath });
1045
+ runGit(["update-ref", `refs/r5d/pre-canonical-checkout/${previousHead}`, previousHead], { cwd: input.branchPath });
1046
+ runGit(["checkout", "--no-recurse-submodules", "-B", input.branchName, remoteRef], { cwd: input.branchPath });
1047
+ }
1035
1048
  function migrateExistingCheckoutToRequiredRemote(input) {
1036
1049
  if (originRemoteUrl(input.branchPath) === input.remoteUrl) return;
1037
1050
  const dirtyWorkingTree = hasWorktreeChanges(input.branchPath);
@@ -1139,6 +1152,9 @@ function ensureVisibleGitCheckout(input) {
1139
1152
  if (input.requireRemoteBranch && !tryGit(["show-ref", "--verify", "--quiet", `refs/remotes/origin/${input.branchName}`], { cwd: branchPath })) {
1140
1153
  throw new Error(`Existing checkout for ${input.branchName} does not contain its canonical remote branch`);
1141
1154
  }
1155
+ if (input.requireRemoteBranch) {
1156
+ reconcileRewrittenCanonicalHistory({ branchPath, branchName: input.branchName });
1157
+ }
1142
1158
  if (input.requiredBaseCommit) {
1143
1159
  assertCheckoutDerivedFromRequiredBase({
1144
1160
  branchPath,
@@ -2889,7 +2905,6 @@ async function startWorker(options) {
2889
2905
  configureGitHubAuth(message.githubCredential);
2890
2906
  visibleGitIdentity = message.gitIdentity;
2891
2907
  workspaceRemoteUrl = message.workspaceRemoteUrl;
2892
- const migratedProjectIds = (0, import_managed_paths.migrateLegacyProjectRoots)(projectsRoot, message.projects);
2893
2908
  manifestByProjectId.clear();
2894
2909
  for (const project of message.projects) manifestByProjectId.set(project.projectId, project);
2895
2910
  const currentCheckouts = allManifestCheckouts();
@@ -2905,7 +2920,7 @@ async function startWorker(options) {
2905
2920
  if (!hasNormalVisibleGitDir(branchPath)) pendingManifestCheckouts.set(key, checkout);
2906
2921
  }
2907
2922
  if (!workspaceManifestRevision.isCurrent(revisionToken)) return false;
2908
- const created = firstBootstrap || migratedProjectIds.length > 0 ? ensureVisibleWorktrees(currentCheckouts, { strictCanonicalRevalidation: true }) : [];
2923
+ const created = firstBootstrap ? ensureVisibleWorktrees(currentCheckouts, { strictCanonicalRevalidation: true }) : [];
2909
2924
  if (!workspaceManifestRevision.isCurrent(revisionToken)) return false;
2910
2925
  const bootstrapped = await (0, import_workspace_sync.convergeWorkspaceHead)(workspaceSyncInput({ type: "connect" }, { newVisibleCheckouts: created }), {
2911
2926
  // An existing checkout becomes routable after a fetch. Its
@@ -2934,10 +2949,8 @@ async function startWorker(options) {
2934
2949
  pendingManifestCheckouts.delete(manifestCheckoutKey(checkout.projectId, checkout.branchName));
2935
2950
  }
2936
2951
  }
2937
- process.stdout.write(
2938
- `[r5d-worker] workspace manifest: ${message.projects.length} projects${migratedProjectIds.length > 0 ? `; migrated ${migratedProjectIds.length} project checkout root(s)` : ""}
2939
- `
2940
- );
2952
+ process.stdout.write(`[r5d-worker] workspace manifest: ${message.projects.length} projects
2953
+ `);
2941
2954
  return true;
2942
2955
  });
2943
2956
  if (!completed || !workspaceManifestRevision.complete(revisionToken)) return;
@@ -31,10 +31,8 @@ __export(managed_paths_exports, {
31
31
  BRANCH_NAME_MAX_LENGTH: () => BRANCH_NAME_MAX_LENGTH,
32
32
  BRANCH_NAME_PATTERN: () => BRANCH_NAME_PATTERN,
33
33
  assertPathInside: () => assertPathInside,
34
- legacyProjectSlug: () => legacyProjectSlug,
35
34
  managedBranchPath: () => managedBranchPath,
36
35
  managedProjectRoot: () => managedProjectRoot,
37
- migrateLegacyProjectRoots: () => migrateLegacyProjectRoots,
38
36
  validateCheckoutPathSegments: () => validateCheckoutPathSegments,
39
37
  validateManagedBranchName: () => validateManagedBranchName
40
38
  });
@@ -105,54 +103,13 @@ function managedBranchPath(projectsRoot, checkoutPathSegments, branchName) {
105
103
  assertNoSymlinkComponents(projectRoot, result);
106
104
  return result;
107
105
  }
108
- function legacyProjectSlug(projectPath, projectId) {
109
- return (projectPath || projectId).trim().toLowerCase().replace(/[^a-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "") || projectId;
110
- }
111
- function migrateLegacyProjectRoots(projectsRoot, projects) {
112
- const resolvedRoot = import_node_path.default.resolve(projectsRoot);
113
- const legacyOwners = /* @__PURE__ */ new Map();
114
- const nestedOwners = /* @__PURE__ */ new Map();
115
- const moves = [];
116
- for (const project of projects) {
117
- const nestedRoot = managedProjectRoot(resolvedRoot, project.checkoutPathSegments);
118
- const legacySlug = legacyProjectSlug(project.projectPath, project.projectId);
119
- const legacyRoot = import_node_path.default.join(resolvedRoot, legacySlug);
120
- assertNoSymlinkComponents(resolvedRoot, legacyRoot);
121
- const existingLegacyOwner = legacyOwners.get(legacyRoot);
122
- if (existingLegacyOwner) {
123
- throw new Error(`Projects ${existingLegacyOwner} and ${project.projectId} collide at legacy checkout path '${legacyRoot}'`);
124
- }
125
- legacyOwners.set(legacyRoot, project.projectId);
126
- const existingNestedOwner = nestedOwners.get(nestedRoot);
127
- if (existingNestedOwner) {
128
- throw new Error(`Projects ${existingNestedOwner} and ${project.projectId} collide at checkout path '${nestedRoot}'`);
129
- }
130
- nestedOwners.set(nestedRoot, project.projectId);
131
- const legacyExists = import_node_fs.default.existsSync(legacyRoot);
132
- const nestedExists = import_node_fs.default.existsSync(nestedRoot);
133
- if (legacyExists && nestedExists) {
134
- throw new Error(
135
- `Checkout migration is ambiguous for ${project.projectPath}: both '${legacyRoot}' and '${nestedRoot}' exist. Preserve the desired checkout and remove or relocate the other path before reconnecting the worker.`
136
- );
137
- }
138
- if (legacyExists) moves.push({ projectId: project.projectId, legacyRoot, nestedRoot });
139
- }
140
- for (const move of moves) {
141
- import_node_fs.default.mkdirSync(import_node_path.default.dirname(move.nestedRoot), { recursive: true });
142
- assertNoSymlinkComponents(resolvedRoot, import_node_path.default.dirname(move.nestedRoot));
143
- import_node_fs.default.renameSync(move.legacyRoot, move.nestedRoot);
144
- }
145
- return moves.map((move) => move.projectId);
146
- }
147
106
  // Annotate the CommonJS export names for ESM import in node:
148
107
  0 && (module.exports = {
149
108
  BRANCH_NAME_MAX_LENGTH,
150
109
  BRANCH_NAME_PATTERN,
151
110
  assertPathInside,
152
- legacyProjectSlug,
153
111
  managedBranchPath,
154
112
  managedProjectRoot,
155
- migrateLegacyProjectRoots,
156
113
  validateCheckoutPathSegments,
157
114
  validateManagedBranchName
158
115
  });
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.62",
3
+ "version": "0.0.64",
4
4
  "type": "commonjs"
5
5
  }
@@ -41,11 +41,8 @@ function hasNormalGitDirectory(checkoutPath) {
41
41
  function inspectWorkspaceManifestFilesystem(input) {
42
42
  const firstBootstrap = !hasNormalGitDirectory(input.workspaceShadowRoot);
43
43
  const missingCheckouts = [];
44
- const migratedProjectIds = [];
45
44
  for (const project of input.projects) {
46
45
  const projectRoot = (0, import_managed_paths.managedProjectRoot)(input.projectsRoot, project.checkoutPathSegments);
47
- const legacyRoot = import_node_path.default.join(input.projectsRoot, (0, import_managed_paths.legacyProjectSlug)(project.projectPath, project.projectId));
48
- if (import_node_fs.default.existsSync(legacyRoot)) migratedProjectIds.push(project.projectId);
49
46
  for (const branchName of project.branches) {
50
47
  if (!hasNormalGitDirectory(import_node_path.default.join(projectRoot, branchName))) {
51
48
  missingCheckouts.push({ projectId: project.projectId, branchName });
@@ -54,8 +51,7 @@ function inspectWorkspaceManifestFilesystem(input) {
54
51
  }
55
52
  return {
56
53
  firstBootstrap,
57
- missingCheckouts,
58
- migratedProjectIds
54
+ missingCheckouts
59
55
  };
60
56
  }
61
57
  // Annotate the CommonJS export names for ESM import in node:
package/dist/mjs/main.mjs CHANGED
@@ -35,7 +35,7 @@ import {
35
35
  WORKER_RELOAD_EXIT_CODE,
36
36
  WORKER_RUNTIME_ENV
37
37
  } from "./supervisor.mjs";
38
- import { managedProjectRoot, migrateLegacyProjectRoots, validateManagedBranchName } from "./managed-paths.mjs";
38
+ import { managedProjectRoot, validateManagedBranchName } from "./managed-paths.mjs";
39
39
  import {
40
40
  WorkspaceSyncSingleFlight,
41
41
  convergeWorkspaceHead,
@@ -1003,6 +1003,19 @@ function checkoutVisibleBranch(input) {
1003
1003
  }
1004
1004
  runGit(["checkout", "--no-recurse-submodules", "-B", input.branchName], { cwd: input.branchPath });
1005
1005
  }
1006
+ function reconcileRewrittenCanonicalHistory(input) {
1007
+ const remoteRef = `refs/remotes/origin/${input.branchName}`;
1008
+ if (!tryGit(["rev-parse", "--verify", "HEAD"], { cwd: input.branchPath })) return;
1009
+ if (!tryGit(["show-ref", "--verify", "--quiet", remoteRef], { cwd: input.branchPath })) return;
1010
+ if (tryGit(["merge-base", "HEAD", remoteRef], { cwd: input.branchPath })) return;
1011
+ if (hasWorktreeChanges(input.branchPath)) return;
1012
+ const localTree = runGit(["rev-parse", "HEAD^{tree}"], { cwd: input.branchPath });
1013
+ const remoteTree = runGit(["rev-parse", `${remoteRef}^{tree}`], { cwd: input.branchPath });
1014
+ if (localTree !== remoteTree) return;
1015
+ const previousHead = runGit(["rev-parse", "HEAD"], { cwd: input.branchPath });
1016
+ runGit(["update-ref", `refs/r5d/pre-canonical-checkout/${previousHead}`, previousHead], { cwd: input.branchPath });
1017
+ runGit(["checkout", "--no-recurse-submodules", "-B", input.branchName, remoteRef], { cwd: input.branchPath });
1018
+ }
1006
1019
  function migrateExistingCheckoutToRequiredRemote(input) {
1007
1020
  if (originRemoteUrl(input.branchPath) === input.remoteUrl) return;
1008
1021
  const dirtyWorkingTree = hasWorktreeChanges(input.branchPath);
@@ -1110,6 +1123,9 @@ function ensureVisibleGitCheckout(input) {
1110
1123
  if (input.requireRemoteBranch && !tryGit(["show-ref", "--verify", "--quiet", `refs/remotes/origin/${input.branchName}`], { cwd: branchPath })) {
1111
1124
  throw new Error(`Existing checkout for ${input.branchName} does not contain its canonical remote branch`);
1112
1125
  }
1126
+ if (input.requireRemoteBranch) {
1127
+ reconcileRewrittenCanonicalHistory({ branchPath, branchName: input.branchName });
1128
+ }
1113
1129
  if (input.requiredBaseCommit) {
1114
1130
  assertCheckoutDerivedFromRequiredBase({
1115
1131
  branchPath,
@@ -2860,7 +2876,6 @@ async function startWorker(options) {
2860
2876
  configureGitHubAuth(message.githubCredential);
2861
2877
  visibleGitIdentity = message.gitIdentity;
2862
2878
  workspaceRemoteUrl = message.workspaceRemoteUrl;
2863
- const migratedProjectIds = migrateLegacyProjectRoots(projectsRoot, message.projects);
2864
2879
  manifestByProjectId.clear();
2865
2880
  for (const project of message.projects) manifestByProjectId.set(project.projectId, project);
2866
2881
  const currentCheckouts = allManifestCheckouts();
@@ -2876,7 +2891,7 @@ async function startWorker(options) {
2876
2891
  if (!hasNormalVisibleGitDir(branchPath)) pendingManifestCheckouts.set(key, checkout);
2877
2892
  }
2878
2893
  if (!workspaceManifestRevision.isCurrent(revisionToken)) return false;
2879
- const created = firstBootstrap || migratedProjectIds.length > 0 ? ensureVisibleWorktrees(currentCheckouts, { strictCanonicalRevalidation: true }) : [];
2894
+ const created = firstBootstrap ? ensureVisibleWorktrees(currentCheckouts, { strictCanonicalRevalidation: true }) : [];
2880
2895
  if (!workspaceManifestRevision.isCurrent(revisionToken)) return false;
2881
2896
  const bootstrapped = await convergeWorkspaceHead(workspaceSyncInput({ type: "connect" }, { newVisibleCheckouts: created }), {
2882
2897
  // An existing checkout becomes routable after a fetch. Its
@@ -2905,10 +2920,8 @@ async function startWorker(options) {
2905
2920
  pendingManifestCheckouts.delete(manifestCheckoutKey(checkout.projectId, checkout.branchName));
2906
2921
  }
2907
2922
  }
2908
- process.stdout.write(
2909
- `[r5d-worker] workspace manifest: ${message.projects.length} projects${migratedProjectIds.length > 0 ? `; migrated ${migratedProjectIds.length} project checkout root(s)` : ""}
2910
- `
2911
- );
2923
+ process.stdout.write(`[r5d-worker] workspace manifest: ${message.projects.length} projects
2924
+ `);
2912
2925
  return true;
2913
2926
  });
2914
2927
  if (!completed || !workspaceManifestRevision.complete(revisionToken)) return;
@@ -64,53 +64,12 @@ function managedBranchPath(projectsRoot, checkoutPathSegments, branchName) {
64
64
  assertNoSymlinkComponents(projectRoot, result);
65
65
  return result;
66
66
  }
67
- function legacyProjectSlug(projectPath, projectId) {
68
- return (projectPath || projectId).trim().toLowerCase().replace(/[^a-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "") || projectId;
69
- }
70
- function migrateLegacyProjectRoots(projectsRoot, projects) {
71
- const resolvedRoot = path.resolve(projectsRoot);
72
- const legacyOwners = /* @__PURE__ */ new Map();
73
- const nestedOwners = /* @__PURE__ */ new Map();
74
- const moves = [];
75
- for (const project of projects) {
76
- const nestedRoot = managedProjectRoot(resolvedRoot, project.checkoutPathSegments);
77
- const legacySlug = legacyProjectSlug(project.projectPath, project.projectId);
78
- const legacyRoot = path.join(resolvedRoot, legacySlug);
79
- assertNoSymlinkComponents(resolvedRoot, legacyRoot);
80
- const existingLegacyOwner = legacyOwners.get(legacyRoot);
81
- if (existingLegacyOwner) {
82
- throw new Error(`Projects ${existingLegacyOwner} and ${project.projectId} collide at legacy checkout path '${legacyRoot}'`);
83
- }
84
- legacyOwners.set(legacyRoot, project.projectId);
85
- const existingNestedOwner = nestedOwners.get(nestedRoot);
86
- if (existingNestedOwner) {
87
- throw new Error(`Projects ${existingNestedOwner} and ${project.projectId} collide at checkout path '${nestedRoot}'`);
88
- }
89
- nestedOwners.set(nestedRoot, project.projectId);
90
- const legacyExists = fs.existsSync(legacyRoot);
91
- const nestedExists = fs.existsSync(nestedRoot);
92
- if (legacyExists && nestedExists) {
93
- throw new Error(
94
- `Checkout migration is ambiguous for ${project.projectPath}: both '${legacyRoot}' and '${nestedRoot}' exist. Preserve the desired checkout and remove or relocate the other path before reconnecting the worker.`
95
- );
96
- }
97
- if (legacyExists) moves.push({ projectId: project.projectId, legacyRoot, nestedRoot });
98
- }
99
- for (const move of moves) {
100
- fs.mkdirSync(path.dirname(move.nestedRoot), { recursive: true });
101
- assertNoSymlinkComponents(resolvedRoot, path.dirname(move.nestedRoot));
102
- fs.renameSync(move.legacyRoot, move.nestedRoot);
103
- }
104
- return moves.map((move) => move.projectId);
105
- }
106
67
  export {
107
68
  BRANCH_NAME_MAX_LENGTH,
108
69
  BRANCH_NAME_PATTERN,
109
70
  assertPathInside,
110
- legacyProjectSlug,
111
71
  managedBranchPath,
112
72
  managedProjectRoot,
113
- migrateLegacyProjectRoots,
114
73
  validateCheckoutPathSegments,
115
74
  validateManagedBranchName
116
75
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.62",
3
+ "version": "0.0.64",
4
4
  "type": "module"
5
5
  }
@@ -1,6 +1,6 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import { legacyProjectSlug, managedProjectRoot } from "./managed-paths.mjs";
3
+ import { managedProjectRoot } from "./managed-paths.mjs";
4
4
  function hasNormalGitDirectory(checkoutPath) {
5
5
  const gitPath = path.join(checkoutPath, ".git");
6
6
  return fs.existsSync(gitPath) && fs.statSync(gitPath).isDirectory();
@@ -8,11 +8,8 @@ function hasNormalGitDirectory(checkoutPath) {
8
8
  function inspectWorkspaceManifestFilesystem(input) {
9
9
  const firstBootstrap = !hasNormalGitDirectory(input.workspaceShadowRoot);
10
10
  const missingCheckouts = [];
11
- const migratedProjectIds = [];
12
11
  for (const project of input.projects) {
13
12
  const projectRoot = managedProjectRoot(input.projectsRoot, project.checkoutPathSegments);
14
- const legacyRoot = path.join(input.projectsRoot, legacyProjectSlug(project.projectPath, project.projectId));
15
- if (fs.existsSync(legacyRoot)) migratedProjectIds.push(project.projectId);
16
13
  for (const branchName of project.branches) {
17
14
  if (!hasNormalGitDirectory(path.join(projectRoot, branchName))) {
18
15
  missingCheckouts.push({ projectId: project.projectId, branchName });
@@ -21,8 +18,7 @@ function inspectWorkspaceManifestFilesystem(input) {
21
18
  }
22
19
  return {
23
20
  firstBootstrap,
24
- missingCheckouts,
25
- migratedProjectIds
21
+ missingCheckouts
26
22
  };
27
23
  }
28
24
  export {
@@ -1,15 +1,8 @@
1
1
  export declare const BRANCH_NAME_MAX_LENGTH = 45;
2
2
  export declare const BRANCH_NAME_PATTERN: RegExp;
3
3
  export type CheckoutPathSegments = [namespace: string, project: string];
4
- export type ManagedProjectManifestPath = {
5
- projectId: string;
6
- projectPath: string;
7
- checkoutPathSegments: CheckoutPathSegments;
8
- };
9
4
  export declare function validateManagedBranchName(branchName: string): void;
10
5
  export declare function validateCheckoutPathSegments(value: unknown): CheckoutPathSegments;
11
6
  export declare function assertPathInside(root: string, candidate: string, label: string): void;
12
7
  export declare function managedProjectRoot(projectsRoot: string, checkoutPathSegments: unknown): string;
13
8
  export declare function managedBranchPath(projectsRoot: string, checkoutPathSegments: unknown, branchName: string): string;
14
- export declare function legacyProjectSlug(projectPath: string, projectId: string): string;
15
- export declare function migrateLegacyProjectRoots(projectsRoot: string, projects: ManagedProjectManifestPath[]): string[];
@@ -1,6 +1,5 @@
1
1
  export type WorkspaceManifestCheckout = {
2
2
  projectId: string;
3
- projectPath: string;
4
3
  checkoutPathSegments: [namespace: string, project: string];
5
4
  branches: string[];
6
5
  };
@@ -10,7 +9,6 @@ export type WorkspaceManifestFilesystemState = {
10
9
  projectId: string;
11
10
  branchName: string;
12
11
  }>;
13
- migratedProjectIds: string[];
14
12
  };
15
13
  /**
16
14
  * Inspects manifest-related filesystem state without reserving visible paths.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.62",
3
+ "version": "0.0.64",
4
4
  "type": "module",
5
5
  "main": "./dist/cjs/main.cjs",
6
6
  "module": "./dist/mjs/main.mjs",