@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.
Files changed (527) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +63 -978
  3. package/README.zh-CN.md +1096 -0
  4. package/dist/cli/commands/agent-metrics/human.d.ts +4 -0
  5. package/dist/cli/commands/agent-metrics/human.d.ts.map +1 -0
  6. package/dist/cli/commands/agent-metrics/human.js +134 -0
  7. package/dist/cli/commands/agent-metrics/human.js.map +1 -0
  8. package/dist/cli/commands/agent-metrics/index.d.ts +15 -0
  9. package/dist/cli/commands/agent-metrics/index.d.ts.map +1 -0
  10. package/dist/cli/commands/agent-metrics/index.js +116 -0
  11. package/dist/cli/commands/agent-metrics/index.js.map +1 -0
  12. package/dist/cli/commands/analyze-options.d.ts.map +1 -1
  13. package/dist/cli/commands/analyze-options.js +8 -0
  14. package/dist/cli/commands/analyze-options.js.map +1 -1
  15. package/dist/cli/commands/analyze.d.ts +3 -196
  16. package/dist/cli/commands/analyze.d.ts.map +1 -1
  17. package/dist/cli/commands/analyze.js +27 -1162
  18. package/dist/cli/commands/analyze.js.map +1 -1
  19. package/dist/cli/commands/benchmark.d.ts +8 -0
  20. package/dist/cli/commands/benchmark.d.ts.map +1 -0
  21. package/dist/cli/commands/benchmark.js +153 -0
  22. package/dist/cli/commands/benchmark.js.map +1 -0
  23. package/dist/cli/commands/complexity.d.ts.map +1 -1
  24. package/dist/cli/commands/complexity.js +62 -95
  25. package/dist/cli/commands/complexity.js.map +1 -1
  26. package/dist/cli/commands/deps.d.ts +3 -59
  27. package/dist/cli/commands/deps.d.ts.map +1 -1
  28. package/dist/cli/commands/deps.js +25 -331
  29. package/dist/cli/commands/deps.js.map +1 -1
  30. package/dist/cli/commands/doctor.d.ts +3 -0
  31. package/dist/cli/commands/doctor.d.ts.map +1 -0
  32. package/dist/cli/commands/doctor.js +34 -0
  33. package/dist/cli/commands/doctor.js.map +1 -0
  34. package/dist/cli/commands/env-contract.d.ts +3 -0
  35. package/dist/cli/commands/env-contract.d.ts.map +1 -0
  36. package/dist/cli/commands/env-contract.js +221 -0
  37. package/dist/cli/commands/env-contract.js.map +1 -0
  38. package/dist/cli/commands/generate.d.ts +19 -1
  39. package/dist/cli/commands/generate.d.ts.map +1 -1
  40. package/dist/cli/commands/generate.js +735 -89
  41. package/dist/cli/commands/generate.js.map +1 -1
  42. package/dist/cli/commands/impact.d.ts +4 -38
  43. package/dist/cli/commands/impact.d.ts.map +1 -1
  44. package/dist/cli/commands/impact.js +133 -375
  45. package/dist/cli/commands/impact.js.map +1 -1
  46. package/dist/cli/commands/init.d.ts +1 -0
  47. package/dist/cli/commands/init.d.ts.map +1 -1
  48. package/dist/cli/commands/init.js +61 -2
  49. package/dist/cli/commands/init.js.map +1 -1
  50. package/dist/cli/commands/preview.d.ts +3 -0
  51. package/dist/cli/commands/preview.d.ts.map +1 -0
  52. package/dist/cli/commands/preview.js +216 -0
  53. package/dist/cli/commands/preview.js.map +1 -0
  54. package/dist/cli/commands/query.d.ts +2 -20
  55. package/dist/cli/commands/query.d.ts.map +1 -1
  56. package/dist/cli/commands/query.js +23 -708
  57. package/dist/cli/commands/query.js.map +1 -1
  58. package/dist/cli/commands/watch-foreground.d.ts.map +1 -1
  59. package/dist/cli/commands/watch-foreground.js +5 -1
  60. package/dist/cli/commands/watch-foreground.js.map +1 -1
  61. package/dist/cli/config-loader.d.ts.map +1 -1
  62. package/dist/cli/config-loader.js +51 -13
  63. package/dist/cli/config-loader.js.map +1 -1
  64. package/dist/cli/doctor/check-agent.d.ts +3 -0
  65. package/dist/cli/doctor/check-agent.d.ts.map +1 -0
  66. package/dist/cli/doctor/check-agent.js +60 -0
  67. package/dist/cli/doctor/check-agent.js.map +1 -0
  68. package/dist/cli/doctor/check-env-contract.d.ts +3 -0
  69. package/dist/cli/doctor/check-env-contract.d.ts.map +1 -0
  70. package/dist/cli/doctor/check-env-contract.js +96 -0
  71. package/dist/cli/doctor/check-env-contract.js.map +1 -0
  72. package/dist/cli/doctor/check-ghost-commands.d.ts +3 -0
  73. package/dist/cli/doctor/check-ghost-commands.d.ts.map +1 -0
  74. package/dist/cli/doctor/check-ghost-commands.js +86 -0
  75. package/dist/cli/doctor/check-ghost-commands.js.map +1 -0
  76. package/dist/cli/doctor/check-native-deps.d.ts +3 -0
  77. package/dist/cli/doctor/check-native-deps.d.ts.map +1 -0
  78. package/dist/cli/doctor/check-native-deps.js +70 -0
  79. package/dist/cli/doctor/check-native-deps.js.map +1 -0
  80. package/dist/cli/doctor/check-workspace-drift.d.ts +3 -0
  81. package/dist/cli/doctor/check-workspace-drift.d.ts.map +1 -0
  82. package/dist/cli/doctor/check-workspace-drift.js +83 -0
  83. package/dist/cli/doctor/check-workspace-drift.js.map +1 -0
  84. package/dist/cli/doctor/formatter.d.ts +20 -0
  85. package/dist/cli/doctor/formatter.d.ts.map +1 -0
  86. package/dist/cli/doctor/formatter.js +91 -0
  87. package/dist/cli/doctor/formatter.js.map +1 -0
  88. package/dist/cli/doctor/index.d.ts +8 -0
  89. package/dist/cli/doctor/index.d.ts.map +1 -0
  90. package/dist/cli/doctor/index.js +9 -0
  91. package/dist/cli/doctor/index.js.map +1 -0
  92. package/dist/cli/doctor/orchestrator.d.ts +3 -0
  93. package/dist/cli/doctor/orchestrator.d.ts.map +1 -0
  94. package/dist/cli/doctor/orchestrator.js +40 -0
  95. package/dist/cli/doctor/orchestrator.js.map +1 -0
  96. package/dist/cli/doctor/types.d.ts +19 -0
  97. package/dist/cli/doctor/types.d.ts.map +1 -0
  98. package/dist/cli/doctor/types.js +4 -0
  99. package/dist/cli/doctor/types.js.map +1 -0
  100. package/dist/cli/env-contract/check.d.ts +18 -0
  101. package/dist/cli/env-contract/check.d.ts.map +1 -0
  102. package/dist/cli/env-contract/check.js +118 -0
  103. package/dist/cli/env-contract/check.js.map +1 -0
  104. package/dist/cli/env-contract/discovery.d.ts +12 -0
  105. package/dist/cli/env-contract/discovery.d.ts.map +1 -0
  106. package/dist/cli/env-contract/discovery.js +249 -0
  107. package/dist/cli/env-contract/discovery.js.map +1 -0
  108. package/dist/cli/env-contract/filters.d.ts +10 -0
  109. package/dist/cli/env-contract/filters.d.ts.map +1 -0
  110. package/dist/cli/env-contract/filters.js +23 -0
  111. package/dist/cli/env-contract/filters.js.map +1 -0
  112. package/dist/cli/env-contract/index.d.ts +6 -0
  113. package/dist/cli/env-contract/index.d.ts.map +1 -0
  114. package/dist/cli/env-contract/index.js +8 -0
  115. package/dist/cli/env-contract/index.js.map +1 -0
  116. package/dist/cli/env-contract/reminder-engine.d.ts +34 -0
  117. package/dist/cli/env-contract/reminder-engine.d.ts.map +1 -0
  118. package/dist/cli/env-contract/reminder-engine.js +51 -0
  119. package/dist/cli/env-contract/reminder-engine.js.map +1 -0
  120. package/dist/cli/env-contract/reminder-hook-runner.d.ts +45 -0
  121. package/dist/cli/env-contract/reminder-hook-runner.d.ts.map +1 -0
  122. package/dist/cli/env-contract/reminder-hook-runner.js +273 -0
  123. package/dist/cli/env-contract/reminder-hook-runner.js.map +1 -0
  124. package/dist/cli/env-contract/reminder-ledger.d.ts +11 -0
  125. package/dist/cli/env-contract/reminder-ledger.d.ts.map +1 -0
  126. package/dist/cli/env-contract/reminder-ledger.js +37 -0
  127. package/dist/cli/env-contract/reminder-ledger.js.map +1 -0
  128. package/dist/cli/env-contract/types.d.ts +48 -0
  129. package/dist/cli/env-contract/types.d.ts.map +1 -0
  130. package/dist/cli/env-contract/types.js +22 -0
  131. package/dist/cli/env-contract/types.js.map +1 -0
  132. package/dist/cli/env-contract/validation.d.ts +10 -0
  133. package/dist/cli/env-contract/validation.d.ts.map +1 -0
  134. package/dist/cli/env-contract/validation.js +116 -0
  135. package/dist/cli/env-contract/validation.js.map +1 -0
  136. package/dist/cli/first-run-guide.d.ts.map +1 -1
  137. package/dist/cli/first-run-guide.js +8 -3
  138. package/dist/cli/first-run-guide.js.map +1 -1
  139. package/dist/cli/index.js +94 -22
  140. package/dist/cli/index.js.map +1 -1
  141. package/dist/cli/init/assistant-plan.d.ts +14 -0
  142. package/dist/cli/init/assistant-plan.d.ts.map +1 -0
  143. package/dist/cli/init/assistant-plan.js +208 -0
  144. package/dist/cli/init/assistant-plan.js.map +1 -0
  145. package/dist/cli/init/detect.d.ts +28 -0
  146. package/dist/cli/init/detect.d.ts.map +1 -0
  147. package/dist/cli/init/detect.js +63 -0
  148. package/dist/cli/init/detect.js.map +1 -0
  149. package/dist/cli/init/env-contract-plan.d.ts +28 -0
  150. package/dist/cli/init/env-contract-plan.d.ts.map +1 -0
  151. package/dist/cli/init/env-contract-plan.js +184 -0
  152. package/dist/cli/init/env-contract-plan.js.map +1 -0
  153. package/dist/cli/init/manifest-extractors.d.ts +22 -0
  154. package/dist/cli/init/manifest-extractors.d.ts.map +1 -0
  155. package/dist/cli/init/manifest-extractors.js +185 -0
  156. package/dist/cli/init/manifest-extractors.js.map +1 -0
  157. package/dist/cli/init/profile-loader.d.ts +49 -0
  158. package/dist/cli/init/profile-loader.d.ts.map +1 -0
  159. package/dist/cli/init/profile-loader.js +107 -0
  160. package/dist/cli/init/profile-loader.js.map +1 -0
  161. package/dist/cli/init/profile-plan.d.ts +38 -0
  162. package/dist/cli/init/profile-plan.d.ts.map +1 -0
  163. package/dist/cli/init/profile-plan.js +120 -0
  164. package/dist/cli/init/profile-plan.js.map +1 -0
  165. package/dist/cli/init/profiles/generic.json +16 -0
  166. package/dist/cli/init/profiles/go.json +12 -0
  167. package/dist/cli/init/profiles/nodejs.json +16 -0
  168. package/dist/cli/init/profiles/python.json +17 -0
  169. package/dist/cli/init/profiles/rust.json +12 -0
  170. package/dist/cli/init/receipt.d.ts.map +1 -1
  171. package/dist/cli/init/receipt.js +107 -7
  172. package/dist/cli/init/receipt.js.map +1 -1
  173. package/dist/cli/init/reconciler.d.ts +10 -1
  174. package/dist/cli/init/reconciler.d.ts.map +1 -1
  175. package/dist/cli/init/reconciler.js +85 -15
  176. package/dist/cli/init/reconciler.js.map +1 -1
  177. package/dist/cli/interface-contract/commands/agent-metrics.d.ts +3 -0
  178. package/dist/cli/interface-contract/commands/agent-metrics.d.ts.map +1 -0
  179. package/dist/cli/interface-contract/commands/agent-metrics.js +217 -0
  180. package/dist/cli/interface-contract/commands/agent-metrics.js.map +1 -0
  181. package/dist/cli/interface-contract/commands/analyze.d.ts +3 -0
  182. package/dist/cli/interface-contract/commands/analyze.d.ts.map +1 -0
  183. package/dist/cli/interface-contract/commands/analyze.js +139 -0
  184. package/dist/cli/interface-contract/commands/analyze.js.map +1 -0
  185. package/dist/cli/interface-contract/commands/benchmark.d.ts +3 -0
  186. package/dist/cli/interface-contract/commands/benchmark.d.ts.map +1 -0
  187. package/dist/cli/interface-contract/commands/benchmark.js +108 -0
  188. package/dist/cli/interface-contract/commands/benchmark.js.map +1 -0
  189. package/dist/cli/interface-contract/commands/deps.d.ts +3 -0
  190. package/dist/cli/interface-contract/commands/deps.d.ts.map +1 -0
  191. package/dist/cli/interface-contract/commands/deps.js +130 -0
  192. package/dist/cli/interface-contract/commands/deps.js.map +1 -0
  193. package/dist/cli/interface-contract/commands/doctor.d.ts +3 -0
  194. package/dist/cli/interface-contract/commands/doctor.d.ts.map +1 -0
  195. package/dist/cli/interface-contract/commands/doctor.js +60 -0
  196. package/dist/cli/interface-contract/commands/doctor.js.map +1 -0
  197. package/dist/cli/interface-contract/commands/env-contract.d.ts +3 -0
  198. package/dist/cli/interface-contract/commands/env-contract.d.ts.map +1 -0
  199. package/dist/cli/interface-contract/commands/env-contract.js +168 -0
  200. package/dist/cli/interface-contract/commands/env-contract.js.map +1 -0
  201. package/dist/cli/interface-contract/commands/index.d.ts +12 -0
  202. package/dist/cli/interface-contract/commands/index.d.ts.map +1 -0
  203. package/dist/cli/interface-contract/commands/index.js +24 -0
  204. package/dist/cli/interface-contract/commands/index.js.map +1 -0
  205. package/dist/cli/interface-contract/commands/init.d.ts +3 -0
  206. package/dist/cli/interface-contract/commands/init.d.ts.map +1 -0
  207. package/dist/cli/interface-contract/commands/init.js +96 -0
  208. package/dist/cli/interface-contract/commands/init.js.map +1 -0
  209. package/dist/cli/interface-contract/commands/preview.d.ts +3 -0
  210. package/dist/cli/interface-contract/commands/preview.d.ts.map +1 -0
  211. package/dist/cli/interface-contract/commands/preview.js +118 -0
  212. package/dist/cli/interface-contract/commands/preview.js.map +1 -0
  213. package/dist/cli/interface-contract/commands/query.d.ts +3 -0
  214. package/dist/cli/interface-contract/commands/query.d.ts.map +1 -0
  215. package/dist/cli/interface-contract/commands/query.js +186 -0
  216. package/dist/cli/interface-contract/commands/query.js.map +1 -0
  217. package/dist/cli/interface-contract/index.d.ts +22 -0
  218. package/dist/cli/interface-contract/index.d.ts.map +1 -0
  219. package/dist/cli/interface-contract/index.js +41 -0
  220. package/dist/cli/interface-contract/index.js.map +1 -0
  221. package/dist/cli/interface-contract/schema.d.ts +30 -0
  222. package/dist/cli/interface-contract/schema.d.ts.map +1 -0
  223. package/dist/cli/interface-contract/schema.js +73 -0
  224. package/dist/cli/interface-contract/schema.js.map +1 -0
  225. package/dist/cli/interface-contract/types.d.ts +77 -0
  226. package/dist/cli/interface-contract/types.d.ts.map +1 -0
  227. package/dist/cli/interface-contract/types.js +4 -0
  228. package/dist/cli/interface-contract/types.js.map +1 -0
  229. package/dist/cli/output/apply-suggestion.d.ts +12 -0
  230. package/dist/cli/output/apply-suggestion.d.ts.map +1 -0
  231. package/dist/cli/output/apply-suggestion.js +29 -0
  232. package/dist/cli/output/apply-suggestion.js.map +1 -0
  233. package/dist/cli/output/error-codes.d.ts +24 -0
  234. package/dist/cli/output/error-codes.d.ts.map +1 -0
  235. package/dist/cli/output/error-codes.js +94 -0
  236. package/dist/cli/output/error-codes.js.map +1 -0
  237. package/dist/cli/output/errors.d.ts +14 -0
  238. package/dist/cli/output/errors.d.ts.map +1 -0
  239. package/dist/cli/output/errors.js +182 -0
  240. package/dist/cli/output/errors.js.map +1 -0
  241. package/dist/cli/output/index.d.ts +13 -0
  242. package/dist/cli/output/index.d.ts.map +1 -0
  243. package/dist/cli/output/index.js +11 -0
  244. package/dist/cli/output/index.js.map +1 -0
  245. package/dist/cli/output/mode.d.ts +12 -0
  246. package/dist/cli/output/mode.d.ts.map +1 -0
  247. package/dist/cli/output/mode.js +23 -0
  248. package/dist/cli/output/mode.js.map +1 -0
  249. package/dist/cli/output/progress.d.ts +9 -0
  250. package/dist/cli/output/progress.d.ts.map +1 -0
  251. package/dist/cli/output/progress.js +65 -0
  252. package/dist/cli/output/progress.js.map +1 -0
  253. package/dist/cli/output/render.d.ts +11 -0
  254. package/dist/cli/output/render.d.ts.map +1 -0
  255. package/dist/cli/output/render.js +18 -0
  256. package/dist/cli/output/render.js.map +1 -0
  257. package/dist/cli/output/types.d.ts +53 -0
  258. package/dist/cli/output/types.d.ts.map +1 -0
  259. package/dist/cli/output/types.js +14 -0
  260. package/dist/cli/output/types.js.map +1 -0
  261. package/dist/cli/output/wasm-fallback.d.ts +14 -0
  262. package/dist/cli/output/wasm-fallback.d.ts.map +1 -0
  263. package/dist/cli/output/wasm-fallback.js +92 -0
  264. package/dist/cli/output/wasm-fallback.js.map +1 -0
  265. package/dist/cli/preview/complexity-scanner.d.ts +21 -0
  266. package/dist/cli/preview/complexity-scanner.d.ts.map +1 -0
  267. package/dist/cli/preview/complexity-scanner.js +52 -0
  268. package/dist/cli/preview/complexity-scanner.js.map +1 -0
  269. package/dist/cli/preview/dependency-extractor.d.ts +38 -0
  270. package/dist/cli/preview/dependency-extractor.d.ts.map +1 -0
  271. package/dist/cli/preview/dependency-extractor.js +140 -0
  272. package/dist/cli/preview/dependency-extractor.js.map +1 -0
  273. package/dist/cli/preview/preview-renderer.d.ts +32 -0
  274. package/dist/cli/preview/preview-renderer.d.ts.map +1 -0
  275. package/dist/cli/preview/preview-renderer.js +54 -0
  276. package/dist/cli/preview/preview-renderer.js.map +1 -0
  277. package/dist/cli/storage-runtime.d.ts +7 -0
  278. package/dist/cli/storage-runtime.d.ts.map +1 -1
  279. package/dist/cli/storage-runtime.js +22 -0
  280. package/dist/cli/storage-runtime.js.map +1 -1
  281. package/dist/cli/tree-sitter-check.d.ts +6 -1
  282. package/dist/cli/tree-sitter-check.d.ts.map +1 -1
  283. package/dist/cli/tree-sitter-check.js +23 -1
  284. package/dist/cli/tree-sitter-check.js.map +1 -1
  285. package/dist/cli-new/index.js +1 -1
  286. package/dist/cli-new/index.js.map +1 -1
  287. package/dist/composition/parser-composition.d.ts +7 -0
  288. package/dist/composition/parser-composition.d.ts.map +1 -0
  289. package/dist/composition/parser-composition.js +15 -0
  290. package/dist/composition/parser-composition.js.map +1 -0
  291. package/dist/core/analyzer.d.ts.map +1 -1
  292. package/dist/core/analyzer.js +83 -67
  293. package/dist/core/analyzer.js.map +1 -1
  294. package/dist/core/ast-complexity-analyzer.d.ts +12 -6
  295. package/dist/core/ast-complexity-analyzer.d.ts.map +1 -1
  296. package/dist/core/ast-complexity-analyzer.js +368 -209
  297. package/dist/core/ast-complexity-analyzer.js.map +1 -1
  298. package/dist/core/file-discovery.d.ts +1 -1
  299. package/dist/core/file-discovery.d.ts.map +1 -1
  300. package/dist/core/file-discovery.js +3 -0
  301. package/dist/core/file-discovery.js.map +1 -1
  302. package/dist/core/global-index.d.ts +3 -1
  303. package/dist/core/global-index.d.ts.map +1 -1
  304. package/dist/core/global-index.js +69 -4
  305. package/dist/core/global-index.js.map +1 -1
  306. package/dist/domain/entities/CodeGraph.d.ts +3 -0
  307. package/dist/domain/entities/CodeGraph.d.ts.map +1 -1
  308. package/dist/domain/entities/CodeGraph.js +19 -2
  309. package/dist/domain/entities/CodeGraph.js.map +1 -1
  310. package/dist/domain/entities/Dependency.d.ts +5 -2
  311. package/dist/domain/entities/Dependency.d.ts.map +1 -1
  312. package/dist/domain/entities/Dependency.js +49 -3
  313. package/dist/domain/entities/Dependency.js.map +1 -1
  314. package/dist/domain/repositories/CodeGraphRepository.d.ts +5 -0
  315. package/dist/domain/repositories/CodeGraphRepository.d.ts.map +1 -1
  316. package/dist/domain/repositories/CodeGraphRepository.js.map +1 -1
  317. package/dist/execution/contract-tools/analyze.d.ts +205 -0
  318. package/dist/execution/contract-tools/analyze.d.ts.map +1 -0
  319. package/dist/execution/contract-tools/analyze.js +1215 -0
  320. package/dist/execution/contract-tools/analyze.js.map +1 -0
  321. package/dist/execution/contract-tools/deps.d.ts +62 -0
  322. package/dist/execution/contract-tools/deps.d.ts.map +1 -0
  323. package/dist/execution/contract-tools/deps.js +234 -0
  324. package/dist/execution/contract-tools/deps.js.map +1 -0
  325. package/dist/execution/contract-tools/index.d.ts +5 -0
  326. package/dist/execution/contract-tools/index.d.ts.map +1 -0
  327. package/dist/execution/contract-tools/index.js +7 -0
  328. package/dist/execution/contract-tools/index.js.map +1 -0
  329. package/dist/execution/contract-tools/query.d.ts +60 -0
  330. package/dist/execution/contract-tools/query.d.ts.map +1 -0
  331. package/dist/execution/contract-tools/query.js +532 -0
  332. package/dist/execution/contract-tools/query.js.map +1 -0
  333. package/dist/execution/contract-tools/types.d.ts +26 -0
  334. package/dist/execution/contract-tools/types.d.ts.map +1 -0
  335. package/dist/execution/contract-tools/types.js +32 -0
  336. package/dist/execution/contract-tools/types.js.map +1 -0
  337. package/dist/generator/index.d.ts.map +1 -1
  338. package/dist/generator/index.js +0 -3
  339. package/dist/generator/index.js.map +1 -1
  340. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.d.ts +12 -0
  341. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.d.ts.map +1 -0
  342. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.js +55 -0
  343. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.js.map +1 -0
  344. package/dist/infrastructure/parser/implementations/GoParser.d.ts +2 -1
  345. package/dist/infrastructure/parser/implementations/GoParser.d.ts.map +1 -1
  346. package/dist/infrastructure/parser/implementations/GoParser.js +13 -1
  347. package/dist/infrastructure/parser/implementations/GoParser.js.map +1 -1
  348. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.d.ts +114 -0
  349. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.d.ts.map +1 -0
  350. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.js +1022 -0
  351. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.js.map +1 -0
  352. package/dist/infrastructure/parser/implementations/TreeSitterParser.d.ts +78 -0
  353. package/dist/infrastructure/parser/implementations/TreeSitterParser.d.ts.map +1 -0
  354. package/dist/infrastructure/parser/implementations/TreeSitterParser.js +648 -0
  355. package/dist/infrastructure/parser/implementations/TreeSitterParser.js.map +1 -0
  356. package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts +3 -55
  357. package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts.map +1 -1
  358. package/dist/infrastructure/parser/implementations/TypeScriptParser.js +4 -411
  359. package/dist/infrastructure/parser/implementations/TypeScriptParser.js.map +1 -1
  360. package/dist/infrastructure/parser/index.d.ts +2 -0
  361. package/dist/infrastructure/parser/index.d.ts.map +1 -1
  362. package/dist/infrastructure/parser/index.js +9 -6
  363. package/dist/infrastructure/parser/index.js.map +1 -1
  364. package/dist/infrastructure/parser/interfaces/ParserBase.d.ts.map +1 -1
  365. package/dist/infrastructure/parser/interfaces/ParserBase.js +1 -0
  366. package/dist/infrastructure/parser/interfaces/ParserBase.js.map +1 -1
  367. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts +2 -0
  368. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts.map +1 -1
  369. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js +4 -0
  370. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js.map +1 -1
  371. package/dist/infrastructure/storage/StorageFactory.d.ts +5 -18
  372. package/dist/infrastructure/storage/StorageFactory.d.ts.map +1 -1
  373. package/dist/infrastructure/storage/StorageFactory.js +30 -98
  374. package/dist/infrastructure/storage/StorageFactory.js.map +1 -1
  375. package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts +13 -1
  376. package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts.map +1 -1
  377. package/dist/infrastructure/storage/adapters/SQLiteStorage.js +322 -76
  378. package/dist/infrastructure/storage/adapters/SQLiteStorage.js.map +1 -1
  379. package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts +45 -0
  380. package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts.map +1 -0
  381. package/dist/infrastructure/storage/adapters/sqlite-loader.js +266 -0
  382. package/dist/infrastructure/storage/adapters/sqlite-loader.js.map +1 -0
  383. package/dist/infrastructure/storage/community-helpers.d.ts +4 -0
  384. package/dist/infrastructure/storage/community-helpers.d.ts.map +1 -0
  385. package/dist/infrastructure/storage/community-helpers.js +392 -0
  386. package/dist/infrastructure/storage/community-helpers.js.map +1 -0
  387. package/dist/infrastructure/storage/graph-helpers.d.ts +22 -5
  388. package/dist/infrastructure/storage/graph-helpers.d.ts.map +1 -1
  389. package/dist/infrastructure/storage/graph-helpers.js +496 -91
  390. package/dist/infrastructure/storage/graph-helpers.js.map +1 -1
  391. package/dist/infrastructure/storage/index.d.ts +1 -1
  392. package/dist/infrastructure/storage/index.d.ts.map +1 -1
  393. package/dist/infrastructure/storage/index.js +1 -1
  394. package/dist/infrastructure/storage/index.js.map +1 -1
  395. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts +2 -2
  396. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts.map +1 -1
  397. package/dist/infrastructure/storage/interfaces/StorageBase.js.map +1 -1
  398. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts +2 -0
  399. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts.map +1 -1
  400. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js +52 -12
  401. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js.map +1 -1
  402. package/dist/infrastructure/storage/sqlite/schema.d.ts +2 -2
  403. package/dist/infrastructure/storage/sqlite/schema.d.ts.map +1 -1
  404. package/dist/infrastructure/storage/sqlite/schema.js +49 -1
  405. package/dist/infrastructure/storage/sqlite/schema.js.map +1 -1
  406. package/dist/interface/config/index.d.ts +5 -3
  407. package/dist/interface/config/index.d.ts.map +1 -1
  408. package/dist/interface/types/index.d.ts +37 -6
  409. package/dist/interface/types/index.d.ts.map +1 -1
  410. package/dist/interface/types/parser.d.ts +85 -0
  411. package/dist/interface/types/parser.d.ts.map +1 -1
  412. package/dist/interface/types/storage.d.ts +227 -10
  413. package/dist/interface/types/storage.d.ts.map +1 -1
  414. package/dist/orchestrator/agent-metrics-service.d.ts +126 -0
  415. package/dist/orchestrator/agent-metrics-service.d.ts.map +1 -0
  416. package/dist/orchestrator/agent-metrics-service.js +444 -0
  417. package/dist/orchestrator/agent-metrics-service.js.map +1 -0
  418. package/dist/orchestrator/types.d.ts +2 -0
  419. package/dist/orchestrator/types.d.ts.map +1 -1
  420. package/dist/orchestrator/types.js.map +1 -1
  421. package/dist/parser/enhancers/PythonTypeEnhancer.d.ts +26 -0
  422. package/dist/parser/enhancers/PythonTypeEnhancer.d.ts.map +1 -0
  423. package/dist/parser/enhancers/PythonTypeEnhancer.js +440 -0
  424. package/dist/parser/enhancers/PythonTypeEnhancer.js.map +1 -0
  425. package/dist/parser/implementations/smart-parser.d.ts.map +1 -1
  426. package/dist/parser/implementations/smart-parser.js +7 -69
  427. package/dist/parser/implementations/smart-parser.js.map +1 -1
  428. package/dist/parser/implementations/tree-sitter-loader.d.ts +18 -0
  429. package/dist/parser/implementations/tree-sitter-loader.d.ts.map +1 -0
  430. package/dist/parser/implementations/tree-sitter-loader.js +136 -0
  431. package/dist/parser/implementations/tree-sitter-loader.js.map +1 -0
  432. package/dist/parser/index.d.ts +5 -3
  433. package/dist/parser/index.d.ts.map +1 -1
  434. package/dist/parser/index.js +68 -6
  435. package/dist/parser/index.js.map +1 -1
  436. package/dist/parser/interfaces/IParser.d.ts +19 -6
  437. package/dist/parser/interfaces/IParser.d.ts.map +1 -1
  438. package/dist/parser/interfaces/IParser.js +2 -3
  439. package/dist/parser/interfaces/IParser.js.map +1 -1
  440. package/dist/server/handlers/AnalysisHandler.d.ts +13 -2
  441. package/dist/server/handlers/AnalysisHandler.d.ts.map +1 -1
  442. package/dist/server/handlers/AnalysisHandler.js +24 -0
  443. package/dist/server/handlers/AnalysisHandler.js.map +1 -1
  444. package/dist/server/handlers/QueryHandler.d.ts.map +1 -1
  445. package/dist/server/handlers/QueryHandler.js +11 -30
  446. package/dist/server/handlers/QueryHandler.js.map +1 -1
  447. package/dist/server/mcp/context-tool.d.ts +9 -0
  448. package/dist/server/mcp/context-tool.d.ts.map +1 -0
  449. package/dist/server/mcp/context-tool.js +257 -0
  450. package/dist/server/mcp/context-tool.js.map +1 -0
  451. package/dist/server/mcp/schema-adapter.d.ts +55 -0
  452. package/dist/server/mcp/schema-adapter.d.ts.map +1 -0
  453. package/dist/server/mcp/schema-adapter.js +409 -0
  454. package/dist/server/mcp/schema-adapter.js.map +1 -0
  455. package/dist/server/mcp/server.d.ts +3 -3
  456. package/dist/server/mcp/server.d.ts.map +1 -1
  457. package/dist/server/mcp/server.js +134 -20
  458. package/dist/server/mcp/server.js.map +1 -1
  459. package/dist/server/mcp/service.d.ts +6 -2
  460. package/dist/server/mcp/service.d.ts.map +1 -1
  461. package/dist/server/mcp/service.js +138 -36
  462. package/dist/server/mcp/service.js.map +1 -1
  463. package/dist/server/mcp/stdio-transport.d.ts +23 -0
  464. package/dist/server/mcp/stdio-transport.d.ts.map +1 -0
  465. package/dist/server/mcp/stdio-transport.js +101 -0
  466. package/dist/server/mcp/stdio-transport.js.map +1 -0
  467. package/dist/server/mcp/types.d.ts +133 -8
  468. package/dist/server/mcp/types.d.ts.map +1 -1
  469. package/dist/server/routes/api.d.ts.map +1 -1
  470. package/dist/server/routes/api.js +11 -2
  471. package/dist/server/routes/api.js.map +1 -1
  472. package/docs/AI_ASSISTANT_SETUP.md +281 -12
  473. package/docs/API.md +170 -0
  474. package/docs/CONFIGURATION.md +141 -0
  475. package/docs/DEVELOPMENT.md +96 -0
  476. package/docs/GETTING-STARTED.md +114 -0
  477. package/docs/README.md +40 -1
  478. package/docs/SETUP_GUIDE.md +60 -14
  479. package/docs/TESTING.md +81 -0
  480. package/docs/ai-guide/COMMANDS.md +68 -10
  481. package/docs/ai-guide/INTEGRATION.md +77 -10
  482. package/docs/ai-guide/OUTPUT.md +345 -9
  483. package/docs/ai-guide/PROMPTS.md +2 -2
  484. package/docs/ai-guide/QUICKSTART.md +28 -1
  485. package/docs/ai-guide/README.md +2 -2
  486. package/docs/archive/ideation/2026-04-15-executable-architecture-constitution-ideation-archive.md +70 -0
  487. package/docs/archive/ideation/2026-04-20-mycodemap-init-enhancements-ideation-archive.md +109 -0
  488. package/docs/archive/ideation/2026-04-22-rules-entry-docs-optimization-consolidated-ideation-archive.md +54 -0
  489. package/docs/backlog.md +232 -144
  490. package/docs/brainstorms/2026-05-10-agent-effectiveness-validation-requirements.md +112 -0
  491. package/docs/generated/phase-58/subagent-evidence/claude-hook-example.json +15 -0
  492. package/docs/generated/phase-58/subagent-evidence/claude-session.md +146 -0
  493. package/docs/generated/phase-58/subagent-evidence/claude-subagent.json +28 -0
  494. package/docs/generated/phase-58/subagent-evidence/codex-agent-example.toml +19 -0
  495. package/docs/generated/phase-58/subagent-evidence/codex-session.md +150 -0
  496. package/docs/generated/phase-58/subagent-evidence/codex-subagent.json +20 -0
  497. package/docs/generated/phase-58/subagent-evidence/negative-no-retrieval.json +12 -0
  498. package/docs/generated/phase-58/subagent-evidence/verification-manifest.json +19 -0
  499. package/docs/ideation/2026-04-15-executable-architecture-constitution-ideation.md +10 -22
  500. package/docs/ideation/2026-04-20-mycodemap-init-enhancements-ideation.md +15 -60
  501. package/docs/ideation/2026-04-22-rules-entry-docs-optimization-consolidated-ideation.md +47 -52
  502. package/docs/ideation/2026-04-29-ux-install-agent-experience-ideation.md +256 -0
  503. package/docs/ideation/2026-05-02-subagent-environment-contract-injection-ideation.md +183 -0
  504. package/docs/ideation/2026-05-04-subagent-hooks-deep-dive-ideation.md +133 -0
  505. package/docs/ideation/2026-05-10-agent-effectiveness-validation-ideation.md +219 -0
  506. package/docs/plans/2026-04-30-install-guide-and-repo-analyzer-design.md +394 -0
  507. package/docs/rules/README.md +1 -0
  508. package/docs/rules/architecture-guardrails.md +2 -1
  509. package/docs/rules/engineering-with-codex-openai.md +1 -1
  510. package/docs/rules/harness.md +106 -0
  511. package/docs/rules/pre-release-checklist.md +28 -0
  512. package/docs/rules/testing.md +51 -0
  513. package/examples/claude/skills/mycodemap-repo-analyzer/SKILL.md +294 -0
  514. package/examples/claude/skills/mycodemap-repo-analyzer/references/analysis-guide.md +166 -0
  515. package/examples/claude/skills/mycodemap-repo-analyzer/references/module-analysis-guide.md +150 -0
  516. package/package.json +12 -4
  517. package/scripts/copy-build-assets.mjs +23 -0
  518. package/scripts/hooks/templates/pre-commit +33 -2
  519. package/scripts/sync-analyze-docs.js +2 -2
  520. package/scripts/tests/test_rule_control_workflow.py +15 -1
  521. package/scripts/validate-docs.js +113 -16
  522. package/scripts/verify-subagent-env-contract.mjs +279 -0
  523. package/dist/parser/implementations/tree-sitter-parser.d.ts +0 -57
  524. package/dist/parser/implementations/tree-sitter-parser.d.ts.map +0 -1
  525. package/dist/parser/implementations/tree-sitter-parser.js +0 -375
  526. package/dist/parser/implementations/tree-sitter-parser.js.map +0 -1
  527. 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] 提供基于 AST 的精确圈复杂度计算,支持函数级复杂度详情分析
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
- * 基于 AST 分析单个文件的圈复杂度
10
- */
11
- function analyzeFileWithAST(filePath, sourceCode) {
12
- const sourceFile = ts.createSourceFile(path.basename(filePath), sourceCode, ts.ScriptTarget.Latest, true);
13
- const functionDetails = [];
14
- // 遍历 AST 节点
15
- function visit(node, context) {
16
- // 检测函数/方法
17
- let currentFunction = context.inFunction;
18
- let functionName = context.functionName;
19
- let functionKind = context.functionKind;
20
- let functionStart = context.functionStart;
21
- let cyclomatic = 1;
22
- let maxDepth = 0;
23
- let currentDepth = 0;
24
- if (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node) || ts.isConstructorDeclaration(node)) {
25
- currentFunction = true;
26
- functionName = node.name?.getText(sourceFile) || '<anonymous>';
27
- functionKind = ts.isFunctionDeclaration(node) ? 'function' : ts.isMethodDeclaration(node) ? 'method' : 'constructor';
28
- functionStart = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
29
- cyclomatic = 1;
30
- currentDepth = 0;
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
- if (currentFunction) {
34
- if (ts.isIfStatement(node) || ts.isWhileStatement(node) ||
35
- ts.isForStatement(node) || ts.isForInStatement(node) ||
36
- ts.isForOfStatement(node) || ts.isCaseClause(node) ||
37
- ts.isCatchClause(node) || ts.isConditionalExpression(node)) {
38
- cyclomatic++;
39
- }
40
- // 三元运算符增加复杂度
41
- if (ts.isConditionalExpression(node)) {
42
- cyclomatic++; // 三元运算符算作一个分支
43
- }
44
- // 逻辑运算符增加复杂度
45
- if (ts.isBinaryExpression(node)) {
46
- const operator = node.operatorToken.kind;
47
- if (operator === ts.SyntaxKind.AmpersandAmpersandToken ||
48
- operator === ts.SyntaxKind.BarBarToken) {
49
- // && 和 || 每个增加一个分支
50
- cyclomatic++;
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 (ts.isIfStatement(node) || ts.isWhileStatement(node) ||
56
- ts.isForStatement(node) || ts.isForInStatement(node) ||
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
- const kind = ts.isFunctionDeclaration(node) ? 'function' : ts.isMethodDeclaration(node) ? 'method' : 'constructor';
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
- line: start.line + 1,
131
- cyclomatic,
132
- cognitive: cyclomatic + maxDepth * 2,
133
- nestingDepth: maxDepth
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, collectFunctions);
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
- collectFunctions(sourceFile);
139
- // 统计类数量
140
- let classCount = 0;
141
- function countClasses(n) {
142
- if (ts.isClassDeclaration(n)) {
143
- classCount++;
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
- ts.forEachChild(n, countClasses);
146
- }
147
- countClasses(sourceFile);
148
- // 计算文件级别的圈复杂度
149
- let fileCyclomatic = 1;
150
- function countFileControlFlow(n) {
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
- // switch 语句: 每个 case 增加复杂度 (不包括 default)
157
- if (ts.isCaseClause(n)) {
158
- fileCyclomatic++;
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 (ts.isConditionalExpression(n)) {
162
- fileCyclomatic++;
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
- if (ts.isBinaryExpression(n)) {
165
- const operator = n.operatorToken.kind;
166
- if (operator === ts.SyntaxKind.AmpersandAmpersandToken ||
167
- operator === ts.SyntaxKind.BarBarToken) {
168
- fileCyclomatic++;
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
- countFileControlFlow(sourceFile);
174
- // 计算认知复杂度(考虑嵌套)
175
- let maxNesting = 0;
176
- function countNesting(n, depth) {
177
- if (ts.isIfStatement(n) || ts.isWhileStatement(n) ||
178
- ts.isForStatement(n) || ts.isForInStatement(n) ||
179
- ts.isForOfStatement(n) || ts.isSwitchStatement(n) ||
180
- ts.isTryStatement(n)) {
181
- maxNesting = Math.max(maxNesting, depth + 1);
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
- ts.forEachChild(n, child => countNesting(child, ts.isBlock(n) ? depth : depth));
344
+ braceDepth += countRegexMatches(rawLine, /{/g) - countRegexMatches(rawLine, /}/g);
184
345
  }
185
- countNesting(sourceFile, 0);
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
- filePath,
194
- relativePath: path.basename(filePath),
195
- cyclomatic: fileCyclomatic,
196
- cognitive: fileCognitive,
197
- maintainability,
198
- functions: allFunctions.length,
199
- classes: classCount,
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
- function calculateMaintainabilityIndex(loc, cyclomatic, commentRatio) {
217
- const normalizedLOC = Math.max(1, loc);
218
- const normalizedCC = Math.max(1, cyclomatic);
219
- let mi = 100;
220
- mi -= (normalizedCC - 1) * 2;
221
- mi -= Math.log(normalizedLOC / 10 + 1) * 5;
222
- mi += commentRatio * 15;
223
- return Math.max(0, Math.min(100, Math.round(mi)));
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
- return analyzeFileWithAST(filePath, sourceCode);
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, f) => sum + f.cyclomatic, 0);
265
- const totalCognitive = files.reduce((sum, f) => sum + f.cognitive, 0);
266
- const totalMaintainability = files.reduce((sum, f) => sum + f.maintainability, 0);
267
- const highComplexityFunctions = files.reduce((sum, f) => sum + f.functionDetails.filter(d => d.isHighComplexity).length, 0);
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