@parcha/agentrun-serve 0.1.0-beta.38 → 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 (410) hide show
  1. package/CHANGELOG.md +418 -0
  2. package/README.md +325 -124
  3. package/dist/adapters.d.ts +4 -1
  4. package/dist/adapters.js +4 -2
  5. package/dist/agent-rows.d.ts +0 -2
  6. package/dist/agents-store.d.ts +5 -5
  7. package/dist/agents-store.js +14 -14
  8. package/dist/bash-read-only.js +2 -1
  9. package/dist/cap-short.d.ts +12 -0
  10. package/dist/cap-short.js +60 -0
  11. package/dist/cap.d.ts +3 -10
  12. package/dist/cap.js +2 -5
  13. package/dist/catalog.d.ts +0 -5
  14. package/dist/catalog.js +1 -5
  15. package/dist/chatgpt-plan.d.ts +163 -0
  16. package/dist/chatgpt-plan.js +549 -0
  17. package/dist/cli.js +26 -6
  18. package/dist/composio-preset.d.ts +8 -0
  19. package/dist/composio-preset.js +8 -7
  20. package/dist/composio-triggers.d.ts +113 -0
  21. package/dist/composio-triggers.js +411 -0
  22. package/dist/computer-calls.js +2 -2
  23. package/dist/computer-commands.d.ts +2 -0
  24. package/dist/computer-commands.js +7 -3
  25. package/dist/computer-live.d.ts +7 -2
  26. package/dist/computer-live.js +9 -5
  27. package/dist/computer-routes.d.ts +2 -2
  28. package/dist/computer-routes.js +2 -2
  29. package/dist/computer-setting.d.ts +3 -3
  30. package/dist/computer-setting.js +5 -5
  31. package/dist/computer-view.d.ts +15 -0
  32. package/dist/computer-view.js +16 -2
  33. package/dist/computer-viewer.js +14 -1
  34. package/dist/computers.d.ts +5 -2
  35. package/dist/computers.js +9 -5
  36. package/dist/console/assets/index-BNhZs-jp.css +1 -0
  37. package/dist/console/assets/index-BQv5aOGB.js +700 -0
  38. package/dist/console/index.html +2 -2
  39. package/dist/console-links.js +3 -3
  40. package/dist/decision-cap.d.ts +2 -5
  41. package/dist/decision-cap.js +3 -6
  42. package/dist/decision-rows.js +11 -11
  43. package/dist/email/account.d.ts +84 -0
  44. package/dist/email/account.js +159 -0
  45. package/dist/email/answer.d.ts +10 -0
  46. package/dist/email/answer.js +182 -0
  47. package/dist/email/email-faux.d.ts +95 -0
  48. package/dist/email/email-faux.js +849 -0
  49. package/dist/email/labels.d.ts +1 -0
  50. package/dist/email/labels.js +84 -0
  51. package/dist/email/mail.d.ts +186 -0
  52. package/dist/email/mail.js +380 -0
  53. package/dist/email/names.d.ts +20 -0
  54. package/dist/email/names.js +40 -0
  55. package/dist/email/routes.d.ts +9 -0
  56. package/dist/email/routes.js +50 -0
  57. package/dist/email/tools.d.ts +20 -0
  58. package/dist/email/tools.js +517 -0
  59. package/dist/environment.d.ts +17 -2
  60. package/dist/environment.js +36 -8
  61. package/dist/errors.d.ts +6 -0
  62. package/dist/errors.js +12 -0
  63. package/dist/eval-mailbox.d.ts +103 -0
  64. package/dist/eval-mailbox.js +236 -0
  65. package/dist/graph-view.d.ts +9 -2
  66. package/dist/graph-view.js +6 -2
  67. package/dist/harness-install.d.ts +28 -2
  68. package/dist/harness-install.js +147 -59
  69. package/dist/harness-opencode/adapter.js +2 -26
  70. package/dist/harness-opencode/facts.js +5 -2
  71. package/dist/harness-opencode/host/policy.d.ts +2 -0
  72. package/dist/harness-opencode/host/policy.js +10 -5
  73. package/dist/harness-opencode/index.d.ts +1 -1
  74. package/dist/harness-opencode/index.js +1 -1
  75. package/dist/harness-opencode/versions.d.ts +6 -0
  76. package/dist/harness-opencode/versions.js +6 -0
  77. package/dist/harness-table.js +8 -5
  78. package/dist/harness.d.ts +12 -0
  79. package/dist/harness.js +15 -3
  80. package/dist/hosted-search.d.ts +3 -1
  81. package/dist/hosted-search.js +51 -11
  82. package/dist/import-sources.d.ts +1 -1
  83. package/dist/import-sources.js +3 -3
  84. package/dist/import.d.ts +21 -0
  85. package/dist/import.js +186 -1
  86. package/dist/key-check.d.ts +0 -2
  87. package/dist/key-check.js +3 -4
  88. package/dist/key-refusal.d.ts +8 -2
  89. package/dist/key-refusal.js +16 -13
  90. package/dist/learn/check.d.ts +18 -3
  91. package/dist/learn/check.js +328 -3
  92. package/dist/learn/compile.d.ts +9 -2
  93. package/dist/learn/compile.js +52 -16
  94. package/dist/learn/grade.d.ts +4 -0
  95. package/dist/learn/grade.js +4 -1
  96. package/dist/learn/promote.d.ts +106 -51
  97. package/dist/learn/promote.js +82 -189
  98. package/dist/learn/refit.d.ts +21 -12
  99. package/dist/learn/refit.js +51 -23
  100. package/dist/learn/replay-calls.js +1 -1
  101. package/dist/learn/skills.d.ts +2 -7
  102. package/dist/learn/skills.js +28 -14
  103. package/dist/learned-nodes.d.ts +15 -7
  104. package/dist/learned-nodes.js +29 -5
  105. package/dist/learned-workflow.d.ts +41 -31
  106. package/dist/learned-workflow.js +122 -63
  107. package/dist/learning-batch.js +3 -3
  108. package/dist/learning-cost.d.ts +26 -8
  109. package/dist/learning-cost.js +17 -7
  110. package/dist/learning-routes.d.ts +2 -4
  111. package/dist/learning-routes.js +20 -3
  112. package/dist/learning-words.d.ts +1 -1
  113. package/dist/learning-words.js +4 -1
  114. package/dist/learning.d.ts +5 -5
  115. package/dist/link-check.d.ts +27 -0
  116. package/dist/link-check.js +164 -0
  117. package/dist/local-models.d.ts +33 -2
  118. package/dist/local-models.js +43 -5
  119. package/dist/mcp-pin-first.js +6 -0
  120. package/dist/mcp-secret-writes.js +3 -0
  121. package/dist/mcp-servers-store.d.ts +25 -16
  122. package/dist/mcp-servers-store.js +23 -3
  123. package/dist/model-form.d.ts +11 -0
  124. package/dist/model-form.js +17 -1
  125. package/dist/model.d.ts +26 -6
  126. package/dist/model.js +126 -18
  127. package/dist/monid.d.ts +26 -31
  128. package/dist/monid.js +84 -79
  129. package/dist/native/binding.d.ts +13 -0
  130. package/dist/native/binding.js +57 -0
  131. package/dist/native/cli.d.ts +2 -0
  132. package/dist/native/cli.js +48 -0
  133. package/dist/native/connection.d.ts +8 -0
  134. package/dist/native/connection.js +94 -0
  135. package/dist/native/context.d.ts +6 -0
  136. package/dist/native/context.js +22 -0
  137. package/dist/native/discovery.d.ts +27 -0
  138. package/dist/native/discovery.js +404 -0
  139. package/dist/native/environment.d.ts +4 -0
  140. package/dist/native/environment.js +18 -0
  141. package/dist/native/history.d.ts +20 -0
  142. package/dist/native/history.js +147 -0
  143. package/dist/native/instructions.d.ts +21 -0
  144. package/dist/native/instructions.js +173 -0
  145. package/dist/native/remote-worker-bridge.d.ts +3 -0
  146. package/dist/native/remote-worker-bridge.js +278 -0
  147. package/dist/native/remote.d.ts +187 -0
  148. package/dist/native/remote.js +492 -0
  149. package/dist/native/runtime.d.ts +17 -0
  150. package/dist/native/runtime.js +316 -0
  151. package/dist/native/runtimes.d.ts +66 -0
  152. package/dist/native/runtimes.js +41 -0
  153. package/dist/native/schema.d.ts +46 -0
  154. package/dist/native/schema.js +41 -0
  155. package/dist/native/types.d.ts +87 -0
  156. package/dist/native/types.js +1 -0
  157. package/dist/observation/http.d.ts +4 -0
  158. package/dist/observation/http.js +140 -0
  159. package/dist/observation/observer.d.ts +301 -0
  160. package/dist/observation/observer.js +919 -0
  161. package/dist/observation/schema.d.ts +52 -0
  162. package/dist/observation/schema.js +154 -0
  163. package/dist/openapi.d.ts +1 -0
  164. package/dist/openapi.js +394 -85
  165. package/dist/paid-calls.d.ts +8 -3
  166. package/dist/paid-calls.js +6 -2
  167. package/dist/place-offers.d.ts +4 -8
  168. package/dist/place-offers.js +4 -9
  169. package/dist/port-models.d.ts +7 -2
  170. package/dist/port-models.js +5 -2
  171. package/dist/print.d.ts +4 -2
  172. package/dist/print.js +4 -3
  173. package/dist/propose.d.ts +1 -2
  174. package/dist/propose.js +10 -1
  175. package/dist/provider.d.ts +5 -1
  176. package/dist/provider.js +8 -0
  177. package/dist/push-handler.d.ts +3 -2
  178. package/dist/push-handler.js +20 -6
  179. package/dist/refusal-words.d.ts +11 -0
  180. package/dist/refusal-words.js +13 -2
  181. package/dist/run-launch.d.ts +10 -1
  182. package/dist/run-launch.js +11 -4
  183. package/dist/run-learning-served.d.ts +75 -2
  184. package/dist/run-manifest.d.ts +3 -0
  185. package/dist/run-manifest.js +13 -1
  186. package/dist/run-reads-over-store.d.ts +3 -3
  187. package/dist/run-reads-over-store.js +13 -10
  188. package/dist/run-timeline-served.d.ts +3 -2
  189. package/dist/run-timeline-served.js +8 -9
  190. package/dist/run-view.d.ts +42 -35
  191. package/dist/run-view.js +79 -44
  192. package/dist/runnable.d.ts +13 -5
  193. package/dist/runnable.js +69 -60
  194. package/dist/runner/adapter-loop.d.ts +42 -11
  195. package/dist/runner/adapter-loop.js +651 -247
  196. package/dist/runner/adapter-run-spec.d.ts +37 -12
  197. package/dist/runner/adapter-run-spec.js +139 -106
  198. package/dist/runner/adapters/pi.d.ts +24 -0
  199. package/dist/runner/adapters/pi.js +59 -9
  200. package/dist/runner/beside.d.ts +3 -1
  201. package/dist/runner/beside.js +24 -8
  202. package/dist/runner/claim-secrets.d.ts +3 -1
  203. package/dist/runner/claim-secrets.js +28 -4
  204. package/dist/runner/cli-run-spec.d.ts +30 -0
  205. package/dist/runner/cli-run-spec.js +94 -50
  206. package/dist/runner/computer-channel.d.ts +5 -2
  207. package/dist/runner/computer-channel.js +3 -2
  208. package/dist/runner/computer-journal.d.ts +6 -0
  209. package/dist/runner/computer-journal.js +8 -10
  210. package/dist/runner/conformance/harness.js +6 -3
  211. package/dist/runner/end-of-run.d.ts +2 -0
  212. package/dist/runner/end-of-run.js +3 -1
  213. package/dist/runner/feedback-round.d.ts +40 -13
  214. package/dist/runner/feedback-round.js +64 -16
  215. package/dist/runner/harness-loops.js +17 -0
  216. package/dist/runner/journal-kinds.d.ts +37 -13
  217. package/dist/runner/journal-kinds.js +9 -5
  218. package/dist/runner/learning-dispatch.d.ts +3 -2
  219. package/dist/runner/learning-dispatch.js +6 -6
  220. package/dist/runner/learning-end.d.ts +4 -0
  221. package/dist/runner/learning-end.js +64 -36
  222. package/dist/runner/learning-factory.d.ts +3 -0
  223. package/dist/runner/learning-factory.js +8 -2
  224. package/dist/runner/learning-loop.d.ts +2 -0
  225. package/dist/runner/learning-loop.js +19 -4
  226. package/dist/runner/loop.d.ts +18 -0
  227. package/dist/runner/loop.js +34 -0
  228. package/dist/runner/main.d.ts +6 -1
  229. package/dist/runner/main.js +26 -4
  230. package/dist/runner/mcp-run.d.ts +4 -1
  231. package/dist/runner/mcp-run.js +11 -5
  232. package/dist/runner/meta-tools.d.ts +10 -3
  233. package/dist/runner/meta-tools.js +112 -36
  234. package/dist/runner/metrics.d.ts +80 -21
  235. package/dist/runner/metrics.js +114 -39
  236. package/dist/runner/model-route.d.ts +12 -3
  237. package/dist/runner/model-route.js +139 -18
  238. package/dist/runner/monid-run.d.ts +8 -6
  239. package/dist/runner/monid-run.js +117 -43
  240. package/dist/runner/native-loop.d.ts +11 -0
  241. package/dist/runner/native-loop.js +438 -0
  242. package/dist/runner/promotion.d.ts +74 -8
  243. package/dist/runner/promotion.js +365 -124
  244. package/dist/runner/redact.js +3 -0
  245. package/dist/runner/reflect-hook.js +9 -0
  246. package/dist/runner/runner.d.ts +7 -1
  247. package/dist/runner/runner.js +8 -4
  248. package/dist/runner/sdk-loop.d.ts +7 -0
  249. package/dist/runner/sdk-loop.js +470 -0
  250. package/dist/runner/spec-holds.d.ts +16 -2
  251. package/dist/runner/spec-holds.js +42 -14
  252. package/dist/runner/store-secrets.js +17 -2
  253. package/dist/runner/workflow-first.d.ts +30 -20
  254. package/dist/runner/workflow-first.js +22 -32
  255. package/dist/runner/workflow-loop.d.ts +1 -1
  256. package/dist/runner/workflow-loop.js +18 -12
  257. package/dist/runner/workflow-spec.d.ts +4 -1
  258. package/dist/runner/workflow-spec.js +56 -45
  259. package/dist/runs-over-store.d.ts +30 -2
  260. package/dist/runs-over-store.js +46 -14
  261. package/dist/sdk/runs.d.ts +115 -0
  262. package/dist/sdk/runs.js +422 -0
  263. package/dist/sdk/schema.d.ts +175 -0
  264. package/dist/sdk/schema.js +138 -0
  265. package/dist/sdk/workflows.d.ts +22 -0
  266. package/dist/sdk/workflows.js +39 -0
  267. package/dist/secrets.d.ts +2 -0
  268. package/dist/secrets.js +19 -1
  269. package/dist/server.d.ts +48 -32
  270. package/dist/server.js +554 -130
  271. package/dist/skill-route.d.ts +3 -0
  272. package/dist/skill-route.js +16 -0
  273. package/dist/skills/agentrun-serve/SKILL.md +368 -0
  274. package/dist/stats.d.ts +10 -10
  275. package/dist/store/agent-body.d.ts +12 -8
  276. package/dist/store/agent-body.js +9 -4
  277. package/dist/store/index.d.ts +1 -1
  278. package/dist/store/native-command-owner.d.ts +10 -0
  279. package/dist/store/native-command-owner.js +47 -0
  280. package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
  281. package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
  282. package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
  283. package/dist/store/postgres/store.js +3 -0
  284. package/dist/store/schema.d.ts +7 -0
  285. package/dist/store/schema.js +20 -1
  286. package/dist/store/sqlite/run-patch.d.ts +8 -1
  287. package/dist/store/sqlite/run-patch.js +14 -3
  288. package/dist/store/sqlite/store.js +133 -18
  289. package/dist/store/store.d.ts +52 -7
  290. package/dist/store-reads/analytics.d.ts +7 -7
  291. package/dist/store-reads/analytics.js +23 -5
  292. package/dist/store-reads/cap.js +8 -6
  293. package/dist/store-reads/journal.d.ts +5 -0
  294. package/dist/store-reads/journal.js +85 -41
  295. package/dist/store-reads/learning.d.ts +85 -5
  296. package/dist/store-reads/learning.js +45 -17
  297. package/dist/store-reads/runs.d.ts +5 -0
  298. package/dist/store-reads/runs.js +3 -2
  299. package/dist/store-view.js +75 -21
  300. package/dist/template-eval.d.ts +73 -11
  301. package/dist/template-eval.js +535 -75
  302. package/dist/templates.d.ts +70 -20
  303. package/dist/templates.js +191 -34
  304. package/dist/text-urls.d.ts +38 -0
  305. package/dist/text-urls.js +170 -0
  306. package/dist/timeline/index.d.ts +3 -2
  307. package/dist/timeline/index.js +3 -2
  308. package/dist/timeline/labels.d.ts +5 -2
  309. package/dist/timeline/labels.js +29 -6
  310. package/dist/timeline/origin.d.ts +1 -1
  311. package/dist/timeline/origin.js +2 -2
  312. package/dist/timeline/render-text.js +1 -1
  313. package/dist/timeline/timeline.d.ts +66 -4
  314. package/dist/timeline/timeline.js +160 -30
  315. package/dist/timeline/util.d.ts +5 -0
  316. package/dist/timeline/util.js +44 -8
  317. package/dist/timeline/web-calls.d.ts +17 -0
  318. package/dist/timeline/web-calls.js +106 -0
  319. package/dist/tool-gate.d.ts +42 -42
  320. package/dist/tool-gate.js +97 -91
  321. package/dist/tool-list.d.ts +4 -1
  322. package/dist/tool-list.js +8 -1
  323. package/dist/tool-names.d.ts +18 -13
  324. package/dist/tool-names.js +19 -17
  325. package/dist/tool-plane.d.ts +17 -13
  326. package/dist/tool-plane.js +12 -5
  327. package/dist/tools.d.ts +44 -16
  328. package/dist/tools.js +28 -28
  329. package/dist/trigger-adapter.d.ts +85 -5
  330. package/dist/trigger-adapter.js +6 -0
  331. package/dist/trigger-adapters.js +3 -1
  332. package/dist/trigger-composio.d.ts +10 -0
  333. package/dist/trigger-composio.js +122 -0
  334. package/dist/trigger-email.d.ts +4 -0
  335. package/dist/trigger-email.js +228 -0
  336. package/dist/trigger-signatures.d.ts +6 -10
  337. package/dist/trigger-signatures.js +16 -16
  338. package/dist/trigger-targets.d.ts +1 -1
  339. package/dist/trigger-targets.js +4 -3
  340. package/dist/trigger-webhook.js +6 -4
  341. package/dist/triggers.d.ts +94 -9
  342. package/dist/triggers.js +263 -62
  343. package/dist/uploads.d.ts +9 -0
  344. package/dist/uploads.js +27 -0
  345. package/dist/validate.js +1 -7
  346. package/dist/web-fake.d.ts +56 -0
  347. package/dist/web-fake.js +102 -0
  348. package/dist/web-fetch-direct.d.ts +3 -0
  349. package/dist/web-fetch-direct.js +4 -1
  350. package/dist/web-fetch.d.ts +5 -1
  351. package/dist/web-fetch.js +8 -31
  352. package/dist/web-search.d.ts +51 -2
  353. package/dist/web-search.js +116 -18
  354. package/dist/webhooks.d.ts +2 -1
  355. package/dist/webhooks.js +5 -1
  356. package/dist/workflow/node-runner.js +10 -2
  357. package/dist/workspace/archil-claim.d.ts +3 -0
  358. package/dist/workspace/archil-claim.js +9 -2
  359. package/dist/workspace/computer-deps.d.ts +22 -9
  360. package/dist/workspace/computer-deps.js +78 -37
  361. package/dist/workspace/computer-for-claim.d.ts +54 -4
  362. package/dist/workspace/computer-for-claim.js +179 -39
  363. package/dist/workspace/computer-janitor.d.ts +10 -3
  364. package/dist/workspace/computer-janitor.js +96 -29
  365. package/dist/workspace/computer-kept.d.ts +82 -0
  366. package/dist/workspace/computer-kept.js +147 -0
  367. package/dist/workspace/computer-mcp.js +4 -3
  368. package/dist/workspace/computer-ports.d.ts +23 -3
  369. package/dist/workspace/computer-ports.js +115 -5
  370. package/dist/workspace/index.d.ts +1 -2
  371. package/dist/workspace/index.js +1 -2
  372. package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
  373. package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
  374. package/dist/workspace/resolve-computer.d.ts +15 -3
  375. package/dist/workspace/resolve-computer.js +10 -7
  376. package/dist/workspace/revision-skills.d.ts +6 -2
  377. package/dist/workspace/revision-skills.js +12 -5
  378. package/dist/workspace/run-end-computers.d.ts +30 -0
  379. package/dist/workspace/run-end-computers.js +137 -0
  380. package/dist/workspace/run-tools.d.ts +28 -29
  381. package/dist/workspace/run-tools.js +29 -30
  382. package/dist/wrap-up.d.ts +19 -5
  383. package/dist/wrap-up.js +31 -4
  384. package/package.json +13 -9
  385. package/skills/agentrun-serve/SKILL.md +248 -10
  386. package/templates/README.md +117 -23
  387. package/templates/TOOLS.md +168 -0
  388. package/templates/code-review/agent.md +18 -4
  389. package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
  390. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
  391. package/templates/code-review/evals/other-repo/case.yaml +1 -1
  392. package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
  393. package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
  394. package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
  395. package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
  396. package/templates/code-review/skills/review/DEEP.md +2 -2
  397. package/templates/code-review/skills/review/REVIEWER.md +2 -2
  398. package/templates/code-review/skills/review/SKILL.md +7 -3
  399. package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
  400. package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
  401. package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
  402. package/templates/release-notes/evals/other-repo/case.yaml +1 -1
  403. package/dist/console/assets/index-CjqQirbo.css +0 -1
  404. package/dist/console/assets/index-b6-XY5A9.js +0 -576
  405. package/dist/host-calls.d.ts +0 -20
  406. package/dist/host-calls.js +0 -12
  407. package/dist/runner/adapters/pi-computer.d.ts +0 -9
  408. package/dist/runner/adapters/pi-computer.js +0 -51
  409. package/dist/workspace/computer-script.d.ts +0 -53
  410. package/dist/workspace/computer-script.js +0 -172
