peachsim 0.1.2406 → 0.1.2409

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 (107) hide show
  1. package/cli/agent-note.ts +231 -0
  2. package/cli/cloud-client.ts +8 -3
  3. package/cli/cloud-dispatch.ts +1 -1
  4. package/cli/command-agent.ts +122 -0
  5. package/cli/commands/agent.ts +29 -26
  6. package/cli/commands/stream.ts +11 -7
  7. package/cli/main.ts +16 -2
  8. package/cli/outbound-endpoints.ts +15 -0
  9. package/cli/ws-bridge.ts +4 -1
  10. package/dist-lib/agent-daemon-client.cjs +23 -3
  11. package/dist-lib/agent-events.cjs +1 -1
  12. package/dist-lib/attached-projects.cjs +1 -1
  13. package/dist-lib/auth/shared-session.cjs +1 -1
  14. package/dist-lib/backend-origin.cjs +1 -1
  15. package/dist-lib/beta.cjs +1 -1
  16. package/dist-lib/beta.mjs +1 -1
  17. package/dist-lib/bridge-constants.cjs +1 -1
  18. package/dist-lib/bridge-contract-input.cjs +1 -1
  19. package/dist-lib/bridge-contract-input.mjs +1 -1
  20. package/dist-lib/bridge-contract.cjs +1 -1
  21. package/dist-lib/bridge-contract.mjs +1 -1
  22. package/dist-lib/bundle-channel.cjs +205 -62
  23. package/dist-lib/capture-contract.cjs +1 -1
  24. package/dist-lib/capture-contract.mjs +1 -1
  25. package/dist-lib/cloud-contract.cjs +20 -1
  26. package/dist-lib/cloud-contract.mjs +18 -1
  27. package/dist-lib/cloud-test-args.cjs +1 -1
  28. package/dist-lib/cloud-test-args.mjs +1 -1
  29. package/dist-lib/cloud.cjs +1 -1
  30. package/dist-lib/cloud.mjs +1 -1
  31. package/dist-lib/config.cjs +1 -1
  32. package/dist-lib/config.mjs +1 -1
  33. package/dist-lib/detox/index.cjs +1630 -1513
  34. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  35. package/dist-lib/expo-swift-bundle.cjs +203 -60
  36. package/dist-lib/expo-swift-metadata.cjs +1 -1
  37. package/dist-lib/expo-swift-metadata.mjs +1 -1
  38. package/dist-lib/home-paths.cjs +1 -1
  39. package/dist-lib/host/bridge-host.cjs +394 -102
  40. package/dist-lib/host/fetch-proxy-handler.cjs +5 -5
  41. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  42. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  43. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  44. package/dist-lib/host/websocket-proxy.cjs +1 -1
  45. package/dist-lib/index.cjs +392 -272
  46. package/dist-lib/jump-to-source-babel.cjs +1 -1
  47. package/dist-lib/jump-to-source-native.cjs +1 -1
  48. package/dist-lib/kotlin-host.cjs +1 -1
  49. package/dist-lib/menu.cjs +1 -1
  50. package/dist-lib/menu.mjs +1 -1
  51. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  52. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  53. package/dist-lib/metro-production-bundle.cjs +1 -1
  54. package/dist-lib/metro-production-bundle.mjs +1 -1
  55. package/dist-lib/metro.cjs +5 -5
  56. package/dist-lib/native-app-identity-project.cjs +3 -3
  57. package/dist-lib/native-app-identity-project.mjs +3 -3
  58. package/dist-lib/native-app-identity.cjs +1 -1
  59. package/dist-lib/native-app-identity.mjs +1 -1
  60. package/dist-lib/native-firebase-metadata.cjs +1 -1
  61. package/dist-lib/native-firebase-metadata.mjs +1 -1
  62. package/dist-lib/pdfium-raster.cjs +1 -1
  63. package/dist-lib/pdfium-raster.mjs +1 -1
  64. package/dist-lib/plist.cjs +1 -1
  65. package/dist-lib/plist.mjs +1 -1
  66. package/dist-lib/profiles.cjs +1 -1
  67. package/dist-lib/public-brand.cjs +1 -1
  68. package/dist-lib/public-origins-lib-esm.json +24 -24
  69. package/dist-lib/public-origins-lib.json +70 -60
  70. package/dist-lib/react-native-host-modules.cjs +1 -1
  71. package/dist-lib/react-native-host-modules.mjs +1 -1
  72. package/dist-lib/reap-browser.cjs +1 -1
  73. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  74. package/dist-lib/sdk.cjs +1 -1
  75. package/dist-lib/sdk.mjs +1 -1
  76. package/dist-lib/skills.cjs +1199 -821
  77. package/dist-lib/swift-compile.cjs +197 -55
  78. package/dist-lib/swift-compile.mjs +197 -55
  79. package/dist-lib/swift-package.cjs +1 -1
  80. package/dist-lib/swift-package.mjs +1 -1
  81. package/dist-lib/swift-submit.cjs +1 -1
  82. package/dist-lib/swift-submit.mjs +1 -1
  83. package/dist-lib/swift-toolchain.cjs +1 -1
  84. package/dist-lib/swift.cjs +1 -1
  85. package/dist-lib/vite-swift.cjs +213 -58
  86. package/dist-lib/vite.cjs +5 -5
  87. package/dist-lib/worklet-executable.cjs +1 -1
  88. package/dist-lib/worklet-executable.mjs +1 -1
  89. package/dist-types/packages/peach-engine/src/remote-stream/cloud-display.d.ts +2 -2
  90. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  91. package/dist-types/packages/peach-globals/src/replayBridgeContract.d.ts +7 -0
  92. package/kotlin/sdk.tar.gz +0 -0
  93. package/package.json +1 -1
  94. package/runtime-companion.json +1 -1
  95. package/skills/peach-setup/SKILL.md +8 -3
  96. package/src/agent-daemon-client.ts +35 -2
  97. package/src/agent-prompt.ts +68 -0
  98. package/src/bridge-contract.ts +4 -0
  99. package/src/canvas-agent-note-delivery.ts +83 -0
  100. package/src/cloud-contract.ts +30 -0
  101. package/src/host/agent-host.ts +128 -18
  102. package/src/swift-compile.ts +124 -66
  103. package/src/swift-host.ts +2 -1
  104. package/src/swift-objc-import.ts +99 -0
  105. package/src/swift-packages.ts +1 -0
  106. package/src/swift-shared-sdk.ts +2 -1
  107. package/src/xcode-header-search.ts +33 -0
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2406 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2409 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -2476,7 +2476,7 @@ function isValidRuntimeVersion(value) {
2476
2476
  }
2477
2477
 
2478
2478
  // runtime-companion.json
2479
- var runtime_companion_default = { abi: 1, sha256: "7e162f525497b8964ff8f7274ce8219416ec01ac8fc6986a80d2df90a54c71c4", file: "node/cli-7e162f525497b8964ff8f7274ce8219416ec01ac8fc6986a80d2df90a54c71c4.cjs" };
2479
+ var runtime_companion_default = { abi: 1, sha256: "f0ebf18540275693f13d5f0638e9e6e2afd2b8a2fa10c6d5c1190341feaa430b", file: "node/cli-f0ebf18540275693f13d5f0638e9e6e2afd2b8a2fa10c6d5c1190341feaa430b.cjs" };
2480
2480
 
2481
2481
  // src/answeredNativePackages.ts
2482
2482
  var import_node_async_hooks = require("node:async_hooks");
