@namzu/sdk 54.0.0 → 55.1.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 (325) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +1 -0
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/compaction/extractor.d.ts.map +1 -1
  6. package/dist/compaction/extractor.js +5 -1
  7. package/dist/compaction/extractor.js.map +1 -1
  8. package/dist/compaction/managers/structured.d.ts.map +1 -1
  9. package/dist/compaction/managers/structured.js +5 -0
  10. package/dist/compaction/managers/structured.js.map +1 -1
  11. package/dist/compaction/manual.d.ts.map +1 -1
  12. package/dist/compaction/manual.js +6 -0
  13. package/dist/compaction/manual.js.map +1 -1
  14. package/dist/compaction/serializer.d.ts +6 -0
  15. package/dist/compaction/serializer.d.ts.map +1 -1
  16. package/dist/compaction/serializer.js +21 -3
  17. package/dist/compaction/serializer.js.map +1 -1
  18. package/dist/compaction/verifier.d.ts.map +1 -1
  19. package/dist/compaction/verifier.js +27 -6
  20. package/dist/compaction/verifier.js.map +1 -1
  21. package/dist/constants/compaction/index.d.ts +1 -0
  22. package/dist/constants/compaction/index.d.ts.map +1 -1
  23. package/dist/constants/compaction/index.js +1 -0
  24. package/dist/constants/compaction/index.js.map +1 -1
  25. package/dist/{manager/resident/learning-cycle.d.ts → learning/cycle.d.ts} +45 -36
  26. package/dist/learning/cycle.d.ts.map +1 -0
  27. package/dist/{manager/resident/learning-cycle.js → learning/cycle.js} +52 -20
  28. package/dist/learning/cycle.js.map +1 -0
  29. package/dist/learning/deprecated.d.ts +86 -0
  30. package/dist/learning/deprecated.d.ts.map +1 -0
  31. package/dist/learning/deprecated.js +22 -0
  32. package/dist/learning/deprecated.js.map +1 -0
  33. package/dist/learning/experience-store.d.ts +35 -0
  34. package/dist/learning/experience-store.d.ts.map +1 -0
  35. package/dist/learning/experience-store.js +143 -0
  36. package/dist/learning/experience-store.js.map +1 -0
  37. package/dist/learning/experience.d.ts +150 -0
  38. package/dist/learning/experience.d.ts.map +1 -0
  39. package/dist/learning/experience.js +146 -0
  40. package/dist/learning/experience.js.map +1 -0
  41. package/dist/learning/generator.d.ts +118 -0
  42. package/dist/learning/generator.d.ts.map +1 -0
  43. package/dist/learning/generator.js +275 -0
  44. package/dist/learning/generator.js.map +1 -0
  45. package/dist/learning/leak-tripwire.d.ts +66 -0
  46. package/dist/learning/leak-tripwire.d.ts.map +1 -0
  47. package/dist/learning/leak-tripwire.js +208 -0
  48. package/dist/learning/leak-tripwire.js.map +1 -0
  49. package/dist/{manager/resident/learning-observation.d.ts → learning/observation.d.ts} +4 -4
  50. package/dist/learning/observation.d.ts.map +1 -0
  51. package/dist/{manager/resident/learning-observation.js → learning/observation.js} +3 -3
  52. package/dist/learning/observation.js.map +1 -0
  53. package/dist/{manager/resident/learning.d.ts → learning/skill.d.ts} +29 -29
  54. package/dist/learning/skill.d.ts.map +1 -0
  55. package/dist/{manager/resident/learning.js → learning/skill.js} +27 -27
  56. package/dist/learning/skill.js.map +1 -0
  57. package/dist/{manager/resident/learning-store.d.ts → learning/store.d.ts} +38 -31
  58. package/dist/learning/store.d.ts.map +1 -0
  59. package/dist/{manager/resident/learning-store.js → learning/store.js} +52 -20
  60. package/dist/learning/store.js.map +1 -0
  61. package/dist/manager/resident/activity.d.ts +30 -6
  62. package/dist/manager/resident/activity.d.ts.map +1 -1
  63. package/dist/manager/resident/activity.js.map +1 -1
  64. package/dist/manager/resident/agenda.d.ts +42 -12
  65. package/dist/manager/resident/agenda.d.ts.map +1 -1
  66. package/dist/manager/resident/agenda.js +9 -7
  67. package/dist/manager/resident/agenda.js.map +1 -1
  68. package/dist/manager/resident/consumption.d.ts +27 -5
  69. package/dist/manager/resident/consumption.d.ts.map +1 -1
  70. package/dist/manager/resident/consumption.js +2 -0
  71. package/dist/manager/resident/consumption.js.map +1 -1
  72. package/dist/manager/resident/delivery-window.d.ts +7 -1
  73. package/dist/manager/resident/delivery-window.d.ts.map +1 -1
  74. package/dist/manager/resident/delivery-window.js +2 -0
  75. package/dist/manager/resident/delivery-window.js.map +1 -1
  76. package/dist/manager/resident/evidence-recall.d.ts +7 -1
  77. package/dist/manager/resident/evidence-recall.d.ts.map +1 -1
  78. package/dist/manager/resident/evidence-recall.js +2 -0
  79. package/dist/manager/resident/evidence-recall.js.map +1 -1
  80. package/dist/manager/resident/history.d.ts +45 -9
  81. package/dist/manager/resident/history.d.ts.map +1 -1
  82. package/dist/manager/resident/history.js.map +1 -1
  83. package/dist/manager/resident/host.d.ts +44 -10
  84. package/dist/manager/resident/host.d.ts.map +1 -1
  85. package/dist/manager/resident/host.js +4 -2
  86. package/dist/manager/resident/host.js.map +1 -1
  87. package/dist/manager/resident/initiative.d.ts +32 -6
  88. package/dist/manager/resident/initiative.d.ts.map +1 -1
  89. package/dist/manager/resident/initiative.js +2 -0
  90. package/dist/manager/resident/initiative.js.map +1 -1
  91. package/dist/manager/resident/loop.d.ts +22 -4
  92. package/dist/manager/resident/loop.d.ts.map +1 -1
  93. package/dist/manager/resident/loop.js +7 -1
  94. package/dist/manager/resident/loop.js.map +1 -1
  95. package/dist/manager/resident/outbox.d.ts +42 -8
  96. package/dist/manager/resident/outbox.d.ts.map +1 -1
  97. package/dist/manager/resident/outbox.js +2 -0
  98. package/dist/manager/resident/outbox.js.map +1 -1
  99. package/dist/manager/resident/proposal.d.ts +19 -5
  100. package/dist/manager/resident/proposal.d.ts.map +1 -1
  101. package/dist/manager/resident/proposal.js +2 -0
  102. package/dist/manager/resident/proposal.js.map +1 -1
  103. package/dist/manager/resident/store.d.ts +31 -9
  104. package/dist/manager/resident/store.d.ts.map +1 -1
  105. package/dist/manager/resident/store.js +7 -1
  106. package/dist/manager/resident/store.js.map +1 -1
  107. package/dist/manager/resident/tool-evidence.d.ts +45 -9
  108. package/dist/manager/resident/tool-evidence.d.ts.map +1 -1
  109. package/dist/manager/resident/tool-evidence.js +5 -1
  110. package/dist/manager/resident/tool-evidence.js.map +1 -1
  111. package/dist/prompt/coding-agent-doctrine.d.ts +3 -3
  112. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  113. package/dist/prompt/coding-agent-doctrine.js +18 -20
  114. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  115. package/dist/prompt/resident-learning.d.ts +12 -2
  116. package/dist/prompt/resident-learning.d.ts.map +1 -1
  117. package/dist/prompt/resident-learning.js +6 -5
  118. package/dist/prompt/resident-learning.js.map +1 -1
  119. package/dist/prompt/resident-step.d.ts +10 -4
  120. package/dist/prompt/resident-step.d.ts.map +1 -1
  121. package/dist/prompt/resident-step.js +6 -4
  122. package/dist/prompt/resident-step.js.map +1 -1
  123. package/dist/public-runtime.d.ts +10 -4
  124. package/dist/public-runtime.d.ts.map +1 -1
  125. package/dist/public-runtime.js +11 -4
  126. package/dist/public-runtime.js.map +1 -1
  127. package/dist/public-types.d.ts +9 -4
  128. package/dist/public-types.d.ts.map +1 -1
  129. package/dist/runtime/query/checkpoint.d.ts +12 -2
  130. package/dist/runtime/query/checkpoint.d.ts.map +1 -1
  131. package/dist/runtime/query/checkpoint.js +42 -8
  132. package/dist/runtime/query/checkpoint.js.map +1 -1
  133. package/dist/runtime/query/executor.d.ts +39 -1
  134. package/dist/runtime/query/executor.d.ts.map +1 -1
  135. package/dist/runtime/query/executor.js +115 -7
  136. package/dist/runtime/query/executor.js.map +1 -1
  137. package/dist/runtime/query/index.d.ts +18 -0
  138. package/dist/runtime/query/index.d.ts.map +1 -1
  139. package/dist/runtime/query/index.js +20 -1
  140. package/dist/runtime/query/index.js.map +1 -1
  141. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  142. package/dist/runtime/query/iteration/index.js +17 -8
  143. package/dist/runtime/query/iteration/index.js.map +1 -1
  144. package/dist/runtime/query/iteration/phases/context.d.ts +24 -2
  145. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  146. package/dist/runtime/query/iteration/phases/context.js +22 -22
  147. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  148. package/dist/runtime/query/iteration/phases/per-call-review.d.ts +87 -0
  149. package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -0
  150. package/dist/runtime/query/iteration/phases/per-call-review.js +513 -0
  151. package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -0
  152. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  153. package/dist/runtime/query/iteration/phases/tool-review.js +129 -62
  154. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  155. package/dist/runtime/query/iteration/step-context.d.ts +14 -0
  156. package/dist/runtime/query/iteration/step-context.d.ts.map +1 -1
  157. package/dist/runtime/query/iteration/step-context.js +29 -0
  158. package/dist/runtime/query/iteration/step-context.js.map +1 -1
  159. package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
  160. package/dist/runtime/query/iteration/step-shaping.js +6 -2
  161. package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
  162. package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
  163. package/dist/runtime/query/prepare-turn.js +16 -3
  164. package/dist/runtime/query/prepare-turn.js.map +1 -1
  165. package/dist/runtime/query/project-instructions.d.ts +24 -5
  166. package/dist/runtime/query/project-instructions.d.ts.map +1 -1
  167. package/dist/runtime/query/project-instructions.js +107 -35
  168. package/dist/runtime/query/project-instructions.js.map +1 -1
  169. package/dist/runtime/query/prompt.d.ts +6 -0
  170. package/dist/runtime/query/prompt.d.ts.map +1 -1
  171. package/dist/runtime/query/prompt.js +10 -49
  172. package/dist/runtime/query/prompt.js.map +1 -1
  173. package/dist/runtime/query/resume-pending.d.ts +8 -0
  174. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  175. package/dist/runtime/query/resume-pending.js +101 -0
  176. package/dist/runtime/query/resume-pending.js.map +1 -1
  177. package/dist/runtime/query/review-policy.d.ts +18 -0
  178. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  179. package/dist/runtime/query/review-policy.js +10 -0
  180. package/dist/runtime/query/review-policy.js.map +1 -1
  181. package/dist/runtime/query/steering.d.ts +55 -56
  182. package/dist/runtime/query/steering.d.ts.map +1 -1
  183. package/dist/runtime/query/steering.js +78 -72
  184. package/dist/runtime/query/steering.js.map +1 -1
  185. package/dist/tools/builtins/bash.d.ts +8 -0
  186. package/dist/tools/builtins/bash.d.ts.map +1 -1
  187. package/dist/tools/builtins/bash.js +13 -18
  188. package/dist/tools/builtins/bash.js.map +1 -1
  189. package/dist/tools/builtins/browser.d.ts.map +1 -1
  190. package/dist/tools/builtins/browser.js +38 -12
  191. package/dist/tools/builtins/browser.js.map +1 -1
  192. package/dist/tools/builtins/edit.js +4 -4
  193. package/dist/tools/builtins/edit.js.map +1 -1
  194. package/dist/tools/builtins/job.js +1 -1
  195. package/dist/tools/builtins/job.js.map +1 -1
  196. package/dist/tools/builtins/skill.js +1 -1
  197. package/dist/tools/builtins/skill.js.map +1 -1
  198. package/dist/tools/builtins/structuredOutput.js +1 -1
  199. package/dist/tools/builtins/structuredOutput.js.map +1 -1
  200. package/dist/tools/builtins/verify-outputs.js +1 -1
  201. package/dist/tools/builtins/verify-outputs.js.map +1 -1
  202. package/dist/tools/builtins/write-file.js +4 -4
  203. package/dist/tools/builtins/write-file.js.map +1 -1
  204. package/dist/tools/coordinator/ask-user-question.d.ts +6 -0
  205. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  206. package/dist/tools/coordinator/ask-user-question.js +6 -1
  207. package/dist/tools/coordinator/ask-user-question.js.map +1 -1
  208. package/dist/tools/coordinator/index.d.ts.map +1 -1
  209. package/dist/tools/coordinator/index.js +10 -3
  210. package/dist/tools/coordinator/index.js.map +1 -1
  211. package/dist/tools/resident-history.d.ts +2 -0
  212. package/dist/tools/resident-history.d.ts.map +1 -1
  213. package/dist/tools/resident-history.js +2 -0
  214. package/dist/tools/resident-history.js.map +1 -1
  215. package/dist/tools/resident-tool-evidence.d.ts +5 -1
  216. package/dist/tools/resident-tool-evidence.d.ts.map +1 -1
  217. package/dist/tools/resident-tool-evidence.js +5 -1
  218. package/dist/tools/resident-tool-evidence.js.map +1 -1
  219. package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
  220. package/dist/tools/schedules/loop-tool.js +4 -2
  221. package/dist/tools/schedules/loop-tool.js.map +1 -1
  222. package/dist/tools/schedules/schedule-tool.js +2 -2
  223. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  224. package/dist/tools/task/create.js +1 -1
  225. package/dist/tools/task/create.js.map +1 -1
  226. package/dist/tools/untrusted-envelope.js +1 -1
  227. package/dist/tools/untrusted-envelope.js.map +1 -1
  228. package/dist/turn/evidence-query.d.ts.map +1 -1
  229. package/dist/turn/evidence-query.js +16 -1
  230. package/dist/turn/evidence-query.js.map +1 -1
  231. package/dist/turn/evidence-recall.js +1 -1
  232. package/dist/turn/evidence-recall.js.map +1 -1
  233. package/dist/types/agent/base.d.ts +7 -0
  234. package/dist/types/agent/base.d.ts.map +1 -1
  235. package/dist/types/hitl/index.d.ts +66 -0
  236. package/dist/types/hitl/index.d.ts.map +1 -1
  237. package/dist/types/hitl/index.js.map +1 -1
  238. package/dist/types/message/index.d.ts +8 -0
  239. package/dist/types/message/index.d.ts.map +1 -1
  240. package/dist/types/message/index.js +12 -2
  241. package/dist/types/message/index.js.map +1 -1
  242. package/dist/types/message/notice-frame.d.ts +41 -0
  243. package/dist/types/message/notice-frame.d.ts.map +1 -0
  244. package/dist/types/message/notice-frame.js +65 -0
  245. package/dist/types/message/notice-frame.js.map +1 -0
  246. package/package.json +1 -1
  247. package/src/agents/QueryAgent.ts +1 -0
  248. package/src/compaction/extractor.ts +8 -1
  249. package/src/compaction/managers/structured.ts +3 -0
  250. package/src/compaction/manual.ts +5 -0
  251. package/src/compaction/serializer.ts +28 -3
  252. package/src/compaction/verifier.ts +32 -6
  253. package/src/constants/compaction/index.ts +1 -0
  254. package/src/{manager/resident/learning-cycle.ts → learning/cycle.ts} +130 -78
  255. package/src/learning/deprecated.ts +124 -0
  256. package/src/learning/experience-store.ts +202 -0
  257. package/src/learning/experience.ts +238 -0
  258. package/src/learning/generator.ts +388 -0
  259. package/src/learning/leak-tripwire.ts +280 -0
  260. package/src/{manager/resident/learning-observation.ts → learning/observation.ts} +5 -5
  261. package/src/{manager/resident/learning.ts → learning/skill.ts} +64 -67
  262. package/src/{manager/resident/learning-store.ts → learning/store.ts} +97 -67
  263. package/src/manager/resident/activity.ts +30 -6
  264. package/src/manager/resident/agenda.ts +63 -33
  265. package/src/manager/resident/consumption.ts +27 -5
  266. package/src/manager/resident/delivery-window.ts +7 -1
  267. package/src/manager/resident/evidence-recall.ts +7 -1
  268. package/src/manager/resident/history.ts +45 -9
  269. package/src/manager/resident/host.ts +45 -11
  270. package/src/manager/resident/initiative.ts +32 -6
  271. package/src/manager/resident/loop.ts +22 -4
  272. package/src/manager/resident/outbox.ts +42 -8
  273. package/src/manager/resident/proposal.ts +17 -3
  274. package/src/manager/resident/store.ts +27 -5
  275. package/src/manager/resident/tool-evidence.ts +45 -9
  276. package/src/prompt/coding-agent-doctrine.ts +18 -20
  277. package/src/prompt/resident-learning.ts +16 -7
  278. package/src/prompt/resident-step.ts +19 -13
  279. package/src/public-runtime.ts +36 -5
  280. package/src/public-types.ts +96 -34
  281. package/src/runtime/query/checkpoint.ts +49 -8
  282. package/src/runtime/query/executor.ts +165 -15
  283. package/src/runtime/query/index.ts +45 -1
  284. package/src/runtime/query/iteration/index.ts +19 -6
  285. package/src/runtime/query/iteration/phases/context.ts +37 -11
  286. package/src/runtime/query/iteration/phases/per-call-review.ts +617 -0
  287. package/src/runtime/query/iteration/phases/tool-review.ts +168 -83
  288. package/src/runtime/query/iteration/step-context.ts +29 -0
  289. package/src/runtime/query/iteration/step-shaping.ts +6 -2
  290. package/src/runtime/query/prepare-turn.ts +18 -1
  291. package/src/runtime/query/project-instructions.ts +119 -38
  292. package/src/runtime/query/prompt.ts +11 -54
  293. package/src/runtime/query/resume-pending.ts +131 -0
  294. package/src/runtime/query/review-policy.ts +28 -0
  295. package/src/runtime/query/steering.ts +100 -96
  296. package/src/tools/builtins/bash.ts +13 -19
  297. package/src/tools/builtins/browser.ts +38 -12
  298. package/src/tools/builtins/edit.ts +4 -4
  299. package/src/tools/builtins/job.ts +1 -1
  300. package/src/tools/builtins/skill.ts +1 -1
  301. package/src/tools/builtins/structuredOutput.ts +1 -1
  302. package/src/tools/builtins/verify-outputs.ts +1 -1
  303. package/src/tools/builtins/write-file.ts +4 -4
  304. package/src/tools/coordinator/ask-user-question.ts +12 -1
  305. package/src/tools/coordinator/index.ts +10 -3
  306. package/src/tools/resident-history.ts +2 -0
  307. package/src/tools/resident-tool-evidence.ts +5 -1
  308. package/src/tools/schedules/loop-tool.ts +4 -2
  309. package/src/tools/schedules/schedule-tool.ts +2 -2
  310. package/src/tools/task/create.ts +1 -1
  311. package/src/tools/untrusted-envelope.ts +1 -1
  312. package/src/turn/evidence-query.ts +19 -1
  313. package/src/turn/evidence-recall.ts +1 -1
  314. package/src/types/agent/base.ts +8 -0
  315. package/src/types/hitl/index.ts +67 -0
  316. package/src/types/message/index.ts +20 -2
  317. package/src/types/message/notice-frame.ts +88 -0
  318. package/dist/manager/resident/learning-cycle.d.ts.map +0 -1
  319. package/dist/manager/resident/learning-cycle.js.map +0 -1
  320. package/dist/manager/resident/learning-observation.d.ts.map +0 -1
  321. package/dist/manager/resident/learning-observation.js.map +0 -1
  322. package/dist/manager/resident/learning-store.d.ts.map +0 -1
  323. package/dist/manager/resident/learning-store.js.map +0 -1
  324. package/dist/manager/resident/learning.d.ts.map +0 -1
  325. package/dist/manager/resident/learning.js.map +0 -1
