@deeplake/hivemind 0.6.47 → 0.6.48
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +11 -31
- package/bundle/cli.js +3597 -233
- package/codex/bundle/capture.js +1 -1
- package/codex/bundle/commands/auth-login.js +10 -6
- package/codex/bundle/pre-tool-use.js +84 -4
- package/codex/bundle/session-start-setup.js +15 -1
- package/codex/bundle/session-start.js +15 -1
- package/codex/bundle/stop.js +1 -1
- package/cursor/bundle/commands/auth-login.js +10 -6
- package/cursor/bundle/pre-tool-use.js +1193 -0
- package/cursor/bundle/session-start.js +17 -3
- package/hermes/bundle/capture.js +481 -0
- package/hermes/bundle/commands/auth-login.js +866 -0
- package/hermes/bundle/package.json +1 -0
- package/hermes/bundle/pre-tool-use.js +1190 -0
- package/hermes/bundle/session-end.js +42 -0
- package/hermes/bundle/session-start.js +514 -0
- package/hermes/bundle/shell/deeplake-shell.js +69338 -0
- package/mcp/bundle/server.js +37 -2
- package/openclaw/dist/index.js +1 -1
- package/openclaw/openclaw.plugin.json +1 -1
- package/openclaw/package.json +1 -1
- package/package.json +6 -3
- package/pi/extension-source/hivemind.ts +355 -0
package/bundle/cli.js
CHANGED
|
@@ -55,14 +55,10 @@ var PLATFORM_MARKERS = [
|
|
|
55
55
|
{ id: "claw", markerDir: join(HOME, ".openclaw") },
|
|
56
56
|
{ id: "cursor", markerDir: join(HOME, ".cursor") },
|
|
57
57
|
{ id: "hermes", markerDir: join(HOME, ".hermes") },
|
|
58
|
-
// pi (badlogic/pi-mono coding-agent) — config at ~/.pi/agent
|
|
59
|
-
|
|
60
|
-
//
|
|
61
|
-
{ id: "
|
|
62
|
-
// Roo Code (rooveterinaryinc.roo-cline VS Code extension)
|
|
63
|
-
{ id: "roo", markerDir: join(HOME, ".config", "Code", "User", "globalStorage", "rooveterinaryinc.roo-cline") },
|
|
64
|
-
// Kilo Code — config at ~/.kilocode/
|
|
65
|
-
{ id: "kilo", markerDir: join(HOME, ".kilocode") }
|
|
58
|
+
// pi (badlogic/pi-mono coding-agent) — config at ~/.pi/agent/. pi exposes
|
|
59
|
+
// a rich extension event API (session_start / input / tool_call /
|
|
60
|
+
// tool_result / message_end / session_shutdown / etc.) — Tier 1 capable.
|
|
61
|
+
{ id: "pi", markerDir: join(HOME, ".pi") }
|
|
66
62
|
];
|
|
67
63
|
function detectPlatforms() {
|
|
68
64
|
return PLATFORM_MARKERS.filter((p) => existsSync(p.markerDir));
|
|
@@ -146,7 +142,7 @@ function uninstallClaude() {
|
|
|
146
142
|
}
|
|
147
143
|
|
|
148
144
|
// dist/src/cli/install-codex.js
|
|
149
|
-
import { existsSync as existsSync2, unlinkSync as unlinkSync2 } from "node:fs";
|
|
145
|
+
import { existsSync as existsSync2, readFileSync as readFileSync3, unlinkSync as unlinkSync2 } from "node:fs";
|
|
150
146
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
151
147
|
import { join as join3 } from "node:path";
|
|
152
148
|
|
|
@@ -191,6 +187,42 @@ function buildHooksJson() {
|
|
|
191
187
|
}
|
|
192
188
|
};
|
|
193
189
|
}
|
|
190
|
+
function isHivemindHookEntry(entry) {
|
|
191
|
+
if (!entry || typeof entry !== "object")
|
|
192
|
+
return false;
|
|
193
|
+
const e = entry;
|
|
194
|
+
const hooks = Array.isArray(e.hooks) ? e.hooks : [];
|
|
195
|
+
return hooks.some((h) => {
|
|
196
|
+
if (!h || typeof h !== "object")
|
|
197
|
+
return false;
|
|
198
|
+
const cmd = h.command;
|
|
199
|
+
return typeof cmd === "string" && cmd.includes(`${PLUGIN_DIR}/bundle/`);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function mergeHooksJson(ours) {
|
|
203
|
+
let existing = {};
|
|
204
|
+
try {
|
|
205
|
+
if (existsSync2(HOOKS_PATH)) {
|
|
206
|
+
const parsed = JSON.parse(readFileSync3(HOOKS_PATH, "utf-8"));
|
|
207
|
+
if (parsed && typeof parsed === "object")
|
|
208
|
+
existing = parsed;
|
|
209
|
+
}
|
|
210
|
+
} catch {
|
|
211
|
+
warn(` Codex ${HOOKS_PATH} unparseable \u2014 ignoring prior content`);
|
|
212
|
+
}
|
|
213
|
+
const existingHooks = existing.hooks && typeof existing.hooks === "object" ? existing.hooks : {};
|
|
214
|
+
const ourHooks = ours.hooks;
|
|
215
|
+
const merged = {};
|
|
216
|
+
for (const [event, entries] of Object.entries(existingHooks)) {
|
|
217
|
+
const surviving = (entries ?? []).filter((e) => !isHivemindHookEntry(e));
|
|
218
|
+
if (surviving.length)
|
|
219
|
+
merged[event] = surviving;
|
|
220
|
+
}
|
|
221
|
+
for (const [event, entries] of Object.entries(ourHooks)) {
|
|
222
|
+
merged[event] = [...merged[event] ?? [], ...entries ?? []];
|
|
223
|
+
}
|
|
224
|
+
return { ...existing, hooks: merged };
|
|
225
|
+
}
|
|
194
226
|
function tryEnableCodexHooks() {
|
|
195
227
|
try {
|
|
196
228
|
execFileSync2("codex", ["features", "enable", "codex_hooks"], { stdio: "ignore" });
|
|
@@ -208,7 +240,7 @@ function installCodex() {
|
|
|
208
240
|
if (existsSync2(srcSkills))
|
|
209
241
|
copyDir(srcSkills, join3(PLUGIN_DIR, "skills"));
|
|
210
242
|
tryEnableCodexHooks();
|
|
211
|
-
writeJson(HOOKS_PATH, buildHooksJson());
|
|
243
|
+
writeJson(HOOKS_PATH, mergeHooksJson(buildHooksJson()));
|
|
212
244
|
ensureDir(AGENTS_SKILLS_DIR);
|
|
213
245
|
const skillTarget = join3(PLUGIN_DIR, "skills", "deeplake-memory");
|
|
214
246
|
if (existsSync2(skillTarget)) {
|
|
@@ -232,7 +264,7 @@ function uninstallCodex() {
|
|
|
232
264
|
}
|
|
233
265
|
|
|
234
266
|
// dist/src/cli/install-openclaw.js
|
|
235
|
-
import { existsSync as existsSync3, rmSync } from "node:fs";
|
|
267
|
+
import { existsSync as existsSync3, copyFileSync, rmSync } from "node:fs";
|
|
236
268
|
import { join as join4 } from "node:path";
|
|
237
269
|
var PLUGIN_DIR2 = join4(HOME, ".openclaw", "extensions", "hivemind");
|
|
238
270
|
function installOpenclaw() {
|
|
@@ -246,9 +278,9 @@ function installOpenclaw() {
|
|
|
246
278
|
ensureDir(PLUGIN_DIR2);
|
|
247
279
|
copyDir(srcDist, join4(PLUGIN_DIR2, "dist"));
|
|
248
280
|
if (existsSync3(srcManifest))
|
|
249
|
-
|
|
281
|
+
copyFileSync(srcManifest, join4(PLUGIN_DIR2, "openclaw.plugin.json"));
|
|
250
282
|
if (existsSync3(srcPkg))
|
|
251
|
-
|
|
283
|
+
copyFileSync(srcPkg, join4(PLUGIN_DIR2, "package.json"));
|
|
252
284
|
if (existsSync3(srcSkills))
|
|
253
285
|
copyDir(srcSkills, join4(PLUGIN_DIR2, "skills"));
|
|
254
286
|
writeVersionStamp(PLUGIN_DIR2, getVersion());
|
|
@@ -277,10 +309,21 @@ function buildHookCmd(bundleFile, timeout) {
|
|
|
277
309
|
timeout
|
|
278
310
|
};
|
|
279
311
|
}
|
|
312
|
+
function buildHookCmdShellMatcher(bundleFile, timeout) {
|
|
313
|
+
return {
|
|
314
|
+
type: "command",
|
|
315
|
+
command: `node "${join5(PLUGIN_DIR3, "bundle", bundleFile)}"`,
|
|
316
|
+
timeout,
|
|
317
|
+
matcher: "Shell"
|
|
318
|
+
};
|
|
319
|
+
}
|
|
280
320
|
function buildHookConfig() {
|
|
281
321
|
return {
|
|
282
322
|
sessionStart: [buildHookCmd("session-start.js", 30)],
|
|
283
323
|
beforeSubmitPrompt: [buildHookCmd("capture.js", 10)],
|
|
324
|
+
// preToolUse with Shell matcher rewrites grep/rg against ~/.deeplake/memory/
|
|
325
|
+
// into a single SQL fast-path call, matching Claude Code / Codex accuracy.
|
|
326
|
+
preToolUse: [buildHookCmdShellMatcher("pre-tool-use.js", 30)],
|
|
284
327
|
postToolUse: [buildHookCmd("capture.js", 15)],
|
|
285
328
|
afterAgentResponse: [buildHookCmd("capture.js", 15)],
|
|
286
329
|
stop: [buildHookCmd("capture.js", 15)],
|
|
@@ -344,7 +387,8 @@ function uninstallCursor() {
|
|
|
344
387
|
return;
|
|
345
388
|
}
|
|
346
389
|
const stripped = stripHooksFromConfig(existing);
|
|
347
|
-
|
|
390
|
+
const meaningfulKeys = stripped ? Object.keys(stripped).filter((k) => k !== "version").length : 0;
|
|
391
|
+
if (!stripped || meaningfulKeys === 0) {
|
|
348
392
|
if (existsSync4(HOOKS_PATH2))
|
|
349
393
|
unlinkSync3(HOOKS_PATH2);
|
|
350
394
|
} else {
|
|
@@ -354,10 +398,2620 @@ function uninstallCursor() {
|
|
|
354
398
|
}
|
|
355
399
|
|
|
356
400
|
// dist/src/cli/install-hermes.js
|
|
357
|
-
import { existsSync as
|
|
401
|
+
import { existsSync as existsSync6, writeFileSync as writeFileSync2, readFileSync as readFileSync4, rmSync as rmSync2, unlinkSync as unlinkSync4 } from "node:fs";
|
|
402
|
+
import { join as join7 } from "node:path";
|
|
403
|
+
|
|
404
|
+
// node_modules/js-yaml/dist/js-yaml.mjs
|
|
405
|
+
function isNothing(subject) {
|
|
406
|
+
return typeof subject === "undefined" || subject === null;
|
|
407
|
+
}
|
|
408
|
+
function isObject(subject) {
|
|
409
|
+
return typeof subject === "object" && subject !== null;
|
|
410
|
+
}
|
|
411
|
+
function toArray(sequence) {
|
|
412
|
+
if (Array.isArray(sequence)) return sequence;
|
|
413
|
+
else if (isNothing(sequence)) return [];
|
|
414
|
+
return [sequence];
|
|
415
|
+
}
|
|
416
|
+
function extend(target, source) {
|
|
417
|
+
var index, length, key, sourceKeys;
|
|
418
|
+
if (source) {
|
|
419
|
+
sourceKeys = Object.keys(source);
|
|
420
|
+
for (index = 0, length = sourceKeys.length; index < length; index += 1) {
|
|
421
|
+
key = sourceKeys[index];
|
|
422
|
+
target[key] = source[key];
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return target;
|
|
426
|
+
}
|
|
427
|
+
function repeat(string, count) {
|
|
428
|
+
var result = "", cycle;
|
|
429
|
+
for (cycle = 0; cycle < count; cycle += 1) {
|
|
430
|
+
result += string;
|
|
431
|
+
}
|
|
432
|
+
return result;
|
|
433
|
+
}
|
|
434
|
+
function isNegativeZero(number) {
|
|
435
|
+
return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
|
|
436
|
+
}
|
|
437
|
+
var isNothing_1 = isNothing;
|
|
438
|
+
var isObject_1 = isObject;
|
|
439
|
+
var toArray_1 = toArray;
|
|
440
|
+
var repeat_1 = repeat;
|
|
441
|
+
var isNegativeZero_1 = isNegativeZero;
|
|
442
|
+
var extend_1 = extend;
|
|
443
|
+
var common = {
|
|
444
|
+
isNothing: isNothing_1,
|
|
445
|
+
isObject: isObject_1,
|
|
446
|
+
toArray: toArray_1,
|
|
447
|
+
repeat: repeat_1,
|
|
448
|
+
isNegativeZero: isNegativeZero_1,
|
|
449
|
+
extend: extend_1
|
|
450
|
+
};
|
|
451
|
+
function formatError(exception2, compact) {
|
|
452
|
+
var where = "", message = exception2.reason || "(unknown reason)";
|
|
453
|
+
if (!exception2.mark) return message;
|
|
454
|
+
if (exception2.mark.name) {
|
|
455
|
+
where += 'in "' + exception2.mark.name + '" ';
|
|
456
|
+
}
|
|
457
|
+
where += "(" + (exception2.mark.line + 1) + ":" + (exception2.mark.column + 1) + ")";
|
|
458
|
+
if (!compact && exception2.mark.snippet) {
|
|
459
|
+
where += "\n\n" + exception2.mark.snippet;
|
|
460
|
+
}
|
|
461
|
+
return message + " " + where;
|
|
462
|
+
}
|
|
463
|
+
function YAMLException$1(reason, mark) {
|
|
464
|
+
Error.call(this);
|
|
465
|
+
this.name = "YAMLException";
|
|
466
|
+
this.reason = reason;
|
|
467
|
+
this.mark = mark;
|
|
468
|
+
this.message = formatError(this, false);
|
|
469
|
+
if (Error.captureStackTrace) {
|
|
470
|
+
Error.captureStackTrace(this, this.constructor);
|
|
471
|
+
} else {
|
|
472
|
+
this.stack = new Error().stack || "";
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
YAMLException$1.prototype = Object.create(Error.prototype);
|
|
476
|
+
YAMLException$1.prototype.constructor = YAMLException$1;
|
|
477
|
+
YAMLException$1.prototype.toString = function toString(compact) {
|
|
478
|
+
return this.name + ": " + formatError(this, compact);
|
|
479
|
+
};
|
|
480
|
+
var exception = YAMLException$1;
|
|
481
|
+
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
|
|
482
|
+
var head = "";
|
|
483
|
+
var tail = "";
|
|
484
|
+
var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
|
|
485
|
+
if (position - lineStart > maxHalfLength) {
|
|
486
|
+
head = " ... ";
|
|
487
|
+
lineStart = position - maxHalfLength + head.length;
|
|
488
|
+
}
|
|
489
|
+
if (lineEnd - position > maxHalfLength) {
|
|
490
|
+
tail = " ...";
|
|
491
|
+
lineEnd = position + maxHalfLength - tail.length;
|
|
492
|
+
}
|
|
493
|
+
return {
|
|
494
|
+
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "\u2192") + tail,
|
|
495
|
+
pos: position - lineStart + head.length
|
|
496
|
+
// relative position
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
function padStart(string, max) {
|
|
500
|
+
return common.repeat(" ", max - string.length) + string;
|
|
501
|
+
}
|
|
502
|
+
function makeSnippet(mark, options) {
|
|
503
|
+
options = Object.create(options || null);
|
|
504
|
+
if (!mark.buffer) return null;
|
|
505
|
+
if (!options.maxLength) options.maxLength = 79;
|
|
506
|
+
if (typeof options.indent !== "number") options.indent = 1;
|
|
507
|
+
if (typeof options.linesBefore !== "number") options.linesBefore = 3;
|
|
508
|
+
if (typeof options.linesAfter !== "number") options.linesAfter = 2;
|
|
509
|
+
var re = /\r?\n|\r|\0/g;
|
|
510
|
+
var lineStarts = [0];
|
|
511
|
+
var lineEnds = [];
|
|
512
|
+
var match;
|
|
513
|
+
var foundLineNo = -1;
|
|
514
|
+
while (match = re.exec(mark.buffer)) {
|
|
515
|
+
lineEnds.push(match.index);
|
|
516
|
+
lineStarts.push(match.index + match[0].length);
|
|
517
|
+
if (mark.position <= match.index && foundLineNo < 0) {
|
|
518
|
+
foundLineNo = lineStarts.length - 2;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
|
|
522
|
+
var result = "", i, line;
|
|
523
|
+
var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
|
|
524
|
+
var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
|
|
525
|
+
for (i = 1; i <= options.linesBefore; i++) {
|
|
526
|
+
if (foundLineNo - i < 0) break;
|
|
527
|
+
line = getLine(
|
|
528
|
+
mark.buffer,
|
|
529
|
+
lineStarts[foundLineNo - i],
|
|
530
|
+
lineEnds[foundLineNo - i],
|
|
531
|
+
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
|
|
532
|
+
maxLineLength
|
|
533
|
+
);
|
|
534
|
+
result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + "\n" + result;
|
|
535
|
+
}
|
|
536
|
+
line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
|
|
537
|
+
result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
538
|
+
result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^\n";
|
|
539
|
+
for (i = 1; i <= options.linesAfter; i++) {
|
|
540
|
+
if (foundLineNo + i >= lineEnds.length) break;
|
|
541
|
+
line = getLine(
|
|
542
|
+
mark.buffer,
|
|
543
|
+
lineStarts[foundLineNo + i],
|
|
544
|
+
lineEnds[foundLineNo + i],
|
|
545
|
+
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
|
|
546
|
+
maxLineLength
|
|
547
|
+
);
|
|
548
|
+
result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
549
|
+
}
|
|
550
|
+
return result.replace(/\n$/, "");
|
|
551
|
+
}
|
|
552
|
+
var snippet = makeSnippet;
|
|
553
|
+
var TYPE_CONSTRUCTOR_OPTIONS = [
|
|
554
|
+
"kind",
|
|
555
|
+
"multi",
|
|
556
|
+
"resolve",
|
|
557
|
+
"construct",
|
|
558
|
+
"instanceOf",
|
|
559
|
+
"predicate",
|
|
560
|
+
"represent",
|
|
561
|
+
"representName",
|
|
562
|
+
"defaultStyle",
|
|
563
|
+
"styleAliases"
|
|
564
|
+
];
|
|
565
|
+
var YAML_NODE_KINDS = [
|
|
566
|
+
"scalar",
|
|
567
|
+
"sequence",
|
|
568
|
+
"mapping"
|
|
569
|
+
];
|
|
570
|
+
function compileStyleAliases(map2) {
|
|
571
|
+
var result = {};
|
|
572
|
+
if (map2 !== null) {
|
|
573
|
+
Object.keys(map2).forEach(function(style) {
|
|
574
|
+
map2[style].forEach(function(alias) {
|
|
575
|
+
result[String(alias)] = style;
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
return result;
|
|
580
|
+
}
|
|
581
|
+
function Type$1(tag, options) {
|
|
582
|
+
options = options || {};
|
|
583
|
+
Object.keys(options).forEach(function(name) {
|
|
584
|
+
if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
|
585
|
+
throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
this.options = options;
|
|
589
|
+
this.tag = tag;
|
|
590
|
+
this.kind = options["kind"] || null;
|
|
591
|
+
this.resolve = options["resolve"] || function() {
|
|
592
|
+
return true;
|
|
593
|
+
};
|
|
594
|
+
this.construct = options["construct"] || function(data) {
|
|
595
|
+
return data;
|
|
596
|
+
};
|
|
597
|
+
this.instanceOf = options["instanceOf"] || null;
|
|
598
|
+
this.predicate = options["predicate"] || null;
|
|
599
|
+
this.represent = options["represent"] || null;
|
|
600
|
+
this.representName = options["representName"] || null;
|
|
601
|
+
this.defaultStyle = options["defaultStyle"] || null;
|
|
602
|
+
this.multi = options["multi"] || false;
|
|
603
|
+
this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
|
|
604
|
+
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
|
605
|
+
throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
var type = Type$1;
|
|
609
|
+
function compileList(schema2, name) {
|
|
610
|
+
var result = [];
|
|
611
|
+
schema2[name].forEach(function(currentType) {
|
|
612
|
+
var newIndex = result.length;
|
|
613
|
+
result.forEach(function(previousType, previousIndex) {
|
|
614
|
+
if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
|
|
615
|
+
newIndex = previousIndex;
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
result[newIndex] = currentType;
|
|
619
|
+
});
|
|
620
|
+
return result;
|
|
621
|
+
}
|
|
622
|
+
function compileMap() {
|
|
623
|
+
var result = {
|
|
624
|
+
scalar: {},
|
|
625
|
+
sequence: {},
|
|
626
|
+
mapping: {},
|
|
627
|
+
fallback: {},
|
|
628
|
+
multi: {
|
|
629
|
+
scalar: [],
|
|
630
|
+
sequence: [],
|
|
631
|
+
mapping: [],
|
|
632
|
+
fallback: []
|
|
633
|
+
}
|
|
634
|
+
}, index, length;
|
|
635
|
+
function collectType(type2) {
|
|
636
|
+
if (type2.multi) {
|
|
637
|
+
result.multi[type2.kind].push(type2);
|
|
638
|
+
result.multi["fallback"].push(type2);
|
|
639
|
+
} else {
|
|
640
|
+
result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
for (index = 0, length = arguments.length; index < length; index += 1) {
|
|
644
|
+
arguments[index].forEach(collectType);
|
|
645
|
+
}
|
|
646
|
+
return result;
|
|
647
|
+
}
|
|
648
|
+
function Schema$1(definition) {
|
|
649
|
+
return this.extend(definition);
|
|
650
|
+
}
|
|
651
|
+
Schema$1.prototype.extend = function extend2(definition) {
|
|
652
|
+
var implicit = [];
|
|
653
|
+
var explicit = [];
|
|
654
|
+
if (definition instanceof type) {
|
|
655
|
+
explicit.push(definition);
|
|
656
|
+
} else if (Array.isArray(definition)) {
|
|
657
|
+
explicit = explicit.concat(definition);
|
|
658
|
+
} else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
|
|
659
|
+
if (definition.implicit) implicit = implicit.concat(definition.implicit);
|
|
660
|
+
if (definition.explicit) explicit = explicit.concat(definition.explicit);
|
|
661
|
+
} else {
|
|
662
|
+
throw new exception("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");
|
|
663
|
+
}
|
|
664
|
+
implicit.forEach(function(type$1) {
|
|
665
|
+
if (!(type$1 instanceof type)) {
|
|
666
|
+
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
667
|
+
}
|
|
668
|
+
if (type$1.loadKind && type$1.loadKind !== "scalar") {
|
|
669
|
+
throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
|
|
670
|
+
}
|
|
671
|
+
if (type$1.multi) {
|
|
672
|
+
throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
explicit.forEach(function(type$1) {
|
|
676
|
+
if (!(type$1 instanceof type)) {
|
|
677
|
+
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
var result = Object.create(Schema$1.prototype);
|
|
681
|
+
result.implicit = (this.implicit || []).concat(implicit);
|
|
682
|
+
result.explicit = (this.explicit || []).concat(explicit);
|
|
683
|
+
result.compiledImplicit = compileList(result, "implicit");
|
|
684
|
+
result.compiledExplicit = compileList(result, "explicit");
|
|
685
|
+
result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
|
|
686
|
+
return result;
|
|
687
|
+
};
|
|
688
|
+
var schema = Schema$1;
|
|
689
|
+
var str = new type("tag:yaml.org,2002:str", {
|
|
690
|
+
kind: "scalar",
|
|
691
|
+
construct: function(data) {
|
|
692
|
+
return data !== null ? data : "";
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
var seq = new type("tag:yaml.org,2002:seq", {
|
|
696
|
+
kind: "sequence",
|
|
697
|
+
construct: function(data) {
|
|
698
|
+
return data !== null ? data : [];
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
var map = new type("tag:yaml.org,2002:map", {
|
|
702
|
+
kind: "mapping",
|
|
703
|
+
construct: function(data) {
|
|
704
|
+
return data !== null ? data : {};
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
var failsafe = new schema({
|
|
708
|
+
explicit: [
|
|
709
|
+
str,
|
|
710
|
+
seq,
|
|
711
|
+
map
|
|
712
|
+
]
|
|
713
|
+
});
|
|
714
|
+
function resolveYamlNull(data) {
|
|
715
|
+
if (data === null) return true;
|
|
716
|
+
var max = data.length;
|
|
717
|
+
return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
|
|
718
|
+
}
|
|
719
|
+
function constructYamlNull() {
|
|
720
|
+
return null;
|
|
721
|
+
}
|
|
722
|
+
function isNull(object) {
|
|
723
|
+
return object === null;
|
|
724
|
+
}
|
|
725
|
+
var _null = new type("tag:yaml.org,2002:null", {
|
|
726
|
+
kind: "scalar",
|
|
727
|
+
resolve: resolveYamlNull,
|
|
728
|
+
construct: constructYamlNull,
|
|
729
|
+
predicate: isNull,
|
|
730
|
+
represent: {
|
|
731
|
+
canonical: function() {
|
|
732
|
+
return "~";
|
|
733
|
+
},
|
|
734
|
+
lowercase: function() {
|
|
735
|
+
return "null";
|
|
736
|
+
},
|
|
737
|
+
uppercase: function() {
|
|
738
|
+
return "NULL";
|
|
739
|
+
},
|
|
740
|
+
camelcase: function() {
|
|
741
|
+
return "Null";
|
|
742
|
+
},
|
|
743
|
+
empty: function() {
|
|
744
|
+
return "";
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
defaultStyle: "lowercase"
|
|
748
|
+
});
|
|
749
|
+
function resolveYamlBoolean(data) {
|
|
750
|
+
if (data === null) return false;
|
|
751
|
+
var max = data.length;
|
|
752
|
+
return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
|
|
753
|
+
}
|
|
754
|
+
function constructYamlBoolean(data) {
|
|
755
|
+
return data === "true" || data === "True" || data === "TRUE";
|
|
756
|
+
}
|
|
757
|
+
function isBoolean(object) {
|
|
758
|
+
return Object.prototype.toString.call(object) === "[object Boolean]";
|
|
759
|
+
}
|
|
760
|
+
var bool = new type("tag:yaml.org,2002:bool", {
|
|
761
|
+
kind: "scalar",
|
|
762
|
+
resolve: resolveYamlBoolean,
|
|
763
|
+
construct: constructYamlBoolean,
|
|
764
|
+
predicate: isBoolean,
|
|
765
|
+
represent: {
|
|
766
|
+
lowercase: function(object) {
|
|
767
|
+
return object ? "true" : "false";
|
|
768
|
+
},
|
|
769
|
+
uppercase: function(object) {
|
|
770
|
+
return object ? "TRUE" : "FALSE";
|
|
771
|
+
},
|
|
772
|
+
camelcase: function(object) {
|
|
773
|
+
return object ? "True" : "False";
|
|
774
|
+
}
|
|
775
|
+
},
|
|
776
|
+
defaultStyle: "lowercase"
|
|
777
|
+
});
|
|
778
|
+
function isHexCode(c) {
|
|
779
|
+
return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
|
|
780
|
+
}
|
|
781
|
+
function isOctCode(c) {
|
|
782
|
+
return 48 <= c && c <= 55;
|
|
783
|
+
}
|
|
784
|
+
function isDecCode(c) {
|
|
785
|
+
return 48 <= c && c <= 57;
|
|
786
|
+
}
|
|
787
|
+
function resolveYamlInteger(data) {
|
|
788
|
+
if (data === null) return false;
|
|
789
|
+
var max = data.length, index = 0, hasDigits = false, ch;
|
|
790
|
+
if (!max) return false;
|
|
791
|
+
ch = data[index];
|
|
792
|
+
if (ch === "-" || ch === "+") {
|
|
793
|
+
ch = data[++index];
|
|
794
|
+
}
|
|
795
|
+
if (ch === "0") {
|
|
796
|
+
if (index + 1 === max) return true;
|
|
797
|
+
ch = data[++index];
|
|
798
|
+
if (ch === "b") {
|
|
799
|
+
index++;
|
|
800
|
+
for (; index < max; index++) {
|
|
801
|
+
ch = data[index];
|
|
802
|
+
if (ch === "_") continue;
|
|
803
|
+
if (ch !== "0" && ch !== "1") return false;
|
|
804
|
+
hasDigits = true;
|
|
805
|
+
}
|
|
806
|
+
return hasDigits && ch !== "_";
|
|
807
|
+
}
|
|
808
|
+
if (ch === "x") {
|
|
809
|
+
index++;
|
|
810
|
+
for (; index < max; index++) {
|
|
811
|
+
ch = data[index];
|
|
812
|
+
if (ch === "_") continue;
|
|
813
|
+
if (!isHexCode(data.charCodeAt(index))) return false;
|
|
814
|
+
hasDigits = true;
|
|
815
|
+
}
|
|
816
|
+
return hasDigits && ch !== "_";
|
|
817
|
+
}
|
|
818
|
+
if (ch === "o") {
|
|
819
|
+
index++;
|
|
820
|
+
for (; index < max; index++) {
|
|
821
|
+
ch = data[index];
|
|
822
|
+
if (ch === "_") continue;
|
|
823
|
+
if (!isOctCode(data.charCodeAt(index))) return false;
|
|
824
|
+
hasDigits = true;
|
|
825
|
+
}
|
|
826
|
+
return hasDigits && ch !== "_";
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
if (ch === "_") return false;
|
|
830
|
+
for (; index < max; index++) {
|
|
831
|
+
ch = data[index];
|
|
832
|
+
if (ch === "_") continue;
|
|
833
|
+
if (!isDecCode(data.charCodeAt(index))) {
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
hasDigits = true;
|
|
837
|
+
}
|
|
838
|
+
if (!hasDigits || ch === "_") return false;
|
|
839
|
+
return true;
|
|
840
|
+
}
|
|
841
|
+
function constructYamlInteger(data) {
|
|
842
|
+
var value = data, sign = 1, ch;
|
|
843
|
+
if (value.indexOf("_") !== -1) {
|
|
844
|
+
value = value.replace(/_/g, "");
|
|
845
|
+
}
|
|
846
|
+
ch = value[0];
|
|
847
|
+
if (ch === "-" || ch === "+") {
|
|
848
|
+
if (ch === "-") sign = -1;
|
|
849
|
+
value = value.slice(1);
|
|
850
|
+
ch = value[0];
|
|
851
|
+
}
|
|
852
|
+
if (value === "0") return 0;
|
|
853
|
+
if (ch === "0") {
|
|
854
|
+
if (value[1] === "b") return sign * parseInt(value.slice(2), 2);
|
|
855
|
+
if (value[1] === "x") return sign * parseInt(value.slice(2), 16);
|
|
856
|
+
if (value[1] === "o") return sign * parseInt(value.slice(2), 8);
|
|
857
|
+
}
|
|
858
|
+
return sign * parseInt(value, 10);
|
|
859
|
+
}
|
|
860
|
+
function isInteger(object) {
|
|
861
|
+
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
|
|
862
|
+
}
|
|
863
|
+
var int = new type("tag:yaml.org,2002:int", {
|
|
864
|
+
kind: "scalar",
|
|
865
|
+
resolve: resolveYamlInteger,
|
|
866
|
+
construct: constructYamlInteger,
|
|
867
|
+
predicate: isInteger,
|
|
868
|
+
represent: {
|
|
869
|
+
binary: function(obj) {
|
|
870
|
+
return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
|
|
871
|
+
},
|
|
872
|
+
octal: function(obj) {
|
|
873
|
+
return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
|
|
874
|
+
},
|
|
875
|
+
decimal: function(obj) {
|
|
876
|
+
return obj.toString(10);
|
|
877
|
+
},
|
|
878
|
+
/* eslint-disable max-len */
|
|
879
|
+
hexadecimal: function(obj) {
|
|
880
|
+
return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
|
|
881
|
+
}
|
|
882
|
+
},
|
|
883
|
+
defaultStyle: "decimal",
|
|
884
|
+
styleAliases: {
|
|
885
|
+
binary: [2, "bin"],
|
|
886
|
+
octal: [8, "oct"],
|
|
887
|
+
decimal: [10, "dec"],
|
|
888
|
+
hexadecimal: [16, "hex"]
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
var YAML_FLOAT_PATTERN = new RegExp(
|
|
892
|
+
// 2.5e4, 2.5 and integers
|
|
893
|
+
"^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"
|
|
894
|
+
);
|
|
895
|
+
function resolveYamlFloat(data) {
|
|
896
|
+
if (data === null) return false;
|
|
897
|
+
if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
|
|
898
|
+
// Probably should update regexp & check speed
|
|
899
|
+
data[data.length - 1] === "_") {
|
|
900
|
+
return false;
|
|
901
|
+
}
|
|
902
|
+
return true;
|
|
903
|
+
}
|
|
904
|
+
function constructYamlFloat(data) {
|
|
905
|
+
var value, sign;
|
|
906
|
+
value = data.replace(/_/g, "").toLowerCase();
|
|
907
|
+
sign = value[0] === "-" ? -1 : 1;
|
|
908
|
+
if ("+-".indexOf(value[0]) >= 0) {
|
|
909
|
+
value = value.slice(1);
|
|
910
|
+
}
|
|
911
|
+
if (value === ".inf") {
|
|
912
|
+
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
913
|
+
} else if (value === ".nan") {
|
|
914
|
+
return NaN;
|
|
915
|
+
}
|
|
916
|
+
return sign * parseFloat(value, 10);
|
|
917
|
+
}
|
|
918
|
+
var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
|
919
|
+
function representYamlFloat(object, style) {
|
|
920
|
+
var res;
|
|
921
|
+
if (isNaN(object)) {
|
|
922
|
+
switch (style) {
|
|
923
|
+
case "lowercase":
|
|
924
|
+
return ".nan";
|
|
925
|
+
case "uppercase":
|
|
926
|
+
return ".NAN";
|
|
927
|
+
case "camelcase":
|
|
928
|
+
return ".NaN";
|
|
929
|
+
}
|
|
930
|
+
} else if (Number.POSITIVE_INFINITY === object) {
|
|
931
|
+
switch (style) {
|
|
932
|
+
case "lowercase":
|
|
933
|
+
return ".inf";
|
|
934
|
+
case "uppercase":
|
|
935
|
+
return ".INF";
|
|
936
|
+
case "camelcase":
|
|
937
|
+
return ".Inf";
|
|
938
|
+
}
|
|
939
|
+
} else if (Number.NEGATIVE_INFINITY === object) {
|
|
940
|
+
switch (style) {
|
|
941
|
+
case "lowercase":
|
|
942
|
+
return "-.inf";
|
|
943
|
+
case "uppercase":
|
|
944
|
+
return "-.INF";
|
|
945
|
+
case "camelcase":
|
|
946
|
+
return "-.Inf";
|
|
947
|
+
}
|
|
948
|
+
} else if (common.isNegativeZero(object)) {
|
|
949
|
+
return "-0.0";
|
|
950
|
+
}
|
|
951
|
+
res = object.toString(10);
|
|
952
|
+
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
|
|
953
|
+
}
|
|
954
|
+
function isFloat(object) {
|
|
955
|
+
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
|
|
956
|
+
}
|
|
957
|
+
var float = new type("tag:yaml.org,2002:float", {
|
|
958
|
+
kind: "scalar",
|
|
959
|
+
resolve: resolveYamlFloat,
|
|
960
|
+
construct: constructYamlFloat,
|
|
961
|
+
predicate: isFloat,
|
|
962
|
+
represent: representYamlFloat,
|
|
963
|
+
defaultStyle: "lowercase"
|
|
964
|
+
});
|
|
965
|
+
var json = failsafe.extend({
|
|
966
|
+
implicit: [
|
|
967
|
+
_null,
|
|
968
|
+
bool,
|
|
969
|
+
int,
|
|
970
|
+
float
|
|
971
|
+
]
|
|
972
|
+
});
|
|
973
|
+
var core = json;
|
|
974
|
+
var YAML_DATE_REGEXP = new RegExp(
|
|
975
|
+
"^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"
|
|
976
|
+
);
|
|
977
|
+
var YAML_TIMESTAMP_REGEXP = new RegExp(
|
|
978
|
+
"^([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]))?))?$"
|
|
979
|
+
);
|
|
980
|
+
function resolveYamlTimestamp(data) {
|
|
981
|
+
if (data === null) return false;
|
|
982
|
+
if (YAML_DATE_REGEXP.exec(data) !== null) return true;
|
|
983
|
+
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
function constructYamlTimestamp(data) {
|
|
987
|
+
var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
|
|
988
|
+
match = YAML_DATE_REGEXP.exec(data);
|
|
989
|
+
if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
|
|
990
|
+
if (match === null) throw new Error("Date resolve error");
|
|
991
|
+
year = +match[1];
|
|
992
|
+
month = +match[2] - 1;
|
|
993
|
+
day = +match[3];
|
|
994
|
+
if (!match[4]) {
|
|
995
|
+
return new Date(Date.UTC(year, month, day));
|
|
996
|
+
}
|
|
997
|
+
hour = +match[4];
|
|
998
|
+
minute = +match[5];
|
|
999
|
+
second = +match[6];
|
|
1000
|
+
if (match[7]) {
|
|
1001
|
+
fraction = match[7].slice(0, 3);
|
|
1002
|
+
while (fraction.length < 3) {
|
|
1003
|
+
fraction += "0";
|
|
1004
|
+
}
|
|
1005
|
+
fraction = +fraction;
|
|
1006
|
+
}
|
|
1007
|
+
if (match[9]) {
|
|
1008
|
+
tz_hour = +match[10];
|
|
1009
|
+
tz_minute = +(match[11] || 0);
|
|
1010
|
+
delta = (tz_hour * 60 + tz_minute) * 6e4;
|
|
1011
|
+
if (match[9] === "-") delta = -delta;
|
|
1012
|
+
}
|
|
1013
|
+
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
1014
|
+
if (delta) date.setTime(date.getTime() - delta);
|
|
1015
|
+
return date;
|
|
1016
|
+
}
|
|
1017
|
+
function representYamlTimestamp(object) {
|
|
1018
|
+
return object.toISOString();
|
|
1019
|
+
}
|
|
1020
|
+
var timestamp = new type("tag:yaml.org,2002:timestamp", {
|
|
1021
|
+
kind: "scalar",
|
|
1022
|
+
resolve: resolveYamlTimestamp,
|
|
1023
|
+
construct: constructYamlTimestamp,
|
|
1024
|
+
instanceOf: Date,
|
|
1025
|
+
represent: representYamlTimestamp
|
|
1026
|
+
});
|
|
1027
|
+
function resolveYamlMerge(data) {
|
|
1028
|
+
return data === "<<" || data === null;
|
|
1029
|
+
}
|
|
1030
|
+
var merge = new type("tag:yaml.org,2002:merge", {
|
|
1031
|
+
kind: "scalar",
|
|
1032
|
+
resolve: resolveYamlMerge
|
|
1033
|
+
});
|
|
1034
|
+
var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
|
|
1035
|
+
function resolveYamlBinary(data) {
|
|
1036
|
+
if (data === null) return false;
|
|
1037
|
+
var code, idx, bitlen = 0, max = data.length, map2 = BASE64_MAP;
|
|
1038
|
+
for (idx = 0; idx < max; idx++) {
|
|
1039
|
+
code = map2.indexOf(data.charAt(idx));
|
|
1040
|
+
if (code > 64) continue;
|
|
1041
|
+
if (code < 0) return false;
|
|
1042
|
+
bitlen += 6;
|
|
1043
|
+
}
|
|
1044
|
+
return bitlen % 8 === 0;
|
|
1045
|
+
}
|
|
1046
|
+
function constructYamlBinary(data) {
|
|
1047
|
+
var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map2 = BASE64_MAP, bits = 0, result = [];
|
|
1048
|
+
for (idx = 0; idx < max; idx++) {
|
|
1049
|
+
if (idx % 4 === 0 && idx) {
|
|
1050
|
+
result.push(bits >> 16 & 255);
|
|
1051
|
+
result.push(bits >> 8 & 255);
|
|
1052
|
+
result.push(bits & 255);
|
|
1053
|
+
}
|
|
1054
|
+
bits = bits << 6 | map2.indexOf(input.charAt(idx));
|
|
1055
|
+
}
|
|
1056
|
+
tailbits = max % 4 * 6;
|
|
1057
|
+
if (tailbits === 0) {
|
|
1058
|
+
result.push(bits >> 16 & 255);
|
|
1059
|
+
result.push(bits >> 8 & 255);
|
|
1060
|
+
result.push(bits & 255);
|
|
1061
|
+
} else if (tailbits === 18) {
|
|
1062
|
+
result.push(bits >> 10 & 255);
|
|
1063
|
+
result.push(bits >> 2 & 255);
|
|
1064
|
+
} else if (tailbits === 12) {
|
|
1065
|
+
result.push(bits >> 4 & 255);
|
|
1066
|
+
}
|
|
1067
|
+
return new Uint8Array(result);
|
|
1068
|
+
}
|
|
1069
|
+
function representYamlBinary(object) {
|
|
1070
|
+
var result = "", bits = 0, idx, tail, max = object.length, map2 = BASE64_MAP;
|
|
1071
|
+
for (idx = 0; idx < max; idx++) {
|
|
1072
|
+
if (idx % 3 === 0 && idx) {
|
|
1073
|
+
result += map2[bits >> 18 & 63];
|
|
1074
|
+
result += map2[bits >> 12 & 63];
|
|
1075
|
+
result += map2[bits >> 6 & 63];
|
|
1076
|
+
result += map2[bits & 63];
|
|
1077
|
+
}
|
|
1078
|
+
bits = (bits << 8) + object[idx];
|
|
1079
|
+
}
|
|
1080
|
+
tail = max % 3;
|
|
1081
|
+
if (tail === 0) {
|
|
1082
|
+
result += map2[bits >> 18 & 63];
|
|
1083
|
+
result += map2[bits >> 12 & 63];
|
|
1084
|
+
result += map2[bits >> 6 & 63];
|
|
1085
|
+
result += map2[bits & 63];
|
|
1086
|
+
} else if (tail === 2) {
|
|
1087
|
+
result += map2[bits >> 10 & 63];
|
|
1088
|
+
result += map2[bits >> 4 & 63];
|
|
1089
|
+
result += map2[bits << 2 & 63];
|
|
1090
|
+
result += map2[64];
|
|
1091
|
+
} else if (tail === 1) {
|
|
1092
|
+
result += map2[bits >> 2 & 63];
|
|
1093
|
+
result += map2[bits << 4 & 63];
|
|
1094
|
+
result += map2[64];
|
|
1095
|
+
result += map2[64];
|
|
1096
|
+
}
|
|
1097
|
+
return result;
|
|
1098
|
+
}
|
|
1099
|
+
function isBinary(obj) {
|
|
1100
|
+
return Object.prototype.toString.call(obj) === "[object Uint8Array]";
|
|
1101
|
+
}
|
|
1102
|
+
var binary = new type("tag:yaml.org,2002:binary", {
|
|
1103
|
+
kind: "scalar",
|
|
1104
|
+
resolve: resolveYamlBinary,
|
|
1105
|
+
construct: constructYamlBinary,
|
|
1106
|
+
predicate: isBinary,
|
|
1107
|
+
represent: representYamlBinary
|
|
1108
|
+
});
|
|
1109
|
+
var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
1110
|
+
var _toString$2 = Object.prototype.toString;
|
|
1111
|
+
function resolveYamlOmap(data) {
|
|
1112
|
+
if (data === null) return true;
|
|
1113
|
+
var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
|
|
1114
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
1115
|
+
pair = object[index];
|
|
1116
|
+
pairHasKey = false;
|
|
1117
|
+
if (_toString$2.call(pair) !== "[object Object]") return false;
|
|
1118
|
+
for (pairKey in pair) {
|
|
1119
|
+
if (_hasOwnProperty$3.call(pair, pairKey)) {
|
|
1120
|
+
if (!pairHasKey) pairHasKey = true;
|
|
1121
|
+
else return false;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
if (!pairHasKey) return false;
|
|
1125
|
+
if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
|
|
1126
|
+
else return false;
|
|
1127
|
+
}
|
|
1128
|
+
return true;
|
|
1129
|
+
}
|
|
1130
|
+
function constructYamlOmap(data) {
|
|
1131
|
+
return data !== null ? data : [];
|
|
1132
|
+
}
|
|
1133
|
+
var omap = new type("tag:yaml.org,2002:omap", {
|
|
1134
|
+
kind: "sequence",
|
|
1135
|
+
resolve: resolveYamlOmap,
|
|
1136
|
+
construct: constructYamlOmap
|
|
1137
|
+
});
|
|
1138
|
+
var _toString$1 = Object.prototype.toString;
|
|
1139
|
+
function resolveYamlPairs(data) {
|
|
1140
|
+
if (data === null) return true;
|
|
1141
|
+
var index, length, pair, keys, result, object = data;
|
|
1142
|
+
result = new Array(object.length);
|
|
1143
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
1144
|
+
pair = object[index];
|
|
1145
|
+
if (_toString$1.call(pair) !== "[object Object]") return false;
|
|
1146
|
+
keys = Object.keys(pair);
|
|
1147
|
+
if (keys.length !== 1) return false;
|
|
1148
|
+
result[index] = [keys[0], pair[keys[0]]];
|
|
1149
|
+
}
|
|
1150
|
+
return true;
|
|
1151
|
+
}
|
|
1152
|
+
function constructYamlPairs(data) {
|
|
1153
|
+
if (data === null) return [];
|
|
1154
|
+
var index, length, pair, keys, result, object = data;
|
|
1155
|
+
result = new Array(object.length);
|
|
1156
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
1157
|
+
pair = object[index];
|
|
1158
|
+
keys = Object.keys(pair);
|
|
1159
|
+
result[index] = [keys[0], pair[keys[0]]];
|
|
1160
|
+
}
|
|
1161
|
+
return result;
|
|
1162
|
+
}
|
|
1163
|
+
var pairs = new type("tag:yaml.org,2002:pairs", {
|
|
1164
|
+
kind: "sequence",
|
|
1165
|
+
resolve: resolveYamlPairs,
|
|
1166
|
+
construct: constructYamlPairs
|
|
1167
|
+
});
|
|
1168
|
+
var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
1169
|
+
function resolveYamlSet(data) {
|
|
1170
|
+
if (data === null) return true;
|
|
1171
|
+
var key, object = data;
|
|
1172
|
+
for (key in object) {
|
|
1173
|
+
if (_hasOwnProperty$2.call(object, key)) {
|
|
1174
|
+
if (object[key] !== null) return false;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
return true;
|
|
1178
|
+
}
|
|
1179
|
+
function constructYamlSet(data) {
|
|
1180
|
+
return data !== null ? data : {};
|
|
1181
|
+
}
|
|
1182
|
+
var set = new type("tag:yaml.org,2002:set", {
|
|
1183
|
+
kind: "mapping",
|
|
1184
|
+
resolve: resolveYamlSet,
|
|
1185
|
+
construct: constructYamlSet
|
|
1186
|
+
});
|
|
1187
|
+
var _default = core.extend({
|
|
1188
|
+
implicit: [
|
|
1189
|
+
timestamp,
|
|
1190
|
+
merge
|
|
1191
|
+
],
|
|
1192
|
+
explicit: [
|
|
1193
|
+
binary,
|
|
1194
|
+
omap,
|
|
1195
|
+
pairs,
|
|
1196
|
+
set
|
|
1197
|
+
]
|
|
1198
|
+
});
|
|
1199
|
+
var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
1200
|
+
var CONTEXT_FLOW_IN = 1;
|
|
1201
|
+
var CONTEXT_FLOW_OUT = 2;
|
|
1202
|
+
var CONTEXT_BLOCK_IN = 3;
|
|
1203
|
+
var CONTEXT_BLOCK_OUT = 4;
|
|
1204
|
+
var CHOMPING_CLIP = 1;
|
|
1205
|
+
var CHOMPING_STRIP = 2;
|
|
1206
|
+
var CHOMPING_KEEP = 3;
|
|
1207
|
+
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
|
1208
|
+
var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
|
|
1209
|
+
var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
|
|
1210
|
+
var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
|
|
1211
|
+
var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
|
|
1212
|
+
function _class(obj) {
|
|
1213
|
+
return Object.prototype.toString.call(obj);
|
|
1214
|
+
}
|
|
1215
|
+
function is_EOL(c) {
|
|
1216
|
+
return c === 10 || c === 13;
|
|
1217
|
+
}
|
|
1218
|
+
function is_WHITE_SPACE(c) {
|
|
1219
|
+
return c === 9 || c === 32;
|
|
1220
|
+
}
|
|
1221
|
+
function is_WS_OR_EOL(c) {
|
|
1222
|
+
return c === 9 || c === 32 || c === 10 || c === 13;
|
|
1223
|
+
}
|
|
1224
|
+
function is_FLOW_INDICATOR(c) {
|
|
1225
|
+
return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
|
|
1226
|
+
}
|
|
1227
|
+
function fromHexCode(c) {
|
|
1228
|
+
var lc;
|
|
1229
|
+
if (48 <= c && c <= 57) {
|
|
1230
|
+
return c - 48;
|
|
1231
|
+
}
|
|
1232
|
+
lc = c | 32;
|
|
1233
|
+
if (97 <= lc && lc <= 102) {
|
|
1234
|
+
return lc - 97 + 10;
|
|
1235
|
+
}
|
|
1236
|
+
return -1;
|
|
1237
|
+
}
|
|
1238
|
+
function escapedHexLen(c) {
|
|
1239
|
+
if (c === 120) {
|
|
1240
|
+
return 2;
|
|
1241
|
+
}
|
|
1242
|
+
if (c === 117) {
|
|
1243
|
+
return 4;
|
|
1244
|
+
}
|
|
1245
|
+
if (c === 85) {
|
|
1246
|
+
return 8;
|
|
1247
|
+
}
|
|
1248
|
+
return 0;
|
|
1249
|
+
}
|
|
1250
|
+
function fromDecimalCode(c) {
|
|
1251
|
+
if (48 <= c && c <= 57) {
|
|
1252
|
+
return c - 48;
|
|
1253
|
+
}
|
|
1254
|
+
return -1;
|
|
1255
|
+
}
|
|
1256
|
+
function simpleEscapeSequence(c) {
|
|
1257
|
+
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" : "";
|
|
1258
|
+
}
|
|
1259
|
+
function charFromCodepoint(c) {
|
|
1260
|
+
if (c <= 65535) {
|
|
1261
|
+
return String.fromCharCode(c);
|
|
1262
|
+
}
|
|
1263
|
+
return String.fromCharCode(
|
|
1264
|
+
(c - 65536 >> 10) + 55296,
|
|
1265
|
+
(c - 65536 & 1023) + 56320
|
|
1266
|
+
);
|
|
1267
|
+
}
|
|
1268
|
+
function setProperty(object, key, value) {
|
|
1269
|
+
if (key === "__proto__") {
|
|
1270
|
+
Object.defineProperty(object, key, {
|
|
1271
|
+
configurable: true,
|
|
1272
|
+
enumerable: true,
|
|
1273
|
+
writable: true,
|
|
1274
|
+
value
|
|
1275
|
+
});
|
|
1276
|
+
} else {
|
|
1277
|
+
object[key] = value;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
var simpleEscapeCheck = new Array(256);
|
|
1281
|
+
var simpleEscapeMap = new Array(256);
|
|
1282
|
+
for (i = 0; i < 256; i++) {
|
|
1283
|
+
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|
1284
|
+
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|
1285
|
+
}
|
|
1286
|
+
var i;
|
|
1287
|
+
function State$1(input, options) {
|
|
1288
|
+
this.input = input;
|
|
1289
|
+
this.filename = options["filename"] || null;
|
|
1290
|
+
this.schema = options["schema"] || _default;
|
|
1291
|
+
this.onWarning = options["onWarning"] || null;
|
|
1292
|
+
this.legacy = options["legacy"] || false;
|
|
1293
|
+
this.json = options["json"] || false;
|
|
1294
|
+
this.listener = options["listener"] || null;
|
|
1295
|
+
this.implicitTypes = this.schema.compiledImplicit;
|
|
1296
|
+
this.typeMap = this.schema.compiledTypeMap;
|
|
1297
|
+
this.length = input.length;
|
|
1298
|
+
this.position = 0;
|
|
1299
|
+
this.line = 0;
|
|
1300
|
+
this.lineStart = 0;
|
|
1301
|
+
this.lineIndent = 0;
|
|
1302
|
+
this.firstTabInLine = -1;
|
|
1303
|
+
this.documents = [];
|
|
1304
|
+
}
|
|
1305
|
+
function generateError(state, message) {
|
|
1306
|
+
var mark = {
|
|
1307
|
+
name: state.filename,
|
|
1308
|
+
buffer: state.input.slice(0, -1),
|
|
1309
|
+
// omit trailing \0
|
|
1310
|
+
position: state.position,
|
|
1311
|
+
line: state.line,
|
|
1312
|
+
column: state.position - state.lineStart
|
|
1313
|
+
};
|
|
1314
|
+
mark.snippet = snippet(mark);
|
|
1315
|
+
return new exception(message, mark);
|
|
1316
|
+
}
|
|
1317
|
+
function throwError(state, message) {
|
|
1318
|
+
throw generateError(state, message);
|
|
1319
|
+
}
|
|
1320
|
+
function throwWarning(state, message) {
|
|
1321
|
+
if (state.onWarning) {
|
|
1322
|
+
state.onWarning.call(null, generateError(state, message));
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
var directiveHandlers = {
|
|
1326
|
+
YAML: function handleYamlDirective(state, name, args) {
|
|
1327
|
+
var match, major, minor;
|
|
1328
|
+
if (state.version !== null) {
|
|
1329
|
+
throwError(state, "duplication of %YAML directive");
|
|
1330
|
+
}
|
|
1331
|
+
if (args.length !== 1) {
|
|
1332
|
+
throwError(state, "YAML directive accepts exactly one argument");
|
|
1333
|
+
}
|
|
1334
|
+
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
1335
|
+
if (match === null) {
|
|
1336
|
+
throwError(state, "ill-formed argument of the YAML directive");
|
|
1337
|
+
}
|
|
1338
|
+
major = parseInt(match[1], 10);
|
|
1339
|
+
minor = parseInt(match[2], 10);
|
|
1340
|
+
if (major !== 1) {
|
|
1341
|
+
throwError(state, "unacceptable YAML version of the document");
|
|
1342
|
+
}
|
|
1343
|
+
state.version = args[0];
|
|
1344
|
+
state.checkLineBreaks = minor < 2;
|
|
1345
|
+
if (minor !== 1 && minor !== 2) {
|
|
1346
|
+
throwWarning(state, "unsupported YAML version of the document");
|
|
1347
|
+
}
|
|
1348
|
+
},
|
|
1349
|
+
TAG: function handleTagDirective(state, name, args) {
|
|
1350
|
+
var handle, prefix;
|
|
1351
|
+
if (args.length !== 2) {
|
|
1352
|
+
throwError(state, "TAG directive accepts exactly two arguments");
|
|
1353
|
+
}
|
|
1354
|
+
handle = args[0];
|
|
1355
|
+
prefix = args[1];
|
|
1356
|
+
if (!PATTERN_TAG_HANDLE.test(handle)) {
|
|
1357
|
+
throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
1358
|
+
}
|
|
1359
|
+
if (_hasOwnProperty$1.call(state.tagMap, handle)) {
|
|
1360
|
+
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
|
1361
|
+
}
|
|
1362
|
+
if (!PATTERN_TAG_URI.test(prefix)) {
|
|
1363
|
+
throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
1364
|
+
}
|
|
1365
|
+
try {
|
|
1366
|
+
prefix = decodeURIComponent(prefix);
|
|
1367
|
+
} catch (err) {
|
|
1368
|
+
throwError(state, "tag prefix is malformed: " + prefix);
|
|
1369
|
+
}
|
|
1370
|
+
state.tagMap[handle] = prefix;
|
|
1371
|
+
}
|
|
1372
|
+
};
|
|
1373
|
+
function captureSegment(state, start, end, checkJson) {
|
|
1374
|
+
var _position, _length, _character, _result;
|
|
1375
|
+
if (start < end) {
|
|
1376
|
+
_result = state.input.slice(start, end);
|
|
1377
|
+
if (checkJson) {
|
|
1378
|
+
for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
|
|
1379
|
+
_character = _result.charCodeAt(_position);
|
|
1380
|
+
if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
|
|
1381
|
+
throwError(state, "expected valid JSON character");
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
|
1385
|
+
throwError(state, "the stream contains non-printable characters");
|
|
1386
|
+
}
|
|
1387
|
+
state.result += _result;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
function mergeMappings(state, destination, source, overridableKeys) {
|
|
1391
|
+
var sourceKeys, key, index, quantity;
|
|
1392
|
+
if (!common.isObject(source)) {
|
|
1393
|
+
throwError(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1394
|
+
}
|
|
1395
|
+
sourceKeys = Object.keys(source);
|
|
1396
|
+
for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
|
|
1397
|
+
key = sourceKeys[index];
|
|
1398
|
+
if (!_hasOwnProperty$1.call(destination, key)) {
|
|
1399
|
+
setProperty(destination, key, source[key]);
|
|
1400
|
+
overridableKeys[key] = true;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) {
|
|
1405
|
+
var index, quantity;
|
|
1406
|
+
if (Array.isArray(keyNode)) {
|
|
1407
|
+
keyNode = Array.prototype.slice.call(keyNode);
|
|
1408
|
+
for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
|
|
1409
|
+
if (Array.isArray(keyNode[index])) {
|
|
1410
|
+
throwError(state, "nested arrays are not supported inside keys");
|
|
1411
|
+
}
|
|
1412
|
+
if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
|
|
1413
|
+
keyNode[index] = "[object Object]";
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
|
|
1418
|
+
keyNode = "[object Object]";
|
|
1419
|
+
}
|
|
1420
|
+
keyNode = String(keyNode);
|
|
1421
|
+
if (_result === null) {
|
|
1422
|
+
_result = {};
|
|
1423
|
+
}
|
|
1424
|
+
if (keyTag === "tag:yaml.org,2002:merge") {
|
|
1425
|
+
if (Array.isArray(valueNode)) {
|
|
1426
|
+
for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
|
|
1427
|
+
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|
1428
|
+
}
|
|
1429
|
+
} else {
|
|
1430
|
+
mergeMappings(state, _result, valueNode, overridableKeys);
|
|
1431
|
+
}
|
|
1432
|
+
} else {
|
|
1433
|
+
if (!state.json && !_hasOwnProperty$1.call(overridableKeys, keyNode) && _hasOwnProperty$1.call(_result, keyNode)) {
|
|
1434
|
+
state.line = startLine || state.line;
|
|
1435
|
+
state.lineStart = startLineStart || state.lineStart;
|
|
1436
|
+
state.position = startPos || state.position;
|
|
1437
|
+
throwError(state, "duplicated mapping key");
|
|
1438
|
+
}
|
|
1439
|
+
setProperty(_result, keyNode, valueNode);
|
|
1440
|
+
delete overridableKeys[keyNode];
|
|
1441
|
+
}
|
|
1442
|
+
return _result;
|
|
1443
|
+
}
|
|
1444
|
+
function readLineBreak(state) {
|
|
1445
|
+
var ch;
|
|
1446
|
+
ch = state.input.charCodeAt(state.position);
|
|
1447
|
+
if (ch === 10) {
|
|
1448
|
+
state.position++;
|
|
1449
|
+
} else if (ch === 13) {
|
|
1450
|
+
state.position++;
|
|
1451
|
+
if (state.input.charCodeAt(state.position) === 10) {
|
|
1452
|
+
state.position++;
|
|
1453
|
+
}
|
|
1454
|
+
} else {
|
|
1455
|
+
throwError(state, "a line break is expected");
|
|
1456
|
+
}
|
|
1457
|
+
state.line += 1;
|
|
1458
|
+
state.lineStart = state.position;
|
|
1459
|
+
state.firstTabInLine = -1;
|
|
1460
|
+
}
|
|
1461
|
+
function skipSeparationSpace(state, allowComments, checkIndent) {
|
|
1462
|
+
var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
|
|
1463
|
+
while (ch !== 0) {
|
|
1464
|
+
while (is_WHITE_SPACE(ch)) {
|
|
1465
|
+
if (ch === 9 && state.firstTabInLine === -1) {
|
|
1466
|
+
state.firstTabInLine = state.position;
|
|
1467
|
+
}
|
|
1468
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1469
|
+
}
|
|
1470
|
+
if (allowComments && ch === 35) {
|
|
1471
|
+
do {
|
|
1472
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1473
|
+
} while (ch !== 10 && ch !== 13 && ch !== 0);
|
|
1474
|
+
}
|
|
1475
|
+
if (is_EOL(ch)) {
|
|
1476
|
+
readLineBreak(state);
|
|
1477
|
+
ch = state.input.charCodeAt(state.position);
|
|
1478
|
+
lineBreaks++;
|
|
1479
|
+
state.lineIndent = 0;
|
|
1480
|
+
while (ch === 32) {
|
|
1481
|
+
state.lineIndent++;
|
|
1482
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1483
|
+
}
|
|
1484
|
+
} else {
|
|
1485
|
+
break;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|
1489
|
+
throwWarning(state, "deficient indentation");
|
|
1490
|
+
}
|
|
1491
|
+
return lineBreaks;
|
|
1492
|
+
}
|
|
1493
|
+
function testDocumentSeparator(state) {
|
|
1494
|
+
var _position = state.position, ch;
|
|
1495
|
+
ch = state.input.charCodeAt(_position);
|
|
1496
|
+
if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
|
|
1497
|
+
_position += 3;
|
|
1498
|
+
ch = state.input.charCodeAt(_position);
|
|
1499
|
+
if (ch === 0 || is_WS_OR_EOL(ch)) {
|
|
1500
|
+
return true;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
return false;
|
|
1504
|
+
}
|
|
1505
|
+
function writeFoldedLines(state, count) {
|
|
1506
|
+
if (count === 1) {
|
|
1507
|
+
state.result += " ";
|
|
1508
|
+
} else if (count > 1) {
|
|
1509
|
+
state.result += common.repeat("\n", count - 1);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
1513
|
+
var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
|
|
1514
|
+
ch = state.input.charCodeAt(state.position);
|
|
1515
|
+
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) {
|
|
1516
|
+
return false;
|
|
1517
|
+
}
|
|
1518
|
+
if (ch === 63 || ch === 45) {
|
|
1519
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1520
|
+
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1521
|
+
return false;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
state.kind = "scalar";
|
|
1525
|
+
state.result = "";
|
|
1526
|
+
captureStart = captureEnd = state.position;
|
|
1527
|
+
hasPendingContent = false;
|
|
1528
|
+
while (ch !== 0) {
|
|
1529
|
+
if (ch === 58) {
|
|
1530
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1531
|
+
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1532
|
+
break;
|
|
1533
|
+
}
|
|
1534
|
+
} else if (ch === 35) {
|
|
1535
|
+
preceding = state.input.charCodeAt(state.position - 1);
|
|
1536
|
+
if (is_WS_OR_EOL(preceding)) {
|
|
1537
|
+
break;
|
|
1538
|
+
}
|
|
1539
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
|
1540
|
+
break;
|
|
1541
|
+
} else if (is_EOL(ch)) {
|
|
1542
|
+
_line = state.line;
|
|
1543
|
+
_lineStart = state.lineStart;
|
|
1544
|
+
_lineIndent = state.lineIndent;
|
|
1545
|
+
skipSeparationSpace(state, false, -1);
|
|
1546
|
+
if (state.lineIndent >= nodeIndent) {
|
|
1547
|
+
hasPendingContent = true;
|
|
1548
|
+
ch = state.input.charCodeAt(state.position);
|
|
1549
|
+
continue;
|
|
1550
|
+
} else {
|
|
1551
|
+
state.position = captureEnd;
|
|
1552
|
+
state.line = _line;
|
|
1553
|
+
state.lineStart = _lineStart;
|
|
1554
|
+
state.lineIndent = _lineIndent;
|
|
1555
|
+
break;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
if (hasPendingContent) {
|
|
1559
|
+
captureSegment(state, captureStart, captureEnd, false);
|
|
1560
|
+
writeFoldedLines(state, state.line - _line);
|
|
1561
|
+
captureStart = captureEnd = state.position;
|
|
1562
|
+
hasPendingContent = false;
|
|
1563
|
+
}
|
|
1564
|
+
if (!is_WHITE_SPACE(ch)) {
|
|
1565
|
+
captureEnd = state.position + 1;
|
|
1566
|
+
}
|
|
1567
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1568
|
+
}
|
|
1569
|
+
captureSegment(state, captureStart, captureEnd, false);
|
|
1570
|
+
if (state.result) {
|
|
1571
|
+
return true;
|
|
1572
|
+
}
|
|
1573
|
+
state.kind = _kind;
|
|
1574
|
+
state.result = _result;
|
|
1575
|
+
return false;
|
|
1576
|
+
}
|
|
1577
|
+
function readSingleQuotedScalar(state, nodeIndent) {
|
|
1578
|
+
var ch, captureStart, captureEnd;
|
|
1579
|
+
ch = state.input.charCodeAt(state.position);
|
|
1580
|
+
if (ch !== 39) {
|
|
1581
|
+
return false;
|
|
1582
|
+
}
|
|
1583
|
+
state.kind = "scalar";
|
|
1584
|
+
state.result = "";
|
|
1585
|
+
state.position++;
|
|
1586
|
+
captureStart = captureEnd = state.position;
|
|
1587
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1588
|
+
if (ch === 39) {
|
|
1589
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1590
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1591
|
+
if (ch === 39) {
|
|
1592
|
+
captureStart = state.position;
|
|
1593
|
+
state.position++;
|
|
1594
|
+
captureEnd = state.position;
|
|
1595
|
+
} else {
|
|
1596
|
+
return true;
|
|
1597
|
+
}
|
|
1598
|
+
} else if (is_EOL(ch)) {
|
|
1599
|
+
captureSegment(state, captureStart, captureEnd, true);
|
|
1600
|
+
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1601
|
+
captureStart = captureEnd = state.position;
|
|
1602
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1603
|
+
throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
1604
|
+
} else {
|
|
1605
|
+
state.position++;
|
|
1606
|
+
captureEnd = state.position;
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
1610
|
+
}
|
|
1611
|
+
function readDoubleQuotedScalar(state, nodeIndent) {
|
|
1612
|
+
var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
|
|
1613
|
+
ch = state.input.charCodeAt(state.position);
|
|
1614
|
+
if (ch !== 34) {
|
|
1615
|
+
return false;
|
|
1616
|
+
}
|
|
1617
|
+
state.kind = "scalar";
|
|
1618
|
+
state.result = "";
|
|
1619
|
+
state.position++;
|
|
1620
|
+
captureStart = captureEnd = state.position;
|
|
1621
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1622
|
+
if (ch === 34) {
|
|
1623
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1624
|
+
state.position++;
|
|
1625
|
+
return true;
|
|
1626
|
+
} else if (ch === 92) {
|
|
1627
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1628
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1629
|
+
if (is_EOL(ch)) {
|
|
1630
|
+
skipSeparationSpace(state, false, nodeIndent);
|
|
1631
|
+
} else if (ch < 256 && simpleEscapeCheck[ch]) {
|
|
1632
|
+
state.result += simpleEscapeMap[ch];
|
|
1633
|
+
state.position++;
|
|
1634
|
+
} else if ((tmp = escapedHexLen(ch)) > 0) {
|
|
1635
|
+
hexLength = tmp;
|
|
1636
|
+
hexResult = 0;
|
|
1637
|
+
for (; hexLength > 0; hexLength--) {
|
|
1638
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1639
|
+
if ((tmp = fromHexCode(ch)) >= 0) {
|
|
1640
|
+
hexResult = (hexResult << 4) + tmp;
|
|
1641
|
+
} else {
|
|
1642
|
+
throwError(state, "expected hexadecimal character");
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
state.result += charFromCodepoint(hexResult);
|
|
1646
|
+
state.position++;
|
|
1647
|
+
} else {
|
|
1648
|
+
throwError(state, "unknown escape sequence");
|
|
1649
|
+
}
|
|
1650
|
+
captureStart = captureEnd = state.position;
|
|
1651
|
+
} else if (is_EOL(ch)) {
|
|
1652
|
+
captureSegment(state, captureStart, captureEnd, true);
|
|
1653
|
+
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1654
|
+
captureStart = captureEnd = state.position;
|
|
1655
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1656
|
+
throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
1657
|
+
} else {
|
|
1658
|
+
state.position++;
|
|
1659
|
+
captureEnd = state.position;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
1663
|
+
}
|
|
1664
|
+
function readFlowCollection(state, nodeIndent) {
|
|
1665
|
+
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;
|
|
1666
|
+
ch = state.input.charCodeAt(state.position);
|
|
1667
|
+
if (ch === 91) {
|
|
1668
|
+
terminator = 93;
|
|
1669
|
+
isMapping = false;
|
|
1670
|
+
_result = [];
|
|
1671
|
+
} else if (ch === 123) {
|
|
1672
|
+
terminator = 125;
|
|
1673
|
+
isMapping = true;
|
|
1674
|
+
_result = {};
|
|
1675
|
+
} else {
|
|
1676
|
+
return false;
|
|
1677
|
+
}
|
|
1678
|
+
if (state.anchor !== null) {
|
|
1679
|
+
state.anchorMap[state.anchor] = _result;
|
|
1680
|
+
}
|
|
1681
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1682
|
+
while (ch !== 0) {
|
|
1683
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1684
|
+
ch = state.input.charCodeAt(state.position);
|
|
1685
|
+
if (ch === terminator) {
|
|
1686
|
+
state.position++;
|
|
1687
|
+
state.tag = _tag;
|
|
1688
|
+
state.anchor = _anchor;
|
|
1689
|
+
state.kind = isMapping ? "mapping" : "sequence";
|
|
1690
|
+
state.result = _result;
|
|
1691
|
+
return true;
|
|
1692
|
+
} else if (!readNext) {
|
|
1693
|
+
throwError(state, "missed comma between flow collection entries");
|
|
1694
|
+
} else if (ch === 44) {
|
|
1695
|
+
throwError(state, "expected the node content, but found ','");
|
|
1696
|
+
}
|
|
1697
|
+
keyTag = keyNode = valueNode = null;
|
|
1698
|
+
isPair = isExplicitPair = false;
|
|
1699
|
+
if (ch === 63) {
|
|
1700
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1701
|
+
if (is_WS_OR_EOL(following)) {
|
|
1702
|
+
isPair = isExplicitPair = true;
|
|
1703
|
+
state.position++;
|
|
1704
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
_line = state.line;
|
|
1708
|
+
_lineStart = state.lineStart;
|
|
1709
|
+
_pos = state.position;
|
|
1710
|
+
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1711
|
+
keyTag = state.tag;
|
|
1712
|
+
keyNode = state.result;
|
|
1713
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1714
|
+
ch = state.input.charCodeAt(state.position);
|
|
1715
|
+
if ((isExplicitPair || state.line === _line) && ch === 58) {
|
|
1716
|
+
isPair = true;
|
|
1717
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1718
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1719
|
+
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1720
|
+
valueNode = state.result;
|
|
1721
|
+
}
|
|
1722
|
+
if (isMapping) {
|
|
1723
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
|
|
1724
|
+
} else if (isPair) {
|
|
1725
|
+
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
|
|
1726
|
+
} else {
|
|
1727
|
+
_result.push(keyNode);
|
|
1728
|
+
}
|
|
1729
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1730
|
+
ch = state.input.charCodeAt(state.position);
|
|
1731
|
+
if (ch === 44) {
|
|
1732
|
+
readNext = true;
|
|
1733
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1734
|
+
} else {
|
|
1735
|
+
readNext = false;
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
throwError(state, "unexpected end of the stream within a flow collection");
|
|
1739
|
+
}
|
|
1740
|
+
function readBlockScalar(state, nodeIndent) {
|
|
1741
|
+
var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
|
|
1742
|
+
ch = state.input.charCodeAt(state.position);
|
|
1743
|
+
if (ch === 124) {
|
|
1744
|
+
folding = false;
|
|
1745
|
+
} else if (ch === 62) {
|
|
1746
|
+
folding = true;
|
|
1747
|
+
} else {
|
|
1748
|
+
return false;
|
|
1749
|
+
}
|
|
1750
|
+
state.kind = "scalar";
|
|
1751
|
+
state.result = "";
|
|
1752
|
+
while (ch !== 0) {
|
|
1753
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1754
|
+
if (ch === 43 || ch === 45) {
|
|
1755
|
+
if (CHOMPING_CLIP === chomping) {
|
|
1756
|
+
chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
1757
|
+
} else {
|
|
1758
|
+
throwError(state, "repeat of a chomping mode identifier");
|
|
1759
|
+
}
|
|
1760
|
+
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
|
1761
|
+
if (tmp === 0) {
|
|
1762
|
+
throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
1763
|
+
} else if (!detectedIndent) {
|
|
1764
|
+
textIndent = nodeIndent + tmp - 1;
|
|
1765
|
+
detectedIndent = true;
|
|
1766
|
+
} else {
|
|
1767
|
+
throwError(state, "repeat of an indentation width identifier");
|
|
1768
|
+
}
|
|
1769
|
+
} else {
|
|
1770
|
+
break;
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
if (is_WHITE_SPACE(ch)) {
|
|
1774
|
+
do {
|
|
1775
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1776
|
+
} while (is_WHITE_SPACE(ch));
|
|
1777
|
+
if (ch === 35) {
|
|
1778
|
+
do {
|
|
1779
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1780
|
+
} while (!is_EOL(ch) && ch !== 0);
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
while (ch !== 0) {
|
|
1784
|
+
readLineBreak(state);
|
|
1785
|
+
state.lineIndent = 0;
|
|
1786
|
+
ch = state.input.charCodeAt(state.position);
|
|
1787
|
+
while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
|
|
1788
|
+
state.lineIndent++;
|
|
1789
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1790
|
+
}
|
|
1791
|
+
if (!detectedIndent && state.lineIndent > textIndent) {
|
|
1792
|
+
textIndent = state.lineIndent;
|
|
1793
|
+
}
|
|
1794
|
+
if (is_EOL(ch)) {
|
|
1795
|
+
emptyLines++;
|
|
1796
|
+
continue;
|
|
1797
|
+
}
|
|
1798
|
+
if (state.lineIndent < textIndent) {
|
|
1799
|
+
if (chomping === CHOMPING_KEEP) {
|
|
1800
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1801
|
+
} else if (chomping === CHOMPING_CLIP) {
|
|
1802
|
+
if (didReadContent) {
|
|
1803
|
+
state.result += "\n";
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
break;
|
|
1807
|
+
}
|
|
1808
|
+
if (folding) {
|
|
1809
|
+
if (is_WHITE_SPACE(ch)) {
|
|
1810
|
+
atMoreIndented = true;
|
|
1811
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1812
|
+
} else if (atMoreIndented) {
|
|
1813
|
+
atMoreIndented = false;
|
|
1814
|
+
state.result += common.repeat("\n", emptyLines + 1);
|
|
1815
|
+
} else if (emptyLines === 0) {
|
|
1816
|
+
if (didReadContent) {
|
|
1817
|
+
state.result += " ";
|
|
1818
|
+
}
|
|
1819
|
+
} else {
|
|
1820
|
+
state.result += common.repeat("\n", emptyLines);
|
|
1821
|
+
}
|
|
1822
|
+
} else {
|
|
1823
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1824
|
+
}
|
|
1825
|
+
didReadContent = true;
|
|
1826
|
+
detectedIndent = true;
|
|
1827
|
+
emptyLines = 0;
|
|
1828
|
+
captureStart = state.position;
|
|
1829
|
+
while (!is_EOL(ch) && ch !== 0) {
|
|
1830
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1831
|
+
}
|
|
1832
|
+
captureSegment(state, captureStart, state.position, false);
|
|
1833
|
+
}
|
|
1834
|
+
return true;
|
|
1835
|
+
}
|
|
1836
|
+
function readBlockSequence(state, nodeIndent) {
|
|
1837
|
+
var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
|
|
1838
|
+
if (state.firstTabInLine !== -1) return false;
|
|
1839
|
+
if (state.anchor !== null) {
|
|
1840
|
+
state.anchorMap[state.anchor] = _result;
|
|
1841
|
+
}
|
|
1842
|
+
ch = state.input.charCodeAt(state.position);
|
|
1843
|
+
while (ch !== 0) {
|
|
1844
|
+
if (state.firstTabInLine !== -1) {
|
|
1845
|
+
state.position = state.firstTabInLine;
|
|
1846
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
1847
|
+
}
|
|
1848
|
+
if (ch !== 45) {
|
|
1849
|
+
break;
|
|
1850
|
+
}
|
|
1851
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1852
|
+
if (!is_WS_OR_EOL(following)) {
|
|
1853
|
+
break;
|
|
1854
|
+
}
|
|
1855
|
+
detected = true;
|
|
1856
|
+
state.position++;
|
|
1857
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
1858
|
+
if (state.lineIndent <= nodeIndent) {
|
|
1859
|
+
_result.push(null);
|
|
1860
|
+
ch = state.input.charCodeAt(state.position);
|
|
1861
|
+
continue;
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
_line = state.line;
|
|
1865
|
+
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|
1866
|
+
_result.push(state.result);
|
|
1867
|
+
skipSeparationSpace(state, true, -1);
|
|
1868
|
+
ch = state.input.charCodeAt(state.position);
|
|
1869
|
+
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1870
|
+
throwError(state, "bad indentation of a sequence entry");
|
|
1871
|
+
} else if (state.lineIndent < nodeIndent) {
|
|
1872
|
+
break;
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
if (detected) {
|
|
1876
|
+
state.tag = _tag;
|
|
1877
|
+
state.anchor = _anchor;
|
|
1878
|
+
state.kind = "sequence";
|
|
1879
|
+
state.result = _result;
|
|
1880
|
+
return true;
|
|
1881
|
+
}
|
|
1882
|
+
return false;
|
|
1883
|
+
}
|
|
1884
|
+
function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
1885
|
+
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;
|
|
1886
|
+
if (state.firstTabInLine !== -1) return false;
|
|
1887
|
+
if (state.anchor !== null) {
|
|
1888
|
+
state.anchorMap[state.anchor] = _result;
|
|
1889
|
+
}
|
|
1890
|
+
ch = state.input.charCodeAt(state.position);
|
|
1891
|
+
while (ch !== 0) {
|
|
1892
|
+
if (!atExplicitKey && state.firstTabInLine !== -1) {
|
|
1893
|
+
state.position = state.firstTabInLine;
|
|
1894
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
1895
|
+
}
|
|
1896
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1897
|
+
_line = state.line;
|
|
1898
|
+
if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
|
|
1899
|
+
if (ch === 63) {
|
|
1900
|
+
if (atExplicitKey) {
|
|
1901
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1902
|
+
keyTag = keyNode = valueNode = null;
|
|
1903
|
+
}
|
|
1904
|
+
detected = true;
|
|
1905
|
+
atExplicitKey = true;
|
|
1906
|
+
allowCompact = true;
|
|
1907
|
+
} else if (atExplicitKey) {
|
|
1908
|
+
atExplicitKey = false;
|
|
1909
|
+
allowCompact = true;
|
|
1910
|
+
} else {
|
|
1911
|
+
throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
|
|
1912
|
+
}
|
|
1913
|
+
state.position += 1;
|
|
1914
|
+
ch = following;
|
|
1915
|
+
} else {
|
|
1916
|
+
_keyLine = state.line;
|
|
1917
|
+
_keyLineStart = state.lineStart;
|
|
1918
|
+
_keyPos = state.position;
|
|
1919
|
+
if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
|
1920
|
+
break;
|
|
1921
|
+
}
|
|
1922
|
+
if (state.line === _line) {
|
|
1923
|
+
ch = state.input.charCodeAt(state.position);
|
|
1924
|
+
while (is_WHITE_SPACE(ch)) {
|
|
1925
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1926
|
+
}
|
|
1927
|
+
if (ch === 58) {
|
|
1928
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1929
|
+
if (!is_WS_OR_EOL(ch)) {
|
|
1930
|
+
throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
1931
|
+
}
|
|
1932
|
+
if (atExplicitKey) {
|
|
1933
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1934
|
+
keyTag = keyNode = valueNode = null;
|
|
1935
|
+
}
|
|
1936
|
+
detected = true;
|
|
1937
|
+
atExplicitKey = false;
|
|
1938
|
+
allowCompact = false;
|
|
1939
|
+
keyTag = state.tag;
|
|
1940
|
+
keyNode = state.result;
|
|
1941
|
+
} else if (detected) {
|
|
1942
|
+
throwError(state, "can not read an implicit mapping pair; a colon is missed");
|
|
1943
|
+
} else {
|
|
1944
|
+
state.tag = _tag;
|
|
1945
|
+
state.anchor = _anchor;
|
|
1946
|
+
return true;
|
|
1947
|
+
}
|
|
1948
|
+
} else if (detected) {
|
|
1949
|
+
throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
1950
|
+
} else {
|
|
1951
|
+
state.tag = _tag;
|
|
1952
|
+
state.anchor = _anchor;
|
|
1953
|
+
return true;
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
if (state.line === _line || state.lineIndent > nodeIndent) {
|
|
1957
|
+
if (atExplicitKey) {
|
|
1958
|
+
_keyLine = state.line;
|
|
1959
|
+
_keyLineStart = state.lineStart;
|
|
1960
|
+
_keyPos = state.position;
|
|
1961
|
+
}
|
|
1962
|
+
if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
|
1963
|
+
if (atExplicitKey) {
|
|
1964
|
+
keyNode = state.result;
|
|
1965
|
+
} else {
|
|
1966
|
+
valueNode = state.result;
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
if (!atExplicitKey) {
|
|
1970
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
|
|
1971
|
+
keyTag = keyNode = valueNode = null;
|
|
1972
|
+
}
|
|
1973
|
+
skipSeparationSpace(state, true, -1);
|
|
1974
|
+
ch = state.input.charCodeAt(state.position);
|
|
1975
|
+
}
|
|
1976
|
+
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1977
|
+
throwError(state, "bad indentation of a mapping entry");
|
|
1978
|
+
} else if (state.lineIndent < nodeIndent) {
|
|
1979
|
+
break;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
if (atExplicitKey) {
|
|
1983
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1984
|
+
}
|
|
1985
|
+
if (detected) {
|
|
1986
|
+
state.tag = _tag;
|
|
1987
|
+
state.anchor = _anchor;
|
|
1988
|
+
state.kind = "mapping";
|
|
1989
|
+
state.result = _result;
|
|
1990
|
+
}
|
|
1991
|
+
return detected;
|
|
1992
|
+
}
|
|
1993
|
+
function readTagProperty(state) {
|
|
1994
|
+
var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
|
|
1995
|
+
ch = state.input.charCodeAt(state.position);
|
|
1996
|
+
if (ch !== 33) return false;
|
|
1997
|
+
if (state.tag !== null) {
|
|
1998
|
+
throwError(state, "duplication of a tag property");
|
|
1999
|
+
}
|
|
2000
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2001
|
+
if (ch === 60) {
|
|
2002
|
+
isVerbatim = true;
|
|
2003
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2004
|
+
} else if (ch === 33) {
|
|
2005
|
+
isNamed = true;
|
|
2006
|
+
tagHandle = "!!";
|
|
2007
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2008
|
+
} else {
|
|
2009
|
+
tagHandle = "!";
|
|
2010
|
+
}
|
|
2011
|
+
_position = state.position;
|
|
2012
|
+
if (isVerbatim) {
|
|
2013
|
+
do {
|
|
2014
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2015
|
+
} while (ch !== 0 && ch !== 62);
|
|
2016
|
+
if (state.position < state.length) {
|
|
2017
|
+
tagName = state.input.slice(_position, state.position);
|
|
2018
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2019
|
+
} else {
|
|
2020
|
+
throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
2021
|
+
}
|
|
2022
|
+
} else {
|
|
2023
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2024
|
+
if (ch === 33) {
|
|
2025
|
+
if (!isNamed) {
|
|
2026
|
+
tagHandle = state.input.slice(_position - 1, state.position + 1);
|
|
2027
|
+
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
2028
|
+
throwError(state, "named tag handle cannot contain such characters");
|
|
2029
|
+
}
|
|
2030
|
+
isNamed = true;
|
|
2031
|
+
_position = state.position + 1;
|
|
2032
|
+
} else {
|
|
2033
|
+
throwError(state, "tag suffix cannot contain exclamation marks");
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2037
|
+
}
|
|
2038
|
+
tagName = state.input.slice(_position, state.position);
|
|
2039
|
+
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
2040
|
+
throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
|
2044
|
+
throwError(state, "tag name cannot contain such characters: " + tagName);
|
|
2045
|
+
}
|
|
2046
|
+
try {
|
|
2047
|
+
tagName = decodeURIComponent(tagName);
|
|
2048
|
+
} catch (err) {
|
|
2049
|
+
throwError(state, "tag name is malformed: " + tagName);
|
|
2050
|
+
}
|
|
2051
|
+
if (isVerbatim) {
|
|
2052
|
+
state.tag = tagName;
|
|
2053
|
+
} else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
|
|
2054
|
+
state.tag = state.tagMap[tagHandle] + tagName;
|
|
2055
|
+
} else if (tagHandle === "!") {
|
|
2056
|
+
state.tag = "!" + tagName;
|
|
2057
|
+
} else if (tagHandle === "!!") {
|
|
2058
|
+
state.tag = "tag:yaml.org,2002:" + tagName;
|
|
2059
|
+
} else {
|
|
2060
|
+
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
|
2061
|
+
}
|
|
2062
|
+
return true;
|
|
2063
|
+
}
|
|
2064
|
+
function readAnchorProperty(state) {
|
|
2065
|
+
var _position, ch;
|
|
2066
|
+
ch = state.input.charCodeAt(state.position);
|
|
2067
|
+
if (ch !== 38) return false;
|
|
2068
|
+
if (state.anchor !== null) {
|
|
2069
|
+
throwError(state, "duplication of an anchor property");
|
|
2070
|
+
}
|
|
2071
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2072
|
+
_position = state.position;
|
|
2073
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
2074
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2075
|
+
}
|
|
2076
|
+
if (state.position === _position) {
|
|
2077
|
+
throwError(state, "name of an anchor node must contain at least one character");
|
|
2078
|
+
}
|
|
2079
|
+
state.anchor = state.input.slice(_position, state.position);
|
|
2080
|
+
return true;
|
|
2081
|
+
}
|
|
2082
|
+
function readAlias(state) {
|
|
2083
|
+
var _position, alias, ch;
|
|
2084
|
+
ch = state.input.charCodeAt(state.position);
|
|
2085
|
+
if (ch !== 42) return false;
|
|
2086
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2087
|
+
_position = state.position;
|
|
2088
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
2089
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2090
|
+
}
|
|
2091
|
+
if (state.position === _position) {
|
|
2092
|
+
throwError(state, "name of an alias node must contain at least one character");
|
|
2093
|
+
}
|
|
2094
|
+
alias = state.input.slice(_position, state.position);
|
|
2095
|
+
if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
|
|
2096
|
+
throwError(state, 'unidentified alias "' + alias + '"');
|
|
2097
|
+
}
|
|
2098
|
+
state.result = state.anchorMap[alias];
|
|
2099
|
+
skipSeparationSpace(state, true, -1);
|
|
2100
|
+
return true;
|
|
2101
|
+
}
|
|
2102
|
+
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
|
2103
|
+
var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type2, flowIndent, blockIndent;
|
|
2104
|
+
if (state.listener !== null) {
|
|
2105
|
+
state.listener("open", state);
|
|
2106
|
+
}
|
|
2107
|
+
state.tag = null;
|
|
2108
|
+
state.anchor = null;
|
|
2109
|
+
state.kind = null;
|
|
2110
|
+
state.result = null;
|
|
2111
|
+
allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
|
|
2112
|
+
if (allowToSeek) {
|
|
2113
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
2114
|
+
atNewLine = true;
|
|
2115
|
+
if (state.lineIndent > parentIndent) {
|
|
2116
|
+
indentStatus = 1;
|
|
2117
|
+
} else if (state.lineIndent === parentIndent) {
|
|
2118
|
+
indentStatus = 0;
|
|
2119
|
+
} else if (state.lineIndent < parentIndent) {
|
|
2120
|
+
indentStatus = -1;
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
if (indentStatus === 1) {
|
|
2125
|
+
while (readTagProperty(state) || readAnchorProperty(state)) {
|
|
2126
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
2127
|
+
atNewLine = true;
|
|
2128
|
+
allowBlockCollections = allowBlockStyles;
|
|
2129
|
+
if (state.lineIndent > parentIndent) {
|
|
2130
|
+
indentStatus = 1;
|
|
2131
|
+
} else if (state.lineIndent === parentIndent) {
|
|
2132
|
+
indentStatus = 0;
|
|
2133
|
+
} else if (state.lineIndent < parentIndent) {
|
|
2134
|
+
indentStatus = -1;
|
|
2135
|
+
}
|
|
2136
|
+
} else {
|
|
2137
|
+
allowBlockCollections = false;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
if (allowBlockCollections) {
|
|
2142
|
+
allowBlockCollections = atNewLine || allowCompact;
|
|
2143
|
+
}
|
|
2144
|
+
if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
|
2145
|
+
if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
|
2146
|
+
flowIndent = parentIndent;
|
|
2147
|
+
} else {
|
|
2148
|
+
flowIndent = parentIndent + 1;
|
|
2149
|
+
}
|
|
2150
|
+
blockIndent = state.position - state.lineStart;
|
|
2151
|
+
if (indentStatus === 1) {
|
|
2152
|
+
if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
|
|
2153
|
+
hasContent = true;
|
|
2154
|
+
} else {
|
|
2155
|
+
if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
|
|
2156
|
+
hasContent = true;
|
|
2157
|
+
} else if (readAlias(state)) {
|
|
2158
|
+
hasContent = true;
|
|
2159
|
+
if (state.tag !== null || state.anchor !== null) {
|
|
2160
|
+
throwError(state, "alias node should not have any properties");
|
|
2161
|
+
}
|
|
2162
|
+
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
|
2163
|
+
hasContent = true;
|
|
2164
|
+
if (state.tag === null) {
|
|
2165
|
+
state.tag = "?";
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
if (state.anchor !== null) {
|
|
2169
|
+
state.anchorMap[state.anchor] = state.result;
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
} else if (indentStatus === 0) {
|
|
2173
|
+
hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
if (state.tag === null) {
|
|
2177
|
+
if (state.anchor !== null) {
|
|
2178
|
+
state.anchorMap[state.anchor] = state.result;
|
|
2179
|
+
}
|
|
2180
|
+
} else if (state.tag === "?") {
|
|
2181
|
+
if (state.result !== null && state.kind !== "scalar") {
|
|
2182
|
+
throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
|
2183
|
+
}
|
|
2184
|
+
for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
|
|
2185
|
+
type2 = state.implicitTypes[typeIndex];
|
|
2186
|
+
if (type2.resolve(state.result)) {
|
|
2187
|
+
state.result = type2.construct(state.result);
|
|
2188
|
+
state.tag = type2.tag;
|
|
2189
|
+
if (state.anchor !== null) {
|
|
2190
|
+
state.anchorMap[state.anchor] = state.result;
|
|
2191
|
+
}
|
|
2192
|
+
break;
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
} else if (state.tag !== "!") {
|
|
2196
|
+
if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
|
|
2197
|
+
type2 = state.typeMap[state.kind || "fallback"][state.tag];
|
|
2198
|
+
} else {
|
|
2199
|
+
type2 = null;
|
|
2200
|
+
typeList = state.typeMap.multi[state.kind || "fallback"];
|
|
2201
|
+
for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) {
|
|
2202
|
+
if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
|
|
2203
|
+
type2 = typeList[typeIndex];
|
|
2204
|
+
break;
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
if (!type2) {
|
|
2209
|
+
throwError(state, "unknown tag !<" + state.tag + ">");
|
|
2210
|
+
}
|
|
2211
|
+
if (state.result !== null && type2.kind !== state.kind) {
|
|
2212
|
+
throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"');
|
|
2213
|
+
}
|
|
2214
|
+
if (!type2.resolve(state.result, state.tag)) {
|
|
2215
|
+
throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
|
|
2216
|
+
} else {
|
|
2217
|
+
state.result = type2.construct(state.result, state.tag);
|
|
2218
|
+
if (state.anchor !== null) {
|
|
2219
|
+
state.anchorMap[state.anchor] = state.result;
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
if (state.listener !== null) {
|
|
2224
|
+
state.listener("close", state);
|
|
2225
|
+
}
|
|
2226
|
+
return state.tag !== null || state.anchor !== null || hasContent;
|
|
2227
|
+
}
|
|
2228
|
+
function readDocument(state) {
|
|
2229
|
+
var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
|
|
2230
|
+
state.version = null;
|
|
2231
|
+
state.checkLineBreaks = state.legacy;
|
|
2232
|
+
state.tagMap = /* @__PURE__ */ Object.create(null);
|
|
2233
|
+
state.anchorMap = /* @__PURE__ */ Object.create(null);
|
|
2234
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
2235
|
+
skipSeparationSpace(state, true, -1);
|
|
2236
|
+
ch = state.input.charCodeAt(state.position);
|
|
2237
|
+
if (state.lineIndent > 0 || ch !== 37) {
|
|
2238
|
+
break;
|
|
2239
|
+
}
|
|
2240
|
+
hasDirectives = true;
|
|
2241
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2242
|
+
_position = state.position;
|
|
2243
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2244
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2245
|
+
}
|
|
2246
|
+
directiveName = state.input.slice(_position, state.position);
|
|
2247
|
+
directiveArgs = [];
|
|
2248
|
+
if (directiveName.length < 1) {
|
|
2249
|
+
throwError(state, "directive name must not be less than one character in length");
|
|
2250
|
+
}
|
|
2251
|
+
while (ch !== 0) {
|
|
2252
|
+
while (is_WHITE_SPACE(ch)) {
|
|
2253
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2254
|
+
}
|
|
2255
|
+
if (ch === 35) {
|
|
2256
|
+
do {
|
|
2257
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2258
|
+
} while (ch !== 0 && !is_EOL(ch));
|
|
2259
|
+
break;
|
|
2260
|
+
}
|
|
2261
|
+
if (is_EOL(ch)) break;
|
|
2262
|
+
_position = state.position;
|
|
2263
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2264
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2265
|
+
}
|
|
2266
|
+
directiveArgs.push(state.input.slice(_position, state.position));
|
|
2267
|
+
}
|
|
2268
|
+
if (ch !== 0) readLineBreak(state);
|
|
2269
|
+
if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
|
|
2270
|
+
directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
|
2271
|
+
} else {
|
|
2272
|
+
throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
skipSeparationSpace(state, true, -1);
|
|
2276
|
+
if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
|
|
2277
|
+
state.position += 3;
|
|
2278
|
+
skipSeparationSpace(state, true, -1);
|
|
2279
|
+
} else if (hasDirectives) {
|
|
2280
|
+
throwError(state, "directives end mark is expected");
|
|
2281
|
+
}
|
|
2282
|
+
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
|
2283
|
+
skipSeparationSpace(state, true, -1);
|
|
2284
|
+
if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|
2285
|
+
throwWarning(state, "non-ASCII line breaks are interpreted as content");
|
|
2286
|
+
}
|
|
2287
|
+
state.documents.push(state.result);
|
|
2288
|
+
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
2289
|
+
if (state.input.charCodeAt(state.position) === 46) {
|
|
2290
|
+
state.position += 3;
|
|
2291
|
+
skipSeparationSpace(state, true, -1);
|
|
2292
|
+
}
|
|
2293
|
+
return;
|
|
2294
|
+
}
|
|
2295
|
+
if (state.position < state.length - 1) {
|
|
2296
|
+
throwError(state, "end of the stream or a document separator is expected");
|
|
2297
|
+
} else {
|
|
2298
|
+
return;
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
function loadDocuments(input, options) {
|
|
2302
|
+
input = String(input);
|
|
2303
|
+
options = options || {};
|
|
2304
|
+
if (input.length !== 0) {
|
|
2305
|
+
if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
|
|
2306
|
+
input += "\n";
|
|
2307
|
+
}
|
|
2308
|
+
if (input.charCodeAt(0) === 65279) {
|
|
2309
|
+
input = input.slice(1);
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
var state = new State$1(input, options);
|
|
2313
|
+
var nullpos = input.indexOf("\0");
|
|
2314
|
+
if (nullpos !== -1) {
|
|
2315
|
+
state.position = nullpos;
|
|
2316
|
+
throwError(state, "null byte is not allowed in input");
|
|
2317
|
+
}
|
|
2318
|
+
state.input += "\0";
|
|
2319
|
+
while (state.input.charCodeAt(state.position) === 32) {
|
|
2320
|
+
state.lineIndent += 1;
|
|
2321
|
+
state.position += 1;
|
|
2322
|
+
}
|
|
2323
|
+
while (state.position < state.length - 1) {
|
|
2324
|
+
readDocument(state);
|
|
2325
|
+
}
|
|
2326
|
+
return state.documents;
|
|
2327
|
+
}
|
|
2328
|
+
function loadAll$1(input, iterator, options) {
|
|
2329
|
+
if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
|
|
2330
|
+
options = iterator;
|
|
2331
|
+
iterator = null;
|
|
2332
|
+
}
|
|
2333
|
+
var documents = loadDocuments(input, options);
|
|
2334
|
+
if (typeof iterator !== "function") {
|
|
2335
|
+
return documents;
|
|
2336
|
+
}
|
|
2337
|
+
for (var index = 0, length = documents.length; index < length; index += 1) {
|
|
2338
|
+
iterator(documents[index]);
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
function load$1(input, options) {
|
|
2342
|
+
var documents = loadDocuments(input, options);
|
|
2343
|
+
if (documents.length === 0) {
|
|
2344
|
+
return void 0;
|
|
2345
|
+
} else if (documents.length === 1) {
|
|
2346
|
+
return documents[0];
|
|
2347
|
+
}
|
|
2348
|
+
throw new exception("expected a single document in the stream, but found more");
|
|
2349
|
+
}
|
|
2350
|
+
var loadAll_1 = loadAll$1;
|
|
2351
|
+
var load_1 = load$1;
|
|
2352
|
+
var loader = {
|
|
2353
|
+
loadAll: loadAll_1,
|
|
2354
|
+
load: load_1
|
|
2355
|
+
};
|
|
2356
|
+
var _toString = Object.prototype.toString;
|
|
2357
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2358
|
+
var CHAR_BOM = 65279;
|
|
2359
|
+
var CHAR_TAB = 9;
|
|
2360
|
+
var CHAR_LINE_FEED = 10;
|
|
2361
|
+
var CHAR_CARRIAGE_RETURN = 13;
|
|
2362
|
+
var CHAR_SPACE = 32;
|
|
2363
|
+
var CHAR_EXCLAMATION = 33;
|
|
2364
|
+
var CHAR_DOUBLE_QUOTE = 34;
|
|
2365
|
+
var CHAR_SHARP = 35;
|
|
2366
|
+
var CHAR_PERCENT = 37;
|
|
2367
|
+
var CHAR_AMPERSAND = 38;
|
|
2368
|
+
var CHAR_SINGLE_QUOTE = 39;
|
|
2369
|
+
var CHAR_ASTERISK = 42;
|
|
2370
|
+
var CHAR_COMMA = 44;
|
|
2371
|
+
var CHAR_MINUS = 45;
|
|
2372
|
+
var CHAR_COLON = 58;
|
|
2373
|
+
var CHAR_EQUALS = 61;
|
|
2374
|
+
var CHAR_GREATER_THAN = 62;
|
|
2375
|
+
var CHAR_QUESTION = 63;
|
|
2376
|
+
var CHAR_COMMERCIAL_AT = 64;
|
|
2377
|
+
var CHAR_LEFT_SQUARE_BRACKET = 91;
|
|
2378
|
+
var CHAR_RIGHT_SQUARE_BRACKET = 93;
|
|
2379
|
+
var CHAR_GRAVE_ACCENT = 96;
|
|
2380
|
+
var CHAR_LEFT_CURLY_BRACKET = 123;
|
|
2381
|
+
var CHAR_VERTICAL_LINE = 124;
|
|
2382
|
+
var CHAR_RIGHT_CURLY_BRACKET = 125;
|
|
2383
|
+
var ESCAPE_SEQUENCES = {};
|
|
2384
|
+
ESCAPE_SEQUENCES[0] = "\\0";
|
|
2385
|
+
ESCAPE_SEQUENCES[7] = "\\a";
|
|
2386
|
+
ESCAPE_SEQUENCES[8] = "\\b";
|
|
2387
|
+
ESCAPE_SEQUENCES[9] = "\\t";
|
|
2388
|
+
ESCAPE_SEQUENCES[10] = "\\n";
|
|
2389
|
+
ESCAPE_SEQUENCES[11] = "\\v";
|
|
2390
|
+
ESCAPE_SEQUENCES[12] = "\\f";
|
|
2391
|
+
ESCAPE_SEQUENCES[13] = "\\r";
|
|
2392
|
+
ESCAPE_SEQUENCES[27] = "\\e";
|
|
2393
|
+
ESCAPE_SEQUENCES[34] = '\\"';
|
|
2394
|
+
ESCAPE_SEQUENCES[92] = "\\\\";
|
|
2395
|
+
ESCAPE_SEQUENCES[133] = "\\N";
|
|
2396
|
+
ESCAPE_SEQUENCES[160] = "\\_";
|
|
2397
|
+
ESCAPE_SEQUENCES[8232] = "\\L";
|
|
2398
|
+
ESCAPE_SEQUENCES[8233] = "\\P";
|
|
2399
|
+
var DEPRECATED_BOOLEANS_SYNTAX = [
|
|
2400
|
+
"y",
|
|
2401
|
+
"Y",
|
|
2402
|
+
"yes",
|
|
2403
|
+
"Yes",
|
|
2404
|
+
"YES",
|
|
2405
|
+
"on",
|
|
2406
|
+
"On",
|
|
2407
|
+
"ON",
|
|
2408
|
+
"n",
|
|
2409
|
+
"N",
|
|
2410
|
+
"no",
|
|
2411
|
+
"No",
|
|
2412
|
+
"NO",
|
|
2413
|
+
"off",
|
|
2414
|
+
"Off",
|
|
2415
|
+
"OFF"
|
|
2416
|
+
];
|
|
2417
|
+
var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
|
|
2418
|
+
function compileStyleMap(schema2, map2) {
|
|
2419
|
+
var result, keys, index, length, tag, style, type2;
|
|
2420
|
+
if (map2 === null) return {};
|
|
2421
|
+
result = {};
|
|
2422
|
+
keys = Object.keys(map2);
|
|
2423
|
+
for (index = 0, length = keys.length; index < length; index += 1) {
|
|
2424
|
+
tag = keys[index];
|
|
2425
|
+
style = String(map2[tag]);
|
|
2426
|
+
if (tag.slice(0, 2) === "!!") {
|
|
2427
|
+
tag = "tag:yaml.org,2002:" + tag.slice(2);
|
|
2428
|
+
}
|
|
2429
|
+
type2 = schema2.compiledTypeMap["fallback"][tag];
|
|
2430
|
+
if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) {
|
|
2431
|
+
style = type2.styleAliases[style];
|
|
2432
|
+
}
|
|
2433
|
+
result[tag] = style;
|
|
2434
|
+
}
|
|
2435
|
+
return result;
|
|
2436
|
+
}
|
|
2437
|
+
function encodeHex(character) {
|
|
2438
|
+
var string, handle, length;
|
|
2439
|
+
string = character.toString(16).toUpperCase();
|
|
2440
|
+
if (character <= 255) {
|
|
2441
|
+
handle = "x";
|
|
2442
|
+
length = 2;
|
|
2443
|
+
} else if (character <= 65535) {
|
|
2444
|
+
handle = "u";
|
|
2445
|
+
length = 4;
|
|
2446
|
+
} else if (character <= 4294967295) {
|
|
2447
|
+
handle = "U";
|
|
2448
|
+
length = 8;
|
|
2449
|
+
} else {
|
|
2450
|
+
throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
|
|
2451
|
+
}
|
|
2452
|
+
return "\\" + handle + common.repeat("0", length - string.length) + string;
|
|
2453
|
+
}
|
|
2454
|
+
var QUOTING_TYPE_SINGLE = 1;
|
|
2455
|
+
var QUOTING_TYPE_DOUBLE = 2;
|
|
2456
|
+
function State(options) {
|
|
2457
|
+
this.schema = options["schema"] || _default;
|
|
2458
|
+
this.indent = Math.max(1, options["indent"] || 2);
|
|
2459
|
+
this.noArrayIndent = options["noArrayIndent"] || false;
|
|
2460
|
+
this.skipInvalid = options["skipInvalid"] || false;
|
|
2461
|
+
this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
|
|
2462
|
+
this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
|
|
2463
|
+
this.sortKeys = options["sortKeys"] || false;
|
|
2464
|
+
this.lineWidth = options["lineWidth"] || 80;
|
|
2465
|
+
this.noRefs = options["noRefs"] || false;
|
|
2466
|
+
this.noCompatMode = options["noCompatMode"] || false;
|
|
2467
|
+
this.condenseFlow = options["condenseFlow"] || false;
|
|
2468
|
+
this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
|
|
2469
|
+
this.forceQuotes = options["forceQuotes"] || false;
|
|
2470
|
+
this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
|
|
2471
|
+
this.implicitTypes = this.schema.compiledImplicit;
|
|
2472
|
+
this.explicitTypes = this.schema.compiledExplicit;
|
|
2473
|
+
this.tag = null;
|
|
2474
|
+
this.result = "";
|
|
2475
|
+
this.duplicates = [];
|
|
2476
|
+
this.usedDuplicates = null;
|
|
2477
|
+
}
|
|
2478
|
+
function indentString(string, spaces) {
|
|
2479
|
+
var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
|
|
2480
|
+
while (position < length) {
|
|
2481
|
+
next = string.indexOf("\n", position);
|
|
2482
|
+
if (next === -1) {
|
|
2483
|
+
line = string.slice(position);
|
|
2484
|
+
position = length;
|
|
2485
|
+
} else {
|
|
2486
|
+
line = string.slice(position, next + 1);
|
|
2487
|
+
position = next + 1;
|
|
2488
|
+
}
|
|
2489
|
+
if (line.length && line !== "\n") result += ind;
|
|
2490
|
+
result += line;
|
|
2491
|
+
}
|
|
2492
|
+
return result;
|
|
2493
|
+
}
|
|
2494
|
+
function generateNextLine(state, level) {
|
|
2495
|
+
return "\n" + common.repeat(" ", state.indent * level);
|
|
2496
|
+
}
|
|
2497
|
+
function testImplicitResolving(state, str2) {
|
|
2498
|
+
var index, length, type2;
|
|
2499
|
+
for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
|
|
2500
|
+
type2 = state.implicitTypes[index];
|
|
2501
|
+
if (type2.resolve(str2)) {
|
|
2502
|
+
return true;
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
return false;
|
|
2506
|
+
}
|
|
2507
|
+
function isWhitespace(c) {
|
|
2508
|
+
return c === CHAR_SPACE || c === CHAR_TAB;
|
|
2509
|
+
}
|
|
2510
|
+
function isPrintable(c) {
|
|
2511
|
+
return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111;
|
|
2512
|
+
}
|
|
2513
|
+
function isNsCharOrWhitespace(c) {
|
|
2514
|
+
return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
|
|
2515
|
+
}
|
|
2516
|
+
function isPlainSafe(c, prev, inblock) {
|
|
2517
|
+
var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
|
|
2518
|
+
var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
|
|
2519
|
+
return (
|
|
2520
|
+
// ns-plain-safe
|
|
2521
|
+
(inblock ? (
|
|
2522
|
+
// c = flow-in
|
|
2523
|
+
cIsNsCharOrWhitespace
|
|
2524
|
+
) : 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
|
|
2525
|
+
);
|
|
2526
|
+
}
|
|
2527
|
+
function isPlainSafeFirst(c) {
|
|
2528
|
+
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;
|
|
2529
|
+
}
|
|
2530
|
+
function isPlainSafeLast(c) {
|
|
2531
|
+
return !isWhitespace(c) && c !== CHAR_COLON;
|
|
2532
|
+
}
|
|
2533
|
+
function codePointAt(string, pos) {
|
|
2534
|
+
var first = string.charCodeAt(pos), second;
|
|
2535
|
+
if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
|
|
2536
|
+
second = string.charCodeAt(pos + 1);
|
|
2537
|
+
if (second >= 56320 && second <= 57343) {
|
|
2538
|
+
return (first - 55296) * 1024 + second - 56320 + 65536;
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
return first;
|
|
2542
|
+
}
|
|
2543
|
+
function needIndentIndicator(string) {
|
|
2544
|
+
var leadingSpaceRe = /^\n* /;
|
|
2545
|
+
return leadingSpaceRe.test(string);
|
|
2546
|
+
}
|
|
2547
|
+
var STYLE_PLAIN = 1;
|
|
2548
|
+
var STYLE_SINGLE = 2;
|
|
2549
|
+
var STYLE_LITERAL = 3;
|
|
2550
|
+
var STYLE_FOLDED = 4;
|
|
2551
|
+
var STYLE_DOUBLE = 5;
|
|
2552
|
+
function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
|
|
2553
|
+
var i;
|
|
2554
|
+
var char = 0;
|
|
2555
|
+
var prevChar = null;
|
|
2556
|
+
var hasLineBreak = false;
|
|
2557
|
+
var hasFoldableLine = false;
|
|
2558
|
+
var shouldTrackWidth = lineWidth !== -1;
|
|
2559
|
+
var previousLineBreak = -1;
|
|
2560
|
+
var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
|
|
2561
|
+
if (singleLineOnly || forceQuotes) {
|
|
2562
|
+
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2563
|
+
char = codePointAt(string, i);
|
|
2564
|
+
if (!isPrintable(char)) {
|
|
2565
|
+
return STYLE_DOUBLE;
|
|
2566
|
+
}
|
|
2567
|
+
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2568
|
+
prevChar = char;
|
|
2569
|
+
}
|
|
2570
|
+
} else {
|
|
2571
|
+
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2572
|
+
char = codePointAt(string, i);
|
|
2573
|
+
if (char === CHAR_LINE_FEED) {
|
|
2574
|
+
hasLineBreak = true;
|
|
2575
|
+
if (shouldTrackWidth) {
|
|
2576
|
+
hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
|
|
2577
|
+
i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
2578
|
+
previousLineBreak = i;
|
|
2579
|
+
}
|
|
2580
|
+
} else if (!isPrintable(char)) {
|
|
2581
|
+
return STYLE_DOUBLE;
|
|
2582
|
+
}
|
|
2583
|
+
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2584
|
+
prevChar = char;
|
|
2585
|
+
}
|
|
2586
|
+
hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
|
|
2587
|
+
}
|
|
2588
|
+
if (!hasLineBreak && !hasFoldableLine) {
|
|
2589
|
+
if (plain && !forceQuotes && !testAmbiguousType(string)) {
|
|
2590
|
+
return STYLE_PLAIN;
|
|
2591
|
+
}
|
|
2592
|
+
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2593
|
+
}
|
|
2594
|
+
if (indentPerLevel > 9 && needIndentIndicator(string)) {
|
|
2595
|
+
return STYLE_DOUBLE;
|
|
2596
|
+
}
|
|
2597
|
+
if (!forceQuotes) {
|
|
2598
|
+
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
|
2599
|
+
}
|
|
2600
|
+
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2601
|
+
}
|
|
2602
|
+
function writeScalar(state, string, level, iskey, inblock) {
|
|
2603
|
+
state.dump = (function() {
|
|
2604
|
+
if (string.length === 0) {
|
|
2605
|
+
return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
|
|
2606
|
+
}
|
|
2607
|
+
if (!state.noCompatMode) {
|
|
2608
|
+
if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
|
|
2609
|
+
return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
var indent = state.indent * Math.max(1, level);
|
|
2613
|
+
var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
|
|
2614
|
+
var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
|
|
2615
|
+
function testAmbiguity(string2) {
|
|
2616
|
+
return testImplicitResolving(state, string2);
|
|
2617
|
+
}
|
|
2618
|
+
switch (chooseScalarStyle(
|
|
2619
|
+
string,
|
|
2620
|
+
singleLineOnly,
|
|
2621
|
+
state.indent,
|
|
2622
|
+
lineWidth,
|
|
2623
|
+
testAmbiguity,
|
|
2624
|
+
state.quotingType,
|
|
2625
|
+
state.forceQuotes && !iskey,
|
|
2626
|
+
inblock
|
|
2627
|
+
)) {
|
|
2628
|
+
case STYLE_PLAIN:
|
|
2629
|
+
return string;
|
|
2630
|
+
case STYLE_SINGLE:
|
|
2631
|
+
return "'" + string.replace(/'/g, "''") + "'";
|
|
2632
|
+
case STYLE_LITERAL:
|
|
2633
|
+
return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
|
|
2634
|
+
case STYLE_FOLDED:
|
|
2635
|
+
return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
|
2636
|
+
case STYLE_DOUBLE:
|
|
2637
|
+
return '"' + escapeString(string) + '"';
|
|
2638
|
+
default:
|
|
2639
|
+
throw new exception("impossible error: invalid scalar style");
|
|
2640
|
+
}
|
|
2641
|
+
})();
|
|
2642
|
+
}
|
|
2643
|
+
function blockHeader(string, indentPerLevel) {
|
|
2644
|
+
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
2645
|
+
var clip = string[string.length - 1] === "\n";
|
|
2646
|
+
var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
|
|
2647
|
+
var chomp = keep ? "+" : clip ? "" : "-";
|
|
2648
|
+
return indentIndicator + chomp + "\n";
|
|
2649
|
+
}
|
|
2650
|
+
function dropEndingNewline(string) {
|
|
2651
|
+
return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
|
|
2652
|
+
}
|
|
2653
|
+
function foldString(string, width) {
|
|
2654
|
+
var lineRe = /(\n+)([^\n]*)/g;
|
|
2655
|
+
var result = (function() {
|
|
2656
|
+
var nextLF = string.indexOf("\n");
|
|
2657
|
+
nextLF = nextLF !== -1 ? nextLF : string.length;
|
|
2658
|
+
lineRe.lastIndex = nextLF;
|
|
2659
|
+
return foldLine(string.slice(0, nextLF), width);
|
|
2660
|
+
})();
|
|
2661
|
+
var prevMoreIndented = string[0] === "\n" || string[0] === " ";
|
|
2662
|
+
var moreIndented;
|
|
2663
|
+
var match;
|
|
2664
|
+
while (match = lineRe.exec(string)) {
|
|
2665
|
+
var prefix = match[1], line = match[2];
|
|
2666
|
+
moreIndented = line[0] === " ";
|
|
2667
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
2668
|
+
prevMoreIndented = moreIndented;
|
|
2669
|
+
}
|
|
2670
|
+
return result;
|
|
2671
|
+
}
|
|
2672
|
+
function foldLine(line, width) {
|
|
2673
|
+
if (line === "" || line[0] === " ") return line;
|
|
2674
|
+
var breakRe = / [^ ]/g;
|
|
2675
|
+
var match;
|
|
2676
|
+
var start = 0, end, curr = 0, next = 0;
|
|
2677
|
+
var result = "";
|
|
2678
|
+
while (match = breakRe.exec(line)) {
|
|
2679
|
+
next = match.index;
|
|
2680
|
+
if (next - start > width) {
|
|
2681
|
+
end = curr > start ? curr : next;
|
|
2682
|
+
result += "\n" + line.slice(start, end);
|
|
2683
|
+
start = end + 1;
|
|
2684
|
+
}
|
|
2685
|
+
curr = next;
|
|
2686
|
+
}
|
|
2687
|
+
result += "\n";
|
|
2688
|
+
if (line.length - start > width && curr > start) {
|
|
2689
|
+
result += line.slice(start, curr) + "\n" + line.slice(curr + 1);
|
|
2690
|
+
} else {
|
|
2691
|
+
result += line.slice(start);
|
|
2692
|
+
}
|
|
2693
|
+
return result.slice(1);
|
|
2694
|
+
}
|
|
2695
|
+
function escapeString(string) {
|
|
2696
|
+
var result = "";
|
|
2697
|
+
var char = 0;
|
|
2698
|
+
var escapeSeq;
|
|
2699
|
+
for (var i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2700
|
+
char = codePointAt(string, i);
|
|
2701
|
+
escapeSeq = ESCAPE_SEQUENCES[char];
|
|
2702
|
+
if (!escapeSeq && isPrintable(char)) {
|
|
2703
|
+
result += string[i];
|
|
2704
|
+
if (char >= 65536) result += string[i + 1];
|
|
2705
|
+
} else {
|
|
2706
|
+
result += escapeSeq || encodeHex(char);
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
return result;
|
|
2710
|
+
}
|
|
2711
|
+
function writeFlowSequence(state, level, object) {
|
|
2712
|
+
var _result = "", _tag = state.tag, index, length, value;
|
|
2713
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2714
|
+
value = object[index];
|
|
2715
|
+
if (state.replacer) {
|
|
2716
|
+
value = state.replacer.call(object, String(index), value);
|
|
2717
|
+
}
|
|
2718
|
+
if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
|
|
2719
|
+
if (_result !== "") _result += "," + (!state.condenseFlow ? " " : "");
|
|
2720
|
+
_result += state.dump;
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
state.tag = _tag;
|
|
2724
|
+
state.dump = "[" + _result + "]";
|
|
2725
|
+
}
|
|
2726
|
+
function writeBlockSequence(state, level, object, compact) {
|
|
2727
|
+
var _result = "", _tag = state.tag, index, length, value;
|
|
2728
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2729
|
+
value = object[index];
|
|
2730
|
+
if (state.replacer) {
|
|
2731
|
+
value = state.replacer.call(object, String(index), value);
|
|
2732
|
+
}
|
|
2733
|
+
if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
|
|
2734
|
+
if (!compact || _result !== "") {
|
|
2735
|
+
_result += generateNextLine(state, level);
|
|
2736
|
+
}
|
|
2737
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2738
|
+
_result += "-";
|
|
2739
|
+
} else {
|
|
2740
|
+
_result += "- ";
|
|
2741
|
+
}
|
|
2742
|
+
_result += state.dump;
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
state.tag = _tag;
|
|
2746
|
+
state.dump = _result || "[]";
|
|
2747
|
+
}
|
|
2748
|
+
function writeFlowMapping(state, level, object) {
|
|
2749
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
|
|
2750
|
+
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2751
|
+
pairBuffer = "";
|
|
2752
|
+
if (_result !== "") pairBuffer += ", ";
|
|
2753
|
+
if (state.condenseFlow) pairBuffer += '"';
|
|
2754
|
+
objectKey = objectKeyList[index];
|
|
2755
|
+
objectValue = object[objectKey];
|
|
2756
|
+
if (state.replacer) {
|
|
2757
|
+
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
2758
|
+
}
|
|
2759
|
+
if (!writeNode(state, level, objectKey, false, false)) {
|
|
2760
|
+
continue;
|
|
2761
|
+
}
|
|
2762
|
+
if (state.dump.length > 1024) pairBuffer += "? ";
|
|
2763
|
+
pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
|
|
2764
|
+
if (!writeNode(state, level, objectValue, false, false)) {
|
|
2765
|
+
continue;
|
|
2766
|
+
}
|
|
2767
|
+
pairBuffer += state.dump;
|
|
2768
|
+
_result += pairBuffer;
|
|
2769
|
+
}
|
|
2770
|
+
state.tag = _tag;
|
|
2771
|
+
state.dump = "{" + _result + "}";
|
|
2772
|
+
}
|
|
2773
|
+
function writeBlockMapping(state, level, object, compact) {
|
|
2774
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
|
|
2775
|
+
if (state.sortKeys === true) {
|
|
2776
|
+
objectKeyList.sort();
|
|
2777
|
+
} else if (typeof state.sortKeys === "function") {
|
|
2778
|
+
objectKeyList.sort(state.sortKeys);
|
|
2779
|
+
} else if (state.sortKeys) {
|
|
2780
|
+
throw new exception("sortKeys must be a boolean or a function");
|
|
2781
|
+
}
|
|
2782
|
+
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2783
|
+
pairBuffer = "";
|
|
2784
|
+
if (!compact || _result !== "") {
|
|
2785
|
+
pairBuffer += generateNextLine(state, level);
|
|
2786
|
+
}
|
|
2787
|
+
objectKey = objectKeyList[index];
|
|
2788
|
+
objectValue = object[objectKey];
|
|
2789
|
+
if (state.replacer) {
|
|
2790
|
+
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
2791
|
+
}
|
|
2792
|
+
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
|
2793
|
+
continue;
|
|
2794
|
+
}
|
|
2795
|
+
explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
|
|
2796
|
+
if (explicitPair) {
|
|
2797
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2798
|
+
pairBuffer += "?";
|
|
2799
|
+
} else {
|
|
2800
|
+
pairBuffer += "? ";
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
pairBuffer += state.dump;
|
|
2804
|
+
if (explicitPair) {
|
|
2805
|
+
pairBuffer += generateNextLine(state, level);
|
|
2806
|
+
}
|
|
2807
|
+
if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
|
|
2808
|
+
continue;
|
|
2809
|
+
}
|
|
2810
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2811
|
+
pairBuffer += ":";
|
|
2812
|
+
} else {
|
|
2813
|
+
pairBuffer += ": ";
|
|
2814
|
+
}
|
|
2815
|
+
pairBuffer += state.dump;
|
|
2816
|
+
_result += pairBuffer;
|
|
2817
|
+
}
|
|
2818
|
+
state.tag = _tag;
|
|
2819
|
+
state.dump = _result || "{}";
|
|
2820
|
+
}
|
|
2821
|
+
function detectType(state, object, explicit) {
|
|
2822
|
+
var _result, typeList, index, length, type2, style;
|
|
2823
|
+
typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
|
2824
|
+
for (index = 0, length = typeList.length; index < length; index += 1) {
|
|
2825
|
+
type2 = typeList[index];
|
|
2826
|
+
if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object === "object" && object instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object))) {
|
|
2827
|
+
if (explicit) {
|
|
2828
|
+
if (type2.multi && type2.representName) {
|
|
2829
|
+
state.tag = type2.representName(object);
|
|
2830
|
+
} else {
|
|
2831
|
+
state.tag = type2.tag;
|
|
2832
|
+
}
|
|
2833
|
+
} else {
|
|
2834
|
+
state.tag = "?";
|
|
2835
|
+
}
|
|
2836
|
+
if (type2.represent) {
|
|
2837
|
+
style = state.styleMap[type2.tag] || type2.defaultStyle;
|
|
2838
|
+
if (_toString.call(type2.represent) === "[object Function]") {
|
|
2839
|
+
_result = type2.represent(object, style);
|
|
2840
|
+
} else if (_hasOwnProperty.call(type2.represent, style)) {
|
|
2841
|
+
_result = type2.represent[style](object, style);
|
|
2842
|
+
} else {
|
|
2843
|
+
throw new exception("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style');
|
|
2844
|
+
}
|
|
2845
|
+
state.dump = _result;
|
|
2846
|
+
}
|
|
2847
|
+
return true;
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
return false;
|
|
2851
|
+
}
|
|
2852
|
+
function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
2853
|
+
state.tag = null;
|
|
2854
|
+
state.dump = object;
|
|
2855
|
+
if (!detectType(state, object, false)) {
|
|
2856
|
+
detectType(state, object, true);
|
|
2857
|
+
}
|
|
2858
|
+
var type2 = _toString.call(state.dump);
|
|
2859
|
+
var inblock = block;
|
|
2860
|
+
var tagStr;
|
|
2861
|
+
if (block) {
|
|
2862
|
+
block = state.flowLevel < 0 || state.flowLevel > level;
|
|
2863
|
+
}
|
|
2864
|
+
var objectOrArray = type2 === "[object Object]" || type2 === "[object Array]", duplicateIndex, duplicate;
|
|
2865
|
+
if (objectOrArray) {
|
|
2866
|
+
duplicateIndex = state.duplicates.indexOf(object);
|
|
2867
|
+
duplicate = duplicateIndex !== -1;
|
|
2868
|
+
}
|
|
2869
|
+
if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
|
|
2870
|
+
compact = false;
|
|
2871
|
+
}
|
|
2872
|
+
if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
|
2873
|
+
state.dump = "*ref_" + duplicateIndex;
|
|
2874
|
+
} else {
|
|
2875
|
+
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
|
2876
|
+
state.usedDuplicates[duplicateIndex] = true;
|
|
2877
|
+
}
|
|
2878
|
+
if (type2 === "[object Object]") {
|
|
2879
|
+
if (block && Object.keys(state.dump).length !== 0) {
|
|
2880
|
+
writeBlockMapping(state, level, state.dump, compact);
|
|
2881
|
+
if (duplicate) {
|
|
2882
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2883
|
+
}
|
|
2884
|
+
} else {
|
|
2885
|
+
writeFlowMapping(state, level, state.dump);
|
|
2886
|
+
if (duplicate) {
|
|
2887
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
} else if (type2 === "[object Array]") {
|
|
2891
|
+
if (block && state.dump.length !== 0) {
|
|
2892
|
+
if (state.noArrayIndent && !isblockseq && level > 0) {
|
|
2893
|
+
writeBlockSequence(state, level - 1, state.dump, compact);
|
|
2894
|
+
} else {
|
|
2895
|
+
writeBlockSequence(state, level, state.dump, compact);
|
|
2896
|
+
}
|
|
2897
|
+
if (duplicate) {
|
|
2898
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2899
|
+
}
|
|
2900
|
+
} else {
|
|
2901
|
+
writeFlowSequence(state, level, state.dump);
|
|
2902
|
+
if (duplicate) {
|
|
2903
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
} else if (type2 === "[object String]") {
|
|
2907
|
+
if (state.tag !== "?") {
|
|
2908
|
+
writeScalar(state, state.dump, level, iskey, inblock);
|
|
2909
|
+
}
|
|
2910
|
+
} else if (type2 === "[object Undefined]") {
|
|
2911
|
+
return false;
|
|
2912
|
+
} else {
|
|
2913
|
+
if (state.skipInvalid) return false;
|
|
2914
|
+
throw new exception("unacceptable kind of an object to dump " + type2);
|
|
2915
|
+
}
|
|
2916
|
+
if (state.tag !== null && state.tag !== "?") {
|
|
2917
|
+
tagStr = encodeURI(
|
|
2918
|
+
state.tag[0] === "!" ? state.tag.slice(1) : state.tag
|
|
2919
|
+
).replace(/!/g, "%21");
|
|
2920
|
+
if (state.tag[0] === "!") {
|
|
2921
|
+
tagStr = "!" + tagStr;
|
|
2922
|
+
} else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
|
|
2923
|
+
tagStr = "!!" + tagStr.slice(18);
|
|
2924
|
+
} else {
|
|
2925
|
+
tagStr = "!<" + tagStr + ">";
|
|
2926
|
+
}
|
|
2927
|
+
state.dump = tagStr + " " + state.dump;
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
return true;
|
|
2931
|
+
}
|
|
2932
|
+
function getDuplicateReferences(object, state) {
|
|
2933
|
+
var objects = [], duplicatesIndexes = [], index, length;
|
|
2934
|
+
inspectNode(object, objects, duplicatesIndexes);
|
|
2935
|
+
for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
|
|
2936
|
+
state.duplicates.push(objects[duplicatesIndexes[index]]);
|
|
2937
|
+
}
|
|
2938
|
+
state.usedDuplicates = new Array(length);
|
|
2939
|
+
}
|
|
2940
|
+
function inspectNode(object, objects, duplicatesIndexes) {
|
|
2941
|
+
var objectKeyList, index, length;
|
|
2942
|
+
if (object !== null && typeof object === "object") {
|
|
2943
|
+
index = objects.indexOf(object);
|
|
2944
|
+
if (index !== -1) {
|
|
2945
|
+
if (duplicatesIndexes.indexOf(index) === -1) {
|
|
2946
|
+
duplicatesIndexes.push(index);
|
|
2947
|
+
}
|
|
2948
|
+
} else {
|
|
2949
|
+
objects.push(object);
|
|
2950
|
+
if (Array.isArray(object)) {
|
|
2951
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2952
|
+
inspectNode(object[index], objects, duplicatesIndexes);
|
|
2953
|
+
}
|
|
2954
|
+
} else {
|
|
2955
|
+
objectKeyList = Object.keys(object);
|
|
2956
|
+
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2957
|
+
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
function dump$1(input, options) {
|
|
2964
|
+
options = options || {};
|
|
2965
|
+
var state = new State(options);
|
|
2966
|
+
if (!state.noRefs) getDuplicateReferences(input, state);
|
|
2967
|
+
var value = input;
|
|
2968
|
+
if (state.replacer) {
|
|
2969
|
+
value = state.replacer.call({ "": value }, "", value);
|
|
2970
|
+
}
|
|
2971
|
+
if (writeNode(state, 0, value, true, true)) return state.dump + "\n";
|
|
2972
|
+
return "";
|
|
2973
|
+
}
|
|
2974
|
+
var dump_1 = dump$1;
|
|
2975
|
+
var dumper = {
|
|
2976
|
+
dump: dump_1
|
|
2977
|
+
};
|
|
2978
|
+
function renamed(from, to) {
|
|
2979
|
+
return function() {
|
|
2980
|
+
throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default.");
|
|
2981
|
+
};
|
|
2982
|
+
}
|
|
2983
|
+
var load = loader.load;
|
|
2984
|
+
var loadAll = loader.loadAll;
|
|
2985
|
+
var dump = dumper.dump;
|
|
2986
|
+
var safeLoad = renamed("safeLoad", "load");
|
|
2987
|
+
var safeLoadAll = renamed("safeLoadAll", "loadAll");
|
|
2988
|
+
var safeDump = renamed("safeDump", "dump");
|
|
2989
|
+
|
|
2990
|
+
// dist/src/cli/install-mcp-shared.js
|
|
2991
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
358
2992
|
import { join as join6 } from "node:path";
|
|
359
|
-
var
|
|
360
|
-
var
|
|
2993
|
+
var HIVEMIND_DIR = join6(HOME, ".hivemind");
|
|
2994
|
+
var MCP_DIR = join6(HIVEMIND_DIR, "mcp");
|
|
2995
|
+
var MCP_SERVER_PATH = join6(MCP_DIR, "server.js");
|
|
2996
|
+
var MCP_PACKAGE_JSON = join6(MCP_DIR, "package.json");
|
|
2997
|
+
function ensureMcpServerInstalled() {
|
|
2998
|
+
const srcDir = join6(pkgRoot(), "mcp", "bundle");
|
|
2999
|
+
if (!existsSync5(srcDir)) {
|
|
3000
|
+
throw new Error(`MCP server bundle missing at ${srcDir}. Run 'npm run build' to produce it before installing Tier B consumers.`);
|
|
3001
|
+
}
|
|
3002
|
+
ensureDir(MCP_DIR);
|
|
3003
|
+
copyDir(srcDir, MCP_DIR);
|
|
3004
|
+
writeVersionStamp(HIVEMIND_DIR, getVersion());
|
|
3005
|
+
log(` hivemind-mcp server installed -> ${MCP_SERVER_PATH}`);
|
|
3006
|
+
}
|
|
3007
|
+
|
|
3008
|
+
// dist/src/cli/install-hermes.js
|
|
3009
|
+
var HERMES_HOME = join7(HOME, ".hermes");
|
|
3010
|
+
var SKILLS_DIR = join7(HERMES_HOME, "skills", "hivemind-memory");
|
|
3011
|
+
var HIVEMIND_DIR2 = join7(HERMES_HOME, "hivemind");
|
|
3012
|
+
var BUNDLE_DIR = join7(HIVEMIND_DIR2, "bundle");
|
|
3013
|
+
var CONFIG_PATH = join7(HERMES_HOME, "config.yaml");
|
|
3014
|
+
var SERVER_KEY = "hivemind";
|
|
361
3015
|
var SKILL_BODY = `---
|
|
362
3016
|
name: hivemind-memory
|
|
363
3017
|
description: Global team and org memory powered by Activeloop. ALWAYS check BOTH built-in memory AND Hivemind memory when recalling information.
|
|
@@ -367,7 +3021,19 @@ description: Global team and org memory powered by Activeloop. ALWAYS check BOTH
|
|
|
367
3021
|
|
|
368
3022
|
You have persistent memory at \`~/.deeplake/memory/\` \u2014 global memory shared across all sessions, users, and agents in the org.
|
|
369
3023
|
|
|
370
|
-
##
|
|
3024
|
+
## Hivemind tools (preferred)
|
|
3025
|
+
|
|
3026
|
+
When you need to recall org memory, prefer calling the hivemind MCP tools \u2014 one tool call returns ranked hits across all summaries and sessions in a single SQL query:
|
|
3027
|
+
|
|
3028
|
+
- \`hivemind_search { query, limit? }\` \u2014 keyword/regex search across summaries + sessions
|
|
3029
|
+
- \`hivemind_read { path }\` \u2014 read full content at a Hivemind memory path (e.g. \`/summaries/alice/abc.md\`)
|
|
3030
|
+
- \`hivemind_index { prefix?, limit? }\` \u2014 list summary entries
|
|
3031
|
+
|
|
3032
|
+
Different paths under \`/summaries/<username>/\` are different users \u2014 do NOT merge or alias them.
|
|
3033
|
+
|
|
3034
|
+
## Direct filesystem fallback
|
|
3035
|
+
|
|
3036
|
+
If MCP tools are unavailable for some reason, fall back to reading the virtual filesystem at \`~/.deeplake/memory/\`:
|
|
371
3037
|
|
|
372
3038
|
\`\`\`
|
|
373
3039
|
~/.deeplake/memory/
|
|
@@ -381,42 +3047,161 @@ You have persistent memory at \`~/.deeplake/memory/\` \u2014 global memory share
|
|
|
381
3047
|
\u2514\u2500\u2500 user_org_ws_slug2.jsonl
|
|
382
3048
|
\`\`\`
|
|
383
3049
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
1. **First**: Read \`~/.deeplake/memory/index.md\` \u2014 quick scan of all sessions with dates, projects, descriptions
|
|
3050
|
+
1. **First**: Read \`~/.deeplake/memory/index.md\`
|
|
387
3051
|
2. **If you need details**: Read the specific summary at \`~/.deeplake/memory/summaries/<session>.md\`
|
|
388
3052
|
3. **If you need raw data**: Read the session JSONL at \`~/.deeplake/memory/sessions/<user>/<file>.jsonl\`
|
|
389
|
-
4. **Keyword search**: \`grep -r "keyword" ~/.deeplake/memory/\`
|
|
3053
|
+
4. **Keyword search**: \`grep -r "keyword" ~/.deeplake/memory/\` (use \`grep\`, NOT \`rg\`/ripgrep \u2014 \`rg\` may not be installed)
|
|
390
3054
|
|
|
391
3055
|
Do NOT jump straight to reading raw JSONL files. Always start with index.md and summaries.
|
|
392
3056
|
|
|
393
3057
|
## Important Constraints
|
|
394
3058
|
|
|
395
|
-
-
|
|
3059
|
+
- Use \`grep\` (NOT \`rg\`/ripgrep) for keyword search \u2014 \`rg\` may not be installed on the host system.
|
|
3060
|
+
- Only use these bash builtins to interact with \`~/.deeplake/memory/\`: \`cat\`, \`ls\`, \`grep\`, \`echo\`, \`jq\`, \`head\`, \`tail\`, \`sed\`, \`awk\`, \`wc\`, \`sort\`, \`find\`. The memory filesystem does NOT support \`rg\`, \`python\`, \`python3\`, \`node\`, or \`curl\`.
|
|
396
3061
|
- If a file returns empty after 2 attempts, skip it and move on. Report what you found rather than retrying exhaustively.
|
|
397
3062
|
`;
|
|
3063
|
+
function isHivemindHook(entry) {
|
|
3064
|
+
if (!entry || typeof entry !== "object")
|
|
3065
|
+
return false;
|
|
3066
|
+
const cmd = entry.command;
|
|
3067
|
+
return typeof cmd === "string" && cmd.includes("/.hermes/hivemind/bundle/");
|
|
3068
|
+
}
|
|
3069
|
+
function buildHookEntry(bundleFile, timeout, matcher) {
|
|
3070
|
+
const entry = {
|
|
3071
|
+
command: `node ${join7(BUNDLE_DIR, bundleFile)}`,
|
|
3072
|
+
timeout
|
|
3073
|
+
};
|
|
3074
|
+
if (matcher)
|
|
3075
|
+
entry.matcher = matcher;
|
|
3076
|
+
return entry;
|
|
3077
|
+
}
|
|
3078
|
+
function buildHooksBlock() {
|
|
3079
|
+
return {
|
|
3080
|
+
on_session_start: [buildHookEntry("session-start.js", 30)],
|
|
3081
|
+
// pre_tool_call (matcher: terminal) intercepts grep/rg against
|
|
3082
|
+
// ~/.deeplake/memory/ and replies with a single SQL fast-path result.
|
|
3083
|
+
// Belt-and-suspenders alongside the hivemind_search MCP tool — if the
|
|
3084
|
+
// agent ignores the skill guidance and runs a terminal grep, accuracy
|
|
3085
|
+
// still matches Tier 1 (Claude / Codex / Cursor).
|
|
3086
|
+
pre_tool_call: [buildHookEntry("pre-tool-use.js", 30, "terminal")],
|
|
3087
|
+
pre_llm_call: [buildHookEntry("capture.js", 10)],
|
|
3088
|
+
post_tool_call: [buildHookEntry("capture.js", 15)],
|
|
3089
|
+
post_llm_call: [buildHookEntry("capture.js", 15)],
|
|
3090
|
+
on_session_end: [buildHookEntry("session-end.js", 30)]
|
|
3091
|
+
};
|
|
3092
|
+
}
|
|
3093
|
+
function mergeHooks2(existing) {
|
|
3094
|
+
const merged = { ...existing ?? {} };
|
|
3095
|
+
const ours = buildHooksBlock();
|
|
3096
|
+
for (const [event, entries] of Object.entries(ours)) {
|
|
3097
|
+
const prior = Array.isArray(merged[event]) ? merged[event] : [];
|
|
3098
|
+
const stripped = prior.filter((e) => !isHivemindHook(e));
|
|
3099
|
+
merged[event] = [...stripped, ...entries];
|
|
3100
|
+
}
|
|
3101
|
+
return merged;
|
|
3102
|
+
}
|
|
3103
|
+
function stripHivemindHooks(existing) {
|
|
3104
|
+
if (!existing)
|
|
3105
|
+
return void 0;
|
|
3106
|
+
const out = {};
|
|
3107
|
+
for (const [event, entries] of Object.entries(existing)) {
|
|
3108
|
+
const kept = (entries ?? []).filter((e) => !isHivemindHook(e));
|
|
3109
|
+
if (kept.length > 0)
|
|
3110
|
+
out[event] = kept;
|
|
3111
|
+
}
|
|
3112
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
3113
|
+
}
|
|
3114
|
+
function readConfig() {
|
|
3115
|
+
if (!existsSync6(CONFIG_PATH))
|
|
3116
|
+
return {};
|
|
3117
|
+
try {
|
|
3118
|
+
const raw = readFileSync4(CONFIG_PATH, "utf-8");
|
|
3119
|
+
const parsed = load(raw);
|
|
3120
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
3121
|
+
return parsed;
|
|
3122
|
+
}
|
|
3123
|
+
return {};
|
|
3124
|
+
} catch {
|
|
3125
|
+
return {};
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
function writeConfig(cfg) {
|
|
3129
|
+
ensureDir(HERMES_HOME);
|
|
3130
|
+
const dumped = dump(cfg, { lineWidth: 100, noRefs: true });
|
|
3131
|
+
writeFileSync2(CONFIG_PATH, dumped);
|
|
3132
|
+
}
|
|
398
3133
|
function installHermes() {
|
|
399
3134
|
ensureDir(SKILLS_DIR);
|
|
400
|
-
writeFileSync2(
|
|
3135
|
+
writeFileSync2(join7(SKILLS_DIR, "SKILL.md"), SKILL_BODY);
|
|
401
3136
|
writeVersionStamp(SKILLS_DIR, getVersion());
|
|
402
3137
|
log(` Hermes skill installed -> ${SKILLS_DIR}`);
|
|
3138
|
+
const srcBundle = join7(pkgRoot(), "hermes", "bundle");
|
|
3139
|
+
if (!existsSync6(srcBundle)) {
|
|
3140
|
+
throw new Error(`Hermes bundle missing at ${srcBundle}. Run 'npm run build' first.`);
|
|
3141
|
+
}
|
|
3142
|
+
ensureDir(HIVEMIND_DIR2);
|
|
3143
|
+
copyDir(srcBundle, BUNDLE_DIR);
|
|
3144
|
+
writeVersionStamp(HIVEMIND_DIR2, getVersion());
|
|
3145
|
+
log(` Hermes bundle installed -> ${BUNDLE_DIR}`);
|
|
3146
|
+
ensureMcpServerInstalled();
|
|
3147
|
+
const cfg = readConfig();
|
|
3148
|
+
if (!cfg.mcp_servers || typeof cfg.mcp_servers !== "object")
|
|
3149
|
+
cfg.mcp_servers = {};
|
|
3150
|
+
cfg.mcp_servers[SERVER_KEY] = {
|
|
3151
|
+
command: "node",
|
|
3152
|
+
args: [MCP_SERVER_PATH]
|
|
3153
|
+
};
|
|
3154
|
+
cfg.hooks = mergeHooks2(cfg.hooks);
|
|
3155
|
+
cfg.hooks_auto_accept = true;
|
|
3156
|
+
writeConfig(cfg);
|
|
3157
|
+
log(` Hermes config updated -> ${CONFIG_PATH} (mcp_servers + hooks + hooks_auto_accept)`);
|
|
403
3158
|
}
|
|
404
3159
|
function uninstallHermes() {
|
|
405
|
-
if (
|
|
3160
|
+
if (existsSync6(SKILLS_DIR)) {
|
|
406
3161
|
rmSync2(SKILLS_DIR, { recursive: true, force: true });
|
|
407
3162
|
log(` Hermes removed ${SKILLS_DIR}`);
|
|
408
|
-
}
|
|
409
|
-
|
|
3163
|
+
}
|
|
3164
|
+
if (existsSync6(HIVEMIND_DIR2)) {
|
|
3165
|
+
rmSync2(HIVEMIND_DIR2, { recursive: true, force: true });
|
|
3166
|
+
log(` Hermes removed ${HIVEMIND_DIR2}`);
|
|
3167
|
+
}
|
|
3168
|
+
if (existsSync6(CONFIG_PATH)) {
|
|
3169
|
+
const cfg = readConfig();
|
|
3170
|
+
let touched = false;
|
|
3171
|
+
if (cfg.mcp_servers && typeof cfg.mcp_servers === "object" && SERVER_KEY in cfg.mcp_servers) {
|
|
3172
|
+
delete cfg.mcp_servers[SERVER_KEY];
|
|
3173
|
+
if (Object.keys(cfg.mcp_servers).length === 0)
|
|
3174
|
+
delete cfg.mcp_servers;
|
|
3175
|
+
touched = true;
|
|
3176
|
+
}
|
|
3177
|
+
const stripped = stripHivemindHooks(cfg.hooks);
|
|
3178
|
+
if (cfg.hooks && (!stripped || Object.keys(stripped).length !== Object.keys(cfg.hooks).length)) {
|
|
3179
|
+
if (stripped)
|
|
3180
|
+
cfg.hooks = stripped;
|
|
3181
|
+
else
|
|
3182
|
+
delete cfg.hooks;
|
|
3183
|
+
touched = true;
|
|
3184
|
+
}
|
|
3185
|
+
if (touched) {
|
|
3186
|
+
if (Object.keys(cfg).length === 0) {
|
|
3187
|
+
unlinkSync4(CONFIG_PATH);
|
|
3188
|
+
} else {
|
|
3189
|
+
writeConfig(cfg);
|
|
3190
|
+
}
|
|
3191
|
+
log(` Hermes hivemind entries removed from ${CONFIG_PATH}`);
|
|
3192
|
+
}
|
|
410
3193
|
}
|
|
411
3194
|
}
|
|
412
3195
|
|
|
413
3196
|
// dist/src/cli/install-pi.js
|
|
414
|
-
import { existsSync as
|
|
415
|
-
import { join as
|
|
416
|
-
var PI_AGENT_DIR =
|
|
417
|
-
var AGENTS_MD =
|
|
418
|
-
var
|
|
419
|
-
var
|
|
3197
|
+
import { existsSync as existsSync7, writeFileSync as writeFileSync3, rmSync as rmSync3, readFileSync as readFileSync5, copyFileSync as copyFileSync2 } from "node:fs";
|
|
3198
|
+
import { join as join8 } from "node:path";
|
|
3199
|
+
var PI_AGENT_DIR = join8(HOME, ".pi", "agent");
|
|
3200
|
+
var AGENTS_MD = join8(PI_AGENT_DIR, "AGENTS.md");
|
|
3201
|
+
var LEGACY_SKILL_DIR = join8(PI_AGENT_DIR, "skills", "hivemind-memory");
|
|
3202
|
+
var EXTENSIONS_DIR = join8(PI_AGENT_DIR, "extensions");
|
|
3203
|
+
var EXTENSION_PATH = join8(EXTENSIONS_DIR, "hivemind.ts");
|
|
3204
|
+
var VERSION_DIR = join8(PI_AGENT_DIR, ".hivemind");
|
|
420
3205
|
var HIVEMIND_BLOCK_START = "<!-- BEGIN hivemind-memory -->";
|
|
421
3206
|
var HIVEMIND_BLOCK_END = "<!-- END hivemind-memory -->";
|
|
422
3207
|
var HIVEMIND_BLOCK_BODY = `${HIVEMIND_BLOCK_START}
|
|
@@ -426,51 +3211,16 @@ You have access to global org memory at \`~/.deeplake/memory/\`. Always check bo
|
|
|
426
3211
|
your local context AND Hivemind memory when the user asks you to recall, look up,
|
|
427
3212
|
or remember anything.
|
|
428
3213
|
|
|
3214
|
+
- Three hivemind tools are registered: \`hivemind_search\`, \`hivemind_read\`, \`hivemind_index\`. **Prefer these** \u2014 one call returns ranked hits in a single SQL query.
|
|
3215
|
+
- Fall back to direct filesystem if the tools fail:
|
|
429
3216
|
- Start with \`~/.deeplake/memory/index.md\` (table of all sessions)
|
|
430
3217
|
- Then read specific summaries at \`~/.deeplake/memory/summaries/<user>/<session>.md\`
|
|
431
3218
|
- Only fall back to raw \`~/.deeplake/memory/sessions/<user>/*.jsonl\` if summaries don't have enough detail
|
|
432
|
-
- Search: \`grep -
|
|
3219
|
+
- Search: use \`grep\` (NOT \`rg\`/ripgrep \u2014 \`rg\` is not always installed). Example: \`grep -ri "keyword" ~/.deeplake/memory/\`
|
|
433
3220
|
|
|
434
|
-
Use only bash builtins (cat, ls, grep, jq, head, tail, sed, awk) to read this filesystem \u2014
|
|
435
|
-
node
|
|
3221
|
+
Use only bash builtins (cat, ls, grep, jq, head, tail, sed, awk, wc, sort, find) to read this filesystem \u2014
|
|
3222
|
+
rg/ripgrep, node, python, curl are not available there.
|
|
436
3223
|
${HIVEMIND_BLOCK_END}`;
|
|
437
|
-
var SKILL_BODY2 = `---
|
|
438
|
-
name: hivemind-memory
|
|
439
|
-
description: Global team and org memory powered by Activeloop. Always check both local context AND Hivemind memory when recalling information.
|
|
440
|
-
---
|
|
441
|
-
|
|
442
|
-
# Hivemind Memory
|
|
443
|
-
|
|
444
|
-
You have persistent memory at \`~/.deeplake/memory/\` \u2014 global memory shared across all sessions, users, and agents in the org.
|
|
445
|
-
|
|
446
|
-
## Memory Structure
|
|
447
|
-
|
|
448
|
-
\`\`\`
|
|
449
|
-
~/.deeplake/memory/
|
|
450
|
-
\u251C\u2500\u2500 index.md \u2190 START HERE \u2014 table of all sessions
|
|
451
|
-
\u251C\u2500\u2500 summaries/
|
|
452
|
-
\u2502 \u251C\u2500\u2500 session-abc.md \u2190 AI-generated wiki summary
|
|
453
|
-
\u2502 \u2514\u2500\u2500 session-xyz.md
|
|
454
|
-
\u2514\u2500\u2500 sessions/
|
|
455
|
-
\u2514\u2500\u2500 username/
|
|
456
|
-
\u251C\u2500\u2500 user_org_ws_slug1.jsonl \u2190 raw session data
|
|
457
|
-
\u2514\u2500\u2500 user_org_ws_slug2.jsonl
|
|
458
|
-
\`\`\`
|
|
459
|
-
|
|
460
|
-
## How to Search
|
|
461
|
-
|
|
462
|
-
1. **First**: Read \`~/.deeplake/memory/index.md\` \u2014 quick scan of all sessions with dates, projects, descriptions
|
|
463
|
-
2. **If you need details**: Read the specific summary at \`~/.deeplake/memory/summaries/<session>.md\`
|
|
464
|
-
3. **If you need raw data**: Read the session JSONL at \`~/.deeplake/memory/sessions/<user>/<file>.jsonl\`
|
|
465
|
-
4. **Keyword search**: \`grep -r "keyword" ~/.deeplake/memory/\`
|
|
466
|
-
|
|
467
|
-
Do NOT jump straight to reading raw JSONL files. Always start with index.md and summaries.
|
|
468
|
-
|
|
469
|
-
## Important Constraints
|
|
470
|
-
|
|
471
|
-
- Only use bash builtins (\`cat\`, \`ls\`, \`grep\`, \`echo\`, \`jq\`, \`head\`, \`tail\`, \`sed\`, \`awk\`, \`wc\`, \`sort\`, \`find\`) to interact with \`~/.deeplake/memory/\`. The memory filesystem does NOT support \`python\`, \`python3\`, \`node\`, or \`curl\`.
|
|
472
|
-
- If a file returns empty after 2 attempts, skip it and move on. Report what you found rather than retrying exhaustively.
|
|
473
|
-
`;
|
|
474
3224
|
function upsertHivemindBlock(existing) {
|
|
475
3225
|
const block = HIVEMIND_BLOCK_BODY;
|
|
476
3226
|
if (!existing)
|
|
@@ -519,23 +3269,34 @@ ${after}`;
|
|
|
519
3269
|
}
|
|
520
3270
|
function installPi() {
|
|
521
3271
|
ensureDir(PI_AGENT_DIR);
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
3272
|
+
if (existsSync7(LEGACY_SKILL_DIR)) {
|
|
3273
|
+
rmSync3(LEGACY_SKILL_DIR, { recursive: true, force: true });
|
|
3274
|
+
}
|
|
3275
|
+
const prior = existsSync7(AGENTS_MD) ? readFileSync5(AGENTS_MD, "utf-8") : null;
|
|
525
3276
|
const next = upsertHivemindBlock(prior);
|
|
526
3277
|
writeFileSync3(AGENTS_MD, next);
|
|
3278
|
+
const srcExtension = join8(pkgRoot(), "pi", "extension-source", "hivemind.ts");
|
|
3279
|
+
if (!existsSync7(srcExtension)) {
|
|
3280
|
+
throw new Error(`pi extension source missing at ${srcExtension}. Reinstall the @deeplake/hivemind package.`);
|
|
3281
|
+
}
|
|
3282
|
+
ensureDir(EXTENSIONS_DIR);
|
|
3283
|
+
copyFileSync2(srcExtension, EXTENSION_PATH);
|
|
527
3284
|
ensureDir(VERSION_DIR);
|
|
528
3285
|
writeVersionStamp(VERSION_DIR, getVersion());
|
|
529
|
-
log(` pi skill installed -> ${SKILL_DIR}`);
|
|
530
3286
|
log(` pi AGENTS.md updated -> ${AGENTS_MD}`);
|
|
3287
|
+
log(` pi extension installed -> ${EXTENSION_PATH}`);
|
|
531
3288
|
}
|
|
532
3289
|
function uninstallPi() {
|
|
533
|
-
if (
|
|
534
|
-
rmSync3(
|
|
535
|
-
log(` pi removed ${
|
|
3290
|
+
if (existsSync7(LEGACY_SKILL_DIR)) {
|
|
3291
|
+
rmSync3(LEGACY_SKILL_DIR, { recursive: true, force: true });
|
|
3292
|
+
log(` pi removed ${LEGACY_SKILL_DIR}`);
|
|
536
3293
|
}
|
|
537
|
-
if (
|
|
538
|
-
|
|
3294
|
+
if (existsSync7(EXTENSION_PATH)) {
|
|
3295
|
+
rmSync3(EXTENSION_PATH, { force: true });
|
|
3296
|
+
log(` pi removed extension ${EXTENSION_PATH}`);
|
|
3297
|
+
}
|
|
3298
|
+
if (existsSync7(AGENTS_MD)) {
|
|
3299
|
+
const prior = readFileSync5(AGENTS_MD, "utf-8");
|
|
539
3300
|
const stripped = stripHivemindBlock(prior);
|
|
540
3301
|
if (stripped.trim().length === 0) {
|
|
541
3302
|
rmSync3(AGENTS_MD, { force: true });
|
|
@@ -545,160 +3306,44 @@ function uninstallPi() {
|
|
|
545
3306
|
log(` pi stripped hivemind block from ${AGENTS_MD}`);
|
|
546
3307
|
}
|
|
547
3308
|
}
|
|
548
|
-
if (
|
|
3309
|
+
if (existsSync7(VERSION_DIR)) {
|
|
549
3310
|
rmSync3(VERSION_DIR, { recursive: true, force: true });
|
|
550
3311
|
}
|
|
551
3312
|
}
|
|
552
3313
|
|
|
553
|
-
// dist/src/cli/install-cline.js
|
|
554
|
-
import { existsSync as existsSync8, unlinkSync as unlinkSync4 } from "node:fs";
|
|
555
|
-
import { join as join9 } from "node:path";
|
|
556
|
-
|
|
557
|
-
// dist/src/cli/install-mcp-shared.js
|
|
558
|
-
import { existsSync as existsSync7 } from "node:fs";
|
|
559
|
-
import { join as join8 } from "node:path";
|
|
560
|
-
var HIVEMIND_DIR = join8(HOME, ".hivemind");
|
|
561
|
-
var MCP_DIR = join8(HIVEMIND_DIR, "mcp");
|
|
562
|
-
var MCP_SERVER_PATH = join8(MCP_DIR, "server.js");
|
|
563
|
-
var MCP_PACKAGE_JSON = join8(MCP_DIR, "package.json");
|
|
564
|
-
function ensureMcpServerInstalled() {
|
|
565
|
-
const srcDir = join8(pkgRoot(), "mcp", "bundle");
|
|
566
|
-
if (!existsSync7(srcDir)) {
|
|
567
|
-
throw new Error(`MCP server bundle missing at ${srcDir}. Run 'npm run build' to produce it before installing Tier B consumers.`);
|
|
568
|
-
}
|
|
569
|
-
ensureDir(MCP_DIR);
|
|
570
|
-
copyDir(srcDir, MCP_DIR);
|
|
571
|
-
writeVersionStamp(HIVEMIND_DIR, getVersion());
|
|
572
|
-
log(` hivemind-mcp server installed -> ${MCP_SERVER_PATH}`);
|
|
573
|
-
}
|
|
574
|
-
function buildMcpServerEntry() {
|
|
575
|
-
return {
|
|
576
|
-
command: "node",
|
|
577
|
-
args: [MCP_SERVER_PATH]
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
// dist/src/cli/install-cline.js
|
|
582
|
-
var CONFIG_PATH = join9(HOME, ".config", "Code", "User", "globalStorage", "saoudrizwan.claude-dev", "settings", "cline_mcp_settings.json");
|
|
583
|
-
var SERVER_KEY = "hivemind";
|
|
584
|
-
function installCline() {
|
|
585
|
-
ensureMcpServerInstalled();
|
|
586
|
-
const cfg = readJson(CONFIG_PATH) ?? {};
|
|
587
|
-
if (!cfg.mcpServers)
|
|
588
|
-
cfg.mcpServers = {};
|
|
589
|
-
cfg.mcpServers[SERVER_KEY] = buildMcpServerEntry();
|
|
590
|
-
writeJson(CONFIG_PATH, cfg);
|
|
591
|
-
log(` Cline MCP server registered in ${CONFIG_PATH}`);
|
|
592
|
-
}
|
|
593
|
-
function uninstallCline() {
|
|
594
|
-
const cfg = readJson(CONFIG_PATH);
|
|
595
|
-
if (!cfg?.mcpServers || !(SERVER_KEY in cfg.mcpServers)) {
|
|
596
|
-
log(" Cline nothing to remove");
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
delete cfg.mcpServers[SERVER_KEY];
|
|
600
|
-
if (Object.keys(cfg.mcpServers).length === 0) {
|
|
601
|
-
delete cfg.mcpServers;
|
|
602
|
-
}
|
|
603
|
-
if (Object.keys(cfg).length === 0) {
|
|
604
|
-
if (existsSync8(CONFIG_PATH))
|
|
605
|
-
unlinkSync4(CONFIG_PATH);
|
|
606
|
-
} else {
|
|
607
|
-
writeJson(CONFIG_PATH, cfg);
|
|
608
|
-
}
|
|
609
|
-
log(` Cline MCP entry removed from ${CONFIG_PATH}`);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
// dist/src/cli/install-roo.js
|
|
613
|
-
import { existsSync as existsSync9, unlinkSync as unlinkSync5 } from "node:fs";
|
|
614
|
-
import { join as join10 } from "node:path";
|
|
615
|
-
var CONFIG_PATH2 = join10(HOME, ".config", "Code", "User", "globalStorage", "rooveterinaryinc.roo-cline", "settings", "mcp_settings.json");
|
|
616
|
-
var SERVER_KEY2 = "hivemind";
|
|
617
|
-
function installRoo() {
|
|
618
|
-
ensureMcpServerInstalled();
|
|
619
|
-
const cfg = readJson(CONFIG_PATH2) ?? {};
|
|
620
|
-
if (!cfg.mcpServers)
|
|
621
|
-
cfg.mcpServers = {};
|
|
622
|
-
cfg.mcpServers[SERVER_KEY2] = buildMcpServerEntry();
|
|
623
|
-
writeJson(CONFIG_PATH2, cfg);
|
|
624
|
-
log(` Roo Code MCP server registered in ${CONFIG_PATH2}`);
|
|
625
|
-
}
|
|
626
|
-
function uninstallRoo() {
|
|
627
|
-
const cfg = readJson(CONFIG_PATH2);
|
|
628
|
-
if (!cfg?.mcpServers || !(SERVER_KEY2 in cfg.mcpServers)) {
|
|
629
|
-
log(" Roo Code nothing to remove");
|
|
630
|
-
return;
|
|
631
|
-
}
|
|
632
|
-
delete cfg.mcpServers[SERVER_KEY2];
|
|
633
|
-
if (Object.keys(cfg.mcpServers).length === 0)
|
|
634
|
-
delete cfg.mcpServers;
|
|
635
|
-
if (Object.keys(cfg).length === 0) {
|
|
636
|
-
if (existsSync9(CONFIG_PATH2))
|
|
637
|
-
unlinkSync5(CONFIG_PATH2);
|
|
638
|
-
} else {
|
|
639
|
-
writeJson(CONFIG_PATH2, cfg);
|
|
640
|
-
}
|
|
641
|
-
log(` Roo Code MCP entry removed from ${CONFIG_PATH2}`);
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
// dist/src/cli/install-kilo.js
|
|
645
|
-
import { existsSync as existsSync10, unlinkSync as unlinkSync6 } from "node:fs";
|
|
646
|
-
import { join as join11 } from "node:path";
|
|
647
|
-
var CONFIG_PATH3 = join11(HOME, ".kilocode", "mcp.json");
|
|
648
|
-
var SERVER_KEY3 = "hivemind";
|
|
649
|
-
function installKilo() {
|
|
650
|
-
ensureMcpServerInstalled();
|
|
651
|
-
const cfg = readJson(CONFIG_PATH3) ?? {};
|
|
652
|
-
if (!cfg.mcpServers)
|
|
653
|
-
cfg.mcpServers = {};
|
|
654
|
-
cfg.mcpServers[SERVER_KEY3] = buildMcpServerEntry();
|
|
655
|
-
writeJson(CONFIG_PATH3, cfg);
|
|
656
|
-
log(` Kilo Code MCP server registered in ${CONFIG_PATH3}`);
|
|
657
|
-
}
|
|
658
|
-
function uninstallKilo() {
|
|
659
|
-
const cfg = readJson(CONFIG_PATH3);
|
|
660
|
-
if (!cfg?.mcpServers || !(SERVER_KEY3 in cfg.mcpServers)) {
|
|
661
|
-
log(" Kilo Code nothing to remove");
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
delete cfg.mcpServers[SERVER_KEY3];
|
|
665
|
-
if (Object.keys(cfg.mcpServers).length === 0)
|
|
666
|
-
delete cfg.mcpServers;
|
|
667
|
-
if (Object.keys(cfg).length === 0) {
|
|
668
|
-
if (existsSync10(CONFIG_PATH3))
|
|
669
|
-
unlinkSync6(CONFIG_PATH3);
|
|
670
|
-
} else {
|
|
671
|
-
writeJson(CONFIG_PATH3, cfg);
|
|
672
|
-
}
|
|
673
|
-
log(` Kilo Code MCP entry removed from ${CONFIG_PATH3}`);
|
|
674
|
-
}
|
|
675
|
-
|
|
676
3314
|
// dist/src/cli/auth.js
|
|
677
|
-
import { existsSync as
|
|
678
|
-
import { join as
|
|
3315
|
+
import { existsSync as existsSync9 } from "node:fs";
|
|
3316
|
+
import { join as join10 } from "node:path";
|
|
679
3317
|
|
|
680
3318
|
// dist/src/commands/auth.js
|
|
681
|
-
import { readFileSync as
|
|
682
|
-
import { join as
|
|
3319
|
+
import { readFileSync as readFileSync6, writeFileSync as writeFileSync4, existsSync as existsSync8, mkdirSync as mkdirSync2, unlinkSync as unlinkSync5 } from "node:fs";
|
|
3320
|
+
import { join as join9 } from "node:path";
|
|
683
3321
|
import { homedir as homedir2 } from "node:os";
|
|
684
3322
|
import { execSync } from "node:child_process";
|
|
685
|
-
var CONFIG_DIR =
|
|
686
|
-
var CREDS_PATH =
|
|
3323
|
+
var CONFIG_DIR = join9(homedir2(), ".deeplake");
|
|
3324
|
+
var CREDS_PATH = join9(CONFIG_DIR, "credentials.json");
|
|
687
3325
|
var DEFAULT_API_URL = "https://api.deeplake.ai";
|
|
688
3326
|
function loadCredentials() {
|
|
689
|
-
if (!
|
|
3327
|
+
if (!existsSync8(CREDS_PATH))
|
|
690
3328
|
return null;
|
|
691
3329
|
try {
|
|
692
|
-
return JSON.parse(
|
|
3330
|
+
return JSON.parse(readFileSync6(CREDS_PATH, "utf-8"));
|
|
693
3331
|
} catch {
|
|
694
3332
|
return null;
|
|
695
3333
|
}
|
|
696
3334
|
}
|
|
697
3335
|
function saveCredentials(creds) {
|
|
698
|
-
if (!
|
|
3336
|
+
if (!existsSync8(CONFIG_DIR))
|
|
699
3337
|
mkdirSync2(CONFIG_DIR, { recursive: true, mode: 448 });
|
|
700
3338
|
writeFileSync4(CREDS_PATH, JSON.stringify({ ...creds, savedAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2), { mode: 384 });
|
|
701
3339
|
}
|
|
3340
|
+
function deleteCredentials() {
|
|
3341
|
+
if (existsSync8(CREDS_PATH)) {
|
|
3342
|
+
unlinkSync5(CREDS_PATH);
|
|
3343
|
+
return true;
|
|
3344
|
+
}
|
|
3345
|
+
return false;
|
|
3346
|
+
}
|
|
702
3347
|
async function apiGet(path, token, apiUrl, orgId) {
|
|
703
3348
|
const headers = {
|
|
704
3349
|
Authorization: `Bearer ${token}`,
|
|
@@ -723,6 +3368,17 @@ async function apiPost(path, body, token, apiUrl, orgId) {
|
|
|
723
3368
|
throw new Error(`API ${resp.status}: ${await resp.text().catch(() => "")}`);
|
|
724
3369
|
return resp.json();
|
|
725
3370
|
}
|
|
3371
|
+
async function apiDelete(path, token, apiUrl, orgId) {
|
|
3372
|
+
const headers = {
|
|
3373
|
+
Authorization: `Bearer ${token}`,
|
|
3374
|
+
"Content-Type": "application/json"
|
|
3375
|
+
};
|
|
3376
|
+
if (orgId)
|
|
3377
|
+
headers["X-Activeloop-Org-Id"] = orgId;
|
|
3378
|
+
const resp = await fetch(`${apiUrl}${path}`, { method: "DELETE", headers });
|
|
3379
|
+
if (!resp.ok)
|
|
3380
|
+
throw new Error(`API ${resp.status}: ${await resp.text().catch(() => "")}`);
|
|
3381
|
+
}
|
|
726
3382
|
async function requestDeviceCode(apiUrl = DEFAULT_API_URL) {
|
|
727
3383
|
const resp = await fetch(`${apiUrl}/auth/device/code`, {
|
|
728
3384
|
method: "POST",
|
|
@@ -788,6 +3444,33 @@ async function listOrgs(token, apiUrl = DEFAULT_API_URL) {
|
|
|
788
3444
|
const data = await apiGet("/organizations", token, apiUrl);
|
|
789
3445
|
return Array.isArray(data) ? data : [];
|
|
790
3446
|
}
|
|
3447
|
+
async function switchOrg(orgId, orgName) {
|
|
3448
|
+
const creds = loadCredentials();
|
|
3449
|
+
if (!creds)
|
|
3450
|
+
throw new Error("Not logged in. Run deeplake login first.");
|
|
3451
|
+
saveCredentials({ ...creds, orgId, orgName });
|
|
3452
|
+
}
|
|
3453
|
+
async function listWorkspaces(token, apiUrl = DEFAULT_API_URL, orgId) {
|
|
3454
|
+
const raw = await apiGet("/workspaces", token, apiUrl, orgId);
|
|
3455
|
+
const data = raw.data ?? raw;
|
|
3456
|
+
return Array.isArray(data) ? data : [];
|
|
3457
|
+
}
|
|
3458
|
+
async function switchWorkspace(workspaceId) {
|
|
3459
|
+
const creds = loadCredentials();
|
|
3460
|
+
if (!creds)
|
|
3461
|
+
throw new Error("Not logged in. Run deeplake login first.");
|
|
3462
|
+
saveCredentials({ ...creds, workspaceId });
|
|
3463
|
+
}
|
|
3464
|
+
async function inviteMember(username, accessMode, token, orgId, apiUrl = DEFAULT_API_URL) {
|
|
3465
|
+
await apiPost(`/organizations/${orgId}/members/invite`, { username, access_mode: accessMode }, token, apiUrl, orgId);
|
|
3466
|
+
}
|
|
3467
|
+
async function listMembers(token, orgId, apiUrl = DEFAULT_API_URL) {
|
|
3468
|
+
const data = await apiGet(`/organizations/${orgId}/members`, token, apiUrl, orgId);
|
|
3469
|
+
return data.members ?? [];
|
|
3470
|
+
}
|
|
3471
|
+
async function removeMember(userId, token, orgId, apiUrl = DEFAULT_API_URL) {
|
|
3472
|
+
await apiDelete(`/organizations/${orgId}/members/${userId}`, token, apiUrl, orgId);
|
|
3473
|
+
}
|
|
791
3474
|
async function login(apiUrl = DEFAULT_API_URL) {
|
|
792
3475
|
const { token: authToken } = await deviceFlowLogin(apiUrl);
|
|
793
3476
|
const user = await apiGet("/me", authToken, apiUrl);
|
|
@@ -834,9 +3517,9 @@ Using: ${orgName}
|
|
|
834
3517
|
}
|
|
835
3518
|
|
|
836
3519
|
// dist/src/cli/auth.js
|
|
837
|
-
var CREDS_PATH2 =
|
|
3520
|
+
var CREDS_PATH2 = join10(HOME, ".deeplake", "credentials.json");
|
|
838
3521
|
function isLoggedIn() {
|
|
839
|
-
return
|
|
3522
|
+
return existsSync9(CREDS_PATH2) && loadCredentials() !== null;
|
|
840
3523
|
}
|
|
841
3524
|
async function ensureLoggedIn() {
|
|
842
3525
|
if (isLoggedIn())
|
|
@@ -868,7 +3551,680 @@ async function maybeShowOrgChoice() {
|
|
|
868
3551
|
}
|
|
869
3552
|
}
|
|
870
3553
|
|
|
3554
|
+
// dist/src/config.js
|
|
3555
|
+
import { readFileSync as readFileSync7, existsSync as existsSync10 } from "node:fs";
|
|
3556
|
+
import { join as join11 } from "node:path";
|
|
3557
|
+
import { homedir as homedir3, userInfo } from "node:os";
|
|
3558
|
+
function loadConfig() {
|
|
3559
|
+
const home = homedir3();
|
|
3560
|
+
const credPath = join11(home, ".deeplake", "credentials.json");
|
|
3561
|
+
let creds = null;
|
|
3562
|
+
if (existsSync10(credPath)) {
|
|
3563
|
+
try {
|
|
3564
|
+
creds = JSON.parse(readFileSync7(credPath, "utf-8"));
|
|
3565
|
+
} catch {
|
|
3566
|
+
return null;
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
const token = process.env.HIVEMIND_TOKEN ?? creds?.token;
|
|
3570
|
+
const orgId = process.env.HIVEMIND_ORG_ID ?? creds?.orgId;
|
|
3571
|
+
if (!token || !orgId)
|
|
3572
|
+
return null;
|
|
3573
|
+
return {
|
|
3574
|
+
token,
|
|
3575
|
+
orgId,
|
|
3576
|
+
orgName: creds?.orgName ?? orgId,
|
|
3577
|
+
userName: creds?.userName || userInfo().username || "unknown",
|
|
3578
|
+
workspaceId: process.env.HIVEMIND_WORKSPACE_ID ?? creds?.workspaceId ?? "default",
|
|
3579
|
+
apiUrl: process.env.HIVEMIND_API_URL ?? creds?.apiUrl ?? "https://api.deeplake.ai",
|
|
3580
|
+
tableName: process.env.HIVEMIND_TABLE ?? "memory",
|
|
3581
|
+
sessionsTableName: process.env.HIVEMIND_SESSIONS_TABLE ?? "sessions",
|
|
3582
|
+
memoryPath: process.env.HIVEMIND_MEMORY_PATH ?? join11(home, ".deeplake", "memory")
|
|
3583
|
+
};
|
|
3584
|
+
}
|
|
3585
|
+
|
|
3586
|
+
// dist/src/deeplake-api.js
|
|
3587
|
+
import { randomUUID } from "node:crypto";
|
|
3588
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync3, readFileSync as readFileSync8, writeFileSync as writeFileSync5 } from "node:fs";
|
|
3589
|
+
import { join as join13 } from "node:path";
|
|
3590
|
+
import { tmpdir } from "node:os";
|
|
3591
|
+
|
|
3592
|
+
// dist/src/utils/debug.js
|
|
3593
|
+
import { appendFileSync } from "node:fs";
|
|
3594
|
+
import { join as join12 } from "node:path";
|
|
3595
|
+
import { homedir as homedir4 } from "node:os";
|
|
3596
|
+
var DEBUG = process.env.HIVEMIND_DEBUG === "1";
|
|
3597
|
+
var LOG = join12(homedir4(), ".deeplake", "hook-debug.log");
|
|
3598
|
+
function log2(tag, msg) {
|
|
3599
|
+
if (!DEBUG)
|
|
3600
|
+
return;
|
|
3601
|
+
appendFileSync(LOG, `${(/* @__PURE__ */ new Date()).toISOString()} [${tag}] ${msg}
|
|
3602
|
+
`);
|
|
3603
|
+
}
|
|
3604
|
+
|
|
3605
|
+
// dist/src/utils/sql.js
|
|
3606
|
+
function sqlStr(value) {
|
|
3607
|
+
return value.replace(/\\/g, "\\\\").replace(/'/g, "''").replace(/\0/g, "").replace(/[\x01-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "");
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3610
|
+
// dist/src/deeplake-api.js
|
|
3611
|
+
var log3 = (msg) => log2("sdk", msg);
|
|
3612
|
+
function summarizeSql(sql, maxLen = 220) {
|
|
3613
|
+
const compact = sql.replace(/\s+/g, " ").trim();
|
|
3614
|
+
return compact.length > maxLen ? `${compact.slice(0, maxLen)}...` : compact;
|
|
3615
|
+
}
|
|
3616
|
+
function traceSql(msg) {
|
|
3617
|
+
const traceEnabled = process.env.HIVEMIND_TRACE_SQL === "1" || process.env.HIVEMIND_DEBUG === "1";
|
|
3618
|
+
if (!traceEnabled)
|
|
3619
|
+
return;
|
|
3620
|
+
process.stderr.write(`[deeplake-sql] ${msg}
|
|
3621
|
+
`);
|
|
3622
|
+
if (process.env.HIVEMIND_DEBUG === "1")
|
|
3623
|
+
log3(msg);
|
|
3624
|
+
}
|
|
3625
|
+
var RETRYABLE_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
|
|
3626
|
+
var MAX_RETRIES = 3;
|
|
3627
|
+
var BASE_DELAY_MS = 500;
|
|
3628
|
+
var MAX_CONCURRENCY = 5;
|
|
3629
|
+
var QUERY_TIMEOUT_MS = Number(process.env.HIVEMIND_QUERY_TIMEOUT_MS ?? 1e4);
|
|
3630
|
+
var INDEX_MARKER_TTL_MS = Number(process.env.HIVEMIND_INDEX_MARKER_TTL_MS ?? 6 * 60 * 6e4);
|
|
3631
|
+
function sleep(ms) {
|
|
3632
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3633
|
+
}
|
|
3634
|
+
function isTimeoutError(error) {
|
|
3635
|
+
const name = error instanceof Error ? error.name.toLowerCase() : "";
|
|
3636
|
+
const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
|
|
3637
|
+
return name.includes("timeout") || name === "aborterror" || message.includes("timeout") || message.includes("timed out");
|
|
3638
|
+
}
|
|
3639
|
+
function isDuplicateIndexError(error) {
|
|
3640
|
+
const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
|
|
3641
|
+
return message.includes("duplicate key value violates unique constraint") || message.includes("pg_class_relname_nsp_index") || message.includes("already exists");
|
|
3642
|
+
}
|
|
3643
|
+
function isSessionInsertQuery(sql) {
|
|
3644
|
+
return /^\s*insert\s+into\s+"[^"]+"\s*\(\s*id\s*,\s*path\s*,\s*filename\s*,\s*message\s*,/i.test(sql);
|
|
3645
|
+
}
|
|
3646
|
+
function isTransientHtml403(text) {
|
|
3647
|
+
const body = text.toLowerCase();
|
|
3648
|
+
return body.includes("<html") || body.includes("403 forbidden") || body.includes("cloudflare") || body.includes("nginx");
|
|
3649
|
+
}
|
|
3650
|
+
function getIndexMarkerDir() {
|
|
3651
|
+
return process.env.HIVEMIND_INDEX_MARKER_DIR ?? join13(tmpdir(), "hivemind-deeplake-indexes");
|
|
3652
|
+
}
|
|
3653
|
+
var Semaphore = class {
|
|
3654
|
+
max;
|
|
3655
|
+
waiting = [];
|
|
3656
|
+
active = 0;
|
|
3657
|
+
constructor(max) {
|
|
3658
|
+
this.max = max;
|
|
3659
|
+
}
|
|
3660
|
+
async acquire() {
|
|
3661
|
+
if (this.active < this.max) {
|
|
3662
|
+
this.active++;
|
|
3663
|
+
return;
|
|
3664
|
+
}
|
|
3665
|
+
await new Promise((resolve) => this.waiting.push(resolve));
|
|
3666
|
+
}
|
|
3667
|
+
release() {
|
|
3668
|
+
this.active--;
|
|
3669
|
+
const next = this.waiting.shift();
|
|
3670
|
+
if (next) {
|
|
3671
|
+
this.active++;
|
|
3672
|
+
next();
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
};
|
|
3676
|
+
var DeeplakeApi = class {
|
|
3677
|
+
token;
|
|
3678
|
+
apiUrl;
|
|
3679
|
+
orgId;
|
|
3680
|
+
workspaceId;
|
|
3681
|
+
tableName;
|
|
3682
|
+
_pendingRows = [];
|
|
3683
|
+
_sem = new Semaphore(MAX_CONCURRENCY);
|
|
3684
|
+
_tablesCache = null;
|
|
3685
|
+
constructor(token, apiUrl, orgId, workspaceId, tableName) {
|
|
3686
|
+
this.token = token;
|
|
3687
|
+
this.apiUrl = apiUrl;
|
|
3688
|
+
this.orgId = orgId;
|
|
3689
|
+
this.workspaceId = workspaceId;
|
|
3690
|
+
this.tableName = tableName;
|
|
3691
|
+
}
|
|
3692
|
+
/** Execute SQL with retry on transient errors and bounded concurrency. */
|
|
3693
|
+
async query(sql) {
|
|
3694
|
+
const startedAt = Date.now();
|
|
3695
|
+
const summary = summarizeSql(sql);
|
|
3696
|
+
traceSql(`query start: ${summary}`);
|
|
3697
|
+
await this._sem.acquire();
|
|
3698
|
+
try {
|
|
3699
|
+
const rows = await this._queryWithRetry(sql);
|
|
3700
|
+
traceSql(`query ok (${Date.now() - startedAt}ms, rows=${rows.length}): ${summary}`);
|
|
3701
|
+
return rows;
|
|
3702
|
+
} catch (e) {
|
|
3703
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
3704
|
+
traceSql(`query fail (${Date.now() - startedAt}ms): ${summary} :: ${message}`);
|
|
3705
|
+
throw e;
|
|
3706
|
+
} finally {
|
|
3707
|
+
this._sem.release();
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
async _queryWithRetry(sql) {
|
|
3711
|
+
let lastError;
|
|
3712
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
3713
|
+
let resp;
|
|
3714
|
+
try {
|
|
3715
|
+
const signal = AbortSignal.timeout(QUERY_TIMEOUT_MS);
|
|
3716
|
+
resp = await fetch(`${this.apiUrl}/workspaces/${this.workspaceId}/tables/query`, {
|
|
3717
|
+
method: "POST",
|
|
3718
|
+
headers: {
|
|
3719
|
+
Authorization: `Bearer ${this.token}`,
|
|
3720
|
+
"Content-Type": "application/json",
|
|
3721
|
+
"X-Activeloop-Org-Id": this.orgId
|
|
3722
|
+
},
|
|
3723
|
+
signal,
|
|
3724
|
+
body: JSON.stringify({ query: sql })
|
|
3725
|
+
});
|
|
3726
|
+
} catch (e) {
|
|
3727
|
+
if (isTimeoutError(e)) {
|
|
3728
|
+
lastError = new Error(`Query timeout after ${QUERY_TIMEOUT_MS}ms`);
|
|
3729
|
+
throw lastError;
|
|
3730
|
+
}
|
|
3731
|
+
lastError = e instanceof Error ? e : new Error(String(e));
|
|
3732
|
+
if (attempt < MAX_RETRIES) {
|
|
3733
|
+
const delay = BASE_DELAY_MS * Math.pow(2, attempt) + Math.random() * 200;
|
|
3734
|
+
log3(`query retry ${attempt + 1}/${MAX_RETRIES} (fetch error: ${lastError.message}) in ${delay.toFixed(0)}ms`);
|
|
3735
|
+
await sleep(delay);
|
|
3736
|
+
continue;
|
|
3737
|
+
}
|
|
3738
|
+
throw lastError;
|
|
3739
|
+
}
|
|
3740
|
+
if (resp.ok) {
|
|
3741
|
+
const raw = await resp.json();
|
|
3742
|
+
if (!raw?.rows || !raw?.columns)
|
|
3743
|
+
return [];
|
|
3744
|
+
return raw.rows.map((row) => Object.fromEntries(raw.columns.map((col, i) => [col, row[i]])));
|
|
3745
|
+
}
|
|
3746
|
+
const text = await resp.text().catch(() => "");
|
|
3747
|
+
const retryable403 = isSessionInsertQuery(sql) && (resp.status === 401 || resp.status === 403 && (text.length === 0 || isTransientHtml403(text)));
|
|
3748
|
+
if (attempt < MAX_RETRIES && (RETRYABLE_CODES.has(resp.status) || retryable403)) {
|
|
3749
|
+
const delay = BASE_DELAY_MS * Math.pow(2, attempt) + Math.random() * 200;
|
|
3750
|
+
log3(`query retry ${attempt + 1}/${MAX_RETRIES} (${resp.status}) in ${delay.toFixed(0)}ms`);
|
|
3751
|
+
await sleep(delay);
|
|
3752
|
+
continue;
|
|
3753
|
+
}
|
|
3754
|
+
throw new Error(`Query failed: ${resp.status}: ${text.slice(0, 200)}`);
|
|
3755
|
+
}
|
|
3756
|
+
throw lastError ?? new Error("Query failed: max retries exceeded");
|
|
3757
|
+
}
|
|
3758
|
+
// ── Writes ──────────────────────────────────────────────────────────────────
|
|
3759
|
+
/** Queue rows for writing. Call commit() to flush. */
|
|
3760
|
+
appendRows(rows) {
|
|
3761
|
+
this._pendingRows.push(...rows);
|
|
3762
|
+
}
|
|
3763
|
+
/** Flush pending rows via SQL. */
|
|
3764
|
+
async commit() {
|
|
3765
|
+
if (this._pendingRows.length === 0)
|
|
3766
|
+
return;
|
|
3767
|
+
const rows = this._pendingRows;
|
|
3768
|
+
this._pendingRows = [];
|
|
3769
|
+
const CONCURRENCY = 10;
|
|
3770
|
+
for (let i = 0; i < rows.length; i += CONCURRENCY) {
|
|
3771
|
+
const chunk = rows.slice(i, i + CONCURRENCY);
|
|
3772
|
+
await Promise.allSettled(chunk.map((r) => this.upsertRowSql(r)));
|
|
3773
|
+
}
|
|
3774
|
+
log3(`commit: ${rows.length} rows`);
|
|
3775
|
+
}
|
|
3776
|
+
async upsertRowSql(row) {
|
|
3777
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
3778
|
+
const cd = row.creationDate ?? ts;
|
|
3779
|
+
const lud = row.lastUpdateDate ?? ts;
|
|
3780
|
+
const exists = await this.query(`SELECT path FROM "${this.tableName}" WHERE path = '${sqlStr(row.path)}' LIMIT 1`);
|
|
3781
|
+
if (exists.length > 0) {
|
|
3782
|
+
let setClauses = `summary = E'${sqlStr(row.contentText)}', mime_type = '${sqlStr(row.mimeType)}', size_bytes = ${row.sizeBytes}, last_update_date = '${lud}'`;
|
|
3783
|
+
if (row.project !== void 0)
|
|
3784
|
+
setClauses += `, project = '${sqlStr(row.project)}'`;
|
|
3785
|
+
if (row.description !== void 0)
|
|
3786
|
+
setClauses += `, description = '${sqlStr(row.description)}'`;
|
|
3787
|
+
await this.query(`UPDATE "${this.tableName}" SET ${setClauses} WHERE path = '${sqlStr(row.path)}'`);
|
|
3788
|
+
} else {
|
|
3789
|
+
const id = randomUUID();
|
|
3790
|
+
let cols = "id, path, filename, summary, mime_type, size_bytes, creation_date, last_update_date";
|
|
3791
|
+
let vals = `'${id}', '${sqlStr(row.path)}', '${sqlStr(row.filename)}', E'${sqlStr(row.contentText)}', '${sqlStr(row.mimeType)}', ${row.sizeBytes}, '${cd}', '${lud}'`;
|
|
3792
|
+
if (row.project !== void 0) {
|
|
3793
|
+
cols += ", project";
|
|
3794
|
+
vals += `, '${sqlStr(row.project)}'`;
|
|
3795
|
+
}
|
|
3796
|
+
if (row.description !== void 0) {
|
|
3797
|
+
cols += ", description";
|
|
3798
|
+
vals += `, '${sqlStr(row.description)}'`;
|
|
3799
|
+
}
|
|
3800
|
+
await this.query(`INSERT INTO "${this.tableName}" (${cols}) VALUES (${vals})`);
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
/** Update specific columns on a row by path. */
|
|
3804
|
+
async updateColumns(path, columns) {
|
|
3805
|
+
const setClauses = Object.entries(columns).map(([col, val]) => typeof val === "number" ? `${col} = ${val}` : `${col} = '${sqlStr(String(val))}'`).join(", ");
|
|
3806
|
+
await this.query(`UPDATE "${this.tableName}" SET ${setClauses} WHERE path = '${sqlStr(path)}'`);
|
|
3807
|
+
}
|
|
3808
|
+
// ── Convenience ─────────────────────────────────────────────────────────────
|
|
3809
|
+
/** Create a BM25 search index on a column. */
|
|
3810
|
+
async createIndex(column) {
|
|
3811
|
+
await this.query(`CREATE INDEX IF NOT EXISTS idx_${sqlStr(column)}_bm25 ON "${this.tableName}" USING deeplake_index ("${column}")`);
|
|
3812
|
+
}
|
|
3813
|
+
buildLookupIndexName(table, suffix) {
|
|
3814
|
+
return `idx_${table}_${suffix}`.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
3815
|
+
}
|
|
3816
|
+
getLookupIndexMarkerPath(table, suffix) {
|
|
3817
|
+
const markerKey = [
|
|
3818
|
+
this.workspaceId,
|
|
3819
|
+
this.orgId,
|
|
3820
|
+
table,
|
|
3821
|
+
suffix
|
|
3822
|
+
].join("__").replace(/[^a-zA-Z0-9_.-]/g, "_");
|
|
3823
|
+
return join13(getIndexMarkerDir(), `${markerKey}.json`);
|
|
3824
|
+
}
|
|
3825
|
+
hasFreshLookupIndexMarker(table, suffix) {
|
|
3826
|
+
const markerPath = this.getLookupIndexMarkerPath(table, suffix);
|
|
3827
|
+
if (!existsSync11(markerPath))
|
|
3828
|
+
return false;
|
|
3829
|
+
try {
|
|
3830
|
+
const raw = JSON.parse(readFileSync8(markerPath, "utf-8"));
|
|
3831
|
+
const updatedAt = raw.updatedAt ? new Date(raw.updatedAt).getTime() : NaN;
|
|
3832
|
+
if (!Number.isFinite(updatedAt) || Date.now() - updatedAt > INDEX_MARKER_TTL_MS)
|
|
3833
|
+
return false;
|
|
3834
|
+
return true;
|
|
3835
|
+
} catch {
|
|
3836
|
+
return false;
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
markLookupIndexReady(table, suffix) {
|
|
3840
|
+
mkdirSync3(getIndexMarkerDir(), { recursive: true });
|
|
3841
|
+
writeFileSync5(this.getLookupIndexMarkerPath(table, suffix), JSON.stringify({ updatedAt: (/* @__PURE__ */ new Date()).toISOString() }), "utf-8");
|
|
3842
|
+
}
|
|
3843
|
+
async ensureLookupIndex(table, suffix, columnsSql) {
|
|
3844
|
+
if (this.hasFreshLookupIndexMarker(table, suffix))
|
|
3845
|
+
return;
|
|
3846
|
+
const indexName = this.buildLookupIndexName(table, suffix);
|
|
3847
|
+
try {
|
|
3848
|
+
await this.query(`CREATE INDEX IF NOT EXISTS "${indexName}" ON "${table}" ${columnsSql}`);
|
|
3849
|
+
this.markLookupIndexReady(table, suffix);
|
|
3850
|
+
} catch (e) {
|
|
3851
|
+
if (isDuplicateIndexError(e)) {
|
|
3852
|
+
this.markLookupIndexReady(table, suffix);
|
|
3853
|
+
return;
|
|
3854
|
+
}
|
|
3855
|
+
log3(`index "${indexName}" skipped: ${e.message}`);
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
/** List all tables in the workspace (with retry). */
|
|
3859
|
+
async listTables(forceRefresh = false) {
|
|
3860
|
+
if (!forceRefresh && this._tablesCache)
|
|
3861
|
+
return [...this._tablesCache];
|
|
3862
|
+
const { tables, cacheable } = await this._fetchTables();
|
|
3863
|
+
if (cacheable)
|
|
3864
|
+
this._tablesCache = [...tables];
|
|
3865
|
+
return tables;
|
|
3866
|
+
}
|
|
3867
|
+
async _fetchTables() {
|
|
3868
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
3869
|
+
try {
|
|
3870
|
+
const resp = await fetch(`${this.apiUrl}/workspaces/${this.workspaceId}/tables`, {
|
|
3871
|
+
headers: {
|
|
3872
|
+
Authorization: `Bearer ${this.token}`,
|
|
3873
|
+
"X-Activeloop-Org-Id": this.orgId
|
|
3874
|
+
}
|
|
3875
|
+
});
|
|
3876
|
+
if (resp.ok) {
|
|
3877
|
+
const data = await resp.json();
|
|
3878
|
+
return {
|
|
3879
|
+
tables: (data.tables ?? []).map((t) => t.table_name),
|
|
3880
|
+
cacheable: true
|
|
3881
|
+
};
|
|
3882
|
+
}
|
|
3883
|
+
if (attempt < MAX_RETRIES && RETRYABLE_CODES.has(resp.status)) {
|
|
3884
|
+
await sleep(BASE_DELAY_MS * Math.pow(2, attempt) + Math.random() * 200);
|
|
3885
|
+
continue;
|
|
3886
|
+
}
|
|
3887
|
+
return { tables: [], cacheable: false };
|
|
3888
|
+
} catch {
|
|
3889
|
+
if (attempt < MAX_RETRIES) {
|
|
3890
|
+
await sleep(BASE_DELAY_MS * Math.pow(2, attempt));
|
|
3891
|
+
continue;
|
|
3892
|
+
}
|
|
3893
|
+
return { tables: [], cacheable: false };
|
|
3894
|
+
}
|
|
3895
|
+
}
|
|
3896
|
+
return { tables: [], cacheable: false };
|
|
3897
|
+
}
|
|
3898
|
+
/** Create the memory table if it doesn't already exist. Migrate columns on existing tables. */
|
|
3899
|
+
async ensureTable(name) {
|
|
3900
|
+
const tbl = name ?? this.tableName;
|
|
3901
|
+
const tables = await this.listTables();
|
|
3902
|
+
if (!tables.includes(tbl)) {
|
|
3903
|
+
log3(`table "${tbl}" not found, creating`);
|
|
3904
|
+
await this.query(`CREATE TABLE IF NOT EXISTS "${tbl}" (id TEXT NOT NULL DEFAULT '', path TEXT NOT NULL DEFAULT '', filename TEXT NOT NULL DEFAULT '', summary TEXT NOT NULL DEFAULT '', author TEXT NOT NULL DEFAULT '', mime_type TEXT NOT NULL DEFAULT 'text/plain', size_bytes BIGINT NOT NULL DEFAULT 0, project TEXT NOT NULL DEFAULT '', description TEXT NOT NULL DEFAULT '', agent TEXT NOT NULL DEFAULT '', creation_date TEXT NOT NULL DEFAULT '', last_update_date TEXT NOT NULL DEFAULT '') USING deeplake`);
|
|
3905
|
+
log3(`table "${tbl}" created`);
|
|
3906
|
+
if (!tables.includes(tbl))
|
|
3907
|
+
this._tablesCache = [...tables, tbl];
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
/** Create the sessions table (uses JSONB for message since every row is a JSON event). */
|
|
3911
|
+
async ensureSessionsTable(name) {
|
|
3912
|
+
const tables = await this.listTables();
|
|
3913
|
+
if (!tables.includes(name)) {
|
|
3914
|
+
log3(`table "${name}" not found, creating`);
|
|
3915
|
+
await this.query(`CREATE TABLE IF NOT EXISTS "${name}" (id TEXT NOT NULL DEFAULT '', path TEXT NOT NULL DEFAULT '', filename TEXT NOT NULL DEFAULT '', message JSONB, author TEXT NOT NULL DEFAULT '', mime_type TEXT NOT NULL DEFAULT 'application/json', size_bytes BIGINT NOT NULL DEFAULT 0, project TEXT NOT NULL DEFAULT '', description TEXT NOT NULL DEFAULT '', agent TEXT NOT NULL DEFAULT '', creation_date TEXT NOT NULL DEFAULT '', last_update_date TEXT NOT NULL DEFAULT '') USING deeplake`);
|
|
3916
|
+
log3(`table "${name}" created`);
|
|
3917
|
+
if (!tables.includes(name))
|
|
3918
|
+
this._tablesCache = [...tables, name];
|
|
3919
|
+
}
|
|
3920
|
+
await this.ensureLookupIndex(name, "path_creation_date", `("path", "creation_date")`);
|
|
3921
|
+
}
|
|
3922
|
+
};
|
|
3923
|
+
|
|
3924
|
+
// dist/src/commands/session-prune.js
|
|
3925
|
+
import { createInterface } from "node:readline";
|
|
3926
|
+
function parseArgs(argv) {
|
|
3927
|
+
let before;
|
|
3928
|
+
let sessionId;
|
|
3929
|
+
let all = false;
|
|
3930
|
+
let yes = false;
|
|
3931
|
+
for (let i = 0; i < argv.length; i++) {
|
|
3932
|
+
const arg = argv[i];
|
|
3933
|
+
if (arg === "--before" && argv[i + 1]) {
|
|
3934
|
+
before = argv[++i];
|
|
3935
|
+
} else if (arg === "--session-id" && argv[i + 1]) {
|
|
3936
|
+
sessionId = argv[++i];
|
|
3937
|
+
} else if (arg === "--all") {
|
|
3938
|
+
all = true;
|
|
3939
|
+
} else if (arg === "--yes" || arg === "-y") {
|
|
3940
|
+
yes = true;
|
|
3941
|
+
}
|
|
3942
|
+
}
|
|
3943
|
+
return { before, sessionId, all, yes };
|
|
3944
|
+
}
|
|
3945
|
+
function confirm(message) {
|
|
3946
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
3947
|
+
return new Promise((resolve) => {
|
|
3948
|
+
rl.question(`${message} [y/N] `, (answer) => {
|
|
3949
|
+
rl.close();
|
|
3950
|
+
resolve(answer.trim().toLowerCase() === "y");
|
|
3951
|
+
});
|
|
3952
|
+
});
|
|
3953
|
+
}
|
|
3954
|
+
function extractSessionId(path) {
|
|
3955
|
+
const m = path.match(/\/sessions\/[^/]+\/[^/]+_([^.]+)\.jsonl$/);
|
|
3956
|
+
return m ? m[1] : path.split("/").pop()?.replace(/\.jsonl$/, "") ?? path;
|
|
3957
|
+
}
|
|
3958
|
+
async function listSessions(api, sessionsTable, author) {
|
|
3959
|
+
const rows = await api.query(`SELECT path, COUNT(*) as cnt, MIN(creation_date) as first_event, MAX(creation_date) as last_event, MAX(project) as project FROM "${sessionsTable}" WHERE author = '${sqlStr(author)}' GROUP BY path ORDER BY first_event DESC`);
|
|
3960
|
+
return rows.map((r) => ({
|
|
3961
|
+
path: String(r.path),
|
|
3962
|
+
rowCount: Number(r.cnt),
|
|
3963
|
+
firstEvent: String(r.first_event),
|
|
3964
|
+
lastEvent: String(r.last_event),
|
|
3965
|
+
project: String(r.project ?? "")
|
|
3966
|
+
}));
|
|
3967
|
+
}
|
|
3968
|
+
async function deleteSessions(config, sessionPaths) {
|
|
3969
|
+
if (sessionPaths.length === 0)
|
|
3970
|
+
return { sessionsDeleted: 0, summariesDeleted: 0 };
|
|
3971
|
+
const sessionsApi = new DeeplakeApi(config.token, config.apiUrl, config.orgId, config.workspaceId, config.sessionsTableName);
|
|
3972
|
+
const memoryApi = new DeeplakeApi(config.token, config.apiUrl, config.orgId, config.workspaceId, config.tableName);
|
|
3973
|
+
let sessionsDeleted = 0;
|
|
3974
|
+
let summariesDeleted = 0;
|
|
3975
|
+
for (const sessionPath of sessionPaths) {
|
|
3976
|
+
await sessionsApi.query(`DELETE FROM "${config.sessionsTableName}" WHERE path = '${sqlStr(sessionPath)}'`);
|
|
3977
|
+
sessionsDeleted++;
|
|
3978
|
+
const sessionId = extractSessionId(sessionPath);
|
|
3979
|
+
const summaryPath = `/summaries/${config.userName}/${sessionId}.md`;
|
|
3980
|
+
const existing = await memoryApi.query(`SELECT path FROM "${config.tableName}" WHERE path = '${sqlStr(summaryPath)}' LIMIT 1`);
|
|
3981
|
+
if (existing.length > 0) {
|
|
3982
|
+
await memoryApi.query(`DELETE FROM "${config.tableName}" WHERE path = '${sqlStr(summaryPath)}'`);
|
|
3983
|
+
summariesDeleted++;
|
|
3984
|
+
}
|
|
3985
|
+
}
|
|
3986
|
+
return { sessionsDeleted, summariesDeleted };
|
|
3987
|
+
}
|
|
3988
|
+
async function sessionPrune(argv) {
|
|
3989
|
+
const config = loadConfig();
|
|
3990
|
+
if (!config) {
|
|
3991
|
+
console.error("Not logged in. Run: deeplake login");
|
|
3992
|
+
process.exit(1);
|
|
3993
|
+
}
|
|
3994
|
+
const { before, sessionId, all, yes } = parseArgs(argv);
|
|
3995
|
+
const author = config.userName;
|
|
3996
|
+
const sessionsApi = new DeeplakeApi(config.token, config.apiUrl, config.orgId, config.workspaceId, config.sessionsTableName);
|
|
3997
|
+
const sessions = await listSessions(sessionsApi, config.sessionsTableName, author);
|
|
3998
|
+
if (sessions.length === 0) {
|
|
3999
|
+
console.log(`No sessions found for author "${author}".`);
|
|
4000
|
+
return;
|
|
4001
|
+
}
|
|
4002
|
+
let targets;
|
|
4003
|
+
if (sessionId) {
|
|
4004
|
+
targets = sessions.filter((s) => extractSessionId(s.path) === sessionId);
|
|
4005
|
+
if (targets.length === 0) {
|
|
4006
|
+
console.error(`Session not found: ${sessionId}`);
|
|
4007
|
+
console.error(`
|
|
4008
|
+
Your sessions:`);
|
|
4009
|
+
for (const s of sessions.slice(0, 10)) {
|
|
4010
|
+
console.error(` ${extractSessionId(s.path)} ${s.firstEvent.slice(0, 10)} ${s.project}`);
|
|
4011
|
+
}
|
|
4012
|
+
process.exit(1);
|
|
4013
|
+
}
|
|
4014
|
+
} else if (before) {
|
|
4015
|
+
const cutoff = new Date(before);
|
|
4016
|
+
if (isNaN(cutoff.getTime())) {
|
|
4017
|
+
console.error(`Invalid date: ${before}`);
|
|
4018
|
+
process.exit(1);
|
|
4019
|
+
}
|
|
4020
|
+
targets = sessions.filter((s) => new Date(s.lastEvent) < cutoff);
|
|
4021
|
+
} else if (all) {
|
|
4022
|
+
targets = sessions;
|
|
4023
|
+
} else {
|
|
4024
|
+
console.log(`Sessions for "${author}" (${sessions.length} total):
|
|
4025
|
+
`);
|
|
4026
|
+
console.log(" Session ID".padEnd(42) + "Date".padEnd(14) + "Events".padEnd(10) + "Project");
|
|
4027
|
+
console.log(" " + "\u2500".repeat(80));
|
|
4028
|
+
for (const s of sessions) {
|
|
4029
|
+
const id = extractSessionId(s.path);
|
|
4030
|
+
const date = s.firstEvent.slice(0, 10);
|
|
4031
|
+
console.log(` ${id.padEnd(40)}${date.padEnd(14)}${String(s.rowCount).padEnd(10)}${s.project}`);
|
|
4032
|
+
}
|
|
4033
|
+
console.log(`
|
|
4034
|
+
To delete, use: --all, --before <date>, or --session-id <id>`);
|
|
4035
|
+
return;
|
|
4036
|
+
}
|
|
4037
|
+
if (targets.length === 0) {
|
|
4038
|
+
console.log("No sessions match the given criteria.");
|
|
4039
|
+
return;
|
|
4040
|
+
}
|
|
4041
|
+
console.log(`Will delete ${targets.length} session(s) for "${author}":
|
|
4042
|
+
`);
|
|
4043
|
+
for (const s of targets) {
|
|
4044
|
+
const id = extractSessionId(s.path);
|
|
4045
|
+
console.log(` ${id} ${s.firstEvent.slice(0, 10)} ${s.rowCount} events ${s.project}`);
|
|
4046
|
+
}
|
|
4047
|
+
console.log();
|
|
4048
|
+
if (!yes) {
|
|
4049
|
+
const ok = await confirm("Proceed with deletion?");
|
|
4050
|
+
if (!ok) {
|
|
4051
|
+
console.log("Aborted.");
|
|
4052
|
+
return;
|
|
4053
|
+
}
|
|
4054
|
+
}
|
|
4055
|
+
const { sessionsDeleted, summariesDeleted } = await deleteSessions(config, targets.map((t) => t.path));
|
|
4056
|
+
console.log(`Deleted ${sessionsDeleted} session(s) and ${summariesDeleted} summary file(s).`);
|
|
4057
|
+
}
|
|
4058
|
+
|
|
4059
|
+
// dist/src/commands/auth-login.js
|
|
4060
|
+
async function runAuthCommand(args) {
|
|
4061
|
+
const cmd = args[0] ?? "whoami";
|
|
4062
|
+
const creds = loadCredentials();
|
|
4063
|
+
const apiUrl = creds?.apiUrl ?? "https://api.deeplake.ai";
|
|
4064
|
+
switch (cmd) {
|
|
4065
|
+
case "login": {
|
|
4066
|
+
await login(apiUrl);
|
|
4067
|
+
break;
|
|
4068
|
+
}
|
|
4069
|
+
case "whoami": {
|
|
4070
|
+
if (!creds) {
|
|
4071
|
+
console.log("Not logged in. Run: node auth-login.js login");
|
|
4072
|
+
break;
|
|
4073
|
+
}
|
|
4074
|
+
console.log(`User org: ${creds.orgName ?? creds.orgId}`);
|
|
4075
|
+
console.log(`Workspace: ${creds.workspaceId ?? "default"}`);
|
|
4076
|
+
console.log(`API: ${creds.apiUrl ?? "https://api.deeplake.ai"}`);
|
|
4077
|
+
break;
|
|
4078
|
+
}
|
|
4079
|
+
case "org": {
|
|
4080
|
+
if (!creds) {
|
|
4081
|
+
console.log("Not logged in.");
|
|
4082
|
+
process.exit(1);
|
|
4083
|
+
}
|
|
4084
|
+
const sub = args[1];
|
|
4085
|
+
if (sub === "list") {
|
|
4086
|
+
const orgs = await listOrgs(creds.token, apiUrl);
|
|
4087
|
+
orgs.forEach((o) => console.log(`${o.id} ${o.name}`));
|
|
4088
|
+
} else if (sub === "switch") {
|
|
4089
|
+
const target = args[2];
|
|
4090
|
+
if (!target) {
|
|
4091
|
+
console.log("Usage: org switch <org-name-or-id>");
|
|
4092
|
+
process.exit(1);
|
|
4093
|
+
}
|
|
4094
|
+
const orgs = await listOrgs(creds.token, apiUrl);
|
|
4095
|
+
const match = orgs.find((o) => o.id === target || o.name.toLowerCase() === target.toLowerCase());
|
|
4096
|
+
if (!match) {
|
|
4097
|
+
console.log(`Org not found: ${target}`);
|
|
4098
|
+
process.exit(1);
|
|
4099
|
+
}
|
|
4100
|
+
await switchOrg(match.id, match.name);
|
|
4101
|
+
console.log(`Switched to org: ${match.name}`);
|
|
4102
|
+
} else {
|
|
4103
|
+
console.log("Usage: org list | org switch <name-or-id>");
|
|
4104
|
+
}
|
|
4105
|
+
break;
|
|
4106
|
+
}
|
|
4107
|
+
case "workspaces": {
|
|
4108
|
+
if (!creds) {
|
|
4109
|
+
console.log("Not logged in.");
|
|
4110
|
+
process.exit(1);
|
|
4111
|
+
}
|
|
4112
|
+
const ws = await listWorkspaces(creds.token, apiUrl, creds.orgId);
|
|
4113
|
+
ws.forEach((w) => console.log(`${w.id} ${w.name}`));
|
|
4114
|
+
break;
|
|
4115
|
+
}
|
|
4116
|
+
case "workspace": {
|
|
4117
|
+
if (!creds) {
|
|
4118
|
+
console.log("Not logged in.");
|
|
4119
|
+
process.exit(1);
|
|
4120
|
+
}
|
|
4121
|
+
const wsId = args[1];
|
|
4122
|
+
if (!wsId) {
|
|
4123
|
+
console.log("Usage: workspace <id>");
|
|
4124
|
+
process.exit(1);
|
|
4125
|
+
}
|
|
4126
|
+
await switchWorkspace(wsId);
|
|
4127
|
+
console.log(`Switched to workspace: ${wsId}`);
|
|
4128
|
+
break;
|
|
4129
|
+
}
|
|
4130
|
+
case "invite": {
|
|
4131
|
+
if (!creds) {
|
|
4132
|
+
console.log("Not logged in.");
|
|
4133
|
+
process.exit(1);
|
|
4134
|
+
}
|
|
4135
|
+
const email = args[1];
|
|
4136
|
+
const mode = args[2]?.toUpperCase() ?? "WRITE";
|
|
4137
|
+
if (!email) {
|
|
4138
|
+
console.log("Usage: invite <email> [ADMIN|WRITE|READ]");
|
|
4139
|
+
process.exit(1);
|
|
4140
|
+
}
|
|
4141
|
+
await inviteMember(email, mode, creds.token, creds.orgId, apiUrl);
|
|
4142
|
+
console.log(`Invited ${email} with ${mode} access`);
|
|
4143
|
+
break;
|
|
4144
|
+
}
|
|
4145
|
+
case "members": {
|
|
4146
|
+
if (!creds) {
|
|
4147
|
+
console.log("Not logged in.");
|
|
4148
|
+
process.exit(1);
|
|
4149
|
+
}
|
|
4150
|
+
const members = await listMembers(creds.token, creds.orgId, apiUrl);
|
|
4151
|
+
members.forEach((m) => console.log(`${m.role.padEnd(8)} ${m.email ?? m.name}`));
|
|
4152
|
+
break;
|
|
4153
|
+
}
|
|
4154
|
+
case "remove": {
|
|
4155
|
+
if (!creds) {
|
|
4156
|
+
console.log("Not logged in.");
|
|
4157
|
+
process.exit(1);
|
|
4158
|
+
}
|
|
4159
|
+
const userId = args[1];
|
|
4160
|
+
if (!userId) {
|
|
4161
|
+
console.log("Usage: remove <user-id>");
|
|
4162
|
+
process.exit(1);
|
|
4163
|
+
}
|
|
4164
|
+
await removeMember(userId, creds.token, creds.orgId, apiUrl);
|
|
4165
|
+
console.log(`Removed user ${userId}`);
|
|
4166
|
+
break;
|
|
4167
|
+
}
|
|
4168
|
+
case "sessions": {
|
|
4169
|
+
const sub = args[1];
|
|
4170
|
+
if (sub === "prune") {
|
|
4171
|
+
await sessionPrune(args.slice(2));
|
|
4172
|
+
} else {
|
|
4173
|
+
console.log("Usage: sessions prune [--all | --before <date> | --session-id <id>] [--yes]");
|
|
4174
|
+
}
|
|
4175
|
+
break;
|
|
4176
|
+
}
|
|
4177
|
+
case "autoupdate": {
|
|
4178
|
+
if (!creds) {
|
|
4179
|
+
console.log("Not logged in.");
|
|
4180
|
+
process.exit(1);
|
|
4181
|
+
}
|
|
4182
|
+
const val = args[1]?.toLowerCase();
|
|
4183
|
+
if (val === "on" || val === "true") {
|
|
4184
|
+
saveCredentials({ ...creds, autoupdate: true });
|
|
4185
|
+
console.log("Autoupdate enabled. Plugin will update automatically on session start.");
|
|
4186
|
+
} else if (val === "off" || val === "false") {
|
|
4187
|
+
saveCredentials({ ...creds, autoupdate: false });
|
|
4188
|
+
console.log("Autoupdate disabled. You'll see a notice when updates are available.");
|
|
4189
|
+
} else {
|
|
4190
|
+
const current = creds.autoupdate !== false ? "on" : "off";
|
|
4191
|
+
console.log(`Autoupdate is currently: ${current}`);
|
|
4192
|
+
console.log("Usage: autoupdate [on|off]");
|
|
4193
|
+
}
|
|
4194
|
+
break;
|
|
4195
|
+
}
|
|
4196
|
+
case "logout": {
|
|
4197
|
+
if (deleteCredentials()) {
|
|
4198
|
+
console.log("Logged out. Credentials removed.");
|
|
4199
|
+
} else {
|
|
4200
|
+
console.log("Not logged in.");
|
|
4201
|
+
}
|
|
4202
|
+
break;
|
|
4203
|
+
}
|
|
4204
|
+
default:
|
|
4205
|
+
console.log("Commands: login, logout, whoami, org list, org switch, workspaces, workspace, sessions prune, invite, members, remove, autoupdate");
|
|
4206
|
+
}
|
|
4207
|
+
}
|
|
4208
|
+
if (process.argv[1] && process.argv[1].endsWith("auth-login.js")) {
|
|
4209
|
+
runAuthCommand(process.argv.slice(2)).catch((e) => {
|
|
4210
|
+
console.error(e.message);
|
|
4211
|
+
process.exit(1);
|
|
4212
|
+
});
|
|
4213
|
+
}
|
|
4214
|
+
|
|
871
4215
|
// dist/src/cli/index.js
|
|
4216
|
+
var AUTH_SUBCOMMANDS = /* @__PURE__ */ new Set([
|
|
4217
|
+
"whoami",
|
|
4218
|
+
"logout",
|
|
4219
|
+
"org",
|
|
4220
|
+
"workspaces",
|
|
4221
|
+
"workspace",
|
|
4222
|
+
"invite",
|
|
4223
|
+
"members",
|
|
4224
|
+
"remove",
|
|
4225
|
+
"autoupdate",
|
|
4226
|
+
"sessions"
|
|
4227
|
+
]);
|
|
872
4228
|
var USAGE = `
|
|
873
4229
|
hivemind \u2014 one brain for every agent on your team
|
|
874
4230
|
|
|
@@ -883,13 +4239,24 @@ Usage:
|
|
|
883
4239
|
hivemind cursor install | uninstall
|
|
884
4240
|
hivemind hermes install | uninstall
|
|
885
4241
|
hivemind pi install | uninstall
|
|
886
|
-
hivemind cline install | uninstall
|
|
887
|
-
hivemind roo install | uninstall
|
|
888
|
-
hivemind kilo install | uninstall
|
|
889
4242
|
Install or remove hivemind for a specific assistant.
|
|
890
4243
|
|
|
891
4244
|
hivemind login Run device-flow login (open browser).
|
|
892
4245
|
hivemind status Show which assistants are wired up.
|
|
4246
|
+
|
|
4247
|
+
Account / org / workspace:
|
|
4248
|
+
hivemind whoami Show current user, org, workspace.
|
|
4249
|
+
hivemind logout Remove credentials.
|
|
4250
|
+
hivemind org list List organizations.
|
|
4251
|
+
hivemind org switch <name-or-id> Switch active organization.
|
|
4252
|
+
hivemind workspaces List workspaces in current org.
|
|
4253
|
+
hivemind workspace <id> Switch active workspace.
|
|
4254
|
+
hivemind members List org members.
|
|
4255
|
+
hivemind invite <email> <ADMIN|WRITE|READ> Invite a teammate.
|
|
4256
|
+
hivemind remove <user-id> Remove a member.
|
|
4257
|
+
hivemind autoupdate [on|off] Toggle Claude Code plugin auto-update.
|
|
4258
|
+
hivemind sessions prune [...] Manage your captured sessions.
|
|
4259
|
+
|
|
893
4260
|
hivemind --version Print the hivemind version.
|
|
894
4261
|
hivemind --help Show this message.
|
|
895
4262
|
|
|
@@ -953,12 +4320,6 @@ function runSingleInstall(id) {
|
|
|
953
4320
|
installHermes();
|
|
954
4321
|
else if (id === "pi")
|
|
955
4322
|
installPi();
|
|
956
|
-
else if (id === "cline")
|
|
957
|
-
installCline();
|
|
958
|
-
else if (id === "roo")
|
|
959
|
-
installRoo();
|
|
960
|
-
else if (id === "kilo")
|
|
961
|
-
installKilo();
|
|
962
4323
|
} catch (err) {
|
|
963
4324
|
warn(` ${id.padEnd(14)} FAILED: ${err.message}`);
|
|
964
4325
|
}
|
|
@@ -977,12 +4338,6 @@ function runSingleUninstall(id) {
|
|
|
977
4338
|
uninstallHermes();
|
|
978
4339
|
else if (id === "pi")
|
|
979
4340
|
uninstallPi();
|
|
980
|
-
else if (id === "cline")
|
|
981
|
-
uninstallCline();
|
|
982
|
-
else if (id === "roo")
|
|
983
|
-
uninstallRoo();
|
|
984
|
-
else if (id === "kilo")
|
|
985
|
-
uninstallKilo();
|
|
986
4341
|
} catch (err) {
|
|
987
4342
|
warn(` ${id.padEnd(14)} FAILED: ${err.message}`);
|
|
988
4343
|
}
|
|
@@ -1028,7 +4383,11 @@ async function main() {
|
|
|
1028
4383
|
runStatus();
|
|
1029
4384
|
return;
|
|
1030
4385
|
}
|
|
1031
|
-
|
|
4386
|
+
if (AUTH_SUBCOMMANDS.has(cmd)) {
|
|
4387
|
+
await runAuthCommand(args);
|
|
4388
|
+
return;
|
|
4389
|
+
}
|
|
4390
|
+
const platformCmds = ["claude", "codex", "claw", "cursor", "hermes", "pi"];
|
|
1032
4391
|
if (platformCmds.includes(cmd)) {
|
|
1033
4392
|
const sub = args[1];
|
|
1034
4393
|
if (sub === "install")
|
|
@@ -1049,3 +4408,8 @@ main().catch((err) => {
|
|
|
1049
4408
|
warn(`hivemind: ${err.message}`);
|
|
1050
4409
|
process.exit(1);
|
|
1051
4410
|
});
|
|
4411
|
+
/*! Bundled license information:
|
|
4412
|
+
|
|
4413
|
+
js-yaml/dist/js-yaml.mjs:
|
|
4414
|
+
(*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT *)
|
|
4415
|
+
*/
|