@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35

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 (466) hide show
  1. package/CHANGELOG.md +368 -0
  2. package/README.md +341 -208
  3. package/dist/adapters.d.ts +3 -4
  4. package/dist/adapters.js +18 -15
  5. package/dist/agent-rows.d.ts +99 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +75 -25
  9. package/dist/agents.d.ts +9 -125
  10. package/dist/agents.js +15 -305
  11. package/dist/answer-json.d.ts +23 -0
  12. package/dist/answer-json.js +58 -0
  13. package/dist/api-only.d.ts +1 -1
  14. package/dist/api-only.js +2 -2
  15. package/dist/archil-settings.d.ts +11 -1
  16. package/dist/archil-settings.js +10 -0
  17. package/dist/bash-read-only.d.ts +35 -0
  18. package/dist/bash-read-only.js +778 -0
  19. package/dist/box-settings.d.ts +3 -23
  20. package/dist/box-settings.js +7 -51
  21. package/dist/boxes.d.ts +17 -0
  22. package/dist/boxes.js +27 -20
  23. package/dist/browser-commands.d.ts +5 -2
  24. package/dist/browser-commands.js +4 -4
  25. package/dist/browser-computer.d.ts +5 -0
  26. package/dist/browser-computer.js +21 -0
  27. package/dist/browser-cost.d.ts +9 -6
  28. package/dist/browser-cost.js +95 -51
  29. package/dist/browser-live.d.ts +7 -20
  30. package/dist/browser-live.js +15 -93
  31. package/dist/browser-person.d.ts +18 -51
  32. package/dist/browser-person.js +94 -277
  33. package/dist/budget.d.ts +0 -5
  34. package/dist/budget.js +0 -5
  35. package/dist/cap.d.ts +14 -8
  36. package/dist/cap.js +19 -9
  37. package/dist/cli.js +71 -18
  38. package/dist/closed-pipes.d.ts +2 -0
  39. package/dist/closed-pipes.js +13 -0
  40. package/dist/computer-commands.d.ts +2 -0
  41. package/dist/computer-commands.js +2 -0
  42. package/dist/computer-keys.d.ts +20 -10
  43. package/dist/computer-keys.js +36 -54
  44. package/dist/computer-setting.d.ts +20 -3
  45. package/dist/computer-setting.js +58 -10
  46. package/dist/computers.d.ts +35 -2
  47. package/dist/computers.js +72 -11
  48. package/dist/confine.d.ts +120 -0
  49. package/dist/confine.js +436 -0
  50. package/dist/console/assets/index-B7NKTU8E.css +1 -0
  51. package/dist/console/assets/index-CXZMgJE7.js +550 -0
  52. package/dist/console/index.html +2 -2
  53. package/dist/content-filter.d.ts +7 -0
  54. package/dist/content-filter.js +23 -0
  55. package/dist/decision-cap.d.ts +7 -29
  56. package/dist/decision-cap.js +3 -94
  57. package/dist/decision-rows.d.ts +1 -1
  58. package/dist/decision-rows.js +1 -1
  59. package/dist/docker-daemon.d.ts +31 -0
  60. package/dist/docker-daemon.js +56 -0
  61. package/dist/effort-guidance.js +4 -3
  62. package/dist/environment.d.ts +0 -3
  63. package/dist/environment.js +3 -5
  64. package/dist/errors.d.ts +1 -2
  65. package/dist/errors.js +9 -9
  66. package/dist/explain.js +3 -1
  67. package/dist/filed-answer.d.ts +32 -0
  68. package/dist/filed-answer.js +160 -0
  69. package/dist/files.d.ts +1 -3
  70. package/dist/files.js +2 -4
  71. package/dist/github-connection.d.ts +1 -1
  72. package/dist/github-connection.js +25 -7
  73. package/dist/github-faux.d.ts +26 -0
  74. package/dist/github-faux.js +76 -0
  75. package/dist/github.d.ts +6 -2
  76. package/dist/github.js +5 -3
  77. package/dist/graph-served.d.ts +5 -3
  78. package/dist/graph-served.js +14 -6
  79. package/dist/graph-view.d.ts +3 -5
  80. package/dist/graph-view.js +9 -16
  81. package/dist/handed-values.d.ts +9 -0
  82. package/dist/handed-values.js +26 -0
  83. package/dist/harness-install.d.ts +1 -7
  84. package/dist/harness-install.js +1 -18
  85. package/dist/harness-opencode/adapter.d.ts +7 -0
  86. package/dist/harness-opencode/adapter.js +23 -6
  87. package/dist/harness-opencode/harness.js +0 -1
  88. package/dist/harness-opencode/host/policy.js +2 -2
  89. package/dist/harness-opencode/index.d.ts +1 -1
  90. package/dist/harness-opencode/index.js +1 -1
  91. package/dist/harness-opencode/verify.d.ts +17 -0
  92. package/dist/harness-opencode/verify.js +30 -10
  93. package/dist/harness-table.js +6 -1
  94. package/dist/heard.js +1 -1
  95. package/dist/held-fd.d.ts +5 -0
  96. package/dist/held-fd.js +14 -0
  97. package/dist/host-calls.d.ts +20 -0
  98. package/dist/host-calls.js +12 -0
  99. package/dist/host-tools.d.ts +4 -21
  100. package/dist/host-tools.js +4 -61
  101. package/dist/host.d.ts +2 -4
  102. package/dist/host.js +2 -7
  103. package/dist/import-summary.d.ts +1 -5
  104. package/dist/import-summary.js +0 -21
  105. package/dist/import.d.ts +6 -6
  106. package/dist/import.js +14 -15
  107. package/dist/index.d.ts +1 -0
  108. package/dist/index.js +1 -0
  109. package/dist/key-refusal.d.ts +5 -1
  110. package/dist/key-refusal.js +19 -4
  111. package/dist/learn/check.d.ts +8 -2
  112. package/dist/learn/check.js +85 -31
  113. package/dist/learn/folder.d.ts +11 -4
  114. package/dist/learn/folder.js +17 -19
  115. package/dist/learn/grade.d.ts +18 -1
  116. package/dist/learn/grade.js +108 -14
  117. package/dist/learn/index.d.ts +5 -5
  118. package/dist/learn/index.js +5 -5
  119. package/dist/learn/learning.sh +1 -14
  120. package/dist/learn/notes.d.ts +14 -3
  121. package/dist/learn/notes.js +16 -6
  122. package/dist/learn/reflect.d.ts +31 -2
  123. package/dist/learn/reflect.js +83 -6
  124. package/dist/learn/relevance.d.ts +24 -0
  125. package/dist/learn/relevance.js +91 -0
  126. package/dist/learn/secrets.d.ts +7 -1
  127. package/dist/learn/secrets.js +86 -19
  128. package/dist/learn/skills.d.ts +159 -18
  129. package/dist/learn/skills.js +644 -64
  130. package/dist/learned-nodes.d.ts +14 -0
  131. package/dist/learned-nodes.js +8 -0
  132. package/dist/learned-workflow.d.ts +41 -6
  133. package/dist/learned-workflow.js +153 -18
  134. package/dist/learning-routes.d.ts +49 -4
  135. package/dist/learning-routes.js +113 -31
  136. package/dist/learning-run.d.ts +16 -31
  137. package/dist/learning-run.js +31 -38
  138. package/dist/learning-words.d.ts +12 -5
  139. package/dist/learning-words.js +18 -9
  140. package/dist/learning.d.ts +91 -97
  141. package/dist/learning.js +176 -320
  142. package/dist/live/stream.js +1 -1
  143. package/dist/live/translate.js +12 -2
  144. package/dist/llm.d.ts +4 -1
  145. package/dist/llm.js +4 -2
  146. package/dist/local-models.d.ts +11 -5
  147. package/dist/local-models.js +13 -8
  148. package/dist/mcp-gateway.d.ts +17 -49
  149. package/dist/mcp-gateway.js +55 -136
  150. package/dist/mcp-oauth.d.ts +10 -14
  151. package/dist/mcp-oauth.js +14 -32
  152. package/dist/mcp-probe.d.ts +0 -7
  153. package/dist/mcp-probe.js +4 -10
  154. package/dist/mcp-servers-store.d.ts +18 -18
  155. package/dist/mcp-servers-store.js +12 -14
  156. package/dist/mcp-store.js +3 -4
  157. package/dist/mcp.js +4 -3
  158. package/dist/model.d.ts +9 -7
  159. package/dist/model.js +51 -27
  160. package/dist/monid.d.ts +0 -2
  161. package/dist/monid.js +3 -6
  162. package/dist/openapi.d.ts +8 -1
  163. package/dist/openapi.js +156 -58
  164. package/dist/page.d.ts +1 -3
  165. package/dist/page.js +6 -18
  166. package/dist/paid-calls.d.ts +21 -27
  167. package/dist/paid-calls.js +26 -61
  168. package/dist/pause.d.ts +2 -19
  169. package/dist/pause.js +5 -74
  170. package/dist/port-models.d.ts +10 -3
  171. package/dist/port-models.js +26 -6
  172. package/dist/propose.d.ts +2 -0
  173. package/dist/propose.js +80 -45
  174. package/dist/push-handler.d.ts +1 -1
  175. package/dist/reflect-range.d.ts +25 -0
  176. package/dist/reflect-range.js +30 -0
  177. package/dist/refusal-words.d.ts +5 -1
  178. package/dist/refusal-words.js +5 -1
  179. package/dist/rows.d.ts +1 -1
  180. package/dist/run-cut.d.ts +0 -6
  181. package/dist/run-cut.js +0 -6
  182. package/dist/run-db.d.ts +2 -11
  183. package/dist/run-db.js +2 -37
  184. package/dist/run-launch.d.ts +21 -2
  185. package/dist/run-launch.js +14 -5
  186. package/dist/run-learning-served.d.ts +21 -4
  187. package/dist/run-learning-served.js +23 -13
  188. package/dist/run-reads-over-store.d.ts +5 -3
  189. package/dist/run-reads-over-store.js +25 -14
  190. package/dist/run-secrets.d.ts +1 -1
  191. package/dist/run-timeline-served.d.ts +5 -1
  192. package/dist/run-timeline-served.js +27 -6
  193. package/dist/run-view.d.ts +37 -22
  194. package/dist/run-view.js +85 -38
  195. package/dist/runnable.d.ts +21 -10
  196. package/dist/runnable.js +35 -12
  197. package/dist/runner/adapter-loop.d.ts +36 -5
  198. package/dist/runner/adapter-loop.js +663 -69
  199. package/dist/runner/adapter-run-spec.d.ts +42 -8
  200. package/dist/runner/adapter-run-spec.js +186 -52
  201. package/dist/runner/adapters/index.js +11 -1
  202. package/dist/runner/adapters/pi.d.ts +40 -2
  203. package/dist/runner/adapters/pi.js +110 -27
  204. package/dist/runner/beside.d.ts +38 -3
  205. package/dist/runner/beside.js +54 -5
  206. package/dist/runner/claim-secrets.d.ts +16 -1
  207. package/dist/runner/claim-secrets.js +62 -14
  208. package/dist/runner/cli-run-spec.d.ts +5 -0
  209. package/dist/runner/cli-run-spec.js +159 -41
  210. package/dist/runner/commands.js +1 -1
  211. package/dist/runner/computer-journal.d.ts +15 -2
  212. package/dist/runner/computer-journal.js +41 -5
  213. package/dist/runner/conformance/harness.d.ts +1 -0
  214. package/dist/runner/conformance/harness.js +123 -13
  215. package/dist/runner/conformance/subject.d.ts +4 -1
  216. package/dist/runner/dispatch.d.ts +8 -1
  217. package/dist/runner/dispatch.js +81 -7
  218. package/dist/runner/end-of-run.d.ts +8 -2
  219. package/dist/runner/end-of-run.js +10 -4
  220. package/dist/runner/github-app.d.ts +7 -2
  221. package/dist/runner/github-app.js +47 -16
  222. package/dist/runner/harness-loops.d.ts +15 -2
  223. package/dist/runner/harness-loops.js +38 -2
  224. package/dist/runner/journal-kinds.d.ts +60 -6
  225. package/dist/runner/journal-kinds.js +43 -5
  226. package/dist/runner/journal-reader.d.ts +1 -1
  227. package/dist/runner/journal-reader.js +2 -2
  228. package/dist/runner/learning-ask.d.ts +4 -0
  229. package/dist/runner/learning-ask.js +15 -1
  230. package/dist/runner/learning-end.d.ts +18 -3
  231. package/dist/runner/learning-end.js +194 -20
  232. package/dist/runner/learning-loop.d.ts +7 -0
  233. package/dist/runner/learning-loop.js +36 -8
  234. package/dist/runner/learning-seed.d.ts +6 -0
  235. package/dist/runner/learning-seed.js +6 -0
  236. package/dist/runner/loop-contract.d.ts +4 -0
  237. package/dist/runner/main.d.ts +61 -9
  238. package/dist/runner/main.js +144 -20
  239. package/dist/runner/mcp-claim.d.ts +3 -0
  240. package/dist/runner/mcp-claim.js +7 -3
  241. package/dist/runner/mcp-github.d.ts +11 -2
  242. package/dist/runner/mcp-github.js +55 -4
  243. package/dist/runner/mcp-run.d.ts +2 -0
  244. package/dist/runner/mcp-run.js +16 -5
  245. package/dist/runner/memory-claim.d.ts +9 -0
  246. package/dist/runner/memory-claim.js +25 -0
  247. package/dist/runner/metrics.d.ts +46 -1
  248. package/dist/runner/metrics.js +156 -1
  249. package/dist/runner/model-route.d.ts +16 -0
  250. package/dist/runner/model-route.js +134 -10
  251. package/dist/runner/reflect-hook.d.ts +12 -1
  252. package/dist/runner/reflect-hook.js +33 -3
  253. package/dist/runner/runner.d.ts +20 -0
  254. package/dist/runner/runner.js +146 -18
  255. package/dist/runner/spec-holds.d.ts +7 -2
  256. package/dist/runner/spec-holds.js +4 -3
  257. package/dist/runner/store-port.d.ts +1 -1
  258. package/dist/runner/store-secrets.d.ts +3 -3
  259. package/dist/runner/store-secrets.js +8 -12
  260. package/dist/runner/text-tools.d.ts +44 -0
  261. package/dist/runner/text-tools.js +237 -0
  262. package/dist/runner/workflow-host.d.ts +7 -2
  263. package/dist/runner/workflow-host.js +3 -1
  264. package/dist/runner/workflow-loop.d.ts +10 -1
  265. package/dist/runner/workflow-loop.js +14 -6
  266. package/dist/runner/workflow-spec.d.ts +21 -0
  267. package/dist/runner/workflow-spec.js +217 -93
  268. package/dist/runs-over-store.d.ts +14 -3
  269. package/dist/runs-over-store.js +100 -23
  270. package/dist/seal-key.d.ts +0 -2
  271. package/dist/seal-key.js +5 -45
  272. package/dist/sealed-settings-store.d.ts +19 -4
  273. package/dist/sealed-settings-store.js +9 -9
  274. package/dist/sealing.d.ts +4 -0
  275. package/dist/sealing.js +20 -0
  276. package/dist/secret-cut.d.ts +1 -1
  277. package/dist/secret-cut.js +1 -1
  278. package/dist/secret-name.d.ts +9 -0
  279. package/dist/secret-name.js +15 -0
  280. package/dist/secret-writes.d.ts +0 -1
  281. package/dist/secret-writes.js +0 -1
  282. package/dist/server-fs.d.ts +4 -0
  283. package/dist/server-fs.js +8 -2
  284. package/dist/server-lock.d.ts +0 -24
  285. package/dist/server-lock.js +5 -85
  286. package/dist/server-secrets-store.d.ts +4 -4
  287. package/dist/server-secrets-store.js +9 -31
  288. package/dist/server-secrets.d.ts +4 -9
  289. package/dist/server-secrets.js +12 -36
  290. package/dist/server.d.ts +37 -56
  291. package/dist/server.js +322 -134
  292. package/dist/sign-ins-store.d.ts +34 -36
  293. package/dist/sign-ins-store.js +27 -38
  294. package/dist/sign-ins.d.ts +2 -119
  295. package/dist/sign-ins.js +5 -311
  296. package/dist/standard-webhooks.d.ts +1 -1
  297. package/dist/standard-webhooks.js +1 -1
  298. package/dist/stats.d.ts +3 -2
  299. package/dist/stats.js +1 -1
  300. package/dist/stop-signals.d.ts +4 -2
  301. package/dist/stop-signals.js +5 -3
  302. package/dist/store/agent-body.d.ts +12 -2
  303. package/dist/store/agent-body.js +22 -4
  304. package/dist/store/deadline.d.ts +18 -0
  305. package/dist/store/deadline.js +45 -0
  306. package/dist/store/index.d.ts +2 -2
  307. package/dist/store/index.js +2 -2
  308. package/dist/store/open.d.ts +6 -3
  309. package/dist/store/open.js +2 -2
  310. package/dist/store/postgres/connection.d.ts +22 -2
  311. package/dist/store/postgres/connection.js +211 -41
  312. package/dist/store/postgres/migrate.d.ts +4 -0
  313. package/dist/store/postgres/migrate.js +9 -2
  314. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  315. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  316. package/dist/store/postgres/store.d.ts +9 -2
  317. package/dist/store/postgres/store.js +9 -0
  318. package/dist/store/schema.js +1 -1
  319. package/dist/store/seal.js +2 -2
  320. package/dist/store/sqlite/connection.js +14 -5
  321. package/dist/store/sqlite/run-patch.d.ts +3 -0
  322. package/dist/store/sqlite/run-patch.js +3 -0
  323. package/dist/store/sqlite/store.js +41 -12
  324. package/dist/store/store.d.ts +35 -6
  325. package/dist/store/store.js +12 -2
  326. package/dist/store-reads/cap.d.ts +1 -1
  327. package/dist/store-reads/cap.js +22 -4
  328. package/dist/store-reads/journal.d.ts +9 -6
  329. package/dist/store-reads/journal.js +129 -18
  330. package/dist/store-reads/learning.d.ts +82 -8
  331. package/dist/store-reads/learning.js +184 -11
  332. package/dist/store-reads/workflow.d.ts +1 -1
  333. package/dist/store-reads/workflow.js +1 -1
  334. package/dist/store-view.d.ts +19 -1
  335. package/dist/store-view.js +95 -27
  336. package/dist/template-eval.d.ts +60 -4
  337. package/dist/template-eval.js +120 -54
  338. package/dist/templates.d.ts +33 -14
  339. package/dist/templates.js +82 -46
  340. package/dist/timeline/group.d.ts +33 -0
  341. package/dist/timeline/group.js +77 -0
  342. package/dist/timeline/index.d.ts +7 -0
  343. package/dist/timeline/index.js +7 -0
  344. package/dist/timeline/labels.d.ts +79 -0
  345. package/dist/timeline/labels.js +150 -0
  346. package/dist/timeline/origin.d.ts +56 -0
  347. package/dist/timeline/origin.js +92 -0
  348. package/dist/timeline/render-text.d.ts +11 -0
  349. package/dist/timeline/render-text.js +62 -0
  350. package/dist/timeline/timeline.d.ts +282 -0
  351. package/dist/timeline/timeline.js +1308 -0
  352. package/dist/timeline/util.d.ts +17 -0
  353. package/dist/timeline/util.js +49 -0
  354. package/dist/tool-budget.d.ts +18 -0
  355. package/dist/tool-budget.js +50 -0
  356. package/dist/tool-gate.d.ts +47 -218
  357. package/dist/tool-gate.js +87 -545
  358. package/dist/tool-keys-store.d.ts +11 -12
  359. package/dist/tool-keys-store.js +24 -31
  360. package/dist/tool-keys.d.ts +5 -101
  361. package/dist/tool-keys.js +8 -267
  362. package/dist/tool-plane.d.ts +23 -52
  363. package/dist/tool-plane.js +23 -81
  364. package/dist/tool-settings-store.d.ts +1 -2
  365. package/dist/tool-settings-store.js +5 -8
  366. package/dist/tools.d.ts +67 -25
  367. package/dist/tools.js +170 -119
  368. package/dist/trigger-adapter.d.ts +2 -2
  369. package/dist/trigger-targets.d.ts +13 -1
  370. package/dist/trigger-targets.js +31 -1
  371. package/dist/triggers.d.ts +2 -2
  372. package/dist/triggers.js +3 -3
  373. package/dist/turn-end.d.ts +1 -1
  374. package/dist/turn-end.js +1 -1
  375. package/dist/turns.d.ts +0 -6
  376. package/dist/turns.js +0 -19
  377. package/dist/uploads.d.ts +28 -5
  378. package/dist/uploads.js +83 -10
  379. package/dist/usage.d.ts +1 -49
  380. package/dist/usage.js +3 -84
  381. package/dist/validate.d.ts +4 -0
  382. package/dist/validate.js +33 -14
  383. package/dist/webhooks.d.ts +102 -76
  384. package/dist/webhooks.js +266 -233
  385. package/dist/workflow-run.d.ts +114 -0
  386. package/dist/workflow-run.js +144 -0
  387. package/dist/workspace/archil-claim.d.ts +2 -2
  388. package/dist/workspace/archil-claim.js +4 -3
  389. package/dist/workspace/archil-disk.d.ts +10 -1
  390. package/dist/workspace/archil-disk.js +4 -0
  391. package/dist/workspace/archil-exec.d.ts +12 -2
  392. package/dist/workspace/archil-exec.js +16 -0
  393. package/dist/workspace/archil.d.ts +2 -2
  394. package/dist/workspace/archil.js +25 -5
  395. package/dist/workspace/attach.js +2 -0
  396. package/dist/workspace/beneath.d.ts +19 -0
  397. package/dist/workspace/beneath.js +106 -0
  398. package/dist/workspace/computer-deps.d.ts +26 -9
  399. package/dist/workspace/computer-deps.js +144 -43
  400. package/dist/workspace/computer-for-claim.d.ts +17 -14
  401. package/dist/workspace/computer-for-claim.js +99 -26
  402. package/dist/workspace/computer-hold.d.ts +6 -1
  403. package/dist/workspace/computer-hold.js +6 -1
  404. package/dist/workspace/computer-janitor.d.ts +47 -0
  405. package/dist/workspace/computer-janitor.js +182 -0
  406. package/dist/workspace/computer-ledger.d.ts +1 -8
  407. package/dist/workspace/computer-ledger.js +0 -3
  408. package/dist/workspace/computer-providers.d.ts +5 -3
  409. package/dist/workspace/computer-providers.js +11 -9
  410. package/dist/workspace/grep-worker.d.ts +5 -0
  411. package/dist/workspace/grep-worker.js +9 -6
  412. package/dist/workspace/hands.d.ts +5 -2
  413. package/dist/workspace/hands.js +4 -3
  414. package/dist/workspace/index.d.ts +6 -5
  415. package/dist/workspace/index.js +4 -4
  416. package/dist/workspace/local.d.ts +14 -2
  417. package/dist/workspace/local.js +170 -43
  418. package/dist/workspace/paths.js +3 -2
  419. package/dist/workspace/pi-env.d.ts +4 -0
  420. package/dist/workspace/pi-env.js +3 -2
  421. package/dist/workspace/resolve-computer.d.ts +55 -10
  422. package/dist/workspace/resolve-computer.js +66 -14
  423. package/dist/workspace/run-tools.d.ts +15 -31
  424. package/dist/workspace/run-tools.js +19 -30
  425. package/dist/workspace/workspace.d.ts +5 -0
  426. package/dist/workspace-paths.d.ts +0 -17
  427. package/dist/workspace-paths.js +1 -41
  428. package/dist/workspace.d.ts +0 -17
  429. package/dist/workspace.js +4 -110
  430. package/package.json +14 -14
  431. package/skills/agentrun-serve/SKILL.md +1 -1
  432. package/templates/README.md +11 -5
  433. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  434. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  435. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  436. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  437. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  438. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  439. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  440. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  441. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  442. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  443. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  444. package/templates/market-monitor/agent.md +2 -2
  445. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  446. package/templates/release-notes/agent.md +11 -0
  447. package/dist/bound-files.d.ts +0 -4
  448. package/dist/bound-files.js +0 -164
  449. package/dist/coding-tools.d.ts +0 -47
  450. package/dist/coding-tools.js +0 -189
  451. package/dist/computer-adb.d.ts +0 -12
  452. package/dist/computer-adb.js +0 -14
  453. package/dist/console/assets/index-Dn0ngwG9.js +0 -535
  454. package/dist/console/assets/index-DvW6Aled.css +0 -1
  455. package/dist/grade.d.ts +0 -63
  456. package/dist/grade.js +0 -150
  457. package/dist/mcp-servers.d.ts +0 -269
  458. package/dist/mcp-servers.js +0 -456
  459. package/dist/packs.d.ts +0 -71
  460. package/dist/packs.js +0 -180
  461. package/dist/sealed-settings.d.ts +0 -60
  462. package/dist/sealed-settings.js +0 -171
  463. package/dist/sessions.d.ts +0 -6
  464. package/dist/sessions.js +0 -109
  465. package/dist/workspace/computer-serves.d.ts +0 -12
  466. package/dist/workspace/computer-serves.js +0 -15
