opencode-plugin-search 0.0.2 → 0.0.4

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 (3) hide show
  1. package/README.md +62 -13
  2. package/dist/index.js +3101 -42
  3. package/package.json +13 -4
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "node:module";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __export = (target, all) => {
3
4
  for (var name in all)
@@ -8,6 +9,7 @@ var __export = (target, all) => {
8
9
  set: (newValue) => all[name] = () => newValue
9
10
  });
10
11
  };
12
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
11
13
 
12
14
  // node_modules/zod/v4/classic/external.js
13
15
  var exports_external = {};
@@ -12329,7 +12331,2692 @@ function tool(input) {
12329
12331
  return input;
12330
12332
  }
12331
12333
  tool.schema = exports_external;
12332
- // src/utils.ts
12334
+ // node_modules/js-yaml/dist/js-yaml.mjs
12335
+ /*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT */
12336
+ function isNothing(subject) {
12337
+ return typeof subject === "undefined" || subject === null;
12338
+ }
12339
+ function isObject2(subject) {
12340
+ return typeof subject === "object" && subject !== null;
12341
+ }
12342
+ function toArray(sequence) {
12343
+ if (Array.isArray(sequence))
12344
+ return sequence;
12345
+ else if (isNothing(sequence))
12346
+ return [];
12347
+ return [sequence];
12348
+ }
12349
+ function extend2(target, source) {
12350
+ var index, length, key, sourceKeys;
12351
+ if (source) {
12352
+ sourceKeys = Object.keys(source);
12353
+ for (index = 0, length = sourceKeys.length;index < length; index += 1) {
12354
+ key = sourceKeys[index];
12355
+ target[key] = source[key];
12356
+ }
12357
+ }
12358
+ return target;
12359
+ }
12360
+ function repeat(string4, count) {
12361
+ var result = "", cycle;
12362
+ for (cycle = 0;cycle < count; cycle += 1) {
12363
+ result += string4;
12364
+ }
12365
+ return result;
12366
+ }
12367
+ function isNegativeZero(number4) {
12368
+ return number4 === 0 && Number.NEGATIVE_INFINITY === 1 / number4;
12369
+ }
12370
+ var isNothing_1 = isNothing;
12371
+ var isObject_1 = isObject2;
12372
+ var toArray_1 = toArray;
12373
+ var repeat_1 = repeat;
12374
+ var isNegativeZero_1 = isNegativeZero;
12375
+ var extend_1 = extend2;
12376
+ var common = {
12377
+ isNothing: isNothing_1,
12378
+ isObject: isObject_1,
12379
+ toArray: toArray_1,
12380
+ repeat: repeat_1,
12381
+ isNegativeZero: isNegativeZero_1,
12382
+ extend: extend_1
12383
+ };
12384
+ function formatError2(exception, compact) {
12385
+ var where = "", message = exception.reason || "(unknown reason)";
12386
+ if (!exception.mark)
12387
+ return message;
12388
+ if (exception.mark.name) {
12389
+ where += 'in "' + exception.mark.name + '" ';
12390
+ }
12391
+ where += "(" + (exception.mark.line + 1) + ":" + (exception.mark.column + 1) + ")";
12392
+ if (!compact && exception.mark.snippet) {
12393
+ where += `
12394
+
12395
+ ` + exception.mark.snippet;
12396
+ }
12397
+ return message + " " + where;
12398
+ }
12399
+ function YAMLException$1(reason, mark) {
12400
+ Error.call(this);
12401
+ this.name = "YAMLException";
12402
+ this.reason = reason;
12403
+ this.mark = mark;
12404
+ this.message = formatError2(this, false);
12405
+ if (Error.captureStackTrace) {
12406
+ Error.captureStackTrace(this, this.constructor);
12407
+ } else {
12408
+ this.stack = new Error().stack || "";
12409
+ }
12410
+ }
12411
+ YAMLException$1.prototype = Object.create(Error.prototype);
12412
+ YAMLException$1.prototype.constructor = YAMLException$1;
12413
+ YAMLException$1.prototype.toString = function toString(compact) {
12414
+ return this.name + ": " + formatError2(this, compact);
12415
+ };
12416
+ var exception = YAMLException$1;
12417
+ function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
12418
+ var head = "";
12419
+ var tail = "";
12420
+ var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
12421
+ if (position - lineStart > maxHalfLength) {
12422
+ head = " ... ";
12423
+ lineStart = position - maxHalfLength + head.length;
12424
+ }
12425
+ if (lineEnd - position > maxHalfLength) {
12426
+ tail = " ...";
12427
+ lineEnd = position + maxHalfLength - tail.length;
12428
+ }
12429
+ return {
12430
+ str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "→") + tail,
12431
+ pos: position - lineStart + head.length
12432
+ };
12433
+ }
12434
+ function padStart(string4, max) {
12435
+ return common.repeat(" ", max - string4.length) + string4;
12436
+ }
12437
+ function makeSnippet(mark, options) {
12438
+ options = Object.create(options || null);
12439
+ if (!mark.buffer)
12440
+ return null;
12441
+ if (!options.maxLength)
12442
+ options.maxLength = 79;
12443
+ if (typeof options.indent !== "number")
12444
+ options.indent = 1;
12445
+ if (typeof options.linesBefore !== "number")
12446
+ options.linesBefore = 3;
12447
+ if (typeof options.linesAfter !== "number")
12448
+ options.linesAfter = 2;
12449
+ var re = /\r?\n|\r|\0/g;
12450
+ var lineStarts = [0];
12451
+ var lineEnds = [];
12452
+ var match;
12453
+ var foundLineNo = -1;
12454
+ while (match = re.exec(mark.buffer)) {
12455
+ lineEnds.push(match.index);
12456
+ lineStarts.push(match.index + match[0].length);
12457
+ if (mark.position <= match.index && foundLineNo < 0) {
12458
+ foundLineNo = lineStarts.length - 2;
12459
+ }
12460
+ }
12461
+ if (foundLineNo < 0)
12462
+ foundLineNo = lineStarts.length - 1;
12463
+ var result = "", i, line;
12464
+ var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
12465
+ var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
12466
+ for (i = 1;i <= options.linesBefore; i++) {
12467
+ if (foundLineNo - i < 0)
12468
+ break;
12469
+ line = getLine(mark.buffer, lineStarts[foundLineNo - i], lineEnds[foundLineNo - i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), maxLineLength);
12470
+ result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + `
12471
+ ` + result;
12472
+ }
12473
+ line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
12474
+ result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + `
12475
+ `;
12476
+ result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^" + `
12477
+ `;
12478
+ for (i = 1;i <= options.linesAfter; i++) {
12479
+ if (foundLineNo + i >= lineEnds.length)
12480
+ break;
12481
+ line = getLine(mark.buffer, lineStarts[foundLineNo + i], lineEnds[foundLineNo + i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), maxLineLength);
12482
+ result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + `
12483
+ `;
12484
+ }
12485
+ return result.replace(/\n$/, "");
12486
+ }
12487
+ var snippet = makeSnippet;
12488
+ var TYPE_CONSTRUCTOR_OPTIONS = [
12489
+ "kind",
12490
+ "multi",
12491
+ "resolve",
12492
+ "construct",
12493
+ "instanceOf",
12494
+ "predicate",
12495
+ "represent",
12496
+ "representName",
12497
+ "defaultStyle",
12498
+ "styleAliases"
12499
+ ];
12500
+ var YAML_NODE_KINDS = [
12501
+ "scalar",
12502
+ "sequence",
12503
+ "mapping"
12504
+ ];
12505
+ function compileStyleAliases(map2) {
12506
+ var result = {};
12507
+ if (map2 !== null) {
12508
+ Object.keys(map2).forEach(function(style) {
12509
+ map2[style].forEach(function(alias) {
12510
+ result[String(alias)] = style;
12511
+ });
12512
+ });
12513
+ }
12514
+ return result;
12515
+ }
12516
+ function Type$1(tag, options) {
12517
+ options = options || {};
12518
+ Object.keys(options).forEach(function(name) {
12519
+ if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
12520
+ throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
12521
+ }
12522
+ });
12523
+ this.options = options;
12524
+ this.tag = tag;
12525
+ this.kind = options["kind"] || null;
12526
+ this.resolve = options["resolve"] || function() {
12527
+ return true;
12528
+ };
12529
+ this.construct = options["construct"] || function(data) {
12530
+ return data;
12531
+ };
12532
+ this.instanceOf = options["instanceOf"] || null;
12533
+ this.predicate = options["predicate"] || null;
12534
+ this.represent = options["represent"] || null;
12535
+ this.representName = options["representName"] || null;
12536
+ this.defaultStyle = options["defaultStyle"] || null;
12537
+ this.multi = options["multi"] || false;
12538
+ this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
12539
+ if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
12540
+ throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
12541
+ }
12542
+ }
12543
+ var type = Type$1;
12544
+ function compileList(schema, name) {
12545
+ var result = [];
12546
+ schema[name].forEach(function(currentType) {
12547
+ var newIndex = result.length;
12548
+ result.forEach(function(previousType, previousIndex) {
12549
+ if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
12550
+ newIndex = previousIndex;
12551
+ }
12552
+ });
12553
+ result[newIndex] = currentType;
12554
+ });
12555
+ return result;
12556
+ }
12557
+ function compileMap() {
12558
+ var result = {
12559
+ scalar: {},
12560
+ sequence: {},
12561
+ mapping: {},
12562
+ fallback: {},
12563
+ multi: {
12564
+ scalar: [],
12565
+ sequence: [],
12566
+ mapping: [],
12567
+ fallback: []
12568
+ }
12569
+ }, index, length;
12570
+ function collectType(type2) {
12571
+ if (type2.multi) {
12572
+ result.multi[type2.kind].push(type2);
12573
+ result.multi["fallback"].push(type2);
12574
+ } else {
12575
+ result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2;
12576
+ }
12577
+ }
12578
+ for (index = 0, length = arguments.length;index < length; index += 1) {
12579
+ arguments[index].forEach(collectType);
12580
+ }
12581
+ return result;
12582
+ }
12583
+ function Schema$1(definition) {
12584
+ return this.extend(definition);
12585
+ }
12586
+ Schema$1.prototype.extend = function extend3(definition) {
12587
+ var implicit = [];
12588
+ var explicit = [];
12589
+ if (definition instanceof type) {
12590
+ explicit.push(definition);
12591
+ } else if (Array.isArray(definition)) {
12592
+ explicit = explicit.concat(definition);
12593
+ } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
12594
+ if (definition.implicit)
12595
+ implicit = implicit.concat(definition.implicit);
12596
+ if (definition.explicit)
12597
+ explicit = explicit.concat(definition.explicit);
12598
+ } else {
12599
+ throw new exception("Schema.extend argument should be a Type, [ Type ], " + "or a schema definition ({ implicit: [...], explicit: [...] })");
12600
+ }
12601
+ implicit.forEach(function(type$1) {
12602
+ if (!(type$1 instanceof type)) {
12603
+ throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
12604
+ }
12605
+ if (type$1.loadKind && type$1.loadKind !== "scalar") {
12606
+ throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
12607
+ }
12608
+ if (type$1.multi) {
12609
+ throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
12610
+ }
12611
+ });
12612
+ explicit.forEach(function(type$1) {
12613
+ if (!(type$1 instanceof type)) {
12614
+ throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
12615
+ }
12616
+ });
12617
+ var result = Object.create(Schema$1.prototype);
12618
+ result.implicit = (this.implicit || []).concat(implicit);
12619
+ result.explicit = (this.explicit || []).concat(explicit);
12620
+ result.compiledImplicit = compileList(result, "implicit");
12621
+ result.compiledExplicit = compileList(result, "explicit");
12622
+ result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
12623
+ return result;
12624
+ };
12625
+ var schema = Schema$1;
12626
+ var str = new type("tag:yaml.org,2002:str", {
12627
+ kind: "scalar",
12628
+ construct: function(data) {
12629
+ return data !== null ? data : "";
12630
+ }
12631
+ });
12632
+ var seq = new type("tag:yaml.org,2002:seq", {
12633
+ kind: "sequence",
12634
+ construct: function(data) {
12635
+ return data !== null ? data : [];
12636
+ }
12637
+ });
12638
+ var map2 = new type("tag:yaml.org,2002:map", {
12639
+ kind: "mapping",
12640
+ construct: function(data) {
12641
+ return data !== null ? data : {};
12642
+ }
12643
+ });
12644
+ var failsafe = new schema({
12645
+ explicit: [
12646
+ str,
12647
+ seq,
12648
+ map2
12649
+ ]
12650
+ });
12651
+ function resolveYamlNull(data) {
12652
+ if (data === null)
12653
+ return true;
12654
+ var max = data.length;
12655
+ return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
12656
+ }
12657
+ function constructYamlNull() {
12658
+ return null;
12659
+ }
12660
+ function isNull(object2) {
12661
+ return object2 === null;
12662
+ }
12663
+ var _null4 = new type("tag:yaml.org,2002:null", {
12664
+ kind: "scalar",
12665
+ resolve: resolveYamlNull,
12666
+ construct: constructYamlNull,
12667
+ predicate: isNull,
12668
+ represent: {
12669
+ canonical: function() {
12670
+ return "~";
12671
+ },
12672
+ lowercase: function() {
12673
+ return "null";
12674
+ },
12675
+ uppercase: function() {
12676
+ return "NULL";
12677
+ },
12678
+ camelcase: function() {
12679
+ return "Null";
12680
+ },
12681
+ empty: function() {
12682
+ return "";
12683
+ }
12684
+ },
12685
+ defaultStyle: "lowercase"
12686
+ });
12687
+ function resolveYamlBoolean(data) {
12688
+ if (data === null)
12689
+ return false;
12690
+ var max = data.length;
12691
+ return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
12692
+ }
12693
+ function constructYamlBoolean(data) {
12694
+ return data === "true" || data === "True" || data === "TRUE";
12695
+ }
12696
+ function isBoolean(object2) {
12697
+ return Object.prototype.toString.call(object2) === "[object Boolean]";
12698
+ }
12699
+ var bool = new type("tag:yaml.org,2002:bool", {
12700
+ kind: "scalar",
12701
+ resolve: resolveYamlBoolean,
12702
+ construct: constructYamlBoolean,
12703
+ predicate: isBoolean,
12704
+ represent: {
12705
+ lowercase: function(object2) {
12706
+ return object2 ? "true" : "false";
12707
+ },
12708
+ uppercase: function(object2) {
12709
+ return object2 ? "TRUE" : "FALSE";
12710
+ },
12711
+ camelcase: function(object2) {
12712
+ return object2 ? "True" : "False";
12713
+ }
12714
+ },
12715
+ defaultStyle: "lowercase"
12716
+ });
12717
+ function isHexCode(c) {
12718
+ return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
12719
+ }
12720
+ function isOctCode(c) {
12721
+ return 48 <= c && c <= 55;
12722
+ }
12723
+ function isDecCode(c) {
12724
+ return 48 <= c && c <= 57;
12725
+ }
12726
+ function resolveYamlInteger(data) {
12727
+ if (data === null)
12728
+ return false;
12729
+ var max = data.length, index = 0, hasDigits = false, ch;
12730
+ if (!max)
12731
+ return false;
12732
+ ch = data[index];
12733
+ if (ch === "-" || ch === "+") {
12734
+ ch = data[++index];
12735
+ }
12736
+ if (ch === "0") {
12737
+ if (index + 1 === max)
12738
+ return true;
12739
+ ch = data[++index];
12740
+ if (ch === "b") {
12741
+ index++;
12742
+ for (;index < max; index++) {
12743
+ ch = data[index];
12744
+ if (ch === "_")
12745
+ continue;
12746
+ if (ch !== "0" && ch !== "1")
12747
+ return false;
12748
+ hasDigits = true;
12749
+ }
12750
+ return hasDigits && ch !== "_";
12751
+ }
12752
+ if (ch === "x") {
12753
+ index++;
12754
+ for (;index < max; index++) {
12755
+ ch = data[index];
12756
+ if (ch === "_")
12757
+ continue;
12758
+ if (!isHexCode(data.charCodeAt(index)))
12759
+ return false;
12760
+ hasDigits = true;
12761
+ }
12762
+ return hasDigits && ch !== "_";
12763
+ }
12764
+ if (ch === "o") {
12765
+ index++;
12766
+ for (;index < max; index++) {
12767
+ ch = data[index];
12768
+ if (ch === "_")
12769
+ continue;
12770
+ if (!isOctCode(data.charCodeAt(index)))
12771
+ return false;
12772
+ hasDigits = true;
12773
+ }
12774
+ return hasDigits && ch !== "_";
12775
+ }
12776
+ }
12777
+ if (ch === "_")
12778
+ return false;
12779
+ for (;index < max; index++) {
12780
+ ch = data[index];
12781
+ if (ch === "_")
12782
+ continue;
12783
+ if (!isDecCode(data.charCodeAt(index))) {
12784
+ return false;
12785
+ }
12786
+ hasDigits = true;
12787
+ }
12788
+ if (!hasDigits || ch === "_")
12789
+ return false;
12790
+ return true;
12791
+ }
12792
+ function constructYamlInteger(data) {
12793
+ var value = data, sign = 1, ch;
12794
+ if (value.indexOf("_") !== -1) {
12795
+ value = value.replace(/_/g, "");
12796
+ }
12797
+ ch = value[0];
12798
+ if (ch === "-" || ch === "+") {
12799
+ if (ch === "-")
12800
+ sign = -1;
12801
+ value = value.slice(1);
12802
+ ch = value[0];
12803
+ }
12804
+ if (value === "0")
12805
+ return 0;
12806
+ if (ch === "0") {
12807
+ if (value[1] === "b")
12808
+ return sign * parseInt(value.slice(2), 2);
12809
+ if (value[1] === "x")
12810
+ return sign * parseInt(value.slice(2), 16);
12811
+ if (value[1] === "o")
12812
+ return sign * parseInt(value.slice(2), 8);
12813
+ }
12814
+ return sign * parseInt(value, 10);
12815
+ }
12816
+ function isInteger(object2) {
12817
+ return Object.prototype.toString.call(object2) === "[object Number]" && (object2 % 1 === 0 && !common.isNegativeZero(object2));
12818
+ }
12819
+ var int2 = new type("tag:yaml.org,2002:int", {
12820
+ kind: "scalar",
12821
+ resolve: resolveYamlInteger,
12822
+ construct: constructYamlInteger,
12823
+ predicate: isInteger,
12824
+ represent: {
12825
+ binary: function(obj) {
12826
+ return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
12827
+ },
12828
+ octal: function(obj) {
12829
+ return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
12830
+ },
12831
+ decimal: function(obj) {
12832
+ return obj.toString(10);
12833
+ },
12834
+ hexadecimal: function(obj) {
12835
+ return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
12836
+ }
12837
+ },
12838
+ defaultStyle: "decimal",
12839
+ styleAliases: {
12840
+ binary: [2, "bin"],
12841
+ octal: [8, "oct"],
12842
+ decimal: [10, "dec"],
12843
+ hexadecimal: [16, "hex"]
12844
+ }
12845
+ });
12846
+ var YAML_FLOAT_PATTERN = new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?" + "|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?" + "|[-+]?\\.(?:inf|Inf|INF)" + "|\\.(?:nan|NaN|NAN))$");
12847
+ function resolveYamlFloat(data) {
12848
+ if (data === null)
12849
+ return false;
12850
+ if (!YAML_FLOAT_PATTERN.test(data) || data[data.length - 1] === "_") {
12851
+ return false;
12852
+ }
12853
+ return true;
12854
+ }
12855
+ function constructYamlFloat(data) {
12856
+ var value, sign;
12857
+ value = data.replace(/_/g, "").toLowerCase();
12858
+ sign = value[0] === "-" ? -1 : 1;
12859
+ if ("+-".indexOf(value[0]) >= 0) {
12860
+ value = value.slice(1);
12861
+ }
12862
+ if (value === ".inf") {
12863
+ return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
12864
+ } else if (value === ".nan") {
12865
+ return NaN;
12866
+ }
12867
+ return sign * parseFloat(value, 10);
12868
+ }
12869
+ var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
12870
+ function representYamlFloat(object2, style) {
12871
+ var res;
12872
+ if (isNaN(object2)) {
12873
+ switch (style) {
12874
+ case "lowercase":
12875
+ return ".nan";
12876
+ case "uppercase":
12877
+ return ".NAN";
12878
+ case "camelcase":
12879
+ return ".NaN";
12880
+ }
12881
+ } else if (Number.POSITIVE_INFINITY === object2) {
12882
+ switch (style) {
12883
+ case "lowercase":
12884
+ return ".inf";
12885
+ case "uppercase":
12886
+ return ".INF";
12887
+ case "camelcase":
12888
+ return ".Inf";
12889
+ }
12890
+ } else if (Number.NEGATIVE_INFINITY === object2) {
12891
+ switch (style) {
12892
+ case "lowercase":
12893
+ return "-.inf";
12894
+ case "uppercase":
12895
+ return "-.INF";
12896
+ case "camelcase":
12897
+ return "-.Inf";
12898
+ }
12899
+ } else if (common.isNegativeZero(object2)) {
12900
+ return "-0.0";
12901
+ }
12902
+ res = object2.toString(10);
12903
+ return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
12904
+ }
12905
+ function isFloat(object2) {
12906
+ return Object.prototype.toString.call(object2) === "[object Number]" && (object2 % 1 !== 0 || common.isNegativeZero(object2));
12907
+ }
12908
+ var float = new type("tag:yaml.org,2002:float", {
12909
+ kind: "scalar",
12910
+ resolve: resolveYamlFloat,
12911
+ construct: constructYamlFloat,
12912
+ predicate: isFloat,
12913
+ represent: representYamlFloat,
12914
+ defaultStyle: "lowercase"
12915
+ });
12916
+ var json2 = failsafe.extend({
12917
+ implicit: [
12918
+ _null4,
12919
+ bool,
12920
+ int2,
12921
+ float
12922
+ ]
12923
+ });
12924
+ var core2 = json2;
12925
+ var YAML_DATE_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])" + "-([0-9][0-9])" + "-([0-9][0-9])$");
12926
+ var YAML_TIMESTAMP_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])" + "-([0-9][0-9]?)" + "-([0-9][0-9]?)" + "(?:[Tt]|[ \\t]+)" + "([0-9][0-9]?)" + ":([0-9][0-9])" + ":([0-9][0-9])" + "(?:\\.([0-9]*))?" + "(?:[ \\t]*(Z|([-+])([0-9][0-9]?)" + "(?::([0-9][0-9]))?))?$");
12927
+ function resolveYamlTimestamp(data) {
12928
+ if (data === null)
12929
+ return false;
12930
+ if (YAML_DATE_REGEXP.exec(data) !== null)
12931
+ return true;
12932
+ if (YAML_TIMESTAMP_REGEXP.exec(data) !== null)
12933
+ return true;
12934
+ return false;
12935
+ }
12936
+ function constructYamlTimestamp(data) {
12937
+ var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date5;
12938
+ match = YAML_DATE_REGEXP.exec(data);
12939
+ if (match === null)
12940
+ match = YAML_TIMESTAMP_REGEXP.exec(data);
12941
+ if (match === null)
12942
+ throw new Error("Date resolve error");
12943
+ year = +match[1];
12944
+ month = +match[2] - 1;
12945
+ day = +match[3];
12946
+ if (!match[4]) {
12947
+ return new Date(Date.UTC(year, month, day));
12948
+ }
12949
+ hour = +match[4];
12950
+ minute = +match[5];
12951
+ second = +match[6];
12952
+ if (match[7]) {
12953
+ fraction = match[7].slice(0, 3);
12954
+ while (fraction.length < 3) {
12955
+ fraction += "0";
12956
+ }
12957
+ fraction = +fraction;
12958
+ }
12959
+ if (match[9]) {
12960
+ tz_hour = +match[10];
12961
+ tz_minute = +(match[11] || 0);
12962
+ delta = (tz_hour * 60 + tz_minute) * 60000;
12963
+ if (match[9] === "-")
12964
+ delta = -delta;
12965
+ }
12966
+ date5 = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
12967
+ if (delta)
12968
+ date5.setTime(date5.getTime() - delta);
12969
+ return date5;
12970
+ }
12971
+ function representYamlTimestamp(object2) {
12972
+ return object2.toISOString();
12973
+ }
12974
+ var timestamp = new type("tag:yaml.org,2002:timestamp", {
12975
+ kind: "scalar",
12976
+ resolve: resolveYamlTimestamp,
12977
+ construct: constructYamlTimestamp,
12978
+ instanceOf: Date,
12979
+ represent: representYamlTimestamp
12980
+ });
12981
+ function resolveYamlMerge(data) {
12982
+ return data === "<<" || data === null;
12983
+ }
12984
+ var merge2 = new type("tag:yaml.org,2002:merge", {
12985
+ kind: "scalar",
12986
+ resolve: resolveYamlMerge
12987
+ });
12988
+ var BASE64_MAP = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
12989
+ \r`;
12990
+ function resolveYamlBinary(data) {
12991
+ if (data === null)
12992
+ return false;
12993
+ var code, idx, bitlen = 0, max = data.length, map3 = BASE64_MAP;
12994
+ for (idx = 0;idx < max; idx++) {
12995
+ code = map3.indexOf(data.charAt(idx));
12996
+ if (code > 64)
12997
+ continue;
12998
+ if (code < 0)
12999
+ return false;
13000
+ bitlen += 6;
13001
+ }
13002
+ return bitlen % 8 === 0;
13003
+ }
13004
+ function constructYamlBinary(data) {
13005
+ var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map3 = BASE64_MAP, bits = 0, result = [];
13006
+ for (idx = 0;idx < max; idx++) {
13007
+ if (idx % 4 === 0 && idx) {
13008
+ result.push(bits >> 16 & 255);
13009
+ result.push(bits >> 8 & 255);
13010
+ result.push(bits & 255);
13011
+ }
13012
+ bits = bits << 6 | map3.indexOf(input.charAt(idx));
13013
+ }
13014
+ tailbits = max % 4 * 6;
13015
+ if (tailbits === 0) {
13016
+ result.push(bits >> 16 & 255);
13017
+ result.push(bits >> 8 & 255);
13018
+ result.push(bits & 255);
13019
+ } else if (tailbits === 18) {
13020
+ result.push(bits >> 10 & 255);
13021
+ result.push(bits >> 2 & 255);
13022
+ } else if (tailbits === 12) {
13023
+ result.push(bits >> 4 & 255);
13024
+ }
13025
+ return new Uint8Array(result);
13026
+ }
13027
+ function representYamlBinary(object2) {
13028
+ var result = "", bits = 0, idx, tail, max = object2.length, map3 = BASE64_MAP;
13029
+ for (idx = 0;idx < max; idx++) {
13030
+ if (idx % 3 === 0 && idx) {
13031
+ result += map3[bits >> 18 & 63];
13032
+ result += map3[bits >> 12 & 63];
13033
+ result += map3[bits >> 6 & 63];
13034
+ result += map3[bits & 63];
13035
+ }
13036
+ bits = (bits << 8) + object2[idx];
13037
+ }
13038
+ tail = max % 3;
13039
+ if (tail === 0) {
13040
+ result += map3[bits >> 18 & 63];
13041
+ result += map3[bits >> 12 & 63];
13042
+ result += map3[bits >> 6 & 63];
13043
+ result += map3[bits & 63];
13044
+ } else if (tail === 2) {
13045
+ result += map3[bits >> 10 & 63];
13046
+ result += map3[bits >> 4 & 63];
13047
+ result += map3[bits << 2 & 63];
13048
+ result += map3[64];
13049
+ } else if (tail === 1) {
13050
+ result += map3[bits >> 2 & 63];
13051
+ result += map3[bits << 4 & 63];
13052
+ result += map3[64];
13053
+ result += map3[64];
13054
+ }
13055
+ return result;
13056
+ }
13057
+ function isBinary(obj) {
13058
+ return Object.prototype.toString.call(obj) === "[object Uint8Array]";
13059
+ }
13060
+ var binary = new type("tag:yaml.org,2002:binary", {
13061
+ kind: "scalar",
13062
+ resolve: resolveYamlBinary,
13063
+ construct: constructYamlBinary,
13064
+ predicate: isBinary,
13065
+ represent: representYamlBinary
13066
+ });
13067
+ var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
13068
+ var _toString$2 = Object.prototype.toString;
13069
+ function resolveYamlOmap(data) {
13070
+ if (data === null)
13071
+ return true;
13072
+ var objectKeys = [], index, length, pair, pairKey, pairHasKey, object2 = data;
13073
+ for (index = 0, length = object2.length;index < length; index += 1) {
13074
+ pair = object2[index];
13075
+ pairHasKey = false;
13076
+ if (_toString$2.call(pair) !== "[object Object]")
13077
+ return false;
13078
+ for (pairKey in pair) {
13079
+ if (_hasOwnProperty$3.call(pair, pairKey)) {
13080
+ if (!pairHasKey)
13081
+ pairHasKey = true;
13082
+ else
13083
+ return false;
13084
+ }
13085
+ }
13086
+ if (!pairHasKey)
13087
+ return false;
13088
+ if (objectKeys.indexOf(pairKey) === -1)
13089
+ objectKeys.push(pairKey);
13090
+ else
13091
+ return false;
13092
+ }
13093
+ return true;
13094
+ }
13095
+ function constructYamlOmap(data) {
13096
+ return data !== null ? data : [];
13097
+ }
13098
+ var omap = new type("tag:yaml.org,2002:omap", {
13099
+ kind: "sequence",
13100
+ resolve: resolveYamlOmap,
13101
+ construct: constructYamlOmap
13102
+ });
13103
+ var _toString$1 = Object.prototype.toString;
13104
+ function resolveYamlPairs(data) {
13105
+ if (data === null)
13106
+ return true;
13107
+ var index, length, pair, keys, result, object2 = data;
13108
+ result = new Array(object2.length);
13109
+ for (index = 0, length = object2.length;index < length; index += 1) {
13110
+ pair = object2[index];
13111
+ if (_toString$1.call(pair) !== "[object Object]")
13112
+ return false;
13113
+ keys = Object.keys(pair);
13114
+ if (keys.length !== 1)
13115
+ return false;
13116
+ result[index] = [keys[0], pair[keys[0]]];
13117
+ }
13118
+ return true;
13119
+ }
13120
+ function constructYamlPairs(data) {
13121
+ if (data === null)
13122
+ return [];
13123
+ var index, length, pair, keys, result, object2 = data;
13124
+ result = new Array(object2.length);
13125
+ for (index = 0, length = object2.length;index < length; index += 1) {
13126
+ pair = object2[index];
13127
+ keys = Object.keys(pair);
13128
+ result[index] = [keys[0], pair[keys[0]]];
13129
+ }
13130
+ return result;
13131
+ }
13132
+ var pairs = new type("tag:yaml.org,2002:pairs", {
13133
+ kind: "sequence",
13134
+ resolve: resolveYamlPairs,
13135
+ construct: constructYamlPairs
13136
+ });
13137
+ var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
13138
+ function resolveYamlSet(data) {
13139
+ if (data === null)
13140
+ return true;
13141
+ var key, object2 = data;
13142
+ for (key in object2) {
13143
+ if (_hasOwnProperty$2.call(object2, key)) {
13144
+ if (object2[key] !== null)
13145
+ return false;
13146
+ }
13147
+ }
13148
+ return true;
13149
+ }
13150
+ function constructYamlSet(data) {
13151
+ return data !== null ? data : {};
13152
+ }
13153
+ var set2 = new type("tag:yaml.org,2002:set", {
13154
+ kind: "mapping",
13155
+ resolve: resolveYamlSet,
13156
+ construct: constructYamlSet
13157
+ });
13158
+ var _default3 = core2.extend({
13159
+ implicit: [
13160
+ timestamp,
13161
+ merge2
13162
+ ],
13163
+ explicit: [
13164
+ binary,
13165
+ omap,
13166
+ pairs,
13167
+ set2
13168
+ ]
13169
+ });
13170
+ var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
13171
+ var CONTEXT_FLOW_IN = 1;
13172
+ var CONTEXT_FLOW_OUT = 2;
13173
+ var CONTEXT_BLOCK_IN = 3;
13174
+ var CONTEXT_BLOCK_OUT = 4;
13175
+ var CHOMPING_CLIP = 1;
13176
+ var CHOMPING_STRIP = 2;
13177
+ var CHOMPING_KEEP = 3;
13178
+ var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
13179
+ var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
13180
+ var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
13181
+ var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
13182
+ var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
13183
+ function _class(obj) {
13184
+ return Object.prototype.toString.call(obj);
13185
+ }
13186
+ function is_EOL(c) {
13187
+ return c === 10 || c === 13;
13188
+ }
13189
+ function is_WHITE_SPACE(c) {
13190
+ return c === 9 || c === 32;
13191
+ }
13192
+ function is_WS_OR_EOL(c) {
13193
+ return c === 9 || c === 32 || c === 10 || c === 13;
13194
+ }
13195
+ function is_FLOW_INDICATOR(c) {
13196
+ return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
13197
+ }
13198
+ function fromHexCode(c) {
13199
+ var lc;
13200
+ if (48 <= c && c <= 57) {
13201
+ return c - 48;
13202
+ }
13203
+ lc = c | 32;
13204
+ if (97 <= lc && lc <= 102) {
13205
+ return lc - 97 + 10;
13206
+ }
13207
+ return -1;
13208
+ }
13209
+ function escapedHexLen(c) {
13210
+ if (c === 120) {
13211
+ return 2;
13212
+ }
13213
+ if (c === 117) {
13214
+ return 4;
13215
+ }
13216
+ if (c === 85) {
13217
+ return 8;
13218
+ }
13219
+ return 0;
13220
+ }
13221
+ function fromDecimalCode(c) {
13222
+ if (48 <= c && c <= 57) {
13223
+ return c - 48;
13224
+ }
13225
+ return -1;
13226
+ }
13227
+ function simpleEscapeSequence(c) {
13228
+ return c === 48 ? "\x00" : c === 97 ? "\x07" : c === 98 ? "\b" : c === 116 ? "\t" : c === 9 ? "\t" : c === 110 ? `
13229
+ ` : c === 118 ? "\v" : c === 102 ? "\f" : c === 114 ? "\r" : c === 101 ? "\x1B" : c === 32 ? " " : c === 34 ? '"' : c === 47 ? "/" : c === 92 ? "\\" : c === 78 ? "…" : c === 95 ? " " : c === 76 ? "\u2028" : c === 80 ? "\u2029" : "";
13230
+ }
13231
+ function charFromCodepoint(c) {
13232
+ if (c <= 65535) {
13233
+ return String.fromCharCode(c);
13234
+ }
13235
+ return String.fromCharCode((c - 65536 >> 10) + 55296, (c - 65536 & 1023) + 56320);
13236
+ }
13237
+ function setProperty(object2, key, value) {
13238
+ if (key === "__proto__") {
13239
+ Object.defineProperty(object2, key, {
13240
+ configurable: true,
13241
+ enumerable: true,
13242
+ writable: true,
13243
+ value
13244
+ });
13245
+ } else {
13246
+ object2[key] = value;
13247
+ }
13248
+ }
13249
+ var simpleEscapeCheck = new Array(256);
13250
+ var simpleEscapeMap = new Array(256);
13251
+ for (i = 0;i < 256; i++) {
13252
+ simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
13253
+ simpleEscapeMap[i] = simpleEscapeSequence(i);
13254
+ }
13255
+ var i;
13256
+ function State$1(input, options) {
13257
+ this.input = input;
13258
+ this.filename = options["filename"] || null;
13259
+ this.schema = options["schema"] || _default3;
13260
+ this.onWarning = options["onWarning"] || null;
13261
+ this.legacy = options["legacy"] || false;
13262
+ this.json = options["json"] || false;
13263
+ this.listener = options["listener"] || null;
13264
+ this.implicitTypes = this.schema.compiledImplicit;
13265
+ this.typeMap = this.schema.compiledTypeMap;
13266
+ this.length = input.length;
13267
+ this.position = 0;
13268
+ this.line = 0;
13269
+ this.lineStart = 0;
13270
+ this.lineIndent = 0;
13271
+ this.firstTabInLine = -1;
13272
+ this.documents = [];
13273
+ }
13274
+ function generateError(state, message) {
13275
+ var mark = {
13276
+ name: state.filename,
13277
+ buffer: state.input.slice(0, -1),
13278
+ position: state.position,
13279
+ line: state.line,
13280
+ column: state.position - state.lineStart
13281
+ };
13282
+ mark.snippet = snippet(mark);
13283
+ return new exception(message, mark);
13284
+ }
13285
+ function throwError(state, message) {
13286
+ throw generateError(state, message);
13287
+ }
13288
+ function throwWarning(state, message) {
13289
+ if (state.onWarning) {
13290
+ state.onWarning.call(null, generateError(state, message));
13291
+ }
13292
+ }
13293
+ var directiveHandlers = {
13294
+ YAML: function handleYamlDirective(state, name, args) {
13295
+ var match, major, minor;
13296
+ if (state.version !== null) {
13297
+ throwError(state, "duplication of %YAML directive");
13298
+ }
13299
+ if (args.length !== 1) {
13300
+ throwError(state, "YAML directive accepts exactly one argument");
13301
+ }
13302
+ match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
13303
+ if (match === null) {
13304
+ throwError(state, "ill-formed argument of the YAML directive");
13305
+ }
13306
+ major = parseInt(match[1], 10);
13307
+ minor = parseInt(match[2], 10);
13308
+ if (major !== 1) {
13309
+ throwError(state, "unacceptable YAML version of the document");
13310
+ }
13311
+ state.version = args[0];
13312
+ state.checkLineBreaks = minor < 2;
13313
+ if (minor !== 1 && minor !== 2) {
13314
+ throwWarning(state, "unsupported YAML version of the document");
13315
+ }
13316
+ },
13317
+ TAG: function handleTagDirective(state, name, args) {
13318
+ var handle, prefix;
13319
+ if (args.length !== 2) {
13320
+ throwError(state, "TAG directive accepts exactly two arguments");
13321
+ }
13322
+ handle = args[0];
13323
+ prefix = args[1];
13324
+ if (!PATTERN_TAG_HANDLE.test(handle)) {
13325
+ throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
13326
+ }
13327
+ if (_hasOwnProperty$1.call(state.tagMap, handle)) {
13328
+ throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
13329
+ }
13330
+ if (!PATTERN_TAG_URI.test(prefix)) {
13331
+ throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
13332
+ }
13333
+ try {
13334
+ prefix = decodeURIComponent(prefix);
13335
+ } catch (err) {
13336
+ throwError(state, "tag prefix is malformed: " + prefix);
13337
+ }
13338
+ state.tagMap[handle] = prefix;
13339
+ }
13340
+ };
13341
+ function captureSegment(state, start, end, checkJson) {
13342
+ var _position, _length2, _character, _result;
13343
+ if (start < end) {
13344
+ _result = state.input.slice(start, end);
13345
+ if (checkJson) {
13346
+ for (_position = 0, _length2 = _result.length;_position < _length2; _position += 1) {
13347
+ _character = _result.charCodeAt(_position);
13348
+ if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
13349
+ throwError(state, "expected valid JSON character");
13350
+ }
13351
+ }
13352
+ } else if (PATTERN_NON_PRINTABLE.test(_result)) {
13353
+ throwError(state, "the stream contains non-printable characters");
13354
+ }
13355
+ state.result += _result;
13356
+ }
13357
+ }
13358
+ function mergeMappings(state, destination, source, overridableKeys) {
13359
+ var sourceKeys, key, index, quantity;
13360
+ if (!common.isObject(source)) {
13361
+ throwError(state, "cannot merge mappings; the provided source object is unacceptable");
13362
+ }
13363
+ sourceKeys = Object.keys(source);
13364
+ for (index = 0, quantity = sourceKeys.length;index < quantity; index += 1) {
13365
+ key = sourceKeys[index];
13366
+ if (!_hasOwnProperty$1.call(destination, key)) {
13367
+ setProperty(destination, key, source[key]);
13368
+ overridableKeys[key] = true;
13369
+ }
13370
+ }
13371
+ }
13372
+ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) {
13373
+ var index, quantity;
13374
+ if (Array.isArray(keyNode)) {
13375
+ keyNode = Array.prototype.slice.call(keyNode);
13376
+ for (index = 0, quantity = keyNode.length;index < quantity; index += 1) {
13377
+ if (Array.isArray(keyNode[index])) {
13378
+ throwError(state, "nested arrays are not supported inside keys");
13379
+ }
13380
+ if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
13381
+ keyNode[index] = "[object Object]";
13382
+ }
13383
+ }
13384
+ }
13385
+ if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
13386
+ keyNode = "[object Object]";
13387
+ }
13388
+ keyNode = String(keyNode);
13389
+ if (_result === null) {
13390
+ _result = {};
13391
+ }
13392
+ if (keyTag === "tag:yaml.org,2002:merge") {
13393
+ if (Array.isArray(valueNode)) {
13394
+ for (index = 0, quantity = valueNode.length;index < quantity; index += 1) {
13395
+ mergeMappings(state, _result, valueNode[index], overridableKeys);
13396
+ }
13397
+ } else {
13398
+ mergeMappings(state, _result, valueNode, overridableKeys);
13399
+ }
13400
+ } else {
13401
+ if (!state.json && !_hasOwnProperty$1.call(overridableKeys, keyNode) && _hasOwnProperty$1.call(_result, keyNode)) {
13402
+ state.line = startLine || state.line;
13403
+ state.lineStart = startLineStart || state.lineStart;
13404
+ state.position = startPos || state.position;
13405
+ throwError(state, "duplicated mapping key");
13406
+ }
13407
+ setProperty(_result, keyNode, valueNode);
13408
+ delete overridableKeys[keyNode];
13409
+ }
13410
+ return _result;
13411
+ }
13412
+ function readLineBreak(state) {
13413
+ var ch;
13414
+ ch = state.input.charCodeAt(state.position);
13415
+ if (ch === 10) {
13416
+ state.position++;
13417
+ } else if (ch === 13) {
13418
+ state.position++;
13419
+ if (state.input.charCodeAt(state.position) === 10) {
13420
+ state.position++;
13421
+ }
13422
+ } else {
13423
+ throwError(state, "a line break is expected");
13424
+ }
13425
+ state.line += 1;
13426
+ state.lineStart = state.position;
13427
+ state.firstTabInLine = -1;
13428
+ }
13429
+ function skipSeparationSpace(state, allowComments, checkIndent) {
13430
+ var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
13431
+ while (ch !== 0) {
13432
+ while (is_WHITE_SPACE(ch)) {
13433
+ if (ch === 9 && state.firstTabInLine === -1) {
13434
+ state.firstTabInLine = state.position;
13435
+ }
13436
+ ch = state.input.charCodeAt(++state.position);
13437
+ }
13438
+ if (allowComments && ch === 35) {
13439
+ do {
13440
+ ch = state.input.charCodeAt(++state.position);
13441
+ } while (ch !== 10 && ch !== 13 && ch !== 0);
13442
+ }
13443
+ if (is_EOL(ch)) {
13444
+ readLineBreak(state);
13445
+ ch = state.input.charCodeAt(state.position);
13446
+ lineBreaks++;
13447
+ state.lineIndent = 0;
13448
+ while (ch === 32) {
13449
+ state.lineIndent++;
13450
+ ch = state.input.charCodeAt(++state.position);
13451
+ }
13452
+ } else {
13453
+ break;
13454
+ }
13455
+ }
13456
+ if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
13457
+ throwWarning(state, "deficient indentation");
13458
+ }
13459
+ return lineBreaks;
13460
+ }
13461
+ function testDocumentSeparator(state) {
13462
+ var _position = state.position, ch;
13463
+ ch = state.input.charCodeAt(_position);
13464
+ if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
13465
+ _position += 3;
13466
+ ch = state.input.charCodeAt(_position);
13467
+ if (ch === 0 || is_WS_OR_EOL(ch)) {
13468
+ return true;
13469
+ }
13470
+ }
13471
+ return false;
13472
+ }
13473
+ function writeFoldedLines(state, count) {
13474
+ if (count === 1) {
13475
+ state.result += " ";
13476
+ } else if (count > 1) {
13477
+ state.result += common.repeat(`
13478
+ `, count - 1);
13479
+ }
13480
+ }
13481
+ function readPlainScalar(state, nodeIndent, withinFlowCollection) {
13482
+ var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
13483
+ ch = state.input.charCodeAt(state.position);
13484
+ if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96) {
13485
+ return false;
13486
+ }
13487
+ if (ch === 63 || ch === 45) {
13488
+ following = state.input.charCodeAt(state.position + 1);
13489
+ if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
13490
+ return false;
13491
+ }
13492
+ }
13493
+ state.kind = "scalar";
13494
+ state.result = "";
13495
+ captureStart = captureEnd = state.position;
13496
+ hasPendingContent = false;
13497
+ while (ch !== 0) {
13498
+ if (ch === 58) {
13499
+ following = state.input.charCodeAt(state.position + 1);
13500
+ if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
13501
+ break;
13502
+ }
13503
+ } else if (ch === 35) {
13504
+ preceding = state.input.charCodeAt(state.position - 1);
13505
+ if (is_WS_OR_EOL(preceding)) {
13506
+ break;
13507
+ }
13508
+ } else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
13509
+ break;
13510
+ } else if (is_EOL(ch)) {
13511
+ _line = state.line;
13512
+ _lineStart = state.lineStart;
13513
+ _lineIndent = state.lineIndent;
13514
+ skipSeparationSpace(state, false, -1);
13515
+ if (state.lineIndent >= nodeIndent) {
13516
+ hasPendingContent = true;
13517
+ ch = state.input.charCodeAt(state.position);
13518
+ continue;
13519
+ } else {
13520
+ state.position = captureEnd;
13521
+ state.line = _line;
13522
+ state.lineStart = _lineStart;
13523
+ state.lineIndent = _lineIndent;
13524
+ break;
13525
+ }
13526
+ }
13527
+ if (hasPendingContent) {
13528
+ captureSegment(state, captureStart, captureEnd, false);
13529
+ writeFoldedLines(state, state.line - _line);
13530
+ captureStart = captureEnd = state.position;
13531
+ hasPendingContent = false;
13532
+ }
13533
+ if (!is_WHITE_SPACE(ch)) {
13534
+ captureEnd = state.position + 1;
13535
+ }
13536
+ ch = state.input.charCodeAt(++state.position);
13537
+ }
13538
+ captureSegment(state, captureStart, captureEnd, false);
13539
+ if (state.result) {
13540
+ return true;
13541
+ }
13542
+ state.kind = _kind;
13543
+ state.result = _result;
13544
+ return false;
13545
+ }
13546
+ function readSingleQuotedScalar(state, nodeIndent) {
13547
+ var ch, captureStart, captureEnd;
13548
+ ch = state.input.charCodeAt(state.position);
13549
+ if (ch !== 39) {
13550
+ return false;
13551
+ }
13552
+ state.kind = "scalar";
13553
+ state.result = "";
13554
+ state.position++;
13555
+ captureStart = captureEnd = state.position;
13556
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
13557
+ if (ch === 39) {
13558
+ captureSegment(state, captureStart, state.position, true);
13559
+ ch = state.input.charCodeAt(++state.position);
13560
+ if (ch === 39) {
13561
+ captureStart = state.position;
13562
+ state.position++;
13563
+ captureEnd = state.position;
13564
+ } else {
13565
+ return true;
13566
+ }
13567
+ } else if (is_EOL(ch)) {
13568
+ captureSegment(state, captureStart, captureEnd, true);
13569
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
13570
+ captureStart = captureEnd = state.position;
13571
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
13572
+ throwError(state, "unexpected end of the document within a single quoted scalar");
13573
+ } else {
13574
+ state.position++;
13575
+ captureEnd = state.position;
13576
+ }
13577
+ }
13578
+ throwError(state, "unexpected end of the stream within a single quoted scalar");
13579
+ }
13580
+ function readDoubleQuotedScalar(state, nodeIndent) {
13581
+ var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
13582
+ ch = state.input.charCodeAt(state.position);
13583
+ if (ch !== 34) {
13584
+ return false;
13585
+ }
13586
+ state.kind = "scalar";
13587
+ state.result = "";
13588
+ state.position++;
13589
+ captureStart = captureEnd = state.position;
13590
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
13591
+ if (ch === 34) {
13592
+ captureSegment(state, captureStart, state.position, true);
13593
+ state.position++;
13594
+ return true;
13595
+ } else if (ch === 92) {
13596
+ captureSegment(state, captureStart, state.position, true);
13597
+ ch = state.input.charCodeAt(++state.position);
13598
+ if (is_EOL(ch)) {
13599
+ skipSeparationSpace(state, false, nodeIndent);
13600
+ } else if (ch < 256 && simpleEscapeCheck[ch]) {
13601
+ state.result += simpleEscapeMap[ch];
13602
+ state.position++;
13603
+ } else if ((tmp = escapedHexLen(ch)) > 0) {
13604
+ hexLength = tmp;
13605
+ hexResult = 0;
13606
+ for (;hexLength > 0; hexLength--) {
13607
+ ch = state.input.charCodeAt(++state.position);
13608
+ if ((tmp = fromHexCode(ch)) >= 0) {
13609
+ hexResult = (hexResult << 4) + tmp;
13610
+ } else {
13611
+ throwError(state, "expected hexadecimal character");
13612
+ }
13613
+ }
13614
+ state.result += charFromCodepoint(hexResult);
13615
+ state.position++;
13616
+ } else {
13617
+ throwError(state, "unknown escape sequence");
13618
+ }
13619
+ captureStart = captureEnd = state.position;
13620
+ } else if (is_EOL(ch)) {
13621
+ captureSegment(state, captureStart, captureEnd, true);
13622
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
13623
+ captureStart = captureEnd = state.position;
13624
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
13625
+ throwError(state, "unexpected end of the document within a double quoted scalar");
13626
+ } else {
13627
+ state.position++;
13628
+ captureEnd = state.position;
13629
+ }
13630
+ }
13631
+ throwError(state, "unexpected end of the stream within a double quoted scalar");
13632
+ }
13633
+ function readFlowCollection(state, nodeIndent) {
13634
+ var readNext = true, _line, _lineStart, _pos, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = Object.create(null), keyNode, keyTag, valueNode, ch;
13635
+ ch = state.input.charCodeAt(state.position);
13636
+ if (ch === 91) {
13637
+ terminator = 93;
13638
+ isMapping = false;
13639
+ _result = [];
13640
+ } else if (ch === 123) {
13641
+ terminator = 125;
13642
+ isMapping = true;
13643
+ _result = {};
13644
+ } else {
13645
+ return false;
13646
+ }
13647
+ if (state.anchor !== null) {
13648
+ state.anchorMap[state.anchor] = _result;
13649
+ }
13650
+ ch = state.input.charCodeAt(++state.position);
13651
+ while (ch !== 0) {
13652
+ skipSeparationSpace(state, true, nodeIndent);
13653
+ ch = state.input.charCodeAt(state.position);
13654
+ if (ch === terminator) {
13655
+ state.position++;
13656
+ state.tag = _tag;
13657
+ state.anchor = _anchor;
13658
+ state.kind = isMapping ? "mapping" : "sequence";
13659
+ state.result = _result;
13660
+ return true;
13661
+ } else if (!readNext) {
13662
+ throwError(state, "missed comma between flow collection entries");
13663
+ } else if (ch === 44) {
13664
+ throwError(state, "expected the node content, but found ','");
13665
+ }
13666
+ keyTag = keyNode = valueNode = null;
13667
+ isPair = isExplicitPair = false;
13668
+ if (ch === 63) {
13669
+ following = state.input.charCodeAt(state.position + 1);
13670
+ if (is_WS_OR_EOL(following)) {
13671
+ isPair = isExplicitPair = true;
13672
+ state.position++;
13673
+ skipSeparationSpace(state, true, nodeIndent);
13674
+ }
13675
+ }
13676
+ _line = state.line;
13677
+ _lineStart = state.lineStart;
13678
+ _pos = state.position;
13679
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
13680
+ keyTag = state.tag;
13681
+ keyNode = state.result;
13682
+ skipSeparationSpace(state, true, nodeIndent);
13683
+ ch = state.input.charCodeAt(state.position);
13684
+ if ((isExplicitPair || state.line === _line) && ch === 58) {
13685
+ isPair = true;
13686
+ ch = state.input.charCodeAt(++state.position);
13687
+ skipSeparationSpace(state, true, nodeIndent);
13688
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
13689
+ valueNode = state.result;
13690
+ }
13691
+ if (isMapping) {
13692
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
13693
+ } else if (isPair) {
13694
+ _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
13695
+ } else {
13696
+ _result.push(keyNode);
13697
+ }
13698
+ skipSeparationSpace(state, true, nodeIndent);
13699
+ ch = state.input.charCodeAt(state.position);
13700
+ if (ch === 44) {
13701
+ readNext = true;
13702
+ ch = state.input.charCodeAt(++state.position);
13703
+ } else {
13704
+ readNext = false;
13705
+ }
13706
+ }
13707
+ throwError(state, "unexpected end of the stream within a flow collection");
13708
+ }
13709
+ function readBlockScalar(state, nodeIndent) {
13710
+ var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
13711
+ ch = state.input.charCodeAt(state.position);
13712
+ if (ch === 124) {
13713
+ folding = false;
13714
+ } else if (ch === 62) {
13715
+ folding = true;
13716
+ } else {
13717
+ return false;
13718
+ }
13719
+ state.kind = "scalar";
13720
+ state.result = "";
13721
+ while (ch !== 0) {
13722
+ ch = state.input.charCodeAt(++state.position);
13723
+ if (ch === 43 || ch === 45) {
13724
+ if (CHOMPING_CLIP === chomping) {
13725
+ chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
13726
+ } else {
13727
+ throwError(state, "repeat of a chomping mode identifier");
13728
+ }
13729
+ } else if ((tmp = fromDecimalCode(ch)) >= 0) {
13730
+ if (tmp === 0) {
13731
+ throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
13732
+ } else if (!detectedIndent) {
13733
+ textIndent = nodeIndent + tmp - 1;
13734
+ detectedIndent = true;
13735
+ } else {
13736
+ throwError(state, "repeat of an indentation width identifier");
13737
+ }
13738
+ } else {
13739
+ break;
13740
+ }
13741
+ }
13742
+ if (is_WHITE_SPACE(ch)) {
13743
+ do {
13744
+ ch = state.input.charCodeAt(++state.position);
13745
+ } while (is_WHITE_SPACE(ch));
13746
+ if (ch === 35) {
13747
+ do {
13748
+ ch = state.input.charCodeAt(++state.position);
13749
+ } while (!is_EOL(ch) && ch !== 0);
13750
+ }
13751
+ }
13752
+ while (ch !== 0) {
13753
+ readLineBreak(state);
13754
+ state.lineIndent = 0;
13755
+ ch = state.input.charCodeAt(state.position);
13756
+ while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
13757
+ state.lineIndent++;
13758
+ ch = state.input.charCodeAt(++state.position);
13759
+ }
13760
+ if (!detectedIndent && state.lineIndent > textIndent) {
13761
+ textIndent = state.lineIndent;
13762
+ }
13763
+ if (is_EOL(ch)) {
13764
+ emptyLines++;
13765
+ continue;
13766
+ }
13767
+ if (state.lineIndent < textIndent) {
13768
+ if (chomping === CHOMPING_KEEP) {
13769
+ state.result += common.repeat(`
13770
+ `, didReadContent ? 1 + emptyLines : emptyLines);
13771
+ } else if (chomping === CHOMPING_CLIP) {
13772
+ if (didReadContent) {
13773
+ state.result += `
13774
+ `;
13775
+ }
13776
+ }
13777
+ break;
13778
+ }
13779
+ if (folding) {
13780
+ if (is_WHITE_SPACE(ch)) {
13781
+ atMoreIndented = true;
13782
+ state.result += common.repeat(`
13783
+ `, didReadContent ? 1 + emptyLines : emptyLines);
13784
+ } else if (atMoreIndented) {
13785
+ atMoreIndented = false;
13786
+ state.result += common.repeat(`
13787
+ `, emptyLines + 1);
13788
+ } else if (emptyLines === 0) {
13789
+ if (didReadContent) {
13790
+ state.result += " ";
13791
+ }
13792
+ } else {
13793
+ state.result += common.repeat(`
13794
+ `, emptyLines);
13795
+ }
13796
+ } else {
13797
+ state.result += common.repeat(`
13798
+ `, didReadContent ? 1 + emptyLines : emptyLines);
13799
+ }
13800
+ didReadContent = true;
13801
+ detectedIndent = true;
13802
+ emptyLines = 0;
13803
+ captureStart = state.position;
13804
+ while (!is_EOL(ch) && ch !== 0) {
13805
+ ch = state.input.charCodeAt(++state.position);
13806
+ }
13807
+ captureSegment(state, captureStart, state.position, false);
13808
+ }
13809
+ return true;
13810
+ }
13811
+ function readBlockSequence(state, nodeIndent) {
13812
+ var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
13813
+ if (state.firstTabInLine !== -1)
13814
+ return false;
13815
+ if (state.anchor !== null) {
13816
+ state.anchorMap[state.anchor] = _result;
13817
+ }
13818
+ ch = state.input.charCodeAt(state.position);
13819
+ while (ch !== 0) {
13820
+ if (state.firstTabInLine !== -1) {
13821
+ state.position = state.firstTabInLine;
13822
+ throwError(state, "tab characters must not be used in indentation");
13823
+ }
13824
+ if (ch !== 45) {
13825
+ break;
13826
+ }
13827
+ following = state.input.charCodeAt(state.position + 1);
13828
+ if (!is_WS_OR_EOL(following)) {
13829
+ break;
13830
+ }
13831
+ detected = true;
13832
+ state.position++;
13833
+ if (skipSeparationSpace(state, true, -1)) {
13834
+ if (state.lineIndent <= nodeIndent) {
13835
+ _result.push(null);
13836
+ ch = state.input.charCodeAt(state.position);
13837
+ continue;
13838
+ }
13839
+ }
13840
+ _line = state.line;
13841
+ composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
13842
+ _result.push(state.result);
13843
+ skipSeparationSpace(state, true, -1);
13844
+ ch = state.input.charCodeAt(state.position);
13845
+ if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
13846
+ throwError(state, "bad indentation of a sequence entry");
13847
+ } else if (state.lineIndent < nodeIndent) {
13848
+ break;
13849
+ }
13850
+ }
13851
+ if (detected) {
13852
+ state.tag = _tag;
13853
+ state.anchor = _anchor;
13854
+ state.kind = "sequence";
13855
+ state.result = _result;
13856
+ return true;
13857
+ }
13858
+ return false;
13859
+ }
13860
+ function readBlockMapping(state, nodeIndent, flowIndent) {
13861
+ var following, allowCompact, _line, _keyLine, _keyLineStart, _keyPos, _tag = state.tag, _anchor = state.anchor, _result = {}, overridableKeys = Object.create(null), keyTag = null, keyNode = null, valueNode = null, atExplicitKey = false, detected = false, ch;
13862
+ if (state.firstTabInLine !== -1)
13863
+ return false;
13864
+ if (state.anchor !== null) {
13865
+ state.anchorMap[state.anchor] = _result;
13866
+ }
13867
+ ch = state.input.charCodeAt(state.position);
13868
+ while (ch !== 0) {
13869
+ if (!atExplicitKey && state.firstTabInLine !== -1) {
13870
+ state.position = state.firstTabInLine;
13871
+ throwError(state, "tab characters must not be used in indentation");
13872
+ }
13873
+ following = state.input.charCodeAt(state.position + 1);
13874
+ _line = state.line;
13875
+ if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
13876
+ if (ch === 63) {
13877
+ if (atExplicitKey) {
13878
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
13879
+ keyTag = keyNode = valueNode = null;
13880
+ }
13881
+ detected = true;
13882
+ atExplicitKey = true;
13883
+ allowCompact = true;
13884
+ } else if (atExplicitKey) {
13885
+ atExplicitKey = false;
13886
+ allowCompact = true;
13887
+ } else {
13888
+ throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
13889
+ }
13890
+ state.position += 1;
13891
+ ch = following;
13892
+ } else {
13893
+ _keyLine = state.line;
13894
+ _keyLineStart = state.lineStart;
13895
+ _keyPos = state.position;
13896
+ if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
13897
+ break;
13898
+ }
13899
+ if (state.line === _line) {
13900
+ ch = state.input.charCodeAt(state.position);
13901
+ while (is_WHITE_SPACE(ch)) {
13902
+ ch = state.input.charCodeAt(++state.position);
13903
+ }
13904
+ if (ch === 58) {
13905
+ ch = state.input.charCodeAt(++state.position);
13906
+ if (!is_WS_OR_EOL(ch)) {
13907
+ throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
13908
+ }
13909
+ if (atExplicitKey) {
13910
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
13911
+ keyTag = keyNode = valueNode = null;
13912
+ }
13913
+ detected = true;
13914
+ atExplicitKey = false;
13915
+ allowCompact = false;
13916
+ keyTag = state.tag;
13917
+ keyNode = state.result;
13918
+ } else if (detected) {
13919
+ throwError(state, "can not read an implicit mapping pair; a colon is missed");
13920
+ } else {
13921
+ state.tag = _tag;
13922
+ state.anchor = _anchor;
13923
+ return true;
13924
+ }
13925
+ } else if (detected) {
13926
+ throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
13927
+ } else {
13928
+ state.tag = _tag;
13929
+ state.anchor = _anchor;
13930
+ return true;
13931
+ }
13932
+ }
13933
+ if (state.line === _line || state.lineIndent > nodeIndent) {
13934
+ if (atExplicitKey) {
13935
+ _keyLine = state.line;
13936
+ _keyLineStart = state.lineStart;
13937
+ _keyPos = state.position;
13938
+ }
13939
+ if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
13940
+ if (atExplicitKey) {
13941
+ keyNode = state.result;
13942
+ } else {
13943
+ valueNode = state.result;
13944
+ }
13945
+ }
13946
+ if (!atExplicitKey) {
13947
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
13948
+ keyTag = keyNode = valueNode = null;
13949
+ }
13950
+ skipSeparationSpace(state, true, -1);
13951
+ ch = state.input.charCodeAt(state.position);
13952
+ }
13953
+ if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
13954
+ throwError(state, "bad indentation of a mapping entry");
13955
+ } else if (state.lineIndent < nodeIndent) {
13956
+ break;
13957
+ }
13958
+ }
13959
+ if (atExplicitKey) {
13960
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
13961
+ }
13962
+ if (detected) {
13963
+ state.tag = _tag;
13964
+ state.anchor = _anchor;
13965
+ state.kind = "mapping";
13966
+ state.result = _result;
13967
+ }
13968
+ return detected;
13969
+ }
13970
+ function readTagProperty(state) {
13971
+ var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
13972
+ ch = state.input.charCodeAt(state.position);
13973
+ if (ch !== 33)
13974
+ return false;
13975
+ if (state.tag !== null) {
13976
+ throwError(state, "duplication of a tag property");
13977
+ }
13978
+ ch = state.input.charCodeAt(++state.position);
13979
+ if (ch === 60) {
13980
+ isVerbatim = true;
13981
+ ch = state.input.charCodeAt(++state.position);
13982
+ } else if (ch === 33) {
13983
+ isNamed = true;
13984
+ tagHandle = "!!";
13985
+ ch = state.input.charCodeAt(++state.position);
13986
+ } else {
13987
+ tagHandle = "!";
13988
+ }
13989
+ _position = state.position;
13990
+ if (isVerbatim) {
13991
+ do {
13992
+ ch = state.input.charCodeAt(++state.position);
13993
+ } while (ch !== 0 && ch !== 62);
13994
+ if (state.position < state.length) {
13995
+ tagName = state.input.slice(_position, state.position);
13996
+ ch = state.input.charCodeAt(++state.position);
13997
+ } else {
13998
+ throwError(state, "unexpected end of the stream within a verbatim tag");
13999
+ }
14000
+ } else {
14001
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
14002
+ if (ch === 33) {
14003
+ if (!isNamed) {
14004
+ tagHandle = state.input.slice(_position - 1, state.position + 1);
14005
+ if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
14006
+ throwError(state, "named tag handle cannot contain such characters");
14007
+ }
14008
+ isNamed = true;
14009
+ _position = state.position + 1;
14010
+ } else {
14011
+ throwError(state, "tag suffix cannot contain exclamation marks");
14012
+ }
14013
+ }
14014
+ ch = state.input.charCodeAt(++state.position);
14015
+ }
14016
+ tagName = state.input.slice(_position, state.position);
14017
+ if (PATTERN_FLOW_INDICATORS.test(tagName)) {
14018
+ throwError(state, "tag suffix cannot contain flow indicator characters");
14019
+ }
14020
+ }
14021
+ if (tagName && !PATTERN_TAG_URI.test(tagName)) {
14022
+ throwError(state, "tag name cannot contain such characters: " + tagName);
14023
+ }
14024
+ try {
14025
+ tagName = decodeURIComponent(tagName);
14026
+ } catch (err) {
14027
+ throwError(state, "tag name is malformed: " + tagName);
14028
+ }
14029
+ if (isVerbatim) {
14030
+ state.tag = tagName;
14031
+ } else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
14032
+ state.tag = state.tagMap[tagHandle] + tagName;
14033
+ } else if (tagHandle === "!") {
14034
+ state.tag = "!" + tagName;
14035
+ } else if (tagHandle === "!!") {
14036
+ state.tag = "tag:yaml.org,2002:" + tagName;
14037
+ } else {
14038
+ throwError(state, 'undeclared tag handle "' + tagHandle + '"');
14039
+ }
14040
+ return true;
14041
+ }
14042
+ function readAnchorProperty(state) {
14043
+ var _position, ch;
14044
+ ch = state.input.charCodeAt(state.position);
14045
+ if (ch !== 38)
14046
+ return false;
14047
+ if (state.anchor !== null) {
14048
+ throwError(state, "duplication of an anchor property");
14049
+ }
14050
+ ch = state.input.charCodeAt(++state.position);
14051
+ _position = state.position;
14052
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
14053
+ ch = state.input.charCodeAt(++state.position);
14054
+ }
14055
+ if (state.position === _position) {
14056
+ throwError(state, "name of an anchor node must contain at least one character");
14057
+ }
14058
+ state.anchor = state.input.slice(_position, state.position);
14059
+ return true;
14060
+ }
14061
+ function readAlias(state) {
14062
+ var _position, alias, ch;
14063
+ ch = state.input.charCodeAt(state.position);
14064
+ if (ch !== 42)
14065
+ return false;
14066
+ ch = state.input.charCodeAt(++state.position);
14067
+ _position = state.position;
14068
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
14069
+ ch = state.input.charCodeAt(++state.position);
14070
+ }
14071
+ if (state.position === _position) {
14072
+ throwError(state, "name of an alias node must contain at least one character");
14073
+ }
14074
+ alias = state.input.slice(_position, state.position);
14075
+ if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
14076
+ throwError(state, 'unidentified alias "' + alias + '"');
14077
+ }
14078
+ state.result = state.anchorMap[alias];
14079
+ skipSeparationSpace(state, true, -1);
14080
+ return true;
14081
+ }
14082
+ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
14083
+ var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type2, flowIndent, blockIndent;
14084
+ if (state.listener !== null) {
14085
+ state.listener("open", state);
14086
+ }
14087
+ state.tag = null;
14088
+ state.anchor = null;
14089
+ state.kind = null;
14090
+ state.result = null;
14091
+ allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
14092
+ if (allowToSeek) {
14093
+ if (skipSeparationSpace(state, true, -1)) {
14094
+ atNewLine = true;
14095
+ if (state.lineIndent > parentIndent) {
14096
+ indentStatus = 1;
14097
+ } else if (state.lineIndent === parentIndent) {
14098
+ indentStatus = 0;
14099
+ } else if (state.lineIndent < parentIndent) {
14100
+ indentStatus = -1;
14101
+ }
14102
+ }
14103
+ }
14104
+ if (indentStatus === 1) {
14105
+ while (readTagProperty(state) || readAnchorProperty(state)) {
14106
+ if (skipSeparationSpace(state, true, -1)) {
14107
+ atNewLine = true;
14108
+ allowBlockCollections = allowBlockStyles;
14109
+ if (state.lineIndent > parentIndent) {
14110
+ indentStatus = 1;
14111
+ } else if (state.lineIndent === parentIndent) {
14112
+ indentStatus = 0;
14113
+ } else if (state.lineIndent < parentIndent) {
14114
+ indentStatus = -1;
14115
+ }
14116
+ } else {
14117
+ allowBlockCollections = false;
14118
+ }
14119
+ }
14120
+ }
14121
+ if (allowBlockCollections) {
14122
+ allowBlockCollections = atNewLine || allowCompact;
14123
+ }
14124
+ if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
14125
+ if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
14126
+ flowIndent = parentIndent;
14127
+ } else {
14128
+ flowIndent = parentIndent + 1;
14129
+ }
14130
+ blockIndent = state.position - state.lineStart;
14131
+ if (indentStatus === 1) {
14132
+ if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
14133
+ hasContent = true;
14134
+ } else {
14135
+ if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
14136
+ hasContent = true;
14137
+ } else if (readAlias(state)) {
14138
+ hasContent = true;
14139
+ if (state.tag !== null || state.anchor !== null) {
14140
+ throwError(state, "alias node should not have any properties");
14141
+ }
14142
+ } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
14143
+ hasContent = true;
14144
+ if (state.tag === null) {
14145
+ state.tag = "?";
14146
+ }
14147
+ }
14148
+ if (state.anchor !== null) {
14149
+ state.anchorMap[state.anchor] = state.result;
14150
+ }
14151
+ }
14152
+ } else if (indentStatus === 0) {
14153
+ hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
14154
+ }
14155
+ }
14156
+ if (state.tag === null) {
14157
+ if (state.anchor !== null) {
14158
+ state.anchorMap[state.anchor] = state.result;
14159
+ }
14160
+ } else if (state.tag === "?") {
14161
+ if (state.result !== null && state.kind !== "scalar") {
14162
+ throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
14163
+ }
14164
+ for (typeIndex = 0, typeQuantity = state.implicitTypes.length;typeIndex < typeQuantity; typeIndex += 1) {
14165
+ type2 = state.implicitTypes[typeIndex];
14166
+ if (type2.resolve(state.result)) {
14167
+ state.result = type2.construct(state.result);
14168
+ state.tag = type2.tag;
14169
+ if (state.anchor !== null) {
14170
+ state.anchorMap[state.anchor] = state.result;
14171
+ }
14172
+ break;
14173
+ }
14174
+ }
14175
+ } else if (state.tag !== "!") {
14176
+ if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
14177
+ type2 = state.typeMap[state.kind || "fallback"][state.tag];
14178
+ } else {
14179
+ type2 = null;
14180
+ typeList = state.typeMap.multi[state.kind || "fallback"];
14181
+ for (typeIndex = 0, typeQuantity = typeList.length;typeIndex < typeQuantity; typeIndex += 1) {
14182
+ if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
14183
+ type2 = typeList[typeIndex];
14184
+ break;
14185
+ }
14186
+ }
14187
+ }
14188
+ if (!type2) {
14189
+ throwError(state, "unknown tag !<" + state.tag + ">");
14190
+ }
14191
+ if (state.result !== null && type2.kind !== state.kind) {
14192
+ throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"');
14193
+ }
14194
+ if (!type2.resolve(state.result, state.tag)) {
14195
+ throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
14196
+ } else {
14197
+ state.result = type2.construct(state.result, state.tag);
14198
+ if (state.anchor !== null) {
14199
+ state.anchorMap[state.anchor] = state.result;
14200
+ }
14201
+ }
14202
+ }
14203
+ if (state.listener !== null) {
14204
+ state.listener("close", state);
14205
+ }
14206
+ return state.tag !== null || state.anchor !== null || hasContent;
14207
+ }
14208
+ function readDocument(state) {
14209
+ var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
14210
+ state.version = null;
14211
+ state.checkLineBreaks = state.legacy;
14212
+ state.tagMap = Object.create(null);
14213
+ state.anchorMap = Object.create(null);
14214
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
14215
+ skipSeparationSpace(state, true, -1);
14216
+ ch = state.input.charCodeAt(state.position);
14217
+ if (state.lineIndent > 0 || ch !== 37) {
14218
+ break;
14219
+ }
14220
+ hasDirectives = true;
14221
+ ch = state.input.charCodeAt(++state.position);
14222
+ _position = state.position;
14223
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
14224
+ ch = state.input.charCodeAt(++state.position);
14225
+ }
14226
+ directiveName = state.input.slice(_position, state.position);
14227
+ directiveArgs = [];
14228
+ if (directiveName.length < 1) {
14229
+ throwError(state, "directive name must not be less than one character in length");
14230
+ }
14231
+ while (ch !== 0) {
14232
+ while (is_WHITE_SPACE(ch)) {
14233
+ ch = state.input.charCodeAt(++state.position);
14234
+ }
14235
+ if (ch === 35) {
14236
+ do {
14237
+ ch = state.input.charCodeAt(++state.position);
14238
+ } while (ch !== 0 && !is_EOL(ch));
14239
+ break;
14240
+ }
14241
+ if (is_EOL(ch))
14242
+ break;
14243
+ _position = state.position;
14244
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
14245
+ ch = state.input.charCodeAt(++state.position);
14246
+ }
14247
+ directiveArgs.push(state.input.slice(_position, state.position));
14248
+ }
14249
+ if (ch !== 0)
14250
+ readLineBreak(state);
14251
+ if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
14252
+ directiveHandlers[directiveName](state, directiveName, directiveArgs);
14253
+ } else {
14254
+ throwWarning(state, 'unknown document directive "' + directiveName + '"');
14255
+ }
14256
+ }
14257
+ skipSeparationSpace(state, true, -1);
14258
+ if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
14259
+ state.position += 3;
14260
+ skipSeparationSpace(state, true, -1);
14261
+ } else if (hasDirectives) {
14262
+ throwError(state, "directives end mark is expected");
14263
+ }
14264
+ composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
14265
+ skipSeparationSpace(state, true, -1);
14266
+ if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
14267
+ throwWarning(state, "non-ASCII line breaks are interpreted as content");
14268
+ }
14269
+ state.documents.push(state.result);
14270
+ if (state.position === state.lineStart && testDocumentSeparator(state)) {
14271
+ if (state.input.charCodeAt(state.position) === 46) {
14272
+ state.position += 3;
14273
+ skipSeparationSpace(state, true, -1);
14274
+ }
14275
+ return;
14276
+ }
14277
+ if (state.position < state.length - 1) {
14278
+ throwError(state, "end of the stream or a document separator is expected");
14279
+ } else {
14280
+ return;
14281
+ }
14282
+ }
14283
+ function loadDocuments(input, options) {
14284
+ input = String(input);
14285
+ options = options || {};
14286
+ if (input.length !== 0) {
14287
+ if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
14288
+ input += `
14289
+ `;
14290
+ }
14291
+ if (input.charCodeAt(0) === 65279) {
14292
+ input = input.slice(1);
14293
+ }
14294
+ }
14295
+ var state = new State$1(input, options);
14296
+ var nullpos = input.indexOf("\x00");
14297
+ if (nullpos !== -1) {
14298
+ state.position = nullpos;
14299
+ throwError(state, "null byte is not allowed in input");
14300
+ }
14301
+ state.input += "\x00";
14302
+ while (state.input.charCodeAt(state.position) === 32) {
14303
+ state.lineIndent += 1;
14304
+ state.position += 1;
14305
+ }
14306
+ while (state.position < state.length - 1) {
14307
+ readDocument(state);
14308
+ }
14309
+ return state.documents;
14310
+ }
14311
+ function loadAll$1(input, iterator, options) {
14312
+ if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
14313
+ options = iterator;
14314
+ iterator = null;
14315
+ }
14316
+ var documents = loadDocuments(input, options);
14317
+ if (typeof iterator !== "function") {
14318
+ return documents;
14319
+ }
14320
+ for (var index = 0, length = documents.length;index < length; index += 1) {
14321
+ iterator(documents[index]);
14322
+ }
14323
+ }
14324
+ function load$1(input, options) {
14325
+ var documents = loadDocuments(input, options);
14326
+ if (documents.length === 0) {
14327
+ return;
14328
+ } else if (documents.length === 1) {
14329
+ return documents[0];
14330
+ }
14331
+ throw new exception("expected a single document in the stream, but found more");
14332
+ }
14333
+ var loadAll_1 = loadAll$1;
14334
+ var load_1 = load$1;
14335
+ var loader = {
14336
+ loadAll: loadAll_1,
14337
+ load: load_1
14338
+ };
14339
+ var _toString = Object.prototype.toString;
14340
+ var _hasOwnProperty = Object.prototype.hasOwnProperty;
14341
+ var CHAR_BOM = 65279;
14342
+ var CHAR_TAB = 9;
14343
+ var CHAR_LINE_FEED = 10;
14344
+ var CHAR_CARRIAGE_RETURN = 13;
14345
+ var CHAR_SPACE = 32;
14346
+ var CHAR_EXCLAMATION = 33;
14347
+ var CHAR_DOUBLE_QUOTE = 34;
14348
+ var CHAR_SHARP = 35;
14349
+ var CHAR_PERCENT = 37;
14350
+ var CHAR_AMPERSAND = 38;
14351
+ var CHAR_SINGLE_QUOTE = 39;
14352
+ var CHAR_ASTERISK = 42;
14353
+ var CHAR_COMMA = 44;
14354
+ var CHAR_MINUS = 45;
14355
+ var CHAR_COLON = 58;
14356
+ var CHAR_EQUALS = 61;
14357
+ var CHAR_GREATER_THAN = 62;
14358
+ var CHAR_QUESTION = 63;
14359
+ var CHAR_COMMERCIAL_AT = 64;
14360
+ var CHAR_LEFT_SQUARE_BRACKET = 91;
14361
+ var CHAR_RIGHT_SQUARE_BRACKET = 93;
14362
+ var CHAR_GRAVE_ACCENT = 96;
14363
+ var CHAR_LEFT_CURLY_BRACKET = 123;
14364
+ var CHAR_VERTICAL_LINE = 124;
14365
+ var CHAR_RIGHT_CURLY_BRACKET = 125;
14366
+ var ESCAPE_SEQUENCES = {};
14367
+ ESCAPE_SEQUENCES[0] = "\\0";
14368
+ ESCAPE_SEQUENCES[7] = "\\a";
14369
+ ESCAPE_SEQUENCES[8] = "\\b";
14370
+ ESCAPE_SEQUENCES[9] = "\\t";
14371
+ ESCAPE_SEQUENCES[10] = "\\n";
14372
+ ESCAPE_SEQUENCES[11] = "\\v";
14373
+ ESCAPE_SEQUENCES[12] = "\\f";
14374
+ ESCAPE_SEQUENCES[13] = "\\r";
14375
+ ESCAPE_SEQUENCES[27] = "\\e";
14376
+ ESCAPE_SEQUENCES[34] = "\\\"";
14377
+ ESCAPE_SEQUENCES[92] = "\\\\";
14378
+ ESCAPE_SEQUENCES[133] = "\\N";
14379
+ ESCAPE_SEQUENCES[160] = "\\_";
14380
+ ESCAPE_SEQUENCES[8232] = "\\L";
14381
+ ESCAPE_SEQUENCES[8233] = "\\P";
14382
+ var DEPRECATED_BOOLEANS_SYNTAX = [
14383
+ "y",
14384
+ "Y",
14385
+ "yes",
14386
+ "Yes",
14387
+ "YES",
14388
+ "on",
14389
+ "On",
14390
+ "ON",
14391
+ "n",
14392
+ "N",
14393
+ "no",
14394
+ "No",
14395
+ "NO",
14396
+ "off",
14397
+ "Off",
14398
+ "OFF"
14399
+ ];
14400
+ var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
14401
+ function compileStyleMap(schema2, map3) {
14402
+ var result, keys, index, length, tag, style, type2;
14403
+ if (map3 === null)
14404
+ return {};
14405
+ result = {};
14406
+ keys = Object.keys(map3);
14407
+ for (index = 0, length = keys.length;index < length; index += 1) {
14408
+ tag = keys[index];
14409
+ style = String(map3[tag]);
14410
+ if (tag.slice(0, 2) === "!!") {
14411
+ tag = "tag:yaml.org,2002:" + tag.slice(2);
14412
+ }
14413
+ type2 = schema2.compiledTypeMap["fallback"][tag];
14414
+ if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) {
14415
+ style = type2.styleAliases[style];
14416
+ }
14417
+ result[tag] = style;
14418
+ }
14419
+ return result;
14420
+ }
14421
+ function encodeHex(character) {
14422
+ var string4, handle, length;
14423
+ string4 = character.toString(16).toUpperCase();
14424
+ if (character <= 255) {
14425
+ handle = "x";
14426
+ length = 2;
14427
+ } else if (character <= 65535) {
14428
+ handle = "u";
14429
+ length = 4;
14430
+ } else if (character <= 4294967295) {
14431
+ handle = "U";
14432
+ length = 8;
14433
+ } else {
14434
+ throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
14435
+ }
14436
+ return "\\" + handle + common.repeat("0", length - string4.length) + string4;
14437
+ }
14438
+ var QUOTING_TYPE_SINGLE = 1;
14439
+ var QUOTING_TYPE_DOUBLE = 2;
14440
+ function State(options) {
14441
+ this.schema = options["schema"] || _default3;
14442
+ this.indent = Math.max(1, options["indent"] || 2);
14443
+ this.noArrayIndent = options["noArrayIndent"] || false;
14444
+ this.skipInvalid = options["skipInvalid"] || false;
14445
+ this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
14446
+ this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
14447
+ this.sortKeys = options["sortKeys"] || false;
14448
+ this.lineWidth = options["lineWidth"] || 80;
14449
+ this.noRefs = options["noRefs"] || false;
14450
+ this.noCompatMode = options["noCompatMode"] || false;
14451
+ this.condenseFlow = options["condenseFlow"] || false;
14452
+ this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
14453
+ this.forceQuotes = options["forceQuotes"] || false;
14454
+ this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
14455
+ this.implicitTypes = this.schema.compiledImplicit;
14456
+ this.explicitTypes = this.schema.compiledExplicit;
14457
+ this.tag = null;
14458
+ this.result = "";
14459
+ this.duplicates = [];
14460
+ this.usedDuplicates = null;
14461
+ }
14462
+ function indentString(string4, spaces) {
14463
+ var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string4.length;
14464
+ while (position < length) {
14465
+ next = string4.indexOf(`
14466
+ `, position);
14467
+ if (next === -1) {
14468
+ line = string4.slice(position);
14469
+ position = length;
14470
+ } else {
14471
+ line = string4.slice(position, next + 1);
14472
+ position = next + 1;
14473
+ }
14474
+ if (line.length && line !== `
14475
+ `)
14476
+ result += ind;
14477
+ result += line;
14478
+ }
14479
+ return result;
14480
+ }
14481
+ function generateNextLine(state, level) {
14482
+ return `
14483
+ ` + common.repeat(" ", state.indent * level);
14484
+ }
14485
+ function testImplicitResolving(state, str2) {
14486
+ var index, length, type2;
14487
+ for (index = 0, length = state.implicitTypes.length;index < length; index += 1) {
14488
+ type2 = state.implicitTypes[index];
14489
+ if (type2.resolve(str2)) {
14490
+ return true;
14491
+ }
14492
+ }
14493
+ return false;
14494
+ }
14495
+ function isWhitespace(c) {
14496
+ return c === CHAR_SPACE || c === CHAR_TAB;
14497
+ }
14498
+ function isPrintable(c) {
14499
+ return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111;
14500
+ }
14501
+ function isNsCharOrWhitespace(c) {
14502
+ return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
14503
+ }
14504
+ function isPlainSafe(c, prev, inblock) {
14505
+ var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
14506
+ var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
14507
+ return (inblock ? cIsNsCharOrWhitespace : cIsNsCharOrWhitespace && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET) && c !== CHAR_SHARP && !(prev === CHAR_COLON && !cIsNsChar) || isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP || prev === CHAR_COLON && cIsNsChar;
14508
+ }
14509
+ function isPlainSafeFirst(c) {
14510
+ return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
14511
+ }
14512
+ function isPlainSafeLast(c) {
14513
+ return !isWhitespace(c) && c !== CHAR_COLON;
14514
+ }
14515
+ function codePointAt(string4, pos) {
14516
+ var first = string4.charCodeAt(pos), second;
14517
+ if (first >= 55296 && first <= 56319 && pos + 1 < string4.length) {
14518
+ second = string4.charCodeAt(pos + 1);
14519
+ if (second >= 56320 && second <= 57343) {
14520
+ return (first - 55296) * 1024 + second - 56320 + 65536;
14521
+ }
14522
+ }
14523
+ return first;
14524
+ }
14525
+ function needIndentIndicator(string4) {
14526
+ var leadingSpaceRe = /^\n* /;
14527
+ return leadingSpaceRe.test(string4);
14528
+ }
14529
+ var STYLE_PLAIN = 1;
14530
+ var STYLE_SINGLE = 2;
14531
+ var STYLE_LITERAL = 3;
14532
+ var STYLE_FOLDED = 4;
14533
+ var STYLE_DOUBLE = 5;
14534
+ function chooseScalarStyle(string4, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
14535
+ var i2;
14536
+ var char = 0;
14537
+ var prevChar = null;
14538
+ var hasLineBreak = false;
14539
+ var hasFoldableLine = false;
14540
+ var shouldTrackWidth = lineWidth !== -1;
14541
+ var previousLineBreak = -1;
14542
+ var plain = isPlainSafeFirst(codePointAt(string4, 0)) && isPlainSafeLast(codePointAt(string4, string4.length - 1));
14543
+ if (singleLineOnly || forceQuotes) {
14544
+ for (i2 = 0;i2 < string4.length; char >= 65536 ? i2 += 2 : i2++) {
14545
+ char = codePointAt(string4, i2);
14546
+ if (!isPrintable(char)) {
14547
+ return STYLE_DOUBLE;
14548
+ }
14549
+ plain = plain && isPlainSafe(char, prevChar, inblock);
14550
+ prevChar = char;
14551
+ }
14552
+ } else {
14553
+ for (i2 = 0;i2 < string4.length; char >= 65536 ? i2 += 2 : i2++) {
14554
+ char = codePointAt(string4, i2);
14555
+ if (char === CHAR_LINE_FEED) {
14556
+ hasLineBreak = true;
14557
+ if (shouldTrackWidth) {
14558
+ hasFoldableLine = hasFoldableLine || i2 - previousLineBreak - 1 > lineWidth && string4[previousLineBreak + 1] !== " ";
14559
+ previousLineBreak = i2;
14560
+ }
14561
+ } else if (!isPrintable(char)) {
14562
+ return STYLE_DOUBLE;
14563
+ }
14564
+ plain = plain && isPlainSafe(char, prevChar, inblock);
14565
+ prevChar = char;
14566
+ }
14567
+ hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i2 - previousLineBreak - 1 > lineWidth && string4[previousLineBreak + 1] !== " ");
14568
+ }
14569
+ if (!hasLineBreak && !hasFoldableLine) {
14570
+ if (plain && !forceQuotes && !testAmbiguousType(string4)) {
14571
+ return STYLE_PLAIN;
14572
+ }
14573
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
14574
+ }
14575
+ if (indentPerLevel > 9 && needIndentIndicator(string4)) {
14576
+ return STYLE_DOUBLE;
14577
+ }
14578
+ if (!forceQuotes) {
14579
+ return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
14580
+ }
14581
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
14582
+ }
14583
+ function writeScalar(state, string4, level, iskey, inblock) {
14584
+ state.dump = function() {
14585
+ if (string4.length === 0) {
14586
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
14587
+ }
14588
+ if (!state.noCompatMode) {
14589
+ if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string4) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string4)) {
14590
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string4 + '"' : "'" + string4 + "'";
14591
+ }
14592
+ }
14593
+ var indent = state.indent * Math.max(1, level);
14594
+ var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
14595
+ var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
14596
+ function testAmbiguity(string5) {
14597
+ return testImplicitResolving(state, string5);
14598
+ }
14599
+ switch (chooseScalarStyle(string4, singleLineOnly, state.indent, lineWidth, testAmbiguity, state.quotingType, state.forceQuotes && !iskey, inblock)) {
14600
+ case STYLE_PLAIN:
14601
+ return string4;
14602
+ case STYLE_SINGLE:
14603
+ return "'" + string4.replace(/'/g, "''") + "'";
14604
+ case STYLE_LITERAL:
14605
+ return "|" + blockHeader(string4, state.indent) + dropEndingNewline(indentString(string4, indent));
14606
+ case STYLE_FOLDED:
14607
+ return ">" + blockHeader(string4, state.indent) + dropEndingNewline(indentString(foldString(string4, lineWidth), indent));
14608
+ case STYLE_DOUBLE:
14609
+ return '"' + escapeString(string4) + '"';
14610
+ default:
14611
+ throw new exception("impossible error: invalid scalar style");
14612
+ }
14613
+ }();
14614
+ }
14615
+ function blockHeader(string4, indentPerLevel) {
14616
+ var indentIndicator = needIndentIndicator(string4) ? String(indentPerLevel) : "";
14617
+ var clip = string4[string4.length - 1] === `
14618
+ `;
14619
+ var keep = clip && (string4[string4.length - 2] === `
14620
+ ` || string4 === `
14621
+ `);
14622
+ var chomp = keep ? "+" : clip ? "" : "-";
14623
+ return indentIndicator + chomp + `
14624
+ `;
14625
+ }
14626
+ function dropEndingNewline(string4) {
14627
+ return string4[string4.length - 1] === `
14628
+ ` ? string4.slice(0, -1) : string4;
14629
+ }
14630
+ function foldString(string4, width) {
14631
+ var lineRe = /(\n+)([^\n]*)/g;
14632
+ var result = function() {
14633
+ var nextLF = string4.indexOf(`
14634
+ `);
14635
+ nextLF = nextLF !== -1 ? nextLF : string4.length;
14636
+ lineRe.lastIndex = nextLF;
14637
+ return foldLine(string4.slice(0, nextLF), width);
14638
+ }();
14639
+ var prevMoreIndented = string4[0] === `
14640
+ ` || string4[0] === " ";
14641
+ var moreIndented;
14642
+ var match;
14643
+ while (match = lineRe.exec(string4)) {
14644
+ var prefix = match[1], line = match[2];
14645
+ moreIndented = line[0] === " ";
14646
+ result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? `
14647
+ ` : "") + foldLine(line, width);
14648
+ prevMoreIndented = moreIndented;
14649
+ }
14650
+ return result;
14651
+ }
14652
+ function foldLine(line, width) {
14653
+ if (line === "" || line[0] === " ")
14654
+ return line;
14655
+ var breakRe = / [^ ]/g;
14656
+ var match;
14657
+ var start = 0, end, curr = 0, next = 0;
14658
+ var result = "";
14659
+ while (match = breakRe.exec(line)) {
14660
+ next = match.index;
14661
+ if (next - start > width) {
14662
+ end = curr > start ? curr : next;
14663
+ result += `
14664
+ ` + line.slice(start, end);
14665
+ start = end + 1;
14666
+ }
14667
+ curr = next;
14668
+ }
14669
+ result += `
14670
+ `;
14671
+ if (line.length - start > width && curr > start) {
14672
+ result += line.slice(start, curr) + `
14673
+ ` + line.slice(curr + 1);
14674
+ } else {
14675
+ result += line.slice(start);
14676
+ }
14677
+ return result.slice(1);
14678
+ }
14679
+ function escapeString(string4) {
14680
+ var result = "";
14681
+ var char = 0;
14682
+ var escapeSeq;
14683
+ for (var i2 = 0;i2 < string4.length; char >= 65536 ? i2 += 2 : i2++) {
14684
+ char = codePointAt(string4, i2);
14685
+ escapeSeq = ESCAPE_SEQUENCES[char];
14686
+ if (!escapeSeq && isPrintable(char)) {
14687
+ result += string4[i2];
14688
+ if (char >= 65536)
14689
+ result += string4[i2 + 1];
14690
+ } else {
14691
+ result += escapeSeq || encodeHex(char);
14692
+ }
14693
+ }
14694
+ return result;
14695
+ }
14696
+ function writeFlowSequence(state, level, object2) {
14697
+ var _result = "", _tag = state.tag, index, length, value;
14698
+ for (index = 0, length = object2.length;index < length; index += 1) {
14699
+ value = object2[index];
14700
+ if (state.replacer) {
14701
+ value = state.replacer.call(object2, String(index), value);
14702
+ }
14703
+ if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
14704
+ if (_result !== "")
14705
+ _result += "," + (!state.condenseFlow ? " " : "");
14706
+ _result += state.dump;
14707
+ }
14708
+ }
14709
+ state.tag = _tag;
14710
+ state.dump = "[" + _result + "]";
14711
+ }
14712
+ function writeBlockSequence(state, level, object2, compact) {
14713
+ var _result = "", _tag = state.tag, index, length, value;
14714
+ for (index = 0, length = object2.length;index < length; index += 1) {
14715
+ value = object2[index];
14716
+ if (state.replacer) {
14717
+ value = state.replacer.call(object2, String(index), value);
14718
+ }
14719
+ if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
14720
+ if (!compact || _result !== "") {
14721
+ _result += generateNextLine(state, level);
14722
+ }
14723
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
14724
+ _result += "-";
14725
+ } else {
14726
+ _result += "- ";
14727
+ }
14728
+ _result += state.dump;
14729
+ }
14730
+ }
14731
+ state.tag = _tag;
14732
+ state.dump = _result || "[]";
14733
+ }
14734
+ function writeFlowMapping(state, level, object2) {
14735
+ var _result = "", _tag = state.tag, objectKeyList = Object.keys(object2), index, length, objectKey, objectValue, pairBuffer;
14736
+ for (index = 0, length = objectKeyList.length;index < length; index += 1) {
14737
+ pairBuffer = "";
14738
+ if (_result !== "")
14739
+ pairBuffer += ", ";
14740
+ if (state.condenseFlow)
14741
+ pairBuffer += '"';
14742
+ objectKey = objectKeyList[index];
14743
+ objectValue = object2[objectKey];
14744
+ if (state.replacer) {
14745
+ objectValue = state.replacer.call(object2, objectKey, objectValue);
14746
+ }
14747
+ if (!writeNode(state, level, objectKey, false, false)) {
14748
+ continue;
14749
+ }
14750
+ if (state.dump.length > 1024)
14751
+ pairBuffer += "? ";
14752
+ pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
14753
+ if (!writeNode(state, level, objectValue, false, false)) {
14754
+ continue;
14755
+ }
14756
+ pairBuffer += state.dump;
14757
+ _result += pairBuffer;
14758
+ }
14759
+ state.tag = _tag;
14760
+ state.dump = "{" + _result + "}";
14761
+ }
14762
+ function writeBlockMapping(state, level, object2, compact) {
14763
+ var _result = "", _tag = state.tag, objectKeyList = Object.keys(object2), index, length, objectKey, objectValue, explicitPair, pairBuffer;
14764
+ if (state.sortKeys === true) {
14765
+ objectKeyList.sort();
14766
+ } else if (typeof state.sortKeys === "function") {
14767
+ objectKeyList.sort(state.sortKeys);
14768
+ } else if (state.sortKeys) {
14769
+ throw new exception("sortKeys must be a boolean or a function");
14770
+ }
14771
+ for (index = 0, length = objectKeyList.length;index < length; index += 1) {
14772
+ pairBuffer = "";
14773
+ if (!compact || _result !== "") {
14774
+ pairBuffer += generateNextLine(state, level);
14775
+ }
14776
+ objectKey = objectKeyList[index];
14777
+ objectValue = object2[objectKey];
14778
+ if (state.replacer) {
14779
+ objectValue = state.replacer.call(object2, objectKey, objectValue);
14780
+ }
14781
+ if (!writeNode(state, level + 1, objectKey, true, true, true)) {
14782
+ continue;
14783
+ }
14784
+ explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
14785
+ if (explicitPair) {
14786
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
14787
+ pairBuffer += "?";
14788
+ } else {
14789
+ pairBuffer += "? ";
14790
+ }
14791
+ }
14792
+ pairBuffer += state.dump;
14793
+ if (explicitPair) {
14794
+ pairBuffer += generateNextLine(state, level);
14795
+ }
14796
+ if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
14797
+ continue;
14798
+ }
14799
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
14800
+ pairBuffer += ":";
14801
+ } else {
14802
+ pairBuffer += ": ";
14803
+ }
14804
+ pairBuffer += state.dump;
14805
+ _result += pairBuffer;
14806
+ }
14807
+ state.tag = _tag;
14808
+ state.dump = _result || "{}";
14809
+ }
14810
+ function detectType(state, object2, explicit) {
14811
+ var _result, typeList, index, length, type2, style;
14812
+ typeList = explicit ? state.explicitTypes : state.implicitTypes;
14813
+ for (index = 0, length = typeList.length;index < length; index += 1) {
14814
+ type2 = typeList[index];
14815
+ if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object2 === "object" && object2 instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object2))) {
14816
+ if (explicit) {
14817
+ if (type2.multi && type2.representName) {
14818
+ state.tag = type2.representName(object2);
14819
+ } else {
14820
+ state.tag = type2.tag;
14821
+ }
14822
+ } else {
14823
+ state.tag = "?";
14824
+ }
14825
+ if (type2.represent) {
14826
+ style = state.styleMap[type2.tag] || type2.defaultStyle;
14827
+ if (_toString.call(type2.represent) === "[object Function]") {
14828
+ _result = type2.represent(object2, style);
14829
+ } else if (_hasOwnProperty.call(type2.represent, style)) {
14830
+ _result = type2.represent[style](object2, style);
14831
+ } else {
14832
+ throw new exception("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style');
14833
+ }
14834
+ state.dump = _result;
14835
+ }
14836
+ return true;
14837
+ }
14838
+ }
14839
+ return false;
14840
+ }
14841
+ function writeNode(state, level, object2, block, compact, iskey, isblockseq) {
14842
+ state.tag = null;
14843
+ state.dump = object2;
14844
+ if (!detectType(state, object2, false)) {
14845
+ detectType(state, object2, true);
14846
+ }
14847
+ var type2 = _toString.call(state.dump);
14848
+ var inblock = block;
14849
+ var tagStr;
14850
+ if (block) {
14851
+ block = state.flowLevel < 0 || state.flowLevel > level;
14852
+ }
14853
+ var objectOrArray = type2 === "[object Object]" || type2 === "[object Array]", duplicateIndex, duplicate;
14854
+ if (objectOrArray) {
14855
+ duplicateIndex = state.duplicates.indexOf(object2);
14856
+ duplicate = duplicateIndex !== -1;
14857
+ }
14858
+ if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
14859
+ compact = false;
14860
+ }
14861
+ if (duplicate && state.usedDuplicates[duplicateIndex]) {
14862
+ state.dump = "*ref_" + duplicateIndex;
14863
+ } else {
14864
+ if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
14865
+ state.usedDuplicates[duplicateIndex] = true;
14866
+ }
14867
+ if (type2 === "[object Object]") {
14868
+ if (block && Object.keys(state.dump).length !== 0) {
14869
+ writeBlockMapping(state, level, state.dump, compact);
14870
+ if (duplicate) {
14871
+ state.dump = "&ref_" + duplicateIndex + state.dump;
14872
+ }
14873
+ } else {
14874
+ writeFlowMapping(state, level, state.dump);
14875
+ if (duplicate) {
14876
+ state.dump = "&ref_" + duplicateIndex + " " + state.dump;
14877
+ }
14878
+ }
14879
+ } else if (type2 === "[object Array]") {
14880
+ if (block && state.dump.length !== 0) {
14881
+ if (state.noArrayIndent && !isblockseq && level > 0) {
14882
+ writeBlockSequence(state, level - 1, state.dump, compact);
14883
+ } else {
14884
+ writeBlockSequence(state, level, state.dump, compact);
14885
+ }
14886
+ if (duplicate) {
14887
+ state.dump = "&ref_" + duplicateIndex + state.dump;
14888
+ }
14889
+ } else {
14890
+ writeFlowSequence(state, level, state.dump);
14891
+ if (duplicate) {
14892
+ state.dump = "&ref_" + duplicateIndex + " " + state.dump;
14893
+ }
14894
+ }
14895
+ } else if (type2 === "[object String]") {
14896
+ if (state.tag !== "?") {
14897
+ writeScalar(state, state.dump, level, iskey, inblock);
14898
+ }
14899
+ } else if (type2 === "[object Undefined]") {
14900
+ return false;
14901
+ } else {
14902
+ if (state.skipInvalid)
14903
+ return false;
14904
+ throw new exception("unacceptable kind of an object to dump " + type2);
14905
+ }
14906
+ if (state.tag !== null && state.tag !== "?") {
14907
+ tagStr = encodeURI(state.tag[0] === "!" ? state.tag.slice(1) : state.tag).replace(/!/g, "%21");
14908
+ if (state.tag[0] === "!") {
14909
+ tagStr = "!" + tagStr;
14910
+ } else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
14911
+ tagStr = "!!" + tagStr.slice(18);
14912
+ } else {
14913
+ tagStr = "!<" + tagStr + ">";
14914
+ }
14915
+ state.dump = tagStr + " " + state.dump;
14916
+ }
14917
+ }
14918
+ return true;
14919
+ }
14920
+ function getDuplicateReferences(object2, state) {
14921
+ var objects = [], duplicatesIndexes = [], index, length;
14922
+ inspectNode(object2, objects, duplicatesIndexes);
14923
+ for (index = 0, length = duplicatesIndexes.length;index < length; index += 1) {
14924
+ state.duplicates.push(objects[duplicatesIndexes[index]]);
14925
+ }
14926
+ state.usedDuplicates = new Array(length);
14927
+ }
14928
+ function inspectNode(object2, objects, duplicatesIndexes) {
14929
+ var objectKeyList, index, length;
14930
+ if (object2 !== null && typeof object2 === "object") {
14931
+ index = objects.indexOf(object2);
14932
+ if (index !== -1) {
14933
+ if (duplicatesIndexes.indexOf(index) === -1) {
14934
+ duplicatesIndexes.push(index);
14935
+ }
14936
+ } else {
14937
+ objects.push(object2);
14938
+ if (Array.isArray(object2)) {
14939
+ for (index = 0, length = object2.length;index < length; index += 1) {
14940
+ inspectNode(object2[index], objects, duplicatesIndexes);
14941
+ }
14942
+ } else {
14943
+ objectKeyList = Object.keys(object2);
14944
+ for (index = 0, length = objectKeyList.length;index < length; index += 1) {
14945
+ inspectNode(object2[objectKeyList[index]], objects, duplicatesIndexes);
14946
+ }
14947
+ }
14948
+ }
14949
+ }
14950
+ }
14951
+ function dump$1(input, options) {
14952
+ options = options || {};
14953
+ var state = new State(options);
14954
+ if (!state.noRefs)
14955
+ getDuplicateReferences(input, state);
14956
+ var value = input;
14957
+ if (state.replacer) {
14958
+ value = state.replacer.call({ "": value }, "", value);
14959
+ }
14960
+ if (writeNode(state, 0, value, true, true))
14961
+ return state.dump + `
14962
+ `;
14963
+ return "";
14964
+ }
14965
+ var dump_1 = dump$1;
14966
+ var dumper = {
14967
+ dump: dump_1
14968
+ };
14969
+ function renamed(from, to) {
14970
+ return function() {
14971
+ throw new Error("Function yaml." + from + " is removed in js-yaml 4. " + "Use yaml." + to + " instead, which is now safe by default.");
14972
+ };
14973
+ }
14974
+ var Type = type;
14975
+ var Schema = schema;
14976
+ var FAILSAFE_SCHEMA = failsafe;
14977
+ var JSON_SCHEMA = json2;
14978
+ var CORE_SCHEMA = core2;
14979
+ var DEFAULT_SCHEMA = _default3;
14980
+ var load = loader.load;
14981
+ var loadAll = loader.loadAll;
14982
+ var dump = dumper.dump;
14983
+ var YAMLException = exception;
14984
+ var types = {
14985
+ binary,
14986
+ float,
14987
+ map: map2,
14988
+ null: _null4,
14989
+ pairs,
14990
+ set: set2,
14991
+ timestamp,
14992
+ bool,
14993
+ int: int2,
14994
+ merge: merge2,
14995
+ omap,
14996
+ seq,
14997
+ str
14998
+ };
14999
+ var safeLoad = renamed("safeLoad", "load");
15000
+ var safeLoadAll = renamed("safeLoadAll", "loadAll");
15001
+ var safeDump = renamed("safeDump", "dump");
15002
+ var jsYaml = {
15003
+ Type,
15004
+ Schema,
15005
+ FAILSAFE_SCHEMA,
15006
+ JSON_SCHEMA,
15007
+ CORE_SCHEMA,
15008
+ DEFAULT_SCHEMA,
15009
+ load,
15010
+ loadAll,
15011
+ dump,
15012
+ YAMLException,
15013
+ types,
15014
+ safeLoad,
15015
+ safeLoadAll,
15016
+ safeDump
15017
+ };
15018
+
15019
+ // src/astgrep/utils.ts
12333
15020
  import { spawn } from "node:child_process";
