@optave/codegraph 3.12.0 → 3.15.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/README.md +83 -46
- package/dist/ast-analysis/engine.d.ts.map +1 -1
- package/dist/ast-analysis/engine.js +38 -40
- package/dist/ast-analysis/engine.js.map +1 -1
- package/dist/ast-analysis/rules/b2.d.ts +7 -0
- package/dist/ast-analysis/rules/b2.d.ts.map +1 -0
- package/dist/ast-analysis/rules/b2.js +240 -0
- package/dist/ast-analysis/rules/b2.js.map +1 -0
- package/dist/ast-analysis/rules/b3.d.ts +6 -0
- package/dist/ast-analysis/rules/b3.d.ts.map +1 -0
- package/dist/ast-analysis/rules/b3.js +105 -0
- package/dist/ast-analysis/rules/b3.js.map +1 -0
- package/dist/ast-analysis/rules/b4.d.ts +9 -0
- package/dist/ast-analysis/rules/b4.d.ts.map +1 -0
- package/dist/ast-analysis/rules/b4.js +361 -0
- package/dist/ast-analysis/rules/b4.js.map +1 -0
- package/dist/ast-analysis/rules/b5.d.ts +4 -0
- package/dist/ast-analysis/rules/b5.d.ts.map +1 -0
- package/dist/ast-analysis/rules/b5.js +52 -0
- package/dist/ast-analysis/rules/b5.js.map +1 -0
- package/dist/ast-analysis/rules/c.d.ts +4 -0
- package/dist/ast-analysis/rules/c.d.ts.map +1 -0
- package/dist/ast-analysis/rules/c.js +143 -0
- package/dist/ast-analysis/rules/c.js.map +1 -0
- package/dist/ast-analysis/rules/index.d.ts.map +1 -1
- package/dist/ast-analysis/rules/index.js +34 -0
- package/dist/ast-analysis/rules/index.js.map +1 -1
- package/dist/ast-analysis/rules/javascript.d.ts.map +1 -1
- package/dist/ast-analysis/rules/javascript.js +3 -0
- package/dist/ast-analysis/rules/javascript.js.map +1 -1
- package/dist/ast-analysis/shared.d.ts.map +1 -1
- package/dist/ast-analysis/shared.js +2 -0
- package/dist/ast-analysis/shared.js.map +1 -1
- package/dist/ast-analysis/visitor-utils.d.ts +1 -0
- package/dist/ast-analysis/visitor-utils.d.ts.map +1 -1
- package/dist/ast-analysis/visitor-utils.js +5 -0
- package/dist/ast-analysis/visitor-utils.js.map +1 -1
- package/dist/ast-analysis/visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitor.js +60 -47
- package/dist/ast-analysis/visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/cfg-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/cfg-visitor.js +126 -76
- package/dist/ast-analysis/visitors/cfg-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.js +27 -15
- package/dist/ast-analysis/visitors/complexity-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.js +54 -21
- package/dist/ast-analysis/visitors/dataflow-visitor.js.map +1 -1
- package/dist/cli/commands/audit.d.ts.map +1 -1
- package/dist/cli/commands/audit.js +2 -1
- package/dist/cli/commands/audit.js.map +1 -1
- package/dist/cli/commands/batch.d.ts.map +1 -1
- package/dist/cli/commands/batch.js +1 -0
- package/dist/cli/commands/batch.js.map +1 -1
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +6 -1
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/config.d.ts +3 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +275 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/roles.d.ts.map +1 -1
- package/dist/cli/commands/roles.js +6 -1
- package/dist/cli/commands/roles.js.map +1 -1
- package/dist/cli/commands/triage.js +1 -1
- package/dist/cli/commands/triage.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +10 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/shared/options.d.ts +2 -1
- package/dist/cli/shared/options.d.ts.map +1 -1
- package/dist/cli/shared/options.js +11 -1
- package/dist/cli/shared/options.js.map +1 -1
- package/dist/cli/types.d.ts +2 -0
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/db/better-sqlite3.d.ts +2 -1
- package/dist/db/better-sqlite3.d.ts.map +1 -1
- package/dist/db/better-sqlite3.js.map +1 -1
- package/dist/db/connection.d.ts +7 -1
- package/dist/db/connection.d.ts.map +1 -1
- package/dist/db/connection.js +20 -5
- package/dist/db/connection.js.map +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/migrations.js +69 -1
- package/dist/db/migrations.js.map +1 -1
- package/dist/db/repository/build-stmts.d.ts.map +1 -1
- package/dist/db/repository/build-stmts.js +18 -0
- package/dist/db/repository/build-stmts.js.map +1 -1
- package/dist/db/repository/dataflow.d.ts +5 -0
- package/dist/db/repository/dataflow.d.ts.map +1 -1
- package/dist/db/repository/dataflow.js +14 -0
- package/dist/db/repository/dataflow.js.map +1 -1
- package/dist/db/repository/index.d.ts +1 -1
- package/dist/db/repository/index.d.ts.map +1 -1
- package/dist/db/repository/index.js +1 -1
- package/dist/db/repository/index.js.map +1 -1
- package/dist/db/repository/native-repository.d.ts.map +1 -1
- package/dist/db/repository/native-repository.js +47 -34
- package/dist/db/repository/native-repository.js.map +1 -1
- package/dist/domain/analysis/context.d.ts +2 -2
- package/dist/domain/analysis/dependencies.d.ts +2 -2
- package/dist/domain/analysis/diff-impact.d.ts +2 -2
- package/dist/domain/analysis/fn-impact.d.ts +3 -1
- package/dist/domain/analysis/fn-impact.d.ts.map +1 -1
- package/dist/domain/analysis/fn-impact.js +4 -0
- package/dist/domain/analysis/fn-impact.js.map +1 -1
- package/dist/domain/analysis/implementations.d.ts +2 -2
- package/dist/domain/analysis/module-map.d.ts.map +1 -1
- package/dist/domain/analysis/module-map.js +32 -5
- package/dist/domain/analysis/module-map.js.map +1 -1
- package/dist/domain/analysis/roles.d.ts +7 -1
- package/dist/domain/analysis/roles.d.ts.map +1 -1
- package/dist/domain/analysis/roles.js +16 -0
- package/dist/domain/analysis/roles.js.map +1 -1
- package/dist/domain/analysis/symbol-lookup.d.ts +4 -4
- package/dist/domain/graph/builder/call-resolver.d.ts +29 -13
- package/dist/domain/graph/builder/call-resolver.d.ts.map +1 -1
- package/dist/domain/graph/builder/call-resolver.js +125 -205
- package/dist/domain/graph/builder/call-resolver.js.map +1 -1
- package/dist/domain/graph/builder/cha.d.ts +9 -1
- package/dist/domain/graph/builder/cha.d.ts.map +1 -1
- package/dist/domain/graph/builder/cha.js +17 -2
- package/dist/domain/graph/builder/cha.js.map +1 -1
- package/dist/domain/graph/builder/context.d.ts +1 -0
- package/dist/domain/graph/builder/context.d.ts.map +1 -1
- package/dist/domain/graph/builder/context.js.map +1 -1
- package/dist/domain/graph/builder/helpers.d.ts +24 -1
- package/dist/domain/graph/builder/helpers.d.ts.map +1 -1
- package/dist/domain/graph/builder/helpers.js +174 -65
- package/dist/domain/graph/builder/helpers.js.map +1 -1
- package/dist/domain/graph/builder/incremental.d.ts.map +1 -1
- package/dist/domain/graph/builder/incremental.js +166 -97
- package/dist/domain/graph/builder/incremental.js.map +1 -1
- package/dist/domain/graph/builder/pipeline.d.ts.map +1 -1
- package/dist/domain/graph/builder/pipeline.js +46 -5
- package/dist/domain/graph/builder/pipeline.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.d.ts +0 -2
- package/dist/domain/graph/builder/stages/build-edges.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.js +554 -538
- package/dist/domain/graph/builder/stages/build-edges.js.map +1 -1
- package/dist/domain/graph/builder/stages/collect-files.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/collect-files.js +10 -7
- package/dist/domain/graph/builder/stages/collect-files.js.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.js +3 -2
- package/dist/domain/graph/builder/stages/detect-changes.js.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.js +4 -0
- package/dist/domain/graph/builder/stages/finalize.js.map +1 -1
- package/dist/domain/graph/builder/stages/native-orchestrator.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/native-orchestrator.js +952 -343
- package/dist/domain/graph/builder/stages/native-orchestrator.js.map +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.js +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.js.map +1 -1
- package/dist/domain/graph/resolver/points-to.d.ts.map +1 -1
- package/dist/domain/graph/resolver/points-to.js +105 -57
- package/dist/domain/graph/resolver/points-to.js.map +1 -1
- package/dist/domain/graph/resolver/strategy.d.ts +61 -0
- package/dist/domain/graph/resolver/strategy.d.ts.map +1 -0
- package/dist/domain/graph/resolver/strategy.js +222 -0
- package/dist/domain/graph/resolver/strategy.js.map +1 -0
- package/dist/domain/graph/watcher.d.ts.map +1 -1
- package/dist/domain/graph/watcher.js +16 -9
- package/dist/domain/graph/watcher.js.map +1 -1
- package/dist/domain/parser.d.ts +16 -5
- package/dist/domain/parser.d.ts.map +1 -1
- package/dist/domain/parser.js +58 -17
- package/dist/domain/parser.js.map +1 -1
- package/dist/domain/queries.d.ts +1 -1
- package/dist/domain/queries.d.ts.map +1 -1
- package/dist/domain/queries.js +1 -1
- package/dist/domain/queries.js.map +1 -1
- package/dist/domain/wasm-worker-entry.js +13 -2
- package/dist/domain/wasm-worker-entry.js.map +1 -1
- package/dist/domain/wasm-worker-pool.d.ts.map +1 -1
- package/dist/domain/wasm-worker-pool.js +26 -5
- package/dist/domain/wasm-worker-pool.js.map +1 -1
- package/dist/domain/wasm-worker-protocol.d.ts +8 -0
- package/dist/domain/wasm-worker-protocol.d.ts.map +1 -1
- package/dist/extractors/cpp.d.ts.map +1 -1
- package/dist/extractors/cpp.js +42 -1
- package/dist/extractors/cpp.js.map +1 -1
- package/dist/extractors/cuda.d.ts.map +1 -1
- package/dist/extractors/cuda.js +42 -1
- package/dist/extractors/cuda.js.map +1 -1
- package/dist/extractors/dart.js +48 -3
- package/dist/extractors/dart.js.map +1 -1
- package/dist/extractors/groovy.js +62 -3
- package/dist/extractors/groovy.js.map +1 -1
- package/dist/extractors/helpers.d.ts +15 -2
- package/dist/extractors/helpers.d.ts.map +1 -1
- package/dist/extractors/helpers.js +45 -1
- package/dist/extractors/helpers.js.map +1 -1
- package/dist/extractors/java.d.ts.map +1 -1
- package/dist/extractors/java.js +85 -8
- package/dist/extractors/java.js.map +1 -1
- package/dist/extractors/javascript.d.ts.map +1 -1
- package/dist/extractors/javascript.js +686 -169
- package/dist/extractors/javascript.js.map +1 -1
- package/dist/extractors/kotlin.js +58 -3
- package/dist/extractors/kotlin.js.map +1 -1
- package/dist/extractors/objc.js +25 -2
- package/dist/extractors/objc.js.map +1 -1
- package/dist/extractors/scala.js +62 -2
- package/dist/extractors/scala.js.map +1 -1
- package/dist/extractors/swift.js +52 -3
- package/dist/extractors/swift.js.map +1 -1
- package/dist/features/audit.js +26 -23
- package/dist/features/audit.js.map +1 -1
- package/dist/features/boundaries.d.ts.map +1 -1
- package/dist/features/boundaries.js +12 -9
- package/dist/features/boundaries.js.map +1 -1
- package/dist/features/cfg.d.ts.map +1 -1
- package/dist/features/cfg.js +25 -18
- package/dist/features/cfg.js.map +1 -1
- package/dist/features/check.d.ts.map +1 -1
- package/dist/features/check.js +18 -5
- package/dist/features/check.js.map +1 -1
- package/dist/features/communities.d.ts +4 -2
- package/dist/features/communities.d.ts.map +1 -1
- package/dist/features/communities.js +6 -4
- package/dist/features/communities.js.map +1 -1
- package/dist/features/dataflow.d.ts +60 -0
- package/dist/features/dataflow.d.ts.map +1 -1
- package/dist/features/dataflow.js +530 -6
- package/dist/features/dataflow.js.map +1 -1
- package/dist/features/manifesto.d.ts.map +1 -1
- package/dist/features/manifesto.js +59 -72
- package/dist/features/manifesto.js.map +1 -1
- package/dist/features/sequence.d.ts.map +1 -1
- package/dist/features/sequence.js +27 -22
- package/dist/features/sequence.js.map +1 -1
- package/dist/features/snapshot.d.ts.map +1 -1
- package/dist/features/snapshot.js +36 -28
- package/dist/features/snapshot.js.map +1 -1
- package/dist/features/structure-query.d.ts +1 -1
- package/dist/features/structure-query.d.ts.map +1 -1
- package/dist/features/structure-query.js +6 -6
- package/dist/features/structure-query.js.map +1 -1
- package/dist/features/structure.d.ts.map +1 -1
- package/dist/features/structure.js +150 -62
- package/dist/features/structure.js.map +1 -1
- package/dist/features/triage.d.ts.map +1 -1
- package/dist/features/triage.js +18 -11
- package/dist/features/triage.js.map +1 -1
- package/dist/graph/algorithms/bfs.d.ts +1 -1
- package/dist/graph/algorithms/bfs.d.ts.map +1 -1
- package/dist/graph/algorithms/bfs.js +14 -13
- package/dist/graph/algorithms/bfs.js.map +1 -1
- package/dist/graph/algorithms/tarjan.d.ts.map +1 -1
- package/dist/graph/algorithms/tarjan.js +5 -0
- package/dist/graph/algorithms/tarjan.js.map +1 -1
- package/dist/graph/builders/dependency.js +28 -22
- package/dist/graph/builders/dependency.js.map +1 -1
- package/dist/graph/classifiers/roles.d.ts +10 -1
- package/dist/graph/classifiers/roles.d.ts.map +1 -1
- package/dist/graph/classifiers/roles.js +60 -6
- package/dist/graph/classifiers/roles.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/config.d.ts +87 -4
- package/dist/infrastructure/config.d.ts.map +1 -1
- package/dist/infrastructure/config.js +424 -22
- package/dist/infrastructure/config.js.map +1 -1
- package/dist/infrastructure/registry.d.ts +27 -7
- package/dist/infrastructure/registry.d.ts.map +1 -1
- package/dist/infrastructure/registry.js +79 -5
- package/dist/infrastructure/registry.js.map +1 -1
- package/dist/infrastructure/update-check.d.ts.map +1 -1
- package/dist/infrastructure/update-check.js +49 -31
- package/dist/infrastructure/update-check.js.map +1 -1
- package/dist/mcp/server.d.ts +2 -10
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools/ast-query.d.ts +1 -1
- package/dist/mcp/tools/ast-query.d.ts.map +1 -1
- package/dist/mcp/tools/audit.d.ts +1 -1
- package/dist/mcp/tools/audit.d.ts.map +1 -1
- package/dist/mcp/tools/batch-query.d.ts +1 -1
- package/dist/mcp/tools/batch-query.d.ts.map +1 -1
- package/dist/mcp/tools/branch-compare.d.ts +1 -1
- package/dist/mcp/tools/branch-compare.d.ts.map +1 -1
- package/dist/mcp/tools/brief.d.ts +1 -1
- package/dist/mcp/tools/brief.d.ts.map +1 -1
- package/dist/mcp/tools/cfg.d.ts +1 -1
- package/dist/mcp/tools/cfg.d.ts.map +1 -1
- package/dist/mcp/tools/check.d.ts +1 -1
- package/dist/mcp/tools/check.d.ts.map +1 -1
- package/dist/mcp/tools/co-changes.d.ts +1 -1
- package/dist/mcp/tools/co-changes.d.ts.map +1 -1
- package/dist/mcp/tools/code-owners.d.ts +1 -1
- package/dist/mcp/tools/code-owners.d.ts.map +1 -1
- package/dist/mcp/tools/communities.d.ts +1 -1
- package/dist/mcp/tools/communities.d.ts.map +1 -1
- package/dist/mcp/tools/complexity.d.ts +1 -1
- package/dist/mcp/tools/complexity.d.ts.map +1 -1
- package/dist/mcp/tools/context.d.ts +1 -1
- package/dist/mcp/tools/context.d.ts.map +1 -1
- package/dist/mcp/tools/dataflow.d.ts +1 -1
- package/dist/mcp/tools/dataflow.d.ts.map +1 -1
- package/dist/mcp/tools/diff-impact.d.ts +1 -1
- package/dist/mcp/tools/diff-impact.d.ts.map +1 -1
- package/dist/mcp/tools/execution-flow.d.ts +1 -1
- package/dist/mcp/tools/execution-flow.d.ts.map +1 -1
- package/dist/mcp/tools/export-graph.d.ts +1 -1
- package/dist/mcp/tools/export-graph.d.ts.map +1 -1
- package/dist/mcp/tools/file-deps.d.ts +1 -1
- package/dist/mcp/tools/file-deps.d.ts.map +1 -1
- package/dist/mcp/tools/file-exports.d.ts +1 -1
- package/dist/mcp/tools/file-exports.d.ts.map +1 -1
- package/dist/mcp/tools/find-cycles.d.ts +1 -1
- package/dist/mcp/tools/find-cycles.d.ts.map +1 -1
- package/dist/mcp/tools/fn-impact.d.ts +1 -1
- package/dist/mcp/tools/fn-impact.d.ts.map +1 -1
- package/dist/mcp/tools/impact-analysis.d.ts +1 -1
- package/dist/mcp/tools/impact-analysis.d.ts.map +1 -1
- package/dist/mcp/tools/implementations.d.ts +1 -1
- package/dist/mcp/tools/implementations.d.ts.map +1 -1
- package/dist/mcp/tools/index.d.ts +2 -5
- package/dist/mcp/tools/index.d.ts.map +1 -1
- package/dist/mcp/tools/index.js.map +1 -1
- package/dist/mcp/tools/interfaces.d.ts +1 -1
- package/dist/mcp/tools/interfaces.d.ts.map +1 -1
- package/dist/mcp/tools/list-functions.d.ts +1 -1
- package/dist/mcp/tools/list-functions.d.ts.map +1 -1
- package/dist/mcp/tools/list-repos.d.ts +1 -1
- package/dist/mcp/tools/list-repos.d.ts.map +1 -1
- package/dist/mcp/tools/module-map.d.ts +1 -1
- package/dist/mcp/tools/module-map.d.ts.map +1 -1
- package/dist/mcp/tools/node-roles.d.ts +1 -1
- package/dist/mcp/tools/node-roles.d.ts.map +1 -1
- package/dist/mcp/tools/path.d.ts +1 -1
- package/dist/mcp/tools/path.d.ts.map +1 -1
- package/dist/mcp/tools/query.d.ts +1 -1
- package/dist/mcp/tools/query.d.ts.map +1 -1
- package/dist/mcp/tools/semantic-search.d.ts +1 -1
- package/dist/mcp/tools/semantic-search.d.ts.map +1 -1
- package/dist/mcp/tools/sequence.d.ts +1 -1
- package/dist/mcp/tools/sequence.d.ts.map +1 -1
- package/dist/mcp/tools/structure.d.ts +1 -1
- package/dist/mcp/tools/structure.d.ts.map +1 -1
- package/dist/mcp/tools/symbol-children.d.ts +1 -1
- package/dist/mcp/tools/symbol-children.d.ts.map +1 -1
- package/dist/mcp/tools/triage.d.ts +1 -1
- package/dist/mcp/tools/triage.d.ts.map +1 -1
- package/dist/mcp/tools/where.d.ts +1 -1
- package/dist/mcp/tools/where.d.ts.map +1 -1
- package/dist/mcp/types.d.ts +19 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +6 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/presentation/queries-cli/index.d.ts +1 -1
- package/dist/presentation/queries-cli/index.d.ts.map +1 -1
- package/dist/presentation/queries-cli/index.js +1 -1
- package/dist/presentation/queries-cli/index.js.map +1 -1
- package/dist/presentation/queries-cli/overview.d.ts +1 -0
- package/dist/presentation/queries-cli/overview.d.ts.map +1 -1
- package/dist/presentation/queries-cli/overview.js +20 -1
- package/dist/presentation/queries-cli/overview.js.map +1 -1
- package/dist/presentation/queries-cli.d.ts +1 -1
- package/dist/presentation/queries-cli.d.ts.map +1 -1
- package/dist/presentation/queries-cli.js +1 -1
- package/dist/presentation/queries-cli.js.map +1 -1
- package/dist/presentation/structure.d.ts +1 -1
- package/dist/presentation/structure.d.ts.map +1 -1
- package/dist/presentation/structure.js +2 -2
- package/dist/presentation/structure.js.map +1 -1
- package/dist/presentation/viewer.d.ts.map +1 -1
- package/dist/presentation/viewer.js +45 -32
- package/dist/presentation/viewer.js.map +1 -1
- package/dist/shared/constants.d.ts +21 -0
- package/dist/shared/constants.d.ts.map +1 -1
- package/dist/shared/constants.js +25 -0
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/normalize.d.ts.map +1 -1
- package/dist/shared/normalize.js +12 -22
- package/dist/shared/normalize.js.map +1 -1
- package/dist/shared/paginate.d.ts +4 -17
- package/dist/shared/paginate.d.ts.map +1 -1
- package/dist/shared/paginate.js.map +1 -1
- package/dist/types.d.ts +113 -1
- package/dist/types.d.ts.map +1 -1
- package/grammars/tree-sitter-erlang.wasm +0 -0
- package/grammars/tree-sitter-gleam.wasm +0 -0
- package/package.json +7 -8
- package/src/ast-analysis/engine.ts +43 -63
- package/src/ast-analysis/rules/b2.ts +263 -0
- package/src/ast-analysis/rules/b3.ts +127 -0
- package/src/ast-analysis/rules/b4.ts +378 -0
- package/src/ast-analysis/rules/b5.ts +65 -0
- package/src/ast-analysis/rules/c.ts +157 -0
- package/src/ast-analysis/rules/index.ts +34 -0
- package/src/ast-analysis/rules/javascript.ts +3 -0
- package/src/ast-analysis/shared.ts +2 -0
- package/src/ast-analysis/visitor-utils.ts +5 -0
- package/src/ast-analysis/visitor.ts +82 -52
- package/src/ast-analysis/visitors/cfg-visitor.ts +198 -84
- package/src/ast-analysis/visitors/complexity-visitor.ts +44 -16
- package/src/ast-analysis/visitors/dataflow-visitor.ts +68 -29
- package/src/cli/commands/audit.ts +2 -1
- package/src/cli/commands/batch.ts +1 -0
- package/src/cli/commands/build.ts +6 -1
- package/src/cli/commands/config.ts +353 -0
- package/src/cli/commands/roles.ts +6 -1
- package/src/cli/commands/triage.ts +1 -1
- package/src/cli/index.ts +10 -0
- package/src/cli/shared/options.ts +11 -1
- package/src/cli/types.ts +2 -0
- package/src/db/better-sqlite3.ts +5 -4
- package/src/db/connection.ts +23 -5
- package/src/db/index.ts +1 -0
- package/src/db/migrations.ts +69 -1
- package/src/db/repository/build-stmts.ts +30 -0
- package/src/db/repository/dataflow.ts +16 -0
- package/src/db/repository/index.ts +1 -1
- package/src/db/repository/native-repository.ts +56 -40
- package/src/domain/analysis/fn-impact.ts +4 -0
- package/src/domain/analysis/module-map.ts +38 -6
- package/src/domain/analysis/roles.ts +23 -0
- package/src/domain/graph/builder/call-resolver.ts +156 -218
- package/src/domain/graph/builder/cha.ts +18 -1
- package/src/domain/graph/builder/context.ts +1 -0
- package/src/domain/graph/builder/helpers.ts +205 -67
- package/src/domain/graph/builder/incremental.ts +249 -119
- package/src/domain/graph/builder/pipeline.ts +59 -6
- package/src/domain/graph/builder/stages/build-edges.ts +783 -652
- package/src/domain/graph/builder/stages/collect-files.ts +12 -6
- package/src/domain/graph/builder/stages/detect-changes.ts +4 -2
- package/src/domain/graph/builder/stages/finalize.ts +4 -0
- package/src/domain/graph/builder/stages/native-orchestrator.ts +1214 -398
- package/src/domain/graph/builder/stages/resolve-imports.ts +1 -1
- package/src/domain/graph/resolver/points-to.ts +182 -59
- package/src/domain/graph/resolver/strategy.ts +265 -0
- package/src/domain/graph/watcher.ts +19 -9
- package/src/domain/parser.ts +57 -16
- package/src/domain/queries.ts +1 -1
- package/src/domain/wasm-worker-entry.ts +13 -2
- package/src/domain/wasm-worker-pool.ts +29 -4
- package/src/domain/wasm-worker-protocol.ts +5 -0
- package/src/extractors/cpp.ts +44 -1
- package/src/extractors/cuda.ts +44 -1
- package/src/extractors/dart.ts +48 -3
- package/src/extractors/groovy.ts +62 -2
- package/src/extractors/helpers.ts +48 -2
- package/src/extractors/java.ts +88 -8
- package/src/extractors/javascript.ts +693 -167
- package/src/extractors/kotlin.ts +57 -3
- package/src/extractors/objc.ts +25 -1
- package/src/extractors/scala.ts +63 -1
- package/src/extractors/swift.ts +46 -3
- package/src/features/audit.ts +43 -34
- package/src/features/boundaries.ts +17 -9
- package/src/features/cfg.ts +31 -22
- package/src/features/check.ts +21 -5
- package/src/features/communities.ts +28 -19
- package/src/features/dataflow.ts +755 -6
- package/src/features/manifesto.ts +76 -75
- package/src/features/sequence.ts +29 -23
- package/src/features/snapshot.ts +36 -25
- package/src/features/structure-query.ts +7 -7
- package/src/features/structure.ts +185 -55
- package/src/features/triage.ts +28 -15
- package/src/graph/algorithms/bfs.ts +13 -12
- package/src/graph/algorithms/tarjan.ts +5 -0
- package/src/graph/builders/dependency.ts +35 -23
- package/src/graph/classifiers/roles.ts +74 -7
- package/src/index.ts +5 -1
- package/src/infrastructure/config.ts +511 -23
- package/src/infrastructure/registry.ts +117 -12
- package/src/infrastructure/update-check.ts +55 -33
- package/src/mcp/server.ts +2 -8
- package/src/mcp/tools/ast-query.ts +1 -1
- package/src/mcp/tools/audit.ts +1 -1
- package/src/mcp/tools/batch-query.ts +1 -1
- package/src/mcp/tools/branch-compare.ts +1 -1
- package/src/mcp/tools/brief.ts +1 -1
- package/src/mcp/tools/cfg.ts +1 -1
- package/src/mcp/tools/check.ts +1 -1
- package/src/mcp/tools/co-changes.ts +1 -1
- package/src/mcp/tools/code-owners.ts +1 -1
- package/src/mcp/tools/communities.ts +1 -1
- package/src/mcp/tools/complexity.ts +1 -1
- package/src/mcp/tools/context.ts +1 -1
- package/src/mcp/tools/dataflow.ts +1 -1
- package/src/mcp/tools/diff-impact.ts +1 -1
- package/src/mcp/tools/execution-flow.ts +1 -1
- package/src/mcp/tools/export-graph.ts +1 -1
- package/src/mcp/tools/file-deps.ts +1 -1
- package/src/mcp/tools/file-exports.ts +1 -1
- package/src/mcp/tools/find-cycles.ts +1 -1
- package/src/mcp/tools/fn-impact.ts +1 -1
- package/src/mcp/tools/impact-analysis.ts +1 -1
- package/src/mcp/tools/implementations.ts +1 -1
- package/src/mcp/tools/index.ts +2 -5
- package/src/mcp/tools/interfaces.ts +1 -1
- package/src/mcp/tools/list-functions.ts +1 -1
- package/src/mcp/tools/list-repos.ts +1 -1
- package/src/mcp/tools/module-map.ts +1 -1
- package/src/mcp/tools/node-roles.ts +1 -1
- package/src/mcp/tools/path.ts +1 -1
- package/src/mcp/tools/query.ts +1 -1
- package/src/mcp/tools/semantic-search.ts +1 -1
- package/src/mcp/tools/sequence.ts +1 -1
- package/src/mcp/tools/structure.ts +1 -1
- package/src/mcp/tools/symbol-children.ts +1 -1
- package/src/mcp/tools/triage.ts +1 -1
- package/src/mcp/tools/where.ts +1 -1
- package/src/mcp/types.ts +21 -0
- package/src/presentation/queries-cli/index.ts +1 -1
- package/src/presentation/queries-cli/overview.ts +35 -1
- package/src/presentation/queries-cli.ts +1 -0
- package/src/presentation/structure.ts +3 -3
- package/src/presentation/viewer.ts +98 -87
- package/src/shared/constants.ts +26 -0
- package/src/shared/normalize.ts +13 -22
- package/src/shared/paginate.ts +4 -18
- package/src/types.ts +127 -1
|
@@ -124,7 +124,331 @@ function insertDataflowEdges(insert, data, resolveNode) {
|
|
|
124
124
|
}
|
|
125
125
|
return edgeCount;
|
|
126
126
|
}
|
|
127
|
+
// ── P1: dataflow_vertices + intra def_use edges ───────────────────────────────
|
|
128
|
+
function prepareVertexStmts(db) {
|
|
129
|
+
try {
|
|
130
|
+
return {
|
|
131
|
+
insertVertex: db.prepare(`INSERT INTO dataflow_vertices (func_id, kind, name, param_index, line, node_id)
|
|
132
|
+
VALUES (?, ?, ?, ?, ?, ?)`),
|
|
133
|
+
insertIntraEdge: db.prepare(`INSERT INTO dataflow
|
|
134
|
+
(source_id, target_id, kind, source_vertex, target_vertex, scope, expression, line, confidence)
|
|
135
|
+
VALUES (?, ?, 'def_use', ?, ?, 'intra', ?, ?, 1.0)`),
|
|
136
|
+
available: true,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return {
|
|
141
|
+
insertVertex: db.prepare('SELECT 1'),
|
|
142
|
+
insertIntraEdge: db.prepare('SELECT 1'),
|
|
143
|
+
available: false,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Build dataflow_vertices, intra def_use edges, and summaries for one file.
|
|
149
|
+
* Called alongside insertDataflowEdges in the same transaction.
|
|
150
|
+
*
|
|
151
|
+
* Returns stitch candidates and return captures for the P2 inter-procedural
|
|
152
|
+
* post-pass (run after all files are processed).
|
|
153
|
+
*/
|
|
154
|
+
function buildDataflowVerticesAndEdges(db, vstmts, data, resolveNode) {
|
|
155
|
+
const empty = {
|
|
156
|
+
candidates: [],
|
|
157
|
+
captures: [],
|
|
158
|
+
};
|
|
159
|
+
if (!vstmts.available)
|
|
160
|
+
return empty;
|
|
161
|
+
const params = data.parameters;
|
|
162
|
+
const returns = data.returns;
|
|
163
|
+
const assignments = data.assignments;
|
|
164
|
+
const argFlows = data.argFlows;
|
|
165
|
+
const mutations = data.mutations;
|
|
166
|
+
// 1. param vertices
|
|
167
|
+
const paramVertexIds = new Map(); // "funcName:paramName" → vertex id
|
|
168
|
+
const paramIndexByFuncAndIndex = new Map(); // "funcId:paramIndex" → vertex id
|
|
169
|
+
for (const p of params) {
|
|
170
|
+
const fn = resolveNode(p.funcName);
|
|
171
|
+
if (!fn)
|
|
172
|
+
continue;
|
|
173
|
+
const result = vstmts.insertVertex.run(fn.id, 'param', p.paramName, p.paramIndex, p.line, null);
|
|
174
|
+
const vid = result.lastInsertRowid;
|
|
175
|
+
paramVertexIds.set(`${p.funcName}:${p.paramName}`, vid);
|
|
176
|
+
paramIndexByFuncAndIndex.set(`${fn.id}:${p.paramIndex}`, vid);
|
|
177
|
+
}
|
|
178
|
+
// 2. return vertices (one per function that has a return statement)
|
|
179
|
+
const returnVertexIds = new Map(); // funcName → vertex id
|
|
180
|
+
const returnFuncsSeen = new Set();
|
|
181
|
+
for (const r of returns) {
|
|
182
|
+
if (returnFuncsSeen.has(r.funcName))
|
|
183
|
+
continue;
|
|
184
|
+
returnFuncsSeen.add(r.funcName);
|
|
185
|
+
const fn = resolveNode(r.funcName);
|
|
186
|
+
if (!fn)
|
|
187
|
+
continue;
|
|
188
|
+
const result = vstmts.insertVertex.run(fn.id, 'return', null, null, r.line, null);
|
|
189
|
+
returnVertexIds.set(r.funcName, result.lastInsertRowid);
|
|
190
|
+
}
|
|
191
|
+
// 3. local vertices (from call-return assignments)
|
|
192
|
+
const localVertexIds = new Map(); // "funcName:varName" → vertex id
|
|
193
|
+
const localsSeen = new Set();
|
|
194
|
+
for (const a of assignments) {
|
|
195
|
+
const key = `${a.callerFunc}:${a.varName}`;
|
|
196
|
+
if (localsSeen.has(key))
|
|
197
|
+
continue;
|
|
198
|
+
localsSeen.add(key);
|
|
199
|
+
const fn = resolveNode(a.callerFunc);
|
|
200
|
+
if (!fn)
|
|
201
|
+
continue;
|
|
202
|
+
const result = vstmts.insertVertex.run(fn.id, 'local', a.varName, null, a.line, null);
|
|
203
|
+
localVertexIds.set(key, result.lastInsertRowid);
|
|
204
|
+
}
|
|
205
|
+
// 4. intra def_use edges: param/local → return
|
|
206
|
+
for (const r of returns) {
|
|
207
|
+
const fn = resolveNode(r.funcName);
|
|
208
|
+
if (!fn)
|
|
209
|
+
continue;
|
|
210
|
+
const returnVid = returnVertexIds.get(r.funcName);
|
|
211
|
+
if (!returnVid)
|
|
212
|
+
continue;
|
|
213
|
+
for (const name of r.referencedNames) {
|
|
214
|
+
const paramVid = paramVertexIds.get(`${r.funcName}:${name}`);
|
|
215
|
+
if (paramVid) {
|
|
216
|
+
vstmts.insertIntraEdge.run(fn.id, fn.id, paramVid, returnVid, r.expression, r.line);
|
|
217
|
+
}
|
|
218
|
+
const localVid = localVertexIds.get(`${r.funcName}:${name}`);
|
|
219
|
+
if (localVid) {
|
|
220
|
+
vstmts.insertIntraEdge.run(fn.id, fn.id, localVid, returnVid, r.expression, r.line);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// 5. summaries: flows_to_return = direct def_use from param to function's return
|
|
225
|
+
const checkDefUse = db.prepare(`SELECT 1 FROM dataflow WHERE source_vertex = ? AND target_vertex = ? AND kind = 'def_use' LIMIT 1`);
|
|
226
|
+
const insertSummary = db.prepare(`INSERT OR REPLACE INTO dataflow_summary (func_id, param_index, flows_to_return, is_mutated) VALUES (?, ?, ?, ?)`);
|
|
227
|
+
for (const p of params) {
|
|
228
|
+
const fn = resolveNode(p.funcName);
|
|
229
|
+
if (!fn)
|
|
230
|
+
continue;
|
|
231
|
+
const paramVid = paramVertexIds.get(`${p.funcName}:${p.paramName}`);
|
|
232
|
+
if (!paramVid)
|
|
233
|
+
continue;
|
|
234
|
+
const returnVid = returnVertexIds.get(p.funcName);
|
|
235
|
+
const flowsToReturn = returnVid ? (checkDefUse.get(paramVid, returnVid) ? 1 : 0) : 0;
|
|
236
|
+
const isMutated = mutations.some((m) => m.funcName === p.funcName &&
|
|
237
|
+
m.binding?.type === 'param' &&
|
|
238
|
+
m.binding?.index === p.paramIndex)
|
|
239
|
+
? 1
|
|
240
|
+
: 0;
|
|
241
|
+
insertSummary.run(fn.id, p.paramIndex, flowsToReturn, isMutated);
|
|
242
|
+
}
|
|
243
|
+
// 6. collect stitch candidates for P2 inter-procedural post-pass
|
|
244
|
+
const candidates = [];
|
|
245
|
+
for (const af of argFlows) {
|
|
246
|
+
const callerFn = resolveNode(af.callerFunc);
|
|
247
|
+
const calleeFn = resolveNode(af.calleeName);
|
|
248
|
+
if (!callerFn || !calleeFn)
|
|
249
|
+
continue;
|
|
250
|
+
candidates.push({
|
|
251
|
+
callerFuncId: callerFn.id,
|
|
252
|
+
calleeFuncId: calleeFn.id,
|
|
253
|
+
argIndex: af.argIndex,
|
|
254
|
+
bindingType: af.binding.type,
|
|
255
|
+
bindingIndex: af.binding.index,
|
|
256
|
+
argName: af.argName,
|
|
257
|
+
expression: af.expression,
|
|
258
|
+
line: af.line,
|
|
259
|
+
confidence: af.confidence,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
// 7. collect return captures (locals that hold a callee's return value)
|
|
263
|
+
const captures = [];
|
|
264
|
+
for (const a of assignments) {
|
|
265
|
+
const callerFn = resolveNode(a.callerFunc);
|
|
266
|
+
const calleeFn = resolveNode(a.sourceCallName);
|
|
267
|
+
if (!callerFn || !calleeFn)
|
|
268
|
+
continue;
|
|
269
|
+
captures.push({ callerFuncId: callerFn.id, calleeFuncId: calleeFn.id, varName: a.varName });
|
|
270
|
+
}
|
|
271
|
+
return { candidates, captures };
|
|
272
|
+
}
|
|
273
|
+
// ── P2: interprocedural stitching ─────────────────────────────────────────────
|
|
274
|
+
/**
|
|
275
|
+
* Core stitch logic — must be called inside an already-open transaction.
|
|
276
|
+
*
|
|
277
|
+
* All callers (buildDataflowVerticesFromMap, buildDataflowEdges,
|
|
278
|
+
* buildDataflowP4ForNative) manage their own outer transaction and call this
|
|
279
|
+
* directly to avoid nested transactions, which better-sqlite3 does not support.
|
|
280
|
+
*/
|
|
281
|
+
function runInterproceduralStitch(db, candidates, captures) {
|
|
282
|
+
if (candidates.length === 0)
|
|
283
|
+
return 0;
|
|
284
|
+
const getParamVertex = db.prepare(`SELECT id FROM dataflow_vertices WHERE func_id = ? AND kind = 'param' AND param_index = ? LIMIT 1`);
|
|
285
|
+
const getLocalVertex = db.prepare(`SELECT id FROM dataflow_vertices WHERE func_id = ? AND kind = 'local' AND name = ? LIMIT 1`);
|
|
286
|
+
const getReturnVertex = db.prepare(`SELECT id FROM dataflow_vertices WHERE func_id = ? AND kind = 'return' LIMIT 1`);
|
|
287
|
+
const getCallEdge = db.prepare(`SELECT id FROM edges WHERE source_id = ? AND target_id = ? AND kind = 'calls' LIMIT 1`);
|
|
288
|
+
const getSummary = db.prepare(`SELECT flows_to_return FROM dataflow_summary WHERE func_id = ? AND param_index = ?`);
|
|
289
|
+
const insertInterEdge = db.prepare(`INSERT INTO dataflow
|
|
290
|
+
(source_id, target_id, kind, source_vertex, target_vertex, scope, call_edge_id, expression, line, confidence)
|
|
291
|
+
VALUES (?, ?, ?, ?, ?, 'inter', ?, ?, ?, ?)`);
|
|
292
|
+
// Build capture map: "callerFuncId:calleeFuncId" → varName (first match wins)
|
|
293
|
+
const captureMap = new Map();
|
|
294
|
+
for (const cap of captures) {
|
|
295
|
+
const key = `${cap.callerFuncId}:${cap.calleeFuncId}`;
|
|
296
|
+
if (!captureMap.has(key))
|
|
297
|
+
captureMap.set(key, cap.varName);
|
|
298
|
+
}
|
|
299
|
+
let count = 0;
|
|
300
|
+
for (const cand of candidates) {
|
|
301
|
+
// Resolve call edge for this site
|
|
302
|
+
const callEdge = getCallEdge.get(cand.callerFuncId, cand.calleeFuncId);
|
|
303
|
+
const callEdgeId = callEdge?.id ?? null;
|
|
304
|
+
// Find source vertex x in caller
|
|
305
|
+
let srcVertexId = null;
|
|
306
|
+
if (cand.bindingType === 'param' && cand.bindingIndex != null) {
|
|
307
|
+
const v = getParamVertex.get(cand.callerFuncId, cand.bindingIndex);
|
|
308
|
+
srcVertexId = v?.id ?? null;
|
|
309
|
+
}
|
|
310
|
+
else if (cand.bindingType === 'local') {
|
|
311
|
+
const v = getLocalVertex.get(cand.callerFuncId, cand.argName);
|
|
312
|
+
srcVertexId = v?.id ?? null;
|
|
313
|
+
}
|
|
314
|
+
if (!srcVertexId)
|
|
315
|
+
continue;
|
|
316
|
+
// Find callee's param[argIndex] vertex
|
|
317
|
+
const calleeParam = getParamVertex.get(cand.calleeFuncId, cand.argIndex);
|
|
318
|
+
if (!calleeParam)
|
|
319
|
+
continue;
|
|
320
|
+
// arg_in: A's source → B.param[j]
|
|
321
|
+
insertInterEdge.run(cand.callerFuncId, cand.calleeFuncId, 'arg_in', srcVertexId, calleeParam.id, callEdgeId, cand.expression, cand.line, cand.confidence);
|
|
322
|
+
count++;
|
|
323
|
+
// return_out: if B.param[j] reaches B's return, emit B.return → A's capture
|
|
324
|
+
const summary = getSummary.get(cand.calleeFuncId, cand.argIndex);
|
|
325
|
+
if (summary?.flows_to_return) {
|
|
326
|
+
const calleeReturn = getReturnVertex.get(cand.calleeFuncId);
|
|
327
|
+
if (calleeReturn) {
|
|
328
|
+
const captureVarName = captureMap.get(`${cand.callerFuncId}:${cand.calleeFuncId}`);
|
|
329
|
+
const captureVertex = captureVarName
|
|
330
|
+
? getLocalVertex.get(cand.callerFuncId, captureVarName)
|
|
331
|
+
: null;
|
|
332
|
+
if (captureVertex) {
|
|
333
|
+
insertInterEdge.run(cand.calleeFuncId, cand.callerFuncId, 'return_out', calleeReturn.id, captureVertex.id, callEdgeId, cand.expression, cand.line, cand.confidence);
|
|
334
|
+
count++;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return count;
|
|
340
|
+
}
|
|
127
341
|
// ── buildDataflowEdges ──────────────────────────────────────────────────────
|
|
342
|
+
// ── P4 helpers ───────────────────────────────────────────────────────────────
|
|
343
|
+
/** Return IDs of all function/method nodes in the given relative file paths. */
|
|
344
|
+
export function collectFuncIdsForFiles(db, relPaths) {
|
|
345
|
+
const stmt = db.prepare(`SELECT id FROM nodes WHERE file = ? AND kind IN ('function', 'method')`);
|
|
346
|
+
const ids = [];
|
|
347
|
+
for (const p of relPaths) {
|
|
348
|
+
for (const row of stmt.all(p))
|
|
349
|
+
ids.push(row.id);
|
|
350
|
+
}
|
|
351
|
+
return ids;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* P4: Re-collect stitch candidates from caller files that were NOT in the
|
|
355
|
+
* changed set but contain calls to functions that WERE changed.
|
|
356
|
+
*
|
|
357
|
+
* During an incremental build the changed files' param vertices are purged
|
|
358
|
+
* and recreated, but the callers' files are never re-parsed — so their
|
|
359
|
+
* arg_in edges (pointing to the old param vertices) are deleted and never
|
|
360
|
+
* replaced. This function reads those caller files from disk and rebuilds
|
|
361
|
+
* the StitchCandidate list so runInterproceduralStitch can reconnect them.
|
|
362
|
+
*/
|
|
363
|
+
export async function collectCallerStitchCandidates(db, changedFuncIds, changedRelPaths, rootDir, extToLang, parsers, getParserFn) {
|
|
364
|
+
if (changedFuncIds.length === 0)
|
|
365
|
+
return { candidates: [], captures: [] };
|
|
366
|
+
// Find distinct caller files that have flows_to edges targeting any changed
|
|
367
|
+
// function and are NOT already in the changed file set (those are handled by
|
|
368
|
+
// the main per-file loop).
|
|
369
|
+
//
|
|
370
|
+
// Chunk the query to avoid exceeding SQLite's SQLITE_MAX_VARIABLE_NUMBER
|
|
371
|
+
// (999 on older builds, 32766 on SQLite ≥ 3.32). 500 is a safe batch size
|
|
372
|
+
// that works across all SQLite versions.
|
|
373
|
+
const CHUNK_SIZE = 500;
|
|
374
|
+
const callerFileSet = new Set();
|
|
375
|
+
for (let i = 0; i < changedFuncIds.length; i += CHUNK_SIZE) {
|
|
376
|
+
const chunk = changedFuncIds.slice(i, i + CHUNK_SIZE);
|
|
377
|
+
const placeholders = chunk.map(() => '?').join(',');
|
|
378
|
+
const rows = db
|
|
379
|
+
.prepare(`SELECT DISTINCT n.file AS caller_file
|
|
380
|
+
FROM dataflow d
|
|
381
|
+
JOIN nodes n ON n.id = d.source_id
|
|
382
|
+
WHERE d.target_id IN (${placeholders})
|
|
383
|
+
AND d.kind = 'flows_to'`)
|
|
384
|
+
.all(...chunk);
|
|
385
|
+
for (const r of rows)
|
|
386
|
+
callerFileSet.add(r.caller_file);
|
|
387
|
+
}
|
|
388
|
+
const callerFileRows = [...callerFileSet].map((f) => ({ caller_file: f }));
|
|
389
|
+
const callerFiles = callerFileRows
|
|
390
|
+
.map((r) => r.caller_file)
|
|
391
|
+
.filter((f) => !changedRelPaths.has(f));
|
|
392
|
+
if (callerFiles.length === 0)
|
|
393
|
+
return { candidates: [], captures: [] };
|
|
394
|
+
// Ensure parsers are available — the main loop may have skipped loading them
|
|
395
|
+
// if all changed files came through the native bulk-insert path.
|
|
396
|
+
let activeParsers = parsers;
|
|
397
|
+
let activeGetParserFn = getParserFn;
|
|
398
|
+
if (!activeGetParserFn) {
|
|
399
|
+
const { createParsers, getParser } = await import('../domain/parser.js');
|
|
400
|
+
activeParsers = await createParsers();
|
|
401
|
+
activeGetParserFn = getParser;
|
|
402
|
+
}
|
|
403
|
+
const changedFuncIdSet = new Set(changedFuncIds);
|
|
404
|
+
const stmts = prepareNodeResolvers(db);
|
|
405
|
+
const candidates = [];
|
|
406
|
+
const captures = [];
|
|
407
|
+
for (const callerFile of callerFiles) {
|
|
408
|
+
// Read the caller file from disk without touching its existing DB rows.
|
|
409
|
+
// definitions: [] is an intentional stub — P4 only needs argFlow/assignment
|
|
410
|
+
// data from the visitor, not pre-loaded symbol definitions. extractDataflow
|
|
411
|
+
// does not currently use _definitions, so this is safe. If that changes,
|
|
412
|
+
// the stub must be replaced with the actual symbol list for the caller file.
|
|
413
|
+
const stub = { definitions: [], _langId: null, _tree: null };
|
|
414
|
+
const data = getDataflowForFile(stub, callerFile, rootDir, extToLang, activeParsers, activeGetParserFn);
|
|
415
|
+
if (!data)
|
|
416
|
+
continue;
|
|
417
|
+
const resolver = makeNodeResolver(stmts, callerFile);
|
|
418
|
+
const argFlows = data.argFlows;
|
|
419
|
+
const assignments = data.assignments;
|
|
420
|
+
for (const af of argFlows) {
|
|
421
|
+
const callerFn = resolver(af.callerFunc);
|
|
422
|
+
const calleeFn = resolver(af.calleeName);
|
|
423
|
+
if (!callerFn || !calleeFn)
|
|
424
|
+
continue;
|
|
425
|
+
if (!changedFuncIdSet.has(calleeFn.id))
|
|
426
|
+
continue; // only re-stitch calls to changed callees
|
|
427
|
+
candidates.push({
|
|
428
|
+
callerFuncId: callerFn.id,
|
|
429
|
+
calleeFuncId: calleeFn.id,
|
|
430
|
+
argIndex: af.argIndex,
|
|
431
|
+
bindingType: af.binding.type,
|
|
432
|
+
bindingIndex: af.binding.index,
|
|
433
|
+
argName: af.argName,
|
|
434
|
+
expression: af.expression,
|
|
435
|
+
line: af.line,
|
|
436
|
+
confidence: af.confidence,
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
for (const a of assignments) {
|
|
440
|
+
const callerFn = resolver(a.callerFunc);
|
|
441
|
+
const calleeFn = resolver(a.sourceCallName);
|
|
442
|
+
if (!callerFn || !calleeFn)
|
|
443
|
+
continue;
|
|
444
|
+
if (!changedFuncIdSet.has(calleeFn.id))
|
|
445
|
+
continue;
|
|
446
|
+
captures.push({ callerFuncId: callerFn.id, calleeFuncId: calleeFn.id, varName: a.varName });
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
debug(`Dataflow P4: re-stitched ${candidates.length} candidate(s) from ${callerFiles.length} caller file(s)`);
|
|
450
|
+
return { candidates, captures };
|
|
451
|
+
}
|
|
128
452
|
function prepareNodeResolvers(db) {
|
|
129
453
|
return {
|
|
130
454
|
getNodeByNameAndFile: db.prepare(`SELECT id, name, kind, file, line FROM nodes
|
|
@@ -135,12 +459,24 @@ function prepareNodeResolvers(db) {
|
|
|
135
459
|
};
|
|
136
460
|
}
|
|
137
461
|
function makeNodeResolver(stmts, relPath) {
|
|
462
|
+
// Memoise per (relPath, funcName). buildDataflowVerticesAndEdges resolves the
|
|
463
|
+
// same handful of function names many times per file — once per param, return,
|
|
464
|
+
// assignment, argFlow, summary row, and capture — and each miss costs one or
|
|
465
|
+
// two `nodes` table queries. The nodes table is never mutated during the P6
|
|
466
|
+
// vertex pass (only dataflow* tables are written), so the lookup is stable for
|
|
467
|
+
// the lifetime of the resolver; caching collapses tens of thousands of
|
|
468
|
+
// redundant queries on a full build into one per distinct name (#perf).
|
|
469
|
+
const cache = new Map();
|
|
138
470
|
return (funcName) => {
|
|
471
|
+
const cached = cache.get(funcName);
|
|
472
|
+
if (cached !== undefined)
|
|
473
|
+
return cached;
|
|
139
474
|
const local = stmts.getNodeByNameAndFile.all(funcName, relPath);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
475
|
+
const resolved = local.length > 0
|
|
476
|
+
? local[0]
|
|
477
|
+
: (stmts.getNodeByName.all(funcName)[0] ?? null);
|
|
478
|
+
cache.set(funcName, resolved);
|
|
479
|
+
return resolved;
|
|
144
480
|
};
|
|
145
481
|
}
|
|
146
482
|
function collectNativeEdges(data, resolveNode, edges) {
|
|
@@ -189,6 +525,99 @@ function collectNativeEdges(data, resolveNode, edges) {
|
|
|
189
525
|
}
|
|
190
526
|
}
|
|
191
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* P6 vertex-only pass for the native orchestrator path.
|
|
530
|
+
*
|
|
531
|
+
* When the Rust orchestrator runs with analysisComplete=true it inserts
|
|
532
|
+
* flows_to/returns/mutates edges directly into the DB but never writes to
|
|
533
|
+
* dataflow_vertices or dataflow_summary. This function takes pre-extracted
|
|
534
|
+
* DataflowResult objects (from native.extractDataflowAnalysis) and builds
|
|
535
|
+
* the missing vertex rows and inter-procedural edges — without touching the
|
|
536
|
+
* already-correct function-level edges.
|
|
537
|
+
*/
|
|
538
|
+
export function buildDataflowVerticesFromMap(db, dataflowMap, extraCandidates, extraCaptures) {
|
|
539
|
+
const vstmts = prepareVertexStmts(db);
|
|
540
|
+
if (!vstmts.available || dataflowMap.size === 0)
|
|
541
|
+
return 0;
|
|
542
|
+
const stmts = prepareNodeResolvers(db);
|
|
543
|
+
// Vertex writes and inter-procedural stitch are a single atomic unit: if the
|
|
544
|
+
// stitch throws or the process is killed between the two, the DB would be left
|
|
545
|
+
// with dataflow_vertices rows but no arg_in/return_out edges. Wrapping both
|
|
546
|
+
// under one transaction boundary prevents that half-written state.
|
|
547
|
+
let stitchCount = 0;
|
|
548
|
+
const tx = db.transaction(() => {
|
|
549
|
+
const allCandidates = [];
|
|
550
|
+
const allCaptures = [];
|
|
551
|
+
for (const [relPath, data] of dataflowMap) {
|
|
552
|
+
const resolver = makeNodeResolver(stmts, relPath);
|
|
553
|
+
const { candidates, captures } = buildDataflowVerticesAndEdges(db, vstmts, data, resolver);
|
|
554
|
+
allCandidates.push(...candidates);
|
|
555
|
+
allCaptures.push(...captures);
|
|
556
|
+
}
|
|
557
|
+
// P4: merge in stitch candidates from unchanged caller files if provided.
|
|
558
|
+
if (extraCandidates && extraCandidates.length > 0)
|
|
559
|
+
allCandidates.push(...extraCandidates);
|
|
560
|
+
if (extraCaptures && extraCaptures.length > 0)
|
|
561
|
+
allCaptures.push(...extraCaptures);
|
|
562
|
+
stitchCount = runInterproceduralStitch(db, allCandidates, allCaptures);
|
|
563
|
+
});
|
|
564
|
+
tx();
|
|
565
|
+
return stitchCount;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* P4 re-stitch pass for the native engine path.
|
|
569
|
+
*
|
|
570
|
+
* On incremental builds the changed files' param vertices are purged and
|
|
571
|
+
* recreated by the P6 vertex pass, but unchanged caller files are never
|
|
572
|
+
* re-parsed — so their arg_in edges (which pointed to the old param vertex
|
|
573
|
+
* IDs) are deleted and not replaced. This function re-parses those caller
|
|
574
|
+
* files and rebuilds the arg_in edges for any call that targets a function
|
|
575
|
+
* in one of the changed callee files.
|
|
576
|
+
*
|
|
577
|
+
* Called by the native orchestrator after buildDataflowVerticesFromMap.
|
|
578
|
+
* Safe to call on full builds — the guard below exits early when
|
|
579
|
+
* changedFiles covers all distinct files in the DB.
|
|
580
|
+
*/
|
|
581
|
+
export async function buildDataflowP4ForNative(db, changedFiles, rootDir) {
|
|
582
|
+
if (changedFiles.length === 0)
|
|
583
|
+
return;
|
|
584
|
+
// Deduplicate upfront so the full-build guard uses unique-file count, not
|
|
585
|
+
// raw array length (the orchestrator may emit the same path more than once).
|
|
586
|
+
const changedRelPaths = new Set(changedFiles);
|
|
587
|
+
// Skip on full builds — all files were in the changed set, so there are no
|
|
588
|
+
// unchanged callers to re-stitch.
|
|
589
|
+
const totalFilesInDb = db.prepare(`SELECT COUNT(DISTINCT file) AS n FROM nodes`).get().n;
|
|
590
|
+
if (changedRelPaths.size >= totalFilesInDb)
|
|
591
|
+
return;
|
|
592
|
+
const extToLang = buildExtToLangMap();
|
|
593
|
+
const changedFuncIds = collectFuncIdsForFiles(db, changedRelPaths);
|
|
594
|
+
if (changedFuncIds.length === 0)
|
|
595
|
+
return;
|
|
596
|
+
// parsers=null, getParserFn=null → collectCallerStitchCandidates initialises
|
|
597
|
+
// WASM parsers lazily for the caller files it needs to re-parse.
|
|
598
|
+
const { candidates, captures } = await collectCallerStitchCandidates(db, changedFuncIds, changedRelPaths, rootDir, extToLang, null, null);
|
|
599
|
+
if (candidates.length > 0) {
|
|
600
|
+
let count = 0;
|
|
601
|
+
// Wrap the DELETE + stitch in a single transaction so that a crash between
|
|
602
|
+
// the purge and the re-insert cannot leave arg_in edges permanently removed
|
|
603
|
+
// but never replaced.
|
|
604
|
+
db.transaction(() => {
|
|
605
|
+
// Purge any existing arg_in edges targeting the changed callees from unchanged
|
|
606
|
+
// caller files. These edges were inserted by a previous P4 pass. Without this
|
|
607
|
+
// guard, repeated calls to buildDataflowP4ForNative insert duplicates because
|
|
608
|
+
// the dataflow table has no UNIQUE constraint on (source_vertex, target_vertex).
|
|
609
|
+
const placeholders = changedFuncIds.map(() => '?').join(',');
|
|
610
|
+
db.prepare(`DELETE FROM dataflow
|
|
611
|
+
WHERE kind = 'arg_in'
|
|
612
|
+
AND target_id IN (${placeholders})
|
|
613
|
+
AND source_id NOT IN (${placeholders})`).run(...changedFuncIds, ...changedFuncIds);
|
|
614
|
+
count = runInterproceduralStitch(db, candidates, captures);
|
|
615
|
+
})();
|
|
616
|
+
if (count > 0) {
|
|
617
|
+
info(`Dataflow (native P4): ${count} inter-procedural edges re-stitched`);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
192
621
|
export async function buildDataflowEdges(db, fileSymbols, rootDir, engineOpts) {
|
|
193
622
|
const extToLang = buildExtToLangMap();
|
|
194
623
|
// ── Native bulk-insert fast path ──────────────────────────────────────
|
|
@@ -219,6 +648,61 @@ export async function buildDataflowEdges(db, fileSymbols, rootDir, engineOpts) {
|
|
|
219
648
|
}
|
|
220
649
|
info(`Dataflow (native bulk): ${inserted} edges inserted`);
|
|
221
650
|
}
|
|
651
|
+
// P6: vertex extraction on the native path.
|
|
652
|
+
// Rust DataflowResult already contains parameters/returns — no re-parse needed.
|
|
653
|
+
const vstmts = prepareVertexStmts(db);
|
|
654
|
+
if (vstmts.available) {
|
|
655
|
+
// P4: Incremental re-stitch — unchanged caller files are not in
|
|
656
|
+
// fileSymbols so their arg_in edges to the old param vertices were
|
|
657
|
+
// deleted by the purge and never recreated. Re-collect stitch
|
|
658
|
+
// candidates from those caller files by parsing them from disk.
|
|
659
|
+
//
|
|
660
|
+
// Skip on full builds: fileSymbols covers every file in the DB, so
|
|
661
|
+
// there are no unchanged callers to re-stitch.
|
|
662
|
+
//
|
|
663
|
+
// This async disk-read step must happen BEFORE the transaction opens
|
|
664
|
+
// (SQLite transactions are synchronous; async work inside them is not
|
|
665
|
+
// supported by better-sqlite3).
|
|
666
|
+
const totalFilesInDb = db.prepare(`SELECT COUNT(DISTINCT file) AS n FROM nodes`).get().n;
|
|
667
|
+
let p4CallerCount = 0;
|
|
668
|
+
const p4Candidates = [];
|
|
669
|
+
const p4Captures = [];
|
|
670
|
+
if (fileSymbols.size < totalFilesInDb) {
|
|
671
|
+
const changedRelPaths = new Set(fileSymbols.keys());
|
|
672
|
+
const changedFuncIds = collectFuncIdsForFiles(db, changedRelPaths);
|
|
673
|
+
const extra = await collectCallerStitchCandidates(db, changedFuncIds, changedRelPaths, rootDir, extToLang, null, null);
|
|
674
|
+
p4Candidates.push(...extra.candidates);
|
|
675
|
+
p4Captures.push(...extra.captures);
|
|
676
|
+
p4CallerCount = extra.candidates.length;
|
|
677
|
+
}
|
|
678
|
+
// Vertex writes and inter-procedural stitch are a single atomic unit:
|
|
679
|
+
// if the stitch throws or the process is killed between the two, the DB
|
|
680
|
+
// would be left with dataflow_vertices rows but no arg_in/return_out
|
|
681
|
+
// edges. Wrapping both under one transaction boundary prevents that
|
|
682
|
+
// half-written state.
|
|
683
|
+
let interCount = 0;
|
|
684
|
+
const txVertex = db.transaction(() => {
|
|
685
|
+
const allCandidates = [];
|
|
686
|
+
const allCaptures = [];
|
|
687
|
+
for (const [relPath, symbols] of fileSymbols) {
|
|
688
|
+
if (!symbols.dataflow)
|
|
689
|
+
continue;
|
|
690
|
+
const ext = path.extname(relPath).toLowerCase();
|
|
691
|
+
if (!DATAFLOW_EXTENSIONS.has(ext))
|
|
692
|
+
continue;
|
|
693
|
+
const resolver = makeNodeResolver(stmts, relPath);
|
|
694
|
+
const { candidates, captures } = buildDataflowVerticesAndEdges(db, vstmts, symbols.dataflow, resolver);
|
|
695
|
+
allCandidates.push(...candidates);
|
|
696
|
+
allCaptures.push(...captures);
|
|
697
|
+
}
|
|
698
|
+
// Merge in the P4 candidates collected above before opening the tx.
|
|
699
|
+
allCandidates.push(...p4Candidates);
|
|
700
|
+
allCaptures.push(...p4Captures);
|
|
701
|
+
interCount = runInterproceduralStitch(db, allCandidates, allCaptures);
|
|
702
|
+
});
|
|
703
|
+
txVertex();
|
|
704
|
+
info(`Dataflow (native): ${interCount} inter-procedural edges inserted${p4CallerCount > 0 ? ` (P4: ${p4CallerCount} re-stitch candidate(s) from unchanged callers)` : ''}`);
|
|
705
|
+
}
|
|
222
706
|
return;
|
|
223
707
|
}
|
|
224
708
|
debug('Dataflow: some files lack pre-computed data — falling back to JS');
|
|
@@ -228,8 +712,39 @@ export async function buildDataflowEdges(db, fileSymbols, rootDir, engineOpts) {
|
|
|
228
712
|
const insert = db.prepare(`INSERT INTO dataflow (source_id, target_id, kind, param_index, expression, line, confidence)
|
|
229
713
|
VALUES (?, ?, ?, ?, ?, ?, ?)`);
|
|
230
714
|
const stmts = prepareNodeResolvers(db);
|
|
715
|
+
const vstmts = prepareVertexStmts(db);
|
|
716
|
+
// P4: Incremental re-stitch — if only a subset of files changed, callers of
|
|
717
|
+
// the changed functions were not in fileSymbols, so their arg_in edges were
|
|
718
|
+
// deleted by the purge but never reconstructed. Re-collect stitch candidates
|
|
719
|
+
// from those caller files now (read from disk, no DB writes).
|
|
720
|
+
//
|
|
721
|
+
// Skip P4 on full builds: when fileSymbols covers every file in the DB there
|
|
722
|
+
// are no unchanged callers, and collectFuncIdsForFiles would issue one SELECT
|
|
723
|
+
// per file for nothing. A single COUNT query is cheaper than N per-file SELECTs.
|
|
724
|
+
//
|
|
725
|
+
// This async disk-read step must happen BEFORE the transaction opens
|
|
726
|
+
// (SQLite transactions are synchronous; async work inside them is not
|
|
727
|
+
// supported by better-sqlite3).
|
|
728
|
+
const totalFilesInDb = db.prepare(`SELECT COUNT(DISTINCT file) AS n FROM nodes`).get().n;
|
|
729
|
+
const p4Candidates = [];
|
|
730
|
+
const p4Captures = [];
|
|
731
|
+
if (vstmts.available && fileSymbols.size < totalFilesInDb) {
|
|
732
|
+
const changedRelPaths = new Set(fileSymbols.keys());
|
|
733
|
+
const changedFuncIds = collectFuncIdsForFiles(db, changedRelPaths);
|
|
734
|
+
const extra = await collectCallerStitchCandidates(db, changedFuncIds, changedRelPaths, rootDir, extToLang, parsers, getParserFn);
|
|
735
|
+
p4Candidates.push(...extra.candidates);
|
|
736
|
+
p4Captures.push(...extra.captures);
|
|
737
|
+
}
|
|
738
|
+
// Edge writes, vertex writes, and inter-procedural stitch are a single
|
|
739
|
+
// atomic unit: if the stitch throws or the process is killed between vertex
|
|
740
|
+
// writes and the stitch, the DB would be left with dataflow_vertices rows
|
|
741
|
+
// but no arg_in/return_out edges. Wrapping all three under one transaction
|
|
742
|
+
// boundary prevents that half-written state.
|
|
231
743
|
let totalEdges = 0;
|
|
744
|
+
let interCount = 0;
|
|
232
745
|
const tx = db.transaction(() => {
|
|
746
|
+
const allCandidates = [];
|
|
747
|
+
const allCaptures = [];
|
|
233
748
|
for (const [relPath, symbols] of fileSymbols) {
|
|
234
749
|
const ext = path.extname(relPath).toLowerCase();
|
|
235
750
|
if (!DATAFLOW_EXTENSIONS.has(ext))
|
|
@@ -237,11 +752,20 @@ export async function buildDataflowEdges(db, fileSymbols, rootDir, engineOpts) {
|
|
|
237
752
|
const data = getDataflowForFile(symbols, relPath, rootDir, extToLang, parsers, getParserFn);
|
|
238
753
|
if (!data)
|
|
239
754
|
continue;
|
|
240
|
-
|
|
755
|
+
const resolver = makeNodeResolver(stmts, relPath);
|
|
756
|
+
totalEdges += insertDataflowEdges(insert, data, resolver);
|
|
757
|
+
const { candidates, captures } = buildDataflowVerticesAndEdges(db, vstmts, data, resolver);
|
|
758
|
+
allCandidates.push(...candidates);
|
|
759
|
+
allCaptures.push(...captures);
|
|
241
760
|
}
|
|
761
|
+
// Merge in the P4 candidates collected above before opening the tx.
|
|
762
|
+
allCandidates.push(...p4Candidates);
|
|
763
|
+
allCaptures.push(...p4Captures);
|
|
764
|
+
// P2: inter-procedural stitch — runs after all per-file vertices + summaries written
|
|
765
|
+
interCount = vstmts.available ? runInterproceduralStitch(db, allCandidates, allCaptures) : 0;
|
|
242
766
|
});
|
|
243
767
|
tx();
|
|
244
|
-
info(`Dataflow: ${totalEdges} edges inserted`);
|
|
768
|
+
info(`Dataflow: ${totalEdges} fn-level edges, ${interCount} inter-procedural edges inserted`);
|
|
245
769
|
}
|
|
246
770
|
function prepareDataflowStmts(db) {
|
|
247
771
|
return {
|