@astrasyncai/verification-gateway 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter-interface/interface.d.mts +71 -0
- package/dist/adapter-interface/interface.d.ts +71 -0
- package/dist/adapter-interface/interface.js +36 -0
- package/dist/adapter-interface/interface.js.map +1 -0
- package/dist/adapter-interface/interface.mjs +10 -0
- package/dist/adapter-interface/interface.mjs.map +1 -0
- package/dist/adapter-interface/purpose-mapping.d.mts +28 -0
- package/dist/adapter-interface/purpose-mapping.d.ts +28 -0
- package/dist/adapter-interface/purpose-mapping.js +117 -0
- package/dist/adapter-interface/purpose-mapping.js.map +1 -0
- package/dist/adapter-interface/purpose-mapping.mjs +89 -0
- package/dist/adapter-interface/purpose-mapping.mjs.map +1 -0
- package/dist/adapters/express.d.mts +2 -2
- package/dist/adapters/express.d.ts +2 -2
- package/dist/adapters/express.js +46 -9
- package/dist/adapters/express.js.map +1 -1
- package/dist/adapters/express.mjs +46 -9
- package/dist/adapters/express.mjs.map +1 -1
- package/dist/adapters/nextjs.d.mts +2 -2
- package/dist/adapters/nextjs.d.ts +2 -2
- package/dist/adapters/nextjs.js +19 -9
- package/dist/adapters/nextjs.js.map +1 -1
- package/dist/adapters/nextjs.mjs +19 -9
- package/dist/adapters/nextjs.mjs.map +1 -1
- package/dist/adapters/sdk.d.mts +2 -2
- package/dist/adapters/sdk.d.ts +2 -2
- package/dist/adapters/sdk.js +20 -4
- package/dist/adapters/sdk.js.map +1 -1
- package/dist/adapters/sdk.mjs +20 -4
- package/dist/adapters/sdk.mjs.map +1 -1
- package/dist/agent/index.d.mts +2 -0
- package/dist/agent/index.d.ts +2 -0
- package/dist/agent/index.js +354 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/index.mjs +323 -0
- package/dist/agent/index.mjs.map +1 -0
- package/dist/browser/browser-adapter.d.mts +106 -0
- package/dist/browser/browser-adapter.d.ts +106 -0
- package/dist/browser/browser-adapter.js +286 -0
- package/dist/browser/browser-adapter.js.map +1 -0
- package/dist/browser/browser-adapter.mjs +259 -0
- package/dist/browser/browser-adapter.mjs.map +1 -0
- package/dist/cli/index.d.mts +241 -0
- package/dist/cli/index.d.ts +241 -0
- package/dist/cli/index.js +3734 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.mjs +3688 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/cursor/cursor-adapter.d.mts +92 -0
- package/dist/cursor/cursor-adapter.d.ts +92 -0
- package/dist/cursor/cursor-adapter.js +273 -0
- package/dist/cursor/cursor-adapter.js.map +1 -0
- package/dist/cursor/cursor-adapter.mjs +246 -0
- package/dist/cursor/cursor-adapter.mjs.map +1 -0
- package/dist/{express-DUDYpvNZ.d.mts → express-Cp4eg77F.d.mts} +1 -1
- package/dist/{express-BhD3mWsL.d.ts → express-DIEyq1Tz.d.ts} +1 -1
- package/dist/gateway/gateway.d.mts +70 -0
- package/dist/gateway/gateway.d.ts +70 -0
- package/dist/gateway/gateway.js +3726 -0
- package/dist/gateway/gateway.js.map +1 -0
- package/dist/gateway/gateway.mjs +3706 -0
- package/dist/gateway/gateway.mjs.map +1 -0
- package/dist/git-trigger/git-hooks.d.mts +69 -0
- package/dist/git-trigger/git-hooks.d.ts +69 -0
- package/dist/git-trigger/git-hooks.js +244 -0
- package/dist/git-trigger/git-hooks.js.map +1 -0
- package/dist/git-trigger/git-hooks.mjs +221 -0
- package/dist/git-trigger/git-hooks.mjs.map +1 -0
- package/dist/index-BhTbGU-o.d.mts +206 -0
- package/dist/index-Bhfxq9xI.d.ts +206 -0
- package/dist/index-CNkmHmpi.d.ts +89 -0
- package/dist/index-CoLebmwv.d.mts +89 -0
- package/dist/index.d.mts +8 -295
- package/dist/index.d.ts +8 -295
- package/dist/index.js +60 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -21
- package/dist/index.mjs.map +1 -1
- package/dist/local-evaluator/evaluator.d.mts +55 -0
- package/dist/local-evaluator/evaluator.d.ts +55 -0
- package/dist/local-evaluator/evaluator.js +272 -0
- package/dist/local-evaluator/evaluator.js.map +1 -0
- package/dist/local-evaluator/evaluator.mjs +244 -0
- package/dist/local-evaluator/evaluator.mjs.map +1 -0
- package/dist/{nextjs-C9FPOjSh.d.ts → nextjs-Cag7libc.d.ts} +1 -1
- package/dist/{nextjs-BtqyLSVQ.d.mts → nextjs-_C_FcJY5.d.mts} +1 -1
- package/dist/{sdk-BkVigGjF.d.ts → sdk-CMPDFUjo.d.ts} +3 -1
- package/dist/{sdk-xCbZgeZx.d.mts → sdk-DAJahT3p.d.mts} +3 -1
- package/dist/transport/index.d.mts +2 -0
- package/dist/transport/index.d.ts +2 -0
- package/dist/transport/index.js +211 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/index.mjs +176 -0
- package/dist/transport/index.mjs.map +1 -0
- package/dist/{types-CS6v75-d.d.mts → types-Bf8pML07.d.mts} +9 -1
- package/dist/{types-CS6v75-d.d.ts → types-Bf8pML07.d.ts} +9 -1
- package/dist/types-BvpGdsv1.d.mts +153 -0
- package/dist/types-Ce2mFJkO.d.ts +153 -0
- package/dist/ui/index.d.mts +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/package.json +46 -1
|
@@ -0,0 +1,3688 @@
|
|
|
1
|
+
// ../../node_modules/js-yaml/dist/js-yaml.mjs
|
|
2
|
+
function isNothing(subject) {
|
|
3
|
+
return typeof subject === "undefined" || subject === null;
|
|
4
|
+
}
|
|
5
|
+
function isObject(subject) {
|
|
6
|
+
return typeof subject === "object" && subject !== null;
|
|
7
|
+
}
|
|
8
|
+
function toArray(sequence) {
|
|
9
|
+
if (Array.isArray(sequence)) return sequence;
|
|
10
|
+
else if (isNothing(sequence)) return [];
|
|
11
|
+
return [sequence];
|
|
12
|
+
}
|
|
13
|
+
function extend(target, source) {
|
|
14
|
+
var index, length, key, sourceKeys;
|
|
15
|
+
if (source) {
|
|
16
|
+
sourceKeys = Object.keys(source);
|
|
17
|
+
for (index = 0, length = sourceKeys.length; index < length; index += 1) {
|
|
18
|
+
key = sourceKeys[index];
|
|
19
|
+
target[key] = source[key];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return target;
|
|
23
|
+
}
|
|
24
|
+
function repeat(string, count) {
|
|
25
|
+
var result = "", cycle;
|
|
26
|
+
for (cycle = 0; cycle < count; cycle += 1) {
|
|
27
|
+
result += string;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function isNegativeZero(number) {
|
|
32
|
+
return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
|
|
33
|
+
}
|
|
34
|
+
var isNothing_1 = isNothing;
|
|
35
|
+
var isObject_1 = isObject;
|
|
36
|
+
var toArray_1 = toArray;
|
|
37
|
+
var repeat_1 = repeat;
|
|
38
|
+
var isNegativeZero_1 = isNegativeZero;
|
|
39
|
+
var extend_1 = extend;
|
|
40
|
+
var common = {
|
|
41
|
+
isNothing: isNothing_1,
|
|
42
|
+
isObject: isObject_1,
|
|
43
|
+
toArray: toArray_1,
|
|
44
|
+
repeat: repeat_1,
|
|
45
|
+
isNegativeZero: isNegativeZero_1,
|
|
46
|
+
extend: extend_1
|
|
47
|
+
};
|
|
48
|
+
function formatError(exception2, compact) {
|
|
49
|
+
var where = "", message = exception2.reason || "(unknown reason)";
|
|
50
|
+
if (!exception2.mark) return message;
|
|
51
|
+
if (exception2.mark.name) {
|
|
52
|
+
where += 'in "' + exception2.mark.name + '" ';
|
|
53
|
+
}
|
|
54
|
+
where += "(" + (exception2.mark.line + 1) + ":" + (exception2.mark.column + 1) + ")";
|
|
55
|
+
if (!compact && exception2.mark.snippet) {
|
|
56
|
+
where += "\n\n" + exception2.mark.snippet;
|
|
57
|
+
}
|
|
58
|
+
return message + " " + where;
|
|
59
|
+
}
|
|
60
|
+
function YAMLException$1(reason, mark) {
|
|
61
|
+
Error.call(this);
|
|
62
|
+
this.name = "YAMLException";
|
|
63
|
+
this.reason = reason;
|
|
64
|
+
this.mark = mark;
|
|
65
|
+
this.message = formatError(this, false);
|
|
66
|
+
if (Error.captureStackTrace) {
|
|
67
|
+
Error.captureStackTrace(this, this.constructor);
|
|
68
|
+
} else {
|
|
69
|
+
this.stack = new Error().stack || "";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
YAMLException$1.prototype = Object.create(Error.prototype);
|
|
73
|
+
YAMLException$1.prototype.constructor = YAMLException$1;
|
|
74
|
+
YAMLException$1.prototype.toString = function toString(compact) {
|
|
75
|
+
return this.name + ": " + formatError(this, compact);
|
|
76
|
+
};
|
|
77
|
+
var exception = YAMLException$1;
|
|
78
|
+
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
|
|
79
|
+
var head = "";
|
|
80
|
+
var tail = "";
|
|
81
|
+
var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
|
|
82
|
+
if (position - lineStart > maxHalfLength) {
|
|
83
|
+
head = " ... ";
|
|
84
|
+
lineStart = position - maxHalfLength + head.length;
|
|
85
|
+
}
|
|
86
|
+
if (lineEnd - position > maxHalfLength) {
|
|
87
|
+
tail = " ...";
|
|
88
|
+
lineEnd = position + maxHalfLength - tail.length;
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "\u2192") + tail,
|
|
92
|
+
pos: position - lineStart + head.length
|
|
93
|
+
// relative position
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function padStart(string, max) {
|
|
97
|
+
return common.repeat(" ", max - string.length) + string;
|
|
98
|
+
}
|
|
99
|
+
function makeSnippet(mark, options) {
|
|
100
|
+
options = Object.create(options || null);
|
|
101
|
+
if (!mark.buffer) return null;
|
|
102
|
+
if (!options.maxLength) options.maxLength = 79;
|
|
103
|
+
if (typeof options.indent !== "number") options.indent = 1;
|
|
104
|
+
if (typeof options.linesBefore !== "number") options.linesBefore = 3;
|
|
105
|
+
if (typeof options.linesAfter !== "number") options.linesAfter = 2;
|
|
106
|
+
var re = /\r?\n|\r|\0/g;
|
|
107
|
+
var lineStarts = [0];
|
|
108
|
+
var lineEnds = [];
|
|
109
|
+
var match;
|
|
110
|
+
var foundLineNo = -1;
|
|
111
|
+
while (match = re.exec(mark.buffer)) {
|
|
112
|
+
lineEnds.push(match.index);
|
|
113
|
+
lineStarts.push(match.index + match[0].length);
|
|
114
|
+
if (mark.position <= match.index && foundLineNo < 0) {
|
|
115
|
+
foundLineNo = lineStarts.length - 2;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
|
|
119
|
+
var result = "", i, line;
|
|
120
|
+
var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
|
|
121
|
+
var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
|
|
122
|
+
for (i = 1; i <= options.linesBefore; i++) {
|
|
123
|
+
if (foundLineNo - i < 0) break;
|
|
124
|
+
line = getLine(
|
|
125
|
+
mark.buffer,
|
|
126
|
+
lineStarts[foundLineNo - i],
|
|
127
|
+
lineEnds[foundLineNo - i],
|
|
128
|
+
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
|
|
129
|
+
maxLineLength
|
|
130
|
+
);
|
|
131
|
+
result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + "\n" + result;
|
|
132
|
+
}
|
|
133
|
+
line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
|
|
134
|
+
result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
135
|
+
result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^\n";
|
|
136
|
+
for (i = 1; i <= options.linesAfter; i++) {
|
|
137
|
+
if (foundLineNo + i >= lineEnds.length) break;
|
|
138
|
+
line = getLine(
|
|
139
|
+
mark.buffer,
|
|
140
|
+
lineStarts[foundLineNo + i],
|
|
141
|
+
lineEnds[foundLineNo + i],
|
|
142
|
+
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
|
|
143
|
+
maxLineLength
|
|
144
|
+
);
|
|
145
|
+
result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
146
|
+
}
|
|
147
|
+
return result.replace(/\n$/, "");
|
|
148
|
+
}
|
|
149
|
+
var snippet = makeSnippet;
|
|
150
|
+
var TYPE_CONSTRUCTOR_OPTIONS = [
|
|
151
|
+
"kind",
|
|
152
|
+
"multi",
|
|
153
|
+
"resolve",
|
|
154
|
+
"construct",
|
|
155
|
+
"instanceOf",
|
|
156
|
+
"predicate",
|
|
157
|
+
"represent",
|
|
158
|
+
"representName",
|
|
159
|
+
"defaultStyle",
|
|
160
|
+
"styleAliases"
|
|
161
|
+
];
|
|
162
|
+
var YAML_NODE_KINDS = [
|
|
163
|
+
"scalar",
|
|
164
|
+
"sequence",
|
|
165
|
+
"mapping"
|
|
166
|
+
];
|
|
167
|
+
function compileStyleAliases(map2) {
|
|
168
|
+
var result = {};
|
|
169
|
+
if (map2 !== null) {
|
|
170
|
+
Object.keys(map2).forEach(function(style) {
|
|
171
|
+
map2[style].forEach(function(alias) {
|
|
172
|
+
result[String(alias)] = style;
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
function Type$1(tag, options) {
|
|
179
|
+
options = options || {};
|
|
180
|
+
Object.keys(options).forEach(function(name) {
|
|
181
|
+
if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
|
182
|
+
throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
this.options = options;
|
|
186
|
+
this.tag = tag;
|
|
187
|
+
this.kind = options["kind"] || null;
|
|
188
|
+
this.resolve = options["resolve"] || function() {
|
|
189
|
+
return true;
|
|
190
|
+
};
|
|
191
|
+
this.construct = options["construct"] || function(data) {
|
|
192
|
+
return data;
|
|
193
|
+
};
|
|
194
|
+
this.instanceOf = options["instanceOf"] || null;
|
|
195
|
+
this.predicate = options["predicate"] || null;
|
|
196
|
+
this.represent = options["represent"] || null;
|
|
197
|
+
this.representName = options["representName"] || null;
|
|
198
|
+
this.defaultStyle = options["defaultStyle"] || null;
|
|
199
|
+
this.multi = options["multi"] || false;
|
|
200
|
+
this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
|
|
201
|
+
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
|
202
|
+
throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
var type = Type$1;
|
|
206
|
+
function compileList(schema2, name) {
|
|
207
|
+
var result = [];
|
|
208
|
+
schema2[name].forEach(function(currentType) {
|
|
209
|
+
var newIndex = result.length;
|
|
210
|
+
result.forEach(function(previousType, previousIndex) {
|
|
211
|
+
if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
|
|
212
|
+
newIndex = previousIndex;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
result[newIndex] = currentType;
|
|
216
|
+
});
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
function compileMap() {
|
|
220
|
+
var result = {
|
|
221
|
+
scalar: {},
|
|
222
|
+
sequence: {},
|
|
223
|
+
mapping: {},
|
|
224
|
+
fallback: {},
|
|
225
|
+
multi: {
|
|
226
|
+
scalar: [],
|
|
227
|
+
sequence: [],
|
|
228
|
+
mapping: [],
|
|
229
|
+
fallback: []
|
|
230
|
+
}
|
|
231
|
+
}, index, length;
|
|
232
|
+
function collectType(type2) {
|
|
233
|
+
if (type2.multi) {
|
|
234
|
+
result.multi[type2.kind].push(type2);
|
|
235
|
+
result.multi["fallback"].push(type2);
|
|
236
|
+
} else {
|
|
237
|
+
result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
for (index = 0, length = arguments.length; index < length; index += 1) {
|
|
241
|
+
arguments[index].forEach(collectType);
|
|
242
|
+
}
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
function Schema$1(definition) {
|
|
246
|
+
return this.extend(definition);
|
|
247
|
+
}
|
|
248
|
+
Schema$1.prototype.extend = function extend2(definition) {
|
|
249
|
+
var implicit = [];
|
|
250
|
+
var explicit = [];
|
|
251
|
+
if (definition instanceof type) {
|
|
252
|
+
explicit.push(definition);
|
|
253
|
+
} else if (Array.isArray(definition)) {
|
|
254
|
+
explicit = explicit.concat(definition);
|
|
255
|
+
} else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
|
|
256
|
+
if (definition.implicit) implicit = implicit.concat(definition.implicit);
|
|
257
|
+
if (definition.explicit) explicit = explicit.concat(definition.explicit);
|
|
258
|
+
} else {
|
|
259
|
+
throw new exception("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");
|
|
260
|
+
}
|
|
261
|
+
implicit.forEach(function(type$1) {
|
|
262
|
+
if (!(type$1 instanceof type)) {
|
|
263
|
+
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
264
|
+
}
|
|
265
|
+
if (type$1.loadKind && type$1.loadKind !== "scalar") {
|
|
266
|
+
throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
|
|
267
|
+
}
|
|
268
|
+
if (type$1.multi) {
|
|
269
|
+
throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
explicit.forEach(function(type$1) {
|
|
273
|
+
if (!(type$1 instanceof type)) {
|
|
274
|
+
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
var result = Object.create(Schema$1.prototype);
|
|
278
|
+
result.implicit = (this.implicit || []).concat(implicit);
|
|
279
|
+
result.explicit = (this.explicit || []).concat(explicit);
|
|
280
|
+
result.compiledImplicit = compileList(result, "implicit");
|
|
281
|
+
result.compiledExplicit = compileList(result, "explicit");
|
|
282
|
+
result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
|
|
283
|
+
return result;
|
|
284
|
+
};
|
|
285
|
+
var schema = Schema$1;
|
|
286
|
+
var str = new type("tag:yaml.org,2002:str", {
|
|
287
|
+
kind: "scalar",
|
|
288
|
+
construct: function(data) {
|
|
289
|
+
return data !== null ? data : "";
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
var seq = new type("tag:yaml.org,2002:seq", {
|
|
293
|
+
kind: "sequence",
|
|
294
|
+
construct: function(data) {
|
|
295
|
+
return data !== null ? data : [];
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
var map = new type("tag:yaml.org,2002:map", {
|
|
299
|
+
kind: "mapping",
|
|
300
|
+
construct: function(data) {
|
|
301
|
+
return data !== null ? data : {};
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
var failsafe = new schema({
|
|
305
|
+
explicit: [
|
|
306
|
+
str,
|
|
307
|
+
seq,
|
|
308
|
+
map
|
|
309
|
+
]
|
|
310
|
+
});
|
|
311
|
+
function resolveYamlNull(data) {
|
|
312
|
+
if (data === null) return true;
|
|
313
|
+
var max = data.length;
|
|
314
|
+
return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
|
|
315
|
+
}
|
|
316
|
+
function constructYamlNull() {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
function isNull(object) {
|
|
320
|
+
return object === null;
|
|
321
|
+
}
|
|
322
|
+
var _null = new type("tag:yaml.org,2002:null", {
|
|
323
|
+
kind: "scalar",
|
|
324
|
+
resolve: resolveYamlNull,
|
|
325
|
+
construct: constructYamlNull,
|
|
326
|
+
predicate: isNull,
|
|
327
|
+
represent: {
|
|
328
|
+
canonical: function() {
|
|
329
|
+
return "~";
|
|
330
|
+
},
|
|
331
|
+
lowercase: function() {
|
|
332
|
+
return "null";
|
|
333
|
+
},
|
|
334
|
+
uppercase: function() {
|
|
335
|
+
return "NULL";
|
|
336
|
+
},
|
|
337
|
+
camelcase: function() {
|
|
338
|
+
return "Null";
|
|
339
|
+
},
|
|
340
|
+
empty: function() {
|
|
341
|
+
return "";
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
defaultStyle: "lowercase"
|
|
345
|
+
});
|
|
346
|
+
function resolveYamlBoolean(data) {
|
|
347
|
+
if (data === null) return false;
|
|
348
|
+
var max = data.length;
|
|
349
|
+
return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
|
|
350
|
+
}
|
|
351
|
+
function constructYamlBoolean(data) {
|
|
352
|
+
return data === "true" || data === "True" || data === "TRUE";
|
|
353
|
+
}
|
|
354
|
+
function isBoolean(object) {
|
|
355
|
+
return Object.prototype.toString.call(object) === "[object Boolean]";
|
|
356
|
+
}
|
|
357
|
+
var bool = new type("tag:yaml.org,2002:bool", {
|
|
358
|
+
kind: "scalar",
|
|
359
|
+
resolve: resolveYamlBoolean,
|
|
360
|
+
construct: constructYamlBoolean,
|
|
361
|
+
predicate: isBoolean,
|
|
362
|
+
represent: {
|
|
363
|
+
lowercase: function(object) {
|
|
364
|
+
return object ? "true" : "false";
|
|
365
|
+
},
|
|
366
|
+
uppercase: function(object) {
|
|
367
|
+
return object ? "TRUE" : "FALSE";
|
|
368
|
+
},
|
|
369
|
+
camelcase: function(object) {
|
|
370
|
+
return object ? "True" : "False";
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
defaultStyle: "lowercase"
|
|
374
|
+
});
|
|
375
|
+
function isHexCode(c) {
|
|
376
|
+
return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
|
|
377
|
+
}
|
|
378
|
+
function isOctCode(c) {
|
|
379
|
+
return 48 <= c && c <= 55;
|
|
380
|
+
}
|
|
381
|
+
function isDecCode(c) {
|
|
382
|
+
return 48 <= c && c <= 57;
|
|
383
|
+
}
|
|
384
|
+
function resolveYamlInteger(data) {
|
|
385
|
+
if (data === null) return false;
|
|
386
|
+
var max = data.length, index = 0, hasDigits = false, ch;
|
|
387
|
+
if (!max) return false;
|
|
388
|
+
ch = data[index];
|
|
389
|
+
if (ch === "-" || ch === "+") {
|
|
390
|
+
ch = data[++index];
|
|
391
|
+
}
|
|
392
|
+
if (ch === "0") {
|
|
393
|
+
if (index + 1 === max) return true;
|
|
394
|
+
ch = data[++index];
|
|
395
|
+
if (ch === "b") {
|
|
396
|
+
index++;
|
|
397
|
+
for (; index < max; index++) {
|
|
398
|
+
ch = data[index];
|
|
399
|
+
if (ch === "_") continue;
|
|
400
|
+
if (ch !== "0" && ch !== "1") return false;
|
|
401
|
+
hasDigits = true;
|
|
402
|
+
}
|
|
403
|
+
return hasDigits && ch !== "_";
|
|
404
|
+
}
|
|
405
|
+
if (ch === "x") {
|
|
406
|
+
index++;
|
|
407
|
+
for (; index < max; index++) {
|
|
408
|
+
ch = data[index];
|
|
409
|
+
if (ch === "_") continue;
|
|
410
|
+
if (!isHexCode(data.charCodeAt(index))) return false;
|
|
411
|
+
hasDigits = true;
|
|
412
|
+
}
|
|
413
|
+
return hasDigits && ch !== "_";
|
|
414
|
+
}
|
|
415
|
+
if (ch === "o") {
|
|
416
|
+
index++;
|
|
417
|
+
for (; index < max; index++) {
|
|
418
|
+
ch = data[index];
|
|
419
|
+
if (ch === "_") continue;
|
|
420
|
+
if (!isOctCode(data.charCodeAt(index))) return false;
|
|
421
|
+
hasDigits = true;
|
|
422
|
+
}
|
|
423
|
+
return hasDigits && ch !== "_";
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
if (ch === "_") return false;
|
|
427
|
+
for (; index < max; index++) {
|
|
428
|
+
ch = data[index];
|
|
429
|
+
if (ch === "_") continue;
|
|
430
|
+
if (!isDecCode(data.charCodeAt(index))) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
hasDigits = true;
|
|
434
|
+
}
|
|
435
|
+
if (!hasDigits || ch === "_") return false;
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
function constructYamlInteger(data) {
|
|
439
|
+
var value = data, sign = 1, ch;
|
|
440
|
+
if (value.indexOf("_") !== -1) {
|
|
441
|
+
value = value.replace(/_/g, "");
|
|
442
|
+
}
|
|
443
|
+
ch = value[0];
|
|
444
|
+
if (ch === "-" || ch === "+") {
|
|
445
|
+
if (ch === "-") sign = -1;
|
|
446
|
+
value = value.slice(1);
|
|
447
|
+
ch = value[0];
|
|
448
|
+
}
|
|
449
|
+
if (value === "0") return 0;
|
|
450
|
+
if (ch === "0") {
|
|
451
|
+
if (value[1] === "b") return sign * parseInt(value.slice(2), 2);
|
|
452
|
+
if (value[1] === "x") return sign * parseInt(value.slice(2), 16);
|
|
453
|
+
if (value[1] === "o") return sign * parseInt(value.slice(2), 8);
|
|
454
|
+
}
|
|
455
|
+
return sign * parseInt(value, 10);
|
|
456
|
+
}
|
|
457
|
+
function isInteger(object) {
|
|
458
|
+
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
|
|
459
|
+
}
|
|
460
|
+
var int = new type("tag:yaml.org,2002:int", {
|
|
461
|
+
kind: "scalar",
|
|
462
|
+
resolve: resolveYamlInteger,
|
|
463
|
+
construct: constructYamlInteger,
|
|
464
|
+
predicate: isInteger,
|
|
465
|
+
represent: {
|
|
466
|
+
binary: function(obj) {
|
|
467
|
+
return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
|
|
468
|
+
},
|
|
469
|
+
octal: function(obj) {
|
|
470
|
+
return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
|
|
471
|
+
},
|
|
472
|
+
decimal: function(obj) {
|
|
473
|
+
return obj.toString(10);
|
|
474
|
+
},
|
|
475
|
+
/* eslint-disable max-len */
|
|
476
|
+
hexadecimal: function(obj) {
|
|
477
|
+
return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
defaultStyle: "decimal",
|
|
481
|
+
styleAliases: {
|
|
482
|
+
binary: [2, "bin"],
|
|
483
|
+
octal: [8, "oct"],
|
|
484
|
+
decimal: [10, "dec"],
|
|
485
|
+
hexadecimal: [16, "hex"]
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
var YAML_FLOAT_PATTERN = new RegExp(
|
|
489
|
+
// 2.5e4, 2.5 and integers
|
|
490
|
+
"^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"
|
|
491
|
+
);
|
|
492
|
+
function resolveYamlFloat(data) {
|
|
493
|
+
if (data === null) return false;
|
|
494
|
+
if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
|
|
495
|
+
// Probably should update regexp & check speed
|
|
496
|
+
data[data.length - 1] === "_") {
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
function constructYamlFloat(data) {
|
|
502
|
+
var value, sign;
|
|
503
|
+
value = data.replace(/_/g, "").toLowerCase();
|
|
504
|
+
sign = value[0] === "-" ? -1 : 1;
|
|
505
|
+
if ("+-".indexOf(value[0]) >= 0) {
|
|
506
|
+
value = value.slice(1);
|
|
507
|
+
}
|
|
508
|
+
if (value === ".inf") {
|
|
509
|
+
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
510
|
+
} else if (value === ".nan") {
|
|
511
|
+
return NaN;
|
|
512
|
+
}
|
|
513
|
+
return sign * parseFloat(value, 10);
|
|
514
|
+
}
|
|
515
|
+
var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
|
516
|
+
function representYamlFloat(object, style) {
|
|
517
|
+
var res;
|
|
518
|
+
if (isNaN(object)) {
|
|
519
|
+
switch (style) {
|
|
520
|
+
case "lowercase":
|
|
521
|
+
return ".nan";
|
|
522
|
+
case "uppercase":
|
|
523
|
+
return ".NAN";
|
|
524
|
+
case "camelcase":
|
|
525
|
+
return ".NaN";
|
|
526
|
+
}
|
|
527
|
+
} else if (Number.POSITIVE_INFINITY === object) {
|
|
528
|
+
switch (style) {
|
|
529
|
+
case "lowercase":
|
|
530
|
+
return ".inf";
|
|
531
|
+
case "uppercase":
|
|
532
|
+
return ".INF";
|
|
533
|
+
case "camelcase":
|
|
534
|
+
return ".Inf";
|
|
535
|
+
}
|
|
536
|
+
} else if (Number.NEGATIVE_INFINITY === object) {
|
|
537
|
+
switch (style) {
|
|
538
|
+
case "lowercase":
|
|
539
|
+
return "-.inf";
|
|
540
|
+
case "uppercase":
|
|
541
|
+
return "-.INF";
|
|
542
|
+
case "camelcase":
|
|
543
|
+
return "-.Inf";
|
|
544
|
+
}
|
|
545
|
+
} else if (common.isNegativeZero(object)) {
|
|
546
|
+
return "-0.0";
|
|
547
|
+
}
|
|
548
|
+
res = object.toString(10);
|
|
549
|
+
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
|
|
550
|
+
}
|
|
551
|
+
function isFloat(object) {
|
|
552
|
+
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
|
|
553
|
+
}
|
|
554
|
+
var float = new type("tag:yaml.org,2002:float", {
|
|
555
|
+
kind: "scalar",
|
|
556
|
+
resolve: resolveYamlFloat,
|
|
557
|
+
construct: constructYamlFloat,
|
|
558
|
+
predicate: isFloat,
|
|
559
|
+
represent: representYamlFloat,
|
|
560
|
+
defaultStyle: "lowercase"
|
|
561
|
+
});
|
|
562
|
+
var json = failsafe.extend({
|
|
563
|
+
implicit: [
|
|
564
|
+
_null,
|
|
565
|
+
bool,
|
|
566
|
+
int,
|
|
567
|
+
float
|
|
568
|
+
]
|
|
569
|
+
});
|
|
570
|
+
var core = json;
|
|
571
|
+
var YAML_DATE_REGEXP = new RegExp(
|
|
572
|
+
"^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"
|
|
573
|
+
);
|
|
574
|
+
var YAML_TIMESTAMP_REGEXP = new RegExp(
|
|
575
|
+
"^([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]))?))?$"
|
|
576
|
+
);
|
|
577
|
+
function resolveYamlTimestamp(data) {
|
|
578
|
+
if (data === null) return false;
|
|
579
|
+
if (YAML_DATE_REGEXP.exec(data) !== null) return true;
|
|
580
|
+
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
function constructYamlTimestamp(data) {
|
|
584
|
+
var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
|
|
585
|
+
match = YAML_DATE_REGEXP.exec(data);
|
|
586
|
+
if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
|
|
587
|
+
if (match === null) throw new Error("Date resolve error");
|
|
588
|
+
year = +match[1];
|
|
589
|
+
month = +match[2] - 1;
|
|
590
|
+
day = +match[3];
|
|
591
|
+
if (!match[4]) {
|
|
592
|
+
return new Date(Date.UTC(year, month, day));
|
|
593
|
+
}
|
|
594
|
+
hour = +match[4];
|
|
595
|
+
minute = +match[5];
|
|
596
|
+
second = +match[6];
|
|
597
|
+
if (match[7]) {
|
|
598
|
+
fraction = match[7].slice(0, 3);
|
|
599
|
+
while (fraction.length < 3) {
|
|
600
|
+
fraction += "0";
|
|
601
|
+
}
|
|
602
|
+
fraction = +fraction;
|
|
603
|
+
}
|
|
604
|
+
if (match[9]) {
|
|
605
|
+
tz_hour = +match[10];
|
|
606
|
+
tz_minute = +(match[11] || 0);
|
|
607
|
+
delta = (tz_hour * 60 + tz_minute) * 6e4;
|
|
608
|
+
if (match[9] === "-") delta = -delta;
|
|
609
|
+
}
|
|
610
|
+
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
611
|
+
if (delta) date.setTime(date.getTime() - delta);
|
|
612
|
+
return date;
|
|
613
|
+
}
|
|
614
|
+
function representYamlTimestamp(object) {
|
|
615
|
+
return object.toISOString();
|
|
616
|
+
}
|
|
617
|
+
var timestamp = new type("tag:yaml.org,2002:timestamp", {
|
|
618
|
+
kind: "scalar",
|
|
619
|
+
resolve: resolveYamlTimestamp,
|
|
620
|
+
construct: constructYamlTimestamp,
|
|
621
|
+
instanceOf: Date,
|
|
622
|
+
represent: representYamlTimestamp
|
|
623
|
+
});
|
|
624
|
+
function resolveYamlMerge(data) {
|
|
625
|
+
return data === "<<" || data === null;
|
|
626
|
+
}
|
|
627
|
+
var merge = new type("tag:yaml.org,2002:merge", {
|
|
628
|
+
kind: "scalar",
|
|
629
|
+
resolve: resolveYamlMerge
|
|
630
|
+
});
|
|
631
|
+
var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
|
|
632
|
+
function resolveYamlBinary(data) {
|
|
633
|
+
if (data === null) return false;
|
|
634
|
+
var code, idx, bitlen = 0, max = data.length, map2 = BASE64_MAP;
|
|
635
|
+
for (idx = 0; idx < max; idx++) {
|
|
636
|
+
code = map2.indexOf(data.charAt(idx));
|
|
637
|
+
if (code > 64) continue;
|
|
638
|
+
if (code < 0) return false;
|
|
639
|
+
bitlen += 6;
|
|
640
|
+
}
|
|
641
|
+
return bitlen % 8 === 0;
|
|
642
|
+
}
|
|
643
|
+
function constructYamlBinary(data) {
|
|
644
|
+
var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map2 = BASE64_MAP, bits = 0, result = [];
|
|
645
|
+
for (idx = 0; idx < max; idx++) {
|
|
646
|
+
if (idx % 4 === 0 && idx) {
|
|
647
|
+
result.push(bits >> 16 & 255);
|
|
648
|
+
result.push(bits >> 8 & 255);
|
|
649
|
+
result.push(bits & 255);
|
|
650
|
+
}
|
|
651
|
+
bits = bits << 6 | map2.indexOf(input.charAt(idx));
|
|
652
|
+
}
|
|
653
|
+
tailbits = max % 4 * 6;
|
|
654
|
+
if (tailbits === 0) {
|
|
655
|
+
result.push(bits >> 16 & 255);
|
|
656
|
+
result.push(bits >> 8 & 255);
|
|
657
|
+
result.push(bits & 255);
|
|
658
|
+
} else if (tailbits === 18) {
|
|
659
|
+
result.push(bits >> 10 & 255);
|
|
660
|
+
result.push(bits >> 2 & 255);
|
|
661
|
+
} else if (tailbits === 12) {
|
|
662
|
+
result.push(bits >> 4 & 255);
|
|
663
|
+
}
|
|
664
|
+
return new Uint8Array(result);
|
|
665
|
+
}
|
|
666
|
+
function representYamlBinary(object) {
|
|
667
|
+
var result = "", bits = 0, idx, tail, max = object.length, map2 = BASE64_MAP;
|
|
668
|
+
for (idx = 0; idx < max; idx++) {
|
|
669
|
+
if (idx % 3 === 0 && idx) {
|
|
670
|
+
result += map2[bits >> 18 & 63];
|
|
671
|
+
result += map2[bits >> 12 & 63];
|
|
672
|
+
result += map2[bits >> 6 & 63];
|
|
673
|
+
result += map2[bits & 63];
|
|
674
|
+
}
|
|
675
|
+
bits = (bits << 8) + object[idx];
|
|
676
|
+
}
|
|
677
|
+
tail = max % 3;
|
|
678
|
+
if (tail === 0) {
|
|
679
|
+
result += map2[bits >> 18 & 63];
|
|
680
|
+
result += map2[bits >> 12 & 63];
|
|
681
|
+
result += map2[bits >> 6 & 63];
|
|
682
|
+
result += map2[bits & 63];
|
|
683
|
+
} else if (tail === 2) {
|
|
684
|
+
result += map2[bits >> 10 & 63];
|
|
685
|
+
result += map2[bits >> 4 & 63];
|
|
686
|
+
result += map2[bits << 2 & 63];
|
|
687
|
+
result += map2[64];
|
|
688
|
+
} else if (tail === 1) {
|
|
689
|
+
result += map2[bits >> 2 & 63];
|
|
690
|
+
result += map2[bits << 4 & 63];
|
|
691
|
+
result += map2[64];
|
|
692
|
+
result += map2[64];
|
|
693
|
+
}
|
|
694
|
+
return result;
|
|
695
|
+
}
|
|
696
|
+
function isBinary(obj) {
|
|
697
|
+
return Object.prototype.toString.call(obj) === "[object Uint8Array]";
|
|
698
|
+
}
|
|
699
|
+
var binary = new type("tag:yaml.org,2002:binary", {
|
|
700
|
+
kind: "scalar",
|
|
701
|
+
resolve: resolveYamlBinary,
|
|
702
|
+
construct: constructYamlBinary,
|
|
703
|
+
predicate: isBinary,
|
|
704
|
+
represent: representYamlBinary
|
|
705
|
+
});
|
|
706
|
+
var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
707
|
+
var _toString$2 = Object.prototype.toString;
|
|
708
|
+
function resolveYamlOmap(data) {
|
|
709
|
+
if (data === null) return true;
|
|
710
|
+
var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
|
|
711
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
712
|
+
pair = object[index];
|
|
713
|
+
pairHasKey = false;
|
|
714
|
+
if (_toString$2.call(pair) !== "[object Object]") return false;
|
|
715
|
+
for (pairKey in pair) {
|
|
716
|
+
if (_hasOwnProperty$3.call(pair, pairKey)) {
|
|
717
|
+
if (!pairHasKey) pairHasKey = true;
|
|
718
|
+
else return false;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (!pairHasKey) return false;
|
|
722
|
+
if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
|
|
723
|
+
else return false;
|
|
724
|
+
}
|
|
725
|
+
return true;
|
|
726
|
+
}
|
|
727
|
+
function constructYamlOmap(data) {
|
|
728
|
+
return data !== null ? data : [];
|
|
729
|
+
}
|
|
730
|
+
var omap = new type("tag:yaml.org,2002:omap", {
|
|
731
|
+
kind: "sequence",
|
|
732
|
+
resolve: resolveYamlOmap,
|
|
733
|
+
construct: constructYamlOmap
|
|
734
|
+
});
|
|
735
|
+
var _toString$1 = Object.prototype.toString;
|
|
736
|
+
function resolveYamlPairs(data) {
|
|
737
|
+
if (data === null) return true;
|
|
738
|
+
var index, length, pair, keys, result, object = data;
|
|
739
|
+
result = new Array(object.length);
|
|
740
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
741
|
+
pair = object[index];
|
|
742
|
+
if (_toString$1.call(pair) !== "[object Object]") return false;
|
|
743
|
+
keys = Object.keys(pair);
|
|
744
|
+
if (keys.length !== 1) return false;
|
|
745
|
+
result[index] = [keys[0], pair[keys[0]]];
|
|
746
|
+
}
|
|
747
|
+
return true;
|
|
748
|
+
}
|
|
749
|
+
function constructYamlPairs(data) {
|
|
750
|
+
if (data === null) return [];
|
|
751
|
+
var index, length, pair, keys, result, object = data;
|
|
752
|
+
result = new Array(object.length);
|
|
753
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
754
|
+
pair = object[index];
|
|
755
|
+
keys = Object.keys(pair);
|
|
756
|
+
result[index] = [keys[0], pair[keys[0]]];
|
|
757
|
+
}
|
|
758
|
+
return result;
|
|
759
|
+
}
|
|
760
|
+
var pairs = new type("tag:yaml.org,2002:pairs", {
|
|
761
|
+
kind: "sequence",
|
|
762
|
+
resolve: resolveYamlPairs,
|
|
763
|
+
construct: constructYamlPairs
|
|
764
|
+
});
|
|
765
|
+
var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
766
|
+
function resolveYamlSet(data) {
|
|
767
|
+
if (data === null) return true;
|
|
768
|
+
var key, object = data;
|
|
769
|
+
for (key in object) {
|
|
770
|
+
if (_hasOwnProperty$2.call(object, key)) {
|
|
771
|
+
if (object[key] !== null) return false;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
776
|
+
function constructYamlSet(data) {
|
|
777
|
+
return data !== null ? data : {};
|
|
778
|
+
}
|
|
779
|
+
var set = new type("tag:yaml.org,2002:set", {
|
|
780
|
+
kind: "mapping",
|
|
781
|
+
resolve: resolveYamlSet,
|
|
782
|
+
construct: constructYamlSet
|
|
783
|
+
});
|
|
784
|
+
var _default = core.extend({
|
|
785
|
+
implicit: [
|
|
786
|
+
timestamp,
|
|
787
|
+
merge
|
|
788
|
+
],
|
|
789
|
+
explicit: [
|
|
790
|
+
binary,
|
|
791
|
+
omap,
|
|
792
|
+
pairs,
|
|
793
|
+
set
|
|
794
|
+
]
|
|
795
|
+
});
|
|
796
|
+
var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
797
|
+
var CONTEXT_FLOW_IN = 1;
|
|
798
|
+
var CONTEXT_FLOW_OUT = 2;
|
|
799
|
+
var CONTEXT_BLOCK_IN = 3;
|
|
800
|
+
var CONTEXT_BLOCK_OUT = 4;
|
|
801
|
+
var CHOMPING_CLIP = 1;
|
|
802
|
+
var CHOMPING_STRIP = 2;
|
|
803
|
+
var CHOMPING_KEEP = 3;
|
|
804
|
+
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
|
805
|
+
var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
|
|
806
|
+
var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
|
|
807
|
+
var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
|
|
808
|
+
var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
|
|
809
|
+
function _class(obj) {
|
|
810
|
+
return Object.prototype.toString.call(obj);
|
|
811
|
+
}
|
|
812
|
+
function is_EOL(c) {
|
|
813
|
+
return c === 10 || c === 13;
|
|
814
|
+
}
|
|
815
|
+
function is_WHITE_SPACE(c) {
|
|
816
|
+
return c === 9 || c === 32;
|
|
817
|
+
}
|
|
818
|
+
function is_WS_OR_EOL(c) {
|
|
819
|
+
return c === 9 || c === 32 || c === 10 || c === 13;
|
|
820
|
+
}
|
|
821
|
+
function is_FLOW_INDICATOR(c) {
|
|
822
|
+
return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
|
|
823
|
+
}
|
|
824
|
+
function fromHexCode(c) {
|
|
825
|
+
var lc;
|
|
826
|
+
if (48 <= c && c <= 57) {
|
|
827
|
+
return c - 48;
|
|
828
|
+
}
|
|
829
|
+
lc = c | 32;
|
|
830
|
+
if (97 <= lc && lc <= 102) {
|
|
831
|
+
return lc - 97 + 10;
|
|
832
|
+
}
|
|
833
|
+
return -1;
|
|
834
|
+
}
|
|
835
|
+
function escapedHexLen(c) {
|
|
836
|
+
if (c === 120) {
|
|
837
|
+
return 2;
|
|
838
|
+
}
|
|
839
|
+
if (c === 117) {
|
|
840
|
+
return 4;
|
|
841
|
+
}
|
|
842
|
+
if (c === 85) {
|
|
843
|
+
return 8;
|
|
844
|
+
}
|
|
845
|
+
return 0;
|
|
846
|
+
}
|
|
847
|
+
function fromDecimalCode(c) {
|
|
848
|
+
if (48 <= c && c <= 57) {
|
|
849
|
+
return c - 48;
|
|
850
|
+
}
|
|
851
|
+
return -1;
|
|
852
|
+
}
|
|
853
|
+
function simpleEscapeSequence(c) {
|
|
854
|
+
return c === 48 ? "\0" : c === 97 ? "\x07" : c === 98 ? "\b" : c === 116 ? " " : c === 9 ? " " : c === 110 ? "\n" : c === 118 ? "\v" : c === 102 ? "\f" : c === 114 ? "\r" : c === 101 ? "\x1B" : c === 32 ? " " : c === 34 ? '"' : c === 47 ? "/" : c === 92 ? "\\" : c === 78 ? "\x85" : c === 95 ? "\xA0" : c === 76 ? "\u2028" : c === 80 ? "\u2029" : "";
|
|
855
|
+
}
|
|
856
|
+
function charFromCodepoint(c) {
|
|
857
|
+
if (c <= 65535) {
|
|
858
|
+
return String.fromCharCode(c);
|
|
859
|
+
}
|
|
860
|
+
return String.fromCharCode(
|
|
861
|
+
(c - 65536 >> 10) + 55296,
|
|
862
|
+
(c - 65536 & 1023) + 56320
|
|
863
|
+
);
|
|
864
|
+
}
|
|
865
|
+
function setProperty(object, key, value) {
|
|
866
|
+
if (key === "__proto__") {
|
|
867
|
+
Object.defineProperty(object, key, {
|
|
868
|
+
configurable: true,
|
|
869
|
+
enumerable: true,
|
|
870
|
+
writable: true,
|
|
871
|
+
value
|
|
872
|
+
});
|
|
873
|
+
} else {
|
|
874
|
+
object[key] = value;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
var simpleEscapeCheck = new Array(256);
|
|
878
|
+
var simpleEscapeMap = new Array(256);
|
|
879
|
+
for (i = 0; i < 256; i++) {
|
|
880
|
+
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|
881
|
+
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|
882
|
+
}
|
|
883
|
+
var i;
|
|
884
|
+
function State$1(input, options) {
|
|
885
|
+
this.input = input;
|
|
886
|
+
this.filename = options["filename"] || null;
|
|
887
|
+
this.schema = options["schema"] || _default;
|
|
888
|
+
this.onWarning = options["onWarning"] || null;
|
|
889
|
+
this.legacy = options["legacy"] || false;
|
|
890
|
+
this.json = options["json"] || false;
|
|
891
|
+
this.listener = options["listener"] || null;
|
|
892
|
+
this.implicitTypes = this.schema.compiledImplicit;
|
|
893
|
+
this.typeMap = this.schema.compiledTypeMap;
|
|
894
|
+
this.length = input.length;
|
|
895
|
+
this.position = 0;
|
|
896
|
+
this.line = 0;
|
|
897
|
+
this.lineStart = 0;
|
|
898
|
+
this.lineIndent = 0;
|
|
899
|
+
this.firstTabInLine = -1;
|
|
900
|
+
this.documents = [];
|
|
901
|
+
}
|
|
902
|
+
function generateError(state, message) {
|
|
903
|
+
var mark = {
|
|
904
|
+
name: state.filename,
|
|
905
|
+
buffer: state.input.slice(0, -1),
|
|
906
|
+
// omit trailing \0
|
|
907
|
+
position: state.position,
|
|
908
|
+
line: state.line,
|
|
909
|
+
column: state.position - state.lineStart
|
|
910
|
+
};
|
|
911
|
+
mark.snippet = snippet(mark);
|
|
912
|
+
return new exception(message, mark);
|
|
913
|
+
}
|
|
914
|
+
function throwError(state, message) {
|
|
915
|
+
throw generateError(state, message);
|
|
916
|
+
}
|
|
917
|
+
function throwWarning(state, message) {
|
|
918
|
+
if (state.onWarning) {
|
|
919
|
+
state.onWarning.call(null, generateError(state, message));
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
var directiveHandlers = {
|
|
923
|
+
YAML: function handleYamlDirective(state, name, args) {
|
|
924
|
+
var match, major, minor;
|
|
925
|
+
if (state.version !== null) {
|
|
926
|
+
throwError(state, "duplication of %YAML directive");
|
|
927
|
+
}
|
|
928
|
+
if (args.length !== 1) {
|
|
929
|
+
throwError(state, "YAML directive accepts exactly one argument");
|
|
930
|
+
}
|
|
931
|
+
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
932
|
+
if (match === null) {
|
|
933
|
+
throwError(state, "ill-formed argument of the YAML directive");
|
|
934
|
+
}
|
|
935
|
+
major = parseInt(match[1], 10);
|
|
936
|
+
minor = parseInt(match[2], 10);
|
|
937
|
+
if (major !== 1) {
|
|
938
|
+
throwError(state, "unacceptable YAML version of the document");
|
|
939
|
+
}
|
|
940
|
+
state.version = args[0];
|
|
941
|
+
state.checkLineBreaks = minor < 2;
|
|
942
|
+
if (minor !== 1 && minor !== 2) {
|
|
943
|
+
throwWarning(state, "unsupported YAML version of the document");
|
|
944
|
+
}
|
|
945
|
+
},
|
|
946
|
+
TAG: function handleTagDirective(state, name, args) {
|
|
947
|
+
var handle, prefix;
|
|
948
|
+
if (args.length !== 2) {
|
|
949
|
+
throwError(state, "TAG directive accepts exactly two arguments");
|
|
950
|
+
}
|
|
951
|
+
handle = args[0];
|
|
952
|
+
prefix = args[1];
|
|
953
|
+
if (!PATTERN_TAG_HANDLE.test(handle)) {
|
|
954
|
+
throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
955
|
+
}
|
|
956
|
+
if (_hasOwnProperty$1.call(state.tagMap, handle)) {
|
|
957
|
+
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
|
958
|
+
}
|
|
959
|
+
if (!PATTERN_TAG_URI.test(prefix)) {
|
|
960
|
+
throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
961
|
+
}
|
|
962
|
+
try {
|
|
963
|
+
prefix = decodeURIComponent(prefix);
|
|
964
|
+
} catch (err) {
|
|
965
|
+
throwError(state, "tag prefix is malformed: " + prefix);
|
|
966
|
+
}
|
|
967
|
+
state.tagMap[handle] = prefix;
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
function captureSegment(state, start, end, checkJson) {
|
|
971
|
+
var _position, _length, _character, _result;
|
|
972
|
+
if (start < end) {
|
|
973
|
+
_result = state.input.slice(start, end);
|
|
974
|
+
if (checkJson) {
|
|
975
|
+
for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
|
|
976
|
+
_character = _result.charCodeAt(_position);
|
|
977
|
+
if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
|
|
978
|
+
throwError(state, "expected valid JSON character");
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
|
982
|
+
throwError(state, "the stream contains non-printable characters");
|
|
983
|
+
}
|
|
984
|
+
state.result += _result;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
function mergeMappings(state, destination, source, overridableKeys) {
|
|
988
|
+
var sourceKeys, key, index, quantity;
|
|
989
|
+
if (!common.isObject(source)) {
|
|
990
|
+
throwError(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
991
|
+
}
|
|
992
|
+
sourceKeys = Object.keys(source);
|
|
993
|
+
for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
|
|
994
|
+
key = sourceKeys[index];
|
|
995
|
+
if (!_hasOwnProperty$1.call(destination, key)) {
|
|
996
|
+
setProperty(destination, key, source[key]);
|
|
997
|
+
overridableKeys[key] = true;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) {
|
|
1002
|
+
var index, quantity;
|
|
1003
|
+
if (Array.isArray(keyNode)) {
|
|
1004
|
+
keyNode = Array.prototype.slice.call(keyNode);
|
|
1005
|
+
for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
|
|
1006
|
+
if (Array.isArray(keyNode[index])) {
|
|
1007
|
+
throwError(state, "nested arrays are not supported inside keys");
|
|
1008
|
+
}
|
|
1009
|
+
if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
|
|
1010
|
+
keyNode[index] = "[object Object]";
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
|
|
1015
|
+
keyNode = "[object Object]";
|
|
1016
|
+
}
|
|
1017
|
+
keyNode = String(keyNode);
|
|
1018
|
+
if (_result === null) {
|
|
1019
|
+
_result = {};
|
|
1020
|
+
}
|
|
1021
|
+
if (keyTag === "tag:yaml.org,2002:merge") {
|
|
1022
|
+
if (Array.isArray(valueNode)) {
|
|
1023
|
+
for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
|
|
1024
|
+
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|
1025
|
+
}
|
|
1026
|
+
} else {
|
|
1027
|
+
mergeMappings(state, _result, valueNode, overridableKeys);
|
|
1028
|
+
}
|
|
1029
|
+
} else {
|
|
1030
|
+
if (!state.json && !_hasOwnProperty$1.call(overridableKeys, keyNode) && _hasOwnProperty$1.call(_result, keyNode)) {
|
|
1031
|
+
state.line = startLine || state.line;
|
|
1032
|
+
state.lineStart = startLineStart || state.lineStart;
|
|
1033
|
+
state.position = startPos || state.position;
|
|
1034
|
+
throwError(state, "duplicated mapping key");
|
|
1035
|
+
}
|
|
1036
|
+
setProperty(_result, keyNode, valueNode);
|
|
1037
|
+
delete overridableKeys[keyNode];
|
|
1038
|
+
}
|
|
1039
|
+
return _result;
|
|
1040
|
+
}
|
|
1041
|
+
function readLineBreak(state) {
|
|
1042
|
+
var ch;
|
|
1043
|
+
ch = state.input.charCodeAt(state.position);
|
|
1044
|
+
if (ch === 10) {
|
|
1045
|
+
state.position++;
|
|
1046
|
+
} else if (ch === 13) {
|
|
1047
|
+
state.position++;
|
|
1048
|
+
if (state.input.charCodeAt(state.position) === 10) {
|
|
1049
|
+
state.position++;
|
|
1050
|
+
}
|
|
1051
|
+
} else {
|
|
1052
|
+
throwError(state, "a line break is expected");
|
|
1053
|
+
}
|
|
1054
|
+
state.line += 1;
|
|
1055
|
+
state.lineStart = state.position;
|
|
1056
|
+
state.firstTabInLine = -1;
|
|
1057
|
+
}
|
|
1058
|
+
function skipSeparationSpace(state, allowComments, checkIndent) {
|
|
1059
|
+
var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
|
|
1060
|
+
while (ch !== 0) {
|
|
1061
|
+
while (is_WHITE_SPACE(ch)) {
|
|
1062
|
+
if (ch === 9 && state.firstTabInLine === -1) {
|
|
1063
|
+
state.firstTabInLine = state.position;
|
|
1064
|
+
}
|
|
1065
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1066
|
+
}
|
|
1067
|
+
if (allowComments && ch === 35) {
|
|
1068
|
+
do {
|
|
1069
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1070
|
+
} while (ch !== 10 && ch !== 13 && ch !== 0);
|
|
1071
|
+
}
|
|
1072
|
+
if (is_EOL(ch)) {
|
|
1073
|
+
readLineBreak(state);
|
|
1074
|
+
ch = state.input.charCodeAt(state.position);
|
|
1075
|
+
lineBreaks++;
|
|
1076
|
+
state.lineIndent = 0;
|
|
1077
|
+
while (ch === 32) {
|
|
1078
|
+
state.lineIndent++;
|
|
1079
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1080
|
+
}
|
|
1081
|
+
} else {
|
|
1082
|
+
break;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|
1086
|
+
throwWarning(state, "deficient indentation");
|
|
1087
|
+
}
|
|
1088
|
+
return lineBreaks;
|
|
1089
|
+
}
|
|
1090
|
+
function testDocumentSeparator(state) {
|
|
1091
|
+
var _position = state.position, ch;
|
|
1092
|
+
ch = state.input.charCodeAt(_position);
|
|
1093
|
+
if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
|
|
1094
|
+
_position += 3;
|
|
1095
|
+
ch = state.input.charCodeAt(_position);
|
|
1096
|
+
if (ch === 0 || is_WS_OR_EOL(ch)) {
|
|
1097
|
+
return true;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
return false;
|
|
1101
|
+
}
|
|
1102
|
+
function writeFoldedLines(state, count) {
|
|
1103
|
+
if (count === 1) {
|
|
1104
|
+
state.result += " ";
|
|
1105
|
+
} else if (count > 1) {
|
|
1106
|
+
state.result += common.repeat("\n", count - 1);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
1110
|
+
var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
|
|
1111
|
+
ch = state.input.charCodeAt(state.position);
|
|
1112
|
+
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) {
|
|
1113
|
+
return false;
|
|
1114
|
+
}
|
|
1115
|
+
if (ch === 63 || ch === 45) {
|
|
1116
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1117
|
+
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1118
|
+
return false;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
state.kind = "scalar";
|
|
1122
|
+
state.result = "";
|
|
1123
|
+
captureStart = captureEnd = state.position;
|
|
1124
|
+
hasPendingContent = false;
|
|
1125
|
+
while (ch !== 0) {
|
|
1126
|
+
if (ch === 58) {
|
|
1127
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1128
|
+
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1129
|
+
break;
|
|
1130
|
+
}
|
|
1131
|
+
} else if (ch === 35) {
|
|
1132
|
+
preceding = state.input.charCodeAt(state.position - 1);
|
|
1133
|
+
if (is_WS_OR_EOL(preceding)) {
|
|
1134
|
+
break;
|
|
1135
|
+
}
|
|
1136
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
|
1137
|
+
break;
|
|
1138
|
+
} else if (is_EOL(ch)) {
|
|
1139
|
+
_line = state.line;
|
|
1140
|
+
_lineStart = state.lineStart;
|
|
1141
|
+
_lineIndent = state.lineIndent;
|
|
1142
|
+
skipSeparationSpace(state, false, -1);
|
|
1143
|
+
if (state.lineIndent >= nodeIndent) {
|
|
1144
|
+
hasPendingContent = true;
|
|
1145
|
+
ch = state.input.charCodeAt(state.position);
|
|
1146
|
+
continue;
|
|
1147
|
+
} else {
|
|
1148
|
+
state.position = captureEnd;
|
|
1149
|
+
state.line = _line;
|
|
1150
|
+
state.lineStart = _lineStart;
|
|
1151
|
+
state.lineIndent = _lineIndent;
|
|
1152
|
+
break;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
if (hasPendingContent) {
|
|
1156
|
+
captureSegment(state, captureStart, captureEnd, false);
|
|
1157
|
+
writeFoldedLines(state, state.line - _line);
|
|
1158
|
+
captureStart = captureEnd = state.position;
|
|
1159
|
+
hasPendingContent = false;
|
|
1160
|
+
}
|
|
1161
|
+
if (!is_WHITE_SPACE(ch)) {
|
|
1162
|
+
captureEnd = state.position + 1;
|
|
1163
|
+
}
|
|
1164
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1165
|
+
}
|
|
1166
|
+
captureSegment(state, captureStart, captureEnd, false);
|
|
1167
|
+
if (state.result) {
|
|
1168
|
+
return true;
|
|
1169
|
+
}
|
|
1170
|
+
state.kind = _kind;
|
|
1171
|
+
state.result = _result;
|
|
1172
|
+
return false;
|
|
1173
|
+
}
|
|
1174
|
+
function readSingleQuotedScalar(state, nodeIndent) {
|
|
1175
|
+
var ch, captureStart, captureEnd;
|
|
1176
|
+
ch = state.input.charCodeAt(state.position);
|
|
1177
|
+
if (ch !== 39) {
|
|
1178
|
+
return false;
|
|
1179
|
+
}
|
|
1180
|
+
state.kind = "scalar";
|
|
1181
|
+
state.result = "";
|
|
1182
|
+
state.position++;
|
|
1183
|
+
captureStart = captureEnd = state.position;
|
|
1184
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1185
|
+
if (ch === 39) {
|
|
1186
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1187
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1188
|
+
if (ch === 39) {
|
|
1189
|
+
captureStart = state.position;
|
|
1190
|
+
state.position++;
|
|
1191
|
+
captureEnd = state.position;
|
|
1192
|
+
} else {
|
|
1193
|
+
return true;
|
|
1194
|
+
}
|
|
1195
|
+
} else if (is_EOL(ch)) {
|
|
1196
|
+
captureSegment(state, captureStart, captureEnd, true);
|
|
1197
|
+
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1198
|
+
captureStart = captureEnd = state.position;
|
|
1199
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1200
|
+
throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
1201
|
+
} else {
|
|
1202
|
+
state.position++;
|
|
1203
|
+
captureEnd = state.position;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
1207
|
+
}
|
|
1208
|
+
function readDoubleQuotedScalar(state, nodeIndent) {
|
|
1209
|
+
var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
|
|
1210
|
+
ch = state.input.charCodeAt(state.position);
|
|
1211
|
+
if (ch !== 34) {
|
|
1212
|
+
return false;
|
|
1213
|
+
}
|
|
1214
|
+
state.kind = "scalar";
|
|
1215
|
+
state.result = "";
|
|
1216
|
+
state.position++;
|
|
1217
|
+
captureStart = captureEnd = state.position;
|
|
1218
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1219
|
+
if (ch === 34) {
|
|
1220
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1221
|
+
state.position++;
|
|
1222
|
+
return true;
|
|
1223
|
+
} else if (ch === 92) {
|
|
1224
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1225
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1226
|
+
if (is_EOL(ch)) {
|
|
1227
|
+
skipSeparationSpace(state, false, nodeIndent);
|
|
1228
|
+
} else if (ch < 256 && simpleEscapeCheck[ch]) {
|
|
1229
|
+
state.result += simpleEscapeMap[ch];
|
|
1230
|
+
state.position++;
|
|
1231
|
+
} else if ((tmp = escapedHexLen(ch)) > 0) {
|
|
1232
|
+
hexLength = tmp;
|
|
1233
|
+
hexResult = 0;
|
|
1234
|
+
for (; hexLength > 0; hexLength--) {
|
|
1235
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1236
|
+
if ((tmp = fromHexCode(ch)) >= 0) {
|
|
1237
|
+
hexResult = (hexResult << 4) + tmp;
|
|
1238
|
+
} else {
|
|
1239
|
+
throwError(state, "expected hexadecimal character");
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
state.result += charFromCodepoint(hexResult);
|
|
1243
|
+
state.position++;
|
|
1244
|
+
} else {
|
|
1245
|
+
throwError(state, "unknown escape sequence");
|
|
1246
|
+
}
|
|
1247
|
+
captureStart = captureEnd = state.position;
|
|
1248
|
+
} else if (is_EOL(ch)) {
|
|
1249
|
+
captureSegment(state, captureStart, captureEnd, true);
|
|
1250
|
+
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1251
|
+
captureStart = captureEnd = state.position;
|
|
1252
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1253
|
+
throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
1254
|
+
} else {
|
|
1255
|
+
state.position++;
|
|
1256
|
+
captureEnd = state.position;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
1260
|
+
}
|
|
1261
|
+
function readFlowCollection(state, nodeIndent) {
|
|
1262
|
+
var readNext = true, _line, _lineStart, _pos, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = /* @__PURE__ */ Object.create(null), keyNode, keyTag, valueNode, ch;
|
|
1263
|
+
ch = state.input.charCodeAt(state.position);
|
|
1264
|
+
if (ch === 91) {
|
|
1265
|
+
terminator = 93;
|
|
1266
|
+
isMapping = false;
|
|
1267
|
+
_result = [];
|
|
1268
|
+
} else if (ch === 123) {
|
|
1269
|
+
terminator = 125;
|
|
1270
|
+
isMapping = true;
|
|
1271
|
+
_result = {};
|
|
1272
|
+
} else {
|
|
1273
|
+
return false;
|
|
1274
|
+
}
|
|
1275
|
+
if (state.anchor !== null) {
|
|
1276
|
+
state.anchorMap[state.anchor] = _result;
|
|
1277
|
+
}
|
|
1278
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1279
|
+
while (ch !== 0) {
|
|
1280
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1281
|
+
ch = state.input.charCodeAt(state.position);
|
|
1282
|
+
if (ch === terminator) {
|
|
1283
|
+
state.position++;
|
|
1284
|
+
state.tag = _tag;
|
|
1285
|
+
state.anchor = _anchor;
|
|
1286
|
+
state.kind = isMapping ? "mapping" : "sequence";
|
|
1287
|
+
state.result = _result;
|
|
1288
|
+
return true;
|
|
1289
|
+
} else if (!readNext) {
|
|
1290
|
+
throwError(state, "missed comma between flow collection entries");
|
|
1291
|
+
} else if (ch === 44) {
|
|
1292
|
+
throwError(state, "expected the node content, but found ','");
|
|
1293
|
+
}
|
|
1294
|
+
keyTag = keyNode = valueNode = null;
|
|
1295
|
+
isPair = isExplicitPair = false;
|
|
1296
|
+
if (ch === 63) {
|
|
1297
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1298
|
+
if (is_WS_OR_EOL(following)) {
|
|
1299
|
+
isPair = isExplicitPair = true;
|
|
1300
|
+
state.position++;
|
|
1301
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
_line = state.line;
|
|
1305
|
+
_lineStart = state.lineStart;
|
|
1306
|
+
_pos = state.position;
|
|
1307
|
+
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1308
|
+
keyTag = state.tag;
|
|
1309
|
+
keyNode = state.result;
|
|
1310
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1311
|
+
ch = state.input.charCodeAt(state.position);
|
|
1312
|
+
if ((isExplicitPair || state.line === _line) && ch === 58) {
|
|
1313
|
+
isPair = true;
|
|
1314
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1315
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1316
|
+
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1317
|
+
valueNode = state.result;
|
|
1318
|
+
}
|
|
1319
|
+
if (isMapping) {
|
|
1320
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
|
|
1321
|
+
} else if (isPair) {
|
|
1322
|
+
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
|
|
1323
|
+
} else {
|
|
1324
|
+
_result.push(keyNode);
|
|
1325
|
+
}
|
|
1326
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1327
|
+
ch = state.input.charCodeAt(state.position);
|
|
1328
|
+
if (ch === 44) {
|
|
1329
|
+
readNext = true;
|
|
1330
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1331
|
+
} else {
|
|
1332
|
+
readNext = false;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
throwError(state, "unexpected end of the stream within a flow collection");
|
|
1336
|
+
}
|
|
1337
|
+
function readBlockScalar(state, nodeIndent) {
|
|
1338
|
+
var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
|
|
1339
|
+
ch = state.input.charCodeAt(state.position);
|
|
1340
|
+
if (ch === 124) {
|
|
1341
|
+
folding = false;
|
|
1342
|
+
} else if (ch === 62) {
|
|
1343
|
+
folding = true;
|
|
1344
|
+
} else {
|
|
1345
|
+
return false;
|
|
1346
|
+
}
|
|
1347
|
+
state.kind = "scalar";
|
|
1348
|
+
state.result = "";
|
|
1349
|
+
while (ch !== 0) {
|
|
1350
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1351
|
+
if (ch === 43 || ch === 45) {
|
|
1352
|
+
if (CHOMPING_CLIP === chomping) {
|
|
1353
|
+
chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
1354
|
+
} else {
|
|
1355
|
+
throwError(state, "repeat of a chomping mode identifier");
|
|
1356
|
+
}
|
|
1357
|
+
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
|
1358
|
+
if (tmp === 0) {
|
|
1359
|
+
throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
1360
|
+
} else if (!detectedIndent) {
|
|
1361
|
+
textIndent = nodeIndent + tmp - 1;
|
|
1362
|
+
detectedIndent = true;
|
|
1363
|
+
} else {
|
|
1364
|
+
throwError(state, "repeat of an indentation width identifier");
|
|
1365
|
+
}
|
|
1366
|
+
} else {
|
|
1367
|
+
break;
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
if (is_WHITE_SPACE(ch)) {
|
|
1371
|
+
do {
|
|
1372
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1373
|
+
} while (is_WHITE_SPACE(ch));
|
|
1374
|
+
if (ch === 35) {
|
|
1375
|
+
do {
|
|
1376
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1377
|
+
} while (!is_EOL(ch) && ch !== 0);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
while (ch !== 0) {
|
|
1381
|
+
readLineBreak(state);
|
|
1382
|
+
state.lineIndent = 0;
|
|
1383
|
+
ch = state.input.charCodeAt(state.position);
|
|
1384
|
+
while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
|
|
1385
|
+
state.lineIndent++;
|
|
1386
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1387
|
+
}
|
|
1388
|
+
if (!detectedIndent && state.lineIndent > textIndent) {
|
|
1389
|
+
textIndent = state.lineIndent;
|
|
1390
|
+
}
|
|
1391
|
+
if (is_EOL(ch)) {
|
|
1392
|
+
emptyLines++;
|
|
1393
|
+
continue;
|
|
1394
|
+
}
|
|
1395
|
+
if (state.lineIndent < textIndent) {
|
|
1396
|
+
if (chomping === CHOMPING_KEEP) {
|
|
1397
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1398
|
+
} else if (chomping === CHOMPING_CLIP) {
|
|
1399
|
+
if (didReadContent) {
|
|
1400
|
+
state.result += "\n";
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
break;
|
|
1404
|
+
}
|
|
1405
|
+
if (folding) {
|
|
1406
|
+
if (is_WHITE_SPACE(ch)) {
|
|
1407
|
+
atMoreIndented = true;
|
|
1408
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1409
|
+
} else if (atMoreIndented) {
|
|
1410
|
+
atMoreIndented = false;
|
|
1411
|
+
state.result += common.repeat("\n", emptyLines + 1);
|
|
1412
|
+
} else if (emptyLines === 0) {
|
|
1413
|
+
if (didReadContent) {
|
|
1414
|
+
state.result += " ";
|
|
1415
|
+
}
|
|
1416
|
+
} else {
|
|
1417
|
+
state.result += common.repeat("\n", emptyLines);
|
|
1418
|
+
}
|
|
1419
|
+
} else {
|
|
1420
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1421
|
+
}
|
|
1422
|
+
didReadContent = true;
|
|
1423
|
+
detectedIndent = true;
|
|
1424
|
+
emptyLines = 0;
|
|
1425
|
+
captureStart = state.position;
|
|
1426
|
+
while (!is_EOL(ch) && ch !== 0) {
|
|
1427
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1428
|
+
}
|
|
1429
|
+
captureSegment(state, captureStart, state.position, false);
|
|
1430
|
+
}
|
|
1431
|
+
return true;
|
|
1432
|
+
}
|
|
1433
|
+
function readBlockSequence(state, nodeIndent) {
|
|
1434
|
+
var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
|
|
1435
|
+
if (state.firstTabInLine !== -1) return false;
|
|
1436
|
+
if (state.anchor !== null) {
|
|
1437
|
+
state.anchorMap[state.anchor] = _result;
|
|
1438
|
+
}
|
|
1439
|
+
ch = state.input.charCodeAt(state.position);
|
|
1440
|
+
while (ch !== 0) {
|
|
1441
|
+
if (state.firstTabInLine !== -1) {
|
|
1442
|
+
state.position = state.firstTabInLine;
|
|
1443
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
1444
|
+
}
|
|
1445
|
+
if (ch !== 45) {
|
|
1446
|
+
break;
|
|
1447
|
+
}
|
|
1448
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1449
|
+
if (!is_WS_OR_EOL(following)) {
|
|
1450
|
+
break;
|
|
1451
|
+
}
|
|
1452
|
+
detected = true;
|
|
1453
|
+
state.position++;
|
|
1454
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
1455
|
+
if (state.lineIndent <= nodeIndent) {
|
|
1456
|
+
_result.push(null);
|
|
1457
|
+
ch = state.input.charCodeAt(state.position);
|
|
1458
|
+
continue;
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
_line = state.line;
|
|
1462
|
+
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|
1463
|
+
_result.push(state.result);
|
|
1464
|
+
skipSeparationSpace(state, true, -1);
|
|
1465
|
+
ch = state.input.charCodeAt(state.position);
|
|
1466
|
+
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1467
|
+
throwError(state, "bad indentation of a sequence entry");
|
|
1468
|
+
} else if (state.lineIndent < nodeIndent) {
|
|
1469
|
+
break;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
if (detected) {
|
|
1473
|
+
state.tag = _tag;
|
|
1474
|
+
state.anchor = _anchor;
|
|
1475
|
+
state.kind = "sequence";
|
|
1476
|
+
state.result = _result;
|
|
1477
|
+
return true;
|
|
1478
|
+
}
|
|
1479
|
+
return false;
|
|
1480
|
+
}
|
|
1481
|
+
function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
1482
|
+
var following, allowCompact, _line, _keyLine, _keyLineStart, _keyPos, _tag = state.tag, _anchor = state.anchor, _result = {}, overridableKeys = /* @__PURE__ */ Object.create(null), keyTag = null, keyNode = null, valueNode = null, atExplicitKey = false, detected = false, ch;
|
|
1483
|
+
if (state.firstTabInLine !== -1) return false;
|
|
1484
|
+
if (state.anchor !== null) {
|
|
1485
|
+
state.anchorMap[state.anchor] = _result;
|
|
1486
|
+
}
|
|
1487
|
+
ch = state.input.charCodeAt(state.position);
|
|
1488
|
+
while (ch !== 0) {
|
|
1489
|
+
if (!atExplicitKey && state.firstTabInLine !== -1) {
|
|
1490
|
+
state.position = state.firstTabInLine;
|
|
1491
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
1492
|
+
}
|
|
1493
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1494
|
+
_line = state.line;
|
|
1495
|
+
if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
|
|
1496
|
+
if (ch === 63) {
|
|
1497
|
+
if (atExplicitKey) {
|
|
1498
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1499
|
+
keyTag = keyNode = valueNode = null;
|
|
1500
|
+
}
|
|
1501
|
+
detected = true;
|
|
1502
|
+
atExplicitKey = true;
|
|
1503
|
+
allowCompact = true;
|
|
1504
|
+
} else if (atExplicitKey) {
|
|
1505
|
+
atExplicitKey = false;
|
|
1506
|
+
allowCompact = true;
|
|
1507
|
+
} else {
|
|
1508
|
+
throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
|
|
1509
|
+
}
|
|
1510
|
+
state.position += 1;
|
|
1511
|
+
ch = following;
|
|
1512
|
+
} else {
|
|
1513
|
+
_keyLine = state.line;
|
|
1514
|
+
_keyLineStart = state.lineStart;
|
|
1515
|
+
_keyPos = state.position;
|
|
1516
|
+
if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
|
1517
|
+
break;
|
|
1518
|
+
}
|
|
1519
|
+
if (state.line === _line) {
|
|
1520
|
+
ch = state.input.charCodeAt(state.position);
|
|
1521
|
+
while (is_WHITE_SPACE(ch)) {
|
|
1522
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1523
|
+
}
|
|
1524
|
+
if (ch === 58) {
|
|
1525
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1526
|
+
if (!is_WS_OR_EOL(ch)) {
|
|
1527
|
+
throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
1528
|
+
}
|
|
1529
|
+
if (atExplicitKey) {
|
|
1530
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1531
|
+
keyTag = keyNode = valueNode = null;
|
|
1532
|
+
}
|
|
1533
|
+
detected = true;
|
|
1534
|
+
atExplicitKey = false;
|
|
1535
|
+
allowCompact = false;
|
|
1536
|
+
keyTag = state.tag;
|
|
1537
|
+
keyNode = state.result;
|
|
1538
|
+
} else if (detected) {
|
|
1539
|
+
throwError(state, "can not read an implicit mapping pair; a colon is missed");
|
|
1540
|
+
} else {
|
|
1541
|
+
state.tag = _tag;
|
|
1542
|
+
state.anchor = _anchor;
|
|
1543
|
+
return true;
|
|
1544
|
+
}
|
|
1545
|
+
} else if (detected) {
|
|
1546
|
+
throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
1547
|
+
} else {
|
|
1548
|
+
state.tag = _tag;
|
|
1549
|
+
state.anchor = _anchor;
|
|
1550
|
+
return true;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
if (state.line === _line || state.lineIndent > nodeIndent) {
|
|
1554
|
+
if (atExplicitKey) {
|
|
1555
|
+
_keyLine = state.line;
|
|
1556
|
+
_keyLineStart = state.lineStart;
|
|
1557
|
+
_keyPos = state.position;
|
|
1558
|
+
}
|
|
1559
|
+
if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
|
1560
|
+
if (atExplicitKey) {
|
|
1561
|
+
keyNode = state.result;
|
|
1562
|
+
} else {
|
|
1563
|
+
valueNode = state.result;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
if (!atExplicitKey) {
|
|
1567
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
|
|
1568
|
+
keyTag = keyNode = valueNode = null;
|
|
1569
|
+
}
|
|
1570
|
+
skipSeparationSpace(state, true, -1);
|
|
1571
|
+
ch = state.input.charCodeAt(state.position);
|
|
1572
|
+
}
|
|
1573
|
+
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1574
|
+
throwError(state, "bad indentation of a mapping entry");
|
|
1575
|
+
} else if (state.lineIndent < nodeIndent) {
|
|
1576
|
+
break;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
if (atExplicitKey) {
|
|
1580
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1581
|
+
}
|
|
1582
|
+
if (detected) {
|
|
1583
|
+
state.tag = _tag;
|
|
1584
|
+
state.anchor = _anchor;
|
|
1585
|
+
state.kind = "mapping";
|
|
1586
|
+
state.result = _result;
|
|
1587
|
+
}
|
|
1588
|
+
return detected;
|
|
1589
|
+
}
|
|
1590
|
+
function readTagProperty(state) {
|
|
1591
|
+
var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
|
|
1592
|
+
ch = state.input.charCodeAt(state.position);
|
|
1593
|
+
if (ch !== 33) return false;
|
|
1594
|
+
if (state.tag !== null) {
|
|
1595
|
+
throwError(state, "duplication of a tag property");
|
|
1596
|
+
}
|
|
1597
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1598
|
+
if (ch === 60) {
|
|
1599
|
+
isVerbatim = true;
|
|
1600
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1601
|
+
} else if (ch === 33) {
|
|
1602
|
+
isNamed = true;
|
|
1603
|
+
tagHandle = "!!";
|
|
1604
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1605
|
+
} else {
|
|
1606
|
+
tagHandle = "!";
|
|
1607
|
+
}
|
|
1608
|
+
_position = state.position;
|
|
1609
|
+
if (isVerbatim) {
|
|
1610
|
+
do {
|
|
1611
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1612
|
+
} while (ch !== 0 && ch !== 62);
|
|
1613
|
+
if (state.position < state.length) {
|
|
1614
|
+
tagName = state.input.slice(_position, state.position);
|
|
1615
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1616
|
+
} else {
|
|
1617
|
+
throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
1618
|
+
}
|
|
1619
|
+
} else {
|
|
1620
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
1621
|
+
if (ch === 33) {
|
|
1622
|
+
if (!isNamed) {
|
|
1623
|
+
tagHandle = state.input.slice(_position - 1, state.position + 1);
|
|
1624
|
+
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
1625
|
+
throwError(state, "named tag handle cannot contain such characters");
|
|
1626
|
+
}
|
|
1627
|
+
isNamed = true;
|
|
1628
|
+
_position = state.position + 1;
|
|
1629
|
+
} else {
|
|
1630
|
+
throwError(state, "tag suffix cannot contain exclamation marks");
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1634
|
+
}
|
|
1635
|
+
tagName = state.input.slice(_position, state.position);
|
|
1636
|
+
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
1637
|
+
throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
|
1641
|
+
throwError(state, "tag name cannot contain such characters: " + tagName);
|
|
1642
|
+
}
|
|
1643
|
+
try {
|
|
1644
|
+
tagName = decodeURIComponent(tagName);
|
|
1645
|
+
} catch (err) {
|
|
1646
|
+
throwError(state, "tag name is malformed: " + tagName);
|
|
1647
|
+
}
|
|
1648
|
+
if (isVerbatim) {
|
|
1649
|
+
state.tag = tagName;
|
|
1650
|
+
} else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
|
|
1651
|
+
state.tag = state.tagMap[tagHandle] + tagName;
|
|
1652
|
+
} else if (tagHandle === "!") {
|
|
1653
|
+
state.tag = "!" + tagName;
|
|
1654
|
+
} else if (tagHandle === "!!") {
|
|
1655
|
+
state.tag = "tag:yaml.org,2002:" + tagName;
|
|
1656
|
+
} else {
|
|
1657
|
+
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
|
1658
|
+
}
|
|
1659
|
+
return true;
|
|
1660
|
+
}
|
|
1661
|
+
function readAnchorProperty(state) {
|
|
1662
|
+
var _position, ch;
|
|
1663
|
+
ch = state.input.charCodeAt(state.position);
|
|
1664
|
+
if (ch !== 38) return false;
|
|
1665
|
+
if (state.anchor !== null) {
|
|
1666
|
+
throwError(state, "duplication of an anchor property");
|
|
1667
|
+
}
|
|
1668
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1669
|
+
_position = state.position;
|
|
1670
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
1671
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1672
|
+
}
|
|
1673
|
+
if (state.position === _position) {
|
|
1674
|
+
throwError(state, "name of an anchor node must contain at least one character");
|
|
1675
|
+
}
|
|
1676
|
+
state.anchor = state.input.slice(_position, state.position);
|
|
1677
|
+
return true;
|
|
1678
|
+
}
|
|
1679
|
+
function readAlias(state) {
|
|
1680
|
+
var _position, alias, ch;
|
|
1681
|
+
ch = state.input.charCodeAt(state.position);
|
|
1682
|
+
if (ch !== 42) return false;
|
|
1683
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1684
|
+
_position = state.position;
|
|
1685
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
1686
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1687
|
+
}
|
|
1688
|
+
if (state.position === _position) {
|
|
1689
|
+
throwError(state, "name of an alias node must contain at least one character");
|
|
1690
|
+
}
|
|
1691
|
+
alias = state.input.slice(_position, state.position);
|
|
1692
|
+
if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
|
|
1693
|
+
throwError(state, 'unidentified alias "' + alias + '"');
|
|
1694
|
+
}
|
|
1695
|
+
state.result = state.anchorMap[alias];
|
|
1696
|
+
skipSeparationSpace(state, true, -1);
|
|
1697
|
+
return true;
|
|
1698
|
+
}
|
|
1699
|
+
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
|
1700
|
+
var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type2, flowIndent, blockIndent;
|
|
1701
|
+
if (state.listener !== null) {
|
|
1702
|
+
state.listener("open", state);
|
|
1703
|
+
}
|
|
1704
|
+
state.tag = null;
|
|
1705
|
+
state.anchor = null;
|
|
1706
|
+
state.kind = null;
|
|
1707
|
+
state.result = null;
|
|
1708
|
+
allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
|
|
1709
|
+
if (allowToSeek) {
|
|
1710
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
1711
|
+
atNewLine = true;
|
|
1712
|
+
if (state.lineIndent > parentIndent) {
|
|
1713
|
+
indentStatus = 1;
|
|
1714
|
+
} else if (state.lineIndent === parentIndent) {
|
|
1715
|
+
indentStatus = 0;
|
|
1716
|
+
} else if (state.lineIndent < parentIndent) {
|
|
1717
|
+
indentStatus = -1;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
if (indentStatus === 1) {
|
|
1722
|
+
while (readTagProperty(state) || readAnchorProperty(state)) {
|
|
1723
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
1724
|
+
atNewLine = true;
|
|
1725
|
+
allowBlockCollections = allowBlockStyles;
|
|
1726
|
+
if (state.lineIndent > parentIndent) {
|
|
1727
|
+
indentStatus = 1;
|
|
1728
|
+
} else if (state.lineIndent === parentIndent) {
|
|
1729
|
+
indentStatus = 0;
|
|
1730
|
+
} else if (state.lineIndent < parentIndent) {
|
|
1731
|
+
indentStatus = -1;
|
|
1732
|
+
}
|
|
1733
|
+
} else {
|
|
1734
|
+
allowBlockCollections = false;
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
if (allowBlockCollections) {
|
|
1739
|
+
allowBlockCollections = atNewLine || allowCompact;
|
|
1740
|
+
}
|
|
1741
|
+
if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
|
1742
|
+
if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
|
1743
|
+
flowIndent = parentIndent;
|
|
1744
|
+
} else {
|
|
1745
|
+
flowIndent = parentIndent + 1;
|
|
1746
|
+
}
|
|
1747
|
+
blockIndent = state.position - state.lineStart;
|
|
1748
|
+
if (indentStatus === 1) {
|
|
1749
|
+
if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
|
|
1750
|
+
hasContent = true;
|
|
1751
|
+
} else {
|
|
1752
|
+
if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
|
|
1753
|
+
hasContent = true;
|
|
1754
|
+
} else if (readAlias(state)) {
|
|
1755
|
+
hasContent = true;
|
|
1756
|
+
if (state.tag !== null || state.anchor !== null) {
|
|
1757
|
+
throwError(state, "alias node should not have any properties");
|
|
1758
|
+
}
|
|
1759
|
+
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
|
1760
|
+
hasContent = true;
|
|
1761
|
+
if (state.tag === null) {
|
|
1762
|
+
state.tag = "?";
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
if (state.anchor !== null) {
|
|
1766
|
+
state.anchorMap[state.anchor] = state.result;
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
} else if (indentStatus === 0) {
|
|
1770
|
+
hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
if (state.tag === null) {
|
|
1774
|
+
if (state.anchor !== null) {
|
|
1775
|
+
state.anchorMap[state.anchor] = state.result;
|
|
1776
|
+
}
|
|
1777
|
+
} else if (state.tag === "?") {
|
|
1778
|
+
if (state.result !== null && state.kind !== "scalar") {
|
|
1779
|
+
throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
|
1780
|
+
}
|
|
1781
|
+
for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
|
|
1782
|
+
type2 = state.implicitTypes[typeIndex];
|
|
1783
|
+
if (type2.resolve(state.result)) {
|
|
1784
|
+
state.result = type2.construct(state.result);
|
|
1785
|
+
state.tag = type2.tag;
|
|
1786
|
+
if (state.anchor !== null) {
|
|
1787
|
+
state.anchorMap[state.anchor] = state.result;
|
|
1788
|
+
}
|
|
1789
|
+
break;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
} else if (state.tag !== "!") {
|
|
1793
|
+
if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
|
|
1794
|
+
type2 = state.typeMap[state.kind || "fallback"][state.tag];
|
|
1795
|
+
} else {
|
|
1796
|
+
type2 = null;
|
|
1797
|
+
typeList = state.typeMap.multi[state.kind || "fallback"];
|
|
1798
|
+
for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) {
|
|
1799
|
+
if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
|
|
1800
|
+
type2 = typeList[typeIndex];
|
|
1801
|
+
break;
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
if (!type2) {
|
|
1806
|
+
throwError(state, "unknown tag !<" + state.tag + ">");
|
|
1807
|
+
}
|
|
1808
|
+
if (state.result !== null && type2.kind !== state.kind) {
|
|
1809
|
+
throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"');
|
|
1810
|
+
}
|
|
1811
|
+
if (!type2.resolve(state.result, state.tag)) {
|
|
1812
|
+
throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
|
|
1813
|
+
} else {
|
|
1814
|
+
state.result = type2.construct(state.result, state.tag);
|
|
1815
|
+
if (state.anchor !== null) {
|
|
1816
|
+
state.anchorMap[state.anchor] = state.result;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
if (state.listener !== null) {
|
|
1821
|
+
state.listener("close", state);
|
|
1822
|
+
}
|
|
1823
|
+
return state.tag !== null || state.anchor !== null || hasContent;
|
|
1824
|
+
}
|
|
1825
|
+
function readDocument(state) {
|
|
1826
|
+
var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
|
|
1827
|
+
state.version = null;
|
|
1828
|
+
state.checkLineBreaks = state.legacy;
|
|
1829
|
+
state.tagMap = /* @__PURE__ */ Object.create(null);
|
|
1830
|
+
state.anchorMap = /* @__PURE__ */ Object.create(null);
|
|
1831
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1832
|
+
skipSeparationSpace(state, true, -1);
|
|
1833
|
+
ch = state.input.charCodeAt(state.position);
|
|
1834
|
+
if (state.lineIndent > 0 || ch !== 37) {
|
|
1835
|
+
break;
|
|
1836
|
+
}
|
|
1837
|
+
hasDirectives = true;
|
|
1838
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1839
|
+
_position = state.position;
|
|
1840
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
1841
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1842
|
+
}
|
|
1843
|
+
directiveName = state.input.slice(_position, state.position);
|
|
1844
|
+
directiveArgs = [];
|
|
1845
|
+
if (directiveName.length < 1) {
|
|
1846
|
+
throwError(state, "directive name must not be less than one character in length");
|
|
1847
|
+
}
|
|
1848
|
+
while (ch !== 0) {
|
|
1849
|
+
while (is_WHITE_SPACE(ch)) {
|
|
1850
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1851
|
+
}
|
|
1852
|
+
if (ch === 35) {
|
|
1853
|
+
do {
|
|
1854
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1855
|
+
} while (ch !== 0 && !is_EOL(ch));
|
|
1856
|
+
break;
|
|
1857
|
+
}
|
|
1858
|
+
if (is_EOL(ch)) break;
|
|
1859
|
+
_position = state.position;
|
|
1860
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
1861
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1862
|
+
}
|
|
1863
|
+
directiveArgs.push(state.input.slice(_position, state.position));
|
|
1864
|
+
}
|
|
1865
|
+
if (ch !== 0) readLineBreak(state);
|
|
1866
|
+
if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
|
|
1867
|
+
directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
|
1868
|
+
} else {
|
|
1869
|
+
throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
skipSeparationSpace(state, true, -1);
|
|
1873
|
+
if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
|
|
1874
|
+
state.position += 3;
|
|
1875
|
+
skipSeparationSpace(state, true, -1);
|
|
1876
|
+
} else if (hasDirectives) {
|
|
1877
|
+
throwError(state, "directives end mark is expected");
|
|
1878
|
+
}
|
|
1879
|
+
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
|
1880
|
+
skipSeparationSpace(state, true, -1);
|
|
1881
|
+
if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|
1882
|
+
throwWarning(state, "non-ASCII line breaks are interpreted as content");
|
|
1883
|
+
}
|
|
1884
|
+
state.documents.push(state.result);
|
|
1885
|
+
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1886
|
+
if (state.input.charCodeAt(state.position) === 46) {
|
|
1887
|
+
state.position += 3;
|
|
1888
|
+
skipSeparationSpace(state, true, -1);
|
|
1889
|
+
}
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
if (state.position < state.length - 1) {
|
|
1893
|
+
throwError(state, "end of the stream or a document separator is expected");
|
|
1894
|
+
} else {
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
function loadDocuments(input, options) {
|
|
1899
|
+
input = String(input);
|
|
1900
|
+
options = options || {};
|
|
1901
|
+
if (input.length !== 0) {
|
|
1902
|
+
if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
|
|
1903
|
+
input += "\n";
|
|
1904
|
+
}
|
|
1905
|
+
if (input.charCodeAt(0) === 65279) {
|
|
1906
|
+
input = input.slice(1);
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
var state = new State$1(input, options);
|
|
1910
|
+
var nullpos = input.indexOf("\0");
|
|
1911
|
+
if (nullpos !== -1) {
|
|
1912
|
+
state.position = nullpos;
|
|
1913
|
+
throwError(state, "null byte is not allowed in input");
|
|
1914
|
+
}
|
|
1915
|
+
state.input += "\0";
|
|
1916
|
+
while (state.input.charCodeAt(state.position) === 32) {
|
|
1917
|
+
state.lineIndent += 1;
|
|
1918
|
+
state.position += 1;
|
|
1919
|
+
}
|
|
1920
|
+
while (state.position < state.length - 1) {
|
|
1921
|
+
readDocument(state);
|
|
1922
|
+
}
|
|
1923
|
+
return state.documents;
|
|
1924
|
+
}
|
|
1925
|
+
function loadAll$1(input, iterator, options) {
|
|
1926
|
+
if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
|
|
1927
|
+
options = iterator;
|
|
1928
|
+
iterator = null;
|
|
1929
|
+
}
|
|
1930
|
+
var documents = loadDocuments(input, options);
|
|
1931
|
+
if (typeof iterator !== "function") {
|
|
1932
|
+
return documents;
|
|
1933
|
+
}
|
|
1934
|
+
for (var index = 0, length = documents.length; index < length; index += 1) {
|
|
1935
|
+
iterator(documents[index]);
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
function load$1(input, options) {
|
|
1939
|
+
var documents = loadDocuments(input, options);
|
|
1940
|
+
if (documents.length === 0) {
|
|
1941
|
+
return void 0;
|
|
1942
|
+
} else if (documents.length === 1) {
|
|
1943
|
+
return documents[0];
|
|
1944
|
+
}
|
|
1945
|
+
throw new exception("expected a single document in the stream, but found more");
|
|
1946
|
+
}
|
|
1947
|
+
var loadAll_1 = loadAll$1;
|
|
1948
|
+
var load_1 = load$1;
|
|
1949
|
+
var loader = {
|
|
1950
|
+
loadAll: loadAll_1,
|
|
1951
|
+
load: load_1
|
|
1952
|
+
};
|
|
1953
|
+
var _toString = Object.prototype.toString;
|
|
1954
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1955
|
+
var CHAR_BOM = 65279;
|
|
1956
|
+
var CHAR_TAB = 9;
|
|
1957
|
+
var CHAR_LINE_FEED = 10;
|
|
1958
|
+
var CHAR_CARRIAGE_RETURN = 13;
|
|
1959
|
+
var CHAR_SPACE = 32;
|
|
1960
|
+
var CHAR_EXCLAMATION = 33;
|
|
1961
|
+
var CHAR_DOUBLE_QUOTE = 34;
|
|
1962
|
+
var CHAR_SHARP = 35;
|
|
1963
|
+
var CHAR_PERCENT = 37;
|
|
1964
|
+
var CHAR_AMPERSAND = 38;
|
|
1965
|
+
var CHAR_SINGLE_QUOTE = 39;
|
|
1966
|
+
var CHAR_ASTERISK = 42;
|
|
1967
|
+
var CHAR_COMMA = 44;
|
|
1968
|
+
var CHAR_MINUS = 45;
|
|
1969
|
+
var CHAR_COLON = 58;
|
|
1970
|
+
var CHAR_EQUALS = 61;
|
|
1971
|
+
var CHAR_GREATER_THAN = 62;
|
|
1972
|
+
var CHAR_QUESTION = 63;
|
|
1973
|
+
var CHAR_COMMERCIAL_AT = 64;
|
|
1974
|
+
var CHAR_LEFT_SQUARE_BRACKET = 91;
|
|
1975
|
+
var CHAR_RIGHT_SQUARE_BRACKET = 93;
|
|
1976
|
+
var CHAR_GRAVE_ACCENT = 96;
|
|
1977
|
+
var CHAR_LEFT_CURLY_BRACKET = 123;
|
|
1978
|
+
var CHAR_VERTICAL_LINE = 124;
|
|
1979
|
+
var CHAR_RIGHT_CURLY_BRACKET = 125;
|
|
1980
|
+
var ESCAPE_SEQUENCES = {};
|
|
1981
|
+
ESCAPE_SEQUENCES[0] = "\\0";
|
|
1982
|
+
ESCAPE_SEQUENCES[7] = "\\a";
|
|
1983
|
+
ESCAPE_SEQUENCES[8] = "\\b";
|
|
1984
|
+
ESCAPE_SEQUENCES[9] = "\\t";
|
|
1985
|
+
ESCAPE_SEQUENCES[10] = "\\n";
|
|
1986
|
+
ESCAPE_SEQUENCES[11] = "\\v";
|
|
1987
|
+
ESCAPE_SEQUENCES[12] = "\\f";
|
|
1988
|
+
ESCAPE_SEQUENCES[13] = "\\r";
|
|
1989
|
+
ESCAPE_SEQUENCES[27] = "\\e";
|
|
1990
|
+
ESCAPE_SEQUENCES[34] = '\\"';
|
|
1991
|
+
ESCAPE_SEQUENCES[92] = "\\\\";
|
|
1992
|
+
ESCAPE_SEQUENCES[133] = "\\N";
|
|
1993
|
+
ESCAPE_SEQUENCES[160] = "\\_";
|
|
1994
|
+
ESCAPE_SEQUENCES[8232] = "\\L";
|
|
1995
|
+
ESCAPE_SEQUENCES[8233] = "\\P";
|
|
1996
|
+
var DEPRECATED_BOOLEANS_SYNTAX = [
|
|
1997
|
+
"y",
|
|
1998
|
+
"Y",
|
|
1999
|
+
"yes",
|
|
2000
|
+
"Yes",
|
|
2001
|
+
"YES",
|
|
2002
|
+
"on",
|
|
2003
|
+
"On",
|
|
2004
|
+
"ON",
|
|
2005
|
+
"n",
|
|
2006
|
+
"N",
|
|
2007
|
+
"no",
|
|
2008
|
+
"No",
|
|
2009
|
+
"NO",
|
|
2010
|
+
"off",
|
|
2011
|
+
"Off",
|
|
2012
|
+
"OFF"
|
|
2013
|
+
];
|
|
2014
|
+
var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
|
|
2015
|
+
function compileStyleMap(schema2, map2) {
|
|
2016
|
+
var result, keys, index, length, tag, style, type2;
|
|
2017
|
+
if (map2 === null) return {};
|
|
2018
|
+
result = {};
|
|
2019
|
+
keys = Object.keys(map2);
|
|
2020
|
+
for (index = 0, length = keys.length; index < length; index += 1) {
|
|
2021
|
+
tag = keys[index];
|
|
2022
|
+
style = String(map2[tag]);
|
|
2023
|
+
if (tag.slice(0, 2) === "!!") {
|
|
2024
|
+
tag = "tag:yaml.org,2002:" + tag.slice(2);
|
|
2025
|
+
}
|
|
2026
|
+
type2 = schema2.compiledTypeMap["fallback"][tag];
|
|
2027
|
+
if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) {
|
|
2028
|
+
style = type2.styleAliases[style];
|
|
2029
|
+
}
|
|
2030
|
+
result[tag] = style;
|
|
2031
|
+
}
|
|
2032
|
+
return result;
|
|
2033
|
+
}
|
|
2034
|
+
function encodeHex(character) {
|
|
2035
|
+
var string, handle, length;
|
|
2036
|
+
string = character.toString(16).toUpperCase();
|
|
2037
|
+
if (character <= 255) {
|
|
2038
|
+
handle = "x";
|
|
2039
|
+
length = 2;
|
|
2040
|
+
} else if (character <= 65535) {
|
|
2041
|
+
handle = "u";
|
|
2042
|
+
length = 4;
|
|
2043
|
+
} else if (character <= 4294967295) {
|
|
2044
|
+
handle = "U";
|
|
2045
|
+
length = 8;
|
|
2046
|
+
} else {
|
|
2047
|
+
throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
|
|
2048
|
+
}
|
|
2049
|
+
return "\\" + handle + common.repeat("0", length - string.length) + string;
|
|
2050
|
+
}
|
|
2051
|
+
var QUOTING_TYPE_SINGLE = 1;
|
|
2052
|
+
var QUOTING_TYPE_DOUBLE = 2;
|
|
2053
|
+
function State(options) {
|
|
2054
|
+
this.schema = options["schema"] || _default;
|
|
2055
|
+
this.indent = Math.max(1, options["indent"] || 2);
|
|
2056
|
+
this.noArrayIndent = options["noArrayIndent"] || false;
|
|
2057
|
+
this.skipInvalid = options["skipInvalid"] || false;
|
|
2058
|
+
this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
|
|
2059
|
+
this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
|
|
2060
|
+
this.sortKeys = options["sortKeys"] || false;
|
|
2061
|
+
this.lineWidth = options["lineWidth"] || 80;
|
|
2062
|
+
this.noRefs = options["noRefs"] || false;
|
|
2063
|
+
this.noCompatMode = options["noCompatMode"] || false;
|
|
2064
|
+
this.condenseFlow = options["condenseFlow"] || false;
|
|
2065
|
+
this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
|
|
2066
|
+
this.forceQuotes = options["forceQuotes"] || false;
|
|
2067
|
+
this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
|
|
2068
|
+
this.implicitTypes = this.schema.compiledImplicit;
|
|
2069
|
+
this.explicitTypes = this.schema.compiledExplicit;
|
|
2070
|
+
this.tag = null;
|
|
2071
|
+
this.result = "";
|
|
2072
|
+
this.duplicates = [];
|
|
2073
|
+
this.usedDuplicates = null;
|
|
2074
|
+
}
|
|
2075
|
+
function indentString(string, spaces) {
|
|
2076
|
+
var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
|
|
2077
|
+
while (position < length) {
|
|
2078
|
+
next = string.indexOf("\n", position);
|
|
2079
|
+
if (next === -1) {
|
|
2080
|
+
line = string.slice(position);
|
|
2081
|
+
position = length;
|
|
2082
|
+
} else {
|
|
2083
|
+
line = string.slice(position, next + 1);
|
|
2084
|
+
position = next + 1;
|
|
2085
|
+
}
|
|
2086
|
+
if (line.length && line !== "\n") result += ind;
|
|
2087
|
+
result += line;
|
|
2088
|
+
}
|
|
2089
|
+
return result;
|
|
2090
|
+
}
|
|
2091
|
+
function generateNextLine(state, level) {
|
|
2092
|
+
return "\n" + common.repeat(" ", state.indent * level);
|
|
2093
|
+
}
|
|
2094
|
+
function testImplicitResolving(state, str2) {
|
|
2095
|
+
var index, length, type2;
|
|
2096
|
+
for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
|
|
2097
|
+
type2 = state.implicitTypes[index];
|
|
2098
|
+
if (type2.resolve(str2)) {
|
|
2099
|
+
return true;
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
return false;
|
|
2103
|
+
}
|
|
2104
|
+
function isWhitespace(c) {
|
|
2105
|
+
return c === CHAR_SPACE || c === CHAR_TAB;
|
|
2106
|
+
}
|
|
2107
|
+
function isPrintable(c) {
|
|
2108
|
+
return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111;
|
|
2109
|
+
}
|
|
2110
|
+
function isNsCharOrWhitespace(c) {
|
|
2111
|
+
return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
|
|
2112
|
+
}
|
|
2113
|
+
function isPlainSafe(c, prev, inblock) {
|
|
2114
|
+
var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
|
|
2115
|
+
var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
|
|
2116
|
+
return (
|
|
2117
|
+
// ns-plain-safe
|
|
2118
|
+
(inblock ? (
|
|
2119
|
+
// c = flow-in
|
|
2120
|
+
cIsNsCharOrWhitespace
|
|
2121
|
+
) : 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
|
|
2122
|
+
);
|
|
2123
|
+
}
|
|
2124
|
+
function isPlainSafeFirst(c) {
|
|
2125
|
+
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;
|
|
2126
|
+
}
|
|
2127
|
+
function isPlainSafeLast(c) {
|
|
2128
|
+
return !isWhitespace(c) && c !== CHAR_COLON;
|
|
2129
|
+
}
|
|
2130
|
+
function codePointAt(string, pos) {
|
|
2131
|
+
var first = string.charCodeAt(pos), second;
|
|
2132
|
+
if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
|
|
2133
|
+
second = string.charCodeAt(pos + 1);
|
|
2134
|
+
if (second >= 56320 && second <= 57343) {
|
|
2135
|
+
return (first - 55296) * 1024 + second - 56320 + 65536;
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
return first;
|
|
2139
|
+
}
|
|
2140
|
+
function needIndentIndicator(string) {
|
|
2141
|
+
var leadingSpaceRe = /^\n* /;
|
|
2142
|
+
return leadingSpaceRe.test(string);
|
|
2143
|
+
}
|
|
2144
|
+
var STYLE_PLAIN = 1;
|
|
2145
|
+
var STYLE_SINGLE = 2;
|
|
2146
|
+
var STYLE_LITERAL = 3;
|
|
2147
|
+
var STYLE_FOLDED = 4;
|
|
2148
|
+
var STYLE_DOUBLE = 5;
|
|
2149
|
+
function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
|
|
2150
|
+
var i;
|
|
2151
|
+
var char = 0;
|
|
2152
|
+
var prevChar = null;
|
|
2153
|
+
var hasLineBreak = false;
|
|
2154
|
+
var hasFoldableLine = false;
|
|
2155
|
+
var shouldTrackWidth = lineWidth !== -1;
|
|
2156
|
+
var previousLineBreak = -1;
|
|
2157
|
+
var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
|
|
2158
|
+
if (singleLineOnly || forceQuotes) {
|
|
2159
|
+
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2160
|
+
char = codePointAt(string, i);
|
|
2161
|
+
if (!isPrintable(char)) {
|
|
2162
|
+
return STYLE_DOUBLE;
|
|
2163
|
+
}
|
|
2164
|
+
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2165
|
+
prevChar = char;
|
|
2166
|
+
}
|
|
2167
|
+
} else {
|
|
2168
|
+
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2169
|
+
char = codePointAt(string, i);
|
|
2170
|
+
if (char === CHAR_LINE_FEED) {
|
|
2171
|
+
hasLineBreak = true;
|
|
2172
|
+
if (shouldTrackWidth) {
|
|
2173
|
+
hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
|
|
2174
|
+
i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
2175
|
+
previousLineBreak = i;
|
|
2176
|
+
}
|
|
2177
|
+
} else if (!isPrintable(char)) {
|
|
2178
|
+
return STYLE_DOUBLE;
|
|
2179
|
+
}
|
|
2180
|
+
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2181
|
+
prevChar = char;
|
|
2182
|
+
}
|
|
2183
|
+
hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
|
|
2184
|
+
}
|
|
2185
|
+
if (!hasLineBreak && !hasFoldableLine) {
|
|
2186
|
+
if (plain && !forceQuotes && !testAmbiguousType(string)) {
|
|
2187
|
+
return STYLE_PLAIN;
|
|
2188
|
+
}
|
|
2189
|
+
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2190
|
+
}
|
|
2191
|
+
if (indentPerLevel > 9 && needIndentIndicator(string)) {
|
|
2192
|
+
return STYLE_DOUBLE;
|
|
2193
|
+
}
|
|
2194
|
+
if (!forceQuotes) {
|
|
2195
|
+
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
|
2196
|
+
}
|
|
2197
|
+
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2198
|
+
}
|
|
2199
|
+
function writeScalar(state, string, level, iskey, inblock) {
|
|
2200
|
+
state.dump = (function() {
|
|
2201
|
+
if (string.length === 0) {
|
|
2202
|
+
return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
|
|
2203
|
+
}
|
|
2204
|
+
if (!state.noCompatMode) {
|
|
2205
|
+
if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
|
|
2206
|
+
return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
var indent = state.indent * Math.max(1, level);
|
|
2210
|
+
var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
|
|
2211
|
+
var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
|
|
2212
|
+
function testAmbiguity(string2) {
|
|
2213
|
+
return testImplicitResolving(state, string2);
|
|
2214
|
+
}
|
|
2215
|
+
switch (chooseScalarStyle(
|
|
2216
|
+
string,
|
|
2217
|
+
singleLineOnly,
|
|
2218
|
+
state.indent,
|
|
2219
|
+
lineWidth,
|
|
2220
|
+
testAmbiguity,
|
|
2221
|
+
state.quotingType,
|
|
2222
|
+
state.forceQuotes && !iskey,
|
|
2223
|
+
inblock
|
|
2224
|
+
)) {
|
|
2225
|
+
case STYLE_PLAIN:
|
|
2226
|
+
return string;
|
|
2227
|
+
case STYLE_SINGLE:
|
|
2228
|
+
return "'" + string.replace(/'/g, "''") + "'";
|
|
2229
|
+
case STYLE_LITERAL:
|
|
2230
|
+
return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
|
|
2231
|
+
case STYLE_FOLDED:
|
|
2232
|
+
return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
|
2233
|
+
case STYLE_DOUBLE:
|
|
2234
|
+
return '"' + escapeString(string) + '"';
|
|
2235
|
+
default:
|
|
2236
|
+
throw new exception("impossible error: invalid scalar style");
|
|
2237
|
+
}
|
|
2238
|
+
})();
|
|
2239
|
+
}
|
|
2240
|
+
function blockHeader(string, indentPerLevel) {
|
|
2241
|
+
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
2242
|
+
var clip = string[string.length - 1] === "\n";
|
|
2243
|
+
var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
|
|
2244
|
+
var chomp = keep ? "+" : clip ? "" : "-";
|
|
2245
|
+
return indentIndicator + chomp + "\n";
|
|
2246
|
+
}
|
|
2247
|
+
function dropEndingNewline(string) {
|
|
2248
|
+
return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
|
|
2249
|
+
}
|
|
2250
|
+
function foldString(string, width) {
|
|
2251
|
+
var lineRe = /(\n+)([^\n]*)/g;
|
|
2252
|
+
var result = (function() {
|
|
2253
|
+
var nextLF = string.indexOf("\n");
|
|
2254
|
+
nextLF = nextLF !== -1 ? nextLF : string.length;
|
|
2255
|
+
lineRe.lastIndex = nextLF;
|
|
2256
|
+
return foldLine(string.slice(0, nextLF), width);
|
|
2257
|
+
})();
|
|
2258
|
+
var prevMoreIndented = string[0] === "\n" || string[0] === " ";
|
|
2259
|
+
var moreIndented;
|
|
2260
|
+
var match;
|
|
2261
|
+
while (match = lineRe.exec(string)) {
|
|
2262
|
+
var prefix = match[1], line = match[2];
|
|
2263
|
+
moreIndented = line[0] === " ";
|
|
2264
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
2265
|
+
prevMoreIndented = moreIndented;
|
|
2266
|
+
}
|
|
2267
|
+
return result;
|
|
2268
|
+
}
|
|
2269
|
+
function foldLine(line, width) {
|
|
2270
|
+
if (line === "" || line[0] === " ") return line;
|
|
2271
|
+
var breakRe = / [^ ]/g;
|
|
2272
|
+
var match;
|
|
2273
|
+
var start = 0, end, curr = 0, next = 0;
|
|
2274
|
+
var result = "";
|
|
2275
|
+
while (match = breakRe.exec(line)) {
|
|
2276
|
+
next = match.index;
|
|
2277
|
+
if (next - start > width) {
|
|
2278
|
+
end = curr > start ? curr : next;
|
|
2279
|
+
result += "\n" + line.slice(start, end);
|
|
2280
|
+
start = end + 1;
|
|
2281
|
+
}
|
|
2282
|
+
curr = next;
|
|
2283
|
+
}
|
|
2284
|
+
result += "\n";
|
|
2285
|
+
if (line.length - start > width && curr > start) {
|
|
2286
|
+
result += line.slice(start, curr) + "\n" + line.slice(curr + 1);
|
|
2287
|
+
} else {
|
|
2288
|
+
result += line.slice(start);
|
|
2289
|
+
}
|
|
2290
|
+
return result.slice(1);
|
|
2291
|
+
}
|
|
2292
|
+
function escapeString(string) {
|
|
2293
|
+
var result = "";
|
|
2294
|
+
var char = 0;
|
|
2295
|
+
var escapeSeq;
|
|
2296
|
+
for (var i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2297
|
+
char = codePointAt(string, i);
|
|
2298
|
+
escapeSeq = ESCAPE_SEQUENCES[char];
|
|
2299
|
+
if (!escapeSeq && isPrintable(char)) {
|
|
2300
|
+
result += string[i];
|
|
2301
|
+
if (char >= 65536) result += string[i + 1];
|
|
2302
|
+
} else {
|
|
2303
|
+
result += escapeSeq || encodeHex(char);
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
return result;
|
|
2307
|
+
}
|
|
2308
|
+
function writeFlowSequence(state, level, object) {
|
|
2309
|
+
var _result = "", _tag = state.tag, index, length, value;
|
|
2310
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2311
|
+
value = object[index];
|
|
2312
|
+
if (state.replacer) {
|
|
2313
|
+
value = state.replacer.call(object, String(index), value);
|
|
2314
|
+
}
|
|
2315
|
+
if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
|
|
2316
|
+
if (_result !== "") _result += "," + (!state.condenseFlow ? " " : "");
|
|
2317
|
+
_result += state.dump;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
state.tag = _tag;
|
|
2321
|
+
state.dump = "[" + _result + "]";
|
|
2322
|
+
}
|
|
2323
|
+
function writeBlockSequence(state, level, object, compact) {
|
|
2324
|
+
var _result = "", _tag = state.tag, index, length, value;
|
|
2325
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2326
|
+
value = object[index];
|
|
2327
|
+
if (state.replacer) {
|
|
2328
|
+
value = state.replacer.call(object, String(index), value);
|
|
2329
|
+
}
|
|
2330
|
+
if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
|
|
2331
|
+
if (!compact || _result !== "") {
|
|
2332
|
+
_result += generateNextLine(state, level);
|
|
2333
|
+
}
|
|
2334
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2335
|
+
_result += "-";
|
|
2336
|
+
} else {
|
|
2337
|
+
_result += "- ";
|
|
2338
|
+
}
|
|
2339
|
+
_result += state.dump;
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
state.tag = _tag;
|
|
2343
|
+
state.dump = _result || "[]";
|
|
2344
|
+
}
|
|
2345
|
+
function writeFlowMapping(state, level, object) {
|
|
2346
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
|
|
2347
|
+
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2348
|
+
pairBuffer = "";
|
|
2349
|
+
if (_result !== "") pairBuffer += ", ";
|
|
2350
|
+
if (state.condenseFlow) pairBuffer += '"';
|
|
2351
|
+
objectKey = objectKeyList[index];
|
|
2352
|
+
objectValue = object[objectKey];
|
|
2353
|
+
if (state.replacer) {
|
|
2354
|
+
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
2355
|
+
}
|
|
2356
|
+
if (!writeNode(state, level, objectKey, false, false)) {
|
|
2357
|
+
continue;
|
|
2358
|
+
}
|
|
2359
|
+
if (state.dump.length > 1024) pairBuffer += "? ";
|
|
2360
|
+
pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
|
|
2361
|
+
if (!writeNode(state, level, objectValue, false, false)) {
|
|
2362
|
+
continue;
|
|
2363
|
+
}
|
|
2364
|
+
pairBuffer += state.dump;
|
|
2365
|
+
_result += pairBuffer;
|
|
2366
|
+
}
|
|
2367
|
+
state.tag = _tag;
|
|
2368
|
+
state.dump = "{" + _result + "}";
|
|
2369
|
+
}
|
|
2370
|
+
function writeBlockMapping(state, level, object, compact) {
|
|
2371
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
|
|
2372
|
+
if (state.sortKeys === true) {
|
|
2373
|
+
objectKeyList.sort();
|
|
2374
|
+
} else if (typeof state.sortKeys === "function") {
|
|
2375
|
+
objectKeyList.sort(state.sortKeys);
|
|
2376
|
+
} else if (state.sortKeys) {
|
|
2377
|
+
throw new exception("sortKeys must be a boolean or a function");
|
|
2378
|
+
}
|
|
2379
|
+
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2380
|
+
pairBuffer = "";
|
|
2381
|
+
if (!compact || _result !== "") {
|
|
2382
|
+
pairBuffer += generateNextLine(state, level);
|
|
2383
|
+
}
|
|
2384
|
+
objectKey = objectKeyList[index];
|
|
2385
|
+
objectValue = object[objectKey];
|
|
2386
|
+
if (state.replacer) {
|
|
2387
|
+
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
2388
|
+
}
|
|
2389
|
+
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
|
2390
|
+
continue;
|
|
2391
|
+
}
|
|
2392
|
+
explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
|
|
2393
|
+
if (explicitPair) {
|
|
2394
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2395
|
+
pairBuffer += "?";
|
|
2396
|
+
} else {
|
|
2397
|
+
pairBuffer += "? ";
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
pairBuffer += state.dump;
|
|
2401
|
+
if (explicitPair) {
|
|
2402
|
+
pairBuffer += generateNextLine(state, level);
|
|
2403
|
+
}
|
|
2404
|
+
if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
|
|
2405
|
+
continue;
|
|
2406
|
+
}
|
|
2407
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2408
|
+
pairBuffer += ":";
|
|
2409
|
+
} else {
|
|
2410
|
+
pairBuffer += ": ";
|
|
2411
|
+
}
|
|
2412
|
+
pairBuffer += state.dump;
|
|
2413
|
+
_result += pairBuffer;
|
|
2414
|
+
}
|
|
2415
|
+
state.tag = _tag;
|
|
2416
|
+
state.dump = _result || "{}";
|
|
2417
|
+
}
|
|
2418
|
+
function detectType(state, object, explicit) {
|
|
2419
|
+
var _result, typeList, index, length, type2, style;
|
|
2420
|
+
typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
|
2421
|
+
for (index = 0, length = typeList.length; index < length; index += 1) {
|
|
2422
|
+
type2 = typeList[index];
|
|
2423
|
+
if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object === "object" && object instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object))) {
|
|
2424
|
+
if (explicit) {
|
|
2425
|
+
if (type2.multi && type2.representName) {
|
|
2426
|
+
state.tag = type2.representName(object);
|
|
2427
|
+
} else {
|
|
2428
|
+
state.tag = type2.tag;
|
|
2429
|
+
}
|
|
2430
|
+
} else {
|
|
2431
|
+
state.tag = "?";
|
|
2432
|
+
}
|
|
2433
|
+
if (type2.represent) {
|
|
2434
|
+
style = state.styleMap[type2.tag] || type2.defaultStyle;
|
|
2435
|
+
if (_toString.call(type2.represent) === "[object Function]") {
|
|
2436
|
+
_result = type2.represent(object, style);
|
|
2437
|
+
} else if (_hasOwnProperty.call(type2.represent, style)) {
|
|
2438
|
+
_result = type2.represent[style](object, style);
|
|
2439
|
+
} else {
|
|
2440
|
+
throw new exception("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style');
|
|
2441
|
+
}
|
|
2442
|
+
state.dump = _result;
|
|
2443
|
+
}
|
|
2444
|
+
return true;
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
return false;
|
|
2448
|
+
}
|
|
2449
|
+
function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
2450
|
+
state.tag = null;
|
|
2451
|
+
state.dump = object;
|
|
2452
|
+
if (!detectType(state, object, false)) {
|
|
2453
|
+
detectType(state, object, true);
|
|
2454
|
+
}
|
|
2455
|
+
var type2 = _toString.call(state.dump);
|
|
2456
|
+
var inblock = block;
|
|
2457
|
+
var tagStr;
|
|
2458
|
+
if (block) {
|
|
2459
|
+
block = state.flowLevel < 0 || state.flowLevel > level;
|
|
2460
|
+
}
|
|
2461
|
+
var objectOrArray = type2 === "[object Object]" || type2 === "[object Array]", duplicateIndex, duplicate;
|
|
2462
|
+
if (objectOrArray) {
|
|
2463
|
+
duplicateIndex = state.duplicates.indexOf(object);
|
|
2464
|
+
duplicate = duplicateIndex !== -1;
|
|
2465
|
+
}
|
|
2466
|
+
if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
|
|
2467
|
+
compact = false;
|
|
2468
|
+
}
|
|
2469
|
+
if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
|
2470
|
+
state.dump = "*ref_" + duplicateIndex;
|
|
2471
|
+
} else {
|
|
2472
|
+
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
|
2473
|
+
state.usedDuplicates[duplicateIndex] = true;
|
|
2474
|
+
}
|
|
2475
|
+
if (type2 === "[object Object]") {
|
|
2476
|
+
if (block && Object.keys(state.dump).length !== 0) {
|
|
2477
|
+
writeBlockMapping(state, level, state.dump, compact);
|
|
2478
|
+
if (duplicate) {
|
|
2479
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2480
|
+
}
|
|
2481
|
+
} else {
|
|
2482
|
+
writeFlowMapping(state, level, state.dump);
|
|
2483
|
+
if (duplicate) {
|
|
2484
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
} else if (type2 === "[object Array]") {
|
|
2488
|
+
if (block && state.dump.length !== 0) {
|
|
2489
|
+
if (state.noArrayIndent && !isblockseq && level > 0) {
|
|
2490
|
+
writeBlockSequence(state, level - 1, state.dump, compact);
|
|
2491
|
+
} else {
|
|
2492
|
+
writeBlockSequence(state, level, state.dump, compact);
|
|
2493
|
+
}
|
|
2494
|
+
if (duplicate) {
|
|
2495
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2496
|
+
}
|
|
2497
|
+
} else {
|
|
2498
|
+
writeFlowSequence(state, level, state.dump);
|
|
2499
|
+
if (duplicate) {
|
|
2500
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
} else if (type2 === "[object String]") {
|
|
2504
|
+
if (state.tag !== "?") {
|
|
2505
|
+
writeScalar(state, state.dump, level, iskey, inblock);
|
|
2506
|
+
}
|
|
2507
|
+
} else if (type2 === "[object Undefined]") {
|
|
2508
|
+
return false;
|
|
2509
|
+
} else {
|
|
2510
|
+
if (state.skipInvalid) return false;
|
|
2511
|
+
throw new exception("unacceptable kind of an object to dump " + type2);
|
|
2512
|
+
}
|
|
2513
|
+
if (state.tag !== null && state.tag !== "?") {
|
|
2514
|
+
tagStr = encodeURI(
|
|
2515
|
+
state.tag[0] === "!" ? state.tag.slice(1) : state.tag
|
|
2516
|
+
).replace(/!/g, "%21");
|
|
2517
|
+
if (state.tag[0] === "!") {
|
|
2518
|
+
tagStr = "!" + tagStr;
|
|
2519
|
+
} else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
|
|
2520
|
+
tagStr = "!!" + tagStr.slice(18);
|
|
2521
|
+
} else {
|
|
2522
|
+
tagStr = "!<" + tagStr + ">";
|
|
2523
|
+
}
|
|
2524
|
+
state.dump = tagStr + " " + state.dump;
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
return true;
|
|
2528
|
+
}
|
|
2529
|
+
function getDuplicateReferences(object, state) {
|
|
2530
|
+
var objects = [], duplicatesIndexes = [], index, length;
|
|
2531
|
+
inspectNode(object, objects, duplicatesIndexes);
|
|
2532
|
+
for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
|
|
2533
|
+
state.duplicates.push(objects[duplicatesIndexes[index]]);
|
|
2534
|
+
}
|
|
2535
|
+
state.usedDuplicates = new Array(length);
|
|
2536
|
+
}
|
|
2537
|
+
function inspectNode(object, objects, duplicatesIndexes) {
|
|
2538
|
+
var objectKeyList, index, length;
|
|
2539
|
+
if (object !== null && typeof object === "object") {
|
|
2540
|
+
index = objects.indexOf(object);
|
|
2541
|
+
if (index !== -1) {
|
|
2542
|
+
if (duplicatesIndexes.indexOf(index) === -1) {
|
|
2543
|
+
duplicatesIndexes.push(index);
|
|
2544
|
+
}
|
|
2545
|
+
} else {
|
|
2546
|
+
objects.push(object);
|
|
2547
|
+
if (Array.isArray(object)) {
|
|
2548
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2549
|
+
inspectNode(object[index], objects, duplicatesIndexes);
|
|
2550
|
+
}
|
|
2551
|
+
} else {
|
|
2552
|
+
objectKeyList = Object.keys(object);
|
|
2553
|
+
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2554
|
+
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
function dump$1(input, options) {
|
|
2561
|
+
options = options || {};
|
|
2562
|
+
var state = new State(options);
|
|
2563
|
+
if (!state.noRefs) getDuplicateReferences(input, state);
|
|
2564
|
+
var value = input;
|
|
2565
|
+
if (state.replacer) {
|
|
2566
|
+
value = state.replacer.call({ "": value }, "", value);
|
|
2567
|
+
}
|
|
2568
|
+
if (writeNode(state, 0, value, true, true)) return state.dump + "\n";
|
|
2569
|
+
return "";
|
|
2570
|
+
}
|
|
2571
|
+
var dump_1 = dump$1;
|
|
2572
|
+
var dumper = {
|
|
2573
|
+
dump: dump_1
|
|
2574
|
+
};
|
|
2575
|
+
function renamed(from, to) {
|
|
2576
|
+
return function() {
|
|
2577
|
+
throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default.");
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
var load = loader.load;
|
|
2581
|
+
var loadAll = loader.loadAll;
|
|
2582
|
+
var dump = dumper.dump;
|
|
2583
|
+
var safeLoad = renamed("safeLoad", "load");
|
|
2584
|
+
var safeLoadAll = renamed("safeLoadAll", "loadAll");
|
|
2585
|
+
var safeDump = renamed("safeDump", "dump");
|
|
2586
|
+
|
|
2587
|
+
// src/local-evaluator/schema.ts
|
|
2588
|
+
function validatePolicy(policy) {
|
|
2589
|
+
const errors = [];
|
|
2590
|
+
if (!policy || typeof policy !== "object") {
|
|
2591
|
+
return { valid: false, errors: [{ path: "", message: "Policy must be an object" }] };
|
|
2592
|
+
}
|
|
2593
|
+
const p = policy;
|
|
2594
|
+
if (typeof p.version !== "string") {
|
|
2595
|
+
errors.push({ path: "version", message: "version is required and must be a string" });
|
|
2596
|
+
}
|
|
2597
|
+
if (typeof p.name !== "string") {
|
|
2598
|
+
errors.push({ path: "name", message: "name is required and must be a string" });
|
|
2599
|
+
}
|
|
2600
|
+
if (!Array.isArray(p.purposes)) {
|
|
2601
|
+
errors.push({ path: "purposes", message: "purposes is required and must be an array" });
|
|
2602
|
+
} else {
|
|
2603
|
+
p.purposes.forEach((purpose, i) => {
|
|
2604
|
+
errors.push(...validatePurpose(purpose, `purposes[${i}]`));
|
|
2605
|
+
});
|
|
2606
|
+
}
|
|
2607
|
+
if (p.scope !== void 0) {
|
|
2608
|
+
errors.push(...validateScope(p.scope, "scope"));
|
|
2609
|
+
}
|
|
2610
|
+
if (p.limits !== void 0) {
|
|
2611
|
+
errors.push(...validateLimits(p.limits, "limits"));
|
|
2612
|
+
}
|
|
2613
|
+
if (p.riskThresholds !== void 0) {
|
|
2614
|
+
errors.push(...validateRiskThresholds(p.riskThresholds, "riskThresholds"));
|
|
2615
|
+
}
|
|
2616
|
+
return { valid: errors.length === 0, errors };
|
|
2617
|
+
}
|
|
2618
|
+
function validatePurpose(purpose, path) {
|
|
2619
|
+
const errors = [];
|
|
2620
|
+
if (!purpose || typeof purpose !== "object") {
|
|
2621
|
+
return [{ path, message: "purpose must be an object" }];
|
|
2622
|
+
}
|
|
2623
|
+
const p = purpose;
|
|
2624
|
+
if (typeof p.id !== "string" || !p.id) {
|
|
2625
|
+
errors.push({ path: `${path}.id`, message: "id is required and must be a non-empty string" });
|
|
2626
|
+
}
|
|
2627
|
+
if (typeof p.allowed !== "boolean") {
|
|
2628
|
+
errors.push({ path: `${path}.allowed`, message: "allowed is required and must be a boolean" });
|
|
2629
|
+
}
|
|
2630
|
+
if (p.targets !== void 0 && !isStringArray(p.targets)) {
|
|
2631
|
+
errors.push({ path: `${path}.targets`, message: "targets must be an array of strings" });
|
|
2632
|
+
}
|
|
2633
|
+
if (p.blockedPatterns !== void 0 && !isStringArray(p.blockedPatterns)) {
|
|
2634
|
+
errors.push({ path: `${path}.blockedPatterns`, message: "blockedPatterns must be an array of strings" });
|
|
2635
|
+
}
|
|
2636
|
+
if (p.requiresApproval !== void 0 && typeof p.requiresApproval !== "boolean") {
|
|
2637
|
+
errors.push({ path: `${path}.requiresApproval`, message: "requiresApproval must be a boolean" });
|
|
2638
|
+
}
|
|
2639
|
+
return errors;
|
|
2640
|
+
}
|
|
2641
|
+
function validateScope(scope, path) {
|
|
2642
|
+
const errors = [];
|
|
2643
|
+
if (typeof scope !== "object" || scope === null) {
|
|
2644
|
+
return [{ path, message: "scope must be an object" }];
|
|
2645
|
+
}
|
|
2646
|
+
const s = scope;
|
|
2647
|
+
for (const field of ["allowedDomains", "blockedDomains", "blockedResources"]) {
|
|
2648
|
+
if (s[field] !== void 0 && !isStringArray(s[field])) {
|
|
2649
|
+
errors.push({ path: `${path}.${field}`, message: `${field} must be an array of strings` });
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
return errors;
|
|
2653
|
+
}
|
|
2654
|
+
function validateLimits(limits, path) {
|
|
2655
|
+
const errors = [];
|
|
2656
|
+
if (typeof limits !== "object" || limits === null) {
|
|
2657
|
+
return [{ path, message: "limits must be an object" }];
|
|
2658
|
+
}
|
|
2659
|
+
const l = limits;
|
|
2660
|
+
if (l.maxTransactionAmount !== void 0 && typeof l.maxTransactionAmount !== "number") {
|
|
2661
|
+
errors.push({ path: `${path}.maxTransactionAmount`, message: "maxTransactionAmount must be a number" });
|
|
2662
|
+
}
|
|
2663
|
+
if (l.maxRequestsPerHour !== void 0 && typeof l.maxRequestsPerHour !== "number") {
|
|
2664
|
+
errors.push({ path: `${path}.maxRequestsPerHour`, message: "maxRequestsPerHour must be a number" });
|
|
2665
|
+
}
|
|
2666
|
+
if (l.currency !== void 0 && typeof l.currency !== "string") {
|
|
2667
|
+
errors.push({ path: `${path}.currency`, message: "currency must be a string" });
|
|
2668
|
+
}
|
|
2669
|
+
return errors;
|
|
2670
|
+
}
|
|
2671
|
+
function validateRiskThresholds(thresholds, path) {
|
|
2672
|
+
const errors = [];
|
|
2673
|
+
if (typeof thresholds !== "object" || thresholds === null) {
|
|
2674
|
+
return [{ path, message: "riskThresholds must be an object" }];
|
|
2675
|
+
}
|
|
2676
|
+
const t = thresholds;
|
|
2677
|
+
for (const range of ["autoAllow", "requireApproval", "autoBlock"]) {
|
|
2678
|
+
if (!t[range] || typeof t[range] !== "object") {
|
|
2679
|
+
errors.push({ path: `${path}.${range}`, message: `${range} is required and must be an object with min and max` });
|
|
2680
|
+
continue;
|
|
2681
|
+
}
|
|
2682
|
+
const r = t[range];
|
|
2683
|
+
if (typeof r.min !== "number" || typeof r.max !== "number") {
|
|
2684
|
+
errors.push({ path: `${path}.${range}`, message: `${range} must have numeric min and max` });
|
|
2685
|
+
} else if (r.min > r.max) {
|
|
2686
|
+
errors.push({ path: `${path}.${range}`, message: `${range}.min must be <= ${range}.max` });
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
if (isValidThresholdShape(t)) {
|
|
2690
|
+
const thresholdObj = t;
|
|
2691
|
+
if (thresholdObj.autoAllow.max + 1 !== thresholdObj.requireApproval.min) {
|
|
2692
|
+
errors.push({
|
|
2693
|
+
path: `${path}`,
|
|
2694
|
+
message: `Gap between autoAllow.max (${thresholdObj.autoAllow.max}) and requireApproval.min (${thresholdObj.requireApproval.min}). Ranges must be contiguous.`
|
|
2695
|
+
});
|
|
2696
|
+
}
|
|
2697
|
+
if (thresholdObj.requireApproval.max + 1 !== thresholdObj.autoBlock.min) {
|
|
2698
|
+
errors.push({
|
|
2699
|
+
path: `${path}`,
|
|
2700
|
+
message: `Gap between requireApproval.max (${thresholdObj.requireApproval.max}) and autoBlock.min (${thresholdObj.autoBlock.min}). Ranges must be contiguous.`
|
|
2701
|
+
});
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
return errors;
|
|
2705
|
+
}
|
|
2706
|
+
function isStringArray(val) {
|
|
2707
|
+
return Array.isArray(val) && val.every((v) => typeof v === "string");
|
|
2708
|
+
}
|
|
2709
|
+
function isValidThresholdShape(t) {
|
|
2710
|
+
for (const key of ["autoAllow", "requireApproval", "autoBlock"]) {
|
|
2711
|
+
const r = t[key];
|
|
2712
|
+
if (!r || typeof r !== "object") return false;
|
|
2713
|
+
const range = r;
|
|
2714
|
+
if (typeof range.min !== "number" || typeof range.max !== "number") return false;
|
|
2715
|
+
}
|
|
2716
|
+
return true;
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
// src/local-evaluator/pdlss-parser.ts
|
|
2720
|
+
function toYaml(policy) {
|
|
2721
|
+
return dump(policy, { lineWidth: 120, noRefs: true });
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
// src/cli/wizard.ts
|
|
2725
|
+
var PURPOSE_CATEGORIES = [
|
|
2726
|
+
{
|
|
2727
|
+
id: "email",
|
|
2728
|
+
label: "EMAIL ACCESS",
|
|
2729
|
+
explainer: "",
|
|
2730
|
+
subActions: [
|
|
2731
|
+
{
|
|
2732
|
+
id: "email.read",
|
|
2733
|
+
label: "Can this agent read your emails?",
|
|
2734
|
+
explainer: "This means the agent can view email content in your inbox.\n Useful for agents that summarise or search emails.",
|
|
2735
|
+
recommended: "yes"
|
|
2736
|
+
},
|
|
2737
|
+
{
|
|
2738
|
+
id: "email.send",
|
|
2739
|
+
label: "Can it send emails on your behalf?",
|
|
2740
|
+
explainer: "The agent could compose and send emails as you. This is powerful\n but risky \u2014 a mistake could send something to the wrong person.",
|
|
2741
|
+
recommended: "approval"
|
|
2742
|
+
},
|
|
2743
|
+
{
|
|
2744
|
+
id: "email.delete",
|
|
2745
|
+
label: "Can it delete emails?",
|
|
2746
|
+
explainer: "Permanently removes emails from your mailbox. Usually not needed\n and hard to undo.",
|
|
2747
|
+
recommended: "no"
|
|
2748
|
+
}
|
|
2749
|
+
],
|
|
2750
|
+
recommendedDefault: ""
|
|
2751
|
+
},
|
|
2752
|
+
{
|
|
2753
|
+
id: "shell",
|
|
2754
|
+
label: "SHELL / TERMINAL COMMANDS",
|
|
2755
|
+
explainer: "",
|
|
2756
|
+
subActions: [
|
|
2757
|
+
{
|
|
2758
|
+
id: "shell.exec",
|
|
2759
|
+
label: "Can this agent run commands on your computer?",
|
|
2760
|
+
explainer: '"Shell commands" are instructions your computer executes directly,\n like installing software, moving files, or running scripts. Some\n commands are harmless (listing files), others can be dangerous\n (deleting everything, changing system settings).',
|
|
2761
|
+
recommended: "approval"
|
|
2762
|
+
}
|
|
2763
|
+
],
|
|
2764
|
+
recommendedDefault: ""
|
|
2765
|
+
},
|
|
2766
|
+
{
|
|
2767
|
+
id: "file",
|
|
2768
|
+
label: "FILE ACCESS",
|
|
2769
|
+
explainer: "",
|
|
2770
|
+
subActions: [
|
|
2771
|
+
{
|
|
2772
|
+
id: "file.read",
|
|
2773
|
+
label: "Can this agent read files?",
|
|
2774
|
+
explainer: "Reading files lets the agent look at your source code, documents,\n and configuration. Usually needed for most tasks.",
|
|
2775
|
+
recommended: "yes"
|
|
2776
|
+
},
|
|
2777
|
+
{
|
|
2778
|
+
id: "file.write",
|
|
2779
|
+
label: "Can it create or modify files?",
|
|
2780
|
+
explainer: '"Write" means creating new files or changing existing ones.\n Restricting this to your project folder prevents the agent\n from accidentally modifying system files or personal data.',
|
|
2781
|
+
recommended: "yes"
|
|
2782
|
+
},
|
|
2783
|
+
{
|
|
2784
|
+
id: "file.delete",
|
|
2785
|
+
label: "Can it delete files?",
|
|
2786
|
+
explainer: "Permanently removes files from your filesystem. Can be dangerous\n if the agent deletes the wrong files.",
|
|
2787
|
+
recommended: "approval"
|
|
2788
|
+
}
|
|
2789
|
+
],
|
|
2790
|
+
recommendedDefault: ""
|
|
2791
|
+
},
|
|
2792
|
+
{
|
|
2793
|
+
id: "network",
|
|
2794
|
+
label: "NETWORK ACCESS",
|
|
2795
|
+
explainer: "",
|
|
2796
|
+
subActions: [
|
|
2797
|
+
{
|
|
2798
|
+
id: "network.request",
|
|
2799
|
+
label: "Can this agent connect to websites/APIs?",
|
|
2800
|
+
explainer: "Controls which external services the agent can communicate with.\n Restricting this prevents the agent from sending your data to\n unknown services.",
|
|
2801
|
+
recommended: "yes"
|
|
2802
|
+
}
|
|
2803
|
+
],
|
|
2804
|
+
recommendedDefault: ""
|
|
2805
|
+
},
|
|
2806
|
+
{
|
|
2807
|
+
id: "calendar",
|
|
2808
|
+
label: "CALENDAR ACCESS",
|
|
2809
|
+
explainer: "",
|
|
2810
|
+
subActions: [
|
|
2811
|
+
{
|
|
2812
|
+
id: "calendar.read",
|
|
2813
|
+
label: "Can this agent read your calendar?",
|
|
2814
|
+
explainer: "Lets the agent see your scheduled events and availability.",
|
|
2815
|
+
recommended: "yes"
|
|
2816
|
+
},
|
|
2817
|
+
{
|
|
2818
|
+
id: "calendar.create",
|
|
2819
|
+
label: "Can it create new calendar events?",
|
|
2820
|
+
explainer: "The agent could add meetings or reminders to your calendar.",
|
|
2821
|
+
recommended: "approval"
|
|
2822
|
+
},
|
|
2823
|
+
{
|
|
2824
|
+
id: "calendar.modify",
|
|
2825
|
+
label: "Can it modify existing events?",
|
|
2826
|
+
explainer: "Changes to existing calendar events could cause missed meetings.",
|
|
2827
|
+
recommended: "no"
|
|
2828
|
+
}
|
|
2829
|
+
],
|
|
2830
|
+
recommendedDefault: ""
|
|
2831
|
+
},
|
|
2832
|
+
{
|
|
2833
|
+
id: "database",
|
|
2834
|
+
label: "DATABASE ACCESS",
|
|
2835
|
+
explainer: "",
|
|
2836
|
+
subActions: [
|
|
2837
|
+
{
|
|
2838
|
+
id: "database.query",
|
|
2839
|
+
label: "Can this agent query databases?",
|
|
2840
|
+
explainer: "Read-only database access for looking up information.",
|
|
2841
|
+
recommended: "approval"
|
|
2842
|
+
},
|
|
2843
|
+
{
|
|
2844
|
+
id: "database.write",
|
|
2845
|
+
label: "Can it write to databases?",
|
|
2846
|
+
explainer: "Modifying database records can cause data loss or corruption.",
|
|
2847
|
+
recommended: "no"
|
|
2848
|
+
}
|
|
2849
|
+
],
|
|
2850
|
+
recommendedDefault: ""
|
|
2851
|
+
},
|
|
2852
|
+
{
|
|
2853
|
+
id: "payment",
|
|
2854
|
+
label: "FINANCIAL / PAYMENTS",
|
|
2855
|
+
explainer: "",
|
|
2856
|
+
subActions: [
|
|
2857
|
+
{
|
|
2858
|
+
id: "payment.execute",
|
|
2859
|
+
label: "Can this agent make purchases or financial transactions?",
|
|
2860
|
+
explainer: "This allows the agent to spend money on your behalf. Almost\n always should be blocked or require approval.",
|
|
2861
|
+
recommended: "no"
|
|
2862
|
+
}
|
|
2863
|
+
],
|
|
2864
|
+
recommendedDefault: ""
|
|
2865
|
+
}
|
|
2866
|
+
];
|
|
2867
|
+
var DEFAULT_BLOCKED_COMMANDS = [
|
|
2868
|
+
{ pattern: "sudo*", label: '"sudo" \u2014 runs commands with administrator/root privileges', recommended: true },
|
|
2869
|
+
{ pattern: "rm -rf*", label: '"rm -rf" \u2014 forcefully deletes files and folders (cannot be undone)', recommended: true },
|
|
2870
|
+
{ pattern: "chmod 777*", label: '"chmod 777" \u2014 makes files accessible to everyone on the system', recommended: true },
|
|
2871
|
+
{ pattern: "curl*|*bash*", label: '"curl | bash" \u2014 downloads and immediately runs code from the internet', recommended: true },
|
|
2872
|
+
{ pattern: "wget*|*sh*", label: '"wget | sh" \u2014 same as above, different tool', recommended: true },
|
|
2873
|
+
{ pattern: "kill*", label: '"kill" \u2014 stops running programs', recommended: false },
|
|
2874
|
+
{ pattern: "reboot*", label: '"reboot" / "shutdown" \u2014 restarts or turns off your computer', recommended: false },
|
|
2875
|
+
{ pattern: "shutdown*", label: '"shutdown" \u2014 turns off your computer', recommended: false },
|
|
2876
|
+
{ pattern: "mkfs*", label: '"mkfs" \u2014 formats/erases a disk drive', recommended: false }
|
|
2877
|
+
];
|
|
2878
|
+
var DEFAULT_BLOCKED_PATHS = [
|
|
2879
|
+
{ pattern: "~/.ssh/*", label: "SSH keys (~/.ssh/) \u2014 used to log into remote servers", recommended: true },
|
|
2880
|
+
{ pattern: "~/.aws/*", label: "AWS credentials (~/.aws/) \u2014 cloud service access keys", recommended: true },
|
|
2881
|
+
{ pattern: "**/.env", label: "Environment files (.env) \u2014 often contain passwords and secrets", recommended: true },
|
|
2882
|
+
{ pattern: "~/.gitconfig", label: "Git config (~/.gitconfig) \u2014 may contain access tokens", recommended: true }
|
|
2883
|
+
];
|
|
2884
|
+
var RISK_PRESETS = [
|
|
2885
|
+
{
|
|
2886
|
+
name: "conservative",
|
|
2887
|
+
label: "Conservative \u2014 Ask for approval on anything even slightly risky",
|
|
2888
|
+
thresholds: { autoAllow: { min: 0, max: 15 }, requireApproval: { min: 16, max: 50 }, autoBlock: { min: 51, max: 100 } }
|
|
2889
|
+
},
|
|
2890
|
+
{
|
|
2891
|
+
name: "balanced",
|
|
2892
|
+
label: "Balanced \u2014 Auto-allow low risk, ask for medium, block high [Recommended]",
|
|
2893
|
+
thresholds: { autoAllow: { min: 0, max: 30 }, requireApproval: { min: 31, max: 70 }, autoBlock: { min: 71, max: 100 } }
|
|
2894
|
+
},
|
|
2895
|
+
{
|
|
2896
|
+
name: "permissive",
|
|
2897
|
+
label: "Permissive \u2014 Auto-allow most things, only block clearly dangerous",
|
|
2898
|
+
thresholds: { autoAllow: { min: 0, max: 60 }, requireApproval: { min: 61, max: 85 }, autoBlock: { min: 86, max: 100 } }
|
|
2899
|
+
}
|
|
2900
|
+
];
|
|
2901
|
+
var SetupWizard = class {
|
|
2902
|
+
constructor(prompt) {
|
|
2903
|
+
this.prompt = prompt;
|
|
2904
|
+
}
|
|
2905
|
+
/**
|
|
2906
|
+
* Run the full interactive wizard and return a validated LocalPolicy.
|
|
2907
|
+
*/
|
|
2908
|
+
async run() {
|
|
2909
|
+
this.print("\nAstraSync Local Guard Setup\n");
|
|
2910
|
+
this.print("Let's set up protection for your AI agent. Each question includes an");
|
|
2911
|
+
this.print("explanation \u2014 if you're unsure, the recommended defaults are highlighted.\n");
|
|
2912
|
+
const purposes = [];
|
|
2913
|
+
for (const category of PURPOSE_CATEGORIES) {
|
|
2914
|
+
this.print(`---
|
|
2915
|
+
|
|
2916
|
+
${category.label}
|
|
2917
|
+
`);
|
|
2918
|
+
if (category.subActions) {
|
|
2919
|
+
for (const sub of category.subActions) {
|
|
2920
|
+
const rule = await this.askPurposeQuestion(sub);
|
|
2921
|
+
purposes.push(rule);
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
const shellRule = purposes.find((p) => p.id === "shell.exec");
|
|
2926
|
+
if (shellRule && shellRule.allowed) {
|
|
2927
|
+
this.print("\nShould any commands be automatically blocked?");
|
|
2928
|
+
this.print(" These are commands that could cause serious damage.\n");
|
|
2929
|
+
const blocked = await this.askBlockedCommands();
|
|
2930
|
+
if (blocked.length > 0) {
|
|
2931
|
+
shellRule.blockedPatterns = blocked;
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
const fileWriteRule = purposes.find((p) => p.id === "file.write");
|
|
2935
|
+
if (fileWriteRule && fileWriteRule.allowed) {
|
|
2936
|
+
this.print("\nWhich folders can the agent write to?");
|
|
2937
|
+
this.print(" Restricting this to your project folder prevents the agent");
|
|
2938
|
+
this.print(" from accidentally modifying system files or personal data.");
|
|
2939
|
+
const targets = await this.askCommaSeparated("[Default: no restriction] ");
|
|
2940
|
+
if (targets.length > 0) {
|
|
2941
|
+
fileWriteRule.targets = targets;
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
const fileReadRule = purposes.find((p) => p.id === "file.read");
|
|
2945
|
+
if (fileReadRule && fileReadRule.allowed) {
|
|
2946
|
+
this.print("\nShould any files be off-limits for reading?");
|
|
2947
|
+
this.print(" Some files contain passwords, API keys, or private credentials.\n");
|
|
2948
|
+
const blocked = await this.askBlockedPaths();
|
|
2949
|
+
if (blocked.length > 0) {
|
|
2950
|
+
fileReadRule.blockedPatterns = blocked;
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
let scope;
|
|
2954
|
+
const networkRule = purposes.find((p) => p.id === "network.request");
|
|
2955
|
+
if (networkRule && networkRule.allowed) {
|
|
2956
|
+
this.print("\nWhich websites/APIs can this agent connect to?");
|
|
2957
|
+
this.print(" Leave blank to allow all, or list specific domains.\n");
|
|
2958
|
+
const allowed = await this.askCommaSeparated("[Default: all allowed] ");
|
|
2959
|
+
this.print("\nAny websites that should always be blocked?");
|
|
2960
|
+
const blocked = await this.askCommaSeparated("[Default: none] ");
|
|
2961
|
+
if (allowed.length > 0 || blocked.length > 0) {
|
|
2962
|
+
scope = {};
|
|
2963
|
+
if (allowed.length > 0) scope.allowedDomains = allowed;
|
|
2964
|
+
if (blocked.length > 0) scope.blockedDomains = blocked;
|
|
2965
|
+
}
|
|
2966
|
+
}
|
|
2967
|
+
let limits;
|
|
2968
|
+
const paymentRule = purposes.find((p) => p.id === "payment.execute");
|
|
2969
|
+
if (paymentRule && paymentRule.allowed) {
|
|
2970
|
+
this.print("\nMaximum transaction amount?");
|
|
2971
|
+
this.print(" If the agent makes any purchases, this is the max amount.\n");
|
|
2972
|
+
const amountStr = await this.ask("[Default: $1000] ");
|
|
2973
|
+
const amount = parseFloat(amountStr.replace(/[$,]/g, "")) || 1e3;
|
|
2974
|
+
limits = { maxTransactionAmount: amount };
|
|
2975
|
+
}
|
|
2976
|
+
this.print("\nMaximum requests per hour?");
|
|
2977
|
+
this.print(" Limits how many actions the agent can take per hour.\n");
|
|
2978
|
+
const rateStr = await this.ask("[Default: 100, Enter to skip] ");
|
|
2979
|
+
if (rateStr.trim()) {
|
|
2980
|
+
const rate = parseInt(rateStr, 10);
|
|
2981
|
+
if (!isNaN(rate) && rate > 0) {
|
|
2982
|
+
if (!limits) limits = {};
|
|
2983
|
+
limits.maxRequestsPerHour = rate;
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
this.print("\n---\n\nRISK THRESHOLDS\n");
|
|
2987
|
+
this.print("How cautious should the agent be?");
|
|
2988
|
+
this.print(" This controls how the agent handles actions that fall in a grey");
|
|
2989
|
+
this.print(" area \u2014 not clearly safe, not clearly dangerous.\n");
|
|
2990
|
+
const riskThresholds = await this.askRiskPreset();
|
|
2991
|
+
this.print("\n---\n\nADDITIONAL BLOCKS (optional)\n");
|
|
2992
|
+
this.print("Would you like to block any additional resource patterns?");
|
|
2993
|
+
this.print(" You can block specific patterns the agent should never access.\n");
|
|
2994
|
+
const additionalBlocked = await this.askCommaSeparated("[Enter to skip] ");
|
|
2995
|
+
if (additionalBlocked.length > 0) {
|
|
2996
|
+
if (!scope) scope = {};
|
|
2997
|
+
scope.blockedResources = additionalBlocked;
|
|
2998
|
+
}
|
|
2999
|
+
this.print("");
|
|
3000
|
+
const name = (await this.ask("Policy name [default: local-guard]: ")).trim() || "local-guard";
|
|
3001
|
+
const policy = {
|
|
3002
|
+
version: "1.0",
|
|
3003
|
+
name,
|
|
3004
|
+
purposes,
|
|
3005
|
+
...scope && { scope },
|
|
3006
|
+
...limits && { limits },
|
|
3007
|
+
riskThresholds
|
|
3008
|
+
};
|
|
3009
|
+
const validation = validatePolicy(policy);
|
|
3010
|
+
if (!validation.valid) {
|
|
3011
|
+
this.print("\nWarning: Policy has validation issues:");
|
|
3012
|
+
for (const err of validation.errors) {
|
|
3013
|
+
this.print(` - ${err.message}`);
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
return policy;
|
|
3017
|
+
}
|
|
3018
|
+
/**
|
|
3019
|
+
* Run the wizard and write the result to a YAML file.
|
|
3020
|
+
*/
|
|
3021
|
+
async runAndSave(outputPath) {
|
|
3022
|
+
const policy = await this.run();
|
|
3023
|
+
const yaml = toYaml(policy);
|
|
3024
|
+
const fs = await import("fs");
|
|
3025
|
+
fs.writeFileSync(outputPath, yaml, "utf-8");
|
|
3026
|
+
this.print(`
|
|
3027
|
+
Policy saved to ${outputPath}`);
|
|
3028
|
+
this.print(" AstraSync Local Guard is now protecting your agent.\n");
|
|
3029
|
+
this.print(" You can edit this file directly at any time, or re-run the wizard");
|
|
3030
|
+
this.print(" with: astrasync guard setup\n");
|
|
3031
|
+
this.print(" To upgrade to cloud-connected verification with trust scoring");
|
|
3032
|
+
this.print(" and audit trails: astrasync guard upgrade\n");
|
|
3033
|
+
return policy;
|
|
3034
|
+
}
|
|
3035
|
+
// =====================================================================
|
|
3036
|
+
// Question helpers
|
|
3037
|
+
// =====================================================================
|
|
3038
|
+
async askPurposeQuestion(sub) {
|
|
3039
|
+
this.print(`${sub.label}`);
|
|
3040
|
+
this.print(` ${sub.explainer}`);
|
|
3041
|
+
const recommendLabel = sub.recommended === "yes" ? "Yes" : sub.recommended === "no" ? "No" : "Yes, but ask me first";
|
|
3042
|
+
this.print(` [Recommended: ${recommendLabel}]`);
|
|
3043
|
+
const answer = await this.ask(" (y)es / (n)o / (a)sk me first [default: " + sub.recommended.charAt(0) + "]: ");
|
|
3044
|
+
const choice = this.parseYesNoApproval(answer, sub.recommended);
|
|
3045
|
+
const rule = {
|
|
3046
|
+
id: sub.id,
|
|
3047
|
+
allowed: choice !== "no"
|
|
3048
|
+
};
|
|
3049
|
+
if (choice === "approval") {
|
|
3050
|
+
rule.requiresApproval = true;
|
|
3051
|
+
}
|
|
3052
|
+
return rule;
|
|
3053
|
+
}
|
|
3054
|
+
async askBlockedCommands() {
|
|
3055
|
+
const blocked = [];
|
|
3056
|
+
for (const cmd of DEFAULT_BLOCKED_COMMANDS) {
|
|
3057
|
+
const label = cmd.recommended ? "[x]" : "[ ]";
|
|
3058
|
+
this.print(` ${label} ${cmd.label}`);
|
|
3059
|
+
}
|
|
3060
|
+
const answer = await this.ask("\n Accept recommended defaults? (y)es / (n)o / (c)ustomize [default: y]: ");
|
|
3061
|
+
const choice = answer.trim().toLowerCase();
|
|
3062
|
+
if (choice === "n" || choice === "no") {
|
|
3063
|
+
return [];
|
|
3064
|
+
}
|
|
3065
|
+
if (choice === "c" || choice === "customize") {
|
|
3066
|
+
for (const cmd of DEFAULT_BLOCKED_COMMANDS) {
|
|
3067
|
+
const def = cmd.recommended ? "y" : "n";
|
|
3068
|
+
const a = await this.ask(` Block ${cmd.pattern}? [default: ${def}]: `);
|
|
3069
|
+
if (this.parseYesNo(a, cmd.recommended)) {
|
|
3070
|
+
blocked.push(cmd.pattern);
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
return blocked;
|
|
3074
|
+
}
|
|
3075
|
+
return DEFAULT_BLOCKED_COMMANDS.filter((c) => c.recommended).map((c) => c.pattern);
|
|
3076
|
+
}
|
|
3077
|
+
async askBlockedPaths() {
|
|
3078
|
+
const blocked = [];
|
|
3079
|
+
for (const p of DEFAULT_BLOCKED_PATHS) {
|
|
3080
|
+
this.print(` [x] ${p.label}`);
|
|
3081
|
+
}
|
|
3082
|
+
const answer = await this.ask("\n Accept recommended defaults? (y)es / (n)o / (c)ustomize [default: y]: ");
|
|
3083
|
+
const choice = answer.trim().toLowerCase();
|
|
3084
|
+
if (choice === "n" || choice === "no") {
|
|
3085
|
+
return [];
|
|
3086
|
+
}
|
|
3087
|
+
if (choice === "c" || choice === "customize") {
|
|
3088
|
+
for (const p of DEFAULT_BLOCKED_PATHS) {
|
|
3089
|
+
const def = p.recommended ? "y" : "n";
|
|
3090
|
+
const a = await this.ask(` Block ${p.pattern}? [default: ${def}]: `);
|
|
3091
|
+
if (this.parseYesNo(a, p.recommended)) {
|
|
3092
|
+
blocked.push(p.pattern);
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
return blocked;
|
|
3096
|
+
}
|
|
3097
|
+
return DEFAULT_BLOCKED_PATHS.filter((p) => p.recommended).map((p) => p.pattern);
|
|
3098
|
+
}
|
|
3099
|
+
async askRiskPreset() {
|
|
3100
|
+
for (let i = 0; i < RISK_PRESETS.length; i++) {
|
|
3101
|
+
this.print(` ${i + 1}. ${RISK_PRESETS[i].label}`);
|
|
3102
|
+
}
|
|
3103
|
+
const answer = await this.ask("\n Choose (1-3) [default: 2]: ");
|
|
3104
|
+
const choice = parseInt(answer.trim(), 10);
|
|
3105
|
+
if (choice >= 1 && choice <= 3) {
|
|
3106
|
+
return RISK_PRESETS[choice - 1].thresholds;
|
|
3107
|
+
}
|
|
3108
|
+
return RISK_PRESETS[1].thresholds;
|
|
3109
|
+
}
|
|
3110
|
+
async askCommaSeparated(prompt) {
|
|
3111
|
+
const answer = await this.ask(` ${prompt}`);
|
|
3112
|
+
if (!answer.trim()) return [];
|
|
3113
|
+
return answer.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
3114
|
+
}
|
|
3115
|
+
// =====================================================================
|
|
3116
|
+
// Utilities
|
|
3117
|
+
// =====================================================================
|
|
3118
|
+
parseYesNoApproval(answer, defaultValue) {
|
|
3119
|
+
const a = answer.trim().toLowerCase();
|
|
3120
|
+
if (!a) return defaultValue;
|
|
3121
|
+
if (a === "y" || a === "yes") return "yes";
|
|
3122
|
+
if (a === "n" || a === "no") return "no";
|
|
3123
|
+
if (a === "a" || a === "ask" || a === "approval") return "approval";
|
|
3124
|
+
return defaultValue;
|
|
3125
|
+
}
|
|
3126
|
+
parseYesNo(answer, defaultValue) {
|
|
3127
|
+
const a = answer.trim().toLowerCase();
|
|
3128
|
+
if (!a) return defaultValue;
|
|
3129
|
+
return a === "y" || a === "yes";
|
|
3130
|
+
}
|
|
3131
|
+
async ask(prompt) {
|
|
3132
|
+
return this.prompt.question(prompt);
|
|
3133
|
+
}
|
|
3134
|
+
print(text) {
|
|
3135
|
+
console.log(text);
|
|
3136
|
+
}
|
|
3137
|
+
};
|
|
3138
|
+
function importFromCursorRules(content) {
|
|
3139
|
+
const purposes = [];
|
|
3140
|
+
const blockedPatterns = [];
|
|
3141
|
+
const blockedResources = [];
|
|
3142
|
+
const lines = content.split("\n").filter((l) => l.trim());
|
|
3143
|
+
for (const line of lines) {
|
|
3144
|
+
const lower = line.toLowerCase().trim();
|
|
3145
|
+
if (lower.includes("block") || lower.includes("deny") || lower.includes("never") || lower.includes("forbidden")) {
|
|
3146
|
+
const quoted = line.match(/"([^"]+)"|'([^']+)'/g);
|
|
3147
|
+
if (quoted) {
|
|
3148
|
+
for (const q of quoted) {
|
|
3149
|
+
const pattern = q.replace(/['"]/g, "");
|
|
3150
|
+
if (lower.includes("shell") || lower.includes("command") || lower.includes("exec")) {
|
|
3151
|
+
blockedPatterns.push(pattern);
|
|
3152
|
+
} else if (lower.includes("file") || lower.includes("path") || lower.includes("directory")) {
|
|
3153
|
+
blockedResources.push(pattern);
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
if (blockedPatterns.length > 0) {
|
|
3160
|
+
purposes.push({ id: "shell.exec", allowed: true, blockedPatterns });
|
|
3161
|
+
}
|
|
3162
|
+
const scope = blockedResources.length > 0 ? { blockedResources } : void 0;
|
|
3163
|
+
return {
|
|
3164
|
+
purposes,
|
|
3165
|
+
scope,
|
|
3166
|
+
source: ".cursorrules",
|
|
3167
|
+
rulesImported: blockedPatterns.length + blockedResources.length
|
|
3168
|
+
};
|
|
3169
|
+
}
|
|
3170
|
+
function inferFromGitignore(content) {
|
|
3171
|
+
const sensitiveKeywords = ["secret", "credential", "password", "key", "token", ".env", "private"];
|
|
3172
|
+
const patterns = [];
|
|
3173
|
+
for (const line of content.split("\n")) {
|
|
3174
|
+
const trimmed = line.trim();
|
|
3175
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
3176
|
+
const lower = trimmed.toLowerCase();
|
|
3177
|
+
if (sensitiveKeywords.some((kw) => lower.includes(kw))) {
|
|
3178
|
+
patterns.push(trimmed);
|
|
3179
|
+
}
|
|
3180
|
+
}
|
|
3181
|
+
return patterns;
|
|
3182
|
+
}
|
|
3183
|
+
|
|
3184
|
+
// src/cli/upgrade.ts
|
|
3185
|
+
var UpgradeFlow = class {
|
|
3186
|
+
constructor(config, callbacks, trigger) {
|
|
3187
|
+
this.config = config;
|
|
3188
|
+
this.callbacks = callbacks;
|
|
3189
|
+
this.platformUrl = config.platformUrl || "https://astrasync.ai";
|
|
3190
|
+
this.configDir = config.configDir || ".astrasync";
|
|
3191
|
+
this.trigger = trigger || { reason: "cli" };
|
|
3192
|
+
}
|
|
3193
|
+
/**
|
|
3194
|
+
* Run the full upgrade flow.
|
|
3195
|
+
*/
|
|
3196
|
+
async run() {
|
|
3197
|
+
const { print, prompt } = this.callbacks;
|
|
3198
|
+
this.printIntro();
|
|
3199
|
+
const confirm = await prompt("Continue with upgrade? (y/n) [default: y]: ");
|
|
3200
|
+
if (confirm.trim().toLowerCase() === "n") {
|
|
3201
|
+
return { success: false, error: "Upgrade cancelled by user" };
|
|
3202
|
+
}
|
|
3203
|
+
print("\n[1/5] Create your AstraSync account");
|
|
3204
|
+
const signupUrl = `${this.platformUrl}/signup?source=local-guard&redirect=cli`;
|
|
3205
|
+
print(` Opening ${signupUrl} ...`);
|
|
3206
|
+
try {
|
|
3207
|
+
await this.callbacks.openBrowser(signupUrl);
|
|
3208
|
+
} catch {
|
|
3209
|
+
print(` Could not open browser. Please visit: ${signupUrl}`);
|
|
3210
|
+
}
|
|
3211
|
+
print("\n[2/5] Create your KYD identity");
|
|
3212
|
+
print(" KYD (Know Your Developer) gives your agents a verified developer");
|
|
3213
|
+
print(" identity. Registration takes seconds.\n");
|
|
3214
|
+
const apiKey = await prompt(" Paste your API key from the dashboard: ");
|
|
3215
|
+
if (!apiKey.trim()) {
|
|
3216
|
+
return { success: false, error: "No API key provided" };
|
|
3217
|
+
}
|
|
3218
|
+
print("\n Validating API key...");
|
|
3219
|
+
const validationResult = await this.validateApiKey(apiKey.trim());
|
|
3220
|
+
if (!validationResult.valid) {
|
|
3221
|
+
print(` API key validation failed: ${validationResult.error}`);
|
|
3222
|
+
const retry = await prompt(" Try a different key? (y/n) [default: y]: ");
|
|
3223
|
+
if (retry.trim().toLowerCase() !== "n") {
|
|
3224
|
+
const retryKey = await prompt(" Paste your API key: ");
|
|
3225
|
+
if (!retryKey.trim()) {
|
|
3226
|
+
return { success: false, error: "No API key provided" };
|
|
3227
|
+
}
|
|
3228
|
+
const retryValidation = await this.validateApiKey(retryKey.trim());
|
|
3229
|
+
if (!retryValidation.valid) {
|
|
3230
|
+
return { success: false, error: `API key validation failed: ${retryValidation.error}` };
|
|
3231
|
+
}
|
|
3232
|
+
return this.continueUpgrade(retryKey.trim(), retryValidation.kydId);
|
|
3233
|
+
}
|
|
3234
|
+
return { success: false, error: "API key validation failed" };
|
|
3235
|
+
}
|
|
3236
|
+
print(` API key valid. Developer: ${validationResult.kydId || "confirmed"}`);
|
|
3237
|
+
return this.continueUpgrade(apiKey.trim(), validationResult.kydId);
|
|
3238
|
+
}
|
|
3239
|
+
/**
|
|
3240
|
+
* Continue the upgrade flow after API key validation.
|
|
3241
|
+
*/
|
|
3242
|
+
async continueUpgrade(apiKey, kydId) {
|
|
3243
|
+
const { print, prompt } = this.callbacks;
|
|
3244
|
+
print("\n[3/5] Migrate local policy to cloud");
|
|
3245
|
+
print(` Policy: ${this.config.policyPath}`);
|
|
3246
|
+
print(` Name: ${this.config.policy.name}`);
|
|
3247
|
+
print(` Rules: ${this.config.policy.purposes.length} purpose rules`);
|
|
3248
|
+
if (this.config.policy.scope) {
|
|
3249
|
+
const scope = this.config.policy.scope;
|
|
3250
|
+
const domains = [
|
|
3251
|
+
...(scope.allowedDomains || []).length ? [`${scope.allowedDomains.length} allowed`] : [],
|
|
3252
|
+
...(scope.blockedDomains || []).length ? [`${scope.blockedDomains.length} blocked`] : []
|
|
3253
|
+
];
|
|
3254
|
+
if (domains.length) print(` Scope: ${domains.join(", ")} domains`);
|
|
3255
|
+
}
|
|
3256
|
+
print("");
|
|
3257
|
+
print(" Uploading YAML -> Cloud PDLSS boundary...");
|
|
3258
|
+
const uploadResult = await this.uploadPolicy(apiKey);
|
|
3259
|
+
if (!uploadResult.success) {
|
|
3260
|
+
print(` Upload failed: ${uploadResult.error}`);
|
|
3261
|
+
return uploadResult;
|
|
3262
|
+
}
|
|
3263
|
+
print(" Policy uploaded. Same rules, now with trust scoring and audit.");
|
|
3264
|
+
print(` Agent registered: ${uploadResult.agentId}`);
|
|
3265
|
+
if (kydId) {
|
|
3266
|
+
print(` Developer: ${kydId}`);
|
|
3267
|
+
}
|
|
3268
|
+
print("\n[4/5] Choose verification mode");
|
|
3269
|
+
print(" online \u2014 All evaluation in the cloud. Full features, requires connectivity.");
|
|
3270
|
+
print(" hybrid \u2014 Local evaluation for speed, cloud sync for audit. Works offline.\n");
|
|
3271
|
+
const modeInput = await prompt(" Mode (online/hybrid) [default: hybrid]: ");
|
|
3272
|
+
const mode = modeInput.trim().toLowerCase() === "online" ? "online" : "hybrid";
|
|
3273
|
+
print(`
|
|
3274
|
+
[5/5] Activating ${mode} verification`);
|
|
3275
|
+
await this.writeLocalConfig(apiKey, uploadResult.agentId, mode, kydId);
|
|
3276
|
+
print(` Config written to ${this.configDir}/config`);
|
|
3277
|
+
print(` Mode: ${mode}`);
|
|
3278
|
+
print(" Done!\n");
|
|
3279
|
+
print(` Your agent (${uploadResult.agentId}) is verified on the AstraSync network.`);
|
|
3280
|
+
if (mode === "hybrid") {
|
|
3281
|
+
print(" Local evaluation active for speed. Cloud sync for audit and trust scoring.");
|
|
3282
|
+
} else {
|
|
3283
|
+
print(" Trust scoring, audit trails, and blockchain recording are active.");
|
|
3284
|
+
}
|
|
3285
|
+
print(`
|
|
3286
|
+
Dashboard: ${this.platformUrl}/agents/${uploadResult.agentId}
|
|
3287
|
+
`);
|
|
3288
|
+
return {
|
|
3289
|
+
success: true,
|
|
3290
|
+
apiKey,
|
|
3291
|
+
agentId: uploadResult.agentId,
|
|
3292
|
+
kydId,
|
|
3293
|
+
mode
|
|
3294
|
+
};
|
|
3295
|
+
}
|
|
3296
|
+
/**
|
|
3297
|
+
* Print the intro message based on what triggered the upgrade.
|
|
3298
|
+
*/
|
|
3299
|
+
printIntro() {
|
|
3300
|
+
const { print } = this.callbacks;
|
|
3301
|
+
print("\nUpgrade to AstraSync Developer Tier\n");
|
|
3302
|
+
if (this.trigger.reason === "counterparty-rejection") {
|
|
3303
|
+
const cp = this.trigger.details?.counterpartyUrl || "A service";
|
|
3304
|
+
print(`${cp} requires a verified agent identity to grant access.`);
|
|
3305
|
+
if (this.trigger.details?.rejectionMessage) {
|
|
3306
|
+
print(` "${this.trigger.details.rejectionMessage}"`);
|
|
3307
|
+
}
|
|
3308
|
+
print("");
|
|
3309
|
+
print("Upgrading registers your agent so counterparties can verify it.\n");
|
|
3310
|
+
} else if (this.trigger.reason === "deployment") {
|
|
3311
|
+
print("Deploying your agent requires an ASTRA-ID so counterparties can");
|
|
3312
|
+
print("verify it at runtime.\n");
|
|
3313
|
+
} else if (this.trigger.reason === "git-push") {
|
|
3314
|
+
print("Your git push triggered a policy check. Upgrading gives you cloud");
|
|
3315
|
+
print("audit trails for every evaluation \u2014 locally and in CI.\n");
|
|
3316
|
+
} else {
|
|
3317
|
+
print("You're currently running in local-only mode. Your agent is protected");
|
|
3318
|
+
print("locally but has no identity on the AstraSync network \u2014 counterparties");
|
|
3319
|
+
print("can't verify it.\n");
|
|
3320
|
+
print("Upgrading registers your agent with a trust score so services");
|
|
3321
|
+
print("accept it, plus you get audit trails and blockchain recording.\n");
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
/**
|
|
3325
|
+
* Validate the API key by calling the platform.
|
|
3326
|
+
*/
|
|
3327
|
+
async validateApiKey(apiKey) {
|
|
3328
|
+
try {
|
|
3329
|
+
const response = await fetch(`${this.platformUrl}/api/v1/auth/me`, {
|
|
3330
|
+
headers: { Authorization: `Bearer ${apiKey}` }
|
|
3331
|
+
});
|
|
3332
|
+
if (!response.ok) {
|
|
3333
|
+
if (response.status === 401) {
|
|
3334
|
+
return { valid: false, error: "Invalid or expired API key" };
|
|
3335
|
+
}
|
|
3336
|
+
return { valid: false, error: `Unexpected response (${response.status})` };
|
|
3337
|
+
}
|
|
3338
|
+
const data = await response.json();
|
|
3339
|
+
return { valid: true, kydId: data.kydId || data.userId };
|
|
3340
|
+
} catch (err) {
|
|
3341
|
+
return { valid: true, error: `Could not reach platform (proceeding anyway)` };
|
|
3342
|
+
}
|
|
3343
|
+
}
|
|
3344
|
+
/**
|
|
3345
|
+
* Upload local policy to the AstraSync cloud.
|
|
3346
|
+
* YAML -> cloud PDLSS boundary, 1:1 mapping, no lossy transformation.
|
|
3347
|
+
*/
|
|
3348
|
+
async uploadPolicy(apiKey) {
|
|
3349
|
+
const policyYaml = toYaml(this.config.policy);
|
|
3350
|
+
try {
|
|
3351
|
+
const response = await fetch(`${this.platformUrl}/api/v1/agents/policies/upload`, {
|
|
3352
|
+
method: "POST",
|
|
3353
|
+
headers: {
|
|
3354
|
+
"Content-Type": "application/json",
|
|
3355
|
+
Authorization: `Bearer ${apiKey}`
|
|
3356
|
+
},
|
|
3357
|
+
body: JSON.stringify({
|
|
3358
|
+
policy: policyYaml,
|
|
3359
|
+
policyObject: this.config.policy,
|
|
3360
|
+
format: "yaml",
|
|
3361
|
+
source: "local-guard-upgrade",
|
|
3362
|
+
name: this.config.policy.name
|
|
3363
|
+
})
|
|
3364
|
+
});
|
|
3365
|
+
if (!response.ok) {
|
|
3366
|
+
const body = await response.text();
|
|
3367
|
+
return { success: false, error: `Upload failed (${response.status}): ${body}` };
|
|
3368
|
+
}
|
|
3369
|
+
const data = await response.json();
|
|
3370
|
+
return {
|
|
3371
|
+
success: true,
|
|
3372
|
+
agentId: data.agentId || "ASTRA-PENDING",
|
|
3373
|
+
kydId: data.kydId
|
|
3374
|
+
};
|
|
3375
|
+
} catch (err) {
|
|
3376
|
+
return {
|
|
3377
|
+
success: false,
|
|
3378
|
+
error: `Network error: ${err instanceof Error ? err.message : String(err)}`
|
|
3379
|
+
};
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
/**
|
|
3383
|
+
* Write the config file for the chosen mode.
|
|
3384
|
+
*/
|
|
3385
|
+
async writeLocalConfig(apiKey, agentId, mode, kydId) {
|
|
3386
|
+
const config = JSON.stringify(
|
|
3387
|
+
{
|
|
3388
|
+
mode,
|
|
3389
|
+
apiKey,
|
|
3390
|
+
agentId,
|
|
3391
|
+
kydId,
|
|
3392
|
+
platformUrl: this.platformUrl,
|
|
3393
|
+
upgradedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3394
|
+
previousMode: "local",
|
|
3395
|
+
policyFile: this.config.policyPath
|
|
3396
|
+
},
|
|
3397
|
+
null,
|
|
3398
|
+
2
|
|
3399
|
+
);
|
|
3400
|
+
await this.callbacks.writeConfig(`${this.configDir}/config`, config);
|
|
3401
|
+
}
|
|
3402
|
+
};
|
|
3403
|
+
async function isUpgraded(configDir, readFile) {
|
|
3404
|
+
try {
|
|
3405
|
+
const content = await readFile(`${configDir}/config`);
|
|
3406
|
+
if (!content) return false;
|
|
3407
|
+
const config = JSON.parse(content);
|
|
3408
|
+
return config.mode === "online" || config.mode === "hybrid";
|
|
3409
|
+
} catch {
|
|
3410
|
+
return false;
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
|
|
3414
|
+
// src/adapter-interface/interface.ts
|
|
3415
|
+
var ADAPTER_INTERFACE_VERSION = 1;
|
|
3416
|
+
|
|
3417
|
+
// src/adapter-interface/purpose-mapping.ts
|
|
3418
|
+
var TOOL_PURPOSE_MAP = {
|
|
3419
|
+
// Shell
|
|
3420
|
+
shell_exec: "shell.exec",
|
|
3421
|
+
run_command: "shell.exec",
|
|
3422
|
+
execute: "shell.exec",
|
|
3423
|
+
terminal_exec: "shell.exec",
|
|
3424
|
+
run_terminal_command: "shell.exec",
|
|
3425
|
+
// File read
|
|
3426
|
+
file_read: "file.read",
|
|
3427
|
+
read_file: "file.read",
|
|
3428
|
+
// File write
|
|
3429
|
+
file_write: "file.write",
|
|
3430
|
+
write_file: "file.write",
|
|
3431
|
+
create_file: "file.write",
|
|
3432
|
+
edit_file: "file.write",
|
|
3433
|
+
// File delete
|
|
3434
|
+
file_delete: "file.delete",
|
|
3435
|
+
delete_file: "file.delete",
|
|
3436
|
+
// Network
|
|
3437
|
+
http_request: "network.request",
|
|
3438
|
+
fetch: "network.request",
|
|
3439
|
+
web_request: "network.request",
|
|
3440
|
+
// Email
|
|
3441
|
+
send_email: "email.send",
|
|
3442
|
+
read_email: "email.read",
|
|
3443
|
+
// Calendar
|
|
3444
|
+
create_event: "calendar.create",
|
|
3445
|
+
// Database
|
|
3446
|
+
query_database: "database.query",
|
|
3447
|
+
write_database: "database.write",
|
|
3448
|
+
// Payment
|
|
3449
|
+
payment_execute: "payment.execute"
|
|
3450
|
+
};
|
|
3451
|
+
function mapToolToPurpose(toolName) {
|
|
3452
|
+
return TOOL_PURPOSE_MAP[toolName] || `tool.${toolName}`;
|
|
3453
|
+
}
|
|
3454
|
+
function extractTarget(toolName, args) {
|
|
3455
|
+
const purpose = mapToolToPurpose(toolName);
|
|
3456
|
+
if (purpose.startsWith("shell.")) {
|
|
3457
|
+
return String(args.command || args.cmd || args.script || "");
|
|
3458
|
+
}
|
|
3459
|
+
if (purpose.startsWith("file.")) {
|
|
3460
|
+
return String(args.path || args.file || args.filename || args.file_path || "");
|
|
3461
|
+
}
|
|
3462
|
+
if (purpose.startsWith("network.")) {
|
|
3463
|
+
return String(args.url || args.endpoint || args.uri || "");
|
|
3464
|
+
}
|
|
3465
|
+
if (purpose.startsWith("email.")) {
|
|
3466
|
+
return String(args.to || args.recipient || args.address || "");
|
|
3467
|
+
}
|
|
3468
|
+
if (purpose.startsWith("database.")) {
|
|
3469
|
+
return String(args.query || args.table || "");
|
|
3470
|
+
}
|
|
3471
|
+
if (purpose.startsWith("payment.")) {
|
|
3472
|
+
return String(args.description || args.merchant || args.amount || "");
|
|
3473
|
+
}
|
|
3474
|
+
if (args.command) return String(args.command);
|
|
3475
|
+
if (args.path) return String(args.path);
|
|
3476
|
+
if (args.url) return String(args.url);
|
|
3477
|
+
for (const val of Object.values(args)) {
|
|
3478
|
+
if (typeof val === "string" && val.length > 0) return val;
|
|
3479
|
+
}
|
|
3480
|
+
return toolName;
|
|
3481
|
+
}
|
|
3482
|
+
function extractNetworkDomains(target) {
|
|
3483
|
+
try {
|
|
3484
|
+
if (target.startsWith("http://") || target.startsWith("https://")) {
|
|
3485
|
+
const url = new URL(target);
|
|
3486
|
+
return [url.hostname];
|
|
3487
|
+
}
|
|
3488
|
+
} catch {
|
|
3489
|
+
}
|
|
3490
|
+
return void 0;
|
|
3491
|
+
}
|
|
3492
|
+
|
|
3493
|
+
// src/cli/openclaw-adapter.ts
|
|
3494
|
+
import * as http from "http";
|
|
3495
|
+
var OpenClawCliAdapter = class {
|
|
3496
|
+
constructor(options) {
|
|
3497
|
+
this.interfaceVersion = ADAPTER_INTERFACE_VERSION;
|
|
3498
|
+
this.server = null;
|
|
3499
|
+
this._isRunning = false;
|
|
3500
|
+
this.options = {
|
|
3501
|
+
proxyPort: options?.proxyPort ?? 18790,
|
|
3502
|
+
targetPort: options?.targetPort ?? 18789,
|
|
3503
|
+
targetHost: options?.targetHost ?? "127.0.0.1",
|
|
3504
|
+
interactiveApproval: options?.interactiveApproval ?? true,
|
|
3505
|
+
onApprovalRequired: options?.onApprovalRequired ?? (async () => false)
|
|
3506
|
+
};
|
|
3507
|
+
}
|
|
3508
|
+
get isRunning() {
|
|
3509
|
+
return this._isRunning;
|
|
3510
|
+
}
|
|
3511
|
+
get proxyPort() {
|
|
3512
|
+
return this.options.proxyPort;
|
|
3513
|
+
}
|
|
3514
|
+
get targetPort() {
|
|
3515
|
+
return this.options.targetPort;
|
|
3516
|
+
}
|
|
3517
|
+
async initialize(config) {
|
|
3518
|
+
this.gateway = config.gateway;
|
|
3519
|
+
if (config.adapterOptions.proxyPort) {
|
|
3520
|
+
this.options.proxyPort = config.adapterOptions.proxyPort;
|
|
3521
|
+
}
|
|
3522
|
+
if (config.adapterOptions.targetPort) {
|
|
3523
|
+
this.options.targetPort = config.adapterOptions.targetPort;
|
|
3524
|
+
}
|
|
3525
|
+
await this.startProxy();
|
|
3526
|
+
}
|
|
3527
|
+
async shutdown() {
|
|
3528
|
+
if (this.server) {
|
|
3529
|
+
await new Promise((resolve) => {
|
|
3530
|
+
this.server.close(() => resolve());
|
|
3531
|
+
});
|
|
3532
|
+
this.server = null;
|
|
3533
|
+
this._isRunning = false;
|
|
3534
|
+
}
|
|
3535
|
+
}
|
|
3536
|
+
async interceptAction(action) {
|
|
3537
|
+
const raw = action.raw;
|
|
3538
|
+
const toolName = raw.tool || raw.name || "";
|
|
3539
|
+
if (!toolName) {
|
|
3540
|
+
return { intercepted: false, skipReason: "No tool name in request" };
|
|
3541
|
+
}
|
|
3542
|
+
const context = this.extractContext(action);
|
|
3543
|
+
return { intercepted: true, context };
|
|
3544
|
+
}
|
|
3545
|
+
extractContext(action) {
|
|
3546
|
+
const raw = action.raw;
|
|
3547
|
+
const toolName = raw.tool || raw.name || "unknown";
|
|
3548
|
+
const args = raw.args || raw.arguments || raw.params || {};
|
|
3549
|
+
const purpose = mapToolToPurpose(toolName);
|
|
3550
|
+
const target = extractTarget(toolName, args);
|
|
3551
|
+
const networkAccess = extractNetworkDomains(target);
|
|
3552
|
+
return {
|
|
3553
|
+
purpose,
|
|
3554
|
+
action: toolName,
|
|
3555
|
+
target,
|
|
3556
|
+
...networkAccess && { networkAccess }
|
|
3557
|
+
};
|
|
3558
|
+
}
|
|
3559
|
+
async enforceDecision(decision) {
|
|
3560
|
+
if (decision.recommendation === "DENY") {
|
|
3561
|
+
return;
|
|
3562
|
+
}
|
|
3563
|
+
if (decision.recommendation === "MANUAL_REVIEW") {
|
|
3564
|
+
return;
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
// =====================================================================
|
|
3568
|
+
// Proxy server
|
|
3569
|
+
// =====================================================================
|
|
3570
|
+
async startProxy() {
|
|
3571
|
+
return new Promise((resolve, reject) => {
|
|
3572
|
+
this.server = http.createServer(async (req, res) => {
|
|
3573
|
+
await this.handleProxyRequest(req, res);
|
|
3574
|
+
});
|
|
3575
|
+
this.server.on("error", (err) => {
|
|
3576
|
+
this._isRunning = false;
|
|
3577
|
+
reject(err);
|
|
3578
|
+
});
|
|
3579
|
+
this.server.listen(this.options.proxyPort, "127.0.0.1", () => {
|
|
3580
|
+
this._isRunning = true;
|
|
3581
|
+
resolve();
|
|
3582
|
+
});
|
|
3583
|
+
});
|
|
3584
|
+
}
|
|
3585
|
+
async handleProxyRequest(req, res) {
|
|
3586
|
+
const chunks = [];
|
|
3587
|
+
for await (const chunk of req) {
|
|
3588
|
+
chunks.push(chunk);
|
|
3589
|
+
}
|
|
3590
|
+
const bodyStr = Buffer.concat(chunks).toString("utf-8");
|
|
3591
|
+
let toolCall = null;
|
|
3592
|
+
try {
|
|
3593
|
+
if (bodyStr) {
|
|
3594
|
+
toolCall = JSON.parse(bodyStr);
|
|
3595
|
+
}
|
|
3596
|
+
} catch {
|
|
3597
|
+
}
|
|
3598
|
+
if (toolCall && (toolCall.tool || toolCall.name)) {
|
|
3599
|
+
const action = {
|
|
3600
|
+
raw: toolCall,
|
|
3601
|
+
platform: "openclaw-cli",
|
|
3602
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
3603
|
+
};
|
|
3604
|
+
const interception = await this.interceptAction(action);
|
|
3605
|
+
if (interception.intercepted && interception.context) {
|
|
3606
|
+
const decision = await this.gateway.evaluate(interception.context);
|
|
3607
|
+
if (decision.recommendation === "DENY") {
|
|
3608
|
+
res.writeHead(403, { "Content-Type": "application/json" });
|
|
3609
|
+
res.end(
|
|
3610
|
+
JSON.stringify({
|
|
3611
|
+
error: "Action blocked by AstraSync Local Guard",
|
|
3612
|
+
reason: decision.reason,
|
|
3613
|
+
recommendation: decision.recommendation
|
|
3614
|
+
})
|
|
3615
|
+
);
|
|
3616
|
+
return;
|
|
3617
|
+
}
|
|
3618
|
+
if (decision.recommendation === "MANUAL_REVIEW") {
|
|
3619
|
+
const approved = await this.handleApproval(interception.context, decision);
|
|
3620
|
+
if (!approved) {
|
|
3621
|
+
res.writeHead(403, { "Content-Type": "application/json" });
|
|
3622
|
+
res.end(
|
|
3623
|
+
JSON.stringify({
|
|
3624
|
+
error: "Action denied after manual review",
|
|
3625
|
+
reason: decision.reason,
|
|
3626
|
+
recommendation: "DENY"
|
|
3627
|
+
})
|
|
3628
|
+
);
|
|
3629
|
+
return;
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
this.forwardRequest(req, bodyStr, res);
|
|
3635
|
+
}
|
|
3636
|
+
forwardRequest(originalReq, body, clientRes) {
|
|
3637
|
+
const proxyReq = http.request(
|
|
3638
|
+
{
|
|
3639
|
+
hostname: this.options.targetHost,
|
|
3640
|
+
port: this.options.targetPort,
|
|
3641
|
+
path: originalReq.url,
|
|
3642
|
+
method: originalReq.method,
|
|
3643
|
+
headers: { ...originalReq.headers, host: `${this.options.targetHost}:${this.options.targetPort}` }
|
|
3644
|
+
},
|
|
3645
|
+
(proxyRes) => {
|
|
3646
|
+
clientRes.writeHead(proxyRes.statusCode || 500, proxyRes.headers);
|
|
3647
|
+
proxyRes.pipe(clientRes);
|
|
3648
|
+
}
|
|
3649
|
+
);
|
|
3650
|
+
proxyReq.on("error", (err) => {
|
|
3651
|
+
clientRes.writeHead(502, { "Content-Type": "application/json" });
|
|
3652
|
+
clientRes.end(
|
|
3653
|
+
JSON.stringify({
|
|
3654
|
+
error: "Could not reach OpenClaw gateway",
|
|
3655
|
+
detail: err.message
|
|
3656
|
+
})
|
|
3657
|
+
);
|
|
3658
|
+
});
|
|
3659
|
+
if (body) {
|
|
3660
|
+
proxyReq.write(body);
|
|
3661
|
+
}
|
|
3662
|
+
proxyReq.end();
|
|
3663
|
+
}
|
|
3664
|
+
async handleApproval(context, decision) {
|
|
3665
|
+
if (this.options.onApprovalRequired) {
|
|
3666
|
+
return this.options.onApprovalRequired(context, decision);
|
|
3667
|
+
}
|
|
3668
|
+
return false;
|
|
3669
|
+
}
|
|
3670
|
+
};
|
|
3671
|
+
export {
|
|
3672
|
+
DEFAULT_BLOCKED_COMMANDS,
|
|
3673
|
+
DEFAULT_BLOCKED_PATHS,
|
|
3674
|
+
OpenClawCliAdapter,
|
|
3675
|
+
PURPOSE_CATEGORIES,
|
|
3676
|
+
RISK_PRESETS,
|
|
3677
|
+
SetupWizard,
|
|
3678
|
+
UpgradeFlow,
|
|
3679
|
+
importFromCursorRules,
|
|
3680
|
+
inferFromGitignore,
|
|
3681
|
+
isUpgraded
|
|
3682
|
+
};
|
|
3683
|
+
/*! Bundled license information:
|
|
3684
|
+
|
|
3685
|
+
js-yaml/dist/js-yaml.mjs:
|
|
3686
|
+
(*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT *)
|
|
3687
|
+
*/
|
|
3688
|
+
//# sourceMappingURL=index.mjs.map
|