pair-mode 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/codex.js CHANGED
@@ -94,13 +94,13 @@ var require_identity = __commonJS({
94
94
  var require_visit = __commonJS({
95
95
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/visit.js"(exports) {
96
96
  "use strict";
97
- var identity = require_identity();
97
+ var identity2 = require_identity();
98
98
  var BREAK = Symbol("break visit");
99
99
  var SKIP = Symbol("skip children");
100
100
  var REMOVE = Symbol("remove node");
101
101
  function visit(node, visitor) {
102
102
  const visitor_ = initVisitor(visitor);
103
- if (identity.isDocument(node)) {
103
+ if (identity2.isDocument(node)) {
104
104
  const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
105
105
  if (cd === REMOVE)
106
106
  node.contents = null;
@@ -112,12 +112,12 @@ var require_visit = __commonJS({
112
112
  visit.REMOVE = REMOVE;
113
113
  function visit_(key, node, visitor, path) {
114
114
  const ctrl = callVisitor(key, node, visitor, path);
115
- if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
115
+ if (identity2.isNode(ctrl) || identity2.isPair(ctrl)) {
116
116
  replaceNode(key, path, ctrl);
117
117
  return visit_(key, ctrl, visitor, path);
118
118
  }
119
119
  if (typeof ctrl !== "symbol") {
120
- if (identity.isCollection(node)) {
120
+ if (identity2.isCollection(node)) {
121
121
  path = Object.freeze(path.concat(node));
122
122
  for (let i = 0; i < node.items.length; ++i) {
123
123
  const ci = visit_(i, node.items[i], visitor, path);
@@ -130,7 +130,7 @@ var require_visit = __commonJS({
130
130
  i -= 1;
131
131
  }
132
132
  }
133
- } else if (identity.isPair(node)) {
133
+ } else if (identity2.isPair(node)) {
134
134
  path = Object.freeze(path.concat(node));
135
135
  const ck = visit_("key", node.key, visitor, path);
136
136
  if (ck === BREAK)
@@ -148,7 +148,7 @@ var require_visit = __commonJS({
148
148
  }
149
149
  async function visitAsync(node, visitor) {
150
150
  const visitor_ = initVisitor(visitor);
151
- if (identity.isDocument(node)) {
151
+ if (identity2.isDocument(node)) {
152
152
  const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));
153
153
  if (cd === REMOVE)
154
154
  node.contents = null;
@@ -160,12 +160,12 @@ var require_visit = __commonJS({
160
160
  visitAsync.REMOVE = REMOVE;
161
161
  async function visitAsync_(key, node, visitor, path) {
162
162
  const ctrl = await callVisitor(key, node, visitor, path);
163
- if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
163
+ if (identity2.isNode(ctrl) || identity2.isPair(ctrl)) {
164
164
  replaceNode(key, path, ctrl);
165
165
  return visitAsync_(key, ctrl, visitor, path);
166
166
  }
167
167
  if (typeof ctrl !== "symbol") {
168
- if (identity.isCollection(node)) {
168
+ if (identity2.isCollection(node)) {
169
169
  path = Object.freeze(path.concat(node));
170
170
  for (let i = 0; i < node.items.length; ++i) {
171
171
  const ci = await visitAsync_(i, node.items[i], visitor, path);
@@ -178,7 +178,7 @@ var require_visit = __commonJS({
178
178
  i -= 1;
179
179
  }
180
180
  }
181
- } else if (identity.isPair(node)) {
181
+ } else if (identity2.isPair(node)) {
182
182
  path = Object.freeze(path.concat(node));
183
183
  const ck = await visitAsync_("key", node.key, visitor, path);
184
184
  if (ck === BREAK)
@@ -215,31 +215,31 @@ var require_visit = __commonJS({
215
215
  function callVisitor(key, node, visitor, path) {
216
216
  if (typeof visitor === "function")
217
217
  return visitor(key, node, path);
218
- if (identity.isMap(node))
218
+ if (identity2.isMap(node))
219
219
  return visitor.Map?.(key, node, path);
220
- if (identity.isSeq(node))
220
+ if (identity2.isSeq(node))
221
221
  return visitor.Seq?.(key, node, path);
222
- if (identity.isPair(node))
222
+ if (identity2.isPair(node))
223
223
  return visitor.Pair?.(key, node, path);
224
- if (identity.isScalar(node))
224
+ if (identity2.isScalar(node))
225
225
  return visitor.Scalar?.(key, node, path);
226
- if (identity.isAlias(node))
226
+ if (identity2.isAlias(node))
227
227
  return visitor.Alias?.(key, node, path);
228
228
  return void 0;
229
229
  }
230
230
  function replaceNode(key, path, node) {
231
231
  const parent = path[path.length - 1];
232
- if (identity.isCollection(parent)) {
232
+ if (identity2.isCollection(parent)) {
233
233
  parent.items[key] = node;
234
- } else if (identity.isPair(parent)) {
234
+ } else if (identity2.isPair(parent)) {
235
235
  if (key === "key")
236
236
  parent.key = node;
237
237
  else
238
238
  parent.value = node;
239
- } else if (identity.isDocument(parent)) {
239
+ } else if (identity2.isDocument(parent)) {
240
240
  parent.contents = node;
241
241
  } else {
242
- const pt = identity.isAlias(parent) ? "alias" : "scalar";
242
+ const pt = identity2.isAlias(parent) ? "alias" : "scalar";
243
243
  throw new Error(`Cannot replace node with ${pt} parent`);
244
244
  }
245
245
  }
@@ -252,7 +252,7 @@ var require_visit = __commonJS({
252
252
  var require_directives = __commonJS({
253
253
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/doc/directives.js"(exports) {
254
254
  "use strict";
255
- var identity = require_identity();
255
+ var identity2 = require_identity();
256
256
  var visit = require_visit();
257
257
  var escapeChars = {
258
258
  "!": "%21",
@@ -395,10 +395,10 @@ var require_directives = __commonJS({
395
395
  const lines = this.yaml.explicit ? [`%YAML ${this.yaml.version || "1.2"}`] : [];
396
396
  const tagEntries = Object.entries(this.tags);
397
397
  let tagNames;
398
- if (doc && tagEntries.length > 0 && identity.isNode(doc.contents)) {
398
+ if (doc && tagEntries.length > 0 && identity2.isNode(doc.contents)) {
399
399
  const tags = {};
400
400
  visit.visit(doc.contents, (_key, node) => {
401
- if (identity.isNode(node) && node.tag)
401
+ if (identity2.isNode(node) && node.tag)
402
402
  tags[node.tag] = true;
403
403
  });
404
404
  tagNames = Object.keys(tags);
@@ -423,7 +423,7 @@ var require_directives = __commonJS({
423
423
  var require_anchors = __commonJS({
424
424
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/doc/anchors.js"(exports) {
425
425
  "use strict";
426
- var identity = require_identity();
426
+ var identity2 = require_identity();
427
427
  var visit = require_visit();
428
428
  function anchorIsValid(anchor2) {
429
429
  if (/[\x00-\x19\s,[\]{}]/.test(anchor2)) {
@@ -470,7 +470,7 @@ var require_anchors = __commonJS({
470
470
  setAnchors: () => {
471
471
  for (const source of aliasObjects) {
472
472
  const ref = sourceObjects.get(source);
473
- if (typeof ref === "object" && ref.anchor && (identity.isScalar(ref.node) || identity.isCollection(ref.node))) {
473
+ if (typeof ref === "object" && ref.anchor && (identity2.isScalar(ref.node) || identity2.isCollection(ref.node))) {
474
474
  ref.node.anchor = ref.anchor;
475
475
  } else {
476
476
  const error = new Error("Failed to resolve repeated object (this should not happen)");
@@ -543,12 +543,12 @@ var require_applyReviver = __commonJS({
543
543
  var require_toJS = __commonJS({
544
544
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/nodes/toJS.js"(exports) {
545
545
  "use strict";
546
- var identity = require_identity();
546
+ var identity2 = require_identity();
547
547
  function toJS(value, arg, ctx) {
548
548
  if (Array.isArray(value))
549
549
  return value.map((v, i) => toJS(v, String(i), ctx));
550
550
  if (value && typeof value.toJSON === "function") {
551
- if (!ctx || !identity.hasAnchor(value))
551
+ if (!ctx || !identity2.hasAnchor(value))
552
552
  return value.toJSON(arg, ctx);
553
553
  const data = { aliasCount: 0, count: 1, res: void 0 };
554
554
  ctx.anchors.set(value, data);
@@ -574,11 +574,11 @@ var require_Node = __commonJS({
574
574
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/nodes/Node.js"(exports) {
575
575
  "use strict";
576
576
  var applyReviver = require_applyReviver();
577
- var identity = require_identity();
577
+ var identity2 = require_identity();
578
578
  var toJS = require_toJS();
579
579
  var NodeBase = class {
580
580
  constructor(type) {
581
- Object.defineProperty(this, identity.NODE_TYPE, { value: type });
581
+ Object.defineProperty(this, identity2.NODE_TYPE, { value: type });
582
582
  }
583
583
  /** Create a copy of this node. */
584
584
  clone() {
@@ -589,7 +589,7 @@ var require_Node = __commonJS({
589
589
  }
590
590
  /** A plain JavaScript representation of this node. */
591
591
  toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
592
- if (!identity.isDocument(doc))
592
+ if (!identity2.isDocument(doc))
593
593
  throw new TypeError("A document argument is required");
594
594
  const ctx = {
595
595
  anchors: /* @__PURE__ */ new Map(),
@@ -616,12 +616,12 @@ var require_Alias = __commonJS({
616
616
  "use strict";
617
617
  var anchors = require_anchors();
618
618
  var visit = require_visit();
619
- var identity = require_identity();
619
+ var identity2 = require_identity();
620
620
  var Node = require_Node();
621
621
  var toJS = require_toJS();
622
622
  var Alias = class extends Node.NodeBase {
623
623
  constructor(source) {
624
- super(identity.ALIAS);
624
+ super(identity2.ALIAS);
625
625
  this.source = source;
626
626
  Object.defineProperty(this, "tag", {
627
627
  set() {
@@ -643,7 +643,7 @@ var require_Alias = __commonJS({
643
643
  nodes = [];
644
644
  visit.visit(doc, {
645
645
  Node: (_key, node) => {
646
- if (identity.isAlias(node) || identity.hasAnchor(node))
646
+ if (identity2.isAlias(node) || identity2.hasAnchor(node))
647
647
  nodes.push(node);
648
648
  }
649
649
  });
@@ -703,11 +703,11 @@ var require_Alias = __commonJS({
703
703
  }
704
704
  };
705
705
  function getAliasCount(doc, node, anchors2) {
706
- if (identity.isAlias(node)) {
706
+ if (identity2.isAlias(node)) {
707
707
  const source = node.resolve(doc);
708
708
  const anchor2 = anchors2 && source && anchors2.get(source);
709
709
  return anchor2 ? anchor2.count * anchor2.aliasCount : 0;
710
- } else if (identity.isCollection(node)) {
710
+ } else if (identity2.isCollection(node)) {
711
711
  let count = 0;
712
712
  for (const item of node.items) {
713
713
  const c = getAliasCount(doc, item, anchors2);
@@ -715,7 +715,7 @@ var require_Alias = __commonJS({
715
715
  count = c;
716
716
  }
717
717
  return count;
718
- } else if (identity.isPair(node)) {
718
+ } else if (identity2.isPair(node)) {
719
719
  const kc = getAliasCount(doc, node.key, anchors2);
720
720
  const vc = getAliasCount(doc, node.value, anchors2);
721
721
  return Math.max(kc, vc);
@@ -730,13 +730,13 @@ var require_Alias = __commonJS({
730
730
  var require_Scalar = __commonJS({
731
731
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/nodes/Scalar.js"(exports) {
732
732
  "use strict";
733
- var identity = require_identity();
733
+ var identity2 = require_identity();
734
734
  var Node = require_Node();
735
735
  var toJS = require_toJS();
736
736
  var isScalarValue = (value) => !value || typeof value !== "function" && typeof value !== "object";
737
737
  var Scalar = class extends Node.NodeBase {
738
738
  constructor(value) {
739
- super(identity.SCALAR);
739
+ super(identity2.SCALAR);
740
740
  this.value = value;
741
741
  }
742
742
  toJSON(arg, ctx) {
@@ -761,7 +761,7 @@ var require_createNode = __commonJS({
761
761
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/doc/createNode.js"(exports) {
762
762
  "use strict";
763
763
  var Alias = require_Alias();
764
- var identity = require_identity();
764
+ var identity2 = require_identity();
765
765
  var Scalar = require_Scalar();
766
766
  var defaultTagPrefix = "tag:yaml.org,2002:";
767
767
  function findTagObject(value, tagName, tags) {
@@ -775,12 +775,12 @@ var require_createNode = __commonJS({
775
775
  return tags.find((t) => t.identify?.(value) && !t.format);
776
776
  }
777
777
  function createNode(value, tagName, ctx) {
778
- if (identity.isDocument(value))
778
+ if (identity2.isDocument(value))
779
779
  value = value.contents;
780
- if (identity.isNode(value))
780
+ if (identity2.isNode(value))
781
781
  return value;
782
- if (identity.isPair(value)) {
783
- const map = ctx.schema[identity.MAP].createNode?.(ctx.schema, null, ctx);
782
+ if (identity2.isPair(value)) {
783
+ const map = ctx.schema[identity2.MAP].createNode?.(ctx.schema, null, ctx);
784
784
  map.items.push(value);
785
785
  return map;
786
786
  }
@@ -812,7 +812,7 @@ var require_createNode = __commonJS({
812
812
  ref.node = node2;
813
813
  return node2;
814
814
  }
815
- tagObj = value instanceof Map ? schema[identity.MAP] : Symbol.iterator in Object(value) ? schema[identity.SEQ] : schema[identity.MAP];
815
+ tagObj = value instanceof Map ? schema[identity2.MAP] : Symbol.iterator in Object(value) ? schema[identity2.SEQ] : schema[identity2.MAP];
816
816
  }
817
817
  if (onTagObj) {
818
818
  onTagObj(tagObj);
@@ -836,7 +836,7 @@ var require_Collection = __commonJS({
836
836
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/nodes/Collection.js"(exports) {
837
837
  "use strict";
838
838
  var createNode = require_createNode();
839
- var identity = require_identity();
839
+ var identity2 = require_identity();
840
840
  var Node = require_Node();
841
841
  function collectionFromPath(schema, path, value) {
842
842
  let v = value;
@@ -880,7 +880,7 @@ var require_Collection = __commonJS({
880
880
  const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
881
881
  if (schema)
882
882
  copy.schema = schema;
883
- copy.items = copy.items.map((it) => identity.isNode(it) || identity.isPair(it) ? it.clone(schema) : it);
883
+ copy.items = copy.items.map((it) => identity2.isNode(it) || identity2.isPair(it) ? it.clone(schema) : it);
884
884
  if (this.range)
885
885
  copy.range = this.range.slice();
886
886
  return copy;
@@ -896,7 +896,7 @@ var require_Collection = __commonJS({
896
896
  else {
897
897
  const [key, ...rest] = path;
898
898
  const node = this.get(key, true);
899
- if (identity.isCollection(node))
899
+ if (identity2.isCollection(node))
900
900
  node.addIn(rest, value);
901
901
  else if (node === void 0 && this.schema)
902
902
  this.set(key, collectionFromPath(this.schema, rest, value));
@@ -913,7 +913,7 @@ var require_Collection = __commonJS({
913
913
  if (rest.length === 0)
914
914
  return this.delete(key);
915
915
  const node = this.get(key, true);
916
- if (identity.isCollection(node))
916
+ if (identity2.isCollection(node))
917
917
  return node.deleteIn(rest);
918
918
  else
919
919
  throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
@@ -927,16 +927,16 @@ var require_Collection = __commonJS({
927
927
  const [key, ...rest] = path;
928
928
  const node = this.get(key, true);
929
929
  if (rest.length === 0)
930
- return !keepScalar && identity.isScalar(node) ? node.value : node;
930
+ return !keepScalar && identity2.isScalar(node) ? node.value : node;
931
931
  else
932
- return identity.isCollection(node) ? node.getIn(rest, keepScalar) : void 0;
932
+ return identity2.isCollection(node) ? node.getIn(rest, keepScalar) : void 0;
933
933
  }
934
934
  hasAllNullValues(allowScalar) {
935
935
  return this.items.every((node) => {
936
- if (!identity.isPair(node))
936
+ if (!identity2.isPair(node))
937
937
  return false;
938
938
  const n = node.value;
939
- return n == null || allowScalar && identity.isScalar(n) && n.value == null && !n.commentBefore && !n.comment && !n.tag;
939
+ return n == null || allowScalar && identity2.isScalar(n) && n.value == null && !n.commentBefore && !n.comment && !n.tag;
940
940
  });
941
941
  }
942
942
  /**
@@ -947,7 +947,7 @@ var require_Collection = __commonJS({
947
947
  if (rest.length === 0)
948
948
  return this.has(key);
949
949
  const node = this.get(key, true);
950
- return identity.isCollection(node) ? node.hasIn(rest) : false;
950
+ return identity2.isCollection(node) ? node.hasIn(rest) : false;
951
951
  }
952
952
  /**
953
953
  * Sets a value in this collection. For `!!set`, `value` needs to be a
@@ -959,7 +959,7 @@ var require_Collection = __commonJS({
959
959
  this.set(key, value);
960
960
  } else {
961
961
  const node = this.get(key, true);
962
- if (identity.isCollection(node))
962
+ if (identity2.isCollection(node))
963
963
  node.setIn(rest, value);
964
964
  else if (node === void 0 && this.schema)
965
965
  this.set(key, collectionFromPath(this.schema, rest, value));
@@ -1415,7 +1415,7 @@ var require_stringify = __commonJS({
1415
1415
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/stringify/stringify.js"(exports) {
1416
1416
  "use strict";
1417
1417
  var anchors = require_anchors();
1418
- var identity = require_identity();
1418
+ var identity2 = require_identity();
1419
1419
  var stringifyComment = require_stringifyComment();
1420
1420
  var stringifyString = require_stringifyString();
1421
1421
  function createStringifyContext(doc, options) {
@@ -1468,7 +1468,7 @@ var require_stringify = __commonJS({
1468
1468
  }
1469
1469
  let tagObj = void 0;
1470
1470
  let obj;
1471
- if (identity.isScalar(item)) {
1471
+ if (identity2.isScalar(item)) {
1472
1472
  obj = item.value;
1473
1473
  let match = tags.filter((t) => t.identify?.(obj));
1474
1474
  if (match.length > 1) {
@@ -1491,7 +1491,7 @@ var require_stringify = __commonJS({
1491
1491
  if (!doc.directives)
1492
1492
  return "";
1493
1493
  const props = [];
1494
- const anchor2 = (identity.isScalar(node) || identity.isCollection(node)) && node.anchor;
1494
+ const anchor2 = (identity2.isScalar(node) || identity2.isCollection(node)) && node.anchor;
1495
1495
  if (anchor2 && anchors.anchorIsValid(anchor2)) {
1496
1496
  anchors$1.add(anchor2);
1497
1497
  props.push(`&${anchor2}`);
@@ -1502,9 +1502,9 @@ var require_stringify = __commonJS({
1502
1502
  return props.join(" ");
1503
1503
  }
1504
1504
  function stringify2(item, ctx, onComment, onChompKeep) {
1505
- if (identity.isPair(item))
1505
+ if (identity2.isPair(item))
1506
1506
  return item.toString(ctx, onComment, onChompKeep);
1507
- if (identity.isAlias(item)) {
1507
+ if (identity2.isAlias(item)) {
1508
1508
  if (ctx.doc.directives)
1509
1509
  return item.toString(ctx);
1510
1510
  if (ctx.resolvedAliases?.has(item)) {
@@ -1518,15 +1518,15 @@ var require_stringify = __commonJS({
1518
1518
  }
1519
1519
  }
1520
1520
  let tagObj = void 0;
1521
- const node = identity.isNode(item) ? item : ctx.doc.createNode(item, { onTagObj: (o) => tagObj = o });
1521
+ const node = identity2.isNode(item) ? item : ctx.doc.createNode(item, { onTagObj: (o) => tagObj = o });
1522
1522
  tagObj ?? (tagObj = getTagObject(ctx.doc.schema.tags, node));
1523
1523
  const props = stringifyProps(node, tagObj, ctx);
1524
1524
  if (props.length > 0)
1525
1525
  ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
1526
- const str = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : identity.isScalar(node) ? stringifyString.stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep);
1526
+ const str = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : identity2.isScalar(node) ? stringifyString.stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep);
1527
1527
  if (!props)
1528
1528
  return str;
1529
- return identity.isScalar(node) || str[0] === "{" || str[0] === "[" ? `${props} ${str}` : `${props}
1529
+ return identity2.isScalar(node) || str[0] === "{" || str[0] === "[" ? `${props} ${str}` : `${props}
1530
1530
  ${ctx.indent}${str}`;
1531
1531
  }
1532
1532
  exports.createStringifyContext = createStringifyContext;
@@ -1538,23 +1538,23 @@ ${ctx.indent}${str}`;
1538
1538
  var require_stringifyPair = __commonJS({
1539
1539
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/stringify/stringifyPair.js"(exports) {
1540
1540
  "use strict";
1541
- var identity = require_identity();
1541
+ var identity2 = require_identity();
1542
1542
  var Scalar = require_Scalar();
1543
1543
  var stringify2 = require_stringify();
1544
1544
  var stringifyComment = require_stringifyComment();
1545
1545
  function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
1546
1546
  const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
1547
- let keyComment = identity.isNode(key) && key.comment || null;
1547
+ let keyComment = identity2.isNode(key) && key.comment || null;
1548
1548
  if (simpleKeys) {
1549
1549
  if (keyComment) {
1550
1550
  throw new Error("With simple keys, key nodes cannot have comments");
1551
1551
  }
1552
- if (identity.isCollection(key) || !identity.isNode(key) && typeof key === "object") {
1552
+ if (identity2.isCollection(key) || !identity2.isNode(key) && typeof key === "object") {
1553
1553
  const msg = "With simple keys, collection cannot be used as a key value";
1554
1554
  throw new Error(msg);
1555
1555
  }
1556
1556
  }
1557
- let explicitKey = !simpleKeys && (!key || keyComment && value == null && !ctx.inFlow || identity.isCollection(key) || (identity.isScalar(key) ? key.type === Scalar.Scalar.BLOCK_FOLDED || key.type === Scalar.Scalar.BLOCK_LITERAL : typeof key === "object"));
1557
+ let explicitKey = !simpleKeys && (!key || keyComment && value == null && !ctx.inFlow || identity2.isCollection(key) || (identity2.isScalar(key) ? key.type === Scalar.Scalar.BLOCK_FOLDED || key.type === Scalar.Scalar.BLOCK_LITERAL : typeof key === "object"));
1558
1558
  ctx = Object.assign({}, ctx, {
1559
1559
  allNullValues: false,
1560
1560
  implicitKey: !explicitKey && (simpleKeys || !allNullValues),
@@ -1595,7 +1595,7 @@ ${indent}:`;
1595
1595
  str += stringifyComment.lineComment(str, ctx.indent, commentString(keyComment));
1596
1596
  }
1597
1597
  let vsb, vcb, valueComment;
1598
- if (identity.isNode(value)) {
1598
+ if (identity2.isNode(value)) {
1599
1599
  vsb = !!value.spaceBefore;
1600
1600
  vcb = value.commentBefore;
1601
1601
  valueComment = value.comment;
@@ -1607,10 +1607,10 @@ ${indent}:`;
1607
1607
  value = doc.createNode(value);
1608
1608
  }
1609
1609
  ctx.implicitKey = false;
1610
- if (!explicitKey && !keyComment && identity.isScalar(value))
1610
+ if (!explicitKey && !keyComment && identity2.isScalar(value))
1611
1611
  ctx.indentAtStart = str.length + 1;
1612
1612
  chompKeep = false;
1613
- if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && identity.isSeq(value) && !value.flow && !value.tag && !value.anchor) {
1613
+ if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && identity2.isSeq(value) && !value.flow && !value.tag && !value.anchor) {
1614
1614
  ctx.indent = ctx.indent.substring(2);
1615
1615
  }
1616
1616
  let valueCommentDone = false;
@@ -1630,7 +1630,7 @@ ${stringifyComment.indentComment(cs, ctx.indent)}`;
1630
1630
  ws += `
1631
1631
  ${ctx.indent}`;
1632
1632
  }
1633
- } else if (!explicitKey && identity.isCollection(value)) {
1633
+ } else if (!explicitKey && identity2.isCollection(value)) {
1634
1634
  const vs0 = valueStr[0];
1635
1635
  const nl0 = valueStr.indexOf("\n");
1636
1636
  const hasNewline = nl0 !== -1;
@@ -1693,7 +1693,7 @@ var require_log = __commonJS({
1693
1693
  var require_merge = __commonJS({
1694
1694
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/schema/yaml-1.1/merge.js"(exports) {
1695
1695
  "use strict";
1696
- var identity = require_identity();
1696
+ var identity2 = require_identity();
1697
1697
  var Scalar = require_Scalar();
1698
1698
  var MERGE_KEY = "<<";
1699
1699
  var merge = {
@@ -1706,10 +1706,10 @@ var require_merge = __commonJS({
1706
1706
  }),
1707
1707
  stringify: () => MERGE_KEY
1708
1708
  };
1709
- var isMergeKey = (ctx, key) => (merge.identify(key) || identity.isScalar(key) && (!key.type || key.type === Scalar.Scalar.PLAIN) && merge.identify(key.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default);
1709
+ var isMergeKey = (ctx, key) => (merge.identify(key) || identity2.isScalar(key) && (!key.type || key.type === Scalar.Scalar.PLAIN) && merge.identify(key.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default);
1710
1710
  function addMergeToJSMap(ctx, map, value) {
1711
1711
  const source = resolveAliasValue(ctx, value);
1712
- if (identity.isSeq(source))
1712
+ if (identity2.isSeq(source))
1713
1713
  for (const it of source.items)
1714
1714
  mergeValue(ctx, map, it);
1715
1715
  else if (Array.isArray(source))
@@ -1720,7 +1720,7 @@ var require_merge = __commonJS({
1720
1720
  }
1721
1721
  function mergeValue(ctx, map, value) {
1722
1722
  const source = resolveAliasValue(ctx, value);
1723
- if (!identity.isMap(source))
1723
+ if (!identity2.isMap(source))
1724
1724
  throw new Error("Merge sources must be maps or map aliases");
1725
1725
  const srcMap = source.toJSON(null, ctx, Map);
1726
1726
  for (const [key, value2] of srcMap) {
@@ -1741,7 +1741,7 @@ var require_merge = __commonJS({
1741
1741
  return map;
1742
1742
  }
1743
1743
  function resolveAliasValue(ctx, value) {
1744
- return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
1744
+ return ctx && identity2.isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
1745
1745
  }
1746
1746
  exports.addMergeToJSMap = addMergeToJSMap;
1747
1747
  exports.isMergeKey = isMergeKey;
@@ -1756,10 +1756,10 @@ var require_addPairToJSMap = __commonJS({
1756
1756
  var log = require_log();
1757
1757
  var merge = require_merge();
1758
1758
  var stringify2 = require_stringify();
1759
- var identity = require_identity();
1759
+ var identity2 = require_identity();
1760
1760
  var toJS = require_toJS();
1761
1761
  function addPairToJSMap(ctx, map, { key, value }) {
1762
- if (identity.isNode(key) && key.addToJSMap)
1762
+ if (identity2.isNode(key) && key.addToJSMap)
1763
1763
  key.addToJSMap(ctx, map, value);
1764
1764
  else if (merge.isMergeKey(ctx, key))
1765
1765
  merge.addMergeToJSMap(ctx, map, value);
@@ -1790,7 +1790,7 @@ var require_addPairToJSMap = __commonJS({
1790
1790
  return "";
1791
1791
  if (typeof jsKey !== "object")
1792
1792
  return String(jsKey);
1793
- if (identity.isNode(key) && ctx?.doc) {
1793
+ if (identity2.isNode(key) && ctx?.doc) {
1794
1794
  const strCtx = stringify2.createStringifyContext(ctx.doc, {});
1795
1795
  strCtx.anchors = /* @__PURE__ */ new Set();
1796
1796
  for (const node of ctx.anchors.keys())
@@ -1820,7 +1820,7 @@ var require_Pair = __commonJS({
1820
1820
  var createNode = require_createNode();
1821
1821
  var stringifyPair = require_stringifyPair();
1822
1822
  var addPairToJSMap = require_addPairToJSMap();
1823
- var identity = require_identity();
1823
+ var identity2 = require_identity();
1824
1824
  function createPair(key, value, ctx) {
1825
1825
  const k = createNode.createNode(key, void 0, ctx);
1826
1826
  const v = createNode.createNode(value, void 0, ctx);
@@ -1828,15 +1828,15 @@ var require_Pair = __commonJS({
1828
1828
  }
1829
1829
  var Pair = class _Pair {
1830
1830
  constructor(key, value = null) {
1831
- Object.defineProperty(this, identity.NODE_TYPE, { value: identity.PAIR });
1831
+ Object.defineProperty(this, identity2.NODE_TYPE, { value: identity2.PAIR });
1832
1832
  this.key = key;
1833
1833
  this.value = value;
1834
1834
  }
1835
1835
  clone(schema) {
1836
1836
  let { key, value } = this;
1837
- if (identity.isNode(key))
1837
+ if (identity2.isNode(key))
1838
1838
  key = key.clone(schema);
1839
- if (identity.isNode(value))
1839
+ if (identity2.isNode(value))
1840
1840
  value = value.clone(schema);
1841
1841
  return new _Pair(key, value);
1842
1842
  }
@@ -1857,7 +1857,7 @@ var require_Pair = __commonJS({
1857
1857
  var require_stringifyCollection = __commonJS({
1858
1858
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/stringify/stringifyCollection.js"(exports) {
1859
1859
  "use strict";
1860
- var identity = require_identity();
1860
+ var identity2 = require_identity();
1861
1861
  var stringify2 = require_stringify();
1862
1862
  var stringifyComment = require_stringifyComment();
1863
1863
  function stringifyCollection(collection, ctx, options) {
@@ -1873,14 +1873,14 @@ var require_stringifyCollection = __commonJS({
1873
1873
  for (let i = 0; i < items.length; ++i) {
1874
1874
  const item = items[i];
1875
1875
  let comment2 = null;
1876
- if (identity.isNode(item)) {
1876
+ if (identity2.isNode(item)) {
1877
1877
  if (!chompKeep && item.spaceBefore)
1878
1878
  lines.push("");
1879
1879
  addCommentBefore(ctx, lines, item.commentBefore, chompKeep);
1880
1880
  if (item.comment)
1881
1881
  comment2 = item.comment;
1882
- } else if (identity.isPair(item)) {
1883
- const ik = identity.isNode(item.key) ? item.key : null;
1882
+ } else if (identity2.isPair(item)) {
1883
+ const ik = identity2.isNode(item.key) ? item.key : null;
1884
1884
  if (ik) {
1885
1885
  if (!chompKeep && ik.spaceBefore)
1886
1886
  lines.push("");
@@ -1928,14 +1928,14 @@ ${indent}${line}` : "\n";
1928
1928
  for (let i = 0; i < items.length; ++i) {
1929
1929
  const item = items[i];
1930
1930
  let comment = null;
1931
- if (identity.isNode(item)) {
1931
+ if (identity2.isNode(item)) {
1932
1932
  if (item.spaceBefore)
1933
1933
  lines.push("");
1934
1934
  addCommentBefore(ctx, lines, item.commentBefore, false);
1935
1935
  if (item.comment)
1936
1936
  comment = item.comment;
1937
- } else if (identity.isPair(item)) {
1938
- const ik = identity.isNode(item.key) ? item.key : null;
1937
+ } else if (identity2.isPair(item)) {
1938
+ const ik = identity2.isNode(item.key) ? item.key : null;
1939
1939
  if (ik) {
1940
1940
  if (ik.spaceBefore)
1941
1941
  lines.push("");
@@ -1943,7 +1943,7 @@ ${indent}${line}` : "\n";
1943
1943
  if (ik.comment)
1944
1944
  reqNewline = true;
1945
1945
  }
1946
- const iv = identity.isNode(item.value) ? item.value : null;
1946
+ const iv = identity2.isNode(item.value) ? item.value : null;
1947
1947
  if (iv) {
1948
1948
  if (iv.comment)
1949
1949
  comment = iv.comment;
@@ -2011,16 +2011,16 @@ var require_YAMLMap = __commonJS({
2011
2011
  var stringifyCollection = require_stringifyCollection();
2012
2012
  var addPairToJSMap = require_addPairToJSMap();
2013
2013
  var Collection = require_Collection();
2014
- var identity = require_identity();
2014
+ var identity2 = require_identity();
2015
2015
  var Pair = require_Pair();
2016
2016
  var Scalar = require_Scalar();
2017
2017
  function findPair(items, key) {
2018
- const k = identity.isScalar(key) ? key.value : key;
2018
+ const k = identity2.isScalar(key) ? key.value : key;
2019
2019
  for (const it of items) {
2020
- if (identity.isPair(it)) {
2020
+ if (identity2.isPair(it)) {
2021
2021
  if (it.key === key || it.key === k)
2022
2022
  return it;
2023
- if (identity.isScalar(it.key) && it.key.value === k)
2023
+ if (identity2.isScalar(it.key) && it.key.value === k)
2024
2024
  return it;
2025
2025
  }
2026
2026
  }
@@ -2031,7 +2031,7 @@ var require_YAMLMap = __commonJS({
2031
2031
  return "tag:yaml.org,2002:map";
2032
2032
  }
2033
2033
  constructor(schema) {
2034
- super(identity.MAP, schema);
2034
+ super(identity2.MAP, schema);
2035
2035
  this.items = [];
2036
2036
  }
2037
2037
  /**
@@ -2069,7 +2069,7 @@ var require_YAMLMap = __commonJS({
2069
2069
  */
2070
2070
  add(pair, overwrite) {
2071
2071
  let _pair;
2072
- if (identity.isPair(pair))
2072
+ if (identity2.isPair(pair))
2073
2073
  _pair = pair;
2074
2074
  else if (!pair || typeof pair !== "object" || !("key" in pair)) {
2075
2075
  _pair = new Pair.Pair(pair, pair?.value);
@@ -2080,7 +2080,7 @@ var require_YAMLMap = __commonJS({
2080
2080
  if (prev) {
2081
2081
  if (!overwrite)
2082
2082
  throw new Error(`Key ${_pair.key} already set`);
2083
- if (identity.isScalar(prev.value) && Scalar.isScalarValue(_pair.value))
2083
+ if (identity2.isScalar(prev.value) && Scalar.isScalarValue(_pair.value))
2084
2084
  prev.value.value = _pair.value;
2085
2085
  else
2086
2086
  prev.value = _pair.value;
@@ -2104,7 +2104,7 @@ var require_YAMLMap = __commonJS({
2104
2104
  get(key, keepScalar) {
2105
2105
  const it = findPair(this.items, key);
2106
2106
  const node = it?.value;
2107
- return (!keepScalar && identity.isScalar(node) ? node.value : node) ?? void 0;
2107
+ return (!keepScalar && identity2.isScalar(node) ? node.value : node) ?? void 0;
2108
2108
  }
2109
2109
  has(key) {
2110
2110
  return !!findPair(this.items, key);
@@ -2129,7 +2129,7 @@ var require_YAMLMap = __commonJS({
2129
2129
  if (!ctx)
2130
2130
  return JSON.stringify(this);
2131
2131
  for (const item of this.items) {
2132
- if (!identity.isPair(item))
2132
+ if (!identity2.isPair(item))
2133
2133
  throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
2134
2134
  }
2135
2135
  if (!ctx.allNullValues && this.hasAllNullValues(false))
@@ -2152,7 +2152,7 @@ var require_YAMLMap = __commonJS({
2152
2152
  var require_map = __commonJS({
2153
2153
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/schema/common/map.js"(exports) {
2154
2154
  "use strict";
2155
- var identity = require_identity();
2155
+ var identity2 = require_identity();
2156
2156
  var YAMLMap = require_YAMLMap();
2157
2157
  var map = {
2158
2158
  collection: "map",
@@ -2160,7 +2160,7 @@ var require_map = __commonJS({
2160
2160
  nodeClass: YAMLMap.YAMLMap,
2161
2161
  tag: "tag:yaml.org,2002:map",
2162
2162
  resolve(map2, onError) {
2163
- if (!identity.isMap(map2))
2163
+ if (!identity2.isMap(map2))
2164
2164
  onError("Expected a mapping for this tag");
2165
2165
  return map2;
2166
2166
  },
@@ -2177,7 +2177,7 @@ var require_YAMLSeq = __commonJS({
2177
2177
  var createNode = require_createNode();
2178
2178
  var stringifyCollection = require_stringifyCollection();
2179
2179
  var Collection = require_Collection();
2180
- var identity = require_identity();
2180
+ var identity2 = require_identity();
2181
2181
  var Scalar = require_Scalar();
2182
2182
  var toJS = require_toJS();
2183
2183
  var YAMLSeq = class extends Collection.Collection {
@@ -2185,7 +2185,7 @@ var require_YAMLSeq = __commonJS({
2185
2185
  return "tag:yaml.org,2002:seq";
2186
2186
  }
2187
2187
  constructor(schema) {
2188
- super(identity.SEQ, schema);
2188
+ super(identity2.SEQ, schema);
2189
2189
  this.items = [];
2190
2190
  }
2191
2191
  add(value) {
@@ -2211,7 +2211,7 @@ var require_YAMLSeq = __commonJS({
2211
2211
  if (typeof idx !== "number")
2212
2212
  return void 0;
2213
2213
  const it = this.items[idx];
2214
- return !keepScalar && identity.isScalar(it) ? it.value : it;
2214
+ return !keepScalar && identity2.isScalar(it) ? it.value : it;
2215
2215
  }
2216
2216
  /**
2217
2217
  * Checks if the collection includes a value with the key `key`.
@@ -2235,7 +2235,7 @@ var require_YAMLSeq = __commonJS({
2235
2235
  if (typeof idx !== "number")
2236
2236
  throw new Error(`Expected a valid index, not ${key}.`);
2237
2237
  const prev = this.items[idx];
2238
- if (identity.isScalar(prev) && Scalar.isScalarValue(value))
2238
+ if (identity2.isScalar(prev) && Scalar.isScalarValue(value))
2239
2239
  prev.value = value;
2240
2240
  else
2241
2241
  this.items[idx] = value;
@@ -2277,7 +2277,7 @@ var require_YAMLSeq = __commonJS({
2277
2277
  }
2278
2278
  };
2279
2279
  function asItemIndex(key) {
2280
- let idx = identity.isScalar(key) ? key.value : key;
2280
+ let idx = identity2.isScalar(key) ? key.value : key;
2281
2281
  if (idx && typeof idx === "string")
2282
2282
  idx = Number(idx);
2283
2283
  return typeof idx === "number" && Number.isInteger(idx) && idx >= 0 ? idx : null;
@@ -2290,7 +2290,7 @@ var require_YAMLSeq = __commonJS({
2290
2290
  var require_seq = __commonJS({
2291
2291
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/schema/common/seq.js"(exports) {
2292
2292
  "use strict";
2293
- var identity = require_identity();
2293
+ var identity2 = require_identity();
2294
2294
  var YAMLSeq = require_YAMLSeq();
2295
2295
  var seq = {
2296
2296
  collection: "seq",
@@ -2298,7 +2298,7 @@ var require_seq = __commonJS({
2298
2298
  nodeClass: YAMLSeq.YAMLSeq,
2299
2299
  tag: "tag:yaml.org,2002:seq",
2300
2300
  resolve(seq2, onError) {
2301
- if (!identity.isSeq(seq2))
2301
+ if (!identity2.isSeq(seq2))
2302
2302
  onError("Expected a sequence for this tag");
2303
2303
  return seq2;
2304
2304
  },
@@ -2652,17 +2652,17 @@ var require_binary = __commonJS({
2652
2652
  var require_pairs = __commonJS({
2653
2653
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/schema/yaml-1.1/pairs.js"(exports) {
2654
2654
  "use strict";
2655
- var identity = require_identity();
2655
+ var identity2 = require_identity();
2656
2656
  var Pair = require_Pair();
2657
2657
  var Scalar = require_Scalar();
2658
2658
  var YAMLSeq = require_YAMLSeq();
2659
2659
  function resolvePairs(seq, onError) {
2660
- if (identity.isSeq(seq)) {
2660
+ if (identity2.isSeq(seq)) {
2661
2661
  for (let i = 0; i < seq.items.length; ++i) {
2662
2662
  let item = seq.items[i];
2663
- if (identity.isPair(item))
2663
+ if (identity2.isPair(item))
2664
2664
  continue;
2665
- else if (identity.isMap(item)) {
2665
+ else if (identity2.isMap(item)) {
2666
2666
  if (item.items.length > 1)
2667
2667
  onError("Each pair must have its own sequence indicator");
2668
2668
  const pair = item.items[0] || new Pair.Pair(new Scalar.Scalar(null));
@@ -2676,7 +2676,7 @@ ${cn.comment}` : item.comment;
2676
2676
  }
2677
2677
  item = pair;
2678
2678
  }
2679
- seq.items[i] = identity.isPair(item) ? item : new Pair.Pair(item);
2679
+ seq.items[i] = identity2.isPair(item) ? item : new Pair.Pair(item);
2680
2680
  }
2681
2681
  } else
2682
2682
  onError("Expected a sequence for this tag");
@@ -2730,7 +2730,7 @@ ${cn.comment}` : item.comment;
2730
2730
  var require_omap = __commonJS({
2731
2731
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/schema/yaml-1.1/omap.js"(exports) {
2732
2732
  "use strict";
2733
- var identity = require_identity();
2733
+ var identity2 = require_identity();
2734
2734
  var toJS = require_toJS();
2735
2735
  var YAMLMap = require_YAMLMap();
2736
2736
  var YAMLSeq = require_YAMLSeq();
@@ -2757,7 +2757,7 @@ var require_omap = __commonJS({
2757
2757
  ctx.onCreate(map);
2758
2758
  for (const pair of this.items) {
2759
2759
  let key, value;
2760
- if (identity.isPair(pair)) {
2760
+ if (identity2.isPair(pair)) {
2761
2761
  key = toJS.toJS(pair.key, "", ctx);
2762
2762
  value = toJS.toJS(pair.value, key, ctx);
2763
2763
  } else {
@@ -2787,7 +2787,7 @@ var require_omap = __commonJS({
2787
2787
  const pairs$1 = pairs.resolvePairs(seq, onError);
2788
2788
  const seenKeys = [];
2789
2789
  for (const { key } of pairs$1.items) {
2790
- if (identity.isScalar(key)) {
2790
+ if (identity2.isScalar(key)) {
2791
2791
  if (seenKeys.includes(key.value)) {
2792
2792
  onError(`Ordered maps must not include duplicate keys: ${key.value}`);
2793
2793
  } else {
@@ -2968,7 +2968,7 @@ var require_int2 = __commonJS({
2968
2968
  var require_set = __commonJS({
2969
2969
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/schema/yaml-1.1/set.js"(exports) {
2970
2970
  "use strict";
2971
- var identity = require_identity();
2971
+ var identity2 = require_identity();
2972
2972
  var Pair = require_Pair();
2973
2973
  var YAMLMap = require_YAMLMap();
2974
2974
  var YAMLSet = class _YAMLSet extends YAMLMap.YAMLMap {
@@ -2978,7 +2978,7 @@ var require_set = __commonJS({
2978
2978
  }
2979
2979
  add(key) {
2980
2980
  let pair;
2981
- if (identity.isPair(key))
2981
+ if (identity2.isPair(key))
2982
2982
  pair = key;
2983
2983
  else if (key && typeof key === "object" && "key" in key && "value" in key && key.value === null)
2984
2984
  pair = new Pair.Pair(key.key, null);
@@ -2994,7 +2994,7 @@ var require_set = __commonJS({
2994
2994
  */
2995
2995
  get(key, keepPair) {
2996
2996
  const pair = YAMLMap.findPair(this.items, key);
2997
- return !keepPair && identity.isPair(pair) ? identity.isScalar(pair.key) ? pair.key.value : pair.key : pair;
2997
+ return !keepPair && identity2.isPair(pair) ? identity2.isScalar(pair.key) ? pair.key.value : pair.key : pair;
2998
2998
  }
2999
2999
  set(key, value) {
3000
3000
  if (typeof value !== "boolean")
@@ -3038,7 +3038,7 @@ var require_set = __commonJS({
3038
3038
  tag: "tag:yaml.org,2002:set",
3039
3039
  createNode: (schema, iterable, ctx) => YAMLSet.from(schema, iterable, ctx),
3040
3040
  resolve(map, onError) {
3041
- if (identity.isMap(map)) {
3041
+ if (identity2.isMap(map)) {
3042
3042
  if (map.hasAllNullValues(true))
3043
3043
  return Object.assign(new YAMLSet(), map);
3044
3044
  else
@@ -3283,7 +3283,7 @@ var require_tags = __commonJS({
3283
3283
  var require_Schema = __commonJS({
3284
3284
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/schema/Schema.js"(exports) {
3285
3285
  "use strict";
3286
- var identity = require_identity();
3286
+ var identity2 = require_identity();
3287
3287
  var map = require_map();
3288
3288
  var seq = require_seq();
3289
3289
  var string = require_string();
@@ -3296,9 +3296,9 @@ var require_Schema = __commonJS({
3296
3296
  this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
3297
3297
  this.tags = tags.getTags(customTags, this.name, merge);
3298
3298
  this.toStringOptions = toStringDefaults ?? null;
3299
- Object.defineProperty(this, identity.MAP, { value: map.map });
3300
- Object.defineProperty(this, identity.SCALAR, { value: string.string });
3301
- Object.defineProperty(this, identity.SEQ, { value: seq.seq });
3299
+ Object.defineProperty(this, identity2.MAP, { value: map.map });
3300
+ Object.defineProperty(this, identity2.SCALAR, { value: string.string });
3301
+ Object.defineProperty(this, identity2.SEQ, { value: seq.seq });
3302
3302
  this.sortMapEntries = typeof sortMapEntries === "function" ? sortMapEntries : sortMapEntries === true ? sortMapEntriesByKey : null;
3303
3303
  }
3304
3304
  clone() {
@@ -3315,7 +3315,7 @@ var require_Schema = __commonJS({
3315
3315
  var require_stringifyDocument = __commonJS({
3316
3316
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/stringify/stringifyDocument.js"(exports) {
3317
3317
  "use strict";
3318
- var identity = require_identity();
3318
+ var identity2 = require_identity();
3319
3319
  var stringify2 = require_stringify();
3320
3320
  var stringifyComment = require_stringifyComment();
3321
3321
  function stringifyDocument(doc, options) {
@@ -3342,7 +3342,7 @@ var require_stringifyDocument = __commonJS({
3342
3342
  let chompKeep = false;
3343
3343
  let contentComment = null;
3344
3344
  if (doc.contents) {
3345
- if (identity.isNode(doc.contents)) {
3345
+ if (identity2.isNode(doc.contents)) {
3346
3346
  if (doc.contents.spaceBefore && hasDirectives)
3347
3347
  lines.push("");
3348
3348
  if (doc.contents.commentBefore) {
@@ -3397,7 +3397,7 @@ var require_Document = __commonJS({
3397
3397
  "use strict";
3398
3398
  var Alias = require_Alias();
3399
3399
  var Collection = require_Collection();
3400
- var identity = require_identity();
3400
+ var identity2 = require_identity();
3401
3401
  var Pair = require_Pair();
3402
3402
  var toJS = require_toJS();
3403
3403
  var Schema = require_Schema();
@@ -3412,7 +3412,7 @@ var require_Document = __commonJS({
3412
3412
  this.comment = null;
3413
3413
  this.errors = [];
3414
3414
  this.warnings = [];
3415
- Object.defineProperty(this, identity.NODE_TYPE, { value: identity.DOC });
3415
+ Object.defineProperty(this, identity2.NODE_TYPE, { value: identity2.DOC });
3416
3416
  let _replacer = null;
3417
3417
  if (typeof replacer === "function" || Array.isArray(replacer)) {
3418
3418
  _replacer = replacer;
@@ -3448,7 +3448,7 @@ var require_Document = __commonJS({
3448
3448
  */
3449
3449
  clone() {
3450
3450
  const copy = Object.create(_Document.prototype, {
3451
- [identity.NODE_TYPE]: { value: identity.DOC }
3451
+ [identity2.NODE_TYPE]: { value: identity2.DOC }
3452
3452
  });
3453
3453
  copy.commentBefore = this.commentBefore;
3454
3454
  copy.comment = this.comment;
@@ -3458,7 +3458,7 @@ var require_Document = __commonJS({
3458
3458
  if (this.directives)
3459
3459
  copy.directives = this.directives.clone();
3460
3460
  copy.schema = this.schema.clone();
3461
- copy.contents = identity.isNode(this.contents) ? this.contents.clone(copy.schema) : this.contents;
3461
+ copy.contents = identity2.isNode(this.contents) ? this.contents.clone(copy.schema) : this.contents;
3462
3462
  if (this.range)
3463
3463
  copy.range = this.range.slice();
3464
3464
  return copy;
@@ -3521,7 +3521,7 @@ var require_Document = __commonJS({
3521
3521
  sourceObjects
3522
3522
  };
3523
3523
  const node = createNode.createNode(value, tag, ctx);
3524
- if (flow && identity.isCollection(node))
3524
+ if (flow && identity2.isCollection(node))
3525
3525
  node.flow = true;
3526
3526
  setAnchors();
3527
3527
  return node;
@@ -3561,7 +3561,7 @@ var require_Document = __commonJS({
3561
3561
  * `true` (collections are always returned intact).
3562
3562
  */
3563
3563
  get(key, keepScalar) {
3564
- return identity.isCollection(this.contents) ? this.contents.get(key, keepScalar) : void 0;
3564
+ return identity2.isCollection(this.contents) ? this.contents.get(key, keepScalar) : void 0;
3565
3565
  }
3566
3566
  /**
3567
3567
  * Returns item at `path`, or `undefined` if not found. By default unwraps
@@ -3570,14 +3570,14 @@ var require_Document = __commonJS({
3570
3570
  */
3571
3571
  getIn(path, keepScalar) {
3572
3572
  if (Collection.isEmptyPath(path))
3573
- return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
3574
- return identity.isCollection(this.contents) ? this.contents.getIn(path, keepScalar) : void 0;
3573
+ return !keepScalar && identity2.isScalar(this.contents) ? this.contents.value : this.contents;
3574
+ return identity2.isCollection(this.contents) ? this.contents.getIn(path, keepScalar) : void 0;
3575
3575
  }
3576
3576
  /**
3577
3577
  * Checks if the document includes a value with the key `key`.
3578
3578
  */
3579
3579
  has(key) {
3580
- return identity.isCollection(this.contents) ? this.contents.has(key) : false;
3580
+ return identity2.isCollection(this.contents) ? this.contents.has(key) : false;
3581
3581
  }
3582
3582
  /**
3583
3583
  * Checks if the document includes a value at `path`.
@@ -3585,7 +3585,7 @@ var require_Document = __commonJS({
3585
3585
  hasIn(path) {
3586
3586
  if (Collection.isEmptyPath(path))
3587
3587
  return this.contents !== void 0;
3588
- return identity.isCollection(this.contents) ? this.contents.hasIn(path) : false;
3588
+ return identity2.isCollection(this.contents) ? this.contents.hasIn(path) : false;
3589
3589
  }
3590
3590
  /**
3591
3591
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -3692,7 +3692,7 @@ var require_Document = __commonJS({
3692
3692
  }
3693
3693
  };
3694
3694
  function assertCollection(contents) {
3695
- if (identity.isCollection(contents))
3695
+ if (identity2.isCollection(contents))
3696
3696
  return true;
3697
3697
  throw new Error("Expected a YAML collection as document contents");
3698
3698
  }
@@ -3963,12 +3963,12 @@ var require_util_flow_indent_check = __commonJS({
3963
3963
  var require_util_map_includes = __commonJS({
3964
3964
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/compose/util-map-includes.js"(exports) {
3965
3965
  "use strict";
3966
- var identity = require_identity();
3966
+ var identity2 = require_identity();
3967
3967
  function mapIncludes(ctx, items, search) {
3968
3968
  const { uniqueKeys } = ctx.options;
3969
3969
  if (uniqueKeys === false)
3970
3970
  return false;
3971
- const isEqual = typeof uniqueKeys === "function" ? uniqueKeys : (a, b) => a === b || identity.isScalar(a) && identity.isScalar(b) && a.value === b.value;
3971
+ const isEqual = typeof uniqueKeys === "function" ? uniqueKeys : (a, b) => a === b || identity2.isScalar(a) && identity2.isScalar(b) && a.value === b.value;
3972
3972
  return items.some((pair) => isEqual(pair.key, search));
3973
3973
  }
3974
3974
  exports.mapIncludes = mapIncludes;
@@ -4181,7 +4181,7 @@ var require_resolve_end = __commonJS({
4181
4181
  var require_resolve_flow_collection = __commonJS({
4182
4182
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/compose/resolve-flow-collection.js"(exports) {
4183
4183
  "use strict";
4184
- var identity = require_identity();
4184
+ var identity2 = require_identity();
4185
4185
  var Pair = require_Pair();
4186
4186
  var YAMLMap = require_YAMLMap();
4187
4187
  var YAMLSeq = require_YAMLSeq();
@@ -4260,7 +4260,7 @@ var require_resolve_flow_collection = __commonJS({
4260
4260
  }
4261
4261
  if (prevItemComment) {
4262
4262
  let prev = coll.items[coll.items.length - 1];
4263
- if (identity.isPair(prev))
4263
+ if (identity2.isPair(prev))
4264
4264
  prev = prev.value ?? prev.key;
4265
4265
  if (prev.comment)
4266
4266
  prev.comment += "\n" + prevItemComment;
@@ -4375,7 +4375,7 @@ var require_resolve_flow_collection = __commonJS({
4375
4375
  var require_compose_collection = __commonJS({
4376
4376
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/compose/compose-collection.js"(exports) {
4377
4377
  "use strict";
4378
- var identity = require_identity();
4378
+ var identity2 = require_identity();
4379
4379
  var Scalar = require_Scalar();
4380
4380
  var YAMLMap = require_YAMLMap();
4381
4381
  var YAMLSeq = require_YAMLSeq();
@@ -4425,7 +4425,7 @@ var require_compose_collection = __commonJS({
4425
4425
  }
4426
4426
  const coll = resolveCollection(CN, ctx, token, onError, tagName, tag);
4427
4427
  const res = tag.resolve?.(coll, (msg) => onError(tagToken, "TAG_RESOLVE_FAILED", msg), ctx.options) ?? coll;
4428
- const node = identity.isNode(res) ? res : new Scalar.Scalar(res);
4428
+ const node = identity2.isNode(res) ? res : new Scalar.Scalar(res);
4429
4429
  node.range = coll.range;
4430
4430
  node.tag = tagName;
4431
4431
  if (tag?.format)
@@ -4843,7 +4843,7 @@ var require_resolve_flow_scalar = __commonJS({
4843
4843
  var require_compose_scalar = __commonJS({
4844
4844
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/compose/compose-scalar.js"(exports) {
4845
4845
  "use strict";
4846
- var identity = require_identity();
4846
+ var identity2 = require_identity();
4847
4847
  var Scalar = require_Scalar();
4848
4848
  var resolveBlockScalar = require_resolve_block_scalar();
4849
4849
  var resolveFlowScalar = require_resolve_flow_scalar();
@@ -4852,17 +4852,17 @@ var require_compose_scalar = __commonJS({
4852
4852
  const tagName = tagToken ? ctx.directives.tagName(tagToken.source, (msg) => onError(tagToken, "TAG_RESOLVE_FAILED", msg)) : null;
4853
4853
  let tag;
4854
4854
  if (ctx.options.stringKeys && ctx.atKey) {
4855
- tag = ctx.schema[identity.SCALAR];
4855
+ tag = ctx.schema[identity2.SCALAR];
4856
4856
  } else if (tagName)
4857
4857
  tag = findScalarTagByName(ctx.schema, value, tagName, tagToken, onError);
4858
4858
  else if (token.type === "scalar")
4859
4859
  tag = findScalarTagByTest(ctx, value, token, onError);
4860
4860
  else
4861
- tag = ctx.schema[identity.SCALAR];
4861
+ tag = ctx.schema[identity2.SCALAR];
4862
4862
  let scalar;
4863
4863
  try {
4864
4864
  const res = tag.resolve(value, (msg) => onError(tagToken ?? token, "TAG_RESOLVE_FAILED", msg), ctx.options);
4865
- scalar = identity.isScalar(res) ? res : new Scalar.Scalar(res);
4865
+ scalar = identity2.isScalar(res) ? res : new Scalar.Scalar(res);
4866
4866
  } catch (error) {
4867
4867
  const msg = error instanceof Error ? error.message : String(error);
4868
4868
  onError(tagToken ?? token, "TAG_RESOLVE_FAILED", msg);
@@ -4882,7 +4882,7 @@ var require_compose_scalar = __commonJS({
4882
4882
  }
4883
4883
  function findScalarTagByName(schema, value, tagName, tagToken, onError) {
4884
4884
  if (tagName === "!")
4885
- return schema[identity.SCALAR];
4885
+ return schema[identity2.SCALAR];
4886
4886
  const matchWithTest = [];
4887
4887
  for (const tag of schema.tags) {
4888
4888
  if (!tag.collection && tag.tag === tagName) {
@@ -4901,12 +4901,12 @@ var require_compose_scalar = __commonJS({
4901
4901
  return kt;
4902
4902
  }
4903
4903
  onError(tagToken, "TAG_RESOLVE_FAILED", `Unresolved tag: ${tagName}`, tagName !== "tag:yaml.org,2002:str");
4904
- return schema[identity.SCALAR];
4904
+ return schema[identity2.SCALAR];
4905
4905
  }
4906
4906
  function findScalarTagByTest({ atKey, directives, schema }, value, token, onError) {
4907
- const tag = schema.tags.find((tag2) => (tag2.default === true || atKey && tag2.default === "key") && tag2.test?.test(value)) || schema[identity.SCALAR];
4907
+ const tag = schema.tags.find((tag2) => (tag2.default === true || atKey && tag2.default === "key") && tag2.test?.test(value)) || schema[identity2.SCALAR];
4908
4908
  if (schema.compat) {
4909
- const compat = schema.compat.find((tag2) => tag2.default && tag2.test?.test(value)) ?? schema[identity.SCALAR];
4909
+ const compat = schema.compat.find((tag2) => tag2.default && tag2.test?.test(value)) ?? schema[identity2.SCALAR];
4910
4910
  if (tag.tag !== compat.tag) {
4911
4911
  const ts = directives.tagString(tag.tag);
4912
4912
  const cs = directives.tagString(compat.tag);
@@ -4955,7 +4955,7 @@ var require_compose_node = __commonJS({
4955
4955
  "node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/compose/compose-node.js"(exports) {
4956
4956
  "use strict";
4957
4957
  var Alias = require_Alias();
4958
- var identity = require_identity();
4958
+ var identity2 = require_identity();
4959
4959
  var composeCollection = require_compose_collection();
4960
4960
  var composeScalar = require_compose_scalar();
4961
4961
  var resolveEnd = require_resolve_end();
@@ -5001,7 +5001,7 @@ var require_compose_node = __commonJS({
5001
5001
  node ?? (node = composeEmptyNode(ctx, token.offset, void 0, null, props, onError));
5002
5002
  if (anchor2 && node.anchor === "")
5003
5003
  onError(anchor2, "BAD_ALIAS", "Anchor cannot be an empty string");
5004
- if (atKey && ctx.options.stringKeys && (!identity.isScalar(node) || typeof node.value !== "string" || node.tag && node.tag !== "tag:yaml.org,2002:str")) {
5004
+ if (atKey && ctx.options.stringKeys && (!identity2.isScalar(node) || typeof node.value !== "string" || node.tag && node.tag !== "tag:yaml.org,2002:str")) {
5005
5005
  const msg = "With stringKeys, all keys must be strings";
5006
5006
  onError(tag ?? token, "NON_STRING_KEY", msg);
5007
5007
  }
@@ -5107,7 +5107,7 @@ var require_composer = __commonJS({
5107
5107
  var directives = require_directives();
5108
5108
  var Document = require_Document();
5109
5109
  var errors = require_errors();
5110
- var identity = require_identity();
5110
+ var identity2 = require_identity();
5111
5111
  var composeDoc = require_compose_doc();
5112
5112
  var resolveEnd = require_resolve_end();
5113
5113
  function getErrorPos(src) {
@@ -5169,9 +5169,9 @@ var require_composer = __commonJS({
5169
5169
  ${comment}` : comment;
5170
5170
  } else if (afterEmptyLine || doc.directives.docStart || !dc) {
5171
5171
  doc.commentBefore = comment;
5172
- } else if (identity.isCollection(dc) && !dc.flow && dc.items.length > 0) {
5172
+ } else if (identity2.isCollection(dc) && !dc.flow && dc.items.length > 0) {
5173
5173
  let it = dc.items[0];
5174
- if (identity.isPair(it))
5174
+ if (identity2.isPair(it))
5175
5175
  it = it.key;
5176
5176
  const cb = it.commentBefore;
5177
5177
  it.commentBefore = cb ? `${comment}
@@ -7219,7 +7219,7 @@ var require_public_api = __commonJS({
7219
7219
  var Document = require_Document();
7220
7220
  var errors = require_errors();
7221
7221
  var log = require_log();
7222
- var identity = require_identity();
7222
+ var identity2 = require_identity();
7223
7223
  var lineCounter = require_line_counter();
7224
7224
  var parser = require_parser();
7225
7225
  function parseOptions(options) {
@@ -7297,7 +7297,7 @@ var require_public_api = __commonJS({
7297
7297
  if (!keepUndefined)
7298
7298
  return void 0;
7299
7299
  }
7300
- if (identity.isDocument(value) && !_replacer)
7300
+ if (identity2.isDocument(value) && !_replacer)
7301
7301
  return value.toString(options);
7302
7302
  return new Document.Document(value, _replacer, options).toString(options);
7303
7303
  }
@@ -7317,7 +7317,7 @@ var require_dist = __commonJS({
7317
7317
  var Schema = require_Schema();
7318
7318
  var errors = require_errors();
7319
7319
  var Alias = require_Alias();
7320
- var identity = require_identity();
7320
+ var identity2 = require_identity();
7321
7321
  var Pair = require_Pair();
7322
7322
  var Scalar = require_Scalar();
7323
7323
  var YAMLMap = require_YAMLMap();
@@ -7335,14 +7335,14 @@ var require_dist = __commonJS({
7335
7335
  exports.YAMLParseError = errors.YAMLParseError;
7336
7336
  exports.YAMLWarning = errors.YAMLWarning;
7337
7337
  exports.Alias = Alias.Alias;
7338
- exports.isAlias = identity.isAlias;
7339
- exports.isCollection = identity.isCollection;
7340
- exports.isDocument = identity.isDocument;
7341
- exports.isMap = identity.isMap;
7342
- exports.isNode = identity.isNode;
7343
- exports.isPair = identity.isPair;
7344
- exports.isScalar = identity.isScalar;
7345
- exports.isSeq = identity.isSeq;
7338
+ exports.isAlias = identity2.isAlias;
7339
+ exports.isCollection = identity2.isCollection;
7340
+ exports.isDocument = identity2.isDocument;
7341
+ exports.isMap = identity2.isMap;
7342
+ exports.isNode = identity2.isNode;
7343
+ exports.isPair = identity2.isPair;
7344
+ exports.isScalar = identity2.isScalar;
7345
+ exports.isSeq = identity2.isSeq;
7346
7346
  exports.Pair = Pair.Pair;
7347
7347
  exports.Scalar = Scalar.Scalar;
7348
7348
  exports.YAMLMap = YAMLMap.YAMLMap;
@@ -9169,13 +9169,14 @@ function detect(preference, adapters = {}) {
9169
9169
 
9170
9170
  // src/transports/pane/pane.ts
9171
9171
  var NAME_BYTES2 = 6;
9172
+ var OWNER_ONLY_FILE = 384;
9172
9173
  function splitCommand(value) {
9173
9174
  return value.trim().split(/\s+/).filter((part) => part !== "");
9174
9175
  }
9175
9176
  function tempFile(prefix, suffix, content) {
9176
9177
  const name = `${prefix}${randomBytes3(NAME_BYTES2).toString("hex")}${suffix}`;
9177
9178
  const path = join8(tmpdir2(), name);
9178
- writeFileSync5(path, content, "utf-8");
9179
+ writeFileSync5(path, content, { encoding: "utf-8", mode: OWNER_ONLY_FILE, flag: "wx" });
9179
9180
  return path;
9180
9181
  }
9181
9182
  function removeTreeQuietly(path) {
@@ -9527,6 +9528,71 @@ function trace(message, config) {
9527
9528
  }
9528
9529
  }
9529
9530
 
9531
+ // src/adapters/codex/apply.ts
9532
+ var identity = (line) => line;
9533
+ var trimTrailing = (line) => line.replace(/\s+$/, "");
9534
+ var trimBoth = (line) => line.trim();
9535
+ function findRun(lines, target, from, normalize) {
9536
+ const wanted = target.map(normalize);
9537
+ for (let i = from; i + target.length <= lines.length; i++) {
9538
+ let matches = true;
9539
+ for (let offset = 0; offset < wanted.length; offset++) {
9540
+ if (normalize(lines[i + offset] ?? "") !== wanted[offset]) {
9541
+ matches = false;
9542
+ break;
9543
+ }
9544
+ }
9545
+ if (matches) {
9546
+ return i;
9547
+ }
9548
+ }
9549
+ return -1;
9550
+ }
9551
+ function findOldRun(lines, oldLines, from) {
9552
+ const exact = findRun(lines, oldLines, from, identity);
9553
+ if (exact !== -1) return exact;
9554
+ const trailingTrimmed = findRun(lines, oldLines, from, trimTrailing);
9555
+ if (trailingTrimmed !== -1) return trailingTrimmed;
9556
+ return findRun(lines, oldLines, from, trimBoth);
9557
+ }
9558
+ function findContext(lines, ctx, cursor) {
9559
+ for (let i = cursor; i < lines.length; i++) {
9560
+ if (lines[i] === ctx) {
9561
+ return i;
9562
+ }
9563
+ }
9564
+ return -1;
9565
+ }
9566
+ function applyHunks(text, hunks) {
9567
+ let lines = text.split("\n");
9568
+ let cursor = 0;
9569
+ for (const hunk of hunks) {
9570
+ if (hunk.context !== null) {
9571
+ const contextIndex = findContext(lines, hunk.context, cursor);
9572
+ if (contextIndex === -1) {
9573
+ return null;
9574
+ }
9575
+ cursor = contextIndex + 1;
9576
+ }
9577
+ const oldLines = hunk.lines.flatMap((line) => line.old !== null ? [line.old] : []);
9578
+ const newLines = hunk.lines.flatMap((line) => line.new !== null ? [line.new] : []);
9579
+ if (oldLines.length === 0) {
9580
+ return null;
9581
+ }
9582
+ const matchIndex = findOldRun(lines, oldLines, cursor);
9583
+ if (matchIndex === -1) {
9584
+ return null;
9585
+ }
9586
+ lines = [
9587
+ ...lines.slice(0, matchIndex),
9588
+ ...newLines,
9589
+ ...lines.slice(matchIndex + oldLines.length)
9590
+ ];
9591
+ cursor = matchIndex + newLines.length;
9592
+ }
9593
+ return lines.join("\n");
9594
+ }
9595
+
9530
9596
  // src/adapters/entry-point.ts
9531
9597
  import { realpathSync as realpathSync2 } from "node:fs";
9532
9598
  import { fileURLToPath as fileURLToPath3 } from "node:url";
@@ -9544,13 +9610,18 @@ function isEntryPoint(moduleUrl) {
9544
9610
 
9545
9611
  // src/adapters/codex/codex.ts
9546
9612
  var BEGIN_PATCH = "*** Begin Patch";
9613
+ var END_PATCH = "*** End Patch";
9547
9614
  var END_OF_FILE = "*** End of File";
9548
- function stripEndOfFile(inner) {
9549
- const lastIndex = inner.findLastIndex((line) => line.trim() !== "");
9550
- if (lastIndex === -1 || inner[lastIndex]?.trim() !== END_OF_FILE) {
9551
- return inner;
9615
+ var MOVE_TO_PREFIX = "*** Move to:";
9616
+ function isSectionHeader(line) {
9617
+ return line.startsWith("*** ") && !line.startsWith(MOVE_TO_PREFIX) && line.trim() !== END_OF_FILE;
9618
+ }
9619
+ function stripEndOfFile(body) {
9620
+ const lastIndex = body.findLastIndex((line) => line.trim() !== "");
9621
+ if (lastIndex === -1 || body[lastIndex]?.trim() !== END_OF_FILE) {
9622
+ return body;
9552
9623
  }
9553
- return [...inner.slice(0, lastIndex), ...inner.slice(lastIndex + 1)];
9624
+ return [...body.slice(0, lastIndex), ...body.slice(lastIndex + 1)];
9554
9625
  }
9555
9626
  var hasPatchMarker = (value) => typeof value === "string" && value.includes(BEGIN_PATCH);
9556
9627
  function extractPatchText(toolInput) {
@@ -9559,28 +9630,29 @@ function extractPatchText(toolInput) {
9559
9630
  if (!Array.isArray(command)) return null;
9560
9631
  return command.find(hasPatchMarker) ?? null;
9561
9632
  }
9562
- function extractSection(patchText) {
9633
+ function parseSections(patchText) {
9563
9634
  const lines = patchText.split("\n");
9564
9635
  const beginIndex = lines.findIndex((line) => line.trim() === BEGIN_PATCH);
9565
- const endIndex = lines.findIndex((line) => line.trim() === "*** End Patch");
9636
+ const endIndex = lines.findIndex((line) => line.trim() === END_PATCH);
9566
9637
  if (beginIndex === -1 || endIndex === -1 || endIndex <= beginIndex) {
9567
9638
  return null;
9568
9639
  }
9569
- const inner = stripEndOfFile(lines.slice(beginIndex + 1, endIndex));
9570
- const headerIndex = inner.findIndex((line) => line.startsWith("*** "));
9571
- if (headerIndex === -1) {
9572
- return null;
9573
- }
9574
- const header = inner[headerIndex];
9575
- const rest = inner.slice(headerIndex + 1);
9576
- const nextHeaderIndex = rest.findIndex((line) => line.startsWith("*** "));
9577
- if (header === void 0) {
9578
- return null;
9579
- }
9580
- if (nextHeaderIndex !== -1) {
9640
+ const inner = lines.slice(beginIndex + 1, endIndex);
9641
+ const headerIndices = inner.reduce(
9642
+ (acc, line, index) => isSectionHeader(line) ? [...acc, index] : acc,
9643
+ []
9644
+ );
9645
+ if (headerIndices.length === 0) {
9581
9646
  return null;
9582
9647
  }
9583
- return { header, body: rest };
9648
+ return headerIndices.map((headerIndex, order) => {
9649
+ const header = inner[headerIndex] ?? "";
9650
+ const end = headerIndices[order + 1] ?? inner.length;
9651
+ const rawBody = inner.slice(headerIndex + 1, end);
9652
+ const bodyNoEof = stripEndOfFile(rawBody);
9653
+ const body = bodyNoEof.filter((line) => !line.startsWith(MOVE_TO_PREFIX));
9654
+ return { header, body };
9655
+ });
9584
9656
  }
9585
9657
  function pathFromHeader(header, marker) {
9586
9658
  if (!header.startsWith(marker)) {
@@ -9611,47 +9683,43 @@ function classifyHunkLine(line) {
9611
9683
  }
9612
9684
  return null;
9613
9685
  }
9614
- function hunkToEdit(hunkLines) {
9615
- const classified = hunkLines.map(classifyHunkLine);
9616
- if (!classified.every((entry) => entry !== null)) {
9617
- return null;
9618
- }
9619
- const oldLines = classified.flatMap((entry) => entry.old !== null ? [entry.old] : []);
9620
- const newLines = classified.flatMap((entry) => entry.new !== null ? [entry.new] : []);
9621
- if (oldLines.length === 0) {
9686
+ function contextFor(line) {
9687
+ if (line === "@@") {
9622
9688
  return null;
9623
9689
  }
9624
- return { old_string: oldLines.join("\n"), new_string: newLines.join("\n") };
9690
+ return line.startsWith("@@ ") ? line.slice(3) : line.slice(2);
9625
9691
  }
9626
9692
  function parseUpdateFile(body) {
9627
- const hunks = [];
9693
+ const groups = [];
9628
9694
  let current = null;
9629
9695
  for (const line of body) {
9630
9696
  if (line.startsWith("@@")) {
9631
- current = [];
9632
- hunks.push(current);
9697
+ current = { context: contextFor(line), raw: [] };
9698
+ groups.push(current);
9633
9699
  continue;
9634
9700
  }
9635
9701
  if (current === null) {
9636
- current = [];
9637
- hunks.push(current);
9702
+ current = { context: null, raw: [] };
9703
+ groups.push(current);
9638
9704
  }
9639
- current.push(line);
9705
+ current.raw.push(line);
9640
9706
  }
9641
- if (hunks.length === 0) {
9707
+ if (groups.length === 0) {
9642
9708
  return null;
9643
9709
  }
9644
- const edits = hunks.map(hunkToEdit);
9645
- if (!edits.every((edit) => edit !== null)) {
9710
+ const hunks = groups.map((group) => {
9711
+ const classified = group.raw.map(classifyHunkLine);
9712
+ if (!classified.every((entry) => entry !== null)) {
9713
+ return null;
9714
+ }
9715
+ return { context: group.context, lines: classified };
9716
+ });
9717
+ if (!hunks.every((hunk) => hunk !== null)) {
9646
9718
  return null;
9647
9719
  }
9648
- return edits;
9720
+ return hunks;
9649
9721
  }
9650
- function parsePatch(patchText) {
9651
- const section = extractSection(patchText);
9652
- if (section === null) {
9653
- return null;
9654
- }
9722
+ function parseSection(section) {
9655
9723
  const addPath = pathFromHeader(section.header, "*** Add File:");
9656
9724
  if (addPath !== null) {
9657
9725
  const content = parseAddFile(section.body);
@@ -9666,18 +9734,84 @@ function parsePatch(patchText) {
9666
9734
  }
9667
9735
  const updatePath = pathFromHeader(section.header, "*** Update File:");
9668
9736
  if (updatePath !== null) {
9669
- const edits = parseUpdateFile(section.body);
9670
- if (edits === null) {
9737
+ const hunks = parseUpdateFile(section.body);
9738
+ if (hunks === null) {
9671
9739
  return null;
9672
9740
  }
9673
- return { filePath: updatePath, tool: "MultiEdit", edits };
9741
+ return { filePath: updatePath, tool: "MultiEdit", hunks };
9674
9742
  }
9675
9743
  return null;
9676
9744
  }
9745
+ function parsePatch(patchText) {
9746
+ const sections = parseSections(patchText);
9747
+ if (sections === null) {
9748
+ return null;
9749
+ }
9750
+ const parsed = sections.map(parseSection);
9751
+ if (!parsed.every((entry) => entry !== null)) {
9752
+ return null;
9753
+ }
9754
+ return parsed;
9755
+ }
9677
9756
  function toolNameFor(payload) {
9678
9757
  const value = payload["tool_name"];
9679
9758
  return typeof value === "string" ? value : "";
9680
9759
  }
9760
+ function emitDeny(reason) {
9761
+ const denyJson = JSON.stringify({
9762
+ hookSpecificOutput: {
9763
+ hookEventName: "PreToolUse",
9764
+ permissionDecision: "deny",
9765
+ permissionDecisionReason: reason
9766
+ }
9767
+ });
9768
+ try {
9769
+ process.stdout.write(denyJson + "\n");
9770
+ return 0;
9771
+ } catch {
9772
+ process.stderr.write(reason + "\n");
9773
+ return 2;
9774
+ }
9775
+ }
9776
+ function buildRequest(section, sessionId, config) {
9777
+ if (section.tool === "Write") {
9778
+ const input = { file_path: section.filePath, content: section.content ?? "" };
9779
+ return simulate("Write", input, readFileOrEmpty, sessionId);
9780
+ }
9781
+ const before = readFileOrEmpty(section.filePath);
9782
+ const after = applyHunks(before, section.hunks ?? []);
9783
+ if (after === null) {
9784
+ trace("exit: apply_patch hunk defeated the applier", config);
9785
+ return null;
9786
+ }
9787
+ return { tool: "MultiEdit", filePath: section.filePath, before, after, sessionId };
9788
+ }
9789
+ async function reviewPatch(toolInput, sessionId, key, config) {
9790
+ const patchText = extractPatchText(toolInput);
9791
+ if (patchText === null) {
9792
+ trace("exit: apply_patch payload had no patch text", config);
9793
+ return 0;
9794
+ }
9795
+ const sections = parsePatch(patchText);
9796
+ if (sections === null) {
9797
+ trace("exit: apply_patch body defeated the parser", config);
9798
+ return 0;
9799
+ }
9800
+ for (const section of sections) {
9801
+ if (!isEnabled(section.filePath, key)) {
9802
+ continue;
9803
+ }
9804
+ const request = buildRequest(section, sessionId, config);
9805
+ if (request === null) {
9806
+ continue;
9807
+ }
9808
+ const verdict = await runPair(request, config);
9809
+ if (verdict.decision === "deny") {
9810
+ return emitDeny(verdict.reason);
9811
+ }
9812
+ }
9813
+ return 0;
9814
+ }
9681
9815
  async function main(config) {
9682
9816
  const payload = readPayload();
9683
9817
  if (!isRecord(payload)) {
@@ -9690,32 +9824,16 @@ async function main(config) {
9690
9824
  }
9691
9825
  const rawSessionId = payload["session_id"];
9692
9826
  const sessionId = typeof rawSessionId === "string" ? rawSessionId : void 0;
9693
- let simTool = tool;
9694
- let simInput = toolInput;
9827
+ const key = keyFor(sessionId);
9695
9828
  if (tool === "apply_patch") {
9696
- const patchText = extractPatchText(toolInput);
9697
- if (patchText === null) {
9698
- trace("exit: apply_patch payload had no patch text", config);
9699
- return 0;
9700
- }
9701
- const parsed = parsePatch(patchText);
9702
- if (parsed === null) {
9703
- trace("exit: apply_patch body defeated the parser", config);
9704
- return 0;
9705
- }
9706
- simTool = parsed.tool;
9707
- simInput = parsed.tool === "Write" ? { file_path: parsed.filePath, content: parsed.content ?? "" } : { file_path: parsed.filePath, edits: parsed.edits ?? [] };
9829
+ return reviewPatch(toolInput, sessionId, key, config);
9708
9830
  }
9709
- const filePathValue = simInput["file_path"];
9831
+ const filePathValue = toolInput["file_path"];
9710
9832
  const filePath = typeof filePathValue === "string" ? filePathValue : "";
9711
- if (filePath === "") {
9712
- return 0;
9713
- }
9714
- const key = keyFor(sessionId);
9715
- if (!isEnabled(filePath, key)) {
9833
+ if (filePath === "" || !isEnabled(filePath, key)) {
9716
9834
  return 0;
9717
9835
  }
9718
- const request = simulate(simTool, simInput, readFileOrEmpty, sessionId);
9836
+ const request = simulate(tool, toolInput, readFileOrEmpty, sessionId);
9719
9837
  if (request === null) {
9720
9838
  trace("exit: could not simulate", config);
9721
9839
  return 0;
@@ -9724,20 +9842,7 @@ async function main(config) {
9724
9842
  if (verdict.decision === "allow") {
9725
9843
  return 0;
9726
9844
  }
9727
- const denyJson = JSON.stringify({
9728
- hookSpecificOutput: {
9729
- hookEventName: "PreToolUse",
9730
- permissionDecision: "deny",
9731
- permissionDecisionReason: verdict.reason
9732
- }
9733
- });
9734
- try {
9735
- process.stdout.write(denyJson + "\n");
9736
- return 0;
9737
- } catch {
9738
- process.stderr.write(verdict.reason + "\n");
9739
- return 2;
9740
- }
9845
+ return emitDeny(verdict.reason);
9741
9846
  }
9742
9847
  async function run() {
9743
9848
  let config = DEFAULT_CONFIG;