weavatrix 0.3.14 → 1.1.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 (306) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +132 -200
  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 +10 -67
  14. package/server.json +38 -0
  15. package/skill/SKILL.md +62 -374
  16. package/skill/agents/openai.yaml +4 -0
  17. package/skill/references/tool-routing.md +45 -0
  18. package/SECURITY.md +0 -101
  19. package/docs/adr/0001-v0.3-offline-online-split.md +0 -60
  20. package/docs/agent-task-benchmark.md +0 -58
  21. package/docs/releases/v0.2.19.md +0 -33
  22. package/docs/releases/v0.3.0.md +0 -43
  23. package/docs/releases/v0.3.1.md +0 -30
  24. package/docs/releases/v0.3.10.md +0 -76
  25. package/docs/releases/v0.3.11.md +0 -55
  26. package/docs/releases/v0.3.12.md +0 -44
  27. package/docs/releases/v0.3.13.md +0 -34
  28. package/docs/releases/v0.3.14.md +0 -37
  29. package/docs/releases/v0.3.2.md +0 -15
  30. package/docs/releases/v0.3.3.md +0 -25
  31. package/docs/releases/v0.3.4.md +0 -40
  32. package/docs/releases/v0.3.5.md +0 -50
  33. package/docs/releases/v0.3.6.md +0 -44
  34. package/docs/releases/v0.3.7.md +0 -37
  35. package/docs/releases/v0.3.8.md +0 -21
  36. package/docs/releases/v0.3.9.md +0 -36
  37. package/scripts/run-agent-task-benchmark.mjs +0 -118
  38. package/src/analysis/allowed-test-runner.js +0 -70
  39. package/src/analysis/architecture/contract-graph.js +0 -119
  40. package/src/analysis/architecture/contract-schema.js +0 -110
  41. package/src/analysis/architecture/contract-storage.js +0 -35
  42. package/src/analysis/architecture/contract-verification.js +0 -168
  43. package/src/analysis/architecture-contract.js +0 -16
  44. package/src/analysis/audit-debt.js +0 -94
  45. package/src/analysis/audit-extensions.js +0 -60
  46. package/src/analysis/cargo-dependency-evidence.js +0 -108
  47. package/src/analysis/cargo-manifests.js +0 -81
  48. package/src/analysis/change-classification/diff-parser.js +0 -103
  49. package/src/analysis/change-classification/options.js +0 -40
  50. package/src/analysis/change-classification/symbol-classifier.js +0 -177
  51. package/src/analysis/change-classification.js +0 -188
  52. package/src/analysis/coverage-reports-tarpaulin.js +0 -112
  53. package/src/analysis/coverage-reports.js +0 -246
  54. package/src/analysis/cycle-route.js +0 -14
  55. package/src/analysis/data-flow-evidence.js +0 -114
  56. package/src/analysis/dead-check.js +0 -300
  57. package/src/analysis/dead-code-review/candidates.js +0 -194
  58. package/src/analysis/dead-code-review/policy.js +0 -23
  59. package/src/analysis/dead-code-review.js +0 -119
  60. package/src/analysis/dep-check-ecosystems.js +0 -205
  61. package/src/analysis/dep-check.js +0 -290
  62. package/src/analysis/dep-rules.js +0 -10
  63. package/src/analysis/dependency/conventions.js +0 -16
  64. package/src/analysis/dependency/scoped-dependencies.js +0 -51
  65. package/src/analysis/dependency/source-references.js +0 -21
  66. package/src/analysis/duplicate-groups.js +0 -104
  67. package/src/analysis/duplicates-worker.js +0 -11
  68. package/src/analysis/duplicates.compute.js +0 -269
  69. package/src/analysis/duplicates.js +0 -15
  70. package/src/analysis/duplicates.run.js +0 -52
  71. package/src/analysis/duplicates.tokenize.js +0 -199
  72. package/src/analysis/endpoints/common.js +0 -79
  73. package/src/analysis/endpoints/extract.js +0 -120
  74. package/src/analysis/endpoints/inventory.js +0 -84
  75. package/src/analysis/endpoints/mounts.js +0 -129
  76. package/src/analysis/endpoints-java.js +0 -260
  77. package/src/analysis/endpoints-rust.js +0 -124
  78. package/src/analysis/endpoints.js +0 -3
  79. package/src/analysis/findings.js +0 -70
  80. package/src/analysis/git-history/analytics.js +0 -177
  81. package/src/analysis/git-history/collector.js +0 -67
  82. package/src/analysis/git-history/options.js +0 -66
  83. package/src/analysis/git-history.js +0 -143
  84. package/src/analysis/git-ref-graph.js +0 -76
  85. package/src/analysis/go-dependency-evidence.js +0 -62
  86. package/src/analysis/graph-analysis.aggregate.js +0 -296
  87. package/src/analysis/graph-analysis.edges.js +0 -24
  88. package/src/analysis/graph-analysis.js +0 -7
  89. package/src/analysis/graph-analysis.refs.js +0 -202
  90. package/src/analysis/graph-analysis.summaries.js +0 -65
  91. package/src/analysis/health-capabilities.js +0 -83
  92. package/src/analysis/hot-path-review.js +0 -266
  93. package/src/analysis/http-contract-wrappers.js +0 -241
  94. package/src/analysis/http-contracts/analysis.js +0 -179
  95. package/src/analysis/http-contracts/client-call-detection.js +0 -82
  96. package/src/analysis/http-contracts/client-call-parser.js +0 -273
  97. package/src/analysis/http-contracts/graph-context.js +0 -143
  98. package/src/analysis/http-contracts/matching.js +0 -61
  99. package/src/analysis/http-contracts/shared.js +0 -85
  100. package/src/analysis/http-contracts.js +0 -6
  101. package/src/analysis/internal-audit/dependency-health.js +0 -113
  102. package/src/analysis/internal-audit/python-manifests.js +0 -78
  103. package/src/analysis/internal-audit/repo-files.js +0 -50
  104. package/src/analysis/internal-audit/supply-chain.js +0 -149
  105. package/src/analysis/internal-audit.collect.js +0 -213
  106. package/src/analysis/internal-audit.js +0 -9
  107. package/src/analysis/internal-audit.reach.js +0 -201
  108. package/src/analysis/internal-audit.run.js +0 -256
  109. package/src/analysis/java-source.js +0 -36
  110. package/src/analysis/jvm-artifact-index.js +0 -87
  111. package/src/analysis/jvm-dependency-evidence.js +0 -138
  112. package/src/analysis/jvm-manifests.js +0 -114
  113. package/src/analysis/manifests.js +0 -123
  114. package/src/analysis/package-reachability.js +0 -39
  115. package/src/analysis/source-complexity.ast.js +0 -97
  116. package/src/analysis/source-complexity.constants.js +0 -55
  117. package/src/analysis/source-complexity.js +0 -14
  118. package/src/analysis/source-complexity.report.js +0 -81
  119. package/src/analysis/source-complexity.walk.js +0 -228
  120. package/src/analysis/source-correctness/retry-patterns.js +0 -93
  121. package/src/analysis/source-correctness.js +0 -222
  122. package/src/analysis/static-test-reachability.js +0 -150
  123. package/src/analysis/structure/dependency-graph.js +0 -151
  124. package/src/analysis/structure/findings.js +0 -162
  125. package/src/analysis/task-retrieval.js +0 -107
  126. package/src/analysis/transport-contracts.js +0 -224
  127. package/src/analysis/transport-runtime-evidence.js +0 -155
  128. package/src/analysis-kit.mjs +0 -17
  129. package/src/bounds.js +0 -4
  130. package/src/build-graph.js +0 -209
  131. package/src/child-env.js +0 -7
  132. package/src/config.js +0 -5
  133. package/src/extension/local-services.mjs +0 -75
  134. package/src/git-exec.js +0 -67
  135. package/src/graph/build-worker.js +0 -49
  136. package/src/graph/builder/go-receiver-resolution.js +0 -112
  137. package/src/graph/builder/js/dynamic-import.js +0 -26
  138. package/src/graph/builder/js/queries.js +0 -48
  139. package/src/graph/builder/lang-csharp.js +0 -40
  140. package/src/graph/builder/lang-css.js +0 -29
  141. package/src/graph/builder/lang-go.js +0 -140
  142. package/src/graph/builder/lang-html.js +0 -29
  143. package/src/graph/builder/lang-java-calls.js +0 -142
  144. package/src/graph/builder/lang-java.js +0 -215
  145. package/src/graph/builder/lang-js.js +0 -291
  146. package/src/graph/builder/lang-python.js +0 -235
  147. package/src/graph/builder/lang-rust-calls.js +0 -63
  148. package/src/graph/builder/lang-rust.js +0 -299
  149. package/src/graph/builder/lang-solidity.js +0 -126
  150. package/src/graph/builder/lang-sql.js +0 -263
  151. package/src/graph/builder/pass2-resolution.js +0 -81
  152. package/src/graph/builder/spec-pkg.js +0 -87
  153. package/src/graph/community.js +0 -27
  154. package/src/graph/edge-provenance.js +0 -31
  155. package/src/graph/file-lock.js +0 -69
  156. package/src/graph/freshness-probe.js +0 -142
  157. package/src/graph/graph-filter.js +0 -63
  158. package/src/graph/incremental-refresh.js +0 -235
  159. package/src/graph/internal-builder.barrels.js +0 -235
  160. package/src/graph/internal-builder.build.js +0 -300
  161. package/src/graph/internal-builder.java.js +0 -33
  162. package/src/graph/internal-builder.js +0 -12
  163. package/src/graph/internal-builder.langs.js +0 -157
  164. package/src/graph/internal-builder.pass2.js +0 -163
  165. package/src/graph/internal-builder.resolvers.js +0 -286
  166. package/src/graph/layout.js +0 -51
  167. package/src/graph/node-id.js +0 -7
  168. package/src/graph/parser-artifact-boundary.js +0 -55
  169. package/src/graph/relations.js +0 -4
  170. package/src/graph/repo-registry.js +0 -124
  171. package/src/graph/resolvers/rust.js +0 -117
  172. package/src/infra/infra-items.js +0 -255
  173. package/src/infra/infra-registry.js +0 -184
  174. package/src/infra/infra.detect.js +0 -119
  175. package/src/infra/infra.js +0 -38
  176. package/src/infra/infra.match.js +0 -102
  177. package/src/infra/infra.scan.js +0 -93
  178. package/src/mcp/actions/graph-lifecycle.mjs +0 -148
  179. package/src/mcp/architecture-bootstrap.mjs +0 -168
  180. package/src/mcp/architecture-starter.mjs +0 -234
  181. package/src/mcp/catalog.mjs +0 -233
  182. package/src/mcp/company-contract-page.mjs +0 -142
  183. package/src/mcp/company-contract-reconcile.mjs +0 -87
  184. package/src/mcp/company-contract-verdict.mjs +0 -42
  185. package/src/mcp/evidence/bun-lock-graph.mjs +0 -209
  186. package/src/mcp/evidence/duplicate-member-order.mjs +0 -8
  187. package/src/mcp/evidence/package-graph-common.mjs +0 -115
  188. package/src/mcp/evidence/package-lock-graph.mjs +0 -92
  189. package/src/mcp/evidence-snapshot.architecture.mjs +0 -80
  190. package/src/mcp/evidence-snapshot.common.mjs +0 -158
  191. package/src/mcp/evidence-snapshot.duplicates.mjs +0 -213
  192. package/src/mcp/evidence-snapshot.health.mjs +0 -102
  193. package/src/mcp/evidence-snapshot.inventory.mjs +0 -148
  194. package/src/mcp/evidence-snapshot.mjs +0 -50
  195. package/src/mcp/evidence-snapshot.package-graph.mjs +0 -34
  196. package/src/mcp/evidence-snapshot.structure.mjs +0 -84
  197. package/src/mcp/extension-api.mjs +0 -77
  198. package/src/mcp/git-output.mjs +0 -7
  199. package/src/mcp/graph/context-core.mjs +0 -111
  200. package/src/mcp/graph/context-seeds.mjs +0 -207
  201. package/src/mcp/graph/context-state.mjs +0 -85
  202. package/src/mcp/graph/reverse-reach.mjs +0 -42
  203. package/src/mcp/graph/tools-core.mjs +0 -143
  204. package/src/mcp/graph/tools-query.mjs +0 -276
  205. package/src/mcp/graph-context.mjs +0 -5
  206. package/src/mcp/graph-diff.mjs +0 -218
  207. package/src/mcp/health/audit-format.mjs +0 -199
  208. package/src/mcp/health/audit.mjs +0 -199
  209. package/src/mcp/health/dead-code.mjs +0 -110
  210. package/src/mcp/health/duplicates.mjs +0 -121
  211. package/src/mcp/health/endpoints.mjs +0 -71
  212. package/src/mcp/health/structure.mjs +0 -220
  213. package/src/mcp/runtime-version.mjs +0 -31
  214. package/src/mcp/server/auto-refresh.mjs +0 -66
  215. package/src/mcp/server/runtime-config.mjs +0 -43
  216. package/src/mcp/server/shutdown.mjs +0 -40
  217. package/src/mcp/staleness-notice.mjs +0 -20
  218. package/src/mcp/sync/evidence-architecture.mjs +0 -54
  219. package/src/mcp/sync/evidence-common.mjs +0 -88
  220. package/src/mcp/sync/evidence-duplicates.mjs +0 -97
  221. package/src/mcp/sync/evidence-health.mjs +0 -56
  222. package/src/mcp/sync/evidence-packages.mjs +0 -95
  223. package/src/mcp/sync/payload-common.mjs +0 -97
  224. package/src/mcp/sync/payload-v2.mjs +0 -54
  225. package/src/mcp/sync/payload-v3.mjs +0 -79
  226. package/src/mcp/sync-evidence.mjs +0 -23
  227. package/src/mcp/sync-payload.mjs +0 -70
  228. package/src/mcp/tool-result.mjs +0 -54
  229. package/src/mcp/tools-actions.mjs +0 -11
  230. package/src/mcp/tools-architecture.mjs +0 -177
  231. package/src/mcp/tools-company.mjs +0 -251
  232. package/src/mcp/tools-context.mjs +0 -222
  233. package/src/mcp/tools-endpoints.mjs +0 -207
  234. package/src/mcp/tools-graph-hubs.mjs +0 -78
  235. package/src/mcp/tools-graph.mjs +0 -17
  236. package/src/mcp/tools-health.mjs +0 -24
  237. package/src/mcp/tools-history.mjs +0 -28
  238. package/src/mcp/tools-impact-change.mjs +0 -220
  239. package/src/mcp/tools-impact-precision.mjs +0 -89
  240. package/src/mcp/tools-impact.mjs +0 -169
  241. package/src/mcp/tools-source.mjs +0 -238
  242. package/src/mcp/tools-verified-change.mjs +0 -200
  243. package/src/mcp-rg.mjs +0 -50
  244. package/src/mcp-runtime.mjs +0 -2
  245. package/src/mcp-server.mjs +0 -298
  246. package/src/mcp-source-tools.mjs +0 -163
  247. package/src/path-classification.js +0 -226
  248. package/src/path-ignore.js +0 -69
  249. package/src/precision/lsp-client/constants.js +0 -12
  250. package/src/precision/lsp-client/environment.js +0 -20
  251. package/src/precision/lsp-client/errors.js +0 -15
  252. package/src/precision/lsp-client/lifecycle.js +0 -114
  253. package/src/precision/lsp-client/message-parser.js +0 -81
  254. package/src/precision/lsp-client/protocol.js +0 -212
  255. package/src/precision/lsp-client/registry.js +0 -59
  256. package/src/precision/lsp-client/repo-uri.js +0 -60
  257. package/src/precision/lsp-client/stdio-client.js +0 -140
  258. package/src/precision/lsp-client.js +0 -10
  259. package/src/precision/lsp-overlay/budget-policy.js +0 -78
  260. package/src/precision/lsp-overlay/build.js +0 -261
  261. package/src/precision/lsp-overlay/contract.js +0 -61
  262. package/src/precision/lsp-overlay/reference-results.js +0 -108
  263. package/src/precision/lsp-overlay/semantic-inputs.js +0 -62
  264. package/src/precision/lsp-overlay/source-session.js +0 -142
  265. package/src/precision/lsp-overlay/store.js +0 -150
  266. package/src/precision/lsp-overlay/target-index.js +0 -152
  267. package/src/precision/lsp-overlay/target-query.js +0 -55
  268. package/src/precision/lsp-overlay.js +0 -11
  269. package/src/precision/symbol-query.js +0 -224
  270. package/src/precision/typescript-lsp-provider.js +0 -12
  271. package/src/precision/typescript-provider/client.js +0 -89
  272. package/src/precision/typescript-provider/discovery.js +0 -124
  273. package/src/precision/typescript-provider/isolated-runtime.js +0 -39
  274. package/src/precision/typescript-provider/project-host.js +0 -254
  275. package/src/precision/typescript-provider/project-safety.js +0 -166
  276. package/src/precision/typescript-provider/reference-usage.js +0 -53
  277. package/src/process.js +0 -95
  278. package/src/repo-path.js +0 -53
  279. package/src/scan/discover.inventory.js +0 -78
  280. package/src/scan/discover.js +0 -5
  281. package/src/scan/discover.list.js +0 -79
  282. package/src/scan/discover.stack.js +0 -227
  283. package/src/scan/search.core.js +0 -24
  284. package/src/scan/search.git.js +0 -102
  285. package/src/scan/search.js +0 -9
  286. package/src/scan/search.node.js +0 -83
  287. package/src/scan/search.preview.js +0 -49
  288. package/src/scan/search.rg.js +0 -145
  289. package/src/security/advisory-store.js +0 -172
  290. package/src/security/installed-jvm-rust.js +0 -46
  291. package/src/security/installed.js +0 -280
  292. package/src/security/malware-file-heuristics.js +0 -121
  293. package/src/security/malware-heuristics.exclusions.js +0 -134
  294. package/src/security/malware-heuristics.js +0 -15
  295. package/src/security/malware-heuristics.roots.js +0 -145
  296. package/src/security/malware-heuristics.scan.js +0 -89
  297. package/src/security/malware-heuristics.sweep.js +0 -122
  298. package/src/security/malware-scoring.js +0 -105
  299. package/src/security/match.js +0 -85
  300. package/src/security/registry-sig.classify.js +0 -137
  301. package/src/security/registry-sig.js +0 -18
  302. package/src/security/registry-sig.rules.js +0 -192
  303. package/src/security/rust-advisory-report.js +0 -60
  304. package/src/security/typosquat.js +0 -81
  305. package/src/util.js +0 -40
  306. package/src/version.js +0 -7
