@afaik-lab/weigh 0.0.0 → 0.6.1

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 (349) hide show
  1. package/.env.example +49 -0
  2. package/LICENSE +373 -0
  3. package/README.md +103 -1
  4. package/dist/agent.d.ts +83 -0
  5. package/dist/agent.d.ts.map +1 -0
  6. package/dist/agent.js +204 -0
  7. package/dist/agent.js.map +1 -0
  8. package/dist/ceilings.d.ts +32 -0
  9. package/dist/ceilings.d.ts.map +1 -0
  10. package/dist/ceilings.js +61 -0
  11. package/dist/ceilings.js.map +1 -0
  12. package/dist/cli.d.ts +3 -0
  13. package/dist/cli.d.ts.map +1 -0
  14. package/dist/cli.js +530 -0
  15. package/dist/cli.js.map +1 -0
  16. package/dist/config-cli.d.ts +15 -0
  17. package/dist/config-cli.d.ts.map +1 -0
  18. package/dist/config-cli.js +141 -0
  19. package/dist/config-cli.js.map +1 -0
  20. package/dist/config.d.ts +198 -0
  21. package/dist/config.d.ts.map +1 -0
  22. package/dist/config.js +373 -0
  23. package/dist/config.js.map +1 -0
  24. package/dist/context-cli.d.ts +35 -0
  25. package/dist/context-cli.d.ts.map +1 -0
  26. package/dist/context-cli.js +251 -0
  27. package/dist/context-cli.js.map +1 -0
  28. package/dist/context.d.ts +118 -0
  29. package/dist/context.d.ts.map +1 -0
  30. package/dist/context.js +159 -0
  31. package/dist/context.js.map +1 -0
  32. package/dist/corrections/correction-set.d.ts +67 -0
  33. package/dist/corrections/correction-set.d.ts.map +1 -0
  34. package/dist/corrections/correction-set.js +104 -0
  35. package/dist/corrections/correction-set.js.map +1 -0
  36. package/dist/corrections/correction.d.ts +74 -0
  37. package/dist/corrections/correction.d.ts.map +1 -0
  38. package/dist/corrections/correction.js +154 -0
  39. package/dist/corrections/correction.js.map +1 -0
  40. package/dist/corrections/follow-up.d.ts +69 -0
  41. package/dist/corrections/follow-up.d.ts.map +1 -0
  42. package/dist/corrections/follow-up.js +217 -0
  43. package/dist/corrections/follow-up.js.map +1 -0
  44. package/dist/corrections/index.d.ts +31 -0
  45. package/dist/corrections/index.d.ts.map +1 -0
  46. package/dist/corrections/index.js +31 -0
  47. package/dist/corrections/index.js.map +1 -0
  48. package/dist/corrections/ledger.d.ts +78 -0
  49. package/dist/corrections/ledger.d.ts.map +1 -0
  50. package/dist/corrections/ledger.js +117 -0
  51. package/dist/corrections/ledger.js.map +1 -0
  52. package/dist/corrections/promotion.d.ts +119 -0
  53. package/dist/corrections/promotion.d.ts.map +1 -0
  54. package/dist/corrections/promotion.js +221 -0
  55. package/dist/corrections/promotion.js.map +1 -0
  56. package/dist/corrections/schema.d.ts +125 -0
  57. package/dist/corrections/schema.d.ts.map +1 -0
  58. package/dist/corrections/schema.js +100 -0
  59. package/dist/corrections/schema.js.map +1 -0
  60. package/dist/corrections-cli.d.ts +28 -0
  61. package/dist/corrections-cli.d.ts.map +1 -0
  62. package/dist/corrections-cli.js +157 -0
  63. package/dist/corrections-cli.js.map +1 -0
  64. package/dist/diff.d.ts +105 -0
  65. package/dist/diff.d.ts.map +1 -0
  66. package/dist/diff.js +202 -0
  67. package/dist/diff.js.map +1 -0
  68. package/dist/doctor.d.ts +38 -0
  69. package/dist/doctor.d.ts.map +1 -0
  70. package/dist/doctor.js +197 -0
  71. package/dist/doctor.js.map +1 -0
  72. package/dist/events.d.ts +21 -0
  73. package/dist/events.d.ts.map +1 -0
  74. package/dist/events.js +5 -0
  75. package/dist/events.js.map +1 -0
  76. package/dist/findings.d.ts +510 -0
  77. package/dist/findings.d.ts.map +1 -0
  78. package/dist/findings.js +645 -0
  79. package/dist/findings.js.map +1 -0
  80. package/dist/follow-up-cli.d.ts +88 -0
  81. package/dist/follow-up-cli.d.ts.map +1 -0
  82. package/dist/follow-up-cli.js +208 -0
  83. package/dist/follow-up-cli.js.map +1 -0
  84. package/dist/harness.d.ts +64 -0
  85. package/dist/harness.d.ts.map +1 -0
  86. package/dist/harness.js +71 -0
  87. package/dist/harness.js.map +1 -0
  88. package/dist/help/command-help.d.ts +9 -0
  89. package/dist/help/command-help.d.ts.map +1 -0
  90. package/dist/help/command-help.js +21 -0
  91. package/dist/help/command-help.js.map +1 -0
  92. package/dist/help/commands/answer.d.ts +3 -0
  93. package/dist/help/commands/answer.d.ts.map +1 -0
  94. package/dist/help/commands/answer.js +39 -0
  95. package/dist/help/commands/answer.js.map +1 -0
  96. package/dist/help/commands/config.d.ts +3 -0
  97. package/dist/help/commands/config.d.ts.map +1 -0
  98. package/dist/help/commands/config.js +25 -0
  99. package/dist/help/commands/config.js.map +1 -0
  100. package/dist/help/commands/context.d.ts +3 -0
  101. package/dist/help/commands/context.d.ts.map +1 -0
  102. package/dist/help/commands/context.js +44 -0
  103. package/dist/help/commands/context.js.map +1 -0
  104. package/dist/help/commands/corrections.d.ts +3 -0
  105. package/dist/help/commands/corrections.d.ts.map +1 -0
  106. package/dist/help/commands/corrections.js +30 -0
  107. package/dist/help/commands/corrections.js.map +1 -0
  108. package/dist/help/commands/doctor.d.ts +3 -0
  109. package/dist/help/commands/doctor.d.ts.map +1 -0
  110. package/dist/help/commands/doctor.js +12 -0
  111. package/dist/help/commands/doctor.js.map +1 -0
  112. package/dist/help/commands/index.d.ts +4 -0
  113. package/dist/help/commands/index.d.ts.map +1 -0
  114. package/dist/help/commands/index.js +27 -0
  115. package/dist/help/commands/index.js.map +1 -0
  116. package/dist/help/commands/memory.d.ts +3 -0
  117. package/dist/help/commands/memory.d.ts.map +1 -0
  118. package/dist/help/commands/memory.js +33 -0
  119. package/dist/help/commands/memory.js.map +1 -0
  120. package/dist/help/commands/models.d.ts +3 -0
  121. package/dist/help/commands/models.d.ts.map +1 -0
  122. package/dist/help/commands/models.js +17 -0
  123. package/dist/help/commands/models.js.map +1 -0
  124. package/dist/help/commands/options.d.ts +4 -0
  125. package/dist/help/commands/options.d.ts.map +1 -0
  126. package/dist/help/commands/options.js +13 -0
  127. package/dist/help/commands/options.js.map +1 -0
  128. package/dist/help/commands/review.d.ts +3 -0
  129. package/dist/help/commands/review.d.ts.map +1 -0
  130. package/dist/help/commands/review.js +50 -0
  131. package/dist/help/commands/review.js.map +1 -0
  132. package/dist/help/commands/sessions.d.ts +3 -0
  133. package/dist/help/commands/sessions.d.ts.map +1 -0
  134. package/dist/help/commands/sessions.js +23 -0
  135. package/dist/help/commands/sessions.js.map +1 -0
  136. package/dist/help/commands/show.d.ts +3 -0
  137. package/dist/help/commands/show.d.ts.map +1 -0
  138. package/dist/help/commands/show.js +18 -0
  139. package/dist/help/commands/show.js.map +1 -0
  140. package/dist/help/help.d.ts +16 -0
  141. package/dist/help/help.d.ts.map +1 -0
  142. package/dist/help/help.js +68 -0
  143. package/dist/help/help.js.map +1 -0
  144. package/dist/help/index.d.ts +4 -0
  145. package/dist/help/index.d.ts.map +1 -0
  146. package/dist/help/index.js +7 -0
  147. package/dist/help/index.js.map +1 -0
  148. package/dist/index.d.ts +80 -0
  149. package/dist/index.d.ts.map +1 -0
  150. package/dist/index.js +51 -0
  151. package/dist/index.js.map +1 -0
  152. package/dist/knowledge/block.d.ts +65 -0
  153. package/dist/knowledge/block.d.ts.map +1 -0
  154. package/dist/knowledge/block.js +89 -0
  155. package/dist/knowledge/block.js.map +1 -0
  156. package/dist/knowledge/claim.d.ts +143 -0
  157. package/dist/knowledge/claim.d.ts.map +1 -0
  158. package/dist/knowledge/claim.js +303 -0
  159. package/dist/knowledge/claim.js.map +1 -0
  160. package/dist/knowledge/index.d.ts +32 -0
  161. package/dist/knowledge/index.d.ts.map +1 -0
  162. package/dist/knowledge/index.js +29 -0
  163. package/dist/knowledge/index.js.map +1 -0
  164. package/dist/knowledge/novelty.d.ts +65 -0
  165. package/dist/knowledge/novelty.d.ts.map +1 -0
  166. package/dist/knowledge/novelty.js +100 -0
  167. package/dist/knowledge/novelty.js.map +1 -0
  168. package/dist/knowledge/recall.d.ts +134 -0
  169. package/dist/knowledge/recall.d.ts.map +1 -0
  170. package/dist/knowledge/recall.js +229 -0
  171. package/dist/knowledge/recall.js.map +1 -0
  172. package/dist/knowledge/recalled-claim.d.ts +35 -0
  173. package/dist/knowledge/recalled-claim.d.ts.map +1 -0
  174. package/dist/knowledge/recalled-claim.js +67 -0
  175. package/dist/knowledge/recalled-claim.js.map +1 -0
  176. package/dist/knowledge/recalled.d.ts +70 -0
  177. package/dist/knowledge/recalled.d.ts.map +1 -0
  178. package/dist/knowledge/recalled.js +149 -0
  179. package/dist/knowledge/recalled.js.map +1 -0
  180. package/dist/knowledge/schema.d.ts +83 -0
  181. package/dist/knowledge/schema.d.ts.map +1 -0
  182. package/dist/knowledge/schema.js +96 -0
  183. package/dist/knowledge/schema.js.map +1 -0
  184. package/dist/knowledge/staleness.d.ts +48 -0
  185. package/dist/knowledge/staleness.d.ts.map +1 -0
  186. package/dist/knowledge/staleness.js +85 -0
  187. package/dist/knowledge/staleness.js.map +1 -0
  188. package/dist/knowledge/store.d.ts +100 -0
  189. package/dist/knowledge/store.d.ts.map +1 -0
  190. package/dist/knowledge/store.js +184 -0
  191. package/dist/knowledge/store.js.map +1 -0
  192. package/dist/memory/compose-file.d.ts +14 -0
  193. package/dist/memory/compose-file.d.ts.map +1 -0
  194. package/dist/memory/compose-file.js +25 -0
  195. package/dist/memory/compose-file.js.map +1 -0
  196. package/dist/memory/index.d.ts +43 -0
  197. package/dist/memory/index.d.ts.map +1 -0
  198. package/dist/memory/index.js +119 -0
  199. package/dist/memory/index.js.map +1 -0
  200. package/dist/memory/oss.d.ts +62 -0
  201. package/dist/memory/oss.d.ts.map +1 -0
  202. package/dist/memory/oss.js +230 -0
  203. package/dist/memory/oss.js.map +1 -0
  204. package/dist/memory/platform.d.ts +37 -0
  205. package/dist/memory/platform.d.ts.map +1 -0
  206. package/dist/memory/platform.js +131 -0
  207. package/dist/memory/platform.js.map +1 -0
  208. package/dist/memory/scope.d.ts +49 -0
  209. package/dist/memory/scope.d.ts.map +1 -0
  210. package/dist/memory/scope.js +70 -0
  211. package/dist/memory/scope.js.map +1 -0
  212. package/dist/memory/types.d.ts +113 -0
  213. package/dist/memory/types.d.ts.map +1 -0
  214. package/dist/memory/types.js +18 -0
  215. package/dist/memory/types.js.map +1 -0
  216. package/dist/memory-cli.d.ts +17 -0
  217. package/dist/memory-cli.d.ts.map +1 -0
  218. package/dist/memory-cli.js +107 -0
  219. package/dist/memory-cli.js.map +1 -0
  220. package/dist/models-cli.d.ts +12 -0
  221. package/dist/models-cli.d.ts.map +1 -0
  222. package/dist/models-cli.js +54 -0
  223. package/dist/models-cli.js.map +1 -0
  224. package/dist/models.d.ts +111 -0
  225. package/dist/models.d.ts.map +1 -0
  226. package/dist/models.js +228 -0
  227. package/dist/models.js.map +1 -0
  228. package/dist/paths.d.ts +35 -0
  229. package/dist/paths.d.ts.map +1 -0
  230. package/dist/paths.js +65 -0
  231. package/dist/paths.js.map +1 -0
  232. package/dist/profile.d.ts +28 -0
  233. package/dist/profile.d.ts.map +1 -0
  234. package/dist/profile.js +154 -0
  235. package/dist/profile.js.map +1 -0
  236. package/dist/progress.d.ts +70 -0
  237. package/dist/progress.d.ts.map +1 -0
  238. package/dist/progress.js +132 -0
  239. package/dist/progress.js.map +1 -0
  240. package/dist/quiet.d.ts +2 -0
  241. package/dist/quiet.d.ts.map +1 -0
  242. package/dist/quiet.js +21 -0
  243. package/dist/quiet.js.map +1 -0
  244. package/dist/reconcile/continuation.d.ts +132 -0
  245. package/dist/reconcile/continuation.d.ts.map +1 -0
  246. package/dist/reconcile/continuation.js +306 -0
  247. package/dist/reconcile/continuation.js.map +1 -0
  248. package/dist/reconcile/index.d.ts +26 -0
  249. package/dist/reconcile/index.d.ts.map +1 -0
  250. package/dist/reconcile/index.js +28 -0
  251. package/dist/reconcile/index.js.map +1 -0
  252. package/dist/reconcile/outcome-set.d.ts +53 -0
  253. package/dist/reconcile/outcome-set.d.ts.map +1 -0
  254. package/dist/reconcile/outcome-set.js +124 -0
  255. package/dist/reconcile/outcome-set.js.map +1 -0
  256. package/dist/reconcile/outcome.d.ts +56 -0
  257. package/dist/reconcile/outcome.d.ts.map +1 -0
  258. package/dist/reconcile/outcome.js +60 -0
  259. package/dist/reconcile/outcome.js.map +1 -0
  260. package/dist/reconcile/reconciliation.d.ts +49 -0
  261. package/dist/reconcile/reconciliation.d.ts.map +1 -0
  262. package/dist/reconcile/reconciliation.js +88 -0
  263. package/dist/reconcile/reconciliation.js.map +1 -0
  264. package/dist/reconcile/schema.d.ts +157 -0
  265. package/dist/reconcile/schema.d.ts.map +1 -0
  266. package/dist/reconcile/schema.js +97 -0
  267. package/dist/reconcile/schema.js.map +1 -0
  268. package/dist/record/index.d.ts +23 -0
  269. package/dist/record/index.d.ts.map +1 -0
  270. package/dist/record/index.js +25 -0
  271. package/dist/record/index.js.map +1 -0
  272. package/dist/record/review-record.d.ts +28 -0
  273. package/dist/record/review-record.d.ts.map +1 -0
  274. package/dist/record/review-record.js +78 -0
  275. package/dist/record/review-record.js.map +1 -0
  276. package/dist/record/schema.d.ts +153 -0
  277. package/dist/record/schema.d.ts.map +1 -0
  278. package/dist/record/schema.js +87 -0
  279. package/dist/record/schema.js.map +1 -0
  280. package/dist/record/store.d.ts +83 -0
  281. package/dist/record/store.d.ts.map +1 -0
  282. package/dist/record/store.js +162 -0
  283. package/dist/record/store.js.map +1 -0
  284. package/dist/record/stored-review.d.ts +36 -0
  285. package/dist/record/stored-review.d.ts.map +1 -0
  286. package/dist/record/stored-review.js +90 -0
  287. package/dist/record/stored-review.js.map +1 -0
  288. package/dist/refute.d.ts +318 -0
  289. package/dist/refute.d.ts.map +1 -0
  290. package/dist/refute.js +513 -0
  291. package/dist/refute.js.map +1 -0
  292. package/dist/render.d.ts +212 -0
  293. package/dist/render.d.ts.map +1 -0
  294. package/dist/render.js +544 -0
  295. package/dist/render.js.map +1 -0
  296. package/dist/review-cli.d.ts +181 -0
  297. package/dist/review-cli.d.ts.map +1 -0
  298. package/dist/review-cli.js +598 -0
  299. package/dist/review-cli.js.map +1 -0
  300. package/dist/reviewer.d.ts +297 -0
  301. package/dist/reviewer.d.ts.map +1 -0
  302. package/dist/reviewer.js +584 -0
  303. package/dist/reviewer.js.map +1 -0
  304. package/dist/session-cli.d.ts +17 -0
  305. package/dist/session-cli.d.ts.map +1 -0
  306. package/dist/session-cli.js +62 -0
  307. package/dist/session-cli.js.map +1 -0
  308. package/dist/session.d.ts +36 -0
  309. package/dist/session.d.ts.map +1 -0
  310. package/dist/session.js +105 -0
  311. package/dist/session.js.map +1 -0
  312. package/dist/settings.d.ts +68 -0
  313. package/dist/settings.d.ts.map +1 -0
  314. package/dist/settings.js +175 -0
  315. package/dist/settings.js.map +1 -0
  316. package/dist/show-cli.d.ts +39 -0
  317. package/dist/show-cli.d.ts.map +1 -0
  318. package/dist/show-cli.js +56 -0
  319. package/dist/show-cli.js.map +1 -0
  320. package/dist/stdout.d.ts +28 -0
  321. package/dist/stdout.d.ts.map +1 -0
  322. package/dist/stdout.js +44 -0
  323. package/dist/stdout.js.map +1 -0
  324. package/dist/target.d.ts +58 -0
  325. package/dist/target.d.ts.map +1 -0
  326. package/dist/target.js +96 -0
  327. package/dist/target.js.map +1 -0
  328. package/dist/tools/index.d.ts +93 -0
  329. package/dist/tools/index.d.ts.map +1 -0
  330. package/dist/tools/index.js +146 -0
  331. package/dist/tools/index.js.map +1 -0
  332. package/dist/tools/root.d.ts +62 -0
  333. package/dist/tools/root.d.ts.map +1 -0
  334. package/dist/tools/root.js +51 -0
  335. package/dist/tools/root.js.map +1 -0
  336. package/dist/usage.d.ts +75 -0
  337. package/dist/usage.d.ts.map +1 -0
  338. package/dist/usage.js +100 -0
  339. package/dist/usage.js.map +1 -0
  340. package/dist/version.d.ts +14 -0
  341. package/dist/version.d.ts.map +1 -0
  342. package/dist/version.js +26 -0
  343. package/dist/version.js.map +1 -0
  344. package/dist/workspace.d.ts +48 -0
  345. package/dist/workspace.d.ts.map +1 -0
  346. package/dist/workspace.js +126 -0
  347. package/dist/workspace.js.map +1 -0
  348. package/docker-compose.yml +61 -0
  349. package/package.json +72 -1