@@ -19,8 +19,8 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
19
19
  import { dropPostgresSchema, openPostgresStore, openStore, RunFinal, StoreConstraint, storeTarget } from "../../store/index.js";
20
20
  import { sendCommand } from "../commands.js";
21
21
  import { callsOf, journalRecords, messagesOf } from "../journal-reader.js";
22
- import { KINDS } from "../journal-kinds.js";
23
- import { timelineReducer } from "@parcha/pi-durable-agent/timeline";
22
+ import { KINDS, MESSAGE_SENT_AGAIN } from "../journal-kinds.js";
23
+ import { timelineReducer } from "../../timeline/index.js";
24
24
  import { emptyState, translate } from "../../live/translate.js";
25
25
  /** The one row a person's stop gives on the live timeline (live/translate.ts STOPPED_BY_YOU), the same on every harness. */
26
26
  const STOPPED_BY_YOU = "Stopped by you";
@@ -119,19 +119,16 @@ function crashAt(point, holder) {
119
119
  return {
120
120
  beforeIntent: async () => (point === "beforeIntent" ? crash() : undefined),
121
121
  beforeResult: async () => (point === "beforeResult" ? crash() : undefined),
122
+ afterMessageSent: async () => (point === "afterMessageSent" ? crash() : undefined),
122
123
  };
123
124
  }
