@clef-sh/core 0.1.18 → 0.1.19

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
@@ -304,10 +304,10 @@ var require_lib = __commonJS({
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) {
@@ -2254,7 +2255,8 @@ function keyPreview(key) {
2254
2255
 
2255
2256
  // src/manifest/parser.ts
2256
2257
  var CLEF_MANIFEST_FILENAME = "clef.yaml";
2257
- var VALID_BACKENDS = ["age", "awskms", "gcpkms", "azurekv", "pgp"];
2258
+ var VALID_BACKENDS = ["age", "awskms", "gcpkms", "azurekv", "pgp", "hsm"];
2259
+ var PKCS11_URI_PATTERN = /^pkcs11:[a-zA-Z][a-zA-Z0-9_-]*=[^;]+/;
2258
2260
  var VALID_TOP_LEVEL_KEYS = [
2259
2261
  "version",
2260
2262
  "environments",
@@ -2413,12 +2415,27 @@ var ManifestParser = class {
2413
2415
  "environments"
2414
2416
  );
2415
2417
  }
2418
+ if (backend === "hsm") {
2419
+ if (typeof sopsOverride.pkcs11_uri !== "string") {
2420
+ throw new ManifestValidationError(
2421
+ `Environment '${envObj.name}' uses 'hsm' backend but is missing 'pkcs11_uri'.`,
2422
+ "environments"
2423
+ );
2424
+ }
2425
+ if (!PKCS11_URI_PATTERN.test(sopsOverride.pkcs11_uri)) {
2426
+ throw new ManifestValidationError(
2427
+ `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').`,
2428
+ "environments"
2429
+ );
2430
+ }
2431
+ }
2416
2432
  result.sops = {
2417
2433
  backend,
2418
2434
  ...typeof sopsOverride.aws_kms_arn === "string" ? { aws_kms_arn: sopsOverride.aws_kms_arn } : {},
2419
2435
  ...typeof sopsOverride.gcp_kms_resource_id === "string" ? { gcp_kms_resource_id: sopsOverride.gcp_kms_resource_id } : {},
2420
2436
  ...typeof sopsOverride.azure_kv_url === "string" ? { azure_kv_url: sopsOverride.azure_kv_url } : {},
2421
- ...typeof sopsOverride.pgp_fingerprint === "string" ? { pgp_fingerprint: sopsOverride.pgp_fingerprint } : {}
2437
+ ...typeof sopsOverride.pgp_fingerprint === "string" ? { pgp_fingerprint: sopsOverride.pgp_fingerprint } : {},
2438
+ ...typeof sopsOverride.pkcs11_uri === "string" ? { pkcs11_uri: sopsOverride.pkcs11_uri } : {}
2422
2439
  };
2423
2440
  }
2424
2441
  if (envObj.recipients !== void 0) {
@@ -2550,7 +2567,7 @@ var ManifestParser = class {
2550
2567
  const sopsObj = obj.sops;
2551
2568
  if (!sopsObj.default_backend || typeof sopsObj.default_backend !== "string") {
2552
2569
  throw new ManifestValidationError(
2553
- "Field 'sops.default_backend' is required and must be one of: age, awskms, gcpkms, azurekv, pgp.",
2570
+ `Field 'sops.default_backend' is required and must be one of: ${VALID_BACKENDS.join(", ")}.`,
2554
2571
  "sops.default_backend"
2555
2572
  );
2556
2573
  }
@@ -2577,13 +2594,32 @@ var ManifestParser = class {
2577
2594
  })
2578
2595
  }
2579
2596
  } : {};
2597
+ if (sopsObj.pkcs11_uri !== void 0 && typeof sopsObj.pkcs11_uri !== "string") {
2598
+ throw new ManifestValidationError(
2599
+ "Field 'sops.pkcs11_uri' must be a string.",
2600
+ "sops.pkcs11_uri"
2601
+ );
2602
+ }
2603
+ if (typeof sopsObj.pkcs11_uri === "string" && !PKCS11_URI_PATTERN.test(sopsObj.pkcs11_uri)) {
2604
+ throw new ManifestValidationError(
2605
+ `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').`,
2606
+ "sops.pkcs11_uri"
2607
+ );
2608
+ }
2609
+ if (sopsObj.default_backend === "hsm" && typeof sopsObj.pkcs11_uri !== "string") {
2610
+ throw new ManifestValidationError(
2611
+ "Field 'sops.pkcs11_uri' is required when sops.default_backend is 'hsm'.",
2612
+ "sops.pkcs11_uri"
2613
+ );
2614
+ }
2580
2615
  const sopsConfig = {
2581
2616
  default_backend: sopsObj.default_backend,
2582
2617
  ...parsedAge,
2583
2618
  ...typeof sopsObj.aws_kms_arn === "string" ? { aws_kms_arn: sopsObj.aws_kms_arn } : {},
2584
2619
  ...typeof sopsObj.gcp_kms_resource_id === "string" ? { gcp_kms_resource_id: sopsObj.gcp_kms_resource_id } : {},
2585
2620
  ...typeof sopsObj.azure_kv_url === "string" ? { azure_kv_url: sopsObj.azure_kv_url } : {},
2586
- ...typeof sopsObj.pgp_fingerprint === "string" ? { pgp_fingerprint: sopsObj.pgp_fingerprint } : {}
2621
+ ...typeof sopsObj.pgp_fingerprint === "string" ? { pgp_fingerprint: sopsObj.pgp_fingerprint } : {},
2622
+ ...typeof sopsObj.pkcs11_uri === "string" ? { pkcs11_uri: sopsObj.pkcs11_uri } : {}
2587
2623
  };
2588
2624
  for (const env of environments) {
2589
2625
  if (env.recipients && env.recipients.length > 0) {
@@ -4548,6 +4584,39 @@ ${privateKey}
4548
4584
  `;
4549
4585
  }
4550
4586
 
4587
+ // src/sops/hsm-arn.ts
4588
+ var CLEF_HSM_ARN_RE = /^arn:aws[\w-]*:kms:[^:]+:\d+:alias\/clef-hsm\/(v\d+)\/([A-Za-z0-9_-]+)$/;
4589
+ var ARN_PREFIX = "arn:aws:kms:us-east-1:000000000000:alias/clef-hsm/v1/";
4590
+ var SUPPORTED_VERSION = "v1";
4591
+ function pkcs11UriToSyntheticArn(uri) {
4592
+ if (!uri.startsWith("pkcs11:")) {
4593
+ throw new Error(`Expected a pkcs11 URI starting with 'pkcs11:', got '${uri}'.`);
4594
+ }
4595
+ const payload = Buffer.from(uri, "utf8").toString("base64url");
4596
+ const arn = ARN_PREFIX + payload;
4597
+ if (!CLEF_HSM_ARN_RE.test(arn)) {
4598
+ throw new Error(`Synthesized ARN failed self-validation: '${arn}'.`);
4599
+ }
4600
+ return arn;
4601
+ }
4602
+ function syntheticArnToPkcs11Uri(arn) {
4603
+ const match = CLEF_HSM_ARN_RE.exec(arn);
4604
+ if (!match) return null;
4605
+ const [, version, payload] = match;
4606
+ if (version !== SUPPORTED_VERSION) return null;
4607
+ let decoded;
4608
+ try {
4609
+ decoded = Buffer.from(payload, "base64url").toString("utf8");
4610
+ } catch {
4611
+ return null;
4612
+ }
4613
+ if (!decoded.startsWith("pkcs11:")) return null;
4614
+ return decoded;
4615
+ }
4616
+ function isClefHsmArn(arn) {
4617
+ return CLEF_HSM_ARN_RE.test(arn);
4618
+ }
4619
+
4551
4620
  // src/sops/client.ts
4552
4621
  function formatFromPath(filePath) {
4553
4622
  return filePath.endsWith(".json") ? "json" : "yaml";
@@ -4579,14 +4648,25 @@ var SopsClient = class {
4579
4648
  * to the subprocess environment.
4580
4649
  * @param sopsPath - Optional explicit path to the sops binary. When omitted,
4581
4650
  * resolved automatically via {@link resolveSopsPath}.
4651
+ * @param keyserviceAddr - Optional address of an external SOPS KeyService
4652
+ * sidecar (e.g. `tcp://127.0.0.1:12345`). When set, every SOPS invocation
4653
+ * includes `--enable-local-keyservice=false --keyservice <addr>` so KMS
4654
+ * wrap/unwrap is routed to the sidecar (used for the HSM backend, where
4655
+ * the sidecar is `clef-keyservice` talking PKCS#11 to the HSM).
4656
+ *
4657
+ * The flags are inserted **after** the SOPS subcommand — placing them
4658
+ * before is silently ignored by SOPS (a footgun discovered the first
4659
+ * time we shipped this).
4582
4660
  */
4583
- constructor(runner, ageKeyFile, ageKey, sopsPath) {
4661
+ constructor(runner, ageKeyFile, ageKey, sopsPath, keyserviceAddr) {
4584
4662
  this.runner = runner;
4585
4663
  this.ageKeyFile = ageKeyFile;
4586
4664
  this.ageKey = ageKey;
4587
4665
  this.sopsCommand = sopsPath ?? resolveSopsPath().path;
4666
+ this.keyserviceArgs = keyserviceAddr ? Object.freeze(["--enable-local-keyservice=false", "--keyservice", keyserviceAddr]) : Object.freeze([]);
4588
4667
  }
4589
4668
  sopsCommand;
4669
+ keyserviceArgs;
4590
4670
  buildSopsEnv() {
4591
4671
  const env = {};
4592
4672
  if (this.ageKey) {
@@ -4611,7 +4691,7 @@ var SopsClient = class {
4611
4691
  const env = this.buildSopsEnv();
4612
4692
  const result = await this.runner.run(
4613
4693
  this.sopsCommand,
4614
- ["decrypt", "--output-type", fmt, filePath],
4694
+ ["decrypt", ...this.keyserviceArgs, "--output-type", fmt, filePath],
4615
4695
  {
4616
4696
  ...env ? { env } : {}
4617
4697
  }
@@ -4678,6 +4758,7 @@ var SopsClient = class {
4678
4758
  "--config",
4679
4759
  configPath,
4680
4760
  "encrypt",
4761
+ ...this.keyserviceArgs,
4681
4762
  ...args,
4682
4763
  "--input-type",
4683
4764
  fmt,
@@ -4734,7 +4815,7 @@ var SopsClient = class {
4734
4815
  const env = this.buildSopsEnv();
4735
4816
  const result = await this.runner.run(
4736
4817
  this.sopsCommand,
4737
- ["rotate", "-i", "--add-age", key, filePath],
4818
+ ["rotate", ...this.keyserviceArgs, "-i", "--add-age", key, filePath],
4738
4819
  {
4739
4820
  ...env ? { env } : {}
4740
4821
  }
@@ -4758,7 +4839,7 @@ var SopsClient = class {
4758
4839
  const env = this.buildSopsEnv();
4759
4840
  const result = await this.runner.run(
4760
4841
  this.sopsCommand,
4761
- ["rotate", "-i", "--rm-age", key, filePath],
4842
+ ["rotate", ...this.keyserviceArgs, "-i", "--rm-age", key, filePath],
4762
4843
  {
4763
4844
  ...env ? { env } : {}
4764
4845
  }
@@ -4873,7 +4954,14 @@ var SopsClient = class {
4873
4954
  }
4874
4955
  detectBackend(sops) {
4875
4956
  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";
4957
+ if (sops.kms && Array.isArray(sops.kms) && sops.kms.length > 0) {
4958
+ const kmsEntries = sops.kms;
4959
+ const firstArn = kmsEntries[0]?.arn;
4960
+ if (typeof firstArn === "string" && isClefHsmArn(firstArn)) {
4961
+ return "hsm";
4962
+ }
4963
+ return "awskms";
4964
+ }
4877
4965
  if (sops.gcp_kms && Array.isArray(sops.gcp_kms) && sops.gcp_kms.length > 0)
4878
4966
  return "gcpkms";
4879
4967
  if (sops.azure_kv && Array.isArray(sops.azure_kv) && sops.azure_kv.length > 0)
@@ -4891,6 +4979,13 @@ var SopsClient = class {
4891
4979
  const entries = sops.kms;
4892
4980
  return entries?.map((e) => String(e.arn ?? "")) ?? [];
4893
4981
  }
4982
+ case "hsm": {
4983
+ const entries = sops.kms;
4984
+ return entries?.map((e) => {
4985
+ const raw = String(e.arn ?? "");
4986
+ return syntheticArnToPkcs11Uri(raw) ?? raw;
4987
+ }) ?? [];
4988
+ }
4894
4989
  case "gcpkms": {
4895
4990
  const entries = sops.gcp_kms;
4896
4991
  return entries?.map((e) => String(e.resource_id ?? "")) ?? [];
@@ -4916,7 +5011,8 @@ var SopsClient = class {
4916
5011
  aws_kms_arn: manifest.sops.aws_kms_arn,
4917
5012
  gcp_kms_resource_id: manifest.sops.gcp_kms_resource_id,
4918
5013
  azure_kv_url: manifest.sops.azure_kv_url,
4919
- pgp_fingerprint: manifest.sops.pgp_fingerprint
5014
+ pgp_fingerprint: manifest.sops.pgp_fingerprint,
5015
+ pkcs11_uri: manifest.sops.pkcs11_uri
4920
5016
  };
4921
5017
  switch (config.backend) {
4922
5018
  case "age": {
@@ -4948,13 +5044,172 @@ var SopsClient = class {
4948
5044
  args.push("--pgp", config.pgp_fingerprint);
4949
5045
  }
4950
5046
  break;
5047
+ case "hsm":
5048
+ if (config.pkcs11_uri) {
5049
+ args.push("--kms", pkcs11UriToSyntheticArn(config.pkcs11_uri));
5050
+ }
5051
+ break;
4951
5052
  }
4952
5053
  return args;
4953
5054
  }
4954
5055
  };
4955
5056
 
4956
- // src/lint/runner.ts
5057
+ // src/hsm/bundled.ts
5058
+ import * as fs14 from "fs";
4957
5059
  import * as path12 from "path";
5060
+ function tryBundledKeyservice() {
5061
+ const platform = process.platform;
5062
+ const arch = process.arch;
5063
+ const archName = arch === "x64" ? "x64" : arch === "arm64" ? "arm64" : null;
5064
+ if (!archName) return null;
5065
+ const platformName = platform === "darwin" ? "darwin" : platform === "linux" ? "linux" : null;
5066
+ if (!platformName) return null;
5067
+ const packageName = `@clef-sh/keyservice-${platformName}-${archName}`;
5068
+ const binName = "clef-keyservice";
5069
+ try {
5070
+ const packageMain = __require.resolve(`${packageName}/package.json`);
5071
+ const packageDir = path12.dirname(packageMain);
5072
+ const binPath = path12.join(packageDir, "bin", binName);
5073
+ return fs14.existsSync(binPath) ? binPath : null;
5074
+ } catch {
5075
+ return null;
5076
+ }
5077
+ }
5078
+
5079
+ // src/hsm/resolver.ts
5080
+ import * as fs15 from "fs";
5081
+ import * as path13 from "path";
5082
+ function validateKeyservicePath(candidate) {
5083
+ if (!path13.isAbsolute(candidate)) {
5084
+ throw new Error(`CLEF_KEYSERVICE_PATH must be an absolute path, got '${candidate}'.`);
5085
+ }
5086
+ const segments = candidate.split(/[/\\]/);
5087
+ if (segments.includes("..")) {
5088
+ throw new Error(
5089
+ `CLEF_KEYSERVICE_PATH contains '..' path segments ('${candidate}'). Use an absolute path without directory traversal.`
5090
+ );
5091
+ }
5092
+ }
5093
+ var cached2;
5094
+ function resolveKeyservicePath() {
5095
+ if (cached2) return cached2;
5096
+ const envPath = process.env.CLEF_KEYSERVICE_PATH?.trim();
5097
+ if (envPath) {
5098
+ validateKeyservicePath(envPath);
5099
+ if (!fs15.existsSync(envPath)) {
5100
+ throw new Error(`CLEF_KEYSERVICE_PATH points to '${envPath}' but the file does not exist.`);
5101
+ }
5102
+ cached2 = { path: envPath, source: "env" };
5103
+ return cached2;
5104
+ }
5105
+ const bundledPath = tryBundledKeyservice();
5106
+ if (bundledPath) {
5107
+ cached2 = { path: bundledPath, source: "bundled" };
5108
+ return cached2;
5109
+ }
5110
+ cached2 = { path: "clef-keyservice", source: "system" };
5111
+ return cached2;
5112
+ }
5113
+ function resetKeyserviceResolution() {
5114
+ cached2 = void 0;
5115
+ }
5116
+
5117
+ // src/hsm/keyservice.ts
5118
+ import { spawn } from "child_process";
5119
+ import * as readline from "readline";
5120
+ var PORT_REGEX = /^PORT=(\d+)$/;
5121
+ var STARTUP_TIMEOUT_MS = 5e3;
5122
+ var SHUTDOWN_TIMEOUT_MS = 3e3;
5123
+ async function spawnKeyservice(options) {
5124
+ if (!options.pin && !options.pinFile) {
5125
+ throw new Error(
5126
+ "Keyservice requires a PIN. Set CLEF_PKCS11_PIN, CLEF_PKCS11_PIN_FILE, or .clef/config.yaml pkcs11_pin_file."
5127
+ );
5128
+ }
5129
+ const args = ["--addr", "127.0.0.1:0", "--pkcs11-module", options.modulePath];
5130
+ const childEnv = {
5131
+ ...process.env,
5132
+ ...options.extraEnv ?? {},
5133
+ ...options.pin ? { CLEF_PKCS11_PIN: options.pin } : {},
5134
+ ...options.pinFile ? { CLEF_PKCS11_PIN_FILE: options.pinFile } : {}
5135
+ };
5136
+ const child = spawn(options.binaryPath, args, {
5137
+ stdio: ["ignore", "pipe", "pipe"],
5138
+ env: childEnv
5139
+ });
5140
+ const port = await readPort(child);
5141
+ return {
5142
+ addr: `tcp://127.0.0.1:${port}`,
5143
+ kill: () => killGracefully(child)
5144
+ };
5145
+ }
5146
+ function readPort(child) {
5147
+ return new Promise((resolve, reject) => {
5148
+ let settled = false;
5149
+ if (!child.stdout) {
5150
+ reject(new Error("Keyservice child has no stdout pipe."));
5151
+ return;
5152
+ }
5153
+ const rl = readline.createInterface({ input: child.stdout });
5154
+ const settle = () => {
5155
+ clearTimeout(timer);
5156
+ rl.close();
5157
+ };
5158
+ const timer = setTimeout(() => {
5159
+ if (!settled) {
5160
+ settled = true;
5161
+ settle();
5162
+ child.kill("SIGKILL");
5163
+ reject(
5164
+ new Error(
5165
+ `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.`
5166
+ )
5167
+ );
5168
+ }
5169
+ }, STARTUP_TIMEOUT_MS);
5170
+ rl.on("line", (line) => {
5171
+ const match = PORT_REGEX.exec(line);
5172
+ if (match && !settled) {
5173
+ settled = true;
5174
+ settle();
5175
+ resolve(parseInt(match[1], 10));
5176
+ }
5177
+ });
5178
+ child.on("error", (err) => {
5179
+ if (!settled) {
5180
+ settled = true;
5181
+ settle();
5182
+ reject(new Error(`Failed to start clef-keyservice: ${err.message}`));
5183
+ }
5184
+ });
5185
+ child.on("exit", (code) => {
5186
+ if (!settled) {
5187
+ settled = true;
5188
+ settle();
5189
+ reject(new Error(`clef-keyservice exited with code ${code} before reporting a port.`));
5190
+ }
5191
+ });
5192
+ });
5193
+ }
5194
+ function killGracefully(child) {
5195
+ return new Promise((resolve) => {
5196
+ if (child.exitCode !== null) {
5197
+ resolve();
5198
+ return;
5199
+ }
5200
+ const timer = setTimeout(() => {
5201
+ child.kill("SIGKILL");
5202
+ }, SHUTDOWN_TIMEOUT_MS);
5203
+ child.on("exit", () => {
5204
+ clearTimeout(timer);
5205
+ resolve();
5206
+ });
5207
+ child.kill("SIGTERM");
5208
+ });
5209
+ }
5210
+
5211
+ // src/lint/runner.ts
5212
+ import * as path14 from "path";
4958
5213
  var LintRunner = class {
4959
5214
  constructor(matrixManager, schemaValidator, sopsClient) {
4960
5215
  this.matrixManager = matrixManager;
@@ -5054,7 +5309,7 @@ var LintRunner = class {
5054
5309
  }
5055
5310
  const ns = manifest.namespaces.find((n) => n.name === cell.namespace);
5056
5311
  if (ns?.schema) {
5057
- const schemaPath = path12.join(repoRoot, ns.schema);
5312
+ const schemaPath = path14.join(repoRoot, ns.schema);
5058
5313
  try {
5059
5314
  const schema = this.schemaValidator.loadSchema(schemaPath);
5060
5315
  const result = this.schemaValidator.validate(decrypted.values, schema);
@@ -5341,14 +5596,14 @@ Use 'clef exec' to inject secrets directly into a process, or 'clef export --for
5341
5596
  };
5342
5597
 
5343
5598
  // src/import/index.ts
5344
- import * as path14 from "path";
5599
+ import * as path16 from "path";
5345
5600
 
5346
5601
  // src/import/parsers.ts
5347
- import * as path13 from "path";
5602
+ import * as path15 from "path";
5348
5603
  import * as YAML8 from "yaml";
5349
5604
  function detectFormat(filePath, content) {
5350
- const base = path13.basename(filePath);
5351
- const ext = path13.extname(filePath).toLowerCase();
5605
+ const base = path15.basename(filePath);
5606
+ const ext = path15.extname(filePath).toLowerCase();
5352
5607
  if (base === ".env" || base.startsWith(".env.")) {
5353
5608
  return "dotenv";
5354
5609
  }
@@ -5514,7 +5769,7 @@ var ImportRunner = class {
5514
5769
  */
5515
5770
  async import(target, sourcePath, content, manifest, repoRoot, options) {
5516
5771
  const [ns, env] = target.split("/");
5517
- const filePath = path14.join(
5772
+ const filePath = path16.join(
5518
5773
  repoRoot,
5519
5774
  manifest.file_pattern.replace("{namespace}", ns).replace("{environment}", env)
5520
5775
  );
@@ -5566,7 +5821,7 @@ var ImportRunner = class {
5566
5821
  if (imported.length === 0) {
5567
5822
  return { imported, skipped, failed, warnings, dryRun: false };
5568
5823
  }
5569
- const relCellPath = path14.relative(repoRoot, filePath);
5824
+ const relCellPath = path16.relative(repoRoot, filePath);
5570
5825
  const relMetaPath = relCellPath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
5571
5826
  await this.tx.run(repoRoot, {
5572
5827
  description: `clef import ${target}: ${imported.length} key(s)`,
@@ -5585,7 +5840,7 @@ var ImportRunner = class {
5585
5840
  };
5586
5841
 
5587
5842
  // src/recipients/index.ts
5588
- import * as path15 from "path";
5843
+ import * as path17 from "path";
5589
5844
  function parseRecipientEntry(entry) {
5590
5845
  if (typeof entry === "string") {
5591
5846
  return { key: entry };
@@ -5710,7 +5965,7 @@ var RecipientManager = class {
5710
5965
  const reEncryptedFiles = [];
5711
5966
  await this.tx.run(repoRoot, {
5712
5967
  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],
5968
+ paths: [...cells.map((c) => path17.relative(repoRoot, c.filePath)), CLEF_MANIFEST_FILENAME],
5714
5969
  mutate: async () => {
5715
5970
  const doc = readManifestYaml(repoRoot);
5716
5971
  const recipients = environment ? ensureEnvironmentRecipientsArray(doc, environment) : ensureRecipientsArray(doc);
@@ -5769,7 +6024,7 @@ var RecipientManager = class {
5769
6024
  const reEncryptedFiles = [];
5770
6025
  await this.tx.run(repoRoot, {
5771
6026
  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],
6027
+ paths: [...cells.map((c) => path17.relative(repoRoot, c.filePath)), CLEF_MANIFEST_FILENAME],
5773
6028
  mutate: async () => {
5774
6029
  const doc = readManifestYaml(repoRoot);
5775
6030
  const recipients = environment ? ensureEnvironmentRecipientsArray(doc, environment) : ensureRecipientsArray(doc);
@@ -5798,19 +6053,19 @@ var RecipientManager = class {
5798
6053
  };
5799
6054
 
5800
6055
  // src/recipients/requests.ts
5801
- import * as fs14 from "fs";
5802
- import * as path16 from "path";
6056
+ import * as fs16 from "fs";
6057
+ import * as path18 from "path";
5803
6058
  import * as YAML9 from "yaml";
5804
6059
  var REQUESTS_FILENAME = ".clef-requests.yaml";
5805
6060
  var HEADER_COMMENT2 = "# Pending recipient access requests. Approve with: clef recipients approve <label>\n";
5806
6061
  function requestsFilePath(repoRoot) {
5807
- return path16.join(repoRoot, REQUESTS_FILENAME);
6062
+ return path18.join(repoRoot, REQUESTS_FILENAME);
5808
6063
  }
5809
6064
  function loadRequests(repoRoot) {
5810
6065
  const filePath = requestsFilePath(repoRoot);
5811
6066
  try {
5812
- if (!fs14.existsSync(filePath)) return [];
5813
- const content = fs14.readFileSync(filePath, "utf-8");
6067
+ if (!fs16.existsSync(filePath)) return [];
6068
+ const content = fs16.readFileSync(filePath, "utf-8");
5814
6069
  const parsed = YAML9.parse(content);
5815
6070
  if (!parsed || !Array.isArray(parsed.requests)) return [];
5816
6071
  return parsed.requests.map((r) => ({
@@ -5827,7 +6082,7 @@ function saveRequests(repoRoot, requests) {
5827
6082
  const filePath = requestsFilePath(repoRoot);
5828
6083
  if (requests.length === 0) {
5829
6084
  try {
5830
- fs14.unlinkSync(filePath);
6085
+ fs16.unlinkSync(filePath);
5831
6086
  } catch {
5832
6087
  }
5833
6088
  return;
@@ -5843,7 +6098,7 @@ function saveRequests(repoRoot, requests) {
5843
6098
  return raw;
5844
6099
  })
5845
6100
  };
5846
- fs14.writeFileSync(filePath, HEADER_COMMENT2 + YAML9.stringify(data), "utf-8");
6101
+ fs16.writeFileSync(filePath, HEADER_COMMENT2 + YAML9.stringify(data), "utf-8");
5847
6102
  }
5848
6103
  function upsertRequest(repoRoot, key, label, environment) {
5849
6104
  const requests = loadRequests(repoRoot);
@@ -5879,7 +6134,7 @@ function findInList(requests, identifier) {
5879
6134
  }
5880
6135
 
5881
6136
  // src/drift/detector.ts
5882
- import * as path17 from "path";
6137
+ import * as path19 from "path";
5883
6138
  var DriftDetector = class {
5884
6139
  parser = new ManifestParser();
5885
6140
  matrix = new MatrixManager();
@@ -5892,8 +6147,8 @@ var DriftDetector = class {
5892
6147
  * @returns Drift result with any issues found.
5893
6148
  */
5894
6149
  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));
6150
+ const localManifest = this.parser.parse(path19.join(localRoot, CLEF_MANIFEST_FILENAME));
6151
+ const remoteManifest = this.parser.parse(path19.join(remoteRoot, CLEF_MANIFEST_FILENAME));
5897
6152
  const localCells = this.matrix.resolveMatrix(localManifest, localRoot);
5898
6153
  const remoteCells = this.matrix.resolveMatrix(remoteManifest, remoteRoot);
5899
6154
  const localEnvNames = localManifest.environments.map((e) => e.name);
@@ -5957,7 +6212,7 @@ var DriftDetector = class {
5957
6212
  };
5958
6213
 
5959
6214
  // src/report/generator.ts
5960
- import * as path18 from "path";
6215
+ import * as path20 from "path";
5961
6216
 
5962
6217
  // src/report/sanitizer.ts
5963
6218
  var ReportSanitizer = class {
@@ -6113,7 +6368,7 @@ var ReportGenerator = class {
6113
6368
  let manifest = null;
6114
6369
  try {
6115
6370
  const parser = new ManifestParser();
6116
- manifest = parser.parse(path18.join(repoRoot, "clef.yaml"));
6371
+ manifest = parser.parse(path20.join(repoRoot, "clef.yaml"));
6117
6372
  } catch {
6118
6373
  const emptyManifest = {
6119
6374
  manifestVersion: 0,
@@ -6591,7 +6846,7 @@ var SopsMergeDriver = class {
6591
6846
  };
6592
6847
 
6593
6848
  // src/merge/metadata-driver.ts
6594
- import * as fs15 from "fs";
6849
+ import * as fs17 from "fs";
6595
6850
  import * as YAML10 from "yaml";
6596
6851
  var HEADER_COMMENT3 = "# Managed by Clef. Do not edit manually.\n";
6597
6852
  function parseMetadata(content) {
@@ -6694,14 +6949,14 @@ function mergeMetadataContents(oursContent, theirsContent) {
6694
6949
  return serializeMetadata({ version: 1, pending, rotations });
6695
6950
  }
6696
6951
  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") : "";
6952
+ const oursContent = fs17.existsSync(oursPath) ? fs17.readFileSync(oursPath, "utf-8") : "";
6953
+ const theirsContent = fs17.existsSync(theirsPath) ? fs17.readFileSync(theirsPath, "utf-8") : "";
6699
6954
  const merged = mergeMetadataContents(oursContent, theirsContent);
6700
- fs15.writeFileSync(oursPath, merged, "utf-8");
6955
+ fs17.writeFileSync(oursPath, merged, "utf-8");
6701
6956
  }
6702
6957
 
6703
6958
  // src/service-identity/manager.ts
6704
- import * as path19 from "path";
6959
+ import * as path21 from "path";
6705
6960
  var ServiceIdentityManager = class {
6706
6961
  constructor(encryption, matrixManager, tx) {
6707
6962
  this.encryption = encryption;
@@ -6713,7 +6968,7 @@ var ServiceIdentityManager = class {
6713
6968
  * to seed TransactionManager.run's `paths` argument.
6714
6969
  */
6715
6970
  txPaths(repoRoot, cells) {
6716
- return [...cells.map((c) => path19.relative(repoRoot, c.filePath)), CLEF_MANIFEST_FILENAME];
6971
+ return [...cells.map((c) => path21.relative(repoRoot, c.filePath)), CLEF_MANIFEST_FILENAME];
6717
6972
  }
6718
6973
  /**
6719
6974
  * Create a new service identity with per-environment age key pairs or KMS envelope config.
@@ -7235,8 +7490,8 @@ var ServiceIdentityManager = class {
7235
7490
  };
7236
7491
 
7237
7492
  // src/structure/manager.ts
7238
- import * as fs16 from "fs";
7239
- import * as path20 from "path";
7493
+ import * as fs18 from "fs";
7494
+ import * as path22 from "path";
7240
7495
  var StructureManager = class {
7241
7496
  constructor(matrixManager, encryption, tx) {
7242
7497
  this.matrixManager = matrixManager;
@@ -7257,15 +7512,15 @@ var StructureManager = class {
7257
7512
  this.assertValidIdentifier("namespace", name);
7258
7513
  const newCellPaths = manifest.environments.map((env) => ({
7259
7514
  environment: env.name,
7260
- filePath: path20.join(
7515
+ filePath: path22.join(
7261
7516
  repoRoot,
7262
7517
  manifest.file_pattern.replace("{namespace}", name).replace("{environment}", env.name)
7263
7518
  )
7264
7519
  }));
7265
7520
  for (const cell of newCellPaths) {
7266
- if (fs16.existsSync(cell.filePath)) {
7521
+ if (fs18.existsSync(cell.filePath)) {
7267
7522
  throw new Error(
7268
- `Cannot add namespace '${name}': file '${path20.relative(repoRoot, cell.filePath)}' already exists.`
7523
+ `Cannot add namespace '${name}': file '${path22.relative(repoRoot, cell.filePath)}' already exists.`
7269
7524
  );
7270
7525
  }
7271
7526
  }
@@ -7284,7 +7539,7 @@ var StructureManager = class {
7284
7539
  await this.tx.run(repoRoot, {
7285
7540
  description: `clef namespace add ${name}`,
7286
7541
  paths: [
7287
- ...newCellPaths.map((c) => path20.relative(repoRoot, c.filePath)),
7542
+ ...newCellPaths.map((c) => path22.relative(repoRoot, c.filePath)),
7288
7543
  CLEF_MANIFEST_FILENAME
7289
7544
  ],
7290
7545
  mutate: async () => {
@@ -7329,15 +7584,15 @@ var StructureManager = class {
7329
7584
  this.assertValidIdentifier("environment", name);
7330
7585
  const newCellPaths = manifest.namespaces.map((ns) => ({
7331
7586
  namespace: ns.name,
7332
- filePath: path20.join(
7587
+ filePath: path22.join(
7333
7588
  repoRoot,
7334
7589
  manifest.file_pattern.replace("{namespace}", ns.name).replace("{environment}", name)
7335
7590
  )
7336
7591
  }));
7337
7592
  for (const cell of newCellPaths) {
7338
- if (fs16.existsSync(cell.filePath)) {
7593
+ if (fs18.existsSync(cell.filePath)) {
7339
7594
  throw new Error(
7340
- `Cannot add environment '${name}': file '${path20.relative(repoRoot, cell.filePath)}' already exists.`
7595
+ `Cannot add environment '${name}': file '${path22.relative(repoRoot, cell.filePath)}' already exists.`
7341
7596
  );
7342
7597
  }
7343
7598
  }
@@ -7356,7 +7611,7 @@ var StructureManager = class {
7356
7611
  await this.tx.run(repoRoot, {
7357
7612
  description: `clef env add ${name}`,
7358
7613
  paths: [
7359
- ...newCellPaths.map((c) => path20.relative(repoRoot, c.filePath)),
7614
+ ...newCellPaths.map((c) => path22.relative(repoRoot, c.filePath)),
7360
7615
  CLEF_MANIFEST_FILENAME
7361
7616
  ],
7362
7617
  mutate: async () => {
@@ -7419,7 +7674,7 @@ var StructureManager = class {
7419
7674
  paths: this.deletePaths(repoRoot, cellsToDelete),
7420
7675
  mutate: async () => {
7421
7676
  for (const cell of cellsToDelete) {
7422
- fs16.unlinkSync(cell.filePath);
7677
+ fs18.unlinkSync(cell.filePath);
7423
7678
  this.unlinkMetaSibling(cell.filePath);
7424
7679
  }
7425
7680
  const doc = readManifestYaml(repoRoot);
@@ -7469,7 +7724,7 @@ var StructureManager = class {
7469
7724
  paths: this.deletePaths(repoRoot, cellsToDelete),
7470
7725
  mutate: async () => {
7471
7726
  for (const cell of cellsToDelete) {
7472
- fs16.unlinkSync(cell.filePath);
7727
+ fs18.unlinkSync(cell.filePath);
7473
7728
  this.unlinkMetaSibling(cell.filePath);
7474
7729
  }
7475
7730
  const doc = readManifestYaml(repoRoot);
@@ -7511,9 +7766,9 @@ var StructureManager = class {
7511
7766
  const renamePairs = isRename ? this.collectRenamePairs(manifest, repoRoot, name, opts.rename, "namespace") : [];
7512
7767
  if (isRename) {
7513
7768
  for (const pair of renamePairs) {
7514
- if (fs16.existsSync(pair.to)) {
7769
+ if (fs18.existsSync(pair.to)) {
7515
7770
  throw new Error(
7516
- `Rename target '${path20.relative(repoRoot, pair.to)}' already exists. Move or remove it first.`
7771
+ `Rename target '${path22.relative(repoRoot, pair.to)}' already exists. Move or remove it first.`
7517
7772
  );
7518
7773
  }
7519
7774
  }
@@ -7554,9 +7809,9 @@ var StructureManager = class {
7554
7809
  const renamePairs = isRename ? this.collectRenamePairs(manifest, repoRoot, name, opts.rename, "environment") : [];
7555
7810
  if (isRename) {
7556
7811
  for (const pair of renamePairs) {
7557
- if (fs16.existsSync(pair.to)) {
7812
+ if (fs18.existsSync(pair.to)) {
7558
7813
  throw new Error(
7559
- `Rename target '${path20.relative(repoRoot, pair.to)}' already exists. Move or remove it first.`
7814
+ `Rename target '${path22.relative(repoRoot, pair.to)}' already exists. Move or remove it first.`
7560
7815
  );
7561
7816
  }
7562
7817
  }
@@ -7591,7 +7846,7 @@ var StructureManager = class {
7591
7846
  const newCellPath = this.swapAxisInCellPath(repoRoot, manifest, cell, axis, newName);
7592
7847
  pairs.push({ from: cell.filePath, to: newCellPath });
7593
7848
  const oldMeta = cell.filePath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
7594
- if (fs16.existsSync(oldMeta)) {
7849
+ if (fs18.existsSync(oldMeta)) {
7595
7850
  const newMeta = newCellPath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
7596
7851
  pairs.push({ from: oldMeta, to: newMeta });
7597
7852
  }
@@ -7606,7 +7861,7 @@ var StructureManager = class {
7606
7861
  swapAxisInCellPath(repoRoot, manifest, cell, axis, newName) {
7607
7862
  const ns = axis === "namespace" ? newName : cell.namespace;
7608
7863
  const env = axis === "environment" ? newName : cell.environment;
7609
- return path20.join(
7864
+ return path22.join(
7610
7865
  repoRoot,
7611
7866
  manifest.file_pattern.replace("{namespace}", ns).replace("{environment}", env)
7612
7867
  );
@@ -7618,8 +7873,8 @@ var StructureManager = class {
7618
7873
  txPaths(repoRoot, renamePairs) {
7619
7874
  const paths = /* @__PURE__ */ new Set();
7620
7875
  for (const pair of renamePairs) {
7621
- paths.add(path20.relative(repoRoot, pair.from));
7622
- paths.add(path20.relative(repoRoot, pair.to));
7876
+ paths.add(path22.relative(repoRoot, pair.from));
7877
+ paths.add(path22.relative(repoRoot, pair.to));
7623
7878
  }
7624
7879
  paths.add(CLEF_MANIFEST_FILENAME);
7625
7880
  return [...paths];
@@ -7630,11 +7885,11 @@ var StructureManager = class {
7630
7885
  */
7631
7886
  applyRenames(pairs) {
7632
7887
  for (const pair of pairs) {
7633
- const targetDir = path20.dirname(pair.to);
7634
- if (!fs16.existsSync(targetDir)) {
7635
- fs16.mkdirSync(targetDir, { recursive: true });
7888
+ const targetDir = path22.dirname(pair.to);
7889
+ if (!fs18.existsSync(targetDir)) {
7890
+ fs18.mkdirSync(targetDir, { recursive: true });
7636
7891
  }
7637
- fs16.renameSync(pair.from, pair.to);
7892
+ fs18.renameSync(pair.from, pair.to);
7638
7893
  }
7639
7894
  }
7640
7895
  /**
@@ -7645,10 +7900,10 @@ var StructureManager = class {
7645
7900
  deletePaths(repoRoot, cells) {
7646
7901
  const paths = /* @__PURE__ */ new Set();
7647
7902
  for (const cell of cells) {
7648
- paths.add(path20.relative(repoRoot, cell.filePath));
7903
+ paths.add(path22.relative(repoRoot, cell.filePath));
7649
7904
  const meta = cell.filePath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
7650
- if (fs16.existsSync(meta)) {
7651
- paths.add(path20.relative(repoRoot, meta));
7905
+ if (fs18.existsSync(meta)) {
7906
+ paths.add(path22.relative(repoRoot, meta));
7652
7907
  }
7653
7908
  }
7654
7909
  paths.add(CLEF_MANIFEST_FILENAME);
@@ -7661,8 +7916,8 @@ var StructureManager = class {
7661
7916
  */
7662
7917
  unlinkMetaSibling(cellPath) {
7663
7918
  const meta = cellPath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml");
7664
- if (fs16.existsSync(meta)) {
7665
- fs16.unlinkSync(meta);
7919
+ if (fs18.existsSync(meta)) {
7920
+ fs18.unlinkSync(meta);
7666
7921
  }
7667
7922
  }
7668
7923
  /**
@@ -7807,20 +8062,20 @@ async function resolveIdentitySecrets(identityName, environment, manifest, repoR
7807
8062
  import * as crypto3 from "crypto";
7808
8063
 
7809
8064
  // src/artifact/output.ts
7810
- import * as fs17 from "fs";
7811
- import * as path21 from "path";
8065
+ import * as fs19 from "fs";
8066
+ import * as path23 from "path";
7812
8067
  var FilePackOutput = class {
7813
8068
  constructor(outputPath) {
7814
8069
  this.outputPath = outputPath;
7815
8070
  }
7816
8071
  async write(_artifact, json) {
7817
- const outputDir = path21.dirname(this.outputPath);
7818
- if (!fs17.existsSync(outputDir)) {
7819
- fs17.mkdirSync(outputDir, { recursive: true });
8072
+ const outputDir = path23.dirname(this.outputPath);
8073
+ if (!fs19.existsSync(outputDir)) {
8074
+ fs19.mkdirSync(outputDir, { recursive: true });
7820
8075
  }
7821
8076
  const tmpOutput = `${this.outputPath}.tmp.${process.pid}`;
7822
- fs17.writeFileSync(tmpOutput, json, "utf-8");
7823
- fs17.renameSync(tmpOutput, this.outputPath);
8077
+ fs19.writeFileSync(tmpOutput, json, "utf-8");
8078
+ fs19.renameSync(tmpOutput, this.outputPath);
7824
8079
  }
7825
8080
  };
7826
8081
  var MemoryPackOutput = class {
@@ -8027,28 +8282,187 @@ var ArtifactPacker = class {
8027
8282
  const json = JSON.stringify(artifact, null, 2);
8028
8283
  const output = config.output ?? new FilePackOutput(config.outputPath ?? "artifact.json");
8029
8284
  await output.write(artifact, json);
8285
+ const keys = Object.keys(resolved.values);
8030
8286
  return {
8031
8287
  outputPath: config.outputPath ?? "",
8032
8288
  namespaceCount: resolved.identity.namespaces.length,
8033
- keyCount: Object.keys(resolved.values).length,
8289
+ keyCount: keys.length,
8290
+ keys,
8034
8291
  artifactSize: Buffer.byteLength(json, "utf-8"),
8035
8292
  revision: artifact.revision
8036
8293
  };
8037
8294
  }
8038
8295
  };
8039
8296
 
8297
+ // src/artifact/guards.ts
8298
+ var InvalidArtifactError = class extends ClefError {
8299
+ constructor(message) {
8300
+ super(
8301
+ message,
8302
+ "Ensure the artifact was produced by a compatible clef version and was not tampered with."
8303
+ );
8304
+ this.name = "InvalidArtifactError";
8305
+ }
8306
+ };
8307
+ var VALID_SIGNATURE_ALGORITHMS = ["Ed25519", "ECDSA_SHA256"];
8308
+ function isKmsEnvelope2(x) {
8309
+ if (typeof x !== "object" || x === null) return false;
8310
+ const o = x;
8311
+ 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";
8312
+ }
8313
+ function validatePackedArtifact(x) {
8314
+ if (typeof x !== "object" || x === null) {
8315
+ return { valid: false, reason: "expected object" };
8316
+ }
8317
+ const o = x;
8318
+ if (o.version !== 1) {
8319
+ return { valid: false, reason: `unsupported version: ${String(o.version)}` };
8320
+ }
8321
+ if (typeof o.identity !== "string") {
8322
+ return { valid: false, reason: "missing or invalid 'identity' (expected string)" };
8323
+ }
8324
+ if (typeof o.environment !== "string") {
8325
+ return { valid: false, reason: "missing or invalid 'environment' (expected string)" };
8326
+ }
8327
+ if (typeof o.packedAt !== "string") {
8328
+ return { valid: false, reason: "missing or invalid 'packedAt' (expected string)" };
8329
+ }
8330
+ if (typeof o.revision !== "string") {
8331
+ return { valid: false, reason: "missing or invalid 'revision' (expected string)" };
8332
+ }
8333
+ if (typeof o.ciphertextHash !== "string") {
8334
+ return { valid: false, reason: "missing or invalid 'ciphertextHash' (expected string)" };
8335
+ }
8336
+ if (typeof o.ciphertext !== "string") {
8337
+ return { valid: false, reason: "missing or invalid 'ciphertext' (expected string)" };
8338
+ }
8339
+ if (o.envelope !== void 0 && !isKmsEnvelope2(o.envelope)) {
8340
+ return { valid: false, reason: "invalid 'envelope' (expected KmsEnvelope shape)" };
8341
+ }
8342
+ if (o.expiresAt !== void 0 && typeof o.expiresAt !== "string") {
8343
+ return { valid: false, reason: "invalid 'expiresAt' (expected string)" };
8344
+ }
8345
+ if (o.revokedAt !== void 0 && typeof o.revokedAt !== "string") {
8346
+ return { valid: false, reason: "invalid 'revokedAt' (expected string)" };
8347
+ }
8348
+ if (o.signature !== void 0 && typeof o.signature !== "string") {
8349
+ return { valid: false, reason: "invalid 'signature' (expected string)" };
8350
+ }
8351
+ if (o.signatureAlgorithm !== void 0 && !VALID_SIGNATURE_ALGORITHMS.includes(o.signatureAlgorithm)) {
8352
+ return {
8353
+ valid: false,
8354
+ reason: `invalid 'signatureAlgorithm': expected one of ${VALID_SIGNATURE_ALGORITHMS.join(", ")}`
8355
+ };
8356
+ }
8357
+ return { valid: true, value: o };
8358
+ }
8359
+ function isPackedArtifact(x) {
8360
+ return validatePackedArtifact(x).valid;
8361
+ }
8362
+ function assertPackedArtifact(x, context) {
8363
+ const result = validatePackedArtifact(x);
8364
+ if (!result.valid) {
8365
+ const prefix = context ? `${context}: ` : "";
8366
+ throw new InvalidArtifactError(`${prefix}${result.reason}`);
8367
+ }
8368
+ }
8369
+
8370
+ // src/pack/registry.ts
8371
+ var PackBackendRegistry = class {
8372
+ factories = /* @__PURE__ */ new Map();
8373
+ /**
8374
+ * Register a backend factory under the given id. Throws if a backend
8375
+ * with the same id is already registered — collisions surface as a clear
8376
+ * error rather than a silent overwrite.
8377
+ */
8378
+ register(id, factory) {
8379
+ if (this.factories.has(id)) {
8380
+ throw new Error(`Pack backend "${id}" is already registered.`);
8381
+ }
8382
+ this.factories.set(id, factory);
8383
+ }
8384
+ /** Whether a backend with the given id has been registered. */
8385
+ has(id) {
8386
+ return this.factories.has(id);
8387
+ }
8388
+ /** Registered backend ids, in registration order. */
8389
+ list() {
8390
+ return [...this.factories.keys()];
8391
+ }
8392
+ /**
8393
+ * Resolve a backend by id. Throws if unknown. Factories may be async so
8394
+ * a plugin package can defer construction (e.g. loading a heavy SDK only
8395
+ * when the backend is actually used).
8396
+ */
8397
+ async resolve(id) {
8398
+ const factory = this.factories.get(id);
8399
+ if (!factory) {
8400
+ const available = this.list().join(", ") || "(none)";
8401
+ throw new Error(`Unknown pack backend "${id}". Available backends: ${available}`);
8402
+ }
8403
+ return await factory();
8404
+ }
8405
+ };
8406
+
8407
+ // src/pack/backends/json-envelope.ts
8408
+ var JsonEnvelopeBackend = class {
8409
+ id = "json-envelope";
8410
+ description = "Write the Clef JSON artifact envelope to a local file (default).";
8411
+ validateOptions(raw) {
8412
+ const opts = raw;
8413
+ if (opts.signingKey && opts.signingKmsKeyId) {
8414
+ throw new Error(
8415
+ "Cannot specify both signingKey (Ed25519) and signingKmsKeyId (KMS). Choose one."
8416
+ );
8417
+ }
8418
+ if (!opts.outputPath && !opts.output) {
8419
+ throw new Error("json-envelope backend requires an 'outputPath' or 'output' option.");
8420
+ }
8421
+ }
8422
+ async pack(req) {
8423
+ const opts = req.backendOptions;
8424
+ const packer = new ArtifactPacker(
8425
+ req.services.encryption,
8426
+ new MatrixManager(),
8427
+ req.services.kms
8428
+ );
8429
+ const output = opts.output ?? (opts.outputPath ? new FilePackOutput(opts.outputPath) : void 0);
8430
+ const result = await packer.pack(
8431
+ {
8432
+ identity: req.identity,
8433
+ environment: req.environment,
8434
+ outputPath: opts.outputPath,
8435
+ output,
8436
+ ttl: req.ttl,
8437
+ signingKey: opts.signingKey,
8438
+ signingKmsKeyId: opts.signingKmsKeyId
8439
+ },
8440
+ req.manifest,
8441
+ req.repoRoot
8442
+ );
8443
+ return {
8444
+ ...result,
8445
+ backend: this.id,
8446
+ details: {
8447
+ outputPath: opts.outputPath ?? null
8448
+ }
8449
+ };
8450
+ }
8451
+ };
8452
+
8040
8453
  // src/kms/types.ts
8041
8454
  var VALID_KMS_PROVIDERS = ["aws", "gcp", "azure"];
8042
8455
 
8043
8456
  // src/migration/backend.ts
8044
- import * as path22 from "path";
8457
+ import * as path24 from "path";
8045
8458
  import * as YAML11 from "yaml";
8046
8459
  var BACKEND_KEY_FIELDS = {
8047
8460
  age: void 0,
8048
8461
  awskms: "aws_kms_arn",
8049
8462
  gcpkms: "gcp_kms_resource_id",
8050
8463
  azurekv: "azure_kv_url",
8051
- pgp: "pgp_fingerprint"
8464
+ pgp: "pgp_fingerprint",
8465
+ hsm: "pkcs11_uri"
8052
8466
  };
8053
8467
  var ALL_KEY_FIELDS = Object.values(BACKEND_KEY_FIELDS).filter(
8054
8468
  (v) => v !== void 0
@@ -8158,7 +8572,7 @@ var BackendMigrator = class {
8158
8572
  await this.tx.run(repoRoot, {
8159
8573
  description: environment ? `clef migrate-backend ${target.backend}: ${environment}` : `clef migrate-backend ${target.backend}`,
8160
8574
  paths: [
8161
- ...toMigrate.map((c) => path22.relative(repoRoot, c.filePath)),
8575
+ ...toMigrate.map((c) => path24.relative(repoRoot, c.filePath)),
8162
8576
  CLEF_MANIFEST_FILENAME
8163
8577
  ],
8164
8578
  mutate: async () => {
@@ -8256,7 +8670,7 @@ var BackendMigrator = class {
8256
8670
  };
8257
8671
 
8258
8672
  // src/reset/manager.ts
8259
- import * as path23 from "path";
8673
+ import * as path25 from "path";
8260
8674
  var ResetManager = class {
8261
8675
  constructor(matrixManager, encryption, schemaValidator, tx) {
8262
8676
  this.matrixManager = matrixManager;
@@ -8281,11 +8695,11 @@ var ResetManager = class {
8281
8695
  txPaths.push(CLEF_MANIFEST_FILENAME);
8282
8696
  }
8283
8697
  for (const cell of targetCells) {
8284
- txPaths.push(path23.relative(repoRoot, cell.filePath));
8698
+ txPaths.push(path25.relative(repoRoot, cell.filePath));
8285
8699
  const cellKeys = keyPlan.get(cell.namespace) ?? [];
8286
8700
  if (cellKeys.length > 0) {
8287
8701
  txPaths.push(
8288
- path23.relative(repoRoot, cell.filePath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml"))
8702
+ path25.relative(repoRoot, cell.filePath.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml"))
8289
8703
  );
8290
8704
  }
8291
8705
  }
@@ -8373,7 +8787,7 @@ var ResetManager = class {
8373
8787
  for (const namespace of namespaces) {
8374
8788
  const nsDef = manifest.namespaces.find((n) => n.name === namespace);
8375
8789
  if (nsDef?.schema) {
8376
- const schema = this.schemaValidator.loadSchema(path23.join(repoRoot, nsDef.schema));
8790
+ const schema = this.schemaValidator.loadSchema(path25.join(repoRoot, nsDef.schema));
8377
8791
  plan.set(namespace, Object.keys(schema.keys));
8378
8792
  continue;
8379
8793
  }
@@ -8452,7 +8866,7 @@ function withBackendOverride(manifest, envNames, backend, key) {
8452
8866
  }
8453
8867
 
8454
8868
  // src/sync/manager.ts
8455
- import * as path24 from "path";
8869
+ import * as path26 from "path";
8456
8870
  var SyncManager = class {
8457
8871
  constructor(matrixManager, encryption, tx) {
8458
8872
  this.matrixManager = matrixManager;
@@ -8521,7 +8935,7 @@ var SyncManager = class {
8521
8935
  }
8522
8936
  const txPaths = [];
8523
8937
  for (const cell of syncPlan.cells) {
8524
- const rel = path24.relative(repoRoot, cell.filePath);
8938
+ const rel = path26.relative(repoRoot, cell.filePath);
8525
8939
  txPaths.push(rel);
8526
8940
  txPaths.push(rel.replace(/\.enc\.(yaml|json)$/, ".clef-meta.yaml"));
8527
8941
  }
@@ -8560,7 +8974,7 @@ var SyncManager = class {
8560
8974
  };
8561
8975
 
8562
8976
  // src/policy/parser.ts
8563
- import * as fs18 from "fs";
8977
+ import * as fs20 from "fs";
8564
8978
  import * as YAML12 from "yaml";
8565
8979
 
8566
8980
  // src/policy/types.ts
@@ -8582,7 +8996,7 @@ var PolicyParser = class {
8582
8996
  parse(filePath) {
8583
8997
  let raw;
8584
8998
  try {
8585
- raw = fs18.readFileSync(filePath, "utf-8");
8999
+ raw = fs20.readFileSync(filePath, "utf-8");
8586
9000
  } catch {
8587
9001
  throw new PolicyValidationError(`Could not read policy file at '${filePath}'.`);
8588
9002
  }
@@ -8610,7 +9024,7 @@ var PolicyParser = class {
8610
9024
  * not exist. Any other read or validation error throws.
8611
9025
  */
8612
9026
  load(filePath) {
8613
- if (!fs18.existsSync(filePath)) return DEFAULT_POLICY;
9027
+ if (!fs20.existsSync(filePath)) return DEFAULT_POLICY;
8614
9028
  return this.parse(filePath);
8615
9029
  }
8616
9030
  validate(raw) {
@@ -8803,13 +9217,13 @@ var ComplianceGenerator = class {
8803
9217
  };
8804
9218
 
8805
9219
  // src/compliance/run.ts
8806
- import * as path25 from "path";
9220
+ import * as path27 from "path";
8807
9221
  var UNKNOWN = "unknown";
8808
9222
  async function runCompliance(opts) {
8809
9223
  const start = Date.now();
8810
9224
  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);
9225
+ const manifestPath = opts.manifestPath ?? path27.join(repoRoot, "clef.yaml");
9226
+ const policyPath = opts.policyPath ?? path27.join(repoRoot, CLEF_POLICY_FILENAME);
8813
9227
  const include = {
8814
9228
  scan: opts.include?.scan ?? true,
8815
9229
  lint: opts.include?.lint ?? true,
@@ -8855,7 +9269,7 @@ async function evaluateMatrix(args) {
8855
9269
  return Promise.all(
8856
9270
  cells.map(async (cell) => {
8857
9271
  const metadata = await args.sopsClient.getMetadata(cell.filePath);
8858
- const relPath = path25.relative(args.repoRoot, cell.filePath).replace(/\\/g, "/");
9272
+ const relPath = path27.relative(args.repoRoot, cell.filePath).replace(/\\/g, "/");
8859
9273
  const keys = readSopsKeyNames(cell.filePath) ?? [];
8860
9274
  const rotations = await getRotations(cell.filePath);
8861
9275
  return evaluator.evaluateFile(relPath, cell.environment, metadata, keys, rotations, args.now);
@@ -8933,11 +9347,14 @@ export {
8933
9347
  GitIntegration,
8934
9348
  GitOperationError,
8935
9349
  ImportRunner,
9350
+ InvalidArtifactError,
9351
+ JsonEnvelopeBackend,
8936
9352
  LintRunner,
8937
9353
  ManifestParser,
8938
9354
  ManifestValidationError,
8939
9355
  MatrixManager,
8940
9356
  MemoryPackOutput,
9357
+ PackBackendRegistry,
8941
9358
  PolicyEvaluator,
8942
9359
  PolicyParser,
8943
9360
  PolicyValidationError,
@@ -8966,6 +9383,7 @@ export {
8966
9383
  TransactionPreflightError,
8967
9384
  TransactionRollbackError,
8968
9385
  VALID_KMS_PROVIDERS,
9386
+ assertPackedArtifact,
8969
9387
  assertSops,
8970
9388
  buildSigningPayload,
8971
9389
  checkAll,
@@ -8982,8 +9400,10 @@ export {
8982
9400
  generateSigningKeyPair,
8983
9401
  getPendingKeys,
8984
9402
  getRotations,
9403
+ isClefHsmArn,
8985
9404
  isHighEntropy,
8986
9405
  isKmsEnvelope,
9406
+ isPackedArtifact,
8987
9407
  isPending,
8988
9408
  keyPreview,
8989
9409
  loadIgnoreRules,
@@ -9001,15 +9421,18 @@ export {
9001
9421
  parseIgnoreContent,
9002
9422
  parseJson,
9003
9423
  parseYaml,
9424
+ pkcs11UriToSyntheticArn,
9004
9425
  readManifestYaml,
9005
9426
  recordRotation,
9006
9427
  redactValue,
9007
9428
  removeRequest as removeAccessRequest,
9008
9429
  removeRotation,
9009
9430
  requestsFilePath,
9431
+ resetKeyserviceResolution,
9010
9432
  resetSopsResolution,
9011
9433
  resolveBackendConfig,
9012
9434
  resolveIdentitySecrets,
9435
+ resolveKeyservicePath,
9013
9436
  resolveRecipientsForEnvironment,
9014
9437
  resolveSopsPath,
9015
9438
  runCompliance,
@@ -9020,8 +9443,12 @@ export {
9020
9443
  shouldIgnoreMatch,
9021
9444
  signEd25519,
9022
9445
  signKms,
9446
+ spawnKeyservice,
9447
+ syntheticArnToPkcs11Uri,
9448
+ tryBundledKeyservice,
9023
9449
  upsertRequest,
9024
9450
  validateAgePublicKey,
9451
+ validatePackedArtifact,
9025
9452
  validateResetScope,
9026
9453
  verifySignature,
9027
9454
  writeManifestYaml,