@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (410) hide show
  1. package/CHANGELOG.md +418 -0
  2. package/README.md +325 -124
  3. package/dist/adapters.d.ts +4 -1
  4. package/dist/adapters.js +4 -2
  5. package/dist/agent-rows.d.ts +0 -2
  6. package/dist/agents-store.d.ts +5 -5
  7. package/dist/agents-store.js +14 -14
  8. package/dist/bash-read-only.js +2 -1
  9. package/dist/cap-short.d.ts +12 -0
  10. package/dist/cap-short.js +60 -0
  11. package/dist/cap.d.ts +3 -10
  12. package/dist/cap.js +2 -5
  13. package/dist/catalog.d.ts +0 -5
  14. package/dist/catalog.js +1 -5
  15. package/dist/chatgpt-plan.d.ts +163 -0
  16. package/dist/chatgpt-plan.js +549 -0
  17. package/dist/cli.js +26 -6
  18. package/dist/composio-preset.d.ts +8 -0
  19. package/dist/composio-preset.js +8 -7
  20. package/dist/composio-triggers.d.ts +113 -0
  21. package/dist/composio-triggers.js +411 -0
  22. package/dist/computer-calls.js +2 -2
  23. package/dist/computer-commands.d.ts +2 -0
  24. package/dist/computer-commands.js +7 -3
  25. package/dist/computer-live.d.ts +7 -2
  26. package/dist/computer-live.js +9 -5
  27. package/dist/computer-routes.d.ts +2 -2
  28. package/dist/computer-routes.js +2 -2
  29. package/dist/computer-setting.d.ts +3 -3
  30. package/dist/computer-setting.js +5 -5
  31. package/dist/computer-view.d.ts +15 -0
  32. package/dist/computer-view.js +16 -2
  33. package/dist/computer-viewer.js +14 -1
  34. package/dist/computers.d.ts +5 -2
  35. package/dist/computers.js +9 -5
  36. package/dist/console/assets/index-BNhZs-jp.css +1 -0
  37. package/dist/console/assets/index-BQv5aOGB.js +700 -0
  38. package/dist/console/index.html +2 -2
  39. package/dist/console-links.js +3 -3
  40. package/dist/decision-cap.d.ts +2 -5
  41. package/dist/decision-cap.js +3 -6
  42. package/dist/decision-rows.js +11 -11
  43. package/dist/email/account.d.ts +84 -0
  44. package/dist/email/account.js +159 -0
  45. package/dist/email/answer.d.ts +10 -0
  46. package/dist/email/answer.js +182 -0
  47. package/dist/email/email-faux.d.ts +95 -0
  48. package/dist/email/email-faux.js +849 -0
  49. package/dist/email/labels.d.ts +1 -0
  50. package/dist/email/labels.js +84 -0
  51. package/dist/email/mail.d.ts +186 -0
  52. package/dist/email/mail.js +380 -0
  53. package/dist/email/names.d.ts +20 -0
  54. package/dist/email/names.js +40 -0
  55. package/dist/email/routes.d.ts +9 -0
  56. package/dist/email/routes.js +50 -0
  57. package/dist/email/tools.d.ts +20 -0
  58. package/dist/email/tools.js +517 -0
  59. package/dist/environment.d.ts +17 -2
  60. package/dist/environment.js +36 -8
  61. package/dist/errors.d.ts +6 -0
  62. package/dist/errors.js +12 -0
  63. package/dist/eval-mailbox.d.ts +103 -0
  64. package/dist/eval-mailbox.js +236 -0
  65. package/dist/graph-view.d.ts +9 -2
  66. package/dist/graph-view.js +6 -2
  67. package/dist/harness-install.d.ts +28 -2
  68. package/dist/harness-install.js +147 -59
  69. package/dist/harness-opencode/adapter.js +2 -26
  70. package/dist/harness-opencode/facts.js +5 -2
  71. package/dist/harness-opencode/host/policy.d.ts +2 -0
  72. package/dist/harness-opencode/host/policy.js +10 -5
  73. package/dist/harness-opencode/index.d.ts +1 -1
  74. package/dist/harness-opencode/index.js +1 -1
  75. package/dist/harness-opencode/versions.d.ts +6 -0
  76. package/dist/harness-opencode/versions.js +6 -0
  77. package/dist/harness-table.js +8 -5
  78. package/dist/harness.d.ts +12 -0
  79. package/dist/harness.js +15 -3
  80. package/dist/hosted-search.d.ts +3 -1
  81. package/dist/hosted-search.js +51 -11
  82. package/dist/import-sources.d.ts +1 -1
  83. package/dist/import-sources.js +3 -3
  84. package/dist/import.d.ts +21 -0
  85. package/dist/import.js +186 -1
  86. package/dist/key-check.d.ts +0 -2
  87. package/dist/key-check.js +3 -4
  88. package/dist/key-refusal.d.ts +8 -2
  89. package/dist/key-refusal.js +16 -13
  90. package/dist/learn/check.d.ts +18 -3
  91. package/dist/learn/check.js +328 -3
  92. package/dist/learn/compile.d.ts +9 -2
  93. package/dist/learn/compile.js +52 -16
  94. package/dist/learn/grade.d.ts +4 -0
  95. package/dist/learn/grade.js +4 -1
  96. package/dist/learn/promote.d.ts +106 -51
  97. package/dist/learn/promote.js +82 -189
  98. package/dist/learn/refit.d.ts +21 -12
  99. package/dist/learn/refit.js +51 -23
  100. package/dist/learn/replay-calls.js +1 -1
  101. package/dist/learn/skills.d.ts +2 -7
  102. package/dist/learn/skills.js +28 -14
  103. package/dist/learned-nodes.d.ts +15 -7
  104. package/dist/learned-nodes.js +29 -5
  105. package/dist/learned-workflow.d.ts +41 -31
  106. package/dist/learned-workflow.js +122 -63
  107. package/dist/learning-batch.js +3 -3
  108. package/dist/learning-cost.d.ts +26 -8
  109. package/dist/learning-cost.js +17 -7
  110. package/dist/learning-routes.d.ts +2 -4
  111. package/dist/learning-routes.js +20 -3
  112. package/dist/learning-words.d.ts +1 -1
  113. package/dist/learning-words.js +4 -1
  114. package/dist/learning.d.ts +5 -5
  115. package/dist/link-check.d.ts +27 -0
  116. package/dist/link-check.js +164 -0
  117. package/dist/local-models.d.ts +33 -2
  118. package/dist/local-models.js +43 -5
  119. package/dist/mcp-pin-first.js +6 -0
  120. package/dist/mcp-secret-writes.js +3 -0
  121. package/dist/mcp-servers-store.d.ts +25 -16
  122. package/dist/mcp-servers-store.js +23 -3
  123. package/dist/model-form.d.ts +11 -0
  124. package/dist/model-form.js +17 -1
  125. package/dist/model.d.ts +26 -6
  126. package/dist/model.js +126 -18
  127. package/dist/monid.d.ts +26 -31
  128. package/dist/monid.js +84 -79
  129. package/dist/native/binding.d.ts +13 -0
  130. package/dist/native/binding.js +57 -0
  131. package/dist/native/cli.d.ts +2 -0
  132. package/dist/native/cli.js +48 -0
  133. package/dist/native/connection.d.ts +8 -0
  134. package/dist/native/connection.js +94 -0
  135. package/dist/native/context.d.ts +6 -0
  136. package/dist/native/context.js +22 -0
  137. package/dist/native/discovery.d.ts +27 -0
  138. package/dist/native/discovery.js +404 -0
  139. package/dist/native/environment.d.ts +4 -0
  140. package/dist/native/environment.js +18 -0
  141. package/dist/native/history.d.ts +20 -0
  142. package/dist/native/history.js +147 -0
  143. package/dist/native/instructions.d.ts +21 -0
  144. package/dist/native/instructions.js +173 -0
  145. package/dist/native/remote-worker-bridge.d.ts +3 -0
  146. package/dist/native/remote-worker-bridge.js +278 -0
  147. package/dist/native/remote.d.ts +187 -0
  148. package/dist/native/remote.js +492 -0
  149. package/dist/native/runtime.d.ts +17 -0
  150. package/dist/native/runtime.js +316 -0
  151. package/dist/native/runtimes.d.ts +66 -0
  152. package/dist/native/runtimes.js +41 -0
  153. package/dist/native/schema.d.ts +46 -0
  154. package/dist/native/schema.js +41 -0
  155. package/dist/native/types.d.ts +87 -0
  156. package/dist/native/types.js +1 -0
  157. package/dist/observation/http.d.ts +4 -0
  158. package/dist/observation/http.js +140 -0
  159. package/dist/observation/observer.d.ts +301 -0
  160. package/dist/observation/observer.js +919 -0
  161. package/dist/observation/schema.d.ts +52 -0
  162. package/dist/observation/schema.js +154 -0
  163. package/dist/openapi.d.ts +1 -0
  164. package/dist/openapi.js +394 -85
  165. package/dist/paid-calls.d.ts +8 -3
  166. package/dist/paid-calls.js +6 -2
  167. package/dist/place-offers.d.ts +4 -8
  168. package/dist/place-offers.js +4 -9
  169. package/dist/port-models.d.ts +7 -2
  170. package/dist/port-models.js +5 -2
  171. package/dist/print.d.ts +4 -2
  172. package/dist/print.js +4 -3
  173. package/dist/propose.d.ts +1 -2
  174. package/dist/propose.js +10 -1
  175. package/dist/provider.d.ts +5 -1
  176. package/dist/provider.js +8 -0
  177. package/dist/push-handler.d.ts +3 -2
  178. package/dist/push-handler.js +20 -6
  179. package/dist/refusal-words.d.ts +11 -0
  180. package/dist/refusal-words.js +13 -2
  181. package/dist/run-launch.d.ts +10 -1
  182. package/dist/run-launch.js +11 -4
  183. package/dist/run-learning-served.d.ts +75 -2
  184. package/dist/run-manifest.d.ts +3 -0
  185. package/dist/run-manifest.js +13 -1
  186. package/dist/run-reads-over-store.d.ts +3 -3
  187. package/dist/run-reads-over-store.js +13 -10
  188. package/dist/run-timeline-served.d.ts +3 -2
  189. package/dist/run-timeline-served.js +8 -9
  190. package/dist/run-view.d.ts +42 -35
  191. package/dist/run-view.js +79 -44
  192. package/dist/runnable.d.ts +13 -5
  193. package/dist/runnable.js +69 -60
  194. package/dist/runner/adapter-loop.d.ts +42 -11
  195. package/dist/runner/adapter-loop.js +651 -247
  196. package/dist/runner/adapter-run-spec.d.ts +37 -12
  197. package/dist/runner/adapter-run-spec.js +139 -106
  198. package/dist/runner/adapters/pi.d.ts +24 -0
  199. package/dist/runner/adapters/pi.js +59 -9
  200. package/dist/runner/beside.d.ts +3 -1
  201. package/dist/runner/beside.js +24 -8
  202. package/dist/runner/claim-secrets.d.ts +3 -1
  203. package/dist/runner/claim-secrets.js +28 -4
  204. package/dist/runner/cli-run-spec.d.ts +30 -0
  205. package/dist/runner/cli-run-spec.js +94 -50
  206. package/dist/runner/computer-channel.d.ts +5 -2
  207. package/dist/runner/computer-channel.js +3 -2
  208. package/dist/runner/computer-journal.d.ts +6 -0
  209. package/dist/runner/computer-journal.js +8 -10
  210. package/dist/runner/conformance/harness.js +6 -3
  211. package/dist/runner/end-of-run.d.ts +2 -0
  212. package/dist/runner/end-of-run.js +3 -1
  213. package/dist/runner/feedback-round.d.ts +40 -13
  214. package/dist/runner/feedback-round.js +64 -16
  215. package/dist/runner/harness-loops.js +17 -0
  216. package/dist/runner/journal-kinds.d.ts +37 -13
  217. package/dist/runner/journal-kinds.js +9 -5
  218. package/dist/runner/learning-dispatch.d.ts +3 -2
  219. package/dist/runner/learning-dispatch.js +6 -6
  220. package/dist/runner/learning-end.d.ts +4 -0
  221. package/dist/runner/learning-end.js +64 -36
  222. package/dist/runner/learning-factory.d.ts +3 -0
  223. package/dist/runner/learning-factory.js +8 -2
  224. package/dist/runner/learning-loop.d.ts +2 -0
  225. package/dist/runner/learning-loop.js +19 -4
  226. package/dist/runner/loop.d.ts +18 -0
  227. package/dist/runner/loop.js +34 -0
  228. package/dist/runner/main.d.ts +6 -1
  229. package/dist/runner/main.js +26 -4
  230. package/dist/runner/mcp-run.d.ts +4 -1
  231. package/dist/runner/mcp-run.js +11 -5
  232. package/dist/runner/meta-tools.d.ts +10 -3
  233. package/dist/runner/meta-tools.js +112 -36
  234. package/dist/runner/metrics.d.ts +80 -21
  235. package/dist/runner/metrics.js +114 -39
  236. package/dist/runner/model-route.d.ts +12 -3
  237. package/dist/runner/model-route.js +139 -18
  238. package/dist/runner/monid-run.d.ts +8 -6
  239. package/dist/runner/monid-run.js +117 -43
  240. package/dist/runner/native-loop.d.ts +11 -0
  241. package/dist/runner/native-loop.js +438 -0
  242. package/dist/runner/promotion.d.ts +74 -8
  243. package/dist/runner/promotion.js +365 -124
  244. package/dist/runner/redact.js +3 -0
  245. package/dist/runner/reflect-hook.js +9 -0
  246. package/dist/runner/runner.d.ts +7 -1
  247. package/dist/runner/runner.js +8 -4
  248. package/dist/runner/sdk-loop.d.ts +7 -0
  249. package/dist/runner/sdk-loop.js +470 -0
  250. package/dist/runner/spec-holds.d.ts +16 -2
  251. package/dist/runner/spec-holds.js +42 -14
  252. package/dist/runner/store-secrets.js +17 -2
  253. package/dist/runner/workflow-first.d.ts +30 -20
  254. package/dist/runner/workflow-first.js +22 -32
  255. package/dist/runner/workflow-loop.d.ts +1 -1
  256. package/dist/runner/workflow-loop.js +18 -12
  257. package/dist/runner/workflow-spec.d.ts +4 -1
  258. package/dist/runner/workflow-spec.js +56 -45
  259. package/dist/runs-over-store.d.ts +30 -2
  260. package/dist/runs-over-store.js +46 -14
  261. package/dist/sdk/runs.d.ts +115 -0
  262. package/dist/sdk/runs.js +422 -0
  263. package/dist/sdk/schema.d.ts +175 -0
  264. package/dist/sdk/schema.js +138 -0
  265. package/dist/sdk/workflows.d.ts +22 -0
  266. package/dist/sdk/workflows.js +39 -0
  267. package/dist/secrets.d.ts +2 -0
  268. package/dist/secrets.js +19 -1
  269. package/dist/server.d.ts +48 -32
  270. package/dist/server.js +554 -130
  271. package/dist/skill-route.d.ts +3 -0
  272. package/dist/skill-route.js +16 -0
  273. package/dist/skills/agentrun-serve/SKILL.md +368 -0
  274. package/dist/stats.d.ts +10 -10
  275. package/dist/store/agent-body.d.ts +12 -8
  276. package/dist/store/agent-body.js +9 -4
  277. package/dist/store/index.d.ts +1 -1
  278. package/dist/store/native-command-owner.d.ts +10 -0
  279. package/dist/store/native-command-owner.js +47 -0
  280. package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
  281. package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
  282. package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
  283. package/dist/store/postgres/store.js +3 -0
  284. package/dist/store/schema.d.ts +7 -0
  285. package/dist/store/schema.js +20 -1
  286. package/dist/store/sqlite/run-patch.d.ts +8 -1
  287. package/dist/store/sqlite/run-patch.js +14 -3
  288. package/dist/store/sqlite/store.js +133 -18
  289. package/dist/store/store.d.ts +52 -7
  290. package/dist/store-reads/analytics.d.ts +7 -7
  291. package/dist/store-reads/analytics.js +23 -5
  292. package/dist/store-reads/cap.js +8 -6
  293. package/dist/store-reads/journal.d.ts +5 -0
  294. package/dist/store-reads/journal.js +85 -41
  295. package/dist/store-reads/learning.d.ts +85 -5
  296. package/dist/store-reads/learning.js +45 -17
  297. package/dist/store-reads/runs.d.ts +5 -0
  298. package/dist/store-reads/runs.js +3 -2
  299. package/dist/store-view.js +75 -21
  300. package/dist/template-eval.d.ts +73 -11
  301. package/dist/template-eval.js +535 -75
  302. package/dist/templates.d.ts +70 -20
  303. package/dist/templates.js +191 -34
  304. package/dist/text-urls.d.ts +38 -0
  305. package/dist/text-urls.js +170 -0
  306. package/dist/timeline/index.d.ts +3 -2
  307. package/dist/timeline/index.js +3 -2
  308. package/dist/timeline/labels.d.ts +5 -2
  309. package/dist/timeline/labels.js +29 -6
  310. package/dist/timeline/origin.d.ts +1 -1
  311. package/dist/timeline/origin.js +2 -2
  312. package/dist/timeline/render-text.js +1 -1
  313. package/dist/timeline/timeline.d.ts +66 -4
  314. package/dist/timeline/timeline.js +160 -30
  315. package/dist/timeline/util.d.ts +5 -0
  316. package/dist/timeline/util.js +44 -8
  317. package/dist/timeline/web-calls.d.ts +17 -0
  318. package/dist/timeline/web-calls.js +106 -0
  319. package/dist/tool-gate.d.ts +42 -42
  320. package/dist/tool-gate.js +97 -91
  321. package/dist/tool-list.d.ts +4 -1
  322. package/dist/tool-list.js +8 -1
  323. package/dist/tool-names.d.ts +18 -13
  324. package/dist/tool-names.js +19 -17
  325. package/dist/tool-plane.d.ts +17 -13
  326. package/dist/tool-plane.js +12 -5
  327. package/dist/tools.d.ts +44 -16
  328. package/dist/tools.js +28 -28
  329. package/dist/trigger-adapter.d.ts +85 -5
  330. package/dist/trigger-adapter.js +6 -0
  331. package/dist/trigger-adapters.js +3 -1
  332. package/dist/trigger-composio.d.ts +10 -0
  333. package/dist/trigger-composio.js +122 -0
  334. package/dist/trigger-email.d.ts +4 -0
  335. package/dist/trigger-email.js +228 -0
  336. package/dist/trigger-signatures.d.ts +6 -10
  337. package/dist/trigger-signatures.js +16 -16
  338. package/dist/trigger-targets.d.ts +1 -1
  339. package/dist/trigger-targets.js +4 -3
  340. package/dist/trigger-webhook.js +6 -4
  341. package/dist/triggers.d.ts +94 -9
  342. package/dist/triggers.js +263 -62
  343. package/dist/uploads.d.ts +9 -0
  344. package/dist/uploads.js +27 -0
  345. package/dist/validate.js +1 -7
  346. package/dist/web-fake.d.ts +56 -0
  347. package/dist/web-fake.js +102 -0
  348. package/dist/web-fetch-direct.d.ts +3 -0
  349. package/dist/web-fetch-direct.js +4 -1
  350. package/dist/web-fetch.d.ts +5 -1
  351. package/dist/web-fetch.js +8 -31
  352. package/dist/web-search.d.ts +51 -2
  353. package/dist/web-search.js +116 -18
  354. package/dist/webhooks.d.ts +2 -1
  355. package/dist/webhooks.js +5 -1
  356. package/dist/workflow/node-runner.js +10 -2
  357. package/dist/workspace/archil-claim.d.ts +3 -0
  358. package/dist/workspace/archil-claim.js +9 -2
  359. package/dist/workspace/computer-deps.d.ts +22 -9
  360. package/dist/workspace/computer-deps.js +78 -37
  361. package/dist/workspace/computer-for-claim.d.ts +54 -4
  362. package/dist/workspace/computer-for-claim.js +179 -39
  363. package/dist/workspace/computer-janitor.d.ts +10 -3
  364. package/dist/workspace/computer-janitor.js +96 -29
  365. package/dist/workspace/computer-kept.d.ts +82 -0
  366. package/dist/workspace/computer-kept.js +147 -0
  367. package/dist/workspace/computer-mcp.js +4 -3
  368. package/dist/workspace/computer-ports.d.ts +23 -3
  369. package/dist/workspace/computer-ports.js +115 -5
  370. package/dist/workspace/index.d.ts +1 -2
  371. package/dist/workspace/index.js +1 -2
  372. package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
  373. package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
  374. package/dist/workspace/resolve-computer.d.ts +15 -3
  375. package/dist/workspace/resolve-computer.js +10 -7
  376. package/dist/workspace/revision-skills.d.ts +6 -2
  377. package/dist/workspace/revision-skills.js +12 -5
  378. package/dist/workspace/run-end-computers.d.ts +30 -0
  379. package/dist/workspace/run-end-computers.js +137 -0
  380. package/dist/workspace/run-tools.d.ts +28 -29
  381. package/dist/workspace/run-tools.js +29 -30
  382. package/dist/wrap-up.d.ts +19 -5
  383. package/dist/wrap-up.js +31 -4
  384. package/package.json +13 -9
  385. package/skills/agentrun-serve/SKILL.md +248 -10
  386. package/templates/README.md +117 -23
  387. package/templates/TOOLS.md +168 -0
  388. package/templates/code-review/agent.md +18 -4
  389. package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
  390. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
  391. package/templates/code-review/evals/other-repo/case.yaml +1 -1
  392. package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
  393. package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
  394. package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
  395. package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
  396. package/templates/code-review/skills/review/DEEP.md +2 -2
  397. package/templates/code-review/skills/review/REVIEWER.md +2 -2
  398. package/templates/code-review/skills/review/SKILL.md +7 -3
  399. package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
  400. package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
  401. package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
  402. package/templates/release-notes/evals/other-repo/case.yaml +1 -1
  403. package/dist/console/assets/index-CjqQirbo.css +0 -1
  404. package/dist/console/assets/index-b6-XY5A9.js +0 -576
  405. package/dist/host-calls.d.ts +0 -20
  406. package/dist/host-calls.js +0 -12
  407. package/dist/runner/adapters/pi-computer.d.ts +0 -9
  408. package/dist/runner/adapters/pi-computer.js +0 -51
  409. package/dist/workspace/computer-script.d.ts +0 -53
  410. package/dist/workspace/computer-script.js +0 -172
