weavatrix 0.3.13 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 -65
- 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.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.js +0 -235
- 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 -62
- package/src/analysis/endpoints/extract.js +0 -107
- 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 -295
- 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 -154
- 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 -173
- 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 -174
- package/src/mcp/health/dead-code.mjs +0 -110
- package/src/mcp/health/duplicates.mjs +0 -85
- package/src/mcp/health/endpoints.mjs +0 -71
- package/src/mcp/health/structure.mjs +0 -219
- 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 -220
- 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
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import {existsSync, readFileSync} from 'node:fs'
|
|
2
|
-
import {dirname, resolve} from 'node:path'
|
|
3
|
-
import {atomicWriteFileSync} from '../../graph/file-lock.js'
|
|
4
|
-
import {edgeProvenance} from '../../graph/edge-provenance.js'
|
|
5
|
-
import {
|
|
6
|
-
PRECISION_FILE,
|
|
7
|
-
PRECISION_OVERLAY_V,
|
|
8
|
-
baseOverlay,
|
|
9
|
-
endpoint,
|
|
10
|
-
precisionOverlayMatches,
|
|
11
|
-
} from './contract.js'
|
|
12
|
-
|
|
13
|
-
export function precisionPathForGraph(graphPath) {
|
|
14
|
-
return resolve(dirname(graphPath), PRECISION_FILE)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function readPrecisionOverlay(graphPath, graph) {
|
|
18
|
-
const path = precisionPathForGraph(graphPath)
|
|
19
|
-
if (!existsSync(path)) return null
|
|
20
|
-
try {
|
|
21
|
-
const overlay = JSON.parse(readFileSync(path, 'utf8'))
|
|
22
|
-
return precisionOverlayMatches(overlay, graph) ? overlay : null
|
|
23
|
-
} catch { return null }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function precisionSummary(overlay) {
|
|
27
|
-
if (!overlay) return {
|
|
28
|
-
state: 'UNAVAILABLE',
|
|
29
|
-
provider: null,
|
|
30
|
-
verifiedEdges: 0,
|
|
31
|
-
candidates: 0,
|
|
32
|
-
queried: 0,
|
|
33
|
-
reason: 'no revision-matched precision overlay',
|
|
34
|
-
}
|
|
35
|
-
const engine = Array.isArray(overlay.engines) ? overlay.engines[0] : null
|
|
36
|
-
return {
|
|
37
|
-
state: String(overlay.state || 'UNAVAILABLE'),
|
|
38
|
-
provider: engine?.provider || null,
|
|
39
|
-
providerVersion: engine?.version || null,
|
|
40
|
-
typescriptVersion: engine?.typescriptVersion || null,
|
|
41
|
-
verifiedEdges: Number(overlay.coverage?.verifiedEdges) || 0,
|
|
42
|
-
candidates: Number(overlay.coverage?.candidates) || 0,
|
|
43
|
-
selected: Number(overlay.coverage?.selected) || 0,
|
|
44
|
-
queried: Number(overlay.coverage?.queried) || 0,
|
|
45
|
-
references: Number(overlay.coverage?.references) || 0,
|
|
46
|
-
unclassifiedReferences: Number(overlay.coverage?.unclassifiedReferences) || 0,
|
|
47
|
-
referenceEvidence: Array.isArray(overlay.referenceEvidence) ? overlay.referenceEvidence.length : 0,
|
|
48
|
-
truncated: overlay.coverage?.truncated === true,
|
|
49
|
-
reason: overlay.reason || engine?.reason || null,
|
|
50
|
-
noReferenceSymbols: Array.isArray(overlay.noReferenceSymbols) ? overlay.noReferenceSymbols.length : 0,
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function mergePrecisionOverlay(graph, overlay) {
|
|
55
|
-
if (!precisionOverlayMatches(overlay, graph)) return {...graph, precision: precisionSummary(null)}
|
|
56
|
-
const nodes = Array.isArray(graph.nodes) ? graph.nodes : []
|
|
57
|
-
const ids = new Set(nodes.map((node) => String(node.id)))
|
|
58
|
-
const links = (Array.isArray(graph.links) ? graph.links : []).map((link) => ({...link}))
|
|
59
|
-
for (const exact of Array.isArray(overlay.links) ? overlay.links : []) {
|
|
60
|
-
const source = endpoint(exact.source)
|
|
61
|
-
const target = endpoint(exact.target)
|
|
62
|
-
if (!ids.has(source) || !ids.has(target) || source === target) continue
|
|
63
|
-
const relation = String(exact.relation || 'references')
|
|
64
|
-
const exactLine = Number.isInteger(exact.line) ? exact.line : null
|
|
65
|
-
const exactCharacter = Number.isInteger(exact.character) ? exact.character : null
|
|
66
|
-
let matched = false
|
|
67
|
-
for (const link of links) {
|
|
68
|
-
if (edgeProvenance(link) !== 'EXACT_LSP') continue
|
|
69
|
-
if (endpoint(link.source) !== source || endpoint(link.target) !== target
|
|
70
|
-
|| String(link.relation || '') !== relation) continue
|
|
71
|
-
if (exactLine != null && (!Number.isInteger(link.line) || link.line !== exactLine)) continue
|
|
72
|
-
if (exactCharacter != null
|
|
73
|
-
&& (!Number.isInteger(link.character) || link.character !== exactCharacter)) continue
|
|
74
|
-
link.provenance = 'EXACT_LSP'
|
|
75
|
-
link.confidence = 'EXACT_LSP'
|
|
76
|
-
link.precisionProvider = String(exact.provider || 'typescript-language-server')
|
|
77
|
-
if (exact.typeOnly === true) link.typeOnly = true
|
|
78
|
-
else delete link.typeOnly
|
|
79
|
-
if (exact.compileOnly === true) link.compileOnly = true
|
|
80
|
-
else delete link.compileOnly
|
|
81
|
-
matched = true
|
|
82
|
-
break
|
|
83
|
-
}
|
|
84
|
-
if (!matched) links.push({
|
|
85
|
-
source,
|
|
86
|
-
target,
|
|
87
|
-
relation: relation || 'references',
|
|
88
|
-
provenance: 'EXACT_LSP',
|
|
89
|
-
confidence: 'EXACT_LSP',
|
|
90
|
-
precisionProvider: String(exact.provider || 'typescript-language-server'),
|
|
91
|
-
...(exact.typeOnly === true ? {typeOnly: true} : {}),
|
|
92
|
-
...(exact.compileOnly === true ? {compileOnly: true} : {}),
|
|
93
|
-
...(exactLine != null ? {line: exactLine} : {}),
|
|
94
|
-
...(exactCharacter != null ? {character: exactCharacter} : {}),
|
|
95
|
-
...(Number.isInteger(exact.endLine) ? {endLine: exact.endLine} : {}),
|
|
96
|
-
...(Number.isInteger(exact.endCharacter) ? {endCharacter: exact.endCharacter} : {}),
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
...graph,
|
|
101
|
-
links,
|
|
102
|
-
precisionOverlayV: PRECISION_OVERLAY_V,
|
|
103
|
-
precision: precisionSummary(overlay),
|
|
104
|
-
precisionNoReferenceSymbols: Array.isArray(overlay.noReferenceSymbols)
|
|
105
|
-
? overlay.noReferenceSymbols.filter((id) => ids.has(String(id))).map(String) : [],
|
|
106
|
-
precisionReferenceEvidence: Array.isArray(overlay.referenceEvidence)
|
|
107
|
-
? overlay.referenceEvidence.filter((evidence) => ids.has(endpoint(evidence.source))
|
|
108
|
-
&& ids.has(endpoint(evidence.target))).map((evidence) => ({
|
|
109
|
-
source: endpoint(evidence.source),
|
|
110
|
-
target: endpoint(evidence.target),
|
|
111
|
-
...(Number.isInteger(evidence.line) ? {line: evidence.line} : {}),
|
|
112
|
-
...(Number.isInteger(evidence.character) ? {character: evidence.character} : {}),
|
|
113
|
-
classification: String(evidence.classification || 'unknown'),
|
|
114
|
-
provider: String(evidence.provider || 'typescript-language-server'),
|
|
115
|
-
})) : [],
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function writePrecisionOverlay(graphPath, overlay) {
|
|
120
|
-
atomicWriteFileSync(precisionPathForGraph(graphPath), JSON.stringify(overlay), 'utf8')
|
|
121
|
-
return overlay
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const SAFE_INVALIDATION_REASON = 'repository changed while semantic precision was running'
|
|
125
|
-
|
|
126
|
-
export function invalidatePrecisionOverlay(graphPath, graph, reason = SAFE_INVALIDATION_REASON) {
|
|
127
|
-
if (!graphPath || !graph) throw new Error('precision invalidation requires graphPath and graph')
|
|
128
|
-
const previous = readPrecisionOverlay(graphPath, graph)
|
|
129
|
-
const safeReason = typeof reason === 'string'
|
|
130
|
-
&& reason.length > 0 && reason.length <= 160
|
|
131
|
-
&& /^[A-Za-z0-9 _.,()-]+$/.test(reason) ? reason : SAFE_INVALIDATION_REASON
|
|
132
|
-
const engines = (Array.isArray(previous?.engines) && previous.engines.length
|
|
133
|
-
? previous.engines
|
|
134
|
-
: [{
|
|
135
|
-
provider: 'typescript-language-server', version: null,
|
|
136
|
-
language: 'typescript/javascript', capability: 'textDocument/references',
|
|
137
|
-
}]).map((engine) => ({...engine, status: 'PARTIAL'}))
|
|
138
|
-
return writePrecisionOverlay(graphPath, baseOverlay(graph, 'PARTIAL', {
|
|
139
|
-
...(previous?.request ? {request: previous.request} : {}),
|
|
140
|
-
reason: safeReason,
|
|
141
|
-
engines,
|
|
142
|
-
coverage: {
|
|
143
|
-
candidates: 0, selected: 0, queried: 0, references: 0,
|
|
144
|
-
unclassifiedReferences: 0, verifiedEdges: 0, truncated: true,
|
|
145
|
-
},
|
|
146
|
-
links: [],
|
|
147
|
-
referenceEvidence: [],
|
|
148
|
-
noReferenceSymbols: [],
|
|
149
|
-
}))
|
|
150
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import {realpathSync} from 'node:fs'
|
|
2
|
-
import {isAbsolute, relative, resolve, sep} from 'node:path'
|
|
3
|
-
import {fileURLToPath} from 'node:url'
|
|
4
|
-
import {edgeProvenance} from '../../graph/edge-provenance.js'
|
|
5
|
-
import {isStructuralRelation} from '../../graph/relations.js'
|
|
6
|
-
import {isPathInside} from '../../repo-path.js'
|
|
7
|
-
import {JS_TS_FILE, endpoint, norm} from './contract.js'
|
|
8
|
-
|
|
9
|
-
const lineNumber = (value) => {
|
|
10
|
-
const match = /L(\d+)/.exec(String(value || ''))
|
|
11
|
-
return match ? Number(match[1]) : 0
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function repoFileFromLocation(repoRoot, location) {
|
|
15
|
-
if (location?.file) {
|
|
16
|
-
try {
|
|
17
|
-
const root = realpathSync.native(repoRoot)
|
|
18
|
-
const path = realpathSync.native(resolve(root, String(location.file)))
|
|
19
|
-
if (!isPathInside(root, path)) return null
|
|
20
|
-
const rel = relative(root, path)
|
|
21
|
-
return rel && !rel.startsWith(`..${sep}`) && !isAbsolute(rel) ? norm(rel) : null
|
|
22
|
-
} catch { return null }
|
|
23
|
-
}
|
|
24
|
-
const uri = typeof location === 'string' ? location : location?.uri || location?.targetUri
|
|
25
|
-
if (!uri || !String(uri).startsWith('file:')) return null
|
|
26
|
-
try {
|
|
27
|
-
const root = realpathSync.native(repoRoot)
|
|
28
|
-
const path = realpathSync.native(fileURLToPath(uri))
|
|
29
|
-
if (!isPathInside(root, path)) return null
|
|
30
|
-
const rel = relative(root, path)
|
|
31
|
-
if (!rel || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) return null
|
|
32
|
-
return norm(rel)
|
|
33
|
-
} catch { return null }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function locationStart(location) {
|
|
37
|
-
return location?.range?.start || location?.targetSelectionRange?.start
|
|
38
|
-
|| location?.targetRange?.start || null
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const comparePosition = (left, right) => left.line - right.line || left.character - right.character
|
|
42
|
-
|
|
43
|
-
export function symbolIndex(graph) {
|
|
44
|
-
const files = new Set()
|
|
45
|
-
const byFile = new Map()
|
|
46
|
-
for (const node of graph.nodes || []) {
|
|
47
|
-
const id = String(node.id)
|
|
48
|
-
const file = norm(node.source_file || (id.includes('#') ? id.slice(0, id.indexOf('#')) : id))
|
|
49
|
-
if (!file) continue
|
|
50
|
-
if (!id.includes('#')) files.add(file)
|
|
51
|
-
else {
|
|
52
|
-
const start = lineNumber(node.source_location) || Number(node.selection_start?.line) + 1 || 0
|
|
53
|
-
const end = lineNumber(node.source_end) || start
|
|
54
|
-
if (!start) continue
|
|
55
|
-
const range = node.source_range
|
|
56
|
-
const hasRange = Number.isInteger(range?.start?.line)
|
|
57
|
-
&& Number.isInteger(range?.start?.character)
|
|
58
|
-
&& Number.isInteger(range?.end?.line)
|
|
59
|
-
&& Number.isInteger(range?.end?.character)
|
|
60
|
-
const rows = byFile.get(file) || []
|
|
61
|
-
rows.push({id, start, end: Math.max(start, end), ...(hasRange ? {range} : {})})
|
|
62
|
-
byFile.set(file, rows)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
for (const rows of byFile.values()) rows.sort((a, b) => {
|
|
66
|
-
if (a.range && b.range) {
|
|
67
|
-
return comparePosition(b.range.start, a.range.start)
|
|
68
|
-
|| comparePosition(a.range.end, b.range.end)
|
|
69
|
-
|| a.id.localeCompare(b.id)
|
|
70
|
-
}
|
|
71
|
-
return (a.end - a.start) - (b.end - b.start) || b.start - a.start || a.id.localeCompare(b.id)
|
|
72
|
-
})
|
|
73
|
-
return {files, byFile}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function sourceAt(index, file, position) {
|
|
77
|
-
if (!Number.isInteger(position?.line) || !Number.isInteger(position?.character)) {
|
|
78
|
-
return index.files.has(file) ? file : null
|
|
79
|
-
}
|
|
80
|
-
const line = position.line + 1
|
|
81
|
-
const rows = (index.byFile.get(file) || []).filter((row) => row.range
|
|
82
|
-
? comparePosition(row.range.start, position) <= 0 && comparePosition(position, row.range.end) < 0
|
|
83
|
-
: row.start < line && line < row.end)
|
|
84
|
-
if (rows.length) {
|
|
85
|
-
const first = rows[0]
|
|
86
|
-
const span = first.range ? null : first.end - first.start
|
|
87
|
-
const tied = rows.filter((row) => {
|
|
88
|
-
if (first.range || row.range) return Boolean(first.range && row.range
|
|
89
|
-
&& comparePosition(first.range.start, row.range.start) === 0
|
|
90
|
-
&& comparePosition(first.range.end, row.range.end) === 0)
|
|
91
|
-
return row.end - row.start === span
|
|
92
|
-
})
|
|
93
|
-
if (tied.length === 1) return tied[0].id
|
|
94
|
-
}
|
|
95
|
-
return index.files.has(file) ? file : null
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function eligibleTargets(graph, limit, requestedIds = null) {
|
|
99
|
-
const byId = new Map((graph.nodes || []).map((node) => [String(node.id), node]))
|
|
100
|
-
if (Array.isArray(requestedIds) && requestedIds.length) {
|
|
101
|
-
const ids = [...new Set(requestedIds.map(String))]
|
|
102
|
-
const eligible = ids.map((id) => byId.get(id))
|
|
103
|
-
.filter((node) => node?.selection_start && JS_TS_FILE.test(String(node.source_file || '')))
|
|
104
|
-
// total counts only eligible targets so coverage fractions stay honest when ids were dropped.
|
|
105
|
-
return {
|
|
106
|
-
targets: eligible.slice(0, limit),
|
|
107
|
-
total: eligible.length,
|
|
108
|
-
droppedRequested: ids.length - eligible.length,
|
|
109
|
-
orphanIds: new Set(),
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const ranked = new Map()
|
|
113
|
-
const inbound = new Set()
|
|
114
|
-
for (const link of graph.links || []) {
|
|
115
|
-
const relation = String(link.relation || '')
|
|
116
|
-
if (!isStructuralRelation(relation)) inbound.add(endpoint(link.target))
|
|
117
|
-
if (isStructuralRelation(relation)
|
|
118
|
-
|| !['calls', 'references', 'inherits', 'implements'].includes(relation)) continue
|
|
119
|
-
if (edgeProvenance(link) === 'EXACT_LSP') continue
|
|
120
|
-
const target = endpoint(link.target)
|
|
121
|
-
const node = byId.get(target)
|
|
122
|
-
if (!node?.selection_start || !JS_TS_FILE.test(String(node.source_file || ''))) continue
|
|
123
|
-
const score = (relation === 'calls' ? 30 : relation === 'inherits' || relation === 'implements' ? 20 : 10)
|
|
124
|
-
+ (edgeProvenance(link) === 'INFERRED' ? 8 : 0)
|
|
125
|
-
ranked.set(target, Math.max(ranked.get(target) || 0, score))
|
|
126
|
-
}
|
|
127
|
-
const orphans = new Set()
|
|
128
|
-
for (const node of byId.values()) {
|
|
129
|
-
const id = String(node.id)
|
|
130
|
-
const visibility = String(node.visibility || '').toLowerCase()
|
|
131
|
-
if (!node.selection_start || !JS_TS_FILE.test(String(node.source_file || '')) || inbound.has(id)) continue
|
|
132
|
-
if (node.exported === true || visibility === 'public' || visibility === 'protected') continue
|
|
133
|
-
if (!/\(\)$/.test(String(node.label || ''))
|
|
134
|
-
&& !['function', 'method', 'constructor'].includes(String(node.symbol_kind || '').toLowerCase())) continue
|
|
135
|
-
if (!ranked.has(id)) { ranked.set(id, 4); orphans.add(id) }
|
|
136
|
-
}
|
|
137
|
-
const all = [...ranked.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
138
|
-
const positive = all.filter(([id]) => !orphans.has(id))
|
|
139
|
-
const orphan = all.filter(([id]) => orphans.has(id))
|
|
140
|
-
const reserve = orphan.length ? Math.min(8, Math.ceil(limit / 4), limit) : 0
|
|
141
|
-
const selected = positive.slice(0, Math.max(0, limit - reserve))
|
|
142
|
-
selected.push(...orphan.slice(0, reserve))
|
|
143
|
-
if (selected.length < limit) {
|
|
144
|
-
const selectedIds = new Set(selected.map(([id]) => id))
|
|
145
|
-
selected.push(...all.filter(([id]) => !selectedIds.has(id)).slice(0, limit - selected.length))
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
targets: selected.map(([id]) => byId.get(id)),
|
|
149
|
-
total: all.length,
|
|
150
|
-
orphanIds: new Set(orphan.map(([id]) => id)),
|
|
151
|
-
}
|
|
152
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {isStructuralRelation} from '../../graph/relations.js'
|
|
2
|
-
import {JS_TS_FILE, endpoint, norm} from './contract.js'
|
|
3
|
-
import {
|
|
4
|
-
ensureBudget,
|
|
5
|
-
ensureFullUniverse,
|
|
6
|
-
ensureOpen,
|
|
7
|
-
requestReferences,
|
|
8
|
-
} from './source-session.js'
|
|
9
|
-
|
|
10
|
-
function supportFilesFor(session, target, relPath) {
|
|
11
|
-
const supportFiles = []
|
|
12
|
-
for (const link of session.graph.links || []) {
|
|
13
|
-
if (endpoint(link.target) !== String(target.id) || isStructuralRelation(link.relation)) continue
|
|
14
|
-
const sourceId = endpoint(link.source)
|
|
15
|
-
const sourceFile = norm(session.nodesById.get(sourceId)?.source_file
|
|
16
|
-
|| (sourceId.includes('#') ? sourceId.slice(0, sourceId.indexOf('#')) : sourceId))
|
|
17
|
-
if (sourceFile && JS_TS_FILE.test(sourceFile)
|
|
18
|
-
&& sourceFile !== relPath && !supportFiles.includes(sourceFile)) supportFiles.push(sourceFile)
|
|
19
|
-
if (supportFiles.length >= 12) break
|
|
20
|
-
}
|
|
21
|
-
return supportFiles
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function queryPrecisionTarget(session, target) {
|
|
25
|
-
const relPath = norm(target.source_file)
|
|
26
|
-
await ensureOpen(session, relPath)
|
|
27
|
-
for (const file of supportFilesFor(session, target, relPath)) await ensureOpen(session, file)
|
|
28
|
-
if (session.universe.complete
|
|
29
|
-
&& session.universe.files.every((file) => session.opened.has(file))) {
|
|
30
|
-
session.fullUniverseOpened = true
|
|
31
|
-
}
|
|
32
|
-
let locations = await requestReferences(session, relPath, target.selection_start)
|
|
33
|
-
if (!Array.isArray(locations)) throw new Error('language server returned an invalid references result')
|
|
34
|
-
session.queried++
|
|
35
|
-
if (locations.length !== 0) return locations
|
|
36
|
-
ensureBudget(session)
|
|
37
|
-
const configRel = session.semanticInputs.fileConfigs?.[relPath]
|
|
38
|
-
const project = configRel ? session.semanticInputs.projects?.[configRel] : null
|
|
39
|
-
const configuredFiles = [...new Set((project?.projectFiles || [])
|
|
40
|
-
.map(norm).filter((file) => JS_TS_FILE.test(file)))].sort()
|
|
41
|
-
const projectFiles = new Set(configuredFiles)
|
|
42
|
-
const exactlyCoversUniverse = session.universe.complete
|
|
43
|
-
&& configuredFiles.length === session.universe.files.length
|
|
44
|
-
&& session.universe.files.every((file) => projectFiles.has(file))
|
|
45
|
-
ensureBudget(session)
|
|
46
|
-
if (configRel && projectFiles.has(relPath) && exactlyCoversUniverse) {
|
|
47
|
-
const alreadyComplete = session.fullUniverseOpened
|
|
48
|
-
if (alreadyComplete || await ensureFullUniverse(session)) {
|
|
49
|
-
if (!alreadyComplete) locations = await requestReferences(session, relPath, target.selection_start)
|
|
50
|
-
if (!Array.isArray(locations)) throw new Error('language server returned an invalid references result')
|
|
51
|
-
if (locations.length === 0) session.noReferenceSymbols.push(String(target.id))
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return locations
|
|
55
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export {PRECISION_FILE, PRECISION_OVERLAY_V, precisionOverlayMatches} from './lsp-overlay/contract.js'
|
|
2
|
-
export {
|
|
3
|
-
invalidatePrecisionOverlay,
|
|
4
|
-
mergePrecisionOverlay,
|
|
5
|
-
precisionPathForGraph,
|
|
6
|
-
precisionSummary,
|
|
7
|
-
readPrecisionOverlay,
|
|
8
|
-
writePrecisionOverlay,
|
|
9
|
-
} from './lsp-overlay/store.js'
|
|
10
|
-
export {precisionSemanticInputs, precisionSemanticInputsMatch} from './lsp-overlay/semantic-inputs.js'
|
|
11
|
-
export {buildLspPrecisionOverlay} from './lsp-overlay/build.js'
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import {existsSync, readFileSync, statSync} from 'node:fs'
|
|
2
|
-
import {dirname, resolve} from 'node:path'
|
|
3
|
-
import {boundedInteger} from '../bounds.js'
|
|
4
|
-
import {atomicWriteFileSync, withFileLock} from '../graph/file-lock.js'
|
|
5
|
-
import {
|
|
6
|
-
buildLspPrecisionOverlay,
|
|
7
|
-
precisionOverlayMatches,
|
|
8
|
-
precisionSemanticInputsMatch,
|
|
9
|
-
} from './lsp-overlay.js'
|
|
10
|
-
import {createPathClassifier, hasPathClass} from '../path-classification.js'
|
|
11
|
-
|
|
12
|
-
const SYMBOL_PRECISION_CACHE_V = 1
|
|
13
|
-
const SYMBOL_PRECISION_CACHE_FILE = 'precision-symbols.json'
|
|
14
|
-
|
|
15
|
-
const MAX_CACHE_ENTRIES = 32
|
|
16
|
-
const MAX_CACHE_BYTES = 8 * 1024 * 1024
|
|
17
|
-
const MAX_CACHE_READ_BYTES = 16 * 1024 * 1024
|
|
18
|
-
const inFlight = new Map()
|
|
19
|
-
|
|
20
|
-
export function symbolPrecisionCachePath(graphPath) {
|
|
21
|
-
return resolve(dirname(graphPath), SYMBOL_PRECISION_CACHE_FILE)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function loadRawGraph(graphPath) {
|
|
25
|
-
const graph = JSON.parse(readFileSync(graphPath, 'utf8'))
|
|
26
|
-
if (!graph || !Array.isArray(graph.nodes) || !Array.isArray(graph.links)) {
|
|
27
|
-
throw new Error('the active graph is not a valid Weavatrix graph')
|
|
28
|
-
}
|
|
29
|
-
return graph
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function emptyCache() {
|
|
33
|
-
return {symbolPrecisionCacheV: SYMBOL_PRECISION_CACHE_V, entries: []}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function readCache(path) {
|
|
37
|
-
if (!existsSync(path)) return emptyCache()
|
|
38
|
-
try {
|
|
39
|
-
if (statSync(path).size > MAX_CACHE_READ_BYTES) return emptyCache()
|
|
40
|
-
const value = JSON.parse(readFileSync(path, 'utf8'))
|
|
41
|
-
if (Number(value?.symbolPrecisionCacheV) !== SYMBOL_PRECISION_CACHE_V || !Array.isArray(value.entries)) return emptyCache()
|
|
42
|
-
return {symbolPrecisionCacheV: SYMBOL_PRECISION_CACHE_V, entries: value.entries.slice(0, MAX_CACHE_ENTRIES)}
|
|
43
|
-
} catch {
|
|
44
|
-
return emptyCache()
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function writeBoundedCache(path, entries) {
|
|
49
|
-
const kept = entries
|
|
50
|
-
.filter((entry) => entry && typeof entry === 'object')
|
|
51
|
-
.sort((left, right) => Number(right.usedAt) - Number(left.usedAt))
|
|
52
|
-
.slice(0, MAX_CACHE_ENTRIES)
|
|
53
|
-
let body
|
|
54
|
-
do {
|
|
55
|
-
body = JSON.stringify({symbolPrecisionCacheV: SYMBOL_PRECISION_CACHE_V, entries: kept})
|
|
56
|
-
if (Buffer.byteLength(body) <= MAX_CACHE_BYTES || !kept.length) break
|
|
57
|
-
kept.pop()
|
|
58
|
-
} while (true)
|
|
59
|
-
atomicWriteFileSync(path, body, 'utf8')
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function cacheMatch(entry, {targetId, graph, repoRoot, request}) {
|
|
63
|
-
if (String(entry?.targetId || '') !== targetId || !entry.overlay) return false
|
|
64
|
-
if (!precisionOverlayMatches(entry.overlay, graph, {request})) return false
|
|
65
|
-
return precisionSemanticInputsMatch(entry.overlay, repoRoot, graph)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async function storeEntry(path, entry) {
|
|
69
|
-
await withFileLock(`${path}.lock`, async () => {
|
|
70
|
-
const current = readCache(path)
|
|
71
|
-
const entries = current.entries.filter((item) => String(item?.targetId || '') !== entry.targetId)
|
|
72
|
-
entries.unshift(entry)
|
|
73
|
-
writeBoundedCache(path, entries)
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function cacheable(overlay) {
|
|
78
|
-
// NONE is stable for the fingerprint, but only COMPLETE ever proves absence (see reader below).
|
|
79
|
-
if (overlay?.state === 'COMPLETE' || overlay?.state === 'NONE') return true
|
|
80
|
-
return overlay?.state === 'PARTIAL'
|
|
81
|
-
&& overlay?.reason === 'semantic precision stopped at a configured safety limit'
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Point-query results intentionally live outside the broad precision overlay. Health tools still
|
|
85
|
-
// need to consume revision-bound positive evidence: once an exact query found a reference, the
|
|
86
|
-
// same symbol must not remain in a dead-code queue. This reader is synchronous and fail-closed;
|
|
87
|
-
// stale, malformed, incomplete no-reference, or semantically changed entries contribute nothing.
|
|
88
|
-
export function readCachedSymbolPrecisionEvidence({repoRoot, graphPath, graph} = {}) {
|
|
89
|
-
const empty = {referenceSymbols: [], productionReferenceSymbols: [], testReferenceSymbols: [], noReferenceSymbols: []}
|
|
90
|
-
if (!repoRoot || !graphPath || !graph) return empty
|
|
91
|
-
const precisionGraph = graph.graphPrecisionMode === 'off' ? {...graph, graphPrecisionMode: 'lsp'} : graph
|
|
92
|
-
const nodesById = new Map((precisionGraph.nodes || []).map((node) => [String(node.id), node]))
|
|
93
|
-
const classifier = createPathClassifier(repoRoot)
|
|
94
|
-
const referenced = new Set()
|
|
95
|
-
const production = new Set()
|
|
96
|
-
const tests = new Set()
|
|
97
|
-
const noReference = new Set()
|
|
98
|
-
const semanticMatches = new Map()
|
|
99
|
-
for (const entry of readCache(symbolPrecisionCachePath(graphPath)).entries) {
|
|
100
|
-
const overlay = entry?.overlay
|
|
101
|
-
if (!overlay || !precisionOverlayMatches(overlay, precisionGraph, {request: overlay.request})) continue
|
|
102
|
-
const fingerprint = String(overlay.semanticInputFingerprint || '')
|
|
103
|
-
if (!semanticMatches.has(fingerprint)) semanticMatches.set(
|
|
104
|
-
fingerprint,
|
|
105
|
-
precisionSemanticInputsMatch(overlay, repoRoot, precisionGraph),
|
|
106
|
-
)
|
|
107
|
-
if (!semanticMatches.get(fingerprint)) continue
|
|
108
|
-
const targetId = String(entry.targetId || '')
|
|
109
|
-
if (!nodesById.has(targetId)) continue
|
|
110
|
-
const locations = Array.isArray(overlay.locations)
|
|
111
|
-
? overlay.locations.filter((location) => String(location?.target || '') === targetId)
|
|
112
|
-
: []
|
|
113
|
-
if (locations.length) {
|
|
114
|
-
referenced.add(targetId)
|
|
115
|
-
for (const location of locations) {
|
|
116
|
-
const file = String(location?.file || nodesById.get(String(location?.source || ''))?.source_file || '')
|
|
117
|
-
if (!file) continue
|
|
118
|
-
const info = classifier.explain(file, {content: ''})
|
|
119
|
-
if (hasPathClass(info, 'test', 'e2e')) tests.add(targetId)
|
|
120
|
-
else production.add(targetId)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (overlay.state === 'COMPLETE' && Array.isArray(overlay.noReferenceSymbols)
|
|
124
|
-
&& overlay.noReferenceSymbols.some((id) => String(id) === targetId)) noReference.add(targetId)
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
referenceSymbols: [...referenced],
|
|
128
|
-
productionReferenceSymbols: [...production],
|
|
129
|
-
testReferenceSymbols: [...tests],
|
|
130
|
-
noReferenceSymbols: [...noReference],
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export async function querySymbolPrecision({
|
|
135
|
-
repoRoot,
|
|
136
|
-
graphPath,
|
|
137
|
-
targetId,
|
|
138
|
-
maxReferences = 1_000,
|
|
139
|
-
timeoutMs = 30_000,
|
|
140
|
-
clientFactory,
|
|
141
|
-
} = {}) {
|
|
142
|
-
if (!repoRoot || !graphPath || !targetId) throw new Error('symbol precision requires repoRoot, graphPath, and targetId')
|
|
143
|
-
const boundedReferences = boundedInteger(maxReferences, 1_000, 1, 5_000)
|
|
144
|
-
const boundedTimeout = boundedInteger(timeoutMs, 30_000, 1_000, 60_000)
|
|
145
|
-
const request = {maxSymbols: 1, maxReferences: boundedReferences, maxLinks: boundedReferences}
|
|
146
|
-
const rawGraph = loadRawGraph(graphPath)
|
|
147
|
-
const graph = rawGraph.graphPrecisionMode === 'off' ? {...rawGraph, graphPrecisionMode: 'lsp'} : rawGraph
|
|
148
|
-
const target = graph.nodes.find((node) => String(node?.id || '') === String(targetId))
|
|
149
|
-
if (!target) throw new Error('the selected symbol is not present in the active raw graph')
|
|
150
|
-
if (!target.selection_start || !/\.(?:[cm]?[jt]sx?)$/i.test(String(target.source_file || ''))) {
|
|
151
|
-
throw new Error('exact symbol precision currently supports JavaScript and TypeScript symbols with source selections')
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const id = String(targetId)
|
|
155
|
-
const cachePath = symbolPrecisionCachePath(graphPath)
|
|
156
|
-
const startedAt = Date.now()
|
|
157
|
-
const cached = readCache(cachePath).entries.find((entry) => cacheMatch(entry, {targetId: id, graph, repoRoot, request}))
|
|
158
|
-
if (cached) return {overlay: cached.overlay, cached: true, elapsedMs: Date.now() - startedAt, cachePath}
|
|
159
|
-
|
|
160
|
-
const flightKey = `${graphPath}\0${graph.graphRevision || ''}\0${id}\0${boundedReferences}`
|
|
161
|
-
if (inFlight.has(flightKey)) return inFlight.get(flightKey)
|
|
162
|
-
const operation = (async () => {
|
|
163
|
-
const overlay = await buildLspPrecisionOverlay({
|
|
164
|
-
repoRoot,
|
|
165
|
-
graph,
|
|
166
|
-
mode: 'lsp',
|
|
167
|
-
maxSymbols: 1,
|
|
168
|
-
maxReferences: boundedReferences,
|
|
169
|
-
maxLinks: boundedReferences,
|
|
170
|
-
timeoutMs: boundedTimeout,
|
|
171
|
-
targetIds: [id],
|
|
172
|
-
clientFactory,
|
|
173
|
-
})
|
|
174
|
-
if (cacheable(overlay)) {
|
|
175
|
-
await storeEntry(cachePath, {targetId: id, usedAt: Date.now(), overlay})
|
|
176
|
-
}
|
|
177
|
-
return {overlay, cached: false, elapsedMs: Date.now() - startedAt, cachePath}
|
|
178
|
-
})()
|
|
179
|
-
inFlight.set(flightKey, operation)
|
|
180
|
-
try {
|
|
181
|
-
return await operation
|
|
182
|
-
} finally {
|
|
183
|
-
inFlight.delete(flightKey)
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export async function querySymbolsPrecision({
|
|
188
|
-
repoRoot,
|
|
189
|
-
graphPath,
|
|
190
|
-
targetIds,
|
|
191
|
-
maxReferences = 5_000,
|
|
192
|
-
timeoutMs = 45_000,
|
|
193
|
-
clientFactory,
|
|
194
|
-
} = {}) {
|
|
195
|
-
if (!repoRoot || !graphPath || !Array.isArray(targetIds) || !targetIds.length) {
|
|
196
|
-
throw new Error('batch symbol precision requires repoRoot, graphPath, and targetIds')
|
|
197
|
-
}
|
|
198
|
-
const ids = [...new Set(targetIds.map(String).filter(Boolean))].slice(0, 16)
|
|
199
|
-
const boundedReferences = boundedInteger(maxReferences, 5_000, 1, 16_384)
|
|
200
|
-
const boundedTimeout = boundedInteger(timeoutMs, 45_000, 1_000, 60_000)
|
|
201
|
-
const rawGraph = loadRawGraph(graphPath)
|
|
202
|
-
const graph = rawGraph.graphPrecisionMode === 'off' ? {...rawGraph, graphPrecisionMode: 'lsp'} : rawGraph
|
|
203
|
-
const nodes = new Map((graph.nodes || []).map((node) => [String(node?.id || ''), node]))
|
|
204
|
-
for (const id of ids) {
|
|
205
|
-
const target = nodes.get(id)
|
|
206
|
-
if (!target) throw new Error(`precision target is absent from the active graph: ${id}`)
|
|
207
|
-
if (!target.selection_start || !/\.(?:[cm]?[jt]sx?)$/i.test(String(target.source_file || ''))) {
|
|
208
|
-
throw new Error(`exact batch precision does not support target: ${id}`)
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
const startedAt = Date.now()
|
|
212
|
-
const overlay = await buildLspPrecisionOverlay({
|
|
213
|
-
repoRoot,
|
|
214
|
-
graph,
|
|
215
|
-
mode: 'lsp',
|
|
216
|
-
maxSymbols: ids.length,
|
|
217
|
-
maxReferences: boundedReferences,
|
|
218
|
-
maxLinks: boundedReferences,
|
|
219
|
-
timeoutMs: boundedTimeout,
|
|
220
|
-
targetIds: ids,
|
|
221
|
-
clientFactory,
|
|
222
|
-
})
|
|
223
|
-
return {overlay, targetIds: ids, elapsedMs: Date.now() - startedAt}
|
|
224
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
TYPESCRIPT_LSP_CAPABILITY_CONTRACT,
|
|
3
|
-
typeScriptLanguageId,
|
|
4
|
-
typeScriptLspAvailability,
|
|
5
|
-
typeScriptLspContract,
|
|
6
|
-
} from './typescript-provider/discovery.js'
|
|
7
|
-
export {classifyTypeScriptReferenceUsage} from './typescript-provider/reference-usage.js'
|
|
8
|
-
export {
|
|
9
|
-
typeScriptConfiguredProjectMembership,
|
|
10
|
-
typeScriptProjectSafety,
|
|
11
|
-
} from './typescript-provider/project-safety.js'
|
|
12
|
-
export {createTypeScriptLspClient} from './typescript-provider/client.js'
|