homegraph 1.2.0 → 1.5.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 (560) hide show
  1. package/README.md +48 -11
  2. package/dist/bin/homegraph.js +298 -72
  3. package/dist/bin/homegraph.js.map +1 -1
  4. package/dist/context/index.d.ts.map +1 -1
  5. package/dist/context/index.js +117 -11
  6. package/dist/context/index.js.map +1 -1
  7. package/dist/db/index.d.ts +207 -6
  8. package/dist/db/index.d.ts.map +1 -1
  9. package/dist/db/index.js +461 -20
  10. package/dist/db/index.js.map +1 -1
  11. package/dist/db/migrations.d.ts +1 -1
  12. package/dist/db/migrations.d.ts.map +1 -1
  13. package/dist/db/migrations.js +19 -1
  14. package/dist/db/migrations.js.map +1 -1
  15. package/dist/db/queries.d.ts +157 -3
  16. package/dist/db/queries.d.ts.map +1 -1
  17. package/dist/db/queries.js +426 -9
  18. package/dist/db/queries.js.map +1 -1
  19. package/dist/db/schema.sql +32 -1
  20. package/dist/db/sqlite-adapter.d.ts +24 -17
  21. package/dist/db/sqlite-adapter.d.ts.map +1 -1
  22. package/dist/db/sqlite-adapter.js +292 -36
  23. package/dist/db/sqlite-adapter.js.map +1 -1
  24. package/dist/db/wal-valve.d.ts +119 -0
  25. package/dist/db/wal-valve.d.ts.map +1 -0
  26. package/dist/db/wal-valve.js +290 -0
  27. package/dist/db/wal-valve.js.map +1 -0
  28. package/dist/directory.d.ts +9 -5
  29. package/dist/directory.d.ts.map +1 -1
  30. package/dist/directory.js +210 -19
  31. package/dist/directory.js.map +1 -1
  32. package/dist/extraction/arkts-batch-worker.js +3 -2
  33. package/dist/extraction/arkts-batch-worker.js.map +1 -1
  34. package/dist/extraction/cfml-extractor.d.ts +107 -0
  35. package/dist/extraction/cfml-extractor.d.ts.map +1 -0
  36. package/dist/extraction/cfml-extractor.js +494 -0
  37. package/dist/extraction/cfml-extractor.js.map +1 -0
  38. package/dist/extraction/default-ignore.d.ts +39 -0
  39. package/dist/extraction/default-ignore.d.ts.map +1 -0
  40. package/dist/extraction/default-ignore.js +221 -0
  41. package/dist/extraction/default-ignore.js.map +1 -0
  42. package/dist/extraction/grammars.d.ts +25 -1
  43. package/dist/extraction/grammars.d.ts.map +1 -1
  44. package/dist/extraction/grammars.js +177 -24
  45. package/dist/extraction/grammars.js.map +1 -1
  46. package/dist/extraction/index.d.ts +52 -14
  47. package/dist/extraction/index.d.ts.map +1 -1
  48. package/dist/extraction/index.js +521 -314
  49. package/dist/extraction/index.js.map +1 -1
  50. package/dist/extraction/languages/arkts.d.ts +90 -6
  51. package/dist/extraction/languages/arkts.d.ts.map +1 -1
  52. package/dist/extraction/languages/arkts.js +1579 -128
  53. package/dist/extraction/languages/arkts.js.map +1 -1
  54. package/dist/extraction/languages/c-cpp.d.ts +42 -0
  55. package/dist/extraction/languages/c-cpp.d.ts.map +1 -1
  56. package/dist/extraction/languages/c-cpp.js +369 -4
  57. package/dist/extraction/languages/c-cpp.js.map +1 -1
  58. package/dist/extraction/languages/cfquery.d.ts +12 -0
  59. package/dist/extraction/languages/cfquery.d.ts.map +1 -0
  60. package/dist/extraction/languages/cfquery.js +28 -0
  61. package/dist/extraction/languages/cfquery.js.map +1 -0
  62. package/dist/extraction/languages/cfscript.d.ts +3 -0
  63. package/dist/extraction/languages/cfscript.d.ts.map +1 -0
  64. package/dist/extraction/languages/cfscript.js +73 -0
  65. package/dist/extraction/languages/cfscript.js.map +1 -0
  66. package/dist/extraction/languages/cobol.d.ts +33 -0
  67. package/dist/extraction/languages/cobol.d.ts.map +1 -0
  68. package/dist/extraction/languages/cobol.js +499 -0
  69. package/dist/extraction/languages/cobol.js.map +1 -0
  70. package/dist/extraction/languages/erlang.d.ts +3 -0
  71. package/dist/extraction/languages/erlang.d.ts.map +1 -0
  72. package/dist/extraction/languages/erlang.js +350 -0
  73. package/dist/extraction/languages/erlang.js.map +1 -0
  74. package/dist/extraction/languages/index.d.ts.map +1 -1
  75. package/dist/extraction/languages/index.js +16 -0
  76. package/dist/extraction/languages/index.js.map +1 -1
  77. package/dist/extraction/languages/nix.d.ts +3 -0
  78. package/dist/extraction/languages/nix.d.ts.map +1 -0
  79. package/dist/extraction/languages/nix.js +294 -0
  80. package/dist/extraction/languages/nix.js.map +1 -0
  81. package/dist/extraction/languages/solidity.d.ts +3 -0
  82. package/dist/extraction/languages/solidity.d.ts.map +1 -0
  83. package/dist/extraction/languages/solidity.js +293 -0
  84. package/dist/extraction/languages/solidity.js.map +1 -0
  85. package/dist/extraction/languages/terraform.d.ts +3 -0
  86. package/dist/extraction/languages/terraform.d.ts.map +1 -0
  87. package/dist/extraction/languages/terraform.js +641 -0
  88. package/dist/extraction/languages/terraform.js.map +1 -0
  89. package/dist/extraction/languages/vbnet.d.ts +11 -0
  90. package/dist/extraction/languages/vbnet.d.ts.map +1 -0
  91. package/dist/extraction/languages/vbnet.js +141 -0
  92. package/dist/extraction/languages/vbnet.js.map +1 -0
  93. package/dist/extraction/mybatis-extractor.d.ts +30 -10
  94. package/dist/extraction/mybatis-extractor.d.ts.map +1 -1
  95. package/dist/extraction/mybatis-extractor.js +140 -38
  96. package/dist/extraction/mybatis-extractor.js.map +1 -1
  97. package/dist/extraction/parse-pool.d.ts +27 -1
  98. package/dist/extraction/parse-pool.d.ts.map +1 -1
  99. package/dist/extraction/parse-pool.js +75 -7
  100. package/dist/extraction/parse-pool.js.map +1 -1
  101. package/dist/extraction/parse-worker.js +9 -2
  102. package/dist/extraction/parse-worker.js.map +1 -1
  103. package/dist/extraction/store-worker.d.ts +20 -0
  104. package/dist/extraction/store-worker.d.ts.map +1 -0
  105. package/dist/extraction/store-worker.js +102 -0
  106. package/dist/extraction/store-worker.js.map +1 -0
  107. package/dist/extraction/store-writer.d.ts +48 -0
  108. package/dist/extraction/store-writer.d.ts.map +1 -0
  109. package/dist/extraction/store-writer.js +167 -0
  110. package/dist/extraction/store-writer.js.map +1 -0
  111. package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -1
  112. package/dist/extraction/tree-sitter-helpers.js +1 -0
  113. package/dist/extraction/tree-sitter-helpers.js.map +1 -1
  114. package/dist/extraction/tree-sitter-types.d.ts +3 -1
  115. package/dist/extraction/tree-sitter-types.d.ts.map +1 -1
  116. package/dist/extraction/tree-sitter.d.ts +38 -0
  117. package/dist/extraction/tree-sitter.d.ts.map +1 -1
  118. package/dist/extraction/tree-sitter.js +801 -10
  119. package/dist/extraction/tree-sitter.js.map +1 -1
  120. package/dist/extraction/wasm/tree-sitter-arkts.wasm +0 -0
  121. package/dist/extraction/wasm/tree-sitter-cfml.wasm +0 -0
  122. package/dist/extraction/wasm/tree-sitter-cfquery.wasm +0 -0
  123. package/dist/extraction/wasm/tree-sitter-cfscript.wasm +0 -0
  124. package/dist/extraction/wasm/tree-sitter-cobol.wasm +0 -0
  125. package/dist/extraction/wasm/tree-sitter-erlang.wasm +0 -0
  126. package/dist/extraction/wasm/tree-sitter-nix.wasm +0 -0
  127. package/dist/extraction/wasm/tree-sitter-terraform.wasm +0 -0
  128. package/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
  129. package/dist/extraction/wasm-runtime-flags.d.ts +14 -4
  130. package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
  131. package/dist/extraction/wasm-runtime-flags.js +55 -7
  132. package/dist/extraction/wasm-runtime-flags.js.map +1 -1
  133. package/dist/graph/traversal.d.ts.map +1 -1
  134. package/dist/graph/traversal.js +1 -1
  135. package/dist/graph/traversal.js.map +1 -1
  136. package/dist/index.d.ts +74 -5
  137. package/dist/index.d.ts.map +1 -1
  138. package/dist/index.js +436 -55
  139. package/dist/index.js.map +1 -1
  140. package/dist/installer/index.d.ts +42 -0
  141. package/dist/installer/index.d.ts.map +1 -1
  142. package/dist/installer/index.js +97 -2
  143. package/dist/installer/index.js.map +1 -1
  144. package/dist/mcp/daemon.d.ts +25 -3
  145. package/dist/mcp/daemon.d.ts.map +1 -1
  146. package/dist/mcp/daemon.js +62 -8
  147. package/dist/mcp/daemon.js.map +1 -1
  148. package/dist/mcp/dynamic-boundaries.d.ts.map +1 -1
  149. package/dist/mcp/dynamic-boundaries.js +2 -1
  150. package/dist/mcp/dynamic-boundaries.js.map +1 -1
  151. package/dist/mcp/early-ppid.d.ts +26 -0
  152. package/dist/mcp/early-ppid.d.ts.map +1 -0
  153. package/dist/mcp/early-ppid.js +29 -0
  154. package/dist/mcp/early-ppid.js.map +1 -0
  155. package/dist/mcp/engine.d.ts +4 -5
  156. package/dist/mcp/engine.d.ts.map +1 -1
  157. package/dist/mcp/engine.js +27 -1
  158. package/dist/mcp/engine.js.map +1 -1
  159. package/dist/mcp/index.d.ts.map +1 -1
  160. package/dist/mcp/index.js +41 -6
  161. package/dist/mcp/index.js.map +1 -1
  162. package/dist/mcp/liveness-watchdog.d.ts +18 -1
  163. package/dist/mcp/liveness-watchdog.d.ts.map +1 -1
  164. package/dist/mcp/liveness-watchdog.js +73 -13
  165. package/dist/mcp/liveness-watchdog.js.map +1 -1
  166. package/dist/mcp/memory-budget.d.ts +30 -0
  167. package/dist/mcp/memory-budget.d.ts.map +1 -0
  168. package/dist/mcp/memory-budget.js +123 -0
  169. package/dist/mcp/memory-budget.js.map +1 -0
  170. package/dist/mcp/proxy.d.ts.map +1 -1
  171. package/dist/mcp/proxy.js +88 -4
  172. package/dist/mcp/proxy.js.map +1 -1
  173. package/dist/mcp/query-cache.d.ts +35 -4
  174. package/dist/mcp/query-cache.d.ts.map +1 -1
  175. package/dist/mcp/query-cache.js +89 -19
  176. package/dist/mcp/query-cache.js.map +1 -1
  177. package/dist/mcp/query-pool.d.ts +46 -12
  178. package/dist/mcp/query-pool.d.ts.map +1 -1
  179. package/dist/mcp/query-pool.js +100 -23
  180. package/dist/mcp/query-pool.js.map +1 -1
  181. package/dist/mcp/query-worker.d.ts +2 -2
  182. package/dist/mcp/query-worker.js +2 -2
  183. package/dist/mcp/server-instructions.d.ts +4 -27
  184. package/dist/mcp/server-instructions.d.ts.map +1 -1
  185. package/dist/mcp/server-instructions.js +39 -84
  186. package/dist/mcp/server-instructions.js.map +1 -1
  187. package/dist/mcp/session.d.ts +14 -0
  188. package/dist/mcp/session.d.ts.map +1 -1
  189. package/dist/mcp/session.js +28 -1
  190. package/dist/mcp/session.js.map +1 -1
  191. package/dist/mcp/startup-handshake.d.ts +44 -0
  192. package/dist/mcp/startup-handshake.d.ts.map +1 -0
  193. package/dist/mcp/startup-handshake.js +73 -0
  194. package/dist/mcp/startup-handshake.js.map +1 -0
  195. package/dist/mcp/tools.d.ts +104 -4
  196. package/dist/mcp/tools.d.ts.map +1 -1
  197. package/dist/mcp/tools.js +2432 -217
  198. package/dist/mcp/tools.js.map +1 -1
  199. package/dist/mcp/transport.d.ts.map +1 -1
  200. package/dist/mcp/transport.js +18 -0
  201. package/dist/mcp/transport.js.map +1 -1
  202. package/dist/project-config.d.ts +38 -0
  203. package/dist/project-config.d.ts.map +1 -1
  204. package/dist/project-config.js +101 -2
  205. package/dist/project-config.js.map +1 -1
  206. package/dist/resolution/c-fnptr-synthesizer.d.ts +2 -1
  207. package/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
  208. package/dist/resolution/c-fnptr-synthesizer.js +178 -146
  209. package/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
  210. package/dist/resolution/callback-synthesizer.d.ts +54 -10
  211. package/dist/resolution/callback-synthesizer.d.ts.map +1 -1
  212. package/dist/resolution/callback-synthesizer.js +1299 -257
  213. package/dist/resolution/callback-synthesizer.js.map +1 -1
  214. package/dist/resolution/cooperative-yield.d.ts +10 -2
  215. package/dist/resolution/cooperative-yield.d.ts.map +1 -1
  216. package/dist/resolution/cooperative-yield.js +6 -4
  217. package/dist/resolution/cooperative-yield.js.map +1 -1
  218. package/dist/resolution/frameworks/cics.d.ts +20 -0
  219. package/dist/resolution/frameworks/cics.d.ts.map +1 -0
  220. package/dist/resolution/frameworks/cics.js +90 -0
  221. package/dist/resolution/frameworks/cics.js.map +1 -0
  222. package/dist/resolution/frameworks/go.d.ts.map +1 -1
  223. package/dist/resolution/frameworks/go.js +29 -6
  224. package/dist/resolution/frameworks/go.js.map +1 -1
  225. package/dist/resolution/frameworks/index.d.ts.map +1 -1
  226. package/dist/resolution/frameworks/index.js +3 -0
  227. package/dist/resolution/frameworks/index.js.map +1 -1
  228. package/dist/resolution/frameworks/java.d.ts.map +1 -1
  229. package/dist/resolution/frameworks/java.js +14 -6
  230. package/dist/resolution/frameworks/java.js.map +1 -1
  231. package/dist/resolution/frameworks/terraform.d.ts +38 -0
  232. package/dist/resolution/frameworks/terraform.d.ts.map +1 -0
  233. package/dist/resolution/frameworks/terraform.js +277 -0
  234. package/dist/resolution/frameworks/terraform.js.map +1 -0
  235. package/dist/resolution/goframe-synthesizer.d.ts +2 -1
  236. package/dist/resolution/goframe-synthesizer.d.ts.map +1 -1
  237. package/dist/resolution/goframe-synthesizer.js +8 -3
  238. package/dist/resolution/goframe-synthesizer.js.map +1 -1
  239. package/dist/resolution/import-resolver.d.ts +9 -3
  240. package/dist/resolution/import-resolver.d.ts.map +1 -1
  241. package/dist/resolution/import-resolver.js +295 -11
  242. package/dist/resolution/import-resolver.js.map +1 -1
  243. package/dist/resolution/index.d.ts +146 -8
  244. package/dist/resolution/index.d.ts.map +1 -1
  245. package/dist/resolution/index.js +1089 -131
  246. package/dist/resolution/index.js.map +1 -1
  247. package/dist/resolution/memory-budget.d.ts +48 -0
  248. package/dist/resolution/memory-budget.d.ts.map +1 -0
  249. package/dist/resolution/memory-budget.js +162 -0
  250. package/dist/resolution/memory-budget.js.map +1 -0
  251. package/dist/resolution/name-matcher.d.ts +12 -4
  252. package/dist/resolution/name-matcher.d.ts.map +1 -1
  253. package/dist/resolution/name-matcher.js +793 -130
  254. package/dist/resolution/name-matcher.js.map +1 -1
  255. package/dist/resolution/resolver-pool.d.ts +106 -0
  256. package/dist/resolution/resolver-pool.d.ts.map +1 -0
  257. package/dist/resolution/resolver-pool.js +344 -0
  258. package/dist/resolution/resolver-pool.js.map +1 -0
  259. package/dist/resolution/resolver-worker.d.ts +17 -0
  260. package/dist/resolution/resolver-worker.d.ts.map +1 -0
  261. package/dist/resolution/resolver-worker.js +141 -0
  262. package/dist/resolution/resolver-worker.js.map +1 -0
  263. package/dist/resolution/strip-comments.d.ts +1 -1
  264. package/dist/resolution/strip-comments.d.ts.map +1 -1
  265. package/dist/resolution/strip-comments.js +49 -0
  266. package/dist/resolution/strip-comments.js.map +1 -1
  267. package/dist/resolution/types.d.ts +32 -0
  268. package/dist/resolution/types.d.ts.map +1 -1
  269. package/dist/resolution/workspace-packages.d.ts +10 -0
  270. package/dist/resolution/workspace-packages.d.ts.map +1 -1
  271. package/dist/resolution/workspace-packages.js +142 -4
  272. package/dist/resolution/workspace-packages.js.map +1 -1
  273. package/dist/search/identifier-segments.d.ts +60 -0
  274. package/dist/search/identifier-segments.d.ts.map +1 -0
  275. package/dist/search/identifier-segments.js +176 -0
  276. package/dist/search/identifier-segments.js.map +1 -0
  277. package/dist/search/query-utils.d.ts +201 -0
  278. package/dist/search/query-utils.d.ts.map +1 -1
  279. package/dist/search/query-utils.js +919 -2
  280. package/dist/search/query-utils.js.map +1 -1
  281. package/dist/spec/build/diff-parser.d.ts +55 -0
  282. package/dist/spec/build/diff-parser.d.ts.map +1 -0
  283. package/dist/spec/build/diff-parser.js +205 -0
  284. package/dist/spec/build/diff-parser.js.map +1 -0
  285. package/dist/spec/build/git-scanner.d.ts +93 -0
  286. package/dist/spec/build/git-scanner.d.ts.map +1 -0
  287. package/dist/spec/build/git-scanner.js +254 -0
  288. package/dist/spec/build/git-scanner.js.map +1 -0
  289. package/dist/spec/build/pipeline.d.ts +54 -0
  290. package/dist/spec/build/pipeline.d.ts.map +1 -0
  291. package/dist/spec/build/pipeline.js +170 -0
  292. package/dist/spec/build/pipeline.js.map +1 -0
  293. package/dist/spec/build/scan.d.ts +48 -0
  294. package/dist/spec/build/scan.d.ts.map +1 -0
  295. package/dist/spec/build/scan.js +89 -0
  296. package/dist/spec/build/scan.js.map +1 -0
  297. package/dist/spec/build/scope-resolver.d.ts +50 -0
  298. package/dist/spec/build/scope-resolver.d.ts.map +1 -0
  299. package/dist/spec/build/scope-resolver.js +105 -0
  300. package/dist/spec/build/scope-resolver.js.map +1 -0
  301. package/dist/spec/build/spec-extractor.d.ts +74 -0
  302. package/dist/spec/build/spec-extractor.d.ts.map +1 -0
  303. package/dist/spec/build/spec-extractor.js +344 -0
  304. package/dist/spec/build/spec-extractor.js.map +1 -0
  305. package/dist/spec/config.d.ts +35 -1
  306. package/dist/spec/config.d.ts.map +1 -1
  307. package/dist/spec/config.js +30 -5
  308. package/dist/spec/config.js.map +1 -1
  309. package/dist/spec/db/fts.d.ts.map +1 -1
  310. package/dist/spec/db/fts.js +19 -50
  311. package/dist/spec/db/fts.js.map +1 -1
  312. package/dist/spec/db/index.d.ts +5 -3
  313. package/dist/spec/db/index.d.ts.map +1 -1
  314. package/dist/spec/db/index.js +16 -1
  315. package/dist/spec/db/index.js.map +1 -1
  316. package/dist/spec/db/persist.d.ts +45 -0
  317. package/dist/spec/db/persist.d.ts.map +1 -0
  318. package/dist/spec/db/persist.js +66 -0
  319. package/dist/spec/db/persist.js.map +1 -0
  320. package/dist/spec/db/relations.d.ts +80 -1
  321. package/dist/spec/db/relations.d.ts.map +1 -1
  322. package/dist/spec/db/relations.js +175 -4
  323. package/dist/spec/db/relations.js.map +1 -1
  324. package/dist/spec/db/schema.d.ts +4 -0
  325. package/dist/spec/db/schema.d.ts.map +1 -1
  326. package/dist/spec/db/schema.js +4 -0
  327. package/dist/spec/db/schema.js.map +1 -1
  328. package/dist/spec/db/schema.sql +5 -1
  329. package/dist/spec/db/spec-node.d.ts +5 -0
  330. package/dist/spec/db/spec-node.d.ts.map +1 -1
  331. package/dist/spec/db/spec-node.js +11 -5
  332. package/dist/spec/db/spec-node.js.map +1 -1
  333. package/dist/spec/db/sql-utils.d.ts +11 -0
  334. package/dist/spec/db/sql-utils.d.ts.map +1 -0
  335. package/dist/spec/db/sql-utils.js +19 -0
  336. package/dist/spec/db/sql-utils.js.map +1 -0
  337. package/dist/spec/evolve/cluster-context.d.ts +30 -0
  338. package/dist/spec/evolve/cluster-context.d.ts.map +1 -0
  339. package/dist/spec/evolve/cluster-context.js +78 -0
  340. package/dist/spec/evolve/cluster-context.js.map +1 -0
  341. package/dist/spec/evolve/commit-spec-analyzer.d.ts +51 -0
  342. package/dist/spec/evolve/commit-spec-analyzer.d.ts.map +1 -0
  343. package/dist/spec/evolve/commit-spec-analyzer.js +88 -0
  344. package/dist/spec/evolve/commit-spec-analyzer.js.map +1 -0
  345. package/dist/spec/evolve/commit-spec-persister.d.ts +53 -0
  346. package/dist/spec/evolve/commit-spec-persister.d.ts.map +1 -0
  347. package/dist/spec/evolve/commit-spec-persister.js +93 -0
  348. package/dist/spec/evolve/commit-spec-persister.js.map +1 -0
  349. package/dist/spec/evolve/impact-locator.d.ts +23 -7
  350. package/dist/spec/evolve/impact-locator.d.ts.map +1 -1
  351. package/dist/spec/evolve/impact-locator.js +58 -14
  352. package/dist/spec/evolve/impact-locator.js.map +1 -1
  353. package/dist/spec/evolve/pipeline.d.ts +62 -25
  354. package/dist/spec/evolve/pipeline.d.ts.map +1 -1
  355. package/dist/spec/evolve/pipeline.js +436 -457
  356. package/dist/spec/evolve/pipeline.js.map +1 -1
  357. package/dist/spec/evolve/spec-rewriter.d.ts +13 -13
  358. package/dist/spec/evolve/spec-rewriter.d.ts.map +1 -1
  359. package/dist/spec/evolve/spec-rewriter.js +45 -45
  360. package/dist/spec/evolve/spec-rewriter.js.map +1 -1
  361. package/dist/spec/git/commits.d.ts +85 -0
  362. package/dist/spec/git/commits.d.ts.map +1 -0
  363. package/dist/spec/git/commits.js +218 -0
  364. package/dist/spec/git/commits.js.map +1 -0
  365. package/dist/spec/git/exec.d.ts +13 -0
  366. package/dist/spec/git/exec.d.ts.map +1 -0
  367. package/dist/spec/git/exec.js +19 -0
  368. package/dist/spec/git/exec.js.map +1 -0
  369. package/dist/spec/git/index.d.ts +9 -0
  370. package/dist/spec/git/index.d.ts.map +1 -0
  371. package/dist/spec/git/index.js +22 -0
  372. package/dist/spec/git/index.js.map +1 -0
  373. package/dist/spec/git-utils.d.ts +8 -0
  374. package/dist/spec/git-utils.d.ts.map +1 -0
  375. package/dist/spec/git-utils.js +14 -0
  376. package/dist/spec/git-utils.js.map +1 -0
  377. package/dist/spec/graph/index.d.ts +8 -0
  378. package/dist/spec/graph/index.d.ts.map +1 -0
  379. package/dist/spec/graph/index.js +17 -0
  380. package/dist/spec/graph/index.js.map +1 -0
  381. package/dist/spec/graph/queries.d.ts +6 -35
  382. package/dist/spec/graph/queries.d.ts.map +1 -1
  383. package/dist/spec/graph/queries.js +71 -248
  384. package/dist/spec/graph/queries.js.map +1 -1
  385. package/dist/spec/llm/agent-client.d.ts +59 -0
  386. package/dist/spec/llm/agent-client.d.ts.map +1 -0
  387. package/dist/spec/llm/agent-client.js +213 -0
  388. package/dist/spec/llm/agent-client.js.map +1 -0
  389. package/dist/spec/llm/agents/claude-code.d.ts +32 -0
  390. package/dist/spec/llm/agents/claude-code.d.ts.map +1 -0
  391. package/dist/spec/llm/agents/claude-code.js +125 -0
  392. package/dist/spec/llm/agents/claude-code.js.map +1 -0
  393. package/dist/spec/llm/agents/codex.d.ts +32 -0
  394. package/dist/spec/llm/agents/codex.d.ts.map +1 -0
  395. package/dist/spec/llm/agents/codex.js +145 -0
  396. package/dist/spec/llm/agents/codex.js.map +1 -0
  397. package/dist/spec/llm/agents/detect-utils.d.ts +28 -0
  398. package/dist/spec/llm/agents/detect-utils.d.ts.map +1 -0
  399. package/dist/spec/llm/agents/detect-utils.js +91 -0
  400. package/dist/spec/llm/agents/detect-utils.js.map +1 -0
  401. package/dist/spec/llm/agents/deveco-code.d.ts +33 -0
  402. package/dist/spec/llm/agents/deveco-code.d.ts.map +1 -0
  403. package/dist/spec/llm/agents/deveco-code.js +165 -0
  404. package/dist/spec/llm/agents/deveco-code.js.map +1 -0
  405. package/dist/spec/llm/agents/index.d.ts +31 -0
  406. package/dist/spec/llm/agents/index.d.ts.map +1 -0
  407. package/dist/spec/llm/agents/index.js +65 -0
  408. package/dist/spec/llm/agents/index.js.map +1 -0
  409. package/dist/spec/llm/agents/types.d.ts +76 -0
  410. package/dist/spec/llm/agents/types.d.ts.map +1 -0
  411. package/dist/spec/llm/agents/types.js +15 -0
  412. package/dist/spec/llm/agents/types.js.map +1 -0
  413. package/dist/spec/llm/client.d.ts +31 -11
  414. package/dist/spec/llm/client.d.ts.map +1 -1
  415. package/dist/spec/llm/client.js +143 -81
  416. package/dist/spec/llm/client.js.map +1 -1
  417. package/dist/spec/llm/factory.d.ts +41 -0
  418. package/dist/spec/llm/factory.d.ts.map +1 -0
  419. package/dist/spec/llm/factory.js +80 -0
  420. package/dist/spec/llm/factory.js.map +1 -0
  421. package/dist/spec/llm/prompts.d.ts +24 -8
  422. package/dist/spec/llm/prompts.d.ts.map +1 -1
  423. package/dist/spec/llm/prompts.js +100 -50
  424. package/dist/spec/llm/prompts.js.map +1 -1
  425. package/dist/spec/llm/retry.d.ts +53 -0
  426. package/dist/spec/llm/retry.d.ts.map +1 -0
  427. package/dist/spec/llm/retry.js +153 -0
  428. package/dist/spec/llm/retry.js.map +1 -0
  429. package/dist/spec/mine/clusterer.d.ts +63 -0
  430. package/dist/spec/mine/clusterer.d.ts.map +1 -0
  431. package/dist/spec/mine/clusterer.js +904 -0
  432. package/dist/spec/mine/clusterer.js.map +1 -0
  433. package/dist/spec/mine/clustering/features.d.ts +38 -0
  434. package/dist/spec/mine/clustering/features.d.ts.map +1 -0
  435. package/dist/spec/mine/clustering/features.js +108 -0
  436. package/dist/spec/mine/clustering/features.js.map +1 -0
  437. package/dist/spec/mine/clustering/index.d.ts +62 -0
  438. package/dist/spec/mine/clustering/index.d.ts.map +1 -0
  439. package/dist/spec/mine/clustering/index.js +259 -0
  440. package/dist/spec/mine/clustering/index.js.map +1 -0
  441. package/dist/spec/mine/clustering/leiden.d.ts +61 -0
  442. package/dist/spec/mine/clustering/leiden.d.ts.map +1 -0
  443. package/dist/spec/mine/clustering/leiden.js +489 -0
  444. package/dist/spec/mine/clustering/leiden.js.map +1 -0
  445. package/dist/spec/mine/clustering/text-similarity.d.ts +22 -0
  446. package/dist/spec/mine/clustering/text-similarity.d.ts.map +1 -0
  447. package/dist/spec/mine/clustering/text-similarity.js +98 -0
  448. package/dist/spec/mine/clustering/text-similarity.js.map +1 -0
  449. package/dist/spec/mine/generator.d.ts +54 -0
  450. package/dist/spec/mine/generator.d.ts.map +1 -0
  451. package/dist/spec/mine/generator.js +267 -0
  452. package/dist/spec/mine/generator.js.map +1 -0
  453. package/dist/spec/mine/persist.d.ts +37 -0
  454. package/dist/spec/mine/persist.d.ts.map +1 -0
  455. package/dist/spec/mine/persist.js +170 -0
  456. package/dist/spec/mine/persist.js.map +1 -0
  457. package/dist/spec/mine/pipeline.d.ts +41 -0
  458. package/dist/spec/mine/pipeline.d.ts.map +1 -0
  459. package/dist/spec/mine/pipeline.js +236 -0
  460. package/dist/spec/mine/pipeline.js.map +1 -0
  461. package/dist/spec/mine/progress-handler.d.ts +22 -0
  462. package/dist/spec/mine/progress-handler.d.ts.map +1 -0
  463. package/dist/spec/mine/progress-handler.js +108 -0
  464. package/dist/spec/mine/progress-handler.js.map +1 -0
  465. package/dist/spec/mine/progress.d.ts +23 -0
  466. package/dist/spec/mine/progress.d.ts.map +1 -0
  467. package/dist/spec/mine/progress.js +12 -0
  468. package/dist/spec/mine/progress.js.map +1 -0
  469. package/dist/spec/mine/scanner.d.ts +59 -0
  470. package/dist/spec/mine/scanner.d.ts.map +1 -0
  471. package/dist/spec/mine/scanner.js +383 -0
  472. package/dist/spec/mine/scanner.js.map +1 -0
  473. package/dist/spec/types.d.ts +32 -0
  474. package/dist/spec/types.d.ts.map +1 -1
  475. package/dist/spec/ui/index.d.ts +9 -0
  476. package/dist/spec/ui/index.d.ts.map +1 -0
  477. package/dist/spec/ui/index.js +16 -0
  478. package/dist/spec/ui/index.js.map +1 -0
  479. package/dist/spec/ui/progress-handler.d.ts +33 -0
  480. package/dist/spec/ui/progress-handler.d.ts.map +1 -0
  481. package/dist/spec/ui/progress-handler.js +132 -0
  482. package/dist/spec/ui/progress-handler.js.map +1 -0
  483. package/dist/spec/ui/progress.d.ts +24 -0
  484. package/dist/spec/ui/progress.d.ts.map +1 -0
  485. package/dist/spec/ui/progress.js +13 -0
  486. package/dist/spec/ui/progress.js.map +1 -0
  487. package/dist/spec/utils/fs.d.ts +45 -0
  488. package/dist/spec/utils/fs.d.ts.map +1 -0
  489. package/dist/spec/utils/fs.js +163 -0
  490. package/dist/spec/utils/fs.js.map +1 -0
  491. package/dist/spec/utils/index.d.ts +12 -0
  492. package/dist/spec/utils/index.d.ts.map +1 -0
  493. package/dist/spec/utils/index.js +26 -0
  494. package/dist/spec/utils/index.js.map +1 -0
  495. package/dist/spec/utils/meta.d.ts +32 -0
  496. package/dist/spec/utils/meta.d.ts.map +1 -0
  497. package/dist/spec/utils/meta.js +122 -0
  498. package/dist/spec/utils/meta.js.map +1 -0
  499. package/dist/spec/utils/truncate.d.ts +86 -0
  500. package/dist/spec/utils/truncate.d.ts.map +1 -0
  501. package/dist/spec/utils/truncate.js +172 -0
  502. package/dist/spec/utils/truncate.js.map +1 -0
  503. package/dist/spec/utils.d.ts +4 -16
  504. package/dist/spec/utils.d.ts.map +1 -1
  505. package/dist/spec/utils.js +6 -58
  506. package/dist/spec/utils.js.map +1 -1
  507. package/dist/sync/git-hooks.d.ts.map +1 -1
  508. package/dist/sync/git-hooks.js +2 -0
  509. package/dist/sync/git-hooks.js.map +1 -1
  510. package/dist/sync/watcher.d.ts +35 -6
  511. package/dist/sync/watcher.d.ts.map +1 -1
  512. package/dist/sync/watcher.js +127 -17
  513. package/dist/sync/watcher.js.map +1 -1
  514. package/dist/sync/worktree.d.ts.map +1 -1
  515. package/dist/sync/worktree.js +5 -0
  516. package/dist/sync/worktree.js.map +1 -1
  517. package/dist/telemetry/index.js +3 -3
  518. package/dist/telemetry/index.js.map +1 -1
  519. package/dist/types.d.ts +22 -1
  520. package/dist/types.d.ts.map +1 -1
  521. package/dist/types.js +10 -0
  522. package/dist/types.js.map +1 -1
  523. package/dist/upgrade/index.d.ts +32 -0
  524. package/dist/upgrade/index.d.ts.map +1 -1
  525. package/dist/upgrade/index.js +162 -14
  526. package/dist/upgrade/index.js.map +1 -1
  527. package/dist/upgrade/remove-binary.d.ts +87 -0
  528. package/dist/upgrade/remove-binary.d.ts.map +1 -0
  529. package/dist/upgrade/remove-binary.js +289 -0
  530. package/dist/upgrade/remove-binary.js.map +1 -0
  531. package/dist/upgrade/update-check.d.ts +92 -0
  532. package/dist/upgrade/update-check.d.ts.map +1 -0
  533. package/dist/upgrade/update-check.js +258 -0
  534. package/dist/upgrade/update-check.js.map +1 -0
  535. package/package.json +6 -2
  536. package/scripts/agent-eval/run-all.sh +6 -0
  537. package/scripts/build-bundle.sh +5 -0
  538. package/scripts/npm-shim.js +8 -1
  539. package/scripts/exp_boundary_eval/__pycache__/_utils.cpython-310.pyc +0 -0
  540. package/scripts/exp_boundary_eval/__pycache__/analyze.cpython-310.pyc +0 -0
  541. package/scripts/exp_boundary_eval/__pycache__/deveco_arm.cpython-310.pyc +0 -0
  542. package/scripts/exp_boundary_eval/__pycache__/run_one.cpython-310.pyc +0 -0
  543. package/scripts/exp_boundary_eval/__pycache__/run_session.cpython-310.pyc +0 -0
  544. package/scripts/exp_boundary_eval/__pycache__/setup.cpython-310.pyc +0 -0
  545. package/scripts/exp_boundary_eval/data/agents.json +0 -109
  546. package/scripts/exp_boundary_eval/data/experiments.json +0 -140
  547. package/scripts/qa_eval/README.md +0 -407
  548. package/scripts/qa_eval/_test_deveco_probe.py +0 -41
  549. package/scripts/qa_eval/agent_runner.py +0 -526
  550. package/scripts/qa_eval/data/.gitignore +0 -4
  551. package/scripts/qa_eval/data/test-set.jsonl +0 -2
  552. package/scripts/qa_eval/eval_metrics.py +0 -274
  553. package/scripts/qa_eval/external_agent.py +0 -976
  554. package/scripts/qa_eval/llm_config.py +0 -92
  555. package/scripts/qa_eval/memory_monitor.py +0 -132
  556. package/scripts/qa_eval/my_answer_accuracy.py +0 -187
  557. package/scripts/qa_eval/requirements.txt +0 -2
  558. package/scripts/qa_eval/run_pipeline.py +0 -804
  559. package/scripts/qa_eval/stats_efficiency.py +0 -279
  560. package/scripts/qa_eval/stats_scores.py +0 -207
