@ricsam/r5d-worker 0.0.59 → 0.0.60

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.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/r5d-worker",
3
- "version": "0.0.59",
3
+ "version": "0.0.60",
4
4
  "type": "commonjs"
5
5
  }
@@ -28,85 +28,23 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var workspace_convergence_exports = {};
30
30
  __export(workspace_convergence_exports, {
31
- ExplicitWorkspaceCheckpointQueue: () => ExplicitWorkspaceCheckpointQueue,
32
- WORKSPACE_CHECKPOINT_QUIET_MS: () => WORKSPACE_CHECKPOINT_QUIET_MS,
31
+ ExplicitWorkspacePublicationQueue: () => ExplicitWorkspacePublicationQueue,
33
32
  WORKSPACE_IDLE_SAFETY_SCAN_MS: () => WORKSPACE_IDLE_SAFETY_SCAN_MS,
33
+ WORKSPACE_PUBLICATION_QUIET_MS: () => WORKSPACE_PUBLICATION_QUIET_MS,
34
34
  WorkspaceConvergenceState: () => WorkspaceConvergenceState,
35
- WorkspaceFilesystemWriterGate: () => WorkspaceFilesystemWriterGate,
36
35
  WorkspaceManifestRevisionFence: () => WorkspaceManifestRevisionFence,
37
36
  processWorkspaceConvergenceState: () => processWorkspaceConvergenceState,
38
- processWorkspaceFilesystemWriterGate: () => processWorkspaceFilesystemWriterGate,
39
37
  readWorkspaceConvergenceState: () => readWorkspaceConvergenceState,
40
- waitForWorkspaceCheckpointOnShutdown: () => waitForWorkspaceCheckpointOnShutdown,
41
- workspaceCheckpointIncidentAction: () => workspaceCheckpointIncidentAction,
42
- workspaceCheckpointTelemetry: () => workspaceCheckpointTelemetry
38
+ waitForWorkspacePublicationOnShutdown: () => waitForWorkspacePublicationOnShutdown,
39
+ workspacePublicationIncidentAction: () => workspacePublicationIncidentAction,
40
+ workspacePublicationTelemetry: () => workspacePublicationTelemetry
43
41
  });
44
42
  module.exports = __toCommonJS(workspace_convergence_exports);
45
43
  var import_node_fs = __toESM(require("node:fs"), 1);
46
44
  var import_node_path = __toESM(require("node:path"), 1);
47
- const WORKSPACE_CHECKPOINT_QUIET_MS = 5e3;
45
+ const WORKSPACE_PUBLICATION_QUIET_MS = 5e3;
48
46
  const WORKSPACE_IDLE_SAFETY_SCAN_MS = 6e4;
49
47
  const WORKSPACE_MANIFEST_REVISION_PATTERN = /^[0-9a-f]{64}$/;
50
- class WorkspaceFilesystemWriterGate {
51
- activeWriters = 0;
52
- checkpointActive = false;
53
- waitingWriters = [];
54
- waitingCheckpoints = [];
55
- acquireWriter() {
56
- if (!this.checkpointActive && this.waitingCheckpoints.length === 0) {
57
- this.activeWriters += 1;
58
- return Promise.resolve(this.writerRelease());
59
- }
60
- return new Promise((resolve) => this.waitingWriters.push(resolve));
61
- }
62
- tryAcquireCheckpoint() {
63
- if (this.checkpointActive || this.activeWriters > 0 || this.waitingCheckpoints.length > 0) return null;
64
- this.checkpointActive = true;
65
- return this.checkpointRelease();
66
- }
67
- acquireCheckpoint() {
68
- const immediate = this.tryAcquireCheckpoint();
69
- if (immediate) return Promise.resolve(immediate);
70
- return new Promise((resolve) => this.waitingCheckpoints.push(resolve));
71
- }
72
- checkpointRelease() {
73
- let released = false;
74
- return () => {
75
- if (released) return;
76
- released = true;
77
- this.checkpointActive = false;
78
- this.drain();
79
- };
80
- }
81
- writerRelease() {
82
- let released = false;
83
- return () => {
84
- if (released) return;
85
- released = true;
86
- this.activeWriters -= 1;
87
- this.drain();
88
- };
89
- }
90
- drain() {
91
- if (this.checkpointActive || this.activeWriters > 0) return;
92
- const checkpoint = this.waitingCheckpoints.shift();
93
- if (checkpoint) {
94
- this.checkpointActive = true;
95
- checkpoint(this.checkpointRelease());
96
- return;
97
- }
98
- while (this.waitingWriters.length > 0) {
99
- const resolve = this.waitingWriters.shift();
100
- if (!resolve) continue;
101
- this.activeWriters += 1;
102
- resolve(this.writerRelease());
103
- }
104
- }
105
- }
106
- const PROCESS_WORKSPACE_FILESYSTEM_WRITERS = new WorkspaceFilesystemWriterGate();
107
- function processWorkspaceFilesystemWriterGate() {
108
- return PROCESS_WORKSPACE_FILESYSTEM_WRITERS;
109
- }
110
48
  class WorkspaceManifestRevisionFence {
111
49
  sequence = 0;
112
50
  requestedRevision = null;
@@ -132,7 +70,7 @@ class WorkspaceManifestRevisionFence {
132
70
  return this.completedRevision === this.requestedRevision ? this.completedRevision : null;
133
71
  }
134
72
  }
