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