weavatrix 0.3.14 → 1.0.0

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 (305) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +231 -199
  3. package/bin/native/darwin-arm64/weavatrix +0 -0
  4. package/bin/native/darwin-x64/weavatrix +0 -0
  5. package/bin/native/linux-arm64/weavatrix +0 -0
  6. package/bin/native/linux-x64/weavatrix +0 -0
  7. package/bin/native/win32-arm64/weavatrix.exe +0 -0
  8. package/bin/native/win32-x64/weavatrix.exe +0 -0
  9. package/bin/resolve-binary.mjs +73 -0
  10. package/bin/run-native.mjs +26 -0
  11. package/bin/weavatrix-mcp.mjs +7 -6
  12. package/bin/weavatrix.mjs +5 -0
  13. package/package.json +8 -66
  14. package/skill/SKILL.md +62 -374
  15. package/skill/agents/openai.yaml +4 -0
  16. package/skill/references/tool-routing.md +45 -0
  17. package/SECURITY.md +0 -101
  18. package/docs/adr/0001-v0.3-offline-online-split.md +0 -60
  19. package/docs/agent-task-benchmark.md +0 -58
  20. package/docs/releases/v0.2.19.md +0 -33
  21. package/docs/releases/v0.3.0.md +0 -43
  22. package/docs/releases/v0.3.1.md +0 -30
  23. package/docs/releases/v0.3.10.md +0 -76
  24. package/docs/releases/v0.3.11.md +0 -55
  25. package/docs/releases/v0.3.12.md +0 -44
  26. package/docs/releases/v0.3.13.md +0 -34
  27. package/docs/releases/v0.3.14.md +0 -37
  28. package/docs/releases/v0.3.2.md +0 -15
  29. package/docs/releases/v0.3.3.md +0 -25
  30. package/docs/releases/v0.3.4.md +0 -40
  31. package/docs/releases/v0.3.5.md +0 -50
  32. package/docs/releases/v0.3.6.md +0 -44
  33. package/docs/releases/v0.3.7.md +0 -37
  34. package/docs/releases/v0.3.8.md +0 -21
  35. package/docs/releases/v0.3.9.md +0 -36
  36. package/scripts/run-agent-task-benchmark.mjs +0 -118
  37. package/src/analysis/allowed-test-runner.js +0 -70
  38. package/src/analysis/architecture/contract-graph.js +0 -119
  39. package/src/analysis/architecture/contract-schema.js +0 -110
  40. package/src/analysis/architecture/contract-storage.js +0 -35
  41. package/src/analysis/architecture/contract-verification.js +0 -168
  42. package/src/analysis/architecture-contract.js +0 -16
  43. package/src/analysis/audit-debt.js +0 -94
  44. package/src/analysis/audit-extensions.js +0 -60
  45. package/src/analysis/cargo-dependency-evidence.js +0 -108
  46. package/src/analysis/cargo-manifests.js +0 -81
  47. package/src/analysis/change-classification/diff-parser.js +0 -103
  48. package/src/analysis/change-classification/options.js +0 -40
  49. package/src/analysis/change-classification/symbol-classifier.js +0 -177
  50. package/src/analysis/change-classification.js +0 -188
  51. package/src/analysis/coverage-reports-tarpaulin.js +0 -112
  52. package/src/analysis/coverage-reports.js +0 -246
  53. package/src/analysis/cycle-route.js +0 -14
  54. package/src/analysis/data-flow-evidence.js +0 -114
  55. package/src/analysis/dead-check.js +0 -300
  56. package/src/analysis/dead-code-review/candidates.js +0 -194
  57. package/src/analysis/dead-code-review/policy.js +0 -23
  58. package/src/analysis/dead-code-review.js +0 -119
  59. package/src/analysis/dep-check-ecosystems.js +0 -205
  60. package/src/analysis/dep-check.js +0 -290
  61. package/src/analysis/dep-rules.js +0 -10
  62. package/src/analysis/dependency/conventions.js +0 -16
  63. package/src/analysis/dependency/scoped-dependencies.js +0 -51
  64. package/src/analysis/dependency/source-references.js +0 -21
  65. package/src/analysis/duplicate-groups.js +0 -104
  66. package/src/analysis/duplicates-worker.js +0 -11
  67. package/src/analysis/duplicates.compute.js +0 -269
  68. package/src/analysis/duplicates.js +0 -15
  69. package/src/analysis/duplicates.run.js +0 -52
  70. package/src/analysis/duplicates.tokenize.js +0 -199
  71. package/src/analysis/endpoints/common.js +0 -79
  72. package/src/analysis/endpoints/extract.js +0 -120
  73. package/src/analysis/endpoints/inventory.js +0 -84
  74. package/src/analysis/endpoints/mounts.js +0 -129
  75. package/src/analysis/endpoints-java.js +0 -260
  76. package/src/analysis/endpoints-rust.js +0 -124
  77. package/src/analysis/endpoints.js +0 -3
  78. package/src/analysis/findings.js +0 -70
  79. package/src/analysis/git-history/analytics.js +0 -177
  80. package/src/analysis/git-history/collector.js +0 -67
  81. package/src/analysis/git-history/options.js +0 -66
  82. package/src/analysis/git-history.js +0 -143
  83. package/src/analysis/git-ref-graph.js +0 -76
  84. package/src/analysis/go-dependency-evidence.js +0 -62
  85. package/src/analysis/graph-analysis.aggregate.js +0 -296
  86. package/src/analysis/graph-analysis.edges.js +0 -24
  87. package/src/analysis/graph-analysis.js +0 -7
  88. package/src/analysis/graph-analysis.refs.js +0 -202
  89. package/src/analysis/graph-analysis.summaries.js +0 -65
  90. package/src/analysis/health-capabilities.js +0 -83
  91. package/src/analysis/hot-path-review.js +0 -266
  92. package/src/analysis/http-contract-wrappers.js +0 -241
  93. package/src/analysis/http-contracts/analysis.js +0 -179
  94. package/src/analysis/http-contracts/client-call-detection.js +0 -82
  95. package/src/analysis/http-contracts/client-call-parser.js +0 -273
  96. package/src/analysis/http-contracts/graph-context.js +0 -143
  97. package/src/analysis/http-contracts/matching.js +0 -61
  98. package/src/analysis/http-contracts/shared.js +0 -85
  99. package/src/analysis/http-contracts.js +0 -6
  100. package/src/analysis/internal-audit/dependency-health.js +0 -113
  101. package/src/analysis/internal-audit/python-manifests.js +0 -78
  102. package/src/analysis/internal-audit/repo-files.js +0 -50
  103. package/src/analysis/internal-audit/supply-chain.js +0 -149
  104. package/src/analysis/internal-audit.collect.js +0 -213
  105. package/src/analysis/internal-audit.js +0 -9
  106. package/src/analysis/internal-audit.reach.js +0 -201
  107. package/src/analysis/internal-audit.run.js +0 -256
  108. package/src/analysis/java-source.js +0 -36
  109. package/src/analysis/jvm-artifact-index.js +0 -87
  110. package/src/analysis/jvm-dependency-evidence.js +0 -138
  111. package/src/analysis/jvm-manifests.js +0 -114
  112. package/src/analysis/manifests.js +0 -123
  113. package/src/analysis/package-reachability.js +0 -39
  114. package/src/analysis/source-complexity.ast.js +0 -97
  115. package/src/analysis/source-complexity.constants.js +0 -55
  116. package/src/analysis/source-complexity.js +0 -14
  117. package/src/analysis/source-complexity.report.js +0 -81
  118. package/src/analysis/source-complexity.walk.js +0 -228
  119. package/src/analysis/source-correctness/retry-patterns.js +0 -93
  120. package/src/analysis/source-correctness.js +0 -222
  121. package/src/analysis/static-test-reachability.js +0 -150
  122. package/src/analysis/structure/dependency-graph.js +0 -151
  123. package/src/analysis/structure/findings.js +0 -162
  124. package/src/analysis/task-retrieval.js +0 -107
  125. package/src/analysis/transport-contracts.js +0 -224
  126. package/src/analysis/transport-runtime-evidence.js +0 -155
  127. package/src/analysis-kit.mjs +0 -17
  128. package/src/bounds.js +0 -4
  129. package/src/build-graph.js +0 -209
  130. package/src/child-env.js +0 -7
  131. package/src/config.js +0 -5
  132. package/src/extension/local-services.mjs +0 -75
  133. package/src/git-exec.js +0 -67
  134. package/src/graph/build-worker.js +0 -49
  135. package/src/graph/builder/go-receiver-resolution.js +0 -112
  136. package/src/graph/builder/js/dynamic-import.js +0 -26
  137. package/src/graph/builder/js/queries.js +0 -48
  138. package/src/graph/builder/lang-csharp.js +0 -40
  139. package/src/graph/builder/lang-css.js +0 -29
  140. package/src/graph/builder/lang-go.js +0 -140
  141. package/src/graph/builder/lang-html.js +0 -29
  142. package/src/graph/builder/lang-java-calls.js +0 -142
  143. package/src/graph/builder/lang-java.js +0 -215
  144. package/src/graph/builder/lang-js.js +0 -291
  145. package/src/graph/builder/lang-python.js +0 -235
  146. package/src/graph/builder/lang-rust-calls.js +0 -63
  147. package/src/graph/builder/lang-rust.js +0 -299
  148. package/src/graph/builder/lang-solidity.js +0 -126
  149. package/src/graph/builder/lang-sql.js +0 -263
  150. package/src/graph/builder/pass2-resolution.js +0 -81
  151. package/src/graph/builder/spec-pkg.js +0 -87
  152. package/src/graph/community.js +0 -27
  153. package/src/graph/edge-provenance.js +0 -31
  154. package/src/graph/file-lock.js +0 -69
  155. package/src/graph/freshness-probe.js +0 -142
  156. package/src/graph/graph-filter.js +0 -63
  157. package/src/graph/incremental-refresh.js +0 -235
  158. package/src/graph/internal-builder.barrels.js +0 -235
  159. package/src/graph/internal-builder.build.js +0 -300
  160. package/src/graph/internal-builder.java.js +0 -33
  161. package/src/graph/internal-builder.js +0 -12
  162. package/src/graph/internal-builder.langs.js +0 -157
  163. package/src/graph/internal-builder.pass2.js +0 -163
  164. package/src/graph/internal-builder.resolvers.js +0 -286
  165. package/src/graph/layout.js +0 -51
  166. package/src/graph/node-id.js +0 -7
  167. package/src/graph/parser-artifact-boundary.js +0 -55
  168. package/src/graph/relations.js +0 -4
  169. package/src/graph/repo-registry.js +0 -124
  170. package/src/graph/resolvers/rust.js +0 -117
  171. package/src/infra/infra-items.js +0 -255
  172. package/src/infra/infra-registry.js +0 -184
  173. package/src/infra/infra.detect.js +0 -119
  174. package/src/infra/infra.js +0 -38
  175. package/src/infra/infra.match.js +0 -102
  176. package/src/infra/infra.scan.js +0 -93
  177. package/src/mcp/actions/graph-lifecycle.mjs +0 -148
  178. package/src/mcp/architecture-bootstrap.mjs +0 -168
  179. package/src/mcp/architecture-starter.mjs +0 -234
  180. package/src/mcp/catalog.mjs +0 -233
  181. package/src/mcp/company-contract-page.mjs +0 -142
  182. package/src/mcp/company-contract-reconcile.mjs +0 -87
  183. package/src/mcp/company-contract-verdict.mjs +0 -42
  184. package/src/mcp/evidence/bun-lock-graph.mjs +0 -209
  185. package/src/mcp/evidence/duplicate-member-order.mjs +0 -8
  186. package/src/mcp/evidence/package-graph-common.mjs +0 -115
  187. package/src/mcp/evidence/package-lock-graph.mjs +0 -92
  188. package/src/mcp/evidence-snapshot.architecture.mjs +0 -80
  189. package/src/mcp/evidence-snapshot.common.mjs +0 -158
  190. package/src/mcp/evidence-snapshot.duplicates.mjs +0 -213
  191. package/src/mcp/evidence-snapshot.health.mjs +0 -102
  192. package/src/mcp/evidence-snapshot.inventory.mjs +0 -148
  193. package/src/mcp/evidence-snapshot.mjs +0 -50
  194. package/src/mcp/evidence-snapshot.package-graph.mjs +0 -34
  195. package/src/mcp/evidence-snapshot.structure.mjs +0 -84
  196. package/src/mcp/extension-api.mjs +0 -77
  197. package/src/mcp/git-output.mjs +0 -7
  198. package/src/mcp/graph/context-core.mjs +0 -111
  199. package/src/mcp/graph/context-seeds.mjs +0 -207
  200. package/src/mcp/graph/context-state.mjs +0 -85
  201. package/src/mcp/graph/reverse-reach.mjs +0 -42
  202. package/src/mcp/graph/tools-core.mjs +0 -143
  203. package/src/mcp/graph/tools-query.mjs +0 -276
  204. package/src/mcp/graph-context.mjs +0 -5
  205. package/src/mcp/graph-diff.mjs +0 -218
  206. package/src/mcp/health/audit-format.mjs +0 -199
  207. package/src/mcp/health/audit.mjs +0 -199
  208. package/src/mcp/health/dead-code.mjs +0 -110
  209. package/src/mcp/health/duplicates.mjs +0 -121
  210. package/src/mcp/health/endpoints.mjs +0 -71
  211. package/src/mcp/health/structure.mjs +0 -220
  212. package/src/mcp/runtime-version.mjs +0 -31
  213. package/src/mcp/server/auto-refresh.mjs +0 -66
  214. package/src/mcp/server/runtime-config.mjs +0 -43
  215. package/src/mcp/server/shutdown.mjs +0 -40
  216. package/src/mcp/staleness-notice.mjs +0 -20
  217. package/src/mcp/sync/evidence-architecture.mjs +0 -54
  218. package/src/mcp/sync/evidence-common.mjs +0 -88
  219. package/src/mcp/sync/evidence-duplicates.mjs +0 -97
  220. package/src/mcp/sync/evidence-health.mjs +0 -56
  221. package/src/mcp/sync/evidence-packages.mjs +0 -95
  222. package/src/mcp/sync/payload-common.mjs +0 -97
  223. package/src/mcp/sync/payload-v2.mjs +0 -54
  224. package/src/mcp/sync/payload-v3.mjs +0 -79
  225. package/src/mcp/sync-evidence.mjs +0 -23
  226. package/src/mcp/sync-payload.mjs +0 -70
  227. package/src/mcp/tool-result.mjs +0 -54
  228. package/src/mcp/tools-actions.mjs +0 -11
  229. package/src/mcp/tools-architecture.mjs +0 -177
  230. package/src/mcp/tools-company.mjs +0 -251
  231. package/src/mcp/tools-context.mjs +0 -222
  232. package/src/mcp/tools-endpoints.mjs +0 -207
  233. package/src/mcp/tools-graph-hubs.mjs +0 -78
  234. package/src/mcp/tools-graph.mjs +0 -17
  235. package/src/mcp/tools-health.mjs +0 -24
  236. package/src/mcp/tools-history.mjs +0 -28
  237. package/src/mcp/tools-impact-change.mjs +0 -220
  238. package/src/mcp/tools-impact-precision.mjs +0 -89
  239. package/src/mcp/tools-impact.mjs +0 -169
  240. package/src/mcp/tools-source.mjs +0 -238
  241. package/src/mcp/tools-verified-change.mjs +0 -200
  242. package/src/mcp-rg.mjs +0 -50
  243. package/src/mcp-runtime.mjs +0 -2
  244. package/src/mcp-server.mjs +0 -298
  245. package/src/mcp-source-tools.mjs +0 -163
  246. package/src/path-classification.js +0 -226
  247. package/src/path-ignore.js +0 -69
  248. package/src/precision/lsp-client/constants.js +0 -12
  249. package/src/precision/lsp-client/environment.js +0 -20
  250. package/src/precision/lsp-client/errors.js +0 -15
  251. package/src/precision/lsp-client/lifecycle.js +0 -114
  252. package/src/precision/lsp-client/message-parser.js +0 -81
  253. package/src/precision/lsp-client/protocol.js +0 -212
  254. package/src/precision/lsp-client/registry.js +0 -59
  255. package/src/precision/lsp-client/repo-uri.js +0 -60
  256. package/src/precision/lsp-client/stdio-client.js +0 -140
  257. package/src/precision/lsp-client.js +0 -10
  258. package/src/precision/lsp-overlay/budget-policy.js +0 -78
  259. package/src/precision/lsp-overlay/build.js +0 -261
  260. package/src/precision/lsp-overlay/contract.js +0 -61
  261. package/src/precision/lsp-overlay/reference-results.js +0 -108
  262. package/src/precision/lsp-overlay/semantic-inputs.js +0 -62
  263. package/src/precision/lsp-overlay/source-session.js +0 -142
  264. package/src/precision/lsp-overlay/store.js +0 -150
  265. package/src/precision/lsp-overlay/target-index.js +0 -152
  266. package/src/precision/lsp-overlay/target-query.js +0 -55
  267. package/src/precision/lsp-overlay.js +0 -11
  268. package/src/precision/symbol-query.js +0 -224
  269. package/src/precision/typescript-lsp-provider.js +0 -12
  270. package/src/precision/typescript-provider/client.js +0 -89
  271. package/src/precision/typescript-provider/discovery.js +0 -124
  272. package/src/precision/typescript-provider/isolated-runtime.js +0 -39
  273. package/src/precision/typescript-provider/project-host.js +0 -254
  274. package/src/precision/typescript-provider/project-safety.js +0 -166
  275. package/src/precision/typescript-provider/reference-usage.js +0 -53
  276. package/src/process.js +0 -95
  277. package/src/repo-path.js +0 -53
  278. package/src/scan/discover.inventory.js +0 -78
  279. package/src/scan/discover.js +0 -5
  280. package/src/scan/discover.list.js +0 -79
  281. package/src/scan/discover.stack.js +0 -227
  282. package/src/scan/search.core.js +0 -24
  283. package/src/scan/search.git.js +0 -102
  284. package/src/scan/search.js +0 -9
  285. package/src/scan/search.node.js +0 -83
  286. package/src/scan/search.preview.js +0 -49
  287. package/src/scan/search.rg.js +0 -145
  288. package/src/security/advisory-store.js +0 -172
  289. package/src/security/installed-jvm-rust.js +0 -46
  290. package/src/security/installed.js +0 -280
  291. package/src/security/malware-file-heuristics.js +0 -121
  292. package/src/security/malware-heuristics.exclusions.js +0 -134
  293. package/src/security/malware-heuristics.js +0 -15
  294. package/src/security/malware-heuristics.roots.js +0 -145
  295. package/src/security/malware-heuristics.scan.js +0 -89
  296. package/src/security/malware-heuristics.sweep.js +0 -122
  297. package/src/security/malware-scoring.js +0 -105
  298. package/src/security/match.js +0 -85
  299. package/src/security/registry-sig.classify.js +0 -137
  300. package/src/security/registry-sig.js +0 -18
  301. package/src/security/registry-sig.rules.js +0 -192
  302. package/src/security/rust-advisory-report.js +0 -60
  303. package/src/security/typosquat.js +0 -81
  304. package/src/util.js +0 -40
  305. package/src/version.js +0 -7
