@ricsam/r5d-worker 0.0.74 → 0.0.76
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/README.md +6 -4
- package/dist/cjs/main.cjs +1031 -976
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/project-workspace-state.cjs +777 -0
- package/dist/cjs/project-worktrees.cjs +559 -0
- package/dist/cjs/working-tree-mirror.cjs +225 -0
- package/dist/cjs/workspace-git-sync.cjs +565 -0
- package/dist/cjs/workspace-incident-state.cjs +2 -38
- package/dist/mjs/main.mjs +1048 -987
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/project-workspace-state.mjs +745 -0
- package/dist/mjs/project-worktrees.mjs +513 -0
- package/dist/mjs/working-tree-mirror.mjs +190 -0
- package/dist/mjs/workspace-git-sync.mjs +524 -0
- package/dist/mjs/workspace-incident-state.mjs +1 -35
- package/dist/types/main.d.ts +35 -55
- package/dist/types/project-workspace-state.d.ts +144 -0
- package/dist/types/project-worktrees.d.ts +112 -0
- package/dist/types/working-tree-mirror.d.ts +24 -0
- package/dist/types/workspace-git-sync.d.ts +97 -0
- package/dist/types/workspace-incident-state.d.ts +0 -17
- package/dist/types/workspace-mutation-gate.d.ts +3 -3
- package/package.json +1 -1
- package/dist/cjs/workspace-convergence.cjs +0 -280
- package/dist/cjs/workspace-manifest-admission.cjs +0 -60
- package/dist/cjs/workspace-sync.cjs +0 -2469
- package/dist/mjs/workspace-convergence.mjs +0 -236
- package/dist/mjs/workspace-manifest-admission.mjs +0 -26
- package/dist/mjs/workspace-sync.mjs +0 -2417
- package/dist/types/workspace-convergence.d.ts +0 -93
- package/dist/types/workspace-manifest-admission.d.ts +0 -22
- package/dist/types/workspace-sync.d.ts +0 -167
|
@@ -0,0 +1,225 @@
|
|
|
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 working_tree_mirror_exports = {};
|
|
30
|
+
__export(working_tree_mirror_exports, {
|
|
31
|
+
inspectWorkingTree: () => inspectWorkingTree,
|
|
32
|
+
mirrorWorkingTree: () => mirrorWorkingTree
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(working_tree_mirror_exports);
|
|
35
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
36
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
37
|
+
function isGitMetadataPath(relativePath) {
|
|
38
|
+
return relativePath.split("/").includes(".git");
|
|
39
|
+
}
|
|
40
|
+
function normalizeRelativePath(value) {
|
|
41
|
+
const normalized = value.split(import_node_path.default.sep).join(import_node_path.default.posix.sep).replace(/^\.\/+/, "").replace(/^\/+|\/+$/g, "");
|
|
42
|
+
if (!normalized || normalized === "." || normalized.split("/").includes("..") || isGitMetadataPath(normalized)) return null;
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
function assertInside(root, candidate) {
|
|
46
|
+
const relative = import_node_path.default.relative(import_node_path.default.resolve(root), import_node_path.default.resolve(candidate));
|
|
47
|
+
if (relative === ".." || relative.startsWith(`..${import_node_path.default.sep}`) || import_node_path.default.isAbsolute(relative)) {
|
|
48
|
+
throw new Error(`Working-tree path escapes its root: ${candidate}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function gitEligibleRoots(root) {
|
|
52
|
+
const result = Bun.spawnSync(
|
|
53
|
+
[
|
|
54
|
+
"git",
|
|
55
|
+
"-c",
|
|
56
|
+
"submodule.recurse=false",
|
|
57
|
+
"-c",
|
|
58
|
+
"fetch.recurseSubmodules=false",
|
|
59
|
+
"-c",
|
|
60
|
+
"push.recurseSubmodules=false",
|
|
61
|
+
"ls-files",
|
|
62
|
+
"-z",
|
|
63
|
+
"--cached",
|
|
64
|
+
"--others",
|
|
65
|
+
"--exclude-standard",
|
|
66
|
+
"--",
|
|
67
|
+
"."
|
|
68
|
+
],
|
|
69
|
+
{
|
|
70
|
+
cwd: root,
|
|
71
|
+
stdout: "pipe",
|
|
72
|
+
stderr: "pipe",
|
|
73
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
if (result.exitCode !== 0) {
|
|
77
|
+
throw new Error(`Inspect Git working tree: ${result.stderr.toString().trim() || `git exited ${result.exitCode}`}`);
|
|
78
|
+
}
|
|
79
|
+
return result.stdout.toString().split("\0").flatMap((entry) => {
|
|
80
|
+
const normalized = normalizeRelativePath(entry);
|
|
81
|
+
return normalized ? [normalized] : [];
|
|
82
|
+
}).sort();
|
|
83
|
+
}
|
|
84
|
+
function addEntry(entries, root, relativePath, recurseDirectories) {
|
|
85
|
+
const normalized = normalizeRelativePath(relativePath);
|
|
86
|
+
if (!normalized || entries.has(normalized)) return;
|
|
87
|
+
const absolutePath = import_node_path.default.join(root, ...normalized.split("/"));
|
|
88
|
+
assertInside(root, absolutePath);
|
|
89
|
+
let stat;
|
|
90
|
+
try {
|
|
91
|
+
stat = import_node_fs.default.lstatSync(absolutePath);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (error.code === "ENOENT") return;
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
if (stat.isSymbolicLink()) {
|
|
97
|
+
entries.set(normalized, { kind: "symlink", mode: stat.mode, target: import_node_fs.default.readlinkSync(absolutePath) });
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (stat.isFile()) {
|
|
101
|
+
entries.set(normalized, { kind: "file", mode: stat.mode, size: stat.size });
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!stat.isDirectory()) return;
|
|
105
|
+
entries.set(normalized, { kind: "directory", mode: stat.mode });
|
|
106
|
+
if (!recurseDirectories) return;
|
|
107
|
+
for (const child of import_node_fs.default.readdirSync(absolutePath).sort()) {
|
|
108
|
+
addEntry(entries, root, import_node_path.default.posix.join(normalized, child), true);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function addParentDirectories(entries, root) {
|
|
112
|
+
for (const relativePath of [...entries.keys()]) {
|
|
113
|
+
let parent = import_node_path.default.posix.dirname(relativePath);
|
|
114
|
+
while (parent !== ".") {
|
|
115
|
+
if (!entries.has(parent)) {
|
|
116
|
+
const absolutePath = import_node_path.default.join(root, ...parent.split("/"));
|
|
117
|
+
const stat = import_node_fs.default.lstatSync(absolutePath);
|
|
118
|
+
entries.set(parent, { kind: "directory", mode: stat.mode });
|
|
119
|
+
}
|
|
120
|
+
parent = import_node_path.default.posix.dirname(parent);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function inspectWorkingTree(root, mode) {
|
|
125
|
+
const entries = /* @__PURE__ */ new Map();
|
|
126
|
+
if (!import_node_fs.default.existsSync(root)) return entries;
|
|
127
|
+
if (mode === "all") {
|
|
128
|
+
for (const child of import_node_fs.default.readdirSync(root).sort()) addEntry(entries, root, child, true);
|
|
129
|
+
} else {
|
|
130
|
+
for (const relativePath of gitEligibleRoots(root)) {
|
|
131
|
+
addEntry(entries, root, relativePath, true);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
addParentDirectories(entries, root);
|
|
135
|
+
return entries;
|
|
136
|
+
}
|
|
137
|
+
function removeEntry(targetRoot, relativePath) {
|
|
138
|
+
const targetPath = import_node_path.default.join(targetRoot, ...relativePath.split("/"));
|
|
139
|
+
assertInside(targetRoot, targetPath);
|
|
140
|
+
import_node_fs.default.rmSync(targetPath, { recursive: true, force: true });
|
|
141
|
+
}
|
|
142
|
+
function ensureDirectory(targetRoot, relativePath, mode) {
|
|
143
|
+
const targetPath = import_node_path.default.join(targetRoot, ...relativePath.split("/"));
|
|
144
|
+
assertInside(targetRoot, targetPath);
|
|
145
|
+
if (import_node_fs.default.existsSync(targetPath) && !import_node_fs.default.lstatSync(targetPath).isDirectory()) removeEntry(targetRoot, relativePath);
|
|
146
|
+
import_node_fs.default.mkdirSync(targetPath, { recursive: true, mode: mode & 511 });
|
|
147
|
+
}
|
|
148
|
+
function filesEqual(leftPath, rightPath, size) {
|
|
149
|
+
let rightStat;
|
|
150
|
+
try {
|
|
151
|
+
rightStat = import_node_fs.default.lstatSync(rightPath);
|
|
152
|
+
} catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (!rightStat.isFile() || rightStat.size !== size) return false;
|
|
156
|
+
const left = import_node_fs.default.openSync(leftPath, "r");
|
|
157
|
+
const right = import_node_fs.default.openSync(rightPath, "r");
|
|
158
|
+
const leftBuffer = Buffer.allocUnsafe(64 * 1024);
|
|
159
|
+
const rightBuffer = Buffer.allocUnsafe(64 * 1024);
|
|
160
|
+
try {
|
|
161
|
+
let offset = 0;
|
|
162
|
+
while (offset < size) {
|
|
163
|
+
const length = Math.min(leftBuffer.length, size - offset);
|
|
164
|
+
const leftRead = import_node_fs.default.readSync(left, leftBuffer, 0, length, offset);
|
|
165
|
+
const rightRead = import_node_fs.default.readSync(right, rightBuffer, 0, length, offset);
|
|
166
|
+
if (leftRead !== rightRead || !leftBuffer.subarray(0, leftRead).equals(rightBuffer.subarray(0, rightRead))) return false;
|
|
167
|
+
offset += leftRead;
|
|
168
|
+
}
|
|
169
|
+
return true;
|
|
170
|
+
} finally {
|
|
171
|
+
import_node_fs.default.closeSync(left);
|
|
172
|
+
import_node_fs.default.closeSync(right);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function copyEntry(sourceRoot, targetRoot, relativePath, entry) {
|
|
176
|
+
const sourcePath = import_node_path.default.join(sourceRoot, ...relativePath.split("/"));
|
|
177
|
+
const targetPath = import_node_path.default.join(targetRoot, ...relativePath.split("/"));
|
|
178
|
+
assertInside(sourceRoot, sourcePath);
|
|
179
|
+
assertInside(targetRoot, targetPath);
|
|
180
|
+
const parent = import_node_path.default.posix.dirname(relativePath);
|
|
181
|
+
if (parent !== ".") ensureDirectory(targetRoot, parent, 493);
|
|
182
|
+
if (entry.kind === "directory") {
|
|
183
|
+
ensureDirectory(targetRoot, relativePath, entry.mode);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (entry.kind === "symlink") {
|
|
187
|
+
let unchanged = false;
|
|
188
|
+
try {
|
|
189
|
+
unchanged = import_node_fs.default.lstatSync(targetPath).isSymbolicLink() && import_node_fs.default.readlinkSync(targetPath) === entry.target;
|
|
190
|
+
} catch {
|
|
191
|
+
unchanged = false;
|
|
192
|
+
}
|
|
193
|
+
if (!unchanged) {
|
|
194
|
+
removeEntry(targetRoot, relativePath);
|
|
195
|
+
import_node_fs.default.symlinkSync(entry.target, targetPath);
|
|
196
|
+
}
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (!filesEqual(sourcePath, targetPath, entry.size)) {
|
|
200
|
+
if (import_node_fs.default.existsSync(targetPath) && !import_node_fs.default.lstatSync(targetPath).isFile()) removeEntry(targetRoot, relativePath);
|
|
201
|
+
import_node_fs.default.copyFileSync(sourcePath, targetPath);
|
|
202
|
+
}
|
|
203
|
+
import_node_fs.default.chmodSync(targetPath, entry.mode & 511);
|
|
204
|
+
}
|
|
205
|
+
function mirrorWorkingTree(input) {
|
|
206
|
+
const sourceRoot = import_node_path.default.resolve(input.sourceRoot);
|
|
207
|
+
const targetRoot = import_node_path.default.resolve(input.targetRoot);
|
|
208
|
+
import_node_fs.default.mkdirSync(targetRoot, { recursive: true });
|
|
209
|
+
const desired = inspectWorkingTree(sourceRoot, input.sourceMode);
|
|
210
|
+
const existing = inspectWorkingTree(targetRoot, input.deletionMode === "git" ? "git" : "all");
|
|
211
|
+
for (const relativePath of [...existing.keys()].sort((left, right) => right.split("/").length - left.split("/").length)) {
|
|
212
|
+
if (!desired.has(relativePath)) removeEntry(targetRoot, relativePath);
|
|
213
|
+
}
|
|
214
|
+
for (const [relativePath, entry] of [...desired.entries()].sort(
|
|
215
|
+
([left], [right]) => left.split("/").length - right.split("/").length || left.localeCompare(right)
|
|
216
|
+
)) {
|
|
217
|
+
copyEntry(sourceRoot, targetRoot, relativePath, entry);
|
|
218
|
+
}
|
|
219
|
+
return { paths: [...desired.keys()].filter((relativePath) => desired.get(relativePath)?.kind !== "directory").sort() };
|
|
220
|
+
}
|
|
221
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
222
|
+
0 && (module.exports = {
|
|
223
|
+
inspectWorkingTree,
|
|
224
|
+
mirrorWorkingTree
|
|
225
|
+
});
|