@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.
Files changed (236) hide show
  1. package/README.md +4 -94
  2. package/dist/cjs/package.json +1 -1
  3. package/dist/mjs/main.mjs +46 -7543
  4. package/dist/mjs/package.json +1 -1
  5. package/dist/mjs/personal/action-scheduler.mjs +31 -0
  6. package/dist/mjs/personal/client.mjs +215 -0
  7. package/dist/mjs/personal/runtime.mjs +359 -0
  8. package/dist/mjs/personal/tcp.mjs +217 -0
  9. package/dist/mjs/runtime/adapter.mjs +42 -0
  10. package/dist/mjs/runtime/client.mjs +95 -0
  11. package/dist/mjs/runtime/daemon.mjs +131 -0
  12. package/dist/mjs/runtime/executor.mjs +436 -0
  13. package/dist/mjs/runtime/index.mjs +15 -0
  14. package/dist/mjs/runtime/protocol.mjs +139 -0
  15. package/dist/mjs/runtime/pty-host.mjs +156 -0
  16. package/dist/mjs/runtime/pty.mjs +127 -0
  17. package/dist/mjs/runtime/releases/artifacts.mjs +201 -0
  18. package/dist/mjs/runtime/releases/grants.mjs +93 -0
  19. package/dist/mjs/runtime/releases/main.mjs +101 -0
  20. package/dist/mjs/runtime/releases/manager.mjs +541 -0
  21. package/dist/mjs/runtime/releases/process.mjs +88 -0
  22. package/dist/mjs/runtime/releases/retirement.mjs +18 -0
  23. package/dist/mjs/runtime/releases/rpc-client.mjs +184 -0
  24. package/dist/mjs/runtime/releases/rpc-main.mjs +213 -0
  25. package/dist/mjs/runtime/releases/rpc-protocol.mjs +103 -0
  26. package/dist/mjs/runtime/storage.mjs +156 -0
  27. package/dist/mjs/runtime/workspace/artifacts.mjs +121 -0
  28. package/dist/mjs/runtime/workspace/authority.mjs +1355 -0
  29. package/dist/mjs/runtime/workspace/contracts.mjs +60 -0
  30. package/dist/mjs/runtime/workspace/file-write.mjs +23 -0
  31. package/dist/mjs/runtime/workspace/files.mjs +308 -0
  32. package/dist/mjs/runtime/workspace/http-body.mjs +45 -0
  33. package/dist/mjs/runtime/workspace/storage-client.mjs +59 -0
  34. package/dist/mjs/runtime/workspace/storage-wire.mjs +53 -0
  35. package/dist/types/main.d.ts +0 -1167
  36. package/dist/types/personal/action-scheduler.d.ts +23 -0
  37. package/dist/types/personal/client.d.ts +14 -0
  38. package/dist/types/personal/runtime.d.ts +121 -0
  39. package/dist/types/personal/tcp.d.ts +14 -0
  40. package/dist/types/runtime/client.d.ts +3 -1
  41. package/dist/types/runtime/executor.d.ts +6 -1
  42. package/dist/types/runtime/protocol.d.ts +176 -4
  43. package/dist/types/runtime/pty.d.ts +1 -0
  44. package/dist/types/runtime/releases/artifacts.d.ts +51 -0
  45. package/dist/types/runtime/releases/grants.d.ts +16 -0
  46. package/dist/types/runtime/releases/manager.d.ts +145 -0
  47. package/dist/types/runtime/releases/process.d.ts +14 -0
  48. package/dist/types/runtime/releases/retirement.d.ts +15 -0
  49. package/dist/types/runtime/releases/rpc-client.d.ts +52 -0
  50. package/dist/types/runtime/releases/rpc-main.d.ts +10 -0
  51. package/dist/types/runtime/releases/rpc-protocol.d.ts +1139 -0
  52. package/dist/types/runtime/workspace/artifacts.d.ts +30 -0
  53. package/dist/types/runtime/workspace/authority.d.ts +338 -0
  54. package/dist/types/runtime/workspace/contracts.d.ts +86 -0
  55. package/dist/types/runtime/workspace/file-write.d.ts +14 -0
  56. package/dist/types/runtime/workspace/files.d.ts +21 -0
  57. package/dist/types/runtime/workspace/http-body.d.ts +9 -0
  58. package/dist/types/runtime/workspace/storage-client.d.ts +23 -0
  59. package/dist/types/runtime/workspace/storage-wire.d.ts +138 -0
  60. package/package.json +8 -6
  61. package/dist/cjs/atomic-rename.cjs +0 -303
  62. package/dist/cjs/browser-upload.cjs +0 -73
  63. package/dist/cjs/cli-update.cjs +0 -108
  64. package/dist/cjs/command-launcher.cjs +0 -423
  65. package/dist/cjs/control-command-policy.cjs +0 -177
  66. package/dist/cjs/git-blob-hash.cjs +0 -41
  67. package/dist/cjs/git-identity.cjs +0 -39
  68. package/dist/cjs/git-process-environment.cjs +0 -133
  69. package/dist/cjs/inline-output.cjs +0 -62
  70. package/dist/cjs/main.cjs +0 -7517
  71. package/dist/cjs/managed-paths.cjs +0 -215
  72. package/dist/cjs/plan-lint.cjs +0 -165
  73. package/dist/cjs/plan-parser.cjs +0 -127
  74. package/dist/cjs/plan-paths.cjs +0 -53
  75. package/dist/cjs/port-forward-client.cjs +0 -206
  76. package/dist/cjs/process-tree.cjs +0 -117
  77. package/dist/cjs/project-checkout-garbage.cjs +0 -219
  78. package/dist/cjs/project-mirror-fetch-policy.cjs +0 -82
  79. package/dist/cjs/project-mirror-refs-token.cjs +0 -85
  80. package/dist/cjs/project-workspace-state.cjs +0 -972
  81. package/dist/cjs/project-worktrees.cjs +0 -1713
  82. package/dist/cjs/pty-output-coalescer.cjs +0 -87
  83. package/dist/cjs/recovery-journal-protocol.cjs +0 -56
  84. package/dist/cjs/recovery-journal-runtime.cjs +0 -133
  85. package/dist/cjs/recovery-journal-thread.cjs +0 -9
  86. package/dist/cjs/recovery-journal.cjs +0 -742
  87. package/dist/cjs/recovery-output-window.cjs +0 -77
  88. package/dist/cjs/recovery-protocol.cjs +0 -31
  89. package/dist/cjs/recovery-store.cjs +0 -252
  90. package/dist/cjs/registry-auth.cjs +0 -310
  91. package/dist/cjs/repository-transition-policy.cjs +0 -49
  92. package/dist/cjs/runtime-version.cjs +0 -88
  93. package/dist/cjs/session-file-mutations.cjs +0 -61
  94. package/dist/cjs/supervisor.cjs +0 -147
  95. package/dist/cjs/three-way-merge.cjs +0 -346
  96. package/dist/cjs/working-tree-mirror.cjs +0 -1872
  97. package/dist/cjs/workspace-automatic-sync-policy.cjs +0 -79
  98. package/dist/cjs/workspace-branch-incarnation-policy.cjs +0 -37
  99. package/dist/cjs/workspace-command-sync-policy.cjs +0 -112
  100. package/dist/cjs/workspace-command-targets.cjs +0 -63
  101. package/dist/cjs/workspace-filesystem-executor-thread.cjs +0 -36
  102. package/dist/cjs/workspace-filesystem-executor.cjs +0 -327
  103. package/dist/cjs/workspace-filesystem-job-types.cjs +0 -144
  104. package/dist/cjs/workspace-filesystem-jobs.cjs +0 -59
  105. package/dist/cjs/workspace-git-sync.cjs +0 -3595
  106. package/dist/cjs/workspace-hydration-ledger.cjs +0 -83
  107. package/dist/cjs/workspace-hydration-merge.cjs +0 -448
  108. package/dist/cjs/workspace-hydration-recovery-state.cjs +0 -53
  109. package/dist/cjs/workspace-incident-state.cjs +0 -37
  110. package/dist/cjs/workspace-merge-projection.cjs +0 -628
  111. package/dist/cjs/workspace-mount-boundary.cjs +0 -71
  112. package/dist/cjs/workspace-mount-hold-fence.cjs +0 -120
  113. package/dist/cjs/workspace-mutation-gate.cjs +0 -127
  114. package/dist/cjs/workspace-path-move.cjs +0 -195
  115. package/dist/cjs/workspace-preserve-only-policy.cjs +0 -36
  116. package/dist/cjs/workspace-project-config-policy.cjs +0 -53
  117. package/dist/cjs/workspace-projection-ledger.cjs +0 -81
  118. package/dist/cjs/workspace-publication-evidence.cjs +0 -46
  119. package/dist/cjs/workspace-sync-coalescer.cjs +0 -58
  120. package/dist/mjs/atomic-rename.mjs +0 -261
  121. package/dist/mjs/browser-upload.mjs +0 -42
  122. package/dist/mjs/command-launcher.mjs +0 -393
  123. package/dist/mjs/control-command-policy.mjs +0 -146
  124. package/dist/mjs/git-blob-hash.mjs +0 -16
  125. package/dist/mjs/git-identity.mjs +0 -15
  126. package/dist/mjs/git-process-environment.mjs +0 -105
  127. package/dist/mjs/inline-output.mjs +0 -37
  128. package/dist/mjs/managed-paths.mjs +0 -174
  129. package/dist/mjs/plan-lint.mjs +0 -129
  130. package/dist/mjs/plan-parser.mjs +0 -94
  131. package/dist/mjs/plan-paths.mjs +0 -25
  132. package/dist/mjs/port-forward-client.mjs +0 -172
  133. package/dist/mjs/project-checkout-garbage.mjs +0 -178
  134. package/dist/mjs/project-mirror-fetch-policy.mjs +0 -56
  135. package/dist/mjs/project-mirror-refs-token.mjs +0 -53
  136. package/dist/mjs/project-workspace-state.mjs +0 -937
  137. package/dist/mjs/project-worktrees.mjs +0 -1657
  138. package/dist/mjs/pty-output-coalescer.mjs +0 -61
  139. package/dist/mjs/recovery-journal-protocol.mjs +0 -30
  140. package/dist/mjs/recovery-journal-runtime.mjs +0 -112
  141. package/dist/mjs/recovery-journal-thread.mjs +0 -8
  142. package/dist/mjs/recovery-journal.mjs +0 -694
  143. package/dist/mjs/recovery-output-window.mjs +0 -53
  144. package/dist/mjs/recovery-protocol.mjs +0 -6
  145. package/dist/mjs/recovery-store.mjs +0 -217
  146. package/dist/mjs/registry-auth.mjs +0 -269
  147. package/dist/mjs/repository-transition-policy.mjs +0 -22
  148. package/dist/mjs/runtime-version.mjs +0 -54
  149. package/dist/mjs/session-file-mutations.mjs +0 -37
  150. package/dist/mjs/supervisor.mjs +0 -114
  151. package/dist/mjs/three-way-merge.mjs +0 -318
  152. package/dist/mjs/working-tree-mirror.mjs +0 -1817
  153. package/dist/mjs/workspace-automatic-sync-policy.mjs +0 -48
  154. package/dist/mjs/workspace-branch-incarnation-policy.mjs +0 -13
  155. package/dist/mjs/workspace-command-sync-policy.mjs +0 -84
  156. package/dist/mjs/workspace-command-targets.mjs +0 -37
  157. package/dist/mjs/workspace-filesystem-executor-thread.mjs +0 -38
  158. package/dist/mjs/workspace-filesystem-executor.mjs +0 -287
  159. package/dist/mjs/workspace-filesystem-job-types.mjs +0 -116
  160. package/dist/mjs/workspace-filesystem-jobs.mjs +0 -55
  161. package/dist/mjs/workspace-git-sync.mjs +0 -3553
  162. package/dist/mjs/workspace-hydration-ledger.mjs +0 -58
  163. package/dist/mjs/workspace-hydration-merge.mjs +0 -414
  164. package/dist/mjs/workspace-hydration-recovery-state.mjs +0 -29
  165. package/dist/mjs/workspace-incident-state.mjs +0 -12
  166. package/dist/mjs/workspace-merge-projection.mjs +0 -594
  167. package/dist/mjs/workspace-mount-boundary.mjs +0 -37
  168. package/dist/mjs/workspace-mount-hold-fence.mjs +0 -95
  169. package/dist/mjs/workspace-mutation-gate.mjs +0 -103
  170. package/dist/mjs/workspace-path-move.mjs +0 -160
  171. package/dist/mjs/workspace-preserve-only-policy.mjs +0 -11
  172. package/dist/mjs/workspace-project-config-policy.mjs +0 -27
  173. package/dist/mjs/workspace-projection-ledger.mjs +0 -57
  174. package/dist/mjs/workspace-publication-evidence.mjs +0 -21
  175. package/dist/mjs/workspace-sync-coalescer.mjs +0 -34
  176. package/dist/types/atomic-rename.d.ts +0 -78
  177. package/dist/types/browser-upload.d.ts +0 -7
  178. package/dist/types/command-launcher.d.ts +0 -104
  179. package/dist/types/control-command-policy.d.ts +0 -53
  180. package/dist/types/git-blob-hash.d.ts +0 -10
  181. package/dist/types/git-identity.d.ts +0 -9
  182. package/dist/types/git-process-environment.d.ts +0 -9
  183. package/dist/types/inline-output.d.ts +0 -3
  184. package/dist/types/managed-paths.d.ts +0 -19
  185. package/dist/types/plan-lint.d.ts +0 -16
  186. package/dist/types/plan-parser.d.ts +0 -38
  187. package/dist/types/plan-paths.d.ts +0 -36
  188. package/dist/types/port-forward-client.d.ts +0 -8
  189. package/dist/types/project-checkout-garbage.d.ts +0 -86
  190. package/dist/types/project-mirror-fetch-policy.d.ts +0 -84
  191. package/dist/types/project-mirror-refs-token.d.ts +0 -53
  192. package/dist/types/project-workspace-state.d.ts +0 -188
  193. package/dist/types/project-worktrees.d.ts +0 -397
  194. package/dist/types/pty-output-coalescer.d.ts +0 -20
  195. package/dist/types/recovery-journal-protocol.d.ts +0 -35
  196. package/dist/types/recovery-journal-runtime.d.ts +0 -12
  197. package/dist/types/recovery-journal-stall-fixture.d.ts +0 -1
  198. package/dist/types/recovery-journal-thread.d.ts +0 -1
  199. package/dist/types/recovery-journal.d.ts +0 -248
  200. package/dist/types/recovery-output-window.d.ts +0 -19
  201. package/dist/types/recovery-protocol.d.ts +0 -59
  202. package/dist/types/recovery-store.d.ts +0 -52
  203. package/dist/types/registry-auth.d.ts +0 -47
  204. package/dist/types/repository-transition-policy.d.ts +0 -26
  205. package/dist/types/runtime-version.d.ts +0 -1
  206. package/dist/types/session-file-mutations.d.ts +0 -22
  207. package/dist/types/supervisor-daemonized-fixture.d.ts +0 -1
  208. package/dist/types/supervisor-launcher-cleanup-fixture.d.ts +0 -1
  209. package/dist/types/supervisor-signal-fixture.d.ts +0 -1
  210. package/dist/types/supervisor.d.ts +0 -23
  211. package/dist/types/three-way-merge.d.ts +0 -77
  212. package/dist/types/working-tree-mirror.d.ts +0 -424
  213. package/dist/types/workspace-automatic-sync-policy.d.ts +0 -57
  214. package/dist/types/workspace-branch-incarnation-policy.d.ts +0 -14
  215. package/dist/types/workspace-command-sync-policy.d.ts +0 -57
  216. package/dist/types/workspace-command-targets.d.ts +0 -37
  217. package/dist/types/workspace-filesystem-executor-thread.d.ts +0 -1
  218. package/dist/types/workspace-filesystem-executor.d.ts +0 -123
  219. package/dist/types/workspace-filesystem-job-types.d.ts +0 -302
  220. package/dist/types/workspace-filesystem-jobs.d.ts +0 -7
  221. package/dist/types/workspace-git-sync.d.ts +0 -514
  222. package/dist/types/workspace-hydration-ledger.d.ts +0 -76
  223. package/dist/types/workspace-hydration-merge.d.ts +0 -103
  224. package/dist/types/workspace-hydration-recovery-state.d.ts +0 -10
  225. package/dist/types/workspace-incident-state.d.ts +0 -19
  226. package/dist/types/workspace-merge-projection.d.ts +0 -69
  227. package/dist/types/workspace-mount-boundary.d.ts +0 -10
  228. package/dist/types/workspace-mount-hold-fence.d.ts +0 -42
  229. package/dist/types/workspace-mutation-gate.d.ts +0 -42
  230. package/dist/types/workspace-path-move.d.ts +0 -21
  231. package/dist/types/workspace-preserve-only-policy.d.ts +0 -15
  232. package/dist/types/workspace-project-config-policy.d.ts +0 -48
  233. package/dist/types/workspace-projection-ledger.d.ts +0 -59
  234. package/dist/types/workspace-publication-evidence.d.ts +0 -17
  235. package/dist/types/workspace-sync-coalescer.d.ts +0 -28
  236. /package/dist/types/{credential-authority-lock-fixture.d.ts → runtime/releases/main.d.ts} +0 -0
