@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
package/CHANGELOG.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [2.7.0] - 2026-05-11 - Agent Effectiveness Validation
6
+
7
+ ### 🛠️ Infrastructure
8
+
9
+ - **agent-metrics**: 新增 `codemap agent-metrics` 命令家族,支持 token 成本分析、报告聚合、CI threshold gate
10
+ - **agent-metrics**: `codemap agent-metrics token` 对代表性查询执行 token 成本分析(响应大小、估算 token 数、原始字符数)
11
+ - **agent-metrics**: `codemap agent-metrics report` 输出格式化报告,支持人类可读表格和 JSON 两种模式
12
+ - **agent-metrics**: `codemap agent-metrics gate` CI 管道阈值检测,默认 warn-only 模式
13
+
14
+ ### 📊 Intelligence
15
+
16
+ - **trends**: 追踪 latest-vs-previous 绝对 token 趋势,按查询类型分组
17
+ - **distribution**: 提供 `p50/p95/max` 分布深度,用于异常值检测
18
+ - **advisory**: 识别最高成本查询类型和样本,提供优化建议
19
+
20
+ ### 📝 Documentation
21
+
22
+ - **release**: 同步 `llms.txt`、`AI_GUIDE.md`、`AI_DISCOVERY.md`、`ai-document-index.yaml` 到 `v2.7.0`
23
+ - **changelog**: 新增 v2.7.0 发布条目,记录 agent-effectiveness-validation milestone
24
+
5
25
  ## [2.0.0] - 2026-05-01 - Agent-Native Foundation
6
26
 
7
27
  ### 🏗️ Architecture
package/README.md CHANGED
@@ -1,241 +1,116 @@
1
- # CodeMap
2
-
3
- > AI-Native, Human-Friendly Code Architecture Governance Infrastructure — `v2.0` Milestone
4
-
5
- [中文版本](./README.zh-CN.md)
6
-
7
- CodeMap is an AI-Native-first, human-friendly code architecture governance infrastructure for TypeScript/JavaScript/Go projects. `v2.0` upgraded the CLI surface to a schema-driven self-describing unified interface: a single contract schema simultaneously generates the parser, MCP tool definitions, `--help-json`, and shell completions. `codemap doctor` provides continuous health diagnostics, the `Failure-to-Action Protocol` turns errors into structured state transitions, and the WASM-first build foundation eliminates the #1 installation drop-off caused by native dependency compilation failures. Human users get table/color output via `--human` or TTY auto-detection; AI/Agents receive JSON/NDJSON by default.
8
-
9
- ---
10
-
11
- ## Features
1
+ <!-- generated-by: gsd-doc-writer -->
12
2
 
13
- ### v2.0 Core Features
14
-
15
- - **Interface Contract Schema** — A single machine-readable schema defines the entire CLI surface; `codemap --schema` outputs the full contract JSON for agent introspection and dynamic adaptation
16
- - **CLI-as-MCP Automatic Gateway** — All schema-defined CLI commands are automatically exposed as MCP tools with zero handwritten maintenance; new commands automatically get MCP exposure
17
- - **AI-First Default Output** — JSON/NDJSON by default; `--human` flag renders tables/colors on demand; TTY auto-detection preserves interactive experience; progress events go to stderr
18
- - **`codemap doctor`** — Continuous health diagnostics detecting ghost commands, native dependency issues, workspace drift, and agent connectivity
19
- - **Failure-to-Action Protocol** — Every error returns structured `rootCause` + `remediationPlan` + `confidence` + `nextCommand`; agents can attempt automatic remediation
20
- - **Validation Router** — Routes minimal verification by change type; docs guardrail validates that referenced commands are real and runnable
21
- - **WASM-First Build Foundation** — `tree-sitter` / `better-sqlite3` provide WASM fallback paths; `--native` forces native mode; `codemap benchmark` compares WASM vs Native performance
3
+ # CodeMap
22
4
 
23
- ### Core Capabilities
5
+ CodeMap is an AI-Native TypeScript code map tool for AI-assisted development. It analyzes a repository, builds symbol and dependency graphs, exposes the results through a CLI, HTTP API, and MCP server, and writes structured artifacts that agents can consume directly.
24
6
 
