@ricsam/r5d-worker 0.0.132 → 0.0.134

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 (47) hide show
  1. package/dist/cjs/atomic-rename.cjs +303 -0
  2. package/dist/cjs/git-blob-hash.cjs +41 -0
  3. package/dist/cjs/main.cjs +187 -38
  4. package/dist/cjs/package.json +1 -1
  5. package/dist/cjs/three-way-merge.cjs +346 -0
  6. package/dist/cjs/working-tree-mirror.cjs +1049 -64
  7. package/dist/cjs/workspace-command-sync-policy.cjs +8 -4
  8. package/dist/cjs/workspace-command-targets.cjs +63 -0
  9. package/dist/cjs/workspace-filesystem-job-types.cjs +11 -1
  10. package/dist/cjs/workspace-filesystem-jobs.cjs +2 -0
  11. package/dist/cjs/workspace-git-sync.cjs +846 -61
  12. package/dist/cjs/workspace-hydration-ledger.cjs +66 -0
  13. package/dist/cjs/workspace-hydration-merge.cjs +433 -0
  14. package/dist/cjs/workspace-hydration-recovery-state.cjs +53 -0
  15. package/dist/cjs/workspace-merge-projection.cjs +81 -10
  16. package/dist/cjs/workspace-project-config-policy.cjs +19 -12
  17. package/dist/mjs/atomic-rename.mjs +261 -0
  18. package/dist/mjs/git-blob-hash.mjs +16 -0
  19. package/dist/mjs/main.mjs +196 -39
  20. package/dist/mjs/package.json +1 -1
  21. package/dist/mjs/three-way-merge.mjs +318 -0
  22. package/dist/mjs/working-tree-mirror.mjs +1035 -64
  23. package/dist/mjs/workspace-command-sync-policy.mjs +8 -4
  24. package/dist/mjs/workspace-command-targets.mjs +37 -0
  25. package/dist/mjs/workspace-filesystem-job-types.mjs +11 -1
  26. package/dist/mjs/workspace-filesystem-jobs.mjs +4 -0
  27. package/dist/mjs/workspace-git-sync.mjs +854 -62
  28. package/dist/mjs/workspace-hydration-ledger.mjs +42 -0
  29. package/dist/mjs/workspace-hydration-merge.mjs +399 -0
  30. package/dist/mjs/workspace-hydration-recovery-state.mjs +29 -0
  31. package/dist/mjs/workspace-merge-projection.mjs +85 -11
  32. package/dist/mjs/workspace-project-config-policy.mjs +16 -10
  33. package/dist/types/atomic-rename.d.ts +78 -0
  34. package/dist/types/git-blob-hash.d.ts +10 -0
  35. package/dist/types/main.d.ts +21 -2
  36. package/dist/types/three-way-merge.d.ts +77 -0
  37. package/dist/types/working-tree-mirror.d.ts +270 -7
  38. package/dist/types/workspace-command-sync-policy.d.ts +12 -6
  39. package/dist/types/workspace-command-targets.d.ts +37 -0
  40. package/dist/types/workspace-filesystem-job-types.d.ts +46 -4
  41. package/dist/types/workspace-git-sync.d.ts +125 -3
  42. package/dist/types/workspace-hydration-ledger.d.ts +43 -0
  43. package/dist/types/workspace-hydration-merge.d.ts +95 -0
  44. package/dist/types/workspace-hydration-recovery-state.d.ts +10 -0
  45. package/dist/types/workspace-merge-projection.d.ts +19 -1
  46. package/dist/types/workspace-project-config-policy.d.ts +17 -3
  47. package/package.json +2 -2
