@mycodemap/mycodemap 1.9.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (527) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +63 -978
  3. package/README.zh-CN.md +1096 -0
  4. package/dist/cli/commands/agent-metrics/human.d.ts +4 -0
  5. package/dist/cli/commands/agent-metrics/human.d.ts.map +1 -0
  6. package/dist/cli/commands/agent-metrics/human.js +134 -0
  7. package/dist/cli/commands/agent-metrics/human.js.map +1 -0
  8. package/dist/cli/commands/agent-metrics/index.d.ts +15 -0
  9. package/dist/cli/commands/agent-metrics/index.d.ts.map +1 -0
  10. package/dist/cli/commands/agent-metrics/index.js +116 -0
  11. package/dist/cli/commands/agent-metrics/index.js.map +1 -0
  12. package/dist/cli/commands/analyze-options.d.ts.map +1 -1
  13. package/dist/cli/commands/analyze-options.js +8 -0
  14. package/dist/cli/commands/analyze-options.js.map +1 -1
  15. package/dist/cli/commands/analyze.d.ts +3 -196
  16. package/dist/cli/commands/analyze.d.ts.map +1 -1
  17. package/dist/cli/commands/analyze.js +27 -1162
  18. package/dist/cli/commands/analyze.js.map +1 -1
  19. package/dist/cli/commands/benchmark.d.ts +8 -0
  20. package/dist/cli/commands/benchmark.d.ts.map +1 -0
  21. package/dist/cli/commands/benchmark.js +153 -0
  22. package/dist/cli/commands/benchmark.js.map +1 -0
  23. package/dist/cli/commands/complexity.d.ts.map +1 -1
  24. package/dist/cli/commands/complexity.js +62 -95
  25. package/dist/cli/commands/complexity.js.map +1 -1
  26. package/dist/cli/commands/deps.d.ts +3 -59
  27. package/dist/cli/commands/deps.d.ts.map +1 -1
  28. package/dist/cli/commands/deps.js +25 -331
  29. package/dist/cli/commands/deps.js.map +1 -1
  30. package/dist/cli/commands/doctor.d.ts +3 -0
  31. package/dist/cli/commands/doctor.d.ts.map +1 -0
  32. package/dist/cli/commands/doctor.js +34 -0
  33. package/dist/cli/commands/doctor.js.map +1 -0
  34. package/dist/cli/commands/env-contract.d.ts +3 -0
  35. package/dist/cli/commands/env-contract.d.ts.map +1 -0
  36. package/dist/cli/commands/env-contract.js +221 -0
  37. package/dist/cli/commands/env-contract.js.map +1 -0
  38. package/dist/cli/commands/generate.d.ts +19 -1
  39. package/dist/cli/commands/generate.d.ts.map +1 -1
  40. package/dist/cli/commands/generate.js +735 -89
  41. package/dist/cli/commands/generate.js.map +1 -1
  42. package/dist/cli/commands/impact.d.ts +4 -38
  43. package/dist/cli/commands/impact.d.ts.map +1 -1
  44. package/dist/cli/commands/impact.js +133 -375
  45. package/dist/cli/commands/impact.js.map +1 -1
  46. package/dist/cli/commands/init.d.ts +1 -0
  47. package/dist/cli/commands/init.d.ts.map +1 -1
  48. package/dist/cli/commands/init.js +61 -2
  49. package/dist/cli/commands/init.js.map +1 -1
  50. package/dist/cli/commands/preview.d.ts +3 -0
  51. package/dist/cli/commands/preview.d.ts.map +1 -0
  52. package/dist/cli/commands/preview.js +216 -0
  53. package/dist/cli/commands/preview.js.map +1 -0
  54. package/dist/cli/commands/query.d.ts +2 -20
  55. package/dist/cli/commands/query.d.ts.map +1 -1
  56. package/dist/cli/commands/query.js +23 -708
  57. package/dist/cli/commands/query.js.map +1 -1
  58. package/dist/cli/commands/watch-foreground.d.ts.map +1 -1
  59. package/dist/cli/commands/watch-foreground.js +5 -1
  60. package/dist/cli/commands/watch-foreground.js.map +1 -1
  61. package/dist/cli/config-loader.d.ts.map +1 -1
  62. package/dist/cli/config-loader.js +51 -13
  63. package/dist/cli/config-loader.js.map +1 -1
  64. package/dist/cli/doctor/check-agent.d.ts +3 -0
  65. package/dist/cli/doctor/check-agent.d.ts.map +1 -0
  66. package/dist/cli/doctor/check-agent.js +60 -0
  67. package/dist/cli/doctor/check-agent.js.map +1 -0
  68. package/dist/cli/doctor/check-env-contract.d.ts +3 -0
  69. package/dist/cli/doctor/check-env-contract.d.ts.map +1 -0
  70. package/dist/cli/doctor/check-env-contract.js +96 -0
  71. package/dist/cli/doctor/check-env-contract.js.map +1 -0
  72. package/dist/cli/doctor/check-ghost-commands.d.ts +3 -0
  73. package/dist/cli/doctor/check-ghost-commands.d.ts.map +1 -0
  74. package/dist/cli/doctor/check-ghost-commands.js +86 -0
  75. package/dist/cli/doctor/check-ghost-commands.js.map +1 -0
  76. package/dist/cli/doctor/check-native-deps.d.ts +3 -0
  77. package/dist/cli/doctor/check-native-deps.d.ts.map +1 -0
  78. package/dist/cli/doctor/check-native-deps.js +70 -0
  79. package/dist/cli/doctor/check-native-deps.js.map +1 -0
  80. package/dist/cli/doctor/check-workspace-drift.d.ts +3 -0
  81. package/dist/cli/doctor/check-workspace-drift.d.ts.map +1 -0
  82. package/dist/cli/doctor/check-workspace-drift.js +83 -0
  83. package/dist/cli/doctor/check-workspace-drift.js.map +1 -0
  84. package/dist/cli/doctor/formatter.d.ts +20 -0
  85. package/dist/cli/doctor/formatter.d.ts.map +1 -0
  86. package/dist/cli/doctor/formatter.js +91 -0
  87. package/dist/cli/doctor/formatter.js.map +1 -0
  88. package/dist/cli/doctor/index.d.ts +8 -0
  89. package/dist/cli/doctor/index.d.ts.map +1 -0
  90. package/dist/cli/doctor/index.js +9 -0
  91. package/dist/cli/doctor/index.js.map +1 -0
  92. package/dist/cli/doctor/orchestrator.d.ts +3 -0
  93. package/dist/cli/doctor/orchestrator.d.ts.map +1 -0
  94. package/dist/cli/doctor/orchestrator.js +40 -0
  95. package/dist/cli/doctor/orchestrator.js.map +1 -0
  96. package/dist/cli/doctor/types.d.ts +19 -0
  97. package/dist/cli/doctor/types.d.ts.map +1 -0
  98. package/dist/cli/doctor/types.js +4 -0
  99. package/dist/cli/doctor/types.js.map +1 -0
  100. package/dist/cli/env-contract/check.d.ts +18 -0
  101. package/dist/cli/env-contract/check.d.ts.map +1 -0
  102. package/dist/cli/env-contract/check.js +118 -0
  103. package/dist/cli/env-contract/check.js.map +1 -0
  104. package/dist/cli/env-contract/discovery.d.ts +12 -0
  105. package/dist/cli/env-contract/discovery.d.ts.map +1 -0
  106. package/dist/cli/env-contract/discovery.js +249 -0
  107. package/dist/cli/env-contract/discovery.js.map +1 -0
  108. package/dist/cli/env-contract/filters.d.ts +10 -0
  109. package/dist/cli/env-contract/filters.d.ts.map +1 -0
  110. package/dist/cli/env-contract/filters.js +23 -0
  111. package/dist/cli/env-contract/filters.js.map +1 -0
  112. package/dist/cli/env-contract/index.d.ts +6 -0
  113. package/dist/cli/env-contract/index.d.ts.map +1 -0
  114. package/dist/cli/env-contract/index.js +8 -0
  115. package/dist/cli/env-contract/index.js.map +1 -0
  116. package/dist/cli/env-contract/reminder-engine.d.ts +34 -0
  117. package/dist/cli/env-contract/reminder-engine.d.ts.map +1 -0
  118. package/dist/cli/env-contract/reminder-engine.js +51 -0
  119. package/dist/cli/env-contract/reminder-engine.js.map +1 -0
  120. package/dist/cli/env-contract/reminder-hook-runner.d.ts +45 -0
  121. package/dist/cli/env-contract/reminder-hook-runner.d.ts.map +1 -0
  122. package/dist/cli/env-contract/reminder-hook-runner.js +273 -0
  123. package/dist/cli/env-contract/reminder-hook-runner.js.map +1 -0
  124. package/dist/cli/env-contract/reminder-ledger.d.ts +11 -0
  125. package/dist/cli/env-contract/reminder-ledger.d.ts.map +1 -0
  126. package/dist/cli/env-contract/reminder-ledger.js +37 -0
  127. package/dist/cli/env-contract/reminder-ledger.js.map +1 -0
  128. package/dist/cli/env-contract/types.d.ts +48 -0
  129. package/dist/cli/env-contract/types.d.ts.map +1 -0
  130. package/dist/cli/env-contract/types.js +22 -0
  131. package/dist/cli/env-contract/types.js.map +1 -0
  132. package/dist/cli/env-contract/validation.d.ts +10 -0
  133. package/dist/cli/env-contract/validation.d.ts.map +1 -0
  134. package/dist/cli/env-contract/validation.js +116 -0
  135. package/dist/cli/env-contract/validation.js.map +1 -0
  136. package/dist/cli/first-run-guide.d.ts.map +1 -1
  137. package/dist/cli/first-run-guide.js +8 -3
  138. package/dist/cli/first-run-guide.js.map +1 -1
  139. package/dist/cli/index.js +94 -22
  140. package/dist/cli/index.js.map +1 -1
  141. package/dist/cli/init/assistant-plan.d.ts +14 -0
  142. package/dist/cli/init/assistant-plan.d.ts.map +1 -0
  143. package/dist/cli/init/assistant-plan.js +208 -0
  144. package/dist/cli/init/assistant-plan.js.map +1 -0
  145. package/dist/cli/init/detect.d.ts +28 -0
  146. package/dist/cli/init/detect.d.ts.map +1 -0
  147. package/dist/cli/init/detect.js +63 -0
  148. package/dist/cli/init/detect.js.map +1 -0
  149. package/dist/cli/init/env-contract-plan.d.ts +28 -0
  150. package/dist/cli/init/env-contract-plan.d.ts.map +1 -0
  151. package/dist/cli/init/env-contract-plan.js +184 -0
  152. package/dist/cli/init/env-contract-plan.js.map +1 -0
  153. package/dist/cli/init/manifest-extractors.d.ts +22 -0
  154. package/dist/cli/init/manifest-extractors.d.ts.map +1 -0
  155. package/dist/cli/init/manifest-extractors.js +185 -0
  156. package/dist/cli/init/manifest-extractors.js.map +1 -0
  157. package/dist/cli/init/profile-loader.d.ts +49 -0
  158. package/dist/cli/init/profile-loader.d.ts.map +1 -0
  159. package/dist/cli/init/profile-loader.js +107 -0
  160. package/dist/cli/init/profile-loader.js.map +1 -0
  161. package/dist/cli/init/profile-plan.d.ts +38 -0
  162. package/dist/cli/init/profile-plan.d.ts.map +1 -0
  163. package/dist/cli/init/profile-plan.js +120 -0
  164. package/dist/cli/init/profile-plan.js.map +1 -0
  165. package/dist/cli/init/profiles/generic.json +16 -0
  166. package/dist/cli/init/profiles/go.json +12 -0
  167. package/dist/cli/init/profiles/nodejs.json +16 -0
  168. package/dist/cli/init/profiles/python.json +17 -0
  169. package/dist/cli/init/profiles/rust.json +12 -0
  170. package/dist/cli/init/receipt.d.ts.map +1 -1
  171. package/dist/cli/init/receipt.js +107 -7
  172. package/dist/cli/init/receipt.js.map +1 -1
  173. package/dist/cli/init/reconciler.d.ts +10 -1
  174. package/dist/cli/init/reconciler.d.ts.map +1 -1
  175. package/dist/cli/init/reconciler.js +85 -15
  176. package/dist/cli/init/reconciler.js.map +1 -1
  177. package/dist/cli/interface-contract/commands/agent-metrics.d.ts +3 -0
  178. package/dist/cli/interface-contract/commands/agent-metrics.d.ts.map +1 -0
  179. package/dist/cli/interface-contract/commands/agent-metrics.js +217 -0
  180. package/dist/cli/interface-contract/commands/agent-metrics.js.map +1 -0
  181. package/dist/cli/interface-contract/commands/analyze.d.ts +3 -0
  182. package/dist/cli/interface-contract/commands/analyze.d.ts.map +1 -0
  183. package/dist/cli/interface-contract/commands/analyze.js +139 -0
  184. package/dist/cli/interface-contract/commands/analyze.js.map +1 -0
  185. package/dist/cli/interface-contract/commands/benchmark.d.ts +3 -0
  186. package/dist/cli/interface-contract/commands/benchmark.d.ts.map +1 -0
  187. package/dist/cli/interface-contract/commands/benchmark.js +108 -0
  188. package/dist/cli/interface-contract/commands/benchmark.js.map +1 -0
  189. package/dist/cli/interface-contract/commands/deps.d.ts +3 -0
  190. package/dist/cli/interface-contract/commands/deps.d.ts.map +1 -0
  191. package/dist/cli/interface-contract/commands/deps.js +130 -0
  192. package/dist/cli/interface-contract/commands/deps.js.map +1 -0
  193. package/dist/cli/interface-contract/commands/doctor.d.ts +3 -0
  194. package/dist/cli/interface-contract/commands/doctor.d.ts.map +1 -0
  195. package/dist/cli/interface-contract/commands/doctor.js +60 -0
  196. package/dist/cli/interface-contract/commands/doctor.js.map +1 -0
  197. package/dist/cli/interface-contract/commands/env-contract.d.ts +3 -0
  198. package/dist/cli/interface-contract/commands/env-contract.d.ts.map +1 -0
  199. package/dist/cli/interface-contract/commands/env-contract.js +168 -0
  200. package/dist/cli/interface-contract/commands/env-contract.js.map +1 -0
  201. package/dist/cli/interface-contract/commands/index.d.ts +12 -0
  202. package/dist/cli/interface-contract/commands/index.d.ts.map +1 -0
  203. package/dist/cli/interface-contract/commands/index.js +24 -0
  204. package/dist/cli/interface-contract/commands/index.js.map +1 -0
  205. package/dist/cli/interface-contract/commands/init.d.ts +3 -0
  206. package/dist/cli/interface-contract/commands/init.d.ts.map +1 -0
  207. package/dist/cli/interface-contract/commands/init.js +96 -0
  208. package/dist/cli/interface-contract/commands/init.js.map +1 -0
  209. package/dist/cli/interface-contract/commands/preview.d.ts +3 -0
  210. package/dist/cli/interface-contract/commands/preview.d.ts.map +1 -0
  211. package/dist/cli/interface-contract/commands/preview.js +118 -0
  212. package/dist/cli/interface-contract/commands/preview.js.map +1 -0
  213. package/dist/cli/interface-contract/commands/query.d.ts +3 -0
  214. package/dist/cli/interface-contract/commands/query.d.ts.map +1 -0
  215. package/dist/cli/interface-contract/commands/query.js +186 -0
  216. package/dist/cli/interface-contract/commands/query.js.map +1 -0
  217. package/dist/cli/interface-contract/index.d.ts +22 -0
  218. package/dist/cli/interface-contract/index.d.ts.map +1 -0
  219. package/dist/cli/interface-contract/index.js +41 -0
  220. package/dist/cli/interface-contract/index.js.map +1 -0
  221. package/dist/cli/interface-contract/schema.d.ts +30 -0
  222. package/dist/cli/interface-contract/schema.d.ts.map +1 -0
  223. package/dist/cli/interface-contract/schema.js +73 -0
  224. package/dist/cli/interface-contract/schema.js.map +1 -0
  225. package/dist/cli/interface-contract/types.d.ts +77 -0
  226. package/dist/cli/interface-contract/types.d.ts.map +1 -0
  227. package/dist/cli/interface-contract/types.js +4 -0
  228. package/dist/cli/interface-contract/types.js.map +1 -0
  229. package/dist/cli/output/apply-suggestion.d.ts +12 -0
  230. package/dist/cli/output/apply-suggestion.d.ts.map +1 -0
  231. package/dist/cli/output/apply-suggestion.js +29 -0
  232. package/dist/cli/output/apply-suggestion.js.map +1 -0
  233. package/dist/cli/output/error-codes.d.ts +24 -0
  234. package/dist/cli/output/error-codes.d.ts.map +1 -0
  235. package/dist/cli/output/error-codes.js +94 -0
  236. package/dist/cli/output/error-codes.js.map +1 -0
  237. package/dist/cli/output/errors.d.ts +14 -0
  238. package/dist/cli/output/errors.d.ts.map +1 -0
  239. package/dist/cli/output/errors.js +182 -0
  240. package/dist/cli/output/errors.js.map +1 -0
  241. package/dist/cli/output/index.d.ts +13 -0
  242. package/dist/cli/output/index.d.ts.map +1 -0
  243. package/dist/cli/output/index.js +11 -0
  244. package/dist/cli/output/index.js.map +1 -0
  245. package/dist/cli/output/mode.d.ts +12 -0
  246. package/dist/cli/output/mode.d.ts.map +1 -0
  247. package/dist/cli/output/mode.js +23 -0
  248. package/dist/cli/output/mode.js.map +1 -0
  249. package/dist/cli/output/progress.d.ts +9 -0
  250. package/dist/cli/output/progress.d.ts.map +1 -0
  251. package/dist/cli/output/progress.js +65 -0
  252. package/dist/cli/output/progress.js.map +1 -0
  253. package/dist/cli/output/render.d.ts +11 -0
  254. package/dist/cli/output/render.d.ts.map +1 -0
  255. package/dist/cli/output/render.js +18 -0
  256. package/dist/cli/output/render.js.map +1 -0
  257. package/dist/cli/output/types.d.ts +53 -0
  258. package/dist/cli/output/types.d.ts.map +1 -0
  259. package/dist/cli/output/types.js +14 -0
  260. package/dist/cli/output/types.js.map +1 -0
  261. package/dist/cli/output/wasm-fallback.d.ts +14 -0
  262. package/dist/cli/output/wasm-fallback.d.ts.map +1 -0
  263. package/dist/cli/output/wasm-fallback.js +92 -0
  264. package/dist/cli/output/wasm-fallback.js.map +1 -0
  265. package/dist/cli/preview/complexity-scanner.d.ts +21 -0
  266. package/dist/cli/preview/complexity-scanner.d.ts.map +1 -0
  267. package/dist/cli/preview/complexity-scanner.js +52 -0
  268. package/dist/cli/preview/complexity-scanner.js.map +1 -0
  269. package/dist/cli/preview/dependency-extractor.d.ts +38 -0
  270. package/dist/cli/preview/dependency-extractor.d.ts.map +1 -0
  271. package/dist/cli/preview/dependency-extractor.js +140 -0
  272. package/dist/cli/preview/dependency-extractor.js.map +1 -0
  273. package/dist/cli/preview/preview-renderer.d.ts +32 -0
  274. package/dist/cli/preview/preview-renderer.d.ts.map +1 -0
  275. package/dist/cli/preview/preview-renderer.js +54 -0
  276. package/dist/cli/preview/preview-renderer.js.map +1 -0
  277. package/dist/cli/storage-runtime.d.ts +7 -0
  278. package/dist/cli/storage-runtime.d.ts.map +1 -1
  279. package/dist/cli/storage-runtime.js +22 -0
  280. package/dist/cli/storage-runtime.js.map +1 -1
  281. package/dist/cli/tree-sitter-check.d.ts +6 -1
  282. package/dist/cli/tree-sitter-check.d.ts.map +1 -1
  283. package/dist/cli/tree-sitter-check.js +23 -1
  284. package/dist/cli/tree-sitter-check.js.map +1 -1
  285. package/dist/cli-new/index.js +1 -1
  286. package/dist/cli-new/index.js.map +1 -1
  287. package/dist/composition/parser-composition.d.ts +7 -0
  288. package/dist/composition/parser-composition.d.ts.map +1 -0
  289. package/dist/composition/parser-composition.js +15 -0
  290. package/dist/composition/parser-composition.js.map +1 -0
  291. package/dist/core/analyzer.d.ts.map +1 -1
  292. package/dist/core/analyzer.js +83 -67
  293. package/dist/core/analyzer.js.map +1 -1
  294. package/dist/core/ast-complexity-analyzer.d.ts +12 -6
  295. package/dist/core/ast-complexity-analyzer.d.ts.map +1 -1
  296. package/dist/core/ast-complexity-analyzer.js +368 -209
  297. package/dist/core/ast-complexity-analyzer.js.map +1 -1
  298. package/dist/core/file-discovery.d.ts +1 -1
  299. package/dist/core/file-discovery.d.ts.map +1 -1
  300. package/dist/core/file-discovery.js +3 -0
  301. package/dist/core/file-discovery.js.map +1 -1
  302. package/dist/core/global-index.d.ts +3 -1
  303. package/dist/core/global-index.d.ts.map +1 -1
  304. package/dist/core/global-index.js +69 -4
  305. package/dist/core/global-index.js.map +1 -1
  306. package/dist/domain/entities/CodeGraph.d.ts +3 -0
  307. package/dist/domain/entities/CodeGraph.d.ts.map +1 -1
  308. package/dist/domain/entities/CodeGraph.js +19 -2
  309. package/dist/domain/entities/CodeGraph.js.map +1 -1
  310. package/dist/domain/entities/Dependency.d.ts +5 -2
  311. package/dist/domain/entities/Dependency.d.ts.map +1 -1
  312. package/dist/domain/entities/Dependency.js +49 -3
  313. package/dist/domain/entities/Dependency.js.map +1 -1
  314. package/dist/domain/repositories/CodeGraphRepository.d.ts +5 -0
  315. package/dist/domain/repositories/CodeGraphRepository.d.ts.map +1 -1
  316. package/dist/domain/repositories/CodeGraphRepository.js.map +1 -1
  317. package/dist/execution/contract-tools/analyze.d.ts +205 -0
  318. package/dist/execution/contract-tools/analyze.d.ts.map +1 -0
  319. package/dist/execution/contract-tools/analyze.js +1215 -0
  320. package/dist/execution/contract-tools/analyze.js.map +1 -0
  321. package/dist/execution/contract-tools/deps.d.ts +62 -0
  322. package/dist/execution/contract-tools/deps.d.ts.map +1 -0
  323. package/dist/execution/contract-tools/deps.js +234 -0
  324. package/dist/execution/contract-tools/deps.js.map +1 -0
  325. package/dist/execution/contract-tools/index.d.ts +5 -0
  326. package/dist/execution/contract-tools/index.d.ts.map +1 -0
  327. package/dist/execution/contract-tools/index.js +7 -0
  328. package/dist/execution/contract-tools/index.js.map +1 -0
  329. package/dist/execution/contract-tools/query.d.ts +60 -0
  330. package/dist/execution/contract-tools/query.d.ts.map +1 -0
  331. package/dist/execution/contract-tools/query.js +532 -0
  332. package/dist/execution/contract-tools/query.js.map +1 -0
  333. package/dist/execution/contract-tools/types.d.ts +26 -0
  334. package/dist/execution/contract-tools/types.d.ts.map +1 -0
  335. package/dist/execution/contract-tools/types.js +32 -0
  336. package/dist/execution/contract-tools/types.js.map +1 -0
  337. package/dist/generator/index.d.ts.map +1 -1
  338. package/dist/generator/index.js +0 -3
  339. package/dist/generator/index.js.map +1 -1
  340. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.d.ts +12 -0
  341. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.d.ts.map +1 -0
  342. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.js +55 -0
  343. package/dist/infrastructure/parser/enhancers/TypeScriptTypeEnhancer.js.map +1 -0
  344. package/dist/infrastructure/parser/implementations/GoParser.d.ts +2 -1
  345. package/dist/infrastructure/parser/implementations/GoParser.d.ts.map +1 -1
  346. package/dist/infrastructure/parser/implementations/GoParser.js +13 -1
  347. package/dist/infrastructure/parser/implementations/GoParser.js.map +1 -1
  348. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.d.ts +114 -0
  349. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.d.ts.map +1 -0
  350. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.js +1022 -0
  351. package/dist/infrastructure/parser/implementations/PythonTreeSitterParser.js.map +1 -0
  352. package/dist/infrastructure/parser/implementations/TreeSitterParser.d.ts +78 -0
  353. package/dist/infrastructure/parser/implementations/TreeSitterParser.d.ts.map +1 -0
  354. package/dist/infrastructure/parser/implementations/TreeSitterParser.js +648 -0
  355. package/dist/infrastructure/parser/implementations/TreeSitterParser.js.map +1 -0
  356. package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts +3 -55
  357. package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts.map +1 -1
  358. package/dist/infrastructure/parser/implementations/TypeScriptParser.js +4 -411
  359. package/dist/infrastructure/parser/implementations/TypeScriptParser.js.map +1 -1
  360. package/dist/infrastructure/parser/index.d.ts +2 -0
  361. package/dist/infrastructure/parser/index.d.ts.map +1 -1
  362. package/dist/infrastructure/parser/index.js +9 -6
  363. package/dist/infrastructure/parser/index.js.map +1 -1
  364. package/dist/infrastructure/parser/interfaces/ParserBase.d.ts.map +1 -1
  365. package/dist/infrastructure/parser/interfaces/ParserBase.js +1 -0
  366. package/dist/infrastructure/parser/interfaces/ParserBase.js.map +1 -1
  367. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts +2 -0
  368. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.d.ts.map +1 -1
  369. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js +4 -0
  370. package/dist/infrastructure/repositories/CodeGraphRepositoryImpl.js.map +1 -1
  371. package/dist/infrastructure/storage/StorageFactory.d.ts +5 -18
  372. package/dist/infrastructure/storage/StorageFactory.d.ts.map +1 -1
  373. package/dist/infrastructure/storage/StorageFactory.js +30 -98
  374. package/dist/infrastructure/storage/StorageFactory.js.map +1 -1
  375. package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts +13 -1
  376. package/dist/infrastructure/storage/adapters/SQLiteStorage.d.ts.map +1 -1
  377. package/dist/infrastructure/storage/adapters/SQLiteStorage.js +322 -76
  378. package/dist/infrastructure/storage/adapters/SQLiteStorage.js.map +1 -1
  379. package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts +45 -0
  380. package/dist/infrastructure/storage/adapters/sqlite-loader.d.ts.map +1 -0
  381. package/dist/infrastructure/storage/adapters/sqlite-loader.js +266 -0
  382. package/dist/infrastructure/storage/adapters/sqlite-loader.js.map +1 -0
  383. package/dist/infrastructure/storage/community-helpers.d.ts +4 -0
  384. package/dist/infrastructure/storage/community-helpers.d.ts.map +1 -0
  385. package/dist/infrastructure/storage/community-helpers.js +392 -0
  386. package/dist/infrastructure/storage/community-helpers.js.map +1 -0
  387. package/dist/infrastructure/storage/graph-helpers.d.ts +22 -5
  388. package/dist/infrastructure/storage/graph-helpers.d.ts.map +1 -1
  389. package/dist/infrastructure/storage/graph-helpers.js +496 -91
  390. package/dist/infrastructure/storage/graph-helpers.js.map +1 -1
  391. package/dist/infrastructure/storage/index.d.ts +1 -1
  392. package/dist/infrastructure/storage/index.d.ts.map +1 -1
  393. package/dist/infrastructure/storage/index.js +1 -1
  394. package/dist/infrastructure/storage/index.js.map +1 -1
  395. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts +2 -2
  396. package/dist/infrastructure/storage/interfaces/StorageBase.d.ts.map +1 -1
  397. package/dist/infrastructure/storage/interfaces/StorageBase.js.map +1 -1
  398. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts +2 -0
  399. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.d.ts.map +1 -1
  400. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js +52 -12
  401. package/dist/infrastructure/storage/sqlite/GovernanceGraphCache.js.map +1 -1
  402. package/dist/infrastructure/storage/sqlite/schema.d.ts +2 -2
  403. package/dist/infrastructure/storage/sqlite/schema.d.ts.map +1 -1
  404. package/dist/infrastructure/storage/sqlite/schema.js +49 -1
  405. package/dist/infrastructure/storage/sqlite/schema.js.map +1 -1
  406. package/dist/interface/config/index.d.ts +5 -3
  407. package/dist/interface/config/index.d.ts.map +1 -1
  408. package/dist/interface/types/index.d.ts +37 -6
  409. package/dist/interface/types/index.d.ts.map +1 -1
  410. package/dist/interface/types/parser.d.ts +85 -0
  411. package/dist/interface/types/parser.d.ts.map +1 -1
  412. package/dist/interface/types/storage.d.ts +227 -10
  413. package/dist/interface/types/storage.d.ts.map +1 -1
  414. package/dist/orchestrator/agent-metrics-service.d.ts +126 -0
  415. package/dist/orchestrator/agent-metrics-service.d.ts.map +1 -0
  416. package/dist/orchestrator/agent-metrics-service.js +444 -0
  417. package/dist/orchestrator/agent-metrics-service.js.map +1 -0
  418. package/dist/orchestrator/types.d.ts +2 -0
  419. package/dist/orchestrator/types.d.ts.map +1 -1
  420. package/dist/orchestrator/types.js.map +1 -1
  421. package/dist/parser/enhancers/PythonTypeEnhancer.d.ts +26 -0
  422. package/dist/parser/enhancers/PythonTypeEnhancer.d.ts.map +1 -0
  423. package/dist/parser/enhancers/PythonTypeEnhancer.js +440 -0
  424. package/dist/parser/enhancers/PythonTypeEnhancer.js.map +1 -0
  425. package/dist/parser/implementations/smart-parser.d.ts.map +1 -1
  426. package/dist/parser/implementations/smart-parser.js +7 -69
  427. package/dist/parser/implementations/smart-parser.js.map +1 -1
  428. package/dist/parser/implementations/tree-sitter-loader.d.ts +18 -0
  429. package/dist/parser/implementations/tree-sitter-loader.d.ts.map +1 -0
  430. package/dist/parser/implementations/tree-sitter-loader.js +136 -0
  431. package/dist/parser/implementations/tree-sitter-loader.js.map +1 -0
  432. package/dist/parser/index.d.ts +5 -3
  433. package/dist/parser/index.d.ts.map +1 -1
  434. package/dist/parser/index.js +68 -6
  435. package/dist/parser/index.js.map +1 -1
  436. package/dist/parser/interfaces/IParser.d.ts +19 -6
  437. package/dist/parser/interfaces/IParser.d.ts.map +1 -1
  438. package/dist/parser/interfaces/IParser.js +2 -3
  439. package/dist/parser/interfaces/IParser.js.map +1 -1
  440. package/dist/server/handlers/AnalysisHandler.d.ts +13 -2
  441. package/dist/server/handlers/AnalysisHandler.d.ts.map +1 -1
  442. package/dist/server/handlers/AnalysisHandler.js +24 -0
  443. package/dist/server/handlers/AnalysisHandler.js.map +1 -1
  444. package/dist/server/handlers/QueryHandler.d.ts.map +1 -1
  445. package/dist/server/handlers/QueryHandler.js +11 -30
  446. package/dist/server/handlers/QueryHandler.js.map +1 -1
  447. package/dist/server/mcp/context-tool.d.ts +9 -0
  448. package/dist/server/mcp/context-tool.d.ts.map +1 -0
  449. package/dist/server/mcp/context-tool.js +257 -0
  450. package/dist/server/mcp/context-tool.js.map +1 -0
  451. package/dist/server/mcp/schema-adapter.d.ts +55 -0
  452. package/dist/server/mcp/schema-adapter.d.ts.map +1 -0
  453. package/dist/server/mcp/schema-adapter.js +409 -0
  454. package/dist/server/mcp/schema-adapter.js.map +1 -0
  455. package/dist/server/mcp/server.d.ts +3 -3
  456. package/dist/server/mcp/server.d.ts.map +1 -1
  457. package/dist/server/mcp/server.js +134 -20
  458. package/dist/server/mcp/server.js.map +1 -1
  459. package/dist/server/mcp/service.d.ts +6 -2
  460. package/dist/server/mcp/service.d.ts.map +1 -1
  461. package/dist/server/mcp/service.js +138 -36
  462. package/dist/server/mcp/service.js.map +1 -1
  463. package/dist/server/mcp/stdio-transport.d.ts +23 -0
  464. package/dist/server/mcp/stdio-transport.d.ts.map +1 -0
  465. package/dist/server/mcp/stdio-transport.js +101 -0
  466. package/dist/server/mcp/stdio-transport.js.map +1 -0
  467. package/dist/server/mcp/types.d.ts +133 -8
  468. package/dist/server/mcp/types.d.ts.map +1 -1
  469. package/dist/server/routes/api.d.ts.map +1 -1
  470. package/dist/server/routes/api.js +11 -2
  471. package/dist/server/routes/api.js.map +1 -1
  472. package/docs/AI_ASSISTANT_SETUP.md +281 -12
  473. package/docs/API.md +170 -0
  474. package/docs/CONFIGURATION.md +141 -0
  475. package/docs/DEVELOPMENT.md +96 -0
  476. package/docs/GETTING-STARTED.md +114 -0
  477. package/docs/README.md +40 -1
  478. package/docs/SETUP_GUIDE.md +60 -14
  479. package/docs/TESTING.md +81 -0
  480. package/docs/ai-guide/COMMANDS.md +68 -10
  481. package/docs/ai-guide/INTEGRATION.md +77 -10
  482. package/docs/ai-guide/OUTPUT.md +345 -9
  483. package/docs/ai-guide/PROMPTS.md +2 -2
  484. package/docs/ai-guide/QUICKSTART.md +28 -1
  485. package/docs/ai-guide/README.md +2 -2
  486. package/docs/archive/ideation/2026-04-15-executable-architecture-constitution-ideation-archive.md +70 -0
  487. package/docs/archive/ideation/2026-04-20-mycodemap-init-enhancements-ideation-archive.md +109 -0
  488. package/docs/archive/ideation/2026-04-22-rules-entry-docs-optimization-consolidated-ideation-archive.md +54 -0
  489. package/docs/backlog.md +232 -144
  490. package/docs/brainstorms/2026-05-10-agent-effectiveness-validation-requirements.md +112 -0
  491. package/docs/generated/phase-58/subagent-evidence/claude-hook-example.json +15 -0
  492. package/docs/generated/phase-58/subagent-evidence/claude-session.md +146 -0
  493. package/docs/generated/phase-58/subagent-evidence/claude-subagent.json +28 -0
  494. package/docs/generated/phase-58/subagent-evidence/codex-agent-example.toml +19 -0
  495. package/docs/generated/phase-58/subagent-evidence/codex-session.md +150 -0
  496. package/docs/generated/phase-58/subagent-evidence/codex-subagent.json +20 -0
  497. package/docs/generated/phase-58/subagent-evidence/negative-no-retrieval.json +12 -0
  498. package/docs/generated/phase-58/subagent-evidence/verification-manifest.json +19 -0
  499. package/docs/ideation/2026-04-15-executable-architecture-constitution-ideation.md +10 -22
  500. package/docs/ideation/2026-04-20-mycodemap-init-enhancements-ideation.md +15 -60
  501. package/docs/ideation/2026-04-22-rules-entry-docs-optimization-consolidated-ideation.md +47 -52
  502. package/docs/ideation/2026-04-29-ux-install-agent-experience-ideation.md +256 -0
  503. package/docs/ideation/2026-05-02-subagent-environment-contract-injection-ideation.md +183 -0
  504. package/docs/ideation/2026-05-04-subagent-hooks-deep-dive-ideation.md +133 -0
  505. package/docs/ideation/2026-05-10-agent-effectiveness-validation-ideation.md +219 -0
  506. package/docs/plans/2026-04-30-install-guide-and-repo-analyzer-design.md +394 -0
  507. package/docs/rules/README.md +1 -0
  508. package/docs/rules/architecture-guardrails.md +2 -1
  509. package/docs/rules/engineering-with-codex-openai.md +1 -1
  510. package/docs/rules/harness.md +106 -0
  511. package/docs/rules/pre-release-checklist.md +28 -0
  512. package/docs/rules/testing.md +51 -0
  513. package/examples/claude/skills/mycodemap-repo-analyzer/SKILL.md +294 -0
  514. package/examples/claude/skills/mycodemap-repo-analyzer/references/analysis-guide.md +166 -0
  515. package/examples/claude/skills/mycodemap-repo-analyzer/references/module-analysis-guide.md +150 -0
  516. package/package.json +12 -4
  517. package/scripts/copy-build-assets.mjs +23 -0
  518. package/scripts/hooks/templates/pre-commit +33 -2
  519. package/scripts/sync-analyze-docs.js +2 -2
  520. package/scripts/tests/test_rule_control_workflow.py +15 -1
  521. package/scripts/validate-docs.js +113 -16
  522. package/scripts/verify-subagent-env-contract.mjs +279 -0
  523. package/dist/parser/implementations/tree-sitter-parser.d.ts +0 -57
  524. package/dist/parser/implementations/tree-sitter-parser.d.ts.map +0 -1
  525. package/dist/parser/implementations/tree-sitter-parser.js +0 -375
  526. package/dist/parser/implementations/tree-sitter-parser.js.map +0 -1
  527. package/docs/references/tmp.md +0 -527
