@ricsam/r5d-worker 0.0.123 → 0.0.124

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 (60) hide show
  1. package/dist/cjs/main.cjs +488 -238
  2. package/dist/cjs/package.json +1 -1
  3. package/dist/cjs/project-checkout-garbage.cjs +32 -3
  4. package/dist/cjs/project-workspace-state.cjs +51 -35
  5. package/dist/cjs/project-worktrees.cjs +79 -34
  6. package/dist/cjs/recovery-journal-protocol.cjs +56 -0
  7. package/dist/cjs/recovery-journal-runtime.cjs +133 -0
  8. package/dist/cjs/recovery-journal-thread.cjs +9 -0
  9. package/dist/cjs/recovery-journal.cjs +735 -0
  10. package/dist/cjs/recovery-store.cjs +8 -0
  11. package/dist/cjs/session-file-mutations.cjs +61 -0
  12. package/dist/cjs/working-tree-mirror.cjs +1 -0
  13. package/dist/cjs/workspace-command-sync-policy.cjs +37 -8
  14. package/dist/cjs/workspace-filesystem-executor-thread.cjs +36 -0
  15. package/dist/cjs/workspace-filesystem-executor.cjs +327 -0
  16. package/dist/cjs/workspace-filesystem-job-types.cjs +134 -0
  17. package/dist/cjs/workspace-filesystem-jobs.cjs +57 -0
  18. package/dist/cjs/workspace-git-sync.cjs +275 -201
  19. package/dist/cjs/workspace-mount-hold-fence.cjs +120 -0
  20. package/dist/mjs/main.mjs +491 -244
  21. package/dist/mjs/package.json +1 -1
  22. package/dist/mjs/project-checkout-garbage.mjs +30 -2
  23. package/dist/mjs/project-workspace-state.mjs +51 -35
  24. package/dist/mjs/project-worktrees.mjs +74 -34
  25. package/dist/mjs/recovery-journal-protocol.mjs +30 -0
  26. package/dist/mjs/recovery-journal-runtime.mjs +112 -0
  27. package/dist/mjs/recovery-journal-thread.mjs +8 -0
  28. package/dist/mjs/recovery-journal.mjs +687 -0
  29. package/dist/mjs/recovery-store.mjs +8 -0
  30. package/dist/mjs/session-file-mutations.mjs +37 -0
  31. package/dist/mjs/working-tree-mirror.mjs +1 -0
  32. package/dist/mjs/workspace-command-sync-policy.mjs +37 -8
  33. package/dist/mjs/workspace-filesystem-executor-thread.mjs +38 -0
  34. package/dist/mjs/workspace-filesystem-executor.mjs +287 -0
  35. package/dist/mjs/workspace-filesystem-job-types.mjs +106 -0
  36. package/dist/mjs/workspace-filesystem-jobs.mjs +51 -0
  37. package/dist/mjs/workspace-git-sync.mjs +264 -202
  38. package/dist/mjs/workspace-mount-hold-fence.mjs +95 -0
  39. package/dist/types/main.d.ts +24 -19
  40. package/dist/types/project-checkout-garbage.d.ts +19 -2
  41. package/dist/types/project-workspace-state.d.ts +9 -9
  42. package/dist/types/project-worktrees.d.ts +49 -5
  43. package/dist/types/recovery-journal-protocol.d.ts +35 -0
  44. package/dist/types/recovery-journal-runtime.d.ts +12 -0
  45. package/dist/types/recovery-journal-stall-fixture.d.ts +1 -0
  46. package/dist/types/recovery-journal-thread.d.ts +1 -0
  47. package/dist/types/recovery-journal.d.ts +246 -0
  48. package/dist/types/recovery-store.d.ts +6 -0
  49. package/dist/types/session-file-mutations.d.ts +22 -0
  50. package/dist/types/workspace-command-sync-policy.d.ts +22 -7
  51. package/dist/types/workspace-filesystem-executor-thread.d.ts +1 -0
  52. package/dist/types/workspace-filesystem-executor.d.ts +123 -0
  53. package/dist/types/workspace-filesystem-job-types.d.ts +246 -0
  54. package/dist/types/workspace-filesystem-jobs.d.ts +7 -0
  55. package/dist/types/workspace-git-sync.d.ts +113 -7
  56. package/dist/types/workspace-mount-hold-fence.d.ts +42 -0
  57. package/package.json +1 -1
  58. package/dist/cjs/project-snapshot-recovery-runner.cjs +0 -171
  59. package/dist/mjs/project-snapshot-recovery-runner.mjs +0 -135
  60. package/dist/types/project-snapshot-recovery-runner.d.ts +0 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.123",
3
+ "version": "0.0.124",
4
4
  "type": "module",
5
5
  "main": "./dist/cjs/main.cjs",