25
- - **AI-first code map** — Generates `AI_MAP.md`, `CONTEXT.md`, `codemap.json`, and other AI/Agent-consumable context
26
- - **Core analysis commands** — `generate`, `query`, `deps`, `impact`, `complexity`, `cycles`, `analyze`, `design`, `export`, `ci`
27
- - **Layered architecture (MVP3)** — Clear boundaries: `Interface → Infrastructure → Domain → Server → CLI`
28
- - **Dual parsing modes** — `fast` (regex) and `smart` (TypeScript AST)
29
- - **Multi-language support** — TypeScript/JavaScript, Go, Python (extensible architecture)
30
- - **Dependency / impact / complexity analysis** — For change impact assessment, refactoring inventory, and architecture retrospectives
31
- - **CI gate and docs guardrail** — Commit format, file headers, risk assessment, docs/output contract checks
32
- - **Multi-format export and storage abstraction** — Export graph data with filesystem / memory / sqlite backends
7
+ AI/Agent 是主要消费者,人类主要负责启动、审查和发布。
33
8
 
34
- ---
9
+ [![npm version](https://img.shields.io/npm/v/@mycodemap/mycodemap)](https://www.npmjs.com/package/@mycodemap/mycodemap)
10
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
11
+ [![CI](https://github.com/yuanyuanyuan/mycodemap/actions/workflows/ci-gateway.yml/badge.svg)](https://github.com/yuanyuanyuan/mycodemap/actions/workflows/ci-gateway.yml)
35
12
 
36
- ## Installation
13
+ ## Install
37
14
 
38
15
  ```bash
39
- # Using npm
40
- npm install @mycodemap/mycodemap
41
-
42
- # Using yarn
43
- yarn add @mycodemap/mycodemap
44
-
45
- # Using pnpm
46
- pnpm add @mycodemap/mycodemap
47
-
48
- # Global install (recommended for CLI access)
49
16
  npm install -g @mycodemap/mycodemap
50
17
  ```
51
18
 
52
- **Requirements**: Node.js >= 20.0.0
53
-
54
- ### No Build Tools? No Problem
19
+ Requirements:
55
20
 
56
- CodeMap ships with WASM-first fallback. If your system lacks `python`, `make`, or `gcc`:
57
- - `tree-sitter` automatically falls back to `web-tree-sitter` (WASM)
58
- - `better-sqlite3` automatically falls back to `node:sqlite` (Node.js 22+) or `sql.js` (WASM)
59
- - No manual intervention required — fallback activates on first run
60
-
61
- ### Force Native (Performance)
62
-
63
- If you have build tools installed and want maximum performance:
64
- ```bash
65
- mycodemap --native <command>
66
- ```
67
-
68
- ---
21
+ - Node.js `>= 20.0.0`
22
+ - A project with source files to analyze
69
23
 
70
24
  ## Quick Start
71
25
 
72
26
  ```bash
73
- # 1. Initialize configuration in project root
27
+ # 1. Initialize a project (preview mode)
74
28
  mycodemap init
75
29
 
76
- # 2. Generate code map
77
- mycodemap generate
78
-
79
- # 3. View generated files
80
- ls .mycodemap/
81
- # AI_MAP.md - Project overview (for AI)
82
- # CONTEXT.md - Context entry (links to context/README.md)
83
- # context/ - Detailed module contexts
84
- # codemap.json - Structured JSON data
85
- # dependency-graph.md - Mermaid dependency graph
86
- ```
87
-
88
- ```bash
89
- # 4. For AI/Agent: structured output is the default
90
- mycodemap impact -f src/cli/index.ts -j
91
-
92
- # Human-readable output on demand
93
- mycodemap analyze -i read -t src/cli/index.ts --human
94
-
95
- # Human design → design contract → AI/Agent consumption
96
- cp docs/product-specs/DESIGN_CONTRACT_TEMPLATE.md mycodemap.design.md
97
- mycodemap design validate mycodemap.design.md --json
98
- mycodemap design map mycodemap.design.md --json
99
- mycodemap design handoff mycodemap.design.md --json
100
- mycodemap design verify mycodemap.design.md --json
101
- ```
102
-
103
- After generation, provide `.mycodemap/AI_MAP.md` to your AI assistant for rapid project understanding. For structured results, use JSON/machine mode.
30
+ # 2. Apply the config with --yes
31
+ mycodemap init --yes
104
32
 
105
- ---
106
-
107
- ## CLI Commands
108
-
109
- ### `mycodemap init`
110
-
111
- Initialize and reconcile the project's CodeMap workspace / config / hooks / rules state.
112
-
113
- ```bash
114
- mycodemap init # Show reconciliation preview (default: no write)
115
- mycodemap init --interactive # Explicitly show preview (same as default)
116
- mycodemap init -y # Write with defaults
33
+ # 3. Generate the code map
34
+ mycodemap generate
117
35
  ```
118
36
 
119
- ### `mycodemap generate`
37
+ `mycodemap init` previews the reconciliation plan by default. Use `--yes` to apply it immediately, or `--profile <name>` to bypass auto-detection.
120
38
 
121
- Analyze the project and generate code map files.
39
+ `mycodemap generate` writes analysis output to `.mycodemap/` by default. The canonical config path is `.mycodemap/config.json`; the loader still accepts <!-- VERIFY: `mycodemap.config.json` --> and legacy <!-- VERIFY: `codemap.config.json` --> for compatibility.
122
40
 
123
- ```bash
124
- mycodemap generate # Default hybrid mode
125
- mycodemap generate -m smart # Smart mode (AST deep analysis)
126
- mycodemap generate -o ./docs/codemap # Custom output directory
127
- mycodemap generate --symbol-level # Extra symbol-level call deps
128
- ```
129
-
130
- | Option | Description | Default |
131
- |--------|-------------|---------|
132
- | `-m, --mode <mode>` | Analysis mode: `fast`, `smart`, or `hybrid` | `hybrid` |
133
- | `-o, --output <dir>` | Output directory | `.mycodemap` |
134
- | `--symbol-level` | Materialize symbol-level `call` deps | `false` |
41
+ ## Usage Examples
135
42
 
136
- ### `mycodemap query`
137
-
138
- Query symbols, modules, and dependencies in the code map.
43
+ ### Search symbols across the project
139
44
 
140
45
  ```bash
141
- mycodemap query -s "ModuleInfo" # Exact symbol query
142
- mycodemap query -m "src/parser" # Module info
143
- mycodemap query -S "cache" # Fuzzy search
144
- mycodemap query -S "parse" -j # JSON output
46
+ mycodemap query --symbol createCheckCommand
145
47
  ```
146
48
 
147
- ### `mycodemap analyze`
148
-
149
- Unified analysis entry with four intents: `find`, `read`, `link`, `show`.
49
+ ### Analyze with intent-driven output
150
50
 
151
51
  ```bash
152
52
  mycodemap analyze -i find -k SourceLocation
153
- mycodemap analyze -i read -t src/cli/index.ts --scope transitive
53
+ mycodemap analyze -i read -t src/cli/index.ts --include-tests --json
154
54
  mycodemap analyze -i link -t src/cli/index.ts
155
55
  mycodemap analyze -i show -t src/orchestrator
156
56
  ```
157
57
 
158
- ### `mycodemap --schema`
159
-
160
- Output the full Interface Contract Schema JSON for agent introspection.
58
+ ### Detect circular dependencies
161
59
 
162
60
  ```bash
163
- mycodemap --schema # Full contract output
164
- mycodemap --schema | jq '.' # Pretty-print with jq
61
+ mycodemap cycles
165
62
  ```
166
63
 
167
- ### `mycodemap doctor`
168
-
169
- Continuous health diagnostics for the CodeMap ecosystem.
64
+ ### Export the dependency graph
170
65
 
171
66
  ```bash
172
- mycodemap doctor # Human-readable report
173
- mycodemap doctor --json # Machine-readable JSON
67
+ mycodemap export --format mermaid
174
68
  ```
175
69
 
176
- | Category | Checks |
177
- |----------|--------|
178
- | **install** | Native deps (`tree-sitter`, `better-sqlite3`) load status |
179
- | **config** | `.mycodemap/` workspace configuration integrity |
180
- | **runtime** | Ghost commands, command stubs, package.json consistency |
181
- | **agent** | MCP connectivity, schema validity, tool registration |
182
-
183
- ### `mycodemap benchmark`
184
-
185
- Compare WASM vs Native performance.
70
+ ## Main Commands
186
71
 
187
- ```bash
188
- mycodemap benchmark # Default benchmark
189
- mycodemap benchmark --wasm # Force WASM mode
190
- mycodemap benchmark --native # Force Native mode
191
- ```
72
+ | Command | Purpose |
73
+ |---|---|
74
+ | `mycodemap generate` | Analyze the project and write the code map artifacts |
75
+ | `mycodemap query` | Search symbols, modules, and dependencies |
76
+ | `mycodemap deps` | Inspect module dependency relationships |
77
+ | `mycodemap cycles` | Detect circular dependencies |
78
+ | `mycodemap complexity` | Inspect file and function complexity |
79
+ | `mycodemap impact` | Estimate the impact of a file change |
80
+ | `mycodemap analyze` | Unified analysis entry with intent-driven output |
81
+ | `mycodemap doctor` | Run health diagnostics for config, runtime, and agents |
82
+ | `mycodemap benchmark` | Compare WASM and native startup/performance |
83
+ | `mycodemap export` | Export graph data as JSON, GraphML, DOT, or Mermaid |
84
+ | `mycodemap ship` | Release workflow helpers |
192
85
 
193
- ### MCP Integration (CLI-as-MCP Gateway)
86
+ Additional operational commands include `ci`, `check`, `workflow`, `history`, `preview`, `env-contract`, `mcp`, and `readiness-gate`.
194
87
 
195
- v2.0 MCP integration has upgraded from an experimental 2-tool slice to the **CLI-as-MCP Automatic Gateway**: all schema-defined CLI commands are automatically exposed as MCP tools.
88
+ ### 已移除的公共 CLI 命令
196
89
 
197
- ```bash
198
- mycodemap mcp install # Write local server config to `.mcp.json`
199
- mycodemap mcp start # Start local stdio MCP server
200
- ```
90
+ - `mycodemap server`
91
+ - `mycodemap watch`
92
+ - `mycodemap report`
93
+ - `mycodemap logs`
201
94
 
202
- - All 20+ schema-defined CLI commands are callable via MCP
203
- - Dynamic tool registration: add command to schema → restart MCP server → new tool appears automatically
204
- - See `docs/ai-guide/INTEGRATION.md` for details
95
+ These commands are no longer part of the public CLI surface. Use the current `mycodemap` entry points and the `/api/v1` HTTP server instead.
205
96
 
206
- ---
97
+ `server`、`watch`、`report`、`logs` 已从 public CLI 移除,并在调用时给出迁移提示。
207
98
 
208
99
  ## Documentation
209
100
 
210
- ### For Human Users
211
-
212
- | Document | Audience | Content |
213
- |----------|----------|---------|
214
- | [🧭 Docs Index](docs/README.md) | All readers | Document layers, reading order, migration status |
215
- | [🏗️ Architecture](ARCHITECTURE.md) | Developers | System map, module boundaries, main execution flows |
216
- | [📖 Setup Guide](docs/SETUP_GUIDE.md) | Human developers | Full installation, configuration, and usage guide |
217
- | [📁 Examples](examples/) | All users | Ready-to-use configuration files |
218
-
219
- ### 🤖 AI / Agent Docs
220
-
221
- | Document | Description |
222
- |----------|-------------|
223
- | **[📘 AI_GUIDE.md](AI_GUIDE.md)** | **AI main guide** — quick reference, command decision tree, prompt templates |
224
- | **[🚀 Quick Start](docs/ai-guide/QUICKSTART.md)** | Scenario-to-command mapping |
225
- | **[📚 Commands](docs/ai-guide/COMMANDS.md)** | Full CLI command reference |
226
- | **[📊 Output Schema](docs/ai-guide/OUTPUT.md)** | JSON output structure parsing |
227
- | **[🔧 Integration](docs/ai-guide/INTEGRATION.md)** | MCP/Agent integration, error handling |
228
- | **[🛡️ AGENTS.md](AGENTS.md)** | Repository-level constraints |
229
- | **[⚡ CLAUDE.md](CLAUDE.md)** | AI entry routing |
230
-
231
- ---
101
+ - [AI Guide](AI_GUIDE.md)
102
+ - [Getting Started](docs/GETTING-STARTED.md)
103
+ - [Development](docs/DEVELOPMENT.md)
104
+ - [Testing](docs/TESTING.md)
105
+ - [Configuration](docs/CONFIGURATION.md)
106
+ - [API Reference](docs/API.md)
107
+ - [Contributing](CONTRIBUTING.md)
108
+ - [Architecture](ARCHITECTURE.md)
232
109
 
233
110
  ## Contributing
234
111
 
235
- See [README.zh-CN.md](./README.zh-CN.md) for full development setup, commit conventions, and coding standards (中文版本包含完整的开发环境搭建、提交规范和代码规范).
236
-
237
- ---
112
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
238
113
 
239
114
  ## License
240
115
 
241
- [MIT](LICENSE)
116
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,4 @@
1
+ import type { AgentMetricsReportResult, AgentMetricsTokenRunResult } from '../../../orchestrator/agent-metrics-service.js';
2
+ export declare function formatAgentMetricsTokenRunHuman(result: AgentMetricsTokenRunResult): string;
3
+ export declare function formatAgentMetricsReportHuman(result: AgentMetricsReportResult): string;
4
+ //# sourceMappingURL=human.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"human.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/agent-metrics/human.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,gDAAgD,CAAC;AA+DxD,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,0BAA0B,GAAG,MAAM,CAqB1F;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,wBAAwB,GAAG,MAAM,CAuFtF"}
@@ -0,0 +1,134 @@
1
+ // [META] since:2026-05-10 | owner:cli-team | stable:false
2
+ // [WHY] Human renderer for agent-metrics outputs while keeping shared output mode as the primary surface
3
+ function formatTotals(totals) {
4
+ return [
5
+ `Queries: ${totals.queryCount}`,
6
+ `Response bytes: ${totals.responseSizeBytes}`,
7
+ `Raw chars: ${totals.rawCharCount}`,
8
+ `Estimated input tokens: ${totals.estimatedInputTokens}`,
9
+ `Estimated output tokens: ${totals.estimatedOutputTokens}`,
10
+ `Estimated total tokens: ${totals.estimatedTotalTokens}`,
11
+ `Execution time: ${totals.executionTimeMs}ms`,
12
+ ];
13
+ }
14
+ function formatTable(headers, rows) {
15
+ const widths = headers.map((header, index) => Math.max(header.length, ...rows.map((row) => row[index]?.length ?? 0)));
16
+ const formatRow = (row) => row.map((cell, index) => cell.padEnd(widths[index] ?? cell.length)).join(' | ');
17
+ return [
18
+ formatRow(headers),
19
+ widths.map((width) => '-'.repeat(width)).join('-|-'),
20
+ ...rows.map((row) => formatRow(row)),
21
+ ];
22
+ }
23
+ function formatGateBlock(gate) {
24
+ const lines = ['Gate:'];
25
+ if (gate.warnOnly) {
26
+ lines.push('verdict=warn warn_only=true threshold=none');
27
+ lines.push('No default calibrated threshold yet; showing the worst observed row only.');
28
+ if (gate.maxRow) {
29
+ lines.push(`Worst row: ${gate.maxRow.queryType} | ${gate.maxRow.commandSlug} | est_total=${gate.maxRow.estimatedTotalTokens}`);
30
+ }
31
+ return lines;
32
+ }
33
+ lines.push(`verdict=${gate.verdict} warn_only=false threshold=${gate.threshold ?? 'none'} violation_count=${gate.violationCount}`);
34
+ if (gate.maxRow) {
35
+ lines.push(`Worst row: ${gate.maxRow.queryType} | ${gate.maxRow.commandSlug} | est_total=${gate.maxRow.estimatedTotalTokens}`);
36
+ }
37
+ if (gate.violations.length > 0) {
38
+ lines.push('Violations:');
39
+ for (const violation of gate.violations.slice(0, 3)) {
40
+ lines.push(`- ${violation.queryType} | ${violation.commandSlug} | est_total=${violation.estimatedTotalTokens}`);
41
+ }
42
+ }
43
+ return lines;
44
+ }
45
+ export function formatAgentMetricsTokenRunHuman(result) {
46
+ const lines = [
47
+ 'Agent Metrics Token Run',
48
+ `Run ID: ${result.runId}`,
49
+ `Recorded: ${result.recordedAt}`,
50
+ `Sample set: ${result.sampleSetVersion}`,
51
+ `Estimator: ${result.estimatorVersion} (estimated values, not tokenizer-exact)`,
52
+ '',
53
+ 'Per-query results:',
54
+ ];
55
+ for (const item of result.items) {
56
+ lines.push(`- ${item.queryType} | ${item.commandSlug}`, ` bytes=${item.responseSizeBytes} chars=${item.rawCharCount} est_in=${item.estimatedInputTokens} est_out=${item.estimatedOutputTokens} est_total=${item.estimatedTotalTokens} time=${item.executionTimeMs}ms`);
57
+ }
58
+ lines.push('', 'Totals:');
59
+ lines.push(...formatTotals(result.totals));
60
+ return lines.join('\n');
61
+ }
62
+ export function formatAgentMetricsReportHuman(result) {
63
+ const lines = [
64
+ 'Agent Metrics Report',
65
+ `Run ID: ${result.runId}`,
66
+ `Recorded: ${result.recordedAt}`,
67
+ `Generated: ${result.generatedAt}`,
68
+ `Sample set: ${result.sampleSetVersion}`,
69
+ `Estimator: ${result.estimatorVersion} (estimated values, not tokenizer-exact)`,
70
+ '',
71
+ 'Summary:',
72
+ ];
73
+ lines.push(...formatGateBlock(result.gate));
74
+ lines.push(...formatTotals(result.totals));
75
+ lines.push('', 'By query type:');
76
+ lines.push(...formatTable(['Query type', 'Count', 'Hist', 'Avg tok', 'P50 tok', 'P95 tok', 'Max tok', 'Avg bytes', 'Min bytes', 'Max bytes'], result.queryTypeSummaries.map((summary) => [
77
+ summary.queryType,
78
+ String(summary.queryCount),
79
+ String(summary.historicalSampleCount),
80
+ String(summary.avgEstimatedTotalTokens),
81
+ String(summary.p50EstimatedTotalTokens),
82
+ String(summary.p95EstimatedTotalTokens),
83
+ String(summary.maxEstimatedTotalTokens),
84
+ String(summary.avgResponseSizeBytes),
85
+ String(summary.minResponseSizeBytes),
86
+ String(summary.maxResponseSizeBytes),
87
+ ])));
88
+ lines.push('', 'Per-query rows:');
89
+ lines.push(...formatTable(['Query type', 'Command', 'Bytes', 'Chars', 'Est in', 'Est out', 'Est total', 'Time'], result.rows.map((row) => [
90
+ row.queryType,
91
+ row.commandSlug,
92
+ String(row.responseSizeBytes),
93
+ String(row.rawCharCount),
94
+ String(row.estimatedInputTokens),
95
+ String(row.estimatedOutputTokens),
96
+ String(row.estimatedTotalTokens),
97
+ `${row.executionTimeMs}ms`,
98
+ ])));
99
+ lines.push('', 'Trend vs previous run:');
100
+ if (result.queryTypeTrends.length === 0) {
101
+ lines.push('- none');
102
+ }
103
+ else {
104
+ for (const trend of result.queryTypeTrends.slice(0, 3)) {
105
+ const previous = trend.previousEstimatedTotalTokens ?? 'none';
106
+ const delta = trend.deltaEstimatedTotalTokens ?? 'none';
107
+ const deltaPercent = trend.deltaPercent === null ? 'none' : `${trend.deltaPercent}%`;
108
+ lines.push(`- ${trend.queryType} | latest=${trend.latestEstimatedTotalTokens} previous=${previous} delta=${delta} delta_percent=${deltaPercent}`);
109
+ if (!trend.baselineAvailable) {
110
+ lines.push(' Baseline unavailable for comparison.');
111
+ }
112
+ }
113
+ }
114
+ lines.push('', 'Highest cost query types:');
115
+ if (result.highestCostQueryTypes.length === 0) {
116
+ lines.push('- none');
117
+ }
118
+ else {
119
+ for (const item of result.highestCostQueryTypes.slice(0, 3)) {
120
+ lines.push(`- ${item.queryType} | est_total=${item.estimatedTotalTokens} | ${item.riskNote}`);
121
+ }
122
+ }
123
+ lines.push('', 'Highest cost samples:');
124
+ if (result.highestCostRows.length === 0) {
125
+ lines.push('- none');
126
+ }
127
+ else {
128
+ for (const item of result.highestCostRows.slice(0, 3)) {
129
+ lines.push(`- ${item.queryType} | ${item.commandSlug} | est_total=${item.estimatedTotalTokens} | ${item.riskNote}`);
130
+ }
131
+ }
132
+ return lines.join('\n');
133
+ }
134
+ //# sourceMappingURL=human.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"human.js","sourceRoot":"","sources":["../../../../src/cli/commands/agent-metrics/human.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,yGAAyG;AAQzG,SAAS,YAAY,CAAC,MAA4C;IAChE,OAAO;QACL,YAAY,MAAM,CAAC,UAAU,EAAE;QAC/B,mBAAmB,MAAM,CAAC,iBAAiB,EAAE;QAC7C,cAAc,MAAM,CAAC,YAAY,EAAE;QACnC,2BAA2B,MAAM,CAAC,oBAAoB,EAAE;QACxD,4BAA4B,MAAM,CAAC,qBAAqB,EAAE;QAC1D,2BAA2B,MAAM,CAAC,oBAAoB,EAAE;QACxD,mBAAmB,MAAM,CAAC,eAAe,IAAI;KAC9C,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,OAAiB,EAAE,IAAgB;IACtD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAC3C,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC,CACvE,CAAC;IAEF,MAAM,SAAS,GAAG,CAAC,GAAa,EAAU,EAAE,CAC1C,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,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IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC;gBAC7B,KAAK,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,2BAA2B,CAAC,CAAC;IAC5C,IAAI,MAAM,CAAC,qBAAqB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9C,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YAC5D,KAAK,CAAC,IAAI,CACR,KAAK,IAAI,CAAC,SAAS,gBAAgB,IAAI,CAAC,oBAAoB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAClF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,uBAAuB,CAAC,CAAC;IACxC,IAAI,MAAM,CAAC,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YACtD,KAAK,CAAC,IAAI,CACR,KAAK,IAAI,CAAC,SAAS,MAAM,IAAI,CAAC,WAAW,gBAAgB,IAAI,CAAC,oBAAoB,MAAM,IAAI,CAAC,QAAQ,EAAE,CACxG,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { Command } from 'commander';
2
+ import { type AgentMetricsReportResult, type AgentMetricsTokenRunResult } from '../../../orchestrator/agent-metrics-service.js';
3
+ export interface AgentMetricsCommandOptions {
4
+ json?: boolean;
5
+ human?: boolean;
6
+ maxTokensPerQuery?: string;
7
+ }
8
+ export interface AgentMetricsServiceLike {
9
+ executeTokenRun(rootDir: string): Promise<AgentMetricsTokenRunResult>;
10
+ runReportFlow(rootDir: string): Promise<AgentMetricsReportResult>;
11
+ requireLatestReport(rootDir: string): Promise<AgentMetricsReportResult>;
12
+ }
13
+ export declare function createAgentMetricsCommand(service?: AgentMetricsServiceLike): Command;
14
+ export declare const agentMetricsCommand: Command;
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/agent-metrics/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAChC,MAAM,gDAAgD,CAAC;AAMxD,MAAM,WAAW,0BAA0B;IACzC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACtE,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAClE,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;CACzE;AA0HD,wBAAgB,yBAAyB,CACvC,OAAO,GAAE,uBAAmD,GAC3D,OAAO,CAkCT;AAED,eAAO,MAAM,mBAAmB,SAA8B,CAAC"}
@@ -0,0 +1,116 @@
1
+ // [META] since:2026-05-10 | owner:cli-team | stable:false
2
+ // [WHY] Thin CLI wrapper for agent-metrics so measurement/report logic stays in the dedicated service
3
+ import { Command } from 'commander';
4
+ import { cwd } from 'node:process';
5
+ import { createProgressEmitter, formatError, renderOutput, resolveOutputMode, } from '../../output/index.js';
6
+ import { AgentMetricsService, } from '../../../orchestrator/agent-metrics-service.js';
7
+ import { formatAgentMetricsReportHuman, formatAgentMetricsTokenRunHuman, } from './human.js';
8
+ function applyOutputOptions(command) {
9
+ return command
10
+ .option('-j, --json', 'JSON 格式输出')
11
+ .option('--human', '强制人类可读输出');
12
+ }
13
+ function applyThresholdOption(command) {
14
+ return command.option('--max-tokens-per-query <number>', '报告路径允许的单次查询最大估算 token 数');
15
+ }
16
+ function toMode(options) {
17
+ return resolveOutputMode({ json: options.json, human: options.human });
18
+ }
19
+ function toCommandOptions(command) {
20
+ return command.opts();
21
+ }
22
+ function toCommandOptionsWithGlobals(command) {
23
+ return command.optsWithGlobals();
24
+ }
25
+ function resolveMaxTokensPerQuery(options) {
26
+ if (options.maxTokensPerQuery === undefined) {
27
+ return undefined;
28
+ }
29
+ const parsed = Number(options.maxTokensPerQuery);
30
+ if (!Number.isFinite(parsed) || parsed < 0) {
31
+ const error = new Error(`Invalid --max-tokens-per-query value: ${options.maxTokensPerQuery}`);
32
+ error.code = 'AGENT_METRICS_INVALID_THRESHOLD';
33
+ error.remediation = 'Provide a finite non-negative number for --max-tokens-per-query.';
34
+ error.nextCommand = 'codemap agent-metrics report --max-tokens-per-query 160';
35
+ error.confidence = 0.95;
36
+ throw error;
37
+ }
38
+ return parsed;
39
+ }
40
+ function renderReportResult(result, mode, maxTokensPerQuery) {
41
+ const gatedResult = AgentMetricsService.withGate(result, maxTokensPerQuery);
42
+ renderOutput(gatedResult, formatAgentMetricsReportHuman, mode);
43
+ if (maxTokensPerQuery !== undefined && gatedResult.gate.verdict === 'fail') {
44
+ process.exitCode = 1;
45
+ }
46
+ }
47
+ async function handleTokenCommand(service, options) {
48
+ const mode = toMode(options);
49
+ const progress = createProgressEmitter(mode, 'Measuring token costs...');
50
+ try {
51
+ progress.update(30, 'Running built-in agent-metrics samples...');
52
+ const result = await service.executeTokenRun(cwd());
53
+ progress.complete();
54
+ renderOutput(result, formatAgentMetricsTokenRunHuman, mode);
55
+ }
56
+ catch (error) {
57
+ progress.fail();
58
+ process.stdout.write(formatError(error, mode, 'codemap agent-metrics token') + '\n');
59
+ process.exitCode = 1;
60
+ }
61
+ }
62
+ async function handleReportCommand(service, options) {
63
+ const mode = toMode(options);
64
+ const progress = createProgressEmitter(mode, 'Building agent-metrics report...');
65
+ try {
66
+ const maxTokensPerQuery = resolveMaxTokensPerQuery(options);
67
+ progress.update(30, 'Loading latest persisted run...');
68
+ const result = await service.requireLatestReport(cwd());
69
+ progress.complete();
70
+ renderReportResult(result, mode, maxTokensPerQuery);
71
+ }
72
+ catch (error) {
73
+ progress.fail();
74
+ process.stdout.write(formatError(error, mode, 'codemap agent-metrics report') + '\n');
75
+ process.exitCode = 1;
76
+ }
77
+ }
78
+ async function handleRootCommand(service, options) {
79
+ const mode = toMode(options);
80
+ const progress = createProgressEmitter(mode, 'Building agent-metrics report...');
81
+ try {
82
+ const maxTokensPerQuery = resolveMaxTokensPerQuery(options);
83
+ progress.update(30, 'Loading latest run or executing the fixed sample set...');
84
+ const result = await service.runReportFlow(cwd());
85
+ progress.complete();
86
+ renderReportResult(result, mode, maxTokensPerQuery);
87
+ }
88
+ catch (error) {
89
+ progress.fail();
90
+ process.stdout.write(formatError(error, mode, 'codemap agent-metrics') + '\n');
91
+ process.exitCode = 1;
92
+ }
93
+ }
94
+ export function createAgentMetricsCommand(service = new AgentMetricsService()) {
95
+ const command = applyThresholdOption(applyOutputOptions(new Command('agent-metrics')
96
+ .description('分析 CodeMap 查询响应的估算 LLM token 成本')));
97
+ const tokenCommand = applyOutputOptions(command.command('token')
98
+ .description('执行固定 built-in 查询样本并持久化 token-cost 明细'));
99
+ tokenCommand.action(async (...args) => {
100
+ const actionCommand = args.at(-1);
101
+ await handleTokenCommand(service, toCommandOptions(actionCommand));
102
+ });
103
+ const reportCommand = applyThresholdOption(applyOutputOptions(command.command('report')
104
+ .description('输出最新一次 token-cost run 的最小报告;若不存在则提示先运行测量')));
105
+ reportCommand.action(async (...args) => {
106
+ const actionCommand = args.at(-1);
107
+ await handleReportCommand(service, toCommandOptionsWithGlobals(actionCommand));
108
+ });
109
+ command.action(async (...args) => {
110
+ const actionCommand = args.at(-1);
111
+ await handleRootCommand(service, toCommandOptionsWithGlobals(actionCommand));
112
+ });
113
+ return command;
114
+ }
115
+ export const agentMetricsCommand = createAgentMetricsCommand();
116
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cli/commands/agent-metrics/index.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,sGAAsG;AAEtG,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,mBAAmB,GAGpB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,6BAA6B,EAC7B,+BAA+B,GAChC,MAAM,YAAY,CAAC;AAcpB,SAAS,kBAAkB,CAAC,OAAgB;IAC1C,OAAO,OAAO;SACX,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC;SACjC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAgB;IAC5C,OAAO,OAAO,CAAC,MAAM,CACnB,iCAAiC,EACjC,yBAAyB,CAC1B,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,OAAmC;IACjD,OAAO,iBAAiB,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAgB;I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