@clef-sh/core 0.1.18 → 0.1.20-beta.142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  mod
31
31
  ));
32
32
 
33
- // node_modules/signal-exit/dist/cjs/signals.js
33
+ // ../../node_modules/write-file-atomic/node_modules/signal-exit/dist/cjs/signals.js
34
34
  var require_signals = __commonJS({
35
- "node_modules/signal-exit/dist/cjs/signals.js"(exports) {
35
+ "../../node_modules/write-file-atomic/node_modules/signal-exit/dist/cjs/signals.js"(exports) {
36
36
  "use strict";
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.signals = void 0;
@@ -61,9 +61,9 @@ var require_signals = __commonJS({
61
61
  }
62
62
  });
63
63
 
64
- // node_modules/signal-exit/dist/cjs/index.js
64
+ // ../../node_modules/write-file-atomic/node_modules/signal-exit/dist/cjs/index.js
65
65
  var require_cjs = __commonJS({
66
- "node_modules/signal-exit/dist/cjs/index.js"(exports) {
66
+ "../../node_modules/write-file-atomic/node_modules/signal-exit/dist/cjs/index.js"(exports) {
67
67
  "use strict";
68
68
  var _a;
69
69
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -296,18 +296,18 @@ var require_cjs = __commonJS({
296
296
  }
297
297
  });
298
298
 
299
- // node_modules/write-file-atomic/lib/index.js
299
+ // ../../node_modules/write-file-atomic/lib/index.js
300
300
  var require_lib = __commonJS({
301
- "node_modules/write-file-atomic/lib/index.js"(exports, module) {
301
+ "../../node_modules/write-file-atomic/lib/index.js"(exports, module) {
302
302
  "use strict";
303
303
  module.exports = writeFile;
304
304
  module.exports.sync = writeFileSync7;
305
305
  module.exports._getTmpname = getTmpname;
306
306
  module.exports._cleanupOnExit = cleanupOnExit;
307
- var fs19 = __require("fs");
307
+ var fs21 = __require("fs");
308
308
  var crypto4 = __require("node:crypto");
309
309
  var { onExit } = require_cjs();
310
- var path26 = __require("path");
310
+ var path28 = __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
- fs19.unlinkSync(typeof tmpfile === "function" ? tmpfile() : tmpfile);
328
+ fs21.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 = path26.resolve(filename);
363
+ const absoluteName = path28.resolve(filename);
364
364
  try {
365
365
  await serializeActiveFile(absoluteName);
366
- const truename = await promisify(fs19.realpath)(filename).catch(() => filename);
366
+ const truename = await promisify(fs21.realpath)(filename).catch(() => filename);
367
367
  tmpfile = getTmpname(truename);
368
368
  if (!options.mode || !options.chown) {
369
- const stats = await promisify(fs19.stat)(truename).catch(() => {
369
+ const stats = await promisify(fs21.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(fs19.open)(tmpfile, "w", options.mode);
380
+ fd = await promisify(fs21.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(fs19.write)(fd, data, 0, data.length, 0);
385
+ await promisify(fs21.write)(fd, data, 0, data.length, 0);
386
386
  } else if (data != null) {
387
- await promisify(fs19.write)(fd, String(data), 0, String(options.encoding || "utf8"));
387
+ await promisify(fs21.write)(fd, String(data), 0, String(options.encoding || "utf8"));
388
388
  }
389
389
  if (options.fsync !== false) {
390
- await promisify(fs19.fsync)(fd);
390
+ await promisify(fs21.fsync)(fd);
391
391
  }
392
- await promisify(fs19.close)(fd);
392
+ await promisify(fs21.close)(fd);
393
393
  fd = null;
394
394
  if (options.chown) {
395
- await promisify(fs19.chown)(tmpfile, options.chown.uid, options.chown.gid).catch((err) => {
395
+ await promisify(fs21.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(fs19.chmod)(tmpfile, options.mode).catch((err) => {
402
+ await promisify(fs21.chmod)(tmpfile, options.mode).catch((err) => {
403
403
  if (!isChownErrOk(err)) {
404
404
  throw err;
405
405
  }
406
406
  });
407
407
  }
408
- await promisify(fs19.rename)(tmpfile, truename);
408
+ await promisify(fs21.rename)(tmpfile, truename);
409
409
  } finally {
410
410
  if (fd) {
411
- await promisify(fs19.close)(fd).catch(
411
+ await promisify(fs21.close)(fd).catch(
412
412
  /* istanbul ignore next */
413
413
  () => {
414
414
  }
415
415
  );
416
416
  }
417
417
  removeOnExitHandler();
418
- await promisify(fs19.unlink)(tmpfile).catch(() => {
418
+ await promisify(fs21.unlink)(tmpfile).catch(() => {
419
419
  });
420
420
  activeFiles[absoluteName].shift();
421
421
  if (activeFiles[absoluteName].length > 0) {
@@ -448,13 +448,13 @@ var require_lib = __commonJS({
448
448
  options = {};
449
449
  }
450
450
  try {
451
- filename = fs19.realpathSync(filename);
451
+ filename = fs21.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 = fs19.statSync(filename);
457
+ const stats = fs21.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 = fs19.openSync(tmpfile, "w", options.mode || 438);
473
+ fd = fs21.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
- fs19.writeSync(fd, data, 0, data.length, 0);
478
+ fs21.writeSync(fd, data, 0, data.length, 0);
479
479
  } else if (data != null) {
480
- fs19.writeSync(fd, String(data), 0, String(options.encoding || "utf8"));
480
+ fs21.writeSync(fd, String(data), 0, String(options.encoding || "utf8"));
481
481
  }
482
482
  if (options.fsync !== false) {
483
- fs19.fsyncSync(fd);
483
+ fs21.fsyncSync(fd);
484
484
  }
485
- fs19.closeSync(fd);
485
+ fs21.closeSync(fd);
486
486
  fd = null;
487
487
  if (options.chown) {
488
488
  try {
489
- fs19.chownSync(tmpfile, options.chown.uid, options.chown.gid);
489
+ fs21.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
- fs19.chmodSync(tmpfile, options.mode);
498
+ fs21.chmodSync(tmpfile, options.mode);
499
499
  } catch (err) {
500
500
  if (!isChownErrOk(err)) {
501
501
  throw err;
502
502
  }
503
503
  }
504
504
  }
505
- fs19.renameSync(tmpfile, filename);
505
+ fs21.renameSync(tmpfile, filename);
506
506
  threw = false;
507
507
  } finally {
508
508
  if (fd) {
509
509
  try {
510
- fs19.closeSync(fd);
510
+ fs21.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
  module.exports = patch;
549
- function patch(fs19) {
549
+ function patch(fs21) {
550
550
  if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
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) {
551
+ patchLchmod(fs21);
552
+ }
553
+ if (!fs21.lutimes) {
554
+ patchLutimes(fs21);
555
+ }
556
+ fs21.chown = chownFix(fs21.chown);
557
+ fs21.fchown = chownFix(fs21.fchown);
558
+ fs21.lchown = chownFix(fs21.lchown);
559
+ fs21.chmod = chmodFix(fs21.chmod);
560
+ fs21.fchmod = chmodFix(fs21.fchmod);
561
+ fs21.lchmod = chmodFix(fs21.lchmod);
562
+ fs21.chownSync = chownFixSync(fs21.chownSync);
563
+ fs21.fchownSync = chownFixSync(fs21.fchownSync);
564
+ fs21.lchownSync = chownFixSync(fs21.lchownSync);
565
+ fs21.chmodSync = chmodFixSync(fs21.chmodSync);
566
+ fs21.fchmodSync = chmodFixSync(fs21.fchmodSync);
567
+ fs21.lchmodSync = chmodFixSync(fs21.lchmodSync);
568
+ fs21.stat = statFix(fs21.stat);
569
+ fs21.fstat = statFix(fs21.fstat);
570
+ fs21.lstat = statFix(fs21.lstat);
571
+ fs21.statSync = statFixSync(fs21.statSync);
572
+ fs21.fstatSync = statFixSync(fs21.fstatSync);
573
+ fs21.lstatSync = statFixSync(fs21.lstatSync);
574
+ if (fs21.chmod && !fs21.lchmod) {
575
+ fs21.lchmod = function(path28, mode, cb) {
576
576
  if (cb) process.nextTick(cb);
577
577
  };
578
- fs19.lchmodSync = function() {
578
+ fs21.lchmodSync = function() {
579
579
  };
580
580
  }
581
- if (fs19.chown && !fs19.lchown) {
582
- fs19.lchown = function(path26, uid, gid, cb) {
581
+ if (fs21.chown && !fs21.lchown) {
582
+ fs21.lchown = function(path28, uid, gid, cb) {
583
583
  if (cb) process.nextTick(cb);
584
584
  };
585
- fs19.lchownSync = function() {
585
+ fs21.lchownSync = function() {
586
586
  };
587
587
  }
588
588
  if (platform === "win32") {
589
- fs19.rename = typeof fs19.rename !== "function" ? fs19.rename : (function(fs$rename) {
589
+ fs21.rename = typeof fs21.rename !== "function" ? fs21.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
- fs19.stat(to, function(stater, st) {
596
+ fs21.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
- })(fs19.rename);
612
+ })(fs21.rename);
613
613
  }
614
- fs19.read = typeof fs19.read !== "function" ? fs19.read : (function(fs$read) {
614
+ fs21.read = typeof fs21.read !== "function" ? fs21.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(fs19, fd, buffer, offset, length, position, callback);
622
+ return fs$read.call(fs21, fd, buffer, offset, length, position, callback);
623
623
  }
624
624
  callback_.apply(this, arguments);
625
625
  };
626
626
  }
627
- return fs$read.call(fs19, fd, buffer, offset, length, position, callback);
627
+ return fs$read.call(fs21, fd, buffer, offset, length, position, callback);
628
628
  }
629
629
  if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
630
630
  return read;
631
- })(fs19.read);
632
- fs19.readSync = typeof fs19.readSync !== "function" ? fs19.readSync : /* @__PURE__ */ (function(fs$readSync) {
631
+ })(fs21.read);
632
+ fs21.readSync = typeof fs21.readSync !== "function" ? fs21.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(fs19, fd, buffer, offset, length, position);
637
+ return fs$readSync.call(fs21, 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
- })(fs19.readSync);
648
- function patchLchmod(fs20) {
649
- fs20.lchmod = function(path26, mode, callback) {
650
- fs20.open(
651
- path26,
647
+ })(fs21.readSync);
648
+ function patchLchmod(fs22) {
649
+ fs22.lchmod = function(path28, mode, callback) {
650
+ fs22.open(
651
+ path28,
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
- fs20.fchmod(fd, mode, function(err2) {
660
- fs20.close(fd, function(err22) {
659
+ fs22.fchmod(fd, mode, function(err2) {
660
+ fs22.close(fd, function(err22) {
661
661
  if (callback) callback(err2 || err22);
662
662
  });
663
663
  });
664
664
  }
665
665
  );
666
666
  };
667
- fs20.lchmodSync = function(path26, mode) {
668
- var fd = fs20.openSync(path26, constants.O_WRONLY | constants.O_SYMLINK, mode);
667
+ fs22.lchmodSync = function(path28, mode) {
668
+ var fd = fs22.openSync(path28, constants.O_WRONLY | constants.O_SYMLINK, mode);
669
669
  var threw = true;
670
670
  var ret;
671
671
  try {
672
- ret = fs20.fchmodSync(fd, mode);
672
+ ret = fs22.fchmodSync(fd, mode);
673
673
  threw = false;
674
674
  } finally {
675
675
  if (threw) {
676
676
  try {
677
- fs20.closeSync(fd);
677
+ fs22.closeSync(fd);
678
678
  } catch (er) {
679
679
  }
680
680
  } else {
681
- fs20.closeSync(fd);
681
+ fs22.closeSync(fd);
682
682
  }
683
683
  }
684
684
  return ret;
685
685
  };
686
686
  }
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) {
687
+ function patchLutimes(fs22) {
688
+ if (constants.hasOwnProperty("O_SYMLINK") && fs22.futimes) {
689
+ fs22.lutimes = function(path28, at, mt, cb) {
690
+ fs22.open(path28, constants.O_SYMLINK, function(er, fd) {
691
691
  if (er) {
692
692
  if (cb) cb(er);
693
693
  return;
694
694
  }
695
- fs20.futimes(fd, at, mt, function(er2) {
696
- fs20.close(fd, function(er22) {
695
+ fs22.futimes(fd, at, mt, function(er2) {
696
+ fs22.close(fd, function(er22) {
697
697
  if (cb) cb(er2 || er22);
698
698
  });
699
699
  });
700
700
  });
701
701
  };
702
- fs20.lutimesSync = function(path26, at, mt) {
703
- var fd = fs20.openSync(path26, constants.O_SYMLINK);
702
+ fs22.lutimesSync = function(path28, at, mt) {
703
+ var fd = fs22.openSync(path28, constants.O_SYMLINK);
704
704
  var ret;
705
705
  var threw = true;
706
706
  try {
707
- ret = fs20.futimesSync(fd, at, mt);
707
+ ret = fs22.futimesSync(fd, at, mt);
708
708
  threw = false;
709
709
  } finally {
710
710
  if (threw) {
711
711
  try {
712
- fs20.closeSync(fd);
712
+ fs22.closeSync(fd);
713
713
  } catch (er) {
714
714
  }
715
715
  } else {
716
- fs20.closeSync(fd);
716
+ fs22.closeSync(fd);
717
717
  }
718
718
  }
719
719
  return ret;
720
720
  };
721
- } else if (fs20.futimes) {
722
- fs20.lutimes = function(_a, _b, _c, cb) {
721
+ } else if (fs22.futimes) {
722
+ fs22.lutimes = function(_a, _b, _c, cb) {
723
723
  if (cb) process.nextTick(cb);
724
724
  };
725
- fs20.lutimesSync = function() {
725
+ fs22.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(fs19, target, mode, function(er) {
732
+ return orig.call(fs21, 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(fs19, target, mode);
742
+ return orig.call(fs21, 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(fs19, target, uid, gid, function(er) {
751
+ return orig.call(fs21, 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(fs19, target, uid, gid);
761
+ return orig.call(fs21, 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(fs19, target, options, callback) : orig.call(fs19, target, callback);
781
+ return options ? orig.call(fs21, target, options, callback) : orig.call(fs21, 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(fs19, target, options) : orig.call(fs19, target);
787
+ var stats = options ? orig.call(fs21, target, options) : orig.call(fs21, 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"(exports, module) {
814
814
  var Stream = __require("stream").Stream;
815
815
  module.exports = legacy;
816
- function legacy(fs19) {
816
+ function legacy(fs21) {
817
817
  return {
818
818
  ReadStream,
819
819
  WriteStream
820
820
  };
821
- function ReadStream(path26, options) {
822
- if (!(this instanceof ReadStream)) return new ReadStream(path26, options);
821
+ function ReadStream(path28, options) {
822
+ if (!(this instanceof ReadStream)) return new ReadStream(path28, options);
823
823
  Stream.call(this);
824
824
  var self = this;
825
- this.path = path26;
825
+ this.path = path28;
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
- fs19.open(this.path, this.flags, this.mode, function(err, fd) {
859
+ fs21.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(path26, options) {
871
- if (!(this instanceof WriteStream)) return new WriteStream(path26, options);
870
+ function WriteStream(path28, options) {
871
+ if (!(this instanceof WriteStream)) return new WriteStream(path28, options);
872
872
  Stream.call(this);
873
- this.path = path26;
873
+ this.path = path28;
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 = fs19.open;
898
+ this._open = fs21.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"(exports, module) {
933
- var fs19 = __require("fs");
933
+ var fs21 = __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 (!fs19[gracefulQueue]) {
965
+ if (!fs21[gracefulQueue]) {
966
966
  queue = global[gracefulQueue] || [];
967
- publishQueue(fs19, queue);
968
- fs19.close = (function(fs$close) {
967
+ publishQueue(fs21, queue);
968
+ fs21.close = (function(fs$close) {
969
969
  function close(fd, cb) {
970
- return fs$close.call(fs19, fd, function(err) {
970
+ return fs$close.call(fs21, 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
- })(fs19.close);
983
- fs19.closeSync = (function(fs$closeSync) {
982
+ })(fs21.close);
983
+ fs21.closeSync = (function(fs$closeSync) {
984
984
  function closeSync2(fd) {
985
- fs$closeSync.apply(fs19, arguments);
985
+ fs$closeSync.apply(fs21, arguments);
986
986
  resetQueue();
987
987
  }
988
988
  Object.defineProperty(closeSync2, previousSymbol, {
989
989
  value: fs$closeSync
990
990
  });
991
991
  return closeSync2;
992
- })(fs19.closeSync);
992
+ })(fs21.closeSync);
993
993
  if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
994
994
  process.on("exit", function() {
995
- debug(fs19[gracefulQueue]);
996
- __require("assert").equal(fs19[gracefulQueue].length, 0);
995
+ debug(fs21[gracefulQueue]);
996
+ __require("assert").equal(fs21[gracefulQueue].length, 0);
997
997
  });
998
998
  }
999
999
  }
1000
1000
  var queue;
1001
1001
  if (!global[gracefulQueue]) {
1002
- publishQueue(global, fs19[gracefulQueue]);
1003
- }
1004
- module.exports = patch(clone(fs19));
1005
- if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs19.__patched) {
1006
- module.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) {
1002
+ publishQueue(global, fs21[gracefulQueue]);
1003
+ }
1004
+ module.exports = patch(clone(fs21));
1005
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs21.__patched) {
1006
+ module.exports = patch(fs21);
1007
+ fs21.__patched = true;
1008
+ }
1009
+ function patch(fs22) {
1010
+ polyfills(fs22);
1011
+ fs22.gracefulify = patch;
1012
+ fs22.createReadStream = createReadStream;
1013
+ fs22.createWriteStream = createWriteStream;
1014
+ var fs$readFile = fs22.readFile;
1015
+ fs22.readFile = readFile;
1016
+ function readFile(path28, options, cb) {
1017
1017
  if (typeof options === "function")
1018
1018
  cb = options, options = null;
1019
- return go$readFile(path26, options, cb);
1020
- function go$readFile(path27, options2, cb2, startTime) {
1021
- return fs$readFile(path27, options2, function(err) {
1019
+ return go$readFile(path28, options, cb);
1020
+ function go$readFile(path29, options2, cb2, startTime) {
1021
+ return fs$readFile(path29, options2, function(err) {
1022
1022
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
1023
- enqueue([go$readFile, [path27, options2, cb2], err, startTime || Date.now(), Date.now()]);
1023
+ enqueue([go$readFile, [path29, 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 = fs20.writeFile;
1032
- fs20.writeFile = writeFile;
1033
- function writeFile(path26, data, options, cb) {
1031
+ var fs$writeFile = fs22.writeFile;
1032
+ fs22.writeFile = writeFile;
1033
+ function writeFile(path28, data, options, cb) {
1034
1034
  if (typeof options === "function")
1035
1035
  cb = options, options = null;
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) {
1036
+ return go$writeFile(path28, data, options, cb);
1037
+ function go$writeFile(path29, data2, options2, cb2, startTime) {
1038
+ return fs$writeFile(path29, data2, options2, function(err) {
1039
1039
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
1040
- enqueue([go$writeFile, [path27, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
1040
+ enqueue([go$writeFile, [path29, 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 = fs20.appendFile;
1048
+ var fs$appendFile = fs22.appendFile;
1049
1049
  if (fs$appendFile)
1050
- fs20.appendFile = appendFile;
1051
- function appendFile(path26, data, options, cb) {
1050
+ fs22.appendFile = appendFile;
1051
+ function appendFile(path28, data, options, cb) {
1052
1052
  if (typeof options === "function")
1053
1053
  cb = options, options = null;
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) {
1054
+ return go$appendFile(path28, data, options, cb);
1055
+ function go$appendFile(path29, data2, options2, cb2, startTime) {
1056
+ return fs$appendFile(path29, data2, options2, function(err) {
1057
1057
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
1058
- enqueue([go$appendFile, [path27, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
1058
+ enqueue([go$appendFile, [path29, 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 = fs20.copyFile;
1066
+ var fs$copyFile = fs22.copyFile;
1067
1067
  if (fs$copyFile)
1068
- fs20.copyFile = copyFile;
1068
+ fs22.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 = fs20.readdir;
1087
- fs20.readdir = readdir;
1086
+ var fs$readdir = fs22.readdir;
1087
+ fs22.readdir = readdir;
1088
1088
  var noReaddirOptionVersions = /^v[0-5]\./;
1089
- function readdir(path26, options, cb) {
1089
+ function readdir(path28, 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(path27, options2, cb2, startTime) {
1093
- return fs$readdir(path27, fs$readdirCallback(
1094
- path27,
1092
+ var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path29, options2, cb2, startTime) {
1093
+ return fs$readdir(path29, fs$readdirCallback(
1094
+ path29,
1095
1095
  options2,
1096
1096
  cb2,
1097
1097
  startTime
1098
1098
  ));
1099
- } : function go$readdir2(path27, options2, cb2, startTime) {
1100
- return fs$readdir(path27, options2, fs$readdirCallback(
1101
- path27,
1099
+ } : function go$readdir2(path29, options2, cb2, startTime) {
1100
+ return fs$readdir(path29, options2, fs$readdirCallback(
1101
+ path29,
1102
1102
  options2,
1103
1103
  cb2,
1104
1104
  startTime
1105
1105
  ));
1106
1106
  };
1107
- return go$readdir(path26, options, cb);
1108
- function fs$readdirCallback(path27, options2, cb2, startTime) {
1107
+ return go$readdir(path28, options, cb);
1108
+ function fs$readdirCallback(path29, 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
- [path27, options2, cb2],
1113
+ [path29, 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(fs20);
1128
+ var legStreams = legacy(fs22);
1129
1129
  ReadStream = legStreams.ReadStream;
1130
1130
  WriteStream = legStreams.WriteStream;
1131
1131
  }
1132
- var fs$ReadStream = fs20.ReadStream;
1132
+ var fs$ReadStream = fs22.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 = fs20.WriteStream;
1137
+ var fs$WriteStream = fs22.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(fs20, "ReadStream", {
1142
+ Object.defineProperty(fs22, "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(fs20, "WriteStream", {
1152
+ Object.defineProperty(fs22, "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(fs20, "FileReadStream", {
1163
+ Object.defineProperty(fs22, "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(fs20, "FileWriteStream", {
1174
+ Object.defineProperty(fs22, "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(path26, options) {
1184
+ function ReadStream(path28, 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(path26, options) {
1204
+ function WriteStream(path28, 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(path26, options) {
1223
- return new fs20.ReadStream(path26, options);
1222
+ function createReadStream(path28, options) {
1223
+ return new fs22.ReadStream(path28, options);
1224
1224
  }
1225
- function createWriteStream(path26, options) {
1226
- return new fs20.WriteStream(path26, options);
1225
+ function createWriteStream(path28, options) {
1226
+ return new fs22.WriteStream(path28, options);
1227
1227
  }
1228
- var fs$open = fs20.open;
1229
- fs20.open = open;
1230
- function open(path26, flags, mode, cb) {
1228
+ var fs$open = fs22.open;
1229
+ fs22.open = open;
1230
+ function open(path28, flags, mode, cb) {
1231
1231
  if (typeof mode === "function")
1232
1232
  cb = mode, mode = null;
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) {
1233
+ return go$open(path28, flags, mode, cb);
1234
+ function go$open(path29, flags2, mode2, cb2, startTime) {
1235
+ return fs$open(path29, flags2, mode2, function(err, fd) {
1236
1236
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
1237
- enqueue([go$open, [path27, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
1237
+ enqueue([go$open, [path29, 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 fs20;
1245
+ return fs22;
1246
1246
  }
1247
1247
  function enqueue(elem) {
1248
1248
  debug("ENQUEUE", elem[0].name, elem[1]);
1249
- fs19[gracefulQueue].push(elem);
1249
+ fs21[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 < fs19[gracefulQueue].length; ++i) {
1256
- if (fs19[gracefulQueue][i].length > 2) {
1257
- fs19[gracefulQueue][i][3] = now;
1258
- fs19[gracefulQueue][i][4] = now;
1255
+ for (var i = 0; i < fs21[gracefulQueue].length; ++i) {
1256
+ if (fs21[gracefulQueue][i].length > 2) {
1257
+ fs21[gracefulQueue][i][3] = now;
1258
+ fs21[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 (fs19[gracefulQueue].length === 0)
1266
+ if (fs21[gracefulQueue].length === 0)
1267
1267
  return;
1268
- var elem = fs19[gracefulQueue].shift();
1268
+ var elem = fs21[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
- fs19[gracefulQueue].push(elem);
1290
+ fs21[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"(exports, module) {
1723
1723
  "use strict";
1724
1724
  var cacheSymbol = /* @__PURE__ */ Symbol();
1725
- function probe(file, fs19, callback) {
1726
- const cachedPrecision = fs19[cacheSymbol];
1725
+ function probe(file, fs21, callback) {
1726
+ const cachedPrecision = fs21[cacheSymbol];
1727
1727
  if (cachedPrecision) {
1728
- return fs19.stat(file, (err, stat) => {
1728
+ return fs21.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
- fs19.utimes(file, mtime, mtime, (err) => {
1736
+ fs21.utimes(file, mtime, mtime, (err) => {
1737
1737
  if (err) {
1738
1738
  return callback(err);
1739
1739
  }
1740
- fs19.stat(file, (err2, stat) => {
1740
+ fs21.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(fs19, cacheSymbol, { value: precision });
1745
+ Object.defineProperty(fs21, 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"(exports, module) {
1765
1765
  "use strict";
1766
- var path26 = __require("path");
1767
- var fs19 = require_graceful_fs();
1766
+ var path28 = __require("path");
1767
+ var fs21 = 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, path26.resolve(file));
1777
+ return callback(null, path28.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: fs19,
1898
+ fs: fs21,
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: fs19,
1942
+ fs: fs21,
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: fs19,
1964
+ fs: fs21,
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"(exports, module) {
2002
2002
  "use strict";
2003
- var fs19 = require_graceful_fs();
2004
- function createSyncFs(fs20) {
2003
+ var fs21 = require_graceful_fs();
2004
+ function createSyncFs(fs22) {
2005
2005
  const methods = ["mkdir", "realpath", "stat", "rmdir", "utimes"];
2006
- const newFs = { ...fs20 };
2006
+ const newFs = { ...fs22 };
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 = fs20[`${method}Sync`](...args);
2012
+ ret = fs22[`${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 || fs19);
2050
+ options.fs = createSyncFs(options.fs || fs21);
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
  }
@@ -2107,7 +2107,8 @@ function resolveBackendConfig(manifest, environment) {
2107
2107
  aws_kms_arn: manifest.sops.aws_kms_arn,
2108
2108
  gcp_kms_resource_id: manifest.sops.gcp_kms_resource_id,
2109
2109
  azure_kv_url: manifest.sops.azure_kv_url,
2110
- pgp_fingerprint: manifest.sops.pgp_fingerprint
2110
+ pgp_fingerprint: manifest.sops.pgp_fingerprint,
2111
+ pkcs11_uri: manifest.sops.pkcs11_uri
2111
2112
  };
2112
2113
  }
2113
2114
  function resolveRecipientsForEnvironment(manifest, environment) {
@@ -2121,6 +2122,7 @@ var ClefError = class extends Error {
2121
2122
  this.fix = fix;
2122
2123
  this.name = "ClefError";
2123
2124
  }
2125
+ fix;
2124
2126
  };
2125
2127
  var ManifestValidationError = class extends ClefError {
2126
2128
  constructor(message, field) {
@@ -2128,6 +2130,7 @@ var ManifestValidationError = class extends ClefError {
2128
2130
  this.field = field;
2129
2131
  this.name = "ManifestValidationError";
2130
2132
  }
2133
+ field;
2131
2134
  };
2132
2135
  var SopsDecryptionError = class extends ClefError {
2133
2136
  constructor(message, filePath) {
@@ -2138,6 +2141,7 @@ var SopsDecryptionError = class extends ClefError {
2138
2141
  this.filePath = filePath;
2139
2142
  this.name = "SopsDecryptionError";
2140
2143
  }
2144
+ filePath;
2141
2145
  };
2142
2146
  var SopsEncryptionError = class extends ClefError {
2143
2147
  constructor(message, filePath) {
@@ -2148,6 +2152,7 @@ var SopsEncryptionError = class extends ClefError {
2148
2152
  this.filePath = filePath;
2149
2153
  this.name = "SopsEncryptionError";
2150
2154
  }
2155
+ filePath;
2151
2156
  };
2152
2157
  var SopsKeyNotFoundError = class extends ClefError {
2153
2158
  constructor(message) {
@@ -2167,6 +2172,7 @@ var PolicyValidationError = class extends ClefError {
2167
2172
  this.field = field;
2168
2173
  this.name = "PolicyValidationError";
2169
2174
  }
2175
+ field;
2170
2176
  };
2171
2177
  var SchemaLoadError = class extends ClefError {
2172
2178
  constructor(message, filePath) {
@@ -2177,6 +2183,7 @@ var SchemaLoadError = class extends ClefError {
2177
2183
  this.filePath = filePath;
2178
2184
  this.name = "SchemaLoadError";
2179
2185
  }
2186
+ filePath;
2180
2187
  };
2181
2188
  var SopsMissingError = class extends ClefError {
2182
2189
  constructor(installHint) {
@@ -2188,6 +2195,7 @@ Then run clef doctor to verify your setup.`
2188
2195
  this.installHint = installHint;
2189
2196
  this.name = "SopsMissingError";
2190
2197
  }
2198
+ installHint;
2191
2199
  };
2192
2200
  var SopsVersionError = class extends ClefError {
2193
2201
  constructor(installed, required, installHint) {
@@ -2201,6 +2209,9 @@ Then run clef doctor to verify your setup.`
2201
2209
  this.installHint = installHint;
2202
2210
  this.name = "SopsVersionError";
2203
2211
  }
2212
+ installed;
2213
+ required;
2214
+ installHint;
2204
2215
  };
2205
2216
  function isKmsEnvelope(cfg) {
2206
2217
  return cfg.kms !== void 0;
@@ -2212,6 +2223,7 @@ var CloudApiError = class extends ClefError {
2212
2223
  this.statusCode = statusCode;
2213
2224
  this.name = "CloudApiError";
2214
2225
  }
2226
+ statusCode;
2215
2227
  };
2216
2228
 
2217
2229
  // src/manifest/parser.ts
@@ -2254,7 +2266,8 @@ function keyPreview(key) {
2254
2266
 
2255
2267
  // src/manifest/parser.ts
2256
2268
  var CLEF_MANIFEST_FILENAME = "clef.yaml";
2257
- var VALID_BACKENDS = ["age", "awskms", "gcpkms", "azurekv", "pgp"];
2269
+ var VALID_BACKENDS = ["age", "awskms", "gcpkms", "azurekv", "pgp", "hsm"];
2270
+ var PKCS11_URI_PATTERN = /^pkcs11:[a-zA-Z][a-zA-Z0-9_-]*=[^;]+/;
2258
2271
  var VALID_TOP_LEVEL_KEYS = [
2259
2272
  "version",
2260
2273
  "environments",
@@ -2413,12 +2426,27 @@ var ManifestParser = class {
2413
2426
  "environments"
2414
2427
  );
2415
2428
  }
2429
+ if (backend === "hsm") {
2430
+ if (typeof sopsOverride.pkcs11_uri !== "string") {
2431
+ throw new ManifestValidationError(
2432
+ `Environment '${envObj.name}' uses 'hsm' backend but is missing 'pkcs11_uri'.`,
2433
+ "environments"
2434
+ );
2435
+ }
2436
+ if (!PKCS11_URI_PATTERN.test(sopsOverride.pkcs11_uri)) {
2437
+ throw new ManifestValidationError(
2438
+ `Environment '${envObj.name}' has an invalid 'pkcs11_uri' '${sopsOverride.pkcs11_uri}'. Must start with 'pkcs11:' and contain at least one attribute (e.g. 'pkcs11:slot=0;label=clef-dek-wrapper').`,
2439
+ "environments"
2440
+ );
2441
+ }
2442
+ }
2416
2443
  result.sops = {
2417
2444
  backend,
2418
2445
  ...typeof sopsOverride.aws_kms_arn === "string" ? { aws_kms_arn: sopsOverride.aws_kms_arn } : {},
2419
2446
  ...typeof sopsOverride.gcp_kms_resource_id === "string" ? { gcp_kms_resource_id: sopsOverride.gcp_kms_resource_id } : {},
2420
2447
  ...typeof sopsOverride.azure_kv_url === "string" ? { azure_kv_url: sopsOverride.azure_kv_url } : {},
2421
- ...typeof sopsOverride.pgp_fingerprint === "string" ? { pgp_fingerprint: sopsOverride.pgp_fingerprint } : {}
2448
+ ...typeof sopsOverride.pgp_fingerprint === "string" ? { pgp_fingerprint: sopsOverride.pgp_fingerprint } : {},
2449
+ ...typeof sopsOverride.pkcs11_uri === "string" ? { pkcs11_uri: sopsOverride.pkcs11_uri } : {}
2422
2450
  };
2423
2451
  }
2424
2452
  if (envObj.recipients !== void 0) {
@@ -2550,7 +2578,7 @@ var ManifestParser = class {
2550
2578
  const sopsObj = obj.sops;
2551
2579
  if (!sopsObj.default_backend || typeof sopsObj.default_backend !== "string") {
2552
2580
  throw new ManifestValidationError(
2553
- "Field 'sops.default_backend' is required and must be one of: age, awskms, gcpkms, azurekv, pgp.",
2581
+ `Field 'sops.default_backend' is required and must be one of: ${VALID_BACKENDS.join(", ")}.`,
2554
2582
  "sops.default_backend"
2555
2583
  );
2556
2584
  }
@@ -2577,13 +2605,32 @@ var ManifestParser = class {
2577
2605
  })
2578
2606
  }
2579
2607
  } : {};
2608
+ if (sopsObj.pkcs11_uri !== void 0 && typeof sopsObj.pkcs11_uri !== "string") {
2609
+ throw new ManifestValidationError(
2610
+ "Field 'sops.pkcs11_uri' must be a string.",
2611
+ "sops.pkcs11_uri"
2612
+ );
2613
+ }
2614
+ if (typeof sopsObj.pkcs11_uri === "string" && !PKCS11_URI_PATTERN.test(sopsObj.pkcs11_uri)) {
2615
+ throw new ManifestValidationError(
2616
+ `Field 'sops.pkcs11_uri' has invalid format '${sopsObj.pkcs11_uri}'. Must start with 'pkcs11:' and contain at least one attribute (e.g. 'pkcs11:slot=0;label=clef-dek-wrapper').`,
2617
+ "sops.pkcs11_uri"
2618
+ );
2619
+ }
2620
+ if (sopsObj.default_backend === "hsm" && typeof sopsObj.pkcs11_uri !== "string") {
2621
+ throw new ManifestValidationError(
2622
+ "Field 'sops.pkcs11_uri' is required when sops.default_backend is 'hsm'.",
2623
+ "sops.pkcs11_uri"
2624
+ );
2625
+ }
2580
2626
  const sopsConfig = {
2581
2627
  default_backend: sopsObj.default_backend,
2582
2628
  ...parsedAge,
2583
2629
  ...typeof sopsObj.aws_kms_arn === "string" ? { aws_kms_arn: sopsObj.aws_kms_arn } : {},
2584
2630
  ...typeof sopsObj.gcp_kms_resource_id === "string" ? { gcp_kms_resource_id: sopsObj.gcp_kms_resource_id } : {},
2585
2631
  ...typeof sopsObj.azure_kv_url === "string" ? { azure_kv_url: sopsObj.azure_kv_url } : {},
2586
- ...typeof sopsObj.pgp_fingerprint === "string" ? { pgp_fingerprint: sopsObj.pgp_fingerprint } : {}
2632
+ ...typeof sopsObj.pgp_fingerprint === "string" ? { pgp_fingerprint: sopsObj.pgp_fingerprint } : {},
2633
+ ...typeof sopsObj.pkcs11_uri === "string" ? { pkcs11_uri: sopsObj.pkcs11_uri } : {}
2587
2634
  };
2588
2635
  for (const env of environments) {
2589
2636
  if (env.recipients && env.recipients.length > 0) {
@@ -2964,6 +3011,7 @@ var ScanRunner = class {
2964
3011
  constructor(runner) {
2965
3012
  this.runner = runner;
2966
3013
  }
3014
+ runner;
2967
3015
  /**
2968
3016
  * Scan tracked (or staged) files for secret-like values and unencrypted matrix files.
2969
3017
  *
@@ -3675,6 +3723,7 @@ var BulkOps = class {
3675
3723
  constructor(tx) {
3676
3724
  this.tx = tx;
3677
3725
  }
3726
+ tx;
3678
3727
  /**
3679
3728
  * Set a key to different values in multiple environments at once.
3680
3729
  *
@@ -3818,6 +3867,7 @@ var GitIntegration = class {
3818
3867
  constructor(runner) {
3819
3868
  this.runner = runner;
3820
3869
  }
3870
+ runner;
3821
3871
  /**
3822
3872
  * Stage one or more file paths with `git add`.
3823
3873
  *
@@ -4201,6 +4251,7 @@ var TransactionLockError = class extends Error {
4201
4251
  this.holderPid = holderPid;
4202
4252
  this.name = "TransactionLockError";
4203
4253
  }
4254
+ holderPid;
4204
4255
  };
4205
4256
  var TransactionPreflightError = class extends Error {
4206
4257
  constructor(reason, message, hint) {
@@ -4209,6 +4260,8 @@ var TransactionPreflightError = class extends Error {
4209
4260
  this.hint = hint;
4210
4261
  this.name = "TransactionPreflightError";
4211
4262
  }
4263
+ reason;
4264
+ hint;
4212
4265
  };
4213
4266
  var TransactionRollbackError = class extends Error {
4214
4267
  constructor(originalError, rollbackOk, message) {
@@ -4217,6 +4270,8 @@ var TransactionRollbackError = class extends Error {
4217
4270
  this.rollbackOk = rollbackOk;
4218
4271
  this.name = "TransactionRollbackError";
4219
4272
  }
4273
+ originalError;
4274
+ rollbackOk;
4220
4275
  };
4221
4276
 
4222
4277
  // src/tx/transaction-manager.ts
@@ -4231,6 +4286,7 @@ var TransactionManager = class {
4231
4286
  constructor(git) {
4232
4287
  this.git = git;
4233
4288
  }
4289
+ git;
4234
4290
  async run(repoRoot, opts) {
4235
4291
  const shouldCommit = opts.commit !== false;
4236
4292
  const allowDirty = opts.allowDirty === true;
@@ -4548,6 +4604,39 @@ ${privateKey}
4548
4604
  `;
4549
4605
  }
4550
4606
 
4607
+ // src/sops/hsm-arn.ts
4608
+ var CLEF_HSM_ARN_RE = /^arn:aws[\w-]*:kms:[^:]+:\d+:alias\/clef-hsm\/(v\d+)\/([A-Za-z0-9_-]+)$/;
4609
+ var ARN_PREFIX = "arn:aws:kms:us-east-1:000000000000:alias/clef-hsm/v1/";
4610
+ var SUPPORTED_VERSION = "v1";
4611
+ function pkcs11UriToSyntheticArn(uri) {
4612
+ if (!uri.startsWith("pkcs11:")) {
4613
+ throw new Error(`Expected a pkcs11 URI starting with 'pkcs11:', got '${uri}'.`);
4614
+ }
4615
+ const payload = Buffer.from(uri, "utf8").toString("base64url");
4616
+ const arn = ARN_PREFIX + payload;
4617
+ if (!CLEF_HSM_ARN_RE.test(arn)) {
4618
+ throw new Error(`Synthesized ARN failed self-validation: '${arn}'.`);
4619
+ }
4620
+ return arn;
4621
+ }
4622
+ function syntheticArnToPkcs11Uri(arn) {
4623
+ const match = CLEF_HSM_ARN_RE.exec(arn);
4624
+ if (!match) return null;
4625
+ const [, version, payload] = match;
4626
+ if (version !== SUPPORTED_VERSION) return null;
4627
+ let decoded;
4628
+ try {
4629
+ decoded = Buffer.from(payload, "base64url").toString("utf8");
4630
+ } catch {
4631
+ return null;
4632
+ }
4633
+ if (!decoded.startsWith("pkcs11:")) return null;
4634
+ return decoded;
4635
+ }
4636
+ function isClefHsmArn(arn) {
4637
+ return CLEF_HSM_ARN_RE.test(arn);
4638
+ }
4639
+
4551
4640
  // src/sops/client.ts
4552
4641
  function formatFromPath(filePath) {
4553
4642
  return filePath.endsWith(".json") ? "json" : "yaml";
@@ -4579,14 +4668,28 @@ var SopsClient = class {
4579
4668
  * to the subprocess environment.
4580
4669
  * @param sopsPath - Optional explicit path to the sops binary. When omitted,
4581
4670
  * resolved automatically via {@link resolveSopsPath}.
4671
+ * @param keyserviceAddr - Optional address of an external SOPS KeyService
4672
+ * sidecar (e.g. `tcp://127.0.0.1:12345`). When set, every SOPS invocation
4673
+ * includes `--enable-local-keyservice=false --keyservice <addr>` so KMS
4674
+ * wrap/unwrap is routed to the sidecar (used for the HSM backend, where
4675
+ * the sidecar is `clef-keyservice` talking PKCS#11 to the HSM).
4676
+ *
4677
+ * The flags are inserted **after** the SOPS subcommand — placing them
4678
+ * before is silently ignored by SOPS (a footgun discovered the first
4679
+ * time we shipped this).
4582
4680
  */
4583
- constructor(runner, ageKeyFile, ageKey, sopsPath) {
4681
+ constructor(runner, ageKeyFile, ageKey, sopsPath, keyserviceAddr) {
4584
4682
  this.runner = runner;
4585
4683
  this.ageKeyFile = ageKeyFile;
4586
4684
  this.ageKey = ageKey;
4587
4685
  this.sopsCommand = sopsPath ?? resolveSopsPath().path;
4686
+ this.keyserviceArgs = keyserviceAddr ? Object.freeze(["--enable-local-keyservice=false", "--keyservice", keyserviceAddr]) : Object.freeze([]);
4588
4687
  }
4688
+ runner;
4689
+ ageKeyFile;
4690
+ ageKey;
4589
4691
  sopsCommand;
4692
+ keyserviceArgs;
4590
4693
  buildSopsEnv() {
4591
4694
  const env = {};
4592
4695
  if (this.ageKey) {
@@ -4611,7 +4714,7 @@ var SopsClient = class {
4611
4714
  const env = this.buildSopsEnv();
4612
4715
  const result = await this.runner.run(
4613
4716
  this.sopsCommand,
4614
- ["decrypt", "--output-type", fmt, filePath],
4717
+ ["decrypt", ...this.keyserviceArgs, "--output-type", fmt, filePath],
4615
4718
  {
4616
4719
  ...env ? { env } : {}
4617
4720
  }
@@ -4678,6 +4781,7 @@ var SopsClient = class {
4678
4781
  "--config",
4679
4782
  configPath,
4680
4783
  "encrypt",
4784
+ ...this.keyserviceArgs,
4681
4785
  ...args,
4682
4786
  "--input-type",
4683
4787
  fmt,
@@ -4734,7 +4838,7 @@ var SopsClient = class {
4734
4838
  const env = this.buildSopsEnv();
4735
4839
  const result = await this.runner.run(
4736
4840
  this.sopsCommand,
4737
- ["rotate", "-i", "--add-age", key, filePath],
4841
+ ["rotate", ...this.keyserviceArgs, "-i", "--add-age", key, filePath],
4738
4842
  {
4739
4843
  ...env ? { env } : {}
4740
4844
  }
@@ -4758,7 +4862,7 @@ var SopsClient = class {
4758
4862
  const env = this.buildSopsEnv();
4759
4863
  const result = await this.runner.run(
4760
4864
  this.sopsCommand,
4761
- ["rotate", "-i", "--rm-age", key, filePath],
4865
+ ["rotate", ...this.keyserviceArgs, "-i", "--rm-age", key, filePath],
4762
4866
  {
4763
4867
  ...env ? { env } : {}
4764
4868
  }
@@ -4873,7 +4977,14 @@ var SopsClient = class {
4873
4977
  }
4874
4978
  detectBackend(sops) {
4875
4979
  if (sops.age && Array.isArray(sops.age) && sops.age.length > 0) return "age";
4876
- if (sops.kms && Array.isArray(sops.kms) && sops.kms.length > 0) return "awskms";
4980
+ if (sops.kms && Array.isArray(sops.kms) && sops.kms.length > 0) {
4981
+ const kmsEntries = sops.kms;
4982
+ const firstArn = kmsEntries[0]?.arn;
4983
+ if (typeof firstArn === "string" && isClefHsmArn(firstArn)) {
4984
+ return "hsm";
4985
+ }
4986
+ return "awskms";
4987
+ }
4877
4988
  if (sops.gcp_kms && Array.isArray(sops.gcp_kms) && sops.gcp_kms.length > 0)
4878
4989
  return "gcpkms";
4879
4990
  if (sops.azure_kv && Array.isArray(sops.azure_kv) && sops.azure_kv.length > 0)
@@ -4891,6 +5002,13 @@ var SopsClient = class {
4891
5002
  const entries = sops.kms;
4892
5003
  return entries?.map((e) => String(e.arn ?? "")) ?? [];
4893
5004
  }
5005
+ case "hsm": {
5006
+ const entries = sops.kms;
5007
+ return entries?.map((e) => {
5008
+ const raw = String(e.arn ?? "");
5009
+ return syntheticArnToPkcs11Uri(raw) ?? raw;
5010
+ }) ?? [];
5011
+ }
4894
5012
  case "gcpkms": {
4895
5013
  const entries = sops.gcp_kms;
4896
5014
  return entries?.map((e) => String(e.resource_id ?? "")) ?? [];
@@ -4916,7 +5034,8 @@ var SopsClient = class {
4916
5034
  aws_kms_arn: manifest.sops.aws_kms_arn,
4917
5035
  gcp_kms_resource_id: manifest.sops.gcp_kms_resource_id,
4918
5036
  azure_kv_url: manifest.sops.azure_kv_url,
4919
- pgp_fingerprint: manifest.sops.pgp_fingerprint
5037
+ pgp_fingerprint: manifest.sops.pgp_fingerprint,
5038
+ pkcs11_uri: manifest.sops.pkcs11_uri
4920
5039
  };
4921
5040
  switch (config.backend) {
4922
5041
  case "age": {
@@ -4948,19 +5067,181 @@ var SopsClient = class {
4948
5067
  args.push("--pgp", config.pgp_fingerprint);
4949
5068
  }
4950
5069
  break;
5070
+ case "hsm":
5071
+ if (config.pkcs11_uri) {
5072
+ args.push("--kms", pkcs11UriToSyntheticArn(config.pkcs11_uri));
5073
+ }
5074
+ break;
4951
5075
  }
4952
5076
  return args;
4953
5077
  }
4954
5078
  };
4955
5079
 
4956
- // src/lint/runner.ts
5080
+ // src/hsm/bundled.ts
5081
+ import * as fs14 from "fs";
4957
5082
  import * as path12 from "path";
5083
+ function tryBundledKeyservice() {
5084
+ const platform = process.platform;
5085
+ const arch = process.arch;
5086
+ const archName = arch === "x64" ? "x64" : arch === "arm64" ? "arm64" : null;
5087
+ if (!archName) return null;
5088
+ const platformName = platform === "darwin" ? "darwin" : platform === "linux" ? "linux" : null;
5089
+ if (!platformName) return null;
5090
+ const packageName = `@clef-sh/keyservice-${platformName}-${archName}`;
5091
+ const binName = "clef-keyservice";
5092
+ try {
5093
+ const packageMain = __require.resolve(`${packageName}/package.json`);
5094
+ const packageDir = path12.dirname(packageMain);
5095
+ const binPath = path12.join(packageDir, "bin", binName);
5096
+ return fs14.existsSync(binPath) ? binPath : null;
5097
+ } catch {
5098
+ return null;
5099
+ }
5100
+ }
5101
+
5102
+ // src/hsm/resolver.ts
5103
+ import * as fs15 from "fs";
5104
+ import * as path13 from "path";
5105
+ function validateKeyservicePath(candidate) {
5106
+ if (!path13.isAbsolute(candidate)) {
5107
+ throw new Error(`CLEF_KEYSERVICE_PATH must be an absolute path, got '${candidate}'.`);
5108
+ }
5109
+ const segments = candidate.split(/[/\\]/);
5110
+ if (segments.includes("..")) {
5111
+ throw new Error(
5112
+ `CLEF_KEYSERVICE_PATH contains '..' path segments ('${candidate}'). Use an absolute path without directory traversal.`
5113
+ );
5114
+ }
5115
+ }
5116
+ var cached2;
5117
+ function resolveKeyservicePath() {
5118
+ if (cached2) return cached2;
5119
+ const envPath = process.env.CLEF_KEYSERVICE_PATH?.trim();
5120
+ if (envPath) {
5121
+ validateKeyservicePath(envPath);
5122
+ if (!fs15.existsSync(envPath)) {
5123
+ throw new Error(`CLEF_KEYSERVICE_PATH points to '${envPath}' but the file does not exist.`);
5124
+ }
5125
+ cached2 = { path: envPath, source: "env" };
5126
+ return cached2;
5127
+ }
5128
+ const bundledPath = tryBundledKeyservice();
5129
+ if (bundledPath) {
5130
+ cached2 = { path: bundledPath, source: "bundled" };
5131
+ return cached2;
5132
+ }
5133
+ cached2 = { path: "clef-keyservice", source: "system" };
5134
+ return cached2;
5135
+ }
5136
+ function resetKeyserviceResolution() {
5137
+ cached2 = void 0;
5138
+ }
5139
+
5140
+ // src/hsm/keyservice.ts
5141
+ import { spawn } from "child_process";
5142
+ import * as readline from "readline";
5143
+ var PORT_REGEX = /^PORT=(\d+)$/;
5144
+ var STARTUP_TIMEOUT_MS = 5e3;
5145
+ var SHUTDOWN_TIMEOUT_MS = 3e3;
5146
+ async function spawnKeyservice(options) {
5147
+ if (!options.pin && !options.pinFile) {
5148
+ throw new Error(
5149
+ "Keyservice requires a PIN. Set CLEF_PKCS11_PIN, CLEF_PKCS11_PIN_FILE, or .clef/config.yaml pkcs11_pin_file."
5150
+ );
5151
+ }
5152
+ const args = ["--addr", "127.0.0.1:0", "--pkcs11-module", options.modulePath];
5153
+ const childEnv = {
5154
+ ...process.env,
5155
+ ...options.extraEnv ?? {},
5156
+ ...options.pin ? { CLEF_PKCS11_PIN: options.pin } : {},
5157
+ ...options.pinFile ? { CLEF_PKCS11_PIN_FILE: options.pinFile } : {}
5158
+ };
5159
+ const child = spawn(options.binaryPath, args, {
5160
+ stdio: ["ignore", "pipe", "pipe"],
5161
+ env: childEnv
5162
+ });
5163
+ const port = await readPort(child);
5164
+ return {
5165
+ addr: `tcp://127.0.0.1:${port}`,
5166
+ kill: () => killGracefully(child)
5167
+ };
5168
+ }
5169
+ function readPort(child) {
5170
+ return new Promise((resolve, reject) => {
5171
+ let settled = false;
5172
+ if (!child.stdout) {
5173
+ reject(new Error("Keyservice child has no stdout pipe."));
5174
+ return;
5175
+ }
5176
+ const rl = readline.createInterface({ input: child.stdout });
5177
+ const settle = () => {
5178
+ clearTimeout(timer);
5179
+ rl.close();
5180
+ };
5181
+ const timer = setTimeout(() => {
5182
+ if (!settled) {
5183
+ settled = true;
5184
+ settle();
5185
+ child.kill("SIGKILL");
5186
+ reject(
5187
+ new Error(
5188
+ `clef-keyservice did not report a port within ${STARTUP_TIMEOUT_MS}ms. Check that the PKCS#11 module path is valid and the PIN is correct.`
5189
+ )
5190
+ );
5191
+ }
5192
+ }, STARTUP_TIMEOUT_MS);
5193
+ rl.on("line", (line) => {
5194
+ const match = PORT_REGEX.exec(line);
5195
+ if (match && !settled) {
5196
+ settled = true;
5197
+ settle();
5198
+ resolve(parseInt(match[1], 10));
5199
+ }
5200
+ });
5201
+ child.on("error", (err) => {
5202
+ if (!settled) {
5203
+ settled = true;
5204
+ settle();
5205
+ reject(new Error(`Failed to start clef-keyservice: ${err.message}`));
5206
+ }
5207
+ });
5208
+ child.on("exit", (code) => {
5209
+ if (!settled) {
5210
+ settled = true;
5211
+ settle();
5212
+ reject(new Error(`clef-keyservice exited with code ${code} before reporting a port.`));
5213
+ }
5214
+ });
5215
+ });
5216
+ }
5217
+ function killGracefully(child) {
5218
+ return new Promise((resolve) => {
5219
+ if (child.exitCode !== null) {
5220
+ resolve();
5221
+ return;
5222
+ }
5223
+ const timer = setTimeout(() => {
5224
+ child.kill("SIGKILL");
5225
+ }, SHUTDOWN_TIMEOUT_MS);
5226
+ child.on("exit", () => {
5227
+ clearTimeout(timer);
5228
+ resolve();
5229
+ });
5230
+ child.kill("SIGTERM");
5231
+ });
5232
+ }
5233
+
5234
+ // src/lint/runner.ts
5235
+ import * as path14 from "path";
4958
5236
  var LintRunner = class {
4959
5237
  constructor(matrixManager, schemaValidator, sopsClient) {
4960
5238
  this.matrixManager = matrixManager;
4961
5239
  this.schemaValidator = schemaValidator;
4962
5240
  this.sopsClient = sopsClient;
4963
5241
  }
5242
+ matrixManager;
5243
+ schemaValidator;
5244
+ sopsClient;
4964
5245
  /**
4965
5246
  * Lint the entire matrix: check missing files, schema errors, SOPS integrity,
4966
5247
  * single-recipient warnings, and cross-environment key drift.
@@ -5054,7 +5335,7 @@ var LintRunner = class {
5054
5335
  }
5055
5336
  const ns = manifest.namespaces.find((n) => n.name === cell.namespace);
5056
5337
  if (ns?.schema) {
5057
- const schemaPath = path12.join(repoRoot, ns.schema);
5338
+ const schemaPath = path14.join(repoRoot, ns.schema);
5058
5339
  try {
5059
5340
  const schema = this.schemaValidator.loadSchema(schemaPath);
5060
5341
  const result = this.schemaValidator.validate(decrypted.values, schema);
@@ -5341,14 +5622,14 @@ Use 'clef exec' to inject secrets directly into a process, or 'clef export --for
5341
5622
  };
5342
5623
 
5343
5624
  // src/import/index.ts
5344
- import * as path14 from "path";
5625
+ import * as path16 from "path";
5345
5626
 
5346
5627
  // src/import/parsers.ts
5347
- import * as path13 from "path";
5628
+ import * as path15 from "path";
5348
5629
  import * as YAML8 from "yaml";
5349
5630
  function detectFormat(filePath, content) {
5350
- const base = path13.basename(filePath);
5351
- const ext = path13.extname(filePath).toLowerCase();
5631
+ const base = path15.basename(filePath);
5632
+ const ext = path15.extname(filePath).toLowerCase();
5352
5633
  if (base === ".env" || base.startsWith(".env.")) {
5353
5634
  return "dotenv";
5354
5635
  }
@@ -5502,6 +5783,8 @@ var ImportRunner = class {
5502
5783
  this.sopsClient = sopsClient;
5503
5784
  this.tx = tx;
5504
5785
  }
5786
+ sopsClient;
5787
+ tx;
5505
5788
  /**
5506
5789
  * Parse a source file and import its key/value pairs into a target `namespace/environment` cell.
5507
5790
  *
@@ -5514,7 +5797,7 @@ var ImportRunner = class {
5514
5797
  */
5515
5798
  async import(target, sourcePath, content, manifest, repoRoot, options) {
5516
5799
  const [ns, env] = target.split("/");
5517
- const filePath = path14.join(
5800
+ const filePath = path16.join(
5518
5801
  repoRoot,
5519
5802
  manifest.file_pattern.replace("{namespace}", ns).replace("{environment}", env)
5520
5803
  );
@@ -5566,7 +5849,7 @@ var ImportRunner = class {
5566
5849
  if (imported.length === 0) {
5567
5850
  return { imported, skipped, failed, warnings, dryRun: false };
5568
5851
  }
5569
- const relCellPath = path14.relative(repoRoot, filePath);
5852
+ const relCellPath = path16.relative(repoRoot, filePath);
5570
5853
  const relMetaPath = relCellPath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
5571
5854
  await this.tx.run(repoRoot, {
5572
5855
  description: `clef import ${target}: ${imported.length} key(s)`,
@@ -5585,7 +5868,7 @@ var ImportRunner = class {
5585
5868
  };
5586
5869
 
5587
5870
  // src/recipients/index.ts
5588
- import * as path15 from "path";
5871
+ import * as path17 from "path";
5589
5872
  function parseRecipientEntry(entry) {
5590
5873
  if (typeof entry === "string") {
5591
5874
  return { key: entry };
@@ -5658,6 +5941,9 @@ var RecipientManager = class {
5658
5941
  this.matrixManager = matrixManager;
5659
5942
  this.tx = tx;
5660
5943
  }
5944
+ encryption;
5945
+ matrixManager;
5946
+ tx;
5661
5947
  /**
5662
5948
  * List all age recipients declared in the manifest.
5663
5949
  *
@@ -5710,7 +5996,7 @@ var RecipientManager = class {
5710
5996
  const reEncryptedFiles = [];
5711
5997
  await this.tx.run(repoRoot, {
5712
5998
  description: environment ? `clef recipients add ${keyPreview(normalizedKey)} -e ${environment}` : `clef recipients add ${keyPreview(normalizedKey)}`,
5713
- paths: [...cells.map((c) => path15.relative(repoRoot, c.filePath)), CLEF_MANIFEST_FILENAME],
5999
+ paths: [...cells.map((c) => path17.relative(repoRoot, c.filePath)), CLEF_MANIFEST_FILENAME],
5714
6000
  mutate: async () => {
5715
6001
  const doc = readManifestYaml(repoRoot);
5716
6002
  const recipients = environment ? ensureEnvironmentRecipientsArray(doc, environment) : ensureRecipientsArray(doc);
@@ -5769,7 +6055,7 @@ var RecipientManager = class {
5769
6055
  const reEncryptedFiles = [];
5770
6056
  await this.tx.run(repoRoot, {
5771
6057
  description: environment ? `clef recipients remove ${keyPreview(trimmedKey)} -e ${environment}` : `clef recipients remove ${keyPreview(trimmedKey)}`,
5772
- paths: [...cells.map((c) => path15.relative(repoRoot, c.filePath)), CLEF_MANIFEST_FILENAME],
6058
+ paths: [...cells.map((c) => path17.relative(repoRoot, c.filePath)), CLEF_MANIFEST_FILENAME],
5773
6059
  mutate: async () => {
5774
6060
  const doc = readManifestYaml(repoRoot);
5775
6061
  const recipients = environment ? ensureEnvironmentRecipientsArray(doc, environment) : ensureRecipientsArray(doc);
@@ -5798,19 +6084,19 @@ var RecipientManager = class {
5798
6084
  };
5799
6085
 
5800
6086
  // src/recipients/requests.ts
5801
- import * as fs14 from "fs";
5802
- import * as path16 from "path";
6087
+ import * as fs16 from "fs";
6088
+ import * as path18 from "path";
5803
6089
  import * as YAML9 from "yaml";
5804
6090
  var REQUESTS_FILENAME = ".clef-requests.yaml";
5805
6091
  var HEADER_COMMENT2 = "# Pending recipient access requests. Approve with: clef recipients approve <label>\n";
5806
6092
  function requestsFilePath(repoRoot) {
5807
- return path16.join(repoRoot, REQUESTS_FILENAME);
6093
+ return path18.join(repoRoot, REQUESTS_FILENAME);
5808
6094
  }
5809
6095
  function loadRequests(repoRoot) {
5810
6096
  const filePath = requestsFilePath(repoRoot);
5811
6097
  try {
5812
- if (!fs14.existsSync(filePath)) return [];
5813
- const content = fs14.readFileSync(filePath, "utf-8");
6098
+ if (!fs16.existsSync(filePath)) return [];
6099
+ const content = fs16.readFileSync(filePath, "utf-8");
5814
6100
  const parsed = YAML9.parse(content);
5815
6101
  if (!parsed || !Array.isArray(parsed.requests)) return [];
5816
6102
  return parsed.requests.map((r) => ({
@@ -5827,7 +6113,7 @@ function saveRequests(repoRoot, requests) {
5827
6113
  const filePath = requestsFilePath(repoRoot);
5828
6114
  if (requests.length === 0) {
5829
6115
  try {
5830
- fs14.unlinkSync(filePath);
6116
+ fs16.unlinkSync(filePath);
5831
6117
  } catch {
5832
6118
  }
5833
6119
  return;
@@ -5843,7 +6129,7 @@ function saveRequests(repoRoot, requests) {
5843
6129
  return raw;
5844
6130
  })
5845
6131
  };
5846
- fs14.writeFileSync(filePath, HEADER_COMMENT2 + YAML9.stringify(data), "utf-8");
6132
+ fs16.writeFileSync(filePath, HEADER_COMMENT2 + YAML9.stringify(data), "utf-8");
5847
6133
  }
5848
6134
  function upsertRequest(repoRoot, key, label, environment) {
5849
6135
  const requests = loadRequests(repoRoot);
@@ -5879,7 +6165,7 @@ function findInList(requests, identifier) {
5879
6165
  }
5880
6166
 
5881
6167
  // src/drift/detector.ts
5882
- import * as path17 from "path";
6168
+ import * as path19 from "path";
5883
6169
  var DriftDetector = class {
5884
6170
  parser = new ManifestParser();
5885
6171
  matrix = new MatrixManager();
@@ -5892,8 +6178,8 @@ var DriftDetector = class {
5892
6178
  * @returns Drift result with any issues found.
5893
6179
  */
5894
6180
  detect(localRoot, remoteRoot, namespaceFilter) {
5895
- const localManifest = this.parser.parse(path17.join(localRoot, CLEF_MANIFEST_FILENAME));
5896
- const remoteManifest = this.parser.parse(path17.join(remoteRoot, CLEF_MANIFEST_FILENAME));
6181
+ const localManifest = this.parser.parse(path19.join(localRoot, CLEF_MANIFEST_FILENAME));
6182
+ const remoteManifest = this.parser.parse(path19.join(remoteRoot, CLEF_MANIFEST_FILENAME));
5897
6183
  const localCells = this.matrix.resolveMatrix(localManifest, localRoot);
5898
6184
  const remoteCells = this.matrix.resolveMatrix(remoteManifest, remoteRoot);
5899
6185
  const localEnvNames = localManifest.environments.map((e) => e.name);
@@ -5957,7 +6243,7 @@ var DriftDetector = class {
5957
6243
  };
5958
6244
 
5959
6245
  // src/report/generator.ts
5960
- import * as path18 from "path";
6246
+ import * as path20 from "path";
5961
6247
 
5962
6248
  // src/report/sanitizer.ts
5963
6249
  var ReportSanitizer = class {
@@ -6100,6 +6386,10 @@ var ReportGenerator = class {
6100
6386
  this.matrixManager = matrixManager;
6101
6387
  this.schemaValidator = schemaValidator;
6102
6388
  }
6389
+ runner;
6390
+ sopsClient;
6391
+ matrixManager;
6392
+ schemaValidator;
6103
6393
  /**
6104
6394
  * Generate a full {@link ClefReport} for the given repository root.
6105
6395
  * Each section gathers data independently — partial failures return empty
@@ -6113,7 +6403,7 @@ var ReportGenerator = class {
6113
6403
  let manifest = null;
6114
6404
  try {
6115
6405
  const parser = new ManifestParser();
6116
- manifest = parser.parse(path18.join(repoRoot, "clef.yaml"));
6406
+ manifest = parser.parse(path20.join(repoRoot, "clef.yaml"));
6117
6407
  } catch {
6118
6408
  const emptyManifest = {
6119
6409
  manifestVersion: 0,
@@ -6511,6 +6801,7 @@ var SopsMergeDriver = class {
6511
6801
  constructor(sopsClient) {
6512
6802
  this.sopsClient = sopsClient;
6513
6803
  }
6804
+ sopsClient;
6514
6805
  /**
6515
6806
  * Perform a three-way merge on three in-memory key/value maps.
6516
6807
  *
@@ -6591,7 +6882,7 @@ var SopsMergeDriver = class {
6591
6882
  };
6592
6883
 
6593
6884
  // src/merge/metadata-driver.ts
6594
- import * as fs15 from "fs";
6885
+ import * as fs17 from "fs";
6595
6886
  import * as YAML10 from "yaml";
6596
6887
  var HEADER_COMMENT3 = "# Managed by Clef. Do not edit manually.\n";
6597
6888
  function parseMetadata(content) {
@@ -6694,26 +6985,29 @@ function mergeMetadataContents(oursContent, theirsContent) {
6694
6985
  return serializeMetadata({ version: 1, pending, rotations });
6695
6986
  }
6696
6987
  function mergeMetadataFiles(_basePath, oursPath, theirsPath) {
6697
- const oursContent = fs15.existsSync(oursPath) ? fs15.readFileSync(oursPath, "utf-8") : "";
6698
- const theirsContent = fs15.existsSync(theirsPath) ? fs15.readFileSync(theirsPath, "utf-8") : "";
6988
+ const oursContent = fs17.existsSync(oursPath) ? fs17.readFileSync(oursPath, "utf-8") : "";
6989
+ const theirsContent = fs17.existsSync(theirsPath) ? fs17.readFileSync(theirsPath, "utf-8") : "";
6699
6990
  const merged = mergeMetadataContents(oursContent, theirsContent);
6700
- fs15.writeFileSync(oursPath, merged, "utf-8");
6991
+ fs17.writeFileSync(oursPath, merged, "utf-8");
6701
6992
  }
6702
6993
 
6703
6994
  // src/service-identity/manager.ts
6704
- import * as path19 from "path";
6995
+ import * as path21 from "path";
6705
6996
  var ServiceIdentityManager = class {
6706
6997
  constructor(encryption, matrixManager, tx) {
6707
6998
  this.encryption = encryption;
6708
6999
  this.matrixManager = matrixManager;
6709
7000
  this.tx = tx;
6710
7001
  }
7002
+ encryption;
7003
+ matrixManager;
7004
+ tx;
6711
7005
  /**
6712
7006
  * Compute repo-relative paths for a set of cells plus the manifest. Used
6713
7007
  * to seed TransactionManager.run's `paths` argument.
6714
7008
  */
6715
7009
  txPaths(repoRoot, cells) {
6716
- return [...cells.map((c) => path19.relative(repoRoot, c.filePath)), CLEF_MANIFEST_FILENAME];
7010
+ return [...cells.map((c) => path21.relative(repoRoot, c.filePath)), CLEF_MANIFEST_FILENAME];
6717
7011
  }
6718
7012
  /**
6719
7013
  * Create a new service identity with per-environment age key pairs or KMS envelope config.
@@ -7235,14 +7529,17 @@ var ServiceIdentityManager = class {
7235
7529
  };
7236
7530
 
7237
7531
  // src/structure/manager.ts
7238
- import * as fs16 from "fs";
7239
- import * as path20 from "path";
7532
+ import * as fs18 from "fs";
7533
+ import * as path22 from "path";
7240
7534
  var StructureManager = class {
7241
7535
  constructor(matrixManager, encryption, tx) {
7242
7536
  this.matrixManager = matrixManager;
7243
7537
  this.encryption = encryption;
7244
7538
  this.tx = tx;
7245
7539
  }
7540
+ matrixManager;
7541
+ encryption;
7542
+ tx;
7246
7543
  // ── add ──────────────────────────────────────────────────────────────────
7247
7544
  /**
7248
7545
  * Add a new namespace to the manifest and scaffold an empty encrypted cell
@@ -7257,15 +7554,15 @@ var StructureManager = class {
7257
7554
  this.assertValidIdentifier("namespace", name);
7258
7555
  const newCellPaths = manifest.environments.map((env) => ({
7259
7556
  environment: env.name,
7260
- filePath: path20.join(
7557
+ filePath: path22.join(
7261
7558
  repoRoot,
7262
7559
  manifest.file_pattern.replace("{namespace}", name).replace("{environment}", env.name)
7263
7560
  )
7264
7561
  }));
7265
7562
  for (const cell of newCellPaths) {
7266
- if (fs16.existsSync(cell.filePath)) {
7563
+ if (fs18.existsSync(cell.filePath)) {
7267
7564
  throw new Error(
7268
- `Cannot add namespace '${name}': file '${path20.relative(repoRoot, cell.filePath)}' already exists.`
7565
+ `Cannot add namespace '${name}': file '${path22.relative(repoRoot, cell.filePath)}' already exists.`
7269
7566
  );
7270
7567
  }
7271
7568
  }
@@ -7284,7 +7581,7 @@ var StructureManager = class {
7284
7581
  await this.tx.run(repoRoot, {
7285
7582
  description: `clef namespace add ${name}`,
7286
7583
  paths: [
7287
- ...newCellPaths.map((c) => path20.relative(repoRoot, c.filePath)),
7584
+ ...newCellPaths.map((c) => path22.relative(repoRoot, c.filePath)),
7288
7585
  CLEF_MANIFEST_FILENAME
7289
7586
  ],
7290
7587
  mutate: async () => {
@@ -7329,15 +7626,15 @@ var StructureManager = class {
7329
7626
  this.assertValidIdentifier("environment", name);
7330
7627
  const newCellPaths = manifest.namespaces.map((ns) => ({
7331
7628
  namespace: ns.name,
7332
- filePath: path20.join(
7629
+ filePath: path22.join(
7333
7630
  repoRoot,
7334
7631
  manifest.file_pattern.replace("{namespace}", ns.name).replace("{environment}", name)
7335
7632
  )
7336
7633
  }));
7337
7634
  for (const cell of newCellPaths) {
7338
- if (fs16.existsSync(cell.filePath)) {
7635
+ if (fs18.existsSync(cell.filePath)) {
7339
7636
  throw new Error(
7340
- `Cannot add environment '${name}': file '${path20.relative(repoRoot, cell.filePath)}' already exists.`
7637
+ `Cannot add environment '${name}': file '${path22.relative(repoRoot, cell.filePath)}' already exists.`
7341
7638
  );
7342
7639
  }
7343
7640
  }
@@ -7356,7 +7653,7 @@ var StructureManager = class {
7356
7653
  await this.tx.run(repoRoot, {
7357
7654
  description: `clef env add ${name}`,
7358
7655
  paths: [
7359
- ...newCellPaths.map((c) => path20.relative(repoRoot, c.filePath)),
7656
+ ...newCellPaths.map((c) => path22.relative(repoRoot, c.filePath)),
7360
7657
  CLEF_MANIFEST_FILENAME
7361
7658
  ],
7362
7659
  mutate: async () => {
@@ -7419,7 +7716,7 @@ var StructureManager = class {
7419
7716
  paths: this.deletePaths(repoRoot, cellsToDelete),
7420
7717
  mutate: async () => {
7421
7718
  for (const cell of cellsToDelete) {
7422
- fs16.unlinkSync(cell.filePath);
7719
+ fs18.unlinkSync(cell.filePath);
7423
7720
  this.unlinkMetaSibling(cell.filePath);
7424
7721
  }
7425
7722
  const doc = readManifestYaml(repoRoot);
@@ -7469,7 +7766,7 @@ var StructureManager = class {
7469
7766
  paths: this.deletePaths(repoRoot, cellsToDelete),
7470
7767
  mutate: async () => {
7471
7768
  for (const cell of cellsToDelete) {
7472
- fs16.unlinkSync(cell.filePath);
7769
+ fs18.unlinkSync(cell.filePath);
7473
7770
  this.unlinkMetaSibling(cell.filePath);
7474
7771
  }
7475
7772
  const doc = readManifestYaml(repoRoot);
@@ -7511,9 +7808,9 @@ var StructureManager = class {
7511
7808
  const renamePairs = isRename ? this.collectRenamePairs(manifest, repoRoot, name, opts.rename, "namespace") : [];
7512
7809
  if (isRename) {
7513
7810
  for (const pair of renamePairs) {
7514
- if (fs16.existsSync(pair.to)) {
7811
+ if (fs18.existsSync(pair.to)) {
7515
7812
  throw new Error(
7516
- `Rename target '${path20.relative(repoRoot, pair.to)}' already exists. Move or remove it first.`
7813
+ `Rename target '${path22.relative(repoRoot, pair.to)}' already exists. Move or remove it first.`
7517
7814
  );
7518
7815
  }
7519
7816
  }
@@ -7554,9 +7851,9 @@ var StructureManager = class {
7554
7851
  const renamePairs = isRename ? this.collectRenamePairs(manifest, repoRoot, name, opts.rename, "environment") : [];
7555
7852
  if (isRename) {
7556
7853
  for (const pair of renamePairs) {
7557
- if (fs16.existsSync(pair.to)) {
7854
+ if (fs18.existsSync(pair.to)) {
7558
7855
  throw new Error(
7559
- `Rename target '${path20.relative(repoRoot, pair.to)}' already exists. Move or remove it first.`
7856
+ `Rename target '${path22.relative(repoRoot, pair.to)}' already exists. Move or remove it first.`
7560
7857
  );
7561
7858
  }
7562
7859
  }
@@ -7591,7 +7888,7 @@ var StructureManager = class {
7591
7888
  const newCellPath = this.swapAxisInCellPath(repoRoot, manifest, cell, axis, newName);
7592
7889
  pairs.push({ from: cell.filePath, to: newCellPath });
7593
7890
  const oldMeta = cell.filePath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
7594
- if (fs16.existsSync(oldMeta)) {
7891
+ if (fs18.existsSync(oldMeta)) {
7595
7892
  const newMeta = newCellPath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
7596
7893
  pairs.push({ from: oldMeta, to: newMeta });
7597
7894
  }
@@ -7606,7 +7903,7 @@ var StructureManager = class {
7606
7903
  swapAxisInCellPath(repoRoot, manifest, cell, axis, newName) {
7607
7904
  const ns = axis === "namespace" ? newName : cell.namespace;
7608
7905
  const env = axis === "environment" ? newName : cell.environment;
7609
- return path20.join(
7906
+ return path22.join(
7610
7907
  repoRoot,
7611
7908
  manifest.file_pattern.replace("{namespace}", ns).replace("{environment}", env)
7612
7909
  );
@@ -7618,8 +7915,8 @@ var StructureManager = class {
7618
7915
  txPaths(repoRoot, renamePairs) {
7619
7916
  const paths = /* @__PURE__ */ new Set();
7620
7917
  for (const pair of renamePairs) {
7621
- paths.add(path20.relative(repoRoot, pair.from));
7622
- paths.add(path20.relative(repoRoot, pair.to));
7918
+ paths.add(path22.relative(repoRoot, pair.from));
7919
+ paths.add(path22.relative(repoRoot, pair.to));
7623
7920
  }
7624
7921
  paths.add(CLEF_MANIFEST_FILENAME);
7625
7922
  return [...paths];
@@ -7630,11 +7927,11 @@ var StructureManager = class {
7630
7927
  */
7631
7928
  applyRenames(pairs) {
7632
7929
  for (const pair of pairs) {
7633
- const targetDir = path20.dirname(pair.to);
7634
- if (!fs16.existsSync(targetDir)) {
7635
- fs16.mkdirSync(targetDir, { recursive: true });
7930
+ const targetDir = path22.dirname(pair.to);
7931
+ if (!fs18.existsSync(targetDir)) {
7932
+ fs18.mkdirSync(targetDir, { recursive: true });
7636
7933
  }
7637
- fs16.renameSync(pair.from, pair.to);
7934
+ fs18.renameSync(pair.from, pair.to);
7638
7935
  }
7639
7936
  }
7640
7937
  /**
@@ -7645,10 +7942,10 @@ var StructureManager = class {
7645
7942
  deletePaths(repoRoot, cells) {
7646
7943
  const paths = /* @__PURE__ */ new Set();
7647
7944
  for (const cell of cells) {
7648
- paths.add(path20.relative(repoRoot, cell.filePath));
7945
+ paths.add(path22.relative(repoRoot, cell.filePath));
7649
7946
  const meta = cell.filePath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
7650
- if (fs16.existsSync(meta)) {
7651
- paths.add(path20.relative(repoRoot, meta));
7947
+ if (fs18.existsSync(meta)) {
7948
+ paths.add(path22.relative(repoRoot, meta));
7652
7949
  }
7653
7950
  }
7654
7951
  paths.add(CLEF_MANIFEST_FILENAME);
@@ -7661,8 +7958,8 @@ var StructureManager = class {
7661
7958
  */
7662
7959
  unlinkMetaSibling(cellPath) {
7663
7960
  const meta = cellPath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
7664
- if (fs16.existsSync(meta)) {
7665
- fs16.unlinkSync(meta);
7961
+ if (fs18.existsSync(meta)) {
7962
+ fs18.unlinkSync(meta);
7666
7963
  }
7667
7964
  }
7668
7965
  /**
@@ -7807,20 +8104,21 @@ async function resolveIdentitySecrets(identityName, environment, manifest, repoR
7807
8104
  import * as crypto3 from "crypto";
7808
8105
 
7809
8106
  // src/artifact/output.ts
7810
- import * as fs17 from "fs";
7811
- import * as path21 from "path";
8107
+ import * as fs19 from "fs";
8108
+ import * as path23 from "path";
7812
8109
  var FilePackOutput = class {
7813
8110
  constructor(outputPath) {
7814
8111
  this.outputPath = outputPath;
7815
8112
  }
8113
+ outputPath;
7816
8114
  async write(_artifact, json) {
7817
- const outputDir = path21.dirname(this.outputPath);
7818
- if (!fs17.existsSync(outputDir)) {
7819
- fs17.mkdirSync(outputDir, { recursive: true });
8115
+ const outputDir = path23.dirname(this.outputPath);
8116
+ if (!fs19.existsSync(outputDir)) {
8117
+ fs19.mkdirSync(outputDir, { recursive: true });
7820
8118
  }
7821
8119
  const tmpOutput = `${this.outputPath}.tmp.${process.pid}`;
7822
- fs17.writeFileSync(tmpOutput, json, "utf-8");
7823
- fs17.renameSync(tmpOutput, this.outputPath);
8120
+ fs19.writeFileSync(tmpOutput, json, "utf-8");
8121
+ fs19.renameSync(tmpOutput, this.outputPath);
7824
8122
  }
7825
8123
  };
7826
8124
  var MemoryPackOutput = class {
@@ -7926,6 +8224,9 @@ var ArtifactPacker = class {
7926
8224
  this.matrixManager = matrixManager;
7927
8225
  this.kms = kms;
7928
8226
  }
8227
+ encryption;
8228
+ matrixManager;
8229
+ kms;
7929
8230
  /**
7930
8231
  * Pack an artifact: decrypt scoped SOPS files, age-encrypt the merged
7931
8232
  * values to the service identity's recipient, and write a JSON envelope.
@@ -8027,28 +8328,187 @@ var ArtifactPacker = class {
8027
8328
  const json = JSON.stringify(artifact, null, 2);
8028
8329
  const output = config.output ?? new FilePackOutput(config.outputPath ?? "artifact.json");
8029
8330
  await output.write(artifact, json);
8331
+ const keys = Object.keys(resolved.values);
8030
8332
  return {
8031
8333
  outputPath: config.outputPath ?? "",
8032
8334
  namespaceCount: resolved.identity.namespaces.length,
8033
- keyCount: Object.keys(resolved.values).length,
8335
+ keyCount: keys.length,
8336
+ keys,
8034
8337
  artifactSize: Buffer.byteLength(json, "utf-8"),
8035
8338
  revision: artifact.revision
8036
8339
  };
8037
8340
  }
8038
8341
  };
8039
8342
 
8343
+ // src/artifact/guards.ts
8344
+ var InvalidArtifactError = class extends ClefError {
8345
+ constructor(message) {
8346
+ super(
8347
+ message,
8348
+ "Ensure the artifact was produced by a compatible clef version and was not tampered with."
8349
+ );
8350
+ this.name = "InvalidArtifactError";
8351
+ }
8352
+ };
8353
+ var VALID_SIGNATURE_ALGORITHMS = ["Ed25519", "ECDSA_SHA256"];
8354
+ function isKmsEnvelope2(x) {
8355
+ if (typeof x !== "object" || x === null) return false;
8356
+ const o = x;
8357
+ return typeof o.provider === "string" && typeof o.keyId === "string" && typeof o.wrappedKey === "string" && typeof o.algorithm === "string" && typeof o.iv === "string" && typeof o.authTag === "string";
8358
+ }
8359
+ function validatePackedArtifact(x) {
8360
+ if (typeof x !== "object" || x === null) {
8361
+ return { valid: false, reason: "expected object" };
8362
+ }
8363
+ const o = x;
8364
+ if (o.version !== 1) {
8365
+ return { valid: false, reason: `unsupported version: ${String(o.version)}` };
8366
+ }
8367
+ if (typeof o.identity !== "string") {
8368
+ return { valid: false, reason: "missing or invalid 'identity' (expected string)" };
8369
+ }
8370
+ if (typeof o.environment !== "string") {
8371
+ return { valid: false, reason: "missing or invalid 'environment' (expected string)" };
8372
+ }
8373
+ if (typeof o.packedAt !== "string") {
8374
+ return { valid: false, reason: "missing or invalid 'packedAt' (expected string)" };
8375
+ }
8376
+ if (typeof o.revision !== "string") {
8377
+ return { valid: false, reason: "missing or invalid 'revision' (expected string)" };
8378
+ }
8379
+ if (typeof o.ciphertextHash !== "string") {
8380
+ return { valid: false, reason: "missing or invalid 'ciphertextHash' (expected string)" };
8381
+ }
8382
+ if (typeof o.ciphertext !== "string") {
8383
+ return { valid: false, reason: "missing or invalid 'ciphertext' (expected string)" };
8384
+ }
8385
+ if (o.envelope !== void 0 && !isKmsEnvelope2(o.envelope)) {
8386
+ return { valid: false, reason: "invalid 'envelope' (expected KmsEnvelope shape)" };
8387
+ }
8388
+ if (o.expiresAt !== void 0 && typeof o.expiresAt !== "string") {
8389
+ return { valid: false, reason: "invalid 'expiresAt' (expected string)" };
8390
+ }
8391
+ if (o.revokedAt !== void 0 && typeof o.revokedAt !== "string") {
8392
+ return { valid: false, reason: "invalid 'revokedAt' (expected string)" };
8393
+ }
8394
+ if (o.signature !== void 0 && typeof o.signature !== "string") {
8395
+ return { valid: false, reason: "invalid 'signature' (expected string)" };
8396
+ }
8397
+ if (o.signatureAlgorithm !== void 0 && !VALID_SIGNATURE_ALGORITHMS.includes(o.signatureAlgorithm)) {
8398
+ return {
8399
+ valid: false,
8400
+ reason: `invalid 'signatureAlgorithm': expected one of ${VALID_SIGNATURE_ALGORITHMS.join(", ")}`
8401
+ };
8402
+ }
8403
+ return { valid: true, value: o };
8404
+ }
8405
+ function isPackedArtifact(x) {
8406
+ return validatePackedArtifact(x).valid;
8407
+ }
8408
+ function assertPackedArtifact(x, context) {
8409
+ const result = validatePackedArtifact(x);
8410
+ if (!result.valid) {
8411
+ const prefix = context ? `${context}: ` : "";
8412
+ throw new InvalidArtifactError(`${prefix}${result.reason}`);
8413
+ }
8414
+ }
8415
+
8416
+ // src/pack/registry.ts
8417
+ var PackBackendRegistry = class {
8418
+ factories = /* @__PURE__ */ new Map();
8419
+ /**
8420
+ * Register a backend factory under the given id. Throws if a backend
8421
+ * with the same id is already registered — collisions surface as a clear
8422
+ * error rather than a silent overwrite.
8423
+ */
8424
+ register(id, factory) {
8425
+ if (this.factories.has(id)) {
8426
+ throw new Error(`Pack backend "${id}" is already registered.`);
8427
+ }
8428
+ this.factories.set(id, factory);
8429
+ }
8430
+ /** Whether a backend with the given id has been registered. */
8431
+ has(id) {
8432
+ return this.factories.has(id);
8433
+ }
8434
+ /** Registered backend ids, in registration order. */
8435
+ list() {
8436
+ return [...this.factories.keys()];
8437
+ }
8438
+ /**
8439
+ * Resolve a backend by id. Throws if unknown. Factories may be async so
8440
+ * a plugin package can defer construction (e.g. loading a heavy SDK only
8441
+ * when the backend is actually used).
8442
+ */
8443
+ async resolve(id) {
8444
+ const factory = this.factories.get(id);
8445
+ if (!factory) {
8446
+ const available = this.list().join(", ") || "(none)";
8447
+ throw new Error(`Unknown pack backend "${id}". Available backends: ${available}`);
8448
+ }
8449
+ return await factory();
8450
+ }
8451
+ };
8452
+
8453
+ // src/pack/backends/json-envelope.ts
8454
+ var JsonEnvelopeBackend = class {
8455
+ id = "json-envelope";
8456
+ description = "Write the Clef JSON artifact envelope to a local file (default).";
8457
+ validateOptions(raw) {
8458
+ const opts = raw;
8459
+ if (opts.signingKey && opts.signingKmsKeyId) {
8460
+ throw new Error(
8461
+ "Cannot specify both signingKey (Ed25519) and signingKmsKeyId (KMS). Choose one."
8462
+ );
8463
+ }
8464
+ if (!opts.outputPath && !opts.output) {
8465
+ throw new Error("json-envelope backend requires an 'outputPath' or 'output' option.");
8466
+ }
8467
+ }
8468
+ async pack(req) {
8469
+ const opts = req.backendOptions;
8470
+ const packer = new ArtifactPacker(
8471
+ req.services.encryption,
8472
+ new MatrixManager(),
8473
+ req.services.kms
8474
+ );
8475
+ const output = opts.output ?? (opts.outputPath ? new FilePackOutput(opts.outputPath) : void 0);
8476
+ const result = await packer.pack(
8477
+ {
8478
+ identity: req.identity,
8479
+ environment: req.environment,
8480
+ outputPath: opts.outputPath,
8481
+ output,
8482
+ ttl: req.ttl,
8483
+ signingKey: opts.signingKey,
8484
+ signingKmsKeyId: opts.signingKmsKeyId
8485
+ },
8486
+ req.manifest,
8487
+ req.repoRoot
8488
+ );
8489
+ return {
8490
+ ...result,
8491
+ backend: this.id,
8492
+ details: {
8493
+ outputPath: opts.outputPath ?? null
8494
+ }
8495
+ };
8496
+ }
8497
+ };
8498
+
8040
8499
  // src/kms/types.ts
8041
8500
  var VALID_KMS_PROVIDERS = ["aws", "gcp", "azure"];
8042
8501
 
8043
8502
  // src/migration/backend.ts
8044
- import * as path22 from "path";
8503
+ import * as path24 from "path";
8045
8504
  import * as YAML11 from "yaml";
8046
8505
  var BACKEND_KEY_FIELDS = {
8047
8506
  age: void 0,
8048
8507
  awskms: "aws_kms_arn",
8049
8508
  gcpkms: "gcp_kms_resource_id",
8050
8509
  azurekv: "azure_kv_url",
8051
- pgp: "pgp_fingerprint"
8510
+ pgp: "pgp_fingerprint",
8511
+ hsm: "pkcs11_uri"
8052
8512
  };
8053
8513
  var ALL_KEY_FIELDS = Object.values(BACKEND_KEY_FIELDS).filter(
8054
8514
  (v) => v !== void 0
@@ -8081,6 +8541,8 @@ var BackendMigrator = class {
8081
8541
  this.decryptBackend = encryption;
8082
8542
  this.encryptBackend = targetEncryption ?? encryption;
8083
8543
  }
8544
+ matrixManager;
8545
+ tx;
8084
8546
  decryptBackend;
8085
8547
  encryptBackend;
8086
8548
  async migrate(manifest, repoRoot, options, onProgress) {
@@ -8158,7 +8620,7 @@ var BackendMigrator = class {
8158
8620
  await this.tx.run(repoRoot, {
8159
8621
  description: environment ? `clef migrate-backend ${target.backend}: ${environment}` : `clef migrate-backend ${target.backend}`,
8160
8622
  paths: [
8161
- ...toMigrate.map((c) => path22.relative(repoRoot, c.filePath)),
8623
+ ...toMigrate.map((c) => path24.relative(repoRoot, c.filePath)),
8162
8624
  CLEF_MANIFEST_FILENAME
8163
8625
  ],
8164
8626
  mutate: async () => {
@@ -8256,7 +8718,7 @@ var BackendMigrator = class {
8256
8718
  };
8257
8719
 
8258
8720
  // src/reset/manager.ts
8259
- import * as path23 from "path";
8721
+ import * as path25 from "path";
8260
8722
  var ResetManager = class {
8261
8723
  constructor(matrixManager, encryption, schemaValidator, tx) {
8262
8724
  this.matrixManager = matrixManager;
@@ -8264,6 +8726,10 @@ var ResetManager = class {
8264
8726
  this.schemaValidator = schemaValidator;
8265
8727
  this.tx = tx;
8266
8728
  }
8729
+ matrixManager;
8730
+ encryption;
8731
+ schemaValidator;
8732
+ tx;
8267
8733
  async reset(opts, manifest, repoRoot) {
8268
8734
  validateResetScope(opts.scope, manifest);
8269
8735
  validateBackendKeyCombination(opts.backend, opts.key);
@@ -8281,11 +8747,11 @@ var ResetManager = class {
8281
8747
  txPaths.push(CLEF_MANIFEST_FILENAME);
8282
8748
  }
8283
8749
  for (const cell of targetCells) {
8284
- txPaths.push(path23.relative(repoRoot, cell.filePath));
8750
+ txPaths.push(path25.relative(repoRoot, cell.filePath));
8285
8751
  const cellKeys = keyPlan.get(cell.namespace) ?? [];
8286
8752
  if (cellKeys.length > 0) {
8287
8753
  txPaths.push(
8288
- path23.relative(repoRoot, cell.filePath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml"))
8754
+ path25.relative(repoRoot, cell.filePath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml"))
8289
8755
  );
8290
8756
  }
8291
8757
  }
@@ -8373,7 +8839,7 @@ var ResetManager = class {
8373
8839
  for (const namespace of namespaces) {
8374
8840
  const nsDef = manifest.namespaces.find((n) => n.name === namespace);
8375
8841
  if (nsDef?.schema) {
8376
- const schema = this.schemaValidator.loadSchema(path23.join(repoRoot, nsDef.schema));
8842
+ const schema = this.schemaValidator.loadSchema(path25.join(repoRoot, nsDef.schema));
8377
8843
  plan.set(namespace, Object.keys(schema.keys));
8378
8844
  continue;
8379
8845
  }
@@ -8452,13 +8918,16 @@ function withBackendOverride(manifest, envNames, backend, key) {
8452
8918
  }
8453
8919
 
8454
8920
  // src/sync/manager.ts
8455
- import * as path24 from "path";
8921
+ import * as path26 from "path";
8456
8922
  var SyncManager = class {
8457
8923
  constructor(matrixManager, encryption, tx) {
8458
8924
  this.matrixManager = matrixManager;
8459
8925
  this.encryption = encryption;
8460
8926
  this.tx = tx;
8461
8927
  }
8928
+ matrixManager;
8929
+ encryption;
8930
+ tx;
8462
8931
  /**
8463
8932
  * Compute what sync would do without mutating anything.
8464
8933
  */
@@ -8521,7 +8990,7 @@ var SyncManager = class {
8521
8990
  }
8522
8991
  const txPaths = [];
8523
8992
  for (const cell of syncPlan.cells) {
8524
- const rel = path24.relative(repoRoot, cell.filePath);
8993
+ const rel = path26.relative(repoRoot, cell.filePath);
8525
8994
  txPaths.push(rel);
8526
8995
  txPaths.push(rel.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml"));
8527
8996
  }
@@ -8560,7 +9029,7 @@ var SyncManager = class {
8560
9029
  };
8561
9030
 
8562
9031
  // src/policy/parser.ts
8563
- import * as fs18 from "fs";
9032
+ import * as fs20 from "fs";
8564
9033
  import * as YAML12 from "yaml";
8565
9034
 
8566
9035
  // src/policy/types.ts
@@ -8582,7 +9051,7 @@ var PolicyParser = class {
8582
9051
  parse(filePath) {
8583
9052
  let raw;
8584
9053
  try {
8585
- raw = fs18.readFileSync(filePath, "utf-8");
9054
+ raw = fs20.readFileSync(filePath, "utf-8");
8586
9055
  } catch {
8587
9056
  throw new PolicyValidationError(`Could not read policy file at '${filePath}'.`);
8588
9057
  }
@@ -8610,7 +9079,7 @@ var PolicyParser = class {
8610
9079
  * not exist. Any other read or validation error throws.
8611
9080
  */
8612
9081
  load(filePath) {
8613
- if (!fs18.existsSync(filePath)) return DEFAULT_POLICY;
9082
+ if (!fs20.existsSync(filePath)) return DEFAULT_POLICY;
8614
9083
  return this.parse(filePath);
8615
9084
  }
8616
9085
  validate(raw) {
@@ -8677,6 +9146,7 @@ var PolicyEvaluator = class {
8677
9146
  constructor(policy) {
8678
9147
  this.policy = policy;
8679
9148
  }
9149
+ policy;
8680
9150
  /**
8681
9151
  * Evaluate a single encrypted file's per-key rotation state.
8682
9152
  *
@@ -8803,13 +9273,13 @@ var ComplianceGenerator = class {
8803
9273
  };
8804
9274
 
8805
9275
  // src/compliance/run.ts
8806
- import * as path25 from "path";
9276
+ import * as path27 from "path";
8807
9277
  var UNKNOWN = "unknown";
8808
9278
  async function runCompliance(opts) {
8809
9279
  const start = Date.now();
8810
9280
  const repoRoot = opts.repoRoot ?? process.cwd();
8811
- const manifestPath = opts.manifestPath ?? path25.join(repoRoot, "clef.yaml");
8812
- const policyPath = opts.policyPath ?? path25.join(repoRoot, CLEF_POLICY_FILENAME);
9281
+ const manifestPath = opts.manifestPath ?? path27.join(repoRoot, "clef.yaml");
9282
+ const policyPath = opts.policyPath ?? path27.join(repoRoot, CLEF_POLICY_FILENAME);
8813
9283
  const include = {
8814
9284
  scan: opts.include?.scan ?? true,
8815
9285
  lint: opts.include?.lint ?? true,
@@ -8855,7 +9325,7 @@ async function evaluateMatrix(args) {
8855
9325
  return Promise.all(
8856
9326
  cells.map(async (cell) => {
8857
9327
  const metadata = await args.sopsClient.getMetadata(cell.filePath);
8858
- const relPath = path25.relative(args.repoRoot, cell.filePath).replace(/\\/g, "/");
9328
+ const relPath = path27.relative(args.repoRoot, cell.filePath).replace(/\\/g, "/");
8859
9329
  const keys = readSopsKeyNames(cell.filePath) ?? [];
8860
9330
  const rotations = await getRotations(cell.filePath);
8861
9331
  return evaluator.evaluateFile(relPath, cell.environment, metadata, keys, rotations, args.now);
@@ -8933,11 +9403,14 @@ export {
8933
9403
  GitIntegration,
8934
9404
  GitOperationError,
8935
9405
  ImportRunner,
9406
+ InvalidArtifactError,
9407
+ JsonEnvelopeBackend,
8936
9408
  LintRunner,
8937
9409
  ManifestParser,
8938
9410
  ManifestValidationError,
8939
9411
  MatrixManager,
8940
9412
  MemoryPackOutput,
9413
+ PackBackendRegistry,
8941
9414
  PolicyEvaluator,
8942
9415
  PolicyParser,
8943
9416
  PolicyValidationError,
@@ -8966,6 +9439,7 @@ export {
8966
9439
  TransactionPreflightError,
8967
9440
  TransactionRollbackError,
8968
9441
  VALID_KMS_PROVIDERS,
9442
+ assertPackedArtifact,
8969
9443
  assertSops,
8970
9444
  buildSigningPayload,
8971
9445
  checkAll,
@@ -8982,8 +9456,10 @@ export {
8982
9456
  generateSigningKeyPair,
8983
9457
  getPendingKeys,
8984
9458
  getRotations,
9459
+ isClefHsmArn,
8985
9460
  isHighEntropy,
8986
9461
  isKmsEnvelope,
9462
+ isPackedArtifact,
8987
9463
  isPending,
8988
9464
  keyPreview,
8989
9465
  loadIgnoreRules,
@@ -9001,15 +9477,18 @@ export {
9001
9477
  parseIgnoreContent,
9002
9478
  parseJson,
9003
9479
  parseYaml,
9480
+ pkcs11UriToSyntheticArn,
9004
9481
  readManifestYaml,
9005
9482
  recordRotation,
9006
9483
  redactValue,
9007
9484
  removeRequest as removeAccessRequest,
9008
9485
  removeRotation,
9009
9486
  requestsFilePath,
9487
+ resetKeyserviceResolution,
9010
9488
  resetSopsResolution,
9011
9489
  resolveBackendConfig,
9012
9490
  resolveIdentitySecrets,
9491
+ resolveKeyservicePath,
9013
9492
  resolveRecipientsForEnvironment,
9014
9493
  resolveSopsPath,
9015
9494
  runCompliance,
@@ -9020,8 +9499,12 @@ export {
9020
9499
  shouldIgnoreMatch,
9021
9500
  signEd25519,
9022
9501
  signKms,
9502
+ spawnKeyservice,
9503
+ syntheticArnToPkcs11Uri,
9504
+ tryBundledKeyservice,
9023
9505
  upsertRequest,
9024
9506
  validateAgePublicKey,
9507
+ validatePackedArtifact,
9025
9508
  validateResetScope,
9026
9509
  verifySignature,
9027
9510
  writeManifestYaml,