@@ -1,102 +0,0 @@
1
- // git grep / git ls-files engine for the cross-repo search — the fast native fallback when no
2
- // ripgrep can be resolved (falls back to the pure-Node scanner per repo). Split out of search.js.
3
- import { join } from "node:path";
4
- import { runCommand } from "../process.js";
5
- import { repoBaseName } from "./discover.js";
6
- import { SKIP_DIRS, nodeSearch } from "./search.node.js";
7
-
8
- // ---- git grep native fallback ------------------------------------------------------------------
9
- const GIT_PATHSPECS = [
10
- ".",
11
- ...[...SKIP_DIRS].map((dir) => `:(exclude)${dir}/**`)
12
- ];
13
-
14
- function gitArgs(root, subcommand, args) {
15
- return ["-C", root, "-c", "core.quotePath=false", subcommand, ...args];
16
- }
17
-
18
- function parseGitGrepLine(line) {
19
- const m = /^(.+?):(\d+):(\d+):(.*)$/.exec(line);
20
- if (!m) return null;
21
- return {
22
- relPath: m[1],
23
- line: Number(m[2]) || 0,
24
- column: Math.max(0, (Number(m[3]) || 1) - 1),
25
- preview: m[4]
26
- };
27
- }
28
-
29
- function pathHasSkippedDir(relPath) {
30
- return String(relPath || "")
31
- .split(/[\\/]+/)
32
- .some((part) => SKIP_DIRS.has(part));
33
- }
34
-
35
- async function gitSearchRoot(git, root, query, mode, cap) {
36
- if (mode === "filename") {
37
- const r = await runCommand(git, gitArgs(root, "ls-files", ["-z", "--cached", "--others", "--exclude-standard", "--", ...GIT_PATHSPECS]), { timeoutMs: 15000 });
38
- if (r.exitCode !== 0) return { ok: false, error: (r.stderr || r.stdout || "git ls-files failed").slice(0, 300) };
39
- const lower = query.toLowerCase();
40
- const ci = query === lower;
41
- const hitIdx = (s) => (ci ? s.toLowerCase().indexOf(lower) : s.indexOf(query));
42
- const files = String(r.stdout || "").split("\0").filter(Boolean);
43
- const results = [];
44
- for (const relPath of files) {
45
- if (results.length >= cap) break;
46
- if (pathHasSkippedDir(relPath)) continue;
47
- const idx = hitIdx(relPath);
48
- if (idx >= 0) results.push({ repo: repoBaseName(root), path: join(root, relPath), line: 0, column: idx, preview: relPath.replace(/\\/g, "/") });
49
- }
50
- return { ok: true, truncated: files.length > results.length && results.length >= cap, results };
51
- }
52
-
53
- const r = await runCommand(
54
- git,
55
- gitArgs(root, "grep", ["-n", "--column", "-I", "--untracked", "-F", "-e", query, "--", ...GIT_PATHSPECS]),
56
- { timeoutMs: 20000 }
57
- );
58
- if (r.exitCode !== 0 && r.exitCode !== 1) return { ok: false, error: (r.stderr || r.stdout || "git grep failed").slice(0, 300) };
59
- const lines = String(r.stdout || "").split(/\r?\n/).filter(Boolean);
60
- const results = [];
61
- for (const line of lines) {
62
- if (results.length >= cap) break;
63
- const parsed = parseGitGrepLine(line);
64
- if (!parsed || pathHasSkippedDir(parsed.relPath)) continue;
65
- results.push({
66
- repo: repoBaseName(root),
67
- path: join(root, parsed.relPath),
68
- line: parsed.line,
69
- column: parsed.column,
70
- preview: parsed.preview.slice(0, 400)
71
- });
72
- }
73
- return { ok: true, truncated: lines.length > results.length && results.length >= cap, results };
74
- }
75
-
76
- export async function gitSearch(git, roots, query, mode, cap) {
77
- const results = [];
78
- let truncated = false;
79
- let usedNodeFallback = false;
80
- for (const root of roots) {
81
- if (results.length >= cap) {
82
- truncated = true;
83
- break;
84
- }
85
- let r;
86
- try {
87
- r = await gitSearchRoot(git, root, query, mode, cap - results.length);
88
- } catch {
89
- r = { ok: false };
90
- }
91
- if (!r.ok) {
92
- usedNodeFallback = true;
93
- const fallback = await nodeSearch([root], query, mode, cap - results.length);
94
- results.push(...fallback.results);
95
- truncated ||= fallback.truncated;
96
- continue;
97
- }
98
- results.push(...r.results);
99
- truncated ||= r.truncated;
100
- }
101
- return { ok: true, engine: usedNodeFallback ? "git-grep+node-fallback" : "git-grep", truncated, results };
102
- }
@@ -1,9 +0,0 @@
1
- // Fast cross-repo search: file NAMES + TEXT inside files, across every open repo at once. Backed by
2
- // ripgrep when one can be resolved (bundled / VS Code / Cursor / PATH), git grep as a fast native
3
- // fallback, and finally a dependency-free Node fs-walk fallback. One reusable searchAcrossRepos() so
4
- // a future MCP server can call the same code.
5
- // Facade: the implementation lives in search.rg.js (ripgrep), search.git.js (git grep),
6
- // search.node.js (pure-Node walker), search.core.js (orchestrator) and search.preview.js.
7
- export { resolveRgInfo, resolveRg } from "./search.rg.js";
8
- export { searchAcrossRepos } from "./search.core.js";
9
- export { readFileForPreview, writeFileForPreview } from "./search.preview.js";
@@ -1,83 +0,0 @@
1
- // Dependency-free Node fs-walk search engine for the cross-repo search, plus the shared SKIP_DIRS
2
- // list. Split out of search.js.
3
- import { statSync } from "node:fs";
4
- import { readFile, opendir } from "node:fs/promises";
5
- import { join, relative } from "node:path";
6
- import { repoBaseName } from "./discover.js";
7
-
8
- export const SKIP_DIRS = new Set([".git", "node_modules", "dist", "build", "out", "coverage", ".next", ".cache", ".turbo", "vendor", "__pycache__", ".venv"]);
9
-
10
- // ---- Node fs-walk fallback (no ripgrep) ---------------------------------------------------------
11
- export async function nodeSearch(roots, query, mode, cap) {
12
- const isContent = mode !== "filename";
13
- const lower = query.toLowerCase();
14
- const ci = query === lower; // smart-case: case-insensitive unless the query has an uppercase letter
15
- const hit = (s) => (ci ? s.toLowerCase().includes(lower) : s.includes(query));
16
- const hitIdx = (s) => (ci ? s.toLowerCase().indexOf(lower) : s.indexOf(query));
17
- const results = [];
18
- let truncated = false;
19
- async function walk(dir, root) {
20
- if (results.length >= cap) {
21
- truncated = true;
22
- return;
23
- }
24
- let dh;
25
- try {
26
- dh = await opendir(dir);
27
- } catch {
28
- return;
29
- }
30
- for await (const ent of dh) {
31
- if (results.length >= cap) {
32
- truncated = true;
33
- break;
34
- }
35
- const full = join(dir, ent.name);
36
- if (ent.isDirectory()) {
37
- if (!SKIP_DIRS.has(ent.name)) await walk(full, root);
38
- continue;
39
- }
40
- if (!ent.isFile()) continue;
41
- const relPath = relative(root, full).replace(/\\/g, "/");
42
- if (!isContent) {
43
- const nameIdx = hitIdx(ent.name);
44
- const relIdx = hitIdx(relPath);
45
- if (nameIdx >= 0 || relIdx >= 0) results.push({ repo: repoBaseName(root), path: full, line: 0, column: Math.max(0, relIdx >= 0 ? relIdx : nameIdx), preview: relPath });
46
- continue;
47
- }
48
- let st;
49
- try {
50
- st = statSync(full);
51
- } catch {
52
- continue;
53
- }
54
- if (st.size > 1500000) continue;
55
- let buf;
56
- try {
57
- buf = await readFile(full);
58
- } catch {
59
- continue;
60
- }
61
- if (buf.includes(0)) continue; // binary
62
- const linesArr = buf.toString("utf8").split(/\r?\n/);
63
- let fileHits = 0;
64
- for (let i = 0; i < linesArr.length; i++) {
65
- if (results.length >= cap) {
66
- truncated = true;
67
- break;
68
- }
69
- const idx = hitIdx(linesArr[i]);
70
- if (idx >= 0) {
71
- results.push({ repo: repoBaseName(root), path: full, line: i + 1, column: idx, preview: linesArr[i].slice(0, 400) });
72
- fileHits++;
73
- if (fileHits >= 40) break; // match rgSearch's --max-count 40 per file
74
- }
75
- }
76
- }
77
- }
78
- for (const root of roots) {
79
- if (results.length >= cap) break;
80
- await walk(root, root);
81
- }
82
- return { ok: true, engine: "node-fallback", truncated, results };
83
- }
@@ -1,49 +0,0 @@
1
- // In-app search preview file access: read/write a file's text ONLY if it sits under one of the
2
- // known repo roots. Split out of search.js.
3
- import { existsSync, statSync } from "node:fs";
4
- import { readFile, writeFile } from "node:fs/promises";
5
- import { resolve, sep } from "node:path";
6
-
7
- // Resolve a preview/edit target ONLY if it sits UNDER one of the known repo roots — the shared guard
8
- // for files:read and files:write. Returns { ok:true, path } or { ok:false, error }.
9
- function resolveRepoFilePath(filePath, repos) {
10
- const roots = (Array.isArray(repos) ? repos : []).filter(Boolean).map((p) => resolve(p));
11
- const abs = resolve(String(filePath || ""));
12
- if (!abs || !roots.some((r) => abs === r || abs.startsWith(r + sep))) return { ok: false, error: "Path is outside the known repos" };
13
- if (!existsSync(abs)) return { ok: false, error: "File not found" };
14
- return { ok: true, path: abs };
15
- }
16
-
17
- // Read a file's text for the in-app preview — only if it sits UNDER one of the known repo roots.
18
- export async function readFileForPreview(filePath, repos) {
19
- const resolved = resolveRepoFilePath(filePath, repos);
20
- if (resolved.ok === false) return resolved;
21
- const abs = resolved.path;
22
- let st;
23
- try {
24
- st = statSync(abs);
25
- } catch {
26
- return { ok: false, error: "Cannot stat file" };
27
- }
28
- if (st.size > 2000000) return { ok: false, error: "File too large to preview (>2 MB) — open it in VS Code." };
29
- try {
30
- return { ok: true, path: abs, content: await readFile(abs, "utf8") };
31
- } catch (error) {
32
- return { ok: false, error: error.message };
33
- }
34
- }
35
-
36
- // Write edited text back from the Search preview's Edit mode — same repo-root guard as the read, and
37
- // only over files that already exist (the in-app editor touches up files, it never creates them).
38
- export async function writeFileForPreview(filePath, repos, content) {
39
- const resolved = resolveRepoFilePath(filePath, repos);
40
- if (resolved.ok === false) return resolved;
41
- const text = String(content ?? "");
42
- if (text.length > 2000000) return { ok: false, error: "Edited text too large to save (>2 MB) — use VS Code." };
43
- try {
44
- await writeFile(resolved.path, text, "utf8");
45
- return { ok: true, path: resolved.path };
46
- } catch (error) {
47
- return { ok: false, error: error.message };
48
- }
49
- }
@@ -1,145 +0,0 @@
1
- // ripgrep engine for the cross-repo search: resolve a usable rg binary (bundled / VS Code / Cursor /
2
- // PATH) and run the ripgrep-backed filename + content search. Split out of search.js.
3
- import { existsSync, readdirSync } from "node:fs";
4
- import { join, sep } from "node:path";
5
- import { runCommand } from "../process.js";
6
- import { repoBaseName } from "./discover.js";
7
-
8
- // ---- ripgrep resolution (no bare `rg` — a packaged app's PATH usually lacks it) -----------------
9
- function rgInInstall(base) {
10
- return [
11
- join(base, "resources", "app", "node_modules", "@vscode", "ripgrep", "bin", "rg.exe"),
12
- join(base, "resources", "app", "node_modules", "@vscode", "ripgrep-universal", "bin", "win32-x64", "rg.exe")
13
- ];
14
- }
15
- function editorRgCandidates() {
16
- const local = process.env.LOCALAPPDATA || "";
17
- const pf = process.env.PROGRAMFILES || "";
18
- const roots = [local && join(local, "Programs", "Microsoft VS Code"), local && join(local, "Programs", "cursor"), pf && join(pf, "Microsoft VS Code")].filter(Boolean);
19
- const out = [];
20
- for (const root of roots) {
21
- if (!existsSync(root)) continue;
22
- out.push(...rgInInstall(root)); // non-versioned install
23
- try {
24
- for (const d of readdirSync(root, { withFileTypes: true })) if (d.isDirectory()) out.push(...rgInInstall(join(root, d.name))); // version-hashed dir
25
- } catch {
26
- /* ignore */
27
- }
28
- }
29
- return out;
30
- }
31
- function extensionRgCandidates() {
32
- const home = process.env.USERPROFILE || process.env.HOME || "";
33
- const roots = [".vscode", ".vscode-insiders", ".cursor"].map((d) => home && join(home, d, "extensions")).filter(Boolean);
34
- const out = [];
35
- const walk = (dir, depth = 0) => {
36
- if (!dir || depth > 5 || out.length >= 20 || !existsSync(dir)) return;
37
- let entries = [];
38
- try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return; }
39
- for (const ent of entries) {
40
- if (out.length >= 20) break;
41
- const full = join(dir, ent.name);
42
- if (ent.isFile() && /^rg(\.exe)?$/i.test(ent.name)) out.push(full);
43
- else if (ent.isDirectory()) walk(full, depth + 1);
44
- }
45
- };
46
- for (const root of roots) walk(root);
47
- return out;
48
- }
49
- async function whereRg() {
50
- if (process.platform !== "win32") return [];
51
- try {
52
- const r = await runCommand("where.exe", ["rg"], { timeoutMs: 4000 });
53
- return String(r.stdout || "").split(/\r?\n/).map((l) => l.trim()).filter((l) => /\.exe$/i.test(l));
54
- } catch {
55
- return [];
56
- }
57
- }
58
- // engine (settings.searchEngine): "auto" (default — custom path → env → editor-bundled rg → PATH →
59
- // git grep → Node), "system" (ONLY the system-installed rg from PATH, then Node), "git" (git grep /
60
- // git ls-files, then Node), "node" (skip native tools entirely, pure-Node scanner).
61
- const _rgCache = new Map(); // engine|rgPath -> { info, at }
62
- // exported: the malware scanner (security/malware-heuristics.js) reuses the same rg resolution
63
- export async function resolveRgInfo(engine = "auto", rgPath = "") {
64
- if (engine === "node" || engine === "git") return null;
65
- const key = `${engine}|${rgPath}`;
66
- const hit = _rgCache.get(key);
67
- if (hit && Date.now() - hit.at < 60000) return hit.info;
68
- const env = process.env.WEAVATRIX_RG_CMD && process.env.WEAVATRIX_RG_CMD.replace(/^"|"$/g, "");
69
- const pathCands = (await whereRg()).map((path) => ({ path, source: "PATH" }));
70
- const cands = [
71
- rgPath && { path: rgPath, source: "custom path" },
72
- engine === "auto" && env && { path: env, source: "WEAVATRIX_RG_CMD" },
73
- ...editorRgCandidates().map((path) => ({ path, source: "VS Code/Cursor bundle" })),
74
- ...extensionRgCandidates().map((path) => ({ path, source: "editor extension" })),
75
- ...pathCands,
76
- process.platform === "win32" ? null : { path: "rg", source: "PATH" },
77
- ].filter(Boolean);
78
- let info = null;
79
- for (const c of cands) {
80
- if (c.path === "rg" || existsSync(c.path)) {
81
- info = { path: c.path, source: c.source, detail: `${c.source}: ${c.path}` };
82
- break;
83
- }
84
- }
85
- _rgCache.set(key, { info, at: Date.now() });
86
- return info;
87
- }
88
-
89
- export async function resolveRg(engine = "auto", rgPath = "") {
90
- return (await resolveRgInfo(engine, rgPath))?.path || null;
91
- }
92
-
93
- function repoOfPath(roots, p) {
94
- const m = roots.find((r) => p === r || p.startsWith(r + sep) || p.startsWith(r + "/"));
95
- return m ? repoBaseName(m) : "";
96
- }
97
-
98
- // ---- ripgrep search -----------------------------------------------------------------------------
99
- export async function rgSearch(rg, roots, query, mode, cap) {
100
- if (mode === "filename") {
101
- const term = query.replace(/[[\]{}]/g, ""); // keep it a plain substring glob
102
- const args = ["--files", "--hidden", "-g", "!.git", "-g", "!node_modules", "-g", `*${term}*`, "--", ...roots];
103
- const r = await runCommand(rg, args, { timeoutMs: 15000 });
104
- if (r.exitCode === 2 && !r.stdout) return { ok: false, error: (r.stderr || "ripgrep error").slice(0, 300) };
105
- const lines = String(r.stdout || "").split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
106
- const results = [];
107
- for (const p of lines) {
108
- if (results.length >= cap) break;
109
- results.push({ repo: repoOfPath(roots, p), path: p, line: 0, column: 0, preview: p.split(/[\\/]/).pop() });
110
- }
111
- return { ok: true, engine: "ripgrep", truncated: lines.length > cap, results };
112
- }
113
- // content (literal/fixed-string smart-case)
114
- const args = ["--json", "-F", "--smart-case", "--max-count", "40", "--max-columns", "400", "--max-columns-preview", "--threads", "0", "-g", "!.git", "-g", "!node_modules", "-e", query, "--", ...roots];
115
- const r = await runCommand(rg, args, { timeoutMs: 20000 });
116
- if (r.exitCode === 2 && !r.stdout) return { ok: false, error: (r.stderr || "ripgrep error").slice(0, 300) };
117
- const results = [];
118
- let truncated = false;
119
- for (const line of String(r.stdout || "").split(/\r?\n/)) {
120
- if (!line) continue;
121
- if (results.length >= cap) {
122
- truncated = true;
123
- break;
124
- }
125
- let obj;
126
- try {
127
- obj = JSON.parse(line);
128
- } catch {
129
- continue;
130
- }
131
- if (obj.type !== "match") continue;
132
- const d = obj.data || {};
133
- const path = d.path?.text || "";
134
- if (!path) continue;
135
- const sub = (d.submatches || [])[0];
136
- results.push({
137
- repo: repoOfPath(roots, path),
138
- path,
139
- line: d.line_number || 0,
140
- column: sub ? sub.start : 0,
141
- preview: String(d.lines?.text || "").replace(/\r?\n$/, "").slice(0, 400)
142
- });
143
- }
144
- return { ok: true, engine: "ripgrep", truncated, results };
145
- }
@@ -1,172 +0,0 @@
1
- // Offline advisory cache. The MIT core plans source-free OSV coordinates, validates returned
2
- // records and reads/writes the local cache, but never performs network I/O. A connector extension
3
- // owns remote transport and passes bounded response data to commitAdvisoryRefresh().
4
- import {existsSync, readFileSync, writeFileSync, mkdirSync} from 'node:fs'
5
- import {join, dirname} from 'node:path'
6
- import {homedir} from 'node:os'
7
- import {createHash} from 'node:crypto'
8
- import {uniqueBy} from '../util.js'
9
-
10
- export const DEFAULT_STORE = join(homedir(), '.weavatrix', 'advisories.json')
11
- const OSV_SUPPORTED_ECOSYSTEMS = new Set(['npm', 'PyPI', 'Go', 'Maven', 'crates.io'])
12
-
13
- const keyOf = (ecosystem, name) => `${ecosystem}|${ecosystem === 'PyPI' ? String(name).toLowerCase().replace(/[-_.]+/g, '-') : name}`
14
- const uniquePackages = (packages) => uniqueBy(packages, (item) => `${item.ecosystem}|${item.name}|${item.version}`)
15
-
16
- export function createAdvisoryQueryPlan(installed = []) {
17
- const pinned = installed.filter((item) => item?.ecosystem && item?.name && item?.version)
18
- const unsupported = pinned.filter((item) => !OSV_SUPPORTED_ECOSYSTEMS.has(item.ecosystem)).length
19
- const packages = uniquePackages(pinned.filter((item) => OSV_SUPPORTED_ECOSYSTEMS.has(item.ecosystem)))
20
- .map(({ecosystem, name, version}) => ({ecosystem, name, version}))
21
- return Object.freeze({packages: Object.freeze(packages), unsupported})
22
- }
23
-
24
- export function advisoryQueryFingerprint(installed = []) {
25
- const rows = createAdvisoryQueryPlan(installed).packages
26
- .map((item) => `${item.ecosystem}|${item.name}|${item.version}`)
27
- .sort()
28
- return createHash('sha256').update(rows.join('\n'), 'utf8').digest('hex')
29
- }
30
-
31
- export function loadStore(storePath = DEFAULT_STORE) {
32
- try {
33
- const store = JSON.parse(readFileSync(storePath, 'utf8'))
34
- if (store && typeof store === 'object' && store.records) return store
35
- } catch { /* missing/corrupt -> empty */ }
36
- return {meta: {fetched_at: null}, records: {}}
37
- }
38
-
39
- export const queryStore = (store, ecosystem, name) => (store?.records?.[keyOf(ecosystem, name)]) || []
40
-
41
- export function storeMeta(storePath = DEFAULT_STORE) {
42
- const store = loadStore(storePath)
43
- return {
44
- fetchedAt: store.meta?.fetched_at || null,
45
- advisoryCount: Object.values(store.records || {}).reduce((total, records) => total + records.length, 0),
46
- }
47
- }
48
-
49
- function severityOf(record) {
50
- if (String(record.id || '').startsWith('MAL-')) return 'critical'
51
- const label = String(record.database_specific?.severity || '').toLowerCase()
52
- if (label === 'critical') return 'critical'
53
- if (label === 'high') return 'high'
54
- if (label === 'moderate' || label === 'medium') return 'medium'
55
- if (label === 'low') return 'low'
56
- let best = 0
57
- for (const severity of record.severity || []) {
58
- const value = String(severity.score || '')
59
- const match = /CVSS:[\d.]+\/.*?\bA[VC]?:/i.test(value) ? null : value.match(/^(\d+(?:\.\d+)?)$/)
60
- if (match) best = Math.max(best, Number(match[1]))
61
- }
62
- if (best >= 9) return 'critical'
63
- if (best >= 7) return 'high'
64
- return 'medium'
65
- }
66
-
67
- export function normalizeOsvAdvisory(record, ecosystem, name) {
68
- const affected = (record?.affected || []).find((item) => item?.package
69
- && item.package.ecosystem === ecosystem
70
- && keyOf(ecosystem, item.package.name) === keyOf(ecosystem, name))
71
- if (!affected) return null
72
- const fixed = []
73
- for (const range of affected.ranges || []) for (const event of range.events || []) if (event.fixed) fixed.push(event.fixed)
74
- return {
75
- id: record.id,
76
- kind: String(record.id || '').startsWith('MAL-') ? 'malicious' : 'vuln',
77
- severity: severityOf(record),
78
- summary: String(record.summary || record.details || '').slice(0, 300),
79
- modified: record.modified || '',
80
- aliases: (record.aliases || []).slice(0, 6),
81
- fixedIn: [...new Set(fixed)].slice(0, 4),
82
- affected: {versions: affected.versions || [], ranges: affected.ranges || []},
83
- }
84
- }
85
-
86
- // idsByPackage is an array parallel to plan.packages; advisoryRecords is an id-keyed plain object.
87
- // Remote failures arrive explicitly in errors. A zero-response failure never stamps the cache fresh.
88
- export function commitAdvisoryRefresh({
89
- plan,
90
- idsByPackage = [],
91
- advisoryRecords = {},
92
- queriedOk = 0,
93
- errors: initialErrors = [],
94
- storePath = DEFAULT_STORE,
95
- repoKey = '',
96
- repoKeys = [],
97
- } = {}) {
98
- const packages = plan?.packages || []
99
- const unsupported = Number(plan?.unsupported) || 0
100
- if (!packages.length) return {ok: false, queried: 0, unsupported, error: 'No OSV-supported pinned package versions found to check.'}
101
- const errors = [...initialErrors.map(String)]
102
- if (errors.length && queriedOk === 0) {
103
- return {ok: false, queried: packages.length, unsupported, error: `advisory refresh failed: ${errors[0]}`, errors}
104
- }
105
-
106
- const store = loadStore(storePath)
107
- const wanted = new Map()
108
- idsByPackage.forEach((ids, index) => {
109
- for (const id of Array.isArray(ids) ? ids : []) {
110
- if (!wanted.has(id)) wanted.set(id, [])
111
- wanted.get(id).push(packages[index])
112
- }
113
- })
114
-
115
- let fetched = 0
116
- for (const [id, packageList] of wanted) {
117
- const record = advisoryRecords[id]
118
- if (!record || record.id !== id) {
119
- errors.push(`${id}: advisory detail response is missing or has a mismatched id`)
120
- continue
121
- }
122
- let normalized = 0
123
- for (const item of packageList) {
124
- const row = normalizeOsvAdvisory(record, item.ecosystem, item.name)
125
- if (!row) {
126
- errors.push(`${id}: advisory detail does not describe ${item.ecosystem}:${item.name}`)
127
- continue
128
- }
129
- normalized++
130
- const key = keyOf(item.ecosystem, item.name)
131
- const records = store.records[key] || (store.records[key] = [])
132
- const index = records.findIndex((existing) => existing.id === row.id)
133
- if (index >= 0) records[index] = row
134
- else records.push(row)
135
- }
136
- if (normalized) fetched++
137
- }
138
-
139
- const fetchedAt = new Date().toISOString()
140
- const status = errors.length ? 'PARTIAL' : 'OK'
141
- store.meta.fetched_at = fetchedAt
142
- const stampRepos = [...new Set([repoKey, ...repoKeys].filter(Boolean))]
143
- if (stampRepos.length) {
144
- store.meta.repos ||= {}
145
- for (const key of stampRepos) store.meta.repos[key] = {
146
- fetched_at: fetchedAt,
147
- status,
148
- queried: packages.length,
149
- queried_ok: queriedOk,
150
- unsupported,
151
- error_count: errors.length,
152
- query_fingerprint: advisoryQueryFingerprint(packages),
153
- }
154
- }
155
- try {
156
- mkdirSync(dirname(storePath), {recursive: true})
157
- writeFileSync(storePath, JSON.stringify(store), 'utf8')
158
- } catch (error) {
159
- return {ok: false, error: `store write failed: ${error.message}`, errors}
160
- }
161
- return {
162
- ok: true,
163
- status,
164
- queried: packages.length,
165
- queriedOk,
166
- unsupported,
167
- vulnerable: wanted.size,
168
- fetched,
169
- saved: existsSync(storePath),
170
- errors,
171
- }
172
- }
@@ -1,46 +0,0 @@
1
- import { createRepoBoundary } from "../repo-path.js";
2
- import { listRepoFiles, readRepoText } from "../analysis/internal-audit/repo-files.js";
3
- import { parseCargoLockPackages } from "../analysis/cargo-manifests.js";
4
- import { parseGradleDependencies, parseGradleLockPackages, parseGradleVersionCatalog, parseMavenPom } from "../analysis/jvm-manifests.js";
5
-
6
- const dedupe = (items) => {
7
- const seen = new Set();
8
- return items.filter((item) => {
9
- const key = `${item.ecosystem}|${item.name}|${item.version}`;
10
- if (!item.name || !item.version || seen.has(key)) return false;
11
- seen.add(key); return true;
12
- });
13
- };
14
- const concreteVersion = (value) => !!value && !/[\[\](),${}*+]/.test(String(value));
15
-
16
- export function collectJvmRustInstalled(repoPath) {
17
- const boundary = createRepoBoundary(repoPath);
18
- if (!boundary.root) return [];
19
- const files = listRepoFiles(repoPath);
20
- const installed = [];
21
- for (const file of files.filter((name) => /(^|\/)Cargo\.lock$/i.test(name))) {
22
- installed.push(...parseCargoLockPackages(readRepoText(boundary, file)));
23
- }
24
- for (const file of files.filter((name) => /(^|\/)pom\.xml$/i.test(name))) {
25
- const parsed = parseMavenPom(readRepoText(boundary, file));
26
- installed.push(...parsed.dependencies.filter((item) => concreteVersion(item.version)).map((item) => ({
27
- ecosystem: "Maven", name: item.name, version: item.version, dev: item.scope === "test",
28
- integrity: "", source: "pom",
29
- })));
30
- }
31
- const catalog = new Map();
32
- for (const file of files.filter((name) => /(^|\/)libs\.versions\.toml$/i.test(name))) {
33
- for (const [alias, entry] of parseGradleVersionCatalog(readRepoText(boundary, file))) catalog.set(alias, entry);
34
- }
35
- for (const file of files.filter((name) => /(^|\/)(?:build|settings|[^/]+)\.gradle(?:\.kts)?$/i.test(name))) {
36
- const dependencies = parseGradleDependencies(readRepoText(boundary, file), catalog);
37
- installed.push(...dependencies.filter((item) => concreteVersion(item.version)).map((item) => ({
38
- ecosystem: "Maven", name: item.name, version: item.version,
39
- dev: /test/i.test(item.scope || ""), integrity: "", source: "gradle-manifest",
40
- })));
41
- }
42
- for (const file of files.filter((name) => /(^|\/)(?:gradle\.lockfile|dependency-locks\/[^/]+\.lockfile)$/i.test(name))) {
43
- installed.push(...parseGradleLockPackages(readRepoText(boundary, file)));
44
- }
45
- return dedupe(installed);
46
- }