@optave/codegraph 3.4.0 → 3.4.1
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 +7 -7
- package/dist/ast-analysis/engine.d.ts.map +1 -1
- package/dist/ast-analysis/engine.js +3 -9
- package/dist/ast-analysis/engine.js.map +1 -1
- package/dist/ast-analysis/shared.d.ts.map +1 -1
- package/dist/ast-analysis/shared.js +0 -1
- package/dist/ast-analysis/shared.js.map +1 -1
- package/dist/ast-analysis/visitors/cfg-conditionals.d.ts +5 -0
- package/dist/ast-analysis/visitors/cfg-conditionals.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-conditionals.js +166 -0
- package/dist/ast-analysis/visitors/cfg-conditionals.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-loops.d.ts +7 -0
- package/dist/ast-analysis/visitors/cfg-loops.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-loops.js +73 -0
- package/dist/ast-analysis/visitors/cfg-loops.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-shared.d.ts +56 -0
- package/dist/ast-analysis/visitors/cfg-shared.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-shared.js +107 -0
- package/dist/ast-analysis/visitors/cfg-shared.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.d.ts +4 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.js +100 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-visitor.d.ts +2 -2
- package/dist/ast-analysis/visitors/cfg-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/cfg-visitor.js +11 -445
- 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.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.js.map +1 -1
- package/dist/cli/commands/batch.d.ts.map +1 -1
- package/dist/cli/commands/batch.js +4 -3
- package/dist/cli/commands/batch.js.map +1 -1
- package/dist/cli/commands/branch-compare.js +1 -1
- package/dist/cli/commands/branch-compare.js.map +1 -1
- package/dist/cli/commands/build.js +1 -1
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/info.d.ts.map +1 -1
- package/dist/cli/commands/info.js +1 -2
- package/dist/cli/commands/info.js.map +1 -1
- package/dist/cli/commands/path.d.ts.map +1 -1
- package/dist/cli/commands/path.js +7 -2
- package/dist/cli/commands/path.js.map +1 -1
- package/dist/cli/commands/plot.d.ts.map +1 -1
- package/dist/cli/commands/plot.js +2 -2
- package/dist/cli/commands/plot.js.map +1 -1
- package/dist/cli/commands/watch.js +1 -1
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/shared/open-graph.d.ts +2 -2
- package/dist/cli/shared/open-graph.d.ts.map +1 -1
- package/dist/cli/shared/open-graph.js.map +1 -1
- package/dist/cli/types.d.ts +1 -1
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli.js +2 -3
- package/dist/cli.js.map +1 -1
- package/dist/db/connection.d.ts +17 -0
- package/dist/db/connection.d.ts.map +1 -1
- package/dist/db/connection.js +91 -2
- 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 +7 -0
- package/dist/db/migrations.js.map +1 -1
- package/dist/domain/analysis/brief.d.ts.map +1 -1
- package/dist/domain/analysis/brief.js +1 -3
- package/dist/domain/analysis/brief.js.map +1 -1
- package/dist/domain/analysis/context.d.ts.map +1 -1
- package/dist/domain/analysis/context.js +2 -4
- package/dist/domain/analysis/context.js.map +1 -1
- package/dist/domain/analysis/dependencies.d.ts +49 -0
- package/dist/domain/analysis/dependencies.d.ts.map +1 -1
- package/dist/domain/analysis/dependencies.js +145 -0
- package/dist/domain/analysis/dependencies.js.map +1 -1
- package/dist/domain/analysis/diff-impact.d.ts +76 -0
- package/dist/domain/analysis/diff-impact.d.ts.map +1 -0
- package/dist/domain/analysis/diff-impact.js +282 -0
- package/dist/domain/analysis/diff-impact.js.map +1 -0
- package/dist/domain/analysis/exports.d.ts.map +1 -1
- package/dist/domain/analysis/exports.js +0 -1
- package/dist/domain/analysis/exports.js.map +1 -1
- package/dist/domain/analysis/fn-impact.d.ts +66 -0
- package/dist/domain/analysis/fn-impact.d.ts.map +1 -0
- package/dist/domain/analysis/fn-impact.js +189 -0
- package/dist/domain/analysis/fn-impact.js.map +1 -0
- package/dist/domain/analysis/impact.d.ts +8 -148
- package/dist/domain/analysis/impact.d.ts.map +1 -1
- package/dist/domain/analysis/impact.js +8 -568
- package/dist/domain/analysis/impact.js.map +1 -1
- package/dist/domain/analysis/module-map.d.ts.map +1 -1
- package/dist/domain/analysis/module-map.js +1 -3
- package/dist/domain/analysis/module-map.js.map +1 -1
- package/dist/domain/graph/builder/context.d.ts +2 -3
- 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 +4 -5
- package/dist/domain/graph/builder/helpers.d.ts.map +1 -1
- package/dist/domain/graph/builder/helpers.js +1 -2
- package/dist/domain/graph/builder/helpers.js.map +1 -1
- package/dist/domain/graph/builder/incremental.d.ts +2 -3
- package/dist/domain/graph/builder/incremental.d.ts.map +1 -1
- 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 +6 -0
- package/dist/domain/graph/builder/pipeline.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.js +12 -2
- package/dist/domain/graph/builder/stages/build-edges.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-structure.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-structure.js +155 -59
- package/dist/domain/graph/builder/stages/build-structure.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 +6 -6
- 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 +85 -61
- package/dist/domain/graph/builder/stages/finalize.js.map +1 -1
- package/dist/domain/graph/builder/stages/insert-nodes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/insert-nodes.js.map +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.js +58 -11
- package/dist/domain/graph/builder/stages/resolve-imports.js.map +1 -1
- package/dist/domain/graph/cycles.js +2 -2
- package/dist/domain/graph/cycles.js.map +1 -1
- package/dist/domain/graph/resolve.d.ts.map +1 -1
- package/dist/domain/graph/resolve.js +10 -8
- package/dist/domain/graph/resolve.js.map +1 -1
- package/dist/domain/graph/watcher.d.ts.map +1 -1
- package/dist/domain/graph/watcher.js +1 -3
- package/dist/domain/graph/watcher.js.map +1 -1
- package/dist/domain/parser.d.ts.map +1 -1
- package/dist/domain/parser.js +11 -12
- package/dist/domain/parser.js.map +1 -1
- package/dist/domain/queries.d.ts +3 -2
- package/dist/domain/queries.d.ts.map +1 -1
- package/dist/domain/queries.js +3 -2
- package/dist/domain/queries.js.map +1 -1
- package/dist/domain/search/generator.d.ts.map +1 -1
- package/dist/domain/search/generator.js.map +1 -1
- package/dist/extractors/csharp.js +2 -2
- package/dist/extractors/csharp.js.map +1 -1
- package/dist/extractors/go.js +2 -2
- package/dist/extractors/go.js.map +1 -1
- package/dist/extractors/helpers.d.ts +5 -0
- package/dist/extractors/helpers.d.ts.map +1 -1
- package/dist/extractors/helpers.js +5 -0
- package/dist/extractors/helpers.js.map +1 -1
- package/dist/extractors/javascript.js +58 -60
- package/dist/extractors/javascript.js.map +1 -1
- package/dist/extractors/php.js +2 -2
- package/dist/extractors/php.js.map +1 -1
- package/dist/extractors/python.js +2 -2
- package/dist/extractors/python.js.map +1 -1
- package/dist/extractors/rust.js +2 -2
- package/dist/extractors/rust.js.map +1 -1
- package/dist/features/audit.d.ts.map +1 -1
- package/dist/features/audit.js +1 -2
- package/dist/features/audit.js.map +1 -1
- package/dist/features/branch-compare.d.ts.map +1 -1
- package/dist/features/branch-compare.js +2 -3
- package/dist/features/branch-compare.js.map +1 -1
- package/dist/features/cfg.d.ts.map +1 -1
- package/dist/features/cfg.js +2 -4
- package/dist/features/cfg.js.map +1 -1
- package/dist/features/cochange.js +4 -4
- package/dist/features/cochange.js.map +1 -1
- package/dist/features/communities.js +4 -4
- package/dist/features/communities.js.map +1 -1
- package/dist/features/complexity-query.d.ts +37 -0
- package/dist/features/complexity-query.d.ts.map +1 -0
- package/dist/features/complexity-query.js +263 -0
- package/dist/features/complexity-query.js.map +1 -0
- package/dist/features/complexity.d.ts +2 -30
- package/dist/features/complexity.d.ts.map +1 -1
- package/dist/features/complexity.js +7 -261
- package/dist/features/complexity.js.map +1 -1
- package/dist/features/dataflow.d.ts.map +1 -1
- package/dist/features/dataflow.js +8 -24
- package/dist/features/dataflow.js.map +1 -1
- package/dist/features/export.d.ts +7 -8
- package/dist/features/export.d.ts.map +1 -1
- package/dist/features/export.js.map +1 -1
- package/dist/features/flow.d.ts.map +1 -1
- package/dist/features/flow.js.map +1 -1
- package/dist/features/graph-enrichment.d.ts.map +1 -1
- package/dist/features/graph-enrichment.js +1 -3
- package/dist/features/graph-enrichment.js.map +1 -1
- package/dist/features/manifesto.js +8 -8
- package/dist/features/manifesto.js.map +1 -1
- package/dist/features/snapshot.d.ts.map +1 -1
- package/dist/features/snapshot.js +0 -1
- package/dist/features/snapshot.js.map +1 -1
- package/dist/features/structure-query.d.ts +76 -0
- package/dist/features/structure-query.d.ts.map +1 -0
- package/dist/features/structure-query.js +245 -0
- package/dist/features/structure-query.js.map +1 -0
- package/dist/features/structure.d.ts +12 -67
- package/dist/features/structure.d.ts.map +1 -1
- package/dist/features/structure.js +188 -244
- package/dist/features/structure.js.map +1 -1
- package/dist/features/triage.js +2 -2
- package/dist/features/triage.js.map +1 -1
- package/dist/graph/algorithms/leiden/adapter.d.ts.map +1 -1
- package/dist/graph/algorithms/leiden/adapter.js +2 -9
- package/dist/graph/algorithms/leiden/adapter.js.map +1 -1
- package/dist/graph/classifiers/roles.d.ts +5 -1
- package/dist/graph/classifiers/roles.d.ts.map +1 -1
- package/dist/graph/classifiers/roles.js +20 -12
- package/dist/graph/classifiers/roles.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/config.d.ts.map +1 -1
- package/dist/infrastructure/config.js +12 -11
- package/dist/infrastructure/config.js.map +1 -1
- package/dist/infrastructure/native.d.ts.map +1 -1
- package/dist/infrastructure/native.js +7 -3
- package/dist/infrastructure/native.js.map +1 -1
- package/dist/infrastructure/registry.d.ts.map +1 -1
- package/dist/infrastructure/registry.js +1 -1
- package/dist/infrastructure/registry.js.map +1 -1
- package/dist/infrastructure/update-check.js +3 -3
- package/dist/infrastructure/update-check.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +2 -8
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tool-registry.d.ts.map +1 -1
- package/dist/mcp/tool-registry.js +9 -4
- package/dist/mcp/tool-registry.js.map +1 -1
- package/dist/mcp/tools/audit.js +1 -1
- package/dist/mcp/tools/audit.js.map +1 -1
- package/dist/mcp/tools/cfg.js +1 -1
- package/dist/mcp/tools/cfg.js.map +1 -1
- package/dist/mcp/tools/check.js +2 -2
- package/dist/mcp/tools/check.js.map +1 -1
- package/dist/mcp/tools/dataflow.js +2 -2
- package/dist/mcp/tools/dataflow.js.map +1 -1
- package/dist/mcp/tools/export-graph.js +1 -1
- package/dist/mcp/tools/export-graph.js.map +1 -1
- package/dist/mcp/tools/index.d.ts.map +1 -1
- package/dist/mcp/tools/index.js.map +1 -1
- package/dist/mcp/tools/path.d.ts +1 -0
- package/dist/mcp/tools/path.d.ts.map +1 -1
- package/dist/mcp/tools/path.js +9 -0
- package/dist/mcp/tools/path.js.map +1 -1
- package/dist/mcp/tools/query.js +1 -1
- package/dist/mcp/tools/query.js.map +1 -1
- package/dist/mcp/tools/semantic-search.js +1 -1
- package/dist/mcp/tools/semantic-search.js.map +1 -1
- package/dist/mcp/tools/sequence.js +1 -1
- package/dist/mcp/tools/sequence.js.map +1 -1
- package/dist/mcp/tools/symbol-children.js +1 -1
- package/dist/mcp/tools/symbol-children.js.map +1 -1
- package/dist/mcp/tools/triage.js +1 -1
- package/dist/mcp/tools/triage.js.map +1 -1
- package/dist/presentation/audit.d.ts.map +1 -1
- package/dist/presentation/audit.js +0 -1
- package/dist/presentation/audit.js.map +1 -1
- package/dist/presentation/diff-impact-mermaid.d.ts +11 -0
- package/dist/presentation/diff-impact-mermaid.d.ts.map +1 -0
- package/dist/presentation/diff-impact-mermaid.js +105 -0
- package/dist/presentation/diff-impact-mermaid.js.map +1 -0
- package/dist/presentation/flow.d.ts.map +1 -1
- package/dist/presentation/flow.js +0 -2
- package/dist/presentation/flow.js.map +1 -1
- package/dist/presentation/manifesto.d.ts.map +1 -1
- package/dist/presentation/manifesto.js +0 -1
- package/dist/presentation/manifesto.js.map +1 -1
- package/dist/presentation/queries-cli/inspect.d.ts.map +1 -1
- package/dist/presentation/queries-cli/inspect.js.map +1 -1
- package/dist/presentation/queries-cli/path.d.ts.map +1 -1
- package/dist/presentation/queries-cli/path.js +45 -1
- package/dist/presentation/queries-cli/path.js.map +1 -1
- package/dist/presentation/result-formatter.d.ts.map +1 -1
- package/dist/presentation/result-formatter.js +1 -3
- package/dist/presentation/result-formatter.js.map +1 -1
- package/dist/presentation/sequence.d.ts.map +1 -1
- package/dist/presentation/sequence.js +0 -1
- package/dist/presentation/sequence.js.map +1 -1
- package/dist/presentation/structure.d.ts.map +1 -1
- package/dist/presentation/structure.js.map +1 -1
- package/dist/presentation/triage.d.ts.map +1 -1
- package/dist/presentation/triage.js +0 -1
- package/dist/presentation/triage.js.map +1 -1
- package/dist/shared/constants.d.ts +9 -3
- package/dist/shared/constants.d.ts.map +1 -1
- package/dist/shared/constants.js +6 -3
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/errors.d.ts +2 -0
- package/dist/shared/errors.d.ts.map +1 -1
- package/dist/shared/errors.js +4 -0
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/version.d.ts +2 -0
- package/dist/shared/version.d.ts.map +1 -0
- package/dist/shared/version.js +5 -0
- package/dist/shared/version.js.map +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/ast-analysis/engine.ts +3 -9
- package/src/ast-analysis/shared.ts +0 -1
- package/src/ast-analysis/visitors/cfg-conditionals.ts +227 -0
- package/src/ast-analysis/visitors/cfg-loops.ts +136 -0
- package/src/ast-analysis/visitors/cfg-shared.ts +196 -0
- package/src/ast-analysis/visitors/cfg-try-catch.ts +142 -0
- package/src/ast-analysis/visitors/cfg-visitor.ts +34 -655
- package/src/ast-analysis/visitors/complexity-visitor.ts +0 -1
- package/src/ast-analysis/visitors/dataflow-visitor.ts +0 -1
- package/src/cli/commands/batch.ts +4 -3
- package/src/cli/commands/branch-compare.ts +1 -1
- package/src/cli/commands/build.ts +1 -1
- package/src/cli/commands/info.ts +1 -2
- package/src/cli/commands/path.ts +7 -2
- package/src/cli/commands/plot.ts +2 -2
- package/src/cli/commands/watch.ts +1 -1
- package/src/cli/index.ts +2 -2
- package/src/cli/shared/open-graph.ts +2 -2
- package/src/cli/types.ts +1 -1
- package/src/cli.ts +2 -3
- package/src/db/connection.ts +97 -13
- package/src/db/index.ts +2 -0
- package/src/db/migrations.ts +7 -0
- package/src/domain/analysis/brief.ts +0 -1
- package/src/domain/analysis/context.ts +2 -6
- package/src/domain/analysis/dependencies.ts +165 -0
- package/src/domain/analysis/diff-impact.ts +354 -0
- package/src/domain/analysis/exports.ts +0 -2
- package/src/domain/analysis/fn-impact.ts +241 -0
- package/src/domain/analysis/impact.ts +8 -718
- package/src/domain/analysis/module-map.ts +1 -5
- package/src/domain/graph/builder/context.ts +2 -2
- package/src/domain/graph/builder/helpers.ts +14 -11
- package/src/domain/graph/builder/incremental.ts +33 -28
- package/src/domain/graph/builder/pipeline.ts +8 -0
- package/src/domain/graph/builder/stages/build-edges.ts +17 -4
- package/src/domain/graph/builder/stages/build-structure.ts +205 -76
- package/src/domain/graph/builder/stages/detect-changes.ts +11 -12
- package/src/domain/graph/builder/stages/finalize.ts +100 -81
- package/src/domain/graph/builder/stages/insert-nodes.ts +12 -8
- package/src/domain/graph/builder/stages/resolve-imports.ts +75 -10
- package/src/domain/graph/cycles.ts +2 -2
- package/src/domain/graph/resolve.ts +14 -8
- package/src/domain/graph/watcher.ts +2 -4
- package/src/domain/parser.ts +11 -13
- package/src/domain/queries.ts +2 -2
- package/src/domain/search/generator.ts +3 -4
- package/src/extractors/csharp.ts +2 -2
- package/src/extractors/go.ts +2 -2
- package/src/extractors/helpers.ts +6 -0
- package/src/extractors/javascript.ts +58 -61
- package/src/extractors/php.ts +2 -2
- package/src/extractors/python.ts +2 -2
- package/src/extractors/rust.ts +2 -2
- package/src/features/audit.ts +1 -2
- package/src/features/branch-compare.ts +3 -9
- package/src/features/cfg.ts +2 -4
- package/src/features/cochange.ts +4 -4
- package/src/features/communities.ts +4 -4
- package/src/features/complexity-query.ts +370 -0
- package/src/features/complexity.ts +6 -365
- package/src/features/dataflow.ts +48 -70
- package/src/features/export.ts +12 -16
- package/src/features/flow.ts +0 -1
- package/src/features/graph-enrichment.ts +1 -3
- package/src/features/manifesto.ts +8 -8
- package/src/features/snapshot.ts +1 -2
- package/src/features/structure-query.ts +387 -0
- package/src/features/structure.ts +231 -376
- package/src/features/triage.ts +2 -2
- package/src/graph/algorithms/leiden/adapter.ts +2 -9
- package/src/graph/classifiers/roles.ts +22 -13
- package/src/index.ts +1 -0
- package/src/infrastructure/config.ts +12 -13
- package/src/infrastructure/native.ts +7 -3
- package/src/infrastructure/registry.ts +1 -1
- package/src/infrastructure/update-check.ts +3 -3
- package/src/mcp/server.ts +2 -10
- package/src/mcp/tool-registry.ts +11 -4
- package/src/mcp/tools/audit.ts +1 -1
- package/src/mcp/tools/cfg.ts +1 -1
- package/src/mcp/tools/check.ts +2 -2
- package/src/mcp/tools/dataflow.ts +2 -2
- package/src/mcp/tools/export-graph.ts +1 -1
- package/src/mcp/tools/index.ts +0 -1
- package/src/mcp/tools/path.ts +10 -0
- 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/symbol-children.ts +1 -1
- package/src/mcp/tools/triage.ts +1 -1
- package/src/presentation/audit.ts +0 -1
- package/src/presentation/diff-impact-mermaid.ts +127 -0
- package/src/presentation/flow.ts +0 -2
- package/src/presentation/manifesto.ts +0 -1
- package/src/presentation/queries-cli/inspect.ts +0 -1
- package/src/presentation/queries-cli/path.ts +71 -1
- package/src/presentation/result-formatter.ts +0 -1
- package/src/presentation/sequence.ts +0 -1
- package/src/presentation/structure.ts +0 -12
- package/src/presentation/triage.ts +0 -1
- package/src/shared/constants.ts +33 -19
- package/src/shared/errors.ts +5 -0
- package/src/shared/version.ts +10 -0
- package/src/types.ts +4 -10
- package/src/vendor.d.ts +0 -39
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complexity query functions — read-only DB queries for complexity metrics.
|
|
3
|
+
*
|
|
4
|
+
* Split from complexity.ts to separate query-time concerns (DB reads, filtering,
|
|
5
|
+
* pagination) from compute-time concerns (AST traversal, metric algorithms).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { openReadonlyOrFail } from '../db/index.js';
|
|
9
|
+
import { buildFileConditionSQL } from '../db/query-builder.js';
|
|
10
|
+
import { loadConfig } from '../infrastructure/config.js';
|
|
11
|
+
import { debug } from '../infrastructure/logger.js';
|
|
12
|
+
import { isTestFile } from '../infrastructure/test-filter.js';
|
|
13
|
+
import { paginateResult } from '../shared/paginate.js';
|
|
14
|
+
import type { CodegraphConfig } from '../types.js';
|
|
15
|
+
|
|
16
|
+
// ─── Query-Time Functions ─────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
interface ComplexityRow {
|
|
19
|
+
name: string;
|
|
20
|
+
kind: string;
|
|
21
|
+
file: string;
|
|
22
|
+
line: number;
|
|
23
|
+
end_line: number | null;
|
|
24
|
+
cognitive: number;
|
|
25
|
+
cyclomatic: number;
|
|
26
|
+
max_nesting: number;
|
|
27
|
+
loc: number;
|
|
28
|
+
sloc: number;
|
|
29
|
+
maintainability_index: number;
|
|
30
|
+
halstead_volume: number;
|
|
31
|
+
halstead_difficulty: number;
|
|
32
|
+
halstead_effort: number;
|
|
33
|
+
halstead_bugs: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function complexityData(
|
|
37
|
+
customDbPath?: string,
|
|
38
|
+
opts: {
|
|
39
|
+
target?: string;
|
|
40
|
+
limit?: number;
|
|
41
|
+
sort?: string;
|
|
42
|
+
aboveThreshold?: boolean;
|
|
43
|
+
file?: string;
|
|
44
|
+
kind?: string;
|
|
45
|
+
noTests?: boolean;
|
|
46
|
+
config?: CodegraphConfig;
|
|
47
|
+
offset?: number;
|
|
48
|
+
} = {},
|
|
49
|
+
): Record<string, unknown> {
|
|
50
|
+
const db = openReadonlyOrFail(customDbPath);
|
|
51
|
+
try {
|
|
52
|
+
const sort = opts.sort || 'cognitive';
|
|
53
|
+
const noTests = opts.noTests || false;
|
|
54
|
+
const aboveThreshold = opts.aboveThreshold || false;
|
|
55
|
+
const target = opts.target || null;
|
|
56
|
+
const fileFilter = opts.file || null;
|
|
57
|
+
const kindFilter = opts.kind || null;
|
|
58
|
+
|
|
59
|
+
// Load thresholds from config
|
|
60
|
+
const config = opts.config || loadConfig(process.cwd());
|
|
61
|
+
const thresholds: any = config.manifesto?.rules || {
|
|
62
|
+
cognitive: { warn: 15, fail: null },
|
|
63
|
+
cyclomatic: { warn: 10, fail: null },
|
|
64
|
+
maxNesting: { warn: 4, fail: null },
|
|
65
|
+
maintainabilityIndex: { warn: 20, fail: null },
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// Build query
|
|
69
|
+
let where = "WHERE n.kind IN ('function','method')";
|
|
70
|
+
const params: unknown[] = [];
|
|
71
|
+
|
|
72
|
+
if (noTests) {
|
|
73
|
+
where += ` AND n.file NOT LIKE '%.test.%'
|
|
74
|
+
AND n.file NOT LIKE '%.spec.%'
|
|
75
|
+
AND n.file NOT LIKE '%__test__%'
|
|
76
|
+
AND n.file NOT LIKE '%__tests__%'
|
|
77
|
+
AND n.file NOT LIKE '%.stories.%'`;
|
|
78
|
+
}
|
|
79
|
+
if (target) {
|
|
80
|
+
where += ' AND n.name LIKE ?';
|
|
81
|
+
params.push(`%${target}%`);
|
|
82
|
+
}
|
|
83
|
+
{
|
|
84
|
+
const fc = buildFileConditionSQL(fileFilter as string, 'n.file');
|
|
85
|
+
where += fc.sql;
|
|
86
|
+
params.push(...fc.params);
|
|
87
|
+
}
|
|
88
|
+
if (kindFilter) {
|
|
89
|
+
where += ' AND n.kind = ?';
|
|
90
|
+
params.push(kindFilter);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const isValidThreshold = (v: unknown): v is number =>
|
|
94
|
+
typeof v === 'number' && Number.isFinite(v);
|
|
95
|
+
|
|
96
|
+
let having = '';
|
|
97
|
+
if (aboveThreshold) {
|
|
98
|
+
const conditions: string[] = [];
|
|
99
|
+
if (isValidThreshold(thresholds.cognitive?.warn)) {
|
|
100
|
+
conditions.push(`fc.cognitive >= ${thresholds.cognitive.warn}`);
|
|
101
|
+
}
|
|
102
|
+
if (isValidThreshold(thresholds.cyclomatic?.warn)) {
|
|
103
|
+
conditions.push(`fc.cyclomatic >= ${thresholds.cyclomatic.warn}`);
|
|
104
|
+
}
|
|
105
|
+
if (isValidThreshold(thresholds.maxNesting?.warn)) {
|
|
106
|
+
conditions.push(`fc.max_nesting >= ${thresholds.maxNesting.warn}`);
|
|
107
|
+
}
|
|
108
|
+
if (isValidThreshold(thresholds.maintainabilityIndex?.warn)) {
|
|
109
|
+
conditions.push(
|
|
110
|
+
`fc.maintainability_index > 0 AND fc.maintainability_index <= ${thresholds.maintainabilityIndex.warn}`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
if (conditions.length > 0) {
|
|
114
|
+
having = `AND (${conditions.join(' OR ')})`;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const orderMap: Record<string, string> = {
|
|
119
|
+
cognitive: 'fc.cognitive DESC',
|
|
120
|
+
cyclomatic: 'fc.cyclomatic DESC',
|
|
121
|
+
nesting: 'fc.max_nesting DESC',
|
|
122
|
+
mi: 'fc.maintainability_index ASC',
|
|
123
|
+
volume: 'fc.halstead_volume DESC',
|
|
124
|
+
effort: 'fc.halstead_effort DESC',
|
|
125
|
+
bugs: 'fc.halstead_bugs DESC',
|
|
126
|
+
loc: 'fc.loc DESC',
|
|
127
|
+
};
|
|
128
|
+
const orderBy = orderMap[sort] || 'fc.cognitive DESC';
|
|
129
|
+
|
|
130
|
+
let rows: ComplexityRow[];
|
|
131
|
+
try {
|
|
132
|
+
rows = db
|
|
133
|
+
.prepare<ComplexityRow>(
|
|
134
|
+
`SELECT n.name, n.kind, n.file, n.line, n.end_line,
|
|
135
|
+
fc.cognitive, fc.cyclomatic, fc.max_nesting,
|
|
136
|
+
fc.loc, fc.sloc, fc.maintainability_index,
|
|
137
|
+
fc.halstead_volume, fc.halstead_difficulty, fc.halstead_effort, fc.halstead_bugs
|
|
138
|
+
FROM function_complexity fc
|
|
139
|
+
JOIN nodes n ON fc.node_id = n.id
|
|
140
|
+
${where} ${having}
|
|
141
|
+
ORDER BY ${orderBy}`,
|
|
142
|
+
)
|
|
143
|
+
.all(...params);
|
|
144
|
+
} catch (e: unknown) {
|
|
145
|
+
debug(`complexity query failed (table may not exist): ${(e as Error).message}`);
|
|
146
|
+
// Check if graph has nodes even though complexity table is missing/empty
|
|
147
|
+
let hasGraph = false;
|
|
148
|
+
try {
|
|
149
|
+
hasGraph = (db.prepare<{ c: number }>('SELECT COUNT(*) as c FROM nodes').get()?.c ?? 0) > 0;
|
|
150
|
+
} catch (e2: unknown) {
|
|
151
|
+
debug(`nodes table check failed: ${(e2 as Error).message}`);
|
|
152
|
+
}
|
|
153
|
+
return { functions: [], summary: null, thresholds, hasGraph };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Post-filter test files if needed (belt-and-suspenders for isTestFile)
|
|
157
|
+
const filtered = noTests ? rows.filter((r) => !isTestFile(r.file)) : rows;
|
|
158
|
+
|
|
159
|
+
const functions = filtered.map((r) => {
|
|
160
|
+
const exceeds: string[] = [];
|
|
161
|
+
if (
|
|
162
|
+
isValidThreshold(thresholds.cognitive?.warn) &&
|
|
163
|
+
r.cognitive >= (thresholds.cognitive?.warn ?? 0)
|
|
164
|
+
)
|
|
165
|
+
exceeds.push('cognitive');
|
|
166
|
+
if (
|
|
167
|
+
isValidThreshold(thresholds.cyclomatic?.warn) &&
|
|
168
|
+
r.cyclomatic >= (thresholds.cyclomatic?.warn ?? 0)
|
|
169
|
+
)
|
|
170
|
+
exceeds.push('cyclomatic');
|
|
171
|
+
if (
|
|
172
|
+
isValidThreshold(thresholds.maxNesting?.warn) &&
|
|
173
|
+
r.max_nesting >= (thresholds.maxNesting?.warn ?? 0)
|
|
174
|
+
)
|
|
175
|
+
exceeds.push('maxNesting');
|
|
176
|
+
if (
|
|
177
|
+
isValidThreshold(thresholds.maintainabilityIndex?.warn) &&
|
|
178
|
+
r.maintainability_index > 0 &&
|
|
179
|
+
r.maintainability_index <= (thresholds.maintainabilityIndex?.warn ?? 0)
|
|
180
|
+
)
|
|
181
|
+
exceeds.push('maintainabilityIndex');
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
name: r.name,
|
|
185
|
+
kind: r.kind,
|
|
186
|
+
file: r.file,
|
|
187
|
+
line: r.line,
|
|
188
|
+
endLine: r.end_line || null,
|
|
189
|
+
cognitive: r.cognitive,
|
|
190
|
+
cyclomatic: r.cyclomatic,
|
|
191
|
+
maxNesting: r.max_nesting,
|
|
192
|
+
loc: r.loc || 0,
|
|
193
|
+
sloc: r.sloc || 0,
|
|
194
|
+
maintainabilityIndex: r.maintainability_index || 0,
|
|
195
|
+
halstead: {
|
|
196
|
+
volume: r.halstead_volume || 0,
|
|
197
|
+
difficulty: r.halstead_difficulty || 0,
|
|
198
|
+
effort: r.halstead_effort || 0,
|
|
199
|
+
bugs: r.halstead_bugs || 0,
|
|
200
|
+
},
|
|
201
|
+
exceeds: exceeds.length > 0 ? exceeds : undefined,
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Summary stats
|
|
206
|
+
let summary: Record<string, unknown> | null = null;
|
|
207
|
+
try {
|
|
208
|
+
const allRows = db
|
|
209
|
+
.prepare<{
|
|
210
|
+
cognitive: number;
|
|
211
|
+
cyclomatic: number;
|
|
212
|
+
max_nesting: number;
|
|
213
|
+
maintainability_index: number;
|
|
214
|
+
}>(
|
|
215
|
+
`SELECT fc.cognitive, fc.cyclomatic, fc.max_nesting, fc.maintainability_index
|
|
216
|
+
FROM function_complexity fc JOIN nodes n ON fc.node_id = n.id
|
|
217
|
+
WHERE n.kind IN ('function','method')
|
|
218
|
+
${noTests ? `AND n.file NOT LIKE '%.test.%' AND n.file NOT LIKE '%.spec.%' AND n.file NOT LIKE '%__test__%' AND n.file NOT LIKE '%__tests__%' AND n.file NOT LIKE '%.stories.%'` : ''}`,
|
|
219
|
+
)
|
|
220
|
+
.all();
|
|
221
|
+
|
|
222
|
+
if (allRows.length > 0) {
|
|
223
|
+
const miValues = allRows.map((r) => r.maintainability_index || 0);
|
|
224
|
+
summary = {
|
|
225
|
+
analyzed: allRows.length,
|
|
226
|
+
avgCognitive: +(allRows.reduce((s, r) => s + r.cognitive, 0) / allRows.length).toFixed(1),
|
|
227
|
+
avgCyclomatic: +(allRows.reduce((s, r) => s + r.cyclomatic, 0) / allRows.length).toFixed(
|
|
228
|
+
1,
|
|
229
|
+
),
|
|
230
|
+
maxCognitive: Math.max(...allRows.map((r) => r.cognitive)),
|
|
231
|
+
maxCyclomatic: Math.max(...allRows.map((r) => r.cyclomatic)),
|
|
232
|
+
avgMI: +(miValues.reduce((s, v) => s + v, 0) / miValues.length).toFixed(1),
|
|
233
|
+
minMI: +Math.min(...miValues).toFixed(1),
|
|
234
|
+
aboveWarn: allRows.filter(
|
|
235
|
+
(r) =>
|
|
236
|
+
(isValidThreshold(thresholds.cognitive?.warn) &&
|
|
237
|
+
r.cognitive >= (thresholds.cognitive?.warn ?? 0)) ||
|
|
238
|
+
(isValidThreshold(thresholds.cyclomatic?.warn) &&
|
|
239
|
+
r.cyclomatic >= (thresholds.cyclomatic?.warn ?? 0)) ||
|
|
240
|
+
(isValidThreshold(thresholds.maxNesting?.warn) &&
|
|
241
|
+
r.max_nesting >= (thresholds.maxNesting?.warn ?? 0)) ||
|
|
242
|
+
(isValidThreshold(thresholds.maintainabilityIndex?.warn) &&
|
|
243
|
+
r.maintainability_index > 0 &&
|
|
244
|
+
r.maintainability_index <= (thresholds.maintainabilityIndex?.warn ?? 0)),
|
|
245
|
+
).length,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
} catch (e: unknown) {
|
|
249
|
+
debug(`complexity summary query failed: ${(e as Error).message}`);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// When summary is null (no complexity rows), check if graph has nodes
|
|
253
|
+
let hasGraph = false;
|
|
254
|
+
if (summary === null) {
|
|
255
|
+
try {
|
|
256
|
+
hasGraph = (db.prepare<{ c: number }>('SELECT COUNT(*) as c FROM nodes').get()?.c ?? 0) > 0;
|
|
257
|
+
} catch (e: unknown) {
|
|
258
|
+
debug(`nodes table check failed: ${(e as Error).message}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const base = { functions, summary, thresholds, hasGraph };
|
|
263
|
+
return paginateResult(base, 'functions', { limit: opts.limit, offset: opts.offset });
|
|
264
|
+
} finally {
|
|
265
|
+
db.close();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
interface IterComplexityRow {
|
|
270
|
+
name: string;
|
|
271
|
+
kind: string;
|
|
272
|
+
file: string;
|
|
273
|
+
line: number;
|
|
274
|
+
end_line: number | null;
|
|
275
|
+
cognitive: number;
|
|
276
|
+
cyclomatic: number;
|
|
277
|
+
max_nesting: number;
|
|
278
|
+
loc: number;
|
|
279
|
+
sloc: number;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function* iterComplexity(
|
|
283
|
+
customDbPath?: string,
|
|
284
|
+
opts: {
|
|
285
|
+
noTests?: boolean;
|
|
286
|
+
file?: string;
|
|
287
|
+
target?: string;
|
|
288
|
+
kind?: string;
|
|
289
|
+
sort?: string;
|
|
290
|
+
} = {},
|
|
291
|
+
): Generator<{
|
|
292
|
+
name: string;
|
|
293
|
+
kind: string;
|
|
294
|
+
file: string;
|
|
295
|
+
line: number;
|
|
296
|
+
endLine: number | null;
|
|
297
|
+
cognitive: number;
|
|
298
|
+
cyclomatic: number;
|
|
299
|
+
maxNesting: number;
|
|
300
|
+
loc: number;
|
|
301
|
+
sloc: number;
|
|
302
|
+
}> {
|
|
303
|
+
const db = openReadonlyOrFail(customDbPath);
|
|
304
|
+
try {
|
|
305
|
+
const noTests = opts.noTests || false;
|
|
306
|
+
const sort = opts.sort || 'cognitive';
|
|
307
|
+
|
|
308
|
+
let where = "WHERE n.kind IN ('function','method')";
|
|
309
|
+
const params: unknown[] = [];
|
|
310
|
+
|
|
311
|
+
if (noTests) {
|
|
312
|
+
where += ` AND n.file NOT LIKE '%.test.%'
|
|
313
|
+
AND n.file NOT LIKE '%.spec.%'
|
|
314
|
+
AND n.file NOT LIKE '%__test__%'
|
|
315
|
+
AND n.file NOT LIKE '%__tests__%'
|
|
316
|
+
AND n.file NOT LIKE '%.stories.%'`;
|
|
317
|
+
}
|
|
318
|
+
if (opts.target) {
|
|
319
|
+
where += ' AND n.name LIKE ?';
|
|
320
|
+
params.push(`%${opts.target}%`);
|
|
321
|
+
}
|
|
322
|
+
{
|
|
323
|
+
const fc = buildFileConditionSQL(opts.file as string, 'n.file');
|
|
324
|
+
where += fc.sql;
|
|
325
|
+
params.push(...fc.params);
|
|
326
|
+
}
|
|
327
|
+
if (opts.kind) {
|
|
328
|
+
where += ' AND n.kind = ?';
|
|
329
|
+
params.push(opts.kind);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const orderMap: Record<string, string> = {
|
|
333
|
+
cognitive: 'fc.cognitive DESC',
|
|
334
|
+
cyclomatic: 'fc.cyclomatic DESC',
|
|
335
|
+
nesting: 'fc.max_nesting DESC',
|
|
336
|
+
mi: 'fc.maintainability_index ASC',
|
|
337
|
+
volume: 'fc.halstead_volume DESC',
|
|
338
|
+
effort: 'fc.halstead_effort DESC',
|
|
339
|
+
bugs: 'fc.halstead_bugs DESC',
|
|
340
|
+
loc: 'fc.loc DESC',
|
|
341
|
+
};
|
|
342
|
+
const orderBy = orderMap[sort] || 'fc.cognitive DESC';
|
|
343
|
+
|
|
344
|
+
const stmt = db.prepare<IterComplexityRow>(
|
|
345
|
+
`SELECT n.name, n.kind, n.file, n.line, n.end_line,
|
|
346
|
+
fc.cognitive, fc.cyclomatic, fc.max_nesting, fc.loc, fc.sloc
|
|
347
|
+
FROM function_complexity fc
|
|
348
|
+
JOIN nodes n ON fc.node_id = n.id
|
|
349
|
+
${where}
|
|
350
|
+
ORDER BY ${orderBy}`,
|
|
351
|
+
);
|
|
352
|
+
for (const r of stmt.iterate(...params)) {
|
|
353
|
+
if (noTests && isTestFile(r.file)) continue;
|
|
354
|
+
yield {
|
|
355
|
+
name: r.name,
|
|
356
|
+
kind: r.kind,
|
|
357
|
+
file: r.file,
|
|
358
|
+
line: r.line,
|
|
359
|
+
endLine: r.end_line || null,
|
|
360
|
+
cognitive: r.cognitive,
|
|
361
|
+
cyclomatic: r.cyclomatic,
|
|
362
|
+
maxNesting: r.max_nesting,
|
|
363
|
+
loc: r.loc || 0,
|
|
364
|
+
sloc: r.sloc || 0,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
} finally {
|
|
368
|
+
db.close();
|
|
369
|
+
}
|
|
370
|
+
}
|