weavatrix 0.3.14 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/README.md +231 -199
- package/bin/native/darwin-arm64/weavatrix +0 -0
- package/bin/native/darwin-x64/weavatrix +0 -0
- package/bin/native/linux-arm64/weavatrix +0 -0
- package/bin/native/linux-x64/weavatrix +0 -0
- package/bin/native/win32-arm64/weavatrix.exe +0 -0
- package/bin/native/win32-x64/weavatrix.exe +0 -0
- package/bin/resolve-binary.mjs +73 -0
- package/bin/run-native.mjs +26 -0
- package/bin/weavatrix-mcp.mjs +7 -6
- package/bin/weavatrix.mjs +5 -0
- package/package.json +8 -66
- package/skill/SKILL.md +62 -374
- package/skill/agents/openai.yaml +4 -0
- package/skill/references/tool-routing.md +45 -0
- package/SECURITY.md +0 -101
- package/docs/adr/0001-v0.3-offline-online-split.md +0 -60
- package/docs/agent-task-benchmark.md +0 -58
- package/docs/releases/v0.2.19.md +0 -33
- package/docs/releases/v0.3.0.md +0 -43
- package/docs/releases/v0.3.1.md +0 -30
- package/docs/releases/v0.3.10.md +0 -76
- package/docs/releases/v0.3.11.md +0 -55
- package/docs/releases/v0.3.12.md +0 -44
- package/docs/releases/v0.3.13.md +0 -34
- package/docs/releases/v0.3.14.md +0 -37
- package/docs/releases/v0.3.2.md +0 -15
- package/docs/releases/v0.3.3.md +0 -25
- package/docs/releases/v0.3.4.md +0 -40
- package/docs/releases/v0.3.5.md +0 -50
- package/docs/releases/v0.3.6.md +0 -44
- package/docs/releases/v0.3.7.md +0 -37
- package/docs/releases/v0.3.8.md +0 -21
- package/docs/releases/v0.3.9.md +0 -36
- package/scripts/run-agent-task-benchmark.mjs +0 -118
- package/src/analysis/allowed-test-runner.js +0 -70
- package/src/analysis/architecture/contract-graph.js +0 -119
- package/src/analysis/architecture/contract-schema.js +0 -110
- package/src/analysis/architecture/contract-storage.js +0 -35
- package/src/analysis/architecture/contract-verification.js +0 -168
- package/src/analysis/architecture-contract.js +0 -16
- package/src/analysis/audit-debt.js +0 -94
- package/src/analysis/audit-extensions.js +0 -60
- package/src/analysis/cargo-dependency-evidence.js +0 -108
- package/src/analysis/cargo-manifests.js +0 -81
- package/src/analysis/change-classification/diff-parser.js +0 -103
- package/src/analysis/change-classification/options.js +0 -40
- package/src/analysis/change-classification/symbol-classifier.js +0 -177
- package/src/analysis/change-classification.js +0 -188
- package/src/analysis/coverage-reports-tarpaulin.js +0 -112
- package/src/analysis/coverage-reports.js +0 -246
- package/src/analysis/cycle-route.js +0 -14
- package/src/analysis/data-flow-evidence.js +0 -114
- package/src/analysis/dead-check.js +0 -300
- package/src/analysis/dead-code-review/candidates.js +0 -194
- package/src/analysis/dead-code-review/policy.js +0 -23
- package/src/analysis/dead-code-review.js +0 -119
- package/src/analysis/dep-check-ecosystems.js +0 -205
- package/src/analysis/dep-check.js +0 -290
- package/src/analysis/dep-rules.js +0 -10
- package/src/analysis/dependency/conventions.js +0 -16
- package/src/analysis/dependency/scoped-dependencies.js +0 -51
- package/src/analysis/dependency/source-references.js +0 -21
- package/src/analysis/duplicate-groups.js +0 -104
- package/src/analysis/duplicates-worker.js +0 -11
- package/src/analysis/duplicates.compute.js +0 -269
- package/src/analysis/duplicates.js +0 -15
- package/src/analysis/duplicates.run.js +0 -52
- package/src/analysis/duplicates.tokenize.js +0 -199
- package/src/analysis/endpoints/common.js +0 -79
- package/src/analysis/endpoints/extract.js +0 -120
- package/src/analysis/endpoints/inventory.js +0 -84
- package/src/analysis/endpoints/mounts.js +0 -129
- package/src/analysis/endpoints-java.js +0 -260
- package/src/analysis/endpoints-rust.js +0 -124
- package/src/analysis/endpoints.js +0 -3
- package/src/analysis/findings.js +0 -70
- package/src/analysis/git-history/analytics.js +0 -177
- package/src/analysis/git-history/collector.js +0 -67
- package/src/analysis/git-history/options.js +0 -66
- package/src/analysis/git-history.js +0 -143
- package/src/analysis/git-ref-graph.js +0 -76
- package/src/analysis/go-dependency-evidence.js +0 -62
- package/src/analysis/graph-analysis.aggregate.js +0 -296
- package/src/analysis/graph-analysis.edges.js +0 -24
- package/src/analysis/graph-analysis.js +0 -7
- package/src/analysis/graph-analysis.refs.js +0 -202
- package/src/analysis/graph-analysis.summaries.js +0 -65
- package/src/analysis/health-capabilities.js +0 -83
- package/src/analysis/hot-path-review.js +0 -266
- package/src/analysis/http-contract-wrappers.js +0 -241
- package/src/analysis/http-contracts/analysis.js +0 -179
- package/src/analysis/http-contracts/client-call-detection.js +0 -82
- package/src/analysis/http-contracts/client-call-parser.js +0 -273
- package/src/analysis/http-contracts/graph-context.js +0 -143
- package/src/analysis/http-contracts/matching.js +0 -61
- package/src/analysis/http-contracts/shared.js +0 -85
- package/src/analysis/http-contracts.js +0 -6
- package/src/analysis/internal-audit/dependency-health.js +0 -113
- package/src/analysis/internal-audit/python-manifests.js +0 -78
- package/src/analysis/internal-audit/repo-files.js +0 -50
- package/src/analysis/internal-audit/supply-chain.js +0 -149
- package/src/analysis/internal-audit.collect.js +0 -213
- package/src/analysis/internal-audit.js +0 -9
- package/src/analysis/internal-audit.reach.js +0 -201
- package/src/analysis/internal-audit.run.js +0 -256
- package/src/analysis/java-source.js +0 -36
- package/src/analysis/jvm-artifact-index.js +0 -87
- package/src/analysis/jvm-dependency-evidence.js +0 -138
- package/src/analysis/jvm-manifests.js +0 -114
- package/src/analysis/manifests.js +0 -123
- package/src/analysis/package-reachability.js +0 -39
- package/src/analysis/source-complexity.ast.js +0 -97
- package/src/analysis/source-complexity.constants.js +0 -55
- package/src/analysis/source-complexity.js +0 -14
- package/src/analysis/source-complexity.report.js +0 -81
- package/src/analysis/source-complexity.walk.js +0 -228
- package/src/analysis/source-correctness/retry-patterns.js +0 -93
- package/src/analysis/source-correctness.js +0 -222
- package/src/analysis/static-test-reachability.js +0 -150
- package/src/analysis/structure/dependency-graph.js +0 -151
- package/src/analysis/structure/findings.js +0 -162
- package/src/analysis/task-retrieval.js +0 -107
- package/src/analysis/transport-contracts.js +0 -224
- package/src/analysis/transport-runtime-evidence.js +0 -155
- package/src/analysis-kit.mjs +0 -17
- package/src/bounds.js +0 -4
- package/src/build-graph.js +0 -209
- package/src/child-env.js +0 -7
- package/src/config.js +0 -5
- package/src/extension/local-services.mjs +0 -75
- package/src/git-exec.js +0 -67
- package/src/graph/build-worker.js +0 -49
- package/src/graph/builder/go-receiver-resolution.js +0 -112
- package/src/graph/builder/js/dynamic-import.js +0 -26
- package/src/graph/builder/js/queries.js +0 -48
- package/src/graph/builder/lang-csharp.js +0 -40
- package/src/graph/builder/lang-css.js +0 -29
- package/src/graph/builder/lang-go.js +0 -140
- package/src/graph/builder/lang-html.js +0 -29
- package/src/graph/builder/lang-java-calls.js +0 -142
- package/src/graph/builder/lang-java.js +0 -215
- package/src/graph/builder/lang-js.js +0 -291
- package/src/graph/builder/lang-python.js +0 -235
- package/src/graph/builder/lang-rust-calls.js +0 -63
- package/src/graph/builder/lang-rust.js +0 -299
- package/src/graph/builder/lang-solidity.js +0 -126
- package/src/graph/builder/lang-sql.js +0 -263
- package/src/graph/builder/pass2-resolution.js +0 -81
- package/src/graph/builder/spec-pkg.js +0 -87
- package/src/graph/community.js +0 -27
- package/src/graph/edge-provenance.js +0 -31
- package/src/graph/file-lock.js +0 -69
- package/src/graph/freshness-probe.js +0 -142
- package/src/graph/graph-filter.js +0 -63
- package/src/graph/incremental-refresh.js +0 -235
- package/src/graph/internal-builder.barrels.js +0 -235
- package/src/graph/internal-builder.build.js +0 -300
- package/src/graph/internal-builder.java.js +0 -33
- package/src/graph/internal-builder.js +0 -12
- package/src/graph/internal-builder.langs.js +0 -157
- package/src/graph/internal-builder.pass2.js +0 -163
- package/src/graph/internal-builder.resolvers.js +0 -286
- package/src/graph/layout.js +0 -51
- package/src/graph/node-id.js +0 -7
- package/src/graph/parser-artifact-boundary.js +0 -55
- package/src/graph/relations.js +0 -4
- package/src/graph/repo-registry.js +0 -124
- package/src/graph/resolvers/rust.js +0 -117
- package/src/infra/infra-items.js +0 -255
- package/src/infra/infra-registry.js +0 -184
- package/src/infra/infra.detect.js +0 -119
- package/src/infra/infra.js +0 -38
- package/src/infra/infra.match.js +0 -102
- package/src/infra/infra.scan.js +0 -93
- package/src/mcp/actions/graph-lifecycle.mjs +0 -148
- package/src/mcp/architecture-bootstrap.mjs +0 -168
- package/src/mcp/architecture-starter.mjs +0 -234
- package/src/mcp/catalog.mjs +0 -233
- package/src/mcp/company-contract-page.mjs +0 -142
- package/src/mcp/company-contract-reconcile.mjs +0 -87
- package/src/mcp/company-contract-verdict.mjs +0 -42
- package/src/mcp/evidence/bun-lock-graph.mjs +0 -209
- package/src/mcp/evidence/duplicate-member-order.mjs +0 -8
- package/src/mcp/evidence/package-graph-common.mjs +0 -115
- package/src/mcp/evidence/package-lock-graph.mjs +0 -92
- package/src/mcp/evidence-snapshot.architecture.mjs +0 -80
- package/src/mcp/evidence-snapshot.common.mjs +0 -158
- package/src/mcp/evidence-snapshot.duplicates.mjs +0 -213
- package/src/mcp/evidence-snapshot.health.mjs +0 -102
- package/src/mcp/evidence-snapshot.inventory.mjs +0 -148
- package/src/mcp/evidence-snapshot.mjs +0 -50
- package/src/mcp/evidence-snapshot.package-graph.mjs +0 -34
- package/src/mcp/evidence-snapshot.structure.mjs +0 -84
- package/src/mcp/extension-api.mjs +0 -77
- package/src/mcp/git-output.mjs +0 -7
- package/src/mcp/graph/context-core.mjs +0 -111
- package/src/mcp/graph/context-seeds.mjs +0 -207
- package/src/mcp/graph/context-state.mjs +0 -85
- package/src/mcp/graph/reverse-reach.mjs +0 -42
- package/src/mcp/graph/tools-core.mjs +0 -143
- package/src/mcp/graph/tools-query.mjs +0 -276
- package/src/mcp/graph-context.mjs +0 -5
- package/src/mcp/graph-diff.mjs +0 -218
- package/src/mcp/health/audit-format.mjs +0 -199
- package/src/mcp/health/audit.mjs +0 -199
- package/src/mcp/health/dead-code.mjs +0 -110
- package/src/mcp/health/duplicates.mjs +0 -121
- package/src/mcp/health/endpoints.mjs +0 -71
- package/src/mcp/health/structure.mjs +0 -220
- package/src/mcp/runtime-version.mjs +0 -31
- package/src/mcp/server/auto-refresh.mjs +0 -66
- package/src/mcp/server/runtime-config.mjs +0 -43
- package/src/mcp/server/shutdown.mjs +0 -40
- package/src/mcp/staleness-notice.mjs +0 -20
- package/src/mcp/sync/evidence-architecture.mjs +0 -54
- package/src/mcp/sync/evidence-common.mjs +0 -88
- package/src/mcp/sync/evidence-duplicates.mjs +0 -97
- package/src/mcp/sync/evidence-health.mjs +0 -56
- package/src/mcp/sync/evidence-packages.mjs +0 -95
- package/src/mcp/sync/payload-common.mjs +0 -97
- package/src/mcp/sync/payload-v2.mjs +0 -54
- package/src/mcp/sync/payload-v3.mjs +0 -79
- package/src/mcp/sync-evidence.mjs +0 -23
- package/src/mcp/sync-payload.mjs +0 -70
- package/src/mcp/tool-result.mjs +0 -54
- package/src/mcp/tools-actions.mjs +0 -11
- package/src/mcp/tools-architecture.mjs +0 -177
- package/src/mcp/tools-company.mjs +0 -251
- package/src/mcp/tools-context.mjs +0 -222
- package/src/mcp/tools-endpoints.mjs +0 -207
- package/src/mcp/tools-graph-hubs.mjs +0 -78
- package/src/mcp/tools-graph.mjs +0 -17
- package/src/mcp/tools-health.mjs +0 -24
- package/src/mcp/tools-history.mjs +0 -28
- package/src/mcp/tools-impact-change.mjs +0 -220
- package/src/mcp/tools-impact-precision.mjs +0 -89
- package/src/mcp/tools-impact.mjs +0 -169
- package/src/mcp/tools-source.mjs +0 -238
- package/src/mcp/tools-verified-change.mjs +0 -200
- package/src/mcp-rg.mjs +0 -50
- package/src/mcp-runtime.mjs +0 -2
- package/src/mcp-server.mjs +0 -298
- package/src/mcp-source-tools.mjs +0 -163
- package/src/path-classification.js +0 -226
- package/src/path-ignore.js +0 -69
- package/src/precision/lsp-client/constants.js +0 -12
- package/src/precision/lsp-client/environment.js +0 -20
- package/src/precision/lsp-client/errors.js +0 -15
- package/src/precision/lsp-client/lifecycle.js +0 -114
- package/src/precision/lsp-client/message-parser.js +0 -81
- package/src/precision/lsp-client/protocol.js +0 -212
- package/src/precision/lsp-client/registry.js +0 -59
- package/src/precision/lsp-client/repo-uri.js +0 -60
- package/src/precision/lsp-client/stdio-client.js +0 -140
- package/src/precision/lsp-client.js +0 -10
- package/src/precision/lsp-overlay/budget-policy.js +0 -78
- package/src/precision/lsp-overlay/build.js +0 -261
- package/src/precision/lsp-overlay/contract.js +0 -61
- package/src/precision/lsp-overlay/reference-results.js +0 -108
- package/src/precision/lsp-overlay/semantic-inputs.js +0 -62
- package/src/precision/lsp-overlay/source-session.js +0 -142
- package/src/precision/lsp-overlay/store.js +0 -150
- package/src/precision/lsp-overlay/target-index.js +0 -152
- package/src/precision/lsp-overlay/target-query.js +0 -55
- package/src/precision/lsp-overlay.js +0 -11
- package/src/precision/symbol-query.js +0 -224
- package/src/precision/typescript-lsp-provider.js +0 -12
- package/src/precision/typescript-provider/client.js +0 -89
- package/src/precision/typescript-provider/discovery.js +0 -124
- package/src/precision/typescript-provider/isolated-runtime.js +0 -39
- package/src/precision/typescript-provider/project-host.js +0 -254
- package/src/precision/typescript-provider/project-safety.js +0 -166
- package/src/precision/typescript-provider/reference-usage.js +0 -53
- package/src/process.js +0 -95
- package/src/repo-path.js +0 -53
- package/src/scan/discover.inventory.js +0 -78
- package/src/scan/discover.js +0 -5
- package/src/scan/discover.list.js +0 -79
- package/src/scan/discover.stack.js +0 -227
- package/src/scan/search.core.js +0 -24
- package/src/scan/search.git.js +0 -102
- package/src/scan/search.js +0 -9
- package/src/scan/search.node.js +0 -83
- package/src/scan/search.preview.js +0 -49
- package/src/scan/search.rg.js +0 -145
- package/src/security/advisory-store.js +0 -172
- package/src/security/installed-jvm-rust.js +0 -46
- package/src/security/installed.js +0 -280
- package/src/security/malware-file-heuristics.js +0 -121
- package/src/security/malware-heuristics.exclusions.js +0 -134
- package/src/security/malware-heuristics.js +0 -15
- package/src/security/malware-heuristics.roots.js +0 -145
- package/src/security/malware-heuristics.scan.js +0 -89
- package/src/security/malware-heuristics.sweep.js +0 -122
- package/src/security/malware-scoring.js +0 -105
- package/src/security/match.js +0 -85
- package/src/security/registry-sig.classify.js +0 -137
- package/src/security/registry-sig.js +0 -18
- package/src/security/registry-sig.rules.js +0 -192
- package/src/security/rust-advisory-report.js +0 -60
- package/src/security/typosquat.js +0 -81
- package/src/util.js +0 -40
- package/src/version.js +0 -7
package/docs/releases/v0.3.4.md
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# Weavatrix 0.3.4
|
|
2
|
-
|
|
3
|
-
0.3.4 is a focused self-audit precision release. It removes false Health and
|
|
4
|
-
dead-code noise found while dogfooding Core against its own current source,
|
|
5
|
-
without widening the 34-tool offline boundary.
|
|
6
|
-
|
|
7
|
-
## Bounded dynamic-import evidence
|
|
8
|
-
|
|
9
|
-
JS/TS graph construction now recognizes the statically named local module in
|
|
10
|
-
URL-based imports such as
|
|
11
|
-
``import(new URL(`./tools-health.mjs${cacheBust}`, import.meta.url).href)``.
|
|
12
|
-
The resolved local candidate participates in reachability, while the edge keeps
|
|
13
|
-
its `dynamic` marker. Variable-first templates, remote URLs, non-`import.meta.url`
|
|
14
|
-
bases and other runtime-only expressions remain unresolved rather than being
|
|
15
|
-
guessed.
|
|
16
|
-
|
|
17
|
-
## Health and dead-code precision
|
|
18
|
-
|
|
19
|
-
- The dependency summary uses the same production-first path scope as the
|
|
20
|
-
findings shown below it. Findings isolated to fixtures/tests are reported as a
|
|
21
|
-
separate suppressed count instead of leaking into the production headline.
|
|
22
|
-
- Comment-only lexical mentions no longer prove symbol liveness. String-based
|
|
23
|
-
registries and reflective dispatch stay conservative because they may be real
|
|
24
|
-
runtime entry points.
|
|
25
|
-
- Dogfood removed unnecessary internal exports, obsolete declarations and
|
|
26
|
-
uncalled LSP wrapper methods. Supported Online extension exports and
|
|
27
|
-
TypeScript host callbacks remain intact.
|
|
28
|
-
|
|
29
|
-
Current-source dogfood reports zero Health findings in both full and no-tests
|
|
30
|
-
graphs. The remaining low-confidence dead-code queue contains only the five
|
|
31
|
-
supported Online extension exports and two TypeScript host callbacks. Classified
|
|
32
|
-
benchmark dependency findings remain available through `include_classified`.
|
|
33
|
-
|
|
34
|
-
The release remains gated by the full Node suite, release metadata validation,
|
|
35
|
-
portable MCPB/npm runtime smoke, dependency audit and self-dogfood.
|
|
36
|
-
|
|
37
|
-
The strict source-free real-repository benchmark was refreshed from clean,
|
|
38
|
-
revision-bound checkouts and passes all six language repositories (TypeScript,
|
|
39
|
-
JavaScript, Python, Go, Java and Rust) with complete provenance, expected-signal
|
|
40
|
-
and relation-regression gates.
|
package/docs/releases/v0.3.5.md
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# Weavatrix 0.3.5
|
|
2
|
-
|
|
3
|
-
0.3.5 removes the hidden 64-symbol ceiling from deliberately high-budget
|
|
4
|
-
TypeScript/JavaScript semantic prewarms while keeping the ordinary offline
|
|
5
|
-
startup profile unchanged.
|
|
6
|
-
|
|
7
|
-
## Explicit full semantic prewarm
|
|
8
|
-
|
|
9
|
-
- The default remains a 32-symbol ranked prewarm with the previous 64-symbol,
|
|
10
|
-
16,384-reference/link and 60-second hard ceilings.
|
|
11
|
-
- Setting `WEAVATRIX_PRECISION_MAX_SYMBOLS` above 64 now explicitly opts into
|
|
12
|
-
the expanded policy instead of being silently clamped back to 64.
|
|
13
|
-
- `WEAVATRIX_PRECISION_PREWARM=full` selects all eligible targets, bounded by a
|
|
14
|
-
10,000-symbol hard ceiling. It is intended for CI, release evidence and
|
|
15
|
-
manually requested deep repository audits, not implicit startup work.
|
|
16
|
-
- Expanded runs scale their default reference/link budget to 16 per requested
|
|
17
|
-
symbol and their deadline to one second per requested symbol. Hard limits
|
|
18
|
-
remain 131,072 references/links and 30 minutes.
|
|
19
|
-
- Verified source remains bounded to 4 MiB per file, 1,024 simultaneously open
|
|
20
|
-
documents and 128 MiB total. Crossing a ceiling remains `PARTIAL`; it never
|
|
21
|
-
becomes a false complete result or an unbounded allocation.
|
|
22
|
-
|
|
23
|
-
The point-query cache used by `get_dependents` and `inspect_symbol`, and the
|
|
24
|
-
bounded changed-symbol batch used by `change_impact`, remain separate from this
|
|
25
|
-
broad overlay. Existing default and on-demand behavior is unchanged.
|
|
26
|
-
|
|
27
|
-
The regression suite proves both sides of the contract: an ordinary build still
|
|
28
|
-
selects 32 of 80 candidates and reports `PARTIAL`, while an explicit 1,000-symbol
|
|
29
|
-
budget and `full` mode each query all 80 targets and report `COMPLETE` with a
|
|
30
|
-
cooperative provider.
|
|
31
|
-
|
|
32
|
-
## Dead-code verdict consistency
|
|
33
|
-
|
|
34
|
-
- `run_audit` now labels an unreferenced public export as low-confidence
|
|
35
|
-
`unused-export-surface` evidence and sets `deadCodeCandidate:false`.
|
|
36
|
-
- The audit explains that an unused module surface is not proof of a dead
|
|
37
|
-
implementation; downstream packages and runtime registries may be invisible.
|
|
38
|
-
- This matches `find_dead_code`, which keeps the same uncertain public surface
|
|
39
|
-
out of its default medium-confidence review queue while reporting the
|
|
40
|
-
suppressed low-confidence count.
|
|
41
|
-
|
|
42
|
-
## Consistent unused-export confidence
|
|
43
|
-
|
|
44
|
-
`run_audit` now labels an unused export as low-confidence export-surface
|
|
45
|
-
evidence, not a medium-confidence dead implementation. The finding explicitly
|
|
46
|
-
distinguishes removing an unnecessary export keyword from deleting the symbol,
|
|
47
|
-
which still requires the separate exact/reference-aware `find_dead_code`
|
|
48
|
-
workflow. This aligns Health with the default dead-code queue, where public and
|
|
49
|
-
framework-sensitive candidates are intentionally suppressed until
|
|
50
|
-
`min_confidence=low` is requested.
|
package/docs/releases/v0.3.6.md
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Weavatrix 0.3.6
|
|
2
|
-
|
|
3
|
-
0.3.6 corrects Rust dependency evidence so that language builtins, relative-path
|
|
4
|
-
modules and self-crate references are no longer reported as missing Cargo
|
|
5
|
-
dependencies. Symbol, module and call extraction are unchanged.
|
|
6
|
-
|
|
7
|
-
## Rust missing-dependency precision
|
|
8
|
-
|
|
9
|
-
Rust crate detection previously read every leading path segment as a potential
|
|
10
|
-
external crate. Four classes of local or built-in path were therefore reported
|
|
11
|
-
as missing Cargo dependencies:
|
|
12
|
-
|
|
13
|
-
- **Primitive types.** `f64::from(..)`, `u8::MAX`, `str::len` and the rest of the
|
|
14
|
-
numeric, `bool`, `char` and `str` primitives are language builtins and are now
|
|
15
|
-
excluded from crate detection.
|
|
16
|
-
- **`use`-bound aliases.** A name imported into scope by `use foo::bar` (module
|
|
17
|
-
alias or item) no longer re-registers as a crate when it later appears as
|
|
18
|
-
`bar::baz`. The crate's own root name — for example `use anyhow::{self}` — is
|
|
19
|
-
deliberately preserved as a dependency.
|
|
20
|
-
- **Declared child modules.** A `mod child;` (or inline `mod child { .. }`)
|
|
21
|
-
declaration shadows any same-named crate, so `child::item` paths resolve
|
|
22
|
-
locally instead of surfacing as a missing crate.
|
|
23
|
-
- **Self-crate references.** A crate that refers to its own package name — the
|
|
24
|
-
routine `use <crate>::..` in `examples/`, `tests/`, `benches/` and the `[[bin]]`
|
|
25
|
-
that pairs with a `[lib]` — is treated as a resolved self-reference rather than
|
|
26
|
-
a missing dependency.
|
|
27
|
-
|
|
28
|
-
Relative anchors (`crate::`, `self::`, `super::`) and `extern crate` continue to
|
|
29
|
-
resolve exactly as before, and genuinely undeclared external crates are still
|
|
30
|
-
reported.
|
|
31
|
-
|
|
32
|
-
## Verification
|
|
33
|
-
|
|
34
|
-
New regression tests pin both layers: the Rust extractor keeps a real crate as
|
|
35
|
-
the only external import when a file mixes an `f64` primitive path, a
|
|
36
|
-
`super::` module and in-scope aliases, and the Cargo evidence layer keeps a
|
|
37
|
-
self-crate reference out of the missing-dependency set while still reporting an
|
|
38
|
-
undeclared crate.
|
|
39
|
-
|
|
40
|
-
## HTTP contract detector hygiene
|
|
41
|
-
|
|
42
|
-
The HTTP client-call detector builds its `fetch` token at runtime and uses an
|
|
43
|
-
`isFetch` flag, so the analyzer's own source carries no literal call-shape of the
|
|
44
|
-
Web API it scans for. Detection behavior is unchanged.
|
package/docs/releases/v0.3.7.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Weavatrix 0.3.7
|
|
2
|
-
|
|
3
|
-
0.3.7 fixes three defects surfaced by cross-repository validation: a
|
|
4
|
-
reverse-shell detection gap, an unbounded ripgrep-path probe that could hang the
|
|
5
|
-
server, and a `search_code` path that excluded `node_modules` only through the
|
|
6
|
-
gitignore stack.
|
|
7
|
-
|
|
8
|
-
## Reverse-shell pre-filter now covers the confirming regex
|
|
9
|
-
|
|
10
|
-
The malware content sweep uses each rule's `pattern` as the ripgrep pre-filter
|
|
11
|
-
and only then applies the stricter `re` to confirm. The reverse-shell `pattern`
|
|
12
|
-
had drifted narrower than its `re`: it required `SOCK_STREAM` followed by
|
|
13
|
-
`/bin/sh` or `exec`, so socket-backed shells using `connect`, `subprocess`,
|
|
14
|
-
`pty.spawn` or `os.dup2` — and default `socket.socket()` calls with no
|
|
15
|
-
`SOCK_STREAM` literal — were dropped before they could be confirmed. The
|
|
16
|
-
pre-filter is now a superset of the confirming regex, and a new invariant test
|
|
17
|
-
asserts that every payload the confirming regex flags is also surfaced by the
|
|
18
|
-
pre-filter.
|
|
19
|
-
|
|
20
|
-
A separate, deeper case is deliberately left for a follow-up: multi-line reverse
|
|
21
|
-
shells, where ripgrep's per-line matching cannot span a `socket` call and the
|
|
22
|
-
shell invocation on different lines.
|
|
23
|
-
|
|
24
|
-
## Bounded ripgrep-path probe
|
|
25
|
-
|
|
26
|
-
The `where`/`which rg` fallback in the MCP ripgrep resolver ran `spawnSync`
|
|
27
|
-
without a timeout on the main thread, so a slow or unreachable PATH entry (for
|
|
28
|
-
example a disconnected network drive) could hang the server. The probe now runs
|
|
29
|
-
with a three-second timeout and `windowsHide`.
|
|
30
|
-
|
|
31
|
-
## search_code excludes node_modules explicitly
|
|
32
|
-
|
|
33
|
-
The `search_code` ripgrep invocation passed `--hidden` with only a `.git`
|
|
34
|
-
exclusion, leaving `node_modules` out of results solely through ripgrep's
|
|
35
|
-
implicit gitignore stack — which fails for repositories that commit their
|
|
36
|
-
dependency tree or lack a gitignore. An explicit `!node_modules` glob is now
|
|
37
|
-
applied; a caller-supplied glob is still appended afterward and wins.
|
package/docs/releases/v0.3.8.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# Weavatrix 0.3.8
|
|
2
|
-
|
|
3
|
-
0.3.8 is a documentation and internal-structure release. Tool behavior and
|
|
4
|
-
output are unchanged.
|
|
5
|
-
|
|
6
|
-
## Slimmer README
|
|
7
|
-
|
|
8
|
-
The README is refocused on the current release — install, configuration, tools,
|
|
9
|
-
benchmarks and the security model — and the accumulated per-version changelog is
|
|
10
|
-
removed in favor of the existing per-version notes under
|
|
11
|
-
[docs/releases/](../releases/). This also slims the README rendered on the npm
|
|
12
|
-
package page.
|
|
13
|
-
|
|
14
|
-
## Internal module split
|
|
15
|
-
|
|
16
|
-
`src/analysis/dead-code-review.js` is split along the repository's existing
|
|
17
|
-
facade convention: the per-candidate record builders (`symbolCandidate`,
|
|
18
|
-
`fileCandidate`) move to `src/analysis/dead-code-review/candidates.js`, while the
|
|
19
|
-
orchestrator and the public `computeDeadCodeReview` export stay in place.
|
|
20
|
-
Importers and returned records are unchanged, and both files are now within the
|
|
21
|
-
300-line owner-module budget.
|
package/docs/releases/v0.3.9.md
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# Weavatrix 0.3.9
|
|
2
|
-
|
|
3
|
-
0.3.9 consolidates every subprocess launch behind a small number of audited
|
|
4
|
-
chokepoints. Tool behavior and output are unchanged — verified byte-identical
|
|
5
|
-
against 0.3.8 on real repositories.
|
|
6
|
-
|
|
7
|
-
## Single-chokepoint subprocess execution
|
|
8
|
-
|
|
9
|
-
Git and other subprocess launches were scattered across roughly fifteen modules,
|
|
10
|
-
each with its own near-identical spawn wrapper. They now route through two
|
|
11
|
-
focused modules:
|
|
12
|
-
|
|
13
|
-
- **git** — every git command runs through `src/git-exec.js`: `runGit` for
|
|
14
|
-
synchronous run-and-collect calls and `boundedGitCommand` for the streaming
|
|
15
|
-
history collector.
|
|
16
|
-
- **everything else** — ripgrep resolution and search, `tar` archive extraction,
|
|
17
|
-
and `where`/`which` binary probing run through `src/process.js`: the existing
|
|
18
|
-
async `runCommand` plus a new synchronous `runCommandSync`.
|
|
19
|
-
|
|
20
|
-
Every launch now applies the same credential-stripped child environment,
|
|
21
|
-
`windowsHide`, bounded timeout, and `-C <repoRoot>`/`cwd` containment in one
|
|
22
|
-
place. The number of modules importing `node:child_process` drops from fifteen
|
|
23
|
-
to four — the two runners plus the long-lived language-server client — removing
|
|
24
|
-
duplicated wrappers and making the whole process surface auditable from a single
|
|
25
|
-
point.
|
|
26
|
-
|
|
27
|
-
This is a pure refactor: graph construction, change impact, Health, history and
|
|
28
|
-
search produce identical results. A byte-level comparison of the entire graph
|
|
29
|
-
(every node, edge and external import, hashed with SHA-256) against the published
|
|
30
|
-
0.3.8 matched exactly on the analytics, controller-rest-api and Weavatrix
|
|
31
|
-
repositories.
|
|
32
|
-
|
|
33
|
-
## Minor
|
|
34
|
-
|
|
35
|
-
Removed two redundant module imports (`node:perf_hooks`, `node:process`) that
|
|
36
|
-
re-imported values already available as Node globals.
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import {readFileSync} from 'node:fs'
|
|
2
|
-
import {pathToFileURL} from 'node:url'
|
|
3
|
-
import {retrieveTaskContext} from '../src/analysis/task-retrieval.js'
|
|
4
|
-
|
|
5
|
-
function graphFixture() {
|
|
6
|
-
const nodes = [
|
|
7
|
-
{id: 'src/auth/session.js#validateSession@10', label: 'validateSession()', source_file: 'src/auth/session.js', symbol_kind: 'function'},
|
|
8
|
-
{id: 'src/http/router.js#registerRoutes@20', label: 'registerRoutes()', source_file: 'src/http/router.js', symbol_kind: 'function'},
|
|
9
|
-
{id: 'src/cache/store.js#readCache@5', label: 'readCache()', source_file: 'src/cache/store.js', symbol_kind: 'function'},
|
|
10
|
-
{id: 'src/auth/session.test.js#sessionTest@3', label: 'sessionTest()', source_file: 'src/auth/session.test.js', symbol_kind: 'function'},
|
|
11
|
-
]
|
|
12
|
-
return {nodes, byId: new Map(nodes.map((node) => [node.id, node])), out: new Map(), inn: new Map()}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const CASES = [
|
|
16
|
-
{task: 'validate authentication session', expected: 'src/auth/session.js#validateSession@10'},
|
|
17
|
-
{task: 'register HTTP API routes', expected: 'src/http/router.js#registerRoutes@20'},
|
|
18
|
-
{task: 'read values from cache store', expected: 'src/cache/store.js#readCache@5'},
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
function competitorTemplate(name) {
|
|
22
|
-
return {name, status: 'MISSING', reason: 'supply same-task blind evaluator output with --independent-results <json>'}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function readCompetitors(path) {
|
|
26
|
-
if (!path) return {}
|
|
27
|
-
const parsed = JSON.parse(readFileSync(path, 'utf8'))
|
|
28
|
-
return parsed?.competitors && typeof parsed.competitors === 'object' ? parsed.competitors : {}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const SYSTEMS = ['weavatrix', 'codebase-memory', 'serena']
|
|
32
|
-
const median = (values) => {
|
|
33
|
-
const sorted = values.slice().sort((left, right) => left - right)
|
|
34
|
-
const middle = Math.floor(sorted.length / 2)
|
|
35
|
-
return sorted.length % 2 ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function independentComparison(path) {
|
|
39
|
-
if (!path) return {status: 'MISSING', reason: 'supply blind evaluator output with --independent-results <json>'}
|
|
40
|
-
try {
|
|
41
|
-
const input = JSON.parse(readFileSync(path, 'utf8'))
|
|
42
|
-
if (input?.schemaVersion !== 'weavatrix.agent-change-results.v1') throw new Error('unsupported schemaVersion')
|
|
43
|
-
const taskSets = []
|
|
44
|
-
const metrics = {}
|
|
45
|
-
for (const name of SYSTEMS) {
|
|
46
|
-
const runs = input.systems?.[name]?.runs
|
|
47
|
-
if (!Array.isArray(runs) || !runs.length) throw new Error(`${name} has no runs`)
|
|
48
|
-
const ids = runs.map((run) => String(run.taskId || '')).sort()
|
|
49
|
-
if (ids.some((id) => !id) || new Set(ids).size !== ids.length) throw new Error(`${name} task IDs are missing or duplicated`)
|
|
50
|
-
for (const run of runs) {
|
|
51
|
-
if (typeof run.success !== 'boolean' || !Number.isFinite(run.falsePositives) || !Number.isFinite(run.tokens) || !Number.isFinite(run.durationMs)) {
|
|
52
|
-
throw new Error(`${name}/${run.taskId || '?'} has incomplete metrics`)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
taskSets.push(ids.join('\0'))
|
|
56
|
-
metrics[name] = {
|
|
57
|
-
tasks: runs.length, changeSuccessRate: runs.filter((run) => run.success).length / runs.length,
|
|
58
|
-
falsePositiveRate: runs.reduce((sum, run) => sum + Math.max(0, run.falsePositives), 0) / runs.length,
|
|
59
|
-
medianTokens: median(runs.map((run) => run.tokens)), medianDurationMs: median(runs.map((run) => run.durationMs)),
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (new Set(taskSets).size !== 1) throw new Error('systems were not evaluated on the same task IDs')
|
|
63
|
-
return {status: 'COMPLETE', evaluator: String(input.evaluator || 'unspecified'), metrics}
|
|
64
|
-
} catch (error) {
|
|
65
|
-
return {status: 'INVALID', reason: error instanceof Error ? error.message : String(error)}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function runAgentTaskBenchmark({competitorResults, independentResults} = {}) {
|
|
70
|
-
const graph = graphFixture()
|
|
71
|
-
const started = performance.now()
|
|
72
|
-
const cases = CASES.map((item) => {
|
|
73
|
-
const semanticSeeds = graph.nodes.filter((node) => item.task.toLowerCase().split(/\W+/).some((word) => word.length > 3 && String(node.id).toLowerCase().includes(word)))
|
|
74
|
-
const result = retrieveTaskContext(graph, {task: item.task, semanticSeeds, maxSymbols: 2})
|
|
75
|
-
const selected = result.selected.map((entry) => entry.id)
|
|
76
|
-
return {task: item.task, expected: item.expected, selected, success: selected[0] === item.expected, falsePositives: selected.filter((id) => id !== item.expected).length}
|
|
77
|
-
})
|
|
78
|
-
const durationMs = performance.now() - started
|
|
79
|
-
const output = JSON.stringify(cases)
|
|
80
|
-
const imported = readCompetitors(competitorResults)
|
|
81
|
-
const independent = independentComparison(independentResults)
|
|
82
|
-
const competitors = independent.status === 'COMPLETE' ? {
|
|
83
|
-
'codebase-memory': {name: 'codebase-memory', status: 'COMPLETE', metrics: independent.metrics['codebase-memory']},
|
|
84
|
-
serena: {name: 'serena', status: 'COMPLETE', metrics: independent.metrics.serena},
|
|
85
|
-
} : {
|
|
86
|
-
'codebase-memory': imported['codebase-memory'] || competitorTemplate('codebase-memory'),
|
|
87
|
-
serena: imported.serena || competitorTemplate('serena'),
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
schemaVersion: 'weavatrix.agent-task-benchmark.v1',
|
|
91
|
-
scope: 'deterministic task-to-symbol routing microbenchmark; not an end-to-end autonomous change benchmark',
|
|
92
|
-
weavatrix: {
|
|
93
|
-
status: cases.every((item) => item.success) ? 'PASS' : 'FAIL', cases,
|
|
94
|
-
metrics: {
|
|
95
|
-
taskSuccessRate: cases.filter((item) => item.success).length / cases.length,
|
|
96
|
-
falsePositiveRate: cases.reduce((sum, item) => sum + item.falsePositives, 0) / Math.max(1, cases.reduce((sum, item) => sum + item.selected.length, 0)),
|
|
97
|
-
estimatedOutputTokens: Math.ceil(Buffer.byteLength(output) / 4), durationMs: Number(durationMs.toFixed(3)),
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
competitors, independentComparison: independent,
|
|
101
|
-
comparisonStatus: independent.status === 'COMPLETE' ? 'COMPLETE' : 'INCOMPLETE',
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function argument(name) {
|
|
106
|
-
const index = process.argv.indexOf(name)
|
|
107
|
-
return index >= 0 ? process.argv[index + 1] : null
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
111
|
-
const report = runAgentTaskBenchmark({
|
|
112
|
-
competitorResults: argument('--competitor-results'),
|
|
113
|
-
independentResults: argument('--independent-results'),
|
|
114
|
-
})
|
|
115
|
-
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`)
|
|
116
|
-
if ((process.argv.includes('--require-independent') || process.argv.includes('--require-competitors')) && report.comparisonStatus !== 'COMPLETE') process.exitCode = 1
|
|
117
|
-
if (report.weavatrix.status !== 'PASS') process.exitCode = 1
|
|
118
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import {existsSync, readFileSync} from 'node:fs'
|
|
2
|
-
import {join} from 'node:path'
|
|
3
|
-
import {createRepoBoundary} from '../repo-path.js'
|
|
4
|
-
import {runCommand} from '../process.js'
|
|
5
|
-
|
|
6
|
-
const SAFE_SCRIPT = /^(?:test(?::|$)|(?:check|verify)(?::|$)|[^:]+:(?:test|check|verify)(?::|$))/i
|
|
7
|
-
const UNSAFE_SHELL_ARG = /[\0\r\n&|<>^%!`\"]/
|
|
8
|
-
const tail = (value, limit = 8000) => String(value || '').slice(-limit)
|
|
9
|
-
|
|
10
|
-
function manifestAt(repoRoot) {
|
|
11
|
-
const resolved = createRepoBoundary(repoRoot).resolve('package.json')
|
|
12
|
-
if (!resolved.ok) return null
|
|
13
|
-
try { return JSON.parse(readFileSync(resolved.path, 'utf8')) } catch { return null }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function packageManager(repoRoot) {
|
|
17
|
-
if (existsSync(join(repoRoot, 'pnpm-lock.yaml'))) return 'pnpm'
|
|
18
|
-
if (existsSync(join(repoRoot, 'yarn.lock'))) return 'yarn'
|
|
19
|
-
return 'npm'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function normalizeTestRequests(requests = []) {
|
|
23
|
-
const tests = []
|
|
24
|
-
for (const request of (Array.isArray(requests) ? requests : []).slice(0, 5)) {
|
|
25
|
-
const script = String(request?.script || '')
|
|
26
|
-
const args = Array.isArray(request?.args) ? request.args.slice(0, 40).map(String) : []
|
|
27
|
-
if (!SAFE_SCRIPT.test(script)) return {ok: false, reason: `script ${script || '(missing)'} is outside the test/check/verify allowlist`, tests}
|
|
28
|
-
if (args.some((arg) => arg.length > 300 || UNSAFE_SHELL_ARG.test(arg))) return {ok: false, reason: `script ${script} has an invalid or shell-sensitive argument`, tests}
|
|
29
|
-
tests.push({script, args})
|
|
30
|
-
}
|
|
31
|
-
return {ok: true, tests}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function validateTestRequests(repoRoot, requests = []) {
|
|
35
|
-
const normalized = normalizeTestRequests(requests)
|
|
36
|
-
if (!normalized.ok || !normalized.tests.length) return normalized
|
|
37
|
-
const manifest = manifestAt(repoRoot)
|
|
38
|
-
if (!manifest) return {ok: false, reason: 'package.json is missing or unreadable', tests: []}
|
|
39
|
-
for (const test of normalized.tests) {
|
|
40
|
-
if (!Object.hasOwn(manifest.scripts || {}, test.script)) return {ok: false, reason: `package.json has no script named ${test.script}`, tests: []}
|
|
41
|
-
}
|
|
42
|
-
const tests = normalized.tests
|
|
43
|
-
return {ok: true, tests, packageManager: packageManager(repoRoot)}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function runAllowedTests(repoRoot, requests = [], {enabled = false, timeoutMs = 60_000} = {}) {
|
|
47
|
-
const normalized = normalizeTestRequests(requests)
|
|
48
|
-
if (!normalized.ok) return {state: 'BLOCKED', reason: normalized.reason, results: []}
|
|
49
|
-
if (!normalized.tests.length) return {state: 'NOT_REQUESTED', reason: 'no package scripts were requested', plan: [], results: []}
|
|
50
|
-
if (!enabled || process.env.WEAVATRIX_ALLOW_TEST_RUNS !== '1') return {
|
|
51
|
-
state: 'DISABLED', reason: 'set WEAVATRIX_ALLOW_TEST_RUNS=1 and pass run_tests:true to execute allowlisted package scripts',
|
|
52
|
-
plan: normalized.tests, results: [],
|
|
53
|
-
}
|
|
54
|
-
const checked = validateTestRequests(repoRoot, normalized.tests)
|
|
55
|
-
if (!checked.ok) return {state: 'BLOCKED', reason: checked.reason, results: []}
|
|
56
|
-
const results = []
|
|
57
|
-
const timeout = Math.max(1000, Math.min(300_000, Number(timeoutMs) || 60_000))
|
|
58
|
-
for (const test of checked.tests) {
|
|
59
|
-
const start = Date.now()
|
|
60
|
-
const separator = checked.packageManager === 'yarn' ? [] : ['--']
|
|
61
|
-
try {
|
|
62
|
-
const run = await runCommand(checked.packageManager, ['run', test.script, ...separator, ...test.args], {cwd: repoRoot, timeoutMs: timeout})
|
|
63
|
-
results.push({script: test.script, status: run.exitCode === 0 ? 'PASS' : 'FAIL', exitCode: run.exitCode, durationMs: Date.now() - start, stdoutTail: tail(run.stdout), stderrTail: tail(run.stderr)})
|
|
64
|
-
} catch (error) {
|
|
65
|
-
const message = error instanceof Error ? error.message : String(error)
|
|
66
|
-
results.push({script: test.script, status: /timed out/i.test(message) ? 'TIMEOUT' : 'FAIL', exitCode: null, durationMs: Date.now() - start, stdoutTail: '', stderrTail: tail(message)})
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return {state: results.every((result) => result.status === 'PASS') ? 'PASS' : 'FAIL', packageManager: checked.packageManager, results}
|
|
70
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import {architectureHash} from './contract-schema.js'
|
|
2
|
-
|
|
3
|
-
export const isSymbolNode = (id) => String(id).includes('#')
|
|
4
|
-
const endpointId = (value) => value && typeof value === 'object' ? String(value.id) : String(value ?? '')
|
|
5
|
-
|
|
6
|
-
export function fileOfNode(id, byId) {
|
|
7
|
-
const node = byId.get(String(id))
|
|
8
|
-
if (node?.source_file) return String(node.source_file).replace(/\\/g, '/')
|
|
9
|
-
return String(id).split('#')[0].replace(/\\/g, '/')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function componentForFile(file, components) {
|
|
13
|
-
const normalized = String(file || '').replace(/\\/g, '/')
|
|
14
|
-
let best = null
|
|
15
|
-
for (const component of components) for (const prefix of component.paths) {
|
|
16
|
-
if (normalized !== prefix && !normalized.startsWith(`${prefix}/`)) continue
|
|
17
|
-
if (!best || prefix.length > best.prefix.length) best = {id: component.id, prefix}
|
|
18
|
-
}
|
|
19
|
-
return best?.id || '(unmapped)'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function relationKind(link) {
|
|
23
|
-
if (link.typeOnly === true) return 'type-only'
|
|
24
|
-
if (link.compileOnly === true) return 'compile-only'
|
|
25
|
-
return 'runtime'
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function runtimeFileGraph(graph) {
|
|
29
|
-
const byId = new Map((graph.nodes || []).map((node) => [String(node.id), node]))
|
|
30
|
-
const files = new Set((graph.nodes || []).filter((node) => !isSymbolNode(node.id)).map((node) => String(node.id)))
|
|
31
|
-
const adjacency = new Map([...files].map((file) => [file, new Set()]))
|
|
32
|
-
for (const link of graph.links || []) {
|
|
33
|
-
if (relationKind(link) !== 'runtime' || !['imports', 're_exports'].includes(link.relation) || link.barrelProxy === true) continue
|
|
34
|
-
const source = fileOfNode(endpointId(link.source), byId)
|
|
35
|
-
const target = fileOfNode(endpointId(link.target), byId)
|
|
36
|
-
if (source && target && source !== target && files.has(source) && files.has(target)) adjacency.get(source)?.add(target)
|
|
37
|
-
}
|
|
38
|
-
return adjacency
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function stronglyConnected(adjacency) {
|
|
42
|
-
let index = 0
|
|
43
|
-
const indexes = new Map(), low = new Map(), stack = [], onStack = new Set(), out = []
|
|
44
|
-
const visit = (node) => {
|
|
45
|
-
indexes.set(node, index); low.set(node, index); index++; stack.push(node); onStack.add(node)
|
|
46
|
-
for (const target of adjacency.get(node) || []) {
|
|
47
|
-
if (!indexes.has(target)) { visit(target); low.set(node, Math.min(low.get(node), low.get(target))) }
|
|
48
|
-
else if (onStack.has(target)) low.set(node, Math.min(low.get(node), indexes.get(target)))
|
|
49
|
-
}
|
|
50
|
-
if (low.get(node) !== indexes.get(node)) return
|
|
51
|
-
const component = []
|
|
52
|
-
while (stack.length) {
|
|
53
|
-
const value = stack.pop()
|
|
54
|
-
onStack.delete(value)
|
|
55
|
-
component.push(value)
|
|
56
|
-
if (value === node) break
|
|
57
|
-
}
|
|
58
|
-
if (component.length > 1 || adjacency.get(node)?.has(node)) out.push(component.sort())
|
|
59
|
-
}
|
|
60
|
-
for (const node of [...adjacency.keys()].sort()) if (!indexes.has(node)) visit(node)
|
|
61
|
-
return out.sort((a, b) => b.length - a.length || a[0].localeCompare(b[0]))
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function architectureViolation(ruleId, kind, evidence, current, target) {
|
|
65
|
-
const normalizedEvidence = String(evidence).replace(/:\d+(?=\b|$)/g, '')
|
|
66
|
-
const fingerprint = architectureHash({ruleId, kind, evidence: normalizedEvidence}).slice(0, 32)
|
|
67
|
-
return {fingerprint, ruleId, kind, evidence, ...(current != null ? {current} : {}), ...(target != null ? {target} : {})}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const matchComponentSelector = (selector, value) => selector.includes('*') || selector.includes(value)
|
|
71
|
-
|
|
72
|
-
export function collectComponentEdges(graph, contract) {
|
|
73
|
-
const nodes = Array.isArray(graph?.nodes) ? graph.nodes : []
|
|
74
|
-
const links = Array.isArray(graph?.links) ? graph.links : []
|
|
75
|
-
const byId = new Map(nodes.map((node) => [String(node.id), node]))
|
|
76
|
-
const componentEdges = new Map()
|
|
77
|
-
for (const link of links) {
|
|
78
|
-
if (!['imports', 're_exports', 'calls', 'references'].includes(link.relation) || link.barrelProxy === true) continue
|
|
79
|
-
const fromFile = fileOfNode(endpointId(link.source), byId)
|
|
80
|
-
const toFile = fileOfNode(endpointId(link.target), byId)
|
|
81
|
-
if (!fromFile || !toFile || fromFile === toFile) continue
|
|
82
|
-
const from = componentForFile(fromFile, contract.components)
|
|
83
|
-
const to = componentForFile(toFile, contract.components)
|
|
84
|
-
if (from === to) continue
|
|
85
|
-
const kind = relationKind(link)
|
|
86
|
-
const key = `${from}\0${to}\0${kind}`
|
|
87
|
-
const record = componentEdges.get(key) || {from, to, kind, count: 0, samples: []}
|
|
88
|
-
record.count++
|
|
89
|
-
if (record.samples.length < 5) record.samples.push(`${fromFile} -> ${toFile}`)
|
|
90
|
-
componentEdges.set(key, record)
|
|
91
|
-
}
|
|
92
|
-
return {nodes, links, byId, componentEdges}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function collectComponentFitness(nodes, links, byId, contract) {
|
|
96
|
-
const stats = new Map(contract.components.map((component) => [component.id, {
|
|
97
|
-
files: new Set(), internalPairs: new Set(), boundaryPairs: new Set(),
|
|
98
|
-
}]))
|
|
99
|
-
for (const node of nodes.filter((item) => !isSymbolNode(item.id))) {
|
|
100
|
-
const file = String(node.source_file || node.id).replace(/\\/g, '/')
|
|
101
|
-
stats.get(componentForFile(file, contract.components))?.files.add(file)
|
|
102
|
-
}
|
|
103
|
-
const runtimePairs = new Set()
|
|
104
|
-
for (const link of links) {
|
|
105
|
-
if (relationKind(link) !== 'runtime' || !['imports', 're_exports', 'calls', 'references'].includes(link.relation) || link.barrelProxy === true) continue
|
|
106
|
-
const source = fileOfNode(endpointId(link.source), byId), target = fileOfNode(endpointId(link.target), byId)
|
|
107
|
-
if (!source || !target || source === target) continue
|
|
108
|
-
const pair = `${source}\0${target}`
|
|
109
|
-
if (runtimePairs.has(pair)) continue
|
|
110
|
-
runtimePairs.add(pair)
|
|
111
|
-
const from = componentForFile(source, contract.components), to = componentForFile(target, contract.components)
|
|
112
|
-
if (from === to) stats.get(from)?.internalPairs.add(pair)
|
|
113
|
-
else {
|
|
114
|
-
stats.get(from)?.boundaryPairs.add(pair)
|
|
115
|
-
stats.get(to)?.boundaryPairs.add(pair)
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return stats
|
|
119
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import {createHash} from 'node:crypto'
|
|
2
|
-
|
|
3
|
-
export const ARCHITECTURE_CONTRACT_V = 1
|
|
4
|
-
|
|
5
|
-
const RELATION_KIND = new Set(['runtime', 'type-only', 'compile-only', 'any'])
|
|
6
|
-
const ACTION = new Set(['allow', 'forbid'])
|
|
7
|
-
const ENFORCEMENT = new Set(['ratchet', 'strict', 'advisory'])
|
|
8
|
-
|
|
9
|
-
export const safeArchitectureId = (value, fallback = '') => {
|
|
10
|
-
const text = String(value ?? '').trim()
|
|
11
|
-
return /^[a-z0-9][a-z0-9._:-]{0,127}$/i.test(text) ? text : fallback
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const architecturePathPrefix = (value) => {
|
|
15
|
-
const text = String(value ?? '').replace(/\\/g, '/').replace(/^\.\//, '').replace(/^\/+|\/+$/g, '')
|
|
16
|
-
return text && !text.split('/').some((part) => !part || part === '.' || part === '..') ? text : null
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const finiteArchitectureBudget = (value, fallback = null) => {
|
|
20
|
-
const number = Number(value)
|
|
21
|
-
return Number.isFinite(number) && number >= 0 ? number : fallback
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const stringList = (value, sanitize, cap = 100) => [...new Set((Array.isArray(value) ? value : [])
|
|
25
|
-
.slice(0, cap).map(sanitize).filter(Boolean))]
|
|
26
|
-
|
|
27
|
-
const stable = (value) => Array.isArray(value)
|
|
28
|
-
? `[${value.map(stable).join(',')}]`
|
|
29
|
-
: value && typeof value === 'object'
|
|
30
|
-
? `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stable(value[key])}`).join(',')}}`
|
|
31
|
-
: JSON.stringify(value)
|
|
32
|
-
|
|
33
|
-
export const architectureHash = (value) => createHash('sha256').update(stable(value)).digest('hex')
|
|
34
|
-
|
|
35
|
-
function sanitizeComponent(value, index) {
|
|
36
|
-
const id = safeArchitectureId(value?.id, `component-${index + 1}`)
|
|
37
|
-
const paths = stringList(value?.paths ?? [value?.path], architecturePathPrefix, 64)
|
|
38
|
-
if (!paths.length) return null
|
|
39
|
-
return {id, name: String(value?.name || id).slice(0, 128), paths}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function sanitizeRule(value, index) {
|
|
43
|
-
const from = stringList(value?.from, (item) => item === '*' ? '*' : safeArchitectureId(item), 64)
|
|
44
|
-
const to = stringList(value?.to, (item) => item === '*' ? '*' : safeArchitectureId(item), 64)
|
|
45
|
-
if (!from.length || !to.length) return null
|
|
46
|
-
return {
|
|
47
|
-
id: safeArchitectureId(value?.id, `dependency-${index + 1}`),
|
|
48
|
-
action: ACTION.has(value?.action) ? value.action : 'forbid',
|
|
49
|
-
kinds: stringList(value?.kinds ?? ['runtime'], (kind) => RELATION_KIND.has(kind) ? kind : '', 4),
|
|
50
|
-
from,
|
|
51
|
-
to,
|
|
52
|
-
...(value?.reason ? {reason: String(value.reason).slice(0, 300)} : {}),
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function sanitizeException(value) {
|
|
57
|
-
const fingerprint = /^[a-f0-9]{16,64}$/i.test(String(value?.fingerprint || '')) ? String(value.fingerprint) : null
|
|
58
|
-
if (!fingerprint) return null
|
|
59
|
-
const expires = /^\d{4}-\d{2}-\d{2}$/.test(String(value?.expires || '')) ? String(value.expires) : null
|
|
60
|
-
return {fingerprint, reason: String(value?.reason || '').slice(0, 300), ...(expires ? {expires} : {})}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function normalizeBudgets(raw = {}) {
|
|
64
|
-
const budgets = {
|
|
65
|
-
runtimeCycles: finiteArchitectureBudget(raw.runtimeCycles),
|
|
66
|
-
maxFunctionLoc: finiteArchitectureBudget(raw.maxFunctionLoc),
|
|
67
|
-
maxFileLoc: finiteArchitectureBudget(raw.maxFileLoc),
|
|
68
|
-
maxCyclomatic: finiteArchitectureBudget(raw.maxCyclomatic),
|
|
69
|
-
maxParams: finiteArchitectureBudget(raw.maxParams),
|
|
70
|
-
maxRuntimeDependenciesPerComponent: finiteArchitectureBudget(raw.maxRuntimeDependenciesPerComponent),
|
|
71
|
-
maxModuleFiles: finiteArchitectureBudget(raw.maxModuleFiles),
|
|
72
|
-
minModuleCohesion: finiteArchitectureBudget(raw.minModuleCohesion),
|
|
73
|
-
maxModuleBoundaryRatio: finiteArchitectureBudget(raw.maxModuleBoundaryRatio),
|
|
74
|
-
}
|
|
75
|
-
for (const key of Object.keys(budgets)) if (budgets[key] == null) delete budgets[key]
|
|
76
|
-
return budgets
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function normalizeArchitectureContract(input) {
|
|
80
|
-
if (!input || typeof input !== 'object' || Array.isArray(input)) throw new Error('architecture contract must be an object')
|
|
81
|
-
const components = (Array.isArray(input.components) ? input.components : [])
|
|
82
|
-
.slice(0, 200).map(sanitizeComponent).filter(Boolean)
|
|
83
|
-
const componentIds = new Set(components.map((item) => item.id))
|
|
84
|
-
const dependencyRules = (Array.isArray(input.dependencyRules) ? input.dependencyRules : [])
|
|
85
|
-
.slice(0, 500).map(sanitizeRule).filter(Boolean)
|
|
86
|
-
.filter((rule) => [...rule.from, ...rule.to].every((id) => id === '*' || componentIds.has(id)))
|
|
87
|
-
const baseline = input.ratchet?.baseline && typeof input.ratchet.baseline === 'object'
|
|
88
|
-
? {
|
|
89
|
-
fingerprints: stringList(input.ratchet.baseline.fingerprints, (item) => /^[a-f0-9]{16,64}$/i.test(String(item)) ? String(item) : '', 5_000),
|
|
90
|
-
metrics: Object.fromEntries(Object.entries(input.ratchet.baseline.metrics || {}).slice(0, 500)
|
|
91
|
-
.map(([key, value]) => [safeArchitectureId(key), finiteArchitectureBudget(value)]).filter(([key, value]) => key && value != null)),
|
|
92
|
-
}
|
|
93
|
-
: {fingerprints: [], metrics: {}}
|
|
94
|
-
const contract = {
|
|
95
|
-
architectureContractV: ARCHITECTURE_CONTRACT_V,
|
|
96
|
-
name: String(input.name || 'Target architecture').slice(0, 128),
|
|
97
|
-
style: safeArchitectureId(input.style, 'custom'),
|
|
98
|
-
enforcement: ENFORCEMENT.has(input.enforcement) ? input.enforcement : 'ratchet',
|
|
99
|
-
components,
|
|
100
|
-
dependencyRules,
|
|
101
|
-
budgets: normalizeBudgets(input.budgets),
|
|
102
|
-
technologies: {
|
|
103
|
-
required: stringList(input.technologies?.required, (item) => safeArchitectureId(item), 100),
|
|
104
|
-
forbidden: stringList(input.technologies?.forbidden, (item) => safeArchitectureId(item), 100),
|
|
105
|
-
},
|
|
106
|
-
exceptions: (Array.isArray(input.exceptions) ? input.exceptions : []).slice(0, 500).map(sanitizeException).filter(Boolean),
|
|
107
|
-
ratchet: {baseline},
|
|
108
|
-
}
|
|
109
|
-
return {...contract, contractHash: architectureHash(contract)}
|
|
110
|
-
}
|