weavatrix 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +92 -17
  2. package/package.json +1 -1
  3. package/skill/SKILL.md +62 -4
  4. package/src/analysis/dead-check.js +87 -6
  5. package/src/analysis/dep-check-ecosystems.js +157 -0
  6. package/src/analysis/dep-check.js +97 -133
  7. package/src/analysis/dep-rules.js +91 -12
  8. package/src/analysis/duplicates.compute.js +12 -18
  9. package/src/analysis/endpoints-rust.js +124 -0
  10. package/src/analysis/endpoints.js +56 -6
  11. package/src/analysis/graph-analysis.aggregate.js +34 -25
  12. package/src/analysis/graph-analysis.edges.js +21 -0
  13. package/src/analysis/graph-analysis.js +1 -1
  14. package/src/analysis/graph-analysis.summaries.js +4 -1
  15. package/src/analysis/internal-audit.collect.js +162 -25
  16. package/src/analysis/internal-audit.reach.js +52 -11
  17. package/src/analysis/internal-audit.run.js +71 -18
  18. package/src/graph/builder/lang-java.js +177 -14
  19. package/src/graph/builder/lang-js.js +66 -23
  20. package/src/graph/builder/lang-rust.js +129 -6
  21. package/src/graph/community.js +17 -0
  22. package/src/graph/internal-builder.build.js +79 -17
  23. package/src/graph/internal-builder.java.js +33 -0
  24. package/src/graph/internal-builder.langs.js +43 -2
  25. package/src/graph/internal-builder.resolvers.js +197 -21
  26. package/src/graph/relations.js +4 -0
  27. package/src/mcp/catalog.mjs +4 -4
  28. package/src/mcp/graph-context.mjs +22 -94
  29. package/src/mcp/graph-diff.mjs +163 -0
  30. package/src/mcp/sync-payload.mjs +36 -6
  31. package/src/mcp/tools-actions.mjs +22 -7
  32. package/src/mcp/tools-graph-hubs.mjs +58 -0
  33. package/src/mcp/tools-graph.mjs +13 -22
  34. package/src/mcp/tools-health.mjs +54 -18
  35. package/src/mcp/tools-impact.mjs +61 -45
  36. package/src/mcp-server.mjs +3 -0
  37. package/src/security/advisory-store.js +51 -7
@@ -10,6 +10,7 @@
10
10
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
11
11
  import { join, dirname } from "node:path";
12
12
  import { homedir } from "node:os";
13
+ import { createHash } from "node:crypto";
13
14
  import { uniqueBy } from "../util.js";
14
15
 
15
16
  export const DEFAULT_STORE = join(homedir(), ".weavatrix", "advisories.json");
