@parcha/agentrun-serve 0.1.0-beta.37 → 0.1.0-beta.39

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 (620) hide show
  1. package/CHANGELOG.md +700 -0
  2. package/README.md +441 -177
  3. package/dist/adapters.d.ts +4 -1
  4. package/dist/adapters.js +4 -2
  5. package/dist/agent-rows.d.ts +1 -3
  6. package/dist/agents-store.d.ts +35 -3
  7. package/dist/agents-store.js +48 -23
  8. package/dist/answer-json.d.ts +34 -1
  9. package/dist/answer-json.js +91 -9
  10. package/dist/api-only.d.ts +1 -1
  11. package/dist/api-only.js +2 -2
  12. package/dist/bash-read-only.js +2 -1
  13. package/dist/browser-cost.js +52 -93
  14. package/dist/cap-short.d.ts +12 -0
  15. package/dist/cap-short.js +60 -0
  16. package/dist/cap.d.ts +3 -400
  17. package/dist/cap.js +6 -942
  18. package/dist/catalog.d.ts +0 -5
  19. package/dist/catalog.js +2 -6
  20. package/dist/chatgpt-plan.d.ts +163 -0
  21. package/dist/chatgpt-plan.js +549 -0
  22. package/dist/cli.js +26 -6
  23. package/dist/composio-preset.d.ts +25 -0
  24. package/dist/composio-preset.js +51 -8
  25. package/dist/composio-triggers.d.ts +113 -0
  26. package/dist/composio-triggers.js +411 -0
  27. package/dist/computer-calls.d.ts +36 -24
  28. package/dist/computer-calls.js +110 -27
  29. package/dist/computer-commands.d.ts +2 -0
  30. package/dist/computer-commands.js +7 -3
  31. package/dist/computer-live.d.ts +12 -2
  32. package/dist/computer-live.js +21 -5
  33. package/dist/computer-routes.d.ts +2 -2
  34. package/dist/computer-routes.js +2 -2
  35. package/dist/computer-setting.d.ts +15 -2
  36. package/dist/computer-setting.js +20 -4
  37. package/dist/computer-view.d.ts +18 -2
  38. package/dist/computer-view.js +21 -6
  39. package/dist/computer-viewer.js +40 -13
  40. package/dist/computers.d.ts +8 -2
  41. package/dist/computers.js +18 -8
  42. package/dist/console/assets/index-BNhZs-jp.css +1 -0
  43. package/dist/console/assets/index-BQv5aOGB.js +700 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/console-links.d.ts +2 -0
  46. package/dist/console-links.js +6 -3
  47. package/dist/decision-cap.d.ts +2 -5
  48. package/dist/decision-cap.js +3 -6
  49. package/dist/decision-rows.js +11 -11
  50. package/dist/decisions.js +4 -0
  51. package/dist/email/account.d.ts +84 -0
  52. package/dist/email/account.js +159 -0
  53. package/dist/email/answer.d.ts +10 -0
  54. package/dist/email/answer.js +182 -0
  55. package/dist/email/email-faux.d.ts +95 -0
  56. package/dist/email/email-faux.js +849 -0
  57. package/dist/email/labels.d.ts +1 -0
  58. package/dist/email/labels.js +84 -0
  59. package/dist/email/mail.d.ts +186 -0
  60. package/dist/email/mail.js +380 -0
  61. package/dist/email/names.d.ts +20 -0
  62. package/dist/email/names.js +40 -0
  63. package/dist/email/routes.d.ts +9 -0
  64. package/dist/email/routes.js +50 -0
  65. package/dist/email/tools.d.ts +20 -0
  66. package/dist/email/tools.js +517 -0
  67. package/dist/environment.d.ts +17 -2
  68. package/dist/environment.js +36 -8
  69. package/dist/errors.d.ts +6 -0
  70. package/dist/errors.js +12 -0
  71. package/dist/eval-mailbox.d.ts +103 -0
  72. package/dist/eval-mailbox.js +236 -0
  73. package/dist/faux-computers.js +4 -2
  74. package/dist/graph-view.d.ts +9 -2
  75. package/dist/graph-view.js +6 -2
  76. package/dist/harness-install.d.ts +28 -2
  77. package/dist/harness-install.js +147 -59
  78. package/dist/harness-opencode/adapter.js +2 -22
  79. package/dist/harness-opencode/facts.js +5 -4
  80. package/dist/harness-opencode/host/policy.d.ts +4 -5
  81. package/dist/harness-opencode/host/policy.js +14 -33
  82. package/dist/harness-opencode/index.d.ts +1 -1
  83. package/dist/harness-opencode/index.js +1 -1
  84. package/dist/harness-opencode/versions.d.ts +6 -0
  85. package/dist/harness-opencode/versions.js +6 -0
  86. package/dist/harness-table.d.ts +0 -2
  87. package/dist/harness-table.js +8 -7
  88. package/dist/harness.d.ts +12 -0
  89. package/dist/harness.js +15 -3
  90. package/dist/host-tools.d.ts +1 -5
  91. package/dist/host-tools.js +7 -10
  92. package/dist/hosted-search.d.ts +3 -3
  93. package/dist/hosted-search.js +51 -32
  94. package/dist/import-sources.d.ts +1 -1
  95. package/dist/import-sources.js +3 -3
  96. package/dist/import.d.ts +21 -0
  97. package/dist/import.js +186 -1
  98. package/dist/key-check.d.ts +0 -2
  99. package/dist/key-check.js +3 -4
  100. package/dist/key-refusal.d.ts +8 -2
  101. package/dist/key-refusal.js +16 -13
  102. package/dist/key-words.d.ts +3 -2
  103. package/dist/key-words.js +4 -2
  104. package/dist/learn/check.d.ts +24 -4
  105. package/dist/learn/check.js +340 -7
  106. package/dist/learn/commit.d.ts +10 -0
  107. package/dist/learn/commit.js +18 -4
  108. package/dist/learn/compile.d.ts +250 -0
  109. package/dist/learn/compile.js +507 -0
  110. package/dist/learn/general.d.ts +3 -0
  111. package/dist/learn/general.js +4 -2
  112. package/dist/learn/grade.d.ts +5 -1
  113. package/dist/learn/grade.js +11 -7
  114. package/dist/learn/notes.d.ts +8 -0
  115. package/dist/learn/notes.js +18 -0
  116. package/dist/learn/promote.d.ts +308 -0
  117. package/dist/learn/promote.js +321 -0
  118. package/dist/learn/refit.d.ts +48 -0
  119. package/dist/learn/refit.js +264 -0
  120. package/dist/learn/reflect.d.ts +5 -25
  121. package/dist/learn/reflect.js +14 -131
  122. package/dist/learn/replay-calls.d.ts +63 -0
  123. package/dist/learn/replay-calls.js +158 -0
  124. package/dist/learn/skills.d.ts +19 -16
  125. package/dist/learn/skills.js +157 -53
  126. package/dist/learn/workflow-nodes.d.ts +15 -0
  127. package/dist/learn/workflow-nodes.js +44 -0
  128. package/dist/learned-nodes.d.ts +58 -2
  129. package/dist/learned-nodes.js +68 -5
  130. package/dist/learned-workflow.d.ts +58 -32
  131. package/dist/learned-workflow.js +215 -77
  132. package/dist/learning-batch.d.ts +2 -2
  133. package/dist/learning-batch.js +4 -4
  134. package/dist/learning-cost.d.ts +41 -11
  135. package/dist/learning-cost.js +31 -13
  136. package/dist/learning-routes.d.ts +12 -2
  137. package/dist/learning-routes.js +34 -6
  138. package/dist/learning-words.d.ts +8 -1
  139. package/dist/learning-words.js +11 -1
  140. package/dist/learning.d.ts +26 -1
  141. package/dist/learning.js +7 -4
  142. package/dist/link-check.d.ts +27 -0
  143. package/dist/link-check.js +164 -0
  144. package/dist/llm.js +0 -3
  145. package/dist/local-models.d.ts +33 -2
  146. package/dist/local-models.js +43 -5
  147. package/dist/mcp-gateway.d.ts +12 -20
  148. package/dist/mcp-gateway.js +16 -44
  149. package/dist/mcp-oauth.d.ts +5 -0
  150. package/dist/mcp-oauth.js +1 -1
  151. package/dist/mcp-pin-first.d.ts +37 -0
  152. package/dist/mcp-pin-first.js +113 -0
  153. package/dist/mcp-probe.d.ts +8 -9
  154. package/dist/mcp-probe.js +16 -33
  155. package/dist/mcp-secret-writes.js +3 -0
  156. package/dist/mcp-servers-store.d.ts +102 -26
  157. package/dist/mcp-servers-store.js +151 -25
  158. package/dist/mcp-sources.d.ts +39 -0
  159. package/dist/mcp-sources.js +74 -0
  160. package/dist/mcp-store.d.ts +11 -0
  161. package/dist/mcp-store.js +16 -2
  162. package/dist/mcp-wire.d.ts +22 -0
  163. package/dist/mcp-wire.js +36 -0
  164. package/dist/mcp.js +3 -3
  165. package/dist/meta-tool-names.d.ts +1 -0
  166. package/dist/meta-tool-names.js +3 -0
  167. package/dist/model-form.d.ts +11 -0
  168. package/dist/model-form.js +17 -1
  169. package/dist/model.d.ts +39 -6
  170. package/dist/model.js +171 -32
  171. package/dist/monid.d.ts +50 -29
  172. package/dist/monid.js +234 -143
  173. package/dist/native/binding.d.ts +13 -0
  174. package/dist/native/binding.js +57 -0
  175. package/dist/native/cli.d.ts +2 -0
  176. package/dist/native/cli.js +48 -0
  177. package/dist/native/connection.d.ts +8 -0
  178. package/dist/native/connection.js +94 -0
  179. package/dist/native/context.d.ts +6 -0
  180. package/dist/native/context.js +22 -0
  181. package/dist/native/discovery.d.ts +27 -0
  182. package/dist/native/discovery.js +404 -0
  183. package/dist/native/environment.d.ts +4 -0
  184. package/dist/native/environment.js +18 -0
  185. package/dist/native/history.d.ts +20 -0
  186. package/dist/native/history.js +147 -0
  187. package/dist/native/instructions.d.ts +21 -0
  188. package/dist/native/instructions.js +173 -0
  189. package/dist/native/remote-worker-bridge.d.ts +3 -0
  190. package/dist/native/remote-worker-bridge.js +278 -0
  191. package/dist/native/remote.d.ts +187 -0
  192. package/dist/native/remote.js +492 -0
  193. package/dist/native/runtime.d.ts +17 -0
  194. package/dist/native/runtime.js +316 -0
  195. package/dist/native/runtimes.d.ts +66 -0
  196. package/dist/native/runtimes.js +41 -0
  197. package/dist/native/schema.d.ts +46 -0
  198. package/dist/native/schema.js +41 -0
  199. package/dist/native/types.d.ts +87 -0
  200. package/dist/native/types.js +1 -0
  201. package/dist/observation/http.d.ts +4 -0
  202. package/dist/observation/http.js +140 -0
  203. package/dist/observation/observer.d.ts +301 -0
  204. package/dist/observation/observer.js +919 -0
  205. package/dist/observation/schema.d.ts +52 -0
  206. package/dist/observation/schema.js +154 -0
  207. package/dist/openapi.d.ts +1 -0
  208. package/dist/openapi.js +705 -126
  209. package/dist/paid-calls.d.ts +34 -32
  210. package/dist/paid-calls.js +52 -104
  211. package/dist/place-offers.d.ts +4 -8
  212. package/dist/place-offers.js +4 -9
  213. package/dist/port-models.d.ts +7 -2
  214. package/dist/port-models.js +5 -2
  215. package/dist/print.d.ts +4 -2
  216. package/dist/print.js +4 -3
  217. package/dist/propose.d.ts +8 -3
  218. package/dist/propose.js +28 -7
  219. package/dist/provider.d.ts +5 -1
  220. package/dist/provider.js +17 -2
  221. package/dist/push-handler.d.ts +3 -2
  222. package/dist/push-handler.js +20 -6
  223. package/dist/reflect-range.js +2 -1
  224. package/dist/refusal-words.d.ts +11 -0
  225. package/dist/refusal-words.js +13 -2
  226. package/dist/rows.d.ts +5 -3
  227. package/dist/rows.js +15 -4
  228. package/dist/run-launch.d.ts +23 -1
  229. package/dist/run-launch.js +17 -4
  230. package/dist/run-learning-served.d.ts +84 -0
  231. package/dist/run-manifest.d.ts +8 -0
  232. package/dist/run-manifest.js +33 -1
  233. package/dist/run-reads-over-store.d.ts +3 -3
  234. package/dist/run-reads-over-store.js +13 -10
  235. package/dist/run-secrets.js +2 -3
  236. package/dist/run-timeline-served.d.ts +3 -2
  237. package/dist/run-timeline-served.js +12 -10
  238. package/dist/run-view.d.ts +59 -41
  239. package/dist/run-view.js +128 -64
  240. package/dist/runnable.d.ts +13 -8
  241. package/dist/runnable.js +77 -60
  242. package/dist/runner/adapter-loop.d.ts +60 -15
  243. package/dist/runner/adapter-loop.js +1406 -464
  244. package/dist/runner/adapter-run-spec.d.ts +45 -14
  245. package/dist/runner/adapter-run-spec.js +200 -116
  246. package/dist/runner/adapters/pi.d.ts +40 -7
  247. package/dist/runner/adapters/pi.js +149 -38
  248. package/dist/runner/beside.d.ts +3 -1
  249. package/dist/runner/beside.js +24 -8
  250. package/dist/runner/claim-secrets.d.ts +3 -1
  251. package/dist/runner/claim-secrets.js +28 -4
  252. package/dist/runner/cli-run-spec.d.ts +30 -0
  253. package/dist/runner/cli-run-spec.js +150 -66
  254. package/dist/runner/computer-channel.d.ts +5 -2
  255. package/dist/runner/computer-channel.js +5 -3
  256. package/dist/runner/computer-journal.d.ts +6 -0
  257. package/dist/runner/computer-journal.js +8 -10
  258. package/dist/runner/conformance/harness.d.ts +3 -0
  259. package/dist/runner/conformance/harness.js +149 -5
  260. package/dist/runner/conformance/subject.d.ts +11 -4
  261. package/dist/runner/end-of-run.d.ts +8 -5
  262. package/dist/runner/end-of-run.js +11 -6
  263. package/dist/runner/feedback-round.d.ts +79 -0
  264. package/dist/runner/feedback-round.js +127 -0
  265. package/dist/runner/harness-loops.js +17 -0
  266. package/dist/runner/journal-kinds.d.ts +55 -13
  267. package/dist/runner/journal-kinds.js +19 -0
  268. package/dist/runner/learning-dispatch.d.ts +3 -2
  269. package/dist/runner/learning-dispatch.js +6 -6
  270. package/dist/runner/learning-end.d.ts +58 -19
  271. package/dist/runner/learning-end.js +316 -115
  272. package/dist/runner/learning-factory.d.ts +3 -0
  273. package/dist/runner/learning-factory.js +8 -2
  274. package/dist/runner/learning-loop.d.ts +21 -1
  275. package/dist/runner/learning-loop.js +24 -6
  276. package/dist/runner/learning-seed.d.ts +4 -0
  277. package/dist/runner/learning-seed.js +14 -0
  278. package/dist/runner/loop-contract.d.ts +19 -3
  279. package/dist/runner/loop.d.ts +34 -1
  280. package/dist/runner/loop.js +55 -1
  281. package/dist/runner/main.d.ts +6 -1
  282. package/dist/runner/main.js +26 -4
  283. package/dist/runner/mcp-claim.d.ts +5 -1
  284. package/dist/runner/mcp-claim.js +66 -50
  285. package/dist/runner/mcp-run.d.ts +20 -53
  286. package/dist/runner/mcp-run.js +22 -88
  287. package/dist/runner/meta-tools.d.ts +44 -0
  288. package/dist/runner/meta-tools.js +344 -0
  289. package/dist/runner/metrics.d.ts +80 -21
  290. package/dist/runner/metrics.js +128 -42
  291. package/dist/runner/model-route.d.ts +12 -3
  292. package/dist/runner/model-route.js +149 -19
  293. package/dist/runner/monid-run.d.ts +18 -0
  294. package/dist/runner/monid-run.js +170 -0
  295. package/dist/runner/native-loop.d.ts +11 -0
  296. package/dist/runner/native-loop.js +438 -0
  297. package/dist/runner/promotion.d.ts +146 -0
  298. package/dist/runner/promotion.js +803 -0
  299. package/dist/runner/redact.js +3 -0
  300. package/dist/runner/reflect-hook.d.ts +36 -21
  301. package/dist/runner/reflect-hook.js +147 -49
  302. package/dist/runner/runner.d.ts +7 -1
  303. package/dist/runner/runner.js +34 -8
  304. package/dist/runner/sdk-loop.d.ts +7 -0
  305. package/dist/runner/sdk-loop.js +470 -0
  306. package/dist/runner/sessions.d.ts +8 -3
  307. package/dist/runner/sessions.js +5 -1
  308. package/dist/runner/spec-holds.d.ts +16 -2
  309. package/dist/runner/spec-holds.js +42 -14
  310. package/dist/runner/step-guard.d.ts +62 -0
  311. package/dist/runner/step-guard.js +93 -0
  312. package/dist/runner/store-secrets.js +17 -2
  313. package/dist/runner/subagent.d.ts +0 -3
  314. package/dist/runner/subagent.js +7 -12
  315. package/dist/runner/workflow-first.d.ts +226 -0
  316. package/dist/runner/workflow-first.js +293 -0
  317. package/dist/runner/workflow-loop.d.ts +1 -1
  318. package/dist/runner/workflow-loop.js +32 -19
  319. package/dist/runner/workflow-spec.d.ts +5 -1
  320. package/dist/runner/workflow-spec.js +63 -48
  321. package/dist/runs-over-store.d.ts +41 -4
  322. package/dist/runs-over-store.js +64 -22
  323. package/dist/sdk/runs.d.ts +115 -0
  324. package/dist/sdk/runs.js +422 -0
  325. package/dist/sdk/schema.d.ts +175 -0
  326. package/dist/sdk/schema.js +138 -0
  327. package/dist/sdk/workflows.d.ts +22 -0
  328. package/dist/sdk/workflows.js +39 -0
  329. package/dist/secrets.d.ts +2 -0
  330. package/dist/secrets.js +19 -1
  331. package/dist/server.d.ts +108 -20
  332. package/dist/server.js +874 -157
  333. package/dist/settings-wake.d.ts +8 -6
  334. package/dist/settings-wake.js +13 -7
  335. package/dist/skill-route.d.ts +3 -0
  336. package/dist/skill-route.js +16 -0
  337. package/dist/skills/agentrun-serve/SKILL.md +368 -0
  338. package/dist/stats.d.ts +10 -10
  339. package/dist/store/agent-body.d.ts +22 -7
  340. package/dist/store/agent-body.js +23 -14
  341. package/dist/store/command-wake.d.ts +3 -2
  342. package/dist/store/command-wake.js +4 -4
  343. package/dist/store/index.d.ts +1 -1
  344. package/dist/store/native-command-owner.d.ts +10 -0
  345. package/dist/store/native-command-owner.js +47 -0
  346. package/dist/store/postgres/connection.js +3 -1
  347. package/dist/store/postgres/migrations/0010_imported_templates.sql +18 -0
  348. package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
  349. package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
  350. package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
  351. package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
  352. package/dist/store/postgres/store.js +3 -0
  353. package/dist/store/schema.d.ts +16 -0
  354. package/dist/store/schema.js +47 -8
  355. package/dist/store/sqlite/connection.d.ts +2 -2
  356. package/dist/store/sqlite/connection.js +2 -2
  357. package/dist/store/sqlite/run-patch.d.ts +8 -1
  358. package/dist/store/sqlite/run-patch.js +33 -10
  359. package/dist/store/sqlite/store.js +184 -28
  360. package/dist/store/store.d.ts +98 -21
  361. package/dist/store-reads/analytics.d.ts +7 -7
  362. package/dist/store-reads/analytics.js +23 -5
  363. package/dist/store-reads/cap.js +8 -6
  364. package/dist/store-reads/journal.d.ts +30 -1
  365. package/dist/store-reads/journal.js +141 -83
  366. package/dist/store-reads/learning.d.ts +179 -13
  367. package/dist/store-reads/learning.js +230 -68
  368. package/dist/store-reads/loop.d.ts +61 -0
  369. package/dist/store-reads/loop.js +111 -0
  370. package/dist/store-reads/runs.d.ts +5 -0
  371. package/dist/store-reads/runs.js +3 -2
  372. package/dist/store-view.d.ts +3 -2
  373. package/dist/store-view.js +109 -37
  374. package/dist/template-eval.d.ts +87 -16
  375. package/dist/template-eval.js +605 -120
  376. package/dist/template-github-permissions.d.ts +2 -2
  377. package/dist/template-github-permissions.js +2 -1
  378. package/dist/template-import.d.ts +31 -0
  379. package/dist/template-import.js +121 -0
  380. package/dist/template-source.d.ts +51 -0
  381. package/dist/template-source.js +371 -0
  382. package/dist/templates.d.ts +274 -52
  383. package/dist/templates.js +670 -201
  384. package/dist/text-urls.d.ts +38 -0
  385. package/dist/text-urls.js +170 -0
  386. package/dist/timeline/computer.d.ts +48 -0
  387. package/dist/timeline/computer.js +169 -0
  388. package/dist/timeline/index.d.ts +7 -5
  389. package/dist/timeline/index.js +7 -5
  390. package/dist/timeline/labels.d.ts +11 -4
  391. package/dist/timeline/labels.js +122 -8
  392. package/dist/timeline/origin.d.ts +20 -6
  393. package/dist/timeline/origin.js +13 -6
  394. package/dist/timeline/render-text.js +1 -1
  395. package/dist/timeline/timeline.d.ts +76 -20
  396. package/dist/timeline/timeline.js +184 -39
  397. package/dist/timeline/util.d.ts +5 -0
  398. package/dist/timeline/util.js +44 -8
  399. package/dist/timeline/web-calls.d.ts +17 -0
  400. package/dist/timeline/web-calls.js +106 -0
  401. package/dist/tool-gate.d.ts +103 -76
  402. package/dist/tool-gate.js +200 -127
  403. package/dist/tool-keys.d.ts +4 -1
  404. package/dist/tool-keys.js +8 -3
  405. package/dist/tool-list.d.ts +29 -0
  406. package/dist/tool-list.js +50 -0
  407. package/dist/tool-names.d.ts +76 -0
  408. package/dist/tool-names.js +101 -0
  409. package/dist/tool-plane.d.ts +34 -28
  410. package/dist/tool-plane.js +72 -37
  411. package/dist/tools.d.ts +59 -15
  412. package/dist/tools.js +46 -42
  413. package/dist/trigger-adapter.d.ts +85 -5
  414. package/dist/trigger-adapter.js +6 -0
  415. package/dist/trigger-adapters.js +3 -1
  416. package/dist/trigger-composio.d.ts +10 -0
  417. package/dist/trigger-composio.js +122 -0
  418. package/dist/trigger-email.d.ts +4 -0
  419. package/dist/trigger-email.js +228 -0
  420. package/dist/trigger-signatures.d.ts +6 -10
  421. package/dist/trigger-signatures.js +16 -16
  422. package/dist/trigger-targets.d.ts +1 -1
  423. package/dist/trigger-targets.js +4 -3
  424. package/dist/trigger-webhook.js +6 -4
  425. package/dist/triggers.d.ts +94 -9
  426. package/dist/triggers.js +263 -62
  427. package/dist/uploads.d.ts +9 -0
  428. package/dist/uploads.js +27 -0
  429. package/dist/validate.d.ts +15 -7
  430. package/dist/validate.js +91 -50
  431. package/dist/web-fake.d.ts +56 -0
  432. package/dist/web-fake.js +102 -0
  433. package/dist/web-fetch-direct.d.ts +3 -0
  434. package/dist/web-fetch-direct.js +4 -1
  435. package/dist/web-fetch.d.ts +6 -8
  436. package/dist/web-fetch.js +10 -53
  437. package/dist/web-search.d.ts +51 -2
  438. package/dist/web-search.js +116 -18
  439. package/dist/webhooks.d.ts +2 -1
  440. package/dist/webhooks.js +5 -1
  441. package/dist/workflow/node-runner.js +10 -2
  442. package/dist/workspace/archil-claim.d.ts +3 -0
  443. package/dist/workspace/archil-claim.js +9 -2
  444. package/dist/workspace/computer-deps.d.ts +25 -9
  445. package/dist/workspace/computer-deps.js +82 -38
  446. package/dist/workspace/computer-for-claim.d.ts +60 -4
  447. package/dist/workspace/computer-for-claim.js +203 -45
  448. package/dist/workspace/computer-hold.js +7 -1
  449. package/dist/workspace/computer-janitor.d.ts +10 -3
  450. package/dist/workspace/computer-janitor.js +96 -29
  451. package/dist/workspace/computer-kept.d.ts +82 -0
  452. package/dist/workspace/computer-kept.js +147 -0
  453. package/dist/workspace/computer-mcp.js +4 -3
  454. package/dist/workspace/computer-ports.d.ts +23 -3
  455. package/dist/workspace/computer-ports.js +115 -5
  456. package/dist/workspace/index.d.ts +2 -3
  457. package/dist/workspace/index.js +1 -2
  458. package/dist/workspace/kind-skills/desktop/SKILL.md +31 -11
  459. package/dist/workspace/kind-skills/phone/SKILL.md +29 -14
  460. package/dist/workspace/local.js +2 -2
  461. package/dist/workspace/resolve-computer.d.ts +33 -1
  462. package/dist/workspace/resolve-computer.js +37 -16
  463. package/dist/workspace/revision-skills.d.ts +6 -2
  464. package/dist/workspace/revision-skills.js +12 -5
  465. package/dist/workspace/run-end-computers.d.ts +30 -0
  466. package/dist/workspace/run-end-computers.js +137 -0
  467. package/dist/workspace/run-tools.d.ts +40 -23
  468. package/dist/workspace/run-tools.js +46 -19
  469. package/dist/wrap-up.d.ts +35 -0
  470. package/dist/wrap-up.js +48 -0
  471. package/launcher/agentrun-serve +4 -2
  472. package/package.json +13 -9
  473. package/skills/agentrun-serve/SKILL.md +248 -10
  474. package/templates/README.md +220 -60
  475. package/templates/TOOLS.md +168 -0
  476. package/templates/code-review/agent.md +46 -16
  477. package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
  478. package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
  479. package/templates/code-review/evals/injection/case.yaml +2 -1
  480. package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
  481. package/templates/code-review/evals/mentions-defused/case.yaml +3 -3
  482. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
  483. package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
  484. package/templates/code-review/evals/never-flag/case.yaml +2 -1
  485. package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
  486. package/templates/code-review/evals/null-name/case.yaml +2 -1
  487. package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
  488. package/templates/code-review/evals/off-by-one/case.yaml +2 -1
  489. package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
  490. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
  491. package/templates/code-review/evals/other-repo/case.yaml +16 -0
  492. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
  493. package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
  494. package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
  495. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
  496. package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
  497. package/templates/code-review/evals/other-repo/prompt.md +10 -0
  498. package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
  499. package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
  500. package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
  501. package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
  502. package/templates/code-review/evals/re-review/case.yaml +2 -1
  503. package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
  504. package/templates/code-review/evals/re-review-open/case.yaml +2 -1
  505. package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
  506. package/templates/code-review/evals/repo-rule/case.yaml +2 -1
  507. package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
  508. package/templates/code-review/evals/two-defects/case.yaml +2 -1
  509. package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
  510. package/templates/code-review/rules/CODEREVIEW.md +1 -1
  511. package/templates/code-review/skills/review/DEEP.md +5 -4
  512. package/templates/code-review/skills/review/REVIEWER.md +5 -4
  513. package/templates/code-review/skills/review/SKILL.md +11 -6
  514. package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
  515. package/templates/inbound-lead/agent.md +26 -16
  516. package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
  517. package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
  518. package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
  519. package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
  520. package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
  521. package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
  522. package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
  523. package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
  524. package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
  525. package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
  526. package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
  527. package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
  528. package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
  529. package/templates/kyb/agent.md +15 -5
  530. package/templates/kyb/evals/adverse-media/prompt.md +2 -7
  531. package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
  532. package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
  533. package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
  534. package/templates/kyb/evals/name-collision/prompt.md +2 -6
  535. package/templates/kyb/evals/no-invention/prompt.md +2 -6
  536. package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
  537. package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
  538. package/templates/kyb/kyb.schema.json +8 -7
  539. package/templates/kyb/skills/kyb/SKILL.md +9 -6
  540. package/templates/market-monitor/agent.md +19 -12
  541. package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
  542. package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
  543. package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
  544. package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
  545. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  546. package/templates/release-notes/agent.md +32 -10
  547. package/templates/release-notes/evals/draft-not-publish/case.yaml +5 -4
  548. package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
  549. package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
  550. package/templates/release-notes/evals/issue-write-refused/case.yaml +5 -4
  551. package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
  552. package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
  553. package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
  554. package/templates/release-notes/evals/learned-style/case.yaml +2 -1
  555. package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
  556. package/templates/release-notes/evals/other-repo/case.yaml +24 -0
  557. package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
  558. package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
  559. package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
  560. package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
  561. package/templates/release-notes/evals/other-repo/prompt.md +32 -0
  562. package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
  563. package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
  564. package/templates/release-notes/notes.schema.json +1 -1
  565. package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
  566. package/dist/console/assets/index-Cn6JX1uH.js +0 -563
  567. package/dist/console/assets/index-DRN62V5v.css +0 -1
  568. package/dist/host-calls.d.ts +0 -20
  569. package/dist/host-calls.js +0 -12
  570. package/dist/runner/adapters/pi-computer.d.ts +0 -7
  571. package/dist/runner/adapters/pi-computer.js +0 -43
  572. package/dist/tool-blurbs.d.ts +0 -4
  573. package/dist/tool-blurbs.js +0 -28
  574. package/dist/tool-budget.d.ts +0 -38
  575. package/dist/tool-budget.js +0 -62
  576. package/dist/workspace/computer-script.d.ts +0 -37
  577. package/dist/workspace/computer-script.js +0 -138
  578. package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
  579. package/templates/code-review/evals/injection/graders/schema.md +0 -5
  580. package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
  581. package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
  582. package/templates/code-review/evals/null-name/graders/schema.md +0 -5
  583. package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
  584. package/templates/code-review/evals/re-review/graders/schema.md +0 -5
  585. package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
  586. package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
  587. package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
  588. package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
  589. package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
  590. package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
  591. package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
  592. package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
  593. package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
  594. package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
  595. package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
  596. package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
  597. package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
  598. package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
  599. package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
  600. package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
  601. package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
  602. package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
  603. package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
  604. package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
  605. package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
  606. package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
  607. package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
  608. package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
  609. package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
  610. package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
  611. package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
  612. package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
  613. package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
  614. package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
  615. package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
  616. package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
  617. package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
  618. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
  619. package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
  620. package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
