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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (466) hide show
  1. package/CHANGELOG.md +368 -0
  2. package/README.md +341 -208
  3. package/dist/adapters.d.ts +3 -4
  4. package/dist/adapters.js +18 -15
  5. package/dist/agent-rows.d.ts +99 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +75 -25
  9. package/dist/agents.d.ts +9 -125
  10. package/dist/agents.js +15 -305
  11. package/dist/answer-json.d.ts +23 -0
  12. package/dist/answer-json.js +58 -0
  13. package/dist/api-only.d.ts +1 -1
  14. package/dist/api-only.js +2 -2
  15. package/dist/archil-settings.d.ts +11 -1
  16. package/dist/archil-settings.js +10 -0
  17. package/dist/bash-read-only.d.ts +35 -0
  18. package/dist/bash-read-only.js +778 -0
  19. package/dist/box-settings.d.ts +3 -23
  20. package/dist/box-settings.js +7 -51
  21. package/dist/boxes.d.ts +17 -0
  22. package/dist/boxes.js +27 -20
  23. package/dist/browser-commands.d.ts +5 -2
  24. package/dist/browser-commands.js +4 -4
  25. package/dist/browser-computer.d.ts +5 -0
  26. package/dist/browser-computer.js +21 -0
  27. package/dist/browser-cost.d.ts +9 -6
  28. package/dist/browser-cost.js +95 -51
  29. package/dist/browser-live.d.ts +7 -20
  30. package/dist/browser-live.js +15 -93
  31. package/dist/browser-person.d.ts +18 -51
  32. package/dist/browser-person.js +94 -277
  33. package/dist/budget.d.ts +0 -5
  34. package/dist/budget.js +0 -5
  35. package/dist/cap.d.ts +14 -8
  36. package/dist/cap.js +19 -9
  37. package/dist/cli.js +71 -18
  38. package/dist/closed-pipes.d.ts +2 -0
  39. package/dist/closed-pipes.js +13 -0
  40. package/dist/computer-commands.d.ts +2 -0
  41. package/dist/computer-commands.js +2 -0
  42. package/dist/computer-keys.d.ts +20 -10
  43. package/dist/computer-keys.js +36 -54
  44. package/dist/computer-setting.d.ts +20 -3
  45. package/dist/computer-setting.js +58 -10
  46. package/dist/computers.d.ts +35 -2
  47. package/dist/computers.js +72 -11
  48. package/dist/confine.d.ts +120 -0
  49. package/dist/confine.js +436 -0
  50. package/dist/console/assets/index-B7NKTU8E.css +1 -0
  51. package/dist/console/assets/index-CXZMgJE7.js +550 -0
  52. package/dist/console/index.html +2 -2
  53. package/dist/content-filter.d.ts +7 -0
  54. package/dist/content-filter.js +23 -0
  55. package/dist/decision-cap.d.ts +7 -29
  56. package/dist/decision-cap.js +3 -94
  57. package/dist/decision-rows.d.ts +1 -1
  58. package/dist/decision-rows.js +1 -1
  59. package/dist/docker-daemon.d.ts +31 -0
  60. package/dist/docker-daemon.js +56 -0
  61. package/dist/effort-guidance.js +4 -3
  62. package/dist/environment.d.ts +0 -3
  63. package/dist/environment.js +3 -5
  64. package/dist/errors.d.ts +1 -2
  65. package/dist/errors.js +9 -9
  66. package/dist/explain.js +3 -1
  67. package/dist/filed-answer.d.ts +32 -0
  68. package/dist/filed-answer.js +160 -0
  69. package/dist/files.d.ts +1 -3
  70. package/dist/files.js +2 -4
  71. package/dist/github-connection.d.ts +1 -1
  72. package/dist/github-connection.js +25 -7
  73. package/dist/github-faux.d.ts +26 -0
  74. package/dist/github-faux.js +76 -0
  75. package/dist/github.d.ts +6 -2
  76. package/dist/github.js +5 -3
  77. package/dist/graph-served.d.ts +5 -3
  78. package/dist/graph-served.js +14 -6
  79. package/dist/graph-view.d.ts +3 -5
  80. package/dist/graph-view.js +9 -16
  81. package/dist/handed-values.d.ts +9 -0
  82. package/dist/handed-values.js +26 -0
  83. package/dist/harness-install.d.ts +1 -7
  84. package/dist/harness-install.js +1 -18
  85. package/dist/harness-opencode/adapter.d.ts +7 -0
  86. package/dist/harness-opencode/adapter.js +23 -6
  87. package/dist/harness-opencode/harness.js +0 -1
  88. package/dist/harness-opencode/host/policy.js +2 -2
  89. package/dist/harness-opencode/index.d.ts +1 -1
  90. package/dist/harness-opencode/index.js +1 -1
  91. package/dist/harness-opencode/verify.d.ts +17 -0
  92. package/dist/harness-opencode/verify.js +30 -10
  93. package/dist/harness-table.js +6 -1
  94. package/dist/heard.js +1 -1
  95. package/dist/held-fd.d.ts +5 -0
  96. package/dist/held-fd.js +14 -0
  97. package/dist/host-calls.d.ts +20 -0
  98. package/dist/host-calls.js +12 -0
  99. package/dist/host-tools.d.ts +4 -21
  100. package/dist/host-tools.js +4 -61
  101. package/dist/host.d.ts +2 -4
  102. package/dist/host.js +2 -7
  103. package/dist/import-summary.d.ts +1 -5
  104. package/dist/import-summary.js +0 -21
  105. package/dist/import.d.ts +6 -6
  106. package/dist/import.js +14 -15
  107. package/dist/index.d.ts +1 -0
  108. package/dist/index.js +1 -0
  109. package/dist/key-refusal.d.ts +5 -1
  110. package/dist/key-refusal.js +19 -4
  111. package/dist/learn/check.d.ts +8 -2
  112. package/dist/learn/check.js +85 -31
  113. package/dist/learn/folder.d.ts +11 -4
  114. package/dist/learn/folder.js +17 -19
  115. package/dist/learn/grade.d.ts +18 -1
  116. package/dist/learn/grade.js +108 -14
  117. package/dist/learn/index.d.ts +5 -5
  118. package/dist/learn/index.js +5 -5
  119. package/dist/learn/learning.sh +1 -14
  120. package/dist/learn/notes.d.ts +14 -3
  121. package/dist/learn/notes.js +16 -6
  122. package/dist/learn/reflect.d.ts +31 -2
  123. package/dist/learn/reflect.js +83 -6
  124. package/dist/learn/relevance.d.ts +24 -0
  125. package/dist/learn/relevance.js +91 -0
  126. package/dist/learn/secrets.d.ts +7 -1
  127. package/dist/learn/secrets.js +86 -19
  128. package/dist/learn/skills.d.ts +159 -18
  129. package/dist/learn/skills.js +644 -64
  130. package/dist/learned-nodes.d.ts +14 -0
  131. package/dist/learned-nodes.js +8 -0
  132. package/dist/learned-workflow.d.ts +41 -6
  133. package/dist/learned-workflow.js +153 -18
  134. package/dist/learning-routes.d.ts +49 -4
  135. package/dist/learning-routes.js +113 -31
  136. package/dist/learning-run.d.ts +16 -31
  137. package/dist/learning-run.js +31 -38
  138. package/dist/learning-words.d.ts +12 -5
  139. package/dist/learning-words.js +18 -9
  140. package/dist/learning.d.ts +91 -97
  141. package/dist/learning.js +176 -320
  142. package/dist/live/stream.js +1 -1
  143. package/dist/live/translate.js +12 -2
  144. package/dist/llm.d.ts +4 -1
  145. package/dist/llm.js +4 -2
  146. package/dist/local-models.d.ts +11 -5
  147. package/dist/local-models.js +13 -8
  148. package/dist/mcp-gateway.d.ts +17 -49
  149. package/dist/mcp-gateway.js +55 -136
  150. package/dist/mcp-oauth.d.ts +10 -14
  151. package/dist/mcp-oauth.js +14 -32
  152. package/dist/mcp-probe.d.ts +0 -7
  153. package/dist/mcp-probe.js +4 -10
  154. package/dist/mcp-servers-store.d.ts +18 -18
  155. package/dist/mcp-servers-store.js +12 -14
  156. package/dist/mcp-store.js +3 -4
  157. package/dist/mcp.js +4 -3
  158. package/dist/model.d.ts +9 -7
  159. package/dist/model.js +51 -27
  160. package/dist/monid.d.ts +0 -2
  161. package/dist/monid.js +3 -6
  162. package/dist/openapi.d.ts +8 -1
  163. package/dist/openapi.js +156 -58
  164. package/dist/page.d.ts +1 -3
  165. package/dist/page.js +6 -18
  166. package/dist/paid-calls.d.ts +21 -27
  167. package/dist/paid-calls.js +26 -61
  168. package/dist/pause.d.ts +2 -19
  169. package/dist/pause.js +5 -74
  170. package/dist/port-models.d.ts +10 -3
  171. package/dist/port-models.js +26 -6
  172. package/dist/propose.d.ts +2 -0
  173. package/dist/propose.js +80 -45
  174. package/dist/push-handler.d.ts +1 -1
  175. package/dist/reflect-range.d.ts +25 -0
  176. package/dist/reflect-range.js +30 -0
  177. package/dist/refusal-words.d.ts +5 -1
  178. package/dist/refusal-words.js +5 -1
  179. package/dist/rows.d.ts +1 -1
  180. package/dist/run-cut.d.ts +0 -6
  181. package/dist/run-cut.js +0 -6
  182. package/dist/run-db.d.ts +2 -11
  183. package/dist/run-db.js +2 -37
  184. package/dist/run-launch.d.ts +21 -2
  185. package/dist/run-launch.js +14 -5
  186. package/dist/run-learning-served.d.ts +21 -4
  187. package/dist/run-learning-served.js +23 -13
  188. package/dist/run-reads-over-store.d.ts +5 -3
  189. package/dist/run-reads-over-store.js +25 -14
  190. package/dist/run-secrets.d.ts +1 -1
  191. package/dist/run-timeline-served.d.ts +5 -1
  192. package/dist/run-timeline-served.js +27 -6
  193. package/dist/run-view.d.ts +37 -22
  194. package/dist/run-view.js +85 -38
  195. package/dist/runnable.d.ts +21 -10
  196. package/dist/runnable.js +35 -12
  197. package/dist/runner/adapter-loop.d.ts +36 -5
  198. package/dist/runner/adapter-loop.js +663 -69
  199. package/dist/runner/adapter-run-spec.d.ts +42 -8
  200. package/dist/runner/adapter-run-spec.js +186 -52
  201. package/dist/runner/adapters/index.js +11 -1
  202. package/dist/runner/adapters/pi.d.ts +40 -2
  203. package/dist/runner/adapters/pi.js +110 -27
  204. package/dist/runner/beside.d.ts +38 -3
  205. package/dist/runner/beside.js +54 -5
  206. package/dist/runner/claim-secrets.d.ts +16 -1
  207. package/dist/runner/claim-secrets.js +62 -14
  208. package/dist/runner/cli-run-spec.d.ts +5 -0
  209. package/dist/runner/cli-run-spec.js +159 -41
  210. package/dist/runner/commands.js +1 -1
  211. package/dist/runner/computer-journal.d.ts +15 -2
  212. package/dist/runner/computer-journal.js +41 -5
  213. package/dist/runner/conformance/harness.d.ts +1 -0
  214. package/dist/runner/conformance/harness.js +123 -13
  215. package/dist/runner/conformance/subject.d.ts +4 -1
  216. package/dist/runner/dispatch.d.ts +8 -1
  217. package/dist/runner/dispatch.js +81 -7
  218. package/dist/runner/end-of-run.d.ts +8 -2
  219. package/dist/runner/end-of-run.js +10 -4
  220. package/dist/runner/github-app.d.ts +7 -2
  221. package/dist/runner/github-app.js +47 -16
  222. package/dist/runner/harness-loops.d.ts +15 -2
  223. package/dist/runner/harness-loops.js +38 -2
  224. package/dist/runner/journal-kinds.d.ts +60 -6
  225. package/dist/runner/journal-kinds.js +43 -5
  226. package/dist/runner/journal-reader.d.ts +1 -1
  227. package/dist/runner/journal-reader.js +2 -2
  228. package/dist/runner/learning-ask.d.ts +4 -0
  229. package/dist/runner/learning-ask.js +15 -1
  230. package/dist/runner/learning-end.d.ts +18 -3
  231. package/dist/runner/learning-end.js +194 -20
  232. package/dist/runner/learning-loop.d.ts +7 -0
  233. package/dist/runner/learning-loop.js +36 -8
  234. package/dist/runner/learning-seed.d.ts +6 -0
  235. package/dist/runner/learning-seed.js +6 -0
  236. package/dist/runner/loop-contract.d.ts +4 -0
  237. package/dist/runner/main.d.ts +61 -9
  238. package/dist/runner/main.js +144 -20
  239. package/dist/runner/mcp-claim.d.ts +3 -0
  240. package/dist/runner/mcp-claim.js +7 -3
  241. package/dist/runner/mcp-github.d.ts +11 -2
  242. package/dist/runner/mcp-github.js +55 -4
  243. package/dist/runner/mcp-run.d.ts +2 -0
  244. package/dist/runner/mcp-run.js +16 -5
  245. package/dist/runner/memory-claim.d.ts +9 -0
  246. package/dist/runner/memory-claim.js +25 -0
  247. package/dist/runner/metrics.d.ts +46 -1
  248. package/dist/runner/metrics.js +156 -1
  249. package/dist/runner/model-route.d.ts +16 -0
  250. package/dist/runner/model-route.js +134 -10
  251. package/dist/runner/reflect-hook.d.ts +12 -1
  252. package/dist/runner/reflect-hook.js +33 -3
  253. package/dist/runner/runner.d.ts +20 -0
  254. package/dist/runner/runner.js +146 -18
  255. package/dist/runner/spec-holds.d.ts +7 -2
  256. package/dist/runner/spec-holds.js +4 -3
  257. package/dist/runner/store-port.d.ts +1 -1
  258. package/dist/runner/store-secrets.d.ts +3 -3
  259. package/dist/runner/store-secrets.js +8 -12
  260. package/dist/runner/text-tools.d.ts +44 -0
  261. package/dist/runner/text-tools.js +237 -0
  262. package/dist/runner/workflow-host.d.ts +7 -2
  263. package/dist/runner/workflow-host.js +3 -1
  264. package/dist/runner/workflow-loop.d.ts +10 -1
  265. package/dist/runner/workflow-loop.js +14 -6
  266. package/dist/runner/workflow-spec.d.ts +21 -0
  267. package/dist/runner/workflow-spec.js +217 -93
  268. package/dist/runs-over-store.d.ts +14 -3
  269. package/dist/runs-over-store.js +100 -23
  270. package/dist/seal-key.d.ts +0 -2
  271. package/dist/seal-key.js +5 -45
  272. package/dist/sealed-settings-store.d.ts +19 -4
  273. package/dist/sealed-settings-store.js +9 -9
  274. package/dist/sealing.d.ts +4 -0
  275. package/dist/sealing.js +20 -0
  276. package/dist/secret-cut.d.ts +1 -1
  277. package/dist/secret-cut.js +1 -1
  278. package/dist/secret-name.d.ts +9 -0
  279. package/dist/secret-name.js +15 -0
  280. package/dist/secret-writes.d.ts +0 -1
  281. package/dist/secret-writes.js +0 -1
  282. package/dist/server-fs.d.ts +4 -0
  283. package/dist/server-fs.js +8 -2
  284. package/dist/server-lock.d.ts +0 -24
  285. package/dist/server-lock.js +5 -85
  286. package/dist/server-secrets-store.d.ts +4 -4
  287. package/dist/server-secrets-store.js +9 -31
  288. package/dist/server-secrets.d.ts +4 -9
  289. package/dist/server-secrets.js +12 -36
  290. package/dist/server.d.ts +37 -56
  291. package/dist/server.js +322 -134
  292. package/dist/sign-ins-store.d.ts +34 -36
  293. package/dist/sign-ins-store.js +27 -38
  294. package/dist/sign-ins.d.ts +2 -119
  295. package/dist/sign-ins.js +5 -311
  296. package/dist/standard-webhooks.d.ts +1 -1
  297. package/dist/standard-webhooks.js +1 -1
  298. package/dist/stats.d.ts +3 -2
  299. package/dist/stats.js +1 -1
  300. package/dist/stop-signals.d.ts +4 -2
  301. package/dist/stop-signals.js +5 -3
  302. package/dist/store/agent-body.d.ts +12 -2
  303. package/dist/store/agent-body.js +22 -4
  304. package/dist/store/deadline.d.ts +18 -0
  305. package/dist/store/deadline.js +45 -0
  306. package/dist/store/index.d.ts +2 -2
  307. package/dist/store/index.js +2 -2
  308. package/dist/store/open.d.ts +6 -3
  309. package/dist/store/open.js +2 -2
  310. package/dist/store/postgres/connection.d.ts +22 -2
  311. package/dist/store/postgres/connection.js +211 -41
  312. package/dist/store/postgres/migrate.d.ts +4 -0
  313. package/dist/store/postgres/migrate.js +9 -2
  314. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  315. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  316. package/dist/store/postgres/store.d.ts +9 -2
  317. package/dist/store/postgres/store.js +9 -0
  318. package/dist/store/schema.js +1 -1
  319. package/dist/store/seal.js +2 -2
  320. package/dist/store/sqlite/connection.js +14 -5
  321. package/dist/store/sqlite/run-patch.d.ts +3 -0
  322. package/dist/store/sqlite/run-patch.js +3 -0
  323. package/dist/store/sqlite/store.js +41 -12
  324. package/dist/store/store.d.ts +35 -6
  325. package/dist/store/store.js +12 -2
  326. package/dist/store-reads/cap.d.ts +1 -1
  327. package/dist/store-reads/cap.js +22 -4
  328. package/dist/store-reads/journal.d.ts +9 -6
  329. package/dist/store-reads/journal.js +129 -18
  330. package/dist/store-reads/learning.d.ts +82 -8
  331. package/dist/store-reads/learning.js +184 -11
  332. package/dist/store-reads/workflow.d.ts +1 -1
  333. package/dist/store-reads/workflow.js +1 -1
  334. package/dist/store-view.d.ts +19 -1
  335. package/dist/store-view.js +95 -27
  336. package/dist/template-eval.d.ts +60 -4
  337. package/dist/template-eval.js +120 -54
  338. package/dist/templates.d.ts +33 -14
  339. package/dist/templates.js +82 -46
  340. package/dist/timeline/group.d.ts +33 -0
  341. package/dist/timeline/group.js +77 -0
  342. package/dist/timeline/index.d.ts +7 -0
  343. package/dist/timeline/index.js +7 -0
  344. package/dist/timeline/labels.d.ts +79 -0
  345. package/dist/timeline/labels.js +150 -0
  346. package/dist/timeline/origin.d.ts +56 -0
  347. package/dist/timeline/origin.js +92 -0
  348. package/dist/timeline/render-text.d.ts +11 -0
  349. package/dist/timeline/render-text.js +62 -0
  350. package/dist/timeline/timeline.d.ts +282 -0
  351. package/dist/timeline/timeline.js +1308 -0
  352. package/dist/timeline/util.d.ts +17 -0
  353. package/dist/timeline/util.js +49 -0
  354. package/dist/tool-budget.d.ts +18 -0
  355. package/dist/tool-budget.js +50 -0
  356. package/dist/tool-gate.d.ts +47 -218
  357. package/dist/tool-gate.js +87 -545
  358. package/dist/tool-keys-store.d.ts +11 -12
  359. package/dist/tool-keys-store.js +24 -31
  360. package/dist/tool-keys.d.ts +5 -101
  361. package/dist/tool-keys.js +8 -267
  362. package/dist/tool-plane.d.ts +23 -52
  363. package/dist/tool-plane.js +23 -81
  364. package/dist/tool-settings-store.d.ts +1 -2
  365. package/dist/tool-settings-store.js +5 -8
  366. package/dist/tools.d.ts +67 -25
  367. package/dist/tools.js +170 -119
  368. package/dist/trigger-adapter.d.ts +2 -2
  369. package/dist/trigger-targets.d.ts +13 -1
  370. package/dist/trigger-targets.js +31 -1
  371. package/dist/triggers.d.ts +2 -2
  372. package/dist/triggers.js +3 -3
  373. package/dist/turn-end.d.ts +1 -1
  374. package/dist/turn-end.js +1 -1
  375. package/dist/turns.d.ts +0 -6
  376. package/dist/turns.js +0 -19
  377. package/dist/uploads.d.ts +28 -5
  378. package/dist/uploads.js +83 -10
  379. package/dist/usage.d.ts +1 -49
  380. package/dist/usage.js +3 -84
  381. package/dist/validate.d.ts +4 -0
  382. package/dist/validate.js +33 -14
  383. package/dist/webhooks.d.ts +102 -76
  384. package/dist/webhooks.js +266 -233
  385. package/dist/workflow-run.d.ts +114 -0
  386. package/dist/workflow-run.js +144 -0
  387. package/dist/workspace/archil-claim.d.ts +2 -2
  388. package/dist/workspace/archil-claim.js +4 -3
  389. package/dist/workspace/archil-disk.d.ts +10 -1
  390. package/dist/workspace/archil-disk.js +4 -0
  391. package/dist/workspace/archil-exec.d.ts +12 -2
  392. package/dist/workspace/archil-exec.js +16 -0
  393. package/dist/workspace/archil.d.ts +2 -2
  394. package/dist/workspace/archil.js +25 -5
  395. package/dist/workspace/attach.js +2 -0
  396. package/dist/workspace/beneath.d.ts +19 -0
  397. package/dist/workspace/beneath.js +106 -0
  398. package/dist/workspace/computer-deps.d.ts +26 -9
  399. package/dist/workspace/computer-deps.js +144 -43
  400. package/dist/workspace/computer-for-claim.d.ts +17 -14
  401. package/dist/workspace/computer-for-claim.js +99 -26
  402. package/dist/workspace/computer-hold.d.ts +6 -1
  403. package/dist/workspace/computer-hold.js +6 -1
  404. package/dist/workspace/computer-janitor.d.ts +47 -0
  405. package/dist/workspace/computer-janitor.js +182 -0
  406. package/dist/workspace/computer-ledger.d.ts +1 -8
  407. package/dist/workspace/computer-ledger.js +0 -3
  408. package/dist/workspace/computer-providers.d.ts +5 -3
  409. package/dist/workspace/computer-providers.js +11 -9
  410. package/dist/workspace/grep-worker.d.ts +5 -0
  411. package/dist/workspace/grep-worker.js +9 -6
  412. package/dist/workspace/hands.d.ts +5 -2
  413. package/dist/workspace/hands.js +4 -3
  414. package/dist/workspace/index.d.ts +6 -5
  415. package/dist/workspace/index.js +4 -4
  416. package/dist/workspace/local.d.ts +14 -2
  417. package/dist/workspace/local.js +170 -43
  418. package/dist/workspace/paths.js +3 -2
  419. package/dist/workspace/pi-env.d.ts +4 -0
  420. package/dist/workspace/pi-env.js +3 -2
  421. package/dist/workspace/resolve-computer.d.ts +55 -10
  422. package/dist/workspace/resolve-computer.js +66 -14
  423. package/dist/workspace/run-tools.d.ts +15 -31
  424. package/dist/workspace/run-tools.js +19 -30
  425. package/dist/workspace/workspace.d.ts +5 -0
  426. package/dist/workspace-paths.d.ts +0 -17
  427. package/dist/workspace-paths.js +1 -41
  428. package/dist/workspace.d.ts +0 -17
  429. package/dist/workspace.js +4 -110
  430. package/package.json +14 -14
  431. package/skills/agentrun-serve/SKILL.md +1 -1
  432. package/templates/README.md +11 -5
  433. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  434. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  435. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  436. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  437. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  438. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  439. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  440. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  441. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  442. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  443. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  444. package/templates/market-monitor/agent.md +2 -2
  445. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  446. package/templates/release-notes/agent.md +11 -0
  447. package/dist/bound-files.d.ts +0 -4
  448. package/dist/bound-files.js +0 -164
  449. package/dist/coding-tools.d.ts +0 -47
  450. package/dist/coding-tools.js +0 -189
  451. package/dist/computer-adb.d.ts +0 -12
  452. package/dist/computer-adb.js +0 -14
  453. package/dist/console/assets/index-Dn0ngwG9.js +0 -535
  454. package/dist/console/assets/index-DvW6Aled.css +0 -1
  455. package/dist/grade.d.ts +0 -63
  456. package/dist/grade.js +0 -150
  457. package/dist/mcp-servers.d.ts +0 -269
  458. package/dist/mcp-servers.js +0 -456
  459. package/dist/packs.d.ts +0 -71
  460. package/dist/packs.js +0 -180
  461. package/dist/sealed-settings.d.ts +0 -60
  462. package/dist/sealed-settings.js +0 -171
  463. package/dist/sessions.d.ts +0 -6
  464. package/dist/sessions.js +0 -109
  465. package/dist/workspace/computer-serves.d.ts +0 -12
  466. package/dist/workspace/computer-serves.js +0 -15
