weavatrix 0.3.13 → 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 (303) 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 -65
  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.2.md +0 -15
  28. package/docs/releases/v0.3.3.md +0 -25
  29. package/docs/releases/v0.3.4.md +0 -40
  30. package/docs/releases/v0.3.5.md +0 -50
  31. package/docs/releases/v0.3.6.md +0 -44
  32. package/docs/releases/v0.3.7.md +0 -37
  33. package/docs/releases/v0.3.8.md +0 -21
  34. package/docs/releases/v0.3.9.md +0 -36
  35. package/scripts/run-agent-task-benchmark.mjs +0 -118
  36. package/src/analysis/allowed-test-runner.js +0 -70
  37. package/src/analysis/architecture/contract-graph.js +0 -119
  38. package/src/analysis/architecture/contract-schema.js +0 -110
  39. package/src/analysis/architecture/contract-storage.js +0 -35
  40. package/src/analysis/architecture/contract-verification.js +0 -168
  41. package/src/analysis/architecture-contract.js +0 -16
  42. package/src/analysis/audit-debt.js +0 -94
  43. package/src/analysis/audit-extensions.js +0 -60
  44. package/src/analysis/cargo-dependency-evidence.js +0 -108
  45. package/src/analysis/cargo-manifests.js +0 -81
  46. package/src/analysis/change-classification/diff-parser.js +0 -103
  47. package/src/analysis/change-classification/options.js +0 -40
  48. package/src/analysis/change-classification/symbol-classifier.js +0 -177
  49. package/src/analysis/change-classification.js +0 -188
  50. package/src/analysis/coverage-reports.js +0 -235
  51. package/src/analysis/cycle-route.js +0 -14
  52. package/src/analysis/data-flow-evidence.js +0 -114
  53. package/src/analysis/dead-check.js +0 -300
  54. package/src/analysis/dead-code-review/candidates.js +0 -194
  55. package/src/analysis/dead-code-review/policy.js +0 -23
  56. package/src/analysis/dead-code-review.js +0 -119
  57. package/src/analysis/dep-check-ecosystems.js +0 -205
  58. package/src/analysis/dep-check.js +0 -290
  59. package/src/analysis/dep-rules.js +0 -10
  60. package/src/analysis/dependency/conventions.js +0 -16
  61. package/src/analysis/dependency/scoped-dependencies.js +0 -51
  62. package/src/analysis/dependency/source-references.js +0 -21
  63. package/src/analysis/duplicate-groups.js +0 -104
  64. package/src/analysis/duplicates-worker.js +0 -11
  65. package/src/analysis/duplicates.compute.js +0 -269
  66. package/src/analysis/duplicates.js +0 -15
  67. package/src/analysis/duplicates.run.js +0 -52
  68. package/src/analysis/duplicates.tokenize.js +0 -199
  69. package/src/analysis/endpoints/common.js +0 -62
  70. package/src/analysis/endpoints/extract.js +0 -107
  71. package/src/analysis/endpoints/inventory.js +0 -84
  72. package/src/analysis/endpoints/mounts.js +0 -129
  73. package/src/analysis/endpoints-java.js +0 -260
  74. package/src/analysis/endpoints-rust.js +0 -124
  75. package/src/analysis/endpoints.js +0 -3
  76. package/src/analysis/findings.js +0 -70
  77. package/src/analysis/git-history/analytics.js +0 -177
  78. package/src/analysis/git-history/collector.js +0 -67
  79. package/src/analysis/git-history/options.js +0 -66
  80. package/src/analysis/git-history.js +0 -143
  81. package/src/analysis/git-ref-graph.js +0 -76
  82. package/src/analysis/go-dependency-evidence.js +0 -62
  83. package/src/analysis/graph-analysis.aggregate.js +0 -295
  84. package/src/analysis/graph-analysis.edges.js +0 -24
  85. package/src/analysis/graph-analysis.js +0 -7
  86. package/src/analysis/graph-analysis.refs.js +0 -154
  87. package/src/analysis/graph-analysis.summaries.js +0 -65
  88. package/src/analysis/health-capabilities.js +0 -83
  89. package/src/analysis/hot-path-review.js +0 -266
  90. package/src/analysis/http-contract-wrappers.js +0 -241
  91. package/src/analysis/http-contracts/analysis.js +0 -179
  92. package/src/analysis/http-contracts/client-call-detection.js +0 -82
  93. package/src/analysis/http-contracts/client-call-parser.js +0 -273
  94. package/src/analysis/http-contracts/graph-context.js +0 -143
  95. package/src/analysis/http-contracts/matching.js +0 -61
  96. package/src/analysis/http-contracts/shared.js +0 -85
  97. package/src/analysis/http-contracts.js +0 -6
  98. package/src/analysis/internal-audit/dependency-health.js +0 -113
  99. package/src/analysis/internal-audit/python-manifests.js +0 -78
  100. package/src/analysis/internal-audit/repo-files.js +0 -50
  101. package/src/analysis/internal-audit/supply-chain.js +0 -149
  102. package/src/analysis/internal-audit.collect.js +0 -213
  103. package/src/analysis/internal-audit.js +0 -9
  104. package/src/analysis/internal-audit.reach.js +0 -173
  105. package/src/analysis/internal-audit.run.js +0 -256
  106. package/src/analysis/java-source.js +0 -36
  107. package/src/analysis/jvm-artifact-index.js +0 -87
  108. package/src/analysis/jvm-dependency-evidence.js +0 -138
  109. package/src/analysis/jvm-manifests.js +0 -114
  110. package/src/analysis/manifests.js +0 -123
  111. package/src/analysis/package-reachability.js +0 -39
  112. package/src/analysis/source-complexity.ast.js +0 -97
  113. package/src/analysis/source-complexity.constants.js +0 -55
  114. package/src/analysis/source-complexity.js +0 -14
  115. package/src/analysis/source-complexity.report.js +0 -81
  116. package/src/analysis/source-complexity.walk.js +0 -228
  117. package/src/analysis/source-correctness/retry-patterns.js +0 -93
  118. package/src/analysis/source-correctness.js +0 -222
  119. package/src/analysis/static-test-reachability.js +0 -150
  120. package/src/analysis/structure/dependency-graph.js +0 -151
  121. package/src/analysis/structure/findings.js +0 -162
  122. package/src/analysis/task-retrieval.js +0 -107
  123. package/src/analysis/transport-contracts.js +0 -224
  124. package/src/analysis/transport-runtime-evidence.js +0 -155
  125. package/src/analysis-kit.mjs +0 -17
  126. package/src/bounds.js +0 -4
  127. package/src/build-graph.js +0 -209
  128. package/src/child-env.js +0 -7
  129. package/src/config.js +0 -5
  130. package/src/extension/local-services.mjs +0 -75
  131. package/src/git-exec.js +0 -67
  132. package/src/graph/build-worker.js +0 -49
  133. package/src/graph/builder/go-receiver-resolution.js +0 -112
  134. package/src/graph/builder/js/dynamic-import.js +0 -26
  135. package/src/graph/builder/js/queries.js +0 -48
  136. package/src/graph/builder/lang-csharp.js +0 -40
  137. package/src/graph/builder/lang-css.js +0 -29
  138. package/src/graph/builder/lang-go.js +0 -140
  139. package/src/graph/builder/lang-html.js +0 -29
  140. package/src/graph/builder/lang-java-calls.js +0 -142
  141. package/src/graph/builder/lang-java.js +0 -215
  142. package/src/graph/builder/lang-js.js +0 -291
  143. package/src/graph/builder/lang-python.js +0 -235
  144. package/src/graph/builder/lang-rust-calls.js +0 -63
  145. package/src/graph/builder/lang-rust.js +0 -299
  146. package/src/graph/builder/lang-solidity.js +0 -126
  147. package/src/graph/builder/lang-sql.js +0 -263
  148. package/src/graph/builder/pass2-resolution.js +0 -81
  149. package/src/graph/builder/spec-pkg.js +0 -87
  150. package/src/graph/community.js +0 -27
  151. package/src/graph/edge-provenance.js +0 -31
  152. package/src/graph/file-lock.js +0 -69
  153. package/src/graph/freshness-probe.js +0 -142
  154. package/src/graph/graph-filter.js +0 -63
  155. package/src/graph/incremental-refresh.js +0 -235
  156. package/src/graph/internal-builder.barrels.js +0 -235
  157. package/src/graph/internal-builder.build.js +0 -300
  158. package/src/graph/internal-builder.java.js +0 -33
  159. package/src/graph/internal-builder.js +0 -12
  160. package/src/graph/internal-builder.langs.js +0 -157
  161. package/src/graph/internal-builder.pass2.js +0 -163
  162. package/src/graph/internal-builder.resolvers.js +0 -286
  163. package/src/graph/layout.js +0 -51
  164. package/src/graph/node-id.js +0 -7
  165. package/src/graph/parser-artifact-boundary.js +0 -55
  166. package/src/graph/relations.js +0 -4
  167. package/src/graph/repo-registry.js +0 -124
  168. package/src/graph/resolvers/rust.js +0 -117
  169. package/src/infra/infra-items.js +0 -255
  170. package/src/infra/infra-registry.js +0 -184
  171. package/src/infra/infra.detect.js +0 -119
  172. package/src/infra/infra.js +0 -38
  173. package/src/infra/infra.match.js +0 -102
  174. package/src/infra/infra.scan.js +0 -93
  175. package/src/mcp/actions/graph-lifecycle.mjs +0 -148
  176. package/src/mcp/architecture-bootstrap.mjs +0 -168
  177. package/src/mcp/architecture-starter.mjs +0 -234
  178. package/src/mcp/catalog.mjs +0 -233
  179. package/src/mcp/company-contract-page.mjs +0 -142
  180. package/src/mcp/company-contract-reconcile.mjs +0 -87
  181. package/src/mcp/company-contract-verdict.mjs +0 -42
  182. package/src/mcp/evidence/bun-lock-graph.mjs +0 -209
  183. package/src/mcp/evidence/duplicate-member-order.mjs +0 -8
  184. package/src/mcp/evidence/package-graph-common.mjs +0 -115
  185. package/src/mcp/evidence/package-lock-graph.mjs +0 -92
  186. package/src/mcp/evidence-snapshot.architecture.mjs +0 -80
  187. package/src/mcp/evidence-snapshot.common.mjs +0 -158
  188. package/src/mcp/evidence-snapshot.duplicates.mjs +0 -213
  189. package/src/mcp/evidence-snapshot.health.mjs +0 -102
  190. package/src/mcp/evidence-snapshot.inventory.mjs +0 -148
  191. package/src/mcp/evidence-snapshot.mjs +0 -50
  192. package/src/mcp/evidence-snapshot.package-graph.mjs +0 -34
  193. package/src/mcp/evidence-snapshot.structure.mjs +0 -84
  194. package/src/mcp/extension-api.mjs +0 -77
  195. package/src/mcp/git-output.mjs +0 -7
  196. package/src/mcp/graph/context-core.mjs +0 -111
  197. package/src/mcp/graph/context-seeds.mjs +0 -207
  198. package/src/mcp/graph/context-state.mjs +0 -85
  199. package/src/mcp/graph/reverse-reach.mjs +0 -42
  200. package/src/mcp/graph/tools-core.mjs +0 -143
  201. package/src/mcp/graph/tools-query.mjs +0 -276
  202. package/src/mcp/graph-context.mjs +0 -5
  203. package/src/mcp/graph-diff.mjs +0 -218
  204. package/src/mcp/health/audit-format.mjs +0 -199
  205. package/src/mcp/health/audit.mjs +0 -174
  206. package/src/mcp/health/dead-code.mjs +0 -110
  207. package/src/mcp/health/duplicates.mjs +0 -85
  208. package/src/mcp/health/endpoints.mjs +0 -71
  209. package/src/mcp/health/structure.mjs +0 -219
  210. package/src/mcp/runtime-version.mjs +0 -31
  211. package/src/mcp/server/auto-refresh.mjs +0 -66
  212. package/src/mcp/server/runtime-config.mjs +0 -43
  213. package/src/mcp/server/shutdown.mjs +0 -40
  214. package/src/mcp/staleness-notice.mjs +0 -20
  215. package/src/mcp/sync/evidence-architecture.mjs +0 -54
  216. package/src/mcp/sync/evidence-common.mjs +0 -88
  217. package/src/mcp/sync/evidence-duplicates.mjs +0 -97
  218. package/src/mcp/sync/evidence-health.mjs +0 -56
  219. package/src/mcp/sync/evidence-packages.mjs +0 -95
  220. package/src/mcp/sync/payload-common.mjs +0 -97
  221. package/src/mcp/sync/payload-v2.mjs +0 -54
  222. package/src/mcp/sync/payload-v3.mjs +0 -79
  223. package/src/mcp/sync-evidence.mjs +0 -23
  224. package/src/mcp/sync-payload.mjs +0 -70
  225. package/src/mcp/tool-result.mjs +0 -54
  226. package/src/mcp/tools-actions.mjs +0 -11
  227. package/src/mcp/tools-architecture.mjs +0 -177
  228. package/src/mcp/tools-company.mjs +0 -251
  229. package/src/mcp/tools-context.mjs +0 -222
  230. package/src/mcp/tools-endpoints.mjs +0 -207
  231. package/src/mcp/tools-graph-hubs.mjs +0 -78
  232. package/src/mcp/tools-graph.mjs +0 -17
  233. package/src/mcp/tools-health.mjs +0 -24
  234. package/src/mcp/tools-history.mjs +0 -28
  235. package/src/mcp/tools-impact-change.mjs +0 -220
  236. package/src/mcp/tools-impact-precision.mjs +0 -89
  237. package/src/mcp/tools-impact.mjs +0 -169
  238. package/src/mcp/tools-source.mjs +0 -238
  239. package/src/mcp/tools-verified-change.mjs +0 -200
  240. package/src/mcp-rg.mjs +0 -50
  241. package/src/mcp-runtime.mjs +0 -2
  242. package/src/mcp-server.mjs +0 -298
  243. package/src/mcp-source-tools.mjs +0 -163
  244. package/src/path-classification.js +0 -220
  245. package/src/path-ignore.js +0 -69
  246. package/src/precision/lsp-client/constants.js +0 -12
  247. package/src/precision/lsp-client/environment.js +0 -20
  248. package/src/precision/lsp-client/errors.js +0 -15
  249. package/src/precision/lsp-client/lifecycle.js +0 -114
  250. package/src/precision/lsp-client/message-parser.js +0 -81
  251. package/src/precision/lsp-client/protocol.js +0 -212
  252. package/src/precision/lsp-client/registry.js +0 -59
  253. package/src/precision/lsp-client/repo-uri.js +0 -60
  254. package/src/precision/lsp-client/stdio-client.js +0 -140
  255. package/src/precision/lsp-client.js +0 -10
  256. package/src/precision/lsp-overlay/budget-policy.js +0 -78
  257. package/src/precision/lsp-overlay/build.js +0 -261
  258. package/src/precision/lsp-overlay/contract.js +0 -61
  259. package/src/precision/lsp-overlay/reference-results.js +0 -108
  260. package/src/precision/lsp-overlay/semantic-inputs.js +0 -62
  261. package/src/precision/lsp-overlay/source-session.js +0 -142
  262. package/src/precision/lsp-overlay/store.js +0 -150
  263. package/src/precision/lsp-overlay/target-index.js +0 -152
  264. package/src/precision/lsp-overlay/target-query.js +0 -55
  265. package/src/precision/lsp-overlay.js +0 -11
  266. package/src/precision/symbol-query.js +0 -224
  267. package/src/precision/typescript-lsp-provider.js +0 -12
  268. package/src/precision/typescript-provider/client.js +0 -89
  269. package/src/precision/typescript-provider/discovery.js +0 -124
  270. package/src/precision/typescript-provider/isolated-runtime.js +0 -39
  271. package/src/precision/typescript-provider/project-host.js +0 -254
  272. package/src/precision/typescript-provider/project-safety.js +0 -166
  273. package/src/precision/typescript-provider/reference-usage.js +0 -53
  274. package/src/process.js +0 -95
  275. package/src/repo-path.js +0 -53
  276. package/src/scan/discover.inventory.js +0 -78
  277. package/src/scan/discover.js +0 -5
  278. package/src/scan/discover.list.js +0 -79
  279. package/src/scan/discover.stack.js +0 -227
  280. package/src/scan/search.core.js +0 -24
  281. package/src/scan/search.git.js +0 -102
  282. package/src/scan/search.js +0 -9
  283. package/src/scan/search.node.js +0 -83
  284. package/src/scan/search.preview.js +0 -49
  285. package/src/scan/search.rg.js +0 -145
  286. package/src/security/advisory-store.js +0 -172
  287. package/src/security/installed-jvm-rust.js +0 -46
  288. package/src/security/installed.js +0 -280
  289. package/src/security/malware-file-heuristics.js +0 -121
  290. package/src/security/malware-heuristics.exclusions.js +0 -134
  291. package/src/security/malware-heuristics.js +0 -15
  292. package/src/security/malware-heuristics.roots.js +0 -145
  293. package/src/security/malware-heuristics.scan.js +0 -89
  294. package/src/security/malware-heuristics.sweep.js +0 -122
  295. package/src/security/malware-scoring.js +0 -105
  296. package/src/security/match.js +0 -85
  297. package/src/security/registry-sig.classify.js +0 -137
  298. package/src/security/registry-sig.js +0 -18
  299. package/src/security/registry-sig.rules.js +0 -192
  300. package/src/security/rust-advisory-report.js +0 -60
  301. package/src/security/typosquat.js +0 -81
  302. package/src/util.js +0 -40
  303. package/src/version.js +0 -7
