@vibgrate/cli 2026.722.2 → 2026.727.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.
Files changed (145) hide show
  1. package/DOCS.md +418 -213
  2. package/README.md +34 -8
  3. package/dist/baseline-TG4ATZGZ.js +8 -0
  4. package/dist/{baseline-BD3A7EXD.js.map → baseline-TG4ATZGZ.js.map} +1 -1
  5. package/dist/chunk-2MBL43EJ.js +82 -0
  6. package/dist/chunk-2MBL43EJ.js.map +1 -0
  7. package/dist/chunk-2XQDMLKB.js +465 -0
  8. package/dist/chunk-2XQDMLKB.js.map +1 -0
  9. package/dist/{chunk-PY3DNX5H.js → chunk-3Q7QBWFW.js} +13 -2
  10. package/dist/chunk-3Q7QBWFW.js.map +1 -0
  11. package/dist/chunk-3V24O47U.js +478 -0
  12. package/dist/chunk-3V24O47U.js.map +1 -0
  13. package/dist/chunk-5I4VSBWQ.js +764 -0
  14. package/dist/chunk-5I4VSBWQ.js.map +1 -0
  15. package/dist/{chunk-WNIIKCNF.js → chunk-6ABXHZRN.js} +59 -311
  16. package/dist/chunk-6ABXHZRN.js.map +1 -0
  17. package/dist/chunk-6AYDFFP5.js +136 -0
  18. package/dist/chunk-6AYDFFP5.js.map +1 -0
  19. package/dist/chunk-6UQMXIAG.js +122 -0
  20. package/dist/chunk-6UQMXIAG.js.map +1 -0
  21. package/dist/chunk-7N4Y3E47.js +108 -0
  22. package/dist/chunk-7N4Y3E47.js.map +1 -0
  23. package/dist/chunk-BPF3YX2U.js +64 -0
  24. package/dist/chunk-BPF3YX2U.js.map +1 -0
  25. package/dist/chunk-BWPBB45M.js +88 -0
  26. package/dist/chunk-BWPBB45M.js.map +1 -0
  27. package/dist/{chunk-6CXTPC74.js → chunk-CY4WKXB2.js} +27 -6
  28. package/dist/chunk-CY4WKXB2.js.map +1 -0
  29. package/dist/chunk-DGUM43GV.js +10 -0
  30. package/dist/chunk-DGUM43GV.js.map +1 -0
  31. package/dist/{chunk-NONYJLOJ.js → chunk-EX4PQT6W.js} +3 -3
  32. package/dist/{chunk-NONYJLOJ.js.map → chunk-EX4PQT6W.js.map} +1 -1
  33. package/dist/chunk-IS7VTH2Q.js +627 -0
  34. package/dist/chunk-IS7VTH2Q.js.map +1 -0
  35. package/dist/chunk-IZDH67DX.js +289 -0
  36. package/dist/chunk-IZDH67DX.js.map +1 -0
  37. package/dist/chunk-J4RFRKZH.js +2496 -0
  38. package/dist/chunk-J4RFRKZH.js.map +1 -0
  39. package/dist/chunk-J7LKEB2R.js +51 -0
  40. package/dist/chunk-J7LKEB2R.js.map +1 -0
  41. package/dist/chunk-JIBOJTGS.js +313 -0
  42. package/dist/chunk-JIBOJTGS.js.map +1 -0
  43. package/dist/chunk-K3MZIVZW.js +88 -0
  44. package/dist/chunk-K3MZIVZW.js.map +1 -0
  45. package/dist/chunk-K7REHDQS.js +776 -0
  46. package/dist/chunk-K7REHDQS.js.map +1 -0
  47. package/dist/{chunk-2O5YZVZV.js → chunk-KCKYKDMS.js} +23 -19
  48. package/dist/chunk-KCKYKDMS.js.map +1 -0
  49. package/dist/{chunk-3MXNNBLI.js → chunk-KNELIQJO.js} +1647 -2042
  50. package/dist/chunk-KNELIQJO.js.map +1 -0
  51. package/dist/chunk-KSBHGWRV.js +613 -0
  52. package/dist/chunk-KSBHGWRV.js.map +1 -0
  53. package/dist/chunk-LKVMI67M.js +1695 -0
  54. package/dist/chunk-LKVMI67M.js.map +1 -0
  55. package/dist/chunk-NDMDSPFX.js +69 -0
  56. package/dist/chunk-NDMDSPFX.js.map +1 -0
  57. package/dist/{chunk-CS37OBE3.js → chunk-OFUC6RYN.js} +791 -783
  58. package/dist/chunk-OFUC6RYN.js.map +1 -0
  59. package/dist/chunk-OOIG3RUM.js +276 -0
  60. package/dist/chunk-OOIG3RUM.js.map +1 -0
  61. package/dist/chunk-PMYWZRRS.js +62 -0
  62. package/dist/chunk-PMYWZRRS.js.map +1 -0
  63. package/dist/chunk-PXHNTC6D.js +382 -0
  64. package/dist/chunk-PXHNTC6D.js.map +1 -0
  65. package/dist/{chunk-I7GY7MVN.js → chunk-RNP3SMTV.js} +60 -12
  66. package/dist/chunk-RNP3SMTV.js.map +1 -0
  67. package/dist/chunk-TCDAZZNP.js +843 -0
  68. package/dist/chunk-TCDAZZNP.js.map +1 -0
  69. package/dist/{chunk-5BDHQ7DD.js → chunk-WGUL45AV.js} +24 -17
  70. package/dist/chunk-WGUL45AV.js.map +1 -0
  71. package/dist/cli.d.ts +3 -0
  72. package/dist/cli.js +3373 -617
  73. package/dist/cli.js.map +1 -1
  74. package/dist/execution-env-ZU45JZ4G.js +4 -0
  75. package/dist/execution-env-ZU45JZ4G.js.map +1 -0
  76. package/dist/federation-SZWZIFZ7.js +7 -0
  77. package/dist/federation-SZWZIFZ7.js.map +1 -0
  78. package/dist/{fs-IPY4FJKH.js → fs-B5HZ2MIU.js} +3 -2
  79. package/dist/fs-B5HZ2MIU.js.map +1 -0
  80. package/dist/{fs-KCABDURV.js → fs-O5IQYXHO.js} +3 -2
  81. package/dist/fs-O5IQYXHO.js.map +1 -0
  82. package/dist/git-ref-XDXB6JP5.js +4 -0
  83. package/dist/git-ref-XDXB6JP5.js.map +1 -0
  84. package/dist/graph-backend-73URGTFY.js +11 -0
  85. package/dist/graph-backend-73URGTFY.js.map +1 -0
  86. package/dist/index.d.ts +472 -137
  87. package/dist/index.js +15 -7
  88. package/dist/index.js.map +1 -1
  89. package/dist/{interactive-A4DISSIW.js → interactive-372NLI5C.js} +186 -226
  90. package/dist/interactive-372NLI5C.js.map +1 -0
  91. package/dist/llm-host-7GWDO6IX.js +9 -0
  92. package/dist/llm-host-7GWDO6IX.js.map +1 -0
  93. package/dist/load-I333TGNI.js +8 -0
  94. package/dist/load-I333TGNI.js.map +1 -0
  95. package/dist/local-runtime-5O2NN3GA.js +5 -0
  96. package/dist/local-runtime-5O2NN3GA.js.map +1 -0
  97. package/dist/mcp-tools-I7JK3S2M.js +4 -0
  98. package/dist/{mcp-tools-I6PME3AV.js.map → mcp-tools-I7JK3S2M.js.map} +1 -1
  99. package/dist/model-execution-profile-TFBKCNJG.js +4 -0
  100. package/dist/model-execution-profile-TFBKCNJG.js.map +1 -0
  101. package/dist/model-orchestrator-TVONAUPS.js +9 -0
  102. package/dist/model-orchestrator-TVONAUPS.js.map +1 -0
  103. package/dist/parse-worker.d.ts +1 -1
  104. package/dist/parse-worker.js +2 -1
  105. package/dist/parse-worker.js.map +1 -1
  106. package/dist/paths-2RAH3GME.js +6 -0
  107. package/dist/paths-2RAH3GME.js.map +1 -0
  108. package/dist/resolve-gguf-VPL4YQ6J.js +8 -0
  109. package/dist/resolve-gguf-VPL4YQ6J.js.map +1 -0
  110. package/dist/runtime-session-JRKCQUHY.js +18 -0
  111. package/dist/runtime-session-JRKCQUHY.js.map +1 -0
  112. package/dist/session-ITPYQ5XI.js +11 -0
  113. package/dist/{session-POJUDFPH.js.map → session-ITPYQ5XI.js.map} +1 -1
  114. package/dist/session-store-WFBX7HXL.js +4 -0
  115. package/dist/{session-store-W5RZZHA3.js.map → session-store-WFBX7HXL.js.map} +1 -1
  116. package/dist/{stream-json-Q2JGWPHB.js → stream-json-SLMDKLXP.js} +17 -6
  117. package/dist/stream-json-SLMDKLXP.js.map +1 -0
  118. package/dist/{types-Jl6RJ175.d.ts → types-7AHBUbFm.d.ts} +8 -2
  119. package/dist/ui-Q6DJ3GCU.js +5 -0
  120. package/dist/ui-Q6DJ3GCU.js.map +1 -0
  121. package/dist/vgd-7JV5KCNJ.js +17 -0
  122. package/dist/vgd-7JV5KCNJ.js.map +1 -0
  123. package/package.json +9 -6
  124. package/dist/baseline-BD3A7EXD.js +0 -7
  125. package/dist/chunk-2O5YZVZV.js.map +0 -1
  126. package/dist/chunk-3MXNNBLI.js.map +0 -1
  127. package/dist/chunk-5BDHQ7DD.js.map +0 -1
  128. package/dist/chunk-6CXTPC74.js.map +0 -1
  129. package/dist/chunk-CS37OBE3.js.map +0 -1
  130. package/dist/chunk-GGJZA3Q6.js +0 -961
  131. package/dist/chunk-GGJZA3Q6.js.map +0 -1
  132. package/dist/chunk-I7GY7MVN.js.map +0 -1
  133. package/dist/chunk-JBXNQCGE.js +0 -484
  134. package/dist/chunk-JBXNQCGE.js.map +0 -1
  135. package/dist/chunk-PY3DNX5H.js.map +0 -1
  136. package/dist/chunk-WNIIKCNF.js.map +0 -1
  137. package/dist/fs-IPY4FJKH.js.map +0 -1
  138. package/dist/fs-KCABDURV.js.map +0 -1
  139. package/dist/interactive-A4DISSIW.js.map +0 -1
  140. package/dist/mcp-tools-I6PME3AV.js +0 -3
  141. package/dist/session-POJUDFPH.js +0 -6
  142. package/dist/session-store-W5RZZHA3.js +0 -3
  143. package/dist/stream-json-Q2JGWPHB.js.map +0 -1
  144. package/dist/ui-HOVOPWMX.js +0 -4
  145. package/dist/ui-HOVOPWMX.js.map +0 -1
