@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.60

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 (474) hide show
  1. package/CHANGELOG.md +402 -1
  2. package/README.md +516 -190
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agent-delete.d.ts +6 -9
  8. package/dist/agent-delete.js +5 -3
  9. package/dist/agent-package.js +11 -1
  10. package/dist/agents-store.js +1 -1
  11. package/dist/answer-text.d.ts +3 -0
  12. package/dist/answer-text.js +22 -0
  13. package/dist/api-only.d.ts +2 -2
  14. package/dist/api-only.js +3 -3
  15. package/dist/archil-routes.d.ts +4 -1
  16. package/dist/archil-routes.js +15 -12
  17. package/dist/archil-settings.d.ts +18 -8
  18. package/dist/archil-settings.js +35 -17
  19. package/dist/attach-conformance.js +5 -4
  20. package/dist/box-paths.d.ts +3 -2
  21. package/dist/box-paths.js +5 -4
  22. package/dist/browser-computer.d.ts +3 -8
  23. package/dist/browser-computer.js +12 -35
  24. package/dist/browser-cost.js +94 -20
  25. package/dist/capacity.d.ts +1 -1
  26. package/dist/capacity.js +3 -3
  27. package/dist/chatgpt-plan.d.ts +7 -0
  28. package/dist/chatgpt-plan.js +35 -11
  29. package/dist/claude-login-token.d.ts +20 -11
  30. package/dist/claude-login-token.js +175 -107
  31. package/dist/claude-login.d.ts +124 -33
  32. package/dist/claude-login.js +562 -85
  33. package/dist/claude-sign-in.d.ts +3 -0
  34. package/dist/claude-sign-in.js +10 -1
  35. package/dist/cli-learning/connections.js +1 -1
  36. package/dist/cli.js +323 -292
  37. package/dist/composio-made.d.ts +1 -6
  38. package/dist/composio-made.js +1 -6
  39. package/dist/composio-owners.d.ts +26 -0
  40. package/dist/composio-owners.js +36 -0
  41. package/dist/composio-preset.d.ts +56 -23
  42. package/dist/composio-preset.js +173 -77
  43. package/dist/composio-triggers.d.ts +4 -4
  44. package/dist/composio-triggers.js +6 -7
  45. package/dist/compute-cost.js +11 -2
  46. package/dist/computer-attach.d.ts +6 -3
  47. package/dist/computer-attach.js +41 -29
  48. package/dist/computer-held-routes.d.ts +1 -1
  49. package/dist/computer-held-routes.js +9 -4
  50. package/dist/computer-keys.d.ts +11 -1
  51. package/dist/computer-keys.js +26 -1
  52. package/dist/computer-record.js +3 -1
  53. package/dist/computer-view.d.ts +5 -3
  54. package/dist/computer-view.js +10 -6
  55. package/dist/computer-viewer.js +36 -7
  56. package/dist/computers.d.ts +2 -1
  57. package/dist/computers.js +6 -3
  58. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  59. package/dist/console/assets/backend-QnwGVBeU.js +166 -0
  60. package/dist/console/assets/index-DZi-muIj.js +629 -0
  61. package/dist/console/assets/share-pz61zIn9.js +6 -0
  62. package/dist/console/assets/styles-CcceGcu2.js +291 -0
  63. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  64. package/dist/console/index.html +4 -3
  65. package/dist/console/share.html +17 -0
  66. package/dist/decisions.d.ts +17 -7
  67. package/dist/decisions.js +41 -15
  68. package/dist/dial-relay.js +10 -4
  69. package/dist/docker-daemon.js +4 -5
  70. package/dist/docker-host-addresses.js +29 -11
  71. package/dist/email/account.d.ts +6 -0
  72. package/dist/email/account.js +6 -0
  73. package/dist/email/authentication.d.ts +21 -0
  74. package/dist/email/authentication.js +106 -0
  75. package/dist/email/email-faux.d.ts +11 -2
  76. package/dist/email/email-faux.js +21 -5
  77. package/dist/email/mail.d.ts +25 -0
  78. package/dist/email/mail.js +58 -2
  79. package/dist/email/names.js +2 -2
  80. package/dist/email/tools.d.ts +9 -4
  81. package/dist/email/tools.js +95 -13
  82. package/dist/env-switch.d.ts +12 -2
  83. package/dist/env-switch.js +23 -3
  84. package/dist/errors.d.ts +1 -0
  85. package/dist/errors.js +2 -0
  86. package/dist/factory-activity.d.ts +68 -0
  87. package/dist/factory-activity.js +153 -0
  88. package/dist/factory-runs.d.ts +11 -0
  89. package/dist/factory-runs.js +52 -0
  90. package/dist/fal-price.d.ts +11 -1
  91. package/dist/fal-price.js +33 -0
  92. package/dist/faux-computers.js +1 -1
  93. package/dist/filed-answer.d.ts +2 -2
  94. package/dist/filed-answer.js +2 -2
  95. package/dist/filed-tool.d.ts +32 -0
  96. package/dist/filed-tool.js +122 -0
  97. package/dist/graph-served.d.ts +10 -5
  98. package/dist/graph-served.js +40 -10
  99. package/dist/handed-values.js +1 -2
  100. package/dist/harness-check.d.ts +2 -1
  101. package/dist/harness-check.js +45 -12
  102. package/dist/harness-keys.d.ts +1 -2
  103. package/dist/harness-keys.js +10 -8
  104. package/dist/harness-opencode/facts.js +2 -0
  105. package/dist/harness-recipe-entry.d.ts +9 -3
  106. package/dist/harness-recipe-entry.js +18 -9
  107. package/dist/harness-recipe.d.ts +21 -0
  108. package/dist/harness-recipe.js +25 -3
  109. package/dist/harness-table.d.ts +12 -0
  110. package/dist/harness-table.js +21 -6
  111. package/dist/harness.js +6 -2
  112. package/dist/helper-env.d.ts +4 -1
  113. package/dist/helper-env.js +4 -1
  114. package/dist/host-check.d.ts +2 -3
  115. package/dist/host-check.js +13 -7
  116. package/dist/hosted-search.js +1 -1
  117. package/dist/import-worker.js +2 -2
  118. package/dist/import.d.ts +20 -8
  119. package/dist/import.js +448 -187
  120. package/dist/key-refusal.d.ts +14 -2
  121. package/dist/key-refusal.js +97 -33
  122. package/dist/learn/audit.d.ts +28 -27
  123. package/dist/learn/audit.js +87 -62
  124. package/dist/learn/check.js +1 -1
  125. package/dist/learn/commit.d.ts +35 -43
  126. package/dist/learn/commit.js +62 -270
  127. package/dist/learn/compile.d.ts +9 -6
  128. package/dist/learn/compile.js +51 -28
  129. package/dist/learn/corrections.js +1 -1
  130. package/dist/learn/delete.d.ts +5 -12
  131. package/dist/learn/delete.js +17 -30
  132. package/dist/learn/field-check.d.ts +111 -0
  133. package/dist/learn/field-check.js +174 -0
  134. package/dist/learn/forget-run.d.ts +16 -0
  135. package/dist/learn/forget-run.js +53 -0
  136. package/dist/learn/index.js +1 -1
  137. package/dist/learn/learning-of.d.ts +0 -4
  138. package/dist/learn/learning-of.js +0 -5
  139. package/dist/learn/ledger.d.ts +32 -29
  140. package/dist/learn/ledger.js +26 -19
  141. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  142. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  143. package/dist/learn/legacy/place.d.ts +16 -0
  144. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  145. package/dist/learn/legacy/scrub.d.ts +28 -0
  146. package/dist/learn/legacy/scrub.js +258 -0
  147. package/dist/learn/promote.d.ts +119 -102
  148. package/dist/learn/promote.js +119 -262
  149. package/dist/learn/reset-ledger.d.ts +18 -0
  150. package/dist/learn/reset-ledger.js +14 -0
  151. package/dist/learn/rows.d.ts +186 -0
  152. package/dist/learn/rows.js +376 -0
  153. package/dist/learn/secrets.d.ts +4 -0
  154. package/dist/learn/secrets.js +12 -0
  155. package/dist/learn/workflow-draft.d.ts +4 -1
  156. package/dist/learn/workflow-draft.js +12 -2
  157. package/dist/learned-nodes.d.ts +8 -5
  158. package/dist/learned-nodes.js +8 -5
  159. package/dist/learned-workflow.d.ts +2 -1
  160. package/dist/learned-workflow.js +13 -10
  161. package/dist/learning-cost.d.ts +25 -8
  162. package/dist/learning-cost.js +23 -8
  163. package/dist/learning-reset.d.ts +1 -1
  164. package/dist/learning-reset.js +9 -11
  165. package/dist/learning-routes.d.ts +60 -81
  166. package/dist/learning-routes.js +187 -360
  167. package/dist/learning-setting.d.ts +6 -0
  168. package/dist/learning-setting.js +11 -1
  169. package/dist/learning-words.d.ts +2 -0
  170. package/dist/learning-words.js +2 -0
  171. package/dist/learning.d.ts +18 -24
  172. package/dist/learning.js +35 -66
  173. package/dist/listen-first.d.ts +5 -4
  174. package/dist/listen-first.js +4 -5
  175. package/dist/live-reach.d.ts +7 -0
  176. package/dist/live-reach.js +7 -0
  177. package/dist/mcp-api-only-origins.d.ts +15 -0
  178. package/dist/mcp-api-only-origins.js +40 -0
  179. package/dist/mcp-gateway.d.ts +22 -2
  180. package/dist/mcp-gateway.js +85 -11
  181. package/dist/mcp-oauth.d.ts +1 -1
  182. package/dist/mcp-oauth.js +3 -2
  183. package/dist/mcp-probe.d.ts +3 -0
  184. package/dist/mcp-probe.js +3 -0
  185. package/dist/mcp-resources.d.ts +1 -1
  186. package/dist/mcp-secret-writes.d.ts +24 -2
  187. package/dist/mcp-secret-writes.js +30 -2
  188. package/dist/mcp-servers-store.d.ts +52 -14
  189. package/dist/mcp-servers-store.js +165 -61
  190. package/dist/mcp-sources.d.ts +1 -2
  191. package/dist/mcp-sources.js +1 -2
  192. package/dist/mcp-store.d.ts +5 -5
  193. package/dist/mcp-store.js +3 -3
  194. package/dist/mcp.js +1 -1
  195. package/dist/model-gateway.d.ts +1 -1
  196. package/dist/model-gateway.js +20 -36
  197. package/dist/native/discovery.d.ts +6 -0
  198. package/dist/native/discovery.js +14 -1
  199. package/dist/native/remote.d.ts +5 -0
  200. package/dist/native/remote.js +16 -0
  201. package/dist/native/runtime.js +3 -2
  202. package/dist/observation/observer.d.ts +6 -6
  203. package/dist/ollama-provider.d.ts +23 -9
  204. package/dist/ollama-provider.js +49 -20
  205. package/dist/openapi.js +290 -79
  206. package/dist/otel/genai.d.ts +83 -7
  207. package/dist/otel/genai.js +69 -9
  208. package/dist/otel/tracer.d.ts +42 -13
  209. package/dist/otel/tracer.js +241 -56
  210. package/dist/page.d.ts +7 -1
  211. package/dist/page.js +76 -22
  212. package/dist/paid-calls.d.ts +6 -4
  213. package/dist/paid-calls.js +15 -7
  214. package/dist/place-offers.d.ts +58 -34
  215. package/dist/place-offers.js +96 -54
  216. package/dist/place.d.ts +41 -20
  217. package/dist/place.js +97 -47
  218. package/dist/print.js +1 -1
  219. package/dist/provider.d.ts +3 -2
  220. package/dist/provider.js +17 -8
  221. package/dist/purged-workflow.d.ts +0 -33
  222. package/dist/purged-workflow.js +3 -71
  223. package/dist/redact/match.d.ts +42 -9
  224. package/dist/redact/match.js +356 -54
  225. package/dist/run-census.d.ts +1 -1
  226. package/dist/run-census.js +4 -5
  227. package/dist/run-cut.js +4 -5
  228. package/dist/run-export-store.d.ts +15 -0
  229. package/dist/run-export-store.js +30 -0
  230. package/dist/run-export.d.ts +139 -0
  231. package/dist/run-export.js +379 -0
  232. package/dist/run-file-cut.d.ts +5 -0
  233. package/dist/run-file-cut.js +13 -0
  234. package/dist/run-launch.d.ts +3 -3
  235. package/dist/run-launch.js +16 -3
  236. package/dist/run-learning-served.d.ts +3 -3
  237. package/dist/run-learning-served.js +1 -1
  238. package/dist/run-listing.d.ts +1 -1
  239. package/dist/run-model-key.d.ts +15 -6
  240. package/dist/run-model-key.js +30 -31
  241. package/dist/run-reads-over-store.js +4 -4
  242. package/dist/run-secrets.js +3 -5
  243. package/dist/run-timeline-served.d.ts +1 -1
  244. package/dist/run-timeline-served.js +8 -5
  245. package/dist/runnable.js +26 -9
  246. package/dist/runner/adapter-loop.d.ts +35 -18
  247. package/dist/runner/adapter-loop.js +94 -47
  248. package/dist/runner/adapter-run-spec.d.ts +14 -1
  249. package/dist/runner/adapter-run-spec.js +73 -46
  250. package/dist/runner/adapters/pi.js +4 -2
  251. package/dist/runner/audit.d.ts +10 -9
  252. package/dist/runner/audit.js +64 -67
  253. package/dist/runner/beside.js +5 -6
  254. package/dist/runner/claim-secrets.d.ts +10 -3
  255. package/dist/runner/claim-secrets.js +29 -13
  256. package/dist/runner/cli-run-spec.d.ts +18 -0
  257. package/dist/runner/cli-run-spec.js +87 -58
  258. package/dist/runner/compare-end.d.ts +2 -3
  259. package/dist/runner/compare-end.js +30 -11
  260. package/dist/runner/conformance/harness.js +2 -3
  261. package/dist/runner/conformance/subject.d.ts +4 -1
  262. package/dist/runner/disk-free.d.ts +15 -4
  263. package/dist/runner/disk-free.js +25 -7
  264. package/dist/runner/feedback-round.d.ts +1 -1
  265. package/dist/runner/feedback-round.js +2 -2
  266. package/dist/runner/harness-loops.js +3 -4
  267. package/dist/runner/held.d.ts +5 -12
  268. package/dist/runner/held.js +0 -25
  269. package/dist/runner/journal-kinds.d.ts +8 -2
  270. package/dist/runner/journal-kinds.js +23 -5
  271. package/dist/runner/learned-first.d.ts +0 -2
  272. package/dist/runner/learned-first.js +23 -7
  273. package/dist/runner/learning-end.d.ts +14 -24
  274. package/dist/runner/learning-end.js +52 -94
  275. package/dist/runner/learning-seed.d.ts +13 -16
  276. package/dist/runner/learning-seed.js +13 -23
  277. package/dist/runner/live-ticker.js +7 -5
  278. package/dist/runner/loop-contract.d.ts +0 -2
  279. package/dist/runner/loop.d.ts +7 -0
  280. package/dist/runner/loop.js +1 -0
  281. package/dist/runner/main.js +13 -12
  282. package/dist/runner/mcp-claim.js +21 -5
  283. package/dist/runner/mcp-run.d.ts +4 -0
  284. package/dist/runner/mcp-run.js +2 -0
  285. package/dist/runner/meta-tools.js +3 -2
  286. package/dist/runner/metrics.d.ts +7 -0
  287. package/dist/runner/metrics.js +19 -0
  288. package/dist/runner/model-route.d.ts +10 -7
  289. package/dist/runner/model-route.js +79 -15
  290. package/dist/runner/native-loop.js +12 -11
  291. package/dist/runner/presence.d.ts +1 -4
  292. package/dist/runner/presence.js +6 -8
  293. package/dist/runner/promotion.d.ts +39 -36
  294. package/dist/runner/promotion.js +168 -112
  295. package/dist/runner/redact.d.ts +3 -1
  296. package/dist/runner/redact.js +5 -3
  297. package/dist/runner/reflect-hook.d.ts +2 -2
  298. package/dist/runner/reflect-hook.js +4 -1
  299. package/dist/runner/responses-fetch.d.ts +36 -0
  300. package/dist/runner/responses-fetch.js +511 -0
  301. package/dist/runner/run-child-host.d.ts +21 -14
  302. package/dist/runner/run-child-host.js +187 -141
  303. package/dist/runner/run-child.js +11 -4
  304. package/dist/runner/runner-check.js +5 -1
  305. package/dist/runner/runner.d.ts +3 -4
  306. package/dist/runner/runner.js +13 -9
  307. package/dist/runner/sdk-loop.js +10 -12
  308. package/dist/runner/spec-holds.d.ts +8 -1
  309. package/dist/runner/spec-holds.js +9 -4
  310. package/dist/runner/workflow-calls.d.ts +9 -0
  311. package/dist/runner/workflow-calls.js +150 -0
  312. package/dist/runner/workflow-first.d.ts +120 -32
  313. package/dist/runner/workflow-first.js +218 -94
  314. package/dist/runner/workflow-spec.js +1 -1
  315. package/dist/runs-over-store.js +8 -7
  316. package/dist/save-once.d.ts +14 -0
  317. package/dist/save-once.js +31 -0
  318. package/dist/scrub-command.d.ts +34 -31
  319. package/dist/scrub-command.js +116 -147
  320. package/dist/sdk/check.d.ts +1 -4
  321. package/dist/sdk/check.js +2 -3
  322. package/dist/sdk/runs.d.ts +26 -7
  323. package/dist/sdk/runs.js +194 -78
  324. package/dist/seal-key.js +4 -4
  325. package/dist/secret-cut.d.ts +3 -0
  326. package/dist/secret-cut.js +7 -1
  327. package/dist/secret-rules.d.ts +8 -1
  328. package/dist/secret-rules.js +482 -53
  329. package/dist/secrets.d.ts +55 -9
  330. package/dist/secrets.js +345 -21
  331. package/dist/server-fs.d.ts +1 -1
  332. package/dist/server-fs.js +1 -1
  333. package/dist/server-keys.d.ts +10 -3
  334. package/dist/server-keys.js +16 -3
  335. package/dist/server-secrets-store.js +2 -4
  336. package/dist/server.d.ts +30 -18
  337. package/dist/server.js +520 -238
  338. package/dist/share-context.d.ts +22 -0
  339. package/dist/share-context.js +76 -0
  340. package/dist/shell-lex.d.ts +105 -0
  341. package/dist/shell-lex.js +646 -0
  342. package/dist/sign-ins-store.d.ts +5 -7
  343. package/dist/sign-ins-store.js +12 -16
  344. package/dist/sign-ins.d.ts +7 -11
  345. package/dist/sign-ins.js +40 -41
  346. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  347. package/dist/source-sync/auxiliary.js +2 -2
  348. package/dist/start-switches.d.ts +6 -5
  349. package/dist/start-switches.js +8 -4
  350. package/dist/stats.d.ts +5 -1
  351. package/dist/stats.js +1 -1
  352. package/dist/store/agent-body.js +2 -2
  353. package/dist/store/dialect.d.ts +4 -0
  354. package/dist/store/dialect.js +1 -0
  355. package/dist/store/index.d.ts +2 -2
  356. package/dist/store/index.js +1 -1
  357. package/dist/store/mcp-record-keys.d.ts +10 -0
  358. package/dist/store/mcp-record-keys.js +13 -0
  359. package/dist/store/postgres/dialect.js +2 -0
  360. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  361. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  362. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  363. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  364. package/dist/store/postgres/store.js +4 -0
  365. package/dist/store/schema.d.ts +60 -11
  366. package/dist/store/schema.js +147 -17
  367. package/dist/store/seal.d.ts +4 -1
  368. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  369. package/dist/store/sqlite/learning-rows.js +559 -0
  370. package/dist/store/sqlite/run-launch.d.ts +3 -10
  371. package/dist/store/sqlite/run-launch.js +12 -23
  372. package/dist/store/sqlite/run-patch.d.ts +17 -10
  373. package/dist/store/sqlite/run-patch.js +50 -13
  374. package/dist/store/sqlite/store.d.ts +9 -0
  375. package/dist/store/sqlite/store.js +194 -46
  376. package/dist/store/store-schema.js +3 -4
  377. package/dist/store/store.d.ts +286 -38
  378. package/dist/store/store.js +27 -11
  379. package/dist/store-reads/analytics.d.ts +2 -1
  380. package/dist/store-reads/analytics.js +7 -5
  381. package/dist/store-reads/journal.d.ts +33 -3
  382. package/dist/store-reads/journal.js +99 -4
  383. package/dist/store-reads/learning.d.ts +50 -45
  384. package/dist/store-reads/learning.js +153 -116
  385. package/dist/store-reads/loop.js +1 -1
  386. package/dist/store-reads/stats.d.ts +2 -2
  387. package/dist/store-reads/stats.js +13 -7
  388. package/dist/store-view.d.ts +24 -2
  389. package/dist/store-view.js +49 -17
  390. package/dist/suggestions.d.ts +1 -1
  391. package/dist/suggestions.js +29 -13
  392. package/dist/template-eval.d.ts +72 -9
  393. package/dist/template-eval.js +358 -64
  394. package/dist/templates.d.ts +10 -2
  395. package/dist/templates.js +31 -4
  396. package/dist/timeline/labels.d.ts +1 -1
  397. package/dist/timeline/labels.js +4 -3
  398. package/dist/timeline/timeline.d.ts +23 -11
  399. package/dist/timeline/timeline.js +115 -31
  400. package/dist/timeline/web-calls.d.ts +8 -6
  401. package/dist/timeline/web-calls.js +10 -6
  402. package/dist/tool-gate.d.ts +13 -1
  403. package/dist/tool-gate.js +43 -3
  404. package/dist/tool-keys-store.js +2 -4
  405. package/dist/tool-keys.d.ts +11 -0
  406. package/dist/tool-keys.js +16 -0
  407. package/dist/tool-plane.d.ts +54 -13
  408. package/dist/tool-plane.js +103 -32
  409. package/dist/tools.d.ts +5 -1
  410. package/dist/tools.js +7 -7
  411. package/dist/trigger-email.js +12 -6
  412. package/dist/triggers.d.ts +15 -34
  413. package/dist/triggers.js +119 -126
  414. package/dist/validate.d.ts +8 -1
  415. package/dist/validate.js +163 -23
  416. package/dist/web-fake.d.ts +2 -1
  417. package/dist/web-fake.js +8 -6
  418. package/dist/web-fetch.d.ts +8 -6
  419. package/dist/web-fetch.js +13 -11
  420. package/dist/web-holds.d.ts +34 -0
  421. package/dist/web-holds.js +89 -0
  422. package/dist/web-run.d.ts +32 -5
  423. package/dist/web-run.js +76 -28
  424. package/dist/web-save.js +23 -12
  425. package/dist/web-search.js +14 -25
  426. package/dist/wires.d.ts +4 -3
  427. package/dist/wires.js +5 -4
  428. package/dist/workspace/archil-claim.d.ts +12 -5
  429. package/dist/workspace/archil-claim.js +45 -5
  430. package/dist/workspace/archil-exec.js +1 -1
  431. package/dist/workspace/archil.d.ts +1 -1
  432. package/dist/workspace/archil.js +1 -1
  433. package/dist/workspace/attach.js +52 -19
  434. package/dist/workspace/attached-computers.d.ts +6 -2
  435. package/dist/workspace/attached-computers.js +5 -4
  436. package/dist/workspace/computer-deps.d.ts +23 -6
  437. package/dist/workspace/computer-deps.js +38 -18
  438. package/dist/workspace/computer-for-claim.d.ts +21 -4
  439. package/dist/workspace/computer-for-claim.js +160 -54
  440. package/dist/workspace/computer-intervals.d.ts +2 -0
  441. package/dist/workspace/computer-intervals.js +1 -1
  442. package/dist/workspace/computer-janitor.d.ts +48 -14
  443. package/dist/workspace/computer-janitor.js +153 -44
  444. package/dist/workspace/computer-kept.d.ts +158 -32
  445. package/dist/workspace/computer-kept.js +288 -63
  446. package/dist/workspace/computer-providers.d.ts +19 -4
  447. package/dist/workspace/computer-providers.js +40 -6
  448. package/dist/workspace/index.d.ts +2 -3
  449. package/dist/workspace/index.js +2 -3
  450. package/dist/workspace/local.js +41 -1
  451. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  452. package/dist/workspace/mount-revoke-left.js +72 -0
  453. package/dist/workspace/paired-route.js +4 -5
  454. package/dist/workspace/paths.d.ts +0 -4
  455. package/dist/workspace/paths.js +0 -6
  456. package/dist/workspace/resolve-computer.d.ts +5 -2
  457. package/dist/workspace/resolve-computer.js +9 -3
  458. package/dist/workspace/run-end-computers.d.ts +11 -5
  459. package/dist/workspace/run-end-computers.js +153 -28
  460. package/dist/workspace/run-tools.d.ts +22 -3
  461. package/dist/workspace/run-tools.js +17 -5
  462. package/dist/workspace/run-workspace.d.ts +14 -1
  463. package/dist/workspace/run-workspace.js +34 -1
  464. package/dist/workspace/workspace.d.ts +7 -1
  465. package/dist/workspace/workspace.js +1 -1
  466. package/package.json +13 -14
  467. package/skills/agentrun-serve/SKILL.md +5 -2
  468. package/templates/README.md +22 -6
  469. package/templates/TOOLS.md +46 -0
  470. package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
  471. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  472. package/dist/console/assets/index-DPh29cyz.js +0 -747
  473. package/dist/workspace/learning-workspace.d.ts +0 -24
  474. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