124
125
  /** The Postgres store each registered subject's worlds open (registerHarnessConformance's `storeUrl`), by the subject
125
126
  * object the suite's cases are handed: none for the data directory's SQLite store. */
126
127
  const STORE_URLS = new WeakMap();
127
- /** Cases a Postgres store can't pass yet, each with what it waits on: they run on SQLite and are skipped on Postgres. */
128
- const POSTGRES_PENDING = {
129
- "approval-double-click": "waits on the Postgres commands_one_answer migration (pgstore-1): the one-answer index is SQLite's today",
130
- };
128
+ /** Cases a Postgres store can't pass yet, each with what it waits on: they run on SQLite and are skipped on Postgres. None
129
+ * today. */
130
+ const POSTGRES_PENDING = {};
131
131
  /** A store in a data directory of its own, one queued run, and runners started on it (each its own connection). */
132
- /** The suite's short lease, for the crash cases: a crashed runner's claim must run out for the second runner to take
133
- * the run over. */
134
- const TAKEOVER = {};
135
132
  /** The stores' clock skew a runner process reads (child.ts): the file holds the milliseconds the clock moved, so the
136
133
  * process's store moves with the case's (runOut). */
137
134
  export const storeClockOf = (file) => {
@@ -630,6 +627,88 @@ const CASES = [
630
627
  assert.ok((await w.commandRow(steer.id)).takenAt !== null, "the steer row is taken");
631
628
  },
632
629
  },
