@vibgrate/cli 2026.801.1 → 2026.803.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-JTA4YWMQ.js +24 -0
- package/dist/{agent-4DAECASW.js.map → agent-JTA4YWMQ.js.map} +1 -1
- package/dist/baseline-2V7PKA7Q.js +9 -0
- package/dist/{baseline-4BDH4F2W.js.map → baseline-2V7PKA7Q.js.map} +1 -1
- package/dist/{chunk-76TDXGGF.js → chunk-3Q3ZXJZP.js} +218 -51
- package/dist/chunk-3Q3ZXJZP.js.map +1 -0
- package/dist/{chunk-G7W4MFPZ.js → chunk-4ACXDVON.js} +4 -4
- package/dist/{chunk-G7W4MFPZ.js.map → chunk-4ACXDVON.js.map} +1 -1
- package/dist/{chunk-E6H2F2XF.js → chunk-6DFV4WCQ.js} +3 -3
- package/dist/{chunk-E6H2F2XF.js.map → chunk-6DFV4WCQ.js.map} +1 -1
- package/dist/{chunk-FF5ZQ6KI.js → chunk-6JP7HGIF.js} +4 -4
- package/dist/{chunk-FF5ZQ6KI.js.map → chunk-6JP7HGIF.js.map} +1 -1
- package/dist/chunk-7KNFG44U.js +6 -0
- package/dist/{chunk-TGDHOAXX.js.map → chunk-7KNFG44U.js.map} +1 -1
- package/dist/{chunk-T6DRYOMT.js → chunk-CPLG4GFB.js} +4 -4
- package/dist/{chunk-T6DRYOMT.js.map → chunk-CPLG4GFB.js.map} +1 -1
- package/dist/{chunk-SDG242R4.js → chunk-HC44772H.js} +132 -365
- package/dist/chunk-HC44772H.js.map +1 -0
- package/dist/{chunk-MPP4S4OE.js → chunk-K6Q6HTFD.js} +32 -11
- package/dist/chunk-K6Q6HTFD.js.map +1 -0
- package/dist/{chunk-7G5S5KZN.js → chunk-KUZLILN3.js} +16 -3
- package/dist/chunk-KUZLILN3.js.map +1 -0
- package/dist/{chunk-XEJJGDGX.js → chunk-KYX2YCXT.js} +134 -9
- package/dist/chunk-KYX2YCXT.js.map +1 -0
- package/dist/{chunk-V2QK3IUY.js → chunk-L5PUNO3T.js} +4 -4
- package/dist/{chunk-V2QK3IUY.js.map → chunk-L5PUNO3T.js.map} +1 -1
- package/dist/{chunk-7PVCHLR2.js → chunk-M452MRWI.js} +109 -10
- package/dist/chunk-M452MRWI.js.map +1 -0
- package/dist/{chunk-WIDZ5IE7.js → chunk-M7773OUN.js} +14 -7
- package/dist/chunk-M7773OUN.js.map +1 -0
- package/dist/{chunk-XRN7DQGR.js → chunk-NJFQCDGA.js} +3 -3
- package/dist/{chunk-XRN7DQGR.js.map → chunk-NJFQCDGA.js.map} +1 -1
- package/dist/{chunk-BNEHDLVZ.js → chunk-NSWEJPLV.js} +129 -20
- package/dist/chunk-NSWEJPLV.js.map +1 -0
- package/dist/{chunk-JLWI2JGA.js → chunk-NUZM7UOR.js} +117 -6
- package/dist/chunk-NUZM7UOR.js.map +1 -0
- package/dist/{chunk-B3OMGYZZ.js → chunk-PXM3VZYR.js} +4 -4
- package/dist/{chunk-B3OMGYZZ.js.map → chunk-PXM3VZYR.js.map} +1 -1
- package/dist/chunk-QMME6TB4.js +457 -0
- package/dist/chunk-QMME6TB4.js.map +1 -0
- package/dist/{chunk-G25STLE7.js → chunk-SJFBXCII.js} +30 -3
- package/dist/chunk-SJFBXCII.js.map +1 -0
- package/dist/{chunk-A43I2AJ4.js → chunk-TM5XQY3L.js} +3 -3
- package/dist/{chunk-A43I2AJ4.js.map → chunk-TM5XQY3L.js.map} +1 -1
- package/dist/{chunk-KL65SSR7.js → chunk-TNADGCOX.js} +323 -152
- package/dist/chunk-TNADGCOX.js.map +1 -0
- package/dist/{chunk-V3X3DBZL.js → chunk-UXR7FBE3.js} +6 -6
- package/dist/{chunk-V3X3DBZL.js.map → chunk-UXR7FBE3.js.map} +1 -1
- package/dist/{chunk-IPICO2RV.js → chunk-VIWZ4QT7.js} +14 -3
- package/dist/chunk-VIWZ4QT7.js.map +1 -0
- package/dist/{chunk-IRCYOTRG.js → chunk-WGPS3NZQ.js} +240 -13
- package/dist/chunk-WGPS3NZQ.js.map +1 -0
- package/dist/{chunk-I6RBAIS3.js → chunk-XK5LKOBF.js} +4 -4
- package/dist/{chunk-I6RBAIS3.js.map → chunk-XK5LKOBF.js.map} +1 -1
- package/dist/cli.js +796 -359
- package/dist/cli.js.map +1 -1
- package/dist/ensure-map-TAVYMPEG.js +29 -0
- package/dist/{ensure-map-SMWHKOUY.js.map → ensure-map-TAVYMPEG.js.map} +1 -1
- package/dist/{graph-backend-I4I72J4W.js → graph-backend-WF4LGBGD.js} +5 -5
- package/dist/{graph-backend-I4I72J4W.js.map → graph-backend-WF4LGBGD.js.map} +1 -1
- package/dist/index.d.ts +143 -7
- package/dist/index.js +17 -16
- package/dist/index.js.map +1 -1
- package/dist/{interactive-TMQR6TXM.js → interactive-6PN237LX.js} +49 -32
- package/dist/interactive-6PN237LX.js.map +1 -0
- package/dist/load-T2FOJUPI.js +10 -0
- package/dist/{load-E3OTM7BS.js.map → load-T2FOJUPI.js.map} +1 -1
- package/dist/model-manager-GJ2YSTSK.js +1 -1
- package/dist/{run-outcome-QWLNBASF.js → run-outcome-AMIKAASL.js} +6 -6
- package/dist/{run-outcome-QWLNBASF.js.map → run-outcome-AMIKAASL.js.map} +1 -1
- package/dist/runtime-session-QAVOPSSH.js +20 -0
- package/dist/{runtime-session-UQ7UVAPL.js.map → runtime-session-QAVOPSSH.js.map} +1 -1
- package/dist/session-SCHQQTHN.js +15 -0
- package/dist/{session-MG6BJVAG.js.map → session-SCHQQTHN.js.map} +1 -1
- package/dist/session-store-F7NX7SZN.js +4 -0
- package/dist/{session-store-SQECEXUU.js.map → session-store-F7NX7SZN.js.map} +1 -1
- package/dist/{stream-json-GM44SP7L.js → stream-json-A6K2MONY.js} +48 -16
- package/dist/stream-json-A6K2MONY.js.map +1 -0
- package/dist/{vg-mcp-bridge-3WFC7LGE.js → vg-mcp-bridge-3TSFOL4V.js} +13 -11
- package/dist/vg-mcp-bridge-3TSFOL4V.js.map +1 -0
- package/dist/{vgd-ZUSBEVUL.js → vgd-B67JCNJP.js} +9 -9
- package/dist/vgd-B67JCNJP.js.map +1 -0
- package/package.json +1 -1
- package/dist/agent-4DAECASW.js +0 -22
- package/dist/baseline-4BDH4F2W.js +0 -9
- package/dist/chunk-76TDXGGF.js.map +0 -1
- package/dist/chunk-7G5S5KZN.js.map +0 -1
- package/dist/chunk-7PVCHLR2.js.map +0 -1
- package/dist/chunk-BNEHDLVZ.js.map +0 -1
- package/dist/chunk-G25STLE7.js.map +0 -1
- package/dist/chunk-IPICO2RV.js.map +0 -1
- package/dist/chunk-IRCYOTRG.js.map +0 -1
- package/dist/chunk-JLWI2JGA.js.map +0 -1
- package/dist/chunk-KL65SSR7.js.map +0 -1
- package/dist/chunk-MPP4S4OE.js.map +0 -1
- package/dist/chunk-SDG242R4.js.map +0 -1
- package/dist/chunk-TGDHOAXX.js +0 -6
- package/dist/chunk-WIDZ5IE7.js.map +0 -1
- package/dist/chunk-XEJJGDGX.js.map +0 -1
- package/dist/chunk-ZKNB4YH4.js +0 -102
- package/dist/chunk-ZKNB4YH4.js.map +0 -1
- package/dist/ensure-map-SMWHKOUY.js +0 -28
- package/dist/interactive-TMQR6TXM.js.map +0 -1
- package/dist/load-E3OTM7BS.js +0 -10
- package/dist/runtime-session-UQ7UVAPL.js +0 -20
- package/dist/session-MG6BJVAG.js +0 -13
- package/dist/session-store-SQECEXUU.js +0 -4
- package/dist/stream-json-GM44SP7L.js.map +0 -1
- package/dist/vg-mcp-bridge-3WFC7LGE.js.map +0 -1
- package/dist/vgd-ZUSBEVUL.js.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { CONTEXT_POLICY_VERSION, DISCOVERY_TOOLS, MUTATION_TOOLS, compact, compactWithModel, runAgent } from './chunk-WGPS3NZQ.js';
|
|
2
|
+
import './chunk-543E6WDJ.js';
|
|
3
|
+
import './chunk-SJFBXCII.js';
|
|
4
|
+
import './chunk-REIGWTTH.js';
|
|
5
|
+
import './chunk-TM5XQY3L.js';
|
|
6
|
+
import './chunk-RBIRXQR6.js';
|
|
7
|
+
import './chunk-5HYCB55P.js';
|
|
8
|
+
export { summarizeCapsule } from './chunk-K6Q6HTFD.js';
|
|
9
|
+
import './chunk-VIWZ4QT7.js';
|
|
10
|
+
import './chunk-XK5LKOBF.js';
|
|
11
|
+
import './chunk-3LSG7Z4I.js';
|
|
12
|
+
import './chunk-J7LKEB2R.js';
|
|
13
|
+
import './chunk-HC44772H.js';
|
|
14
|
+
import './chunk-UTNNGKKX.js';
|
|
15
|
+
import './chunk-RXP66R2E.js';
|
|
16
|
+
import './chunk-3Q3ZXJZP.js';
|
|
17
|
+
import './chunk-7KNFG44U.js';
|
|
18
|
+
import './chunk-QMME6TB4.js';
|
|
19
|
+
import './chunk-BWPBB45M.js';
|
|
20
|
+
import './chunk-JFGYT6BI.js';
|
|
21
|
+
import './chunk-BPF3YX2U.js';
|
|
22
|
+
import './chunk-Z6ZWNWWR.js';
|
|
23
|
+
//# sourceMappingURL=agent-JTA4YWMQ.js.map
|
|
24
|
+
//# sourceMappingURL=agent-JTA4YWMQ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"agent-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"agent-JTA4YWMQ.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { baselineCommand, runBaseline } from './chunk-6JP7HGIF.js';
|
|
2
|
+
import './chunk-NJFQCDGA.js';
|
|
3
|
+
import './chunk-DT4KIVRI.js';
|
|
4
|
+
import './chunk-CRAMOEBE.js';
|
|
5
|
+
import './chunk-RXP66R2E.js';
|
|
6
|
+
import './chunk-7KNFG44U.js';
|
|
7
|
+
import './chunk-Z6ZWNWWR.js';
|
|
8
|
+
//# sourceMappingURL=baseline-2V7PKA7Q.js.map
|
|
9
|
+
//# sourceMappingURL=baseline-2V7PKA7Q.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"baseline-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"baseline-2V7PKA7Q.js"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { VERSION } from './chunk-
|
|
2
|
-
import { parseGraph, stableStringify, serializeGraph } from './chunk-
|
|
1
|
+
import { VERSION } from './chunk-7KNFG44U.js';
|
|
2
|
+
import { parseGraph, stableStringify, WEAK_TERMS, serializeGraph } from './chunk-QMME6TB4.js';
|
|
3
3
|
import { globalGraphPathForRef, globalGraphPath, repositoryStoreDir } from './chunk-BWPBB45M.js';
|
|
4
4
|
import { detectGitRef } from './chunk-BPF3YX2U.js';
|
|
5
|
-
import * as
|
|
5
|
+
import * as fs3 from 'fs';
|
|
6
6
|
import * as zlib from 'zlib';
|
|
7
7
|
import { Packr } from 'msgpackr';
|
|
8
|
-
import * as
|
|
8
|
+
import * as os from 'os';
|
|
9
|
+
import * as path2 from 'path';
|
|
10
|
+
import { pathToFileURL } from 'url';
|
|
9
11
|
|
|
10
12
|
var MAGIC = Buffer.from("VGSNAP1\0", "latin1");
|
|
11
13
|
var crc322 = zlib.crc32 ?? jsCrc32;
|
|
@@ -43,7 +45,7 @@ function writeGraphSnapshot(graphPath, graph, opts = {}) {
|
|
|
43
45
|
standalone: true
|
|
44
46
|
});
|
|
45
47
|
} else {
|
|
46
|
-
const stat =
|
|
48
|
+
const stat = fs3.statSync(graphPath);
|
|
47
49
|
header = newPackr().pack({
|
|
48
50
|
engine: VERSION,
|
|
49
51
|
sourceSize: stat.size,
|
|
@@ -56,10 +58,10 @@ function writeGraphSnapshot(graphPath, graph, opts = {}) {
|
|
|
56
58
|
const file = snapshotPathFor(graphPath);
|
|
57
59
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
58
60
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
fs3.writeFileSync(tmp, Buffer.concat([MAGIC, lenBuf, header, payload]));
|
|
62
|
+
fs3.renameSync(tmp, file);
|
|
61
63
|
} catch (err) {
|
|
62
|
-
|
|
64
|
+
fs3.rmSync(tmp, { force: true });
|
|
63
65
|
throw err;
|
|
64
66
|
}
|
|
65
67
|
return true;
|
|
@@ -70,8 +72,8 @@ function writeGraphSnapshot(graphPath, graph, opts = {}) {
|
|
|
70
72
|
function readGraphSnapshot(graphPath) {
|
|
71
73
|
try {
|
|
72
74
|
const file = snapshotPathFor(graphPath);
|
|
73
|
-
if (!
|
|
74
|
-
const raw =
|
|
75
|
+
if (!fs3.existsSync(file)) return null;
|
|
76
|
+
const raw = fs3.readFileSync(file);
|
|
75
77
|
if (raw.length < MAGIC.length + 4 || !raw.subarray(0, MAGIC.length).equals(MAGIC)) return null;
|
|
76
78
|
const headerLen = raw.readUInt32LE(MAGIC.length);
|
|
77
79
|
const payloadStart = MAGIC.length + 4 + headerLen;
|
|
@@ -79,7 +81,7 @@ function readGraphSnapshot(graphPath) {
|
|
|
79
81
|
const header = newPackr().unpack(raw.subarray(MAGIC.length + 4, payloadStart));
|
|
80
82
|
if (!header.standalone) {
|
|
81
83
|
if (header.engine !== VERSION) return null;
|
|
82
|
-
const sourceStat =
|
|
84
|
+
const sourceStat = fs3.statSync(graphPath);
|
|
83
85
|
if (header.sourceSize !== sourceStat.size || header.sourceMtimeMs !== sourceStat.mtimeMs) return null;
|
|
84
86
|
}
|
|
85
87
|
const payload = raw.subarray(payloadStart);
|
|
@@ -92,24 +94,24 @@ function readGraphSnapshot(graphPath) {
|
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
function mapFileExists(graphPath) {
|
|
95
|
-
if (
|
|
97
|
+
if (fs3.existsSync(graphPath)) return true;
|
|
96
98
|
return readSnapshotHeader(snapshotPathFor(graphPath))?.standalone === true;
|
|
97
99
|
}
|
|
98
100
|
function mapFileStat(graphPath) {
|
|
99
101
|
try {
|
|
100
|
-
return
|
|
102
|
+
return fs3.statSync(graphPath);
|
|
101
103
|
} catch (err) {
|
|
102
104
|
const snap = snapshotPathFor(graphPath);
|
|
103
|
-
if (
|
|
105
|
+
if (fs3.existsSync(snap)) return fs3.statSync(snap);
|
|
104
106
|
throw err;
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
function readSnapshotHeader(file) {
|
|
108
110
|
let fd = null;
|
|
109
111
|
try {
|
|
110
|
-
fd =
|
|
112
|
+
fd = fs3.openSync(file, "r");
|
|
111
113
|
const prefix = Buffer.alloc(4096);
|
|
112
|
-
const read =
|
|
114
|
+
const read = fs3.readSync(fd, prefix, 0, prefix.length, 0);
|
|
113
115
|
if (read < MAGIC.length + 4 || !prefix.subarray(0, MAGIC.length).equals(MAGIC)) return null;
|
|
114
116
|
const headerLen = prefix.readUInt32LE(MAGIC.length);
|
|
115
117
|
if (MAGIC.length + 4 + headerLen > read) return null;
|
|
@@ -117,7 +119,7 @@ function readSnapshotHeader(file) {
|
|
|
117
119
|
} catch {
|
|
118
120
|
return null;
|
|
119
121
|
} finally {
|
|
120
|
-
if (fd !== null)
|
|
122
|
+
if (fd !== null) fs3.closeSync(fd);
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
125
|
function loadGraphFileWithSnapshot(graphPath) {
|
|
@@ -125,7 +127,7 @@ function loadGraphFileWithSnapshot(graphPath) {
|
|
|
125
127
|
if (snap) return snap;
|
|
126
128
|
let json;
|
|
127
129
|
try {
|
|
128
|
-
json =
|
|
130
|
+
json = fs3.readFileSync(graphPath, "utf8");
|
|
129
131
|
} catch {
|
|
130
132
|
return null;
|
|
131
133
|
}
|
|
@@ -290,11 +292,85 @@ ${embedded}
|
|
|
290
292
|
function esc(s) {
|
|
291
293
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
292
294
|
}
|
|
295
|
+
var MAX_PROVIDER_EXPANSIONS = 24;
|
|
296
|
+
function disabled() {
|
|
297
|
+
const v = process.env.VIBGRATE_NO_KERNEL;
|
|
298
|
+
return v === "1" || v === "true";
|
|
299
|
+
}
|
|
300
|
+
function relevanceModuleDir() {
|
|
301
|
+
const base = process.env.XDG_CACHE_HOME || path2.join(os.homedir(), ".cache");
|
|
302
|
+
return path2.join(base, "vibgrate", "modules", "relevance");
|
|
303
|
+
}
|
|
304
|
+
function defaultModulePath() {
|
|
305
|
+
return path2.join(relevanceModuleDir(), "index.js");
|
|
306
|
+
}
|
|
307
|
+
function candidatePaths() {
|
|
308
|
+
const custom = process.env.VIBGRATE_RELEVANCE_PATH;
|
|
309
|
+
if (custom) {
|
|
310
|
+
const p = path2.resolve(custom);
|
|
311
|
+
try {
|
|
312
|
+
if (fs3.statSync(p).isDirectory()) return [path2.join(p, "index.js")];
|
|
313
|
+
} catch {
|
|
314
|
+
}
|
|
315
|
+
return [p];
|
|
316
|
+
}
|
|
317
|
+
return [defaultModulePath()];
|
|
318
|
+
}
|
|
319
|
+
var cached;
|
|
320
|
+
function resetRelevanceProviderCache() {
|
|
321
|
+
cached = void 0;
|
|
322
|
+
}
|
|
323
|
+
async function loadRelevanceProvider() {
|
|
324
|
+
if (cached !== void 0) return cached;
|
|
325
|
+
cached = null;
|
|
326
|
+
if (disabled()) return cached;
|
|
327
|
+
for (const p of candidatePaths()) {
|
|
328
|
+
if (!fs3.existsSync(p)) continue;
|
|
329
|
+
try {
|
|
330
|
+
const mod = await import(pathToFileURL(p).href);
|
|
331
|
+
const provider = mod.createRelevanceProvider?.();
|
|
332
|
+
if (provider && typeof provider.version === "function" && typeof provider.analyzeQuery === "function") {
|
|
333
|
+
cached = provider;
|
|
334
|
+
return cached;
|
|
335
|
+
}
|
|
336
|
+
} catch {
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return cached;
|
|
340
|
+
}
|
|
341
|
+
async function analyzeQuestion(question) {
|
|
342
|
+
const provider = await loadRelevanceProvider();
|
|
343
|
+
if (!provider) return null;
|
|
344
|
+
try {
|
|
345
|
+
return sanitizeAnalysis(provider.analyzeQuery(question));
|
|
346
|
+
} catch {
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function sanitizeAnalysis(raw) {
|
|
351
|
+
if (!raw || typeof raw.version !== "string") return null;
|
|
352
|
+
const seen = /* @__PURE__ */ new Set();
|
|
353
|
+
const expansions = [];
|
|
354
|
+
for (const e of raw.expansions ?? []) {
|
|
355
|
+
const term = String(e?.term ?? "").toLowerCase().trim();
|
|
356
|
+
const from = String(e?.from ?? "").toLowerCase().trim();
|
|
357
|
+
const weight = Number(e?.weight);
|
|
358
|
+
if (!term || !from || term.includes(" ")) continue;
|
|
359
|
+
if (WEAK_TERMS.has(from) || WEAK_TERMS.has(term)) continue;
|
|
360
|
+
if (!Number.isFinite(weight) || weight <= 0) continue;
|
|
361
|
+
if (seen.has(term)) continue;
|
|
362
|
+
seen.add(term);
|
|
363
|
+
expansions.push({ term, from, weight: Math.min(1, weight) });
|
|
364
|
+
if (expansions.length >= MAX_PROVIDER_EXPANSIONS) break;
|
|
365
|
+
}
|
|
366
|
+
const topics = (raw.topics ?? []).filter((t) => t && typeof t.id === "string" && Number.isFinite(t.score)).map((t) => ({ id: t.id, score: Math.max(0, Math.min(1, t.score)) }));
|
|
367
|
+
return { version: raw.version, topics, expansions };
|
|
368
|
+
}
|
|
293
369
|
function vibgrateDir(root) {
|
|
294
|
-
return
|
|
370
|
+
return path2.join(root, ".vibgrate");
|
|
295
371
|
}
|
|
296
372
|
function legacyGraphPath(root) {
|
|
297
|
-
return
|
|
373
|
+
return path2.join(vibgrateDir(root), "graph.json");
|
|
298
374
|
}
|
|
299
375
|
function preferInRepoGraph(env = process.env) {
|
|
300
376
|
const v = env.VIBGRATE_GRAPH_IN_REPO?.trim().toLowerCase();
|
|
@@ -307,10 +383,10 @@ function defaultGraphPath(root, env = process.env) {
|
|
|
307
383
|
return globalGraphPath(root, "current", env);
|
|
308
384
|
}
|
|
309
385
|
function resolveGraphPath(root, override, env = process.env) {
|
|
310
|
-
if (override?.trim()) return
|
|
386
|
+
if (override?.trim()) return path2.resolve(override.trim());
|
|
311
387
|
if (preferInRepoGraph(env)) {
|
|
312
388
|
const legacy2 = legacyGraphPath(root);
|
|
313
|
-
if (
|
|
389
|
+
if (fs3.existsSync(legacy2)) return legacy2;
|
|
314
390
|
return legacy2;
|
|
315
391
|
}
|
|
316
392
|
const { ref, kind } = detectGitRef(root);
|
|
@@ -321,7 +397,7 @@ function resolveGraphPath(root, override, env = process.env) {
|
|
|
321
397
|
const globalPath = globalGraphPath(root, "current", env);
|
|
322
398
|
if (mapFileExists(globalPath)) return globalPath;
|
|
323
399
|
const legacy = legacyGraphPath(root);
|
|
324
|
-
if (
|
|
400
|
+
if (fs3.existsSync(legacy)) return legacy;
|
|
325
401
|
return defaultGraphPath(root, env);
|
|
326
402
|
}
|
|
327
403
|
var DEFAULT_GITIGNORE = [
|
|
@@ -333,6 +409,7 @@ var DEFAULT_GITIGNORE = [
|
|
|
333
409
|
"cache/",
|
|
334
410
|
"graph.json",
|
|
335
411
|
"graph.snap",
|
|
412
|
+
"graph.tags.snap",
|
|
336
413
|
"graph.html",
|
|
337
414
|
"GRAPH_REPORT.md",
|
|
338
415
|
"facts.jsonl",
|
|
@@ -346,73 +423,163 @@ var DEFAULT_GITIGNORE = [
|
|
|
346
423
|
"run-outcomes.jsonl"
|
|
347
424
|
];
|
|
348
425
|
function ensureVibgrateGitignore(root) {
|
|
349
|
-
const file =
|
|
350
|
-
if (
|
|
351
|
-
|
|
352
|
-
|
|
426
|
+
const file = path2.join(vibgrateDir(root), ".gitignore");
|
|
427
|
+
if (fs3.existsSync(file)) return;
|
|
428
|
+
fs3.mkdirSync(vibgrateDir(root), { recursive: true });
|
|
429
|
+
fs3.writeFileSync(file, `${DEFAULT_GITIGNORE.join("\n")}
|
|
353
430
|
`);
|
|
354
431
|
}
|
|
355
432
|
function companionArtifactDir(root, graphPath, env = process.env) {
|
|
356
|
-
const resolved =
|
|
357
|
-
const legacy =
|
|
433
|
+
const resolved = path2.resolve(graphPath);
|
|
434
|
+
const legacy = path2.resolve(legacyGraphPath(root));
|
|
358
435
|
if (resolved === legacy) return vibgrateDir(root);
|
|
359
|
-
const globalDefault =
|
|
436
|
+
const globalDefault = path2.resolve(globalGraphPath(root, "current", env));
|
|
360
437
|
if (resolved === globalDefault) return repositoryStoreDir(root, env);
|
|
361
|
-
return
|
|
438
|
+
return path2.dirname(resolved);
|
|
362
439
|
}
|
|
363
440
|
function writeArtifacts(graph, options) {
|
|
364
441
|
const graphPath = options.graphPath ?? defaultGraphPath(options.root);
|
|
365
442
|
const companions = companionArtifactDir(options.root, graphPath);
|
|
366
443
|
const inRepo = isPathInside(companions, options.root) || isPathInside(graphPath, options.root);
|
|
367
|
-
|
|
368
|
-
|
|
444
|
+
fs3.mkdirSync(path2.dirname(graphPath), { recursive: true });
|
|
445
|
+
fs3.mkdirSync(companions, { recursive: true });
|
|
369
446
|
if (inRepo && isPathInside(companions, vibgrateDir(options.root))) {
|
|
370
447
|
ensureVibgrateGitignore(options.root);
|
|
371
|
-
} else if (
|
|
448
|
+
} else if (path2.resolve(graphPath) === path2.resolve(legacyGraphPath(options.root))) {
|
|
372
449
|
ensureVibgrateGitignore(options.root);
|
|
373
450
|
}
|
|
374
451
|
const storeMode = isPathInside(graphPath, repositoryStoreDir(options.root));
|
|
452
|
+
deleteTagsSidecarFor(graphPath);
|
|
375
453
|
if (storeMode) {
|
|
376
454
|
if (!writeGraphSnapshot(graphPath, graph, { standalone: true })) ; else {
|
|
377
|
-
|
|
455
|
+
fs3.rmSync(graphPath, { force: true });
|
|
378
456
|
}
|
|
379
457
|
}
|
|
380
|
-
if (!storeMode || !
|
|
458
|
+
if (!storeMode || !fs3.existsSync(snapshotPathFor(graphPath))) {
|
|
381
459
|
const tmp = `${graphPath}.${process.pid}.tmp`;
|
|
382
460
|
try {
|
|
383
|
-
|
|
384
|
-
|
|
461
|
+
fs3.writeFileSync(tmp, serializeGraph(graph));
|
|
462
|
+
fs3.renameSync(tmp, graphPath);
|
|
385
463
|
} catch (err) {
|
|
386
|
-
|
|
464
|
+
fs3.rmSync(tmp, { force: true });
|
|
387
465
|
throw err;
|
|
388
466
|
}
|
|
389
467
|
writeGraphSnapshot(graphPath, graph);
|
|
390
468
|
}
|
|
391
469
|
const written = {
|
|
392
|
-
graphPath: storeMode && !
|
|
470
|
+
graphPath: storeMode && !fs3.existsSync(graphPath) ? snapshotPathFor(graphPath) : graphPath
|
|
393
471
|
};
|
|
394
472
|
if (options.report !== false) {
|
|
395
|
-
const reportPath =
|
|
396
|
-
|
|
473
|
+
const reportPath = path2.join(companions, "GRAPH_REPORT.md");
|
|
474
|
+
fs3.writeFileSync(reportPath, renderReport(graph));
|
|
397
475
|
written.reportPath = reportPath;
|
|
398
476
|
}
|
|
399
477
|
if (options.html !== false) {
|
|
400
|
-
const htmlPath =
|
|
401
|
-
|
|
478
|
+
const htmlPath = path2.join(companions, "graph.html");
|
|
479
|
+
fs3.writeFileSync(htmlPath, renderHtml(graph));
|
|
402
480
|
written.htmlPath = htmlPath;
|
|
403
481
|
}
|
|
404
482
|
if (graph.facts && graph.facts.length) {
|
|
405
|
-
const factsPath =
|
|
406
|
-
|
|
483
|
+
const factsPath = path2.join(companions, "facts.jsonl");
|
|
484
|
+
fs3.writeFileSync(factsPath, graph.facts.map((f) => JSON.stringify(f)).join("\n") + "\n");
|
|
407
485
|
written.factsPath = factsPath;
|
|
408
486
|
}
|
|
409
487
|
return written;
|
|
410
488
|
}
|
|
411
489
|
function isPathInside(child, parent) {
|
|
412
|
-
const rel =
|
|
413
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
490
|
+
const rel = path2.relative(path2.resolve(parent), path2.resolve(child));
|
|
491
|
+
return rel === "" || !rel.startsWith("..") && !path2.isAbsolute(rel);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/engine/relevance-enrich.ts
|
|
495
|
+
var MAGIC2 = Buffer.from("VGTAGS1\0", "latin1");
|
|
496
|
+
var crc324 = zlib.crc32 ?? (() => 0);
|
|
497
|
+
function newPackr2() {
|
|
498
|
+
return new Packr({ useRecords: true });
|
|
499
|
+
}
|
|
500
|
+
function tagsSidecarPathFor(graphPath) {
|
|
501
|
+
return graphPath.endsWith(".json") ? `${graphPath.slice(0, -5)}.tags.snap` : `${graphPath}.tags.snap`;
|
|
502
|
+
}
|
|
503
|
+
function deleteTagsSidecarFor(graphPath) {
|
|
504
|
+
try {
|
|
505
|
+
fs3.rmSync(tagsSidecarPathFor(graphPath), { force: true });
|
|
506
|
+
} catch {
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
function readSidecar(file, expect) {
|
|
510
|
+
try {
|
|
511
|
+
if (!fs3.existsSync(file)) return null;
|
|
512
|
+
const raw = fs3.readFileSync(file);
|
|
513
|
+
if (raw.length < MAGIC2.length + 4 || !raw.subarray(0, MAGIC2.length).equals(MAGIC2)) return null;
|
|
514
|
+
const headerLen = raw.readUInt32LE(MAGIC2.length);
|
|
515
|
+
const headerStart = MAGIC2.length + 4;
|
|
516
|
+
if (raw.length < headerStart + headerLen) return null;
|
|
517
|
+
const header = newPackr2().unpack(raw.subarray(headerStart, headerStart + headerLen));
|
|
518
|
+
if (header.engine !== VERSION) return null;
|
|
519
|
+
if (header.provider !== expect.provider) return null;
|
|
520
|
+
if (header.corpusHash !== expect.corpusHash) return null;
|
|
521
|
+
const payload = raw.subarray(headerStart + headerLen);
|
|
522
|
+
if (crc324(payload) >>> 0 !== header.crc32 >>> 0) return null;
|
|
523
|
+
const tags = newPackr2().unpack(payload);
|
|
524
|
+
return tags && typeof tags === "object" ? tags : null;
|
|
525
|
+
} catch {
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
function writeSidecar(file, meta, tags) {
|
|
530
|
+
try {
|
|
531
|
+
const sorted = Object.fromEntries(Object.entries(tags).sort(([a], [b]) => a < b ? -1 : 1));
|
|
532
|
+
const payload = newPackr2().pack(sorted);
|
|
533
|
+
const header = newPackr2().pack({
|
|
534
|
+
engine: VERSION,
|
|
535
|
+
provider: meta.provider,
|
|
536
|
+
corpusHash: meta.corpusHash,
|
|
537
|
+
crc32: crc324(payload) >>> 0
|
|
538
|
+
});
|
|
539
|
+
const lenBuf = Buffer.alloc(4);
|
|
540
|
+
lenBuf.writeUInt32LE(header.length);
|
|
541
|
+
fs3.mkdirSync(path2.dirname(file), { recursive: true });
|
|
542
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
543
|
+
fs3.writeFileSync(tmp, Buffer.concat([MAGIC2, lenBuf, Buffer.from(header), Buffer.from(payload)]));
|
|
544
|
+
fs3.renameSync(tmp, file);
|
|
545
|
+
} catch {
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
async function loadTopicTags(graph, root, graphPath) {
|
|
549
|
+
const provider = await loadRelevanceProvider();
|
|
550
|
+
if (!provider?.tagNode) return null;
|
|
551
|
+
let providerVersion;
|
|
552
|
+
try {
|
|
553
|
+
providerVersion = provider.version();
|
|
554
|
+
} catch {
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
const corpusHash = graph.provenance?.corpusHash;
|
|
558
|
+
if (!corpusHash) return null;
|
|
559
|
+
const file = tagsSidecarPathFor(graphPath?.trim() ? path2.resolve(graphPath) : resolveGraphPath(root));
|
|
560
|
+
const cached2 = readSidecar(file, { provider: providerVersion, corpusHash });
|
|
561
|
+
if (cached2) {
|
|
562
|
+
const tags2 = /* @__PURE__ */ new Map();
|
|
563
|
+
for (const [id, t] of Object.entries(cached2)) if (t.length) tags2.set(id, t);
|
|
564
|
+
return tags2;
|
|
565
|
+
}
|
|
566
|
+
const record = {};
|
|
567
|
+
const tags = /* @__PURE__ */ new Map();
|
|
568
|
+
try {
|
|
569
|
+
for (const node of graph.nodes) {
|
|
570
|
+
if (node.kind === "file" || node.kind === "external") continue;
|
|
571
|
+
const computed = provider.tagNode({ qualifiedName: node.qualifiedName, file: node.file }) ?? [];
|
|
572
|
+
const clean = computed.filter((t) => typeof t === "string" && t.length > 0).map((t) => t.toLowerCase()).slice(0, 3);
|
|
573
|
+
record[node.id] = clean;
|
|
574
|
+
if (clean.length) tags.set(node.id, clean);
|
|
575
|
+
}
|
|
576
|
+
} catch {
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
writeSidecar(file, { provider: providerVersion, corpusHash }, record);
|
|
580
|
+
return tags;
|
|
414
581
|
}
|
|
415
582
|
|
|
416
|
-
export { defaultGraphPath, ensureVibgrateGitignore, legacyGraphPath, loadGraphFileWithSnapshot, mapFileExists, mapFileStat, preferInRepoGraph, renderHtml, renderReport, resolveGraphPath, vibgrateDir, writeArtifacts };
|
|
417
|
-
//# sourceMappingURL=chunk-
|
|
418
|
-
//# sourceMappingURL=chunk-
|
|
583
|
+
export { analyzeQuestion, defaultGraphPath, ensureVibgrateGitignore, legacyGraphPath, loadGraphFileWithSnapshot, loadRelevanceProvider, loadTopicTags, mapFileExists, mapFileStat, preferInRepoGraph, relevanceModuleDir, renderHtml, renderReport, resetRelevanceProviderCache, resolveGraphPath, vibgrateDir, writeArtifacts };
|
|
584
|
+
//# sourceMappingURL=chunk-3Q3ZXJZP.js.map
|
|
585
|
+
//# sourceMappingURL=chunk-3Q3ZXJZP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine/snapshot.ts","../src/engine/report.ts","../src/engine/html.ts","../src/engine/relevance-provider.ts","../src/engine/artifacts.ts","../src/engine/relevance-enrich.ts"],"names":["crc32","fs","path","fs2","legacy","MAGIC","zlib2","newPackr","Packr","fs4","path3","cached","tags"],"mappings":";;;;;;;;;;;AAsCA,IAAM,KAAA,GAAQ,MAAA,CAAO,IAAA,CAAK,WAAA,EAAa,QAAQ,CAAA;AAG/C,IAAMA,SAA2C,IAAA,CAAA,KAAA,IAAS,OAAA;AAE1D,IAAI,QAAA,GAA+B,IAAA;AAEnC,SAAS,QAAQ,IAAA,EAA0B;AACzC,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,QAAA,GAAW,IAAI,YA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,MAAA,MAAM,QAAA,GAAW,QAAA,CAAS,OAAA,CAAQ,EAAE,aAAA,EAAe,IAAA,CAAK,aAAA,EAAe,IAAA,EAAM,IAAA,CAAK,IAAA,EAAM,CAAA,IAAK,EAAC;AAE9F,MAAA,MAAM,KAAA,GAAQ,SACX,MAAA,CAAO,CAAC,MAAM,OAAO,CAAA,KAAM,YAAY,CAAA,CAAE,MAAA,GAAS,CAAC,CAAA,CACnD,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,aAAa,CAAA,CAC1B,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA;AACb,MAAA,MAAA,CAAO,IAAA,CAAK,EAAE,CAAA,GAAI,KAAA;AAClB,MAAA,IAAI,MAAM,MAAA,EAAQ,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,IAAI,KAAK,CAAA;AAAA,IAC3C;AAAA,EACF,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,YAAA,CAAa,MAAM,EAAE,QAAA,EAAU,eAAA,EAAiB,UAAA,IAAc,MAAM,CAAA;AACpE,EAAA,OAAO,IAAA;AACT","file":"chunk-3Q3ZXJZP.js","sourcesContent":["import * as fs from 'node:fs';\nimport * as zlib from 'node:zlib';\nimport { Packr } from 'msgpackr';\nimport { parseGraph } from './serialize.js';\nimport { VERSION } from '../version.js';\nimport type { VgGraph } from '../schema.js';\n\n/**\n * Binary graph snapshot — a derived, local **cache** beside `graph.json`.\n *\n * `graph.json` stays the canonical, committed, human-diffable artifact and the\n * only interchange format (`vg export` / `share` / `bundle` are unchanged); the\n * determinism contract attaches to it, not to this file. The snapshot exists\n * purely so hot paths (`vg ask`/`serve`/`code`, vgd session attach) skip the\n * large-string `JSON.parse` on load and the pretty-print on write — measured\n * ~2.6× faster cold load and ~4× faster encode on XL maps, at ~40% of the size.\n *\n * Robustness rules (each one keeps JSON as the unquestioned fallback):\n * - The loader trusts a snapshot only when its recorded (size, mtimeMs) of\n * the source `graph.json` still match — any rebuild or hand-edit of the\n * JSON silently invalidates it. Staleness never needs to parse the JSON.\n * - A CRC-32 over the payload rejects torn/corrupted files; any decode error\n * (unknown magic, short file, bad msgpack, version skew) returns null\n * rather than throwing, and the caller re-reads JSON and rewrites the\n * snapshot (\"self-healing\" — first load after upgrade migrates for free).\n * - Writes are atomic (temp + rename) and best-effort: a full disk or\n * read-only store must never fail a build or a query.\n * - The engine VERSION is recorded and must match: the msgpack record layout\n * tracks the in-memory graph shape, which may change between releases.\n *\n * Format: MAGIC (\"VGSNAP1\\0\") · u32LE header length · msgpack header\n * {engine, sourceSize, sourceMtimeMs, crc32} · msgpack graph payload.\n * Everything is explicit little-endian via DataView/Buffer — no platform\n * variance. msgpackr runs its pure-JS path (its native accelerator is an\n * optional dependency we do not rely on); a fresh Packr per encode/decode\n * keeps record-id assignment deterministic for identical input.\n */\n\nconst MAGIC = Buffer.from('VGSNAP1\\0', 'latin1');\n\n/** node:zlib gained crc32 in 22.2; fall back to a table crc for 22.0/22.1. */\nconst crc32: (data: Uint8Array) => number = zlib.crc32 ?? jsCrc32;\n\nlet crcTable: Uint32Array | null = null;\n\nfunction jsCrc32(data: Uint8Array): number {\n if (!crcTable) {\n crcTable = new Uint32Array(256);\n for (let n = 0; n < 256; n++) {\n let c = n;\n for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;\n crcTable[n] = c >>> 0;\n }\n }\n let crc = 0xffffffff;\n for (let i = 0; i < data.length; i++) crc = crcTable[(crc ^ data[i]) & 0xff] ^ (crc >>> 8);\n return (crc ^ 0xffffffff) >>> 0;\n}\n\ninterface SnapshotHeader {\n engine: string;\n crc32: number;\n /**\n * True when the snapshot IS the map (global-store mode, no graph.json\n * beside it). False/absent = sidecar of a canonical graph.json, valid only\n * while that JSON's recorded stat still matches.\n */\n standalone?: boolean;\n sourceSize?: number;\n sourceMtimeMs?: number;\n}\n\n/** Sidecar path for a map file: `…/graph.json` → `…/graph.snap`. */\nexport function snapshotPathFor(graphPath: string): string {\n return graphPath.endsWith('.json') ? `${graphPath.slice(0, -5)}.snap` : `${graphPath}.snap`;\n}\n\nfunction newPackr(): Packr {\n return new Packr({ useRecords: true });\n}\n\n/** Msgpack payload bytes for a graph (exported for the determinism test). */\nexport function encodeGraphPayload(graph: VgGraph): Buffer {\n return Buffer.from(newPackr().pack(graph));\n}\n\n/**\n * Write the snapshot beside `graphPath`.\n *\n * Sidecar mode (default): call after `graph.json` is on disk — the header\n * records its stat so readers can cheaply detect staleness.\n * `standalone: true` (global-store mode): the snapshot IS the map; no\n * `graph.json` is required or consulted.\n * Best-effort: returns false (never throws) when the file can't be written.\n */\nexport function writeGraphSnapshot(\n graphPath: string,\n graph: VgGraph,\n opts: { standalone?: boolean } = {},\n): boolean {\n try {\n const payload = encodeGraphPayload(graph);\n let header: Buffer;\n if (opts.standalone) {\n header = newPackr().pack({\n engine: VERSION,\n crc32: crc32(payload),\n standalone: true,\n } satisfies SnapshotHeader);\n } else {\n const stat = fs.statSync(graphPath);\n header = newPackr().pack({\n engine: VERSION,\n sourceSize: stat.size,\n sourceMtimeMs: stat.mtimeMs,\n crc32: crc32(payload),\n } satisfies SnapshotHeader);\n }\n const lenBuf = Buffer.alloc(4);\n lenBuf.writeUInt32LE(header.length, 0);\n const file = snapshotPathFor(graphPath);\n const tmp = `${file}.${process.pid}.tmp`;\n try {\n fs.writeFileSync(tmp, Buffer.concat([MAGIC, lenBuf, header, payload]));\n fs.renameSync(tmp, file);\n } catch (err) {\n fs.rmSync(tmp, { force: true });\n throw err;\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Load the snapshot for `graphPath`, or null when it is absent, stale,\n * or corrupted.\n *\n * Sidecar snapshots additionally require their source `graph.json` to exist\n * with an unchanged stat AND an identical engine version — the JSON fallback\n * is free, so any doubt invalidates. Standalone snapshots are the map itself:\n * they are accepted on magic + CRC + a structural sanity check, including\n * across engine versions (msgpack embeds its record layout, so an older\n * snapshot decodes the same way an older committed graph.json would parse).\n */\nexport function readGraphSnapshot(graphPath: string): VgGraph | null {\n try {\n const file = snapshotPathFor(graphPath);\n if (!fs.existsSync(file)) return null;\n const raw = fs.readFileSync(file);\n if (raw.length < MAGIC.length + 4 || !raw.subarray(0, MAGIC.length).equals(MAGIC)) return null;\n const headerLen = raw.readUInt32LE(MAGIC.length);\n const payloadStart = MAGIC.length + 4 + headerLen;\n if (payloadStart > raw.length) return null;\n const header = newPackr().unpack(raw.subarray(MAGIC.length + 4, payloadStart)) as SnapshotHeader;\n if (!header.standalone) {\n if (header.engine !== VERSION) return null;\n const sourceStat = fs.statSync(graphPath); // no source JSON → nothing to be a cache of\n if (header.sourceSize !== sourceStat.size || header.sourceMtimeMs !== sourceStat.mtimeMs) return null;\n }\n const payload = raw.subarray(payloadStart);\n if (crc32(payload) !== header.crc32) return null;\n const graph = newPackr().unpack(payload) as VgGraph;\n if (!graph || !Array.isArray(graph.nodes) || !Array.isArray(graph.edges)) return null;\n return graph;\n } catch {\n return null;\n }\n}\n\n/**\n * Does a map exist at `graphPath` in either representation — the canonical\n * `graph.json`, or a standalone binary snapshot (global-store mode)?\n * Cheap: reads only the snapshot header, never the payload or the JSON.\n */\nexport function mapFileExists(graphPath: string): boolean {\n if (fs.existsSync(graphPath)) return true;\n return readSnapshotHeader(snapshotPathFor(graphPath))?.standalone === true;\n}\n\n/**\n * Stat for \"did the map change on disk\" mtime tracking: the JSON when\n * present, else the standalone snapshot file. Throws when neither exists —\n * same contract callers had with `fs.statSync(graphPath)`.\n */\nexport function mapFileStat(graphPath: string): fs.Stats {\n try {\n return fs.statSync(graphPath);\n } catch (err) {\n const snap = snapshotPathFor(graphPath);\n if (fs.existsSync(snap)) return fs.statSync(snap);\n throw err;\n }\n}\n\n/** Parse just the envelope header of a snapshot file (null on any problem). */\nfunction readSnapshotHeader(file: string): SnapshotHeader | null {\n let fd: number | null = null;\n try {\n fd = fs.openSync(file, 'r');\n const prefix = Buffer.alloc(4096);\n const read = fs.readSync(fd, prefix, 0, prefix.length, 0);\n if (read < MAGIC.length + 4 || !prefix.subarray(0, MAGIC.length).equals(MAGIC)) return null;\n const headerLen = prefix.readUInt32LE(MAGIC.length);\n if (MAGIC.length + 4 + headerLen > read) return null;\n return newPackr().unpack(prefix.subarray(MAGIC.length + 4, MAGIC.length + 4 + headerLen)) as SnapshotHeader;\n } catch {\n return null;\n } finally {\n if (fd !== null) fs.closeSync(fd);\n }\n}\n\n/**\n * Load a map file, preferring the binary snapshot and self-healing it.\n * Fast path: valid snapshot (sidecar or standalone) → decode it. Fallback:\n * parse `graph.json`, then (best-effort) rewrite the sidecar so the next load\n * takes the fast path. Returns null only when neither representation yields a\n * graph — exactly the cases the pre-snapshot code treated as \"no graph\".\n */\nexport function loadGraphFileWithSnapshot(graphPath: string): VgGraph | null {\n const snap = readGraphSnapshot(graphPath);\n if (snap) return snap;\n let json: string;\n try {\n json = fs.readFileSync(graphPath, 'utf8');\n } catch {\n return null;\n }\n let graph: VgGraph;\n try {\n graph = parseGraph(json);\n } catch {\n return null;\n }\n writeGraphSnapshot(graphPath, graph);\n return graph;\n}\n","import type { VgGraph } from '../schema.js';\n\n/**\n * Deterministic Markdown summary (`GRAPH_REPORT.md`). Given a pinned\n * `generatedAt`, the report is byte-stable. Numbers are derived purely from the\n * graph, so the report can be regenerated from a committed `graph.json`.\n */\nexport function renderReport(graph: VgGraph): string {\n const { meta, provenance, nodes, edges } = graph;\n const lines: string[] = [];\n\n lines.push('# Code Graph Report');\n lines.push('');\n lines.push(`Generated by \\`vg\\` ${provenance.version} · schema \\`${graph.schemaVersion}\\``);\n lines.push('');\n lines.push('## Summary');\n lines.push('');\n lines.push(`- **Nodes:** ${meta.counts.nodes.toLocaleString('en-US')}`);\n lines.push(`- **Edges:** ${meta.counts.edges.toLocaleString('en-US')}`);\n lines.push(`- **Areas:** ${meta.counts.areas.toLocaleString('en-US')}`);\n lines.push(`- **Languages:** ${meta.languages.join(', ') || '—'}`);\n lines.push(`- **Clustering:** ${meta.cluster}`);\n lines.push(`- **Resolvers:** ${provenance.resolver.join(', ')}`);\n lines.push(`- **Edge kinds:** ${meta.edgeKinds.join(', ') || '—'}`);\n lines.push('');\n\n // Files by definition count.\n const fileNodes = nodes.filter((n) => n.kind === 'file');\n const defsByFile = new Map<string, number>();\n for (const n of nodes) {\n if (n.kind === 'file' || n.kind === 'external') continue;\n defsByFile.set(n.file, (defsByFile.get(n.file) ?? 0) + 1);\n }\n const topFiles = [...defsByFile.entries()]\n .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))\n .slice(0, 15);\n if (topFiles.length) {\n lines.push('## Largest files (by definitions)');\n lines.push('');\n lines.push('| File | Definitions |');\n lines.push('| --- | ---: |');\n for (const [file, count] of topFiles) lines.push(`| \\`${file}\\` | ${count} |`);\n lines.push('');\n }\n\n // Most-connected nodes (Phase 0 importance = normalised degree).\n const topNodes = nodes\n .filter((n) => n.kind !== 'file' && n.kind !== 'external')\n .sort((a, b) => b.importance - a.importance || a.qualifiedName.localeCompare(b.qualifiedName))\n .slice(0, 15);\n if (topNodes.length) {\n lines.push('## Most-connected definitions');\n lines.push('');\n lines.push('| Symbol | Kind | File | Importance |');\n lines.push('| --- | --- | --- | ---: |');\n for (const n of topNodes) {\n lines.push(\n `| \\`${n.qualifiedName}\\` | ${n.kind} | \\`${n.file}\\`:${n.span.start} | ${n.importance.toFixed(3)} |`,\n );\n }\n lines.push('');\n }\n\n // Edge-kind breakdown.\n const byKind = new Map<string, number>();\n for (const e of edges) byKind.set(e.kind, (byKind.get(e.kind) ?? 0) + 1);\n if (byKind.size) {\n lines.push('## Edges by kind');\n lines.push('');\n lines.push('| Kind | Count |');\n lines.push('| --- | ---: |');\n for (const [kind, count] of [...byKind.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {\n lines.push(`| ${kind} | ${count} |`);\n }\n lines.push('');\n }\n\n lines.push('---');\n lines.push('');\n lines.push(`_Files: ${fileNodes.length} · Corpus: \\`${provenance.corpusHash.slice(0, 16)}…\\`_`);\n lines.push('');\n\n return lines.join('\\n');\n}\n","import { stableStringify } from './serialize.js';\nimport type { VgGraph } from '../schema.js';\n\n/**\n * `graph.html`: self-contained, dependency-free, deterministic overview.\n *\n * For small/medium maps we embed the full graph JSON for tooling.\n * For large maps (default: >5k nodes) we embed only a\n * **hub + area summary** so the HTML stays openable; full data stays in\n * graph.json / graph.db. Interactive WebGL (sigma.js) remains a follow-up.\n */\n\nconst EMBED_NODE_LIMIT = 5_000;\n\nexport function renderHtml(graph: VgGraph): string {\n const top = graph.nodes\n .filter((n) => n.kind !== 'file' && n.kind !== 'external')\n .sort((a, b) => b.importance - a.importance || a.qualifiedName.localeCompare(b.qualifiedName))\n .slice(0, 50);\n\n const areas = [...graph.areas]\n .sort((a, b) => b.size - a.size || a.id - b.id)\n .slice(0, 40);\n\n const rows = top\n .map(\n (n) =>\n `<tr><td><code>${esc(n.qualifiedName)}</code></td><td>${esc(n.kind)}</td>` +\n `<td><code>${esc(n.file)}</code>:${n.span.start}</td><td>${n.importance.toFixed(3)}</td></tr>`,\n )\n .join('\\n');\n\n const areaRows = areas\n .map(\n (a) =>\n `<tr><td>${a.id}</td><td><code>${esc(a.label)}</code></td>` +\n `<td>${a.size}</td><td>${a.cohesion.toFixed(3)}</td><td>${a.externalEdges}</td></tr>`,\n )\n .join('\\n');\n\n const large = graph.meta.counts.nodes > EMBED_NODE_LIMIT;\n const embedPayload = large\n ? {\n schemaVersion: graph.schemaVersion,\n generatedAt: graph.generatedAt,\n provenance: graph.provenance,\n meta: graph.meta,\n hubs: top.map((n) => ({\n id: n.id,\n name: n.qualifiedName,\n kind: n.kind,\n file: n.file,\n line: n.span.start,\n importance: n.importance,\n area: n.area,\n })),\n areas: areas.map((a) => ({\n id: a.id,\n label: a.label,\n size: a.size,\n cohesion: a.cohesion,\n externalEdges: a.externalEdges,\n })),\n note: `Full graph omitted (${graph.meta.counts.nodes} nodes > ${EMBED_NODE_LIMIT}). Use graph.json or .vibgrate/cache/graph.db.`,\n }\n : graph;\n\n const embedded = stableStringify(embedPayload, 0);\n const tier = graph.meta.analysisTier ?? 'full';\n\n return `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>vg · code graph</title>\n<style>\n :root { color-scheme: light dark; }\n body { font: 14px/1.5 system-ui, sans-serif; margin: 2rem auto; max-width: 60rem; padding: 0 1rem; }\n h1 { font-size: 1.4rem; } h2 { font-size: 1.1rem; margin-top: 2rem; }\n table { border-collapse: collapse; width: 100%; }\n th, td { text-align: left; padding: 4px 8px; border-bottom: 1px solid #8884; }\n td:last-child, th:last-child { text-align: right; }\n .meta { color: #888; } code { font-size: 0.9em; }\n .banner { background: #8882; padding: 0.6rem 0.8rem; border-radius: 6px; margin: 1rem 0; }\n</style>\n</head>\n<body>\n<h1>vg · code graph</h1>\n<p class=\"meta\">${graph.meta.counts.nodes} nodes · ${graph.meta.counts.edges} edges ·\n${graph.meta.counts.areas} areas · ${esc(graph.meta.languages.join(', ') || '—')} ·\nclustering: ${esc(graph.meta.cluster)} · tier: ${esc(tier)} · vg ${esc(graph.provenance.version)}</p>\n${\n large\n ? `<p class=\"banner\">Large map (${graph.meta.counts.nodes} nodes): HTML shows hubs + areas only.\nFull graph remains in <code>graph.json</code> / <code>.vibgrate/cache/graph.db</code> (query via <code>vg serve</code>).</p>`\n : ''\n}\n<h2>Areas (subsystems)</h2>\n<table>\n<thead><tr><th>Id</th><th>Label</th><th>Size</th><th>Cohesion</th><th>External</th></tr></thead>\n<tbody>\n${areaRows || '<tr><td colspan=\"5\" class=\"meta\">no areas</td></tr>'}\n</tbody>\n</table>\n<h2>Most-connected definitions (hubs)</h2>\n<table>\n<thead><tr><th>Symbol</th><th>Kind</th><th>Location</th><th>Importance</th></tr></thead>\n<tbody>\n${rows}\n</tbody>\n</table>\n<p class=\"meta\">${large ? 'Summary payload' : 'Full graph'} embedded below for tooling.</p>\n<script type=\"application/json\" id=\"vg-graph\">\n${embedded}\n</script>\n</body>\n</html>\n`;\n}\n\nfunction esc(s: string): string {\n return s\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"');\n}\n","/**\n * Optional relevance-provider seam for ask / Task Capsule seed ranking.\n *\n * A relevance provider is an OPTIONAL, separately installed local module that\n * analyzes a natural-language question and returns weighted expansion terms\n * with provenance (plus inferred topics). When present, its expansions join\n * the built-in concept lexicon (engine/concepts.ts) inside `queryGraph`'s\n * term preparation; when absent (the default install), nothing changes —\n * the deterministic lexicon path is the complete, supported baseline.\n *\n * Loading mirrors the optional-embedder pattern (engine/embeddings.ts):\n * - `VIBGRATE_NO_KERNEL=1` disables the seam entirely (off by default).\n * - `VIBGRATE_RELEVANCE_PATH` points at a provider module (a file, or a\n * directory containing `index.js`).\n * - Otherwise the default module location is probed:\n * `$XDG_CACHE_HOME|~/.cache /vibgrate/modules/relevance/index.js`.\n * The module contract: it exports `createRelevanceProvider()` returning\n * `{ version(): string, analyzeQuery(q: string): RelevanceAnalysis }`.\n *\n * Trust boundary: provider output is sanitized here — terms lowercased,\n * weights clamped to [0,1], expansions whose provenance is a weak process\n * verb dropped (they could re-open the `add*` grab-bag failure the term-role\n * model closed), and the total capped — so a buggy or adversarial module can\n * widen vocabulary but never bypass the ranking invariants. Every failure\n * path degrades to `null` (no provider), never to an error: relevance\n * analysis is an enhancement, not a dependency.\n *\n * Determinism: given the same question and the same provider version, the\n * sanitized analysis is deterministic; the provider version is surfaced so\n * capsules can record it as ranking provenance.\n */\nimport * as os from 'node:os';\nimport * as path from 'node:path';\nimport * as fs from 'node:fs';\nimport { pathToFileURL } from 'node:url';\nimport { WEAK_TERMS } from './concepts.js';\n\nexport interface RelevanceExpansion {\n /** Single lowercase word, ready for identifier-part matching. */\n term: string;\n /** The question token/phrase (or topic id) that produced it. */\n from: string;\n /** 0..1 relative confidence; scales the expansion's scoring contribution. */\n weight: number;\n}\n\nexport interface RelevanceTopic {\n id: string;\n /** 0..1, normalized within one analysis. */\n score: number;\n}\n\nexport interface RelevanceAnalysis {\n version: string;\n topics: RelevanceTopic[];\n expansions: RelevanceExpansion[];\n}\n\nexport interface RelevanceProvider {\n version(): string;\n analyzeQuery(question: string): RelevanceAnalysis;\n /** Optional build-time enrichment: deterministic topic tags for one node\n * (path + identifier evidence). Providers without it still work. */\n tagNode?(input: { qualifiedName: string; file: string }): string[];\n}\n\n/** Upper bound on sanitized expansions accepted from a provider. */\nconst MAX_PROVIDER_EXPANSIONS = 24;\n\nfunction disabled(): boolean {\n const v = process.env.VIBGRATE_NO_KERNEL;\n return v === '1' || v === 'true';\n}\n\n/** Default install location for the optional relevance module (shared with\n * the install flow in install/relevance-module.ts). */\nexport function relevanceModuleDir(): string {\n const base = process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache');\n return path.join(base, 'vibgrate', 'modules', 'relevance');\n}\n\nfunction defaultModulePath(): string {\n return path.join(relevanceModuleDir(), 'index.js');\n}\n\nfunction candidatePaths(): string[] {\n const custom = process.env.VIBGRATE_RELEVANCE_PATH;\n if (custom) {\n const p = path.resolve(custom);\n try {\n if (fs.statSync(p).isDirectory()) return [path.join(p, 'index.js')];\n } catch {\n /* fall through — treat as a file path */\n }\n return [p];\n }\n return [defaultModulePath()];\n}\n\nlet cached: RelevanceProvider | null | undefined;\n\n/** Reset the memoized provider (tests only). */\nexport function resetRelevanceProviderCache(): void {\n cached = undefined;\n}\n\n/**\n * Load the optional relevance provider. Memoized per process; returns `null`\n * when disabled, not installed, or the module fails to load or violates the\n * contract — callers treat `null` as \"no analysis\" and proceed unchanged.\n */\nexport async function loadRelevanceProvider(): Promise<RelevanceProvider | null> {\n if (cached !== undefined) return cached;\n cached = null;\n if (disabled()) return cached;\n for (const p of candidatePaths()) {\n if (!fs.existsSync(p)) continue;\n try {\n const mod = (await import(pathToFileURL(p).href)) as {\n createRelevanceProvider?: () => RelevanceProvider;\n };\n const provider = mod.createRelevanceProvider?.();\n if (provider && typeof provider.version === 'function' && typeof provider.analyzeQuery === 'function') {\n cached = provider;\n return cached;\n }\n } catch {\n // A broken module must never break ask/capsule — fall through to null.\n }\n }\n return cached;\n}\n\n/**\n * Run the provider over a question and sanitize the result. Returns `null`\n * when no provider is available or its output is unusable; the caller passes\n * the analysis into `queryGraph({ relevance })` as-is.\n */\nexport async function analyzeQuestion(question: string): Promise<RelevanceAnalysis | null> {\n const provider = await loadRelevanceProvider();\n if (!provider) return null;\n try {\n return sanitizeAnalysis(provider.analyzeQuery(question));\n } catch {\n return null;\n }\n}\n\n/** Enforce the trust boundary on raw provider output (exported for tests). */\nexport function sanitizeAnalysis(raw: RelevanceAnalysis): RelevanceAnalysis | null {\n if (!raw || typeof raw.version !== 'string') return null;\n const seen = new Set<string>();\n const expansions: RelevanceExpansion[] = [];\n for (const e of raw.expansions ?? []) {\n const term = String(e?.term ?? '').toLowerCase().trim();\n const from = String(e?.from ?? '').toLowerCase().trim();\n const weight = Number(e?.weight);\n if (!term || !from || term.includes(' ')) continue;\n // A weak process verb as provenance means the provider expanded the ACTION\n // (\"add\", \"create\"), not the topic — exactly the grab-bag failure the\n // term-role model suppresses. Never accept those.\n if (WEAK_TERMS.has(from) || WEAK_TERMS.has(term)) continue;\n if (!Number.isFinite(weight) || weight <= 0) continue;\n if (seen.has(term)) continue;\n seen.add(term);\n expansions.push({ term, from, weight: Math.min(1, weight) });\n if (expansions.length >= MAX_PROVIDER_EXPANSIONS) break;\n }\n const topics = (raw.topics ?? [])\n .filter((t) => t && typeof t.id === 'string' && Number.isFinite(t.score))\n .map((t) => ({ id: t.id, score: Math.max(0, Math.min(1, t.score)) }));\n return { version: raw.version, topics, expansions };\n}\n","import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { serializeGraph } from './serialize.js';\nimport { mapFileExists, snapshotPathFor, writeGraphSnapshot } from './snapshot.js';\nimport { renderReport } from './report.js';\nimport { renderHtml } from './html.js';\nimport { globalGraphPath, globalGraphPathForRef, repositoryStoreDir } from '../runtime/paths.js';\nimport { deleteTagsSidecarFor } from './relevance-enrich.js';\nimport { detectGitRef } from '../runtime/git-ref.js';\nimport type { VgGraph } from '../schema.js';\n\n/**\n * Graph artifact layout (Fusion Runtime Phase 1).\n *\n * By default the code map lives in the **global** application store\n * (XDG / Application Support), keyed by repository id — not inside the repo.\n * That keeps `vg` / `vg serve` / auto-refresh from dirtying the working tree.\n *\n * Legacy in-repo path `.vibgrate/graph.json` is still **read** when present\n * (migration), and is still the write target when:\n * - `VIBGRATE_GRAPH_IN_REPO=1` (or true/yes), or\n * - callers pass an explicit `graphPath` / `--graph`.\n *\n * `vg share` continues to opt into a committed in-repo map by writing under\n * `.vibgrate/` (and rewriting its gitignore).\n */\n\nexport interface WriteOptions {\n root: string;\n html?: boolean; // default true\n report?: boolean; // default true\n graphPath?: string; // override graph.json path\n}\n\nexport interface WrittenArtifacts {\n graphPath: string;\n reportPath?: string;\n htmlPath?: string;\n factsPath?: string;\n}\n\nexport function vibgrateDir(root: string): string {\n return path.join(root, '.vibgrate');\n}\n\n/** Historical in-repo map path (still read as a fallback). */\nexport function legacyGraphPath(root: string): string {\n return path.join(vibgrateDir(root), 'graph.json');\n}\n\n/**\n * When true, default writes go to `.vibgrate/graph.json` (pre–Phase-1 layout).\n * Useful for CI that asserts in-repo artifacts, and for `vg share` workflows.\n */\nexport function preferInRepoGraph(env: NodeJS.ProcessEnv = process.env): boolean {\n const v = env.VIBGRATE_GRAPH_IN_REPO?.trim().toLowerCase();\n return v === '1' || v === 'true' || v === 'yes';\n}\n\n/**\n * Default **write** path for the map. Global store unless the operator opts\n * into the legacy in-repo layout. When git is available, prefer a\n * branch-keyed snapshot (Fusion §4.1.1) so switching branches does not\n * overwrite another ref's on-disk map.\n */\nexport function defaultGraphPath(root: string, env: NodeJS.ProcessEnv = process.env): string {\n if (preferInRepoGraph(env)) return legacyGraphPath(root);\n const { ref, kind } = detectGitRef(root);\n if (kind !== 'none' && ref) return globalGraphPathForRef(root, ref, env);\n return globalGraphPath(root, 'current', env);\n}\n\n/**\n * Resolve where to **read** the map from.\n * Order: explicit override → legacy in-repo when `VIBGRATE_GRAPH_IN_REPO` is set\n * → branch-keyed global (if on a git ref) → `current` global snapshot →\n * legacy in-repo → default write path.\n *\n * The in-repo env short-circuit matters for CI and the release benchmark: they\n * force portable `.vibgrate/graph.json` artifacts and must not pay a synchronous\n * `git rev-parse` (or prefer a leftover global snapshot) on every resolve.\n */\nexport function resolveGraphPath(root: string, override?: string, env: NodeJS.ProcessEnv = process.env): string {\n if (override?.trim()) return path.resolve(override.trim());\n if (preferInRepoGraph(env)) {\n const legacy = legacyGraphPath(root);\n if (fs.existsSync(legacy)) return legacy;\n return legacy;\n }\n const { ref, kind } = detectGitRef(root);\n if (kind !== 'none' && ref) {\n const branchPath = globalGraphPathForRef(root, ref, env);\n if (mapFileExists(branchPath)) return branchPath;\n }\n const globalPath = globalGraphPath(root, 'current', env);\n if (mapFileExists(globalPath)) return globalPath;\n const legacy = legacyGraphPath(root);\n if (fs.existsSync(legacy)) return legacy;\n return defaultGraphPath(root, env);\n}\n\n/**\n * By default the graph artifacts are *local*: builds and auto-refreshes rewrite\n * them constantly, and without an ignore file every `vg ask`/`vg serve` leaves\n * the branch dirty (untracked or modified `.vibgrate/` files) — irritating for\n * humans and a source of junk commits from AI agents. So the first time vg\n * writes into `.vibgrate/` it also drops a `.gitignore` covering the graph\n * artifacts, the cache, and itself.\n *\n * Deliberately create-once: an existing `.vibgrate/.gitignore` is NEVER\n * touched, whatever its content — `vg share` owns it after opt-in (rewritten to\n * commit `graph.json`), and a user-managed file (even an empty one) is theirs.\n * Scanner artifacts meant for git (`baseline.json`, `standards.json`,\n * `attestation.intoto.jsonl`) are intentionally not listed.\n *\n * With the global store default, this gitignore is only created when something\n * is still written under `.vibgrate/` (in-repo mode or other in-repo writers).\n */\nconst DEFAULT_GITIGNORE = [\n '# Created once by vg — local graph artifacts stay out of git by default.',\n '# Run `vg share` to commit the map for your team (it rewrites this file).',\n '# vg never touches an existing .vibgrate/.gitignore: edit it (or leave it',\n '# empty) to manage these ignores yourself.',\n '.gitignore',\n 'cache/',\n 'graph.json',\n 'graph.snap',\n 'graph.tags.snap',\n 'graph.html',\n 'GRAPH_REPORT.md',\n 'facts.jsonl',\n 'mcp-navigation.json',\n // Machine-local telemetry the LSP/`vg code` accrue over time — never meant\n // for git: score-history.jsonl is per-machine trend data (lsp/score-history.ts),\n // run-outcomes.jsonl is per-machine agent-run telemetry (code/run-outcome.ts).\n // Neither is a snapshot artifact like scan_result.json/baseline.json, which\n // are intentionally left out of this list for a user to commit if they choose.\n 'score-history.jsonl',\n 'run-outcomes.jsonl',\n];\n\nexport function ensureVibgrateGitignore(root: string): void {\n const file = path.join(vibgrateDir(root), '.gitignore');\n if (fs.existsSync(file)) return;\n fs.mkdirSync(vibgrateDir(root), { recursive: true });\n fs.writeFileSync(file, `${DEFAULT_GITIGNORE.join('\\n')}\\n`);\n}\n\n/**\n * Directory for companion artifacts (report, html, facts) next to the map.\n * Global maps → repository store root; in-repo maps → `.vibgrate/`.\n */\nexport function companionArtifactDir(root: string, graphPath: string, env: NodeJS.ProcessEnv = process.env): string {\n const resolved = path.resolve(graphPath);\n const legacy = path.resolve(legacyGraphPath(root));\n if (resolved === legacy) return vibgrateDir(root);\n const globalDefault = path.resolve(globalGraphPath(root, 'current', env));\n if (resolved === globalDefault) return repositoryStoreDir(root, env);\n // Custom --graph: keep companions next to the map file.\n return path.dirname(resolved);\n}\n\nexport function writeArtifacts(graph: VgGraph, options: WriteOptions): WrittenArtifacts {\n const graphPath = options.graphPath ?? defaultGraphPath(options.root);\n const companions = companionArtifactDir(options.root, graphPath);\n const inRepo = isPathInside(companions, options.root) || isPathInside(graphPath, options.root);\n\n fs.mkdirSync(path.dirname(graphPath), { recursive: true });\n fs.mkdirSync(companions, { recursive: true });\n\n // Only drop `.vibgrate/.gitignore` when we still touch the in-repo layout.\n if (inRepo && isPathInside(companions, vibgrateDir(options.root))) {\n ensureVibgrateGitignore(options.root);\n } else if (path.resolve(graphPath) === path.resolve(legacyGraphPath(options.root))) {\n ensureVibgrateGitignore(options.root);\n }\n\n // Global-store maps are machine-consumed only, so the snapshot IS the map\n // there — skipping the pretty-JSON serialize is the bulk of the write cost\n // on large repos. Everywhere a human (or git) can see the file — legacy\n // in-repo layout, VIBGRATE_GRAPH_IN_REPO, `vg share`, an explicit --graph\n // path — the canonical graph.json is still written, with the snapshot as a\n // sidecar cache.\n const storeMode = isPathInside(graphPath, repositoryStoreDir(options.root));\n\n // A (re)written graph at this path is a NEW graph: drop the relevance-tags\n // sidecar bound to the previous content so nothing stale can outlive its\n // graph (the sidecar would also self-invalidate via corpusHash, but a\n // removed/replaced graph must take its derived artifacts with it).\n deleteTagsSidecarFor(graphPath);\n\n if (storeMode) {\n if (!writeGraphSnapshot(graphPath, graph, { standalone: true })) {\n // Store not writable for the binary — fall back to the JSON write below\n // rather than losing the build.\n } else {\n // Drop any JSON left by an older CLI at this path so a downgrade can\n // never silently serve a stale map from beside a newer snapshot.\n fs.rmSync(graphPath, { force: true });\n }\n }\n\n if (!storeMode || !fs.existsSync(snapshotPathFor(graphPath))) {\n // Atomic write (temp + rename): `vg serve` hot-reloads the map on mtime\n // change, so a rebuild — including its own in-process auto-refresh — must\n // never expose a half-written file to a concurrent reader.\n const tmp = `${graphPath}.${process.pid}.tmp`;\n try {\n fs.writeFileSync(tmp, serializeGraph(graph));\n fs.renameSync(tmp, graphPath);\n } catch (err) {\n fs.rmSync(tmp, { force: true });\n throw err;\n }\n // Binary sidecar cache for fast loads; best-effort, JSON stays canonical.\n writeGraphSnapshot(graphPath, graph);\n }\n\n const written: WrittenArtifacts = {\n graphPath: storeMode && !fs.existsSync(graphPath) ? snapshotPathFor(graphPath) : graphPath,\n };\n\n if (options.report !== false) {\n const reportPath = path.join(companions, 'GRAPH_REPORT.md');\n fs.writeFileSync(reportPath, renderReport(graph));\n written.reportPath = reportPath;\n }\n\n if (options.html !== false) {\n const htmlPath = path.join(companions, 'graph.html');\n fs.writeFileSync(htmlPath, renderHtml(graph));\n written.htmlPath = htmlPath;\n }\n\n // facts.jsonl (deterministic NDJSON) when facts were derived.\n if (graph.facts && graph.facts.length) {\n const factsPath = path.join(companions, 'facts.jsonl');\n fs.writeFileSync(factsPath, graph.facts.map((f) => JSON.stringify(f)).join('\\n') + '\\n');\n written.factsPath = factsPath;\n }\n\n return written;\n}\n\nfunction isPathInside(child: string, parent: string): boolean {\n const rel = path.relative(path.resolve(parent), path.resolve(child));\n return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));\n}\n","/**\n * Graph enrichment via the optional relevance provider: per-node TOPIC TAGS,\n * stored as a binary sidecar BOUND TO ONE EXACT GRAPH.\n *\n * When the installed provider exposes `tagNode`, every graph node gets a\n * deterministic topic tag set derived from path/identifier evidence\n * (\"src/payments/DirectDebitMandate.ts\" → [\"payments\"]). Query-time ranking\n * then adds a bounded affinity bonus when the question's inferred topics\n * intersect a node's tags.\n *\n * Storage contract (the part that keeps everything in step):\n *\n * - Tags NEVER enter `graph.json` — byte-identical output for identical\n * input is a hard invariant of `vg build`.\n * - The sidecar lives BESIDE the resolved graph artifact\n * (`<id>.graph.tags.snap` next to `<id>.graph.json` / `.graph.snap`).\n * Graphs are branch-keyed in the global repository store (Fusion §4.1.1),\n * so switching branches resolves a different graph file — and therefore a\n * different sidecar — with zero extra bookkeeping. Legacy in-repo maps get\n * `.vibgrate/graph.tags.snap` (gitignored alongside `graph.snap`).\n * - The binding is CONTENT identity, not path or time: the header records\n * the graph's `provenance.corpusHash` (blake3 over the included file set)\n * and is trusted only when it matches the LOADED graph. A rebuild, a\n * branch switch served through the same path, or a hand-swapped file all\n * invalidate it exactly; anything published downstream (vgd scans) that\n * carries the graph's corpusHash can verify the tags belong to it.\n * - The provider version and engine VERSION are recorded and must match — a\n * kernel/pack or CLI upgrade recomputes cleanly.\n * - Any mismatch, torn file (CRC), decode error, or provider fault degrades\n * to recompute-or-null; a sidecar problem must never break ranking.\n * - Writes are atomic (temp + rename) and best-effort; the graph write path\n * (engine/artifacts.ts) deletes the sidecar whenever the graph at that\n * path is rewritten or removed, so an orphaned sidecar cannot outlive its\n * graph.\n *\n * Format (mirrors engine/snapshot.ts conventions): MAGIC (\"VGTAGS1\\0\") ·\n * u32LE header length · msgpack header {engine, provider, corpusHash, crc32}\n * · msgpack payload (node id → tags, sorted by id). Explicit little-endian,\n * pure-JS msgpackr, fresh Packr per encode/decode — no platform variance.\n */\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as zlib from 'node:zlib';\nimport { Packr } from 'msgpackr';\nimport { loadRelevanceProvider } from './relevance-provider.js';\nimport { resolveGraphPath } from './artifacts.js';\nimport { VERSION } from '../version.js';\nimport type { VgGraph } from '../schema.js';\n\nconst MAGIC = Buffer.from('VGTAGS1\\0', 'latin1');\n\n/** node:zlib gained crc32 in 22.2; engines pins Node >= 22 so it's present,\n * but guard anyway (same posture as engine/snapshot.ts). */\nconst crc32: (data: Uint8Array) => number = zlib.crc32 ?? (() => 0);\n\ninterface TagsHeader {\n engine: string;\n provider: string;\n corpusHash: string;\n crc32: number;\n}\n\nfunction newPackr(): Packr {\n return new Packr({ useRecords: true });\n}\n\n/** Sidecar path for a resolved graph artifact path. */\nexport function tagsSidecarPathFor(graphPath: string): string {\n return graphPath.endsWith('.json') ? `${graphPath.slice(0, -5)}.tags.snap` : `${graphPath}.tags.snap`;\n}\n\n/** Remove the tags sidecar for a graph path (graph rewrite/removal hook). */\nexport function deleteTagsSidecarFor(graphPath: string): void {\n try {\n fs.rmSync(tagsSidecarPathFor(graphPath), { force: true });\n } catch {\n /* best-effort — a locked file self-invalidates via corpusHash anyway */\n }\n}\n\nfunction readSidecar(file: string, expect: { provider: string; corpusHash: string }): Record<string, string[]> | null {\n try {\n if (!fs.existsSync(file)) return null;\n const raw = fs.readFileSync(file);\n if (raw.length < MAGIC.length + 4 || !raw.subarray(0, MAGIC.length).equals(MAGIC)) return null;\n const headerLen = raw.readUInt32LE(MAGIC.length);\n const headerStart = MAGIC.length + 4;\n if (raw.length < headerStart + headerLen) return null;\n const header = newPackr().unpack(raw.subarray(headerStart, headerStart + headerLen)) as TagsHeader;\n if (header.engine !== VERSION) return null;\n if (header.provider !== expect.provider) return null;\n if (header.corpusHash !== expect.corpusHash) return null;\n const payload = raw.subarray(headerStart + headerLen);\n if ((crc32(payload) >>> 0) !== (header.crc32 >>> 0)) return null;\n const tags = newPackr().unpack(payload) as Record<string, string[]>;\n return tags && typeof tags === 'object' ? tags : null;\n } catch {\n return null;\n }\n}\n\nfunction writeSidecar(file: string, meta: { provider: string; corpusHash: string }, tags: Record<string, string[]>): void {\n try {\n // Deterministic payload: sorted node ids.\n const sorted = Object.fromEntries(Object.entries(tags).sort(([a], [b]) => (a < b ? -1 : 1)));\n const payload = newPackr().pack(sorted);\n const header = newPackr().pack({\n engine: VERSION,\n provider: meta.provider,\n corpusHash: meta.corpusHash,\n crc32: crc32(payload) >>> 0,\n } satisfies TagsHeader);\n const lenBuf = Buffer.alloc(4);\n lenBuf.writeUInt32LE(header.length);\n fs.mkdirSync(path.dirname(file), { recursive: true });\n const tmp = `${file}.${process.pid}.tmp`;\n fs.writeFileSync(tmp, Buffer.concat([MAGIC, lenBuf, Buffer.from(header), Buffer.from(payload)]));\n fs.renameSync(tmp, file);\n } catch {\n // Best-effort: a full disk or read-only store never fails a query.\n }\n}\n\n/**\n * Topic tags for every scorable node of THIS graph, computed through the\n * provider and cached in the graph's own sidecar. Returns `null` when no\n * provider (or none with `tagNode`) is active — callers treat that as \"no\n * enrichment\" and proceed unchanged.\n *\n * `graphPath` should be the path the graph was actually loaded from (the MCP\n * server and `vg ask` pass it); when omitted it is re-resolved from the root\n * with the same branch-keyed rules `loadGraph` uses, so the sidecar always\n * sits beside the graph the current workspace state resolves to.\n */\nexport async function loadTopicTags(\n graph: VgGraph,\n root: string,\n graphPath?: string,\n): Promise<Map<string, readonly string[]> | null> {\n const provider = await loadRelevanceProvider();\n if (!provider?.tagNode) return null;\n let providerVersion: string;\n try {\n providerVersion = provider.version();\n } catch {\n return null;\n }\n const corpusHash = graph.provenance?.corpusHash;\n if (!corpusHash) return null; // no content identity → no cacheable binding\n\n const file = tagsSidecarPathFor(graphPath?.trim() ? path.resolve(graphPath) : resolveGraphPath(root));\n const cached = readSidecar(file, { provider: providerVersion, corpusHash });\n if (cached) {\n const tags = new Map<string, readonly string[]>();\n for (const [id, t] of Object.entries(cached)) if (t.length) tags.set(id, t);\n return tags;\n }\n\n const record: Record<string, string[]> = {};\n const tags = new Map<string, readonly string[]>();\n try {\n for (const node of graph.nodes) {\n if (node.kind === 'file' || node.kind === 'external') continue;\n const computed = provider.tagNode({ qualifiedName: node.qualifiedName, file: node.file }) ?? [];\n // Sanitize at the trust boundary: strings only, lowercased, capped.\n const clean = computed\n .filter((t) => typeof t === 'string' && t.length > 0)\n .map((t) => t.toLowerCase())\n .slice(0, 3);\n record[node.id] = clean;\n if (clean.length) tags.set(node.id, clean);\n }\n } catch {\n return null; // a faulting provider must never break ranking\n }\n writeSidecar(file, { provider: providerVersion, corpusHash }, record);\n return tags;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { runBuild } from './chunk-
|
|
2
|
-
import { loadGraph } from './chunk-
|
|
1
|
+
import { runBuild } from './chunk-KYX2YCXT.js';
|
|
2
|
+
import { loadGraph } from './chunk-CPLG4GFB.js';
|
|
3
3
|
|
|
4
4
|
// src/code/ensure-map.ts
|
|
5
5
|
async function ensureCodeMap(root, global, hooks) {
|
|
@@ -38,5 +38,5 @@ async function ensureCodeMap(root, global, hooks) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export { ensureCodeMap };
|
|
41
|
-
//# sourceMappingURL=chunk-
|
|
42
|
-
//# sourceMappingURL=chunk-
|
|
41
|
+
//# sourceMappingURL=chunk-4ACXDVON.js.map
|
|
42
|
+
//# sourceMappingURL=chunk-4ACXDVON.js.map
|