@@ -0,0 +1,124 @@
1
+ /**
2
+ * The learning module used to live under `manager/resident` and carried a
3
+ * `Resident` prefix. Learning is a feature of all of Namzu, not of residents,
4
+ * so every name now lives in `learning/` without the prefix. The old names stay
5
+ * as aliases of the new ones until the next major release.
6
+ */
7
+ import { runLearningCycle } from './cycle.js'
8
+ import type * as Cycle from './cycle.js'
9
+ import type * as Observation from './observation.js'
10
+ import { hashLearningSkill, projectLearning } from './skill.js'
11
+ import type * as Skill from './skill.js'
12
+ import {
13
+ SqliteLearningStore,
14
+ runStoredLearningCycle,
15
+ runStoredLearningFromObservations,
16
+ } from './store.js'
17
+ import type * as Store from './store.js'
18
+
19
+ /** @deprecated Renamed to `LearningEvidence`; the old name is removed in the next major release. */
20
+ export type ResidentLearningEvidence = Skill.LearningEvidence
21
+
22
+ /** @deprecated Renamed to `LearningSkillCandidate`; the old name is removed in the next major release. */
23
+ export type ResidentSkillCandidate = Skill.LearningSkillCandidate
24
+
25
+ /** @deprecated Renamed to `LearnedSkill`; the old name is removed in the next major release. */
26
+ export type ResidentLearnedSkill = Skill.LearnedSkill
27
+
28
+ /** @deprecated Renamed to `LearningState`; the old name is removed in the next major release. */
29
+ export type ResidentLearningState = Skill.LearningState
30
+
31
+ /** @deprecated Renamed to `LearningProfileUpdate`; the old name is removed in the next major release. */
32
+ export type ResidentProfileUpdate = Skill.LearningProfileUpdate
33
+
34
+ /** @deprecated Renamed to `LearningSkillEvaluation`; the old name is removed in the next major release. */
35
+ export type ResidentSkillEvaluation = Skill.LearningSkillEvaluation
36
+
37
+ /** @deprecated Renamed to `LearningProjectionOptions`; the old name is removed in the next major release. */
38
+ export type ResidentLearningProjectionOptions = Skill.LearningProjectionOptions
39
+
40
+ /** @deprecated Renamed to `LearningSource`; the old name is removed in the next major release. */
41
+ export type ResidentLearningSource = Skill.LearningSource
42
+
43
+ /** @deprecated Renamed to `LearningProjection`; the old name is removed in the next major release. */
44
+ export type ResidentLearningProjection = Skill.LearningProjection
45
+
46
+ /** @deprecated Renamed to `LearningStage`; the old name is removed in the next major release. */
47
+ export type ResidentLearningStage = Cycle.LearningStage
48
+
49
+ /** @deprecated Renamed to `LearningReceipt`; the old name is removed in the next major release. */
50
+ export type ResidentLearningReceipt = Cycle.LearningReceipt
51
+
52
+ /** @deprecated Renamed to `LearningConsumption`; the old name is removed in the next major release. */
53
+ export type ResidentLearningConsumption = Cycle.LearningConsumption
54
+
55
+ /** @deprecated Renamed to `LearningCycleEvent`; the old name is removed in the next major release. */
56
+ export type ResidentLearningCycleEvent = Cycle.LearningCycleEvent
57
+
58
+ /** @deprecated Renamed to `LearningCycleContext`; the old name is removed in the next major release. */
59
+ export type ResidentLearningCycleContext = Cycle.LearningCycleContext
60
+
61
+ /** @deprecated Renamed to `LearningGenerationContext`; the old name is removed in the next major release. */
62
+ export type ResidentLearningGenerationContext = Cycle.LearningGenerationContext
63
+
64
+ /** @deprecated Renamed to `LearningExplorationContext`; the old name is removed in the next major release. */
65
+ export type ResidentLearningExplorationContext = Cycle.LearningExplorationContext
66
+
67
+ /** @deprecated Renamed to `LearningExploration`; the old name is removed in the next major release. */
68
+ export type ResidentLearningExploration = Cycle.LearningExploration
69
+
70
+ /** @deprecated Renamed to `LearningEvaluationContext`; the old name is removed in the next major release. */
71
+ export type ResidentLearningEvaluationContext = Cycle.LearningEvaluationContext
72
+
73
+ /** @deprecated Renamed to `LearningCycleOptions`; the old name is removed in the next major release. */
74
+ export type ResidentLearningCycleOptions = Cycle.LearningCycleOptions
75
+
76
+ /** @deprecated Renamed to `LearningCycleResult`; the old name is removed in the next major release. */
77
+ export type ResidentLearningCycleResult = Cycle.LearningCycleResult
78
+
79
+ /** @deprecated Renamed to `SqliteLearningStoreOptions`; the old name is removed in the next major release. */
80
+ export type SqliteResidentLearningStoreOptions = Store.SqliteLearningStoreOptions
81
+
82
+ /** @deprecated Renamed to `LearningArtifact`; the old name is removed in the next major release. */
83
+ export type ResidentLearningArtifact = Store.LearningArtifact
84
+
85
+ /** @deprecated Renamed to `LearningRecordedUsage`; the old name is removed in the next major release. */
86
+ export type ResidentLearningRecordedUsage = Store.LearningRecordedUsage
87
+
88
+ /** @deprecated Renamed to `LearningCycleSummary`; the old name is removed in the next major release. */
89
+ export type ResidentLearningCycleSummary = Store.LearningCycleSummary
90
+
91
+ /** @deprecated Renamed to `LearningDiscoveryOptions`; the old name is removed in the next major release. */
92
+ export type ResidentLearningDiscoveryOptions = Store.LearningDiscoveryOptions
93
+
94
+ /** @deprecated Renamed to `LearningDiscoveryResult`; the old name is removed in the next major release. */
95
+ export type ResidentLearningDiscoveryResult = Store.LearningDiscoveryResult
96
+
97
+ /** @deprecated Renamed to `LearningObservation`; the old name is removed in the next major release. */
98
+ export type ResidentLearningObservation = Observation.LearningObservation
99
+
100
+ /** @deprecated Renamed to `LearningObservationRecord`; the old name is removed in the next major release. */
101
+ export type ResidentLearningObservationRecord = Observation.LearningObservationRecord
102
+
103
+ /** @deprecated Renamed to `LearningTarget`; the old name is removed in the next major release. */
104
+ export type ResidentLearningTarget = Observation.LearningTarget
105
+
106
+ /** @deprecated Renamed to `hashLearningSkill`; the old name is removed in the next major release. */
107
+ export const hashResidentSkill = hashLearningSkill
108
+
109
+ /** @deprecated Renamed to `projectLearning`; the old name is removed in the next major release. */
110
+ export const projectResidentLearning = projectLearning
111
+
112
+ /** @deprecated Renamed to `runLearningCycle`; the old name is removed in the next major release. */
113
+ export const runResidentLearningCycle = runLearningCycle
114
+
115
+ /** @deprecated Renamed to `runStoredLearningCycle`; the old name is removed in the next major release. */
116
+ export const runStoredResidentLearningCycle = runStoredLearningCycle
117
+
118
+ /** @deprecated Renamed to `runStoredLearningFromObservations`; the old name is removed in the next major release. */
119
+ export const runStoredResidentLearningFromObservations = runStoredLearningFromObservations
120
+
121
+ /** @deprecated Renamed to `SqliteLearningStore`; the old name is removed in the next major release. */
122
+ export const SqliteResidentLearningStore = SqliteLearningStore
123
+ /** @deprecated Renamed to `SqliteLearningStore`; the old name is removed in the next major release. */
124
+ export type SqliteResidentLearningStore = SqliteLearningStore
@@ -0,0 +1,202 @@
1
+ import { mkdirSync } from 'node:fs'
2
+ import { createRequire } from 'node:module'
3
+ import { dirname, resolve } from 'node:path'
4
+ import type { DatabaseSync } from 'node:sqlite'
5
+ import { z } from 'zod'
6
+ import type { ProjectId, TenantId } from '../types/ids/index.js'
7
+ import { asProjectId, asTenantId } from '../utils/id.js'
8
+ import {
9
+ type LearningExperienceEntry,
10
+ type LearningExperienceInput,
11
+ type LearningExperienceQuery,
12
+ assertExperienceHasNoLeak,
13
+ normalizeLearningExperience,
14
+ selectLearningExperience,
15
+ } from './experience.js'
16
+
17
+ const SCHEMA = `
18
+ CREATE TABLE experience (
19
+ ordinal INTEGER PRIMARY KEY AUTOINCREMENT,
20
+ tenant_id TEXT NOT NULL, project_id TEXT NOT NULL, agent_key TEXT NOT NULL,
21
+ domain TEXT NOT NULL, cycle_id TEXT NOT NULL, evaluator_revision TEXT NOT NULL,
22
+ decision TEXT NOT NULL, body TEXT NOT NULL,
23
+ UNIQUE(tenant_id, project_id, agent_key, cycle_id)
24
+ );
25
+ CREATE INDEX experience_read ON experience(
26
+ tenant_id, project_id, agent_key, domain, evaluator_revision, ordinal
27
+ );
28
+ `
29
+
30
+ /** The schema version this store reads and writes. */
31
+ export const LEARNING_EXPERIENCE_STORE_VERSION = 1
32
+
33
+ /** @experimental Where the library lives; a separate file from the observation journal. */
34
+ export interface SqliteLearningExperienceStoreOptions {
35
+ readonly databasePath: string
36
+ readonly scope: {
37
+ readonly tenantId: TenantId
38
+ readonly projectId: ProjectId
39
+ readonly agentKey: string
40
+ }
41
+ readonly readOnly?: boolean
42
+ }
43
+
44
+ type Row = { ordinal: number; body: string }
45
+
46
+ /**
47
+ * @experimental Durable experience library. Entries are immutable: recording
48
+ * the same cycle again with identical content returns the stored entry, with
49
+ * different content is refused. The artefact is stored whole.
50
+ */
51
+ export class SqliteLearningExperienceStore {
52
+ readonly databasePath: string
53
+ private readonly scope: SqliteLearningExperienceStoreOptions['scope']
54
+ private readonly readOnly: boolean
55
+
56
+ constructor(options: SqliteLearningExperienceStoreOptions) {
57
+ this.databasePath = resolve(options.databasePath)
58
+ this.scope = Object.freeze({
59
+ tenantId: asTenantId(options.scope.tenantId.toLowerCase()),
60
+ projectId: asProjectId(options.scope.projectId.toLowerCase()),
61
+ agentKey: z
62
+ .string()
63
+ .regex(/^[a-z0-9][a-z0-9_-]{0,63}$/)
64
+ .parse(options.scope.agentKey),
65
+ })
66
+ this.readOnly = options.readOnly === true
67
+ }
68
+
69
+ private use<T>(write: boolean, operation: (db: DatabaseSync) => T, whenEmpty?: () => T): T {
70
+ if (write && this.readOnly) throw new Error('Learning experience database is read-only.')
71
+ let Database: typeof DatabaseSync
72
+ try {
73
+ Database = (createRequire(import.meta.url)('node:sqlite') as typeof import('node:sqlite'))
74
+ .DatabaseSync
75
+ } catch (error) {
76
+ throw new Error('SqliteLearningExperienceStore requires Node.js 22.13 or newer.', {
77
+ cause: error,
78
+ })
79
+ }
80
+ if (!this.readOnly) mkdirSync(dirname(this.databasePath), { recursive: true, mode: 0o700 })
81
+ const db = new Database(this.databasePath, { readOnly: this.readOnly })
82
+ try {
83
+ db.exec('PRAGMA busy_timeout = 5000;')
84
+ if (!this.readOnly) db.exec('PRAGMA journal_mode = DELETE; PRAGMA synchronous = FULL;')
85
+ db.exec(write ? 'BEGIN IMMEDIATE' : 'BEGIN')
86
+ try {
87
+ const version = Number(db.prepare('PRAGMA user_version').get()?.user_version)
88
+ if (version === 0 && write) {
89
+ db.exec(`${SCHEMA} PRAGMA user_version = ${LEARNING_EXPERIENCE_STORE_VERSION};`)
90
+ } else if (version === 0) {
91
+ if (whenEmpty) {
92
+ db.exec('COMMIT')
93
+ return whenEmpty()
94
+ }
95
+ throw new Error(
96
+ 'Learning experience database is not initialized; open it for writing first.',
97
+ )
98
+ } else if (version !== LEARNING_EXPERIENCE_STORE_VERSION)
99
+ throw new Error(
100
+ `Learning experience database is at schema version ${version}; this store reads version ${LEARNING_EXPERIENCE_STORE_VERSION} only.`,
101
+ )
102
+ const value = operation(db)
103
+ db.exec('COMMIT')
104
+ return value
105
+ } catch (error) {
106
+ db.exec('ROLLBACK')
107
+ throw error
108
+ }
109
+ } finally {
110
+ db.close()
111
+ }
112
+ }
113
+
114
+ private scopeArgs(): [string, string, string] {
115
+ return [this.scope.tenantId, this.scope.projectId, this.scope.agentKey]
116
+ }
117
+
118
+ private decode(row: Row): LearningExperienceEntry {
119
+ return {
120
+ ...(JSON.parse(row.body) as Omit<LearningExperienceEntry, 'ordinal'>),
121
+ ordinal: row.ordinal,
122
+ }
123
+ }
124
+
125
+ /** Record one finished cycle. Throws `LearningLeakError` when the entry carries evaluator-side material. */
126
+ async record(input: LearningExperienceInput): Promise<LearningExperienceEntry> {
127
+ if (!input.leakGuard) throw new Error('Recording an experience entry requires a leakGuard.')
128
+ const entry = normalizeLearningExperience(input)
129
+ assertExperienceHasNoLeak(entry, input.leakGuard)
130
+ const body = JSON.stringify(entry)
131
+ return this.use(true, (db) => {
132
+ const existing = db
133
+ .prepare(
134
+ 'SELECT ordinal, body FROM experience WHERE tenant_id=? AND project_id=? AND agent_key=? AND cycle_id=?',
135
+ )
136
+ .get(...this.scopeArgs(), entry.cycleId) as Row | undefined
137
+ if (existing) {
138
+ if (existing.body !== body)
139
+ throw new Error(
140
+ 'This cycle already has a different experience entry; entries are immutable.',
141
+ )
142
+ return this.decode(existing)
143
+ }
144
+ const result = db
145
+ .prepare(
146
+ 'INSERT INTO experience (tenant_id, project_id, agent_key, domain, cycle_id, evaluator_revision, decision, body) VALUES (?,?,?,?,?,?,?,?)',
147
+ )
148
+ .run(
149
+ ...this.scopeArgs(),
150
+ entry.domain,
151
+ entry.cycleId,
152
+ entry.evaluatorRevision,
153
+ entry.decision,
154
+ body,
155
+ )
156
+ return { ...entry, ordinal: Number(result.lastInsertRowid) }
157
+ })
158
+ }
159
+
160
+ /** The ordinal the next entry will be recorded after; pass it as `beforeOrdinal` to read everything so far. */
161
+ async nextOrdinal(): Promise<number> {
162
+ return this.use(
163
+ false,
164
+ (db) => {
165
+ const row = db
166
+ .prepare(
167
+ 'SELECT MAX(ordinal) AS last FROM experience WHERE tenant_id=? AND project_id=? AND agent_key=?',
168
+ )
169
+ .get(...this.scopeArgs()) as { last: number | null }
170
+ return (row.last ?? 0) + 1
171
+ },
172
+ () => 1,
173
+ )
174
+ }
175
+
176
+ /** Entries of one domain and evaluator revision recorded before `beforeOrdinal`, newest first. */
177
+ async retrieve(query: LearningExperienceQuery): Promise<LearningExperienceEntry[]> {
178
+ const rows = this.use(
179
+ false,
180
+ (db) =>
181
+ db
182
+ .prepare(
183
+ 'SELECT ordinal, body FROM experience WHERE tenant_id=? AND project_id=? AND agent_key=? AND domain=? AND evaluator_revision=? AND ordinal<? ORDER BY ordinal DESC',
184
+ )
185
+ .all(
186
+ ...this.scopeArgs(),
187
+ query.domain,
188
+ query.evaluatorRevision,
189
+ query.beforeOrdinal,
190
+ ) as Row[],
191
+ () => [],
192
+ )
193
+ if (!query.leakGuard) throw new Error('Retrieving experience entries requires a leakGuard.')
194
+ const selected = selectLearningExperience(
195
+ rows.map((row) => this.decode(row)),
196
+ query,
197
+ )
198
+ for (const { ordinal: _ordinal, ...entry } of selected)
199
+ assertExperienceHasNoLeak(entry, query.leakGuard)
200
+ return selected
201
+ }
202
+ }
@@ -0,0 +1,238 @@
1
+ import { z } from 'zod'
2
+ import { type LearningLeakGuard, assertNoLearningLeak } from './leak-tripwire.js'
3
+ import {
4
+ type LearningSkillCandidate,
5
+ hashLearningSkill,
6
+ learningEvidenceSchema,
7
+ normalizeLearningSkill,
8
+ } from './skill.js'
9
+
10
+ /**
11
+ * The experience library: what an earlier cycle tried and what came of it,
12
+ * kept beside the observations so a later generator can read it. Three rules
13
+ * hold throughout. An entry stores the adopted or rejected artefact whole,
14
+ * never a summary of it. Retrieval is limited to one domain and to entries
15
+ * recorded before a stated point. And a verdict never claims more than the
16
+ * evidence can separate: when a candidate changed several components at once,
17
+ * the result belongs to the whole change, so each row says `confounded`.
18
+ */
19
+
20
+ const label = z.string().trim().min(1).max(256)
21
+ const text = z.string().trim().min(1).max(2_000)
22
+ const domainLabel = z.string().regex(/^[a-z0-9][a-z0-9_.-]{0,63}$/)
23
+
24
+ export const LEARNING_EDIT_VERDICTS = [
25
+ 'helped',
26
+ 'hurt',
27
+ 'no observed effect',
28
+ 'confounded',
29
+ ] as const
30
+ /** @experimental What one edit did, as far as the evidence can separate it from the others. */
31
+ export type LearningEditVerdict = (typeof LEARNING_EDIT_VERDICTS)[number]
32
+
33
+ export const LEARNING_CONFIDENCE_LEVELS = ['high', 'medium', 'low'] as const
34
+ /** @experimental How far a lesson can be trusted. */
35
+ export type LearningConfidence = (typeof LEARNING_CONFIDENCE_LEVELS)[number]
36
+
37
+ const editSchema = z.object({
38
+ /** The part of the harness the edit touched, such as `instruction-skill`. */
39
+ surface: label,
40
+ /** What changed, in a sentence. */
41
+ change: text,
42
+ verdict: z.enum(LEARNING_EDIT_VERDICTS),
43
+ /**
44
+ * True only when this edit was tried alone (an ablation), so its verdict is
45
+ * separable even though the candidate changed several components. The store
46
+ * trusts this flag from the caller; it does not check that an ablation ran.
47
+ */
48
+ isolated: z.boolean().optional(),
49
+ })
50
+
51
+ const lessonSchema = z.object({
52
+ /** The shape of the situation the lesson applies to, not the incident itself. */
53
+ cue: text,
54
+ lesson: text,
55
+ /** References into the observations, session log or verification receipts. */
56
+ evidence: z.array(learningEvidenceSchema).min(1).max(16),
57
+ confidence: z.enum(LEARNING_CONFIDENCE_LEVELS),
58
+ confidenceReason: text,
59
+ /** Indexes into the entry's edits that the lesson rests on. */
60
+ edits: z.array(z.number().int().min(0).max(63)).max(64).optional(),
61
+ })
62
+
63
+ /** @experimental One edit row of the typed ledger. */
64
+ export type LearningEditRow = Readonly<z.infer<typeof editSchema>>
65
+ /** @experimental A lesson, with the confidence the evidence supports. */
66
+ export type LearningLesson = Readonly<
67
+ Omit<z.infer<typeof lessonSchema>, 'evidence' | 'edits'> & {
68
+ readonly evidence: readonly Readonly<z.infer<typeof learningEvidenceSchema>>[]
69
+ readonly edits?: readonly number[]
70
+ }
71
+ >
72
+
73
+ /** What a host passes when it records one finished cycle. */
74
+ export interface LearningExperienceInput {
75
+ /** The kind of task the cycle was about; retrieval never crosses domains. */
76
+ readonly domain: string
77
+ /** The cycle that produced the entry; one entry per cycle. */
78
+ readonly cycleId: string
79
+ /** The evaluator that judged the candidate. Lessons are only comparable under the same revision. */
80
+ readonly evaluatorRevision: string
81
+ readonly decision: 'adopted' | 'rejected'
82
+ /** Why, as the verification recorded it. */
83
+ readonly reason: string
84
+ /** The whole artefact, as proposed. */
85
+ readonly candidate: LearningSkillCandidate
86
+ readonly edits: readonly LearningEditRow[]
87
+ readonly lessons?: readonly LearningLesson[]
88
+ /**
89
+ * Evaluator-side material to refuse in anything the entry would keep. Required:
90
+ * pass `{}` to apply only the built-in markers and secret shapes.
91
+ */
92
+ readonly leakGuard: LearningLeakGuard
93
+ }
94
+
95
+ const inputSchema = z.object({
96
+ domain: domainLabel,
97
+ cycleId: z.string().uuid(),
98
+ evaluatorRevision: label,
99
+ decision: z.enum(['adopted', 'rejected']),
100
+ reason: text,
101
+ edits: z.array(editSchema).min(1).max(64),
102
+ lessons: z.array(lessonSchema).max(32).optional(),
103
+ })
104
+
105
+ /** @experimental A stored entry. `ordinal` is its position in recording order. */
106
+ export interface LearningExperienceEntry {
107
+ readonly ordinal: number
108
+ readonly domain: string
109
+ readonly cycleId: string
110
+ readonly evaluatorRevision: string
111
+ readonly decision: 'adopted' | 'rejected'
112
+ readonly reason: string
113
+ /** The full artefact as proposed, unabridged. */
114
+ readonly candidate: LearningSkillCandidate
115
+ readonly candidateRevision: string
116
+ readonly edits: readonly LearningEditRow[]
117
+ readonly lessons: readonly LearningLesson[]
118
+ }
119
+
120
+ const CAP: Record<LearningConfidence, number> = { low: 0, medium: 1, high: 2 }
121
+ const BY_RANK: readonly LearningConfidence[] = ['low', 'medium', 'high']
122
+
123
+ /**
124
+ * Apply the rules that keep a record honest. Several components in one
125
+ * candidate share a single outcome, so unless a row was tried alone its
126
+ * verdict becomes `confounded`. A lesson that rests on a confounded edit is
127
+ * capped at medium; one that rests only on confounded edits is low, and its
128
+ * reason says why.
129
+ */
130
+ export function normalizeLearningExperience(
131
+ input: LearningExperienceInput,
132
+ ): Omit<LearningExperienceEntry, 'ordinal'> {
133
+ const { leakGuard: _guard, candidate: rawCandidate, ...rest } = input
134
+ const parsed = inputSchema.parse(rest)
135
+ const candidate = normalizeLearningSkill(rawCandidate)
136
+ // More than one edit row changed together, whatever its component label.
137
+ const several = parsed.edits.length > 1
138
+ const edits: LearningEditRow[] = parsed.edits.map((edit) => {
139
+ const { isolated, ...row } = edit
140
+ if (several && isolated !== true) return { ...row, verdict: 'confounded' as const }
141
+ return isolated === true ? { ...row, isolated } : row
142
+ })
143
+ const lessons: LearningLesson[] = (parsed.lessons ?? []).map((lesson) => {
144
+ // A lesson that cites no edits rests on all of them.
145
+ const refs = lesson.edits?.length ? lesson.edits : edits.map((_, index) => index)
146
+ for (const index of refs)
147
+ if (index >= edits.length) throw new Error(`Lesson refers to edit ${index}, which is absent.`)
148
+ const confounded = refs.filter((index) => edits[index]?.verdict === 'confounded').length
149
+ if (confounded === 0) return lesson
150
+ const all = confounded === refs.length
151
+ const cap = all ? 'low' : 'medium'
152
+ if (CAP[lesson.confidence] <= CAP[cap]) {
153
+ return {
154
+ ...lesson,
155
+ confidenceReason: `${lesson.confidenceReason} (Stands on confounded edits.)`,
156
+ }
157
+ }
158
+ return {
159
+ ...lesson,
160
+ confidence: BY_RANK[CAP[cap]] as LearningConfidence,
161
+ confidenceReason: `${lesson.confidenceReason} (Narrowed to ${cap}: ${
162
+ all ? 'every' : 'some'
163
+ } edit it rests on changed together with others.)`,
164
+ }
165
+ })
166
+ return {
167
+ domain: parsed.domain,
168
+ cycleId: parsed.cycleId.toLowerCase(),
169
+ evaluatorRevision: parsed.evaluatorRevision,
170
+ decision: parsed.decision,
171
+ reason: parsed.reason,
172
+ candidate,
173
+ candidateRevision: hashLearningSkill(candidate),
174
+ edits,
175
+ lessons,
176
+ }
177
+ }
178
+
179
+ function collectStrings(
180
+ value: unknown,
181
+ subject: string,
182
+ out: { subject: string; text: string }[],
183
+ ): void {
184
+ if (typeof value === 'string') out.push({ subject, text: value })
185
+ else if (Array.isArray(value)) value.forEach((v, i) => collectStrings(v, `${subject}[${i}]`, out))
186
+ else if (value && typeof value === 'object')
187
+ for (const [key, v] of Object.entries(value)) collectStrings(v, `${subject}.${key}`, out)
188
+ }
189
+
190
+ /**
191
+ * Refuse an entry that would keep evaluator-side material. Every string the
192
+ * entry holds is scanned, found by walking the entry rather than by naming
193
+ * fields; source keys are also tried as paths. Throws {@link LearningLeakError}.
194
+ */
195
+ export function assertExperienceHasNoLeak(
196
+ entry: Omit<LearningExperienceEntry, 'ordinal'>,
197
+ guard: LearningLeakGuard | undefined,
198
+ ): void {
199
+ const subjects: { subject: string; text?: string; paths?: readonly string[] }[] = []
200
+ const texts: { subject: string; text: string }[] = []
201
+ collectStrings(entry, 'experience', texts)
202
+ subjects.push(...texts)
203
+ for (const [i, source] of (entry.candidate.sources ?? []).entries())
204
+ subjects.push({ subject: `experience.candidate.sources[${i}].path`, paths: [source.key] })
205
+ assertNoLearningLeak(guard, subjects)
206
+ }
207
+
208
+ /** @experimental Where retrieval may look. */
209
+ export interface LearningExperienceQuery {
210
+ readonly domain: string
211
+ /** The evaluator the reader is judged by; entries from another revision are not comparable. */
212
+ readonly evaluatorRevision: string
213
+ /** Evaluator-side material; entries are scanned again before they are returned. */
214
+ readonly leakGuard: LearningLeakGuard
215
+ /** Only entries recorded before this ordinal. The reader's own entry is never among them. */
216
+ readonly beforeOrdinal: number
217
+ readonly decision?: 'adopted' | 'rejected'
218
+ /** Newest first; default 20. */
219
+ readonly limit?: number
220
+ }
221
+
222
+ /** The retrieval rule, shared by every store: same domain, same evaluator, strictly earlier. */
223
+ export function selectLearningExperience(
224
+ entries: readonly LearningExperienceEntry[],
225
+ query: LearningExperienceQuery,
226
+ ): LearningExperienceEntry[] {
227
+ const limit = Math.max(1, Math.min(query.limit ?? 20, 200))
228
+ return entries
229
+ .filter(
230
+ (entry) =>
231
+ entry.domain === query.domain &&
232
+ entry.evaluatorRevision === query.evaluatorRevision &&
233
+ entry.ordinal < query.beforeOrdinal &&
234
+ (query.decision === undefined || entry.decision === query.decision),
235
+ )
236
+ .sort((a, b) => b.ordinal - a.ordinal)
237
+ .slice(0, limit)
238
+ }