@afaik-lab/weigh 0.0.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (349) hide show
  1. package/.env.example +49 -0
  2. package/LICENSE +373 -0
  3. package/README.md +103 -1
  4. package/dist/agent.d.ts +83 -0
  5. package/dist/agent.d.ts.map +1 -0
  6. package/dist/agent.js +204 -0
  7. package/dist/agent.js.map +1 -0
  8. package/dist/ceilings.d.ts +32 -0
  9. package/dist/ceilings.d.ts.map +1 -0
  10. package/dist/ceilings.js +61 -0
  11. package/dist/ceilings.js.map +1 -0
  12. package/dist/cli.d.ts +3 -0
  13. package/dist/cli.d.ts.map +1 -0
  14. package/dist/cli.js +530 -0
  15. package/dist/cli.js.map +1 -0
  16. package/dist/config-cli.d.ts +15 -0
  17. package/dist/config-cli.d.ts.map +1 -0
  18. package/dist/config-cli.js +141 -0
  19. package/dist/config-cli.js.map +1 -0
  20. package/dist/config.d.ts +198 -0
  21. package/dist/config.d.ts.map +1 -0
  22. package/dist/config.js +373 -0
  23. package/dist/config.js.map +1 -0
  24. package/dist/context-cli.d.ts +35 -0
  25. package/dist/context-cli.d.ts.map +1 -0
  26. package/dist/context-cli.js +251 -0
  27. package/dist/context-cli.js.map +1 -0
  28. package/dist/context.d.ts +118 -0
  29. package/dist/context.d.ts.map +1 -0
  30. package/dist/context.js +159 -0
  31. package/dist/context.js.map +1 -0
  32. package/dist/corrections/correction-set.d.ts +67 -0
  33. package/dist/corrections/correction-set.d.ts.map +1 -0
  34. package/dist/corrections/correction-set.js +104 -0
  35. package/dist/corrections/correction-set.js.map +1 -0
  36. package/dist/corrections/correction.d.ts +74 -0
  37. package/dist/corrections/correction.d.ts.map +1 -0
  38. package/dist/corrections/correction.js +154 -0
  39. package/dist/corrections/correction.js.map +1 -0
  40. package/dist/corrections/follow-up.d.ts +69 -0
  41. package/dist/corrections/follow-up.d.ts.map +1 -0
  42. package/dist/corrections/follow-up.js +217 -0
  43. package/dist/corrections/follow-up.js.map +1 -0
  44. package/dist/corrections/index.d.ts +31 -0
  45. package/dist/corrections/index.d.ts.map +1 -0
  46. package/dist/corrections/index.js +31 -0
  47. package/dist/corrections/index.js.map +1 -0
  48. package/dist/corrections/ledger.d.ts +78 -0
  49. package/dist/corrections/ledger.d.ts.map +1 -0
  50. package/dist/corrections/ledger.js +117 -0
  51. package/dist/corrections/ledger.js.map +1 -0
  52. package/dist/corrections/promotion.d.ts +119 -0
  53. package/dist/corrections/promotion.d.ts.map +1 -0
  54. package/dist/corrections/promotion.js +221 -0
  55. package/dist/corrections/promotion.js.map +1 -0
  56. package/dist/corrections/schema.d.ts +125 -0
  57. package/dist/corrections/schema.d.ts.map +1 -0
  58. package/dist/corrections/schema.js +100 -0
  59. package/dist/corrections/schema.js.map +1 -0
  60. package/dist/corrections-cli.d.ts +28 -0
  61. package/dist/corrections-cli.d.ts.map +1 -0
  62. package/dist/corrections-cli.js +157 -0
  63. package/dist/corrections-cli.js.map +1 -0
  64. package/dist/diff.d.ts +105 -0
  65. package/dist/diff.d.ts.map +1 -0
  66. package/dist/diff.js +202 -0
  67. package/dist/diff.js.map +1 -0
  68. package/dist/doctor.d.ts +38 -0
  69. package/dist/doctor.d.ts.map +1 -0
  70. package/dist/doctor.js +197 -0
  71. package/dist/doctor.js.map +1 -0
  72. package/dist/events.d.ts +21 -0
  73. package/dist/events.d.ts.map +1 -0
  74. package/dist/events.js +5 -0
  75. package/dist/events.js.map +1 -0
  76. package/dist/findings.d.ts +510 -0
  77. package/dist/findings.d.ts.map +1 -0
  78. package/dist/findings.js +645 -0
  79. package/dist/findings.js.map +1 -0
  80. package/dist/follow-up-cli.d.ts +88 -0
  81. package/dist/follow-up-cli.d.ts.map +1 -0
  82. package/dist/follow-up-cli.js +208 -0
  83. package/dist/follow-up-cli.js.map +1 -0
  84. package/dist/harness.d.ts +64 -0
  85. package/dist/harness.d.ts.map +1 -0
  86. package/dist/harness.js +71 -0
  87. package/dist/harness.js.map +1 -0
  88. package/dist/help/command-help.d.ts +9 -0
  89. package/dist/help/command-help.d.ts.map +1 -0
  90. package/dist/help/command-help.js +21 -0
  91. package/dist/help/command-help.js.map +1 -0
  92. package/dist/help/commands/answer.d.ts +3 -0
  93. package/dist/help/commands/answer.d.ts.map +1 -0
  94. package/dist/help/commands/answer.js +39 -0
  95. package/dist/help/commands/answer.js.map +1 -0
  96. package/dist/help/commands/config.d.ts +3 -0
  97. package/dist/help/commands/config.d.ts.map +1 -0
  98. package/dist/help/commands/config.js +25 -0
  99. package/dist/help/commands/config.js.map +1 -0
  100. package/dist/help/commands/context.d.ts +3 -0
  101. package/dist/help/commands/context.d.ts.map +1 -0
  102. package/dist/help/commands/context.js +44 -0
  103. package/dist/help/commands/context.js.map +1 -0
  104. package/dist/help/commands/corrections.d.ts +3 -0
  105. package/dist/help/commands/corrections.d.ts.map +1 -0
  106. package/dist/help/commands/corrections.js +30 -0
  107. package/dist/help/commands/corrections.js.map +1 -0
  108. package/dist/help/commands/doctor.d.ts +3 -0
  109. package/dist/help/commands/doctor.d.ts.map +1 -0
  110. package/dist/help/commands/doctor.js +12 -0
  111. package/dist/help/commands/doctor.js.map +1 -0
  112. package/dist/help/commands/index.d.ts +4 -0
  113. package/dist/help/commands/index.d.ts.map +1 -0
  114. package/dist/help/commands/index.js +27 -0
  115. package/dist/help/commands/index.js.map +1 -0
  116. package/dist/help/commands/memory.d.ts +3 -0
  117. package/dist/help/commands/memory.d.ts.map +1 -0
  118. package/dist/help/commands/memory.js +33 -0
  119. package/dist/help/commands/memory.js.map +1 -0
  120. package/dist/help/commands/models.d.ts +3 -0
  121. package/dist/help/commands/models.d.ts.map +1 -0
  122. package/dist/help/commands/models.js +17 -0
  123. package/dist/help/commands/models.js.map +1 -0
  124. package/dist/help/commands/options.d.ts +4 -0
  125. package/dist/help/commands/options.d.ts.map +1 -0
  126. package/dist/help/commands/options.js +13 -0
  127. package/dist/help/commands/options.js.map +1 -0
  128. package/dist/help/commands/review.d.ts +3 -0
  129. package/dist/help/commands/review.d.ts.map +1 -0
  130. package/dist/help/commands/review.js +50 -0
  131. package/dist/help/commands/review.js.map +1 -0
  132. package/dist/help/commands/sessions.d.ts +3 -0
  133. package/dist/help/commands/sessions.d.ts.map +1 -0
  134. package/dist/help/commands/sessions.js +23 -0
  135. package/dist/help/commands/sessions.js.map +1 -0
  136. package/dist/help/commands/show.d.ts +3 -0
  137. package/dist/help/commands/show.d.ts.map +1 -0
  138. package/dist/help/commands/show.js +18 -0
  139. package/dist/help/commands/show.js.map +1 -0
  140. package/dist/help/help.d.ts +16 -0
  141. package/dist/help/help.d.ts.map +1 -0
  142. package/dist/help/help.js +68 -0
  143. package/dist/help/help.js.map +1 -0
  144. package/dist/help/index.d.ts +4 -0
  145. package/dist/help/index.d.ts.map +1 -0
  146. package/dist/help/index.js +7 -0
  147. package/dist/help/index.js.map +1 -0
  148. package/dist/index.d.ts +80 -0
  149. package/dist/index.d.ts.map +1 -0
  150. package/dist/index.js +51 -0
  151. package/dist/index.js.map +1 -0
  152. package/dist/knowledge/block.d.ts +65 -0
  153. package/dist/knowledge/block.d.ts.map +1 -0
  154. package/dist/knowledge/block.js +89 -0
  155. package/dist/knowledge/block.js.map +1 -0
  156. package/dist/knowledge/claim.d.ts +143 -0
  157. package/dist/knowledge/claim.d.ts.map +1 -0
  158. package/dist/knowledge/claim.js +303 -0
  159. package/dist/knowledge/claim.js.map +1 -0
  160. package/dist/knowledge/index.d.ts +32 -0
  161. package/dist/knowledge/index.d.ts.map +1 -0
  162. package/dist/knowledge/index.js +29 -0
  163. package/dist/knowledge/index.js.map +1 -0
  164. package/dist/knowledge/novelty.d.ts +65 -0
  165. package/dist/knowledge/novelty.d.ts.map +1 -0
  166. package/dist/knowledge/novelty.js +100 -0
  167. package/dist/knowledge/novelty.js.map +1 -0
  168. package/dist/knowledge/recall.d.ts +134 -0
  169. package/dist/knowledge/recall.d.ts.map +1 -0
  170. package/dist/knowledge/recall.js +229 -0
  171. package/dist/knowledge/recall.js.map +1 -0
  172. package/dist/knowledge/recalled-claim.d.ts +35 -0
  173. package/dist/knowledge/recalled-claim.d.ts.map +1 -0
  174. package/dist/knowledge/recalled-claim.js +67 -0
  175. package/dist/knowledge/recalled-claim.js.map +1 -0
  176. package/dist/knowledge/recalled.d.ts +70 -0
  177. package/dist/knowledge/recalled.d.ts.map +1 -0
  178. package/dist/knowledge/recalled.js +149 -0
  179. package/dist/knowledge/recalled.js.map +1 -0
  180. package/dist/knowledge/schema.d.ts +83 -0
  181. package/dist/knowledge/schema.d.ts.map +1 -0
  182. package/dist/knowledge/schema.js +96 -0
  183. package/dist/knowledge/schema.js.map +1 -0
  184. package/dist/knowledge/staleness.d.ts +48 -0
  185. package/dist/knowledge/staleness.d.ts.map +1 -0
  186. package/dist/knowledge/staleness.js +85 -0
  187. package/dist/knowledge/staleness.js.map +1 -0
  188. package/dist/knowledge/store.d.ts +100 -0
  189. package/dist/knowledge/store.d.ts.map +1 -0
  190. package/dist/knowledge/store.js +184 -0
  191. package/dist/knowledge/store.js.map +1 -0
  192. package/dist/memory/compose-file.d.ts +14 -0
  193. package/dist/memory/compose-file.d.ts.map +1 -0
  194. package/dist/memory/compose-file.js +25 -0
  195. package/dist/memory/compose-file.js.map +1 -0
  196. package/dist/memory/index.d.ts +43 -0
  197. package/dist/memory/index.d.ts.map +1 -0
  198. package/dist/memory/index.js +119 -0
  199. package/dist/memory/index.js.map +1 -0
  200. package/dist/memory/oss.d.ts +62 -0
  201. package/dist/memory/oss.d.ts.map +1 -0
  202. package/dist/memory/oss.js +230 -0
  203. package/dist/memory/oss.js.map +1 -0
  204. package/dist/memory/platform.d.ts +37 -0
  205. package/dist/memory/platform.d.ts.map +1 -0
  206. package/dist/memory/platform.js +131 -0
  207. package/dist/memory/platform.js.map +1 -0
  208. package/dist/memory/scope.d.ts +49 -0
  209. package/dist/memory/scope.d.ts.map +1 -0
  210. package/dist/memory/scope.js +70 -0
  211. package/dist/memory/scope.js.map +1 -0
  212. package/dist/memory/types.d.ts +113 -0
  213. package/dist/memory/types.d.ts.map +1 -0
  214. package/dist/memory/types.js +18 -0
  215. package/dist/memory/types.js.map +1 -0
  216. package/dist/memory-cli.d.ts +17 -0
  217. package/dist/memory-cli.d.ts.map +1 -0
  218. package/dist/memory-cli.js +107 -0
  219. package/dist/memory-cli.js.map +1 -0
  220. package/dist/models-cli.d.ts +12 -0
  221. package/dist/models-cli.d.ts.map +1 -0
  222. package/dist/models-cli.js +54 -0
  223. package/dist/models-cli.js.map +1 -0
  224. package/dist/models.d.ts +111 -0
  225. package/dist/models.d.ts.map +1 -0
  226. package/dist/models.js +228 -0
  227. package/dist/models.js.map +1 -0
  228. package/dist/paths.d.ts +35 -0
  229. package/dist/paths.d.ts.map +1 -0
  230. package/dist/paths.js +65 -0
  231. package/dist/paths.js.map +1 -0
  232. package/dist/profile.d.ts +28 -0
  233. package/dist/profile.d.ts.map +1 -0
  234. package/dist/profile.js +154 -0
  235. package/dist/profile.js.map +1 -0
  236. package/dist/progress.d.ts +70 -0
  237. package/dist/progress.d.ts.map +1 -0
  238. package/dist/progress.js +132 -0
  239. package/dist/progress.js.map +1 -0
  240. package/dist/quiet.d.ts +2 -0
  241. package/dist/quiet.d.ts.map +1 -0
  242. package/dist/quiet.js +21 -0
  243. package/dist/quiet.js.map +1 -0
  244. package/dist/reconcile/continuation.d.ts +132 -0
  245. package/dist/reconcile/continuation.d.ts.map +1 -0
  246. package/dist/reconcile/continuation.js +306 -0
  247. package/dist/reconcile/continuation.js.map +1 -0
  248. package/dist/reconcile/index.d.ts +26 -0
  249. package/dist/reconcile/index.d.ts.map +1 -0
  250. package/dist/reconcile/index.js +28 -0
  251. package/dist/reconcile/index.js.map +1 -0
  252. package/dist/reconcile/outcome-set.d.ts +53 -0
  253. package/dist/reconcile/outcome-set.d.ts.map +1 -0
  254. package/dist/reconcile/outcome-set.js +124 -0
  255. package/dist/reconcile/outcome-set.js.map +1 -0
  256. package/dist/reconcile/outcome.d.ts +56 -0
  257. package/dist/reconcile/outcome.d.ts.map +1 -0
  258. package/dist/reconcile/outcome.js +60 -0
  259. package/dist/reconcile/outcome.js.map +1 -0
  260. package/dist/reconcile/reconciliation.d.ts +49 -0
  261. package/dist/reconcile/reconciliation.d.ts.map +1 -0
  262. package/dist/reconcile/reconciliation.js +88 -0
  263. package/dist/reconcile/reconciliation.js.map +1 -0
  264. package/dist/reconcile/schema.d.ts +157 -0
  265. package/dist/reconcile/schema.d.ts.map +1 -0
  266. package/dist/reconcile/schema.js +97 -0
  267. package/dist/reconcile/schema.js.map +1 -0
  268. package/dist/record/index.d.ts +23 -0
  269. package/dist/record/index.d.ts.map +1 -0
  270. package/dist/record/index.js +25 -0
  271. package/dist/record/index.js.map +1 -0
  272. package/dist/record/review-record.d.ts +28 -0
  273. package/dist/record/review-record.d.ts.map +1 -0
  274. package/dist/record/review-record.js +78 -0
  275. package/dist/record/review-record.js.map +1 -0
  276. package/dist/record/schema.d.ts +153 -0
  277. package/dist/record/schema.d.ts.map +1 -0
  278. package/dist/record/schema.js +87 -0
  279. package/dist/record/schema.js.map +1 -0
  280. package/dist/record/store.d.ts +83 -0
  281. package/dist/record/store.d.ts.map +1 -0
  282. package/dist/record/store.js +162 -0
  283. package/dist/record/store.js.map +1 -0
  284. package/dist/record/stored-review.d.ts +36 -0
  285. package/dist/record/stored-review.d.ts.map +1 -0
  286. package/dist/record/stored-review.js +90 -0
  287. package/dist/record/stored-review.js.map +1 -0
  288. package/dist/refute.d.ts +318 -0
  289. package/dist/refute.d.ts.map +1 -0
  290. package/dist/refute.js +513 -0
  291. package/dist/refute.js.map +1 -0
  292. package/dist/render.d.ts +212 -0
  293. package/dist/render.d.ts.map +1 -0
  294. package/dist/render.js +544 -0
  295. package/dist/render.js.map +1 -0
  296. package/dist/review-cli.d.ts +181 -0
  297. package/dist/review-cli.d.ts.map +1 -0
  298. package/dist/review-cli.js +598 -0
  299. package/dist/review-cli.js.map +1 -0
  300. package/dist/reviewer.d.ts +297 -0
  301. package/dist/reviewer.d.ts.map +1 -0
  302. package/dist/reviewer.js +584 -0
  303. package/dist/reviewer.js.map +1 -0
  304. package/dist/session-cli.d.ts +17 -0
  305. package/dist/session-cli.d.ts.map +1 -0
  306. package/dist/session-cli.js +62 -0
  307. package/dist/session-cli.js.map +1 -0
  308. package/dist/session.d.ts +36 -0
  309. package/dist/session.d.ts.map +1 -0
  310. package/dist/session.js +105 -0
  311. package/dist/session.js.map +1 -0
  312. package/dist/settings.d.ts +68 -0
  313. package/dist/settings.d.ts.map +1 -0
  314. package/dist/settings.js +175 -0
  315. package/dist/settings.js.map +1 -0
  316. package/dist/show-cli.d.ts +39 -0
  317. package/dist/show-cli.d.ts.map +1 -0
  318. package/dist/show-cli.js +56 -0
  319. package/dist/show-cli.js.map +1 -0
  320. package/dist/stdout.d.ts +28 -0
  321. package/dist/stdout.d.ts.map +1 -0
  322. package/dist/stdout.js +44 -0
  323. package/dist/stdout.js.map +1 -0
  324. package/dist/target.d.ts +58 -0
  325. package/dist/target.d.ts.map +1 -0
  326. package/dist/target.js +96 -0
  327. package/dist/target.js.map +1 -0
  328. package/dist/tools/index.d.ts +93 -0
  329. package/dist/tools/index.d.ts.map +1 -0
  330. package/dist/tools/index.js +146 -0
  331. package/dist/tools/index.js.map +1 -0
  332. package/dist/tools/root.d.ts +62 -0
  333. package/dist/tools/root.d.ts.map +1 -0
  334. package/dist/tools/root.js +51 -0
  335. package/dist/tools/root.js.map +1 -0
  336. package/dist/usage.d.ts +75 -0
  337. package/dist/usage.d.ts.map +1 -0
  338. package/dist/usage.js +100 -0
  339. package/dist/usage.js.map +1 -0
  340. package/dist/version.d.ts +14 -0
  341. package/dist/version.d.ts.map +1 -0
  342. package/dist/version.js +26 -0
  343. package/dist/version.js.map +1 -0
  344. package/dist/workspace.d.ts +48 -0
  345. package/dist/workspace.d.ts.map +1 -0
  346. package/dist/workspace.js +126 -0
  347. package/dist/workspace.js.map +1 -0
  348. package/docker-compose.yml +61 -0
  349. package/package.json +72 -1
