@clef-sh/core 0.1.16 → 0.1.18

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 (37) hide show
  1. package/dist/compliance/generator.d.ts +19 -0
  2. package/dist/compliance/generator.d.ts.map +1 -0
  3. package/dist/compliance/run.d.ts +85 -0
  4. package/dist/compliance/run.d.ts.map +1 -0
  5. package/dist/compliance/types.d.ts +72 -0
  6. package/dist/compliance/types.d.ts.map +1 -0
  7. package/dist/git/integration.d.ts +8 -5
  8. package/dist/git/integration.d.ts.map +1 -1
  9. package/dist/import/index.d.ts +7 -0
  10. package/dist/import/index.d.ts.map +1 -1
  11. package/dist/index.d.mts +11 -2
  12. package/dist/index.d.ts +11 -2
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +979 -318
  15. package/dist/index.js.map +4 -4
  16. package/dist/index.mjs +913 -294
  17. package/dist/index.mjs.map +4 -4
  18. package/dist/lint/runner.d.ts +7 -0
  19. package/dist/lint/runner.d.ts.map +1 -1
  20. package/dist/merge/metadata-driver.d.ts +17 -0
  21. package/dist/merge/metadata-driver.d.ts.map +1 -0
  22. package/dist/pending/metadata.d.ts +40 -15
  23. package/dist/pending/metadata.d.ts.map +1 -1
  24. package/dist/policy/evaluator.d.ts +49 -0
  25. package/dist/policy/evaluator.d.ts.map +1 -0
  26. package/dist/policy/parser.d.ts +36 -0
  27. package/dist/policy/parser.d.ts.map +1 -0
  28. package/dist/policy/types.d.ts +101 -0
  29. package/dist/policy/types.d.ts.map +1 -0
  30. package/dist/scanner/index.d.ts +9 -1
  31. package/dist/scanner/index.d.ts.map +1 -1
  32. package/dist/scanner/patterns.d.ts +12 -0
  33. package/dist/scanner/patterns.d.ts.map +1 -1
  34. package/dist/sops/client.d.ts.map +1 -1
  35. package/dist/types/index.d.ts +25 -1
  36. package/dist/types/index.d.ts.map +1 -1
  37. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -301,13 +301,13 @@ var require_lib = __commonJS({
301
301
  "node_modules/write-file-atomic/lib/index.js"(exports2, module2) {
302
302
  "use strict";
303
303
  module2.exports = writeFile;
304
- module2.exports.sync = writeFileSync6;
304
+ module2.exports.sync = writeFileSync7;
305
305
  module2.exports._getTmpname = getTmpname;
306
306
  module2.exports._cleanupOnExit = cleanupOnExit;
307
- var fs17 = require("fs");
307
+ var fs19 = require("fs");
308
308
  var crypto5 = require("node:crypto");
309
309
  var { onExit } = require_cjs();
310
- var path25 = require("path");
310
+ var path26 = require("path");
311
311
  var { promisify } = require("util");
312
312
  var activeFiles = {};
313
313
  var threadId = (function getId() {
@@ -325,7 +325,7 @@ var require_lib = __commonJS({
325
325
  function cleanupOnExit(tmpfile) {
326
326
  return () => {
327
327
  try {
328
- fs17.unlinkSync(typeof tmpfile === "function" ? tmpfile() : tmpfile);
328
+ fs19.unlinkSync(typeof tmpfile === "function" ? tmpfile() : tmpfile);
329
329
  } catch {
330
330
  }
331
331
  };
@@ -360,13 +360,13 @@ var require_lib = __commonJS({
360
360
  let fd;
361
361
  let tmpfile;
362
362
  const removeOnExitHandler = onExit(cleanupOnExit(() => tmpfile));
363
- const absoluteName = path25.resolve(filename);
363
+ const absoluteName = path26.resolve(filename);
364
364
  try {
365
365
  await serializeActiveFile(absoluteName);
366
- const truename = await promisify(fs17.realpath)(filename).catch(() => filename);
366
+ const truename = await promisify(fs19.realpath)(filename).catch(() => filename);
367
367
  tmpfile = getTmpname(truename);
368
368
  if (!options.mode || !options.chown) {
369
- const stats = await promisify(fs17.stat)(truename).catch(() => {
369
+ const stats = await promisify(fs19.stat)(truename).catch(() => {
370
370
  });
371
371
  if (stats) {
372
372
  if (options.mode == null) {
@@ -377,45 +377,45 @@ var require_lib = __commonJS({
377
377
  }
378
378
  }
379
379
  }
380
- fd = await promisify(fs17.open)(tmpfile, "w", options.mode);
380
+ fd = await promisify(fs19.open)(tmpfile, "w", options.mode);
381
381
  if (options.tmpfileCreated) {
382
382
  await options.tmpfileCreated(tmpfile);
383
383
  }
384
384
  if (ArrayBuffer.isView(data)) {
385
- await promisify(fs17.write)(fd, data, 0, data.length, 0);
385
+ await promisify(fs19.write)(fd, data, 0, data.length, 0);
386
386
  } else if (data != null) {
387
- await promisify(fs17.write)(fd, String(data), 0, String(options.encoding || "utf8"));
387
+ await promisify(fs19.write)(fd, String(data), 0, String(options.encoding || "utf8"));
388
388
  }
389
389
  if (options.fsync !== false) {
390
- await promisify(fs17.fsync)(fd);
390
+ await promisify(fs19.fsync)(fd);
391
391
  }
392
- await promisify(fs17.close)(fd);
392
+ await promisify(fs19.close)(fd);
393
393
  fd = null;
394
394
  if (options.chown) {
395
- await promisify(fs17.chown)(tmpfile, options.chown.uid, options.chown.gid).catch((err) => {
395
+ await promisify(fs19.chown)(tmpfile, options.chown.uid, options.chown.gid).catch((err) => {
396
396
  if (!isChownErrOk(err)) {
397
397
  throw err;
398
398
  }
399
399
  });
400
400
  }
401
401
  if (options.mode) {
402
- await promisify(fs17.chmod)(tmpfile, options.mode).catch((err) => {
402
+ await promisify(fs19.chmod)(tmpfile, options.mode).catch((err) => {
403
403
  if (!isChownErrOk(err)) {
404
404
  throw err;
405
405
  }
406
406
  });
407
407
  }
408
- await promisify(fs17.rename)(tmpfile, truename);
408
+ await promisify(fs19.rename)(tmpfile, truename);
409
409
  } finally {
410
410
  if (fd) {
411
- await promisify(fs17.close)(fd).catch(
411
+ await promisify(fs19.close)(fd).catch(
412
412
  /* istanbul ignore next */
413
413
  () => {
414
414
  }
415
415
  );
416
416
  }
417
417
  removeOnExitHandler();
418
- await promisify(fs17.unlink)(tmpfile).catch(() => {
418
+ await promisify(fs19.unlink)(tmpfile).catch(() => {
419
419
  });
420
420
  activeFiles[absoluteName].shift();
421
421
  if (activeFiles[absoluteName].length > 0) {
@@ -441,20 +441,20 @@ var require_lib = __commonJS({
441
441
  }
442
442
  return promise;
443
443
  }
444
- function writeFileSync6(filename, data, options) {
444
+ function writeFileSync7(filename, data, options) {
445
445
  if (typeof options === "string") {
446
446
  options = { encoding: options };
447
447
  } else if (!options) {
448
448
  options = {};
449
449
  }
450
450
  try {
451
- filename = fs17.realpathSync(filename);
451
+ filename = fs19.realpathSync(filename);
452
452
  } catch (ex) {
453
453
  }
454
454
  const tmpfile = getTmpname(filename);
455
455
  if (!options.mode || !options.chown) {
456
456
  try {
457
- const stats = fs17.statSync(filename);
457
+ const stats = fs19.statSync(filename);
458
458
  options = Object.assign({}, options);
459
459
  if (!options.mode) {
460
460
  options.mode = stats.mode;
@@ -470,23 +470,23 @@ var require_lib = __commonJS({
470
470
  const removeOnExitHandler = onExit(cleanup);
471
471
  let threw = true;
472
472
  try {
473
- fd = fs17.openSync(tmpfile, "w", options.mode || 438);
473
+ fd = fs19.openSync(tmpfile, "w", options.mode || 438);
474
474
  if (options.tmpfileCreated) {
475
475
  options.tmpfileCreated(tmpfile);
476
476
  }
477
477
  if (ArrayBuffer.isView(data)) {
478
- fs17.writeSync(fd, data, 0, data.length, 0);
478
+ fs19.writeSync(fd, data, 0, data.length, 0);
479
479
  } else if (data != null) {
480
- fs17.writeSync(fd, String(data), 0, String(options.encoding || "utf8"));
480
+ fs19.writeSync(fd, String(data), 0, String(options.encoding || "utf8"));
481
481
  }
482
482
  if (options.fsync !== false) {
483
- fs17.fsyncSync(fd);
483
+ fs19.fsyncSync(fd);
484
484
  }
485
- fs17.closeSync(fd);
485
+ fs19.closeSync(fd);
486
486
  fd = null;
487
487
  if (options.chown) {
488
488
  try {
489
- fs17.chownSync(tmpfile, options.chown.uid, options.chown.gid);
489
+ fs19.chownSync(tmpfile, options.chown.uid, options.chown.gid);
490
490
  } catch (err) {
491
491
  if (!isChownErrOk(err)) {
492
492
  throw err;
@@ -495,19 +495,19 @@ var require_lib = __commonJS({
495
495
  }
496
496
  if (options.mode) {
497
497
  try {
498
- fs17.chmodSync(tmpfile, options.mode);
498
+ fs19.chmodSync(tmpfile, options.mode);
499
499
  } catch (err) {
500
500
  if (!isChownErrOk(err)) {
501
501
  throw err;
502
502
  }
503
503
  }
504
504
  }
505
- fs17.renameSync(tmpfile, filename);
505
+ fs19.renameSync(tmpfile, filename);
506
506
  threw = false;
507
507
  } finally {
508
508
  if (fd) {
509
509
  try {
510
- fs17.closeSync(fd);
510
+ fs19.closeSync(fd);
511
511
  } catch (ex) {
512
512
  }
513
513
  }
@@ -546,54 +546,54 @@ var require_polyfills = __commonJS({
546
546
  }
547
547
  var chdir;
548
548
  module2.exports = patch;
549
- function patch(fs17) {
549
+ function patch(fs19) {
550
550
  if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
551
- patchLchmod(fs17);
552
- }
553
- if (!fs17.lutimes) {
554
- patchLutimes(fs17);
555
- }
556
- fs17.chown = chownFix(fs17.chown);
557
- fs17.fchown = chownFix(fs17.fchown);
558
- fs17.lchown = chownFix(fs17.lchown);
559
- fs17.chmod = chmodFix(fs17.chmod);
560
- fs17.fchmod = chmodFix(fs17.fchmod);
561
- fs17.lchmod = chmodFix(fs17.lchmod);
562
- fs17.chownSync = chownFixSync(fs17.chownSync);
563
- fs17.fchownSync = chownFixSync(fs17.fchownSync);
564
- fs17.lchownSync = chownFixSync(fs17.lchownSync);
565
- fs17.chmodSync = chmodFixSync(fs17.chmodSync);
566
- fs17.fchmodSync = chmodFixSync(fs17.fchmodSync);
567
- fs17.lchmodSync = chmodFixSync(fs17.lchmodSync);
568
- fs17.stat = statFix(fs17.stat);
569
- fs17.fstat = statFix(fs17.fstat);
570
- fs17.lstat = statFix(fs17.lstat);
571
- fs17.statSync = statFixSync(fs17.statSync);
572
- fs17.fstatSync = statFixSync(fs17.fstatSync);
573
- fs17.lstatSync = statFixSync(fs17.lstatSync);
574
- if (fs17.chmod && !fs17.lchmod) {
575
- fs17.lchmod = function(path25, mode, cb) {
551
+ patchLchmod(fs19);
552
+ }
553
+ if (!fs19.lutimes) {
554
+ patchLutimes(fs19);
555
+ }
556
+ fs19.chown = chownFix(fs19.chown);
557
+ fs19.fchown = chownFix(fs19.fchown);
558
+ fs19.lchown = chownFix(fs19.lchown);
559
+ fs19.chmod = chmodFix(fs19.chmod);
560
+ fs19.fchmod = chmodFix(fs19.fchmod);
561
+ fs19.lchmod = chmodFix(fs19.lchmod);
562
+ fs19.chownSync = chownFixSync(fs19.chownSync);
563
+ fs19.fchownSync = chownFixSync(fs19.fchownSync);
564
+ fs19.lchownSync = chownFixSync(fs19.lchownSync);
565
+ fs19.chmodSync = chmodFixSync(fs19.chmodSync);
566
+ fs19.fchmodSync = chmodFixSync(fs19.fchmodSync);
567
+ fs19.lchmodSync = chmodFixSync(fs19.lchmodSync);
568
+ fs19.stat = statFix(fs19.stat);
569
+ fs19.fstat = statFix(fs19.fstat);
570
+ fs19.lstat = statFix(fs19.lstat);
571
+ fs19.statSync = statFixSync(fs19.statSync);
572
+ fs19.fstatSync = statFixSync(fs19.fstatSync);
573
+ fs19.lstatSync = statFixSync(fs19.lstatSync);
574
+ if (fs19.chmod && !fs19.lchmod) {
575
+ fs19.lchmod = function(path26, mode, cb) {
576
576
  if (cb) process.nextTick(cb);
577
577
  };
578
- fs17.lchmodSync = function() {
578
+ fs19.lchmodSync = function() {
579
579
  };
580
580
  }
581
- if (fs17.chown && !fs17.lchown) {
582
- fs17.lchown = function(path25, uid, gid, cb) {
581
+ if (fs19.chown && !fs19.lchown) {
582
+ fs19.lchown = function(path26, uid, gid, cb) {
583
583
  if (cb) process.nextTick(cb);
584
584
  };
585
- fs17.lchownSync = function() {
585
+ fs19.lchownSync = function() {
586
586
  };
587
587
  }
588
588
  if (platform === "win32") {
589
- fs17.rename = typeof fs17.rename !== "function" ? fs17.rename : (function(fs$rename) {
589
+ fs19.rename = typeof fs19.rename !== "function" ? fs19.rename : (function(fs$rename) {
590
590
  function rename(from, to, cb) {
591
591
  var start = Date.now();
592
592
  var backoff = 0;
593
593
  fs$rename(from, to, function CB(er) {
594
594
  if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
595
595
  setTimeout(function() {
596
- fs17.stat(to, function(stater, st) {
596
+ fs19.stat(to, function(stater, st) {
597
597
  if (stater && stater.code === "ENOENT")
598
598
  fs$rename(from, to, CB);
599
599
  else
@@ -609,9 +609,9 @@ var require_polyfills = __commonJS({
609
609
  }
610
610
  if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
611
611
  return rename;
612
- })(fs17.rename);
612
+ })(fs19.rename);
613
613
  }
614
- fs17.read = typeof fs17.read !== "function" ? fs17.read : (function(fs$read) {
614
+ fs19.read = typeof fs19.read !== "function" ? fs19.read : (function(fs$read) {
615
615
  function read(fd, buffer, offset, length, position, callback_) {
616
616
  var callback;
617
617
  if (callback_ && typeof callback_ === "function") {
@@ -619,22 +619,22 @@ var require_polyfills = __commonJS({
619
619
  callback = function(er, _, __) {
620
620
  if (er && er.code === "EAGAIN" && eagCounter < 10) {
621
621
  eagCounter++;
622
- return fs$read.call(fs17, fd, buffer, offset, length, position, callback);
622
+ return fs$read.call(fs19, fd, buffer, offset, length, position, callback);
623
623
  }
624
624
  callback_.apply(this, arguments);
625
625
  };
626
626
  }
627
- return fs$read.call(fs17, fd, buffer, offset, length, position, callback);
627
+ return fs$read.call(fs19, fd, buffer, offset, length, position, callback);
628
628
  }
629
629
  if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
630
630
  return read;
631
- })(fs17.read);
632
- fs17.readSync = typeof fs17.readSync !== "function" ? fs17.readSync : /* @__PURE__ */ (function(fs$readSync) {
631
+ })(fs19.read);
632
+ fs19.readSync = typeof fs19.readSync !== "function" ? fs19.readSync : /* @__PURE__ */ (function(fs$readSync) {
633
633
  return function(fd, buffer, offset, length, position) {
634
634
  var eagCounter = 0;
635
635
  while (true) {
636
636
  try {
637
- return fs$readSync.call(fs17, fd, buffer, offset, length, position);
637
+ return fs$readSync.call(fs19, fd, buffer, offset, length, position);
638
638
  } catch (er) {
639
639
  if (er.code === "EAGAIN" && eagCounter < 10) {
640
640
  eagCounter++;
@@ -644,11 +644,11 @@ var require_polyfills = __commonJS({
644
644
  }
645
645
  }
646
646
  };
647
- })(fs17.readSync);
648
- function patchLchmod(fs18) {
649
- fs18.lchmod = function(path25, mode, callback) {
650
- fs18.open(
651
- path25,
647
+ })(fs19.readSync);
648
+ function patchLchmod(fs20) {
649
+ fs20.lchmod = function(path26, mode, callback) {
650
+ fs20.open(
651
+ path26,
652
652
  constants.O_WRONLY | constants.O_SYMLINK,
653
653
  mode,
654
654
  function(err, fd) {
@@ -656,80 +656,80 @@ var require_polyfills = __commonJS({
656
656
  if (callback) callback(err);
657
657
  return;
658
658
  }
659
- fs18.fchmod(fd, mode, function(err2) {
660
- fs18.close(fd, function(err22) {
659
+ fs20.fchmod(fd, mode, function(err2) {
660
+ fs20.close(fd, function(err22) {
661
661
  if (callback) callback(err2 || err22);
662
662
  });
663
663
  });
664
664
  }
665
665
  );
666
666
  };
667
- fs18.lchmodSync = function(path25, mode) {
668
- var fd = fs18.openSync(path25, constants.O_WRONLY | constants.O_SYMLINK, mode);
667
+ fs20.lchmodSync = function(path26, mode) {
668
+ var fd = fs20.openSync(path26, constants.O_WRONLY | constants.O_SYMLINK, mode);
669
669
  var threw = true;
670
670
  var ret;
671
671
  try {
672
- ret = fs18.fchmodSync(fd, mode);
672
+ ret = fs20.fchmodSync(fd, mode);
673
673
  threw = false;
674
674
  } finally {
675
675
  if (threw) {
676
676
  try {
677
- fs18.closeSync(fd);
677
+ fs20.closeSync(fd);
678
678
  } catch (er) {
679
679
  }
680
680
  } else {
681
- fs18.closeSync(fd);
681
+ fs20.closeSync(fd);
682
682
  }
683
683
  }
684
684
  return ret;
685
685
  };
686
686
  }
687
- function patchLutimes(fs18) {
688
- if (constants.hasOwnProperty("O_SYMLINK") && fs18.futimes) {
689
- fs18.lutimes = function(path25, at, mt, cb) {
690
- fs18.open(path25, constants.O_SYMLINK, function(er, fd) {
687
+ function patchLutimes(fs20) {
688
+ if (constants.hasOwnProperty("O_SYMLINK") && fs20.futimes) {
689
+ fs20.lutimes = function(path26, at, mt, cb) {
690
+ fs20.open(path26, constants.O_SYMLINK, function(er, fd) {
691
691
  if (er) {
692
692
  if (cb) cb(er);
693
693
  return;
694
694
  }
695
- fs18.futimes(fd, at, mt, function(er2) {
696
- fs18.close(fd, function(er22) {
695
+ fs20.futimes(fd, at, mt, function(er2) {
696
+ fs20.close(fd, function(er22) {
697
697
  if (cb) cb(er2 || er22);
698
698
  });
699
699
  });
700
700
  });
701
701
  };
702
- fs18.lutimesSync = function(path25, at, mt) {
703
- var fd = fs18.openSync(path25, constants.O_SYMLINK);
702
+ fs20.lutimesSync = function(path26, at, mt) {
703
+ var fd = fs20.openSync(path26, constants.O_SYMLINK);
704
704
  var ret;
705
705
  var threw = true;
706
706
  try {
707
- ret = fs18.futimesSync(fd, at, mt);
707
+ ret = fs20.futimesSync(fd, at, mt);
708
708
  threw = false;
709
709
  } finally {
710
710
  if (threw) {
711
711
  try {
712
- fs18.closeSync(fd);
712
+ fs20.closeSync(fd);
713
713
  } catch (er) {
714
714
  }
715
715
  } else {
716
- fs18.closeSync(fd);
716
+ fs20.closeSync(fd);
717
717
  }
718
718
  }
719
719
  return ret;
720
720
  };
721
- } else if (fs18.futimes) {
722
- fs18.lutimes = function(_a, _b, _c, cb) {
721
+ } else if (fs20.futimes) {
722
+ fs20.lutimes = function(_a, _b, _c, cb) {
723
723
  if (cb) process.nextTick(cb);
724
724
  };
725
- fs18.lutimesSync = function() {
725
+ fs20.lutimesSync = function() {
726
726
  };
727
727
  }
728
728
  }
729
729
  function chmodFix(orig) {
730
730
  if (!orig) return orig;
731
731
  return function(target, mode, cb) {
732
- return orig.call(fs17, target, mode, function(er) {
732
+ return orig.call(fs19, target, mode, function(er) {
733
733
  if (chownErOk(er)) er = null;
734
734
  if (cb) cb.apply(this, arguments);
735
735
  });
@@ -739,7 +739,7 @@ var require_polyfills = __commonJS({
739
739
  if (!orig) return orig;
740
740
  return function(target, mode) {
741
741
  try {
742
- return orig.call(fs17, target, mode);
742
+ return orig.call(fs19, target, mode);
743
743
  } catch (er) {
744
744
  if (!chownErOk(er)) throw er;
745
745
  }
@@ -748,7 +748,7 @@ var require_polyfills = __commonJS({
748
748
  function chownFix(orig) {
749
749
  if (!orig) return orig;
750
750
  return function(target, uid, gid, cb) {
751
- return orig.call(fs17, target, uid, gid, function(er) {
751
+ return orig.call(fs19, target, uid, gid, function(er) {
752
752
  if (chownErOk(er)) er = null;
753
753
  if (cb) cb.apply(this, arguments);
754
754
  });
@@ -758,7 +758,7 @@ var require_polyfills = __commonJS({
758
758
  if (!orig) return orig;
759
759
  return function(target, uid, gid) {
760
760
  try {
761
- return orig.call(fs17, target, uid, gid);
761
+ return orig.call(fs19, target, uid, gid);
762
762
  } catch (er) {
763
763
  if (!chownErOk(er)) throw er;
764
764
  }
@@ -778,13 +778,13 @@ var require_polyfills = __commonJS({
778
778
  }
779
779
  if (cb) cb.apply(this, arguments);
780
780
  }
781
- return options ? orig.call(fs17, target, options, callback) : orig.call(fs17, target, callback);
781
+ return options ? orig.call(fs19, target, options, callback) : orig.call(fs19, target, callback);
782
782
  };
783
783
  }
784
784
  function statFixSync(orig) {
785
785
  if (!orig) return orig;
786
786
  return function(target, options) {
787
- var stats = options ? orig.call(fs17, target, options) : orig.call(fs17, target);
787
+ var stats = options ? orig.call(fs19, target, options) : orig.call(fs19, target);
788
788
  if (stats) {
789
789
  if (stats.uid < 0) stats.uid += 4294967296;
790
790
  if (stats.gid < 0) stats.gid += 4294967296;
@@ -813,16 +813,16 @@ var require_legacy_streams = __commonJS({
813
813
  "../../node_modules/graceful-fs/legacy-streams.js"(exports2, module2) {
814
814
  var Stream = require("stream").Stream;
815
815
  module2.exports = legacy;
816
- function legacy(fs17) {
816
+ function legacy(fs19) {
817
817
  return {
818
818
  ReadStream,
819
819
  WriteStream
820
820
  };
821
- function ReadStream(path25, options) {
822
- if (!(this instanceof ReadStream)) return new ReadStream(path25, options);
821
+ function ReadStream(path26, options) {
822
+ if (!(this instanceof ReadStream)) return new ReadStream(path26, options);
823
823
  Stream.call(this);
824
824
  var self = this;
825
- this.path = path25;
825
+ this.path = path26;
826
826
  this.fd = null;
827
827
  this.readable = true;
828
828
  this.paused = false;
@@ -856,7 +856,7 @@ var require_legacy_streams = __commonJS({
856
856
  });
857
857
  return;
858
858
  }
859
- fs17.open(this.path, this.flags, this.mode, function(err, fd) {
859
+ fs19.open(this.path, this.flags, this.mode, function(err, fd) {
860
860
  if (err) {
861
861
  self.emit("error", err);
862
862
  self.readable = false;
@@ -867,10 +867,10 @@ var require_legacy_streams = __commonJS({
867
867
  self._read();
868
868
  });
869
869
  }
870
- function WriteStream(path25, options) {
871
- if (!(this instanceof WriteStream)) return new WriteStream(path25, options);
870
+ function WriteStream(path26, options) {
871
+ if (!(this instanceof WriteStream)) return new WriteStream(path26, options);
872
872
  Stream.call(this);
873
- this.path = path25;
873
+ this.path = path26;
874
874
  this.fd = null;
875
875
  this.writable = true;
876
876
  this.flags = "w";
@@ -895,7 +895,7 @@ var require_legacy_streams = __commonJS({
895
895
  this.busy = false;
896
896
  this._queue = [];
897
897
  if (this.fd === null) {
898
- this._open = fs17.open;
898
+ this._open = fs19.open;
899
899
  this._queue.push([this._open, this.path, this.flags, this.mode, void 0]);
900
900
  this.flush();
901
901
  }
@@ -930,7 +930,7 @@ var require_clone = __commonJS({
930
930
  // ../../node_modules/graceful-fs/graceful-fs.js
931
931
  var require_graceful_fs = __commonJS({
932
932
  "../../node_modules/graceful-fs/graceful-fs.js"(exports2, module2) {
933
- var fs17 = require("fs");
933
+ var fs19 = require("fs");
934
934
  var polyfills = require_polyfills();
935
935
  var legacy = require_legacy_streams();
936
936
  var clone = require_clone();
@@ -962,12 +962,12 @@ var require_graceful_fs = __commonJS({
962
962
  m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
963
963
  console.error(m);
964
964
  };
965
- if (!fs17[gracefulQueue]) {
965
+ if (!fs19[gracefulQueue]) {
966
966
  queue = global[gracefulQueue] || [];
967
- publishQueue(fs17, queue);
968
- fs17.close = (function(fs$close) {
967
+ publishQueue(fs19, queue);
968
+ fs19.close = (function(fs$close) {
969
969
  function close(fd, cb) {
970
- return fs$close.call(fs17, fd, function(err) {
970
+ return fs$close.call(fs19, fd, function(err) {
971
971
  if (!err) {
972
972
  resetQueue();
973
973
  }
@@ -979,48 +979,48 @@ var require_graceful_fs = __commonJS({
979
979
  value: fs$close
980
980
  });
981
981
  return close;
982
- })(fs17.close);
983
- fs17.closeSync = (function(fs$closeSync) {
982
+ })(fs19.close);
983
+ fs19.closeSync = (function(fs$closeSync) {
984
984
  function closeSync2(fd) {
985
- fs$closeSync.apply(fs17, arguments);
985
+ fs$closeSync.apply(fs19, arguments);
986
986
  resetQueue();
987
987
  }
988
988
  Object.defineProperty(closeSync2, previousSymbol, {
989
989
  value: fs$closeSync
990
990
  });
991
991
  return closeSync2;
992
- })(fs17.closeSync);
992
+ })(fs19.closeSync);
993
993
  if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
994
994
  process.on("exit", function() {
995
- debug(fs17[gracefulQueue]);
996
- require("assert").equal(fs17[gracefulQueue].length, 0);
995
+ debug(fs19[gracefulQueue]);
996
+ require("assert").equal(fs19[gracefulQueue].length, 0);
997
997
  });
998
998
  }
999
999
  }
1000
1000
  var queue;
1001
1001
  if (!global[gracefulQueue]) {
1002
- publishQueue(global, fs17[gracefulQueue]);
1003
- }
1004
- module2.exports = patch(clone(fs17));
1005
- if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs17.__patched) {
1006
- module2.exports = patch(fs17);
1007
- fs17.__patched = true;
1008
- }
1009
- function patch(fs18) {
1010
- polyfills(fs18);
1011
- fs18.gracefulify = patch;
1012
- fs18.createReadStream = createReadStream;
1013
- fs18.createWriteStream = createWriteStream;
1014
- var fs$readFile = fs18.readFile;
1015
- fs18.readFile = readFile;
1016
- function readFile(path25, options, cb) {
1002
+ publishQueue(global, fs19[gracefulQueue]);
1003
+ }
1004
+ module2.exports = patch(clone(fs19));
1005
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs19.__patched) {
1006
+ module2.exports = patch(fs19);
1007
+ fs19.__patched = true;
1008
+ }
1009
+ function patch(fs20) {
1010
+ polyfills(fs20);
1011
+ fs20.gracefulify = patch;
1012
+ fs20.createReadStream = createReadStream;
1013
+ fs20.createWriteStream = createWriteStream;
1014
+ var fs$readFile = fs20.readFile;
1015
+ fs20.readFile = readFile;
1016
+ function readFile(path26, options, cb) {
1017
1017
  if (typeof options === "function")
1018
1018
  cb = options, options = null;
1019
- return go$readFile(path25, options, cb);
1020
- function go$readFile(path26, options2, cb2, startTime) {
1021
- return fs$readFile(path26, options2, function(err) {
1019
+ return go$readFile(path26, options, cb);
1020
+ function go$readFile(path27, options2, cb2, startTime) {
1021
+ return fs$readFile(path27, options2, function(err) {
1022
1022
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
1023
- enqueue([go$readFile, [path26, options2, cb2], err, startTime || Date.now(), Date.now()]);
1023
+ enqueue([go$readFile, [path27, options2, cb2], err, startTime || Date.now(), Date.now()]);
1024
1024
  else {
1025
1025
  if (typeof cb2 === "function")
1026
1026
  cb2.apply(this, arguments);
@@ -1028,16 +1028,16 @@ var require_graceful_fs = __commonJS({
1028
1028
  });
1029
1029
  }
1030
1030
  }
1031
- var fs$writeFile = fs18.writeFile;
1032
- fs18.writeFile = writeFile;
1033
- function writeFile(path25, data, options, cb) {
1031
+ var fs$writeFile = fs20.writeFile;
1032
+ fs20.writeFile = writeFile;
1033
+ function writeFile(path26, data, options, cb) {
1034
1034
  if (typeof options === "function")
1035
1035
  cb = options, options = null;
1036
- return go$writeFile(path25, data, options, cb);
1037
- function go$writeFile(path26, data2, options2, cb2, startTime) {
1038
- return fs$writeFile(path26, data2, options2, function(err) {
1036
+ return go$writeFile(path26, data, options, cb);
1037
+ function go$writeFile(path27, data2, options2, cb2, startTime) {
1038
+ return fs$writeFile(path27, data2, options2, function(err) {
1039
1039
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
1040
- enqueue([go$writeFile, [path26, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
1040
+ enqueue([go$writeFile, [path27, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
1041
1041
  else {
1042
1042
  if (typeof cb2 === "function")
1043
1043
  cb2.apply(this, arguments);
@@ -1045,17 +1045,17 @@ var require_graceful_fs = __commonJS({
1045
1045
  });
1046
1046
  }
1047
1047
  }
1048
- var fs$appendFile = fs18.appendFile;
1048
+ var fs$appendFile = fs20.appendFile;
1049
1049
  if (fs$appendFile)
1050
- fs18.appendFile = appendFile;
1051
- function appendFile(path25, data, options, cb) {
1050
+ fs20.appendFile = appendFile;
1051
+ function appendFile(path26, data, options, cb) {
1052
1052
  if (typeof options === "function")
1053
1053
  cb = options, options = null;
1054
- return go$appendFile(path25, data, options, cb);
1055
- function go$appendFile(path26, data2, options2, cb2, startTime) {
1056
- return fs$appendFile(path26, data2, options2, function(err) {
1054
+ return go$appendFile(path26, data, options, cb);
1055
+ function go$appendFile(path27, data2, options2, cb2, startTime) {
1056
+ return fs$appendFile(path27, data2, options2, function(err) {
1057
1057
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
1058
- enqueue([go$appendFile, [path26, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
1058
+ enqueue([go$appendFile, [path27, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
1059
1059
  else {
1060
1060
  if (typeof cb2 === "function")
1061
1061
  cb2.apply(this, arguments);
@@ -1063,9 +1063,9 @@ var require_graceful_fs = __commonJS({
1063
1063
  });
1064
1064
  }
1065
1065
  }
1066
- var fs$copyFile = fs18.copyFile;
1066
+ var fs$copyFile = fs20.copyFile;
1067
1067
  if (fs$copyFile)
1068
- fs18.copyFile = copyFile;
1068
+ fs20.copyFile = copyFile;
1069
1069
  function copyFile(src, dest, flags, cb) {
1070
1070
  if (typeof flags === "function") {
1071
1071
  cb = flags;
@@ -1083,34 +1083,34 @@ var require_graceful_fs = __commonJS({
1083
1083
  });
1084
1084
  }
1085
1085
  }
1086
- var fs$readdir = fs18.readdir;
1087
- fs18.readdir = readdir;
1086
+ var fs$readdir = fs20.readdir;
1087
+ fs20.readdir = readdir;
1088
1088
  var noReaddirOptionVersions = /^v[0-5]\./;
1089
- function readdir(path25, options, cb) {
1089
+ function readdir(path26, options, cb) {
1090
1090
  if (typeof options === "function")
1091
1091
  cb = options, options = null;
1092
- var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path26, options2, cb2, startTime) {
1093
- return fs$readdir(path26, fs$readdirCallback(
1094
- path26,
1092
+ var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path27, options2, cb2, startTime) {
1093
+ return fs$readdir(path27, fs$readdirCallback(
1094
+ path27,
1095
1095
  options2,
1096
1096
  cb2,
1097
1097
  startTime
1098
1098
  ));
1099
- } : function go$readdir2(path26, options2, cb2, startTime) {
1100
- return fs$readdir(path26, options2, fs$readdirCallback(
1101
- path26,
1099
+ } : function go$readdir2(path27, options2, cb2, startTime) {
1100
+ return fs$readdir(path27, options2, fs$readdirCallback(
1101
+ path27,
1102
1102
  options2,
1103
1103
  cb2,
1104
1104
  startTime
1105
1105
  ));
1106
1106
  };
1107
- return go$readdir(path25, options, cb);
1108
- function fs$readdirCallback(path26, options2, cb2, startTime) {
1107
+ return go$readdir(path26, options, cb);
1108
+ function fs$readdirCallback(path27, options2, cb2, startTime) {
1109
1109
  return function(err, files) {
1110
1110
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
1111
1111
  enqueue([
1112
1112
  go$readdir,
1113
- [path26, options2, cb2],
1113
+ [path27, options2, cb2],
1114
1114
  err,
1115
1115
  startTime || Date.now(),
1116
1116
  Date.now()
@@ -1125,21 +1125,21 @@ var require_graceful_fs = __commonJS({
1125
1125
  }
1126
1126
  }
1127
1127
  if (process.version.substr(0, 4) === "v0.8") {
1128
- var legStreams = legacy(fs18);
1128
+ var legStreams = legacy(fs20);
1129
1129
  ReadStream = legStreams.ReadStream;
1130
1130
  WriteStream = legStreams.WriteStream;
1131
1131
  }
1132
- var fs$ReadStream = fs18.ReadStream;
1132
+ var fs$ReadStream = fs20.ReadStream;
1133
1133
  if (fs$ReadStream) {
1134
1134
  ReadStream.prototype = Object.create(fs$ReadStream.prototype);
1135
1135
  ReadStream.prototype.open = ReadStream$open;
1136
1136
  }
1137
- var fs$WriteStream = fs18.WriteStream;
1137
+ var fs$WriteStream = fs20.WriteStream;
1138
1138
  if (fs$WriteStream) {
1139
1139
  WriteStream.prototype = Object.create(fs$WriteStream.prototype);
1140
1140
  WriteStream.prototype.open = WriteStream$open;
1141
1141
  }
1142
- Object.defineProperty(fs18, "ReadStream", {
1142
+ Object.defineProperty(fs20, "ReadStream", {
1143
1143
  get: function() {
1144
1144
  return ReadStream;
1145
1145
  },
@@ -1149,7 +1149,7 @@ var require_graceful_fs = __commonJS({
1149
1149
  enumerable: true,
1150
1150
  configurable: true
1151
1151
  });
1152
- Object.defineProperty(fs18, "WriteStream", {
1152
+ Object.defineProperty(fs20, "WriteStream", {
1153
1153
  get: function() {
1154
1154
  return WriteStream;
1155
1155
  },
@@ -1160,7 +1160,7 @@ var require_graceful_fs = __commonJS({
1160
1160
  configurable: true
1161
1161
  });
1162
1162
  var FileReadStream = ReadStream;
1163
- Object.defineProperty(fs18, "FileReadStream", {
1163
+ Object.defineProperty(fs20, "FileReadStream", {
1164
1164
  get: function() {
1165
1165
  return FileReadStream;
1166
1166
  },
@@ -1171,7 +1171,7 @@ var require_graceful_fs = __commonJS({
1171
1171
  configurable: true
1172
1172
  });
1173
1173
  var FileWriteStream = WriteStream;
1174
- Object.defineProperty(fs18, "FileWriteStream", {
1174
+ Object.defineProperty(fs20, "FileWriteStream", {
1175
1175
  get: function() {
1176
1176
  return FileWriteStream;
1177
1177
  },
@@ -1181,7 +1181,7 @@ var require_graceful_fs = __commonJS({
1181
1181
  enumerable: true,
1182
1182
  configurable: true
1183
1183
  });
1184
- function ReadStream(path25, options) {
1184
+ function ReadStream(path26, options) {
1185
1185
  if (this instanceof ReadStream)
1186
1186
  return fs$ReadStream.apply(this, arguments), this;
1187
1187
  else
@@ -1201,7 +1201,7 @@ var require_graceful_fs = __commonJS({
1201
1201
  }
1202
1202
  });
1203
1203
  }
1204
- function WriteStream(path25, options) {
1204
+ function WriteStream(path26, options) {
1205
1205
  if (this instanceof WriteStream)
1206
1206
  return fs$WriteStream.apply(this, arguments), this;
1207
1207
  else
@@ -1219,22 +1219,22 @@ var require_graceful_fs = __commonJS({
1219
1219
  }
1220
1220
  });
1221
1221
  }
1222
- function createReadStream(path25, options) {
1223
- return new fs18.ReadStream(path25, options);
1222
+ function createReadStream(path26, options) {
1223
+ return new fs20.ReadStream(path26, options);
1224
1224
  }
1225
- function createWriteStream(path25, options) {
1226
- return new fs18.WriteStream(path25, options);
1225
+ function createWriteStream(path26, options) {
1226
+ return new fs20.WriteStream(path26, options);
1227
1227
  }
1228
- var fs$open = fs18.open;
1229
- fs18.open = open;
1230
- function open(path25, flags, mode, cb) {
1228
+ var fs$open = fs20.open;
1229
+ fs20.open = open;
1230
+ function open(path26, flags, mode, cb) {
1231
1231
  if (typeof mode === "function")
1232
1232
  cb = mode, mode = null;
1233
- return go$open(path25, flags, mode, cb);
1234
- function go$open(path26, flags2, mode2, cb2, startTime) {
1235
- return fs$open(path26, flags2, mode2, function(err, fd) {
1233
+ return go$open(path26, flags, mode, cb);
1234
+ function go$open(path27, flags2, mode2, cb2, startTime) {
1235
+ return fs$open(path27, flags2, mode2, function(err, fd) {
1236
1236
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
1237
- enqueue([go$open, [path26, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
1237
+ enqueue([go$open, [path27, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
1238
1238
  else {
1239
1239
  if (typeof cb2 === "function")
1240
1240
  cb2.apply(this, arguments);
@@ -1242,20 +1242,20 @@ var require_graceful_fs = __commonJS({
1242
1242
  });
1243
1243
  }
1244
1244
  }
1245
- return fs18;
1245
+ return fs20;
1246
1246
  }
1247
1247
  function enqueue(elem) {
1248
1248
  debug("ENQUEUE", elem[0].name, elem[1]);
1249
- fs17[gracefulQueue].push(elem);
1249
+ fs19[gracefulQueue].push(elem);
1250
1250
  retry();
1251
1251
  }
1252
1252
  var retryTimer;
1253
1253
  function resetQueue() {
1254
1254
  var now = Date.now();
1255
- for (var i = 0; i < fs17[gracefulQueue].length; ++i) {
1256
- if (fs17[gracefulQueue][i].length > 2) {
1257
- fs17[gracefulQueue][i][3] = now;
1258
- fs17[gracefulQueue][i][4] = now;
1255
+ for (var i = 0; i < fs19[gracefulQueue].length; ++i) {
1256
+ if (fs19[gracefulQueue][i].length > 2) {
1257
+ fs19[gracefulQueue][i][3] = now;
1258
+ fs19[gracefulQueue][i][4] = now;
1259
1259
  }
1260
1260
  }
1261
1261
  retry();
@@ -1263,9 +1263,9 @@ var require_graceful_fs = __commonJS({
1263
1263
  function retry() {
1264
1264
  clearTimeout(retryTimer);
1265
1265
  retryTimer = void 0;
1266
- if (fs17[gracefulQueue].length === 0)
1266
+ if (fs19[gracefulQueue].length === 0)
1267
1267
  return;
1268
- var elem = fs17[gracefulQueue].shift();
1268
+ var elem = fs19[gracefulQueue].shift();
1269
1269
  var fn = elem[0];
1270
1270
  var args = elem[1];
1271
1271
  var err = elem[2];
@@ -1287,7 +1287,7 @@ var require_graceful_fs = __commonJS({
1287
1287
  debug("RETRY", fn.name, args);
1288
1288
  fn.apply(null, args.concat([startTime]));
1289
1289
  } else {
1290
- fs17[gracefulQueue].push(elem);
1290
+ fs19[gracefulQueue].push(elem);
1291
1291
  }
1292
1292
  }
1293
1293
  if (retryTimer === void 0) {
@@ -1722,10 +1722,10 @@ var require_mtime_precision = __commonJS({
1722
1722
  "../../node_modules/proper-lockfile/lib/mtime-precision.js"(exports2, module2) {
1723
1723
  "use strict";
1724
1724
  var cacheSymbol = /* @__PURE__ */ Symbol();
1725
- function probe(file, fs17, callback) {
1726
- const cachedPrecision = fs17[cacheSymbol];
1725
+ function probe(file, fs19, callback) {
1726
+ const cachedPrecision = fs19[cacheSymbol];
1727
1727
  if (cachedPrecision) {
1728
- return fs17.stat(file, (err, stat) => {
1728
+ return fs19.stat(file, (err, stat) => {
1729
1729
  if (err) {
1730
1730
  return callback(err);
1731
1731
  }
@@ -1733,16 +1733,16 @@ var require_mtime_precision = __commonJS({
1733
1733
  });
1734
1734
  }
1735
1735
  const mtime = new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
1736
- fs17.utimes(file, mtime, mtime, (err) => {
1736
+ fs19.utimes(file, mtime, mtime, (err) => {
1737
1737
  if (err) {
1738
1738
  return callback(err);
1739
1739
  }
1740
- fs17.stat(file, (err2, stat) => {
1740
+ fs19.stat(file, (err2, stat) => {
1741
1741
  if (err2) {
1742
1742
  return callback(err2);
1743
1743
  }
1744
1744
  const precision = stat.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
1745
- Object.defineProperty(fs17, cacheSymbol, { value: precision });
1745
+ Object.defineProperty(fs19, cacheSymbol, { value: precision });
1746
1746
  callback(null, stat.mtime, precision);
1747
1747
  });
1748
1748
  });
@@ -1763,8 +1763,8 @@ var require_mtime_precision = __commonJS({
1763
1763
  var require_lockfile = __commonJS({
1764
1764
  "../../node_modules/proper-lockfile/lib/lockfile.js"(exports2, module2) {
1765
1765
  "use strict";
1766
- var path25 = require("path");
1767
- var fs17 = require_graceful_fs();
1766
+ var path26 = require("path");
1767
+ var fs19 = require_graceful_fs();
1768
1768
  var retry = require_retry2();
1769
1769
  var onExit = require_signal_exit();
1770
1770
  var mtimePrecision = require_mtime_precision();
@@ -1774,7 +1774,7 @@ var require_lockfile = __commonJS({
1774
1774
  }
1775
1775
  function resolveCanonicalPath(file, options, callback) {
1776
1776
  if (!options.realpath) {
1777
- return callback(null, path25.resolve(file));
1777
+ return callback(null, path26.resolve(file));
1778
1778
  }
1779
1779
  options.fs.realpath(file, callback);
1780
1780
  }
@@ -1895,7 +1895,7 @@ var require_lockfile = __commonJS({
1895
1895
  update: null,
1896
1896
  realpath: true,
1897
1897
  retries: 0,
1898
- fs: fs17,
1898
+ fs: fs19,
1899
1899
  onCompromised: (err) => {
1900
1900
  throw err;
1901
1901
  },
@@ -1939,7 +1939,7 @@ var require_lockfile = __commonJS({
1939
1939
  }
1940
1940
  function unlock(file, options, callback) {
1941
1941
  options = {
1942
- fs: fs17,
1942
+ fs: fs19,
1943
1943
  realpath: true,
1944
1944
  ...options
1945
1945
  };
@@ -1961,7 +1961,7 @@ var require_lockfile = __commonJS({
1961
1961
  options = {
1962
1962
  stale: 1e4,
1963
1963
  realpath: true,
1964
- fs: fs17,
1964
+ fs: fs19,
1965
1965
  ...options
1966
1966
  };
1967
1967
  options.stale = Math.max(options.stale || 0, 2e3);
@@ -2000,16 +2000,16 @@ var require_lockfile = __commonJS({
2000
2000
  var require_adapter = __commonJS({
2001
2001
  "../../node_modules/proper-lockfile/lib/adapter.js"(exports2, module2) {
2002
2002
  "use strict";
2003
- var fs17 = require_graceful_fs();
2004
- function createSyncFs(fs18) {
2003
+ var fs19 = require_graceful_fs();
2004
+ function createSyncFs(fs20) {
2005
2005
  const methods = ["mkdir", "realpath", "stat", "rmdir", "utimes"];
2006
- const newFs = { ...fs18 };
2006
+ const newFs = { ...fs20 };
2007
2007
  methods.forEach((method) => {
2008
2008
  newFs[method] = (...args) => {
2009
2009
  const callback = args.pop();
2010
2010
  let ret;
2011
2011
  try {
2012
- ret = fs18[`${method}Sync`](...args);
2012
+ ret = fs20[`${method}Sync`](...args);
2013
2013
  } catch (err) {
2014
2014
  return callback(err);
2015
2015
  }
@@ -2047,7 +2047,7 @@ var require_adapter = __commonJS({
2047
2047
  }
2048
2048
  function toSyncOptions(options) {
2049
2049
  options = { ...options };
2050
- options.fs = createSyncFs(options.fs || fs17);
2050
+ options.fs = createSyncFs(options.fs || fs19);
2051
2051
  if (typeof options.retries === "number" && options.retries > 0 || options.retries && typeof options.retries.retries === "number" && options.retries.retries > 0) {
2052
2052
  throw Object.assign(new Error("Cannot use retries with the sync api"), { code: "ESYNC" });
2053
2053
  }
@@ -2131,12 +2131,16 @@ var require_age_encryption = __commonJS({
2131
2131
  });
2132
2132
  module2.exports = __toCommonJS2(stdin_exports);
2133
2133
  function isBytes(a) {
2134
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
2134
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
2135
2135
  }
2136
2136
  function anumber(n, title = "") {
2137
+ if (typeof n !== "number") {
2138
+ const prefix2 = title && `"${title}" `;
2139
+ throw new TypeError(`${prefix2}expected number, got ${typeof n}`);
2140
+ }
2137
2141
  if (!Number.isSafeInteger(n) || n < 0) {
2138
2142
  const prefix2 = title && `"${title}" `;
2139
- throw new Error(`${prefix2}expected integer >= 0, got ${n}`);
2143
+ throw new RangeError(`${prefix2}expected integer >= 0, got ${n}`);
2140
2144
  }
2141
2145
  }
2142
2146
  function abytes(value, length, title = "") {
@@ -2147,15 +2151,22 @@ var require_age_encryption = __commonJS({
2147
2151
  const prefix2 = title && `"${title}" `;
2148
2152
  const ofLen = needsLen ? ` of length ${length}` : "";
2149
2153
  const got = bytes ? `length=${len}` : `type=${typeof value}`;
2150
- throw new Error(prefix2 + "expected Uint8Array" + ofLen + ", got " + got);
2154
+ const message = prefix2 + "expected Uint8Array" + ofLen + ", got " + got;
2155
+ if (!bytes)
2156
+ throw new TypeError(message);
2157
+ throw new RangeError(message);
2151
2158
  }
2152
2159
  return value;
2153
2160
  }
2154
2161
  function ahash(h) {
2155
2162
  if (typeof h !== "function" || typeof h.create !== "function")
2156
- throw new Error("Hash must wrapped by utils.createHasher");
2163
+ throw new TypeError("Hash must wrapped by utils.createHasher");
2157
2164
  anumber(h.outputLen);
2158
2165
  anumber(h.blockLen);
2166
+ if (h.outputLen < 1)
2167
+ throw new Error('"outputLen" must be >= 1');
2168
+ if (h.blockLen < 1)
2169
+ throw new Error('"blockLen" must be >= 1');
2159
2170
  }
2160
2171
  function aexists(instance, checkFinished = true) {
2161
2172
  if (instance.destroyed)
@@ -2167,7 +2178,7 @@ var require_age_encryption = __commonJS({
2167
2178
  abytes(out, void 0, "digestInto() output");
2168
2179
  const min = instance.outputLen;
2169
2180
  if (out.length < min) {
2170
- throw new Error('"digestInto() output" expected to be of length >=' + min);
2181
+ throw new RangeError('"digestInto() output" expected to be of length >=' + min);
2171
2182
  }
2172
2183
  }
2173
2184
  function u32(arr) {
@@ -2200,7 +2211,7 @@ var require_age_encryption = __commonJS({
2200
2211
  var swap32IfBE = isLE ? (u) => u : byteSwap32;
2201
2212
  function utf8ToBytes(str) {
2202
2213
  if (typeof str !== "string")
2203
- throw new Error("string expected");
2214
+ throw new TypeError("string expected");
2204
2215
  return new Uint8Array(new TextEncoder().encode(str));
2205
2216
  }
2206
2217
  function kdfInputToBytes(data, errorTitle = "") {
@@ -2210,7 +2221,7 @@ var require_age_encryption = __commonJS({
2210
2221
  }
2211
2222
  function checkOpts(defaults, opts2) {
2212
2223
  if (opts2 !== void 0 && {}.toString.call(opts2) !== "[object Object]")
2213
- throw new Error("options must be object or undefined");
2224
+ throw new TypeError("options must be object or undefined");
2214
2225
  const merged = Object.assign(defaults, opts2);
2215
2226
  return merged;
2216
2227
  }
@@ -2219,17 +2230,23 @@ var require_age_encryption = __commonJS({
2219
2230
  const tmp = hashCons(void 0);
2220
2231
  hashC.outputLen = tmp.outputLen;
2221
2232
  hashC.blockLen = tmp.blockLen;
2233
+ hashC.canXOF = tmp.canXOF;
2222
2234
  hashC.create = (opts2) => hashCons(opts2);
2223
2235
  Object.assign(hashC, info);
2224
2236
  return Object.freeze(hashC);
2225
2237
  }
2226
2238
  function randomBytes4(bytesLength = 32) {
2239
+ anumber(bytesLength, "bytesLength");
2227
2240
  const cr = typeof globalThis === "object" ? globalThis.crypto : null;
2228
2241
  if (typeof cr?.getRandomValues !== "function")
2229
2242
  throw new Error("crypto.getRandomValues must be defined");
2243
+ if (bytesLength > 65536)
2244
+ throw new RangeError(`"bytesLength" expected <= 65536, got ${bytesLength}`);
2230
2245
  return cr.getRandomValues(new Uint8Array(bytesLength));
2231
2246
  }
2232
2247
  var oidNist = (suffix) => ({
2248
+ // Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
2249
+ // Larger suffix values would need base-128 OID encoding and a different length byte.
2233
2250
  oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
2234
2251
  });
2235
2252
  var _HMAC = class {
@@ -2237,6 +2254,7 @@ var require_age_encryption = __commonJS({
2237
2254
  iHash;
2238
2255
  blockLen;
2239
2256
  outputLen;
2257
+ canXOF = false;
2240
2258
  finished = false;
2241
2259
  destroyed = false;
2242
2260
  constructor(hash, key) {
@@ -2266,11 +2284,12 @@ var require_age_encryption = __commonJS({
2266
2284
  }
2267
2285
  digestInto(out) {
2268
2286
  aexists(this);
2269
- abytes(out, this.outputLen, "output");
2287
+ aoutput(out, this);
2270
2288
  this.finished = true;
2271
- this.iHash.digestInto(out);
2272
- this.oHash.update(out);
2273
- this.oHash.digestInto(out);
2289
+ const buf = out.subarray(0, this.outputLen);
2290
+ this.iHash.digestInto(buf);
2291
+ this.oHash.update(buf);
2292
+ this.oHash.digestInto(buf);
2274
2293
  this.destroy();
2275
2294
  }
2276
2295
  digest() {
@@ -2299,8 +2318,11 @@ var require_age_encryption = __commonJS({
2299
2318
  this.iHash.destroy();
2300
2319
  }
2301
2320
  };
2302
- var hmac = (hash, key, message) => new _HMAC(hash, key).update(message).digest();
2303
- hmac.create = (hash, key) => new _HMAC(hash, key);
2321
+ var hmac = /* @__PURE__ */ (() => {
2322
+ const hmac_ = ((hash, key, message) => new _HMAC(hash, key).update(message).digest());
2323
+ hmac_.create = (hash, key) => new _HMAC(hash, key);
2324
+ return hmac_;
2325
+ })();
2304
2326
  function extract(hash, ikm, salt) {
2305
2327
  ahash(hash);
2306
2328
  if (salt === void 0)
@@ -2312,7 +2334,10 @@ var require_age_encryption = __commonJS({
2312
2334
  function expand(hash, prk, info, length = 32) {
2313
2335
  ahash(hash);
2314
2336
  anumber(length, "length");
2337
+ abytes(prk, void 0, "prk");
2315
2338
  const olen = hash.outputLen;
2339
+ if (prk.length < olen)
2340
+ throw new Error('"prk" must be at least HashLen octets');
2316
2341
  if (length > 255 * olen)
2317
2342
  throw new Error("Length must be <= 255*HashLen");
2318
2343
  const blocks = Math.ceil(length / olen);
@@ -2345,6 +2370,7 @@ var require_age_encryption = __commonJS({
2345
2370
  var HashMD = class {
2346
2371
  blockLen;
2347
2372
  outputLen;
2373
+ canXOF = false;
2348
2374
  padOffset;
2349
2375
  isLE;
2350
2376
  // For partial updates less than block size
@@ -2572,6 +2598,7 @@ var require_age_encryption = __commonJS({
2572
2598
  clean(SHA256_W);
2573
2599
  }
2574
2600
  destroy() {
2601
+ this.destroyed = true;
2575
2602
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
2576
2603
  clean(this.buffer);
2577
2604
  }
@@ -2675,7 +2702,7 @@ var require_age_encryption = __commonJS({
2675
2702
  };
2676
2703
  }
2677
2704
  // @__NO_SIDE_EFFECTS__
2678
- function join18(separator = "") {
2705
+ function join19(separator = "") {
2679
2706
  astr("join", separator);
2680
2707
  return {
2681
2708
  encode: (from) => {
@@ -2805,9 +2832,9 @@ var require_age_encryption = __commonJS({
2805
2832
  decode(s) {
2806
2833
  return decodeBase64Builtin(s, false);
2807
2834
  }
2808
- } : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding(6), /* @__PURE__ */ join18(""));
2809
- var base64nopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ join18(""));
2810
- var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join18(""));
2835
+ } : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding(6), /* @__PURE__ */ join19(""));
2836
+ var base64nopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ join19(""));
2837
+ var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join19(""));
2811
2838
  var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
2812
2839
  function bech32Polymod(pre) {
2813
2840
  const b = pre >> 25;
@@ -2909,6 +2936,10 @@ var require_age_encryption = __commonJS({
2909
2936
  anumber(asyncTick, "asyncTick");
2910
2937
  if (c < 1)
2911
2938
  throw new Error("iterations (c) must be >= 1");
2939
+ if (dkLen < 1)
2940
+ throw new Error('"dkLen" must be >= 1');
2941
+ if (dkLen > (2 ** 32 - 1) * hash.outputLen)
2942
+ throw new Error("derived key too long");
2912
2943
  const password = kdfInputToBytes(_password, "password");
2913
2944
  const salt = kdfInputToBytes(_salt, "salt");
2914
2945
  const DK = new Uint8Array(dkLen);
@@ -3040,9 +3071,9 @@ var require_age_encryption = __commonJS({
3040
3071
  throw new Error('"p" expected integer 1..((2^32 - 1) * 32) / (128 * r)');
3041
3072
  if (dkLen < 1 || dkLen > (pow32 - 1) * 32)
3042
3073
  throw new Error('"dkLen" expected integer 1..(2^32 - 1) * 32');
3043
- const memUsed = blockSize * (N2 + p);
3074
+ const memUsed = blockSize * (N2 + p + 1);
3044
3075
  if (memUsed > maxmem)
3045
- throw new Error('"maxmem" limit was hit, expected 128*r*(N+p) <= "maxmem"=' + maxmem);
3076
+ throw new Error('"maxmem" limit was hit: memUsed(128*r*(N+p+1))=' + memUsed + ", maxmem=" + maxmem);
3046
3077
  const B = pbkdf2(sha256, password, salt, { c: 1, dkLen: blockSize * p });
3047
3078
  const B32 = u32(B);
3048
3079
  const V = u32(new Uint8Array(blockSize * N2));
@@ -8984,12 +9015,15 @@ __export(index_exports, {
8984
9015
  BackendMigrator: () => BackendMigrator,
8985
9016
  BulkOps: () => BulkOps,
8986
9017
  CLEF_MANIFEST_FILENAME: () => CLEF_MANIFEST_FILENAME,
9018
+ CLEF_POLICY_FILENAME: () => CLEF_POLICY_FILENAME,
8987
9019
  CLEF_REPORT_SCHEMA_VERSION: () => CLEF_REPORT_SCHEMA_VERSION,
8988
9020
  CLEF_SUPPORTED_EXTENSIONS: () => CLEF_SUPPORTED_EXTENSIONS,
8989
9021
  ClefError: () => ClefError,
8990
9022
  CloudApiError: () => CloudApiError,
8991
9023
  CloudClient: () => CloudClient,
9024
+ ComplianceGenerator: () => ComplianceGenerator,
8992
9025
  ConsumptionClient: () => ConsumptionClient,
9026
+ DEFAULT_POLICY: () => DEFAULT_POLICY,
8993
9027
  DiffEngine: () => DiffEngine,
8994
9028
  DriftDetector: () => DriftDetector,
8995
9029
  FilePackOutput: () => FilePackOutput,
@@ -9001,6 +9035,9 @@ __export(index_exports, {
9001
9035
  ManifestValidationError: () => ManifestValidationError,
9002
9036
  MatrixManager: () => MatrixManager,
9003
9037
  MemoryPackOutput: () => MemoryPackOutput,
9038
+ PolicyEvaluator: () => PolicyEvaluator,
9039
+ PolicyParser: () => PolicyParser,
9040
+ PolicyValidationError: () => PolicyValidationError,
9004
9041
  REQUESTS_FILENAME: () => REQUESTS_FILENAME,
9005
9042
  REQUIREMENTS: () => REQUIREMENTS,
9006
9043
  RecipientManager: () => RecipientManager,
@@ -9041,6 +9078,7 @@ __export(index_exports, {
9041
9078
  generateRandomValue: () => generateRandomValue,
9042
9079
  generateSigningKeyPair: () => generateSigningKeyPair,
9043
9080
  getPendingKeys: () => getPendingKeys,
9081
+ getRotations: () => getRotations,
9044
9082
  isHighEntropy: () => isHighEntropy,
9045
9083
  isKmsEnvelope: () => isKmsEnvelope,
9046
9084
  isPending: () => isPending,
@@ -9052,6 +9090,8 @@ __export(index_exports, {
9052
9090
  markPendingWithRetry: () => markPendingWithRetry,
9053
9091
  markResolved: () => markResolved,
9054
9092
  matchPatterns: () => matchPatterns,
9093
+ mergeMetadataContents: () => mergeMetadataContents,
9094
+ mergeMetadataFiles: () => mergeMetadataFiles,
9055
9095
  metadataPath: () => metadataPath,
9056
9096
  parse: () => parse9,
9057
9097
  parseDotenv: () => parseDotenv,
@@ -9059,14 +9099,17 @@ __export(index_exports, {
9059
9099
  parseJson: () => parseJson,
9060
9100
  parseYaml: () => parseYaml,
9061
9101
  readManifestYaml: () => readManifestYaml,
9102
+ recordRotation: () => recordRotation,
9062
9103
  redactValue: () => redactValue,
9063
9104
  removeAccessRequest: () => removeRequest,
9105
+ removeRotation: () => removeRotation,
9064
9106
  requestsFilePath: () => requestsFilePath,
9065
9107
  resetSopsResolution: () => resetSopsResolution,
9066
9108
  resolveBackendConfig: () => resolveBackendConfig,
9067
9109
  resolveIdentitySecrets: () => resolveIdentitySecrets,
9068
9110
  resolveRecipientsForEnvironment: () => resolveRecipientsForEnvironment,
9069
9111
  resolveSopsPath: () => resolveSopsPath,
9112
+ runCompliance: () => runCompliance,
9070
9113
  saveMetadata: () => saveMetadata,
9071
9114
  saveRequests: () => saveRequests,
9072
9115
  shannonEntropy: () => shannonEntropy,
@@ -9147,6 +9190,13 @@ var GitOperationError = class extends ClefError {
9147
9190
  this.name = "GitOperationError";
9148
9191
  }
9149
9192
  };
9193
+ var PolicyValidationError = class extends ClefError {
9194
+ constructor(message, field) {
9195
+ super(message, field ? `Check the '${field}' field in .clef/policy.yaml` : void 0);
9196
+ this.field = field;
9197
+ this.name = "PolicyValidationError";
9198
+ }
9199
+ };
9150
9200
  var SchemaLoadError = class extends ClefError {
9151
9201
  constructor(message, filePath) {
9152
9202
  super(
@@ -9821,6 +9871,20 @@ var PATTERNS = [
9821
9871
  },
9822
9872
  { name: "Database URL", regex: /(?:postgres|mysql|mongodb|redis):\/\/[^:]+:[^@]+@/ }
9823
9873
  ];
9874
+ var PUBLIC_PREFIX_PATTERNS = [
9875
+ // reCAPTCHA v2, v3, and Enterprise site keys are exactly 40 chars and
9876
+ // begin with 6L[c-f]. Site keys are designed to be embedded in HTML.
9877
+ // https://developers.google.com/recaptcha/docs/faq
9878
+ { name: "reCAPTCHA site key", regex: /^6L[c-f][0-9A-Za-z_-]{37}$/ },
9879
+ // Stripe publishable keys (client-side, distinct from sk_live_/sk_test_).
9880
+ { name: "Stripe publishable key", regex: /^pk_(?:live|test)_[0-9a-zA-Z]{24,}$/ }
9881
+ ];
9882
+ function matchPublicPrefix(value) {
9883
+ for (const def of PUBLIC_PREFIX_PATTERNS) {
9884
+ if (def.regex.test(value)) return { name: def.name };
9885
+ }
9886
+ return null;
9887
+ }
9824
9888
  function shannonEntropy(str) {
9825
9889
  if (str.length === 0) return 0;
9826
9890
  const freq = /* @__PURE__ */ new Map();
@@ -10009,7 +10073,8 @@ var ScanRunner = class {
10009
10073
  }
10010
10074
  }
10011
10075
  if (options.severity !== "high") {
10012
- const entropyHit = this.detectEntropy(line, lineNum, relPath);
10076
+ const allowPublic = options.publicAllowlist !== false;
10077
+ const entropyHit = this.detectEntropy(line, lineNum, relPath, allowPublic);
10013
10078
  if (entropyHit && !shouldIgnoreMatch(entropyHit, ignoreRules)) {
10014
10079
  matches.push(entropyHit);
10015
10080
  }
@@ -10050,13 +10115,14 @@ var ScanRunner = class {
10050
10115
  return false;
10051
10116
  }
10052
10117
  }
10053
- detectEntropy(line, lineNum, filePath) {
10118
+ detectEntropy(line, lineNum, filePath, allowPublic) {
10054
10119
  const valuePattern = /(?:=|:\s*)["']?([A-Za-z0-9+/=_-]{20,})["']?/;
10055
10120
  const match = valuePattern.exec(line);
10056
10121
  if (!match) return null;
10057
10122
  const value = match[1];
10058
10123
  const entropy = shannonEntropy(value);
10059
10124
  if (!isHighEntropy(value)) return null;
10125
+ if (allowPublic && matchPublicPrefix(value)) return null;
10060
10126
  const varMatch = /(\w+)\s*(?:=|:)/.exec(line);
10061
10127
  const varName = varMatch ? varMatch[1] : "";
10062
10128
  const preview = varName ? `${varName}=\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022` : redactValue(value);
@@ -10138,41 +10204,50 @@ function metadataPath(encryptedFilePath) {
10138
10204
  return path4.join(dir, `${base}.clef-meta.yaml`);
10139
10205
  }
10140
10206
  var HEADER_COMMENT = "# Managed by Clef. Do not edit manually.\n";
10207
+ function emptyMetadata() {
10208
+ return { version: 1, pending: [], rotations: [] };
10209
+ }
10141
10210
  async function loadMetadata(filePath) {
10142
10211
  const metaPath = metadataPath(filePath);
10143
10212
  try {
10144
- if (!fs5.existsSync(metaPath)) {
10145
- return { version: 1, pending: [] };
10146
- }
10213
+ if (!fs5.existsSync(metaPath)) return emptyMetadata();
10147
10214
  const content = fs5.readFileSync(metaPath, "utf-8");
10148
10215
  const parsed = YAML3.parse(content);
10149
- if (!parsed || !Array.isArray(parsed.pending)) {
10150
- return { version: 1, pending: [] };
10151
- }
10152
- return {
10153
- version: 1,
10154
- pending: parsed.pending.map((p) => ({
10155
- key: p.key,
10156
- since: new Date(p.since),
10157
- setBy: p.setBy
10158
- }))
10159
- };
10216
+ if (!parsed || typeof parsed !== "object") return emptyMetadata();
10217
+ const pendingRaw = Array.isArray(parsed.pending) ? parsed.pending : [];
10218
+ const pending = pendingRaw.filter(
10219
+ (p) => !!p && typeof p === "object" && typeof p.key === "string" && typeof p.since === "string" && typeof p.setBy === "string"
10220
+ ).map((p) => ({ key: p.key, since: new Date(p.since), setBy: p.setBy }));
10221
+ const rotationsRaw = Array.isArray(parsed.rotations) ? parsed.rotations : [];
10222
+ const rotations = rotationsRaw.filter(
10223
+ (r) => !!r && typeof r === "object" && typeof r.key === "string" && typeof r.last_rotated_at === "string" && typeof r.rotated_by === "string" && typeof r.rotation_count === "number"
10224
+ ).map((r) => ({
10225
+ key: r.key,
10226
+ lastRotatedAt: new Date(r.last_rotated_at),
10227
+ rotatedBy: r.rotated_by,
10228
+ rotationCount: r.rotation_count
10229
+ }));
10230
+ return { version: 1, pending, rotations };
10160
10231
  } catch {
10161
- return { version: 1, pending: [] };
10232
+ return emptyMetadata();
10162
10233
  }
10163
10234
  }
10164
10235
  async function saveMetadata(filePath, metadata) {
10165
10236
  const metaPath = metadataPath(filePath);
10166
10237
  const dir = path4.dirname(metaPath);
10167
- if (!fs5.existsSync(dir)) {
10168
- fs5.mkdirSync(dir, { recursive: true });
10169
- }
10238
+ if (!fs5.existsSync(dir)) fs5.mkdirSync(dir, { recursive: true });
10170
10239
  const data = {
10171
10240
  version: metadata.version,
10172
10241
  pending: metadata.pending.map((p) => ({
10173
10242
  key: p.key,
10174
10243
  since: p.since.toISOString(),
10175
10244
  setBy: p.setBy
10245
+ })),
10246
+ rotations: metadata.rotations.map((r) => ({
10247
+ key: r.key,
10248
+ last_rotated_at: r.lastRotatedAt.toISOString(),
10249
+ rotated_by: r.rotatedBy,
10250
+ rotation_count: r.rotationCount
10176
10251
  }))
10177
10252
  };
10178
10253
  fs5.writeFileSync(metaPath, HEADER_COMMENT + YAML3.stringify(data), "utf-8");
@@ -10203,6 +10278,38 @@ async function isPending(filePath, key) {
10203
10278
  const metadata = await loadMetadata(filePath);
10204
10279
  return metadata.pending.some((p) => p.key === key);
10205
10280
  }
10281
+ async function recordRotation(filePath, keys, rotatedBy, now = /* @__PURE__ */ new Date()) {
10282
+ const metadata = await loadMetadata(filePath);
10283
+ for (const key of keys) {
10284
+ const existing = metadata.rotations.findIndex((r) => r.key === key);
10285
+ if (existing >= 0) {
10286
+ metadata.rotations[existing] = {
10287
+ key,
10288
+ lastRotatedAt: now,
10289
+ rotatedBy,
10290
+ rotationCount: metadata.rotations[existing].rotationCount + 1
10291
+ };
10292
+ } else {
10293
+ metadata.rotations.push({
10294
+ key,
10295
+ lastRotatedAt: now,
10296
+ rotatedBy,
10297
+ rotationCount: 1
10298
+ });
10299
+ }
10300
+ }
10301
+ metadata.pending = metadata.pending.filter((p) => !keys.includes(p.key));
10302
+ await saveMetadata(filePath, metadata);
10303
+ }
10304
+ async function removeRotation(filePath, keys) {
10305
+ const metadata = await loadMetadata(filePath);
10306
+ metadata.rotations = metadata.rotations.filter((r) => !keys.includes(r.key));
10307
+ await saveMetadata(filePath, metadata);
10308
+ }
10309
+ async function getRotations(filePath) {
10310
+ const metadata = await loadMetadata(filePath);
10311
+ return metadata.rotations;
10312
+ }
10206
10313
  function generateRandomValue() {
10207
10314
  return crypto2.randomBytes(32).toString("hex");
10208
10315
  }
@@ -11004,61 +11111,83 @@ var GitIntegration = class {
11004
11111
  * @throws {@link GitOperationError} On failure.
11005
11112
  */
11006
11113
  async installMergeDriver(repoRoot) {
11007
- const configResult = await this.runner.run(
11008
- "git",
11009
- ["config", "merge.sops.name", "SOPS-aware merge driver"],
11010
- { cwd: repoRoot }
11011
- );
11012
- if (configResult.exitCode !== 0) {
11013
- throw new GitOperationError(
11014
- `Failed to configure merge driver name: ${configResult.stderr.trim()}`,
11015
- "Ensure you are inside a git repository."
11114
+ const drivers = [
11115
+ { config: "merge.sops", friendly: "SOPS-aware merge driver" },
11116
+ { config: "merge.clef-metadata", friendly: "Clef metadata merge driver" }
11117
+ ];
11118
+ for (const driver of drivers) {
11119
+ const nameResult = await this.runner.run(
11120
+ "git",
11121
+ ["config", `${driver.config}.name`, driver.friendly],
11122
+ { cwd: repoRoot }
11016
11123
  );
11017
- }
11018
- const driverResult = await this.runner.run(
11019
- "git",
11020
- ["config", "merge.sops.driver", "clef merge-driver %O %A %B"],
11021
- { cwd: repoRoot }
11022
- );
11023
- if (driverResult.exitCode !== 0) {
11024
- throw new GitOperationError(
11025
- `Failed to configure merge driver command: ${driverResult.stderr.trim()}`,
11026
- "Ensure you are inside a git repository."
11124
+ if (nameResult.exitCode !== 0) {
11125
+ throw new GitOperationError(
11126
+ `Failed to configure merge driver name: ${nameResult.stderr.trim()}`,
11127
+ "Ensure you are inside a git repository."
11128
+ );
11129
+ }
11130
+ const driverResult = await this.runner.run(
11131
+ "git",
11132
+ ["config", `${driver.config}.driver`, "clef merge-driver %O %A %B"],
11133
+ { cwd: repoRoot }
11027
11134
  );
11135
+ if (driverResult.exitCode !== 0) {
11136
+ throw new GitOperationError(
11137
+ `Failed to configure merge driver command: ${driverResult.stderr.trim()}`,
11138
+ "Ensure you are inside a git repository."
11139
+ );
11140
+ }
11028
11141
  }
11029
11142
  await this.ensureGitattributes(repoRoot);
11030
11143
  }
11031
11144
  /**
11032
- * Check whether the SOPS merge driver is configured in both
11033
- * `.git/config` and `.gitattributes`.
11034
- *
11035
- * @param repoRoot - Absolute path to the repository root.
11036
- * @returns An object indicating which parts are configured.
11145
+ * Check whether both Clef merge drivers are configured in `.git/config`
11146
+ * and `.gitattributes`. Reports separately on the SOPS driver
11147
+ * (`merge=sops` for `.enc.*`) and the metadata driver
11148
+ * (`merge=clef-metadata` for `.clef-meta.yaml`) so `clef doctor` can
11149
+ * prompt the user to run `clef hooks` when only the SOPS driver is
11150
+ * installed (older install, pre-metadata-merge).
11037
11151
  */
11038
11152
  async checkMergeDriver(repoRoot) {
11039
- const configResult = await this.runner.run("git", ["config", "--get", "merge.sops.driver"], {
11153
+ const sopsConfig = await this.runner.run("git", ["config", "--get", "merge.sops.driver"], {
11040
11154
  cwd: repoRoot
11041
11155
  });
11042
- const gitConfig = configResult.exitCode === 0 && configResult.stdout.trim().length > 0;
11156
+ const gitConfig = sopsConfig.exitCode === 0 && sopsConfig.stdout.trim().length > 0;
11157
+ const metaConfig = await this.runner.run(
11158
+ "git",
11159
+ ["config", "--get", "merge.clef-metadata.driver"],
11160
+ { cwd: repoRoot }
11161
+ );
11162
+ const metadataGitConfig = metaConfig.exitCode === 0 && metaConfig.stdout.trim().length > 0;
11043
11163
  const attrFilePath = path8.join(repoRoot, ".gitattributes");
11044
11164
  const attrContent = fs9.existsSync(attrFilePath) ? fs9.readFileSync(attrFilePath, "utf-8") : "";
11045
11165
  const gitattributes = attrContent.includes("merge=sops");
11046
- return { gitConfig, gitattributes };
11166
+ const metadataGitattributes = attrContent.includes("merge=clef-metadata");
11167
+ return { gitConfig, gitattributes, metadataGitConfig, metadataGitattributes };
11047
11168
  }
11048
11169
  async ensureGitattributes(repoRoot) {
11049
11170
  const attrPath = path8.join(repoRoot, ".gitattributes");
11050
- const mergeRule = "*.enc.yaml merge=sops\n*.enc.json merge=sops";
11051
11171
  const existing = fs9.existsSync(attrPath) ? fs9.readFileSync(attrPath, "utf-8") : "";
11052
- if (existing.includes("merge=sops")) {
11053
- return;
11054
- }
11055
- const newContent = existing.trimEnd() ? `${existing.trimEnd()}
11172
+ let newContent = existing;
11173
+ if (!existing.includes("merge=sops")) {
11174
+ const block = `# Clef: SOPS-aware merge driver for encrypted files
11175
+ *.enc.yaml merge=sops
11176
+ *.enc.json merge=sops
11177
+ `;
11178
+ newContent = newContent.trimEnd() ? `${newContent.trimEnd()}
11056
11179
 
11057
- # Clef: SOPS-aware merge driver for encrypted files
11058
- ${mergeRule}
11059
- ` : `# Clef: SOPS-aware merge driver for encrypted files
11060
- ${mergeRule}
11180
+ ${block}` : block;
11181
+ }
11182
+ if (!newContent.includes("merge=clef-metadata")) {
11183
+ const block = `# Clef: rotation-aware merge driver for metadata sidecars
11184
+ *.clef-meta.yaml merge=clef-metadata
11061
11185
  `;
11186
+ newContent = newContent.trimEnd() ? `${newContent.trimEnd()}
11187
+
11188
+ ${block}` : block;
11189
+ }
11190
+ if (newContent === existing) return;
11062
11191
  try {
11063
11192
  fs9.writeFileSync(attrPath, newContent, "utf-8");
11064
11193
  } catch (err) {
@@ -11765,8 +11894,11 @@ var SopsClient = class {
11765
11894
  }
11766
11895
  const backend = this.detectBackend(sops);
11767
11896
  const recipients = this.extractRecipients(sops, backend);
11768
- const lastModified = sops.lastmodified ? new Date(sops.lastmodified) : /* @__PURE__ */ new Date();
11769
- return { backend, recipients, lastModified };
11897
+ const lastModifiedRaw = typeof sops.lastmodified === "string" ? sops.lastmodified : void 0;
11898
+ const lastModified = lastModifiedRaw ? new Date(lastModifiedRaw) : /* @__PURE__ */ new Date();
11899
+ const lastModifiedPresent = lastModifiedRaw !== void 0;
11900
+ const version = typeof sops.version === "string" ? sops.version : void 0;
11901
+ return { backend, recipients, lastModified, lastModifiedPresent, version };
11770
11902
  }
11771
11903
  detectBackend(sops) {
11772
11904
  if (sops.age && Array.isArray(sops.age) && sops.age.length > 0) return "age";
@@ -12052,8 +12184,50 @@ var LintRunner = class {
12052
12184
  );
12053
12185
  issues.push(...siIssues);
12054
12186
  }
12187
+ const metadataIssues = await this.lintMetadataConsistency(existingCells);
12188
+ issues.push(...metadataIssues);
12055
12189
  return { issues, fileCount: fileCount + missingCells.length, pendingCount };
12056
12190
  }
12191
+ /**
12192
+ * Cross-reference `.clef-meta.yaml` against the cipher's plaintext key
12193
+ * names for each existing cell. Reports orphan rotation records and
12194
+ * dual-state (pending + rotation) inconsistencies. Uses
12195
+ * {@link readSopsKeyNames} (plaintext YAML parse) — no decryption.
12196
+ */
12197
+ async lintMetadataConsistency(cells) {
12198
+ const issues = [];
12199
+ for (const cell of cells) {
12200
+ const keysInCipher = readSopsKeyNames(cell.filePath);
12201
+ if (keysInCipher === null) continue;
12202
+ const cipherKeys = new Set(keysInCipher);
12203
+ const metadata = await loadMetadata(cell.filePath);
12204
+ for (const record of metadata.rotations) {
12205
+ if (!cipherKeys.has(record.key)) {
12206
+ issues.push({
12207
+ severity: "warning",
12208
+ category: "metadata",
12209
+ file: cell.filePath,
12210
+ key: record.key,
12211
+ message: `Rotation record exists for key '${record.key}' but the key is not in this cell. Remove the orphan entry from .clef-meta.yaml or re-add the key via clef set.`
12212
+ });
12213
+ }
12214
+ }
12215
+ const pendingKeys = new Set(metadata.pending.map((p) => p.key));
12216
+ for (const record of metadata.rotations) {
12217
+ if (pendingKeys.has(record.key)) {
12218
+ issues.push({
12219
+ severity: "error",
12220
+ category: "metadata",
12221
+ file: cell.filePath,
12222
+ key: record.key,
12223
+ message: `Key '${record.key}' appears in both 'pending' and 'rotations' sections of .clef-meta.yaml. One of them is stale \u2014 likely a manual edit or a failed transaction. Re-run clef set to reconcile.`,
12224
+ fixCommand: `clef set ${cell.namespace}/${cell.environment} ${record.key}`
12225
+ });
12226
+ }
12227
+ }
12228
+ }
12229
+ return issues;
12230
+ }
12057
12231
  /**
12058
12232
  * Lint service identity configurations for drift issues.
12059
12233
  */
@@ -12406,22 +12580,33 @@ var ImportRunner = class {
12406
12580
  }
12407
12581
  const decrypted = await this.sopsClient.decrypt(filePath);
12408
12582
  const newValues = { ...decrypted.values };
12583
+ const rotatedKeys = [];
12409
12584
  for (const [key, value] of candidates) {
12410
- if (key in decrypted.values && !options.overwrite) {
12585
+ const existed = key in decrypted.values;
12586
+ if (existed && !options.overwrite) {
12411
12587
  skipped.push(key);
12412
12588
  continue;
12413
12589
  }
12590
+ const valueChanged = !existed || decrypted.values[key] !== value;
12414
12591
  newValues[key] = value;
12415
12592
  imported.push(key);
12593
+ if (valueChanged) rotatedKeys.push(key);
12416
12594
  }
12417
12595
  if (imported.length === 0) {
12418
12596
  return { imported, skipped, failed, warnings, dryRun: false };
12419
12597
  }
12598
+ const relCellPath = path14.relative(repoRoot, filePath);
12599
+ const relMetaPath = relCellPath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
12420
12600
  await this.tx.run(repoRoot, {
12421
12601
  description: `clef import ${target}: ${imported.length} key(s)`,
12422
- paths: [path14.relative(repoRoot, filePath)],
12602
+ // Include the metadata path so rotation records created in the mutate
12603
+ // callback are staged and rolled back atomically with the ciphertext.
12604
+ paths: [relCellPath, relMetaPath],
12423
12605
  mutate: async () => {
12424
12606
  await this.sopsClient.encrypt(filePath, newValues, manifest, env);
12607
+ if (options.rotatedBy && rotatedKeys.length > 0) {
12608
+ await recordRotation(filePath, rotatedKeys, options.rotatedBy);
12609
+ }
12425
12610
  }
12426
12611
  });
12427
12612
  return { imported, skipped, failed, warnings, dryRun: false };
@@ -13434,6 +13619,116 @@ var SopsMergeDriver = class {
13434
13619
  }
13435
13620
  };
13436
13621
 
13622
+ // src/merge/metadata-driver.ts
13623
+ var fs15 = __toESM(require("fs"));
13624
+ var YAML10 = __toESM(require("yaml"));
13625
+ var HEADER_COMMENT3 = "# Managed by Clef. Do not edit manually.\n";
13626
+ function parseMetadata(content) {
13627
+ try {
13628
+ const parsed = YAML10.parse(content);
13629
+ if (!parsed || typeof parsed !== "object") return emptyMetadata2();
13630
+ const pendingRaw = Array.isArray(parsed.pending) ? parsed.pending : [];
13631
+ const pending = pendingRaw.filter(
13632
+ (p) => !!p && typeof p === "object" && typeof p.key === "string" && typeof p.since === "string" && typeof p.setBy === "string"
13633
+ ).map((p) => ({ key: p.key, since: new Date(p.since), setBy: p.setBy }));
13634
+ const rotationsRaw = Array.isArray(parsed.rotations) ? parsed.rotations : [];
13635
+ const rotations = rotationsRaw.filter(
13636
+ (r) => !!r && typeof r === "object" && typeof r.key === "string" && typeof r.last_rotated_at === "string" && typeof r.rotated_by === "string" && typeof r.rotation_count === "number"
13637
+ ).map((r) => ({
13638
+ key: r.key,
13639
+ lastRotatedAt: new Date(r.last_rotated_at),
13640
+ rotatedBy: r.rotated_by,
13641
+ rotationCount: r.rotation_count
13642
+ }));
13643
+ return { version: 1, pending, rotations };
13644
+ } catch {
13645
+ return emptyMetadata2();
13646
+ }
13647
+ }
13648
+ function emptyMetadata2() {
13649
+ return { version: 1, pending: [], rotations: [] };
13650
+ }
13651
+ function serializeMetadata(m) {
13652
+ const data = {
13653
+ version: m.version,
13654
+ pending: m.pending.map((p) => ({
13655
+ key: p.key,
13656
+ since: p.since.toISOString(),
13657
+ setBy: p.setBy
13658
+ })),
13659
+ rotations: m.rotations.map((r) => ({
13660
+ key: r.key,
13661
+ last_rotated_at: r.lastRotatedAt.toISOString(),
13662
+ rotated_by: r.rotatedBy,
13663
+ rotation_count: r.rotationCount
13664
+ }))
13665
+ };
13666
+ return HEADER_COMMENT3 + YAML10.stringify(data);
13667
+ }
13668
+ function mergeRotations(ours, theirs) {
13669
+ const byKey = /* @__PURE__ */ new Map();
13670
+ const ourByKey = new Map(ours.map((r) => [r.key, r]));
13671
+ const theirByKey = new Map(theirs.map((r) => [r.key, r]));
13672
+ const allKeys = /* @__PURE__ */ new Set([...ourByKey.keys(), ...theirByKey.keys()]);
13673
+ for (const key of allKeys) {
13674
+ const o = ourByKey.get(key);
13675
+ const t = theirByKey.get(key);
13676
+ if (o && t) {
13677
+ const oTime = o.lastRotatedAt.getTime();
13678
+ const tTime = t.lastRotatedAt.getTime();
13679
+ const winner = tTime > oTime ? t : o;
13680
+ byKey.set(key, {
13681
+ key,
13682
+ lastRotatedAt: winner.lastRotatedAt,
13683
+ rotatedBy: winner.rotatedBy,
13684
+ rotationCount: Math.max(o.rotationCount, t.rotationCount) + 1
13685
+ });
13686
+ } else if (o) {
13687
+ byKey.set(key, o);
13688
+ } else if (t) {
13689
+ byKey.set(key, t);
13690
+ }
13691
+ }
13692
+ return Array.from(byKey.values());
13693
+ }
13694
+ function mergePending(oursPending, theirsPending, oursRotations, theirsRotations) {
13695
+ const ourByKey = new Map(oursPending.map((p) => [p.key, p]));
13696
+ const theirByKey = new Map(theirsPending.map((p) => [p.key, p]));
13697
+ const rotatedKeys = /* @__PURE__ */ new Set([
13698
+ ...oursRotations.map((r) => r.key),
13699
+ ...theirsRotations.map((r) => r.key)
13700
+ ]);
13701
+ const allKeys = /* @__PURE__ */ new Set([...ourByKey.keys(), ...theirByKey.keys()]);
13702
+ const out = [];
13703
+ for (const key of allKeys) {
13704
+ if (rotatedKeys.has(key)) continue;
13705
+ const o = ourByKey.get(key);
13706
+ const t = theirByKey.get(key);
13707
+ if (o && t) {
13708
+ const winner = t.since.getTime() > o.since.getTime() ? t : o;
13709
+ out.push({ key, since: winner.since, setBy: winner.setBy });
13710
+ } else if (o) {
13711
+ out.push(o);
13712
+ } else if (t) {
13713
+ out.push(t);
13714
+ }
13715
+ }
13716
+ return out;
13717
+ }
13718
+ function mergeMetadataContents(oursContent, theirsContent) {
13719
+ const ours = parseMetadata(oursContent);
13720
+ const theirs = parseMetadata(theirsContent);
13721
+ const rotations = mergeRotations(ours.rotations, theirs.rotations);
13722
+ const pending = mergePending(ours.pending, theirs.pending, ours.rotations, theirs.rotations);
13723
+ return serializeMetadata({ version: 1, pending, rotations });
13724
+ }
13725
+ function mergeMetadataFiles(_basePath, oursPath, theirsPath) {
13726
+ const oursContent = fs15.existsSync(oursPath) ? fs15.readFileSync(oursPath, "utf-8") : "";
13727
+ const theirsContent = fs15.existsSync(theirsPath) ? fs15.readFileSync(theirsPath, "utf-8") : "";
13728
+ const merged = mergeMetadataContents(oursContent, theirsContent);
13729
+ fs15.writeFileSync(oursPath, merged, "utf-8");
13730
+ }
13731
+
13437
13732
  // src/service-identity/manager.ts
13438
13733
  var path19 = __toESM(require("path"));
13439
13734
  var ServiceIdentityManager = class {
@@ -13969,7 +14264,7 @@ var ServiceIdentityManager = class {
13969
14264
  };
13970
14265
 
13971
14266
  // src/structure/manager.ts
13972
- var fs15 = __toESM(require("fs"));
14267
+ var fs16 = __toESM(require("fs"));
13973
14268
  var path20 = __toESM(require("path"));
13974
14269
  var StructureManager = class {
13975
14270
  constructor(matrixManager, encryption, tx) {
@@ -13997,7 +14292,7 @@ var StructureManager = class {
13997
14292
  )
13998
14293
  }));
13999
14294
  for (const cell of newCellPaths) {
14000
- if (fs15.existsSync(cell.filePath)) {
14295
+ if (fs16.existsSync(cell.filePath)) {
14001
14296
  throw new Error(
14002
14297
  `Cannot add namespace '${name}': file '${path20.relative(repoRoot, cell.filePath)}' already exists.`
14003
14298
  );
@@ -14069,7 +14364,7 @@ var StructureManager = class {
14069
14364
  )
14070
14365
  }));
14071
14366
  for (const cell of newCellPaths) {
14072
- if (fs15.existsSync(cell.filePath)) {
14367
+ if (fs16.existsSync(cell.filePath)) {
14073
14368
  throw new Error(
14074
14369
  `Cannot add environment '${name}': file '${path20.relative(repoRoot, cell.filePath)}' already exists.`
14075
14370
  );
@@ -14153,7 +14448,7 @@ var StructureManager = class {
14153
14448
  paths: this.deletePaths(repoRoot, cellsToDelete),
14154
14449
  mutate: async () => {
14155
14450
  for (const cell of cellsToDelete) {
14156
- fs15.unlinkSync(cell.filePath);
14451
+ fs16.unlinkSync(cell.filePath);
14157
14452
  this.unlinkMetaSibling(cell.filePath);
14158
14453
  }
14159
14454
  const doc = readManifestYaml(repoRoot);
@@ -14203,7 +14498,7 @@ var StructureManager = class {
14203
14498
  paths: this.deletePaths(repoRoot, cellsToDelete),
14204
14499
  mutate: async () => {
14205
14500
  for (const cell of cellsToDelete) {
14206
- fs15.unlinkSync(cell.filePath);
14501
+ fs16.unlinkSync(cell.filePath);
14207
14502
  this.unlinkMetaSibling(cell.filePath);
14208
14503
  }
14209
14504
  const doc = readManifestYaml(repoRoot);
@@ -14245,7 +14540,7 @@ var StructureManager = class {
14245
14540
  const renamePairs = isRename ? this.collectRenamePairs(manifest, repoRoot, name, opts.rename, "namespace") : [];
14246
14541
  if (isRename) {
14247
14542
  for (const pair of renamePairs) {
14248
- if (fs15.existsSync(pair.to)) {
14543
+ if (fs16.existsSync(pair.to)) {
14249
14544
  throw new Error(
14250
14545
  `Rename target '${path20.relative(repoRoot, pair.to)}' already exists. Move or remove it first.`
14251
14546
  );
@@ -14288,7 +14583,7 @@ var StructureManager = class {
14288
14583
  const renamePairs = isRename ? this.collectRenamePairs(manifest, repoRoot, name, opts.rename, "environment") : [];
14289
14584
  if (isRename) {
14290
14585
  for (const pair of renamePairs) {
14291
- if (fs15.existsSync(pair.to)) {
14586
+ if (fs16.existsSync(pair.to)) {
14292
14587
  throw new Error(
14293
14588
  `Rename target '${path20.relative(repoRoot, pair.to)}' already exists. Move or remove it first.`
14294
14589
  );
@@ -14325,7 +14620,7 @@ var StructureManager = class {
14325
14620
  const newCellPath = this.swapAxisInCellPath(repoRoot, manifest, cell, axis, newName);
14326
14621
  pairs.push({ from: cell.filePath, to: newCellPath });
14327
14622
  const oldMeta = cell.filePath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
14328
- if (fs15.existsSync(oldMeta)) {
14623
+ if (fs16.existsSync(oldMeta)) {
14329
14624
  const newMeta = newCellPath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
14330
14625
  pairs.push({ from: oldMeta, to: newMeta });
14331
14626
  }
@@ -14365,10 +14660,10 @@ var StructureManager = class {
14365
14660
  applyRenames(pairs) {
14366
14661
  for (const pair of pairs) {
14367
14662
  const targetDir = path20.dirname(pair.to);
14368
- if (!fs15.existsSync(targetDir)) {
14369
- fs15.mkdirSync(targetDir, { recursive: true });
14663
+ if (!fs16.existsSync(targetDir)) {
14664
+ fs16.mkdirSync(targetDir, { recursive: true });
14370
14665
  }
14371
- fs15.renameSync(pair.from, pair.to);
14666
+ fs16.renameSync(pair.from, pair.to);
14372
14667
  }
14373
14668
  }
14374
14669
  /**
@@ -14381,7 +14676,7 @@ var StructureManager = class {
14381
14676
  for (const cell of cells) {
14382
14677
  paths.add(path20.relative(repoRoot, cell.filePath));
14383
14678
  const meta = cell.filePath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
14384
- if (fs15.existsSync(meta)) {
14679
+ if (fs16.existsSync(meta)) {
14385
14680
  paths.add(path20.relative(repoRoot, meta));
14386
14681
  }
14387
14682
  }
@@ -14395,8 +14690,8 @@ var StructureManager = class {
14395
14690
  */
14396
14691
  unlinkMetaSibling(cellPath) {
14397
14692
  const meta = cellPath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
14398
- if (fs15.existsSync(meta)) {
14399
- fs15.unlinkSync(meta);
14693
+ if (fs16.existsSync(meta)) {
14694
+ fs16.unlinkSync(meta);
14400
14695
  }
14401
14696
  }
14402
14697
  /**
@@ -14541,7 +14836,7 @@ async function resolveIdentitySecrets(identityName, environment, manifest, repoR
14541
14836
  var crypto4 = __toESM(require("crypto"));
14542
14837
 
14543
14838
  // src/artifact/output.ts
14544
- var fs16 = __toESM(require("fs"));
14839
+ var fs17 = __toESM(require("fs"));
14545
14840
  var path21 = __toESM(require("path"));
14546
14841
  var FilePackOutput = class {
14547
14842
  constructor(outputPath) {
@@ -14549,12 +14844,12 @@ var FilePackOutput = class {
14549
14844
  }
14550
14845
  async write(_artifact, json) {
14551
14846
  const outputDir = path21.dirname(this.outputPath);
14552
- if (!fs16.existsSync(outputDir)) {
14553
- fs16.mkdirSync(outputDir, { recursive: true });
14847
+ if (!fs17.existsSync(outputDir)) {
14848
+ fs17.mkdirSync(outputDir, { recursive: true });
14554
14849
  }
14555
14850
  const tmpOutput = `${this.outputPath}.tmp.${process.pid}`;
14556
- fs16.writeFileSync(tmpOutput, json, "utf-8");
14557
- fs16.renameSync(tmpOutput, this.outputPath);
14851
+ fs17.writeFileSync(tmpOutput, json, "utf-8");
14852
+ fs17.renameSync(tmpOutput, this.outputPath);
14558
14853
  }
14559
14854
  };
14560
14855
  var MemoryPackOutput = class {
@@ -14776,7 +15071,7 @@ var VALID_KMS_PROVIDERS = ["aws", "gcp", "azure"];
14776
15071
 
14777
15072
  // src/migration/backend.ts
14778
15073
  var path22 = __toESM(require("path"));
14779
- var YAML10 = __toESM(require("yaml"));
15074
+ var YAML11 = __toESM(require("yaml"));
14780
15075
  var BACKEND_KEY_FIELDS = {
14781
15076
  age: void 0,
14782
15077
  awskms: "aws_kms_arn",
@@ -14899,7 +15194,7 @@ var BackendMigrator = class {
14899
15194
  const doc = readManifestYaml(repoRoot);
14900
15195
  this.updateManifestDoc(doc, target, environment);
14901
15196
  writeManifestYaml(repoRoot, doc);
14902
- const updatedManifest = YAML10.parse(YAML10.stringify(doc));
15197
+ const updatedManifest = YAML11.parse(YAML11.stringify(doc));
14903
15198
  for (const cell of toMigrate) {
14904
15199
  onProgress?.({
14905
15200
  type: "migrate",
@@ -15292,18 +15587,376 @@ var SyncManager = class {
15292
15587
  };
15293
15588
  }
15294
15589
  };
15590
+
15591
+ // src/policy/parser.ts
15592
+ var fs18 = __toESM(require("fs"));
15593
+ var YAML12 = __toESM(require("yaml"));
15594
+
15595
+ // src/policy/types.ts
15596
+ var DEFAULT_POLICY = Object.freeze({
15597
+ version: 1,
15598
+ rotation: Object.freeze({ max_age_days: 90 })
15599
+ });
15600
+
15601
+ // src/policy/parser.ts
15602
+ var CLEF_POLICY_FILENAME = ".clef/policy.yaml";
15603
+ var SUPPORTED_VERSIONS = [1];
15604
+ var PolicyParser = class {
15605
+ /**
15606
+ * Read and validate a policy file from disk.
15607
+ *
15608
+ * @throws {@link PolicyValidationError} If the file cannot be read, contains
15609
+ * invalid YAML, or fails schema validation.
15610
+ */
15611
+ parse(filePath) {
15612
+ let raw;
15613
+ try {
15614
+ raw = fs18.readFileSync(filePath, "utf-8");
15615
+ } catch {
15616
+ throw new PolicyValidationError(`Could not read policy file at '${filePath}'.`);
15617
+ }
15618
+ return this.parseContent(raw);
15619
+ }
15620
+ /**
15621
+ * Parse and validate a policy document from a YAML string.
15622
+ *
15623
+ * @throws {@link PolicyValidationError} If the content is malformed or
15624
+ * fails validation.
15625
+ */
15626
+ parseContent(content) {
15627
+ let parsed;
15628
+ try {
15629
+ parsed = YAML12.parse(content);
15630
+ } catch {
15631
+ throw new PolicyValidationError(
15632
+ "Policy file contains invalid YAML. Check for syntax errors."
15633
+ );
15634
+ }
15635
+ return this.validate(parsed);
15636
+ }
15637
+ /**
15638
+ * Load policy from disk, returning {@link DEFAULT_POLICY} if the file does
15639
+ * not exist. Any other read or validation error throws.
15640
+ */
15641
+ load(filePath) {
15642
+ if (!fs18.existsSync(filePath)) return DEFAULT_POLICY;
15643
+ return this.parse(filePath);
15644
+ }
15645
+ validate(raw) {
15646
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
15647
+ throw new PolicyValidationError("Policy file must be a YAML object.");
15648
+ }
15649
+ const doc = raw;
15650
+ if (!SUPPORTED_VERSIONS.includes(doc.version)) {
15651
+ throw new PolicyValidationError(
15652
+ `Policy file must declare 'version: 1', got: ${JSON.stringify(doc.version)}.`,
15653
+ "version"
15654
+ );
15655
+ }
15656
+ const rotation = doc.rotation === void 0 ? void 0 : this.validateRotation(doc.rotation);
15657
+ return { version: 1, ...rotation ? { rotation } : {} };
15658
+ }
15659
+ validateRotation(raw) {
15660
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
15661
+ throw new PolicyValidationError("Policy 'rotation' must be an object.", "rotation");
15662
+ }
15663
+ const rot = raw;
15664
+ const maxAge = rot.max_age_days;
15665
+ if (typeof maxAge !== "number" || !Number.isFinite(maxAge) || maxAge <= 0) {
15666
+ throw new PolicyValidationError(
15667
+ "Policy 'rotation.max_age_days' must be a positive number.",
15668
+ "rotation.max_age_days"
15669
+ );
15670
+ }
15671
+ const result = { max_age_days: maxAge };
15672
+ if (rot.environments !== void 0) {
15673
+ if (typeof rot.environments !== "object" || rot.environments === null || Array.isArray(rot.environments)) {
15674
+ throw new PolicyValidationError(
15675
+ "Policy 'rotation.environments' must be an object keyed by environment name.",
15676
+ "rotation.environments"
15677
+ );
15678
+ }
15679
+ const envs = {};
15680
+ for (const [envName, envVal] of Object.entries(rot.environments)) {
15681
+ if (typeof envVal !== "object" || envVal === null || Array.isArray(envVal)) {
15682
+ throw new PolicyValidationError(
15683
+ `Policy 'rotation.environments.${envName}' must be an object.`,
15684
+ `rotation.environments.${envName}`
15685
+ );
15686
+ }
15687
+ const envMaxAge = envVal.max_age_days;
15688
+ if (typeof envMaxAge !== "number" || !Number.isFinite(envMaxAge) || envMaxAge <= 0) {
15689
+ throw new PolicyValidationError(
15690
+ `Policy 'rotation.environments.${envName}.max_age_days' must be a positive number.`,
15691
+ `rotation.environments.${envName}.max_age_days`
15692
+ );
15693
+ }
15694
+ envs[envName] = { max_age_days: envMaxAge };
15695
+ }
15696
+ result.environments = envs;
15697
+ }
15698
+ return result;
15699
+ }
15700
+ };
15701
+
15702
+ // src/policy/evaluator.ts
15703
+ var MS_PER_DAY = 864e5;
15704
+ var DEFAULT_MAX_AGE_DAYS = 90;
15705
+ var PolicyEvaluator = class {
15706
+ constructor(policy) {
15707
+ this.policy = policy;
15708
+ }
15709
+ /**
15710
+ * Evaluate a single encrypted file's per-key rotation state.
15711
+ *
15712
+ * @param filePath Repo-relative or absolute path to the encrypted file.
15713
+ * @param environment Environment name; selects per-env overrides.
15714
+ * @param metadata SOPS metadata for the file (carries last_modified,
15715
+ * backend, recipients). The evaluator does not read
15716
+ * `last_modified` for the policy gate — it is echoed
15717
+ * into the output for audit consumers only.
15718
+ * @param keys Plaintext key names present in the cipher, enumerated
15719
+ * from the unencrypted YAML top-level keys (no decrypt
15720
+ * required since SOPS stores key names in plaintext).
15721
+ * @param rotations Rotation records from `.clef-meta.yaml`. Records for
15722
+ * keys not in `keys` are ignored (those are orphans;
15723
+ * lint surfaces them as a warning).
15724
+ * @param now Reference time. Inject for deterministic tests.
15725
+ */
15726
+ evaluateFile(filePath, environment, metadata, keys, rotations, now = /* @__PURE__ */ new Date()) {
15727
+ const maxAgeDays = this.resolveMaxAgeDays(environment);
15728
+ const byKey = new Map(rotations.map((r) => [r.key, r]));
15729
+ const keyStatuses = keys.map(
15730
+ (key) => this.evaluateKey(key, byKey.get(key), maxAgeDays, now)
15731
+ );
15732
+ return {
15733
+ path: filePath,
15734
+ environment,
15735
+ backend: metadata.backend,
15736
+ recipients: metadata.recipients,
15737
+ last_modified: metadata.lastModified.toISOString(),
15738
+ last_modified_known: metadata.lastModifiedPresent !== false,
15739
+ keys: keyStatuses,
15740
+ // Cell-level compliance is the AND of per-key verdicts. An empty
15741
+ // `keys` array (cell with no secrets) is vacuously compliant.
15742
+ compliant: keyStatuses.every((k) => k.compliant)
15743
+ };
15744
+ }
15745
+ evaluateKey(key, record, maxAgeDays, now) {
15746
+ if (!record) {
15747
+ return {
15748
+ key,
15749
+ last_rotated_at: null,
15750
+ last_rotated_known: false,
15751
+ rotated_by: null,
15752
+ rotation_count: 0,
15753
+ rotation_due: null,
15754
+ rotation_overdue: false,
15755
+ days_overdue: 0,
15756
+ compliant: false
15757
+ };
15758
+ }
15759
+ const rotationDue = new Date(record.lastRotatedAt.getTime() + maxAgeDays * MS_PER_DAY);
15760
+ const rotationOverdue = now.getTime() > rotationDue.getTime();
15761
+ const daysOverdue = rotationOverdue ? Math.floor((now.getTime() - rotationDue.getTime()) / MS_PER_DAY) : 0;
15762
+ return {
15763
+ key,
15764
+ last_rotated_at: record.lastRotatedAt.toISOString(),
15765
+ last_rotated_known: true,
15766
+ rotated_by: record.rotatedBy,
15767
+ rotation_count: record.rotationCount,
15768
+ rotation_due: rotationDue.toISOString(),
15769
+ rotation_overdue: rotationOverdue,
15770
+ days_overdue: daysOverdue,
15771
+ compliant: !rotationOverdue
15772
+ };
15773
+ }
15774
+ resolveMaxAgeDays(environment) {
15775
+ const envOverride = this.policy.rotation?.environments?.[environment];
15776
+ if (envOverride !== void 0) return envOverride.max_age_days;
15777
+ return this.policy.rotation?.max_age_days ?? DEFAULT_MAX_AGE_DAYS;
15778
+ }
15779
+ };
15780
+
15781
+ // src/compliance/generator.ts
15782
+ var import_crypto2 = require("crypto");
15783
+ var SCHEMA_VERSION = "1";
15784
+ function canonicalJson(value) {
15785
+ if (value === null || typeof value !== "object") {
15786
+ return JSON.stringify(value);
15787
+ }
15788
+ if (Array.isArray(value)) {
15789
+ return `[${value.map(canonicalJson).join(",")}]`;
15790
+ }
15791
+ const obj = value;
15792
+ const keys = Object.keys(obj).sort();
15793
+ const entries = keys.map((k) => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`);
15794
+ return `{${entries.join(",")}}`;
15795
+ }
15796
+ var ComplianceGenerator = class {
15797
+ generate(opts) {
15798
+ const { sha, repo, policy, scanResult, lintResult, files, now } = opts;
15799
+ const generated_at = (now ?? /* @__PURE__ */ new Date()).toISOString();
15800
+ const policy_hash = `sha256:${(0, import_crypto2.createHash)("sha256").update(canonicalJson(policy)).digest("hex")}`;
15801
+ return {
15802
+ schema_version: SCHEMA_VERSION,
15803
+ generated_at,
15804
+ sha,
15805
+ repo,
15806
+ policy_hash,
15807
+ policy_snapshot: policy,
15808
+ summary: this.buildSummary(scanResult, lintResult, files),
15809
+ files,
15810
+ scan: scanResult,
15811
+ lint: lintResult
15812
+ };
15813
+ }
15814
+ /**
15815
+ * Compute a {@link ComplianceDocument.policy_hash}-format hash of any
15816
+ * {@link PolicyDocument} without generating a full document. Useful for
15817
+ * external consumers that want to compare policies across repos.
15818
+ */
15819
+ static hashPolicy(policy) {
15820
+ return `sha256:${(0, import_crypto2.createHash)("sha256").update(canonicalJson(policy)).digest("hex")}`;
15821
+ }
15822
+ buildSummary(scan, lint, files) {
15823
+ const rotationOverdue = files.filter((f) => !f.compliant).length;
15824
+ return {
15825
+ total_files: files.length,
15826
+ compliant: files.filter((f) => f.compliant).length,
15827
+ rotation_overdue: rotationOverdue,
15828
+ scan_violations: scan.matches.length,
15829
+ lint_errors: lint.issues.filter((i) => i.severity === "error").length
15830
+ };
15831
+ }
15832
+ };
15833
+
15834
+ // src/compliance/run.ts
15835
+ var path25 = __toESM(require("path"));
15836
+ var UNKNOWN = "unknown";
15837
+ async function runCompliance(opts) {
15838
+ const start = Date.now();
15839
+ const repoRoot = opts.repoRoot ?? process.cwd();
15840
+ const manifestPath = opts.manifestPath ?? path25.join(repoRoot, "clef.yaml");
15841
+ const policyPath = opts.policyPath ?? path25.join(repoRoot, CLEF_POLICY_FILENAME);
15842
+ const include = {
15843
+ scan: opts.include?.scan ?? true,
15844
+ lint: opts.include?.lint ?? true,
15845
+ rotation: opts.include?.rotation ?? true
15846
+ };
15847
+ const now = opts.now ?? /* @__PURE__ */ new Date();
15848
+ const manifest = new ManifestParser().parse(manifestPath);
15849
+ const policy = opts.policy ?? new PolicyParser().load(policyPath);
15850
+ const sopsClient = new SopsClient(opts.runner, opts.ageKeyFile, opts.ageKey, opts.sopsPath);
15851
+ const matrixManager = new MatrixManager();
15852
+ const schemaValidator = new SchemaValidator();
15853
+ const [sha, repo, files, scanResult, lintResult] = await Promise.all([
15854
+ opts.sha !== void 0 ? Promise.resolve(opts.sha) : detectSha(opts.runner, repoRoot),
15855
+ opts.repo !== void 0 ? Promise.resolve(opts.repo) : detectRepo(opts.runner, repoRoot),
15856
+ include.rotation ? evaluateMatrix({
15857
+ manifest,
15858
+ repoRoot,
15859
+ policy,
15860
+ matrixManager,
15861
+ sopsClient,
15862
+ filter: opts.filter,
15863
+ now
15864
+ }) : Promise.resolve([]),
15865
+ include.scan ? new ScanRunner(opts.runner).scan(repoRoot, manifest) : Promise.resolve(emptyScan()),
15866
+ include.lint ? new LintRunner(matrixManager, schemaValidator, sopsClient).run(manifest, repoRoot) : Promise.resolve(emptyLint())
15867
+ ]);
15868
+ const adjustedLint = downgradeDecryptIssues(lintResult);
15869
+ const document = new ComplianceGenerator().generate({
15870
+ sha,
15871
+ repo,
15872
+ policy,
15873
+ scanResult,
15874
+ lintResult: adjustedLint,
15875
+ files,
15876
+ now
15877
+ });
15878
+ const passed = document.summary.rotation_overdue === 0 && document.summary.scan_violations === 0 && document.summary.lint_errors === 0;
15879
+ return { document, passed, durationMs: Date.now() - start };
15880
+ }
15881
+ async function evaluateMatrix(args) {
15882
+ const evaluator = new PolicyEvaluator(args.policy);
15883
+ const cells = args.matrixManager.resolveMatrix(args.manifest, args.repoRoot).filter((c) => applyFilter(c.namespace, c.environment, args.filter)).filter((c) => c.exists);
15884
+ return Promise.all(
15885
+ cells.map(async (cell) => {
15886
+ const metadata = await args.sopsClient.getMetadata(cell.filePath);
15887
+ const relPath = path25.relative(args.repoRoot, cell.filePath).replace(/\\/g, "/");
15888
+ const keys = readSopsKeyNames(cell.filePath) ?? [];
15889
+ const rotations = await getRotations(cell.filePath);
15890
+ return evaluator.evaluateFile(relPath, cell.environment, metadata, keys, rotations, args.now);
15891
+ })
15892
+ );
15893
+ }
15894
+ function applyFilter(namespace, environment, filter) {
15895
+ if (filter?.namespaces?.length && !filter.namespaces.includes(namespace)) return false;
15896
+ if (filter?.environments?.length && !filter.environments.includes(environment)) return false;
15897
+ return true;
15898
+ }
15899
+ function emptyScan() {
15900
+ return {
15901
+ matches: [],
15902
+ filesScanned: 0,
15903
+ filesSkipped: 0,
15904
+ unencryptedMatrixFiles: [],
15905
+ durationMs: 0
15906
+ };
15907
+ }
15908
+ function emptyLint() {
15909
+ return { issues: [], fileCount: 0, pendingCount: 0 };
15910
+ }
15911
+ function downgradeDecryptIssues(result) {
15912
+ return {
15913
+ ...result,
15914
+ issues: result.issues.map((issue) => {
15915
+ if (issue.category === "sops" && issue.message.startsWith("Failed to decrypt")) {
15916
+ return {
15917
+ ...issue,
15918
+ severity: "info",
15919
+ message: `File not decryptable in this environment (compliance runs without keys). Original check: ${issue.message}`
15920
+ };
15921
+ }
15922
+ return issue;
15923
+ })
15924
+ };
15925
+ }
15926
+ async function detectSha(runner, repoRoot) {
15927
+ const env = process.env;
15928
+ const fromEnv = env.GITHUB_SHA ?? env.CI_COMMIT_SHA ?? env.BITBUCKET_COMMIT ?? env.CIRCLE_SHA1 ?? env.BUILD_VCS_NUMBER;
15929
+ if (fromEnv) return fromEnv;
15930
+ const result = await runner.run("git", ["rev-parse", "HEAD"], { cwd: repoRoot });
15931
+ if (result.exitCode !== 0) return UNKNOWN;
15932
+ const trimmed = result.stdout.trim();
15933
+ return trimmed || UNKNOWN;
15934
+ }
15935
+ async function detectRepo(runner, repoRoot) {
15936
+ const env = process.env;
15937
+ const fromEnv = env.GITHUB_REPOSITORY ?? env.CI_PROJECT_PATH ?? env.BITBUCKET_REPO_FULL_NAME ?? (env.CIRCLE_PROJECT_USERNAME && env.CIRCLE_PROJECT_REPONAME ? `${env.CIRCLE_PROJECT_USERNAME}/${env.CIRCLE_PROJECT_REPONAME}` : void 0);
15938
+ if (fromEnv) return fromEnv;
15939
+ const result = await runner.run("git", ["remote", "get-url", "origin"], { cwd: repoRoot });
15940
+ if (result.exitCode !== 0) return UNKNOWN;
15941
+ const url = result.stdout.trim();
15942
+ const match = url.match(/[:/]([^/:]+)\/([^/]+?)(?:\.git)?\/?$/);
15943
+ return match ? `${match[1]}/${match[2]}` : UNKNOWN;
15944
+ }
15295
15945
  // Annotate the CommonJS export names for ESM import in node:
15296
15946
  0 && (module.exports = {
15297
15947
  ArtifactPacker,
15298
15948
  BackendMigrator,
15299
15949
  BulkOps,
15300
15950
  CLEF_MANIFEST_FILENAME,
15951
+ CLEF_POLICY_FILENAME,
15301
15952
  CLEF_REPORT_SCHEMA_VERSION,
15302
15953
  CLEF_SUPPORTED_EXTENSIONS,
15303
15954
  ClefError,
15304
15955
  CloudApiError,
15305
15956
  CloudClient,
15957
+ ComplianceGenerator,
15306
15958
  ConsumptionClient,
15959
+ DEFAULT_POLICY,
15307
15960
  DiffEngine,
15308
15961
  DriftDetector,
15309
15962
  FilePackOutput,
@@ -15315,6 +15968,9 @@ var SyncManager = class {
15315
15968
  ManifestValidationError,
15316
15969
  MatrixManager,
15317
15970
  MemoryPackOutput,
15971
+ PolicyEvaluator,
15972
+ PolicyParser,
15973
+ PolicyValidationError,
15318
15974
  REQUESTS_FILENAME,
15319
15975
  REQUIREMENTS,
15320
15976
  RecipientManager,
@@ -15355,6 +16011,7 @@ var SyncManager = class {
15355
16011
  generateRandomValue,
15356
16012
  generateSigningKeyPair,
15357
16013
  getPendingKeys,
16014
+ getRotations,
15358
16015
  isHighEntropy,
15359
16016
  isKmsEnvelope,
15360
16017
  isPending,
@@ -15366,6 +16023,8 @@ var SyncManager = class {
15366
16023
  markPendingWithRetry,
15367
16024
  markResolved,
15368
16025
  matchPatterns,
16026
+ mergeMetadataContents,
16027
+ mergeMetadataFiles,
15369
16028
  metadataPath,
15370
16029
  parse,
15371
16030
  parseDotenv,
@@ -15373,14 +16032,17 @@ var SyncManager = class {
15373
16032
  parseJson,
15374
16033
  parseYaml,
15375
16034
  readManifestYaml,
16035
+ recordRotation,
15376
16036
  redactValue,
15377
16037
  removeAccessRequest,
16038
+ removeRotation,
15378
16039
  requestsFilePath,
15379
16040
  resetSopsResolution,
15380
16041
  resolveBackendConfig,
15381
16042
  resolveIdentitySecrets,
15382
16043
  resolveRecipientsForEnvironment,
15383
16044
  resolveSopsPath,
16045
+ runCompliance,
15384
16046
  saveMetadata,
15385
16047
  saveRequests,
15386
16048
  shannonEntropy,
@@ -15397,17 +16059,16 @@ var SyncManager = class {
15397
16059
  });
15398
16060
  /*! Bundled license information:
15399
16061
 
15400
- @noble/hashes/utils.js:
15401
- @noble/hashes/utils.js:
15402
- @noble/hashes/utils.js:
15403
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
15404
-
15405
16062
  @scure/base/index.js:
15406
16063
  (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
15407
16064
 
15408
16065
  @noble/ciphers/utils.js:
15409
16066
  (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
15410
16067
 
16068
+ @noble/hashes/utils.js:
16069
+ @noble/hashes/utils.js:
16070
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
16071
+
15411
16072
  @noble/curves/utils.js:
15412
16073
  @noble/curves/abstract/modular.js:
15413
16074
  @noble/curves/abstract/curve.js: