@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
|
@@ -1,240 +1,399 @@
|
|
|
1
1
|
// [META] since:2026-03-03 | owner:orchestrator-team | stable:true
|
|
2
|
-
// [WHY]
|
|
3
|
-
import * as ts from 'typescript';
|
|
2
|
+
// [WHY] Provide the canonical complexity seam for active TS/JS/Python/Go parser flows
|
|
4
3
|
import * as fs from 'fs';
|
|
5
4
|
import * as path from 'path';
|
|
6
|
-
|
|
5
|
+
import * as ts from 'typescript';
|
|
7
6
|
const HIGH_COMPLEXITY_THRESHOLD = 10;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
7
|
+
const SUPPORTED_EXTENSIONS = new Map([
|
|
8
|
+
['.ts', 'typescript'],
|
|
9
|
+
['.tsx', 'typescript'],
|
|
10
|
+
['.js', 'javascript'],
|
|
11
|
+
['.jsx', 'javascript'],
|
|
12
|
+
['.mjs', 'javascript'],
|
|
13
|
+
['.cjs', 'javascript'],
|
|
14
|
+
['.py', 'python'],
|
|
15
|
+
['.go', 'go'],
|
|
16
|
+
]);
|
|
17
|
+
function calculateMaintainabilityIndex(loc, cyclomatic, commentRatio) {
|
|
18
|
+
const normalizedLOC = Math.max(1, loc);
|
|
19
|
+
const normalizedCC = Math.max(1, cyclomatic);
|
|
20
|
+
let mi = 100;
|
|
21
|
+
mi -= (normalizedCC - 1) * 2;
|
|
22
|
+
mi -= Math.log(normalizedLOC / 10 + 1) * 5;
|
|
23
|
+
mi += commentRatio * 15;
|
|
24
|
+
return Math.max(0, Math.min(100, Math.round(mi)));
|
|
25
|
+
}
|
|
26
|
+
function detectLanguageFromFilePath(filePath) {
|
|
27
|
+
const extension = path.extname(filePath).toLowerCase();
|
|
28
|
+
const language = SUPPORTED_EXTENSIONS.get(extension);
|
|
29
|
+
if (!language) {
|
|
30
|
+
throw new Error(`不支持的 complexity 语言: ${filePath}`);
|
|
31
|
+
}
|
|
32
|
+
return language;
|
|
33
|
+
}
|
|
34
|
+
function toComplexityMetrics(fileComplexity) {
|
|
35
|
+
return {
|
|
36
|
+
cyclomatic: fileComplexity.cyclomatic,
|
|
37
|
+
cognitive: fileComplexity.cognitive,
|
|
38
|
+
maintainability: fileComplexity.maintainability,
|
|
39
|
+
details: {
|
|
40
|
+
functions: fileComplexity.functionDetails.map((detail) => ({
|
|
41
|
+
name: detail.name,
|
|
42
|
+
cyclomatic: detail.cyclomatic,
|
|
43
|
+
cognitive: detail.cognitive,
|
|
44
|
+
lines: detail.lines,
|
|
45
|
+
})),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function buildFileComplexity(filePath, lines, classes, functionDetails, cyclomatic, cognitive, maintainability) {
|
|
50
|
+
return {
|
|
51
|
+
filePath,
|
|
52
|
+
relativePath: path.basename(filePath),
|
|
53
|
+
cyclomatic,
|
|
54
|
+
cognitive,
|
|
55
|
+
maintainability,
|
|
56
|
+
functions: functionDetails.length,
|
|
57
|
+
classes,
|
|
58
|
+
lines,
|
|
59
|
+
functionDetails: functionDetails.map((detail) => ({
|
|
60
|
+
name: detail.name,
|
|
61
|
+
kind: detail.kind,
|
|
62
|
+
line: detail.line,
|
|
63
|
+
column: 1,
|
|
64
|
+
cyclomatic: detail.cyclomatic,
|
|
65
|
+
cognitive: detail.cognitive,
|
|
66
|
+
lines: detail.lines,
|
|
67
|
+
nestingDepth: detail.nestingDepth,
|
|
68
|
+
isHighComplexity: detail.cyclomatic >= HIGH_COMPLEXITY_THRESHOLD,
|
|
69
|
+
})),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function countLines(content) {
|
|
73
|
+
return content.split('\n').length;
|
|
74
|
+
}
|
|
75
|
+
function countCommentLines(content, language) {
|
|
76
|
+
return content
|
|
77
|
+
.split('\n')
|
|
78
|
+
.filter((line) => {
|
|
79
|
+
const trimmed = line.trim();
|
|
80
|
+
if (language === 'python') {
|
|
81
|
+
return trimmed.startsWith('#');
|
|
31
82
|
}
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
83
|
+
return trimmed.startsWith('//') || trimmed.startsWith('/*') || trimmed.startsWith('*');
|
|
84
|
+
})
|
|
85
|
+
.length;
|
|
86
|
+
}
|
|
87
|
+
function normalizeIndent(rawLine) {
|
|
88
|
+
return rawLine.replace(/\t/g, ' ').match(/^ */)?.[0].length ?? 0;
|
|
89
|
+
}
|
|
90
|
+
function stripPythonInlineComment(line) {
|
|
91
|
+
let inSingle = false;
|
|
92
|
+
let inDouble = false;
|
|
93
|
+
for (let index = 0; index < line.length; index++) {
|
|
94
|
+
const current = line[index];
|
|
95
|
+
if (current === "'" && !inDouble && line[index - 1] !== '\\') {
|
|
96
|
+
inSingle = !inSingle;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (current === '"' && !inSingle && line[index - 1] !== '\\') {
|
|
100
|
+
inDouble = !inDouble;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (current === '#' && !inSingle && !inDouble) {
|
|
104
|
+
return line.slice(0, index);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return line;
|
|
108
|
+
}
|
|
109
|
+
function countRegexMatches(value, regex) {
|
|
110
|
+
const matches = value.match(regex);
|
|
111
|
+
return matches ? matches.length : 0;
|
|
112
|
+
}
|
|
113
|
+
function isTypeScriptBranchNode(node) {
|
|
114
|
+
return ts.isIfStatement(node) ||
|
|
115
|
+
ts.isWhileStatement(node) ||
|
|
116
|
+
ts.isForStatement(node) ||
|
|
117
|
+
ts.isForInStatement(node) ||
|
|
118
|
+
ts.isForOfStatement(node) ||
|
|
119
|
+
ts.isCaseClause(node) ||
|
|
120
|
+
ts.isCatchClause(node) ||
|
|
121
|
+
ts.isConditionalExpression(node) ||
|
|
122
|
+
ts.isSwitchStatement(node) ||
|
|
123
|
+
ts.isTryStatement(node);
|
|
124
|
+
}
|
|
125
|
+
function measureTypeScriptComplexity(node) {
|
|
126
|
+
let branches = 0;
|
|
127
|
+
let maxDepth = 0;
|
|
128
|
+
const visit = (current, depth) => {
|
|
129
|
+
const isBranch = isTypeScriptBranchNode(current);
|
|
130
|
+
if (ts.isIfStatement(current) ||
|
|
131
|
+
ts.isWhileStatement(current) ||
|
|
132
|
+
ts.isForStatement(current) ||
|
|
133
|
+
ts.isForInStatement(current) ||
|
|
134
|
+
ts.isForOfStatement(current) ||
|
|
135
|
+
ts.isCaseClause(current) ||
|
|
136
|
+
ts.isCatchClause(current) ||
|
|
137
|
+
ts.isConditionalExpression(current)) {
|
|
138
|
+
branches++;
|
|
139
|
+
}
|
|
140
|
+
if (ts.isBinaryExpression(current)) {
|
|
141
|
+
const operator = current.operatorToken.kind;
|
|
142
|
+
if (operator === ts.SyntaxKind.AmpersandAmpersandToken ||
|
|
143
|
+
operator === ts.SyntaxKind.BarBarToken) {
|
|
144
|
+
branches++;
|
|
52
145
|
}
|
|
53
146
|
}
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
ts.isForOfStatement(node) || ts.isSwitchStatement(node) ||
|
|
58
|
-
ts.isTryStatement(node)) {
|
|
59
|
-
currentDepth = context.depth + 1;
|
|
60
|
-
maxDepth = Math.max(maxDepth, currentDepth);
|
|
147
|
+
const nextDepth = isBranch ? depth + 1 : depth;
|
|
148
|
+
if (isBranch) {
|
|
149
|
+
maxDepth = Math.max(maxDepth, nextDepth);
|
|
61
150
|
}
|
|
62
|
-
|
|
151
|
+
ts.forEachChild(current, (child) => visit(child, nextDepth));
|
|
152
|
+
};
|
|
153
|
+
visit(node, 0);
|
|
154
|
+
const cyclomatic = branches + 1;
|
|
155
|
+
return {
|
|
156
|
+
cyclomatic,
|
|
157
|
+
cognitive: cyclomatic + maxDepth * 2,
|
|
158
|
+
nestingDepth: maxDepth,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function analyzeTypeScriptFile(filePath, sourceCode) {
|
|
162
|
+
const sourceFile = ts.createSourceFile(path.basename(filePath), sourceCode, ts.ScriptTarget.Latest, true);
|
|
163
|
+
const functionDetails = [];
|
|
164
|
+
let classCount = 0;
|
|
165
|
+
const collect = (node) => {
|
|
63
166
|
if (ts.isClassDeclaration(node)) {
|
|
64
167
|
classCount++;
|
|
65
168
|
}
|
|
66
|
-
// 递归遍历子节点
|
|
67
|
-
ts.forEachChild(node, child => {
|
|
68
|
-
visit(child, {
|
|
69
|
-
depth: currentDepth,
|
|
70
|
-
inFunction: currentFunction,
|
|
71
|
-
functionName,
|
|
72
|
-
functionKind,
|
|
73
|
-
functionStart
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
// 在函数结束时记录复杂度
|
|
77
|
-
if (currentFunction && (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node))) {
|
|
78
|
-
const endLine = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
79
|
-
functionDetails.push({
|
|
80
|
-
name: functionName,
|
|
81
|
-
kind: functionKind,
|
|
82
|
-
line: functionStart.line + 1,
|
|
83
|
-
column: functionStart.character + 1,
|
|
84
|
-
cyclomatic,
|
|
85
|
-
cognitive: cyclomatic + maxDepth * 2, // 认知复杂度考虑嵌套深度
|
|
86
|
-
nestingDepth: maxDepth,
|
|
87
|
-
isHighComplexity: cyclomatic >= HIGH_COMPLEXITY_THRESHOLD
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// 先收集所有函数信息,然后计算文件级别的复杂度
|
|
92
|
-
const allFunctions = [];
|
|
93
|
-
function collectFunctions(node) {
|
|
94
169
|
if (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node)) {
|
|
170
|
+
const position = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
171
|
+
const metrics = measureTypeScriptComplexity(node);
|
|
95
172
|
const name = node.name?.getText(sourceFile) || '<anonymous>';
|
|
96
|
-
|
|
97
|
-
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
98
|
-
let cyclomatic = 1;
|
|
99
|
-
let maxDepth = 0;
|
|
100
|
-
// 统计函数内的控制流
|
|
101
|
-
function countControlFlow(n, depth) {
|
|
102
|
-
if (ts.isIfStatement(n) || ts.isWhileStatement(n) ||
|
|
103
|
-
ts.isForStatement(n) || ts.isForInStatement(n) ||
|
|
104
|
-
ts.isForOfStatement(n) || ts.isCaseClause(n) ||
|
|
105
|
-
ts.isCatchClause(n)) {
|
|
106
|
-
cyclomatic++;
|
|
107
|
-
}
|
|
108
|
-
if (ts.isConditionalExpression(n)) {
|
|
109
|
-
cyclomatic++;
|
|
110
|
-
}
|
|
111
|
-
if (ts.isBinaryExpression(n)) {
|
|
112
|
-
const operator = n.operatorToken.kind;
|
|
113
|
-
if (operator === ts.SyntaxKind.AmpersandAmpersandToken ||
|
|
114
|
-
operator === ts.SyntaxKind.BarBarToken) {
|
|
115
|
-
cyclomatic++;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (ts.isIfStatement(n) || ts.isWhileStatement(n) ||
|
|
119
|
-
ts.isForStatement(n) || ts.isForInStatement(n) ||
|
|
120
|
-
ts.isForOfStatement(n) || ts.isSwitchStatement(n) ||
|
|
121
|
-
ts.isTryStatement(n)) {
|
|
122
|
-
maxDepth = Math.max(maxDepth, depth + 1);
|
|
123
|
-
}
|
|
124
|
-
ts.forEachChild(n, child => countControlFlow(child, ts.isBlock(n) ? depth : depth + (ts.isIfStatement(n) || ts.isWhileStatement(n) || ts.isForStatement(n) ? 1 : 0)));
|
|
125
|
-
}
|
|
126
|
-
countControlFlow(node, 0);
|
|
127
|
-
allFunctions.push({
|
|
173
|
+
functionDetails.push({
|
|
128
174
|
name,
|
|
129
|
-
kind
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
175
|
+
kind: ts.isConstructorDeclaration(node)
|
|
176
|
+
? 'constructor'
|
|
177
|
+
: ts.isMethodDeclaration(node)
|
|
178
|
+
? 'method'
|
|
179
|
+
: 'function',
|
|
180
|
+
line: position.line + 1,
|
|
181
|
+
cyclomatic: metrics.cyclomatic,
|
|
182
|
+
cognitive: metrics.cognitive,
|
|
183
|
+
lines: sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line - position.line + 1,
|
|
184
|
+
nestingDepth: metrics.nestingDepth,
|
|
134
185
|
});
|
|
135
186
|
}
|
|
136
|
-
ts.forEachChild(node,
|
|
187
|
+
ts.forEachChild(node, collect);
|
|
188
|
+
};
|
|
189
|
+
collect(sourceFile);
|
|
190
|
+
const fileMetrics = measureTypeScriptComplexity(sourceFile);
|
|
191
|
+
const lines = countLines(sourceCode);
|
|
192
|
+
const commentRatio = countCommentLines(sourceCode, 'typescript') / Math.max(1, lines);
|
|
193
|
+
return buildFileComplexity(filePath, lines, classCount, functionDetails, fileMetrics.cyclomatic, fileMetrics.cognitive, calculateMaintainabilityIndex(lines, fileMetrics.cyclomatic, commentRatio));
|
|
194
|
+
}
|
|
195
|
+
function countPythonBranchTokens(line) {
|
|
196
|
+
let branches = countRegexMatches(line, /\b(if|elif|for|while|except|assert)\b/g);
|
|
197
|
+
branches += countRegexMatches(line, /\b(and|or)\b/g);
|
|
198
|
+
if (/\bif\b.+\belse\b/.test(line)) {
|
|
199
|
+
branches++;
|
|
137
200
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
201
|
+
return branches;
|
|
202
|
+
}
|
|
203
|
+
function countPythonClasses(content) {
|
|
204
|
+
return content
|
|
205
|
+
.split('\n')
|
|
206
|
+
.filter((line) => /^\s*class\s+\w+/.test(stripPythonInlineComment(line)))
|
|
207
|
+
.length;
|
|
208
|
+
}
|
|
209
|
+
function analyzePythonFile(filePath, content) {
|
|
210
|
+
const lines = content.split('\n');
|
|
211
|
+
const classStack = [];
|
|
212
|
+
const functionStack = [];
|
|
213
|
+
const functionDetails = [];
|
|
214
|
+
let fileBranches = 0;
|
|
215
|
+
let fileMaxDepth = 0;
|
|
216
|
+
const finalizeFunctions = (indent, lineNumber) => {
|
|
217
|
+
while (functionStack.length > 0 && indent <= functionStack[functionStack.length - 1].indent) {
|
|
218
|
+
const current = functionStack.pop();
|
|
219
|
+
functionDetails.push({
|
|
220
|
+
name: current.qualifiedName,
|
|
221
|
+
kind: current.kind,
|
|
222
|
+
line: current.startLine,
|
|
223
|
+
cyclomatic: current.branchCount + 1,
|
|
224
|
+
cognitive: current.branchCount + 1 + current.maxDepth * 2,
|
|
225
|
+
lines: Math.max(1, lineNumber - current.startLine),
|
|
226
|
+
nestingDepth: current.maxDepth,
|
|
227
|
+
});
|
|
144
228
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (ts.isIfStatement(n) || ts.isWhileStatement(n) ||
|
|
152
|
-
ts.isForStatement(n) || ts.isForInStatement(n) ||
|
|
153
|
-
ts.isForOfStatement(n) || ts.isCatchClause(n)) {
|
|
154
|
-
fileCyclomatic++;
|
|
229
|
+
};
|
|
230
|
+
lines.forEach((rawLine, index) => {
|
|
231
|
+
const line = stripPythonInlineComment(rawLine);
|
|
232
|
+
const trimmed = line.trim();
|
|
233
|
+
if (trimmed.length === 0) {
|
|
234
|
+
return;
|
|
155
235
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
236
|
+
const indent = normalizeIndent(rawLine);
|
|
237
|
+
finalizeFunctions(indent, index + 1);
|
|
238
|
+
while (classStack.length > 0 && indent <= classStack[classStack.length - 1].indent) {
|
|
239
|
+
classStack.pop();
|
|
159
240
|
}
|
|
160
|
-
|
|
161
|
-
if (
|
|
162
|
-
|
|
241
|
+
const classMatch = trimmed.match(/^class\s+([A-Za-z_]\w*)/);
|
|
242
|
+
if (classMatch) {
|
|
243
|
+
classStack.push({ indent, name: classMatch[1] });
|
|
244
|
+
return;
|
|
163
245
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
246
|
+
const functionMatch = trimmed.match(/^(?:async\s+)?def\s+([A-Za-z_]\w*)\s*\(/);
|
|
247
|
+
if (functionMatch) {
|
|
248
|
+
const currentClass = classStack[classStack.length - 1];
|
|
249
|
+
const currentFunction = functionStack[functionStack.length - 1];
|
|
250
|
+
const isMethod = Boolean(currentClass && (!currentFunction || currentClass.indent >= currentFunction.indent));
|
|
251
|
+
const name = functionMatch[1];
|
|
252
|
+
functionStack.push({
|
|
253
|
+
indent,
|
|
254
|
+
startLine: index + 1,
|
|
255
|
+
name,
|
|
256
|
+
qualifiedName: isMethod ? `${currentClass.name}.${name}` : name,
|
|
257
|
+
kind: isMethod ? 'method' : 'function',
|
|
258
|
+
branchCount: 0,
|
|
259
|
+
maxDepth: 0,
|
|
260
|
+
});
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const branches = countPythonBranchTokens(trimmed);
|
|
264
|
+
if (branches === 0) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
fileBranches += branches;
|
|
268
|
+
const fileDepth = Math.floor(indent / 4) + 1;
|
|
269
|
+
fileMaxDepth = Math.max(fileMaxDepth, fileDepth);
|
|
270
|
+
const currentFunction = functionStack[functionStack.length - 1];
|
|
271
|
+
if (!currentFunction) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
currentFunction.branchCount += branches;
|
|
275
|
+
const relativeDepth = Math.max(1, Math.floor(Math.max(0, indent - currentFunction.indent - 4) / 4) + 1);
|
|
276
|
+
currentFunction.maxDepth = Math.max(currentFunction.maxDepth, relativeDepth);
|
|
277
|
+
});
|
|
278
|
+
finalizeFunctions(-1, lines.length + 1);
|
|
279
|
+
const totalLines = countLines(content);
|
|
280
|
+
const commentRatio = countCommentLines(content, 'python') / Math.max(1, totalLines);
|
|
281
|
+
const cyclomatic = fileBranches + 1;
|
|
282
|
+
return buildFileComplexity(filePath, totalLines, countPythonClasses(content), functionDetails, cyclomatic, cyclomatic + fileMaxDepth * 2, calculateMaintainabilityIndex(totalLines, cyclomatic, commentRatio));
|
|
283
|
+
}
|
|
284
|
+
function findMatchingBrace(content, openBraceIndex) {
|
|
285
|
+
let depth = 0;
|
|
286
|
+
for (let index = openBraceIndex; index < content.length; index++) {
|
|
287
|
+
const current = content[index];
|
|
288
|
+
if (current === '{') {
|
|
289
|
+
depth++;
|
|
290
|
+
}
|
|
291
|
+
else if (current === '}') {
|
|
292
|
+
depth--;
|
|
293
|
+
if (depth === 0) {
|
|
294
|
+
return index;
|
|
169
295
|
}
|
|
170
296
|
}
|
|
171
|
-
ts.forEachChild(n, countFileControlFlow);
|
|
172
297
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
298
|
+
return content.length - 1;
|
|
299
|
+
}
|
|
300
|
+
function getLineNumber(content, index) {
|
|
301
|
+
return content.slice(0, index).split('\n').length;
|
|
302
|
+
}
|
|
303
|
+
function countGoBranchTokens(line) {
|
|
304
|
+
let branches = countRegexMatches(line, /\b(if|for|switch|case|select)\b/g);
|
|
305
|
+
branches += countRegexMatches(line, /&&|\|\|/g);
|
|
306
|
+
return branches;
|
|
307
|
+
}
|
|
308
|
+
function extractGoFunctions(content) {
|
|
309
|
+
const functions = [];
|
|
310
|
+
const functionRegex = /func\s+(?:\([^)]+\)\s+)?([A-Za-z_]\w*)\s*\([^)]*\)\s*[^{]*\{/g;
|
|
311
|
+
let match;
|
|
312
|
+
while ((match = functionRegex.exec(content)) !== null) {
|
|
313
|
+
const name = match[1];
|
|
314
|
+
const braceIndex = content.indexOf('{', match.index);
|
|
315
|
+
if (!name || braceIndex === -1) {
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
functions.push({
|
|
319
|
+
name,
|
|
320
|
+
startLine: getLineNumber(content, match.index),
|
|
321
|
+
startOffset: braceIndex,
|
|
322
|
+
endOffset: findMatchingBrace(content, braceIndex),
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return functions;
|
|
326
|
+
}
|
|
327
|
+
function measureGoFunctionComplexity(content, range) {
|
|
328
|
+
const body = content.slice(range.startOffset + 1, range.endOffset);
|
|
329
|
+
const lines = body.split('\n');
|
|
330
|
+
let branchCount = 0;
|
|
331
|
+
let maxDepth = 0;
|
|
332
|
+
let braceDepth = 0;
|
|
333
|
+
for (const rawLine of lines) {
|
|
334
|
+
const trimmed = rawLine.trim();
|
|
335
|
+
if (!trimmed) {
|
|
336
|
+
braceDepth += countRegexMatches(rawLine, /{/g) - countRegexMatches(rawLine, /}/g);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const branches = countGoBranchTokens(trimmed);
|
|
340
|
+
if (branches > 0) {
|
|
341
|
+
branchCount += branches;
|
|
342
|
+
maxDepth = Math.max(maxDepth, braceDepth + 1);
|
|
182
343
|
}
|
|
183
|
-
|
|
344
|
+
braceDepth += countRegexMatches(rawLine, /{/g) - countRegexMatches(rawLine, /}/g);
|
|
184
345
|
}
|
|
185
|
-
|
|
186
|
-
const fileCognitive = fileCyclomatic + maxNesting * 2;
|
|
187
|
-
// 计算可维护性指数
|
|
188
|
-
const lines = sourceCode.split('\n').length;
|
|
189
|
-
const commentLines = sourceCode.split('\n').filter(line => line.trim().startsWith('//') || line.trim().startsWith('/*') || line.trim().startsWith('*')).length;
|
|
190
|
-
const commentRatio = commentLines / Math.max(1, lines);
|
|
191
|
-
const maintainability = calculateMaintainabilityIndex(lines, fileCyclomatic, commentRatio);
|
|
346
|
+
const cyclomatic = branchCount + 1;
|
|
192
347
|
return {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
lines,
|
|
201
|
-
functionDetails: allFunctions.map(f => ({
|
|
202
|
-
name: f.name,
|
|
203
|
-
kind: f.kind,
|
|
204
|
-
line: f.line,
|
|
205
|
-
column: 1,
|
|
206
|
-
cyclomatic: f.cyclomatic,
|
|
207
|
-
cognitive: f.cognitive,
|
|
208
|
-
nestingDepth: f.nestingDepth,
|
|
209
|
-
isHighComplexity: f.cyclomatic >= HIGH_COMPLEXITY_THRESHOLD
|
|
210
|
-
}))
|
|
348
|
+
name: range.name,
|
|
349
|
+
kind: 'function',
|
|
350
|
+
line: range.startLine,
|
|
351
|
+
cyclomatic,
|
|
352
|
+
cognitive: cyclomatic + maxDepth * 2,
|
|
353
|
+
lines: Math.max(1, body.split('\n').length),
|
|
354
|
+
nestingDepth: maxDepth,
|
|
211
355
|
};
|
|
212
356
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
357
|
+
function analyzeGoFile(filePath, content) {
|
|
358
|
+
const functionRanges = extractGoFunctions(content);
|
|
359
|
+
const functionDetails = functionRanges.map((range) => measureGoFunctionComplexity(content, range));
|
|
360
|
+
const totalLines = countLines(content);
|
|
361
|
+
const commentRatio = countCommentLines(content, 'go') / Math.max(1, totalLines);
|
|
362
|
+
const totalBranches = countRegexMatches(content, /\b(if|for|switch|case|select)\b/g) + countRegexMatches(content, /&&|\|\|/g);
|
|
363
|
+
const maxDepth = functionDetails.reduce((highest, detail) => Math.max(highest, detail.nestingDepth), 0);
|
|
364
|
+
const cyclomatic = totalBranches + 1;
|
|
365
|
+
return buildFileComplexity(filePath, totalLines, 0, functionDetails, cyclomatic, cyclomatic + maxDepth * 2, calculateMaintainabilityIndex(totalLines, cyclomatic, commentRatio));
|
|
366
|
+
}
|
|
367
|
+
export function analyzeFileComplexityFromContent(input) {
|
|
368
|
+
switch (input.language) {
|
|
369
|
+
case 'typescript':
|
|
370
|
+
case 'javascript':
|
|
371
|
+
return analyzeTypeScriptFile(input.filePath, input.content);
|
|
372
|
+
case 'python':
|
|
373
|
+
return analyzePythonFile(input.filePath, input.content);
|
|
374
|
+
case 'go':
|
|
375
|
+
return analyzeGoFile(input.filePath, input.content);
|
|
376
|
+
default: {
|
|
377
|
+
const exhaustiveCheck = input.language;
|
|
378
|
+
throw new Error(`不支持的 complexity 语言: ${exhaustiveCheck}`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
export function analyzeComplexityFromContent(input) {
|
|
383
|
+
return toComplexityMetrics(analyzeFileComplexityFromContent(input));
|
|
224
384
|
}
|
|
225
|
-
/**
|
|
226
|
-
* 分析文件复杂度(公开 API)
|
|
227
|
-
*/
|
|
228
385
|
export function analyzeFileComplexity(filePath) {
|
|
229
386
|
if (!fs.existsSync(filePath)) {
|
|
230
387
|
throw new Error(`文件不存在: ${filePath}`);
|
|
231
388
|
}
|
|
232
389
|
const sourceCode = fs.readFileSync(filePath, 'utf-8');
|
|
233
|
-
|
|
390
|
+
const language = detectLanguageFromFilePath(filePath);
|
|
391
|
+
return analyzeFileComplexityFromContent({
|
|
392
|
+
filePath,
|
|
393
|
+
content: sourceCode,
|
|
394
|
+
language,
|
|
395
|
+
});
|
|
234
396
|
}
|
|
235
|
-
/**
|
|
236
|
-
* 分析多个文件复杂度(公开 API)
|
|
237
|
-
*/
|
|
238
397
|
export function analyzeMultipleFiles(filePaths, rootDir) {
|
|
239
398
|
const files = [];
|
|
240
399
|
for (const filePath of filePaths) {
|
|
@@ -257,14 +416,14 @@ export function analyzeMultipleFiles(filePaths, rootDir) {
|
|
|
257
416
|
averageCyclomatic: 0,
|
|
258
417
|
averageCognitive: 0,
|
|
259
418
|
averageMaintainability: 0,
|
|
260
|
-
highComplexityFunctions: 0
|
|
261
|
-
}
|
|
419
|
+
highComplexityFunctions: 0,
|
|
420
|
+
},
|
|
262
421
|
};
|
|
263
422
|
}
|
|
264
|
-
const totalCyclomatic = files.reduce((sum,
|
|
265
|
-
const totalCognitive = files.reduce((sum,
|
|
266
|
-
const totalMaintainability = files.reduce((sum,
|
|
267
|
-
const highComplexityFunctions = files.reduce((sum,
|
|
423
|
+
const totalCyclomatic = files.reduce((sum, file) => sum + file.cyclomatic, 0);
|
|
424
|
+
const totalCognitive = files.reduce((sum, file) => sum + file.cognitive, 0);
|
|
425
|
+
const totalMaintainability = files.reduce((sum, file) => sum + file.maintainability, 0);
|
|
426
|
+
const highComplexityFunctions = files.reduce((sum, file) => sum + file.functionDetails.filter((detail) => detail.isHighComplexity).length, 0);
|
|
268
427
|
return {
|
|
269
428
|
files,
|
|
270
429
|
summary: {
|
|
@@ -272,8 +431,8 @@ export function analyzeMultipleFiles(filePaths, rootDir) {
|
|
|
272
431
|
averageCyclomatic: Math.round(totalCyclomatic / files.length),
|
|
273
432
|
averageCognitive: Math.round(totalCognitive / files.length),
|
|
274
433
|
averageMaintainability: Math.round(totalMaintainability / files.length),
|
|
275
|
-
highComplexityFunctions
|
|
276
|
-
}
|
|
434
|
+
highComplexityFunctions,
|
|
435
|
+
},
|
|
277
436
|
};
|
|
278
437
|
}
|
|
279
438
|
//# sourceMappingURL=ast-complexity-analyzer.js.map
|