630
+ {
631
+ id: "message-mid-turn-kept",
632
+ title: "messages sent mid-turn are never dropped: each is taken, in order, and the model answers each",
633
+ async body(subject, t) {
634
+ const w = await world(subject, t);
635
+ const { tools, letSlowGo, slowStarted } = suiteTools();
636
+ // A harness that steers places a message in the turn in flight (steer-mid-turn); one that does not (a CLI's: its
637
+ // adapter's facts say steer false) sends each as a turn of its own once the turn ends, in the order they came. Either
638
+ // way the model reads it, and its row is taken, never refused after the API accepted it (#2174).
639
+ const steers = subject.facts?.steer !== false;
640
+ const texts = steers ? ["check the totals"] : ["check the totals", "and the dates"];
641
+ // The model's steps: the call, then what it says after it (the steer it read, when it steers), then, for each message
642
+ // sent as a turn of its own, that message (the last the person sent).
643
+ const script = [{ call: "slow" }, { sayLastSteer: true }, ...(steers ? [] : texts.map(() => ({ sayLastSteer: true })))];
644
+ await w.start("runner-a", { script, tools, hooks: quiet });
645
+ await slowStarted;
646
+ const rows = [];
647
+ for (const text of texts)
648
+ rows.push(await sendCommand(w.server, RUN, { kind: "steer", body: { text } }));
649
+ // The tool goes on once every message is with the loop: the turn in flight has them, never a timer.
650
+ await until(() => rows.every((row) => w.handedOver(row.id)), "the messages handed to the loop mid-turn");
651
+ letSlowGo();
652
+ await w.ended("ended");
653
+ const { calls, messages } = await w.read();
654
+ const slow = calls.find((call) => call.tool === "slow");
655
+ assert.ok(slow?.endEntry !== undefined && slow.status === "done", `slow ran to its end: ${JSON.stringify(calls)}`);
656
+ const sent = texts.map((text) => messages.find((message) => message.role !== "model" && message.text === text));
657
+ assert.ok(sent.every((message) => message !== undefined), `each message is in the journal: ${JSON.stringify(messages)}`);
658
+ for (const [i, message] of sent.entries()) {
659
+ assert.ok(message.entry > slow.endEntry, `"${texts[i]}" comes after the call it was sent during: ${JSON.stringify(messages)}`);
660
+ if (i > 0)
661
+ assert.ok(message.entry > sent[i - 1].entry, `in the order they came: ${JSON.stringify(messages)}`);
662
+ const answered = messages.find((one) => one.role === "model" && one.entry > message.entry && one.text.includes(texts[i]));
663
+ assert.ok(answered, `the model answered "${texts[i]}": ${JSON.stringify(messages)}`);
664
+ }
665
+ for (const row of rows) {
666
+ const taken = await w.commandRow(row.id);
667
+ assert.ok(taken.takenAt !== null && taken.refused === null, `its row is taken, not refused: ${JSON.stringify(taken)}`);
668
+ }
669
+ },
670
+ },
671
+ {
672
+ id: "message-resent-after-crash",
673
+ title: "a message sent as its own turn by a runner lost before its row was taken is sent again by the next, and the timeline says so",
674
+ async body(subject, t) {
675
+ const w = await world(subject, t);
676
+ const { tools, letSlowGo, slowStarted } = suiteTools();
677
+ const text = "check the totals";
678
+ // The call, then the turn's words, then the message's turn (sent once by runner-a, again by runner-b), each saying
679
+ // the message it was given.
680
+ const script = [{ call: "slow" }, { sayLastSteer: true }, { sayLastSteer: true }, { sayLastSteer: true }];
681
+ const holder = {};
682
+ await w.start("runner-a", { script, tools, hooks: crashAt("afterMessageSent", holder) }, holder);
683
+ await slowStarted;
684
+ const row = await sendCommand(w.server, RUN, { kind: "steer", body: { text } });
685
+ await until(() => w.handedOver(row.id), "the message handed to the loop mid-turn");
686
+ letSlowGo();
687
+ // runner-a dies once the session holds the message, before the commit that records it and takes its row.
688
+ await until(() => holder.crashed, "the crash after the message was sent", EVENT_WAIT_MS);
689
+ assert.equal((await w.commandRow(row.id)).takenAt, null, "the row is untaken when runner-a is lost");
690
+ await w.claimsSettled("runner-a");
691
+ w.runOut();
692
+ await w.start("runner-b", { script, tools, hooks: quiet });
693
+ await w.ended("ended", EVENT_WAIT_MS);
694
+ const { messages } = await w.read();
695
+ const sent = messages.filter((message) => message.role !== "model" && message.text === text);
696
+ assert.ok(sent.length >= 1, `the message is on the record: ${JSON.stringify(messages)}`);
697
+ assert.ok(messages.some((message) => message.role === "model" && message.text.includes(text) && message.entry > sent[0].entry), `the model answered it: ${JSON.stringify(messages)}`);
698
+ const taken = await w.commandRow(row.id);
699
+ assert.ok(taken.takenAt !== null && taken.refused === null, `its row is taken once runner-b sent it: ${JSON.stringify(taken)}`);
700
+ // Never silent: the timeline says the message went again, once, before it.
701
+ const rows = await w.liveRows();
702
+ const again = rows.filter((one) => one.summary === MESSAGE_SENT_AGAIN);
703
+ const shown = JSON.stringify(rows.map((one) => [one.kind, one.summary]));
704
+ assert.deepEqual(again.map((one) => one.kind), ["phase"], `one row says it was sent again: ${shown}`);
705
+ // Just before the message it was said of: the person's row of it is the next message row.
706
+ const at = rows.indexOf(again[0]);
707
+ const message = rows.findIndex((one, i) => i > at && one.kind === "user_message");
708
+ assert.ok(message > at && rows[message].text === text, `the notice comes right before the message it was sent again: ${shown}`);
709
+ assert.ok(!rows.slice(0, at).some((one) => one.kind === "user_message" && one.text === text), `no row of the message before the notice: ${shown}`);
710
+ },
711
+ },
633
712
  {
634
713
  id: "stop-ends-turn",
635
714
  title: "stop ends the turn; the run says why",
@@ -705,10 +784,13 @@ const CASES = [
705
784
  await sendCommand(w.server, RUN, { kind: "deny", body: { approval: callId, note: "not on a Friday" } });
706
785
  await w.ended("ended");
707
786
  assert.equal(ran.asked, 0, "denied, it never ran");
708
- const { answers, messages } = await w.read();
787
+ const { answers, messages, calls } = await w.read();
709
788
  // The fields this case is about; its time is the loop's clock's (adapter-pi-approval-entries pins it).
710
789
  assert.deepEqual(answers.map(({ callId: id, approved, decision, note }) => ({ callId: id, approved, decision, note })), [{ callId, approved: false, decision: "deny", note: "not on a Friday" }], "the answer is a deny that keeps the note");
711
- const said = messages.filter((message) => message.role === "model").map((message) => message.text);
790
+ // What the model said after the asked call: its answer to the refusal. What it said with the call, before the gate
791
+ // asked (a CLI's "Calling asked."), is on the record before the call's row, as pi keeps a call's text in its message.
792
+ const asked = calls.find((call) => call.callId === callId);
793
+ const said = messages.filter((message) => message.role === "model" && message.entry > (asked?.startEntry ?? -1)).map((message) => message.text);
712
794
  assert.equal(said.length, 1, `the model answered once: ${JSON.stringify(messages)}`);
713
795
  // Main's words for a call a person denied (tool-gate.ts refusedText), the note with them. The harness may frame a
714
796
  // refusal its own way (pi: a blocked call's error) around them.
@@ -798,6 +880,31 @@ const CASES = [
798
880
  assert.deepEqual(calls.map((call) => [call.tool, call.status]), [["asked", "done"]]);
799
881
  },
800
882
  },
883
+ {
884
+ id: "approval-race",
885
+ title: "an approve and a deny sent at once write one answer: the store refuses the other (one answer per approval), and the run acts on the one written",
886
+ async body(subject, t) {
887
+ const w = await world(subject, t);
888
+ const { tools, ran } = suiteTools();
889
+ await w.start("runner-a", { script: [{ call: "asked" }, { say: "done" }], tools, hooks: quiet });
890
+ await w.ended("parked");
891
+ const callId = await w.askedCall();
892
+ // Both sent before either is awaited (on Postgres, each on its own pooled connection). Whichever is written first, the
893
+ // store's one-answer index refuses the other: no order is imposed, so the case holds for either winner.
894
+ const settled = await Promise.allSettled([
895
+ sendCommand(w.server, RUN, { kind: "approve", body: { approval: callId } }),
896
+ sendCommand(w.server, RUN, { kind: "deny", body: { approval: callId } }),
897
+ ]);
898
+ const won = settled.filter((r) => r.status === "fulfilled");
899
+ const lost = settled.filter((r) => r.status === "rejected");
900
+ assert.equal(won.length, 1, `one answer is written, not both: ${JSON.stringify(settled.map((r) => r.status))}`);
901
+ assert.ok(lost[0]?.reason instanceof StoreConstraint, `the other is refused by the store: ${String(lost[0]?.reason)}`);
902
+ await w.ended("ended");
903
+ const winner = won[0].value;
904
+ assert.equal(ran.asked, winner.kind === "approve" ? 1 : 0, "the run acted on the answer written, never the other");
905
+ assert.equal((await w.commandRow(winner.id)).refused, null, "the answer written stands");
906
+ },
907
+ },
801
908
  {
802
909
  id: "message-never-answers",
803
910
  title: "a message that answers nothing (a trigger's, answers: false) never answers a waiting call, whatever its words",
@@ -879,12 +986,13 @@ const CASES = [
879
986
  },
880
987
  },
881
988
  ];