@@ -2,7 +2,8 @@
2
2
  // it (PEEK only: every message stays as unread as it was), email_draft keeps a message in its Drafts folder, email_send
3
3
  // sends one, marked as this server's (X-AgentRun-Sent, its value the run's id) so the email trigger never starts a run on
4
4
  // it, and files a copy in Sent unless the provider files its own (Gmail); email_file files a message under a Gmail label
5
- // or in a folder, and never deletes one (the trash and junk folders are refused). Host tools on every harness, bound beside
5
+ // or in a folder, and never deletes one (the trash and junk folders are refused) nor files one into Sent or Drafts. Host
6
+ // tools on every harness, bound beside
6
7
  // web_fetch (tool-list.ts `host`); the password is read in the runner, from the one store under its seal key, and never
7
8
  // in an answer. Each answer is held under the host's result bound (answer.ts).
8
9
  // Thread scope: a run an email trigger started reads only that email's thread (the message, and every message whose
@@ -24,7 +25,7 @@ const opens = (host) => host.store !== undefined && (host.sealKey !== undefined
24
25
  const accountOf = async (host) => (host.sealKey ? openAccount(host.store, host.sealKey) : held()?.emailAccount());
25
26
  import { EMAIL_ANSWER_MAX_CHARS, emailError, emailText } from "./answer.js";
26
27
  import { archiveDescription, EMAIL_ADDRESS, EMAIL_DESCRIPTIONS, EMAIL_DRAFT, EMAIL_FILE, EMAIL_READ, EMAIL_SEARCH, EMAIL_SEND, fileDescription, LIMIT_DEFAULT, LIMIT_MAX, OUTSIDE_THREAD, SEND_CAP } from "./names.js";
27
- import { composed, foundOf, inThread, involves, MailError, READ_BYTES, readOf, SEARCH_BYTES, SENT_HEADER, smtpSend, TOOL_SOCKET_TIMEOUT_MS, withImap } from "./mail.js";
28
+ import { addressKey, composed, foundOf, inThread, involves, MailError, neverSentTo, READ_BYTES, readOf, SEARCH_BYTES, SENT_HEADER, smtpSend, TOOL_SOCKET_TIMEOUT_MS, withImap } from "./mail.js";
28
29
  export { EMAIL_DRAFT, EMAIL_FILE, EMAIL_READ, EMAIL_SCOPES, EMAIL_SEARCH, EMAIL_SEND, OUTSIDE_THREAD, SCOPED_TOOLS, SEND_CAP, sendSummary } from "./names.js";
29
30
  /** The most ids a thread is read by: its message and the 49 nearest it. */
30
31
  const THREAD_IDS = 50;
@@ -72,11 +73,11 @@ const messageId = (value) => {
72
73
  * sender, its Message-ID and where the trigger found it. Null when any of them is missing or does not read, so the run
73
74
  * reads nothing (fail closed). */
74
75
  export function threadRootOf(attrs) {
75
- const { from, message_id, mailbox, uidvalidity, uid } = attrs ?? {};
76
+ const { from, message_id, mailbox, uidvalidity, uid, dmarc } = attrs ?? {};
76
77
  const named = (value) => typeof value === "string" && value.trim() !== "";
77
78
  if (!named(from) || !named(message_id) || !named(mailbox) || !named(uidvalidity) || !named(uid) || !/^[1-9]\d{0,15}$/.test(uid))
78
79
  return null;
79
- return { from: from.trim().toLowerCase(), message_id, mailbox, uidvalidity, uid: Number(uid) };
80
+ return { from: addressKey(from), message_id, mailbox, uidvalidity, uid: Number(uid), dmarc: dmarc === "pass" };
80
81
  }
81
82
  /** The scope of `tool`'s calls in the run `host` binds for: the agent's `scope: "mailbox"` reads the whole account; a run
82
83
  * an email trigger started reads its thread; any other run, the whole account. */
@@ -112,7 +113,7 @@ async function located(session, root) {
112
113
  return head ? { ids: new Set(threadIds(root.message_id, head)), sender: root.from } : nothing();
113
114
  }
114
115
  /** Whether `head` is `root`'s message: its Message-ID, from its sender. */
115
- const isRoot = (head, root) => head.message_id === root.message_id && head.from.trim().toLowerCase() === root.from;
116
+ const isRoot = (head, root) => head.message_id === root.message_id && addressKey(head.from) === root.from;
116
117
  /** `root`'s message where the trigger found it, when it is still there. */
117
118
  async function recorded(session, root) {
118
119
  if (root.mailbox.toUpperCase() !== "INBOX" && !(await session.mailboxes()).some((box) => box.path === root.mailbox))
@@ -182,13 +183,13 @@ class Mail {
182
183
  const inside = new Set(await session.uids(session.threadQuery([...thread])));
183
184
  return found.filter((uid) => inside.has(uid));
184
185
  }
185
- /** The thread's people, lowercased: the account's own address and every From, To and Cc of the thread's messages (those
186
+ /** The thread's people, as compared (addressKey): the account's own address and every From, To and Cc of the thread's messages (those
186
187
  * `allows` takes), across the account's mailboxes; undefined when the run reads the whole account. */
187
188
  async people(session) {
188
189
  const ids = await this.thread(session);
189
190
  if (!ids)
190
191
  return undefined;
191
- const people = new Set([this.account.address.trim().toLowerCase()]);
192
+ const people = new Set([addressKey(this.account.address)]);
192
193
  if (!ids.size)
193
194
  return people;
194
195
  for (const path of await session.searchable()) {
@@ -196,7 +197,7 @@ class Mail {
196
197
  for (const head of await session.heads(path, await session.uids(session.threadQuery([...ids])))) {
197
198
  if (inThread(head, ids) && (await this.allows(session, head)))
198
199
  for (const one of [head.from, ...head.to, ...head.cc])
199
- people.add(one.trim().toLowerCase());
200
+ people.add(addressKey(one));
200
201
  }
201
202
  }
202
203
  return people;
@@ -383,8 +384,11 @@ async function send(mail, args, runId) {
383
384
  const listed = (names) => (names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`);
384
385
  /** Why an email_send its setting allows asks a person anyway (tools.ts ToolEntry.asks), or nothing: the run has sent
385
386
  * SEND_CAP emails or more (its record's count, across pauses); or, on a run that reads only its email's thread (email_read's
386
- * scope), it sends to someone outside the thread's people (Mail.people), each named. Both, when both. A thread that can't
387
- * be read asks too, saying so. A call whose arguments don't read asks nothing: the tool refuses it in its own words. */
387
+ * scope), it sends to someone outside the thread's people (Mail.people), each named; or, on any run a trigger started
388
+ * (that thread run too), it sends to an address the account has never sent to (newWords), each named. Each that holds,
389
+ * joined. A thread
390
+ * or a Sent folder that can't be read asks too, saying so. A call whose arguments don't read asks nothing: the tool
391
+ * refuses it in its own words. */
388
392
  export async function sendAsks(args, ctx) {
389
393
  const why = [];
390
394
  const sent = await ctx.ran(EMAIL_SEND);
@@ -393,8 +397,59 @@ export async function sendAsks(args, ctx) {
393
397
  const outside = await outsideWords(ctx.host, args);
394
398
  if (outside)
395
399
  why.push(outside);
400
+ const fresh = await newWords(ctx, args);
401
+ if (fresh)
402
+ why.push(fresh);
396
403
  return why.length ? why.join("; ") : undefined;
397
404
  }
405
+ /** The recipients of a send's arguments (to and cc), as compared (addressKey), once each; none when they don't read. */
406
+ function recipientsOf(args) {
407
+ const list = (value) => (typeof value === "string" ? [value] : Array.isArray(value) ? value.filter((one) => typeof one === "string") : []);
408
+ return [...new Set([...list(args.to), ...list(args.cc)].map(addressKey))];
409
+ }
410
+ /** On a run a trigger started (host.startedBy: a schedule, a webhook, an email, any source), the recipients of the send
411
+ * `args` this account has never sent to, in words: none of its Sent mail, from the account and no draft, is to them
412
+ * (mail.ts neverSentTo, To, Cc or Bcc, the exact address). The account's own address is never new, nor one this run
413
+ * already sent to (its earlier sends, unasked or approved, from its record: a copy in Sent or not), nor, on a run that
414
+ * reads only its email's thread, the thread's starter (its root's From, as the trigger read it: ThreadRoot.from), whom
415
+ * an auto-responder answers, but only when the receiving server vouched for that From (ThreadRoot.dmarc: its own
416
+ * Authentication-Results said dmarc=pass for the From's domain); a From it didn't vouch for may be forged, and asks
417
+ * as anyone's. Everyone else that message names, its Cc's strangers among them, is checked as on any other run. A Sent
418
+ * folder that can't be read asks, saying so (fail closed). Nothing on a run no trigger started. */
419
+ async function newWords(ctx, args) {
420
+ const host = ctx.host;
421
+ if (!host.startedBy || !opens(host))
422
+ return undefined;
423
+ const scope = await scopeOf(host, EMAIL_READ);
424
+ const starter = scope.kind === "thread" && scope.root?.dmarc ? [scope.root.from] : [];
425
+ let recipients;
426
+ try {
427
+ const letter = letterOf(args);
428
+ recipients = [...new Set([...letter.to, ...letter.cc].map(addressKey))];
429
+ }
430
+ catch {
431
+ return undefined;
432
+ }
433
+ try {
434
+ const account = await accountOf(host);
435
+ // No account when the send is checked: the tool opens the account again when it runs, so one saved in between would
436
+ // let the send out unchecked. It asks, saying so (fail closed).
437
+ if (!account)
438
+ throw new MailError("missing", NO_ACCOUNT);
439
+ // One a template eval's run may not open: the send itself is refused in its own words.
440
+ if (!fakeHeld(host, account))
441
+ return undefined;
442
+ const known = new Set([addressKey(account.address), ...starter, ...(await ctx.made(EMAIL_SEND)).flatMap((one) => (isObject(one) ? recipientsOf(one) : []))]);
443
+ const unknown = recipients.filter((one) => !known.has(one));
444
+ if (!unknown.length)
445
+ return undefined;
446
+ const never = await withImap(account, (session) => neverSentTo(session, unknown, account.address), { socketTimeoutMs: TOOL_SOCKET_TIMEOUT_MS });
447
+ return never.length ? `${listed(never)}: this account has never sent to them` : undefined;
448
+ }
449
+ catch (error) {
450
+ return `its recipients couldn't be checked against this account's sent mail (${error?.message ?? String(error)})`;
451
+ }
452
+ }
398
453
  /** The recipients of the send `args` outside the run's thread, in words; nothing on a run that reads the whole account. */
399
454
  async function outsideWords(host, args) {
400
455
  const scope = await scopeOf(host, EMAIL_READ);
@@ -403,7 +458,7 @@ async function outsideWords(host, args) {
403
458
  let recipients;
404
459
  try {
405
460
  const letter = letterOf(args);
406
- recipients = [...new Set([...letter.to, ...letter.cc].map((one) => one.toLowerCase()))];
461
+ recipients = [...new Set([...letter.to, ...letter.cc].map(addressKey))];
407
462
  }
408
463
  catch {
409
464
  return undefined;
@@ -432,13 +487,20 @@ function fakeHeld(host, account) {
432
487
  }
433
488
  /** The names email_file refuses whatever the account flags: the trash and junk folders by their usual names. */
434
489
  const BINS = new Set(["trash", "junk", "spam", "[gmail]/trash", "[gmail]/spam", "\\trash", "\\junk"]);
490
+ /** The names email_file refuses as Sent or Drafts whatever the account flags: those ImapSession.resolve takes for them,
491
+ * Gmail's folders and its \Sent and \Draft labels. Sent holds what the account sent (the never-written-to check reads
492
+ * it), so only email_send and email_draft put mail there. */
493
+ const KEPT = new Set(["sent", "drafts", "\\sent", "\\drafts", "\\draft", "[gmail]/sent mail", "[gmail]/drafts"]);
435
494
  /** A folders server's answer to an explicit archive: false, a filing that would keep the message in the inbox. */
436
495
  const FOLDERS_REFUSAL = "this server has folders: filing moves the message out of the inbox; pass archive: true to move it";
437
496
  /** Gmail's label for a message in the inbox: taken off, the message is archived. */
438
497
  const INBOX_LABEL = "\\Inbox";
439
498
  /** The message `id` filed under `to`: a Gmail label (archive: true takes its \Inbox label off too), else a move to the
440
499
  * folder `to`, created if missing, with no archive or archive: true. Never a delete: the trash and junk folders are
441
- * refused before anything is touched; and an explicit archive: false never takes mail out of the inbox. */
500
+ * refused before anything is touched; and an explicit archive: false never takes mail out of the inbox. Never into Sent
501
+ * or Drafts either (KEPT, or the folder flagged \Sent or \Drafts; and once made, only into a mailbox the server lists
502
+ * by exactly that name: listedExactly): a message filed there would read as the account's own sent mail to the
503
+ * never-written-to check. */
442
504
  async function file(mail, args) {
443
505
  const id = messageId(text(args, "message_id", 998, true));
444
506
  const to = text(args, "to", 300, true).trim();
@@ -447,18 +509,25 @@ async function file(mail, args) {
447
509
  if (args.archive !== undefined && typeof args.archive !== "boolean")
448
510
  throw new BadArgs("archive is true or false.");
449
511
  const refused = () => new BadArgs(`${EMAIL_FILE} files mail, it never deletes it: ${to} is the trash or junk folder.`);
512
+ const kept = () => new BadArgs(`${EMAIL_FILE} never files into Sent or Drafts: ${to} is the account's sent or drafts mail, which only ${EMAIL_SEND} and ${EMAIL_DRAFT} write.`);
450
513
  if (BINS.has(to.toLowerCase()))
451
514
  throw refused();
515
+ if (KEPT.has(to.toLowerCase()))
516
+ throw kept();
452
517
  return withMail(mail, async (session) => {
453
- const bin = (await session.mailboxes()).find((box) => box.path === to && (box.specialUse === "\\Trash" || box.specialUse === "\\Junk"));
518
+ const boxes = await session.mailboxes();
519
+ const bin = boxes.find((box) => box.path === to && (box.specialUse === "\\Trash" || box.specialUse === "\\Junk"));
454
520
  if (bin)
455
521
  throw refused();
522
+ if (boxes.some((box) => box.path.toLowerCase() === to.toLowerCase() && (box.specialUse === "\\Sent" || box.specialUse === "\\Drafts")))
523
+ throw kept();
456
524
  const found = await findById(session, id, mail);
457
525
  if (!found)
458
526
  throw new MailError("missing", mail.scope.kind === "thread" ? `${id} is ${OUTSIDE_THREAD}, or not in this account: this run files only the thread of the email that started it.` : `No message ${id} in this account.`);
459
527
  const done = (archived, note) => ({ filed: true, message_id: id, to, archived, subject: found.subject, ...(note ? { note } : {}) });
460
528
  if (session.can("X-GM-EXT-1")) {
461
529
  await session.ensure(to);
530
+ await listedExactly(session, to, kept);
462
531
  await session.select(found.mailbox);
463
532
  await session.label(found.uid, [to]);
464
533
  const leaves = args.archive === true && found.mailbox.toUpperCase() === "INBOX";
@@ -471,12 +540,25 @@ async function file(mail, args) {
471
540
  if (args.archive === false)
472
541
  throw new BadArgs(FOLDERS_REFUSAL);
473
542
  await session.ensure(to);
543
+ await listedExactly(session, to, kept);
474
544
  await session.select(found.mailbox);
475
545
  await session.move(found.uid, to);
476
546
  // The answer says the move: the model reads the answer, not the timeline.
477
547
  return done(true, `moved out of the inbox to ${to}`);
478
548
  });
479
549
  }
550
+ /** Once `to` is made (ImapSession.ensure), that the server lists a mailbox of exactly that name (INBOX in any case), and
551
+ * that it is neither Sent nor Drafts, by its flag or as ImapSession.resolve reads them: a server may take a name as
552
+ * another's (CREATE may drop a trailing hierarchy delimiter, so `Sent/` is Sent; an alias), and the names alone
553
+ * can't say so. Otherwise nothing is filed: `kept()`'s refusal for Sent or Drafts, else one that says the name. */
554
+ async function listedExactly(session, to, kept) {
555
+ const box = (await session.mailboxes()).find((one) => one.path === to || (to.toUpperCase() === "INBOX" && one.path.toUpperCase() === "INBOX"));
556
+ if (!box)
557
+ throw new MailError("failed", `the mail server lists no mailbox named exactly ${JSON.stringify(to)} once it is made, so nothing was filed: give the folder's name as the server lists it.`);
558
+ const special = await Promise.all(["Sent", "Drafts"].map((name) => session.resolve(name).catch(() => undefined)));
559
+ if (box.specialUse === "\\Sent" || box.specialUse === "\\Drafts" || special.includes(box.path))
560
+ throw kept();
561
+ }
480
562
  const STRING = { type: "string" };
481
563
  const ADDRESSES = { type: "array", items: STRING, description: "Email addresses, such as [\"ana@example.com\"]." };
482
564
  /** The five tools, by name: their words for the model (names.ts EMAIL_DESCRIPTIONS, the catalog's too), their arguments,
@@ -2,21 +2,31 @@
2
2
  export declare const API_ONLY_ENV = "AGENTRUN_API_ONLY";
3
3
  /** The run-keys setting (run-keys.ts). */
4
4
  export declare const RUN_KEYS_ENV = "AGENTRUN_RUN_KEYS";
5
+ /** Jev off for the web tools (web-run.ts jevWebOf): web_search's results go unranked, whatever key the server holds. */
6
+ export declare const WEB_JEV_OFF_ENV = "AGENTRUN_WEB_JEV_OFF";
5
7
  /** What each setting means on, and off where off needs saying: the words a refused value answers. */
6
8
  declare const MEANS: {
7
9
  readonly AGENTRUN_API_ONLY: readonly ["serve the run API only", "the whole server"];
8
10
  readonly AGENTRUN_RUN_KEYS: readonly ["each run brings the tool keys this server does not hold"];
11
+ readonly AGENTRUN_WEB_JEV_OFF: readonly ["the web tools run without Jev", "Jev ranks web_search's results where the server holds a TypeSafe key"];
9
12
  };
10
13
  /** Whether `env` turns setting `name` on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused
11
14
  * in words that say what each means (a TypeError), so a typo never leaves the console open on a server meant to be
12
15
  * API-only. */
13
16
  export declare function switchFrom(name: keyof typeof MEANS, env?: NodeJS.ProcessEnv): boolean;
17
+ /** Whether Jev is off for the web tools under `env`: AGENTRUN_WEB_JEV_OFF on. The CLI refuses any other value at start;
18
+ * one met later (a runner's claim) reads as off, so a typo never turns Jev on. */
19
+ export declare function webJevOff(env: NodeJS.ProcessEnv): boolean;
14
20
  /** The MCP origins an API-only server's token may save a per_run MCP server at: the serve README's API-only section. */
15
21
  export declare const API_ONLY_MCP_ORIGINS_ENV = "AGENTRUN_API_ONLY_MCP_ORIGINS";
22
+ /** A URL hostname on this machine: localhost, ::1 (bracketed, as URL writes it) or 127.0.0.0/8. Defined here, since this
23
+ * module imports nothing; mcp-oauth.ts LOOPBACK is this one. */
24
+ export declare const LOOPBACK_HOST: RegExp;
16
25
  /** The origins `value` (API_ONLY_MCP_ORIGINS_ENV) names, each once, in its order: none when unset or blank. An entry
17
26
  * that is not an http or https origin alone (a path, query, fragment, user or password, or no URL at all) is refused
18
27
  * (a TypeError naming the entry by its place, never its text, which could hold a password), and so is a wildcard
19
- * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing. Empty entries are
20
- * skipped. */
28
+ * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing, and so is plain http
29
+ * to any host but a loopback one (LOOPBACK_HOST), whose traffic would cross the network in the clear. Empty entries
30
+ * are skipped. */
21
31
  export declare function apiOnlyMcpOriginsFrom(value: string | undefined): string[];
22
32
  export {};
@@ -1,13 +1,16 @@
1
- // The server's two on/off settings, and the API-only profile's MCP origins, which the CLI reads before the rest of the
1
+ // The server's on/off settings, and the API-only profile's MCP origins, which the CLI reads before the rest of the
2
2
  // server loads (cli.ts): this module imports nothing.
3
3
  /** The API-only profile (api-only.ts). */
4
4
  export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
5
5
  /** The run-keys setting (run-keys.ts). */
6
6
  export const RUN_KEYS_ENV = "AGENTRUN_RUN_KEYS";
7
+ /** Jev off for the web tools (web-run.ts jevWebOf): web_search's results go unranked, whatever key the server holds. */
8
+ export const WEB_JEV_OFF_ENV = "AGENTRUN_WEB_JEV_OFF";
7
9
  /** What each setting means on, and off where off needs saying: the words a refused value answers. */
8
10
  const MEANS = {
9
11
  [API_ONLY_ENV]: ["serve the run API only", "the whole server"],
10
12
  [RUN_KEYS_ENV]: ["each run brings the tool keys this server does not hold"],
13
+ [WEB_JEV_OFF_ENV]: ["the web tools run without Jev", "Jev ranks web_search's results where the server holds a TypeSafe key"],
11
14
  };
12
15
  /** Whether `env` turns setting `name` on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused
13
16
  * in words that say what each means (a TypeError), so a typo never leaves the console open on a server meant to be
@@ -21,13 +24,27 @@ export function switchFrom(name, env = process.env) {
21
24
  const [on, off] = MEANS[name];
22
25
  throw new TypeError(`${name} is 1 (${on}) or 0${off === undefined ? "" : ` (${off})`}, not ${JSON.stringify(env[name])}`);
23
26
  }
27
+ /** Whether Jev is off for the web tools under `env`: AGENTRUN_WEB_JEV_OFF on. The CLI refuses any other value at start;
28
+ * one met later (a runner's claim) reads as off, so a typo never turns Jev on. */
29
+ export function webJevOff(env) {
30
+ try {
31
+ return switchFrom(WEB_JEV_OFF_ENV, env);
32
+ }
33
+ catch {
34
+ return true;
35
+ }
36
+ }
24
37
  /** The MCP origins an API-only server's token may save a per_run MCP server at: the serve README's API-only section. */
25
38
  export const API_ONLY_MCP_ORIGINS_ENV = "AGENTRUN_API_ONLY_MCP_ORIGINS";
39
+ /** A URL hostname on this machine: localhost, ::1 (bracketed, as URL writes it) or 127.0.0.0/8. Defined here, since this
40
+ * module imports nothing; mcp-oauth.ts LOOPBACK is this one. */
41
+ export const LOOPBACK_HOST = /^(?:localhost|\[::1\]|127(?:[.]\d{1,3}){3})$/; // key-gate: loopback-rule the one loopback rule, for the API-only MCP origins and MCP sign-in
26
42
  /** The origins `value` (API_ONLY_MCP_ORIGINS_ENV) names, each once, in its order: none when unset or blank. An entry
27
43
  * that is not an http or https origin alone (a path, query, fragment, user or password, or no URL at all) is refused
28
44
  * (a TypeError naming the entry by its place, never its text, which could hold a password), and so is a wildcard
29
- * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing. Empty entries are
30
- * skipped. */
45
+ * (`https://*.example.com`), which would otherwise be taken as a literal host and match nothing, and so is plain http
46
+ * to any host but a loopback one (LOOPBACK_HOST), whose traffic would cross the network in the clear. Empty entries
47
+ * are skipped. */
31
48
  export function apiOnlyMcpOriginsFrom(value) {
32
49
  const origins = [];
33
50
  (value ?? "").split(",").map((entry) => entry.trim()).forEach((entry, at) => {
@@ -45,6 +62,9 @@ export function apiOnlyMcpOriginsFrom(value) {
45
62
  if (!url || (url.protocol !== "http:" && url.protocol !== "https:") || url.href !== `${url.origin}/`) {
46
63
  throw new TypeError(`${API_ONLY_MCP_ORIGINS_ENV} is a comma-separated list of MCP origins (http or https, scheme://host[:port], no path): entry ${at + 1} is not one`);
47
64
  }
65
+ if (url.protocol === "http:" && !LOOPBACK_HOST.test(url.hostname)) {
66
+ throw new TypeError(`${API_ONLY_MCP_ORIGINS_ENV} takes plain http only for this machine (127.0.0.0/8, ::1, localhost): entry ${at + 1} is plain http to a host off this machine; list it as https`);
67
+ }
48
68
  if (!origins.includes(url.origin))
49
69
  origins.push(url.origin);
50
70
  });
package/dist/errors.d.ts CHANGED
@@ -64,6 +64,7 @@ export declare const ERROR_STATUS: {
64
64
  readonly run_not_final: 409;
65
65
  readonly run_learning: 409;
66
66
  readonly not_exportable: 409;
67
+ readonly export_too_large: 413;
67
68
  readonly purged: 410;
68
69
  readonly model_key_required: 422;
69
70
  readonly runner_refused: 503;
package/dist/errors.js CHANGED
@@ -96,6 +96,8 @@ export const ERROR_STATUS = {
96
96
  // GET /agents/{id}/package (agent-package.ts) of an agent whose source is elsewhere (a native, CLI learning, SDK or
97
97
  // another system's agent), a workflow, or one with no revision: there is no package of it to write.
98
98
  not_exportable: 409,
99
+ // GET /runs/{id}/export (run-export.ts) of a run whose bundle is over its 8 MiB cap: it is never cut short.
100
+ export_too_large: 413,
99
101
  // A run or an agent that was purged (DELETE /runs/{id}, /agents/{id}): every route of it reads its tombstone in the
100
102
  // error's details, and its DELETE answers 204 again.
101
103
  purged: 410,
@@ -0,0 +1,68 @@
1
+ import type { RunLaunch } from "./run-launch.js";
2
+ import type { JournalRecords } from "./runner/journal-reader.js";
3
+ import type { Store } from "./store/store.js";
4
+ export type FactoryGithub = {
5
+ repository: string;
6
+ issue: number | null;
7
+ pull_request: number | null;
8
+ head_sha: string | null;
9
+ provenance: "launch" | "github_trigger";
10
+ };
11
+ export type FactoryChild = {
12
+ id: string;
13
+ conversation_id: number;
14
+ parent_call_id: string;
15
+ status: "active" | "completed";
16
+ label: string | null;
17
+ };
18
+ export type FactoryActivity = {
19
+ lifecycle_version: string;
20
+ source: "managed" | "native" | "sdk" | "cli";
21
+ runtime: string;
22
+ control: "managed" | "observed";
23
+ controls: {
24
+ stop: boolean;
25
+ cancel: boolean;
26
+ approve: boolean;
27
+ };
28
+ observation: {
29
+ basis: "runner" | "connector" | "unreported";
30
+ status: "current" | "offline" | "revoked" | "unreported";
31
+ last_seen_at: string | null;
32
+ };
33
+ last_activity_at: string | null;
34
+ github: FactoryGithub | null;
35
+ children: FactoryChild[];
36
+ };
37
+ /** Only an explicit launch binding or what the server saved of the GitHub delivery that fired the run (its firing's
38
+ * attributes, trigger-github.ts: the repository, the number and a pull request's head, read from the signed body)
39
+ * establishes a repository. Owner prose, task titles and arbitrary tool results are never searched for URLs or issue
40
+ * numbers, and no payload tag in the run's input is taken for the event on its place alone. */
41
+ export declare function factoryGithub(launch: RunLaunch | undefined, redact: (text: string) => string): FactoryGithub | null;
42
+ /** Actual journal/model timestamps only. A runner renewing a lease is not progress from an external SDK. */
43
+ export declare function factoryLastActivity(records: JournalRecords): string | null;
44
+ /** Child identity comes from the durable conversation's ownership edge and its actual subagent tool task, whether the
45
+ * model called subagent itself or through tools_call or a script. A conversation another tool's task owns, however
46
+ * its arguments read, is not an independent session. */
47
+ export declare function factoryChildren(store: Store, runId: string, records: JournalRecords, redact: (text: string) => string): Promise<FactoryChild[]>;
48
+ /** What runs a run, from its launch: its source, the runtime it recorded (else `harness`, the run's own), and whether
49
+ * AgentRun controls its execution. An SDK run and a connected CLI session are run by their own application, which reports
50
+ * them here: AgentRun observes them and refuses to stop or cancel them (runs-over-store.ts refuseSdkStop), so neither is
51
+ * managed and no control of theirs is offered. A native run and every other are run through AgentRun. */
52
+ export declare function factorySource(launch: RunLaunch | undefined, harness: string): Pick<FactoryActivity, "source" | "runtime" | "control">;
53
+ /** Who a run is observed through, from its launch: nothing reports the liveness of an SDK run or a connected CLI session
54
+ * (no runner holds either), a remote native run is seen through its paired connector, and any other through the runner
55
+ * that holds it. It never changes for a run, so a listing keeps it. */
56
+ export type FactoryObserved = {
57
+ readonly basis: "unreported";
58
+ } | {
59
+ readonly basis: "connector";
60
+ readonly connector: string;
61
+ } | {
62
+ readonly basis: "runner";
63
+ };
64
+ export declare const factoryObserved: (launch: RunLaunch | undefined) => FactoryObserved;
65
+ /** A run's observation now: its connector's health, or whether a runner holds it (`live`) and that runner's last tick.
66
+ * Read at each request, never kept: a lease renewed or a connector lost writes nothing to the run. */
67
+ export declare function observationOf(store: Store, observed: FactoryObserved, live: boolean, lastTick: number | undefined, now: () => number): Promise<FactoryActivity["observation"]>;
68
+ export declare const factoryObservation: (store: Store, launch: RunLaunch | undefined, live: boolean, lastTick: number | undefined, now: () => number) => Promise<FactoryActivity["observation"]>;
@@ -0,0 +1,153 @@
1
+ // Factory metadata is an observation of an existing run, never a second lifecycle or a GitHub authorization grant.
2
+ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
3
+ import { RemoteConnectors } from "./native/remote.js";
4
+ import { isObject } from "./validate.js";
5
+ const REPOSITORY = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}\/(?!\.{1,2}$)[A-Za-z0-9._-]{1,100}$/;
6
+ const NUMBER = /^[1-9]\d{0,14}$/;
7
+ const SHA = /^[0-9a-f]{40}$/;
8
+ const unescapeAttr = (value) => value.replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
9
+ /** Whether a payload tag's attribute text (` name="value"` each, then ` untrusted`) is the one the server writes for a
10
+ * GitHub firing with the saved attributes `attrs` (triggers.ts tagAttrs: a value cut to 200 characters, its line breaks
11
+ * made spaces, escaped). Every saved attribute and no other: an example tag, or one a sender wrote, lacks the delivery
12
+ * id GitHub gave this event. */
13
+ function tagOf(text, attrs) {
14
+ const written = Object.entries(attrs).filter(([name]) => /^[a-z][a-z0-9_-]{0,31}$/.test(name) && name !== "source" && name !== "untrusted");
15
+ const read = new Map([...text.matchAll(/ ([a-z][a-z0-9_-]*)="([^"]*)"/g)].map((match) => [match[1], unescapeAttr(match[2])]));
16
+ return read.size === written.length + 1 && read.get("source") === "github" && written.every(([name, value]) => read.get(name) === value.slice(0, 200).replace(/[\r\n\t]/g, " "));
17
+ }
18
+ /** Whether issue `number` of the event is an issue or a pull request: `issue.pull_request` of the signed body, read from
19
+ * the server's own payload block for this firing alone (tagOf). The trigger owner's instructions come first in the input
20
+ * and may hold an example block, so the first block is never taken for the event. No such block, a cut or malformed
21
+ * body, or a body about another number says neither: an issue type is never guessed. */
22
+ function issueKind(input, attrs, number) {
23
+ const content = isObject(input) ? input.content : undefined;
24
+ if (typeof content !== "string")
25
+ return null;
26
+ for (const tag of content.matchAll(/<trigger-payload( [^>]*)>/g)) {
27
+ if (!tagOf(tag[1], attrs))
28
+ continue;
29
+ const from = tag.index + tag[0].length;
30
+ const end = content.indexOf("</trigger-payload>", from);
31
+ if (end < 0)
32
+ return null;
33
+ try {
34
+ const body = JSON.parse(content.slice(from, end));
35
+ const issue = isObject(body) && isObject(body.issue) ? body.issue : undefined;
36
+ if (!issue || issue.number !== number)
37
+ return null;
38
+ return isObject(issue.pull_request) ? "pull_request" : "issue";
39
+ }
40
+ catch {
41
+ return null; /* A truncated event still has its trusted repository. */
42
+ }
43
+ }
44
+ return null;
45
+ }
46
+ /** Only an explicit launch binding or what the server saved of the GitHub delivery that fired the run (its firing's
47
+ * attributes, trigger-github.ts: the repository, the number and a pull request's head, read from the signed body)
48
+ * establishes a repository. Owner prose, task titles and arbitrary tool results are never searched for URLs or issue
49
+ * numbers, and no payload tag in the run's input is taken for the event on its place alone. */
50
+ export function factoryGithub(launch, redact) {
51
+ if (!launch)
52
+ return null;
53
+ const binding = () => {
54
+ if (typeof launch.repo !== "string")
55
+ return null;
56
+ const repository = redact(launch.repo);
57
+ return REPOSITORY.test(repository) && repository === launch.repo ? { repository, issue: null, pull_request: null, head_sha: null, provenance: "launch" } : null;
58
+ };
59
+ if (!launch.trigger || launch.inputOrigin?.kind !== "trigger" || launch.inputOrigin.source !== "github" || launch.inputOrigin.trigger_id !== launch.trigger.id || launch.inputOrigin.owner)
60
+ return binding();
61
+ const attrs = launch.trigger.attrs ?? {};
62
+ const repository = attrs.repo;
63
+ if (repository === undefined || !REPOSITORY.test(repository) || redact(repository) !== repository)
64
+ return binding();
65
+ // Preserve the explicit binding if two independently recorded sources disagree; never attach another repo's PR.
66
+ if (launch.repo !== undefined && launch.repo.toLowerCase() !== repository.toLowerCase())
67
+ return binding();
68
+ const number = NUMBER.test(attrs.number ?? "") ? Number(attrs.number) : null;
69
+ const head = SHA.test(attrs.head_sha ?? "") ? attrs.head_sha : null;
70
+ // A head is a pull request event's own (trigger-signatures.ts attrsOf). A number with no head is an issue's, or an
71
+ // issue comment's, which may be on a pull request: only its signed body distinguishes them.
72
+ const kind = number === null ? null : head !== null ? "pull_request" : issueKind(launch.input, attrs, number);
73
+ return { repository, issue: kind === "issue" ? number : null, pull_request: kind === "pull_request" ? number : null, head_sha: kind === "pull_request" && head !== null && redact(head) === head ? head : null, provenance: "github_trigger" };
74
+ }
75
+ /** Actual journal/model timestamps only. A runner renewing a lease is not progress from an external SDK. */
76
+ export function factoryLastActivity(records) {
77
+ let latest = 0;
78
+ const take = (value) => { if (typeof value === "number" && Number.isFinite(value) && value > latest && value <= 8.64e15)
79
+ latest = value; };
80
+ for (const entry of records.entries) {
81
+ if (isObject(entry.data))
82
+ take(entry.data.at);
83
+ for (const message of entry.model ?? [])
84
+ if (isObject(message))
85
+ take(message.timestamp);
86
+ }
87
+ return latest ? new Date(latest).toISOString() : null;
88
+ }
89
+ /** The call a tool task runs. pi keeps a call the model issued on its assistant entry, which the task names with the
90
+ * call's id; a call a tool made (tools_call's, a script's) has no such entry, and its nested task holds the call itself. */
91
+ function callOf(input, entries) {
92
+ if (input.kind === "nested")
93
+ return isObject(input.call) && typeof input.call.id === "string" ? { id: input.call.id, name: input.call.name, arguments: input.call.arguments } : undefined;
94
+ const { callId, assistant } = input;
95
+ if (typeof callId !== "string" || typeof assistant !== "number")
96
+ return undefined;
97
+ const entry = entries.get(assistant);
98
+ const content = entry?.model?.[0] && "content" in entry.model[0] ? entry.model[0].content : undefined;
99
+ const call = Array.isArray(content) ? content.find((block) => isObject(block) && block.type === "toolCall" && block.id === callId) : undefined;
100
+ return isObject(call) ? { id: callId, name: call.name, arguments: call.arguments } : undefined;
101
+ }
102
+ /** Child identity comes from the durable conversation's ownership edge and its actual subagent tool task, whether the
103
+ * model called subagent itself or through tools_call or a script. A conversation another tool's task owns, however
104
+ * its arguments read, is not an independent session. */
105
+ export async function factoryChildren(store, runId, records, redact) {
106
+ const journal = store.readJournal(runId);
107
+ const conversations = [];
108
+ let cursor;
109
+ do {
110
+ const page = await journal.scanConversations({ order: "ascending" }, 500, cursor, BACKGROUND_CONTEXT);
111
+ conversations.push(...page.items);
112
+ cursor = page.next;
113
+ } while (cursor !== undefined);
114
+ const tasks = new Map(records.tasks.map((task) => [Number(task.id), task]));
115
+ const entries = new Map(records.entries.map((entry) => [Number(entry.id), entry]));
116
+ return conversations.flatMap((conversation) => {
117
+ const task = conversation.owner && tasks.get(Number(conversation.owner.taskId));
118
+ if (!task || task.kind !== "pi.tool" || task.state.status === "terminal" || task.state.status === "completing" || !isObject(task.input))
119
+ return [];
120
+ const call = callOf(task.input, entries);
121
+ if (!call || call.name !== "subagent")
122
+ return [];
123
+ const prompt = isObject(call.arguments) && typeof call.arguments.prompt === "string" ? call.arguments.prompt : null;
124
+ const id = Number(conversation.id);
125
+ if (!Number.isSafeInteger(id) || id < 0 || redact(call.id) !== call.id)
126
+ return [];
127
+ return [{ id: `${runId}:conversation:${id}`, conversation_id: id, parent_call_id: call.id, status: "active", label: prompt === null ? null : redact(prompt).slice(0, 160) }];
128
+ });
129
+ }
130
+ /** What runs a run, from its launch: its source, the runtime it recorded (else `harness`, the run's own), and whether
131
+ * AgentRun controls its execution. An SDK run and a connected CLI session are run by their own application, which reports
132
+ * them here: AgentRun observes them and refuses to stop or cancel them (runs-over-store.ts refuseSdkStop), so neither is
133
+ * managed and no control of theirs is offered. A native run and every other are run through AgentRun. */
134
+ export function factorySource(launch, harness) {
135
+ if (launch?.sdk)
136
+ return { source: "sdk", runtime: launch.sdk.runtime, control: "observed" };
137
+ if (launch?.cli_learning)
138
+ return { source: "cli", runtime: launch.cli_learning.runtime, control: "observed" };
139
+ if (launch?.native)
140
+ return { source: "native", runtime: launch.native.runtime, control: "managed" };
141
+ return { source: "managed", runtime: harness, control: "managed" };
142
+ }
143
+ export const factoryObserved = (launch) => launch?.sdk || launch?.cli_learning ? { basis: "unreported" } : launch?.native?.remote ? { basis: "connector", connector: launch.native.remote.connector_id } : { basis: "runner" };
144
+ /** A run's observation now: its connector's health, or whether a runner holds it (`live`) and that runner's last tick.
145
+ * Read at each request, never kept: a lease renewed or a connector lost writes nothing to the run. */
146
+ export async function observationOf(store, observed, live, lastTick, now) {
147
+ if (observed.basis === "unreported")
148
+ return { basis: "unreported", status: "unreported", last_seen_at: null };
149
+ if (observed.basis === "connector")
150
+ return { basis: "connector", ...await new RemoteConnectors(store, now).health(observed.connector) };
151
+ return { basis: "runner", status: live ? "current" : "unreported", last_seen_at: lastTick === undefined ? null : new Date(lastTick).toISOString() };
152
+ }
153
+ export const factoryObservation = (store, launch, live, lastTick, now) => observationOf(store, factoryObserved(launch), live, lastTick, now);
@@ -0,0 +1,11 @@
1
+ import type { RunRow, Store } from "./store/store.js";
2
+ export type FactoryScope = "active" | "review";
3
+ export declare function factoryRunsPage(store: Pick<Store, "runs">, url: URL, filter: {
4
+ agent?: string;
5
+ revision?: string;
6
+ }, summarize: (rows: readonly RunRow[]) => Promise<Record<string, unknown>[]>, now?: () => number): Promise<{
7
+ runs: Record<string, unknown>[];
8
+ next_cursor: string | null;
9
+ scope: string;
10
+ observed_at: string;
11
+ }>;
@@ -0,0 +1,52 @@
1
+ // Read-only factory pages over the ordinary run store. Scope is selected in SQL before any journal is read; the
2
+ // keyset cursor is bound to its filters so rows ending or new runs starting cannot shift an offset page.
3
+ import { ApiError } from "./errors.js";
4
+ import { ID } from "./validate.js";
5
+ const badCursor = () => new ApiError("bad_request", "cursor is not a factory cursor for these filters");
6
+ function cursorOf(text, filter) {
7
+ if (text === null)
8
+ return undefined;
9
+ if (text.length > 4096 || !/^factory\.[A-Za-z0-9_-]+$/.test(text))
10
+ throw badCursor();
11
+ let value;
12
+ try {
13
+ value = JSON.parse(Buffer.from(text.slice(8), "base64url").toString("utf8"));
14
+ }
15
+ catch {
16
+ throw badCursor();
17
+ }
18
+ if (!value || value.version !== 1 || value.scope !== filter.scope || value.agent !== filter.agent || value.revision !== filter.revision
19
+ || !value.before || !Number.isSafeInteger(value.before.startedAt) || value.before.startedAt < 0
20
+ || typeof value.before.id !== "string" || !ID.test(value.before.id)
21
+ || Object.keys(value).some((key) => !["version", "scope", "agent", "revision", "before"].includes(key))
22
+ || Object.keys(value.before).some((key) => !["startedAt", "id"].includes(key)))
23
+ throw badCursor();
24
+ return value.before;
25
+ }
26
+ export async function factoryRunsPage(store, url, filter, summarize, now = Date.now) {
27
+ const scope = url.searchParams.get("scope");
28
+ if (scope !== "active" && scope !== "review")
29
+ throw new ApiError("bad_request", "scope is active or review");
30
+ if (url.searchParams.has("status") || url.searchParams.has("archived"))
31
+ throw new ApiError("bad_request", "scope cannot be combined with status or archived: active includes archived executions; review lists terminal reviews separately");
32
+ for (const [key, value] of Object.entries(filter))
33
+ if (value !== undefined && !ID.test(value))
34
+ throw new ApiError("bad_request", `${key} is an id`);
35
+ const asked = url.searchParams.get("limit");
36
+ const limit = asked === null ? 50 : Number(asked);
37
+ if (asked !== null && (!/^\d+$/.test(asked) || limit < 1 || limit > 100))
38
+ throw new ApiError("bad_request", "limit is an integer from 1 to 100");
39
+ const bound = { ...filter, scope };
40
+ const before = cursorOf(url.searchParams.get("cursor"), bound);
41
+ const observed_at = new Date(now()).toISOString();
42
+ const rows = await store.runs.list({ scope, agentId: filter.agent, revisionId: filter.revision, before, limit: limit + 1 });
43
+ const page = rows.slice(0, limit);
44
+ // The page's rows go to the caller together, so what it reads beside them is read once for the page, never per run
45
+ // (server.ts runsPage: each run's kept listing). Failures are surfaced, never hidden as empty.
46
+ const runs = await summarize(page);
47
+ const last = page.at(-1);
48
+ const next_cursor = rows.length > limit && last
49
+ ? `factory.${Buffer.from(JSON.stringify({ version: 1, ...bound, before: { startedAt: last.startedAt, id: last.id } })).toString("base64url")}`
50
+ : null;
51
+ return { runs, next_cursor, scope, observed_at };
52
+ }