@@ -1,718 +1,33 @@
1
1
  // [META] since:2026-03-03 | owner:orchestrator-team | stable:true
2
- // [WHY] 查询命令优化:改进缓存策略、添加索引结构、添加性能指标输出
3
- import chalk from 'chalk';
4
- import fs from 'fs';
5
- import path from 'path';
6
- import { resolveDataPath } from '../paths.js';
7
- // ===== 性能优化:改进的缓存机制 =====
8
- // 缓存配置
9
- const CACHE_CONFIG = {
10
- TTL: 60000, // 60秒缓存(从5秒提升)
11
- MAX_SIZE: 10, // 最大缓存 10 个项目的索引
12
- };
13
- const indexCache = new Map();
14
- /**
15
- * 标准化依赖名称,用于去重比较
16
- * 1. 去除扩展名(如 .ts, .js)
17
- * 2. 去除 ./ 前缀
18
- * 3. 转换为小写
19
- */
20
- function normalizeDependencyName(name) {
21
- return name
22
- .replace(/\.[jt]s$/, "") // 去除 .ts 或 .js 扩展名
23
- .replace(/^\.\//, "") // 去除 ./ 前缀
24
- .toLowerCase();
2
+ // [WHY] Thin CLI wrapper for shared query execution so CLI and MCP can converge on one transport-free truth
3
+ import { resolveOutputMode, renderOutput, createProgressEmitter, formatError } from '../output/index.js';
4
+ import { executeQueryTool, formatQueryHuman, } from '../../execution/contract-tools/query.js';
5
+ function toExecutionError(error) {
6
+ const executionError = new Error(error.message);
7
+ executionError.code = error.code;
8
+ executionError.remediation = error.remediation;
9
+ executionError.details = error.details;
10
+ return executionError;
25
11
  }
26
- /**
27
- * 预构建索引以加速查询
28
- */
29
- function buildIndex(codeMap, rootDir) {
30
- const index = {
31
- symbols: new Map(),
32
- symbolsExact: new Map(),
33
- modules: new Map(),
34
- dependencies: new Map(),
35
- prefixIndex: new Map(),
36
- prefixIndexExact: new Map(),
37
- };
38
- for (const module of codeMap.modules) {
39
- const relativePath = path.relative(rootDir, module.absolutePath);
40
- const moduleIndex = {
41
- absolutePath: module.absolutePath,
42
- relativePath,
43
- type: module.type,
44
- exports: module.exports.map(e => e.name),
45
- };
46
- // 索引模块(使用相对路径作为主键)
47
- index.modules.set(relativePath.toLowerCase(), moduleIndex);
48
- // 索引导出
49
- for (const exp of module.exports) {
50
- const entry = {
51
- name: exp.name,
52
- kind: exp.kind,
53
- filePath: relativePath,
54
- isExported: true,
55
- };
56
- // 精确索引(不区分大小写)
57
- const lowerName = exp.name.toLowerCase();
58
- if (!index.symbols.has(lowerName)) {
59
- index.symbols.set(lowerName, []);
60
- }
61
- index.symbols.get(lowerName).push(entry);
62
- // 精确索引(区分大小写)
63
- if (!index.symbolsExact.has(exp.name)) {
64
- index.symbolsExact.set(exp.name, []);
65
- }
66
- index.symbolsExact.get(exp.name).push(entry);
67
- // 前缀索引(不区分大小写)
68
- for (let i = 1; i <= exp.name.length; i++) {
69
- const prefix = exp.name.substring(0, i).toLowerCase();
70
- if (!index.prefixIndex.has(prefix)) {
71
- index.prefixIndex.set(prefix, []);
72
- }
73
- index.prefixIndex.get(prefix).push(entry);
74
- }
75
- // 前缀索引(区分大小写)
76
- for (let i = 1; i <= exp.name.length; i++) {
77
- const prefix = exp.name.substring(0, i);
78
- if (!index.prefixIndexExact.has(prefix)) {
79
- index.prefixIndexExact.set(prefix, []);
80
- }
81
- index.prefixIndexExact.get(prefix).push(entry);
82
- }
83
- }
84
- // 索引符号
85
- for (const sym of module.symbols) {
86
- const entry = {
87
- name: sym.name,
88
- kind: sym.kind,
89
- filePath: relativePath,
90
- line: sym.location.line,
91
- column: sym.location.column,
92
- isExported: false,
93
- };
94
- const lowerName = sym.name.toLowerCase();
95
- if (!index.symbols.has(lowerName)) {
96
- index.symbols.set(lowerName, []);
97
- }
98
- index.symbols.get(lowerName).push(entry);
99
- // 精确索引(区分大小写)
100
- if (!index.symbolsExact.has(sym.name)) {
101
- index.symbolsExact.set(sym.name, []);
102
- }
103
- index.symbolsExact.get(sym.name).push(entry);
104
- // 前缀索引(不区分大小写)
105
- for (let i = 1; i <= sym.name.length; i++) {
106
- const prefix = sym.name.substring(0, i).toLowerCase();
107
- if (!index.prefixIndex.has(prefix)) {
108
- index.prefixIndex.set(prefix, []);
109
- }
110
- index.prefixIndex.get(prefix).push(entry);
111
- }
112
- // 前缀索引(区分大小写)
113
- for (let i = 1; i <= sym.name.length; i++) {
114
- const prefix = sym.name.substring(0, i);
115
- if (!index.prefixIndexExact.has(prefix)) {
116
- index.prefixIndexExact.set(prefix, []);
117
- }
118
- index.prefixIndexExact.get(prefix).push(entry);
119
- }
120
- }
121
- // 索引依赖和导入,进行去重处理
122
- // 使用 Set 跟踪当前模块已添加的依赖(基于标准化名称)
123
- const seenDeps = new Set();
124
- // 先索引 dependencies(优先保留)
125
- for (const dep of module.dependencies) {
126
- const normalizedDep = normalizeDependencyName(dep);
127
- const depKey = `${relativePath}:${normalizedDep}`;
128
- // 跳过已存在的依赖
129
- if (seenDeps.has(depKey)) {
130
- continue;
131
- }
132
- seenDeps.add(depKey);
133
- const depEntry = {
134
- name: dep,
135
- sourcePath: relativePath,
136
- type: "dependency",
137
- };
138
- const lowerDep = dep.toLowerCase();
139
- if (!index.dependencies.has(lowerDep)) {
140
- index.dependencies.set(lowerDep, []);
141
- }
142
- index.dependencies.get(lowerDep).push(depEntry);
143
- }
144
- // 再索引 imports(如果与 dependency 重复则跳过)
145
- for (const imp of module.imports) {
146
- const normalizedSource = normalizeDependencyName(imp.source);
147
- const impKey = `${relativePath}:${normalizedSource}`;
148
- // 跳过已存在的依赖(避免与 dependency 重复)
149
- if (seenDeps.has(impKey)) {
150
- continue;
151
- }
152
- seenDeps.add(impKey);
153
- const impEntry = {
154
- name: imp.source,
155
- sourcePath: relativePath,
156
- type: "import",
157
- };
158
- const lowerSource = imp.source.toLowerCase();
159
- if (!index.dependencies.has(lowerSource)) {
160
- index.dependencies.set(lowerSource, []);
161
- }
162
- index.dependencies.get(lowerSource).push(impEntry);
163
- }
164
- }
165
- return index;
166
- }
167
- /**
168
- * 加载代码地图数据(带改进的缓存)
169
- */
170
- function loadCodeMap(rootDir, useCache = true) {
171
- const codemapPath = resolveDataPath(rootDir);
172
- const startTime = performance.now();
173
- // 检查缓存
174
- if (useCache) {
175
- const cached = indexCache.get(rootDir);
176
- if (cached && Date.now() - cached.timestamp < CACHE_CONFIG.TTL) {
177
- return {
178
- codeMap: cached.data,
179
- index: cached.index,
180
- cacheHit: true,
181
- loadTime: 0,
182
- };
183
- }
184
- }
185
- if (!fs.existsSync(codemapPath)) {
186
- console.log(chalk.red('错误: 代码地图不存在,请先运行 codemap generate'));
187
- return { codeMap: null, index: null, cacheHit: false, loadTime: 0 };
188
- }
12
+ export async function queryCommand(options) {
13
+ const mode = resolveOutputMode({ json: options.json, human: options.human });
14
+ const progress = createProgressEmitter(mode, 'Querying...');
189
15
  try {
190
- const data = fs.readFileSync(codemapPath, 'utf-8');
191
- const parsed = JSON.parse(data);
192
- const loadTime = performance.now() - startTime;
193
- // 构建索引
194
- const index = buildIndex(parsed, rootDir);
195
- // 缓存(如果启用)
196
- if (useCache) {
197
- // 清理超出限制的旧缓存
198
- if (indexCache.size >= CACHE_CONFIG.MAX_SIZE) {
199
- // 删除最旧的缓存
200
- let oldestKey = null;
201
- let oldestTime = Infinity;
202
- for (const [key, val] of indexCache.entries()) {
203
- if (val.timestamp < oldestTime) {
204
- oldestTime = val.timestamp;
205
- oldestKey = key;
206
- }
207
- }
208
- if (oldestKey) {
209
- indexCache.delete(oldestKey);
210
- }
211
- }
212
- indexCache.set(rootDir, {
213
- data: parsed,
214
- timestamp: Date.now(),
215
- path: codemapPath,
216
- index,
16
+ progress.update(30, 'Loading index...');
17
+ const execution = await executeQueryTool(options, process.cwd());
18
+ if (execution.status !== 'ok' || !execution.result) {
19
+ throw toExecutionError(execution.error ?? {
20
+ code: 'EXECUTION_FAILED',
21
+ message: 'Query execution failed',
217
22
  });
218
23
  }
219
- return {
220
- codeMap: parsed,
221
- index,
222
- cacheHit: false,
223
- loadTime,
224
- };
24
+ progress.complete();
25
+ renderOutput(execution.result, formatQueryHuman, mode);
225
26
  }
226
27
  catch (error) {
227
- console.log(chalk.red('错误: 读取代码地图失败:', error instanceof Error ? error.message : String(error)));
228
- return { codeMap: null, index: null, cacheHit: false, loadTime: 0 };
229
- }
230
- }
231
- /**
232
- * 清除缓存
233
- */
234
- function clearCache() {
235
- indexCache.clear();
236
- }
237
- /**
238
- * 查找符号的引用位置
239
- */
240
- function findReferences(codeMap, symbolName, excludeFile, caseSensitive = false) {
241
- const references = [];
242
- const searchName = caseSensitive ? symbolName : symbolName.toLowerCase();
243
- for (const mod of codeMap.modules) {
244
- const relPath = path.relative(codeMap.project.rootDir, mod.absolutePath);
245
- // 跳过定义位置文件
246
- if (relPath === excludeFile)
247
- continue;
248
- // 检查 imports 中是否引用了该符号
249
- for (const imp of mod.imports) {
250
- // 检查导入源
251
- const impSource = caseSensitive ? imp.source : imp.source.toLowerCase();
252
- if (impSource.includes(searchName)) {
253
- references.push({
254
- file: relPath,
255
- line: 1, // 简化处理,显示第一行
256
- type: 'import',
257
- });
258
- continue;
259
- }
260
- // 检查导入的 specifiers
261
- for (const spec of imp.specifiers) {
262
- const specName = caseSensitive ? spec.name : spec.name.toLowerCase();
263
- if (specName === searchName) {
264
- references.push({
265
- file: relPath,
266
- line: 1,
267
- type: 'import',
268
- });
269
- break;
270
- }
271
- }
272
- }
273
- // 检查 exports 中是否导出该符号
274
- for (const exp of mod.exports) {
275
- const expName = caseSensitive ? exp.name : exp.name.toLowerCase();
276
- if (expName === searchName) {
277
- references.push({
278
- file: relPath,
279
- line: 1,
280
- type: 'export',
281
- });
282
- }
283
- }
284
- }
285
- return references.slice(0, 20); // 限制引用数量
286
- }
287
- /**
288
- * 读取代码上下文
289
- */
290
- function readCodeContext(filePath, lineNumber, contextLines, rootDir) {
291
- const fullPath = path.join(rootDir, filePath);
292
- if (!fs.existsSync(fullPath)) {
293
- return [];
294
- }
295
- try {
296
- const content = fs.readFileSync(fullPath, 'utf-8');
297
- const lines = content.split('\n');
298
- const context = [];
299
- const startLine = Math.max(1, lineNumber - contextLines);
300
- const endLine = Math.min(lines.length, lineNumber + contextLines);
301
- for (let i = startLine; i <= endLine; i++) {
302
- context.push({
303
- line: i,
304
- content: lines[i - 1] || '',
305
- });
306
- }
307
- return context;
308
- }
309
- catch {
310
- return [];
311
- }
312
- }
313
- /**
314
- * 查询符号(使用索引)
315
- */
316
- function querySymbol(index, codeMap, symbolName, limit, caseSensitive = false, includeReferences = false, contextLines = 0) {
317
- const results = [];
318
- // 选择正确的索引
319
- const symbolsMap = caseSensitive ? index.symbolsExact : index.symbols;
320
- const prefixMap = caseSensitive ? index.prefixIndexExact : index.prefixIndex;
321
- // 搜索键:不区分大小写时转换为小写
322
- const searchKey = caseSensitive ? symbolName : symbolName.toLowerCase();
323
- // 用于去重的 Set
324
- const seenResults = new Set();
325
- // 首先尝试精确匹配(完全相等)
326
- const exactMatches = symbolsMap.get(searchKey);
327
- if (exactMatches) {
328
- for (const entry of exactMatches) {
329
- const key = `${entry.name}:${entry.filePath}`;
330
- if (!seenResults.has(key)) {
331
- seenResults.add(key);
332
- results.push({
333
- name: entry.name,
334
- path: path.join(codeMap.project.rootDir, entry.filePath),
335
- kind: entry.kind,
336
- details: `${entry.isExported ? '导出于' : '定义于'} ${entry.filePath}${entry.line ? ':' + entry.line : ''}`,
337
- location: { file: entry.filePath, line: entry.line, column: entry.column },
338
- isExported: entry.isExported,
339
- });
340
- }
341
- }
342
- }
343
- // 尝试前缀匹配(以搜索词开头)
344
- const prefixResults = prefixMap.get(searchKey) || [];
345
- for (const entry of prefixResults) {
346
- const key = `${entry.name}:${entry.filePath}`;
347
- if (!seenResults.has(key)) {
348
- seenResults.add(key);
349
- results.push({
350
- name: entry.name,
351
- path: path.join(codeMap.project.rootDir, entry.filePath),
352
- kind: entry.kind,
353
- details: `${entry.isExported ? '导出于' : '定义于'} ${entry.filePath}${entry.line ? ':' + entry.line : ''}`,
354
- location: { file: entry.filePath, line: entry.line, column: entry.column },
355
- isExported: entry.isExported,
356
- });
357
- }
358
- }
359
- // 尝试子串匹配(包含匹配)
360
- // 例如:搜索 "Analyzer" 应匹配 "GitAnalyzer"
361
- for (const [key, entries] of symbolsMap.entries()) {
362
- if (key.includes(searchKey) && !key.startsWith(searchKey)) {
363
- // 跳过已经通过精确匹配和前缀匹配找到的键
364
- for (const entry of entries) {
365
- const resultKey = `${entry.name}:${entry.filePath}`;
366
- if (!seenResults.has(resultKey)) {
367
- seenResults.add(resultKey);
368
- results.push({
369
- name: entry.name,
370
- path: path.join(codeMap.project.rootDir, entry.filePath),
371
- kind: entry.kind,
372
- details: `${entry.isExported ? '导出于' : '定义于'} ${entry.filePath}${entry.line ? ':' + entry.line : ''}`,
373
- location: { file: entry.filePath, line: entry.line, column: entry.column },
374
- isExported: entry.isExported,
375
- });
376
- }
377
- }
378
- }
379
- }
380
- // 添加引用信息
381
- if (includeReferences) {
382
- for (const result of results) {
383
- result.references = findReferences(codeMap, symbolName, result.location?.file || '', caseSensitive);
384
- }
385
- }
386
- // 添加代码上下文
387
- if (contextLines > 0) {
388
- for (const result of results) {
389
- result.context = readCodeContext(result.location?.file || '', result.location?.line || 0, contextLines, codeMap.project.rootDir);
390
- }
391
- }
392
- return results.slice(0, limit);
393
- }
394
- /**
395
- * 查询模块(使用索引)
396
- */
397
- function queryModule(index, codeMap, modulePath, limit) {
398
- const results = [];
399
- const searchPath = modulePath.toLowerCase();
400
- // 使用索引查找
401
- for (const [key, moduleIdx] of index.modules.entries()) {
402
- if (key.includes(searchPath) || moduleIdx.absolutePath.toLowerCase().includes(searchPath)) {
403
- const exports = moduleIdx.exports.join(', ') || '无导出';
404
- results.push({
405
- name: moduleIdx.relativePath,
406
- path: moduleIdx.absolutePath,
407
- kind: moduleIdx.type,
408
- details: `导出: ${exports}`,
409
- location: { file: moduleIdx.relativePath },
410
- isExported: moduleIdx.exports.length > 0,
411
- });
412
- }
413
- }
414
- return results.slice(0, limit);
415
- }
416
- /**
417
- * 查询依赖(使用索引)
418
- * @param index 符号索引
419
- * @param codeMap 代码地图数据
420
- * @param depName 依赖名称
421
- * @param limit 结果数量限制
422
- * @param deduplicate 是否去重(默认true)
423
- */
424
- function queryDeps(index, codeMap, depName, limit, deduplicate = true) {
425
- const results = [];
426
- const searchDep = depName.toLowerCase();
427
- // 使用索引查找
428
- const depEntries = index.dependencies.get(searchDep);
429
- if (depEntries) {
430
- for (const entry of depEntries) {
431
- results.push({
432
- name: entry.name,
433
- path: path.join(codeMap.project.rootDir, entry.sourcePath),
434
- kind: entry.type,
435
- details: `${entry.type === 'dependency' ? '被' : '导入自'} ${entry.sourcePath} 引用`,
436
- location: { file: entry.sourcePath },
437
- isExported: false,
438
- });
439
- }
440
- }
441
- // 去重:基于 name:sourcePath 组合去重,避免 dependency 和 import 重复
442
- if (deduplicate) {
443
- const unique = new Map();
444
- for (const item of results) {
445
- const key = `${item.name}:${item.path}`;
446
- if (!unique.has(key)) {
447
- unique.set(key, item);
448
- }
449
- }
450
- return Array.from(unique.values()).slice(0, limit);
451
- }
452
- return results.slice(0, limit);
453
- }
454
- /**
455
- * 模糊搜索(使用索引)
456
- * @param index 符号索引
457
- * @param codeMap 代码地图数据
458
- * @param keyword 搜索关键词
459
- * @param limit 结果数量限制
460
- * @param useRegex 是否使用正则表达式搜索
461
- * @param caseSensitive 大小写敏感
462
- * @param contextLines 代码上下文行数
463
- */
464
- function search(index, codeMap, keyword, limit, useRegex = false, caseSensitive = false, contextLines = 0) {
465
- const results = [];
466
- // 正则表达式模式
467
- let regex = null;
468
- if (useRegex) {
469
- try {
470
- const flags = caseSensitive ? '' : 'i';
471
- regex = new RegExp(keyword, flags);
472
- }
473
- catch {
474
- // 正则表达式无效,回退到普通搜索
475
- regex = null;
476
- }
477
- }
478
- // 1. 搜索模块路径
479
- for (const [key, moduleIdx] of index.modules.entries()) {
480
- const searchTarget = caseSensitive ? key : key.toLowerCase();
481
- const keywordLower = keyword.toLowerCase();
482
- const matches = regex
483
- ? regex.test(key) || regex.test(moduleIdx.relativePath)
484
- : searchTarget.includes(keywordLower);
485
- if (matches) {
486
- results.push({
487
- name: moduleIdx.relativePath,
488
- path: moduleIdx.absolutePath,
489
- kind: 'module',
490
- details: useRegex ? `正则匹配` : `模块匹配`,
491
- location: { file: moduleIdx.relativePath },
492
- isExported: false,
493
- });
494
- }
495
- }
496
- // 2. 搜索符号和导出(使用前缀索引)
497
- // 选择正确的索引
498
- const symbolsMap = caseSensitive ? index.symbolsExact : index.symbols;
499
- const prefixMap = caseSensitive ? index.prefixIndexExact : index.prefixIndex;
500
- if (useRegex && regex) {
501
- // 正则模式:遍历所有符号进行匹配
502
- for (const [symbolKey, entries] of symbolsMap.entries()) {
503
- const matchTarget = caseSensitive ? symbolKey : symbolKey.toLowerCase();
504
- if (regex.test(matchTarget) || regex.test(symbolKey)) {
505
- for (const entry of entries) {
506
- results.push({
507
- name: entry.name,
508
- path: path.join(codeMap.project.rootDir, entry.filePath),
509
- kind: entry.isExported ? `export (${entry.kind})` : entry.kind,
510
- details: `正则匹配于 ${entry.filePath}${entry.line ? ':' + entry.line : ''}`,
511
- location: { file: entry.filePath, line: entry.line, column: entry.column },
512
- isExported: entry.isExported,
513
- });
514
- }
515
- }
516
- }
517
- }
518
- else {
519
- // 普通模式:使用前缀索引
520
- // 搜索键:不区分大小写时转换为小写
521
- const searchKey = caseSensitive ? keyword : keyword.toLowerCase();
522
- const prefixResults = prefixMap.get(searchKey) || [];
523
- for (const entry of prefixResults) {
524
- results.push({
525
- name: entry.name,
526
- path: path.join(codeMap.project.rootDir, entry.filePath),
527
- kind: entry.isExported ? `export (${entry.kind})` : entry.kind,
528
- details: `${entry.isExported ? '导出于' : '定义于'} ${entry.filePath}${entry.line ? ':' + entry.line : ''}`,
529
- location: { file: entry.filePath, line: entry.line, column: entry.column },
530
- isExported: entry.isExported,
531
- });
532
- }
533
- }
534
- // 去重(基于 name:path 组合)
535
- const unique = new Map();
536
- for (const item of results) {
537
- const key = `${item.name}:${item.path}`;
538
- if (!unique.has(key)) {
539
- unique.set(key, item);
540
- }
541
- }
542
- const finalResults = Array.from(unique.values()).slice(0, limit);
543
- // 添加代码上下文
544
- if (contextLines > 0) {
545
- for (const result of finalResults) {
546
- result.context = readCodeContext(result.location?.file || '', result.location?.line || 0, contextLines, codeMap.project.rootDir);
547
- }
548
- }
549
- return finalResults;
550
- }
551
- /**
552
- * 格式化输出结果
553
- */
554
- function formatResults(result, isJson, verbose, structured = false) {
555
- if (isJson) {
556
- // 如果是 structured 模式,移除 details 字段
557
- if (structured) {
558
- const structuredResult = {
559
- ...result,
560
- results: result.results.map(item => {
561
- const { details, ...rest } = item;
562
- void details; // 标记为有意忽略的变量
563
- return rest;
564
- })
565
- };
566
- console.log(JSON.stringify(structuredResult, null, 2));
567
- }
568
- else {
569
- console.log(JSON.stringify(result, null, 2));
570
- }
571
- return;
572
- }
573
- console.log(chalk.cyan(`\n查询 "${result.query}" (${result.type})`));
574
- console.log(chalk.gray(` 找到 ${result.count} 个结果\n`));
575
- if (result.count === 0) {
576
- console.log(chalk.yellow(' 未找到匹配结果'));
577
- return;
578
- }
579
- for (const item of result.results) {
580
- console.log(chalk.green(` ${item.name}`));
581
- if (item.kind) {
582
- console.log(chalk.gray(` 类型: ${item.kind}`));
583
- }
584
- if (item.path) {
585
- console.log(chalk.gray(` 路径: ${item.path}`));
586
- }
587
- if (item.details) {
588
- console.log(chalk.gray(` ${item.details}`));
589
- }
590
- // 显示引用信息
591
- if (item.references && item.references.length > 0) {
592
- console.log(chalk.gray(` 引用:`));
593
- for (const ref of item.references.slice(0, 5)) {
594
- console.log(chalk.gray(` - ${ref.type}: ${ref.file}`));
595
- }
596
- if (item.references.length > 5) {
597
- console.log(chalk.gray(` ... 还有 ${item.references.length - 5} 个引用`));
598
- }
599
- }
600
- // 显示代码上下文
601
- if (item.context && item.context.length > 0) {
602
- console.log(chalk.gray(` 代码上下文:`));
603
- for (const ctx of item.context) {
604
- const prefix = ctx.line === item.location?.line ? '>' : ' ';
605
- console.log(chalk.gray(` ${prefix}${ctx.line}: ${ctx.content}`));
606
- }
607
- }
608
- console.log('');
609
- }
610
- // verbose 模式输出性能指标
611
- if (verbose && result.metrics) {
612
- const m = result.metrics;
613
- console.log(chalk.cyan('性能指标:'));
614
- console.log(chalk.gray(` 索引加载: ${m.indexLoadTime.toFixed(2)}ms ${m.cacheHit ? '(缓存命中)' : ''}`));
615
- console.log(chalk.gray(` 查询执行: ${m.queryTime.toFixed(2)}ms`));
616
- console.log(chalk.gray(` 总耗时: ${m.totalTime.toFixed(2)}ms`));
617
- console.log(chalk.gray(` 索引大小: ${m.indexSize} 个条目`));
618
- }
619
- }
620
- /**
621
- * Query 命令实现
622
- */
623
- export async function queryCommand(options) {
624
- const rootDir = process.cwd();
625
- const limit = options.limit || 50;
626
- const useCache = options.cache !== false; // 默认启用缓存
627
- const verbose = options.verbose || false;
628
- const useRegex = options.regex || false;
629
- const depsFormat = options.depsFormat || 'default';
630
- const caseSensitive = options.caseSensitive || false;
631
- const contextLines = typeof options.context === 'string' ? parseInt(options.context, 10) : (options.context || 0);
632
- const includeReferences = options.includeReferences || false;
633
- // 清除缓存(如果指定 --no-cache)
634
- if (!useCache) {
635
- clearCache();
636
- }
637
- // 加载代码地图(带缓存)
638
- const startTotal = performance.now();
639
- const { codeMap, index, cacheHit, loadTime } = loadCodeMap(rootDir, useCache);
640
- if (!codeMap || !index) {
641
- process.exit(1);
642
- }
643
- const indexLoadTime = loadTime;
644
- const indexSize = index.symbols.size + index.modules.size + index.dependencies.size;
645
- let result;
646
- const queryStartTime = performance.now();
647
- // 执行查询
648
- if (options.symbol) {
649
- const items = querySymbol(index, codeMap, options.symbol, limit, caseSensitive, includeReferences, contextLines);
650
- result = {
651
- type: 'symbol',
652
- query: options.symbol,
653
- count: items.length,
654
- results: items,
655
- };
656
- }
657
- else if (options.module) {
658
- const items = queryModule(index, codeMap, options.module, limit);
659
- result = {
660
- type: 'module',
661
- query: options.module,
662
- count: items.length,
663
- results: items,
664
- };
665
- }
666
- else if (options.deps) {
667
- // 依赖查询:根据 depsFormat 决定是否去重
668
- // default 模式下去重,detailed 模式显示完整信息(包含 dependency 和 import)
669
- const deduplicate = depsFormat !== 'detailed';
670
- const items = queryDeps(index, codeMap, options.deps, limit, deduplicate);
671
- result = {
672
- type: 'deps',
673
- query: options.deps,
674
- count: items.length,
675
- results: items,
676
- };
677
- }
678
- else if (options.search) {
679
- const items = search(index, codeMap, options.search, limit, useRegex, caseSensitive, contextLines);
680
- result = {
681
- type: 'search',
682
- query: options.search,
683
- count: items.length,
684
- results: items,
685
- };
686
- }
687
- else {
688
- console.log(chalk.red('错误: 请指定查询类型: --symbol, --module, --deps, 或 --search'));
689
- console.log(chalk.gray('\n用法:'));
690
- console.log(chalk.gray(' codemap query --symbol <name> # 查询符号'));
691
- console.log(chalk.gray(' codemap query --module <path> # 查询模块'));
692
- console.log(chalk.gray(' codemap query --deps <name> # 查询依赖'));
693
- console.log(chalk.gray(' codemap query --search <word> # 模糊搜索'));
694
- console.log(chalk.gray('\n选项:'));
695
- console.log(chalk.gray(' -l, --limit <number> 限制结果数量'));
696
- console.log(chalk.gray(' -j, --json JSON 格式输出'));
697
- console.log(chalk.gray(' -v, --verbose 显示性能指标'));
698
- console.log(chalk.gray(' -r, --regex 使用正则表达式搜索'));
699
- console.log(chalk.gray(' --deps-format 依赖查询格式 (default|detailed)'));
700
- console.log(chalk.gray(' --no-cache 禁用缓存'));
701
- process.exit(1);
702
- }
703
- const queryTime = performance.now() - queryStartTime;
704
- const totalTime = performance.now() - startTotal;
705
- // 添加性能指标
706
- if (verbose) {
707
- result.metrics = {
708
- indexLoadTime,
709
- queryTime,
710
- totalTime,
711
- cacheHit,
712
- indexSize,
713
- };
28
+ progress.fail();
29
+ process.stdout.write(formatError(error, mode, 'codemap query') + '\n');
30
+ process.exitCode = 1;
714
31
  }
715
- // 输出结果
716
- formatResults(result, options.json || false, verbose, options.structured || false);
717
32
  }
718
33
  //# sourceMappingURL=query.js.map