@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
@@ -15,9 +15,11 @@ import { CAP_TOLERANCE, money } from "./cap.js";
15
15
  import { ApiError, invalid, unsupported } from "./errors.js";
16
16
  import { harnessOfBody } from "./harness.js";
17
17
  import { redacted, redactedOutput } from "./key-refusal.js";
18
- import { givenOf, LEARNING_BUDGET, learnedOf } from "./learning.js";
18
+ import { chooseWorkflows, LEARNING_BUDGET, learnedParts } from "./learning.js";
19
+ import { thinkingLevel } from "./model.js";
19
20
  import { resolvePlace } from "./place.js";
20
21
  import { launchBody } from "./run-launch.js";
22
+ import { raiseFollowUpId } from "./run-view.js";
21
23
  import { sendCommand } from "./runner/commands.js";
22
24
  import { ExternalBodyConflict, RunFinal, StoreConstraint } from "./store/index.js";
23
25
  import { toolingOf } from "./tools.js";
@@ -155,9 +157,12 @@ export async function message(store, moment, content, { requestId, answers = tru
155
157
  await sendCommand(store, moment.id, { kind: "steer", body });
156
158
  return { mode, messageId };
157
159
  }
158
- /** The raise command rows this run already has, newest last, with the cap each names. */
160
+ /** The raise command rows this run already has, newest last: the cap each names, and whether its runner has taken it. */
159
161
  async function raiseRows(store, runId) {
160
- return (await store.commands(runId, 0)).filter((c) => c.kind === "raise").map((c) => Number(c.body?.capUsd)).filter((n) => Number.isFinite(n));
162
+ return (await store.commands(runId, 0))
163
+ .filter((c) => c.kind === "raise")
164
+ .map((c) => ({ capUsd: Number(c.body?.capUsd), taken: c.takenAt !== null }))
165
+ .filter((row) => Number.isFinite(row.capUsd));
161
166
  }
162
167
  /** Raises the cap of an agentic or workflow run that names one, to `cap`: above its own (by more than CAP_TOLERANCE), or the
163
168
  * same as its newest raise (a retry, which changes nothing). A raise command row the run's runner reads: it resumes a run
@@ -173,9 +178,15 @@ export async function raiseCap(store, moment, cap) {
173
178
  throw invalid([{ field: "max_cost_usd", reason: "not_allowed", message: "This run has no cap to raise: a cap is named when a run starts." }]);
174
179
  const raises = await raiseRows(store, moment.id);
175
180
  const last = raises.at(-1);
176
- // The same raise again (a retry): what the first one did stands, no second row.
177
- if (Math.abs(cap - from) <= CAP_TOLERANCE && last !== undefined && Math.abs(last - cap) <= CAP_TOLERANCE) {
178
- return moment.paused ? { resumed: true } : { resumed: false };
181
+ // An agentic run paused at its cap goes on with one follow-up turn the runner sends under its pause's id
182
+ // (raiseFollowUpId): the answer names it, so every raise of this pause (a retry, two sent at once) names the same message.
183
+ // A workflow run sends none (the step that waits is judged again), so its answer names no message.
184
+ const resumed = () => ({ resumed: true, ...(moment.kind === "agentic" && moment.pause !== undefined ? { messageId: raiseFollowUpId(moment.pause) } : {}) });
185
+ // The same raise again (a retry): what the first one did stands, no second row. It resumes the run only while that raise
186
+ // is still on its way (its row untaken): once taken, a pause the run stands at now is a new one, under the raised cap,
187
+ // which this retry does not raise (it answers resumed false, and the run stays paused).
188
+ if (Math.abs(cap - from) <= CAP_TOLERANCE && last !== undefined && Math.abs(last.capUsd - cap) <= CAP_TOLERANCE) {
189
+ return moment.paused && !last.taken ? resumed() : { resumed: false };
179
190
  }
180
191
  if (!(cap > from + CAP_TOLERANCE))
181
192
  throw invalid([{ field: "max_cost_usd", reason: "invalid", message: `A cap is only raised: name more than the run's ${money(from)}.` }]);
@@ -192,7 +203,7 @@ export async function raiseCap(store, moment, cap) {
192
203
  }
193
204
  // A run paused at its cap is brought back by the raise (its runner claims it and sends its continuation).
194
205
  if (moment.paused)
195
- return { resumed: true };
206
+ return resumed();
196
207
  // A run its runner holds takes the raise as its next command: its next step is admitted under the raised cap (the
197
208
  // runner's loop holds the run to its newest raise), and a step already under way keeps the cap it was admitted at.
198
209
  return { resumed: false, ...(moment.live ? { note: `The ${money(cap)} cap holds from the run's next step; a step already under way keeps the ${money(from)} cap it was admitted at.` } : {}) };
@@ -210,6 +221,17 @@ async function sentAnswer(store, runId, id) {
210
221
  const row = (await store.commands(runId, 0)).find((command) => (command.kind === "approve" || command.kind === "deny") && command.refused === null && isObject(command.body) && command.body.approval === id);
211
222
  return row && { decision: row.kind === "approve" ? "allow" : "deny" };
212
223
  }
224
+ /** How a stop or cancel written to run `runId` before `before` (a command id; absent, any) answers every call still waiting:
225
+ * the runner reads commands in the order they were written, so it applies the stop first and withdraws (or, on a cancel,
226
+ * cancels) the call, and refuses every answer written after it. An answer written then is told so at once, the same 409
227
+ * the call's withdrawal gives, never 204 for a call that will not run. Read by the rows' order, so a stop that lands
228
+ * between this read and the answer's write is caught once the answer is written (approve). Untaken rows only, unless
229
+ * `taken` (a run already final: the end its runner applied). */
230
+ async function endBefore(store, runId, { before = Number.POSITIVE_INFINITY, taken = false } = {}) {
231
+ // The first: the runner applies the first stop or cancel it reads and stops reading there.
232
+ const row = (await store.commands(runId, 0)).find((command) => (command.kind === "stop" || command.kind === "cancel") && command.id < before && command.refused === null && (taken || command.takenAt === null));
233
+ return row && { decision: row.kind === "cancel" ? "canceled" : "withdrawn" };
234
+ }
213
235
  /** A person's answer to the tool call `id` that waits for approval (tool-gate.ts): an approve or deny command row the run's
214
236
  * runner reads and acts on. The first answer wins from the moment it is written, before the runner takes it — the same one
215
237
  * again changes nothing, another is 409 already-answered — and a run with no such waiting call is 404. Two answers at once
@@ -225,16 +247,31 @@ export async function approve(store, moment, id, decision, note) {
225
247
  return settle(given);
226
248
  if (!(moment.approvalIds?.has(id) ?? false))
227
249
  throw new ApiError("not_found", `The run ${moment.id} has no tool call ${id} waiting for approval.`);
250
+ const ending = await endBefore(store, moment.id);
251
+ if (ending)
252
+ throw alreadyAnswered(id, ending.decision);
228
253
  const body = { approval: id, ...(note !== undefined ? { note } : {}) };
254
+ let sent;
229
255
  try {
230
- await sendCommand(store, moment.id, { kind: decision === "allow" ? "approve" : "deny", body });
256
+ sent = await sendCommand(store, moment.id, { kind: decision === "allow" ? "approve" : "deny", body });
231
257
  }
232
258
  catch (error) {
259
+ // The run went final since it was read (its runner took a stop or a cancel, or it ended): its calls were answered by
260
+ // that end, so the answer is told how, never a 500.
261
+ if (error instanceof RunFinal) {
262
+ const end = await endBefore(store, moment.id, { taken: true });
263
+ throw alreadyAnswered(id, end?.decision ?? "withdrawn", end === undefined);
264
+ }
233
265
  const won = error instanceof StoreConstraint ? await sentAnswer(store, moment.id, id) : undefined;
234
266
  if (!won)
235
267
  throw error;
236
- settle(won);
268
+ return settle(won);
237
269
  }
270
+ // A stop or cancel written between the read above and this answer comes first in the runner's order: the answer will be
271
+ // refused at that end, so the person is told now.
272
+ const raced = await endBefore(store, moment.id, { before: sent.id });
273
+ if (raced)
274
+ throw alreadyAnswered(id, raced.decision);
238
275
  }
239
276
  // ---- start -----------------------------------------------------------------------------------------------------------
240
277
  /** A UUIDv7 run id: time-ordered, so a listing by start time is stable, and unique per run. */
@@ -250,21 +287,38 @@ function uuidv7(now = Date.now()) {
250
287
  const noShown = { text: (text) => text, name: (name) => name, holds: () => false };
251
288
  /** The run's learning start as the old start decided it (learning-run.ts onStart): undefined when the run does not learn (the
252
289
  * server's learning off, a workflow revision, or its revision does not say learning), else the notes its # Learned section
253
- * names (givenOf, the one decision the runner puts in the prompt), the # Learned text (learnedOf), the seed sha it starts
290
+ * names and the # Learned text (learnedParts, the one decision the runner puts in the prompt), the seed sha it starts
254
291
  * from and the count of all the seed's notes before the budget picked `given` (seedNotes) — or given empty, seed null and no
255
292
  * seedNotes when its seed cannot be read (a learning fault never refuses a run). */
256
- async function learningStartFor(deps, entry, revision, rbody) {
293
+ async function learningStartFor(deps, entry, revision, rbody, input) {
257
294
  const learns = deps.learning !== undefined && deps.learning !== "off" && revision.kind === "agentic" && rbody.learning === true;
258
295
  if (!learns || !deps.seedFor)
259
296
  return undefined;
297
+ const grade = deps.gradeModel ? { gradeModel: deps.gradeModel } : {};
260
298
  const seeded = await deps.seedFor(entry.agent.id);
299
+ // The folder could not be read (main's STOPPED.unreadable), or what it read could not be made into the start (main's
300
+ // copy that threw, STOPPED.notCopied): the run starts with nothing learned, and its learning end says which.
261
301
  if (!("seed" in seeded))
262
- return { given: [], seed: null, section: "" };
263
- const options = { budget: deps.learningBudget ?? LEARNING_BUDGET, read: Array.isArray(rbody.tools) && rbody.tools.includes("read"), shown: deps.shown ? deps.shown() : noShown };
264
- // The notes and the # Learned text are the old start's one decision (learnedParts): givenOf and learnedOf over the same
265
- // seed and options, so the runner lays exactly this section for exactly these notes and reads no learning folder. seedNotes
266
- // is the whole seed's note count, before the budget narrowed `given` (as the old seed_notes was).
267
- return { given: givenOf(seeded.seed, options), seed: seeded.seed.sha, section: learnedOf(seeded.seed, options) ?? "", seedNotes: Object.keys(seeded.seed.notes).length };
302
+ return { given: [], seed: null, section: "", seedFailed: "unreadable", ...grade };
303
+ try {
304
+ // The run's input goes to the note selector (learning.ts NoteSelector; byRelevance, the default, scores the notes by it).
305
+ const options = { budget: deps.learningBudget ?? LEARNING_BUDGET, read: Array.isArray(rbody.tools) && rbody.tools.includes("read"), shown: deps.shown ? deps.shown() : noShown, run: { input } };
306
+ // The notes and the # Learned text are the old start's one decision (learnedParts: one choice of the note selector), so
307
+ // the runner lays exactly this section for exactly these notes and reads no learning folder. seedNotes is the whole
308
+ // seed's note count, before the budget narrowed `given` (as the old seed_notes was).
309
+ const { section, given } = learnedParts(seeded.seed, options);
310
+ // The learned skills the seed offers the run, by name: each with its files (one over a run's skill budget at all is held
311
+ // by its size and never laid) and no host secret in it, as chooseSkills leaves them out. The claim lays them; the
312
+ // end-of-run turn counts the runs each served (runner/learning-end.ts draftForOf).
313
+ const skills = (seeded.seed.skills ?? []).flatMap(({ name, files }) => (files && !options.shown.holds(name) && !Object.entries(files).some(([path, text]) => options.shown.holds(path) || options.shown.holds(text)) ? [name] : []));
314
+ // The learned workflows its learned_workflow tool runs, by name, as the claim chooses them (chooseWorkflows): what the
315
+ // agent's impact counts a run as started from, beside its notes and skills.
316
+ const workflows = chooseWorkflows(seeded.seed, options.shown).flows.map(({ name }) => name);
317
+ return { given: given.map(({ file, name }) => ({ file, name })), seed: seeded.seed.sha, section: section ?? "", seedNotes: Object.keys(seeded.seed.notes).length, ...(skills.length ? { skills } : {}), ...(workflows.length ? { workflows } : {}), ...grade };
318
+ }
319
+ catch {
320
+ return { given: [], seed: null, section: "", seedFailed: "not_copied", ...grade };
321
+ }
268
322
  }
269
323
  /** Starts a run of `entry`'s agent from a create body, as POST /agents/{id}/runs starts it: every check the old start made
270
324
  * before a run started (prepareLaunch), then an INSERT — a queued run and its launch body in one transaction
@@ -275,7 +329,7 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
275
329
  const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}) });
276
330
  const runId = (deps.newRunId ?? uuidv7)();
277
331
  try {
278
- return await store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}) }, { body: launchBody(launch) });
332
+ return await withHeldFiles(deps, runId, launch, () => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}) }, { body: launchBody(launch) }));
279
333
  }
280
334
  catch (error) {
281
335
  // Only another writer of the store got here first under the same origin key: its run is the one asked for.
@@ -288,6 +342,24 @@ export async function startRun(store, deps, entry, body, { trigger, origin, capp
288
342
  throw error;
289
343
  }
290
344
  }
345
+ /** Writes run `runId` with `write`, its files (launch.files) held for it first (StartDeps.files): a hold that fails part
346
+ * way, a write that fails, or one that answers another run (an origin key's run started before), lets go of the hold. */
347
+ async function withHeldFiles(deps, runId, launch, write) {
348
+ const ids = launch.files ?? [];
349
+ if (!ids.length || !deps.files)
350
+ return await write();
351
+ try {
352
+ await deps.files.hold(runId, ids);
353
+ const row = await write();
354
+ if (row.id !== runId)
355
+ await deps.files.release(runId);
356
+ return row;
357
+ }
358
+ catch (error) {
359
+ await deps.files.release(runId).catch(() => undefined);
360
+ throw error;
361
+ }
362
+ }
291
363
  /** Starts a run of an agent given inline, as POST /agents/{id}/runs starts a run of a stored one: the same checks over the
292
364
  * revision the definition makes (prepareLaunch), then ONE transaction (store.runs.createInline) that writes the agent on
293
365
  * its reference's first run and the revision on its version's first run, or reads them, then the run and its launch. The
@@ -307,12 +379,12 @@ export async function startInline(store, deps, inline, body, { origin } = {}) {
307
379
  const { launch } = await prepareLaunch(deps, entry, body, { revision: revision });
308
380
  const runId = (deps.newRunId ?? uuidv7)();
309
381
  try {
310
- return await store.runs.createInline({
382
+ return await withHeldFiles(deps, runId, launch, () => store.runs.createInline({
311
383
  agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
312
384
  revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}) },
313
385
  run: { id: runId, ...(origin ? { origin } : {}) },
314
386
  launch: { body: launchBody(launch) },
315
- });
387
+ }));
316
388
  }
317
389
  catch (error) {
318
390
  if (error instanceof ExternalBodyConflict) {
@@ -381,22 +453,27 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
381
453
  // The run's model, resolved once, at start (the runner reads launch.model only).
382
454
  const model = await deps.modelOf(entry, revision);
383
455
  // The run's learning start, decided here as the old start did (learning-run.ts onStart): a run learns when the server's
384
- // learning is on and its revision says so; then its seed is read now and the notes its # Learned section names (givenOf,
456
+ // learning is on and its revision says so; then its seed is read now and the notes its # Learned section names (learnedParts,
385
457
  // the one decision) are pinned in the launch for the runner to put in the prompt. A seed that cannot be read starts it with
386
458
  // nothing (given empty, seed null); the end state is the runner's.
387
- const learning = await learningStartFor(deps, entry, revision, rbody);
459
+ const learning = await learningStartFor(deps, entry, revision, rbody, input);
460
+ // The run's effort: its own, else its revision's saved thinking, else the host's AGENT_THINKING (each a thinking level,
461
+ // else none). Nothing set: none, so the run gets no effort note and its harness's own default. Kept in its launch, so
462
+ // its harness's thinking, its guidance and its metrics all read the one value.
463
+ const effort = typeof body.effort === "string" ? body.effort : (thinkingLevel(rbody.thinking) ?? thinkingLevel(deps.planeEnv().AGENT_THINKING));
388
464
  const launch = {
389
465
  input,
390
466
  title: clip(redacted(title.trim().replace(/\s+/g, " "), deps.serverSecrets()), 80),
391
467
  place,
392
468
  harness: harnessOfBody(revision.body),
393
- ...(typeof body.effort === "string" ? { effort: body.effort } : {}),
469
+ ...(effort !== undefined ? { effort } : {}),
394
470
  ...(cap !== undefined ? { maxCostUsd: cap } : {}),
395
471
  ...(capMode !== undefined ? { capMode } : {}),
396
472
  ...(Object.keys(plane).length ? { plane } : {}),
397
473
  ...(deps.approvers !== undefined ? { approvers: deps.approvers } : {}),
398
474
  ...(deps.documents !== undefined ? { documents: deps.documents } : {}),
399
475
  ...(deps.boxAllow !== undefined ? { boxAllow: deps.boxAllow } : {}),
476
+ ...(deps.boxAllowSet ? { boxAllowSet: true } : {}),
400
477
  ...(fileIds.length ? { files: fileIds } : {}),
401
478
  ...(learning ? { learning } : {}),
402
479
  ...(trigger ? { trigger } : {}),
@@ -26,8 +26,6 @@ export type SealKey = {
26
26
  export type BootedSealKey = SealKey & {
27
27
  readonly release: () => void;
28
28
  };
29
- /** Where the data directory `dataDir` keeps its seal key. */
30
- export declare const sealKeyPath: (dataDir: string) => string;
31
29
  /** The key file's rules alone, with no store to check against: `given` (AGENTRUN_SEAL_KEY as it was handed) when set,
32
30
  * else the one kept in `dataDir`, made there when there is none. A start never calls this by itself: bootSealKey checks
33
31
  * the key against the store first, and makes one only for a store that holds no secret. */
package/dist/seal-key.js CHANGED
@@ -16,12 +16,11 @@
16
16
  // start makes a key and records it (and the import's, which sets a data directory up as the server does); a runner reads
17
17
  // one and checks it, and never makes or records one. Several data directories in one process each keep their own key.
18
18
  import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
19
- import { chmodSync, closeSync, linkSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, rmSync, writeSync } from "node:fs";
19
+ import { chmodSync, closeSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, rmSync, writeSync } from "node:fs";
20
20
  import { join } from "node:path";
21
- import { unseal } from "@parcha/pi-durable-agent";
21
+ import { unseal } from "./sealing.js";
22
22
  import { SEAL_KEY_ENV, sealKeyOf } from "./tool-keys.js";
23
23
  import { handedSecret, holdSealKey } from "./secrets.js";
24
- import { webhookSecretIn } from "./webhooks.js";
25
24
  /** The seal key's own directory in the data directory, and its file there. */
26
25
  export const SEAL_KEY_DIR = "seal";
27
26
  export const SEAL_KEY_FILE = "seal.key";
@@ -39,8 +38,6 @@ export class SealKeyRefused extends Error {
39
38
  export class SealKeyNotTheStores extends SealKeyRefused {
40
39
  name = "SealKeyNotTheStores";
41
40
  }
42
- /** Where the data directory `dataDir` keeps its seal key. */
43
- export const sealKeyPath = (dataDir) => join(dataDir, SEAL_KEY_DIR, SEAL_KEY_FILE);
44
41
  const HOW = `Hand the server ${SEAL_KEY_ENV} (32 random bytes in base64, e.g. \`openssl rand -base64 32\`), or let it keep one in ${SEAL_KEY_DIR}/${SEAL_KEY_FILE} in its data directory, made at the first start.`;
45
42
  const refused = (why) => new SealKeyRefused(`No seal key: ${why}. ${HOW}`);
46
43
  function lstatOf(path) {
@@ -173,49 +170,12 @@ function opensUnder(key, sealed, aad) {
173
170
  return false;
174
171
  }
175
172
  }
176
- /** The values data directory `dataDir` keeps sealed beside the store, under the same key: the outbound webhook's signing
177
- * secret (webhooks.ts) and any trigger settings file (sealed-settings.ts), each a check of whether a key opens it. */
178
- function sealedBeside(dataDir) {
179
- const checks = [];
180
- if (webhookSecretIn(dataDir, {}) !== undefined)
181
- checks.push((key) => "secret" in (webhookSecretIn(dataDir, { [SEAL_KEY_ENV]: key.toString("base64") }) ?? {}));
182
- let names = [];
183
- try {
184
- names = readdirSync(dataDir);
185
- }
186
- catch {
187
- // No data directory yet: nothing kept beside the store.
188
- }
189
- for (const name of names) {
190
- const adapter = /^trigger-settings-(.+)\.json$/.exec(name)?.[1];
191
- if (adapter === undefined)
192
- continue;
193
- let values;
194
- try {
195
- values = JSON.parse(readFileSync(join(dataDir, name), "utf8")).values;
196
- }
197
- catch {
198
- continue;
199
- }
200
- if (!values || typeof values !== "object")
201
- continue;
202
- for (const [scope, fields] of Object.entries(values)) {
203
- if (!fields || typeof fields !== "object")
204
- continue;
205
- for (const [field, sealed] of Object.entries(fields)) {
206
- if (typeof sealed === "string")
207
- checks.push((key) => opensUnder(key, Buffer.from(sealed, "base64"), `trigger-settings|${adapter}|${scope}|${field}`));
208
- }
209
- }
210
- }
211
- return checks;
212
- }
213
- async function storeSealOf(store, dataDir) {
173
+ async function storeSealOf(store) {
214
174
  const fingerprint = recordedIn(await store.settings.get(SEAL_KEY_SETTING));
215
175
  if (fingerprint !== undefined)
216
176
  return { fingerprint, sealed: [] };
217
177
  const rows = (await store.sealedSecrets.all()).map((row) => (key) => opensUnder(key, row.sealed, row.aad));
218
- return { fingerprint, sealed: [...rows, ...sealedBeside(dataDir)] };
178
+ return { fingerprint, sealed: rows };
219
179
  }
220
180
  const holdsSecrets = (seal) => seal.fingerprint !== undefined || seal.sealed.length > 0;
221
181
  /** Whether `key` is the store's, or why not: the one its fingerprint records; with none recorded, one that opens every
@@ -234,7 +194,7 @@ function notTheStoresWhy(seal, key) {
234
194
  const notTheStores = (why) => new SealKeyNotTheStores(`${SEALED_ELSEWHERE}. ${why}`);
235
195
  const PUT_BACK = `put the original there (mode 0600, in a 0700 directory), or hand it as ${SEAL_KEY_ENV}`;
236
196
  async function sealKeyFor(store, dataDir, given, role, write) {
237
- const kept = await storeSealOf(store, dataDir);
197
+ const kept = await storeSealOf(store);
238
198
  const dir = join(dataDir, SEAL_KEY_DIR);
239
199
  const file = join(dir, SEAL_KEY_FILE);
240
200
  let seal;
@@ -1,6 +1,21 @@
1
- import type { SettingsSpec } from "./sealed-settings.js";
2
1
  import type { TriggerSettings } from "./store/index.js";
3
- export { SERVER_SCOPE, type SettingsSpec } from "./sealed-settings.js";
2
+ /** What an adapter keeps sealed, and where: `server`, one set for the server; `trigger`, one set per trigger, by its id.
3
+ * A field with `mint` is a Standard Webhooks secret this server makes (standard-webhooks.ts), shown once; any other is
4
+ * given (set). `minBytes`: the fewest bytes its value may hold (standard-webhooks.ts keyBytes), MIN_KEY_BYTES for a key
5
+ * a request is verified with. `public`: a value that is no secret (an app's id, its name), kept with the rest but never
6
+ * in the list of the server's secrets, so no run's text is cut of it, and of any length. `format: "pem"`: a PEM private
7
+ * key, whose lines each are listed as secrets. */
8
+ export type SettingsSpec = {
9
+ scope: "server" | "trigger";
10
+ fields: Record<string, {
11
+ mint?: true;
12
+ minBytes?: number;
13
+ public?: true;
14
+ format?: "pem";
15
+ }>;
16
+ };
17
+ /** The scope of a server-scoped adapter's settings. */
18
+ export declare const SERVER_SCOPE = "server";
4
19
  /** The store slice this layer reads and writes. */
5
20
  type SealedSettingsStore = {
6
21
  readonly triggerSettings: Pick<TriggerSettings, "get" | "put" | "removeScope">;
@@ -66,6 +81,6 @@ declare class SealedSettingsOverStore {
66
81
  private remember;
67
82
  }
68
83
  export type { SealedSettingsOverStore };
69
- /** The SealedSettings surface over the one store: the switch swaps `new SealedSettings(data, id, spec, key, say)` for this,
70
- * then awaits load() once at start before the first get()/values(). */
84
+ /** An adapter's sealed settings over the one store; the server awaits load() once at start before the first
85
+ * get()/values(). */
71
86
  export declare function sealedSettingsOverStore(store: SealedSettingsStore, adapterId: string, spec: SettingsSpec, key: Buffer, say: (fields: Record<string, string>) => void): SealedSettingsOverStore;
@@ -1,15 +1,15 @@
1
- // A trigger source's sealed settings over the one store (store.triggerSettings), the store-backed replacement for the
2
- // SealedSettings file class (sealed-settings.ts). Each (scope, field) is a sealed row, bound to its adapter, scope and
3
- // field by the store's documented AAD trigger_settings|<adapter>|<scope>|<field>; the store holds base64 ciphertext and
4
- // never opens it. With no seal key none is kept, never in the clear. The surface is SealedSettings', so the switch swaps
5
- // `new SealedSettings(data, ...)` for `sealedSettingsOverStore(store, ...)` then awaits load() once: get()/values() are
1
+ // A trigger source's sealed settings over the one store (store.triggerSettings): the trigger kernel's one store of them.
2
+ // Each (scope, field) is a sealed row, bound to its adapter, scope and field by the store's documented AAD
3
+ // trigger_settings|<adapter>|<scope>|<field>; the store holds base64 ciphertext and never opens it, and none is kept in
4
+ // the clear (the server always has its seal key: seal-key.ts). The server awaits load() once: get()/values() are
6
5
  // synchronous off a snapshot the server (the one writer) loads once and keeps in step with every write; set/mint/remove
7
6
  // are durable before they resolve.
8
- import { seal, unseal } from "@parcha/pi-durable-agent";
7
+ import { seal, unseal } from "./sealing.js";
9
8
  import { invalid } from "./errors.js";
10
9
  import { keyBytes, MIN_KEY_BYTES, mintSecret, SECRET_PREFIX } from "./standard-webhooks.js";
11
10
  import { SEAL_KEY_ENV } from "./tool-keys.js";
12
- export { SERVER_SCOPE } from "./sealed-settings.js";
11
+ /** The scope of a server-scoped adapter's settings. */
12
+ export const SERVER_SCOPE = "server";
13
13
  /** The store's documented AAD for a trigger setting (store schema `trigger_settings`): the composite row key is in the
14
14
  * AAD, not store/seal.ts's single-row aadOf, which refuses a key holding the separator. */
15
15
  const aad = (adapterId, scope, field) => `trigger_settings|${adapterId}|${scope}|${field}`;
@@ -198,8 +198,8 @@ class SealedSettingsOverStore {
198
198
  this.retired.add(secret);
199
199
  }
200
200
  }
201
- /** The SealedSettings surface over the one store: the switch swaps `new SealedSettings(data, id, spec, key, say)` for this,
202
- * then awaits load() once at start before the first get()/values(). */
201
+ /** An adapter's sealed settings over the one store; the server awaits load() once at start before the first
202
+ * get()/values(). */
203
203
  export function sealedSettingsOverStore(store, adapterId, spec, key, say) {
204
204
  return new SealedSettingsOverStore(store, adapterId, spec, key, say);
205
205
  }
@@ -0,0 +1,4 @@
1
+ /** AES-256-GCM over `plain`, bound to `aad`: the IV, the ciphertext and the tag, in that order. */
2
+ export declare function seal(key: Buffer, plain: Buffer, aad: string): Buffer;
3
+ /** `seal`'s inverse; it throws when the bytes, the key or the `aad` differ from the sealing's. */
4
+ export declare function unseal(key: Buffer, sealed: Buffer, aad: string): Buffer;
@@ -0,0 +1,20 @@
1
+ // AES-256-GCM sealing, the one primitive every secret this server keeps at rest is sealed with (copied from
2
+ // @parcha/pi-durable-agent's vault.ts): the store's sealed columns (store/seal.ts), the
3
+ // trigger settings, the outbound webhook's secret, and what a runner opens under the server's seal key.
4
+ import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
5
+ const IV_BYTES = 12;
6
+ const TAG_BYTES = 16;
7
+ /** AES-256-GCM over `plain`, bound to `aad`: the IV, the ciphertext and the tag, in that order. */
8
+ export function seal(key, plain, aad) {
9
+ const iv = randomBytes(IV_BYTES);
10
+ const cipher = createCipheriv("aes-256-gcm", key, iv).setAAD(Buffer.from(aad, "utf8"));
11
+ return Buffer.concat([iv, cipher.update(plain), cipher.final(), cipher.getAuthTag()]);
12
+ }
13
+ /** `seal`'s inverse; it throws when the bytes, the key or the `aad` differ from the sealing's. */
14
+ export function unseal(key, sealed, aad) {
15
+ if (sealed.length < IV_BYTES + TAG_BYTES)
16
+ throw new Error("too short");
17
+ const decipher = createDecipheriv("aes-256-gcm", key, sealed.subarray(0, IV_BYTES)).setAAD(Buffer.from(aad, "utf8"));
18
+ decipher.setAuthTag(sealed.subarray(sealed.length - TAG_BYTES));
19
+ return Buffer.concat([decipher.update(sealed.subarray(IV_BYTES, sealed.length - TAG_BYTES)), decipher.final()]);
20
+ }
@@ -1,4 +1,4 @@
1
- import { keyShaped } from "@parcha/pi-durable-disk/secret-name";
1
+ import { keyShaped } from "./secret-name.js";
2
2
  /** Whether a name is a secret's, whatever list names it or none does: one of its `_`-separated segments, in any case, is
3
3
  * KEY, TOKEN, SECRET, PASSWORD, PASSWD, PASS, PAT, CREDENTIAL, CREDENTIALS or DSN, or its last is PWD after another.
4
4
  * The one rule, pi-durable-disk's own: this cut, the harness log's and a run's environment (secrets.ts' withoutSecrets)
@@ -6,7 +6,7 @@ import { secretLintProfiler } from "@secretlint/profiler";
6
6
  import { rules as recommended } from "@secretlint/secretlint-rule-preset-recommend";
7
7
  // No performance marks: the profiler would leave about 14 a call in the process's global buffer.
8
8
  secretLintProfiler.setEnabled(false);
9
- import { keyShaped } from "@parcha/pi-durable-disk/secret-name";
9
+ import { keyShaped } from "./secret-name.js";
10
10
  /** Whether a name is a secret's, whatever list names it or none does: one of its `_`-separated segments, in any case, is
11
11
  * KEY, TOKEN, SECRET, PASSWORD, PASSWD, PASS, PAT, CREDENTIAL, CREDENTIALS or DSN, or its last is PWD after another.
12
12
  * The one rule, pi-durable-disk's own: this cut, the harness log's and a run's environment (secrets.ts' withoutSecrets)
@@ -0,0 +1,9 @@
1
+ /** The `_`-separated segments, in any case, that make a name a secret's. */
2
+ export declare const SECRET_SEGMENTS: readonly string[];
3
+ /**
4
+ * Whether `name` is a secret's name: one of its `_`-separated segments, in any case, is one of SECRET_SEGMENTS, or its last
5
+ * segment is PWD after another (DB_PWD). Segments, not suffixes, so MODAL_TOKEN_ID, FOO_TOKEN_BAR and MY_TOKEN_FILE are
6
+ * secrets' names, and CACHE_KEY_PREFIX too, which is the cheaper error; KEYBOARD, TOKENIZER, SECRETARY and PATTERN are
7
+ * not. PWD alone and OLDPWD are the shell's working directories, never a secret's.
8
+ */
9
+ export declare function keyShaped(name: string): boolean;
@@ -0,0 +1,15 @@
1
+ // The one rule for whether a variable's name is a secret's, by its name alone: what serve keeps out of a run's
2
+ // environment, cuts out of what an import keeps and out of a harness's log (secret-cut.ts).
3
+ /** The `_`-separated segments, in any case, that make a name a secret's. */
4
+ export const SECRET_SEGMENTS = Object.freeze(["KEY", "TOKEN", "SECRET", "PASSWORD", "PASSWD", "PASS", "PAT", "CREDENTIAL", "CREDENTIALS", "DSN"]);
5
+ const SEGMENTS = new Set(SECRET_SEGMENTS);
6
+ /**
7
+ * Whether `name` is a secret's name: one of its `_`-separated segments, in any case, is one of SECRET_SEGMENTS, or its last
8
+ * segment is PWD after another (DB_PWD). Segments, not suffixes, so MODAL_TOKEN_ID, FOO_TOKEN_BAR and MY_TOKEN_FILE are
9
+ * secrets' names, and CACHE_KEY_PREFIX too, which is the cheaper error; KEYBOARD, TOKENIZER, SECRETARY and PATTERN are
10
+ * not. PWD alone and OLDPWD are the shell's working directories, never a secret's.
11
+ */
12
+ export function keyShaped(name) {
13
+ const segments = name.toUpperCase().split("_");
14
+ return segments.some((segment) => SEGMENTS.has(segment)) || (segments.length > 1 && segments.at(-1) === "PWD");
15
+ }
@@ -26,7 +26,6 @@ export type SecretWriterFacts = {
26
26
  * off on a loopback-bound server, open the console from the launch link); no_accounts, accounts are off and the server is
27
27
  * reachable off loopback, where no one writes one until accounts are on. */
28
28
  export type SecretsReason = "token" | "sign_in" | "no_accounts";
29
- export declare const SECRETS_REASONS: readonly SecretsReason[];
30
29
  /** The one decision: whether a caller with these facts may write a secret, and if not, why. The owner's password session
31
30
  * always may; the accounts-off console on a loopback-bound server may where `loopbackConsoleIsOwner`
32
31
  * (LOOPBACK_CONSOLE_IS_OWNER); the API token never may, anywhere. */
@@ -11,7 +11,6 @@ export const SECRET_WRITE_REFUSAL = "Saving, replacing or removing a secret take
11
11
  * secrets_writable) follows it.
12
12
  */
13
13
  export const LOOPBACK_CONSOLE_IS_OWNER = true;
14
- export const SECRETS_REASONS = ["token", "sign_in", "no_accounts"];
15
14
  /** The one decision: whether a caller with these facts may write a secret, and if not, why. The owner's password session
16
15
  * always may; the accounts-off console on a loopback-bound server may where `loopbackConsoleIsOwner`
17
16
  * (LOOPBACK_CONSOLE_IS_OWNER); the API token never may, anywhere. */
@@ -16,6 +16,10 @@ export declare const defaultData: (env?: NodeJS.ProcessEnv) => string;
16
16
  * npxLine). */
17
17
  export declare const DATA_ENV = "AGENTRUN_SERVE_DATA";
18
18
  /** Agent `agentId`'s folder on the disk, which holds its learning folder (learning.ts) and its runs: `<data>/disk/agents/<agent>`. */
19
+ /** The folder of a data directory that holds each agent's disk: its runs and its learning. */
20
+ export declare const DISK_DIR = "disk";
21
+ /** Agent `agentId`'s folder on the disk of data directory `data`: `<data>/disk/agents/<name>`. */
22
+ export declare const agentDiskDir: (data: string, agentId: string) => string;
19
23
  export declare const agentFolderOf: (data: string, agentId: string) => string;
20
24
  /** The file parsed as JSON, or null when it is missing, unreadable, or not whole JSON (a half-written file). */
21
25
  export declare const readJson: (path: string) => Promise<Json | null>;
package/dist/server-fs.js CHANGED
@@ -3,12 +3,11 @@
3
3
  // runner cutover deletes) can go on their own. Nothing here knows a run: it is whole-file writes made durable, a directory
4
4
  // sync, a JSON read that fails to null, a per-key work queue, the data-directory location and the names of the two files
5
5
  // the owner's CLI reads (the API token and the server record).
6
- import { randomBytes } from "node:crypto";
6
+ import { createHash, randomBytes } from "node:crypto";
7
7
  import { closeSync, constants, fsyncSync, openSync, readFileSync, renameSync, unlinkSync, writeSync } from "node:fs";
8
8
  import { open, readFile, rename, unlink, writeFile } from "node:fs/promises";
9
9
  import { homedir } from "node:os";
10
10
  import { dirname, join } from "node:path";
11
- import { agentDiskDir } from "@parcha/pi-durable-agent";
12
11
  /** The server's API token (`ar_local_...`), in the data directory, made at its first start when it is given none. */
13
12
  export const TOKEN_FILE = ".token";
14
13
  /** Where a running server is, for the launcher's CLI (`npx @parcha/agentrun agents list`), in the data directory: its
@@ -33,6 +32,13 @@ export const defaultData = (env = process.env) => join(env.XDG_DATA_HOME || join
33
32
  * npxLine). */
34
33
  export const DATA_ENV = "AGENTRUN_SERVE_DATA";
35
34
  /** Agent `agentId`'s folder on the disk, which holds its learning folder (learning.ts) and its runs: `<data>/disk/agents/<agent>`. */
35
+ /** The folder of a data directory that holds each agent's disk: its runs and its learning. */
36
+ export const DISK_DIR = "disk";
37
+ /** An agent's folder's name on the disk: its id in lower case, then 16 hex digits of the id's SHA-256, so ids that differ
38
+ * only in case never share one on a disk that folds case. */
39
+ const agentDirName = (agentId) => `${agentId.toLowerCase()}-${createHash("sha256").update(agentId, "utf8").digest("hex").slice(0, 16)}`;
40
+ /** Agent `agentId`'s folder on the disk of data directory `data`: `<data>/disk/agents/<name>`. */
41
+ export const agentDiskDir = (data, agentId) => join(data, DISK_DIR, "agents", agentDirName(agentId));
36
42
  export const agentFolderOf = (data, agentId) => agentDiskDir(data, agentId);
37
43
  /** The file parsed as JSON, or null when it is missing, unreadable, or not whole JSON (a half-written file). */
38
44
  export const readJson = (path) => readFile(path, "utf8")
@@ -1,6 +1,4 @@
1
1
  export declare const SERVER_LOCK = "server.lock";
2
- /** The data root's server, as it last said: `{ pid, until }`, `until` (epoch ms) when it stops, null while it runs. */
3
- export declare const SERVER_STATE = "server.state";
4
2
  /** Another server holds the data root. Its message is the one line the CLI prints before it exits 1. */
5
3
  export declare class ServerLockHeldError extends Error {
6
4
  readonly code = "SERVER_LOCK_HELD";
@@ -20,25 +18,3 @@ export interface ServerLock {
20
18
  export declare function takeServerLock(dataRoot: string, options?: {
21
19
  chmod?: (file: string, mode: number) => void;
22
20
  }): ServerLock;
23
- /** A server that is stopping, by its mark: its process, and when its stop is over at the latest (epoch ms). */
24
- export type Stopping = {
25
- pid: number;
26
- until: number;
27
- };
28
- /** Records the data root's server as this process, running: once, as it starts, right after it takes the lock. */
29
- export declare function markRunning(dataRoot: string): void;
30
- /** Records the data root's server as stopping until `until`, as its close begins: the same file, rewritten in place in one
31
- * write of the same length, never made again (a record that is gone is left gone), so the stop adds no entry. */
32
- export declare function markStopping(dataRoot: string, until: number): void;
33
- /** The data root's server, when its record says it is stopping, its process lives and its time is still ahead; none
34
- * otherwise (no record, one that can't be read, a server that runs, or one that died as it stopped). */
35
- export declare function stoppingOf(dataRoot: string, now?: number): Stopping | undefined;
36
- /** Takes the data root's server lock, as takeServerLock. When another server holds it and is stopping (its record),
37
- * waits for that server as long as its process lives, under one cap, its record's `until` (the server's whole close:
38
- * its runs' drain, their carry backs and their boxes' cleanup), retrying every `everyMs`, and tells `waiting` once as it
39
- * starts to. A server that is not stopping is refused at once with ServerLockHeldError, as is one that still holds the
40
- * lock at its `until`, or a holder that is not the stopping server (its process gone, the lock still held). */
41
- export declare function takeServerLockAfterStop(dataRoot: string, options?: {
42
- waiting?: (stopping: Stopping) => void;
43
- everyMs?: number;
44
- }): Promise<ServerLock>;