@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,24 @@
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
+
13
+ import { Schema } from "effect"
14
+
15
+ /**
16
+ * A count in `[0, Number.MAX_SAFE_INTEGER]`.
17
+ *
18
+ * @since 1.0.0-rc.0
19
+ * @private
20
+ */
21
+ export const NonNegativeSafeInt = Schema.Int.check(
22
+ Schema.isGreaterThanOrEqualTo(0),
23
+ Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)
24
+ )
@@ -0,0 +1,90 @@
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
+
8
+ import type * as Classifier from "@smthrs/model/Classifier"
9
+ import * as Evaluator from "@smthrs/model/Evaluator"
10
+ import type * as EngineLike from "../EngineLike.ts"
11
+
12
+ /**
13
+ * One reading's metered usage and the model that read it; absent when the
14
+ * transport reported none.
15
+ *
16
+ * @since 1.0.0-rc.1
17
+ * @private
18
+ */
19
+ export type Metered =
20
+ | { readonly inputTokens: number; readonly outputTokens: number; readonly modelId?: string | undefined }
21
+ | undefined
22
+
23
+ /**
24
+ * Sums the readings that were metered, one share per model in the order each
25
+ * model first read. `undefined` when none was: a reading the transport did not
26
+ * meter is not a reading that cost zero.
27
+ *
28
+ * @since 1.0.0-rc.1
29
+ * @private
30
+ */
31
+ export const paidUsage = (readings: ReadonlyArray<Metered>): ReadonlyArray<EngineLike.Paid> | undefined => {
32
+ const shares = new Map<string | undefined, { inputTokens: number; outputTokens: number }>()
33
+ for (const reading of readings) {
34
+ if (reading === undefined) continue
35
+ const share = shares.get(reading.modelId)
36
+ shares.set(reading.modelId, {
37
+ inputTokens: (share?.inputTokens ?? 0) + reading.inputTokens,
38
+ outputTokens: (share?.outputTokens ?? 0) + reading.outputTokens
39
+ })
40
+ }
41
+ if (shares.size === 0) return undefined
42
+ return [...shares].map(([modelId, usage]) => modelId === undefined ? { usage } : { usage, modelId })
43
+ }
44
+
45
+ /**
46
+ * What two readings of one completion paid together. Either may come back
47
+ * unmetered; the completion costs what was metered. Both ask the same judge,
48
+ * so the sum keeps its model id, and drops it only when a fallback answered
49
+ * one.
50
+ *
51
+ * @since 1.0.0-rc.1
52
+ * @private
53
+ */
54
+ export const paidTogether = (
55
+ first: Evaluator.Usage | undefined,
56
+ second: Evaluator.Usage | undefined
57
+ ): Evaluator.Usage | undefined => {
58
+ if (first === undefined) return second
59
+ if (second === undefined) return first
60
+ const modelId = first.modelId === second.modelId ? first.modelId : undefined
61
+ return {
62
+ inputTokens: first.inputTokens + second.inputTokens,
63
+ outputTokens: first.outputTokens + second.outputTokens,
64
+ ...(modelId === undefined ? {} : { modelId })
65
+ }
66
+ }
67
+
68
+ /**
69
+ * A reading that failed, as the typed cause its turn fails with: the
70
+ * transport's code and structured facts, its public message (a transport's
71
+ * own text can name hosts and URLs), and what it paid with what the
72
+ * `earlier` readings of the same completion paid, so the run's budget
73
+ * charges both (#3010).
74
+ *
75
+ * @since 1.0.0-rc.1
76
+ * @private
77
+ */
78
+ export const failedReading = (
79
+ error: Classifier.ClassifierError,
80
+ earlier: Evaluator.Usage | undefined
81
+ ): Evaluator.EvaluatorError => {
82
+ const usage = paidTogether(earlier, error.usage)
83
+ return new Evaluator.EvaluatorError({
84
+ code: error.code,
85
+ message: Evaluator.publicMessage(error),
86
+ ...(error.resetAtEpochMillis === undefined ? {} : { resetAtEpochMillis: error.resetAtEpochMillis }),
87
+ ...(error.status === undefined ? {} : { status: error.status }),
88
+ ...(usage === undefined ? {} : { usage })
89
+ })
90
+ }
@@ -0,0 +1,434 @@
1
+ /**
2
+ * 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
+
38
+ import { isRecord } from "@smthrs/canonical/Record"
39
+ import * as CanonicalJson from "@smthrs/model/CanonicalJson"
40
+ import type { Schema } from "effect"
41
+ import * as bytes from "./bytes.ts"
42
+ import * as elide from "./elide.ts"
43
+
44
+ /**
45
+ * How many UTF-8 bytes of one frame's whole print buffer reach the next model turn.
46
+ *
47
+ * This is the only ceiling on the channel. A frame's statements *share* it:
48
+ * each is middle-elided to the share it is apportioned, and a statement short
49
+ * of its share hands the remainder back to the statements that are over theirs.
50
+ *
51
+ * They used to cap independently at 4 KiB each, head-first, and the r95repl
52
+ * lane priced that: 197 of its 357 printing frames had a statement cut, 191 of
53
+ * them while this frame budget sat mostly unspent, and 3.06 MB went to
54
+ * per-statement caps against 6 frames that ever reached this one. The
55
+ * `sympy__sympy-13878` run fused one `console.log` of 38,928 bytes; it was
56
+ * shown the first 4,096 and lost the tail, which held the result of a
57
+ * three-minute test suite the frame had already paid for. It ran that suite
58
+ * again four frames later. Sharing the budget shows that frame 16 KiB from both
59
+ * ends instead of 4 KiB from the head, and moves no ceiling: 16 KiB was the
60
+ * most a frame could ever deliver before, and it is the most now.
61
+ *
62
+ * Every elision is from the middle with the dropped byte count stated, because
63
+ * the head and the tail of a log are where it identifies itself, and the notices
64
+ * are reserved out of this budget before any of it is apportioned — so the
65
+ * assembled buffer is bounded outright and nothing has to shorten it a second
66
+ * time. Sized against the `recall` budget it replaces, and delivered once rather
67
+ * than re-rendered every frame.
68
+ *
69
+ * @category constants
70
+ * @since 0.1.0
71
+ */
72
+ export const printFrameBytes = 16 * 1024
73
+
74
+ /**
75
+ * The smallest UTF-8-byte share of {@link printFrameBytes} one print statement is given.
76
+ *
77
+ * A share below this is all notice and no value — a middle elision of 80 bytes
78
+ * says less than the sentence explaining it — so a frame that printed more
79
+ * statements than the budget can floor drops whole statements from the middle
80
+ * and states how many, rather than cutting every one of them to nothing. That
81
+ * is the same shape the frame bound already had, applied a statement at a time
82
+ * so nothing is cut mid-line.
83
+ *
84
+ * It bounds how many statements are *kept*, but it is not a division of the
85
+ * budget: how many a frame can carry is priced off the statements it actually
86
+ * printed, so a statement at or under this size is shown whole and costs only
87
+ * itself. Two hundred eight-byte lines cost eighteen hundred bytes and all two
88
+ * hundred survive; sixty statements of four times this size do not, and whole
89
+ * ones go from the middle rather than every one of them being cut to a notice.
90
+ *
91
+ * @category constants
92
+ * @since 0.1.0
93
+ * @slop
94
+ */
95
+ export const printStatementFloor = 512
96
+
97
+ /**
98
+ * How many UTF-8 bytes of one frame's print buffer the host keeps while the cell still runs.
99
+ *
100
+ * {@link printFrameBytes} bounds what the model is shown; this bounds what the
101
+ * host holds to show it from, and the two are different numbers because they
102
+ * answer different questions. A cell printing in a loop hands the host one
103
+ * payload per statement, and every payload is copied out of the sandbox's heap
104
+ * and decoded before anything can judge it surplus, so the frame budget alone
105
+ * bounds the answer while leaving the work unbounded. Sixteen times the frame
106
+ * budget is far past any honest use and still a fixed ceiling: past it the
107
+ * payload is not read at all, and the count of what went unread is stated in the
108
+ * buffer rather than dropped in silence.
109
+ *
110
+ * A statement is held at no more than {@link printFrameBytes} — the two ends of
111
+ * it, with the size it had — because a whole frame's budget is the most any one
112
+ * statement could ever be shown. So this ceiling holds at least sixteen
113
+ * statements whatever a cell prints, and a cell that prints many small values
114
+ * reaches it only after hundreds of them.
115
+ *
116
+ * @category constants
117
+ * @since 0.1.0
118
+ */
119
+ export const printRetainedBytes = 256 * 1024
120
+
121
+ /**
122
+ * The fewest records an array needs before it is rendered as a table.
123
+ *
124
+ * Two rows do not repay a header line, and one row is not a table at all.
125
+ *
126
+ * @since 0.1.0
127
+ * @private
128
+ * @slop
129
+ */
130
+ export const tableRows = 3
131
+
132
+ /**
133
+ * What the model is told when a print was cut: the value is still bound.
134
+ *
135
+ * @since 0.1.0
136
+ * @private
137
+ * @slop
138
+ */
139
+ export const recall = "print a narrower slice of this value; it is still bound in the realm"
140
+
141
+ /**
142
+ * One `console.log` call, as the host kept it.
143
+ *
144
+ * @since 0.1.0
145
+ * @private
146
+ * @slop
147
+ */
148
+ export interface Statement {
149
+ /** The head and tail the host kept, in order and possibly the whole thing. */
150
+ readonly text: string
151
+ /** What the statement rendered to before anything was dropped. */
152
+ readonly bytes: number
153
+ }
154
+
155
+ const cell = (value: Schema.Json): string =>
156
+ typeof value === "string" && !value.includes("\n") && !value.includes("|")
157
+ ? value
158
+ : CanonicalJson.stringify(value)
159
+
160
+ /** A source line, shared by hits and their context. */
161
+ type MatchLine = { readonly line: number; readonly text: string }
162
+
163
+ /** The optional symbol attached to a source hit. */
164
+ type MatchSymbol = {
165
+ readonly kind: string
166
+ readonly name: string
167
+ readonly startLine: number
168
+ readonly endLine: number
169
+ }
170
+
171
+ /** The exact match shape; additional data must survive in the generic table. */
172
+ type Match = MatchLine & {
173
+ readonly file: string
174
+ readonly before?: ReadonlyArray<MatchLine>
175
+ readonly after?: ReadonlyArray<MatchLine>
176
+ readonly symbol?: MatchSymbol
177
+ }
178
+
179
+ const isMatchLine = (value: Schema.Json): value is MatchLine =>
180
+ isRecord<Schema.Json>(value) && Object.keys(value).length === 2 &&
181
+ Number.isInteger(value.line) && typeof value.text === "string"
182
+
183
+ const isMatchSymbol = (value: Schema.Json | undefined): value is MatchSymbol =>
184
+ isRecord<Schema.Json>(value) && Object.keys(value).length === 4 &&
185
+ typeof value.kind === "string" && typeof value.name === "string" &&
186
+ Number.isInteger(value.startLine) && Number.isInteger(value.endLine)
187
+
188
+ const isMatch = (value: Schema.Json): value is Match =>
189
+ isRecord<Schema.Json>(value) &&
190
+ typeof value.file === "string" && Number.isInteger(value.line) && typeof value.text === "string" &&
191
+ Object.keys(value).every((key) => ["file", "line", "text", "before", "after", "symbol"].includes(key)) &&
192
+ (!Object.hasOwn(value, "before") || Array.isArray(value.before) && value.before.every(isMatchLine)) &&
193
+ (!Object.hasOwn(value, "after") || Array.isArray(value.after) && value.after.every(isMatchLine)) &&
194
+ (!Object.hasOwn(value, "symbol") || isMatchSymbol(value.symbol))
195
+
196
+ /** Renders nonempty match lists in consecutive file groups, using rg's line markers. */
197
+ const matchList = (value: Schema.Json): string | undefined => {
198
+ if (!Array.isArray(value) || value.length === 0 || !value.every(isMatch)) return undefined
199
+ const lines: Array<string> = []
200
+ let previousFile: string | undefined
201
+ let previousLine = 0
202
+ for (const match of value) {
203
+ const before = match.before ?? []
204
+ const after = match.after ?? []
205
+ if (match.file !== previousFile) lines.push(match.file)
206
+ else if ((before[0]?.line ?? match.line) > previousLine + 1) lines.push("--")
207
+ for (const context of before) lines.push(`${context.line}-${context.text}`)
208
+ const symbol = match.symbol
209
+ const suffix = symbol === undefined ? "" : ` ‹${symbol.kind} ${symbol.name} ${symbol.startLine}-${symbol.endLine}›`
210
+ lines.push(`${match.line}:${match.text}${suffix}`)
211
+ for (const context of after) lines.push(`${context.line}-${context.text}`)
212
+ previousFile = match.file
213
+ previousLine = after.at(-1)?.line ?? match.line
214
+ }
215
+ return lines.join("\n")
216
+ }
217
+
218
+ /**
219
+ * Renders an array of records as a table, or nothing.
220
+ *
221
+ * Columns are the union of keys in first-seen order. An absent member is an
222
+ * empty cell; explicit null, empty arrays and empty objects stay `null`, `[]`
223
+ * and `{}`. Cells are the string itself where that is unambiguous — no newline,
224
+ * no column separator — and canonical JSON everywhere else. An empty string
225
+ * still looks absent, and a string spelling a JSON literal still looks like
226
+ * that value: this is a log rather than a wire format, so it is not paid for in
227
+ * quoting every cell.
228
+ *
229
+ * @since 0.1.0
230
+ * @private
231
+ * @slop
232
+ */
233
+ export const table = (value: Schema.Json): string | undefined => {
234
+ if (!Array.isArray(value) || value.length < tableRows) return undefined
235
+ if (!value.every(isRecord<Schema.Json>)) return undefined
236
+ const columns = [...new Set(value.flatMap((element) => Object.keys(element)))]
237
+ if (columns.length < 2) return undefined
238
+ const rows = value.map((element) =>
239
+ columns.map((column) => Object.hasOwn(element, column) ? cell(element[column]!) : "").join(" | ")
240
+ )
241
+ return `${columns.join(" | ")}\n${rows.join("\n")}`
242
+ }
243
+
244
+ /**
245
+ * Renders one printed JSON value compactly.
246
+ *
247
+ * A match list becomes numbered source lines; other records become a table.
248
+ * An object with exactly one such member becomes that object's other members
249
+ * as JSON, then the member's name, count and rendered list. An exact failed-call
250
+ * envelope becomes its code, message and optional hint. Everything else is
251
+ * canonical JSON as before.
252
+ *
253
+ * Tables save repeated keys but pay for every column boundary, including
254
+ * absent members. The three-row, two-column floor saves bytes for uniform
255
+ * records; it does not guarantee savings for sparse records. Rendering stays
256
+ * shape-based rather than comparing both encodings.
257
+ *
258
+ * @since 0.1.0
259
+ * @private
260
+ * @slop
261
+ */
262
+ export const render = (value: Schema.Json): string => {
263
+ // A string is itself, which is what `Cell.renderText` promises everywhere
264
+ // else the harness renders a projected value. The prelude sends a primitive
265
+ // string down the `text` side, so this arm answers only for a boxed one.
266
+ if (typeof value === "string") return value
267
+ const flat = matchList(value) ?? table(value)
268
+ if (flat !== undefined) return flat
269
+ if (!isRecord<Schema.Json>(value)) return CanonicalJson.stringify(value)
270
+ const error = value.error
271
+ if (
272
+ Object.keys(value).length === 2 && value.ok === false &&
273
+ isRecord<Schema.Json>(error) &&
274
+ typeof error.code === "string" && typeof error.message === "string" &&
275
+ Object.keys(error).every((key) => key === "code" || key === "message" || key === "hint") &&
276
+ (!Object.hasOwn(error, "hint") || typeof error.hint === "string")
277
+ ) {
278
+ return `failed (${error.code}): ${error.message}${Object.hasOwn(error, "hint") ? ` — hint: ${error.hint}` : ""}`
279
+ }
280
+ const tabled = Object.entries(value).flatMap(([key, member]) => {
281
+ const rendered = matchList(member) ?? table(member)
282
+ return rendered === undefined ? [] : [[key, member as ReadonlyArray<unknown>, rendered] as const]
283
+ })
284
+ if (tabled.length !== 1) return CanonicalJson.stringify(value)
285
+ const [key, member, rendered] = tabled[0]!
286
+ const rest = Object.fromEntries(Object.entries(value).filter(([name]) => name !== key))
287
+ return `${
288
+ Object.keys(rest).length === 0 ? "" : `${CanonicalJson.stringify(rest)}\n`
289
+ }${key} (${member.length}):\n${rendered}`
290
+ }
291
+
292
+ /**
293
+ * Apportions one budget across statements of the given sizes.
294
+ *
295
+ * Short statements take what they need and hand the remainder back, so a frame
296
+ * that printed one long value and three short ones spends the budget on the long
297
+ * one. Allocation runs shortest first, which is what makes the hand-back
298
+ * possible, and the result is in the order the sizes were given.
299
+ *
300
+ * @since 0.1.0
301
+ * @private
302
+ * @slop
303
+ */
304
+ export const shares = (sizes: ReadonlyArray<number>, budget: number): ReadonlyArray<number> => {
305
+ const order = sizes.map((size, index) => ({ size, index })).sort((left, right) =>
306
+ left.size === right.size ? left.index - right.index : left.size - right.size
307
+ )
308
+ const allotted = new Array<number>(sizes.length).fill(0)
309
+ let remaining = budget
310
+ let left = sizes.length
311
+ for (const { index, size } of order) {
312
+ const fair = Math.floor(remaining / left)
313
+ const given = Math.min(size, fair)
314
+ allotted[index] = given
315
+ remaining = remaining - given
316
+ left = left - 1
317
+ }
318
+ return allotted
319
+ }
320
+
321
+ /** The line a frame writes about the statements it dropped whole. */
322
+ const droppedNotice = (count: number): string =>
323
+ `… ${count} print statements elided from the middle of this frame; the values are still bound in the realm.`
324
+
325
+ /** The line a frame writes about the statements the host never copied out. */
326
+ const unreadNotice = (count: number): string =>
327
+ `… ${count} further print statements were not kept: this frame printed more than the harness holds.`
328
+
329
+ /**
330
+ * What keeping one statement costs the budget: its floor, its notice, its newline.
331
+ *
332
+ * A statement at or under {@link printStatementFloor} costs only itself
333
+ * and no notice, because {@link buffer} shows it whole and a whole statement has
334
+ * nothing to say about what it lost. One over the floor is promised the floor,
335
+ * and the notice that shortening it prints is charged with it.
336
+ */
337
+ const price = (statement: Statement): number =>
338
+ Math.min(statement.bytes, printStatementFloor) +
339
+ (statement.bytes > printStatementFloor ? elide.noticeCost(statement.bytes, recall) : 0) + 1
340
+
341
+ /**
342
+ * How many of *these* statements a budget can keep at the floor, head first.
343
+ *
344
+ * A count of the statements in hand rather than a constant, because what a
345
+ * statement costs is what it is. Taken as `printFrameBytes / printStatementFloor`
346
+ * it was 32 whatever a frame printed, so a frame of two hundred eight-byte lines
347
+ * dropped a hundred and sixty-eight of them while fifteen of its sixteen
348
+ * kilobytes went unspent — the failure the shared budget exists to end,
349
+ * reintroduced one level up. Two hundred lines that cost nine bytes each cost
350
+ * eighteen hundred, and the budget keeps every one of them.
351
+ *
352
+ * The walk takes the head, then the tail, then the head again, which is the
353
+ * order {@link buffer} assembles them in, so a budget that affords an odd number
354
+ * spends the odd one on the earlier statement.
355
+ *
356
+ * @since 0.1.0
357
+ * @private
358
+ * @slop
359
+ */
360
+ export const capacity = (statements: ReadonlyArray<Statement>, budget: number): number => {
361
+ let left = budget
362
+ let kept = 0
363
+ while (kept < statements.length) {
364
+ const statement = kept % 2 === 0 ? statements[kept / 2]! : statements[statements.length - 1 - (kept - 1) / 2]!
365
+ const cost = price(statement)
366
+ if (cost > left) break
367
+ left = left - cost
368
+ kept = kept + 1
369
+ }
370
+ return kept
371
+ }
372
+
373
+ /**
374
+ * Assembles what a frame printed, bounded by {@link printFrameBytes}.
375
+ *
376
+ * `unread` is the count of statements the host stopped copying out of the realm
377
+ * because the frame had already handed over more than it holds. It is stated
378
+ * rather than dropped, because a buffer that simply stopped reads as a cell that
379
+ * simply stopped printing.
380
+ *
381
+ * The bound holds by construction rather than by a second pass over the result,
382
+ * because a second pass would cut a notice in half and that is the one thing a
383
+ * bound may not do. {@link capacity} charges every kept statement the floor it is
384
+ * promised, the notice it would print and its newline; what survives that walk is
385
+ * therefore affordable, and the apportionment below spends only what the walk
386
+ * left. A statement at or under the floor is shown whole and reserves no notice
387
+ * at all — reserving one apiece is what left a frame of short lines nothing to
388
+ * spend on the lines themselves.
389
+ *
390
+ * @since 0.1.0
391
+ * @private
392
+ * @slop
393
+ */
394
+ export const buffer = (statements: ReadonlyArray<Statement>, unread: number): string => {
395
+ if (statements.length === 0 && unread === 0) return ""
396
+ // The count-lines come out of the budget before the statements are counted,
397
+ // and the drop line only where there is a drop — so it is priced by asking
398
+ // twice, rather than by charging every frame for a line most never print.
399
+ const overhead = unread === 0 ? 0 : bytes.size(unreadNotice(unread)) + 1
400
+ const roomy = capacity(statements, printFrameBytes - overhead)
401
+ const affordable = roomy === statements.length
402
+ ? roomy
403
+ : capacity(statements, printFrameBytes - overhead - bytes.size(droppedNotice(statements.length)) - 1)
404
+ // More statements than the budget can floor: whole statements go from the
405
+ // middle, counted, rather than every one of them being cut to a notice.
406
+ const head = Math.ceil(affordable / 2)
407
+ const kept = statements.length === affordable
408
+ ? statements
409
+ : [...statements.slice(0, head), ...statements.slice(statements.length - Math.floor(affordable / 2))]
410
+ const dropped = statements.length - kept.length
411
+ const notices = [
412
+ ...(dropped === 0 ? [] : [droppedNotice(dropped)]),
413
+ ...(unread === 0 ? [] : [unreadNotice(unread)])
414
+ ]
415
+ // What the budget cannot spend on values: the count-lines, the newline between
416
+ // every pair, and one elision notice for each statement the floor does not
417
+ // cover whole.
418
+ const sizes = kept.map((statement) => statement.bytes)
419
+ const reserve = kept.reduce(
420
+ (sum, statement) => sum + (statement.bytes > printStatementFloor ? elide.noticeCost(statement.bytes, recall) : 0),
421
+ 0
422
+ ) +
423
+ notices.reduce((sum, line) => sum + bytes.size(line), 0) +
424
+ Math.max(0, kept.length + notices.length - 1)
425
+ const allotted = shares(sizes, Math.max(0, printFrameBytes - reserve))
426
+ const lines = kept.map((statement, index) =>
427
+ elide.middleFrom(statement.text, statement.bytes, allotted[index]!, recall)
428
+ )
429
+ return [
430
+ ...lines.slice(0, dropped === 0 ? lines.length : head),
431
+ ...(dropped === 0 ? [] : [notices[0]!, ...lines.slice(head)]),
432
+ ...(unread === 0 ? [] : [notices[notices.length - 1]!])
433
+ ].join("\n")
434
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The one rendering of a frame's print buffer into the turn that reads it.
3
+ *
4
+ * The controller journals the RAW buffer as `AgentEvent.CellPrinted` and sends
5
+ * this rendering to the model, so a projection that replays the raw text
6
+ * rebuilds a window the run never had. Both callers go through here for that
7
+ * reason: `CellTurn` when it builds the next turn, and `Transcript` when it
8
+ * rebuilds one from the journal.
9
+ *
10
+ * An empty buffer is a message and not a silence. A cell that printed nothing
11
+ * still opened a turn, and the turn it opened says so — dropping it loses a
12
+ * user message the model actually read, and the model is told the realm still
13
+ * holds everything the cell bound, which is the recovery it needs.
14
+ *
15
+ * @since 0.1.0
16
+ * @private
17
+ */
18
+
19
+ import { untrustedData } from "./untrustedData.ts"
20
+
21
+ /**
22
+ * Renders one frame's print buffer as the user turn its successor read.
23
+ *
24
+ * @category conversions
25
+ * @since 0.1.0
26
+ * @private
27
+ */
28
+ export const printsObservation = (prints: string): string =>
29
+ prints === ""
30
+ ? "Your cell printed nothing, so this turn opens with nothing new to read. Everything it bound is still in the realm; print what you need to look at."
31
+ : untrustedData(`What your cell printed:\n${prints}`, "cell print buffer (may contain repository and tool output)")
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The one constructor for a refusal a cell observes as a resolved envelope.
3
+ *
4
+ * A failed call **resolves** with a `failure` `Cell.CallResult`; it does not
5
+ * throw, and `Cell.callFailure` renders it as `{ ok: false, error }`. The shape
6
+ * is fixed — `value` is `null`, because a refusal has no value to hand back,
7
+ * except a timeout's, which records the limit it ran past (see {@link timedOut})
8
+ * — so every boundary that refuses a call builds it here rather than repeating
9
+ * the literal. The cell never sees `value` on a failure. An absent `code` is left absent rather than written as
10
+ * `undefined`: the encoded result is the durable wire contract used in sealed
11
+ * keys, and it means {@link Cell.defaultCallFailureCode}.
12
+ *
13
+ * @since 1.0.0-rc.0
14
+ * @private
15
+ */
16
+
17
+ import * as Schema from "effect/Schema"
18
+ import { type CallFailureCode, CallResult } from "../Cell.ts"
19
+
20
+ /**
21
+ * A refusal the cell observes as a resolved `{ ok: false, error }` envelope.
22
+ *
23
+ * @since 1.0.0-rc.0
24
+ * @private
25
+ */
26
+ export const refusal = (code: CallFailureCode | undefined, message: string): CallResult =>
27
+ code === undefined
28
+ ? new CallResult({ outcome: "failure", value: null, message })
29
+ : new CallResult({ outcome: "failure", value: null, code, message })
30
+
31
+ /**
32
+ * A timeout refusal: the `timeout` code, with the limit the call ran past
33
+ * recorded as `{ limitMillis }` in `value`, so a host that guards timeouts
34
+ * parks the run on the exact limit whichever clock enforced it.
35
+ *
36
+ * @since 1.0.0-rc.1
37
+ * @private
38
+ */
39
+ export const timedOut = (message: string, limitMillis: number): CallResult =>
40
+ new CallResult({ outcome: "failure", value: { limitMillis }, code: "timeout", message })
41
+
42
+ /**
43
+ * The limit a {@link timedOut} refusal recorded, when it recorded one.
44
+ *
45
+ * @since 1.0.0-rc.1
46
+ * @private
47
+ */
48
+ export const limitOf = (result: CallResult): number | undefined => {
49
+ const recorded = decodeLimit(result.value)
50
+ return recorded._tag === "Success" ? recorded.success.limitMillis : undefined
51
+ }
52
+
53
+ const decodeLimit = Schema.decodeUnknownResult(Schema.Struct({ limitMillis: Schema.Number }))