6
6
  "module": "./dist/mjs/main.mjs",
@@ -1,171 +0,0 @@
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 project_snapshot_recovery_runner_exports = {};
30
- __export(project_snapshot_recovery_runner_exports, {
31
- PROJECT_SNAPSHOT_RECOVERY_HELPER_COMMAND: () => PROJECT_SNAPSHOT_RECOVERY_HELPER_COMMAND,
32
- recoverProjectSnapshotsInChild: () => recoverProjectSnapshotsInChild,
33
- runProjectSnapshotRecoveryHelper: () => runProjectSnapshotRecoveryHelper
34
- });
35
- module.exports = __toCommonJS(project_snapshot_recovery_runner_exports);
36
- var import_node_path = __toESM(require("node:path"), 1);
37
- var import_node_child_process = require("node:child_process");
38
- var import_project_worktrees = require("./project-worktrees.cjs");
39
- const PROJECT_SNAPSHOT_RECOVERY_HELPER_COMMAND = "__recover-project-snapshots";
40
- function requireAbsolutePath(value, label) {
41
- if (!value) throw new Error(`Missing ${label}`);
42
- const resolved = import_node_path.default.resolve(value);
43
- if (resolved !== value) throw new Error(`${label} must be an absolute path`);
44
- return resolved;
45
- }
46
- function parseHelperArguments(args) {
47
- let projectsRoot;
48
- let snapshotRoot;
49
- for (let index = 0; index < args.length; index += 1) {
50
- const argument = args[index];
51
- if (argument === "--projects-root") {
52
- projectsRoot = args[index + 1];
53
- index += 1;
54
- continue;
55
- }
56
- if (argument === "--snapshot-root") {
57
- snapshotRoot = args[index + 1];
58
- index += 1;
59
- continue;
60
- }
61
- throw new Error(`Unknown project snapshot recovery helper argument: ${argument ?? "(missing)"}`);
62
- }
63
- return {
64
- projectsRoot: requireAbsolutePath(projectsRoot, "projects root"),
65
- snapshotRoot: requireAbsolutePath(snapshotRoot, "snapshot root")
66
- };
67
- }
68
- function writeHelperMessage(message) {
69
- process.stdout.write(`${JSON.stringify(message)}
70
- `);
71
- }
72
- function runProjectSnapshotRecoveryHelper(args) {
73
- const { projectsRoot, snapshotRoot } = parseHelperArguments(args);
74
- const result = (0, import_project_worktrees.recoverStaleProjectWorktreeSnapshots)({
75
- projectsRoot,
76
- temporaryRoot: snapshotRoot,
77
- onProgress: (progress) => writeHelperMessage({ type: "progress", progress })
78
- });
79
- writeHelperMessage({ type: "result", result });
80
- return result.failed.length === 0 ? 0 : 1;
81
- }
82
- function isRecoveryProgress(value) {
83
- if (!value || typeof value !== "object") return false;
84
- const progress = value;
85
- return progress.operation === "restore" && (progress.phase === "scanning" || progress.phase === "copying" || progress.phase === "moving" || progress.phase === "syncing" || progress.phase === "cleaning") && typeof progress.projectRoot === "string" && Number.isSafeInteger(progress.completedBranches) && Number.isSafeInteger(progress.totalBranches) && typeof progress.completedBytes === "number" && Number.isFinite(progress.completedBytes) && (progress.totalBytes === void 0 || typeof progress.totalBytes === "number" && Number.isFinite(progress.totalBytes));
86
- }
87
- function isRecoveryResult(value) {
88
- if (!value || typeof value !== "object") return false;
89
- const result = value;
90
- return Array.isArray(result.restored) && Array.isArray(result.removed) && Array.isArray(result.failed);
91
- }
92
- function recoveryChildEnvironment() {
93
- const environment = {};
94
- for (const name of ["PATH", "TMPDIR", "TMP", "TEMP", "SystemRoot", "WINDIR"]) {
95
- const value = process.env[name];
96
- if (value !== void 0) environment[name] = value;
97
- }
98
- return environment;
99
- }
100
- async function recoverProjectSnapshotsInChild(input) {
101
- const entrypoint = process.argv[1];
102
- if (!entrypoint) throw new Error("Cannot locate the r5d-worker runtime entrypoint for snapshot recovery");
103
- const child = (0, import_node_child_process.spawn)(
104
- process.execPath,
105
- [
106
- entrypoint,
107
- PROJECT_SNAPSHOT_RECOVERY_HELPER_COMMAND,
108
- "--projects-root",
109
- import_node_path.default.resolve(input.projectsRoot),
110
- "--snapshot-root",
111
- import_node_path.default.resolve(input.snapshotRoot)
112
- ],
113
- {
114
- env: recoveryChildEnvironment(),
115
- stdio: ["ignore", "pipe", "pipe"]
116
- }
117
- );
118
- const terminateOnParentExit = () => {
119
- if (child.exitCode === null && child.signalCode === null) child.kill("SIGTERM");
120
- };
121
- const parentProcessEvents = process;
122
- parentProcessEvents.once("exit", terminateOnParentExit);
123
- let stdout = "";
124
- let stderr = "";
125
- let result;
126
- child.stdout.setEncoding("utf8");
127
- child.stdout.on("data", (chunk) => {
128
- stdout += chunk;
129
- while (true) {
130
- const newline = stdout.indexOf("\n");
131
- if (newline < 0) break;
132
- const line = stdout.slice(0, newline);
133
- stdout = stdout.slice(newline + 1);
134
- if (!line.trim()) continue;
135
- let message;
136
- try {
137
- message = JSON.parse(line);
138
- } catch {
139
- stderr += `Invalid recovery helper output: ${line}
140
- `;
141
- continue;
142
- }
143
- if (!message || typeof message !== "object") continue;
144
- const record = message;
145
- if (record.type === "progress" && isRecoveryProgress(record.progress)) input.onProgress?.(record.progress);
146
- if (record.type === "result" && isRecoveryResult(record.result)) result = record.result;
147
- }
148
- });
149
- child.stderr.setEncoding("utf8");
150
- child.stderr.on("data", (chunk) => {
151
- stderr = `${stderr}${chunk}`.slice(-32768);
152
- });
153
- const exitCode = await new Promise((resolve, reject) => {
154
- child.once("error", reject);
155
- child.once("close", (code, signal) => {
156
- if (signal) reject(new Error(`Project snapshot recovery helper exited on signal ${signal}`));
157
- else resolve(code ?? 1);
158
- });
159
- }).finally(() => parentProcessEvents.off("exit", terminateOnParentExit));
160
- if (exitCode !== 0 || !result) {
161
- const detail = stderr.trim();
162
- throw new Error(detail || `Project snapshot recovery helper exited with status ${exitCode}`);
163
- }
164
- return result;
165
- }
166
- // Annotate the CommonJS export names for ESM import in node:
167
- 0 && (module.exports = {
168
- PROJECT_SNAPSHOT_RECOVERY_HELPER_COMMAND,
169
- recoverProjectSnapshotsInChild,
170
- runProjectSnapshotRecoveryHelper
171
- });
@@ -1,135 +0,0 @@
1
- import path from "node:path";
2
- import { spawn } from "node:child_process";
3
- import { recoverStaleProjectWorktreeSnapshots } from "./project-worktrees.mjs";
4
- const PROJECT_SNAPSHOT_RECOVERY_HELPER_COMMAND = "__recover-project-snapshots";
5
- function requireAbsolutePath(value, label) {
6
- if (!value) throw new Error(`Missing ${label}`);
7
- const resolved = path.resolve(value);
8
- if (resolved !== value) throw new Error(`${label} must be an absolute path`);
9
- return resolved;
10
- }
11
- function parseHelperArguments(args) {
12
- let projectsRoot;
13
- let snapshotRoot;
14
- for (let index = 0; index < args.length; index += 1) {
15
- const argument = args[index];
16
- if (argument === "--projects-root") {
17
- projectsRoot = args[index + 1];
18
- index += 1;
19
- continue;
20
- }
21
- if (argument === "--snapshot-root") {
22
- snapshotRoot = args[index + 1];
23
- index += 1;
24
- continue;
25
- }
26
- throw new Error(`Unknown project snapshot recovery helper argument: ${argument ?? "(missing)"}`);
27
- }
28
- return {
29
- projectsRoot: requireAbsolutePath(projectsRoot, "projects root"),
30
- snapshotRoot: requireAbsolutePath(snapshotRoot, "snapshot root")
31
- };
32
- }
33
- function writeHelperMessage(message) {
34
- process.stdout.write(`${JSON.stringify(message)}
35
- `);
36
- }
37
- function runProjectSnapshotRecoveryHelper(args) {
38
- const { projectsRoot, snapshotRoot } = parseHelperArguments(args);
39
- const result = recoverStaleProjectWorktreeSnapshots({
40
- projectsRoot,
41
- temporaryRoot: snapshotRoot,
42
- onProgress: (progress) => writeHelperMessage({ type: "progress", progress })
43
- });
44
- writeHelperMessage({ type: "result", result });
45
- return result.failed.length === 0 ? 0 : 1;
46
- }
47
- function isRecoveryProgress(value) {
48
- if (!value || typeof value !== "object") return false;
49
- const progress = value;
50
- return progress.operation === "restore" && (progress.phase === "scanning" || progress.phase === "copying" || progress.phase === "moving" || progress.phase === "syncing" || progress.phase === "cleaning") && typeof progress.projectRoot === "string" && Number.isSafeInteger(progress.completedBranches) && Number.isSafeInteger(progress.totalBranches) && typeof progress.completedBytes === "number" && Number.isFinite(progress.completedBytes) && (progress.totalBytes === void 0 || typeof progress.totalBytes === "number" && Number.isFinite(progress.totalBytes));
51
- }
52
- function isRecoveryResult(value) {
53
- if (!value || typeof value !== "object") return false;
54
- const result = value;
55
- return Array.isArray(result.restored) && Array.isArray(result.removed) && Array.isArray(result.failed);
56
- }
57
- function recoveryChildEnvironment() {
58
- const environment = {};
59
- for (const name of ["PATH", "TMPDIR", "TMP", "TEMP", "SystemRoot", "WINDIR"]) {
60
- const value = process.env[name];
61
- if (value !== void 0) environment[name] = value;
62
- }
63
- return environment;
64
- }
65
- async function recoverProjectSnapshotsInChild(input) {
66
- const entrypoint = process.argv[1];
67
- if (!entrypoint) throw new Error("Cannot locate the r5d-worker runtime entrypoint for snapshot recovery");
68
- const child = spawn(
69
- process.execPath,
70
- [
71
- entrypoint,
72
- PROJECT_SNAPSHOT_RECOVERY_HELPER_COMMAND,
73
- "--projects-root",
74
- path.resolve(input.projectsRoot),
75
- "--snapshot-root",
76
- path.resolve(input.snapshotRoot)
77
- ],
78
- {
79
- env: recoveryChildEnvironment(),
80
- stdio: ["ignore", "pipe", "pipe"]
81
- }
82
- );
83
- const terminateOnParentExit = () => {
84
- if (child.exitCode === null && child.signalCode === null) child.kill("SIGTERM");
85
- };
86
- const parentProcessEvents = process;
87
- parentProcessEvents.once("exit", terminateOnParentExit);
88
- let stdout = "";
89
- let stderr = "";
90
- let result;
91
- child.stdout.setEncoding("utf8");
92
- child.stdout.on("data", (chunk) => {
93
- stdout += chunk;
94
- while (true) {
95
- const newline = stdout.indexOf("\n");
96
- if (newline < 0) break;
97
- const line = stdout.slice(0, newline);
98
- stdout = stdout.slice(newline + 1);
99
- if (!line.trim()) continue;
100
- let message;
101
- try {
102
- message = JSON.parse(line);
103
- } catch {
104
- stderr += `Invalid recovery helper output: ${line}
105
- `;
106
- continue;
107
- }
108
- if (!message || typeof message !== "object") continue;
109
- const record = message;
110
- if (record.type === "progress" && isRecoveryProgress(record.progress)) input.onProgress?.(record.progress);
111
- if (record.type === "result" && isRecoveryResult(record.result)) result = record.result;
112
- }
113
- });
114
- child.stderr.setEncoding("utf8");
115
- child.stderr.on("data", (chunk) => {
116
- stderr = `${stderr}${chunk}`.slice(-32768);
117
- });
118
- const exitCode = await new Promise((resolve, reject) => {
119
- child.once("error", reject);
120
- child.once("close", (code, signal) => {
121
- if (signal) reject(new Error(`Project snapshot recovery helper exited on signal ${signal}`));
122
- else resolve(code ?? 1);
123
- });
124
- }).finally(() => parentProcessEvents.off("exit", terminateOnParentExit));
125
- if (exitCode !== 0 || !result) {
126
- const detail = stderr.trim();
127
- throw new Error(detail || `Project snapshot recovery helper exited with status ${exitCode}`);
128
- }
129
- return result;
130
- }
131
- export {
132
- PROJECT_SNAPSHOT_RECOVERY_HELPER_COMMAND,
133
- recoverProjectSnapshotsInChild,
134
- runProjectSnapshotRecoveryHelper
135
- };
@@ -1,10 +0,0 @@
1
- import { recoverStaleProjectWorktreeSnapshots, type ProjectWorktreeSnapshotProgress } from "./project-worktrees";
2
- export declare const PROJECT_SNAPSHOT_RECOVERY_HELPER_COMMAND = "__recover-project-snapshots";
3
- type ProjectSnapshotRecoveryResult = ReturnType<typeof recoverStaleProjectWorktreeSnapshots>;
4
- export declare function runProjectSnapshotRecoveryHelper(args: readonly string[]): number;
5
- export declare function recoverProjectSnapshotsInChild(input: {
6
- projectsRoot: string;
7
- snapshotRoot: string;
8
- onProgress?: (progress: ProjectWorktreeSnapshotProgress) => void;
9
- }): Promise<ProjectSnapshotRecoveryResult>;
10
- export {};