@@ -12,7 +12,7 @@ type ToolKeysStore = {
12
12
  /** What the start's log line says to a person when saved keys do not open, by why: where they are kept is the server's
13
13
  * store (`kept=store`), and what to do is to save them again in the console's Settings. */
14
14
  export declare const REENTER_SAID: Readonly<Record<(typeof UNREADABLE)[number], string>>;
15
- /** The store-backed ToolKeys. `toolKeysOverStore` builds it; the switch awaits load() once before the first read. */
15
+ /** The saved tool keys over the store. `toolKeysOverStore` builds it; the server awaits load() once before the first read. */
16
16
  declare class ToolKeysOverStore {
17
17
  private readonly store;
18
18
  private readonly env;
@@ -30,15 +30,15 @@ declare class ToolKeysOverStore {
30
30
  /** The checks and fingerprints the settings row holds, failing closed (an unreadable row reads as none, so no value is
31
31
  * lost and each field is just asked to be checked again). */
32
32
  private readChecks;
33
- /** Opens a field's sealed bytes now, or why not: no seal key (seal_key_missing); a fingerprint that no longer matches
34
- * (seal_key_changed); else unseal, which fails as file_unreadable. */
33
+ /** Opens a field's sealed bytes now, or why not: a fingerprint that no longer matches (seal_key_changed); else unseal,
34
+ * which fails as file_unreadable. */
35
35
  private openAt;
36
36
  /** The stored value of the field `name`, opened; undefined with none, or one that does not open: never a clear fallback. */
37
37
  value(name: string): string | undefined;
38
38
  /** Every stored value that opens, by field name. */
39
39
  values(): Record<string, string>;
40
40
  /** GET: each key's fields, whether set and where from (never a value), what it unlocks, its check, and what to enter
41
- * again, with why. The ToolKeys.view shape, over the snapshot. */
41
+ * again, with why. Over the snapshot. */
42
42
  view(offers?: Parameters<typeof rowUnlocks>[3]): {
43
43
  keys: {
44
44
  fields: ({
@@ -75,17 +75,17 @@ declare class ToolKeysOverStore {
75
75
  label: string;
76
76
  }[];
77
77
  reenter: {
78
- reason: "seal_key_missing" | "seal_key_changed" | "file_unreadable";
78
+ reason: "seal_key_changed" | "file_unreadable";
79
79
  fields: string[];
80
80
  } | null;
81
81
  };
82
82
  /** Each tool key the server is started with, checked against its provider once (key-check.ts), all at once; `answered`
83
- * as each answers unless `stop` came first. Held in memory for this start, like ToolKeys.checkServer. */
83
+ * as each answers unless `stop` came first. Held in memory for this start. */
84
84
  checkServer(fetchFor: (id: string) => Promise<typeof fetch | null>, stop: AbortSignal, answered: () => void): Promise<void>;
85
85
  /** The variables of the keys the server was started with that their provider refused at the start, each with why. */
86
86
  refused(): Record<string, string>;
87
87
  /** A PUT's check, before save(): the key it sends checked against its provider, or 422 when the provider refuses it;
88
- * undefined when the body sends no key. The ToolKeys.check shape. */
88
+ * undefined when the body sends no key. */
89
89
  check(id: string, body: Record<string, unknown>, fetchFor: (id: string) => Promise<typeof fetch | undefined>, stop?: AbortSignal): Promise<KeyCheck | undefined>;
90
90
  /** PUT: each of `body.values` sealed under the seal key in its own row, the check kept for the key when given; the key's
91
91
  * other fields stay as they are. Durable before it resolves (as writeDurableSync was), so a 204 never outruns the disk. */
@@ -94,17 +94,16 @@ declare class ToolKeysOverStore {
94
94
  remove(id: string): Promise<void>;
95
95
  /** The checks and fingerprints written back as one settings row. */
96
96
  private writeChecks;
97
- /** What a PUT may save: the key's row and the body's values, or 422 (the body), 409 (a field the server's, or no seal
98
- * key). No message holds a value. The ToolKeys.admit, byte for byte. */
97
+ /** What a PUT may save: the key's row and the body's values, or 422 (the body), 409 (a field the server's). No message
98
+ * holds a value. */
99
99
  private admit;
100
100
  private row;
101
101
  /** 409 when this server's own environment sets one of `names`: that one wins, and is changed where the server starts. */
102
102
  private notServers;
103
103
  }
104
104
  export type { ToolKeysOverStore };
105
- /** The ToolKeys surface over the one store: the switch swaps `new ToolKeys(data, env, say)` for this, then awaits load()
106
- * once at start before the first read. `env` is what the server is started with (its own keys; never a saved one), as
107
- * ToolKeys takes it. */
105
+ /** The saved tool keys over the one store, awaited load() once at start before the first read. `env` is what the server is
106
+ * started with (its own keys, and its seal key; never a saved one). */
108
107
  export declare function toolKeysOverStore(store: ToolKeysStore, env: NodeJS.ProcessEnv, say: (fields: Record<string, string>) => void): ToolKeysOverStore;
109
108
  /** The bytes a value would be sealed as, for a test that checks a field is sealed at rest, not in the clear. */
110
109
  export declare const sealedToolKeyBytes: (key: Buffer, name: string, value: string) => Uint8Array;
@@ -1,15 +1,12 @@
1
- // The keys a person saves for this server's tools, over the one store (A), the store-backed replacement for tool-keys.ts's
2
- // tool-keys.json field store. Each field's value is a sealed row in store.sealedKeys (server-keys.ts, AAD
1
+ // The keys a person saves for this server's tools, over the one store. Each field's value is a sealed row in store.sealedKeys (server-keys.ts, AAD
3
2
  // sealed_keys|<name>|sealed); the store holds ciphertext alone and never opens it. The per-key provider checks and the
4
3
  // seal-key fingerprints that tell "sealed under another key" from "damaged" live in one store.settings row (no secret: a
5
4
  // check is state and a time, a fingerprint is an HMAC of a fixed label, neither the key nor a hash of it). Only this
6
- // process opens a value, with the seal key the launcher hands it (AGENTRUN_SEAL_KEY), never in the data directory.
5
+ // process opens a value, with the server's seal key (seal-key.ts bootSealKey: the server never starts without one).
7
6
  //
8
- // The surface is ToolKeys' (tool-keys.ts), byte for byte, so the switch swaps `new ToolKeys(data, env, say)` for
9
- // `toolKeysOverStore(store, env, say)` without touching a route: value/values/view/refused/checkServer/check are the same
10
- // shapes, and save/remove return a promise the handler awaits (durable before the 204, as writeDurableSync was). The reads
11
- // are served from an in-memory snapshot the server (the one writer of these rows) loads once at start (load()) and keeps in
12
- // step with every write, so a read answers without a round trip, exactly as ToolKeys read its file.
7
+ // save/remove return a promise the handler awaits (durable before the 204). The reads are served from an in-memory
8
+ // snapshot the server (the one writer of these rows) loads once at start (load()) and keeps in step with every write, so a
9
+ // read answers without a round trip.
13
10
  import { createHmac } from "node:crypto";
14
11
  import { decisionsOf } from "./decisions.js";
15
12
  import { ApiError, invalid } from "./errors.js";
@@ -23,11 +20,11 @@ import { isObject, unknownFields } from "./validate.js";
23
20
  export const TOOL_KEY_CHECKS_KEY = "tool-key-checks";
24
21
  const MAX_VALUE_BYTES = 1024;
25
22
  const CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
26
- /** Every field a person may save (the fields of every key row), the same set ToolKeys keeps. */
23
+ /** Every field a person may save (the fields of every key row). */
27
24
  const FIELDS = TOOL_KEYS.flatMap((row) => row.fields);
28
- /** The check a key kept before this server checked keys reads as: none was made. Mirrors ToolKeys' UNCHECKED. */
25
+ /** The check a key kept before this server checked keys reads as: none was made. */
29
26
  const UNCHECKED = { state: "not_checked", reason: "Saved before this server checked keys; save it again to check it" };
30
- /** A check as the store row keeps it, else undefined (mirrors ToolKeys' keptCheck). */
27
+ /** A check as the store row keeps it, else undefined. */
31
28
  const keptCheck = (entry) => !isObject(entry) ? undefined
32
29
  : entry.state === "accepted" && typeof entry.at === "string" ? { state: "accepted", at: entry.at }
33
30
  : entry.state === "not_checked" && typeof entry.reason === "string" ? { state: "not_checked", reason: entry.reason, ...(typeof entry.at === "string" ? { at: entry.at } : {}) }
@@ -39,10 +36,9 @@ const fingerprint = (key) => createHmac("sha256", key).update("agentrun-serve se
39
36
  * store (`kept=store`), and what to do is to save them again in the console's Settings. */
40
37
  export const REENTER_SAID = {
41
38
  seal_key_changed: "these saved keys were sealed under another seal key, so they do not open: save them again in Settings → Tool keys",
42
- seal_key_missing: "no seal key opens these saved keys: start the server with its seal key, or save them again in Settings → Tool keys",
43
39
  file_unreadable: "these saved keys do not read: save them again in Settings → Tool keys",
44
40
  };
45
- /** The store-backed ToolKeys. `toolKeysOverStore` builds it; the switch awaits load() once before the first read. */
41
+ /** The saved tool keys over the store. `toolKeysOverStore` builds it; the server awaits load() once before the first read. */
46
42
  class ToolKeysOverStore {
47
43
  store;
48
44
  env;
@@ -57,10 +53,12 @@ class ToolKeysOverStore {
57
53
  this.store = store;
58
54
  this.env = env;
59
55
  this.say = say;
60
- this.key = sealKeyOf(env[SEAL_KEY_ENV]);
61
- this.sealCheck = this.key && fingerprint(this.key);
62
- if (env[SEAL_KEY_ENV] !== undefined && !this.key)
63
- say({ condition: "seal_key_invalid", name: SEAL_KEY_ENV });
56
+ // There is always a seal key (seal-key.ts bootSealKey): no tool key is ever kept, or read, without one.
57
+ const key = sealKeyOf(env[SEAL_KEY_ENV]);
58
+ if (!key)
59
+ throw new Error(`tool keys are kept under the server's seal key (${SEAL_KEY_ENV}), and none was handed over: the server does not start without one`);
60
+ this.key = key;
61
+ this.sealCheck = fingerprint(key);
64
62
  }
65
63
  /** Reads the store once into the snapshot: each sealed field opened now, the checks and the fingerprints beside them.
66
64
  * Awaited once at start, before the first read. */
@@ -95,11 +93,9 @@ class ToolKeysOverStore {
95
93
  }
96
94
  return { checks, seals };
97
95
  }
98
- /** Opens a field's sealed bytes now, or why not: no seal key (seal_key_missing); a fingerprint that no longer matches
99
- * (seal_key_changed); else unseal, which fails as file_unreadable. */
96
+ /** Opens a field's sealed bytes now, or why not: a fingerprint that no longer matches (seal_key_changed); else unseal,
97
+ * which fails as file_unreadable. */
100
98
  openAt(name, sealed, fp) {
101
- if (!this.key)
102
- return { unreadable: "seal_key_missing" };
103
99
  if (fp !== undefined && fp !== this.sealCheck)
104
100
  return { unreadable: "seal_key_changed" };
105
101
  try {
@@ -124,7 +120,7 @@ class ToolKeysOverStore {
124
120
  }));
125
121
  }
126
122
  /** GET: each key's fields, whether set and where from (never a value), what it unlocks, its check, and what to enter
127
- * again, with why. The ToolKeys.view shape, over the snapshot. */
123
+ * again, with why. Over the snapshot. */
128
124
  view(offers = []) {
129
125
  const again = [];
130
126
  const tools = toolsView(this.env);
@@ -156,7 +152,7 @@ class ToolKeysOverStore {
156
152
  return { keys, reenter };
157
153
  }
158
154
  /** Each tool key the server is started with, checked against its provider once (key-check.ts), all at once; `answered`
159
- * as each answers unless `stop` came first. Held in memory for this start, like ToolKeys.checkServer. */
155
+ * as each answers unless `stop` came first. Held in memory for this start. */
160
156
  async checkServer(fetchFor, stop, answered) {
161
157
  await Promise.all(TOOL_KEYS.filter((row) => row.kind === "tool" && this.env[row.fields[0]]).map(async (row) => {
162
158
  const name = row.fields[0];
@@ -189,7 +185,7 @@ class ToolKeysOverStore {
189
185
  }));
190
186
  }
191
187
  /** A PUT's check, before save(): the key it sends checked against its provider, or 422 when the provider refuses it;
192
- * undefined when the body sends no key. The ToolKeys.check shape. */
188
+ * undefined when the body sends no key. */
193
189
  async check(id, body, fetchFor, stop) {
194
190
  const { row, values } = this.admit(id, body);
195
191
  const name = row.fields[0];
@@ -242,8 +238,8 @@ class ToolKeysOverStore {
242
238
  async writeChecks() {
243
239
  await this.store.settings.put(TOOL_KEY_CHECKS_KEY, { v: 1, checks: Object.fromEntries(this.snapshot.checks), seals: Object.fromEntries(this.snapshot.seals) });
244
240
  }
245
- /** What a PUT may save: the key's row and the body's values, or 422 (the body), 409 (a field the server's, or no seal
246
- * key). No message holds a value. The ToolKeys.admit, byte for byte. */
241
+ /** What a PUT may save: the key's row and the body's values, or 422 (the body), 409 (a field the server's). No message
242
+ * holds a value. */
247
243
  admit(id, body) {
248
244
  const row = this.row(id);
249
245
  const issues = unknownFields(body, ["values"]);
@@ -264,8 +260,6 @@ class ToolKeysOverStore {
264
260
  if (issues.length)
265
261
  throw invalid(issues);
266
262
  this.notServers(Object.keys(values));
267
- if (!this.key)
268
- throw new ApiError("no_sealing_key", `This server was handed no seal key (${SEAL_KEY_ENV}), so it keeps no tool key: it never keeps one in the clear.`);
269
263
  return { row, values };
270
264
  }
271
265
  row(id) {
@@ -281,9 +275,8 @@ class ToolKeysOverStore {
281
275
  throw new ApiError("key_set_by_server", `This server is started with ${held.join(" and ")}: change it where the server is started.`, { details: { fields: held } });
282
276
  }
283
277
  }
284
- /** The ToolKeys surface over the one store: the switch swaps `new ToolKeys(data, env, say)` for this, then awaits load()
285
- * once at start before the first read. `env` is what the server is started with (its own keys; never a saved one), as
286
- * ToolKeys takes it. */
278
+ /** The saved tool keys over the one store, awaited load() once at start before the first read. `env` is what the server is
279
+ * started with (its own keys, and its seal key; never a saved one). */
287
280
  export function toolKeysOverStore(store, env, say) {
288
281
  return new ToolKeysOverStore(store, env, say);
289
282
  }
@@ -1,6 +1,5 @@
1
- import { type KeyCheck } from "./key-check.js";
1
+ import type { KeyCheck } from "./key-check.js";
2
2
  import { type SecretMeta } from "./secret-writes.js";
3
- export declare const TOOL_KEYS_FILE = "tool-keys.json";
4
3
  export declare const SEAL_KEY_ENV = "AGENTRUN_SEAL_KEY";
5
4
  /** Each key a person may save, fixed here: its kind, the fields it is entered as (BROWSERBASE_PROJECT_ID is no secret,
6
5
  * and is kept the same way), and what it may unlock: tools by name, and `decisions.<id>`, a workflow's decision
@@ -82,10 +81,10 @@ export declare function rowUnlocks(row: {
82
81
  };
83
82
  /** The key that unlocks the tool `name` (capabilities' `tools[].key`, so a page links "needs the X key" to it), if any. */
84
83
  export declare const keyOf: (name: string) => string | undefined;
85
- /** Why a stored value does not open, in the order a re-entry names one: no seal key now, another than it was sealed
86
- * under, or the file (or its entry) damaged. */
87
- export declare const UNREADABLE: readonly ["seal_key_missing", "seal_key_changed", "file_unreadable"];
88
- /** The check of a key the server was started with (ToolKeys.checkServer): a KeyCheck, or refused by its provider, why in
84
+ /** Why a stored value does not open, in the order a re-entry names one: sealed under another key than the server's, or
85
+ * its row damaged. */
86
+ export declare const UNREADABLE: readonly ["seal_key_changed", "file_unreadable"];
87
+ /** The check of a key the server was started with (tool-keys-store.ts checkServer): a KeyCheck, or refused by its provider, why in
89
88
  * plain words. Held in memory only, for this start. */
90
89
  export type StartCheck = KeyCheck | {
91
90
  state: "refused";
@@ -105,98 +104,3 @@ export declare function rowSecrets(row: {
105
104
  }[], changedAt: (name: string) => string | null): SecretMeta[];
106
105
  /** The seal key `text` gives: 32 bytes in base64 (or base64url), else none. */
107
106
  export declare function sealKeyOf(text: string | undefined): Buffer | undefined;
108
- export declare class ToolKeys {
109
- private readonly env;
110
- private readonly say;
111
- readonly file: string;
112
- private readonly key;
113
- private readonly sealCheck;
114
- private said;
115
- /** The checks of the keys the server was started with, by key id, each once it answered (checkServer). */
116
- private readonly started;
117
- /** `env` is what the server is started with (withSecrets' `"own"`, never a saved key, or each would read as the
118
- * server's and could not be deleted): a field it sets is the server's, and wins. `say` takes a log line's fields. */
119
- constructor(data: string, env: NodeJS.ProcessEnv, say: (fields: Record<string, string>) => void);
120
- /** The file's entries, none with no file; "unreadable" when it does not read as this format. A file from before checks
121
- * has none. */
122
- private kept;
123
- private open;
124
- /** The stored value of the field `name`, opened now (secrets.ts reads a saved key by name through this); undefined
125
- * with none, or one that does not open, which view() asks for again: never a clear fallback. */
126
- value(name: string): string | undefined;
127
- /** Every stored value that opens, by field name. */
128
- values(): Record<string, string>;
129
- /** GET: each key's fields, whether set and where from (never a value), what it unlocks of what capabilities shows
130
- * here (a model key: the harnesses `offers` says this server runs or would on the key), its check when its key (its first field) is
131
- * stored here (null otherwise: the server's own is not checked here), and what to enter again, with why. */
132
- view(offers?: Parameters<typeof rowUnlocks>[3]): {
133
- keys: {
134
- fields: ({
135
- name: string;
136
- set: boolean;
137
- source: "server";
138
- } | {
139
- name: string;
140
- set: boolean;
141
- source: "stored";
142
- } | {
143
- stored_unreadable?: true | undefined;
144
- name: string;
145
- set: boolean;
146
- source: null;
147
- })[];
148
- secrets: SecretMeta[];
149
- check: {
150
- state: "accepted";
151
- at: string;
152
- } | {
153
- state: "not_checked";
154
- reason: string;
155
- at?: string;
156
- } | {
157
- state: "refused";
158
- reason: string;
159
- at: string;
160
- } | null;
161
- unlocks: string[];
162
- harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
163
- id: string;
164
- kind: "model" | "tool";
165
- label: string;
166
- }[];
167
- reenter: {
168
- reason: "seal_key_missing" | "seal_key_changed" | "file_unreadable";
169
- fields: string[];
170
- } | null;
171
- };
172
- /** Each tool key the server is started with (a `tool` row whose key, its first field, the server sets), checked against
173
- * its provider once, as a saved one is (key-check.ts), through the fetch `fetchFor` gives for the row (null: not
174
- * checked, its check stays null); all at once, none holding up another or the start. `answered` is called as each
175
- * answers, unless `stop` (the server closing) came first. A fetch that cannot be made (a fake that does not load)
176
- * reads as not checked, saying so; this never rejects. A model key is not checked here: a run on a refused one fails
177
- * at its first request, saying so. */
178
- checkServer(fetchFor: (id: string) => Promise<typeof fetch | null>, stop: AbortSignal, answered: () => void): Promise<void>;
179
- /** The variables of the keys the server was started with that their provider refused at the start, each with why
180
- * (capabilities' tools that need one read unavailable: tools.ts toolsView). */
181
- refused(): Record<string, string>;
182
- /** A PUT's check, before save(): the key it sends (its row's first field; Browserbase's project id is no key) checked
183
- * against its provider (key-check.ts), the fetch `fetchFor` gives for the row (undefined: none, so not checked), its
184
- * wait cut by `stop`. The body is held to what save() takes first, so a save that would be refused sends nothing. A
185
- * key the provider refuses is 422 in its words, and nothing is kept; undefined when the body sends no key: the row's
186
- * check stays as it was. */
187
- check(id: string, body: Record<string, unknown>, fetchFor: (id: string) => Promise<typeof fetch | undefined>, stop?: AbortSignal): Promise<KeyCheck | undefined>;
188
- /** PUT: each of `body.values` sealed under the seal key, and `check` (check()'s) kept for the key when given; the key's
189
- * other fields stay as they are. A key saved with no check (a caller other than the route) drops the one it had. */
190
- save(id: string, body: Record<string, unknown>, check?: KeyCheck): void;
191
- /** What a PUT may save: the key's row and the body's values, or 422 (the body), 409 (a field the server's, or no seal
192
- * key). No message holds a value, or any part of one. */
193
- private admit;
194
- /** DELETE: the key's stored fields gone, and its check. Refused only when the server sets every field of it: none is
195
- * the page's. */
196
- remove(id: string): void;
197
- private row;
198
- /** 409 when this server's own environment (its launcher) sets one of `names`: that one wins, and is changed where the
199
- * server is started. */
200
- private notServers;
201
- private write;
202
- }
package/dist/tool-keys.js CHANGED
@@ -1,38 +1,17 @@
1
- // The keys a person saves for this server's tools, by name, through /v2/settings/tool-keys. DIR/tool-keys.json (0600,
2
- // written whole and synced, then renamed) holds them only as AES-256-GCM ciphertext (pi-durable-agent's `seal`) under the seal
3
- // key the launcher hands the server (AGENTRUN_SEAL_KEY), which is never in the data directory: a copy of the directory
4
- // holds ciphertext alone. Each value is bound to its field's name and this format, so one moved to another name does
5
- // not open, and carries a check of the key it was sealed under (an HMAC of a fixed label, neither the key nor a hash of
6
- // it), so a value sealed under another key reads as that, told apart from a damaged one. Only this process opens a
7
- // value, when it is asked for. One that does not open is never a crash and never a clear fallback: it reads as not
8
- // set, to be entered again, and the log says why once, naming the file, never a value. The server reads a saved value by
9
- // name as it reads a launcher's secret (secrets.ts' `secret`), the launcher's winning: a run gets it over its pipe (a
10
- // decision key on its decision descriptor) at its launch, and capabilities and checks see it once it is saved. A key is
11
- // checked against its provider before it is kept (key-check.ts): one the provider refuses is never kept, and the file
12
- // keeps, beside the sealed values, whether each key was accepted or kept not checked, and why (never any of a value).
13
- import { createHmac } from "node:crypto";
14
- import { readFileSync } from "node:fs";
15
- import { join } from "node:path";
16
- import { seal, unseal } from "@parcha/pi-durable-agent";
17
- import { decisionsOf } from "./decisions.js";
18
- import { ApiError, invalid } from "./errors.js";
19
- import { writeDurableSync } from "./files.js";
1
+ // The keys a person saves for this server's tools and models, by name, through /v2/settings/tool-keys: the rows each key
2
+ // is entered as and what it unlocks, the words a re-entry gives, and the seal key's name and reading. The values are kept
3
+ // sealed in the one store (tool-keys-store.ts), opened only by the server, never in the clear; a key is checked against
4
+ // its provider before it is kept (key-check.ts). The server reads a saved value by name as it reads a launcher's secret
5
+ // (secrets.ts' `secret`), the launcher's winning: a run gets it over its claim, never its environment.
20
6
  import { HARNESSES } from "./harness.js";
21
- import { checkKey } from "./key-check.js";
22
- import { toolsView } from "./tools.js";
23
7
  import { MODEL_KEYS } from "./model.js";
24
8
  import { TOOL_KEY_ROWS } from "./key-words.js";
25
- import { isObject, unknownFields } from "./validate.js";
26
9
  import { registerSecretWrite, secretMeta, secretName } from "./secret-writes.js";
27
10
  // Every value a person saves here is a secret (a tool's key, a model provider's key; BROWSERBASE_PROJECT_ID is kept the
28
11
  // same way): saving one, replacing it or removing it takes the owner's session (secret-writes.ts), never the token.
29
12
  registerSecretWrite("saveToolKey", () => true);
30
13
  registerSecretWrite("deleteToolKey", () => true);
31
- export const TOOL_KEYS_FILE = "tool-keys.json";
32
14
  export const SEAL_KEY_ENV = "AGENTRUN_SEAL_KEY";
33
- const FORMAT = "tool-keys/1";
34
- const MAX_VALUE_BYTES = 1024;
35
- const CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
36
15
  /** Each key a person may save, fixed here: its kind, the fields it is entered as (BROWSERBASE_PROJECT_ID is no secret,
37
16
  * and is kept the same way), and what it may unlock: tools by name, and `decisions.<id>`, a workflow's decision
38
17
  * provider. GET lists only those this server binds (unlockedBy), so a name here the server does not bind is never
@@ -45,7 +24,6 @@ export const TOOL_KEYS = [
45
24
  // launcher's model keys reach every run. Its harnesses are pi and those that talk to the provider's API (MODEL_KEYS).
46
25
  ...MODEL_KEYS.map(({ id, label, field, harnesses }) => ({ id, kind: "model", label, fields: [field], unlocks: [], harnesses })),
47
26
  ];
48
- const FIELDS = TOOL_KEYS.flatMap((row) => row.fields);
49
27
  /** The fields of the `tool` rows: keys a tool or a decision provider reads, and no harness (the harnesses read their
50
28
  * packages, their pins and their models' keys). A row of another kind (a model's) is outside them. */
51
29
  export const TOOL_FIELDS = TOOL_KEYS.filter((row) => row.kind === "tool").flatMap((row) => row.fields);
@@ -75,16 +53,9 @@ export function rowUnlocks(row, tools, providers, offers) {
75
53
  }
76
54
  /** The key that unlocks the tool `name` (capabilities' `tools[].key`, so a page links "needs the X key" to it), if any. */
77
55
  export const keyOf = (name) => TOOL_KEYS.find((row) => row.unlocks.includes(name))?.id;
78
- /** Why a stored value does not open, in the order a re-entry names one: no seal key now, another than it was sealed
79
- * under, or the file (or its entry) damaged. */
80
- export const UNREADABLE = ["seal_key_missing", "seal_key_changed", "file_unreadable"];
81
- /** The check a key kept before this server checked keys reads as: none was made. */
82
- const UNCHECKED = { state: "not_checked", reason: "Saved before this server checked keys; save it again to check it" };
83
- /** A check as the file keeps it, else undefined. */
84
- const keptCheck = (entry) => !isObject(entry) ? undefined
85
- : entry.state === "accepted" && typeof entry.at === "string" ? { state: "accepted", at: entry.at }
86
- : entry.state === "not_checked" && typeof entry.reason === "string" ? { state: "not_checked", reason: entry.reason, ...(typeof entry.at === "string" ? { at: entry.at } : {}) }
87
- : undefined;
56
+ /** Why a stored value does not open, in the order a re-entry names one: sealed under another key than the server's, or
57
+ * its row damaged. */
58
+ export const UNREADABLE = ["seal_key_changed", "file_unreadable"];
88
59
  /** A key row's secrets as every secret's view says them (secret-writes.ts SecretMeta): one per field, named
89
60
  * "<kind>:<FIELD>" (tool:MONID_API_KEY, model:OPENROUTER_API_KEY); source env when the server is started with it, console
90
61
  * when the owner saved it; `changedAt` the time that field's own value was saved (its own row in the store, its own entry
@@ -100,233 +71,3 @@ export function sealKeyOf(text) {
100
71
  const trimmed = text?.trim() ?? "";
101
72
  return /^[A-Za-z0-9+/_-]{43}=?$/.test(trimmed) ? Buffer.from(trimmed, "base64") : undefined;
102
73
  }
103
- const aad = (name) => `${FORMAT}|${name}`;
104
- export class ToolKeys {
105
- env;
106
- say;
107
- file;
108
- key;
109
- sealCheck;
110
- said = "";
111
- /** The checks of the keys the server was started with, by key id, each once it answered (checkServer). */
112
- started = {};
113
- /** `env` is what the server is started with (withSecrets' `"own"`, never a saved key, or each would read as the
114
- * server's and could not be deleted): a field it sets is the server's, and wins. `say` takes a log line's fields. */
115
- constructor(data, env, say) {
116
- this.env = env;
117
- this.say = say;
118
- this.file = join(data, TOOL_KEYS_FILE);
119
- this.key = sealKeyOf(env[SEAL_KEY_ENV]);
120
- this.sealCheck = this.key && createHmac("sha256", this.key).update(`agentrun-serve ${FORMAT} key check`).digest("base64url");
121
- if (env[SEAL_KEY_ENV] !== undefined && !this.key)
122
- say({ condition: "seal_key_invalid", name: SEAL_KEY_ENV });
123
- }
124
- /** The file's entries, none with no file; "unreadable" when it does not read as this format. A file from before checks
125
- * has none. */
126
- kept() {
127
- try {
128
- const doc = JSON.parse(readFileSync(this.file, "utf8"));
129
- if (!isObject(doc) || doc.v !== 1 || !isObject(doc.fields))
130
- return "unreadable";
131
- const checks = Object.entries(isObject(doc.checks) ? doc.checks : {}).flatMap(([id, entry]) => {
132
- const check = keptCheck(entry);
133
- return check ? [[id, check]] : [];
134
- });
135
- return { fields: { ...doc.fields }, checks: Object.fromEntries(checks) };
136
- }
137
- catch (error) {
138
- return error.code === "ENOENT" ? { fields: {}, checks: {} } : "unreadable";
139
- }
140
- }
141
- open(name, entry) {
142
- if (!this.key)
143
- return { unreadable: "seal_key_missing" };
144
- if (!isObject(entry) || typeof entry.sealed !== "string" || typeof entry.check !== "string")
145
- return { unreadable: "file_unreadable" };
146
- if (entry.check !== this.sealCheck)
147
- return { unreadable: "seal_key_changed" };
148
- try {
149
- return { value: unseal(this.key, Buffer.from(entry.sealed, "base64"), aad(name)).toString("utf8") };
150
- }
151
- catch {
152
- return { unreadable: "file_unreadable" };
153
- }
154
- }
155
- /** The stored value of the field `name`, opened now (secrets.ts reads a saved key by name through this); undefined
156
- * with none, or one that does not open, which view() asks for again: never a clear fallback. */
157
- value(name) {
158
- if (!FIELDS.includes(name))
159
- return undefined;
160
- const kept = this.kept();
161
- const opened = kept !== "unreadable" && kept.fields[name] !== undefined ? this.open(name, kept.fields[name]) : undefined;
162
- return opened && "value" in opened ? opened.value : undefined;
163
- }
164
- /** Every stored value that opens, by field name. */
165
- values() {
166
- return Object.fromEntries(FIELDS.flatMap((name) => {
167
- const value = this.value(name);
168
- return value === undefined ? [] : [[name, value]];
169
- }));
170
- }
171
- /** GET: each key's fields, whether set and where from (never a value), what it unlocks of what capabilities shows
172
- * here (a model key: the harnesses `offers` says this server runs or would on the key), its check when its key (its first field) is
173
- * stored here (null otherwise: the server's own is not checked here), and what to enter again, with why. */
174
- view(offers = []) {
175
- const kept = this.kept();
176
- const again = [];
177
- const tools = toolsView(this.env);
178
- const providers = decisionsOf(this.env);
179
- const keys = TOOL_KEYS.map((row) => {
180
- const fields = row.fields.map((name) => {
181
- if (this.env[name])
182
- return { name, set: true, source: "server" };
183
- const opened = kept !== "unreadable" && kept.fields[name] !== undefined ? this.open(name, kept.fields[name]) : undefined;
184
- if (opened && "value" in opened)
185
- return { name, set: true, source: "stored" };
186
- if (opened)
187
- again.push({ name, why: opened.unreadable });
188
- return { name, set: false, source: null, ...(opened ? { stored_unreadable: true } : {}) };
189
- });
190
- const check = fields[0].source === "stored" && kept !== "unreadable" ? (kept.checks[row.id] ?? UNCHECKED) : fields[0].source === "server" ? (this.started[row.id] ?? null) : null;
191
- const secrets = rowSecrets(row, fields, (name) => (kept !== "unreadable" && isObject(kept.fields[name]) && typeof kept.fields[name].changed_at === "string" ? kept.fields[name].changed_at : null));
192
- return { id: row.id, kind: row.kind, label: row.label, ...rowUnlocks(row, tools, providers, offers), fields, secrets, check };
193
- });
194
- // A file that does not read as a whole names no field: which it held is unknown.
195
- const reason = kept === "unreadable" ? "file_unreadable" : UNREADABLE.find((why) => again.some((field) => field.why === why));
196
- const reenter = reason ? { reason, fields: again.map((field) => field.name) } : null;
197
- const said = JSON.stringify(reenter);
198
- if (reenter && said !== this.said)
199
- this.say({ condition: reenter.reason, file: this.file, fields: reenter.fields.join(",") || "unknown" });
200
- this.said = said;
201
- return { keys, reenter };
202
- }
203
- /** Each tool key the server is started with (a `tool` row whose key, its first field, the server sets), checked against
204
- * its provider once, as a saved one is (key-check.ts), through the fetch `fetchFor` gives for the row (null: not
205
- * checked, its check stays null); all at once, none holding up another or the start. `answered` is called as each
206
- * answers, unless `stop` (the server closing) came first. A fetch that cannot be made (a fake that does not load)
207
- * reads as not checked, saying so; this never rejects. A model key is not checked here: a run on a refused one fails
208
- * at its first request, saying so. */
209
- async checkServer(fetchFor, stop, answered) {
210
- await Promise.all(TOOL_KEYS.filter((row) => row.kind === "tool" && this.env[row.fields[0]]).map(async (row) => {
211
- const name = row.fields[0];
212
- let fetcher;
213
- try {
214
- fetcher = await fetchFor(row.id);
215
- }
216
- catch (error) {
217
- if (stop.aborted)
218
- return;
219
- const why = error?.code ?? error?.name ?? "an error";
220
- this.started[row.id] = { state: "not_checked", reason: `${row.label}'s key could not be checked: its check did not start (${why})`, at: new Date().toISOString() };
221
- answered();
222
- return;
223
- }
224
- if (!fetcher)
225
- return;
226
- const outcome = await checkKey(row, this.env[name], this.env, fetcher, undefined, stop, name).catch(() => undefined);
227
- if (!outcome || stop.aborted)
228
- return;
229
- this.started[row.id] = outcome.state === "refused" ? { state: "refused", reason: `${outcome.message} when this server started: set the right one where AgentRun starts, then restart it`, at: new Date().toISOString() } : outcome;
230
- answered();
231
- }));
232
- }
233
- /** The variables of the keys the server was started with that their provider refused at the start, each with why
234
- * (capabilities' tools that need one read unavailable: tools.ts toolsView). */
235
- refused() {
236
- return Object.fromEntries(TOOL_KEYS.flatMap((row) => {
237
- const check = this.started[row.id];
238
- return check?.state === "refused" ? [[row.fields[0], check.reason]] : [];
239
- }));
240
- }
241
- /** A PUT's check, before save(): the key it sends (its row's first field; Browserbase's project id is no key) checked
242
- * against its provider (key-check.ts), the fetch `fetchFor` gives for the row (undefined: none, so not checked), its
243
- * wait cut by `stop`. The body is held to what save() takes first, so a save that would be refused sends nothing. A
244
- * key the provider refuses is 422 in its words, and nothing is kept; undefined when the body sends no key: the row's
245
- * check stays as it was. */
246
- async check(id, body, fetchFor, stop) {
247
- const { row, values } = this.admit(id, body);
248
- const name = row.fields[0];
249
- if (values[name] === undefined)
250
- return undefined;
251
- const outcome = await checkKey(row, values[name], this.env, await fetchFor(row.id), undefined, stop);
252
- if (outcome.state === "refused")
253
- throw invalid([{ field: `values.${name}`, reason: "refused_by_provider", message: outcome.message }]);
254
- return outcome;
255
- }
256
- /** PUT: each of `body.values` sealed under the seal key, and `check` (check()'s) kept for the key when given; the key's
257
- * other fields stay as they are. A key saved with no check (a caller other than the route) drops the one it had. */
258
- save(id, body, check) {
259
- const { row, values } = this.admit(id, body);
260
- const kept = this.kept();
261
- // A file that does not read is replaced: what it held opens nowhere.
262
- const { fields, checks } = kept === "unreadable" ? { fields: {}, checks: {} } : kept;
263
- // Each field keeps its own changed_at: saving one key never moves another's.
264
- const at = new Date().toISOString();
265
- for (const [name, value] of Object.entries(values))
266
- fields[name] = { sealed: seal(this.key, Buffer.from(value, "utf8"), aad(name)).toString("base64"), check: this.sealCheck, changed_at: at };
267
- if (values[row.fields[0]] !== undefined)
268
- delete checks[row.id];
269
- if (check)
270
- checks[row.id] = check;
271
- this.write(fields, checks);
272
- }
273
- /** What a PUT may save: the key's row and the body's values, or 422 (the body), 409 (a field the server's, or no seal
274
- * key). No message holds a value, or any part of one. */
275
- admit(id, body) {
276
- const row = this.row(id);
277
- const issues = unknownFields(body, ["values"]);
278
- const values = isObject(body.values) ? body.values : {};
279
- if (!Object.keys(values).length)
280
- issues.push({ field: "values", reason: body.values === undefined ? "missing" : "wrong_type", message: `values holds one or more of ${row.fields.join(", ")}, by name` });
281
- for (const [name, value] of Object.entries(values)) {
282
- const field = `values.${name}`;
283
- if (!row.fields.includes(name))
284
- issues.push({ field, reason: "not_allowed", message: `The key ${row.id} has the fields ${row.fields.join(", ")}.` });
285
- else if (typeof value !== "string" || value === "")
286
- issues.push({ field, reason: "wrong_type", message: `${name} is text, not empty` });
287
- else if (CONTROL.test(value))
288
- issues.push({ field, reason: "invalid", message: `${name} holds a control character` });
289
- else if (Buffer.byteLength(value) > MAX_VALUE_BYTES)
290
- issues.push({ field, reason: "too_long", message: `${name} is at most ${MAX_VALUE_BYTES} bytes` });
291
- }
292
- if (issues.length)
293
- throw invalid(issues);
294
- this.notServers(Object.keys(values));
295
- if (!this.key)
296
- throw new ApiError("no_sealing_key", `This server was handed no seal key (${SEAL_KEY_ENV}), so it keeps no tool key: it never keeps one in the clear.`);
297
- return { row, values };
298
- }
299
- /** DELETE: the key's stored fields gone, and its check. Refused only when the server sets every field of it: none is
300
- * the page's. */
301
- remove(id) {
302
- const row = this.row(id);
303
- if (row.fields.every((name) => this.env[name]))
304
- this.notServers(row.fields);
305
- const kept = this.kept();
306
- if (kept !== "unreadable" && !row.fields.some((name) => name in kept.fields))
307
- return;
308
- const { fields, checks } = kept === "unreadable" ? { fields: {}, checks: {} } : kept;
309
- for (const name of row.fields)
310
- delete fields[name];
311
- delete checks[row.id];
312
- this.write(fields, checks);
313
- }
314
- row(id) {
315
- const row = TOOL_KEYS.find((r) => r.id === id);
316
- if (!row)
317
- throw invalid([{ field: "key_id", reason: "not_an_option", message: `The tool keys are ${TOOL_KEYS.map((r) => r.id).join(", ")}.` }]);
318
- return row;
319
- }
320
- /** 409 when this server's own environment (its launcher) sets one of `names`: that one wins, and is changed where the
321
- * server is started. */
322
- notServers(names) {
323
- const held = names.filter((name) => this.env[name]);
324
- if (held.length)
325
- throw new ApiError("key_set_by_server", `This server is started with ${held.join(" and ")}: change it where the server is started.`, { details: { fields: held } });
326
- }
327
- write(fields, checks) {
328
- // On disk, the file and then its directory, before the 204: a crash after it neither loses a saved key nor brings
329
- // back a forgotten one.
330
- writeDurableSync(this.file, `${JSON.stringify({ v: 1, fields, checks }, null, 2)}\n`);
331
- }
332
- }