@@ -22,6 +23,13 @@ const keyOf = (ecosystem, name) => `${ecosystem}|${ecosystem === "PyPI" ? String
22
23
 
23
24
  const uniquePackages = (pkgs) => uniqueBy(pkgs, (p) => `${p.ecosystem}|${p.name}|${p.version}`);
24
25
 
26
+ export function advisoryQueryFingerprint(installed = []) {
27
+ const rows = uniquePackages(installed.filter((p) => p?.ecosystem && p?.name && p?.version && OSV_SUPPORTED_ECOSYSTEMS.has(p.ecosystem)))
28
+ .map((p) => `${p.ecosystem}|${p.name}|${p.version}`)
29
+ .sort();
30
+ return createHash("sha256").update(rows.join("\n"), "utf8").digest("hex");
31
+ }
32
+
25
33
  async function fetchJson(fetcher, url, options, timeoutMs) {
26
34
  const timeout = Math.max(50, Number(timeoutMs) || DEFAULT_FETCH_TIMEOUT_MS);
27
35
  const ctrl = typeof AbortController === "function" ? new AbortController() : null;
@@ -119,6 +127,7 @@ export async function refreshAdvisories({ installed = [], storePath = DEFAULT_ST
119
127
  const store = loadStore(storePath);
120
128
  const idsByPkg = new Map(); // pkgIndex -> [vuln ids]
121
129
  const errors = [];
130
+ let queriedOk = 0;
122
131
 
123
132
  for (let i = 0; i < pkgs.length; i += batchSize) {
124
133
  const batch = pkgs.slice(i, i + batchSize);
@@ -128,7 +137,22 @@ export async function refreshAdvisories({ installed = [], storePath = DEFAULT_ST
128
137
  headers: { "Content-Type": "application/json" },
129
138
  body: JSON.stringify({ queries: batch.map((p) => ({ package: { ecosystem: p.ecosystem, name: p.name }, version: p.version })) }),
130
139
  }, timeoutMs);
131
- (json.results || []).forEach((r, j) => { if (r && Array.isArray(r.vulns) && r.vulns.length) idsByPkg.set(i + j, r.vulns.map((v) => v.id)); });
140
+ if (!Array.isArray(json?.results) || json.results.length !== batch.length) {
141
+ throw new Error(`OSV querybatch returned ${Array.isArray(json?.results) ? json.results.length : "no"} result(s) for ${batch.length} query item(s)`);
142
+ }
143
+ for (const [resultIndex, result] of json.results.entries()) {
144
+ if (!result || typeof result !== "object" || Array.isArray(result)) {
145
+ throw new Error(`OSV querybatch result ${resultIndex + 1} is not an object`);
146
+ }
147
+ if (result.vulns !== undefined && !Array.isArray(result.vulns)) {
148
+ throw new Error(`OSV querybatch result ${resultIndex + 1} has a non-array vulns field`);
149
+ }
150
+ if (Array.isArray(result.vulns) && result.vulns.some((v) => !v || typeof v.id !== "string" || !v.id.trim())) {
151
+ throw new Error(`OSV querybatch result ${resultIndex + 1} contains an advisory without a valid id`);
152
+ }
153
+ }
154
+ queriedOk += batch.length;
155
+ json.results.forEach((r, j) => { if (r && Array.isArray(r.vulns) && r.vulns.length) idsByPkg.set(i + j, r.vulns.map((v) => v.id)); });
132
156
  } catch (error) {
133
157
  errors.push(`querybatch ${Math.floor(i / batchSize) + 1}/${Math.ceil(pkgs.length / batchSize)}: ${error.message}`);
134
158
  }
@@ -141,16 +165,24 @@ export async function refreshAdvisories({ installed = [], storePath = DEFAULT_ST
141
165
  for (const [id, pkgList] of wanted) {
142
166
  try {
143
167
  const rec = await fetchJson(fetcher, OSV_VULN_URL + encodeURIComponent(id), {}, timeoutMs);
144
- if (!rec || !rec.id) continue;
145
- fetched++;
168
+ if (!rec || typeof rec.id !== "string" || !rec.id) throw new Error("OSV detail response is missing its advisory id");
169
+ if (rec.id !== id) throw new Error(`OSV detail id mismatch (expected ${id}, received ${rec.id})`);
170
+ let normalized = 0;
146
171
  for (const p of pkgList) {
147
172
  const row = normalizeRecord(rec, p.ecosystem, p.name);
148
- if (!row) continue;
173
+ if (!row) {
174
+ errors.push(`${id}: OSV detail does not describe ${p.ecosystem}:${p.name} reported by querybatch`);
175
+ continue;
176
+ }
177
+ normalized++;
149
178
  const key = keyOf(p.ecosystem, p.name);
150
179
  const list = store.records[key] || (store.records[key] = []);
151
180
  const at = list.findIndex((x) => x.id === row.id);
152
181
  if (at >= 0) list[at] = row; else list.push(row);
153
182
  }
183
+ // Count a detail response as fetched only after at least one package-specific row was
184
+ // validated. A malformed or unrelated response must never make coverage look complete.
185
+ if (normalized > 0) fetched++;
154
186
  } catch (error) {
155
187
  errors.push(`${id}: ${error.message}`);
156
188
  }
@@ -158,20 +190,32 @@ export async function refreshAdvisories({ installed = [], storePath = DEFAULT_ST
158
190
 
159
191
  // A refresh where NOTHING was fetched but errors occurred (offline, OSV blocked) must NOT stamp
160
192
  // fetched_at — that would turn an empty cache into "No known vulnerabilities as of <today>".
161
- if (errors.length && fetched === 0 && (idsByPkg.size === 0 || wanted.size > 0)) {
193
+ if (errors.length && queriedOk === 0) {
162
194
  return { ok: false, queried: pkgs.length, unsupported, error: `advisory refresh failed: ${errors[0]}${errors.length > 1 ? ` (+${errors.length - 1} more)` : ""}`, errors };
163
195
  }
164
196
  store.meta.fetched_at = new Date().toISOString();
197
+ const status = errors.length ? "PARTIAL" : "OK";
165
198
  // per-repo stamp: the cache only covers packages that were QUERIED — a repo that never refreshed must
166
199
  // show "fetch advisories", not "0 vulnerabilities as of <someone else's date>" (false assurance).
167
200
  // repoKeys[] lets one online pass (a "refresh all repos") stamp every repo whose packages it covered.
168
201
  const stampRepos = [...new Set([repoKey, ...repoKeys].filter(Boolean))];
169
- if (stampRepos.length) { store.meta.repos = store.meta.repos || {}; for (const k of stampRepos) store.meta.repos[k] = store.meta.fetched_at; }
202
+ if (stampRepos.length) {
203
+ store.meta.repos = store.meta.repos || {};
204
+ for (const k of stampRepos) store.meta.repos[k] = {
205
+ fetched_at: store.meta.fetched_at,
206
+ status,
207
+ queried: pkgs.length,
208
+ queried_ok: queriedOk,
209
+ unsupported,
210
+ error_count: errors.length,
211
+ query_fingerprint: advisoryQueryFingerprint(pkgs),
212
+ };
213
+ }
170
214
  try {
171
215
  mkdirSync(dirname(storePath), { recursive: true });
172
216
  writeFileSync(storePath, JSON.stringify(store), "utf8");
173
217
  } catch (error) {
174
218
  return { ok: false, error: `store write failed: ${error.message}`, errors };
175
219
  }
176
- return { ok: true, queried: pkgs.length, unsupported, vulnerable: wanted.size, fetched, saved: existsSync(storePath), errors };
220
+ return { ok: true, status, queried: pkgs.length, queriedOk, unsupported, vulnerable: wanted.size, fetched, saved: existsSync(storePath), errors };
177
221
  }