@@ -9,7 +9,13 @@
9
9
  // A monid provider's slug and an endpoint's path are monid's own (its listing, GET /v1/endpoints): a slug is lowercase
10
10
  // letters, digits, `.` and `-` (`apollo`, `api.strale.io`); an endpoint is its path less the leading `/`, in letters,
11
11
  // digits and `-._:{}/` (`people/match`, `people/{id}`). Its wire name is catalog.ts wireName's, hashed when long.
12
- import { WIRE_NAME } from "./catalog.js";
12
+ // It imports nothing (its test holds it to that): the console bundles it from source, as `@agentrun/tool-names`.
13
+ /** A wire name: at most 52 characters, not the adapter's 64. One CLI gives the model the name with a 12-character
14
+ * `mcp__hands__` prefix, and the model API's 64-character limit is on the name the model sees, so 52 is the budget that
15
+ * holds on every harness. The identity branch reads it: a plain 53-64 character name of valid characters must not skip
16
+ * the mapping and come out over budget. An MCP tool whose `mcp__<server>__<tool>` is past it (Composio's 58-character
17
+ * `mcp__slack__SLACK_FETCH_MESSAGE_THREAD_FROM_A_CONVERSATION`) is granted and called by its hashed name. */
18
+ export const WIRE_NAME = /^[A-Za-z0-9_-]{1,52}$/;
13
19
  const SERVER = "[a-z][a-z0-9-]{0,31}";
14
20
  const TOOL = "[A-Za-z0-9_-]{1,64}";
15
21
  const PROVIDER = "[a-z0-9][a-z0-9.-]{0,63}";
@@ -25,6 +31,8 @@ export const MCP_TOOL_NAME = new RegExp(`^${TOOL}$`);
25
31
  /** A catalog tool's name, as a JSON Schema pattern (openapi.ts): `mcp:<server>/<tool>`, `monid:<provider>/<endpoint>`,
26
32
  * or either's wildcard. */
27
33
  export const CATALOG_KEY_PATTERN = `^(?:mcp:${SERVER}/(?:\\*|${TOOL})|monid:${PROVIDER}/(?:\\*|${ENDPOINT}))$`;
34
+ /** One MCP tool's catalog key, without a server wildcard: the same server/tool grammar as mcpNameOf. */
35
+ export const MCP_TOOL_KEY_PATTERN = `^mcp:${SERVER}/${TOOL}$`;
28
36
  const MCP_NAME = new RegExp(`^mcp:(${SERVER})/(\\*|${TOOL})$`);
29
37
  const MONID_NAME = new RegExp(`^monid:(${PROVIDER})/(\\*|${ENDPOINT})$`);
30
38
  const PLAIN_NAME = new RegExp(`^${PLAIN}$`);
@@ -77,23 +85,17 @@ export function mcpServerOf(name) {
77
85
  const parsed = parseToolName(name);
78
86
  return parsed?.kind === "mcp" || parsed?.kind === "mcp-server" ? parsed.server : undefined;
79
87
  }
80
- /** Whether `name` is an MCP server's wildcard, `mcp:<server>/*`. */
81
- export const isMcpWildcard = (name) => parseToolName(name)?.kind === "mcp-server";
82
88
  /** Why a grant of an MCP server's tool is refused by its name alone, said after the grant (`mcp:<server>/<tool> ...`): the
83
89
  * one place the console's picker and the save's blockers (runnable.ts) both read it. `hands` is the harnesses' own tools'
84
90
  * server. */
85
91
  export const MCP_HANDS_WORDS = "names the MCP server hands, a name the harnesses keep for their own tools: save the server under another name.";