@@ -2615,6 +2615,7 @@ function getCliRuntime() {
2615
2615
  var NativeURL = globalThis.URL;
2616
2616
 
2617
2617
  // src/cloud-contract.ts
2618
+ var AGENT_IDENTITY_MAX_CHARS = 200;
2618
2619
  var RNX_CLOUD_DESIGN_MAX_STORAGE_BYTES = 1024 * 1024;
2619
2620
  var RNX_CLOUD_COMMAND_SCOPES = {
2620
2621
  state: "read",
@@ -2732,197 +2733,705 @@ var RNX_SHELL_UPDATE_PREFIX = "__RNX_SHELL_UPDATE_V1__";
2732
2733
  var RNX_SHELL_UPDATE_SET_PREFIX = `${RNX_SHELL_UPDATE_PREFIX}set:`;
2733
2734
  var RNX_SHELL_UPDATE_UNSET = `${RNX_SHELL_UPDATE_PREFIX}unset`;
2734
2735
 
2735
- // cli/commands/detect.ts
2736
- var import_json5 = __toESM(require_lib(), 1);
2736
+ // cli/command-agent.ts
2737
+ var import_os2 = require("os");
2737
2738
 
2738
- // ../../node_modules/yaml/browser/dist/nodes/identity.js
2739
- var ALIAS = Symbol.for("yaml.alias");
2740
- var DOC = Symbol.for("yaml.document");
2741
- var MAP = Symbol.for("yaml.map");
2742
- var PAIR = Symbol.for("yaml.pair");
2743
- var SCALAR = Symbol.for("yaml.scalar");
2744
- var SEQ = Symbol.for("yaml.seq");
2745
- var NODE_TYPE = Symbol.for("yaml.node.type");
2746
- var isAlias = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === ALIAS;
2747
- var isDocument = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === DOC;
2748
- var isMap = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === MAP;
2749
- var isPair = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === PAIR;
2750
- var isScalar = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SCALAR;
2751
- var isSeq = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SEQ;
2752
- function isCollection(node) {
2753
- if (node && typeof node === "object")
2754
- switch (node[NODE_TYPE]) {
2755
- case MAP:
2756
- case SEQ:
2757
- return true;
2758
- }
2759
- return false;
2760
- }
2761
- function isNode(node) {
2762
- if (node && typeof node === "object")
2763
- switch (node[NODE_TYPE]) {
2764
- case ALIAS:
2765
- case MAP:
2766
- case SCALAR:
2767
- case SEQ:
2768
- return true;
2769
- }
2770
- return false;
2739
+ // ../peach-kit/src/agent-identity.ts
2740
+ function formatLockOwner(owner) {
2741
+ const colon = owner.indexOf(":");
2742
+ if (colon <= 0) return owner.length > 24 ? `${owner.slice(0, 21)}\u2026` : owner;
2743
+ const source = owner.slice(0, colon);
2744
+ const value = owner.slice(colon + 1);
2745
+ if (source === "PEACH_CLI_IDENTITY" && value) return value;
2746
+ const short = value.length > 12 ? `${value.slice(0, 8)}\u2026` : value;
2747
+ if (source === "CLAUDE_CODE_SESSION_ID" || source === "CODEX_THREAD_ID") {
2748
+ return `agent ${short}`;
2749
+ }
2750
+ return `${source} ${short}`;
2771
2751
  }
2772
- var hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
2773
2752
 
2774
- // ../../node_modules/yaml/browser/dist/visit.js
2775
- var BREAK = Symbol("break visit");
2776
- var SKIP = Symbol("skip children");
2777
- var REMOVE = Symbol("remove node");
2778
- function visit(node, visitor) {
2779
- const visitor_ = initVisitor(visitor);
2780
- if (isDocument(node)) {
2781
- const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
2782
- if (cd === REMOVE)
2783
- node.contents = null;
2784
- } else
2785
- visit_(null, node, visitor_, Object.freeze([]));
2786
- }
2787
- visit.BREAK = BREAK;
2788
- visit.SKIP = SKIP;
2789
- visit.REMOVE = REMOVE;
2790
- function visit_(key, node, visitor, path7) {
2791
- const ctrl = callVisitor(key, node, visitor, path7);
2792
- if (isNode(ctrl) || isPair(ctrl)) {
2793
- replaceNode(key, path7, ctrl);
2794
- return visit_(key, ctrl, visitor, path7);
2795
- }
2796
- if (typeof ctrl !== "symbol") {
2797
- if (isCollection(node)) {
2798
- path7 = Object.freeze(path7.concat(node));
2799
- for (let i = 0; i < node.items.length; ++i) {
2800
- const ci = visit_(i, node.items[i], visitor, path7);
2801
- if (typeof ci === "number")
2802
- i = ci - 1;
2803
- else if (ci === BREAK)
2804
- return BREAK;
2805
- else if (ci === REMOVE) {
2806
- node.items.splice(i, 1);
2807
- i -= 1;
2808
- }
2809
- }
2810
- } else if (isPair(node)) {
2811
- path7 = Object.freeze(path7.concat(node));
2812
- const ck = visit_("key", node.key, visitor, path7);
2813
- if (ck === BREAK)
2814
- return BREAK;
2815
- else if (ck === REMOVE)
2816
- node.key = null;
2817
- const cv = visit_("value", node.value, visitor, path7);
2818
- if (cv === BREAK)
2819
- return BREAK;
2820
- else if (cv === REMOVE)
2821
- node.value = null;
2822
- }
2753
+ // cli/current-sim.ts
2754
+ var import_fs3 = require("fs");
2755
+ var import_os = require("os");
2756
+ var import_path2 = require("path");
2757
+
2758
+ // cli/parent-pid.ts
2759
+ var import_child_process = require("child_process");
2760
+ var import_fs2 = require("fs");
2761
+ var import_module = require("module");
2762
+ var cached = null;
2763
+ var cachedComm = null;
2764
+ var cachedPgid = null;
2765
+ function getParentPid(pid) {
2766
+ if (!cached) cached = build();
2767
+ try {
2768
+ return cached(pid);
2769
+ } catch {
2770
+ return null;
2823
2771
  }
2824
- return ctrl;
2825
2772
  }
2826
- async function visitAsync(node, visitor) {
2827
- const visitor_ = initVisitor(visitor);
2828
- if (isDocument(node)) {
2829
- const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));
2830
- if (cd === REMOVE)
2831
- node.contents = null;
2832
- } else
2833
- await visitAsync_(null, node, visitor_, Object.freeze([]));
2773
+ function getProcessComm(pid) {
2774
+ if (!cachedComm) cachedComm = buildComm();
2775
+ try {
2776
+ return cachedComm(pid);
2777
+ } catch {
2778
+ return null;
2779
+ }
2834
2780
  }
2835
- visitAsync.BREAK = BREAK;
2836
- visitAsync.SKIP = SKIP;
2837
- visitAsync.REMOVE = REMOVE;
2838
- async function visitAsync_(key, node, visitor, path7) {
2839
- const ctrl = await callVisitor(key, node, visitor, path7);
2840
- if (isNode(ctrl) || isPair(ctrl)) {
2841
- replaceNode(key, path7, ctrl);
2842
- return visitAsync_(key, ctrl, visitor, path7);
2781
+ function getProcessPgid(pid) {
2782
+ if (!cachedPgid) cachedPgid = buildPgid();
2783
+ try {
2784
+ return cachedPgid(pid);
2785
+ } catch {
2786
+ return null;
2843
2787
  }
2844
- if (typeof ctrl !== "symbol") {
2845
- if (isCollection(node)) {
2846
- path7 = Object.freeze(path7.concat(node));
2847
- for (let i = 0; i < node.items.length; ++i) {
2848
- const ci = await visitAsync_(i, node.items[i], visitor, path7);
2849
- if (typeof ci === "number")
2850
- i = ci - 1;
2851
- else if (ci === BREAK)
2852
- return BREAK;
2853
- else if (ci === REMOVE) {
2854
- node.items.splice(i, 1);
2855
- i -= 1;
2856
- }
2788
+ }
2789
+ function buildComm() {
2790
+ if (process.platform === "linux") {
2791
+ return (pid) => {
2792
+ try {
2793
+ return (0, import_fs2.readFileSync)(`/proc/${pid}/comm`, "utf8").trim() || null;
2794
+ } catch {
2795
+ return null;
2857
2796
  }
2858
- } else if (isPair(node)) {
2859
- path7 = Object.freeze(path7.concat(node));
2860
- const ck = await visitAsync_("key", node.key, visitor, path7);
2861
- if (ck === BREAK)
2862
- return BREAK;
2863
- else if (ck === REMOVE)
2864
- node.key = null;
2865
- const cv = await visitAsync_("value", node.value, visitor, path7);
2866
- if (cv === BREAK)
2867
- return BREAK;
2868
- else if (cv === REMOVE)
2869
- node.value = null;
2870
- }
2797
+ };
2871
2798
  }
2872
- return ctrl;
2873
- }
2874
- function initVisitor(visitor) {
2875
- if (typeof visitor === "object" && (visitor.Collection || visitor.Node || visitor.Value)) {
2876
- return Object.assign({
2877
- Alias: visitor.Node,
2878
- Map: visitor.Node,
2879
- Scalar: visitor.Node,
2880
- Seq: visitor.Node
2881
- }, visitor.Value && {
2882
- Map: visitor.Value,
2883
- Scalar: visitor.Value,
2884
- Seq: visitor.Value
2885
- }, visitor.Collection && {
2886
- Map: visitor.Collection,
2887
- Seq: visitor.Collection
2888
- }, visitor);
2799
+ if (process.platform === "darwin") {
2800
+ const ffi = tryBuildDarwinCommFfi();
2801
+ if (ffi) return ffi;
2802
+ return (pid) => readProcessTable2().get(pid)?.comm || null;
2889
2803
  }
2890
- return visitor;
2804
+ return () => null;
2891
2805
  }
2892
- function callVisitor(key, node, visitor, path7) {
2893
- if (typeof visitor === "function")
2894
- return visitor(key, node, path7);
2895
- if (isMap(node))
2896
- return visitor.Map?.(key, node, path7);
2897
- if (isSeq(node))
2898
- return visitor.Seq?.(key, node, path7);
2899
- if (isPair(node))
2900
- return visitor.Pair?.(key, node, path7);
2901
- if (isScalar(node))
2902
- return visitor.Scalar?.(key, node, path7);
2903
- if (isAlias(node))
2904
- return visitor.Alias?.(key, node, path7);
2905
- return void 0;
2806
+ function build() {
2807
+ if (process.platform === "linux") return buildLinux();
2808
+ if (process.platform === "darwin") {
2809
+ const ffi = tryBuildDarwinFfi();
2810
+ if (ffi) return ffi;
2811
+ return (pid) => {
2812
+ const ppid = readProcessTable2().get(pid)?.ppid;
2813
+ return ppid !== void 0 && ppid > 0 ? ppid : null;
2814
+ };
2815
+ }
2816
+ return () => null;
2906
2817
  }
2907
- function replaceNode(key, path7, node) {
2908
- const parent = path7[path7.length - 1];
2909
- if (isCollection(parent)) {
2910
- parent.items[key] = node;
2911
- } else if (isPair(parent)) {
2912
- if (key === "key")
2913
- parent.key = node;
2914
- else
2915
- parent.value = node;
2916
- } else if (isDocument(parent)) {
2917
- parent.contents = node;
2918
- } else {
2919
- const pt = isAlias(parent) ? "alias" : "scalar";
2920
- throw new Error(`Cannot replace node with ${pt} parent`);
2818
+ function buildPgid() {
2819
+ if (process.platform === "linux") {
2820
+ return (pid) => {
2821
+ try {
2822
+ const raw = (0, import_fs2.readFileSync)(`/proc/${pid}/stat`, "utf8");
2823
+ const end = raw.lastIndexOf(")");
2824
+ if (end < 0) return null;
2825
+ const rest = raw.slice(end + 1).trim().split(/\s+/);
2826
+ const pgid = Number(rest[2]);
2827
+ return Number.isFinite(pgid) && pgid > 0 ? pgid : null;
2828
+ } catch {
2829
+ return null;
2830
+ }
2831
+ };
2832
+ }
2833
+ if (process.platform === "darwin") {
2834
+ const ffi = tryBuildDarwinPgidFfi();
2835
+ if (ffi) return ffi;
2836
+ return (pid) => {
2837
+ const pgid = readProcessTable2().get(pid)?.pgid;
2838
+ return pgid !== void 0 && pgid > 0 ? pgid : null;
2839
+ };
2921
2840
  }
2841
+ return () => null;
2922
2842
  }
2923
-
2924
- // ../../node_modules/yaml/browser/dist/doc/directives.js
2925
- var escapeChars = {
2843
+ var PROCESS_TABLE_TTL_MS = 2e3;
2844
+ var processTable = { readAt: 0, rows: /* @__PURE__ */ new Map() };
2845
+ function readProcessTable2() {
2846
+ const now = Date.now();
2847
+ if (processTable.readAt && now - processTable.readAt < PROCESS_TABLE_TTL_MS) {
2848
+ return processTable.rows;
2849
+ }
2850
+ const rows = /* @__PURE__ */ new Map();
2851
+ try {
2852
+ const out = (0, import_child_process.execFileSync)("ps", ["-eo", "pid=,ppid=,pgid=,comm="], {
2853
+ encoding: "utf8",
2854
+ timeout: 5e3,
2855
+ maxBuffer: 8 * 1024 * 1024,
2856
+ stdio: ["ignore", "pipe", "ignore"]
2857
+ });
2858
+ for (const line of out.split("\n")) {
2859
+ const parsed = line.trim().match(/^(\d+)\s+(\d+)\s+(\d+)\s+(.*)$/);
2860
+ if (!parsed) continue;
2861
+ rows.set(Number(parsed[1]), {
2862
+ ppid: Number(parsed[2]),
2863
+ pgid: Number(parsed[3]),
2864
+ comm: (parsed[4].split("/").at(-1) ?? "").slice(0, PBI_COMM_LEN)
2865
+ });
2866
+ }
2867
+ } catch {
2868
+ }
2869
+ processTable = { readAt: now, rows };
2870
+ return rows;
2871
+ }
2872
+ function buildLinux() {
2873
+ return (pid) => {
2874
+ try {
2875
+ const raw = (0, import_fs2.readFileSync)(`/proc/${pid}/stat`, "utf8");
2876
+ const end = raw.lastIndexOf(")");
2877
+ if (end < 0) return null;
2878
+ const rest = raw.slice(end + 1).trim().split(/\s+/);
2879
+ const ppid = Number(rest[1]);
2880
+ return Number.isFinite(ppid) && ppid > 0 ? ppid : null;
2881
+ } catch {
2882
+ return null;
2883
+ }
2884
+ };
2885
+ }
2886
+ var PROC_PIDTBSDINFO = 3;
2887
+ var PROC_BSDINFO_SIZE = 216;
2888
+ var PBI_PPID_OFFSET = 16;
2889
+ var PBI_COMM_OFFSET = 48;
2890
+ var PBI_COMM_LEN = 16;
2891
+ function tryBuildDarwinFfi() {
2892
+ if (!process.versions?.bun) return null;
2893
+ try {
2894
+ const r = (0, import_module.createRequire)(__sootsim_import_meta_url);
2895
+ const { dlopen, FFIType } = r("bun:ffi");
2896
+ const lib = dlopen("/usr/lib/libproc.dylib", {
2897
+ proc_pidinfo: {
2898
+ args: [FFIType.i32, FFIType.i32, FFIType.u64, FFIType.ptr, FFIType.i32],
2899
+ returns: FFIType.i32
2900
+ }
2901
+ });
2902
+ const buf = Buffer.alloc(PROC_BSDINFO_SIZE);
2903
+ return (pid) => {
2904
+ const ret = Number(
2905
+ lib.symbols.proc_pidinfo(pid, PROC_PIDTBSDINFO, 0n, buf, PROC_BSDINFO_SIZE)
2906
+ );
2907
+ if (ret <= 0) return null;
2908
+ const ppid = buf.readUInt32LE(PBI_PPID_OFFSET);
2909
+ return ppid > 0 ? ppid : null;
2910
+ };
2911
+ } catch {
2912
+ return null;
2913
+ }
2914
+ }
2915
+ function tryBuildDarwinCommFfi() {
2916
+ if (!process.versions?.bun) return null;
2917
+ try {
2918
+ const r = (0, import_module.createRequire)(__sootsim_import_meta_url);
2919
+ const { dlopen, FFIType } = r("bun:ffi");
2920
+ const lib = dlopen("/usr/lib/libproc.dylib", {
2921
+ proc_pidinfo: {
2922
+ args: [FFIType.i32, FFIType.i32, FFIType.u64, FFIType.ptr, FFIType.i32],
2923
+ returns: FFIType.i32
2924
+ }
2925
+ });
2926
+ const buf = Buffer.alloc(PROC_BSDINFO_SIZE);
2927
+ return (pid) => {
2928
+ const ret = Number(
2929
+ lib.symbols.proc_pidinfo(pid, PROC_PIDTBSDINFO, 0n, buf, PROC_BSDINFO_SIZE)
2930
+ );
2931
+ if (ret <= 0) return null;
2932
+ const raw = buf.subarray(PBI_COMM_OFFSET, PBI_COMM_OFFSET + PBI_COMM_LEN);
2933
+ const end = raw.indexOf(0);
2934
+ const comm = raw.subarray(0, end < 0 ? raw.length : end).toString("utf8");
2935
+ return comm || null;
2936
+ };
2937
+ } catch {
2938
+ return null;
2939
+ }
2940
+ }
2941
+ var PBI_PGID_OFFSET = 100;
2942
+ function tryBuildDarwinPgidFfi() {
2943
+ if (!process.versions?.bun) return null;
2944
+ try {
2945
+ const r = (0, import_module.createRequire)(__sootsim_import_meta_url);
2946
+ const { dlopen, FFIType } = r("bun:ffi");
2947
+ const lib = dlopen("/usr/lib/libproc.dylib", {
2948
+ proc_pidinfo: {
2949
+ args: [FFIType.i32, FFIType.i32, FFIType.u64, FFIType.ptr, FFIType.i32],
2950
+ returns: FFIType.i32
2951
+ }
2952
+ });
2953
+ const buf = Buffer.alloc(PROC_BSDINFO_SIZE);
2954
+ return (pid) => {
2955
+ const ret = Number(
2956
+ lib.symbols.proc_pidinfo(pid, PROC_PIDTBSDINFO, 0n, buf, PROC_BSDINFO_SIZE)
2957
+ );
2958
+ if (ret <= 0) return null;
2959
+ const pgid = buf.readUInt32LE(PBI_PGID_OFFSET);
2960
+ return pgid > 0 ? pgid : null;
2961
+ };
2962
+ } catch {
2963
+ return null;
2964
+ }
2965
+ }
2966
+
2967
+ // cli/current-sim.ts
2968
+ var CURRENT_SIM_VERSION = 2;
2969
+ var CURRENT_SIM_PATH_ENV = "PEACH_CLI_CURRENT_SIM_PATH";
2970
+ var IDENTITY_ENV_VARS = [
2971
+ "PEACH_CLI_IDENTITY",
2972
+ // explicit override — fastest path, skips all pid lookups
2973
+ "CLAUDE_CODE_SESSION_ID",
2974
+ // claude code, if ever set
2975
+ "CODEX_THREAD_ID",
2976
+ // codex / openai agent thread, stable across tool invocations
2977
+ // a Team Machine session, per agent run. its other runners set no session
2978
+ // variable of their own, and the terminal variables below are inherited from
2979
+ // whatever shell started the daemon, so every such agent would share one key.
2980
+ "TM_SESSION",
2981
+ "TERM_SESSION_ID",
2982
+ // macOS Terminal.app + iTerm2
2983
+ "ITERM_SESSION_ID",
2984
+ // iTerm2 (older variant)
2985
+ "TMUX_PANE",
2986
+ // tmux — stable per pane
2987
+ "STY",
2988
+ // GNU screen session
2989
+ "KITTY_WINDOW_ID",
2990
+ // kitty
2991
+ "WEZTERM_PANE",
2992
+ // wezterm
2993
+ "ALACRITTY_WINDOW_ID",
2994
+ // alacritty
2995
+ "WINDOWID",
2996
+ // X11 terminals
2997
+ "VSCODE_INJECTION"
2998
+ // vscode integrated terminal
2999
+ ];
3000
+ var IMMORTAL_HOST_COMM_RE = /^(?:tmux|screen)|^tm$/i;
3001
+ var INIT_COMM_RE = /^(?:init|systemd|launchd|tini|docker-init|dumb-init|catatonit|s6-svscan|runsvdir)$/i;
3002
+ function findTopAncestor(start, maxDepth = 20) {
3003
+ let prev = start;
3004
+ let pid = getParentPid(start);
3005
+ if (!pid || pid <= 1) {
3006
+ const comm = getProcessComm(start);
3007
+ if (!comm || start < 1 || IMMORTAL_HOST_COMM_RE.test(comm)) return null;
3008
+ return start > 1 || !INIT_COMM_RE.test(comm) ? start : null;
3009
+ }
3010
+ for (let i = 0; i < maxDepth; i++) {
3011
+ const comm = getProcessComm(pid);
3012
+ if (comm && IMMORTAL_HOST_COMM_RE.test(comm)) return prev;
3013
+ const parent = getParentPid(pid);
3014
+ if (!parent || parent <= 1) {
3015
+ return comm ? pid : prev;
3016
+ }
3017
+ prev = pid;
3018
+ pid = parent;
3019
+ }
3020
+ return pid;
3021
+ }
3022
+ function getCliIdentity() {
3023
+ for (const name2 of IDENTITY_ENV_VARS) {
3024
+ const value = process.env[name2];
3025
+ if (value && value.trim()) {
3026
+ return { key: `${name2}:${value.trim()}`, source: name2, stable: true };
3027
+ }
3028
+ }
3029
+ const topPid = findTopAncestor(process.ppid);
3030
+ if (topPid) {
3031
+ return { key: `gppid-${topPid}`, source: "grand-ppid", stable: true };
3032
+ }
3033
+ return { key: `pid-${process.ppid}`, source: "ppid", stable: false };
3034
+ }
3035
+ function getCliIdentityKey() {
3036
+ return getCliIdentity().key;
3037
+ }
3038
+ function getStableOwnerPid() {
3039
+ return findTopAncestor(process.ppid);
3040
+ }
3041
+ function getOwnerProcessGroupId(owner = getStableOwnerPid()) {
3042
+ if (!owner || owner <= 1) return null;
3043
+ const pgid = getProcessPgid(owner);
3044
+ return pgid !== null && pgid > 1 ? pgid : null;
3045
+ }
3046
+ function getCurrentSimPath() {
3047
+ const envPath = process.env[CURRENT_SIM_PATH_ENV];
3048
+ if (envPath) {
3049
+ return (0, import_path2.resolve)(envPath);
3050
+ }
3051
+ const key = getCliIdentityKey();
3052
+ return (0, import_path2.join)((0, import_os.tmpdir)(), `peach-current-sim-${key}.json`);
3053
+ }
3054
+ function legacyCloudCredentialDirectory(filepath) {
3055
+ return (0, import_path2.join)((0, import_path2.dirname)(filepath), `${(0, import_path2.basename)(filepath)}.credentials`);
3056
+ }
3057
+ function readCurrentTarget() {
3058
+ const filepath = getCurrentSimPath();
3059
+ (0, import_fs3.rmSync)(legacyCloudCredentialDirectory(filepath), { recursive: true, force: true });
3060
+ if (!(0, import_fs3.existsSync)(filepath)) return null;
3061
+ try {
3062
+ const parsed = JSON.parse((0, import_fs3.readFileSync)(filepath, "utf8"));
3063
+ if (parsed === null || typeof parsed !== "object") {
3064
+ (0, import_fs3.rmSync)(filepath, { force: true });
3065
+ return null;
3066
+ }
3067
+ if (Reflect.get(parsed, "pendingOpen") === true) return null;
3068
+ const version = Reflect.get(parsed, "version");
3069
+ const plane = Reflect.get(parsed, "plane");
3070
+ const simId = Reflect.get(parsed, "simId");
3071
+ const updatedAt = Reflect.get(parsed, "updatedAt");
3072
+ const rawPort = Reflect.get(parsed, "bridgePort");
3073
+ const bridgePort = typeof rawPort === "number" && Number.isInteger(rawPort) && rawPort > 0 ? rawPort : void 0;
3074
+ if (version !== 1 && version !== CURRENT_SIM_VERSION || version === CURRENT_SIM_VERSION && plane !== "local" || typeof simId !== "string" || !simId.trim() || typeof updatedAt !== "string") {
3075
+ (0, import_fs3.rmSync)(filepath, { force: true });
3076
+ return null;
3077
+ }
3078
+ const target = {
3079
+ version: CURRENT_SIM_VERSION,
3080
+ plane: "local",
3081
+ simId: simId.trim(),
3082
+ ...bridgePort === void 0 ? {} : { bridgePort },
3083
+ updatedAt
3084
+ };
3085
+ if (version === 1) writeSecureJsonAtomic(filepath, target, { durable: false });
3086
+ return target;
3087
+ } catch {
3088
+ (0, import_fs3.rmSync)(filepath, { force: true });
3089
+ return null;
3090
+ }
3091
+ }
3092
+ function readCurrentSimId() {
3093
+ return readCurrentTarget()?.simId ?? null;
3094
+ }
3095
+ function writeCurrentSim(simId, bridgePort) {
3096
+ const normalized = simId.trim();
3097
+ if (!normalized) return;
3098
+ writeSecureJsonAtomic(
3099
+ getCurrentSimPath(),
3100
+ {
3101
+ version: CURRENT_SIM_VERSION,
3102
+ plane: "local",
3103
+ simId: normalized,
3104
+ ...bridgePort === void 0 ? {} : { bridgePort },
3105
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
3106
+ },
3107
+ { durable: false }
3108
+ );
3109
+ }
3110
+ function saveCurrentSimId(simId, bridgePort) {
3111
+ writeCurrentSim(simId, bridgePort);
3112
+ }
3113
+ function getAgentIdPath() {
3114
+ return `${getCurrentSimPath()}.agent-id`;
3115
+ }
3116
+ function readAgentId() {
3117
+ const filepath = getAgentIdPath();
3118
+ if (!(0, import_fs3.existsSync)(filepath)) return void 0;
3119
+ try {
3120
+ const parsed = JSON.parse((0, import_fs3.readFileSync)(filepath, "utf8"));
3121
+ const agentId = parsed !== null && typeof parsed === "object" ? Reflect.get(parsed, "agentId") : void 0;
3122
+ return typeof agentId === "string" && agentId.trim() ? agentId.trim() : void 0;
3123
+ } catch {
3124
+ (0, import_fs3.rmSync)(filepath, { force: true });
3125
+ return void 0;
3126
+ }
3127
+ }
3128
+ var PendingOpenError = class extends Error {
3129
+ };
3130
+ function assertNoPendingOpen() {
3131
+ if (!isOpenPending()) return;
3132
+ throw new PendingOpenError(
3133
+ "the last `peach open` did not pin a sim, so this command would land on whichever tab is connected. run `peach open` again, `peach use <sim>`, or pass --sim <id>"
3134
+ );
3135
+ }
3136
+ function isOpenPending() {
3137
+ const filepath = getCurrentSimPath();
3138
+ if (!(0, import_fs3.existsSync)(filepath)) return false;
3139
+ try {
3140
+ const parsed = JSON.parse((0, import_fs3.readFileSync)(filepath, "utf8"));
3141
+ return parsed !== null && typeof parsed === "object" && Reflect.get(parsed, "pendingOpen") === true;
3142
+ } catch {
3143
+ return false;
3144
+ }
3145
+ }
3146
+
3147
+ // cli/command-agent.ts
3148
+ function clip(text) {
3149
+ return text.length > AGENT_IDENTITY_MAX_CHARS ? `${text.slice(0, AGENT_IDENTITY_MAX_CHARS - 1)}\u2026` : text;
3150
+ }
3151
+ function targetName(target) {
3152
+ const name2 = target?.text?.trim() || target?.testID?.trim() || target?.id?.trim();
3153
+ return name2 ? name2.replace(/\s+/g, " ") : null;
3154
+ }
3155
+ function verb(action, target) {
3156
+ return target ? `${action} ${target}` : action;
3157
+ }
3158
+ function describeStep(step) {
3159
+ switch (step.type) {
3160
+ case "tap":
3161
+ return verb("Tapping", targetName(step.target));
3162
+ case "tapId":
3163
+ return verb("Tapping", step.id);
3164
+ case "doubleTap":
3165
+ return "Double tapping";
3166
+ case "longPress":
3167
+ return verb("Long pressing", targetName(step.target));
3168
+ case "drag":
3169
+ return "Dragging";
3170
+ case "pinch":
3171
+ return "Pinching";
3172
+ case "scroll":
3173
+ return verb("Scrolling", step.id);
3174
+ case "touchDown":
3175
+ case "touchMove":
3176
+ case "touchUp":
3177
+ case "touchCancel":
3178
+ return "Touching the screen";
3179
+ case "type":
3180
+ case "typeInto":
3181
+ case "setElementValue":
3182
+ return "Typing";
3183
+ case "key":
3184
+ case "keyDown":
3185
+ case "keyUp":
3186
+ return "Pressing a key";
3187
+ case "dismissKeyboard":
3188
+ case "toggleKeyboard":
3189
+ return "Using the keyboard";
3190
+ case "openUrl":
3191
+ return "Opening a link";
3192
+ case "setOrientation":
3193
+ return `Rotating to ${step.orientation}`;
3194
+ case "incrementElement":
3195
+ case "decrementElement":
3196
+ return verb("Adjusting", step.id);
3197
+ case "buttonDown":
3198
+ case "buttonUp":
3199
+ case "wait":
3200
+ case "waitFor":
3201
+ case "deviceInfo":
3202
+ case "discoverStoreKitConfig":
3203
+ case "clearStoreKitConfig":
3204
+ return null;
3205
+ }
3206
+ }
3207
+ function describeCommand(command) {
3208
+ switch (command.type) {
3209
+ case "tap":
3210
+ return verb("Tapping", targetName(command.target));
3211
+ case "longPress":
3212
+ return verb("Long pressing", targetName(command.target));
3213
+ case "keyboard":
3214
+ return command.action === "dismiss" ? "Dismissing the keyboard" : command.action === "press" || command.action === "dispatchKey" ? "Pressing a key" : "Typing";
3215
+ case "screenshot":
3216
+ return "Taking a screenshot";
3217
+ case "perform": {
3218
+ const labels = (command.steps ?? []).flatMap((step) => describeStep(step) ?? []);
3219
+ const [first] = labels;
3220
+ if (!first) return null;
3221
+ return labels.length === 1 ? first : `${first}, then ${labels.length - 1} more`;
3222
+ }
3223
+ default:
3224
+ return null;
3225
+ }
3226
+ }
3227
+ function commandAgent(command) {
3228
+ const step = describeCommand(command);
3229
+ if (!step) return void 0;
3230
+ const identity = getCliIdentity();
3231
+ if (!identity.stable) return void 0;
3232
+ const machine = (0, import_os2.hostname)().split(".")[0];
3233
+ if (!machine) return void 0;
3234
+ return {
3235
+ id: clip(identity.key),
3236
+ name: clip(
3237
+ readAgentId() ?? (process.env.PEACH_AGENT_ID?.trim() || formatLockOwner(identity.key))
3238
+ ),
3239
+ machine: clip(machine),
3240
+ step: clip(step)
3241
+ };
3242
+ }
3243
+
3244
+ // cli/commands/detect.ts
3245
+ var import_json5 = __toESM(require_lib(), 1);
3246
+
3247
+ // ../../node_modules/yaml/browser/dist/nodes/identity.js
3248
+ var ALIAS = Symbol.for("yaml.alias");
3249
+ var DOC = Symbol.for("yaml.document");
3250
+ var MAP = Symbol.for("yaml.map");
3251
+ var PAIR = Symbol.for("yaml.pair");
3252
+ var SCALAR = Symbol.for("yaml.scalar");
3253
+ var SEQ = Symbol.for("yaml.seq");
3254
+ var NODE_TYPE = Symbol.for("yaml.node.type");
3255
+ var isAlias = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === ALIAS;
3256
+ var isDocument = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === DOC;
3257
+ var isMap = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === MAP;
3258
+ var isPair = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === PAIR;
3259
+ var isScalar = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SCALAR;
3260
+ var isSeq = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SEQ;
3261
+ function isCollection(node) {
3262
+ if (node && typeof node === "object")
3263
+ switch (node[NODE_TYPE]) {
3264
+ case MAP:
3265
+ case SEQ:
3266
+ return true;
3267
+ }
3268
+ return false;
3269
+ }
3270
+ function isNode(node) {
3271
+ if (node && typeof node === "object")
3272
+ switch (node[NODE_TYPE]) {
3273
+ case ALIAS:
3274
+ case MAP:
3275
+ case SCALAR:
3276
+ case SEQ:
3277
+ return true;
3278
+ }
3279
+ return false;
3280
+ }
3281
+ var hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
3282
+
3283
+ // ../../node_modules/yaml/browser/dist/visit.js
3284
+ var BREAK = Symbol("break visit");
3285
+ var SKIP = Symbol("skip children");
3286
+ var REMOVE = Symbol("remove node");
3287
+ function visit(node, visitor) {
3288
+ const visitor_ = initVisitor(visitor);
3289
+ if (isDocument(node)) {
3290
+ const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
3291
+ if (cd === REMOVE)
3292
+ node.contents = null;
3293
+ } else
3294
+ visit_(null, node, visitor_, Object.freeze([]));
3295
+ }
3296
+ visit.BREAK = BREAK;
3297
+ visit.SKIP = SKIP;
3298
+ visit.REMOVE = REMOVE;
3299
+ function visit_(key, node, visitor, path7) {
3300
+ const ctrl = callVisitor(key, node, visitor, path7);
3301
+ if (isNode(ctrl) || isPair(ctrl)) {
3302
+ replaceNode(key, path7, ctrl);
3303
+ return visit_(key, ctrl, visitor, path7);
3304
+ }
3305
+ if (typeof ctrl !== "symbol") {
3306
+ if (isCollection(node)) {
3307
+ path7 = Object.freeze(path7.concat(node));
3308
+ for (let i = 0; i < node.items.length; ++i) {
3309
+ const ci = visit_(i, node.items[i], visitor, path7);
3310
+ if (typeof ci === "number")
3311
+ i = ci - 1;
3312
+ else if (ci === BREAK)
3313
+ return BREAK;
3314
+ else if (ci === REMOVE) {
3315
+ node.items.splice(i, 1);
3316
+ i -= 1;
3317
+ }
3318
+ }
3319
+ } else if (isPair(node)) {
3320
+ path7 = Object.freeze(path7.concat(node));
3321
+ const ck = visit_("key", node.key, visitor, path7);
3322
+ if (ck === BREAK)
3323
+ return BREAK;
3324
+ else if (ck === REMOVE)
3325
+ node.key = null;
3326
+ const cv = visit_("value", node.value, visitor, path7);
3327
+ if (cv === BREAK)
3328
+ return BREAK;
3329
+ else if (cv === REMOVE)
3330
+ node.value = null;
3331
+ }
3332
+ }
3333
+ return ctrl;
3334
+ }
3335
+ async function visitAsync(node, visitor) {
3336
+ const visitor_ = initVisitor(visitor);
3337
+ if (isDocument(node)) {
3338
+ const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));
3339
+ if (cd === REMOVE)
3340
+ node.contents = null;
3341
+ } else
3342
+ await visitAsync_(null, node, visitor_, Object.freeze([]));
3343
+ }
3344
+ visitAsync.BREAK = BREAK;
3345
+ visitAsync.SKIP = SKIP;
3346
+ visitAsync.REMOVE = REMOVE;
3347
+ async function visitAsync_(key, node, visitor, path7) {
3348
+ const ctrl = await callVisitor(key, node, visitor, path7);
3349
+ if (isNode(ctrl) || isPair(ctrl)) {
3350
+ replaceNode(key, path7, ctrl);
3351
+ return visitAsync_(key, ctrl, visitor, path7);
3352
+ }
3353
+ if (typeof ctrl !== "symbol") {
3354
+ if (isCollection(node)) {
3355
+ path7 = Object.freeze(path7.concat(node));
3356
+ for (let i = 0; i < node.items.length; ++i) {
3357
+ const ci = await visitAsync_(i, node.items[i], visitor, path7);
3358
+ if (typeof ci === "number")
3359
+ i = ci - 1;
3360
+ else if (ci === BREAK)
3361
+ return BREAK;
3362
+ else if (ci === REMOVE) {
3363
+ node.items.splice(i, 1);
3364
+ i -= 1;
3365
+ }
3366
+ }
3367
+ } else if (isPair(node)) {
3368
+ path7 = Object.freeze(path7.concat(node));
3369
+ const ck = await visitAsync_("key", node.key, visitor, path7);
3370
+ if (ck === BREAK)
3371
+ return BREAK;
3372
+ else if (ck === REMOVE)
3373
+ node.key = null;
3374
+ const cv = await visitAsync_("value", node.value, visitor, path7);
3375
+ if (cv === BREAK)
3376
+ return BREAK;
3377
+ else if (cv === REMOVE)
3378
+ node.value = null;
3379
+ }
3380
+ }
3381
+ return ctrl;
3382
+ }
3383
+ function initVisitor(visitor) {
3384
+ if (typeof visitor === "object" && (visitor.Collection || visitor.Node || visitor.Value)) {
3385
+ return Object.assign({
3386
+ Alias: visitor.Node,
3387
+ Map: visitor.Node,
3388
+ Scalar: visitor.Node,
3389
+ Seq: visitor.Node
3390
+ }, visitor.Value && {
3391
+ Map: visitor.Value,
3392
+ Scalar: visitor.Value,
3393
+ Seq: visitor.Value
3394
+ }, visitor.Collection && {
3395
+ Map: visitor.Collection,
3396
+ Seq: visitor.Collection
3397
+ }, visitor);
3398
+ }
3399
+ return visitor;
3400
+ }
3401
+ function callVisitor(key, node, visitor, path7) {
3402
+ if (typeof visitor === "function")
3403
+ return visitor(key, node, path7);
3404
+ if (isMap(node))
3405
+ return visitor.Map?.(key, node, path7);
3406
+ if (isSeq(node))
3407
+ return visitor.Seq?.(key, node, path7);
3408
+ if (isPair(node))
3409
+ return visitor.Pair?.(key, node, path7);
3410
+ if (isScalar(node))
3411
+ return visitor.Scalar?.(key, node, path7);
3412
+ if (isAlias(node))
3413
+ return visitor.Alias?.(key, node, path7);
3414
+ return void 0;
3415
+ }
3416
+ function replaceNode(key, path7, node) {
3417
+ const parent = path7[path7.length - 1];
3418
+ if (isCollection(parent)) {
3419
+ parent.items[key] = node;
3420
+ } else if (isPair(parent)) {
3421
+ if (key === "key")
3422
+ parent.key = node;
3423
+ else
3424
+ parent.value = node;
3425
+ } else if (isDocument(parent)) {
3426
+ parent.contents = node;
3427
+ } else {
3428
+ const pt = isAlias(parent) ? "alias" : "scalar";
3429
+ throw new Error(`Cannot replace node with ${pt} parent`);
3430
+ }
3431
+ }
3432
+
3433
+ // ../../node_modules/yaml/browser/dist/doc/directives.js
3434
+ var escapeChars = {
2926
3435
  "!": "%21",
2927
3436
  ",": "%2C",
2928
3437
  "[": "%5B",
@@ -3993,1435 +4502,1041 @@ function getTagObject(tags, item) {
3993
4502
  }
3994
4503
  if (!tagObj) {
3995
4504
  const name2 = obj?.constructor?.name ?? (obj === null ? "null" : typeof obj);
3996
- throw new Error(`Tag not resolved for ${name2} value`);
3997
- }
3998
- return tagObj;
3999
- }
4000
- function stringifyProps(node, tagObj, { anchors, doc }) {
4001
- if (!doc.directives)
4002
- return "";
4003
- const props = [];
4004
- const anchor = (isScalar(node) || isCollection(node)) && node.anchor;
4005
- if (anchor && anchorIsValid(anchor)) {
4006
- anchors.add(anchor);
4007
- props.push(`&${anchor}`);
4008
- }
4009
- const tag = node.tag ?? (tagObj.default ? null : tagObj.tag);
4010
- if (tag)
4011
- props.push(doc.directives.tagString(tag));
4012
- return props.join(" ");
4013
- }
4014
- function stringify(item, ctx, onComment, onChompKeep) {
4015
- if (isPair(item))
4016
- return item.toString(ctx, onComment, onChompKeep);
4017
- if (isAlias(item)) {
4018
- if (ctx.doc.directives)
4019
- return item.toString(ctx);
4020
- if (ctx.resolvedAliases?.has(item)) {
4021
- throw new TypeError(`Cannot stringify circular structure without alias nodes`);
4022
- } else {
4023
- if (ctx.resolvedAliases)
4024
- ctx.resolvedAliases.add(item);
4025
- else
4026
- ctx.resolvedAliases = /* @__PURE__ */ new Set([item]);
4027
- item = item.resolve(ctx.doc);
4028
- }
4029
- }
4030
- let tagObj = void 0;
4031
- const node = isNode(item) ? item : ctx.doc.createNode(item, { onTagObj: (o) => tagObj = o });
4032
- tagObj ?? (tagObj = getTagObject(ctx.doc.schema.tags, node));
4033
- const props = stringifyProps(node, tagObj, ctx);
4034
- if (props.length > 0)
4035
- ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
4036
- const str = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : isScalar(node) ? stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep);
4037
- if (!props)
4038
- return str;
4039
- return isScalar(node) || str[0] === "{" || str[0] === "[" ? `${props} ${str}` : `${props}
4040
- ${ctx.indent}${str}`;
4041
- }
4042
-
4043
- // ../../node_modules/yaml/browser/dist/stringify/stringifyPair.js
4044
- function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
4045
- const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
4046
- let keyComment = isNode(key) && key.comment || null;
4047
- if (simpleKeys) {
4048
- if (keyComment) {
4049
- throw new Error("With simple keys, key nodes cannot have comments");
4050
- }
4051
- if (isCollection(key) || !isNode(key) && typeof key === "object") {
4052
- const msg = "With simple keys, collection cannot be used as a key value";
4053
- throw new Error(msg);
4054
- }
4055
- }
4056
- let explicitKey = !simpleKeys && (!key || keyComment && value == null && !ctx.inFlow || isCollection(key) || (isScalar(key) ? key.type === Scalar.BLOCK_FOLDED || key.type === Scalar.BLOCK_LITERAL : typeof key === "object"));
4057
- ctx = Object.assign({}, ctx, {
4058
- allNullValues: false,
4059
- implicitKey: !explicitKey && (simpleKeys || !allNullValues),
4060
- indent: indent + indentStep
4061
- });
4062
- let keyCommentDone = false;
4063
- let chompKeep = false;
4064
- let str = stringify(key, ctx, () => keyCommentDone = true, () => chompKeep = true);
4065
- if (!explicitKey && !ctx.inFlow && str.length > 1024) {
4066
- if (simpleKeys)
4067
- throw new Error("With simple keys, single line scalar must not span more than 1024 characters");
4068
- explicitKey = true;
4069
- }
4070
- if (ctx.inFlow) {
4071
- if (allNullValues || value == null) {
4072
- if (keyCommentDone && onComment)
4073
- onComment();
4074
- return str === "" ? "?" : explicitKey ? `? ${str}` : str;
4075
- }
4076
- } else if (allNullValues && !simpleKeys || value == null && explicitKey) {
4077
- str = `? ${str}`;
4078
- if (keyComment && !keyCommentDone) {
4079
- str += lineComment(str, ctx.indent, commentString(keyComment));
4080
- } else if (chompKeep && onChompKeep)
4081
- onChompKeep();
4082
- return str;
4083
- }
4084
- if (keyCommentDone)
4085
- keyComment = null;
4086
- if (explicitKey) {
4087
- if (keyComment)
4088
- str += lineComment(str, ctx.indent, commentString(keyComment));
4089
- str = `? ${str}
4090
- ${indent}:`;
4091
- } else {
4092
- str = `${str}:`;
4093
- if (keyComment)
4094
- str += lineComment(str, ctx.indent, commentString(keyComment));
4095
- }
4096
- let vsb, vcb, valueComment;
4097
- if (isNode(value)) {
4098
- vsb = !!value.spaceBefore;
4099
- vcb = value.commentBefore;
4100
- valueComment = value.comment;
4101
- } else {
4102
- vsb = false;
4103
- vcb = null;
4104
- valueComment = null;
4105
- if (value && typeof value === "object")
4106
- value = doc.createNode(value);
4107
- }
4108
- ctx.implicitKey = false;
4109
- if (!explicitKey && !keyComment && isScalar(value))
4110
- ctx.indentAtStart = str.length + 1;
4111
- chompKeep = false;
4112
- if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && isSeq(value) && !value.flow && !value.tag && !value.anchor) {
4113
- ctx.indent = ctx.indent.substring(2);
4114
- }
4115
- let valueCommentDone = false;
4116
- const valueStr = stringify(value, ctx, () => valueCommentDone = true, () => chompKeep = true);
4117
- let ws = " ";
4118
- if (keyComment || vsb || vcb) {
4119
- ws = vsb ? "\n" : "";
4120
- if (vcb) {
4121
- const cs = commentString(vcb);
4122
- ws += `
4123
- ${indentComment(cs, ctx.indent)}`;
4124
- }
4125
- if (valueStr === "" && !ctx.inFlow) {
4126
- if (ws === "\n" && valueComment)
4127
- ws = "\n\n";
4128
- } else {
4129
- ws += `
4130
- ${ctx.indent}`;
4131
- }
4132
- } else if (!explicitKey && isCollection(value)) {
4133
- const vs0 = valueStr[0];
4134
- const nl0 = valueStr.indexOf("\n");
4135
- const hasNewline = nl0 !== -1;
4136
- const flow = ctx.inFlow ?? value.flow ?? value.items.length === 0;
4137
- if (hasNewline || !flow) {
4138
- let hasPropsLine = false;
4139
- if (hasNewline && (vs0 === "&" || vs0 === "!")) {
4140
- let sp0 = valueStr.indexOf(" ");
4141
- if (vs0 === "&" && sp0 !== -1 && sp0 < nl0 && valueStr[sp0 + 1] === "!") {
4142
- sp0 = valueStr.indexOf(" ", sp0 + 1);
4143
- }
4144
- if (sp0 === -1 || nl0 < sp0)
4145
- hasPropsLine = true;
4146
- }
4147
- if (!hasPropsLine)
4148
- ws = `
4149
- ${ctx.indent}`;
4150
- }
4151
- } else if (valueStr === "" || valueStr[0] === "\n") {
4152
- ws = "";
4153
- }
4154
- str += ws + valueStr;
4155
- if (ctx.inFlow) {
4156
- if (valueCommentDone && onComment)
4157
- onComment();
4158
- } else if (valueComment && !valueCommentDone) {
4159
- str += lineComment(str, ctx.indent, commentString(valueComment));
4160
- } else if (chompKeep && onChompKeep) {
4161
- onChompKeep();
4162
- }
4163
- return str;
4164
- }
4165
-
4166
- // ../../node_modules/yaml/browser/dist/log.js
4167
- function warn(logLevel, warning) {
4168
- if (logLevel === "debug" || logLevel === "warn") {
4169
- console.warn(warning);
4170
- }
4171
- }
4172
-
4173
- // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js
4174
- var MERGE_KEY = "<<";
4175
- var merge = {
4176
- identify: (value) => value === MERGE_KEY || typeof value === "symbol" && value.description === MERGE_KEY,
4177
- default: "key",
4178
- tag: "tag:yaml.org,2002:merge",
4179
- test: /^<<$/,
4180
- resolve: () => Object.assign(new Scalar(Symbol(MERGE_KEY)), {
4181
- addToJSMap: addMergeToJSMap
4182
- }),
4183
- stringify: () => MERGE_KEY
4184
- };
4185
- var isMergeKey = (ctx, key) => (merge.identify(key) || isScalar(key) && (!key.type || key.type === Scalar.PLAIN) && merge.identify(key.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default);
4186
- function addMergeToJSMap(ctx, map2, value) {
4187
- const source = resolveAliasValue(ctx, value);
4188
- if (isSeq(source))
4189
- for (const it of source.items)
4190
- mergeValue(ctx, map2, it);
4191
- else if (Array.isArray(source))
4192
- for (const it of source)
4193
- mergeValue(ctx, map2, it);
4194
- else
4195
- mergeValue(ctx, map2, source);
4196
- }
4197
- function mergeValue(ctx, map2, value) {
4198
- const source = resolveAliasValue(ctx, value);
4199
- if (!isMap(source))
4200
- throw new Error("Merge sources must be maps or map aliases");
4201
- const srcMap = source.toJSON(null, ctx, Map);
4202
- for (const [key, value2] of srcMap) {
4203
- if (map2 instanceof Map) {
4204
- if (!map2.has(key))
4205
- map2.set(key, value2);
4206
- } else if (map2 instanceof Set) {
4207
- map2.add(key);
4208
- } else if (!Object.prototype.hasOwnProperty.call(map2, key)) {
4209
- Object.defineProperty(map2, key, {
4210
- value: value2,
4211
- writable: true,
4212
- enumerable: true,
4213
- configurable: true
4214
- });
4215
- }
4505
+ throw new Error(`Tag not resolved for ${name2} value`);
4216
4506
  }
4217
- return map2;
4507
+ return tagObj;
4218
4508
  }
4219
- function resolveAliasValue(ctx, value) {
4220
- return ctx && isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
4509
+ function stringifyProps(node, tagObj, { anchors, doc }) {
4510
+ if (!doc.directives)
4511
+ return "";
4512
+ const props = [];
4513
+ const anchor = (isScalar(node) || isCollection(node)) && node.anchor;
4514
+ if (anchor && anchorIsValid(anchor)) {
4515
+ anchors.add(anchor);
4516
+ props.push(`&${anchor}`);
4517
+ }
4518
+ const tag = node.tag ?? (tagObj.default ? null : tagObj.tag);
4519
+ if (tag)
4520
+ props.push(doc.directives.tagString(tag));
4521
+ return props.join(" ");
4221
4522
  }
4222
-
4223
- // ../../node_modules/yaml/browser/dist/nodes/addPairToJSMap.js
4224
- function addPairToJSMap(ctx, map2, { key, value }) {
4225
- if (isNode(key) && key.addToJSMap)
4226
- key.addToJSMap(ctx, map2, value);
4227
- else if (isMergeKey(ctx, key))
4228
- addMergeToJSMap(ctx, map2, value);
4229
- else {
4230
- const jsKey = toJS(key, "", ctx);
4231
- if (map2 instanceof Map) {
4232
- map2.set(jsKey, toJS(value, jsKey, ctx));
4233
- } else if (map2 instanceof Set) {
4234
- map2.add(jsKey);
4523
+ function stringify(item, ctx, onComment, onChompKeep) {
4524
+ if (isPair(item))
4525
+ return item.toString(ctx, onComment, onChompKeep);
4526
+ if (isAlias(item)) {
4527
+ if (ctx.doc.directives)
4528
+ return item.toString(ctx);
4529
+ if (ctx.resolvedAliases?.has(item)) {
4530
+ throw new TypeError(`Cannot stringify circular structure without alias nodes`);
4235
4531
  } else {
4236
- const stringKey = stringifyKey(key, jsKey, ctx);
4237
- const jsValue = toJS(value, stringKey, ctx);
4238
- if (stringKey in map2)
4239
- Object.defineProperty(map2, stringKey, {
4240
- value: jsValue,
4241
- writable: true,
4242
- enumerable: true,
4243
- configurable: true
4244
- });
4532
+ if (ctx.resolvedAliases)
4533
+ ctx.resolvedAliases.add(item);
4245
4534
  else
4246
- map2[stringKey] = jsValue;
4247
- }
4248
- }
4249
- return map2;
4250
- }
4251
- function stringifyKey(key, jsKey, ctx) {
4252
- if (jsKey === null)
4253
- return "";
4254
- if (typeof jsKey !== "object")
4255
- return String(jsKey);
4256
- if (isNode(key) && ctx?.doc) {
4257
- const strCtx = createStringifyContext(ctx.doc, {});
4258
- strCtx.anchors = /* @__PURE__ */ new Set();
4259
- for (const node of ctx.anchors.keys())
4260
- strCtx.anchors.add(node.anchor);
4261
- strCtx.inFlow = true;
4262
- strCtx.inStringifyKey = true;
4263
- const strKey = key.toString(strCtx);
4264
- if (!ctx.mapKeyWarned) {
4265
- let jsonStr = JSON.stringify(strKey);
4266
- if (jsonStr.length > 40)
4267
- jsonStr = jsonStr.substring(0, 36) + '..."';
4268
- warn(ctx.doc.options.logLevel, `Keys with collection values will be stringified due to JS Object restrictions: ${jsonStr}. Set mapAsMap: true to use object keys.`);
4269
- ctx.mapKeyWarned = true;
4535
+ ctx.resolvedAliases = /* @__PURE__ */ new Set([item]);
4536
+ item = item.resolve(ctx.doc);
4270
4537
  }
4271
- return strKey;
4272
4538
  }
4273
- return JSON.stringify(jsKey);
4274
- }
4275
-
4276
- // ../../node_modules/yaml/browser/dist/nodes/Pair.js
4277
- function createPair(key, value, ctx) {
4278
- const k = createNode(key, void 0, ctx);
4279
- const v = createNode(value, void 0, ctx);
4280
- return new Pair(k, v);
4539
+ let tagObj = void 0;
4540
+ const node = isNode(item) ? item : ctx.doc.createNode(item, { onTagObj: (o) => tagObj = o });
4541
+ tagObj ?? (tagObj = getTagObject(ctx.doc.schema.tags, node));
4542
+ const props = stringifyProps(node, tagObj, ctx);
4543
+ if (props.length > 0)
4544
+ ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
4545
+ const str = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : isScalar(node) ? stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep);
4546
+ if (!props)
4547
+ return str;
4548
+ return isScalar(node) || str[0] === "{" || str[0] === "[" ? `${props} ${str}` : `${props}
4549
+ ${ctx.indent}${str}`;
4281
4550
  }
4282
- var Pair = class _Pair {
4283
- constructor(key, value = null) {
4284
- Object.defineProperty(this, NODE_TYPE, { value: PAIR });
4285
- this.key = key;
4286
- this.value = value;
4287
- }
4288
- clone(schema4) {
4289
- let { key, value } = this;
4290
- if (isNode(key))
4291
- key = key.clone(schema4);
4292
- if (isNode(value))
4293
- value = value.clone(schema4);
4294
- return new _Pair(key, value);
4295
- }
4296
- toJSON(_, ctx) {
4297
- const pair = ctx?.mapAsMap ? /* @__PURE__ */ new Map() : {};
4298
- return addPairToJSMap(ctx, pair, this);
4299
- }
4300
- toString(ctx, onComment, onChompKeep) {
4301
- return ctx?.doc ? stringifyPair(this, ctx, onComment, onChompKeep) : JSON.stringify(this);
4302
- }
4303
- };
4304
4551
 
4305
- // ../../node_modules/yaml/browser/dist/stringify/stringifyCollection.js
4306
- function stringifyCollection(collection, ctx, options) {
4307
- const flow = ctx.inFlow ?? collection.flow;
4308
- const stringify4 = flow ? stringifyFlowCollection : stringifyBlockCollection;
4309
- return stringify4(collection, ctx, options);
4310
- }
4311
- function stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, flowChars, itemIndent, onChompKeep, onComment }) {
4312
- const { indent, options: { commentString } } = ctx;
4313
- const itemCtx = Object.assign({}, ctx, { indent: itemIndent, type: null });
4314
- let chompKeep = false;
4315
- const lines = [];
4316
- for (let i = 0; i < items.length; ++i) {
4317
- const item = items[i];
4318
- let comment2 = null;
4319
- if (isNode(item)) {
4320
- if (!chompKeep && item.spaceBefore)
4321
- lines.push("");
4322
- addCommentBefore(ctx, lines, item.commentBefore, chompKeep);
4323
- if (item.comment)
4324
- comment2 = item.comment;
4325
- } else if (isPair(item)) {
4326
- const ik = isNode(item.key) ? item.key : null;
4327
- if (ik) {
4328
- if (!chompKeep && ik.spaceBefore)
4329
- lines.push("");
4330
- addCommentBefore(ctx, lines, ik.commentBefore, chompKeep);
4331
- }
4552
+ // ../../node_modules/yaml/browser/dist/stringify/stringifyPair.js
4553
+ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
4554
+ const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
4555
+ let keyComment = isNode(key) && key.comment || null;
4556
+ if (simpleKeys) {
4557
+ if (keyComment) {
4558
+ throw new Error("With simple keys, key nodes cannot have comments");
4332
4559
  }
4333
- chompKeep = false;
4334
- let str2 = stringify(item, itemCtx, () => comment2 = null, () => chompKeep = true);
4335
- if (comment2)
4336
- str2 += lineComment(str2, itemIndent, commentString(comment2));
4337
- if (chompKeep && comment2)
4338
- chompKeep = false;
4339
- lines.push(blockItemPrefix + str2);
4340
- }
4341
- let str;
4342
- if (lines.length === 0) {
4343
- str = flowChars.start + flowChars.end;
4344
- } else {
4345
- str = lines[0];
4346
- for (let i = 1; i < lines.length; ++i) {
4347
- const line = lines[i];
4348
- str += line ? `
4349
- ${indent}${line}` : "\n";
4560
+ if (isCollection(key) || !isNode(key) && typeof key === "object") {
4561
+ const msg = "With simple keys, collection cannot be used as a key value";
4562
+ throw new Error(msg);
4350
4563
  }
4351
4564
  }
4352
- if (comment) {
4353
- str += "\n" + indentComment(commentString(comment), indent);
4354
- if (onComment)
4355
- onComment();
4356
- } else if (chompKeep && onChompKeep)
4357
- onChompKeep();
4358
- return str;
4359
- }
4360
- function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
4361
- const { indent, indentStep, flowCollectionPadding: fcPadding, options: { commentString } } = ctx;
4362
- itemIndent += indentStep;
4363
- const itemCtx = Object.assign({}, ctx, {
4364
- indent: itemIndent,
4365
- inFlow: true,
4366
- type: null
4565
+ let explicitKey = !simpleKeys && (!key || keyComment && value == null && !ctx.inFlow || isCollection(key) || (isScalar(key) ? key.type === Scalar.BLOCK_FOLDED || key.type === Scalar.BLOCK_LITERAL : typeof key === "object"));
4566
+ ctx = Object.assign({}, ctx, {
4567
+ allNullValues: false,
4568
+ implicitKey: !explicitKey && (simpleKeys || !allNullValues),
4569
+ indent: indent + indentStep
4367
4570
  });
4368
- let reqNewline = false;
4369
- let linesAtValue = 0;
4370
- const lines = [];
4371
- for (let i = 0; i < items.length; ++i) {
4372
- const item = items[i];
4373
- let comment = null;
4374
- if (isNode(item)) {
4375
- if (item.spaceBefore)
4376
- lines.push("");
4377
- addCommentBefore(ctx, lines, item.commentBefore, false);
4378
- if (item.comment)
4379
- comment = item.comment;
4380
- } else if (isPair(item)) {
4381
- const ik = isNode(item.key) ? item.key : null;
4382
- if (ik) {
4383
- if (ik.spaceBefore)
4384
- lines.push("");
4385
- addCommentBefore(ctx, lines, ik.commentBefore, false);
4386
- if (ik.comment)
4387
- reqNewline = true;
4388
- }
4389
- const iv = isNode(item.value) ? item.value : null;
4390
- if (iv) {
4391
- if (iv.comment)
4392
- comment = iv.comment;
4393
- if (iv.commentBefore)
4394
- reqNewline = true;
4395
- } else if (item.value == null && ik?.comment) {
4396
- comment = ik.comment;
4397
- }
4398
- }
4399
- if (comment)
4400
- reqNewline = true;
4401
- let str = stringify(item, itemCtx, () => comment = null);
4402
- reqNewline || (reqNewline = lines.length > linesAtValue || str.includes("\n"));
4403
- if (i < items.length - 1) {
4404
- str += ",";
4405
- } else if (ctx.options.trailingComma) {
4406
- if (ctx.options.lineWidth > 0) {
4407
- reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) + (str.length + 2) > ctx.options.lineWidth);
4408
- }
4409
- if (reqNewline) {
4410
- str += ",";
4411
- }
4571
+ let keyCommentDone = false;
4572
+ let chompKeep = false;
4573
+ let str = stringify(key, ctx, () => keyCommentDone = true, () => chompKeep = true);
4574
+ if (!explicitKey && !ctx.inFlow && str.length > 1024) {
4575
+ if (simpleKeys)
4576
+ throw new Error("With simple keys, single line scalar must not span more than 1024 characters");
4577
+ explicitKey = true;
4578
+ }
4579
+ if (ctx.inFlow) {
4580
+ if (allNullValues || value == null) {
4581
+ if (keyCommentDone && onComment)
4582
+ onComment();
4583
+ return str === "" ? "?" : explicitKey ? `? ${str}` : str;
4412
4584
  }
4413
- if (comment)
4414
- str += lineComment(str, itemIndent, commentString(comment));
4415
- lines.push(str);
4416
- linesAtValue = lines.length;
4585
+ } else if (allNullValues && !simpleKeys || value == null && explicitKey) {
4586
+ str = `? ${str}`;
4587
+ if (keyComment && !keyCommentDone) {
4588
+ str += lineComment(str, ctx.indent, commentString(keyComment));
4589
+ } else if (chompKeep && onChompKeep)
4590
+ onChompKeep();
4591
+ return str;
4417
4592
  }
4418
- const { start, end } = flowChars;
4419
- if (lines.length === 0) {
4420
- return start + end;
4593
+ if (keyCommentDone)
4594
+ keyComment = null;
4595
+ if (explicitKey) {
4596
+ if (keyComment)
4597
+ str += lineComment(str, ctx.indent, commentString(keyComment));
4598
+ str = `? ${str}
4599
+ ${indent}:`;
4421
4600
  } else {
4422
- if (!reqNewline) {
4423
- const len = lines.reduce((sum, line) => sum + line.length + 2, 2);
4424
- reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;
4601
+ str = `${str}:`;
4602
+ if (keyComment)
4603
+ str += lineComment(str, ctx.indent, commentString(keyComment));
4604
+ }
4605
+ let vsb, vcb, valueComment;
4606
+ if (isNode(value)) {
4607
+ vsb = !!value.spaceBefore;
4608
+ vcb = value.commentBefore;
4609
+ valueComment = value.comment;
4610
+ } else {
4611
+ vsb = false;
4612
+ vcb = null;
4613
+ valueComment = null;
4614
+ if (value && typeof value === "object")
4615
+ value = doc.createNode(value);
4616
+ }
4617
+ ctx.implicitKey = false;
4618
+ if (!explicitKey && !keyComment && isScalar(value))
4619
+ ctx.indentAtStart = str.length + 1;
4620
+ chompKeep = false;
4621
+ if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && isSeq(value) && !value.flow && !value.tag && !value.anchor) {
4622
+ ctx.indent = ctx.indent.substring(2);
4623
+ }
4624
+ let valueCommentDone = false;
4625
+ const valueStr = stringify(value, ctx, () => valueCommentDone = true, () => chompKeep = true);
4626
+ let ws = " ";
4627
+ if (keyComment || vsb || vcb) {
4628
+ ws = vsb ? "\n" : "";
4629
+ if (vcb) {
4630
+ const cs = commentString(vcb);
4631
+ ws += `
4632
+ ${indentComment(cs, ctx.indent)}`;
4425
4633
  }
4426
- if (reqNewline) {
4427
- let str = start;
4428
- for (const line of lines)
4429
- str += line ? `
4430
- ${indentStep}${indent}${line}` : "\n";
4431
- return `${str}
4432
- ${indent}${end}`;
4634
+ if (valueStr === "" && !ctx.inFlow) {
4635
+ if (ws === "\n" && valueComment)
4636
+ ws = "\n\n";
4433
4637
  } else {
4434
- return `${start}${fcPadding}${lines.join(" ")}${fcPadding}${end}`;
4638
+ ws += `
4639
+ ${ctx.indent}`;
4640
+ }
4641
+ } else if (!explicitKey && isCollection(value)) {
4642
+ const vs0 = valueStr[0];
4643
+ const nl0 = valueStr.indexOf("\n");
4644
+ const hasNewline = nl0 !== -1;
4645
+ const flow = ctx.inFlow ?? value.flow ?? value.items.length === 0;
4646
+ if (hasNewline || !flow) {
4647
+ let hasPropsLine = false;
4648
+ if (hasNewline && (vs0 === "&" || vs0 === "!")) {
4649
+ let sp0 = valueStr.indexOf(" ");
4650
+ if (vs0 === "&" && sp0 !== -1 && sp0 < nl0 && valueStr[sp0 + 1] === "!") {
4651
+ sp0 = valueStr.indexOf(" ", sp0 + 1);
4652
+ }
4653
+ if (sp0 === -1 || nl0 < sp0)
4654
+ hasPropsLine = true;
4655
+ }
4656
+ if (!hasPropsLine)
4657
+ ws = `
4658
+ ${ctx.indent}`;
4435
4659
  }
4660
+ } else if (valueStr === "" || valueStr[0] === "\n") {
4661
+ ws = "";
4436
4662
  }
4437
- }
4438
- function addCommentBefore({ indent, options: { commentString } }, lines, comment, chompKeep) {
4439
- if (comment && chompKeep)
4440
- comment = comment.replace(/^\n+/, "");
4441
- if (comment) {
4442
- const ic = indentComment(commentString(comment), indent);
4443
- lines.push(ic.trimStart());
4663
+ str += ws + valueStr;
4664
+ if (ctx.inFlow) {
4665
+ if (valueCommentDone && onComment)
4666
+ onComment();
4667
+ } else if (valueComment && !valueCommentDone) {
4668
+ str += lineComment(str, ctx.indent, commentString(valueComment));
4669
+ } else if (chompKeep && onChompKeep) {
4670
+ onChompKeep();
4444
4671
  }
4672
+ return str;
4445
4673
  }
4446
4674
 
4447
- // ../../node_modules/yaml/browser/dist/nodes/YAMLMap.js
4448
- function findPair(items, key) {
4449
- const k = isScalar(key) ? key.value : key;
4450
- for (const it of items) {
4451
- if (isPair(it)) {
4452
- if (it.key === key || it.key === k)
4453
- return it;
4454
- if (isScalar(it.key) && it.key.value === k)
4455
- return it;
4456
- }
4675
+ // ../../node_modules/yaml/browser/dist/log.js
4676
+ function warn(logLevel, warning) {
4677
+ if (logLevel === "debug" || logLevel === "warn") {
4678
+ console.warn(warning);
4457
4679
  }
4458
- return void 0;
4459
4680
  }
4460
- var YAMLMap = class extends Collection {
4461
- static get tagName() {
4462
- return "tag:yaml.org,2002:map";
4463
- }
4464
- constructor(schema4) {
4465
- super(MAP, schema4);
4466
- this.items = [];
4467
- }
4468
- /**
4469
- * A generic collection parsing method that can be extended
4470
- * to other node classes that inherit from YAMLMap
4471
- */
4472
- static from(schema4, obj, ctx) {
4473
- const { keepUndefined, replacer } = ctx;
4474
- const map2 = new this(schema4);
4475
- const add = (key, value) => {
4476
- if (typeof replacer === "function")
4477
- value = replacer.call(obj, key, value);
4478
- else if (Array.isArray(replacer) && !replacer.includes(key))
4479
- return;
4480
- if (value !== void 0 || keepUndefined)
4481
- map2.items.push(createPair(key, value, ctx));
4482
- };
4483
- if (obj instanceof Map) {
4484
- for (const [key, value] of obj)
4485
- add(key, value);
4486
- } else if (obj && typeof obj === "object") {
4487
- for (const key of Object.keys(obj))
4488
- add(key, obj[key]);
4489
- }
4490
- if (typeof schema4.sortMapEntries === "function") {
4491
- map2.items.sort(schema4.sortMapEntries);
4681
+
4682
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js
4683
+ var MERGE_KEY = "<<";
4684
+ var merge = {
4685
+ identify: (value) => value === MERGE_KEY || typeof value === "symbol" && value.description === MERGE_KEY,
4686
+ default: "key",
4687
+ tag: "tag:yaml.org,2002:merge",
4688
+ test: /^<<$/,
4689
+ resolve: () => Object.assign(new Scalar(Symbol(MERGE_KEY)), {
4690
+ addToJSMap: addMergeToJSMap
4691
+ }),
4692
+ stringify: () => MERGE_KEY
4693
+ };
4694
+ var isMergeKey = (ctx, key) => (merge.identify(key) || isScalar(key) && (!key.type || key.type === Scalar.PLAIN) && merge.identify(key.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default);
4695
+ function addMergeToJSMap(ctx, map2, value) {
4696
+ const source = resolveAliasValue(ctx, value);
4697
+ if (isSeq(source))
4698
+ for (const it of source.items)
4699
+ mergeValue(ctx, map2, it);
4700
+ else if (Array.isArray(source))
4701
+ for (const it of source)
4702
+ mergeValue(ctx, map2, it);
4703
+ else
4704
+ mergeValue(ctx, map2, source);
4705
+ }
4706
+ function mergeValue(ctx, map2, value) {
4707
+ const source = resolveAliasValue(ctx, value);
4708
+ if (!isMap(source))
4709
+ throw new Error("Merge sources must be maps or map aliases");
4710
+ const srcMap = source.toJSON(null, ctx, Map);
4711
+ for (const [key, value2] of srcMap) {
4712
+ if (map2 instanceof Map) {
4713
+ if (!map2.has(key))
4714
+ map2.set(key, value2);
4715
+ } else if (map2 instanceof Set) {
4716
+ map2.add(key);
4717
+ } else if (!Object.prototype.hasOwnProperty.call(map2, key)) {
4718
+ Object.defineProperty(map2, key, {
4719
+ value: value2,
4720
+ writable: true,
4721
+ enumerable: true,
4722
+ configurable: true
4723
+ });
4492
4724
  }
4493
- return map2;
4494
4725
  }
4495
- /**
4496
- * Adds a value to the collection.
4497
- *
4498
- * @param overwrite - If not set `true`, using a key that is already in the
4499
- * collection will throw. Otherwise, overwrites the previous value.
4500
- */
4501
- add(pair, overwrite) {
4502
- let _pair;
4503
- if (isPair(pair))
4504
- _pair = pair;
4505
- else if (!pair || typeof pair !== "object" || !("key" in pair)) {
4506
- _pair = new Pair(pair, pair?.value);
4507
- } else
4508
- _pair = new Pair(pair.key, pair.value);
4509
- const prev = findPair(this.items, _pair.key);
4510
- const sortEntries = this.schema?.sortMapEntries;
4511
- if (prev) {
4512
- if (!overwrite)
4513
- throw new Error(`Key ${_pair.key} already set`);
4514
- if (isScalar(prev.value) && isScalarValue(_pair.value))
4515
- prev.value.value = _pair.value;
4516
- else
4517
- prev.value = _pair.value;
4518
- } else if (sortEntries) {
4519
- const i = this.items.findIndex((item) => sortEntries(_pair, item) < 0);
4520
- if (i === -1)
4521
- this.items.push(_pair);
4522
- else
4523
- this.items.splice(i, 0, _pair);
4726
+ return map2;
4727
+ }
4728
+ function resolveAliasValue(ctx, value) {
4729
+ return ctx && isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
4730
+ }
4731
+
4732
+ // ../../node_modules/yaml/browser/dist/nodes/addPairToJSMap.js
4733
+ function addPairToJSMap(ctx, map2, { key, value }) {
4734
+ if (isNode(key) && key.addToJSMap)
4735
+ key.addToJSMap(ctx, map2, value);
4736
+ else if (isMergeKey(ctx, key))
4737
+ addMergeToJSMap(ctx, map2, value);
4738
+ else {
4739
+ const jsKey = toJS(key, "", ctx);
4740
+ if (map2 instanceof Map) {
4741
+ map2.set(jsKey, toJS(value, jsKey, ctx));
4742
+ } else if (map2 instanceof Set) {
4743
+ map2.add(jsKey);
4524
4744
  } else {
4525
- this.items.push(_pair);
4745
+ const stringKey = stringifyKey(key, jsKey, ctx);
4746
+ const jsValue = toJS(value, stringKey, ctx);
4747
+ if (stringKey in map2)
4748
+ Object.defineProperty(map2, stringKey, {
4749
+ value: jsValue,
4750
+ writable: true,
4751
+ enumerable: true,
4752
+ configurable: true
4753
+ });
4754
+ else
4755
+ map2[stringKey] = jsValue;
4526
4756
  }
4527
4757
  }
4528
- delete(key) {
4529
- const it = findPair(this.items, key);
4530
- if (!it)
4531
- return false;
4532
- const del = this.items.splice(this.items.indexOf(it), 1);
4533
- return del.length > 0;
4534
- }
4535
- get(key, keepScalar) {
4536
- const it = findPair(this.items, key);
4537
- const node = it?.value;
4538
- return (!keepScalar && isScalar(node) ? node.value : node) ?? void 0;
4758
+ return map2;
4759
+ }
4760
+ function stringifyKey(key, jsKey, ctx) {
4761
+ if (jsKey === null)
4762
+ return "";
4763
+ if (typeof jsKey !== "object")
4764
+ return String(jsKey);
4765
+ if (isNode(key) && ctx?.doc) {
4766
+ const strCtx = createStringifyContext(ctx.doc, {});
4767
+ strCtx.anchors = /* @__PURE__ */ new Set();
4768
+ for (const node of ctx.anchors.keys())
4769
+ strCtx.anchors.add(node.anchor);
4770
+ strCtx.inFlow = true;
4771
+ strCtx.inStringifyKey = true;
4772
+ const strKey = key.toString(strCtx);
4773
+ if (!ctx.mapKeyWarned) {
4774
+ let jsonStr = JSON.stringify(strKey);
4775
+ if (jsonStr.length > 40)
4776
+ jsonStr = jsonStr.substring(0, 36) + '..."';
4777
+ warn(ctx.doc.options.logLevel, `Keys with collection values will be stringified due to JS Object restrictions: ${jsonStr}. Set mapAsMap: true to use object keys.`);
4778
+ ctx.mapKeyWarned = true;
4779
+ }
4780
+ return strKey;
4539
4781
  }
4540
- has(key) {
4541
- return !!findPair(this.items, key);
4782
+ return JSON.stringify(jsKey);
4783
+ }
4784
+
4785
+ // ../../node_modules/yaml/browser/dist/nodes/Pair.js
4786
+ function createPair(key, value, ctx) {
4787
+ const k = createNode(key, void 0, ctx);
4788
+ const v = createNode(value, void 0, ctx);
4789
+ return new Pair(k, v);
4790
+ }
4791
+ var Pair = class _Pair {
4792
+ constructor(key, value = null) {
4793
+ Object.defineProperty(this, NODE_TYPE, { value: PAIR });
4794
+ this.key = key;
4795
+ this.value = value;
4542
4796
  }
4543
- set(key, value) {
4544
- this.add(new Pair(key, value), true);
4797
+ clone(schema4) {
4798
+ let { key, value } = this;
4799
+ if (isNode(key))
4800
+ key = key.clone(schema4);
4801
+ if (isNode(value))
4802
+ value = value.clone(schema4);
4803
+ return new _Pair(key, value);
4545
4804
  }
4546
- /**
4547
- * @param ctx - Conversion context, originally set in Document#toJS()
4548
- * @param {Class} Type - If set, forces the returned collection type
4549
- * @returns Instance of Type, Map, or Object
4550
- */
4551
- toJSON(_, ctx, Type) {
4552
- const map2 = Type ? new Type() : ctx?.mapAsMap ? /* @__PURE__ */ new Map() : {};
4553
- if (ctx?.onCreate)
4554
- ctx.onCreate(map2);
4555
- for (const item of this.items)
4556
- addPairToJSMap(ctx, map2, item);
4557
- return map2;
4805
+ toJSON(_, ctx) {
4806
+ const pair = ctx?.mapAsMap ? /* @__PURE__ */ new Map() : {};
4807
+ return addPairToJSMap(ctx, pair, this);
4558
4808
  }
4559
4809
  toString(ctx, onComment, onChompKeep) {
4560
- if (!ctx)
4561
- return JSON.stringify(this);
4562
- for (const item of this.items) {
4563
- if (!isPair(item))
4564
- throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
4565
- }
4566
- if (!ctx.allNullValues && this.hasAllNullValues(false))
4567
- ctx = Object.assign({}, ctx, { allNullValues: true });
4568
- return stringifyCollection(this, ctx, {
4569
- blockItemPrefix: "",
4570
- flowChars: { start: "{", end: "}" },
4571
- itemIndent: ctx.indent || "",
4572
- onChompKeep,
4573
- onComment
4574
- });
4810
+ return ctx?.doc ? stringifyPair(this, ctx, onComment, onChompKeep) : JSON.stringify(this);
4575
4811
  }
4576
4812
  };
4577
4813
 
4578
- // ../../node_modules/yaml/browser/dist/schema/common/map.js
4579
- var map = {
4580
- collection: "map",
4581
- default: true,
4582
- nodeClass: YAMLMap,
4583
- tag: "tag:yaml.org,2002:map",
4584
- resolve(map2, onError) {
4585
- if (!isMap(map2))
4586
- onError("Expected a mapping for this tag");
4587
- return map2;
4588
- },
4589
- createNode: (schema4, obj, ctx) => YAMLMap.from(schema4, obj, ctx)
4590
- };
4591
-
4592
- // ../../node_modules/yaml/browser/dist/nodes/YAMLSeq.js
4593
- var YAMLSeq = class extends Collection {
4594
- static get tagName() {
4595
- return "tag:yaml.org,2002:seq";
4596
- }
4597
- constructor(schema4) {
4598
- super(SEQ, schema4);
4599
- this.items = [];
4600
- }
4601
- add(value) {
4602
- this.items.push(value);
4603
- }
4604
- /**
4605
- * Removes a value from the collection.
4606
- *
4607
- * `key` must contain a representation of an integer for this to succeed.
4608
- * It may be wrapped in a `Scalar`.
4609
- *
4610
- * @returns `true` if the item was found and removed.
4611
- */
4612
- delete(key) {
4613
- const idx = asItemIndex(key);
4614
- if (typeof idx !== "number")
4615
- return false;
4616
- const del = this.items.splice(idx, 1);
4617
- return del.length > 0;
4618
- }
4619
- get(key, keepScalar) {
4620
- const idx = asItemIndex(key);
4621
- if (typeof idx !== "number")
4622
- return void 0;
4623
- const it = this.items[idx];
4624
- return !keepScalar && isScalar(it) ? it.value : it;
4625
- }
4626
- /**
4627
- * Checks if the collection includes a value with the key `key`.
4628
- *
4629
- * `key` must contain a representation of an integer for this to succeed.
4630
- * It may be wrapped in a `Scalar`.
4631
- */
4632
- has(key) {
4633
- const idx = asItemIndex(key);
4634
- return typeof idx === "number" && idx < this.items.length;
4635
- }
4636
- /**
4637
- * Sets a value in this collection. For `!!set`, `value` needs to be a
4638
- * boolean to add/remove the item from the set.
4639
- *
4640
- * If `key` does not contain a representation of an integer, this will throw.
4641
- * It may be wrapped in a `Scalar`.
4642
- */
4643
- set(key, value) {
4644
- const idx = asItemIndex(key);
4645
- if (typeof idx !== "number")
4646
- throw new Error(`Expected a valid index, not ${key}.`);
4647
- const prev = this.items[idx];
4648
- if (isScalar(prev) && isScalarValue(value))
4649
- prev.value = value;
4650
- else
4651
- this.items[idx] = value;
4652
- }
4653
- toJSON(_, ctx) {
4654
- const seq2 = [];
4655
- if (ctx?.onCreate)
4656
- ctx.onCreate(seq2);
4657
- let i = 0;
4658
- for (const item of this.items)
4659
- seq2.push(toJS(item, String(i++), ctx));
4660
- return seq2;
4814
+ // ../../node_modules/yaml/browser/dist/stringify/stringifyCollection.js
4815
+ function stringifyCollection(collection, ctx, options) {
4816
+ const flow = ctx.inFlow ?? collection.flow;
4817
+ const stringify4 = flow ? stringifyFlowCollection : stringifyBlockCollection;
4818
+ return stringify4(collection, ctx, options);
4819
+ }
4820
+ function stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, flowChars, itemIndent, onChompKeep, onComment }) {
4821
+ const { indent, options: { commentString } } = ctx;
4822
+ const itemCtx = Object.assign({}, ctx, { indent: itemIndent, type: null });
4823
+ let chompKeep = false;
4824
+ const lines = [];
4825
+ for (let i = 0; i < items.length; ++i) {
4826
+ const item = items[i];
4827
+ let comment2 = null;
4828
+ if (isNode(item)) {
4829
+ if (!chompKeep && item.spaceBefore)
4830
+ lines.push("");
4831
+ addCommentBefore(ctx, lines, item.commentBefore, chompKeep);
4832
+ if (item.comment)
4833
+ comment2 = item.comment;
4834
+ } else if (isPair(item)) {
4835
+ const ik = isNode(item.key) ? item.key : null;
4836
+ if (ik) {
4837
+ if (!chompKeep && ik.spaceBefore)
4838
+ lines.push("");
4839
+ addCommentBefore(ctx, lines, ik.commentBefore, chompKeep);
4840
+ }
4841
+ }
4842
+ chompKeep = false;
4843
+ let str2 = stringify(item, itemCtx, () => comment2 = null, () => chompKeep = true);
4844
+ if (comment2)
4845
+ str2 += lineComment(str2, itemIndent, commentString(comment2));
4846
+ if (chompKeep && comment2)
4847
+ chompKeep = false;
4848
+ lines.push(blockItemPrefix + str2);
4661
4849
  }
4662
- toString(ctx, onComment, onChompKeep) {
4663
- if (!ctx)
4664
- return JSON.stringify(this);
4665
- return stringifyCollection(this, ctx, {
4666
- blockItemPrefix: "- ",
4667
- flowChars: { start: "[", end: "]" },
4668
- itemIndent: (ctx.indent || "") + " ",
4669
- onChompKeep,
4670
- onComment
4671
- });
4850
+ let str;
4851
+ if (lines.length === 0) {
4852
+ str = flowChars.start + flowChars.end;
4853
+ } else {
4854
+ str = lines[0];
4855
+ for (let i = 1; i < lines.length; ++i) {
4856
+ const line = lines[i];
4857
+ str += line ? `
4858
+ ${indent}${line}` : "\n";
4859
+ }
4672
4860
  }
4673
- static from(schema4, obj, ctx) {
4674
- const { replacer } = ctx;
4675
- const seq2 = new this(schema4);
4676
- if (obj && Symbol.iterator in Object(obj)) {
4677
- let i = 0;
4678
- for (let it of obj) {
4679
- if (typeof replacer === "function") {
4680
- const key = obj instanceof Set ? it : String(i++);
4681
- it = replacer.call(obj, key, it);
4682
- }
4683
- seq2.items.push(createNode(it, void 0, ctx));
4861
+ if (comment) {
4862
+ str += "\n" + indentComment(commentString(comment), indent);
4863
+ if (onComment)
4864
+ onComment();
4865
+ } else if (chompKeep && onChompKeep)
4866
+ onChompKeep();
4867
+ return str;
4868
+ }
4869
+ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
4870
+ const { indent, indentStep, flowCollectionPadding: fcPadding, options: { commentString } } = ctx;
4871
+ itemIndent += indentStep;
4872
+ const itemCtx = Object.assign({}, ctx, {
4873
+ indent: itemIndent,
4874
+ inFlow: true,
4875
+ type: null
4876
+ });
4877
+ let reqNewline = false;
4878
+ let linesAtValue = 0;
4879
+ const lines = [];
4880
+ for (let i = 0; i < items.length; ++i) {
4881
+ const item = items[i];
4882
+ let comment = null;
4883
+ if (isNode(item)) {
4884
+ if (item.spaceBefore)
4885
+ lines.push("");
4886
+ addCommentBefore(ctx, lines, item.commentBefore, false);
4887
+ if (item.comment)
4888
+ comment = item.comment;
4889
+ } else if (isPair(item)) {
4890
+ const ik = isNode(item.key) ? item.key : null;
4891
+ if (ik) {
4892
+ if (ik.spaceBefore)
4893
+ lines.push("");
4894
+ addCommentBefore(ctx, lines, ik.commentBefore, false);
4895
+ if (ik.comment)
4896
+ reqNewline = true;
4897
+ }
4898
+ const iv = isNode(item.value) ? item.value : null;
4899
+ if (iv) {
4900
+ if (iv.comment)
4901
+ comment = iv.comment;
4902
+ if (iv.commentBefore)
4903
+ reqNewline = true;
4904
+ } else if (item.value == null && ik?.comment) {
4905
+ comment = ik.comment;
4684
4906
  }
4685
4907
  }
4686
- return seq2;
4908
+ if (comment)
4909
+ reqNewline = true;
4910
+ let str = stringify(item, itemCtx, () => comment = null);
4911
+ reqNewline || (reqNewline = lines.length > linesAtValue || str.includes("\n"));
4912
+ if (i < items.length - 1) {
4913
+ str += ",";
4914
+ } else if (ctx.options.trailingComma) {
4915
+ if (ctx.options.lineWidth > 0) {
4916
+ reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) + (str.length + 2) > ctx.options.lineWidth);
4917
+ }
4918
+ if (reqNewline) {
4919
+ str += ",";
4920
+ }
4921
+ }
4922
+ if (comment)
4923
+ str += lineComment(str, itemIndent, commentString(comment));
4924
+ lines.push(str);
4925
+ linesAtValue = lines.length;
4926
+ }
4927
+ const { start, end } = flowChars;
4928
+ if (lines.length === 0) {
4929
+ return start + end;
4930
+ } else {
4931
+ if (!reqNewline) {
4932
+ const len = lines.reduce((sum, line) => sum + line.length + 2, 2);
4933
+ reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;
4934
+ }
4935
+ if (reqNewline) {
4936
+ let str = start;
4937
+ for (const line of lines)
4938
+ str += line ? `
4939
+ ${indentStep}${indent}${line}` : "\n";
4940
+ return `${str}
4941
+ ${indent}${end}`;
4942
+ } else {
4943
+ return `${start}${fcPadding}${lines.join(" ")}${fcPadding}${end}`;
4944
+ }
4945
+ }
4946
+ }
4947
+ function addCommentBefore({ indent, options: { commentString } }, lines, comment, chompKeep) {
4948
+ if (comment && chompKeep)
4949
+ comment = comment.replace(/^\n+/, "");
4950
+ if (comment) {
4951
+ const ic = indentComment(commentString(comment), indent);
4952
+ lines.push(ic.trimStart());
4687
4953
  }
4688
- };
4689
- function asItemIndex(key) {
4690
- let idx = isScalar(key) ? key.value : key;
4691
- if (idx && typeof idx === "string")
4692
- idx = Number(idx);
4693
- return typeof idx === "number" && Number.isInteger(idx) && idx >= 0 ? idx : null;
4694
4954
  }
4695
4955
 
4696
- // ../../node_modules/yaml/browser/dist/schema/common/seq.js
4697
- var seq = {
4698
- collection: "seq",
4699
- default: true,
4700
- nodeClass: YAMLSeq,
4701
- tag: "tag:yaml.org,2002:seq",
4702
- resolve(seq2, onError) {
4703
- if (!isSeq(seq2))
4704
- onError("Expected a sequence for this tag");
4705
- return seq2;
4706
- },
4707
- createNode: (schema4, obj, ctx) => YAMLSeq.from(schema4, obj, ctx)
4708
- };
4709
-
4710
- // ../../node_modules/yaml/browser/dist/schema/json/schema.js
4711
- function intIdentify(value) {
4712
- return typeof value === "bigint" || Number.isInteger(value);
4956
+ // ../../node_modules/yaml/browser/dist/nodes/YAMLMap.js
4957
+ function findPair(items, key) {
4958
+ const k = isScalar(key) ? key.value : key;
4959
+ for (const it of items) {
4960
+ if (isPair(it)) {
4961
+ if (it.key === key || it.key === k)
4962
+ return it;
4963
+ if (isScalar(it.key) && it.key.value === k)
4964
+ return it;
4965
+ }
4966
+ }
4967
+ return void 0;
4713
4968
  }
4714
- var stringifyJSON = ({ value }) => JSON.stringify(value);
4715
- var jsonScalars = [
4716
- {
4717
- identify: (value) => typeof value === "string",
4718
- default: true,
4719
- tag: "tag:yaml.org,2002:str",
4720
- resolve: (str) => str,
4721
- stringify: stringifyJSON
4722
- },
4723
- {
4724
- identify: (value) => value == null,
4725
- createNode: () => new Scalar(null),
4726
- default: true,
4727
- tag: "tag:yaml.org,2002:null",
4728
- test: /^null$/,
4729
- resolve: () => null,
4730
- stringify: stringifyJSON
4731
- },
4732
- {
4733
- identify: (value) => typeof value === "boolean",
4734
- default: true,
4735
- tag: "tag:yaml.org,2002:bool",
4736
- test: /^true$|^false$/,
4737
- resolve: (str) => str === "true",
4738
- stringify: stringifyJSON
4739
- },
4740
- {
4741
- identify: intIdentify,
4742
- default: true,
4743
- tag: "tag:yaml.org,2002:int",
4744
- test: /^-?(?:0|[1-9][0-9]*)$/,
4745
- resolve: (str, _onError, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str, 10),
4746
- stringify: ({ value }) => intIdentify(value) ? value.toString() : JSON.stringify(value)
4747
- },
4748
- {
4749
- identify: (value) => typeof value === "number",
4750
- default: true,
4751
- tag: "tag:yaml.org,2002:float",
4752
- test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
4753
- resolve: (str) => parseFloat(str),
4754
- stringify: stringifyJSON
4969
+ var YAMLMap = class extends Collection {
4970
+ static get tagName() {
4971
+ return "tag:yaml.org,2002:map";
4755
4972
  }
4756
- ];
4757
- var jsonError = {
4758
- default: true,
4759
- tag: "",
4760
- test: /^/,
4761
- resolve(str, onError) {
4762
- onError(`Unresolved plain scalar ${JSON.stringify(str)}`);
4763
- return str;
4973
+ constructor(schema4) {
4974
+ super(MAP, schema4);
4975
+ this.items = [];
4764
4976
  }
4765
- };
4766
- var schema = [map, seq].concat(jsonScalars, jsonError);
4767
-
4768
- // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js
4769
- function createPairs(schema4, iterable, ctx) {
4770
- const { replacer } = ctx;
4771
- const pairs2 = new YAMLSeq(schema4);
4772
- pairs2.tag = "tag:yaml.org,2002:pairs";
4773
- let i = 0;
4774
- if (iterable && Symbol.iterator in Object(iterable))
4775
- for (let it of iterable) {
4977
+ /**
4978
+ * A generic collection parsing method that can be extended
4979
+ * to other node classes that inherit from YAMLMap
4980
+ */
4981
+ static from(schema4, obj, ctx) {
4982
+ const { keepUndefined, replacer } = ctx;
4983
+ const map2 = new this(schema4);
4984
+ const add = (key, value) => {
4776
4985
  if (typeof replacer === "function")
4777
- it = replacer.call(iterable, String(i++), it);
4778
- let key, value;
4779
- if (Array.isArray(it)) {
4780
- if (it.length === 2) {
4781
- key = it[0];
4782
- value = it[1];
4783
- } else
4784
- throw new TypeError(`Expected [key, value] tuple: ${it}`);
4785
- } else if (it && it instanceof Object) {
4786
- const keys = Object.keys(it);
4787
- if (keys.length === 1) {
4788
- key = keys[0];
4789
- value = it[key];
4790
- } else {
4791
- throw new TypeError(`Expected tuple with one key, not ${keys.length} keys`);
4792
- }
4793
- } else {
4794
- key = it;
4795
- }
4796
- pairs2.items.push(createPair(key, value, ctx));
4986
+ value = replacer.call(obj, key, value);
4987
+ else if (Array.isArray(replacer) && !replacer.includes(key))
4988
+ return;
4989
+ if (value !== void 0 || keepUndefined)
4990
+ map2.items.push(createPair(key, value, ctx));
4991
+ };
4992
+ if (obj instanceof Map) {
4993
+ for (const [key, value] of obj)
4994
+ add(key, value);
4995
+ } else if (obj && typeof obj === "object") {
4996
+ for (const key of Object.keys(obj))
4997
+ add(key, obj[key]);
4797
4998
  }
4798
- return pairs2;
4799
- }
4800
-
4801
- // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js
4802
- var YAMLOMap = class _YAMLOMap extends YAMLSeq {
4803
- constructor() {
4804
- super();
4805
- this.add = YAMLMap.prototype.add.bind(this);
4806
- this.delete = YAMLMap.prototype.delete.bind(this);
4807
- this.get = YAMLMap.prototype.get.bind(this);
4808
- this.has = YAMLMap.prototype.has.bind(this);
4809
- this.set = YAMLMap.prototype.set.bind(this);
4810
- this.tag = _YAMLOMap.tag;
4999
+ if (typeof schema4.sortMapEntries === "function") {
5000
+ map2.items.sort(schema4.sortMapEntries);
5001
+ }
5002
+ return map2;
4811
5003
  }
4812
5004
  /**
4813
- * If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
4814
- * but TypeScript won't allow widening the signature of a child method.
5005
+ * Adds a value to the collection.
5006
+ *
5007
+ * @param overwrite - If not set `true`, using a key that is already in the
5008
+ * collection will throw. Otherwise, overwrites the previous value.
4815
5009
  */
4816
- toJSON(_, ctx) {
4817
- if (!ctx)
4818
- return super.toJSON(_);
4819
- const map2 = /* @__PURE__ */ new Map();
4820
- if (ctx?.onCreate)
4821
- ctx.onCreate(map2);
4822
- for (const pair of this.items) {
4823
- let key, value;
4824
- if (isPair(pair)) {
4825
- key = toJS(pair.key, "", ctx);
4826
- value = toJS(pair.value, key, ctx);
4827
- } else {
4828
- key = toJS(pair, "", ctx);
4829
- }
4830
- if (map2.has(key))
4831
- throw new Error("Ordered maps must not include duplicate keys");
4832
- map2.set(key, value);
5010
+ add(pair, overwrite) {
5011
+ let _pair;
5012
+ if (isPair(pair))
5013
+ _pair = pair;
5014
+ else if (!pair || typeof pair !== "object" || !("key" in pair)) {
5015
+ _pair = new Pair(pair, pair?.value);
5016
+ } else
5017
+ _pair = new Pair(pair.key, pair.value);
5018
+ const prev = findPair(this.items, _pair.key);
5019
+ const sortEntries = this.schema?.sortMapEntries;
5020
+ if (prev) {
5021
+ if (!overwrite)
5022
+ throw new Error(`Key ${_pair.key} already set`);
5023
+ if (isScalar(prev.value) && isScalarValue(_pair.value))
5024
+ prev.value.value = _pair.value;
5025
+ else
5026
+ prev.value = _pair.value;
5027
+ } else if (sortEntries) {
5028
+ const i = this.items.findIndex((item) => sortEntries(_pair, item) < 0);
5029
+ if (i === -1)
5030
+ this.items.push(_pair);
5031
+ else
5032
+ this.items.splice(i, 0, _pair);
5033
+ } else {
5034
+ this.items.push(_pair);
4833
5035
  }
4834
- return map2;
4835
- }
4836
- static from(schema4, iterable, ctx) {
4837
- const pairs2 = createPairs(schema4, iterable, ctx);
4838
- const omap2 = new this();
4839
- omap2.items = pairs2.items;
4840
- return omap2;
4841
5036
  }
4842
- };
4843
- YAMLOMap.tag = "tag:yaml.org,2002:omap";
4844
-
4845
- // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/set.js
4846
- var YAMLSet = class _YAMLSet extends YAMLMap {
4847
- constructor(schema4) {
4848
- super(schema4);
4849
- this.tag = _YAMLSet.tag;
5037
+ delete(key) {
5038
+ const it = findPair(this.items, key);
5039
+ if (!it)
5040
+ return false;
5041
+ const del = this.items.splice(this.items.indexOf(it), 1);
5042
+ return del.length > 0;
4850
5043
  }
4851
- add(key) {
4852
- let pair;
4853
- if (isPair(key))
4854
- pair = key;
4855
- else if (key && typeof key === "object" && "key" in key && "value" in key && key.value === null)
4856
- pair = new Pair(key.key, null);
4857
- else
4858
- pair = new Pair(key, null);
4859
- const prev = findPair(this.items, pair.key);
4860
- if (!prev)
4861
- this.items.push(pair);
5044
+ get(key, keepScalar) {
5045
+ const it = findPair(this.items, key);
5046
+ const node = it?.value;
5047
+ return (!keepScalar && isScalar(node) ? node.value : node) ?? void 0;
4862
5048
  }
4863
- /**
4864
- * If `keepPair` is `true`, returns the Pair matching `key`.
4865
- * Otherwise, returns the value of that Pair's key.
4866
- */
4867
- get(key, keepPair) {
4868
- const pair = findPair(this.items, key);
4869
- return !keepPair && isPair(pair) ? isScalar(pair.key) ? pair.key.value : pair.key : pair;
5049
+ has(key) {
5050
+ return !!findPair(this.items, key);
4870
5051
  }
4871
5052
  set(key, value) {
4872
- if (typeof value !== "boolean")
4873
- throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);
4874
- const prev = findPair(this.items, key);
4875
- if (prev && !value) {
4876
- this.items.splice(this.items.indexOf(prev), 1);
4877
- } else if (!prev && value) {
4878
- this.items.push(new Pair(key));
4879
- }
5053
+ this.add(new Pair(key, value), true);
4880
5054
  }
4881
- toJSON(_, ctx) {
4882
- return super.toJSON(_, ctx, Set);
5055
+ /**
5056
+ * @param ctx - Conversion context, originally set in Document#toJS()
5057
+ * @param {Class} Type - If set, forces the returned collection type
5058
+ * @returns Instance of Type, Map, or Object
5059
+ */
5060
+ toJSON(_, ctx, Type) {
5061
+ const map2 = Type ? new Type() : ctx?.mapAsMap ? /* @__PURE__ */ new Map() : {};
5062
+ if (ctx?.onCreate)
5063
+ ctx.onCreate(map2);
5064
+ for (const item of this.items)
5065
+ addPairToJSMap(ctx, map2, item);
5066
+ return map2;
4883
5067
  }
4884
5068
  toString(ctx, onComment, onChompKeep) {
4885
5069
  if (!ctx)
4886
5070
  return JSON.stringify(this);
4887
- if (this.hasAllNullValues(true))
4888
- return super.toString(Object.assign({}, ctx, { allNullValues: true }), onComment, onChompKeep);
4889
- else
4890
- throw new Error("Set items must all have null values");
4891
- }
4892
- static from(schema4, iterable, ctx) {
4893
- const { replacer } = ctx;
4894
- const set2 = new this(schema4);
4895
- if (iterable && Symbol.iterator in Object(iterable))
4896
- for (let value of iterable) {
4897
- if (typeof replacer === "function")
4898
- value = replacer.call(iterable, value, value);
4899
- set2.items.push(createPair(value, null, ctx));
4900
- }
4901
- return set2;
4902
- }
4903
- };
4904
- YAMLSet.tag = "tag:yaml.org,2002:set";
4905
-
4906
- // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js
4907
- function parseSexagesimal(str, asBigInt) {
4908
- const sign = str[0];
4909
- const parts = sign === "-" || sign === "+" ? str.substring(1) : str;
4910
- const num = (n) => asBigInt ? BigInt(n) : Number(n);
4911
- const res = parts.replace(/_/g, "").split(":").reduce((res2, p) => res2 * num(60) + num(p), num(0));
4912
- return sign === "-" ? num(-1) * res : res;
4913
- }
4914
- var timestamp = {
4915
- identify: (value) => value instanceof Date,
4916
- default: true,
4917
- tag: "tag:yaml.org,2002:timestamp",
4918
- // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
4919
- // may be omitted altogether, resulting in a date format. In such a case, the time part is
4920
- // assumed to be 00:00:00Z (start of day, UTC).
4921
- test: RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),
4922
- resolve(str) {
4923
- const match = str.match(timestamp.test);
4924
- if (!match)
4925
- throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");
4926
- const [, year, month, day, hour, minute, second] = match.map(Number);
4927
- const millisec = match[7] ? Number((match[7] + "00").substr(1, 3)) : 0;
4928
- let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec);
4929
- const tz = match[8];
4930
- if (tz && tz !== "Z") {
4931
- let d = parseSexagesimal(tz, false);
4932
- if (Math.abs(d) < 30)
4933
- d *= 60;
4934
- date -= 6e4 * d;
4935
- }
4936
- return new Date(date);
4937
- },
4938
- stringify: ({ value }) => value?.toISOString().replace(/(T00:00:00)?\.000Z$/, "") ?? ""
4939
- };
4940
-
4941
- // ../../node_modules/yaml/browser/dist/parse/cst-visit.js
4942
- var BREAK2 = Symbol("break visit");
4943
- var SKIP2 = Symbol("skip children");
4944
- var REMOVE2 = Symbol("remove item");
4945
- function visit2(cst, visitor) {
4946
- if ("type" in cst && cst.type === "document")
4947
- cst = { start: cst.start, value: cst.value };
4948
- _visit(Object.freeze([]), cst, visitor);
4949
- }
4950
- visit2.BREAK = BREAK2;
4951
- visit2.SKIP = SKIP2;
4952
- visit2.REMOVE = REMOVE2;
4953
- visit2.itemAtPath = (cst, path7) => {
4954
- let item = cst;
4955
- for (const [field, index] of path7) {
4956
- const tok = item?.[field];
4957
- if (tok && "items" in tok) {
4958
- item = tok.items[index];
4959
- } else
4960
- return void 0;
4961
- }
4962
- return item;
4963
- };
4964
- visit2.parentCollection = (cst, path7) => {
4965
- const parent = visit2.itemAtPath(cst, path7.slice(0, -1));
4966
- const field = path7[path7.length - 1][0];
4967
- const coll = parent?.[field];
4968
- if (coll && "items" in coll)
4969
- return coll;
4970
- throw new Error("Parent collection not found");
4971
- };
4972
- function _visit(path7, item, visitor) {
4973
- let ctrl = visitor(item, path7);
4974
- if (typeof ctrl === "symbol")
4975
- return ctrl;
4976
- for (const field of ["key", "value"]) {
4977
- const token = item[field];
4978
- if (token && "items" in token) {
4979
- for (let i = 0; i < token.items.length; ++i) {
4980
- const ci = _visit(Object.freeze(path7.concat([[field, i]])), token.items[i], visitor);
4981
- if (typeof ci === "number")
4982
- i = ci - 1;
4983
- else if (ci === BREAK2)
4984
- return BREAK2;
4985
- else if (ci === REMOVE2) {
4986
- token.items.splice(i, 1);
4987
- i -= 1;
4988
- }
4989
- }
4990
- if (typeof ctrl === "function" && field === "key")
4991
- ctrl = ctrl(item, path7);
5071
+ for (const item of this.items) {
5072
+ if (!isPair(item))
5073
+ throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
4992
5074
  }
5075
+ if (!ctx.allNullValues && this.hasAllNullValues(false))
5076
+ ctx = Object.assign({}, ctx, { allNullValues: true });
5077
+ return stringifyCollection(this, ctx, {
5078
+ blockItemPrefix: "",
5079
+ flowChars: { start: "{", end: "}" },
5080
+ itemIndent: ctx.indent || "",
5081
+ onChompKeep,
5082
+ onComment
5083
+ });
4993
5084
  }
4994
- return typeof ctrl === "function" ? ctrl(item, path7) : ctrl;
4995
- }
4996
-
4997
- // ../../node_modules/yaml/browser/dist/parse/lexer.js
4998
- var hexDigits = new Set("0123456789ABCDEFabcdef");
4999
- var tagChars = new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()");
5000
- var flowIndicatorChars = new Set(",[]{}");
5001
- var invalidAnchorChars = new Set(" ,[]{}\n\r ");
5002
-
5003
- // cli/commands/detect.ts
5004
- var PODFILE_NEW_ARCH_MARK = "PEACH_RCT_NEW_ARCH ";
5005
- var PODFILE_NEW_ARCH_RUBY = `
5006
- require 'json'
5007
- payload = JSON.parse($stdin.read)
5008
- properties = payload['properties']
5009
- properties = {} unless properties.is_a?(Hash)
5010
- podfile_properties = properties
5011
- ENV.delete('RCT_NEW_ARCH_ENABLED')
5012
- scope = binding
5013
- Array(payload['statements']).each do |statement|
5014
- before = ENV['RCT_NEW_ARCH_ENABLED']
5015
- scope.eval(statement)
5016
- after = ENV['RCT_NEW_ARCH_ENABLED']
5017
- if after == before
5018
- puts '${PODFILE_NEW_ARCH_MARK}skip'
5019
- elsif after == '0' || after == '1'
5020
- puts "${PODFILE_NEW_ARCH_MARK}#{after}"
5021
- else
5022
- warn "RCT_NEW_ARCH_ENABLED assigned #{after.inspect}"
5023
- exit 2
5024
- end
5025
- end
5026
- `;
5027
-
5028
- // cli/cloud-client.ts
5029
- var DEFAULT_RNX_CLOUD_ORIGIN = rnxPublicBrand.origin;
5030
-
5031
- // cli/current-sim.ts
5032
- var import_fs3 = require("fs");
5033
- var import_os = require("os");
5034
- var import_path2 = require("path");
5035
-
5036
- // cli/parent-pid.ts
5037
- var import_child_process = require("child_process");
5038
- var import_fs2 = require("fs");
5039
- var import_module = require("module");
5040
- var cached = null;
5041
- var cachedComm = null;
5042
- var cachedPgid = null;
5043
- function getParentPid(pid) {
5044
- if (!cached) cached = build();
5045
- try {
5046
- return cached(pid);
5047
- } catch {
5048
- return null;
5049
- }
5050
- }
5051
- function getProcessComm(pid) {
5052
- if (!cachedComm) cachedComm = buildComm();
5053
- try {
5054
- return cachedComm(pid);
5055
- } catch {
5056
- return null;
5085
+ };
5086
+
5087
+ // ../../node_modules/yaml/browser/dist/schema/common/map.js
5088
+ var map = {
5089
+ collection: "map",
5090
+ default: true,
5091
+ nodeClass: YAMLMap,
5092
+ tag: "tag:yaml.org,2002:map",
5093
+ resolve(map2, onError) {
5094
+ if (!isMap(map2))
5095
+ onError("Expected a mapping for this tag");
5096
+ return map2;
5097
+ },
5098
+ createNode: (schema4, obj, ctx) => YAMLMap.from(schema4, obj, ctx)
5099
+ };
5100
+
5101
+ // ../../node_modules/yaml/browser/dist/nodes/YAMLSeq.js
5102
+ var YAMLSeq = class extends Collection {
5103
+ static get tagName() {
5104
+ return "tag:yaml.org,2002:seq";
5057
5105
  }
5058
- }
5059
- function getProcessPgid(pid) {
5060
- if (!cachedPgid) cachedPgid = buildPgid();
5061
- try {
5062
- return cachedPgid(pid);
5063
- } catch {
5064
- return null;
5106
+ constructor(schema4) {
5107
+ super(SEQ, schema4);
5108
+ this.items = [];
5065
5109
  }
5066
- }
5067
- function buildComm() {
5068
- if (process.platform === "linux") {
5069
- return (pid) => {
5070
- try {
5071
- return (0, import_fs2.readFileSync)(`/proc/${pid}/comm`, "utf8").trim() || null;
5072
- } catch {
5073
- return null;
5074
- }
5075
- };
5110
+ add(value) {
5111
+ this.items.push(value);
5076
5112
  }
5077
- if (process.platform === "darwin") {
5078
- const ffi = tryBuildDarwinCommFfi();
5079
- if (ffi) return ffi;
5080
- return (pid) => readProcessTable2().get(pid)?.comm || null;
5113
+ /**
5114
+ * Removes a value from the collection.
5115
+ *
5116
+ * `key` must contain a representation of an integer for this to succeed.
5117
+ * It may be wrapped in a `Scalar`.
5118
+ *
5119
+ * @returns `true` if the item was found and removed.
5120
+ */
5121
+ delete(key) {
5122
+ const idx = asItemIndex(key);
5123
+ if (typeof idx !== "number")
5124
+ return false;
5125
+ const del = this.items.splice(idx, 1);
5126
+ return del.length > 0;
5081
5127
  }
5082
- return () => null;
5083
- }
5084
- function build() {
5085
- if (process.platform === "linux") return buildLinux();
5086
- if (process.platform === "darwin") {
5087
- const ffi = tryBuildDarwinFfi();
5088
- if (ffi) return ffi;
5089
- return (pid) => {
5090
- const ppid = readProcessTable2().get(pid)?.ppid;
5091
- return ppid !== void 0 && ppid > 0 ? ppid : null;
5092
- };
5128
+ get(key, keepScalar) {
5129
+ const idx = asItemIndex(key);
5130
+ if (typeof idx !== "number")
5131
+ return void 0;
5132
+ const it = this.items[idx];
5133
+ return !keepScalar && isScalar(it) ? it.value : it;
5093
5134
  }
5094
- return () => null;
5095
- }
5096
- function buildPgid() {
5097
- if (process.platform === "linux") {
5098
- return (pid) => {
5099
- try {
5100
- const raw = (0, import_fs2.readFileSync)(`/proc/${pid}/stat`, "utf8");
5101
- const end = raw.lastIndexOf(")");
5102
- if (end < 0) return null;
5103
- const rest = raw.slice(end + 1).trim().split(/\s+/);
5104
- const pgid = Number(rest[2]);
5105
- return Number.isFinite(pgid) && pgid > 0 ? pgid : null;
5106
- } catch {
5107
- return null;
5108
- }
5109
- };
5135
+ /**
5136
+ * Checks if the collection includes a value with the key `key`.
5137
+ *
5138
+ * `key` must contain a representation of an integer for this to succeed.
5139
+ * It may be wrapped in a `Scalar`.
5140
+ */
5141
+ has(key) {
5142
+ const idx = asItemIndex(key);
5143
+ return typeof idx === "number" && idx < this.items.length;
5110
5144
  }
5111
- if (process.platform === "darwin") {
5112
- const ffi = tryBuildDarwinPgidFfi();
5113
- if (ffi) return ffi;
5114
- return (pid) => {
5115
- const pgid = readProcessTable2().get(pid)?.pgid;
5116
- return pgid !== void 0 && pgid > 0 ? pgid : null;
5117
- };
5145
+ /**
5146
+ * Sets a value in this collection. For `!!set`, `value` needs to be a
5147
+ * boolean to add/remove the item from the set.
5148
+ *
5149
+ * If `key` does not contain a representation of an integer, this will throw.
5150
+ * It may be wrapped in a `Scalar`.
5151
+ */
5152
+ set(key, value) {
5153
+ const idx = asItemIndex(key);
5154
+ if (typeof idx !== "number")
5155
+ throw new Error(`Expected a valid index, not ${key}.`);
5156
+ const prev = this.items[idx];
5157
+ if (isScalar(prev) && isScalarValue(value))
5158
+ prev.value = value;
5159
+ else
5160
+ this.items[idx] = value;
5118
5161
  }
5119
- return () => null;
5120
- }
5121
- var PROCESS_TABLE_TTL_MS = 2e3;
5122
- var processTable = { readAt: 0, rows: /* @__PURE__ */ new Map() };
5123
- function readProcessTable2() {
5124
- const now = Date.now();
5125
- if (processTable.readAt && now - processTable.readAt < PROCESS_TABLE_TTL_MS) {
5126
- return processTable.rows;
5162
+ toJSON(_, ctx) {
5163
+ const seq2 = [];
5164
+ if (ctx?.onCreate)
5165
+ ctx.onCreate(seq2);
5166
+ let i = 0;
5167
+ for (const item of this.items)
5168
+ seq2.push(toJS(item, String(i++), ctx));
5169
+ return seq2;
5127
5170
  }
5128
- const rows = /* @__PURE__ */ new Map();
5129
- try {
5130
- const out = (0, import_child_process.execFileSync)("ps", ["-eo", "pid=,ppid=,pgid=,comm="], {
5131
- encoding: "utf8",
5132
- timeout: 5e3,
5133
- maxBuffer: 8 * 1024 * 1024,
5134
- stdio: ["ignore", "pipe", "ignore"]
5171
+ toString(ctx, onComment, onChompKeep) {
5172
+ if (!ctx)
5173
+ return JSON.stringify(this);
5174
+ return stringifyCollection(this, ctx, {
5175
+ blockItemPrefix: "- ",
5176
+ flowChars: { start: "[", end: "]" },
5177
+ itemIndent: (ctx.indent || "") + " ",
5178
+ onChompKeep,
5179
+ onComment
5135
5180
  });
5136
- for (const line of out.split("\n")) {
5137
- const parsed = line.trim().match(/^(\d+)\s+(\d+)\s+(\d+)\s+(.*)$/);
5138
- if (!parsed) continue;
5139
- rows.set(Number(parsed[1]), {
5140
- ppid: Number(parsed[2]),
5141
- pgid: Number(parsed[3]),
5142
- comm: (parsed[4].split("/").at(-1) ?? "").slice(0, PBI_COMM_LEN)
5143
- });
5181
+ }
5182
+ static from(schema4, obj, ctx) {
5183
+ const { replacer } = ctx;
5184
+ const seq2 = new this(schema4);
5185
+ if (obj && Symbol.iterator in Object(obj)) {
5186
+ let i = 0;
5187
+ for (let it of obj) {
5188
+ if (typeof replacer === "function") {
5189
+ const key = obj instanceof Set ? it : String(i++);
5190
+ it = replacer.call(obj, key, it);
5191
+ }
5192
+ seq2.items.push(createNode(it, void 0, ctx));
5193
+ }
5144
5194
  }
5145
- } catch {
5195
+ return seq2;
5196
+ }
5197
+ };
5198
+ function asItemIndex(key) {
5199
+ let idx = isScalar(key) ? key.value : key;
5200
+ if (idx && typeof idx === "string")
5201
+ idx = Number(idx);
5202
+ return typeof idx === "number" && Number.isInteger(idx) && idx >= 0 ? idx : null;
5203
+ }
5204
+
5205
+ // ../../node_modules/yaml/browser/dist/schema/common/seq.js
5206
+ var seq = {
5207
+ collection: "seq",
5208
+ default: true,
5209
+ nodeClass: YAMLSeq,
5210
+ tag: "tag:yaml.org,2002:seq",
5211
+ resolve(seq2, onError) {
5212
+ if (!isSeq(seq2))
5213
+ onError("Expected a sequence for this tag");
5214
+ return seq2;
5215
+ },
5216
+ createNode: (schema4, obj, ctx) => YAMLSeq.from(schema4, obj, ctx)
5217
+ };
5218
+
5219
+ // ../../node_modules/yaml/browser/dist/schema/json/schema.js
5220
+ function intIdentify(value) {
5221
+ return typeof value === "bigint" || Number.isInteger(value);
5222
+ }
5223
+ var stringifyJSON = ({ value }) => JSON.stringify(value);
5224
+ var jsonScalars = [
5225
+ {
5226
+ identify: (value) => typeof value === "string",
5227
+ default: true,
5228
+ tag: "tag:yaml.org,2002:str",
5229
+ resolve: (str) => str,
5230
+ stringify: stringifyJSON
5231
+ },
5232
+ {
5233
+ identify: (value) => value == null,
5234
+ createNode: () => new Scalar(null),
5235
+ default: true,
5236
+ tag: "tag:yaml.org,2002:null",
5237
+ test: /^null$/,
5238
+ resolve: () => null,
5239
+ stringify: stringifyJSON
5240
+ },
5241
+ {
5242
+ identify: (value) => typeof value === "boolean",
5243
+ default: true,
5244
+ tag: "tag:yaml.org,2002:bool",
5245
+ test: /^true$|^false$/,
5246
+ resolve: (str) => str === "true",
5247
+ stringify: stringifyJSON
5248
+ },
5249
+ {
5250
+ identify: intIdentify,
5251
+ default: true,
5252
+ tag: "tag:yaml.org,2002:int",
5253
+ test: /^-?(?:0|[1-9][0-9]*)$/,
5254
+ resolve: (str, _onError, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str, 10),
5255
+ stringify: ({ value }) => intIdentify(value) ? value.toString() : JSON.stringify(value)
5256
+ },
5257
+ {
5258
+ identify: (value) => typeof value === "number",
5259
+ default: true,
5260
+ tag: "tag:yaml.org,2002:float",
5261
+ test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
5262
+ resolve: (str) => parseFloat(str),
5263
+ stringify: stringifyJSON
5146
5264
  }
5147
- processTable = { readAt: now, rows };
5148
- return rows;
5149
- }
5150
- function buildLinux() {
5151
- return (pid) => {
5152
- try {
5153
- const raw = (0, import_fs2.readFileSync)(`/proc/${pid}/stat`, "utf8");
5154
- const end = raw.lastIndexOf(")");
5155
- if (end < 0) return null;
5156
- const rest = raw.slice(end + 1).trim().split(/\s+/);
5157
- const ppid = Number(rest[1]);
5158
- return Number.isFinite(ppid) && ppid > 0 ? ppid : null;
5159
- } catch {
5160
- return null;
5265
+ ];
5266
+ var jsonError = {
5267
+ default: true,
5268
+ tag: "",
5269
+ test: /^/,
5270
+ resolve(str, onError) {
5271
+ onError(`Unresolved plain scalar ${JSON.stringify(str)}`);
5272
+ return str;
5273
+ }
5274
+ };
5275
+ var schema = [map, seq].concat(jsonScalars, jsonError);
5276
+
5277
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js
5278
+ function createPairs(schema4, iterable, ctx) {
5279
+ const { replacer } = ctx;
5280
+ const pairs2 = new YAMLSeq(schema4);
5281
+ pairs2.tag = "tag:yaml.org,2002:pairs";
5282
+ let i = 0;
5283
+ if (iterable && Symbol.iterator in Object(iterable))
5284
+ for (let it of iterable) {
5285
+ if (typeof replacer === "function")
5286
+ it = replacer.call(iterable, String(i++), it);
5287
+ let key, value;
5288
+ if (Array.isArray(it)) {
5289
+ if (it.length === 2) {
5290
+ key = it[0];
5291
+ value = it[1];
5292
+ } else
5293
+ throw new TypeError(`Expected [key, value] tuple: ${it}`);
5294
+ } else if (it && it instanceof Object) {
5295
+ const keys = Object.keys(it);
5296
+ if (keys.length === 1) {
5297
+ key = keys[0];
5298
+ value = it[key];
5299
+ } else {
5300
+ throw new TypeError(`Expected tuple with one key, not ${keys.length} keys`);
5301
+ }
5302
+ } else {
5303
+ key = it;
5304
+ }
5305
+ pairs2.items.push(createPair(key, value, ctx));
5161
5306
  }
5162
- };
5307
+ return pairs2;
5163
5308
  }
5164
- var PROC_PIDTBSDINFO = 3;
5165
- var PROC_BSDINFO_SIZE = 216;
5166
- var PBI_PPID_OFFSET = 16;
5167
- var PBI_COMM_OFFSET = 48;
5168
- var PBI_COMM_LEN = 16;
5169
- function tryBuildDarwinFfi() {
5170
- if (!process.versions?.bun) return null;
5171
- try {
5172
- const r = (0, import_module.createRequire)(__sootsim_import_meta_url);
5173
- const { dlopen, FFIType } = r("bun:ffi");
5174
- const lib = dlopen("/usr/lib/libproc.dylib", {
5175
- proc_pidinfo: {
5176
- args: [FFIType.i32, FFIType.i32, FFIType.u64, FFIType.ptr, FFIType.i32],
5177
- returns: FFIType.i32
5178
- }
5179
- });
5180
- const buf = Buffer.alloc(PROC_BSDINFO_SIZE);
5181
- return (pid) => {
5182
- const ret = Number(
5183
- lib.symbols.proc_pidinfo(pid, PROC_PIDTBSDINFO, 0n, buf, PROC_BSDINFO_SIZE)
5184
- );
5185
- if (ret <= 0) return null;
5186
- const ppid = buf.readUInt32LE(PBI_PPID_OFFSET);
5187
- return ppid > 0 ? ppid : null;
5188
- };
5189
- } catch {
5190
- return null;
5309
+
5310
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js
5311
+ var YAMLOMap = class _YAMLOMap extends YAMLSeq {
5312
+ constructor() {
5313
+ super();
5314
+ this.add = YAMLMap.prototype.add.bind(this);
5315
+ this.delete = YAMLMap.prototype.delete.bind(this);
5316
+ this.get = YAMLMap.prototype.get.bind(this);
5317
+ this.has = YAMLMap.prototype.has.bind(this);
5318
+ this.set = YAMLMap.prototype.set.bind(this);
5319
+ this.tag = _YAMLOMap.tag;
5191
5320
  }
5192
- }
5193
- function tryBuildDarwinCommFfi() {
5194
- if (!process.versions?.bun) return null;
5195
- try {
5196
- const r = (0, import_module.createRequire)(__sootsim_import_meta_url);
5197
- const { dlopen, FFIType } = r("bun:ffi");
5198
- const lib = dlopen("/usr/lib/libproc.dylib", {
5199
- proc_pidinfo: {
5200
- args: [FFIType.i32, FFIType.i32, FFIType.u64, FFIType.ptr, FFIType.i32],
5201
- returns: FFIType.i32
5321
+ /**
5322
+ * If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
5323
+ * but TypeScript won't allow widening the signature of a child method.
5324
+ */
5325
+ toJSON(_, ctx) {
5326
+ if (!ctx)
5327
+ return super.toJSON(_);
5328
+ const map2 = /* @__PURE__ */ new Map();
5329
+ if (ctx?.onCreate)
5330
+ ctx.onCreate(map2);
5331
+ for (const pair of this.items) {
5332
+ let key, value;
5333
+ if (isPair(pair)) {
5334
+ key = toJS(pair.key, "", ctx);
5335
+ value = toJS(pair.value, key, ctx);
5336
+ } else {
5337
+ key = toJS(pair, "", ctx);
5202
5338
  }
5203
- });
5204
- const buf = Buffer.alloc(PROC_BSDINFO_SIZE);
5205
- return (pid) => {
5206
- const ret = Number(
5207
- lib.symbols.proc_pidinfo(pid, PROC_PIDTBSDINFO, 0n, buf, PROC_BSDINFO_SIZE)
5208
- );
5209
- if (ret <= 0) return null;
5210
- const raw = buf.subarray(PBI_COMM_OFFSET, PBI_COMM_OFFSET + PBI_COMM_LEN);
5211
- const end = raw.indexOf(0);
5212
- const comm = raw.subarray(0, end < 0 ? raw.length : end).toString("utf8");
5213
- return comm || null;
5214
- };
5215
- } catch {
5216
- return null;
5339
+ if (map2.has(key))
5340
+ throw new Error("Ordered maps must not include duplicate keys");
5341
+ map2.set(key, value);
5342
+ }
5343
+ return map2;
5217
5344
  }
5218
- }
5219
- var PBI_PGID_OFFSET = 100;
5220
- function tryBuildDarwinPgidFfi() {
5221
- if (!process.versions?.bun) return null;
5222
- try {
5223
- const r = (0, import_module.createRequire)(__sootsim_import_meta_url);
5224
- const { dlopen, FFIType } = r("bun:ffi");
5225
- const lib = dlopen("/usr/lib/libproc.dylib", {
5226
- proc_pidinfo: {
5227
- args: [FFIType.i32, FFIType.i32, FFIType.u64, FFIType.ptr, FFIType.i32],
5228
- returns: FFIType.i32
5229
- }
5230
- });
5231
- const buf = Buffer.alloc(PROC_BSDINFO_SIZE);
5232
- return (pid) => {
5233
- const ret = Number(
5234
- lib.symbols.proc_pidinfo(pid, PROC_PIDTBSDINFO, 0n, buf, PROC_BSDINFO_SIZE)
5235
- );
5236
- if (ret <= 0) return null;
5237
- const pgid = buf.readUInt32LE(PBI_PGID_OFFSET);
5238
- return pgid > 0 ? pgid : null;
5239
- };
5240
- } catch {
5241
- return null;
5345
+ static from(schema4, iterable, ctx) {
5346
+ const pairs2 = createPairs(schema4, iterable, ctx);
5347
+ const omap2 = new this();
5348
+ omap2.items = pairs2.items;
5349
+ return omap2;
5242
5350
  }
5243
- }
5351
+ };
5352
+ YAMLOMap.tag = "tag:yaml.org,2002:omap";
5244
5353
 
5245
- // cli/current-sim.ts
5246
- var CURRENT_SIM_VERSION = 2;
5247
- var CURRENT_SIM_PATH_ENV = "PEACH_CLI_CURRENT_SIM_PATH";
5248
- var IDENTITY_ENV_VARS = [
5249
- "PEACH_CLI_IDENTITY",
5250
- // explicit override — fastest path, skips all pid lookups
5251
- "CLAUDE_CODE_SESSION_ID",
5252
- // claude code, if ever set
5253
- "CODEX_THREAD_ID",
5254
- // codex / openai agent thread, stable across tool invocations
5255
- // a Team Machine session, per agent run. its other runners set no session
5256
- // variable of their own, and the terminal variables below are inherited from
5257
- // whatever shell started the daemon, so every such agent would share one key.
5258
- "TM_SESSION",
5259
- "TERM_SESSION_ID",
5260
- // macOS Terminal.app + iTerm2
5261
- "ITERM_SESSION_ID",
5262
- // iTerm2 (older variant)
5263
- "TMUX_PANE",
5264
- // tmux — stable per pane
5265
- "STY",
5266
- // GNU screen session
5267
- "KITTY_WINDOW_ID",
5268
- // kitty
5269
- "WEZTERM_PANE",
5270
- // wezterm
5271
- "ALACRITTY_WINDOW_ID",
5272
- // alacritty
5273
- "WINDOWID",
5274
- // X11 terminals
5275
- "VSCODE_INJECTION"
5276
- // vscode integrated terminal
5277
- ];
5278
- var IMMORTAL_HOST_COMM_RE = /^(?:tmux|screen)|^tm$/i;
5279
- var INIT_COMM_RE = /^(?:init|systemd|launchd|tini|docker-init|dumb-init|catatonit|s6-svscan|runsvdir)$/i;
5280
- function findTopAncestor(start, maxDepth = 20) {
5281
- let prev = start;
5282
- let pid = getParentPid(start);
5283
- if (!pid || pid <= 1) {
5284
- const comm = getProcessComm(start);
5285
- if (!comm || start < 1 || IMMORTAL_HOST_COMM_RE.test(comm)) return null;
5286
- return start > 1 || !INIT_COMM_RE.test(comm) ? start : null;
5354
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/set.js
5355
+ var YAMLSet = class _YAMLSet extends YAMLMap {
5356
+ constructor(schema4) {
5357
+ super(schema4);
5358
+ this.tag = _YAMLSet.tag;
5287
5359
  }
5288
- for (let i = 0; i < maxDepth; i++) {
5289
- const comm = getProcessComm(pid);
5290
- if (comm && IMMORTAL_HOST_COMM_RE.test(comm)) return prev;
5291
- const parent = getParentPid(pid);
5292
- if (!parent || parent <= 1) {
5293
- return comm ? pid : prev;
5294
- }
5295
- prev = pid;
5296
- pid = parent;
5360
+ add(key) {
5361
+ let pair;
5362
+ if (isPair(key))
5363
+ pair = key;
5364
+ else if (key && typeof key === "object" && "key" in key && "value" in key && key.value === null)
5365
+ pair = new Pair(key.key, null);
5366
+ else
5367
+ pair = new Pair(key, null);
5368
+ const prev = findPair(this.items, pair.key);
5369
+ if (!prev)
5370
+ this.items.push(pair);
5297
5371
  }
5298
- return pid;
5299
- }
5300
- function getCliIdentity() {
5301
- for (const name2 of IDENTITY_ENV_VARS) {
5302
- const value = process.env[name2];
5303
- if (value && value.trim()) {
5304
- return { key: `${name2}:${value.trim()}`, source: name2, stable: true };
5372
+ /**
5373
+ * If `keepPair` is `true`, returns the Pair matching `key`.
5374
+ * Otherwise, returns the value of that Pair's key.
5375
+ */
5376
+ get(key, keepPair) {
5377
+ const pair = findPair(this.items, key);
5378
+ return !keepPair && isPair(pair) ? isScalar(pair.key) ? pair.key.value : pair.key : pair;
5379
+ }
5380
+ set(key, value) {
5381
+ if (typeof value !== "boolean")
5382
+ throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);
5383
+ const prev = findPair(this.items, key);
5384
+ if (prev && !value) {
5385
+ this.items.splice(this.items.indexOf(prev), 1);
5386
+ } else if (!prev && value) {
5387
+ this.items.push(new Pair(key));
5305
5388
  }
5306
5389
  }
5307
- const topPid = findTopAncestor(process.ppid);
5308
- if (topPid) {
5309
- return { key: `gppid-${topPid}`, source: "grand-ppid", stable: true };
5390
+ toJSON(_, ctx) {
5391
+ return super.toJSON(_, ctx, Set);
5310
5392
  }
5311
- return { key: `pid-${process.ppid}`, source: "ppid", stable: false };
5312
- }
5313
- function getCliIdentityKey() {
5314
- return getCliIdentity().key;
5315
- }
5316
- function getStableOwnerPid() {
5317
- return findTopAncestor(process.ppid);
5318
- }
5319
- function getOwnerProcessGroupId(owner = getStableOwnerPid()) {
5320
- if (!owner || owner <= 1) return null;
5321
- const pgid = getProcessPgid(owner);
5322
- return pgid !== null && pgid > 1 ? pgid : null;
5323
- }
5324
- function getCurrentSimPath() {
5325
- const envPath = process.env[CURRENT_SIM_PATH_ENV];
5326
- if (envPath) {
5327
- return (0, import_path2.resolve)(envPath);
5393
+ toString(ctx, onComment, onChompKeep) {
5394
+ if (!ctx)
5395
+ return JSON.stringify(this);
5396
+ if (this.hasAllNullValues(true))
5397
+ return super.toString(Object.assign({}, ctx, { allNullValues: true }), onComment, onChompKeep);
5398
+ else
5399
+ throw new Error("Set items must all have null values");
5328
5400
  }
5329
- const key = getCliIdentityKey();
5330
- return (0, import_path2.join)((0, import_os.tmpdir)(), `peach-current-sim-${key}.json`);
5331
- }
5332
- function legacyCloudCredentialDirectory(filepath) {
5333
- return (0, import_path2.join)((0, import_path2.dirname)(filepath), `${(0, import_path2.basename)(filepath)}.credentials`);
5334
- }
5335
- function readCurrentTarget() {
5336
- const filepath = getCurrentSimPath();
5337
- (0, import_fs3.rmSync)(legacyCloudCredentialDirectory(filepath), { recursive: true, force: true });
5338
- if (!(0, import_fs3.existsSync)(filepath)) return null;
5339
- try {
5340
- const parsed = JSON.parse((0, import_fs3.readFileSync)(filepath, "utf8"));
5341
- if (parsed === null || typeof parsed !== "object") {
5342
- (0, import_fs3.rmSync)(filepath, { force: true });
5343
- return null;
5344
- }
5345
- if (Reflect.get(parsed, "pendingOpen") === true) return null;
5346
- const version = Reflect.get(parsed, "version");
5347
- const plane = Reflect.get(parsed, "plane");
5348
- const simId = Reflect.get(parsed, "simId");
5349
- const updatedAt = Reflect.get(parsed, "updatedAt");
5350
- const rawPort = Reflect.get(parsed, "bridgePort");
5351
- const bridgePort = typeof rawPort === "number" && Number.isInteger(rawPort) && rawPort > 0 ? rawPort : void 0;
5352
- if (version !== 1 && version !== CURRENT_SIM_VERSION || version === CURRENT_SIM_VERSION && plane !== "local" || typeof simId !== "string" || !simId.trim() || typeof updatedAt !== "string") {
5353
- (0, import_fs3.rmSync)(filepath, { force: true });
5354
- return null;
5355
- }
5356
- const target = {
5357
- version: CURRENT_SIM_VERSION,
5358
- plane: "local",
5359
- simId: simId.trim(),
5360
- ...bridgePort === void 0 ? {} : { bridgePort },
5361
- updatedAt
5362
- };
5363
- if (version === 1) writeSecureJsonAtomic(filepath, target, { durable: false });
5364
- return target;
5365
- } catch {
5366
- (0, import_fs3.rmSync)(filepath, { force: true });
5367
- return null;
5401
+ static from(schema4, iterable, ctx) {
5402
+ const { replacer } = ctx;
5403
+ const set2 = new this(schema4);
5404
+ if (iterable && Symbol.iterator in Object(iterable))
5405
+ for (let value of iterable) {
5406
+ if (typeof replacer === "function")
5407
+ value = replacer.call(iterable, value, value);
5408
+ set2.items.push(createPair(value, null, ctx));
5409
+ }
5410
+ return set2;
5368
5411
  }
5412
+ };
5413
+ YAMLSet.tag = "tag:yaml.org,2002:set";
5414
+
5415
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js
5416
+ function parseSexagesimal(str, asBigInt) {
5417
+ const sign = str[0];
5418
+ const parts = sign === "-" || sign === "+" ? str.substring(1) : str;
5419
+ const num = (n) => asBigInt ? BigInt(n) : Number(n);
5420
+ const res = parts.replace(/_/g, "").split(":").reduce((res2, p) => res2 * num(60) + num(p), num(0));
5421
+ return sign === "-" ? num(-1) * res : res;
5369
5422
  }
5370
- function readCurrentSimId() {
5371
- return readCurrentTarget()?.simId ?? null;
5372
- }
5373
- function writeCurrentSim(simId, bridgePort) {
5374
- const normalized = simId.trim();
5375
- if (!normalized) return;
5376
- writeSecureJsonAtomic(
5377
- getCurrentSimPath(),
5378
- {
5379
- version: CURRENT_SIM_VERSION,
5380
- plane: "local",
5381
- simId: normalized,
5382
- ...bridgePort === void 0 ? {} : { bridgePort },
5383
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
5384
- },
5385
- { durable: false }
5386
- );
5387
- }
5388
- function saveCurrentSimId(simId, bridgePort) {
5389
- writeCurrentSim(simId, bridgePort);
5390
- }
5391
- function getAgentIdPath() {
5392
- return `${getCurrentSimPath()}.agent-id`;
5423
+ var timestamp = {
5424
+ identify: (value) => value instanceof Date,
5425
+ default: true,
5426
+ tag: "tag:yaml.org,2002:timestamp",
5427
+ // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
5428
+ // may be omitted altogether, resulting in a date format. In such a case, the time part is
5429
+ // assumed to be 00:00:00Z (start of day, UTC).
5430
+ test: RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),
5431
+ resolve(str) {
5432
+ const match = str.match(timestamp.test);
5433
+ if (!match)
5434
+ throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");
5435
+ const [, year, month, day, hour, minute, second] = match.map(Number);
5436
+ const millisec = match[7] ? Number((match[7] + "00").substr(1, 3)) : 0;
5437
+ let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec);
5438
+ const tz = match[8];
5439
+ if (tz && tz !== "Z") {
5440
+ let d = parseSexagesimal(tz, false);
5441
+ if (Math.abs(d) < 30)
5442
+ d *= 60;
5443
+ date -= 6e4 * d;
5444
+ }
5445
+ return new Date(date);
5446
+ },
5447
+ stringify: ({ value }) => value?.toISOString().replace(/(T00:00:00)?\.000Z$/, "") ?? ""
5448
+ };
5449
+
5450
+ // ../../node_modules/yaml/browser/dist/parse/cst-visit.js
5451
+ var BREAK2 = Symbol("break visit");
5452
+ var SKIP2 = Symbol("skip children");
5453
+ var REMOVE2 = Symbol("remove item");
5454
+ function visit2(cst, visitor) {
5455
+ if ("type" in cst && cst.type === "document")
5456
+ cst = { start: cst.start, value: cst.value };
5457
+ _visit(Object.freeze([]), cst, visitor);
5393
5458
  }
5394
- function readAgentId() {
5395
- const filepath = getAgentIdPath();
5396
- if (!(0, import_fs3.existsSync)(filepath)) return void 0;
5397
- try {
5398
- const parsed = JSON.parse((0, import_fs3.readFileSync)(filepath, "utf8"));
5399
- const agentId = parsed !== null && typeof parsed === "object" ? Reflect.get(parsed, "agentId") : void 0;
5400
- return typeof agentId === "string" && agentId.trim() ? agentId.trim() : void 0;
5401
- } catch {
5402
- (0, import_fs3.rmSync)(filepath, { force: true });
5403
- return void 0;
5459
+ visit2.BREAK = BREAK2;
5460
+ visit2.SKIP = SKIP2;
5461
+ visit2.REMOVE = REMOVE2;
5462
+ visit2.itemAtPath = (cst, path7) => {
5463
+ let item = cst;
5464
+ for (const [field, index] of path7) {
5465
+ const tok = item?.[field];
5466
+ if (tok && "items" in tok) {
5467
+ item = tok.items[index];
5468
+ } else
5469
+ return void 0;
5404
5470
  }
5405
- }
5406
- var PendingOpenError = class extends Error {
5471
+ return item;
5407
5472
  };
5408
- function assertNoPendingOpen() {
5409
- if (!isOpenPending()) return;
5410
- throw new PendingOpenError(
5411
- "the last `peach open` did not pin a sim, so this command would land on whichever tab is connected. run `peach open` again, `peach use <sim>`, or pass --sim <id>"
5412
- );
5413
- }
5414
- function isOpenPending() {
5415
- const filepath = getCurrentSimPath();
5416
- if (!(0, import_fs3.existsSync)(filepath)) return false;
5417
- try {
5418
- const parsed = JSON.parse((0, import_fs3.readFileSync)(filepath, "utf8"));
5419
- return parsed !== null && typeof parsed === "object" && Reflect.get(parsed, "pendingOpen") === true;
5420
- } catch {
5421
- return false;
5473
+ visit2.parentCollection = (cst, path7) => {
5474
+ const parent = visit2.itemAtPath(cst, path7.slice(0, -1));
5475
+ const field = path7[path7.length - 1][0];
5476
+ const coll = parent?.[field];
5477
+ if (coll && "items" in coll)
5478
+ return coll;
5479
+ throw new Error("Parent collection not found");
5480
+ };
5481
+ function _visit(path7, item, visitor) {
5482
+ let ctrl = visitor(item, path7);
5483
+ if (typeof ctrl === "symbol")
5484
+ return ctrl;
5485
+ for (const field of ["key", "value"]) {
5486
+ const token = item[field];
5487
+ if (token && "items" in token) {
5488
+ for (let i = 0; i < token.items.length; ++i) {
5489
+ const ci = _visit(Object.freeze(path7.concat([[field, i]])), token.items[i], visitor);
5490
+ if (typeof ci === "number")
5491
+ i = ci - 1;
5492
+ else if (ci === BREAK2)
5493
+ return BREAK2;
5494
+ else if (ci === REMOVE2) {
5495
+ token.items.splice(i, 1);
5496
+ i -= 1;
5497
+ }
5498
+ }
5499
+ if (typeof ctrl === "function" && field === "key")
5500
+ ctrl = ctrl(item, path7);
5501
+ }
5422
5502
  }
5503
+ return typeof ctrl === "function" ? ctrl(item, path7) : ctrl;
5423
5504
  }
5424
5505
 
5506
+ // ../../node_modules/yaml/browser/dist/parse/lexer.js
5507
+ var hexDigits = new Set("0123456789ABCDEFabcdef");
5508
+ var tagChars = new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()");
5509
+ var flowIndicatorChars = new Set(",[]{}");
5510
+ var invalidAnchorChars = new Set(" ,[]{}\n\r ");
5511
+
5512
+ // cli/commands/detect.ts
5513
+ var PODFILE_NEW_ARCH_MARK = "PEACH_RCT_NEW_ARCH ";
5514
+ var PODFILE_NEW_ARCH_RUBY = `
5515
+ require 'json'
5516
+ payload = JSON.parse($stdin.read)
5517
+ properties = payload['properties']
5518
+ properties = {} unless properties.is_a?(Hash)
5519
+ podfile_properties = properties
5520
+ ENV.delete('RCT_NEW_ARCH_ENABLED')
5521
+ scope = binding
5522
+ Array(payload['statements']).each do |statement|
5523
+ before = ENV['RCT_NEW_ARCH_ENABLED']
5524
+ scope.eval(statement)
5525
+ after = ENV['RCT_NEW_ARCH_ENABLED']
5526
+ if after == before
5527
+ puts '${PODFILE_NEW_ARCH_MARK}skip'
5528
+ elsif after == '0' || after == '1'
5529
+ puts "${PODFILE_NEW_ARCH_MARK}#{after}"
5530
+ else
5531
+ warn "RCT_NEW_ARCH_ENABLED assigned #{after.inspect}"
5532
+ exit 2
5533
+ end
5534
+ end
5535
+ `;
5536
+
5537
+ // cli/cloud-client.ts
5538
+ var DEFAULT_RNX_CLOUD_ORIGIN = rnxPublicBrand.origin;
5539
+
5425
5540
  // cli/pause-aware-timeout.ts
5426
5541
  var import_node_child_process2 = require("node:child_process");
5427
5542
  var import_node_fs5 = require("node:fs");
@@ -5717,12 +5832,14 @@ function createBridge(wsPort, opts = {}) {
5717
5832
  plane: "local",
5718
5833
  async send(cmd, callOpts) {
5719
5834
  const effectiveTimeoutMs = callOpts?.timeoutMs ?? (opts.explicitTimeout ? commandTimeoutMs : callOpts?.defaultTimeoutMs) ?? commandTimeoutMs;
5835
+ const agent = commandAgent(cmd);
5836
+ const sent = agent ? { ...cmd, agent } : cmd;
5720
5837
  const sendOnce = async (defaultSimId, cmdOverride) => {
5721
5838
  await ready;
5722
5839
  if (terminalError) throw terminalError;
5723
5840
  const id = nextId++;
5724
5841
  return new Promise((resolve3, reject) => {
5725
- const payload = { ...cmdOverride ?? cmd, id };
5842
+ const payload = { ...cmdOverride ?? sent, id };
5726
5843
  if (payload.simId === void 0 && defaultSimId) {
5727
5844
  payload.simId = defaultSimId;
5728
5845
  }
@@ -10092,14 +10209,14 @@ var device = {
10092
10209
  );
10093
10210
  const session = await source.page.context().newCDPSession(source.page);
10094
10211
  try {
10095
- const { clip, originX, originY } = getCliRuntime().capture_browser_composite.resolveBrowserCompositeCdpClip(
10212
+ const { clip: clip2, originX, originY } = getCliRuntime().capture_browser_composite.resolveBrowserCompositeCdpClip(
10096
10213
  request,
10097
10214
  await session.send("Page.getLayoutMetrics")
10098
10215
  );
10099
10216
  const result = await session.send("Page.captureScreenshot", {
10100
10217
  format: "png",
10101
10218
  fromSurface: true,
10102
- clip
10219
+ clip: clip2
10103
10220
  });
10104
10221
  return { dataUrl: "data:image/png;base64," + result.data, originX, originY };
10105
10222
  } finally {