@@ -0,0 +1,549 @@
1
+ // A person's ChatGPT plan as this server's model source for codex and pi: OpenAI's Sign in with ChatGPT, through pi-ai's
2
+ // own flow (its `openai` provider's OAuth: a loopback callback on 127.0.0.1:1455, or the final redirect URL pasted back),
3
+ // never one of ours. One sign-in per server: its credential is sealed whole in one row (CHATGPT_PLAN_ROW), and its access
4
+ // token goes to api.openai.com/v1/responses as a bearer, billed to the plan. Whoever holds the store and the seal key reads
5
+ // it per request (the server, its runners, in their own processes or containers); a token within REFRESH_MARGIN_MS of its
6
+ // end is renewed once across all of them: one renewal per refresh token in a process, and one holder at a time across
7
+ // processes, by a lease on the row taken with a compare-and-set on its sealed bytes and judged on the store's clock
8
+ // (ChatGPTPlan.renew). A refusal of the renewal (a refresh token spent or revoked) marks the sign-in expired: nothing
9
+ // retries it. No token outlives the sign-in it belongs to: a sign-out, a new sign-in, or a renewal that loses its write
10
+ // back revokes the pair it leaves behind at OpenAI (ChatGPTPlan.revoke). No token value is logged, journaled, put in a
11
+ // view or an error, or printed with the reader: each one read joins the redaction list (secrets.ts holdSecret).
12
+ import { randomUUID } from "node:crypto";
13
+ import { setTimeout as sleep } from "node:timers/promises";
14
+ import { inspect } from "node:util";
15
+ import { CredentialUnavailable } from "@parcha/agentrun-kernel/host";
16
+ import { holdSecret } from "./secrets.js";
17
+ import { registerSecretWrite } from "./secret-writes.js";
18
+ import { putSealedKey } from "./server-keys.js";
19
+ import { sealColumn, sealedAt, STORE_WRITE_DEADLINE_MS, unsealColumn } from "./store/index.js";
20
+ // Every operation of the sign-in is the owner's session's alone (secret-writes.ts), the token in none of them: its view
21
+ // holds no token, but a pending sign-in's link is the owner's to open.
22
+ for (const operation of ["getChatGPTSignIn", "startChatGPTSignIn", "finishChatGPTSignIn", "signOutChatGPT"])
23
+ registerSecretWrite(operation, () => true);
24
+ /** The sealed row that holds the sign-in. */
25
+ export const CHATGPT_PLAN_ROW = "chatgpt:plan";
26
+ /** The model provider a plan model is named under (`chatgpt/<model-id>`), so a run's billing is never chosen silently. */
27
+ export const PLAN_PROVIDER = "chatgpt";
28
+ /** Where plan requests go. */
29
+ export const PLAN_ORIGIN = "https://api.openai.com";
30
+ /** The models listed when OpenAI's list can't be read at sign-in. */
31
+ export const PLAN_FALLBACK_MODELS = Object.freeze(["gpt-6.1-sol", "gpt-6.1-terra", "gpt-6-luna"]);
32
+ /** The model a run on the plan gets when it names none. */
33
+ export const PLAN_DEFAULT_MODEL = "gpt-6.1-sol";
34
+ const OPENID_CONFIGURATION = "https://auth.openai.com/.well-known/openid-configuration";
35
+ const DIRECT_SCOPE = "chatgpt.tokens.use.direct";
36
+ const AGENT_NAME = "AgentRun";
37
+ const HOST_ID_SETTING = "chatgpt_host_id";
38
+ const PENDING_MS = 10 * 60_000;
39
+ const REFRESH_MARGIN_MS = 5 * 60_000;
40
+ /** The longest one refresh call at OpenAI may take: its holder gives it up by then. */
41
+ const REFRESH_CALL_MS = 15_000;
42
+ /** A refresh lease's length (60 s): the call, the write back (STORE_WRITE_DEADLINE_MS) and 35 s spare, so a lease never lapses
43
+ * while its holder may still spend the token. Its end is stamped and judged on the store's clock (SealedKeys.clock: the
44
+ * database's on Postgres), never a process's own, so a reader whose clock runs ahead of the holder's never takes a lease
45
+ * still live and sends a refresh token the holder may be spending (which OpenAI answers by revoking the sign-in). A
46
+ * holder that dies holds the others up for the lease's length at most. */
47
+ const REFRESH_LEASE_MS = REFRESH_CALL_MS + STORE_WRITE_DEADLINE_MS + 35_000;
48
+ /** How often a reader waiting on a peer's renewal reads the row again. */
49
+ const LEASE_WAIT_MS = 200;
50
+ const RENEW_LATER = "OpenAI could not renew the ChatGPT sign-in just now: try again in a moment.";
51
+ /** Where pi-ai's flow sends the browser at its end: the address a person pastes back from a remote server. */
52
+ /** OpenAI's fixed callback for this flow, built from its parts: a packed package carries no loopback URL as one string. */
53
+ const REDIRECT = Object.assign(new URL("http://callback.invalid/auth/callback"), { hostname: "127.0.0.1", port: "1455" });
54
+ /** The words a run or a request gets when there is no plan token to send. */
55
+ export const SIGNED_OUT = "This server is not signed in to ChatGPT: sign in under Settings → Model keys, or name a model on a key.";
56
+ export const EXPIRED = "This server's ChatGPT sign-in expired: sign in again under Settings → Model keys.";
57
+ /** What a sign-out answers beside `revoked: false`: the sign-in is gone here, and the person ends it at OpenAI. */
58
+ export const SIGN_OUT_UNCONFIRMED = "Signed out here. OpenAI didn't confirm the revocation: remove AgentRun in your ChatGPT settings.";
59
+ /** A sign-in step refused, in words a person acts on (the routes' 400). */
60
+ export class PlanSignInRefused extends Error {
61
+ }
62
+ /** No plan token can be had now (signed out, expired, or OpenAI could not renew it), in plain words: a model proxy
63
+ * refuses the request in these words (CredentialUnavailable). */
64
+ export class PlanUnavailable extends CredentialUnavailable {
65
+ }
66
+ /** Where an environment object carries the plan's reader: a symbol, so no spawn, spread into an env list or JSON of it
67
+ * carries it (Node builds a child's environment from its string keys alone). */
68
+ const PLAN = Symbol.for("agentrun.chatgpt-plan");
69
+ /** `env`'s plan reader, if it has one. */
70
+ export const planOf = (env) => env[PLAN];
71
+ /** `env` carrying `plan`, in place: an enumerable symbol property, so an object spread of it keeps it. */
72
+ export function withPlan(env, plan) {
73
+ if (plan)
74
+ Object.defineProperty(env, PLAN, { value: plan, enumerable: true, configurable: true, writable: true });
75
+ return env;
76
+ }
77
+ /** Whether `env` runs on the plan now. */
78
+ export const signedIn = (env) => planOf(env)?.state === "signed_in";
79
+ /** The claims of a JWT's payload, read without checking its signature (only for what a view shows), or none. */
80
+ function claimsOf(token) {
81
+ try {
82
+ const parsed = JSON.parse(Buffer.from(token.split(".")[1] ?? "", "base64url").toString("utf8"));
83
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
84
+ }
85
+ catch {
86
+ return {};
87
+ }
88
+ }
89
+ /** The email and plan a token names (OpenAI's profile and auth claims), for display alone. pi-ai keeps no ID token, so the
90
+ * access token's claims, which carry the same, are read. */
91
+ function whoOf(token) {
92
+ const claims = claimsOf(token);
93
+ const profile = claims["https://api.openai.com/profile"];
94
+ const auth = claims["https://api.openai.com/auth"];
95
+ const email = typeof profile?.email === "string" ? profile.email : typeof claims.email === "string" ? claims.email : undefined;
96
+ const plan = typeof auth?.chatgpt_plan_type === "string" ? auth.chatgpt_plan_type : undefined;
97
+ return { ...(email ? { email } : {}), ...(plan ? { plan } : {}) };
98
+ }
99
+ /** Whether a renewal's refusal is for good: the refresh token spent, expired or revoked (a 400 or 401 from the token
100
+ * endpoint, as pi-ai words it), not a network fault or a 5xx. */
101
+ const refusedForGood = (error) => /\((400|401)\)|invalid_grant|refresh_token_(reused|expired|invalidated)/.test(String(error?.message ?? ""));
102
+ /** Whether a renewal that failed surely left its refresh token unspent: OpenAI answered with a fault (a 5xx, a 429), or
103
+ * the request never reached it (no address, no connection). A timeout, or a fault once it was sent, may have spent it. */
104
+ function unspent(error) {
105
+ if (/token request failed \((?!400|401)\d{3}\)/.test(String(error?.message ?? "")))
106
+ return true;
107
+ const code = error?.cause?.code;
108
+ return code === "ECONNREFUSED" || code === "ENOTFOUND" || code === "EAI_AGAIN";
109
+ }
110
+ /** The renewals in flight in this process, by the refresh token they spend: two readers of one sign-in share one. */
111
+ const flights = new Map();
112
+ /** The plan over one store: a server's (sign-in, sign-out, its reading) or a runner's (the token, per request). Its
113
+ * fields are #private and it prints as its state alone (util.inspect, JSON), so an environment that carries it (withPlan)
114
+ * never shows a token when logged. */
115
+ export class ChatGPTPlan {
116
+ #snapshot;
117
+ #pending;
118
+ /** An access token OpenAI refused (refused): token() renews rather than send it again. */
119
+ #refusedAccess;
120
+ /** Moved on by each sign-in started and each sign-out: a sign-in keeps its credential only while it is unmoved since it
121
+ * started, so a sign-out (or a newer sign-in) while it finishes wins. */
122
+ #epoch = 0;
123
+ /** Set when a sign-in dropped by a sign-out (keep) could not have its revocation confirmed by OpenAI: that sign-out
124
+ * answers revoked false. Cleared at each sign-out's start. */
125
+ #droppedUnconfirmed = false;
126
+ #watchers = new Set();
127
+ #deps;
128
+ constructor(deps) {
129
+ this.#deps = deps;
130
+ }
131
+ [inspect.custom]() {
132
+ return `ChatGPTPlan { state: '${this.state}' }`;
133
+ }
134
+ toJSON() {
135
+ return { state: this.state };
136
+ }
137
+ watch(listener) {
138
+ this.#watchers.add(listener);
139
+ if (this.#snapshot)
140
+ listener([this.#snapshot.credential.access, this.#snapshot.credential.refresh]);
141
+ }
142
+ /** Each token of `credential` joins this process's redaction, and every watcher's. */
143
+ hold(credential) {
144
+ holdSecret(credential.access, credential.refresh);
145
+ for (const listener of this.#watchers)
146
+ listener([credential.access, credential.refresh]);
147
+ }
148
+ /** This process's clock: what a token's own end (OpenAI's `expires_in`, counted here) is judged by. */
149
+ now() {
150
+ return (this.#deps.now ?? Date.now)();
151
+ }
152
+ /** The store's clock: what a renewal lease is stamped and judged by, the same for every process on the store. */
153
+ storeNow() {
154
+ return this.#deps.store.sealedKeys.clock();
155
+ }
156
+ get state() {
157
+ return this.#snapshot?.state ?? "signed_out";
158
+ }
159
+ get models() {
160
+ return this.#snapshot?.models ?? [];
161
+ }
162
+ /** The row as sealed now, opened; none with none saved or one that does not open. */
163
+ async read() {
164
+ return (await this.readSealed())?.row;
165
+ }
166
+ /** The row as sealed now, opened, with the bytes it was read as (what a compare-and-set on it compares). */
167
+ async readSealed() {
168
+ const bytes = await this.#deps.store.sealedKeys.get(CHATGPT_PLAN_ROW);
169
+ if (bytes === undefined)
170
+ return undefined;
171
+ const row = this.open(bytes);
172
+ return row ? { row, bytes } : undefined;
173
+ }
174
+ /** The row sealed as `bytes`, opened (its tokens held for redaction); none when they do not open. */
175
+ open(bytes) {
176
+ try {
177
+ const row = JSON.parse(unsealColumn(this.#deps.sealKey, sealedAt.sealedKey(CHATGPT_PLAN_ROW), bytes).toString("utf8"));
178
+ if (row?.v !== 1 || !row.credential?.access || !row.credential.refresh)
179
+ return undefined;
180
+ this.hold(row.credential);
181
+ return row;
182
+ }
183
+ catch {
184
+ return undefined;
185
+ }
186
+ }
187
+ /** `row` sealed as the store keeps it: fresh bytes at each seal. */
188
+ seal(row) {
189
+ return sealColumn(this.#deps.sealKey, sealedAt.sealedKey(CHATGPT_PLAN_ROW), JSON.stringify(row));
190
+ }
191
+ /** `row` saved only while the store still holds `was` (SealedKeys.replaceIf): the bytes it was saved as, or none when
192
+ * the row had changed. */
193
+ async swap(was, row) {
194
+ const bytes = this.seal(row);
195
+ return (await this.#deps.store.sealedKeys.replaceIf(CHATGPT_PLAN_ROW, was, bytes)) ? bytes : undefined;
196
+ }
197
+ /** Reads the sealed row into the state a reader sees. Returns this. */
198
+ async load() {
199
+ this.#snapshot = await this.read();
200
+ return this;
201
+ }
202
+ view() {
203
+ if (this.#pending && this.#pending.expiresAt <= this.now())
204
+ this.cancel();
205
+ const row = this.#snapshot;
206
+ const who = row ? { ...(row.email ? { email: row.email } : {}), ...(row.plan ? { plan: row.plan } : {}) } : {};
207
+ if (this.#pending)
208
+ return { state: "pending", authorize_url: this.#pending.authorizeUrl, expires_at: new Date(this.#pending.expiresAt).toISOString(), ...who };
209
+ if (!row)
210
+ return { state: "signed_out" };
211
+ return { state: row.state, ...who, ...(row.state === "signed_in" ? { models: [...row.models] } : {}) };
212
+ }
213
+ /** This server's id at OpenAI (its agent host id): a UUID made once and kept in the store's settings. Not a credential. */
214
+ async hostId() {
215
+ if (!this.#deps.store.settings)
216
+ throw new Error("a ChatGPT sign-in starts on the server, which keeps its host id");
217
+ const kept = await this.#deps.store.settings.putIfAbsent(HOST_ID_SETTING, randomUUID());
218
+ if (typeof kept !== "string")
219
+ throw new Error("this server's ChatGPT host id is not a UUID in its settings");
220
+ return kept;
221
+ }
222
+ cancel() {
223
+ const pending = this.#pending;
224
+ if (!pending)
225
+ return;
226
+ this.#pending = undefined;
227
+ clearTimeout(pending.timer);
228
+ pending.abort.abort();
229
+ }
230
+ /** Starts a sign-in (one at a time: a new start cancels the one waiting) and gives the address to open. It lasts 10
231
+ * minutes: the loopback callback finishes it where the browser runs on this machine; elsewhere finishSignIn does. */
232
+ async startSignIn() {
233
+ // A sign-in still finishing drops its credential (keep): this one is the person's latest.
234
+ const epoch = ++this.#epoch;
235
+ const before = this.#pending;
236
+ this.cancel();
237
+ // pi-ai's callback listener on :1455 closes as its login ends: the one cancelled ends before this one listens.
238
+ if (before)
239
+ await before.result.catch(() => undefined);
240
+ const { openaiProvider } = await import("@earendil-works/pi-ai/providers/openai");
241
+ const oauth = openaiProvider().auth.oauth;
242
+ const hostId = await this.hostId();
243
+ const abort = new AbortController();
244
+ let paste;
245
+ const pasted = new Promise((resolve) => (paste = resolve));
246
+ let linked;
247
+ const link = new Promise((resolve) => (linked = resolve));
248
+ const login = oauth.login({
249
+ signal: abort.signal,
250
+ notify: (event) => void (event.type === "auth_url" ? linked(event.url) : undefined),
251
+ prompt: (prompt) => (prompt.type === "manual_code" ? Promise.race([pasted, new Promise((_, reject) => prompt.signal?.addEventListener("abort", () => reject(new Error("closed")), { once: true }))]) : Promise.reject(new Error("not asked here"))),
252
+ }, { getDeviceId: () => hostId, agentName: AGENT_NAME });
253
+ const settle = () => {
254
+ if (this.#pending?.abort !== abort)
255
+ return;
256
+ clearTimeout(this.#pending.timer);
257
+ this.#pending = undefined;
258
+ };
259
+ // Pending until the credential is kept or dropped, so a sign-out meanwhile cancels it (keep's epoch).
260
+ const result = login.then((credential) => this.keep(credential, epoch)).finally(settle);
261
+ result.catch(() => undefined);
262
+ const authorizeUrl = await Promise.race([link, result.then(() => undefined, (error) => {
263
+ throw new PlanSignInRefused(/in use/.test(String(error?.message)) ? "Another sign-in holds this machine's port 1455: finish or cancel it, then start again." : "The sign-in could not start: try again.");
264
+ })]);
265
+ if (!authorizeUrl)
266
+ throw new PlanSignInRefused("The sign-in could not start: try again.");
267
+ const expiresAt = this.now() + PENDING_MS;
268
+ const timer = setTimeout(() => (this.#pending?.abort === abort ? this.cancel() : undefined), PENDING_MS);
269
+ timer.unref();
270
+ this.#pending = { abort, state: new URL(authorizeUrl).searchParams.get("state") ?? "", authorizeUrl, expiresAt, paste, result, timer };
271
+ return { authorize_url: authorizeUrl, expires_at: new Date(expiresAt).toISOString() };
272
+ }
273
+ /** Finishes the sign-in waiting with the address its browser tab ended on, pasted. A URL that is not that sign-in's end
274
+ * is refused in words and the sign-in keeps waiting; one OpenAI refuses ends it. */
275
+ async finishSignIn(redirectUrl) {
276
+ const pending = this.#pending && this.#pending.expiresAt > this.now() ? this.#pending : undefined;
277
+ if (!pending)
278
+ throw new PlanSignInRefused("No ChatGPT sign-in is waiting (one lasts 10 minutes): start the sign-in again.");
279
+ const shape = `Paste the whole address the sign-in tab ended on: it starts with ${REDIRECT.href}.`;
280
+ let url;
281
+ try {
282
+ url = new URL(String(redirectUrl ?? "").trim());
283
+ }
284
+ catch {
285
+ throw new PlanSignInRefused(shape);
286
+ }
287
+ if (url.origin !== REDIRECT.origin || url.pathname !== REDIRECT.pathname)
288
+ throw new PlanSignInRefused(shape);
289
+ const error = url.searchParams.get("error");
290
+ if (error)
291
+ throw new PlanSignInRefused(`ChatGPT did not sign you in (${error.replace(/[^a-z_]/gi, "").slice(0, 40)}): start the sign-in again.`);
292
+ if (url.searchParams.get("state") !== pending.state)
293
+ throw new PlanSignInRefused("That address is from another sign-in: paste the one from the sign-in you started last, or start again.");
294
+ if (!url.searchParams.get("code") || !url.searchParams.get("client_id"))
295
+ throw new PlanSignInRefused(`That address has no sign-in code in it. ${shape}`);
296
+ pending.paste(url.href);
297
+ try {
298
+ await pending.result;
299
+ }
300
+ catch (error) {
301
+ const words = String(error?.message ?? "");
302
+ if (words.includes(DIRECT_SCOPE))
303
+ throw new PlanSignInRefused("This ChatGPT account did not allow its plan to be used by apps: sign in with an account whose plan allows it.");
304
+ throw new PlanSignInRefused("OpenAI refused the sign-in: start it again.");
305
+ }
306
+ return this.view();
307
+ }
308
+ /** A credential from the sign-in started at `epoch`, checked and sealed with what a view shows. A sign-out or a newer
309
+ * sign-in since then wins: the credential is dropped, never written, and revoked at OpenAI. A sign-in it takes the place
310
+ * of is revoked first, then replaced only while the row still holds it (a renewal of it that wrote back meanwhile is
311
+ * read, revoked and replaced in turn), so no earlier pair is left alive. */
312
+ async keep(credential, epoch) {
313
+ if (credential.scopes && !credential.scopes.includes(DIRECT_SCOPE))
314
+ throw new Error(`the grant did not include ${DIRECT_SCOPE}`);
315
+ this.hold(credential);
316
+ const models = await this.listModels(credential.access);
317
+ const row = { v: 1, state: "signed_in", credential, ...whoOf(credential.access), models };
318
+ let previousRevoked;
319
+ for (;;) {
320
+ if (epoch !== this.#epoch) {
321
+ if (!(await this.revoke(credential)))
322
+ this.#droppedUnconfirmed = true;
323
+ return;
324
+ }
325
+ const was = await this.#deps.store.sealedKeys.get(CHATGPT_PLAN_ROW);
326
+ if (was === undefined) {
327
+ // No row to compare against: only the server signs in, and nothing else makes the row (a runner's renewal
328
+ // replaces one only while it holds its lease), so a plain write.
329
+ await putSealedKey(this.#deps.store, this.#deps.sealKey, CHATGPT_PLAN_ROW, JSON.stringify(row));
330
+ break;
331
+ }
332
+ const previous = this.open(was);
333
+ if (previous && previous.credential.refresh !== credential.refresh)
334
+ previousRevoked = await this.revoke(previous.credential);
335
+ if (epoch !== this.#epoch)
336
+ continue;
337
+ if (await this.swap(was, row))
338
+ break;
339
+ }
340
+ this.#snapshot = row;
341
+ this.#deps.log?.({ chatgpt: "signed_in", ...(previousRevoked === undefined ? {} : { previous_revoked: String(previousRevoked) }) });
342
+ await this.#deps.changed?.();
343
+ }
344
+ /** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families; the fallback
345
+ * list when it can't be read. */
346
+ async listModels(token) {
347
+ try {
348
+ const response = await fetch(`${PLAN_ORIGIN}/v1/models`, { headers: { authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(5_000) });
349
+ if (!response.ok)
350
+ return [...PLAN_FALLBACK_MODELS];
351
+ const body = (await response.json());
352
+ const ids = (body.data ?? []).map((model) => model.id).filter((id) => typeof id === "string" && /^gpt-6(?:[.-]|$)/.test(id));
353
+ return ids.length ? [...new Set(ids)] : [...PLAN_FALLBACK_MODELS];
354
+ }
355
+ catch {
356
+ return [...PLAN_FALLBACK_MODELS];
357
+ }
358
+ }
359
+ /** The access token to send now: the sealed one, renewed first when it ends within 5 minutes. Throws PlanUnavailable,
360
+ * in words, when there is none. */
361
+ async token() {
362
+ const row = await this.read();
363
+ this.#snapshot = row;
364
+ if (!row)
365
+ throw new PlanUnavailable(SIGNED_OUT);
366
+ if (row.state === "expired")
367
+ throw new PlanUnavailable(EXPIRED);
368
+ if (this.fresh(row))
369
+ return row.credential.access;
370
+ // One renewal per refresh token in this process; across processes, the row's lease (renew).
371
+ const key = row.credential.refresh;
372
+ let flight = flights.get(key);
373
+ if (!flight) {
374
+ flight = this.renew(key).finally(() => flights.delete(key));
375
+ flights.set(key, flight);
376
+ }
377
+ return flight;
378
+ }
379
+ /** Whether `row`'s access token may be sent as it is: OpenAI has not refused it here, and it has more than 5 minutes left. */
380
+ fresh(row) {
381
+ return row.credential.access !== this.#refusedAccess && row.credential.expires - this.now() > REFRESH_MARGIN_MS;
382
+ }
383
+ /** OpenAI answered 401 to `sent`: the row read again, and the next token() renews it only when the row still holds
384
+ * `sent` (another holder that renewed already has put a new one there, which is sent instead). */
385
+ async refused(sent) {
386
+ const row = await this.read();
387
+ if (row?.state === "signed_in" && row.credential.access === sent)
388
+ this.#refusedAccess = sent;
389
+ }
390
+ /** Renews the sign-in whose refresh token is `seen`, for any process that holds the store and the seal key (the server,
391
+ * each runner). A refresh token is spent at its use, and one used twice makes OpenAI revoke the whole sign-in, so one
392
+ * holder at a time takes a lease on the row (a compare-and-set on its sealed bytes) before it spends the token. The
393
+ * others adopt the pair it writes back: meanwhile they send the current token while it has not ended, and wait for the
394
+ * new pair once it has. A lease whose holder died lapses after REFRESH_LEASE_MS, and the next reader takes it. The
395
+ * lease's end is stamped and judged on the store's clock, so a process whose own clock runs ahead never takes one
396
+ * still live. */
397
+ async renew(seen) {
398
+ const holder = randomUUID();
399
+ const giveUp = this.now() + REFRESH_LEASE_MS + REFRESH_CALL_MS;
400
+ for (;;) {
401
+ const read = await this.readSealed();
402
+ if (!read)
403
+ throw new PlanUnavailable(SIGNED_OUT);
404
+ const { row, bytes } = read;
405
+ this.#snapshot = row;
406
+ if (row.state === "expired")
407
+ throw new PlanUnavailable(EXPIRED);
408
+ // A peer renewed it since: its pair is the row's now.
409
+ if (row.credential.refresh !== seen && this.fresh(row))
410
+ return row.credential.access;
411
+ const at = await this.storeNow();
412
+ if (row.lease && row.lease.until > at) {
413
+ if (row.credential.access !== this.#refusedAccess && row.credential.expires > this.now())
414
+ return row.credential.access;
415
+ if (this.now() > giveUp)
416
+ throw new PlanUnavailable(RENEW_LATER);
417
+ await sleep(LEASE_WAIT_MS);
418
+ continue;
419
+ }
420
+ const leased = { ...row, lease: { holder, until: at + REFRESH_LEASE_MS } };
421
+ // Changed since it was read (a peer leased or renewed it, or the owner signed in again): read it again.
422
+ const mine = await this.swap(bytes, leased);
423
+ if (!mine)
424
+ continue;
425
+ return this.renewUnder(leased, mine);
426
+ }
427
+ }
428
+ /** The renewal itself, under this holder's lease on `row` (sealed as `bytes`). Every write back is a compare-and-set
429
+ * against the leased row, so a sign-out or a new sign-in meanwhile is never overwritten: ours is dropped. */
430
+ async renewUnder(row, bytes) {
431
+ const { lease: _, ...bare } = row;
432
+ const { openaiProvider } = await import("@earendil-works/pi-ai/providers/openai");
433
+ let next;
434
+ try {
435
+ next = (await openaiProvider().auth.oauth.refresh(bare.credential, AbortSignal.timeout(REFRESH_CALL_MS)));
436
+ }
437
+ catch (error) {
438
+ if (!refusedForGood(error)) {
439
+ // A fault at OpenAI, or none reached: the token is unspent, so the lease is given back for the next try. Sent
440
+ // with no answer read (a timeout, a lost connection): it may be spent, so the lease is held to its end, and no
441
+ // one sends it again sooner.
442
+ if (unspent(error))
443
+ await this.swap(bytes, bare).catch(() => undefined);
444
+ throw new PlanUnavailable(RENEW_LATER);
445
+ }
446
+ const expired = { ...bare, state: "expired" };
447
+ if (await this.swap(bytes, expired)) {
448
+ this.#snapshot = expired;
449
+ this.#deps.log?.({ chatgpt: "expired" });
450
+ await this.#deps.changed?.();
451
+ throw new PlanUnavailable(EXPIRED);
452
+ }
453
+ return this.adopt();
454
+ }
455
+ const renewed = { ...bare, credential: { ...bare.credential, ...next } };
456
+ this.hold(renewed.credential);
457
+ if (await this.swap(bytes, renewed)) {
458
+ this.#snapshot = renewed;
459
+ return renewed.credential.access;
460
+ }
461
+ // The owner signed out or in again while OpenAI renewed it: the new pair is the sign-in's no longer, and no one
462
+ // holds it but this renewal, so it is revoked here, never handed out.
463
+ await this.revoke(renewed.credential);
464
+ return this.adopt();
465
+ }
466
+ /** After a renewal whose write back lost its compare-and-set (the owner signed out or in again meanwhile): its result
467
+ * is dropped, and the row's state wins. */
468
+ async adopt() {
469
+ const now = await this.read();
470
+ this.#snapshot = now;
471
+ if (!now)
472
+ throw new PlanUnavailable(SIGNED_OUT);
473
+ if (now.state === "expired")
474
+ throw new PlanUnavailable(EXPIRED);
475
+ if (this.fresh(now))
476
+ return now.credential.access;
477
+ throw new PlanUnavailable(RENEW_LATER);
478
+ }
479
+ /** Signs out: any sign-in waiting cancelled (one past its browser step waited for: it drops and revokes its credential),
480
+ * then the row removed only while it still holds the bytes read (SealedKeys.removeIf; a renewal that wrote back
481
+ * meanwhile is read and removed in turn), and the pair it held revoked at OpenAI (its documented revocation endpoint,
482
+ * with the refresh token). The row goes whatever the revocation says. `revoked`: nothing of the sign-in is left alive
483
+ * at OpenAI as far as it can tell: none was signed in, or OpenAI confirmed the revocation and no renewal was out under
484
+ * a live lease (that renewal revokes the pair it gets when its write back finds the row gone, but OpenAI's word on it
485
+ * is not this answer's to give). */
486
+ async signOut() {
487
+ this.#droppedUnconfirmed = false;
488
+ this.#epoch += 1;
489
+ const finishing = this.#pending;
490
+ this.cancel();
491
+ await finishing?.result.catch(() => undefined);
492
+ // A sign-in past its browser step, dropped by this sign-out (keep), whose revocation OpenAI didn't confirm.
493
+ let revoked = !this.#droppedUnconfirmed;
494
+ for (;;) {
495
+ const bytes = await this.#deps.store.sealedKeys.get(CHATGPT_PLAN_ROW);
496
+ if (bytes === undefined)
497
+ break;
498
+ const row = this.open(bytes);
499
+ const renewing = row?.lease !== undefined && row.lease.until > (await this.storeNow());
500
+ if (!(await this.#deps.store.sealedKeys.removeIf(CHATGPT_PLAN_ROW, bytes)))
501
+ continue;
502
+ // A row that does not open (sealed under another key) is removed, its tokens beyond reach to revoke.
503
+ const removed = row ? (await this.revoke(row.credential)) && !renewing : false;
504
+ revoked = revoked && removed;
505
+ break;
506
+ }
507
+ this.#snapshot = undefined;
508
+ this.#deps.log?.({ chatgpt: "signed_out", revoked: String(revoked) });
509
+ await this.#deps.changed?.();
510
+ return { revoked };
511
+ }
512
+ /** `credential`'s session revoked at OpenAI (its documented revocation endpoint, with the refresh token): whether OpenAI
513
+ * confirmed it. The endpoint is taken from OpenAI's discovery document only when it is https on auth.openai.com, so a
514
+ * refresh token goes nowhere else. Never throws. */
515
+ async revoke(credential) {
516
+ try {
517
+ const config = (await (await fetch(OPENID_CONFIGURATION, { signal: AbortSignal.timeout(5_000) })).json());
518
+ const endpoint = typeof config.revocation_endpoint === "string" ? new URL(config.revocation_endpoint) : undefined;
519
+ if (endpoint?.protocol !== "https:" || endpoint.host !== new URL(OPENID_CONFIGURATION).host)
520
+ return false;
521
+ const response = await fetch(endpoint, { method: "POST", headers: { "content-type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ token: credential.refresh, token_type_hint: "refresh_token", client_id: credential.clientId }), signal: AbortSignal.timeout(5_000) });
522
+ return response.ok;
523
+ }
524
+ catch {
525
+ return false;
526
+ }
527
+ }
528
+ /** Stops the sign-in waiting, at the server's close. */
529
+ close() {
530
+ this.cancel();
531
+ }
532
+ }
533
+ /** For a run on a plan model (`model`, the one its claim chose): the plan's token read once before anything starts, so a
534
+ * sign-in that is gone, or that OpenAI refuses to renew, fails the run at once, in words (PlanUnavailable). */
535
+ export async function planBeforeRun(env, model) {
536
+ if (model?.provider !== PLAN_PROVIDER)
537
+ return;
538
+ const plan = planOf(env);
539
+ if (!plan)
540
+ throw new PlanUnavailable(SIGNED_OUT);
541
+ await plan.token();
542
+ }
543
+ /** A runner's reader of the plan over its store, loaded now: none when the server holds no sign-in. */
544
+ export async function planReaderOf(store, sealKey) {
545
+ if (!sealKey)
546
+ return undefined;
547
+ const plan = await new ChatGPTPlan({ store, sealKey }).load();
548
+ return plan.state === "signed_out" ? undefined : plan;
549
+ }
package/dist/cli.js CHANGED
@@ -25,7 +25,7 @@ surviveClosedPipes();
25
25
  const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--faux-github] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--learning-budget BYTES] [--grade-model MODEL] [--no-runner]
26
26
  agentrun-serve reset-password [--data DIR]
27
27
  agentrun-serve validate-template DIR
28
- agentrun-serve eval-template DIR [--case NAME ...] [--runs N] [--server URL] [--grader-model PROVIDER/MODEL] [--report FILE] [--faux MODULE]
28
+ agentrun-serve eval-template DIR [--case NAME ...] [--runs N] [--server URL | --on-data DIR] [--grader-model PROVIDER/MODEL] [--report FILE] [--faux MODULE]
29
29
  agentrun-serve import [--data DIR] [--from claude-code,codex,pi] [--dry-run] [--include-deleted] [--all] [--verbose] [--port N]
30
30
  agentrun-serve runner --data DIR [--loops N] [--drain-timeout D] [--name NAME]
31
31
  agentrun-serve runner --check --data DIR [--name NAME]
@@ -74,7 +74,9 @@ to AGENT_MODEL_FAST or AGENT_MODEL_STRONG, each falling back to AGENT_MODEL) is
74
74
  keys from the environment, or, with AGENT_MODEL_BASE_URL, by that one OpenAI Responses gateway (AGENT_MODEL_API_KEY when
75
75
  it needs a key). AGENTRUN_TOKEN, when set, is the token in place of DIR/.token's (a DIR/.token from an earlier start is removed), and is never printed; DIR/.token's is
76
76
  printed only by the start that made it. AGENTRUN_PUBLIC_URL, when set, is the address people open (a container's
77
- published port, or a proxy's URL), and the link printed uses it; with none, Render's RENDER_EXTERNAL_URL is. stdout gets one line per request, per run start and
77
+ published port, or a proxy's URL), and the link printed uses it; with none, Render's RENDER_EXTERNAL_URL is.
78
+ AGENTRUN_FREE_MODEL_REQUESTS (default 60) is the most requests on free models ($0 in the catalog) a run makes, capped
79
+ or not (ChatGPT-plan requests don't count): the next is not sent and the run fails, spend_cap_reached. stdout gets one line per request, per run start and
78
80
  end, and per refused credential; AGENTRUN_LOG=quiet leaves out the request lines.
79
81
 
80
82
  AGENTRUN_API_ONLY=1 serves the run routes alone, for a server behind its caller's backend: a run's launch, read, list,
@@ -105,11 +107,24 @@ session found, those imported before included, and the address to open the conso
105
107
  \`agentrun-serve eval-template DIR\` runs a template package's eval cases (all, or each --case) as real runs of its agent
106
108
  and grades each run with the case's graders (templates/README.md, "Running the evals"). By default on a server of its
107
109
  own in this process, over a temp data directory removed at the end, so it never touches your server; --server URL runs
108
- them on that server instead, its token in AGENTRUN_API_KEY, and archives the agents it made. --runs N runs each case N
110
+ them on that server instead, its token in AGENTRUN_API_KEY, and archives the agents it made. --on-data DIR runs its own
111
+ server on DIR, a stopped server's data folder, so the runs use what that server keeps (its ChatGPT sign-in) and a case's
112
+ fakes (its clock, its mailbox) still bind; it archives the agents it made there and leaves the folder and its settings,
113
+ and is refused while another server holds DIR, when DIR has enabled triggers or runs not ended, or for an email case
114
+ when DIR's server keeps an email account. --runs N runs each case N
109
115
  times in place of its own count; --grader-model is the llm graders' model (default: the server's); --faux answers every
110
116
  model request from MODULE, as the server's --faux does. Progress goes to stderr, a summary to stdout, the whole report
111
117
  as JSON to --report FILE. Exit 0 when every case passed, 1 when one failed, 2 when the flags, the package or a case are
112
118
  wrong and nothing ran. Real runs cost money: each case's prompt.md caps each of its runs (max_cost_usd).`;
119
+ if (process.argv[2] === "remote-bridge") {
120
+ const { runRemoteWorkerBridge } = await import("./native/remote-worker-bridge.js");
121
+ await runRemoteWorkerBridge();
122
+ process.exit(0);
123
+ }
124
+ if (process.argv[2] === "native") {
125
+ const { nativeMain } = await import("./native/cli.js");
126
+ process.exit(await nativeMain(process.argv.slice(3)));
127
+ }
113
128
  if (process.argv[2] === "reset-password") {
114
129
  let dir;
115
130
  try {
@@ -151,12 +166,12 @@ if (process.argv[2] === "validate-template") {
151
166
  // 0: every case passed; 1: one failed; 2: the flags, the package or a case is wrong, and nothing ran. --data is taken and
152
167
  // ignored, as validate-template's is: the npx launcher hands every server command one, and an eval's store is a temp one.
153
168
  if (process.argv[2] === "eval-template") {
154
- const { CaseError, evalTemplate, exitCodeOf, markdownReport } = await import("./template-eval.js");
169
+ const { CaseError, evalTemplate, exitCodeOf, markdownReport, ON_DATA_WITH_SERVER } = await import("./template-eval.js");
155
170
  const { PackageError } = await import("./templates.js");
156
171
  const usage = (message) => (console.error(`agentrun-serve eval-template: ${message}\n\n${USAGE}`), process.exit(2));
157
172
  const read = () => {
158
173
  try {
159
- return parseArgs({ args: process.argv.slice(3), allowPositionals: true, options: { case: { type: "string", multiple: true, default: [] }, runs: { type: "string" }, server: { type: "string" }, "grader-model": { type: "string" }, report: { type: "string" }, faux: { type: "string" }, data: { type: "string" } } });
174
+ return parseArgs({ args: process.argv.slice(3), allowPositionals: true, options: { case: { type: "string", multiple: true, default: [] }, runs: { type: "string" }, server: { type: "string" }, "grader-model": { type: "string" }, report: { type: "string" }, faux: { type: "string" }, data: { type: "string" }, "on-data": { type: "string" } } });
160
175
  }
161
176
  catch (error) {
162
177
  return usage(error.message);
@@ -171,6 +186,10 @@ if (process.argv[2] === "eval-template") {
171
186
  usage("--server takes the server's http(s) address.");
172
187
  if (given.server !== undefined && given.faux !== undefined)
173
188
  usage("--faux is the model of the server it starts itself, and --server names another server.");
189
+ if (given.server !== undefined && given["on-data"] !== undefined)
190
+ usage(`${ON_DATA_WITH_SERVER}.`);
191
+ if (given["on-data"] === "")
192
+ usage("--on-data takes a server's data folder.");
174
193
  const token = given.server === undefined ? undefined : secret("AGENTRUN_API_KEY") || secret("AGENTRUN_TOKEN");
175
194
  if (given.server !== undefined && !token)
176
195
  usage("--server needs that server's token in AGENTRUN_API_KEY.");
@@ -214,7 +233,8 @@ if (process.argv[2] === "eval-template") {
214
233
  const report = await evalTemplate({
215
234
  dir: resolve(positionals[0]), cases: given.case, ...(given.runs !== undefined ? { runs: Number(given.runs) } : {}),
216
235
  ...(given.server !== undefined ? { server: { baseUrl: given.server, token: token } } : {}), ...(given["grader-model"] !== undefined ? { graderModel: given["grader-model"] } : {}),
217
- ...(given.faux !== undefined ? { serve: { faux: resolve(given.faux) } } : {}), log: (line) => console.error(line), signal: stop.signal,
236
+ ...(given.faux !== undefined ? { serve: { faux: resolve(given.faux) } } : {}), ...(given["on-data"] !== undefined ? { data: resolve(given["on-data"]) } : {}),
237
+ log: (line) => console.error(line), signal: stop.signal,
218
238
  });
219
239
  // A stop asked as the eval ended still stops it: no report, 130.
220
240
  stop.signal.throwIfAborted();