86
- /** Why `mcp__<server>__<tool>`, the name every harness calls the tool by, is not within the budget their names share
87
- * (52 characters of letters, digits, `_` and `-`), or undefined when it is. */
88
- export function mcpWireProblem(server, tool) {
89
- const wire = `mcp__${server}__${tool}`;
90
- return WIRE_NAME.test(wire) ? undefined : `is too long: ${wire} must be at most 52 characters, the budget every harness's tool names share.`;
91
- }
92
- /** MCP_HANDS_WORDS or mcpWireProblem's, whichever refuses the name; undefined when neither does. */
93
- export const mcpGrantNameProblem = (server, tool) => (server === "hands" ? MCP_HANDS_WORDS : mcpWireProblem(server, tool));
94
- /** Why a harness's own MCP client drops or retypes `tool` of `server` (its facts' schemaProblems, `dropped` the first):
95
- * the words a save's blocker and a saved server's read both say. */
96
- export const mcpDroppedWords = (server, tool, harness, dropped) => `The MCP server ${server}'s tool ${tool} cannot be offered on ${harness}: ${dropped.replace(/^mcp__\S+: /, "")}.`;
97
- /** Why the harness drops or retypes the pinned monid endpoint `tool`'s input (its facts' schemaProblems, `dropped` the
98
- * first, under the endpoint's wire name): the words a save refuses its grant with. */
99
- export const monidDroppedWords = (tool, harness, dropped) => `The monid endpoint ${tool} cannot be offered on ${harness}: ${dropped.replace(/^monid__\S+: /, "")}. Grant its provider's other endpoints by name, or pick another harness.`;
92
+ /** MCP_HANDS_WORDS when the grant names the server `hands`; undefined otherwise. A name's length refuses nothing: one whose
93
+ * `mcp__<server>__<tool>` is past the budget every harness's names share is called by its hashed wire name (catalog.ts
94
+ * wireName), and read back by lookup. */
95
+ export const mcpGrantNameProblem = (server, _tool) => (server === "hands" ? MCP_HANDS_WORDS : undefined);
96
+ /** Why two granted catalog tools can't both be granted: the harnesses call both by one wire name (`wire`, catalog.ts
97
+ * wireName), so neither could be told apart. Said after the later grant. */
98
+ export const sameWireWords = (tool, other, wire) => `${tool} and ${other} are called by one name on every harness (${wire}): grant one of them by name.`;
99
+ /** Why `harness` drops or retypes the input of the catalog tool `tool` (its facts' schemaProblems, `dropped` the first,
100
+ * said under the tool's wire name): the words a save's blocker and a saved MCP server's read both say. */
101
+ export const droppedWords = (tool, harness, dropped) => `The tool ${tool} cannot be offered on ${harness}: ${dropped.replace(/^[A-Za-z0-9_-]+: /, "")}.`;
@@ -4,6 +4,9 @@ import { type HarnessId } from "./harness.js";
4
4
  import { type ShellPlace } from "@parcha/agentrun-kernel/kernel";
5
5
  import { type Permission, type Pin, type ToolEffect } from "./tool-gate.js";
6
6
  import { type BashPolicy } from "./bash-read-only.js";
7
+ import { EMAIL_SCOPES } from "./email/names.js";
8
+ /** An email read tool's scope (email/names.ts). */
9
+ type EmailScope = (typeof EMAIL_SCOPES)[number];
7
10
  /**
8
11
  * The capabilities a pack or a revision may grant, by name: the tools the kernel gives a run, bound from serve's closed
9
12
  * table (tools.ts) and named the same on every harness that runs them. `web_search` and `web_fetch` resolve to a
@@ -36,11 +39,11 @@ export declare const permissionsOf: (name: string) => readonly Permission[];
36
39
  * give it: the one in force under the server's settings (`permission`), the owner's default (`default_permission`) and
37
40
  * those it may be set to. An agent's read gives the same, the agent's own layer over it (agentTools). */
38
41
  export declare const serverGate: (name: string, settings: ToolSettingsMap, effect?: ToolEffect) => {
39
- default_permission: "ask" | "deny" | "allow";
40
- permissions: ("ask" | "deny" | "allow")[];
42
+ default_permission: "allow" | "ask" | "deny";
43
+ permissions: ("allow" | "ask" | "deny")[];
41
44
  fallback_allow_reads?: true | undefined;
42
45
  allow_reads?: true | undefined;
43
- permission: "ask" | "deny" | "allow";
46
+ permission: "allow" | "ask" | "deny";
44
47
  };
45
48
  /** The run's own tools beyond the table, each its own settings key, allowed by default like a table tool: the learned
46
49
  * workflow a run's pin names runs as `learned_workflow` (learned-workflow.ts LEARNED_WORKFLOW_TOOL), and the host's
@@ -61,7 +64,8 @@ export type ToolSetting = {
61
64
  permission?: Permission;
62
65
  pin?: Pin; /** On an MCP server's wildcard (`mcp:<server>/*`) in the server's settings only: the tools its server marks read-only run with no approval (tool-gate.ts readsLift). Kept only when true. */
63
66
  allow_reads?: true; /** bash's policy, an agent's own only (bash-read-only.ts). */
64
- policy?: BashPolicy; /** Read as a stand-in for a value not offered (checkToolSettings); never shown or written. */
67
+ policy?: BashPolicy; /** An email read tool's scope, an agent's own only (email/tools.ts): its email run's thread (the default), or the whole account. */
68
+ scope?: EmailScope; /** Read as a stand-in for a value not offered (checkToolSettings); never shown or written. */
65
69
  fallback?: true; /** The stand-in's value as written in the file, which a save that keeps the stand-in writes back (ToolSettings.put). Never shown. */
66
70
  raw?: unknown; /** A pin in the file that does not read (readToolSettings): the gate refuses every call of the tool, and a save keeps it (ToolSettings.put) until the owner sets a valid pin or removes the tool's setting. Served as `pin_broken: true`. */
67
71
  brokenPin?: true; /** The broken pin as written in the file, which a save that keeps it writes back. Never shown. */
@@ -281,17 +285,17 @@ export declare function shellUnavailable(name: string, shell: ShellPlace): Resol
281
285
  * computer setting); a tool of bash's family that leaves out resolves unavailable, saying why (shellUnavailable). */
282
286
  export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSettingsMap, agent: Tooling, order: readonly string[], shell?: ShellPlace, effectOf?: (name: string) => ToolEffect | undefined): ({
283
287
  resolved: Resolution;
284
- permission: "ask" | "deny" | "allow";
288
+ permission: "allow" | "ask" | "deny";
285
289
  permission_from: import("./refusal-words.js").SettingFrom;
286
- default_permission: "ask" | "deny" | "allow";
287
- permissions: ("ask" | "deny" | "allow")[];
290
+ default_permission: "allow" | "ask" | "deny";
291
+ permissions: ("allow" | "ask" | "deny")[];
288
292
  blurb?: string | undefined;
289
293
  name: string;
290
294
  } | {
291
- permission: "ask" | "deny" | "allow";
295
+ permission: "allow" | "ask" | "deny";
292
296
  permission_from: import("./refusal-words.js").SettingFrom;
293
- default_permission: "ask" | "deny" | "allow";
294
- permissions: ("ask" | "deny" | "allow")[];
297
+ default_permission: "allow" | "ask" | "deny";
298
+ permissions: ("allow" | "ask" | "deny")[];
295
299
  blurb?: string | undefined;
296
300
  name: string;
297
301
  } | {
@@ -299,10 +303,10 @@ export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSetting
299
303
  provider_from: string;
300
304
  default_provider: string;
301
305
  resolved: Resolution;
302
- permission: "ask" | "deny" | "allow";
306
+ permission: "allow" | "ask" | "deny";
303
307
  permission_from: import("./refusal-words.js").SettingFrom;
304
- default_permission: "ask" | "deny" | "allow";
305
- permissions: ("ask" | "deny" | "allow")[];
308
+ default_permission: "allow" | "ask" | "deny";
309
+ permissions: ("allow" | "ask" | "deny")[];
306
310
  blurb?: string | undefined;
307
311
  name: string;
308
312
  })[];
@@ -30,9 +30,10 @@ import { viaOpenRouter, WIRES } from "./provider.js";
30
30
  import { savedIn } from "./secrets.js";
31
31
  import { hostModel } from "./model.js";
32
32
  import { NEEDS_A_COMPUTER, NO_SHELL } from "@parcha/agentrun-kernel/kernel";
33
- import { canonicalPin, defaultPermission, isCatalogTool, isPinKeys, MAX_PIN_ARGS, MAX_PIN_CHOICES, PERMISSIONS, permissionFrom, permissionOf, SETTINGS_UNREAD, SHELL_FAMILY } from "./tool-gate.js";
33
+ import { canonicalPin, defaultPermission, isPinKeys, MAX_PIN_ARGS, MAX_PIN_CHOICES, PERMISSIONS, permissionFrom, permissionOf, SETTINGS_UNREAD, SHELL_FAMILY } from "./tool-gate.js";
34
34
  import { BASH_POLICIES } from "./bash-read-only.js";
