@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
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
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
+ * Library entry point.
6
+ *
7
+ * import { loadConfig, runAgent } from '@afaik-lab/weigh';
8
+ *
9
+ * const config = loadConfig({ maxSteps: 10 });
10
+ * const { text } = await runAgent(config, 'What is in this repo?');
11
+ */
12
+ export { runAgent, runAgentWithRetry } from './agent.js';
13
+ export { loadConfig } from './config.js';
14
+ export { paths, weighHome, ensureDir } from './paths.js';
15
+ export { loadWeighEnv, parseEnvFile, loadConfigDetailed } from './config.js';
16
+ export { SETTINGS, OWNED_ENV_KEYS, isOwnedEnvKey } from './settings.js';
17
+ export { runConfigCommand, isConfigVerb } from './config-cli.js';
18
+ export { runDoctor } from './doctor.js';
19
+ export { READ_ONLY_TOOLS, WITHHELD_TOOLS, ToolGuard } from './tools/index.js';
20
+ export { confine, display, describeArgs } from './tools/root.js';
21
+ export { harnessOptions } from './harness.js';
22
+ export { resolveTarget } from './target.js';
23
+ export { MODELS, FLOATING, ModelCatalogue, resolveModel, describeModels, refreshCatalogue, isStale, STALE_AFTER_MS } from './models.js';
24
+ export { runModelsCommand } from './models-cli.js';
25
+ export { SEVERITIES, SEVERITY_ORDER, VERDICTS, Verdict, CATEGORIES, reportedFindingSchema, reviewOutputSchema, DECISIONS, GROUNDS, rulingSchema, refuteOutputSchema, strictJsonSchema, evidenceSchema, CodeAnchor, Finding, FindingSet, WorkspaceFiles, StaticFiles, } from './findings.js';
26
+ export { readProfile } from './profile.js';
27
+ export { buildContext, renderContext } from './context.js';
28
+ export { ReviewCommand, runReviewCommand } from './review-cli.js';
29
+ export { Reviewer, CoverageLedger, ReviewOutputParser } from './reviewer.js';
30
+ export { RECORD_VERSION, ReviewRecord, ReviewStore, StoredReview, reviewRecordSchema } from './record/index.js';
31
+ export { RECONCILED, Outcome, Reconciliation, outcomeSchema, reconciledSchema } from './reconcile/index.js';
32
+ export { RefuteBrief, RefuteOutcome, Refuter, RulingSet } from './refute.js';
33
+ export { Ceilings } from './ceilings.js';
34
+ export { Spend } from './usage.js';
35
+ export { writeOut } from './stdout.js';
36
+ export { Palette, ReviewRenderer, wrap, packSegments, ellipsise } from './render.js';
37
+ export { ProgressReporter } from './progress.js';
38
+ export { collectDiff, defaultBase, workingState } from './diff.js';
39
+ export { createWorkspace } from './workspace.js';
40
+ export { initSessionDir, loadSession, saveMessage, listSessions, newSessionPath, sessionId, summarizeSessions, pruneSessions, } from './session.js';
41
+ export { KINDS, SOURCES, Claim, Knowledge, KnowledgeBlock, Recall, Recalled, RecalledClaim, claimInputSchema, claimMetadataSchema, } from './knowledge/index.js';
42
+ export { isContextVerb, runContextCommand, CONTEXT_VERBS } from './context-cli.js';
43
+ // What a human said about a finding
44
+ export { CORRECTION_LABELS, CORRECTION_VERSION, LABEL_RULES, Correction, CorrectionSet, Corrections, FollowUp, Promotion, correctionSchema, } from './corrections/index.js';
45
+ export { FollowUpCommand, runFollowUpCommand } from './follow-up-cli.js';
46
+ export { isCorrectionVerb, runCorrectionsCommand, CORRECTION_VERBS } from './corrections-cli.js';
47
+ export { repoSlug } from './target.js';
48
+ export { Scope } from './memory/scope.js';
49
+ // Memory
50
+ export { createMemoryStore, resolveScope, recall, capture, formatMemories, NullMemoryStore, PlatformMemoryStore, OssMemoryStore, } from './memory/index.js';
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D;;;;;;;GAOG;AACH,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE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,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEjG,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,SAAS;AACT,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,MAAM,EACN,OAAO,EACP,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,cAAc,GACf,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { Claim } from './claim.js';
2
+ import { RecalledClaim, type Mechanism } from './recalled-claim.js';
3
+ /**
4
+ * One labelled block of what Weigh knows, and the claims in it.
5
+ *
6
+ * The blocks exist because the facts are different in kind. What a repository
7
+ * is like, what has been said about this change, and how a particular person
8
+ * reviews are three different warrants, and a flat list invites the model to
9
+ * read a personal preference as a repository invariant. Keeping them apart also
10
+ * disposes of a problem that would otherwise need solving: three searches
11
+ * produce three score sets computed over different candidate pools, so nothing
12
+ * here is ever ranked against anything from another block.
13
+ */
14
+ export declare class KnowledgeBlock {
15
+ /** The heading the model reads. */
16
+ readonly label: string;
17
+ /** One line under it saying what kind of fact this is. */
18
+ readonly note: string;
19
+ /**
20
+ * Which block gets the budget first.
21
+ *
22
+ * Lower goes first. The thread on this change leads, because a correction
23
+ * that does not reach the model is the silent failure this whole loop
24
+ * exists to prevent.
25
+ */
26
+ readonly priority: number;
27
+ private readonly _found;
28
+ private readonly _seen;
29
+ /** How many entries fit the budget. All of them until `Recalled` says less. */
30
+ private _kept;
31
+ constructor(
32
+ /** The heading the model reads. */
33
+ label: string,
34
+ /** One line under it saying what kind of fact this is. */
35
+ note: string,
36
+ /**
37
+ * Which block gets the budget first.
38
+ *
39
+ * Lower goes first. The thread on this change leads, because a correction
40
+ * that does not reach the model is the silent failure this whole loop
41
+ * exists to prevent.
42
+ */
43
+ priority: number);
44
+ /**
45
+ * Adds a claim, unless this block already has it.
46
+ *
47
+ * Four mechanisms can find the same claim, and the first one to find it is
48
+ * the one worth printing: "this is a rule of the house" is a better reason
49
+ * than "it scored 0.61 against a hunk".
50
+ */
51
+ add(claim: Claim, mechanism: Mechanism, because?: string): void;
52
+ has(claim: Claim): boolean;
53
+ get size(): number;
54
+ get isEmpty(): boolean;
55
+ /** Everything found, budget or no budget. What calibration reads. */
56
+ get found(): readonly RecalledClaim[];
57
+ /** The claims that fit. */
58
+ get kept(): readonly RecalledClaim[];
59
+ /** How many were found and left out. Named in the block, never dropped silently. */
60
+ get dropped(): number;
61
+ /** Called once by `Recalled`, which owns the budget. */
62
+ keep(count: number): void;
63
+ toJSON(): Record<string, unknown>;
64
+ }
65
+ //# sourceMappingURL=block.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../src/knowledge/block.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEpE;;;;;;;;;;GAUG;AACH,qBAAa,cAAc;IAOvB,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAjB3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,+EAA+E;IAC/E,OAAO,CAAC,KAAK,CAAqB;IAElC;IACE,mCAAmC;IAC1B,KAAK,EAAE,MAAM;IACtB,0DAA0D;IACjD,IAAI,EAAE,MAAM;IACrB;;;;;;OAMG;IACM,QAAQ,EAAE,MAAM,EACvB;IAEJ;;;;;;OAMG;IACH,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAK9D;IAED,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEzB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,qEAAqE;IACrE,IAAI,KAAK,IAAI,SAAS,aAAa,EAAE,CAEpC;IAED,2BAA2B;IAC3B,IAAI,IAAI,IAAI,SAAS,aAAa,EAAE,CAEnC;IAED,oFAAoF;IACpF,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,wDAAwD;IACxD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAExB;IAED,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOhC;CACF"}
@@ -0,0 +1,89 @@
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 { RecalledClaim } from './recalled-claim.js';
5
+ /**
6
+ * One labelled block of what Weigh knows, and the claims in it.
7
+ *
8
+ * The blocks exist because the facts are different in kind. What a repository
9
+ * is like, what has been said about this change, and how a particular person
10
+ * reviews are three different warrants, and a flat list invites the model to
11
+ * read a personal preference as a repository invariant. Keeping them apart also
12
+ * disposes of a problem that would otherwise need solving: three searches
13
+ * produce three score sets computed over different candidate pools, so nothing
14
+ * here is ever ranked against anything from another block.
15
+ */
16
+ export class KnowledgeBlock {
17
+ label;
18
+ note;
19
+ priority;
20
+ _found = [];
21
+ _seen = new Set();
22
+ /** How many entries fit the budget. All of them until `Recalled` says less. */
23
+ _kept;
24
+ constructor(
25
+ /** The heading the model reads. */
26
+ label,
27
+ /** One line under it saying what kind of fact this is. */
28
+ note,
29
+ /**
30
+ * Which block gets the budget first.
31
+ *
32
+ * Lower goes first. The thread on this change leads, because a correction
33
+ * that does not reach the model is the silent failure this whole loop
34
+ * exists to prevent.
35
+ */
36
+ priority) {
37
+ this.label = label;
38
+ this.note = note;
39
+ this.priority = priority;
40
+ }
41
+ /**
42
+ * Adds a claim, unless this block already has it.
43
+ *
44
+ * Four mechanisms can find the same claim, and the first one to find it is
45
+ * the one worth printing: "this is a rule of the house" is a better reason
46
+ * than "it scored 0.61 against a hunk".
47
+ */
48
+ add(claim, mechanism, because) {
49
+ const entry = new RecalledClaim(claim, mechanism, because);
50
+ if (this._seen.has(entry.key))
51
+ return;
52
+ this._seen.add(entry.key);
53
+ this._found.push(entry);
54
+ }
55
+ has(claim) {
56
+ return this._seen.has(claim.id ?? claim.statement);
57
+ }
58
+ get size() {
59
+ return this._found.length;
60
+ }
61
+ get isEmpty() {
62
+ return this._found.length === 0;
63
+ }
64
+ /** Everything found, budget or no budget. What calibration reads. */
65
+ get found() {
66
+ return this._found;
67
+ }
68
+ /** The claims that fit. */
69
+ get kept() {
70
+ return this._found.slice(0, this._kept ?? this._found.length);
71
+ }
72
+ /** How many were found and left out. Named in the block, never dropped silently. */
73
+ get dropped() {
74
+ return this._found.length - this.kept.length;
75
+ }
76
+ /** Called once by `Recalled`, which owns the budget. */
77
+ keep(count) {
78
+ this._kept = Math.max(0, Math.min(count, this._found.length));
79
+ }
80
+ toJSON() {
81
+ return {
82
+ label: this.label,
83
+ claims: this._found.map((entry) => entry.toJSON()),
84
+ kept: this.kept.length,
85
+ dropped: this.dropped,
86
+ };
87
+ }
88
+ }
89
+ //# sourceMappingURL=block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block.js","sourceRoot":"","sources":["../../src/knowledge/block.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAG5D,OAAO,EAAE,aAAa,EAAkB,MAAM,qBAAqB,CAAC;AAEpE;;;;;;;;;;GAUG;AACH,MAAM,OAAO,cAAc;IAQd,KAAK;IAEL,IAAI;I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;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC/C,CAAC;IAED,wDAAwD;IACxD,IAAI,CAAC,KAAa;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,MAAM;QACJ,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YAClD,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;YACtB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,143 @@
1
+ import type { MemoryRecord } from '../memory/index.js';
2
+ import { type ClaimMetadata, type ClaimSource, type Kind } from './schema.js';
3
+ /**
4
+ * One thing that is true of a repository.
5
+ *
6
+ * Stored as a memory whose text is what a search has to match against, with
7
+ * everything that makes it checkable in the metadata beside it. The text is
8
+ * therefore built for retrieval rather than for reading: the statement, the
9
+ * kind, and the paths the claim cites, because a change's meaning lives in its
10
+ * code and its files rather than in prose about them. The statement is read
11
+ * back out of the metadata, which leaves the text free to be tuned.
12
+ */
13
+ export declare class Claim {
14
+ readonly kind: Kind;
15
+ readonly statement: string;
16
+ readonly evidence: readonly string[];
17
+ /**
18
+ * Globs this claim governs, or `['*']` for a rule of the house.
19
+ *
20
+ * Empty is the common case and means "found by similarity alone". The
21
+ * marker is deliberate rather than a default because unglobbed-means-always
22
+ * does not survive a store with a few hundred claims in it — while a writer
23
+ * who forgets the marker still gets found by proximity, which is a claim
24
+ * arriving late rather than a claim going missing.
25
+ */
26
+ readonly applies: readonly string[];
27
+ readonly confidence: number;
28
+ readonly source: ClaimSource;
29
+ readonly at: string;
30
+ readonly commit: string | undefined;
31
+ /** The store's own id, on a claim that was read back. */
32
+ readonly id: string | undefined;
33
+ /** Relevance, on a claim that came back from a search. */
34
+ readonly score: number | undefined;
35
+ /**
36
+ * The scope it was stored under, on a claim that was read back.
37
+ *
38
+ * Absent means it was written with no scope at all — what holds wherever
39
+ * this reviewer is working. Kept because a read at user scope filters on
40
+ * the user and nothing narrower, so it answers with every repository's
41
+ * claims too, and only the record itself says which it is.
42
+ */
43
+ readonly scope: string | undefined;
44
+ /** When the claim was last found to still hold, and at which commit. */
45
+ readonly verified: {
46
+ commit: string;
47
+ at: string;
48
+ } | undefined;
49
+ /**
50
+ * How close it is in meaning alone, on a claim that came back from a
51
+ * search, when the backend says. `score` may blend in keyword matches and
52
+ * is scaled by what else the search found, so it cannot be held to a fixed
53
+ * floor; this can.
54
+ */
55
+ readonly similarity: number | undefined;
56
+ /** Compiled `applies` globs, built once per claim and only if asked for. */
57
+ private _globs;
58
+ private constructor();
59
+ /**
60
+ * Validates what a writer supplied and fills in what it left out.
61
+ *
62
+ * Throws rather than coercing: this is the one gate between a priming agent
63
+ * and the store, and a claim that is wrong about its own shape is the kind of
64
+ * thing that is only noticed months later, in a review that reads strangely.
65
+ *
66
+ * `head` is the commit the repository was at when the claim was written,
67
+ * used when the writer names none. It is what tells a claim that went stale
68
+ * from one that never held: the code it cites can be read at that commit.
69
+ */
70
+ static parse(data: unknown, now?: Date, head?: string): Claim;
71
+ /**
72
+ * A stored memory read back as a claim, or nothing when it is not one.
73
+ *
74
+ * The store holds more than claims — the prompt path has been writing
75
+ * whatever it learned about its user into the same backend — so the metadata
76
+ * carries a marker and anything without it is left alone rather than
77
+ * guessed at.
78
+ */
79
+ static fromRecord(record: MemoryRecord): Claim | undefined;
80
+ /**
81
+ * This claim, found to still hold at `commit`.
82
+ *
83
+ * What a refresh records about a claim it read again and kept, so the next
84
+ * refresh does not read it again unless its files change after this.
85
+ */
86
+ verifiedAt(commit: string, now?: Date): Claim;
87
+ /**
88
+ * The commit this claim was last known to hold at: when it was last
89
+ * verified, else when it was written. A change to its files after this is
90
+ * what makes it worth reading again.
91
+ */
92
+ get knownAt(): string | undefined;
93
+ /** The files the evidence cites, without their line ranges. */
94
+ get cites(): string[];
95
+ /**
96
+ * Whether this claim is about anything under `prefix`, a path relative to
97
+ * the repository root.
98
+ *
99
+ * It is when it cites a file there, or when one of its globs could match a
100
+ * file there. A glob is compared by its literal head, the part before the
101
+ * first wildcard: `src/**` is about `src/knowledge`, and so is a house rule,
102
+ * which is about everything.
103
+ */
104
+ touches(prefix: string): boolean;
105
+ private static _normalise;
106
+ /** `src/knowledge/**` → `src/knowledge`; `*` → ``. */
107
+ private static _literalHead;
108
+ /**
109
+ * The statement recovered from the stored text, for a record written before
110
+ * the statement was kept in the metadata. Takes the first line and strips the
111
+ * kind prefix; the evidence paths below it are not part of the sentence.
112
+ */
113
+ private static statementOf;
114
+ /** A rule of the house: in every review of this repository, unsearched. */
115
+ get isHouseRule(): boolean;
116
+ /**
117
+ * Whether this claim governs a path.
118
+ *
119
+ * A guarantee rather than a ranking: a claim whose glob names the file under
120
+ * review reaches the review whatever a similarity score would have said
121
+ * about it. A double star crosses directories, a single one and `?` do not,
122
+ * and `{a,b}` is expanded — enough to write a glob over nested TypeScript
123
+ * sources and no more.
124
+ */
125
+ appliesTo(path: string): boolean;
126
+ /** `a/{b,c}.ts` as the two globs it stands for. */
127
+ private static _expand;
128
+ private static _pattern;
129
+ /**
130
+ * What the store holds as the memory itself, and embeds.
131
+ *
132
+ * The paths are here because this string is the only part of a claim a
133
+ * vector search can see. A claim about an auth service embeds closer to a
134
+ * hunk that touches auth files when the file names travel with the sentence,
135
+ * and nothing is lost by it: the statement is read back from the metadata.
136
+ */
137
+ text(): string;
138
+ metadata(): ClaimMetadata;
139
+ toJSON(): Record<string, unknown>;
140
+ /** One claim as `weigh context` prints it. */
141
+ describe(): string;
142
+ }
143
+ //# sourceMappingUR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AM,GAAG,KAAK,CAkBxE;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,KAAK,GAAG,SAAS,CAmBzD;IAED;;;;;OAKG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,KAAK,CAgBxD;IAED;;;;OAIG;IACH,IAAI,OAAO,IAAI,MAAM,GAAG,SAAS,CAEhC;IAED,+DAA+D;IAC/D,IAAI,KAAK,IAAI,MAAM,EAAE,CAEpB;IAED;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAO/B;IAED,OAAO,CAAC,MAAM,CAAC,UAAU;IAIzB,sDAAsD;IACtD,OAAO,CAAC,MAAM,CAAC,YAAY;IAS3B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAM1B,2EAA2E;IAC3E,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED;;;;;;;;OAQG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI/B;IAED,mDAAmD;IACnD,OAAO,CAAC,MAAM,CAAC,OAAO;IAYtB,OAAO,CAAC,MAAM,CAAC,QAAQ;IA4BvB;;;;;;;OAOG;IACH,IAAI,IAAI,MAAM,CAEb;IAED,QAAQ,IAAI,aAAa,CAaxB;IAED,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAahC;IAED,8CAA8C;IAC9C,QAAQ,IAAI,MAAM,CAYjB;CACF"}
@@ -0,0 +1,297 @@
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 { claimInputSchema, claimMetadataSchema } from './schema.js';
5
+ /** The confidence a claim gets when its writer offers none. */
6
+ const ASSUMED = 0.7;
7
+ /** `applies` marker for a claim that holds everywhere in the repository. */
8
+ const EVERYWHERE = '*';
9
+ /**
10
+ * One thing that is true of a repository.
11
+ *
12
+ * Stored as a memory whose text is what a search has to match against, with
13
+ * everything that makes it checkable in the metadata beside it. The text is
14
+ * therefore built for retrieval rather than for reading: the statement, the
15
+ * kind, and the paths the claim cites, because a change's meaning lives in its
16
+ * code and its files rather than in prose about them. The statement is read
17
+ * back out of the metadata, which leaves the text free to be tuned.
18
+ */
19
+ export class Claim {
20
+ kind;
21
+ statement;
22
+ evidence;
23
+ applies;
24
+ confidence;
25
+ source;
26
+ at;
27
+ commit;
28
+ id;
29
+ score;
30
+ scope;
31
+ verified;
32
+ similarity;
33
+ /** Compiled `applies` globs, built once per claim and only if asked for. */
34
+ _globs;
35
+ constructor(kind, statement, evidence,
36
+ /**
37
+ * Globs this claim governs, or `['*']` for a rule of the house.
38
+ *
39
+ * Empty is the common case and means "found by similarity alone". The
40
+ * marker is deliberate rather than a default because unglobbed-means-always
41
+ * does not survive a store with a few hundred claims in it — while a writer
42
+ * who forgets the marker still gets found by proximity, which is a claim
43
+ * arriving late rather than a claim going missing.
44
+ */
45
+ applies, confidence, source, at, commit,
46
+ /** The store's own id, on a claim that was read back. */
47
+ id = undefined,
48
+ /** Relevance, on a claim that came back from a search. */
49
+ score = undefined,
50
+ /**
51
+ * The scope it was stored under, on a claim that was read back.
52
+ *
53
+ * Absent means it was written with no scope at all — what holds wherever
54
+ * this reviewer is working. Kept because a read at user scope filters on
55
+ * the user and nothing narrower, so it answers with every repository's
56
+ * claims too, and only the record itself says which it is.
57
+ */
58
+ scope = undefined,
59
+ /** When the claim was last found to still hold, and at which commit. */
60
+ verified = undefined,
61
+ /**
62
+ * How close it is in meaning alone, on a claim that came back from a
63
+ * search, when the backend says. `score` may blend in keyword matches and
64
+ * is scaled by what else the search found, so it cannot be held to a fixed
65
+ * floor; this can.
66
+ */
67
+ similarity = undefined) {
68
+ this.kind = kind;
69
+ this.statement = statement;
70
+ this.evidence = evidence;
71
+ this.applies = applies;
72
+ this.confidence = confidence;
73
+ this.source = source;
74
+ this.at = at;
75
+ this.commit = commit;
76
+ this.id = id;
77
+ this.score = score;
78
+ this.scope = scope;
79
+ this.verified = verified;
80
+ this.similarity = similarity;
81
+ }
82
+ /**
83
+ * Validates what a writer supplied and fills in what it left out.
84
+ *
85
+ * Throws rather than coercing: this is the one gate between a priming agent
86
+ * and the store, and a claim that is wrong about its own shape is the kind of
87
+ * thing that is only noticed months later, in a review that reads strangely.
88
+ *
89
+ * `head` is the commit the repository was at when the claim was written,
90
+ * used when the writer names none. It is what tells a claim that went stale
91
+ * from one that never held: the code it cites can be read at that commit.
92
+ */
93
+ static parse(data, now = new Date(), head) {
94
+ const parsed = claimInputSchema.safeParse(data);
95
+ if (!parsed.success) {
96
+ const issue = parsed.error.issues[0];
97
+ const where = issue?.path.length ? ` at ${issue.path.join('.')}` : '';
98
+ throw new Error(`not a context claim — ${issue?.message ?? 'unrecognised shape'}${where}`);
99
+ }
100
+ const { kind, statement, evidence, applies, confidence, provenance } = parsed.data;
101
+ return new Claim(kind, statement.trim(), evidence, applies ?? [], confidence ?? ASSUMED, provenance?.source ?? 'priming', provenance?.at ?? now.toISOString(), provenance?.commit ?? head);
102
+ }
103
+ /**
104
+ * A stored memory read back as a claim, or nothing when it is not one.
105
+ *
106
+ * The store holds more than claims — the prompt path has been writing
107
+ * whatever it learned about its user into the same backend — so the metadata
108
+ * carries a marker and anything without it is left alone rather than
109
+ * guessed at.
110
+ */
111
+ static fromRecord(record) {
112
+ const parsed = claimMetadataSchema.safeParse(record.metadata);
113
+ if (!parsed.success)
114
+ return undefined;
115
+ const meta = parsed.data;
116
+ return new Claim(meta.kind, meta.statement ?? Claim.statementOf(record.memory, meta.kind), meta.evidence, meta.applies ?? [], meta.confidence, meta.source, meta.at, meta.commit, record.id, record.score, record.runId, meta.verified, record.similarity);
117
+ }
118
+ /**
119
+ * This claim, found to still hold at `commit`.
120
+ *
121
+ * What a refresh records about a claim it read again and kept, so the next
122
+ * refresh does not read it again unless its files change after this.
123
+ */
124
+ verifiedAt(commit, now = new Date()) {
125
+ return new Claim(this.kind, this.statement, this.evidence, this.applies, this.confidence, this.source, this.at, this.commit, this.id, this.score, this.scope, { commit, at: now.toISOString() }, this.similarity);
126
+ }
127
+ /**
128
+ * The commit this claim was last known to hold at: when it was last
129
+ * verified, else when it was written. A change to its files after this is
130
+ * what makes it worth reading again.
131
+ */
132
+ get knownAt() {
133
+ return this.verified?.commit ?? this.commit;
134
+ }
135
+ /** The files the evidence cites, without their line ranges. */
136
+ get cites() {
137
+ return [...new Set(this.evidence.map((one) => one.replace(/:\d+(?:-\d+)?$/, '')).filter(Boolean))];
138
+ }
139
+ /**
140
+ * Whether this claim is about anything under `prefix`, a path relative to
141
+ * the repository root.
142
+ *
143
+ * It is when it cites a file there, or when one of its globs could match a
144
+ * file there. A glob is compared by its literal head, the part before the
145
+ * first wildcard: `src/**` is about `src/knowledge`, and so is a house rule,
146
+ * which is about everything.
147
+ */
148
+ touches(prefix) {
149
+ const under = Claim._normalise(prefix);
150
+ if (!under)
151
+ return true;
152
+ const overlaps = (path) => path === under || path.startsWith(`${under}/`) || under.startsWith(`${path}/`) || path === '';
153
+ if (this.cites.some((path) => path === under || path.startsWith(`${under}/`)))
154
+ return true;
155
+ return this.applies.some((glob) => overlaps(Claim._literalHead(glob)));
156
+ }
157
+ static _normalise(path) {
158
+ return path.replace(/^\.\/+/, '').replace(/\/+$/, '');
159
+ }
160
+ /** `src/knowledge/**` → `src/knowledge`; `*` → ``. */
161
+ static _literalHead(glob) {
162
+ const parts = [];
163
+ for (const part of glob.split('/')) {
164
+ if (/[*?{[]/.test(part))
165
+ break;
166
+ parts.push(part);
167
+ }
168
+ return parts.join('/');
169
+ }
170
+ /**
171
+ * The statement recovered from the stored text, for a record written before
172
+ * the statement was kept in the metadata. Takes the first line and strips the
173
+ * kind prefix; the evidence paths below it are not part of the sentence.
174
+ */
175
+ static statementOf(text, kind) {
176
+ const first = text.split('\n')[0] ?? text;
177
+ const prefix = `${kind}: `;
178
+ return first.startsWith(prefix) ? first.slice(prefix.length) : first;
179
+ }
180
+ /** A rule of the house: in every review of this repository, unsearched. */
181
+ get isHouseRule() {
182
+ return this.applies.includes(EVERYWHERE);
183
+ }
184
+ /**
185
+ * Whether this claim governs a path.
186
+ *
187
+ * A guarantee rather than a ranking: a claim whose glob names the file under
188
+ * review reaches the review whatever a similarity score would have said
189
+ * about it. A double star crosses directories, a single one and `?` do not,
190
+ * and `{a,b}` is expanded — enough to write a glob over nested TypeScript
191
+ * sources and no more.
192
+ */
193
+ appliesTo(path) {
194
+ if (this.isHouseRule)
195
+ return true;
196
+ this._globs ??= this.applies.flatMap((glob) => Claim._expand(glob)).map((glob) => Claim._pattern(glob));
197
+ return this._globs.some((rx) => rx.test(path));
198
+ }
199
+ /** `a/{b,c}.ts` as the two globs it stands for. */
200
+ static _expand(glob) {
201
+ const open = glob.indexOf('{');
202
+ const close = open === -1 ? -1 : glob.indexOf('}', open);
203
+ if (open === -1 || close === -1)
204
+ return [glob];
205
+ const head = glob.slice(0, open);
206
+ const tail = glob.slice(close + 1);
207
+ return glob
208
+ .slice(open + 1, close)
209
+ .split(',')
210
+ .flatMap((one) => Claim._expand(`${head}${one.trim()}${tail}`));
211
+ }
212
+ static _pattern(glob) {
213
+ let out = '';
214
+ for (let i = 0; i < glob.length; i++) {
215
+ const char = glob[i];
216
+ if (char === '*') {
217
+ if (glob[i + 1] === '*') {
218
+ // A double star followed by a slash matches no directories as well
219
+ // as many, so a glob over src covers a file directly in src — which
220
+ // is what anyone writing it meant.
221
+ if (glob[i + 2] === '/') {
222
+ out += '(?:.*/)?';
223
+ i += 2;
224
+ }
225
+ else {
226
+ out += '.*';
227
+ i += 1;
228
+ }
229
+ }
230
+ else {
231
+ out += '[^/]*';
232
+ }
233
+ }
234
+ else if (char === '?') {
235
+ out += '[^/]';
236
+ }
237
+ else {
238
+ out += char.replace(/[.+^${}()|[\]\\]/g, '\\$&');
239
+ }
240
+ }
241
+ return new RegExp(`^${out}$`);
242
+ }
243
+ /**
244
+ * What the store holds as the memory itself, and embeds.
245
+ *
246
+ * The paths are here because this string is the only part of a claim a
247
+ * vector search can see. A claim about an auth service embeds closer to a
248
+ * hunk that touches auth files when the file names travel with the sentence,
249
+ * and nothing is lost by it: the statement is read back from the metadata.
250
+ */
251
+ text() {
252
+ return [`${this.kind}: ${this.statement}`, this.cites.join(' ')].filter(Boolean).join('\n');
253
+ }
254
+ metadata() {
255
+ return {
256
+ weigh: 'claim',
257
+ kind: this.kind,
258
+ statement: this.statement,
259
+ evidence: [...this.evidence],
260
+ ...(this.applies.length && { applies: [...this.applies] }),
261
+ confidence: this.confidence,
262
+ source: this.source,
263
+ ...(this.commit && { commit: this.commit }),
264
+ at: this.at,
265
+ ...(this.verified && { verified: { ...this.verified } }),
266
+ };
267
+ }
268
+ toJSON() {
269
+ return {
270
+ ...(this.id && { id: this.id }),
271
+ kind: this.kind,
272
+ statement: this.statement,
273
+ evidence: [...this.evidence],
274
+ ...(this.applies.length && { applies: [...this.applies] }),
275
+ confidence: this.confidence,
276
+ provenance: { source: this.source, ...(this.commit && { commit: this.commit }), at: this.at },
277
+ ...(this.verified && { verified: { ...this.verified } }),
278
+ ...(this.score !== undefined && { score: this.score }),
279
+ ...(this.similarity !== undefined && { similarity: this.similarity }),
280
+ };
281
+ }
282
+ /** One claim as `weigh context` prints it. */
283
+ describe() {
284
+ const meta = [
285
+ this.id ? `id ${this.id}` : null,
286
+ `confidence ${this.confidence.toFixed(2)}`,
287
+ this.score !== undefined ? `score ${this.score.toFixed(3)}` : null,
288
+ this.applies.length ? `applies ${this.applies.join(' ')}` : null,
289
+ this.source,
290
+ this.at.slice(0, 10),
291
+ ]
292
+ .filter(Boolean)
293
+ .join(' · ');
294
+ return [`• ${this.kind} ${this.statement}`, ` ${meta}`, ` ${this.evidence.join(', ')}`].join('\n');
295
+ }
296
+ }
297
+ //# sourceMappingURL=claim.js.map