@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.34

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 (444) hide show
  1. package/CHANGELOG.md +270 -0
  2. package/README.md +343 -246
  3. package/dist/adapters.d.ts +0 -7
  4. package/dist/adapters.js +11 -22
  5. package/dist/agent-rows.d.ts +98 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +60 -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 +14 -0
  14. package/dist/api-only.js +33 -0
  15. package/dist/archil-routes.d.ts +1 -1
  16. package/dist/bash-read-only.d.ts +22 -0
  17. package/dist/bash-read-only.js +701 -0
  18. package/dist/box-egress-vm.d.ts +0 -8
  19. package/dist/box-egress-vm.js +0 -10
  20. package/dist/box-egress.d.ts +0 -4
  21. package/dist/box-egress.js +1 -16
  22. package/dist/box-paths.d.ts +25 -2
  23. package/dist/box-paths.js +79 -11
  24. package/dist/box-relay.d.ts +0 -11
  25. package/dist/box-relay.js +0 -20
  26. package/dist/box-settings.d.ts +26 -0
  27. package/dist/box-settings.js +63 -0
  28. package/dist/boxes.d.ts +21 -1
  29. package/dist/boxes.js +27 -20
  30. package/dist/browser-commands.d.ts +5 -2
  31. package/dist/browser-commands.js +4 -4
  32. package/dist/browser-computer.d.ts +5 -0
  33. package/dist/browser-computer.js +21 -0
  34. package/dist/browser-cost.d.ts +9 -6
  35. package/dist/browser-cost.js +94 -51
  36. package/dist/browser-live.d.ts +7 -20
  37. package/dist/browser-live.js +15 -93
  38. package/dist/browser-person.d.ts +18 -53
  39. package/dist/browser-person.js +94 -279
  40. package/dist/budget.d.ts +0 -4
  41. package/dist/budget.js +0 -7
  42. package/dist/cap.d.ts +8 -12
  43. package/dist/cap.js +12 -27
  44. package/dist/cli.js +61 -20
  45. package/dist/closed-pipes.d.ts +2 -0
  46. package/dist/closed-pipes.js +13 -0
  47. package/dist/computer-commands.d.ts +2 -0
  48. package/dist/computer-commands.js +2 -0
  49. package/dist/computer-keys.js +5 -2
  50. package/dist/computer-setting.d.ts +20 -4
  51. package/dist/computer-setting.js +25 -5
  52. package/dist/computers.d.ts +31 -3
  53. package/dist/computers.js +70 -11
  54. package/dist/confine.d.ts +120 -0
  55. package/dist/confine.js +436 -0
  56. package/dist/console/assets/index-RPHGlXmM.js +540 -0
  57. package/dist/console/assets/index-opTN5Naq.css +1 -0
  58. package/dist/console/index.html +2 -2
  59. package/dist/daytona-api.d.ts +0 -11
  60. package/dist/daytona-api.js +1 -82
  61. package/dist/decision-rows.d.ts +1 -1
  62. package/dist/decision-rows.js +1 -1
  63. package/dist/docker-daemon.d.ts +31 -0
  64. package/dist/docker-daemon.js +56 -0
  65. package/dist/docker-host-addresses.d.ts +37 -0
  66. package/dist/docker-host-addresses.js +110 -0
  67. package/dist/effort-guidance.js +4 -3
  68. package/dist/environment.d.ts +0 -3
  69. package/dist/environment.js +3 -5
  70. package/dist/errors.d.ts +0 -2
  71. package/dist/errors.js +6 -9
  72. package/dist/filed-answer.d.ts +32 -0
  73. package/dist/filed-answer.js +160 -0
  74. package/dist/files.d.ts +1 -11
  75. package/dist/files.js +2 -21
  76. package/dist/github-connection.d.ts +2 -2
  77. package/dist/github-connection.js +1 -1
  78. package/dist/graph-view.d.ts +3 -5
  79. package/dist/graph-view.js +4 -14
  80. package/dist/handed-values.d.ts +9 -0
  81. package/dist/handed-values.js +26 -0
  82. package/dist/harness-install.d.ts +22 -5
  83. package/dist/harness-install.js +98 -20
  84. package/dist/harness-opencode/adapter.d.ts +7 -0
  85. package/dist/harness-opencode/adapter.js +23 -6
  86. package/dist/harness-opencode/index.d.ts +1 -1
  87. package/dist/harness-opencode/index.js +1 -1
  88. package/dist/harness-opencode/verify.d.ts +17 -0
  89. package/dist/harness-opencode/verify.js +30 -10
  90. package/dist/harness-table.js +6 -1
  91. package/dist/harness.d.ts +4 -3
  92. package/dist/harness.js +16 -1
  93. package/dist/heard.js +1 -1
  94. package/dist/held-fd.d.ts +5 -0
  95. package/dist/held-fd.js +14 -0
  96. package/dist/host-calls.d.ts +20 -0
  97. package/dist/host-calls.js +12 -0
  98. package/dist/host-tools.d.ts +4 -21
  99. package/dist/host-tools.js +4 -61
  100. package/dist/host.d.ts +2 -4
  101. package/dist/host.js +2 -7
  102. package/dist/import-summary.d.ts +1 -5
  103. package/dist/import-summary.js +0 -21
  104. package/dist/import.d.ts +6 -6
  105. package/dist/import.js +62 -24
  106. package/dist/key-refusal.d.ts +5 -1
  107. package/dist/key-refusal.js +19 -4
  108. package/dist/learn/check.d.ts +6 -2
  109. package/dist/learn/check.js +83 -29
  110. package/dist/learn/folder.d.ts +5 -1
  111. package/dist/learn/folder.js +10 -3
  112. package/dist/learn/grade.d.ts +14 -0
  113. package/dist/learn/grade.js +68 -12
  114. package/dist/learn/index.d.ts +4 -4
  115. package/dist/learn/index.js +4 -4
  116. package/dist/learn/reflect.d.ts +31 -2
  117. package/dist/learn/reflect.js +79 -4
  118. package/dist/learn/relevance.d.ts +24 -0
  119. package/dist/learn/relevance.js +91 -0
  120. package/dist/learn/secrets.d.ts +8 -1
  121. package/dist/learn/secrets.js +95 -15
  122. package/dist/learn/skills.d.ts +112 -14
  123. package/dist/learn/skills.js +556 -52
  124. package/dist/learned-workflow.d.ts +37 -5
  125. package/dist/learned-workflow.js +106 -12
  126. package/dist/learning-routes.d.ts +16 -49
  127. package/dist/learning-routes.js +46 -36
  128. package/dist/learning-run.d.ts +6 -250
  129. package/dist/learning-run.js +11 -665
  130. package/dist/learning-words.d.ts +12 -5
  131. package/dist/learning-words.js +18 -9
  132. package/dist/learning.d.ts +93 -77
  133. package/dist/learning.js +176 -304
  134. package/dist/live/stream.js +1 -1
  135. package/dist/live/translate.js +13 -3
  136. package/dist/local-models.d.ts +11 -5
  137. package/dist/local-models.js +13 -8
  138. package/dist/mcp-gateway.d.ts +11 -52
  139. package/dist/mcp-gateway.js +44 -148
  140. package/dist/mcp-oauth.d.ts +10 -14
  141. package/dist/mcp-oauth.js +14 -32
  142. package/dist/mcp-probe.d.ts +0 -7
  143. package/dist/mcp-probe.js +4 -10
  144. package/dist/mcp-servers-store.d.ts +6 -6
  145. package/dist/mcp-servers-store.js +13 -15
  146. package/dist/mcp-store.js +3 -4
  147. package/dist/mcp.js +4 -3
  148. package/dist/model.d.ts +6 -7
  149. package/dist/model.js +43 -27
  150. package/dist/monid.d.ts +0 -2
  151. package/dist/monid.js +3 -6
  152. package/dist/openapi.d.ts +8 -1
  153. package/dist/openapi.js +124 -50
  154. package/dist/page.d.ts +1 -3
  155. package/dist/page.js +9 -19
  156. package/dist/paid-calls.d.ts +21 -27
  157. package/dist/paid-calls.js +28 -62
  158. package/dist/pause.d.ts +0 -2
  159. package/dist/pause.js +1 -8
  160. package/dist/place.d.ts +0 -5
  161. package/dist/place.js +0 -10
  162. package/dist/print.d.ts +2 -1
  163. package/dist/print.js +4 -2
  164. package/dist/propose.js +83 -39
  165. package/dist/push-handler.d.ts +1 -1
  166. package/dist/reflect-range.d.ts +25 -0
  167. package/dist/reflect-range.js +30 -0
  168. package/dist/refusal-words.d.ts +5 -1
  169. package/dist/refusal-words.js +5 -1
  170. package/dist/rows.d.ts +1 -1
  171. package/dist/run-cut.d.ts +0 -6
  172. package/dist/run-cut.js +0 -6
  173. package/dist/run-db.d.ts +2 -13
  174. package/dist/run-db.js +2 -41
  175. package/dist/run-launch.d.ts +19 -2
  176. package/dist/run-launch.js +13 -5
  177. package/dist/run-learning-served.d.ts +46 -2
  178. package/dist/run-learning-served.js +26 -7
  179. package/dist/run-reads-over-store.d.ts +1 -1
  180. package/dist/run-reads-over-store.js +15 -6
  181. package/dist/run-secrets.d.ts +33 -0
  182. package/dist/run-secrets.js +53 -0
  183. package/dist/run-timeline-served.d.ts +5 -1
  184. package/dist/run-timeline-served.js +19 -5
  185. package/dist/run-view.d.ts +12 -17
  186. package/dist/run-view.js +29 -28
  187. package/dist/runnable.d.ts +18 -10
  188. package/dist/runnable.js +21 -10
  189. package/dist/runner/adapter-loop.d.ts +14 -3
  190. package/dist/runner/adapter-loop.js +464 -62
  191. package/dist/runner/adapter-run-spec.d.ts +29 -8
  192. package/dist/runner/adapter-run-spec.js +96 -37
  193. package/dist/runner/adapters/index.js +11 -1
  194. package/dist/runner/adapters/pi.d.ts +15 -1
  195. package/dist/runner/adapters/pi.js +19 -5
  196. package/dist/runner/beside.d.ts +30 -3
  197. package/dist/runner/beside.js +54 -12
  198. package/dist/runner/claim-secrets.d.ts +10 -1
  199. package/dist/runner/claim-secrets.js +49 -15
  200. package/dist/runner/cli-run-spec.d.ts +2 -0
  201. package/dist/runner/cli-run-spec.js +60 -17
  202. package/dist/runner/commands.js +1 -1
  203. package/dist/runner/computer-journal.d.ts +15 -2
  204. package/dist/runner/computer-journal.js +41 -5
  205. package/dist/runner/conformance/harness.js +118 -8
  206. package/dist/runner/conformance/subject.d.ts +4 -1
  207. package/dist/runner/dispatch.d.ts +8 -1
  208. package/dist/runner/dispatch.js +81 -7
  209. package/dist/runner/end-of-run.d.ts +8 -2
  210. package/dist/runner/end-of-run.js +10 -4
  211. package/dist/runner/github-app.js +1 -1
  212. package/dist/runner/harness-loops.d.ts +9 -1
  213. package/dist/runner/harness-loops.js +15 -2
  214. package/dist/runner/journal-kinds.d.ts +30 -6
  215. package/dist/runner/journal-kinds.js +20 -5
  216. package/dist/runner/journal-reader.d.ts +1 -1
  217. package/dist/runner/journal-reader.js +2 -2
  218. package/dist/runner/learning-ask.d.ts +4 -0
  219. package/dist/runner/learning-ask.js +15 -1
  220. package/dist/runner/learning-end.d.ts +18 -3
  221. package/dist/runner/learning-end.js +113 -11
  222. package/dist/runner/learning-loop.d.ts +5 -0
  223. package/dist/runner/learning-loop.js +26 -6
  224. package/dist/runner/live-ticker.d.ts +1 -1
  225. package/dist/runner/live-ticker.js +28 -4
  226. package/dist/runner/loop-contract.d.ts +3 -2
  227. package/dist/runner/main.d.ts +64 -10
  228. package/dist/runner/main.js +165 -27
  229. package/dist/runner/mcp-claim.d.ts +1 -1
  230. package/dist/runner/mcp-claim.js +2 -3
  231. package/dist/runner/mcp-run.d.ts +2 -0
  232. package/dist/runner/mcp-run.js +15 -5
  233. package/dist/runner/memory-claim.d.ts +9 -0
  234. package/dist/runner/memory-claim.js +25 -0
  235. package/dist/runner/metrics.d.ts +33 -1
  236. package/dist/runner/metrics.js +85 -1
  237. package/dist/runner/model-route.d.ts +13 -0
  238. package/dist/runner/model-route.js +154 -11
  239. package/dist/runner/redact.d.ts +8 -2
  240. package/dist/runner/redact.js +11 -2
  241. package/dist/runner/reflect-hook.d.ts +12 -1
  242. package/dist/runner/reflect-hook.js +33 -3
  243. package/dist/runner/runner.d.ts +20 -0
  244. package/dist/runner/runner.js +56 -10
  245. package/dist/runner/store-port.d.ts +1 -1
  246. package/dist/runner/store-secrets.d.ts +3 -3
  247. package/dist/runner/store-secrets.js +8 -12
  248. package/dist/runner/text-tools.d.ts +44 -0
  249. package/dist/runner/text-tools.js +237 -0
  250. package/dist/runner/workflow-loop.d.ts +6 -0
  251. package/dist/runner/workflow-loop.js +6 -4
  252. package/dist/runner/workflow-spec.d.ts +18 -0
  253. package/dist/runner/workflow-spec.js +68 -26
  254. package/dist/runs-over-store.d.ts +8 -3
  255. package/dist/runs-over-store.js +76 -19
  256. package/dist/seal-key.d.ts +54 -15
  257. package/dist/seal-key.js +232 -82
  258. package/dist/sealed-settings-store.d.ts +19 -4
  259. package/dist/sealed-settings-store.js +9 -9
  260. package/dist/sealing.d.ts +4 -0
  261. package/dist/sealing.js +20 -0
  262. package/dist/secret-cut.d.ts +1 -1
  263. package/dist/secret-cut.js +1 -1
  264. package/dist/secret-name.d.ts +9 -0
  265. package/dist/secret-name.js +15 -0
  266. package/dist/secret-writes.d.ts +0 -1
  267. package/dist/secret-writes.js +0 -1
  268. package/dist/secrets.d.ts +2 -10
  269. package/dist/secrets.js +21 -17
  270. package/dist/server-fs.d.ts +4 -0
  271. package/dist/server-fs.js +8 -2
  272. package/dist/server-lock.d.ts +0 -24
  273. package/dist/server-lock.js +1 -80
  274. package/dist/server-secrets-store.d.ts +4 -4
  275. package/dist/server-secrets-store.js +10 -32
  276. package/dist/server-secrets.d.ts +4 -9
  277. package/dist/server-secrets.js +12 -33
  278. package/dist/server.d.ts +26 -44
  279. package/dist/server.js +229 -142
  280. package/dist/sign-ins-store.d.ts +34 -36
  281. package/dist/sign-ins-store.js +27 -38
  282. package/dist/sign-ins.d.ts +2 -119
  283. package/dist/sign-ins.js +5 -311
  284. package/dist/standard-webhooks.d.ts +1 -1
  285. package/dist/standard-webhooks.js +1 -1
  286. package/dist/stats.d.ts +3 -2
  287. package/dist/stats.js +1 -1
  288. package/dist/store/agent-body.d.ts +8 -2
  289. package/dist/store/agent-body.js +16 -4
  290. package/dist/store/index.d.ts +3 -3
  291. package/dist/store/index.js +3 -3
  292. package/dist/store/open.d.ts +18 -5
  293. package/dist/store/open.js +23 -3
  294. package/dist/store/postgres/connection.d.ts +18 -2
  295. package/dist/store/postgres/connection.js +156 -32
  296. package/dist/store/postgres/migrate.d.ts +4 -0
  297. package/dist/store/postgres/migrate.js +27 -3
  298. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  299. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  300. package/dist/store/postgres/store.d.ts +9 -2
  301. package/dist/store/postgres/store.js +9 -0
  302. package/dist/store/schema.js +1 -1
  303. package/dist/store/seal.js +2 -2
  304. package/dist/store/sqlite/connection.js +49 -5
  305. package/dist/store/sqlite/run-patch.d.ts +3 -0
  306. package/dist/store/sqlite/run-patch.js +3 -0
  307. package/dist/store/sqlite/store.js +64 -20
  308. package/dist/store/store.d.ts +38 -6
  309. package/dist/store/store.js +12 -2
  310. package/dist/store-reads/cap.d.ts +1 -1
  311. package/dist/store-reads/cap.js +22 -4
  312. package/dist/store-reads/journal.d.ts +25 -6
  313. package/dist/store-reads/journal.js +173 -21
  314. package/dist/store-reads/learning.d.ts +26 -8
  315. package/dist/store-reads/learning.js +12 -4
  316. package/dist/store-reads/workflow.d.ts +1 -1
  317. package/dist/store-reads/workflow.js +1 -1
  318. package/dist/store-view.d.ts +5 -1
  319. package/dist/store-view.js +91 -23
  320. package/dist/template-eval.d.ts +60 -4
  321. package/dist/template-eval.js +120 -54
  322. package/dist/templates.d.ts +24 -10
  323. package/dist/templates.js +69 -38
  324. package/dist/timeline/group.d.ts +33 -0
  325. package/dist/timeline/group.js +77 -0
  326. package/dist/timeline/index.d.ts +7 -0
  327. package/dist/timeline/index.js +7 -0
  328. package/dist/timeline/labels.d.ts +79 -0
  329. package/dist/timeline/labels.js +150 -0
  330. package/dist/timeline/origin.d.ts +56 -0
  331. package/dist/timeline/origin.js +92 -0
  332. package/dist/timeline/render-text.d.ts +11 -0
  333. package/dist/timeline/render-text.js +62 -0
  334. package/dist/timeline/timeline.d.ts +274 -0
  335. package/dist/timeline/timeline.js +1308 -0
  336. package/dist/timeline/util.d.ts +17 -0
  337. package/dist/timeline/util.js +49 -0
  338. package/dist/tool-gate.d.ts +41 -216
  339. package/dist/tool-gate.js +79 -540
  340. package/dist/tool-keys-store.d.ts +11 -12
  341. package/dist/tool-keys-store.js +24 -31
  342. package/dist/tool-keys.d.ts +9 -104
  343. package/dist/tool-keys.js +15 -271
  344. package/dist/tool-plane.d.ts +14 -42
  345. package/dist/tool-plane.js +23 -81
  346. package/dist/tool-settings-store.d.ts +1 -2
  347. package/dist/tool-settings-store.js +5 -8
  348. package/dist/tools.d.ts +31 -19
  349. package/dist/tools.js +101 -108
  350. package/dist/trigger-adapter.d.ts +2 -2
  351. package/dist/trigger-schedule.js +2 -1
  352. package/dist/trigger-secrets-shown.js +5 -1
  353. package/dist/trigger-targets.d.ts +13 -1
  354. package/dist/trigger-targets.js +31 -1
  355. package/dist/triggers.d.ts +2 -2
  356. package/dist/triggers.js +3 -3
  357. package/dist/turn-end.d.ts +1 -1
  358. package/dist/turn-end.js +1 -1
  359. package/dist/turns.d.ts +0 -6
  360. package/dist/turns.js +0 -19
  361. package/dist/uploads.js +1 -1
  362. package/dist/usage.d.ts +0 -2
  363. package/dist/usage.js +0 -2
  364. package/dist/validate.d.ts +2 -0
  365. package/dist/validate.js +23 -14
  366. package/dist/webhooks.d.ts +102 -76
  367. package/dist/webhooks.js +266 -233
  368. package/dist/workflow-run.d.ts +114 -0
  369. package/dist/workflow-run.js +144 -0
  370. package/dist/workspace/beneath.d.ts +19 -0
  371. package/dist/workspace/beneath.js +106 -0
  372. package/dist/workspace/computer-deps.d.ts +52 -5
  373. package/dist/workspace/computer-deps.js +154 -19
  374. package/dist/workspace/computer-for-claim.d.ts +19 -14
  375. package/dist/workspace/computer-for-claim.js +77 -16
  376. package/dist/workspace/computer-hold.d.ts +6 -1
  377. package/dist/workspace/computer-hold.js +6 -1
  378. package/dist/workspace/computer-janitor.d.ts +47 -0
  379. package/dist/workspace/computer-janitor.js +182 -0
  380. package/dist/workspace/computer-providers.d.ts +6 -2
  381. package/dist/workspace/computer-providers.js +1 -1
  382. package/dist/workspace/grep-worker.d.ts +5 -0
  383. package/dist/workspace/grep-worker.js +9 -6
  384. package/dist/workspace/index.d.ts +4 -3
  385. package/dist/workspace/index.js +4 -4
  386. package/dist/workspace/local.d.ts +11 -2
  387. package/dist/workspace/local.js +161 -43
  388. package/dist/workspace/resolve-computer.d.ts +50 -10
  389. package/dist/workspace/resolve-computer.js +46 -11
  390. package/dist/workspace/run-tools.d.ts +13 -31
  391. package/dist/workspace/run-tools.js +10 -27
  392. package/dist/workspace-paths.d.ts +0 -17
  393. package/dist/workspace-paths.js +1 -41
  394. package/dist/workspace.d.ts +0 -17
  395. package/dist/workspace.js +3 -99
  396. package/launcher/agentrun-serve +6 -33
  397. package/package.json +14 -14
  398. package/templates/README.md +9 -3
  399. package/templates/inbound-lead/agent.md +1 -1
  400. package/templates/kyb/agent.md +1 -1
  401. package/templates/market-monitor/agent.md +2 -2
  402. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  403. package/dist/app.d.ts +0 -5
  404. package/dist/app.js +0 -514
  405. package/dist/bound-files.d.ts +0 -4
  406. package/dist/bound-files.js +0 -164
  407. package/dist/bounds.d.ts +0 -26
  408. package/dist/bounds.js +0 -137
  409. package/dist/coding-tools.d.ts +0 -47
  410. package/dist/coding-tools.js +0 -189
  411. package/dist/computer-adb.d.ts +0 -12
  412. package/dist/computer-adb.js +0 -14
  413. package/dist/console/assets/index-35-7aeIZ.js +0 -519
  414. package/dist/console/assets/index-Cejbov-Y.css +0 -1
  415. package/dist/content-filter.d.ts +0 -7
  416. package/dist/content-filter.js +0 -23
  417. package/dist/disk.d.ts +0 -33
  418. package/dist/disk.js +0 -85
  419. package/dist/door-line.d.ts +0 -23
  420. package/dist/door-line.js +0 -83
  421. package/dist/grade.d.ts +0 -63
  422. package/dist/grade.js +0 -150
  423. package/dist/harness-app.d.ts +0 -69
  424. package/dist/harness-app.js +0 -1162
  425. package/dist/mcp-servers.d.ts +0 -269
  426. package/dist/mcp-servers.js +0 -456
  427. package/dist/packs.d.ts +0 -71
  428. package/dist/packs.js +0 -180
  429. package/dist/request-start.d.ts +0 -27
  430. package/dist/request-start.js +0 -381
  431. package/dist/run-box.d.ts +0 -205
  432. package/dist/run-box.js +0 -661
  433. package/dist/run-holder.d.ts +0 -52
  434. package/dist/run-holder.js +0 -139
  435. package/dist/runs.d.ts +0 -1200
  436. package/dist/runs.js +0 -4103
  437. package/dist/sealed-settings.d.ts +0 -60
  438. package/dist/sealed-settings.js +0 -178
  439. package/dist/served-only.d.ts +0 -5
  440. package/dist/served-only.js +0 -12
  441. package/dist/sessions.d.ts +0 -6
  442. package/dist/sessions.js +0 -109
  443. package/dist/workspace/computer-serves.d.ts +0 -12
  444. package/dist/workspace/computer-serves.js +0 -15