@@ -0,0 +1,75 @@
1
+ export interface ReviewUsage {
2
+ inputTokens: number;
3
+ outputTokens: number;
4
+ totalTokens: number;
5
+ cachedTokens: number;
6
+ reasoningTokens: number;
7
+ cost?: number;
8
+ modelCalls: number;
9
+ }
10
+ /** What one assistant message reported, keyed so a restream is not counted twice. */
11
+ export interface MessageSpend {
12
+ input: number;
13
+ output: number;
14
+ cacheRead: number;
15
+ cacheWrite: number;
16
+ }
17
+ /** As much of the SDK's result message as the accounting has an opinion about. */
18
+ interface ResultAccounting {
19
+ modelUsage?: Record<string, {
20
+ inputTokens?: number;
21
+ outputTokens?: number;
22
+ cacheReadInputTokens?: number;
23
+ cacheCreationInputTokens?: number;
24
+ thinkingTokens?: number;
25
+ }>;
26
+ total_cost_usd?: number;
27
+ num_turns?: number;
28
+ }
29
+ /**
30
+ * What a run spent, from whichever source has it.
31
+ *
32
+ * Its own file because a review is no longer one model call. The reviewer's
33
+ * call and the refute pass's call each report their own totals, and a footer
34
+ * that shows one of them is not a footer about the review — it is a footer
35
+ * about half of it, printed without saying so.
36
+ */
37
+ export declare class Spend {
38
+ /**
39
+ * Totals from a result message.
40
+ *
41
+ * `modelUsage` rather than `usage`, because `usage` covers the main loop
42
+ * alone. The SDK makes auxiliary calls of its own — measured: 80k input
43
+ * tokens through Haiku on a single review — and a report that omits them
44
+ * understates what the run cost by more than a rounding error.
45
+ */
46
+ static fromResult(result: ResultAccounting): ReviewUsage;
47
+ /**
48
+ * Totals from the running tally, for a call that never produced a result.
49
+ *
50
+ * No cost: the SDK prices a run in the result message, and this is the path
51
+ * where there is no result message. Reporting the ceiling as the figure
52
+ * would be inventing a number — "cost unreported" is true instead.
53
+ */
54
+ static fromMessages(spent: ReadonlyMap<string, MessageSpend>): ReviewUsage;
55
+ /** Nothing spent, because nothing was called. */
56
+ static none(): ReviewUsage;
57
+ /**
58
+ * Several calls, one account.
59
+ *
60
+ * The cost needs a decision, because a call that threw has no price: the
61
+ * SDK bills in the result message and a throw produces none. The sum here
62
+ * is of the prices that exist, and it is `undefined` only when no part
63
+ * reported one at all.
64
+ *
65
+ * That understates a review whose second call failed after spending money,
66
+ * and the alternative understates it worse. Dropping the whole figure
67
+ * because one part of it is unknown throws away the price of the part that
68
+ * is known — which is usually the review itself, and usually most of it.
69
+ * What keeps this honest is the line above it: a pass that did not finish
70
+ * says so in the footer, beside the number it is missing from.
71
+ */
72
+ static merge(...parts: readonly ReviewUsage[]): ReviewUsage;
73
+ }
74
+ export {};
75
+ //# sourceMappingURL=usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qFAAqF;AACrF,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,kFAAkF;AAClF,UAAU,gBAAgB;IACxB,UAAU,CAAC,EAAE,MAAM,CACjB,MAAM,EACN;QACE,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,wBAAwB,CAAC,EAAE,MAAM,CAAC;QAClC,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CACF,CAAC;IACF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,qBAAa,KAAK;IAChB;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,WAAW,CAmBvD;IAED;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,WAAW,CAgBzE;IAED,iDAAiD;IACjD,MAAM,CAAC,IAAI,IAAI,WAAW,CASzB;IAED;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,WAAW,CAa1D;CACF"}
package/dist/usage.js ADDED
@@ -0,0 +1,100 @@
1
+ // This Source Code Form is subject to the terms of the Mozilla Public
2
+ // License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+ /**
5
+ * What a run spent, from whichever source has it.
6
+ *
7
+ * Its own file because a review is no longer one model call. The reviewer's
8
+ * call and the refute pass's call each report their own totals, and a footer
9
+ * that shows one of them is not a footer about the review — it is a footer
10
+ * about half of it, printed without saying so.
11
+ */
12
+ export class Spend {
13
+ /**
14
+ * Totals from a result message.
15
+ *
16
+ * `modelUsage` rather than `usage`, because `usage` covers the main loop
17
+ * alone. The SDK makes auxiliary calls of its own — measured: 80k input
18
+ * tokens through Haiku on a single review — and a report that omits them
19
+ * understates what the run cost by more than a rounding error.
20
+ */
21
+ static fromResult(result) {
22
+ const models = Object.values(result.modelUsage ?? {});
23
+ const sum = (pick) => models.reduce((total, m) => total + (pick(m) ?? 0), 0);
24
+ const inputTokens = sum((m) => m.inputTokens);
25
+ const outputTokens = sum((m) => m.outputTokens);
26
+ const cachedTokens = sum((m) => m.cacheReadInputTokens);
27
+ return {
28
+ inputTokens,
29
+ outputTokens,
30
+ totalTokens: inputTokens + outputTokens + cachedTokens + sum((m) => m.cacheCreationInputTokens),
31
+ cachedTokens,
32
+ reasoningTokens: sum((m) => m.thinkingTokens),
33
+ cost: result.total_cost_usd,
34
+ // One `query()` call, however many round trips it made inside.
35
+ modelCalls: result.num_turns ?? 0,
36
+ };
37
+ }
38
+ /**
39
+ * Totals from the running tally, for a call that never produced a result.
40
+ *
41
+ * No cost: the SDK prices a run in the result message, and this is the path
42
+ * where there is no result message. Reporting the ceiling as the figure
43
+ * would be inventing a number — "cost unreported" is true instead.
44
+ */
45
+ static fromMessages(spent) {
46
+ const all = [...spent.values()];
47
+ const sum = (pick) => all.reduce((total, m) => total + pick(m), 0);
48
+ const inputTokens = sum((m) => m.input);
49
+ const outputTokens = sum((m) => m.output);
50
+ const cachedTokens = sum((m) => m.cacheRead);
51
+ return {
52
+ inputTokens,
53
+ outputTokens,
54
+ totalTokens: inputTokens + outputTokens + cachedTokens + sum((m) => m.cacheWrite),
55
+ cachedTokens,
56
+ reasoningTokens: 0,
57
+ modelCalls: all.length,
58
+ };
59
+ }
60
+ /** Nothing spent, because nothing was called. */
61
+ static none() {
62
+ return {
63
+ inputTokens: 0,
64
+ outputTokens: 0,
65
+ totalTokens: 0,
66
+ cachedTokens: 0,
67
+ reasoningTokens: 0,
68
+ modelCalls: 0,
69
+ };
70
+ }
71
+ /**
72
+ * Several calls, one account.
73
+ *
74
+ * The cost needs a decision, because a call that threw has no price: the
75
+ * SDK bills in the result message and a throw produces none. The sum here
76
+ * is of the prices that exist, and it is `undefined` only when no part
77
+ * reported one at all.
78
+ *
79
+ * That understates a review whose second call failed after spending money,
80
+ * and the alternative understates it worse. Dropping the whole figure
81
+ * because one part of it is unknown throws away the price of the part that
82
+ * is known — which is usually the review itself, and usually most of it.
83
+ * What keeps this honest is the line above it: a pass that did not finish
84
+ * says so in the footer, beside the number it is missing from.
85
+ */
86
+ static merge(...parts) {
87
+ const sum = (pick) => parts.reduce((total, u) => total + pick(u), 0);
88
+ const priced = parts.filter((u) => u.cost !== undefined);
89
+ return {
90
+ inputTokens: sum((u) => u.inputTokens),
91
+ outputTokens: sum((u) => u.outputTokens),
92
+ totalTokens: sum((u) => u.totalTokens),
93
+ cachedTokens: sum((u) => u.cachedTokens),
94
+ reasoningTokens: sum((u) => u.reasoningTokens),
95
+ ...(priced.length > 0 && { cost: priced.reduce((total, u) => total + u.cost, 0) }),
96
+ modelCalls: sum((u) => u.modelCalls),
97
+ };
98
+ }
99
+ }
100
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAoC5D;;;;;;;GAOG;AACH,MAAM,OAAO,KAAK;IAChB;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,MAAwB;QACxC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;QACtD,MAAM,GAAG,GAAG,CAAC,IAAwD,EAAE,EAAE,CACvE,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAEzD,MAAM,WAAW,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;QAC9C,MAAM,YAAY,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAChD,MAAM,YAAY,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC;QAExD,OAAO;YACL,WAAW;YACX,YAAY;YACZ,WAAW,EAAE,WAAW,GAAG,YAAY,GAAG,YAAY,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,wBAAwB,CAAC;YAC/F,YAAY;YACZ,eAAe,EAAE,GAAG,CAAC,CAAC,CAAC,EAA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;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,KAA6B;QAC3C,MAAM,GAAG,GAAG,CAAC,IAAgC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACjG,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;QAEzD,OAAO;YACL,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;YACtC,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;YACxC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;YACtC,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;YACxC,eAAe,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;YAC9C,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,IAAK,EAAE,CAAC,CAAC,EAAE,CAAC;YACnF,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;SACrC,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ /** What VERSION holds when package.json cannot be read. `weigh doctor` fails on it. */
2
+ export declare const UNKNOWN_VERSION = "unknown";
3
+ /**
4
+ * The version of this Weigh, read from its own package.json.
5
+ *
6
+ * One level up from this file is the package root whether it runs from `src/`
7
+ * under bun or from `dist/` under node, and npm always publishes package.json.
8
+ *
9
+ * The Claude Code plugin in this repository reads it through `weigh doctor`
10
+ * to refuse a CLI older than the skill driving it. So a release that adds a
11
+ * command a skill names has to bump this, or the check cannot see the gap.
12
+ */
13
+ export declare const VERSION: string;
14
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAMA,uFAAuF;AACvF,eAAO,MAAM,eAAe,YAAY,CAAC;AAEzC;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,EAAE,MAOlB,CAAC"}
@@ -0,0 +1,26 @@
1
+ // This Source Code Form is subject to the terms of the Mozilla Public
2
+ // License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+ import { readFileSync } from 'fs';
5
+ /** What VERSION holds when package.json cannot be read. `weigh doctor` fails on it. */
6
+ export const UNKNOWN_VERSION = 'unknown';
7
+ /**
8
+ * The version of this Weigh, read from its own package.json.
9
+ *
10
+ * One level up from this file is the package root whether it runs from `src/`
11
+ * under bun or from `dist/` under node, and npm always publishes package.json.
12
+ *
13
+ * The Claude Code plugin in this repository reads it through `weigh doctor`
14
+ * to refuse a CLI older than the skill driving it. So a release that adds a
15
+ * command a skill names has to bump this, or the check cannot see the gap.
16
+ */
17
+ export const VERSION = (() => {
18
+ try {
19
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
20
+ return typeof pkg.version === 'string' ? pkg.version : UNKNOWN_VERSION;
21
+ }
22
+ catch {
23
+ return UNKNOWN_VERSION;
24
+ }
25
+ })();
26
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAElC,uFAAuF;AACvF,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC;AAEzC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,OAAO,GAAW,CAAC,GAAG,EAAE;IACnC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;QAC3F,OAAO,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;IACzE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,eAAe,CAAC;IACzB,CAAC;AACH,CAAC,CAAC,EAAE,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { Target } from './target.js';
2
+ /**
3
+ * Where the code under review is read from.
4
+ *
5
+ * `worktree` is the default because isolation turned out to be nearly free:
6
+ * measured on a real repository, `git worktree add` costs 48ms and 1.0MB, and
7
+ * leaves your branch, index and working tree untouched. Reviewing in place
8
+ * would mean the tree can change underneath the review — you edit a file
9
+ * halfway through and the findings describe a commit that never existed.
10
+ */
11
+ export type WorkspaceMode = 'worktree' | 'in-place';
12
+ export interface Workspace {
13
+ mode: WorkspaceMode;
14
+ /** Where tools are rooted for this review. */
15
+ root: string;
16
+ /** The commit under review. Null when reviewing an uncommitted tree. */
17
+ sha: string | null;
18
+ /** Why this mode was chosen, for `--dry-run` and for diagnosing surprises. */
19
+ reason: string;
20
+ /** Submodule paths declared by the tree. See the note on checkout below. */
21
+ submodules: string[];
22
+ /** Removes only what this call created. Safe to call more than once. */
23
+ cleanup(): void;
24
+ }
25
+ export interface WorkspaceRequest {
26
+ target: Target;
27
+ /** Commit to review at. Defaults to the target's HEAD. */
28
+ sha?: string | null;
29
+ /** Review the working tree as it stands, uncommitted changes included. */
30
+ includeUncommitted?: boolean;
31
+ /** Override the choice below. */
32
+ mode?: WorkspaceMode;
33
+ }
34
+ /**
35
+ * Prepares the tree a review reads from.
36
+ *
37
+ * Worktrees attach to commits, never to branches. `git worktree add <path>
38
+ * main` fails outright while main is checked out — which is the common case,
39
+ * since you are usually sitting on the branch you want reviewed. Resolving to a
40
+ * SHA and checking out detached claims no branch, so nothing can collide; two
41
+ * detached worktrees at the same commit coexist happily.
42
+ *
43
+ * It is also the semantically correct model. A review is of a commit, not a
44
+ * branch: a branch is a moving pointer, and pinning the SHA is what lets a
45
+ * finding be fingerprinted against an immutable tree and reproduced later.
46
+ */
47
+ export declare function createWorkspace(req: WorkspaceRequest): Workspace;
48
+ //# sourceMappingURL=workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,UAAU,CAAC;AAEpD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,aAAa,CAAC;IACpB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,wEAAwE;IACxE,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,0EAA0E;IAC1E,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,iCAAiC;IACjC,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAkDD;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,gBAAgB,GAAG,SAAS,CA0DhE"}
@@ -0,0 +1,126 @@
1
+ // This Source Code Form is subject to the terms of the Mozilla Public
2
+ // License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+ import { createHash } from 'crypto';
5
+ import { existsSync, rmSync } from 'fs';
6
+ import { basename, join } from 'path';
7
+ import { spawnSync } from 'child_process';
8
+ import { paths, ensureDir } from './paths.js';
9
+ function git(cwd, args) {
10
+ const proc = spawnSync('git', args, { cwd, encoding: 'utf-8' });
11
+ return { ok: proc.status === 0, out: (proc.stdout ?? '').trim(), err: (proc.stderr ?? '').trim() };
12
+ }
13
+ /** True on a CI runner whose checkout is already a disposable copy of the repo. */
14
+ function isDisposableCheckout() {
15
+ return process.env.GITHUB_ACTIONS === 'true' || process.env.CI === 'true';
16
+ }
17
+ function chooseMode(req, sha) {
18
+ if (req.mode)
19
+ return { mode: req.mode, reason: 'requested explicitly' };
20
+ // Uncommitted work is not in the object store, so there is nothing for a
21
+ // worktree to check out. Reviewing it means reviewing the tree in place.
22
+ if (req.includeUncommitted)
23
+ return { mode: 'in-place', reason: 'reviewing uncommitted changes' };
24
+ if (isDisposableCheckout())
25
+ return { mode: 'in-place', reason: 'CI checkout is already an isolated copy' };
26
+ if (!sha)
27
+ return { mode: 'in-place', reason: 'no commit to check out' };
28
+ return { mode: 'worktree', reason: 'detached checkout at the reviewed commit' };
29
+ }
30
+ /**
31
+ * Paths are keyed by target and commit so two runs cannot collide, and a rerun
32
+ * of the same review finds the tree it already made.
33
+ */
34
+ function workspacePath(target, sha) {
35
+ const digest = createHash('sha256').update(target.root).digest('hex').slice(0, 8);
36
+ return join(paths.workspaces(), `${basename(target.root)}-${digest}-${sha.slice(0, 12)}`);
37
+ }
38
+ /**
39
+ * Submodules are declared in the tree but not populated by `worktree add`.
40
+ *
41
+ * Weigh does not initialise them: that means network access and arbitrary
42
+ * checkout hooks for code it only intends to read. They are reported instead,
43
+ * so a diff that reaches inside one is explained rather than silently reviewed
44
+ * against an empty directory.
45
+ */
46
+ function detectSubmodules(root) {
47
+ if (!existsSync(join(root, '.gitmodules')))
48
+ return [];
49
+ const listed = git(root, ['config', '-f', '.gitmodules', '--get-regexp', 'path']);
50
+ if (!listed.ok)
51
+ return [];
52
+ return listed.out
53
+ .split('\n')
54
+ .filter(Boolean)
55
+ .map((line) => line.slice(line.indexOf(' ') + 1).trim())
56
+ .filter(Boolean);
57
+ }
58
+ /**
59
+ * Prepares the tree a review reads from.
60
+ *
61
+ * Worktrees attach to commits, never to branches. `git worktree add <path>
62
+ * main` fails outright while main is checked out — which is the common case,
63
+ * since you are usually sitting on the branch you want reviewed. Resolving to a
64
+ * SHA and checking out detached claims no branch, so nothing can collide; two
65
+ * detached worktrees at the same commit coexist happily.
66
+ *
67
+ * It is also the semantically correct model. A review is of a commit, not a
68
+ * branch: a branch is a moving pointer, and pinning the SHA is what lets a
69
+ * finding be fingerprinted against an immutable tree and reproduced later.
70
+ */
71
+ export function createWorkspace(req) {
72
+ const target = req.target;
73
+ const sha = req.sha !== undefined ? req.sha : target.head;
74
+ const { mode, reason } = chooseMode(req, sha);
75
+ if (mode === 'in-place') {
76
+ return {
77
+ mode,
78
+ root: target.root,
79
+ sha,
80
+ reason,
81
+ submodules: detectSubmodules(target.root),
82
+ cleanup: () => { },
83
+ };
84
+ }
85
+ // Unreachable via chooseMode, but createWorkspace is exported and a caller
86
+ // can force the mode; failing here beats `git worktree add --detach null`.
87
+ if (!sha)
88
+ throw new Error('A worktree needs a commit to check out; none was resolved.');
89
+ ensureDir(paths.workspaces());
90
+ const path = workspacePath(target, sha);
91
+ // Defensive: a workspace deleted by hand leaves a stale registration that
92
+ // makes `worktree add` refuse the path it no longer occupies.
93
+ git(target.root, ['worktree', 'prune']);
94
+ // A tree already at this path is at this commit, by construction of the key.
95
+ // Reuse it and, below, decline to remove what this call did not create —
96
+ // otherwise a concurrent review of the same commit gets its tree deleted
97
+ // mid-read.
98
+ const reused = existsSync(path);
99
+ if (!reused) {
100
+ const added = git(target.root, ['worktree', 'add', '--detach', path, sha]);
101
+ if (!added.ok) {
102
+ throw new Error(`Could not create a worktree at ${path}: ${added.err || 'git failed'}`);
103
+ }
104
+ }
105
+ let cleaned = false;
106
+ return {
107
+ mode,
108
+ root: path,
109
+ sha,
110
+ reason: reused ? 'reusing the worktree already at this commit' : reason,
111
+ submodules: detectSubmodules(path),
112
+ cleanup: () => {
113
+ if (cleaned || reused)
114
+ return;
115
+ cleaned = true;
116
+ const removed = git(target.root, ['worktree', 'remove', '--force', path]);
117
+ if (!removed.ok && existsSync(path)) {
118
+ // A worktree git will not release is still just a directory of files we
119
+ // put there. Remove it and let prune reconcile the registration.
120
+ rmSync(path, { recursive: true, force: true });
121
+ }
122
+ git(target.root, ['worktree', 'prune']);
123
+ },
124
+ };
125
+ }
126
+ //# sourceMappingURL=workspace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.js","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAsC9C,SAAS,GAAG,CAAC,GAAW,EAAE,IAAc;IACtC,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAChE,OAAO,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AAC;YACf,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;YAC1E,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBACpC,wEAAwE;gBACxE,iEAAiE;gBACjE,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACjD,CAAC;YACD,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,61 @@
1
+ # Local infrastructure for the self-hosted (oss) memory backend.
2
+ #
3
+ # docker compose up -d # from a checkout
4
+ # weigh memory compose | docker compose -f - up -d # from anywhere
5
+ # docker compose -p weigh down # stop it, from anywhere
6
+ #
7
+ # The npm package ships this file and `weigh memory compose` prints it, so
8
+ # this is the one copy. The fixed project name keeps the volumes the same
9
+ # whichever directory it is run from, the stdin pipe included.
10
+ #
11
+ # With both up, vectors live in Qdrant and embeddings run in Ollama. Reviews,
12
+ # claims and rulings send nothing else anywhere. The one thing that can leave
13
+ # the machine is fact extraction after a prompt run, through OpenRouter, and
14
+ # only when capture is turned on (it is off by default). See
15
+ # docs/self-hosting.md.
16
+ name: weigh
17
+
18
+ services:
19
+ qdrant:
20
+ # Pinned: @qdrant/js-client-rest is held at 1.18.0 for mem0, and this is
21
+ # the server version CI tests that client against.
22
+ image: qdrant/qdrant:v1.19.1
23
+ container_name: weigh-qdrant
24
+ ports:
25
+ - '6333:6333' # REST
26
+ - '6334:6334' # gRPC
27
+ volumes:
28
+ - qdrant-data:/qdrant/storage
29
+ restart: unless-stopped
30
+
31
+ ollama:
32
+ image: ollama/ollama:0.34.0
33
+ container_name: weigh-ollama
34
+ ports:
35
+ - '11434:11434'
36
+ volumes:
37
+ - ollama-models:/root/.ollama
38
+ restart: unless-stopped
39
+ healthcheck:
40
+ test: ['CMD-SHELL', 'ollama list >/dev/null 2>&1 || exit 1']
41
+ interval: 5s
42
+ timeout: 3s
43
+ retries: 30
44
+ start_period: 10s
45
+
46
+ # One-shot: pre-pull the embedding model so the first agent run is not blocked
47
+ # on a 274 MB download. mem0 would pull it on demand, but mid-run is a bad time.
48
+ ollama-pull:
49
+ image: ollama/ollama:0.34.0
50
+ container_name: weigh-ollama-pull
51
+ depends_on:
52
+ ollama:
53
+ condition: service_healthy
54
+ environment:
55
+ OLLAMA_HOST: http://ollama:11434
56
+ entrypoint: ['ollama', 'pull', 'nomic-embed-text']
57
+ restart: 'no'
58
+
59
+ volumes:
60
+ qdrant-data:
61
+ ollama-models:
package/package.json CHANGED
@@ -1 +1,72 @@
1
- {"name":"@afaik-lab/weigh","version":"0.0.0","license":"MPL-2.0"}
1
+ {
2
+ "name": "@afaik-lab/weigh",
3
+ "version": "0.6.1",
4
+ "type": "module",
5
+ "description": "Headless code-review agent built on the Claude Agent SDK",
6
+ "license": "MPL-2.0",
7
+ "author": "Ricardo Lopes",
8
+ "homepage": "https://weigh.sh",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/afaik-lab/weigh.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/afaik-lab/weigh/issues"
15
+ },
16
+ "keywords": [
17
+ "code-review",
18
+ "claude",
19
+ "agent",
20
+ "claude-code",
21
+ "review"
22
+ ],
23
+ "bin": {
24
+ "weigh": "dist/cli.js",
25
+ "wei": "dist/cli.js"
26
+ },
27
+ "main": "dist/index.js",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ }
33
+ },
34
+ "scripts": {
35
+ "start": "bun --env-file=/dev/null src/cli.ts",
36
+ "dev": "bun --env-file=/dev/null --watch src/cli.ts",
37
+ "build": "tsc -p tsconfig.build.json && chmod +x dist/cli.js",
38
+ "weigh": "node dist/cli.js",
39
+ "test": "bun test",
40
+ "typecheck": "tsc --noEmit",
41
+ "prepublishOnly": "bun run typecheck && bun run build",
42
+ "version": "bun scripts/sync-plugin-version.ts && git add .claude-plugin/plugin.json"
43
+ },
44
+ "dependencies": {
45
+ "@anthropic-ai/claude-agent-sdk": "^0.3.325",
46
+ "@qdrant/js-client-rest": "1.18.0",
47
+ "mem0ai": "^3.3.1",
48
+ "ollama": "^0.6.4",
49
+ "p-queue": "^10.0.0",
50
+ "parse-diff": "^0.12.0",
51
+ "zod": "latest"
52
+ },
53
+ "devDependencies": {
54
+ "@types/bun": "latest",
55
+ "@types/node": "^26.6.6",
56
+ "typescript": "latest"
57
+ },
58
+ "types": "dist/index.d.ts",
59
+ "files": [
60
+ "dist",
61
+ "README.md",
62
+ ".env.example",
63
+ "docker-compose.yml",
64
+ "LICENSE"
65
+ ],
66
+ "engines": {
67
+ "node": ">=22"
68
+ },
69
+ "publishConfig": {
70
+ "access": "public"
71
+ }
72
+ }