@mycodemap/mycodemap 2.0.0 → 2.7.0

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