opencode-swarm 7.82.2 → 7.84.0

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 (58) hide show
  1. package/README.md +3 -1
  2. package/dist/cli/capability-probe-jevmgwmf.js +18 -0
  3. package/dist/cli/config-doctor-4tcdd9vt.js +35 -0
  4. package/dist/cli/dispatch-k86d928w.js +477 -0
  5. package/dist/cli/evidence-summary-service-g2znnd33.js +320 -0
  6. package/dist/cli/explorer-gz70sm9b.js +16 -0
  7. package/dist/cli/gate-evidence-y8zn7fe2.js +29 -0
  8. package/dist/cli/guardrail-explain-tcamcdfy.js +30 -0
  9. package/dist/cli/guardrail-log-fd14n96q.js +15 -0
  10. package/dist/cli/index-293f68mj.js +13538 -0
  11. package/dist/cli/index-8ra2qpk8.js +29027 -0
  12. package/dist/cli/index-a76rekgs.js +67 -0
  13. package/dist/cli/index-a82d6d87.js +1241 -0
  14. package/dist/cli/index-b9v501fr.js +371 -0
  15. package/dist/cli/index-bcp79s17.js +1673 -0
  16. package/dist/cli/index-ckntc5gf.js +91 -0
  17. package/dist/cli/index-d9fbxaqd.js +2314 -0
  18. package/dist/cli/index-e7h9bb6v.js +233 -0
  19. package/dist/cli/index-e8pk68cc.js +540 -0
  20. package/dist/cli/index-eb85wtx9.js +242 -0
  21. package/dist/cli/index-f8r50m3h.js +14505 -0
  22. package/dist/cli/index-fjwwrwr5.js +37 -0
  23. package/dist/cli/index-hz59hg4h.js +452 -0
  24. package/dist/cli/index-j710h2ge.js +412 -0
  25. package/dist/cli/index-jfgr5gye.js +110 -0
  26. package/dist/cli/index-jtqkh8jf.js +119 -0
  27. package/dist/cli/index-p0arc26j.js +28 -0
  28. package/dist/cli/index-p0ye10nd.js +222 -0
  29. package/dist/cli/index-pv2xmc9k.js +2391 -0
  30. package/dist/cli/index-red8fm8p.js +2914 -0
  31. package/dist/cli/index-wg3r6acj.js +2042 -0
  32. package/dist/cli/index-xw0bcy0v.js +583 -0
  33. package/dist/cli/index-yhsmmv2z.js +339 -0
  34. package/dist/cli/index-yx44zd0p.js +40 -0
  35. package/dist/cli/index-zfsbaaqh.js +29 -0
  36. package/dist/cli/index.js +73 -69703
  37. package/dist/cli/knowledge-store-n4x6zyk7.js +73 -0
  38. package/dist/cli/pending-delegations-pz61mrsz.js +255 -0
  39. package/dist/cli/pr-subscriptions-y1nn36e5.js +33 -0
  40. package/dist/cli/schema-c2dbzhm8.js +168 -0
  41. package/dist/cli/skill-generator-a5ehggyg.js +55 -0
  42. package/dist/cli/task-envelope-qn0qtnh0.js +90 -0
  43. package/dist/cli/telemetry-9bbyxrvn.js +20 -0
  44. package/dist/cli/workspace-snapshot-w58jr2ga.js +90 -0
  45. package/dist/commands/guardrail-explain.d.ts +1 -0
  46. package/dist/commands/guardrail-log.d.ts +1 -0
  47. package/dist/commands/index.d.ts +2 -0
  48. package/dist/commands/registry.d.ts +14 -0
  49. package/dist/config/index.d.ts +2 -2
  50. package/dist/config/schema.d.ts +7 -0
  51. package/dist/hooks/guardrails/audit-log.d.ts +114 -0
  52. package/dist/hooks/repo-graph-builder.d.ts +4 -1
  53. package/dist/index.js +3615 -2378
  54. package/dist/services/diagnose-service.d.ts +5 -0
  55. package/dist/services/guardrail-explain-service.d.ts +42 -0
  56. package/dist/services/guardrail-log-service.d.ts +10 -0
  57. package/dist/tools/repo-graph/types.d.ts +6 -0
  58. package/package.json +2 -2
