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,263 +0,0 @@
|
|
|
1
|
-
// SQL extractor. No SQL grammar ships in the pinned tree-sitter-wasms, so this module is textOnly:
|
|
2
|
-
// a dependency-free statement scanner built for the graph's needs (symbols + references), NOT a SQL
|
|
3
|
-
// parser. Symbols: CREATE TABLE/VIEW (+ columns as member symbols, ALTER TABLE ADD COLUMN included),
|
|
4
|
-
// FUNCTION/PROCEDURE, INDEX, TRIGGER. References: FROM/JOIN/INSERT INTO/UPDATE…SET/DELETE FROM/
|
|
5
|
-
// TRUNCATE/REFERENCES/EXECUTE FUNCTION/CALL inside .sql files, plus the same verbs found in string
|
|
6
|
-
// literals of every other indexed language (scanEmbeddedSql) — that is what ties the code graph to
|
|
7
|
-
// the database schema: a query in app code becomes a `references` edge onto the table it touches.
|
|
8
|
-
// Known blind spots (kept honest downstream, see dead-check.js): ORM-generated SQL is invisible,
|
|
9
|
-
// `SELECT *` consumes columns namelessly (tables get sql_star), DROP statements are not replayed.
|
|
10
|
-
// String literals and comments are blanked before structural scanning so a quoted "SELECT" can
|
|
11
|
-
// never fabricate a reference; dollar-quoted function bodies stay scannable on purpose.
|
|
12
|
-
|
|
13
|
-
const NAME = String.raw`((?:[\`"\[]?[A-Za-z_][\w$]*[\`"\]]?\.)*[\`"\[]?[A-Za-z_][\w$]*[\`"\]]?)`;
|
|
14
|
-
const cleanName = (raw) => String(raw || "").replace(/[`"\[\]]/g, "").split(".").pop();
|
|
15
|
-
const CONSTRAINT_START = /^(?:CONSTRAINT|PRIMARY|FOREIGN|UNIQUE|CHECK|EXCLUDE|KEY|INDEX|LIKE|PERIOD)\b/i;
|
|
16
|
-
|
|
17
|
-
// strings ('…' with '' doubling) and comments (-- …, /* … */) become spaces of equal length,
|
|
18
|
-
// so offsets/line numbers survive and quoted text can't match structural patterns.
|
|
19
|
-
function sanitizeSql(text) {
|
|
20
|
-
const out = text.split("");
|
|
21
|
-
let i = 0;
|
|
22
|
-
const blank = (from, to) => { for (let k = from; k < to; k++) if (out[k] !== "\n") out[k] = " "; };
|
|
23
|
-
while (i < text.length) {
|
|
24
|
-
const ch = text[i], next = text[i + 1];
|
|
25
|
-
if (ch === "-" && next === "-") { let j = i; while (j < text.length && text[j] !== "\n") j++; blank(i, j); i = j; continue; }
|
|
26
|
-
if (ch === "/" && next === "*") { let j = text.indexOf("*/", i + 2); j = j < 0 ? text.length : j + 2; blank(i, j); i = j; continue; }
|
|
27
|
-
if (ch === "'") {
|
|
28
|
-
let j = i + 1;
|
|
29
|
-
while (j < text.length) { if (text[j] === "'") { if (text[j + 1] === "'") { j += 2; continue; } break; } j++; }
|
|
30
|
-
blank(i + 1, Math.min(j, text.length)); i = j + 1; continue;
|
|
31
|
-
}
|
|
32
|
-
i++;
|
|
33
|
-
}
|
|
34
|
-
return out.join("");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const lineIndex = (text) => {
|
|
38
|
-
const starts = [0];
|
|
39
|
-
for (let i = 0; i < text.length; i++) if (text[i] === "\n") starts.push(i + 1);
|
|
40
|
-
return (offset) => {
|
|
41
|
-
let lo = 0, hi = starts.length - 1;
|
|
42
|
-
while (lo < hi) { const mid = (lo + hi + 1) >> 1; if (starts[mid] <= offset) lo = mid; else hi = mid - 1; }
|
|
43
|
-
return lo + 1;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// split a CREATE TABLE body on top-level commas, keeping each part's offset
|
|
48
|
-
function splitColumns(body, base) {
|
|
49
|
-
const parts = [];
|
|
50
|
-
let depth = 0, start = 0;
|
|
51
|
-
for (let i = 0; i < body.length; i++) {
|
|
52
|
-
const ch = body[i];
|
|
53
|
-
if (ch === "(") depth++;
|
|
54
|
-
else if (ch === ")") depth--;
|
|
55
|
-
else if (ch === "," && depth === 0) { parts.push({ text: body.slice(start, i), offset: base + start }); start = i + 1; }
|
|
56
|
-
}
|
|
57
|
-
parts.push({ text: body.slice(start), offset: base + start });
|
|
58
|
-
return parts;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const REF_PATTERNS = [
|
|
62
|
-
new RegExp(String.raw`\bFROM\s+${NAME}`, "gi"),
|
|
63
|
-
new RegExp(String.raw`\bJOIN\s+${NAME}`, "gi"),
|
|
64
|
-
new RegExp(String.raw`\bINSERT\s+INTO\s+${NAME}`, "gi"),
|
|
65
|
-
new RegExp(String.raw`\bMERGE\s+INTO\s+${NAME}`, "gi"),
|
|
66
|
-
new RegExp(String.raw`\bUPDATE\s+(?:ONLY\s+)?${NAME}\s+SET\b`, "gi"),
|
|
67
|
-
new RegExp(String.raw`\bTRUNCATE\s+(?:TABLE\s+)?${NAME}`, "gi"),
|
|
68
|
-
new RegExp(String.raw`\bREFERENCES\s+${NAME}`, "gi"),
|
|
69
|
-
new RegExp(String.raw`\bEXECUTE\s+(?:FUNCTION|PROCEDURE)\s+${NAME}`, "gi"),
|
|
70
|
-
];
|
|
71
|
-
const STAR_RE = /\bSELECT\s+(?:[A-Za-z_]\w*\.)?\*/i;
|
|
72
|
-
|
|
73
|
-
export default {
|
|
74
|
-
family: "sql",
|
|
75
|
-
grammars: [],
|
|
76
|
-
exts: { ".sql": "sql" },
|
|
77
|
-
isWeb: false,
|
|
78
|
-
textOnly: true,
|
|
79
|
-
calls: null,
|
|
80
|
-
heritage: [],
|
|
81
|
-
|
|
82
|
-
pass1(ctx) {
|
|
83
|
-
const { fileRel, code, addSym, links, sqlRefs } = ctx;
|
|
84
|
-
const text = sanitizeSql(String(code || ""));
|
|
85
|
-
const lineOf = lineIndex(text);
|
|
86
|
-
const fakeNode = (startOffset, endOffset) => ({
|
|
87
|
-
startPosition: { row: lineOf(startOffset) - 1, column: 0 },
|
|
88
|
-
endPosition: { row: lineOf(Math.max(startOffset, endOffset - 1)) - 1, column: 0 },
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// statements with offsets (';' inside dollar-quoted bodies splits early — refs/lines still land right)
|
|
92
|
-
const statements = [];
|
|
93
|
-
let cursor = 0;
|
|
94
|
-
while (cursor <= text.length) {
|
|
95
|
-
let end = text.indexOf(";", cursor);
|
|
96
|
-
if (end < 0) end = text.length;
|
|
97
|
-
if (text.slice(cursor, end).trim()) statements.push({ text: text.slice(cursor, end), offset: cursor });
|
|
98
|
-
cursor = end + 1;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const addRef = (table, offset, star) => {
|
|
102
|
-
const name = cleanName(table);
|
|
103
|
-
if (/^[A-Za-z_][\w$]*$/.test(name)) sqlRefs.push({ file: fileRel, line: lineOf(offset), table: name, star: !!star });
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
for (const stmt of statements) {
|
|
107
|
-
const at = (m) => stmt.offset + m.index;
|
|
108
|
-
const definedHere = new Set();
|
|
109
|
-
const defineSym = (raw, m, callable, extra) => {
|
|
110
|
-
const name = cleanName(raw);
|
|
111
|
-
definedHere.add(name);
|
|
112
|
-
return addSym(name, lineOf(at(m)), callable, {
|
|
113
|
-
sourceNode: fakeNode(at(m), stmt.offset + stmt.text.length),
|
|
114
|
-
exported: true, moduleDeclaration: true, ...extra,
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
let m;
|
|
119
|
-
if ((m = stmt.text.match(new RegExp(String.raw`\bCREATE\s+(?:GLOBAL\s+|LOCAL\s+)?(?:TEMP(?:ORARY)?\s+|UNLOGGED\s+)?TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?${NAME}\s*\(`, "i")))) {
|
|
120
|
-
const tableName = cleanName(m[1]);
|
|
121
|
-
const open = stmt.offset + m.index + m[0].length - 1;
|
|
122
|
-
let depth = 0, close = open;
|
|
123
|
-
for (let i = open; i < text.length; i++) { if (text[i] === "(") depth++; else if (text[i] === ")" && --depth === 0) { close = i; break; } }
|
|
124
|
-
const fieldTypes = {};
|
|
125
|
-
const columns = [];
|
|
126
|
-
for (const part of splitColumns(text.slice(open + 1, close), open + 1)) {
|
|
127
|
-
const trimmed = part.text.trim();
|
|
128
|
-
if (!trimmed || CONSTRAINT_START.test(trimmed)) continue;
|
|
129
|
-
const col = trimmed.match(new RegExp(String.raw`^${NAME}\s+([A-Za-z_]\w*(?:\([^)]*\))?)`));
|
|
130
|
-
if (!col) continue;
|
|
131
|
-
const colName = cleanName(col[1]);
|
|
132
|
-
if (!/^[A-Za-z_][\w$]*$/.test(colName)) continue;
|
|
133
|
-
fieldTypes[colName] = col[2];
|
|
134
|
-
columns.push({ name: colName, offset: part.offset + part.text.indexOf(col[1]) });
|
|
135
|
-
}
|
|
136
|
-
const tableId = defineSym(m[1], m, false, { symbolKind: "table", fieldTypes });
|
|
137
|
-
for (const column of columns) {
|
|
138
|
-
const columnId = addSym(column.name, lineOf(column.offset), false, {
|
|
139
|
-
sourceNode: fakeNode(column.offset, column.offset + 1),
|
|
140
|
-
symbolKind: "column", memberOf: tableName,
|
|
141
|
-
});
|
|
142
|
-
if (tableId && columnId) links.push({ source: tableId, target: columnId, relation: "contains", confidence: "EXTRACTED" });
|
|
143
|
-
}
|
|
144
|
-
} else if ((m = stmt.text.match(new RegExp(String.raw`\bCREATE\s+(?:OR\s+REPLACE\s+)?(?:MATERIALIZED\s+)?VIEW\s+(?:IF\s+NOT\s+EXISTS\s+)?${NAME}`, "i")))) {
|
|
145
|
-
defineSym(m[1], m, false, { symbolKind: "view" });
|
|
146
|
-
} else if ((m = stmt.text.match(new RegExp(String.raw`\bCREATE\s+(?:OR\s+REPLACE\s+)?(?:FUNCTION|PROCEDURE)\s+${NAME}`, "i")))) {
|
|
147
|
-
defineSym(m[1], m, true, { symbolKind: "function" });
|
|
148
|
-
} else if ((m = stmt.text.match(new RegExp(String.raw`\bCREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:CONCURRENTLY\s+)?(?:IF\s+NOT\s+EXISTS\s+)?${NAME}\s+ON\s+(?:ONLY\s+)?${NAME}`, "i")))) {
|
|
149
|
-
defineSym(m[1], m, false, { symbolKind: "index" });
|
|
150
|
-
addRef(m[2], at(m), false);
|
|
151
|
-
} else if ((m = stmt.text.match(new RegExp(String.raw`\bCREATE\s+(?:OR\s+REPLACE\s+)?(?:CONSTRAINT\s+)?TRIGGER\s+${NAME}[\s\S]*?\bON\s+${NAME}`, "i")))) {
|
|
152
|
-
defineSym(m[1], m, false, { symbolKind: "trigger" });
|
|
153
|
-
addRef(m[2], at(m), false);
|
|
154
|
-
} else if ((m = stmt.text.match(new RegExp(String.raw`\bALTER\s+TABLE\s+(?:IF\s+EXISTS\s+)?(?:ONLY\s+)?${NAME}`, "i")))) {
|
|
155
|
-
const tableName = cleanName(m[1]);
|
|
156
|
-
addRef(m[1], at(m), false);
|
|
157
|
-
const addColumn = new RegExp(String.raw`\bADD\s+(?:COLUMN\s+)?(?:IF\s+NOT\s+EXISTS\s+)?(?!CONSTRAINT\b|PRIMARY\b|FOREIGN\b|UNIQUE\b|CHECK\b|EXCLUDE\b)${NAME}\s+[A-Za-z_]`, "gi");
|
|
158
|
-
for (const colMatch of stmt.text.matchAll(addColumn)) {
|
|
159
|
-
const colName = cleanName(colMatch[1]);
|
|
160
|
-
if (!/^[A-Za-z_][\w$]*$/.test(colName)) continue;
|
|
161
|
-
addSym(colName, lineOf(stmt.offset + colMatch.index), false, {
|
|
162
|
-
sourceNode: fakeNode(stmt.offset + colMatch.index, stmt.offset + colMatch.index + 1),
|
|
163
|
-
symbolKind: "column", memberOf: tableName,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const star = STAR_RE.test(stmt.text);
|
|
169
|
-
for (const pattern of REF_PATTERNS) {
|
|
170
|
-
pattern.lastIndex = 0;
|
|
171
|
-
for (const refMatch of stmt.text.matchAll(pattern)) {
|
|
172
|
-
const name = cleanName(refMatch[1]);
|
|
173
|
-
if (!definedHere.has(name)) addRef(refMatch[1], stmt.offset + refMatch.index, star);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
// SQL verbs inside string literals of any host language — the cross-link between app code and schema.
|
|
181
|
-
// Runs on RAW text (strings are exactly where the queries live); comments can over-match, which only
|
|
182
|
-
// errs toward "referenced" and carries INFERRED confidence.
|
|
183
|
-
const EMBEDDED = [
|
|
184
|
-
{ re: new RegExp(String.raw`\bSELECT\b[^;]{0,2000}?\bFROM\s+${NAME}`, "gi"), star: true },
|
|
185
|
-
{ re: new RegExp(String.raw`\bINSERT\s+INTO\s+${NAME}`, "gi") },
|
|
186
|
-
{ re: new RegExp(String.raw`\bUPDATE\s+${NAME}\s+SET\b`, "gi") },
|
|
187
|
-
{ re: new RegExp(String.raw`\bDELETE\s+FROM\s+${NAME}`, "gi") },
|
|
188
|
-
{ re: new RegExp(String.raw`\bJOIN\s+${NAME}\b`, "gi") },
|
|
189
|
-
{ re: new RegExp(String.raw`\bCALL\s+${NAME}\s*\(`, "gi") },
|
|
190
|
-
];
|
|
191
|
-
const EMBEDDED_PREFILTER = /\b(?:select|insert|update|delete|join|call)\b/i;
|
|
192
|
-
|
|
193
|
-
export function scanEmbeddedSql(code, fileRel, sqlRefs) {
|
|
194
|
-
const text = String(code || "");
|
|
195
|
-
if (!EMBEDDED_PREFILTER.test(text)) return;
|
|
196
|
-
const lineOf = lineIndex(text);
|
|
197
|
-
for (const { re, star } of EMBEDDED) {
|
|
198
|
-
re.lastIndex = 0;
|
|
199
|
-
for (const m of text.matchAll(re)) {
|
|
200
|
-
const name = cleanName(m[1]);
|
|
201
|
-
if (!/^[A-Za-z_][\w$]*$/.test(name)) continue;
|
|
202
|
-
sqlRefs.push({ file: fileRel, line: lineOf(m.index), table: name, star: !!(star && STAR_RE.test(m[0])) });
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Dead-code policy for SQL schema objects, consumed by analysis/dead-check.js. Static liveness can
|
|
208
|
-
// only be judged where the repo demonstrably uses literal SQL the scanner can read: without a single
|
|
209
|
-
// embedded-SQL edge from host code, DB consumers (ORMs, external services) are invisible and every
|
|
210
|
-
// verdict would be a guess. Indexes and triggers are DB-engine surface — never judged. Columns of a
|
|
211
|
-
// `SELECT *`-consumed table are consumed namelessly — never judged by name.
|
|
212
|
-
export function createSqlDeadVerdict({ nodes, links, ep, bareName }) {
|
|
213
|
-
const usageFromCode = links.some((l) => l.usage === "sql" && !String(ep(l.source)).split("#")[0].endsWith(".sql"));
|
|
214
|
-
const starTables = new Set(nodes.filter((n) => n.sql_star).map((n) => bareName(n.label)));
|
|
215
|
-
const classify = (n) => {
|
|
216
|
-
if (!String(n.source_file || "").endsWith(".sql")) return null;
|
|
217
|
-
const kind = String(n.symbol_kind || "");
|
|
218
|
-
if (kind === "index" || kind === "trigger" || !usageFromCode) return "veto";
|
|
219
|
-
if (kind === "column" && starTables.has(String(n.member_of || ""))) return "veto";
|
|
220
|
-
return "flag";
|
|
221
|
-
};
|
|
222
|
-
return {
|
|
223
|
-
veto: (n) => classify(n) === "veto",
|
|
224
|
-
reason: (n) => (classify(n) === "flag" ? "no SQL statement in the indexed sources references it" : null),
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// After both passes: resolve collected refs against every table/view/function DEFINED in .sql files.
|
|
229
|
-
// Unknown names drop silently — only schema objects the repo actually declares can gain edges.
|
|
230
|
-
export function resolveSqlReferences({ sqlRefs, links, nodeById, perFileSymbols }) {
|
|
231
|
-
if (!sqlRefs?.length) return;
|
|
232
|
-
const index = new Map();
|
|
233
|
-
for (const [file, syms] of perFileSymbols) {
|
|
234
|
-
if (!file.endsWith(".sql")) continue;
|
|
235
|
-
for (const sym of syms) {
|
|
236
|
-
if (!["table", "view", "function"].includes(sym.symbolKind)) continue;
|
|
237
|
-
(index.get(sym.name) || index.set(sym.name, []).get(sym.name)).push(sym.id);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
if (!index.size) return;
|
|
241
|
-
const enclosing = (file, line) => {
|
|
242
|
-
let best = null;
|
|
243
|
-
for (const symbol of perFileSymbols.get(file) || []) {
|
|
244
|
-
if (line < symbol.start || line > symbol.end) continue;
|
|
245
|
-
if (!best || symbol.start > best.start || (symbol.start === best.start && symbol.end < best.end)) best = symbol;
|
|
246
|
-
}
|
|
247
|
-
return best;
|
|
248
|
-
};
|
|
249
|
-
const seen = new Set();
|
|
250
|
-
for (const ref of sqlRefs) {
|
|
251
|
-
const targets = index.get(ref.table);
|
|
252
|
-
if (!targets) continue;
|
|
253
|
-
const source = enclosing(ref.file, ref.line)?.id || ref.file;
|
|
254
|
-
for (const target of targets) {
|
|
255
|
-
if (ref.star) { const node = nodeById.get(target); if (node) node.sql_star = true; }
|
|
256
|
-
if (target === source) continue;
|
|
257
|
-
const key = source + ">" + target;
|
|
258
|
-
if (seen.has(key)) continue;
|
|
259
|
-
seen.add(key);
|
|
260
|
-
links.push({ source, target, relation: "references", confidence: "INFERRED", usage: "sql", line: ref.line });
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
export function createPass2Resolution({symIdsByFileName, nodeById, importedLocals, symByFileName}) {
|
|
2
|
-
const dirSymbols = new Map(), dirMethods = new Map(), dirMethodsByName = new Map(), dirTypes = new Map()
|
|
3
|
-
// Rust associated functions / methods indexed by their owning type, per directory: `Type::method`
|
|
4
|
-
// resolves to the exact impl member instead of any same-named function in the directory.
|
|
5
|
-
const rustMethods = new Map() // dir -> Map(typeName -> Map(methodName -> id))
|
|
6
|
-
// .sol shares dir scope because Solidity's project namespace is flat: `import "./Base.sol"` names no
|
|
7
|
-
// symbols yet pulls every declaration into scope, so same-dir name resolution is the honest static proxy.
|
|
8
|
-
const sharesDirScope = (file) => file.endsWith('.go') || file.endsWith('.cs') || file.endsWith('.rs') || file.endsWith('.sol')
|
|
9
|
-
for (const [file, names] of symIdsByFileName) {
|
|
10
|
-
if (!sharesDirScope(file)) continue
|
|
11
|
-
const dir = file.includes('/') ? file.slice(0, file.lastIndexOf('/')) : ''
|
|
12
|
-
let symbols = dirSymbols.get(dir)
|
|
13
|
-
if (!symbols) dirSymbols.set(dir, (symbols = new Map()))
|
|
14
|
-
for (const [name, ids] of names) for (const id of ids) {
|
|
15
|
-
const node = nodeById.get(id)
|
|
16
|
-
if (file.endsWith('.go') && node?.member_of && node?.symbol_kind === 'method') {
|
|
17
|
-
let receivers = dirMethods.get(dir)
|
|
18
|
-
if (!receivers) dirMethods.set(dir, (receivers = new Map()))
|
|
19
|
-
let methods = receivers.get(node.member_of)
|
|
20
|
-
if (!methods) receivers.set(node.member_of, (methods = new Map()))
|
|
21
|
-
const exact = methods.get(name) || []
|
|
22
|
-
exact.push(id); methods.set(name, exact)
|
|
23
|
-
let byName = dirMethodsByName.get(dir)
|
|
24
|
-
if (!byName) dirMethodsByName.set(dir, (byName = new Map()))
|
|
25
|
-
const candidates = byName.get(name) || []
|
|
26
|
-
candidates.push(id); byName.set(name, candidates)
|
|
27
|
-
continue
|
|
28
|
-
}
|
|
29
|
-
if (!symbols.has(name)) symbols.set(name, id)
|
|
30
|
-
if (file.endsWith('.rs') && node?.member_of) {
|
|
31
|
-
let byType = rustMethods.get(dir)
|
|
32
|
-
if (!byType) rustMethods.set(dir, (byType = new Map()))
|
|
33
|
-
let methods = byType.get(node.member_of)
|
|
34
|
-
if (!methods) byType.set(node.member_of, (methods = new Map()))
|
|
35
|
-
if (!methods.has(name)) methods.set(name, id)
|
|
36
|
-
}
|
|
37
|
-
if (file.endsWith('.go') && node?.symbol_space === 'type') {
|
|
38
|
-
let types = dirTypes.get(dir)
|
|
39
|
-
if (!types) dirTypes.set(dir, (types = new Map()))
|
|
40
|
-
if (!types.has(name)) types.set(name, id)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const symbolSpace = (node) => {
|
|
45
|
-
const explicit = String(node?.symbol_space || '')
|
|
46
|
-
if (['value', 'type', 'both'].includes(explicit)) return explicit
|
|
47
|
-
const kind = String(node?.symbol_kind || '').toLowerCase()
|
|
48
|
-
if (['interface', 'type'].includes(kind)) return 'type'
|
|
49
|
-
return ['class', 'enum'].includes(kind) ? 'both' : 'value'
|
|
50
|
-
}
|
|
51
|
-
const resolveNamedSymbol = (file, name, space = 'value') => {
|
|
52
|
-
const ids = symIdsByFileName.get(file)?.get(name) || []
|
|
53
|
-
const exact = ids.find((id) => symbolSpace(nodeById.get(id)) === space)
|
|
54
|
-
return exact || ids.find((id) => ['both', space].includes(symbolSpace(nodeById.get(id)))) || null
|
|
55
|
-
}
|
|
56
|
-
const resolveCall = (name, file) => {
|
|
57
|
-
const local = resolveNamedSymbol(file, name, 'value')
|
|
58
|
-
if (local) return local
|
|
59
|
-
if (sharesDirScope(file)) {
|
|
60
|
-
const dir = file.includes('/') ? file.slice(0, file.lastIndexOf('/')) : ''
|
|
61
|
-
const symbols = dirSymbols.get(dir)
|
|
62
|
-
if (symbols?.has(name)) return symbols.get(name)
|
|
63
|
-
}
|
|
64
|
-
const imported = importedLocals.get(file)?.get(name)
|
|
65
|
-
if (!imported?.targetFile) return null
|
|
66
|
-
return resolveNamedSymbol(imported.originFile || imported.targetFile, imported.originName || imported.imported, 'value')
|
|
67
|
-
}
|
|
68
|
-
const resolveRustMethod = (dir, typeName, methodName) => rustMethods.get(dir)?.get(typeName)?.get(methodName) || null
|
|
69
|
-
const javaTypeKinds = new Set(['class', 'interface', 'enum', 'record', 'annotation'])
|
|
70
|
-
const resolveJavaType = (name, file) => {
|
|
71
|
-
const imported = importedLocals.get(file)?.get(name)
|
|
72
|
-
if (imported?.targetFile) {
|
|
73
|
-
const symbols = symByFileName.get(imported.targetFile)
|
|
74
|
-
const target = symbols?.get(imported.imported) || symbols?.get(name)
|
|
75
|
-
if (target && javaTypeKinds.has(nodeById.get(target)?.symbol_kind)) return target
|
|
76
|
-
}
|
|
77
|
-
const target = symByFileName.get(file)?.get(name)
|
|
78
|
-
return target && javaTypeKinds.has(nodeById.get(target)?.symbol_kind) ? target : null
|
|
79
|
-
}
|
|
80
|
-
return {dirSymbols, dirMethods, dirMethodsByName, dirTypes, resolveNamedSymbol, resolveCall, resolveJavaType, resolveRustMethod}
|
|
81
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// specToPkg(spec) — map an import specifier to its npm package name, a Node builtin, or null for
|
|
2
|
-
// relative/absolute/URL specifiers. The core primitive for dependency analysis (unused/missing deps):
|
|
3
|
-
// "axios/lib/core" → axios, "@scope/name/sub" → @scope/name, "node:fs/promises" + "fs/promises" → fs
|
|
4
|
-
// (builtin), "./x" → null. See DEPS_SECURITY_PLAN.md (P0).
|
|
5
|
-
|
|
6
|
-
// Builtins importable WITHOUT the node: prefix. Prefix-only builtins (node:test, node:sea, node:sqlite)
|
|
7
|
-
// are deliberately NOT here — bare "test" is a legitimate npm package name; node:-prefixed specifiers
|
|
8
|
-
// are always classified builtin regardless of this set.
|
|
9
|
-
export const NODE_BUILTINS = new Set([
|
|
10
|
-
"assert", "async_hooks", "buffer", "child_process", "cluster", "console", "constants", "crypto",
|
|
11
|
-
"dgram", "diagnostics_channel", "dns", "domain", "events", "fs", "http", "http2", "https", "inspector",
|
|
12
|
-
"module", "net", "os", "path", "perf_hooks", "process", "punycode", "querystring", "readline", "repl",
|
|
13
|
-
"stream", "string_decoder", "sys", "timers", "tls", "trace_events", "tty", "url", "util", "v8", "vm",
|
|
14
|
-
"wasi", "worker_threads", "zlib",
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
export function specToPkg(spec) {
|
|
18
|
-
const s = String(spec || "").trim();
|
|
19
|
-
if (!s || s.startsWith(".") || s.startsWith("/") || /^[A-Za-z]:[\\/]/.test(s)) return null; // relative/absolute/local
|
|
20
|
-
if (s.startsWith("#")) return null; // package.json "imports" subpath (self-internal), not a dependency
|
|
21
|
-
if (/^(https?|data|file):/.test(s)) return null; // URL-style imports aren't manifest deps
|
|
22
|
-
if (s.startsWith("node:")) return { pkg: s.slice(5).split("/")[0], builtin: true };
|
|
23
|
-
if (s === "bun" || s.startsWith("bun:")) return { pkg: s, builtin: true }; // Bun runtime modules (bun:test, bun:sqlite) — never npm deps
|
|
24
|
-
if (s.startsWith("npm:")) return specToPkg(s.slice(4)); // Deno/import-map npm: specifiers alias real npm packages
|
|
25
|
-
if (/^[a-z][\w+.-]*:/.test(s)) return null; // other scheme-style specifiers (jsr:, deno:, virtual:, …) aren't manifest deps
|
|
26
|
-
const parts = s.split("/");
|
|
27
|
-
const pkg = s.startsWith("@") ? (parts.length >= 2 ? `${parts[0]}/${parts[1]}` : s) : parts[0];
|
|
28
|
-
if (NODE_BUILTINS.has(pkg)) return { pkg, builtin: true };
|
|
29
|
-
return { pkg, builtin: false };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// ---- Go: import path → module (declared in go.mod) or stdlib. Stdlib packages have a dotless first
|
|
33
|
-
// segment (fmt, net/http, encoding/json — and cgo's "C"); everything else is a module path. Prefer the
|
|
34
|
-
// longest go.mod require prefix (exact module identity); fall back to a host-convention guess so
|
|
35
|
-
// MISSING modules still get a sane name (github.com/owner/repo, gopkg.in/pkg.v3, k8s.io/client-go).
|
|
36
|
-
const GO_DEEP_HOSTS = new Set(["github.com", "gitlab.com", "bitbucket.org", "golang.org", "go.googlesource.com"]);
|
|
37
|
-
export function goSpecToPkg(importPath, { requires = [], ownModule = "" } = {}) {
|
|
38
|
-
const s = String(importPath || "").trim();
|
|
39
|
-
if (!s) return null;
|
|
40
|
-
const segs = s.split("/");
|
|
41
|
-
if (!segs[0].includes(".")) return { pkg: s, builtin: true }; // stdlib + "C"
|
|
42
|
-
if (ownModule && (s === ownModule || s.startsWith(ownModule + "/"))) return null; // own module → internal (broken path, not a dep)
|
|
43
|
-
let best = "";
|
|
44
|
-
for (const r of requires) { const p = typeof r === "string" ? r : r.path; if ((s === p || s.startsWith(p + "/")) && p.length > best.length) best = p; }
|
|
45
|
-
if (best) return { pkg: best, builtin: false };
|
|
46
|
-
let n = GO_DEEP_HOSTS.has(segs[0]) ? 3 : 2;
|
|
47
|
-
if (segs[0] === "gopkg.in") n = /\.v\d+$/.test(segs[1] || "") ? 2 : 3;
|
|
48
|
-
return { pkg: segs.slice(0, Math.min(n, segs.length)).join("/"), builtin: false };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// ---- Python: top-level imported module → PyPI distribution (or stdlib). PY_STDLIB ≈ CPython 3.12
|
|
52
|
-
// sys.stdlib_module_names (public names) + legacy stalwarts, so old codebases classify cleanly too.
|
|
53
|
-
export const PY_STDLIB = new Set(("__future__ __main__ _thread abc aifc argparse array ast asyncio atexit audioop base64 bdb binascii bisect builtins bz2 " +
|
|
54
|
-
"calendar cgi cgitb chunk cmath cmd code codecs codeop collections colorsys compileall concurrent configparser contextlib contextvars copy copyreg cProfile crypt csv ctypes curses " +
|
|
55
|
-
"dataclasses datetime dbm decimal difflib dis distutils doctest email encodings ensurepip enum errno faulthandler fcntl filecmp fileinput fnmatch fractions ftplib functools " +
|
|
56
|
-
"gc getopt getpass gettext glob graphlib grp gzip hashlib heapq hmac html http imaplib imghdr imp importlib inspect io ipaddress itertools json keyword " +
|
|
57
|
-
"linecache locale logging lzma mailbox mailcap marshal math mimetypes mmap modulefinder msilib msvcrt multiprocessing netrc nntplib ntpath numbers " +
|
|
58
|
-
"operator optparse os ossaudiodev pathlib pdb pickle pickletools pipes pkgutil platform plistlib poplib posixpath pprint profile pstats pty pwd py_compile pyclbr pydoc queue quopri " +
|
|
59
|
-
"random re readline reprlib resource rlcompleter runpy sched secrets select selectors shelve shlex shutil signal site smtplib sndhdr socket socketserver spwd sqlite3 ssl stat statistics " +
|
|
60
|
-
"sre_compile sre_constants sre_parse string stringprep struct subprocess sunau symtable sys sysconfig syslog tabnanny tarfile telnetlib tempfile termios textwrap threading time timeit tkinter token tokenize tomllib " +
|
|
61
|
-
"trace traceback tracemalloc tty turtle types typing unicodedata unittest urllib uu uuid venv warnings wave weakref webbrowser winreg winsound wsgiref xdrlib xml xmlrpc zipapp zipfile zipimport zlib zoneinfo").split(" "));
|
|
62
|
-
|
|
63
|
-
// import name → PyPI dist where they differ. Generic python-X / X-python / X[2]-binary equivalence is
|
|
64
|
-
// handled by the matcher in dep-check; this map covers the truly irregular names.
|
|
65
|
-
const PY_IMPORT_TO_DIST = {
|
|
66
|
-
yaml: "PyYAML", cv2: "opencv-python", PIL: "Pillow", sklearn: "scikit-learn", skimage: "scikit-image",
|
|
67
|
-
bs4: "beautifulsoup4", dateutil: "python-dateutil", dotenv: "python-dotenv", jose: "python-jose",
|
|
68
|
-
magic: "python-magic", multipart: "python-multipart", docx: "python-docx", pptx: "python-pptx",
|
|
69
|
-
fitz: "PyMuPDF", OpenSSL: "pyOpenSSL", Crypto: "pycryptodome", nacl: "PyNaCl", jwt: "PyJWT",
|
|
70
|
-
MySQLdb: "mysqlclient", attr: "attrs", attrs: "attrs", git: "GitPython", github: "PyGithub",
|
|
71
|
-
kafka: "kafka-python", grpc: "grpcio", serial: "pyserial", usb: "pyusb", zmq: "pyzmq",
|
|
72
|
-
websocket: "websocket-client", socks: "PySocks", telegram: "python-telegram-bot",
|
|
73
|
-
speech_recognition: "SpeechRecognition", wx: "wxPython", cairo: "pycairo", gi: "PyGObject",
|
|
74
|
-
mpl_toolkits: "matplotlib", pkg_resources: "setuptools", Levenshtein: "python-Levenshtein",
|
|
75
|
-
ldap: "python-ldap", memcache: "python-memcached", slugify: "python-slugify", decouple: "python-decouple",
|
|
76
|
-
engineio: "python-engineio", socketio: "python-socketio", ruamel: "ruamel.yaml", flask: "Flask",
|
|
77
|
-
win32api: "pywin32", win32com: "pywin32", win32con: "pywin32", win32gui: "pywin32", pythoncom: "pywin32", pywintypes: "pywin32",
|
|
78
|
-
};
|
|
79
|
-
// namespace roots shared by many dists (google.protobuf/google.cloud.* …) — too ambiguous to name one
|
|
80
|
-
// package; "src" is a repo-layout artifact (stale sys.path import), never a PyPI dist.
|
|
81
|
-
const PY_AMBIGUOUS_TOP = new Set(["google", "src"]);
|
|
82
|
-
export function pySpecToPkg(topModule) {
|
|
83
|
-
const t = String(topModule || "").trim();
|
|
84
|
-
if (!t) return null;
|
|
85
|
-
if (PY_STDLIB.has(t)) return { pkg: t, builtin: true };
|
|
86
|
-
return { pkg: PY_IMPORT_TO_DIST[t] || t, builtin: false, ambiguous: PY_AMBIGUOUS_TOP.has(t) };
|
|
87
|
-
}
|
package/src/graph/community.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Deterministic community territories. Most languages keep the historical top-two-folder bucket. Java
|
|
2
|
-
// Maven/Gradle trees need package depth: otherwise every class under application/src becomes one giant blob.
|
|
3
|
-
export function communityTerritoryOf(file) {
|
|
4
|
-
const normalized = String(file || "").replace(/\\/g, "/");
|
|
5
|
-
if (/\.java$/i.test(normalized)) {
|
|
6
|
-
const marker = /(?:^|\/)src\/(?:main|test)\/java\//.exec(normalized);
|
|
7
|
-
if (marker) {
|
|
8
|
-
const end = marker.index + marker[0].length;
|
|
9
|
-
const prefix = normalized.slice(0, end).replace(/\/$/, "");
|
|
10
|
-
const packageDirs = normalized.slice(end).split("/").filter(Boolean).slice(0, -1);
|
|
11
|
-
if (packageDirs.length) return `${prefix}/${packageDirs.slice(0, 5).join("/")}`;
|
|
12
|
-
return prefix;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const dirs = normalized.split("/").filter(Boolean).slice(0, -1);
|
|
16
|
-
return dirs.length ? dirs.slice(0, 2).join("/") : "(root)";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Community ids are serialized into graph.json and therefore must not depend on which subset of
|
|
20
|
-
// files happened to be reparsed. Assign ids from the complete, sorted territory universe so a
|
|
21
|
-
// scoped incremental merge produces the same ids as a full build.
|
|
22
|
-
export function assignDeterministicCommunities(nodes = []) {
|
|
23
|
-
const territories = [...new Set(nodes.map((node) => communityTerritoryOf(node?.source_file)))].sort();
|
|
24
|
-
const ids = new Map(territories.map((territory, index) => [territory, index]));
|
|
25
|
-
for (const node of nodes) node.community = ids.get(communityTerritoryOf(node?.source_file));
|
|
26
|
-
return nodes;
|
|
27
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// Versioned origin classification for graph edges. `confidence` remains a compatibility field;
|
|
2
|
-
// provenance says how an edge was established and leaves room for a bounded LSP precision overlay.
|
|
3
|
-
export const EDGE_PROVENANCE_V = 1;
|
|
4
|
-
export const EDGE_PROVENANCE_KINDS = Object.freeze([
|
|
5
|
-
"EXACT_LSP", "EXTRACTED", "RESOLVED", "INFERRED", "CONFLICT",
|
|
6
|
-
]);
|
|
7
|
-
|
|
8
|
-
const ALLOWED = new Set(EDGE_PROVENANCE_KINDS);
|
|
9
|
-
|
|
10
|
-
export function edgeProvenance(edge) {
|
|
11
|
-
const explicit = String(edge?.provenance || "").trim().toUpperCase();
|
|
12
|
-
if (ALLOWED.has(explicit)) return explicit;
|
|
13
|
-
if (edge?.semanticOrigin === true) return "RESOLVED";
|
|
14
|
-
const legacy = String(edge?.confidence || "").trim().toUpperCase();
|
|
15
|
-
return ALLOWED.has(legacy) ? legacy : "UNKNOWN";
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function stampEdgeProvenance(links) {
|
|
19
|
-
for (const link of Array.isArray(links) ? links : []) {
|
|
20
|
-
const provenance = edgeProvenance(link);
|
|
21
|
-
if (provenance !== "UNKNOWN") link.provenance = provenance;
|
|
22
|
-
}
|
|
23
|
-
return links;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function summarizeEdgeProvenance(links) {
|
|
27
|
-
const counts = Object.fromEntries([...EDGE_PROVENANCE_KINDS, "UNKNOWN"].map((kind) => [kind, 0]));
|
|
28
|
-
for (const link of Array.isArray(links) ? links : []) counts[edgeProvenance(link)] += 1;
|
|
29
|
-
const total = Array.isArray(links) ? links.length : 0;
|
|
30
|
-
return {version: EDGE_PROVENANCE_V, total, classified: total - counts.UNKNOWN, complete: counts.UNKNOWN === 0, counts};
|
|
31
|
-
}
|
package/src/graph/file-lock.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// Small cross-process lock + atomic file replacement helpers for derived graph state. Multiple MCP
|
|
2
|
-
// clients commonly run at once (Claude, Codex, desktop); a plain read -> write sequence can lose a
|
|
3
|
-
// registry record or expose a half-written multi-megabyte graph to another reader.
|
|
4
|
-
import {mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync} from 'node:fs'
|
|
5
|
-
import {dirname} from 'node:path'
|
|
6
|
-
import process from 'node:process'
|
|
7
|
-
|
|
8
|
-
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
9
|
-
const waitSync = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms)
|
|
10
|
-
|
|
11
|
-
function clearStaleLock(lockDir, staleMs) {
|
|
12
|
-
try {
|
|
13
|
-
if (Date.now() - statSync(lockDir).mtimeMs <= staleMs) return false
|
|
14
|
-
try {
|
|
15
|
-
const ownerPid = Number(readFileSync(`${lockDir}/owner`, 'utf8').split(/\s+/)[0])
|
|
16
|
-
if (Number.isInteger(ownerPid) && ownerPid > 0) {
|
|
17
|
-
try { process.kill(ownerPid, 0); return false }
|
|
18
|
-
catch (error) { if (error?.code === 'EPERM') return false }
|
|
19
|
-
}
|
|
20
|
-
} catch { /* missing owner: stale age remains the authority */ }
|
|
21
|
-
rmSync(lockDir, {recursive: true, force: true})
|
|
22
|
-
return true
|
|
23
|
-
} catch { return false }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function acquired(lockDir) {
|
|
27
|
-
mkdirSync(dirname(lockDir), {recursive: true})
|
|
28
|
-
try {
|
|
29
|
-
mkdirSync(lockDir)
|
|
30
|
-
writeFileSync(`${lockDir}/owner`, `${process.pid}\n${new Date().toISOString()}\n`, 'utf8')
|
|
31
|
-
return true
|
|
32
|
-
} catch (error) {
|
|
33
|
-
if (error?.code === 'EEXIST') return false
|
|
34
|
-
throw error
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export async function withFileLock(lockDir, fn, {timeoutMs = 10_000, staleMs = 60_000, pollMs = 25} = {}) {
|
|
39
|
-
const started = Date.now()
|
|
40
|
-
while (!acquired(lockDir)) {
|
|
41
|
-
clearStaleLock(lockDir, staleMs)
|
|
42
|
-
if (Date.now() - started >= timeoutMs) throw new Error(`timed out waiting for derived-state lock: ${lockDir}`)
|
|
43
|
-
await wait(pollMs)
|
|
44
|
-
}
|
|
45
|
-
try { return await fn() }
|
|
46
|
-
finally { rmSync(lockDir, {recursive: true, force: true}) }
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function withFileLockSync(lockDir, fn, {timeoutMs = 10_000, staleMs = 60_000, pollMs = 20} = {}) {
|
|
50
|
-
const started = Date.now()
|
|
51
|
-
while (!acquired(lockDir)) {
|
|
52
|
-
clearStaleLock(lockDir, staleMs)
|
|
53
|
-
if (Date.now() - started >= timeoutMs) throw new Error(`timed out waiting for derived-state lock: ${lockDir}`)
|
|
54
|
-
waitSync(pollMs)
|
|
55
|
-
}
|
|
56
|
-
try { return fn() }
|
|
57
|
-
finally { rmSync(lockDir, {recursive: true, force: true}) }
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function atomicWriteFileSync(path, data, encoding = undefined) {
|
|
61
|
-
mkdirSync(dirname(path), {recursive: true})
|
|
62
|
-
const temp = `${path}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`
|
|
63
|
-
try {
|
|
64
|
-
writeFileSync(temp, data, encoding)
|
|
65
|
-
renameSync(temp, path)
|
|
66
|
-
} finally {
|
|
67
|
-
try { rmSync(temp, {force: true}) } catch { /* already renamed */ }
|
|
68
|
-
}
|
|
69
|
-
}
|