@@ -1,804 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- QA Eval A/B 一条龙:Agent 跑题 → Judge 打分 → 完整对比报告。
4
-
5
- Usage:
6
- export DASHSCOPE_API_KEY=sk-...
7
- # 或智谱: export ZHIPU_API_KEY='id.secret'
8
- python scripts/qa_eval/run_pipeline.py ab -r /path/to/your/repo
9
- python scripts/qa_eval/run_pipeline.py ab -r /path/to/your/repo --provider zhipu
10
-
11
- # 只重打报告、不重跑 Agent/Judge(无需 --repo):
12
- python scripts/qa_eval/run_pipeline.py ab --no-agent --no-judge
13
- """
14
-
15
- from __future__ import annotations
16
-
17
- import argparse
18
- import io
19
- import json
20
- import os
21
- import re
22
- import shutil
23
- import statistics
24
- import subprocess
25
- import sys
26
- from collections import defaultdict
27
- from contextlib import redirect_stdout
28
- from pathlib import Path
29
-
30
- _SCRIPT_DIR = Path(__file__).resolve().parent
31
- DATA_DIR = _SCRIPT_DIR / "data"
32
- LOG_DIR = _SCRIPT_DIR / "log"
33
- DEFAULT_REPORT = DATA_DIR / "report-builtin.txt"
34
- DEFAULT_DATASET = DATA_DIR / "test-set.jsonl"
35
- DEFAULT_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
36
- DEFAULT_MODEL = "qwen3-235b-a22b-instruct-2507"
37
-
38
- if str(_SCRIPT_DIR) not in sys.path:
39
- sys.path.insert(0, str(_SCRIPT_DIR))
40
-
41
- from agent_runner import run_agent_dataset # noqa: E402
42
- from external_agent import HOST_CLAUDE, HOST_DEVECO, SUPPORTED_HOSTS, run_external_dataset, verify_claude_login # noqa: E402
43
- from llm_config import PROVIDER_DASHSCOPE, PROVIDER_ZHIPU, provider_help, resolve_llm_config # noqa: E402
44
- from my_answer_accuracy import extract_json_blocks_answerbyCOT, remove_tool_calls # noqa: E402
45
- from stats_efficiency import parse_agent_log, summarize_jsonl_usage, summarize_tasks # noqa: E402
46
- from stats_scores import compute_stats_from_rows, print_statistics # noqa: E402
47
-
48
- AGENT_HOST_BUILTIN = "builtin"
49
- ALL_AGENT_HOSTS = (AGENT_HOST_BUILTIN, HOST_CLAUDE, HOST_DEVECO)
50
-
51
- # 各宿主产出文件后缀 → report-builtin.txt / report-claude.txt / report-deveco.txt
52
- HOST_FILE_SUFFIX: dict[str, str] = {
53
- AGENT_HOST_BUILTIN: "builtin",
54
- HOST_CLAUDE: "claude",
55
- HOST_DEVECO: "deveco",
56
- }
57
-
58
-
59
- def require_repo_arg(repo: str | None, *, no_agent: bool) -> Path | None:
60
- """Return resolved repo path; required unless --no-agent (report-only)."""
61
- if no_agent:
62
- return Path(repo).expanduser().resolve() if repo else None
63
- if not repo:
64
- print("错误: 请指定被测仓库路径 --repo / -r(跑 Agent 时必填)")
65
- return None
66
- path = Path(repo).expanduser().resolve()
67
- if not path.is_dir():
68
- print(f"错误: 仓库不存在: {path}")
69
- return None
70
- return path
71
-
72
-
73
- def host_tag(agent_host: str) -> str:
74
- suffix = HOST_FILE_SUFFIX.get(agent_host, agent_host.replace("-code", ""))
75
- return f"-{suffix}"
76
-
77
-
78
- def clear_log_dir(log_dir: Path) -> tuple[int, list[str]]:
79
- """Remove files/subdirs under qa_eval log/ before a fresh run.
80
-
81
- Skips paths locked by another process (common on Windows when a file is open
82
- in the editor) instead of aborting the pipeline.
83
- """
84
- log_dir.mkdir(parents=True, exist_ok=True)
85
- removed = 0
86
- skipped: list[str] = []
87
- for child in sorted(log_dir.iterdir(), key=lambda p: (p.is_dir(), p.name.lower())):
88
- try:
89
- if child.is_file():
90
- child.unlink()
91
- elif child.is_dir():
92
- shutil.rmtree(child)
93
- else:
94
- continue
95
- removed += 1
96
- except OSError as e:
97
- skipped.append(f"{child.name} ({e})")
98
- return removed, skipped
99
-
100
-
101
- def paths_for_host(agent_host: str, *, log_dir: Path = LOG_DIR, data_dir: Path = DATA_DIR) -> dict[str, Path]:
102
- tag = host_tag(agent_host)
103
- log_dir.mkdir(parents=True, exist_ok=True)
104
- return {
105
- "with_jsonl": log_dir / f"result-with{tag}.jsonl",
106
- "without_jsonl": log_dir / f"result-without{tag}.jsonl",
107
- "with_scored": log_dir / f"result-with{tag}-scored.jsonl",
108
- "without_scored": log_dir / f"result-without{tag}-scored.jsonl",
109
- "with_log": log_dir / f"agent-with{tag}.log",
110
- "without_log": log_dir / f"agent-without{tag}.log",
111
- "report": data_dir / f"report{tag}.txt",
112
- }
113
-
114
-
115
- def load_jsonl(path: Path) -> list[dict]:
116
- rows: list[dict] = []
117
- with path.open("r", encoding="utf-8") as f:
118
- for line in f:
119
- line = line.strip()
120
- if line:
121
- rows.append(json.loads(line))
122
- return rows
123
-
124
-
125
- def index_by_id(rows: list[dict]) -> dict[str, dict]:
126
- return {str(r.get("id", i)): r for i, r in enumerate(rows)}
127
-
128
-
129
- def fmt_num(value: float | None, *, digits: int = 2) -> str:
130
- if value is None:
131
- return "N/A"
132
- return f"{value:.{digits}f}"
133
-
134
-
135
- def fmt_delta(a: float | None, b: float | None, *, digits: int = 2) -> str:
136
- if a is None or b is None:
137
- return "N/A"
138
- sign = "+" if a - b >= 0 else ""
139
- return f"{sign}{a - b:.{digits}f}"
140
-
141
-
142
- def clip(text: str, n: int = 56) -> str:
143
- text = " ".join(text.split())
144
- return text if len(text) <= n else text[: n - 1] + "…"
145
-
146
-
147
- def clean_answer(raw: str) -> str:
148
- return remove_tool_calls(extract_json_blocks_answerbyCOT(str(raw or "")))
149
-
150
-
151
- def tool_chain_summary(raw: str, *, used_homegraph: bool | None = None) -> str:
152
- tools = re.findall(r"---\n([^\n]+)\n", str(raw or ""))
153
- chain = " → ".join(tools) if tools else "-"
154
- if used_homegraph is True:
155
- return f"{chain} [homegraph]"
156
- if used_homegraph is False:
157
- return f"{chain} [无homegraph]"
158
- return chain
159
-
160
-
161
- def print_trajectory_section(rows_with: list[dict], rows_without: list[dict]) -> None:
162
- rows = [( "with", r) for r in rows_with] + [("without", r) for r in rows_without]
163
- if not any(r.get("deveco_session_id") or r.get("agent_trace_file") for _, r in rows):
164
- return
165
- print("\n" + "=" * 120)
166
- print("【Agent 轨迹 / DevEco Session】")
167
- print("跑完后查看完整轨迹:")
168
- print(" 1) JSON 文件:scripts/qa_eval/log/traces/<with|without>-deveco/<ID>-ses_*.json")
169
- print(" 2) CLI:deveco export <session_id> 或 deveco session list 找标题 qa-eval-*")
170
- print("-" * 120)
171
- print(f"{'ID':<6}{'臂':<8}{'HG':<4}{'状态':<8}{'工具链':<28}{'session_id':<28}{'轨迹文件'}")
172
- print("-" * 120)
173
- for arm, r in rows:
174
- rid = str(r.get("id", ""))
175
- status = str(r.get("agent_status", ""))[:7]
176
- hg = "Y" if r.get("agent_used_homegraph") else ("N" if arm == "with" else "-")
177
- chain = clip(
178
- tool_chain_summary(
179
- str(r.get("output_answer", "")),
180
- used_homegraph=r.get("agent_used_homegraph") if arm == "with" else None,
181
- ),
182
- 26,
183
- )
184
- sid = str(r.get("deveco_session_id") or "-")
185
- trace = str(r.get("agent_trace_file") or "-")
186
- print(f"{rid:<6}{arm:<8}{hg:<4}{status:<8}{chain:<28}{sid:<28}{trace}")
187
- print("=" * 120)
188
-
189
-
190
- def row_tokens(row: dict) -> int | None:
191
- usage = row.get("agent_usage") or {}
192
- total = usage.get("total_tokens")
193
- return int(total) if isinstance(total, (int, float)) else None
194
-
195
-
196
- def resolve_api_key() -> str | None:
197
- try:
198
- return resolve_llm_config(provider=os.environ.get("QA_EVAL_PROVIDER")).api_key
199
- except RuntimeError:
200
- return None
201
-
202
-
203
- def run_judge(agent_jsonl: Path, scored_jsonl: Path, *, workers: int, llm) -> int:
204
- if not agent_jsonl.is_file():
205
- print(f"错误: Agent 产出不存在,无法 Judge: {agent_jsonl}")
206
- return 1
207
- n = sum(1 for line in agent_jsonl.open(encoding="utf-8") if line.strip())
208
- print(f"\n>>> Judge ({llm.provider}):{agent_jsonl.name},共 {n} 条", flush=True)
209
- cmd = [
210
- sys.executable,
211
- str(_SCRIPT_DIR / "eval_metrics.py"),
212
- "-i",
213
- str(agent_jsonl),
214
- "-o",
215
- str(scored_jsonl),
216
- "-w",
217
- str(workers),
218
- "-m",
219
- llm.model,
220
- "--base-url",
221
- llm.base_url,
222
- "--provider",
223
- llm.provider,
224
- ]
225
- print(f"\n>>> {' '.join(cmd)}\n")
226
- return subprocess.call(cmd)
227
-
228
-
229
- def run_judge_if_needed(agent_jsonl: Path, scored_jsonl: Path, *, workers: int, llm) -> int:
230
- return run_judge(agent_jsonl, scored_jsonl, workers=workers, llm=llm)
231
-
232
-
233
- def print_category_table(rows_with: list[dict], rows_without: list[dict]) -> None:
234
- by_cat: dict[str, list[tuple[float, float]]] = defaultdict(list)
235
- wo = index_by_id(rows_without)
236
- for r in rows_with:
237
- rid = str(r.get("id"))
238
- if rid not in wo:
239
- continue
240
- if r.get("evaluation_status") != "success" or wo[rid].get("evaluation_status") != "success":
241
- continue
242
- cat = str(r.get("category_l1") or "未分类")
243
- by_cat[cat].append((float(r["answer_accuracy_score"]), float(wo[rid]["answer_accuracy_score"])))
244
-
245
- print("\n" + "=" * 88)
246
- print("按类别准确率")
247
- print("=" * 88)
248
- print(f"{'类别':<12}{'题数':>6}{'with均分':>12}{'without均分':>14}{'Δ':>10}")
249
- print("-" * 88)
250
- for cat in sorted(by_cat):
251
- pairs = by_cat[cat]
252
- w_mean = statistics.mean(p[0] for p in pairs)
253
- wo_mean = statistics.mean(p[1] for p in pairs)
254
- print(f"{cat:<12}{len(pairs):>6}{w_mean:>12.4f}{wo_mean:>14.4f}{w_mean - wo_mean:>+10.4f}")
255
- print("=" * 88)
256
-
257
-
258
- def print_per_item_table(rows_with: list[dict], rows_without: list[dict]) -> None:
259
- wo = index_by_id(rows_without)
260
- wins = ties = losses = 0
261
-
262
- print("\n" + "=" * 120)
263
- print("逐题对比(query → with / without 得分与答案摘要)")
264
- print("=" * 120)
265
- print(
266
- f"{'ID':<5}{'类':<6}{'with':>6}{'wo':>6}{'Δ':>7} {'问题':<28} {'with答案':<32} {'without答案'}"
267
- )
268
- print("-" * 120)
269
-
270
- for r in rows_with:
271
- rid = str(r.get("id", ""))
272
- w = wo.get(rid, {})
273
- sw = float(r["answer_accuracy_score"]) if r.get("evaluation_status") == "success" else None
274
- swo = float(w["answer_accuracy_score"]) if w.get("evaluation_status") == "success" else None
275
- if sw is not None and swo is not None:
276
- if sw > swo:
277
- wins += 1
278
- elif sw < swo:
279
- losses += 1
280
- else:
281
- ties += 1
282
- cat = str(r.get("category_l1") or "")[:4]
283
- q = clip(str(r.get("query", "")), 26)
284
- aw = clip(clean_answer(str(r.get("output_answer", ""))), 30)
285
- awo = clip(clean_answer(str(w.get("output_answer", ""))), 30)
286
- print(
287
- f"{rid:<5}{cat:<6}"
288
- f"{fmt_num(sw, digits=2):>6}"
289
- f"{fmt_num(swo, digits=2):>6}"
290
- f"{fmt_delta(sw, swo, digits=2):>7} "
291
- f"{q:<28} {aw:<32} {awo}"
292
- )
293
-
294
- print("-" * 120)
295
- print(f"with 更高: {wins} | 持平: {ties} | without 更高: {losses}")
296
- print("=" * 120)
297
-
298
-
299
- def print_efficiency_section(
300
- label: str, log_path: Path | None, rows: list[dict], *, print_report: bool = True
301
- ) -> dict:
302
- if print_report:
303
- print(f"\n{'=' * 88}")
304
- print(f"{label} — 效率明细")
305
- print("=" * 88)
306
-
307
- if log_path and log_path.is_file():
308
- tasks = parse_agent_log(log_path)
309
- if tasks:
310
- summary = summarize_tasks(tasks, print_report=print_report)
311
- summary["source"] = f"日志 {log_path}"
312
- return summary
313
-
314
- if print_report:
315
- print(f"日志: {log_path} (不存在或未解析到 Evaluate 段)")
316
- print("\n从 JSONL agent_usage 逐题 Token:")
317
- print(f"{'ID':<6}{'Token':>10}{'agent_backend':>20}")
318
- print("-" * 40)
319
- tokens: list[int] = []
320
- for r in rows:
321
- tok = row_tokens(r)
322
- if tok is not None:
323
- tokens.append(tok)
324
- if print_report:
325
- print(
326
- f"{str(r.get('id', '')):<6}"
327
- f"{tok if tok is not None else 'N/A':>10}"
328
- f"{str(r.get('agent_backend', '')):>20}"
329
- )
330
- summary = summarize_jsonl_usage(rows)
331
- summary["source"] = "JSONL agent_usage"
332
- if print_report:
333
- print("-" * 40)
334
- print(f"平均 Token: {summary['avg_tokens']:.0f}" if summary.get("avg_tokens") else "平均 Token: N/A")
335
- print(f"合计 Token: {summary.get('total_tokens', 0)}")
336
- print("=" * 88)
337
- return summary
338
-
339
-
340
- def print_full_ab_report(
341
- *,
342
- with_scored: Path,
343
- without_scored: Path,
344
- with_log: Path | None,
345
- without_log: Path | None,
346
- rows_with: list[dict],
347
- rows_without: list[dict],
348
- ) -> None:
349
- stats_with = compute_stats_from_rows(rows_with)
350
- stats_without = compute_stats_from_rows(rows_without)
351
-
352
- print("\n")
353
- print("#" * 88)
354
- print("#" + " " * 30 + "A/B 完整评测报告" + " " * 30 + "#")
355
- print("#" * 88)
356
-
357
- print("\n【输入文件】")
358
- print(f" with scored : {with_scored}")
359
- print(f" without scored: {without_scored}")
360
- print(f" with log : {with_log} {'(存在)' if with_log and with_log.is_file() else '(无)'}")
361
- print(f" without log : {without_log} {'(存在)' if without_log and without_log.is_file() else '(无)'}")
362
-
363
- eff_with = print_efficiency_section("WITH homegraph", with_log, rows_with)
364
- eff_without = print_efficiency_section("WITHOUT homegraph", without_log, rows_without)
365
-
366
- print_statistics(stats_with, with_scored, title="【WITH homegraph】准确率统计")
367
- print_statistics(stats_without, without_scored, title="【WITHOUT homegraph】准确率统计")
368
-
369
- print_category_table(rows_with, rows_without)
370
- print_per_item_table(rows_with, rows_without)
371
- print_trajectory_section(rows_with, rows_without)
372
-
373
- w = 22
374
- print("\n" + "=" * 88)
375
- print("【A/B 汇总表】")
376
- print("=" * 88)
377
- print(f"{'指标':<24}{'with':>{w}}{'without':>{w}}{'Δ (with−without)':>{w}}")
378
- print("-" * 88)
379
-
380
- def sm(s: dict | None) -> float | None:
381
- return float(s["mean"]) if s and s.get("valid_scores") else None
382
-
383
- def sd(s: dict | None) -> float | None:
384
- return float(s["median"]) if s and s.get("valid_scores") else None
385
-
386
- print(
387
- f"{'准确率 均值':<24}"
388
- f"{fmt_num(sm(stats_with), digits=4):>{w}}"
389
- f"{fmt_num(sm(stats_without), digits=4):>{w}}"
390
- f"{fmt_delta(sm(stats_with), sm(stats_without), digits=4):>{w}}"
391
- )
392
- print(
393
- f"{'准确率 中位数':<24}"
394
- f"{fmt_num(sd(stats_with), digits=4):>{w}}"
395
- f"{fmt_num(sd(stats_without), digits=4):>{w}}"
396
- f"{fmt_delta(sd(stats_with), sd(stats_without), digits=4):>{w}}"
397
- )
398
- jw = f"{stats_with['success_samples']}/{stats_with['total_samples']}"
399
- jo = f"{stats_without['success_samples']}/{stats_without['total_samples']}"
400
- print(
401
- f"{'Judge 成功/总数':<24}"
402
- f"{jw:>{w}}"
403
- f"{jo:>{w}}"
404
- f"{'—':>{w}}"
405
- )
406
- print("-" * 88)
407
- print(
408
- f"{'平均轮次':<24}"
409
- f"{fmt_num(eff_with.get('avg_turns')):>{w}}"
410
- f"{fmt_num(eff_without.get('avg_turns')):>{w}}"
411
- f"{fmt_delta(eff_with.get('avg_turns'), eff_without.get('avg_turns')):>{w}}"
412
- )
413
- print(
414
- f"{'平均耗时 (秒)':<24}"
415
- f"{fmt_num(eff_with.get('avg_duration_s')):>{w}}"
416
- f"{fmt_num(eff_without.get('avg_duration_s')):>{w}}"
417
- f"{fmt_delta(eff_with.get('avg_duration_s'), eff_without.get('avg_duration_s')):>{w}}"
418
- )
419
- tw = eff_with.get("avg_tokens")
420
- two = eff_without.get("avg_tokens")
421
- print(
422
- f"{'平均 Token (k)':<24}"
423
- f"{fmt_num(tw / 1000 if tw else None, digits=2):>{w}}"
424
- f"{fmt_num(two / 1000 if two else None, digits=2):>{w}}"
425
- f"{fmt_delta(tw / 1000 if tw else None, two / 1000 if two else None, digits=2):>{w}}"
426
- )
427
- print(
428
- f"{'平均首响应 (秒)':<24}"
429
- f"{fmt_num(eff_with.get('avg_first_token_s')):>{w}}"
430
- f"{fmt_num(eff_without.get('avg_first_token_s')):>{w}}"
431
- f"{fmt_delta(eff_with.get('avg_first_token_s'), eff_without.get('avg_first_token_s')):>{w}}"
432
- )
433
- print(
434
- f"{'平均峰值内存 (MB)':<24}"
435
- f"{fmt_num(eff_with.get('avg_peak_rss_mb')):>{w}}"
436
- f"{fmt_num(eff_without.get('avg_peak_rss_mb')):>{w}}"
437
- f"{fmt_delta(eff_with.get('avg_peak_rss_mb'), eff_without.get('avg_peak_rss_mb')):>{w}}"
438
- )
439
- print(
440
- f"{'最大峰值内存 (MB)':<24}"
441
- f"{fmt_num(eff_with.get('max_peak_rss_mb')):>{w}}"
442
- f"{fmt_num(eff_without.get('max_peak_rss_mb')):>{w}}"
443
- f"{fmt_delta(eff_with.get('max_peak_rss_mb'), eff_without.get('max_peak_rss_mb')):>{w}}"
444
- )
445
- print("-" * 88)
446
- print("效率数据来源:")
447
- print(f" with : {eff_with.get('source', '?')}")
448
- print(f" without : {eff_without.get('source', '?')}")
449
- print("=" * 88)
450
-
451
-
452
- def run_agent_stage(
453
- *,
454
- agent_host: str,
455
- repo: Path,
456
- dataset: list[dict],
457
- with_jsonl: Path,
458
- without_jsonl: Path,
459
- with_log: Path | None,
460
- without_log: Path | None,
461
- llm,
462
- hg_bin: str | None,
463
- max_turns: int,
464
- deveco_model: str | None = None,
465
- deveco_attach: str | None = None,
466
- ) -> None:
467
- if agent_host == HOST_CLAUDE:
468
- verify_claude_login()
469
- for arm, out, log in (
470
- ("with", with_jsonl, with_log),
471
- ("without", without_jsonl, without_log),
472
- ):
473
- label = "WITH homegraph" if arm == "with" else "WITHOUT (grep/read only)"
474
- print(f"\n>>> Agent [{agent_host}] [{label}] → {out}")
475
- if agent_host == AGENT_HOST_BUILTIN:
476
- run_agent_dataset(
477
- repo,
478
- dataset,
479
- arm=arm,
480
- output=out,
481
- log_file=log,
482
- api_key=llm.api_key,
483
- base_url=llm.base_url,
484
- model=llm.model,
485
- hg_bin=hg_bin,
486
- max_turns=max_turns,
487
- extra_body=llm.extra_body,
488
- )
489
- else:
490
- run_external_dataset(
491
- agent_host,
492
- repo,
493
- dataset,
494
- arm=arm,
495
- output=out,
496
- log_file=log,
497
- hg_bin=hg_bin or "",
498
- model=deveco_model if agent_host == HOST_DEVECO else None,
499
- deveco_attach=deveco_attach if agent_host == HOST_DEVECO else None,
500
- )
501
-
502
-
503
- def cmd_ab(args: argparse.Namespace) -> int:
504
- if args.agent_host == "all":
505
- return cmd_hosts(args)
506
-
507
- agent_host = args.agent_host
508
- paths = paths_for_host(agent_host)
509
- if args.with_scored:
510
- with_scored = Path(args.with_scored)
511
- else:
512
- with_scored = paths["with_scored"]
513
- if args.without_scored:
514
- without_scored = Path(args.without_scored)
515
- else:
516
- without_scored = paths["without_scored"]
517
- if args.with_jsonl:
518
- with_jsonl = Path(args.with_jsonl)
519
- else:
520
- with_jsonl = paths["with_jsonl"]
521
- if args.without_jsonl:
522
- without_jsonl = Path(args.without_jsonl)
523
- else:
524
- without_jsonl = paths["without_jsonl"]
525
- with_log = Path(args.with_log) if args.with_log else paths["with_log"]
526
- without_log = Path(args.without_log) if args.without_log else paths["without_log"]
527
- repo = require_repo_arg(getattr(args, "repo", None), no_agent=args.no_agent)
528
- if repo is None and not args.no_agent:
529
- return 1
530
- dataset_path = Path(args.dataset).expanduser().resolve()
531
-
532
- try:
533
- llm = resolve_llm_config(
534
- provider=getattr(args, "provider", None),
535
- model=getattr(args, "model", None),
536
- base_url=getattr(args, "base_url", None),
537
- )
538
- except RuntimeError as e:
539
- print(f"错误: {e}")
540
- return 1
541
-
542
- if not args.no_agent:
543
- if not dataset_path.is_file():
544
- print(f"错误: 测试集不存在: {dataset_path}")
545
- return 1
546
-
547
- dataset = load_jsonl(dataset_path)
548
- if not getattr(args, "keep_log", False):
549
- removed, skipped = clear_log_dir(LOG_DIR)
550
- print(f"已清空 log 目录: {LOG_DIR} ({removed} 项)", flush=True)
551
- if skipped:
552
- print("⚠ 以下项被占用,未删除(关闭占用进程后可手动删):", flush=True)
553
- for item in skipped:
554
- print(f" - {item}", flush=True)
555
- print("=" * 60)
556
- print(f"Stage 1 — Agent 跑题 ({len(dataset)} 条) host={agent_host}")
557
- print(f" LLM : {llm.provider}")
558
- print(f" 仓库 : {repo}")
559
- print(f" 测试集 : {dataset_path}")
560
- print(f" 报告 : {paths['report']}")
561
- print("=" * 60)
562
-
563
- assert repo is not None
564
- run_agent_stage(
565
- agent_host=agent_host,
566
- repo=repo,
567
- dataset=dataset,
568
- with_jsonl=with_jsonl,
569
- without_jsonl=without_jsonl,
570
- with_log=with_log,
571
- without_log=without_log,
572
- llm=llm,
573
- hg_bin=args.homegraph_bin,
574
- max_turns=args.max_turns,
575
- deveco_model=getattr(args, "deveco_model", None),
576
- deveco_attach=getattr(args, "deveco_attach", None),
577
- )
578
-
579
- if not args.no_judge:
580
- print("\n" + "=" * 60)
581
- print(f"Stage 2 — Judge 打分 ({llm.provider})")
582
- print("=" * 60)
583
- if run_judge(with_jsonl, with_scored, workers=args.workers, llm=llm) != 0:
584
- return 1
585
- if run_judge(without_jsonl, without_scored, workers=args.workers, llm=llm) != 0:
586
- return 1
587
-
588
- if not with_scored.is_file() or not without_scored.is_file():
589
- print("错误: 缺少 scored 结果。请去掉 --no-agent --no-judge 完整跑一遍,或提供 scored 文件。")
590
- return 1
591
-
592
- rows_with = load_jsonl(with_scored)
593
- rows_without = load_jsonl(without_scored)
594
-
595
- print("\n" + "=" * 60)
596
- print("Stage 3–4 — 效率统计 + A/B 对比报告")
597
- print("=" * 60)
598
-
599
- eff_with = print_efficiency_section("WITH homegraph", with_log, rows_with)
600
- eff_without = print_efficiency_section("WITHOUT homegraph", without_log, rows_without)
601
-
602
- report_path = Path(args.report).expanduser().resolve() if args.report else paths["report"]
603
- report_path.parent.mkdir(parents=True, exist_ok=True)
604
-
605
- buf = io.StringIO()
606
- with redirect_stdout(buf):
607
- print_full_ab_report(
608
- with_scored=with_scored,
609
- without_scored=without_scored,
610
- with_log=with_log,
611
- without_log=without_log,
612
- rows_with=rows_with,
613
- rows_without=rows_without,
614
- )
615
-
616
- report_path.write_text(buf.getvalue(), encoding="utf-8")
617
- print(f"\nA/B 完整报告已写入: {report_path}")
618
- return 0
619
-
620
-
621
- def cmd_score(args: argparse.Namespace) -> int:
622
- input_jsonl = Path(args.input)
623
- scored = Path(args.scored) if args.scored else input_jsonl.with_name(input_jsonl.stem + "-scored.jsonl")
624
- cmd = [
625
- sys.executable,
626
- str(_SCRIPT_DIR / "eval_metrics.py"),
627
- "-i",
628
- str(input_jsonl),
629
- "-o",
630
- str(scored),
631
- "-w",
632
- str(args.workers),
633
- ]
634
- if getattr(args, "provider", None):
635
- cmd.extend(["--provider", args.provider])
636
- if args.model:
637
- cmd.extend(["-m", args.model])
638
- rc = subprocess.call(cmd)
639
- if rc != 0:
640
- return rc
641
- rows = load_jsonl(scored)
642
- print_statistics(compute_stats_from_rows(rows), scored)
643
- if args.log:
644
- print_efficiency_section("单路", Path(args.log), rows)
645
- return 0
646
-
647
-
648
- def cmd_hosts(args: argparse.Namespace) -> int:
649
- """Run full A/B for each Agent host (builtin, claude-code, deveco-code)."""
650
- repo = require_repo_arg(getattr(args, "repo", None), no_agent=args.no_agent)
651
- if repo is None and not args.no_agent:
652
- return 1
653
-
654
- hosts_raw = getattr(args, "agent_hosts", None) or ",".join(ALL_AGENT_HOSTS)
655
- hosts = [h.strip() for h in hosts_raw.split(",") if h.strip()]
656
- unknown = [h for h in hosts if h not in ALL_AGENT_HOSTS]
657
- if unknown:
658
- print(f"错误: 未知 agent host: {unknown},可选: {', '.join(ALL_AGENT_HOSTS)}")
659
- return 1
660
-
661
- rc = 0
662
- for host in hosts:
663
- print("\n" + "#" * 88)
664
- print(f"# Agent host: {host}")
665
- print("#" * 88)
666
- host_args = argparse.Namespace(
667
- repo=args.repo,
668
- dataset=args.dataset,
669
- with_scored=None,
670
- without_scored=None,
671
- with_jsonl=None,
672
- without_jsonl=None,
673
- with_log=None,
674
- without_log=None,
675
- workers=args.workers,
676
- provider=getattr(args, "provider", None),
677
- model=args.model,
678
- base_url=args.base_url,
679
- homegraph_bin=args.homegraph_bin,
680
- max_turns=args.max_turns,
681
- no_agent=args.no_agent,
682
- no_judge=args.no_judge,
683
- keep_log=getattr(args, "keep_log", False),
684
- report=None,
685
- agent_host=host,
686
- deveco_model=getattr(args, "deveco_model", None),
687
- deveco_attach=getattr(args, "deveco_attach", None),
688
- )
689
- if cmd_ab(host_args) != 0:
690
- rc = 1
691
- if rc == 0:
692
- print("\n" + "=" * 60)
693
- print("全部宿主跑完,报告文件:")
694
- for host in hosts:
695
- p = paths_for_host(host)["report"]
696
- print(f" {host}: {p}")
697
- print("=" * 60)
698
- return rc
699
-
700
-
701
- def main() -> int:
702
- parser = argparse.ArgumentParser(description="QA Eval A/B — 完整打印全部对比结果")
703
- sub = parser.add_subparsers(dest="command", required=True)
704
-
705
- p_ab = sub.add_parser("ab", help="一条龙:Agent → Judge → 完整报告(默认会更新全部数据)")
706
- p_ab.add_argument(
707
- "--repo",
708
- "-r",
709
- default=None,
710
- help="被测仓库绝对路径(跑 Agent 时必填;仅 --no-agent 重打报告时可省略)",
711
- )
712
- p_ab.add_argument("--dataset", "-d", default=str(DEFAULT_DATASET))
713
- p_ab.add_argument(
714
- "--agent-host",
715
- default=AGENT_HOST_BUILTIN,
716
- choices=[*ALL_AGENT_HOSTS, "all"],
717
- help="Agent 宿主: builtin(Python+Qwen) | claude-code | deveco-code | all",
718
- )
719
- p_ab.add_argument("--with-scored", default=None)
720
- p_ab.add_argument("--without-scored", default=None)
721
- p_ab.add_argument("--with-jsonl", default=None)
722
- p_ab.add_argument("--without-jsonl", default=None)
723
- p_ab.add_argument("--with-log", default=None)
724
- p_ab.add_argument("--without-log", default=None)
725
- p_ab.add_argument("--workers", "-w", type=int, default=1)
726
- p_ab.add_argument(
727
- "--provider",
728
- choices=[PROVIDER_DASHSCOPE, PROVIDER_ZHIPU],
729
- default=None,
730
- help=provider_help(),
731
- )
732
- p_ab.add_argument("--model", "-m", default=None, help="LLM 模型(默认随 provider)")
733
- p_ab.add_argument("--base-url", default=None, help="OpenAI 兼容 API 端点(默认随 provider)")
734
- p_ab.add_argument("--homegraph-bin", default=None)
735
- p_ab.add_argument("--max-turns", type=int, default=8, help="Agent 最多工具轮次")
736
- p_ab.add_argument(
737
- "--deveco-model",
738
- default=None,
739
- help="DevEco Agent 模型(provider/model,如 zhipuai/glm-4.5-flash);默认用 DevEco 自身配置,不用 --model",
740
- )
741
- p_ab.add_argument(
742
- "--deveco-attach",
743
- default=os.environ.get("QA_EVAL_DEVECO_ATTACH"),
744
- help="已运行的 deveco serve 地址(如 http://127.0.0.1:4096),复用进程避免每题冷启动",
745
- )
746
- p_ab.add_argument("--no-agent", action="store_true", help="不跑 Agent,沿用已有 JSONL")
747
- p_ab.add_argument("--no-judge", action="store_true", help="不跑 Judge,沿用已有 scored")
748
- p_ab.add_argument(
749
- "--keep-log",
750
- action="store_true",
751
- help="保留 scripts/qa_eval/log 下旧文件(默认每次跑 Agent 前清空)",
752
- )
753
- p_ab.add_argument(
754
- "--report",
755
- default=None,
756
- help="A/B 完整报告输出路径(默认 data/report-{host}.txt,如 report-deveco.txt)",
757
- )
758
- p_ab.set_defaults(func=cmd_ab)
759
-
760
- p_hosts = sub.add_parser("hosts", help="依次跑 builtin + claude-code + deveco-code 的 A/B")
761
- p_hosts.add_argument(
762
- "--repo",
763
- "-r",
764
- default=None,
765
- help="被测仓库绝对路径(跑 Agent 时必填;仅 --no-agent 重打报告时可省略)",
766
- )
767
- p_hosts.add_argument("--dataset", "-d", default=str(DEFAULT_DATASET))
768
- p_hosts.add_argument("--workers", "-w", type=int, default=1)
769
- p_hosts.add_argument("--provider", choices=[PROVIDER_DASHSCOPE, PROVIDER_ZHIPU], default=None)
770
- p_hosts.add_argument("--model", "-m", default=None)
771
- p_hosts.add_argument("--base-url", default=None)
772
- p_hosts.add_argument("--homegraph-bin", default=None)
773
- p_hosts.add_argument("--max-turns", type=int, default=8)
774
- p_hosts.add_argument("--deveco-model", default=None)
775
- p_hosts.add_argument(
776
- "--deveco-attach",
777
- default=os.environ.get("QA_EVAL_DEVECO_ATTACH"),
778
- help="deveco serve 地址,见 ab --deveco-attach",
779
- )
780
- p_hosts.add_argument("--no-agent", action="store_true")
781
- p_hosts.add_argument("--no-judge", action="store_true")
782
- p_hosts.add_argument("--keep-log", action="store_true")
783
- p_hosts.add_argument(
784
- "--agent-hosts",
785
- default=",".join(ALL_AGENT_HOSTS),
786
- help="逗号分隔: builtin,claude-code,deveco-code",
787
- )
788
- p_hosts.set_defaults(func=cmd_hosts)
789
-
790
- p_score = sub.add_parser("score", help="单路:Agent JSONL → Judge → 统计")
791
- p_score.add_argument("--input", "-i", required=True)
792
- p_score.add_argument("--scored", "-o", default=None)
793
- p_score.add_argument("--log", "-l", default=None)
794
- p_score.add_argument("--workers", "-w", type=int, default=1)
795
- p_score.add_argument("--provider", choices=[PROVIDER_DASHSCOPE, PROVIDER_ZHIPU], default=None)
796
- p_score.add_argument("--model", "-m", default=None)
797
- p_score.set_defaults(func=cmd_score)
798
-
799
- args = parser.parse_args()
800
- return args.func(args)
801
-
802
-
803
- if __name__ == "__main__":
804
- raise SystemExit(main())