@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.36

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 (450) hide show
  1. package/CHANGELOG.md +263 -0
  2. package/README.md +339 -179
  3. package/dist/adapters.d.ts +15 -2
  4. package/dist/adapters.js +34 -2
  5. package/dist/agent-rows.d.ts +3 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +25 -5
  8. package/dist/api-only.d.ts +2 -1
  9. package/dist/api-only.js +3 -1
  10. package/dist/archil-routes.d.ts +40 -7
  11. package/dist/archil-routes.js +167 -54
  12. package/dist/archil-settings.d.ts +90 -8
  13. package/dist/archil-settings.js +150 -14
  14. package/dist/attach-images.d.ts +15 -0
  15. package/dist/attach-images.js +59 -0
  16. package/dist/background.d.ts +0 -6
  17. package/dist/background.js +0 -28
  18. package/dist/bash-read-only.d.ts +13 -0
  19. package/dist/bash-read-only.js +77 -0
  20. package/dist/box-image.d.ts +1 -97
  21. package/dist/box-image.js +4 -284
  22. package/dist/box-paths.d.ts +2 -7
  23. package/dist/box-paths.js +7 -13
  24. package/dist/box-settings.d.ts +0 -11
  25. package/dist/box-settings.js +4 -29
  26. package/dist/browser-commands.js +1 -1
  27. package/dist/browser-computer.d.ts +47 -3
  28. package/dist/browser-computer.js +286 -18
  29. package/dist/browser-cost.d.ts +2 -2
  30. package/dist/browser-cost.js +6 -4
  31. package/dist/browser-person.d.ts +19 -2
  32. package/dist/browser-person.js +55 -6
  33. package/dist/browser-wait-ended.d.ts +23 -0
  34. package/dist/browser-wait-ended.js +42 -0
  35. package/dist/cap.d.ts +19 -44
  36. package/dist/cap.js +31 -77
  37. package/dist/cli.js +36 -27
  38. package/dist/computer-keys.d.ts +20 -10
  39. package/dist/computer-keys.js +36 -57
  40. package/dist/computer-routes.d.ts +1 -4
  41. package/dist/computer-routes.js +3 -5
  42. package/dist/computer-setting.d.ts +8 -5
  43. package/dist/computer-setting.js +91 -26
  44. package/dist/computer-view.d.ts +11 -2
  45. package/dist/computer-view.js +2 -1
  46. package/dist/computers.d.ts +54 -8
  47. package/dist/computers.js +101 -22
  48. package/dist/console/assets/index-BI4Byidu.js +550 -0
  49. package/dist/console/assets/index-C19gUF2n.css +1 -0
  50. package/dist/console/index.html +2 -2
  51. package/dist/content-filter.d.ts +7 -0
  52. package/dist/content-filter.js +23 -0
  53. package/dist/decision-cap.d.ts +7 -29
  54. package/dist/decision-cap.js +3 -94
  55. package/dist/docker-daemon.d.ts +2 -2
  56. package/dist/docker-daemon.js +2 -2
  57. package/dist/errors.d.ts +1 -0
  58. package/dist/errors.js +8 -5
  59. package/dist/explain.js +3 -1
  60. package/dist/faux-computers.js +4 -0
  61. package/dist/files.d.ts +1 -9
  62. package/dist/files.js +1 -9
  63. package/dist/github-connection.js +25 -7
  64. package/dist/github-faux.d.ts +26 -0
  65. package/dist/github-faux.js +76 -0
  66. package/dist/github.d.ts +28 -4
  67. package/dist/github.js +46 -10
  68. package/dist/gpu-words.d.ts +14 -0
  69. package/dist/gpu-words.js +21 -0
  70. package/dist/graph-served.d.ts +5 -3
  71. package/dist/graph-served.js +14 -6
  72. package/dist/graph-view.d.ts +2 -0
  73. package/dist/graph-view.js +29 -2
  74. package/dist/handed-values.d.ts +1 -1
  75. package/dist/handed-values.js +1 -1
  76. package/dist/harness-install.d.ts +60 -3
  77. package/dist/harness-install.js +322 -34
  78. package/dist/harness-opencode/harness.js +0 -1
  79. package/dist/harness-opencode/host/policy.js +2 -2
  80. package/dist/harness.js +1 -1
  81. package/dist/host-tools.d.ts +8 -9
  82. package/dist/host-tools.js +7 -7
  83. package/dist/index.d.ts +2 -3
  84. package/dist/index.js +2 -2
  85. package/dist/key-refusal.d.ts +1 -1
  86. package/dist/key-refusal.js +2 -2
  87. package/dist/learn/check.d.ts +10 -2
  88. package/dist/learn/check.js +126 -8
  89. package/dist/learn/commit.d.ts +40 -6
  90. package/dist/learn/commit.js +164 -20
  91. package/dist/learn/folder.d.ts +11 -3
  92. package/dist/learn/folder.js +40 -16
  93. package/dist/learn/grade.d.ts +22 -2
  94. package/dist/learn/grade.js +127 -19
  95. package/dist/learn/index.d.ts +2 -2
  96. package/dist/learn/index.js +2 -2
  97. package/dist/learn/learning.sh +11 -13
  98. package/dist/learn/notes.d.ts +17 -3
  99. package/dist/learn/notes.js +19 -6
  100. package/dist/learn/reflect.d.ts +5 -2
  101. package/dist/learn/reflect.js +48 -32
  102. package/dist/learn/skills.d.ts +52 -5
  103. package/dist/learn/skills.js +104 -21
  104. package/dist/learned-nodes.d.ts +18 -0
  105. package/dist/learned-nodes.js +8 -0
  106. package/dist/learned-workflow.d.ts +27 -13
  107. package/dist/learned-workflow.js +110 -38
  108. package/dist/learning-cost.d.ts +79 -0
  109. package/dist/learning-cost.js +69 -0
  110. package/dist/learning-routes.d.ts +48 -2
  111. package/dist/learning-routes.js +99 -28
  112. package/dist/learning-run.d.ts +7 -5
  113. package/dist/learning-run.js +9 -6
  114. package/dist/learning-words.d.ts +3 -0
  115. package/dist/learning-words.js +6 -2
  116. package/dist/learning.d.ts +13 -28
  117. package/dist/learning.js +4 -18
  118. package/dist/llm.d.ts +4 -1
  119. package/dist/llm.js +4 -2
  120. package/dist/mcp-gateway.d.ts +6 -0
  121. package/dist/mcp-gateway.js +11 -1
  122. package/dist/mcp-probe.d.ts +8 -1
  123. package/dist/mcp-probe.js +62 -20
  124. package/dist/mcp-secret-writes.js +4 -0
  125. package/dist/mcp-servers-store.d.ts +12 -12
  126. package/dist/mcp-servers-store.js +8 -3
  127. package/dist/model.d.ts +8 -5
  128. package/dist/model.js +14 -6
  129. package/dist/openapi.d.ts +2 -0
  130. package/dist/openapi.js +236 -55
  131. package/dist/owner.d.ts +0 -1
  132. package/dist/owner.js +0 -2
  133. package/dist/pause.d.ts +2 -19
  134. package/dist/pause.js +5 -74
  135. package/dist/place-offers.d.ts +97 -0
  136. package/dist/place-offers.js +206 -0
  137. package/dist/place.d.ts +9 -13
  138. package/dist/place.js +22 -32
  139. package/dist/port-models.d.ts +12 -4
  140. package/dist/port-models.js +31 -9
  141. package/dist/print.d.ts +1 -8
  142. package/dist/print.js +1 -14
  143. package/dist/propose.d.ts +3 -0
  144. package/dist/propose.js +25 -19
  145. package/dist/run-cut.d.ts +5 -0
  146. package/dist/run-cut.js +19 -0
  147. package/dist/run-db.js +3 -3
  148. package/dist/run-launch.d.ts +18 -3
  149. package/dist/run-launch.js +11 -5
  150. package/dist/run-learning-served.d.ts +12 -1
  151. package/dist/run-manifest.d.ts +2 -2
  152. package/dist/run-manifest.js +2 -2
  153. package/dist/run-reads-over-store.d.ts +4 -2
  154. package/dist/run-reads-over-store.js +10 -8
  155. package/dist/run-secrets.js +3 -3
  156. package/dist/run-timeline-served.js +60 -38
  157. package/dist/run-view.d.ts +35 -16
  158. package/dist/run-view.js +64 -35
  159. package/dist/runnable.d.ts +6 -3
  160. package/dist/runnable.js +20 -4
  161. package/dist/runner/adapter-loop.d.ts +46 -5
  162. package/dist/runner/adapter-loop.js +381 -56
  163. package/dist/runner/adapter-run-spec.d.ts +46 -4
  164. package/dist/runner/adapter-run-spec.js +200 -45
  165. package/dist/runner/adapters/pi.d.ts +39 -3
  166. package/dist/runner/adapters/pi.js +124 -29
  167. package/dist/runner/beside.d.ts +8 -0
  168. package/dist/runner/beside.js +24 -2
  169. package/dist/runner/claim-secrets.d.ts +6 -0
  170. package/dist/runner/claim-secrets.js +15 -1
  171. package/dist/runner/cli-run-spec.d.ts +10 -0
  172. package/dist/runner/cli-run-spec.js +207 -64
  173. package/dist/runner/commands.d.ts +5 -1
  174. package/dist/runner/commands.js +3 -3
  175. package/dist/runner/conformance/harness.d.ts +1 -1
  176. package/dist/runner/conformance/harness.js +13 -10
  177. package/dist/runner/github-app.d.ts +7 -2
  178. package/dist/runner/github-app.js +46 -15
  179. package/dist/runner/harness-loops.d.ts +6 -1
  180. package/dist/runner/harness-loops.js +24 -1
  181. package/dist/runner/journal-kinds.d.ts +53 -7
  182. package/dist/runner/journal-kinds.js +29 -1
  183. package/dist/runner/learning-end.d.ts +15 -0
  184. package/dist/runner/learning-end.js +113 -20
  185. package/dist/runner/learning-factory.js +6 -2
  186. package/dist/runner/learning-loop.d.ts +75 -1
  187. package/dist/runner/learning-loop.js +215 -22
  188. package/dist/runner/learning-seed.d.ts +8 -0
  189. package/dist/runner/learning-seed.js +7 -1
  190. package/dist/runner/loop-contract.d.ts +12 -0
  191. package/dist/runner/loop-contract.js +6 -0
  192. package/dist/runner/loop.d.ts +5 -1
  193. package/dist/runner/loop.js +20 -0
  194. package/dist/runner/main.d.ts +9 -4
  195. package/dist/runner/main.js +38 -13
  196. package/dist/runner/mcp-claim.d.ts +7 -0
  197. package/dist/runner/mcp-claim.js +35 -2
  198. package/dist/runner/mcp-github.d.ts +15 -4
  199. package/dist/runner/mcp-github.js +55 -11
  200. package/dist/runner/mcp-run.d.ts +2 -0
  201. package/dist/runner/mcp-run.js +2 -0
  202. package/dist/runner/metrics.d.ts +18 -1
  203. package/dist/runner/metrics.js +81 -1
  204. package/dist/runner/model-route.d.ts +6 -0
  205. package/dist/runner/model-route.js +5 -2
  206. package/dist/runner/pr-checkout.d.ts +59 -0
  207. package/dist/runner/pr-checkout.js +176 -0
  208. package/dist/runner/reflect-hook.d.ts +1 -0
  209. package/dist/runner/reflect-hook.js +3 -3
  210. package/dist/runner/runner.js +136 -19
  211. package/dist/runner/spec-holds.d.ts +13 -3
  212. package/dist/runner/spec-holds.js +13 -10
  213. package/dist/runner/store-port.d.ts +4 -1
  214. package/dist/runner/store-secrets.js +17 -1
  215. package/dist/runner/subagent.d.ts +44 -0
  216. package/dist/runner/subagent.js +188 -0
  217. package/dist/runner/workflow-host.d.ts +25 -4
  218. package/dist/runner/workflow-host.js +26 -4
  219. package/dist/runner/workflow-loop.d.ts +9 -3
  220. package/dist/runner/workflow-loop.js +17 -10
  221. package/dist/runner/workflow-spec.d.ts +28 -13
  222. package/dist/runner/workflow-spec.js +247 -102
  223. package/dist/runs-over-store.d.ts +18 -7
  224. package/dist/runs-over-store.js +149 -31
  225. package/dist/seal-key.d.ts +0 -2
  226. package/dist/seal-key.js +0 -2
  227. package/dist/sealing.js +1 -2
  228. package/dist/secret-cut.d.ts +1 -1
  229. package/dist/secret-cut.js +1 -1
  230. package/dist/server-lock.js +4 -5
  231. package/dist/server.d.ts +49 -63
  232. package/dist/server.js +429 -230
  233. package/dist/stop-signals.d.ts +4 -2
  234. package/dist/stop-signals.js +5 -3
  235. package/dist/store/agent-body.d.ts +14 -3
  236. package/dist/store/agent-body.js +22 -8
  237. package/dist/store/deadline.d.ts +18 -0
  238. package/dist/store/deadline.js +49 -0
  239. package/dist/store/index.d.ts +3 -3
  240. package/dist/store/index.js +2 -2
  241. package/dist/store/journal/storage.js +2 -1
  242. package/dist/store/postgres/connection.d.ts +4 -0
  243. package/dist/store/postgres/connection.js +64 -13
  244. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  245. package/dist/store/schema.d.ts +2 -1
  246. package/dist/store/schema.js +11 -8
  247. package/dist/store/seal.d.ts +13 -0
  248. package/dist/store/seal.js +19 -0
  249. package/dist/store/sqlite/connection.d.ts +5 -0
  250. package/dist/store/sqlite/connection.js +88 -82
  251. package/dist/store/sqlite/run-patch.d.ts +18 -2
  252. package/dist/store/sqlite/run-patch.js +31 -2
  253. package/dist/store/sqlite/store.js +65 -11
  254. package/dist/store/store.d.ts +62 -12
  255. package/dist/store/store.js +22 -1
  256. package/dist/store-reads/analytics.js +3 -2
  257. package/dist/store-reads/cap.d.ts +1 -3
  258. package/dist/store-reads/cap.js +8 -6
  259. package/dist/store-reads/decisions.d.ts +2 -2
  260. package/dist/store-reads/decisions.js +3 -6
  261. package/dist/store-reads/journal.js +83 -15
  262. package/dist/store-reads/learning.d.ts +73 -3
  263. package/dist/store-reads/learning.js +232 -9
  264. package/dist/store-reads/runs.d.ts +6 -4
  265. package/dist/store-reads/runs.js +17 -10
  266. package/dist/store-reads/stats.js +5 -1
  267. package/dist/store-view.d.ts +15 -1
  268. package/dist/store-view.js +88 -29
  269. package/dist/template-eval.js +2 -1
  270. package/dist/templates.d.ts +73 -4
  271. package/dist/templates.js +113 -23
  272. package/dist/timeline/timeline.d.ts +11 -1
  273. package/dist/timeline/timeline.js +19 -4
  274. package/dist/tool-blurbs.js +1 -0
  275. package/dist/tool-budget.d.ts +26 -0
  276. package/dist/tool-budget.js +56 -0
  277. package/dist/tool-gate.d.ts +13 -3
  278. package/dist/tool-gate.js +15 -7
  279. package/dist/tool-plane.d.ts +42 -29
  280. package/dist/tool-plane.js +64 -27
  281. package/dist/tools.d.ts +53 -39
  282. package/dist/tools.js +174 -79
  283. package/dist/trigger-signatures.d.ts +1 -0
  284. package/dist/trigger-signatures.js +3 -1
  285. package/dist/triggers.d.ts +3 -3
  286. package/dist/triggers.js +2 -2
  287. package/dist/turn-end.d.ts +0 -3
  288. package/dist/turn-end.js +0 -3
  289. package/dist/uploads.d.ts +28 -5
  290. package/dist/uploads.js +82 -9
  291. package/dist/usage-lines.d.ts +1 -1
  292. package/dist/usage.d.ts +1 -47
  293. package/dist/usage.js +3 -82
  294. package/dist/validate.d.ts +8 -0
  295. package/dist/validate.js +40 -3
  296. package/dist/webhooks.d.ts +2 -1
  297. package/dist/webhooks.js +5 -2
  298. package/dist/workflow/decision-recovery.d.ts +23 -0
  299. package/dist/workflow/decision-recovery.js +80 -0
  300. package/dist/workflow/decisions.d.ts +134 -0
  301. package/dist/workflow/decisions.js +46 -0
  302. package/dist/workflow/host-session.d.ts +5 -0
  303. package/dist/workflow/host-session.js +85 -0
  304. package/dist/workflow/host-tools.d.ts +3 -0
  305. package/dist/workflow/host-tools.js +3 -0
  306. package/dist/workflow/node-runner.d.ts +112 -0
  307. package/dist/workflow/node-runner.js +270 -0
  308. package/dist/workflow/node.d.ts +88 -0
  309. package/dist/workflow/node.js +99 -0
  310. package/dist/workflow/operator-error.d.ts +4 -0
  311. package/dist/workflow/operator-error.js +4 -0
  312. package/dist/workflow/pi-versions.d.ts +9 -0
  313. package/dist/workflow/pi-versions.js +8 -0
  314. package/dist/workflow/readers.d.ts +36 -0
  315. package/dist/workflow/readers.js +145 -0
  316. package/dist/workflow/record-file.d.ts +10 -0
  317. package/dist/workflow/record-file.js +56 -0
  318. package/dist/workflow/record-tool.d.ts +76 -0
  319. package/dist/workflow/record-tool.js +126 -0
  320. package/dist/workflow/record.d.ts +151 -0
  321. package/dist/workflow/record.js +401 -0
  322. package/dist/workflow/run-error.d.ts +16 -0
  323. package/dist/workflow/run-error.js +26 -0
  324. package/dist/workflow/runner.d.ts +6 -0
  325. package/dist/workflow/runner.js +240 -0
  326. package/dist/workflow/store.d.ts +23 -0
  327. package/dist/workflow/store.js +242 -0
  328. package/dist/workflow/task.d.ts +133 -0
  329. package/dist/workflow/task.js +411 -0
  330. package/dist/workflow/thinking.d.ts +3 -0
  331. package/dist/workflow/thinking.js +7 -0
  332. package/dist/workflow/tool-context.d.ts +21 -0
  333. package/dist/workflow/tool-context.js +13 -0
  334. package/dist/workflow/types.d.ts +126 -0
  335. package/dist/workflow/types.js +1 -0
  336. package/dist/workflow/wal.d.ts +11 -0
  337. package/dist/workflow/wal.js +106 -0
  338. package/dist/workflow-run.d.ts +1 -1
  339. package/dist/workspace/agent-computer.d.ts +137 -0
  340. package/dist/workspace/agent-computer.js +292 -0
  341. package/dist/workspace/archil-claim.d.ts +13 -2
  342. package/dist/workspace/archil-claim.js +22 -13
  343. package/dist/workspace/archil-disk.d.ts +10 -1
  344. package/dist/workspace/archil-disk.js +4 -0
  345. package/dist/workspace/archil-disks.d.ts +49 -0
  346. package/dist/workspace/archil-disks.js +185 -0
  347. package/dist/workspace/archil-exec.d.ts +12 -2
  348. package/dist/workspace/archil-exec.js +18 -3
  349. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  350. package/dist/workspace/archil-mount-credential.js +13 -4
  351. package/dist/workspace/archil.d.ts +2 -2
  352. package/dist/workspace/archil.js +25 -5
  353. package/dist/workspace/attach.js +2 -0
  354. package/dist/workspace/computer-deps.d.ts +18 -11
  355. package/dist/workspace/computer-deps.js +64 -40
  356. package/dist/workspace/computer-for-claim.d.ts +47 -9
  357. package/dist/workspace/computer-for-claim.js +236 -24
  358. package/dist/workspace/computer-janitor.d.ts +3 -2
  359. package/dist/workspace/computer-janitor.js +43 -9
  360. package/dist/workspace/computer-ledger.d.ts +3 -8
  361. package/dist/workspace/computer-ledger.js +7 -3
  362. package/dist/workspace/computer-providers.d.ts +5 -3
  363. package/dist/workspace/computer-providers.js +11 -9
  364. package/dist/workspace/hands.d.ts +5 -2
  365. package/dist/workspace/hands.js +4 -3
  366. package/dist/workspace/index.d.ts +5 -4
  367. package/dist/workspace/index.js +2 -1
  368. package/dist/workspace/local.d.ts +3 -0
  369. package/dist/workspace/local.js +9 -0
  370. package/dist/workspace/paths.js +3 -2
  371. package/dist/workspace/pi-env.d.ts +4 -0
  372. package/dist/workspace/pi-env.js +3 -2
  373. package/dist/workspace/resolve-computer.d.ts +48 -12
  374. package/dist/workspace/resolve-computer.js +88 -19
  375. package/dist/workspace/run-disk.d.ts +34 -0
  376. package/dist/workspace/run-disk.js +91 -0
  377. package/dist/workspace/run-tools.d.ts +6 -4
  378. package/dist/workspace/run-tools.js +17 -9
  379. package/dist/workspace/server-run-workspace.d.ts +3 -2
  380. package/dist/workspace/server-run-workspace.js +17 -4
  381. package/dist/workspace/workspace.d.ts +5 -0
  382. package/dist/workspace.d.ts +0 -3
  383. package/dist/workspace.js +2 -15
  384. package/package.json +11 -16
  385. package/skills/agentrun-serve/SKILL.md +1 -1
  386. package/templates/README.md +11 -8
  387. package/templates/code-review/agent.md +27 -11
  388. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  389. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  390. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  391. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  392. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  393. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  394. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  395. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  396. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  397. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  398. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  399. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  400. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  401. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  402. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  403. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  404. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  405. package/templates/code-review/evals/re-review/prompt.md +1 -1
  406. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  407. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  408. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  409. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  410. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  411. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  412. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  413. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  414. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  415. package/templates/code-review/findings.schema.json +131 -27
  416. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  417. package/templates/code-review/skills/review/DEEP.md +130 -0
  418. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  419. package/templates/code-review/skills/review/SKILL.md +104 -154
  420. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  421. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  422. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  423. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  424. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  425. package/templates/release-notes/agent.md +11 -0
  426. package/dist/box/record.d.ts +0 -6
  427. package/dist/box/record.js +0 -41
  428. package/dist/box/sweep.d.ts +0 -53
  429. package/dist/box/sweep.js +0 -193
  430. package/dist/box-egress-vm.d.ts +0 -118
  431. package/dist/box-egress-vm.js +0 -354
  432. package/dist/box-egress.d.ts +0 -105
  433. package/dist/box-egress.js +0 -256
  434. package/dist/box-relay-vm.d.ts +0 -84
  435. package/dist/box-relay-vm.js +0 -437
  436. package/dist/box-relay.d.ts +0 -36
  437. package/dist/box-relay.js +0 -207
  438. package/dist/boxes.d.ts +0 -109
  439. package/dist/boxes.js +0 -249
  440. package/dist/budget.d.ts +0 -76
  441. package/dist/budget.js +0 -204
  442. package/dist/console/assets/index-RPHGlXmM.js +0 -540
  443. package/dist/console/assets/index-opTN5Naq.css +0 -1
  444. package/dist/daytona-api.d.ts +0 -10
  445. package/dist/daytona-api.js +0 -20
  446. package/dist/egress-proxy.d.ts +0 -45
  447. package/dist/egress-proxy.js +0 -416
  448. package/dist/egress-table.d.ts +0 -24
  449. package/dist/egress-table.js +0 -165
  450. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -0,0 +1,145 @@