@@ -0,0 +1,134 @@
1
+ import type { ChangedFile } from '../diff.js';
2
+ import { Recalled } from './recalled.js';
3
+ import type { Knowledge } from './store.js';
4
+ /**
5
+ * The numbers the retrieval is tuned by.
6
+ *
7
+ * All of them provisional, and all of them settings, because this is a
8
+ * retrieval design and a retrieval design is only as good as its measurements.
9
+ * `weigh context recall` prints what each one lets through.
10
+ */
11
+ export interface RecallLimits {
12
+ /** Relevance a proximity hit needs. Below this it is noise with a score. */
13
+ threshold: number;
14
+ /** Claims per changed-file query. */
15
+ perFile: number;
16
+ /** Changed files queried by proximity, code first. */
17
+ files: number;
18
+ /** Proximity hits kept across the whole repository scope. */
19
+ repoCap: number;
20
+ /** Claims listed from user scope. */
21
+ userCap: number;
22
+ /** Repository claims enumerated for the always-injected and glob mechanisms. */
23
+ scan: number;
24
+ /** Characters of claims to inline. */
25
+ budget: number;
26
+ }
27
+ /** The change the claims are being found for. */
28
+ export interface ChangeUnderReview {
29
+ /**
30
+ * The repository the claims are about: the user's checkout, not the
31
+ * workspace, which in worktree mode is a disposable clone under the cache.
32
+ */
33
+ target: string;
34
+ branch: string | null;
35
+ files: readonly ChangedFile[];
36
+ }
37
+ /**
38
+ * Finds what Weigh knows that bears on one change.
39
+ *
40
+ * Four mechanisms, each matched to what it is good at:
41
+ *
42
+ * - **Always injected** — a claim marked `applies: ["*"]`. These are the rules
43
+ * of the house: a sentence each, a few dozen at most, and their whole purpose
44
+ * is to shape every judgement. You do not search for them, you post them on
45
+ * the wall.
46
+ * - **Path matched** — a claim whose glob names a changed file. A guarantee,
47
+ * not a ranking: the glob is how a writer says "this governs these files",
48
+ * and a guarantee that competed with a similarity score would not be one.
49
+ * - **Proximity, queried from the hunks** — the mechanism that earns the vector
50
+ * store. What carries meaning in a change is its code: the identifiers, the
51
+ * imports, the call sites. A hunk that adds a call to the Volvo API embeds
52
+ * next to "all Volvo API calls go through VolvoAuthService" because they
53
+ * share the concept, and no glob on the API package would have caught it.
54
+ * Queried per changed file rather than over the whole diff, which is a blur
55
+ * that matches nothing well — and queried from the code rather than the path,
56
+ * because "TypeScript files do not use semicolons" has almost nothing in
57
+ * common with the string `src/record/store.ts`.
58
+ * - **Listed** — the thread on this branch, and user scope. Relevance plays no
59
+ * part in either: a correction must never be the eleventh most relevant and
60
+ * therefore absent, and user scope is small enough to read in full.
61
+ *
62
+ * Nothing here fails a review. Memory is an enhancement, so a backend that is
63
+ * down costs the run its context and says so, exactly as recall does on the
64
+ * prompt path.
65
+ */
66
+ export declare class Recall {
67
+ private readonly _knowledge;
68
+ private readonly _limits;
69
+ private readonly _onWarn?;
70
+ constructor(_knowledge: Knowledge, _limits: RecallLimits, _onWarn?: ((message: string) => void) | undefined);
71
+ for(change: ChangeUnderReview): Promise<Recalled>;
72
+ /** Repository scope: the house rules, the globs, then the proximity hits. */
73
+ private _repo;
74
+ /**
75
+ * The repository claims nearest the hunks, best first.
76
+ *
77
+ * Ranked across the whole scope and capped there, rather than per file: ten
78
+ * files that all touch the same service should not each contribute their own
79
+ * third-best match.
80
+ */
81
+ private _nearby;
82
+ /**
83
+ * Target scope: the thread on this change, listed in full.
84
+ *
85
+ * Uncapped and unsearched. This is where a human's correction lives, and a
86
+ * cosine score is a poor thing to stake "did the reviewer see that you said
87
+ * this was deliberate" on.
88
+ */
89
+ private _thread;
90
+ /**
91
+ * User scope: small, and always in.
92
+ *
93
+ * Read wide and filtered here, because user scope is the one scope that
94
+ * filters on nothing narrower than the user — a list at that scope answers
95
+ * with every repository's claims as well, which would put another project's
96
+ * conventions in front of this review under the heading of how you work.
97
+ * What belongs in this block is what was written with no scope at all.
98
+ */
99
+ private _reviewer;
100
+ /**
101
+ * The changed files worth embedding: code first, and the biggest change
102
+ * within each group.
103
+ *
104
+ * A deleted file still carries signal — the code that went is as much a clue
105
+ * to what this change is about as the code that arrived — but a binary has
106
+ * nothing to embed and a lockfile embeds to nothing useful.
107
+ *
108
+ * Size alone would be the wrong order. A README rewritten in one sitting is
109
+ * four hundred changed lines of prose that no claim is phrased in, and it
110
+ * would take a query slot from the six-line change to the service the claims
111
+ * are actually about. So the comparison by size happens inside a group and
112
+ * never across one, and the files most likely to sit near a claim are the
113
+ * ones that survive the cap.
114
+ */
115
+ private static _queryable;
116
+ /** 0 for code, 1 for the prose and data around it. */
117
+ private static _group;
118
+ /** How much of the file this change touched. */
119
+ private static _churn;
120
+ /**
121
+ * One file's change as a query.
122
+ *
123
+ * Diff markers and hunk headers come off: `@@ -1,7 +1,9 @@` is noise in an
124
+ * embedding, and a leading `+` makes two copies of the same line of code look
125
+ * like two different strings. The path leads, because it is weak signal that
126
+ * costs nothing beside the code.
127
+ */
128
+ private static _query;
129
+ /** How many searches a recall has in flight at once. */
130
+ private static readonly _PARALLEL;
131
+ /** A read that costs the review its context rather than its run. */
132
+ private _safe;
133
+ }
134
+ //# sourceMappingURL=recall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recall.d.ts","sourceRoot":"","sources":["../../src/knowledge/recall.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,iDAAiD;AACjD,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;CAC/B;AAeD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,MAAM;IAEf,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IAH3B,YACmB,UAAU,EAAE,SAAS,EACrB,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,aAAA,EAClD;IAEE,GAAG,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqBtD;IAED,6EAA6E;YAC/D,KAAK;IA+BnB;;;;;;OAMG;YACW,OAAO;IA4CrB;;;;;;OAMG;YACW,OAAO;IAUrB;;;;;;;;OAQG;YACW,SAAS;IAavB;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAOzB,sDAAsD;IACtD,OAAO,CAAC,MAAM,CAAC,MAAM;IAIrB,gDAAgD;IAChD,OAAO,CAAC,MAAM,CAAC,MAAM;IAIrB;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,MAAM;IAYrB,wDAAwD;IACxD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAK;IAEtC,oEAAoE;YACtD,KAAK;CAQpB"}
@@ -0,0 +1,229 @@
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 PQueue from 'p-queue';
5
+ import { looksGenerated } from '../context.js';
6
+ import { Scope } from '../memory/scope.js';
7
+ import { KnowledgeBlock } from './block.js';
8
+ import { Recalled } from './recalled.js';
9
+ /** Characters of hunk text that go into one proximity query. */
10
+ const QUERY_CHARS = 2_000;
11
+ /**
12
+ * Paths whose size says little about what a change is about.
13
+ *
14
+ * Prose and data, by extension and by the handful of conventional names that
15
+ * carry none. Not excluded — a claim can be about where the docs live — only
16
+ * queried after the code.
17
+ */
18
+ const PROSE_OR_DATA = /\.(md|mdx|markdown|rst|adoc|txt|json|jsonc|ya?ml|toml|ini|csv|tsv|svg)$|(^|\/)(LICENSE|NOTICE|CHANGELOG|AUTHORS|CODEOWNERS)$/i;
19
+ /**
20
+ * Finds what Weigh knows that bears on one change.
21
+ *
22
+ * Four mechanisms, each matched to what it is good at:
23
+ *
24
+ * - **Always injected** — a claim marked `applies: ["*"]`. These are the rules
25
+ * of the house: a sentence each, a few dozen at most, and their whole purpose
26
+ * is to shape every judgement. You do not search for them, you post them on
27
+ * the wall.
28
+ * - **Path matched** — a claim whose glob names a changed file. A guarantee,
29
+ * not a ranking: the glob is how a writer says "this governs these files",
30
+ * and a guarantee that competed with a similarity score would not be one.
31
+ * - **Proximity, queried from the hunks** — the mechanism that earns the vector
32
+ * store. What carries meaning in a change is its code: the identifiers, the
33
+ * imports, the call sites. A hunk that adds a call to the Volvo API embeds
34
+ * next to "all Volvo API calls go through VolvoAuthService" because they
35
+ * share the concept, and no glob on the API package would have caught it.
36
+ * Queried per changed file rather than over the whole diff, which is a blur
37
+ * that matches nothing well — and queried from the code rather than the path,
38
+ * because "TypeScript files do not use semicolons" has almost nothing in
39
+ * common with the string `src/record/store.ts`.
40
+ * - **Listed** — the thread on this branch, and user scope. Relevance plays no
41
+ * part in either: a correction must never be the eleventh most relevant and
42
+ * therefore absent, and user scope is small enough to read in full.
43
+ *
44
+ * Nothing here fails a review. Memory is an enhancement, so a backend that is
45
+ * down costs the run its context and says so, exactly as recall does on the
46
+ * prompt path.
47
+ */
48
+ export class Recall {
49
+ _knowledge;
50
+ _limits;
51
+ _onWarn;
52
+ constructor(_knowledge, _limits, _onWarn) {
53
+ this._knowledge = _knowledge;
54
+ this._limits = _limits;
55
+ this._onWarn = _onWarn;
56
+ }
57
+ async for(change) {
58
+ const repo = new KnowledgeBlock('This repository', 'House rules, and what is recorded about the files in this change.', 1);
59
+ const thread = new KnowledgeBlock('This change', 'What has already been said about the work on this branch.', 0);
60
+ const reviewer = new KnowledgeBlock('How you review', 'What holds wherever this reviewer is working, repository or not.', 2);
61
+ // Independent reads against three scopes, so they go out together.
62
+ await Promise.all([this._repo(repo, change), this._thread(thread, change), this._reviewer(reviewer)]);
63
+ return new Recalled([repo, thread, reviewer], this._limits.budget);
64
+ }
65
+ /** Repository scope: the house rules, the globs, then the proximity hits. */
66
+ async _repo(block, change) {
67
+ const scope = Scope.repo(change.target);
68
+ const known = await this._safe('what this repository is like', () => this._knowledge.list(scope, this._limits.scan));
69
+ // A listing that came back full is a listing with more behind it, and the
70
+ // two mechanisms below are guarantees — so say it rather than quietly
71
+ // guaranteeing less than was asked for.
72
+ if (known.length >= this._limits.scan) {
73
+ this._onWarn?.(`read the first ${this._limits.scan} claims about this repository; there may be more (WEIGH_KNOWLEDGE_SCAN)`);
74
+ }
75
+ for (const claim of known) {
76
+ if (claim.isHouseRule)
77
+ block.add(claim, 'always');
78
+ }
79
+ const paths = change.files.map((file) => file.path);
80
+ for (const claim of known) {
81
+ if (claim.isHouseRule)
82
+ continue;
83
+ const hit = paths.find((path) => claim.appliesTo(path));
84
+ if (hit)
85
+ block.add(claim, 'path', hit);
86
+ }
87
+ for (const near of await this._nearby(scope, change, block)) {
88
+ block.add(near.claim, 'proximity', near.path);
89
+ }
90
+ }
91
+ /**
92
+ * The repository claims nearest the hunks, best first.
93
+ *
94
+ * Ranked across the whole scope and capped there, rather than per file: ten
95
+ * files that all touch the same service should not each contribute their own
96
+ * third-best match.
97
+ */
98
+ async _nearby(scope, change, block) {
99
+ const files = Recall._queryable(change.files, this._limits.files);
100
+ // One search per file, a few at a time. Each failure is caught by _safe,
101
+ // so addAll never rejects and one bad file costs only its own claims.
102
+ const queue = new PQueue({ concurrency: Recall._PARALLEL });
103
+ const found = await queue.addAll(files.map((file) => () => this._safe(`claims near ${file.path}`, () => this._knowledge.search(Recall._query(file), scope, {
104
+ topK: this._limits.perFile,
105
+ threshold: this._limits.threshold,
106
+ }))));
107
+ const seen = new Set();
108
+ return files
109
+ .flatMap((file, i) => (found[i] ?? []).map((claim) => ({ claim, path: file.path })))
110
+ .filter(({ claim }) => {
111
+ // The floor is applied here as well as passed to the backend. One of
112
+ // the two adapters forwards it to a vector store and the other hands
113
+ // it to a hosted API, and a floor that is only a request is not a
114
+ // floor — this is the number `weigh context recall` is calibrated
115
+ // against, so it has to mean the same thing on both. A hit with no
116
+ // score at all is kept: that is a backend reporting nothing, not a
117
+ // claim scoring zero.
118
+ if (claim.score !== undefined && claim.score < this._limits.threshold)
119
+ return false;
120
+ const key = claim.id ?? claim.statement;
121
+ // Deduped before the cap, not after: the same claim found by four
122
+ // files must not spend four of the ten places.
123
+ if (seen.has(key) || block.has(claim))
124
+ return false;
125
+ seen.add(key);
126
+ return true;
127
+ })
128
+ .sort((a, b) => (b.claim.score ?? 0) - (a.claim.score ?? 0))
129
+ .slice(0, this._limits.repoCap);
130
+ }
131
+ /**
132
+ * Target scope: the thread on this change, listed in full.
133
+ *
134
+ * Uncapped and unsearched. This is where a human's correction lives, and a
135
+ * cosine score is a poor thing to stake "did the reviewer see that you said
136
+ * this was deliberate" on.
137
+ */
138
+ async _thread(block, change) {
139
+ // A detached HEAD has no branch, and the thread is keyed to one: there is
140
+ // nothing that makes a claim belong to this change rather than another.
141
+ if (!change.branch)
142
+ return;
143
+ const scope = Scope.target(change.target, change.branch);
144
+ for (const claim of await this._safe('what was said about this change', () => this._knowledge.list(scope))) {
145
+ block.add(claim, 'listed');
146
+ }
147
+ }
148
+ /**
149
+ * User scope: small, and always in.
150
+ *
151
+ * Read wide and filtered here, because user scope is the one scope that
152
+ * filters on nothing narrower than the user — a list at that scope answers
153
+ * with every repository's claims as well, which would put another project's
154
+ * conventions in front of this review under the heading of how you work.
155
+ * What belongs in this block is what was written with no scope at all.
156
+ */
157
+ async _reviewer(block) {
158
+ const everything = await this._safe('how you review', () => this._knowledge.list(Scope.user(), this._limits.scan));
159
+ const mine = everything.filter((claim) => !claim.scope);
160
+ if (everything.length >= this._limits.scan && mine.length < this._limits.userCap) {
161
+ this._onWarn?.(`read the first ${this._limits.scan} memories looking for what holds everywhere; there may be more (WEIGH_KNOWLEDGE_SCAN)`);
162
+ }
163
+ for (const claim of mine.slice(0, this._limits.userCap))
164
+ block.add(claim, 'listed');
165
+ }
166
+ /**
167
+ * The changed files worth embedding: code first, and the biggest change
168
+ * within each group.
169
+ *
170
+ * A deleted file still carries signal — the code that went is as much a clue
171
+ * to what this change is about as the code that arrived — but a binary has
172
+ * nothing to embed and a lockfile embeds to nothing useful.
173
+ *
174
+ * Size alone would be the wrong order. A README rewritten in one sitting is
175
+ * four hundred changed lines of prose that no claim is phrased in, and it
176
+ * would take a query slot from the six-line change to the service the claims
177
+ * are actually about. So the comparison by size happens inside a group and
178
+ * never across one, and the files most likely to sit near a claim are the
179
+ * ones that survive the cap.
180
+ */
181
+ static _queryable(files, cap) {
182
+ return files
183
+ .filter((file) => !file.binary && file.hunks.length > 0 && !looksGenerated(file.path))
184
+ .sort((a, b) => Recall._group(a.path) - Recall._group(b.path) || Recall._churn(b) - Recall._churn(a))
185
+ .slice(0, cap);
186
+ }
187
+ /** 0 for code, 1 for the prose and data around it. */
188
+ static _group(path) {
189
+ return PROSE_OR_DATA.test(path) ? 1 : 0;
190
+ }
191
+ /** How much of the file this change touched. */
192
+ static _churn(file) {
193
+ return file.additions + file.deletions;
194
+ }
195
+ /**
196
+ * One file's change as a query.
197
+ *
198
+ * Diff markers and hunk headers come off: `@@ -1,7 +1,9 @@` is noise in an
199
+ * embedding, and a leading `+` makes two copies of the same line of code look
200
+ * like two different strings. The path leads, because it is weak signal that
201
+ * costs nothing beside the code.
202
+ */
203
+ static _query(file) {
204
+ const lines = [];
205
+ for (const hunk of file.hunks) {
206
+ for (const line of hunk.text.split('\n')) {
207
+ if (line.startsWith('@@') || line.startsWith('+++') || line.startsWith('---'))
208
+ continue;
209
+ const code = line.replace(/^[+\- ]/, '').trim();
210
+ if (code)
211
+ lines.push(code);
212
+ }
213
+ }
214
+ return [file.path, ...lines].join('\n').slice(0, QUERY_CHARS);
215
+ }
216
+ /** How many searches a recall has in flight at once. */
217
+ static _PARALLEL = 8;
218
+ /** A read that costs the review its context rather than its run. */
219
+ async _safe(what, read) {
220
+ try {
221
+ return await read();
222
+ }
223
+ catch (err) {
224
+ this._onWarn?.(`could not recall ${what} — ${err?.message ?? err}`);
225
+ return [];
226
+ }
227
+ }
228
+ }
229
+ //# sourceMappingURL=recall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recall.js","sourceRoot":"","sources":["../../src/knowledge/recall.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAsCzC,gEAAgE;AAChE,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B;;;;;;GAMG;AACH,MAAM,aAAa,GACjB,+HAA+H,CAAC;AAElI;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,MAAM;IAEE,UAAU;IACV,OAAO;IACP,OAAO;IAH1B,YACmB,UAAqB,EACrB,OAAqB,EACrB,OAAmC;0BAFnC,UAAU;uBACV,OAAO;uBACP,OAAO;IACvB,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,MAAyB;QACjC,MAAM,IAAI,GAAG,IAAI,cAAc,CAC7B,iBAAiB,EACjB,mEAAmE,EACnE,CAAC,CACF,CAAC;QACF,MAAM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K,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;oBAAE,SAAS;gBACxF,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;gBAChD,IAAI,IAAI;oBAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;IAED,wDAAwD;IAChD,MAAM,CAAU,SAAS,GAAG,CAAC,CAAC;IAEtC,oEAAoE;IAC5D,KAAK,CAAC,KAAK,CAAC,IAAY,EAAE,IAA4B;QAC5D,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,EAAE,CAAC;QACtB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,OAAO,EAAE,CAAC,oBAAoB,IAAI,MAAM,GAAG,EAAE,OAAO,IAAI,GAAG,EAAE,CAAC,CAAC;YACpE,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,35 @@
1
+ import type { Claim } from './claim.js';
2
+ /** Why a claim is in front of the reviewer. Printed beside it. */
3
+ export type Mechanism = 'always' | 'path' | 'proximity' | 'listed';
4
+ /**
5
+ * One claim on its way into a review, and how it got there.
6
+ *
7
+ * The mechanism is kept because it is the difference between a guarantee and a
8
+ * guess: a claim that is in because its glob names the file under review is
9
+ * worth more than one that scored well against a hunk, and a reader calibrating
10
+ * the retrieval has no way to tell those apart afterwards otherwise.
11
+ */
12
+ export declare class RecalledClaim {
13
+ readonly claim: Claim;
14
+ readonly mechanism: Mechanism;
15
+ /** The changed file that pulled it in, for `path` and `proximity`. */
16
+ readonly because: string | undefined;
17
+ constructor(claim: Claim, mechanism: Mechanism,
18
+ /** The changed file that pulled it in, for `path` and `proximity`. */
19
+ because?: string | undefined);
20
+ /** The key a block dedupes on: four mechanisms can find the same claim. */
21
+ get key(): string;
22
+ /** The claim as the model reads it: the sentence, then why it is here. */
23
+ describe(): string[];
24
+ /**
25
+ * Why this claim is here, in words.
26
+ *
27
+ * Empty for a claim that was listed rather than found: its block says where
28
+ * it came from, and "it was in the list" is not a reason worth a line.
29
+ */
30
+ why(): string;
31
+ toJSON(): Record<string, unknown>;
32
+ /** One line for the calibration view, where the score is the point. */
33
+ explain(): string;
34
+ }
35
+ //# sourceMappingURL=recalled-claim.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recalled-claim.d.ts","sourceRoot":"","sources":["../../src/knowledge/recalled-claim.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,kEAAkE;AAClE,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;AAEnE;;;;;;;GAOG;AACH,qBAAa,aAAa;IAEtB,QAAQ,CAAC,KAAK,EAAE,KAAK;IACrB,QAAQ,CAAC,SAAS,EAAE,SAAS;IAC7B,sEAAsE;IACtE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;IAJtC,YACW,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,SAAS;IAC7B,sEAAsE;IAC7D,OAAO,GAAE,MAAM,GAAG,SAAqB,EAC9C;IAEJ,2EAA2E;IAC3E,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,0EAA0E;IAC1E,QAAQ,IAAI,MAAM,EAAE,CAMnB;IAED;;;;;OAKG;IACH,GAAG,IAAI,MAAM,CAWZ;IAED,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMhC;IAED,uEAAuE;IACvE,OAAO,IAAI,MAAM,CAIhB;CACF"}
@@ -0,0 +1,67 @@
1
+ // This Source Code Form is subject to the terms of the Mozilla Public
2
+ // License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
+ /**
5
+ * One claim on its way into a review, and how it got there.
6
+ *
7
+ * The mechanism is kept because it is the difference between a guarantee and a
8
+ * guess: a claim that is in because its glob names the file under review is
9
+ * worth more than one that scored well against a hunk, and a reader calibrating
10
+ * the retrieval has no way to tell those apart afterwards otherwise.
11
+ */
12
+ export class RecalledClaim {
13
+ claim;
14
+ mechanism;
15
+ because;
16
+ constructor(claim, mechanism,
17
+ /** The changed file that pulled it in, for `path` and `proximity`. */
18
+ because = undefined) {
19
+ this.claim = claim;
20
+ this.mechanism = mechanism;
21
+ this.because = because;
22
+ }
23
+ /** The key a block dedupes on: four mechanisms can find the same claim. */
24
+ get key() {
25
+ return this.claim.id ?? this.claim.statement;
26
+ }
27
+ /** The claim as the model reads it: the sentence, then why it is here. */
28
+ describe() {
29
+ const meta = [this.why(), `confidence ${this.claim.confidence.toFixed(2)}`].filter(Boolean).join(' · ');
30
+ return [
31
+ `- ${this.claim.kind}: ${this.claim.statement}`,
32
+ ` ${meta} · checkable at ${this.claim.evidence.join(', ')}`,
33
+ ];
34
+ }
35
+ /**
36
+ * Why this claim is here, in words.
37
+ *
38
+ * Empty for a claim that was listed rather than found: its block says where
39
+ * it came from, and "it was in the list" is not a reason worth a line.
40
+ */
41
+ why() {
42
+ switch (this.mechanism) {
43
+ case 'always':
44
+ return 'holds everywhere in this repository';
45
+ case 'path':
46
+ return `governs ${this.because ?? 'files in this change'}`;
47
+ case 'proximity':
48
+ return `related to ${this.because ?? 'this change'}`;
49
+ case 'listed':
50
+ return '';
51
+ }
52
+ }
53
+ toJSON() {
54
+ return {
55
+ ...this.claim.toJSON(),
56
+ mechanism: this.mechanism,
57
+ ...(this.because && { because: this.because }),
58
+ };
59
+ }
60
+ /** One line for the calibration view, where the score is the point. */
61
+ explain() {
62
+ const score = this.claim.score !== undefined ? ` · score ${this.claim.score.toFixed(3)}` : '';
63
+ const why = this.why();
64
+ return ` [${this.mechanism}]${score}${why ? ` · ${why}` : ''}`;
65
+ }
66
+ }
67
+ //# sourceMappingURL=recalled-claim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recalled-claim.js","sourceRoot":"","sources":["../../src/knowledge/recalled-claim.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAO5D;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;IAEb,KAAK;IACL,SAAS;IAET,OAAO;IAJlB,YACW,KAAY,EACZ,SAAoB;IAC7B,sEAAsE;IAC7D,OAAO,GAAuB,SAAS;qBAHvC,KAAK;yBACL,SAAS;uBAET,OAAO;IACf,CAAC;IAEJ,2EAA2E;IAC3E,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;IAC/C,CAAC;IAED,0EAA0E;IAC1E,QAAQ;QACN,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,cAAc,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxG,OAAO;YACL,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;YAC/C,KAAK,IAAI,mBAAmB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;SAC7D,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,GAAG;QACD,QAAQ,IAAI,CAAC,SAAS,EAAE,CAAC;YACvB,KAAK,QAAQ;gBACX,OAAO,qCAAqC,CAAC;YAC/C,KAAK,MAAM;gBACT,OAAO,WAAW,IAAI,CAAC,OAAO,IAAI,sBAAsB,EAAE,CAAC;YAC7D,KAAK,WAAW;gBACd,OAAO,cAAc,IAAI,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;YACvD,KAAK,QAAQ;gBACX,OAAO,EAAE,CAAC;QACd,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO;YACL,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACtB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;SAC/C,CAAC;IACJ,CAAC;IAED,uEAAuE;IACvE,OAAO;QACL,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,YAAY,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9F,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,OAAO,MAAM,IAAI,CAAC,SAAS,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAClE,CAAC;CACF"}
@@ -0,0 +1,70 @@
1
+ import type { KnowledgeBlock } from './block.js';
2
+ /**
3
+ * What reaches one review, in the blocks it is read in.
4
+ *
5
+ * The point of this is a finding that is never born. A convention has to be in
6
+ * the context before the model forms a view of the change, or the finding is
7
+ * produced every run and killed at refute — which costs a call, reads as noise,
8
+ * and teaches nobody anything. So what Weigh knows about the repository goes
9
+ * in with the diff.
10
+ *
11
+ * The blocks arrive already filled; this owns the budget over them. What does
12
+ * not fit is named in its block rather than dropped quietly, which is the rule
13
+ * the coverage ledger already follows: a review that was shown eleven of
14
+ * nineteen claims should say so, because the eight it did not see are exactly
15
+ * the ones that would explain a finding it got wrong.
16
+ */
17
+ export declare class Recalled {
18
+ private readonly _blocks;
19
+ constructor(_blocks: readonly KnowledgeBlock[],
20
+ /** Characters of claims to inline. The block's own budget, like the diff's. */
21
+ budget: number);
22
+ /** The blocks in reading order, those with something in them. */
23
+ get blocks(): readonly KnowledgeBlock[];
24
+ /** Claims found, whether or not they fit. */
25
+ get size(): number;
26
+ get isEmpty(): boolean;
27
+ /** How many were found and left out of the prompt. */
28
+ get dropped(): number;
29
+ /** One line for the progress reporter, before the review starts. */
30
+ describe(): string;
31
+ /**
32
+ * Spends the budget in priority order, not in reading order.
33
+ *
34
+ * The thread on this change is filled first and is never capped: a
35
+ * correction that fell off the end of a budget would be a defect silenced by
36
+ * accident, which is worse than a review that runs with no memory at all.
37
+ * Everything else takes what is left, in the order the blocks declare.
38
+ */
39
+ private _fit;
40
+ /**
41
+ * The part of the reviewer's instructions that only applies when something
42
+ * was recalled.
43
+ *
44
+ * Four sentences do the work. The first is why the claims are there at all:
45
+ * a change that follows a convention this repository holds is not a finding.
46
+ * The second is the one promotion rests on, and it was added after watching a
47
+ * review read a promoted claim and report the finding anyway, in a weaker
48
+ * form — it had been told that the precondition holds elsewhere, and reported
49
+ * the code for not checking it again. A claim that answers a finding has to
50
+ * answer the class of it, or promotion buys a reworded finding rather than no
51
+ * finding. The third is the escape hatch, because knowledge goes stale
52
+ * silently and a reviewer that trusts a stale claim over the code in front of
53
+ * it produces the most confusing kind of false positive. The fourth keeps the
54
+ * citation rule intact: a claim is context, never the evidence a finding rests
55
+ * on.
56
+ */
57
+ instructions(): string;
58
+ /** The blocks as the model receives them, above the change. */
59
+ render(): string;
60
+ toJSON(): Record<string, unknown>;
61
+ /**
62
+ * The same claims with their scores, for calibrating the retrieval.
63
+ *
64
+ * The caps and the threshold are numbers nobody can pick honestly from a
65
+ * design document, so this prints what came back and why: twenty real claims
66
+ * about a repository you know, run against a branch you know, and read it.
67
+ */
68
+ explain(): string;
69
+ }
70
+ //# sourceMappingURL=recalled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recalled.d.ts","sourceRoot":"","sources":["../../src/knowledge/recalled.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,QAAQ;IAEjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAD1B,YACmB,OAAO,EAAE,SAAS,cAAc,EAAE;IACnD,+EAA+E;IAC/E,MAAM,EAAE,MAAM,EAGf;IAED,iEAAiE;IACjE,IAAI,MAAM,IAAI,SAAS,cAAc,EAAE,CAEtC;IAED,6CAA6C;IAC7C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,sDAAsD;IACtD,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,oEAAoE;IACpE,QAAQ,IAAI,MAAM,CAIjB;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,IAAI;IAcZ;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,IAAI,MAAM,CAgBrB;IAED,+DAA+D;IAC/D,MAAM,IAAI,MAAM,CAgBf;IAED,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOhC;IAED;;;;;;OAMG;IACH,OAAO,IAAI,MAAM,CAWhB;CACF"}