35
- import { isMcpName, mcpNameOf, parseToolName } from "./tool-names.js";
35
+ import { EMAIL_SCOPES, SCOPED_TOOLS, SCOPED_WORDS } from "./email/names.js";
36
+ import { isCatalogName, isMcpName, mcpNameOf, parseToolName } from "./tool-names.js";
36
37
  /**
37
38
  * The capabilities a pack or a revision may grant, by name: the tools the kernel gives a run, bound from serve's closed
38
39
  * table (tools.ts) and named the same on every harness that runs them. `web_search` and `web_fetch` resolve to a
@@ -55,7 +56,7 @@ export const PICKABLE = Object.keys(PROVIDERS);
55
56
  /** The permissions `name` may be set to: ask is offered for the tools whose approved call the kernel runs itself, outside
56
57
  * the model's turn (tool-list.ts `askable`) and for catalog tools. Any other (browser, ask_person, the call-only ones) is
57
58
  * allow or deny. */
58
- export const permissionsOf = (name) => (Object.hasOwn(SHELL_FAMILY, name) && SHELL_FAMILY[name] !== name ? permissionsOf(SHELL_FAMILY[name]) : isAskable(name) || isCatalogTool(name) ? PERMISSIONS : ["allow", "deny"]);
59
+ export const permissionsOf = (name) => (Object.hasOwn(SHELL_FAMILY, name) && SHELL_FAMILY[name] !== name ? permissionsOf(SHELL_FAMILY[name]) : isAskable(name) || isCatalogName(name) ? PERMISSIONS : ["allow", "deny"]);
59
60
  /** A tool's permission as this server applies it to an agent that sets none, as capabilities and an MCP server's read
60
61
  * give it: the one in force under the server's settings (`permission`), the owner's default (`default_permission`) and
61
62
  * those it may be set to. An agent's read gives the same, the agent's own layer over it (agentTools). */
@@ -94,7 +95,7 @@ export const DECISION_PROVIDER_KEYS = ["jev", "parallel", "openrouter"];
94
95
  * decision provider's (DECISION_PROVIDER_KEYS), a
95
96
  * catalog tool (`mcp:<server>/<tool>`, `monid:<provider>/<endpoint>`), or a group's wildcard (`mcp:<server>/*`,
96
97
  * `monid:<provider>/*`), which sets each of its tools. */
97
- const isSettingsKey = (name) => parseToolName(name) !== undefined && (isTableTool(name) || SERVE_OWN_TOOLS.includes(name) || KIND_KEYS.includes(name) || DECISION_PROVIDER_KEYS.includes(name) || isCatalogTool(name));
98
+ const isSettingsKey = (name) => parseToolName(name) !== undefined && (isTableTool(name) || SERVE_OWN_TOOLS.includes(name) || KIND_KEYS.includes(name) || DECISION_PROVIDER_KEYS.includes(name) || isCatalogName(name));
98
99
  /** The longest pinned string. */
99
100
  export const MAX_PIN_TEXT = 1024;
100
101
  /** A pinned argument's name: a top-level argument of the tool, as MCP tools name theirs. */
@@ -406,6 +407,12 @@ export function settingsIssues(value, at = "", layer = "server") {
406
407
  return [{ field: field(name, key), reason: "not_allowed", message: `A policy is set on bash in an agent's own tool settings (definition.tool_settings.bash.policy), never ${layer === "agent" ? `on ${name}` : "in the server's"}.` }];
407
408
  return BASH_POLICIES.includes(given) ? [] : [{ field: field(name, key), reason: "not_an_option", message: `${field(name, key)} is one of ${BASH_POLICIES.join(", ")}: read-only refuses, before it runs, any command that could write, run code or read outside the run's folder` }];
408
409
  }
410
+ // An email tool's scope (email/tools.ts): an agent's own, on email_read, email_search and email_file only, set as bash's policy is.
411
+ if (key === "scope") {
412
+ if (layer !== "agent" || !SCOPED_TOOLS.includes(name))
413
+ return [{ field: field(name, key), reason: "not_allowed", message: `A scope is set on ${SCOPED_WORDS} in an agent's own tool settings (definition.tool_settings.email_read.scope), never ${layer === "agent" ? `on ${name}` : "in the server's"}.` }];
414
+ return EMAIL_SCOPES.includes(given) ? [] : [{ field: field(name, key), reason: "not_an_option", message: `${field(name, key)} is one of ${EMAIL_SCOPES.join(", ")}: thread, an email's run reads its thread alone; mailbox, the whole account` }];
415
+ }
409
416
  // The server's own mark of a pin in its file that does not read (withDefaults serves it), which a whole-map save
410
417
  // sends back: it keeps the broken pin, and nothing else. Never an agent's.
