@mycodemap/mycodemap 0.4.1 → 0.5.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 +100 -0
- package/README.md +307 -243
- package/dist/ai/claude.d.ts +38 -0
- package/dist/ai/claude.d.ts.map +1 -0
- package/dist/ai/claude.js +169 -0
- package/dist/ai/claude.js.map +1 -0
- package/dist/ai/codex.d.ts +38 -0
- package/dist/ai/codex.d.ts.map +1 -0
- package/dist/ai/codex.js +169 -0
- package/dist/ai/codex.js.map +1 -0
- package/dist/ai/factory.d.ts +48 -0
- package/dist/ai/factory.d.ts.map +1 -0
- package/dist/ai/factory.js +95 -0
- package/dist/ai/factory.js.map +1 -0
- package/dist/ai/index.d.ts +12 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +29 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/provider.d.ts +70 -0
- package/dist/ai/provider.d.ts.map +1 -0
- package/dist/ai/provider.js +31 -0
- package/dist/ai/provider.js.map +1 -0
- package/dist/ai/subagent-caller.d.ts +90 -0
- package/dist/ai/subagent-caller.d.ts.map +1 -0
- package/dist/ai/subagent-caller.js +280 -0
- package/dist/ai/subagent-caller.js.map +1 -0
- package/dist/ai/types.d.ts +70 -0
- package/dist/ai/types.d.ts.map +1 -0
- package/dist/ai/types.js +5 -0
- package/dist/ai/types.js.map +1 -0
- package/dist/cli/commands/analyze-options.d.ts +36 -0
- package/dist/cli/commands/analyze-options.d.ts.map +1 -0
- package/dist/cli/commands/analyze-options.js +147 -0
- package/dist/cli/commands/analyze-options.js.map +1 -0
- package/dist/cli/commands/analyze.d.ts +93 -4
- package/dist/cli/commands/analyze.d.ts.map +1 -1
- package/dist/cli/commands/analyze.js +592 -176
- package/dist/cli/commands/analyze.js.map +1 -1
- package/dist/cli/commands/ci.d.ts +47 -1
- package/dist/cli/commands/ci.d.ts.map +1 -1
- package/dist/cli/commands/ci.js +208 -1
- package/dist/cli/commands/ci.js.map +1 -1
- package/dist/cli/commands/design.d.ts +47 -0
- package/dist/cli/commands/design.d.ts.map +1 -0
- package/dist/cli/commands/design.js +268 -0
- package/dist/cli/commands/design.js.map +1 -0
- package/dist/cli/commands/export.d.ts.map +1 -1
- package/dist/cli/commands/export.js +2 -2
- package/dist/cli/commands/export.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +8 -2
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +151 -22
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +2 -13
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/server.d.ts.map +1 -1
- package/dist/cli/commands/server.js +2 -5
- package/dist/cli/commands/server.js.map +1 -1
- package/dist/cli/commands/ship/checker.d.ts.map +1 -1
- package/dist/cli/commands/ship/checker.js +0 -3
- package/dist/cli/commands/ship/checker.js.map +1 -1
- package/dist/cli/commands/ship/pipeline.d.ts.map +1 -1
- package/dist/cli/commands/ship/pipeline.js +8 -1
- package/dist/cli/commands/ship/pipeline.js.map +1 -1
- package/dist/cli/commands/ship/publisher.d.ts +9 -1
- package/dist/cli/commands/ship/publisher.d.ts.map +1 -1
- package/dist/cli/commands/ship/publisher.js +149 -6
- package/dist/cli/commands/ship/publisher.js.map +1 -1
- package/dist/cli/commands/ship/rules/quality-rules.d.ts +0 -1
- package/dist/cli/commands/ship/rules/quality-rules.d.ts.map +1 -1
- package/dist/cli/commands/ship/rules/quality-rules.js +4 -76
- package/dist/cli/commands/ship/rules/quality-rules.js.map +1 -1
- package/dist/cli/commands/workflow.js +4 -4
- package/dist/cli/commands/workflow.js.map +1 -1
- package/dist/cli/config-loader.d.ts +31 -0
- package/dist/cli/config-loader.d.ts.map +1 -0
- package/dist/cli/config-loader.js +235 -0
- package/dist/cli/config-loader.js.map +1 -0
- package/dist/cli/design-contract-loader.d.ts +15 -0
- package/dist/cli/design-contract-loader.d.ts.map +1 -0
- package/dist/cli/design-contract-loader.js +175 -0
- package/dist/cli/design-contract-loader.js.map +1 -0
- package/dist/cli/design-contract-schema.d.ts +11 -0
- package/dist/cli/design-contract-schema.d.ts.map +1 -0
- package/dist/cli/design-contract-schema.js +75 -0
- package/dist/cli/design-contract-schema.js.map +1 -0
- package/dist/cli/design-handoff-builder.d.ts +15 -0
- package/dist/cli/design-handoff-builder.d.ts.map +1 -0
- package/dist/cli/design-handoff-builder.js +345 -0
- package/dist/cli/design-handoff-builder.js.map +1 -0
- package/dist/cli/design-scope-resolver.d.ts +8 -0
- package/dist/cli/design-scope-resolver.d.ts.map +1 -0
- package/dist/cli/design-scope-resolver.js +712 -0
- package/dist/cli/design-scope-resolver.js.map +1 -0
- package/dist/cli/design-verification-builder.d.ts +8 -0
- package/dist/cli/design-verification-builder.d.ts.map +1 -0
- package/dist/cli/design-verification-builder.js +369 -0
- package/dist/cli/design-verification-builder.js.map +1 -0
- package/dist/cli/index.js +20 -63
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/removed-commands.d.ts +9 -0
- package/dist/cli/removed-commands.d.ts.map +1 -0
- package/dist/cli/removed-commands.js +48 -0
- package/dist/cli/removed-commands.js.map +1 -0
- package/dist/cli/storage-runtime.d.ts +8 -0
- package/dist/cli/storage-runtime.d.ts.map +1 -0
- package/dist/cli/storage-runtime.js +14 -0
- package/dist/cli/storage-runtime.js.map +1 -0
- package/dist/cli/tree-sitter-check.d.ts.map +1 -1
- package/dist/cli/tree-sitter-check.js +0 -1
- package/dist/cli/tree-sitter-check.js.map +1 -1
- package/dist/cli-new/commands/export.d.ts.map +1 -1
- package/dist/cli-new/commands/export.js +2 -2
- package/dist/cli-new/commands/export.js.map +1 -1
- package/dist/cli-new/commands/query.d.ts.map +1 -1
- package/dist/cli-new/commands/query.js +5 -4
- package/dist/cli-new/commands/query.js.map +1 -1
- package/dist/cli-new/commands/server.d.ts.map +1 -1
- package/dist/cli-new/commands/server.js +2 -6
- package/dist/cli-new/commands/server.js.map +1 -1
- package/dist/cli-new/index.d.ts.map +1 -1
- package/dist/cli-new/index.js +0 -2
- package/dist/cli-new/index.js.map +1 -1
- package/dist/core/analyzer.d.ts.map +1 -1
- package/dist/core/analyzer.js +7 -39
- package/dist/core/analyzer.js.map +1 -1
- package/dist/core/file-discovery.d.ts +17 -0
- package/dist/core/file-discovery.d.ts.map +1 -0
- package/dist/core/file-discovery.js +75 -0
- package/dist/core/file-discovery.js.map +1 -0
- package/dist/core/global-index.d.ts +5 -0
- package/dist/core/global-index.d.ts.map +1 -1
- package/dist/core/global-index.js +71 -21
- package/dist/core/global-index.js.map +1 -1
- package/dist/generator/ai-overview.d.ts +51 -0
- package/dist/generator/ai-overview.d.ts.map +1 -0
- package/dist/generator/ai-overview.js +160 -0
- package/dist/generator/ai-overview.js.map +1 -0
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +8 -0
- package/dist/generator/index.js.map +1 -1
- package/dist/infrastructure/parser/implementations/GoParser.d.ts +2 -5
- package/dist/infrastructure/parser/implementations/GoParser.d.ts.map +1 -1
- package/dist/infrastructure/parser/implementations/GoParser.js +2 -5
- package/dist/infrastructure/parser/implementations/GoParser.js.map +1 -1
- package/dist/infrastructure/parser/implementations/PythonParser.d.ts +1 -5
- package/dist/infrastructure/parser/implementations/PythonParser.d.ts.map +1 -1
- package/dist/infrastructure/parser/implementations/PythonParser.js +1 -5
- package/dist/infrastructure/parser/implementations/PythonParser.js.map +1 -1
- package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts +1 -5
- package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts.map +1 -1
- package/dist/infrastructure/parser/implementations/TypeScriptParser.js +1 -5
- package/dist/infrastructure/parser/implementations/TypeScriptParser.js.map +1 -1
- package/dist/infrastructure/storage/StorageFactory.d.ts +12 -6
- package/dist/infrastructure/storage/StorageFactory.d.ts.map +1 -1
- package/dist/infrastructure/storage/StorageFactory.js +59 -43
- package/dist/infrastructure/storage/StorageFactory.js.map +1 -1
- package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/FileSystemStorage.js +24 -137
- package/dist/infrastructure/storage/adapters/FileSystemStorage.js.map +1 -1
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts +10 -18
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.js +103 -146
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.js.map +1 -1
- package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts +0 -1
- package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/MemoryStorage.js +16 -136
- package/dist/infrastructure/storage/adapters/MemoryStorage.js.map +1 -1
- package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts +9 -17
- package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/Neo4jStorage.js +78 -138
- package/dist/infrastructure/storage/adapters/Neo4jStorage.js.map +1 -1
- package/dist/infrastructure/storage/graph-helpers.d.ts +16 -0
- package/dist/infrastructure/storage/graph-helpers.d.ts.map +1 -0
- package/dist/infrastructure/storage/graph-helpers.js +161 -0
- package/dist/infrastructure/storage/graph-helpers.js.map +1 -0
- package/dist/infrastructure/storage/index.d.ts.map +1 -1
- package/dist/interface/config/index.d.ts +10 -1
- package/dist/interface/config/index.d.ts.map +1 -1
- package/dist/interface/types/design-contract.d.ts +68 -0
- package/dist/interface/types/design-contract.d.ts.map +1 -0
- package/dist/interface/types/design-contract.js +7 -0
- package/dist/interface/types/design-contract.js.map +1 -0
- package/dist/interface/types/design-handoff.d.ts +68 -0
- package/dist/interface/types/design-handoff.d.ts.map +1 -0
- package/dist/interface/types/design-handoff.js +4 -0
- package/dist/interface/types/design-handoff.js.map +1 -0
- package/dist/interface/types/design-mapping.d.ts +51 -0
- package/dist/interface/types/design-mapping.d.ts.map +1 -0
- package/dist/interface/types/design-mapping.js +4 -0
- package/dist/interface/types/design-mapping.js.map +1 -0
- package/dist/interface/types/design-verification.d.ts +49 -0
- package/dist/interface/types/design-verification.d.ts.map +1 -0
- package/dist/interface/types/design-verification.js +4 -0
- package/dist/interface/types/design-verification.js.map +1 -0
- package/dist/interface/types/index.d.ts +17 -0
- package/dist/interface/types/index.d.ts.map +1 -1
- package/dist/interface/types/storage.d.ts +1 -4
- package/dist/interface/types/storage.d.ts.map +1 -1
- package/dist/orchestrator/ai-feed-generator.d.ts +210 -0
- package/dist/orchestrator/ai-feed-generator.d.ts.map +1 -0
- package/dist/orchestrator/ai-feed-generator.js +377 -0
- package/dist/orchestrator/ai-feed-generator.js.map +1 -0
- package/dist/orchestrator/confidence.d.ts +9 -9
- package/dist/orchestrator/confidence.d.ts.map +1 -1
- package/dist/orchestrator/confidence.js +44 -67
- package/dist/orchestrator/confidence.js.map +1 -1
- package/dist/orchestrator/file-header-scanner.d.ts.map +1 -1
- package/dist/orchestrator/file-header-scanner.js +22 -31
- package/dist/orchestrator/file-header-scanner.js.map +1 -1
- package/dist/orchestrator/intent-router.d.ts +2 -11
- package/dist/orchestrator/intent-router.d.ts.map +1 -1
- package/dist/orchestrator/intent-router.js +58 -49
- package/dist/orchestrator/intent-router.js.map +1 -1
- package/dist/orchestrator/tool-orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/tool-orchestrator.js +6 -4
- package/dist/orchestrator/tool-orchestrator.js.map +1 -1
- package/dist/orchestrator/types.d.ts +113 -2
- package/dist/orchestrator/types.d.ts.map +1 -1
- package/dist/orchestrator/types.js +29 -0
- package/dist/orchestrator/types.js.map +1 -1
- package/dist/orchestrator/workflow/config.d.ts +4 -12
- package/dist/orchestrator/workflow/config.d.ts.map +1 -1
- package/dist/orchestrator/workflow/config.js +4 -6
- package/dist/orchestrator/workflow/config.js.map +1 -1
- package/dist/orchestrator/workflow/git-analyzer.d.ts.map +1 -1
- package/dist/orchestrator/workflow/git-analyzer.js +9 -19
- package/dist/orchestrator/workflow/git-analyzer.js.map +1 -1
- package/dist/orchestrator/workflow/phase-inheritance.d.ts.map +1 -1
- package/dist/orchestrator/workflow/phase-inheritance.js +14 -23
- package/dist/orchestrator/workflow/phase-inheritance.js.map +1 -1
- package/dist/orchestrator/workflow/result-fusion.d.ts.map +1 -1
- package/dist/orchestrator/workflow/result-fusion.js +9 -11
- package/dist/orchestrator/workflow/result-fusion.js.map +1 -1
- package/dist/orchestrator/workflow/templates.d.ts +4 -1
- package/dist/orchestrator/workflow/templates.d.ts.map +1 -1
- package/dist/orchestrator/workflow/templates.js +49 -207
- package/dist/orchestrator/workflow/templates.js.map +1 -1
- package/dist/orchestrator/workflow/test-linker.d.ts.map +1 -1
- package/dist/orchestrator/workflow/test-linker.js +12 -24
- package/dist/orchestrator/workflow/test-linker.js.map +1 -1
- package/dist/orchestrator/workflow/types.d.ts +11 -8
- package/dist/orchestrator/workflow/types.d.ts.map +1 -1
- package/dist/orchestrator/workflow/types.js +8 -1
- package/dist/orchestrator/workflow/types.js.map +1 -1
- package/dist/orchestrator/workflow/visualizer.d.ts.map +1 -1
- package/dist/orchestrator/workflow/visualizer.js +7 -9
- package/dist/orchestrator/workflow/visualizer.js.map +1 -1
- package/dist/orchestrator/workflow/workflow-context.d.ts.map +1 -1
- package/dist/orchestrator/workflow/workflow-context.js +3 -5
- package/dist/orchestrator/workflow/workflow-context.js.map +1 -1
- package/dist/orchestrator/workflow/workflow-orchestrator.d.ts +0 -4
- package/dist/orchestrator/workflow/workflow-orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/workflow/workflow-orchestrator.js +7 -99
- package/dist/orchestrator/workflow/workflow-orchestrator.js.map +1 -1
- package/dist/parser/index.d.ts.map +1 -1
- package/dist/parser/index.js +2 -2
- package/dist/parser/index.js.map +1 -1
- package/dist/plugins/index.d.ts +5 -3
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +19 -8
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/plugin-loader.d.ts +21 -6
- package/dist/plugins/plugin-loader.d.ts.map +1 -1
- package/dist/plugins/plugin-loader.js +170 -54
- package/dist/plugins/plugin-loader.js.map +1 -1
- package/dist/plugins/plugin-registry.d.ts +7 -4
- package/dist/plugins/plugin-registry.d.ts.map +1 -1
- package/dist/plugins/plugin-registry.js +62 -14
- package/dist/plugins/plugin-registry.js.map +1 -1
- package/dist/plugins/types.d.ts +16 -6
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/plugins/types.js +2 -0
- package/dist/plugins/types.js.map +1 -1
- package/dist/server/handlers/AnalysisHandler.d.ts +16 -2
- package/dist/server/handlers/AnalysisHandler.d.ts.map +1 -1
- package/dist/server/handlers/AnalysisHandler.js +31 -47
- package/dist/server/handlers/AnalysisHandler.js.map +1 -1
- package/dist/server/routes/api.d.ts.map +1 -1
- package/dist/server/routes/api.js +31 -12
- package/dist/server/routes/api.js.map +1 -1
- package/docs/AI_ASSISTANT_SETUP.md +3 -1
- package/docs/SETUP_GUIDE.md +41 -17
- package/docs/ai-guide/COMMANDS.md +179 -102
- package/docs/ai-guide/INTEGRATION.md +23 -21
- package/docs/ai-guide/OUTPUT.md +621 -10
- package/docs/ai-guide/PATTERNS.md +77 -18
- package/docs/ai-guide/PROMPTS.md +24 -18
- package/docs/ai-guide/QUICKSTART.md +35 -19
- package/docs/ai-guide/README.md +22 -4
- package/docs/archive/test-report-symbol-search.md +384 -0
- package/docs/archive/test-scenario-4-complexity-analysis.md +460 -0
- package/docs/archive/test_report_scenario5.md +615 -0
- package/docs/archive/test_scenario_3_impact_analysis_report.md +520 -0
- package/docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md +79 -0
- package/docs/product-specs/MVP3-ARCHITECTURE-COMPARISON.md +159 -434
- package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-PRD.md +169 -261
- package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-TECH-PRD.md +201 -1259
- package/docs/product-specs/README.md +9 -1
- package/docs/rules/architecture-guardrails.md +1 -2
- package/docs/rules/engineering-with-codex-openai.md +20 -10
- package/docs/rules/validation.md +29 -4
- package/mycodemap.config.schema.json +76 -5
- package/package.json +1 -1
- package/scripts/experiments/arcadedb-http-smoke.mjs +90 -0
- package/scripts/sync-analyze-docs.js +500 -0
- package/scripts/validate-ai-docs.js +54 -1
- package/scripts/validate-docs.js +992 -25
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
# 测试场景 4: 代码复杂度分析测试报告
|
|
2
|
+
|
|
3
|
+
## 测试目标
|
|
4
|
+
测试 `codemap complexity` 功能的有效性和实用性,验证其计算准确性、输出质量和实际开发中的价值。
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 测试环境
|
|
9
|
+
- **CodeMap 版本**: 0.1.0
|
|
10
|
+
- **测试目录**: /data/codemap
|
|
11
|
+
- **项目规模**: 104 个 TypeScript 文件,28,878 行代码
|
|
12
|
+
- **测试时间**: 2026-03-01
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 测试用例 1: 分析整个项目复杂度
|
|
17
|
+
|
|
18
|
+
### CodeMap 执行
|
|
19
|
+
```bash
|
|
20
|
+
time npx codemap complexity
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**输出:**
|
|
24
|
+
```
|
|
25
|
+
📊 项目复杂度分析
|
|
26
|
+
──────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
🔥 复杂度最高的文件 (Top 15):
|
|
29
|
+
|
|
30
|
+
1. src/parser/implementations/smart-parser.ts
|
|
31
|
+
圈复杂度: 48 高
|
|
32
|
+
认知复杂度: 72
|
|
33
|
+
可维护性: 100 高
|
|
34
|
+
|
|
35
|
+
2. src/orchestrator/workflow/workflow-orchestrator.ts
|
|
36
|
+
圈复杂度: 23 高
|
|
37
|
+
认知复杂度: 35
|
|
38
|
+
可维护性: 100 高
|
|
39
|
+
|
|
40
|
+
3. src/orchestrator/test-linker.ts
|
|
41
|
+
圈复杂度: 22 高
|
|
42
|
+
认知复杂度: 33
|
|
43
|
+
可维护性: 100 高
|
|
44
|
+
|
|
45
|
+
... (共 15 个文件)
|
|
46
|
+
|
|
47
|
+
📈 项目统计:
|
|
48
|
+
总文件数: 104
|
|
49
|
+
平均圈复杂度: 6.24 低
|
|
50
|
+
平均认知复杂度: 9.72
|
|
51
|
+
平均可维护性: 100.00 高
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**执行时间**: 0.673s (user 0.837s)
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 测试用例 2: 分析特定文件复杂度
|
|
59
|
+
|
|
60
|
+
### 2.1 analyzer.ts
|
|
61
|
+
```bash
|
|
62
|
+
time npx codemap complexity -f src/core/analyzer.ts
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**输出:**
|
|
66
|
+
```
|
|
67
|
+
📊 文件复杂度: src/core/analyzer.ts
|
|
68
|
+
──────────────────────────────────────────────────
|
|
69
|
+
|
|
70
|
+
圈复杂度 (Cyclomatic Complexity):
|
|
71
|
+
13 中
|
|
72
|
+
衡量代码中独立路径的数量
|
|
73
|
+
|
|
74
|
+
认知复杂度 (Cognitive Complexity):
|
|
75
|
+
20 (越低越好)
|
|
76
|
+
衡量代码的理解难度
|
|
77
|
+
|
|
78
|
+
可维护性指数 (Maintainability):
|
|
79
|
+
100 高
|
|
80
|
+
0-100,越高越易维护
|
|
81
|
+
|
|
82
|
+
统计信息:
|
|
83
|
+
代码行数: 293
|
|
84
|
+
函数/方法: 13
|
|
85
|
+
类: 0
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**执行时间**: 0.791s
|
|
89
|
+
|
|
90
|
+
### 2.2 smart-parser.ts
|
|
91
|
+
```bash
|
|
92
|
+
time npx codemap complexity -f src/parser/implementations/smart-parser.ts
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**输出:**
|
|
96
|
+
```
|
|
97
|
+
📊 文件复杂度: src/parser/implementations/smart-parser.ts
|
|
98
|
+
──────────────────────────────────────────────────
|
|
99
|
+
|
|
100
|
+
圈复杂度 (Cyclomatic Complexity):
|
|
101
|
+
48 高
|
|
102
|
+
衡量代码中独立路径的数量
|
|
103
|
+
|
|
104
|
+
认知复杂度 (Cognitive Complexity):
|
|
105
|
+
72 (越低越好)
|
|
106
|
+
衡量代码的理解难度
|
|
107
|
+
|
|
108
|
+
可维护性指数 (Maintainability):
|
|
109
|
+
100 高
|
|
110
|
+
|
|
111
|
+
统计信息:
|
|
112
|
+
代码行数: 1166
|
|
113
|
+
函数/方法: 47
|
|
114
|
+
类: 1
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**执行时间**: 0.671s
|
|
118
|
+
|
|
119
|
+
### 2.3 tool-orchestrator.ts
|
|
120
|
+
```bash
|
|
121
|
+
time npx codemap complexity -f src/orchestrator/tool-orchestrator.ts
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**输出:**
|
|
125
|
+
```
|
|
126
|
+
📊 文件复杂度: src/orchestrator/tool-orchestrator.ts
|
|
127
|
+
──────────────────────────────────────────────────
|
|
128
|
+
|
|
129
|
+
圈复杂度 (Cyclomatic Complexity):
|
|
130
|
+
9 低
|
|
131
|
+
衡量代码中独立路径的数量
|
|
132
|
+
|
|
133
|
+
认知复杂度 (Cognitive Complexity):
|
|
134
|
+
14 (越低越好)
|
|
135
|
+
衡量代码的理解难度
|
|
136
|
+
|
|
137
|
+
可维护性指数 (Maintainability):
|
|
138
|
+
100 高
|
|
139
|
+
|
|
140
|
+
统计信息:
|
|
141
|
+
代码行数: 177
|
|
142
|
+
函数/方法: 8
|
|
143
|
+
类: 1
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**执行时间**: 0.561s
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 测试用例 3: JSON 格式输出
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
time npx codemap complexity -j | head -50
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**输出:**
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"modules": [
|
|
160
|
+
{
|
|
161
|
+
"path": "src/index.ts",
|
|
162
|
+
"cyclomatic": 1,
|
|
163
|
+
"cognitive": 2,
|
|
164
|
+
"maintainability": 100,
|
|
165
|
+
"functions": 0,
|
|
166
|
+
"classes": 0,
|
|
167
|
+
"lines": 4
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"path": "src/ai/claude.ts",
|
|
171
|
+
"cyclomatic": 6,
|
|
172
|
+
"cognitive": 9,
|
|
173
|
+
"maintainability": 100,
|
|
174
|
+
"functions": 5,
|
|
175
|
+
"classes": 1,
|
|
176
|
+
"lines": 145
|
|
177
|
+
}
|
|
178
|
+
...
|
|
179
|
+
],
|
|
180
|
+
"summary": {
|
|
181
|
+
"totalModules": 104,
|
|
182
|
+
"averageCyclomatic": 6.24,
|
|
183
|
+
"averageCognitive": 9.72,
|
|
184
|
+
"averageMaintainability": 100.00
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**执行时间**: 0.554s
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 对比分析
|
|
194
|
+
|
|
195
|
+
### 执行速度对比
|
|
196
|
+
|
|
197
|
+
| 工具 | 分析整个项目 | 单文件分析 | 备注 |
|
|
198
|
+
|------|-------------|-----------|------|
|
|
199
|
+
| CodeMap | 0.67s | 0.56-0.79s | 基于已有 codemap.json |
|
|
200
|
+
| 理论 ESLint | 5-10s | 1-2s | 需要完整 AST 解析 |
|
|
201
|
+
| 理论 SonarQube | 分钟级 | N/A | 需要服务器支持 |
|
|
202
|
+
|
|
203
|
+
**结论**: CodeMap 执行速度非常快,因为它直接从已生成的代码地图读取数据,无需重新解析源代码。
|
|
204
|
+
|
|
205
|
+
### 风险分布分析
|
|
206
|
+
|
|
207
|
+
| 风险等级 | 圈复杂度阈值 | 文件数量 | 占比 |
|
|
208
|
+
|---------|-------------|---------|------|
|
|
209
|
+
| 高风险 | > 20 | 6 | 5.8% |
|
|
210
|
+
| 中风险 | 10-20 | 15 | 14.4% |
|
|
211
|
+
| 低风险 | ≤ 10 | 83 | 79.8% |
|
|
212
|
+
|
|
213
|
+
### 高风险文件清单
|
|
214
|
+
|
|
215
|
+
| 排名 | 文件路径 | 圈复杂度 | 认知复杂度 | 代码行数 |
|
|
216
|
+
|-----|---------|---------|-----------|---------|
|
|
217
|
+
| 1 | smart-parser.ts | 48 | 72 | 1166 |
|
|
218
|
+
| 2 | workflow-orchestrator.ts | 23 | 35 | ~500 |
|
|
219
|
+
| 3 | test-linker.ts | 22 | 33 | ~350 |
|
|
220
|
+
| 4 | cache/index.ts | 21 | 32 | 217 |
|
|
221
|
+
| 5 | parser/index.ts | 21 | 32 | ~300 |
|
|
222
|
+
| 6 | plugin-loader.ts | 21 | 32 | ~280 |
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## 复杂度计算验证
|
|
227
|
+
|
|
228
|
+
### 手动验证圈复杂度
|
|
229
|
+
|
|
230
|
+
**测试函数**: `getModuleComplexity` (src/cli/commands/complexity.ts:64-93)
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
function getModuleComplexity(module: ModuleInfo): ComplexityInfo {
|
|
234
|
+
if (module.complexity) { // +1 (if)
|
|
235
|
+
return { ... };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const functions = ...; // 0
|
|
239
|
+
const classes = ...; // 0
|
|
240
|
+
const cyclomatic = Math.max(1, functions + classes); // 0
|
|
241
|
+
const cognitive = cyclomatic * 1.5; // 0
|
|
242
|
+
const loc = module.stats.codeLines; // 0
|
|
243
|
+
const maintainability = Math.max(0, Math.min(100, ...)); // +1 (条件表达式)
|
|
244
|
+
|
|
245
|
+
return { ... }; // 0
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**预期圈复杂度**: 1 (基础) + 1 (if) = 2
|
|
250
|
+
**CodeMap 显示**: 函数数量为 1,圈复杂度基于 `functions + classes + 1` 估算
|
|
251
|
+
|
|
252
|
+
### 验证结果
|
|
253
|
+
|
|
254
|
+
CodeMap 的复杂度计算采用**估算模式**而非精确 AST 分析:
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
// 从代码中的计算方法
|
|
258
|
+
const functions = module.symbols.filter(s => s.kind === 'function' || s.kind === 'method').length;
|
|
259
|
+
const classes = module.symbols.filter(s => s.kind === 'class').length;
|
|
260
|
+
const cyclomatic = Math.max(1, functions + classes);
|
|
261
|
+
const cognitive = cyclomatic * 1.5;
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**问题**: 这种方法只是统计函数和类数量,而非真正分析控制流语句(if/for/while/case等)。
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## 发现的问题
|
|
269
|
+
|
|
270
|
+
### 🔴 严重问题
|
|
271
|
+
|
|
272
|
+
1. **可维护性指数计算错误**
|
|
273
|
+
- **现象**: 所有 104 个文件的可维护性指数均为 **100**
|
|
274
|
+
- **原因**: 计算公式 `maintainability = Math.max(0, Math.min(100, 171 - 5.2 * Math.log(loc + 1) - 0.23 * cyclomatic))`
|
|
275
|
+
- **影响**: 该指标完全失去参考价值
|
|
276
|
+
- **建议**: 修复计算公式,参考微软的 Maintainability Index 标准
|
|
277
|
+
|
|
278
|
+
2. **圈复杂度为估算值,非精确计算**
|
|
279
|
+
- **现象**: smart-parser.ts 有 1582 行代码,47 个函数,圈复杂度显示 48
|
|
280
|
+
- **计算**: 47 个函数 + 1 = 48,与代码行数无关
|
|
281
|
+
- **问题**: 没有真正分析控制流语句
|
|
282
|
+
- **建议**: 基于 AST 分析 if/for/while/case/catch 等语句
|
|
283
|
+
|
|
284
|
+
### 🟡 中等问题
|
|
285
|
+
|
|
286
|
+
3. **缺乏函数级别的复杂度详情**
|
|
287
|
+
- CodeMap 只提供文件级复杂度
|
|
288
|
+
- 无法识别具体哪个函数复杂度过高
|
|
289
|
+
- 建议: 增加 `--detail` 选项显示函数级复杂度
|
|
290
|
+
|
|
291
|
+
4. **认知复杂度计算过于简化**
|
|
292
|
+
- 当前实现: `cognitive = cyclomatic * 1.5`
|
|
293
|
+
- 标准认知复杂度应考虑嵌套深度、递归等因素
|
|
294
|
+
- 建议: 实现 SonarQube 风格的认知复杂度算法
|
|
295
|
+
|
|
296
|
+
5. **codemap.json 中不存储复杂度数据** ✅ 已修复
|
|
297
|
+
- 现象: 所有模块的 `complexity` 字段为空对象 `{}`
|
|
298
|
+
- 修复: 扩展 `calculateComplexity` 方法以支持 `MethodDeclaration` 和 `ArrowFunction`
|
|
299
|
+
- 验证: smart-parser.ts 现在存储正确的复杂度数据 (cyclomatic: 417)
|
|
300
|
+
- 复杂度命令现在直接读取 codemap.json 中的数据,无需重新计算
|
|
301
|
+
|
|
302
|
+
### 🟢 轻微问题
|
|
303
|
+
|
|
304
|
+
6. **输出格式可以更丰富**
|
|
305
|
+
- 缺少趋势线图
|
|
306
|
+
- 缺少与行业标准的对比
|
|
307
|
+
- 缺少重构建议
|
|
308
|
+
|
|
309
|
+
7. **复杂度评级阈值可以配置**
|
|
310
|
+
- 当前阈值: 低(≤10), 中(11-20), 高(21-50), 极高(>50)
|
|
311
|
+
- 建议: 支持自定义阈值
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## 与业界标准对比
|
|
316
|
+
|
|
317
|
+
### 复杂度阈值对比
|
|
318
|
+
|
|
319
|
+
| 工具/标准 | 低复杂度 | 中复杂度 | 高复杂度 | 极高复杂度 |
|
|
320
|
+
|----------|---------|---------|---------|-----------|
|
|
321
|
+
| CodeMap | ≤ 10 | 11-20 | 21-50 | > 50 |
|
|
322
|
+
| ESLint | - | - | > 20 | - |
|
|
323
|
+
| SonarQube | ≤ 10 | 11-20 | 21-30 | > 30 |
|
|
324
|
+
| McCabe | - | - | > 10 | - |
|
|
325
|
+
|
|
326
|
+
### 认知复杂度对比
|
|
327
|
+
|
|
328
|
+
| 工具 | 计算方法 | 嵌套惩罚 | 逻辑运算符处理 |
|
|
329
|
+
|-----|---------|---------|--------------|
|
|
330
|
+
| CodeMap | 圈复杂度的 1.5 倍 | ❌ 无 | ❌ 不处理 |
|
|
331
|
+
| SonarQube | 结构化遍历 | ✅ 有 | ✅ 处理 |
|
|
332
|
+
| ESLint | 不支持 | - | - |
|
|
333
|
+
|
|
334
|
+
### 可维护性指数对比
|
|
335
|
+
|
|
336
|
+
| 工具 | 计算公式 | Halstead 指标 | 代码行数 | 圈复杂度 |
|
|
337
|
+
|-----|---------|--------------|---------|---------|
|
|
338
|
+
| CodeMap | 171 - 5.2*ln(loc) - 0.23*cyc | ❌ 无 | ✅ | ✅ |
|
|
339
|
+
| Visual Studio | 标准 MI 公式 | ✅ 有 | ✅ | ✅ |
|
|
340
|
+
| SonarQube | 自定义公式 | ✅ 有 | ✅ | ✅ |
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## 实际开发中的实用价值评估
|
|
345
|
+
|
|
346
|
+
### ✅ 优势
|
|
347
|
+
|
|
348
|
+
1. **快速概览**: 0.6 秒内获得项目整体复杂度分布
|
|
349
|
+
2. **风险识别**: 能够快速定位最复杂的 15 个文件
|
|
350
|
+
3. **简单直观**: 输出格式清晰,非技术人员也能理解
|
|
351
|
+
4. **CI/CD 友好**: JSON 输出便于自动化处理
|
|
352
|
+
|
|
353
|
+
### ❌ 局限性
|
|
354
|
+
|
|
355
|
+
1. **无法用于代码审查**: 缺少函数级详情
|
|
356
|
+
2. **无法跟踪趋势**: 不支持历史对比
|
|
357
|
+
3. **无法提供重构建议**: 只显示数值,不指导改进
|
|
358
|
+
4. **指标不可靠**: 可维护性指数全部相同
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
## 改进建议
|
|
363
|
+
|
|
364
|
+
### 高优先级
|
|
365
|
+
|
|
366
|
+
1. **修复可维护性指数计算**
|
|
367
|
+
```typescript
|
|
368
|
+
// 建议实现
|
|
369
|
+
function calculateMI(loc: number, cyclomatic: number, commentRatio: number): number {
|
|
370
|
+
// 使用标准 Microsoft Maintainability Index 公式
|
|
371
|
+
const mi = 171 - 5.2 * Math.log2(loc) - 0.23 * cyclomatic - 16.2 * Math.log2(loc);
|
|
372
|
+
return Math.max(0, Math.min(100, mi + 50 * commentRatio));
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
2. **实现真正的圈复杂度计算**
|
|
377
|
+
```typescript
|
|
378
|
+
// 在 SmartParser 中实现
|
|
379
|
+
private calculateCyclomatic(sourceFile: ts.SourceFile): number {
|
|
380
|
+
let complexity = 1;
|
|
381
|
+
const visit = (node: ts.Node) => {
|
|
382
|
+
if (ts.isIfStatement(node) || ts.isWhileStatement(node) ||
|
|
383
|
+
ts.isForStatement(node) || ts.isCaseClause(node) ||
|
|
384
|
+
ts.isCatchClause(node) || ts.isConditionalExpression(node)) {
|
|
385
|
+
complexity++;
|
|
386
|
+
}
|
|
387
|
+
ts.forEachChild(node, visit);
|
|
388
|
+
};
|
|
389
|
+
visit(sourceFile);
|
|
390
|
+
return complexity;
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
3. **存储复杂度数据到 codemap.json**
|
|
395
|
+
- 在 `generate` 阶段计算并存储
|
|
396
|
+
- complexity 命令直接读取,无需重新计算
|
|
397
|
+
|
|
398
|
+
### 中优先级
|
|
399
|
+
|
|
400
|
+
4. **增加函数级复杂度分析**
|
|
401
|
+
```bash
|
|
402
|
+
npx codemap complexity -f src/core/analyzer.ts --detail
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
5. **支持复杂度趋势分析**
|
|
406
|
+
```bash
|
|
407
|
+
npx codemap complexity --trend --since="2 weeks ago"
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
6. **增加重构建议**
|
|
411
|
+
- 圈复杂度过高 → 建议提取函数
|
|
412
|
+
- 认知复杂度过高 → 建议减少嵌套
|
|
413
|
+
- 可维护性过低 → 建议增加注释
|
|
414
|
+
|
|
415
|
+
### 低优先级
|
|
416
|
+
|
|
417
|
+
7. **可视化输出**
|
|
418
|
+
- HTML 报告
|
|
419
|
+
- 复杂度热力图
|
|
420
|
+
- 趋势图表
|
|
421
|
+
|
|
422
|
+
8. **配置文件支持**
|
|
423
|
+
```json
|
|
424
|
+
// codemap.config.json
|
|
425
|
+
{
|
|
426
|
+
"complexity": {
|
|
427
|
+
"cyclomaticThresholds": { "low": 10, "medium": 20, "high": 30 },
|
|
428
|
+
"excludePatterns": ["*.test.ts"]
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
---
|
|
434
|
+
|
|
435
|
+
## 总结
|
|
436
|
+
|
|
437
|
+
| 维度 | 评分 | 说明 |
|
|
438
|
+
|-----|------|------|
|
|
439
|
+
| 执行速度 | ⭐⭐⭐⭐⭐ | 极快,0.6-0.8 秒 |
|
|
440
|
+
| 圈复杂度准确性 | ⭐⭐ | 估算值,非精确计算 |
|
|
441
|
+
| 认知复杂度准确性 | ⭐⭐ | 过于简化 |
|
|
442
|
+
| 可维护性指数准确性 | ⭐ | 全部为 100,完全不可用 |
|
|
443
|
+
| 输出可读性 | ⭐⭐⭐⭐ | 清晰直观 |
|
|
444
|
+
| JSON 输出实用性 | ⭐⭐⭐⭐ | 结构化良好 |
|
|
445
|
+
| 风险识别能力 | ⭐⭐⭐ | 能找出高复杂度文件,但缺少函数级详情 |
|
|
446
|
+
| 实际开发价值 | ⭐⭐⭐ | 适合快速概览,不适合深度分析 |
|
|
447
|
+
|
|
448
|
+
### 总体评价
|
|
449
|
+
|
|
450
|
+
CodeMap 的复杂度分析功能适合作为**项目健康度的快速概览工具**,但**不适合用于代码审查或质量门禁**。
|
|
451
|
+
|
|
452
|
+
**建议**:
|
|
453
|
+
- 短期:修复可维护性指数计算 bug
|
|
454
|
+
- 中期:实现基于 AST 的精确复杂度计算
|
|
455
|
+
- 长期:增加函数级分析和重构建议
|
|
456
|
+
|
|
457
|
+
---
|
|
458
|
+
|
|
459
|
+
*测试报告生成时间: 2026-03-01*
|
|
460
|
+
*测试执行者: CodeMap 测试专家*
|