@mycodemap/mycodemap 2.0.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 (424) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +59 -184
  3. package/dist/cli/commands/agent-metrics/human.d.ts +4 -0
  4. package/dist/cli/commands/agent-metrics/human.d.ts.map +1 -0
  5. package/dist/cli/commands/agent-metrics/human.js +134 -0
  6. package/dist/cli/commands/agent-metrics/human.js.map +1 -0
  7. package/dist/cli/commands/agent-metrics/index.d.ts +15 -0
  8. package/dist/cli/commands/agent-metrics/index.d.ts.map +1 -0
  9. package/dist/cli/commands/agent-metrics/index.js +116 -0
  10. package/dist/cli/commands/agent-metrics/index.js.map +1 -0
  11. package/dist/cli/commands/analyze.d.ts +3 -196
  12. package/dist/cli/commands/analyze.d.ts.map +1 -1
  13. package/dist/cli/commands/analyze.js +9 -1163
  14. package/dist/cli/commands/analyze.js.map +1 -1
  15. package/dist/cli/commands/benchmark.d.ts.map +1 -1
  16. package/dist/cli/commands/benchmark.js +5 -2
  17. package/dist/cli/commands/benchmark.js.map +1 -1
  18. package/dist/cli/commands/complexity.d.ts.map +1 -1
  19. package/dist/cli/commands/complexity.js +62 -95
  20. package/dist/cli/commands/complexity.js.map +1 -1
  21. package/dist/cli/commands/deps.d.ts +3 -60
  22. package/dist/cli/commands/deps.d.ts.map +1 -1
  23. package/dist/cli/commands/deps.js +16 -351
  24. package/dist/cli/commands/deps.js.map +1 -1
  25. package/dist/cli/commands/env-contract.d.ts +3 -0
  26. package/dist/cli/commands/env-contract.d.ts.map +1 -0
  27. package/dist/cli/commands/env-contract.js +221 -0
  28. package/dist/cli/commands/env-contract.js.map +1 -0
  29. package/dist/cli/commands/generate.d.ts +19 -1
  30. package/dist/cli/commands/generate.d.ts.map +1 -1
  31. package/dist/cli/commands/generate.js +735 -89
  32. package/dist/cli/commands/generate.js.map +1 -1
  33. package/dist/cli/commands/impact.d.ts +4 -38
  34. package/dist/cli/commands/impact.d.ts.map +1 -1
  35. package/dist/cli/commands/impact.js +133 -375
  36. package/dist/cli/commands/impact.js.map +1 -1
  37. package/dist/cli/commands/init.d.ts +1 -0
  38. package/dist/cli/commands/init.d.ts.map +1 -1
  39. package/dist/cli/commands/init.js +61 -2
  40. package/dist/cli/commands/init.js.map +1 -1
  41. package/dist/cli/commands/preview.d.ts +3 -0
  42. package/dist/cli/commands/preview.d.ts.map +1 -0
  43. package/dist/cli/commands/preview.js +216 -0
  44. package/dist/cli/commands/preview.js.map +1 -0
  45. package/dist/cli/commands/query.d.ts +2 -21
  46. package/dist/cli/commands/query.d.ts.map +1 -1
  47. package/dist/cli/commands/query.js +15 -683
  48. package/dist/cli/commands/query.js.map +1 -1
  49. package/dist/cli/commands/watch-foreground.d.ts.map +1 -1
  50. package/dist/cli/commands/watch-foreground.js +5 -1
  51. package/dist/cli/commands/watch-foreground.js.map +1 -1
  52. package/dist/cli/config-loader.d.ts.map +1 -1
  53. package/dist/cli/config-loader.js +51 -13
  54. package/dist/cli/config-loader.js.map +1 -1
  55. package/dist/cli/doctor/check-env-contract.d.ts +3 -0
  56. package/dist/cli/doctor/check-env-contract.d.ts.map +1 -0
  57. package/dist/cli/doctor/check-env-contract.js +96 -0
  58. package/dist/cli/doctor/check-env-contract.js.map +1 -0
  59. package/dist/cli/doctor/check-native-deps.d.ts.map +1 -1
  60. package/dist/cli/doctor/check-native-deps.js +20 -4
  61. package/dist/cli/doctor/check-native-deps.js.map +1 -1
  62. package/dist/cli/doctor/orchestrator.d.ts.map +1 -1
  63. package/dist/cli/doctor/orchestrator.js +5 -2
  64. package/dist/cli/doctor/orchestrator.js.map +1 -1
  65. package/dist/cli/env-contract/check.d.ts +18 -0
  66. package/dist/cli/env-contract/check.d.ts.map +1 -0
  67. package/dist/cli/env-contract/check.js +118 -0
  68. package/dist/cli/env-contract/check.js.map +1 -0
  69. package/dist/cli/env-contract/discovery.d.ts +12 -0
  70. package/dist/cli/env-contract/discovery.d.ts.map +1 -0
  71. package/dist/cli/env-contract/discovery.js +249 -0
  72. package/dist/cli/env-contract/discovery.js.map +1 -0
  73. package/dist/cli/env-contract/filters.d.ts +10 -0
  74. package/dist/cli/env-contract/filters.d.ts.map +1 -0
  75. package/dist/cli/env-contract/filters.js +23 -0
  76. package/dist/cli/env-contract/filters.js.map +1 -0
  77. package/dist/cli/env-contract/index.d.ts +6 -0
  78. package/dist/cli/env-contract/index.d.ts.map +1 -0
  79. package/dist/cli/env-contract/index.js +8 -0
  80. package/dist/cli/env-contract/index.js.map +1 -0
  81. package/dist/cli/env-contract/reminder-engine.d.ts +34 -0
  82. package/dist/cli/env-contract/reminder-engine.d.ts.map +1 -0
  83. package/dist/cli/env-contract/reminder-engine.js +51 -0
  84. package/dist/cli/env-contract/reminder-engine.js.map +1 -0
  85. package/dist/cli/env-contract/reminder-hook-runner.d.ts +45 -0
  86. package/dist/cli/env-contract/reminder-hook-runner.d.ts.map +1 -0
  87. package/dist/cli/env-contract/reminder-hook-runner.js +273 -0
  88. package/dist/cli/env-contract/reminder-hook-runner.js.map +1 -0
  89. package/dist/cli/env-contract/reminder-ledger.d.ts +11 -0
  90. package/dist/cli/env-contract/reminder-ledger.d.ts.map +1 -0
  91. package/dist/cli/env-contract/reminder-ledger.js +37 -0
  92. package/dist/cli/env-contract/reminder-ledger.js.map +1 -0
  93. package/dist/cli/env-contract/types.d.ts +48 -0
  94. package/dist/cli/env-contract/types.d.ts.map +1 -0
  95. package/dist/cli/env-contract/types.js +22 -0
  96. package/dist/cli/env-contract/types.js.map +1 -0
  97. package/dist/cli/env-contract/validation.d.ts +10 -0
  98. package/dist/cli/env-contract/validation.d.ts.map +1 -0
  99. package/dist/cli/env-contract/validation.js +116 -0
  100. package/dist/cli/env-contract/validation.js.map +1 -0
  101. package/dist/cli/first-run-guide.d.ts.map +1 -1
  102. package/dist/cli/first-run-guide.js +8 -3
  103. package/dist/cli/first-run-guide.js.map +1 -1
  104. package/dist/cli/index.js +23 -3
  105. package/dist/cli/index.js.map +1 -1
  106. package/dist/cli/init/assistant-plan.d.ts +14 -0
  107. package/dist/cli/init/assistant-plan.d.ts.map +1 -0
  108. package/dist/cli/init/assistant-plan.js +208 -0
  109. package/dist/cli/init/assistant-plan.js.map +1 -0
  110. package/dist/cli/init/detect.d.ts +28 -0
  111. package/dist/cli/init/detect.d.ts.map +1 -0
  112. package/dist/cli/init/detect.js +63 -0
  113. package/dist/cli/init/detect.js.map +1 -0
  114. package/dist/cli/init/env-contract-plan.d.ts +28 -0
  115. package/dist/cli/init/env-contract-plan.d.ts.map +1 -0
  116. package/dist/cli/init/env-contract-plan.js +184 -0
  117. package/dist/cli/init/env-contract-plan.js.map +1 -0
  118. package/dist/cli/init/manifest-extractors.d.ts +22 -0
  119. package/dist/cli/init/manifest-extractors.d.ts.map +1 -0
  120. package/dist/cli/init/manifest-extractors.js +185 -0
  121. package/dist/cli/init/manifest-extractors.js.map +1 -0
  122. package/dist/cli/init/profile-loader.d.ts +49 -0
  123. package/dist/cli/init/profile-loader.d.ts.map +1 -0
  124. package/dist/cli/init/profile-loader.js +107 -0
  125. package/dist/cli/init/profile-loader.js.map +1 -0
  126. package/dist/cli/init/profile-plan.d.ts +38 -0
  127. package/dist/cli/init/profile-plan.d.ts.map +1 -0
  128. package/dist/cli/init/profile-plan.js +120 -0
  129. package/dist/cli/init/profile-plan.js.map +1 -0
  130. package/dist/cli/init/profiles/generic.json +16 -0
  131. package/dist/cli/init/profiles/go.json +12 -0
  132. package/dist/cli/init/profiles/nodejs.json +16 -0
  133. package/dist/cli/init/profiles/python.json +17 -0
  134. package/dist/cli/init/profiles/rust.json +12 -0
  135. package/dist/cli/init/receipt.d.ts.map +1 -1
  136. package/dist/cli/init/receipt.js +107 -7
  137. package/dist/cli/init/receipt.js.map +1 -1
  138. package/dist/cli/init/reconciler.d.ts +10 -1
  139. package/dist/cli/init/reconciler.d.ts.map +1 -1
  140. package/dist/cli/init/reconciler.js +85 -15
  141. package/dist/cli/init/reconciler.js.map +1 -1
  142. package/dist/cli/interface-contract/commands/agent-metrics.d.ts +3 -0
  143. package/dist/cli/interface-contract/commands/agent-metrics.d.ts.map +1 -0
  144. package/dist/cli/interface-contract/commands/agent-metrics.js +217 -0
  145. package/dist/cli/interface-contract/commands/agent-metrics.js.map +1 -0
  146. package/dist/cli/interface-contract/commands/analyze.d.ts.map +1 -1
  147. package/dist/cli/interface-contract/commands/analyze.js +1 -0
  148. package/dist/cli/interface-contract/commands/analyze.js.map +1 -1
  149. package/dist/cli/interface-contract/commands/benchmark.d.ts.map +1 -1
  150. package/dist/cli/interface-contract/commands/benchmark.js +1 -0
  151. package/dist/cli/interface-contract/commands/benchmark.js.map +1 -1
  152. package/dist/cli/interface-contract/commands/deps.d.ts.map +1 -1
  153. package/dist/cli/interface-contract/commands/deps.js +1 -0
  154. package/dist/cli/interface-contract/commands/deps.js.map +1 -1
  155. package/dist/cli/interface-contract/commands/doctor.d.ts.map +1 -1
  156. package/dist/cli/interface-contract/commands/doctor.js +1 -0
  157. package/dist/cli/interface-contract/commands/doctor.js.map +1 -1
  158. package/dist/cli/interface-contract/commands/env-contract.d.ts +3 -0
  159. package/dist/cli/interface-contract/commands/env-contract.d.ts.map +1 -0
  160. package/dist/cli/interface-contract/commands/env-contract.js +168 -0
  161. package/dist/cli/interface-contract/commands/env-contract.js.map +1 -0
  162. package/dist/cli/interface-contract/commands/index.d.ts +5 -2
  163. package/dist/cli/interface-contract/commands/index.d.ts.map +1 -1
  164. package/dist/cli/interface-contract/commands/index.js +7 -1
  165. package/dist/cli/interface-contract/commands/index.js.map +1 -1
  166. package/dist/cli/interface-contract/commands/init.d.ts.map +1 -1
  167. package/dist/cli/interface-contract/commands/init.js +9 -0
  168. package/dist/cli/interface-contract/commands/init.js.map +1 -1
  169. package/dist/cli/interface-contract/commands/preview.d.ts +3 -0
  170. package/dist/cli/interface-contract/commands/preview.d.ts.map +1 -0
  171. package/dist/cli/interface-contract/commands/preview.js +118 -0
  172. package/dist/cli/interface-contract/commands/preview.js.map +1 -0
  173. package/dist/cli/interface-contract/commands/query.d.ts.map +1 -1
  174. package/dist/cli/interface-contract/commands/query.js +1 -0
  175. package/dist/cli/interface-contract/commands/query.js.map +1 -1
  176. package/dist/cli/interface-contract/index.d.ts +1 -1
  177. package/dist/cli/interface-contract/index.d.ts.map +1 -1
  178. package/dist/cli/interface-contract/index.js +2 -2
  179. package/dist/cli/interface-contract/index.js.map +1 -1
  180. package/dist/cli/interface-contract/schema.d.ts.map +1 -1
  181. package/dist/cli/interface-contract/schema.js +1 -0
  182. package/dist/cli/interface-contract/schema.js.map +1 -1
  183. package/dist/cli/interface-contract/types.d.ts +1 -0
  184. package/dist/cli/interface-contract/types.d.ts.map +1 -1
  185. package/dist/cli/output/error-codes.d.ts +2 -0
  186. package/dist/cli/output/error-codes.d.ts.map +1 -1
  187. package/dist/cli/output/error-codes.js +12 -0
  188. package/dist/cli/output/error-codes.js.map +1 -1
  189. package/dist/cli/output/errors.d.ts.map +1 -1
  190. package/dist/cli/output/errors.js +12 -0
  191. package/dist/cli/output/errors.js.map +1 -1
  192. package/dist/cli/output/wasm-fallback.d.ts +1 -0
  193. package/dist/cli/output/wasm-fallback.d.ts.map +1 -1
  194. package/dist/cli/output/wasm-fallback.js.map +1 -1
  195. package/dist/cli/preview/complexity-scanner.d.ts +21 -0
  196. package/dist/cli/preview/complexity-scanner.d.ts.map +1 -0
  197. package/dist/cli/preview/complexity-scanner.js +52 -0
  198. package/dist/cli/preview/complexity-scanner.js.map +1 -0
  199. package/dist/cli/preview/dependency-extractor.d.ts +38 -0
  200. package/dist/cli/preview/dependency-extractor.d.ts.map +1 -0
  201. package/dist/cli/preview/dependency-extractor.js +140 -0
  202. package/dist/cli/preview/dependency-extractor.js.map +1 -0
  203. package/dist/cli/preview/preview-renderer.d.ts +32 -0
  204. package/dist/cli/preview/preview-renderer.d.ts.map +1 -0
  205. package/dist/cli/preview/preview-renderer.js +54 -0
  206. package/dist/cli/preview/preview-renderer.js.map +1 -0
  207. package/dist/cli/storage-runtime.d.ts +7 -0
  208. package/dist/cli/storage-runtime.d.ts.map +1 -1
  209. package/dist/cli/storage-runtime.js +22 -0
  210. package/dist/cli/storage-runtime.js.map +1 -1
  211. package/dist/cli-new/index.js +1 -1
  212. package/dist/cli-new/index.js.map +1 -1
  213. package/dist/composition/parser-composition.d.ts +7 -0
  214. package/dist/composition/parser-composition.d.ts.map +1 -0
  215. package/dist/composition/parser-composition.js +15 -0
  216. package/dist/composition/parser-composition.js.map +1 -0
  217. package/dist/core/analyzer.d.ts.map +1 -1
  218. package/dist/core/analyzer.js +83 -67
  219. package/dist/core/analyzer.js.map +1 -1
  220. package/dist/core/ast-complexity-analyzer.d.ts +12 -6
  221. package/dist/core/ast-complexity-analyzer.d.ts.map +1 -1
  222. package/dist/core/ast-complexity-analyzer.js +368 -209
  223. package/dist/core/ast-complexity-analyzer.js.map +1 -1
  224. package/dist/core/file-discovery.d.ts +1 -1
  225. package/dist/core/file-discovery.d.ts.map +1 -1
  226. package/dist/core/file-discovery.js +3 -0
  227. package/dist/core/file-discovery.js.map +1 -1
  228. package/dist/core/global-index.d.ts +3 -1
  229. package/dist/core/global-index.d.ts.map +1 -1
  230. package/dist/core/global-index.js +69 -4
  231. package/dist/core/global-index.js.map +1 -1
  232. package/dist/domain/entities/CodeGraph.d.ts +3 -0
  233. package/dist/domain/entities/CodeGraph.d.ts.map +1 -1
  234. package/dist/domain/entities/CodeGraph.js +19 -2
  235. package/dist/domain/entities/CodeGraph.js.map +1 -1
  236. package/dist/domain/entities/Dependency.d.ts +5 -2
  237. package/dist/domain/entities/Dependency.d.ts.map +1 -1
  238. package/dist/domain/entities/Dependency.js +49 -3
  239. package/dist/domain/entities/Dependency.js.map +1 -1
  240. package/dist/domain/repositories/CodeGraphRepository.d.ts +5 -0
  241. package/dist/domain/repositories/CodeGraphRepository.d.ts.map +1 -1
  242. package/dist/domain/repositories/CodeGraphRepository.js.map +1 -1
  243. package/dist/execution/contract-tools/analyze.d.ts +205 -0
  244. package/dist/execution/contract-tools/analyze.d.ts.map +1 -0
  245. package/dist/execution/contract-tools/analyze.js +1215 -0
  246. package/dist/execution/contract-tools/analyze.js.map +1 -0
  247. package/dist/execution/contract-tools/deps.d.ts +62 -0
  248. package/dist/execution/contract-tools/deps.d.ts.map +1 -0
  249. package/dist/execution/contract-tools/deps.js +234 -0
  250. package/dist/execution/contract-tools/deps.js.map +1 -0
  251. package/dist/execution/contract-tools/index.d.ts +5 -0
  252. package/dist/execution/contract-tools/index.d.ts.map +1 -0
  253. package/dist/execution/contract-tools/index.js +7 -0
  254. package/dist/execution/contract-tools/index.js.map +1 -0
  255. package/dist/execution/contract-tools/query.d.ts +60 -0
  256. package/dist/execution/contract-tools/query.d.ts.map +1 -0
  257. package/dist/execution/contract-tools/query.js +532 -0
  258. package/dist/execution/contract-tools/query.js.map +1 -0
  259. package/dist/execution/contract-tools/types.d.ts +26 -0
  260. package/dist/execution/contract-tools/types.d.ts.map +1 -0
  261. package/dist/execution/contract-tools/types.js +32 -0
  262. package/dist/execution/contract-tools/types.js.map +1 -0
  263. package/dist/generator/index.d.ts.map +1 -1
  264. package/dist/generator/index.js +0 -3
  265. package/dist/generator/index.js.map +1 -1
  266. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.d.ts +12 -0
  267. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.d.ts.map +1 -0
  268. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.js +55 -0
  269. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.js.map +1 -0
  270. package/dist/infrastructure/parser/implementations/GoParser.d.ts +2 -1
  271. package/dist/infrastructure/parser/implementations/GoParser.d.ts.map +1 -1
  272. package/dist/infrastructure/parser/implementations/GoParser.js +13 -1
  273. package/dist/infrastructure/parser/implementations/GoParser.js.map +1 -1
  274. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.d.ts +114 -0
  275. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.d.ts.map +1 -0
  276. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.js +1022 -0
  277. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.js.map +1 -0
  278. package/dist/infrastructure/parser/implementations/TreeSitterParser.d.ts +78 -0
  279. package/dist/infrastructure/parser/implementations/TreeSitterParser.d.ts.map +1 -0
  280. package/dist/infrastructure/parser/implementations/TreeSitterParser.js +648 -0
  281. package/dist/infrastructure/parser/implementations/TreeSitterParser.js.map +1 -0
  282. package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts +3 -55
  283. package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts.map +1 -1
  284. package/dist/infrastructure/parser/implementations/TypeScriptParser.js +4 -411
  285. package/dist/infrastructure/parser/implementations/TypeScriptParser.js.map +1 -1
  286. package/dist/infrastructure/parser/index.d.ts +2 -0
  287. package/dist/infrastructure/parser/index.d.ts.map +1 -1
  288. package/dist/infrastructure/parser/index.js +9 -6
  289. package/dist/infrastructure/parser/index.js.map +1 -1
  290. package/dist/infrastructure/parser/interfaces/ParserBase.d.ts.map +1 -1
  291. package/dist/infrastructure/parser/interfaces/ParserBase.js +1 -0
  292. package/dist/infrastructure/parser/interfaces/ParserBase.js.map +1 -1
  293. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts +2 -0
  294. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts.map +1 -1
  295. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js +4 -0
  296. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js.map +1 -1
  297. package/dist/infrastructure/storage/StorageFactory.d.ts +5 -18
  298. package/dist/infrastructure/storage/StorageFactory.d.ts.map +1 -1
  299. package/dist/infrastructure/storage/StorageFactory.js +30 -98
  300. package/dist/infrastructure/storage/StorageFactory.js.map +1 -1
  301. package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts +13 -1
  302. package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts.map +1 -1
  303. package/dist/infrastructure/storage/adapters/SQLiteStorage.js +321 -75
  304. package/dist/infrastructure/storage/adapters/SQLiteStorage.js.map +1 -1
  305. package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts +22 -0
  306. package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts.map +1 -1
  307. package/dist/infrastructure/storage/adapters/sqlite-loader.js +78 -22
  308. package/dist/infrastructure/storage/adapters/sqlite-loader.js.map +1 -1
  309. package/dist/infrastructure/storage/community-helpers.d.ts +4 -0
  310. package/dist/infrastructure/storage/community-helpers.d.ts.map +1 -0
  311. package/dist/infrastructure/storage/community-helpers.js +392 -0
  312. package/dist/infrastructure/storage/community-helpers.js.map +1 -0
  313. package/dist/infrastructure/storage/graph-helpers.d.ts +22 -5
  314. package/dist/infrastructure/storage/graph-helpers.d.ts.map +1 -1
  315. package/dist/infrastructure/storage/graph-helpers.js +496 -91
  316. package/dist/infrastructure/storage/graph-helpers.js.map +1 -1
  317. package/dist/infrastructure/storage/index.d.ts +1 -1
  318. package/dist/infrastructure/storage/index.d.ts.map +1 -1
  319. package/dist/infrastructure/storage/index.js +1 -1
  320. package/dist/infrastructure/storage/index.js.map +1 -1
  321. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts +2 -2
  322. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts.map +1 -1
  323. package/dist/infrastructure/storage/interfaces/StorageBase.js.map +1 -1
  324. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts +2 -0
  325. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts.map +1 -1
  326. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js +52 -12
  327. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js.map +1 -1
  328. package/dist/infrastructure/storage/sqlite/schema.d.ts +2 -2
  329. package/dist/infrastructure/storage/sqlite/schema.d.ts.map +1 -1
  330. package/dist/infrastructure/storage/sqlite/schema.js +49 -1
  331. package/dist/infrastructure/storage/sqlite/schema.js.map +1 -1
  332. package/dist/interface/config/index.d.ts +5 -3
  333. package/dist/interface/config/index.d.ts.map +1 -1
  334. package/dist/interface/types/index.d.ts +37 -6
  335. package/dist/interface/types/index.d.ts.map +1 -1
  336. package/dist/interface/types/parser.d.ts +85 -0
  337. package/dist/interface/types/parser.d.ts.map +1 -1
  338. package/dist/interface/types/storage.d.ts +227 -10
  339. package/dist/interface/types/storage.d.ts.map +1 -1
  340. package/dist/orchestrator/agent-metrics-service.d.ts +126 -0
  341. package/dist/orchestrator/agent-metrics-service.d.ts.map +1 -0
  342. package/dist/orchestrator/agent-metrics-service.js +444 -0
  343. package/dist/orchestrator/agent-metrics-service.js.map +1 -0
  344. package/dist/parser/enhancers/PythonTypeEnhancer.d.ts +26 -0
  345. package/dist/parser/enhancers/PythonTypeEnhancer.d.ts.map +1 -0
  346. package/dist/parser/enhancers/PythonTypeEnhancer.js +440 -0
  347. package/dist/parser/enhancers/PythonTypeEnhancer.js.map +1 -0
  348. package/dist/parser/implementations/smart-parser.d.ts.map +1 -1
  349. package/dist/parser/implementations/smart-parser.js +7 -69
  350. package/dist/parser/implementations/smart-parser.js.map +1 -1
  351. package/dist/parser/implementations/tree-sitter-loader.d.ts +2 -0
  352. package/dist/parser/implementations/tree-sitter-loader.d.ts.map +1 -1
  353. package/dist/parser/implementations/tree-sitter-loader.js +46 -15
  354. package/dist/parser/implementations/tree-sitter-loader.js.map +1 -1
  355. package/dist/parser/index.d.ts +5 -3
  356. package/dist/parser/index.d.ts.map +1 -1
  357. package/dist/parser/index.js +68 -6
  358. package/dist/parser/index.js.map +1 -1
  359. package/dist/parser/interfaces/IParser.d.ts +19 -6
  360. package/dist/parser/interfaces/IParser.d.ts.map +1 -1
  361. package/dist/parser/interfaces/IParser.js +2 -3
  362. package/dist/parser/interfaces/IParser.js.map +1 -1
  363. package/dist/server/handlers/AnalysisHandler.d.ts +13 -2
  364. package/dist/server/handlers/AnalysisHandler.d.ts.map +1 -1
  365. package/dist/server/handlers/AnalysisHandler.js +24 -0
  366. package/dist/server/handlers/AnalysisHandler.js.map +1 -1
  367. package/dist/server/handlers/QueryHandler.d.ts.map +1 -1
  368. package/dist/server/handlers/QueryHandler.js +11 -30
  369. package/dist/server/handlers/QueryHandler.js.map +1 -1
  370. package/dist/server/mcp/context-tool.d.ts +9 -0
  371. package/dist/server/mcp/context-tool.d.ts.map +1 -0
  372. package/dist/server/mcp/context-tool.js +257 -0
  373. package/dist/server/mcp/context-tool.js.map +1 -0
  374. package/dist/server/mcp/schema-adapter.d.ts +11 -1
  375. package/dist/server/mcp/schema-adapter.d.ts.map +1 -1
  376. package/dist/server/mcp/schema-adapter.js +126 -7
  377. package/dist/server/mcp/schema-adapter.js.map +1 -1
  378. package/dist/server/mcp/server.d.ts +3 -3
  379. package/dist/server/mcp/server.d.ts.map +1 -1
  380. package/dist/server/mcp/server.js +114 -30
  381. package/dist/server/mcp/server.js.map +1 -1
  382. package/dist/server/mcp/service.d.ts +6 -2
  383. package/dist/server/mcp/service.d.ts.map +1 -1
  384. package/dist/server/mcp/service.js +138 -36
  385. package/dist/server/mcp/service.js.map +1 -1
  386. package/dist/server/mcp/stdio-transport.d.ts +23 -0
  387. package/dist/server/mcp/stdio-transport.d.ts.map +1 -0
  388. package/dist/server/mcp/stdio-transport.js +101 -0
  389. package/dist/server/mcp/stdio-transport.js.map +1 -0
  390. package/dist/server/mcp/types.d.ts +133 -8
  391. package/dist/server/mcp/types.d.ts.map +1 -1
  392. package/dist/server/routes/api.d.ts.map +1 -1
  393. package/dist/server/routes/api.js +11 -2
  394. package/dist/server/routes/api.js.map +1 -1
  395. package/docs/AI_ASSISTANT_SETUP.md +112 -0
  396. package/docs/API.md +170 -0
  397. package/docs/CONFIGURATION.md +141 -0
  398. package/docs/DEVELOPMENT.md +96 -0
  399. package/docs/GETTING-STARTED.md +114 -0
  400. package/docs/SETUP_GUIDE.md +49 -0
  401. package/docs/TESTING.md +81 -0
  402. package/docs/ai-guide/OUTPUT.md +51 -8
  403. package/docs/backlog.md +232 -144
  404. package/docs/brainstorms/2026-05-10-agent-effectiveness-validation-requirements.md +112 -0
  405. package/docs/generated/phase-58/subagent-evidence/claude-hook-example.json +15 -0
  406. package/docs/generated/phase-58/subagent-evidence/claude-session.md +146 -0
  407. package/docs/generated/phase-58/subagent-evidence/claude-subagent.json +28 -0
  408. package/docs/generated/phase-58/subagent-evidence/codex-agent-example.toml +19 -0
  409. package/docs/generated/phase-58/subagent-evidence/codex-session.md +150 -0
  410. package/docs/generated/phase-58/subagent-evidence/codex-subagent.json +20 -0
  411. package/docs/generated/phase-58/subagent-evidence/negative-no-retrieval.json +12 -0
  412. package/docs/generated/phase-58/subagent-evidence/verification-manifest.json +19 -0
  413. package/docs/ideation/2026-05-02-subagent-environment-contract-injection-ideation.md +183 -0
  414. package/docs/ideation/2026-05-04-subagent-hooks-deep-dive-ideation.md +133 -0
  415. package/docs/ideation/2026-05-10-agent-effectiveness-validation-ideation.md +219 -0
  416. package/package.json +8 -3
  417. package/scripts/copy-build-assets.mjs +23 -0
  418. package/scripts/hooks/templates/pre-commit +33 -2
  419. package/scripts/tests/test_rule_control_workflow.py +15 -1
  420. package/scripts/verify-subagent-env-contract.mjs +279 -0
  421. package/dist/parser/implementations/tree-sitter-parser.d.ts +0 -60
  422. package/dist/parser/implementations/tree-sitter-parser.d.ts.map +0 -1
  423. package/dist/parser/implementations/tree-sitter-parser.js +0 -380
  424. package/dist/parser/implementations/tree-sitter-parser.js.map +0 -1
@@ -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