@mnemonik/cli 7.109.3 → 7.111.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/auth/credentials.js +297 -36
  2. package/dist/auth/index.d.ts +2 -0
  3. package/dist/auth/index.d.ts.map +1 -1
  4. package/dist/auth/index.js +1914 -19
  5. package/dist/auth/index.js.map +1 -1
  6. package/dist/auth/machineName.d.ts +8 -0
  7. package/dist/auth/machineName.d.ts.map +1 -0
  8. package/dist/auth/machineName.js +23 -0
  9. package/dist/auth/machineName.js.map +1 -0
  10. package/dist/consent.d.ts +29 -0
  11. package/dist/consent.d.ts.map +1 -0
  12. package/dist/consent.js +87 -0
  13. package/dist/consent.js.map +1 -0
  14. package/dist/diagnostics.js +301 -40
  15. package/dist/digests.json +102 -90
  16. package/dist/help.d.ts.map +1 -1
  17. package/dist/help.js +59 -44
  18. package/dist/help.js.map +1 -1
  19. package/dist/humanReason.d.ts +8 -0
  20. package/dist/humanReason.d.ts.map +1 -1
  21. package/dist/humanReason.js +44 -16
  22. package/dist/humanReason.js.map +1 -1
  23. package/dist/identity/migrate.js +1835 -44
  24. package/dist/install/hosts.d.ts +2 -0
  25. package/dist/install/hosts.d.ts.map +1 -1
  26. package/dist/install/hosts.js +23 -14
  27. package/dist/install/hosts.js.map +1 -1
  28. package/dist/install/journal.js +124 -11
  29. package/dist/install/journey.d.ts +20 -0
  30. package/dist/install/journey.d.ts.map +1 -1
  31. package/dist/install/journey.js +1913 -82
  32. package/dist/install/journey.js.map +1 -1
  33. package/dist/install/ownership.d.ts.map +1 -1
  34. package/dist/install/ownership.js +1818 -10
  35. package/dist/install/ownership.js.map +1 -1
  36. package/dist/install/transaction.js +1913 -19
  37. package/dist/install/ui.js +1910 -15
  38. package/dist/installation.js +133 -10
  39. package/dist/launcher.js +108 -4
  40. package/dist/output.d.ts +3 -0
  41. package/dist/output.d.ts.map +1 -1
  42. package/dist/output.js +11 -1
  43. package/dist/output.js.map +1 -1
  44. package/dist/preflight.d.ts +5 -0
  45. package/dist/preflight.d.ts.map +1 -1
  46. package/dist/preflight.js +14 -12
  47. package/dist/preflight.js.map +1 -1
  48. package/dist/project/eligibility.js +1917 -22
  49. package/dist/project/records.js +121 -8
  50. package/dist/project.d.ts +15 -0
  51. package/dist/project.d.ts.map +1 -1
  52. package/dist/project.js +229 -15
  53. package/dist/project.js.map +1 -1
  54. package/dist/router.d.ts +2 -0
  55. package/dist/router.d.ts.map +1 -1
  56. package/dist/router.js +2164 -122
  57. package/dist/router.js.map +1 -1
  58. package/dist/runtime/releaseSource.d.ts +6 -0
  59. package/dist/runtime/releaseSource.d.ts.map +1 -1
  60. package/dist/runtime/releaseSource.js +1933 -32
  61. package/dist/runtime/releaseSource.js.map +1 -1
  62. package/dist/runtime/selfUpdate.js +1809 -8
  63. package/dist/runtime/signers.js +28 -9
  64. package/dist/runtime/store.js +18 -6
  65. package/dist/runtime/updateCheck.d.ts +4 -0
  66. package/dist/runtime/updateCheck.d.ts.map +1 -0
  67. package/dist/runtime/updateCheck.js +6695 -0
  68. package/dist/runtime/updateCheck.js.map +1 -0
  69. package/dist/sbom.json +21 -21
  70. package/dist/scanner/control.d.ts +27 -1
  71. package/dist/scanner/control.d.ts.map +1 -1
  72. package/dist/scanner/control.js +207 -36
  73. package/dist/scanner/control.js.map +1 -1
  74. package/dist/scanner/discover.d.ts +5 -0
  75. package/dist/scanner/discover.d.ts.map +1 -1
  76. package/dist/scanner/discover.js +16 -6
  77. package/dist/scanner/discover.js.map +1 -1
  78. package/dist/scanner/enable.d.ts +2 -0
  79. package/dist/scanner/enable.d.ts.map +1 -1
  80. package/dist/scanner/enable.js +152 -14
  81. package/dist/scanner/enable.js.map +1 -1
  82. package/dist/scanner/picker.d.ts.map +1 -1
  83. package/dist/scanner/picker.js +5 -6
  84. package/dist/scanner/picker.js.map +1 -1
  85. package/dist/scanner/service.d.ts +2 -0
  86. package/dist/scanner/service.d.ts.map +1 -1
  87. package/dist/scanner/service.js +279 -54
  88. package/dist/scanner/service.js.map +1 -1
  89. package/dist/scanner/update.d.ts +8 -0
  90. package/dist/scanner/update.d.ts.map +1 -1
  91. package/dist/scanner/update.js +254 -20
  92. package/dist/scanner/update.js.map +1 -1
  93. package/dist/scanner-release.json +35 -30
  94. package/dist/screens/journey.d.ts +6 -1
  95. package/dist/screens/journey.d.ts.map +1 -1
  96. package/dist/screens/journey.js +29 -8
  97. package/dist/screens/journey.js.map +1 -1
  98. package/dist/status.d.ts +21 -0
  99. package/dist/status.d.ts.map +1 -1
  100. package/dist/status.js +1993 -39
  101. package/dist/status.js.map +1 -1
  102. package/dist/vendor/local-setup.js +256 -29
  103. package/dist/vendor/shared/runtimeSigners.js +38 -11
  104. package/package.json +31 -31