@@ -0,0 +1,1673 @@
1
+ // @bun
2
+ import {
3
+ emit
4
+ } from "./index-p0ye10nd.js";
5
+ import {
6
+ __commonJS,
7
+ __require,
8
+ __toESM
9
+ } from "./index-a76rekgs.js";
10
+
11
+ // node_modules/graceful-fs/polyfills.js
12
+ var require_polyfills = __commonJS((exports, module) => {
13
+ var constants = __require("constants");
14
+ var origCwd = process.cwd;
15
+ var cwd = null;
16
+ var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
17
+ process.cwd = function() {
18
+ if (!cwd)
19
+ cwd = origCwd.call(process);
20
+ return cwd;
21
+ };
22
+ try {
23
+ process.cwd();
24
+ } catch (er) {}
25
+ if (typeof process.chdir === "function") {
26
+ chdir = process.chdir;
27
+ process.chdir = function(d) {
28
+ cwd = null;
29
+ chdir.call(process, d);
30
+ };
31
+ if (Object.setPrototypeOf)
32
+ Object.setPrototypeOf(process.chdir, chdir);
33
+ }
34
+ var chdir;
35
+ module.exports = patch;
36
+ function patch(fs) {
37
+ if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
38
+ patchLchmod(fs);
39
+ }
40
+ if (!fs.lutimes) {
41
+ patchLutimes(fs);
42
+ }
43
+ fs.chown = chownFix(fs.chown);
44
+ fs.fchown = chownFix(fs.fchown);
45
+ fs.lchown = chownFix(fs.lchown);
46
+ fs.chmod = chmodFix(fs.chmod);
47
+ fs.fchmod = chmodFix(fs.fchmod);
48
+ fs.lchmod = chmodFix(fs.lchmod);
49
+ fs.chownSync = chownFixSync(fs.chownSync);
50
+ fs.fchownSync = chownFixSync(fs.fchownSync);
51
+ fs.lchownSync = chownFixSync(fs.lchownSync);
52
+ fs.chmodSync = chmodFixSync(fs.chmodSync);
53
+ fs.fchmodSync = chmodFixSync(fs.fchmodSync);
54
+ fs.lchmodSync = chmodFixSync(fs.lchmodSync);
55
+ fs.stat = statFix(fs.stat);
56
+ fs.fstat = statFix(fs.fstat);
57
+ fs.lstat = statFix(fs.lstat);
58
+ fs.statSync = statFixSync(fs.statSync);
59
+ fs.fstatSync = statFixSync(fs.fstatSync);
60
+ fs.lstatSync = statFixSync(fs.lstatSync);
61
+ if (fs.chmod && !fs.lchmod) {
62
+ fs.lchmod = function(path, mode, cb) {
63
+ if (cb)
64
+ process.nextTick(cb);
65
+ };
66
+ fs.lchmodSync = function() {};
67
+ }
68
+ if (fs.chown && !fs.lchown) {
69
+ fs.lchown = function(path, uid, gid, cb) {
70
+ if (cb)
71
+ process.nextTick(cb);
72
+ };
73
+ fs.lchownSync = function() {};
74
+ }
75
+ if (platform === "win32") {
76
+ fs.rename = typeof fs.rename !== "function" ? fs.rename : function(fs$rename) {
77
+ function rename(from, to, cb) {
78
+ var start = Date.now();
79
+ var backoff = 0;
80
+ fs$rename(from, to, function CB(er) {
81
+ if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 60000) {
82
+ setTimeout(function() {
83
+ fs.stat(to, function(stater, st) {
84
+ if (stater && stater.code === "ENOENT")
85
+ fs$rename(from, to, CB);
86
+ else
87
+ cb(er);
88
+ });
89
+ }, backoff);
90
+ if (backoff < 100)
91
+ backoff += 10;
92
+ return;
93
+ }
94
+ if (cb)
95
+ cb(er);
96
+ });
97
+ }
98
+ if (Object.setPrototypeOf)
99
+ Object.setPrototypeOf(rename, fs$rename);
100
+ return rename;
101
+ }(fs.rename);
102
+ }
103
+ fs.read = typeof fs.read !== "function" ? fs.read : function(fs$read) {
104
+ function read(fd, buffer, offset, length, position, callback_) {
105
+ var callback;
106
+ if (callback_ && typeof callback_ === "function") {
107
+ var eagCounter = 0;
108
+ callback = function(er, _, __) {
109
+ if (er && er.code === "EAGAIN" && eagCounter < 10) {
110
+ eagCounter++;
111
+ return fs$read.call(fs, fd, buffer, offset, length, position, callback);
112
+ }
113
+ callback_.apply(this, arguments);
114
+ };
115
+ }
116
+ return fs$read.call(fs, fd, buffer, offset, length, position, callback);
117
+ }
118
+ if (Object.setPrototypeOf)
119
+ Object.setPrototypeOf(read, fs$read);
120
+ return read;
121
+ }(fs.read);
122
+ fs.readSync = typeof fs.readSync !== "function" ? fs.readSync : function(fs$readSync) {
123
+ return function(fd, buffer, offset, length, position) {
124
+ var eagCounter = 0;
125
+ while (true) {
126
+ try {
127
+ return fs$readSync.call(fs, fd, buffer, offset, length, position);
128
+ } catch (er) {
129
+ if (er.code === "EAGAIN" && eagCounter < 10) {
130
+ eagCounter++;
131
+ continue;
132
+ }
133
+ throw er;
134
+ }
135
+ }
136
+ };
137
+ }(fs.readSync);
138
+ function patchLchmod(fs2) {
139
+ fs2.lchmod = function(path, mode, callback) {
140
+ fs2.open(path, constants.O_WRONLY | constants.O_SYMLINK, mode, function(err, fd) {
141
+ if (err) {
142
+ if (callback)
143
+ callback(err);
144
+ return;
145
+ }
146
+ fs2.fchmod(fd, mode, function(err2) {
147
+ fs2.close(fd, function(err22) {
148
+ if (callback)
149
+ callback(err2 || err22);
150
+ });
151
+ });
152
+ });
153
+ };
154
+ fs2.lchmodSync = function(path, mode) {
155
+ var fd = fs2.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode);
156
+ var threw = true;
157
+ var ret;
158
+ try {
159
+ ret = fs2.fchmodSync(fd, mode);
160
+ threw = false;
161
+ } finally {
162
+ if (threw) {
163
+ try {
164
+ fs2.closeSync(fd);
165
+ } catch (er) {}
166
+ } else {
167
+ fs2.closeSync(fd);
168
+ }
169
+ }
170
+ return ret;
171
+ };
172
+ }
173
+ function patchLutimes(fs2) {
174
+ if (constants.hasOwnProperty("O_SYMLINK") && fs2.futimes) {
175
+ fs2.lutimes = function(path, at, mt, cb) {
176
+ fs2.open(path, constants.O_SYMLINK, function(er, fd) {
177
+ if (er) {
178
+ if (cb)
179
+ cb(er);
180
+ return;
181
+ }
182
+ fs2.futimes(fd, at, mt, function(er2) {
183
+ fs2.close(fd, function(er22) {
184
+ if (cb)
185
+ cb(er2 || er22);
186
+ });
187
+ });
188
+ });
189
+ };
190
+ fs2.lutimesSync = function(path, at, mt) {
191
+ var fd = fs2.openSync(path, constants.O_SYMLINK);
192
+ var ret;
193
+ var threw = true;
194
+ try {
195
+ ret = fs2.futimesSync(fd, at, mt);
196
+ threw = false;
197
+ } finally {
198
+ if (threw) {
199
+ try {
200
+ fs2.closeSync(fd);
201
+ } catch (er) {}
202
+ } else {
203
+ fs2.closeSync(fd);
204
+ }
205
+ }
206
+ return ret;
207
+ };
208
+ } else if (fs2.futimes) {
209
+ fs2.lutimes = function(_a, _b, _c, cb) {
210
+ if (cb)
211
+ process.nextTick(cb);
212
+ };
213
+ fs2.lutimesSync = function() {};
214
+ }
215
+ }
216
+ function chmodFix(orig) {
217
+ if (!orig)
218
+ return orig;
219
+ return function(target, mode, cb) {
220
+ return orig.call(fs, target, mode, function(er) {
221
+ if (chownErOk(er))
222
+ er = null;
223
+ if (cb)
224
+ cb.apply(this, arguments);
225
+ });
226
+ };
227
+ }
228
+ function chmodFixSync(orig) {
229
+ if (!orig)
230
+ return orig;
231
+ return function(target, mode) {
232
+ try {
233
+ return orig.call(fs, target, mode);
234
+ } catch (er) {
235
+ if (!chownErOk(er))
236
+ throw er;
237
+ }
238
+ };
239
+ }
240
+ function chownFix(orig) {
241
+ if (!orig)
242
+ return orig;
243
+ return function(target, uid, gid, cb) {
244
+ return orig.call(fs, target, uid, gid, function(er) {
245
+ if (chownErOk(er))
246
+ er = null;
247
+ if (cb)
248
+ cb.apply(this, arguments);
249
+ });
250
+ };
251
+ }
252
+ function chownFixSync(orig) {
253
+ if (!orig)
254
+ return orig;
255
+ return function(target, uid, gid) {
256
+ try {
257
+ return orig.call(fs, target, uid, gid);
258
+ } catch (er) {
259
+ if (!chownErOk(er))
260
+ throw er;
261
+ }
262
+ };
263
+ }
264
+ function statFix(orig) {
265
+ if (!orig)
266
+ return orig;
267
+ return function(target, options, cb) {
268
+ if (typeof options === "function") {
269
+ cb = options;
270
+ options = null;
271
+ }
272
+ function callback(er, stats) {
273
+ if (stats) {
274
+ if (stats.uid < 0)
275
+ stats.uid += 4294967296;
276
+ if (stats.gid < 0)
277
+ stats.gid += 4294967296;
278
+ }
279
+ if (cb)
280
+ cb.apply(this, arguments);
281
+ }
282
+ return options ? orig.call(fs, target, options, callback) : orig.call(fs, target, callback);
283
+ };
284
+ }
285
+ function statFixSync(orig) {
286
+ if (!orig)
287
+ return orig;
288
+ return function(target, options) {
289
+ var stats = options ? orig.call(fs, target, options) : orig.call(fs, target);
290
+ if (stats) {
291
+ if (stats.uid < 0)
292
+ stats.uid += 4294967296;
293
+ if (stats.gid < 0)
294
+ stats.gid += 4294967296;
295
+ }
296
+ return stats;
297
+ };
298
+ }
299
+ function chownErOk(er) {
300
+ if (!er)
301
+ return true;
302
+ if (er.code === "ENOSYS")
303
+ return true;
304
+ var nonroot = !process.getuid || process.getuid() !== 0;
305
+ if (nonroot) {
306
+ if (er.code === "EINVAL" || er.code === "EPERM")
307
+ return true;
308
+ }
309
+ return false;
310
+ }
311
+ }
312
+ });
313
+
314
+ // node_modules/graceful-fs/legacy-streams.js
315
+ var require_legacy_streams = __commonJS((exports, module) => {
316
+ var Stream = __require("stream").Stream;
317
+ module.exports = legacy;
318
+ function legacy(fs) {
319
+ return {
320
+ ReadStream,
321
+ WriteStream
322
+ };
323
+ function ReadStream(path, options) {
324
+ if (!(this instanceof ReadStream))
325
+ return new ReadStream(path, options);
326
+ Stream.call(this);
327
+ var self = this;
328
+ this.path = path;
329
+ this.fd = null;
330
+ this.readable = true;
331
+ this.paused = false;
332
+ this.flags = "r";
333
+ this.mode = 438;
334
+ this.bufferSize = 64 * 1024;
335
+ options = options || {};
336
+ var keys = Object.keys(options);
337
+ for (var index = 0, length = keys.length;index < length; index++) {
338
+ var key = keys[index];
339
+ this[key] = options[key];
340
+ }
341
+ if (this.encoding)
342
+ this.setEncoding(this.encoding);
343
+ if (this.start !== undefined) {
344
+ if (typeof this.start !== "number") {
345
+ throw TypeError("start must be a Number");
346
+ }
347
+ if (this.end === undefined) {
348
+ this.end = Infinity;
349
+ } else if (typeof this.end !== "number") {
350
+ throw TypeError("end must be a Number");
351
+ }
352
+ if (this.start > this.end) {
353
+ throw new Error("start must be <= end");
354
+ }
355
+ this.pos = this.start;
356
+ }
357
+ if (this.fd !== null) {
358
+ process.nextTick(function() {
359
+ self._read();
360
+ });
361
+ return;
362
+ }
363
+ fs.open(this.path, this.flags, this.mode, function(err, fd) {
364
+ if (err) {
365
+ self.emit("error", err);
366
+ self.readable = false;
367
+ return;
368
+ }
369
+ self.fd = fd;
370
+ self.emit("open", fd);
371
+ self._read();
372
+ });
373
+ }
374
+ function WriteStream(path, options) {
375
+ if (!(this instanceof WriteStream))
376
+ return new WriteStream(path, options);
377
+ Stream.call(this);
378
+ this.path = path;
379
+ this.fd = null;
380
+ this.writable = true;
381
+ this.flags = "w";
382
+ this.encoding = "binary";
383
+ this.mode = 438;
384
+ this.bytesWritten = 0;
385
+ options = options || {};
386
+ var keys = Object.keys(options);
387
+ for (var index = 0, length = keys.length;index < length; index++) {
388
+ var key = keys[index];
389
+ this[key] = options[key];
390
+ }
391
+ if (this.start !== undefined) {
392
+ if (typeof this.start !== "number") {
393
+ throw TypeError("start must be a Number");
394
+ }
395
+ if (this.start < 0) {
396
+ throw new Error("start must be >= zero");
397
+ }
398
+ this.pos = this.start;
399
+ }
400
+ this.busy = false;
401
+ this._queue = [];
402
+ if (this.fd === null) {
403
+ this._open = fs.open;
404
+ this._queue.push([this._open, this.path, this.flags, this.mode, undefined]);
405
+ this.flush();
406
+ }
407
+ }
408
+ }
409
+ });
410
+
411
+ // node_modules/graceful-fs/clone.js
412
+ var require_clone = __commonJS((exports, module) => {
413
+ module.exports = clone;
414
+ var getPrototypeOf = Object.getPrototypeOf || function(obj) {
415
+ return obj.__proto__;
416
+ };
417
+ function clone(obj) {
418
+ if (obj === null || typeof obj !== "object")
419
+ return obj;
420
+ if (obj instanceof Object)
421
+ var copy = { __proto__: getPrototypeOf(obj) };
422
+ else
423
+ var copy = Object.create(null);
424
+ Object.getOwnPropertyNames(obj).forEach(function(key) {
425
+ Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
426
+ });
427
+ return copy;
428
+ }
429
+ });
430
+
431
+ // node_modules/graceful-fs/graceful-fs.js
432
+ var require_graceful_fs = __commonJS((exports, module) => {
433
+ var fs = __require("fs");
434
+ var polyfills = require_polyfills();
435
+ var legacy = require_legacy_streams();
436
+ var clone = require_clone();
437
+ var util = __require("util");
438
+ var gracefulQueue;
439
+ var previousSymbol;
440
+ if (typeof Symbol === "function" && typeof Symbol.for === "function") {
441
+ gracefulQueue = Symbol.for("graceful-fs.queue");
442
+ previousSymbol = Symbol.for("graceful-fs.previous");
443
+ } else {
444
+ gracefulQueue = "___graceful-fs.queue";
445
+ previousSymbol = "___graceful-fs.previous";
446
+ }
447
+ function noop() {}
448
+ function publishQueue(context, queue2) {
449
+ Object.defineProperty(context, gracefulQueue, {
450
+ get: function() {
451
+ return queue2;
452
+ }
453
+ });
454
+ }
455
+ var debug = noop;
456
+ if (util.debuglog)
457
+ debug = util.debuglog("gfs4");
458
+ else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ""))
459
+ debug = function() {
460
+ var m = util.format.apply(util, arguments);
461
+ m = "GFS4: " + m.split(/\n/).join(`
462
+ GFS4: `);
463
+ console.error(m);
464
+ };
465
+ if (!fs[gracefulQueue]) {
466
+ queue = global[gracefulQueue] || [];
467
+ publishQueue(fs, queue);
468
+ fs.close = function(fs$close) {
469
+ function close(fd, cb) {
470
+ return fs$close.call(fs, fd, function(err) {
471
+ if (!err) {
472
+ resetQueue();
473
+ }
474
+ if (typeof cb === "function")
475
+ cb.apply(this, arguments);
476
+ });
477
+ }
478
+ Object.defineProperty(close, previousSymbol, {
479
+ value: fs$close
480
+ });
481
+ return close;
482
+ }(fs.close);
483
+ fs.closeSync = function(fs$closeSync) {
484
+ function closeSync(fd) {
485
+ fs$closeSync.apply(fs, arguments);
486
+ resetQueue();
487
+ }
488
+ Object.defineProperty(closeSync, previousSymbol, {
489
+ value: fs$closeSync
490
+ });
491
+ return closeSync;
492
+ }(fs.closeSync);
493
+ if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
494
+ process.on("exit", function() {
495
+ debug(fs[gracefulQueue]);
496
+ __require("assert").equal(fs[gracefulQueue].length, 0);
497
+ });
498
+ }
499
+ }
500
+ var queue;
501
+ if (!global[gracefulQueue]) {
502
+ publishQueue(global, fs[gracefulQueue]);
503
+ }
504
+ module.exports = patch(clone(fs));
505
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs.__patched) {
506
+ module.exports = patch(fs);
507
+ fs.__patched = true;
508
+ }
509
+ function patch(fs2) {
510
+ polyfills(fs2);
511
+ fs2.gracefulify = patch;
512
+ fs2.createReadStream = createReadStream;
513
+ fs2.createWriteStream = createWriteStream;
514
+ var fs$readFile = fs2.readFile;
515
+ fs2.readFile = readFile;
516
+ function readFile(path, options, cb) {
517
+ if (typeof options === "function")
518
+ cb = options, options = null;
519
+ return go$readFile(path, options, cb);
520
+ function go$readFile(path2, options2, cb2, startTime) {
521
+ return fs$readFile(path2, options2, function(err) {
522
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
523
+ enqueue([go$readFile, [path2, options2, cb2], err, startTime || Date.now(), Date.now()]);
524
+ else {
525
+ if (typeof cb2 === "function")
526
+ cb2.apply(this, arguments);
527
+ }
528
+ });
529
+ }
530
+ }
531
+ var fs$writeFile = fs2.writeFile;
532
+ fs2.writeFile = writeFile;
533
+ function writeFile(path, data, options, cb) {
534
+ if (typeof options === "function")
535
+ cb = options, options = null;
536
+ return go$writeFile(path, data, options, cb);
537
+ function go$writeFile(path2, data2, options2, cb2, startTime) {
538
+ return fs$writeFile(path2, data2, options2, function(err) {
539
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
540
+ enqueue([go$writeFile, [path2, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
541
+ else {
542
+ if (typeof cb2 === "function")
543
+ cb2.apply(this, arguments);
544
+ }
545
+ });
546
+ }
547
+ }
548
+ var fs$appendFile = fs2.appendFile;
549
+ if (fs$appendFile)
550
+ fs2.appendFile = appendFile;
551
+ function appendFile(path, data, options, cb) {
552
+ if (typeof options === "function")
553
+ cb = options, options = null;
554
+ return go$appendFile(path, data, options, cb);
555
+ function go$appendFile(path2, data2, options2, cb2, startTime) {
556
+ return fs$appendFile(path2, data2, options2, function(err) {
557
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
558
+ enqueue([go$appendFile, [path2, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
559
+ else {
560
+ if (typeof cb2 === "function")
561
+ cb2.apply(this, arguments);
562
+ }
563
+ });
564
+ }
565
+ }
566
+ var fs$copyFile = fs2.copyFile;
567
+ if (fs$copyFile)
568
+ fs2.copyFile = copyFile;
569
+ function copyFile(src, dest, flags, cb) {
570
+ if (typeof flags === "function") {
571
+ cb = flags;
572
+ flags = 0;
573
+ }
574
+ return go$copyFile(src, dest, flags, cb);
575
+ function go$copyFile(src2, dest2, flags2, cb2, startTime) {
576
+ return fs$copyFile(src2, dest2, flags2, function(err) {
577
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
578
+ enqueue([go$copyFile, [src2, dest2, flags2, cb2], err, startTime || Date.now(), Date.now()]);
579
+ else {
580
+ if (typeof cb2 === "function")
581
+ cb2.apply(this, arguments);
582
+ }
583
+ });
584
+ }
585
+ }
586
+ var fs$readdir = fs2.readdir;
587
+ fs2.readdir = readdir;
588
+ var noReaddirOptionVersions = /^v[0-5]\./;
589
+ function readdir(path, options, cb) {
590
+ if (typeof options === "function")
591
+ cb = options, options = null;
592
+ var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path2, options2, cb2, startTime) {
593
+ return fs$readdir(path2, fs$readdirCallback(path2, options2, cb2, startTime));
594
+ } : function go$readdir2(path2, options2, cb2, startTime) {
595
+ return fs$readdir(path2, options2, fs$readdirCallback(path2, options2, cb2, startTime));
596
+ };
597
+ return go$readdir(path, options, cb);
598
+ function fs$readdirCallback(path2, options2, cb2, startTime) {
599
+ return function(err, files) {
600
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
601
+ enqueue([
602
+ go$readdir,
603
+ [path2, options2, cb2],
604
+ err,
605
+ startTime || Date.now(),
606
+ Date.now()
607
+ ]);
608
+ else {
609
+ if (files && files.sort)
610
+ files.sort();
611
+ if (typeof cb2 === "function")
612
+ cb2.call(this, err, files);
613
+ }
614
+ };
615
+ }
616
+ }
617
+ if (process.version.substr(0, 4) === "v0.8") {
618
+ var legStreams = legacy(fs2);
619
+ ReadStream = legStreams.ReadStream;
620
+ WriteStream = legStreams.WriteStream;
621
+ }
622
+ var fs$ReadStream = fs2.ReadStream;
623
+ if (fs$ReadStream) {
624
+ ReadStream.prototype = Object.create(fs$ReadStream.prototype);
625
+ ReadStream.prototype.open = ReadStream$open;
626
+ }
627
+ var fs$WriteStream = fs2.WriteStream;
628
+ if (fs$WriteStream) {
629
+ WriteStream.prototype = Object.create(fs$WriteStream.prototype);
630
+ WriteStream.prototype.open = WriteStream$open;
631
+ }
632
+ Object.defineProperty(fs2, "ReadStream", {
633
+ get: function() {
634
+ return ReadStream;
635
+ },
636
+ set: function(val) {
637
+ ReadStream = val;
638
+ },
639
+ enumerable: true,
640
+ configurable: true
641
+ });
642
+ Object.defineProperty(fs2, "WriteStream", {
643
+ get: function() {
644
+ return WriteStream;
645
+ },
646
+ set: function(val) {
647
+ WriteStream = val;
648
+ },
649
+ enumerable: true,
650
+ configurable: true
651
+ });
652
+ var FileReadStream = ReadStream;
653
+ Object.defineProperty(fs2, "FileReadStream", {
654
+ get: function() {
655
+ return FileReadStream;
656
+ },
657
+ set: function(val) {
658
+ FileReadStream = val;
659
+ },
660
+ enumerable: true,
661
+ configurable: true
662
+ });
663
+ var FileWriteStream = WriteStream;
664
+ Object.defineProperty(fs2, "FileWriteStream", {
665
+ get: function() {
666
+ return FileWriteStream;
667
+ },
668
+ set: function(val) {
669
+ FileWriteStream = val;
670
+ },
671
+ enumerable: true,
672
+ configurable: true
673
+ });
674
+ function ReadStream(path, options) {
675
+ if (this instanceof ReadStream)
676
+ return fs$ReadStream.apply(this, arguments), this;
677
+ else
678
+ return ReadStream.apply(Object.create(ReadStream.prototype), arguments);
679
+ }
680
+ function ReadStream$open() {
681
+ var that = this;
682
+ open(that.path, that.flags, that.mode, function(err, fd) {
683
+ if (err) {
684
+ if (that.autoClose)
685
+ that.destroy();
686
+ that.emit("error", err);
687
+ } else {
688
+ that.fd = fd;
689
+ that.emit("open", fd);
690
+ that.read();
691
+ }
692
+ });
693
+ }
694
+ function WriteStream(path, options) {
695
+ if (this instanceof WriteStream)
696
+ return fs$WriteStream.apply(this, arguments), this;
697
+ else
698
+ return WriteStream.apply(Object.create(WriteStream.prototype), arguments);
699
+ }
700
+ function WriteStream$open() {
701
+ var that = this;
702
+ open(that.path, that.flags, that.mode, function(err, fd) {
703
+ if (err) {
704
+ that.destroy();
705
+ that.emit("error", err);
706
+ } else {
707
+ that.fd = fd;
708
+ that.emit("open", fd);
709
+ }
710
+ });
711
+ }
712
+ function createReadStream(path, options) {
713
+ return new fs2.ReadStream(path, options);
714
+ }
715
+ function createWriteStream(path, options) {
716
+ return new fs2.WriteStream(path, options);
717
+ }
718
+ var fs$open = fs2.open;
719
+ fs2.open = open;
720
+ function open(path, flags, mode, cb) {
721
+ if (typeof mode === "function")
722
+ cb = mode, mode = null;
723
+ return go$open(path, flags, mode, cb);
724
+ function go$open(path2, flags2, mode2, cb2, startTime) {
725
+ return fs$open(path2, flags2, mode2, function(err, fd) {
726
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
727
+ enqueue([go$open, [path2, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
728
+ else {
729
+ if (typeof cb2 === "function")
730
+ cb2.apply(this, arguments);
731
+ }
732
+ });
733
+ }
734
+ }
735
+ return fs2;
736
+ }
737
+ function enqueue(elem) {
738
+ debug("ENQUEUE", elem[0].name, elem[1]);
739
+ fs[gracefulQueue].push(elem);
740
+ retry();
741
+ }
742
+ var retryTimer;
743
+ function resetQueue() {
744
+ var now = Date.now();
745
+ for (var i = 0;i < fs[gracefulQueue].length; ++i) {
746
+ if (fs[gracefulQueue][i].length > 2) {
747
+ fs[gracefulQueue][i][3] = now;
748
+ fs[gracefulQueue][i][4] = now;
749
+ }
750
+ }
751
+ retry();
752
+ }
753
+ function retry() {
754
+ clearTimeout(retryTimer);
755
+ retryTimer = undefined;
756
+ if (fs[gracefulQueue].length === 0)
757
+ return;
758
+ var elem = fs[gracefulQueue].shift();
759
+ var fn = elem[0];
760
+ var args = elem[1];
761
+ var err = elem[2];
762
+ var startTime = elem[3];
763
+ var lastTime = elem[4];
764
+ if (startTime === undefined) {
765
+ debug("RETRY", fn.name, args);
766
+ fn.apply(null, args);
767
+ } else if (Date.now() - startTime >= 60000) {
768
+ debug("TIMEOUT", fn.name, args);
769
+ var cb = args.pop();
770
+ if (typeof cb === "function")
771
+ cb.call(null, err);
772
+ } else {
773
+ var sinceAttempt = Date.now() - lastTime;
774
+ var sinceStart = Math.max(lastTime - startTime, 1);
775
+ var desiredDelay = Math.min(sinceStart * 1.2, 100);
776
+ if (sinceAttempt >= desiredDelay) {
777
+ debug("RETRY", fn.name, args);
778
+ fn.apply(null, args.concat([startTime]));
779
+ } else {
780
+ fs[gracefulQueue].push(elem);
781
+ }
782
+ }
783
+ if (retryTimer === undefined) {
784
+ retryTimer = setTimeout(retry, 0);
785
+ }
786
+ }
787
+ });
788
+
789
+ // node_modules/retry/lib/retry_operation.js
790
+ var require_retry_operation = __commonJS((exports, module) => {
791
+ function RetryOperation(timeouts, options) {
792
+ if (typeof options === "boolean") {
793
+ options = { forever: options };
794
+ }
795
+ this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
796
+ this._timeouts = timeouts;
797
+ this._options = options || {};
798
+ this._maxRetryTime = options && options.maxRetryTime || Infinity;
799
+ this._fn = null;
800
+ this._errors = [];
801
+ this._attempts = 1;
802
+ this._operationTimeout = null;
803
+ this._operationTimeoutCb = null;
804
+ this._timeout = null;
805
+ this._operationStart = null;
806
+ if (this._options.forever) {
807
+ this._cachedTimeouts = this._timeouts.slice(0);
808
+ }
809
+ }
810
+ module.exports = RetryOperation;
811
+ RetryOperation.prototype.reset = function() {
812
+ this._attempts = 1;
813
+ this._timeouts = this._originalTimeouts;
814
+ };
815
+ RetryOperation.prototype.stop = function() {
816
+ if (this._timeout) {
817
+ clearTimeout(this._timeout);
818
+ }
819
+ this._timeouts = [];
820
+ this._cachedTimeouts = null;
821
+ };
822
+ RetryOperation.prototype.retry = function(err) {
823
+ if (this._timeout) {
824
+ clearTimeout(this._timeout);
825
+ }
826
+ if (!err) {
827
+ return false;
828
+ }
829
+ var currentTime = new Date().getTime();
830
+ if (err && currentTime - this._operationStart >= this._maxRetryTime) {
831
+ this._errors.unshift(new Error("RetryOperation timeout occurred"));
832
+ return false;
833
+ }
834
+ this._errors.push(err);
835
+ var timeout = this._timeouts.shift();
836
+ if (timeout === undefined) {
837
+ if (this._cachedTimeouts) {
838
+ this._errors.splice(this._errors.length - 1, this._errors.length);
839
+ this._timeouts = this._cachedTimeouts.slice(0);
840
+ timeout = this._timeouts.shift();
841
+ } else {
842
+ return false;
843
+ }
844
+ }
845
+ var self = this;
846
+ var timer = setTimeout(function() {
847
+ self._attempts++;
848
+ if (self._operationTimeoutCb) {
849
+ self._timeout = setTimeout(function() {
850
+ self._operationTimeoutCb(self._attempts);
851
+ }, self._operationTimeout);
852
+ if (self._options.unref) {
853
+ self._timeout.unref();
854
+ }
855
+ }
856
+ self._fn(self._attempts);
857
+ }, timeout);
858
+ if (this._options.unref) {
859
+ timer.unref();
860
+ }
861
+ return true;
862
+ };
863
+ RetryOperation.prototype.attempt = function(fn, timeoutOps) {
864
+ this._fn = fn;
865
+ if (timeoutOps) {
866
+ if (timeoutOps.timeout) {
867
+ this._operationTimeout = timeoutOps.timeout;
868
+ }
869
+ if (timeoutOps.cb) {
870
+ this._operationTimeoutCb = timeoutOps.cb;
871
+ }
872
+ }
873
+ var self = this;
874
+ if (this._operationTimeoutCb) {
875
+ this._timeout = setTimeout(function() {
876
+ self._operationTimeoutCb();
877
+ }, self._operationTimeout);
878
+ }
879
+ this._operationStart = new Date().getTime();
880
+ this._fn(this._attempts);
881
+ };
882
+ RetryOperation.prototype.try = function(fn) {
883
+ console.log("Using RetryOperation.try() is deprecated");
884
+ this.attempt(fn);
885
+ };
886
+ RetryOperation.prototype.start = function(fn) {
887
+ console.log("Using RetryOperation.start() is deprecated");
888
+ this.attempt(fn);
889
+ };
890
+ RetryOperation.prototype.start = RetryOperation.prototype.try;
891
+ RetryOperation.prototype.errors = function() {
892
+ return this._errors;
893
+ };
894
+ RetryOperation.prototype.attempts = function() {
895
+ return this._attempts;
896
+ };
897
+ RetryOperation.prototype.mainError = function() {
898
+ if (this._errors.length === 0) {
899
+ return null;
900
+ }
901
+ var counts = {};
902
+ var mainError = null;
903
+ var mainErrorCount = 0;
904
+ for (var i = 0;i < this._errors.length; i++) {
905
+ var error = this._errors[i];
906
+ var message = error.message;
907
+ var count = (counts[message] || 0) + 1;
908
+ counts[message] = count;
909
+ if (count >= mainErrorCount) {
910
+ mainError = error;
911
+ mainErrorCount = count;
912
+ }
913
+ }
914
+ return mainError;
915
+ };
916
+ });
917
+
918
+ // node_modules/retry/lib/retry.js
919
+ var require_retry = __commonJS((exports) => {
920
+ var RetryOperation = require_retry_operation();
921
+ exports.operation = function(options) {
922
+ var timeouts = exports.timeouts(options);
923
+ return new RetryOperation(timeouts, {
924
+ forever: options && options.forever,
925
+ unref: options && options.unref,
926
+ maxRetryTime: options && options.maxRetryTime
927
+ });
928
+ };
929
+ exports.timeouts = function(options) {
930
+ if (options instanceof Array) {
931
+ return [].concat(options);
932
+ }
933
+ var opts = {
934
+ retries: 10,
935
+ factor: 2,
936
+ minTimeout: 1 * 1000,
937
+ maxTimeout: Infinity,
938
+ randomize: false
939
+ };
940
+ for (var key in options) {
941
+ opts[key] = options[key];
942
+ }
943
+ if (opts.minTimeout > opts.maxTimeout) {
944
+ throw new Error("minTimeout is greater than maxTimeout");
945
+ }
946
+ var timeouts = [];
947
+ for (var i = 0;i < opts.retries; i++) {
948
+ timeouts.push(this.createTimeout(i, opts));
949
+ }
950
+ if (options && options.forever && !timeouts.length) {
951
+ timeouts.push(this.createTimeout(i, opts));
952
+ }
953
+ timeouts.sort(function(a, b) {
954
+ return a - b;
955
+ });
956
+ return timeouts;
957
+ };
958
+ exports.createTimeout = function(attempt, opts) {
959
+ var random = opts.randomize ? Math.random() + 1 : 1;
960
+ var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
961
+ timeout = Math.min(timeout, opts.maxTimeout);
962
+ return timeout;
963
+ };
964
+ exports.wrap = function(obj, options, methods) {
965
+ if (options instanceof Array) {
966
+ methods = options;
967
+ options = null;
968
+ }
969
+ if (!methods) {
970
+ methods = [];
971
+ for (var key in obj) {
972
+ if (typeof obj[key] === "function") {
973
+ methods.push(key);
974
+ }
975
+ }
976
+ }
977
+ for (var i = 0;i < methods.length; i++) {
978
+ var method = methods[i];
979
+ var original = obj[method];
980
+ obj[method] = function retryWrapper(original2) {
981
+ var op = exports.operation(options);
982
+ var args = Array.prototype.slice.call(arguments, 1);
983
+ var callback = args.pop();
984
+ args.push(function(err) {
985
+ if (op.retry(err)) {
986
+ return;
987
+ }
988
+ if (err) {
989
+ arguments[0] = op.mainError();
990
+ }
991
+ callback.apply(this, arguments);
992
+ });
993
+ op.attempt(function() {
994
+ original2.apply(obj, args);
995
+ });
996
+ }.bind(obj, original);
997
+ obj[method].options = options;
998
+ }
999
+ };
1000
+ });
1001
+
1002
+ // node_modules/signal-exit/signals.js
1003
+ var require_signals = __commonJS((exports, module) => {
1004
+ module.exports = [
1005
+ "SIGABRT",
1006
+ "SIGALRM",
1007
+ "SIGHUP",
1008
+ "SIGINT",
1009
+ "SIGTERM"
1010
+ ];
1011
+ if (process.platform !== "win32") {
1012
+ module.exports.push("SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT");
1013
+ }
1014
+ if (process.platform === "linux") {
1015
+ module.exports.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT", "SIGUNUSED");
1016
+ }
1017
+ });
1018
+
1019
+ // node_modules/signal-exit/index.js
1020
+ var require_signal_exit = __commonJS((exports, module) => {
1021
+ var process2 = global.process;
1022
+ var processOk = function(process3) {
1023
+ return process3 && typeof process3 === "object" && typeof process3.removeListener === "function" && typeof process3.emit === "function" && typeof process3.reallyExit === "function" && typeof process3.listeners === "function" && typeof process3.kill === "function" && typeof process3.pid === "number" && typeof process3.on === "function";
1024
+ };
1025
+ if (!processOk(process2)) {
1026
+ module.exports = function() {
1027
+ return function() {};
1028
+ };
1029
+ } else {
1030
+ assert = __require("assert");
1031
+ signals = require_signals();
1032
+ isWin = /^win/i.test(process2.platform);
1033
+ EE = __require("events");
1034
+ if (typeof EE !== "function") {
1035
+ EE = EE.EventEmitter;
1036
+ }
1037
+ if (process2.__signal_exit_emitter__) {
1038
+ emitter = process2.__signal_exit_emitter__;
1039
+ } else {
1040
+ emitter = process2.__signal_exit_emitter__ = new EE;
1041
+ emitter.count = 0;
1042
+ emitter.emitted = {};
1043
+ }
1044
+ if (!emitter.infinite) {
1045
+ emitter.setMaxListeners(Infinity);
1046
+ emitter.infinite = true;
1047
+ }
1048
+ module.exports = function(cb, opts) {
1049
+ if (!processOk(global.process)) {
1050
+ return function() {};
1051
+ }
1052
+ assert.equal(typeof cb, "function", "a callback must be provided for exit handler");
1053
+ if (loaded === false) {
1054
+ load();
1055
+ }
1056
+ var ev = "exit";
1057
+ if (opts && opts.alwaysLast) {
1058
+ ev = "afterexit";
1059
+ }
1060
+ var remove = function() {
1061
+ emitter.removeListener(ev, cb);
1062
+ if (emitter.listeners("exit").length === 0 && emitter.listeners("afterexit").length === 0) {
1063
+ unload();
1064
+ }
1065
+ };
1066
+ emitter.on(ev, cb);
1067
+ return remove;
1068
+ };
1069
+ unload = function unload2() {
1070
+ if (!loaded || !processOk(global.process)) {
1071
+ return;
1072
+ }
1073
+ loaded = false;
1074
+ signals.forEach(function(sig) {
1075
+ try {
1076
+ process2.removeListener(sig, sigListeners[sig]);
1077
+ } catch (er) {}
1078
+ });
1079
+ process2.emit = originalProcessEmit;
1080
+ process2.reallyExit = originalProcessReallyExit;
1081
+ emitter.count -= 1;
1082
+ };
1083
+ module.exports.unload = unload;
1084
+ emit2 = function emit3(event, code, signal) {
1085
+ if (emitter.emitted[event]) {
1086
+ return;
1087
+ }
1088
+ emitter.emitted[event] = true;
1089
+ emitter.emit(event, code, signal);
1090
+ };
1091
+ sigListeners = {};
1092
+ signals.forEach(function(sig) {
1093
+ sigListeners[sig] = function listener() {
1094
+ if (!processOk(global.process)) {
1095
+ return;
1096
+ }
1097
+ var listeners = process2.listeners(sig);
1098
+ if (listeners.length === emitter.count) {
1099
+ unload();
1100
+ emit2("exit", null, sig);
1101
+ emit2("afterexit", null, sig);
1102
+ if (isWin && sig === "SIGHUP") {
1103
+ sig = "SIGINT";
1104
+ }
1105
+ process2.kill(process2.pid, sig);
1106
+ }
1107
+ };
1108
+ });
1109
+ module.exports.signals = function() {
1110
+ return signals;
1111
+ };
1112
+ loaded = false;
1113
+ load = function load2() {
1114
+ if (loaded || !processOk(global.process)) {
1115
+ return;
1116
+ }
1117
+ loaded = true;
1118
+ emitter.count += 1;
1119
+ signals = signals.filter(function(sig) {
1120
+ try {
1121
+ process2.on(sig, sigListeners[sig]);
1122
+ return true;
1123
+ } catch (er) {
1124
+ return false;
1125
+ }
1126
+ });
1127
+ process2.emit = processEmit;
1128
+ process2.reallyExit = processReallyExit;
1129
+ };
1130
+ module.exports.load = load;
1131
+ originalProcessReallyExit = process2.reallyExit;
1132
+ processReallyExit = function processReallyExit2(code) {
1133
+ if (!processOk(global.process)) {
1134
+ return;
1135
+ }
1136
+ process2.exitCode = code || 0;
1137
+ emit2("exit", process2.exitCode, null);
1138
+ emit2("afterexit", process2.exitCode, null);
1139
+ originalProcessReallyExit.call(process2, process2.exitCode);
1140
+ };
1141
+ originalProcessEmit = process2.emit;
1142
+ processEmit = function processEmit2(ev, arg) {
1143
+ if (ev === "exit" && processOk(global.process)) {
1144
+ if (arg !== undefined) {
1145
+ process2.exitCode = arg;
1146
+ }
1147
+ var ret = originalProcessEmit.apply(this, arguments);
1148
+ emit2("exit", process2.exitCode, null);
1149
+ emit2("afterexit", process2.exitCode, null);
1150
+ return ret;
1151
+ } else {
1152
+ return originalProcessEmit.apply(this, arguments);
1153
+ }
1154
+ };
1155
+ }
1156
+ var assert;
1157
+ var signals;
1158
+ var isWin;
1159
+ var EE;
1160
+ var emitter;
1161
+ var unload;
1162
+ var emit2;
1163
+ var sigListeners;
1164
+ var loaded;
1165
+ var load;
1166
+ var originalProcessReallyExit;
1167
+ var processReallyExit;
1168
+ var originalProcessEmit;
1169
+ var processEmit;
1170
+ });
1171
+
1172
+ // node_modules/proper-lockfile/lib/mtime-precision.js
1173
+ var require_mtime_precision = __commonJS((exports, module) => {
1174
+ var cacheSymbol = Symbol();
1175
+ function probe(file, fs, callback) {
1176
+ const cachedPrecision = fs[cacheSymbol];
1177
+ if (cachedPrecision) {
1178
+ return fs.stat(file, (err, stat) => {
1179
+ if (err) {
1180
+ return callback(err);
1181
+ }
1182
+ callback(null, stat.mtime, cachedPrecision);
1183
+ });
1184
+ }
1185
+ const mtime = new Date(Math.ceil(Date.now() / 1000) * 1000 + 5);
1186
+ fs.utimes(file, mtime, mtime, (err) => {
1187
+ if (err) {
1188
+ return callback(err);
1189
+ }
1190
+ fs.stat(file, (err2, stat) => {
1191
+ if (err2) {
1192
+ return callback(err2);
1193
+ }
1194
+ const precision = stat.mtime.getTime() % 1000 === 0 ? "s" : "ms";
1195
+ Object.defineProperty(fs, cacheSymbol, { value: precision });
1196
+ callback(null, stat.mtime, precision);
1197
+ });
1198
+ });
1199
+ }
1200
+ function getMtime(precision) {
1201
+ let now = Date.now();
1202
+ if (precision === "s") {
1203
+ now = Math.ceil(now / 1000) * 1000;
1204
+ }
1205
+ return new Date(now);
1206
+ }
1207
+ exports.probe = probe;
1208
+ exports.getMtime = getMtime;
1209
+ });
1210
+
1211
+ // node_modules/proper-lockfile/lib/lockfile.js
1212
+ var require_lockfile = __commonJS((exports, module) => {
1213
+ var path = __require("path");
1214
+ var fs = require_graceful_fs();
1215
+ var retry = require_retry();
1216
+ var onExit = require_signal_exit();
1217
+ var mtimePrecision = require_mtime_precision();
1218
+ var locks = {};
1219
+ function getLockFile(file, options) {
1220
+ return options.lockfilePath || `${file}.lock`;
1221
+ }
1222
+ function resolveCanonicalPath(file, options, callback) {
1223
+ if (!options.realpath) {
1224
+ return callback(null, path.resolve(file));
1225
+ }
1226
+ options.fs.realpath(file, callback);
1227
+ }
1228
+ function acquireLock(file, options, callback) {
1229
+ const lockfilePath = getLockFile(file, options);
1230
+ options.fs.mkdir(lockfilePath, (err) => {
1231
+ if (!err) {
1232
+ return mtimePrecision.probe(lockfilePath, options.fs, (err2, mtime, mtimePrecision2) => {
1233
+ if (err2) {
1234
+ options.fs.rmdir(lockfilePath, () => {});
1235
+ return callback(err2);
1236
+ }
1237
+ callback(null, mtime, mtimePrecision2);
1238
+ });
1239
+ }
1240
+ if (err.code !== "EEXIST") {
1241
+ return callback(err);
1242
+ }
1243
+ if (options.stale <= 0) {
1244
+ return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
1245
+ }
1246
+ options.fs.stat(lockfilePath, (err2, stat) => {
1247
+ if (err2) {
1248
+ if (err2.code === "ENOENT") {
1249
+ return acquireLock(file, { ...options, stale: 0 }, callback);
1250
+ }
1251
+ return callback(err2);
1252
+ }
1253
+ if (!isLockStale(stat, options)) {
1254
+ return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
1255
+ }
1256
+ removeLock(file, options, (err3) => {
1257
+ if (err3) {
1258
+ return callback(err3);
1259
+ }
1260
+ acquireLock(file, { ...options, stale: 0 }, callback);
1261
+ });
1262
+ });
1263
+ });
1264
+ }
1265
+ function isLockStale(stat, options) {
1266
+ return stat.mtime.getTime() < Date.now() - options.stale;
1267
+ }
1268
+ function removeLock(file, options, callback) {
1269
+ options.fs.rmdir(getLockFile(file, options), (err) => {
1270
+ if (err && err.code !== "ENOENT") {
1271
+ return callback(err);
1272
+ }
1273
+ callback();
1274
+ });
1275
+ }
1276
+ function updateLock(file, options) {
1277
+ const lock2 = locks[file];
1278
+ if (lock2.updateTimeout) {
1279
+ return;
1280
+ }
1281
+ lock2.updateDelay = lock2.updateDelay || options.update;
1282
+ lock2.updateTimeout = setTimeout(() => {
1283
+ lock2.updateTimeout = null;
1284
+ options.fs.stat(lock2.lockfilePath, (err, stat) => {
1285
+ const isOverThreshold = lock2.lastUpdate + options.stale < Date.now();
1286
+ if (err) {
1287
+ if (err.code === "ENOENT" || isOverThreshold) {
1288
+ return setLockAsCompromised(file, lock2, Object.assign(err, { code: "ECOMPROMISED" }));
1289
+ }
1290
+ lock2.updateDelay = 1000;
1291
+ return updateLock(file, options);
1292
+ }
1293
+ const isMtimeOurs = lock2.mtime.getTime() === stat.mtime.getTime();
1294
+ if (!isMtimeOurs) {
1295
+ return setLockAsCompromised(file, lock2, Object.assign(new Error("Unable to update lock within the stale threshold"), { code: "ECOMPROMISED" }));
1296
+ }
1297
+ const mtime = mtimePrecision.getMtime(lock2.mtimePrecision);
1298
+ options.fs.utimes(lock2.lockfilePath, mtime, mtime, (err2) => {
1299
+ const isOverThreshold2 = lock2.lastUpdate + options.stale < Date.now();
1300
+ if (lock2.released) {
1301
+ return;
1302
+ }
1303
+ if (err2) {
1304
+ if (err2.code === "ENOENT" || isOverThreshold2) {
1305
+ return setLockAsCompromised(file, lock2, Object.assign(err2, { code: "ECOMPROMISED" }));
1306
+ }
1307
+ lock2.updateDelay = 1000;
1308
+ return updateLock(file, options);
1309
+ }
1310
+ lock2.mtime = mtime;
1311
+ lock2.lastUpdate = Date.now();
1312
+ lock2.updateDelay = null;
1313
+ updateLock(file, options);
1314
+ });
1315
+ });
1316
+ }, lock2.updateDelay);
1317
+ if (lock2.updateTimeout.unref) {
1318
+ lock2.updateTimeout.unref();
1319
+ }
1320
+ }
1321
+ function setLockAsCompromised(file, lock2, err) {
1322
+ lock2.released = true;
1323
+ if (lock2.updateTimeout) {
1324
+ clearTimeout(lock2.updateTimeout);
1325
+ }
1326
+ if (locks[file] === lock2) {
1327
+ delete locks[file];
1328
+ }
1329
+ lock2.options.onCompromised(err);
1330
+ }
1331
+ function lock(file, options, callback) {
1332
+ options = {
1333
+ stale: 1e4,
1334
+ update: null,
1335
+ realpath: true,
1336
+ retries: 0,
1337
+ fs,
1338
+ onCompromised: (err) => {
1339
+ throw err;
1340
+ },
1341
+ ...options
1342
+ };
1343
+ options.retries = options.retries || 0;
1344
+ options.retries = typeof options.retries === "number" ? { retries: options.retries } : options.retries;
1345
+ options.stale = Math.max(options.stale || 0, 2000);
1346
+ options.update = options.update == null ? options.stale / 2 : options.update || 0;
1347
+ options.update = Math.max(Math.min(options.update, options.stale / 2), 1000);
1348
+ resolveCanonicalPath(file, options, (err, file2) => {
1349
+ if (err) {
1350
+ return callback(err);
1351
+ }
1352
+ const operation = retry.operation(options.retries);
1353
+ operation.attempt(() => {
1354
+ acquireLock(file2, options, (err2, mtime, mtimePrecision2) => {
1355
+ if (operation.retry(err2)) {
1356
+ return;
1357
+ }
1358
+ if (err2) {
1359
+ return callback(operation.mainError());
1360
+ }
1361
+ const lock2 = locks[file2] = {
1362
+ lockfilePath: getLockFile(file2, options),
1363
+ mtime,
1364
+ mtimePrecision: mtimePrecision2,
1365
+ options,
1366
+ lastUpdate: Date.now()
1367
+ };
1368
+ updateLock(file2, options);
1369
+ callback(null, (releasedCallback) => {
1370
+ if (lock2.released) {
1371
+ return releasedCallback && releasedCallback(Object.assign(new Error("Lock is already released"), { code: "ERELEASED" }));
1372
+ }
1373
+ unlock(file2, { ...options, realpath: false }, releasedCallback);
1374
+ });
1375
+ });
1376
+ });
1377
+ });
1378
+ }
1379
+ function unlock(file, options, callback) {
1380
+ options = {
1381
+ fs,
1382
+ realpath: true,
1383
+ ...options
1384
+ };
1385
+ resolveCanonicalPath(file, options, (err, file2) => {
1386
+ if (err) {
1387
+ return callback(err);
1388
+ }
1389
+ const lock2 = locks[file2];
1390
+ if (!lock2) {
1391
+ return callback(Object.assign(new Error("Lock is not acquired/owned by you"), { code: "ENOTACQUIRED" }));
1392
+ }
1393
+ lock2.updateTimeout && clearTimeout(lock2.updateTimeout);
1394
+ lock2.released = true;
1395
+ delete locks[file2];
1396
+ removeLock(file2, options, callback);
1397
+ });
1398
+ }
1399
+ function check(file, options, callback) {
1400
+ options = {
1401
+ stale: 1e4,
1402
+ realpath: true,
1403
+ fs,
1404
+ ...options
1405
+ };
1406
+ options.stale = Math.max(options.stale || 0, 2000);
1407
+ resolveCanonicalPath(file, options, (err, file2) => {
1408
+ if (err) {
1409
+ return callback(err);
1410
+ }
1411
+ options.fs.stat(getLockFile(file2, options), (err2, stat) => {
1412
+ if (err2) {
1413
+ return err2.code === "ENOENT" ? callback(null, false) : callback(err2);
1414
+ }
1415
+ return callback(null, !isLockStale(stat, options));
1416
+ });
1417
+ });
1418
+ }
1419
+ function getLocks() {
1420
+ return locks;
1421
+ }
1422
+ onExit(() => {
1423
+ for (const file in locks) {
1424
+ const options = locks[file].options;
1425
+ try {
1426
+ options.fs.rmdirSync(getLockFile(file, options));
1427
+ } catch (e) {}
1428
+ }
1429
+ });
1430
+ exports.lock = lock;
1431
+ exports.unlock = unlock;
1432
+ exports.check = check;
1433
+ exports.getLocks = getLocks;
1434
+ });
1435
+
1436
+ // node_modules/proper-lockfile/lib/adapter.js
1437
+ var require_adapter = __commonJS((exports, module) => {
1438
+ var fs = require_graceful_fs();
1439
+ function createSyncFs(fs2) {
1440
+ const methods = ["mkdir", "realpath", "stat", "rmdir", "utimes"];
1441
+ const newFs = { ...fs2 };
1442
+ methods.forEach((method) => {
1443
+ newFs[method] = (...args) => {
1444
+ const callback = args.pop();
1445
+ let ret;
1446
+ try {
1447
+ ret = fs2[`${method}Sync`](...args);
1448
+ } catch (err) {
1449
+ return callback(err);
1450
+ }
1451
+ callback(null, ret);
1452
+ };
1453
+ });
1454
+ return newFs;
1455
+ }
1456
+ function toPromise(method) {
1457
+ return (...args) => new Promise((resolve, reject) => {
1458
+ args.push((err, result) => {
1459
+ if (err) {
1460
+ reject(err);
1461
+ } else {
1462
+ resolve(result);
1463
+ }
1464
+ });
1465
+ method(...args);
1466
+ });
1467
+ }
1468
+ function toSync(method) {
1469
+ return (...args) => {
1470
+ let err;
1471
+ let result;
1472
+ args.push((_err, _result) => {
1473
+ err = _err;
1474
+ result = _result;
1475
+ });
1476
+ method(...args);
1477
+ if (err) {
1478
+ throw err;
1479
+ }
1480
+ return result;
1481
+ };
1482
+ }
1483
+ function toSyncOptions(options) {
1484
+ options = { ...options };
1485
+ options.fs = createSyncFs(options.fs || fs);
1486
+ if (typeof options.retries === "number" && options.retries > 0 || options.retries && typeof options.retries.retries === "number" && options.retries.retries > 0) {
1487
+ throw Object.assign(new Error("Cannot use retries with the sync api"), { code: "ESYNC" });
1488
+ }
1489
+ return options;
1490
+ }
1491
+ module.exports = {
1492
+ toPromise,
1493
+ toSync,
1494
+ toSyncOptions
1495
+ };
1496
+ });
1497
+
1498
+ // node_modules/proper-lockfile/index.js
1499
+ var require_proper_lockfile = __commonJS((exports, module) => {
1500
+ var lockfile = require_lockfile();
1501
+ var { toPromise, toSync, toSyncOptions } = require_adapter();
1502
+ async function lock(file, options) {
1503
+ const release = await toPromise(lockfile.lock)(file, options);
1504
+ return toPromise(release);
1505
+ }
1506
+ function lockSync(file, options) {
1507
+ const release = toSync(lockfile.lock)(file, toSyncOptions(options));
1508
+ return toSync(release);
1509
+ }
1510
+ function unlock(file, options) {
1511
+ return toPromise(lockfile.unlock)(file, options);
1512
+ }
1513
+ function unlockSync(file, options) {
1514
+ return toSync(lockfile.unlock)(file, toSyncOptions(options));
1515
+ }
1516
+ function check(file, options) {
1517
+ return toPromise(lockfile.check)(file, options);
1518
+ }
1519
+ function checkSync(file, options) {
1520
+ return toSync(lockfile.check)(file, toSyncOptions(options));
1521
+ }
1522
+ module.exports = lock;
1523
+ module.exports.lock = lock;
1524
+ module.exports.unlock = unlock;
1525
+ module.exports.lockSync = lockSync;
1526
+ module.exports.unlockSync = unlockSync;
1527
+ module.exports.check = check;
1528
+ module.exports.checkSync = checkSync;
1529
+ });
1530
+
1531
+ // src/parallel/file-locks.ts
1532
+ var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
1533
+ import * as fs from "fs";
1534
+ import * as path from "path";
1535
+ var LOCKS_DIR = ".swarm/locks";
1536
+ var LOCK_TIMEOUT_MS = 5 * 60 * 1000;
1537
+ var _internals = {
1538
+ tryAcquireLock,
1539
+ writeFile: fs.promises.writeFile
1540
+ };
1541
+ function getLockFilePath(directory, filePath) {
1542
+ const normalized = path.resolve(directory, filePath);
1543
+ const baseDir = path.resolve(directory) + path.sep;
1544
+ const pathOk = process.platform === "win32" ? normalized.toLowerCase().startsWith(baseDir.toLowerCase()) : normalized.startsWith(baseDir);
1545
+ if (!pathOk) {
1546
+ throw new Error("Invalid file path: path traversal not allowed");
1547
+ }
1548
+ const pathForHash = process.platform === "win32" ? normalized.toLowerCase() : normalized;
1549
+ const hash = Buffer.from(pathForHash).toString("base64").replace(/[/+=]/g, "_");
1550
+ const lockPath = path.join(directory, LOCKS_DIR, `${hash}.lock`);
1551
+ if (process.platform === "win32") {
1552
+ const oldHash = Buffer.from(normalized).toString("base64").replace(/[/+=]/g, "_");
1553
+ const oldLockPath = path.join(directory, LOCKS_DIR, `${oldHash}.lock`);
1554
+ if (fs.existsSync(oldLockPath)) {
1555
+ return oldLockPath;
1556
+ }
1557
+ }
1558
+ return lockPath;
1559
+ }
1560
+ async function tryAcquireLock(directory, filePath, agent, taskId) {
1561
+ const lockPath = getLockFilePath(directory, filePath);
1562
+ const locksDir = path.dirname(lockPath);
1563
+ if (!fs.existsSync(locksDir)) {
1564
+ fs.mkdirSync(locksDir, { recursive: true });
1565
+ }
1566
+ if (!fs.existsSync(lockPath)) {
1567
+ fs.writeFileSync(lockPath, "", "utf-8");
1568
+ }
1569
+ let release;
1570
+ try {
1571
+ release = await import_proper_lockfile.default.lock(lockPath, {
1572
+ stale: LOCK_TIMEOUT_MS,
1573
+ retries: {
1574
+ retries: 5,
1575
+ minTimeout: 10,
1576
+ maxTimeout: 500,
1577
+ factor: 2
1578
+ },
1579
+ realpath: false
1580
+ });
1581
+ } catch (err) {
1582
+ const code = err.code;
1583
+ if (code === "ELOCKED" || code === "EEXIST") {
1584
+ return { acquired: false };
1585
+ }
1586
+ throw err;
1587
+ }
1588
+ const lock = {
1589
+ filePath,
1590
+ agent,
1591
+ taskId,
1592
+ timestamp: new Date().toISOString(),
1593
+ expiresAt: Date.now() + LOCK_TIMEOUT_MS,
1594
+ _release: release
1595
+ };
1596
+ return { acquired: true, lock };
1597
+ }
1598
+
1599
+ // src/evidence/lock.ts
1600
+ class EvidenceLockTimeoutError extends Error {
1601
+ directory;
1602
+ evidencePath;
1603
+ agent;
1604
+ taskId;
1605
+ constructor(directory, evidencePath, agent, taskId, timeoutMs) {
1606
+ super(`Evidence lock timeout after ${timeoutMs}ms for ${evidencePath} (agent=${agent}, task=${taskId})`);
1607
+ this.name = "EvidenceLockTimeoutError";
1608
+ this.directory = directory;
1609
+ this.evidencePath = evidencePath;
1610
+ this.agent = agent;
1611
+ this.taskId = taskId;
1612
+ }
1613
+ }
1614
+ var BACKOFF_START_MS = 50;
1615
+ var BACKOFF_MAX_MS = 2000;
1616
+ var BACKOFF_JITTER_RATIO = 0.25;
1617
+ function backoffMs(attempt) {
1618
+ const base = Math.min(BACKOFF_START_MS * 2 ** attempt, BACKOFF_MAX_MS);
1619
+ const jitter = base * BACKOFF_JITTER_RATIO * (Math.random() * 2 - 1);
1620
+ return Math.max(1, Math.round(base + jitter));
1621
+ }
1622
+ async function withEvidenceLock(directory, evidencePath, agent, taskId, fn, timeoutMs = 60000) {
1623
+ const deadline = Date.now() + timeoutMs;
1624
+ let attempt = 0;
1625
+ while (true) {
1626
+ const result = await tryAcquireLock(directory, evidencePath, agent, taskId);
1627
+ if (result.acquired) {
1628
+ const lock = result.lock;
1629
+ if (attempt > 0) {
1630
+ emit("evidence_lock_stale_recovered", {
1631
+ directory,
1632
+ evidencePath,
1633
+ agent,
1634
+ taskId,
1635
+ attempt
1636
+ });
1637
+ }
1638
+ emit("evidence_lock_acquired", {
1639
+ directory,
1640
+ evidencePath,
1641
+ agent,
1642
+ taskId,
1643
+ attempt
1644
+ });
1645
+ try {
1646
+ return await fn();
1647
+ } finally {
1648
+ if (lock._release) {
1649
+ try {
1650
+ await lock._release();
1651
+ } catch {}
1652
+ }
1653
+ }
1654
+ }
1655
+ if (Date.now() >= deadline) {
1656
+ throw new EvidenceLockTimeoutError(directory, evidencePath, agent, taskId, timeoutMs);
1657
+ }
1658
+ emit("evidence_lock_contended", {
1659
+ directory,
1660
+ evidencePath,
1661
+ agent,
1662
+ taskId,
1663
+ attempt
1664
+ });
1665
+ const delay = Math.min(backoffMs(attempt), deadline - Date.now());
1666
+ if (delay > 0) {
1667
+ await new Promise((resolve2) => setTimeout(resolve2, delay));
1668
+ }
1669
+ attempt++;
1670
+ }
1671
+ }
1672
+
1673
+ export { require_proper_lockfile, tryAcquireLock, withEvidenceLock };