@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,484 @@
1
+ /**
2
+ * Turning one agent's final text into a value the declared output schema
3
+ * accepts, or into a typed failure.
4
+ *
5
+ * A model may answer with a bare JSON document, prose wrapped around a JSON
6
+ * document, a fenced block, or JSON of the wrong shape. Downstream nodes must
7
+ * never receive that ambiguity, so this module implements the recovery
8
+ * contract in `../docs/concepts.md#structured-output`:
9
+ *
10
+ * 1. parse the complete, BOM-stripped response and decode it;
11
+ * 2. otherwise scan once for balanced JSON containers, take the container
12
+ * whose matching close ends last, and decode that;
13
+ * 3. otherwise report a typed {@link StructuredOutputFailure} carrying bounded
14
+ * diagnostics, which is what a caller re-prompts with when it still holds a
15
+ * correction slot.
16
+ *
17
+ * Every candidate is decoded by the declared schema. Extraction never relaxes
18
+ * validation: it only decides which bytes are offered to it, and the schema may
19
+ * accept any JSON root rather than silently requiring an object.
20
+ *
21
+ * The prompt half is {@link instructions}. It renders the declared schema as a
22
+ * JSON Schema document placed in the run's system teaching, which is BAML's
23
+ * `ctx.output_format` injection reached through the seam the vault note
24
+ * specifies — the model is told the shape before it answers, and the answer is
25
+ * still validated locally. Provider acceptance is not a cast.
26
+ *
27
+ * Reference consulted: the `generateObject` function from Effect's
28
+ * `effect/unstable/ai/LanguageModel` module, which
29
+ * sends `responseFormat: { type: "json", schema }` and then decodes the result
30
+ * with the same schema, failing `AiError.InvalidOutputError` on mismatch. The
31
+ * decode-and-fail-typed half is copied. The provider `responseFormat` half is
32
+ * not reachable here: `@smthrs/model`'s `ModelRequest.GenerationParams` has no
33
+ * response-format field, and the cell loop's final answer is a `Cell.Complete`
34
+ * `output` string rather than a provider-decoded value, so the schema is
35
+ * carried in the prompt and enforced at this boundary.
36
+ *
37
+ * @since 0.1.0
38
+ */
39
+
40
+ import * as Digest from "@smthrs/core/Digest"
41
+ import * as Fault from "@smthrs/flow/Fault"
42
+ import * as Effect from "effect/Effect"
43
+ import * as Schema from "effect/Schema"
44
+ import * as SchemaIssue from "effect/SchemaIssue"
45
+ import * as elide from "./internal/elide.ts"
46
+
47
+ /**
48
+ * Stable reasons a structured-output boundary failed.
49
+ *
50
+ * `invalid_json` means candidate text was not JSON. `schema_mismatch` means
51
+ * JSON parsed but the declared schema refused it. `no_candidate` means the
52
+ * answer contained no candidate text. `correction_exhausted` means the
53
+ * boundary had already spent its correction budget.
54
+ *
55
+ * @category models
56
+ * @since 1.0.0-rc.0
57
+ * @slop
58
+ */
59
+ export const StructuredOutputFailureCode = Schema.Literals([
60
+ "invalid_json",
61
+ "schema_mismatch",
62
+ "no_candidate",
63
+ "correction_exhausted"
64
+ ])
65
+
66
+ /**
67
+ * Stable reasons a structured-output boundary failed.
68
+ *
69
+ * @category models
70
+ * @since 1.0.0-rc.0
71
+ * @slop
72
+ */
73
+ export type StructuredOutputFailureCode = typeof StructuredOutputFailureCode.Type
74
+
75
+ /**
76
+ * Stable reasons an individual structured-output issue was reported.
77
+ *
78
+ * `invalid_json` means candidate text was not JSON. `no_candidate` means the
79
+ * answer contained no candidate text. `invalid_type` means a decoded value had
80
+ * the wrong type. `invalid_value` means a value of the expected type was still
81
+ * invalid. `missing_key` means a required property was absent.
82
+ * `unexpected_key` means a prohibited extra property was present. `forbidden`
83
+ * means decoding attempted an operation the schema forbids. `one_of` means
84
+ * more than one exclusive union member matched. `constraint` means a schema
85
+ * check or empty-union fallback failed.
86
+ *
87
+ * @category models
88
+ * @since 1.0.0-rc.0
89
+ * @slop
90
+ */
91
+ export const OutputIssueCode = Schema.Literals([
92
+ "invalid_json",
93
+ "no_candidate",
94
+ "invalid_type",
95
+ "invalid_value",
96
+ "missing_key",
97
+ "unexpected_key",
98
+ "forbidden",
99
+ "one_of",
100
+ "constraint"
101
+ ])
102
+
103
+ /**
104
+ * Stable reasons an individual structured-output issue was reported.
105
+ *
106
+ * @category models
107
+ * @since 1.0.0-rc.0
108
+ * @slop
109
+ */
110
+ export type OutputIssueCode = typeof OutputIssueCode.Type
111
+
112
+ /**
113
+ * One bounded issue raised while decoding structured output.
114
+ *
115
+ * @category models
116
+ * @since 1.0.0-rc.0
117
+ * @slop
118
+ */
119
+ export class OutputIssue extends Schema.Class<OutputIssue>("flows/harness/StructuredOutput/OutputIssue")({
120
+ /** The stable reason this issue was reported. */
121
+ code: OutputIssueCode,
122
+ /** The JSON path of the offending value, dot/bracket joined; empty for the root. */
123
+ path: Schema.String,
124
+ /** What the decoder wanted there. */
125
+ message: Schema.String
126
+ }) {
127
+ /** Renders the issue for existing prose-oriented consumers. */
128
+ override toString(): string {
129
+ return this.path === "" ? this.message : `${this.path}: ${this.message}`
130
+ }
131
+ }
132
+
133
+ /**
134
+ * The terminal failure of one structured-output boundary.
135
+ *
136
+ * It carries what an operator needs to tell two identical-looking refusals
137
+ * apart: which schema was demanded, how many correction slots the attempt
138
+ * consumed out of its budget, the digest of the last candidate that was
139
+ * offered to the decoder, and the bounded issue list.
140
+ *
141
+ * @category errors
142
+ * @since 0.1.0
143
+ * @slop
144
+ */
145
+ export class StructuredOutputFailure extends Schema.TaggedError<StructuredOutputFailure>()(
146
+ "/harness/StructuredOutputFailure",
147
+ {
148
+ /** The stable reason this boundary failed. */
149
+ code: StructuredOutputFailureCode,
150
+ /** The declared output schema's canonical digest. */
151
+ schema: Schema.String,
152
+ /** SHA-256 of the text the decoder was last offered. */
153
+ candidate: Schema.String,
154
+ /** Correction attempts already spent on this boundary. */
155
+ corrections: Schema.Number,
156
+ /** The correction budget the boundary was declared with. */
157
+ limit: Schema.Number,
158
+ /** At most {@link maxIssues} structured validation issues. */
159
+ issues: Schema.Array(OutputIssue),
160
+ message: Schema.String
161
+ }
162
+ ) {}
163
+ // The model's answer did not fit the declared shape: another model may answer it.
164
+ Fault.register("/harness/StructuredOutputFailure", "dependency")
165
+
166
+ /**
167
+ * The most validation issues a failure or a correction prompt carries.
168
+ *
169
+ * Bounded for the same reason smithers bounds its own validation summary: a
170
+ * wide struct that mismatched everywhere would otherwise spend the correction
171
+ * prompt's whole budget restating the schema back to the model.
172
+ *
173
+ * @category constants
174
+ * @since 0.1.0
175
+ * @slop
176
+ */
177
+ export const maxIssues = 5
178
+
179
+ /**
180
+ * The JSON Schema document for a declared output schema.
181
+ *
182
+ * @category conversions
183
+ * @since 0.1.0
184
+ * @slop
185
+ */
186
+ export const jsonSchema = (schema: Schema.Top): unknown => {
187
+ const document = Schema.toJsonSchemaDocument(schema, { onExcessProperty: "error" })
188
+ return Object.keys(document.definitions).length > 0
189
+ ? { ...document.schema, $defs: document.definitions }
190
+ : document.schema
191
+ }
192
+
193
+ /**
194
+ * The canonical digest of a declared output schema.
195
+ *
196
+ * Two declarations that render the same JSON Schema name the same boundary, so
197
+ * this is what a step key folds in rather than the schema value itself.
198
+ *
199
+ * @category identity
200
+ * @since 0.1.0
201
+ * @slop
202
+ */
203
+ export const digest = (schema: Schema.Top): string => Digest.digest(Digest.canonical(jsonSchema(schema)))
204
+
205
+ /**
206
+ * The system teaching that tells a run what its final `output` must be.
207
+ *
208
+ * Written against the cell contract: a cell finishes by calling
209
+ * `ctx.done(output)`, and the sandbox rejects a returned transition, so the
210
+ * instruction is about the argument of that call and not about the assistant
211
+ * message around it. The run passes the value itself: a structured value
212
+ * reaches {@link decode} as canonical JSON, and a string as its own text.
213
+ *
214
+ * @category prompts
215
+ * @since 0.1.0
216
+ * @slop
217
+ */
218
+ export const instructions = (schema: Schema.Top): string =>
219
+ `## Required output shape
220
+
221
+ Finish by calling \`ctx.done(output)\` with the value itself: a JavaScript
222
+ value that validates against this JSON Schema, such as
223
+ \`ctx.done({ ...fields })\`. Do not stringify it, and add no prose around it.
224
+
225
+ \`\`\`json
226
+ ${JSON.stringify(jsonSchema(schema), null, 2)}
227
+ \`\`\``
228
+
229
+ /**
230
+ * The digest of one failure's rendered validation issues.
231
+ *
232
+ * Two rejections that raised the same issues share this digest, which is what a
233
+ * record carries instead of the issues themselves: a journal that repeated the
234
+ * validator's prose for every correction would grow with the model's verbosity,
235
+ * and what an operator actually asks is whether the second answer was wrong the
236
+ * same way as the first.
237
+ *
238
+ * @category identity
239
+ * @since 0.1.0
240
+ */
241
+ export const issuesDigest = (failure: StructuredOutputFailure): string =>
242
+ Digest.digest(
243
+ Digest.canonical(failure.issues.map((issue) => ({ path: issue.path, message: issue.message })))
244
+ )
245
+
246
+ /**
247
+ * The correction teaching appended when a candidate failed to decode.
248
+ *
249
+ * It restates the schema and the bounded diagnostics and nothing else: a
250
+ * correction does not reinterpret the task, so the original prompt is repeated
251
+ * verbatim by the caller and only this section is new.
252
+ *
253
+ * @category prompts
254
+ * @since 0.1.0
255
+ * @slop
256
+ */
257
+ export const correction = (failure: StructuredOutputFailure): string =>
258
+ `## Your previous answer did not validate
259
+
260
+ The output you passed to \`ctx.done\` could not be decoded against the required
261
+ schema. Call \`ctx.done(output)\` again with the same information as a value
262
+ that validates.
263
+
264
+ Validation issues:
265
+ ${failure.issues.map((issue) => `- ${issue}`).join("\n")}`
266
+
267
+ const stripBom = (text: string): string => text.charCodeAt(0) === 0xfeff ? text.slice(1) : text
268
+
269
+ /**
270
+ * The balanced JSON container whose matching close ends last.
271
+ *
272
+ * Scans once, left to right, tracking object and array delimiters, quoted
273
+ * strings, and escapes. A mismatched close abandons the open container rather
274
+ * than pairing it with the wrong opener, so a truncated prefix cannot be
275
+ * reported as a complete document. `undefined` means the text holds no
276
+ * balanced container at all.
277
+ *
278
+ * This is the array-capable form of smithers' `extractLastBalancedJson`, which
279
+ * is object-only.
280
+ *
281
+ * @category extraction
282
+ * @since 0.1.0
283
+ * @slop
284
+ */
285
+ export const lastBalanced = (text: string): string | undefined => {
286
+ const stack: Array<string> = []
287
+ let start = -1
288
+ let found: string | undefined = undefined
289
+ let quoted = false
290
+ let escaped = false
291
+ for (let index = 0; index < text.length; index++) {
292
+ const char = text[index]!
293
+ if (quoted) {
294
+ if (escaped) escaped = false
295
+ else if (char === "\\") escaped = true
296
+ else if (char === "\"") quoted = false
297
+ continue
298
+ }
299
+ if (char === "\"") {
300
+ if (stack.length > 0) quoted = true
301
+ continue
302
+ }
303
+ if (char === "{" || char === "[") {
304
+ if (stack.length === 0) start = index
305
+ stack.push(char)
306
+ continue
307
+ }
308
+ if (char === "}" || char === "]") {
309
+ const opener = stack.pop()
310
+ if (opener === undefined) continue
311
+ if ((char === "}") !== (opener === "{")) {
312
+ // Mismatched close: abandon the whole open container rather than
313
+ // reporting a pairing the text does not contain.
314
+ stack.length = 0
315
+ start = -1
316
+ continue
317
+ }
318
+ if (stack.length === 0 && start >= 0) found = text.slice(start, index + 1)
319
+ }
320
+ }
321
+ return found
322
+ }
323
+
324
+ /**
325
+ * The candidates offered to the decoder, in the declared recovery order.
326
+ *
327
+ * @category extraction
328
+ * @since 0.1.0
329
+ * @slop
330
+ */
331
+ export const candidates = (text: string): ReadonlyArray<string> => {
332
+ const stripped = stripBom(text).trim()
333
+ const balanced = lastBalanced(stripped)
334
+ return balanced === undefined || balanced === stripped ? [stripped] : [stripped, balanced]
335
+ }
336
+
337
+ const issueMessage = (message: string): string => elide.head(message, 240, "reissue the answer to see the whole issue")
338
+
339
+ const issuePath = (path: ReadonlyArray<PropertyKey>): string =>
340
+ path.map((segment, index) =>
341
+ typeof segment === "number" ? `[${segment}]` : `${index === 0 ? "" : "."}${String(segment)}`
342
+ ).join("")
343
+
344
+ type FormattedIssue = {
345
+ readonly message: string
346
+ readonly path: ReadonlyArray<PropertyKey>
347
+ }
348
+
349
+ const issueCodeSeparator = "\u0000"
350
+
351
+ const leafCodes: Record<SchemaIssue.Leaf["_tag"], OutputIssueCode> = {
352
+ InvalidType: "invalid_type",
353
+ InvalidValue: "invalid_value",
354
+ MissingKey: "missing_key",
355
+ UnexpectedKey: "unexpected_key",
356
+ Forbidden: "forbidden",
357
+ OneOf: "one_of"
358
+ }
359
+
360
+ const formatSchemaIssues = SchemaIssue.makeFormatterStandardSchemaV1({
361
+ leafHook: (issue) => `${issue._tag}${issueCodeSeparator}${SchemaIssue.defaultLeafHook(issue)}`
362
+ })
363
+
364
+ const schemaIssuesOf = (error: Schema.SchemaError): ReadonlyArray<OutputIssue> =>
365
+ (formatSchemaIssues(error.issue).issues as ReadonlyArray<FormattedIssue>).slice(0, maxIssues).map((issue) => {
366
+ const separator = issue.message.indexOf(issueCodeSeparator)
367
+ const tagged = separator >= 0
368
+ return new OutputIssue({
369
+ code: tagged ? leafCodes[issue.message.slice(0, separator) as SchemaIssue.Leaf["_tag"]] : "constraint",
370
+ path: issuePath(issue.path),
371
+ message: issueMessage(tagged ? issue.message.slice(separator + issueCodeSeparator.length) : issue.message)
372
+ })
373
+ })
374
+
375
+ const textIssuesOf = (code: OutputIssueCode, message: string): ReadonlyArray<OutputIssue> =>
376
+ message.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).slice(0, maxIssues).map((line) =>
377
+ new OutputIssue({ code, path: "", message: issueMessage(line) })
378
+ )
379
+
380
+ const quoted = (text: string): boolean => {
381
+ try {
382
+ return typeof JSON.parse(text) === "string"
383
+ } catch {
384
+ return false
385
+ }
386
+ }
387
+
388
+ /**
389
+ * Decodes one agent answer with the declared output schema.
390
+ *
391
+ * Decodes an original completion value first when supplied. Only a string
392
+ * refused for its type proceeds to legacy text extraction; refinements and
393
+ * nonstring failures retain the original value's diagnostics.
394
+ * Tries every {@link candidates} entry in order and returns the first the
395
+ * schema accepts, then the answer itself, untrimmed, as a string unless it is
396
+ * a JSON string literal, which is how a `ctx.done("text")` answer reaches a
397
+ * string schema. When none does, the failure reports the issues raised by the
398
+ * LAST candidate, which is the narrowest text the extractor could isolate and
399
+ * therefore the one a correction prompt should be about.
400
+ *
401
+ * @category decoding
402
+ * @since 0.1.0
403
+ * @slop
404
+ */
405
+ export const decode = <S extends Schema.Top>(
406
+ schema: S,
407
+ text: string,
408
+ attempt: { readonly corrections: number; readonly limit: number },
409
+ value?: Schema.Json | undefined
410
+ ): Effect.Effect<S["Type"], StructuredOutputFailure, S["DecodingServices"]> =>
411
+ Effect.gen(function*() {
412
+ const offered = candidates(text)
413
+ const decoder = Schema.decodeUnknownEffect(schema)
414
+ let code: StructuredOutputFailureCode = "no_candidate"
415
+ let issues: ReadonlyArray<OutputIssue> = [
416
+ new OutputIssue({ code: "no_candidate", path: "", message: "the answer held no JSON document" })
417
+ ]
418
+ if (value !== undefined) {
419
+ const result = yield* Effect.result(decoder(value))
420
+ if (result._tag === "Success") return result.success
421
+ const rawIssues = schemaIssuesOf(result.failure)
422
+ // Extraction is only for text offered to a schema expecting another type.
423
+ // Preserve string refinements and nonstring type failures on the value.
424
+ if (typeof value !== "string" || !rawIssues.every((issue) => issue.code === "invalid_type")) {
425
+ return yield* new StructuredOutputFailure({
426
+ code: attempt.corrections >= attempt.limit ? "correction_exhausted" : "schema_mismatch",
427
+ schema: digest(schema),
428
+ candidate: Digest.digest(JSON.stringify(value)),
429
+ corrections: attempt.corrections,
430
+ limit: attempt.limit,
431
+ issues: rawIssues,
432
+ message:
433
+ `The agent's answer did not validate against its declared output schema after ${attempt.corrections} of ${attempt.limit} corrections`
434
+ })
435
+ }
436
+ }
437
+ for (const candidate of offered) {
438
+ if (candidate.length === 0) continue
439
+ let parsed: unknown
440
+ try {
441
+ parsed = JSON.parse(candidate)
442
+ } catch (error) {
443
+ code = "invalid_json"
444
+ // The ECMAScript JSON parser throws a SyntaxError with a message.
445
+ issues = textIssuesOf("invalid_json", (error as SyntaxError).message)
446
+ continue
447
+ }
448
+ const result = yield* Effect.result(decoder(parsed))
449
+ if (result._tag === "Success") return result.success
450
+ code = "schema_mismatch"
451
+ issues = schemaIssuesOf(result.failure)
452
+ }
453
+ // `ctx.done("text")` reaches the boundary as the text itself, not as a
454
+ // JSON string, so a schema that accepts the raw answer takes it as it is.
455
+ // An answer that is a whole JSON string literal already said which string
456
+ // it meant, and its quotes are not part of it.
457
+ // Untrimmed, so an empty or whitespace-bearing string arrives as written.
458
+ const raw = stripBom(text)
459
+ if (!quoted(offered[0]!)) {
460
+ const result = yield* Effect.result(decoder(raw))
461
+ if (result._tag === "Success") return result.success
462
+ // A string the schema read and refused on its merits (too short, not
463
+ // one of the literals) is the issue to correct, not the JSON parse. A
464
+ // schema that wanted no string at all keeps the JSON diagnosis.
465
+ const rawIssues = schemaIssuesOf(result.failure)
466
+ if (code === "invalid_json" && rawIssues[0]?.code !== "invalid_type") {
467
+ code = "schema_mismatch"
468
+ issues = rawIssues
469
+ }
470
+ }
471
+ return yield* new StructuredOutputFailure({
472
+ // Once the budget is spent, exhaustion is the actionable classification;
473
+ // the issue records retain whether the last candidate was invalid JSON or
474
+ // failed schema decoding.
475
+ code: attempt.corrections >= attempt.limit ? "correction_exhausted" : code,
476
+ schema: digest(schema),
477
+ candidate: Digest.digest(offered[offered.length - 1]!),
478
+ corrections: attempt.corrections,
479
+ limit: attempt.limit,
480
+ issues,
481
+ message:
482
+ `The agent's answer did not validate against its declared output schema after ${attempt.corrections} of ${attempt.limit} corrections`
483
+ })
484
+ })