package/dist/seal-key.js CHANGED
@@ -1,26 +1,46 @@
1
1
  // The seal key every secret is kept under (tool keys, MCP credentials, sign-ins, trigger secrets: store/seal.ts). The
2
- // server never starts without one: AGENTRUN_SEAL_KEY as it was handed (the launcher's pipe, or the environment), else
3
- // the one in agentrun/seal.key under the config home (XDG_CONFIG_HOME, else ~/.config), made there at the first start.
4
- // The same rules as the launcher's (launcher/agentrun-serve):
2
+ // server never starts without one: AGENTRUN_SEAL_KEY as it was handed (the launcher's pipe, or the environment), else the
3
+ // one in seal/seal.key in the data directory, beside the store, made there at the server's first start. There is no other
4
+ // place a key is read from. It lives and dies with the data (a disk, a volume): a copy of the data directory is a copy of
5
+ // the secrets, so it is backed up with them.
5
6
  // - made as 32 random bytes in base64, 0600, in a directory of its own that is 0700, written whole beside its name and
6
7
  // then linked to it, so two starts at once read one key, and only its path is ever printed;
7
8
  // - a plain mkdir's directory (0755) with no key yet, this user's own, is tightened to 0700 before the key is made;
8
- // - a key or a directory another user can read is refused, never changed; a linked directory is refused, never followed.
9
- // It is outside the data directory on purpose: a copy of that holds the secrets as ciphertext alone.
10
- import { randomBytes } from "node:crypto";
9
+ // - a key or a directory another user can read is refused, never changed; a linked directory, or one another user owns,
10
+ // is refused, never followed or written into.
11
+ // The store records the key's fingerprint (an HMAC of a fixed label under the key: never the key, nor a hash of it alone),
12
+ // and every process that opens the store (the server, a runner, the `import` command) checks the key it holds against it
13
+ // (bootSealKey). A store whose secrets were sealed with another key is refused, in words, and no key is ever made over
14
+ // sealed secrets, in the store or beside it in the data directory: a lost key file is not replaced by a new one. A store
15
+ // with no fingerprint takes a key that opens every value it keeps sealed, or any key when it keeps none. The server's
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
+ // one and checks it, and never makes or records one. Several data directories in one process each keep their own key.
18
+ import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
11
19
  import { chmodSync, closeSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, rmSync, writeSync } from "node:fs";