@@ -1,78 +1,11 @@
1
+ import { cacheDir } from './chunk-K3MZIVZW.js';
1
2
  import { hashString } from './chunk-JFGYT6BI.js';
2
- import * as fs3 from 'fs';
3
+ import * as fs2 from 'fs';
3
4
  import { createRequire } from 'module';
4
5
  import * as os from 'os';
5
- import * as path3 from 'path';
6
+ import * as path2 from 'path';
6
7
  import { pathToFileURL } from 'url';
7
8
 
8
- // src/engine/serialize.ts
9
- function serializeGraph(graph) {
10
- return `${stableStringify(graph, 2)}
11
- `;
12
- }
13
- function stableStringify(value, indent = 2) {
14
- return JSON.stringify(sortKeys(value), null, indent);
15
- }
16
- function sortKeys(value) {
17
- if (Array.isArray(value)) return value.map(sortKeys);
18
- if (value && typeof value === "object") {
19
- const input = value;
20
- const out = {};
21
- for (const key of Object.keys(input).sort()) {
22
- const v = input[key];
23
- if (v === void 0) continue;
24
- out[key] = sortKeys(v);
25
- }
26
- return out;
27
- }
28
- return value;
29
- }
30
- function parseGraph(json) {
31
- return JSON.parse(json);
32
- }
33
- var CACHE_VERSION = "vg-parse-cache/3";
34
- function cacheDir(root) {
35
- return path3.join(root, ".vibgrate", "cache");
36
- }
37
- function cachePath(root) {
38
- return path3.join(cacheDir(root), "parse-cache.json");
39
- }
40
- function loadCache(root, opts) {
41
- const file = cachePath(root);
42
- let data = {
43
- version: CACHE_VERSION,
44
- toolVersion: opts.toolVersion,
45
- grammars: opts.grammars,
46
- entries: {}
47
- };
48
- if (!opts.disabled && fs3.existsSync(file)) {
49
- try {
50
- const loaded = JSON.parse(fs3.readFileSync(file, "utf8"));
51
- if (loaded.version === CACHE_VERSION && loaded.toolVersion === opts.toolVersion && loaded.grammars === opts.grammars && loaded.entries) {
52
- data = loaded;
53
- }
54
- } catch {
55
- }
56
- }
57
- return {
58
- get(rel, hash) {
59
- const entry = data.entries[rel];
60
- return entry && entry.hash === hash ? entry.parse : void 0;
61
- },
62
- set(rel, parse) {
63
- data.entries[rel] = { hash: parse.hash, parse };
64
- },
65
- prune(currentRels) {
66
- for (const rel of Object.keys(data.entries)) {
67
- if (!currentRels.has(rel)) delete data.entries[rel];
68
- }
69
- },
70
- save() {
71
- fs3.mkdirSync(cacheDir(root), { recursive: true });
72
- fs3.writeFileSync(file, stableStringify(data, 0));
73
- }
74
- };
75
- }
76
9
  var DEFAULT_LOCK_STALE_MS = 15 * 60 * 1e3;
