@mycodemap/mycodemap 1.9.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +63 -978
- package/README.zh-CN.md +1096 -0
- package/dist/cli/commands/agent-metrics/human.d.ts +4 -0
- package/dist/cli/commands/agent-metrics/human.d.ts.map +1 -0
- package/dist/cli/commands/agent-metrics/human.js +134 -0
- package/dist/cli/commands/agent-metrics/human.js.map +1 -0
- package/dist/cli/commands/agent-metrics/index.d.ts +15 -0
- package/dist/cli/commands/agent-metrics/index.d.ts.map +1 -0
- package/dist/cli/commands/agent-metrics/index.js +116 -0
- package/dist/cli/commands/agent-metrics/index.js.map +1 -0
- package/dist/cli/commands/analyze-options.d.ts.map +1 -1
- package/dist/cli/commands/analyze-options.js +8 -0
- package/dist/cli/commands/analyze-options.js.map +1 -1
- package/dist/cli/commands/analyze.d.ts +3 -196
- package/dist/cli/commands/analyze.d.ts.map +1 -1
- package/dist/cli/commands/analyze.js +27 -1162
- package/dist/cli/commands/analyze.js.map +1 -1
- package/dist/cli/commands/benchmark.d.ts +8 -0
- package/dist/cli/commands/benchmark.d.ts.map +1 -0
- package/dist/cli/commands/benchmark.js +153 -0
- package/dist/cli/commands/benchmark.js.map +1 -0
- package/dist/cli/commands/complexity.d.ts.map +1 -1
- package/dist/cli/commands/complexity.js +62 -95
- package/dist/cli/commands/complexity.js.map +1 -1
- package/dist/cli/commands/deps.d.ts +3 -59
- package/dist/cli/commands/deps.d.ts.map +1 -1
- package/dist/cli/commands/deps.js +25 -331
- package/dist/cli/commands/deps.js.map +1 -1
- package/dist/cli/commands/doctor.d.ts +3 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +34 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/env-contract.d.ts +3 -0
- package/dist/cli/commands/env-contract.d.ts.map +1 -0
- package/dist/cli/commands/env-contract.js +221 -0
- package/dist/cli/commands/env-contract.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +19 -1
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +735 -89
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/impact.d.ts +4 -38
- package/dist/cli/commands/impact.d.ts.map +1 -1
- package/dist/cli/commands/impact.js +133 -375
- package/dist/cli/commands/impact.js.map +1 -1
- package/dist/cli/commands/init.d.ts +1 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +61 -2
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/preview.d.ts +3 -0
- package/dist/cli/commands/preview.d.ts.map +1 -0
- package/dist/cli/commands/preview.js +216 -0
- package/dist/cli/commands/preview.js.map +1 -0
- package/dist/cli/commands/query.d.ts +2 -20
- package/dist/cli/commands/query.d.ts.map +1 -1
- package/dist/cli/commands/query.js +23 -708
- package/dist/cli/commands/query.js.map +1 -1
- package/dist/cli/commands/watch-foreground.d.ts.map +1 -1
- package/dist/cli/commands/watch-foreground.js +5 -1
- package/dist/cli/commands/watch-foreground.js.map +1 -1
- package/dist/cli/config-loader.d.ts.map +1 -1
- package/dist/cli/config-loader.js +51 -13
- package/dist/cli/config-loader.js.map +1 -1
- package/dist/cli/doctor/check-agent.d.ts +3 -0
- package/dist/cli/doctor/check-agent.d.ts.map +1 -0
- package/dist/cli/doctor/check-agent.js +60 -0
- package/dist/cli/doctor/check-agent.js.map +1 -0
- package/dist/cli/doctor/check-env-contract.d.ts +3 -0
- package/dist/cli/doctor/check-env-contract.d.ts.map +1 -0
- package/dist/cli/doctor/check-env-contract.js +96 -0
- package/dist/cli/doctor/check-env-contract.js.map +1 -0
- package/dist/cli/doctor/check-ghost-commands.d.ts +3 -0
- package/dist/cli/doctor/check-ghost-commands.d.ts.map +1 -0
- package/dist/cli/doctor/check-ghost-commands.js +86 -0
- package/dist/cli/doctor/check-ghost-commands.js.map +1 -0
- package/dist/cli/doctor/check-native-deps.d.ts +3 -0
- package/dist/cli/doctor/check-native-deps.d.ts.map +1 -0
- package/dist/cli/doctor/check-native-deps.js +70 -0
- package/dist/cli/doctor/check-native-deps.js.map +1 -0
- package/dist/cli/doctor/check-workspace-drift.d.ts +3 -0
- package/dist/cli/doctor/check-workspace-drift.d.ts.map +1 -0
- package/dist/cli/doctor/check-workspace-drift.js +83 -0
- package/dist/cli/doctor/check-workspace-drift.js.map +1 -0
- package/dist/cli/doctor/formatter.d.ts +20 -0
- package/dist/cli/doctor/formatter.d.ts.map +1 -0
- package/dist/cli/doctor/formatter.js +91 -0
- package/dist/cli/doctor/formatter.js.map +1 -0
- package/dist/cli/doctor/index.d.ts +8 -0
- package/dist/cli/doctor/index.d.ts.map +1 -0
- package/dist/cli/doctor/index.js +9 -0
- package/dist/cli/doctor/index.js.map +1 -0
- package/dist/cli/doctor/orchestrator.d.ts +3 -0
- package/dist/cli/doctor/orchestrator.d.ts.map +1 -0
- package/dist/cli/doctor/orchestrator.js +40 -0
- package/dist/cli/doctor/orchestrator.js.map +1 -0
- package/dist/cli/doctor/types.d.ts +19 -0
- package/dist/cli/doctor/types.d.ts.map +1 -0
- package/dist/cli/doctor/types.js +4 -0
- package/dist/cli/doctor/types.js.map +1 -0
- package/dist/cli/env-contract/check.d.ts +18 -0
- package/dist/cli/env-contract/check.d.ts.map +1 -0
- package/dist/cli/env-contract/check.js +118 -0
- package/dist/cli/env-contract/check.js.map +1 -0
- package/dist/cli/env-contract/discovery.d.ts +12 -0
- package/dist/cli/env-contract/discovery.d.ts.map +1 -0
- package/dist/cli/env-contract/discovery.js +249 -0
- package/dist/cli/env-contract/discovery.js.map +1 -0
- package/dist/cli/env-contract/filters.d.ts +10 -0
- package/dist/cli/env-contract/filters.d.ts.map +1 -0
- package/dist/cli/env-contract/filters.js +23 -0
- package/dist/cli/env-contract/filters.js.map +1 -0
- package/dist/cli/env-contract/index.d.ts +6 -0
- package/dist/cli/env-contract/index.d.ts.map +1 -0
- package/dist/cli/env-contract/index.js +8 -0
- package/dist/cli/env-contract/index.js.map +1 -0
- package/dist/cli/env-contract/reminder-engine.d.ts +34 -0
- package/dist/cli/env-contract/reminder-engine.d.ts.map +1 -0
- package/dist/cli/env-contract/reminder-engine.js +51 -0
- package/dist/cli/env-contract/reminder-engine.js.map +1 -0
- package/dist/cli/env-contract/reminder-hook-runner.d.ts +45 -0
- package/dist/cli/env-contract/reminder-hook-runner.d.ts.map +1 -0
- package/dist/cli/env-contract/reminder-hook-runner.js +273 -0
- package/dist/cli/env-contract/reminder-hook-runner.js.map +1 -0
- package/dist/cli/env-contract/reminder-ledger.d.ts +11 -0
- package/dist/cli/env-contract/reminder-ledger.d.ts.map +1 -0
- package/dist/cli/env-contract/reminder-ledger.js +37 -0
- package/dist/cli/env-contract/reminder-ledger.js.map +1 -0
- package/dist/cli/env-contract/types.d.ts +48 -0
- package/dist/cli/env-contract/types.d.ts.map +1 -0
- package/dist/cli/env-contract/types.js +22 -0
- package/dist/cli/env-contract/types.js.map +1 -0
- package/dist/cli/env-contract/validation.d.ts +10 -0
- package/dist/cli/env-contract/validation.d.ts.map +1 -0
- package/dist/cli/env-contract/validation.js +116 -0
- package/dist/cli/env-contract/validation.js.map +1 -0
- package/dist/cli/first-run-guide.d.ts.map +1 -1
- package/dist/cli/first-run-guide.js +8 -3
- package/dist/cli/first-run-guide.js.map +1 -1
- package/dist/cli/index.js +94 -22
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init/assistant-plan.d.ts +14 -0
- package/dist/cli/init/assistant-plan.d.ts.map +1 -0
- package/dist/cli/init/assistant-plan.js +208 -0
- package/dist/cli/init/assistant-plan.js.map +1 -0
- package/dist/cli/init/detect.d.ts +28 -0
- package/dist/cli/init/detect.d.ts.map +1 -0
- package/dist/cli/init/detect.js +63 -0
- package/dist/cli/init/detect.js.map +1 -0
- package/dist/cli/init/env-contract-plan.d.ts +28 -0
- package/dist/cli/init/env-contract-plan.d.ts.map +1 -0
- package/dist/cli/init/env-contract-plan.js +184 -0
- package/dist/cli/init/env-contract-plan.js.map +1 -0
- package/dist/cli/init/manifest-extractors.d.ts +22 -0
- package/dist/cli/init/manifest-extractors.d.ts.map +1 -0
- package/dist/cli/init/manifest-extractors.js +185 -0
- package/dist/cli/init/manifest-extractors.js.map +1 -0
- package/dist/cli/init/profile-loader.d.ts +49 -0
- package/dist/cli/init/profile-loader.d.ts.map +1 -0
- package/dist/cli/init/profile-loader.js +107 -0
- package/dist/cli/init/profile-loader.js.map +1 -0
- package/dist/cli/init/profile-plan.d.ts +38 -0
- package/dist/cli/init/profile-plan.d.ts.map +1 -0
- package/dist/cli/init/profile-plan.js +120 -0
- package/dist/cli/init/profile-plan.js.map +1 -0
- package/dist/cli/init/profiles/generic.json +16 -0
- package/dist/cli/init/profiles/go.json +12 -0
- package/dist/cli/init/profiles/nodejs.json +16 -0
- package/dist/cli/init/profiles/python.json +17 -0
- package/dist/cli/init/profiles/rust.json +12 -0
- package/dist/cli/init/receipt.d.ts.map +1 -1
- package/dist/cli/init/receipt.js +107 -7
- package/dist/cli/init/receipt.js.map +1 -1
- package/dist/cli/init/reconciler.d.ts +10 -1
- package/dist/cli/init/reconciler.d.ts.map +1 -1
- package/dist/cli/init/reconciler.js +85 -15
- package/dist/cli/init/reconciler.js.map +1 -1
- package/dist/cli/interface-contract/commands/agent-metrics.d.ts +3 -0
- package/dist/cli/interface-contract/commands/agent-metrics.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/agent-metrics.js +217 -0
- package/dist/cli/interface-contract/commands/agent-metrics.js.map +1 -0
- package/dist/cli/interface-contract/commands/analyze.d.ts +3 -0
- package/dist/cli/interface-contract/commands/analyze.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/analyze.js +139 -0
- package/dist/cli/interface-contract/commands/analyze.js.map +1 -0
- package/dist/cli/interface-contract/commands/benchmark.d.ts +3 -0
- package/dist/cli/interface-contract/commands/benchmark.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/benchmark.js +108 -0
- package/dist/cli/interface-contract/commands/benchmark.js.map +1 -0
- package/dist/cli/interface-contract/commands/deps.d.ts +3 -0
- package/dist/cli/interface-contract/commands/deps.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/deps.js +130 -0
- package/dist/cli/interface-contract/commands/deps.js.map +1 -0
- package/dist/cli/interface-contract/commands/doctor.d.ts +3 -0
- package/dist/cli/interface-contract/commands/doctor.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/doctor.js +60 -0
- package/dist/cli/interface-contract/commands/doctor.js.map +1 -0
- package/dist/cli/interface-contract/commands/env-contract.d.ts +3 -0
- package/dist/cli/interface-contract/commands/env-contract.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/env-contract.js +168 -0
- package/dist/cli/interface-contract/commands/env-contract.js.map +1 -0
- package/dist/cli/interface-contract/commands/index.d.ts +12 -0
- package/dist/cli/interface-contract/commands/index.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/index.js +24 -0
- package/dist/cli/interface-contract/commands/index.js.map +1 -0
- package/dist/cli/interface-contract/commands/init.d.ts +3 -0
- package/dist/cli/interface-contract/commands/init.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/init.js +96 -0
- package/dist/cli/interface-contract/commands/init.js.map +1 -0
- package/dist/cli/interface-contract/commands/preview.d.ts +3 -0
- package/dist/cli/interface-contract/commands/preview.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/preview.js +118 -0
- package/dist/cli/interface-contract/commands/preview.js.map +1 -0
- package/dist/cli/interface-contract/commands/query.d.ts +3 -0
- package/dist/cli/interface-contract/commands/query.d.ts.map +1 -0
- package/dist/cli/interface-contract/commands/query.js +186 -0
- package/dist/cli/interface-contract/commands/query.js.map +1 -0
- package/dist/cli/interface-contract/index.d.ts +22 -0
- package/dist/cli/interface-contract/index.d.ts.map +1 -0
- package/dist/cli/interface-contract/index.js +41 -0
- package/dist/cli/interface-contract/index.js.map +1 -0
- package/dist/cli/interface-contract/schema.d.ts +30 -0
- package/dist/cli/interface-contract/schema.d.ts.map +1 -0
- package/dist/cli/interface-contract/schema.js +73 -0
- package/dist/cli/interface-contract/schema.js.map +1 -0
- package/dist/cli/interface-contract/types.d.ts +77 -0
- package/dist/cli/interface-contract/types.d.ts.map +1 -0
- package/dist/cli/interface-contract/types.js +4 -0
- package/dist/cli/interface-contract/types.js.map +1 -0
- package/dist/cli/output/apply-suggestion.d.ts +12 -0
- package/dist/cli/output/apply-suggestion.d.ts.map +1 -0
- package/dist/cli/output/apply-suggestion.js +29 -0
- package/dist/cli/output/apply-suggestion.js.map +1 -0
- package/dist/cli/output/error-codes.d.ts +24 -0
- package/dist/cli/output/error-codes.d.ts.map +1 -0
- package/dist/cli/output/error-codes.js +94 -0
- package/dist/cli/output/error-codes.js.map +1 -0
- package/dist/cli/output/errors.d.ts +14 -0
- package/dist/cli/output/errors.d.ts.map +1 -0
- package/dist/cli/output/errors.js +182 -0
- package/dist/cli/output/errors.js.map +1 -0
- package/dist/cli/output/index.d.ts +13 -0
- package/dist/cli/output/index.d.ts.map +1 -0
- package/dist/cli/output/index.js +11 -0
- package/dist/cli/output/index.js.map +1 -0
- package/dist/cli/output/mode.d.ts +12 -0
- package/dist/cli/output/mode.d.ts.map +1 -0
- package/dist/cli/output/mode.js +23 -0
- package/dist/cli/output/mode.js.map +1 -0
- package/dist/cli/output/progress.d.ts +9 -0
- package/dist/cli/output/progress.d.ts.map +1 -0
- package/dist/cli/output/progress.js +65 -0
- package/dist/cli/output/progress.js.map +1 -0
- package/dist/cli/output/render.d.ts +11 -0
- package/dist/cli/output/render.d.ts.map +1 -0
- package/dist/cli/output/render.js +18 -0
- package/dist/cli/output/render.js.map +1 -0
- package/dist/cli/output/types.d.ts +53 -0
- package/dist/cli/output/types.d.ts.map +1 -0
- package/dist/cli/output/types.js +14 -0
- package/dist/cli/output/types.js.map +1 -0
- package/dist/cli/output/wasm-fallback.d.ts +14 -0
- package/dist/cli/output/wasm-fallback.d.ts.map +1 -0
- package/dist/cli/output/wasm-fallback.js +92 -0
- package/dist/cli/output/wasm-fallback.js.map +1 -0
- package/dist/cli/preview/complexity-scanner.d.ts +21 -0
- package/dist/cli/preview/complexity-scanner.d.ts.map +1 -0
- package/dist/cli/preview/complexity-scanner.js +52 -0
- package/dist/cli/preview/complexity-scanner.js.map +1 -0
- package/dist/cli/preview/dependency-extractor.d.ts +38 -0
- package/dist/cli/preview/dependency-extractor.d.ts.map +1 -0
- package/dist/cli/preview/dependency-extractor.js +140 -0
- package/dist/cli/preview/dependency-extractor.js.map +1 -0
- package/dist/cli/preview/preview-renderer.d.ts +32 -0
- package/dist/cli/preview/preview-renderer.d.ts.map +1 -0
- package/dist/cli/preview/preview-renderer.js +54 -0
- package/dist/cli/preview/preview-renderer.js.map +1 -0
- package/dist/cli/storage-runtime.d.ts +7 -0
- package/dist/cli/storage-runtime.d.ts.map +1 -1
- package/dist/cli/storage-runtime.js +22 -0
- package/dist/cli/storage-runtime.js.map +1 -1
- package/dist/cli/tree-sitter-check.d.ts +6 -1
- package/dist/cli/tree-sitter-check.d.ts.map +1 -1
- package/dist/cli/tree-sitter-check.js +23 -1
- package/dist/cli/tree-sitter-check.js.map +1 -1
- package/dist/cli-new/index.js +1 -1
- package/dist/cli-new/index.js.map +1 -1
- package/dist/composition/parser-composition.d.ts +7 -0
- package/dist/composition/parser-composition.d.ts.map +1 -0
- package/dist/composition/parser-composition.js +15 -0
- package/dist/composition/parser-composition.js.map +1 -0
- package/dist/core/analyzer.d.ts.map +1 -1
- package/dist/core/analyzer.js +83 -67
- package/dist/core/analyzer.js.map +1 -1
- package/dist/core/ast-complexity-analyzer.d.ts +12 -6
- package/dist/core/ast-complexity-analyzer.d.ts.map +1 -1
- package/dist/core/ast-complexity-analyzer.js +368 -209
- package/dist/core/ast-complexity-analyzer.js.map +1 -1
- package/dist/core/file-discovery.d.ts +1 -1
- package/dist/core/file-discovery.d.ts.map +1 -1
- package/dist/core/file-discovery.js +3 -0
- package/dist/core/file-discovery.js.map +1 -1
- package/dist/core/global-index.d.ts +3 -1
- package/dist/core/global-index.d.ts.map +1 -1
- package/dist/core/global-index.js +69 -4
- package/dist/core/global-index.js.map +1 -1
- package/dist/domain/entities/CodeGraph.d.ts +3 -0
- package/dist/domain/entities/CodeGraph.d.ts.map +1 -1
- package/dist/domain/entities/CodeGraph.js +19 -2
- package/dist/domain/entities/CodeGraph.js.map +1 -1
- package/dist/domain/entities/Dependency.d.ts +5 -2
- package/dist/domain/entities/Dependency.d.ts.map +1 -1
- package/dist/domain/entities/Dependency.js +49 -3
- package/dist/domain/entities/Dependency.js.map +1 -1
- package/dist/domain/repositories/CodeGraphRepository.d.ts +5 -0
- package/dist/domain/repositories/CodeGraphRepository.d.ts.map +1 -1
- package/dist/domain/repositories/CodeGraphRepository.js.map +1 -1
- package/dist/execution/contract-tools/analyze.d.ts +205 -0
- package/dist/execution/contract-tools/analyze.d.ts.map +1 -0
- package/dist/execution/contract-tools/analyze.js +1215 -0
- package/dist/execution/contract-tools/analyze.js.map +1 -0
- package/dist/execution/contract-tools/deps.d.ts +62 -0
- package/dist/execution/contract-tools/deps.d.ts.map +1 -0
- package/dist/execution/contract-tools/deps.js +234 -0
- package/dist/execution/contract-tools/deps.js.map +1 -0
- package/dist/execution/contract-tools/index.d.ts +5 -0
- package/dist/execution/contract-tools/index.d.ts.map +1 -0
- package/dist/execution/contract-tools/index.js +7 -0
- package/dist/execution/contract-tools/index.js.map +1 -0
- package/dist/execution/contract-tools/query.d.ts +60 -0
- package/dist/execution/contract-tools/query.d.ts.map +1 -0
- package/dist/execution/contract-tools/query.js +532 -0
- package/dist/execution/contract-tools/query.js.map +1 -0
- package/dist/execution/contract-tools/types.d.ts +26 -0
- package/dist/execution/contract-tools/types.d.ts.map +1 -0
- package/dist/execution/contract-tools/types.js +32 -0
- package/dist/execution/contract-tools/types.js.map +1 -0
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +0 -3
- package/dist/generator/index.js.map +1 -1
- package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.d.ts +12 -0
- package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.d.ts.map +1 -0
- package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.js +55 -0
- package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.js.map +1 -0
- package/dist/infrastructure/parser/implementations/GoParser.d.ts +2 -1
- package/dist/infrastructure/parser/implementations/GoParser.d.ts.map +1 -1
- package/dist/infrastructure/parser/implementations/GoParser.js +13 -1
- package/dist/infrastructure/parser/implementations/GoParser.js.map +1 -1
- package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.d.ts +114 -0
- package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.d.ts.map +1 -0
- package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.js +1022 -0
- package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.js.map +1 -0
- package/dist/infrastructure/parser/implementations/TreeSitterParser.d.ts +78 -0
- package/dist/infrastructure/parser/implementations/TreeSitterParser.d.ts.map +1 -0
- package/dist/infrastructure/parser/implementations/TreeSitterParser.js +648 -0
- package/dist/infrastructure/parser/implementations/TreeSitterParser.js.map +1 -0
- package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts +3 -55
- package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts.map +1 -1
- package/dist/infrastructure/parser/implementations/TypeScriptParser.js +4 -411
- package/dist/infrastructure/parser/implementations/TypeScriptParser.js.map +1 -1
- package/dist/infrastructure/parser/index.d.ts +2 -0
- package/dist/infrastructure/parser/index.d.ts.map +1 -1
- package/dist/infrastructure/parser/index.js +9 -6
- package/dist/infrastructure/parser/index.js.map +1 -1
- package/dist/infrastructure/parser/interfaces/ParserBase.d.ts.map +1 -1
- package/dist/infrastructure/parser/interfaces/ParserBase.js +1 -0
- package/dist/infrastructure/parser/interfaces/ParserBase.js.map +1 -1
- package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts +2 -0
- package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts.map +1 -1
- package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js +4 -0
- package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js.map +1 -1
- package/dist/infrastructure/storage/StorageFactory.d.ts +5 -18
- package/dist/infrastructure/storage/StorageFactory.d.ts.map +1 -1
- package/dist/infrastructure/storage/StorageFactory.js +30 -98
- package/dist/infrastructure/storage/StorageFactory.js.map +1 -1
- package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts +13 -1
- package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/SQLiteStorage.js +322 -76
- package/dist/infrastructure/storage/adapters/SQLiteStorage.js.map +1 -1
- package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts +45 -0
- package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts.map +1 -0
- package/dist/infrastructure/storage/adapters/sqlite-loader.js +266 -0
- package/dist/infrastructure/storage/adapters/sqlite-loader.js.map +1 -0
- package/dist/infrastructure/storage/community-helpers.d.ts +4 -0
- package/dist/infrastructure/storage/community-helpers.d.ts.map +1 -0
- package/dist/infrastructure/storage/community-helpers.js +392 -0
- package/dist/infrastructure/storage/community-helpers.js.map +1 -0
- package/dist/infrastructure/storage/graph-helpers.d.ts +22 -5
- package/dist/infrastructure/storage/graph-helpers.d.ts.map +1 -1
- package/dist/infrastructure/storage/graph-helpers.js +496 -91
- package/dist/infrastructure/storage/graph-helpers.js.map +1 -1
- package/dist/infrastructure/storage/index.d.ts +1 -1
- package/dist/infrastructure/storage/index.d.ts.map +1 -1
- package/dist/infrastructure/storage/index.js +1 -1
- package/dist/infrastructure/storage/index.js.map +1 -1
- package/dist/infrastructure/storage/interfaces/StorageBase.d.ts +2 -2
- package/dist/infrastructure/storage/interfaces/StorageBase.d.ts.map +1 -1
- package/dist/infrastructure/storage/interfaces/StorageBase.js.map +1 -1
- package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts +2 -0
- package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts.map +1 -1
- package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js +52 -12
- package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js.map +1 -1
- package/dist/infrastructure/storage/sqlite/schema.d.ts +2 -2
- package/dist/infrastructure/storage/sqlite/schema.d.ts.map +1 -1
- package/dist/infrastructure/storage/sqlite/schema.js +49 -1
- package/dist/infrastructure/storage/sqlite/schema.js.map +1 -1
- package/dist/interface/config/index.d.ts +5 -3
- package/dist/interface/config/index.d.ts.map +1 -1
- package/dist/interface/types/index.d.ts +37 -6
- package/dist/interface/types/index.d.ts.map +1 -1
- package/dist/interface/types/parser.d.ts +85 -0
- package/dist/interface/types/parser.d.ts.map +1 -1
- package/dist/interface/types/storage.d.ts +227 -10
- package/dist/interface/types/storage.d.ts.map +1 -1
- package/dist/orchestrator/agent-metrics-service.d.ts +126 -0
- package/dist/orchestrator/agent-metrics-service.d.ts.map +1 -0
- package/dist/orchestrator/agent-metrics-service.js +444 -0
- package/dist/orchestrator/agent-metrics-service.js.map +1 -0
- package/dist/orchestrator/types.d.ts +2 -0
- package/dist/orchestrator/types.d.ts.map +1 -1
- package/dist/orchestrator/types.js.map +1 -1
- package/dist/parser/enhancers/PythonTypeEnhancer.d.ts +26 -0
- package/dist/parser/enhancers/PythonTypeEnhancer.d.ts.map +1 -0
- package/dist/parser/enhancers/PythonTypeEnhancer.js +440 -0
- package/dist/parser/enhancers/PythonTypeEnhancer.js.map +1 -0
- package/dist/parser/implementations/smart-parser.d.ts.map +1 -1
- package/dist/parser/implementations/smart-parser.js +7 -69
- package/dist/parser/implementations/smart-parser.js.map +1 -1
- package/dist/parser/implementations/tree-sitter-loader.d.ts +18 -0
- package/dist/parser/implementations/tree-sitter-loader.d.ts.map +1 -0
- package/dist/parser/implementations/tree-sitter-loader.js +136 -0
- package/dist/parser/implementations/tree-sitter-loader.js.map +1 -0
- package/dist/parser/index.d.ts +5 -3
- package/dist/parser/index.d.ts.map +1 -1
- package/dist/parser/index.js +68 -6
- package/dist/parser/index.js.map +1 -1
- package/dist/parser/interfaces/IParser.d.ts +19 -6
- package/dist/parser/interfaces/IParser.d.ts.map +1 -1
- package/dist/parser/interfaces/IParser.js +2 -3
- package/dist/parser/interfaces/IParser.js.map +1 -1
- package/dist/server/handlers/AnalysisHandler.d.ts +13 -2
- package/dist/server/handlers/AnalysisHandler.d.ts.map +1 -1
- package/dist/server/handlers/AnalysisHandler.js +24 -0
- package/dist/server/handlers/AnalysisHandler.js.map +1 -1
- package/dist/server/handlers/QueryHandler.d.ts.map +1 -1
- package/dist/server/handlers/QueryHandler.js +11 -30
- package/dist/server/handlers/QueryHandler.js.map +1 -1
- package/dist/server/mcp/context-tool.d.ts +9 -0
- package/dist/server/mcp/context-tool.d.ts.map +1 -0
- package/dist/server/mcp/context-tool.js +257 -0
- package/dist/server/mcp/context-tool.js.map +1 -0
- package/dist/server/mcp/schema-adapter.d.ts +55 -0
- package/dist/server/mcp/schema-adapter.d.ts.map +1 -0
- package/dist/server/mcp/schema-adapter.js +409 -0
- package/dist/server/mcp/schema-adapter.js.map +1 -0
- package/dist/server/mcp/server.d.ts +3 -3
- package/dist/server/mcp/server.d.ts.map +1 -1
- package/dist/server/mcp/server.js +134 -20
- package/dist/server/mcp/server.js.map +1 -1
- package/dist/server/mcp/service.d.ts +6 -2
- package/dist/server/mcp/service.d.ts.map +1 -1
- package/dist/server/mcp/service.js +138 -36
- package/dist/server/mcp/service.js.map +1 -1
- package/dist/server/mcp/stdio-transport.d.ts +23 -0
- package/dist/server/mcp/stdio-transport.d.ts.map +1 -0
- package/dist/server/mcp/stdio-transport.js +101 -0
- package/dist/server/mcp/stdio-transport.js.map +1 -0
- package/dist/server/mcp/types.d.ts +133 -8
- package/dist/server/mcp/types.d.ts.map +1 -1
- package/dist/server/routes/api.d.ts.map +1 -1
- package/dist/server/routes/api.js +11 -2
- package/dist/server/routes/api.js.map +1 -1
- package/docs/AI_ASSISTANT_SETUP.md +281 -12
- package/docs/API.md +170 -0
- package/docs/CONFIGURATION.md +141 -0
- package/docs/DEVELOPMENT.md +96 -0
- package/docs/GETTING-STARTED.md +114 -0
- package/docs/README.md +40 -1
- package/docs/SETUP_GUIDE.md +60 -14
- package/docs/TESTING.md +81 -0
- package/docs/ai-guide/COMMANDS.md +68 -10
- package/docs/ai-guide/INTEGRATION.md +77 -10
- package/docs/ai-guide/OUTPUT.md +345 -9
- package/docs/ai-guide/PROMPTS.md +2 -2
- package/docs/ai-guide/QUICKSTART.md +28 -1
- package/docs/ai-guide/README.md +2 -2
- package/docs/archive/ideation/2026-04-15-executable-architecture-constitution-ideation-archive.md +70 -0
- package/docs/archive/ideation/2026-04-20-mycodemap-init-enhancements-ideation-archive.md +109 -0
- package/docs/archive/ideation/2026-04-22-rules-entry-docs-optimization-consolidated-ideation-archive.md +54 -0
- package/docs/backlog.md +232 -144
- package/docs/brainstorms/2026-05-10-agent-effectiveness-validation-requirements.md +112 -0
- package/docs/generated/phase-58/subagent-evidence/claude-hook-example.json +15 -0
- package/docs/generated/phase-58/subagent-evidence/claude-session.md +146 -0
- package/docs/generated/phase-58/subagent-evidence/claude-subagent.json +28 -0
- package/docs/generated/phase-58/subagent-evidence/codex-agent-example.toml +19 -0
- package/docs/generated/phase-58/subagent-evidence/codex-session.md +150 -0
- package/docs/generated/phase-58/subagent-evidence/codex-subagent.json +20 -0
- package/docs/generated/phase-58/subagent-evidence/negative-no-retrieval.json +12 -0
- package/docs/generated/phase-58/subagent-evidence/verification-manifest.json +19 -0
- package/docs/ideation/2026-04-15-executable-architecture-constitution-ideation.md +10 -22
- package/docs/ideation/2026-04-20-mycodemap-init-enhancements-ideation.md +15 -60
- package/docs/ideation/2026-04-22-rules-entry-docs-optimization-consolidated-ideation.md +47 -52
- package/docs/ideation/2026-04-29-ux-install-agent-experience-ideation.md +256 -0
- package/docs/ideation/2026-05-02-subagent-environment-contract-injection-ideation.md +183 -0
- package/docs/ideation/2026-05-04-subagent-hooks-deep-dive-ideation.md +133 -0
- package/docs/ideation/2026-05-10-agent-effectiveness-validation-ideation.md +219 -0
- package/docs/plans/2026-04-30-install-guide-and-repo-analyzer-design.md +394 -0
- package/docs/rules/README.md +1 -0
- package/docs/rules/architecture-guardrails.md +2 -1
- package/docs/rules/engineering-with-codex-openai.md +1 -1
- package/docs/rules/harness.md +106 -0
- package/docs/rules/pre-release-checklist.md +28 -0
- package/docs/rules/testing.md +51 -0
- package/examples/claude/skills/mycodemap-repo-analyzer/SKILL.md +294 -0
- package/examples/claude/skills/mycodemap-repo-analyzer/references/analysis-guide.md +166 -0
- package/examples/claude/skills/mycodemap-repo-analyzer/references/module-analysis-guide.md +150 -0
- package/package.json +12 -4
- package/scripts/copy-build-assets.mjs +23 -0
- package/scripts/hooks/templates/pre-commit +33 -2
- package/scripts/sync-analyze-docs.js +2 -2
- package/scripts/tests/test_rule_control_workflow.py +15 -1
- package/scripts/validate-docs.js +113 -16
- package/scripts/verify-subagent-env-contract.mjs +279 -0
- package/dist/parser/implementations/tree-sitter-parser.d.ts +0 -57
- package/dist/parser/implementations/tree-sitter-parser.d.ts.map +0 -1
- package/dist/parser/implementations/tree-sitter-parser.js +0 -375
- package/dist/parser/implementations/tree-sitter-parser.js.map +0 -1
- package/docs/references/tmp.md +0 -527
|
@@ -0,0 +1,1022 @@
|
|
|
1
|
+
// [META] since:2026-05-09 | owner:cli-team | stable:false
|
|
2
|
+
// [WHY] AST-based Python parser using tree-sitter-python grammar
|
|
3
|
+
// ============================================
|
|
4
|
+
// Python Tree-sitter 解析器 - 基于 tree-sitter 的 AST 解析
|
|
5
|
+
// ============================================
|
|
6
|
+
import { randomUUID } from 'crypto';
|
|
7
|
+
import { analyzeComplexityFromContent } from '../../../core/ast-complexity-analyzer.js';
|
|
8
|
+
import { ParserBase, ParseError } from '../interfaces/ParserBase.js';
|
|
9
|
+
import { TreeSitterParser } from './TreeSitterParser.js';
|
|
10
|
+
/**
|
|
11
|
+
* Python Tree-sitter 解析器
|
|
12
|
+
*
|
|
13
|
+
* 基于 tree-sitter-python 的 AST 解析器,支持:
|
|
14
|
+
* - import/from 导入语句(含相对导入、别名、通配符)
|
|
15
|
+
* - class/function 定义(含装饰器、异步、类型注解)
|
|
16
|
+
* - __all__ 导出声明
|
|
17
|
+
* - 嵌套定义的递归提取
|
|
18
|
+
* - 多行导入的正确解析
|
|
19
|
+
*/
|
|
20
|
+
export class PythonTreeSitterParser extends ParserBase {
|
|
21
|
+
languageId = 'python';
|
|
22
|
+
fileExtensions = ['py'];
|
|
23
|
+
name = 'Python Tree-sitter Parser';
|
|
24
|
+
supportedFeatures = new Set([
|
|
25
|
+
'decorators',
|
|
26
|
+
'call-graph',
|
|
27
|
+
'cross-file-analysis',
|
|
28
|
+
'complexity-metrics',
|
|
29
|
+
]);
|
|
30
|
+
sharedParser = new TreeSitterParser({
|
|
31
|
+
rootDir: process.cwd(),
|
|
32
|
+
mode: 'tree-sitter',
|
|
33
|
+
});
|
|
34
|
+
// ============================================
|
|
35
|
+
// 生命周期
|
|
36
|
+
// ============================================
|
|
37
|
+
async doInitialize() {
|
|
38
|
+
try {
|
|
39
|
+
await this.sharedParser.initialize();
|
|
40
|
+
await this.sharedParser.parseSyntaxTree('/virtual.py', 'x = 1\n');
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
throw new ParseError('tree-sitter-python grammar not available. ' +
|
|
44
|
+
'Install native: npm install tree-sitter tree-sitter-python. ' +
|
|
45
|
+
'Or WASM: npm install web-tree-sitter tree-sitter-python. ' +
|
|
46
|
+
'No silent fallback to regex parser.');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async doDispose() {
|
|
50
|
+
this.sharedParser.dispose();
|
|
51
|
+
}
|
|
52
|
+
// ============================================
|
|
53
|
+
// parseFile
|
|
54
|
+
// ============================================
|
|
55
|
+
async parseFile(filePath, content, options) {
|
|
56
|
+
this.ensureInitialized();
|
|
57
|
+
const startTime = Date.now();
|
|
58
|
+
try {
|
|
59
|
+
const syntaxTree = await this.sharedParser.parseSyntaxTree(filePath, content);
|
|
60
|
+
const root = syntaxTree.rootNode;
|
|
61
|
+
// 并行提取各种信息
|
|
62
|
+
const [imports, exports, symbols] = await Promise.all([
|
|
63
|
+
this.extractImportsFromAST(root),
|
|
64
|
+
this.extractExportsFromAST(root),
|
|
65
|
+
this.extractSymbolsFromAST(root),
|
|
66
|
+
]);
|
|
67
|
+
const callGraph = options?.includeCallGraph
|
|
68
|
+
? this.buildCallGraphFromAST(root, imports, symbols)
|
|
69
|
+
: undefined;
|
|
70
|
+
const complexity = options?.includeComplexity
|
|
71
|
+
? analyzeComplexityFromContent({ filePath, content, language: 'python' })
|
|
72
|
+
: undefined;
|
|
73
|
+
const symbolsWithComplexity = complexity
|
|
74
|
+
? this.attachComplexityToSymbols(symbols, complexity)
|
|
75
|
+
: symbols;
|
|
76
|
+
// 统计行数
|
|
77
|
+
const lineCounts = this.countLinesFromAST(root, content);
|
|
78
|
+
const module = {
|
|
79
|
+
id: `mod_${randomUUID().replace(/-/g, '').slice(0, 16)}`,
|
|
80
|
+
projectId: '',
|
|
81
|
+
path: filePath,
|
|
82
|
+
language: 'python',
|
|
83
|
+
stats: {
|
|
84
|
+
lines: lineCounts.total,
|
|
85
|
+
codeLines: lineCounts.code,
|
|
86
|
+
commentLines: lineCounts.comment,
|
|
87
|
+
blankLines: lineCounts.blank,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const parseTime = Date.now() - startTime;
|
|
91
|
+
return {
|
|
92
|
+
filePath,
|
|
93
|
+
language: 'python',
|
|
94
|
+
module,
|
|
95
|
+
symbols: symbolsWithComplexity,
|
|
96
|
+
imports,
|
|
97
|
+
exports,
|
|
98
|
+
dependencies: [],
|
|
99
|
+
callGraph,
|
|
100
|
+
complexity,
|
|
101
|
+
parseTime,
|
|
102
|
+
parserUsed: 'PythonTreeSitterParser',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error instanceof ParseError)
|
|
107
|
+
throw error;
|
|
108
|
+
throw new ParseError(`Failed to parse ${filePath}: ${error instanceof Error ? error.message : String(error)}`, filePath);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// ============================================
|
|
112
|
+
// ParserBase 抽象方法实现(基于 content 字符串的接口)
|
|
113
|
+
// ============================================
|
|
114
|
+
async extractImports(content) {
|
|
115
|
+
this.ensureInitialized();
|
|
116
|
+
const syntaxTree = await this.sharedParser.parseSyntaxTree('/virtual.py', content);
|
|
117
|
+
return this.extractImportsFromAST(syntaxTree.rootNode);
|
|
118
|
+
}
|
|
119
|
+
async extractExports(content) {
|
|
120
|
+
this.ensureInitialized();
|
|
121
|
+
const syntaxTree = await this.sharedParser.parseSyntaxTree('/virtual.py', content);
|
|
122
|
+
return this.extractExportsFromAST(syntaxTree.rootNode);
|
|
123
|
+
}
|
|
124
|
+
async extractSymbols(content) {
|
|
125
|
+
this.ensureInitialized();
|
|
126
|
+
const syntaxTree = await this.sharedParser.parseSyntaxTree('/virtual.py', content);
|
|
127
|
+
return this.extractSymbolsFromAST(syntaxTree.rootNode);
|
|
128
|
+
}
|
|
129
|
+
async buildCallGraph(content) {
|
|
130
|
+
this.ensureInitialized();
|
|
131
|
+
const syntaxTree = await this.sharedParser.parseSyntaxTree('/virtual.py', content);
|
|
132
|
+
const root = syntaxTree.rootNode;
|
|
133
|
+
const imports = this.extractImportsFromAST(root);
|
|
134
|
+
const symbols = this.extractSymbolsFromAST(root);
|
|
135
|
+
return this.buildCallGraphFromAST(root, imports, symbols);
|
|
136
|
+
}
|
|
137
|
+
async calculateComplexity(content) {
|
|
138
|
+
this.ensureInitialized();
|
|
139
|
+
return analyzeComplexityFromContent({
|
|
140
|
+
filePath: '/virtual.py',
|
|
141
|
+
content,
|
|
142
|
+
language: 'python',
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
// ============================================
|
|
146
|
+
// AST-based 提取方法
|
|
147
|
+
// ============================================
|
|
148
|
+
/**
|
|
149
|
+
* 提取导入信息
|
|
150
|
+
* Walk root.namedChildren for import_statement, import_from_statement, future_import_statement
|
|
151
|
+
*/
|
|
152
|
+
extractImportsFromAST(root) {
|
|
153
|
+
const imports = [];
|
|
154
|
+
for (const child of root.namedChildren) {
|
|
155
|
+
if (child.type === 'import_statement') {
|
|
156
|
+
imports.push(...this.parseImportStatement(child));
|
|
157
|
+
}
|
|
158
|
+
else if (child.type === 'import_from_statement') {
|
|
159
|
+
imports.push(...this.parseImportFromStatement(child));
|
|
160
|
+
}
|
|
161
|
+
else if (child.type === 'future_import_statement') {
|
|
162
|
+
imports.push(...this.parseFutureImportStatement(child));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return imports;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 解析 import_statement: import x, import x as y
|
|
169
|
+
*/
|
|
170
|
+
parseImportStatement(node) {
|
|
171
|
+
const results = [];
|
|
172
|
+
// import_statement 的 name 字段包含所有导入的模块
|
|
173
|
+
const nameField = node.childForFieldName('name');
|
|
174
|
+
if (!nameField)
|
|
175
|
+
return results;
|
|
176
|
+
// name 字段可以是 dotted_name 或 aliased_import
|
|
177
|
+
const specifiers = this.extractImportSpecifiers(nameField);
|
|
178
|
+
if (specifiers.length > 0) {
|
|
179
|
+
results.push({
|
|
180
|
+
source: specifiers[0].name,
|
|
181
|
+
sourceType: specifiers[0].name.startsWith('.') ? 'relative' : 'absolute',
|
|
182
|
+
specifiers,
|
|
183
|
+
isTypeOnly: false,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return results;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* 解析 import_from_statement: from x import y, from . import x
|
|
190
|
+
*/
|
|
191
|
+
parseImportFromStatement(node) {
|
|
192
|
+
const results = [];
|
|
193
|
+
const moduleName = node.childForFieldName('module_name');
|
|
194
|
+
let source = '';
|
|
195
|
+
let sourceType = 'absolute';
|
|
196
|
+
if (moduleName) {
|
|
197
|
+
if (moduleName.type === 'relative_import') {
|
|
198
|
+
source = moduleName.text;
|
|
199
|
+
sourceType = 'relative';
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
source = moduleName.text;
|
|
203
|
+
sourceType = source.startsWith('.') ? 'relative' : 'absolute';
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// 遍历 namedChildren 提取 specifiers(跳过第一个,即 module_name)
|
|
207
|
+
const specifiers = [];
|
|
208
|
+
const children = node.namedChildren;
|
|
209
|
+
for (let i = 0; i < children.length; i++) {
|
|
210
|
+
const child = children[i];
|
|
211
|
+
// 跳过第一个 namedChild(module_name / relative_import)
|
|
212
|
+
if (i === 0)
|
|
213
|
+
continue;
|
|
214
|
+
if (child.type === 'dotted_name' || child.type === 'identifier') {
|
|
215
|
+
specifiers.push({ name: child.text, isTypeOnly: false });
|
|
216
|
+
}
|
|
217
|
+
else if (child.type === 'aliased_import') {
|
|
218
|
+
const name = child.childForFieldName('name');
|
|
219
|
+
const alias = child.childForFieldName('alias');
|
|
220
|
+
specifiers.push({
|
|
221
|
+
name: name?.text || '',
|
|
222
|
+
alias: alias?.text,
|
|
223
|
+
isTypeOnly: false,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
else if (child.type === 'wildcard_import') {
|
|
227
|
+
specifiers.push({ name: '*', isTypeOnly: false });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (specifiers.length > 0 || source) {
|
|
231
|
+
results.push({
|
|
232
|
+
source,
|
|
233
|
+
sourceType,
|
|
234
|
+
specifiers,
|
|
235
|
+
isTypeOnly: false,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return results;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* 解析 future_import_statement: from __future__ import annotations
|
|
242
|
+
* AST: 无 module_name 字段,namedChildren 全部是 specifiers
|
|
243
|
+
*/
|
|
244
|
+
parseFutureImportStatement(node) {
|
|
245
|
+
const results = [];
|
|
246
|
+
const specifiers = [];
|
|
247
|
+
for (const child of node.namedChildren) {
|
|
248
|
+
if (child.type === 'dotted_name' || child.type === 'identifier') {
|
|
249
|
+
specifiers.push({ name: child.text, isTypeOnly: false });
|
|
250
|
+
}
|
|
251
|
+
else if (child.type === 'aliased_import') {
|
|
252
|
+
const name = child.childForFieldName('name');
|
|
253
|
+
const alias = child.childForFieldName('alias');
|
|
254
|
+
specifiers.push({
|
|
255
|
+
name: name?.text || '',
|
|
256
|
+
alias: alias?.text,
|
|
257
|
+
isTypeOnly: false,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (specifiers.length > 0) {
|
|
262
|
+
results.push({
|
|
263
|
+
source: '__future__',
|
|
264
|
+
sourceType: 'absolute',
|
|
265
|
+
specifiers,
|
|
266
|
+
isTypeOnly: false,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return results;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* 从 name 字段提取 import specifiers
|
|
273
|
+
* 处理 dotted_name, aliased_import, wildcard_import
|
|
274
|
+
*/
|
|
275
|
+
extractImportSpecifiers(nameNode) {
|
|
276
|
+
const specifiers = [];
|
|
277
|
+
if (nameNode.type === 'dotted_name' || nameNode.type === 'identifier') {
|
|
278
|
+
specifiers.push({ name: nameNode.text, isTypeOnly: false });
|
|
279
|
+
}
|
|
280
|
+
else if (nameNode.type === 'aliased_import') {
|
|
281
|
+
const name = nameNode.childForFieldName('name');
|
|
282
|
+
const alias = nameNode.childForFieldName('alias');
|
|
283
|
+
specifiers.push({
|
|
284
|
+
name: name?.text || '',
|
|
285
|
+
alias: alias?.text,
|
|
286
|
+
isTypeOnly: false,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
else if (nameNode.type === 'wildcard_import') {
|
|
290
|
+
specifiers.push({ name: '*', isTypeOnly: false });
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
// 如果是 list(多个 name),遍历 namedChildren
|
|
294
|
+
for (const child of nameNode.namedChildren) {
|
|
295
|
+
if (child.type === 'dotted_name' || child.type === 'identifier') {
|
|
296
|
+
specifiers.push({ name: child.text, isTypeOnly: false });
|
|
297
|
+
}
|
|
298
|
+
else if (child.type === 'aliased_import') {
|
|
299
|
+
const name = child.childForFieldName('name');
|
|
300
|
+
const alias = child.childForFieldName('alias');
|
|
301
|
+
specifiers.push({
|
|
302
|
+
name: name?.text || '',
|
|
303
|
+
alias: alias?.text,
|
|
304
|
+
isTypeOnly: false,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
else if (child.type === 'wildcard_import') {
|
|
308
|
+
specifiers.push({ name: '*', isTypeOnly: false });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return specifiers;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* 提取导出信息
|
|
316
|
+
* 1. 扫描 __all__ assignment
|
|
317
|
+
* 2. 如果没有 __all__,扫描顶层 class/function 定义(不以 _ 开头)
|
|
318
|
+
*/
|
|
319
|
+
extractExportsFromAST(root) {
|
|
320
|
+
const exports = [];
|
|
321
|
+
let hasAll = false;
|
|
322
|
+
// 扫描 __all__ assignment
|
|
323
|
+
for (const child of root.namedChildren) {
|
|
324
|
+
if (child.type === 'assignment') {
|
|
325
|
+
const left = child.childForFieldName('left');
|
|
326
|
+
const right = child.childForFieldName('right');
|
|
327
|
+
if (left?.text === '__all__' && right?.type === 'list') {
|
|
328
|
+
hasAll = true;
|
|
329
|
+
for (const item of right.namedChildren) {
|
|
330
|
+
if (item.type === 'string') {
|
|
331
|
+
// 去掉引号
|
|
332
|
+
const name = item.text.replace(/^['"]|['"]$/g, '');
|
|
333
|
+
if (name) {
|
|
334
|
+
exports.push({
|
|
335
|
+
name,
|
|
336
|
+
kind: 'variable',
|
|
337
|
+
isDefault: false,
|
|
338
|
+
isTypeOnly: false,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// 如果没有 __all__,扫描顶层定义
|
|
347
|
+
if (!hasAll) {
|
|
348
|
+
for (const child of root.namedChildren) {
|
|
349
|
+
if (child.type === 'class_definition') {
|
|
350
|
+
const name = child.childForFieldName('name');
|
|
351
|
+
if (name && !name.text.startsWith('_')) {
|
|
352
|
+
exports.push({
|
|
353
|
+
name: name.text,
|
|
354
|
+
kind: 'class',
|
|
355
|
+
isDefault: false,
|
|
356
|
+
isTypeOnly: false,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
else if (child.type === 'function_definition') {
|
|
361
|
+
const name = child.childForFieldName('name');
|
|
362
|
+
if (name && !name.text.startsWith('_')) {
|
|
363
|
+
exports.push({
|
|
364
|
+
name: name.text,
|
|
365
|
+
kind: 'function',
|
|
366
|
+
isDefault: false,
|
|
367
|
+
isTypeOnly: false,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
else if (child.type === 'decorated_definition') {
|
|
372
|
+
const definition = child.childForFieldName('definition');
|
|
373
|
+
if (definition) {
|
|
374
|
+
if (definition.type === 'class_definition') {
|
|
375
|
+
const name = definition.childForFieldName('name');
|
|
376
|
+
if (name && !name.text.startsWith('_')) {
|
|
377
|
+
exports.push({
|
|
378
|
+
name: name.text,
|
|
379
|
+
kind: 'class',
|
|
380
|
+
isDefault: false,
|
|
381
|
+
isTypeOnly: false,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else if (definition.type === 'function_definition') {
|
|
386
|
+
const name = definition.childForFieldName('name');
|
|
387
|
+
if (name && !name.text.startsWith('_')) {
|
|
388
|
+
exports.push({
|
|
389
|
+
name: name.text,
|
|
390
|
+
kind: 'function',
|
|
391
|
+
isDefault: false,
|
|
392
|
+
isTypeOnly: false,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return exports;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* 提取符号信息(递归遍历)
|
|
404
|
+
*/
|
|
405
|
+
extractSymbolsFromAST(root) {
|
|
406
|
+
const symbols = [];
|
|
407
|
+
this.walkNode(root, symbols, { withinFunction: false });
|
|
408
|
+
return symbols;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* 递归遍历 AST 节点提取符号
|
|
412
|
+
*/
|
|
413
|
+
walkNode(node, symbols, context) {
|
|
414
|
+
if (node.type === 'class_definition') {
|
|
415
|
+
const classSymbol = this.extractClassSymbol(node, null);
|
|
416
|
+
symbols.push(classSymbol);
|
|
417
|
+
const body = node.childForFieldName('body');
|
|
418
|
+
if (body) {
|
|
419
|
+
for (const child of body.namedChildren) {
|
|
420
|
+
this.walkNode(child, symbols, {
|
|
421
|
+
currentClassName: classSymbol.name,
|
|
422
|
+
withinFunction: false,
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (node.type === 'function_definition') {
|
|
429
|
+
const isMethod = Boolean(context.currentClassName && !context.withinFunction);
|
|
430
|
+
symbols.push(this.extractFunctionSymbol(node, null, context.currentClassName, isMethod));
|
|
431
|
+
const body = node.childForFieldName('body');
|
|
432
|
+
if (body) {
|
|
433
|
+
for (const child of body.namedChildren) {
|
|
434
|
+
this.walkNode(child, symbols, {
|
|
435
|
+
currentClassName: context.currentClassName,
|
|
436
|
+
withinFunction: true,
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (node.type === 'decorated_definition') {
|
|
443
|
+
const definition = node.childForFieldName('definition');
|
|
444
|
+
if (definition) {
|
|
445
|
+
const decorators = this.extractDecorators(node);
|
|
446
|
+
if (definition.type === 'class_definition') {
|
|
447
|
+
const classSymbol = this.extractClassSymbol(definition, decorators);
|
|
448
|
+
symbols.push(classSymbol);
|
|
449
|
+
const body = definition.childForFieldName('body');
|
|
450
|
+
if (body) {
|
|
451
|
+
for (const child of body.namedChildren) {
|
|
452
|
+
this.walkNode(child, symbols, {
|
|
453
|
+
currentClassName: classSymbol.name,
|
|
454
|
+
withinFunction: false,
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
else if (definition.type === 'function_definition') {
|
|
460
|
+
const isMethod = Boolean(context.currentClassName && !context.withinFunction);
|
|
461
|
+
symbols.push(this.extractFunctionSymbol(definition, decorators, context.currentClassName, isMethod));
|
|
462
|
+
const body = definition.childForFieldName('body');
|
|
463
|
+
if (body) {
|
|
464
|
+
for (const child of body.namedChildren) {
|
|
465
|
+
this.walkNode(child, symbols, {
|
|
466
|
+
currentClassName: context.currentClassName,
|
|
467
|
+
withinFunction: true,
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
for (const child of node.namedChildren) {
|
|
476
|
+
this.walkNode(child, symbols, context);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* 提取 class 定义的符号信息
|
|
481
|
+
*/
|
|
482
|
+
extractClassSymbol(node, decorators) {
|
|
483
|
+
const name = node.childForFieldName('name');
|
|
484
|
+
const nameText = name?.text || '<anonymous>';
|
|
485
|
+
const superclasses = node.childForFieldName('superclasses');
|
|
486
|
+
const extendsList = [];
|
|
487
|
+
if (superclasses) {
|
|
488
|
+
for (const child of superclasses.namedChildren) {
|
|
489
|
+
extendsList.push(child.text);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return {
|
|
493
|
+
id: `sym_${randomUUID().replace(/-/g, '').slice(0, 16)}`,
|
|
494
|
+
name: nameText,
|
|
495
|
+
kind: 'class',
|
|
496
|
+
location: {
|
|
497
|
+
file: '',
|
|
498
|
+
line: node.startPosition.row + 1,
|
|
499
|
+
column: node.startPosition.column,
|
|
500
|
+
},
|
|
501
|
+
visibility: nameText.startsWith('_') ? 'private' : 'public',
|
|
502
|
+
relatedSymbols: [],
|
|
503
|
+
...(extendsList.length > 0 && { extends: extendsList }),
|
|
504
|
+
...(decorators && decorators.length > 0 && { decorators }),
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* 提取 function 定义的符号信息
|
|
509
|
+
*/
|
|
510
|
+
extractFunctionSymbol(node, decorators, currentClassName, isMethod = false) {
|
|
511
|
+
const name = node.childForFieldName('name');
|
|
512
|
+
const nameText = name?.text || '<anonymous>';
|
|
513
|
+
const symbolName = isMethod && currentClassName ? `${currentClassName}.${nameText}` : nameText;
|
|
514
|
+
const parameters = node.childForFieldName('parameters');
|
|
515
|
+
const returnTypeNode = node.childForFieldName('return_type');
|
|
516
|
+
const isAsync = this.isAsync(node);
|
|
517
|
+
const params = parameters ? this.extractParameters(parameters) : [];
|
|
518
|
+
const signature = {
|
|
519
|
+
parameters: params,
|
|
520
|
+
returnType: returnTypeNode?.text || '',
|
|
521
|
+
async: isAsync,
|
|
522
|
+
};
|
|
523
|
+
return {
|
|
524
|
+
id: `sym_${randomUUID().replace(/-/g, '').slice(0, 16)}`,
|
|
525
|
+
name: symbolName,
|
|
526
|
+
kind: isMethod ? 'method' : 'function',
|
|
527
|
+
location: {
|
|
528
|
+
file: '',
|
|
529
|
+
line: node.startPosition.row + 1,
|
|
530
|
+
column: node.startPosition.column,
|
|
531
|
+
},
|
|
532
|
+
visibility: nameText.startsWith('_') ? 'private' : 'public',
|
|
533
|
+
relatedSymbols: [],
|
|
534
|
+
signature,
|
|
535
|
+
...(decorators && decorators.length > 0 && { decorators }),
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* 从 decorated_definition 提取装饰器信息
|
|
540
|
+
*/
|
|
541
|
+
extractDecorators(node) {
|
|
542
|
+
const decorators = [];
|
|
543
|
+
for (const child of node.children) {
|
|
544
|
+
if (child.type === 'decorator') {
|
|
545
|
+
const expression = child.namedChildren[0];
|
|
546
|
+
let name = '';
|
|
547
|
+
let params = undefined;
|
|
548
|
+
if (expression) {
|
|
549
|
+
if (expression.type === 'call') {
|
|
550
|
+
// @foo(args) — call 表达式
|
|
551
|
+
const funcName = expression.childForFieldName('function');
|
|
552
|
+
name = funcName?.text || expression.text;
|
|
553
|
+
params = true; // 标记有参数
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
// @foo — 简单标识符或属性
|
|
557
|
+
name = expression.text;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
decorators.push({
|
|
561
|
+
name,
|
|
562
|
+
...(params !== undefined && { params }),
|
|
563
|
+
target: this.guessDecoratorTarget(node),
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return decorators;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* 猜测装饰器目标类型
|
|
571
|
+
*/
|
|
572
|
+
guessDecoratorTarget(node) {
|
|
573
|
+
const definition = node.childForFieldName('definition');
|
|
574
|
+
if (definition?.type === 'class_definition')
|
|
575
|
+
return 'class';
|
|
576
|
+
if (definition?.type === 'function_definition')
|
|
577
|
+
return 'method';
|
|
578
|
+
return 'method';
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* 从 parameters 节点提取参数信息
|
|
582
|
+
*/
|
|
583
|
+
extractParameters(parametersNode) {
|
|
584
|
+
const params = [];
|
|
585
|
+
for (const child of parametersNode.namedChildren) {
|
|
586
|
+
if (child.type === 'identifier') {
|
|
587
|
+
// def foo(x): — 普通参数
|
|
588
|
+
params.push({
|
|
589
|
+
name: child.text,
|
|
590
|
+
type: '',
|
|
591
|
+
optional: false,
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
else if (child.type === 'typed_parameter') {
|
|
595
|
+
// def foo(x: int): — 类型注解参数
|
|
596
|
+
const name = child.childForFieldName('name');
|
|
597
|
+
const typeNode = child.childForFieldName('type');
|
|
598
|
+
params.push({
|
|
599
|
+
name: name?.text || child.text.split(':')[0]?.trim() || '',
|
|
600
|
+
type: typeNode?.text || '',
|
|
601
|
+
optional: false,
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
else if (child.type === 'default_parameter') {
|
|
605
|
+
// def foo(x=5): — 带默认值参数
|
|
606
|
+
const name = child.childForFieldName('name');
|
|
607
|
+
const value = child.childForFieldName('value');
|
|
608
|
+
params.push({
|
|
609
|
+
name: name?.text || '',
|
|
610
|
+
type: '',
|
|
611
|
+
optional: true,
|
|
612
|
+
defaultValue: value?.text,
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
else if (child.type === 'typed_default_parameter') {
|
|
616
|
+
// def foo(x: int = 5): — 类型注解 + 默认值
|
|
617
|
+
const name = child.childForFieldName('name');
|
|
618
|
+
const typeNode = child.childForFieldName('type');
|
|
619
|
+
const value = child.childForFieldName('value');
|
|
620
|
+
params.push({
|
|
621
|
+
name: name?.text || '',
|
|
622
|
+
type: typeNode?.text || '',
|
|
623
|
+
optional: true,
|
|
624
|
+
defaultValue: value?.text,
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
else if (child.type === 'list_splat_pattern') {
|
|
628
|
+
// def foo(*args): — *args
|
|
629
|
+
const name = child.namedChildren[0];
|
|
630
|
+
params.push({
|
|
631
|
+
name: name?.text || '*args',
|
|
632
|
+
type: '',
|
|
633
|
+
optional: false,
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
else if (child.type === 'dictionary_splat_pattern') {
|
|
637
|
+
// def foo(**kwargs): — **kwargs
|
|
638
|
+
const name = child.namedChildren[0];
|
|
639
|
+
params.push({
|
|
640
|
+
name: name?.text || '**kwargs',
|
|
641
|
+
type: '',
|
|
642
|
+
optional: false,
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
return params;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* 检测函数是否为 async
|
|
650
|
+
* 检查 node.children(不是 namedChildren)中是否有 type === 'async'
|
|
651
|
+
*/
|
|
652
|
+
isAsync(node) {
|
|
653
|
+
for (const child of node.children) {
|
|
654
|
+
if (child.type === 'async') {
|
|
655
|
+
return true;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
calculateComplexityFromAST(root, content) {
|
|
661
|
+
const fileMetrics = this.measureComplexity(root);
|
|
662
|
+
const functionDetails = this.collectFunctionComplexities(root);
|
|
663
|
+
const lines = content.split('\n').length;
|
|
664
|
+
const commentLines = content
|
|
665
|
+
.split('\n')
|
|
666
|
+
.filter((line) => line.trim().startsWith('#'))
|
|
667
|
+
.length;
|
|
668
|
+
const commentRatio = commentLines / Math.max(1, lines);
|
|
669
|
+
return {
|
|
670
|
+
cyclomatic: fileMetrics.cyclomatic,
|
|
671
|
+
cognitive: fileMetrics.cognitive,
|
|
672
|
+
maintainability: this.calculateMaintainabilityIndex(lines, fileMetrics.cyclomatic, commentRatio),
|
|
673
|
+
details: {
|
|
674
|
+
functions: functionDetails.map((detail) => ({
|
|
675
|
+
name: detail.name,
|
|
676
|
+
cyclomatic: detail.cyclomatic,
|
|
677
|
+
cognitive: detail.cognitive,
|
|
678
|
+
lines: detail.lines,
|
|
679
|
+
})),
|
|
680
|
+
},
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
attachComplexityToSymbols(symbols, complexity) {
|
|
684
|
+
const detailByName = new Map();
|
|
685
|
+
for (const detail of complexity.details.functions) {
|
|
686
|
+
detailByName.set(detail.name, detail);
|
|
687
|
+
}
|
|
688
|
+
return symbols.map((symbol) => {
|
|
689
|
+
if (symbol.kind !== 'function' && symbol.kind !== 'method') {
|
|
690
|
+
return symbol;
|
|
691
|
+
}
|
|
692
|
+
const detail = detailByName.get(symbol.name);
|
|
693
|
+
if (!detail) {
|
|
694
|
+
return symbol;
|
|
695
|
+
}
|
|
696
|
+
return {
|
|
697
|
+
...symbol,
|
|
698
|
+
complexity: {
|
|
699
|
+
cyclomatic: detail.cyclomatic,
|
|
700
|
+
cognitive: detail.cognitive,
|
|
701
|
+
lines: detail.lines,
|
|
702
|
+
},
|
|
703
|
+
};
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
collectFunctionComplexities(root) {
|
|
707
|
+
const details = [];
|
|
708
|
+
this.walkComplexityNode(root, details, { withinFunction: false });
|
|
709
|
+
return details;
|
|
710
|
+
}
|
|
711
|
+
walkComplexityNode(node, details, context) {
|
|
712
|
+
if (node.type === 'class_definition') {
|
|
713
|
+
const className = node.childForFieldName('name')?.text;
|
|
714
|
+
const body = node.childForFieldName('body');
|
|
715
|
+
if (body) {
|
|
716
|
+
for (const child of body.namedChildren) {
|
|
717
|
+
this.walkComplexityNode(child, details, {
|
|
718
|
+
currentClassName: className,
|
|
719
|
+
withinFunction: false,
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (node.type === 'function_definition') {
|
|
726
|
+
const nameText = node.childForFieldName('name')?.text || '<anonymous>';
|
|
727
|
+
const isMethod = Boolean(context.currentClassName && !context.withinFunction);
|
|
728
|
+
const symbolName = isMethod && context.currentClassName
|
|
729
|
+
? `${context.currentClassName}.${nameText}`
|
|
730
|
+
: nameText;
|
|
731
|
+
details.push(this.measureFunctionComplexity(node, symbolName));
|
|
732
|
+
const body = node.childForFieldName('body');
|
|
733
|
+
if (body) {
|
|
734
|
+
for (const child of body.namedChildren) {
|
|
735
|
+
this.walkComplexityNode(child, details, {
|
|
736
|
+
currentClassName: context.currentClassName,
|
|
737
|
+
withinFunction: true,
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
if (node.type === 'decorated_definition') {
|
|
744
|
+
const definition = node.childForFieldName('definition');
|
|
745
|
+
if (definition) {
|
|
746
|
+
this.walkComplexityNode(definition, details, context);
|
|
747
|
+
}
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
for (const child of node.namedChildren) {
|
|
751
|
+
this.walkComplexityNode(child, details, context);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
measureFunctionComplexity(node, name) {
|
|
755
|
+
const body = node.childForFieldName('body') ?? node;
|
|
756
|
+
const metrics = this.measureComplexity(body);
|
|
757
|
+
return {
|
|
758
|
+
name,
|
|
759
|
+
line: node.startPosition.row + 1,
|
|
760
|
+
cyclomatic: metrics.cyclomatic,
|
|
761
|
+
cognitive: metrics.cognitive,
|
|
762
|
+
lines: node.endPosition.row - node.startPosition.row + 1,
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
measureComplexity(node) {
|
|
766
|
+
const counters = { branches: 0, maxDepth: 0 };
|
|
767
|
+
const visit = (current, depth) => {
|
|
768
|
+
const nextDepth = this.isComplexityBranchNode(current) ? depth + 1 : depth;
|
|
769
|
+
if (this.isComplexityBranchNode(current) || current.type === 'boolean_operator') {
|
|
770
|
+
counters.branches++;
|
|
771
|
+
}
|
|
772
|
+
if (this.isComplexityBranchNode(current)) {
|
|
773
|
+
counters.maxDepth = Math.max(counters.maxDepth, nextDepth);
|
|
774
|
+
}
|
|
775
|
+
for (const child of current.namedChildren ?? []) {
|
|
776
|
+
visit(child, nextDepth);
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
visit(node, 0);
|
|
780
|
+
const cyclomatic = counters.branches + 1;
|
|
781
|
+
return {
|
|
782
|
+
cyclomatic,
|
|
783
|
+
cognitive: cyclomatic + counters.maxDepth * 2,
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
isComplexityBranchNode(node) {
|
|
787
|
+
return [
|
|
788
|
+
'if_statement',
|
|
789
|
+
'elif_clause',
|
|
790
|
+
'for_statement',
|
|
791
|
+
'while_statement',
|
|
792
|
+
'except_clause',
|
|
793
|
+
'conditional_expression',
|
|
794
|
+
'assert_statement',
|
|
795
|
+
'comprehension_clause',
|
|
796
|
+
].includes(node.type);
|
|
797
|
+
}
|
|
798
|
+
calculateMaintainabilityIndex(loc, cyclomatic, commentRatio) {
|
|
799
|
+
const normalizedLOC = Math.max(1, loc);
|
|
800
|
+
const normalizedCC = Math.max(1, cyclomatic);
|
|
801
|
+
let mi = 100;
|
|
802
|
+
mi -= (normalizedCC - 1) * 2;
|
|
803
|
+
mi -= Math.log(normalizedLOC / 10 + 1) * 5;
|
|
804
|
+
mi += commentRatio * 15;
|
|
805
|
+
return Math.max(0, Math.min(100, Math.round(mi)));
|
|
806
|
+
}
|
|
807
|
+
buildCallGraphFromAST(root, imports, symbols) {
|
|
808
|
+
const calls = [];
|
|
809
|
+
const issues = [];
|
|
810
|
+
const importedNames = this.collectImportedNames(imports);
|
|
811
|
+
const localClassNames = new Set(symbols
|
|
812
|
+
.filter((symbol) => symbol.kind === 'class')
|
|
813
|
+
.map((symbol) => symbol.name));
|
|
814
|
+
this.walkCallGraph(root, { withinFunction: false }, calls, issues, localClassNames, importedNames);
|
|
815
|
+
const recursive = [...new Set(calls
|
|
816
|
+
.filter((call) => call.caller === call.callee)
|
|
817
|
+
.map((call) => call.caller))];
|
|
818
|
+
return { calls, recursive, issues };
|
|
819
|
+
}
|
|
820
|
+
walkCallGraph(node, context, calls, issues, localClassNames, importedNames) {
|
|
821
|
+
if (node.type === 'class_definition') {
|
|
822
|
+
const className = node.childForFieldName('name')?.text;
|
|
823
|
+
const body = node.childForFieldName('body');
|
|
824
|
+
if (className && body) {
|
|
825
|
+
for (const child of body.namedChildren) {
|
|
826
|
+
this.walkCallGraph(child, {
|
|
827
|
+
currentClassName: className,
|
|
828
|
+
withinFunction: false,
|
|
829
|
+
}, calls, issues, localClassNames, importedNames);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
if (node.type === 'function_definition') {
|
|
835
|
+
this.collectFunctionCalls(node, context, calls, issues, localClassNames, importedNames);
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
if (node.type === 'decorated_definition') {
|
|
839
|
+
const definition = node.childForFieldName('definition');
|
|
840
|
+
if (definition?.type === 'class_definition') {
|
|
841
|
+
this.walkCallGraph(definition, context, calls, issues, localClassNames, importedNames);
|
|
842
|
+
}
|
|
843
|
+
else if (definition?.type === 'function_definition') {
|
|
844
|
+
this.collectFunctionCalls(definition, context, calls, issues, localClassNames, importedNames);
|
|
845
|
+
}
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
for (const child of node.namedChildren) {
|
|
849
|
+
this.walkCallGraph(child, context, calls, issues, localClassNames, importedNames);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
collectFunctionCalls(node, context, calls, issues, localClassNames, importedNames) {
|
|
853
|
+
const nameText = node.childForFieldName('name')?.text || '<anonymous>';
|
|
854
|
+
const isMethod = Boolean(context.currentClassName && !context.withinFunction);
|
|
855
|
+
const callerName = isMethod && context.currentClassName
|
|
856
|
+
? `${context.currentClassName}.${nameText}`
|
|
857
|
+
: nameText;
|
|
858
|
+
const body = node.childForFieldName('body');
|
|
859
|
+
if (!body) {
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
this.collectCallsInNode(body, {
|
|
863
|
+
callerName,
|
|
864
|
+
currentClassName: context.currentClassName,
|
|
865
|
+
withinFunction: true,
|
|
866
|
+
}, calls, issues, localClassNames, importedNames);
|
|
867
|
+
for (const child of body.namedChildren) {
|
|
868
|
+
this.walkCallGraph(child, {
|
|
869
|
+
currentClassName: context.currentClassName,
|
|
870
|
+
withinFunction: true,
|
|
871
|
+
}, calls, issues, localClassNames, importedNames);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
collectCallsInNode(node, context, calls, issues, localClassNames, importedNames) {
|
|
875
|
+
if (node.type === 'class_definition' || node.type === 'function_definition' || node.type === 'decorated_definition') {
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
if (node.type === 'call') {
|
|
879
|
+
this.recordCallNode(node, context, calls, issues, localClassNames, importedNames);
|
|
880
|
+
}
|
|
881
|
+
const functionChild = node.type === 'call' ? node.childForFieldName('function') : null;
|
|
882
|
+
for (const child of node.namedChildren) {
|
|
883
|
+
if (functionChild && this.isSameNode(child, functionChild)) {
|
|
884
|
+
continue;
|
|
885
|
+
}
|
|
886
|
+
this.collectCallsInNode(child, context, calls, issues, localClassNames, importedNames);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
recordCallNode(node, context, calls, issues, localClassNames, importedNames) {
|
|
890
|
+
const functionNode = node.childForFieldName('function');
|
|
891
|
+
if (!functionNode || !context.callerName) {
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
if (functionNode.type === 'identifier') {
|
|
895
|
+
calls.push({
|
|
896
|
+
caller: context.callerName,
|
|
897
|
+
callee: functionNode.text,
|
|
898
|
+
line: node.startPosition.row + 1,
|
|
899
|
+
});
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
if (functionNode.type === 'attribute') {
|
|
903
|
+
const objectNode = functionNode.childForFieldName('object');
|
|
904
|
+
const attributeNode = functionNode.childForFieldName('attribute');
|
|
905
|
+
if (!objectNode || !attributeNode) {
|
|
906
|
+
issues?.push({
|
|
907
|
+
caller: context.callerName,
|
|
908
|
+
expression: node.text,
|
|
909
|
+
line: node.startPosition.row + 1,
|
|
910
|
+
column: node.startPosition.column,
|
|
911
|
+
status: 'unresolved',
|
|
912
|
+
});
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
if (objectNode.type !== 'identifier') {
|
|
916
|
+
issues?.push({
|
|
917
|
+
caller: context.callerName,
|
|
918
|
+
expression: node.text,
|
|
919
|
+
line: node.startPosition.row + 1,
|
|
920
|
+
column: node.startPosition.column,
|
|
921
|
+
status: 'unsupported_dynamic',
|
|
922
|
+
});
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
const objectName = objectNode.text;
|
|
926
|
+
const attributeName = attributeNode.text;
|
|
927
|
+
if ((objectName === 'self' || objectName === 'cls') && context.currentClassName) {
|
|
928
|
+
calls.push({
|
|
929
|
+
caller: context.callerName,
|
|
930
|
+
callee: `${context.currentClassName}.${attributeName}`,
|
|
931
|
+
line: node.startPosition.row + 1,
|
|
932
|
+
});
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
if (localClassNames.has(objectName) || importedNames.has(objectName)) {
|
|
936
|
+
calls.push({
|
|
937
|
+
caller: context.callerName,
|
|
938
|
+
callee: `${objectName}.${attributeName}`,
|
|
939
|
+
line: node.startPosition.row + 1,
|
|
940
|
+
});
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
issues?.push({
|
|
944
|
+
caller: context.callerName,
|
|
945
|
+
expression: node.text,
|
|
946
|
+
line: node.startPosition.row + 1,
|
|
947
|
+
column: node.startPosition.column,
|
|
948
|
+
status: 'ambiguous',
|
|
949
|
+
});
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
issues?.push({
|
|
953
|
+
caller: context.callerName,
|
|
954
|
+
expression: node.text,
|
|
955
|
+
line: node.startPosition.row + 1,
|
|
956
|
+
column: node.startPosition.column,
|
|
957
|
+
status: functionNode.type === 'call' ? 'unsupported_dynamic' : 'unresolved',
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
collectImportedNames(imports) {
|
|
961
|
+
const importedNames = new Set();
|
|
962
|
+
for (const imp of imports) {
|
|
963
|
+
for (const specifier of imp.specifiers) {
|
|
964
|
+
if (specifier.alias) {
|
|
965
|
+
importedNames.add(specifier.alias);
|
|
966
|
+
}
|
|
967
|
+
if (specifier.name && specifier.name !== '*') {
|
|
968
|
+
importedNames.add(specifier.name);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return importedNames;
|
|
973
|
+
}
|
|
974
|
+
isSameNode(left, right) {
|
|
975
|
+
return left.type === right.type &&
|
|
976
|
+
left.startIndex === right.startIndex &&
|
|
977
|
+
left.endIndex === right.endIndex;
|
|
978
|
+
}
|
|
979
|
+
// ============================================
|
|
980
|
+
// 行数统计(基于 AST)
|
|
981
|
+
// ============================================
|
|
982
|
+
/**
|
|
983
|
+
* 基于 AST 统计行数(使用 comment 节点)
|
|
984
|
+
*/
|
|
985
|
+
countLinesFromAST(root, content) {
|
|
986
|
+
const lines = content.split('\n');
|
|
987
|
+
const total = lines.length;
|
|
988
|
+
// 统计空行
|
|
989
|
+
let blank = 0;
|
|
990
|
+
for (const line of lines) {
|
|
991
|
+
if (line.trim().length === 0) {
|
|
992
|
+
blank++;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
// 统计注释行
|
|
996
|
+
const commentLines = new Set();
|
|
997
|
+
this.collectCommentLines(root, commentLines);
|
|
998
|
+
const comment = commentLines.size;
|
|
999
|
+
return {
|
|
1000
|
+
total,
|
|
1001
|
+
code: total - comment - blank,
|
|
1002
|
+
comment,
|
|
1003
|
+
blank,
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* 递归收集注释节点的行号
|
|
1008
|
+
*/
|
|
1009
|
+
collectCommentLines(node, lines) {
|
|
1010
|
+
if (node.type === 'comment') {
|
|
1011
|
+
const start = node.startPosition.row;
|
|
1012
|
+
const end = node.endPosition.row;
|
|
1013
|
+
for (let i = start; i <= end; i++) {
|
|
1014
|
+
lines.add(i);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
for (const child of node.children) {
|
|
1018
|
+
this.collectCommentLines(child, lines);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
//# sourceMappingURL=PythonTreeSitterParser.js.map
|