@smthrs/harness 0.0.0-stage → 1.0.0-rc.3

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 (476) hide show
  1. package/CHANGELOG.md +387 -0
  2. package/LICENSE +21 -0
  3. package/README.md +138 -2
  4. package/dist/cjs/AgentEvent.d.ts +3092 -0
  5. package/dist/cjs/AgentEvent.d.ts.map +1 -0
  6. package/dist/cjs/AgentEvent.js +1116 -0
  7. package/dist/cjs/AgentEvent.js.map +7 -0
  8. package/dist/cjs/CallLedger.d.ts +378 -0
  9. package/dist/cjs/CallLedger.d.ts.map +1 -0
  10. package/dist/cjs/CallLedger.js +240 -0
  11. package/dist/cjs/CallLedger.js.map +7 -0
  12. package/dist/cjs/Cell.d.ts +774 -0
  13. package/dist/cjs/Cell.d.ts.map +1 -0
  14. package/dist/cjs/Cell.js +431 -0
  15. package/dist/cjs/Cell.js.map +7 -0
  16. package/dist/cjs/CellCalls.d.ts +115 -0
  17. package/dist/cjs/CellCalls.d.ts.map +1 -0
  18. package/dist/cjs/CellCalls.js +98 -0
  19. package/dist/cjs/CellCalls.js.map +7 -0
  20. package/dist/cjs/CellHistory.d.ts +102 -0
  21. package/dist/cjs/CellHistory.d.ts.map +1 -0
  22. package/dist/cjs/CellHistory.js +54 -0
  23. package/dist/cjs/CellHistory.js.map +7 -0
  24. package/dist/cjs/CellTurn.d.ts +1071 -0
  25. package/dist/cjs/CellTurn.d.ts.map +1 -0
  26. package/dist/cjs/CellTurn.js +2618 -0
  27. package/dist/cjs/CellTurn.js.map +7 -0
  28. package/dist/cjs/CellValidation.d.ts +94 -0
  29. package/dist/cjs/CellValidation.d.ts.map +1 -0
  30. package/dist/cjs/CellValidation.js +218 -0
  31. package/dist/cjs/CellValidation.js.map +7 -0
  32. package/dist/cjs/Compaction.d.ts +158 -0
  33. package/dist/cjs/Compaction.d.ts.map +1 -0
  34. package/dist/cjs/Compaction.js +189 -0
  35. package/dist/cjs/Compaction.js.map +7 -0
  36. package/dist/cjs/CompletionClaim.d.ts +801 -0
  37. package/dist/cjs/CompletionClaim.d.ts.map +1 -0
  38. package/dist/cjs/CompletionClaim.js +303 -0
  39. package/dist/cjs/CompletionClaim.js.map +7 -0
  40. package/dist/cjs/ContextWindow.d.ts +435 -0
  41. package/dist/cjs/ContextWindow.d.ts.map +1 -0
  42. package/dist/cjs/ContextWindow.js +319 -0
  43. package/dist/cjs/ContextWindow.js.map +7 -0
  44. package/dist/cjs/EngineLike.d.ts +546 -0
  45. package/dist/cjs/EngineLike.d.ts.map +1 -0
  46. package/dist/cjs/EngineLike.js +114 -0
  47. package/dist/cjs/EngineLike.js.map +7 -0
  48. package/dist/cjs/ExternalTranscript.d.ts +349 -0
  49. package/dist/cjs/ExternalTranscript.d.ts.map +1 -0
  50. package/dist/cjs/ExternalTranscript.js +826 -0
  51. package/dist/cjs/ExternalTranscript.js.map +7 -0
  52. package/dist/cjs/FailedCall.d.ts +132 -0
  53. package/dist/cjs/FailedCall.d.ts.map +1 -0
  54. package/dist/cjs/FailedCall.js +53 -0
  55. package/dist/cjs/FailedCall.js.map +7 -0
  56. package/dist/cjs/FlowBinding.d.ts +289 -0
  57. package/dist/cjs/FlowBinding.d.ts.map +1 -0
  58. package/dist/cjs/FlowBinding.js +251 -0
  59. package/dist/cjs/FlowBinding.js.map +7 -0
  60. package/dist/cjs/HarnessError.d.ts +57 -0
  61. package/dist/cjs/HarnessError.d.ts.map +1 -0
  62. package/dist/cjs/HarnessError.js +75 -0
  63. package/dist/cjs/HarnessError.js.map +7 -0
  64. package/dist/cjs/Judgement.d.ts +289 -0
  65. package/dist/cjs/Judgement.d.ts.map +1 -0
  66. package/dist/cjs/Judgement.js +240 -0
  67. package/dist/cjs/Judgement.js.map +7 -0
  68. package/dist/cjs/Monitor.d.ts +374 -0
  69. package/dist/cjs/Monitor.d.ts.map +1 -0
  70. package/dist/cjs/Monitor.js +233 -0
  71. package/dist/cjs/Monitor.js.map +7 -0
  72. package/dist/cjs/NarrowedCheck.d.ts +523 -0
  73. package/dist/cjs/NarrowedCheck.d.ts.map +1 -0
  74. package/dist/cjs/NarrowedCheck.js +263 -0
  75. package/dist/cjs/NarrowedCheck.js.map +7 -0
  76. package/dist/cjs/Notifications.d.ts +42 -0
  77. package/dist/cjs/Notifications.d.ts.map +1 -0
  78. package/dist/cjs/Notifications.js +177 -0
  79. package/dist/cjs/Notifications.js.map +7 -0
  80. package/dist/cjs/Plan.d.ts +127 -0
  81. package/dist/cjs/Plan.d.ts.map +1 -0
  82. package/dist/cjs/Plan.js +77 -0
  83. package/dist/cjs/Plan.js.map +7 -0
  84. package/dist/cjs/QuickJSSandbox.d.ts +151 -0
  85. package/dist/cjs/QuickJSSandbox.d.ts.map +1 -0
  86. package/dist/cjs/QuickJSSandbox.js +987 -0
  87. package/dist/cjs/QuickJSSandbox.js.map +7 -0
  88. package/dist/cjs/Relevance.d.ts +213 -0
  89. package/dist/cjs/Relevance.d.ts.map +1 -0
  90. package/dist/cjs/Relevance.js +183 -0
  91. package/dist/cjs/Relevance.js.map +7 -0
  92. package/dist/cjs/Sandbox.d.ts +637 -0
  93. package/dist/cjs/Sandbox.d.ts.map +1 -0
  94. package/dist/cjs/Sandbox.js +260 -0
  95. package/dist/cjs/Sandbox.js.map +7 -0
  96. package/dist/cjs/Steering.d.ts +464 -0
  97. package/dist/cjs/Steering.d.ts.map +1 -0
  98. package/dist/cjs/Steering.js +153 -0
  99. package/dist/cjs/Steering.js.map +7 -0
  100. package/dist/cjs/StructuredOutput.d.ts +252 -0
  101. package/dist/cjs/StructuredOutput.d.ts.map +1 -0
  102. package/dist/cjs/StructuredOutput.js +266 -0
  103. package/dist/cjs/StructuredOutput.js.map +7 -0
  104. package/dist/cjs/Sufficiency.d.ts +195 -0
  105. package/dist/cjs/Sufficiency.d.ts.map +1 -0
  106. package/dist/cjs/Sufficiency.js +110 -0
  107. package/dist/cjs/Sufficiency.js.map +7 -0
  108. package/dist/cjs/Supervisor.d.ts +719 -0
  109. package/dist/cjs/Supervisor.d.ts.map +1 -0
  110. package/dist/cjs/Supervisor.js +313 -0
  111. package/dist/cjs/Supervisor.js.map +7 -0
  112. package/dist/cjs/Tokens.d.ts +86 -0
  113. package/dist/cjs/Tokens.d.ts.map +1 -0
  114. package/dist/cjs/Tokens.js +72 -0
  115. package/dist/cjs/Tokens.js.map +7 -0
  116. package/dist/cjs/Transcript.d.ts +171 -0
  117. package/dist/cjs/Transcript.d.ts.map +1 -0
  118. package/dist/cjs/Transcript.js +342 -0
  119. package/dist/cjs/Transcript.js.map +7 -0
  120. package/dist/cjs/TruncatedOutput.d.ts +186 -0
  121. package/dist/cjs/TruncatedOutput.d.ts.map +1 -0
  122. package/dist/cjs/TruncatedOutput.js +143 -0
  123. package/dist/cjs/TruncatedOutput.js.map +7 -0
  124. package/dist/cjs/UnmovedTree.d.ts +113 -0
  125. package/dist/cjs/UnmovedTree.d.ts.map +1 -0
  126. package/dist/cjs/UnmovedTree.js +38 -0
  127. package/dist/cjs/UnmovedTree.js.map +7 -0
  128. package/dist/cjs/UnresolvedFailure.d.ts +196 -0
  129. package/dist/cjs/UnresolvedFailure.d.ts.map +1 -0
  130. package/dist/cjs/UnresolvedFailure.js +77 -0
  131. package/dist/cjs/UnresolvedFailure.js.map +7 -0
  132. package/dist/cjs/VacuousVerification.d.ts +237 -0
  133. package/dist/cjs/VacuousVerification.d.ts.map +1 -0
  134. package/dist/cjs/VacuousVerification.js +91 -0
  135. package/dist/cjs/VacuousVerification.js.map +7 -0
  136. package/dist/cjs/VariablesPanel.d.ts +117 -0
  137. package/dist/cjs/VariablesPanel.d.ts.map +1 -0
  138. package/dist/cjs/VariablesPanel.js +108 -0
  139. package/dist/cjs/VariablesPanel.js.map +7 -0
  140. package/dist/cjs/index.d.ts +172 -0
  141. package/dist/cjs/index.d.ts.map +1 -0
  142. package/dist/cjs/index.js +99 -0
  143. package/dist/cjs/index.js.map +7 -0
  144. package/dist/cjs/internal/bytes.d.ts +36 -0
  145. package/dist/cjs/internal/bytes.d.ts.map +1 -0
  146. package/dist/cjs/internal/bytes.js +57 -0
  147. package/dist/cjs/internal/bytes.js.map +7 -0
  148. package/dist/cjs/internal/cellPrompt.d.ts +122 -0
  149. package/dist/cjs/internal/cellPrompt.d.ts.map +1 -0
  150. package/dist/cjs/internal/cellPrompt.js +146 -0
  151. package/dist/cjs/internal/cellPrompt.js.map +7 -0
  152. package/dist/cjs/internal/compactable.d.ts +44 -0
  153. package/dist/cjs/internal/compactable.d.ts.map +1 -0
  154. package/dist/cjs/internal/compactable.js +56 -0
  155. package/dist/cjs/internal/compactable.js.map +7 -0
  156. package/dist/cjs/internal/compactionMarks.d.ts +278 -0
  157. package/dist/cjs/internal/compactionMarks.d.ts.map +1 -0
  158. package/dist/cjs/internal/compactionMarks.js +212 -0
  159. package/dist/cjs/internal/compactionMarks.js.map +7 -0
  160. package/dist/cjs/internal/demandText.d.ts +95 -0
  161. package/dist/cjs/internal/demandText.d.ts.map +1 -0
  162. package/dist/cjs/internal/demandText.js +70 -0
  163. package/dist/cjs/internal/demandText.js.map +7 -0
  164. package/dist/cjs/internal/elide.d.ts +109 -0
  165. package/dist/cjs/internal/elide.d.ts.map +1 -0
  166. package/dist/cjs/internal/elide.js +59 -0
  167. package/dist/cjs/internal/elide.js.map +7 -0
  168. package/dist/cjs/internal/frame.d.ts +463 -0
  169. package/dist/cjs/internal/frame.d.ts.map +1 -0
  170. package/dist/cjs/internal/frame.js +514 -0
  171. package/dist/cjs/internal/frame.js.map +7 -0
  172. package/dist/cjs/internal/nonNegativeSafeInt.d.ts +20 -0
  173. package/dist/cjs/internal/nonNegativeSafeInt.d.ts.map +1 -0
  174. package/dist/cjs/internal/nonNegativeSafeInt.js +29 -0
  175. package/dist/cjs/internal/nonNegativeSafeInt.js.map +7 -0
  176. package/dist/cjs/internal/paidUsage.d.ts +52 -0
  177. package/dist/cjs/internal/paidUsage.d.ts.map +1 -0
  178. package/dist/cjs/internal/paidUsage.js +70 -0
  179. package/dist/cjs/internal/paidUsage.js.map +7 -0
  180. package/dist/cjs/internal/printChannel.d.ts +233 -0
  181. package/dist/cjs/internal/printChannel.d.ts.map +1 -0
  182. package/dist/cjs/internal/printChannel.js +165 -0
  183. package/dist/cjs/internal/printChannel.js.map +7 -0
  184. package/dist/cjs/internal/printsObservation.d.ts +26 -0
  185. package/dist/cjs/internal/printsObservation.d.ts.map +1 -0
  186. package/dist/cjs/internal/printsObservation.js +27 -0
  187. package/dist/cjs/internal/printsObservation.js.map +7 -0
  188. package/dist/cjs/internal/refusal.d.ts +40 -0
  189. package/dist/cjs/internal/refusal.d.ts.map +1 -0
  190. package/dist/cjs/internal/refusal.js +45 -0
  191. package/dist/cjs/internal/refusal.js.map +7 -0
  192. package/dist/cjs/internal/supervision.d.ts +174 -0
  193. package/dist/cjs/internal/supervision.d.ts.map +1 -0
  194. package/dist/cjs/internal/supervision.js +402 -0
  195. package/dist/cjs/internal/supervision.js.map +7 -0
  196. package/dist/cjs/internal/unfinishedWork.d.ts +99 -0
  197. package/dist/cjs/internal/unfinishedWork.d.ts.map +1 -0
  198. package/dist/cjs/internal/unfinishedWork.js +80 -0
  199. package/dist/cjs/internal/unfinishedWork.js.map +7 -0
  200. package/dist/cjs/internal/unobservedCall.d.ts +112 -0
  201. package/dist/cjs/internal/unobservedCall.d.ts.map +1 -0
  202. package/dist/cjs/internal/unobservedCall.js +345 -0
  203. package/dist/cjs/internal/unobservedCall.js.map +7 -0
  204. package/dist/cjs/internal/untrustedData.d.ts +14 -0
  205. package/dist/cjs/internal/untrustedData.d.ts.map +1 -0
  206. package/dist/cjs/internal/untrustedData.js +30 -0
  207. package/dist/cjs/internal/untrustedData.js.map +7 -0
  208. package/dist/cjs/package.json +1 -0
  209. package/dist/esm/AgentEvent.d.ts +3092 -0
  210. package/dist/esm/AgentEvent.d.ts.map +1 -0
  211. package/dist/esm/AgentEvent.js +1610 -0
  212. package/dist/esm/AgentEvent.js.map +1 -0
  213. package/dist/esm/CallLedger.d.ts +378 -0
  214. package/dist/esm/CallLedger.d.ts.map +1 -0
  215. package/dist/esm/CallLedger.js +506 -0
  216. package/dist/esm/CallLedger.js.map +1 -0
  217. package/dist/esm/Cell.d.ts +774 -0
  218. package/dist/esm/Cell.d.ts.map +1 -0
  219. package/dist/esm/Cell.js +772 -0
  220. package/dist/esm/Cell.js.map +1 -0
  221. package/dist/esm/CellCalls.d.ts +115 -0
  222. package/dist/esm/CellCalls.d.ts.map +1 -0
  223. package/dist/esm/CellCalls.js +97 -0
  224. package/dist/esm/CellCalls.js.map +1 -0
  225. package/dist/esm/CellHistory.d.ts +102 -0
  226. package/dist/esm/CellHistory.d.ts.map +1 -0
  227. package/dist/esm/CellHistory.js +91 -0
  228. package/dist/esm/CellHistory.js.map +1 -0
  229. package/dist/esm/CellTurn.d.ts +1071 -0
  230. package/dist/esm/CellTurn.d.ts.map +1 -0
  231. package/dist/esm/CellTurn.js +3410 -0
  232. package/dist/esm/CellTurn.js.map +1 -0
  233. package/dist/esm/CellValidation.d.ts +94 -0
  234. package/dist/esm/CellValidation.d.ts.map +1 -0
  235. package/dist/esm/CellValidation.js +335 -0
  236. package/dist/esm/CellValidation.js.map +1 -0
  237. package/dist/esm/Compaction.d.ts +158 -0
  238. package/dist/esm/Compaction.d.ts.map +1 -0
  239. package/dist/esm/Compaction.js +216 -0
  240. package/dist/esm/Compaction.js.map +1 -0
  241. package/dist/esm/CompletionClaim.d.ts +801 -0
  242. package/dist/esm/CompletionClaim.d.ts.map +1 -0
  243. package/dist/esm/CompletionClaim.js +833 -0
  244. package/dist/esm/CompletionClaim.js.map +1 -0
  245. package/dist/esm/ContextWindow.d.ts +435 -0
  246. package/dist/esm/ContextWindow.d.ts.map +1 -0
  247. package/dist/esm/ContextWindow.js +427 -0
  248. package/dist/esm/ContextWindow.js.map +1 -0
  249. package/dist/esm/EngineLike.d.ts +546 -0
  250. package/dist/esm/EngineLike.d.ts.map +1 -0
  251. package/dist/esm/EngineLike.js +218 -0
  252. package/dist/esm/EngineLike.js.map +1 -0
  253. package/dist/esm/ExternalTranscript.d.ts +349 -0
  254. package/dist/esm/ExternalTranscript.d.ts.map +1 -0
  255. package/dist/esm/ExternalTranscript.js +987 -0
  256. package/dist/esm/ExternalTranscript.js.map +1 -0
  257. package/dist/esm/FailedCall.d.ts +132 -0
  258. package/dist/esm/FailedCall.d.ts.map +1 -0
  259. package/dist/esm/FailedCall.js +131 -0
  260. package/dist/esm/FailedCall.js.map +1 -0
  261. package/dist/esm/FlowBinding.d.ts +289 -0
  262. package/dist/esm/FlowBinding.d.ts.map +1 -0
  263. package/dist/esm/FlowBinding.js +376 -0
  264. package/dist/esm/FlowBinding.js.map +1 -0
  265. package/dist/esm/HarnessError.d.ts +57 -0
  266. package/dist/esm/HarnessError.d.ts.map +1 -0
  267. package/dist/esm/HarnessError.js +85 -0
  268. package/dist/esm/HarnessError.js.map +1 -0
  269. package/dist/esm/Judgement.d.ts +289 -0
  270. package/dist/esm/Judgement.d.ts.map +1 -0
  271. package/dist/esm/Judgement.js +305 -0
  272. package/dist/esm/Judgement.js.map +1 -0
  273. package/dist/esm/Monitor.d.ts +374 -0
  274. package/dist/esm/Monitor.d.ts.map +1 -0
  275. package/dist/esm/Monitor.js +370 -0
  276. package/dist/esm/Monitor.js.map +1 -0
  277. package/dist/esm/NarrowedCheck.d.ts +523 -0
  278. package/dist/esm/NarrowedCheck.d.ts.map +1 -0
  279. package/dist/esm/NarrowedCheck.js +612 -0
  280. package/dist/esm/NarrowedCheck.js.map +1 -0
  281. package/dist/esm/Notifications.d.ts +42 -0
  282. package/dist/esm/Notifications.d.ts.map +1 -0
  283. package/dist/esm/Notifications.js +215 -0
  284. package/dist/esm/Notifications.js.map +1 -0
  285. package/dist/esm/Plan.d.ts +127 -0
  286. package/dist/esm/Plan.d.ts.map +1 -0
  287. package/dist/esm/Plan.js +97 -0
  288. package/dist/esm/Plan.js.map +1 -0
  289. package/dist/esm/QuickJSSandbox.d.ts +151 -0
  290. package/dist/esm/QuickJSSandbox.d.ts.map +1 -0
  291. package/dist/esm/QuickJSSandbox.js +1364 -0
  292. package/dist/esm/QuickJSSandbox.js.map +1 -0
  293. package/dist/esm/Relevance.d.ts +213 -0
  294. package/dist/esm/Relevance.d.ts.map +1 -0
  295. package/dist/esm/Relevance.js +254 -0
  296. package/dist/esm/Relevance.js.map +1 -0
  297. package/dist/esm/Sandbox.d.ts +637 -0
  298. package/dist/esm/Sandbox.d.ts.map +1 -0
  299. package/dist/esm/Sandbox.js +464 -0
  300. package/dist/esm/Sandbox.js.map +1 -0
  301. package/dist/esm/Steering.d.ts +464 -0
  302. package/dist/esm/Steering.d.ts.map +1 -0
  303. package/dist/esm/Steering.js +193 -0
  304. package/dist/esm/Steering.js.map +1 -0
  305. package/dist/esm/StructuredOutput.d.ts +252 -0
  306. package/dist/esm/StructuredOutput.d.ts.map +1 -0
  307. package/dist/esm/StructuredOutput.js +430 -0
  308. package/dist/esm/StructuredOutput.js.map +1 -0
  309. package/dist/esm/Sufficiency.d.ts +195 -0
  310. package/dist/esm/Sufficiency.d.ts.map +1 -0
  311. package/dist/esm/Sufficiency.js +207 -0
  312. package/dist/esm/Sufficiency.js.map +1 -0
  313. package/dist/esm/Supervisor.d.ts +719 -0
  314. package/dist/esm/Supervisor.d.ts.map +1 -0
  315. package/dist/esm/Supervisor.js +575 -0
  316. package/dist/esm/Supervisor.js.map +1 -0
  317. package/dist/esm/Tokens.d.ts +86 -0
  318. package/dist/esm/Tokens.d.ts.map +1 -0
  319. package/dist/esm/Tokens.js +92 -0
  320. package/dist/esm/Tokens.js.map +1 -0
  321. package/dist/esm/Transcript.d.ts +171 -0
  322. package/dist/esm/Transcript.d.ts.map +1 -0
  323. package/dist/esm/Transcript.js +424 -0
  324. package/dist/esm/Transcript.js.map +1 -0
  325. package/dist/esm/TruncatedOutput.d.ts +186 -0
  326. package/dist/esm/TruncatedOutput.d.ts.map +1 -0
  327. package/dist/esm/TruncatedOutput.js +257 -0
  328. package/dist/esm/TruncatedOutput.js.map +1 -0
  329. package/dist/esm/UnmovedTree.d.ts +113 -0
  330. package/dist/esm/UnmovedTree.d.ts.map +1 -0
  331. package/dist/esm/UnmovedTree.js +90 -0
  332. package/dist/esm/UnmovedTree.js.map +1 -0
  333. package/dist/esm/UnresolvedFailure.d.ts +196 -0
  334. package/dist/esm/UnresolvedFailure.d.ts.map +1 -0
  335. package/dist/esm/UnresolvedFailure.js +218 -0
  336. package/dist/esm/UnresolvedFailure.js.map +1 -0
  337. package/dist/esm/VacuousVerification.d.ts +237 -0
  338. package/dist/esm/VacuousVerification.d.ts.map +1 -0
  339. package/dist/esm/VacuousVerification.js +245 -0
  340. package/dist/esm/VacuousVerification.js.map +1 -0
  341. package/dist/esm/VariablesPanel.d.ts +117 -0
  342. package/dist/esm/VariablesPanel.d.ts.map +1 -0
  343. package/dist/esm/VariablesPanel.js +142 -0
  344. package/dist/esm/VariablesPanel.js.map +1 -0
  345. package/dist/esm/index.d.ts +172 -0
  346. package/dist/esm/index.d.ts.map +1 -0
  347. package/dist/esm/index.js +172 -0
  348. package/dist/esm/index.js.map +1 -0
  349. package/dist/esm/internal/bytes.d.ts +36 -0
  350. package/dist/esm/internal/bytes.d.ts.map +1 -0
  351. package/dist/esm/internal/bytes.js +70 -0
  352. package/dist/esm/internal/bytes.js.map +1 -0
  353. package/dist/esm/internal/cellPrompt.d.ts +122 -0
  354. package/dist/esm/internal/cellPrompt.d.ts.map +1 -0
  355. package/dist/esm/internal/cellPrompt.js +276 -0
  356. package/dist/esm/internal/cellPrompt.js.map +1 -0
  357. package/dist/esm/internal/compactable.d.ts +44 -0
  358. package/dist/esm/internal/compactable.d.ts.map +1 -0
  359. package/dist/esm/internal/compactable.js +71 -0
  360. package/dist/esm/internal/compactable.js.map +1 -0
  361. package/dist/esm/internal/compactionMarks.d.ts +278 -0
  362. package/dist/esm/internal/compactionMarks.d.ts.map +1 -0
  363. package/dist/esm/internal/compactionMarks.js +317 -0
  364. package/dist/esm/internal/compactionMarks.js.map +1 -0
  365. package/dist/esm/internal/demandText.d.ts +95 -0
  366. package/dist/esm/internal/demandText.d.ts.map +1 -0
  367. package/dist/esm/internal/demandText.js +128 -0
  368. package/dist/esm/internal/demandText.js.map +1 -0
  369. package/dist/esm/internal/elide.d.ts +109 -0
  370. package/dist/esm/internal/elide.d.ts.map +1 -0
  371. package/dist/esm/internal/elide.js +123 -0
  372. package/dist/esm/internal/elide.js.map +1 -0
  373. package/dist/esm/internal/frame.d.ts +463 -0
  374. package/dist/esm/internal/frame.d.ts.map +1 -0
  375. package/dist/esm/internal/frame.js +861 -0
  376. package/dist/esm/internal/frame.js.map +1 -0
  377. package/dist/esm/internal/nonNegativeSafeInt.d.ts +20 -0
  378. package/dist/esm/internal/nonNegativeSafeInt.d.ts.map +1 -0
  379. package/dist/esm/internal/nonNegativeSafeInt.js +20 -0
  380. package/dist/esm/internal/nonNegativeSafeInt.js.map +1 -0
  381. package/dist/esm/internal/paidUsage.d.ts +52 -0
  382. package/dist/esm/internal/paidUsage.d.ts.map +1 -0
  383. package/dist/esm/internal/paidUsage.js +72 -0
  384. package/dist/esm/internal/paidUsage.js.map +1 -0
  385. package/dist/esm/internal/printChannel.d.ts +233 -0
  386. package/dist/esm/internal/printChannel.d.ts.map +1 -0
  387. package/dist/esm/internal/printChannel.js +376 -0
  388. package/dist/esm/internal/printChannel.js.map +1 -0
  389. package/dist/esm/internal/printsObservation.d.ts +26 -0
  390. package/dist/esm/internal/printsObservation.d.ts.map +1 -0
  391. package/dist/esm/internal/printsObservation.js +29 -0
  392. package/dist/esm/internal/printsObservation.js.map +1 -0
  393. package/dist/esm/internal/refusal.d.ts +40 -0
  394. package/dist/esm/internal/refusal.d.ts.map +1 -0
  395. package/dist/esm/internal/refusal.js +47 -0
  396. package/dist/esm/internal/refusal.js.map +1 -0
  397. package/dist/esm/internal/supervision.d.ts +174 -0
  398. package/dist/esm/internal/supervision.d.ts.map +1 -0
  399. package/dist/esm/internal/supervision.js +485 -0
  400. package/dist/esm/internal/supervision.js.map +1 -0
  401. package/dist/esm/internal/unfinishedWork.d.ts +99 -0
  402. package/dist/esm/internal/unfinishedWork.d.ts.map +1 -0
  403. package/dist/esm/internal/unfinishedWork.js +85 -0
  404. package/dist/esm/internal/unfinishedWork.js.map +1 -0
  405. package/dist/esm/internal/unobservedCall.d.ts +112 -0
  406. package/dist/esm/internal/unobservedCall.d.ts.map +1 -0
  407. package/dist/esm/internal/unobservedCall.js +501 -0
  408. package/dist/esm/internal/unobservedCall.js.map +1 -0
  409. package/dist/esm/internal/untrustedData.d.ts +14 -0
  410. package/dist/esm/internal/untrustedData.d.ts.map +1 -0
  411. package/dist/esm/internal/untrustedData.js +15 -0
  412. package/dist/esm/internal/untrustedData.js.map +1 -0
  413. package/docs/README.md +129 -0
  414. package/docs/api.md +1869 -0
  415. package/docs/concepts.md +238 -0
  416. package/docs/external-transcripts.md +245 -0
  417. package/docs/guides/bind-flows.md +167 -0
  418. package/docs/guides/drive-the-loop.md +265 -0
  419. package/docs/guides/run-cells.md +262 -0
  420. package/docs/guides/workerd.md +144 -0
  421. package/docs/installation.md +69 -0
  422. package/docs/quickstart.md +121 -0
  423. package/docs/reference.md +954 -0
  424. package/docs/troubleshooting.md +177 -0
  425. package/package.json +463 -3
  426. package/src/AgentEvent.ts +1772 -0
  427. package/src/CallLedger.ts +560 -0
  428. package/src/Cell.ts +926 -0
  429. package/src/CellCalls.ts +198 -0
  430. package/src/CellHistory.ts +128 -0
  431. package/src/CellTurn.ts +4450 -0
  432. package/src/CellValidation.ts +382 -0
  433. package/src/Compaction.ts +330 -0
  434. package/src/CompletionClaim.ts +1013 -0
  435. package/src/ContextWindow.ts +669 -0
  436. package/src/EngineLike.ts +614 -0
  437. package/src/ExternalTranscript.ts +1143 -0
  438. package/src/FailedCall.ts +163 -0
  439. package/src/FlowBinding.ts +603 -0
  440. package/src/HarnessError.ts +98 -0
  441. package/src/Judgement.ts +526 -0
  442. package/src/Monitor.ts +579 -0
  443. package/src/NarrowedCheck.ts +694 -0
  444. package/src/Notifications.ts +262 -0
  445. package/src/Plan.ts +113 -0
  446. package/src/QuickJSSandbox.ts +1557 -0
  447. package/src/Relevance.ts +352 -0
  448. package/src/Sandbox.ts +908 -0
  449. package/src/Steering.ts +405 -0
  450. package/src/StructuredOutput.ts +484 -0
  451. package/src/Sufficiency.ts +247 -0
  452. package/src/Supervisor.ts +798 -0
  453. package/src/Tokens.ts +108 -0
  454. package/src/Transcript.ts +513 -0
  455. package/src/TruncatedOutput.ts +297 -0
  456. package/src/UnmovedTree.ts +121 -0
  457. package/src/UnresolvedFailure.ts +240 -0
  458. package/src/VacuousVerification.ts +280 -0
  459. package/src/VariablesPanel.ts +165 -0
  460. package/src/index.ts +204 -0
  461. package/src/internal/bytes.ts +70 -0
  462. package/src/internal/cellPrompt.ts +337 -0
  463. package/src/internal/compactable.ts +76 -0
  464. package/src/internal/compactionMarks.ts +454 -0
  465. package/src/internal/demandText.ts +145 -0
  466. package/src/internal/elide.ts +130 -0
  467. package/src/internal/frame.ts +1178 -0
  468. package/src/internal/nonNegativeSafeInt.ts +24 -0
  469. package/src/internal/paidUsage.ts +90 -0
  470. package/src/internal/printChannel.ts +434 -0
  471. package/src/internal/printsObservation.ts +31 -0
  472. package/src/internal/refusal.ts +53 -0
  473. package/src/internal/supervision.ts +652 -0
  474. package/src/internal/unfinishedWork.ts +123 -0
  475. package/src/internal/unobservedCall.ts +536 -0
  476. package/src/internal/untrustedData.ts +19 -0