12334
15021
  import { existsSync } from "node:fs";
12335
15022
  import { join } from "node:path";
@@ -12428,7 +15115,40 @@ async function executeAstGrep(command, args, options) {
12428
15115
  return { matches: [], stdout, stderr };
12429
15116
  }
12430
15117
 
12431
- // src/tools.ts
15118
+ // src/astgrep/tools.ts
15119
+ var patternSchema = tool.schema.union([
15120
+ tool.schema.string(),
15121
+ tool.schema.object({
15122
+ context: tool.schema.string(),
15123
+ selector: tool.schema.string(),
15124
+ strictness: tool.schema.enum(["cst", "smart", "ast", "relaxed", "signature"]).optional()
15125
+ })
15126
+ ]);
15127
+ var ruleObjectSchema = tool.schema.lazy(() => tool.schema.object({
15128
+ pattern: patternSchema.optional(),
15129
+ kind: tool.schema.string().optional(),
15130
+ regex: tool.schema.string().optional(),
15131
+ inside: ruleObjectSchema.optional(),
15132
+ has: ruleObjectSchema.optional(),
15133
+ follows: ruleObjectSchema.optional(),
15134
+ precedes: ruleObjectSchema.optional(),
15135
+ all: tool.schema.array(ruleObjectSchema).optional(),
15136
+ any: tool.schema.array(ruleObjectSchema).optional(),
15137
+ not: ruleObjectSchema.optional(),
15138
+ matches: tool.schema.string().optional(),
15139
+ stopBy: tool.schema.union([tool.schema.enum(["neighbor", "end"]), ruleObjectSchema]).optional(),
15140
+ field: tool.schema.string().optional()
15141
+ }).passthrough().refine((obj) => Object.keys(obj).length > 0, {
15142
+ message: "Rule object must have at least one property (e.g., pattern, kind, has, inside)"
15143
+ }));
15144
+ var ruleSchema = tool.schema.object({
15145
+ id: tool.schema.string(),
15146
+ language: tool.schema.string(),
15147
+ rule: ruleObjectSchema,
15148
+ message: tool.schema.string().optional(),
15149
+ severity: tool.schema.enum(["error", "warning", "info", "hint"]).optional(),
15150
+ fix: tool.schema.string().optional()
15151
+ });
12432
15152
  function createFindTool(directory) {
12433
15153
  return tool({
12434
15154
  description: "Find code in the project using a simple AST pattern.",
@@ -12438,7 +15158,7 @@ function createFindTool(directory) {
12438
15158
  max_results: tool.schema.number().int().positive().optional(),
12439
15159
  output_format: tool.schema.enum(["text", "json"]).optional()
12440
15160
  },
12441
- async execute(args) {
15161
+ async execute(args, _context) {
12442
15162
  const { pattern, language, max_results, output_format = "text" } = args;
12443
15163
  const cmdArgs = ["--pattern", pattern];
12444
15164
  if (language) {
@@ -12473,37 +15193,54 @@ ${textOutput}`;
12473
15193
  }
12474
15194
  function createFindByRuleTool(directory) {
12475
15195
  return tool({
12476
- description: "Find code using a complex YAML rule for advanced structural queries.",
15196
+ description: "Find code using a structured AST rule for advanced structural queries.",
12477
15197
  args: {
12478
- yaml: tool.schema.string(),
15198
+ rule: ruleSchema,
12479
15199
  max_results: tool.schema.number().int().positive().optional(),
12480
15200
  output_format: tool.schema.enum(["text", "json"]).optional()
12481
15201
  },
12482
- async execute(args) {
12483
- const { yaml, max_results, output_format = "text" } = args;
12484
- const cmdArgs = ["--inline-rules", yaml, "--json", "."];
12485
- const { matches } = await executeAstGrep("scan", cmdArgs, {
12486
- directory
12487
- });
12488
- const totalMatches = matches.length;
12489
- let limitedMatches = matches;
12490
- if (max_results && totalMatches > max_results) {
12491
- limitedMatches = matches.slice(0, max_results);
12492
- }
12493
- if (output_format === "json") {
12494
- return JSON.stringify(limitedMatches, null, 2);
12495
- }
12496
- if (limitedMatches.length === 0) {
12497
- return "No matches found";
12498
- }
12499
- const textOutput = formatMatchesAsText(limitedMatches);
12500
- let header = `Found ${limitedMatches.length} matches`;
12501
- if (max_results && totalMatches > max_results) {
12502
- header += ` (showing first ${max_results} of ${totalMatches})`;
12503
- }
12504
- return `${header}:
15202
+ async execute(args, _context) {
15203
+ const { rule, max_results, output_format = "text" } = args;
15204
+ try {
15205
+ const yamlString = jsYaml.dump(rule);
15206
+ const cmdArgs = ["--inline-rules", yamlString, "--json", "."];
15207
+ const { matches } = await executeAstGrep("scan", cmdArgs, {
15208
+ directory
15209
+ });
15210
+ const totalMatches = matches.length;
15211
+ let limitedMatches = matches;
15212
+ if (max_results && totalMatches > max_results) {
15213
+ limitedMatches = matches.slice(0, max_results);
15214
+ }
15215
+ if (output_format === "json") {
15216
+ return JSON.stringify(limitedMatches, null, 2);
15217
+ }
15218
+ if (limitedMatches.length === 0) {
15219
+ return "No matches found";
15220
+ }
15221
+ const textOutput = formatMatchesAsText(limitedMatches);
15222
+ let header = `Found ${limitedMatches.length} matches`;
15223
+ if (max_results && totalMatches > max_results) {
15224
+ header += ` (showing first ${max_results} of ${totalMatches})`;
15225
+ }
15226
+ return `${header}:
12505
15227
 
12506
15228
  ${textOutput}`;
15229
+ } catch (error45) {
15230
+ if (error45 instanceof Error && error45.message.includes("Cannot parse rule")) {
15231
+ return `Invalid rule structure: ${error45.message}
15232
+
15233
+ Rule must include id, language, and rule fields. The rule field must be an object with at least one property (pattern, kind, has, inside, etc.). Example:
15234
+ ${JSON.stringify({
15235
+ id: "example-rule",
15236
+ language: "javascript",
15237
+ rule: {
15238
+ pattern: "console.log($ARG)"
15239
+ }
15240
+ }, null, 2)}`;
15241
+ }
15242
+ throw error45;
15243
+ }
12507
15244
  }
12508
15245
  });
12509
15246
  }
@@ -12515,7 +15252,7 @@ function createDumpSyntaxTool() {
12515
15252
  language: tool.schema.string(),
12516
15253
  format: tool.schema.enum(["cst", "ast", "pattern"]).optional()
12517
15254
  },
12518
- async execute(args) {
15255
+ async execute(args, _context) {
12519
15256
  const { code, language, format = "cst" } = args;
12520
15257
  const cmdArgs = ["--pattern", code, "--lang", language, `--debug-query=${format}`];
12521
15258
  const { stderr } = await executeAstGrep("run", cmdArgs, {});
@@ -12525,26 +15262,347 @@ function createDumpSyntaxTool() {
12525
15262
  }
12526
15263
  function createTestRuleTool(directory) {
12527
15264
  return tool({
12528
- description: "Test a YAML rule against a code snippet to verify matches.",
15265
+ description: "Test a structured AST rule against a code snippet to verify matches.",
12529
15266
  args: {
12530
15267
  code: tool.schema.string(),
12531
- yaml: tool.schema.string()
15268
+ rule: ruleSchema
12532
15269
  },
12533
- async execute(args) {
12534
- const { code, yaml } = args;
12535
- const cmdArgs = ["--inline-rules", yaml, "--json", "--stdin"];
12536
- const { matches } = await executeAstGrep("scan", cmdArgs, {
12537
- input: code,
12538
- directory
12539
- });
12540
- if (matches.length === 0) {
12541
- return "No matches found for the given code and rule. Try adding `stopBy: end` to your inside/has rule.";
15270
+ async execute(args, _context) {
15271
+ const { code, rule } = args;
15272
+ try {
15273
+ const yamlString = jsYaml.dump(rule);
15274
+ const cmdArgs = ["--inline-rules", yamlString, "--json", "--stdin"];
15275
+ const { matches } = await executeAstGrep("scan", cmdArgs, {
15276
+ input: code,
15277
+ directory
15278
+ });
15279
+ if (matches.length === 0) {
15280
+ return "No matches found for the given code and rule. Try adding `stopBy: end` to your inside/has rule.";
15281
+ }
15282
+ return JSON.stringify(matches, null, 2);
15283
+ } catch (error45) {
15284
+ if (error45 instanceof Error && error45.message.includes("Cannot parse rule")) {
15285
+ return `Invalid rule structure: ${error45.message}
15286
+
15287
+ Rule must include id, language, and rule fields. The rule field must be an object with at least one property (pattern, kind, has, inside, etc.). Example:
15288
+ ${JSON.stringify({
15289
+ id: "test-rule",
15290
+ language: "javascript",
15291
+ rule: {
15292
+ pattern: "console.log($ARG)"
15293
+ }
15294
+ }, null, 2)}`;
15295
+ }
15296
+ throw error45;
12542
15297
  }
12543
- return JSON.stringify(matches, null, 2);
12544
15298
  }
12545
15299
  });
12546
15300
  }
15301
+ // src/websearch/duckduckgo.ts
15302
+ async function searchDuckDuckGo(query, options) {
15303
+ try {
15304
+ const response = await fetch(`https://api.duckduckgo.com/?q=${encodeURIComponent(query)}&format=json&no_html=1&no_redirect=1`);
15305
+ if (!response.ok) {
15306
+ throw new Error(`DuckDuckGo API error: ${response.statusText}`);
15307
+ }
15308
+ const data = await response.json();
15309
+ const results = [];
15310
+ if (data.Abstract && data.AbstractText) {
15311
+ results.push({
15312
+ title: data.Heading || data.AbstractSource || "Instant Answer",
15313
+ link: data.AbstractURL || "",
15314
+ snippet: data.AbstractText
15315
+ });
15316
+ }
15317
+ if (data.Results && Array.isArray(data.Results)) {
15318
+ data.Results.forEach((item) => {
15319
+ if (item.FirstURL) {
15320
+ results.push({
15321
+ title: item.Text || "",
15322
+ link: item.FirstURL,
15323
+ snippet: ""
15324
+ });
15325
+ }
15326
+ });
15327
+ }
15328
+ if (data.RelatedTopics && Array.isArray(data.RelatedTopics)) {
15329
+ data.RelatedTopics.forEach((item) => {
15330
+ if (item.FirstURL && item.Text) {
15331
+ results.push({
15332
+ title: item.Text.split(" - ")[0] || item.Text,
15333
+ link: item.FirstURL,
15334
+ snippet: item.Text.split(" - ").slice(1).join(" - ") || ""
15335
+ });
15336
+ }
15337
+ });
15338
+ }
15339
+ return results.slice(0, options.limit);
15340
+ } catch (error45) {
15341
+ console.error("DuckDuckGo search error:", error45);
15342
+ throw new Error(`DuckDuckGo search failed: ${error45 instanceof Error ? error45.message : String(error45)}`);
15343
+ }
15344
+ }
15345
+
15346
+ // src/websearch/google.ts
15347
+ async function searchGoogle(query, options) {
15348
+ try {
15349
+ const playwright = await import("playwright");
15350
+ const { chromium } = playwright;
15351
+ const browser = await chromium.launch({
15352
+ headless: options.headless ?? true,
15353
+ args: [
15354
+ "--disable-blink-features=AutomationControlled",
15355
+ "--disable-features=IsolateOrigins,site-per-process",
15356
+ "--disable-site-isolation-trials",
15357
+ "--no-sandbox",
15358
+ "--disable-setuid-sandbox",
15359
+ "--disable-dev-shm-usage",
15360
+ "--disable-accelerated-2d-canvas",
15361
+ "--no-first-run",
15362
+ "--no-zygote",
15363
+ "--disable-gpu",
15364
+ "--hide-scrollbars",
15365
+ "--mute-audio"
15366
+ ],
15367
+ ignoreDefaultArgs: ["--enable-automation"]
15368
+ });
15369
+ try {
15370
+ const context = await browser.newContext({
15371
+ viewport: { width: 1920, height: 1080 },
15372
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
15373
+ locale: options.locale,
15374
+ timezoneId: "America/New_York"
15375
+ });
15376
+ await context.addInitScript(() => {
15377
+ Object.defineProperty(navigator, "webdriver", { get: () => false });
15378
+ Object.defineProperty(navigator, "plugins", { get: () => [1, 2, 3, 4, 5] });
15379
+ Object.defineProperty(navigator, "languages", { get: () => ["en-US", "en"] });
15380
+ window.chrome = {
15381
+ runtime: {},
15382
+ loadTimes: () => {},
15383
+ csi: () => {},
15384
+ app: {}
15385
+ };
15386
+ });
15387
+ const page = await context.newPage();
15388
+ const googleDomain = options.country ? `https://www.google.${options.country.toLowerCase()}` : "https://www.google.com";
15389
+ await page.goto(googleDomain, { waitUntil: "networkidle", timeout: options.timeout });
15390
+ const currentUrl = page.url();
15391
+ if (currentUrl.includes("sorry") || currentUrl.includes("captcha") || currentUrl.includes("recaptcha")) {
15392
+ throw new Error("Google CAPTCHA detected. Try enabling headless: false or using a different IP.");
15393
+ }
15394
+ const searchInput = await page.waitForSelector('textarea[name="q"], input[name="q"]', {
15395
+ timeout: options.timeout / 2
15396
+ });
15397
+ await searchInput.click();
15398
+ await searchInput.fill(query);
15399
+ await searchInput.press("Enter");
15400
+ await page.waitForLoadState("networkidle", { timeout: options.timeout });
15401
+ const searchUrl = page.url();
15402
+ if (searchUrl.includes("sorry") || searchUrl.includes("captcha") || searchUrl.includes("recaptcha")) {
15403
+ throw new Error("Google CAPTCHA detected after search. Try enabling headless: false or using a different IP.");
15404
+ }
15405
+ const results = await page.evaluate((limit) => {
15406
+ const extracted = [];
15407
+ const seenUrls = new Set;
15408
+ const selectorSets = [
15409
+ { container: "#search div[data-hveid]", title: "h3", snippet: 'div[role="text"]' },
15410
+ { container: "#rso div[data-hveid]", title: "h3", snippet: 'div[style*="webkit-line-clamp"]' },
15411
+ { container: ".g", title: "h3", snippet: "div" },
15412
+ { container: "div[jscontroller][data-hveid]", title: "h3", snippet: 'div[role="text"]' }
15413
+ ];
15414
+ const alternativeSnippetSelectors = ['div[role="text"]', 'div[style*="webkit-line-clamp"]', "div"];
15415
+ for (const selectors of selectorSets) {
15416
+ if (extracted.length >= limit)
15417
+ break;
15418
+ const containers = Array.from(document.querySelectorAll(selectors.container));
15419
+ for (const container of containers) {
15420
+ if (extracted.length >= limit)
15421
+ break;
15422
+ const titleElement = container.querySelector(selectors.title);
15423
+ if (!titleElement)
15424
+ continue;
15425
+ const title = (titleElement.textContent || "").trim();
15426
+ let link = "";
15427
+ const linkInTitle = titleElement.querySelector("a");
15428
+ if (linkInTitle) {
15429
+ link = linkInTitle.href;
15430
+ } else {
15431
+ let current = titleElement;
15432
+ while (current && current.tagName !== "A") {
15433
+ current = current.parentElement;
15434
+ }
15435
+ if (current && current instanceof HTMLAnchorElement) {
15436
+ link = current.href;
15437
+ } else {
15438
+ const containerLink = container.querySelector("a");
15439
+ if (containerLink) {
15440
+ link = containerLink.href;
15441
+ }
15442
+ }
15443
+ }
15444
+ if (!link || !link.startsWith("http") || seenUrls.has(link))
15445
+ continue;
15446
+ let snippet2 = "";
15447
+ const snippetElement = container.querySelector(selectors.snippet);
15448
+ if (snippetElement) {
15449
+ snippet2 = (snippetElement.textContent || "").trim();
15450
+ } else {
15451
+ for (const altSelector of alternativeSnippetSelectors) {
15452
+ const element = container.querySelector(altSelector);
15453
+ if (element) {
15454
+ snippet2 = (element.textContent || "").trim();
15455
+ break;
15456
+ }
15457
+ }
15458
+ if (!snippet2) {
15459
+ const textNodes = Array.from(container.querySelectorAll("div")).filter((el) => !el.querySelector("h3") && (el.textContent || "").trim().length > 20);
15460
+ if (textNodes.length > 0) {
15461
+ snippet2 = (textNodes[0]?.textContent || "").trim();
15462
+ }
15463
+ }
15464
+ }
15465
+ if (title && link) {
15466
+ extracted.push({ title, link, snippet: snippet2 });
15467
+ seenUrls.add(link);
15468
+ }
15469
+ }
15470
+ }
15471
+ if (extracted.length < limit) {
15472
+ const anchorElements = Array.from(document.querySelectorAll("a[href^='http']"));
15473
+ for (const el of anchorElements) {
15474
+ if (extracted.length >= limit)
15475
+ break;
15476
+ if (!(el instanceof HTMLAnchorElement))
15477
+ continue;
15478
+ const link = el.href;
15479
+ if (!link || seenUrls.has(link) || link.includes("google.com/") || link.includes("accounts.google") || link.includes("support.google")) {
15480
+ continue;
15481
+ }
15482
+ const title = (el.textContent || "").trim();
15483
+ if (!title)
15484
+ continue;
15485
+ let snippet2 = "";
15486
+ let parent = el.parentElement;
15487
+ for (let i2 = 0;i2 < 3 && parent; i2++) {
15488
+ const text = (parent.textContent || "").trim();
15489
+ if (text.length > 20 && text !== title) {
15490
+ snippet2 = text;
15491
+ break;
15492
+ }
15493
+ parent = parent.parentElement;
15494
+ }
15495
+ extracted.push({ title, link, snippet: snippet2 });
15496
+ seenUrls.add(link);
15497
+ }
15498
+ }
15499
+ return extracted.slice(0, limit);
15500
+ }, options.limit);
15501
+ await browser.close();
15502
+ return results;
15503
+ } catch (error45) {
15504
+ await browser.close();
15505
+ throw new Error(`Google search failed: ${error45 instanceof Error ? error45.message : String(error45)}`);
15506
+ }
15507
+ } catch (error45) {
15508
+ if (error45 instanceof Error && error45.message.includes("Cannot find module")) {
15509
+ throw new Error(`Google search requires Playwright to be installed. Please install it with: npm install playwright@latest
15510
+ Note: Playwright requires downloading browser binaries (~180MB).`);
15511
+ }
15512
+ throw error45;
15513
+ }
15514
+ }
15515
+
15516
+ // src/websearch/tools.ts
15517
+ var searchEngineOptionsSchema = tool.schema.object({
15518
+ duckduckgo: tool.schema.object({
15519
+ safe_search: tool.schema.boolean().optional(),
15520
+ region: tool.schema.string().optional(),
15521
+ time_range: tool.schema.enum(["d", "w", "m", "y"]).optional()
15522
+ }).optional(),
15523
+ google: tool.schema.object({
15524
+ safe_search: tool.schema.boolean().optional(),
15525
+ country: tool.schema.string().optional(),
15526
+ headless: tool.schema.boolean().optional(),
15527
+ use_saved_state: tool.schema.boolean().optional()
15528
+ }).optional()
15529
+ }).refine((obj) => obj.duckduckgo !== undefined || obj.google !== undefined, {
15530
+ message: "At least one search engine must be specified (duckduckgo or google)"
15531
+ });
15532
+ function createWebSearchTool() {
15533
+ return tool({
15534
+ description: "Search the web using Google and/or DuckDuckGo. If multiple engines are specified, queries run in parallel.",
15535
+ args: {
15536
+ query: tool.schema.string(),
15537
+ engines: searchEngineOptionsSchema,
15538
+ limit: tool.schema.number().int().positive().max(50).optional(),
15539
+ timeout: tool.schema.number().int().positive().max(120000).optional(),
15540
+ locale: tool.schema.string().optional()
15541
+ },
15542
+ async execute(args, _context) {
15543
+ const { query, engines, limit = 10, timeout = 30000, locale = "en-US" } = args;
15544
+ const results = [];
15545
+ const sources = {};
15546
+ const searchPromises = [];
15547
+ if (engines.google) {
15548
+ searchPromises.push(searchGoogle(query, { ...engines.google, limit, timeout, locale }).then((googleResults) => {
15549
+ sources.google = { count: googleResults.length, success: true };
15550
+ googleResults.forEach((result, index) => {
15551
+ results.push({
15552
+ ...result,
15553
+ source: "google",
15554
+ rank: index + 1
15555
+ });
15556
+ });
15557
+ }).catch((error45) => {
15558
+ sources.google = {
15559
+ count: 0,
15560
+ success: false,
15561
+ error: error45 instanceof Error ? error45.message : String(error45)
15562
+ };
15563
+ }));
15564
+ }
15565
+ if (engines.duckduckgo) {
15566
+ searchPromises.push(searchDuckDuckGo(query, { ...engines.duckduckgo, limit, timeout, locale }).then((ddResults) => {
15567
+ sources.duckduckgo = { count: ddResults.length, success: true };
15568
+ ddResults.forEach((result, index) => {
15569
+ results.push({
15570
+ ...result,
15571
+ source: "duckduckgo",
15572
+ rank: index + 1
15573
+ });
15574
+ });
15575
+ }).catch((error45) => {
15576
+ sources.duckduckgo = {
15577
+ count: 0,
15578
+ success: false,
15579
+ error: error45 instanceof Error ? error45.message : String(error45)
15580
+ };
15581
+ }));
15582
+ }
15583
+ await Promise.allSettled(searchPromises);
15584
+ results.sort((a, b) => {
15585
+ if (a.source === b.source) {
15586
+ return a.rank - b.rank;
15587
+ }
15588
+ return a.source === "google" ? -1 : 1;
15589
+ });
15590
+ if (results.length === 0) {
15591
+ const errors3 = Object.entries(sources).filter(([_, info]) => !info?.success).map(([engine, info]) => `${engine}: ${info?.error}`).join("; ");
15592
+ return `No results found. ${errors3 ? `Errors: ${errors3}` : "Try adjusting your search terms."}`;
15593
+ }
15594
+ const formatted = results.map((r, i2) => `${i2 + 1}. [${r.source.toUpperCase()}] ${r.title}
15595
+ ${r.link}
15596
+ ${r.snippet || "No description"}
15597
+ `).join(`
15598
+ `);
15599
+ const summary = `Found ${results.length} results from: ${Object.entries(sources).filter(([_, info]) => info?.success).map(([engine, info]) => `${engine}(${info?.count})`).join(", ") || "none"}`;
15600
+ return `${summary}
12547
15601
 
15602
+ ${formatted}`;
15603
+ }
15604
+ });
15605
+ }
12548
15606
  // src/plugin.ts
12549
15607
  var SearchPlugin = async ({ directory }) => {
12550
15608
  return {
@@ -12552,7 +15610,8 @@ var SearchPlugin = async ({ directory }) => {
12552
15610
  ast_grep_find: createFindTool(directory),
12553
15611
  ast_grep_find_by_rule: createFindByRuleTool(directory),
12554
15612
  ast_grep_dump_syntax: createDumpSyntaxTool(),
12555
- ast_grep_test_rule: createTestRuleTool(directory)
15613
+ ast_grep_test_rule: createTestRuleTool(directory),
15614
+ web_search: createWebSearchTool()
12556
15615
  }
12557
15616
  };
12558
15617
  };