@@ -72,7 +72,8 @@ export type ConfineChild = (child: Readonly<{
72
72
  };
73
73
  /** What a run's adapter needs of serve: its model, the catalog that prices it as it prices pi's runs, the run's
74
74
  * confinement for the harness's own process, and the skills it loads itself (claude-agent's, codex's and opencode's,
75
- * which its own check took: skills.ts). */
75
+ * which its own check took: skills.ts), and the run's clock when a template eval case sets one (claude-agent's turn date
76
+ * reads it; absent, the real clock). */
76
77
  export type AdapterNeeds = {
77
78
  model: ModelRef;
78
79
  models: {
@@ -83,6 +84,8 @@ export type AdapterNeeds = {
83
84
  confine?: ConfineChild;
84
85
  skills?: readonly SkillFiles[];
85
86
  unpriced?: ReadonlySet<string>;
87
+ now?: () => Date;
88
+ zone?: string;
86
89
  };
87
90
  /** The ConfineChild that starts a child under `prefix` (the argv pi's commands start under, ending in "--"); none when
88
91
  * the run confines nothing (macOS), since an adapter refuses a confinement that adds nothing. */
package/dist/adapters.js CHANGED
@@ -291,7 +291,7 @@ export async function claudeOf(env, needs, load = loadClaude, sdkOf = (version,
291
291
  // order (the SDK before the CLI).
292
292
  await claude.verifyClaudeAgentCliAsync(sdk.cliPath);
293
293
  // The skills only when there are some: with none, the adapter keeps its Skill tool off.
294
- adapter = claude.claudeAgentAdapter({ model: { default: provider?.modelId ?? native.model.modelId }, provider: endpoint, price: priceOf(priced), log: harnessLog(claudeFacts.id, env), sdk: sdk.sdk, sdkVersion: sdk.sdkVersion, cliPath: sdk.cliPath, mcp: sdk.mcp, ...(needs.confine ? { confine: needs.confine } : {}), ...(needs.skills?.length ? { skills: needs.skills } : {}), ...nativeOptions(claudeFacts, env) });
294
+ adapter = claude.claudeAgentAdapter({ model: { default: provider?.modelId ?? native.model.modelId }, provider: endpoint, price: priceOf(priced), log: harnessLog(claudeFacts.id, env), sdk: sdk.sdk, sdkVersion: sdk.sdkVersion, cliPath: sdk.cliPath, mcp: sdk.mcp, ...(needs.confine ? { confine: needs.confine } : {}), ...(needs.skills?.length ? { skills: needs.skills } : {}), ...(needs.now ? { now: needs.now } : {}), ...(needs.zone ? { zone: needs.zone } : {}), ...nativeOptions(claudeFacts, env) });
295
295
  }
296
296
  catch (error) {
297
297
  // The adapter's own install line is a project's; here Claude Code is installed into the data's harnesses directory.
@@ -334,8 +334,10 @@ export async function codexOf(env, needs, load = () => import("@parcha/agentrun-
334
334
  // The id as the provider's endpoint names it (providerFor): a gateway's own name for the model as model.ts chose it,
335
335
  // whole (AGENT_MODEL_GATEWAY_IDS says whether it is provider-qualified), OpenAI's model id, which chooseModel has
336
336
  // already taken out of "openai/<id>", or OpenRouter's whole slug.
337
+ // On a ChatGPT plan: the plan's rules on its route (no output limit, no input count), billed to it, never priced here.
337
338
  const provider = providerFor(codexFacts.wire, env, needs.model, codexFacts.id);
338
- return codex.codexAdapter({ model: provider.modelId, provider: { origin: provider.origin, credential: provider.credential }, price: priceOf({ ...needs, model: provider.priceModel }), log: harnessLog(codexFacts.id, env), ...(nativeOptions(codexFacts, env).webSearch === "live" ? { webSearch: "live" } : {}), ...(needs.confine ? { confine: needs.confine } : {}), ...(needs.skills?.length ? { skills: needs.skills } : {}), ...(standIn ? { standIn } : binary ? { binary } : {}) });
339
+ const plan = provider.billing === "plan";
340
+ return codex.codexAdapter({ model: provider.modelId, provider: { origin: provider.origin, credential: provider.credential, ...(plan ? { plan } : {}), ...(provider.refused ? { refused: provider.refused } : {}) }, price: plan ? () => null : priceOf({ ...needs, model: provider.priceModel }), log: harnessLog(codexFacts.id, env), ...(nativeOptions(codexFacts, env).webSearch === "live" ? { webSearch: "live" } : {}), ...(needs.confine ? { confine: needs.confine } : {}), ...(needs.skills?.length ? { skills: needs.skills } : {}), ...(standIn ? { standIn } : binary ? { binary } : {}) });
339
341
  }
340
342
  /** opencode's adapter, from `load` (this server's own, src/harness-opencode; a test gives its own). Its model goes where
341
343
  * its wire's do (providerFor): serve's gateway (AGENT_MODEL_BASE_URL), OpenAI or OpenRouter, on the Responses API,
@@ -40,7 +40,6 @@ export type AgenticBody = {
40
40
  toolSettings?: Record<string, Record<string, string>>;
41
41
  approvals?: "never";
42
42
  maxCostUsd?: number;
43
- capMode?: string;
44
43
  inputSchema?: Record<string, unknown>;
45
44
  outputSchema?: Record<string, unknown>;
46
45
  checkout?: "pull_request";
@@ -55,7 +54,6 @@ export type WorkflowBody = {
55
54
  toolSettings?: Record<string, Record<string, string>>;
56
55
  approvals?: "never";
57
56
  maxCostUsd?: number;
58
- capMode?: string;
59
57
  };
60
58
  /** A revision, written once: `body.skills` maps a skill path to the SHA-256 of its text. */
61
59
  export type Revision = {
@@ -39,13 +39,11 @@ export declare function externalOf(agent: AgentRow, revision: RevisionRow | null
39
39
  version: string | null;
40
40
  }) | null;
41
41
  /** What a save's check stamps on the revision it let through: its MCP pin (the granted MCP tools as their servers listed
42
- * them at this save), when it grants any. */
43
- export type SaveStamp = {
44
- readonly mcpPin?: unknown;
45
- };
42
+ * them at this save) and its monid pin (monid.ts pinMonid), each when it grants any. */
43
+ export type SaveStamp = Pick<NewRevision, "mcpPin" | "monidPin">;
46
44
  /** A save's check (server.ts saveable): it sees the revision before anything is written, may refuse it, and answers what
47
45
  * to stamp on it. `on`: the revision this save is built on (an edit's: the agent's current one as this try read it, so a
48
- * retry on a newer one sees that one; null for a new agent), whose MCP pin a server that can't be listed keeps. */
46
+ * retry on a newer one sees that one; null for a new agent), whose pins carry what the save's grants did not change. */
49
47
  export type SaveCheck = (revision: NewRevision, on: RevisionRow | null) => Promise<SaveStamp | void>;
50
48
  /** The agent `id` as an entry, or null when there is no such agent: its row, its current revision (by the agent row's
51
49
  * current_revision), that revision's number (newest is the count), and the skill sizes. */
@@ -107,6 +105,7 @@ export declare function definitionOf(agent: AgentRow, revision: RevisionRow, ver
107
105
  /** The agent as the contract shows it, with its current revision, its saved sign-ins (never a ref) and its run counts
108
106
  * (E3's, passed in). `origin`: where its console page is. */
109
107
  export declare function agentView(entry: AgentEntry, origin: string, extra?: {
108
+ nativeStatus?: import("./native/types.js").NativeBinding;
110
109
  signIns?: readonly object[];
111
110
  learning?: {
112
111
  pending: number;
@@ -154,6 +153,7 @@ export declare function agentView(entry: AgentEntry, origin: string, extra?: {
154
153
  external?: (ExternalRef & {
155
154
  version: string | null;
156
155
  }) | undefined;
156
+ native_status?: import("./native/types.js").NativeBinding | undefined;
157
157
  agent_id: string;
158
158
  };
159
159
  /** One revision as GET .../revisions lists it (the v2 shape: revision, version, parent, kind, current, note, created_at,
@@ -97,10 +97,7 @@ function revisionInputOf(definition, files) {
97
97
  // pin's arguments sorted) so two revisions that say the same are one body. The store never reimplements it.
98
98
  const set = toolSettingsOf(definition.tool_settings);
99
99
  const common = { skills: files, tools: definition.tools ?? [], ...harness, ...place, ...set };
100
- const capped = {
101
- ...(typeof definition.max_cost_usd === "number" && definition.max_cost_usd > 0 ? { maxCostUsd: definition.max_cost_usd } : {}),
102
- ...(typeof definition.cap_mode === "string" ? { capMode: definition.cap_mode } : {}),
103
- };
100
+ const capped = typeof definition.max_cost_usd === "number" && definition.max_cost_usd > 0 ? { maxCostUsd: definition.max_cost_usd } : {};
104
101
  // A workflow keeps its approvals too ("never": it runs unattended), so its call nodes are checked with them (runnable.ts,
105
102
  // permissionOf with the revision's approvals): a call node on a tool set to ask runs under never, as on main.
106
103
  if (isObject(definition.workflow))
@@ -109,6 +106,8 @@ function revisionInputOf(definition, files) {
109
106
  return {
110
107
  kind: "agentic",
111
108
  instructions: definition.instructions,
109
+ ...(definition.sdk !== undefined ? { sdk: definition.sdk } : {}),
110
+ ...(isObject(definition.native) ? { native: definition.native } : {}),
112
111
  ...(typeof definition.model === "string" ? { model: definition.model } : {}),
113
112
  ...(isObject(definition.model_tiers) ? { modelTiers: definition.model_tiers } : {}),
114
113
  ...(typeof definition.thinking === "string" ? { thinking: definition.thinking } : {}),
@@ -141,13 +140,13 @@ function checkPast(definition, current) {
141
140
  }
142
141
  /** Whether committing `next` would leave the agent's current revision unchanged: the same kind and body (skills are in the
143
142
  * body as their SHA-256, so equal files are an equal body — and equal pins an equal body, keys sorted by the validator),
144
- * and the same MCP pin: a save after a server changed a granted tool is a new revision, pinned anew (that is how a person
145
- * takes a server's changed tools). */
143
+ * and the same pins: a save after a server changed a granted tool (or monid an endpoint) is a new revision, pinned anew
144
+ * (that is how a person takes a server's changed tools). */
146
145
  function sameRevision(current, next) {
147
- return current.kind === next.kind && canonical(current.body) === canonical(next.body) && canonical(current.mcpPin ?? null) === canonical(next.mcpPin ?? null);
146
+ return current.kind === next.kind && canonical(current.body) === canonical(next.body) && canonical(current.mcpPin ?? null) === canonical(next.mcpPin ?? null) && canonical(current.monidPin ?? null) === canonical(next.monidPin ?? null);
148
147
  }
149
148
  /** `revision` with what its check stamped. */
150
- const stamped = (revision, stamp) => (stamp?.mcpPin === undefined ? revision : { ...revision, mcpPin: stamp.mcpPin });
149
+ const stamped = (revision, stamp) => ({ ...revision, ...(stamp?.mcpPin === undefined ? {} : { mcpPin: stamp.mcpPin }), ...(stamp?.monidPin === undefined ? {} : { monidPin: stamp.monidPin }) });
151
150
  /** The byte size of each of the revision's skill files, by the SHA-256 the body keeps (from the texts on its row). */
152
151
  function sizesOf(revision) {
153
152
  const sizes = new Map();
@@ -190,7 +189,7 @@ export async function createAgent(store, { definition, skills = {}, note }, opti
190
189
  if (given !== undefined && (await store.agents.get(given)))
191
190
  throw new ApiError("agent_exists", `an agent ${given} exists here`);
192
191
  // Stamped on the revision now, never resolved at run time: an agent saved with no place keeps running on the runner.
193
- const placed = options.fresh && definition.place === undefined && definition.computer === undefined && !isObject(definition.workflow)
192
+ const placed = options.fresh && definition.place === undefined && definition.computer === undefined && !isObject(definition.workflow) && !isObject(definition.sdk)
194
193
  ? { place: options.fresh.place, ...(definition.tools === undefined ? { tools: [...options.fresh.tools] } : {}) }
195
194
  : {};
196
195
  // A template's agent keeps the package it was applied from on its first revision (store `revisions.package`).
@@ -297,6 +296,8 @@ function editOn(entry, definition, skills, note) {
297
296
  files = (isObject(current?.skills) ? current.skills : {});
298
297
  const carried = current
299
298
  ? {
299
+ ...(currentBody.sdk && definition.sdk === undefined ? { sdk: currentBody.sdk } : {}),
300
+ ...(currentBody.native && definition.native === undefined ? { native: currentBody.native } : {}),
300
301
  ...(definition.harness === undefined && currentBody.harness ? { harness: currentBody.harness } : {}),
301
302
  // The computer and its place go together: an edit naming neither keeps both (the computer, else the place).
302
303
  ...(definition.place === undefined && definition.computer === undefined ? (currentBody.computer ? { computer: currentBody.computer } : currentBody.place ? { place: currentBody.place } : {}) : {}),
@@ -304,7 +305,6 @@ function editOn(entry, definition, skills, note) {
304
305
  // No approvals here: an edit that leaves them out asks (openapi.ts DefinitionInput.approvals),
305
306
  // so no edit makes an agent unattended by saying nothing. The console's edit sends back the approvals it read.
306
307
  ...(definition.max_cost_usd === undefined && currentBody.maxCostUsd !== undefined ? { max_cost_usd: currentBody.maxCostUsd } : {}),
307
- ...(definition.cap_mode === undefined && currentBody.capMode !== undefined ? { cap_mode: currentBody.capMode } : {}),
308
308
  // Its input's and its structured answer's schemas are the agent's contract with its callers: an edit that leaves
309
309
  // one out keeps it.
310
310
  ...(definition.input_schema === undefined && current.kind === "agentic" && !isObject(definition.workflow) && currentBody.inputSchema !== undefined ? { input_schema: currentBody.inputSchema } : {}),
@@ -349,10 +349,7 @@ export const etagOf = (entry) => `"${entry.revision?.id ?? "none"}"`;
349
349
  /** A revision as a definition, as POST /agents takes one, numbered. */
350
350
  export function definitionOf(agent, revision, version) {
351
351
  const body = revision.body;
352
- const common = {
353
- ...(body.maxCostUsd !== undefined ? { max_cost_usd: body.maxCostUsd } : {}),
354
- ...(body.capMode !== undefined ? { cap_mode: body.capMode } : {}),
355
- };
352
+ const common = body.maxCostUsd !== undefined ? { max_cost_usd: body.maxCostUsd } : {};
356
353
  const kindBody = revision.kind === "agentic"
357
354
  ? { instructions: body.instructions, ...(body.model ? { model: body.model } : {}), ...(body.modelTiers ? { model_tiers: body.modelTiers } : {}), ...(body.thinking ? { thinking: body.thinking } : {}), ...(body.learning !== undefined ? { learning: body.learning } : {}), ...(body.inputSchema !== undefined ? { input_schema: body.inputSchema } : {}), ...(body.outputSchema !== undefined ? { output_schema: body.outputSchema } : {}), ...(body.checkout !== undefined ? { checkout: body.checkout } : {}), ...common }
358
355
  : { workflow: body.workflow, ...common };
@@ -362,6 +359,8 @@ export function definitionOf(agent, revision, version) {
362
359
  name: agent.name,
363
360
  ...(agent.description !== null && agent.description !== undefined ? { description: agent.description } : {}),
364
361
  ...kindBody,
362
+ ...(body.sdk ? { sdk: body.sdk } : {}),
363
+ ...(body.native ? { native: body.native } : {}),
365
364
  // Its approvals, of either kind: "ask" where none is set, as the definition read says it (definitionOf).
366
365
  approvals: approvalsOf(body.approvals),
367
366
  harness: harnessOfBody(body),
@@ -382,6 +381,7 @@ export function agentView(entry, origin, extra = {}) {
382
381
  const external = externalOf(agent, revision);
383
382
  return {
384
383
  agent_id: agent.id,
384
+ ...(extra.nativeStatus ? { native_status: extra.nativeStatus } : {}),
385
385
  // Only on an agent another system owns (POST /runs): read-only here.
386
386
  ...(external ? { external } : {}),
387
387
  definition: revision ? definitionOf(agent, revision, entry.version) : null,
@@ -44,6 +44,7 @@
44
44
  // search (grep -r, rg, git grep, git log -p) reads every file the folder holds. The folder holds the run's own files
45
45
  // (its checkout, its inputs), never a key of the server's, and the agent may read all of it.
46
46
  import { posix } from "node:path";
47
+ import { READ_ONLY_REFUSED } from "./refusal-words.js";
47
48
  /** The policies an agent may set on bash (tool_settings.bash.policy). */
48
49
  export const BASH_POLICIES = ["read-only"];
49
50
  /** An agent's bash policy as its own tool settings write it (tool_settings.bash.policy), or undefined for none: any
@@ -133,7 +134,7 @@ const WATCHERS = new Set(["bash_output", "bash_list", "bash_signal"]);
133
134
  /** What a refusal adds, so the model knows what it may run instead. */
134
135
  export const READ_ONLY_HINT = "Use read commands only: git diff, show, log, grep, ls-files, merge-base or rev-parse; grep -n; sed -n 'N,Mp' FILE; cat, head, tail, wc, ls; find without -exec. Pipe only into head, tail, sed -n, grep, wc, sort, uniq, cut, tr or nl, with no redirection but 2>/dev/null or 2>&1, no $ or backticks, and quote glob patterns.";
135
136
  /** The refusal of a call under the read-only policy, as the model reads it: the reason, that it did not run, and what may. */
136
- export const readOnlyText = (tool, reason, notRun) => `${tool} is read-only for this agent, so this call was refused: ${reason}. ${notRun} ${READ_ONLY_HINT}`;
137
+ export const readOnlyText = (tool, reason, notRun) => `${tool}${READ_ONLY_REFUSED}${reason}. ${notRun} ${READ_ONLY_HINT}`;
137
138
  // The never-open list: any path segment `.ssh`, or a final name matching.
138
139
  const SECRET = [/^\.env/, /^id_rsa/, /\.pem$/, /\.key$/, /^\.npmrc$/, /^\.netrc$/, /^\.git-credentials$/, /^credentials(\.json)?$/];
139
140
  const secretPath = (rel) => {
@@ -0,0 +1,12 @@
1
+ /** What the warning reads of an agent's definition: its model, its thinking level, its instructions. */
2
+ export type CapShortRevision = {
3
+ readonly model?: string;
4
+ readonly thinking?: string;
5
+ readonly instructions: string;
6
+ };
7
+ /**
8
+ * The warning an agent saved with a cap of `capUsd` on `harness` reads when that cap is below what its model needs for one
9
+ * more step and an answer (wrap-up.ts capBelowWarning), else undefined. Never throws: a model or route that cannot be
10
+ * priced here says nothing (the save's other checks name it).
11
+ */
12
+ export declare function capShortOf(env: NodeJS.ProcessEnv, harness: string, revision: CapShortRevision, capUsd: number): Promise<string | undefined>;
@@ -0,0 +1,60 @@
1
+ // A cap saved below what an agent's model needs for one more step and an answer: its every run wraps up at its first tool
2
+ // call (wrap-up.ts). The save says so, as a warning, and never refuses it (a cap is the person's call). The figure is the
3
+ // wrap-up's own (stepAndAnswerFor over the cap's requestFigures), priced before any run on the first request the agent's
4
+ // harness would send: its own base input (AdapterFacts.baseInputTokens, measured on its pinned build; pi's beside its
5
+ // adapter), the agent's prompt counted with o200k_base where its model's tokenizer is that (no count otherwise: 0, a
6
+ // floor), and the least output its harness's policy reads of that request's reasoning settings at the agent's effort.
7
+ import { o200kModel, o200kTokens } from "@parcha/agentrun-kernel/host";
8
+ import { requestFigures } from "@parcha/agentrun-kernel/kernel/cap";
9
+ import { harnessOf } from "./harness-table.js";
10
+ import { thinkingLevel } from "./model.js";
11
+ import { capBelowWarning, stepAndAnswerFor } from "./wrap-up.js";
12
+ /** The model, policy, reasoning settings and base input of the first request `harness` would send for `revision` here;
13
+ * undefined when it cannot be said (the harness or its model does not run here: the save's other warnings say why). */
14
+ async function firstRequestOf(env, harness, revision) {
15
+ // The run's effort as a run without one of its own takes it (runs-over-store.ts prepareLaunch): its revision's thinking,
16
+ // else the host's AGENT_THINKING; none, none (its harness's own default, of which nothing is known here).
17
+ const level = thinkingLevel(revision.thinking) ?? thinkingLevel(env.AGENT_THINKING);
18
+ const entry = harnessOf(env, harness);
19
+ if (!entry)
20
+ return undefined;
21
+ if (entry.facts) {
22
+ const facts = entry.facts;
23
+ const { cliCapModel } = await import("./runner/cli-run-spec.js");
24
+ const { thinkingFor } = await import("./adapters.js");
25
+ const capModel = await cliCapModel({ ...entry, facts }, env, revision.model);
26
+ return { capModel, policy: facts.policy({ model: capModel.id, tools: [] }), reasoning: effortBody(capModel.api, level ? thinkingFor(facts, level) : undefined), baseTokens: facts.baseInputTokens ?? 0 };
27
+ }
28
+ // An entry with no adapter facts is pi's (harness-table.ts): it runs in the run's process on its route, and its first
29
+ // request's reasoning settings are the ones pi-ai builds for its session's model at that level.
30
+ const { routeOf } = await import("./runner/model-route.js");
31
+ const { capModelOf, PI_WIRES } = await import("./runner/adapter-run-spec.js");
32
+ const { PI_BASE_INPUT_TOKENS, piReasoningOf, policyFor } = await import("./runner/adapters/pi.js");
33
+ const route = await routeOf(revision.model, env, "default", PI_WIRES);
34
+ return { capModel: capModelOf(route), policy: await policyFor(route.provider, route.model, []), reasoning: await piReasoningOf(route, level), baseTokens: PI_BASE_INPUT_TOKENS };
35
+ }
36
+ /** The body a CLI harness's first request names its effort in, on `wire`, as its policy reads it: Responses'
37
+ * `reasoning.effort`, Messages' `output_config.effort`. */
38
+ const effortBody = (wire, effort) => effort === undefined ? {} : wire === "openai-responses" ? { reasoning: { effort } } : { output_config: { effort } };
39
+ /**
40
+ * The warning an agent saved with a cap of `capUsd` on `harness` reads when that cap is below what its model needs for one
41
+ * more step and an answer (wrap-up.ts capBelowWarning), else undefined. Never throws: a model or route that cannot be
42
+ * priced here says nothing (the save's other checks name it).
43
+ */
44
+ export async function capShortOf(env, harness, revision, capUsd) {
45
+ try {
46
+ const first = await firstRequestOf(env, harness, revision);
47
+ if (!first || first.capModel.plan || first.capModel.price === null)
48
+ return undefined;
49
+ const { capModel, policy } = first;
50
+ const body = { model: capModel.id, ...first.reasoning };
51
+ const least = policy.outputLeast?.(body);
52
+ const effort = policy.effortOf?.(body);
53
+ const prompt = o200kModel(capModel.id) ? await o200kTokens(revision.instructions) : 0;
54
+ const figures = requestFigures({ kind: "model", id: "save", model: capModel, inputTokens: first.baseTokens + prompt, ...(typeof least === "number" ? { outputTokensLeast: least } : {}) });
55
+ return capBelowWarning(capUsd, capModel.id, effort, stepAndAnswerFor(figures, (step0Usd) => step0Usd));
56
+ }
57
+ catch {
58
+ return undefined;
59
+ }
60
+ }
package/dist/cap.d.ts CHANGED
@@ -8,11 +8,6 @@ export declare const CAP_TOLERANCE = 1e-9;
8
8
  * against a 0.31 cap), never a spend that is past the cap, by however little (a 1e-11 hair is past it). CAP_TOLERANCE
9
9
  * is the other question: how near two caps are the same cap. */
10
10
  export declare const FIT_TOLERANCE = 1e-12;
11
- /** How a run's cap prices a request's input (`cap_mode`): "expected" (the default) from the previous request's cache, so
12
- * only a cache miss can pass the cap, by at most the request's bound; "strict" every input token uncached, the worst
13
- * case, so no request can pass it. */
14
- export declare const CAP_MODES: readonly ["expected", "strict"];
15
- export type CapMode = (typeof CAP_MODES)[number];
16
11
  /** The field of a request's end mark (REQUEST_ENDED) that says what the cap held for it, when its stream ended aborted
17
12
  * or its summary failed: the request counts at that figure. Optional: an end with none (an older store, a run with no
18
13
  * cap) leaves the request cut, at an unknown cost. */
@@ -91,15 +86,13 @@ export declare const CAP_REFUSAL_CODE = "spend_cap_reached (out of budget): ";
91
86
  /** A refusal for room's figures, beside its words: what the cap counted as taken (spent, and held for requests still
92
87
  * answering), the least the refused request needs, and the least cap that sends it (`leastCapUsd`: the very figure its
93
88
  * words name, "Raise the cap to at least $X", from the one call that wrote them: the request's figure there is what
94
- * admission prices it at, its expected cost, or its worst case under strict, so a cap at it admits the request). Kept on
95
- * the refusal's own start mark (`spentUsd`, `needsUsd`, `leastCapUsd`), so a run paused at its cap says them (runs.ts
96
- * pending), and its cap's raise is checked against them. `boundUsd`: the most a cache miss could make the refused
97
- * request cost beyond what it needs (BOUND_USD; absent for 0). */
89
+ * admission prices it at, its worst case, so a cap at it admits the request). Kept on the refusal's own start mark
90
+ * (`spentUsd`, `needsUsd`, `leastCapUsd`), so a run paused at its cap says them (runs.ts pending), and its cap's raise is
91
+ * checked against them. */
98
92
  export type RefusalFigures = {
99
93
  spentUsd: number;
100
94
  needsUsd: number;
101
95
  leastCapUsd: number;
102
- boundUsd?: number;
103
96
  };
104
97
  /** The words of a refusal for room (CAP_REFUSAL_CODE: what is left of the cap cannot buy the request's least), which a
105
98
  * higher cap would send; undefined for any other text, a refusal no cap could fix included (an unknown spend, no price,
package/dist/cap.js CHANGED
@@ -11,10 +11,6 @@ export const CAP_TOLERANCE = 1e-9;
11
11
  * against a 0.31 cap), never a spend that is past the cap, by however little (a 1e-11 hair is past it). CAP_TOLERANCE
12
12
  * is the other question: how near two caps are the same cap. */
13
13
  export const FIT_TOLERANCE = 1e-12;
14
- /** How a run's cap prices a request's input (`cap_mode`): "expected" (the default) from the previous request's cache, so
15
- * only a cache miss can pass the cap, by at most the request's bound; "strict" every input token uncached, the worst
16
- * case, so no request can pass it. */
17
- export const CAP_MODES = ["expected", "strict"];
18
14
  /** The field of a request's end mark (REQUEST_ENDED) that says what the cap held for it, when its stream ended aborted
19
15
  * or its summary failed: the request counts at that figure. Optional: an end with none (an older store, a run with no
20
16
  * cap) leaves the request cut, at an unknown cost. */
@@ -292,7 +288,8 @@ export function meterFiguresFrom(rows) {
292
288
  }
293
289
  const tools = marks.size || charges.some((usd) => usd === undefined) ? null : charges.reduce((sum, usd) => sum + usd, 0);
294
290
  const rest = rows.filter(({ conversation, entry }) => conversation === root && entry.kind !== TOOL_STARTED && entry.kind !== TOOL_COST).map(({ entry }) => entry);
295
- const usage = timelineOf(rest, { settled: true }).find((row) => row.kind === "usage");
291
+ // A hold is no charge here (/usage says no "at most"): read as a cost no one knows, beside the exact charges.
292
+ const usage = timelineOf(rest, { settled: true, holdsUnpriced: true }).find((row) => row.kind === "usage");
296
293
  const otherTools = marks.size || others.some((usd) => usd === undefined) ? null : others.reduce((sum, usd) => sum + usd, 0);
297
294
  known.tokens = usage ? (usage.usage?.usd ?? usage.usage?.so_far_usd ?? 0) : 0;
298
295
  const notMetered = usage?.usage?.not_metered;
package/dist/catalog.d.ts CHANGED
@@ -1,8 +1,3 @@
1
- /** A wire name: at most 52 characters, not the adapter's 64. One CLI gives the model the name with a 12-character
2
- * `mcp__hands__` prefix, and the model API's 64-character limit is on the name the model sees, so 52 is the budget that
3
- * holds on every harness. The one constant the identity branch and the length check both read: a plain 53-64 character
4
- * name of valid characters must not skip the mapping and come out over budget. */
5
- export declare const WIRE_NAME: RegExp;
6
1
  /** A catalog name's wire name: itself when it already is one within the budget, else `:` and `/` to `__`, `.` to `_`,
7
2
  * any other character to `_`, and a `-<8 hex of the catalog name>` suffix (prefix trimmed to fit) when the result is
8
3
  * too long. The suffix makes a long name unique. */
package/dist/catalog.js CHANGED
@@ -4,11 +4,7 @@
4
4
  // deterministic function here, never in an adapter, so every harness gets the same wire name; the journal records the
5
5
  // wire name (recovery matches a call by it), and a reader maps it back to the catalog name by a lookup, never a parse.
6
6
  import { createHash } from "node:crypto";
7
- /** A wire name: at most 52 characters, not the adapter's 64. One CLI gives the model the name with a 12-character
8
- * `mcp__hands__` prefix, and the model API's 64-character limit is on the name the model sees, so 52 is the budget that
9
- * holds on every harness. The one constant the identity branch and the length check both read: a plain 53-64 character
10
- * name of valid characters must not skip the mapping and come out over budget. */
11
- export const WIRE_NAME = /^[A-Za-z0-9_-]{1,52}$/;
7
+ import { WIRE_NAME } from "./tool-names.js";
12
8
  /** A catalog name's wire name: itself when it already is one within the budget, else `:` and `/` to `__`, `.` to `_`,
13
9
  * any other character to `_`, and a `-<8 hex of the catalog name>` suffix (prefix trimmed to fit) when the result is
14
10
  * too long. The suffix makes a long name unique. */
@@ -0,0 +1,163 @@
1
+ import { inspect } from "node:util";
2
+ import { CredentialUnavailable } from "@parcha/agentrun-kernel/host";
3
+ import { type SealedKeys, type Settings } from "./store/index.js";
4
+ /** The sealed row that holds the sign-in. */
5
+ export declare const CHATGPT_PLAN_ROW = "chatgpt:plan";
6
+ /** The model provider a plan model is named under (`chatgpt/<model-id>`), so a run's billing is never chosen silently. */
7
+ export declare const PLAN_PROVIDER = "chatgpt";
8
+ /** Where plan requests go. */
9
+ export declare const PLAN_ORIGIN = "https://api.openai.com";
10
+ /** The models listed when OpenAI's list can't be read at sign-in. */
11
+ export declare const PLAN_FALLBACK_MODELS: readonly string[];
12
+ /** The model a run on the plan gets when it names none. */
13
+ export declare const PLAN_DEFAULT_MODEL = "gpt-6.1-sol";
14
+ export type PlanState = "signed_out" | "pending" | "signed_in" | "expired";
15
+ /** GET /settings/chatgpt: never a token. */
16
+ export type PlanView = {
17
+ state: PlanState;
18
+ email?: string;
19
+ plan?: string;
20
+ authorize_url?: string;
21
+ expires_at?: string;
22
+ models?: string[];
23
+ };
24
+ /** The words a run or a request gets when there is no plan token to send. */
25
+ export declare const SIGNED_OUT = "This server is not signed in to ChatGPT: sign in under Settings \u2192 Model keys, or name a model on a key.";
26
+ export declare const EXPIRED = "This server's ChatGPT sign-in expired: sign in again under Settings \u2192 Model keys.";
27
+ /** What a sign-out answers beside `revoked: false`: the sign-in is gone here, and the person ends it at OpenAI. */
28
+ export declare const SIGN_OUT_UNCONFIRMED = "Signed out here. OpenAI didn't confirm the revocation: remove AgentRun in your ChatGPT settings.";
29
+ /** A sign-in step refused, in words a person acts on (the routes' 400). */
30
+ export declare class PlanSignInRefused extends Error {
31
+ }
32
+ /** No plan token can be had now (signed out, expired, or OpenAI could not renew it), in plain words: a model proxy
33
+ * refuses the request in these words (CredentialUnavailable). */
34
+ export declare class PlanUnavailable extends CredentialUnavailable {
35
+ }
36
+ /** What a run reads of the plan: whether it is signed in now, its models, and its token, asked per request; `watch`
37
+ * tells each token as it is read or renewed, for a redactor. */
38
+ export interface PlanReader {
39
+ readonly state: "signed_out" | "signed_in" | "expired";
40
+ readonly models: readonly string[];
41
+ token(): Promise<string>;
42
+ /** Told OpenAI answered 401 to a request sent with `sent`: the next token() renews it, unless the store already holds
43
+ * another. */
44
+ refused(sent: string): Promise<void>;
45
+ watch(listener: (tokens: string[]) => void): void;
46
+ }
47
+ /** `env`'s plan reader, if it has one. */
48
+ export declare const planOf: (env: NodeJS.ProcessEnv) => PlanReader | undefined;
49
+ /** `env` carrying `plan`, in place: an enumerable symbol property, so an object spread of it keeps it. */
50
+ export declare function withPlan<E extends NodeJS.ProcessEnv>(env: E, plan: PlanReader | undefined): E;
51
+ /** Whether `env` runs on the plan now. */
52
+ export declare const signedIn: (env: NodeJS.ProcessEnv) => boolean;
53
+ export interface ChatGPTPlanDeps {
54
+ /** `settings`: where a server keeps its host id, for a sign-in; a runner, which never signs in, has none. */
55
+ readonly store: {
56
+ readonly sealedKeys: Pick<SealedKeys, "get" | "put" | "replaceIf" | "removeIf" | "clock">;
57
+ readonly settings?: Pick<Settings, "putIfAbsent">;
58
+ };
59
+ readonly sealKey: Buffer;
60
+ readonly now?: () => number;
61
+ /** Told after a sign-in, a sign-out or an expiry changed the state. */
62
+ readonly changed?: () => void | Promise<void>;
63
+ readonly log?: (fields: Record<string, string>) => void;
64
+ }
65
+ /** The plan over one store: a server's (sign-in, sign-out, its reading) or a runner's (the token, per request). Its
66
+ * fields are #private and it prints as its state alone (util.inspect, JSON), so an environment that carries it (withPlan)
67
+ * never shows a token when logged. */
68
+ export declare class ChatGPTPlan implements PlanReader {
69
+ #private;
70
+ constructor(deps: ChatGPTPlanDeps);
71
+ [inspect.custom](): string;
72
+ toJSON(): {
73
+ state: PlanState;
74
+ };
75
+ watch(listener: (tokens: string[]) => void): void;
76
+ /** Each token of `credential` joins this process's redaction, and every watcher's. */
77
+ private hold;
78
+ /** This process's clock: what a token's own end (OpenAI's `expires_in`, counted here) is judged by. */
79
+ private now;
80
+ /** The store's clock: what a renewal lease is stamped and judged by, the same for every process on the store. */
81
+ private storeNow;
82
+ get state(): "signed_out" | "signed_in" | "expired";
83
+ get models(): readonly string[];
84
+ /** The row as sealed now, opened; none with none saved or one that does not open. */
85
+ private read;
86
+ /** The row as sealed now, opened, with the bytes it was read as (what a compare-and-set on it compares). */
87
+ private readSealed;
88
+ /** The row sealed as `bytes`, opened (its tokens held for redaction); none when they do not open. */
89
+ private open;
90
+ /** `row` sealed as the store keeps it: fresh bytes at each seal. */
91
+ private seal;
92
+ /** `row` saved only while the store still holds `was` (SealedKeys.replaceIf): the bytes it was saved as, or none when
93
+ * the row had changed. */
94
+ private swap;
95
+ /** Reads the sealed row into the state a reader sees. Returns this. */
96
+ load(): Promise<this>;
97
+ view(): PlanView;
98
+ /** This server's id at OpenAI (its agent host id): a UUID made once and kept in the store's settings. Not a credential. */
99
+ private hostId;
100
+ private cancel;
101
+ /** Starts a sign-in (one at a time: a new start cancels the one waiting) and gives the address to open. It lasts 10
102
+ * minutes: the loopback callback finishes it where the browser runs on this machine; elsewhere finishSignIn does. */
103
+ startSignIn(): Promise<{
104
+ authorize_url: string;
105
+ expires_at: string;
106
+ }>;
107
+ /** Finishes the sign-in waiting with the address its browser tab ended on, pasted. A URL that is not that sign-in's end
108
+ * is refused in words and the sign-in keeps waiting; one OpenAI refuses ends it. */
109
+ finishSignIn(redirectUrl: unknown): Promise<PlanView>;
110
+ /** A credential from the sign-in started at `epoch`, checked and sealed with what a view shows. A sign-out or a newer
111
+ * sign-in since then wins: the credential is dropped, never written, and revoked at OpenAI. A sign-in it takes the place
112
+ * of is revoked first, then replaced only while the row still holds it (a renewal of it that wrote back meanwhile is
113
+ * read, revoked and replaced in turn), so no earlier pair is left alive. */
114
+ private keep;
115
+ /** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families; the fallback
116
+ * list when it can't be read. */
117
+ private listModels;
118
+ /** The access token to send now: the sealed one, renewed first when it ends within 5 minutes. Throws PlanUnavailable,
119
+ * in words, when there is none. */
120
+ token(): Promise<string>;
121
+ /** 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. */
122
+ private fresh;
123
+ /** OpenAI answered 401 to `sent`: the row read again, and the next token() renews it only when the row still holds
124
+ * `sent` (another holder that renewed already has put a new one there, which is sent instead). */
125
+ refused(sent: string): Promise<void>;
126
+ /** Renews the sign-in whose refresh token is `seen`, for any process that holds the store and the seal key (the server,
127
+ * each runner). A refresh token is spent at its use, and one used twice makes OpenAI revoke the whole sign-in, so one
128
+ * holder at a time takes a lease on the row (a compare-and-set on its sealed bytes) before it spends the token. The
129
+ * others adopt the pair it writes back: meanwhile they send the current token while it has not ended, and wait for the
130
+ * new pair once it has. A lease whose holder died lapses after REFRESH_LEASE_MS, and the next reader takes it. The
131
+ * lease's end is stamped and judged on the store's clock, so a process whose own clock runs ahead never takes one
132
+ * still live. */
133
+ private renew;
134
+ /** The renewal itself, under this holder's lease on `row` (sealed as `bytes`). Every write back is a compare-and-set
135
+ * against the leased row, so a sign-out or a new sign-in meanwhile is never overwritten: ours is dropped. */
136
+ private renewUnder;
137
+ /** After a renewal whose write back lost its compare-and-set (the owner signed out or in again meanwhile): its result
138
+ * is dropped, and the row's state wins. */
139
+ private adopt;
140
+ /** Signs out: any sign-in waiting cancelled (one past its browser step waited for: it drops and revokes its credential),
141
+ * then the row removed only while it still holds the bytes read (SealedKeys.removeIf; a renewal that wrote back
142
+ * meanwhile is read and removed in turn), and the pair it held revoked at OpenAI (its documented revocation endpoint,
143
+ * with the refresh token). The row goes whatever the revocation says. `revoked`: nothing of the sign-in is left alive
144
+ * at OpenAI as far as it can tell: none was signed in, or OpenAI confirmed the revocation and no renewal was out under
145
+ * a live lease (that renewal revokes the pair it gets when its write back finds the row gone, but OpenAI's word on it
146
+ * is not this answer's to give). */
147
+ signOut(): Promise<{
148
+ revoked: boolean;
149
+ }>;
150
+ /** `credential`'s session revoked at OpenAI (its documented revocation endpoint, with the refresh token): whether OpenAI
151
+ * confirmed it. The endpoint is taken from OpenAI's discovery document only when it is https on auth.openai.com, so a
152
+ * refresh token goes nowhere else. Never throws. */
153
+ private revoke;
154
+ /** Stops the sign-in waiting, at the server's close. */
155
+ close(): void;
156
+ }
157
+ /** For a run on a plan model (`model`, the one its claim chose): the plan's token read once before anything starts, so a
158
+ * sign-in that is gone, or that OpenAI refuses to renew, fails the run at once, in words (PlanUnavailable). */
159
+ export declare function planBeforeRun(env: NodeJS.ProcessEnv, model: {
160
+ provider: string;
161
+ } | undefined): Promise<void>;
162
+ /** A runner's reader of the plan over its store, loaded now: none when the server holds no sign-in. */
163
+ export declare function planReaderOf(store: ChatGPTPlanDeps["store"], sealKey: Buffer | undefined): Promise<PlanReader | undefined>;