@@ -0,0 +1,652 @@
1
+ /**
2
+ * The supervisor's seat beside the cell loop: a one-slot sliding queue the
3
+ * loop offers to, a forked fiber that reads the newest snapshot, scores the
4
+ * run's monitors, judges the rows it recalls and marks the transcript
5
+ * segments not yet marked, and a mailbox the next turn boundary takes a
6
+ * monitor's message, memory and marks from.
7
+ *
8
+ * The loop never awaits any of it. `offer` is a sliding enqueue and returns
9
+ * at once; `take` is a `Ref` swap. Everything Jev is asked, and everything
10
+ * that comes back, happens on the forked fiber. A run that ends with a
11
+ * reading in flight gives it `Supervisor.closeGraceMs` to settle and journal
12
+ * as the scope closes, and no longer: a reading still unanswered then is
13
+ * interrupted and journaled `supervisor-unjudged` with reason `interrupted`,
14
+ * so a Jev call that was made is never missing from the record. A snapshot
15
+ * the fiber never took is dropped and journals nothing: nobody asked.
16
+ *
17
+ * The reading is taken through `EngineLike.record`, keyed on the session,
18
+ * the frame and the cell digest, so a resumed run is handed the reading its
19
+ * original attempt recorded and never asks Jev again. The reading records
20
+ * each monitor's raw value and nothing about delivery: `Monitor.gate` runs at
21
+ * the boundary that takes it, inside that boundary's own recorded drain and
22
+ * against the ledger the run holds there, so streaks, cooldowns and limits
23
+ * count every delivery before it, a replayed boundary delivers exactly what it
24
+ * delivered the first time, and a mailbox left over from a replayed frame is
25
+ * discarded as stale rather than delivered twice. The rows a run has been shown are the boundary's to know:
26
+ * a row shown between the offer and the drain is dropped there, so no row is
27
+ * delivered twice however the readings interleave. Marks name segments by
28
+ * digest and are never stale: a boundary stores them whichever frame's
29
+ * reading they came from, and the model is not sent them.
30
+ *
31
+ * @since 1.0.0-rc.0
32
+ * @private
33
+ */
34
+
35
+ import { ModelRequest } from "@smthrs/model"
36
+ import type * as Evaluator from "@smthrs/model/Evaluator"
37
+ import type * as Descriptor from "@smthrs/registry/Descriptor"
38
+ import { Deferred, Effect, Fiber, Option, Queue, Ref, Schema, type Scope } from "effect"
39
+ import * as AgentEvent from "../AgentEvent.ts"
40
+ import type { State } from "../CellTurn.ts"
41
+ import type * as EngineLike from "../EngineLike.ts"
42
+ import * as Judgement from "../Judgement.ts"
43
+ import * as Monitor from "../Monitor.ts"
44
+ import * as Relevance from "../Relevance.ts"
45
+ import * as Supervisor from "../Supervisor.ts"
46
+ import * as UnmovedTree from "../UnmovedTree.ts"
47
+ import * as compactionMarks from "./compactionMarks.ts"
48
+ import type * as Frame from "./frame.ts"
49
+ import { paidUsage } from "./paidUsage.ts"
50
+
51
+ const eventType = AgentEvent.eventType
52
+
53
+ const nothing: Taken = { messages: [], memory: [], suppressed: [], marks: [], compact: [] }
54
+
55
+ /**
56
+ * What one frame hands the supervisor: the snapshot without its frames,
57
+ * which the handle keeps, and the cell digest the record is keyed on.
58
+ *
59
+ * @since 1.0.0-rc.0
60
+ * @private
61
+ */
62
+ export interface Offer {
63
+ readonly frame: number
64
+ readonly digest: string
65
+ /** The frame just closed; the handle keeps the ones before it. */
66
+ readonly current: Supervisor.Frame
67
+ readonly snapshot: Omit<Supervisor.Snapshot, "frames">
68
+ /** Keys of the memory rows the run had been shown when the frame closed; never asked about. */
69
+ readonly shown: ReadonlyArray<string>
70
+ /** The head of the frame's prose, which the relevance reading is told as `recent`. */
71
+ readonly recent: string
72
+ /** Whether more than `Supervisor.skillLimit` skills could have been offered. */
73
+ readonly skillsCapped: boolean
74
+ /**
75
+ * The transcript segments the run has no answer about yet, each once by
76
+ * digest; empty unless the host holds a real judge.
77
+ */
78
+ readonly unmarked: ReadonlyArray<{ readonly digest: string; readonly item: compactionMarks.Item }>
79
+ /** The labels of the checks still failing when the frame closed, which the marks reading is told. */
80
+ readonly failing: ReadonlyArray<string>
81
+ }
82
+
83
+ /**
84
+ * What one boundary takes from the mailbox.
85
+ *
86
+ * @since 1.0.0-rc.0
87
+ * @private
88
+ */
89
+ export interface Taken {
90
+ /** The delivered monitor's message, then each memory row delivered. */
91
+ readonly messages: ReadonlyArray<ModelRequest.Message>
92
+ /** Keys of the memory rows delivered, in order. */
93
+ readonly memory: ReadonlyArray<string>
94
+ /** The monitor whose message leads `messages`, when one was delivered. */
95
+ readonly monitor?: string
96
+ /** Crossed monitors withheld, and why. */
97
+ readonly suppressed: Monitor.Gated["suppressed"]
98
+ /** The ledger after gating a reading; absent when no reading was gated. */
99
+ readonly ledger?: Monitor.Ledger
100
+ /** Jev's answers about the segments the reading marked. */
101
+ readonly marks: ReadonlyArray<compactionMarks.Marking>
102
+ /** The context triggers the reading fired, which compact the run at its next frame. */
103
+ readonly compact: ReadonlyArray<Supervisor.ContextTrigger>
104
+ }
105
+
106
+ /**
107
+ * The loop's two calls into the supervisor.
108
+ *
109
+ * @since 1.0.0-rc.0
110
+ * @private
111
+ */
112
+ export interface Handle {
113
+ /** Slides this frame's snapshot into the one-slot queue and returns at once. */
114
+ readonly offer: (offer: Offer) => Effect.Effect<void>
115
+ /**
116
+ * What the boundary closing `frame` delivers from the newest reading when
117
+ * that reading is of this frame or the one before, nothing otherwise: the
118
+ * one message `Monitor.gate` lets through against `ledger`, the run's
119
+ * ledger as the boundary holds it, then the memory rows. A row whose key is
120
+ * in `shown`, the run's shown set as the boundary holds it, is dropped, and
121
+ * nothing is gated or delivered unless `deliver`. A reading Jev could not
122
+ * take gates nothing. Takes the mailbox either way, so a stale reading is
123
+ * dropped and never delivered later; its marks are taken all the same.
124
+ * A delivered reading's context triggers are taken beside its message.
125
+ */
126
+ readonly take: (
127
+ frame: number,
128
+ options: {
129
+ readonly ledger: Monitor.Ledger
130
+ readonly shown: ReadonlyArray<string>
131
+ readonly deliver: boolean
132
+ }
133
+ ) => Effect.Effect<Taken>
134
+ }
135
+
136
+ const MonitorRow = Schema.Struct({
137
+ id: Schema.String,
138
+ kind: AgentEvent.MonitorKind,
139
+ p: Schema.Number,
140
+ crossed: Schema.Boolean
141
+ })
142
+
143
+ const MonitorCandidate = Schema.Struct({
144
+ id: Schema.String,
145
+ kind: AgentEvent.MonitorKind,
146
+ priority: Schema.Number,
147
+ p: Schema.Number,
148
+ text: Schema.String
149
+ })
150
+
151
+ /** Everything one recorded reading holds, so a replay re-emits and re-delivers it. */
152
+ const Recorded = Schema.Struct({
153
+ settled: Schema.NullOr(AgentEvent.SupervisorSettled),
154
+ decision: Schema.NullOr(AgentEvent.DecisionSettled),
155
+ unjudged: Schema.NullOr(AgentEvent.SupervisorUnjudged),
156
+ /** The relevance reading of the recalled rows; null when none was asked or it failed. */
157
+ memory: Schema.NullOr(AgentEvent.RelevanceSettled),
158
+ memoryDecisions: Schema.Array(AgentEvent.DecisionSettled),
159
+ memoryUnjudged: Schema.NullOr(AgentEvent.DecisionUnjudged),
160
+ /** The recalled rows not withheld: every row when the reading failed. */
161
+ memoryRows: Schema.Array(Supervisor.Recalled),
162
+ /** Every monitor's value in the reading; empty when the reading failed. */
163
+ monitorRows: Schema.Array(MonitorRow),
164
+ /** The crossed monitors' messages, ungated; the boundary gates them. */
165
+ monitorCandidates: Schema.Array(MonitorCandidate),
166
+ /** The answers of the marks reading; empty when none was asked or it failed. */
167
+ marks: Schema.Array(compactionMarks.Marking),
168
+ marksDecisions: Schema.Array(AgentEvent.DecisionSettled),
169
+ marksUnjudged: Schema.NullOr(AgentEvent.DecisionUnjudged)
170
+ })
171
+
172
+ type Recorded = typeof Recorded.Type
173
+
174
+ interface Mailbox {
175
+ readonly frame: number
176
+ /** What the monitors said; absent when Jev could not take the reading. */
177
+ readonly monitors: Monitor.Evaluation | undefined
178
+ /** The monitors the reading scored, which the boundary gates against. */
179
+ readonly declared: ReadonlyArray<Monitor.Monitor>
180
+ readonly rows: ReadonlyArray<Supervisor.Recalled>
181
+ readonly marks: ReadonlyArray<compactionMarks.Marking>
182
+ /** The context triggers the reading fired; empty when Jev could not take it. */
183
+ readonly compact: ReadonlyArray<Supervisor.ContextTrigger>
184
+ }
185
+
186
+ /**
187
+ * The counts the deterministic controls keep, read off the state the frame
188
+ * closed on. Nothing is re-derived: every field is a state field, a ledger
189
+ * length, or a filter over a ledger the harness already wrote.
190
+ *
191
+ * @since 1.0.0-rc.0
192
+ * @private
193
+ */
194
+ export const signals = (
195
+ state: State,
196
+ facts: Frame.Accounting["facts"],
197
+ workspaceDigest: string,
198
+ paths: number
199
+ ): Supervisor.Signals => ({
200
+ frame: state.frame,
201
+ maxFrames: state.maxFrames,
202
+ readOnlyFrames: facts.readOnlyFrames,
203
+ repeatFrames: facts.repeatFrames,
204
+ mutations: facts.mutations,
205
+ remoteMutations: facts.remoteMutations,
206
+ treeMoved: UnmovedTree.find({
207
+ opened: facts.openingDigest,
208
+ digest: workspaceDigest,
209
+ elsewhere: facts.remoteMutations
210
+ }) === undefined,
211
+ paths,
212
+ checksRun: facts.checks.length,
213
+ checksFailing: facts.checks.filter((check) => check.failing).length,
214
+ failuresUnanswered: facts.failures.length,
215
+ callsFailed: facts.callLedger.filter((entry) => !entry.ok).length,
216
+ callsSettled: facts.callLedger.length,
217
+ narrowingDemands: state.narrowingDemands,
218
+ unmovedDemands: state.unmovedDemands,
219
+ unresolvedDemands: state.unresolvedDemands,
220
+ claimDemands: state.claimDemands,
221
+ sufficiencyStated: state.sufficiencyStated
222
+ })
223
+
224
+ /**
225
+ * Whether one ledger subject names `path`. The subject is the call's target
226
+ * as `CallLedger.subject` clipped it, so a path longer than `CallLedger.width`
227
+ * survives only as its head and an elision notice, and an input no sole
228
+ * target was lexed from is quoted whole, with the path inside it (#2028).
229
+ *
230
+ * @since 1.0.0-rc.0
231
+ * @private
232
+ */
233
+ const namesPath = (subject: string, path: string): boolean => {
234
+ if (subject.includes(path)) return true
235
+ const elided = subject.indexOf("… [+")
236
+ return elided > 0 && path.startsWith(subject.slice(0, elided))
237
+ }
238
+
239
+ /**
240
+ * What a snapshot says about the frame's catalog: the Markdown skills the
241
+ * model may call and has not — neither called by name nor read through a
242
+ * `read` call on the skill's path — sorted by name and at most
243
+ * `Supervisor.skillLimit` of them, offered only when `read` is in the catalog
244
+ * to read them with; the distinct flows the ledger names, newest
245
+ * `Supervisor.calledLimit` of them; and whether `jev` is in the catalog.
246
+ *
247
+ * @since 1.0.0-rc.0
248
+ * @private
249
+ */
250
+ export const catalog = (
251
+ flows: ReadonlyArray<Descriptor.FlowDescriptor>,
252
+ ledger: ReadonlyArray<{ readonly flow: string; readonly subject: string }>
253
+ ): Pick<Supervisor.Snapshot, "skills" | "called" | "jevAvailable"> & { readonly capped: boolean } => {
254
+ const called = [...new Set(ledger.map((entry) => entry.flow))]
255
+ const readable = flows.some((descriptor) => descriptor.name === "read")
256
+ // A skill read through `read` is as called as one invoked by name: the
257
+ // reminder says to read it, and the ledger is where that read shows.
258
+ const readSubjects = ledger.flatMap((entry) => entry.flow === "read" ? [entry.subject] : [])
259
+ const skills = readable
260
+ ? flows
261
+ .filter((descriptor) =>
262
+ descriptor.modelInvocable && descriptor.body._tag === "Markdown" && !called.includes(descriptor.name) &&
263
+ !readSubjects.some((subject) => namesPath(subject, descriptor.body.path))
264
+ )
265
+ .sort((a, b) => a.name < b.name ? -1 : 1)
266
+ : []
267
+ return {
268
+ skills: skills.slice(0, Supervisor.skillLimit).map((descriptor) =>
269
+ Supervisor.skill(descriptor.name, descriptor.description, descriptor.body.path)
270
+ ),
271
+ called: called.slice(-Supervisor.calledLimit),
272
+ jevAvailable: flows.some((descriptor) => descriptor.name === "jev"),
273
+ capped: skills.length > Supervisor.skillLimit
274
+ }
275
+ }
276
+
277
+ /**
278
+ * Opens the supervisor beside the loop: the queue, the mailbox, and the
279
+ * forked fiber that serves them. Requires a scope, which is the loop's own,
280
+ * so closing the loop closes the fiber.
281
+ *
282
+ * @since 1.0.0-rc.0
283
+ * @private
284
+ */
285
+ export const open = (input: {
286
+ readonly session: string
287
+ readonly engine: EngineLike.EngineLike
288
+ readonly emit: (event: AgentEvent.AgentEvent) => Effect.Effect<void>
289
+ /** The host's monitors; each reading adds `Monitor.skills` of its snapshot and `Monitor.useJev`. */
290
+ readonly monitors: ReadonlyArray<Monitor.Monitor>
291
+ /** Whether a monitor's message and memory inserts reach the run: the host holds a real judge. */
292
+ readonly deliver: boolean
293
+ }): Effect.Effect<Handle, never, Scope.Scope | Evaluator.Evaluator> =>
294
+ Effect.gen(function*() {
295
+ const { deliver, emit, engine, monitors, session } = input
296
+ const mailbox = yield* Ref.make<Option.Option<Mailbox>>(Option.none())
297
+ // The host's monitors, then one per skill the snapshot offers, then the
298
+ // use-jev lint: what one reading asks and scores and its boundary gates.
299
+ const scored = (snapshot: Supervisor.Snapshot): ReadonlyArray<Monitor.Monitor> => [
300
+ ...monitors,
301
+ ...Monitor.skills(snapshot),
302
+ Monitor.useJev()
303
+ ]
304
+ const memory = yield* Supervisor.Memory
305
+ // The evaluator the loop was given, captured once so the fiber asks the
306
+ // same transport the completion brake does.
307
+ const services = yield* Effect.context<Evaluator.Evaluator>()
308
+ // The newest frames ahead of the one just closed, kept in memory: they
309
+ // are evidence for a reading nothing replays, so durable state need not
310
+ // carry them. A resumed run's first snapshots see fewer frames, which is
311
+ // the honest reading of a past this process did not witness.
312
+ const recent: Array<Supervisor.Frame> = []
313
+ // Digests this fiber has marked. A segment is offered until a boundary
314
+ // stores its answer, and a reading that lags the loop would otherwise
315
+ // ask about it again each frame.
316
+ const marked = new Set<string>()
317
+ // The frame whose reading the fiber is taking, and a latch released when
318
+ // that reading is done, whatever it came to. Read only by the scope's
319
+ // closing grace below.
320
+ const inFlight = yield* Ref.make<Option.Option<{ readonly frame: number; readonly done: Deferred.Deferred<void> }>>(
321
+ Option.none()
322
+ )
323
+ // Which readings last failed for want of a judge. A host with none says so
324
+ // once, not every frame; the next reading still asks, so a judge connected
325
+ // mid-run is used at once, and any other failure is journaled every time.
326
+ const unconfigured = new Set<"supervisor" | "memory" | "marks">()
327
+ const repeated = (
328
+ reading: "supervisor" | "memory" | "marks",
329
+ unjudged: { readonly reason: string } | null,
330
+ answered: boolean
331
+ ): boolean => {
332
+ if (unjudged?.reason === "unconfigured") {
333
+ const seen = unconfigured.has(reading)
334
+ unconfigured.add(reading)
335
+ return seen
336
+ }
337
+ if (unjudged !== null || answered) unconfigured.delete(reading)
338
+ return false
339
+ }
340
+
341
+ // A store that refused a read is journaled, typed, and the reading goes
342
+ // on: memory is the supervisor's aid, not its evidence.
343
+ const recallFailed = (frame: number, failure: Supervisor.MemoryFailure) =>
344
+ emit(
345
+ new AgentEvent.SupervisorMemoryFailed({
346
+ eventType: eventType.supervisorMemoryFailed,
347
+ scope: session,
348
+ frame,
349
+ operation: "recall",
350
+ detail: failure.detail
351
+ })
352
+ )
353
+
354
+ const supervise = (offer: Offer & { readonly frames: ReadonlyArray<Supervisor.Frame> }): Effect.Effect<void> =>
355
+ Effect.gen(function*() {
356
+ const snapshot: Supervisor.Snapshot = { ...offer.snapshot, frames: offer.frames }
357
+ const declared = scored(snapshot)
358
+ const unmarked = offer.unmarked.filter(({ digest }) => !marked.has(digest))
359
+ const recorded = yield* engine.record({
360
+ name: "supervisor",
361
+ identity: { session, frame: offer.frame, boundary: `supervisor:${offer.digest}` },
362
+ success: Recorded,
363
+ // This fiber drops a failed record, so a spent budget is applied by
364
+ // the frame's next primary call rather than parked here (#3010).
365
+ advisory: true,
366
+ // The monitors' reading, then each relevance and marks request: every
367
+ // reading the boundary took is one the run paid for.
368
+ usage: (record) =>
369
+ paidUsage([
370
+ record.settled?.usage,
371
+ ...(record.unjudged?.usage ?? []),
372
+ ...record.memoryDecisions.map((settled) => settled.usage),
373
+ ...(record.memoryUnjudged?.usage ?? []),
374
+ ...record.marksDecisions.map((settled) => settled.usage),
375
+ ...(record.marksUnjudged?.usage ?? [])
376
+ ]),
377
+ execute: Effect.gen(function*() {
378
+ // The task does not change between frames, so the store ranks the
379
+ // same rows first each time: it is asked past every row already
380
+ // shown, and a row shown once is never asked about again.
381
+ const recalled = memory.bound
382
+ ? yield* memory.recall(
383
+ [offer.snapshot.task, offer.recent].filter(Boolean).join("\n").slice(-16_384),
384
+ Supervisor.recalledLimit + offer.shown.length
385
+ ).pipe(
386
+ Effect.catch((failure) => Effect.as(recallFailed(offer.frame, failure), []))
387
+ )
388
+ : []
389
+ const rows = recalled.filter((row) => !offer.shown.includes(row.key)).slice(0, Supervisor.recalledLimit)
390
+ const [result, relevance, marking] = yield* Effect.all([
391
+ Effect.result(Supervisor.read(snapshot, Monitor.questions(declared, snapshot))),
392
+ rows.length === 0 ? Effect.succeed(undefined) : Effect.result(
393
+ Relevance.judge(
394
+ { task: snapshot.task, recent: offer.recent },
395
+ rows.map((row): Relevance.Item => ({ kind: "memory", id: row.key, text: row.text }))
396
+ )
397
+ ),
398
+ unmarked.length === 0 ? Effect.succeed(undefined) : Effect.result(
399
+ compactionMarks.read(
400
+ { task: snapshot.task, failing: offer.failing },
401
+ unmarked.map(({ item }) => item)
402
+ )
403
+ )
404
+ ], { concurrency: 3 }).pipe(Effect.provideContext(services))
405
+ const at = { scope: session, frame: offer.frame }
406
+ // Marking changes nothing the model is sent, so no decision acts.
407
+ const marksRecord = marking === undefined
408
+ ? { marks: [], marksDecisions: [], marksUnjudged: null }
409
+ : marking._tag === "Failure"
410
+ ? {
411
+ marks: [],
412
+ marksDecisions: [],
413
+ marksUnjudged: Judgement.unjudgedEvent(marking.failure, {
414
+ ...at,
415
+ classifier: "compaction/marks",
416
+ items: unmarked.length
417
+ })
418
+ }
419
+ : {
420
+ marks: unmarked.map(({ digest }, index) => ({ digest, ...marking.success.answers[index]! })),
421
+ marksDecisions: marking.success.asked.map((asked) =>
422
+ Judgement.decision(asked, { ...at, acted: false })
423
+ ),
424
+ marksUnjudged: null
425
+ }
426
+ const memoryRecord = relevance === undefined
427
+ ? { memory: null, memoryDecisions: [], memoryUnjudged: null, memoryRows: [] }
428
+ : relevance._tag === "Failure"
429
+ ? {
430
+ memory: null,
431
+ memoryDecisions: [],
432
+ memoryUnjudged: Judgement.unjudgedEvent(relevance.failure, {
433
+ ...at,
434
+ classifier: "relevance/unnecessary",
435
+ items: rows.length
436
+ }),
437
+ memoryRows: rows
438
+ }
439
+ : {
440
+ memory: Relevance.settled(relevance.success, { ...at, source: "supervisor" }),
441
+ memoryDecisions: relevance.success.asked.map((asked) =>
442
+ Judgement.decision(asked, {
443
+ ...at,
444
+ acted: relevance.success.verdicts.some((verdict) => verdict.withheld)
445
+ })
446
+ ),
447
+ memoryUnjudged: null,
448
+ memoryRows: rows.filter((_, index) => !relevance.success.verdicts[index]!.withheld)
449
+ }
450
+ if (result._tag === "Failure") {
451
+ const record: Recorded = {
452
+ settled: null,
453
+ decision: null,
454
+ unjudged: new AgentEvent.SupervisorUnjudged({
455
+ eventType: eventType.supervisorUnjudged,
456
+ ...at,
457
+ reason: result.failure.reason,
458
+ detail: result.failure.detail,
459
+ ...(result.failure.usage === undefined ? {} : { usage: result.failure.usage })
460
+ }),
461
+ ...memoryRecord,
462
+ ...marksRecord,
463
+ monitorRows: [],
464
+ monitorCandidates: []
465
+ }
466
+ return record
467
+ }
468
+ const reading = result.success
469
+ const evaluation = Monitor.evaluate({ monitors: declared, reading, snapshot, values: reading.monitors })
470
+ // Whether a monitor's message is handed to the boundary, which may
471
+ // still withhold it for its streak, cooldown, limit or slot.
472
+ const nudged = deliver && evaluation.candidates.length > 0
473
+ const record: Recorded = {
474
+ settled: new AgentEvent.SupervisorSettled({
475
+ eventType: eventType.supervisorSettled,
476
+ ...at,
477
+ thrashing: reading.thrashing,
478
+ onTarget: reading.onTarget,
479
+ suspect: reading.suspect,
480
+ outdatedContext: reading.outdatedContext,
481
+ irrelevantContext: reading.irrelevantContext,
482
+ ...reading.emotions,
483
+ needsHelp: reading.needsHelp,
484
+ crossed: evaluation.rows.some((row) => row.crossed),
485
+ nudged,
486
+ steer: deliver,
487
+ latencyMs: reading.latencyMs,
488
+ ...(reading.usage === undefined ? {} : { usage: reading.usage }),
489
+ monitors: evaluation.rows,
490
+ ...(offer.skillsCapped ? { skillsCapped: true } : {})
491
+ }),
492
+ decision: new AgentEvent.DecisionSettled({
493
+ eventType: eventType.decisionSettled,
494
+ ...at,
495
+ classifier: Supervisor.classifier.id,
496
+ digest: reading.asked.digest,
497
+ state: reading.asked.state,
498
+ questions: reading.asked.questions,
499
+ answers: reading.asked.answers,
500
+ latencyMs: reading.latencyMs,
501
+ acted: nudged,
502
+ decidedBy: "jev"
503
+ }),
504
+ unjudged: null,
505
+ ...memoryRecord,
506
+ ...marksRecord,
507
+ monitorRows: evaluation.rows,
508
+ monitorCandidates: evaluation.candidates
509
+ }
510
+ return record
511
+ })
512
+ })
513
+ // Posted before anything is journaled: an observer's checkpoint sits
514
+ // inside `emit`, and a boundary that wakes on the settled event must
515
+ // find the reading already waiting for it. Every reading Jev took is
516
+ // posted, crossed or not, so the boundary's gate sees each monitor's
517
+ // streak move.
518
+ for (const { digest } of recorded.marks) marked.add(digest)
519
+ if (recorded.settled !== null || recorded.memoryRows.length > 0 || recorded.marks.length > 0) {
520
+ // A reading replaces the one no boundary took, but not its marks.
521
+ yield* Ref.update(mailbox, (held) =>
522
+ Option.some({
523
+ frame: offer.frame,
524
+ declared,
525
+ monitors: recorded.settled === null
526
+ ? undefined
527
+ : { rows: recorded.monitorRows, candidates: recorded.monitorCandidates },
528
+ rows: recorded.memoryRows,
529
+ compact: recorded.settled === null ? [] : Supervisor.compacting({
530
+ ...recorded.settled,
531
+ outdatedContext: recorded.settled.outdatedContext ?? 0,
532
+ irrelevantContext: recorded.settled.irrelevantContext ?? 0
533
+ }),
534
+ marks: [...Option.match(held, { onNone: () => [], onSome: (value) => value.marks }), ...recorded.marks]
535
+ }))
536
+ }
537
+ // The verdict is the last thing this fiber does with a reading: the
538
+ // full decisions and the memory reading go ahead of it, so a host that
539
+ // acts on the verdict the moment it is checkpointed never finds the
540
+ // record behind it missing.
541
+ const quiet = {
542
+ memory: repeated("memory", recorded.memoryUnjudged, recorded.memory !== null),
543
+ marks: repeated("marks", recorded.marksUnjudged, recorded.marksDecisions.length > 0),
544
+ supervisor: repeated("supervisor", recorded.unjudged, recorded.settled !== null)
545
+ }
546
+ if (recorded.decision !== null) yield* emit(recorded.decision)
547
+ for (const decision of recorded.memoryDecisions) yield* emit(decision)
548
+ if (recorded.memory !== null) yield* emit(recorded.memory)
549
+ if (recorded.memoryUnjudged !== null && !quiet.memory) yield* emit(recorded.memoryUnjudged)
550
+ for (const decision of recorded.marksDecisions) yield* emit(decision)
551
+ if (recorded.marksUnjudged !== null && !quiet.marks) yield* emit(recorded.marksUnjudged)
552
+ if (recorded.unjudged !== null && !quiet.supervisor) yield* emit(recorded.unjudged)
553
+ if (recorded.settled !== null) yield* emit(recorded.settled)
554
+ }).pipe(
555
+ // A reading the fiber could not even record is logged and dropped:
556
+ // the supervisor may not fail the run it watches.
557
+ Effect.catchCause((cause) =>
558
+ Effect.annotateLogs(Effect.logWarning("A supervisor reading could not be recorded", cause), {
559
+ frame: offer.frame
560
+ })
561
+ )
562
+ )
563
+
564
+ const offers = yield* Queue.make<Offer & { readonly frames: ReadonlyArray<Supervisor.Frame> }>({
565
+ capacity: 1,
566
+ strategy: "sliding"
567
+ })
568
+ // The reading the fiber was taking when it was interrupted, if it was.
569
+ const cut = yield* Ref.make<Option.Option<number>>(Option.none())
570
+ const serve = (offer: Offer & { readonly frames: ReadonlyArray<Supervisor.Frame> }) =>
571
+ Effect.gen(function*() {
572
+ const done = yield* Deferred.make<void>()
573
+ yield* Ref.set(inFlight, Option.some({ frame: offer.frame, done }))
574
+ yield* supervise(offer).pipe(
575
+ Effect.onInterrupt(() => Ref.set(cut, Option.some(offer.frame))),
576
+ Effect.ensuring(Ref.set(inFlight, Option.none()).pipe(Effect.andThen(Deferred.succeed(done, undefined))))
577
+ )
578
+ })
579
+ const fiber = yield* Effect.forkScoped(Effect.forever(Effect.flatMap(Queue.take(offers), serve)))
580
+ // Registered after the fork, so it runs before the fork's own interruption:
581
+ // a finalizer added later runs earlier. A reading in flight gets the grace
582
+ // to settle and journal itself; one still unanswered after it is
583
+ // interrupted and journaled as such. Nothing here waits past the grace.
584
+ yield* Effect.addFinalizer(() =>
585
+ Effect.gen(function*() {
586
+ const held = yield* Ref.get(inFlight)
587
+ if (Option.isSome(held)) {
588
+ yield* Deferred.await(held.value.done).pipe(Effect.timeoutOption(Supervisor.closeGraceMs))
589
+ }
590
+ yield* Fiber.interrupt(fiber)
591
+ const interrupted = yield* Ref.get(cut)
592
+ if (Option.isNone(interrupted)) return
593
+ yield* emit(
594
+ new AgentEvent.SupervisorUnjudged({
595
+ eventType: eventType.supervisorUnjudged,
596
+ scope: session,
597
+ frame: interrupted.value,
598
+ reason: "interrupted",
599
+ detail:
600
+ `The run ended with this reading in flight; it was interrupted after a ${Supervisor.closeGraceMs} ms grace.`
601
+ })
602
+ )
603
+ })
604
+ )
605
+
606
+ return {
607
+ offer: (offer) =>
608
+ Effect.suspend(() => {
609
+ // Fixed at offer time, on the loop's fiber, so the snapshot is of
610
+ // the frames as they stood when this one closed whatever the fiber
611
+ // reaches it.
612
+ const frames = [...recent.slice(-(Supervisor.recentFrames - 1)), offer.current]
613
+ recent.push(offer.current)
614
+ if (recent.length > Supervisor.recentFrames) recent.splice(0, recent.length - Supervisor.recentFrames)
615
+ return Effect.asVoid(Queue.offer(offers, { ...offer, frames }))
616
+ }),
617
+ take: (frame, { deliver, ledger, shown }) =>
618
+ Ref.modify(mailbox, (held): readonly [Taken, Option.Option<Mailbox>] => {
619
+ if (Option.isNone(held) || !deliver) return [nothing, Option.none()]
620
+ const { marks } = held.value
621
+ if (held.value.frame < frame - 1) return [{ ...nothing, marks }, Option.none()]
622
+ const rows = held.value.rows.filter((row) => !shown.includes(row.key))
623
+ const gated = held.value.monitors === undefined
624
+ ? undefined
625
+ : Monitor.gate({ ...held.value.monitors, monitors: held.value.declared, ledger, frame })
626
+ const message = gated?.message
627
+ return [{
628
+ messages: [...(message === undefined ? [] : [message.text]), ...rows.map(Supervisor.recalledInsert)].map((
629
+ text
630
+ ) => ModelRequest.Message.user(text)),
631
+ memory: rows.map((row) => row.key),
632
+ ...(message === undefined ? {} : { monitor: message.id }),
633
+ suppressed: gated?.suppressed ?? [],
634
+ ...(gated === undefined ? {} : { ledger: gated.ledger }),
635
+ marks,
636
+ compact: held.value.compact
637
+ }, Option.none()]
638
+ })
639
+ }
640
+ })
641
+
642
+ /**
643
+ * A handle for a loop that supervises nothing: offers are dropped and every
644
+ * boundary takes nothing.
645
+ *
646
+ * @since 1.0.0-rc.0
647
+ * @private
648
+ */
649
+ export const none: Handle = {
650
+ offer: () => Effect.void,
651
+ take: () => Effect.succeed(nothing)
652
+ }