@vibgrate/cli 2026.813.1 → 2026.814.2
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/DOCS.md +258 -22
- package/NOTICE +7 -0
- package/README.md +273 -11
- package/dist/agent-5ANHRYEI.js +26 -0
- package/dist/{agent-N3CP3SPI.js.map → agent-5ANHRYEI.js.map} +1 -1
- package/dist/approvals-T2KXPJLV.js +9 -0
- package/dist/approvals-T2KXPJLV.js.map +1 -0
- package/dist/baseline-WVD6P5IO.js +9 -0
- package/dist/{baseline-ZMRZRGFI.js.map → baseline-WVD6P5IO.js.map} +1 -1
- package/dist/{checkpoint-4WFZMKEO.js → checkpoint-UYMYMMQO.js} +6 -3
- package/dist/checkpoint-UYMYMMQO.js.map +1 -0
- package/dist/chunk-2H2U3DC7.js +6 -0
- package/dist/{chunk-RT7P5AYU.js.map → chunk-2H2U3DC7.js.map} +1 -1
- package/dist/chunk-2U37PFB2.js +64 -0
- package/dist/chunk-2U37PFB2.js.map +1 -0
- package/dist/{chunk-GOPANQZT.js → chunk-54RGT2T5.js} +3 -3
- package/dist/{chunk-GOPANQZT.js.map → chunk-54RGT2T5.js.map} +1 -1
- package/dist/{chunk-OYHAF2J2.js → chunk-5GLQNMTI.js} +5 -5
- package/dist/{chunk-OYHAF2J2.js.map → chunk-5GLQNMTI.js.map} +1 -1
- package/dist/{chunk-EWZKOU66.js → chunk-75LJM5XD.js} +30 -66
- package/dist/chunk-75LJM5XD.js.map +1 -0
- package/dist/{chunk-KF2QT6RY.js → chunk-7NMXE6KG.js} +4 -4
- package/dist/{chunk-KF2QT6RY.js.map → chunk-7NMXE6KG.js.map} +1 -1
- package/dist/{chunk-UZP623Y4.js → chunk-7QDHQLUS.js} +4 -4
- package/dist/{chunk-UZP623Y4.js.map → chunk-7QDHQLUS.js.map} +1 -1
- package/dist/chunk-AJS4EL2C.js +266 -0
- package/dist/chunk-AJS4EL2C.js.map +1 -0
- package/dist/{chunk-Z3MUWXP3.js → chunk-BH54SLGZ.js} +4 -4
- package/dist/{chunk-Z3MUWXP3.js.map → chunk-BH54SLGZ.js.map} +1 -1
- package/dist/{chunk-CJNWHXQD.js → chunk-DSUGC7F5.js} +4 -4
- package/dist/{chunk-CJNWHXQD.js.map → chunk-DSUGC7F5.js.map} +1 -1
- package/dist/{chunk-FBVKQXBH.js → chunk-FOW5IF73.js} +3 -3
- package/dist/{chunk-FBVKQXBH.js.map → chunk-FOW5IF73.js.map} +1 -1
- package/dist/{chunk-6GQLEDVK.js → chunk-IHLLWBZU.js} +6 -5
- package/dist/chunk-IHLLWBZU.js.map +1 -0
- package/dist/{chunk-RHKJPTON.js → chunk-IHXNOY3R.js} +208 -56
- package/dist/chunk-IHXNOY3R.js.map +1 -0
- package/dist/{chunk-5JJBGBP2.js → chunk-JCN6MSXQ.js} +7 -7
- package/dist/{chunk-5JJBGBP2.js.map → chunk-JCN6MSXQ.js.map} +1 -1
- package/dist/{chunk-YJU7S7N6.js → chunk-KGPX4EUN.js} +4 -4
- package/dist/{chunk-YJU7S7N6.js.map → chunk-KGPX4EUN.js.map} +1 -1
- package/dist/{chunk-ADP6ITGF.js → chunk-N3XFY3PX.js} +68 -11
- package/dist/chunk-N3XFY3PX.js.map +1 -0
- package/dist/{chunk-JYM4QT6F.js → chunk-NKFXXP6W.js} +5 -5
- package/dist/{chunk-JYM4QT6F.js.map → chunk-NKFXXP6W.js.map} +1 -1
- package/dist/{chunk-5ROZODMW.js → chunk-TFAXW7VM.js} +2 -2
- package/dist/chunk-TFAXW7VM.js.map +1 -0
- package/dist/{chunk-6423BHLN.js → chunk-TNROG5CO.js} +19 -9
- package/dist/chunk-TNROG5CO.js.map +1 -0
- package/dist/chunk-TVDYEHIM.js +174 -0
- package/dist/chunk-TVDYEHIM.js.map +1 -0
- package/dist/{chunk-7ZHSSGUF.js → chunk-WQLZSVNF.js} +4 -3
- package/dist/chunk-WQLZSVNF.js.map +1 -0
- package/dist/{chunk-3WUTQYRY.js → chunk-WWGLVF7D.js} +9 -8
- package/dist/chunk-WWGLVF7D.js.map +1 -0
- package/dist/{chunk-KBP7GJV6.js → chunk-X76VPOYH.js} +19 -9
- package/dist/chunk-X76VPOYH.js.map +1 -0
- package/dist/{chunk-IJQOZ6ZD.js → chunk-YNV5M3JW.js} +8 -8
- package/dist/chunk-YNV5M3JW.js.map +1 -0
- package/dist/{chunk-Z3AYOZ3C.js → chunk-YQNTIBKS.js} +6 -6
- package/dist/{chunk-Z3AYOZ3C.js.map → chunk-YQNTIBKS.js.map} +1 -1
- package/dist/cli.js +1130 -489
- package/dist/cli.js.map +1 -1
- package/dist/embed-worker-main.js +4 -3
- package/dist/embed-worker-main.js.map +1 -1
- package/dist/{ensure-map-PHAJACFF.js → ensure-map-HQ7A5NDL.js} +15 -14
- package/dist/{ensure-map-PHAJACFF.js.map → ensure-map-HQ7A5NDL.js.map} +1 -1
- package/dist/fastembed-S6YEJYQV.js +292 -0
- package/dist/fastembed-S6YEJYQV.js.map +1 -0
- package/dist/graph-backend-W2TNTMY7.js +14 -0
- package/dist/{graph-backend-4B3MTVIW.js.map → graph-backend-W2TNTMY7.js.map} +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +14 -13
- package/dist/index.js.map +1 -1
- package/dist/{interactive-WUXMXFNM.js → interactive-EW2VJ3BZ.js} +32 -30
- package/dist/interactive-EW2VJ3BZ.js.map +1 -0
- package/dist/load-64RK5O6C.js +10 -0
- package/dist/{load-EUZSV73H.js.map → load-64RK5O6C.js.map} +1 -1
- package/dist/{run-outcome-O5PR7ZCK.js → run-outcome-6QNQIHPV.js} +6 -5
- package/dist/run-outcome-6QNQIHPV.js.map +1 -0
- package/dist/runtime-session-RJHH3KMF.js +21 -0
- package/dist/{runtime-session-PPQDTFIK.js.map → runtime-session-RJHH3KMF.js.map} +1 -1
- package/dist/session-4BGYASOH.js +16 -0
- package/dist/{session-WS7SOVJE.js.map → session-4BGYASOH.js.map} +1 -1
- package/dist/session-store-AQUORKWB.js +4 -0
- package/dist/{session-store-KGONLWHN.js.map → session-store-AQUORKWB.js.map} +1 -1
- package/dist/{stream-json-7MK3QQYG.js → stream-json-GY5N7WZT.js} +76 -24
- package/dist/stream-json-GY5N7WZT.js.map +1 -0
- package/dist/version-DPAMQW6M.js +4 -0
- package/dist/version-DPAMQW6M.js.map +1 -0
- package/dist/{vg-mcp-bridge-DQLCHBI6.js → vg-mcp-bridge-IGHJKKSL.js} +11 -10
- package/dist/vg-mcp-bridge-IGHJKKSL.js.map +1 -0
- package/dist/{vgd-Y25XSQGZ.js → vgd-ORPA5C2K.js} +12 -11
- package/dist/vgd-ORPA5C2K.js.map +1 -0
- package/dist/worktree-session-D575IQWM.js +82 -0
- package/dist/worktree-session-D575IQWM.js.map +1 -0
- package/package.json +4 -2
- package/dist/agent-N3CP3SPI.js +0 -24
- package/dist/baseline-ZMRZRGFI.js +0 -9
- package/dist/checkpoint-4WFZMKEO.js.map +0 -1
- package/dist/chunk-3WUTQYRY.js.map +0 -1
- package/dist/chunk-5ROZODMW.js.map +0 -1
- package/dist/chunk-6423BHLN.js.map +0 -1
- package/dist/chunk-6GQLEDVK.js.map +0 -1
- package/dist/chunk-7ZHSSGUF.js.map +0 -1
- package/dist/chunk-ADP6ITGF.js.map +0 -1
- package/dist/chunk-EWZKOU66.js.map +0 -1
- package/dist/chunk-IJQOZ6ZD.js.map +0 -1
- package/dist/chunk-KBP7GJV6.js.map +0 -1
- package/dist/chunk-RHKJPTON.js.map +0 -1
- package/dist/chunk-RT7P5AYU.js +0 -6
- package/dist/chunk-Z7FM3ETS.js +0 -126
- package/dist/chunk-Z7FM3ETS.js.map +0 -1
- package/dist/graph-backend-4B3MTVIW.js +0 -13
- package/dist/interactive-WUXMXFNM.js.map +0 -1
- package/dist/load-EUZSV73H.js +0 -9
- package/dist/run-outcome-O5PR7ZCK.js.map +0 -1
- package/dist/runtime-session-PPQDTFIK.js +0 -20
- package/dist/session-WS7SOVJE.js +0 -15
- package/dist/session-store-KGONLWHN.js +0 -4
- package/dist/stream-json-7MK3QQYG.js.map +0 -1
- package/dist/vg-mcp-bridge-DQLCHBI6.js.map +0 -1
- package/dist/vgd-Y25XSQGZ.js.map +0 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { ensureVibgrateGitignore } from './chunk-75LJM5XD.js';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
function approvalsPath(root) {
|
|
6
|
+
return path.join(root, ".vibgrate", "code-approvals.json");
|
|
7
|
+
}
|
|
8
|
+
function ruleKey(rule) {
|
|
9
|
+
if (rule.kind === "run") return `run:${rule.prefix}`;
|
|
10
|
+
if (rule.kind === "tool") return `tool:${rule.tool}`;
|
|
11
|
+
return `${rule.kind}:${rule.glob}`;
|
|
12
|
+
}
|
|
13
|
+
function ruleLabel(rule) {
|
|
14
|
+
if (rule.kind === "run") return `run \`${rule.prefix} \u2026\``;
|
|
15
|
+
if (rule.kind === "tool") return `call ${rule.tool}`;
|
|
16
|
+
return `${rule.kind} ${rule.glob}`;
|
|
17
|
+
}
|
|
18
|
+
function loadApprovalRules(root) {
|
|
19
|
+
let raw;
|
|
20
|
+
try {
|
|
21
|
+
raw = JSON.parse(fs.readFileSync(approvalsPath(root), "utf8"));
|
|
22
|
+
} catch {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
const list = Array.isArray(raw) ? raw : raw && typeof raw === "object" && Array.isArray(raw.rules) ? raw.rules : [];
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const item of list) {
|
|
28
|
+
const rule = sanitizeRule(item);
|
|
29
|
+
if (rule) out.push(rule);
|
|
30
|
+
}
|
|
31
|
+
return dedupe(out);
|
|
32
|
+
}
|
|
33
|
+
function sanitizeRule(item) {
|
|
34
|
+
if (!item || typeof item !== "object") return null;
|
|
35
|
+
const o = item;
|
|
36
|
+
if (o.kind === "run" && typeof o.prefix === "string" && o.prefix.trim()) {
|
|
37
|
+
return { kind: "run", prefix: normalizeCommandPrefix(o.prefix) };
|
|
38
|
+
}
|
|
39
|
+
if (o.kind === "tool" && typeof o.tool === "string" && o.tool.trim()) {
|
|
40
|
+
return { kind: "tool", tool: o.tool.trim() };
|
|
41
|
+
}
|
|
42
|
+
if ((o.kind === "edit" || o.kind === "create" || o.kind === "delete") && typeof o.glob === "string" && o.glob.trim()) {
|
|
43
|
+
return { kind: o.kind, glob: o.glob.trim() };
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
function dedupe(rules) {
|
|
48
|
+
const seen = /* @__PURE__ */ new Set();
|
|
49
|
+
const out = [];
|
|
50
|
+
for (const r of rules) {
|
|
51
|
+
const key = ruleKey(r);
|
|
52
|
+
if (seen.has(key)) continue;
|
|
53
|
+
seen.add(key);
|
|
54
|
+
out.push(r);
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
function saveApprovalRules(root, rules) {
|
|
59
|
+
try {
|
|
60
|
+
const dir = path.join(root, ".vibgrate");
|
|
61
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
62
|
+
ensureVibgrateGitignore(root);
|
|
63
|
+
const sorted = dedupe(rules).slice().sort((a, b) => ruleKey(a).localeCompare(ruleKey(b)));
|
|
64
|
+
fs.writeFileSync(approvalsPath(root), `${JSON.stringify({ rules: sorted }, null, 2)}
|
|
65
|
+
`);
|
|
66
|
+
return true;
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function addApprovalRule(root, rule) {
|
|
72
|
+
const rules = loadApprovalRules(root);
|
|
73
|
+
if (rules.some((r) => ruleKey(r) === ruleKey(rule))) return rule;
|
|
74
|
+
rules.push(rule);
|
|
75
|
+
return saveApprovalRules(root, rules) ? rule : null;
|
|
76
|
+
}
|
|
77
|
+
function removeApprovalRule(root, key) {
|
|
78
|
+
const rules = loadApprovalRules(root);
|
|
79
|
+
const kept = rules.filter((r) => ruleKey(r) !== key);
|
|
80
|
+
if (kept.length === rules.length) return false;
|
|
81
|
+
return saveApprovalRules(root, kept);
|
|
82
|
+
}
|
|
83
|
+
function normalizeCommandPrefix(command) {
|
|
84
|
+
const tokens = command.trim().split(/\s+/).filter(Boolean);
|
|
85
|
+
const head = tokens[0] ?? "";
|
|
86
|
+
const second = tokens[1];
|
|
87
|
+
if (!second) return head;
|
|
88
|
+
if (second.startsWith("-")) return tokens.join(" ");
|
|
89
|
+
if (tokens.slice(2).some((t) => !t.startsWith("-"))) return tokens.join(" ");
|
|
90
|
+
return `${head} ${second}`;
|
|
91
|
+
}
|
|
92
|
+
function extensiblePrefix(prefix) {
|
|
93
|
+
return !prefix.split(" ").some((t) => t.startsWith("-"));
|
|
94
|
+
}
|
|
95
|
+
var SHELL_METACHARS = /[><;&|`\n(){}$]/;
|
|
96
|
+
function ruleForAction(action) {
|
|
97
|
+
switch (action.kind) {
|
|
98
|
+
case "run":
|
|
99
|
+
return { kind: "run", prefix: normalizeCommandPrefix(action.command) };
|
|
100
|
+
case "tool":
|
|
101
|
+
return { kind: "tool", tool: action.name };
|
|
102
|
+
case "edit":
|
|
103
|
+
case "create":
|
|
104
|
+
case "delete":
|
|
105
|
+
return { kind: action.kind, glob: action.file };
|
|
106
|
+
case "patch":
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function globMatch(glob, file) {
|
|
111
|
+
let re = "";
|
|
112
|
+
for (let i = 0; i < glob.length; i++) {
|
|
113
|
+
const c = glob[i];
|
|
114
|
+
if (c === "*") {
|
|
115
|
+
if (glob[i + 1] === "*") {
|
|
116
|
+
re += ".*";
|
|
117
|
+
i += glob[i + 2] === "/" ? 2 : 1;
|
|
118
|
+
} else {
|
|
119
|
+
re += "[^/]*";
|
|
120
|
+
}
|
|
121
|
+
} else if (c === "?") {
|
|
122
|
+
re += "[^/]";
|
|
123
|
+
} else if ("\\^$.|+()[]{}".includes(c)) {
|
|
124
|
+
re += `\\${c}`;
|
|
125
|
+
} else {
|
|
126
|
+
re += c;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
return new RegExp(`^${re}$`).test(file);
|
|
131
|
+
} catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function fileRuleMatches(rules, op, file) {
|
|
136
|
+
for (const r of rules) {
|
|
137
|
+
if (r.kind === op && globMatch(r.glob, file)) return r;
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
function findMatchingRule(action, rules) {
|
|
142
|
+
if (!rules.length) return null;
|
|
143
|
+
switch (action.kind) {
|
|
144
|
+
case "run": {
|
|
145
|
+
const full = action.command.trim().split(/\s+/).filter(Boolean).join(" ");
|
|
146
|
+
for (const r of rules) {
|
|
147
|
+
if (r.kind !== "run") continue;
|
|
148
|
+
if (full === r.prefix) return r;
|
|
149
|
+
if (extensiblePrefix(r.prefix) && full.startsWith(`${r.prefix} `)) {
|
|
150
|
+
const tail = full.slice(r.prefix.length + 1);
|
|
151
|
+
if (SHELL_METACHARS.test(tail)) continue;
|
|
152
|
+
const extension = tail.split(" ");
|
|
153
|
+
if (extension.every((t) => t.startsWith("-"))) return r;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
case "tool":
|
|
159
|
+
return rules.find((r) => r.kind === "tool" && r.tool === action.name) ?? null;
|
|
160
|
+
case "edit":
|
|
161
|
+
case "create":
|
|
162
|
+
case "delete":
|
|
163
|
+
return fileRuleMatches(rules, action.kind, action.file);
|
|
164
|
+
case "patch": {
|
|
165
|
+
const covered = action.files.every((f) => fileRuleMatches(rules, f.op, f.file));
|
|
166
|
+
if (!covered) return null;
|
|
167
|
+
return fileRuleMatches(rules, action.files[0].op, action.files[0].file);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { addApprovalRule, approvalsPath, findMatchingRule, globMatch, loadApprovalRules, normalizeCommandPrefix, removeApprovalRule, ruleForAction, ruleKey, ruleLabel, saveApprovalRules };
|
|
173
|
+
//# sourceMappingURL=chunk-TVDYEHIM.js.map
|
|
174
|
+
//# sourceMappingURL=chunk-TVDYEHIM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/code/approvals.ts"],"names":[],"mappings":";;;;AA+BO,SAAS,cAAc,IAAA,EAAsB;AAClD,EAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,EAAM,WAAA,EAAa,qBAAqB,CAAA;AAC3D;AAMO,SAAS,QAAQ,IAAA,EAA4B;AAClD,EAAA,IAAI,KAAK,IAAA,KAAS,KAAA,EAAO,OAAO,CAAA,IAAA,EAAO,KAAK,MAAM,CAAA,CAAA;AAClD,EAAA,IAAI,KAAK,IAAA,KAAS,MAAA,EAAQ,OAAO,CAAA,KAAA,EAAQ,KAAK,IAAI,CAAA,CAAA;AAClD,EAAA,OAAO,CAAA,EAAG,IAAA,CAAK,IAAI,CAAA,CAAA,EAAI,KAAK,IAAI,CAAA,CAAA;AAClC;AAGO,SAAS,UAAU,IAAA,EAA4B;AACpD,EAAA,IAAI,KAAK,IAAA,KAAS,KAAA,EAAO,OAAO,CAAA,MAAA,EAAS,KAAK,MAAM,CAAA,SAAA,CAAA;AACpD,EAAA,IAAI,KAAK,IAAA,KAAS,MAAA,EAAQ,OAAO,CAAA,KAAA,EAAQ,KAAK,IAAI,CAAA,CAAA;AAClD,EAAA,OAAO,CAAA,EAAG,IAAA,CAAK,IAAI,CAAA,CAAA,EAAI,KAAK,IAAI,CAAA,CAAA;AAClC;AAOO,SAAS,kBAAkB,IAAA,EAA8B;AAC9D,EAAA,IAAI,GAAA;AACJ,EAAA,IAAI;AACF,IAAA,GAAA,GAAM,IAAA,CAAK,MAAM,EAAA,CAAG,YAAA,CAAa,cAAc,IAAI,CAAA,EAAG,MAAM,CAAC,CAAA;AAAA,EA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IAAA;AACrB,MAAA,OAAO,eAAA,CAAgB,KAAA,EAAO,MAAA,CAAO,KAAA,CAAM,CAAC,CAAA,CAAG,EAAA,EAAI,MAAA,CAAO,KAAA,CAAM,CAAC,CAAA,CAAG,IAAI,CAAA;AAAA,IAC1E;AAAA;AAEJ","file":"chunk-TVDYEHIM.js","sourcesContent":["/**\n * Allow-always approval rules (P2 — permission parity).\n *\n * The approval gate exists to review state changes, but reviewing the *same*\n * change shape every time (`pnpm test`, edits to a scratch dir) is friction\n * without safety. A user can promote an approval to a standing rule\n * (\"Always allow\"); rules live in `.vibgrate/code-approvals.json` at the repo\n * root so the CLI and VS Code honour the same set, and are re-read on every\n * approval so a revocation (from the VG Code manage UI or by editing the\n * file) takes effect immediately — no session restart, no stale cache.\n *\n * Rules never widen safety: {@link dangerousCommand} still screens every rule\n * match, plan mode still denies everything engine-side before rules are\n * consulted, and a rule-approved action is still announced (notice event) and\n * checkpointed like any human-approved change.\n */\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { ensureVibgrateGitignore } from '../engine/artifacts.js';\nimport type { MutatingAction, PatchFileAction } from './tools.js';\n\n/** One standing approval. Discriminated by `kind`, mirroring MutatingAction. */\nexport type ApprovalRule =\n /** Matches `run` actions whose normalized command starts with these tokens. */\n | { kind: 'run'; prefix: string }\n /** Matches a single-file action of that op when the path matches the glob. */\n | { kind: 'edit' | 'create' | 'delete'; glob: string }\n /** Matches external `tool` calls by tool name. */\n | { kind: 'tool'; tool: string };\n\nexport function approvalsPath(root: string): string {\n return path.join(root, '.vibgrate', 'code-approvals.json');\n}\n\n/**\n * The stable identity of a rule — used for dedupe and for revocation from\n * hosts that only carry the display string.\n */\nexport function ruleKey(rule: ApprovalRule): string {\n if (rule.kind === 'run') return `run:${rule.prefix}`;\n if (rule.kind === 'tool') return `tool:${rule.tool}`;\n return `${rule.kind}:${rule.glob}`;\n}\n\n/** Human-readable label for notices and manage UIs. */\nexport function ruleLabel(rule: ApprovalRule): string {\n if (rule.kind === 'run') return `run \\`${rule.prefix} …\\``;\n if (rule.kind === 'tool') return `call ${rule.tool}`;\n return `${rule.kind} ${rule.glob}`;\n}\n\n/**\n * Load the rule set, tolerating absence and malformed JSON (an unreadable file\n * means \"no rules\", never a crash — same posture as `.vibgrate/code.json`).\n * Unknown shapes are dropped so an untrusted file cannot inject junk.\n */\nexport function loadApprovalRules(root: string): ApprovalRule[] {\n let raw: unknown;\n try {\n raw = JSON.parse(fs.readFileSync(approvalsPath(root), 'utf8'));\n } catch {\n return [];\n }\n const list = Array.isArray(raw)\n ? raw\n : raw && typeof raw === 'object' && Array.isArray((raw as { rules?: unknown }).rules)\n ? ((raw as { rules: unknown[] }).rules)\n : [];\n const out: ApprovalRule[] = [];\n for (const item of list) {\n const rule = sanitizeRule(item);\n if (rule) out.push(rule);\n }\n return dedupe(out);\n}\n\nfunction sanitizeRule(item: unknown): ApprovalRule | null {\n if (!item || typeof item !== 'object') return null;\n const o = item as Record<string, unknown>;\n if (o.kind === 'run' && typeof o.prefix === 'string' && o.prefix.trim()) {\n return { kind: 'run', prefix: normalizeCommandPrefix(o.prefix) };\n }\n if (o.kind === 'tool' && typeof o.tool === 'string' && o.tool.trim()) {\n return { kind: 'tool', tool: o.tool.trim() };\n }\n if ((o.kind === 'edit' || o.kind === 'create' || o.kind === 'delete') && typeof o.glob === 'string' && o.glob.trim()) {\n return { kind: o.kind, glob: o.glob.trim() };\n }\n return null;\n}\n\nfunction dedupe(rules: ApprovalRule[]): ApprovalRule[] {\n const seen = new Set<string>();\n const out: ApprovalRule[] = [];\n for (const r of rules) {\n const key = ruleKey(r);\n if (seen.has(key)) continue;\n seen.add(key);\n out.push(r);\n }\n return out;\n}\n\n/**\n * Persist the rule set, deterministically sorted so identical sets produce an\n * identical file. Best-effort like other `.vibgrate/` writers — a read-only\n * checkout means no standing rules, never a thrown error mid-approval.\n */\nexport function saveApprovalRules(root: string, rules: ApprovalRule[]): boolean {\n try {\n const dir = path.join(root, '.vibgrate');\n fs.mkdirSync(dir, { recursive: true });\n // First writer into .vibgrate/ creates its .gitignore (create-once): one\n // developer's standing consents must not ride into the team's repo.\n ensureVibgrateGitignore(root);\n const sorted = dedupe(rules).slice().sort((a, b) => ruleKey(a).localeCompare(ruleKey(b)));\n fs.writeFileSync(approvalsPath(root), `${JSON.stringify({ rules: sorted }, null, 2)}\\n`);\n return true;\n } catch {\n return false;\n }\n}\n\n/** Add one rule (deduped). Returns the saved rule, or null when nothing was written. */\nexport function addApprovalRule(root: string, rule: ApprovalRule): ApprovalRule | null {\n const rules = loadApprovalRules(root);\n if (rules.some((r) => ruleKey(r) === ruleKey(rule))) return rule;\n rules.push(rule);\n return saveApprovalRules(root, rules) ? rule : null;\n}\n\n/** Remove the rule with this {@link ruleKey}. Returns true when one was removed and saved. */\nexport function removeApprovalRule(root: string, key: string): boolean {\n const rules = loadApprovalRules(root);\n const kept = rules.filter((r) => ruleKey(r) !== key);\n if (kept.length === rules.length) return false;\n return saveApprovalRules(root, kept);\n}\n\n/**\n * Normalize a shell command to its rule prefix: the first two tokens for the\n * `cmd subcommand [flags…]` shape (`git status`, `pnpm test --watch`), the\n * single token for a one-word command, and the *whole* command\n * (whitespace-normalized) in every other case. Collapsing `rm -f temp.log` to\n * bare `rm` — or `rm foo.log secrets.env` to `rm foo.log` — would turn one\n * blessed invocation into a standing grant covering paths the user never saw\n * (2026-08 audit, D2), so a command with a flag second-token or positional\n * arguments beyond the subcommand keeps its exact form.\n */\nexport function normalizeCommandPrefix(command: string): string {\n const tokens = command.trim().split(/\\s+/).filter(Boolean);\n const head = tokens[0] ?? '';\n const second = tokens[1];\n if (!second) return head;\n if (second.startsWith('-')) return tokens.join(' ');\n // Extra positionals after `cmd subcommand` make the rule exact; trailing\n // flags still collapse to the extensible two-token prefix.\n if (tokens.slice(2).some((t) => !t.startsWith('-'))) return tokens.join(' ');\n return `${head} ${second}`;\n}\n\n/** True when a rule prefix is the extensible `cmd [subcommand]` shape (no flags). */\nfunction extensiblePrefix(prefix: string): boolean {\n return !prefix.split(' ').some((t) => t.startsWith('-'));\n}\n\n/**\n * Shell constructs that can smuggle a second command into what looks like a\n * flag: command substitution, redirects, sequencing, backgrounding, subshells.\n * A `pnpm test` rule must not bless `pnpm test --reporter=$(curl … | sh)` —\n * the appended token is flag-shaped, but its *value* is another program the\n * user never saw. Same screen {@link readOnlyCommand} applies; kept local so\n * safety and approvals stay independent modules.\n */\nconst SHELL_METACHARS = /[><;&|`\\n(){}$]/;\n\n/**\n * Derive the standing rule an \"Always allow\" on this action should create.\n * Patch actions return null — an atomic multi-file transaction has no single\n * honest generalisation, so hosts do not offer Always on patch cards.\n */\nexport function ruleForAction(action: MutatingAction): ApprovalRule | null {\n switch (action.kind) {\n case 'run':\n return { kind: 'run', prefix: normalizeCommandPrefix(action.command) };\n case 'tool':\n return { kind: 'tool', tool: action.name };\n case 'edit':\n case 'create':\n case 'delete':\n return { kind: action.kind, glob: action.file };\n case 'patch':\n return null;\n }\n}\n\n/**\n * Minimal glob match for rule paths: `*` matches within a segment, `**`\n * across segments, `?` one character. Deterministic, no dependency, and\n * conservative — a malformed pattern simply never matches.\n */\nexport function globMatch(glob: string, file: string): boolean {\n let re = '';\n for (let i = 0; i < glob.length; i++) {\n const c = glob[i];\n if (c === '*') {\n if (glob[i + 1] === '*') {\n // `**/` or trailing `**` — match across segments.\n re += '.*';\n i += glob[i + 2] === '/' ? 2 : 1;\n } else {\n re += '[^/]*';\n }\n } else if (c === '?') {\n re += '[^/]';\n } else if ('\\\\^$.|+()[]{}'.includes(c)) {\n re += `\\\\${c}`;\n } else {\n re += c;\n }\n }\n try {\n return new RegExp(`^${re}$`).test(file);\n } catch {\n return false;\n }\n}\n\nfunction fileRuleMatches(rules: ApprovalRule[], op: 'edit' | 'create' | 'delete', file: string): ApprovalRule | null {\n for (const r of rules) {\n if (r.kind === op && globMatch(r.glob, file)) return r;\n }\n return null;\n}\n\n/**\n * The first rule matching this action, or null. A `patch` matches only when\n * *every* file in the transaction is covered by a matching file rule — an\n * atomic approval must never be half-earned.\n */\nexport function findMatchingRule(action: MutatingAction, rules: ApprovalRule[]): ApprovalRule | null {\n if (!rules.length) return null;\n switch (action.kind) {\n case 'run': {\n // Match the FULL whitespace-normalized command, never a truncated form:\n // collapsing `rm foo.log secrets.env` to its first two tokens before\n // comparing would silently discard the appended argument and let a rule\n // saved for `rm foo.log` bless it (2026-08 audit, D2).\n const full = action.command.trim().split(/\\s+/).filter(Boolean).join(' ');\n for (const r of rules) {\n if (r.kind !== 'run') continue;\n if (full === r.prefix) return r;\n // A `cmd [subcommand]` prefix extends to longer commands only when\n // every appended token is a flag (`git status --short`). Appended\n // positionals (extra paths, script arguments) are new state the user\n // never blessed — they re-prompt, and can be Always-allowed exactly.\n if (extensiblePrefix(r.prefix) && full.startsWith(`${r.prefix} `)) {\n const tail = full.slice(r.prefix.length + 1);\n // A flag whose value is a subshell is not an extension of the blessed\n // command, it is a different one — screen the appended text before\n // the flag-shape check, never after.\n if (SHELL_METACHARS.test(tail)) continue;\n const extension = tail.split(' ');\n if (extension.every((t) => t.startsWith('-'))) return r;\n }\n }\n return null;\n }\n case 'tool':\n return rules.find((r) => r.kind === 'tool' && r.tool === action.name) ?? null;\n case 'edit':\n case 'create':\n case 'delete':\n return fileRuleMatches(rules, action.kind, action.file);\n case 'patch': {\n const covered = action.files.every((f: PatchFileAction) => fileRuleMatches(rules, f.op, f.file));\n if (!covered) return null;\n return fileRuleMatches(rules, action.files[0]!.op, action.files[0]!.file);\n }\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cacheDir } from './chunk-2U37PFB2.js';
|
|
2
|
+
import { loadGraphFileWithSnapshot, resolveGraphPath } from './chunk-75LJM5XD.js';
|
|
2
3
|
import { __require } from './chunk-Z6ZWNWWR.js';
|
|
3
4
|
import * as fs from 'fs';
|
|
4
5
|
import * as path from 'path';
|
|
@@ -198,5 +199,5 @@ function loadGraph(root, graphPath) {
|
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
export { SCHEMA_VERSION, loadGraph, loadGraphPreferIndex, writeGraphIndex };
|
|
201
|
-
//# sourceMappingURL=chunk-
|
|
202
|
-
//# sourceMappingURL=chunk-
|
|
202
|
+
//# sourceMappingURL=chunk-WQLZSVNF.js.map
|
|
203
|
+
//# sourceMappingURL=chunk-WQLZSVNF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema.ts","../src/engine/index-db.ts","../src/engine/load.ts"],"names":[],"mappings":";;;;;;;AASO,IAAM,cAAA,GAAiB;;;AC2BvB,SAAS,YAAY,IAAA,EAAsB;AAChD,EAAA,OAAY,IAAA,CAAA,IAAA,CAAK,QAAA,CAAS,IAAI,CAAA,EAAG,UAAU,CAAA;AAC7C;AAGO,SAAS,eAAA,CAAgB,MAAc,KAAA,EAAkC;AAC9E,EAAA,MAAM,IAAA,GAAO,YAAY,IAAI,CAAA;AAC7B,EAAA,IAAI;AAEF,IAAA,MAAM,EAAE,YAAA,EAAa,GAAI,SAAA,CAAQ,QAAa,CAAA;AAC9C,IAAG,aAAe,IAAA,CAAA,OAAA,CAAQ,IAAI,GAAG,EAAE,SAAA,EAAW,MAAM,CAAA;AACpD,IAAA,MAAM,GAAA,GAAM,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,QAAQ,GAAG,CAAA,IAAA,CAAA;AAClC,IAAA,IAAI;AACF,MAAA,IAAO,EAAA,CAAA,UAAA,CAAW,GAAG,CAAA,EAAM,cAAW,GAAG,CAAA;AAAA,IAC3C,CAAA,CAAA,MAAQ;AAAA,IAER;AAEA,IAAA,MAAM,EAAA,GAAK,IAAI,YAAA,CAAa,GAAG,CAAA;AAC/B,IAAA,EAAA,CAAG,IAAA,CAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,mBAAmB,IAAI,CAAA;AACzC,EAAA,IAAI,SAAA,EAAW;AACb,IAAA,IAAI,CAAC,SAAA,IAAa,SAAA,CAAU,WAAW,UAAA,KAAe,SAAA,CAAU,WAAW,UAAA,EAAY;AACrF,MAAA,OAAO,EAAE,KAAA,EAAO,SAAA,EAAW,MAAA,EAAQ,OAAA,EAAQ;AAAA,IAC7C;AAAA,EAEF;AACA,EAAA,IAAI,WAAW,OAAO,EAAE,KAAA,EAAO,SAAA,EAAW,QAAQ,MAAA,EAAO;AACzD,EAAA,OAAO,IAAA;AACT;;;ACxWO,SAAS,SAAA,CAAU,MAAc,SAAA,EAAoC;AAC1E,EAAA,MAAM,IAAA,GAAO,gBAAA,CAAiB,IAAA,EAAM,SAAS,CAAA;AAG7C,EAAA,IAAI,CAAC,SAAA,EAAW;AACd,IAAA,MAAM,SAAA,GAAY,oBAAA,CAAqB,IAAA,EAAM,IAAI,CAAA;AACjD,IAAA,IAAI,SAAA,SAAkB,SAAA,CAAU,KAAA;AAAA,EAClC;AACA,EAAA,OAAO,0BAA0B,IAAI,CAAA;AACvC","file":"chunk-WQLZSVNF.js","sourcesContent":["/**\n * The `vg-graph/1.0` on-disk schema.\n *\n * This is vg's own open schema (VG-PACKAGE-AND-SCHEMA.md §4) — informed by good\n * ideas (content-hashed ids, epistemic typing of facts) but standalone and\n * self-contained. Every collection is deterministically serialized\n * (sorted keys, stable element order). These TypeScript shapes are normative.\n */\n\nexport const SCHEMA_VERSION = 'vg-graph/1.0' as const;\n\nexport type ResolverKind = 'scip' | 'stackgraph' | 'tsc' | 'heuristic';\n\n/** Coarse, honest resolution tier for an edge (see engine/epistemic.ts). */\nexport type EpistemicTier = 'observed' | 'name-matched' | 'declared';\n\n/**\n * The toolchain that produced this graph — the reproducibility fingerprint.\n * Everything here deterministically affects graph *content* (parse trees change\n * between grammar releases; resolvers change which edges resolve), so a CI run\n * and a laptop run that disagree can be caught by comparing `fingerprint`.\n * Deliberately excludes the Node/OS version so the graph stays byte-stable\n * across host runtimes; `fingerprint` pins the parse/resolve toolchain only.\n */\nexport interface Toolchain {\n schema: string; // SCHEMA_VERSION\n tool: string; // vg calendar version\n grammars: string; // tree-sitter grammar set version string\n resolvers: ResolverKind[]; // resolver kinds available, sorted\n fingerprint: string; // shortId over the fields above — the value `vg attest` signs\n}\n\nexport interface Provenance {\n tool: 'vg';\n version: string; // calendar version\n grammars: Record<string, string>; // lang → grammar version (determinism input)\n resolver: ResolverKind[];\n deep: boolean; // did the heavier open passes run\n semanticModel?: string; // embedding model id+version if --deep semantic links\n corpusHash: string; // blake3 over the included file set + hashes\n toolchain?: Toolchain; // reproducibility fingerprint (checked by `vg verify`)\n}\n\n/** Analysis cost tier — auto-selected by node count (or forced). Reported honestly. */\nexport type AnalysisTier = 'full' | 'large' | 'xl';\n\nexport interface GraphMeta {\n root: string; // relative; portable across machines\n languages: string[];\n counts: {\n nodes: number;\n edges: number;\n areas: number;\n tests: number;\n untested: number;\n };\n cluster: 'leiden' | 'louvain' | 'none';\n /** Auto-selected (or forced) analysis tier for large maps. */\n analysisTier?: AnalysisTier;\n edgeKinds: EdgeKind[];\n}\n\nexport type NodeKind =\n | 'file'\n | 'module'\n | 'package'\n | 'class'\n | 'interface'\n | 'function'\n | 'method'\n | 'property'\n | 'test'\n | 'route'\n | 'component'\n /** Documentation / config text ingested for semantic ask (markdown, txt, env examples). */\n | 'document'\n | 'external';\n\nexport interface Span {\n start: number; // 1-based start line\n end: number; // 1-based end line\n}\n\nexport interface Centrality {\n degree: number;\n pagerank: number;\n betweenness: number;\n eigenvector: number;\n}\n\nexport interface GraphNode {\n id: string; // blake3(canonical(kind, qualifiedName, file, signature))\n kind: NodeKind;\n name: string; // short name\n qualifiedName: string;\n file: string; // relative path\n span: Span; // line range (excluded from id hash)\n lang: string;\n visibility?: 'public' | 'private' | 'protected' | 'internal';\n signature?: string;\n doc?: string; // short leading doc-comment / docstring summary (deterministic; not a full body)\n importance: number; // 0..1 blended centrality\n centrality: Centrality;\n area: number; // area id (the node's community); -1 = unassigned (cluster \"none\")\n isHub: boolean; // centrality outlier — surfaced by `vg hubs`\n tested: boolean | null; // null = not analyzable (e.g. external)\n coverage?: number; // 0..1 line coverage if a coverage report was ingested\n changeCoupling?: string[]; // node ids that historically change together\n}\n\nexport type EdgeKind =\n | 'call'\n | 'import'\n | 'contains'\n | 'extends'\n | 'implements'\n | 'references'\n | 'test'\n | 'coverage';\n\nexport interface GraphEdge {\n id: string; // blake3(canonical(kind, src, dst))\n kind: EdgeKind;\n src: string; // node id\n dst: string; // node id\n resolution: ResolverKind; // how the edge was resolved\n confidence: number; // 0..1 (1.0 for scip/declared; lower for heuristic/dynamic)\n epistemic?: EpistemicTier; // coarse honesty tier derived from resolution+kind\n surprise?: number; // 0..1 improbability under the area model (`vg oddities`)\n count?: number; // call-site multiplicity\n}\n\nexport interface Area {\n id: number; // stable across runs (remapped to previous committed map)\n label: string; // most-central member's name (editable via `vg label`)\n size: number;\n members: string[]; // node ids, sorted\n cohesion: number; // 0..1\n externalEdges: number; // cross-area edge count\n}\n\nexport type FactKind = 'contract' | 'invariant' | 'characterization';\nexport type DerivedBy = 'declared' | 'static';\nexport type FactConfidence = 'Observed' | 'Derived';\n\nexport interface Fact {\n id: string; // blake3(canonical(kind, subjectIds, predicate))\n kind: FactKind;\n subjectIds: string[]; // node ids this fact constrains\n predicate: unknown; // the constraint\n derivedBy: DerivedBy;\n confidence: FactConfidence;\n evidence: { file: string; span: Span }[];\n}\n\n/**\n * A reference the graph could not resolve — surfaced by `vg unknowns`. Reporting\n * what it *cannot* connect (ranked by blast radius) is the honest inverse of a\n * scanner that hides its unknowns. Only unknowns the precise rungs (tsc/scip)\n * did not supersede are recorded, so a compiler-resolved file never shows here.\n */\nexport interface Unknown {\n from: string; // node id where the unresolved reference occurs\n name: string; // the callee/type name that could not be resolved\n kind: 'call' | 'extends' | 'implements';\n count: number; // occurrences at this site\n}\n\nexport type GroundingKind = 'should_follow' | 'smells_like' | 'relevant_to';\n\nexport interface GroundingEdge {\n src: string; // node id\n packEntryId: string;\n kind: GroundingKind;\n confidence: number; // 0..1\n rationale: 'recommended' | 'conjectured';\n citation: { title: string; url: string };\n}\n\n/** Precomputed hub blast-radius counts for fast agent answers (optional). */\nexport interface HubBlastSummary {\n id: string;\n name: string;\n kind: string;\n file: string;\n importance: number;\n direct: number;\n depth2: number;\n files: number;\n tested: boolean | null;\n}\n\nexport interface GraphSummaries {\n hubs: HubBlastSummary[];\n}\n\nexport interface VgGraph {\n schemaVersion: typeof SCHEMA_VERSION;\n generatedAt: string; // ISO; the ONLY nondeterministic field (pinned by --generated-at)\n provenance: Provenance;\n meta: GraphMeta;\n nodes: GraphNode[]; // sorted by id\n edges: GraphEdge[]; // sorted by (kind, src, dst)\n areas: Area[]; // sorted by id\n facts?: Fact[]; // open facts (contract/invariant/characterization); sorted by id\n grounding?: GroundingEdge[]; // free-pack grounding (default on; omit with --no-ground)\n unknowns?: Unknown[]; // heuristic references left unresolved; sorted by (from, kind, name)\n /** Build-time hub blast-radius summaries (always on; tiny). */\n summaries?: GraphSummaries;\n}\n","/**\n * SQLite serve index for large maps (scale past flat-JSON-only serve).\n *\n * The canonical artifact remains `graph.json` (determinism / git). The index\n * at `.vibgrate/cache/graph.db` is a derived, gitignored structure built after\n * every successful build:\n * - denormalized name/edge columns for O(log n) lookup\n * - full node/edge/area JSON for reconstructing a `VgGraph` without parsing\n * the pretty-printed graph.json (faster cold serve on XL maps)\n *\n * Uses Node's built-in `node:sqlite` (Node ≥22) — no native npm dependency.\n */\n\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { cacheDir } from './cache.js';\nimport { loadGraphFileWithSnapshot } from './snapshot.js';\nimport type {\n Area,\n EpistemicTier,\n GraphEdge,\n GraphNode,\n ResolverKind,\n VgGraph,\n} from '../schema.js';\nimport { SCHEMA_VERSION } from '../schema.js';\n\nexport interface IndexWriteResult {\n path: string;\n nodes: number;\n edges: number;\n /** False when node:sqlite is unavailable — callers should not fail the build. */\n ok: boolean;\n reason?: string;\n}\n\nexport function indexDbPath(root: string): string {\n return path.join(cacheDir(root), 'graph.db');\n}\n\n/** Write (replace) the SQLite index from a built graph. Never throws to callers. */\nexport function writeGraphIndex(root: string, graph: VgGraph): IndexWriteResult {\n const file = indexDbPath(root);\n try {\n \n const { DatabaseSync } = require('node:sqlite') as typeof import('node:sqlite');\n fs.mkdirSync(path.dirname(file), { recursive: true });\n const tmp = `${file}.${process.pid}.tmp`;\n try {\n if (fs.existsSync(tmp)) fs.unlinkSync(tmp);\n } catch {\n /* ignore */\n }\n\n const db = new DatabaseSync(tmp);\n db.exec(`\n PRAGMA journal_mode = OFF;\n PRAGMA synchronous = OFF;\n CREATE TABLE meta (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL\n );\n CREATE TABLE nodes (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n qualified_name TEXT NOT NULL,\n kind TEXT NOT NULL,\n file TEXT NOT NULL,\n line INTEGER NOT NULL,\n importance REAL NOT NULL,\n area INTEGER NOT NULL,\n is_hub INTEGER NOT NULL,\n lang TEXT NOT NULL,\n json TEXT NOT NULL\n );\n CREATE TABLE edges (\n id TEXT PRIMARY KEY,\n kind TEXT NOT NULL,\n src TEXT NOT NULL,\n dst TEXT NOT NULL,\n resolution TEXT NOT NULL,\n confidence REAL NOT NULL,\n epistemic TEXT NOT NULL,\n json TEXT NOT NULL\n );\n CREATE TABLE areas (\n id INTEGER PRIMARY KEY,\n json TEXT NOT NULL\n );\n CREATE INDEX idx_nodes_name ON nodes(name);\n CREATE INDEX idx_nodes_qn ON nodes(qualified_name);\n CREATE INDEX idx_nodes_file ON nodes(file);\n CREATE INDEX idx_edges_src ON edges(src);\n CREATE INDEX idx_edges_dst ON edges(dst);\n CREATE INDEX idx_edges_kind ON edges(kind);\n `);\n\n const insMeta = db.prepare('INSERT INTO meta(key, value) VALUES (?, ?)');\n insMeta.run('corpusHash', graph.provenance.corpusHash);\n insMeta.run('schemaVersion', graph.schemaVersion);\n insMeta.run('generatedAt', graph.generatedAt);\n insMeta.run('nodeCount', String(graph.nodes.length));\n insMeta.run('edgeCount', String(graph.edges.length));\n insMeta.run('analysisTier', graph.meta.analysisTier ?? 'full');\n insMeta.run('indexVersion', 'vg-graph-index/2');\n // Full meta + provenance for reconstruct without graph.json parse.\n insMeta.run('graphMeta', JSON.stringify(graph.meta));\n insMeta.run('graphProvenance', JSON.stringify(graph.provenance));\n if (graph.facts) insMeta.run('factsJson', JSON.stringify(graph.facts));\n if (graph.grounding) insMeta.run('groundingJson', JSON.stringify(graph.grounding));\n if (graph.summaries) insMeta.run('summariesJson', JSON.stringify(graph.summaries));\n if (graph.unknowns) insMeta.run('unknownsJson', JSON.stringify(graph.unknowns));\n\n const insNode = db.prepare(\n `INSERT INTO nodes(id, name, qualified_name, kind, file, line, importance, area, is_hub, lang, json)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n );\n for (const n of graph.nodes) {\n insNode.run(\n n.id,\n n.name,\n n.qualifiedName,\n n.kind,\n n.file,\n n.span.start,\n n.importance,\n n.area,\n n.isHub ? 1 : 0,\n n.lang,\n JSON.stringify(n),\n );\n }\n\n const insEdge = db.prepare(\n `INSERT INTO edges(id, kind, src, dst, resolution, confidence, epistemic, json)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,\n );\n for (const e of graph.edges) {\n insEdge.run(\n e.id,\n e.kind,\n e.src,\n e.dst,\n e.resolution,\n e.confidence,\n e.epistemic ?? 'observed',\n JSON.stringify(e),\n );\n }\n\n const insArea = db.prepare('INSERT INTO areas(id, json) VALUES (?, ?)');\n for (const a of graph.areas) {\n insArea.run(a.id, JSON.stringify(a));\n }\n\n db.close();\n fs.renameSync(tmp, file);\n return { path: file, nodes: graph.nodes.length, edges: graph.edges.length, ok: true };\n } catch (err) {\n return {\n path: file,\n nodes: 0,\n edges: 0,\n ok: false,\n reason: (err as Error).message,\n };\n }\n}\n\nexport interface NameHit {\n id: string;\n name: string;\n qualifiedName: string;\n kind: string;\n file: string;\n line: number;\n importance: number;\n}\n\n/** Fast name / prefix lookup against the index. Empty if index missing. */\nexport function lookupNameIndex(root: string, query: string, limit = 20): NameHit[] {\n const file = indexDbPath(root);\n if (!fs.existsSync(file) || !query.trim()) return [];\n try {\n \n const { DatabaseSync } = require('node:sqlite') as typeof import('node:sqlite');\n const db = new DatabaseSync(file, { readOnly: true });\n const q = query.trim();\n const rows = db\n .prepare(\n `SELECT id, name, qualified_name, kind, file, line, importance\n FROM nodes\n WHERE name = ? OR qualified_name = ? OR name LIKE ? OR qualified_name LIKE ?\n ORDER BY\n CASE WHEN name = ? OR qualified_name = ? THEN 0\n WHEN name LIKE ? THEN 1\n ELSE 2 END,\n importance DESC\n LIMIT ?`,\n )\n .all(q, q, `${q}%`, `%${q}%`, q, q, `${q}%`, limit) as Record<string, unknown>[];\n db.close();\n return rows.map((r) => ({\n id: String(r.id),\n name: String(r.name),\n qualifiedName: String(r.qualified_name),\n kind: String(r.kind),\n file: String(r.file),\n line: Number(r.line),\n importance: Number(r.importance),\n }));\n } catch {\n return [];\n }\n}\n\n/** Neighbor edges for a node id (src or dst). Empty if index missing. */\nexport function lookupNeighbors(\n root: string,\n nodeId: string,\n direction: 'out' | 'in' | 'both' = 'both',\n limit = 50,\n): GraphEdge[] {\n const file = indexDbPath(root);\n if (!fs.existsSync(file) || !nodeId) return [];\n try {\n \n const { DatabaseSync } = require('node:sqlite') as typeof import('node:sqlite');\n const db = new DatabaseSync(file, { readOnly: true });\n let rows: Record<string, unknown>[] = [];\n if (direction === 'out' || direction === 'both') {\n rows = rows.concat(\n db\n .prepare(`SELECT json FROM edges WHERE src = ? LIMIT ?`)\n .all(nodeId, limit) as Record<string, unknown>[],\n );\n }\n if (direction === 'in' || direction === 'both') {\n rows = rows.concat(\n db\n .prepare(`SELECT json FROM edges WHERE dst = ? LIMIT ?`)\n .all(nodeId, limit) as Record<string, unknown>[],\n );\n }\n db.close();\n const byId = new Map<string, GraphEdge>();\n for (const r of rows) {\n try {\n const e = JSON.parse(String(r.json)) as GraphEdge;\n byId.set(e.id, e);\n } catch {\n /* skip bad row */\n }\n }\n return [...byId.values()];\n } catch {\n return [];\n }\n}\n\n/** Read index meta (corpusHash etc.) or null if missing. */\nexport function readIndexMeta(root: string): Record<string, string> | null {\n const file = indexDbPath(root);\n if (!fs.existsSync(file)) return null;\n try {\n \n const { DatabaseSync } = require('node:sqlite') as typeof import('node:sqlite');\n const db = new DatabaseSync(file, { readOnly: true });\n const rows = db.prepare('SELECT key, value FROM meta').all() as { key: string; value: string }[];\n db.close();\n const out: Record<string, string> = {};\n for (const r of rows) out[r.key] = r.value;\n return out;\n } catch {\n return null;\n }\n}\n\n/**\n * Reconstruct a full `VgGraph` from the SQLite index (indexVersion ≥ 2).\n * Returns null if the index is missing, stale schema, or incomplete.\n * Prefer this over JSON.parse of pretty graph.json for cold serve on large maps.\n */\nexport function loadGraphFromIndex(root: string): VgGraph | null {\n const file = indexDbPath(root);\n if (!fs.existsSync(file)) return null;\n try {\n \n const { DatabaseSync } = require('node:sqlite') as typeof import('node:sqlite');\n const db = new DatabaseSync(file, { readOnly: true });\n const metaRows = db.prepare('SELECT key, value FROM meta').all() as {\n key: string;\n value: string;\n }[];\n const meta: Record<string, string> = {};\n for (const r of metaRows) meta[r.key] = r.value;\n\n if (meta.indexVersion !== 'vg-graph-index/2' || !meta.graphMeta || !meta.graphProvenance) {\n db.close();\n return null;\n }\n\n const nodeRows = db.prepare('SELECT json FROM nodes ORDER BY id').all() as {\n json: string;\n }[];\n const edgeRows = db.prepare('SELECT json FROM edges ORDER BY id').all() as {\n json: string;\n }[];\n const areaRows = db.prepare('SELECT json FROM areas ORDER BY id').all() as {\n json: string;\n }[];\n db.close();\n\n const nodes = nodeRows.map((r) => JSON.parse(r.json) as GraphNode);\n const edges = edgeRows.map((r) => JSON.parse(r.json) as GraphEdge);\n const areas = areaRows.map((r) => JSON.parse(r.json) as Area);\n\n // Stable sorts match serialize contract (ids already ordered by SQL, re-sort for safety).\n nodes.sort((a, b) => a.id.localeCompare(b.id));\n edges.sort(\n (a, b) =>\n a.kind.localeCompare(b.kind) || a.src.localeCompare(b.src) || a.dst.localeCompare(b.dst),\n );\n areas.sort((a, b) => a.id - b.id);\n\n const graph: VgGraph = {\n schemaVersion: (meta.schemaVersion as typeof SCHEMA_VERSION) || SCHEMA_VERSION,\n generatedAt: meta.generatedAt ?? new Date(0).toISOString(),\n provenance: JSON.parse(meta.graphProvenance),\n meta: JSON.parse(meta.graphMeta),\n nodes,\n edges,\n areas,\n };\n if (meta.factsJson) graph.facts = JSON.parse(meta.factsJson);\n if (meta.groundingJson) graph.grounding = JSON.parse(meta.groundingJson);\n if (meta.summariesJson) graph.summaries = JSON.parse(meta.summariesJson);\n if (meta.unknownsJson) graph.unknowns = JSON.parse(meta.unknownsJson);\n\n // Lightweight integrity: edge resolution types stay valid.\n for (const e of edges) {\n if (!e.resolution) e.resolution = 'heuristic' as ResolverKind;\n if (!e.epistemic) e.epistemic = 'observed' as EpistemicTier;\n }\n return graph;\n } catch {\n return null;\n }\n}\n\n/**\n * Load the graph preferring the SQLite index when its corpusHash matches the\n * committed graph.json provenance (or when only the index exists). Falls back\n * to graph.json. Returns null if neither is usable.\n */\nexport function loadGraphPreferIndex(\n root: string,\n graphJsonPath: string,\n): { graph: VgGraph; source: 'index' | 'json' } | null {\n // Snapshot-first: skips the large-string JSON.parse when a fresh binary\n // snapshot exists (sidecar or store-mode standalone), and self-heals the\n // sidecar when not (see engine/snapshot.ts).\n const jsonGraph: VgGraph | null = loadGraphFileWithSnapshot(graphJsonPath);\n\n const fromIndex = loadGraphFromIndex(root);\n if (fromIndex) {\n if (!jsonGraph || fromIndex.provenance.corpusHash === jsonGraph.provenance.corpusHash) {\n return { graph: fromIndex, source: 'index' };\n }\n // Index stale vs graph.json — prefer canonical JSON and let next build refresh.\n }\n if (jsonGraph) return { graph: jsonGraph, source: 'json' };\n return null;\n}\n","import { resolveGraphPath } from './artifacts.js';\nimport { loadGraphFileWithSnapshot } from './snapshot.js';\nimport { loadGraphPreferIndex } from './index-db.js';\nimport type { VgGraph } from '../schema.js';\n\n/**\n * Load the code map for a repository.\n *\n * When `graphPath` is omitted, prefers an existing global-store snapshot, then\n * the legacy `.vibgrate/graph.json`, matching {@link resolveGraphPath}.\n * Prefers the SQLite index when its corpusHash matches the committed map\n * (faster cold serve on large repos). Returns null if none exists.\n */\nexport function loadGraph(root: string, graphPath?: string): VgGraph | null {\n const file = resolveGraphPath(root, graphPath);\n // Index is always rooted at the project root; only use it when loading the\n // default map for that root (not an arbitrary --graph path).\n if (!graphPath) {\n const preferred = loadGraphPreferIndex(root, file);\n if (preferred) return preferred.graph;\n }\n return loadGraphFileWithSnapshot(file);\n}\n"]}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { loadConfig, computeUpgradeImpact, getChangelogSignals, gitHistoryAvailable, buildVersionTimelines, findPackageTimeline, severityRank, projectTypeToVulnEcosystem } from './chunk-N6ZMZ5AI.js';
|
|
2
1
|
import { availableRegionIds, resolveIngestHost, dashHostForIngestHost, ingestHostForRegionId } from './chunk-HTLDXEHW.js';
|
|
3
|
-
import {
|
|
2
|
+
import { loadConfig, computeUpgradeImpact, getChangelogSignals, gitHistoryAvailable, buildVersionTimelines, findPackageTimeline, severityRank, projectTypeToVulnEcosystem } from './chunk-N6ZMZ5AI.js';
|
|
3
|
+
import { searchSymbols, resolveVersion, resolveLib, loadCatalog, driftFor, localPackageDocs, readDoc, inventory, localApiSurface } from './chunk-7QDHQLUS.js';
|
|
4
|
+
import { resolveOne } from './chunk-J7LKEB2R.js';
|
|
5
|
+
import { impactOf, indexFor, queryGraphSemantic, queryGraph } from './chunk-KGPX4EUN.js';
|
|
4
6
|
import { discoverModels } from './chunk-CQDUBAQY.js';
|
|
5
7
|
import { loadOrDiscoverFederation, highConfidenceBridges } from './chunk-5I4VSBWQ.js';
|
|
6
8
|
import { writeTextFile, pathExists, readJsonFile } from './chunk-CRAMOEBE.js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { parseGraph, analyzeQuestion, loadTopicTags, cacheDir } from './chunk-EWZKOU66.js';
|
|
9
|
+
import { withTimeout, getNodeEmbeddings, loadEmbedder, isModelReady } from './chunk-X76VPOYH.js';
|
|
10
|
+
import { cacheDir } from './chunk-2U37PFB2.js';
|
|
11
|
+
import { parseGraph, analyzeQuestion, loadTopicTags } from './chunk-75LJM5XD.js';
|
|
11
12
|
import { repositoryIdFromRoot } from './chunk-BWPBB45M.js';
|
|
12
13
|
import { bidirectional } from 'graphology-shortest-path/unweighted.js';
|
|
13
14
|
import Graph from 'graphology';
|
|
@@ -2223,5 +2224,5 @@ function navigationToolsetConfig(serverName = "vibgrate") {
|
|
|
2223
2224
|
}
|
|
2224
2225
|
|
|
2225
2226
|
export { FREE_PACK, HOT_TOOLS, TOOLS, assessDocQuality, budgetSuffix, clearStoredCredentials, countTokens, coveringTests, createWorkspaceDsn, credentialsPath, deferredToolNames, detectRunner, dsnCommand, ensureGitignored, fetchHostedDocsCached, findGitRoot, gitignoreEntryForCredentials, homeCredentialsPath, hostedBase, listedToolNames, navigationToolsetConfig, parseDsn, pathDisconnect, projectCredentialsPath, publishPrivateLibrary, pushCommand, readScanArtifact, readStoredCredentials, renderToolResult, resolveDsn, selectForBudget, shortestPath, symbolsFromApi, testsToRun, uploadScanArtifact, warmEmbedderInBackground, writeStoredCredentials };
|
|
2226
|
-
//# sourceMappingURL=chunk-
|
|
2227
|
-
//# sourceMappingURL=chunk-
|
|
2227
|
+
//# sourceMappingURL=chunk-WWGLVF7D.js.map
|
|
2228
|
+
//# sourceMappingURL=chunk-WWGLVF7D.js.map
|