411
418
  if (key === "pin_broken") {
@@ -440,7 +447,7 @@ export function canonicalToolSettings(map) {
440
447
  return sorted(Object.fromEntries(Object.entries(map).flatMap(([name, setting]) => {
441
448
  if (!setting)
442
449
  return [];
443
- const kept = sorted({ ...(setting.permission ? { permission: setting.permission } : {}), ...(setting.allow_reads === true ? { allow_reads: true } : {}), ...(setting.pin ? { pin: sortedPin(setting.pin) } : {}), ...(setting.policy ? { policy: setting.policy } : {}), ...(setting.provider ? { provider: setting.provider } : {}) });
450
+ const kept = sorted({ ...(setting.permission ? { permission: setting.permission } : {}), ...(setting.allow_reads === true ? { allow_reads: true } : {}), ...(setting.pin ? { pin: sortedPin(setting.pin) } : {}), ...(setting.policy ? { policy: setting.policy } : {}), ...(setting.scope ? { scope: setting.scope } : {}), ...(setting.provider ? { provider: setting.provider } : {}) });
444
451
  return Object.keys(kept).length ? [[name, kept]] : [];
445
452
  })));
446
453
  }
package/dist/tools.d.ts CHANGED
@@ -8,6 +8,7 @@ import { type Ledger, type PaidBooking } from "./paid-calls.js";
8
8
  import type { Refusal } from "@parcha/agentrun-kernel";
9
9
  import { type ShellPlace } from "@parcha/agentrun-kernel/kernel";
10
10
  import { type SearchOn } from "./web-search.js";
11
+ import { type WebFake } from "./web-fake.js";
11
12
  import { type Plane, type Resolution, type Tooling, type ToolSettingsMap } from "./tool-plane.js";
12
13
  import type { DenyFrom, SettingFrom } from "./tool-gate.js";
13
14
  import type { LiveHandover, LiveViewerStore } from "./browser-live.js";
@@ -76,7 +77,19 @@ export type ToolHost = {
76
77
  liveAt?: RunnerLive;
77
78
  /** The one store, for the live-viewer seam above, the run's saved sign-in (its runs and sign-ins, read under `claim`),
78
79
  * the sign-in verify the runner saves, and the Screen tab's ended state (settings: browser-wait-ended.ts). */
79
- store?: LiveViewerStore & Pick<Store, "runs" | "signIns" | "settings">;
80
+ store?: LiveViewerStore & Pick<Store, "runs" | "signIns" | "settings" | "sealedKeys">;
81
+ /** The trigger that started the run, and its source's kind (run-launch.ts trigger, inputOrigin): an email's run reads
82
+ * its thread alone (email/tools.ts). Absent: a person's run, or one no trigger started. */
83
+ startedBy?: {
84
+ readonly trigger: {
85
+ readonly id: string;
86
+ readonly firing_key: string;
87
+ readonly attrs?: Readonly<Record<string, string>>;
88
+ };
89
+ readonly source: string;
90
+ };
91
+ /** The agent's own tool settings (its revision's tool_settings), as its gate reads them: an email read tool's `scope`. */
92
+ toolSettings?: unknown;
80
93
  /** The claim this run is held under: the live-viewer rows are written under it (its epoch fences them), and the run's
81
94
  * saved sign-in is read and its hand kept under it. Present, the run is on the runner: never the process's own pipe. */
82
95
  claim?: Claim;
@@ -107,6 +120,28 @@ export type ToolHost = {
107
120
  /** The run's own models a native web_search goes through (hosted-search.ts), asked as a search runs: on the runner, the
108
121
  * session's port (its proxy, policy, key, price and cap), this run's alone. Absent: a native search has no model. */
109
122
  search?: SearchOn;
123
+ /** A template eval's web fake for this run (web-fake.ts): its web_search and web_fetch answer from it, never the
124
+ * network. Only the eval's own runner sets it (runner/beside.ts evalFakes). Absent: the plane's providers. */
125
+ web?: WebFake;
126
+ /** The run's clock where a template eval case sets one (its `now`): a draft's or a send's Date reads it. Absent: the real
127
+ * clock. */
128
+ now?: Date;
129
+ /** A template eval case's fake mail account (eval-mailbox.ts), the only account the run's email tools open: one saved
130
+ * elsewhere is refused. Only the eval's own runner sets it (runner/beside.ts evalFakes). */
131
+ emailFake?: EmailFake;
132
+ };
133
+ /** A fake mail account's servers, on loopback (email/email-faux.ts), and the kind of server it plays: what email_file's
134
+ * description says, which a loopback account saved as `other` would otherwise read as folders. */
135
+ export type EmailFake = {
136
+ readonly imap: {
137
+ readonly host: string;
138
+ readonly port: number;
139
+ };
140
+ readonly smtp: {
141
+ readonly host: string;
142
+ readonly port: number;
143
+ };
144
+ readonly kind: "gmail" | "folders";
110
145
  };
111
146
  /** What a name stands for in the run: the pi tools it offers, and the extensions a conversation selects for them. */
112
147
  export type ToolBinding = {
@@ -222,7 +257,8 @@ export declare const CALL_TOOLS: readonly string[];
222
257
  export declare const allows: (allowed: readonly string[], name: string) => boolean;
223
258
  /** The tools a run's learned workflow may name (learn/check.ts at learn time, learned-workflow.ts at a call): those of the
224
259
  * agent's `granted` tools a workflow's call node runs here (CALL_TOOLS, and each MCP tool granted by its own name,
225
- * tool-names.ts mcpNameOf: a wildcard is read against its server's listing first, mcpGrantsListed), and with the run's `plane`, none it resolves unavailable (its agent's own tool of the name does not run either). A
260
+ * tool-names.ts mcpNameOf), and with the run's `plane`, none it resolves unavailable (its agent's own tool of the name
261
+ * does not run either). A
226
262
  * learned model node runs without tools (learn/skills.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
227
263
  * exec_command, apply_patch) is never one, so the DSL refuses a draft that names it. */
228
264
  export declare const learnedWorkflowTools: (granted: readonly string[], plane?: Plane, options?: LearnedMcp) => string[];
@@ -235,13 +271,6 @@ export type LearnedMcp = {
235
271
  readonly mcp?: boolean;
236
272
  readonly approvers?: boolean;
237
273
  };
238
- /** `granted` with each MCP server's wildcard (`mcp:<server>/*`) read as the tools its server lists now (`listed`, by the
239
- * server's name: none for a server not saved), each `mcp:<server>/<tool>`, in place; every other name as it is, each
240
- * once. What a revision grants under a wildcard is every tool of its server, so a learned draft may name each one
241
- * (learnedWorkflowTools), its gate holding it as any tool (learnedDraftTools: the wildcard's setting, or the tool's own).
242
- * At proposal time there is no run and no pin: whether the run's pin has the tool is the runtime's to check at the call,
243
- * in the gate's words (learned-workflow.ts). */
244
- export declare function mcpGrantsListed(granted: readonly string[], listed: (server: string) => readonly string[]): string[];
245
274
  /** The tools a learned draft may name (learnedWorkflowTools) that the gate allows: `permission` is what the gate holds a
246
275
  * tool to now (tool-gate.ts permissionOf, or the run's gate's policy), by its settings key. One set to ask or deny is left out of `tools`, so the end-of-run prompt never offers it, and named
247
276
  * in `gated` with its setting, which the checker and a learned workflow's check before it runs refuse a draft for. */
@@ -249,7 +278,6 @@ export declare const learnedDraftTools: (granted: readonly string[], permission:
249
278
  tools: string[];
250
279
  gated: Record<string, string>;
251
280
  deniedBy: Record<string, DenyFrom>;
252
- asked: string[];
253
281
  };
254
282
  /** The tools a workflow names (`nodes` from workflowNodes): on its model nodes (`tools`), and on its `call` nodes
255
283
  * `via: "tool"` (`tool`). */
@@ -291,11 +319,11 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
291
319
  default_provider?: string | undefined;
292
320
  resolves?: Record<"opencode" | "codex" | "pi" | "claude-agent", Resolution> | undefined;
293
321
  why?: Record<"opencode" | "codex" | "pi" | "claude-agent", string> | undefined;
294
- default_permission: "ask" | "deny" | "allow";
295
- permissions: ("ask" | "deny" | "allow")[];
322
+ default_permission: "allow" | "ask" | "deny";
323
+ permissions: ("allow" | "ask" | "deny")[];
296
324
  fallback_allow_reads?: true | undefined;
297
325
  allow_reads?: true | undefined;
298
- permission: "ask" | "deny" | "allow";
326
+ permission: "allow" | "ask" | "deny";
299
327
  harnesses: ("opencode" | "codex" | "pi" | "claude-agent")[];
300
328
  missing?: string[] | undefined;
301
329
  reason?: string | undefined;
@@ -308,11 +336,11 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
308
336
  name: string;
309
337
  summary: string;
310
338
  } | {
311
- default_permission: "ask" | "deny" | "allow";
312
- permissions: ("ask" | "deny" | "allow")[];
339
+ default_permission: "allow" | "ask" | "deny";
340
+ permissions: ("allow" | "ask" | "deny")[];
313
341
  fallback_allow_reads?: true | undefined;
314
342
  allow_reads?: true | undefined;
315
- permission: "ask" | "deny" | "allow";
343
+ permission: "allow" | "ask" | "deny";
316
344
  name: string;
317
345
  summary: string;
318
346
  blurb: string;
package/dist/tools.js CHANGED
@@ -5,7 +5,8 @@
5
5
  // run's folder or its computer. `bash` and the background tools may be named only by an agent whose place is a box
6
6
  // (runnable.ts).
7
7
  import { blurbOf, isHostTool } from "./tool-list.js";
8
- import { mcpNameOf, mcpToolName, parseToolName } from "./tool-names.js";
8
+ import { EMAIL_DRAFT, EMAIL_FILE, EMAIL_READ, EMAIL_SEARCH, EMAIL_SEND } from "./email/names.js";
9
+ import { mcpNameOf } from "./tool-names.js";
9
10
  import { appendFileSync } from "node:fs";
10
11
  import { pathToFileURL } from "node:url";
11
12
  import { defineExtension, defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
@@ -25,6 +26,7 @@ import { browserPrice, browserSpend } from "./browser-cost.js";
25
26
  import { forModel } from "./result.js";
26
27
  import { fetchFor, pagesOf, WEB_FETCH_TOOL, webFetchTool } from "./web-fetch.js";
27
28
  import { searchFor, WEB_SEARCH_TOOL, webSearchTool } from "./web-search.js";
29
+ import { fakeFetch, fakeSearch } from "./web-fake.js";
28
30
  import { browserNeeds, explainsView, isUnavailable, NO_PARALLEL_KEY, PICKABLE, planeOf, PROVIDERS, serverGate, whyUnavailable, withDefaults } from "./tool-plane.js";
29
31
  import { fauxFetch, PARALLEL_KEY_ENV } from "./decisions.js";
30
32
  import { keyNeeded } from "./key-words.js";
@@ -80,13 +82,21 @@ const callOnly = (summary, effect) => ({
80
82
  summary, needs: [], nodes: false, callOnly: true, effect,
81
83
  bind: async () => { throw new Error("a call-only tool binds no agent tool"); },
82
84
  });
85
+ /** An email tool (email/tools.ts emailEntry), its binding loaded at its first bind. */
86
+ const emailTool = (name, summary) => ({
87
+ summary,
88
+ needs: [],
89
+ nodes: false,
90
+ bind: async (host) => (await import("./email/tools.js")).emailEntry(name, summary).bind(host),
91
+ });
83
92
  /** web_fetch, bound under `name`. */
84
93
  const webFetchEntry = (name) => ({
85
94
  summary: `Read one public web page from a public host through the guarded direct fetch, or through Parallel's extract where Parallel is picked (falling back to the direct fetch, saying why, when Parallel answers no page), a part at a time (offset, max_chars; the page fetched once a run): { ok, url, status, title, text, chars, truncated?, original_chars?, beyond_read?, offset?, next_offset?, html_chars?, converted?, links, links_omitted?, via, parallel?, refused?, error? }; html_chars, the page's whole length, when its HTML was cut at ${HTML_READ_CHARS.toLocaleString("en-US")} characters before it was read, so its text is only the start of the page; converted: "text" when the text is plain text, its conversion to markdown having run out of time; a private or local address, a port other than 80 or 443, or a scheme other than http(s) is refused, never sent to Parallel.`,
86
95
  needs: [],
87
96
  nodes: true,
88
97
  bind: async (host) => {
89
- const tool = booking(webFetchTool(host.env, name));
98
+ const web = host.web;
99
+ const tool = booking(webFetchTool(host.env, name, web && ((url, part) => fakeFetch(web, url, part))));
90
100
  const extension = defineExtension({ name: name.replaceAll("_", "-"), tools: [tool] });
91
101
  host.install(extension);
92
102
  return { tools: [tool], extensions: [extension] };
@@ -578,9 +588,17 @@ export const TOOLS = Object.freeze({
578
588
  needs: [],
579
589
  nodes: true,
580
590
  // On the runner its hosted search goes through the run's own route (host.search, run.search), labelled web_search.
581
- bind: async (host) => installTool(host, "web-search", booking(webSearchTool(host.env, host.search))),
591
+ // A template eval's web fake (host.web) answers in the provider's place.
592
+ bind: async (host) => installTool(host, "web-search", booking(webSearchTool(host.env, host.search, host.web && ((args, provider) => fakeSearch(host.web, args, provider))))),
582
593
  effect: async (args, run) => bookedIn(run.ledger, () => searchFor(run.env, args, run.signal, run.search)),
583
594
  },
595
+ // The email tools (email/tools.ts) on the server's one email account (Settings → Email), every harness's as web_fetch is;
596
+ // the mail libraries load at the first bind.
597
+ [EMAIL_SEARCH]: emailTool(EMAIL_SEARCH, "Search the server's email account: { from?, to?, subject?, text?, since?, unread?, mailbox?: \"INBOX\", limit?: 20 (max 50) } -> { messages: [{ message_id, from, to, subject, date, snippet, unread, attachments }] }, newest first. On a run an email started, its thread alone unless the agent's setting says scope: \"mailbox\"."),
598
+ [EMAIL_READ]: emailTool(EMAIL_READ, "Read an email of the server's account by message_id, or its whole thread (thread: true, by References and In-Reply-To, oldest first): { message_id, thread? } -> { messages: [{ from, from_name, to, cc, subject, date, message_id, in_reply_to, text, attachments, references }] }. Reads leave mail unread."),
599
+ [EMAIL_DRAFT]: emailTool(EMAIL_DRAFT, "Save an email to the account's Drafts, sending nothing: { to, cc?, subject, text, in_reply_to? } -> { saved: true, mailbox, message_id }; in_reply_to threads it as a reply."),
600
+ [EMAIL_SEND]: emailTool(EMAIL_SEND, "Send an email from the server's account over SMTP: { to, cc?, subject, text, in_reply_to? } -> { sent: true, message_id }; in_reply_to threads it as a reply, and a copy is filed in Sent. Asks the person first by default."),
601
+ [EMAIL_FILE]: emailTool(EMAIL_FILE, "File an email of the server's account by message_id under to: { message_id, to, archive? } -> { filed: true, message_id, to, archived, subject, note? }. On Gmail it adds the label and the message stays in the inbox (archive: true takes it out too); elsewhere it moves the message out of the inbox to the folder, its note saying \"moved out of the inbox to <to>\" (an explicit archive: false is refused). Folders and labels are made if missing; the trash and junk folders are refused: it never deletes mail. On a run an email started, its thread alone unless the agent's setting says scope: \"mailbox\"."),
584
602
  browser: browserTool,
585
603
  // A pi run's subagent (runner/subagent.ts): a native tool of the run's root agent, bound by the runner's pi spec
586
604
  // (adapter-run-spec.ts), never by this table; not a host tool (tool-list.ts `replay`), so another harness refuses it.
@@ -605,52 +623,34 @@ export const CALL_TOOLS = Object.keys(TOOLS).filter((name) => TOOLS[name].effect
605
623
  export const allows = (allowed, name) => allowed.includes(name);
606
624
  /** The tools a run's learned workflow may name (learn/check.ts at learn time, learned-workflow.ts at a call): those of the
607
625
  * agent's `granted` tools a workflow's call node runs here (CALL_TOOLS, and each MCP tool granted by its own name,
608
- * tool-names.ts mcpNameOf: a wildcard is read against its server's listing first, mcpGrantsListed), and with the run's `plane`, none it resolves unavailable (its agent's own tool of the name does not run either). A
626
+ * tool-names.ts mcpNameOf), and with the run's `plane`, none it resolves unavailable (its agent's own tool of the name
627
+ * does not run either). A
609
628
  * learned model node runs without tools (learn/skills.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
610
629
  * exec_command, apply_patch) is never one, so the DSL refuses a draft that names it. */
611
630
  export const learnedWorkflowTools = (granted, plane, options = {}) => [...new Set(granted.filter((name) => (options.mcp === true && mcpNameOf(name) !== undefined) || (allows(CALL_TOOLS, name) && !isUnavailable(plane?.[name]))))];
612
- /** `granted` with each MCP server's wildcard (`mcp:<server>/*`) read as the tools its server lists now (`listed`, by the
613
- * server's name: none for a server not saved), each `mcp:<server>/<tool>`, in place; every other name as it is, each
614
- * once. What a revision grants under a wildcard is every tool of its server, so a learned draft may name each one
615
- * (learnedWorkflowTools), its gate holding it as any tool (learnedDraftTools: the wildcard's setting, or the tool's own).
616
- * At proposal time there is no run and no pin: whether the run's pin has the tool is the runtime's to check at the call,
617
- * in the gate's words (learned-workflow.ts). */
618
- export function mcpGrantsListed(granted, listed) {
619
- const out = new Set();
620
- for (const name of granted) {
621
- const parsed = parseToolName(name);
622
- if (parsed?.kind !== "mcp-server")
623
- out.add(name);
624
- else
625
- for (const tool of listed(parsed.server))
626
- out.add(mcpToolName(parsed.server, tool));
627
- }
628
- return [...out];
629
- }
630
631
  /** The tools a learned draft may name (learnedWorkflowTools) that the gate allows: `permission` is what the gate holds a
631
632
  * tool to now (tool-gate.ts permissionOf, or the run's gate's policy), by its settings key. One set to ask or deny is left out of `tools`, so the end-of-run prompt never offers it, and named
632
633
  * in `gated` with its setting, which the checker and a learned workflow's check before it runs refuse a draft for. */
633
634
  export const learnedDraftTools = (granted, permission, plane, from, options = {}) => {
634
635
  const gated = {};
635
- // The MCP tools offered because they ask: the ones a learned call's approval card names (#2424).
636
- const asked = [];
637
636
  // Where each deny was set (this agent's settings or this server's), so the refusal names it.
638
637
  const deniedBy = {};
639
638
  const tools = learnedWorkflowTools(granted, plane, options).filter((name) => {
640
639
  const setting = permission(name);
641
- // An MCP tool set to ask is offered where someone can answer: its learned_workflow call asks once, naming its MCP
642
- // tools, before any node runs (#2424). A table tool set to ask is not: its call node can't wait for an approval.
640
+ // An MCP tool set to ask is offered where someone can answer: its learned_workflow call's one card names each of its
641
+ // MCP actions set to ask (learned-workflow.ts learnedAskShown). A table tool set to ask is not: its call node can't
642
+ // wait for an approval.
643
643
  if (setting === "allow")
644
644
  return true;
645
645
  if (setting === "ask" && options.approvers === true && mcpNameOf(name) !== undefined)
646
- return (asked.push(name), true);
646
+ return true;
647
647
  gated[name] = setting;
648
648
  // A deny comes from a layer or the default, never from approvals, which only ever allows.
649
649
  if (setting === "deny" && from)
650
650
  deniedBy[name] = from(name);
651
651
  return false;
652
652
  });
653
- return { tools, gated, deniedBy, asked };
653
+ return { tools, gated, deniedBy };
654
654
  };
655
655
  /** The tools a workflow names (`nodes` from workflowNodes): on its model nodes (`tools`), and on its `call` nodes
656
656
  * `via: "tool"` (`tool`). */
@@ -1,6 +1,12 @@
1
1
  import type { InputIssue } from "./errors.js";
2
2
  import type { SettingsSpec } from "./sealed-settings-store.js";
3
3
  type Json = Record<string, unknown>;
4
+ /** Whether a run `adapter`'s firing starts is handed its trigger's last completed result: the one place it is decided
5
+ * (its previousResult, by default true). */
6
+ export declare const carriesPrevious: (adapter: Pick<TriggerAdapter, "previousResult">) => boolean;
7
+ /** The most of a firing's payload passed on, in bytes of UTF-8 (triggers.ts cuts past it, at a character's start). A
8
+ * source that answers JSON fits its payload within it first (trigger-email.ts), so its JSON is never cut. */
9
+ export declare const PAYLOAD_KEPT_BYTES: number;
4
10
  /** A source as the store keeps it: its kind, the adapter's id, and the adapter's own fields. */
5
11
  export type Source = {
6
12
  kind: string;
@@ -19,19 +25,19 @@ export type TriggerAdapter = {
19
25
  id: string;
20
26
  /** How a person names one: `the <label> "<name>"`, in each run's provenance line. */
21
27
  label: string;
22
- /** `clock`: it fires on its own times, read by the engine's timer. `push`: a request delivered to the server fires it,
28
+ /** `clock`: it fires on its own times, read by the engine's timer (a source that polls, on each). `push`: a request delivered to the server fires it,
23
29
  * keyed by the sender's own id, which a retry repeats. */
24
30
  delivery: "clock" | "push";
31
+ /** Whether a run it starts is handed its trigger's last completed result (trigger-targets.ts previousResultOf). Default
32
+ * true: a repeat run (a schedule's weekly digest) leaves out what the last one reported. false: each firing is a
33
+ * different person's (an email's sender), so one run's answer is never handed to the next. */
34
+ previousResult?: boolean;
25
35
  /** Whether its words are its owner's (a run's message origin `owner`): true only when the owner wrote them as they set
26
36
  * it up; never for words that come from outside. */
27
37
  owner: boolean;
28
38
  /** What it keeps sealed (sealed-settings-store.ts), for the server or for each trigger: a field it mints (a signing secret)
29
39
  * is made at a trigger's create and at a rotation, shown once, and goes with the trigger. */
30
40
  settings?: SettingsSpec;
31
- /** Whether a trigger of this source keeps a secret its sender gave (a create's and a rotation's `secret`, Composio's)
32
- * instead of one this server mints: then the secret is required there, sealed as a minted one is, and never made
33
- * here. Default: it mints. */
34
- givesSecret?(source: Source): boolean;
35
41
  /** Its shapes as a create's error names them: `{kind: "..."}` with its fields. */
36
42
  describe: string;
37
43
  /** When it fires, for the OpenAPI document's source description. */
@@ -57,6 +63,9 @@ export type TriggerAdapter = {
57
63
  /** A pushed source's requests (push-handler.ts), served at /v2/hooks/{trigger_id} when its settings are a trigger's,
58
64
  * else at /v2/hooks/{its id}, with no token: the request's check is its credential. */
59
65
  push?: Push;
66
+ /** For a pushed source whose hook is not the one its settings' scope gives (a source that keeps a key per scope, served
67
+ * at /v2/hooks/{its id}/{scope}): the path under /v2/hooks/ a trigger of `source` is delivered at, its `hook_url`. */
68
+ hookOf?(source: Source): string;
60
69
  /** For a pushed source whose settings are the server's: the scope a trigger of it listens on, matched to each event's
61
70
  * `scope` to find the triggers it fires. */
62
71
  scopeOf?(source: Source): string;
@@ -67,6 +76,73 @@ export type TriggerAdapter = {
67
76
  /** Whether each firing of a trigger of `source` starts its own run, its last run active or not (a webhook that takes
68
77
  * only the events it names). Default false: a firing while the last run is active is skipped. */
69
78
  concurrent?(source: Source): boolean;
79
+ /** For a clock source that polls (the email trigger): what it finds when its time comes, read from outside the server.
80
+ * The engine fires each event it returns through the path a pushed event takes (`takes`, `concurrent`,
81
+ * max_active_runs, the day-kept keys, a run per event), records no `missed` row for a time it was not there for, and
82
+ * keeps the poll's cursor once its firings are recorded. */
83
+ poll?(source: Source, ctx: PollContext): Promise<PollResult>;
84
+ /** For a source that polls: where its trigger starts watching, taken when the trigger is made, when an edit changes one
85
+ * of its source's `on` fields and when it is turned on again; never at its first poll. An edit of any other field keeps
86
+ * the cursor. A start not taken (the source unreachable, or slower than the engine waits) leaves no cursor: the first
87
+ * poll that reads the source takes it, and says so. */
88
+ start?: Start;
89
+ /** A run's title after its trigger's name, from what its source says of the firing (its attrs): an email's sender and
90
+ * subject. Default: the event and action the attrs name. */
91
+ title?(attrs: Record<string, string>): string | undefined;
92
+ };
93
+ /** Why a start is taken: the trigger was made, an edit changed where it reads, or it was turned on again. */
94
+ export type StartWhy = "created" | "edited" | "enabled";
95
+ /** What a start is given: its trigger, why, and the source's credentials, read now (as a poll's). */
96
+ export type StartContext = {
97
+ trigger: string;
98
+ why: StartWhy;
99
+ credentials(): Promise<unknown>;
100
+ };
101
+ /** What a start found: `check`, said on the trigger as its last check (a refusal here never counts toward turning it
102
+ * off); `note`, the history line it writes; `cursor`, the settings it starts from, none when it could not read the
103
+ * source. */
104
+ export type StartResult = {
105
+ check: {
106
+ ok: boolean;
107
+ message: string;
108
+ };
109
+ note: string;
110
+ cursor?: Record<string, string>;
111
+ };
112
+ export type Start = {
113
+ /** The source's fields an edit of which takes a new start. */
114
+ on: readonly string[];
115
+ take(source: Source, ctx: StartContext): Promise<StartResult>;
116
+ /** The words of a start the engine stopped waiting for. */
117
+ unchecked(source: Source, why: StartWhy): string;
118
+ };
119
+ /** What a poll is given: its trigger's own settings (its cursor, public, as the adapter's `settings` names them) and the
120
+ * source's credentials, read now (TriggerDeps.credentials: the email account, opened). */
121
+ export type PollContext = {
122
+ trigger: string;
123
+ setting(field: string): string | undefined;
124
+ credentials(): Promise<unknown>;
125
+ };
126
+ /** One event a poll found: a pushed event's fields; `cursor`, the settings to keep once it and every event before it are
127
+ * recorded; `left`, when it is recorded as skipped and starts nothing, why (in words). */
128
+ export type PolledEvent = PushEvent & {
129
+ cursor: Record<string, string>;
130
+ left?: string;
131
+ };
132
+ /** What a poll found: `check`, said on the trigger as its last check; `refused`, the source's credentials refused (the
133
+ * engine turns the trigger off at the third in a row, `detail` its words); `note`, one history line that starts no run
134
+ * (a first poll's, a reset's); `events`, oldest first; `cursor`, the settings to keep once every event is recorded. */
135
+ export type PollResult = {
136
+ check: {
137
+ ok: boolean;
138
+ message: string;
139
+ };
140
+ refused?: {
141
+ detail: string;
142
+ };
143
+ note?: string;
144
+ events?: PolledEvent[];
145
+ cursor?: Record<string, string>;
70
146
  };
71
147
  /** Request headers, as Node gives them. */
72
148
  export type Headers = Record<string, string | string[] | undefined>;
@@ -77,6 +153,10 @@ export type Push = {
77
153
  maxBodyBytes: number;
78
154
  /** The settings field it checks a request with. */
79
155
  key: string;
156
+ /** For a source whose settings are the server's: it keeps its key per scope (a Composio project's subscription, by its
157
+ * hook), and is served at /v2/hooks/{its id}/{scope} alone, each request checked with that scope's key; its events'
158
+ * `scope` is that scope, for its takes. */
159
+ scoped?: true;
80
160
  /** Why the headers alone are refused, before a byte of the body is read. */
81
161
  headers?(headers: Headers, nowMs: number): string | undefined;
82
162
  /** Why the request is not the sender's under `key`, or undefined when it is (and fits `source`, when given). */
@@ -1,4 +1,10 @@
1
1
  import { unknownFields } from "./validate.js";
2
+ /** Whether a run `adapter`'s firing starts is handed its trigger's last completed result: the one place it is decided
3
+ * (its previousResult, by default true). */
4
+ export const carriesPrevious = (adapter) => adapter.previousResult ?? true;
5
+ /** The most of a firing's payload passed on, in bytes of UTF-8 (triggers.ts cuts past it, at a character's start). A
6
+ * source that answers JSON fits its payload within it first (trigger-email.ts), so its JSON is never cut. */
7
+ export const PAYLOAD_KEPT_BYTES = 16 * 1024;
2
8
  /** A closed object schema: every field in `required` is, and `optional`'s may be. */
3
9
  export const closedSchema = (required, optional = {}) => ({ type: "object", additionalProperties: false, required: Object.keys(required), properties: { ...required, ...optional } });
4
10
  /** `value`'s fields past `allowed`, as issues under `source`. */
@@ -1,4 +1,6 @@
1
+ import { composio } from "./trigger-composio.js";
1
2
  import { schedule } from "./trigger-schedule.js";
2
3
  import { github } from "./trigger-github.js";
3
4
  import { webhook } from "./trigger-webhook.js";
4
- export const TRIGGER_ADAPTERS = [schedule, webhook, github];
5
+ import { email } from "./trigger-email.js";
6
+ export const TRIGGER_ADAPTERS = [schedule, webhook, github, composio, email];
@@ -0,0 +1,10 @@
1
+ import { type TriggerAdapter } from "./trigger-adapter.js";
2
+ /** A Composio trigger slug: upper case, digits and `_` (GITHUB_ISSUE_ADDED_EVENT). */
3
+ export declare const COMPOSIO_EVENT: RegExp;
4
+ /** The id of a project's route here, made once when its subscription is made or moved here. */
5
+ export declare const COMPOSIO_HOOK: RegExp;
6
+ /** The source's field the move of a subscription is asked with: at a create alone, never kept. */
7
+ export declare const MOVE_FIELD = "move_subscription";
8
+ /** The settings field the project's subscription secret is sealed under, one scope per hook. */
9
+ export declare const COMPOSIO_SECRET = "secret";
10
+ export declare const composio: TriggerAdapter;