package/dist/router.js CHANGED
@@ -5,6 +5,12 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
8
14
  var __esm = (fn, res, err2) => function __init() {
9
15
  if (err2) throw err2[0];
10
16
  try {
@@ -13,7 +19,7 @@ var __esm = (fn, res, err2) => function __init() {
13
19
  throw err2 = [e], e;
14
20
  }
15
21
  };
16
- var __commonJS = (cb, mod) => function __require() {
22
+ var __commonJS = (cb, mod) => function __require2() {
17
23
  try {
18
24
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
19
25
  } catch (e) {
@@ -496,11 +502,73 @@ var require_ignore = __commonJS({
496
502
  });
497
503
 
498
504
  // packages/shared/dist/runtimeSigners.js
499
- var ttl;
505
+ import { basename, dirname as dirname2, join as join2, resolve, sep, win32 } from "node:path";
506
+ import { execFile, execFileSync } from "node:child_process";
507
+ function windowsCommand(file) {
508
+ const root = process.env.SystemRoot;
509
+ if (!root || !win32.isAbsolute(root))
510
+ throw new Error("acl_system_root_unavailable");
511
+ return win32.join(root, "System32", file);
512
+ }
513
+ function readIdentity(stdout) {
514
+ const match = /^"([^"\r\n]+)","(S-1-(?:\d+-)+\d+)"$/.exec(stdout.trim());
515
+ if (!match?.[1] || !match[2] || stdout.includes("\uFFFD"))
516
+ throw new Error("acl_identity_unavailable");
517
+ return { name: match[1], sid: match[2] };
518
+ }
519
+ function* readWindowsIdentity() {
520
+ const user = readIdentity(yield [windowsCommand("whoami.exe"), identityArgs]);
521
+ if (!ADMINISTRATOR_RID.test(user.sid))
522
+ return user;
523
+ const groups = yield [windowsCommand("whoami.exe"), groupArgs];
524
+ const local = /^"[^"\r\n]*","[^"\r\n]*","S-1-5-113",/m.test(groups);
525
+ return {
526
+ ...user,
527
+ localAdministratorSid: local ? `${user.sid.slice(0, user.sid.lastIndexOf("-"))}-500` : null
528
+ };
529
+ }
530
+ function windowsCurrentAccountSync() {
531
+ if (currentIdentity)
532
+ return currentIdentity;
533
+ const commands = readWindowsIdentity();
534
+ let step = commands.next();
535
+ while (!step.done)
536
+ step = commands.next(hookExecuteSync(...step.value));
537
+ return currentIdentity = step.value;
538
+ }
539
+ function hookInvocation(file, args2) {
540
+ if (win32.basename(file) === "whoami.exe") {
541
+ if ([file, ...args2].some((arg) => /[%!"\r\n]/.test(arg)))
542
+ throw new Error("acl_path_unavailable");
543
+ const command = args2.map((arg) => /^(?:[a-z0-9]+|\/[a-z]+)$/i.test(arg) ? arg : `"${arg}"`).join(" ");
544
+ return [
545
+ windowsCommand("cmd.exe"),
546
+ ["/d", "/v:off", "/s", "/c", `"chcp 65001>nul & "${file}" ${command}"`]
547
+ ];
548
+ }
549
+ if (win32.basename(file) === "cmd.exe")
550
+ return [file, ["/u", ...args2]];
551
+ return [file, args2];
552
+ }
553
+ function hookExecuteSync(file, args2, input) {
554
+ [file, args2] = hookInvocation(file, args2);
555
+ return execFileSync(file, args2, { ...hookOptions(file, args2), input });
556
+ }
557
+ var identityArgs, groupArgs, ADMINISTRATOR_RID, currentIdentity, ttl, hookOptions;
500
558
  var init_runtimeSigners = __esm({
501
559
  "packages/shared/dist/runtimeSigners.js"() {
502
560
  "use strict";
561
+ identityArgs = ["/user", "/fo", "csv", "/nh"];
562
+ groupArgs = ["/groups", "/fo", "csv", "/nh"];
563
+ ADMINISTRATOR_RID = /^S-1-5-21-\d+-\d+-\d+-500$/;
503
564
  ttl = 10 * 6e4;
565
+ hookOptions = (file, args2) => ({
566
+ encoding: args2.includes("/u") ? "utf16le" : "utf8",
567
+ timeout: win32.basename(file) === "powershell.exe" ? 3e4 : 5e3,
568
+ windowsHide: true,
569
+ maxBuffer: 16 * 1024 * 1024,
570
+ windowsVerbatimArguments: win32.basename(file) === "cmd.exe"
571
+ });
504
572
  }
505
573
  });
506
574
 
@@ -518,7 +586,7 @@ var init_repositoryFingerprint = __esm({
518
586
 
519
587
  // packages/shared/dist/projectIdentityFile.js
520
588
  import { lstat, readFile } from "node:fs/promises";
521
- import { join as join2 } from "node:path";
589
+ import { join as join3 } from "node:path";
522
590
  function parseIdentityFile(text) {
523
591
  let value;
524
592
  try {
@@ -571,7 +639,7 @@ function parseIdentityFile(text) {
571
639
  };
572
640
  }
573
641
  async function readIdentityFile(dir, options = {}) {
574
- const path = join2(dir, ".mnemonik.json");
642
+ const path = join3(dir, ".mnemonik.json");
575
643
  try {
576
644
  const stat = await lstat(path);
577
645
  if (stat.isSymbolicLink())
@@ -612,9 +680,9 @@ var init_projectIdentityFile = __esm({
612
680
 
613
681
  // packages/shared/dist/repositoryRoot.js
614
682
  import { lstat as lstat2, readFile as readFile2 } from "node:fs/promises";
615
- import { execFile } from "node:child_process";
683
+ import { execFile as execFile2 } from "node:child_process";
616
684
  import { homedir } from "node:os";
617
- import { dirname as dirname2, join as join3, resolve } from "node:path";
685
+ import { dirname as dirname3, join as join4, resolve as resolve2 } from "node:path";
618
686
  function gitEnvironment() {
619
687
  const env = {};
620
688
  for (const key of GIT_ENV_KEYS) {
@@ -626,7 +694,7 @@ function gitEnvironment() {
626
694
  }
627
695
  function runGit(cwd, args2) {
628
696
  return new Promise((resolvePromise, reject) => {
629
- execFile("git", args2, { cwd, timeout: GIT_TIMEOUT_MS, encoding: "utf8", env: gitEnvironment() }, (error, stdout, stderr) => {
697
+ execFile2("git", args2, { cwd, timeout: GIT_TIMEOUT_MS, encoding: "utf8", env: gitEnvironment() }, (error, stdout, stderr) => {
630
698
  if (error)
631
699
  reject(Object.assign(error, { stdout, stderr }));
632
700
  else
@@ -636,7 +704,7 @@ function runGit(cwd, args2) {
636
704
  }
637
705
  async function boundaryAt(path) {
638
706
  try {
639
- const stat = await lstat2(join3(path, ".git"));
707
+ const stat = await lstat2(join4(path, ".git"));
640
708
  if (stat.isDirectory())
641
709
  return { path, kind: "directory" };
642
710
  if (stat.isFile())
@@ -666,7 +734,7 @@ async function boundariesBetween(cwd, root) {
666
734
  const boundary = await confirmedBoundaryAt(directory);
667
735
  if (boundary)
668
736
  boundaries.push(boundary);
669
- const parent = dirname2(directory);
737
+ const parent = dirname3(directory);
670
738
  if (parent === directory)
671
739
  break;
672
740
  directory = parent;
@@ -674,12 +742,12 @@ async function boundariesBetween(cwd, root) {
674
742
  return boundaries;
675
743
  }
676
744
  async function containingRepository(root) {
677
- let directory = dirname2(root);
745
+ let directory = dirname3(root);
678
746
  while (true) {
679
747
  const boundary = await confirmedBoundaryAt(directory);
680
748
  if (boundary)
681
749
  return boundary;
682
- const parent = dirname2(directory);
750
+ const parent = dirname3(directory);
683
751
  if (parent === directory)
684
752
  return void 0;
685
753
  directory = parent;
@@ -688,13 +756,13 @@ async function containingRepository(root) {
688
756
  async function canonicalBoundaryRoot(boundary) {
689
757
  if (boundary.kind === "directory")
690
758
  return boundary.path;
691
- const pointer = /^gitdir:\s*(.+)\s*$/im.exec(await readFile2(join3(boundary.path, ".git"), "utf8"))?.[1];
759
+ const pointer = /^gitdir:\s*(.+)\s*$/im.exec(await readFile2(join4(boundary.path, ".git"), "utf8"))?.[1];
692
760
  if (!pointer)
693
761
  return boundary.path;
694
- const gitDir = resolve(boundary.path, pointer);
762
+ const gitDir = resolve2(boundary.path, pointer);
695
763
  try {
696
- const commonDir = resolve(gitDir, (await readFile2(join3(gitDir, "commondir"), "utf8")).trim());
697
- return dirname2(commonDir);
764
+ const commonDir = resolve2(gitDir, (await readFile2(join4(gitDir, "commondir"), "utf8")).trim());
765
+ return dirname3(commonDir);
698
766
  } catch (error) {
699
767
  if (error.code === "ENOENT")
700
768
  return boundary.path;
@@ -702,7 +770,7 @@ async function canonicalBoundaryRoot(boundary) {
702
770
  }
703
771
  }
704
772
  async function resolveRepositoryRoot(cwd) {
705
- const absoluteCwd = resolve(cwd);
773
+ const absoluteCwd = resolve2(cwd);
706
774
  try {
707
775
  const { stdout } = await runGit(absoluteCwd, [
708
776
  "rev-parse",
@@ -713,9 +781,9 @@ async function resolveRepositoryRoot(cwd) {
713
781
  if (!rootLine || !commonLine || extra.length) {
714
782
  return { kind: "git_unavailable", detail: "git rev-parse returned an unexpected response" };
715
783
  }
716
- const root = resolve(rootLine);
717
- const commonDir = resolve(root, commonLine);
718
- const isLinkedWorktree = commonDir !== join3(root, ".git");
784
+ const root = resolve2(rootLine);
785
+ const commonDir = resolve2(root, commonLine);
786
+ const isLinkedWorktree = commonDir !== join4(root, ".git");
719
787
  const nested = await boundariesBetween(absoluteCwd, root);
720
788
  if (!isLinkedWorktree && await containingRepository(root)) {
721
789
  const boundary = await boundaryAt(root);
@@ -738,7 +806,7 @@ async function resolveRepositoryRoot(cwd) {
738
806
  }
739
807
  }
740
808
  async function readPlainIdentity(start2) {
741
- const home = resolve(homedir());
809
+ const home = resolve2(homedir());
742
810
  let directory = start2;
743
811
  while (true) {
744
812
  const result = await readIdentityFile(directory);
@@ -746,7 +814,7 @@ async function readPlainIdentity(start2) {
746
814
  return { root: directory, result };
747
815
  if (directory === home)
748
816
  break;
749
- const parent = dirname2(directory);
817
+ const parent = dirname3(directory);
750
818
  if (parent === directory)
751
819
  break;
752
820
  directory = parent;
@@ -758,7 +826,7 @@ function withBase(repository, root, nested) {
758
826
  }
759
827
  async function resolveProjectIdentity(cwd, options = {}) {
760
828
  const resolved = await resolveRepositoryRoot(cwd);
761
- const repository = resolved.kind === "git_unavailable" ? { kind: "plain", root: resolve(cwd) } : resolved;
829
+ const repository = resolved.kind === "git_unavailable" ? { kind: "plain", root: resolve2(cwd) } : resolved;
762
830
  if (repository.kind === "plain") {
763
831
  const { root, result } = options.selectedRoot ? { root: repository.root, result: await readIdentityFile(repository.root, options) } : await readPlainIdentity(repository.root);
764
832
  const base2 = withBase(repository, root, []);
@@ -770,7 +838,7 @@ async function resolveProjectIdentity(cwd, options = {}) {
770
838
  return { ...base2, ...result, path: root };
771
839
  return { ...base2, kind: "absent" };
772
840
  }
773
- const ownRoot = repository.isLinkedWorktree ? dirname2(repository.commonDir) : repository.root;
841
+ const ownRoot = repository.isLinkedWorktree ? dirname3(repository.commonDir) : repository.root;
774
842
  const outer = repository.isLinkedWorktree ? void 0 : await containingRepository(repository.root);
775
843
  const own = await readIdentityFile(ownRoot, options);
776
844
  if (!outer || options.selectedRoot || own.kind === "ok") {
@@ -802,65 +870,1663 @@ async function resolveProjectIdentity(cwd, options = {}) {
802
870
  ...parent.kind === "ok" ? { parentIdentity: parent.identity } : {}
803
871
  };
804
872
  }
805
- if (parent.kind === "ok")
806
- return { ...base, kind: "ok", identity: parent.identity };
807
- return { ...base, kind: "absent" };
808
- }
809
- var GIT_TIMEOUT_MS, GIT_ENV_KEYS;
810
- var init_repositoryRoot = __esm({
811
- "packages/shared/dist/repositoryRoot.js"() {
873
+ if (parent.kind === "ok")
874
+ return { ...base, kind: "ok", identity: parent.identity };
875
+ return { ...base, kind: "absent" };
876
+ }
877
+ var GIT_TIMEOUT_MS, GIT_ENV_KEYS;
878
+ var init_repositoryRoot = __esm({
879
+ "packages/shared/dist/repositoryRoot.js"() {
880
+ "use strict";
881
+ init_projectIdentityFile();
882
+ GIT_TIMEOUT_MS = 2e3;
883
+ GIT_ENV_KEYS = [
884
+ "PATH",
885
+ "HOME",
886
+ "LANG",
887
+ "LC_ALL",
888
+ "SYSTEMROOT",
889
+ "TEMP",
890
+ "TMP",
891
+ "USERPROFILE"
892
+ ];
893
+ }
894
+ });
895
+
896
+ // packages/shared/dist/runtimeReader.js
897
+ var RuntimeError;
898
+ var init_runtimeReader = __esm({
899
+ "packages/shared/dist/runtimeReader.js"() {
900
+ "use strict";
901
+ init_runtimeSigners();
902
+ init_runtimeSigners();
903
+ RuntimeError = class extends Error {
904
+ reason;
905
+ constructor(reason) {
906
+ super(reason);
907
+ this.reason = reason;
908
+ this.name = "RuntimeError";
909
+ }
910
+ };
911
+ }
912
+ });
913
+
914
+ // packages/shared/dist/projectSetupHandoff.js
915
+ var init_projectSetupHandoff = __esm({
916
+ "packages/shared/dist/projectSetupHandoff.js"() {
917
+ "use strict";
918
+ init_runtimeSigners();
919
+ init_runtimeReader();
920
+ }
921
+ });
922
+
923
+ // packages/shared/dist/hookRuntime.js
924
+ var init_hookRuntime = __esm({
925
+ "packages/shared/dist/hookRuntime.js"() {
926
+ "use strict";
927
+ init_runtimeSigners();
928
+ init_repositoryRoot();
929
+ init_runtimeReader();
930
+ init_runtimeSigners();
931
+ init_projectSetupHandoff();
932
+ }
933
+ });
934
+
935
+ // node_modules/graceful-fs/polyfills.js
936
+ var require_polyfills = __commonJS({
937
+ "node_modules/graceful-fs/polyfills.js"(exports, module2) {
938
+ var constants = __require("constants");
939
+ var origCwd = process.cwd;
940
+ var cwd = null;
941
+ var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
942
+ process.cwd = function() {
943
+ if (!cwd)
944
+ cwd = origCwd.call(process);
945
+ return cwd;
946
+ };
947
+ try {
948
+ process.cwd();
949
+ } catch (er) {
950
+ }
951
+ if (typeof process.chdir === "function") {
952
+ chdir = process.chdir;
953
+ process.chdir = function(d) {
954
+ cwd = null;
955
+ chdir.call(process, d);
956
+ };
957
+ if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
958
+ }
959
+ var chdir;
960
+ module2.exports = patch;
961
+ function patch(fs3) {
962
+ if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
963
+ patchLchmod(fs3);
964
+ }
965
+ if (!fs3.lutimes) {
966
+ patchLutimes(fs3);
967
+ }
968
+ fs3.chown = chownFix(fs3.chown);
969
+ fs3.fchown = chownFix(fs3.fchown);
970
+ fs3.lchown = chownFix(fs3.lchown);
971
+ fs3.chmod = chmodFix(fs3.chmod);
972
+ fs3.fchmod = chmodFix(fs3.fchmod);
973
+ fs3.lchmod = chmodFix(fs3.lchmod);
974
+ fs3.chownSync = chownFixSync(fs3.chownSync);
975
+ fs3.fchownSync = chownFixSync(fs3.fchownSync);
976
+ fs3.lchownSync = chownFixSync(fs3.lchownSync);
977
+ fs3.chmodSync = chmodFixSync(fs3.chmodSync);
978
+ fs3.fchmodSync = chmodFixSync(fs3.fchmodSync);
979
+ fs3.lchmodSync = chmodFixSync(fs3.lchmodSync);
980
+ fs3.stat = statFix(fs3.stat);
981
+ fs3.fstat = statFix(fs3.fstat);
982
+ fs3.lstat = statFix(fs3.lstat);
983
+ fs3.statSync = statFixSync(fs3.statSync);
984
+ fs3.fstatSync = statFixSync(fs3.fstatSync);
985
+ fs3.lstatSync = statFixSync(fs3.lstatSync);
986
+ if (fs3.chmod && !fs3.lchmod) {
987
+ fs3.lchmod = function(path, mode, cb) {
988
+ if (cb) process.nextTick(cb);
989
+ };
990
+ fs3.lchmodSync = function() {
991
+ };
992
+ }
993
+ if (fs3.chown && !fs3.lchown) {
994
+ fs3.lchown = function(path, uid, gid, cb) {
995
+ if (cb) process.nextTick(cb);
996
+ };
997
+ fs3.lchownSync = function() {
998
+ };
999
+ }
1000
+ if (platform === "win32") {
1001
+ fs3.rename = typeof fs3.rename !== "function" ? fs3.rename : (function(fs$rename) {
1002
+ function rename2(from, to, cb) {
1003
+ var start2 = Date.now();
1004
+ var backoff = 0;
1005
+ fs$rename(from, to, function CB(er) {
1006
+ if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start2 < 6e4) {
1007
+ setTimeout(function() {
1008
+ fs3.stat(to, function(stater, st) {
1009
+ if (stater && stater.code === "ENOENT")
1010
+ fs$rename(from, to, CB);
1011
+ else
1012
+ cb(er);
1013
+ });
1014
+ }, backoff);
1015
+ if (backoff < 100)
1016
+ backoff += 10;
1017
+ return;
1018
+ }
1019
+ if (cb) cb(er);
1020
+ });
1021
+ }
1022
+ if (Object.setPrototypeOf) Object.setPrototypeOf(rename2, fs$rename);
1023
+ return rename2;
1024
+ })(fs3.rename);
1025
+ }
1026
+ fs3.read = typeof fs3.read !== "function" ? fs3.read : (function(fs$read) {
1027
+ function read(fd, buffer, offset, length, position, callback_) {
1028
+ var callback;
1029
+ if (callback_ && typeof callback_ === "function") {
1030
+ var eagCounter = 0;
1031
+ callback = function(er, _, __) {
1032
+ if (er && er.code === "EAGAIN" && eagCounter < 10) {
1033
+ eagCounter++;
1034
+ return fs$read.call(fs3, fd, buffer, offset, length, position, callback);
1035
+ }
1036
+ callback_.apply(this, arguments);
1037
+ };
1038
+ }
1039
+ return fs$read.call(fs3, fd, buffer, offset, length, position, callback);
1040
+ }
1041
+ if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
1042
+ return read;
1043
+ })(fs3.read);
1044
+ fs3.readSync = typeof fs3.readSync !== "function" ? fs3.readSync : /* @__PURE__ */ (function(fs$readSync) {
1045
+ return function(fd, buffer, offset, length, position) {
1046
+ var eagCounter = 0;
1047
+ while (true) {
1048
+ try {
1049
+ return fs$readSync.call(fs3, fd, buffer, offset, length, position);
1050
+ } catch (er) {
1051
+ if (er.code === "EAGAIN" && eagCounter < 10) {
1052
+ eagCounter++;
1053
+ continue;
1054
+ }
1055
+ throw er;
1056
+ }
1057
+ }
1058
+ };
1059
+ })(fs3.readSync);
1060
+ function patchLchmod(fs4) {
1061
+ fs4.lchmod = function(path, mode, callback) {
1062
+ fs4.open(
1063
+ path,
1064
+ constants.O_WRONLY | constants.O_SYMLINK,
1065
+ mode,
1066
+ function(err2, fd) {
1067
+ if (err2) {
1068
+ if (callback) callback(err2);
1069
+ return;
1070
+ }
1071
+ fs4.fchmod(fd, mode, function(err3) {
1072
+ fs4.close(fd, function(err22) {
1073
+ if (callback) callback(err3 || err22);
1074
+ });
1075
+ });
1076
+ }
1077
+ );
1078
+ };
1079
+ fs4.lchmodSync = function(path, mode) {
1080
+ var fd = fs4.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode);
1081
+ var threw = true;
1082
+ var ret;
1083
+ try {
1084
+ ret = fs4.fchmodSync(fd, mode);
1085
+ threw = false;
1086
+ } finally {
1087
+ if (threw) {
1088
+ try {
1089
+ fs4.closeSync(fd);
1090
+ } catch (er) {
1091
+ }
1092
+ } else {
1093
+ fs4.closeSync(fd);
1094
+ }
1095
+ }
1096
+ return ret;
1097
+ };
1098
+ }
1099
+ function patchLutimes(fs4) {
1100
+ if (constants.hasOwnProperty("O_SYMLINK") && fs4.futimes) {
1101
+ fs4.lutimes = function(path, at, mt, cb) {
1102
+ fs4.open(path, constants.O_SYMLINK, function(er, fd) {
1103
+ if (er) {
1104
+ if (cb) cb(er);
1105
+ return;
1106
+ }
1107
+ fs4.futimes(fd, at, mt, function(er2) {
1108
+ fs4.close(fd, function(er22) {
1109
+ if (cb) cb(er2 || er22);
1110
+ });
1111
+ });
1112
+ });
1113
+ };
1114
+ fs4.lutimesSync = function(path, at, mt) {
1115
+ var fd = fs4.openSync(path, constants.O_SYMLINK);
1116
+ var ret;
1117
+ var threw = true;
1118
+ try {
1119
+ ret = fs4.futimesSync(fd, at, mt);
1120
+ threw = false;
1121
+ } finally {
1122
+ if (threw) {
1123
+ try {
1124
+ fs4.closeSync(fd);
1125
+ } catch (er) {
1126
+ }
1127
+ } else {
1128
+ fs4.closeSync(fd);
1129
+ }
1130
+ }
1131
+ return ret;
1132
+ };
1133
+ } else if (fs4.futimes) {
1134
+ fs4.lutimes = function(_a, _b, _c, cb) {
1135
+ if (cb) process.nextTick(cb);
1136
+ };
1137
+ fs4.lutimesSync = function() {
1138
+ };
1139
+ }
1140
+ }
1141
+ function chmodFix(orig) {
1142
+ if (!orig) return orig;
1143
+ return function(target, mode, cb) {
1144
+ return orig.call(fs3, target, mode, function(er) {
1145
+ if (chownErOk(er)) er = null;
1146
+ if (cb) cb.apply(this, arguments);
1147
+ });
1148
+ };
1149
+ }
1150
+ function chmodFixSync(orig) {
1151
+ if (!orig) return orig;
1152
+ return function(target, mode) {
1153
+ try {
1154
+ return orig.call(fs3, target, mode);
1155
+ } catch (er) {
1156
+ if (!chownErOk(er)) throw er;
1157
+ }
1158
+ };
1159
+ }
1160
+ function chownFix(orig) {
1161
+ if (!orig) return orig;
1162
+ return function(target, uid, gid, cb) {
1163
+ return orig.call(fs3, target, uid, gid, function(er) {
1164
+ if (chownErOk(er)) er = null;
1165
+ if (cb) cb.apply(this, arguments);
1166
+ });
1167
+ };
1168
+ }
1169
+ function chownFixSync(orig) {
1170
+ if (!orig) return orig;
1171
+ return function(target, uid, gid) {
1172
+ try {
1173
+ return orig.call(fs3, target, uid, gid);
1174
+ } catch (er) {
1175
+ if (!chownErOk(er)) throw er;
1176
+ }
1177
+ };
1178
+ }
1179
+ function statFix(orig) {
1180
+ if (!orig) return orig;
1181
+ return function(target, options, cb) {
1182
+ if (typeof options === "function") {
1183
+ cb = options;
1184
+ options = null;
1185
+ }
1186
+ function callback(er, stats) {
1187
+ if (stats) {
1188
+ if (stats.uid < 0) stats.uid += 4294967296;
1189
+ if (stats.gid < 0) stats.gid += 4294967296;
1190
+ }
1191
+ if (cb) cb.apply(this, arguments);
1192
+ }
1193
+ return options ? orig.call(fs3, target, options, callback) : orig.call(fs3, target, callback);
1194
+ };
1195
+ }
1196
+ function statFixSync(orig) {
1197
+ if (!orig) return orig;
1198
+ return function(target, options) {
1199
+ var stats = options ? orig.call(fs3, target, options) : orig.call(fs3, target);
1200
+ if (stats) {
1201
+ if (stats.uid < 0) stats.uid += 4294967296;
1202
+ if (stats.gid < 0) stats.gid += 4294967296;
1203
+ }
1204
+ return stats;
1205
+ };
1206
+ }
1207
+ function chownErOk(er) {
1208
+ if (!er)
1209
+ return true;
1210
+ if (er.code === "ENOSYS")
1211
+ return true;
1212
+ var nonroot = !process.getuid || process.getuid() !== 0;
1213
+ if (nonroot) {
1214
+ if (er.code === "EINVAL" || er.code === "EPERM")
1215
+ return true;
1216
+ }
1217
+ return false;
1218
+ }
1219
+ }
1220
+ }
1221
+ });
1222
+
1223
+ // node_modules/graceful-fs/legacy-streams.js
1224
+ var require_legacy_streams = __commonJS({
1225
+ "node_modules/graceful-fs/legacy-streams.js"(exports, module2) {
1226
+ var Stream = __require("stream").Stream;
1227
+ module2.exports = legacy;
1228
+ function legacy(fs3) {
1229
+ return {
1230
+ ReadStream,
1231
+ WriteStream
1232
+ };
1233
+ function ReadStream(path, options) {
1234
+ if (!(this instanceof ReadStream)) return new ReadStream(path, options);
1235
+ Stream.call(this);
1236
+ var self = this;
1237
+ this.path = path;
1238
+ this.fd = null;
1239
+ this.readable = true;
1240
+ this.paused = false;
1241
+ this.flags = "r";
1242
+ this.mode = 438;
1243
+ this.bufferSize = 64 * 1024;
1244
+ options = options || {};
1245
+ var keys = Object.keys(options);
1246
+ for (var index = 0, length = keys.length; index < length; index++) {
1247
+ var key = keys[index];
1248
+ this[key] = options[key];
1249
+ }
1250
+ if (this.encoding) this.setEncoding(this.encoding);
1251
+ if (this.start !== void 0) {
1252
+ if ("number" !== typeof this.start) {
1253
+ throw TypeError("start must be a Number");
1254
+ }
1255
+ if (this.end === void 0) {
1256
+ this.end = Infinity;
1257
+ } else if ("number" !== typeof this.end) {
1258
+ throw TypeError("end must be a Number");
1259
+ }
1260
+ if (this.start > this.end) {
1261
+ throw new Error("start must be <= end");
1262
+ }
1263
+ this.pos = this.start;
1264
+ }
1265
+ if (this.fd !== null) {
1266
+ process.nextTick(function() {
1267
+ self._read();
1268
+ });
1269
+ return;
1270
+ }
1271
+ fs3.open(this.path, this.flags, this.mode, function(err2, fd) {
1272
+ if (err2) {
1273
+ self.emit("error", err2);
1274
+ self.readable = false;
1275
+ return;
1276
+ }
1277
+ self.fd = fd;
1278
+ self.emit("open", fd);
1279
+ self._read();
1280
+ });
1281
+ }
1282
+ function WriteStream(path, options) {
1283
+ if (!(this instanceof WriteStream)) return new WriteStream(path, options);
1284
+ Stream.call(this);
1285
+ this.path = path;
1286
+ this.fd = null;
1287
+ this.writable = true;
1288
+ this.flags = "w";
1289
+ this.encoding = "binary";
1290
+ this.mode = 438;
1291
+ this.bytesWritten = 0;
1292
+ options = options || {};
1293
+ var keys = Object.keys(options);
1294
+ for (var index = 0, length = keys.length; index < length; index++) {
1295
+ var key = keys[index];
1296
+ this[key] = options[key];
1297
+ }
1298
+ if (this.start !== void 0) {
1299
+ if ("number" !== typeof this.start) {
1300
+ throw TypeError("start must be a Number");
1301
+ }
1302
+ if (this.start < 0) {
1303
+ throw new Error("start must be >= zero");
1304
+ }
1305
+ this.pos = this.start;
1306
+ }
1307
+ this.busy = false;
1308
+ this._queue = [];
1309
+ if (this.fd === null) {
1310
+ this._open = fs3.open;
1311
+ this._queue.push([this._open, this.path, this.flags, this.mode, void 0]);
1312
+ this.flush();
1313
+ }
1314
+ }
1315
+ }
1316
+ }
1317
+ });
1318
+
1319
+ // node_modules/graceful-fs/clone.js
1320
+ var require_clone = __commonJS({
1321
+ "node_modules/graceful-fs/clone.js"(exports, module2) {
1322
+ "use strict";
1323
+ module2.exports = clone;
1324
+ var getPrototypeOf = Object.getPrototypeOf || function(obj) {
1325
+ return obj.__proto__;
1326
+ };
1327
+ function clone(obj) {
1328
+ if (obj === null || typeof obj !== "object")
1329
+ return obj;
1330
+ if (obj instanceof Object)
1331
+ var copy = { __proto__: getPrototypeOf(obj) };
1332
+ else
1333
+ var copy = /* @__PURE__ */ Object.create(null);
1334
+ Object.getOwnPropertyNames(obj).forEach(function(key) {
1335
+ Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
1336
+ });
1337
+ return copy;
1338
+ }
1339
+ }
1340
+ });
1341
+
1342
+ // node_modules/graceful-fs/graceful-fs.js
1343
+ var require_graceful_fs = __commonJS({
1344
+ "node_modules/graceful-fs/graceful-fs.js"(exports, module2) {
1345
+ var fs3 = __require("fs");
1346
+ var polyfills = require_polyfills();
1347
+ var legacy = require_legacy_streams();
1348
+ var clone = require_clone();
1349
+ var util = __require("util");
1350
+ var gracefulQueue;
1351
+ var previousSymbol;
1352
+ if (typeof Symbol === "function" && typeof Symbol.for === "function") {
1353
+ gracefulQueue = /* @__PURE__ */ Symbol.for("graceful-fs.queue");
1354
+ previousSymbol = /* @__PURE__ */ Symbol.for("graceful-fs.previous");
1355
+ } else {
1356
+ gracefulQueue = "___graceful-fs.queue";
1357
+ previousSymbol = "___graceful-fs.previous";
1358
+ }
1359
+ function noop() {
1360
+ }
1361
+ function publishQueue(context, queue2) {
1362
+ Object.defineProperty(context, gracefulQueue, {
1363
+ get: function() {
1364
+ return queue2;
1365
+ }
1366
+ });
1367
+ }
1368
+ var debug2 = noop;
1369
+ if (util.debuglog)
1370
+ debug2 = util.debuglog("gfs4");
1371
+ else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ""))
1372
+ debug2 = function() {
1373
+ var m = util.format.apply(util, arguments);
1374
+ m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
1375
+ console.error(m);
1376
+ };
1377
+ if (!fs3[gracefulQueue]) {
1378
+ queue = global[gracefulQueue] || [];
1379
+ publishQueue(fs3, queue);
1380
+ fs3.close = (function(fs$close) {
1381
+ function close(fd, cb) {
1382
+ return fs$close.call(fs3, fd, function(err2) {
1383
+ if (!err2) {
1384
+ resetQueue();
1385
+ }
1386
+ if (typeof cb === "function")
1387
+ cb.apply(this, arguments);
1388
+ });
1389
+ }
1390
+ Object.defineProperty(close, previousSymbol, {
1391
+ value: fs$close
1392
+ });
1393
+ return close;
1394
+ })(fs3.close);
1395
+ fs3.closeSync = (function(fs$closeSync) {
1396
+ function closeSync(fd) {
1397
+ fs$closeSync.apply(fs3, arguments);
1398
+ resetQueue();
1399
+ }
1400
+ Object.defineProperty(closeSync, previousSymbol, {
1401
+ value: fs$closeSync
1402
+ });
1403
+ return closeSync;
1404
+ })(fs3.closeSync);
1405
+ if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
1406
+ process.on("exit", function() {
1407
+ debug2(fs3[gracefulQueue]);
1408
+ __require("assert").equal(fs3[gracefulQueue].length, 0);
1409
+ });
1410
+ }
1411
+ }
1412
+ var queue;
1413
+ if (!global[gracefulQueue]) {
1414
+ publishQueue(global, fs3[gracefulQueue]);
1415
+ }
1416
+ module2.exports = patch(clone(fs3));
1417
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs3.__patched) {
1418
+ module2.exports = patch(fs3);
1419
+ fs3.__patched = true;
1420
+ }
1421
+ function patch(fs4) {
1422
+ polyfills(fs4);
1423
+ fs4.gracefulify = patch;
1424
+ fs4.createReadStream = createReadStream;
1425
+ fs4.createWriteStream = createWriteStream;
1426
+ var fs$readFile = fs4.readFile;
1427
+ fs4.readFile = readFile5;
1428
+ function readFile5(path, options, cb) {
1429
+ if (typeof options === "function")
1430
+ cb = options, options = null;
1431
+ return go$readFile(path, options, cb);
1432
+ function go$readFile(path2, options2, cb2, startTime) {
1433
+ return fs$readFile(path2, options2, function(err2) {
1434
+ if (err2 && (err2.code === "EMFILE" || err2.code === "ENFILE"))
1435
+ enqueue([go$readFile, [path2, options2, cb2], err2, startTime || Date.now(), Date.now()]);
1436
+ else {
1437
+ if (typeof cb2 === "function")
1438
+ cb2.apply(this, arguments);
1439
+ }
1440
+ });
1441
+ }
1442
+ }
1443
+ var fs$writeFile = fs4.writeFile;
1444
+ fs4.writeFile = writeFile2;
1445
+ function writeFile2(path, data, options, cb) {
1446
+ if (typeof options === "function")
1447
+ cb = options, options = null;
1448
+ return go$writeFile(path, data, options, cb);
1449
+ function go$writeFile(path2, data2, options2, cb2, startTime) {
1450
+ return fs$writeFile(path2, data2, options2, function(err2) {
1451
+ if (err2 && (err2.code === "EMFILE" || err2.code === "ENFILE"))
1452
+ enqueue([go$writeFile, [path2, data2, options2, cb2], err2, startTime || Date.now(), Date.now()]);
1453
+ else {
1454
+ if (typeof cb2 === "function")
1455
+ cb2.apply(this, arguments);
1456
+ }
1457
+ });
1458
+ }
1459
+ }
1460
+ var fs$appendFile = fs4.appendFile;
1461
+ if (fs$appendFile)
1462
+ fs4.appendFile = appendFile;
1463
+ function appendFile(path, data, options, cb) {
1464
+ if (typeof options === "function")
1465
+ cb = options, options = null;
1466
+ return go$appendFile(path, data, options, cb);
1467
+ function go$appendFile(path2, data2, options2, cb2, startTime) {
1468
+ return fs$appendFile(path2, data2, options2, function(err2) {
1469
+ if (err2 && (err2.code === "EMFILE" || err2.code === "ENFILE"))
1470
+ enqueue([go$appendFile, [path2, data2, options2, cb2], err2, startTime || Date.now(), Date.now()]);
1471
+ else {
1472
+ if (typeof cb2 === "function")
1473
+ cb2.apply(this, arguments);
1474
+ }
1475
+ });
1476
+ }
1477
+ }
1478
+ var fs$copyFile = fs4.copyFile;
1479
+ if (fs$copyFile)
1480
+ fs4.copyFile = copyFile;
1481
+ function copyFile(src, dest, flags2, cb) {
1482
+ if (typeof flags2 === "function") {
1483
+ cb = flags2;
1484
+ flags2 = 0;
1485
+ }
1486
+ return go$copyFile(src, dest, flags2, cb);
1487
+ function go$copyFile(src2, dest2, flags3, cb2, startTime) {
1488
+ return fs$copyFile(src2, dest2, flags3, function(err2) {
1489
+ if (err2 && (err2.code === "EMFILE" || err2.code === "ENFILE"))
1490
+ enqueue([go$copyFile, [src2, dest2, flags3, cb2], err2, startTime || Date.now(), Date.now()]);
1491
+ else {
1492
+ if (typeof cb2 === "function")
1493
+ cb2.apply(this, arguments);
1494
+ }
1495
+ });
1496
+ }
1497
+ }
1498
+ var fs$readdir = fs4.readdir;
1499
+ fs4.readdir = readdir;
1500
+ var noReaddirOptionVersions = /^v[0-5]\./;
1501
+ function readdir(path, options, cb) {
1502
+ if (typeof options === "function")
1503
+ cb = options, options = null;
1504
+ var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path2, options2, cb2, startTime) {
1505
+ return fs$readdir(path2, fs$readdirCallback(
1506
+ path2,
1507
+ options2,
1508
+ cb2,
1509
+ startTime
1510
+ ));
1511
+ } : function go$readdir2(path2, options2, cb2, startTime) {
1512
+ return fs$readdir(path2, options2, fs$readdirCallback(
1513
+ path2,
1514
+ options2,
1515
+ cb2,
1516
+ startTime
1517
+ ));
1518
+ };
1519
+ return go$readdir(path, options, cb);
1520
+ function fs$readdirCallback(path2, options2, cb2, startTime) {
1521
+ return function(err2, files) {
1522
+ if (err2 && (err2.code === "EMFILE" || err2.code === "ENFILE"))
1523
+ enqueue([
1524
+ go$readdir,
1525
+ [path2, options2, cb2],
1526
+ err2,
1527
+ startTime || Date.now(),
1528
+ Date.now()
1529
+ ]);
1530
+ else {
1531
+ if (files && files.sort)
1532
+ files.sort();
1533
+ if (typeof cb2 === "function")
1534
+ cb2.call(this, err2, files);
1535
+ }
1536
+ };
1537
+ }
1538
+ }
1539
+ if (process.version.substr(0, 4) === "v0.8") {
1540
+ var legStreams = legacy(fs4);
1541
+ ReadStream = legStreams.ReadStream;
1542
+ WriteStream = legStreams.WriteStream;
1543
+ }
1544
+ var fs$ReadStream = fs4.ReadStream;
1545
+ if (fs$ReadStream) {
1546
+ ReadStream.prototype = Object.create(fs$ReadStream.prototype);
1547
+ ReadStream.prototype.open = ReadStream$open;
1548
+ }
1549
+ var fs$WriteStream = fs4.WriteStream;
1550
+ if (fs$WriteStream) {
1551
+ WriteStream.prototype = Object.create(fs$WriteStream.prototype);
1552
+ WriteStream.prototype.open = WriteStream$open;
1553
+ }
1554
+ Object.defineProperty(fs4, "ReadStream", {
1555
+ get: function() {
1556
+ return ReadStream;
1557
+ },
1558
+ set: function(val) {
1559
+ ReadStream = val;
1560
+ },
1561
+ enumerable: true,
1562
+ configurable: true
1563
+ });
1564
+ Object.defineProperty(fs4, "WriteStream", {
1565
+ get: function() {
1566
+ return WriteStream;
1567
+ },
1568
+ set: function(val) {
1569
+ WriteStream = val;
1570
+ },
1571
+ enumerable: true,
1572
+ configurable: true
1573
+ });
1574
+ var FileReadStream = ReadStream;
1575
+ Object.defineProperty(fs4, "FileReadStream", {
1576
+ get: function() {
1577
+ return FileReadStream;
1578
+ },
1579
+ set: function(val) {
1580
+ FileReadStream = val;
1581
+ },
1582
+ enumerable: true,
1583
+ configurable: true
1584
+ });
1585
+ var FileWriteStream = WriteStream;
1586
+ Object.defineProperty(fs4, "FileWriteStream", {
1587
+ get: function() {
1588
+ return FileWriteStream;
1589
+ },
1590
+ set: function(val) {
1591
+ FileWriteStream = val;
1592
+ },
1593
+ enumerable: true,
1594
+ configurable: true
1595
+ });
1596
+ function ReadStream(path, options) {
1597
+ if (this instanceof ReadStream)
1598
+ return fs$ReadStream.apply(this, arguments), this;
1599
+ else
1600
+ return ReadStream.apply(Object.create(ReadStream.prototype), arguments);
1601
+ }
1602
+ function ReadStream$open() {
1603
+ var that = this;
1604
+ open2(that.path, that.flags, that.mode, function(err2, fd) {
1605
+ if (err2) {
1606
+ if (that.autoClose)
1607
+ that.destroy();
1608
+ that.emit("error", err2);
1609
+ } else {
1610
+ that.fd = fd;
1611
+ that.emit("open", fd);
1612
+ that.read();
1613
+ }
1614
+ });
1615
+ }
1616
+ function WriteStream(path, options) {
1617
+ if (this instanceof WriteStream)
1618
+ return fs$WriteStream.apply(this, arguments), this;
1619
+ else
1620
+ return WriteStream.apply(Object.create(WriteStream.prototype), arguments);
1621
+ }
1622
+ function WriteStream$open() {
1623
+ var that = this;
1624
+ open2(that.path, that.flags, that.mode, function(err2, fd) {
1625
+ if (err2) {
1626
+ that.destroy();
1627
+ that.emit("error", err2);
1628
+ } else {
1629
+ that.fd = fd;
1630
+ that.emit("open", fd);
1631
+ }
1632
+ });
1633
+ }
1634
+ function createReadStream(path, options) {
1635
+ return new fs4.ReadStream(path, options);
1636
+ }
1637
+ function createWriteStream(path, options) {
1638
+ return new fs4.WriteStream(path, options);
1639
+ }
1640
+ var fs$open = fs4.open;
1641
+ fs4.open = open2;
1642
+ function open2(path, flags2, mode, cb) {
1643
+ if (typeof mode === "function")
1644
+ cb = mode, mode = null;
1645
+ return go$open(path, flags2, mode, cb);
1646
+ function go$open(path2, flags3, mode2, cb2, startTime) {
1647
+ return fs$open(path2, flags3, mode2, function(err2, fd) {
1648
+ if (err2 && (err2.code === "EMFILE" || err2.code === "ENFILE"))
1649
+ enqueue([go$open, [path2, flags3, mode2, cb2], err2, startTime || Date.now(), Date.now()]);
1650
+ else {
1651
+ if (typeof cb2 === "function")
1652
+ cb2.apply(this, arguments);
1653
+ }
1654
+ });
1655
+ }
1656
+ }
1657
+ return fs4;
1658
+ }
1659
+ function enqueue(elem) {
1660
+ debug2("ENQUEUE", elem[0].name, elem[1]);
1661
+ fs3[gracefulQueue].push(elem);
1662
+ retry();
1663
+ }
1664
+ var retryTimer;
1665
+ function resetQueue() {
1666
+ var now = Date.now();
1667
+ for (var i2 = 0; i2 < fs3[gracefulQueue].length; ++i2) {
1668
+ if (fs3[gracefulQueue][i2].length > 2) {
1669
+ fs3[gracefulQueue][i2][3] = now;
1670
+ fs3[gracefulQueue][i2][4] = now;
1671
+ }
1672
+ }
1673
+ retry();
1674
+ }
1675
+ function retry() {
1676
+ clearTimeout(retryTimer);
1677
+ retryTimer = void 0;
1678
+ if (fs3[gracefulQueue].length === 0)
1679
+ return;
1680
+ var elem = fs3[gracefulQueue].shift();
1681
+ var fn = elem[0];
1682
+ var args2 = elem[1];
1683
+ var err2 = elem[2];
1684
+ var startTime = elem[3];
1685
+ var lastTime = elem[4];
1686
+ if (startTime === void 0) {
1687
+ debug2("RETRY", fn.name, args2);
1688
+ fn.apply(null, args2);
1689
+ } else if (Date.now() - startTime >= 6e4) {
1690
+ debug2("TIMEOUT", fn.name, args2);
1691
+ var cb = args2.pop();
1692
+ if (typeof cb === "function")
1693
+ cb.call(null, err2);
1694
+ } else {
1695
+ var sinceAttempt = Date.now() - lastTime;
1696
+ var sinceStart = Math.max(lastTime - startTime, 1);
1697
+ var desiredDelay = Math.min(sinceStart * 1.2, 100);
1698
+ if (sinceAttempt >= desiredDelay) {
1699
+ debug2("RETRY", fn.name, args2);
1700
+ fn.apply(null, args2.concat([startTime]));
1701
+ } else {
1702
+ fs3[gracefulQueue].push(elem);
1703
+ }
1704
+ }
1705
+ if (retryTimer === void 0) {
1706
+ retryTimer = setTimeout(retry, 0);
1707
+ }
1708
+ }
1709
+ }
1710
+ });
1711
+
1712
+ // node_modules/retry/lib/retry_operation.js
1713
+ var require_retry_operation = __commonJS({
1714
+ "node_modules/retry/lib/retry_operation.js"(exports, module2) {
1715
+ function RetryOperation(timeouts, options) {
1716
+ if (typeof options === "boolean") {
1717
+ options = { forever: options };
1718
+ }
1719
+ this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
1720
+ this._timeouts = timeouts;
1721
+ this._options = options || {};
1722
+ this._maxRetryTime = options && options.maxRetryTime || Infinity;
1723
+ this._fn = null;
1724
+ this._errors = [];
1725
+ this._attempts = 1;
1726
+ this._operationTimeout = null;
1727
+ this._operationTimeoutCb = null;
1728
+ this._timeout = null;
1729
+ this._operationStart = null;
1730
+ if (this._options.forever) {
1731
+ this._cachedTimeouts = this._timeouts.slice(0);
1732
+ }
1733
+ }
1734
+ module2.exports = RetryOperation;
1735
+ RetryOperation.prototype.reset = function() {
1736
+ this._attempts = 1;
1737
+ this._timeouts = this._originalTimeouts;
1738
+ };
1739
+ RetryOperation.prototype.stop = function() {
1740
+ if (this._timeout) {
1741
+ clearTimeout(this._timeout);
1742
+ }
1743
+ this._timeouts = [];
1744
+ this._cachedTimeouts = null;
1745
+ };
1746
+ RetryOperation.prototype.retry = function(err2) {
1747
+ if (this._timeout) {
1748
+ clearTimeout(this._timeout);
1749
+ }
1750
+ if (!err2) {
1751
+ return false;
1752
+ }
1753
+ var currentTime = (/* @__PURE__ */ new Date()).getTime();
1754
+ if (err2 && currentTime - this._operationStart >= this._maxRetryTime) {
1755
+ this._errors.unshift(new Error("RetryOperation timeout occurred"));
1756
+ return false;
1757
+ }
1758
+ this._errors.push(err2);
1759
+ var timeout = this._timeouts.shift();
1760
+ if (timeout === void 0) {
1761
+ if (this._cachedTimeouts) {
1762
+ this._errors.splice(this._errors.length - 1, this._errors.length);
1763
+ this._timeouts = this._cachedTimeouts.slice(0);
1764
+ timeout = this._timeouts.shift();
1765
+ } else {
1766
+ return false;
1767
+ }
1768
+ }
1769
+ var self = this;
1770
+ var timer = setTimeout(function() {
1771
+ self._attempts++;
1772
+ if (self._operationTimeoutCb) {
1773
+ self._timeout = setTimeout(function() {
1774
+ self._operationTimeoutCb(self._attempts);
1775
+ }, self._operationTimeout);
1776
+ if (self._options.unref) {
1777
+ self._timeout.unref();
1778
+ }
1779
+ }
1780
+ self._fn(self._attempts);
1781
+ }, timeout);
1782
+ if (this._options.unref) {
1783
+ timer.unref();
1784
+ }
1785
+ return true;
1786
+ };
1787
+ RetryOperation.prototype.attempt = function(fn, timeoutOps) {
1788
+ this._fn = fn;
1789
+ if (timeoutOps) {
1790
+ if (timeoutOps.timeout) {
1791
+ this._operationTimeout = timeoutOps.timeout;
1792
+ }
1793
+ if (timeoutOps.cb) {
1794
+ this._operationTimeoutCb = timeoutOps.cb;
1795
+ }
1796
+ }
1797
+ var self = this;
1798
+ if (this._operationTimeoutCb) {
1799
+ this._timeout = setTimeout(function() {
1800
+ self._operationTimeoutCb();
1801
+ }, self._operationTimeout);
1802
+ }
1803
+ this._operationStart = (/* @__PURE__ */ new Date()).getTime();
1804
+ this._fn(this._attempts);
1805
+ };
1806
+ RetryOperation.prototype.try = function(fn) {
1807
+ console.log("Using RetryOperation.try() is deprecated");
1808
+ this.attempt(fn);
1809
+ };
1810
+ RetryOperation.prototype.start = function(fn) {
1811
+ console.log("Using RetryOperation.start() is deprecated");
1812
+ this.attempt(fn);
1813
+ };
1814
+ RetryOperation.prototype.start = RetryOperation.prototype.try;
1815
+ RetryOperation.prototype.errors = function() {
1816
+ return this._errors;
1817
+ };
1818
+ RetryOperation.prototype.attempts = function() {
1819
+ return this._attempts;
1820
+ };
1821
+ RetryOperation.prototype.mainError = function() {
1822
+ if (this._errors.length === 0) {
1823
+ return null;
1824
+ }
1825
+ var counts2 = {};
1826
+ var mainError = null;
1827
+ var mainErrorCount = 0;
1828
+ for (var i2 = 0; i2 < this._errors.length; i2++) {
1829
+ var error = this._errors[i2];
1830
+ var message = error.message;
1831
+ var count = (counts2[message] || 0) + 1;
1832
+ counts2[message] = count;
1833
+ if (count >= mainErrorCount) {
1834
+ mainError = error;
1835
+ mainErrorCount = count;
1836
+ }
1837
+ }
1838
+ return mainError;
1839
+ };
1840
+ }
1841
+ });
1842
+
1843
+ // node_modules/retry/lib/retry.js
1844
+ var require_retry = __commonJS({
1845
+ "node_modules/retry/lib/retry.js"(exports) {
1846
+ var RetryOperation = require_retry_operation();
1847
+ exports.operation = function(options) {
1848
+ var timeouts = exports.timeouts(options);
1849
+ return new RetryOperation(timeouts, {
1850
+ forever: options && options.forever,
1851
+ unref: options && options.unref,
1852
+ maxRetryTime: options && options.maxRetryTime
1853
+ });
1854
+ };
1855
+ exports.timeouts = function(options) {
1856
+ if (options instanceof Array) {
1857
+ return [].concat(options);
1858
+ }
1859
+ var opts = {
1860
+ retries: 10,
1861
+ factor: 2,
1862
+ minTimeout: 1 * 1e3,
1863
+ maxTimeout: Infinity,
1864
+ randomize: false
1865
+ };
1866
+ for (var key in options) {
1867
+ opts[key] = options[key];
1868
+ }
1869
+ if (opts.minTimeout > opts.maxTimeout) {
1870
+ throw new Error("minTimeout is greater than maxTimeout");
1871
+ }
1872
+ var timeouts = [];
1873
+ for (var i2 = 0; i2 < opts.retries; i2++) {
1874
+ timeouts.push(this.createTimeout(i2, opts));
1875
+ }
1876
+ if (options && options.forever && !timeouts.length) {
1877
+ timeouts.push(this.createTimeout(i2, opts));
1878
+ }
1879
+ timeouts.sort(function(a, b) {
1880
+ return a - b;
1881
+ });
1882
+ return timeouts;
1883
+ };
1884
+ exports.createTimeout = function(attempt, opts) {
1885
+ var random = opts.randomize ? Math.random() + 1 : 1;
1886
+ var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
1887
+ timeout = Math.min(timeout, opts.maxTimeout);
1888
+ return timeout;
1889
+ };
1890
+ exports.wrap = function(obj, options, methods) {
1891
+ if (options instanceof Array) {
1892
+ methods = options;
1893
+ options = null;
1894
+ }
1895
+ if (!methods) {
1896
+ methods = [];
1897
+ for (var key in obj) {
1898
+ if (typeof obj[key] === "function") {
1899
+ methods.push(key);
1900
+ }
1901
+ }
1902
+ }
1903
+ for (var i2 = 0; i2 < methods.length; i2++) {
1904
+ var method = methods[i2];
1905
+ var original = obj[method];
1906
+ obj[method] = function retryWrapper(original2) {
1907
+ var op = exports.operation(options);
1908
+ var args2 = Array.prototype.slice.call(arguments, 1);
1909
+ var callback = args2.pop();
1910
+ args2.push(function(err2) {
1911
+ if (op.retry(err2)) {
1912
+ return;
1913
+ }
1914
+ if (err2) {
1915
+ arguments[0] = op.mainError();
1916
+ }
1917
+ callback.apply(this, arguments);
1918
+ });
1919
+ op.attempt(function() {
1920
+ original2.apply(obj, args2);
1921
+ });
1922
+ }.bind(obj, original);
1923
+ obj[method].options = options;
1924
+ }
1925
+ };
1926
+ }
1927
+ });
1928
+
1929
+ // node_modules/retry/index.js
1930
+ var require_retry2 = __commonJS({
1931
+ "node_modules/retry/index.js"(exports, module2) {
1932
+ module2.exports = require_retry();
1933
+ }
1934
+ });
1935
+
1936
+ // node_modules/proper-lockfile/node_modules/signal-exit/signals.js
1937
+ var require_signals = __commonJS({
1938
+ "node_modules/proper-lockfile/node_modules/signal-exit/signals.js"(exports, module2) {
1939
+ module2.exports = [
1940
+ "SIGABRT",
1941
+ "SIGALRM",
1942
+ "SIGHUP",
1943
+ "SIGINT",
1944
+ "SIGTERM"
1945
+ ];
1946
+ if (process.platform !== "win32") {
1947
+ module2.exports.push(
1948
+ "SIGVTALRM",
1949
+ "SIGXCPU",
1950
+ "SIGXFSZ",
1951
+ "SIGUSR2",
1952
+ "SIGTRAP",
1953
+ "SIGSYS",
1954
+ "SIGQUIT",
1955
+ "SIGIOT"
1956
+ // should detect profiler and enable/disable accordingly.
1957
+ // see #21
1958
+ // 'SIGPROF'
1959
+ );
1960
+ }
1961
+ if (process.platform === "linux") {
1962
+ module2.exports.push(
1963
+ "SIGIO",
1964
+ "SIGPOLL",
1965
+ "SIGPWR",
1966
+ "SIGSTKFLT",
1967
+ "SIGUNUSED"
1968
+ );
1969
+ }
1970
+ }
1971
+ });
1972
+
1973
+ // node_modules/proper-lockfile/node_modules/signal-exit/index.js
1974
+ var require_signal_exit = __commonJS({
1975
+ "node_modules/proper-lockfile/node_modules/signal-exit/index.js"(exports, module2) {
1976
+ var process2 = global.process;
1977
+ var processOk = function(process3) {
1978
+ return process3 && typeof process3 === "object" && typeof process3.removeListener === "function" && typeof process3.emit === "function" && typeof process3.reallyExit === "function" && typeof process3.listeners === "function" && typeof process3.kill === "function" && typeof process3.pid === "number" && typeof process3.on === "function";
1979
+ };
1980
+ if (!processOk(process2)) {
1981
+ module2.exports = function() {
1982
+ return function() {
1983
+ };
1984
+ };
1985
+ } else {
1986
+ assert = __require("assert");
1987
+ signals = require_signals();
1988
+ isWin = /^win/i.test(process2.platform);
1989
+ EE = __require("events");
1990
+ if (typeof EE !== "function") {
1991
+ EE = EE.EventEmitter;
1992
+ }
1993
+ if (process2.__signal_exit_emitter__) {
1994
+ emitter = process2.__signal_exit_emitter__;
1995
+ } else {
1996
+ emitter = process2.__signal_exit_emitter__ = new EE();
1997
+ emitter.count = 0;
1998
+ emitter.emitted = {};
1999
+ }
2000
+ if (!emitter.infinite) {
2001
+ emitter.setMaxListeners(Infinity);
2002
+ emitter.infinite = true;
2003
+ }
2004
+ module2.exports = function(cb, opts) {
2005
+ if (!processOk(global.process)) {
2006
+ return function() {
2007
+ };
2008
+ }
2009
+ assert.equal(typeof cb, "function", "a callback must be provided for exit handler");
2010
+ if (loaded === false) {
2011
+ load();
2012
+ }
2013
+ var ev = "exit";
2014
+ if (opts && opts.alwaysLast) {
2015
+ ev = "afterexit";
2016
+ }
2017
+ var remove = function() {
2018
+ emitter.removeListener(ev, cb);
2019
+ if (emitter.listeners("exit").length === 0 && emitter.listeners("afterexit").length === 0) {
2020
+ unload();
2021
+ }
2022
+ };
2023
+ emitter.on(ev, cb);
2024
+ return remove;
2025
+ };
2026
+ unload = function unload2() {
2027
+ if (!loaded || !processOk(global.process)) {
2028
+ return;
2029
+ }
2030
+ loaded = false;
2031
+ signals.forEach(function(sig) {
2032
+ try {
2033
+ process2.removeListener(sig, sigListeners[sig]);
2034
+ } catch (er) {
2035
+ }
2036
+ });
2037
+ process2.emit = originalProcessEmit;
2038
+ process2.reallyExit = originalProcessReallyExit;
2039
+ emitter.count -= 1;
2040
+ };
2041
+ module2.exports.unload = unload;
2042
+ emit = function emit2(event, code, signal) {
2043
+ if (emitter.emitted[event]) {
2044
+ return;
2045
+ }
2046
+ emitter.emitted[event] = true;
2047
+ emitter.emit(event, code, signal);
2048
+ };
2049
+ sigListeners = {};
2050
+ signals.forEach(function(sig) {
2051
+ sigListeners[sig] = function listener() {
2052
+ if (!processOk(global.process)) {
2053
+ return;
2054
+ }
2055
+ var listeners = process2.listeners(sig);
2056
+ if (listeners.length === emitter.count) {
2057
+ unload();
2058
+ emit("exit", null, sig);
2059
+ emit("afterexit", null, sig);
2060
+ if (isWin && sig === "SIGHUP") {
2061
+ sig = "SIGINT";
2062
+ }
2063
+ process2.kill(process2.pid, sig);
2064
+ }
2065
+ };
2066
+ });
2067
+ module2.exports.signals = function() {
2068
+ return signals;
2069
+ };
2070
+ loaded = false;
2071
+ load = function load2() {
2072
+ if (loaded || !processOk(global.process)) {
2073
+ return;
2074
+ }
2075
+ loaded = true;
2076
+ emitter.count += 1;
2077
+ signals = signals.filter(function(sig) {
2078
+ try {
2079
+ process2.on(sig, sigListeners[sig]);
2080
+ return true;
2081
+ } catch (er) {
2082
+ return false;
2083
+ }
2084
+ });
2085
+ process2.emit = processEmit;
2086
+ process2.reallyExit = processReallyExit;
2087
+ };
2088
+ module2.exports.load = load;
2089
+ originalProcessReallyExit = process2.reallyExit;
2090
+ processReallyExit = function processReallyExit2(code) {
2091
+ if (!processOk(global.process)) {
2092
+ return;
2093
+ }
2094
+ process2.exitCode = code || /* istanbul ignore next */
2095
+ 0;
2096
+ emit("exit", process2.exitCode, null);
2097
+ emit("afterexit", process2.exitCode, null);
2098
+ originalProcessReallyExit.call(process2, process2.exitCode);
2099
+ };
2100
+ originalProcessEmit = process2.emit;
2101
+ processEmit = function processEmit2(ev, arg) {
2102
+ if (ev === "exit" && processOk(global.process)) {
2103
+ if (arg !== void 0) {
2104
+ process2.exitCode = arg;
2105
+ }
2106
+ var ret = originalProcessEmit.apply(this, arguments);
2107
+ emit("exit", process2.exitCode, null);
2108
+ emit("afterexit", process2.exitCode, null);
2109
+ return ret;
2110
+ } else {
2111
+ return originalProcessEmit.apply(this, arguments);
2112
+ }
2113
+ };
2114
+ }
2115
+ var assert;
2116
+ var signals;
2117
+ var isWin;
2118
+ var EE;
2119
+ var emitter;
2120
+ var unload;
2121
+ var emit;
2122
+ var sigListeners;
2123
+ var loaded;
2124
+ var load;
2125
+ var originalProcessReallyExit;
2126
+ var processReallyExit;
2127
+ var originalProcessEmit;
2128
+ var processEmit;
2129
+ }
2130
+ });
2131
+
2132
+ // node_modules/proper-lockfile/lib/mtime-precision.js
2133
+ var require_mtime_precision = __commonJS({
2134
+ "node_modules/proper-lockfile/lib/mtime-precision.js"(exports, module2) {
812
2135
  "use strict";
813
- init_projectIdentityFile();
814
- GIT_TIMEOUT_MS = 2e3;
815
- GIT_ENV_KEYS = [
816
- "PATH",
817
- "HOME",
818
- "LANG",
819
- "LC_ALL",
820
- "SYSTEMROOT",
821
- "TEMP",
822
- "TMP",
823
- "USERPROFILE"
824
- ];
2136
+ var cacheSymbol = /* @__PURE__ */ Symbol();
2137
+ function probe(file, fs3, callback) {
2138
+ const cachedPrecision = fs3[cacheSymbol];
2139
+ if (cachedPrecision) {
2140
+ return fs3.stat(file, (err2, stat) => {
2141
+ if (err2) {
2142
+ return callback(err2);
2143
+ }
2144
+ callback(null, stat.mtime, cachedPrecision);
2145
+ });
2146
+ }
2147
+ const mtime = new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
2148
+ fs3.utimes(file, mtime, mtime, (err2) => {
2149
+ if (err2) {
2150
+ return callback(err2);
2151
+ }
2152
+ fs3.stat(file, (err3, stat) => {
2153
+ if (err3) {
2154
+ return callback(err3);
2155
+ }
2156
+ const precision = stat.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
2157
+ Object.defineProperty(fs3, cacheSymbol, { value: precision });
2158
+ callback(null, stat.mtime, precision);
2159
+ });
2160
+ });
2161
+ }
2162
+ function getMtime(precision) {
2163
+ let now = Date.now();
2164
+ if (precision === "s") {
2165
+ now = Math.ceil(now / 1e3) * 1e3;
2166
+ }
2167
+ return new Date(now);
2168
+ }
2169
+ module2.exports.probe = probe;
2170
+ module2.exports.getMtime = getMtime;
825
2171
  }
826
2172
  });
827
2173
 
828
- // packages/shared/dist/runtimeReader.js
829
- var init_runtimeReader = __esm({
830
- "packages/shared/dist/runtimeReader.js"() {
2174
+ // node_modules/proper-lockfile/lib/lockfile.js
2175
+ var require_lockfile = __commonJS({
2176
+ "node_modules/proper-lockfile/lib/lockfile.js"(exports, module2) {
831
2177
  "use strict";
832
- init_runtimeSigners();
833
- init_runtimeSigners();
2178
+ var path = __require("path");
2179
+ var fs3 = require_graceful_fs();
2180
+ var retry = require_retry2();
2181
+ var onExit = require_signal_exit();
2182
+ var mtimePrecision = require_mtime_precision();
2183
+ var locks = {};
2184
+ function getLockFile(file, options) {
2185
+ return options.lockfilePath || `${file}.lock`;
2186
+ }
2187
+ function resolveCanonicalPath(file, options, callback) {
2188
+ if (!options.realpath) {
2189
+ return callback(null, path.resolve(file));
2190
+ }
2191
+ options.fs.realpath(file, callback);
2192
+ }
2193
+ function acquireLock(file, options, callback) {
2194
+ const lockfilePath = getLockFile(file, options);
2195
+ options.fs.mkdir(lockfilePath, (err2) => {
2196
+ if (!err2) {
2197
+ return mtimePrecision.probe(lockfilePath, options.fs, (err3, mtime, mtimePrecision2) => {
2198
+ if (err3) {
2199
+ options.fs.rmdir(lockfilePath, () => {
2200
+ });
2201
+ return callback(err3);
2202
+ }
2203
+ callback(null, mtime, mtimePrecision2);
2204
+ });
2205
+ }
2206
+ if (err2.code !== "EEXIST") {
2207
+ return callback(err2);
2208
+ }
2209
+ if (options.stale <= 0) {
2210
+ return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
2211
+ }
2212
+ options.fs.stat(lockfilePath, (err3, stat) => {
2213
+ if (err3) {
2214
+ if (err3.code === "ENOENT") {
2215
+ return acquireLock(file, { ...options, stale: 0 }, callback);
2216
+ }
2217
+ return callback(err3);
2218
+ }
2219
+ if (!isLockStale(stat, options)) {
2220
+ return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
2221
+ }
2222
+ removeLock(file, options, (err4) => {
2223
+ if (err4) {
2224
+ return callback(err4);
2225
+ }
2226
+ acquireLock(file, { ...options, stale: 0 }, callback);
2227
+ });
2228
+ });
2229
+ });
2230
+ }
2231
+ function isLockStale(stat, options) {
2232
+ return stat.mtime.getTime() < Date.now() - options.stale;
2233
+ }
2234
+ function removeLock(file, options, callback) {
2235
+ options.fs.rmdir(getLockFile(file, options), (err2) => {
2236
+ if (err2 && err2.code !== "ENOENT") {
2237
+ return callback(err2);
2238
+ }
2239
+ callback();
2240
+ });
2241
+ }
2242
+ function updateLock(file, options) {
2243
+ const lock2 = locks[file];
2244
+ if (lock2.updateTimeout) {
2245
+ return;
2246
+ }
2247
+ lock2.updateDelay = lock2.updateDelay || options.update;
2248
+ lock2.updateTimeout = setTimeout(() => {
2249
+ lock2.updateTimeout = null;
2250
+ options.fs.stat(lock2.lockfilePath, (err2, stat) => {
2251
+ const isOverThreshold = lock2.lastUpdate + options.stale < Date.now();
2252
+ if (err2) {
2253
+ if (err2.code === "ENOENT" || isOverThreshold) {
2254
+ return setLockAsCompromised(file, lock2, Object.assign(err2, { code: "ECOMPROMISED" }));
2255
+ }
2256
+ lock2.updateDelay = 1e3;
2257
+ return updateLock(file, options);
2258
+ }
2259
+ const isMtimeOurs = lock2.mtime.getTime() === stat.mtime.getTime();
2260
+ if (!isMtimeOurs) {
2261
+ return setLockAsCompromised(
2262
+ file,
2263
+ lock2,
2264
+ Object.assign(
2265
+ new Error("Unable to update lock within the stale threshold"),
2266
+ { code: "ECOMPROMISED" }
2267
+ )
2268
+ );
2269
+ }
2270
+ const mtime = mtimePrecision.getMtime(lock2.mtimePrecision);
2271
+ options.fs.utimes(lock2.lockfilePath, mtime, mtime, (err3) => {
2272
+ const isOverThreshold2 = lock2.lastUpdate + options.stale < Date.now();
2273
+ if (lock2.released) {
2274
+ return;
2275
+ }
2276
+ if (err3) {
2277
+ if (err3.code === "ENOENT" || isOverThreshold2) {
2278
+ return setLockAsCompromised(file, lock2, Object.assign(err3, { code: "ECOMPROMISED" }));
2279
+ }
2280
+ lock2.updateDelay = 1e3;
2281
+ return updateLock(file, options);
2282
+ }
2283
+ lock2.mtime = mtime;
2284
+ lock2.lastUpdate = Date.now();
2285
+ lock2.updateDelay = null;
2286
+ updateLock(file, options);
2287
+ });
2288
+ });
2289
+ }, lock2.updateDelay);
2290
+ if (lock2.updateTimeout.unref) {
2291
+ lock2.updateTimeout.unref();
2292
+ }
2293
+ }
2294
+ function setLockAsCompromised(file, lock2, err2) {
2295
+ lock2.released = true;
2296
+ if (lock2.updateTimeout) {
2297
+ clearTimeout(lock2.updateTimeout);
2298
+ }
2299
+ if (locks[file] === lock2) {
2300
+ delete locks[file];
2301
+ }
2302
+ lock2.options.onCompromised(err2);
2303
+ }
2304
+ function lock(file, options, callback) {
2305
+ options = {
2306
+ stale: 1e4,
2307
+ update: null,
2308
+ realpath: true,
2309
+ retries: 0,
2310
+ fs: fs3,
2311
+ onCompromised: (err2) => {
2312
+ throw err2;
2313
+ },
2314
+ ...options
2315
+ };
2316
+ options.retries = options.retries || 0;
2317
+ options.retries = typeof options.retries === "number" ? { retries: options.retries } : options.retries;
2318
+ options.stale = Math.max(options.stale || 0, 2e3);
2319
+ options.update = options.update == null ? options.stale / 2 : options.update || 0;
2320
+ options.update = Math.max(Math.min(options.update, options.stale / 2), 1e3);
2321
+ resolveCanonicalPath(file, options, (err2, file2) => {
2322
+ if (err2) {
2323
+ return callback(err2);
2324
+ }
2325
+ const operation = retry.operation(options.retries);
2326
+ operation.attempt(() => {
2327
+ acquireLock(file2, options, (err3, mtime, mtimePrecision2) => {
2328
+ if (operation.retry(err3)) {
2329
+ return;
2330
+ }
2331
+ if (err3) {
2332
+ return callback(operation.mainError());
2333
+ }
2334
+ const lock2 = locks[file2] = {
2335
+ lockfilePath: getLockFile(file2, options),
2336
+ mtime,
2337
+ mtimePrecision: mtimePrecision2,
2338
+ options,
2339
+ lastUpdate: Date.now()
2340
+ };
2341
+ updateLock(file2, options);
2342
+ callback(null, (releasedCallback) => {
2343
+ if (lock2.released) {
2344
+ return releasedCallback && releasedCallback(Object.assign(new Error("Lock is already released"), { code: "ERELEASED" }));
2345
+ }
2346
+ unlock(file2, { ...options, realpath: false }, releasedCallback);
2347
+ });
2348
+ });
2349
+ });
2350
+ });
2351
+ }
2352
+ function unlock(file, options, callback) {
2353
+ options = {
2354
+ fs: fs3,
2355
+ realpath: true,
2356
+ ...options
2357
+ };
2358
+ resolveCanonicalPath(file, options, (err2, file2) => {
2359
+ if (err2) {
2360
+ return callback(err2);
2361
+ }
2362
+ const lock2 = locks[file2];
2363
+ if (!lock2) {
2364
+ return callback(Object.assign(new Error("Lock is not acquired/owned by you"), { code: "ENOTACQUIRED" }));
2365
+ }
2366
+ lock2.updateTimeout && clearTimeout(lock2.updateTimeout);
2367
+ lock2.released = true;
2368
+ delete locks[file2];
2369
+ removeLock(file2, options, callback);
2370
+ });
2371
+ }
2372
+ function check(file, options, callback) {
2373
+ options = {
2374
+ stale: 1e4,
2375
+ realpath: true,
2376
+ fs: fs3,
2377
+ ...options
2378
+ };
2379
+ options.stale = Math.max(options.stale || 0, 2e3);
2380
+ resolveCanonicalPath(file, options, (err2, file2) => {
2381
+ if (err2) {
2382
+ return callback(err2);
2383
+ }
2384
+ options.fs.stat(getLockFile(file2, options), (err3, stat) => {
2385
+ if (err3) {
2386
+ return err3.code === "ENOENT" ? callback(null, false) : callback(err3);
2387
+ }
2388
+ return callback(null, !isLockStale(stat, options));
2389
+ });
2390
+ });
2391
+ }
2392
+ function getLocks() {
2393
+ return locks;
2394
+ }
2395
+ onExit(() => {
2396
+ for (const file in locks) {
2397
+ const options = locks[file].options;
2398
+ try {
2399
+ options.fs.rmdirSync(getLockFile(file, options));
2400
+ } catch (e) {
2401
+ }
2402
+ }
2403
+ });
2404
+ module2.exports.lock = lock;
2405
+ module2.exports.unlock = unlock;
2406
+ module2.exports.check = check;
2407
+ module2.exports.getLocks = getLocks;
834
2408
  }
835
2409
  });
836
2410
 
837
- // packages/shared/dist/projectSetupHandoff.js
838
- var init_projectSetupHandoff = __esm({
839
- "packages/shared/dist/projectSetupHandoff.js"() {
2411
+ // node_modules/proper-lockfile/lib/adapter.js
2412
+ var require_adapter = __commonJS({
2413
+ "node_modules/proper-lockfile/lib/adapter.js"(exports, module2) {
840
2414
  "use strict";
841
- init_runtimeSigners();
842
- init_runtimeReader();
2415
+ var fs3 = require_graceful_fs();
2416
+ function createSyncFs(fs4) {
2417
+ const methods = ["mkdir", "realpath", "stat", "rmdir", "utimes"];
2418
+ const newFs = { ...fs4 };
2419
+ methods.forEach((method) => {
2420
+ newFs[method] = (...args2) => {
2421
+ const callback = args2.pop();
2422
+ let ret;
2423
+ try {
2424
+ ret = fs4[`${method}Sync`](...args2);
2425
+ } catch (err2) {
2426
+ return callback(err2);
2427
+ }
2428
+ callback(null, ret);
2429
+ };
2430
+ });
2431
+ return newFs;
2432
+ }
2433
+ function toPromise(method) {
2434
+ return (...args2) => new Promise((resolve3, reject) => {
2435
+ args2.push((err2, result) => {
2436
+ if (err2) {
2437
+ reject(err2);
2438
+ } else {
2439
+ resolve3(result);
2440
+ }
2441
+ });
2442
+ method(...args2);
2443
+ });
2444
+ }
2445
+ function toSync(method) {
2446
+ return (...args2) => {
2447
+ let err2;
2448
+ let result;
2449
+ args2.push((_err, _result) => {
2450
+ err2 = _err;
2451
+ result = _result;
2452
+ });
2453
+ method(...args2);
2454
+ if (err2) {
2455
+ throw err2;
2456
+ }
2457
+ return result;
2458
+ };
2459
+ }
2460
+ function toSyncOptions(options) {
2461
+ options = { ...options };
2462
+ options.fs = createSyncFs(options.fs || fs3);
2463
+ if (typeof options.retries === "number" && options.retries > 0 || options.retries && typeof options.retries.retries === "number" && options.retries.retries > 0) {
2464
+ throw Object.assign(new Error("Cannot use retries with the sync api"), { code: "ESYNC" });
2465
+ }
2466
+ return options;
2467
+ }
2468
+ module2.exports = {
2469
+ toPromise,
2470
+ toSync,
2471
+ toSyncOptions
2472
+ };
843
2473
  }
844
2474
  });
845
2475
 
846
- // packages/shared/dist/hookRuntime.js
847
- var init_hookRuntime = __esm({
848
- "packages/shared/dist/hookRuntime.js"() {
2476
+ // node_modules/proper-lockfile/index.js
2477
+ var require_proper_lockfile = __commonJS({
2478
+ "node_modules/proper-lockfile/index.js"(exports, module2) {
849
2479
  "use strict";
850
- init_runtimeSigners();
851
- init_repositoryRoot();
852
- init_runtimeReader();
853
- init_runtimeSigners();
854
- init_projectSetupHandoff();
2480
+ var lockfile = require_lockfile();
2481
+ var { toPromise, toSync, toSyncOptions } = require_adapter();
2482
+ async function lock(file, options) {
2483
+ const release = await toPromise(lockfile.lock)(file, options);
2484
+ return toPromise(release);
2485
+ }
2486
+ function lockSync(file, options) {
2487
+ const release = toSync(lockfile.lock)(file, toSyncOptions(options));
2488
+ return toSync(release);
2489
+ }
2490
+ function unlock(file, options) {
2491
+ return toPromise(lockfile.unlock)(file, options);
2492
+ }
2493
+ function unlockSync(file, options) {
2494
+ return toSync(lockfile.unlock)(file, toSyncOptions(options));
2495
+ }
2496
+ function check(file, options) {
2497
+ return toPromise(lockfile.check)(file, options);
2498
+ }
2499
+ function checkSync(file, options) {
2500
+ return toSync(lockfile.check)(file, toSyncOptions(options));
2501
+ }
2502
+ module2.exports = lock;
2503
+ module2.exports.lock = lock;
2504
+ module2.exports.unlock = unlock;
2505
+ module2.exports.lockSync = lockSync;
2506
+ module2.exports.unlockSync = unlockSync;
2507
+ module2.exports.check = check;
2508
+ module2.exports.checkSync = checkSync;
855
2509
  }
856
2510
  });
857
2511
 
858
2512
  // packages/cli/src/router.ts
859
- import { humanReason, humanReport, humanIdentityState } from "./humanReason.js";
2513
+ import {
2514
+ humanReason,
2515
+ humanReport,
2516
+ humanIdentityState,
2517
+ SCANNER_CONSENT_MESSAGE,
2518
+ SCANNER_UPDATE_CONSENT_MESSAGE
2519
+ } from "./humanReason.js";
2520
+ import { consentDecision, consentLines } from "./consent.js";
860
2521
  import { helpScreen } from "./help.js";
861
2522
  import { enableScanner, updateScannerRoots } from "./scanner/enable.js";
862
- import { controlScanner, scannerReceipt } from "./scanner/control.js";
863
- import { updateScanner } from "./scanner/update.js";
2523
+ import {
2524
+ ABANDONED_PAUSE_RESUMED,
2525
+ controlScanner,
2526
+ pausedForConsent,
2527
+ scannerReceipt
2528
+ } from "./scanner/control.js";
2529
+ import { ScannerConsentRequired, updateScanner } from "./scanner/update.js";
864
2530
  import { deleteScannerIndex } from "./scanner/data.js";
865
2531
  import { devReadiness } from "./runtime/releaseSource.js";
866
2532
  import {
@@ -2375,8 +4041,8 @@ var Language = class _Language {
2375
4041
  if (input instanceof Uint8Array) {
2376
4042
  binary2 = input;
2377
4043
  } else if (globalThis.process?.versions.node) {
2378
- const fs2 = await import("fs/promises");
2379
- binary2 = await fs2.readFile(input);
4044
+ const fs22 = await import("fs/promises");
4045
+ binary2 = await fs22.readFile(input);
2380
4046
  } else {
2381
4047
  const response = await fetch(input);
2382
4048
  if (!response.ok) {
@@ -2478,13 +4144,13 @@ async function Module2(moduleArg = {}) {
2478
4144
  }
2479
4145
  readAsync = /* @__PURE__ */ __name(async (url) => {
2480
4146
  if (isFileURI(url)) {
2481
- return new Promise((resolve2, reject) => {
4147
+ return new Promise((resolve3, reject) => {
2482
4148
  var xhr = new XMLHttpRequest();
2483
4149
  xhr.open("GET", url, true);
2484
4150
  xhr.responseType = "arraybuffer";
2485
4151
  xhr.onload = () => {
2486
4152
  if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
2487
- resolve2(xhr.response);
4153
+ resolve3(xhr.response);
2488
4154
  return;
2489
4155
  }
2490
4156
  reject(xhr.status);
@@ -2680,9 +4346,9 @@ async function Module2(moduleArg = {}) {
2680
4346
  __name(receiveInstantiationResult, "receiveInstantiationResult");
2681
4347
  var info22 = getWasmImports();
2682
4348
  if (Module["instantiateWasm"]) {
2683
- return new Promise((resolve2, reject) => {
4349
+ return new Promise((resolve3, reject) => {
2684
4350
  Module["instantiateWasm"](info22, (mod, inst) => {
2685
- resolve2(receiveInstance(mod, inst));
4351
+ resolve3(receiveInstance(mod, inst));
2686
4352
  });
2687
4353
  });
2688
4354
  }
@@ -4013,8 +5679,8 @@ async function Module2(moduleArg = {}) {
4013
5679
  if (runtimeInitialized) {
4014
5680
  moduleRtn = Module;
4015
5681
  } else {
4016
- moduleRtn = new Promise((resolve2, reject) => {
4017
- readyPromiseResolve = resolve2;
5682
+ moduleRtn = new Promise((resolve3, reject) => {
5683
+ readyPromiseResolve = resolve3;
4018
5684
  readyPromiseReject = reject;
4019
5685
  });
4020
5686
  }
@@ -5161,18 +6827,259 @@ function apiOrigin(env = process.env) {
5161
6827
 
5162
6828
  // packages/local-setup/dist/storage.js
5163
6829
  init_hookRuntime();
5164
- import { homedir as homedir2 } from "node:os";
5165
- import { dirname as dirname3, join as join4, win32, posix } from "node:path";
5166
6830
  init_hookRuntime();
6831
+ import { createHash, randomUUID } from "node:crypto";
6832
+ import { execFile as nodeExecFile } from "node:child_process";
6833
+ import fs2 from "node:fs";
6834
+ import { open, rename, readFile as readFile3, mkdir, lstat as lstat3, chmod, writeFile, unlink, rmdir } from "node:fs/promises";
6835
+ import { homedir as homedir2 } from "node:os";
6836
+ import { dirname as dirname4, join as join5, win32 as win322, posix } from "node:path";
6837
+ import { setTimeout as delay } from "node:timers/promises";
6838
+ var lockfileKey = /* @__PURE__ */ Symbol.for("mnemonik.proper-lockfile");
6839
+ function sharedLockfile() {
6840
+ const shared = globalThis;
6841
+ return shared[lockfileKey] ??= Promise.resolve().then(() => __toESM(require_proper_lockfile(), 1)).then((module2) => module2.default);
6842
+ }
6843
+ var codeIs = (error, code) => error.code === code;
5167
6844
  function stateDirectory(platform = process.platform, env = process.env, home = homedir2()) {
5168
6845
  if (env.MNEMONIK_STATE_DIR)
5169
6846
  return env.MNEMONIK_STATE_DIR;
5170
6847
  if (platform === "win32")
5171
- return win32.join(env.LOCALAPPDATA || win32.join(home, "AppData", "Local"), "Mnemonik");
6848
+ return win322.join(env.LOCALAPPDATA || win322.join(home, "AppData", "Local"), "Mnemonik");
5172
6849
  if (platform === "darwin")
5173
6850
  return posix.join(home, "Library", "Application Support", "Mnemonik");
5174
6851
  return posix.join(env.XDG_STATE_HOME || posix.join(home, ".local", "state"), "mnemonik");
5175
6852
  }
6853
+ async function readBytes(path) {
6854
+ try {
6855
+ if (!(await lstat3(path)).isFile())
6856
+ throw new Error("setup_requires_regular_file");
6857
+ return await readFile3(path);
6858
+ } catch (error) {
6859
+ if (codeIs(error, "ENOENT"))
6860
+ return null;
6861
+ throw error;
6862
+ }
6863
+ }
6864
+ async function syncDirectory(path) {
6865
+ if (process.platform === "win32")
6866
+ return;
6867
+ const fd = await open(path, "r");
6868
+ try {
6869
+ await fd.sync();
6870
+ } finally {
6871
+ await fd.close();
6872
+ }
6873
+ }
6874
+ var windowsCurrentAccount = windowsCurrentAccountSync;
6875
+ async function windowsCurrentUserAcl(path, directory = false, options = {}, created = false) {
6876
+ const username = options.username ?? `*${windowsCurrentAccount().sid}`;
6877
+ const grant = `${username}:${directory ? "(OI)(CI)F" : "F"}`;
6878
+ const execFile3 = options.execFile ?? nodeExecFile;
6879
+ await new Promise((resolve3, reject) => {
6880
+ execFile3("icacls.exe", [
6881
+ path,
6882
+ "/inheritance:r",
6883
+ "/grant:r",
6884
+ grant,
6885
+ ...created ? ["/remove:g", "*S-1-5-32-544", "*S-1-5-18"] : []
6886
+ ], (error) => {
6887
+ if (error)
6888
+ reject(error);
6889
+ else
6890
+ resolve3();
6891
+ });
6892
+ });
6893
+ }
6894
+ async function protectStateFile(path, platform = process.platform, aclOptions) {
6895
+ if (platform === "win32")
6896
+ await windowsCurrentUserAcl(path, false, aclOptions);
6897
+ else
6898
+ await chmod(path, 384);
6899
+ return "private";
6900
+ }
6901
+ async function atomicWrite(path, bytes, fault, assertOwned) {
6902
+ await assertOwned?.();
6903
+ const temp = `${path}.${randomUUID()}.tmp`;
6904
+ const fd = await open(temp, "wx", 384);
6905
+ let permissionStatus;
6906
+ try {
6907
+ permissionStatus = await protectStateFile(temp);
6908
+ const split = Math.ceil(bytes.length / 2);
6909
+ await fd.writeFile(bytes.subarray(0, split));
6910
+ await fault?.("mid_write");
6911
+ await assertOwned?.();
6912
+ await fd.writeFile(bytes.subarray(split));
6913
+ await fd.sync();
6914
+ } finally {
6915
+ await fd.close();
6916
+ }
6917
+ await assertOwned?.();
6918
+ await rename(temp, path);
6919
+ await syncDirectory(dirname4(path));
6920
+ return permissionStatus;
6921
+ }
6922
+ async function withLock(path, waitMs, work) {
6923
+ const lockfile = await sharedLockfile();
6924
+ await mkdir(dirname4(path), { recursive: true, mode: 448 });
6925
+ const generation = randomUUID();
6926
+ const owner = join5(`${path}.lock`, "owner");
6927
+ let compromised = false;
6928
+ let acquired = false;
6929
+ const assertOwned = async () => {
6930
+ if (compromised || (await readBytes(owner).catch(() => null))?.toString() !== generation) {
6931
+ compromised = true;
6932
+ throw new Error("lock_lost");
6933
+ }
6934
+ };
6935
+ const leaseFs = {
6936
+ ...fs2,
6937
+ mkdir: (dir, callback) => {
6938
+ void mkdir(dir).then(() => writeFile(owner, generation, { mode: 384, flag: "wx" })).then(() => callback(), callback);
6939
+ },
6940
+ rmdir: (dir, callback) => {
6941
+ void unlink(join5(dir, "owner")).catch((error) => {
6942
+ if (!codeIs(error, "ENOENT"))
6943
+ throw error;
6944
+ }).then(() => rmdir(dir)).then(() => callback(), callback);
6945
+ },
6946
+ rmdirSync: (dir) => {
6947
+ try {
6948
+ fs2.unlinkSync(join5(dir, "owner"));
6949
+ } catch (error) {
6950
+ if (!codeIs(error, "ENOENT"))
6951
+ throw error;
6952
+ }
6953
+ fs2.rmdirSync(dir);
6954
+ },
6955
+ stat: (file, callback) => {
6956
+ void (acquired ? assertOwned() : Promise.resolve()).then(() => fs2.stat(file, callback), () => callback(Object.assign(new Error("lock_lost"), { code: "ENOENT" })));
6957
+ }
6958
+ };
6959
+ const deadline = performance.now() + waitMs;
6960
+ let release;
6961
+ while (!release) {
6962
+ try {
6963
+ release = await lockfile.lock(path, {
6964
+ realpath: false,
6965
+ stale: 3e4,
6966
+ update: 5e3,
6967
+ retries: 0,
6968
+ fs: leaseFs,
6969
+ onCompromised: () => {
6970
+ compromised = true;
6971
+ }
6972
+ });
6973
+ } catch (error) {
6974
+ if (!codeIs(error, "ELOCKED"))
6975
+ throw error;
6976
+ if (performance.now() >= deadline)
6977
+ throw new RuntimeError("lock_held");
6978
+ await delay(Math.min(100, Math.max(1, deadline - performance.now())));
6979
+ }
6980
+ }
6981
+ acquired = true;
6982
+ try {
6983
+ return await work(assertOwned);
6984
+ } finally {
6985
+ if (await assertOwned().then(() => true, () => false))
6986
+ await release();
6987
+ }
6988
+ }
6989
+
6990
+ // packages/local-setup/dist/automaticUpdate.js
6991
+ import { spawn as nodeSpawn } from "node:child_process";
6992
+ import { realpathSync } from "node:fs";
6993
+ import { stat as nodeStat, utimes } from "node:fs/promises";
6994
+ import { homedir as homedir3 } from "node:os";
6995
+ import { join as join6 } from "node:path";
6996
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
6997
+ var DAY_MS = 864e5;
6998
+ var statePath = (stateDir) => join6(stateDir, "automatic-update.json");
6999
+ function cliLauncherPath(options = {}) {
7000
+ const platform = options.platform ?? process.platform;
7001
+ const home = options.home ?? homedir3();
7002
+ return platform === "win32" ? join6(options.env?.LOCALAPPDATA || join6(home, "AppData", "Local"), "Mnemonik", "bin", "mnemonik.cmd") : join6(home, ".local", "bin", "mnemonik");
7003
+ }
7004
+ async function readState(path) {
7005
+ const bytes = await readBytes(path);
7006
+ if (!bytes)
7007
+ return {};
7008
+ const value = JSON.parse(bytes.toString());
7009
+ if (!value || typeof value !== "object" || value.lastAttempt !== void 0 && (!Number.isFinite(value.lastAttempt) || value.lastAttempt < 0))
7010
+ throw new Error("automatic_update_state_invalid");
7011
+ return value.lastAttempt === void 0 ? {} : { lastAttempt: value.lastAttempt };
7012
+ }
7013
+ async function maybeStartAutomaticUpdate(options = {}) {
7014
+ const stateDir = options.stateDir ?? stateDirectory(options.platform, options.env, options.home);
7015
+ const path = statePath(stateDir);
7016
+ try {
7017
+ const now = (options.now ?? Date.now)();
7018
+ const stat = options.stat ?? nodeStat;
7019
+ try {
7020
+ if (now - (await stat(path)).mtimeMs < DAY_MS)
7021
+ return false;
7022
+ } catch (error) {
7023
+ if (error.code !== "ENOENT")
7024
+ throw error;
7025
+ }
7026
+ if (!options.spawn && !(await stat(cliLauncherPath(options))).isFile())
7027
+ return false;
7028
+ return await withLock(path, 0, async (assertOwned) => {
7029
+ const state = await readState(path);
7030
+ if (state.lastAttempt !== void 0 && now - state.lastAttempt < DAY_MS)
7031
+ return false;
7032
+ await atomicWrite(path, Buffer.from(`${JSON.stringify({ lastAttempt: now })}
7033
+ `), void 0, assertOwned);
7034
+ await utimes(path, now / 1e3, now / 1e3);
7035
+ const platform = options.platform ?? process.platform;
7036
+ const launcher = cliLauncherPath(options);
7037
+ const command = platform === "win32" ? {
7038
+ file: options.env?.ComSpec || "cmd.exe",
7039
+ args: ["/d", "/s", "/c", `""${launcher}" update --automatic"`],
7040
+ windowsVerbatimArguments: true
7041
+ } : platform === "linux" && (options.env ?? process.env).INVOCATION_ID ? {
7042
+ // detached creates a process group, not a new systemd cgroup. An
7043
+ // updater spawned by the scanner must survive stopping that service.
7044
+ file: "systemd-run",
7045
+ args: [
7046
+ "--user",
7047
+ "--collect",
7048
+ "--quiet",
7049
+ `--setenv=MNEMONIK_STATE_DIR=${stateDir}`,
7050
+ "--",
7051
+ launcher,
7052
+ "update",
7053
+ "--automatic"
7054
+ ]
7055
+ } : { file: launcher, args: ["update", "--automatic"] };
7056
+ const child = (options.spawn ?? nodeSpawn)(command.file, command.args, {
7057
+ detached: true,
7058
+ stdio: "ignore",
7059
+ windowsHide: true,
7060
+ ..."windowsVerbatimArguments" in command ? { windowsVerbatimArguments: command.windowsVerbatimArguments } : {}
7061
+ });
7062
+ child.once("error", () => {
7063
+ });
7064
+ child.unref();
7065
+ return true;
7066
+ });
7067
+ } catch {
7068
+ return false;
7069
+ }
7070
+ }
7071
+ var HELPER_FLAG = "--mnemonik-automatic-update";
7072
+ function isHelperInvocation() {
7073
+ if (process.argv[2] !== HELPER_FLAG || !process.argv[3] || !process.argv[1])
7074
+ return false;
7075
+ try {
7076
+ return realpathSync(process.argv[1]) === realpathSync(fileURLToPath2(import.meta.url));
7077
+ } catch {
7078
+ return false;
7079
+ }
7080
+ }
7081
+ if (isHelperInvocation())
7082
+ void maybeStartAutomaticUpdate({ stateDir: process.argv[3] });
5176
7083
 
5177
7084
  // packages/local-setup/dist/index.js
5178
7085
  var MAX_ORIGINAL_BYTES = 64 * 1024;
@@ -5251,12 +7158,13 @@ import {
5251
7158
  import { hostOrder, launchHostLabels } from "./install/adapters.js";
5252
7159
  import { readInstallVersions } from "./install/ownership.js";
5253
7160
  import { ensureLauncher, removeLauncher, LauncherError } from "./launcher.js";
5254
- import { readFile as readFile3, realpath } from "node:fs/promises";
7161
+ import { readFile as readFile4, realpath } from "node:fs/promises";
5255
7162
  import { createInterface } from "node:readline";
5256
7163
  import { RuntimeStore, updateRuntime } from "./runtime/store.js";
7164
+ import { recordUpdateCheck } from "./runtime/updateCheck.js";
5257
7165
  import { updateCli, cliUpdateHint } from "./runtime/selfUpdate.js";
5258
- import { homedir as homedir3 } from "node:os";
5259
- import { join as join5 } from "node:path";
7166
+ import { homedir as homedir4 } from "node:os";
7167
+ import { join as join7 } from "node:path";
5260
7168
  import { Output } from "./output.js";
5261
7169
  import { SCANNER_RESTART_MESSAGE } from "./scanner/service.js";
5262
7170
  import { SCANNER_FAILURE_MESSAGE, SCANNER_RETRY_MESSAGE } from "./screens/journey.js";
@@ -5292,6 +7200,8 @@ import {
5292
7200
  mcpTurnOnAction,
5293
7201
  renderStatusSummaries,
5294
7202
  renderRefusals,
7203
+ REPORT_NOT_SENT,
7204
+ renderScannerFailure,
5295
7205
  statusExitCode
5296
7206
  } from "./status.js";
5297
7207
  import { editorAuthorizationRows } from "./screens/journey.js";
@@ -5312,7 +7222,7 @@ var NOTHING_REMOVED_LINE = "Nothing was removed.";
5312
7222
  var SCANNER_UNINSTALL_PROMPT = "Uninstalling background indexing means your code on this machine is no longer\nindexed. Agents here lose code search and file context until you set it up\nagain with mnemonik scanner enable. This also withdraws your indexing consent\nfor this machine. Type yes to continue.";
5313
7223
  var SCANNER_REMOVED_LINE = "Background indexing removed from this machine.";
5314
7224
  async function revokeScannerCredential(deps, output, stateDir, saved) {
5315
- const state = saved ?? JSON.parse(await readFile3(`${stateDir}/scanner/state.json`, "utf8"));
7225
+ const state = saved ?? JSON.parse(await readFile4(`${stateDir}/scanner/state.json`, "utf8"));
5316
7226
  const bearer = await ensureCliAuth(deps, output, false);
5317
7227
  const response = await (deps.grantFetch ?? fetch)(
5318
7228
  `${apiOrigin()}/api/v1/component-credentials/${encodeURIComponent(state.config.credentialFamilyId)}/revoke`,
@@ -5334,7 +7244,7 @@ async function confirmScannerOptOut(parsed, deps, output) {
5334
7244
  }
5335
7245
  async function uninstallScannerOptOut(deps, output, service, json) {
5336
7246
  const stateDir = deps.installStateDir ?? stateDirectory(process.platform, process.env, deps.home);
5337
- const saved = await readFile3(`${stateDir}/scanner/state.json`, "utf8").then(
7247
+ const saved = await readFile4(`${stateDir}/scanner/state.json`, "utf8").then(
5338
7248
  (text) => JSON.parse(text),
5339
7249
  (error) => {
5340
7250
  if (error.code === "ENOENT") return void 0;
@@ -5367,10 +7277,48 @@ async function retryUpdateOnce(update, failed = () => false) {
5367
7277
  try {
5368
7278
  const result = await update();
5369
7279
  return failed(result) ? update() : result;
5370
- } catch {
7280
+ } catch (error) {
7281
+ if (error instanceof ScannerConsentRequired) throw error;
5371
7282
  return update();
5372
7283
  }
5373
7284
  }
7285
+ async function approveScannerUpdate(parsed, deps, output, stateDir) {
7286
+ if (parsed.flags.has("automatic") || parsed.flags.has("json") || parsed.flags.has("non-interactive"))
7287
+ return "pending";
7288
+ const saved = JSON.parse(await readFile4(join7(stateDir, "scanner/state.json"), "utf8"));
7289
+ try {
7290
+ const document = await enableScanner({
7291
+ stateDir,
7292
+ cwd: deps.cwd ?? process.cwd(),
7293
+ home: deps.home,
7294
+ input: deps.input ?? process.stdin,
7295
+ output,
7296
+ noBrowser: parsed.flags.has("no-browser"),
7297
+ roots: saved.config.roots,
7298
+ exclusions: saved.config.exclusions ?? [],
7299
+ ...deps.scannerService,
7300
+ ...deps.scannerEnable,
7301
+ projectExecutor: deps.projectExecutor,
7302
+ projectStateDir: deps.projectStateDir
7303
+ });
7304
+ return document.installation.state === "READY" ? "approved" : "pending";
7305
+ } catch {
7306
+ return "pending";
7307
+ }
7308
+ }
7309
+ function scannerConsentRequired(output, json) {
7310
+ if (json)
7311
+ output.json({
7312
+ status: "ACTION_REQUIRED",
7313
+ reason: "scanner_consent_required",
7314
+ action: "mnemonik scanner enable"
7315
+ });
7316
+ else {
7317
+ output.line(SCANNER_CONSENT_MESSAGE.sentence);
7318
+ output.line(SCANNER_CONSENT_MESSAGE.nextStep);
7319
+ }
7320
+ return 3;
7321
+ }
5374
7322
  function hostUpdateFailed(result) {
5375
7323
  return result.results.some(
5376
7324
  (target) => target.status !== "READY" && target.reason !== "codex_trust_pending"
@@ -5395,7 +7343,10 @@ var booleans = /* @__PURE__ */ new Set([
5395
7343
  "verify",
5396
7344
  "dry-run",
5397
7345
  "reopen-install",
5398
- "automatic"
7346
+ "automatic",
7347
+ "cancel",
7348
+ "retry",
7349
+ "skip"
5399
7350
  ]);
5400
7351
  var values = /* @__PURE__ */ new Set([
5401
7352
  "components",
@@ -5497,19 +7448,24 @@ function allowed(parsed, names) {
5497
7448
  return void 0;
5498
7449
  }
5499
7450
  function actionRequired2(output, json, message, flag) {
7451
+ const decision = flag ? consentDecision(flag) : void 0;
5500
7452
  if (json)
5501
7453
  output.json({
5502
7454
  status: "action_required",
5503
7455
  reason: "consent_required",
5504
7456
  ...flag ? { flag } : {},
5505
- action: message
7457
+ action: message,
7458
+ ...decision ? { question: decision.question, then: decision.then, answers: decision.answers } : {}
5506
7459
  });
5507
- else
5508
- output.error(
5509
- flag ? `Missing required consent flag: ${flag}` : /^[a-z][a-z0-9_]*$/u.test(message) ? humanReason(message) : message
5510
- );
7460
+ else if (flag) for (const line of consentLines(flag)) output.error(line);
7461
+ else output.error(/^[a-z][a-z0-9_]*$/u.test(message) ? humanReason(message) : message);
5511
7462
  return 3;
5512
7463
  }
7464
+ function retryOnce(flags2) {
7465
+ if (!flags2.has("retry")) return void 0;
7466
+ let retried = false;
7467
+ return async () => retried ? "skip" : (retried = true, "retry");
7468
+ }
5513
7469
  function requireConsent(parsed, output, required) {
5514
7470
  for (const flag of required) {
5515
7471
  if (!parsed.flags.has(flag))
@@ -5558,7 +7514,7 @@ async function hostDependencies(deps, output, state) {
5558
7514
  if (!cliAuth.accountEmail) throw new Error("account_identity_failed");
5559
7515
  const email = await cliAuth.accountEmail(bearer);
5560
7516
  const installation = JSON.parse(
5561
- await readFile3(join5(state, "installation.json"), "utf8").catch(() => "{}")
7517
+ await readFile4(join7(state, "installation.json"), "utf8").catch(() => "{}")
5562
7518
  );
5563
7519
  return {
5564
7520
  stateDir: state,
@@ -5575,7 +7531,7 @@ async function hostDependencies(deps, output, state) {
5575
7531
  async function updateHostDependencies(deps, state) {
5576
7532
  if (deps.hostManagement) return { ...deps.hostManagement, stateDir: state };
5577
7533
  const installation = JSON.parse(
5578
- await readFile3(join5(state, "installation.json"), "utf8").catch(() => "{}")
7534
+ await readFile4(join7(state, "installation.json"), "utf8").catch(() => "{}")
5579
7535
  );
5580
7536
  return {
5581
7537
  stateDir: state,
@@ -5583,7 +7539,7 @@ async function updateHostDependencies(deps, state) {
5583
7539
  };
5584
7540
  }
5585
7541
  async function packageVersion() {
5586
- const contents = await readFile3(new URL("../package.json", import.meta.url), "utf8");
7542
+ const contents = await readFile4(new URL("../package.json", import.meta.url), "utf8");
5587
7543
  return JSON.parse(contents).version;
5588
7544
  }
5589
7545
  async function runHostCommand(command, parsed, deps, output, scannerSelected = false) {
@@ -5628,7 +7584,7 @@ async function runHostCommand(command, parsed, deps, output, scannerSelected = f
5628
7584
  component: component2,
5629
7585
  host: name2,
5630
7586
  scope: "user",
5631
- home: deps.home ?? homedir3(),
7587
+ home: deps.home ?? homedir4(),
5632
7588
  projectRoot: deps.cwd ?? process.cwd()
5633
7589
  }))
5634
7590
  );
@@ -5697,7 +7653,7 @@ async function runHostCommand(command, parsed, deps, output, scannerSelected = f
5697
7653
  noBrowser: parsed.flags.has("no-browser"),
5698
7654
  source: dependencies.source ?? (updatedCli ? (host2) => hostSource(
5699
7655
  host2,
5700
- join5(updatedCli.directory, "node_modules/@mnemonik/cli/package.json")
7656
+ join7(updatedCli.directory, "node_modules/@mnemonik/cli/package.json")
5701
7657
  ) : void 0),
5702
7658
  instruction: json ? void 0 : (text) => output.line(text),
5703
7659
  apply: parsed.flags.has("apply")
@@ -5708,7 +7664,7 @@ async function runHostCommand(command, parsed, deps, output, scannerSelected = f
5708
7664
  let scanner;
5709
7665
  let launcher;
5710
7666
  let scannerRecovery;
5711
- if (all && await readFile3(`${state}/scanner/state.json`).then(
7667
+ if (all && await readFile4(`${state}/scanner/state.json`).then(
5712
7668
  () => true,
5713
7669
  () => false
5714
7670
  )) {
@@ -5721,6 +7677,9 @@ async function runHostCommand(command, parsed, deps, output, scannerSelected = f
5721
7677
  ...deps.scannerService,
5722
7678
  onScannerRestartRequested: () => {
5723
7679
  if (!json) output.line(SCANNER_RESTART_MESSAGE);
7680
+ },
7681
+ onAbandonedPauseResumed: () => {
7682
+ if (!json) output.line(ABANDONED_PAUSE_RESUMED);
5724
7683
  }
5725
7684
  },
5726
7685
  deps.scannerEnable?.source
@@ -5731,8 +7690,14 @@ async function runHostCommand(command, parsed, deps, output, scannerSelected = f
5731
7690
  version: runtime.manifest.version
5732
7691
  };
5733
7692
  } catch (error) {
5734
- scanner = { status: "FAILED", reason: error.message };
5735
- if (!json)
7693
+ if (error instanceof ScannerConsentRequired)
7694
+ scanner = await approveScannerUpdate(parsed, deps, output, state) === "approved" ? { status: "UPDATED" } : {
7695
+ status: "ACTION_REQUIRED",
7696
+ reason: "scanner_update_consent_required",
7697
+ action: "mnemonik scanner enable"
7698
+ };
7699
+ else scanner = { status: "FAILED", reason: error.message };
7700
+ if (!json && scanner.status === "FAILED")
5736
7701
  scannerRecovery = await scannerRecoveryAction(error, {
5737
7702
  stateDir: state,
5738
7703
  ...deps.scannerService
@@ -5740,6 +7705,7 @@ async function runHostCommand(command, parsed, deps, output, scannerSelected = f
5740
7705
  }
5741
7706
  }
5742
7707
  let failed = scanner?.status === "FAILED" || cli?.status === "FAILED";
7708
+ const scannerConsentPending = scanner?.status === "ACTION_REQUIRED";
5743
7709
  const hostExit = maintenanceExitCode(result.results);
5744
7710
  const remaining = command === "repair" ? await collectCurrentInstallation(deps, output) : void 0;
5745
7711
  const remainingExit = remaining?.installation.state === "FAILED" ? 1 : remaining?.installation.state === "READY" || !remaining ? 0 : 3;
@@ -5747,10 +7713,15 @@ async function runHostCommand(command, parsed, deps, output, scannerSelected = f
5747
7713
  const codexTrustPending = result.results.some(
5748
7714
  (target) => target.reason === "codex_trust_pending"
5749
7715
  );
7716
+ if (all)
7717
+ await recordUpdateCheck(
7718
+ state,
7719
+ failed || hostsFailed ? "failed" : cli?.status === "UPDATED" || result.reports.length > 0 || scanner?.status === "UPDATED" ? "updated" : "current"
7720
+ );
5750
7721
  if (fullUninstall && hostExit === 0) {
5751
7722
  const installed = await Promise.all(
5752
7723
  [new RuntimeStore(state).pointerPath("scanner"), `${state}/scanner/state.json`].map(
5753
- (path) => readFile3(path).then(
7724
+ (path) => readFile4(path).then(
5754
7725
  () => true,
5755
7726
  () => false
5756
7727
  )
@@ -5796,15 +7767,15 @@ async function runHostCommand(command, parsed, deps, output, scannerSelected = f
5796
7767
  else if (command === "update") {
5797
7768
  if (failed || hostsFailed) {
5798
7769
  if (cli?.status === "UPDATED") output.line("The mnemonik command updated.");
5799
- if (result.reports.length > 0 && !hostsFailed) output.line("Your editors updated.");
7770
+ if (result.reports.length > 0 && !hostsFailed) output.line("Your coding tools updated.");
5800
7771
  if (scanner?.status === "UPDATED") output.line("The scanner updated.");
5801
7772
  if (cli?.status === "FAILED") {
5802
7773
  output.error("The mnemonik command could not update.");
5803
7774
  output.error("Run npx -y @mnemonik/cli@latest install to update it.");
5804
7775
  }
5805
7776
  if (hostsFailed) {
5806
- output.error("Your editors could not update.");
5807
- output.error("Run mnemonik repair, then start a new session in each editor.");
7777
+ output.error("Your coding tools could not update.");
7778
+ output.error("Run mnemonik repair, then start a new session in each coding tool.");
5808
7779
  }
5809
7780
  if (scanner?.status === "FAILED") {
5810
7781
  output.error(scannerRecovery?.message ?? "The scanner could not update.");
@@ -5817,6 +7788,10 @@ async function runHostCommand(command, parsed, deps, output, scannerSelected = f
5817
7788
  } else if (cli?.status === "UPDATED" || result.reports.length > 0 || scanner?.status === "UPDATED")
5818
7789
  output.line("Mnemonik updated.");
5819
7790
  else output.line("Mnemonik is up to date.");
7791
+ if (scannerConsentPending) {
7792
+ output.line(SCANNER_UPDATE_CONSENT_MESSAGE.sentence);
7793
+ output.line(SCANNER_UPDATE_CONSENT_MESSAGE.nextStep);
7794
+ }
5820
7795
  } else {
5821
7796
  for (const target of result.results)
5822
7797
  output.line(target.status === "READY" ? "Done." : humanReason(target.reason));
@@ -5841,8 +7816,9 @@ async function runHostCommand(command, parsed, deps, output, scannerSelected = f
5841
7816
  }
5842
7817
  }
5843
7818
  if (failed || remainingExit === 1) return 1;
5844
- return hostExit || remainingExit;
7819
+ return hostExit || remainingExit || (scannerConsentPending && !parsed.flags.has("automatic") ? 3 : 0);
5845
7820
  } catch (error) {
7821
+ if (command === "update" && !host && !component) await recordUpdateCheck(state, "failed");
5846
7822
  if (command === "update" && !json) {
5847
7823
  output.error(updateFailureMessage);
5848
7824
  return error instanceof LauncherError ? 3 : 1;
@@ -5905,6 +7881,7 @@ async function enableCommand(parsed, deps, output) {
5905
7881
  output,
5906
7882
  nonInteractive: parsed.flags.has("non-interactive") || json,
5907
7883
  noBrowser: parsed.flags.has("no-browser"),
7884
+ timeout: retryOnce(parsed.flags),
5908
7885
  ...typeof roots === "string" ? { roots: roots.split(",").filter(Boolean) } : {},
5909
7886
  ...typeof exclusions === "string" ? { exclusions: exclusions.split(",").filter(Boolean) } : {},
5910
7887
  ...deps.scannerService,
@@ -5941,9 +7918,13 @@ async function installCommand(parsed, deps, output) {
5941
7918
  "without-scanner",
5942
7919
  "apply",
5943
7920
  "no-browser",
5944
- "dry-run"
7921
+ "dry-run",
7922
+ "retry",
7923
+ "skip"
5945
7924
  ]);
5946
7925
  if (invalid) return flagError(output, parsed, invalid);
7926
+ if (parsed.flags.has("retry") && parsed.flags.has("skip"))
7927
+ return flagError(output, parsed, "Unknown flag combination: --retry --skip");
5947
7928
  if (!deps.install && !parsed.flags.has("dry-run")) {
5948
7929
  const { joinedInstall } = await import("./install/journey.js");
5949
7930
  const state = deps.hostManagement?.stateDir ?? deps.installStateDir ?? stateDirectory(process.platform, process.env, deps.home);
@@ -5997,7 +7978,7 @@ async function doctorCommand(parsed, deps, output) {
5997
7978
  const invalid = allowed(parsed, []);
5998
7979
  if (invalid) return flagError(output, parsed, invalid);
5999
7980
  const result = await runPreflight({ cwd: deps.cwd, home: deps.home, ...deps.preflight });
6000
- output.setContext({ home: deps.home ?? homedir3(), projectRoot: result.project.root });
7981
+ output.setContext({ home: deps.home ?? homedir4(), projectRoot: result.project.root });
6001
7982
  const document = await collectStatusDocument({
6002
7983
  preflight: result,
6003
7984
  cwd: deps.cwd ?? process.cwd(),
@@ -6024,22 +8005,26 @@ async function doctorCommand(parsed, deps, output) {
6024
8005
  else {
6025
8006
  renderPreflight(result, output);
6026
8007
  renderStatusSummaries(document, output, { diagnostics: true });
8008
+ if (document.installation.reasons.some(
8009
+ (reason) => reason === "scanner_failing" || reason === "scanner_signed_out"
8010
+ ))
8011
+ await renderScannerFailure(refusalStateDir(deps), output);
6027
8012
  await renderRefusals(refusalStateDir(deps), output, true);
6028
8013
  }
6029
8014
  await reportCurrentInstallation(deps, output);
6030
8015
  return document.installation.state === "READY" ? 0 : document.installation.state === "FAILED" ? 1 : 3;
6031
8016
  }
6032
- async function collectCurrentInstallation(deps, output) {
8017
+ async function collectCurrentInstallation(deps, output, announce) {
6033
8018
  const result = await runPreflight({
6034
8019
  cwd: deps.cwd,
6035
8020
  home: deps.home,
6036
8021
  ...deps.preflight,
6037
8022
  fetch: async () => new Response(null, { status: 204 })
6038
8023
  });
6039
- output.setContext({ home: deps.home ?? homedir3(), projectRoot: result.project.root });
8024
+ output.setContext({ home: deps.home ?? homedir4(), projectRoot: result.project.root });
6040
8025
  const hostStateDir = deps.hostManagement?.stateDir ?? deps.installStateDir ?? stateDirectory(process.platform, process.env, deps.home);
6041
8026
  const localConditions = deps.projectHookConditions ? [] : [
6042
- ...await localInstallationConditions(deps.home ?? homedir3(), hostStateDir, deps.launcher),
8027
+ ...await localInstallationConditions(deps.home ?? homedir4(), hostStateDir, deps.launcher),
6043
8028
  // Installed Codex hooks that Codex has not trusted cannot run.
6044
8029
  ...await (deps.codexTrustConditions ?? (() => codexTrustConditions({
6045
8030
  stateDir: hostStateDir,
@@ -6065,7 +8050,14 @@ async function collectCurrentInstallation(deps, output) {
6065
8050
  configuredHosts: deps.configuredHosts ?? deps.install?.input.hosts,
6066
8051
  details: deps.statusDetails,
6067
8052
  generatedAt: deps.statusGeneratedAt,
6068
- launcher: { ...deps.launcher, stateDir: hostStateDir, home: deps.home }
8053
+ launcher: { ...deps.launcher, stateDir: hostStateDir, home: deps.home },
8054
+ expectedDisclosureVersion: deps.scannerDisclosureVersion,
8055
+ ...announce ? {
8056
+ abandonedPause: {
8057
+ ...deps.scannerService,
8058
+ onAbandonedPauseResumed: () => announce(ABANDONED_PAUSE_RESUMED)
8059
+ }
8060
+ } : {}
6069
8061
  });
6070
8062
  const versions = await readInstallVersions(hostStateDir, document.scanner?.version ?? void 0);
6071
8063
  const installedCli = await new RuntimeStore(hostStateDir).verifyRuntime("cli").catch(() => void 0);
@@ -6073,21 +8065,33 @@ async function collectCurrentInstallation(deps, output) {
6073
8065
  return { ...document, versions };
6074
8066
  }
6075
8067
  async function reportCurrentInstallation(deps, output, document) {
6076
- const bearer = await auth(deps, output, false).getCliBearer().catch(() => void 0);
6077
- if (typeof bearer !== "string") return;
8068
+ let refused;
8069
+ const bearer = await auth(deps, output, false).getCliBearer().catch((error) => {
8070
+ if (isCredentialSessionUnavailableError(error)) return { status: "ACTION_REQUIRED" };
8071
+ const reason = error?.reason;
8072
+ if (error?.name === "CredentialError" && typeof reason === "string")
8073
+ refused = reason;
8074
+ return void 0;
8075
+ });
8076
+ if (refused) return { refused };
8077
+ if (typeof bearer !== "string")
8078
+ return bearer?.status === "ACTION_REQUIRED" ? "signed_out" : "failed";
6078
8079
  const send = deps.grantFetch ?? globalThis.fetch;
6079
- await postCurrentReadiness(
8080
+ return postCurrentReadiness(
6080
8081
  bearer,
6081
8082
  serializeReadiness(document ?? await collectCurrentInstallation(deps, output)),
6082
8083
  (url, options) => send(url, { ...options, signal: AbortSignal.timeout(2500) })
6083
- ).catch(() => {
6084
- });
8084
+ ).then(
8085
+ () => "sent",
8086
+ /* An unreachable server says nothing about this machine. */
8087
+ () => "failed"
8088
+ );
6085
8089
  }
6086
8090
  async function deleteProjectCommand(parsed, rest, deps, output) {
6087
8091
  const json = parsed.flags.has("json");
6088
8092
  const cwd = deps.cwd ?? process.cwd();
6089
- const resolve2 = deps.projectResolver?.resolveProjectIdentity ?? resolveProjectIdentity;
6090
- const here = await resolve2(cwd, { allowNestedInherit: false });
8093
+ const resolve3 = deps.projectResolver?.resolveProjectIdentity ?? resolveProjectIdentity;
8094
+ const here = await resolve3(cwd, { allowNestedInherit: false });
6091
8095
  const hereId = here.kind === "ok" ? here.identity.projectId : void 0;
6092
8096
  const root = "root" in here ? here.root : cwd;
6093
8097
  const target = rest[0] ?? hereId;
@@ -6154,7 +8158,7 @@ async function deleteProjectCommand(parsed, rest, deps, output) {
6154
8158
  const result = await response.json().catch(() => ({ success: true }));
6155
8159
  const stateDir = deps.installStateDir ?? stateDirectory(process.platform, process.env, deps.home);
6156
8160
  const saved = JSON.parse(
6157
- await readFile3(`${stateDir}/scanner/state.json`, "utf8").catch(() => "null")
8161
+ await readFile4(`${stateDir}/scanner/state.json`, "utf8").catch(() => "null")
6158
8162
  );
6159
8163
  let stillWatched = false;
6160
8164
  if (hereId === project.id && saved?.config.roots.includes(root)) {
@@ -6186,7 +8190,7 @@ async function runCli(args2, deps = {}) {
6186
8190
  const stdout = silent ? discard : deps.stdout ?? process.stdout;
6187
8191
  const stderr = silent ? discard : deps.stderr ?? process.stderr;
6188
8192
  const output = new Output(stdout, stderr, {
6189
- home: deps.home ?? homedir3()
8193
+ home: deps.home ?? homedir4()
6190
8194
  });
6191
8195
  const usageError = (positionals, failure = usageReason(
6192
8196
  parsed.positionals,
@@ -6244,9 +8248,11 @@ async function runCli(args2, deps = {}) {
6244
8248
  );
6245
8249
  const stateDir = deps.installStateDir ?? stateDirectory(process.platform, process.env, deps.home);
6246
8250
  const saved = JSON.parse(
6247
- await readFile3(`${stateDir}/scanner/state.json`, "utf8").catch(() => "null")
8251
+ await readFile4(`${stateDir}/scanner/state.json`, "utf8").catch(() => "null")
6248
8252
  );
6249
8253
  if (!saved) return actionRequired2(output, parsed.flags.has("json"), "mnemonik install");
8254
+ if ((action === "add" || action === "remove") && pausedForConsent(await scannerReceipt(stateDir)))
8255
+ return scannerConsentRequired(output, parsed.flags.has("json"));
6250
8256
  if (action === "list") {
6251
8257
  if (parsed.flags.has("json")) output.json(saved.config.roots);
6252
8258
  else for (const root of saved.config.roots) output.line(root);
@@ -6407,6 +8413,9 @@ async function runCli(args2, deps = {}) {
6407
8413
  ...options,
6408
8414
  onScannerRestartRequested: () => {
6409
8415
  if (!parsed.flags.has("json")) output.line(SCANNER_RESTART_MESSAGE);
8416
+ },
8417
+ onAbandonedPauseResumed: () => {
8418
+ if (!parsed.flags.has("json")) output.line(ABANDONED_PAUSE_RESUMED);
6410
8419
  }
6411
8420
  },
6412
8421
  deps.scannerEnable?.source
@@ -6432,6 +8441,25 @@ async function runCli(args2, deps = {}) {
6432
8441
  );
6433
8442
  return 0;
6434
8443
  } catch (error) {
8444
+ if (command === "update" && error instanceof ScannerConsentRequired) {
8445
+ const stateDir = deps.installStateDir ?? stateDirectory(process.platform, process.env, deps.home);
8446
+ if (await approveScannerUpdate(parsed, deps, output, stateDir) === "approved") {
8447
+ if (parsed.flags.has("json")) output.json({ status: "updated" });
8448
+ else output.line("Mnemonik updated.");
8449
+ return 0;
8450
+ }
8451
+ if (parsed.flags.has("json"))
8452
+ output.json({
8453
+ status: "ACTION_REQUIRED",
8454
+ reason: "scanner_update_consent_required",
8455
+ action: "mnemonik scanner enable"
8456
+ });
8457
+ else {
8458
+ output.line(SCANNER_UPDATE_CONSENT_MESSAGE.sentence);
8459
+ output.line(SCANNER_UPDATE_CONSENT_MESSAGE.nextStep);
8460
+ }
8461
+ return 3;
8462
+ }
6435
8463
  const failure = scannerFailure(error);
6436
8464
  if (command === "uninstall" && parsed.flags.has("json"))
6437
8465
  output.json({
@@ -6556,7 +8584,11 @@ Preview: ${preview.path}
6556
8584
  const invalid = allowed(parsed, []);
6557
8585
  if (invalid || subcommand)
6558
8586
  return invalid ? flagError(output, parsed, invalid) : usageError(["status"]);
6559
- const document = await collectCurrentInstallation(deps, output);
8587
+ const document = await collectCurrentInstallation(
8588
+ deps,
8589
+ output,
8590
+ parsed.flags.has("json") ? void 0 : (line) => output.line(line)
8591
+ );
6560
8592
  const version = await packageVersion();
6561
8593
  const store = new RuntimeStore(
6562
8594
  deps.installStateDir ?? stateDirectory(process.platform, process.env, deps.home)
@@ -6569,7 +8601,12 @@ Preview: ${preview.path}
6569
8601
  if (parsed.flags.has("json"))
6570
8602
  output.json({ ...document, cli: { version, ...hint ? { updateAvailable: hint } : {} } });
6571
8603
  else if (hint) output.line(hint);
6572
- await reportCurrentInstallation(deps, output, document);
8604
+ const reported = await reportCurrentInstallation(deps, output, document);
8605
+ if (reported === "signed_out" && !parsed.flags.has("json")) {
8606
+ output.line(REPORT_NOT_SENT.sentence);
8607
+ output.line(REPORT_NOT_SENT.nextStep);
8608
+ } else if (typeof reported === "object" && !parsed.flags.has("json"))
8609
+ output.line(humanReason(reported.refused));
6573
8610
  return statusExitCode(document);
6574
8611
  }
6575
8612
  if (command === "connect") {
@@ -6578,7 +8615,7 @@ Preview: ${preview.path}
6578
8615
  if (!subcommand || rest.length || !hostOrder.includes(subcommand))
6579
8616
  return subcommand && !hostOrder.includes(subcommand) ? usageError(["connect"], { reason: "invalid_value", detail: subcommand }) : argumentError(["connect"], ["connect"], [subcommand ?? "", ...rest].filter(Boolean), 1);
6580
8617
  const host = subcommand;
6581
- const editor = (await localEditorStatus(deps.home ?? homedir3())).find(
8618
+ const editor = (await localEditorStatus(deps.home ?? homedir4())).find(
6582
8619
  (candidate) => candidate.host === host
6583
8620
  );
6584
8621
  if (host === "codex" && editor?.mcp === "ready" && !parsed.flags.has("json")) {
@@ -6611,7 +8648,7 @@ Preview: ${preview.path}
6611
8648
  return 0;
6612
8649
  }
6613
8650
  }
6614
- const reason = editor?.mcp === "disabled" ? `${editor.name} connection is turned off.` : editor?.mcp === "ready" ? "Finish signing in to Mnemonik in the editor." : `${launchHostLabels[host]} connection is missing.`;
8651
+ const reason = editor?.mcp === "disabled" ? `${editor.name} connection is turned off.` : editor?.mcp === "ready" ? "Finish signing in to Mnemonik in the coding tool." : `${launchHostLabels[host]} connection is missing.`;
6615
8652
  const actions = editor?.mcp === "ready" ? editorAuthorizationRows([host]) : [
6616
8653
  editor?.mcp === "disabled" ? mcpTurnOnAction[host] : "Run mnemonik install to set it up again."
6617
8654
  ];
@@ -6633,7 +8670,7 @@ Preview: ${preview.path}
6633
8670
  }
6634
8671
  const invalid = allowed(
6635
8672
  parsed,
6636
- subcommand === "ensure" ? ["agent"] : subcommand === "status" ? [] : subcommand === "link" ? ["apply", "non-git", "confirm-mismatch", "replace"] : ["apply", "non-git", "owner"]
8673
+ subcommand === "ensure" ? ["agent"] : subcommand === "status" ? [] : subcommand === "link" ? ["apply", "non-git", "confirm-mismatch", "replace"] : subcommand === "setup" ? ["apply", "non-git", "owner", "cancel"] : ["apply", "non-git", "owner"]
6637
8674
  );
6638
8675
  if (invalid) return flagError(output, parsed, invalid);
6639
8676
  if (subcommand === "ensure") {
@@ -6672,6 +8709,7 @@ Preview: ${preview.path}
6672
8709
  apply: parsed.flags.has("apply"),
6673
8710
  confirmMismatch: parsed.flags.has("confirm-mismatch"),
6674
8711
  replace: parsed.flags.has("replace"),
8712
+ cancel: parsed.flags.has("cancel"),
6675
8713
  owner: typeof parsed.flags.get("owner") === "string" ? parsed.flags.get("owner") : void 0
6676
8714
  },
6677
8715
  {
@@ -6752,9 +8790,11 @@ Preview: ${preview.path}
6752
8790
  );
6753
8791
  const invalid = allowed(
6754
8792
  parsed,
6755
- subcommand === "enable" ? ["accept-indexing", "apply", "scan-roots", "exclusions", "no-browser"] : subcommand === "export-preview" ? ["out"] : subcommand === "uninstall" ? ["confirm"] : []
8793
+ subcommand === "enable" ? ["accept-indexing", "apply", "scan-roots", "exclusions", "no-browser", "retry", "skip"] : subcommand === "export-preview" ? ["out"] : subcommand === "uninstall" ? ["confirm"] : subcommand === "start" ? ["retry", "skip"] : []
6756
8794
  );
6757
8795
  if (invalid) return flagError(output, parsed, invalid);
8796
+ if (parsed.flags.has("retry") && parsed.flags.has("skip"))
8797
+ return flagError(output, parsed, "Unknown flag combination: --retry --skip");
6758
8798
  if (subcommand === "enable") return enableCommand(parsed, deps, output);
6759
8799
  if (subcommand === "uninstall") {
6760
8800
  const declined = await confirmScannerOptOut(parsed, deps, output);
@@ -6816,7 +8856,7 @@ Preview: ${preview.path}
6816
8856
  const service = scannerService({
6817
8857
  stateDir: deps.installStateDir ?? stateDirectory(process.platform, process.env, deps.home),
6818
8858
  waiting: json ? void 0 : (phase, ms) => output.line(`Waiting for scanner ${phase} (up to ${ms / 1e3} seconds).`),
6819
- timeout: json || parsed.flags.has("non-interactive") ? void 0 : async (phase) => (await chooseHostProfile(deps.input ?? process.stdin, output, [
8859
+ timeout: json || parsed.flags.has("non-interactive") ? retryOnce(parsed.flags) : async (phase) => (await chooseHostProfile(deps.input ?? process.stdin, output, [
6820
8860
  `Retry scanner ${phase}`,
6821
8861
  "Skip scanner"
6822
8862
  ]))?.startsWith("Retry") ? "retry" : "skip",
@@ -6827,6 +8867,8 @@ Preview: ${preview.path}
6827
8867
  stateDir: deps.installStateDir ?? stateDirectory(process.platform, process.env, deps.home),
6828
8868
  ...deps.scannerService
6829
8869
  };
8870
+ if (subcommand === "resume" && pausedForConsent(await scannerReceipt(options.stateDir)))
8871
+ return scannerConsentRequired(output, json);
6830
8872
  if (subcommand === "pause" || subcommand === "resume")
6831
8873
  await controlScanner(subcommand, options);
6832
8874
  else if (subcommand === "export-preview") {