@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,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/internal/frame.ts"],
4
+ "sourcesContent": ["/**\n * The decisions one controller frame takes from what it measured.\n *\n * `CellTurn` seals a model step and runs a cell, and both need a model, a\n * sandbox and an engine. What the frame decides from the result needs none of\n * them: what it did to the run's ledgers, whether a completion is handed back,\n * and which interventions the next frame is handed are functions of the state\n * the frame opened on and the facts it measured. Each phase here returns a\n * value, events included, instead of writing a variable a later exit reads, so\n * each one is read and tested without running a frame.\n *\n * @since 1.0.0-rc.0\n * @private\n */\n\nimport { ModelRequest } from \"@smthrs/model\"\nimport type * as Evaluator from \"@smthrs/model/Evaluator\"\nimport { Effect, Option, type Schema } from \"effect\"\nimport * as AgentEvent from \"../AgentEvent.ts\"\nimport * as CallLedger from \"../CallLedger.ts\"\nimport type { State } from \"../CellTurn.ts\"\nimport * as CompletionClaim from \"../CompletionClaim.ts\"\nimport type * as ContextWindow from \"../ContextWindow.ts\"\nimport type * as EngineLike from \"../EngineLike.ts\"\nimport * as FailedCall from \"../FailedCall.ts\"\nimport type * as HarnessError from \"../HarnessError.ts\"\nimport * as NarrowedCheck from \"../NarrowedCheck.ts\"\nimport * as Sufficiency from \"../Sufficiency.ts\"\nimport * as TruncatedOutput from \"../TruncatedOutput.ts\"\nimport * as UnmovedTree from \"../UnmovedTree.ts\"\nimport * as UnresolvedFailure from \"../UnresolvedFailure.ts\"\nimport * as VariablesPanel from \"../VariablesPanel.ts\"\nimport * as bytes from \"./bytes.ts\"\nimport * as DemandText from \"./demandText.ts\"\nimport * as elide from \"./elide.ts\"\nimport { paidTogether } from \"./paidUsage.ts\"\nimport * as UnfinishedWork from \"./unfinishedWork.ts\"\nimport * as UnobservedCall from \"./unobservedCall.ts\"\n\n/** The one journal-event-type table; see `AgentEvent.eventType`. */\nconst eventType = AgentEvent.eventType\n\n/**\n * The fields of controller state one step changes; everything else is carried.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport type StateChanges = Partial<ConstructorParameters<typeof State>[0]>\n\n/**\n * Whether the frame budget leaves a frame after this one.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport const hasNextFrame = (state: State): boolean => state.maxFrames === 0 || state.frame + 1 < state.maxFrames\n\n/**\n * Whether a completion can be handed back: a frame is left to answer in, and\n * spending it cannot end the run at the read-only cap. See `judgeCompletion`.\n *\n * @since 1.0.0-rc.1\n * @private\n */\nexport const handBackRoom = (state: State, readOnlyFrames: number): boolean =>\n hasNextFrame(state) && (state.readOnlyCap === 0 || readOnlyFrames + 1 < state.readOnlyCap * 2)\n\n/**\n * One call a cell made this frame, as the frame's accounting reads it.\n *\n * Every call the frame settles is remembered so a raise can hand the model its\n * partial work. Without this, one uncaught throw discarded the frame's reads\n * and the next cell re-did them \u2014 often raising the same way again. Prime\n * Agent's tool errors return stdout-so-far plus the traceback for exactly this\n * reason.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport interface ObservedCall {\n readonly flow: string\n readonly ok: boolean\n readonly summary: string\n /** Where this call lands in the run's ledger, so a salvage line can name it. */\n readonly ordinal: number\n /**\n * Whether the call reached the engine declaring a write, which is what\n * breaks a read-only run. A call the boundary refused is not one: it\n * declared a write and performed none.\n */\n readonly mutates: boolean\n /**\n * Whether the write behind `mutates` was measured on a tree the host's\n * workspace walk does not cover: the result carried the reserved `mutated`\n * key, which `bash` sets by fingerprinting a container's working directory\n * either side of the command. The read-only cap counts such a write like\n * any other; the unmoved-tree demand and the claim judge need to know that\n * the host digests holding still says nothing about it.\n */\n readonly remote: boolean\n /**\n * What this invocation asked for, as `CellTurn`'s `signatureOf` names it,\n * with the tree it asked about folded in.\n *\n * The repeat ledger reads this one, because the identical command against\n * a pinned tree and against the live tree are two different questions and\n * a run that asks both has learned twice.\n */\n readonly signature: string\n /**\n * The same, with the tree left out: what the call asked, of whatever\n * tree.\n *\n * The check ledgers read this one, because `Sufficiency` matches a\n * failing reading against the passing reading that answered it, and the\n * whole shape this surface exists for takes those two readings of one\n * command over two different trees. Keyed on the tree they would never\n * meet. For a call on the live tree the two are the same string, so\n * nothing that existed before checkpoints re-keys.\n */\n readonly subject: string\n /** The checkpoint this call ran against, when it named one. */\n readonly at: string | undefined\n /** What this invocation asked for, verbatim, for the narrowing ledger. */\n readonly input: Schema.Json\n /** What the call resolved with, verbatim, for the call ledger's digest. */\n readonly value: Schema.Json\n /** What the flow said about a failure, for the call ledger's digest. */\n readonly message: string | undefined\n /** What the flow said about its own failure, when it said it ran nothing. */\n readonly invalidProbe: { readonly reason: string; readonly message: string } | undefined\n /**\n * Whether the result reported a failing exit status about its subject.\n *\n * A call that declared an invalid probe is never failing here, whatever\n * its exit status: the flow itself said the failure was about the command\n * and not about the code, so the result is not a statement about the tree\n * at all. See `UnresolvedFailure` `failed`.\n */\n readonly failing: boolean\n /**\n * Whether the result reported a passing exit status about its subject.\n *\n * Not the negation of `failing`: a flow that reports no exit status is\n * neither, and `Sufficiency` needs the difference between a check that\n * passed and a call that never checked anything. An invalid probe is\n * neither either, for the same reason it is never failing \u2014 the flow\n * itself said the result is not a statement about the tree.\n */\n readonly passing: boolean\n}\n\n/**\n * States, unambiguously, that a call this frame failed about itself.\n *\n * The whole defect this closes is that `exitCode: 1` reads the same whether the\n * bug reproduced or the command named a test that does not exist. The flow that\n * ran the command is the only party that can tell, so it says so in its result;\n * this turns that into a sentence the next frame cannot summarise away.\n */\nconst invalidProbeNotice = (calls: ReadonlyArray<ObservedCall>): string | undefined => {\n const lines = calls.flatMap((call) =>\n call.invalidProbe === undefined\n ? []\n : [`- ${call.flow} (${call.invalidProbe.reason}): ${call.invalidProbe.message}`]\n )\n if (lines.length === 0) return undefined\n return `Invalid probe \u2014 ${lines.length} call${\n lines.length === 1 ? \"\" : \"s\"\n } this frame failed about the command, not about the code:\\n${\n lines.join(\"\\n\")\n }\\nThat result is not a reproduction and is not a regression: it reads identically on a broken tree and on a fixed one, so it can neither prove the bug nor prove the repair. Repair the command before editing anything \u2014 find the real names first \u2014 and do not store it as \\`state.verification\\` or name it when you complete.`\n}\n\n/**\n * How many distinct call signatures one run carries forward.\n *\n * The ledger is durable controller state, so it is bounded. Sixty-four covers a\n * whole run at the rate a graded wave actually calls flows \u2014 its longest run\n * issued 43 calls across 24 frames \u2014 so a call is recognised as a repeat\n * however early the run first made it. A run that outlives the bound forgets\n * its oldest distinct calls first, which can cost a demand and can never\n * invent one.\n */\nconst retainedSignatures = 64\n\n/**\n * Folds one frame's signatures into the run's ledger, newest last and bounded.\n *\n * A repeated signature moves to the newest position rather than taking a\n * second slot, so a run looping on one command cannot push everything it\n * learned earlier out of the ledger.\n */\nconst remember = (\n known: ReadonlyArray<string>,\n made: ReadonlyArray<string>\n): ReadonlyArray<string> => {\n const newest = new Set(known)\n for (const digest of made) {\n newest.delete(digest)\n newest.add(digest)\n }\n const distinct = [...newest]\n return distinct.slice(Math.max(0, distinct.length - retainedSignatures))\n}\n\n/**\n * The frame's own record of what it did to the world, computed once and\n * carried out through every exit that continues the run.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport interface Accounting {\n /** Whether the frame changed the workspace, by declaration or by measurement. */\n readonly mutated: boolean\n /** The journal's record of how that answer was reached. */\n readonly observed: AgentEvent.MutationObserved\n /**\n * The digest the frame closed on, when its closing measurement covered the\n * tree; empty otherwise, which makes every demand that reads it inert.\n */\n readonly workspaceDigest: string\n /** This frame's readings of the live tree, in the order they settled. */\n readonly frameChecks: ReadonlyArray<NarrowedCheck.Check>\n /**\n * Every call the frame settled, verbatim, in the order they settled.\n *\n * The ledgers above are what a run carries forward, and they are bounded\n * and lossy on purpose: a durable check entry keeps a clipped label and two\n * exit-status flags, never a result. This is the one place the whole result\n * of a call still exists, and it exists for one frame. `CompletionClaim`\n * quotes the last check out of it; nothing else reads it.\n */\n readonly calls: ReadonlyArray<ObservedCall>\n /** The cell the frame ran, verbatim, for `FailedCall`. */\n readonly source: string\n /** The frame's own broken probes, stated once for whichever exit it takes. */\n readonly probeNotice: string | undefined\n /**\n * Every state field the frame's measurements settle.\n *\n * A continuing exit states only what it changes on top of these, so a field\n * measured here is carried whichever exit the frame leaves by. The read-only\n * streak is one of them: when each exit passed it by hand, the frame's\n * accounting was only as complete as the exit that remembered to.\n */\n readonly facts:\n & StateChanges\n & Required<\n Pick<StateChanges, \"readOnlyFrames\" | \"repeatFrames\" | \"checks\" | \"failures\" | \"mutations\" | \"remoteMutations\">\n >\n & Required<Pick<StateChanges, \"openingDigest\" | \"callLedger\" | \"reported\">>\n}\n\n/**\n * What one frame that ran a cell did to the run's ledgers.\n *\n * Read off the calls the cell made and the two workspace measurements either\n * side of them, and nothing else: no model, sandbox or engine is consulted, so\n * a replayed frame accounts exactly as its original attempt did.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport const account = (options: {\n /** The state the frame opened on. */\n readonly state: State\n /** Every call the cell made, in the order they settled. */\n readonly calls: ReadonlyArray<ObservedCall>\n /** The workspace before the frame's calls. */\n readonly opened: Option.Option<EngineLike.Observation>\n /** The workspace after them. */\n readonly closed: Option.Option<EngineLike.Observation>\n /** Ids of the trees the frame pinned, oldest first. */\n readonly minted: ReadonlyArray<string>\n /** What the realm holds after the frame, for the variables panel. */\n readonly bindings: ReadonlyArray<VariablesPanel.Binding>\n /** Output the run has been handed as a fragment, this frame's included. */\n readonly captures: ReadonlyArray<TruncatedOutput.Capture>\n /** The cell the frame ran, verbatim; omitted reads as a cell that inspects nothing. */\n readonly source?: string | undefined\n}): Accounting => {\n const { calls, closed, opened, state } = options\n\n // `declaredWrites` is what the frame's calls said about themselves and the\n // measurement is what the workspace says. A measurement adds a mutation\n // nothing declared \u2014 the shell redirect this exists for \u2014 and it does not\n // take away a declaration made by a call that *succeeded*, because it does\n // not cover the whole world: it stops at a bound, it prunes directories,\n // and it is rooted at one path, so a real edit outside what it covers\n // would read as an idle frame and twice the cap later the run would fail\n // as `read_only_cap` having edited files the whole time.\n //\n // A declaration made by a call that *failed* is a different claim. It says\n // what the call would have written, and a complete measurement that saw\n // the workspace hold still contradicts it directly rather than merely\n // failing to confirm it: nothing was written, so nothing was written\n // outside the bound either. Wave 7 recorded two such frames on one\n // instance \u2014 an anchor miss reporting `Failed to find expected lines`, and\n // an edit reporting `oldString does not occur` \u2014 each of which cleared a\n // read-only streak the run had not broken. Where the measurement is\n // partial or absent the old rule stands, because then the digest holding\n // still is not evidence of anything.\n const declaredWrites = calls.filter((call) => call.mutates).length\n const measured = Option.isSome(opened) && Option.isSome(closed)\n const covered = measured && opened.value.complete && closed.value.complete\n const standingWrites = calls.filter((call) => call.mutates && (call.ok || !covered)).length\n const mutated = standingWrites > 0 || (covered && opened.value.digest !== closed.value.digest)\n // Writes the host measurement could not have seen. A failed call measured\n // nothing, so only a settled one counts; see `ObservedCall.remote`.\n const remoteWrites = calls.filter((call) => call.ok && call.mutates && call.remote).length\n const closingDigest = Option.match(closed, { onNone: () => \"\", onSome: (value) => value.digest })\n\n // The frame's own repetition, measured the same way and carried the same\n // way: a frame repeats when it issued calls, issued none this run had not\n // already issued, and changed nothing. A signature the ledger has\n // forgotten reads as new, which delays a demand and never fabricates one.\n const signatures = calls.map((call) => call.signature)\n const asked = new Set(state.callSignatures)\n const novel = signatures.some((signature) => !asked.has(signature))\n const repeatFrames = signatures.length === 0\n ? state.repeatFrames\n : novel || mutated\n ? 0\n : state.repeatFrames + 1\n\n // The frame's own checks, and the tree they were taken over.\n //\n // Only a call that succeeded and declared no write is a check: a failed\n // call observed nothing, and a call that changes the workspace is not an\n // observation of it. The digest is the frame's own closing measurement, and\n // only when that measurement covered the tree \u2014 under a partial or absent\n // one a moved digest is as likely to be a bound moving as work, and this\n // ledger's entire purpose is to say that the tree changed since a check\n // ran. An empty digest makes an entry inert rather than wrong.\n const workspaceDigest = covered ? closingDigest : \"\"\n // Where the frame's writes sit among its calls, so a check can be stamped\n // with the tree it actually read. `calls` settle in order, so a check with\n // no standing write after it read the tree the frame closed on, whatever\n // the frame did before it; a check with one after it read an earlier tree\n // and the closing digest would be somebody else's answer. A measurement\n // that moved with nothing declaring it cannot be placed among the calls at\n // all, so that frame stamps nothing as read.\n const standingAt = calls.map((call) => call.mutates && (call.ok || !covered))\n const lastStandingWrite = standingAt.lastIndexOf(true)\n const unattributedMutation = mutated && lastStandingWrite === -1\n const readings = (checkpointed: boolean) =>\n calls.flatMap((call, index) => {\n if (!call.ok || call.mutates || (call.at !== undefined) !== checkpointed) return []\n const recorded = NarrowedCheck.check({\n flow: call.flow,\n signature: call.subject,\n input: call.input,\n // A reading taken against a checkpoint is a reading of a tree that is\n // not this workspace, so it carries no workspace digest: every ledger\n // that reads one asks a question about the tree the run is standing\n // on, and an entry stamped with this frame's digest would answer that\n // question with somebody else's tree. Empty makes it inert there.\n digest: checkpointed ? \"\" : workspaceDigest,\n failing: call.failing,\n passing: call.passing,\n // Whether the tree stamped above is the tree this call read. Every\n // write the frame declared is a call with a position among these ones,\n // so the answer is positional: a check with no standing write after it\n // read the closing tree, and one with a write after it read a tree\n // that is gone. That is what lets the loop a real agent runs \u2014 edit,\n // then run the check that was red, in one frame \u2014 hold its own\n // evidence, while `check, then edit` still stamps nothing.\n //\n // A checkpointed reading is stable for a different reason: the tree it\n // read was pinned and cannot move, so the ordering is established by\n // the pin rather than by position \u2014 which is exactly what that surface\n // exists to buy, and what the run used to buy by reverting its work.\n stable: checkpointed || (!unattributedMutation && index > lastStandingWrite)\n })\n return recorded === undefined ? [] : [recorded]\n })\n const frameChecks = readings(false)\n\n return {\n mutated,\n calls,\n source: options.source ?? \"\",\n observed: new AgentEvent.MutationObserved({\n eventType: eventType.mutationObserved,\n basis: covered ? \"observed\" : measured ? \"partial\" : \"declared\",\n mutated,\n digest: closingDigest,\n paths: Option.match(closed, { onNone: () => 0, onSome: (value) => value.paths }),\n declaredWrites\n }),\n workspaceDigest,\n frameChecks,\n probeNotice: invalidProbeNotice(calls),\n facts: {\n // Seeded from what earlier frames were handed and appended to as this\n // frame's calls settled.\n truncatedOutputs: TruncatedOutput.retain(options.captures),\n workspace: closed,\n // A frame is read-only when it changed nothing; see\n // `State.readOnlyFrames` for why that is measured and not declared.\n // Once the run has written something, a read-only frame that settled a\n // call this run had not issued before holds the streak where it was: it\n // asked a new question about work that exists, which is debugging, not a\n // stall. Before the first write every read-only frame counts, because a\n // run that only ever reads new things is the failure the cap was built\n // for. Zero-call and repeat-only frames always advance it.\n readOnlyFrames: mutated\n ? 0\n : novel && state.mutations > 0\n ? state.readOnlyFrames\n : state.readOnlyFrames + 1,\n repeatFrames,\n callSignatures: remember(state.callSignatures, signatures),\n // Ids this frame pinned: a checkpoint a frame minted before it raised is\n // still a tree the run holds, and forgetting it would leak a stored tree\n // nothing can name.\n checkpointIds: options.minted.length === 0 ? state.checkpointIds : [...state.checkpointIds, ...options.minted],\n // Live readings only. Every consumer of this ledger \u2014 the narrowing\n // demand, the unresolved-failure demand, the vacuous-verification notice\n // \u2014 asks whether the tree the run is completing on was checked, and a\n // checkpointed reading is not a reading of that tree.\n checks: NarrowedCheck.remember(state.checks, frameChecks),\n // What this frame asked, folded into what the run had already asked. A\n // raise carries it too: a call that settled before the throw is work\n // the run paid for, and the ledger is the only place the next model turn\n // can read it.\n callLedger: CallLedger.remember(state.callLedger, calls),\n // Every call that reported an exit status, writes included, for the\n // claim brake. See `CompletionClaim.record`.\n reported: CompletionClaim.record(state.reported, calls),\n // Which of this frame's checks failed before any change did, and how\n // many frames have changed the workspace. Both, because this is the one\n // ledger a checkpointed reading belongs in: its whole question is an\n // ordering \u2014 this failed, then something changed, then that passed \u2014 and\n // a pinned tree answers the first half honestly from a frame that also\n // did the changing.\n failures: Sufficiency.remember(state.failures, {\n frame: [...readings(true), ...frameChecks],\n epoch: state.mutations\n }),\n mutations: state.mutations + (mutated ? 1 : 0),\n remoteMutations: state.remoteMutations + remoteWrites,\n // The tree the run was handed, fixed the first time a frame measured one\n // and never restamped. See `State.openingDigest`.\n openingDigest: state.openingDigest !== \"\"\n ? state.openingDigest\n : Option.match(opened, {\n onNone: () => \"\",\n onSome: (value) => value.complete ? value.digest : \"\"\n }),\n // The panel the next frame opens with, stamped by the frame that ran.\n panel: VariablesPanel.stamp(state.panel, options.bindings, state.frame),\n ...(mutated ? { readOnlyGrace: 0, pendingReadOnlyDemand: undefined } : {})\n }\n }\n}\n\n/**\n * The distinct terms of everything the harness itself put in front of the run.\n *\n * The prefix zone is exactly that text \u2014 the cell contract, the flow catalog,\n * memory, and the task \u2014 and nothing else: transcript, observations, and\n * compaction summaries all land in the tail, so no term a model wrote can\n * reach this set. `NarrowedCheck.findOnly` reads it as the vocabulary the run\n * was taught, which no completion may be bounced for repeating: a run that\n * invokes the runner its task prescribes, with the flag its task prescribes,\n * added no condition of its own. Prefix parts that carry no text \u2014 a tool\n * declaration, a structured message \u2014 teach no terms.\n */\nconst taughtTerms = (window: ContextWindow.ContextWindow): ReadonlyArray<string> =>\n NarrowedCheck.terms(\n window.segments\n .filter((segment) => segment.zone === \"prefix\")\n .flatMap((segment) => segment.content)\n .map((part) => \"text\" in part && typeof part.text === \"string\" ? part.text : \"\")\n .join(\"\\n\")\n )\n\n/**\n * One completion handed back, and what handing it back costs.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport interface CompletionDemand {\n /** The control event that names the demand in the journal. */\n readonly event:\n | AgentEvent.UnmovedDemanded\n | AgentEvent.UnresolvedDemanded\n | AgentEvent.FailedCallDemanded\n | AgentEvent.UnobservedDemanded\n | AgentEvent.NarrowedDemanded\n | AgentEvent.NarrowOnlyDemanded\n | AgentEvent.ClaimDemanded\n /** The in-frame observation the next frame answers. */\n readonly note: string\n /**\n * Whether the answer this demand takes away may come back as the run's\n * answer when the frame budget runs out; see `CellTurn.budgetMessage`.\n *\n * True for the measured demands except `FailedCall`, whose answer was\n * written over a call that failed. `UnobservedCall` keeps its answer: the\n * brake reads the source, not the sentence, so an answer it refused may be\n * right, and a run that ends on the budget should end on it rather than on\n * a bare notice. Each of the others says the record is\n * missing a fact, not that the sentence is wrong, so a run that spends its\n * last frame and never completes again is better served by the answer it\n * wrote than by a bare budget notice.\n *\n * For the claim brake it depends on which of its two heights fired, because\n * they mean different things. A reading between `CompletionClaim.unsupportedAt`\n * and `CompletionClaim.inventedAt` is a bounce that would let the same\n * sentence stand if the run re-stated it, so discarding it against an\n * exhausted budget would throw away an answer the brake was never going to\n * refuse. A reading at or above `inventedAt` is one the brake *would* refuse:\n * restoring that sentence on the budget notice is how one measured run turned\n * a bounced \"the tests pass\" into its final answer with a `stop` finish over a\n * repository whose test exits 1. A bounce that cannot be re-judged must not be\n * undone by the budget. See `CompletionClaim.unrecorded`.\n */\n readonly keeps: boolean\n /** The cap the demand spends. */\n readonly spent: StateChanges\n}\n\n/**\n * What judging one completion produced: at most one demand, and at most one\n * reading to journal whichever way it went.\n *\n * `observed` exists for the sixth brake alone. The five before it are derived\n * from measurements the journal already carries, so a grader recomputes them\n * and there is nothing to write when they stay silent; the claim brake asks a\n * model, and a reading nobody records is a reading nobody can grade. It is set\n * only where that brake ran and issued no demand \u2014 when it does demand, the\n * same event travels on `demand.event`, so exactly one `claim-demanded` is\n * written per evaluation.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport interface CompletionJudgement {\n /** The claim brake's reading, when it ran and issued no demand. */\n readonly observed: AgentEvent.ClaimDemanded | undefined\n /** The demand that hands the completion back, when one of the six issued. */\n readonly demand: CompletionDemand | undefined\n /**\n * The failure the run ends with when the claim brake read a claim the\n * evidence does not support and no bounce was left to spend. It travels on\n * the judgement rather than as the effect's own failure so the caller\n * journals `observed` first: a reading that ends a run is the one a grader\n * most needs, and an effect that failed would take it with it.\n */\n readonly unproven: HarnessError.HarnessError | undefined\n /**\n * The claim brake's whole decision, whenever it read one: the evidence, the\n * questions and the answers behind the three numbers `observed` or the\n * demand carries. Set on every way a reading comes out, because the record a\n * reader reopens a decision from is needed most for the one that acted.\n */\n readonly decision: AgentEvent.DecisionSettled | undefined\n /** The per-sentence decision, when the brake asked for one. */\n readonly sentenceDecision?: AgentEvent.DecisionSettled | undefined\n /**\n * Whether the completion reported its own work unfinished, when the verdict\n * asked. See `UnfinishedWork`.\n */\n readonly unfinishedDecision?: AgentEvent.DecisionSettled | undefined\n}\n\n/** Nothing to say about this completion: it stands. */\nconst stands: CompletionJudgement = {\n observed: undefined,\n demand: undefined,\n unproven: undefined,\n decision: undefined\n}\n\n/** One demand, with the brake's decision beside it when the brake issued it. */\nconst handBack = (demand: CompletionDemand, decision?: AgentEvent.DecisionSettled): CompletionJudgement => ({\n observed: undefined,\n demand,\n unproven: undefined,\n decision\n})\n\n/**\n * The prose the harness itself put in front of the run as its task.\n *\n * The `instructions` segments of the prefix zone and nothing else: `Agent`\n * writes the task there, while the cell contract, the flow catalog, the\n * project's instructions and the host's memory go in as `system` and the\n * transcript goes in the tail. So this is the closest thing the controller holds to the task as\n * the person stated it, and it cannot pick up a sentence the model wrote.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport const taskText = (window: ContextWindow.ContextWindow): string =>\n window.segments\n .filter((segment) => segment.zone === \"prefix\" && segment.kind === \"instructions\")\n .flatMap((segment) => segment.content)\n .map((part) => \"text\" in part && typeof part.text === \"string\" ? part.text : \"\")\n .filter((text) => text !== \"\")\n .join(\"\\n\\n\")\n\n/**\n * The last reading of the completing frame that reported an exit status.\n *\n * The verbatim result exists for exactly one frame, the one being judged, so\n * this is the only check the brake can quote in full, and a completing frame\n * that ran none sends none rather than sending a description of one.\n *\n * It is not the run's evidence, only the newest page of it. `CompletionClaim.record`\n * is the rest, and the two are separate because one measured live failure was\n * exactly the difference: a run that fixed the planted bug, ran the\n * repository's test, and then ran `git diff` to show its work sent the\n * `git diff` and not the test, so its true sentence reported a result nothing\n * in the payload recorded. See `CompletionClaim.Evidence`.\n */\nconst lastCheck = (calls: ReadonlyArray<ObservedCall>): CompletionClaim.Check | undefined => {\n for (let index = calls.length - 1; index >= 0; index--) {\n const call = calls[index]!\n if (!call.ok || call.mutates) continue\n const status = UnresolvedFailure.exitStatus(call.value)\n if (status === undefined) continue\n return {\n command: CompletionClaim.quote(call.input),\n exitCode: status,\n output: CompletionClaim.newest(CompletionClaim.quote(call.value))\n }\n }\n return undefined\n}\n\n/**\n * The demands a completion's own measurements produce, in precedence order \u2014\n * `FailedCall`, `UnobservedCall`, then the three below \u2014 or nothing. The\n * `UnmovedTree` demand is not one of them: an unmoved tree is the right tree\n * for a question, so it is issued only when the claim brake reads the\n * completion as unsupported. See `judgeCompletion`. Every fact read here was taken by the frame that is\n * completing or by an earlier one, so this is a pure function of the state\n * and the accounting and it is what `judgeCompletion` consults first.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nconst measuredDemand = (\n state: State,\n accounting: Accounting,\n contextWindow: ContextWindow.ContextWindow,\n nextFrame: number,\n claim: string\n): CompletionDemand | undefined => {\n const { calls, facts, frameChecks, workspaceDigest } = accounting\n // First, because the others read a record this completion was written\n // without: its own cell failed a call before the claim existed. It is the\n // one measured demand whose answer is not kept, because the answer it takes\n // away is the sentence written blind. See `FailedCall`.\n if (state.failedCallDemands < FailedCall.cap) {\n const failures = FailedCall.find(calls, claim, accounting.source)\n if (failures.length > 0) {\n return {\n event: new AgentEvent.FailedCallDemanded({\n eventType: eventType.failedCallDemanded,\n failures: failures.map((failure) => ({ flow: failure.flow, message: failure.message })),\n nextFrame\n }),\n note: FailedCall.demand(failures),\n keeps: false,\n spent: { failedCallDemands: state.failedCallDemands + 1 }\n }\n }\n }\n // Second, for the same reason: the claim was written before any result of\n // its own cell existed, so every demand below would grade a sentence the\n // model wrote without reading. Kept, unlike the one above: the source was\n // read, not the sentence, so it stays the run's answer at the budget. See\n // `UnobservedCall`.\n if (state.unobservedDemands < UnobservedCall.cap) {\n const unread = UnobservedCall.find(calls, accounting.source)\n if (unread.length > 0) {\n return {\n event: new AgentEvent.UnobservedDemanded({\n eventType: eventType.unobservedDemanded,\n calls: unread,\n nextFrame\n }),\n note: UnobservedCall.demand(unread),\n keeps: true,\n spent: { unobservedDemands: state.unobservedDemands + 1 }\n }\n }\n }\n if (state.unresolvedDemands < state.unresolvedCap) {\n const unresolved = UnresolvedFailure.find({ ledger: facts.checks, digest: workspaceDigest })\n if (unresolved !== undefined) {\n return {\n event: new AgentEvent.UnresolvedDemanded({\n eventType: eventType.unresolvedDemanded,\n flow: unresolved.failed.flow,\n failed: unresolved.failed.label,\n instead: unresolved.instead.label,\n currentDigest: workspaceDigest,\n nextFrame\n }),\n note: UnresolvedFailure.demand(unresolved),\n keeps: true,\n spent: { unresolvedDemands: state.unresolvedDemands + 1 }\n }\n }\n }\n if (state.narrowingDemands >= state.narrowingCap) return undefined\n const spent = { narrowingDemands: state.narrowingDemands + 1 }\n const narrowing = NarrowedCheck.find({ ledger: state.checks, frame: frameChecks, digest: workspaceDigest })\n if (narrowing !== undefined) {\n return {\n event: new AgentEvent.NarrowedDemanded({\n eventType: eventType.narrowedDemanded,\n flow: narrowing.earlier.flow,\n broader: narrowing.earlier.label,\n narrower: narrowing.later.label,\n broaderDigest: narrowing.earlier.digest,\n currentDigest: workspaceDigest,\n nextFrame\n }),\n note: NarrowedCheck.demand(narrowing),\n keeps: true,\n spent\n }\n }\n const only = NarrowedCheck.findOnly({\n ledger: facts.checks,\n before: state.checks.map((entry) => entry.signature),\n frame: frameChecks,\n taught: taughtTerms(contextWindow)\n })\n if (only === undefined) return undefined\n return {\n event: new AgentEvent.NarrowOnlyDemanded({\n eventType: eventType.narrowOnlyDemanded,\n flow: only.later.flow,\n check: only.later.label,\n targets: only.targets,\n currentDigest: workspaceDigest,\n nextFrame\n }),\n note: NarrowedCheck.demandOnly(only),\n keeps: true,\n spent\n }\n}\n\n/**\n * Whether a `complete` transition stands, or which demand hands it back.\n *\n * The completion's own evidence, judged once per demand. A run gets exactly\n * one frame wrong for free \u2014 the last one \u2014 and five things can be wrong with\n * it, four of them read off measurements the controller already took, under\n * four caps:\n *\n * 1. `UnmovedTree`: the tree it is completing on is the tree it opened on, so\n * there is no change for any evidence to be about. This one is not read\n * alone: a question is answered on the tree it was asked on, so it is\n * issued only where the claim brake (5) found the completion unsupported,\n * and then in the brake's place;\n * 2. `UnresolvedFailure`: a check over this exact tree reported a failing exit\n * status and the run answered it with a different reading of the same\n * subject rather than with the check itself;\n * 3. `NarrowedCheck.find`: this frame's check repeats an earlier, broader one\n * and adds conditions to it, run after a change the broader one never saw;\n * 4. `NarrowedCheck.findOnly`: the check this frame ended on is the run's only\n * reading of what it names \u2014 nothing broader was ever taken, so there was\n * no broader check for (3) to find \u2014 and it carries a condition the run\n * itself added, one taught neither by the prefix this harness wrote nor by\n * the run's own other checks.\n *\n * Demands 3 and 4 share one cap. They are two readings of one question \u2014\n * whether the evidence covers what it looks like it covers \u2014 and a run that\n * answers either has answered the question; a second bounce would be the loop\n * asking it twice in different words.\n *\n * 5. `CompletionClaim`: the last brake and the only one that is not a\n * measurement. The four above have said nothing, which means the tree\n * moved, no check was stepped around, and whatever the run checked it\n * checked whole \u2014 and none of that reads the sentence the run wrote. So\n * the claim, the task, the tree fact, every check the run took over this\n * tree and the verbatim result of the last one go to Jev, and a claim that\n * reports a command or a result none of that records hands the frame back\n * from a cap of its own. It is last because it is the only one\n * that costs a request, and because a run one of the four already named\n * has a demand to answer: asking a model to add a second one would hand\n * the frame two questions. It never falls back: a completion Jev could\n * not judge \u2014 no evaluator on the host, a refusal, a deadline, an answer\n * that does not decode \u2014 fails the turn as `completion_unjudged` carrying\n * the reason, the way `read_only_cap` ends a run, rather than standing.\n * `Evaluator` is therefore a required service of this function and of\n * every turn above it.\n *\n * The fifth is the one that is read on *every* completion, and the three\n * things below that take a demand away do not take the reading away. The\n * others are recomputable from the journal, so skipping them costs a grader\n * nothing and a skipped one lets a completion stand that the truth bar still\n * judges. This one is a sentence being checked against the record, it is what\n * the server banner and the operator docs promise happens to every completion,\n * and the run's answer is the product. So when there is no bounce left to\n * spend \u2014 the cap is used up, or none of the room below exists \u2014 a claim that\n * reports work the record does not record ends the run as `claim_unproven`\n * instead of standing. That is the shape `read_only_cap` already uses, and it\n * is the only shape that keeps the promise: a cap that stops at the bounce\n * means the second identical claim is accepted unread, which is what a live\n * run did.\n *\n * The verdict is narrower than the bounce, and that is the whole of what this\n * lane changed. A completion the brake merely finds thin is handed back once\n * and then stands; only a completion at `CompletionClaim.inventedAt` \u2014 a\n * sentence reporting a command or a result nothing in the run produced \u2014 is\n * refused. Arming the verdict on \"is the task done\" instead killed roughly one\n * honest run in four, including five question-shaped turns in a row and one\n * live CI dispatch whose planted bug was fixed. `CompletionClaim`'s header\n * carries the eighteen-state corpus that measured it.\n *\n * A thin completion that stands is still not a success when it says so\n * itself. Where the verdict is reached on a completion read as not done, one\n * more question asks whether the completion reports its own work unfinished,\n * and one that does ends the run as `completion_incomplete` quoting that\n * report, so a host never settles \"I could not finish\" as a completed run.\n * See `UnfinishedWork`.\n *\n * At most one is named, in that order, because they are in descending order of\n * how fundamental the missing thing is: there is nothing to check, then the\n * check said no, then the check said less than it looks like it said, then\n * nothing in the record matches what the run said it did. Naming two at once\n * would ask the run to answer a question it has not been given a frame for.\n *\n * The loop names what is missing and hands the frame back; it does not re-run\n * anything, and it does not judge the answer that comes back.\n *\n * Asking costs the run a frame it can answer in, so a demand is issued only\n * where that frame exists, and three separate things take it away (and leave\n * the claim brake reading anyway, as above):\n *\n * - the frame budget, which has no frame left to spend, and turning a\n * completion into an exhausted budget would lose the run's answer to make a\n * point about it;\n * - the read-only cap, which is the other budget that ends a run and ends it as\n * a typed failure carrying nothing. A run that changed nothing is exactly the\n * run `UnmovedTree` fires on, so a completion one frame short of twice the\n * cap would be bounced, spend that frame reading, and die as `read_only_cap`\n * with the answer it had already written discarded \u2014 a demand turning a\n * finished run into a failure, which is the one outcome none of these may\n * produce;\n * - a demand this run has already answered. Each demand ends by promising that\n * what comes back next is the answer that stands, and three of them fire on\n * one transition, so the frame written to answer one is never judged by the\n * next. See `State.demandedFrame`.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport const judgeCompletion = (\n state: State,\n accounting: Accounting,\n contextWindow: ContextWindow.ContextWindow,\n claim: string,\n read: typeof CompletionClaim.read = CompletionClaim.read\n): Effect.Effect<CompletionJudgement, HarnessError.HarnessError, Evaluator.Evaluator> =>\n Effect.gen(function*() {\n const { calls, facts, workspaceDigest } = accounting\n const room = handBackRoom(state, facts.readOnlyFrames) && state.demandedFrame !== state.frame\n const nextFrame = state.frame + 1\n if (room) {\n const measured = measuredDemand(state, accounting, contextWindow, nextFrame, claim)\n // A measured demand names a missing fact, so the answer it takes away\n // is worth restoring if the budget runs out, unless the demand says the\n // answer was written blind. See `CompletionDemand`.\n if (measured !== undefined) return handBack(measured)\n }\n\n // The sixth brake, and the only one that leaves this package to decide.\n // `claimCap` of zero disarms it: no request, no event, no failure, which\n // is what a host that does not want a model in this path asks for.\n if (state.claimCap === 0) return stands\n // A host may put prior conversation before the current request. Keep\n // both ends of the task; clipping its head alone can leave only history.\n // Reserve the elision notice inside the task's byte budget.\n const originalTask = taskText(contextWindow).trim()\n const recallTask = \"the run record has the whole task\"\n const task = elide.middle(\n originalTask,\n CompletionClaim.proseBytes - elide.noticeCost(bytes.size(originalTask), recallTask),\n recallTask\n )\n const check = lastCheck(calls)\n const unmovedTree = UnmovedTree.find({\n opened: facts.openingDigest,\n digest: workspaceDigest,\n elsewhere: facts.remoteMutations\n })\n const evidence: CompletionClaim.Evidence = {\n task,\n claim: CompletionClaim.prose(claim),\n // The `UnmovedTree` fact, read the other way round. An unmeasured tree\n // reads as moved, which is the reading that asks for nothing.\n treeMoved: unmovedTree === undefined,\n checksRun: facts.reported,\n callsRun: facts.callLedger.map((entry) => ({\n flow: entry.flow,\n input: entry.subject,\n ok: entry.ok,\n resultSummary: entry.digest\n })),\n ...(check === undefined ? {} : { lastCheck: check })\n }\n const reading = yield* read(evidence)\n if (reading === undefined) return stands\n const found = CompletionClaim.find(reading)\n // One bounce while the cap and a frame allow it; the verdict after that,\n // and only over the readings the verdict is about.\n const bounced = found !== undefined && room && state.claimDemands < state.claimCap\n // An unmoved tree alone is not a demand: a read-only question is answered\n // on exactly the tree it was asked on, and bouncing that answer discarded\n // correct replies (#2937). The tree fact names what is missing only when\n // this reading found the claim unsupported, and then its wording is the\n // more precise of the two, so it takes the bounce while its cap lasts and\n // the reading is journaled beside it as one that did not demand.\n const unmoved = found !== undefined && room && state.unmovedDemands < state.unmovedCap\n ? unmovedTree\n : undefined\n // The third way a reading comes out, stated on the event because nothing\n // downstream can derive it: a reading that neither stands nor hands the\n // frame back is the one that ends the run, and a projection that could not\n // tell it from a reading that stood wrote no card for it. See\n // `AgentEvent.ClaimDemanded.refused`.\n const refused = found !== undefined && !bounced && unmoved === undefined && CompletionClaim.unrecorded(found)\n // A completion read as not done, with no bounce left and nothing to\n // refuse, used to stand here whatever it said, so a run reporting its own\n // work unfinished settled as a completed one (#3009). Whether it said so\n // is one more question, asked only here; see `UnfinishedWork`.\n const unfinished = found !== undefined && !bounced && unmoved === undefined && !refused &&\n reading.complete <= CompletionClaim.disprovenAt\n ? yield* UnfinishedWork.read(evidence, reading.usage)\n : undefined\n const incomplete = unfinished !== undefined && unfinished.unfinished >= UnfinishedWork.reportedAt\n const usage = paidTogether(reading.usage, unfinished?.usage)\n const event = new AgentEvent.ClaimDemanded({\n eventType: eventType.claimDemanded,\n complete: reading.complete,\n overclaims: reading.overclaims,\n invented: reading.invented,\n latencyMs: reading.latencyMs + (unfinished?.latencyMs ?? 0),\n ...(usage === undefined ? {} : { usage }),\n demanded: bounced && unmoved === undefined,\n refused,\n currentDigest: workspaceDigest,\n nextFrame\n })\n // The same reading with what it was a reading OF. `acted` is the two ways\n // a reading changes what the run does next, and a reader that reported no\n // evidence journals no decision: see `CompletionClaim.Reading.asked`.\n const decision = reading.asked === undefined ? undefined : new AgentEvent.DecisionSettled({\n eventType: eventType.decisionSettled,\n scope: state.session,\n frame: state.frame,\n classifier: CompletionClaim.classifier.id,\n digest: CompletionClaim.classifier.digest,\n state: reading.asked.state,\n questions: CompletionClaim.classifier.questions,\n answers: reading.asked.answers,\n latencyMs: reading.latencyMs,\n acted: bounced || refused || unmoved !== undefined || incomplete,\n decidedBy: \"jev\"\n })\n const unfinishedDecision = unfinished === undefined ? undefined : new AgentEvent.DecisionSettled({\n eventType: eventType.decisionSettled,\n scope: state.session,\n frame: state.frame,\n classifier: unfinished.asked.classifier,\n digest: unfinished.asked.digest,\n state: unfinished.asked.state,\n questions: unfinished.asked.questions,\n answers: unfinished.asked.answers,\n latencyMs: unfinished.latencyMs,\n acted: incomplete,\n decidedBy: \"jev\"\n })\n // The per-sentence reading, journaled as its own decision because it is\n // one: its own classifier, questions and answers. See\n // `CompletionClaim.sentenceClassifier`.\n const sentenceDecision = reading.sentences === undefined ? undefined : new AgentEvent.DecisionSettled({\n eventType: eventType.decisionSettled,\n scope: state.session,\n frame: state.frame,\n classifier: reading.sentences.classifier,\n digest: reading.sentences.digest,\n state: reading.sentences.state,\n questions: reading.sentences.questions,\n answers: reading.sentences.answers,\n latencyMs: reading.sentences.latencyMs,\n acted: bounced || refused || unmoved !== undefined,\n decidedBy: \"jev\"\n })\n if (found === undefined) {\n return { observed: event, demand: undefined, unproven: undefined, decision, sentenceDecision }\n }\n if (unmoved !== undefined) {\n return {\n ...handBack({\n event: new AgentEvent.UnmovedDemanded({\n eventType: eventType.unmovedDemanded,\n openedDigest: unmoved.opened,\n currentDigest: unmoved.closed,\n nextFrame\n }),\n note: UnmovedTree.demand(unmoved),\n keeps: !CompletionClaim.unrecorded(found),\n spent: { unmovedDemands: state.unmovedDemands + 1 }\n }, decision),\n observed: event,\n sentenceDecision\n }\n }\n if (bounced) {\n return {\n ...handBack({\n event,\n note: CompletionClaim.demand(),\n // A bounce the brake would not refuse is worth restoring against an\n // exhausted budget; one it would refuse is not. See `CompletionDemand`.\n keeps: !CompletionClaim.unrecorded(found),\n spent: { claimDemands: state.claimDemands + 1 }\n }, decision),\n sentenceDecision\n }\n }\n // Out of bounces. A claim the brake only found thin stands here: it was\n // handed back once, the run answered, and refusing the answer as well is\n // the price that destroyed honest runs. Only an unrecorded claim is\n // refused, and only a completion reporting its own work unfinished fails.\n return {\n observed: event,\n demand: undefined,\n // Either bounce handed the claim back: the unmoved demand spends its\n // own cap in the claim brake's place.\n unproven: refused\n ? CompletionClaim.unproven(found, state.claimDemands + state.unmovedDemands > 0, claim)\n : incomplete\n ? UnfinishedWork.incomplete(reading.complete, unfinished.unfinished, claim)\n : undefined,\n decision,\n sentenceDecision,\n ...(unfinishedDecision === undefined ? {} : { unfinishedDecision })\n }\n })\n\n/**\n * The interventions one ordinary continuing frame hands to the next.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport interface Discipline {\n /** The control events that issue them, in journal order. */\n readonly events: ReadonlyArray<AgentEvent.AgentEvent>\n /** The messages the next frame reads after the steering it was sent. */\n readonly messages: ReadonlyArray<ModelRequest.Message>\n /** What issuing them changes on top of the frame's facts. */\n readonly changes: StateChanges\n}\n\n/**\n * The read-only, repeat and sufficiency interventions for a frame that settled\n * a `continue` transition and has a frame after it.\n *\n * The read-only intervention. At the cap the next frame is told, structurally,\n * that it must write something or say why it cannot; a justification is typed\n * data on the transition, is recorded, and buys a bounded quiet spell without\n * resetting the counter that ends the run at twice the cap.\n *\n * A justification buys that spell only when it *answers* a demand this frame\n * was handed. A justification volunteered by a frame nobody asked is recorded \u2014\n * it is a field on the transition and the journal writes the whole transition \u2014\n * and buys nothing. The two cannot be the same price, because the counter runs\n * regardless of which one is written: a run that volunteers one every few\n * frames used to renew the quiet spell before the streak could ever hand the\n * demand out, so the demand was never issued, never journaled, and never got\n * its one chance to redirect the run, while the hard stop at twice the cap \u2014\n * which no grace touches \u2014 killed the run anyway. Two SWE-bench waves lost\n * `pydata__xarray-7393` exactly so: ten volunteered justifications, zero\n * `read-only-demanded` events, and death at 24 frames against a cap of 12\n * without the control ever speaking.\n *\n * The convergence intervention. It is journaled when it is *issued* rather than\n * when the next frame answers it, because what answers it is the shape of that\n * frame's calls \u2014 which the journal already writes one by one \u2014 and not a\n * field on a transition the controller has to wait for. Issuing it restarts the\n * count, so a run that keeps repeating is told once every `repeatCap` frames\n * instead of every frame.\n *\n * The counterweight, and the only notice here that asks for nothing. It is\n * written on the frame that completes the pair rather than at a completion,\n * because its whole purpose is to reach a run that is still deciding whether to\n * keep working \u2014 a run at its `complete` transition has already decided. See\n * `Sufficiency`.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport const discipline = (\n state: State,\n accounting: Accounting,\n justification: string | undefined\n): Discipline => {\n const { facts } = accounting\n const cap = state.readOnlyCap\n const readOnly = !accounting.mutated\n const graceLeft = readOnly ? state.readOnlyGrace : 0\n const justified = readOnly && state.pendingReadOnlyDemand !== undefined &&\n (justification ?? \"\").trim().length > 0\n // Only a frame that advanced the streak earns the demand: a probing frame\n // holds the streak where it was, and repeating the demand to it every frame\n // would nag a run the cap has already decided is working.\n const advanced = readOnly && facts.readOnlyFrames > state.readOnlyFrames\n const demanded = cap > 0 && advanced && facts.readOnlyFrames >= cap && graceLeft === 0 && !justified\n const repeated = state.repeatCap > 0 && facts.repeatFrames >= state.repeatCap\n const sufficient = state.sufficiencyStated\n ? undefined\n : Sufficiency.find({ ledger: facts.failures, frame: accounting.frameChecks, epoch: facts.mutations })\n const nextFrame = state.frame + 1\n return {\n events: [\n ...(demanded\n ? [\n new AgentEvent.ReadOnlyDemandIssued({\n eventType: eventType.readOnlyDemandIssued,\n streak: facts.readOnlyFrames,\n cap,\n nextFrame\n })\n ]\n : []),\n ...(repeated\n ? [\n new AgentEvent.RepeatDemanded({\n eventType: eventType.repeatDemanded,\n frames: facts.repeatFrames,\n cap: state.repeatCap,\n nextFrame\n })\n ]\n : []),\n ...(sufficient === undefined ? [] : [\n new AgentEvent.SufficiencyObserved({\n eventType: eventType.sufficiencyObserved,\n flow: sufficient.failed.flow,\n failed: sufficient.failed.label,\n passed: sufficient.passed.label,\n epoch: sufficient.failed.epoch,\n nextFrame\n })\n ])\n ],\n messages: [\n ...(accounting.probeNotice === undefined ? [] : [ModelRequest.Message.user(accounting.probeNotice)]),\n ...(demanded ? [ModelRequest.Message.user(DemandText.readOnly(cap, facts.readOnlyFrames))] : []),\n ...(repeated ? [ModelRequest.Message.user(DemandText.repeat(facts.repeatFrames, state.repeatCap))] : []),\n ...(sufficient === undefined ? [] : [ModelRequest.Message.user(Sufficiency.observation(sufficient))])\n ],\n changes: {\n readOnlyGrace: justified ? cap : Math.max(0, graceLeft - 1),\n repeatFrames: repeated ? 0 : facts.repeatFrames,\n ...(sufficient === undefined ? {} : { sufficiencyStated: true }),\n pendingReadOnlyDemand: demanded ? { streak: facts.readOnlyFrames, cap } : undefined\n }\n }\n}\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AC,IAAI,CAAC,0BAAa,QAAQ,KAAK,WAAW,WAAW,CAAC;AAAA,MAClG,GAAI,WAAW,CAAC,0BAAa,QAAQ,KAAK,WAAW,SAAS,KAAK,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC;AAAA,MAC9F,GAAI,WAAW,CAAC,0BAAa,QAAQ,KAAK,WAAW,OAAO,MAAM,cAAc,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC;AAAA,MACtG,GAAI,eAAe,SAAY,CAAC,IAAI,CAAC,0BAAa,QAAQ,KAAK,YAAY,YAAY,UAAU,CAAC,CAAC;AAAA,IACrG;AAAA,IACA,SAAS;AAAA,MACP,eAAe,YAAY,MAAM,KAAK,IAAI,GAAG,YAAY,CAAC;AAAA,MAC1D,cAAc,WAAW,IAAI,MAAM;AAAA,MACnC,GAAI,eAAe,SAAY,CAAC,IAAI,EAAE,mBAAmB,KAAK;AAAA,MAC9D,uBAAuB,WAAW,EAAE,QAAQ,MAAM,gBAAgB,IAAI,IAAI;AAAA,IAC5E;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The bound every journaled count in this package is declared with.
3
+ *
4
+ * A count that crossed the safe-integer ceiling would compare and re-encode
5
+ * wrongly on the way back out of a journal, so every ordinal, frame number,
6
+ * byte count and cap is admitted through one validator rather than six copies
7
+ * that happened to agree.
8
+ *
9
+ * @since 1.0.0-rc.0
10
+ * @private
11
+ */
12
+ import { Schema } from "effect";
13
+ /**
14
+ * A count in `[0, Number.MAX_SAFE_INTEGER]`.
15
+ *
16
+ * @since 1.0.0-rc.0
17
+ * @private
18
+ */
19
+ export declare const NonNegativeSafeInt: Schema.Int;
20
+ //# sourceMappingURL=nonNegativeSafeInt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nonNegativeSafeInt.d.ts","sourceRoot":"","sources":["../../../src/internal/nonNegativeSafeInt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,YAG9B,CAAA"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var nonNegativeSafeInt_exports = {};
20
+ __export(nonNegativeSafeInt_exports, {
21
+ NonNegativeSafeInt: () => NonNegativeSafeInt
22
+ });
23
+ module.exports = __toCommonJS(nonNegativeSafeInt_exports);
24
+ var import_effect = require("effect");
25
+ const NonNegativeSafeInt = import_effect.Schema.Int.check(
26
+ import_effect.Schema.isGreaterThanOrEqualTo(0),
27
+ import_effect.Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)
28
+ );
29
+ //# sourceMappingURL=nonNegativeSafeInt.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/internal/nonNegativeSafeInt.ts"],
4
+ "sourcesContent": ["/**\n * The bound every journaled count in this package is declared with.\n *\n * A count that crossed the safe-integer ceiling would compare and re-encode\n * wrongly on the way back out of a journal, so every ordinal, frame number,\n * byte count and cap is admitted through one validator rather than six copies\n * that happened to agree.\n *\n * @since 1.0.0-rc.0\n * @private\n */\n\nimport { Schema } from \"effect\"\n\n/**\n * A count in `[0, Number.MAX_SAFE_INTEGER]`.\n *\n * @since 1.0.0-rc.0\n * @private\n */\nexport const NonNegativeSafeInt = Schema.Int.check(\n Schema.isGreaterThanOrEqualTo(0),\n Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)\n)\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,oBAAuB;AAQhB,MAAM,qBAAqB,qBAAO,IAAI;AAAA,EAC3C,qBAAO,uBAAuB,CAAC;AAAA,EAC/B,qBAAO,oBAAoB,OAAO,gBAAgB;AACpD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The model usage a recorded boundary paid for, summed over its readings.
3
+ *
4
+ * @since 1.0.0-rc.1
5
+ * @private
6
+ */
7
+ import type * as Classifier from "@smthrs/model/Classifier";
8
+ import * as Evaluator from "@smthrs/model/Evaluator";
9
+ import type * as EngineLike from "../EngineLike.ts";
10
+ /**
11
+ * One reading's metered usage and the model that read it; absent when the
12
+ * transport reported none.
13
+ *
14
+ * @since 1.0.0-rc.1
15
+ * @private
16
+ */
17
+ export type Metered = {
18
+ readonly inputTokens: number;
19
+ readonly outputTokens: number;
20
+ readonly modelId?: string | undefined;
21
+ } | undefined;
22
+ /**
23
+ * Sums the readings that were metered, one share per model in the order each
24
+ * model first read. `undefined` when none was: a reading the transport did not
25
+ * meter is not a reading that cost zero.
26
+ *
27
+ * @since 1.0.0-rc.1
28
+ * @private
29
+ */
30
+ export declare const paidUsage: (readings: ReadonlyArray<Metered>) => ReadonlyArray<EngineLike.Paid> | undefined;
31
+ /**
32
+ * What two readings of one completion paid together. Either may come back
33
+ * unmetered; the completion costs what was metered. Both ask the same judge,
34
+ * so the sum keeps its model id, and drops it only when a fallback answered
35
+ * one.
36
+ *
37
+ * @since 1.0.0-rc.1
38
+ * @private
39
+ */
40
+ export declare const paidTogether: (first: Evaluator.Usage | undefined, second: Evaluator.Usage | undefined) => Evaluator.Usage | undefined;
41
+ /**
42
+ * A reading that failed, as the typed cause its turn fails with: the
43
+ * transport's code and structured facts, its public message (a transport's
44
+ * own text can name hosts and URLs), and what it paid with what the
45
+ * `earlier` readings of the same completion paid, so the run's budget
46
+ * charges both (#3010).
47
+ *
48
+ * @since 1.0.0-rc.1
49
+ * @private
50
+ */
51
+ export declare const failedReading: (error: Classifier.ClassifierError, earlier: Evaluator.Usage | undefined) => Evaluator.EvaluatorError;
52
+ //# sourceMappingURL=paidUsage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paidUsage.d.ts","sourceRoot":"","sources":["../../../src/internal/paidUsage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,KAAK,UAAU,MAAM,0BAA0B,CAAA;AAC3D,OAAO,KAAK,SAAS,MAAM,yBAAyB,CAAA;AACpD,OAAO,KAAK,KAAK,UAAU,MAAM,kBAAkB,CAAA;AAEnD;;;;;;GAMG;AACH,MAAM,MAAM,OAAO,GACf;IAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACtG,SAAS,CAAA;AAEb;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GAAI,UAAU,aAAa,CAAC,OAAO,CAAC,KAAG,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,SAY7F,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GACvB,OAAO,SAAS,CAAC,KAAK,GAAG,SAAS,EAClC,QAAQ,SAAS,CAAC,KAAK,GAAG,SAAS,KAClC,SAAS,CAAC,KAAK,GAAG,SASpB,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,UAAU,CAAC,eAAe,EACjC,SAAS,SAAS,CAAC,KAAK,GAAG,SAAS,KACnC,SAAS,CAAC,cASZ,CAAA"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var paidUsage_exports = {};
30
+ __export(paidUsage_exports, {
31
+ failedReading: () => failedReading,
32
+ paidTogether: () => paidTogether,
33
+ paidUsage: () => paidUsage
34
+ });
35
+ module.exports = __toCommonJS(paidUsage_exports);
36
+ var Evaluator = __toESM(require("@smthrs/model/Evaluator"), 1);
37
+ const paidUsage = (readings) => {
38
+ const shares = /* @__PURE__ */ new Map();
39
+ for (const reading of readings) {
40
+ if (reading === void 0) continue;
41
+ const share = shares.get(reading.modelId);
42
+ shares.set(reading.modelId, {
43
+ inputTokens: (share?.inputTokens ?? 0) + reading.inputTokens,
44
+ outputTokens: (share?.outputTokens ?? 0) + reading.outputTokens
45
+ });
46
+ }
47
+ if (shares.size === 0) return void 0;
48
+ return [...shares].map(([modelId, usage]) => modelId === void 0 ? { usage } : { usage, modelId });
49
+ };
50
+ const paidTogether = (first, second) => {
51
+ if (first === void 0) return second;
52
+ if (second === void 0) return first;
53
+ const modelId = first.modelId === second.modelId ? first.modelId : void 0;
54
+ return {
55
+ inputTokens: first.inputTokens + second.inputTokens,
56
+ outputTokens: first.outputTokens + second.outputTokens,
57
+ ...modelId === void 0 ? {} : { modelId }
58
+ };
59
+ };
60
+ const failedReading = (error, earlier) => {
61
+ const usage = paidTogether(earlier, error.usage);
62
+ return new Evaluator.EvaluatorError({
63
+ code: error.code,
64
+ message: Evaluator.publicMessage(error),
65
+ ...error.resetAtEpochMillis === void 0 ? {} : { resetAtEpochMillis: error.resetAtEpochMillis },
66
+ ...error.status === void 0 ? {} : { status: error.status },
67
+ ...usage === void 0 ? {} : { usage }
68
+ });
69
+ };
70
+ //# sourceMappingURL=paidUsage.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/internal/paidUsage.ts"],
4
+ "sourcesContent": ["/**\n * The model usage a recorded boundary paid for, summed over its readings.\n *\n * @since 1.0.0-rc.1\n * @private\n */\n\nimport type * as Classifier from \"@smthrs/model/Classifier\"\nimport * as Evaluator from \"@smthrs/model/Evaluator\"\nimport type * as EngineLike from \"../EngineLike.ts\"\n\n/**\n * One reading's metered usage and the model that read it; absent when the\n * transport reported none.\n *\n * @since 1.0.0-rc.1\n * @private\n */\nexport type Metered =\n | { readonly inputTokens: number; readonly outputTokens: number; readonly modelId?: string | undefined }\n | undefined\n\n/**\n * Sums the readings that were metered, one share per model in the order each\n * model first read. `undefined` when none was: a reading the transport did not\n * meter is not a reading that cost zero.\n *\n * @since 1.0.0-rc.1\n * @private\n */\nexport const paidUsage = (readings: ReadonlyArray<Metered>): ReadonlyArray<EngineLike.Paid> | undefined => {\n const shares = new Map<string | undefined, { inputTokens: number; outputTokens: number }>()\n for (const reading of readings) {\n if (reading === undefined) continue\n const share = shares.get(reading.modelId)\n shares.set(reading.modelId, {\n inputTokens: (share?.inputTokens ?? 0) + reading.inputTokens,\n outputTokens: (share?.outputTokens ?? 0) + reading.outputTokens\n })\n }\n if (shares.size === 0) return undefined\n return [...shares].map(([modelId, usage]) => modelId === undefined ? { usage } : { usage, modelId })\n}\n\n/**\n * What two readings of one completion paid together. Either may come back\n * unmetered; the completion costs what was metered. Both ask the same judge,\n * so the sum keeps its model id, and drops it only when a fallback answered\n * one.\n *\n * @since 1.0.0-rc.1\n * @private\n */\nexport const paidTogether = (\n first: Evaluator.Usage | undefined,\n second: Evaluator.Usage | undefined\n): Evaluator.Usage | undefined => {\n if (first === undefined) return second\n if (second === undefined) return first\n const modelId = first.modelId === second.modelId ? first.modelId : undefined\n return {\n inputTokens: first.inputTokens + second.inputTokens,\n outputTokens: first.outputTokens + second.outputTokens,\n ...(modelId === undefined ? {} : { modelId })\n }\n}\n\n/**\n * A reading that failed, as the typed cause its turn fails with: the\n * transport's code and structured facts, its public message (a transport's\n * own text can name hosts and URLs), and what it paid with what the\n * `earlier` readings of the same completion paid, so the run's budget\n * charges both (#3010).\n *\n * @since 1.0.0-rc.1\n * @private\n */\nexport const failedReading = (\n error: Classifier.ClassifierError,\n earlier: Evaluator.Usage | undefined\n): Evaluator.EvaluatorError => {\n const usage = paidTogether(earlier, error.usage)\n return new Evaluator.EvaluatorError({\n code: error.code,\n message: Evaluator.publicMessage(error),\n ...(error.resetAtEpochMillis === undefined ? {} : { resetAtEpochMillis: error.resetAtEpochMillis }),\n ...(error.status === undefined ? {} : { status: error.status }),\n ...(usage === undefined ? {} : { usage })\n })\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,gBAA2B;AAsBpB,MAAM,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
+ * The print channel: how a REPL frame's `console.log` calls become the bytes
3
+ * its successor reads.
4
+ *
5
+ * Two jobs live here, and both were priced off the `rerun-r95repl` lane rather
6
+ * than chosen.
7
+ *
8
+ * Every number here is a count of UTF-8 bytes, which is what the frame bound
9
+ * and the retention ceiling both mean by "bytes": the notices this module writes
10
+ * carry a `…`, three bytes wide and one UTF-16 unit, and counting them in units
11
+ * put a frame one byte over its own ceiling.
12
+ *
13
+ * **Sharing the frame budget.** Statements used to cap independently at 4 KiB
14
+ * each, head-first, under a 16 KiB frame bound that almost nobody reached: 197
15
+ * of the lane's 357 printing frames had a statement cut, 191 of those while the
16
+ * frame bound sat mostly unspent, and 3.06 MB went to per-statement caps against
17
+ * 6 frames that ever reached the frame one. Head-first is the part that cost
18
+ * verdicts — `sympy__sympy-13878` fused one `console.log` of 38,928 bytes whose
19
+ * head was a Python deprecation banner, so what it lost was the tail: the result
20
+ * of a three-minute test suite the same frame had just paid for, and the `git
21
+ * diff` that would have shown it the edit was already in the tree. It re-ran
22
+ * that suite four frames later. So the statements of a frame share one budget,
23
+ * each is elided from the middle, and no ceiling moves: 16 KiB was the most a
24
+ * frame could deliver before and it is the most now.
25
+ *
26
+ * **Compacting a printed structure.** A result printed whole is mostly repeated
27
+ * keys — a grep hit names `file`, `line`, `text` once per match — so an array of
28
+ * matches renders as file groups with numbered hits and context; other records
29
+ * render as a table with the union of keys named once. It is keyed on the shape
30
+ * and nothing else — this module knows no flow. Repeated keys save bytes;
31
+ * sparse records with mostly distinct keys can cost more as a table.
32
+ *
33
+ * @since 0.1.0
34
+ * @private
35
+ * @slop
36
+ */
37
+ import type { Schema } from "effect";
38
+ /**
39
+ * How many UTF-8 bytes of one frame's whole print buffer reach the next model turn.
40
+ *
41
+ * This is the only ceiling on the channel. A frame's statements *share* it:
42
+ * each is middle-elided to the share it is apportioned, and a statement short
43
+ * of its share hands the remainder back to the statements that are over theirs.
44
+ *
45
+ * They used to cap independently at 4 KiB each, head-first, and the r95repl
46
+ * lane priced that: 197 of its 357 printing frames had a statement cut, 191 of
47
+ * them while this frame budget sat mostly unspent, and 3.06 MB went to
48
+ * per-statement caps against 6 frames that ever reached this one. The
49
+ * `sympy__sympy-13878` run fused one `console.log` of 38,928 bytes; it was
50
+ * shown the first 4,096 and lost the tail, which held the result of a
51
+ * three-minute test suite the frame had already paid for. It ran that suite
52
+ * again four frames later. Sharing the budget shows that frame 16 KiB from both
53
+ * ends instead of 4 KiB from the head, and moves no ceiling: 16 KiB was the
54
+ * most a frame could ever deliver before, and it is the most now.
55
+ *
56
+ * Every elision is from the middle with the dropped byte count stated, because
57
+ * the head and the tail of a log are where it identifies itself, and the notices
58
+ * are reserved out of this budget before any of it is apportioned — so the
59
+ * assembled buffer is bounded outright and nothing has to shorten it a second
60
+ * time. Sized against the `recall` budget it replaces, and delivered once rather
61
+ * than re-rendered every frame.
62
+ *
63
+ * @category constants
64
+ * @since 0.1.0
65
+ */
66
+ export declare const printFrameBytes: number;
67
+ /**
68
+ * The smallest UTF-8-byte share of {@link printFrameBytes} one print statement is given.
69
+ *
70
+ * A share below this is all notice and no value — a middle elision of 80 bytes
71
+ * says less than the sentence explaining it — so a frame that printed more
72
+ * statements than the budget can floor drops whole statements from the middle
73
+ * and states how many, rather than cutting every one of them to nothing. That
74
+ * is the same shape the frame bound already had, applied a statement at a time
75
+ * so nothing is cut mid-line.
76
+ *
77
+ * It bounds how many statements are *kept*, but it is not a division of the
78
+ * budget: how many a frame can carry is priced off the statements it actually
79
+ * printed, so a statement at or under this size is shown whole and costs only
80
+ * itself. Two hundred eight-byte lines cost eighteen hundred bytes and all two
81
+ * hundred survive; sixty statements of four times this size do not, and whole
82
+ * ones go from the middle rather than every one of them being cut to a notice.
83
+ *
84
+ * @category constants
85
+ * @since 0.1.0
86
+ * @slop
87
+ */
88
+ export declare const printStatementFloor = 512;
89
+ /**
90
+ * How many UTF-8 bytes of one frame's print buffer the host keeps while the cell still runs.
91
+ *
92
+ * {@link printFrameBytes} bounds what the model is shown; this bounds what the
93
+ * host holds to show it from, and the two are different numbers because they
94
+ * answer different questions. A cell printing in a loop hands the host one
95
+ * payload per statement, and every payload is copied out of the sandbox's heap
96
+ * and decoded before anything can judge it surplus, so the frame budget alone
97
+ * bounds the answer while leaving the work unbounded. Sixteen times the frame
98
+ * budget is far past any honest use and still a fixed ceiling: past it the
99
+ * payload is not read at all, and the count of what went unread is stated in the
100
+ * buffer rather than dropped in silence.
101
+ *
102
+ * A statement is held at no more than {@link printFrameBytes} — the two ends of
103
+ * it, with the size it had — because a whole frame's budget is the most any one
104
+ * statement could ever be shown. So this ceiling holds at least sixteen
105
+ * statements whatever a cell prints, and a cell that prints many small values
106
+ * reaches it only after hundreds of them.
107
+ *
108
+ * @category constants
109
+ * @since 0.1.0
110
+ */
111
+ export declare const printRetainedBytes: number;
112
+ /**
113
+ * The fewest records an array needs before it is rendered as a table.
114
+ *
115
+ * Two rows do not repay a header line, and one row is not a table at all.
116
+ *
117
+ * @since 0.1.0
118
+ * @private
119
+ * @slop
120
+ */
121
+ export declare const tableRows = 3;
122
+ /**
123
+ * What the model is told when a print was cut: the value is still bound.
124
+ *
125
+ * @since 0.1.0
126
+ * @private
127
+ * @slop
128
+ */
129
+ export declare const recall = "print a narrower slice of this value; it is still bound in the realm";
130
+ /**
131
+ * One `console.log` call, as the host kept it.
132
+ *
133
+ * @since 0.1.0
134
+ * @private
135
+ * @slop
136
+ */
137
+ export interface Statement {
138
+ /** The head and tail the host kept, in order and possibly the whole thing. */
139
+ readonly text: string;
140
+ /** What the statement rendered to before anything was dropped. */
141
+ readonly bytes: number;
142
+ }
143
+ /**
144
+ * Renders an array of records as a table, or nothing.
145
+ *
146
+ * Columns are the union of keys in first-seen order. An absent member is an
147
+ * empty cell; explicit null, empty arrays and empty objects stay `null`, `[]`
148
+ * and `{}`. Cells are the string itself where that is unambiguous — no newline,
149
+ * no column separator — and canonical JSON everywhere else. An empty string
150
+ * still looks absent, and a string spelling a JSON literal still looks like
151
+ * that value: this is a log rather than a wire format, so it is not paid for in
152
+ * quoting every cell.
153
+ *
154
+ * @since 0.1.0
155
+ * @private
156
+ * @slop
157
+ */
158
+ export declare const table: (value: Schema.Json) => string | undefined;
159
+ /**
160
+ * Renders one printed JSON value compactly.
161
+ *
162
+ * A match list becomes numbered source lines; other records become a table.
163
+ * An object with exactly one such member becomes that object's other members
164
+ * as JSON, then the member's name, count and rendered list. An exact failed-call
165
+ * envelope becomes its code, message and optional hint. Everything else is
166
+ * canonical JSON as before.
167
+ *
168
+ * Tables save repeated keys but pay for every column boundary, including
169
+ * absent members. The three-row, two-column floor saves bytes for uniform
170
+ * records; it does not guarantee savings for sparse records. Rendering stays
171
+ * shape-based rather than comparing both encodings.
172
+ *
173
+ * @since 0.1.0
174
+ * @private
175
+ * @slop
176
+ */
177
+ export declare const render: (value: Schema.Json) => string;
178
+ /**
179
+ * Apportions one budget across statements of the given sizes.
180
+ *
181
+ * Short statements take what they need and hand the remainder back, so a frame
182
+ * that printed one long value and three short ones spends the budget on the long
183
+ * one. Allocation runs shortest first, which is what makes the hand-back
184
+ * possible, and the result is in the order the sizes were given.
185
+ *
186
+ * @since 0.1.0
187
+ * @private
188
+ * @slop
189
+ */
190
+ export declare const shares: (sizes: ReadonlyArray<number>, budget: number) => ReadonlyArray<number>;
191
+ /**
192
+ * How many of *these* statements a budget can keep at the floor, head first.
193
+ *
194
+ * A count of the statements in hand rather than a constant, because what a
195
+ * statement costs is what it is. Taken as `printFrameBytes / printStatementFloor`
196
+ * it was 32 whatever a frame printed, so a frame of two hundred eight-byte lines
197
+ * dropped a hundred and sixty-eight of them while fifteen of its sixteen
198
+ * kilobytes went unspent — the failure the shared budget exists to end,
199
+ * reintroduced one level up. Two hundred lines that cost nine bytes each cost
200
+ * eighteen hundred, and the budget keeps every one of them.
201
+ *
202
+ * The walk takes the head, then the tail, then the head again, which is the
203
+ * order {@link buffer} assembles them in, so a budget that affords an odd number
204
+ * spends the odd one on the earlier statement.
205
+ *
206
+ * @since 0.1.0
207
+ * @private
208
+ * @slop
209
+ */
210
+ export declare const capacity: (statements: ReadonlyArray<Statement>, budget: number) => number;
211
+ /**
212
+ * Assembles what a frame printed, bounded by {@link printFrameBytes}.
213
+ *
214
+ * `unread` is the count of statements the host stopped copying out of the realm
215
+ * because the frame had already handed over more than it holds. It is stated
216
+ * rather than dropped, because a buffer that simply stopped reads as a cell that
217
+ * simply stopped printing.
218
+ *
219
+ * The bound holds by construction rather than by a second pass over the result,
220
+ * because a second pass would cut a notice in half and that is the one thing a
221
+ * bound may not do. {@link capacity} charges every kept statement the floor it is
222
+ * promised, the notice it would print and its newline; what survives that walk is
223
+ * therefore affordable, and the apportionment below spends only what the walk
224
+ * left. A statement at or under the floor is shown whole and reserves no notice
225
+ * at all — reserving one apiece is what left a frame of short lines nothing to
226
+ * spend on the lines themselves.
227
+ *
228
+ * @since 0.1.0
229
+ * @private
230
+ * @slop
231
+ */
232
+ export declare const buffer: (statements: ReadonlyArray<Statement>, unread: number) => string;
233
+ //# sourceMappingURL=printChannel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printChannel.d.ts","sourceRoot":"","sources":["../../../src/internal/printChannel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAIpC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,eAAe,QAAY,CAAA;AAExC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAA;AAEtC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,kBAAkB,QAAa,CAAA;AAE5C;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,IAAI,CAAA;AAE1B;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,yEAAyE,CAAA;AAE5F;;;;;;GAMG;AACH,MAAM,WAAW,SA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