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,123 +0,0 @@
1
- // Pure manifest parsers for the non-npm ecosystems (Go + Python) — text in, declared deps out.
2
- // NO filesystem here (internal-audit.js is the fs wrapper; internal-builder reads go.mod for resolvers).
3
- // Philosophy matches dep-check.js: tolerate real-world files, bias to FALSE-NEGATIVES on weird syntax.
4
-
5
- // pep503(name) — PyPI canonical form: lowercase, runs of -_. collapse to "-" (same as security/installed.js).
6
- export const pep503 = (name) => String(name || "").toLowerCase().replace(/[-_.]+/g, "-");
7
-
8
- // ---- go.mod → { module, requires: [{path, version, indirect}], replaces: [{from, to}] } ----
9
- // Handles single-line `require path v1` and `require ( … )` blocks; `// indirect` marks transitive
10
- // requires (never flagged unused — Go owns them via `go mod tidy`).
11
- export function parseGoMod(text) {
12
- const src = String(text || "");
13
- const out = { module: "", requires: [], replaces: [] };
14
- const m = src.match(/^\s*module\s+(\S+)/m);
15
- if (m) out.module = m[1].replace(/^"|"$/g, "");
16
- const addReq = (line) => {
17
- const r = line.match(/^\s*([^\s()=>]+)\s+(v[\w.+-]+)\s*(\/\/.*)?$/);
18
- if (r) out.requires.push({ path: r[1].replace(/^"|"$/g, ""), version: r[2], indirect: /\/\/\s*indirect/.test(line) });
19
- };
20
- const addRepl = (line) => {
21
- const r = line.match(/^\s*([^\s()=>]+)(?:\s+v[\w.+-]+)?\s*=>\s*(\S+)(?:\s+v[\w.+-]+)?\s*(\/\/.*)?$/);
22
- if (r) out.replaces.push({ from: r[1].replace(/^"|"$/g, ""), to: r[2].replace(/^"|"$/g, "") });
23
- };
24
- for (const dir of ["require", "replace"]) {
25
- const add = dir === "require" ? addReq : addRepl;
26
- for (const blk of src.matchAll(new RegExp(`^\\s*${dir}\\s*\\(([\\s\\S]*?)^\\s*\\)`, "gm"))) for (const line of blk[1].split(/\r?\n/)) add(line);
27
- for (const one of src.matchAll(new RegExp(`^\\s*${dir}\\s+([^(\\r\\n]+)$`, "gm"))) add(one[1]);
28
- }
29
- return out;
30
- }
31
-
32
- // ---- PEP 508 requirement line → dist name (extras/specifiers/markers stripped), or null ----
33
- // "-r other.txt", bare options, paths and URLs are skipped; VCS urls keep their #egg= name if present.
34
- export function requirementName(rawLine) {
35
- const line = String(rawLine || "").replace(/(^|\s)#.*$/, "").trim();
36
- if (!line) return null;
37
- const egg = line.match(/#egg=([A-Za-z0-9][\w.-]*)/i);
38
- if (egg) return egg[1];
39
- if (line.startsWith("-") || /^(git\+|hg\+|svn\+|bzr\+|https?:|file:)/i.test(line) || /^\.{0,2}[\\/]/.test(line) || line === ".") return null;
40
- const m = line.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)/);
41
- return m ? m[1] : null;
42
- }
43
-
44
- // requirements.txt (or *.in) text → [{name}] (unique by canonical name)
45
- export function parseRequirementsNames(text) {
46
- const seen = new Set();
47
- const out = [];
48
- for (const raw of String(text || "").split(/\r?\n/)) {
49
- const name = requirementName(raw);
50
- if (!name || seen.has(pep503(name))) continue;
51
- seen.add(pep503(name));
52
- out.push({ name });
53
- }
54
- return out;
55
- }
56
-
57
- // ---- pyproject.toml → { present, deps: [{name, dev, buildSystem}] } ----
58
- // Line-based section scanner (no TOML dependency): covers PEP 621 [project] dependencies /
59
- // optional-dependencies, Poetry [tool.poetry.*dependencies] tables, PEP 735 [dependency-groups],
60
- // and [build-system] requires (declared-but-implicit → suppresses "missing", never checked "unused").
61
- export function parsePyprojectDeps(text) {
62
- const src = String(text || "");
63
- const deps = [];
64
- const seen = new Set();
65
- const add = (name, dev, buildSystem = false) => {
66
- if (!name || name.toLowerCase() === "python" || seen.has(pep503(name))) return;
67
- seen.add(pep503(name));
68
- deps.push({ name, dev: !!dev, buildSystem });
69
- };
70
- let section = "";
71
- let present = false;
72
- let arr = null; // { dev, buildSystem } while inside a dependencies = [ … ] array
73
- // bracket balance OUTSIDE string literals — "requests[security]" must not close the array
74
- const bracketDelta = (s) => { const t = String(s).replace(/"[^"]*"|'[^']*'/g, ""); return ((t.match(/\[/g) || []).length) - ((t.match(/\]/g) || []).length); };
75
- for (const raw of src.split(/\r?\n/)) {
76
- const line = raw.replace(/(^|\s)#.*$/, "").trimEnd();
77
- const sec = line.match(/^\s*\[+([^\]]+)\]+\s*$/);
78
- if (!arr && sec) { section = sec[1].trim(); continue; }
79
- if (arr) { // inside a multi-line array: pull every string literal
80
- for (const s of line.matchAll(/["']([^"']+)["']/g)) add(requirementName(s[1]), arr.dev, arr.buildSystem);
81
- if (bracketDelta(line) < 0) arr = null;
82
- continue;
83
- }
84
- const kv = line.match(/^\s*([\w."'-]+)\s*=\s*(.*)$/);
85
- if (!kv) continue;
86
- const key = kv[1].replace(/^["']|["']$/g, "");
87
- const val = kv[2].trim();
88
- const startArray = (dev, buildSystem = false) => {
89
- present = true;
90
- for (const s of val.matchAll(/["']([^"']+)["']/g)) add(requirementName(s[1]), dev, buildSystem);
91
- if (bracketDelta(val) > 0) arr = { dev, buildSystem };
92
- };
93
- if (section === "project" && key === "dependencies") startArray(false);
94
- else if (section === "project.optional-dependencies" || section === "dependency-groups") startArray(true);
95
- else if (section === "build-system" && key === "requires") startArray(true, true);
96
- else if (section === "tool.poetry.dependencies") { present = true; add(key, false); }
97
- else if (section === "tool.poetry.dev-dependencies" || /^tool\.poetry\.group\.[^.]+\.dependencies$/.test(section)) { present = true; add(key, true); }
98
- }
99
- return { present, deps };
100
- }
101
-
102
- // ---- Pipfile → { present, deps: [{name, dev}] } — [packages] / [dev-packages] table keys ----
103
- export function parsePipfileDeps(text) {
104
- const deps = [];
105
- const seen = new Set();
106
- let section = "";
107
- let present = false;
108
- for (const raw of String(text || "").split(/\r?\n/)) {
109
- const line = raw.replace(/(^|\s)#.*$/, "").trim();
110
- // Match single [section] and array-of-tables [[section]] headers alike. Without the [[...]] case a
111
- // `[[source]]` table following [packages] would leave section === "packages" and its name/url/verify_ssl
112
- // keys would leak as phantom dependencies (the same blind spot fixed in the Cargo.toml parser).
113
- const sec = line.match(/^\[+([^\]]+)\]+$/);
114
- if (sec) { section = sec[1].trim().toLowerCase(); continue; }
115
- if (section !== "packages" && section !== "dev-packages") continue;
116
- const kv = line.match(/^["']?([A-Za-z0-9][\w.-]*)["']?\s*=/);
117
- if (!kv || seen.has(pep503(kv[1]))) continue;
118
- present = true;
119
- seen.add(pep503(kv[1]));
120
- deps.push({ name: kv[1], dev: section === "dev-packages" });
121
- }
122
- return { present, deps };
123
- }
@@ -1,39 +0,0 @@
1
- // Package-level reachability: correlate a dependency finding with the graph's external imports.
2
- // This is intentionally not function-level exploitability analysis. It only states whether product
3
- // code imports the package and preserves unknown as unknown.
4
- const PACKAGE_REACHABILITY_V = 1
5
-
6
- export function packageReachability(externalImports, packageName, {isNonProductPath = () => false} = {}) {
7
- const imports = (Array.isArray(externalImports) ? externalImports : [])
8
- .filter((item) => item?.pkg === packageName && item.builtin !== true)
9
- .map((item) => ({
10
- file: String(item.file || '').replace(/\\/g, '/'),
11
- line: Number.isInteger(item.line) ? item.line : 0,
12
- kind: String(item.kind || 'import'),
13
- typeOnly: item.typeOnly === true,
14
- dynamic: item.dynamic === true,
15
- }))
16
- .filter((item) => item.file)
17
- const product = imports.filter((item) => !isNonProductPath(item.file))
18
- const runtime = product.filter((item) => !item.typeOnly)
19
- const state = runtime.length
20
- ? 'DIRECT_RUNTIME_IMPORT'
21
- : product.length
22
- ? 'TYPE_ONLY_IMPORT'
23
- : imports.length
24
- ? 'NON_PRODUCT_IMPORT_ONLY'
25
- : 'NOT_OBSERVED_IN_GRAPH'
26
- return {
27
- packageReachabilityV: PACKAGE_REACHABILITY_V,
28
- level: 'package-import',
29
- state,
30
- directRuntimeImports: runtime.length,
31
- directProductImports: product.length,
32
- observedImports: imports.length,
33
- files: [...new Set((runtime.length ? runtime : product.length ? product : imports).map((item) => item.file))].sort().slice(0, 20),
34
- evidence: (runtime.length ? runtime : product.length ? product : imports).slice(0, 10),
35
- note: state === 'NOT_OBSERVED_IN_GRAPH'
36
- ? 'No static import was observed; implicit, dynamic, plugin and transitive runtime use remain unknown.'
37
- : 'Package-level static import evidence; this does not prove vulnerable-function reachability.',
38
- }
39
- }
@@ -1,97 +0,0 @@
1
- // Tree-sitter node helpers shared by the source-complexity analysis modules.
2
-
3
- import { IO_PREFIXES } from "./source-complexity.constants.js";
4
-
5
- export function field(node, name) {
6
- try { return node?.childForFieldName ? node.childForFieldName(name) : null; }
7
- catch { return null; }
8
- }
9
-
10
- export function children(node) {
11
- try { return Array.isArray(node?.namedChildren) ? node.namedChildren : []; }
12
- catch { return []; }
13
- }
14
-
15
- export function allChildren(node) {
16
- try { return Array.isArray(node?.children) ? node.children : children(node); }
17
- catch { return children(node); }
18
- }
19
-
20
- export function sameNode(left, right) {
21
- if (!left || !right) return false;
22
- if (left === right) return true;
23
- if (left.id != null && right.id != null) return left.id === right.id;
24
- return left.type === right.type && left.startIndex === right.startIndex && left.endIndex === right.endIndex;
25
- }
26
-
27
- export function normalizedName(value) {
28
- return String(value || "").replace(/[^A-Za-z0-9_$]+/g, "").toLowerCase();
29
- }
30
-
31
- export function looksLikeIoCall(value) {
32
- const raw = String(value || "");
33
- const lower = raw.toLowerCase();
34
- return IO_PREFIXES.some((prefix) => {
35
- if (!lower.startsWith(prefix)) return false;
36
- const boundary = raw[prefix.length];
37
- return boundary == null || /[A-Z_$]/.test(boundary);
38
- });
39
- }
40
-
41
- export function callName(node) {
42
- const callee = field(node, "function") || field(node, "name") || field(node, "constructor");
43
- if (!callee) return "";
44
- const member = field(callee, "property") || field(callee, "field") || field(callee, "attribute") || field(callee, "name");
45
- return String((member || callee).text || "").replace(/\?$/, "");
46
- }
47
-
48
- export function logicalBranch(node) {
49
- if (!/binary_expression|boolean_operator/.test(String(node?.type || ""))) return false;
50
- return allChildren(node).some((child) => ["&&", "||", "??", "and", "or"].includes(String(child?.type || child?.text || "")));
51
- }
52
-
53
- export function isDefaultCase(node) {
54
- const text = String(node?.text || "").trimStart();
55
- return /^(default\b|case\s+default\b)/i.test(text);
56
- }
57
-
58
- export function directParameterCount(paramNode, family) {
59
- if (!paramNode) return 0;
60
- if (!/parameters|parameter_list|formal_parameters/.test(String(paramNode.type || ""))) {
61
- return /^(self|cls)$/.test(String(paramNode.text || "").trim()) ? 0 : 1;
62
- }
63
- let count = 0;
64
- for (const part of children(paramNode)) {
65
- const type = String(part.type || "");
66
- if (/comment|type_parameter|type_parameters/.test(type)) continue;
67
- if (family === "go" && /parameter_declaration|variadic_parameter_declaration/.test(type)) {
68
- const ids = children(part).filter((child) => /^(identifier|field_identifier)$/.test(String(child.type || "")));
69
- count += Math.max(1, ids.length);
70
- continue;
71
- }
72
- if (/^(self|cls)(\s*[:=].*)?$/.test(String(part.text || "").trim())) continue;
73
- count++;
74
- }
75
- return count;
76
- }
77
-
78
- export function countObjectPatternFields(paramNode) {
79
- if (!paramNode) return 0;
80
- let total = 0;
81
- const visit = (node, depth) => {
82
- if (!node || depth > 5) return;
83
- if (node.type === "object_pattern") {
84
- total += children(node).filter((child) => !/type_annotation|comment/.test(String(child.type || ""))).length;
85
- return;
86
- }
87
- for (const child of children(node)) visit(child, depth + 1);
88
- };
89
- visit(paramNode, 0);
90
- return total;
91
- }
92
-
93
- export function sourceRange(node) {
94
- const startLine = node?.startPosition ? node.startPosition.row + 1 : 0;
95
- const endLine = node?.endPosition ? node.endPosition.row + 1 : startLine;
96
- return { startLine, endLine, loc: startLine ? Math.max(1, endLine - startLine + 1) : 0 };
97
- }
@@ -1,55 +0,0 @@
1
- // Syntax node-type and call-name tables for the source-complexity analysis.
2
-
3
- export const LOOP_NODES = new Set([
4
- "for_statement", "for_in_statement", "for_each_statement", "enhanced_for_statement",
5
- "while_statement", "do_statement", "for_in_clause"
6
- ]);
7
- export const CALL_NODES = new Set(["call", "call_expression", "method_invocation", "object_creation_expression"]);
8
- export const RETURN_NODES = new Set(["return_statement"]);
9
- export const AWAIT_NODES = new Set(["await_expression"]);
10
- export const OBJECT_NODES = new Set(["object", "dictionary", "map", "record_literal"]);
11
- export const FIXED_ALLOCATION_NODES = new Set([
12
- ...OBJECT_NODES,
13
- "array", "list", "set", "tuple", "composite_literal", "new_expression",
14
- "object_creation_expression", "array_creation_expression", "make_expression",
15
- "list_comprehension", "set_comprehension", "dictionary_comprehension"
16
- ]);
17
- export const VARIABLE_ALLOCATION_NODES = new Set(["list_comprehension", "set_comprehension", "dictionary_comprehension"]);
18
- export const SPREAD_NODES = new Set([
19
- "spread_element", "list_splat", "dictionary_splat", "set_splat", "spread_expression"
20
- ]);
21
- export const DECLARATION_BOUNDARIES = new Set([
22
- "function_declaration", "generator_function_declaration", "function_definition",
23
- "method_definition", "method_declaration", "constructor_declaration",
24
- "class_declaration", "class_definition", "interface_declaration", "enum_declaration"
25
- ]);
26
- export const EXPRESSION_CALLABLES = new Set([
27
- "arrow_function", "function_expression", "generator_function", "lambda", "lambda_expression"
28
- ]);
29
- export const ARGUMENT_NODES = new Set(["arguments", "argument_list"]);
30
- export const ITERATOR_CALLS = new Set([
31
- "foreach", "map", "flatmap", "filter", "reduce", "reduceright", "some", "every",
32
- "find", "findindex", "findlast", "findlastindex", "collect", "select"
33
- ]);
34
- export const PRODUCER_CALLS = new Set([
35
- "map", "flatmap", "filter", "slice", "concat", "split", "toarray", "tolist",
36
- "keys", "values", "entries", "fromentries", "from", "copy", "clone", "collect", "make",
37
- "all", "allsettled", "stringify", "parse"
38
- ]);
39
- export const LINEAR_CALLS = new Set([
40
- ...ITERATOR_CALLS,
41
- ...PRODUCER_CALLS,
42
- "includes", "indexof", "lastindexof", "join", "reverse", "stringify", "parse",
43
- "all", "allsettled", "any", "race"
44
- ]);
45
- export const SORT_CALLS = new Set(["sort", "sorted", "sortby", "orderby", "order_by"]);
46
- export const IO_PREFIXES = [
47
- "fetch", "request", "query", "execute", "insert", "update", "delete", "save", "read",
48
- "write", "send", "publish", "consume", "find", "load", "download", "upload", "connect", "transaction"
49
- ];
50
-
51
- export const BRANCH_NODES = new Set([
52
- "if_statement", "elif_clause", "catch_clause", "except_clause", "conditional_expression",
53
- "ternary_expression", "switch_case", "case_statement", "expression_case", "type_case",
54
- "communication_case", "match_case"
55
- ]);
@@ -1,14 +0,0 @@
1
- // AST-backed, language-aware source complexity summary.
2
- //
3
- // This intentionally reports LOCAL algorithmic work separately from calls/I/O. A method with no loop
4
- // can be O(1) locally while its end-to-end latency remains callee-bound; object/array spreads are linear
5
- // shallow copies even without an explicit loop. Reports are plain JSON and are persisted on graph nodes,
6
- // so the renderer never needs a second implementation of the algorithm.
7
- //
8
- // Implementation lives in the sibling modules:
9
- // source-complexity.constants.js — node-type and call-name tables
10
- // source-complexity.ast.js — tree-sitter node helpers
11
- // source-complexity.report.js — rank/label/evidence builders
12
- // source-complexity.walk.js — the syntax walk and summary assembly
13
-
14
- export { analyzeSyntaxComplexity } from "./source-complexity.walk.js";
@@ -1,81 +0,0 @@
1
- // Rank, score, label, and evidence builders for the source-complexity report.
2
-
3
- function timeScore(rank) {
4
- return [0.2, 0.4, 0.65, 0.95, 1.3, 1.7][Math.max(0, Math.min(5, rank))] || 0.2;
5
- }
6
-
7
- function memoryScore(rank) {
8
- return [0.15, 0.35, 0.85, 1.05, 1.4, 1.7][Math.max(0, Math.min(5, rank))] || 0.15;
9
- }
10
-
11
- function plural(n, one, many) {
12
- return `${n} ${n === 1 ? one : many}`;
13
- }
14
-
15
- function deriveTimeRank(stats) {
16
- if (stats.maxLoopDepth >= 3) return 5;
17
- if (stats.maxLoopDepth === 2 || (stats.sorts && stats.maxSortLoopDepth > 0)) return 4;
18
- if (stats.sorts) return 3;
19
- if (stats.loops || stats.linearOps || stats.spreadCopies) return 2;
20
- return 0;
21
- }
22
-
23
- function timeLabelForRank(stats, rank) {
24
- if (stats.recursion) return "recursive local work — bound unknown";
25
- if (rank >= 5) return "O(n^3+) local — deeply nested iteration";
26
- if (rank === 4 && stats.sorts && stats.maxSortLoopDepth > 0) return "O(n^2 log n) local — sort inside iteration";
27
- if (rank === 4) return "O(n^2) local — nested iteration";
28
- if (rank === 3) return "O(n log n) local — sort";
29
- if (rank === 2 && stats.spreadCopies) return `O(n) local — ${plural(stats.spreadCopies, "shallow copy", "shallow copies")}`;
30
- if (rank === 2 && stats.loops) return `O(n) local — ${plural(stats.loops, "iteration", "iterations")}`;
31
- return rank === 2 ? "O(n) local — collection traversal" : "O(1) local";
32
- }
33
-
34
- function buildTimeSummary(stats) {
35
- const timeRank = stats.recursion ? Math.max(2, deriveTimeRank(stats)) : deriveTimeRank(stats);
36
- let timeLabel = timeLabelForRank(stats, timeRank);
37
- if (stats.asyncBoundaries || stats.externalCalls) timeLabel += " · I/O/callee-bound";
38
- else if (stats.callCount && !stats.recursion) timeLabel += " · callee-bound";
39
- if (stats.branches >= 8 && timeRank === 0) timeLabel += " · branch-heavy";
40
- return { timeRank, timeScore: timeScore(timeRank), timeLabel };
41
- }
42
-
43
- function buildMemorySummary(stats) {
44
- let memoryRank = 0;
45
- let memoryLabel = "O(1) auxiliary";
46
- const variableAllocation = stats.spreadCopies || stats.producerCalls;
47
- if (variableAllocation) {
48
- memoryRank = stats.maxVariableAllocationDepth >= 2 ? 4 : 2;
49
- memoryLabel = memoryRank >= 4 ? "O(n^2) — nested collection copies" : stats.spreadCopies
50
- ? `O(n) — ${plural(stats.spreadCopies, "shallow copy", "shallow copies")}`
51
- : "O(n) — produced collection";
52
- } else if (stats.recursion) {
53
- memoryRank = 1;
54
- memoryLabel = "O(depth) stack — recursive";
55
- } else if (stats.allocations) {
56
- memoryLabel = "O(1) auxiliary — fixed allocations";
57
- }
58
- return { memoryRank, memoryScore: memoryScore(memoryRank), memoryLabel };
59
- }
60
-
61
- export function buildLabels(stats) {
62
- return { ...buildTimeSummary(stats), ...buildMemorySummary(stats) };
63
- }
64
-
65
- export function buildEvidence(stats) {
66
- const out = [];
67
- if (stats.loops) out.push(plural(stats.loops, "iteration", "iterations"));
68
- if (stats.maxLoopDepth > 1) out.push(`loop depth ${stats.maxLoopDepth}`);
69
- if (stats.sorts) out.push(plural(stats.sorts, "sort", "sorts"));
70
- if (stats.spreadCopies) out.push(plural(stats.spreadCopies, "shallow copy", "shallow copies"));
71
- if (stats.allocationsInLoops) out.push(`${plural(stats.allocationsInLoops, "allocation", "allocations")} inside iteration`);
72
- if (stats.copiesInLoops) out.push(`${plural(stats.copiesInLoops, "copy", "copies")} inside iteration`);
73
- if (stats.linearOpsInLoops) out.push(`${plural(stats.linearOpsInLoops, "linear operation", "linear operations")} inside iteration`);
74
- if (stats.sortsInLoops) out.push(`${plural(stats.sortsInLoops, "sort", "sorts")} inside iteration`);
75
- if (stats.recursionInLoops) out.push(`${plural(stats.recursionInLoops, "recursive call", "recursive calls")} inside iteration`);
76
- if (stats.branches) out.push(plural(stats.branches, "branch point", "branch points"));
77
- if (stats.awaits) out.push(plural(stats.awaits, "await boundary", "await boundaries"));
78
- if (stats.callCount) out.push(plural(stats.callCount, "call", "calls"));
79
- if (stats.recursion) out.push("direct recursion");
80
- return out;
81
- }
@@ -1,228 +0,0 @@
1
- // Syntax-tree walk that gathers complexity stats and assembles the summary report.
2
-
3
- import {
4
- LOOP_NODES, CALL_NODES, RETURN_NODES, AWAIT_NODES, OBJECT_NODES,
5
- FIXED_ALLOCATION_NODES, VARIABLE_ALLOCATION_NODES, SPREAD_NODES,
6
- DECLARATION_BOUNDARIES, EXPRESSION_CALLABLES, ARGUMENT_NODES,
7
- ITERATOR_CALLS, PRODUCER_CALLS, LINEAR_CALLS, SORT_CALLS, BRANCH_NODES
8
- } from "./source-complexity.constants.js";
9
- import {
10
- field, children, sameNode, normalizedName, looksLikeIoCall, callName,
11
- logicalBranch, isDefaultCase, directParameterCount, countObjectPatternFields, sourceRange
12
- } from "./source-complexity.ast.js";
13
- import { buildLabels, buildEvidence } from "./source-complexity.report.js";
14
-
15
- function createStats(parameters, family) {
16
- return {
17
- params: directParameterCount(parameters, family),
18
- objectFields: countObjectPatternFields(parameters),
19
- branches: 0,
20
- loops: 0,
21
- maxLoopDepth: 0,
22
- returns: 0,
23
- awaits: 0,
24
- callCount: 0,
25
- externalCalls: 0,
26
- asyncBoundaries: 0,
27
- allocations: 0,
28
- objectLiterals: 0,
29
- spreadCopies: 0,
30
- sorts: 0,
31
- linearOps: 0,
32
- producerCalls: 0,
33
- recursion: false,
34
- maxSortLoopDepth: 0,
35
- maxVariableAllocationDepth: 0,
36
- allocationsInLoops: 0,
37
- copiesInLoops: 0,
38
- linearOpsInLoops: 0,
39
- sortsInLoops: 0,
40
- recursionInLoops: 0,
41
- hotEvidence: []
42
- };
43
- }
44
-
45
- function recordHotEvidence(stats, node, kind, detail) {
46
- if (stats.hotEvidence.length >= 24) return;
47
- const line = node?.startPosition ? node.startPosition.row + 1 : 0;
48
- if (stats.hotEvidence.some((item) => item.kind === kind && item.line === line)) return;
49
- stats.hotEvidence.push({ kind, line, detail });
50
- }
51
-
52
- function shouldSkipNode(root, node, state) {
53
- if (sameNode(node, root)) return false;
54
- const type = String(node.type || "");
55
- if (DECLARATION_BOUNDARIES.has(type)) return true;
56
- if (!EXPRESSION_CALLABLES.has(type) || state.callbackContext) return false;
57
- const parent = state.parent;
58
- return !(CALL_NODES.has(String(parent?.type || "")) && sameNode(field(parent, "function"), node));
59
- }
60
-
61
- function nodeFacts(node, state) {
62
- const type = String(node.type || "");
63
- const isCall = CALL_NODES.has(type);
64
- const nameAtCall = isCall ? callName(node) : "";
65
- const normalizedCall = normalizedName(nameAtCall);
66
- return {
67
- type,
68
- isCall,
69
- isLoop: LOOP_NODES.has(type),
70
- nameAtCall,
71
- normalizedCall,
72
- iteratorCall: isCall && ITERATOR_CALLS.has(normalizedCall),
73
- sortCall: isCall && SORT_CALLS.has(normalizedCall),
74
- producerCall: isCall && PRODUCER_CALLS.has(normalizedCall),
75
- currentDepth: Math.max(0, Number(state.loopDepth) || 0)
76
- };
77
- }
78
-
79
- function recordBasicSignals(stats, node, facts) {
80
- const { type, currentDepth } = facts;
81
- if (BRANCH_NODES.has(type) && !(type.includes("case") && isDefaultCase(node))) stats.branches++;
82
- else if (logicalBranch(node)) stats.branches++;
83
- if (RETURN_NODES.has(type)) stats.returns++;
84
- if (AWAIT_NODES.has(type)) { stats.awaits++; stats.asyncBoundaries++; }
85
- if (OBJECT_NODES.has(type)) stats.objectLiterals++;
86
- if (FIXED_ALLOCATION_NODES.has(type)) {
87
- stats.allocations++;
88
- if (currentDepth > 0) {
89
- stats.allocationsInLoops++;
90
- recordHotEvidence(stats, node, "allocation-in-loop", type);
91
- }
92
- }
93
- if (!VARIABLE_ALLOCATION_NODES.has(type)) return;
94
- stats.producerCalls++;
95
- stats.maxVariableAllocationDepth = Math.max(stats.maxVariableAllocationDepth, currentDepth + 1);
96
- }
97
-
98
- function recordSpread(stats, node, facts, parent) {
99
- if (!SPREAD_NODES.has(facts.type) || /parameters|parameter_list/.test(String(parent?.type || ""))) return;
100
- stats.spreadCopies++;
101
- stats.linearOps++;
102
- stats.maxVariableAllocationDepth = Math.max(stats.maxVariableAllocationDepth, facts.currentDepth + 1);
103
- if (facts.currentDepth > 0) {
104
- stats.copiesInLoops++;
105
- stats.linearOpsInLoops++;
106
- recordHotEvidence(stats, node, "copy-in-loop", facts.type);
107
- }
108
- }
109
-
110
- function recordCall(stats, node, facts, state, targetName) {
111
- if (!facts.isCall) return;
112
- stats.callCount++;
113
- if (state.awaited || looksLikeIoCall(facts.nameAtCall)) stats.externalCalls++;
114
- if (targetName && facts.normalizedCall === targetName) {
115
- stats.recursion = true;
116
- if (facts.currentDepth > 0) {
117
- stats.recursionInLoops++;
118
- recordHotEvidence(stats, node, "recursion-in-loop", facts.nameAtCall || targetName);
119
- }
120
- }
121
- if (facts.sortCall) {
122
- stats.sorts++;
123
- stats.maxSortLoopDepth = Math.max(stats.maxSortLoopDepth, facts.currentDepth);
124
- if (facts.currentDepth > 0) {
125
- stats.sortsInLoops++;
126
- recordHotEvidence(stats, node, "sort-in-loop", facts.nameAtCall || "sort");
127
- }
128
- } else if (LINEAR_CALLS.has(facts.normalizedCall) && !facts.iteratorCall) {
129
- stats.linearOps++;
130
- if (facts.currentDepth > 0) {
131
- stats.linearOpsInLoops++;
132
- recordHotEvidence(stats, node, "linear-scan-in-loop", facts.nameAtCall || "collection operation");
133
- }
134
- } else if (facts.iteratorCall && facts.currentDepth > 0) {
135
- stats.linearOpsInLoops++;
136
- recordHotEvidence(stats, node, "linear-scan-in-loop", facts.nameAtCall || "iterator");
137
- }
138
- if (!facts.producerCall) return;
139
- stats.producerCalls++;
140
- stats.allocations++;
141
- stats.maxVariableAllocationDepth = Math.max(stats.maxVariableAllocationDepth, facts.currentDepth + 1);
142
- if (facts.currentDepth > 0) {
143
- stats.allocationsInLoops++;
144
- recordHotEvidence(stats, node, "allocation-in-loop", facts.nameAtCall || "collection producer");
145
- }
146
- }
147
-
148
- function recordLoop(stats, node, facts) {
149
- if (!facts.isLoop && !facts.iteratorCall) return facts.currentDepth;
150
- const nextDepth = facts.currentDepth + 1;
151
- stats.loops++;
152
- stats.maxLoopDepth = Math.max(stats.maxLoopDepth, nextDepth);
153
- if (nextDepth > 1) recordHotEvidence(stats, node, "nested-iteration", `depth ${nextDepth}`);
154
- return nextDepth;
155
- }
156
-
157
- function depthForChild(node, child, facts, nextDepth) {
158
- const childIsArgs = ARGUMENT_NODES.has(String(child.type || ""));
159
- if (facts.iteratorCall && childIsArgs) return nextDepth;
160
- if (!facts.isLoop) return facts.currentDepth;
161
- const loopBody = field(node, "body");
162
- if (loopBody) return sameNode(child, loopBody) ? nextDepth : facts.currentDepth;
163
- return facts.type === "for_in_clause" ? facts.currentDepth : nextDepth;
164
- }
165
-
166
- function walkSyntax(root, node, state, context) {
167
- if (!node || shouldSkipNode(root, node, state)) return;
168
- const parent = state.parent || null;
169
- const callbackContext = state.callbackContext || ARGUMENT_NODES.has(String(parent?.type || ""));
170
- const facts = nodeFacts(node, state);
171
- recordBasicSignals(context.stats, node, facts);
172
- recordSpread(context.stats, node, facts, parent);
173
- recordCall(context.stats, node, facts, state, context.targetName);
174
- const nextDepth = recordLoop(context.stats, node, facts);
175
- for (const child of children(node)) {
176
- const childIsArgs = ARGUMENT_NODES.has(String(child.type || ""));
177
- walkSyntax(root, child, {
178
- parent: node,
179
- loopDepth: depthForChild(node, child, facts, nextDepth),
180
- callbackContext: callbackContext || childIsArgs,
181
- awaited: AWAIT_NODES.has(facts.type) && !facts.isCall
182
- }, context);
183
- }
184
- }
185
-
186
- export function analyzeSyntaxComplexity(root, { family = "", name = "" } = {}) {
187
- const parameters = field(root, "parameters") || field(root, "parameter");
188
- const stats = createStats(parameters, family);
189
- walkSyntax(root, root, {}, { stats, targetName: normalizedName(name) });
190
-
191
- const labels = buildLabels(stats);
192
- const range = sourceRange(root);
193
- const evidence = buildEvidence(stats);
194
- const structuralWork = stats.loops || stats.sorts || stats.spreadCopies || stats.linearOps;
195
- const confidence = stats.recursion ? "low" : structuralWork ? "medium" : stats.callCount ? "low" : "high";
196
- return {
197
- ...range,
198
- family,
199
- params: stats.params,
200
- objectFields: stats.objectFields,
201
- branches: stats.branches,
202
- cyclomatic: stats.branches + 1,
203
- loops: stats.loops,
204
- maxLoopDepth: stats.maxLoopDepth,
205
- returns: stats.returns,
206
- awaits: stats.awaits,
207
- callCount: stats.callCount,
208
- externalCalls: stats.externalCalls,
209
- asyncBoundaries: stats.asyncBoundaries,
210
- allocations: stats.allocations,
211
- objectLiterals: stats.objectLiterals,
212
- spreadCopies: stats.spreadCopies,
213
- sorts: stats.sorts,
214
- linearOps: stats.linearOps,
215
- recursion: stats.recursion,
216
- allocationsInLoops: stats.allocationsInLoops,
217
- copiesInLoops: stats.copiesInLoops,
218
- linearOpsInLoops: stats.linearOpsInLoops,
219
- sortsInLoops: stats.sortsInLoops,
220
- recursionInLoops: stats.recursionInLoops,
221
- hotEvidence: stats.hotEvidence,
222
- ...labels,
223
- scope: "local",
224
- complexityScope: "local",
225
- confidence,
226
- evidence
227
- };
228
- }