@monoes/monograph 1.5.6 → 1.5.8
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 +31 -15
- package/dist/src/analysis/changed-files.d.ts +3 -0
- package/dist/src/analysis/changed-files.d.ts.map +1 -1
- package/dist/src/analysis/changed-files.js +11 -9
- package/dist/src/analysis/changed-files.js.map +1 -1
- package/dist/src/analysis/changed-workspaces.d.ts.map +1 -1
- package/dist/src/analysis/changed-workspaces.js +2 -9
- package/dist/src/analysis/changed-workspaces.js.map +1 -1
- package/dist/src/analysis/git-changed-files.d.ts +3 -0
- package/dist/src/analysis/git-changed-files.d.ts.map +1 -1
- package/dist/src/analysis/git-changed-files.js +17 -12
- package/dist/src/analysis/git-changed-files.js.map +1 -1
- package/dist/src/analysis/git-ref.d.ts +33 -0
- package/dist/src/analysis/git-ref.d.ts.map +1 -0
- package/dist/src/analysis/git-ref.js +54 -0
- package/dist/src/analysis/git-ref.js.map +1 -0
- package/dist/src/analyze/boundary-analysis.d.ts.map +1 -1
- package/dist/src/analyze/boundary-analysis.js +42 -42
- package/dist/src/analyze/boundary-analysis.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/lsp/server.d.ts +1 -1
- package/dist/src/lsp/server.d.ts.map +1 -1
- package/dist/src/lsp/server.js +48 -13
- package/dist/src/lsp/server.js.map +1 -1
- package/dist/src/mcp-tools/api-impact.d.ts.map +1 -1
- package/dist/src/mcp-tools/api-impact.js +1 -16
- package/dist/src/mcp-tools/api-impact.js.map +1 -1
- package/dist/src/mcp-tools/context.d.ts.map +1 -1
- package/dist/src/mcp-tools/context.js +12 -23
- package/dist/src/mcp-tools/context.js.map +1 -1
- package/dist/src/mcp-tools/explain.d.ts.map +1 -1
- package/dist/src/mcp-tools/explain.js +15 -20
- package/dist/src/mcp-tools/explain.js.map +1 -1
- package/dist/src/mcp-tools/graph-query.d.ts.map +1 -1
- package/dist/src/mcp-tools/graph-query.js +10 -19
- package/dist/src/mcp-tools/graph-query.js.map +1 -1
- package/dist/src/mcp-tools/impact.d.ts.map +1 -1
- package/dist/src/mcp-tools/impact.js +38 -41
- package/dist/src/mcp-tools/impact.js.map +1 -1
- package/dist/src/mcp-tools/neighbors.d.ts.map +1 -1
- package/dist/src/mcp-tools/neighbors.js +4 -22
- package/dist/src/mcp-tools/neighbors.js.map +1 -1
- package/dist/src/mcp-tools/query.d.ts.map +1 -1
- package/dist/src/mcp-tools/query.js +14 -9
- package/dist/src/mcp-tools/query.js.map +1 -1
- package/dist/src/mcp-tools/rename.d.ts.map +1 -1
- package/dist/src/mcp-tools/rename.js +3 -20
- package/dist/src/mcp-tools/rename.js.map +1 -1
- package/dist/src/parsers/c.d.ts.map +1 -1
- package/dist/src/parsers/c.js +12 -0
- package/dist/src/parsers/c.js.map +1 -1
- package/dist/src/parsers/extractor.d.ts.map +1 -1
- package/dist/src/parsers/extractor.js +2 -1
- package/dist/src/parsers/extractor.js.map +1 -1
- package/dist/src/parsers/go.d.ts.map +1 -1
- package/dist/src/parsers/go.js +19 -1
- package/dist/src/parsers/go.js.map +1 -1
- package/dist/src/parsers/language-config.d.ts +4 -0
- package/dist/src/parsers/language-config.d.ts.map +1 -1
- package/dist/src/parsers/language-parsers.d.ts.map +1 -1
- package/dist/src/parsers/language-parsers.js +3 -1
- package/dist/src/parsers/language-parsers.js.map +1 -1
- package/dist/src/parsers/loader.d.ts +1 -0
- package/dist/src/parsers/loader.d.ts.map +1 -1
- package/dist/src/parsers/loader.js +161 -20
- package/dist/src/parsers/loader.js.map +1 -1
- package/dist/src/parsers/python.d.ts.map +1 -1
- package/dist/src/parsers/python.js +6 -0
- package/dist/src/parsers/python.js.map +1 -1
- package/dist/src/parsers/rust.d.ts.map +1 -1
- package/dist/src/parsers/rust.js +10 -0
- package/dist/src/parsers/rust.js.map +1 -1
- package/dist/src/pipeline/orchestrator.d.ts.map +1 -1
- package/dist/src/pipeline/orchestrator.js +17 -0
- package/dist/src/pipeline/orchestrator.js.map +1 -1
- package/dist/src/pipeline/phases/pdf-parse.d.ts.map +1 -1
- package/dist/src/pipeline/phases/pdf-parse.js +10 -11
- package/dist/src/pipeline/phases/pdf-parse.js.map +1 -1
- package/dist/src/storage/edge-store.d.ts +1 -0
- package/dist/src/storage/edge-store.d.ts.map +1 -1
- package/dist/src/storage/edge-store.js +5 -8
- package/dist/src/storage/edge-store.js.map +1 -1
- package/dist/src/storage/node-store.d.ts +1 -0
- package/dist/src/storage/node-store.d.ts.map +1 -1
- package/dist/src/storage/node-store.js +11 -12
- package/dist/src/storage/node-store.js.map +1 -1
- package/dist/src/storage/schema.d.ts.map +1 -1
- package/dist/src/storage/schema.js +6 -0
- package/dist/src/storage/schema.js.map +1 -1
- package/dist/src/storage/utils.d.ts +11 -0
- package/dist/src/storage/utils.d.ts.map +1 -0
- package/dist/src/storage/utils.js +24 -0
- package/dist/src/storage/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -9
- package/.monomind/data/ranked-context.json +0 -5
- package/.monomind/loops/mastermind-review-1782162423447.json +0 -16
- package/.monomind/sessions/session-1777578175215.json +0 -15
- package/.monomind/sessions/session-1777823684507.json +0 -15
- package/.monomind/sessions/session-1777928944749.json +0 -15
- package/.monomind/sessions/session-1778052902210.json +0 -15
- package/.monomind/sessions/session-1778056744636.json +0 -15
- package/.monomind/sessions/session-1778061077599.json +0 -15
- package/.monomind/sessions/session-1778102154764.json +0 -15
- package/__tests__/analysis/shape-extractor.test.ts +0 -124
- package/__tests__/analysis/surprise-scorer.test.ts +0 -154
- package/__tests__/cache/extraction-cache.test.ts +0 -45
- package/__tests__/cli/ai-context.test.ts +0 -175
- package/__tests__/cli/augment.test.ts +0 -128
- package/__tests__/cli/doctor.test.ts +0 -125
- package/__tests__/cli/eval-server.test.ts +0 -89
- package/__tests__/cli/setup.test.ts +0 -178
- package/__tests__/cli/skill-gen.test.ts +0 -280
- package/__tests__/export/formats.test.ts +0 -82
- package/__tests__/fixtures/sample.c +0 -25
- package/__tests__/fixtures/sample.cpp +0 -32
- package/__tests__/fixtures/sample.dart +0 -34
- package/__tests__/fixtures/sample.kt +0 -30
- package/__tests__/fixtures/sample.php +0 -30
- package/__tests__/fixtures/sample.py +0 -11
- package/__tests__/fixtures/sample.rb +0 -26
- package/__tests__/fixtures/sample.swift +0 -42
- package/__tests__/fixtures/sample.ts +0 -17
- package/__tests__/fixtures/sample.vue +0 -40
- package/__tests__/groups/group-search.test.ts +0 -221
- package/__tests__/groups/group-sync.test.ts +0 -336
- package/__tests__/integration/build-atomicity.test.ts +0 -61
- package/__tests__/integration/call-attribution.test.ts +0 -116
- package/__tests__/integration/full-pipeline.test.ts +0 -64
- package/__tests__/integration/graph-report-freshness.test.ts +0 -53
- package/__tests__/integration/incremental-build.test.ts +0 -103
- package/__tests__/mcp-resources/resources.test.ts +0 -256
- package/__tests__/mcp-tools/api-impact.test.ts +0 -188
- package/__tests__/mcp-tools/context.test.ts +0 -130
- package/__tests__/mcp-tools/cypher.test.ts +0 -258
- package/__tests__/mcp-tools/detect-changes.test.ts +0 -114
- package/__tests__/mcp-tools/impact.test.ts +0 -133
- package/__tests__/mcp-tools/rename.test.ts +0 -117
- package/__tests__/mcp-tools/route-map.test.ts +0 -237
- package/__tests__/mcp-tools/shape-check.test.ts +0 -202
- package/__tests__/mcp-tools/tool-map.test.ts +0 -135
- package/__tests__/parsers/c.test.ts +0 -28
- package/__tests__/parsers/cpp.test.ts +0 -28
- package/__tests__/parsers/csharp.test.ts +0 -62
- package/__tests__/parsers/dart.test.ts +0 -28
- package/__tests__/parsers/kotlin.test.ts +0 -28
- package/__tests__/parsers/loader.test.ts +0 -14
- package/__tests__/parsers/php.test.ts +0 -28
- package/__tests__/parsers/python.test.ts +0 -32
- package/__tests__/parsers/ruby.test.ts +0 -33
- package/__tests__/parsers/swift.test.ts +0 -28
- package/__tests__/parsers/typescript.test.ts +0 -45
- package/__tests__/parsers/vue.test.ts +0 -28
- package/__tests__/pipeline/analysis.test.ts +0 -58
- package/__tests__/pipeline/phases/corpus-check.test.ts +0 -26
- package/__tests__/pipeline/phases/evidence.test.ts +0 -41
- package/__tests__/pipeline/phases/field-access.test.ts +0 -22
- package/__tests__/pipeline/phases/leiden.test.ts +0 -72
- package/__tests__/pipeline/phases/markdown.test.ts +0 -84
- package/__tests__/pipeline/phases/middleware-extractor.test.ts +0 -131
- package/__tests__/pipeline/phases/orm.test.ts +0 -379
- package/__tests__/pipeline/phases/processes.test.ts +0 -191
- package/__tests__/pipeline/phases/routes.test.ts +0 -195
- package/__tests__/pipeline/phases/scope-resolution.test.ts +0 -133
- package/__tests__/pipeline/phases/tools.test.ts +0 -161
- package/__tests__/pipeline/phases/variables.test.ts +0 -30
- package/__tests__/pipeline/phases/wildcard-synthesis.test.ts +0 -207
- package/__tests__/pipeline/phases.test.ts +0 -41
- package/__tests__/pipeline/runner.test.ts +0 -28
- package/__tests__/registry/repo-registry.test.ts +0 -127
- package/__tests__/reporting/graph-report.suggest.test.ts +0 -36
- package/__tests__/reporting/graph-report.test.ts +0 -165
- package/__tests__/search/ast-chunker.test.ts +0 -63
- package/__tests__/search/rrf.test.ts +0 -95
- package/__tests__/security/safe-fetch.test.ts +0 -41
- package/__tests__/security/sensitive-files.test.ts +0 -32
- package/__tests__/setup.ts +0 -1
- package/__tests__/skills/platform-skills.test.ts +0 -63
- package/__tests__/staleness/git-staleness.test.ts +0 -107
- package/__tests__/storage/db.test.ts +0 -37
- package/__tests__/storage/evidence-roundtrip.test.ts +0 -89
- package/__tests__/storage/stores.test.ts +0 -165
- package/__tests__/types.test.ts +0 -13
- package/__tests__/validation/extraction-validator.test.ts +0 -48
- package/__tests__/watch/watcher.test.ts +0 -31
- package/__tests__/web/analyze-api.test.ts +0 -66
- package/__tests__/web/api.test.ts +0 -210
- package/__tests__/web/mcp-http.test.ts +0 -67
- package/__tests__/web/react-ui.test.ts +0 -43
- package/__tests__/wiki/gist-publisher.test.ts +0 -66
- package/__tests__/wiki/providers.test.ts +0 -69
- package/__tests__/wiki/wiki-generator.test.ts +0 -260
- package/dist/src/fix/deps.d.ts +0 -14
- package/dist/src/fix/deps.d.ts.map +0 -1
- package/dist/src/fix/deps.js +0 -47
- package/dist/src/fix/deps.js.map +0 -1
- package/dist/src/fix/enum-members.d.ts +0 -20
- package/dist/src/fix/enum-members.d.ts.map +0 -1
- package/dist/src/fix/enum-members.js +0 -95
- package/dist/src/fix/enum-members.js.map +0 -1
- package/dist/src/fix/export-surgery.d.ts +0 -14
- package/dist/src/fix/export-surgery.d.ts.map +0 -1
- package/dist/src/fix/export-surgery.js +0 -140
- package/dist/src/fix/export-surgery.js.map +0 -1
- package/dist/src/fix/exports.d.ts +0 -16
- package/dist/src/fix/exports.d.ts.map +0 -1
- package/dist/src/fix/exports.js +0 -65
- package/dist/src/fix/exports.js.map +0 -1
- package/dist/src/fix/orchestrator.d.ts +0 -28
- package/dist/src/fix/orchestrator.d.ts.map +0 -1
- package/dist/src/fix/orchestrator.js +0 -39
- package/dist/src/fix/orchestrator.js.map +0 -1
- package/src/__tests__/analysis/benchmark.test.ts +0 -59
- package/src/__tests__/analysis/cluster-quality.test.ts +0 -106
- package/src/__tests__/analysis/corpus-health.test.ts +0 -33
- package/src/__tests__/analysis/dependency-health.test.ts +0 -105
- package/src/__tests__/analysis/file-classifier.test.ts +0 -50
- package/src/__tests__/analysis/node-similarity.test.ts +0 -81
- package/src/__tests__/cache/augment-cache.test.ts +0 -55
- package/src/__tests__/cli/check-update.test.ts +0 -42
- package/src/__tests__/cli/hooks-install.test.ts +0 -56
- package/src/__tests__/cli/hooks-marker.test.ts +0 -138
- package/src/__tests__/cli/hooks-status.test.ts +0 -42
- package/src/__tests__/export/adjacency-matrix.test.ts +0 -116
- package/src/__tests__/export/csv.test.ts +0 -39
- package/src/__tests__/export/dot.test.ts +0 -86
- package/src/__tests__/export/gexf.test.ts +0 -78
- package/src/__tests__/export/graphml.test.ts +0 -57
- package/src/__tests__/export/mermaid.test.ts +0 -89
- package/src/__tests__/graph/betweenness.test.ts +0 -89
- package/src/__tests__/graph/cycles.test.ts +0 -131
- package/src/__tests__/graph/dead-code.test.ts +0 -174
- package/src/__tests__/graph/dfs.test.ts +0 -62
- package/src/__tests__/graph/diff-summary.test.ts +0 -83
- package/src/__tests__/graph/edge-filter.test.ts +0 -129
- package/src/__tests__/graph/import-chain.test.ts +0 -111
- package/src/__tests__/graph/merge.test.ts +0 -151
- package/src/__tests__/graph/node-search.test.ts +0 -167
- package/src/__tests__/graph/normalize-id.test.ts +0 -102
- package/src/__tests__/graph/pagerank.test.ts +0 -96
- package/src/__tests__/graph/prune.test.ts +0 -110
- package/src/__tests__/graph/regex-search.test.ts +0 -166
- package/src/__tests__/graph/ripple-impact.test.ts +0 -73
- package/src/__tests__/graph/scc.test.ts +0 -85
- package/src/__tests__/graph/statistics.test.ts +0 -219
- package/src/__tests__/graph/subgraph.test.ts +0 -127
- package/src/__tests__/graph/topo-sort.test.ts +0 -110
- package/src/__tests__/graph/wcc.test.ts +0 -101
- package/src/__tests__/groups/grpc-extractor.test.ts +0 -47
- package/src/__tests__/groups/service-boundary.test.ts +0 -86
- package/src/__tests__/groups/topic-extractor.test.ts +0 -43
- package/src/__tests__/ingest/git-clone.test.ts +0 -128
- package/src/__tests__/ingest/query-memory.test.ts +0 -123
- package/src/__tests__/ingest/transcribe.test.ts +0 -58
- package/src/__tests__/ingest/url-ingest.test.ts +0 -48
- package/src/__tests__/mcp-resources/repo-context-resource.test.ts +0 -37
- package/src/__tests__/mcp-resources/repos-resource.test.ts +0 -71
- package/src/__tests__/mcp-resources/wiki-resource.test.ts +0 -52
- package/src/__tests__/mcp-tools/explain.test.ts +0 -46
- package/src/__tests__/mcp-tools/graph-query.test.ts +0 -45
- package/src/__tests__/mcp-tools/group-sync.test.ts +0 -8
- package/src/__tests__/mcp-tools/impact-filtering.test.ts +0 -48
- package/src/__tests__/mcp-tools/impact.risk.test.ts +0 -24
- package/src/__tests__/mcp-tools/list-repos.test.ts +0 -24
- package/src/__tests__/mcp-tools/neighbors.test.ts +0 -48
- package/src/__tests__/mcp-tools/query.test.ts +0 -42
- package/src/__tests__/parsers/language-parsers.test.ts +0 -52
- package/src/__tests__/parsers/named-bindings.test.ts +0 -73
- package/src/__tests__/pipeline/cluster-only.test.ts +0 -33
- package/src/__tests__/pipeline/phases/bridge-adapters/electron-ipc.test.ts +0 -87
- package/src/__tests__/pipeline/phases/bridge-adapters/tauri.test.ts +0 -116
- package/src/__tests__/pipeline/phases/bridge-adapters/wails.test.ts +0 -81
- package/src/__tests__/pipeline/phases/bridge-resolver.test.ts +0 -110
- package/src/__tests__/pipeline/phases/communities.cohesion.test.ts +0 -43
- package/src/__tests__/pipeline/phases/community-split.test.ts +0 -30
- package/src/__tests__/pipeline/phases/framework-detect.test.ts +0 -65
- package/src/__tests__/pipeline/phases/import-resolver.test.ts +0 -64
- package/src/__tests__/pipeline/phases/parse-arrow.test.ts +0 -33
- package/src/__tests__/pipeline/phases/parse-csharp.test.ts +0 -33
- package/src/__tests__/pipeline/phases/scan.monographignore.test.ts +0 -53
- package/src/__tests__/pipeline/phases/scan.negation.test.ts +0 -40
- package/src/__tests__/pipeline/phases/scope-resolution.go.test.ts +0 -34
- package/src/__tests__/pipeline/phases/scope-resolution.java.test.ts +0 -30
- package/src/__tests__/pipeline/phases/scope-resolution.rust.test.ts +0 -31
- package/src/__tests__/pipeline/phases/suggest-questions.test.ts +0 -46
- package/src/__tests__/pipeline/phases/surprises-scoring.test.ts +0 -46
- package/src/__tests__/pipeline/phases/variables-phase.test.ts +0 -78
- package/src/__tests__/pipeline/phases/wildcard-phase.test.ts +0 -99
- package/src/__tests__/pipeline/runner.parallel.test.ts +0 -78
- package/src/__tests__/reporting/graph-report-confidence.test.ts +0 -43
- package/src/__tests__/reporting/graph-report-gaps.test.ts +0 -41
- package/src/__tests__/scope-resolution/call-sites.test.ts +0 -89
- package/src/__tests__/scope-resolution/evidence-weights.test.ts +0 -49
- package/src/__tests__/search/diacritic.test.ts +0 -23
- package/src/__tests__/security/safe-fetch.test.ts +0 -125
- package/src/__tests__/skills/platform-skills.extra.test.ts +0 -36
- package/src/__tests__/web/api.clusters.test.ts +0 -65
- package/src/__tests__/web/api.file.test.ts +0 -44
- package/src/__tests__/web/api.grep.test.ts +0 -47
- package/src/__tests__/web/api.info.test.ts +0 -18
- package/src/__tests__/web/api.jobs.test.ts +0 -47
- package/src/__tests__/web/api.progress.test.ts +0 -25
- package/src/__tests__/web/api.stream.test.ts +0 -35
- package/src/__tests__/wiki/providers-reasoning.test.ts +0 -46
- package/src/__tests__/wiki/wiki-review-mode.test.ts +0 -22
- package/src/analysis/benchmark.ts +0 -132
- package/src/analysis/changed-files.ts +0 -73
- package/src/analysis/changed-workspaces.ts +0 -94
- package/src/analysis/churn-cache.ts +0 -179
- package/src/analysis/churn-trend.ts +0 -57
- package/src/analysis/churn.ts +0 -263
- package/src/analysis/cluster-quality.ts +0 -142
- package/src/analysis/combined.ts +0 -41
- package/src/analysis/corpus-health.ts +0 -41
- package/src/analysis/coverage-gaps.ts +0 -246
- package/src/analysis/dep-classification.ts +0 -167
- package/src/analysis/dependency-health.ts +0 -146
- package/src/analysis/duplicate-exports.ts +0 -110
- package/src/analysis/fallow-suppression.ts +0 -98
- package/src/analysis/feature-flags-config.ts +0 -47
- package/src/analysis/feature-flags.ts +0 -223
- package/src/analysis/file-classifier.ts +0 -87
- package/src/analysis/git-changed-files.ts +0 -62
- package/src/analysis/health-baseline.ts +0 -80
- package/src/analysis/issue-filters.ts +0 -56
- package/src/analysis/list.ts +0 -74
- package/src/analysis/node-similarity.ts +0 -115
- package/src/analysis/private-type-leaks.ts +0 -119
- package/src/analysis/progress.ts +0 -43
- package/src/analysis/project-state.ts +0 -95
- package/src/analysis/regression-config.ts +0 -36
- package/src/analysis/rule-overrides.ts +0 -81
- package/src/analysis/scripts.ts +0 -95
- package/src/analysis/shape-extractor.ts +0 -202
- package/src/analysis/since-duration.ts +0 -42
- package/src/analysis/suppression-context.ts +0 -95
- package/src/analysis/suppressions.ts +0 -80
- package/src/analysis/surprise-scorer.ts +0 -74
- package/src/analysis/targets.ts +0 -237
- package/src/analysis/unused-class-members.ts +0 -79
- package/src/analysis/workspace-filter.ts +0 -89
- package/src/analyze/boundary-analysis.ts +0 -129
- package/src/analyze/predicates/file.ts +0 -86
- package/src/analyze/predicates/import.ts +0 -90
- package/src/analyze/predicates/lifecycle.ts +0 -55
- package/src/analyze/unused-deps.ts +0 -70
- package/src/analyze/unused-exports.ts +0 -145
- package/src/analyze/unused-files.ts +0 -46
- package/src/api/production-override.ts +0 -63
- package/src/api/programmatic.ts +0 -118
- package/src/audit.ts +0 -234
- package/src/cache/augment-cache.ts +0 -63
- package/src/cache/extraction-cache.ts +0 -141
- package/src/check/filtering.ts +0 -78
- package/src/check/index.ts +0 -99
- package/src/check/output.ts +0 -79
- package/src/check/rules.ts +0 -61
- package/src/ci-template.ts +0 -84
- package/src/claude-cli.ts +0 -59
- package/src/cli/ai-context.ts +0 -193
- package/src/cli/augment.ts +0 -114
- package/src/cli/check-update.ts +0 -40
- package/src/cli/doctor.ts +0 -182
- package/src/cli/eval-server.ts +0 -126
- package/src/cli/hooks-install.ts +0 -202
- package/src/cli/setup.ts +0 -197
- package/src/cli/skill-gen.ts +0 -347
- package/src/commands/flags.ts +0 -72
- package/src/config/boundary-config.ts +0 -183
- package/src/config/cli-schema.ts +0 -81
- package/src/config/config-parsing.ts +0 -102
- package/src/config/duplicates-config.ts +0 -62
- package/src/config/external-plugin.ts +0 -77
- package/src/config/health-config.ts +0 -42
- package/src/config/ignore-exports-used-in-file.ts +0 -46
- package/src/config/migration-types.ts +0 -73
- package/src/config/output-format.ts +0 -24
- package/src/config/plugins/builtin.ts +0 -411
- package/src/config/plugins/registry.ts +0 -77
- package/src/config/plugins/types.ts +0 -14
- package/src/config/resolution.ts +0 -102
- package/src/config/rules.ts +0 -70
- package/src/config/schema-gen.ts +0 -115
- package/src/config/types.ts +0 -149
- package/src/config/used-class-members.ts +0 -53
- package/src/config/validate.ts +0 -108
- package/src/config/workspace.ts +0 -137
- package/src/coverage/cloud-client.ts +0 -111
- package/src/coverage/upload-inventory.ts +0 -84
- package/src/coverage/upload-source-maps.ts +0 -97
- package/src/discover/entry-points.ts +0 -51
- package/src/discover/infrastructure-entries.ts +0 -175
- package/src/duplicates/detect/concatenation.ts +0 -37
- package/src/duplicates/detect/extraction.ts +0 -107
- package/src/duplicates/detect/filtering.ts +0 -112
- package/src/duplicates/detect/lcp.ts +0 -27
- package/src/duplicates/detect/ranking.ts +0 -16
- package/src/duplicates/detect/statistics.ts +0 -69
- package/src/duplicates/detect/suffix-array.ts +0 -88
- package/src/duplicates/families.ts +0 -95
- package/src/duplicates/normalize.ts +0 -58
- package/src/duplicates/shingle-filter.ts +0 -37
- package/src/duplicates/token-types.ts +0 -62
- package/src/duplicates/tokenize/index.ts +0 -104
- package/src/error/fallow-error.ts +0 -94
- package/src/error.ts +0 -47
- package/src/export/adjacency-matrix.ts +0 -127
- package/src/export/analysis-json.ts +0 -87
- package/src/export/badge.ts +0 -105
- package/src/export/canvas.ts +0 -42
- package/src/export/codeclimate.ts +0 -201
- package/src/export/compact-health.ts +0 -119
- package/src/export/compact.ts +0 -83
- package/src/export/csv.ts +0 -33
- package/src/export/cypher.ts +0 -33
- package/src/export/dot.ts +0 -52
- package/src/export/gexf.ts +0 -59
- package/src/export/graphml.ts +0 -50
- package/src/export/html.ts +0 -548
- package/src/export/index.ts +0 -9
- package/src/export/json.ts +0 -36
- package/src/export/markdown.ts +0 -290
- package/src/export/mermaid.ts +0 -100
- package/src/export/obsidian.ts +0 -44
- package/src/export/sarif.ts +0 -245
- package/src/export/svg.ts +0 -68
- package/src/fix/deps.ts +0 -70
- package/src/fix/enum-members.ts +0 -103
- package/src/fix/export-surgery.ts +0 -197
- package/src/fix/exports.ts +0 -93
- package/src/fix/orchestrator.ts +0 -67
- package/src/graph/analyzer.ts +0 -69
- package/src/graph/author-analytics.ts +0 -217
- package/src/graph/baseline.ts +0 -432
- package/src/graph/clone-families.ts +0 -132
- package/src/graph/codeowners-extended.ts +0 -114
- package/src/graph/codeowners-gitlab.ts +0 -150
- package/src/graph/codeowners.ts +0 -217
- package/src/graph/complexity.ts +0 -200
- package/src/graph/cross-reference-findings.ts +0 -85
- package/src/graph/cross-reference.ts +0 -139
- package/src/graph/cycle-detection.ts +0 -311
- package/src/graph/cycles.ts +0 -222
- package/src/graph/dead-code.ts +0 -128
- package/src/graph/dependency-closure.ts +0 -126
- package/src/graph/dfs.ts +0 -118
- package/src/graph/diff.ts +0 -92
- package/src/graph/duplication-stats.ts +0 -79
- package/src/graph/edge-filter.ts +0 -117
- package/src/graph/explain.ts +0 -133
- package/src/graph/external-style-usage.ts +0 -81
- package/src/graph/health-score.ts +0 -179
- package/src/graph/hotspots.ts +0 -219
- package/src/graph/import-chain.ts +0 -148
- package/src/graph/loader.ts +0 -44
- package/src/graph/maintainability.ts +0 -156
- package/src/graph/merge.ts +0 -174
- package/src/graph/mirrored-dirs.ts +0 -202
- package/src/graph/narrowing.ts +0 -92
- package/src/graph/node-search.ts +0 -201
- package/src/graph/node-types.ts +0 -67
- package/src/graph/normalize-id.ts +0 -138
- package/src/graph/pagerank.ts +0 -165
- package/src/graph/prune.ts +0 -95
- package/src/graph/re-exports/propagate.ts +0 -95
- package/src/graph/reachability.ts +0 -99
- package/src/graph/regex-search.ts +0 -232
- package/src/graph/regression.ts +0 -199
- package/src/graph/resolve/discover-types.ts +0 -45
- package/src/graph/resolve/dynamic-imports.ts +0 -102
- package/src/graph/resolve/fallbacks.ts +0 -79
- package/src/graph/resolve/index.ts +0 -68
- package/src/graph/resolve/path-info.ts +0 -41
- package/src/graph/resolve/re-exports.ts +0 -14
- package/src/graph/resolve/react-native.ts +0 -27
- package/src/graph/resolve/require-imports.ts +0 -18
- package/src/graph/resolve/specifier.ts +0 -120
- package/src/graph/resolve/static-imports.ts +0 -14
- package/src/graph/resolve/types.ts +0 -108
- package/src/graph/resolve/upgrades.ts +0 -32
- package/src/graph/ripple-impact.ts +0 -131
- package/src/graph/risk-profile.ts +0 -179
- package/src/graph/statistics.ts +0 -165
- package/src/graph/stats.ts +0 -157
- package/src/graph/subgraph.ts +0 -162
- package/src/graph/topo-sort.ts +0 -171
- package/src/graph/wcc.ts +0 -187
- package/src/groups/contract-bridge.ts +0 -103
- package/src/groups/contract-registry.ts +0 -263
- package/src/groups/group-config.ts +0 -108
- package/src/groups/group-search.ts +0 -139
- package/src/groups/group-sync.ts +0 -82
- package/src/groups/grpc-extractor.ts +0 -64
- package/src/groups/service-boundary.ts +0 -119
- package/src/groups/topic-extractor.ts +0 -90
- package/src/health/analysis-counts-snapshot.ts +0 -57
- package/src/health/analysis-counts.ts +0 -70
- package/src/health/complexity-findings.ts +0 -115
- package/src/health/distribution-thresholds.ts +0 -54
- package/src/health/grouping.ts +0 -138
- package/src/health/health-grouping.ts +0 -86
- package/src/health/health-report-types.ts +0 -165
- package/src/health/health-report.ts +0 -81
- package/src/health/health-score.ts +0 -65
- package/src/health/hotspot-utils.ts +0 -55
- package/src/health/hotspots.ts +0 -104
- package/src/health/large-functions.ts +0 -34
- package/src/health/ownership-metrics.ts +0 -61
- package/src/health/ownership-risk.ts +0 -98
- package/src/health/ownership.ts +0 -174
- package/src/health/quality-gate.ts +0 -57
- package/src/health/risk-profile.ts +0 -39
- package/src/health/runtime-coverage-report.ts +0 -101
- package/src/health/runtime-coverage.ts +0 -71
- package/src/health/scores.ts +0 -72
- package/src/health/scoring-types.ts +0 -48
- package/src/health/target-thresholds.ts +0 -92
- package/src/health/target-types.ts +0 -54
- package/src/health/targets.ts +0 -151
- package/src/health/timings.ts +0 -86
- package/src/health/trend-types.ts +0 -57
- package/src/health/trends.ts +0 -86
- package/src/health/vital-signs-compute.ts +0 -108
- package/src/health/vital-signs-snapshot.ts +0 -72
- package/src/health/vital-signs.ts +0 -101
- package/src/index.ts +0 -111
- package/src/ingest/git-clone.ts +0 -246
- package/src/ingest/query-memory.ts +0 -132
- package/src/ingest/transcribe.ts +0 -254
- package/src/ingest/url-ingest.ts +0 -87
- package/src/init/agent-hooks.ts +0 -86
- package/src/init/git-hooks.ts +0 -71
- package/src/init/project-detection.ts +0 -105
- package/src/license/manager.ts +0 -120
- package/src/lsp/code-actions.ts +0 -127
- package/src/lsp/code-lens.ts +0 -56
- package/src/lsp/diagnostics-ext.ts +0 -150
- package/src/lsp/diagnostics-push.ts +0 -103
- package/src/lsp/diagnostics.ts +0 -98
- package/src/lsp/hover.ts +0 -64
- package/src/lsp/server.ts +0 -254
- package/src/mcp/params.ts +0 -201
- package/src/mcp/resources.ts +0 -124
- package/src/mcp/tool-builders.ts +0 -203
- package/src/mcp-resources/communities-resource.ts +0 -72
- package/src/mcp-resources/graph-resource.ts +0 -14
- package/src/mcp-resources/index.ts +0 -9
- package/src/mcp-resources/named-cluster-resource.ts +0 -35
- package/src/mcp-resources/named-process-resource.ts +0 -26
- package/src/mcp-resources/processes-resource.ts +0 -67
- package/src/mcp-resources/repo-context-resource.ts +0 -36
- package/src/mcp-resources/repos-resource.ts +0 -21
- package/src/mcp-resources/schema-resource.ts +0 -46
- package/src/mcp-resources/wiki-resource.ts +0 -23
- package/src/mcp-tools/api-impact.ts +0 -181
- package/src/mcp-tools/context.ts +0 -111
- package/src/mcp-tools/cypher.ts +0 -29
- package/src/mcp-tools/detect-changes.ts +0 -116
- package/src/mcp-tools/explain.ts +0 -65
- package/src/mcp-tools/graph-query.ts +0 -128
- package/src/mcp-tools/group-list.ts +0 -88
- package/src/mcp-tools/group-query.ts +0 -26
- package/src/mcp-tools/group-sync.ts +0 -32
- package/src/mcp-tools/impact.ts +0 -202
- package/src/mcp-tools/index.ts +0 -21
- package/src/mcp-tools/list-repos.ts +0 -38
- package/src/mcp-tools/neighbors.ts +0 -80
- package/src/mcp-tools/query.ts +0 -86
- package/src/mcp-tools/rename.ts +0 -118
- package/src/mcp-tools/route-map.ts +0 -98
- package/src/mcp-tools/serve.ts +0 -41
- package/src/mcp-tools/shape-check.ts +0 -182
- package/src/mcp-tools/staleness.ts +0 -13
- package/src/mcp-tools/tool-map.ts +0 -66
- package/src/mcp-tools/wiki-build.ts +0 -37
- package/src/mcp-tools/wiki.ts +0 -28
- package/src/migrate/jscpd.ts +0 -78
- package/src/migrate/jsonc-gen.ts +0 -38
- package/src/migrate/knip.ts +0 -126
- package/src/migrate/toml-gen.ts +0 -48
- package/src/parsers/c.ts +0 -31
- package/src/parsers/cpp.ts +0 -29
- package/src/parsers/csharp.ts +0 -43
- package/src/parsers/dart.ts +0 -39
- package/src/parsers/extractor.ts +0 -202
- package/src/parsers/go.ts +0 -27
- package/src/parsers/java.ts +0 -27
- package/src/parsers/kotlin.ts +0 -36
- package/src/parsers/language-config.ts +0 -28
- package/src/parsers/language-parsers.ts +0 -120
- package/src/parsers/loader.ts +0 -149
- package/src/parsers/named-bindings.ts +0 -63
- package/src/parsers/php.ts +0 -37
- package/src/parsers/python.ts +0 -26
- package/src/parsers/ruby.ts +0 -39
- package/src/parsers/rust.ts +0 -25
- package/src/parsers/swift.ts +0 -28
- package/src/parsers/typescript.ts +0 -41
- package/src/parsers/vue.ts +0 -79
- package/src/pipeline/cluster-only.ts +0 -64
- package/src/pipeline/effort.ts +0 -50
- package/src/pipeline/orchestrator.ts +0 -384
- package/src/pipeline/phases/boundary.ts +0 -151
- package/src/pipeline/phases/bridge-adapters/electron-ipc.ts +0 -91
- package/src/pipeline/phases/bridge-adapters/registry.ts +0 -14
- package/src/pipeline/phases/bridge-adapters/tauri.ts +0 -103
- package/src/pipeline/phases/bridge-adapters/types.ts +0 -31
- package/src/pipeline/phases/bridge-adapters/wails.ts +0 -33
- package/src/pipeline/phases/bridge-resolver.ts +0 -77
- package/src/pipeline/phases/call-site-extractors.ts +0 -177
- package/src/pipeline/phases/communities.ts +0 -183
- package/src/pipeline/phases/contextual-proximity.ts +0 -88
- package/src/pipeline/phases/cross-file.ts +0 -116
- package/src/pipeline/phases/docs-parse.ts +0 -307
- package/src/pipeline/phases/evidence.ts +0 -9
- package/src/pipeline/phases/field-access.ts +0 -49
- package/src/pipeline/phases/framework-detect.ts +0 -109
- package/src/pipeline/phases/god-nodes.ts +0 -163
- package/src/pipeline/phases/import-resolver.ts +0 -114
- package/src/pipeline/phases/leiden.ts +0 -77
- package/src/pipeline/phases/llm-extract.ts +0 -178
- package/src/pipeline/phases/markdown.ts +0 -121
- package/src/pipeline/phases/middleware-extractor.ts +0 -127
- package/src/pipeline/phases/module-resolution.ts +0 -294
- package/src/pipeline/phases/mro.ts +0 -56
- package/src/pipeline/phases/orm.ts +0 -503
- package/src/pipeline/phases/parse.ts +0 -222
- package/src/pipeline/phases/pdf-parse.ts +0 -133
- package/src/pipeline/phases/processes.ts +0 -249
- package/src/pipeline/phases/re-export-propagation.ts +0 -160
- package/src/pipeline/phases/reachability.ts +0 -156
- package/src/pipeline/phases/routes.ts +0 -350
- package/src/pipeline/phases/scan.ts +0 -133
- package/src/pipeline/phases/scope-resolution.ts +0 -442
- package/src/pipeline/phases/structure.ts +0 -68
- package/src/pipeline/phases/suggest.ts +0 -92
- package/src/pipeline/phases/surprises.ts +0 -83
- package/src/pipeline/phases/tools.ts +0 -180
- package/src/pipeline/phases/variables-phase.ts +0 -37
- package/src/pipeline/phases/variables.ts +0 -67
- package/src/pipeline/phases/wildcard-phase.ts +0 -50
- package/src/pipeline/phases/wildcard-synthesis.ts +0 -214
- package/src/pipeline/progress.ts +0 -58
- package/src/pipeline/runner.ts +0 -88
- package/src/pipeline/types.ts +0 -41
- package/src/query/cypher-parser.ts +0 -450
- package/src/registry/repo-registry.ts +0 -125
- package/src/regression/baseline-deltas.ts +0 -215
- package/src/regression/baseline.ts +0 -76
- package/src/regression/counts.ts +0 -87
- package/src/regression/outcome.ts +0 -78
- package/src/regression/tolerance.ts +0 -35
- package/src/report/attributed-duplication.ts +0 -112
- package/src/report/badge-svg.ts +0 -100
- package/src/report/cross-ref-human.ts +0 -50
- package/src/report/duplication-grouping.ts +0 -74
- package/src/report/grouping.ts +0 -137
- package/src/report/human-check.ts +0 -291
- package/src/report/human-dupes.ts +0 -142
- package/src/report/human-health.ts +0 -195
- package/src/report/human.ts +0 -120
- package/src/report/json-actions.ts +0 -91
- package/src/report/json-builders.ts +0 -70
- package/src/report/json-schema.ts +0 -75
- package/src/report/number-format.ts +0 -91
- package/src/report/output-grouped.ts +0 -102
- package/src/report/pipeline-perf.ts +0 -56
- package/src/report/trace-human.ts +0 -127
- package/src/reporting/graph-report.ts +0 -431
- package/src/results/fallow-results.ts +0 -152
- package/src/results/types.ts +0 -149
- package/src/scope-resolution/evidence-weights.ts +0 -41
- package/src/search/ast-chunker.ts +0 -206
- package/src/search/diacritic.ts +0 -7
- package/src/search/hybrid-query.ts +0 -65
- package/src/search/rrf.ts +0 -51
- package/src/security/safe-fetch.ts +0 -113
- package/src/security/sensitive-files.ts +0 -24
- package/src/skills/platform-skills.ts +0 -233
- package/src/staleness/git-staleness.ts +0 -66
- package/src/storage/db.ts +0 -110
- package/src/storage/edge-store.ts +0 -103
- package/src/storage/file-cache.ts +0 -78
- package/src/storage/fts-store.ts +0 -385
- package/src/storage/node-store.ts +0 -209
- package/src/storage/schema.ts +0 -171
- package/src/storage/suppressions.ts +0 -145
- package/src/storage/unlinked-refs.ts +0 -117
- package/src/types.ts +0 -197
- package/src/validation/extraction-validator.ts +0 -54
- package/src/watch/watcher.ts +0 -160
- package/src/web/analyze-api.ts +0 -146
- package/src/web/api.ts +0 -584
- package/src/web/async-jobs.ts +0 -109
- package/src/web/mcp-http.ts +0 -227
- package/src/web/react-ui.ts +0 -78
- package/src/web/server.ts +0 -90
- package/src/web/ui/index.html +0 -204
- package/src/wiki/gist-publisher.ts +0 -76
- package/src/wiki/prompt-builder.ts +0 -35
- package/src/wiki/providers.ts +0 -134
- package/src/wiki/wiki-generator.ts +0 -223
- package/src/wiki/wiki-store.ts +0 -49
- package/tsconfig.json +0 -11
- package/vitest.config.ts +0 -20
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import type Database from 'better-sqlite3';
|
|
2
|
-
import type { MonographNode } from '../types.js';
|
|
3
|
-
|
|
4
|
-
// ── Row → MonographNode mapper ─────────────────────────────────────────────────
|
|
5
|
-
|
|
6
|
-
function rowToNode(row: Record<string, unknown>): MonographNode {
|
|
7
|
-
return {
|
|
8
|
-
id: row.id as string,
|
|
9
|
-
label: row.label as MonographNode['label'],
|
|
10
|
-
name: row.name as string,
|
|
11
|
-
normLabel: row.norm_label as string,
|
|
12
|
-
filePath: row.file_path as string | undefined,
|
|
13
|
-
startLine: row.start_line as number | undefined,
|
|
14
|
-
endLine: row.end_line as number | undefined,
|
|
15
|
-
communityId: row.community_id as number | undefined,
|
|
16
|
-
isExported: (row.is_exported as number) === 1,
|
|
17
|
-
language: row.language as string | undefined,
|
|
18
|
-
properties: row.properties ? JSON.parse(row.properties as string) : undefined,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// ── Output types ───────────────────────────────────────────────────────────────
|
|
23
|
-
|
|
24
|
-
export interface MonographApiImpactResult {
|
|
25
|
-
route: { method: string; path: string; nodeId: string } | null;
|
|
26
|
-
handler: MonographNode | null;
|
|
27
|
-
callees: Array<{ depth: number; node: MonographNode }>;
|
|
28
|
-
affectedProcesses: Array<{ id: string; name: string }>;
|
|
29
|
-
riskScore: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// ── Forward BFS on CALLS edges ─────────────────────────────────────────────────
|
|
33
|
-
|
|
34
|
-
function forwardBfs(
|
|
35
|
-
startId: string,
|
|
36
|
-
db: Database.Database,
|
|
37
|
-
maxDepth: number,
|
|
38
|
-
): Array<{ depth: number; nodeId: string }> {
|
|
39
|
-
const visited = new Map<string, number>([[startId, 0]]);
|
|
40
|
-
const queue: Array<{ id: string; depth: number }> = [{ id: startId, depth: 0 }];
|
|
41
|
-
const result: Array<{ depth: number; nodeId: string }> = [];
|
|
42
|
-
|
|
43
|
-
const stmt = db.prepare(
|
|
44
|
-
`SELECT target_id FROM edges WHERE source_id = ? AND relation = 'CALLS'`,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
while (queue.length > 0) {
|
|
48
|
-
const { id, depth } = queue.shift()!;
|
|
49
|
-
if (depth >= maxDepth) continue;
|
|
50
|
-
|
|
51
|
-
const callees = stmt.all(id) as Array<{ target_id: string }>;
|
|
52
|
-
for (const { target_id } of callees) {
|
|
53
|
-
if (!visited.has(target_id)) {
|
|
54
|
-
visited.set(target_id, depth + 1);
|
|
55
|
-
result.push({ depth: depth + 1, nodeId: target_id });
|
|
56
|
-
queue.push({ id: target_id, depth: depth + 1 });
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ── Implementation ─────────────────────────────────────────────────────────────
|
|
65
|
-
|
|
66
|
-
export function getMonographApiImpact(
|
|
67
|
-
db: Database.Database,
|
|
68
|
-
input: { routePath: string; method?: string },
|
|
69
|
-
): MonographApiImpactResult {
|
|
70
|
-
const MAX_DEPTH = 5;
|
|
71
|
-
|
|
72
|
-
// 1. Find the Route node matching routePath
|
|
73
|
-
const likePattern = '%' + input.routePath + '%';
|
|
74
|
-
let routeRows = db
|
|
75
|
-
.prepare("SELECT * FROM nodes WHERE label = 'Route' AND name LIKE ?")
|
|
76
|
-
.all(likePattern) as Record<string, unknown>[];
|
|
77
|
-
|
|
78
|
-
// If method provided, narrow down by method prefix
|
|
79
|
-
if (input.method && routeRows.length > 0) {
|
|
80
|
-
const methodUpper = input.method.toUpperCase();
|
|
81
|
-
const filtered = routeRows.filter((row) => {
|
|
82
|
-
const name = row.name as string;
|
|
83
|
-
return name.startsWith(methodUpper + ' ');
|
|
84
|
-
});
|
|
85
|
-
// Only apply filter if it returns results; otherwise keep all matches
|
|
86
|
-
if (filtered.length > 0) {
|
|
87
|
-
routeRows = filtered;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (routeRows.length === 0) {
|
|
92
|
-
return {
|
|
93
|
-
route: null,
|
|
94
|
-
handler: null,
|
|
95
|
-
callees: [],
|
|
96
|
-
affectedProcesses: [],
|
|
97
|
-
riskScore: 0,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const routeRow = routeRows[0];
|
|
102
|
-
const routeNodeId = routeRow.id as string;
|
|
103
|
-
const routeName = routeRow.name as string;
|
|
104
|
-
|
|
105
|
-
// Parse method and path from name (format: "METHOD /path")
|
|
106
|
-
const spaceIdx = routeName.indexOf(' ');
|
|
107
|
-
const method = spaceIdx >= 0 ? routeName.slice(0, spaceIdx) : 'ANY';
|
|
108
|
-
const path = spaceIdx >= 0 ? routeName.slice(spaceIdx + 1) : routeName;
|
|
109
|
-
|
|
110
|
-
const route = { method, path, nodeId: routeNodeId };
|
|
111
|
-
|
|
112
|
-
// 2. Find handler via HANDLES_ROUTE edge
|
|
113
|
-
const handlerRow = db
|
|
114
|
-
.prepare(
|
|
115
|
-
`SELECT n.* FROM nodes n
|
|
116
|
-
JOIN edges e ON n.id = e.target_id
|
|
117
|
-
WHERE e.source_id = ? AND e.relation = 'HANDLES_ROUTE'
|
|
118
|
-
LIMIT 1`,
|
|
119
|
-
)
|
|
120
|
-
.get(routeNodeId) as Record<string, unknown> | undefined;
|
|
121
|
-
|
|
122
|
-
const handler = handlerRow ? rowToNode(handlerRow) : null;
|
|
123
|
-
|
|
124
|
-
if (!handler) {
|
|
125
|
-
return {
|
|
126
|
-
route,
|
|
127
|
-
handler: null,
|
|
128
|
-
callees: [],
|
|
129
|
-
affectedProcesses: [],
|
|
130
|
-
riskScore: Math.log2(2),
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// 3. Forward BFS on CALLS edges from handler
|
|
135
|
-
const bfsResults = forwardBfs(handler.id, db, MAX_DEPTH);
|
|
136
|
-
|
|
137
|
-
// 4. Resolve node details for all callees in a single batch query (avoids N+1).
|
|
138
|
-
const callees: Array<{ depth: number; node: MonographNode }> = [];
|
|
139
|
-
if (bfsResults.length > 0) {
|
|
140
|
-
const calleeIds = bfsResults.map((b) => b.nodeId);
|
|
141
|
-
const depthByNodeId = new Map(bfsResults.map((b) => [b.nodeId, b.depth]));
|
|
142
|
-
const placeholders = calleeIds.map(() => '?').join(',');
|
|
143
|
-
const nodeRows = db
|
|
144
|
-
.prepare(`SELECT * FROM nodes WHERE id IN (${placeholders})`)
|
|
145
|
-
.all(...calleeIds) as Record<string, unknown>[];
|
|
146
|
-
for (const nodeRow of nodeRows) {
|
|
147
|
-
const nodeId = nodeRow.id as string;
|
|
148
|
-
const depth = depthByNodeId.get(nodeId) ?? 0;
|
|
149
|
-
callees.push({ depth, node: rowToNode(nodeRow) });
|
|
150
|
-
}
|
|
151
|
-
// Restore BFS order (sort by depth ascending)
|
|
152
|
-
callees.sort((a, b) => a.depth - b.depth);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// 5. Find processes that include the handler or any callee via STEP_IN_PROCESS
|
|
156
|
-
const allNodeIds = [handler.id, ...bfsResults.map((b) => b.nodeId)];
|
|
157
|
-
const affectedProcesses: Array<{ id: string; name: string }> = [];
|
|
158
|
-
|
|
159
|
-
if (allNodeIds.length > 0) {
|
|
160
|
-
const placeholders = allNodeIds.map(() => '?').join(',');
|
|
161
|
-
const processRows = db
|
|
162
|
-
.prepare(
|
|
163
|
-
`SELECT DISTINCT n.id, n.name FROM nodes n
|
|
164
|
-
JOIN edges e ON n.id = e.source_id
|
|
165
|
-
WHERE e.target_id IN (${placeholders}) AND e.relation = 'STEP_IN_PROCESS'`,
|
|
166
|
-
)
|
|
167
|
-
.all(...allNodeIds) as Array<{ id: string; name: string }>;
|
|
168
|
-
affectedProcesses.push(...processRows);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// 6. Risk score: log2(callees.length + 2) capped at 10
|
|
172
|
-
const riskScore = Math.min(Math.log2(callees.length + 2), 10);
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
route,
|
|
176
|
-
handler,
|
|
177
|
-
callees,
|
|
178
|
-
affectedProcesses,
|
|
179
|
-
riskScore,
|
|
180
|
-
};
|
|
181
|
-
}
|
package/src/mcp-tools/context.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import type Database from 'better-sqlite3';
|
|
2
|
-
import type { MonographNode } from '../types.js';
|
|
3
|
-
|
|
4
|
-
// ── Row → MonographNode mapper ─────────────────────────────────────────────────
|
|
5
|
-
|
|
6
|
-
function rowToNode(row: Record<string, unknown>): MonographNode {
|
|
7
|
-
return {
|
|
8
|
-
id: row.id as string,
|
|
9
|
-
label: row.label as MonographNode['label'],
|
|
10
|
-
name: row.name as string,
|
|
11
|
-
normLabel: row.norm_label as string,
|
|
12
|
-
filePath: row.file_path as string | undefined,
|
|
13
|
-
startLine: row.start_line as number | undefined,
|
|
14
|
-
endLine: row.end_line as number | undefined,
|
|
15
|
-
communityId: row.community_id as number | undefined,
|
|
16
|
-
isExported: (row.is_exported as number) === 1,
|
|
17
|
-
language: row.language as string | undefined,
|
|
18
|
-
properties: row.properties ? JSON.parse(row.properties as string) : undefined,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// ── Output type ────────────────────────────────────────────────────────────────
|
|
23
|
-
|
|
24
|
-
export interface MonographContextResult {
|
|
25
|
-
node: MonographNode | null;
|
|
26
|
-
callers: MonographNode[];
|
|
27
|
-
callees: MonographNode[];
|
|
28
|
-
imports: MonographNode[];
|
|
29
|
-
importedBy: MonographNode[];
|
|
30
|
-
community: { id: number; label?: string } | null;
|
|
31
|
-
inProcesses: Array<{ id: string; name: string }>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// ── Shared helper: query related nodes by edge relation and direction ──────────
|
|
35
|
-
|
|
36
|
-
function queryRelated(
|
|
37
|
-
db: Database.Database,
|
|
38
|
-
nodeId: string,
|
|
39
|
-
relation: string,
|
|
40
|
-
inbound: boolean,
|
|
41
|
-
limit = 50,
|
|
42
|
-
): MonographNode[] {
|
|
43
|
-
// inbound=true → this node is the target; source nodes are the result
|
|
44
|
-
// inbound=false → this node is the source; target nodes are the result
|
|
45
|
-
const [filterCol, joinCol] = inbound
|
|
46
|
-
? ['target_id', 'source_id']
|
|
47
|
-
: ['source_id', 'target_id'];
|
|
48
|
-
|
|
49
|
-
const rows = db
|
|
50
|
-
.prepare(
|
|
51
|
-
`SELECT n.* FROM nodes n JOIN edges e ON n.id = e.${joinCol}
|
|
52
|
-
WHERE e.${filterCol} = ? AND e.relation = ? LIMIT ?`,
|
|
53
|
-
)
|
|
54
|
-
.all(nodeId, relation, limit) as Record<string, unknown>[];
|
|
55
|
-
|
|
56
|
-
return rows.map(rowToNode);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// ── Implementation ─────────────────────────────────────────────────────────────
|
|
60
|
-
|
|
61
|
-
export function getMonographContext(
|
|
62
|
-
db: Database.Database,
|
|
63
|
-
input: { name: string; filePath?: string },
|
|
64
|
-
): MonographContextResult {
|
|
65
|
-
const LIMIT = 50;
|
|
66
|
-
|
|
67
|
-
// 1. Find the node
|
|
68
|
-
let nodeRow: Record<string, unknown> | undefined;
|
|
69
|
-
if (input.filePath) {
|
|
70
|
-
nodeRow = db
|
|
71
|
-
.prepare('SELECT * FROM nodes WHERE name = ? AND file_path = ? LIMIT 1')
|
|
72
|
-
.get(input.name, input.filePath) as Record<string, unknown> | undefined;
|
|
73
|
-
} else {
|
|
74
|
-
nodeRow = db
|
|
75
|
-
.prepare('SELECT * FROM nodes WHERE name = ? LIMIT 1')
|
|
76
|
-
.get(input.name) as Record<string, unknown> | undefined;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (!nodeRow) {
|
|
80
|
-
return { node: null, callers: [], callees: [], imports: [], importedBy: [], community: null, inProcesses: [] };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const node = rowToNode(nodeRow);
|
|
84
|
-
const nodeId = node.id;
|
|
85
|
-
|
|
86
|
-
// 2–5. Callers / callees / imports / importedBy via shared helper
|
|
87
|
-
const callers = queryRelated(db, nodeId, 'CALLS', true, LIMIT);
|
|
88
|
-
const callees = queryRelated(db, nodeId, 'CALLS', false, LIMIT);
|
|
89
|
-
const imports = queryRelated(db, nodeId, 'IMPORTS', false, LIMIT);
|
|
90
|
-
const importedBy = queryRelated(db, nodeId, 'IMPORTS', true, LIMIT);
|
|
91
|
-
|
|
92
|
-
// 6. Community: from node's community_id field
|
|
93
|
-
let community: { id: number; label?: string } | null = null;
|
|
94
|
-
if (node.communityId != null) {
|
|
95
|
-
const commRow = db
|
|
96
|
-
.prepare('SELECT id, label FROM communities WHERE id = ?')
|
|
97
|
-
.get(node.communityId) as { id: number; label?: string } | undefined;
|
|
98
|
-
community = commRow ?? { id: node.communityId };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// 7. inProcesses: processes that contain this node as a step
|
|
102
|
-
// STEP_IN_PROCESS edge goes: process → step_symbol
|
|
103
|
-
const processRows = db
|
|
104
|
-
.prepare(
|
|
105
|
-
`SELECT n.id, n.name FROM nodes n JOIN edges e ON n.id = e.source_id
|
|
106
|
-
WHERE e.target_id = ? AND e.relation = 'STEP_IN_PROCESS' LIMIT ?`,
|
|
107
|
-
)
|
|
108
|
-
.all(nodeId, LIMIT) as Array<{ id: string; name: string }>;
|
|
109
|
-
|
|
110
|
-
return { node, callers, callees, imports, importedBy, community, inProcesses: processRows };
|
|
111
|
-
}
|
package/src/mcp-tools/cypher.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type Database from 'better-sqlite3';
|
|
2
|
-
import { executeCypherQuery, formatCypherResult } from '../query/cypher-parser.js';
|
|
3
|
-
import type { CypherResult } from '../query/cypher-parser.js';
|
|
4
|
-
|
|
5
|
-
export type { CypherResult };
|
|
6
|
-
export { formatCypherResult };
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Execute a restricted read-only Cypher-style query against the Monograph graph.
|
|
10
|
-
*
|
|
11
|
-
* @param db - Open better-sqlite3 database handle
|
|
12
|
-
* @param query - Cypher MATCH query string
|
|
13
|
-
* @returns CypherResult with rows, queryTime, and optional error
|
|
14
|
-
*/
|
|
15
|
-
export function getMonographCypher(db: Database.Database, query: string): CypherResult {
|
|
16
|
-
return executeCypherQuery(db, query);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Execute a Cypher-style query and return structured text for LLM consumption.
|
|
21
|
-
* Rows with filePath + startLine fields are rendered as "file:line" navigation hints.
|
|
22
|
-
*
|
|
23
|
-
* @param db - Open better-sqlite3 database handle
|
|
24
|
-
* @param query - Cypher MATCH query string
|
|
25
|
-
* @returns Formatted string suitable for direct injection into LLM context
|
|
26
|
-
*/
|
|
27
|
-
export function getMonographCypherText(db: Database.Database, query: string): string {
|
|
28
|
-
return formatCypherResult(executeCypherQuery(db, query));
|
|
29
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'child_process';
|
|
2
|
-
import type Database from 'better-sqlite3';
|
|
3
|
-
import type { MonographNode } from '../types.js';
|
|
4
|
-
|
|
5
|
-
// ── Output type ────────────────────────────────────────────────────────────────
|
|
6
|
-
|
|
7
|
-
export interface MonographDetectChangesResult {
|
|
8
|
-
changedFiles: string[];
|
|
9
|
-
affectedSymbols: Array<{ name: string; filePath: string; label: string }>;
|
|
10
|
-
affectedProcesses: Array<{ id: string; name: string }>;
|
|
11
|
-
error?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// ── Implementation ─────────────────────────────────────────────────────────────
|
|
15
|
-
|
|
16
|
-
const MAX_FILES = 200; // cap on changed-file count to prevent unbounded IN clauses
|
|
17
|
-
const MAX_STDOUT = 1_048_576; // 1 MiB stdout cap for git output
|
|
18
|
-
|
|
19
|
-
export function detectMonographChanges(
|
|
20
|
-
db: Database.Database,
|
|
21
|
-
input: { baseBranch?: string; includeTests?: boolean },
|
|
22
|
-
repoPath: string,
|
|
23
|
-
): MonographDetectChangesResult {
|
|
24
|
-
const rawBranch = input.baseBranch ?? 'main';
|
|
25
|
-
// Reject branch names that could be shell-injected or path-traversed
|
|
26
|
-
if (!/^[a-zA-Z0-9][a-zA-Z0-9._\-/]*$/.test(rawBranch)) {
|
|
27
|
-
return { changedFiles: [], affectedSymbols: [], affectedProcesses: [], error: `Invalid branch name: ${rawBranch}` };
|
|
28
|
-
}
|
|
29
|
-
const baseBranch = rawBranch;
|
|
30
|
-
const includeTests = input.includeTests ?? true;
|
|
31
|
-
|
|
32
|
-
let changedFiles: string[];
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
// Use spawnSync with argument array to eliminate shell injection entirely
|
|
36
|
-
const result = spawnSync('git', ['diff', '--name-only', `${baseBranch}...HEAD`], {
|
|
37
|
-
cwd: repoPath,
|
|
38
|
-
encoding: 'utf-8',
|
|
39
|
-
maxBuffer: MAX_STDOUT,
|
|
40
|
-
});
|
|
41
|
-
if (result.error) throw result.error;
|
|
42
|
-
if (result.status !== 0) throw new Error(result.stderr ?? `git exited ${result.status}`);
|
|
43
|
-
const output = (result.stdout ?? '').slice(0, MAX_STDOUT).trim();
|
|
44
|
-
|
|
45
|
-
changedFiles = output
|
|
46
|
-
.split('\n')
|
|
47
|
-
.map(f => f.trim())
|
|
48
|
-
.filter(f => f.length > 0)
|
|
49
|
-
.slice(0, MAX_FILES); // cap to prevent unbounded IN clauses
|
|
50
|
-
} catch (err) {
|
|
51
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
52
|
-
return { changedFiles: [], affectedSymbols: [], affectedProcesses: [], error: message };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Filter out test files if requested
|
|
56
|
-
if (!includeTests) {
|
|
57
|
-
changedFiles = changedFiles.filter(f => !(/\.(test|spec)\./.test(f)));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (changedFiles.length === 0) {
|
|
61
|
-
return { changedFiles: [], affectedSymbols: [], affectedProcesses: [] };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Query DB for symbols in changed files (batch if needed)
|
|
65
|
-
let affectedSymbols: Array<{ name: string; filePath: string; label: string }> = [];
|
|
66
|
-
let affectedSymbolIds: string[] = [];
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
// Process in batches of 50 to keep SQLite IN clause size bounded
|
|
70
|
-
const BATCH = 50;
|
|
71
|
-
const allRows: Array<{ id: string; name: string; file_path: string; label: string }> = [];
|
|
72
|
-
for (let i = 0; i < changedFiles.length; i += BATCH) {
|
|
73
|
-
const batch = changedFiles.slice(i, i + BATCH);
|
|
74
|
-
const placeholders = batch.map(() => '?').join(',');
|
|
75
|
-
const rows = db
|
|
76
|
-
.prepare(`SELECT id, name, file_path, label FROM nodes WHERE file_path IN (${placeholders})`)
|
|
77
|
-
.all(...batch) as Array<{ id: string; name: string; file_path: string; label: string }>;
|
|
78
|
-
allRows.push(...rows);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
affectedSymbols = allRows.map(r => ({ name: r.name, filePath: r.file_path, label: r.label }));
|
|
82
|
-
affectedSymbolIds = allRows.map(r => r.id);
|
|
83
|
-
} catch (err) {
|
|
84
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
85
|
-
return { changedFiles, affectedSymbols: [], affectedProcesses: [], error: message };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Find processes that contain any of the affected symbols as steps
|
|
89
|
-
// STEP_IN_PROCESS: process → step_symbol
|
|
90
|
-
let affectedProcesses: Array<{ id: string; name: string }> = [];
|
|
91
|
-
|
|
92
|
-
if (affectedSymbolIds.length > 0) {
|
|
93
|
-
try {
|
|
94
|
-
// Also batch symbol IDs to keep IN clause bounded
|
|
95
|
-
const BATCH = 50;
|
|
96
|
-
const processSet = new Map<string, string>();
|
|
97
|
-
for (let i = 0; i < affectedSymbolIds.length; i += BATCH) {
|
|
98
|
-
const batch = affectedSymbolIds.slice(i, i + BATCH);
|
|
99
|
-
const placeholders = batch.map(() => '?').join(',');
|
|
100
|
-
const processRows = db
|
|
101
|
-
.prepare(
|
|
102
|
-
`SELECT DISTINCT n.id, n.name
|
|
103
|
-
FROM nodes n JOIN edges e ON n.id = e.source_id
|
|
104
|
-
WHERE e.relation = 'STEP_IN_PROCESS' AND e.target_id IN (${placeholders})`,
|
|
105
|
-
)
|
|
106
|
-
.all(...batch) as Array<{ id: string; name: string }>;
|
|
107
|
-
for (const row of processRows) processSet.set(row.id, row.name);
|
|
108
|
-
}
|
|
109
|
-
affectedProcesses = Array.from(processSet.entries()).map(([id, name]) => ({ id, name }));
|
|
110
|
-
} catch {
|
|
111
|
-
// Non-fatal: return what we have
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return { changedFiles, affectedSymbols, affectedProcesses };
|
|
116
|
-
}
|
package/src/mcp-tools/explain.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type Database from 'better-sqlite3';
|
|
2
|
-
import type { MonographNode } from '../types.js';
|
|
3
|
-
|
|
4
|
-
function rowToNode(row: Record<string, unknown>): MonographNode {
|
|
5
|
-
return {
|
|
6
|
-
id: row['id'] as string,
|
|
7
|
-
label: row['label'] as MonographNode['label'],
|
|
8
|
-
name: row['name'] as string,
|
|
9
|
-
normLabel: (row['norm_label'] as string) ?? '',
|
|
10
|
-
filePath: row['file_path'] as string | undefined,
|
|
11
|
-
startLine: row['start_line'] as number | undefined,
|
|
12
|
-
endLine: row['end_line'] as number | undefined,
|
|
13
|
-
communityId: row['community_id'] as number | undefined,
|
|
14
|
-
isExported: (row['is_exported'] as number) === 1,
|
|
15
|
-
language: row['language'] as string | undefined,
|
|
16
|
-
properties: row['properties'] ? JSON.parse(row['properties'] as string) : undefined,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ExplainResult {
|
|
21
|
-
node: MonographNode | null;
|
|
22
|
-
explanation: string | null;
|
|
23
|
-
connectionCount: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function explainNode(db: Database.Database, name: string): ExplainResult {
|
|
27
|
-
const nodeRow = db.prepare('SELECT * FROM nodes WHERE name = ? LIMIT 1').get(name) as Record<string, unknown> | undefined;
|
|
28
|
-
if (!nodeRow) return { node: null, explanation: null, connectionCount: 0 };
|
|
29
|
-
|
|
30
|
-
const node = rowToNode(nodeRow);
|
|
31
|
-
|
|
32
|
-
// Get outbound connections
|
|
33
|
-
const outRows = db.prepare(
|
|
34
|
-
`SELECT n.name, e.relation FROM nodes n JOIN edges e ON n.id = e.target_id WHERE e.source_id = ? LIMIT 10`
|
|
35
|
-
).all(node.id) as { name: string; relation: string }[];
|
|
36
|
-
|
|
37
|
-
// Get inbound connections
|
|
38
|
-
const inRows = db.prepare(
|
|
39
|
-
`SELECT n.name, e.relation FROM nodes n JOIN edges e ON n.id = e.source_id WHERE e.target_id = ? LIMIT 10`
|
|
40
|
-
).all(node.id) as { name: string; relation: string }[];
|
|
41
|
-
|
|
42
|
-
const connectionCount = outRows.length + inRows.length;
|
|
43
|
-
const fileRef = node.filePath
|
|
44
|
-
? (node.startLine != null ? `${node.filePath}:${node.startLine}` : node.filePath)
|
|
45
|
-
: null;
|
|
46
|
-
const fileLine = fileRef ? ` defined in \`${fileRef}\`` : '';
|
|
47
|
-
|
|
48
|
-
let explanation = `**${node.name}** is a ${node.label}${fileLine}.`;
|
|
49
|
-
|
|
50
|
-
if (outRows.length > 0) {
|
|
51
|
-
const outList = outRows.map(r => `\`${r.name}\` (${r.relation})`).join(', ');
|
|
52
|
-
explanation += ` It connects to: ${outList}.`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (inRows.length > 0) {
|
|
56
|
-
const inList = inRows.map(r => `\`${r.name}\``).slice(0, 5).join(', ');
|
|
57
|
-
explanation += ` Referenced by: ${inList}.`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (node.communityId != null) {
|
|
61
|
-
explanation += ` Part of community ${node.communityId}.`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return { node, explanation, connectionCount };
|
|
65
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type Database from 'better-sqlite3';
|
|
2
|
-
import type { MonographNode } from '../types.js';
|
|
3
|
-
|
|
4
|
-
function rowToNode(row: Record<string, unknown>): MonographNode {
|
|
5
|
-
return {
|
|
6
|
-
id: row['id'] as string,
|
|
7
|
-
label: row['label'] as MonographNode['label'],
|
|
8
|
-
name: row['name'] as string,
|
|
9
|
-
normLabel: (row['norm_label'] as string) ?? '',
|
|
10
|
-
filePath: row['file_path'] as string | undefined,
|
|
11
|
-
startLine: row['start_line'] as number | undefined,
|
|
12
|
-
endLine: row['end_line'] as number | undefined,
|
|
13
|
-
communityId: row['community_id'] as number | undefined,
|
|
14
|
-
isExported: (row['is_exported'] as number) === 1,
|
|
15
|
-
language: row['language'] as string | undefined,
|
|
16
|
-
properties: row['properties'] ? JSON.parse(row['properties'] as string) : undefined,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface GraphQueryInput {
|
|
21
|
-
query: string;
|
|
22
|
-
mode?: 'bfs' | 'dfs';
|
|
23
|
-
/** Direction of edge traversal. 'both' includes incoming edges (callers) and outgoing (callees). Default: 'out' */
|
|
24
|
-
direction?: 'out' | 'in' | 'both';
|
|
25
|
-
tokenBudget?: number;
|
|
26
|
-
depth?: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface GraphQueryResult {
|
|
30
|
-
nodes: MonographNode[];
|
|
31
|
-
mode: 'bfs' | 'dfs';
|
|
32
|
-
truncated: boolean;
|
|
33
|
-
tokenEstimate: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function estimateTokens(nodes: MonographNode[]): number {
|
|
37
|
-
return nodes.reduce((acc, n) => acc + n.name.length + (n.filePath?.length ?? 0) + 20, 0);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function queryGraph(
|
|
41
|
-
db: Database.Database,
|
|
42
|
-
input: GraphQueryInput,
|
|
43
|
-
): GraphQueryResult {
|
|
44
|
-
const mode = input.mode ?? 'bfs';
|
|
45
|
-
const direction = input.direction ?? 'out';
|
|
46
|
-
const tokenBudget = input.tokenBudget ?? 2000;
|
|
47
|
-
const maxDepth = input.depth ?? 3;
|
|
48
|
-
|
|
49
|
-
// Find seed nodes matching the query
|
|
50
|
-
const seedRows = db.prepare(
|
|
51
|
-
`SELECT * FROM nodes WHERE name LIKE ? OR label LIKE ? LIMIT 20`
|
|
52
|
-
).all(`%${input.query}%`, `%${input.query}%`) as Record<string, unknown>[];
|
|
53
|
-
|
|
54
|
-
const seeds = seedRows.map(rowToNode);
|
|
55
|
-
const visited = new Map<string, MonographNode>();
|
|
56
|
-
const result: MonographNode[] = [];
|
|
57
|
-
let tokenEstimate = 0;
|
|
58
|
-
let truncated = false;
|
|
59
|
-
|
|
60
|
-
for (const seed of seeds) {
|
|
61
|
-
visited.set(seed.id, seed);
|
|
62
|
-
result.push(seed);
|
|
63
|
-
tokenEstimate += estimateTokens([seed]);
|
|
64
|
-
if (tokenEstimate > tokenBudget) { truncated = true; break; }
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!truncated) {
|
|
68
|
-
// BFS or DFS expansion
|
|
69
|
-
const frontier: Array<{ id: string; depth: number }> = seeds.map(s => ({ id: s.id, depth: 0 }));
|
|
70
|
-
|
|
71
|
-
// Prepare edge traversal statements for each direction.
|
|
72
|
-
// 'out' follows outgoing edges (what this node calls/imports/uses).
|
|
73
|
-
// 'in' follows incoming edges (what calls/imports/uses this node).
|
|
74
|
-
// 'both' follows both directions — needed for full context (callers + callees).
|
|
75
|
-
const outEdgeStmt = db.prepare(
|
|
76
|
-
`SELECT n.* FROM nodes n JOIN edges e ON n.id = e.target_id WHERE e.source_id = ? LIMIT 20`
|
|
77
|
-
);
|
|
78
|
-
const inEdgeStmt = db.prepare(
|
|
79
|
-
`SELECT n.* FROM nodes n JOIN edges e ON n.id = e.source_id WHERE e.target_id = ? LIMIT 20`
|
|
80
|
-
);
|
|
81
|
-
const getNeighbors = (id: string): Record<string, unknown>[] => {
|
|
82
|
-
if (direction === 'out') return outEdgeStmt.all(id) as Record<string, unknown>[];
|
|
83
|
-
if (direction === 'in') return inEdgeStmt.all(id) as Record<string, unknown>[];
|
|
84
|
-
// 'both': union of outgoing and incoming, deduplicated by id
|
|
85
|
-
const outRows = outEdgeStmt.all(id) as Record<string, unknown>[];
|
|
86
|
-
const inRows = inEdgeStmt.all(id) as Record<string, unknown>[];
|
|
87
|
-
const seen = new Set(outRows.map(r => r['id'] as string));
|
|
88
|
-
return [...outRows, ...inRows.filter(r => !seen.has(r['id'] as string))];
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (mode === 'bfs') {
|
|
93
|
-
while (frontier.length > 0 && !truncated) {
|
|
94
|
-
const { id, depth } = frontier.shift()!;
|
|
95
|
-
if (depth >= maxDepth) continue;
|
|
96
|
-
const neighbors = getNeighbors(id);
|
|
97
|
-
for (const row of neighbors) {
|
|
98
|
-
const node = rowToNode(row);
|
|
99
|
-
if (visited.has(node.id)) continue;
|
|
100
|
-
visited.set(node.id, node);
|
|
101
|
-
result.push(node);
|
|
102
|
-
tokenEstimate += estimateTokens([node]);
|
|
103
|
-
if (tokenEstimate > tokenBudget) { truncated = true; break; }
|
|
104
|
-
frontier.push({ id: node.id, depth: depth + 1 });
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
// DFS: use stack
|
|
109
|
-
const stack = [...frontier].reverse();
|
|
110
|
-
while (stack.length > 0 && !truncated) {
|
|
111
|
-
const { id, depth } = stack.pop()!;
|
|
112
|
-
if (depth >= maxDepth) continue;
|
|
113
|
-
const neighbors = getNeighbors(id);
|
|
114
|
-
for (let i = neighbors.length - 1; i >= 0; i--) {
|
|
115
|
-
const node = rowToNode(neighbors[i]!);
|
|
116
|
-
if (visited.has(node.id)) continue;
|
|
117
|
-
visited.set(node.id, node);
|
|
118
|
-
result.push(node);
|
|
119
|
-
tokenEstimate += estimateTokens([node]);
|
|
120
|
-
if (tokenEstimate > tokenBudget) { truncated = true; break; }
|
|
121
|
-
stack.push({ id: node.id, depth: depth + 1 });
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return { nodes: result, mode, truncated, tokenEstimate };
|
|
128
|
-
}
|