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