@@ -0,0 +1,303 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var atomic_rename_exports = {};
30
+ __export(atomic_rename_exports, {
31
+ AtomicRenameError: () => AtomicRenameError,
32
+ atomicRenamePrimitivesFor: () => atomicRenamePrimitivesFor,
33
+ atomicRenameSupport: () => atomicRenameSupport,
34
+ exchangePaths: () => exchangePaths,
35
+ isAtomicRenameUnsupported: () => isAtomicRenameUnsupported,
36
+ overrideAtomicRenameSupportForTests: () => overrideAtomicRenameSupportForTests,
37
+ probeAtomicRenameSupport: () => probeAtomicRenameSupport,
38
+ renameNoReplace: () => renameNoReplace,
39
+ resetAtomicRenameProbesForTests: () => resetAtomicRenameProbesForTests
40
+ });
41
+ module.exports = __toCommonJS(atomic_rename_exports);
42
+ var import_node_fs = __toESM(require("node:fs"), 1);
43
+ var import_node_os = __toESM(require("node:os"), 1);
44
+ var import_node_path = __toESM(require("node:path"), 1);
45
+ var import_node_crypto = require("node:crypto");
46
+ class AtomicRenameError extends Error {
47
+ constructor(syscall, code, errno, path2, dest) {
48
+ super(`${code}: ${syscall} failed, ${path2} -> ${dest}`);
49
+ this.syscall = syscall;
50
+ this.code = code;
51
+ this.errno = errno;
52
+ this.path = path2;
53
+ this.dest = dest;
54
+ this.name = "AtomicRenameError";
55
+ }
56
+ syscall;
57
+ code;
58
+ errno;
59
+ path;
60
+ dest;
61
+ }
62
+ const UNSUPPORTED_CODES = /* @__PURE__ */ new Set(["EINVAL", "ENOSYS", "ENOTSUP", "EOPNOTSUPP", "EPERM"]);
63
+ function isAtomicRenameUnsupported(error) {
64
+ return error instanceof AtomicRenameError && UNSUPPORTED_CODES.has(error.code);
65
+ }
66
+ const LINUX_AT_FDCWD = -100;
67
+ const LINUX_RENAME_NOREPLACE = 1;
68
+ const LINUX_RENAME_EXCHANGE = 2;
69
+ const DARWIN_RENAME_SWAP = 2;
70
+ const DARWIN_RENAME_EXCL = 4;
71
+ const LINUX_SYS_RENAMEAT2 = { x64: 316, arm64: 276 };
72
+ const PROBE_PREFIX = ".r5d-atomic-rename-probe-";
73
+ let loaded = null;
74
+ let override = null;
75
+ const errnoNames = /* @__PURE__ */ new Map();
76
+ for (const [name, value] of Object.entries(import_node_os.default.constants.errno)) errnoNames.set(value, name);
77
+ function errnoCode(errno) {
78
+ return errnoNames.get(errno) ?? `E${errno}`;
79
+ }
80
+ function cString(value) {
81
+ return Buffer.from(`${value}\0`, "utf8");
82
+ }
83
+ function loadNative() {
84
+ if (loaded) return loaded;
85
+ loaded = { calls: null, detail: "not attempted" };
86
+ try {
87
+ const ffi = require("bun:ffi");
88
+ const { dlopen, FFIType, ptr, read } = ffi;
89
+ if (process.platform === "darwin") {
90
+ const lib = dlopen("libSystem.B.dylib", {
91
+ renamex_np: { args: [FFIType.ptr, FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
92
+ __error: { args: [], returns: FFIType.ptr }
93
+ });
94
+ loaded = {
95
+ calls: {
96
+ rename2: (from, to, flags) => {
97
+ const fromBuffer = cString(from);
98
+ const toBuffer = cString(to);
99
+ return lib.symbols.renamex_np(ptr(fromBuffer), ptr(toBuffer), flags);
100
+ },
101
+ errno: () => read.i32(lib.symbols.__error(), 0),
102
+ exchangeFlag: DARWIN_RENAME_SWAP,
103
+ noReplaceFlag: DARWIN_RENAME_EXCL,
104
+ backend: "renamex_np"
105
+ }
106
+ };
107
+ return loaded;
108
+ }
109
+ if (process.platform === "linux") {
110
+ const errnoLib = dlopen("libc.so.6", { __errno_location: { args: [], returns: FFIType.ptr } });
111
+ const errno = () => read.i32(errnoLib.symbols.__errno_location(), 0);
112
+ try {
113
+ const lib = dlopen("libc.so.6", {
114
+ renameat2: { args: [FFIType.i32, FFIType.ptr, FFIType.i32, FFIType.ptr, FFIType.u32], returns: FFIType.i32 }
115
+ });
116
+ loaded = {
117
+ calls: {
118
+ rename2: (from, to, flags) => {
119
+ const fromBuffer = cString(from);
120
+ const toBuffer = cString(to);
121
+ return lib.symbols.renameat2(LINUX_AT_FDCWD, ptr(fromBuffer), LINUX_AT_FDCWD, ptr(toBuffer), flags);
122
+ },
123
+ errno,
124
+ exchangeFlag: LINUX_RENAME_EXCHANGE,
125
+ noReplaceFlag: LINUX_RENAME_NOREPLACE,
126
+ backend: "renameat2"
127
+ }
128
+ };
129
+ return loaded;
130
+ } catch (error) {
131
+ const number = LINUX_SYS_RENAMEAT2[process.arch];
132
+ if (number === void 0) {
133
+ loaded = { calls: null, detail: `renameat2 symbol unavailable and no syscall number for ${process.arch}: ${String(error)}` };
134
+ return loaded;
135
+ }
136
+ const lib = dlopen("libc.so.6", {
137
+ syscall: {
138
+ args: [FFIType.i64, FFIType.i64, FFIType.i64, FFIType.i64, FFIType.i64, FFIType.i64],
139
+ returns: FFIType.i64
140
+ }
141
+ });
142
+ loaded = {
143
+ calls: {
144
+ rename2: (from, to, flags) => {
145
+ const fromBuffer = cString(from);
146
+ const toBuffer = cString(to);
147
+ return Number(
148
+ lib.symbols.syscall(number, LINUX_AT_FDCWD, Number(ptr(fromBuffer)), LINUX_AT_FDCWD, Number(ptr(toBuffer)), flags)
149
+ );
150
+ },
151
+ errno,
152
+ exchangeFlag: LINUX_RENAME_EXCHANGE,
153
+ noReplaceFlag: LINUX_RENAME_NOREPLACE,
154
+ backend: "syscall"
155
+ }
156
+ };
157
+ return loaded;
158
+ }
159
+ }
160
+ loaded = { calls: null, detail: `no atomic exchange primitive on ${process.platform}` };
161
+ } catch (error) {
162
+ loaded = { calls: null, detail: `bun:ffi unavailable: ${error instanceof Error ? error.message : String(error)}` };
163
+ }
164
+ return loaded;
165
+ }
166
+ function applyOverride(support) {
167
+ if (override?.exchange !== void 0) support.exchange = override.exchange;
168
+ if (override?.noReplace !== void 0) support.noReplace = override.noReplace;
169
+ return support;
170
+ }
171
+ function atomicRenameSupport() {
172
+ const native = loadNative();
173
+ return applyOverride(
174
+ native.calls ? { platform: process.platform, exchange: native.calls.backend, noReplace: native.calls.backend } : { platform: process.platform, exchange: "unavailable", noReplace: "link", detail: native.detail }
175
+ );
176
+ }
177
+ function overrideAtomicRenameSupportForTests(value) {
178
+ override = value;
179
+ }
180
+ function resetAtomicRenameProbesForTests() {
181
+ probes.clear();
182
+ }
183
+ function call(native, syscall, from, to, flags) {
184
+ if (native.rename2(from, to, flags) === 0) return;
185
+ const errno = native.errno();
186
+ throw new AtomicRenameError(syscall, errnoCode(errno), errno, from, to);
187
+ }
188
+ function exchangeWith(support, a, b) {
189
+ const native = loadNative().calls;
190
+ if (support.exchange === "unavailable" || !native) {
191
+ throw new AtomicRenameError("exchange", "ENOSYS", import_node_os.default.constants.errno.ENOSYS, a, b);
192
+ }
193
+ call(native, support.exchange, a, b, native.exchangeFlag);
194
+ }
195
+ function renameNoReplaceWith(support, from, to) {
196
+ const native = loadNative().calls;
197
+ if (support.noReplace !== "link" && native) {
198
+ call(native, support.noReplace, from, to, native.noReplaceFlag);
199
+ return;
200
+ }
201
+ const source = import_node_fs.default.lstatSync(from);
202
+ if (!source.isFile()) throw new AtomicRenameError("link", "ENOTSUP", import_node_os.default.constants.errno.ENOTSUP, from, to);
203
+ try {
204
+ import_node_fs.default.linkSync(from, to);
205
+ } catch (error) {
206
+ const code = error.code ?? "EIO";
207
+ throw new AtomicRenameError("link", code, error.errno ?? 0, from, to);
208
+ }
209
+ import_node_fs.default.unlinkSync(from);
210
+ }
211
+ function exchangePaths(a, b) {
212
+ exchangeWith(atomicRenameSupport(), a, b);
213
+ }
214
+ function renameNoReplace(from, to) {
215
+ renameNoReplaceWith(atomicRenameSupport(), from, to);
216
+ }
217
+ const probes = /* @__PURE__ */ new Map();
218
+ function withoutTemporaries(directory, run) {
219
+ const token = (0, import_node_crypto.randomUUID)();
220
+ const a = import_node_path.default.join(directory, `${PROBE_PREFIX}${token}-a`);
221
+ const b = import_node_path.default.join(directory, `${PROBE_PREFIX}${token}-b`);
222
+ try {
223
+ run(a, b);
224
+ } finally {
225
+ import_node_fs.default.rmSync(a, { force: true });
226
+ import_node_fs.default.rmSync(b, { force: true });
227
+ }
228
+ }
229
+ function createProbeFile(filePath, content) {
230
+ const descriptor = import_node_fs.default.openSync(filePath, import_node_fs.default.constants.O_WRONLY | import_node_fs.default.constants.O_CREAT | import_node_fs.default.constants.O_EXCL, 384);
231
+ try {
232
+ import_node_fs.default.writeSync(descriptor, content);
233
+ return import_node_fs.default.fstatSync(descriptor);
234
+ } finally {
235
+ import_node_fs.default.closeSync(descriptor);
236
+ }
237
+ }
238
+ function probeAtomicRenameSupport(directory) {
239
+ const native = atomicRenameSupport();
240
+ const dev = import_node_fs.default.lstatSync(directory).dev;
241
+ const cached = probes.get(dev);
242
+ if (cached) return applyOverride({ ...cached });
243
+ const probed = { ...native };
244
+ if (native.exchange !== "unavailable") {
245
+ withoutTemporaries(directory, (a, b) => {
246
+ const statA = createProbeFile(a, "a");
247
+ const statB = createProbeFile(b, "b");
248
+ let swapped = false;
249
+ let detail;
250
+ try {
251
+ exchangeWith(native, a, b);
252
+ const afterA = import_node_fs.default.lstatSync(a);
253
+ const afterB = import_node_fs.default.lstatSync(b);
254
+ swapped = afterA.ino === statB.ino && afterB.ino === statA.ino;
255
+ if (!swapped) detail = `exchange flag ignored by the filesystem holding ${directory}`;
256
+ } catch (error) {
257
+ detail = `exchange rejected by the filesystem holding ${directory}: ${error instanceof Error ? error.message : String(error)}`;
258
+ }
259
+ if (!swapped) {
260
+ probed.exchange = "unavailable";
261
+ probed.detail = detail;
262
+ }
263
+ });
264
+ }
265
+ if (native.noReplace !== "link") {
266
+ withoutTemporaries(directory, (a, b) => {
267
+ createProbeFile(a, "a");
268
+ createProbeFile(b, "b");
269
+ let refused = false;
270
+ try {
271
+ renameNoReplaceWith(native, a, b);
272
+ } catch (error) {
273
+ refused = error instanceof AtomicRenameError && error.code === "EEXIST";
274
+ }
275
+ if (!refused) {
276
+ probed.noReplace = "link";
277
+ probed.detail = `${probed.detail ? `${probed.detail}; ` : ""}no-replace flag ignored by the filesystem holding ${directory}`;
278
+ }
279
+ });
280
+ }
281
+ probes.set(dev, probed);
282
+ return applyOverride({ ...probed });
283
+ }
284
+ function atomicRenamePrimitivesFor(directory) {
285
+ const support = probeAtomicRenameSupport(directory);
286
+ return {
287
+ support,
288
+ exchange: (a, b) => exchangeWith(support, a, b),
289
+ renameNoReplace: (from, to) => renameNoReplaceWith(support, from, to)
290
+ };
291
+ }
292
+ // Annotate the CommonJS export names for ESM import in node:
293
+ 0 && (module.exports = {
294
+ AtomicRenameError,
295
+ atomicRenamePrimitivesFor,
296
+ atomicRenameSupport,
297
+ exchangePaths,
298
+ isAtomicRenameUnsupported,
299
+ overrideAtomicRenameSupportForTests,
300
+ probeAtomicRenameSupport,
301
+ renameNoReplace,
302
+ resetAtomicRenameProbesForTests
303
+ });
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var git_blob_hash_exports = {};
20
+ __export(git_blob_hash_exports, {
21
+ gitBlobHash: () => gitBlobHash,
22
+ gitObjectHashAlgorithmFor: () => gitObjectHashAlgorithmFor
23
+ });
24
+ module.exports = __toCommonJS(git_blob_hash_exports);
25
+ var import_node_crypto = require("node:crypto");
26
+ function gitObjectHashAlgorithmFor(objectId) {
27
+ if (/^[0-9a-f]{40}$/u.test(objectId)) return "sha1";
28
+ if (/^[0-9a-f]{64}$/u.test(objectId)) return "sha256";
29
+ return null;
30
+ }
31
+ function gitBlobHash(content, algorithm) {
32
+ const hash = (0, import_node_crypto.createHash)(algorithm);
33
+ hash.update(`blob ${content.length}\0`);
34
+ hash.update(content);
35
+ return hash.digest("hex");
36
+ }
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ gitBlobHash,
40
+ gitObjectHashAlgorithmFor
41
+ });