989
+ const STEERS_IN_TURN = "it places a message sent mid-turn in the turn in flight, its row taken in its submission's commit, so it never sends one as a turn of its own (message-resent-after-crash)";
882
990
  const CLI_NEVER_RERUNS = "a CLI never reruns a call that started; only the model calls again (its adapter's facts: rerunsStarted false)";
883
991
  /** The cases a harness's declared facts rule out, each with why: what it does by design, not what it cannot model yet. */
884
992
  export function factsRuleOut(facts) {
885
993
  if (!facts)
886
994
  return {};
887
- const noSteer = `${facts.id} takes no message mid-turn (its adapter's facts: steer false), so the loop refuses a steer for it in words`;
995
+ const noSteer = `${facts.id} takes no message mid-turn (its adapter's facts: steer false), so a message sent while it works is never placed in the turn in flight: it is the run's next turn (message-mid-turn-kept)`;
888
996
  return {
889
997
  // steer-origin steers the turn in flight too: its message is taken mid-turn, or never.
890
998
  ...(facts.steer ? {} : { "steer-mid-turn": noSteer, "steer-origin": noSteer }),
@@ -918,7 +1026,9 @@ export function registerHarnessConformance(given, { test, storeUrl }) {
918
1026
  const ruledOut = factsRuleOut(subject.facts);
919
1027
  for (const entry of CASES) {
920
1028
  const processCase = entry.id.endsWith("-process");
921
- const byFacts = ruledOut[entry.id];
1029
+ // A harness that steers (any whose facts do not say steer false, as message-mid-turn-kept reads them) places a message
1030
+ // in the turn in flight, its row taken in the commit of its submission: it never sends one as a turn of its own.
1031
+ const byFacts = ruledOut[entry.id] ?? (entry.id === "message-resent-after-crash" && subject.facts?.steer !== false ? STEERS_IN_TURN : undefined);
922
1032
  const notYet = subject.unsupported?.[entry.id] ?? (processCase && !subject.process ? "it names no module a runner process can load (subject.process)" : undefined);
923
1033
  const onPostgres = storeUrl ? POSTGRES_PENDING[entry.id] : undefined;
924
1034
  const skip = byFacts ? `${subject.name} does not do this by design: ${byFacts}` : notYet ? `${subject.name} cannot model this yet: ${notYet}` : onPostgres ? `on Postgres, ${onPostgres}` : undefined;
@@ -46,6 +46,9 @@ export interface KernelHooks {
46
46
  beforeBooking?(): Promise<void>;
47
47
  /** The adapter loop waits for its session's paid requests to be booked (bookingsSettled, with one still unbooked). */
48
48
  awaitingBookings?(): void;
49
+ /** A message taken mid-turn was sent as a turn of its own (the adapter loop's sendAfterTurn): the session holds it, and
50
+ * the commit that records it and takes its row has not run yet. */
51
+ afterMessageSent?(): Promise<void>;
49
52
  }
50
53
  export interface ConformanceSetup {
51
54
  readonly script: readonly ScriptStep[];
@@ -54,7 +57,7 @@ export interface ConformanceSetup {
54
57
  /** The run's agent, for the subject's spec to name (AdapterRunSpec.agentId): the end-of-run step is asked with it. */
55
58
  readonly agentId?: string;
56
59
  }
57
- export type ConformanceCase = "crash-before-intent" | "crash-after-intent" | "crash-before-intent-process" | "crash-after-intent-process" | "stalled-past-lease-process" | "replay-safe-rerun" | "steer-mid-turn" | "cancel-ends-for-good" | "cancel-parked" | "deny-note" | "steer-origin" | "stop-ends-turn" | "park-on-ask" | "approval-names-its-call" | "approval-double-click" | "message-never-answers" | "end-of-run-answer" | "fault-effects-once" | "fault-restarts-bounded" | "length-ends-failed" | "length-mid-run";
60
+ export type ConformanceCase = "crash-before-intent" | "crash-after-intent" | "crash-before-intent-process" | "crash-after-intent-process" | "stalled-past-lease-process" | "replay-safe-rerun" | "steer-mid-turn" | "message-mid-turn-kept" | "message-resent-after-crash" | "cancel-ends-for-good" | "cancel-parked" | "deny-note" | "steer-origin" | "stop-ends-turn" | "park-on-ask" | "approval-names-its-call" | "approval-double-click" | "approval-race" | "message-never-answers" | "end-of-run-answer" | "fault-effects-once" | "fault-restarts-bounded" | "length-ends-failed" | "length-mid-run";
58
61
  export interface ConformanceSubject {
59
62
  /** The harness's name, as the suite's tests are titled. */
60
63
  readonly name: string;
@@ -7,7 +7,7 @@ export interface DispatchDeps {
7
7
  launchOf(runId: string): Promise<{
8
8
  readonly body: unknown;
9
9
  }>;
10
- /** The loop factory for a run launched with `harness`, built from its `launch` record and its run id (so the switch may
10
+ /** The loop factory for a run launched with `harness`, built from its `launch` record and its run id (so the resolver may
11
11
  * read the run's revision — a workflow revision runs on the workflow loop whatever its harness name), or undefined when
12
12
  * this runner does not run it (the run fails in words). pi is the adapter loop with adapterRunSpecFromLaunch; a built-in
13
13
  * learning run names "learning"; the CLI harnesses name their own. May be async (the revision read). */
@@ -24,6 +24,13 @@ export declare class LaunchUnreadable extends Error {
24
24
  name: string;
25
25
  constructor(runId: string);
26
26
  }
27
+ /** The first wait before a buffered row whose delivery threw is tried again, and the most any later wait (doubling)
28
+ * grows to. */
29
+ export declare const REPLAY_RETRY_FIRST_MS = 250;
30
+ export declare const REPLAY_RETRY_MAX_MS = 5000;
31
+ /** How many times in all a buffered row's delivery is tried before the dispatch stops trying it on this claim: a row that
32
+ * fails for a lasting reason is said once and left untaken for the run's next claim, never tried for the whole run. */
33
+ export declare const REPLAY_TRIES = 5;
27
34
  /** The loop factory the runner holds for every run: `createDispatchLoop(deps)` picks each run's harness loop at its
28
35
  * claim. The inner loop gets the same LoopDeps the dispatch does, so the runner's fence, flush, live and end-of-run
29
36
  * channels reach it unchanged. */
@@ -25,6 +25,13 @@ export class LaunchUnreadable extends Error {
25
25
  super(`run ${runId}: its launch record could not be read as a launch (it names no place, or is not an object).`);
26
26
  }
27
27
  }
28
+ /** The first wait before a buffered row whose delivery threw is tried again, and the most any later wait (doubling)
29
+ * grows to. */
30
+ export const REPLAY_RETRY_FIRST_MS = 250;
31
+ export const REPLAY_RETRY_MAX_MS = 5_000;
32
+ /** How many times in all a buffered row's delivery is tried before the dispatch stops trying it on this claim: a row that
33
+ * fails for a lasting reason is said once and left untaken for the run's next claim, never tried for the whole run. */
34
+ export const REPLAY_TRIES = 5;
28
35
  /** The loop factory the runner holds for every run: `createDispatchLoop(deps)` picks each run's harness loop at its
29
36
  * claim. The inner loop gets the same LoopDeps the dispatch does, so the runner's fence, flush, live and end-of-run
30
37
  * channels reach it unchanged. */
@@ -62,16 +69,83 @@ function dispatchLoop(deps, loopDeps) {
62
69
  // buffered row and no buffered stop is lost between choosing the loop and replaying what was buffered.
63
70
  inner = factory(innerDeps);
64
71
  const end = inner.start(claim);
65
- // Replay the buffered commands through the inner loop in order, each awaited, then let its `delivered` resolve.
72
+ // Replay the buffered commands through the inner loop in order, each awaited, then let its `delivered` resolve. A
73
+ // command whose delivery throws is never thrown out of here, where nothing would catch it and the runner's process
74
+ // would go down. The runner already moved past its row (the dispatch said it holds it), so the dispatch tries it again
75
+ // itself while the inner loop runs, as the runner tries again a row whose delivery threw (a store that failed for a
76
+ // moment), up to REPLAY_TRIES times. Once the inner loop has ended, or the tries are spent, a row still not delivered
77
+ // stays untaken (the store's take is the inner loop's own commit), so the run's next claim delivers it again and
78
+ // nobody's words are lost.
66
79
  const buffered = early.splice(0);
67
- void (async () => {
80
+ void replay(claim.runId, inner, buffered, end);
81
+ // The buffered stop, not awaited here (start() returns the inner loop's end): an inner stop that throws is said in
82
+ // the log, never an unhandled rejection, which would end the runner process and every run it holds.
83
+ if (earlyStop) {
84
+ inner.stop(earlyStop).catch((error) => {
85
+ const text = error?.message ?? String(error);
86
+ console.warn(`[runner] run ${claim.runId}: its stop failed: ${loopDeps.redact ? loopDeps.redact(text) : text}`);
87
+ });
88
+ }
89
+ return end;
90
+ }
91
+ /** Hands each of `buffered` to `loop` once, in order, then lets the loop's `delivered` resolve; the ones whose delivery
92
+ * threw are tried again, in order, until each goes through, the loop has ended, or a row has been tried REPLAY_TRIES
93
+ * times (said once; it and the failed rows after it are left untaken for the run's next claim). Never rejects. */
94
+ async function replay(runId, loop, buffered, end, tries = REPLAY_TRIES) {
95
+ let ended = false;
96
+ const loopEnded = end.then(() => undefined, () => undefined).then(() => void (ended = true));
97
+ let lastError;
98
+ const delivers = async (command) => {
99
+ try {
100
+ await loop.command(command);
101
+ return true;
102
+ }
103
+ catch (error) {
104
+ lastError = error;
105
+ return false;
106
+ }
107
+ };
108
+ // What went wrong, cut of the values the run holds (LoopDeps.redact), as the log may not show them.
109
+ const why = () => {
110
+ const text = lastError?.message ?? String(lastError);
111
+ return loopDeps.redact ? loopDeps.redact(text) : text;
112
+ };
113
+ const failed = [];
114
+ try {
115
+ // Every row is tried once before the inner loop's `delivered` resolves, a later one even when an earlier one threw:
116
+ // a loop that waits on `delivered` (a run reopened by a follow-up) never goes on with a row still held here.
68
117
  for (const command of buffered)
69
- await inner.command(command);
118
+ if (!(await delivers(command)))
119
+ failed.push(command);
120
+ }
121
+ finally {
70
122
  replayed();
71
- })();
72
- if (earlyStop)
73
- void inner.stop(earlyStop);
74
- return end;
123
+ }
124
+ if (failed.length === 0)
125
+ return;
126
+ console.warn(`[runner] ${runId}: a ${failed[0].kind} row held before its loop was chosen was not delivered (${why()}); it is tried again while the loop runs, up to ${tries} times in all`);
127
+ // How many times the first row still to deliver has been tried: once, in the pass above.
128
+ let tried = 1;
129
+ for (let wait = REPLAY_RETRY_FIRST_MS; failed.length > 0 && !ended; wait = Math.min(wait * 2, REPLAY_RETRY_MAX_MS)) {
130
+ if (tried >= tries) {
131
+ console.warn(`[runner] ${runId}: a ${failed[0].kind} row held before its loop was chosen was tried ${tried} times and not delivered (${why()}); it and the ${failed.length - 1} after it are left untaken, for the run's next claim`);
132
+ return;
133
+ }
134
+ let timer;
135
+ await Promise.race([loopEnded, new Promise((resolve) => (timer = setTimeout(resolve, wait)))]);
136
+ clearTimeout(timer);
137
+ if (ended)
138
+ break;
139
+ // The first row again; once it goes through, the rows after it at once, in order, until one throws.
140
+ while (failed.length > 0 && !ended) {
141
+ tried += 1;
142
+ if (!(await delivers(failed[0])))
143
+ break;
144
+ failed.shift();
145
+ // Every row left was tried once in the first pass.
146
+ tried = 1;
147
+ }
148
+ }
75
149
  }
76
150
  return {
77
151
  start(claim) {
@@ -10,12 +10,18 @@ export declare const reflectRequestId: (runId: string, again?: boolean) => strin
10
10
  * is answered from its submission, never asked of the model twice. */
11
11
  export declare const REFLECT_AGAIN = ":again";
12
12
  /** Where the end-of-run turn began in a run's journal: the entry its input placed, from the input submission under the
13
- * turn's request id; undefined before it is placed, or for a run that asked none. Every entry from it on, until the
14
- * run's end, is the turn's (the server's labelled: after the entry before it). */
13
+ * turn's request id; else, on a CLI harness, the turn's prompt the CLI record wrote as it asked the turn (`entries`:
14
+ * adapter-loop.ts asking, an end-of-run-turn entry of the person's, written before the turn's submission, which only
15
+ * its answer writes). Undefined before either, or for a run that asked none. Every entry from it on, until the run's
16
+ * end, is the turn's (the server's labelled: after the entry before it). */
15
17
  export declare function reflectFrom(submissions: readonly {
16
18
  readonly type?: string;
17
19
  readonly requestId?: string;
18
20
  readonly entry?: unknown;
21
+ }[], entries?: readonly {
22
+ readonly kind?: string;
23
+ readonly id?: unknown;
24
+ readonly data?: unknown;
19
25
  }[]): number | undefined;
20
26
  /** The refusal of the end-of-run turn's write or edit under work/.learning/: the tool gate's one text (NOTE_ONLY_TEXT), so
21
27
  * the adapter loop's refusal and the gate's are the same words. */
@@ -3,6 +3,7 @@
3
3
  // answer's note blocks, never from a file it writes there. The words and the rule are the tool gate's own
4
4
  // (tool-gate.ts NOTE_ONLY_TEXT, underLearning), kept equal by a test.
5
5
  import { posix, resolve, sep, join } from "node:path";
6
+ import { KINDS } from "./journal-kinds.js";
6
7
  /** The prefix of the end-of-run turn's request id: the server's own (turns.ts REFLECT_REQUEST). */
7
8
  export const REFLECT_PREFIX = "learn-reflect-";
8
9
  /** The label a reader puts on the end-of-run turn's rows and messages: the server's (learning.ts LEARNING_LABEL). */
@@ -15,11 +16,16 @@ export const reflectRequestId = (runId, again = false) => `${REFLECT_PREFIX}${ru
15
16
  * is answered from its submission, never asked of the model twice. */
16
17
  export const REFLECT_AGAIN = ":again";
17
18
  /** Where the end-of-run turn began in a run's journal: the entry its input placed, from the input submission under the
18
- * turn's request id; undefined before it is placed, or for a run that asked none. Every entry from it on, until the
19
- * run's end, is the turn's (the server's labelled: after the entry before it). */
20
- export function reflectFrom(submissions) {
19
+ * turn's request id; else, on a CLI harness, the turn's prompt the CLI record wrote as it asked the turn (`entries`:
20
+ * adapter-loop.ts asking, an end-of-run-turn entry of the person's, written before the turn's submission, which only
21
+ * its answer writes). Undefined before either, or for a run that asked none. Every entry from it on, until the run's
22
+ * end, is the turn's (the server's labelled: after the entry before it). */
23
+ export function reflectFrom(submissions, entries = []) {
21
24
  const placed = submissions.filter((record) => record.type === "input" && typeof record.requestId === "string" && record.requestId.startsWith(REFLECT_PREFIX) && record.entry !== undefined);
22
- return placed.length ? Math.min(...placed.map((record) => Number(record.entry))) : undefined;
25
+ if (placed.length)
26
+ return Math.min(...placed.map((record) => Number(record.entry)));
27
+ const asked = entries.find((entry) => entry.kind === KINDS.endOfRunTurn && entry.data?.role === "person");
28
+ return asked === undefined ? undefined : Number(asked.id);
23
29
  }
24
30
  /** The refusal of the end-of-run turn's write or edit under work/.learning/: the tool gate's one text (NOTE_ONLY_TEXT), so
25
31
  * the adapter loop's refusal and the gate's are the same words. */
@@ -7,10 +7,15 @@ export type GithubAppAccessAt = GithubAppAccess & {
7
7
  /** The GitHub App access for one claim of a run whose first input is `firstInput` (run_launch's), or undefined when this
8
8
  * server has no App the runner can open. Its mint goes to https://api.github.com (GITHUB_API): the App's JWT, signed
9
9
  * with its key and good for every installation, goes nowhere else. `api` is a test runner's fake GitHub, given in the
10
- * runner's own options (AdapterSpecDeps.githubApi); nothing kept, no environment variable and no flag reaches it. */
10
+ * runner's own options (AdapterSpecDeps.githubApi); nothing kept, no environment variable and no flag reaches it.
11
+ * `fromGitHub`: the run's first input is a github trigger's firing (its launch's inputOrigin), whose payload tag names
12
+ * the repository and installation; any other run's tag is never read, only its owner's words. `hold`: each token minted
13
+ * joins the run's redactor (its `cut`), the first and every one after. */
11
14
  export declare function githubAppAccess(store: {
12
15
  readonly triggerSettings: Pick<TriggerSettings, "get">;
13
- }, sealKey: Buffer | undefined, firstInput: unknown, { api, now }?: {
16
+ }, sealKey: Buffer | undefined, firstInput: unknown, { api, now, fromGitHub, hold }?: {
14
17
  api?: string;
15
18
  now?: () => number;
19
+ fromGitHub?: boolean;
20
+ hold?: (values: string[]) => void;
16
21
  }): Promise<GithubAppAccessAt | undefined>;
@@ -1,21 +1,18 @@
1
1
  // The runner's side of a github_app MCP server (runner/mcp-github.ts): the server's GitHub App, read from the store at each
2
- // claim, bound into the mint the claim step calls, with the run's repository. The App's id and private key are the rows the
3
- // server sealed in trigger_settings (adapter "github", scope "server", AAD trigger_settings|github|server|<field>, as
4
- // sealed-settings-store.ts writes them), opened here with the runner's seal key and held only in the bound mint's closure.
2
+ // claim and again before each mint, bound into the mint the claim step calls, with the run's repository. The App's id and
3
+ // private key are the rows the server sealed in trigger_settings (adapter "github", scope "server", AAD
4
+ // trigger_settings|github|server|<field>, as sealed-settings-store.ts writes them), opened here with the runner's seal key.
5
5
  // No App (never connected, disconnected, or rows that do not open under this key): no access, and such a server's calls
6
- // are refused in words (GITHUB_UNUSABLE.noAccess).
7
- import { unseal } from "@parcha/pi-durable-agent";
8
- import { GITHUB_API, GITHUB_FIELDS, GITHUB_SCOPE, githubTargetOf, mintInstallationToken } from "../github.js";
6
+ // are refused in words (GITHUB_UNUSABLE.noAccess). An App disconnected or replaced while a run holds a token: its next
7
+ // mint is refused as disconnected, and the claim step drops and revokes the token it holds.
8
+ import { unseal } from "../sealing.js";
9
+ import { GITHUB_API, GITHUB_FIELDS, GITHUB_SCOPE, githubCall, githubTargetOf, mintInstallationToken } from "../github.js";
9
10
  import { isObject } from "../validate.js";
10
11
  const ADAPTER = "github";
11
12
  const aad = (field) => `trigger_settings|${ADAPTER}|${GITHUB_SCOPE}|${field}`;
12
- /** The GitHub App access for one claim of a run whose first input is `firstInput` (run_launch's), or undefined when this
13
- * server has no App the runner can open. Its mint goes to https://api.github.com (GITHUB_API): the App's JWT, signed
14
- * with its key and good for every installation, goes nowhere else. `api` is a test runner's fake GitHub, given in the
15
- * runner's own options (AdapterSpecDeps.githubApi); nothing kept, no environment variable and no flag reaches it. */
16
- export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB_API, now = Date.now } = {}) {
17
- if (!sealKey)
18
- return undefined;
13
+ /** The server's App as the store holds it now, opened with `sealKey`: its id and private key, or undefined when there is none
14
+ * this key opens. */
15
+ async function appOf(store, sealKey) {
19
16
  const rows = (await store.triggerSettings.get(ADAPTER)).filter((row) => row.scope === GITHUB_SCOPE);
20
17
  const open = (field) => {
21
18
  const row = rows.find((r) => r.field === field);
@@ -30,8 +27,42 @@ export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB
30
27
  };
31
28
  const appId = open(GITHUB_FIELDS.appId);
32
29
  const pem = open(GITHUB_FIELDS.privateKey);
33
- if (!appId || !pem)
30
+ return appId && pem ? { appId, pem } : undefined;
31
+ }
32
+ /** The GitHub App access for one claim of a run whose first input is `firstInput` (run_launch's), or undefined when this
33
+ * server has no App the runner can open. Its mint goes to https://api.github.com (GITHUB_API): the App's JWT, signed
34
+ * with its key and good for every installation, goes nowhere else. `api` is a test runner's fake GitHub, given in the
35
+ * runner's own options (AdapterSpecDeps.githubApi); nothing kept, no environment variable and no flag reaches it.
36
+ * `fromGitHub`: the run's first input is a github trigger's firing (its launch's inputOrigin), whose payload tag names
37
+ * the repository and installation; any other run's tag is never read, only its owner's words. `hold`: each token minted
38
+ * joins the run's redactor (its `cut`), the first and every one after. */
39
+ export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB_API, now = Date.now, fromGitHub = false, hold } = {}) {
40
+ if (!sealKey)
41
+ return undefined;
42
+ const app = await appOf(store, sealKey);
43
+ if (!app)
34
44
  return undefined;
35
- const target = githubTargetOf(isObject(firstInput) ? firstInput.content : firstInput);
36
- return { api, mint: (to) => mintInstallationToken(api, appId, pem, to, now()), target };
45
+ const target = githubTargetOf(isObject(firstInput) ? firstInput.content : firstInput, { payload: fromGitHub });
46
+ return {
47
+ api,
48
+ target,
49
+ // The App read again before each mint: one disconnected or replaced since the claim makes no token for this run.
50
+ mint: async (to) => {
51
+ // A read that fails throws on: the step's github_failed path keeps the token held until it expires, never a disconnect.
52
+ const still = await appOf(store, sealKey);
53
+ if (!still || still.appId !== app.appId || still.pem !== app.pem)
54
+ return { ok: false, reason: "disconnected", message: "the GitHub App was disconnected or replaced on this server" };
55
+ const minted = await mintInstallationToken(api, app.appId, app.pem, to, now());
56
+ if (minted.ok)
57
+ hold?.([minted.token]);
58
+ return minted;
59
+ },
60
+ // Before each call: the App as the store holds it now, the same id and key, or the run's token stops.
61
+ same: async () => {
62
+ const still = await appOf(store, sealKey);
63
+ return Boolean(still && still.appId === app.appId && still.pem === app.pem);
64
+ },
65
+ // An installation token revokes itself (DELETE /installation/token, the token its own credential): no App needed.
66
+ revoke: async (token) => void (await githubCall(api, "/installation/token", { method: "DELETE", jwt: token }).catch(() => undefined)),
67
+ };
37
68
  }
@@ -1,10 +1,23 @@
1
1
  import type { RunLaunch } from "../run-launch.js";
2
2
  import { type AdapterSpecDeps } from "./adapter-run-spec.js";
3
- import type { LoopFactory } from "./loop-contract.js";
3
+ import { type GradeRouteAsk } from "./learning-dispatch.js";
4
+ import type { GraderRoute } from "./learning-ask.js";
5
+ import { ClaimRefused, type LoopFactory } from "./loop-contract.js";
6
+ /** A claimed run whose harness this host's memory never holds: its message is the host's words (neverFits). A claim
7
+ * refused for good, so a parked run it wakes fails too, never retried as a resume (runner.ts finish). */
8
+ export declare class NeverFits extends ClaimRefused {
9
+ name: string;
10
+ }
4
11
  /** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
5
12
  * returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
6
13
  export declare function resolveRunnerLoop(deps: AdapterSpecDeps): (harness: string, launch: RunLaunch, runId: string) => Promise<LoopFactory | undefined>;
14
+ /** The route a grade asks for (gradeModelFor: the grade model the server named, else the agent's own), from the runner's
15
+ * one route (`routeOf`), through gradeRouteOf. A grade model the server named (--grade-model, else AGENT_MODEL_STRONG)
16
+ * is the strong tier's: it goes with that tier's settings, sent whole as AGENT_MODEL_STRONG is (never cut to its bare id
17
+ * by AGENT_MODEL_GATEWAY_IDS) and priced at AGENT_MODEL_STRONG_PRICE. The agent's own model goes as its runs' does, on
18
+ * the default tier. */
19
+ export declare function gradeRouteFor(grade: GradeRouteAsk, env: NodeJS.ProcessEnv, routeOf: AdapterSpecDeps["routeOf"]): Promise<GraderRoute>;
7
20
  /** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
8
- * dispatch (dispatch.ts) reads each run's launch and asks the switch (resolveRunnerLoop) for its harness loop. The server
21
+ * dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
9
22
  * start and the test server pass this to startRunner. */
10
23
  export declare function dispatchRunner(deps: AdapterSpecDeps): LoopFactory;
@@ -1,3 +1,13 @@
1
+ // The runner's dispatch switch (design 2.1: "the runner takes every run"): which loop a claimed run runs, by its revision
2
+ // and the harness its launch names. The runner holds one dispatch loop (dispatch.ts) for every run; at the claim the
3
+ // dispatch reads the launch and asks this switch for the run's inner loop:
4
+ // - a workflow revision runs on the workflow loop (createWorkflowLoop), whatever its harness name (a workflow's default
5
+ // harness is pi), so the revision is read here to tell it from an agentic pi run;
6
+ // - a built-in learning run (its launch names harness "learning") runs on the learning loop;
7
+ // - pi runs on the kernel's adapter loop with the run's pi spec (adapterRunSpecFromLaunch);
8
+ // - a CLI harness (claude-agent, codex, opencode) runs on the adapter loop with its own adapter;
9
+ // - anything else fails the run in words (the dispatch's UnknownHarness).
10
+ import { hostMemory, neverFits } from "../host.js";
1
11
  import { resolveHarness } from "./adapters/index.js";
2
12
  import { adapterRunSpecFromLaunch, PI_WIRES } from "./adapter-run-spec.js";
3
13
  import { createAdapterLoop } from "./adapter-loop.js";
@@ -5,8 +15,14 @@ import { savedModelKeys, withModelKeys } from "./claim-secrets.js";
5
15
  import { createDispatchLoop } from "./dispatch.js";
6
16
  import { cliRunSpecFromLaunch } from "./cli-run-spec.js";
7
17
  import { gradeModelFor, gradeRouteOf, learningLoopOf } from "./learning-dispatch.js";
18
+ import { ClaimRefused } from "./loop-contract.js";
8
19
  import { createWorkflowLoop, isWorkflowRevision } from "./workflow-loop.js";
9
20
  import { workflowSpecOf } from "./workflow-spec.js";
21
+ /** A claimed run whose harness this host's memory never holds: its message is the host's words (neverFits). A claim
22
+ * refused for good, so a parked run it wakes fails too, never retried as a resume (runner.ts finish). */
23
+ export class NeverFits extends ClaimRefused {
24
+ name = "NeverFits";
25
+ }
10
26
  /** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
11
27
  * returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
12
28
  export function resolveRunnerLoop(deps) {
@@ -38,9 +54,10 @@ export function resolveRunnerLoop(deps) {
38
54
  routeOf: async (grade) => {
39
55
  const base = deps.env ?? process.env;
40
56
  const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
41
- return gradeRouteOf(gradeModelFor(grade), env, (model) => deps.routeOf(model, env, "default", PI_WIRES));
57
+ return gradeRouteFor(grade, env, deps.routeOf);
42
58
  },
43
59
  ...(deps.log ? { log: deps.log } : {}),
60
+ ...(deps.gradeBound ? { gradeBound: deps.gradeBound } : {}),
44
61
  });
45
62
  }
46
63
  // The harness's own entry decides which spec builds the run, by the entry's facts and never the harness's name: an entry
@@ -48,6 +65,13 @@ export function resolveRunnerLoop(deps) {
48
65
  // runs the pi spec (adapterRunSpecFromLaunch). A harness with no entry is unknown here: the dispatch fails it in words.
49
66
  const runner = resolveHarness(harness);
50
67
  if (runner) {
68
+ // A run this host's memory never holds (host.ts neverFits: one run of its harness is more than the host has for runs)
69
+ // fails at its claim, in the words a start of it is refused in here (harness.ts harnessOffers): a run another host
70
+ // started, or one left before this host's memory shrank. Claimed alone (runner.ts claimByMemory), it would run past
71
+ // the host's memory and its OOM kill would take every run on it.
72
+ const tooBig = neverFits(harness, hostMemory());
73
+ if (tooBig)
74
+ throw new NeverFits(tooBig);
51
75
  // A run that learns supplies its own end-of-run step (reflect + proposal over its store) from its spec builder now,
52
76
  // where the run's Archil claim is: a Mode 2 run's learning folder is on its claim's disk, not this machine's local
53
77
  // path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The loop prefers the spec's step over its deps' (stepOf); a
@@ -59,8 +83,20 @@ export function resolveRunnerLoop(deps) {
59
83
  return undefined;
60
84
  };
61
85
  }
86
+ /** The route a grade asks for (gradeModelFor: the grade model the server named, else the agent's own), from the runner's
87
+ * one route (`routeOf`), through gradeRouteOf. A grade model the server named (--grade-model, else AGENT_MODEL_STRONG)
88
+ * is the strong tier's: it goes with that tier's settings, sent whole as AGENT_MODEL_STRONG is (never cut to its bare id
89
+ * by AGENT_MODEL_GATEWAY_IDS) and priced at AGENT_MODEL_STRONG_PRICE. The agent's own model goes as its runs' does, on
90
+ * the default tier. */
91
+ export function gradeRouteFor(grade, env, routeOf) {
92
+ return gradeRouteOf(gradeModelFor(grade), env, (model) => (grade.model !== undefined && model === grade.model
93
+ // The runner's environment under the grader as its strong model: every key it holds read through it, a non-enumerable
94
+ // one (a launcher-held or Settings key) too, which a copy would drop.
95
+ ? routeOf(undefined, Object.create(env, { AGENT_MODEL_STRONG: { value: model, enumerable: true } }), "strong", PI_WIRES)
96
+ : routeOf(model, env, "default", PI_WIRES)));
97
+ }
62
98
  /** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
63
- * dispatch (dispatch.ts) reads each run's launch and asks the switch (resolveRunnerLoop) for its harness loop. The server
99
+ * dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
64
100
  * start and the test server pass this to startRunner. */
65
101
  export function dispatchRunner(deps) {
66
102
  return createDispatchLoop({