@@ -1,206 +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 port_forward_client_exports = {};
30
- __export(port_forward_client_exports, {
31
- openWorkerPortForwardRelay: () => openWorkerPortForwardRelay
32
- });
33
- module.exports = __toCommonJS(port_forward_client_exports);
34
- var import_node_net = __toESM(require("node:net"), 1);
35
- var import_ws = __toESM(require("ws"), 1);
36
- const RELAY_FRAME_BYTES = 64 * 1024;
37
- const RELAY_PAUSE_BYTES = 1024 * 1024;
38
- const RELAY_RESUME_BYTES = 256 * 1024;
39
- const LOOPBACK_HOSTS = ["127.0.0.1", "::1"];
40
- function relayUrl(baseUrl, label, forwardId, relayConnectionId) {
41
- const url = new URL("/worker/port-forward/ws", baseUrl);
42
- url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
43
- url.searchParams.set("label", label);
44
- url.searchParams.set("forward", forwardId);
45
- url.searchParams.set("connection", relayConnectionId);
46
- return url.toString();
47
- }
48
- function loopbackAddress(host, port) {
49
- return host.includes(":") ? `[${host}]:${port}` : `${host}:${port}`;
50
- }
51
- function rawDataBuffer(data) {
52
- if (Buffer.isBuffer(data)) return data;
53
- if (Array.isArray(data)) return Buffer.concat(data);
54
- return Buffer.from(data);
55
- }
56
- function openWorkerPortForwardRelay(options) {
57
- const relay = new import_ws.default(relayUrl(options.baseUrl, options.label, options.forwardId, options.relayConnectionId), {
58
- headers: { Authorization: `Bearer ${options.token}` },
59
- perMessageDeflate: false
60
- });
61
- let socket;
62
- let relayReady = false;
63
- let targetReady = false;
64
- let targetEndRequested = false;
65
- let targetFailure;
66
- const pendingChunks = [];
67
- let pendingBytes = 0;
68
- const pendingWrites = [];
69
- let pendingWriteBytes = 0;
70
- let closing = false;
71
- let resumeTimer;
72
- const maybeResume = () => {
73
- if (relayReady && targetReady && !resumeTimer) socket?.resume();
74
- };
75
- const cleanup = () => {
76
- if (closing) return;
77
- closing = true;
78
- if (resumeTimer) clearInterval(resumeTimer);
79
- socket?.destroy();
80
- if (relay.readyState === import_ws.default.OPEN || relay.readyState === import_ws.default.CONNECTING) relay.close();
81
- };
82
- const sendError = (message) => {
83
- if (closing) return;
84
- const payload = JSON.stringify({ type: "error", error: message });
85
- if (relay.readyState === import_ws.default.CONNECTING) {
86
- closing = true;
87
- if (resumeTimer) clearInterval(resumeTimer);
88
- socket?.destroy();
89
- relay.once("open", () => {
90
- relay.send(payload);
91
- relay.close();
92
- });
93
- return;
94
- }
95
- if (relay.readyState === import_ws.default.OPEN) relay.send(payload);
96
- cleanup();
97
- };
98
- const waitForRelayDrain = () => {
99
- if (resumeTimer || relay.bufferedAmount <= RELAY_PAUSE_BYTES) return;
100
- socket?.pause();
101
- resumeTimer = setInterval(() => {
102
- if (relay.readyState !== import_ws.default.OPEN) return cleanup();
103
- if (relay.bufferedAmount > RELAY_RESUME_BYTES) return;
104
- clearInterval(resumeTimer);
105
- resumeTimer = void 0;
106
- maybeResume();
107
- }, 10);
108
- };
109
- const sendChunk = (chunk) => {
110
- for (let offset = 0; offset < chunk.byteLength; offset += RELAY_FRAME_BYTES) {
111
- relay.send(chunk.subarray(offset, Math.min(chunk.byteLength, offset + RELAY_FRAME_BYTES)), { binary: true });
112
- }
113
- waitForRelayDrain();
114
- };
115
- const adoptTarget = (target, host) => {
116
- if (closing) return target.destroy();
117
- socket = target;
118
- target.on("data", (chunk) => {
119
- if (!relayReady || relay.readyState !== import_ws.default.OPEN) {
120
- pendingBytes += chunk.byteLength;
121
- if (pendingBytes > RELAY_PAUSE_BYTES) return cleanup();
122
- pendingChunks.push(Buffer.from(chunk));
123
- target.pause();
124
- return;
125
- }
126
- sendChunk(chunk);
127
- });
128
- target.on("end", () => {
129
- if (relay.readyState === import_ws.default.OPEN) relay.send(JSON.stringify({ type: "end" }));
130
- });
131
- target.on("error", (error) => sendError(`Connection to ${loopbackAddress(host, options.workerPort)} failed: ${error.message}`));
132
- target.on("close", cleanup);
133
- target.pause();
134
- targetReady = true;
135
- for (const chunk of pendingWrites.splice(0)) target.write(chunk);
136
- pendingWriteBytes = 0;
137
- if (targetFailure) return void target.destroy(targetFailure);
138
- if (targetEndRequested) target.end();
139
- maybeResume();
140
- };
141
- const dialFailures = [];
142
- const dialTarget = (host, fallbackHosts2) => {
143
- if (closing) return;
144
- const candidate = import_node_net.default.createConnection({ host, port: options.workerPort, allowHalfOpen: true });
145
- candidate.pause();
146
- candidate.setNoDelay(true);
147
- const onDialError = (error) => {
148
- candidate.destroy();
149
- dialFailures.push(`${loopbackAddress(host, options.workerPort)} (${error.code ?? error.message})`);
150
- const [nextHost, ...rest] = fallbackHosts2;
151
- if (nextHost) return dialTarget(nextHost, rest);
152
- sendError(
153
- `Could not connect to ${dialFailures.join(" or ")} on the worker. Nothing is listening on either loopback address for port ${options.workerPort} \u2014 make sure the server is running and bound to a loopback or wildcard host.`
154
- );
155
- };
156
- candidate.once("error", onDialError);
157
- candidate.once("connect", () => {
158
- candidate.off("error", onDialError);
159
- adoptTarget(candidate, host);
160
- });
161
- };
162
- relay.on("message", (data, isBinary) => {
163
- if (!isBinary) {
164
- let control;
165
- try {
166
- control = JSON.parse(rawDataBuffer(data).toString("utf8"));
167
- } catch {
168
- return cleanup();
169
- }
170
- if (control.type === "ready") {
171
- relayReady = true;
172
- for (const chunk2 of pendingChunks.splice(0)) sendChunk(chunk2);
173
- pendingBytes = 0;
174
- maybeResume();
175
- } else if (control.type === "end") {
176
- if (socket) socket.end();
177
- else targetEndRequested = true;
178
- } else if (control.type === "error") {
179
- const failure = new Error(control.error || "Port-forward relay failed.");
180
- if (socket) socket.destroy(failure);
181
- else targetFailure = failure;
182
- }
183
- return;
184
- }
185
- const chunk = rawDataBuffer(data);
186
- if (!socket) {
187
- pendingWriteBytes += chunk.byteLength;
188
- if (pendingWriteBytes > RELAY_PAUSE_BYTES) return cleanup();
189
- pendingWrites.push(Buffer.from(chunk));
190
- return;
191
- }
192
- const target = socket;
193
- if (!target.write(chunk)) {
194
- relay.pause();
195
- target.once("drain", () => relay.resume());
196
- }
197
- });
198
- relay.on("error", cleanup);
199
- relay.once("close", cleanup);
200
- const [primaryHost, ...fallbackHosts] = LOOPBACK_HOSTS;
201
- dialTarget(primaryHost, fallbackHosts);
202
- }
203
- // Annotate the CommonJS export names for ESM import in node:
204
- 0 && (module.exports = {
205
- openWorkerPortForwardRelay
206
- });
@@ -1,117 +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 process_tree_exports = {};
20
- __export(process_tree_exports, {
21
- terminateProcessTree: () => terminateProcessTree
22
- });
23
- module.exports = __toCommonJS(process_tree_exports);
24
- const DEFAULT_TERMINATION_GRACE_MS = 2e3;
25
- const DEFAULT_FORCE_KILL_WAIT_MS = 2e3;
26
- const PROCESS_GROUP_POLL_INTERVAL_MS = 25;
27
- const processTerminations = /* @__PURE__ */ new WeakMap();
28
- function errorCode(error) {
29
- if (!error || typeof error !== "object" || !("code" in error)) {
30
- return void 0;
31
- }
32
- return typeof error.code === "string" ? error.code : void 0;
33
- }
34
- function delay(ms) {
35
- return new Promise((resolve) => setTimeout(resolve, ms));
36
- }
37
- function isPosixProcessGroupRunning(processGroupId) {
38
- try {
39
- process.kill(-processGroupId, 0);
40
- return true;
41
- } catch (error) {
42
- if (errorCode(error) === "ESRCH") {
43
- return false;
44
- }
45
- if (errorCode(error) === "EPERM") {
46
- return true;
47
- }
48
- throw error;
49
- }
50
- }
51
- function signalPosixProcessGroup(processGroupId, signal) {
52
- try {
53
- process.kill(-processGroupId, signal);
54
- } catch (error) {
55
- if (errorCode(error) !== "ESRCH") {
56
- throw error;
57
- }
58
- }
59
- }
60
- async function waitForPosixProcessGroupExit(processGroupId, timeoutMs) {
61
- const deadline = Date.now() + Math.max(0, timeoutMs);
62
- while (isPosixProcessGroupRunning(processGroupId)) {
63
- const remainingMs = deadline - Date.now();
64
- if (remainingMs <= 0) {
65
- return false;
66
- }
67
- await delay(Math.min(PROCESS_GROUP_POLL_INTERVAL_MS, remainingMs));
68
- }
69
- return true;
70
- }
71
- async function runWindowsTaskkill(pid) {
72
- const taskkill = Bun.spawn(["taskkill", "/PID", String(pid), "/T", "/F"], {
73
- stdout: "ignore",
74
- stderr: "pipe"
75
- });
76
- const [exitCode, stderr] = await Promise.all([
77
- taskkill.exited,
78
- taskkill.stderr ? new Response(taskkill.stderr).text() : Promise.resolve("")
79
- ]);
80
- if (exitCode !== 0 && !/not found|no running instance/i.test(stderr)) {
81
- throw new Error(`Failed to terminate process tree ${pid}: ${stderr.trim() || `taskkill exited ${exitCode}`}`);
82
- }
83
- }
84
- async function terminateProcessTreeOnce(subprocess, options) {
85
- if (!Number.isSafeInteger(subprocess.pid) || subprocess.pid <= 0) {
86
- throw new Error(`Cannot terminate invalid subprocess PID: ${subprocess.pid}`);
87
- }
88
- if (process.platform === "win32") {
89
- await runWindowsTaskkill(subprocess.pid);
90
- return;
91
- }
92
- const graceMs = options.graceMs ?? DEFAULT_TERMINATION_GRACE_MS;
93
- const forceKillWaitMs = options.forceKillWaitMs ?? DEFAULT_FORCE_KILL_WAIT_MS;
94
- signalPosixProcessGroup(subprocess.pid, "SIGTERM");
95
- if (await waitForPosixProcessGroupExit(subprocess.pid, graceMs)) {
96
- return;
97
- }
98
- signalPosixProcessGroup(subprocess.pid, "SIGKILL");
99
- if (!await waitForPosixProcessGroupExit(subprocess.pid, forceKillWaitMs)) {
100
- throw new Error(`Process group ${subprocess.pid} remained active after SIGKILL`);
101
- }
102
- }
103
- function terminateProcessTree(subprocess, options = {}) {
104
- const pending = processTerminations.get(subprocess);
105
- if (pending) {
106
- return pending;
107
- }
108
- const termination = terminateProcessTreeOnce(subprocess, options).finally(() => {
109
- processTerminations.delete(subprocess);
110
- });
111
- processTerminations.set(subprocess, termination);
112
- return termination;
113
- }
114
- // Annotate the CommonJS export names for ESM import in node:
115
- 0 && (module.exports = {
116
- terminateProcessTree
117
- });
@@ -1,219 +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_checkout_garbage_exports = {};
30
- __export(project_checkout_garbage_exports, {
31
- PROJECT_DELETED_CHECKOUTS_DIRECTORY: () => PROJECT_DELETED_CHECKOUTS_DIRECTORY,
32
- ProjectCheckoutGarbageCollector: () => ProjectCheckoutGarbageCollector,
33
- discoverStagedProjectCheckouts: () => discoverStagedProjectCheckouts,
34
- isStagedProjectCheckoutPath: () => isStagedProjectCheckoutPath,
35
- ownedStagedPath: () => ownedStagedPath,
36
- removeStagedProjectCheckout: () => removeStagedProjectCheckout,
37
- stageProjectCheckoutForDeletion: () => stageProjectCheckoutForDeletion,
38
- stageProjectForDeletion: () => stageProjectForDeletion
39
- });
40
- module.exports = __toCommonJS(project_checkout_garbage_exports);
41
- var import_node_crypto = require("node:crypto");
42
- var import_node_fs = __toESM(require("node:fs"), 1);
43
- var import_node_path = __toESM(require("node:path"), 1);
44
- const PROJECT_DELETED_CHECKOUTS_DIRECTORY = ".r5d-deleted";
45
- function isRealDirectory(candidate) {
46
- try {
47
- return import_node_fs.default.lstatSync(candidate).isDirectory();
48
- } catch {
49
- return false;
50
- }
51
- }
52
- function stageProjectCheckoutForDeletion(projectRoot, branchName, checkoutPath) {
53
- const garbageRoot = import_node_path.default.join(projectRoot, PROJECT_DELETED_CHECKOUTS_DIRECTORY);
54
- if (!isRealDirectory(checkoutPath)) throw new Error(`Cannot stage ${checkoutPath} for deletion: not a directory`);
55
- import_node_fs.default.mkdirSync(garbageRoot, { recursive: true });
56
- if (!isRealDirectory(garbageRoot)) throw new Error(`Cannot stage ${checkoutPath} for deletion: ${garbageRoot} is not a directory`);
57
- const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
58
- const target = import_node_path.default.join(garbageRoot, `${branchName.replace(/\//g, "__")}-${timestamp}-${(0, import_node_crypto.randomUUID)().slice(0, 8)}`);
59
- import_node_fs.default.renameSync(checkoutPath, target);
60
- return target;
61
- }
62
- function stageProjectForDeletion(projectsRoot, projectRoot) {
63
- const root = import_node_path.default.resolve(projectsRoot);
64
- const resolved = import_node_path.default.resolve(projectRoot);
65
- const relative = import_node_path.default.relative(root, resolved);
66
- const segments = relative.split(import_node_path.default.sep);
67
- if (!relative || relative.startsWith("..") || import_node_path.default.isAbsolute(relative) || segments.length !== 2 || segments.some((segment) => !segment || segment.startsWith("."))) {
68
- throw new Error(`Cannot stage ${projectRoot} for deletion: not a project root under ${projectsRoot}`);
69
- }
70
- if (!isRealDirectory(resolved)) throw new Error(`Cannot stage ${projectRoot} for deletion: not a directory`);
71
- const garbageRoot = import_node_path.default.join(root, segments[0], PROJECT_DELETED_CHECKOUTS_DIRECTORY);
72
- import_node_fs.default.mkdirSync(garbageRoot, { recursive: true });
73
- if (!isRealDirectory(garbageRoot)) throw new Error(`Cannot stage ${projectRoot} for deletion: ${garbageRoot} is not a directory`);
74
- const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
75
- const target = import_node_path.default.join(garbageRoot, `${segments[1]}-${timestamp}-${(0, import_node_crypto.randomUUID)().slice(0, 8)}`);
76
- import_node_fs.default.renameSync(resolved, target);
77
- return target;
78
- }
79
- function isStagedProjectCheckoutPath(projectsRoot, candidate) {
80
- const relative = import_node_path.default.relative(import_node_path.default.resolve(projectsRoot), import_node_path.default.resolve(candidate));
81
- if (!relative || relative.startsWith("..") || import_node_path.default.isAbsolute(relative)) return false;
82
- const segments = relative.split(import_node_path.default.sep);
83
- const entry = segments[segments.length - 1];
84
- if (!entry || entry.startsWith(".")) return false;
85
- if (segments.length === 4)
86
- return segments[2] === PROJECT_DELETED_CHECKOUTS_DIRECTORY && !segments[0].startsWith(".") && !segments[1].startsWith(".");
87
- if (segments.length === 3) return segments[1] === PROJECT_DELETED_CHECKOUTS_DIRECTORY && !segments[0].startsWith(".");
88
- return false;
89
- }
90
- function ownedStagedPath(projectsRoot, candidate) {
91
- const root = import_node_path.default.resolve(projectsRoot);
92
- const resolved = import_node_path.default.resolve(candidate);
93
- if (!isStagedProjectCheckoutPath(root, resolved)) return null;
94
- let current = root;
95
- for (const segment of import_node_path.default.relative(root, import_node_path.default.dirname(resolved)).split(import_node_path.default.sep)) {
96
- current = import_node_path.default.join(current, segment);
97
- if (!isRealDirectory(current)) return null;
98
- }
99
- let stat;
100
- try {
101
- stat = import_node_fs.default.lstatSync(resolved);
102
- } catch {
103
- return null;
104
- }
105
- if (stat.isSymbolicLink()) return { kind: "link" };
106
- return stat.isDirectory() ? { kind: "directory" } : null;
107
- }
108
- function realDirectoryEntries(directory) {
109
- if (!isRealDirectory(directory)) return [];
110
- try {
111
- return import_node_fs.default.readdirSync(directory, { withFileTypes: true }).map((entry) => entry.name).sort();
112
- } catch {
113
- return [];
114
- }
115
- }
116
- function discoverStagedProjectCheckouts(projectsRoot) {
117
- const root = import_node_path.default.resolve(projectsRoot);
118
- const staged = [];
119
- for (const namespace of realDirectoryEntries(root)) {
120
- if (namespace.startsWith(".")) continue;
121
- const namespaceGarbageRoot = import_node_path.default.join(root, namespace, PROJECT_DELETED_CHECKOUTS_DIRECTORY);
122
- for (const entry of realDirectoryEntries(namespaceGarbageRoot)) {
123
- const candidate = import_node_path.default.join(namespaceGarbageRoot, entry);
124
- if (ownedStagedPath(root, candidate)) staged.push(candidate);
125
- }
126
- for (const project of realDirectoryEntries(import_node_path.default.join(root, namespace))) {
127
- if (project.startsWith(".")) continue;
128
- const garbageRoot = import_node_path.default.join(root, namespace, project, PROJECT_DELETED_CHECKOUTS_DIRECTORY);
129
- for (const entry of realDirectoryEntries(garbageRoot)) {
130
- const candidate = import_node_path.default.join(garbageRoot, entry);
131
- if (ownedStagedPath(root, candidate)) staged.push(candidate);
132
- }
133
- }
134
- }
135
- return staged;
136
- }
137
- async function removeStagedProjectCheckout(stagedPath) {
138
- if (import_node_fs.default.lstatSync(stagedPath).isSymbolicLink()) {
139
- import_node_fs.default.unlinkSync(stagedPath);
140
- return;
141
- }
142
- if (process.platform === "win32") {
143
- await import_node_fs.default.promises.rm(stagedPath, { recursive: true, force: true });
144
- return;
145
- }
146
- const command = ["rm", "-rf", "--", stagedPath];
147
- if (Bun.which("nice")) command.unshift("nice", "-n", "19");
148
- if (process.platform === "linux" && Bun.which("ionice")) command.unshift("ionice", "-c", "3");
149
- const child = Bun.spawn(command, { stdin: "ignore", stdout: "ignore", stderr: "pipe" });
150
- const [exitCode, stderr] = await Promise.all([child.exited, new Response(child.stderr).text()]);
151
- if (exitCode !== 0) throw new Error(`rm exited ${exitCode}: ${stderr.trim()}`);
152
- if (import_node_fs.default.existsSync(stagedPath)) throw new Error("staged checkout still exists after removal");
153
- }
154
- class ProjectCheckoutGarbageCollector {
155
- projectsRoot;
156
- remove;
157
- log;
158
- queued = /* @__PURE__ */ new Set();
159
- tail = Promise.resolve();
160
- collectedCount = 0;
161
- constructor(options) {
162
- this.projectsRoot = import_node_path.default.resolve(options.projectsRoot);
163
- this.remove = options.remove ?? removeStagedProjectCheckout;
164
- this.log = options.log ?? ((message) => process.stderr.write(`${message}
165
- `));
166
- }
167
- /** Number of removals that have completed successfully. */
168
- get collected() {
169
- return this.collectedCount;
170
- }
171
- /** Resolves once everything queued so far has been attempted. */
172
- get idle() {
173
- return this.tail;
174
- }
175
- enqueue(stagedPath) {
176
- const resolved = import_node_path.default.resolve(stagedPath);
177
- if (!ownedStagedPath(this.projectsRoot, resolved)) {
178
- throw new Error(`Refusing to collect ${stagedPath}: not a staged checkout under ${this.projectsRoot}`);
179
- }
180
- if (this.queued.has(resolved)) return;
181
- this.queued.add(resolved);
182
- this.tail = this.tail.then(async () => {
183
- try {
184
- const owned = ownedStagedPath(this.projectsRoot, resolved);
185
- if (owned) {
186
- const startedAt = performance.now();
187
- await this.remove(resolved);
188
- this.collectedCount += 1;
189
- this.log(`[r5d-worker] collected deleted checkout ${resolved} in ${Math.round(performance.now() - startedAt)}ms`);
190
- } else if (import_node_fs.default.existsSync(resolved) || isRealDirectory(import_node_path.default.dirname(resolved))) {
191
- this.log(`[r5d-worker] skipped deleted checkout ${resolved}: no longer an owned staged checkout`);
192
- }
193
- } catch (error) {
194
- this.log(
195
- `[r5d-worker] deleted checkout ${resolved} could not be collected yet: ${error instanceof Error ? error.message : String(error)}`
196
- );
197
- } finally {
198
- this.queued.delete(resolved);
199
- }
200
- });
201
- }
202
- /** Enqueue every staged checkout left behind by an earlier process. */
203
- sweep() {
204
- const staged = discoverStagedProjectCheckouts(this.projectsRoot);
205
- for (const stagedPath of staged) this.enqueue(stagedPath);
206
- return staged.length;
207
- }
208
- }
209
- // Annotate the CommonJS export names for ESM import in node:
210
- 0 && (module.exports = {
211
- PROJECT_DELETED_CHECKOUTS_DIRECTORY,
212
- ProjectCheckoutGarbageCollector,
213
- discoverStagedProjectCheckouts,
214
- isStagedProjectCheckoutPath,
215
- ownedStagedPath,
216
- removeStagedProjectCheckout,
217
- stageProjectCheckoutForDeletion,
218
- stageProjectForDeletion
219
- });
@@ -1,82 +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 project_mirror_fetch_policy_exports = {};
20
- __export(project_mirror_fetch_policy_exports, {
21
- parseProjectMirrorRefsTokensMessage: () => parseProjectMirrorRefsTokensMessage,
22
- planProjectMirrorObservationFetch: () => planProjectMirrorObservationFetch,
23
- projectMirrorFetchDecision: () => projectMirrorFetchDecision
24
- });
25
- module.exports = __toCommonJS(project_mirror_fetch_policy_exports);
26
- function projectMirrorFetchDecision(input) {
27
- if (!input.skippingEnabled) return { fetch: true, reason: "skipping_disabled" };
28
- if (input.advertisedToken === void 0) return { fetch: true, reason: "no_advertised_token" };
29
- if (input.fetchedToken === void 0) return { fetch: true, reason: "never_fetched" };
30
- if (input.advertisedToken !== input.fetchedToken) return { fetch: true, reason: "token_changed" };
31
- return { fetch: false, reason: "token_match" };
32
- }
33
- function planProjectMirrorObservationFetch(input) {
34
- if (!input.skippingEnabled) return { scope: "project", reason: "skipping_disabled" };
35
- if (input.advertisedMountTokens === void 0) {
36
- const decision = projectMirrorFetchDecision({
37
- advertisedToken: input.advertisedProjectToken,
38
- fetchedToken: input.fetchedProjectToken,
39
- skippingEnabled: true
40
- });
41
- return decision.fetch ? { scope: "project", reason: decision.reason } : { scope: "none" };
42
- }
43
- const mounts = [];
44
- for (const branchName of [...input.branchNames].sort()) {
45
- const decision = projectMirrorFetchDecision({
46
- advertisedToken: input.advertisedMountTokens.get(branchName),
47
- fetchedToken: input.fetchedMountTokens.get(branchName),
48
- skippingEnabled: true
49
- });
50
- if (decision.fetch) mounts.push({ branchName, reason: decision.reason });
51
- }
52
- return mounts.length === 0 ? { scope: "none" } : { scope: "mounts", mounts };
53
- }
54
- const TOKEN_RE = /^[0-9a-f]{64}$/;
55
- const GIT_OBJECT_NAME_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
56
- function parseProjectMirrorRefsTokensMessage(message) {
57
- const projectTokens = /* @__PURE__ */ new Map();
58
- if (message.tokens && typeof message.tokens === "object") {
59
- for (const [projectId, token] of Object.entries(message.tokens)) {
60
- if (typeof token === "string" && TOKEN_RE.test(token)) projectTokens.set(projectId, token);
61
- }
62
- }
63
- const mountTokens = /* @__PURE__ */ new Map();
64
- if (message.mountTokens && typeof message.mountTokens === "object") {
65
- for (const [projectId, tokensByBranch] of Object.entries(message.mountTokens)) {
66
- if (!tokensByBranch || typeof tokensByBranch !== "object") continue;
67
- const perMount = /* @__PURE__ */ new Map();
68
- for (const [branchName, token] of Object.entries(tokensByBranch)) {
69
- if (typeof token === "string" && TOKEN_RE.test(token)) perMount.set(branchName, token);
70
- }
71
- mountTokens.set(projectId, perMount);
72
- }
73
- }
74
- const workspaceHead = typeof message.workspaceHead === "string" && GIT_OBJECT_NAME_RE.test(message.workspaceHead) ? message.workspaceHead : void 0;
75
- return { projectTokens, mountTokens, workspaceHead };
76
- }
77
- // Annotate the CommonJS export names for ESM import in node:
78
- 0 && (module.exports = {
79
- parseProjectMirrorRefsTokensMessage,
80
- planProjectMirrorObservationFetch,
81
- projectMirrorFetchDecision
82
- });