@ricsam/r5d-worker 0.0.137 → 0.0.139
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 +4 -94
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/main.mjs +46 -7543
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/personal/action-scheduler.mjs +31 -0
- package/dist/mjs/personal/client.mjs +215 -0
- package/dist/mjs/personal/runtime.mjs +359 -0
- package/dist/mjs/personal/tcp.mjs +217 -0
- package/dist/mjs/runtime/adapter.mjs +42 -0
- package/dist/mjs/runtime/client.mjs +95 -0
- package/dist/mjs/runtime/daemon.mjs +131 -0
- package/dist/mjs/runtime/executor.mjs +436 -0
- package/dist/mjs/runtime/index.mjs +15 -0
- package/dist/mjs/runtime/protocol.mjs +139 -0
- package/dist/mjs/runtime/pty-host.mjs +156 -0
- package/dist/mjs/runtime/pty.mjs +127 -0
- package/dist/mjs/runtime/releases/artifacts.mjs +201 -0
- package/dist/mjs/runtime/releases/grants.mjs +93 -0
- package/dist/mjs/runtime/releases/main.mjs +101 -0
- package/dist/mjs/runtime/releases/manager.mjs +541 -0
- package/dist/mjs/runtime/releases/process.mjs +88 -0
- package/dist/mjs/runtime/releases/retirement.mjs +18 -0
- package/dist/mjs/runtime/releases/rpc-client.mjs +184 -0
- package/dist/mjs/runtime/releases/rpc-main.mjs +213 -0
- package/dist/mjs/runtime/releases/rpc-protocol.mjs +103 -0
- package/dist/mjs/runtime/storage.mjs +156 -0
- package/dist/mjs/runtime/workspace/artifacts.mjs +121 -0
- package/dist/mjs/runtime/workspace/authority.mjs +1355 -0
- package/dist/mjs/runtime/workspace/contracts.mjs +60 -0
- package/dist/mjs/runtime/workspace/file-write.mjs +23 -0
- package/dist/mjs/runtime/workspace/files.mjs +308 -0
- package/dist/mjs/runtime/workspace/http-body.mjs +45 -0
- package/dist/mjs/runtime/workspace/storage-client.mjs +59 -0
- package/dist/mjs/runtime/workspace/storage-wire.mjs +53 -0
- package/dist/types/main.d.ts +0 -1167
- package/dist/types/personal/action-scheduler.d.ts +23 -0
- package/dist/types/personal/client.d.ts +14 -0
- package/dist/types/personal/runtime.d.ts +121 -0
- package/dist/types/personal/tcp.d.ts +14 -0
- package/dist/types/runtime/client.d.ts +3 -1
- package/dist/types/runtime/executor.d.ts +6 -1
- package/dist/types/runtime/protocol.d.ts +176 -4
- package/dist/types/runtime/pty.d.ts +1 -0
- package/dist/types/runtime/releases/artifacts.d.ts +51 -0
- package/dist/types/runtime/releases/grants.d.ts +16 -0
- package/dist/types/runtime/releases/manager.d.ts +145 -0
- package/dist/types/runtime/releases/process.d.ts +14 -0
- package/dist/types/runtime/releases/retirement.d.ts +15 -0
- package/dist/types/runtime/releases/rpc-client.d.ts +52 -0
- package/dist/types/runtime/releases/rpc-main.d.ts +10 -0
- package/dist/types/runtime/releases/rpc-protocol.d.ts +1139 -0
- package/dist/types/runtime/workspace/artifacts.d.ts +30 -0
- package/dist/types/runtime/workspace/authority.d.ts +338 -0
- package/dist/types/runtime/workspace/contracts.d.ts +86 -0
- package/dist/types/runtime/workspace/file-write.d.ts +14 -0
- package/dist/types/runtime/workspace/files.d.ts +21 -0
- package/dist/types/runtime/workspace/http-body.d.ts +9 -0
- package/dist/types/runtime/workspace/storage-client.d.ts +23 -0
- package/dist/types/runtime/workspace/storage-wire.d.ts +138 -0
- package/package.json +8 -6
- package/dist/cjs/atomic-rename.cjs +0 -303
- package/dist/cjs/browser-upload.cjs +0 -73
- package/dist/cjs/cli-update.cjs +0 -108
- package/dist/cjs/command-launcher.cjs +0 -423
- package/dist/cjs/control-command-policy.cjs +0 -177
- package/dist/cjs/git-blob-hash.cjs +0 -41
- package/dist/cjs/git-identity.cjs +0 -39
- package/dist/cjs/git-process-environment.cjs +0 -133
- package/dist/cjs/inline-output.cjs +0 -62
- package/dist/cjs/main.cjs +0 -7517
- package/dist/cjs/managed-paths.cjs +0 -215
- package/dist/cjs/plan-lint.cjs +0 -165
- package/dist/cjs/plan-parser.cjs +0 -127
- package/dist/cjs/plan-paths.cjs +0 -53
- package/dist/cjs/port-forward-client.cjs +0 -206
- package/dist/cjs/process-tree.cjs +0 -117
- package/dist/cjs/project-checkout-garbage.cjs +0 -219
- package/dist/cjs/project-mirror-fetch-policy.cjs +0 -82
- package/dist/cjs/project-mirror-refs-token.cjs +0 -85
- package/dist/cjs/project-workspace-state.cjs +0 -972
- package/dist/cjs/project-worktrees.cjs +0 -1713
- package/dist/cjs/pty-output-coalescer.cjs +0 -87
- package/dist/cjs/recovery-journal-protocol.cjs +0 -56
- package/dist/cjs/recovery-journal-runtime.cjs +0 -133
- package/dist/cjs/recovery-journal-thread.cjs +0 -9
- package/dist/cjs/recovery-journal.cjs +0 -742
- package/dist/cjs/recovery-output-window.cjs +0 -77
- package/dist/cjs/recovery-protocol.cjs +0 -31
- package/dist/cjs/recovery-store.cjs +0 -252
- package/dist/cjs/registry-auth.cjs +0 -310
- package/dist/cjs/repository-transition-policy.cjs +0 -49
- package/dist/cjs/runtime-version.cjs +0 -88
- package/dist/cjs/session-file-mutations.cjs +0 -61
- package/dist/cjs/supervisor.cjs +0 -147
- package/dist/cjs/three-way-merge.cjs +0 -346
- package/dist/cjs/working-tree-mirror.cjs +0 -1872
- package/dist/cjs/workspace-automatic-sync-policy.cjs +0 -79
- package/dist/cjs/workspace-branch-incarnation-policy.cjs +0 -37
- package/dist/cjs/workspace-command-sync-policy.cjs +0 -112
- package/dist/cjs/workspace-command-targets.cjs +0 -63
- package/dist/cjs/workspace-filesystem-executor-thread.cjs +0 -36
- package/dist/cjs/workspace-filesystem-executor.cjs +0 -327
- package/dist/cjs/workspace-filesystem-job-types.cjs +0 -144
- package/dist/cjs/workspace-filesystem-jobs.cjs +0 -59
- package/dist/cjs/workspace-git-sync.cjs +0 -3595
- package/dist/cjs/workspace-hydration-ledger.cjs +0 -83
- package/dist/cjs/workspace-hydration-merge.cjs +0 -448
- package/dist/cjs/workspace-hydration-recovery-state.cjs +0 -53
- package/dist/cjs/workspace-incident-state.cjs +0 -37
- package/dist/cjs/workspace-merge-projection.cjs +0 -628
- package/dist/cjs/workspace-mount-boundary.cjs +0 -71
- package/dist/cjs/workspace-mount-hold-fence.cjs +0 -120
- package/dist/cjs/workspace-mutation-gate.cjs +0 -127
- package/dist/cjs/workspace-path-move.cjs +0 -195
- package/dist/cjs/workspace-preserve-only-policy.cjs +0 -36
- package/dist/cjs/workspace-project-config-policy.cjs +0 -53
- package/dist/cjs/workspace-projection-ledger.cjs +0 -81
- package/dist/cjs/workspace-publication-evidence.cjs +0 -46
- package/dist/cjs/workspace-sync-coalescer.cjs +0 -58
- package/dist/mjs/atomic-rename.mjs +0 -261
- package/dist/mjs/browser-upload.mjs +0 -42
- package/dist/mjs/command-launcher.mjs +0 -393
- package/dist/mjs/control-command-policy.mjs +0 -146
- package/dist/mjs/git-blob-hash.mjs +0 -16
- package/dist/mjs/git-identity.mjs +0 -15
- package/dist/mjs/git-process-environment.mjs +0 -105
- package/dist/mjs/inline-output.mjs +0 -37
- package/dist/mjs/managed-paths.mjs +0 -174
- package/dist/mjs/plan-lint.mjs +0 -129
- package/dist/mjs/plan-parser.mjs +0 -94
- package/dist/mjs/plan-paths.mjs +0 -25
- package/dist/mjs/port-forward-client.mjs +0 -172
- package/dist/mjs/project-checkout-garbage.mjs +0 -178
- package/dist/mjs/project-mirror-fetch-policy.mjs +0 -56
- package/dist/mjs/project-mirror-refs-token.mjs +0 -53
- package/dist/mjs/project-workspace-state.mjs +0 -937
- package/dist/mjs/project-worktrees.mjs +0 -1657
- package/dist/mjs/pty-output-coalescer.mjs +0 -61
- package/dist/mjs/recovery-journal-protocol.mjs +0 -30
- package/dist/mjs/recovery-journal-runtime.mjs +0 -112
- package/dist/mjs/recovery-journal-thread.mjs +0 -8
- package/dist/mjs/recovery-journal.mjs +0 -694
- package/dist/mjs/recovery-output-window.mjs +0 -53
- package/dist/mjs/recovery-protocol.mjs +0 -6
- package/dist/mjs/recovery-store.mjs +0 -217
- package/dist/mjs/registry-auth.mjs +0 -269
- package/dist/mjs/repository-transition-policy.mjs +0 -22
- package/dist/mjs/runtime-version.mjs +0 -54
- package/dist/mjs/session-file-mutations.mjs +0 -37
- package/dist/mjs/supervisor.mjs +0 -114
- package/dist/mjs/three-way-merge.mjs +0 -318
- package/dist/mjs/working-tree-mirror.mjs +0 -1817
- package/dist/mjs/workspace-automatic-sync-policy.mjs +0 -48
- package/dist/mjs/workspace-branch-incarnation-policy.mjs +0 -13
- package/dist/mjs/workspace-command-sync-policy.mjs +0 -84
- package/dist/mjs/workspace-command-targets.mjs +0 -37
- package/dist/mjs/workspace-filesystem-executor-thread.mjs +0 -38
- package/dist/mjs/workspace-filesystem-executor.mjs +0 -287
- package/dist/mjs/workspace-filesystem-job-types.mjs +0 -116
- package/dist/mjs/workspace-filesystem-jobs.mjs +0 -55
- package/dist/mjs/workspace-git-sync.mjs +0 -3553
- package/dist/mjs/workspace-hydration-ledger.mjs +0 -58
- package/dist/mjs/workspace-hydration-merge.mjs +0 -414
- package/dist/mjs/workspace-hydration-recovery-state.mjs +0 -29
- package/dist/mjs/workspace-incident-state.mjs +0 -12
- package/dist/mjs/workspace-merge-projection.mjs +0 -594
- package/dist/mjs/workspace-mount-boundary.mjs +0 -37
- package/dist/mjs/workspace-mount-hold-fence.mjs +0 -95
- package/dist/mjs/workspace-mutation-gate.mjs +0 -103
- package/dist/mjs/workspace-path-move.mjs +0 -160
- package/dist/mjs/workspace-preserve-only-policy.mjs +0 -11
- package/dist/mjs/workspace-project-config-policy.mjs +0 -27
- package/dist/mjs/workspace-projection-ledger.mjs +0 -57
- package/dist/mjs/workspace-publication-evidence.mjs +0 -21
- package/dist/mjs/workspace-sync-coalescer.mjs +0 -34
- package/dist/types/atomic-rename.d.ts +0 -78
- package/dist/types/browser-upload.d.ts +0 -7
- package/dist/types/command-launcher.d.ts +0 -104
- package/dist/types/control-command-policy.d.ts +0 -53
- package/dist/types/git-blob-hash.d.ts +0 -10
- package/dist/types/git-identity.d.ts +0 -9
- package/dist/types/git-process-environment.d.ts +0 -9
- package/dist/types/inline-output.d.ts +0 -3
- package/dist/types/managed-paths.d.ts +0 -19
- package/dist/types/plan-lint.d.ts +0 -16
- package/dist/types/plan-parser.d.ts +0 -38
- package/dist/types/plan-paths.d.ts +0 -36
- package/dist/types/port-forward-client.d.ts +0 -8
- package/dist/types/project-checkout-garbage.d.ts +0 -86
- package/dist/types/project-mirror-fetch-policy.d.ts +0 -84
- package/dist/types/project-mirror-refs-token.d.ts +0 -53
- package/dist/types/project-workspace-state.d.ts +0 -188
- package/dist/types/project-worktrees.d.ts +0 -397
- package/dist/types/pty-output-coalescer.d.ts +0 -20
- package/dist/types/recovery-journal-protocol.d.ts +0 -35
- package/dist/types/recovery-journal-runtime.d.ts +0 -12
- package/dist/types/recovery-journal-stall-fixture.d.ts +0 -1
- package/dist/types/recovery-journal-thread.d.ts +0 -1
- package/dist/types/recovery-journal.d.ts +0 -248
- package/dist/types/recovery-output-window.d.ts +0 -19
- package/dist/types/recovery-protocol.d.ts +0 -59
- package/dist/types/recovery-store.d.ts +0 -52
- package/dist/types/registry-auth.d.ts +0 -47
- package/dist/types/repository-transition-policy.d.ts +0 -26
- package/dist/types/runtime-version.d.ts +0 -1
- package/dist/types/session-file-mutations.d.ts +0 -22
- package/dist/types/supervisor-daemonized-fixture.d.ts +0 -1
- package/dist/types/supervisor-launcher-cleanup-fixture.d.ts +0 -1
- package/dist/types/supervisor-signal-fixture.d.ts +0 -1
- package/dist/types/supervisor.d.ts +0 -23
- package/dist/types/three-way-merge.d.ts +0 -77
- package/dist/types/working-tree-mirror.d.ts +0 -424
- package/dist/types/workspace-automatic-sync-policy.d.ts +0 -57
- package/dist/types/workspace-branch-incarnation-policy.d.ts +0 -14
- package/dist/types/workspace-command-sync-policy.d.ts +0 -57
- package/dist/types/workspace-command-targets.d.ts +0 -37
- package/dist/types/workspace-filesystem-executor-thread.d.ts +0 -1
- package/dist/types/workspace-filesystem-executor.d.ts +0 -123
- package/dist/types/workspace-filesystem-job-types.d.ts +0 -302
- package/dist/types/workspace-filesystem-jobs.d.ts +0 -7
- package/dist/types/workspace-git-sync.d.ts +0 -514
- package/dist/types/workspace-hydration-ledger.d.ts +0 -76
- package/dist/types/workspace-hydration-merge.d.ts +0 -103
- package/dist/types/workspace-hydration-recovery-state.d.ts +0 -10
- package/dist/types/workspace-incident-state.d.ts +0 -19
- package/dist/types/workspace-merge-projection.d.ts +0 -69
- package/dist/types/workspace-mount-boundary.d.ts +0 -10
- package/dist/types/workspace-mount-hold-fence.d.ts +0 -42
- package/dist/types/workspace-mutation-gate.d.ts +0 -42
- package/dist/types/workspace-path-move.d.ts +0 -21
- package/dist/types/workspace-preserve-only-policy.d.ts +0 -15
- package/dist/types/workspace-project-config-policy.d.ts +0 -48
- package/dist/types/workspace-projection-ledger.d.ts +0 -59
- package/dist/types/workspace-publication-evidence.d.ts +0 -17
- package/dist/types/workspace-sync-coalescer.d.ts +0 -28
- /package/dist/types/{credential-authority-lock-fixture.d.ts → runtime/releases/main.d.ts} +0 -0
|
@@ -1,77 +0,0 @@
|
|
|
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 recovery_output_window_exports = {};
|
|
20
|
-
__export(recovery_output_window_exports, {
|
|
21
|
-
WorkerOutputWindow: () => WorkerOutputWindow
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(recovery_output_window_exports);
|
|
24
|
-
const keyOf = (runId, stream) => `${runId}:${stream}`;
|
|
25
|
-
class WorkerOutputWindow {
|
|
26
|
-
constructor(windowBytes = 1024 * 1024) {
|
|
27
|
-
this.windowBytes = windowBytes;
|
|
28
|
-
}
|
|
29
|
-
windowBytes;
|
|
30
|
-
sent = /* @__PURE__ */ new Map();
|
|
31
|
-
acknowledged = /* @__PURE__ */ new Map();
|
|
32
|
-
outstanding = 0;
|
|
33
|
-
reset(cursors) {
|
|
34
|
-
this.sent.clear();
|
|
35
|
-
this.acknowledged.clear();
|
|
36
|
-
this.outstanding = 0;
|
|
37
|
-
for (const cursor of cursors) {
|
|
38
|
-
for (const stream of ["stdout", "stderr"]) {
|
|
39
|
-
const offset = stream === "stdout" ? cursor.stdoutBytes : cursor.stderrBytes;
|
|
40
|
-
this.sent.set(keyOf(cursor.runId, stream), offset);
|
|
41
|
-
this.acknowledged.set(keyOf(cursor.runId, stream), offset);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
send(frame, send, bufferedAmount = 0) {
|
|
46
|
-
const key = keyOf(frame.runId, frame.stream);
|
|
47
|
-
const sent = this.sent.get(key) ?? 0;
|
|
48
|
-
const bytes = Buffer.from(frame.data, "utf8");
|
|
49
|
-
const end = frame.offset + bytes.length;
|
|
50
|
-
if (end <= sent) return true;
|
|
51
|
-
if (frame.offset > sent) return false;
|
|
52
|
-
let cursor = sent;
|
|
53
|
-
while (cursor < end) {
|
|
54
|
-
let count = Math.min(end - cursor, 64 * 1024, this.windowBytes - this.outstanding);
|
|
55
|
-
while (count > 0 && ((bytes[cursor - frame.offset + count] ?? 0) & 192) === 128) count -= 1;
|
|
56
|
-
if (count <= 0 || bufferedAmount >= this.windowBytes) return false;
|
|
57
|
-
const data = bytes.subarray(cursor - frame.offset, cursor - frame.offset + count).toString("utf8");
|
|
58
|
-
if (!send({ ...frame, offset: cursor, data })) return false;
|
|
59
|
-
cursor += count;
|
|
60
|
-
this.sent.set(key, cursor);
|
|
61
|
-
this.outstanding += count;
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
acknowledge(runId, stream, offset) {
|
|
66
|
-
if (!Number.isSafeInteger(offset) || offset < 0) return;
|
|
67
|
-
const key = keyOf(runId, stream);
|
|
68
|
-
const previous = this.acknowledged.get(key) ?? 0;
|
|
69
|
-
const next = Math.max(previous, Math.min(this.sent.get(key) ?? 0, offset));
|
|
70
|
-
this.acknowledged.set(key, next);
|
|
71
|
-
this.outstanding = Math.max(0, this.outstanding - (next - previous));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
-
0 && (module.exports = {
|
|
76
|
-
WorkerOutputWindow
|
|
77
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
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 recovery_protocol_exports = {};
|
|
20
|
-
__export(recovery_protocol_exports, {
|
|
21
|
-
WORKER_RECOVERY_TIMEOUT_MS: () => WORKER_RECOVERY_TIMEOUT_MS,
|
|
22
|
-
WORKER_RESUMABLE_PROTOCOL: () => WORKER_RESUMABLE_PROTOCOL
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(recovery_protocol_exports);
|
|
25
|
-
const WORKER_RESUMABLE_PROTOCOL = 1;
|
|
26
|
-
const WORKER_RECOVERY_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 && (module.exports = {
|
|
29
|
-
WORKER_RECOVERY_TIMEOUT_MS,
|
|
30
|
-
WORKER_RESUMABLE_PROTOCOL
|
|
31
|
-
});
|
|
@@ -1,252 +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 recovery_store_exports = {};
|
|
30
|
-
__export(recovery_store_exports, {
|
|
31
|
-
WorkerRecoveryStore: () => WorkerRecoveryStore,
|
|
32
|
-
workerOperationDigest: () => workerOperationDigest
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(recovery_store_exports);
|
|
35
|
-
var import_bun_sqlite = require("bun:sqlite");
|
|
36
|
-
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
37
|
-
var import_node_path = __toESM(require("node:path"), 1);
|
|
38
|
-
var import_node_crypto = require("node:crypto");
|
|
39
|
-
function workerOperationDigest(message) {
|
|
40
|
-
const canonical = (value) => {
|
|
41
|
-
if (Array.isArray(value)) return value.map(canonical);
|
|
42
|
-
if (value && typeof value === "object")
|
|
43
|
-
return Object.fromEntries(
|
|
44
|
-
Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => [key, canonical(item)])
|
|
45
|
-
);
|
|
46
|
-
return value;
|
|
47
|
-
};
|
|
48
|
-
const { requestId: _requestId, ...identity } = message;
|
|
49
|
-
return (0, import_node_crypto.createHash)("sha256").update(JSON.stringify(canonical(identity))).digest("hex");
|
|
50
|
-
}
|
|
51
|
-
class WorkerRecoveryStore {
|
|
52
|
-
db;
|
|
53
|
-
ledgerId;
|
|
54
|
-
constructor(filename) {
|
|
55
|
-
import_node_fs.default.mkdirSync(import_node_path.default.dirname(filename), { recursive: true, mode: 448 });
|
|
56
|
-
this.db = new import_bun_sqlite.Database(filename, { create: true });
|
|
57
|
-
import_node_fs.default.chmodSync(filename, 384);
|
|
58
|
-
this.db.exec(`PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL;
|
|
59
|
-
CREATE TABLE IF NOT EXISTS metadata (key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
60
|
-
CREATE TABLE IF NOT EXISTS operations (request_id TEXT PRIMARY KEY, run_id TEXT, session_id TEXT, request_type TEXT NOT NULL, digest TEXT NOT NULL, state TEXT NOT NULL, response TEXT);
|
|
61
|
-
CREATE UNIQUE INDEX IF NOT EXISTS operation_run_start ON operations(run_id) WHERE request_type='exec_start';
|
|
62
|
-
CREATE INDEX IF NOT EXISTS operation_run_state ON operations(run_id,state);
|
|
63
|
-
CREATE TABLE IF NOT EXISTS aliases (request_id TEXT PRIMARY KEY, operation_id TEXT NOT NULL);
|
|
64
|
-
CREATE TABLE IF NOT EXISTS streams (run_id TEXT NOT NULL, stream TEXT NOT NULL, bytes INTEGER NOT NULL DEFAULT 0, acknowledged INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(run_id, stream));
|
|
65
|
-
CREATE TABLE IF NOT EXISTS output (run_id TEXT NOT NULL, stream TEXT NOT NULL, offset INTEGER NOT NULL, bytes INTEGER NOT NULL, data TEXT NOT NULL, PRIMARY KEY(run_id, stream, offset));
|
|
66
|
-
CREATE TABLE IF NOT EXISTS terminals (run_id TEXT PRIMARY KEY, message TEXT NOT NULL);
|
|
67
|
-
CREATE TABLE IF NOT EXISTS cancelled_requests (request_id TEXT PRIMARY KEY);
|
|
68
|
-
`);
|
|
69
|
-
this.db.run("INSERT OR IGNORE INTO metadata(key,value) VALUES ('ledgerId',?)", [crypto.randomUUID()]);
|
|
70
|
-
this.ledgerId = this.db.query("SELECT value FROM metadata WHERE key='ledgerId'").get().value;
|
|
71
|
-
this.db.run("UPDATE operations SET state='unknown' WHERE state IN ('accepted','preparing','running')");
|
|
72
|
-
}
|
|
73
|
-
close() {
|
|
74
|
-
this.db.close();
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Run several store operations as one durable commit (one FULL fsync).
|
|
78
|
-
* Operations that open their own transaction nest as savepoints. A throw
|
|
79
|
-
* rolls the whole group back; callers treat that as a journal failure.
|
|
80
|
-
*/
|
|
81
|
-
batch(operations) {
|
|
82
|
-
return this.db.transaction(operations)();
|
|
83
|
-
}
|
|
84
|
-
row(requestId) {
|
|
85
|
-
return this.db.query("SELECT * FROM operations WHERE request_id=? OR request_id=(SELECT operation_id FROM aliases WHERE request_id=?)").get(requestId, requestId);
|
|
86
|
-
}
|
|
87
|
-
admit(message) {
|
|
88
|
-
const digest = workerOperationDigest(message);
|
|
89
|
-
let existing = this.row(message.requestId);
|
|
90
|
-
if (!existing && message.type === "exec_start" && typeof message.runId === "string")
|
|
91
|
-
existing = this.db.query("SELECT * FROM operations WHERE run_id=? AND request_type='exec_start'").get(message.runId);
|
|
92
|
-
if (existing) {
|
|
93
|
-
if (existing.digest !== digest) return "conflict";
|
|
94
|
-
this.db.run("INSERT OR IGNORE INTO aliases(request_id, operation_id) VALUES (?,?)", [message.requestId, existing.request_id]);
|
|
95
|
-
return existing.state === "unknown" ? "unknown" : "duplicate";
|
|
96
|
-
}
|
|
97
|
-
this.db.run("INSERT INTO operations(request_id, run_id, session_id, request_type, digest, state) VALUES (?,?,?,?,?,'accepted')", [
|
|
98
|
-
message.requestId,
|
|
99
|
-
typeof message.runId === "string" ? message.runId : null,
|
|
100
|
-
typeof message.sessionId === "string" ? message.sessionId : null,
|
|
101
|
-
message.type,
|
|
102
|
-
digest
|
|
103
|
-
]);
|
|
104
|
-
return "new";
|
|
105
|
-
}
|
|
106
|
-
isUnknown(requestId) {
|
|
107
|
-
return this.row(requestId)?.state === "unknown";
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Re-admit an operation whose crash outcome is unknown so it can run again
|
|
111
|
-
* and record a result. Only a branch deletion qualifies: it is idempotent
|
|
112
|
-
* for its exact incarnation (durable tombstone plus incarnation preflight),
|
|
113
|
-
* so a rerun converges on the same outcome. Every other unknown operation
|
|
114
|
-
* keeps the no-replay invariant.
|
|
115
|
-
*/
|
|
116
|
-
readmitUnknownBranchDeletion(requestId) {
|
|
117
|
-
const row = this.row(requestId);
|
|
118
|
-
if (!row || row.state !== "unknown" || row.request_type !== "delete_project_branch") return false;
|
|
119
|
-
this.db.run("UPDATE operations SET state='accepted', response=NULL WHERE request_id=?", [row.request_id]);
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
unknown(requestId) {
|
|
123
|
-
const row = this.row(requestId);
|
|
124
|
-
if (row) this.db.run("UPDATE operations SET state='unknown' WHERE request_id=?", [row.request_id]);
|
|
125
|
-
}
|
|
126
|
-
unknownRun(runId) {
|
|
127
|
-
this.db.run("UPDATE operations SET state='unknown' WHERE run_id=? AND request_type IN ('exec_start','exec')", [runId]);
|
|
128
|
-
}
|
|
129
|
-
record(message) {
|
|
130
|
-
if (message.type === "exec_output" && typeof message.runId === "string" && (message.stream === "stdout" || message.stream === "stderr") && typeof message.data === "string") {
|
|
131
|
-
const runId = message.runId, stream = message.stream, data = message.data;
|
|
132
|
-
const offset = this.db.transaction(() => {
|
|
133
|
-
this.db.run("INSERT OR IGNORE INTO streams(run_id, stream) VALUES (?,?)", [runId, stream]);
|
|
134
|
-
const offset2 = this.db.query("SELECT bytes FROM streams WHERE run_id=? AND stream=?").get(runId, stream).bytes;
|
|
135
|
-
const bytes = Buffer.byteLength(data);
|
|
136
|
-
if (bytes) {
|
|
137
|
-
this.db.run("INSERT INTO output(run_id, stream, offset, bytes, data) VALUES (?,?,?,?,?)", [runId, stream, offset2, bytes, data]);
|
|
138
|
-
this.db.run("UPDATE streams SET bytes=bytes+? WHERE run_id=? AND stream=?", [bytes, runId, stream]);
|
|
139
|
-
}
|
|
140
|
-
return offset2;
|
|
141
|
-
})();
|
|
142
|
-
return { ...message, offset };
|
|
143
|
-
}
|
|
144
|
-
if ((message.type === "exec_exit" || message.type === "exec_error") && typeof message.runId === "string") {
|
|
145
|
-
const terminal = { ...message, ...this.lengths(message.runId) };
|
|
146
|
-
this.db.transaction(() => {
|
|
147
|
-
this.db.run("INSERT OR REPLACE INTO terminals(run_id,message) VALUES (?,?)", [message.runId, JSON.stringify(terminal)]);
|
|
148
|
-
this.db.run("UPDATE operations SET state='completed' WHERE run_id=? AND request_type='exec_start'", [message.runId]);
|
|
149
|
-
})();
|
|
150
|
-
return terminal;
|
|
151
|
-
}
|
|
152
|
-
if (typeof message.requestId === "string") {
|
|
153
|
-
const row = this.row(message.requestId);
|
|
154
|
-
if (row) {
|
|
155
|
-
const state = message.type === "exec_accepted" || message.type === "operation_queued" ? "preparing" : message.type === "exec_started" ? "running" : message.type === "operation_received" ? "accepted" : "completed";
|
|
156
|
-
if (message.type !== "operation_received")
|
|
157
|
-
this.db.run("UPDATE operations SET state=?, response=? WHERE request_id=?", [state, JSON.stringify(message), row.request_id]);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return message;
|
|
161
|
-
}
|
|
162
|
-
operations() {
|
|
163
|
-
return this.db.query(
|
|
164
|
-
"SELECT * FROM operations WHERE response IS NOT NULL OR state!='completed' UNION ALL SELECT aliases.request_id,operations.run_id,operations.session_id,operations.request_type,operations.digest,operations.state,operations.response FROM aliases JOIN operations ON operations.request_id=aliases.operation_id WHERE aliases.request_id!=operations.request_id AND (response IS NOT NULL OR state!='completed')"
|
|
165
|
-
).all().map((row) => ({
|
|
166
|
-
requestId: row.request_id,
|
|
167
|
-
requestType: row.request_type,
|
|
168
|
-
state: row.state,
|
|
169
|
-
...row.run_id ? { runId: row.run_id } : {},
|
|
170
|
-
...row.session_id ? { sessionId: row.session_id } : {}
|
|
171
|
-
}));
|
|
172
|
-
}
|
|
173
|
-
response(requestId) {
|
|
174
|
-
const row = this.row(requestId);
|
|
175
|
-
return row?.response && row.state !== "unknown" ? { ...JSON.parse(row.response), requestId } : void 0;
|
|
176
|
-
}
|
|
177
|
-
responses(requestIds) {
|
|
178
|
-
const ids = /* @__PURE__ */ new Set([...requestIds, ...this.operations().map((operation) => operation.requestId)]);
|
|
179
|
-
return [...ids].flatMap((requestId) => {
|
|
180
|
-
const response = this.response(requestId);
|
|
181
|
-
return response ? [response] : [];
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
lengths(runId) {
|
|
185
|
-
const result = { stdoutBytes: 0, stderrBytes: 0 };
|
|
186
|
-
for (const row of this.db.query("SELECT stream,bytes FROM streams WHERE run_id=?").all(runId))
|
|
187
|
-
result[row.stream === "stdout" ? "stdoutBytes" : "stderrBytes"] = row.bytes;
|
|
188
|
-
return result;
|
|
189
|
-
}
|
|
190
|
-
outputCursors() {
|
|
191
|
-
const cursors = /* @__PURE__ */ new Map();
|
|
192
|
-
for (const stream of this.db.query("SELECT run_id,stream,acknowledged FROM streams").all()) {
|
|
193
|
-
const cursor = cursors.get(stream.run_id) ?? { runId: stream.run_id, stdoutBytes: 0, stderrBytes: 0 };
|
|
194
|
-
cursor[stream.stream === "stdout" ? "stdoutBytes" : "stderrBytes"] = stream.acknowledged;
|
|
195
|
-
cursors.set(stream.run_id, cursor);
|
|
196
|
-
}
|
|
197
|
-
return [...cursors.values()];
|
|
198
|
-
}
|
|
199
|
-
*output(offsets = []) {
|
|
200
|
-
const cursors = new Map(offsets.map((offset) => [offset.runId, offset]));
|
|
201
|
-
const pendingStreamFilter = offsets.length === 0 ? "bytes>acknowledged AND " : "";
|
|
202
|
-
for (const stream of this.db.query(`SELECT * FROM streams WHERE ${pendingStreamFilter}NOT EXISTS (SELECT 1 FROM operations WHERE operations.run_id=streams.run_id AND operations.state='unknown') ORDER BY rowid`).all()) {
|
|
203
|
-
const supplied = cursors.get(stream.run_id);
|
|
204
|
-
const cursor = supplied ? stream.stream === "stdout" ? supplied.stdoutBytes : supplied.stderrBytes : stream.acknowledged;
|
|
205
|
-
if (cursor >= stream.bytes) continue;
|
|
206
|
-
const firstOffset = this.db.query("SELECT MAX(offset) AS offset FROM output WHERE run_id=? AND stream=? AND offset<=?").get(stream.run_id, stream.stream, cursor)?.offset ?? 0;
|
|
207
|
-
let nextChunk = firstOffset;
|
|
208
|
-
while (true) {
|
|
209
|
-
const row = this.db.query("SELECT offset,data FROM output WHERE run_id=? AND stream=? AND offset>=? AND offset<? AND offset+bytes>? ORDER BY offset LIMIT 1").get(stream.run_id, stream.stream, nextChunk, stream.bytes, cursor);
|
|
210
|
-
if (!row) break;
|
|
211
|
-
nextChunk = row.offset + 1;
|
|
212
|
-
yield { type: "exec_output", runId: stream.run_id, stream: stream.stream, offset: row.offset, data: row.data };
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
terminals() {
|
|
217
|
-
return this.db.query(
|
|
218
|
-
"SELECT message FROM terminals WHERE NOT EXISTS (SELECT 1 FROM operations WHERE operations.run_id=terminals.run_id AND operations.state='unknown')"
|
|
219
|
-
).all().map((row) => JSON.parse(row.message));
|
|
220
|
-
}
|
|
221
|
-
acknowledgeOutput(runId, stream, offset) {
|
|
222
|
-
if (!Number.isSafeInteger(offset) || offset < 0) return;
|
|
223
|
-
this.db.run("UPDATE streams SET acknowledged=MAX(acknowledged,MIN(bytes,?)) WHERE run_id=? AND stream=?", [offset, runId, stream]);
|
|
224
|
-
}
|
|
225
|
-
acknowledgeResult(requestId) {
|
|
226
|
-
const row = this.row(requestId);
|
|
227
|
-
if (row && row.request_type !== "exec_start")
|
|
228
|
-
this.db.run("UPDATE operations SET response=NULL WHERE request_id=? AND state='completed'", [row.request_id]);
|
|
229
|
-
}
|
|
230
|
-
acknowledgeTerminal(runId) {
|
|
231
|
-
this.db.transaction(() => {
|
|
232
|
-
this.db.run("DELETE FROM terminals WHERE run_id=?", [runId]);
|
|
233
|
-
this.db.run("DELETE FROM output WHERE run_id=?", [runId]);
|
|
234
|
-
this.db.run("UPDATE streams SET acknowledged=bytes WHERE run_id=?", [runId]);
|
|
235
|
-
this.db.run("UPDATE operations SET response=NULL WHERE run_id=? AND request_type='exec_start' AND state='completed'", [runId]);
|
|
236
|
-
})();
|
|
237
|
-
}
|
|
238
|
-
cancelSession(sessionId) {
|
|
239
|
-
this.db.run("INSERT OR IGNORE INTO cancelled_requests SELECT request_id FROM operations WHERE session_id=? AND state!='completed'", [
|
|
240
|
-
sessionId
|
|
241
|
-
]);
|
|
242
|
-
}
|
|
243
|
-
isRequestCancelled(requestId) {
|
|
244
|
-
const row = this.row(requestId);
|
|
245
|
-
return !!row && this.db.query("SELECT request_id FROM cancelled_requests WHERE request_id=?").get(row.request_id) !== null;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
249
|
-
0 && (module.exports = {
|
|
250
|
-
WorkerRecoveryStore,
|
|
251
|
-
workerOperationDigest
|
|
252
|
-
});
|
|
@@ -1,310 +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 registry_auth_exports = {};
|
|
30
|
-
__export(registry_auth_exports, {
|
|
31
|
-
APP_MANAGED_GITHUB_REGISTRY: () => APP_MANAGED_GITHUB_REGISTRY,
|
|
32
|
-
RegistryAuthConfigurationError: () => RegistryAuthConfigurationError,
|
|
33
|
-
configureGitHubRegistryAuthFiles: () => configureGitHubRegistryAuthFiles,
|
|
34
|
-
planGitHubRegistryAuthFiles: () => planGitHubRegistryAuthFiles,
|
|
35
|
-
preparePrivateAuthFileGeneration: () => preparePrivateAuthFileGeneration,
|
|
36
|
-
registryAuthHasAppManagedGitHubCredential: () => registryAuthHasAppManagedGitHubCredential,
|
|
37
|
-
registryAuthTestHarness: () => registryAuthTestHarness,
|
|
38
|
-
updateGitHubRegistryAuthFile: () => updateGitHubRegistryAuthFile
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(registry_auth_exports);
|
|
41
|
-
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
42
|
-
var import_node_path = __toESM(require("node:path"), 1);
|
|
43
|
-
const APP_MANAGED_GITHUB_REGISTRY = "ghcr.io";
|
|
44
|
-
class RegistryAuthConfigurationError extends Error {
|
|
45
|
-
constructor(cause) {
|
|
46
|
-
super("Could not authoritatively configure GitHub registry authentication", { cause });
|
|
47
|
-
this.name = "RegistryAuthConfigurationError";
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function isJsonObject(value) {
|
|
51
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52
|
-
}
|
|
53
|
-
function lstatIfExists(filePath) {
|
|
54
|
-
try {
|
|
55
|
-
return import_node_fs.default.lstatSync(filePath);
|
|
56
|
-
} catch (error) {
|
|
57
|
-
if (error.code === "ENOENT") return null;
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function readRegistryAuthConfig(filePath) {
|
|
62
|
-
const stat = lstatIfExists(filePath);
|
|
63
|
-
if (!stat) return null;
|
|
64
|
-
if (stat.isSymbolicLink() || !stat.isFile()) throw new Error(`Registry auth config must be a regular file: ${filePath}`);
|
|
65
|
-
let parsed;
|
|
66
|
-
try {
|
|
67
|
-
parsed = JSON.parse(import_node_fs.default.readFileSync(filePath, "utf8"));
|
|
68
|
-
} catch (error) {
|
|
69
|
-
throw new Error(`Registry auth config is not valid JSON: ${filePath}`, { cause: error });
|
|
70
|
-
}
|
|
71
|
-
if (!isJsonObject(parsed)) throw new Error(`Registry auth config must contain a JSON object: ${filePath}`);
|
|
72
|
-
return parsed;
|
|
73
|
-
}
|
|
74
|
-
function registryAuthHasAppManagedGitHubCredential(filePath) {
|
|
75
|
-
const config = readRegistryAuthConfig(filePath);
|
|
76
|
-
if (!config) return false;
|
|
77
|
-
if (config.auths === void 0) return false;
|
|
78
|
-
if (!isJsonObject(config.auths)) throw new Error(`Registry auth config has an invalid auths object: ${filePath}`);
|
|
79
|
-
return Object.prototype.hasOwnProperty.call(config.auths, APP_MANAGED_GITHUB_REGISTRY);
|
|
80
|
-
}
|
|
81
|
-
function fsyncDirectory(directory, dependencies = {
|
|
82
|
-
platform: process.platform,
|
|
83
|
-
open: (target) => import_node_fs.default.openSync(target, "r"),
|
|
84
|
-
fsync: import_node_fs.default.fsyncSync,
|
|
85
|
-
close: import_node_fs.default.closeSync
|
|
86
|
-
}) {
|
|
87
|
-
if (dependencies.platform === "win32") return;
|
|
88
|
-
const descriptor = dependencies.open(directory);
|
|
89
|
-
try {
|
|
90
|
-
dependencies.fsync(descriptor);
|
|
91
|
-
} finally {
|
|
92
|
-
dependencies.close(descriptor);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function ensurePrivateParentDirectory(filePath) {
|
|
96
|
-
const directory = import_node_path.default.dirname(filePath);
|
|
97
|
-
let existingAncestor = directory;
|
|
98
|
-
while (!lstatIfExists(existingAncestor)) {
|
|
99
|
-
const parent = import_node_path.default.dirname(existingAncestor);
|
|
100
|
-
if (parent === existingAncestor) throw new Error(`Registry auth parent has no existing ancestor: ${directory}`);
|
|
101
|
-
existingAncestor = parent;
|
|
102
|
-
}
|
|
103
|
-
const ancestorStat = lstatIfExists(existingAncestor);
|
|
104
|
-
if (!ancestorStat || ancestorStat.isSymbolicLink() || !ancestorStat.isDirectory()) {
|
|
105
|
-
throw new Error(`Registry auth parent must descend from a real directory: ${directory}`);
|
|
106
|
-
}
|
|
107
|
-
import_node_fs.default.mkdirSync(directory, { recursive: true, mode: 448 });
|
|
108
|
-
let current = directory;
|
|
109
|
-
while (true) {
|
|
110
|
-
const stat = lstatIfExists(current);
|
|
111
|
-
if (!stat || stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
112
|
-
throw new Error(`Registry auth parent must be a real directory: ${current}`);
|
|
113
|
-
}
|
|
114
|
-
fsyncDirectory(current);
|
|
115
|
-
if (current === existingAncestor) break;
|
|
116
|
-
current = import_node_path.default.dirname(current);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function stagePrivateFile(filePath, content) {
|
|
120
|
-
ensurePrivateParentDirectory(filePath);
|
|
121
|
-
const temporaryPath = import_node_path.default.join(import_node_path.default.dirname(filePath), `.${import_node_path.default.basename(filePath)}.r5d-auth.${process.pid}.${crypto.randomUUID()}.tmp`);
|
|
122
|
-
let descriptor;
|
|
123
|
-
try {
|
|
124
|
-
descriptor = import_node_fs.default.openSync(temporaryPath, "wx", 384);
|
|
125
|
-
import_node_fs.default.writeFileSync(descriptor, content, "utf8");
|
|
126
|
-
import_node_fs.default.fsyncSync(descriptor);
|
|
127
|
-
import_node_fs.default.closeSync(descriptor);
|
|
128
|
-
descriptor = void 0;
|
|
129
|
-
import_node_fs.default.chmodSync(temporaryPath, 384);
|
|
130
|
-
return { filePath, temporaryPath };
|
|
131
|
-
} catch (error) {
|
|
132
|
-
if (descriptor !== void 0) import_node_fs.default.closeSync(descriptor);
|
|
133
|
-
import_node_fs.default.rmSync(temporaryPath, { force: true });
|
|
134
|
-
throw error;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function commitStagedPrivateFile(staged, beforeRename) {
|
|
138
|
-
beforeRename?.();
|
|
139
|
-
import_node_fs.default.renameSync(staged.temporaryPath, staged.filePath);
|
|
140
|
-
import_node_fs.default.chmodSync(staged.filePath, 384);
|
|
141
|
-
fsyncDirectory(import_node_path.default.dirname(staged.filePath));
|
|
142
|
-
}
|
|
143
|
-
function discardStagedPrivateFile(staged) {
|
|
144
|
-
import_node_fs.default.rmSync(staged.temporaryPath, { force: true });
|
|
145
|
-
}
|
|
146
|
-
function cleanupAbandonedStagedFiles(filePath) {
|
|
147
|
-
const directory = import_node_path.default.dirname(filePath);
|
|
148
|
-
const prefix = `.${import_node_path.default.basename(filePath)}.r5d-auth.`;
|
|
149
|
-
let entries;
|
|
150
|
-
try {
|
|
151
|
-
entries = import_node_fs.default.readdirSync(directory);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
if (error.code === "ENOENT") return;
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
let removed = false;
|
|
157
|
-
for (const name of entries) {
|
|
158
|
-
if (!name.startsWith(prefix) || !name.endsWith(".tmp")) continue;
|
|
159
|
-
const candidate = import_node_path.default.join(directory, name);
|
|
160
|
-
const stat = import_node_fs.default.lstatSync(candidate);
|
|
161
|
-
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
162
|
-
throw new Error(`Registry auth staging artifact must be a regular file: ${candidate}`);
|
|
163
|
-
}
|
|
164
|
-
import_node_fs.default.rmSync(candidate);
|
|
165
|
-
removed = true;
|
|
166
|
-
}
|
|
167
|
-
if (removed) fsyncDirectory(directory);
|
|
168
|
-
}
|
|
169
|
-
function atomicReplacePrivateFile(filePath, content, beforeRename) {
|
|
170
|
-
const staged = stagePrivateFile(filePath, content);
|
|
171
|
-
try {
|
|
172
|
-
commitStagedPrivateFile(staged, beforeRename);
|
|
173
|
-
} finally {
|
|
174
|
-
discardStagedPrivateFile(staged);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function preparePrivateAuthFileGeneration(updates) {
|
|
178
|
-
try {
|
|
179
|
-
const desiredByPath = /* @__PURE__ */ new Map();
|
|
180
|
-
for (const update of updates) {
|
|
181
|
-
const filePath = import_node_path.default.resolve(update.filePath);
|
|
182
|
-
const existing = desiredByPath.get(filePath);
|
|
183
|
-
const desired = { content: update.content, allowSymlinkRemoval: update.allowSymlinkRemoval === true };
|
|
184
|
-
if (existing && (existing.content !== desired.content || existing.allowSymlinkRemoval !== desired.allowSymlinkRemoval)) {
|
|
185
|
-
throw new Error(`Conflicting desired auth content for ${filePath}`);
|
|
186
|
-
}
|
|
187
|
-
desiredByPath.set(filePath, desired);
|
|
188
|
-
}
|
|
189
|
-
const changes = [];
|
|
190
|
-
const stagedFiles = [];
|
|
191
|
-
try {
|
|
192
|
-
for (const [filePath, desired] of desiredByPath) {
|
|
193
|
-
const { content, allowSymlinkRemoval } = desired;
|
|
194
|
-
cleanupAbandonedStagedFiles(filePath);
|
|
195
|
-
const status = lstatIfExists(filePath);
|
|
196
|
-
if (status && (status.isSymbolicLink() ? !(content === null && allowSymlinkRemoval) : !status.isFile())) {
|
|
197
|
-
throw new Error(`Private auth target must be a regular file: ${filePath}`);
|
|
198
|
-
}
|
|
199
|
-
const unchanged = content === null ? !status : Boolean(status && import_node_fs.default.readFileSync(filePath, "utf8") === content && (status.mode & 511) === 384);
|
|
200
|
-
if (unchanged) continue;
|
|
201
|
-
if (content === null) {
|
|
202
|
-
changes.push({ filePath, content });
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
const staged = stagePrivateFile(filePath, content);
|
|
206
|
-
stagedFiles.push(staged);
|
|
207
|
-
changes.push({ filePath, content, staged });
|
|
208
|
-
}
|
|
209
|
-
} catch (error) {
|
|
210
|
-
for (const staged of stagedFiles) discardStagedPrivateFile(staged);
|
|
211
|
-
throw error;
|
|
212
|
-
}
|
|
213
|
-
let finished = false;
|
|
214
|
-
const discard = () => {
|
|
215
|
-
for (const staged of stagedFiles) discardStagedPrivateFile(staged);
|
|
216
|
-
};
|
|
217
|
-
return {
|
|
218
|
-
changed: changes.length > 0,
|
|
219
|
-
commit(beforeMutation) {
|
|
220
|
-
if (finished) throw new Error("Private auth generation has already been finalized");
|
|
221
|
-
finished = true;
|
|
222
|
-
try {
|
|
223
|
-
changes.forEach((change, index) => {
|
|
224
|
-
beforeMutation?.(change.filePath, index);
|
|
225
|
-
if (change.content === null) {
|
|
226
|
-
import_node_fs.default.unlinkSync(change.filePath);
|
|
227
|
-
fsyncDirectory(import_node_path.default.dirname(change.filePath));
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
if (!change.staged) throw new Error(`Private auth replacement was not staged: ${change.filePath}`);
|
|
231
|
-
commitStagedPrivateFile(change.staged);
|
|
232
|
-
});
|
|
233
|
-
} catch (error) {
|
|
234
|
-
throw error instanceof RegistryAuthConfigurationError ? error : new RegistryAuthConfigurationError(error);
|
|
235
|
-
} finally {
|
|
236
|
-
discard();
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
discard() {
|
|
240
|
-
if (finished) return;
|
|
241
|
-
finished = true;
|
|
242
|
-
discard();
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
} catch (error) {
|
|
246
|
-
throw error instanceof RegistryAuthConfigurationError ? error : new RegistryAuthConfigurationError(error);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
function registryAuthFileContent(filePath, credential) {
|
|
250
|
-
if (credential && credential.registry !== APP_MANAGED_GITHUB_REGISTRY) {
|
|
251
|
-
throw new Error(`Unsupported app-managed registry: ${credential.registry}`);
|
|
252
|
-
}
|
|
253
|
-
const existing = readRegistryAuthConfig(filePath);
|
|
254
|
-
if (!existing && !credential) return null;
|
|
255
|
-
const config = { ...existing ?? {} };
|
|
256
|
-
const existingAuths = config.auths;
|
|
257
|
-
if (existingAuths !== void 0 && !isJsonObject(existingAuths)) {
|
|
258
|
-
throw new Error(`Registry auth config has an invalid auths object: ${filePath}`);
|
|
259
|
-
}
|
|
260
|
-
const auths = { ...existingAuths ?? {} };
|
|
261
|
-
delete auths[APP_MANAGED_GITHUB_REGISTRY];
|
|
262
|
-
if (credential) {
|
|
263
|
-
auths[APP_MANAGED_GITHUB_REGISTRY] = {
|
|
264
|
-
username: credential.username,
|
|
265
|
-
password: credential.token,
|
|
266
|
-
auth: Buffer.from(`${credential.username}:${credential.token}`).toString("base64")
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
config.auths = auths;
|
|
270
|
-
return `${JSON.stringify(config, null, 2)}
|
|
271
|
-
`;
|
|
272
|
-
}
|
|
273
|
-
function configureGitHubRegistryAuthFilesWithHook(filePaths, credential, beforeRename) {
|
|
274
|
-
try {
|
|
275
|
-
const prepared = preparePrivateAuthFileGeneration(planGitHubRegistryAuthFiles(filePaths, credential));
|
|
276
|
-
prepared.commit(beforeRename);
|
|
277
|
-
} catch (error) {
|
|
278
|
-
throw error instanceof RegistryAuthConfigurationError ? error : new RegistryAuthConfigurationError(error);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
function planGitHubRegistryAuthFiles(filePaths, credential) {
|
|
282
|
-
const uniquePaths = [...new Set(filePaths.map((filePath) => import_node_path.default.resolve(filePath)))];
|
|
283
|
-
return uniquePaths.map((filePath) => ({ filePath, content: registryAuthFileContent(filePath, credential) }));
|
|
284
|
-
}
|
|
285
|
-
function updateGitHubRegistryAuthFile(filePath, credential) {
|
|
286
|
-
configureGitHubRegistryAuthFilesWithHook([filePath], credential);
|
|
287
|
-
}
|
|
288
|
-
function configureGitHubRegistryAuthFiles(filePaths, credential) {
|
|
289
|
-
configureGitHubRegistryAuthFilesWithHook(filePaths, credential);
|
|
290
|
-
}
|
|
291
|
-
const registryAuthTestHarness = {
|
|
292
|
-
fsyncDirectory,
|
|
293
|
-
atomicReplacePrivateFile(filePath, content, beforeRename) {
|
|
294
|
-
atomicReplacePrivateFile(filePath, content, beforeRename);
|
|
295
|
-
},
|
|
296
|
-
configureFiles(filePaths, credential, beforeRename) {
|
|
297
|
-
configureGitHubRegistryAuthFilesWithHook(filePaths, credential, beforeRename);
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
301
|
-
0 && (module.exports = {
|
|
302
|
-
APP_MANAGED_GITHUB_REGISTRY,
|
|
303
|
-
RegistryAuthConfigurationError,
|
|
304
|
-
configureGitHubRegistryAuthFiles,
|
|
305
|
-
planGitHubRegistryAuthFiles,
|
|
306
|
-
preparePrivateAuthFileGeneration,
|
|
307
|
-
registryAuthHasAppManagedGitHubCredential,
|
|
308
|
-
registryAuthTestHarness,
|
|
309
|
-
updateGitHubRegistryAuthFile
|
|
310
|
-
});
|