@@ -1,163 +0,0 @@
1
- import {readFileSync} from 'node:fs'
2
- import {extname} from 'node:path'
3
- import {Parser, EXT_LANG, FAMILY, LANGS} from './internal-builder.langs.js'
4
- import {addJavaReferences} from './internal-builder.java.js'
5
- import {resolveJsBarrels} from './internal-builder.barrels.js'
6
- import {createPass2Resolution} from './builder/pass2-resolution.js'
7
- import {createGoReceiverResolution} from './builder/go-receiver-resolution.js'
8
-
9
- export function runInternalGraphPass2({
10
- files, rel, langs, caps, field, links, nodeById, perFileSymbols, symByFileName,
11
- symIdsByFileName, importedLocals, jsExports, resolvers,
12
- }) {
13
- const resolution = createPass2Resolution({symIdsByFileName, nodeById, importedLocals, symByFileName})
14
- const {dirSymbols, resolveNamedSymbol, resolveCall, resolveJavaType, resolveRustMethod} = resolution
15
- const {resolveRustPath, resolveRustCratePath} = resolvers || {}
16
- const {resolveNamespaceMember, reExportOccurrences} = resolveJsBarrels({
17
- jsExports, importedLocals, links,
18
- resolveSymbol: (file, name, typeOnly) => resolveNamedSymbol(file, name, typeOnly ? 'type' : 'value'),
19
- })
20
- const enclosing = (file, line) => {
21
- let best = null
22
- for (const symbol of perFileSymbols.get(file) || []) {
23
- if (line < symbol.start || line > symbol.end) continue
24
- if (!best || symbol.start > best.start || (symbol.start === best.start && symbol.end < best.end)) best = symbol
25
- }
26
- return best
27
- }
28
- const goReceivers = createGoReceiverResolution({resolution, nodeById, importedLocals})
29
- for (const absolute of files) {
30
- const file = rel(absolute), grammar = EXT_LANG[extname(absolute)]
31
- if (!grammar) continue
32
- const lang = LANGS[FAMILY[grammar]]
33
- if (!lang || lang.isWeb || !langs[grammar]) continue
34
- let code
35
- try { code = readFileSync(absolute, 'utf8') } catch { continue }
36
- const parser = new Parser()
37
- parser.setLanguage(langs[grammar])
38
- let tree
39
- try { tree = parser.parse(code) } catch { continue }
40
- if (!lang.customCalls) for (const capture of caps(grammar, lang.calls, tree.rootNode)) {
41
- const caller = enclosing(file, capture.node.startPosition.row + 1)
42
- if (!caller) continue
43
- const target = resolveCall(capture.node.text, file)
44
- if (target && target !== caller.id) links.push({source: caller.id, target, relation: 'calls', confidence: 'INFERRED', line: capture.node.startPosition.row + 1})
45
- }
46
- if (typeof lang.pass2 === 'function') try {
47
- lang.pass2({
48
- grammar, tree, fileRel: file, code, caps, field, enclosing, links, nodeById,
49
- perFileSymbols, symByFileName, symIdsByFileName, importedLocals, resolveCall, resolveJavaType,
50
- dirSymbols, resolveNamedSymbol, resolveRustMethod, resolveRustPath, resolveRustCratePath,
51
- })
52
- } catch { /* one language-specific resolver never sinks the graph */ }
53
- if (lang.selectorCall) for (const capture of caps(grammar, lang.selectorCall, tree.rootNode)) {
54
- const selector = capture.node, operand = field(selector, 'operand'), member = field(selector, 'field')
55
- if (!operand || !member) continue
56
- const caller = enclosing(file, selector.startPosition.row + 1)
57
- if (!caller) continue
58
- const bindings = goReceivers.receiverBindings(selector, file)
59
- const imported = operand.type === 'identifier' && !bindings.has(operand.text)
60
- ? importedLocals.get(file)?.get(operand.text) : null
61
- let target = imported?.targetDir ? dirSymbols.get(imported.targetDir)?.get(member.text) : null
62
- let resolved = !!target
63
- if (!target) {
64
- let receiver = null
65
- if (operand.type === 'identifier') receiver = bindings.get(operand.text) || null
66
- else if (operand.type === 'selector_expression') {
67
- const base = field(operand, 'operand')
68
- const baseType = base?.type === 'identifier' ? bindings.get(base.text) : null
69
- receiver = goReceivers.fieldType(baseType, field(operand, 'field')?.text)
70
- }
71
- target = goReceivers.exactMethod(receiver, member.text)
72
- resolved = !!target
73
- if (!target && !receiver) target = goReceivers.uniqueMethod(goReceivers.dirOf(file), member.text)
74
- }
75
- if (target && target !== caller.id) links.push({
76
- source: caller.id, target, relation: 'calls', confidence: 'INFERRED',
77
- ...(resolved ? {provenance: 'RESOLVED'} : {}), line: selector.startPosition.row + 1,
78
- })
79
- }
80
- for (const heritageSpec of lang.heritage || []) {
81
- const query = typeof heritageSpec === 'string' ? heritageSpec : heritageSpec.query
82
- const relation = typeof heritageSpec === 'string' ? 'inherits' : (heritageSpec.relation || 'inherits')
83
- for (const capture of caps(grammar, query, tree.rootNode)) {
84
- const owner = enclosing(file, capture.node.startPosition.row + 1)
85
- if (!owner) continue
86
- const target = FAMILY[grammar] === 'java' ? resolveJavaType(capture.node.text, file) : resolveCall(capture.node.text, file)
87
- if (target && target !== owner.id) links.push({source: owner.id, target, relation, confidence: 'INFERRED'})
88
- }
89
- }
90
- if (FAMILY[grammar] === 'js') addJavaScriptReferences({
91
- grammar, tree, file, caps, field, importedLocals, resolveNamespaceMember,
92
- resolveNamedSymbol, enclosing, links,
93
- })
94
- if (FAMILY[grammar] === 'go') addGoReferences({
95
- grammar, tree, file, caps, field, importedLocals, dirSymbols, enclosing, links,
96
- })
97
- if (FAMILY[grammar] === 'java') addJavaReferences({grammar, tree, fileRel: file, caps, resolveJavaType, enclosing, links})
98
- tree.delete()
99
- }
100
- return {reExportOccurrences}
101
- }
102
-
103
- function addJavaScriptReferences({grammar, tree, file, caps, field, importedLocals, resolveNamespaceMember, resolveNamedSymbol, enclosing, links}) {
104
- for (const capture of caps(grammar, `(call_expression function: (member_expression) @memberCall)`, tree.rootNode)) {
105
- const object = field(capture.node, 'object'), property = field(capture.node, 'property')
106
- if (!object || object.type !== 'identifier' || !property) continue
107
- const imported = importedLocals.get(file)?.get(object.text)
108
- if (!imported || !['*', 'default'].includes(imported.imported) || imported.typeOnly) continue
109
- const origin = resolveNamespaceMember(file, imported, property.text, 'call')
110
- if (origin.status !== 'resolved') continue
111
- const target = resolveNamedSymbol(origin.origin.file, origin.origin.name, 'value')
112
- const caller = enclosing(file, capture.node.startPosition.row + 1)
113
- if (target && caller && target !== caller.id) links.push({source: caller.id, target, relation: 'calls', confidence: 'INFERRED', line: capture.node.startPosition.row + 1})
114
- }
115
- for (const capture of caps(grammar, `[(jsx_opening_element name: (_) @jsx) (jsx_self_closing_element name: (_) @jsx)]`, tree.rootNode)) {
116
- const parts = capture.node.text.split('.'), localName = parts[0]
117
- if (parts.length === 1 && !/^[A-Z_$]/.test(localName)) continue
118
- const imported = importedLocals.get(file)?.get(localName)
119
- if (!imported?.targetFile || imported.typeOnly) continue
120
- let targetFile = imported.originFile || imported.targetFile
121
- let importedName = imported.originName || imported.imported
122
- if (imported.imported === '*' && parts.length > 1) {
123
- const origin = resolveNamespaceMember(file, imported, parts.at(-1), 'jsx')
124
- if (origin.status === 'resolved') { targetFile = origin.origin.file; importedName = origin.origin.name }
125
- }
126
- const target = resolveNamedSymbol(targetFile, importedName, 'value') || resolveNamedSymbol(targetFile, localName, 'value')
127
- if (!target) continue
128
- const owner = enclosing(file, capture.node.startPosition.row + 1)
129
- links.push({source: owner?.id || file, target, relation: 'references', confidence: 'INFERRED', usage: 'jsx', line: capture.node.startPosition.row + 1})
130
- }
131
- if (grammar === 'javascript') return
132
- for (const capture of caps(grammar, `(type_identifier) @typeRef`, tree.rootNode)) {
133
- const name = capture.node.text, imported = importedLocals.get(file)?.get(name)
134
- const targetFile = imported?.originFile || imported?.targetFile || file
135
- const targetName = imported?.originName || imported?.imported || name
136
- const target = resolveNamedSymbol(targetFile, targetName, 'type')
137
- if (!target || String(target).startsWith(`${file}#${name}@${capture.node.startPosition.row + 1}`)) continue
138
- const source = enclosing(file, capture.node.startPosition.row + 1)?.id || file
139
- if (source !== target) links.push({source, target, relation: 'references', confidence: 'EXTRACTED', provenance: 'RESOLVED', typeOnly: true, line: capture.node.startPosition.row + 1, usage: 'type'})
140
- }
141
- }
142
-
143
- function addGoReferences({grammar, tree, file, caps, field, importedLocals, dirSymbols, enclosing, links}) {
144
- const seen = new Set()
145
- const emit = (source, target) => {
146
- const key = `${source}>${target}`
147
- if (!target || target === source || seen.has(key)) return
148
- seen.add(key); links.push({source, target, relation: 'references', confidence: 'INFERRED'})
149
- }
150
- const dir = file.includes('/') ? file.slice(0, file.lastIndexOf('/')) : '', symbols = dirSymbols.get(dir)
151
- for (const capture of caps(grammar, `[(identifier) (type_identifier)] @id`, tree.rootNode)) {
152
- const target = symbols?.get(capture.node.text)
153
- if (!target || target.slice(0, target.indexOf('#')) === file) continue
154
- emit(enclosing(file, capture.node.startPosition.row + 1)?.id || file, target)
155
- }
156
- for (const capture of caps(grammar, `(selector_expression) @sel`, tree.rootNode)) {
157
- const selector = capture.node, operand = field(selector, 'operand'), member = field(selector, 'field')
158
- if (!operand || operand.type !== 'identifier' || !member) continue
159
- const imported = importedLocals.get(file)?.get(operand.text)
160
- const target = imported?.targetDir && dirSymbols.get(imported.targetDir)?.get(member.text)
161
- if (target) emit(enclosing(file, selector.startPosition.row + 1)?.id || file, target)
162
- }
163
- }
@@ -1,286 +0,0 @@
1
- // Per-repo resolution context shared by the language modules: JS/TS path-aliases + relative imports, Python
2
- // dotted/relative modules, Go package dirs, Rust crate/module paths, Java class files, and web hrefs /
3
- // the CSS selector index.
4
- // (Split from internal-builder.js — see its doc comment for the overall architecture.)
5
- import { readFileSync } from "node:fs";
6
- import { join, dirname } from "node:path";
7
- import { parseGoMod } from "../analysis/manifests.js";
8
- import { parseCargoToml, cargoName } from "../analysis/cargo-manifests.js";
9
- import { createRepoBoundary } from "../repo-path.js";
10
- import { listRepoFiles } from "../analysis/internal-audit/repo-files.js";
11
- import { createRustResolvers } from "./resolvers/rust.js";
12
-
13
- export function buildResolvers(repoDir, fileSet) {
14
- const boundary = createRepoBoundary(repoDir);
15
- const readLocal = (relativePath) => {
16
- const resolved = boundary.resolve(relativePath);
17
- if (!resolved.ok) throw new Error("resolver input is outside the repository");
18
- return readFileSync(resolved.path, "utf8");
19
- };
20
- // Go package = directory (resolved via go.mod module prefix); Java class = file (basename index).
21
- // go.mod requires also feed goSpecToPkg so external Go imports map to their declared module.
22
- let goModule = "";
23
- let goRequires = [];
24
- const goModules = [];
25
- for (const manifest of listRepoFiles(repoDir).filter((file) => /(^|\/)go\.mod$/i.test(file))) {
26
- try {
27
- const gomod = parseGoMod(readLocal(manifest));
28
- if (!gomod.module) continue;
29
- const root = manifest.includes("/") ? manifest.slice(0, manifest.lastIndexOf("/")) : "";
30
- goModules.push({ root, module: gomod.module, requires: gomod.requires.map((item) => item.path) });
31
- } catch { /* unreadable module */ }
32
- }
33
- goModules.sort((left, right) => right.module.length - left.module.length);
34
- goModule = goModules.find((item) => !item.root)?.module || goModules[0]?.module || "";
35
- goRequires = [...new Set(goModules.flatMap((item) => item.requires))];
36
- const dirFiles = new Map();
37
- const filesByBase = new Map();
38
- for (const fr of fileSet) {
39
- const base = fr.split("/").pop();
40
- (filesByBase.get(base) || filesByBase.set(base, []).get(base)).push(fr);
41
- if (fr.endsWith(".go")) { const d = fr.includes("/") ? fr.slice(0, fr.lastIndexOf("/")) : ""; (dirFiles.get(d) || dirFiles.set(d, []).get(d)).push(fr); }
42
- }
43
- const resolveGoImport = (importPath) => {
44
- for (const own of goModules) {
45
- if (importPath !== own.module && !importPath.startsWith(own.module + "/")) continue;
46
- const subpath = importPath === own.module ? "" : importPath.slice(own.module.length + 1);
47
- const d = [own.root, subpath].filter(Boolean).join("/");
48
- if (dirFiles.has(d)) return d;
49
- }
50
- // a module DECLARED in go.mod is external by definition — never let the suffix fallback hijack it
51
- // into a same-named internal dir (pkg/errors/ vs github.com/pkg/errors → false "unused module")
52
- if (goRequires.some((r) => importPath === r || importPath.startsWith(r + "/"))) return null;
53
- const segs = importPath.split("/");
54
- for (const n of [Math.min(2, segs.length), 1]) { const suf = segs.slice(-n).join("/"); for (const d of dirFiles.keys()) if (d === suf || d.endsWith("/" + suf)) return d; }
55
- return null;
56
- };
57
- const resolveJavaImport = (parts) => {
58
- const full = parts.join("/") + ".java", base = parts[parts.length - 1] + ".java";
59
- const cands = filesByBase.get(base) || [];
60
- return cands.find((f) => f === full || f.endsWith("/" + full)) || cands[0] || null;
61
- };
62
-
63
- const { resolveRustMod, resolveRustPath } = createRustResolvers(fileSet);
64
-
65
- // Workspace crate map: normalized package name → its crate source root file (lib.rs/main.rs). A path or
66
- // `use` that starts with a sibling crate's name (`use radiochron::wlan`) then resolves INTO that crate's
67
- // files instead of being logged as an external crates.io dependency — so cross-crate imports and calls
68
- // become real graph edges rather than a false "unused dependency" plus missing coupling.
69
- // Cargo.toml (like go.mod) is a manifest, not a parsed source file, so it is read via listRepoFiles
70
- // rather than the source fileSet. The crate root .rs it points at IS in fileSet (it is parsed).
71
- const rustCrates = new Map();
72
- const ambiguousCrates = new Set();
73
- for (const manifest of listRepoFiles(repoDir).filter((file) => /(^|\/)Cargo\.toml$/i.test(file))) {
74
- let parsed;
75
- try { parsed = parseCargoToml(readLocal(manifest)); } catch { continue; }
76
- if (!parsed.packageName) continue;
77
- const dir = manifest.includes("/") ? manifest.slice(0, manifest.lastIndexOf("/")) : "";
78
- const rootFile = ["src/lib.rs", "src/main.rs", "lib.rs", "main.rs"]
79
- .map((candidate) => [dir, candidate].filter(Boolean).join("/"))
80
- .find((path) => fileSet.has(path));
81
- if (!rootFile) continue;
82
- const key = cargoName(parsed.packageName);
83
- // A repo can hold two crates with the same package name (independent workspaces, vendored copies).
84
- // Cross-crate resolution has no way to pick the right one from a bare `name::path`, so treat the name
85
- // as ambiguous and resolve nothing for it — better a missing edge than a confident wrong one.
86
- if (rustCrates.has(key) && rustCrates.get(key) !== rootFile) ambiguousCrates.add(key);
87
- else rustCrates.set(key, rootFile);
88
- }
89
- // Resolve `<crate>::<segments...>` against the named sibling crate's root, reusing the crate-anchored
90
- // module resolver. Returns {targetFile, remaining} or null when the head is not an unambiguous workspace crate.
91
- const resolveRustCratePath = (crateName, segments = []) => {
92
- const key = cargoName(crateName);
93
- if (ambiguousCrates.has(key)) return null;
94
- const rootFile = rustCrates.get(key);
95
- if (!rootFile) return null;
96
- return resolveRustPath(rootFile, ["crate", ...segments], { unqualified: false });
97
- };
98
-
99
- // Path aliases (tsconfig compilerOptions.paths + vite/webpack alias) are scoped to their config folder.
100
- // Without nearest-config resolution, a monorepo's root `@/*` can hijack the same alias in web/.
101
- const aliasContexts = new Map();
102
- const cleanRel = (p) => String(p || "").replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+/g, "/").replace(/\/$/, "").replace(/^\.$/, "");
103
- const contextFor = (dir) => {
104
- dir = cleanRel(dir);
105
- let ctx = aliasContexts.get(dir);
106
- if (!ctx) aliasContexts.set(dir, (ctx = { dir, aliases: [], baseUrls: [] }));
107
- return ctx;
108
- };
109
- const addAlias = (ctx, a, t) => {
110
- a = String(a).replace(/\/\*$/, "").replace(/\/$/, "");
111
- t = cleanRel(String(t)).replace(/\/\*$/, "");
112
- if (a && t && !ctx.aliases.some((x) => x.alias === a)) ctx.aliases.push({ alias: a, target: t });
113
- };
114
- const parseJsonc = (raw) => {
115
- // Regex comment stripping corrupts perfectly valid path strings such as `"@/*"` followed later by
116
- // `"**/*.ts"`. Strip comments/trailing commas only while outside JSON strings.
117
- raw = String(raw).replace(/^\uFEFF/, "");
118
- let clean = ""; let inString = false; let escaped = false;
119
- for (let i = 0; i < raw.length; i++) {
120
- const ch = raw[i], next = raw[i + 1];
121
- if (inString) {
122
- clean += ch;
123
- if (escaped) escaped = false;
124
- else if (ch === "\\") escaped = true;
125
- else if (ch === '"') inString = false;
126
- continue;
127
- }
128
- if (ch === '"') { inString = true; clean += ch; continue; }
129
- if (ch === "/" && next === "/") { while (i < raw.length && raw[i] !== "\n") i++; clean += "\n"; continue; }
130
- if (ch === "/" && next === "*") {
131
- i += 2;
132
- while (i < raw.length && !(raw[i] === "*" && raw[i + 1] === "/")) { if (raw[i] === "\n") clean += "\n"; i++; }
133
- i++;
134
- continue;
135
- }
136
- clean += ch;
137
- }
138
- let withoutTrailing = ""; inString = false; escaped = false;
139
- for (let i = 0; i < clean.length; i++) {
140
- const ch = clean[i];
141
- if (inString) {
142
- withoutTrailing += ch;
143
- if (escaped) escaped = false;
144
- else if (ch === "\\") escaped = true;
145
- else if (ch === '"') inString = false;
146
- continue;
147
- }
148
- if (ch === '"') { inString = true; withoutTrailing += ch; continue; }
149
- if (ch === ",") {
150
- let j = i + 1; while (/\s/.test(clean[j] || "")) j++;
151
- if (clean[j] === "}" || clean[j] === "]") continue;
152
- }
153
- withoutTrailing += ch;
154
- }
155
- return JSON.parse(withoutTrailing);
156
- };
157
- const configRank = (fr) => /(^|\/)tsconfig\.json$/i.test(fr) ? 0 : /(^|\/)jsconfig\.json$/i.test(fr) ? 1 : 2;
158
- const configFiles = [...fileSet]
159
- .filter((fr) => /(^|\/)(?:tsconfig(?:\.[^/]+)?|jsconfig)\.json$/i.test(fr))
160
- .sort((a, b) => dirname(a).localeCompare(dirname(b)) || configRank(a) - configRank(b) || a.localeCompare(b));
161
- for (const cfg of configFiles) {
162
- try {
163
- const tj = parseJsonc(readLocal(cfg)); const co = tj.compilerOptions || {}; const paths = co.paths || {};
164
- const cfgDir = cleanRel(dirname(cfg)); const ctx = contextFor(cfgDir);
165
- const baseRoot = cleanRel(join(cfgDir || ".", String(co.baseUrl || ".")));
166
- if (co.baseUrl != null && !ctx.baseUrls.includes(baseRoot)) ctx.baseUrls.push(baseRoot);
167
- for (const [k, v] of Object.entries(paths)) {
168
- const t = Array.isArray(v) ? v[0] : v;
169
- if (t) addAlias(ctx, k, join(baseRoot || ".", String(t)));
170
- }
171
- } catch { /* no/invalid tsconfig */ }
172
- }
173
- for (const vc of [...fileSet].filter((fr) => /(^|\/)(?:vite\.config\.(?:ts|js|mjs)|webpack\.config\.js)$/.test(fr))) {
174
- try {
175
- const cfgDir = cleanRel(dirname(vc)); const ctx = contextFor(cfgDir); const src = readLocal(vc);
176
- for (const m of src.matchAll(/['"`]([^'"`]+)['"`]\s*:\s*path\.resolve\([^,]+,\s*['"`]([^'"`]+)['"`]\s*\)/g)) addAlias(ctx, m[1], join(cfgDir || ".", m[2]));
177
- } catch { /* no/invalid bundler config */ }
178
- }
179
- for (const ctx of aliasContexts.values()) ctx.aliases.sort((a, b) => b.alias.length - a.alias.length);
180
- const contextsForFile = (fromRel) => [...aliasContexts.values()]
181
- .filter((ctx) => !ctx.dir || fromRel === ctx.dir || fromRel.startsWith(ctx.dir + "/"))
182
- .sort((a, b) => b.dir.length - a.dir.length);
183
- const resolveAlias = (fromRel, spec) => {
184
- if (spec === undefined) { spec = fromRel; fromRel = ""; }
185
- for (const ctx of contextsForFile(fromRel)) for (const { alias, target } of ctx.aliases) {
186
- if (spec === alias) return target;
187
- if (spec.startsWith(alias + "/")) return target + spec.slice(alias.length);
188
- }
189
- return null;
190
- };
191
-
192
- const JS_EXTS = ["", ".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs", ".json", "/index.js", "/index.ts", "/index.jsx", "/index.tsx"];
193
- const resolveJsBase = (base) => {
194
- for (const extension of JS_EXTS) {
195
- const candidate = (base + extension).replace(/\/+/g, "/");
196
- if (fileSet.has(candidate)) return candidate;
197
- }
198
- // TypeScript NodeNext source commonly imports the emitted extension (`./http.js`) while the
199
- // repository contains `http.ts`/`http.tsx`. Exact runtime files win above; a source counterpart
200
- // is accepted only when unique so same-basename ambiguity is never guessed.
201
- const sourceCandidates = [];
202
- if (/\.js$/i.test(base)) sourceCandidates.push(base.replace(/\.js$/i, ".ts"), base.replace(/\.js$/i, ".tsx"));
203
- else if (/\.jsx$/i.test(base)) sourceCandidates.push(base.replace(/\.jsx$/i, ".tsx"));
204
- const existing = [...new Set(sourceCandidates.map((candidate) => candidate.replace(/\/+/g, "/")))]
205
- .filter((candidate) => fileSet.has(candidate));
206
- return existing.length === 1 ? existing[0] : null;
207
- };
208
- const resolveJsImport = (fromRel, spec) => {
209
- if (!spec) return null;
210
- let base;
211
- if (spec.startsWith(".")) base = join(dirname(fromRel), spec).replace(/\\/g, "/").replace(/^\.\//, "");
212
- else {
213
- base = resolveAlias(fromRel, spec);
214
- if (base == null) {
215
- // baseUrl-rooted internal import ("components/Button" with baseUrl:"src") — try before calling it an npm package
216
- for (const ctx of contextsForFile(fromRel)) for (const b of ctx.baseUrls) {
217
- const root = (b ? b + "/" : "") + spec;
218
- const resolved = resolveJsBase(root);
219
- if (resolved) return resolved;
220
- }
221
- return null; // genuinely bare → npm package (stays unresolved here)
222
- }
223
- }
224
- return resolveJsBase(base);
225
- };
226
-
227
- const resolvePyPath = (baseDir, parts) => {
228
- const p = [baseDir, ...parts].filter(Boolean).join("/").replace(/\/+/g, "/").replace(/^\.\//, "");
229
- // src-layout: absolute imports of the repo's own package live under src/ (PEP 517 convention)
230
- const cands = baseDir ? [p + ".py", p + "/__init__.py"] : [p + ".py", p + "/__init__.py", "src/" + p + ".py", "src/" + p + "/__init__.py"];
231
- for (const cand of cands) if (fileSet.has(cand)) return cand;
232
- return null;
233
- };
234
- const pyBaseDir = (fromRel, dots) => { let d = dots > 0 ? dirname(fromRel) : ""; for (let i = 1; i < dots; i++) d = dirname(d); return d === "." ? "" : d; };
235
- // top-level dirs holding .py files (incl. under src/) — PEP 420 namespace packages have no __init__.py,
236
- // so an absolute import of one resolves to no FILE; knowing the dir exists stops a false "external dep".
237
- const pyTopDirs = new Set();
238
- for (const fr of fileSet) {
239
- if (!fr.endsWith(".py") || !fr.includes("/")) continue;
240
- const seg = fr.split("/");
241
- pyTopDirs.add(seg[0]);
242
- if (seg[0] === "src" && seg.length > 2) pyTopDirs.add(seg[1]);
243
- }
244
-
245
- // Solidity: relative imports, Foundry remappings (remappings.txt beats foundry.toml, longest prefix
246
- // wins), then root-anchored specs (`src/X.sol` — forge resolves those against the project root).
247
- // Nested remapping files are intentionally not scoped per-package: one remapping table per repo is the
248
- // overwhelmingly common layout, and a wrong guess here would fabricate cross-package edges.
249
- const solRemappings = [];
250
- const addRemapping = (entry) => {
251
- const m = /^\s*([^=\s]+)\s*=\s*(\S+)\s*$/.exec(String(entry || ""));
252
- if (m && !solRemappings.some((r) => r.prefix === m[1])) solRemappings.push({ prefix: m[1], target: cleanRel(m[2]) });
253
- };
254
- // neither file has an indexed extension, so probe the filesystem directly rather than fileSet
255
- try { for (const line of readLocal("remappings.txt").split(/\r?\n/)) addRemapping(line); } catch { /* absent/unreadable */ }
256
- try {
257
- const toml = readLocal("foundry.toml");
258
- for (const m of toml.matchAll(/remappings\s*=\s*\[([^\]]*)\]/g)) for (const s of m[1].matchAll(/["']([^"']+)["']/g)) addRemapping(s[1]);
259
- } catch { /* absent/unreadable */ }
260
- solRemappings.sort((a, b) => b.prefix.length - a.prefix.length);
261
- const resolveSolidityImport = (fromRel, spec) => {
262
- if (!spec || !spec.endsWith(".sol")) return null;
263
- if (spec.startsWith(".")) {
264
- const candidate = cleanRel(join(dirname(fromRel), spec));
265
- return fileSet.has(candidate) ? candidate : null;
266
- }
267
- for (const { prefix, target } of solRemappings) {
268
- if (spec !== prefix && !spec.startsWith(prefix)) continue;
269
- const candidate = cleanRel(target + "/" + spec.slice(prefix.length)).replace(/\/+/g, "/");
270
- if (fileSet.has(candidate)) return candidate;
271
- }
272
- return fileSet.has(spec) ? spec : null;
273
- };
274
-
275
- const selectorIndex = new Map();
276
- const htmlUsages = [];
277
- const resolveHref = (fromRel, href) => {
278
- if (!href) return null;
279
- const h = href.split(/[?#]/)[0].replace(/^\.\//, "");
280
- if (/^(https?:)?\/\//.test(h) || h.startsWith("data:") || h.startsWith("#") || h.startsWith("mailto:")) return null;
281
- const cand = h.startsWith("/") ? h.slice(1) : join(dirname(fromRel), h).replace(/\\/g, "/").replace(/^\.\//, "");
282
- return fileSet.has(cand) ? cand : null;
283
- };
284
-
285
- return { resolveJsImport, resolveAlias, resolvePyPath, pyBaseDir, pyTopDirs, resolveGoImport, dirFiles, resolveRustMod, resolveRustPath, resolveRustCratePath, resolveJavaImport, resolveSolidityImport, resolveHref, selectorIndex, htmlUsages, goModule, goModules, goRequires };
286
- }
@@ -1,51 +0,0 @@
1
- // Graph paths + analysis re-exports. This module owns the on-disk graph locations and re-exports the
2
- // pure filter/analysis helpers so callers get everything from one import:
3
- // graph-filter.js — pure graph filters (test-mode, path-scope)
4
- // graph-analysis.js — parse graph.json → file/module/symbol view, hotspots, communities
5
- import { createHash } from "node:crypto";
6
- import { homedir } from "node:os";
7
- import { basename, join, resolve } from "node:path";
8
- import process from "node:process";
9
- import { readdirSync, realpathSync } from "node:fs";
10
-
11
- export * from "./graph-filter.js";
12
- export * from "../analysis/graph-analysis.js";
13
-
14
- // Graphs live in a `weavatrix-graphs/` folder NEXT to the repo (inside the repo's parent folder),
15
- // never inside the repo itself — the graph is derived data, not source. One folder per repo holds
16
- // graph.json plus graph.prev.json (saved by rebuild_graph for graph_diff).
17
- export function graphHomeDir() {
18
- return resolve(process.env.WEAVATRIX_GRAPH_HOME || join(homedir(), ".weavatrix", "graphs"));
19
- }
20
-
21
- export function graphStorageKey(repoPath) {
22
- let absolute;
23
- try { absolute = realpathSync.native(repoPath); }
24
- catch { absolute = resolve(repoPath); }
25
- const normalized = process.platform === "win32" ? absolute.toLowerCase() : absolute;
26
- const slug = (basename(absolute) || "repo").replace(/[^A-Za-z0-9_.-]/g, "_");
27
- const digest = createHash("sha256").update(normalized).digest("hex").slice(0, 12);
28
- return `${slug}-${digest}`;
29
- }
30
-
31
- export function graphOutDirForRepo(repoPath) {
32
- return join(graphHomeDir(), graphStorageKey(repoPath));
33
- }
34
-
35
- // A separate dir for a single module's scoped graph, so it never clobbers the repo's graph.
36
- export function graphOutDirForModule(repoPath, moduleName) {
37
- const safe = String(moduleName).replace(/[^A-Za-z0-9_.-]/g, "_");
38
- return join(graphOutDirForRepo(repoPath), "modules", safe);
39
- }
40
-
41
- // Top-level source folders of a repo (for path-scoped builds).
42
- export function repoTopFolders(repoPath) {
43
- try {
44
- return readdirSync(repoPath, { withFileTypes: true })
45
- .filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !["node_modules", "weavatrix-graphs", "dist", "build", "coverage", "vendor"].includes(entry.name))
46
- .map((entry) => entry.name)
47
- .sort((left, right) => left.localeCompare(right));
48
- } catch {
49
- return [];
50
- }
51
- }
@@ -1,7 +0,0 @@
1
- export const graphEndpointId = (value) => String(value && typeof value === "object" ? value.id : value);
2
-
3
- export const fileOfId = (value) => {
4
- const id = String(value || "");
5
- const hash = id.indexOf("#");
6
- return hash < 0 ? id : id.slice(0, hash);
7
- };
@@ -1,55 +0,0 @@
1
- import {createHash} from 'node:crypto'
2
- import {readFileSync, realpathSync, statSync} from 'node:fs'
3
- import {join} from 'node:path'
4
- import {isPathInside} from '../repo-path.js'
5
-
6
- // Exact SHA-256 allowlist for the parser artifacts shipped by the package-pinned
7
- // web-tree-sitter@0.25.10 and tree-sitter-wasms@0.1.13 dependencies. npm integrity
8
- // protects installation; this second boundary detects replacement or redirection
9
- // before Emscripten compiles a runtime or dynamic language module.
10
- const RUNTIME_SHA256 = 'f38dcc4b43b818f9a0785bc1c6d5611a75ac4cdd428ff3f02757c34ca4e46d7f'
11
- const GRAMMAR_SHA256 = Object.freeze({
12
- javascript: '63812b9e275d26851264734868d27a1656bd44a2ef6eb3e85e6b03728c595ab5',
13
- typescript: '8515404dceed38e1ed86aa34b09fcf3379fff1b4ff9dd3967bcd6d1eb5ac3d8f',
14
- tsx: '6aa3b2c70e76f5d48eafef1093e9c4de383e13f2fdde2f4e9b98a378f6a8f1b6',
15
- python: '9056d0fb0c337810d019fae350e8167786119da98f0f282aceae7ab89ee8253b',
16
- go: '9963ca89b616eaf04b08a43bc1fb0f07b85395bec313330851f1f1ead2f755b6',
17
- java: '637aac4415fb39a211a4f4292d63c66b5ce9c32fa2cd35464af4f681d91b9a1f',
18
- c_sharp: '6266a7e32d68a3459104d994dc848df15d5672b0ea8e86d327274b694f8e6991',
19
- rust: '4409921a70d0aa5bec7d1d7ce809a557a8ee1cf6ace901e3ac6a76e62cfea903',
20
- solidity: '160745e470f234cae903a9ba445d19e758d0b02e1197401fc765976c6254d2b6',
21
- html: '11b3405c1543fb012f5ed7f8ee73125076dce8b168301e1e787e4c717da6b456',
22
- css: '5fc615467b1b98420ed7517e5bf9e1f88468132dd903d842dfb13714f6a1cb0c',
23
- })
24
-
25
- export function verifyParserArtifact({file, root, sha256, label = 'parser artifact'}) {
26
- let rootReal, fileReal
27
- try {
28
- rootReal = realpathSync.native(root)
29
- fileReal = realpathSync.native(file)
30
- } catch {
31
- throw new Error(`${label} is missing or cannot be resolved`)
32
- }
33
- if (!isPathInside(rootReal, fileReal) || !statSync(fileReal).isFile()) {
34
- throw new Error(`${label} resolves outside its pinned package directory`)
35
- }
36
- const actual = createHash('sha256').update(readFileSync(fileReal)).digest('hex')
37
- if (actual !== sha256) throw new Error(`${label} failed the pinned SHA-256 integrity check`)
38
- return fileReal
39
- }
40
-
41
- export function trustedRuntimeWasm(wtsDir) {
42
- return verifyParserArtifact({
43
- file: join(wtsDir, 'tree-sitter.wasm'), root: wtsDir,
44
- sha256: RUNTIME_SHA256, label: 'web-tree-sitter runtime',
45
- })
46
- }
47
-
48
- export function trustedGrammarWasm(wasmDir, grammar) {
49
- const sha256 = GRAMMAR_SHA256[grammar]
50
- if (!sha256) throw new Error(`unsupported tree-sitter grammar: ${grammar}`)
51
- return verifyParserArtifact({
52
- file: join(wasmDir, `tree-sitter-${grammar}.wasm`), root: wasmDir,
53
- sha256, label: `tree-sitter ${grammar} grammar`,
54
- })
55
- }
@@ -1,4 +0,0 @@
1
- // Ownership/nesting edges are useful for navigation, but are not evidence of code usage.
2
- const STRUCTURAL_RELATIONS = new Set(["contains", "method"]);
3
-
4
- export const isStructuralRelation = (relation) => STRUCTURAL_RELATIONS.has(String(relation || ""));