77
10
  function isProcessAlive(pid) {
78
11
  try {
@@ -84,7 +17,7 @@ function isProcessAlive(pid) {
84
17
  }
85
18
  function lockIsStale(file, staleMs) {
86
19
  try {
87
- const { pid, at } = JSON.parse(fs3.readFileSync(file, "utf8"));
20
+ const { pid, at } = JSON.parse(fs2.readFileSync(file, "utf8"));
88
21
  if (typeof at === "number" && Date.now() - at > staleMs) return true;
89
22
  if (typeof pid === "number" && !isProcessAlive(pid)) return true;
90
23
  return false;
@@ -95,10 +28,10 @@ function lockIsStale(file, staleMs) {
95
28
  function acquireLock(file, staleMs = DEFAULT_LOCK_STALE_MS) {
96
29
  const write = () => {
97
30
  try {
98
- fs3.mkdirSync(path3.dirname(file), { recursive: true });
99
- const fd = fs3.openSync(file, "wx");
100
- fs3.writeFileSync(fd, JSON.stringify({ pid: process.pid, at: Date.now() }));
101
- fs3.closeSync(fd);
31
+ fs2.mkdirSync(path2.dirname(file), { recursive: true });
32
+ const fd = fs2.openSync(file, "wx");
33
+ fs2.writeFileSync(fd, JSON.stringify({ pid: process.pid, at: Date.now() }));
34
+ fs2.closeSync(fd);
102
35
  return true;
103
36
  } catch {
104
37
  return false;
@@ -107,7 +40,7 @@ function acquireLock(file, staleMs = DEFAULT_LOCK_STALE_MS) {
107
40
  if (write()) return true;
108
41
  if (lockIsStale(file, staleMs)) {
109
42
  try {
110
- fs3.rmSync(file, { force: true });
43
+ fs2.rmSync(file, { force: true });
111
44
  } catch {
112
45
  }
113
46
  return write();
@@ -116,7 +49,7 @@ function acquireLock(file, staleMs = DEFAULT_LOCK_STALE_MS) {
116
49
  }
117
50
  function releaseLock(file) {
118
51
  try {
119
- fs3.rmSync(file, { force: true });
52
+ fs2.rmSync(file, { force: true });
120
53
  } catch {
121
54
  }
122
55
  }
@@ -126,14 +59,14 @@ function resolveEmbedModel(model) {
126
59
  return model ?? "bge-small-en-v1.5";
127
60
  }
128
61
  function modelCacheDir() {
129
- const base = process.env.XDG_CACHE_HOME || path3.join(os.homedir(), ".cache");
130
- return path3.join(base, "vibgrate", "models");
62
+ const base = process.env.XDG_CACHE_HOME || path2.join(os.homedir(), ".cache");
63
+ return path2.join(base, "vibgrate", "models");
131
64
  }
132
65
  function modelReadyMarker(modelId) {
133
- return path3.join(modelCacheDir(), `.ready-${safe(modelId)}`);
66
+ return path2.join(modelCacheDir(), `.ready-${safe(modelId)}`);
134
67
  }
135
68
  function isModelReady(modelId = resolveEmbedModel()) {
136
- return fs3.existsSync(modelReadyMarker(modelId));
69
+ return fs2.existsSync(modelReadyMarker(modelId));
137
70
  }
138
71
  function unavailableMessage(reason) {
139
72
  switch (reason) {
@@ -150,13 +83,13 @@ function unavailableMessage(reason) {
150
83
  }
151
84
  function modelCacheInfo(modelId = resolveEmbedModel()) {
152
85
  const dir = modelCacheDir();
153
- return { dir, present: isModelReady(modelId) || fs3.existsSync(dir), bytes: dirSize(dir) };
86
+ return { dir, present: isModelReady(modelId) || fs2.existsSync(dir), bytes: dirSize(dir) };
154
87
  }
155
88
  function clearModelCache() {
156
89
  const dir = modelCacheDir();
157
90
  const bytes = dirSize(dir);
158
91
  try {
159
- fs3.rmSync(dir, { recursive: true, force: true });
92
+ fs2.rmSync(dir, { recursive: true, force: true });
160
93
  } catch {
161
94
  }
162
95
  return bytes;
@@ -165,16 +98,16 @@ function dirSize(dir) {
165
98
  let total = 0;
166
99
  let entries;
167
100
  try {
168
- entries = fs3.readdirSync(dir, { withFileTypes: true });
101
+ entries = fs2.readdirSync(dir, { withFileTypes: true });
169
102
  } catch {
170
103
  return 0;
171
104
  }
172
105
  for (const e of entries) {
173
- const p = path3.join(dir, e.name);
106
+ const p = path2.join(dir, e.name);
174
107
  if (e.isDirectory()) total += dirSize(p);
175
108
  else {
176
109
  try {
177
- total += fs3.statSync(p).size;
110
+ total += fs2.statSync(p).size;
178
111
  } catch {
179
112
  }
180
113
  }
@@ -186,7 +119,7 @@ function isPermissionError(e) {
186
119
  return code === "EACCES" || code === "EPERM" || code === "EROFS";
187
120
  }
188
121
  function embeddingsCached(root, modelId) {
189
- return fs3.existsSync(path3.join(cacheDir(root), `embeddings-${safe(modelId)}.json`));
122
+ return fs2.existsSync(path2.join(cacheDir(root), `embeddings-${safe(modelId)}.json`));
190
123
  }
191
124
  async function loadEmbedder(options = {}) {
192
125
  if (options.local) return null;
@@ -200,7 +133,7 @@ async function loadEmbedder(options = {}) {
200
133
  if (!mod?.FlagEmbedding) return fail("not-installed");
201
134
  const cache = modelCacheDir();
202
135
  try {
203
- fs3.mkdirSync(cache, { recursive: true });
136
+ fs2.mkdirSync(cache, { recursive: true });
204
137
  } catch (e) {
205
138
  return fail(isPermissionError(e) ? "no-permission" : "init-failed");
206
139
  }
@@ -215,7 +148,7 @@ async function loadEmbedder(options = {}) {
215
148
  "embedding model init timed out"
216
149
  );
217
150
  try {
218
- fs3.writeFileSync(modelReadyMarker(modelId), (/* @__PURE__ */ new Date(0)).toISOString());
151
+ fs2.writeFileSync(modelReadyMarker(modelId), (/* @__PURE__ */ new Date(0)).toISOString());
219
152
  } catch {
220
153
  }
221
154
  return {
@@ -240,7 +173,7 @@ async function importEmbedBackend() {
240
173
  const hostDir = process.env.VIBGRATE_EMBEDDER_PATH;
241
174
  if (hostDir) {
242
175
  try {
243
- const req = createRequire(path3.join(hostDir, "package.json"));
176
+ const req = createRequire(path2.join(hostDir, "package.json"));
244
177
  const mod = await import(pathToFileURL(req.resolve("fastembed")).href);
245
178
  const resolved = mod?.FlagEmbedding ? mod : mod?.default;
246
179
  if (resolved?.FlagEmbedding) return resolved;
@@ -308,6 +241,31 @@ function pathContext(file) {
308
241
  return [...dirs.slice(-2), stem].filter(Boolean).join(" ");
309
242
  }
310
243
  function nodeEmbedText(node, areaLabel) {
244
+ if (node.kind === "document") {
245
+ const category = (node.signature ?? "document").replace(/^document:/, "");
246
+ const categoryHints = {
247
+ manifest: "package dependencies scripts install dependencies versions",
248
+ docker: "dockerfile container image build runtime",
249
+ compose: "docker-compose services containers networking volumes",
250
+ ci: "continuous integration github actions workflow pipeline test build deploy",
251
+ "build-config": "typescript tsconfig bundler vite webpack eslint prettier test",
252
+ "api-contract": "openapi swagger graphql protobuf api schema endpoints",
253
+ "task-runner": "makefile justfile tasks build test run commands",
254
+ workspace: "monorepo workspace packages pnpm turbo nx",
255
+ infra: "deploy infrastructure kubernetes kubernetes terraform helm kubernetes",
256
+ "env-example": "environment variables configuration secrets template",
257
+ markdown: "documentation readme guide"
258
+ };
259
+ const hint = categoryHints[category] ?? category;
260
+ return [
261
+ node.qualifiedName,
262
+ "document",
263
+ category,
264
+ hint,
265
+ pathContext(node.file),
266
+ (node.doc ?? "").slice(0, 5e3)
267
+ ].filter(Boolean).join("\n");
268
+ }
311
269
  return [node.qualifiedName, node.kind, node.signature ?? "", node.doc ?? "", pathContext(node.file), areaLabel ?? ""].filter(Boolean).join(" ");
312
270
  }
313
271
  function cosine(a, b) {
@@ -326,7 +284,7 @@ function cosine(a, b) {
326
284
  var EMBED_CHUNK = 256;
327
285
  var CACHE_WRITE_INTERVAL_MS = 1500;
328
286
  function vectorCachePath(root, modelId) {
329
- return path3.join(cacheDir(root), `embeddings-${safe(modelId)}.json`);
287
+ return path2.join(cacheDir(root), `embeddings-${safe(modelId)}.json`);
330
288
  }
331
289
  function countPending(graph, root, modelId) {
332
290
  const entries = readCacheEntries(vectorCachePath(root, modelId), modelId);
@@ -341,9 +299,9 @@ function countPending(graph, root, modelId) {
341
299
  return pending;
342
300
  }
343
301
  function readCacheEntries(file, modelId) {
344
- if (!fs3.existsSync(file)) return {};
302
+ if (!fs2.existsSync(file)) return {};
345
303
  try {
346
- const loaded = JSON.parse(fs3.readFileSync(file, "utf8"));
304
+ const loaded = JSON.parse(fs2.readFileSync(file, "utf8"));
347
305
  if (loaded.model === modelId && loaded.entries) return loaded.entries;
348
306
  } catch {
349
307
  }
@@ -352,9 +310,9 @@ function readCacheEntries(file, modelId) {
352
310
  async function getNodeEmbeddings(graph, embedder, root, onProgress) {
353
311
  const file = vectorCachePath(root, embedder.id);
354
312
  let cache = { model: embedder.id, entries: {} };
355
- if (fs3.existsSync(file)) {
313
+ if (fs2.existsSync(file)) {
356
314
  try {
357
- const loaded = JSON.parse(fs3.readFileSync(file, "utf8"));
315
+ const loaded = JSON.parse(fs2.readFileSync(file, "utf8"));
358
316
  if (loaded.model === embedder.id && loaded.entries) cache = loaded;
359
317
  } catch {
360
318
  }
@@ -372,10 +330,10 @@ async function getNodeEmbeddings(graph, embedder, root, onProgress) {
372
330
  }
373
331
  const persist = () => {
374
332
  try {
375
- fs3.mkdirSync(cacheDir(root), { recursive: true });
333
+ fs2.mkdirSync(cacheDir(root), { recursive: true });
376
334
  const tmp = `${file}.tmp.${process.pid}`;
377
- fs3.writeFileSync(tmp, JSON.stringify(cache));
378
- fs3.renameSync(tmp, file);
335
+ fs2.writeFileSync(tmp, JSON.stringify(cache));
336
+ fs2.renameSync(tmp, file);
379
337
  } catch {
380
338
  }
381
339
  };
@@ -756,217 +714,7 @@ function impactOf(graph, rootId, opts = {}) {
756
714
  function round2(x) {
757
715
  return Math.round(x * 1e6) / 1e6;
758
716
  }
759
- var LEDGER = "savings.jsonl";
760
- var PER_FILE_TOKENS = 400;
761
- var SAVINGS_TOOLS = /* @__PURE__ */ new Set(["query_graph", "get_node", "search_symbols"]);
762
- var CLI_TOOL_ALIASES = {
763
- ask: "query_graph",
764
- show: "get_node",
765
- impact: "impact_of",
766
- path: "find_path",
767
- hubs: "list_hubs",
768
- areas: "list_areas",
769
- tree: "tree"
770
- };
771
- function sanitizeClient(name) {
772
- if (typeof name !== "string") return "unknown";
773
- const cleaned = name.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
774
- return cleaned || "unknown";
775
- }
776
- function sanitizeModelId(name) {
777
- if (typeof name !== "string") return void 0;
778
- const cleaned = name.trim().toLowerCase().replace(/[^a-z0-9._:/-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
779
- return cleaned || void 0;
780
- }
781
- function recordCliCall(root, entry, now) {
782
- recordSaving(
783
- root,
784
- {
785
- tool: entry.tool,
786
- source: "cli",
787
- client: sanitizeClient(entry.client),
788
- provider: entry.provider ? sanitizeClient(entry.provider) : void 0,
789
- model: sanitizeModelId(entry.model),
790
- outcome: entry.outcome,
791
- vgTokens: entry.vgTokens ?? 0,
792
- baselineTokens: (entry.baselineFiles ?? 0) * PER_FILE_TOKENS
793
- },
794
- now
795
- );
796
- }
797
- function savingsLedgerPath(root) {
798
- return path3.join(cacheDir(root), LEDGER);
799
- }
800
- function ledgerPath(root) {
801
- return savingsLedgerPath(root);
802
- }
803
- function savingsRecorded(root) {
804
- return fs3.existsSync(ledgerPath(root));
805
- }
806
- function clearSavings(root) {
807
- const file = ledgerPath(root);
808
- const existed = fs3.existsSync(file);
809
- fs3.rmSync(file, { force: true });
810
- fs3.rmSync(path3.join(cacheDir(root), "stats-share.json"), { force: true });
811
- return existed;
812
- }
813
- function recordSaving(root, entry, now) {
814
- try {
815
- fs3.mkdirSync(cacheDir(root), { recursive: true });
816
- const line = JSON.stringify({ ts: now, ...entry });
817
- fs3.appendFileSync(ledgerPath(root), line + "\n");
818
- } catch {
819
- }
820
- }
821
- var DEFAULT_RATE_PER_M = 3;
822
- var DEFAULT_RATE_LABEL = "input @ $3/1M";
823
- function readSavings(root, days, now, ratePerM = DEFAULT_RATE_PER_M) {
824
- const file = ledgerPath(root);
825
- const cutoff = now - days * 24 * 60 * 60 * 1e3;
826
- let queries = 0;
827
- let vgTokens = 0;
828
- let baselineTokens = 0;
829
- if (fs3.existsSync(file)) {
830
- for (const line of fs3.readFileSync(file, "utf8").split("\n")) {
831
- if (!line.trim()) continue;
832
- try {
833
- const e = JSON.parse(line);
834
- if (e.ts < cutoff) continue;
835
- if (!SAVINGS_TOOLS.has(e.tool)) continue;
836
- queries++;
837
- vgTokens += e.vgTokens;
838
- baselineTokens += e.baselineTokens;
839
- } catch {
840
- }
841
- }
842
- }
843
- const estCostVg = vgTokens / 1e6 * ratePerM;
844
- const estCostBaseline = baselineTokens / 1e6 * ratePerM;
845
- return {
846
- enabled: savingsRecorded(root),
847
- days,
848
- queries,
849
- vgTokens,
850
- baselineTokens,
851
- ratio: vgTokens > 0 ? Math.round(baselineTokens / vgTokens * 100) / 100 : 0,
852
- estCostVg: round22(estCostVg),
853
- estCostBaseline: round22(estCostBaseline),
854
- saved: round22(estCostBaseline - estCostVg),
855
- rateLabel: DEFAULT_RATE_LABEL
856
- };
857
- }
858
- function round22(x) {
859
- return Math.round(x * 100) / 100;
860
- }
861
- function readModelSavings(root, days, now, ratePerM = DEFAULT_RATE_PER_M) {
862
- const file = ledgerPath(root);
863
- const cutoff = now - days * 24 * 60 * 60 * 1e3;
864
- const byModel = /* @__PURE__ */ new Map();
865
- if (fs3.existsSync(file)) {
866
- for (const line of fs3.readFileSync(file, "utf8").split("\n")) {
867
- if (!line.trim()) continue;
868
- try {
869
- const e = JSON.parse(line);
870
- if (e.ts < cutoff || !e.model || !SAVINGS_TOOLS.has(e.tool)) continue;
871
- const provider = e.provider ?? "unknown";
872
- const key = `${provider}/${e.model}`;
873
- const row = byModel.get(key) ?? { provider, model: e.model, queries: 0, vg: 0, base: 0 };
874
- row.queries++;
875
- row.vg += e.vgTokens;
876
- row.base += e.baselineTokens;
877
- byModel.set(key, row);
878
- } catch {
879
- }
880
- }
881
- }
882
- return [...byModel.entries()].map(([key, r]) => ({
883
- key,
884
- provider: r.provider,
885
- model: r.model,
886
- queries: r.queries,
887
- vgTokens: r.vg,
888
- baselineTokens: r.base,
889
- saved: round22((r.base - r.vg) / 1e6 * ratePerM)
890
- })).sort((a, b) => b.saved - a.saved || a.key.localeCompare(b.key));
891
- }
892
- function toDimensionStats(byKey) {
893
- return [...byKey.entries()].map(([key, r]) => {
894
- const calls = r.complete + r.partial + r.miss;
895
- return {
896
- key,
897
- calls,
898
- complete: r.complete,
899
- partial: r.partial,
900
- miss: r.miss,
901
- successPct: calls ? Math.round((r.complete + r.partial) / calls * 100) : 0
902
- };
903
- }).sort((a, b) => b.calls - a.calls || a.key.localeCompare(b.key));
904
- }
905
- function readUsage(root, days, now) {
906
- const file = ledgerPath(root);
907
- const cutoff = now - days * 24 * 60 * 60 * 1e3;
908
- const byTool = /* @__PURE__ */ new Map();
909
- const bySource = /* @__PURE__ */ new Map();
910
- const byClient = /* @__PURE__ */ new Map();
911
- const msByTool = /* @__PURE__ */ new Map();
912
- const bump = (m, key, outcome) => {
913
- const row = m.get(key) ?? { complete: 0, partial: 0, miss: 0 };
914
- row[outcome]++;
915
- m.set(key, row);
916
- };
917
- if (fs3.existsSync(file)) {
918
- for (const line of fs3.readFileSync(file, "utf8").split("\n")) {
919
- if (!line.trim()) continue;
920
- try {
921
- const e = JSON.parse(line);
922
- if (e.ts < cutoff) continue;
923
- const outcome = e.outcome ?? "complete";
924
- bump(byTool, e.tool, outcome);
925
- bump(bySource, e.source ?? "mcp", outcome);
926
- bump(byClient, e.client ?? "unknown", outcome);
927
- if (typeof e.ms === "number" && e.ms >= 0) {
928
- const timing = msByTool.get(e.tool) ?? { sum: 0, n: 0 };
929
- timing.sum += e.ms;
930
- timing.n++;
931
- msByTool.set(e.tool, timing);
932
- }
933
- } catch {
934
- }
935
- }
936
- }
937
- const commands = toDimensionStats(byTool).map((d) => {
938
- const timing = msByTool.get(d.key);
939
- return {
940
- tool: d.key,
941
- calls: d.calls,
942
- complete: d.complete,
943
- partial: d.partial,
944
- miss: d.miss,
945
- successPct: d.successPct,
946
- avgMs: timing && timing.n > 0 ? Math.round(timing.sum / timing.n) : null
947
- };
948
- });
949
- const totals = commands.reduce(
950
- (t, c) => ({
951
- calls: t.calls + c.calls,
952
- complete: t.complete + c.complete,
953
- partial: t.partial + c.partial,
954
- miss: t.miss + c.miss
955
- }),
956
- { calls: 0, complete: 0, partial: 0, miss: 0 }
957
- );
958
- const avgSuccessPct = commands.length ? Math.round(commands.reduce((s, c) => s + c.successPct, 0) / commands.length) : 0;
959
- return {
960
- enabled: savingsRecorded(root),
961
- days,
962
- commands,
963
- sources: toDimensionStats(bySource),
964
- clients: toDimensionStats(byClient),
965
- totals,
966
- avgSuccessPct
967
- };
968
- }
969
717
 
970
- export { CLI_TOOL_ALIASES, GraphIndex, PER_FILE_TOKENS, SAVINGS_TOOLS, acquireLock, cacheDir, clearModelCache, clearSavings, cosine, countPending, embeddingsCached, getNodeEmbeddings, identifierParts, impactOf, indexFor, isModelReady, loadCache, loadEmbedder, modelCacheInfo, nodeEmbedText, parseGraph, queryGraph, queryGraphSemantic, readModelSavings, readSavings, readUsage, recordCliCall, recordSaving, releaseLock, resolveEmbedModel, sanitizeClient, savingsLedgerPath, savingsRecorded, serializeGraph, stableStringify, unavailableMessage, withTimeout };
971
- //# sourceMappingURL=chunk-WNIIKCNF.js.map
972
- //# sourceMappingURL=chunk-WNIIKCNF.js.map
718
+ export { GraphIndex, acquireLock, clearModelCache, cosine, countPending, embeddingsCached, getNodeEmbeddings, identifierParts, impactOf, indexFor, isModelReady, loadEmbedder, modelCacheInfo, nodeEmbedText, queryGraph, queryGraphSemantic, releaseLock, resolveEmbedModel, unavailableMessage, withTimeout };
719
+ //# sourceMappingURL=chunk-6ABXHZRN.js.map
720
+ //# sourceMappingURL=chunk-6ABXHZRN.js.map