1
+ // Read-only views of a run's durable file, synchronously and without the Harness: a document by its address, a
2
+ // journal as `documentStore` wrote it, and the route decisions a frozen snapshot holds. A reader that only looks at
3
+ // what ran (the run card, a tail that inherits what a run decided) uses them; the Harness stays the only writer. The
4
+ // readers take the store file itself (pi-durable's SQLite file, wherever the host keeps it), never a directory.
5
+ import fs from "node:fs";
6
+ import { createRequire } from "node:module";
7
+ import { pathToFileURL } from "node:url";
8
+ import { apply } from "@earendil-works/chord/delta";
9
+ import { decisionKey } from "./decisions.js";
10
+ import { effectKey } from "./store.js";
11
+ import { walHasCommit } from "./wal.js";
12
+ /** The run's store `file`, opened read-only for `read`; null when there is no such file. Every query of one `read` runs
13
+ * in one read transaction, so what it returns is one commit's view, whatever a writer commits meanwhile. */
14
+ export function withDurableFile(file, read, options = {}) {
15
+ if (!fs.existsSync(file))
16
+ return null;
17
+ const { DatabaseSync } = createRequire(import.meta.url)("node:sqlite");
18
+ for (let attempt = 1;; attempt++) {
19
+ // Unlocked, a WAL with no verified commit yet is never opened (wal.ts): SQLite's lock-free reader recovers no frame
20
+ // from it and removes it at its close, under a writer that may still be writing its first transaction there. Then
21
+ // the database file is whole: immutable, and its read kept only when the file did not change during it (a run's
22
+ // process wrote and its checkpoint landed meanwhile), else dropped and made again.
23
+ const walFrames = options.unlocked && walHasCommit(`${file}-wal`);
24
+ const alone = options.unlocked && !walFrames;
25
+ const before = alone ? fileMark(file) : undefined;
26
+ const at = options.immutable || alone ? `${pathToFileURL(file).href}?mode=ro&immutable=1` : options.unlocked ? `${pathToFileURL(file).href}?mode=ro&vfs=unix-none` : file;
27
+ const db = new DatabaseSync(at, { readOnly: true, timeout: 5000 });
28
+ let result;
29
+ try {
30
+ if (options.unlocked && walFrames)
31
+ db.exec("PRAGMA locking_mode = EXCLUSIVE");
32
+ db.exec("BEGIN");
33
+ result = read(db);
34
+ }
35
+ finally {
36
+ db.close();
37
+ }
38
+ if (!alone || fileMark(file) === before)
39
+ return result;
40
+ if (attempt >= 3)
41
+ throw new Error(`the run's store ${file} changed during each of ${attempt} reads`);
42
+ }
43
+ }
44
+ /** What says store `file` changed: its inode, size and modification time, and its header's file change counter and page
45
+ * count (bytes 24 to 31). A checkpoint writes the file, so its time and size move even where WAL mode leaves the counter. */
46
+ function fileMark(file) {
47
+ const at = fs.statSync(file, { bigint: true });
48
+ const header = Buffer.alloc(8);
49
+ const fd = fs.openSync(file, "r");
50
+ try {
51
+ fs.readSync(fd, header, 0, 8, 24);
52
+ }
53
+ finally {
54
+ fs.closeSync(fd);
55
+ }
56
+ return `${at.ino}:${at.size}:${at.mtimeNs}:${header.toString("hex")}`;
57
+ }
58
+ /** A document's value: its latest base with every later delta applied, as the storage materializes it. */
59
+ function revisionsOf(db, id) {
60
+ const base = db.prepare("SELECT seq, content FROM document_revisions WHERE document_id = ? AND kind = 'base' ORDER BY seq DESC LIMIT 1").get(id);
61
+ if (!base)
62
+ return undefined;
63
+ let value = JSON.parse(base.content);
64
+ for (const delta of db.prepare("SELECT content FROM document_revisions WHERE document_id = ? AND seq > ? ORDER BY seq").all(id, base.seq)) {
65
+ value = apply(value, JSON.parse(delta.content));
66
+ }
67
+ return value;
68
+ }
69
+ /** The row of a Session document. `key` names a family member; a singleton has none. */
70
+ function sessionDocId(db, kind, key) {
71
+ const row = db.prepare("SELECT id FROM documents WHERE kind = ? AND scope_kind = 'session' AND owner_id = 0 AND family = ? AND key_value = ? AND retired_at IS NULL ORDER BY created_at DESC LIMIT 1")
72
+ .get(JSON.stringify(kind), key === undefined ? 0 : 1, JSON.stringify(key ?? ""));
73
+ return row?.id;
74
+ }
75
+ /** A Session document's current value. `key` names a family member; a singleton has none. */
76
+ function sessionDoc(db, kind, key) {
77
+ const id = sessionDocId(db, kind, key);
78
+ return id === undefined ? undefined : revisionsOf(db, id);
79
+ }
80
+ /** The ids of the effects the map items of `table` own (the keyed layout's `maps`: `{ <map path>: { items, ... } }`), each
81
+ * item's own nested maps included, read as the driver reads them back: item `i` of a map is its record at
82
+ * `<map path>/items/<i>`, for every item the map started. */
83
+ function itemEffects(db, key, table, into) {
84
+ if (!table || typeof table !== "object" || Array.isArray(table))
85
+ return;
86
+ for (const [mapPath, entry] of Object.entries(table)) {
87
+ const started = entry?.items;
88
+ if (typeof started !== "number" || !Number.isSafeInteger(started))
89
+ continue;
90
+ for (let index = 0; index < started; index += 1) {
91
+ const item = sessionDoc(db, "agentrun.items", effectKey(key, `${mapPath}/items/${index}`));
92
+ if (!item)
93
+ continue;
94
+ if (Array.isArray(item.effects))
95
+ for (const id of item.effects)
96
+ if (typeof id === "string")
97
+ into.push(id);
98
+ itemEffects(db, key, item.maps, into);
99
+ }
100
+ }
101
+ }
102
+ /** A Session document of the run's store `file`, read-only; undefined when the file or the document is absent. */
103
+ export function durableDoc(file, kind, key, options = {}) {
104
+ return (withDurableFile(file, (db) => sessionDoc(db, kind, key), options) ?? undefined);
105
+ }
106
+ /** The decision rows (`agentrun.decisions`) of the run's store `file`, in commit order: the keyed documents, one row each, in the order of their keys. */
107
+ export function durableDecisions(file, options = {}) {
108
+ return withDurableFile(file, (db) => {
109
+ const count = sessionDoc(db, "agentrun.decisions.count")?.count;
110
+ const rows = [];
111
+ if (typeof count === "number")
112
+ for (let place = 0; place < count; place += 1) {
113
+ const row = sessionDoc(db, "agentrun.decisions", decisionKey(place));
114
+ if (row)
115
+ rows.push(row);
116
+ }
117
+ return rows;
118
+ }, options) ?? [];
119
+ }
120
+ /** The journal `key` holds in the run's store `file`, as the last commit left it; undefined when the file holds no
121
+ * such journal or none has bound it. `effects` are every effect the journal admitted, once each, in the order they were
122
+ * admitted, in either layout: in the keyed one (`agentrun.frozen_run.v4`) the effects a map item owns, nested maps
123
+ * included, are listed by that item's record, not the driver's, and are read from there. `state` is the driver's own
124
+ * record: in the keyed layout what lies in each map item stays in the item's record. */
125
+ export function readJournal(file, key, options = {}) {
126
+ return withDurableFile(file, (db) => {
127
+ const doc = sessionDoc(db, "agentrun.driver", key);
128
+ if (!doc || doc.binding === null)
129
+ return undefined;
130
+ // The driver's record lists the effects no map item owns; in the keyed layout each item's record lists its own. All of
131
+ // them, once each, in the order they were admitted: an effect's document is created by its admission, and a document's
132
+ // row is numbered when it is created (a later checkpoint folds its revisions, never its row).
133
+ const ids = [...doc.effects];
134
+ itemEffects(db, key, doc.state?.maps, ids);
135
+ const admitted = new Map();
136
+ for (const id of new Set(ids))
137
+ admitted.set(id, sessionDocId(db, "agentrun.effects", effectKey(key, id)) ?? Number.MAX_SAFE_INTEGER);
138
+ // A stable sort: an id whose document is missing keeps its place in the listing, after every admitted one.
139
+ const effects = [...admitted.keys()].sort((a, b) => admitted.get(a) - admitted.get(b)).map((id) => {
140
+ const e = sessionDoc(db, "agentrun.effects", effectKey(key, id));
141
+ return { id, name: e?.name ?? "", argsHash: e?.argsHash ?? "", status: e?.status ?? "unknown", session: e?.session ?? null, result: e?.result ?? null, ...(e?.intent ? { intent: e.intent } : {}), ...(e?.args !== undefined ? { args: e.args } : {}), ...(Array.isArray(e?.calls) ? { calls: e.calls } : {}) };
142
+ });
143
+ return { binding: doc.binding, inputs: doc.inputs, generation: doc.generation, revision: doc.revision, state: doc.state, notes: doc.notes, effects };
144
+ }, options) ?? undefined;
145
+ }
@@ -0,0 +1,10 @@
1
+ import type { RecordContract } from "./record.js";
2
+ /** The file envelope over a workspace directory, under the key the host names. `notBefore` is when the node's
3
+ * conversation first opened, in epoch milliseconds: an older file is another run's and is refused. A file that is
4
+ * not there fails with the file system's own `ENOENT`. A workspace that is the file system's root confines nothing,
5
+ * and every path is refused there as outside it. */
6
+ export declare function workspaceRecordFile(options: {
7
+ key: string;
8
+ workspace: string;
9
+ notBefore?: () => number;
10
+ }): NonNullable<RecordContract["file"]>;
@@ -0,0 +1,56 @@
1
+ // A record delivered as a workspace file: the reader behind the file envelope. The path is the model's, so it is
2
+ // held to the workspace (a relative `.json` path, no symlink on the way, a regular file) and to this run (written
3
+ // after the node's conversation opened), and the file must parse.
4
+ import { constants } from "node:fs";
5
+ import fs from "node:fs/promises";
6
+ import path from "node:path";
7
+ // A file system's modification times can trail the clock slightly; a file the node just wrote is not stale.
8
+ const CLOCK_SKEW_MS = 2_000;
9
+ /** The file envelope over a workspace directory, under the key the host names. `notBefore` is when the node's
10
+ * conversation first opened, in epoch milliseconds: an older file is another run's and is refused. A file that is
11
+ * not there fails with the file system's own `ENOENT`. A workspace that is the file system's root confines nothing,
12
+ * and every path is refused there as outside it. */
13
+ export function workspaceRecordFile(options) {
14
+ const { key } = options;
15
+ return {
16
+ key,
17
+ read: async (relative) => {
18
+ if (path.isAbsolute(relative) || path.extname(relative).toLowerCase() !== ".json")
19
+ throw new Error(`${key} must name a workspace-relative .json file`);
20
+ const root = path.resolve(options.workspace);
21
+ const target = path.resolve(root, relative);
22
+ if (!target.startsWith(`${root}${path.sep}`))
23
+ throw new Error(`${key} names a path outside the workspace: ${relative}`);
24
+ // Lexical containment alone would follow a symlink in the workspace out of it.
25
+ let cursor = root;
26
+ for (const segment of path.relative(root, target).split(path.sep).filter(Boolean)) {
27
+ cursor = path.join(cursor, segment);
28
+ const stat = await fs.lstat(cursor).catch(() => null);
29
+ if (!stat)
30
+ break;
31
+ if (stat.isSymbolicLink())
32
+ throw new Error(`${key} names a path outside the workspace through a symlink: ${relative}`);
33
+ }
34
+ // Non-blocking: a named pipe opens at once and is refused below, where a plain open would wait for its writer.
35
+ const handle = await fs.open(target, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
36
+ let text;
37
+ try {
38
+ const stat = await handle.stat();
39
+ if (!stat.isFile())
40
+ throw new Error(`${key} must name a regular file`);
41
+ if (options.notBefore && stat.mtimeMs < options.notBefore() - CLOCK_SKEW_MS)
42
+ throw new Error(`${key} is stale; write it during this run before submitting`);
43
+ text = await handle.readFile({ encoding: "utf8" });
44
+ }
45
+ finally {
46
+ await handle.close();
47
+ }
48
+ try {
49
+ return JSON.parse(text);
50
+ }
51
+ catch (error) {
52
+ throw new Error(`${key} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
53
+ }
54
+ },
55
+ };
56
+ }
@@ -0,0 +1,76 @@
1
+ import type { Context, JsonValue } from "@earendil-works/chord";
2
+ import { type ConversationId, type DocumentReader, type HookApi, type HookRegistration, type ToolExecutionApi, type ToolRegistration } from "@earendil-works/pi-durable";
3
+ import { type Delivery, type Disagreement, type RecordContract, type RecordStore } from "./record.js";
4
+ /** The record a conversation delivered, or null while it has not, and the delivery attempts it has spent. */
5
+ export declare const RecordDoc: import("@earendil-works/pi-durable").ConversationDocToken<{
6
+ record: JsonValue | null;
7
+ attempts: number;
8
+ }>;
9
+ /** The gate's own state beside the record: whether the second reading's round was spent, and what it still
10
+ * disagreed with in the delivered record. */
11
+ export declare const GateDoc: import("@earendil-works/pi-durable").ConversationDocToken<{
12
+ bounced: boolean;
13
+ disagreements: Disagreement[];
14
+ }>;
15
+ /** The core's store on a conversation's two documents, written through a tool call's commits. */
16
+ export declare function recordStore(api: Pick<ToolExecutionApi, "commit" | "snapshot" | "conversationId">, context: Context): RecordStore;
17
+ /** The record a conversation delivered, or undefined while it has not, with what its second reading still disagreed with. */
18
+ export declare function deliveredRecord(reader: Pick<DocumentReader, "snapshot">, conversationId: ConversationId, context: Context): Promise<{
19
+ record: JsonValue;
20
+ disagreements: Disagreement[];
21
+ } | undefined>;
22
+ /** The `submit` tool as a model is shown it for one record: what it delivers, and the record's top-level fields with
23
+ * their plain types and descriptions, none required, since a partial record is an attempt the core counts. A record
24
+ * that may be delivered as a workspace file is offered the envelope under `fileKey`. */
25
+ export declare function submitDefinition(record: {
26
+ schema: Record<string, unknown>;
27
+ label: string;
28
+ fileKey?: string;
29
+ }): {
30
+ description: string;
31
+ parameters: Record<string, unknown>;
32
+ };
33
+ export type RecordToolOptions = {
34
+ /** The one record this tool delivers: its schema, what the model is told it delivers ("the summary record") and
35
+ * the key it may be delivered under as a workspace file. Absent, the tool serves conversations with different
36
+ * records: it is registered with open parameters, each conversation's contract names its schema and file key, and
37
+ * the host presents each conversation its own definition (`submitDefinition`) in a request hook. */
38
+ record?: {
39
+ schema: Record<string, unknown>;
40
+ label: string;
41
+ fileKey?: string;
42
+ };
43
+ /** The delivery contract of the conversation that called: its schema, reviewers, host checks and file reader. It is
44
+ * read on every call, so a host may resolve it late (a conversation pi resumed before its owner reached it again). */
45
+ contract(api: Pick<ToolExecutionApi, "conversationId" | "snapshot">, context: Context): RecordContract | Promise<RecordContract>;
46
+ /** Told each delivery after its commit: a host writes its own rows from it. A throw is the caller's own failure. */
47
+ onDelivery?(delivery: Delivery, conversationId: ConversationId): void | Promise<void>;
48
+ /** Whether an error is the host's own failure. Such an error ends the node's run with `fatalText`, and the host is
49
+ * told through `onFatal`; any other error is the tool's and is thrown. */
50
+ fatal?: (error: unknown) => boolean;
51
+ onFatal?(error: unknown, conversationId: ConversationId): void;
52
+ fatalText?: string;
53
+ /** How a disagreement is told to the model when its record goes back (default `disagreementText`). */
54
+ say?: (disagreement: Disagreement) => string;
55
+ };
56
+ /** The `submit` tool. */
57
+ export declare function recordTool(options: RecordToolOptions): ToolRegistration;
58
+ export type RecordNudgeOptions = {
59
+ /** What is owed, as the nudge names it; undefined for a conversation this hook does not nudge (it owes no record). */
60
+ label(api: Pick<HookApi, "conversationId" | "snapshot">, context: Context): string | undefined | Promise<string | undefined>;
61
+ /** Counts one delivery attempt on the conversation's record, durably, before the model is nudged. A hook cannot
62
+ * commit, so the conversation's owner supplies the write. */
63
+ spend(conversationId: ConversationId, context: Context): Promise<void>;
64
+ /** Delivery attempts the conversation gets (default `DELIVERY_ATTEMPTS`). */
65
+ maxAttempts?: number;
66
+ };
67
+ /** The nudge: a yield with the record still owed continues the run with a reminder, each nudge one delivery attempt;
68
+ * past the attempts the run ends. The nudge that spends the last attempt still continues, so the model is asked once
69
+ * more after it. */
70
+ export declare function recordNudge(options: RecordNudgeOptions): HookRegistration;
71
+ /** One nudge's delivery attempt, as a commit on the conversation's record. */
72
+ export declare const spendNudge: (tx: {
73
+ doc(token: typeof RecordDoc, conversationId: ConversationId): Promise<{
74
+ attempts: number;
75
+ }>;
76
+ }, conversationId: ConversationId) => Promise<void>;
@@ -0,0 +1,126 @@
1
+ import { defineDoc, defineTool, GenerationTask, hook, } from "@earendil-works/pi-durable";
2
+ import { DELIVERY_ATTEMPTS, deliver, deliveryTerminates, deliveryText, fileSubmission, mixedFileSubmission, nudgeText, repairRecord, VIOLATIONS_SHOWN, } from "./record.js";
3
+ import { SUBMIT_TOOL } from "./host-tools.js";
4
+ import { toolResult } from "./pi-versions.js";
5
+ /** The record a conversation delivered, or null while it has not, and the delivery attempts it has spent. */
6
+ export const RecordDoc = defineDoc({
7
+ kind: "agentrun.record", version: 1, scope: "conversation", history: "latest", fork: "initial", initial: () => ({ record: null, attempts: 0 }),
8
+ checkpointWhen: () => false,
9
+ });
10
+ /** The gate's own state beside the record: whether the second reading's round was spent, and what it still
11
+ * disagreed with in the delivered record. */
12
+ export const GateDoc = defineDoc({
13
+ kind: "agentrun.gate", version: 1, scope: "conversation", history: "latest", fork: "initial", initial: () => ({ bounced: false, disagreements: [] }),
14
+ checkpointWhen: () => false,
15
+ });
16
+ /** Where `prepareArguments` carries a call's arguments to `execute`. A record's own fields are never read as it. */
17
+ const RAW = "_raw";
18
+ /** The core's store on a conversation's two documents, written through a tool call's commits. */
19
+ export function recordStore(api, context) {
20
+ const id = api.conversationId;
21
+ return {
22
+ read: async () => ({
23
+ record: (await api.snapshot(RecordDoc, id, context)) ?? { record: null, attempts: 0 },
24
+ gate: (await api.snapshot(GateDoc, id, context)) ?? { bounced: false, disagreements: [] },
25
+ }),
26
+ reject: () => api.commit(async (tx) => { const state = await tx.doc(RecordDoc, id); state.attempts += 1; return state.attempts; }, context),
27
+ bounce: () => api.commit(async (tx) => {
28
+ (await tx.doc(GateDoc, id)).bounced = true;
29
+ const state = await tx.doc(RecordDoc, id);
30
+ state.attempts += 1;
31
+ return state.attempts;
32
+ }, context),
33
+ accept: (record, disagreements) => api.commit(async (tx) => {
34
+ const state = await tx.doc(RecordDoc, id);
35
+ state.record = record;
36
+ state.attempts += 1;
37
+ if (disagreements.length)
38
+ (await tx.doc(GateDoc, id)).disagreements = disagreements;
39
+ }, context),
40
+ };
41
+ }
42
+ /** The record a conversation delivered, or undefined while it has not, with what its second reading still disagreed with. */
43
+ export async function deliveredRecord(reader, conversationId, context) {
44
+ const state = await reader.snapshot(RecordDoc, conversationId, context);
45
+ if (state?.record == null)
46
+ return undefined;
47
+ return { record: state.record, disagreements: [...((await reader.snapshot(GateDoc, conversationId, context))?.disagreements ?? [])] };
48
+ }
49
+ /** The `submit` tool as a model is shown it for one record: what it delivers, and the record's top-level fields with
50
+ * their plain types and descriptions, none required, since a partial record is an attempt the core counts. A record
51
+ * that may be delivered as a workspace file is offered the envelope under `fileKey`. */
52
+ export function submitDefinition(record) {
53
+ const { schema, label, fileKey } = record;
54
+ const declared = schema.properties && typeof schema.properties === "object" ? schema.properties : {};
55
+ return {
56
+ description: fileKey
57
+ ? `Deliver ${label}. Submit it inline, or for a large record write JSON in the workspace and pass {"${fileKey}":"relative/path.json"}. It ends the run. These parameters are the output schema: submit validates the record against it and returns the violations to fix, up to ${VIOLATIONS_SHOWN} per call, so there is no schema file to find and no need to validate the record yourself first.`
58
+ : `Deliver ${label}. Submit it inline as the tool arguments. It ends the run. These parameters are the output schema: submit validates the record against it and returns the violations to fix, up to ${VIOLATIONS_SHOWN} per call.`,
59
+ parameters: { type: "object", additionalProperties: true, properties: {
60
+ ...Object.fromEntries(Object.entries(declared).filter(([key]) => key !== RAW).map(([key, property]) => [key, { ...(typeof property?.type === "string" ? { type: property.type } : {}), ...(typeof property?.description === "string" ? { description: property.description } : {}) }])),
61
+ ...(fileKey ? { [fileKey]: { type: "string", description: "Workspace-relative path to the complete JSON record" } } : {})
62
+ } },
63
+ };
64
+ }
65
+ /** A call's arguments as the core decides them: a file submission as it is, an inline record repaired as a transport
66
+ * spelling. The reserved file key beside inline fields is the transport's, never the record's. */
67
+ function carried(args, schema, fileKey) {
68
+ if (fileKey && (fileSubmission(args, fileKey) !== null || mixedFileSubmission(args, schema, fileKey)))
69
+ return args;
70
+ const inline = fileKey && args && typeof args === "object" && !Array.isArray(args) ? (({ [fileKey]: _reserved, ...rest }) => rest)(args) : args;
71
+ return repairRecord(inline, schema);
72
+ }
73
+ /** The `submit` tool. */
74
+ export function recordTool(options) {
75
+ const { record } = options;
76
+ const shown = record ? submitDefinition(record) : { description: "Deliver the record. It ends the run.", parameters: { type: "object", additionalProperties: true } };
77
+ const answer = (delivery, maxAttempts) => toolResult([{ type: "text", text: deliveryText(delivery, maxAttempts, options.say) }], {
78
+ ...(delivery.status === "rejected" || delivery.status === "bounced" ? { isError: true } : {}),
79
+ ...(deliveryTerminates(delivery) ? { control: { terminate: true } } : {}),
80
+ });
81
+ return defineTool({
82
+ name: SUBMIT_TOOL,
83
+ description: shown.description,
84
+ parameters: shown.parameters,
85
+ // Every call's arguments are carried to `execute`; one record's are repaired here, before the Harness validates.
86
+ prepareArguments: (args) => ({ [RAW]: record ? carried(args, record.schema, record.fileKey) : args }),
87
+ replay: "safe",
88
+ executionMode: "sequential",
89
+ execute: async (args, api, context) => {
90
+ try {
91
+ const contract = await options.contract(api, context);
92
+ const raw = args[RAW];
93
+ const delivery = await deliver({ ...contract, ...(options.fatal ? { fatal: options.fatal } : {}) }, recordStore(api, context), record ? raw : carried(raw, contract.schema, contract.file?.key));
94
+ await options.onDelivery?.(delivery, api.conversationId);
95
+ return answer(delivery, contract.maxAttempts ?? DELIVERY_ATTEMPTS);
96
+ }
97
+ catch (error) {
98
+ if (!options.fatal?.(error))
99
+ throw error;
100
+ options.onFatal?.(error, api.conversationId);
101
+ return toolResult([{ type: "text", text: options.fatalText ?? "The run cannot record this submission; the run stops." }], { isError: true, control: { terminate: true } });
102
+ }
103
+ },
104
+ });
105
+ }
106
+ /** The nudge: a yield with the record still owed continues the run with a reminder, each nudge one delivery attempt;
107
+ * past the attempts the run ends. The nudge that spends the last attempt still continues, so the model is asked once
108
+ * more after it. */
109
+ export function recordNudge(options) {
110
+ return hook(GenerationTask, {
111
+ onYield: async (_answer, api, context) => {
112
+ const state = await api.snapshot(RecordDoc, api.conversationId, context);
113
+ if (state?.record != null)
114
+ return undefined;
115
+ const label = await options.label(api, context);
116
+ if (label === undefined || (state?.attempts ?? 0) >= (options.maxAttempts ?? DELIVERY_ATTEMPTS))
117
+ return undefined;
118
+ await options.spend(api.conversationId, context);
119
+ return { continue: nudgeText(label) };
120
+ },
121
+ });
122
+ }
123
+ /** One nudge's delivery attempt, as a commit on the conversation's record. */
124
+ export const spendNudge = async (tx, conversationId) => {
125
+ (await tx.doc(RecordDoc, conversationId)).attempts += 1;
126
+ };
@@ -0,0 +1,151 @@
1
+ /** The record a node delivered, or null while it has not, and the delivery attempts it has spent. */
2
+ export type RecordState = {
3
+ record: unknown;
4
+ attempts: number;
5
+ };
6
+ /** What the second reading disagrees with in a record: its question, the kind of reading, the verdict and why. */
7
+ export type Disagreement = {
8
+ id: string;
9
+ kind: string;
10
+ verdict: string;
11
+ reasons: string[];
12
+ };
13
+ /** Whether the second reading's round was spent, and what it still disagreed with in the delivered record. */
14
+ export type GateState = {
15
+ bounced: boolean;
16
+ disagreements: Disagreement[];
17
+ };
18
+ /** Delivery attempts a node gets: rejections, the second reading's one bounce and nudges, each once. */
19
+ export declare const DELIVERY_ATTEMPTS = 6;
20
+ /** The most schema violations one rejected delivery lists; the submit tool's description tells the model the number. */
21
+ export declare const VIOLATIONS_SHOWN = 8;
22
+ /** One reviewer's reading of a structurally valid record. `no_verdict` is a reviewer that could not answer. */
23
+ export type Reading = "disagrees" | "agrees" | "no_verdict";
24
+ /** The second reading on one structurally valid submission: it sends the record back only while its round
25
+ * is unspent and a reviewer disagrees. A reviewer with no verdict never sends a record back. */
26
+ export declare function gate(bounced: boolean, readings: readonly Reading[]): "accept" | "bounce";
27
+ /** What a node is answered with. Only `delivered` is a delivery; each of the others spends one attempt. */
28
+ export type DeliveryEvent = "rejected" | "bounce" | "nudge" | "delivered";
29
+ /** A node's delivery, as far as the attempts count it. */
30
+ export type DeliveryCount = {
31
+ attempts: number;
32
+ delivered: boolean;
33
+ };
34
+ /** Whether a node's delivery has ended: it delivered, or its attempts are spent. */
35
+ export declare const deliveryEnded: (max: number, state: DeliveryCount) => boolean;
36
+ /** One answer applied to the count. An ended delivery takes no further answer; every other answer counts once. */
37
+ export declare function spend(max: number, state: DeliveryCount, event: DeliveryEvent): DeliveryCount;
38
+ /** What makes a schema one no `submit` call can satisfy: a call's arguments are an object, so the schema must be a
39
+ * JSON Schema object whose root type, when it names one, admits an object. A node runner refuses such a schema
40
+ * before any conversation exists. */
41
+ export declare function lintRecordRoot(schema: unknown): string[];
42
+ /** Where the schema expects an object or an array and the submitted value is a string that parses to one, the
43
+ * parsed value; where it expects a number, an integer, a boolean or null and admits no string, the scalar a
44
+ * string spells. Some model families serialise nested tool arguments as strings: the content is valid and
45
+ * every submit fails on its spelling. A string that parses to a container the field also admits is read as that
46
+ * container; only against a scalar does a field that admits a string keep the string. */
47
+ export declare function parseStringifiedContainers(value: unknown, schema: Record<string, unknown> | undefined, depth?: number, root?: unknown): unknown;
48
+ /** The path of every string that spells "no value" in a field whose schema admits JSON null and does not list it. */
49
+ export declare function nullSpellings(value: unknown, schema: unknown, root?: unknown, at?: string): string[];
50
+ /** The record with every such string replaced by JSON null, in place. A repair the record as a whole refuses
51
+ * (it satisfied its schema before and does not after) is undone in full, so a spelling stays only where null
52
+ * is inadmissible; `undo: false` leaves that judgement to a caller that repairs more of the record and judges the
53
+ * whole. `""` is a value and stays. */
54
+ export declare function healNullSpellings<T>(record: T, schema: Record<string, unknown>, options?: {
55
+ undo?: boolean;
56
+ }): T;
57
+ /** A record's transport spellings repaired against its schema, without touching `args`. */
58
+ export declare function repairRecord(args: unknown, schema: Record<string, unknown>): unknown;
59
+ /** The file a submission names and nothing else: `{ <key>: "relative/path.json" }`. */
60
+ export declare function fileSubmission(args: unknown, key: string): string | null;
61
+ /** A submission with fields beside the file key. Fields that form a whole record on their own are that record;
62
+ * otherwise the file holds the record, and each field beside it may only restate the file's value. A schema
63
+ * that declares the file key as its own field keeps it inline. */
64
+ export declare function mixedFileSubmission(args: unknown, schema: Record<string, unknown> | undefined, key: string): {
65
+ file: string;
66
+ extras: Record<string, unknown>;
67
+ } | null;
68
+ /** The fields beside the file key that the file's record does not hold with the same value. */
69
+ export declare function extrasNotInRecord(record: unknown, extras: Record<string, unknown>): string[];
70
+ /** One host check's refusal of a candidate: the problems the model must fix, and the reason they are grouped under. */
71
+ export type Refusal = {
72
+ problems: string[];
73
+ reason?: string;
74
+ };
75
+ /** A second reader of a structurally valid record. It returns what it disagrees with (nothing when it agrees or
76
+ * has no verdict). `round` says whether a disagreement still sends the record back. A reviewer that throws
77
+ * decides nothing, unless the contract's `fatal` claims the error. */
78
+ export type Reviewer = (candidate: unknown, context: {
79
+ round: boolean;
80
+ }) => Disagreement[] | Promise<Disagreement[]>;
81
+ export type RecordContract = {
82
+ /** The node's record schema, the `submit` tool's contract. */
83
+ schema: Record<string, unknown>;
84
+ /** Delivery attempts the node gets (default `DELIVERY_ATTEMPTS`). */
85
+ maxAttempts?: number;
86
+ /** A record may be delivered as a workspace file named under `key`; `read` returns the file's parsed JSON or
87
+ * throws (an error whose `code` is `ENOENT` for a file that is not there). Absent, a record is inline only. */
88
+ file?: {
89
+ key: string;
90
+ read(path: string): Promise<unknown>;
91
+ };
92
+ /** Contracts the host owns, held before the schema: each problem is said with the core's own findings. */
93
+ contracts?: (candidate: unknown) => string[] | Promise<string[]>;
94
+ /** Checks held after the schema, in order; the first refusal is the rejection. One that throws refuses with
95
+ * what it threw. */
96
+ checks?: ReadonlyArray<(candidate: unknown) => Refusal | null | Promise<Refusal | null>>;
97
+ /** The second reading, in order. */
98
+ reviewers?: readonly Reviewer[];
99
+ /** Whether a reviewer's error is the caller's own failure, to be thrown and not absorbed. */
100
+ fatal?: (error: unknown) => boolean;
101
+ };
102
+ /** The two states behind a node's delivery. Each write is one atomic change; `reject` and `bounce` return the
103
+ * attempts spent after it. The bounce spends the round before the model is told, so a crash cannot grant it twice. */
104
+ export type RecordStore = {
105
+ read(): Promise<{
106
+ record: RecordState;
107
+ gate: GateState;
108
+ }>;
109
+ reject(): Promise<number>;
110
+ bounce(): Promise<number>;
111
+ accept(record: unknown, disagreements: Disagreement[]): Promise<void>;
112
+ };
113
+ /** What one submission came to. `spent` says the delivery attempts are gone and the node's run ends here. */
114
+ export type Delivery = {
115
+ status: "already";
116
+ } | {
117
+ status: "rejected";
118
+ attempts: number;
119
+ spent: boolean;
120
+ reason: string;
121
+ problems: string[];
122
+ } | {
123
+ status: "bounced";
124
+ attempts: number;
125
+ spent: boolean;
126
+ disagreements: Disagreement[];
127
+ } | {
128
+ status: "accepted";
129
+ record: unknown;
130
+ disagreements: Disagreement[];
131
+ };
132
+ /** Decide one `submit` call. `args` are the call's arguments as the model sent them, or as `repairRecord`
133
+ * already repaired them. */
134
+ export declare function deliver(contract: RecordContract, store: RecordStore, args: unknown): Promise<Delivery>;
135
+ /** The `submit` tool's answer to the model for one delivery. */
136
+ export declare function deliveryText(delivery: Delivery, maxAttempts?: number, say?: (disagreement: Disagreement) => string): string;
137
+ /** One disagreement as the model reads it. */
138
+ export declare const disagreementText: (d: Disagreement) => string;
139
+ /** Whether a delivery ends the node's run: a record was delivered, or the attempts are spent. */
140
+ export declare const deliveryTerminates: (delivery: Delivery) => boolean;
141
+ /** The delivery contract a node's task ends with: the label, the file envelope when one is offered, the
142
+ * authoritative schema and the host's own delivery instructions. The model sees the exact schema only here. */
143
+ export declare function submitFooter(record: {
144
+ label: string;
145
+ schema: Record<string, unknown>;
146
+ fileKey?: string;
147
+ instructions?: string;
148
+ reviewed?: boolean;
149
+ }): string;
150
+ /** What a yield without a record is answered with, when the delivery has an attempt left for it. */
151
+ export declare const nudgeText: (label: string) => string;