12
20
  import { join } from "node:path";
21
+ import { unseal } from "./sealing.js";
13
22
  import { SEAL_KEY_ENV, sealKeyOf } from "./tool-keys.js";
14
- import { handedSecret, holdMadeSecret } from "./secrets.js";
15
- export const SEAL_KEY_DIR = "agentrun";
23
+ import { handedSecret, holdSealKey } from "./secrets.js";
24
+ /** The seal key's own directory in the data directory, and its file there. */
25
+ export const SEAL_KEY_DIR = "seal";
16
26
  export const SEAL_KEY_FILE = "seal.key";
27
+ /** The store setting that records the key's fingerprint. */
28
+ export const SEAL_KEY_SETTING = "seal_key";
29
+ /** The fixed label the fingerprint is an HMAC of, under the key. */
30
+ const FINGERPRINT_LABEL = "agentrun seal key fingerprint v1";
31
+ /** The refusal of a store whose secrets another key sealed, word for word. */
32
+ export const SEALED_ELSEWHERE = `this store's secrets were sealed with another key; hand the server the original ${SEAL_KEY_ENV}`;
17
33
  /** The server has no seal key it can use, in words: it does not start. */
18
34
  export class SealKeyRefused extends Error {
19
35
  name = "SealKeyRefused";
20
36
  }
