@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,162 @@
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 { existsSync, readdirSync, statSync, writeFileSync } from 'fs';
5
+ import { basename, join } from 'path';
6
+ import { ensureDir, paths } from '../paths.js';
7
+ import { repoSlug } from '../target.js';
8
+ import { StoredReview } from './stored-review.js';
9
+ /**
10
+ * Where reviews are kept, and how one is found again.
11
+ *
12
+ * Under `~/.weigh` and deliberately not under the cache. `paths.repos()` and
13
+ * the workspaces beside it are documented as safe to delete at any time —
14
+ * which is true of a clone and false of the record a correction is keyed to.
15
+ */
16
+ export class ReviewStore {
17
+ _dir;
18
+ constructor(_dir = paths.reviews()) {
19
+ this._dir = _dir;
20
+ }
21
+ /** The root of every repository's reviews. */
22
+ get dir() {
23
+ return this._dir;
24
+ }
25
+ /**
26
+ * One directory per repository, named so a human browsing can tell which.
27
+ *
28
+ * The same identity memory scopes a convention under — one rule, in
29
+ * `target.ts`, so a review and a memory about a repository cannot disagree
30
+ * about which repository they mean.
31
+ */
32
+ static slug(target) {
33
+ return repoSlug(target);
34
+ }
35
+ dirFor(target) {
36
+ return join(this._dir, ReviewStore.slug(target));
37
+ }
38
+ /**
39
+ * Writes a review and returns the path it landed at.
40
+ *
41
+ * Refuses to overwrite. Two ids colliding takes two runs in the same
42
+ * millisecond drawing the same suffix, so this should never fire — and if it
43
+ * does, failing loudly beats writing a record whose name belongs to another
44
+ * review. The caller treats that as a lost record, not a lost review.
45
+ */
46
+ save(record) {
47
+ const json = record.toJSON();
48
+ const dir = ensureDir(this.dirFor(json.repo.target));
49
+ const path = join(dir, `${json.id}.json`);
50
+ if (existsSync(path))
51
+ throw new Error(`a review is already stored at ${path}`);
52
+ writeFileSync(path, JSON.stringify(json, null, 2) + '\n');
53
+ return path;
54
+ }
55
+ /** Ids for one repository, oldest first — the timestamped names sort. */
56
+ ids(target) {
57
+ return this._idsIn(this.dirFor(target));
58
+ }
59
+ /**
60
+ * The most recent review of a repository, or of one branch of it.
61
+ *
62
+ * By id rather than by mtime: the id is when the run started, and that is
63
+ * the order reconciliation means by "the last review". A file touched since
64
+ * is still the review it was.
65
+ *
66
+ * A branch narrows it, because reconciling one branch's findings against
67
+ * another's would report fixes that are only a different change. Narrowed, it
68
+ * reads records newest-first until one matches rather than loading them all.
69
+ *
70
+ * A record this build cannot read — truncated, hand-edited, a later version —
71
+ * is skipped rather than ending the scan. It costs the scan one candidate;
72
+ * throwing would hide a usable record one slot older behind it.
73
+ */
74
+ latest(target, branch) {
75
+ for (const review of this.history(target, branch))
76
+ return review;
77
+ return undefined;
78
+ }
79
+ /**
80
+ * Every review of a repository, or of one branch of it, newest first.
81
+ *
82
+ * Lazy, so a caller that stops at the first one it can use reads only up to
83
+ * it. Unreadable records are skipped, as `latest` skips them.
84
+ */
85
+ *history(target, branch) {
86
+ const dir = this.dirFor(target);
87
+ for (const id of this.ids(target).reverse()) {
88
+ let review;
89
+ try {
90
+ review = StoredReview.read(join(dir, `${id}.json`));
91
+ }
92
+ catch {
93
+ continue;
94
+ }
95
+ if (branch === undefined || review.repo.branch === branch)
96
+ yield review;
97
+ }
98
+ }
99
+ /**
100
+ * Resolves a reference to a review: a path, or an id.
101
+ *
102
+ * An id is looked up in the repository's own directory when a target is
103
+ * known, and otherwise across every repository's — a review's id is what the
104
+ * report printed, and someone holding one should not have to know which
105
+ * checkout produced it.
106
+ */
107
+ load(ref, target) {
108
+ if (ref.endsWith('.json') && existsSync(ref))
109
+ return StoredReview.read(ref);
110
+ if (target) {
111
+ const path = join(this.dirFor(target), `${ref}.json`);
112
+ if (existsSync(path))
113
+ return StoredReview.read(path);
114
+ throw new Error(`No review ${ref} for ${target}`);
115
+ }
116
+ for (const dir of this._repoDirs()) {
117
+ const path = join(dir, `${ref}.json`);
118
+ if (existsSync(path))
119
+ return StoredReview.read(path);
120
+ }
121
+ throw new Error(`No review ${ref} in ${this._dir}`);
122
+ }
123
+ /**
124
+ * The review a command means: the one it was given, or the last of this branch.
125
+ *
126
+ * The last of this branch because that is the one whose report is on the
127
+ * screen. A detached HEAD has no branch to narrow by, and the most recent
128
+ * review of *some* branch would be the wrong one silently, so it is refused
129
+ * and naming the review is the way through. `answer` and `show` both ask
130
+ * this, and one rule is what lets a number read off one land on the same
131
+ * finding in the other. They name a review differently (`show` takes it as a
132
+ * positional, `answer` as `--review <id>`), so `how` is the caller's own
133
+ * phrase for it, and a refusal tells the user what to type.
134
+ */
135
+ pick(target, branch, ref, how = 'by its id') {
136
+ if (ref)
137
+ return this.load(ref, target);
138
+ if (!branch) {
139
+ throw new Error(`HEAD is detached, so there is no branch whose last review this is about. Name one ${how}.`);
140
+ }
141
+ const latest = this.latest(target, branch);
142
+ if (!latest)
143
+ throw new Error(`No stored review of ${branch}. Run a review first, or name one ${how}.`);
144
+ return latest;
145
+ }
146
+ _repoDirs() {
147
+ if (!existsSync(this._dir))
148
+ return [];
149
+ return readdirSync(this._dir)
150
+ .map((name) => join(this._dir, name))
151
+ .filter((path) => statSync(path).isDirectory());
152
+ }
153
+ _idsIn(dir) {
154
+ if (!existsSync(dir))
155
+ return [];
156
+ return readdirSync(dir)
157
+ .filter((f) => f.endsWith('.json'))
158
+ .map((f) => basename(f, '.json'))
159
+ .sort();
160
+ }
161
+ }
162
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/record/store.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EA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AAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,EAAE,CAAC;QAChC,OAAO,WAAW,CAAC,GAAG,CAAC;aACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;aAClC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;aAChC,IAAI,EAAE,CAAC;IACZ,CAAC;CACF"}
@@ -0,0 +1,36 @@
1
+ import { Finding, Suppression } from '../findings.js';
2
+ import { type ReviewRecordJson } from './schema.js';
3
+ /** A review read back from disk. */
4
+ export declare class StoredReview {
5
+ /** Where it was read from. `<memory>` when it was parsed from text. */
6
+ readonly path: string;
7
+ private readonly _raw;
8
+ private readonly _data;
9
+ private constructor();
10
+ static parse(text: string, path?: string): StoredReview;
11
+ static read(path: string): StoredReview;
12
+ get id(): string;
13
+ /** When the review was written, ISO 8601. */
14
+ get at(): string;
15
+ get repo(): ReviewRecordJson['repo'];
16
+ get summary(): string;
17
+ get coverage(): ReviewRecordJson['coverage'];
18
+ /** Why the run stopped early, when it did. A record of an unfinished review. */
19
+ get stopped(): ReviewRecordJson['stopped'];
20
+ /**
21
+ * The findings, in the order the report numbered them.
22
+ *
23
+ * Each identity is recomputed from the stored anchor rather than read off
24
+ * the file. The anchor is the fact; the fingerprint is a function of it, and
25
+ * a record carrying an id that its own anchor no longer produces is a record
26
+ * that would quietly match the wrong correction.
27
+ */
28
+ findings(): Finding[];
29
+ /** The finding the report called `#n`, counting from 1. */
30
+ numbered(n: number): Finding | undefined;
31
+ /** What was taken out of this review, and by whose hand. */
32
+ suppressed(): Suppression[];
33
+ /** The record exactly as stored, including anything a later build added. */
34
+ toJSON(): unknown;
35
+ }
36
+ //# sourceMappingURL=stored-review.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stored-review.d.ts","sourceRoot":"","sources":["../../src/record/stored-review.ts"],"names":[],"mappings":"AAKA,OAAO,EAAc,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAsC,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAExF,oCAAoC;AACpC,qBAAa,YAAY;IAErB,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,OAAO,eAKH;IAEJ,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAa,GAAG,YAAY,CAqB1D;IAED,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAEtC;IAED,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,6CAA6C;IAC7C,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,IAAI,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAEnC;IAED,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,QAAQ,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAE3C;IAED,gFAAgF;IAChF,IAAI,OAAO,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAEzC;IAED;;;;;;;OAOG;IACH,QAAQ,IAAI,OAAO,EAAE,CAEpB;IAED,2DAA2D;IAC3D,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAGvC;IAED,4DAA4D;IAC5D,UAAU,IAAI,WAAW,EAAE,CAI1B;IAED,4EAA4E;IAC5E,MAAM,IAAI,OAAO,CAEhB;CACF"}
@@ -0,0 +1,90 @@
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
+ import { CodeAnchor, Finding, Suppression } from '../findings.js';
6
+ import { RECORD_VERSION, reviewRecordSchema } from './schema.js';
7
+ /** A review read back from disk. */
8
+ export class StoredReview {
9
+ path;
10
+ _raw;
11
+ _data;
12
+ constructor(
13
+ /** Where it was read from. `<memory>` when it was parsed from text. */
14
+ path, _raw, _data) {
15
+ this.path = path;
16
+ this._raw = _raw;
17
+ this._data = _data;
18
+ }
19
+ static parse(text, path = '<memory>') {
20
+ let raw;
21
+ try {
22
+ raw = JSON.parse(text);
23
+ }
24
+ catch (err) {
25
+ throw new Error(`${path}: not a review record (${err?.message ?? err})`);
26
+ }
27
+ const parsed = reviewRecordSchema.safeParse(raw);
28
+ if (parsed.success)
29
+ return new StoredReview(path, raw, parsed.data);
30
+ // A record from a later build is worth its own sentence. Nothing is wrong
31
+ // with the file, and telling someone their review is malformed when it is
32
+ // merely newer sends them looking for a corruption that is not there.
33
+ const version = raw?.version;
34
+ if (typeof version === 'number' && version !== RECORD_VERSION) {
35
+ throw new Error(`${path}: review record version ${version}, and this build reads ${RECORD_VERSION}`);
36
+ }
37
+ const issue = parsed.error.issues[0];
38
+ const where = issue?.path.length ? ` at ${issue.path.join('.')}` : '';
39
+ throw new Error(`${path}: not a review record — ${issue?.message ?? 'unrecognised shape'}${where}`);
40
+ }
41
+ static read(path) {
42
+ return StoredReview.parse(readFileSync(path, 'utf-8'), path);
43
+ }
44
+ get id() {
45
+ return this._data.id;
46
+ }
47
+ /** When the review was written, ISO 8601. */
48
+ get at() {
49
+ return this._data.at;
50
+ }
51
+ get repo() {
52
+ return this._data.repo;
53
+ }
54
+ get summary() {
55
+ return this._data.summary;
56
+ }
57
+ get coverage() {
58
+ return this._data.coverage;
59
+ }
60
+ /** Why the run stopped early, when it did. A record of an unfinished review. */
61
+ get stopped() {
62
+ return this._data.stopped;
63
+ }
64
+ /**
65
+ * The findings, in the order the report numbered them.
66
+ *
67
+ * Each identity is recomputed from the stored anchor rather than read off
68
+ * the file. The anchor is the fact; the fingerprint is a function of it, and
69
+ * a record carrying an id that its own anchor no longer produces is a record
70
+ * that would quietly match the wrong correction.
71
+ */
72
+ findings() {
73
+ return this._data.findings.map((f) => new Finding(f, CodeAnchor.of(f.anchor)));
74
+ }
75
+ /** The finding the report called `#n`, counting from 1. */
76
+ numbered(n) {
77
+ if (!Number.isInteger(n) || n < 1)
78
+ return undefined;
79
+ return this.findings()[n - 1];
80
+ }
81
+ /** What was taken out of this review, and by whose hand. */
82
+ suppressed() {
83
+ return (this._data.suppressed ?? []).map((s) => new Suppression(new Finding(s.finding, CodeAnchor.of(s.finding.anchor)), s.ground, s.reason ?? undefined));
84
+ }
85
+ /** The record exactly as stored, including anything a later build added. */
86
+ toJSON() {
87
+ return this._raw;
88
+ }
89
+ }
90
+ //# sourceMappingURL=stored-review.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stored-review.js","sourceRoot":"","sources":["../../src/record/stored-review.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAyB,MAAM,aAAa,CAAC;AAExF,oCAAoC;AACpC,MAAM,OAAO,YAAY;IAGZ,IAAI;IACI,IAAI;IACJ,KAAK;IAJxB;IACE,uEAAuE;IAC9D,IAAY,EACJ,IAAa,EACb,KAAuB;oBAF/B,IAAI;oBACI,IAAI;qBACJ,KAAK;IACrB,CAAC;IAEJ,MAAM,CAAC,KAAK,CAAC,IAAY,EAAE,IAAI,GAAG,UAAU;QAC1C,IAAI,GAAY,CAAC;QACjB,IAAI,CAAC;YACH,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,0BAA0B,GAAG,EAAE,OAAO,IAAI,GAAG,G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indingSet, type Finding, type RefuteOutput, type Ruling } from './findings.js';
4
+ import { CorrectionSet } from './corrections/index.js';
5
+ import { Ceilings, type StoppedReason } from './ceilings.js';
6
+ import { type ReviewUsage } from './usage.js';
7
+ import type { ReviewEvent } from './events.js';
8
+ /**
9
+ * What the refute pass is told, and what it is shown.
10
+ *
11
+ * Its own prompt, and that is the point of it. The reviewer's instructions
12
+ * with the sign flipped would still be the party that wrote the findings,
13
+ * asked to disagree with itself — and a model agreeing with itself is the
14
+ * exact failure this pass exists to catch. So the refuter gets the findings
15
+ * and none of the reasoning that produced them, the same read-only tools, and
16
+ * one question: does this hold.
17
+ *
18
+ * Split the way the reviewer's prompt is split, for the same reason:
19
+ * `instructions` says how to rule and never changes between runs, `render`
20
+ * says what is being ruled on. The two are tuned independently.
21
+ */
22
+ export declare class RefuteBrief {
23
+ private readonly _findings;
24
+ private readonly _context;
25
+ /**
26
+ * The human rulings in force, printed under the findings they are about.
27
+ *
28
+ * Only what `grounds` returns is shown. The brief tells the pass that
29
+ * `corrected` applies where a ruling is printed and nowhere else. Printing
30
+ * a `wont-fix` here would hand it the one argument the taxonomy exists to
31
+ * refuse it.
32
+ */
33
+ private readonly _corrections;
34
+ constructor(_findings: FindingSet, _context: ReviewContext,
35
+ /**
36
+ * The human rulings in force, printed under the findings they are about.
37
+ *
38
+ * Only what `grounds` returns is shown. The brief tells the pass that
39
+ * `corrected` applies where a ruling is printed and nowhere else. Printing
40
+ * a `wont-fix` here would hand it the one argument the taxonomy exists to
41
+ * refuse it.
42
+ */
43
+ _corrections?: CorrectionSet);
44
+ /**
45
+ * The standing instructions: how to rule, and what may justify a kill.
46
+ *
47
+ * Most of this is spent narrowing the grounds, because the grounds are the
48
+ * only thing standing between a useful second pass and a slow way to lose
49
+ * findings. A refuter with an open-ended licence to disagree will use it,
50
+ * and every finding it takes with it leaves no mark on the review — the run
51
+ * reads cleaner, not broken.
52
+ */
53
+ instructions(): string;
54
+ /**
55
+ * The findings as the refuter receives them.
56
+ *
57
+ * No diff, deliberately. The refuter is not being asked what the change did,
58
+ * it is being asked whether a claim about the code holds, and it has the
59
+ * tools to go and read that code. Handing it the diff as well would double
60
+ * the cost of the call to re-supply the one view of the file the reviewer
61
+ * has already drawn its conclusion from.
62
+ *
63
+ * No suggestion either, for a sharper reason: the suggested patch is the
64
+ * reviewer's reasoning in its most persuasive form, and the pass exists to
65
+ * be unpersuaded. Evidence is what a claim rests on; a suggestion is what
66
+ * follows from believing it.
67
+ */
68
+ render(): string;
69
+ /** Which tree the line numbers below refer to. */
70
+ private _change;
71
+ /**
72
+ * One finding, with the fingerprint as its heading.
73
+ *
74
+ * At the top and on a line of its own because it is the one part of this the
75
+ * model has to reproduce character for character. Buried in a sentence it
76
+ * gets paraphrased, and a ruling nobody can match to a finding is a ruling
77
+ * that silently does nothing.
78
+ */
79
+ private _describe;
80
+ }
81
+ export interface RefuteRunOptions {
82
+ signal?: AbortSignal;
83
+ /** Overrides the configured model for this call. */
84
+ model?: string;
85
+ /** Overrides the configured effort for this call. */
86
+ effort?: Effort;
87
+ /**
88
+ * What this call may spend.
89
+ *
90
+ * Defaults to the whole configured ceiling, which means a refuted review can
91
+ * cost up to twice what `--max-cost` names. That is the honest reading of
92
+ * the flag today — it bounds a call, and there are now two. The caller is
93
+ * the only party that knows what the review already spent, so passing the
94
+ * remainder is its job, and wiring that up is what the accounting task is
95
+ * for.
96
+ */
97
+ maxCost?: number;
98
+ /**
99
+ * The human rulings in force on this branch.
100
+ *
101
+ * Read by the caller, like everything else this class is handed. It makes
102
+ * one model call and does no I/O of its own. Absent means a branch nobody
103
+ * has answered, and then no kill on the `corrected` ground can hold.
104
+ */
105
+ corrections?: CorrectionSet;
106
+ onEvent?: (event: ReviewEvent) => void;
107
+ }
108
+ /**
109
+ * That a refute pass ran, and how it went.
110
+ *
111
+ * Carried on the review rather than returned beside it, because the thing a
112
+ * reader needs is not "here are two results" — it is one review, minus what a
113
+ * second opinion took out of it, with the taking accounted for. Absent means
114
+ * no pass ran, which is not the same as a pass that dropped nothing.
115
+ */
116
+ export interface RefutePass {
117
+ /** Findings it took out. The detail of each is on `findings.suppressed`. */
118
+ dropped: number;
119
+ /**
120
+ * Findings it left standing, of those it was given. A pass that did not run
121
+ * left all of them.
122
+ */
123
+ kept: number;
124
+ /**
125
+ * Findings a continuation carried from the last review, which the pass was
126
+ * not shown. Counted in neither `dropped` nor `kept`, so "kept all 2" cannot
127
+ * describe a pass that made no call.
128
+ */
129
+ carried?: number;
130
+ /** Why it did not finish, when it did not — and then `dropped` is zero. */
131
+ stopped?: StoppedReason;
132
+ /** What the second call spent, already counted in the review's totals. */
133
+ usage: ReviewUsage;
134
+ durationMs: number;
135
+ }
136
+ export interface RefuteResult {
137
+ /** What the pass ruled, joined to the findings it was given. */
138
+ rulings: RulingSet;
139
+ /**
140
+ * Present only when the pass did not run to the end.
141
+ *
142
+ * When it is set, `rulings` is empty and every finding survives. The two
143
+ * always move together: there is no state where this pass both failed and
144
+ * dropped something.
145
+ */
146
+ stopped?: StoppedReason;
147
+ /**
148
+ * What this call spent, on its own.
149
+ *
150
+ * Reported separately rather than folded into the review's, because the
151
+ * caller is the only party that can decide what the two together mean —
152
+ * see `Spend.merge`. A pass that never ran spent nothing, and says so
153
+ * rather than being absent.
154
+ */
155
+ usage: ReviewUsage;
156
+ durationMs: number;
157
+ model: string;
158
+ }
159
+ /**
160
+ * The rulings a pass produced, joined to the findings they are about.
161
+ *
162
+ * A class rather than an array because the join is the part that can go wrong
163
+ * silently, and it is worth having one place that does it. The refuter answers
164
+ * by fingerprint; nothing stops it answering about a fingerprint it invented,
165
+ * or about the same one twice, and either mistake looks from the outside like
166
+ * a pass that simply ruled on less than it was asked to.
167
+ */
168
+ export declare class RulingSet implements Iterable<Ruling> {
169
+ private readonly _byFingerprint;
170
+ /**
171
+ * Rulings naming a fingerprint no finding carries.
172
+ *
173
+ * Counted rather than discarded quietly. A model paraphrasing the key
174
+ * instead of copying it produces a pass that appears to work and rules on
175
+ * nothing, and this number is the only thing that tells the two apart.
176
+ */
177
+ readonly unmatched: number;
178
+ private constructor();
179
+ /**
180
+ * Joins rulings to findings on the fingerprint, and throws away the rest.
181
+ *
182
+ * A ruling naming a finding that does not exist is dropped rather than
183
+ * raised: it changes nothing by definition, and failing the whole pass over
184
+ * it would discard every ruling that did match.
185
+ *
186
+ * A finding ruled on twice keeps the first ruling — unless one of them is a
187
+ * keep, in which case the keep wins. A model that contradicted itself about
188
+ * a finding has said it is not sure, and unsure is what keep is for.
189
+ */
190
+ static match(output: RefuteOutput | undefined, findings: FindingSet): RulingSet;
191
+ /** A pass that ruled on nothing — and the answer when there was nothing to rule on. */
192
+ static none(): RulingSet;
193
+ get size(): number;
194
+ [Symbol.iterator](): Iterator<Ruling>;
195
+ /**
196
+ * What was ruled about one finding, or nothing.
197
+ *
198
+ * Nothing is the common answer, and it means keep: a finding the pass never
199
+ * mentioned is a finding nobody argued against.
200
+ */
201
+ for(finding: Finding): Ruling | undefined;
202
+ /**
203
+ * The findings that survive these rulings, carrying the ones that did not.
204
+ *
205
+ * Four things read as a keep, and only one of them is the refuter saying
206
+ * keep. A finding it never mentioned stands, because nobody argued against
207
+ * it. A kill that named no ground stands too: the instructions say a kill
208
+ * carries what kills it, so a kill without one is the model failing to
209
+ * justify itself, and the answer to that is the finding, not its absence.
210
+ * And a kill on a ground that cannot hold stands — see `_holds`.
211
+ *
212
+ * Suppressions already on the set are carried forward rather than replaced.
213
+ * Nothing applies two passes today; a method that quietly discarded the
214
+ * first one's account if anything ever did is not worth the line it saves.
215
+ *
216
+ * The rulings are passed in because one of the three grounds is a claim
217
+ * about them. Passing none is the honest default, not a convenience for
218
+ * callers: a pass whose grounds cannot be checked keeps every finding it
219
+ * tried to kill on one.
220
+ */
221
+ applyTo(findings: FindingSet, corrections?: CorrectionSet): FindingSet;
222
+ /**
223
+ * Whether a ground is one this pass can actually be standing on.
224
+ *
225
+ * Two of the three are claims about the code. A kill on `code` or
226
+ * `convention` stands or falls on evidence anybody can go and read, so the
227
+ * pass may assert it. `corrected` is a claim about a human: that someone
228
+ * already ruled on this exact finding. The model cannot be the only witness
229
+ * to that, so it is looked up here.
230
+ *
231
+ * The lookup is deliberately narrow. It goes by fingerprint, not by file or
232
+ * wording, so the finding ruled on last month is the finding in front of the
233
+ * pass now. And it goes through `grounds`, so only the two labels the
234
+ * taxonomy licenses can answer. A `wont-fix` sitting in the ledger, printed
235
+ * nowhere in the brief, cannot become a reason to drop the defect it
236
+ * concedes.
237
+ *
238
+ * A missing ruling leaves the finding standing. A kill has to point at
239
+ * something outside the finding that contradicts it, and a ground nobody can
240
+ * check points at nothing. Leaving that to the model's good behaviour would
241
+ * leave the one rule that makes this pass safe to the party it checks.
242
+ */
243
+ private static _holds;
244
+ }
245
+ /**
246
+ * What came back from a refute call, and whether the call finished at all.
247
+ *
248
+ * Its own class because this is the decision the pass most needs to get right
249
+ * and cannot be seen getting wrong. Every failure here — the call threw, it
250
+ * hit a ceiling, it answered with something that is not a set of rulings —
251
+ * produces the same visible result as a pass that read everything and decided
252
+ * to keep it all: nothing is dropped. One of those is the tool working and
253
+ * the other is the tool broken, and without this distinction the report says
254
+ * the same thing about both.
255
+ */
256
+ export declare class RefuteOutcome {
257
+ /** The rulings, when there are any to have. */
258
+ readonly output: RefuteOutput | undefined;
259
+ /** Why the pass did not finish, when it did not. */
260
+ readonly stopped: StoppedReason | undefined;
261
+ private constructor();
262
+ /** A call that ended in a throw: a ceiling, or a fault. */
263
+ static threw(ceilings: Ceilings, err: unknown): RefuteOutcome;
264
+ /** A call that ran to a result, whatever that result turned out to be. */
265
+ static of(ceilings: Ceilings, result: RefuteResultMessage | undefined): RefuteOutcome;
266
+ get completed(): boolean;
267
+ }
268
+ /** As much of the SDK's result message as this pass has an opinion about. */
269
+ interface RefuteResultMessage {
270
+ subtype: string;
271
+ errors?: readonly string[];
272
+ structured_output?: unknown;
273
+ }
274
+ /**
275
+ * Runs the refute pass: one call over the findings a review produced.
276
+ *
277
+ * One call over all of them rather than one per finding, and not only because
278
+ * it is cheaper. A refuter holding the whole list can see that three findings
279
+ * rest on the same misreading of one function, which is a thing no run that
280
+ * sees them one at a time can notice.
281
+ *
282
+ * It gets the same harness the review got: the same root, the same withheld
283
+ * tools, the same confinement. What it does not get is the coverage floor.
284
+ * That floor exists because a review claims an absence — "nothing else here is
285
+ * wrong" — which is worth something only if the files were opened. A refuter
286
+ * claims nothing about files it did not open: it reads what the findings point
287
+ * at, and a finding it never investigated it keeps.
288
+ *
289
+ * Nothing thrown by the call escapes this class except a cancellation, which
290
+ * is where it parts company with the reviewer. A review that fails has
291
+ * produced nothing, so raising is the honest answer. A refute pass that fails
292
+ * has a finished review sitting behind it, and discarding that because the
293
+ * optional second opinion broke would be the tool throwing away work it had
294
+ * already done. An abort is different in kind: it is not the pass failing, it
295
+ * is the caller saying stop.
296
+ */
297
+ export declare class Refuter {
298
+ private readonly _config;
299
+ constructor(_config: AgentConfig);
300
+ /**
301
+ * What is left of a review's ceiling once the review itself is paid for.
302
+ *
303
+ * `--max-cost` names what a review may cost, and a review is two calls when
304
+ * this pass runs. Handing the second call the whole ceiling again would
305
+ * quietly let a flag that says one dollar spend two.
306
+ *
307
+ * An unpriced review subtracts nothing. That is not an oversight: a run on
308
+ * a subscription reports no cost because nothing was metered, and treating
309
+ * "unknown" as "all of it" would leave no budget for a call that is not
310
+ * being billed in the first place.
311
+ */
312
+ static remainingBudget(maxCost: number, spent: number | undefined): number;
313
+ refute(findings: FindingSet, context: ReviewContext, options?: RefuteRunOptions): Promise<RefuteResult>;
314
+ /** The call itself. Throws what the SDK throws; the caller reads it. */
315
+ private _call;
316
+ }
317
+ export {};
318
+ //# sourceMappingURL=refute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refute.d.ts","sourceRoot":"","sources":["../src/refute.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAmB,KAAK,aAAa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