@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,251 @@
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 { collectDiff } from './diff.js';
5
+ import { Claim, Knowledge, Novelty, Recall, Staleness } from './knowledge/index.js';
6
+ import { createMemoryStore } from './memory/index.js';
7
+ import { Scope } from './memory/scope.js';
8
+ import { resolveTarget } from './target.js';
9
+ export const CONTEXT_VERBS = ['add', 'list', 'search', 'recall', 'remove', 'confirm', 'clear'];
10
+ export function isContextVerb(value) {
11
+ return CONTEXT_VERBS.includes(value);
12
+ }
13
+ /**
14
+ * `weigh context <verb>` — what Weigh knows about a repository.
15
+ *
16
+ * The seam between two agents. A priming skill explores an unfamiliar
17
+ * repository and writes what it finds through this command rather than into the
18
+ * store directly: one writer, one schema, one place where a malformed claim is
19
+ * refused. It is also how a human corrects or clears what was written, which
20
+ * matters more than it sounds — knowledge you cannot read back is a liability
21
+ * rather than an asset.
22
+ */
23
+ export async function runContextCommand(verb, args, config, options) {
24
+ const target = resolveTarget({ ...(options.repo && { repo: options.repo }) });
25
+ const scope = Scope.repo(target.root);
26
+ const knowledge = new Knowledge(createMemoryStore(config.memory), config);
27
+ const emit = (payload, text) => {
28
+ if (options.json)
29
+ process.stdout.write(JSON.stringify(payload) + '\n');
30
+ else
31
+ process.stdout.write(text() + '\n');
32
+ };
33
+ const fail = (message) => {
34
+ if (options.json)
35
+ process.stdout.write(JSON.stringify({ type: 'error', message }) + '\n');
36
+ else
37
+ process.stderr.write(`Error: ${message}\n`);
38
+ return 1;
39
+ };
40
+ // A command about the store cannot degrade quietly the way a review can: an
41
+ // empty list from a backend that is down reads as "nothing is remembered".
42
+ if (!knowledge.enabled)
43
+ return fail(`Memory is unavailable: ${knowledge.reason}`);
44
+ switch (verb) {
45
+ case 'add': {
46
+ const text = (options.input ?? '').trim();
47
+ if (!text) {
48
+ return fail('weigh context add reads JSON on stdin — one claim, or an array of them.');
49
+ }
50
+ let data;
51
+ try {
52
+ data = JSON.parse(text);
53
+ }
54
+ catch (err) {
55
+ return fail(`stdin is not JSON (${err?.message ?? err})`);
56
+ }
57
+ let claims;
58
+ try {
59
+ const now = new Date();
60
+ claims = (Array.isArray(data) ? data : [data]).map((one) => Claim.parse(one, now, target.head ?? undefined));
61
+ }
62
+ catch (err) {
63
+ return fail(err?.message ?? String(err));
64
+ }
65
+ // Sifted before anything is written, so a store that fails the check
66
+ // writes nothing rather than whatever came before the failure.
67
+ let skipped = [];
68
+ if (options.ifNew) {
69
+ try {
70
+ ({ fresh: claims, skipped } = await new Novelty(knowledge, config.knowledge.similar).sift(claims, scope));
71
+ }
72
+ catch (err) {
73
+ return fail(`Nothing written: could not check what is already held (${err?.message ?? err}).`);
74
+ }
75
+ }
76
+ const written = await knowledge.add(claims, scope);
77
+ emit({
78
+ scope: scope.toString(),
79
+ added: written.map((c) => c.toJSON()),
80
+ ...(options.ifNew && {
81
+ skipped: skipped.map((one) => ({
82
+ claim: one.claim.toJSON(),
83
+ reason: one.reason,
84
+ match: one.match.toJSON(),
85
+ })),
86
+ }),
87
+ }, () => [
88
+ `Remembered ${written.length} claim${written.length === 1 ? '' : 's'} about ${scope}.`,
89
+ ...(skipped.length ? [`Skipped ${skipped.length}:`, ...skipped.map(describeSkip)] : []),
90
+ ].join('\n'));
91
+ return 0;
92
+ }
93
+ case 'list': {
94
+ if (!options.stale && options.path === undefined) {
95
+ const claims = await knowledge.list(scope, options.limit);
96
+ emit({ scope: scope.toString(), claims: claims.map((c) => c.toJSON()), count: claims.length }, () => render(claims, scope.toString()));
97
+ return 0;
98
+ }
99
+ // Filtered here rather than by the store, which can narrow by scope and
100
+ // nothing finer. Everything is read, and only what matches is printed:
101
+ // a refresh over a large repository needs the store to stay out of the
102
+ // model's context, not out of this process. `--limit` caps what is
103
+ // printed, and `matched` says how many there were, so a caller working
104
+ // through them in batches knows when it is done.
105
+ let claims = await knowledge.list(scope);
106
+ const checked = claims.length;
107
+ if (options.path !== undefined)
108
+ claims = claims.filter((claim) => claim.touches(options.path));
109
+ const stale = options.stale ? new Staleness(target.root).check(claims) : undefined;
110
+ const matched = stale ? stale.map((one) => one.claim) : claims;
111
+ const shown = options.limit !== undefined ? matched.slice(0, options.limit) : matched;
112
+ const why = new Map(stale?.map((one) => [one.claim, one]));
113
+ emit({
114
+ scope: scope.toString(),
115
+ ...(options.path !== undefined && { path: options.path }),
116
+ ...(options.stale && { stale: true }),
117
+ claims: shown.map((claim) => {
118
+ const reason = why.get(claim);
119
+ return { ...claim.toJSON(), ...(reason && { stale: { reason: reason.reason, changed: reason.changed } }) };
120
+ }),
121
+ count: shown.length,
122
+ matched: matched.length,
123
+ checked,
124
+ }, () => {
125
+ const head = `${matched.length} of ${checked} claim${checked === 1 ? '' : 's'}${options.path !== undefined ? ` about ${options.path}` : ''}${options.stale ? ' worth reading again' : ''}${shown.length < matched.length ? `, first ${shown.length} shown` : ''}.`;
126
+ if (shown.length === 0)
127
+ return head;
128
+ const lines = shown.map((claim) => {
129
+ const reason = why.get(claim);
130
+ return reason ? `${claim.describe()}\n stale: ${Staleness.describe(reason)}` : claim.describe();
131
+ });
132
+ return [head, '', ...lines].join('\n');
133
+ });
134
+ return 0;
135
+ }
136
+ case 'search': {
137
+ const query = args.join(' ').trim();
138
+ if (!query)
139
+ return fail('weigh context search needs a query.');
140
+ const claims = await knowledge.search(query, scope, {
141
+ ...(options.limit !== undefined && { topK: options.limit }),
142
+ });
143
+ emit({ scope: scope.toString(), query, claims: claims.map((c) => c.toJSON()), count: claims.length }, () => render(claims, scope.toString()));
144
+ return 0;
145
+ }
146
+ // The calibration view. Every number the retrieval is tuned by is a guess
147
+ // until it has been read against real claims and a real change, so this
148
+ // runs the retrieval a review would run and prints what each mechanism
149
+ // brought back, scores included, without spending a model call.
150
+ case 'recall': {
151
+ let files;
152
+ try {
153
+ files = collectDiff({
154
+ root: target.root,
155
+ ...(options.base && { base: options.base }),
156
+ includeUncommitted: Boolean(options.uncommitted),
157
+ }).files;
158
+ }
159
+ catch (err) {
160
+ return fail(err?.message ?? String(err));
161
+ }
162
+ const recalled = await new Recall(knowledge, config.knowledge, (message) => process.stderr.write(`Warning: ${message}\n`)).for({ target: target.root, branch: target.branch, files });
163
+ emit({ scope: scope.toString(), files: files.length, ...recalled.toJSON() }, () => [
164
+ `${files.length} changed file(s) · ${recalled.describe()}`,
165
+ '',
166
+ recalled.explain(),
167
+ '',
168
+ '── as the review will read it ──',
169
+ '',
170
+ recalled.render() || '(nothing)',
171
+ ].join('\n'));
172
+ return 0;
173
+ }
174
+ // The narrow way back. `clear` takes the whole repository, so before this
175
+ // one wrong claim cost every right one beside it. No --yes: an id is a
176
+ // deliberate pointer at one claim, and what was removed is printed whole,
177
+ // in the shape `context add` reads, so a mistake here is one pipe from
178
+ // undone.
179
+ case 'remove': {
180
+ if (args.length === 0) {
181
+ return fail('weigh context remove needs the id of a claim. weigh context list prints them.');
182
+ }
183
+ let removed;
184
+ try {
185
+ removed = await knowledge.remove(args, scope);
186
+ }
187
+ catch (err) {
188
+ return fail(err?.message ?? String(err));
189
+ }
190
+ emit({ scope: scope.toString(), removed: removed.map((c) => c.toJSON()) }, () => [`Removed ${removed.length} claim${removed.length === 1 ? '' : 's'} about ${scope}:`, render(removed, scope.toString())].join('\n'));
191
+ return 0;
192
+ }
193
+ // The other half of a refresh. A claim read again and found to hold is
194
+ // stamped with the commit it was read at, so `list --stale` stops offering
195
+ // it until its files change again. Without this, a refresh working in
196
+ // batches would be handed the same claims every time.
197
+ case 'confirm': {
198
+ if (args.length === 0) {
199
+ return fail('weigh context confirm needs the id of a claim. weigh context list --stale prints them.');
200
+ }
201
+ if (!target.head)
202
+ return fail('This repository has no commits, so there is nothing to confirm a claim against.');
203
+ // A stamp names a commit. A claim whose files have uncommitted edits was
204
+ // read in a state no commit holds, so stamping it would name code nobody
205
+ // read, and `list --stale` would keep offering it anyway.
206
+ const uncommitted = new Staleness(target.root).uncommitted();
207
+ const check = (claim) => {
208
+ const dirty = claim.cites.filter((path) => uncommitted.has(path));
209
+ return dirty.length
210
+ ? `cites files with uncommitted changes (${dirty.join(', ')}); commit them, then confirm`
211
+ : undefined;
212
+ };
213
+ let confirmed;
214
+ try {
215
+ confirmed = await knowledge.confirm(args, scope, { commit: target.head, check });
216
+ }
217
+ catch (err) {
218
+ return fail(err?.message ?? String(err));
219
+ }
220
+ emit({ scope: scope.toString(), commit: target.head, confirmed: confirmed.map((c) => c.toJSON()) }, () => `Confirmed ${confirmed.length} claim${confirmed.length === 1 ? '' : 's'} about ${scope} at ${target.head.slice(0, 7)}.`);
221
+ return 0;
222
+ }
223
+ case 'clear': {
224
+ // Irreversible, and it takes a repository's whole memory with it —
225
+ // including anything the prompt path wrote under the same scope.
226
+ if (!options.yes) {
227
+ process.stderr.write(`Refusing to clear what weigh knows about ${scope} without --yes.\n` +
228
+ `Read it first with: weigh context list${options.repo ? ` --repo ${options.repo}` : ''}\n`);
229
+ return 1;
230
+ }
231
+ const removed = await knowledge.clear(scope);
232
+ emit({ scope: scope.toString(), cleared: removed }, () => `Cleared ${removed} record${removed === 1 ? '' : 's'} for ${scope}.`);
233
+ return 0;
234
+ }
235
+ }
236
+ }
237
+ function describeSkip(one) {
238
+ const match = one.match.id ? `${one.match.id}` : `"${one.match.statement}"`;
239
+ const why = one.reason === 'held'
240
+ ? `already held as ${match}`
241
+ : one.reason === 'repeated'
242
+ ? 'repeated earlier in this batch'
243
+ : `close to ${match} (similarity ${(one.match.similarity ?? one.match.score)?.toFixed(3) ?? '?'}): "${one.match.statement}"`;
244
+ return `• ${one.claim.statement}\n ${why}`;
245
+ }
246
+ function render(claims, scope) {
247
+ if (claims.length === 0)
248
+ return `Nothing remembered about ${scope}.`;
249
+ return claims.map((c) => c.describe()).join('\n');
250
+ }
251
+ //# sourceMappingURL=context-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-cli.js","sourceRoot":"","sources":["../src/context-cli.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C,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,118 @@
1
+ import type { ChangedFile, Diff } from './diff.js';
2
+ import type { RepoProfile } from './profile.js';
3
+ import type { Workspace } from './workspace.js';
4
+ import type { Target } from './target.js';
5
+ /**
6
+ * Everything the reviewer is handed before it starts reading.
7
+ *
8
+ * The model gets the repository's own facts, the full list of what changed, and
9
+ * as much of the diff as fits — then decides for itself what to open. It is a
10
+ * better triager than a list of exclusion rules: given the file list, it skips
11
+ * the lockfile without being told, and a finding that spans two files does not
12
+ * have to be reassembled from fragments afterwards.
13
+ *
14
+ * What this costs is a guarantee of coverage. So coverage is measured instead:
15
+ * the tools record which changed files were actually read, and the run reports
16
+ * the difference rather than implying it read everything.
17
+ */
18
+ export interface ContextFile {
19
+ path: string;
20
+ previousPath: string | null;
21
+ status: ChangedFile['status'];
22
+ additions: number;
23
+ deletions: number;
24
+ binary: boolean;
25
+ /** Whether this file's hunks were inlined, or left for the tools to fetch. */
26
+ inlined: boolean;
27
+ }
28
+ export interface ReviewContext {
29
+ repo: {
30
+ /** Where the review is read from: the workspace, which may be disposable. */
31
+ root: string;
32
+ /**
33
+ * The repository the review is *about*, which is not always `root`.
34
+ *
35
+ * In worktree mode `root` is a checkout under the cache, keyed to a SHA and
36
+ * deleted when the run ends. Anything that has to recognise this repository
37
+ * on a later run — a stored review, a correction, a remembered convention —
38
+ * keys off this instead.
39
+ */
40
+ target: string;
41
+ branch: string | null;
42
+ base: string;
43
+ baseSha: string;
44
+ headSha: string | null;
45
+ mergeBase: string;
46
+ uncommitted: boolean;
47
+ };
48
+ workspace: {
49
+ mode: Workspace['mode'];
50
+ reason: string;
51
+ submodules: string[];
52
+ };
53
+ /**
54
+ * The last review, when this context holds only what changed since it.
55
+ *
56
+ * Outside `repo` on purpose. `repo` is what makes two reviews reviews of the
57
+ * same change, and it is stored as is; this says which part of that change
58
+ * was shown this time. `files`, `diff` and `totals` are all scoped to it.
59
+ */
60
+ since?: Since;
61
+ profile: RepoProfile;
62
+ files: ContextFile[];
63
+ /** Hunk text for the files that fit the budget, in the order listed. */
64
+ diff: string;
65
+ totals: {
66
+ files: number;
67
+ additions: number;
68
+ deletions: number;
69
+ };
70
+ /** Chars and a rough token count for what renderContext will produce. */
71
+ estimate: {
72
+ chars: number;
73
+ approxTokens: number;
74
+ filesOmitted: number;
75
+ };
76
+ }
77
+ /** The review a continuation picks up from, and the commit it saw. */
78
+ export interface Since {
79
+ /** The id of the last review. */
80
+ review: string;
81
+ /** The head that review was of. The diff is taken from here. */
82
+ sha: string;
83
+ }
84
+ /**
85
+ * Paths whose diffs are rarely worth reading in full.
86
+ *
87
+ * A hint for ordering, not a filter: these files still appear in the list, so
88
+ * the model can ask for one. They simply go last, so a budget that runs out
89
+ * spends itself on source rather than on a lockfile.
90
+ *
91
+ * The coverage floor reuses this for a stronger purpose — a run is never sent
92
+ * back to open a lockfile — so a path added here stops being something the
93
+ * reviewer is held to, not merely something it reads late.
94
+ */
95
+ export declare function looksGenerated(path: string): boolean;
96
+ export interface ContextInput {
97
+ target: Target;
98
+ workspace: Workspace;
99
+ diff: Diff;
100
+ profile: RepoProfile;
101
+ /** Set when `diff` was taken from the last review's head, not the merge base. */
102
+ since?: Since;
103
+ /** Characters of hunk text to inline. */
104
+ diffBudget?: number;
105
+ }
106
+ export declare function buildContext(input: ContextInput): ReviewContext;
107
+ /**
108
+ * The repository's standing facts, as a prompt reads them.
109
+ *
110
+ * Exported because the refute pass is handed the same profile and must read
111
+ * it in the same words. Two renderings of one profile would drift, and the
112
+ * drift would show up as the second pass disagreeing about a convention the
113
+ * first one was told about differently.
114
+ */
115
+ export declare function describeProfile(profile: RepoProfile): string[];
116
+ /** The context as the model receives it. */
117
+ export declare function renderContext(context: ReviewContext): string;
118
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"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;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,yEAAyE;IACzE,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;CACzE;AAED,sEAAsE;AACtE,MAAM,WAAW,KAAK;IACpB,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,GAAG,EAAE,MAAM,CAAC;CACb;AAKD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQpD;AASD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,WAAW,CAAC;IACrB,iFAAiF;IACjF,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa,CAgE/D;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,EAAE,CAe9D;AAED,4CAA4C;AAC5C,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAwD5D"}
@@ -0,0 +1,159 @@
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
+ /** Characters of hunk text to inline. Beyond this the tools fetch on demand. */
5
+ const DEFAULT_DIFF_BUDGET = 240_000;
6
+ /**
7
+ * Paths whose diffs are rarely worth reading in full.
8
+ *
9
+ * A hint for ordering, not a filter: these files still appear in the list, so
10
+ * the model can ask for one. They simply go last, so a budget that runs out
11
+ * spends itself on source rather than on a lockfile.
12
+ *
13
+ * The coverage floor reuses this for a stronger purpose — a run is never sent
14
+ * back to open a lockfile — so a path added here stops being something the
15
+ * reviewer is held to, not merely something it reads late.
16
+ */
17
+ export function looksGenerated(path) {
18
+ return (/(^|\/)(dist|build|out|vendor|node_modules|__snapshots__|\.next|coverage)\//.test(path) ||
19
+ /\.(lock|lockb|snap|min\.js|min\.css|map)$/.test(path) ||
20
+ /(^|\/)(bun\.lock|package-lock\.json|pnpm-lock\.yaml|yarn\.lock|go\.sum|Cargo\.lock|composer\.lock|poetry\.lock|uv\.lock)$/.test(path) ||
21
+ /\.(generated|gen)\.[a-z]+$/.test(path) ||
22
+ /(^|\/)(__generated__|migrations)\//.test(path));
23
+ }
24
+ /** Source first, generated last; stable within each group. */
25
+ function rank(files) {
26
+ const source = files.filter((f) => !looksGenerated(f.path));
27
+ const generated = files.filter((f) => looksGenerated(f.path));
28
+ return [...source, ...generated];
29
+ }
30
+ export function buildContext(input) {
31
+ const budget = input.diffBudget ?? DEFAULT_DIFF_BUDGET;
32
+ const ordered = rank(input.diff.files);
33
+ const sections = [];
34
+ const files = [];
35
+ let used = 0;
36
+ for (const file of ordered) {
37
+ const text = file.hunks.map((h) => h.text).join('\n');
38
+ const header = `--- ${file.path}${file.previousPath ? ` (renamed from ${file.previousPath})` : ''} ---`;
39
+ const block = `${header}\n${text}`;
40
+ // Binary files have nothing to inline; say so once rather than emitting an
41
+ // empty section the model has to interpret.
42
+ const inlined = !file.binary && text.length > 0 && used + block.length <= budget;
43
+ if (inlined) {
44
+ sections.push(block);
45
+ used += block.length;
46
+ }
47
+ files.push({
48
+ path: file.path,
49
+ previousPath: file.previousPath,
50
+ status: file.status,
51
+ additions: file.additions,
52
+ deletions: file.deletions,
53
+ binary: file.binary,
54
+ inlined,
55
+ });
56
+ }
57
+ const context = {
58
+ repo: {
59
+ root: input.workspace.root,
60
+ target: input.target.root,
61
+ branch: input.target.branch,
62
+ base: input.diff.base,
63
+ baseSha: input.diff.baseSha,
64
+ headSha: input.diff.headSha,
65
+ mergeBase: input.diff.mergeBase,
66
+ uncommitted: input.diff.uncommitted,
67
+ },
68
+ workspace: {
69
+ mode: input.workspace.mode,
70
+ reason: input.workspace.reason,
71
+ submodules: input.workspace.submodules,
72
+ },
73
+ ...(input.since && { since: input.since }),
74
+ profile: input.profile,
75
+ files,
76
+ diff: sections.join('\n\n'),
77
+ totals: {
78
+ files: files.length,
79
+ additions: files.reduce((n, f) => n + f.additions, 0),
80
+ deletions: files.reduce((n, f) => n + f.deletions, 0),
81
+ },
82
+ estimate: { chars: 0, approxTokens: 0, filesOmitted: files.filter((f) => !f.inlined).length },
83
+ };
84
+ const rendered = renderContext(context);
85
+ context.estimate.chars = rendered.length;
86
+ // Four characters per token is the usual rule of thumb for code. It is an
87
+ // estimate, and labelled as one wherever it is shown.
88
+ context.estimate.approxTokens = Math.round(rendered.length / 4);
89
+ return context;
90
+ }
91
+ /**
92
+ * The repository's standing facts, as a prompt reads them.
93
+ *
94
+ * Exported because the refute pass is handed the same profile and must read
95
+ * it in the same words. Two renderings of one profile would drift, and the
96
+ * drift would show up as the second pass disagreeing about a convention the
97
+ * first one was told about differently.
98
+ */
99
+ export function describeProfile(profile) {
100
+ const lines = [];
101
+ if (profile.languages.length)
102
+ lines.push(`Languages: ${profile.languages.join(', ')}`);
103
+ if (profile.packageManager)
104
+ lines.push(`Package manager: ${profile.packageManager}`);
105
+ if (profile.testFramework || profile.testConvention) {
106
+ lines.push(`Tests: ${profile.testFramework ?? 'unknown runner'}${profile.testConvention ? `, named ${profile.testConvention}` : ''}`);
107
+ }
108
+ if (profile.conventions.length)
109
+ lines.push(`Conventions: ${profile.conventions.join('; ')}`);
110
+ const scripts = Object.entries(profile.scripts);
111
+ if (scripts.length)
112
+ lines.push(`Commands: ${scripts.map(([k, v]) => `${k} = ${v}`).join('; ')}`);
113
+ return lines;
114
+ }
115
+ /** The context as the model receives it. */
116
+ export function renderContext(context) {
117
+ const { repo, totals } = context;
118
+ const out = [];
119
+ out.push('# Repository');
120
+ out.push(...describeProfile(context.profile));
121
+ if (context.workspace.submodules.length) {
122
+ out.push(`Submodules (not checked out, so their contents cannot be read): ${context.workspace.submodules.join(', ')}`);
123
+ }
124
+ const branch = repo.uncommitted
125
+ ? `The working tree as it stands, against ${repo.base} (merge base ${repo.mergeBase.slice(0, 8)}).`
126
+ : `${repo.base} (${repo.baseSha.slice(0, 8)}) → ${repo.headSha?.slice(0, 8)}, compared at merge base ${repo.mergeBase.slice(0, 8)}.`;
127
+ const { since } = context;
128
+ out.push('');
129
+ if (since) {
130
+ // Both ranges are named. The model is shown the narrow one and has to know
131
+ // it is narrow — a file missing from this list was not left out of the
132
+ // branch, it simply did not change again.
133
+ out.push('# Changes since the last review');
134
+ out.push(`This branch was reviewed at ${since.sha.slice(0, 8)}. Shown here is only what changed since: ${since.sha.slice(0, 8)} → ${repo.uncommitted ? 'the working tree' : repo.headSha?.slice(0, 8)}.`);
135
+ out.push(`The branch as a whole: ${branch}`);
136
+ }
137
+ else {
138
+ out.push('# Change under review');
139
+ out.push(branch);
140
+ }
141
+ if (repo.branch)
142
+ out.push(`Branch: ${repo.branch}`);
143
+ out.push(`${totals.files} file(s) changed${since ? ' since the last review' : ''}, +${totals.additions} −${totals.deletions}.`);
144
+ out.push('');
145
+ out.push(since ? '# Files changed since the last review' : '# Files changed');
146
+ const width = Math.max(...context.files.map((f) => f.path.length), 1);
147
+ for (const file of context.files) {
148
+ const note = file.binary ? ' binary, no diff' : file.inlined ? '' : ' diff not inlined — read the file if it matters';
149
+ const from = file.previousPath ? ` (was ${file.previousPath})` : '';
150
+ out.push(` ${file.status.padEnd(8)} ${file.path.padEnd(width)} +${file.additions} −${file.deletions}${from}${note}`);
151
+ }
152
+ if (context.diff) {
153
+ out.push('');
154
+ out.push('# Diff');
155
+ out.push(context.diff);
156
+ }
157
+ return out.join('\n');
158
+ }
159
+ //# sourceMappingUR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YAAY,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,GAAG,CAAC,IAAI,CACN,KAAK,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,IAAI,EAAE,CAC7G,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACb,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnB,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,67 @@
1
+ import { FindingSet } from '../findings.js';
2
+ import type { Correction } from './correction.js';
3
+ /**
4
+ * The rulings that apply to this review, keyed by the finding each is about.
5
+ *
6
+ * Two callers ask different questions of them. The report asks whether to stop
7
+ * showing a finding: that is `applyTo`, and it needs no model call, because
8
+ * what to report is not a question anyone needs a second opinion on. The
9
+ * refuter asks whether it may kill a finding by citing a human: that is
10
+ * `grounds`, which its `corrected` ground is checked against.
11
+ *
12
+ * The two get different answers. A `wont-fix` means "real, and not now", which
13
+ * is enough to stop reporting but is not an argument that the finding is wrong.
14
+ * Which labels do which is decided in the taxonomy; this class only reads
15
+ * `silences` and `grounds` off a correction.
16
+ *
17
+ * Nothing here touches disk. The caller reads the ledger, as it reads the
18
+ * recalled claims and the prior review. That also makes failure safe: a ledger
19
+ * that cannot be read gives an empty set, so nothing is silenced and nothing is
20
+ * grounded, and the review says too much rather than too little. "Could not
21
+ * check" must never come out as "nobody ruled".
22
+ */
23
+ export declare class CorrectionSet {
24
+ private readonly _byFingerprint;
25
+ private constructor();
26
+ /**
27
+ * Indexes rulings by the finding they are about. The latest one wins.
28
+ *
29
+ * `Corrections.inForce` has already picked the latest and filtered by branch.
30
+ * This picks the latest again instead of trusting the input. If someone later
31
+ * builds a set from the whole ledger by mistake, it still holds the current
32
+ * ruling on each finding, not whichever one was written first.
33
+ */
34
+ static of(corrections: readonly Correction[]): CorrectionSet;
35
+ /** Nobody has ruled, or nobody could be asked. The two behave alike here. */
36
+ static empty(): CorrectionSet;
37
+ get size(): number;
38
+ get isEmpty(): boolean;
39
+ /** For the line a run prints before it starts. */
40
+ describe(): string;
41
+ /**
42
+ * The ruling a refute pass may stand on, when a human made one.
43
+ *
44
+ * Only the two labels the taxonomy marks as grounds come back. The other
45
+ * three are in force, but they are not arguments. Agreeing with a finding is
46
+ * no reason to drop it, and a defect someone put off is still a defect. A
47
+ * pass allowed to kill on those would be learning to stop mentioning known
48
+ * bugs, and nobody ever sees that failure.
49
+ */
50
+ grounds(fingerprint: string): Correction | undefined;
51
+ /**
52
+ * The findings that survive the rulings, carrying the ones that do not.
53
+ *
54
+ * Silenced findings are suppressed, not dropped, like a refute kill or a
55
+ * confidence floor. A finding that disappears between review and report
56
+ * looks the same as one that was never found. The ruler has the strongest
57
+ * claim to see it anyway: they are the one who asked for the silence, and
58
+ * the report is where they check it was heard.
59
+ *
60
+ * Only the labels that silence take anything out. A finding a human called a
61
+ * misreading is still reported, because the code may have changed since and
62
+ * made the claim true. Checking that is the refuter's job. The taxonomy makes
63
+ * that split; this is not a cautious reading of it.
64
+ */
65
+ applyTo(findings: FindingSet): FindingSet;
66
+ }
67
+ //# sourceMappingURL=correction-set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"correction-set.d.ts","sourceRoot":"","sources":["../../src/corrections/correction-set.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAA6B,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,aAAa;IACJ,OAAO,CAAC,QAAQ,CAAC,cAAc;IAAnD,OAAO,eAAiF;IAExF;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,GAAG,aAAa,CAO3D;IAED,6EAA6E;IAC7E,MAAM,CAAC,KAAK,IAAI,aAAa,CAE5B;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,kDAAkD;IAClD,QAAQ,IAAI,MAAM,CAEjB;IAED;;;;;;;;OAQG;IACH,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAGnD;IAED;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,GAAG,UAAU,CAexC;CACF"}