21
- /** The config home a seal key is kept under: XDG_CONFIG_HOME, else ~/.config; undefined with neither. */
22
- export const sealKeyHome = (env) => env.XDG_CONFIG_HOME || (env.HOME ? join(env.HOME, ".config") : undefined);
23
- 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} under $XDG_CONFIG_HOME (~/.config by default), made at the first start.`;
37
+ /** The key held is not the one the store's secrets were sealed with: it does not start. */
38
+ export class SealKeyNotTheStores extends SealKeyRefused {
39
+ name = "SealKeyNotTheStores";
40
+ }
41
+ /** Where the data directory `dataDir` keeps its seal key. */
42
+ export const sealKeyPath = (dataDir) => join(dataDir, SEAL_KEY_DIR, SEAL_KEY_FILE);
43
+ 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.`;
24
44
  const refused = (why) => new SealKeyRefused(`No seal key: ${why}. ${HOW}`);
25
45
  function lstatOf(path) {
26
46
  try {
@@ -37,105 +57,235 @@ function lstatOf(path) {
37
57
  /** No group or other permission bits: only its owner can read it. */
38
58
  const ownerOnly = (stats) => (stats.mode & 0o077) === 0;
39
59
  const mine = (stats) => typeof process.getuid !== "function" || stats.uid === process.getuid();
40
- /**
41
- * The server's seal key: `given` (AGENTRUN_SEAL_KEY as it was handed) when set, else the one kept under `configHome`,
42
- * made there at the first start. Throws SealKeyRefused, in words, when there is none it can use: the server does not start.
43
- */
44
- export function ensureSealKey(given, { configHome }) {
45
- if (given) {
46
- const key = sealKeyOf(given);
47
- if (!key)
48
- throw refused(`${SEAL_KEY_ENV} is set but is not 32 bytes in base64`);
49
- return { key, text: given, path: null, generated: false };
60
+ const linked = (dir) => refused(`${dir} is a link, and a seal key's directory is never followed through one: make it a directory of its own (mode 0700)`);
61
+ /** The key kept in `dir`, checked: undefined when there is none (no directory, or no file in it). Throws SealKeyRefused
62
+ * for a linked directory, a key or directory another user can read, or a file that holds no key: never changed. */
63
+ function keptIn(dir) {
64
+ const file = join(dir, SEAL_KEY_FILE);
65
+ const held = lstatOf(dir);
66
+ if (!held)
67
+ return undefined;
68
+ if (held.isSymbolicLink())
69
+ throw linked(dir);
70
+ if (!held.isDirectory())
71
+ throw refused(`${dir} is not a directory`);
72
+ const stats = lstatOf(file);
73
+ if (!stats)
74
+ return undefined;
75
+ if (!mine(held) || !ownerOnly(held)) {
76
+ throw refused(`${dir} can be read by another user, or is not this user's: make it 0700 (chmod 700 ${dir}); it is never changed for you once a key is in it`);
50
77
  }
51
- if (!configHome)
52
- throw refused(`${SEAL_KEY_ENV} is not set, and there is no config directory to keep one in (XDG_CONFIG_HOME or HOME)`);
53
- const dir = join(configHome, SEAL_KEY_DIR);
78
+ if (!stats.isFile() || !mine(stats) || !ownerOnly(stats)) {
79
+ throw refused(`${file} is not a file only this user can read: make it 0600 (chmod 600 ${file})`);
80
+ }
81
+ const text = readFileSync(file, "utf8").split("\n")[0].trim();
82
+ const key = sealKeyOf(text);
83
+ if (!key)
84
+ throw refused(`${file} does not hold 32 bytes in base64`);
85
+ return { key, text, path: file, generated: false };
86
+ }
87
+ /** Writes `text` as the key in `dir` (made 0700, or a plain mkdir's directory of this user's tightened to it), whole
88
+ * beside its name and then linked, so a start racing another reads the one there. Whether this call wrote it. */
89
+ function writeIn(dir, text) {
54
90
  const file = join(dir, SEAL_KEY_FILE);
55
91
  const before = lstatOf(dir);
56
92
  if (before?.isSymbolicLink())
57
- throw refused(`${dir} is a link, and a seal key's directory is never followed through one: make it a directory of its own (mode 0700)`);
93
+ throw linked(dir);
58
94
  if (before && !before.isDirectory())
59
95
  throw refused(`${dir} is not a directory`);
60
- let generated = false;
61
- if (!lstatOf(file)) {
62
- // A plain mkdir's directory, this user's own, with no key yet: tightened before a key is written in it.
63
- if (before && mine(before) && !ownerOnly(before))
64
- chmodSync(dir, 0o700);
65
- if (!before) {
66
- try {
67
- mkdirSync(dir, { recursive: true, mode: 0o700 });
68
- }
69
- catch (error) {
70
- throw refused(`${dir} could not be made (${error.code ?? String(error)})`);
71
- }
72
- }
73
- const text = randomBytes(32).toString("base64");
74
- const temp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}`;
96
+ if (before && !mine(before))
97
+ throw refused(`${dir} is not this user's: a seal key is never written into another user's directory`);
98
+ // A plain mkdir's directory, this user's own, with no key yet: tightened before a key is written in it.
99
+ if (before && mine(before) && !ownerOnly(before))
100
+ chmodSync(dir, 0o700);
101
+ if (!before) {
75
102
  try {
76
- const fd = openSync(temp, "wx", 0o600);
77
- try {
78
- writeSync(fd, `${text}\n`);
79
- }
80
- finally {
81
- closeSync(fd);
82
- }
83
- try {
84
- linkSync(temp, file);
85
- generated = true;
86
- }
87
- catch (error) {
88
- // Another start made it first: each start reads the one there.
89
- if (error.code !== "EEXIST")
90
- throw error;
91
- }
103
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
92
104
  }
93
105
  catch (error) {
94
- throw refused(`${file} could not be written (${error.code ?? String(error)})`);
106
+ throw refused(`${dir} could not be made (${error.code ?? String(error)})`);
107
+ }
108
+ }
109
+ const temp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}`;
110
+ try {
111
+ const fd = openSync(temp, "wx", 0o600);
112
+ try {
113
+ writeSync(fd, `${text}\n`);
95
114
  }
96
115
  finally {
97
- rmSync(temp, { force: true });
116
+ closeSync(fd);
117
+ }
118
+ try {
119
+ linkSync(temp, file);
120
+ return true;
121
+ }
122
+ catch (error) {
123
+ // Another start made it first: each start reads the one there.
124
+ if (error.code !== "EEXIST")
125
+ throw error;
126
+ return false;
98
127
  }
99
128
  }
100
- const held = lstatOf(dir);
101
- if (!held || held.isSymbolicLink() || !held.isDirectory() || !mine(held) || !ownerOnly(held)) {
102
- throw refused(`${dir} can be read by another user, or is not this user's: make it 0700 (chmod 700 ${dir}); it is never changed for you once a key is in it`);
129
+ catch (error) {
130
+ throw refused(`${file} could not be written (${error.code ?? String(error)})`);
103
131
  }
104
- const stats = lstatOf(file);
105
- if (!stats || !stats.isFile() || !mine(stats) || !ownerOnly(stats)) {
106
- throw refused(`${file} is not a file only this user can read: make it 0600 (chmod 600 ${file}), or remove it to have a new one made at the next start`);
132
+ finally {
133
+ rmSync(temp, { force: true });
107
134
  }
108
- const text = readFileSync(file, "utf8").split("\n")[0].trim();
109
- const key = sealKeyOf(text);
110
- if (!key)
111
- throw refused(`${file} does not hold 32 bytes in base64: remove it to have a new one made at the next start (the secrets kept under the old one will not open)`);
112
- return { key, text, path: file, generated };
135
+ }
136
+ /** The key file's rules alone, with no store to check against: `given` (AGENTRUN_SEAL_KEY as it was handed) when set,
137
+ * else the one kept in `dataDir`, made there when there is none. A start never calls this by itself: bootSealKey checks
138
+ * the key against the store first, and makes one only for a store that holds no secret. */
139
+ export function ensureSealKey(given, { dataDir }) {
140
+ if (given) {
141
+ const key = sealKeyOf(given);
142
+ if (!key)
143
+ throw refused(`${SEAL_KEY_ENV} is set but is not 32 bytes in base64`);
144
+ return { key, text: given, path: null, generated: false };
145
+ }
146
+ const dir = join(dataDir, SEAL_KEY_DIR);
147
+ const kept = keptIn(dir);
148
+ if (kept)
149
+ return kept;
150
+ const generated = writeIn(dir, randomBytes(32).toString("base64"));
151
+ const made = keptIn(dir);
152
+ if (!made)
153
+ throw refused(`${join(dir, SEAL_KEY_FILE)} could not be read back`);
154
+ return { ...made, generated };
155
+ }
156
+ /** The fingerprint the store records of `key`: an HMAC of a fixed label under it. Neither the key nor a hash of it alone. */
157
+ export const sealKeyFingerprint = (key) => createHmac("sha256", key).update(FINGERPRINT_LABEL).digest("base64url");
158
+ /** The fingerprint a store setting's value records: undefined with none, null for one that does not read. */
159
+ function recordedIn(value) {
160
+ if (value === undefined)
161
+ return undefined;
162
+ const record = value;
163
+ return record?.v === 1 && typeof record.fingerprint === "string" ? record.fingerprint : null;
164
+ }
165
+ const sameText = (a, b) => a.length === b.length && timingSafeEqual(Buffer.from(a), Buffer.from(b));
166
+ function opensUnder(key, sealed, aad) {
167
+ try {
168
+ unseal(key, Buffer.from(sealed), aad);
169
+ return true;
170
+ }
171
+ catch {
172
+ return false;
173
+ }
174
+ }
175
+ async function storeSealOf(store) {
176
+ const fingerprint = recordedIn(await store.settings.get(SEAL_KEY_SETTING));
177
+ if (fingerprint !== undefined)
178
+ return { fingerprint, sealed: [] };
179
+ const rows = (await store.sealedSecrets.all()).map((row) => (key) => opensUnder(key, row.sealed, row.aad));
180
+ return { fingerprint, sealed: rows };
181
+ }
182
+ const holdsSecrets = (seal) => seal.fingerprint !== undefined || seal.sealed.length > 0;
183
+ /** Whether `key` is the store's, or why not: the one its fingerprint records; with none recorded, one that opens every
184
+ * value it keeps sealed (some opening and some not is values sealed under more than one key: no key is taken over
185
+ * that), or any key for a store that keeps none. */
186
+ function notTheStoresWhy(seal, key) {
187
+ if (seal.fingerprint === null)
188
+ return ` (the store's record of its key, setting ${SEAL_KEY_SETTING}, does not read)`;
189
+ if (seal.fingerprint !== undefined)
190
+ return sameText(seal.fingerprint, sealKeyFingerprint(key)) ? undefined : "";
191
+ const shut = seal.sealed.filter((opens) => !opens(key)).length;
192
+ if (shut === 0)
193
+ return undefined;
194
+ return shut === seal.sealed.length ? "" : ` (${shut} of the ${seal.sealed.length} values it keeps sealed do not open under this key: they were sealed under more than one)`;
195
+ }
196
+ const notTheStores = (why) => new SealKeyNotTheStores(`${SEALED_ELSEWHERE}. ${why}`);
197
+ const PUT_BACK = `put the original there (mode 0600, in a 0700 directory), or hand it as ${SEAL_KEY_ENV}`;
198
+ async function sealKeyFor(store, dataDir, given, role, write) {
199
+ const kept = await storeSealOf(store);
200
+ const dir = join(dataDir, SEAL_KEY_DIR);
201
+ const file = join(dir, SEAL_KEY_FILE);
202
+ let seal;
203
+ if (given) {
204
+ const key = sealKeyOf(given);
205
+ if (!key)
206
+ throw refused(`${SEAL_KEY_ENV} is set but is not 32 bytes in base64`);
207
+ const why = notTheStoresWhy(kept, key);
208
+ if (why !== undefined)
209
+ throw notTheStores(`The ${SEAL_KEY_ENV} handed now is not it${why}.`);
210
+ seal = { key, text: given, path: null, generated: false };
211
+ }
212
+ else {
213
+ seal = keptIn(dir);
214
+ if (seal) {
215
+ const why = notTheStoresWhy(kept, seal.key);
216
+ if (why !== undefined)
217
+ throw notTheStores(`${file} holds another key${why}: ${PUT_BACK}.`);
218
+ }
219
+ else if (holdsSecrets(kept)) {
220
+ // No key here, over a store that holds secrets: never a new one.
221
+ throw notTheStores(`There is no key in ${file}: ${PUT_BACK}.`);
222
+ }
223
+ else if (role === "runner") {
224
+ // A runner never makes a key: it reads the one the server made.
225
+ throw refused(`there is none in ${file}, and this store records none: start the server on this data directory first, which makes it, or hand ${SEAL_KEY_ENV}`);
226
+ }
227
+ else {
228
+ // A store that holds no secret: its key is made here, at the server's first start (or the import's, which sets a data
229
+ // directory up as the server does when none has); a dry run makes none, and has none.
230
+ if (!write)
231
+ return undefined;
232
+ seal = ensureSealKey(undefined, { dataDir });
233
+ }
234
+ }
235
+ if (write && role !== "runner" && kept.fingerprint === undefined) {
236
+ // Recorded once: the first server to record it wins, and one that loses to another key's record is refused.
237
+ const fingerprint = sealKeyFingerprint(seal.key);
238
+ const now = recordedIn(await store.settings.putIfAbsent(SEAL_KEY_SETTING, { v: 1, fingerprint }));
239
+ if (now === undefined || now === null || !sameText(now, fingerprint)) {
240
+ // A key this start made for a store another process recorded first seals nothing: it goes.
241
+ if (seal.generated && seal.path)
242
+ rmSync(seal.path, { force: true });
243
+ throw notTheStores("Another process recorded its key in this store first.");
244
+ }
245
+ }
246
+ return seal;
247
+ }
248
+ /** `env` (one withSecrets made) with `text` as its seal key, read by name and never enumerated, as withSecrets gives a
249
+ * secret: so what reads the key from it gets the one its start checked against its store. */
250
+ export function withSealKey(env, text) {
251
+ // A copy, every property as it is (a withSecrets secret stays unenumerable, its saved-keys mark too), the key in place of
252
+ // whatever it held.
253
+ const out = {};
254
+ for (const name of Reflect.ownKeys(env))
255
+ if (name !== SEAL_KEY_ENV)
256
+ Object.defineProperty(out, name, Object.getOwnPropertyDescriptor(env, name));
257
+ Object.defineProperty(out, SEAL_KEY_ENV, { value: text, enumerable: false, writable: false, configurable: false });
258
+ return out;
113
259
  }
114
260
  /** The line a start prints about its seal key: where it is, never the key. */
115
261
  export function sealKeyLine(seal) {
116
262
  if (!seal.path)
117
263
  return `agentrun-serve: the seal key is ${SEAL_KEY_ENV}, as it was handed`;
118
- return `agentrun-serve: ${seal.generated ? "made a new seal key" : "the seal key is"} at ${seal.path} (0600): every secret saved here opens with it alone, so keep it, and keep it apart from the data directory`;
264
+ return `agentrun-serve: ${seal.generated ? "made a new seal key" : "the seal key is"} at ${seal.path} (0600), beside the store: every secret saved here opens with it alone, so back it up with the data directory, and keep the two together`;
119
265
  }
120
- /** The seal key every entry point boots the one way — the server, the runner and the `import` command all call this, so
121
- * there is one rule, not three copies: the key handed over (AGENTRUN_SEAL_KEY), else the one kept under the config home of
122
- * `env` (made at the first boot, only its path printed). A made key is held back as this process's own secret, so the
123
- * environment it reads next (withSecrets) carries it. Throws with the start message when there is none and none can be made.
124
- * `say` takes the made-key line (stderr by default). */
125
- export function bootSealKey(env = process.env, say = (line) => void process.stderr.write(line)) {
126
- const handed = handedSecret(SEAL_KEY_ENV);
266
+ /** A refusal in the words a start says: a key that is not the store's, or none it can use. */
267
+ function startRefusal(error) {
268
+ if (error instanceof SealKeyNotTheStores)
269
+ return new SealKeyNotTheStores(`agentrun-serve does not start: ${error.message}`, { cause: error });
270
+ return new SealKeyRefused(`agentrun-serve does not start without a seal key. ${error.message}`, { cause: error });
271
+ }
272
+ export async function bootSealKey(store, dataDir, options = {}) {
273
+ const given = "given" in options ? options.given : handedSecret(SEAL_KEY_ENV);
274
+ const say = options.say ?? ((line) => void process.stderr.write(line));
127
275
  let seal;
128
276
  try {
129
- seal = ensureSealKey(handed, { configHome: sealKeyHome(env) });
277
+ seal = await sealKeyFor(store, dataDir, given, options.role ?? "server", options.write !== false);
130
278
  }
131
279
  catch (error) {
132
280
  if (error instanceof SealKeyRefused)
133
- throw new Error(`agentrun-serve does not start without a seal key. ${error.message}`, { cause: error });
281
+ throw startRefusal(error);
134
282
  throw error;
135
283
  }
136
- if (!handed)
137
- holdMadeSecret(SEAL_KEY_ENV, seal.text);
284
+ if (!seal)
285
+ return undefined;
286
+ // On this process's redaction list while it is open (secrets.ts holdSealKey); each holder passes its own key on.
287
+ const release = holdSealKey(seal.text);
138
288
  if (seal.generated)
139
289
  say(`${sealKeyLine(seal)}\n`);
140
- return seal;
290
+ return { ...seal, release };
141
291
  }
@@ -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. */
package/dist/secrets.d.ts CHANGED
@@ -23,8 +23,8 @@ export type StoredKeys = (name: string) => string | undefined;
23
23
  * every other key, token, secret or password `env` names. One shorter than the checker's MIN_SECRET,
24
24
  * whitespace aside, matches too much text by chance to be refused, and is left out. */
25
25
  export declare const hostSecrets: (env: NodeJS.ProcessEnv, stored?: StoredKeys) => string[];
26
- /** Holds a secret this process made (seal-key.ts' generated seal key), read by name like one it was handed. */
27
- export declare function holdMadeSecret(name: string, value: string): void;
26
+ /** Lists `text` among this process's seal keys, for redaction alone, until the returned release is called. */
27
+ export declare function holdSealKey(text: string): () => void;
28
28
  /** A secret this process was handed (over its pipe, or in its environment), never one it made itself: what a start asks
29
29
  * to tell a handed seal key from none, so a second server in one process makes or reads its own and is not handed the
30
30
  * first one's. */
@@ -58,14 +58,6 @@ export declare function mcpCredentials(): Record<string, {
58
58
  export declare const mcpSecretValues: (credentials: Record<string, {
59
59
  headers?: Record<string, string>;
60
60
  }>) => string[];
61
- /** The pipe's MCP entry for `credentials`, to follow the secrets `handover` encodes. */
62
- export declare const mcpHandover: (credentials: Record<string, unknown>) => Buffer;
63
- /** A run's saved sign-in as its pipe carries it, after its secrets (handover). */
64
- export declare const handoverSignIn: (value: {
65
- provider: string;
66
- ref: string;
67
- save: boolean;
68
- }) => Buffer;
69
61
  /** The saved sign-in this run's process was handed over its pipe, if any: read by the browser tool alone. */
70
62
  export declare function handedSignIn(): {
71
63
  provider: string;
package/dist/secrets.js CHANGED
@@ -94,23 +94,31 @@ const SECRET_NAME = /(?:^|_)(?:KEY|TOKEN|SECRET|PASSWORD)$/i;
94
94
  * every other key, token, secret or password `env` names. One shorter than the checker's MIN_SECRET,
95
95
  * whitespace aside, matches too much text by chance to be refused, and is left out. */
96
96
  export const hostSecrets = (env, stored) => {
97
- const held = [...SECRET_NAMES.flatMap((name) => [secret(name) ?? "", stored?.(name) ?? ""]), ...mcpSecretValues(mcpCredentials())];
97
+ const held = [...SECRET_NAMES.flatMap((name) => [secret(name) ?? "", stored?.(name) ?? ""]), ...mcpSecretValues(mcpCredentials()), ...sealKeys.keys()];
98
98
  const named = Object.entries(env).filter(([name]) => SECRET_NAME.test(name) && !SECRET_NAMES.includes(name)).map(([, value]) => value ?? "");
99
99
  return [...new Set([...held, ...named])].filter((value) => value.replace(/\s+/g, "").length >= MIN_SECRET);
100
100
  };
101
- /** The secrets this process made itself for want of one it was handed: the seal key a start keeps under the config home
102
- * (seal-key.ts) when none was given. Read last, after the handed and the environment's, so a given one always wins;
103
- * never in the environment, so no child inherits it. */
104
- const made = new Map();
105
- /** Holds a secret this process made (seal-key.ts' generated seal key), read by name like one it was handed. */
106
- export function holdMadeSecret(name, value) {
107
- if (!SECRET_NAMES.includes(name))
108
- throw new Error(`${name} is not a secret the launcher lists`);
109
- made.set(name, value);
101
+ /** The seal keys this process's open stores were booted with (seal-key.ts bootSealKey), by how many hold each: several
102
+ * data directories in one process each keep their own. Never read as a secret by name (each holder passes its own key
103
+ * on): only listed by hostSecrets, so what a run writes is cut of every one. */
104
+ const sealKeys = new Map();
105
+ /** Lists `text` among this process's seal keys, for redaction alone, until the returned release is called. */
106
+ export function holdSealKey(text) {
107
+ sealKeys.set(text, (sealKeys.get(text) ?? 0) + 1);
108
+ let released = false;
109
+ return () => {
110
+ if (released)
111
+ return;
112
+ released = true;
113
+ const left = (sealKeys.get(text) ?? 1) - 1;
114
+ if (left > 0)
115
+ sealKeys.set(text, left);
116
+ else
117
+ sealKeys.delete(text);
118
+ };
110
119
  }
111
- /** A secret this process was started with: as handed over, else (no launcher) as its environment has it now, else one it
112
- * made itself (holdMadeSecret). */
113
- const own = (name) => held.get(name) ?? process.env[name] ?? made.get(name);
120
+ /** A secret this process was started with: as handed over, else (no launcher) as its environment has it now. */
121
+ const own = (name) => held.get(name) ?? process.env[name];
114
122
  /** A secret this process was handed (over its pipe, or in its environment), never one it made itself: what a start asks
115
123
  * to tell a handed seal key from none, so a second server in one process makes or reads its own and is not handed the
116
124
  * first one's. */
@@ -168,10 +176,6 @@ export function mcpCredentials() {
168
176
  }
169
177
  /** Every header value of `credentials`: what a secret scan refuses. */
170
178
  export const mcpSecretValues = (credentials) => Object.values(credentials).flatMap((server) => Object.values(server.headers ?? {})).flatMap((value) => [value, value.replace(/^Bearer\s+/i, "")]);
171
- /** The pipe's MCP entry for `credentials`, to follow the secrets `handover` encodes. */
172
- export const mcpHandover = (credentials) => encode([[MCP_AUTH, JSON.stringify(credentials)]]);
173
- /** A run's saved sign-in as its pipe carries it, after its secrets (handover). */
174
- export const handoverSignIn = (value) => encode([[SIGN_IN_PAIR, JSON.stringify(value)]]);
175
179
  /** The saved sign-in this run's process was handed over its pipe, if any: read by the browser tool alone. */
176
180
  export function handedSignIn() {
177
181
  try {