@afaik-lab/weigh 0.0.0-stage → 0.6.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 (349) hide show
  1. package/.env.example +49 -0
  2. package/LICENSE +373 -0
  3. package/README.md +102 -2
  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 +132 -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 +297 -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 +94 -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 +227 -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 +580 -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 +70 -4
@@ -0,0 +1,62 @@
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 { pruneSessions, summarizeSessions } from './session.js';
5
+ export const SESSION_VERBS = ['list', 'prune'];
6
+ export function isSessionVerb(value) {
7
+ return SESSION_VERBS.includes(value);
8
+ }
9
+ /**
10
+ * `weigh sessions <verb>` — inspect and prune local transcripts.
11
+ * The memory-side counterpart is `weigh memory <verb>`; the two are separate
12
+ * stores and are pruned separately.
13
+ */
14
+ export async function runSessionCommand(verb, config, options) {
15
+ const sessions = await summarizeSessions(config.sessionDir);
16
+ if (verb === 'list') {
17
+ const shown = options.limit !== undefined ? sessions.slice(0, options.limit) : sessions;
18
+ if (options.json) {
19
+ process.stdout.write(JSON.stringify({ sessions: shown, count: sessions.length }) + '\n');
20
+ }
21
+ else if (shown.length === 0) {
22
+ process.stdout.write(`No sessions in ${config.sessionDir}.\n`);
23
+ }
24
+ else {
25
+ for (const s of shown) {
26
+ process.stdout.write(`${s.id} ${String(s.bytes).padStart(6)}B ${s.preview || '(empty)'}\n`);
27
+ }
28
+ process.stdout.write(`\n${sessions.length} session(s) in ${config.sessionDir}.\n`);
29
+ }
30
+ return 0;
31
+ }
32
+ // prune
33
+ const keep = options.keep ?? config.sessionRetention;
34
+ if (!keep || keep <= 0) {
35
+ process.stderr.write('Nothing to prune: pass --keep <n>, or run `weigh config set sessionRetention <n>`.\n' +
36
+ 'Both mean "keep the newest n transcripts"; without one, every session is kept.\n');
37
+ return 1;
38
+ }
39
+ const doomed = sessions.slice(keep);
40
+ if (doomed.length === 0) {
41
+ const message = `Nothing to prune: ${sessions.length} session(s), keeping ${keep}.`;
42
+ if (options.json)
43
+ process.stdout.write(JSON.stringify({ pruned: 0, kept: sessions.length }) + '\n');
44
+ else
45
+ process.stdout.write(message + '\n');
46
+ return 0;
47
+ }
48
+ // Transcripts are unrecoverable once gone, so this needs an explicit yes.
49
+ if (!options.yes) {
50
+ process.stderr.write(`Would delete ${doomed.length} of ${sessions.length} session(s), keeping the newest ${keep}.\n` +
51
+ `Oldest to go: ${doomed[doomed.length - 1].id}\n` +
52
+ `Re-run with --yes to confirm.\n`);
53
+ return 1;
54
+ }
55
+ const removed = pruneSessions(config.sessionDir, keep);
56
+ if (options.json)
57
+ process.stdout.write(JSON.stringify({ pruned: removed.length, kept: keep, removed }) + '\n');
58
+ else
59
+ process.stdout.write(`Pruned ${removed.length} session(s), kept the newest ${keep}.\n`);
60
+ return 0;
61
+ }
62
+ //# sourceMappingURL=session-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-cli.js","sourceRoot":"","sources":["../src/session-cli.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAG5D,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEhE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,OAAO,CAAU,CAAC;AAGxD,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,OAAO,aAAa,CAAC,QAAQ,CAAC,KAAoB,CAAC,CAAC;AACtD,CAAC;AASD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAiB,EACjB,MAAmB,EACnB,OAA8B;IAE9B,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAE5D,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACxF,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC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K,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;;YAC/F,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC;IACX,CAAC;IAED,0EAA0E;IAC1E,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QACjB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,gBAAgB,MAAM,CAAC,MAAM,OAAO,QAAQ,CAAC,MAAM,mCAAmC,IAAI,KAAK;YAC7F,iBAAiB,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,EAAE,IAAI;YAClD,iCAAiC,CACpC,CAAC;QACF,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACvD,IAAI,OAAO,CAAC,IAAI;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;;QAC1G,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,OAAO,CAAC,MAAM,gCAAgC,IAAI,KAAK,CAAC,CAAC;IAC7F,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,36 @@
1
+ type Message = {
2
+ role: string;
3
+ content: string;
4
+ [key: string]: unknown;
5
+ };
6
+ export declare function initSessionDir(dir: string): void;
7
+ export declare function saveMessage(sessionPath: string, message: Message): void;
8
+ export declare function loadSession(sessionPath: string): Promise<Message[]>;
9
+ /** Session filenames, oldest first — the ISO-timestamp names sort chronologically. */
10
+ export declare function listSessions(dir: string): string[];
11
+ export interface SessionSummary {
12
+ id: string;
13
+ path: string;
14
+ bytes: number;
15
+ modified: string;
16
+ /** Opening user message, for recognising a session at a glance. */
17
+ preview: string;
18
+ }
19
+ export declare function summarizeSessions(dir: string): Promise<SessionSummary[]>;
20
+ /**
21
+ * Delete all but the newest `keep` sessions. Returns the ids removed.
22
+ *
23
+ * Transcripts are the only local record of a run, so this never runs on its own
24
+ * — either `sessionRetention` is configured, or `weigh sessions prune --yes`.
25
+ * A non-positive `keep` is treated as "unlimited" and removes nothing, so a
26
+ * misread config can't wipe the directory.
27
+ */
28
+ export declare function pruneSessions(dir: string, keep: number): string[];
29
+ /**
30
+ * The session's stable id. Doubles as the memory run scope, so a memory can be
31
+ * traced back to the transcript that produced it.
32
+ */
33
+ export declare function sessionId(sessionPath: string): string;
34
+ export declare function newSessionPath(dir: string): string;
35
+ export {};
36
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAQA,KAAK,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAOzE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEhD;AAED,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAMvE;AAED,wBAAsB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAgBzE;AAED,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAKlD;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAsB9E;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAcjE;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGlD"}
@@ -0,0 +1,105 @@
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 { appendFileSync, mkdirSync, readdirSync, existsSync, statSync, unlinkSync } from 'fs';
5
+ import { readFile } from 'fs/promises';
6
+ import { basename, join } from 'path';
7
+ export function initSessionDir(dir) {
8
+ if (!existsSync(dir))
9
+ mkdirSync(dir, { recursive: true });
10
+ }
11
+ export function saveMessage(sessionPath, message) {
12
+ const entry = {
13
+ timestamp: new Date().toISOString(),
14
+ message,
15
+ };
16
+ appendFileSync(sessionPath, JSON.stringify(entry) + '\n');
17
+ }
18
+ export async function loadSession(sessionPath) {
19
+ if (!existsSync(sessionPath))
20
+ return [];
21
+ const text = await readFile(sessionPath, 'utf-8');
22
+ return text
23
+ .split('\n')
24
+ .filter(Boolean)
25
+ .map((line) => {
26
+ try {
27
+ const entry = JSON.parse(line);
28
+ return entry.message;
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ })
34
+ .filter((m) => m !== null);
35
+ }
36
+ /** Session filenames, oldest first — the ISO-timestamp names sort chronologically. */
37
+ export function listSessions(dir) {
38
+ if (!existsSync(dir))
39
+ return [];
40
+ return readdirSync(dir)
41
+ .filter((f) => f.endsWith('.jsonl'))
42
+ .sort();
43
+ }
44
+ export async function summarizeSessions(dir) {
45
+ const summaries = [];
46
+ for (const file of listSessions(dir)) {
47
+ const path = join(dir, file);
48
+ let preview = '';
49
+ try {
50
+ const first = (await readFile(path, 'utf-8')).split('\n').find(Boolean);
51
+ if (first)
52
+ preview = String(JSON.parse(first)?.message?.content ?? '').replace(/\s+/g, ' ').trim();
53
+ }
54
+ catch {
55
+ preview = '(unreadable)';
56
+ }
57
+ const stat = statSync(path);
58
+ summaries.push({
59
+ id: sessionId(path),
60
+ path,
61
+ bytes: stat.size,
62
+ modified: stat.mtime.toISOString(),
63
+ preview: preview.length > 80 ? preview.slice(0, 80) + '…' : preview,
64
+ });
65
+ }
66
+ // Newest first: that is the order anyone scanning for "the last run" wants.
67
+ return summaries.reverse();
68
+ }
69
+ /**
70
+ * Delete all but the newest `keep` sessions. Returns the ids removed.
71
+ *
72
+ * Transcripts are the only local record of a run, so this never runs on its own
73
+ * — either `sessionRetention` is configured, or `weigh sessions prune --yes`.
74
+ * A non-positive `keep` is treated as "unlimited" and removes nothing, so a
75
+ * misread config can't wipe the directory.
76
+ */
77
+ export function pruneSessions(dir, keep) {
78
+ if (!Number.isFinite(keep) || keep <= 0)
79
+ return [];
80
+ const files = listSessions(dir);
81
+ const doomed = files.slice(0, Math.max(0, files.length - keep));
82
+ const removed = [];
83
+ for (const file of doomed) {
84
+ try {
85
+ unlinkSync(join(dir, file));
86
+ removed.push(basename(file, '.jsonl'));
87
+ }
88
+ catch {
89
+ // A file already gone, or held open elsewhere, is not worth failing a run over.
90
+ }
91
+ }
92
+ return removed;
93
+ }
94
+ /**
95
+ * The session's stable id. Doubles as the memory run scope, so a memory can be
96
+ * traced back to the transcript that produced it.
97
+ */
98
+ export function sessionId(sessionPath) {
99
+ return basename(sessionPath, '.jsonl');
100
+ }
101
+ export function newSessionPath(dir) {
102
+ const id = new Date().toISOString().replace(/[:.]/g, '-');
103
+ return join(dir, `${id}.jsonl`);
104
+ }
105
+ //# s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;IACxC,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The single source of truth for every setting Weigh has.
3
+ *
4
+ * Environment parsing, validation and `weigh config` output are all derived
5
+ * from this table. An earlier design kept a hand-written list of environment
6
+ * variables beside the code that read them; the two copies drifted within a
7
+ * day, and the variable that went missing was the one selecting Weigh's own
8
+ * home directory. Adding an integration is one entry here, not three edits
9
+ * across three files.
10
+ */
11
+ export type SettingType = 'string' | 'number' | 'boolean' | 'enum' | 'json';
12
+ export interface Setting {
13
+ /** Dotted path into AgentConfig, e.g. `memory.oss.qdrantUrl`. */
14
+ key: string;
15
+ env?: string;
16
+ type: SettingType;
17
+ /** Never printed by `config list`; steered towards ~/.weigh/.env. */
18
+ secret?: boolean;
19
+ /**
20
+ * Belongs to one machine or one person, so a repository's shared
21
+ * `.weigh.json` may not set it. A path from a colleague's machine means
22
+ * nothing on yours, and a shared identity would record everyone's rulings
23
+ * under one name. Not being `shared` already keeps it out; this only names
24
+ * the reason in the warning.
25
+ */
26
+ local?: boolean;
27
+ /**
28
+ * A repository's shared `.weigh.json` may recommend it. An allow-list, so a
29
+ * setting added later is not shareable until someone decides it is: the file
30
+ * comes from the checkout under review, and a branch can write anything in it.
31
+ * Endpoints, raw backend config and the agent's own instructions stay out —
32
+ * a branch that sets them chooses where credentials go and what the model obeys.
33
+ */
34
+ shared?: boolean;
35
+ values?: readonly string[];
36
+ /** Has no default and is absent until set, so it is not asserted present. */
37
+ optional?: boolean;
38
+ /** Rejects zero as well as negatives. Some counts legitimately allow zero. */
39
+ positive?: boolean;
40
+ /** The largest value that means anything, inclusive. Checked by `coerce`, so on every layer. */
41
+ max?: number;
42
+ describe: string;
43
+ }
44
+ /**
45
+ * Naming rule: a vendor's own credential or endpoint keeps the vendor's name,
46
+ * because that is what users already have exported. Everything that is a Weigh
47
+ * concept is namespaced — `AGENT_MODEL` would collide the first time Weigh
48
+ * runs in CI beside another agent.
49
+ */
50
+ export declare const SETTINGS: readonly Setting[];
51
+ export declare const SETTINGS_BY_KEY: Map<string, Setting>;
52
+ /**
53
+ * Every environment variable Weigh reads. Derived, so it cannot drift from the
54
+ * settings it describes — which is the whole point of this file. It scopes what
55
+ * `~/.weigh/.env` is allowed to inject: that file configures Weigh, not the
56
+ * process it happens to be running in.
57
+ */
58
+ export declare const OWNED_ENV_KEYS: readonly string[];
59
+ export declare function isOwnedEnvKey(key: string): boolean;
60
+ /**
61
+ * A raw value as the setting's type, or an error naming what was wrong.
62
+ *
63
+ * `name` is what the reader wrote: the environment variable by default, the
64
+ * dotted key when the value came from a file, so a refusal of `maxSteps: 0` in
65
+ * `.weigh.json` does not send them looking for `WEIGH_MAX_STEPS`.
66
+ */
67
+ export declare function coerce(setting: Setting, raw: string, name?: string): unknown;
68
+ //# sourceMappingURL=settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AAEH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAE5E,MAAM,WAAW,OAAO;IACtB,iEAAiE;IACjE,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;IAClB,qEAAqE;IACrE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gGAAgG;IAChG,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,OAAO,EAqHtC,CAAC;AAEF,eAAO,MAAM,eAAe,sBAA2C,CAAC;AAGxE;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAE3C,CAAC;AAEF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,SAA6B,GAAG,OAAO,CAkChG"}
@@ -0,0 +1,175 @@
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
+ * Naming rule: a vendor's own credential or endpoint keeps the vendor's name,
6
+ * because that is what users already have exported. Everything that is a Weigh
7
+ * concept is namespaced — `AGENT_MODEL` would collide the first time Weigh
8
+ * runs in CI beside another agent.
9
+ */
10
+ export const SETTINGS = [
11
+ // ── Bootstrap ─────────────────────────────────────────────────────
12
+ { key: '$home', env: 'WEIGH_HOME', type: 'string', local: true,
13
+ describe: 'Root for config, credentials and sessions. Must be absolute.' },
14
+ { key: '$cache', env: 'WEIGH_CACHE_DIR', type: 'string', local: true,
15
+ describe: 'Where worktrees and repo clones live. Safe to delete at any time.' },
16
+ // ── Model ─────────────────────────────────────────────────────────
17
+ // Optional, unlike every credential before it. The Agent SDK authenticates
18
+ // through the Claude Code binary, which resolves a subscription login of its
19
+ // own when no key is exported — so an empty value here is a working setup,
20
+ // not a missing one. `weigh doctor` is what tells the two apart.
21
+ { key: 'apiKey', env: 'ANTHROPIC_API_KEY', type: 'string', secret: true,
22
+ describe: 'Anthropic credential. Unset falls back to the Claude Code login.' },
23
+ { key: 'model', env: 'WEIGH_MODEL', type: 'string', shared: true,
24
+ describe: 'Model used for review passes.' },
25
+ { key: 'maxSteps', env: 'WEIGH_MAX_STEPS', type: 'number', shared: true, positive: true,
26
+ describe: 'Ceiling on agent turns per run.' },
27
+ { key: 'maxCost', env: 'WEIGH_MAX_COST', type: 'number', shared: true, positive: true,
28
+ describe: 'Ceiling on spend per run, in dollars. Estimated at list price.' },
29
+ { key: 'effort', env: 'WEIGH_EFFORT', type: 'enum', shared: true,
30
+ values: ['low', 'medium', 'high', 'xhigh', 'max'],
31
+ describe: 'How hard the model thinks before it answers.' },
32
+ // A share above 1 is unreachable rather than merely strict, and would send
33
+ // every run back twice for nothing.
34
+ { key: 'coverageFloor', env: 'WEIGH_COVERAGE_FLOOR', type: 'number', shared: true, max: 1,
35
+ describe: 'Share of readable changed files to open before reporting. 0 disables.' },
36
+ // A floor above 1 is not strictness, it is a review that reports nothing:
37
+ // the schema caps confidence at 1, so every finding would fall below it.
38
+ { key: 'confidenceFloor', env: 'WEIGH_CONFIDENCE_FLOOR', type: 'number', shared: true, max: 1,
39
+ describe: 'Confidence a finding needs to be reported. 0 reports every one.' },
40
+ { key: 'continuation', env: 'WEIGH_CONTINUATION', type: 'boolean', shared: true,
41
+ describe: 'Let a second review of a branch rule on the last one\'s findings. Off reviews every run fresh.' },
42
+ { key: 'refute', env: 'WEIGH_REFUTE', type: 'boolean', shared: true,
43
+ describe: 'Put every review\'s findings to a second call that tries to kill them. Roughly twice the calls.' },
44
+ { key: 'systemPrompt', type: 'string', describe: 'Reviewer instructions.' },
45
+ { key: 'name', type: 'string', describe: 'Display name.' },
46
+ { key: 'outputMode', type: 'enum', values: ['text', 'json', 'quiet'],
47
+ describe: 'How findings are rendered.' },
48
+ // ── Sessions ──────────────────────────────────────────────────────
49
+ { key: 'sessionEnabled', env: 'WEIGH_SESSIONS', type: 'boolean',
50
+ describe: 'Keep a record of each run: a transcript for a prompt, the review itself for a review.' },
51
+ { key: 'sessionDir', env: 'WEIGH_SESSION_DIR', type: 'string', local: true,
52
+ describe: 'Where transcripts are written.' },
53
+ { key: 'sessionRetention', env: 'WEIGH_SESSION_RETENTION', type: 'number',
54
+ describe: 'Keep only the newest N transcripts. 0 keeps every one.' },
55
+ // ── What Weigh knows about a repository ──────────────────────────
56
+ { key: 'knowledge.enabled', env: 'WEIGH_KNOWLEDGE', type: 'boolean', shared: true,
57
+ describe: 'Put what is remembered about this repository into the review context.' },
58
+ { key: 'knowledge.threshold', env: 'WEIGH_KNOWLEDGE_THRESHOLD', type: 'number', shared: true,
59
+ describe: 'Relevance a claim needs to be recalled by similarity. 0 takes every hit.' },
60
+ { key: 'knowledge.perFile', env: 'WEIGH_KNOWLEDGE_PER_FILE', type: 'number', shared: true, positive: true,
61
+ describe: 'Claims pulled per changed file.' },
62
+ { key: 'knowledge.files', env: 'WEIGH_KNOWLEDGE_FILES', type: 'number', shared: true, positive: true,
63
+ describe: 'Changed files queried by similarity, code before prose.' },
64
+ { key: 'knowledge.repoCap', env: 'WEIGH_KNOWLEDGE_REPO_CAP', type: 'number', shared: true,
65
+ describe: 'Similarity hits kept for the repository. The thread on a change has no cap.' },
66
+ { key: 'knowledge.userCap', env: 'WEIGH_KNOWLEDGE_USER_CAP', type: 'number', shared: true,
67
+ describe: 'Claims listed from user scope.' },
68
+ { key: 'knowledge.scan', env: 'WEIGH_KNOWLEDGE_SCAN', type: 'number', shared: true, positive: true,
69
+ describe: 'Repository claims read to find the house rules and the glob matches.' },
70
+ { key: 'knowledge.budget', env: 'WEIGH_KNOWLEDGE_BUDGET', type: 'number', shared: true, positive: true,
71
+ describe: 'Characters of claims to inline. What does not fit is named in the prompt.' },
72
+ { key: 'knowledge.similar', env: 'WEIGH_KNOWLEDGE_SIMILAR', type: 'number', shared: true,
73
+ describe: 'Similarity at which context add --if-new holds a claim back as a likely duplicate. 1 checks exact repeats only.' },
74
+ // ── Memory ────────────────────────────────────────────────────────
75
+ { key: 'memory.enabled', env: 'WEIGH_MEMORY', type: 'boolean',
76
+ describe: 'Recall and capture long-term memory.' },
77
+ { key: 'memory.backend', env: 'WEIGH_MEMORY_BACKEND', type: 'enum',
78
+ values: ['platform', 'oss'], describe: 'Hosted Mem0, or self-hosted Qdrant.' },
79
+ { key: 'memory.userId', env: 'WEIGH_USER_ID', type: 'string', local: true,
80
+ describe: 'Identity memories are keyed on across every repository.' },
81
+ { key: 'memory.agentId', env: 'WEIGH_AGENT_ID', type: 'string',
82
+ describe: 'Lets several agents share one user namespace.' },
83
+ { key: 'memory.topK', env: 'WEIGH_MEMORY_TOP_K', type: 'number', positive: true,
84
+ describe: 'Memories recalled into the prompt per run.' },
85
+ { key: 'memory.threshold', env: 'WEIGH_MEMORY_THRESHOLD', type: 'number', optional: true,
86
+ describe: 'Minimum relevance score for a recalled memory.' },
87
+ { key: 'memory.autoCapture', env: 'WEIGH_MEMORY_CAPTURE', type: 'boolean',
88
+ describe: 'Write what each run taught us back to memory.' },
89
+ { key: 'memory.platform.apiKey', env: 'MEM0_API_KEY', type: 'string', secret: true,
90
+ describe: 'Hosted Mem0 credential.' },
91
+ { key: 'memory.platform.host', env: 'MEM0_HOST', type: 'string', optional: true,
92
+ describe: 'Hosted Mem0 endpoint.' },
93
+ { key: 'memory.oss.openRouterApiKey', env: 'OPENROUTER_API_KEY', type: 'string', secret: true,
94
+ describe: 'OpenRouter credential, used only for Mem0 fact extraction.' },
95
+ { key: 'memory.oss.qdrantUrl', env: 'QDRANT_URL', type: 'string',
96
+ describe: 'Qdrant endpoint for the self-hosted backend.' },
97
+ { key: 'memory.oss.qdrantApiKey', env: 'QDRANT_API_KEY', type: 'string', secret: true,
98
+ optional: true, describe: 'Qdrant credential.' },
99
+ { key: 'memory.oss.overrides', type: 'json', optional: true,
100
+ describe: 'Raw mem0 MemoryConfig fragments, merged last.' },
101
+ { key: 'memory.oss.collectionName', env: 'WEIGH_QDRANT_COLLECTION', type: 'string',
102
+ describe: 'Qdrant collection holding memories.' },
103
+ { key: 'memory.oss.extractionModel', env: 'WEIGH_EXTRACTION_MODEL', type: 'string',
104
+ describe: 'Model Mem0 uses to distil facts, via OpenRouter.' },
105
+ { key: 'memory.oss.embeddingProvider', env: 'WEIGH_EMBEDDER', type: 'enum',
106
+ values: ['ollama', 'openai'], describe: 'Where embeddings come from.' },
107
+ { key: 'memory.oss.embeddingModel', env: 'WEIGH_EMBEDDING_MODEL', type: 'string',
108
+ describe: 'Embedding model. Must agree with the dimensions below.' },
109
+ { key: 'memory.oss.embeddingDims', env: 'WEIGH_EMBEDDING_DIMS', type: 'number',
110
+ positive: true, describe: 'Vector size. Qdrant fixes this at collection creation.' },
111
+ { key: 'memory.oss.ollamaUrl', env: 'OLLAMA_URL', type: 'string',
112
+ describe: 'Ollama endpoint for local embeddings.' },
113
+ { key: 'memory.oss.openAiApiKey', env: 'OPENAI_API_KEY', type: 'string', secret: true,
114
+ describe: 'OpenAI credential, used only for embeddings.' },
115
+ // ── Integrations (read before they are wired, so the key set is complete) ──
116
+ { key: 'github.token', env: 'GH_TOKEN', type: 'string', secret: true,
117
+ describe: 'GitHub token. Falls back to the gh CLI keyring.' },
118
+ { key: 'linear.apiKey', env: 'LINEAR_API_KEY', type: 'string', secret: true,
119
+ describe: 'Read-scoped Linear key for acceptance-criteria assessment.' },
120
+ ];
121
+ export const SETTINGS_BY_KEY = new Map(SETTINGS.map((s) => [s.key, s]));
122
+ const SETTINGS_BY_ENV = new Map(SETTINGS.filter((s) => s.env).map((s) => [s.env, s]));
123
+ /**
124
+ * Every environment variable Weigh reads. Derived, so it cannot drift from the
125
+ * settings it describes — which is the whole point of this file. It scopes what
126
+ * `~/.weigh/.env` is allowed to inject: that file configures Weigh, not the
127
+ * process it happens to be running in.
128
+ */
129
+ export const OWNED_ENV_KEYS = SETTINGS.map((s) => s.env).filter((e) => Boolean(e));
130
+ export function isOwnedEnvKey(key) {
131
+ return SETTINGS_BY_ENV.has(key);
132
+ }
133
+ /**
134
+ * A raw value as the setting's type, or an error naming what was wrong.
135
+ *
136
+ * `name` is what the reader wrote: the environment variable by default, the
137
+ * dotted key when the value came from a file, so a refusal of `maxSteps: 0` in
138
+ * `.weigh.json` does not send them looking for `WEIGH_MAX_STEPS`.
139
+ */
140
+ export function coerce(setting, raw, name = setting.env ?? setting.key) {
141
+ switch (setting.type) {
142
+ case 'number': {
143
+ const n = Number(raw);
144
+ if (!Number.isFinite(n))
145
+ throw new Error(`${name} must be a number, got: ${raw}`);
146
+ if (setting.positive && n <= 0) {
147
+ throw new Error(`${name} must be a positive number, got: ${raw}`);
148
+ }
149
+ if (!setting.positive && n < 0) {
150
+ throw new Error(`${name} must be zero or positive, got: ${raw}`);
151
+ }
152
+ if (setting.max !== undefined && n > setting.max) {
153
+ throw new Error(`${name} must be between 0 and ${setting.max}, got: ${raw}`);
154
+ }
155
+ return n;
156
+ }
157
+ case 'boolean':
158
+ return !['0', 'false', 'no', 'off', ''].includes(raw.toLowerCase());
159
+ case 'enum':
160
+ if (!setting.values?.includes(raw)) {
161
+ throw new Error(`${name} must be one of ${setting.values?.join(' | ')}, got: ${raw}`);
162
+ }
163
+ return raw;
164
+ case 'json':
165
+ try {
166
+ return JSON.parse(raw);
167
+ }
168
+ catch {
169
+ throw new Error(`${name} must be valid JSON`);
170
+ }
171
+ default:
172
+ return raw;
173
+ }
174
+ }
175
+ //# sourceMappingURL=settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAgD5D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAuB;IAC1C,qEAAqE;IACrE,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI;QAC5D,QA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,KAAK,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;QACtE,KAAK,MAAM;YACT,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACnC,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,mBAAmB,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,EAAE,CACrE,CAAC;YACJ,CAAC;YACD,OAAO,GAAG,CAAC;QACb,KAAK,MAAM;YACT,IAAI,CAAC;gBACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACzB,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAC;YAChD,CAAC;QACH;YACE,OAAO,GAAG,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ export interface ShowOptions {
2
+ /** An id or a path. Default: the last review of this branch. */
3
+ review?: string;
4
+ repo?: string;
5
+ json: boolean;
6
+ }
7
+ /**
8
+ * `weigh show <review> --json` — a stored review, read back.
9
+ *
10
+ * Until this, a review could be read only by the run that wrote it: `answer
11
+ * --review <id>` could target one and nothing could print one. So anything
12
+ * driving Weigh from outside had to run a review to see one, and running a
13
+ * review renumbers the findings under the person who is reading them.
14
+ *
15
+ * It prints the record exactly as stored, which is the shape `review --json`
16
+ * printed when the run ended. One shape, so a reader written against either
17
+ * reads both.
18
+ *
19
+ * JSON only, for now. Text is a presentation of the record, and the formatter
20
+ * that draws one from a stored review is owed to the PR comment, the format
21
+ * that decides its interface. Without `--json` this refuses rather than
22
+ * improvising a text form, so adding the real one later changes nobody's
23
+ * output.
24
+ */
25
+ export declare class ShowCommand {
26
+ private readonly _options;
27
+ constructor(_options: ShowOptions);
28
+ run(): Promise<number>;
29
+ /**
30
+ * The review asked for.
31
+ *
32
+ * A named review with no `--repo` is looked up across every repository: an
33
+ * id is what a report printed, and holding one should be enough. Unnamed, it
34
+ * is the one `answer` would rule on, by the same rule.
35
+ */
36
+ private _review;
37
+ }
38
+ export declare function runShowCommand(options: ShowOptions): Promise<number>;
39
+ //# sourceMappingURL=show-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show-cli.d.ts","sourceRoot":"","sources":["../src/show-cli.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,WAAW;IAC1B,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAArC,YAA6B,QAAQ,EAAE,WAAW,EAAI;IAEhD,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,CAM3B;IAED;;;;;;OAMG;IACH,OAAO,CAAC,OAAO;CAOhB;AAED,wBAAsB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAE1E"}
@@ -0,0 +1,56 @@
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 { ReviewStore } from './record/index.js';
5
+ import { writeOut } from './stdout.js';
6
+ import { resolveTarget } from './target.js';
7
+ /**
8
+ * `weigh show <review> --json` — a stored review, read back.
9
+ *
10
+ * Until this, a review could be read only by the run that wrote it: `answer
11
+ * --review <id>` could target one and nothing could print one. So anything
12
+ * driving Weigh from outside had to run a review to see one, and running a
13
+ * review renumbers the findings under the person who is reading them.
14
+ *
15
+ * It prints the record exactly as stored, which is the shape `review --json`
16
+ * printed when the run ended. One shape, so a reader written against either
17
+ * reads both.
18
+ *
19
+ * JSON only, for now. Text is a presentation of the record, and the formatter
20
+ * that draws one from a stored review is owed to the PR comment, the format
21
+ * that decides its interface. Without `--json` this refuses rather than
22
+ * improvising a text form, so adding the real one later changes nobody's
23
+ * output.
24
+ */
25
+ export class ShowCommand {
26
+ _options;
27
+ constructor(_options) {
28
+ this._options = _options;
29
+ }
30
+ async run() {
31
+ if (!this._options.json) {
32
+ throw new Error('weigh show prints a stored review as JSON, and has no text form yet. Pass --json.');
33
+ }
34
+ await writeOut(JSON.stringify(this._review().toJSON()) + '\n');
35
+ return 0;
36
+ }
37
+ /**
38
+ * The review asked for.
39
+ *
40
+ * A named review with no `--repo` is looked up across every repository: an
41
+ * id is what a report printed, and holding one should be enough. Unnamed, it
42
+ * is the one `answer` would rule on, by the same rule.
43
+ */
44
+ _review() {
45
+ const { review, repo } = this._options;
46
+ const store = new ReviewStore();
47
+ if (review && !repo)
48
+ return store.load(review);
49
+ const target = resolveTarget({ ...(repo && { repo }) });
50
+ return store.pick(target.root, target.branch, review);
51
+ }
52
+ }
53
+ export async function runShowCommand(options) {
54
+ return new ShowCommand(options).run();
55
+ }
56
+ //# sourceMappingURL=show-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show-cli.js","sourceRoot":"","sources":["../src/show-cli.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D,OAAO,EAAE,WAAW,EAAqB,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAS5C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,WAAW;IACO,QAAQ;IAArC,YAA6B,QAAqB;wBAArB,QAAQ;IAAgB,CAAC;IAEtD,KAAK,CAAC,GAAG;QACP,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAC;QACvG,CAAC;QACD,MAAM,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QAC/D,OAAO,CAAC,CAAC;IACX,CAAC;IAED;;;;;;OAMG;IACK,OAAO;QACb,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QACvC,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC;QAChC,IAAI,MAAM,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC/C,MAAM,MAAM,GAAG,aAAa,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;QACxD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAoB;IACvD,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC;AACxC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Writes to stdout and waits for it to actually leave the process.
3
+ *
4
+ * `process.exit()` does not flush a pending stdout write. Writing to a file is
5
+ * synchronous so it goes unnoticed, but a pipe is not: output is truncated at
6
+ * the pipe buffer, 64KB on Linux and macOS, and `weigh … --json | jq` is the
7
+ * documented way to use this tool. Awaiting the write callback of the last
8
+ * chunk is enough, because writes are ordered — anything queued before it has
9
+ * flushed by the time it fires.
10
+ */
11
+ export declare function writeOut(text: string): Promise<void>;
12
+ /** Exits once everything already queued on stdout has been flushed. */
13
+ export declare function exitAfterFlush(code: number): Promise<never>;
14
+ /**
15
+ * Ends the process quietly when whoever was reading stdout has gone.
16
+ *
17
+ * `weigh doctor | head -3` closes the pipe after three lines, and the next
18
+ * write fails with EPIPE. Node raises that as an 'error' event on stdout, and
19
+ * with no listener it crashes with a stack trace — on the terminal of someone
20
+ * who only asked for three lines. A shell reports a process killed by a closed
21
+ * pipe as 141 (128 + SIGPIPE), so that is the code here too: under `pipefail`
22
+ * a cut-off Weigh reads the same as a cut-off `cat`.
23
+ *
24
+ * Any other stdout error is still thrown. Installed once, by the CLI entry
25
+ * point, so every command gets it rather than each one remembering to.
26
+ */
27
+ export declare function exitOnClosedPipe(): void;
28
+ //# sourceMappingURL=stdout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdout.d.ts","sourceRoot":"","sources":["../src/stdout.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpD;AAED,uEAAuE;AACvE,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAGjE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAKvC"}