@@ -1,299 +0,0 @@
1
- // Rust extractor. Symbols: fn (incl. impl methods) + struct/enum/trait/type/mod + const/static
2
- // (+ macro_rules!/union via optional queries). Calls: `foo()` / `x.foo()` / `path::foo()` (name only).
3
- // File dependencies follow Rust's module tree: outlined `mod`, `use` trees, public re-exports, and anchored
4
- // `crate/self/super` paths resolve to repo-local .rs or */mod.rs files. External crates deliberately stay out
5
- // of this adapter; Cargo dependency analysis owns them.
6
- import { rustScopedCalls } from "./lang-rust-calls.js";
7
-
8
- const SYMS_CORE = `
9
- (function_item name: (identifier) @function)
10
- (struct_item name: (type_identifier) @struct)
11
- (enum_item name: (type_identifier) @enum)
12
- (trait_item name: (type_identifier) @trait)
13
- (type_item name: (type_identifier) @type)
14
- (mod_item name: (identifier) @module)
15
- (const_item name: (identifier) @constant)
16
- (static_item name: (identifier) @static)`;
17
- // Grammar-version-dependent node types, compiled SEPARATELY (one unknown type voids its whole query).
18
- const SYMS_OPTIONAL = [
19
- `(function_signature_item name: (identifier) @function)`,
20
- `(macro_definition name: (identifier) @macro)`,
21
- `(union_item name: (type_identifier) @union)`,
22
- ];
23
-
24
- const cleanSegment = (part) => String(part || "").trim().replace(/^r#/, "");
25
- // Rust primitive types are language builtins, never crate dependencies: `f64::from(..)`, `u8::MAX`,
26
- // `str::len` and friends must not be recorded as external crate imports.
27
- const RUST_PRIMITIVES = new Set(["bool", "char", "str", "f32", "f64", "i8", "i16", "i32", "i64", "i128", "isize", "u8", "u16", "u32", "u64", "u128", "usize"]);
28
- const RUST_NON_CRATE_HEADS = ["crate", "self", "super", "std", "core", "alloc"];
29
- // A path head is an external crate only when it is not an anchor keyword, a std root, a primitive type,
30
- // or a name already bound into local scope by a `use` (a module alias or imported item).
31
- const isExternalCrate = (head, localBindings) => Boolean(head) && !RUST_NON_CRATE_HEADS.includes(head) && !RUST_PRIMITIVES.has(head) && !localBindings.has(head) && /^[a-z_][\w]*$/.test(head);
32
- const pathParts = (node) => String(node?.text || "").split("::").map(cleanSegment).filter(Boolean);
33
- const under = (node, type) => { for (let p = node?.parent; p; p = p.parent) if (p.type === type) return true; return false; };
34
- const ancestor = (node, types) => {
35
- for (let parent = node?.parent; parent; parent = parent.parent) if (types.has(parent.type)) return parent;
36
- return null;
37
- };
38
- const memberOwners = new Set(["impl_item", "trait_item"]);
39
- const publicVisibility = (declaration, owner) => {
40
- if (owner?.type === "trait_item") return "public";
41
- const source = String(declaration?.text || "").trimStart();
42
- if (/^pub\s/.test(source)) return "public";
43
- if (/^pub\s*\(/.test(source)) return "protected";
44
- return "private";
45
- };
46
- const ownerName = (owner, field) => {
47
- if (!owner) return "";
48
- if (owner.type === "trait_item") return field(owner, "name")?.text || "";
49
- const type = field(owner, "type")?.text || "";
50
- const withoutGenerics = type.replace(/<[^<>]*>/g, "");
51
- return (withoutGenerics.match(/[A-Za-z_]\w*/g) || []).at(-1) || "";
52
- };
53
-
54
- function pathAttribute(modNode) {
55
- for (let prev = modNode?.previousNamedSibling; prev?.type === "attribute_item"; prev = prev.previousNamedSibling) {
56
- const hashedRaw = prev.text.match(/\bpath\s*=\s*r(#+)"([^"]+)"\1/);
57
- if (hashedRaw) return hashedRaw[2] || "";
58
- const plain = prev.text.match(/\bpath\s*=\s*(?:r)?"([^"]+)"/);
59
- if (plain) return plain[1] || "";
60
- }
61
- return "";
62
- }
63
-
64
- // Test-only classification must mean "compiled exclusively under `cargo test`": #[cfg(test)] and
65
- // #[cfg(all(test, ...))] guarantee that; #[cfg(any(test, ...))] also compiles into production builds
66
- // and deliberately stays unclassified. #[test]/#[bench] (incl. #[tokio::test]-style harness paths)
67
- // mark the annotated function itself.
68
- const CFG_TEST_RE = /#\s*!?\s*\[\s*cfg\s*\(\s*(?:test\s*\)|all\s*\(\s*test\b)/;
69
- const TEST_FN_ATTR_RE = /#\s*\[\s*(?:[\w]+(?:\s*::\s*[\w]+)*\s*::\s*)?(?:test|bench)\s*(?:\]|\()/;
70
- const CFG_TEST_CARRIERS = new Set(["mod_item", "impl_item", "trait_item", "function_item"]);
71
- const COMMENT_TYPES = new Set(["line_comment", "block_comment"]);
72
- const itemAttributeText = (item) => {
73
- // Comments are NAMED siblings in tree-sitter-rust — `#[test]` + `// note` + `fn` must still classify.
74
- let text = "";
75
- for (let prev = item?.previousNamedSibling; prev; prev = prev.previousNamedSibling) {
76
- if (COMMENT_TYPES.has(prev.type)) continue;
77
- if (prev.type !== "attribute_item") break;
78
- text += prev.text + "\n";
79
- }
80
- return text;
81
- };
82
- // `#![cfg(test)]` at the top of a file or module body gates everything below it. tree-sitter-rust
83
- // tokenizes a file-leading `#!...` as `shebang`; a real shebang line never matches CFG_TEST_RE.
84
- const innerCfgTest = (body) => (body?.namedChildren || [])
85
- .some((child) => (child.type === "inner_attribute_item" || child.type === "shebang") && CFG_TEST_RE.test(child.text));
86
- const underCfgTest = (node) => {
87
- for (let parent = node?.parent; parent; parent = parent.parent) {
88
- if (parent.type === "declaration_list" && innerCfgTest(parent)) return true;
89
- if (CFG_TEST_CARRIERS.has(parent.type) && CFG_TEST_RE.test(itemAttributeText(parent))) return true;
90
- if (!parent.parent && innerCfgTest(parent)) return true; // source_file root
91
- }
92
- return false;
93
- };
94
-
95
- function inlineAncestors(node) {
96
- const result = [];
97
- for (let p = node?.parent; p; p = p.parent) {
98
- if (p.type !== "declaration_list" || p.parent?.type !== "mod_item") continue;
99
- const mod = p.parent;
100
- const name = mod.namedChildren.find((child) => child.type === "identifier")?.text;
101
- if (name) result.unshift({ name: cleanSegment(name), path: pathAttribute(mod) });
102
- }
103
- return result;
104
- }
105
-
106
- // Expand a Rust use tree into its leaf paths while retaining aliases. Examples:
107
- // `crate::api::{self, Client as C, types::*}` -> api, api::Client, api::types.
108
- function useLeaves(node, prefix = []) {
109
- if (!node) return [];
110
- if (node.type === "use_declaration") {
111
- const body = node.namedChildren.find((child) => child.type !== "visibility_modifier");
112
- return useLeaves(body, prefix);
113
- }
114
- if (node.type === "use_list") return node.namedChildren.flatMap((child) => useLeaves(child, prefix));
115
- if (node.type === "scoped_use_list") {
116
- const list = node.namedChildren.find((child) => child.type === "use_list");
117
- const head = node.namedChildren.find((child) => child !== list);
118
- return useLeaves(list, [...prefix, ...pathParts(head)]);
119
- }
120
- if (node.type === "use_as_clause") {
121
- const named = node.namedChildren;
122
- const alias = cleanSegment(named[named.length - 1]?.text);
123
- return useLeaves(named[0], prefix).map((leaf) => ({ ...leaf, local: alias }));
124
- }
125
- if (node.type === "use_wildcard") {
126
- return [{ segments: [...prefix, ...pathParts(node.namedChildren[0])], wildcard: true, local: null }];
127
- }
128
- if (node.type === "self") {
129
- const local = [...prefix].reverse().find((part) => !["crate", "self", "super"].includes(part)) || null;
130
- return [{ segments: prefix.length ? [...prefix] : ["self"], moduleSelf: true, local }];
131
- }
132
- if (["identifier", "scoped_identifier", "scoped_type_identifier", "crate", "super"].includes(node.type)) {
133
- const own = pathParts(node);
134
- const segments = [...prefix, ...own];
135
- const local = [...own].reverse().find((part) => !["crate", "self", "super"].includes(part)) || null;
136
- return [{ segments, local }];
137
- }
138
- return [];
139
- }
140
-
141
- export default {
142
- family: "rust",
143
- grammars: ["rust"],
144
- exts: { ".rs": "rust" },
145
- isWeb: false,
146
- // Bare `foo()` and method `x.foo()` calls resolve by name in the generic pass-2 loop. Scoped
147
- // `Path::foo()` calls are handled in pass2() below with the full qualifier in hand, so an external
148
- // `OpenOptions::new()` cannot bind its bare `new` to an unrelated same-named function in the folder.
149
- calls: `
150
- (call_expression function: (identifier) @callee)
151
- (call_expression function: (field_expression field: (field_identifier) @callee))`,
152
- heritage: [
153
- `(impl_item trait: (type_identifier) @super)`,
154
- `(impl_item trait: (generic_type type: (type_identifier) @super))`,
155
- ],
156
-
157
- pass1(ctx) {
158
- const { grammar, tree, fileRel, caps, field, addSym, addImportEdge, addExternalImport, imports, resolveRustMod, resolveRustPath, resolveRustCratePath, links, nameToId } = ctx;
159
- const owned = [];
160
- for (const src of [SYMS_CORE, ...SYMS_OPTIONAL]) {
161
- for (const cap of caps(grammar, src, tree.rootNode)) {
162
- const declaration = cap.node.parent;
163
- const owner = cap.name === "function" ? ancestor(cap.node, memberOwners) : null;
164
- const memberOf = ownerName(owner, field);
165
- const symbolKind = cap.name === "function" ? (memberOf ? "method" : "function") : cap.name;
166
- const visibility = publicVisibility(declaration, owner);
167
- const attrs = itemAttributeText(declaration);
168
- const testSurface = CFG_TEST_RE.test(attrs)
169
- || (cap.name === "function" && TEST_FN_ATTR_RE.test(attrs))
170
- || underCfgTest(declaration);
171
- const id = addSym(cap.node.text, cap.node.startPosition.row + 1, cap.name === "function", {
172
- sourceNode: declaration,
173
- selectionNode: cap.node,
174
- symbolKind,
175
- ...(testSurface ? { testSurface: true } : {}),
176
- ...(memberOf ? { memberOf, visibility } : { moduleDeclaration: true }),
177
- ...(!memberOf && visibility === "public" ? { exported: true } : {}),
178
- });
179
- if (id && memberOf) owned.push({owner: memberOf, id});
180
- }
181
- }
182
- for (const member of owned) {
183
- const ownerId = nameToId.get(member.owner);
184
- if (ownerId && ownerId !== member.id) links.push({source: ownerId, target: member.id, relation: "method", confidence: "EXTRACTED"});
185
- }
186
-
187
- // File dependency edges are intentionally unique per source/target/relation. A qualified path can be
188
- // nested in another qualified path and often repeats an existing `mod`/`use`; counting occurrences would
189
- // inflate module coupling without adding structure.
190
- const emitted = new Set();
191
- // Names bound into this file's scope by `use` (module aliases and imported items), tracked even when the
192
- // used path did not resolve to a repo file, so later `alias::item` paths are not re-read as external crates.
193
- const localBindings = new Set();
194
- const emit = (target, meta = {}) => {
195
- if (!target || target === fileRel) return;
196
- const relation = meta.relation || "imports";
197
- const key = relation + ">" + target;
198
- if (emitted.has(key)) return;
199
- emitted.add(key);
200
- // Rust `mod`/`use`/`pub use` relationships are resolved by the compiler. They describe real
201
- // architectural coupling, but they are not runtime module loading and therefore must not create
202
- // JavaScript-style initialization cycles or runtime boundary/blast-radius findings.
203
- addImportEdge(target, { ...meta, relation, compileOnly: true });
204
- };
205
-
206
- // `mod foo;` loads foo.rs or foo/mod.rs. Inline `mod foo { ... }` stays in the current file, but any
207
- // outlined modules declared inside it are captured separately with their inline ancestor path.
208
- for (const cap of caps(grammar, `(mod_item) @mod`, tree.rootNode)) {
209
- const mod = cap.node;
210
- const name = mod.namedChildren.find((child) => child.type === "identifier")?.text;
211
- if (name) localBindings.add(cleanSegment(name)); // a declared child module shadows any same-named crate
212
- if (mod.namedChildren.some((child) => child.type === "declaration_list")) continue;
213
- if (!name) continue;
214
- const target = resolveRustMod(fileRel, cleanSegment(name), {
215
- inlineModules: inlineAncestors(mod),
216
- explicitPath: pathAttribute(mod),
217
- });
218
- emit(target, { line: mod.startPosition.row + 1, specifier: `mod ${name}` });
219
- }
220
-
221
- // Imports/re-exports may be nested trees and aliases. Besides the file edge, retain direct item aliases
222
- // so the existing pass-2 call resolver can connect `use crate::worker::run; run()` across folders.
223
- for (const cap of caps(grammar, `(use_declaration) @use`, tree.rootNode)) {
224
- const use = cap.node;
225
- const relation = use.namedChildren.some((child) => child.type === "visibility_modifier") ? "re_exports" : "imports";
226
- const ancestors = inlineAncestors(use);
227
- for (const leaf of useLeaves(use)) {
228
- // A `use` alias or imported item name shadows any same-named crate for the rest of this file. The
229
- // crate's OWN root name (e.g. `use anyhow::{self}`) is excluded so it still counts as a dependency.
230
- if (leaf.local && leaf.local !== "_" && cleanSegment(leaf.local) !== cleanSegment(leaf.segments[0])) localBindings.add(cleanSegment(leaf.local));
231
- const crate = cleanSegment(leaf.segments[0]);
232
- let resolved = resolveRustPath(fileRel, leaf.segments, { inlineModules: ancestors, unqualified: true });
233
- // A head that is not a local module may be a sibling workspace crate (`use radiochron::wlan`):
234
- // resolve it INTO that crate so its items bind here and cross-crate calls resolve in pass 2. It is
235
- // still recorded as a dependency import so the sibling crate is not flagged an unused Cargo dep.
236
- if (!resolved && resolveRustCratePath && isExternalCrate(crate, localBindings)) {
237
- resolved = resolveRustCratePath(crate, leaf.segments.slice(1));
238
- if (resolved) addExternalImport({ spec: leaf.segments.join("::"), pkg: crate.replace(/_/g, "-"), builtin: false, ecosystem: "crates.io", kind: "rust-use", line: use.startPosition.row + 1 });
239
- }
240
- if (!resolved) {
241
- if (isExternalCrate(crate, localBindings)) {
242
- addExternalImport({ spec: leaf.segments.join("::"), pkg: crate.replace(/_/g, "-"), builtin: false, ecosystem: "crates.io", kind: "rust-use", line: use.startPosition.row + 1 });
243
- }
244
- continue;
245
- }
246
- emit(resolved.targetFile, { relation, line: use.startPosition.row + 1, specifier: use.text.replace(/;\s*$/, "") });
247
- if (!leaf.wildcard && leaf.local && leaf.local !== "_") {
248
- const imported = resolved.remaining.length ? cleanSegment(resolved.remaining.at(-1)) : "*";
249
- imports.set(cleanSegment(leaf.local), { imported, targetFile: resolved.targetFile, rustModule: imported === "*" });
250
- }
251
- }
252
- }
253
-
254
- // Fully-qualified paths need no `use` declaration but still prove a dependency. Restrict this pass to
255
- // explicit crate/self/super anchors so associated paths such as `Type::method` cannot be mistaken for a
256
- // same-named module file. Inner prefixes are skipped; only the maximal path emits an edge.
257
- for (const cap of caps(grammar, `[(scoped_identifier) (scoped_type_identifier)] @path`, tree.rootNode)) {
258
- const node = cap.node;
259
- if (under(node, "use_declaration")) continue;
260
- if (["scoped_identifier", "scoped_type_identifier"].includes(node.parent?.type)) continue;
261
- const segments = pathParts(node);
262
- if (!["crate", "self", "super"].includes(segments[0])) {
263
- const crate = cleanSegment(segments[0]);
264
- // A fully-qualified sibling-crate path (`radiochron::events::recent`) is a real cross-crate
265
- // dependency: emit the file edge AND record the dependency import so the sibling crate still
266
- // counts as used, rather than being logged as an external crates.io crate.
267
- const crateResolved = resolveRustCratePath && isExternalCrate(crate, localBindings)
268
- ? resolveRustCratePath(crate, segments.slice(1))
269
- : null;
270
- if (crateResolved) {
271
- emit(crateResolved.targetFile, { line: node.startPosition.row + 1, specifier: node.text });
272
- addExternalImport({ spec: segments.join("::"), pkg: crate.replace(/_/g, "-"), builtin: false, ecosystem: "crates.io", kind: "rust-path", line: node.startPosition.row + 1 });
273
- } else if (isExternalCrate(crate, localBindings)) {
274
- addExternalImport({ spec: segments.join("::"), pkg: crate.replace(/_/g, "-"), builtin: false, ecosystem: "crates.io", kind: "rust-path", line: node.startPosition.row + 1 });
275
- }
276
- continue;
277
- }
278
- const resolved = resolveRustPath(fileRel, segments, { inlineModules: inlineAncestors(node), unqualified: false });
279
- if (!resolved) continue;
280
- emit(resolved.targetFile, { line: node.startPosition.row + 1, specifier: node.text });
281
- const finalName = cleanSegment(segments.at(-1));
282
- if (resolved.remaining.length && finalName && !imports.has(finalName)) {
283
- imports.set(finalName, { imported: finalName, targetFile: resolved.targetFile, rustQualified: true });
284
- }
285
- }
286
-
287
- for (const cap of caps(grammar, `(extern_crate_declaration name: (identifier) @crate)`, tree.rootNode)) {
288
- const crate = cleanSegment(cap.node.text);
289
- if (crate && !["std", "core", "alloc"].includes(crate)) {
290
- addExternalImport({ spec: crate, pkg: crate.replace(/_/g, "-"), builtin: false, ecosystem: "crates.io", kind: "rust-extern-crate", line: cap.node.startPosition.row + 1 });
291
- }
292
- }
293
- },
294
-
295
- // Scoped `Path::method()` calls are resolved in lang-rust-calls.js with the full qualifier in hand.
296
- pass2(ctx) {
297
- rustScopedCalls(ctx, { pathParts, inlineAncestors });
298
- },
299
- };
@@ -1,126 +0,0 @@
1
- // Solidity extractor. Symbols: contract/interface/library (space "both" so `is Base` heritage and
2
- // `new Vault()` both resolve through the value-space resolver), functions/constructors/modifiers/
3
- // events/errors/structs/enums/state vars (members carry memberOf + visibility). Imports: relative
4
- // paths, Foundry remappings (remappings.txt / foundry.toml), and root-anchored specs resolve to repo
5
- // files; everything else (npm-style @openzeppelin/…, absent lib/ submodules) is RECORDED as an
6
- // external import for dependency analysis. Calls: bare `f()`, modifier invocations, `emit Event(…)`,
7
- // `new Contract(…)`, and `using Lib for T` all feed the calls resolver. Same-dir symbols share scope
8
- // (see sharesDirScope): Solidity's flat project namespace makes plain `import "./Base.sol"` — which
9
- // names no symbols — resolvable for siblings without guessing; cross-dir plain imports still produce
10
- // the file-level import edge, so blast radius stays correct even where symbol edges are unknowable.
11
- import { specToPkg } from "./spec-pkg.js";
12
-
13
- const CONTAINERS = new Set(["contract_declaration", "interface_declaration", "library_declaration"]);
14
- const KIND_BY_CONTAINER = {
15
- contract_declaration: "contract",
16
- interface_declaration: "interface",
17
- library_declaration: "library",
18
- };
19
- // external/public functions are the deployed ABI — callable by any transaction, not just repo code.
20
- const VISIBILITY = { external: "public", public: "public", internal: "protected", private: "private" };
21
-
22
- function enclosingContainer(node) {
23
- for (let parent = node?.parent; parent; parent = parent.parent) {
24
- if (CONTAINERS.has(parent.type)) return parent;
25
- }
26
- return null;
27
- }
28
-
29
- const identifierOf = (node) => node?.namedChildren?.find((child) => child.type === "identifier") || null;
30
- const childOfType = (node, type) => node?.namedChildren?.find((child) => child.type === type) || null;
31
- const parameterCount = (node) => (node?.namedChildren || []).filter((child) => child.type === "parameter").length;
32
-
33
- export default {
34
- family: "solidity",
35
- grammars: ["solidity"],
36
- exts: { ".sol": "solidity" },
37
- isWeb: false,
38
- calls: `[(call_expression (identifier) @callee) (modifier_invocation (identifier) @callee) (emit_statement (identifier) @callee) (new_expression (type_name (user_defined_type (identifier) @callee))) (using_directive (type_alias (identifier) @callee))]`,
39
- heritage: [`(inheritance_specifier (user_defined_type (identifier) @base))`],
40
-
41
- pass1(ctx) {
42
- const { grammar, tree, fileRel, caps, addSym, addImportEdge, addExternalImport, imports, links, nameToId, resolveSolidityImport } = ctx;
43
-
44
- // ---- containers (contract/interface/library) ----
45
- for (const cap of caps(grammar, `[(contract_declaration (identifier) @c) (interface_declaration (identifier) @c) (library_declaration (identifier) @c)]`, tree.rootNode)) {
46
- addSym(cap.node.text, cap.node.startPosition.row + 1, false, {
47
- sourceNode: cap.node.parent,
48
- selectionNode: cap.node,
49
- symbolKind: KIND_BY_CONTAINER[cap.node.parent.type],
50
- symbolSpace: "both",
51
- exported: true,
52
- moduleDeclaration: true,
53
- });
54
- }
55
-
56
- // ---- functions (free + members), constructors, modifiers ----
57
- const ownedMembers = [];
58
- const addMember = (name, node, selection, extra) => {
59
- const container = enclosingContainer(node);
60
- const ownerName = container ? identifierOf(container)?.text || null : null;
61
- const id = addSym(name, (selection || node).startPosition.row + 1, extra.callable !== false, {
62
- sourceNode: node,
63
- selectionNode: selection || undefined,
64
- ...(ownerName ? { memberOf: ownerName } : { exported: true, moduleDeclaration: true }),
65
- ...extra,
66
- });
67
- if (ownerName && id) ownedMembers.push({ ownerName, id });
68
- return id;
69
- };
70
- for (const cap of caps(grammar, `(function_definition (identifier) @fn)`, tree.rootNode)) {
71
- const definition = cap.node.parent;
72
- const visibility = VISIBILITY[childOfType(definition, "visibility")?.text || ""];
73
- addMember(cap.node.text, definition, cap.node, {
74
- symbolKind: enclosingContainer(definition) ? "method" : "function",
75
- ...(visibility ? { visibility } : {}),
76
- parameterCount: parameterCount(definition),
77
- });
78
- }
79
- for (const cap of caps(grammar, `(constructor_definition) @ctor`, tree.rootNode))
80
- addMember("constructor", cap.node, null, { symbolKind: "constructor", parameterCount: parameterCount(cap.node) });
81
- for (const cap of caps(grammar, `(modifier_definition (identifier) @m)`, tree.rootNode))
82
- addMember(cap.node.text, cap.node.parent, cap.node, { symbolKind: "modifier", parameterCount: parameterCount(cap.node.parent) });
83
-
84
- // ---- data/type declarations ----
85
- for (const cap of caps(grammar, `[(event_definition (identifier) @n) (error_declaration (identifier) @n)]`, tree.rootNode))
86
- addMember(cap.node.text, cap.node.parent, cap.node, { callable: false, symbolKind: cap.node.parent.type === "event_definition" ? "event" : "error" });
87
- for (const cap of caps(grammar, `[(struct_declaration (identifier) @n) (enum_declaration (identifier) @n)]`, tree.rootNode))
88
- addMember(cap.node.text, cap.node.parent, cap.node, { callable: false, symbolKind: cap.node.parent.type === "struct_declaration" ? "struct" : "enum", symbolSpace: "both" });
89
- // capture the DECLARATION and take its first identifier child (the name): an initializer such as
90
- // `uint x = OTHER_CONST;` can place a second bare identifier under the same declaration node.
91
- for (const cap of caps(grammar, `(constant_variable_declaration) @d`, tree.rootNode)) {
92
- const name = identifierOf(cap.node);
93
- if (name) addMember(name.text, cap.node, name, { callable: false, symbolKind: "constant" });
94
- }
95
- for (const cap of caps(grammar, `(state_variable_declaration) @d`, tree.rootNode)) {
96
- const name = identifierOf(cap.node);
97
- const visibility = VISIBILITY[childOfType(cap.node, "visibility")?.text || ""] || "protected"; // Solidity default: internal
98
- if (name) addMember(name.text, cap.node, name, { callable: false, symbolKind: "variable", visibility });
99
- }
100
- for (const member of ownedMembers) {
101
- const ownerId = nameToId.get(member.ownerName);
102
- if (ownerId) links.push({ source: ownerId, target: member.id, relation: "contains", confidence: "EXTRACTED" });
103
- }
104
-
105
- // ---- imports ----
106
- for (const cap of caps(grammar, `(import_directive) @imp`, tree.rootNode)) {
107
- const specNode = childOfType(cap.node, "string");
108
- if (!specNode) continue;
109
- const spec = specNode.text.replace(/^["']|["']$/g, "");
110
- const line = specNode.startPosition.row + 1;
111
- const target = resolveSolidityImport(fileRel, spec);
112
- if (target) {
113
- addImportEdge(target, { specifier: spec, line });
114
- // `import {A, B} from "./x.sol"` — bind each named symbol. A lone identifier may instead be a
115
- // `* as Alias` namespace name; binding it the same way is harmless (no same-named symbol → no edge).
116
- for (const named of cap.node.namedChildren.filter((child) => child.type === "identifier"))
117
- imports.set(named.text, { imported: named.text, targetFile: target });
118
- continue;
119
- }
120
- if (spec.startsWith(".")) { addExternalImport({ spec, kind: "sol-import", line, unresolved: true }); continue; }
121
- const r = specToPkg(spec);
122
- if (r) addExternalImport({ spec, pkg: r.pkg, builtin: false, kind: "sol-import", line });
123
- else addExternalImport({ spec, kind: "sol-import", line, unresolved: true });
124
- }
125
- },
126
- };