135
- function workspaceCheckpointTelemetry(input) {
73
+ function workspacePublicationTelemetry(input) {
136
74
  return {
137
75
  totalMs: Math.max(0, input.finishedAt - input.requestedAt),
138
76
  queueMs: Math.max(0, input.prepareStartedAt - input.requestedAt),
@@ -140,21 +78,21 @@ function workspaceCheckpointTelemetry(input) {
140
78
  synchronizeMs: Math.max(0, input.finishedAt - input.synchronizeStartedAt)
141
79
  };
142
80
  }
143
- function workspaceCheckpointIncidentAction(requestId) {
81
+ function workspacePublicationIncidentAction(requestId) {
144
82
  return requestId ? "request_terminal_authority" : "defer_automatic";
145
83
  }
146
- class ExplicitWorkspaceCheckpointQueue {
84
+ class ExplicitWorkspacePublicationQueue {
147
85
  scheduled;
148
86
  queued = [];
149
- schedule(checkpoint, pendingRequestId) {
150
- if (pendingRequestId === checkpoint.requestId || this.scheduled?.requestId === checkpoint.requestId || this.queued.some((queued) => queued.requestId === checkpoint.requestId)) {
87
+ schedule(publication, pendingRequestId) {
88
+ if (pendingRequestId === publication.requestId || this.scheduled?.requestId === publication.requestId || this.queued.some((queued) => queued.requestId === publication.requestId)) {
151
89
  return false;
152
90
  }
153
91
  if (pendingRequestId || this.scheduled) {
154
- this.queued.push(checkpoint);
92
+ this.queued.push(publication);
155
93
  return false;
156
94
  }
157
- this.scheduled = checkpoint;
95
+ this.scheduled = publication;
158
96
  return true;
159
97
  }
160
98
  hasScheduled() {
@@ -163,11 +101,11 @@ class ExplicitWorkspaceCheckpointQueue {
163
101
  consumeScheduled(requestId) {
164
102
  if (this.scheduled?.requestId === requestId) this.scheduled = void 0;
165
103
  }
166
- enqueue(checkpoint, pendingRequestId) {
167
- if (pendingRequestId === checkpoint.requestId || this.scheduled?.requestId === checkpoint.requestId || this.queued.some((queued) => queued.requestId === checkpoint.requestId)) {
104
+ enqueue(publication, pendingRequestId) {
105
+ if (pendingRequestId === publication.requestId || this.scheduled?.requestId === publication.requestId || this.queued.some((queued) => queued.requestId === publication.requestId)) {
168
106
  return;
169
107
  }
170
- this.queued.push(checkpoint);
108
+ this.queued.push(publication);
171
109
  }
172
110
  next() {
173
111
  return this.queued.shift();
@@ -205,13 +143,13 @@ class WorkspaceConvergenceState {
205
143
  constructor(statePath) {
206
144
  this.statePath = statePath;
207
145
  this.state = readWorkspaceConvergenceState(statePath);
208
- this.checkpointState = this.state.dirtyGeneration > this.state.publishedGeneration ? "scheduled" : "idle";
146
+ this.publicationState = this.state.dirtyGeneration > this.state.publishedGeneration ? "scheduled" : "idle";
209
147
  }
210
148
  statePath;
211
149
  state;
212
- checkpointState;
150
+ publicationState;
213
151
  snapshot() {
214
- return { ...this.state, checkpointState: this.checkpointState };
152
+ return { ...this.state, publicationState: this.publicationState };
215
153
  }
216
154
  setLocalHead(localHead) {
217
155
  if (!validHead(localHead)) throw new Error("Invalid local workspace head");
@@ -227,39 +165,39 @@ class WorkspaceConvergenceState {
227
165
  }
228
166
  markDirty() {
229
167
  this.state.dirtyGeneration += 1;
230
- if (this.checkpointState === "idle") this.checkpointState = "scheduled";
168
+ if (this.publicationState === "idle") this.publicationState = "scheduled";
231
169
  this.persist();
232
170
  return this.state.dirtyGeneration;
233
171
  }
234
172
  schedule() {
235
- if (this.checkpointState === "idle") this.checkpointState = "scheduled";
173
+ if (this.publicationState === "idle") this.publicationState = "scheduled";
236
174
  }
237
175
  beginPreparing() {
238
- if (this.checkpointState === "preparing" || this.checkpointState === "submitting") {
239
- throw new Error("A workspace checkpoint is already in flight");
176
+ if (this.publicationState === "preparing" || this.publicationState === "submitting") {
177
+ throw new Error("A workspace publication is already in flight");
240
178
  }
241
- this.checkpointState = "preparing";
179
+ this.publicationState = "preparing";
242
180
  }
243
181
  beginSubmitting() {
244
- if (this.checkpointState !== "preparing") throw new Error("Workspace checkpoint authority was not prepared");
245
- this.checkpointState = "submitting";
182
+ if (this.publicationState !== "preparing") throw new Error("Workspace publication authority was not prepared");
183
+ this.publicationState = "submitting";
246
184
  }
247
185
  defer() {
248
- this.checkpointState = "scheduled";
186
+ this.publicationState = "scheduled";
249
187
  }
250
188
  block() {
251
- this.checkpointState = "blocked";
189
+ this.publicationState = "blocked";
252
190
  }
253
191
  releaseBlock() {
254
- this.checkpointState = this.state.dirtyGeneration > this.state.publishedGeneration ? "scheduled" : "idle";
192
+ this.publicationState = this.state.dirtyGeneration > this.state.publishedGeneration ? "scheduled" : "idle";
255
193
  }
256
194
  observeIncidentState(blocked) {
257
- if (this.checkpointState === "preparing" || this.checkpointState === "submitting") return;
195
+ if (this.publicationState === "preparing" || this.publicationState === "submitting") return;
258
196
  if (blocked) this.block();
259
197
  else this.releaseBlock();
260
198
  }
261
- resetTransientCheckpointState() {
262
- this.checkpointState = this.state.dirtyGeneration > this.state.publishedGeneration ? "scheduled" : "idle";
199
+ resetTransientPublicationState() {
200
+ this.publicationState = this.state.dirtyGeneration > this.state.publishedGeneration ? "scheduled" : "idle";
263
201
  }
264
202
  complete(input) {
265
203
  if (!validGeneration(input.generation) || input.generation > this.state.dirtyGeneration) {
@@ -271,7 +209,7 @@ class WorkspaceConvergenceState {
271
209
  this.state.localHead = input.canonicalHead;
272
210
  this.state.desiredCanonicalHead = input.canonicalHead;
273
211
  }
274
- this.checkpointState = this.state.dirtyGeneration > this.state.publishedGeneration ? "scheduled" : "idle";
212
+ this.publicationState = this.state.dirtyGeneration > this.state.publishedGeneration ? "scheduled" : "idle";
275
213
  this.persist();
276
214
  }
277
215
  persist() {
@@ -291,30 +229,28 @@ function processWorkspaceConvergenceState(statePath) {
291
229
  PROCESS_WORKSPACE_CONVERGENCE_STATES.set(key, created);
292
230
  return created;
293
231
  }
294
- async function waitForWorkspaceCheckpointOnShutdown(input) {
295
- input.forceCheckpoint();
232
+ async function waitForWorkspacePublicationOnShutdown(input) {
233
+ input.forcePublication();
296
234
  const deadline = Date.now() + (input.timeoutMs ?? 1e4);
297
235
  const pollMs = input.pollMs ?? 50;
298
236
  while (Date.now() < deadline) {
299
237
  const snapshot = input.snapshot();
300
- if (snapshot.checkpointState === "blocked") return "blocked";
301
- if (snapshot.checkpointState === "idle" && snapshot.publishedGeneration >= snapshot.dirtyGeneration) return "settled";
238
+ if (snapshot.publicationState === "blocked") return "blocked";
239
+ if (snapshot.publicationState === "idle" && snapshot.publishedGeneration >= snapshot.dirtyGeneration) return "settled";
302
240
  await new Promise((resolve) => setTimeout(resolve, pollMs));
303
241
  }
304
242
  return "timed_out";
305
243
  }
306
244
  // Annotate the CommonJS export names for ESM import in node:
307
245
  0 && (module.exports = {
308
- ExplicitWorkspaceCheckpointQueue,
309
- WORKSPACE_CHECKPOINT_QUIET_MS,
246
+ ExplicitWorkspacePublicationQueue,
310
247
  WORKSPACE_IDLE_SAFETY_SCAN_MS,
248
+ WORKSPACE_PUBLICATION_QUIET_MS,
311
249
  WorkspaceConvergenceState,
312
- WorkspaceFilesystemWriterGate,
313
250
  WorkspaceManifestRevisionFence,
314
251
  processWorkspaceConvergenceState,
315
- processWorkspaceFilesystemWriterGate,
316
252
  readWorkspaceConvergenceState,
317
- waitForWorkspaceCheckpointOnShutdown,
318
- workspaceCheckpointIncidentAction,
319
- workspaceCheckpointTelemetry
253
+ waitForWorkspacePublicationOnShutdown,
254
+ workspacePublicationIncidentAction,
255
+ workspacePublicationTelemetry
320
256
  });
@@ -28,8 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var workspace_manifest_admission_exports = {};
30
30
  __export(workspace_manifest_admission_exports, {
31
- acquireWorkspaceManifestVisibleLease: () => acquireWorkspaceManifestVisibleLease,
32
- inspectWorkspaceManifestAdmission: () => inspectWorkspaceManifestAdmission
31
+ inspectWorkspaceManifestFilesystem: () => inspectWorkspaceManifestFilesystem
33
32
  });
34
33
  module.exports = __toCommonJS(workspace_manifest_admission_exports);
35
34
  var import_node_fs = __toESM(require("node:fs"), 1);
@@ -39,7 +38,7 @@ function hasNormalGitDirectory(checkoutPath) {
39
38
  const gitPath = import_node_path.default.join(checkoutPath, ".git");
40
39
  return import_node_fs.default.existsSync(gitPath) && import_node_fs.default.statSync(gitPath).isDirectory();
41
40
  }
42
- function inspectWorkspaceManifestAdmission(input) {
41
+ function inspectWorkspaceManifestFilesystem(input) {
43
42
  const firstBootstrap = !hasNormalGitDirectory(input.workspaceShadowRoot);
44
43
  const missingCheckouts = [];
45
44
  const migratedProjectIds = [];
@@ -56,15 +55,10 @@ function inspectWorkspaceManifestAdmission(input) {
56
55
  return {
57
56
  firstBootstrap,
58
57
  missingCheckouts,
59
- migratedProjectIds,
60
- requiresVisibleLease: firstBootstrap || migratedProjectIds.length > 0
58
+ migratedProjectIds
61
59
  };
62
60
  }
63
- async function acquireWorkspaceManifestVisibleLease(gate, admission) {
64
- return admission.requiresVisibleLease ? await gate.acquireCheckpoint() : void 0;
65
- }
66
61
  // Annotate the CommonJS export names for ESM import in node:
67
62
  0 && (module.exports = {
68
- acquireWorkspaceManifestVisibleLease,
69
- inspectWorkspaceManifestAdmission
63
+ inspectWorkspaceManifestFilesystem
70
64
  });
@@ -1759,9 +1759,7 @@ function assertWorkspaceQuarantineRef(quarantineRef) {
1759
1759
  const prefix = quarantineRef.startsWith(WORKSPACE_PUBLICATION_REF_PREFIX) ? WORKSPACE_PUBLICATION_REF_PREFIX : WORKSPACE_INTENT_REF_PREFIX;
1760
1760
  const suffix = quarantineRef.slice(prefix.length);
1761
1761
  if (!quarantineRef.startsWith(prefix) || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(suffix)) {
1762
- throw new Error(
1763
- `Workspace candidate ref must be below ${WORKSPACE_PUBLICATION_REF_PREFIX} or ${WORKSPACE_INTENT_REF_PREFIX}`
1764
- );
1762
+ throw new Error(`Workspace candidate ref must be below ${WORKSPACE_PUBLICATION_REF_PREFIX} or ${WORKSPACE_INTENT_REF_PREFIX}`);
1765
1763
  }
1766
1764
  const result = Bun.spawnSync(["git", "check-ref-format", quarantineRef], {
1767
1765
  stdout: "pipe",
@@ -1979,11 +1977,7 @@ async function synchronizeWorkspace(rawInput) {
1979
1977
  const destructiveReductions = destructiveCheckoutReductions(input, baseRevision);
1980
1978
  if (destructiveReductions.length > 0 && !input.confirmedLargeDiff) {
1981
1979
  const summary = destructiveReductions.map(({ root, trackedBefore, trackedAfter }) => `${root} (${trackedBefore} -> ${trackedAfter} tracked files)`).join(", ");
1982
- return preserveLargeDiffCandidate(
1983
- input,
1984
- observed,
1985
- `Workspace safety guard blocked a destructive checkout reduction: ${summary}`
1986
- );
1980
+ return preserveLargeDiffCandidate(input, observed, `Workspace safety guard blocked a destructive checkout reduction: ${summary}`);
1987
1981
  }
1988
1982
  if (paths.length > 0 && diffSizeBytes > MAX_WORKSPACE_SYNC_DIFF_BYTES && !input.confirmedLargeDiff && !input.trigger.canonicalCheckoutOnly) {
1989
1983
  return preserveLargeDiffCandidate(