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

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 (399) hide show
  1. package/CHANGELOG.md +282 -0
  2. package/README.md +155 -92
  3. package/dist/agent-rows.d.ts +1 -1
  4. package/dist/agents-store.d.ts +35 -3
  5. package/dist/agents-store.js +39 -14
  6. package/dist/answer-json.d.ts +34 -1
  7. package/dist/answer-json.js +91 -9
  8. package/dist/api-only.d.ts +1 -1
  9. package/dist/api-only.js +2 -2
  10. package/dist/browser-cost.js +52 -93
  11. package/dist/cap.d.ts +0 -390
  12. package/dist/cap.js +4 -937
  13. package/dist/catalog.js +1 -1
  14. package/dist/composio-preset.d.ts +17 -0
  15. package/dist/composio-preset.js +43 -1
  16. package/dist/computer-calls.d.ts +36 -24
  17. package/dist/computer-calls.js +110 -27
  18. package/dist/computer-live.d.ts +5 -0
  19. package/dist/computer-live.js +12 -0
  20. package/dist/computer-setting.d.ts +15 -2
  21. package/dist/computer-setting.js +20 -4
  22. package/dist/computer-view.d.ts +3 -2
  23. package/dist/computer-view.js +5 -4
  24. package/dist/computer-viewer.js +26 -12
  25. package/dist/computers.d.ts +4 -1
  26. package/dist/computers.js +12 -6
  27. package/dist/console/assets/index-CjqQirbo.css +1 -0
  28. package/dist/console/assets/index-b6-XY5A9.js +576 -0
  29. package/dist/console/index.html +2 -2
  30. package/dist/console-links.d.ts +2 -0
  31. package/dist/console-links.js +3 -0
  32. package/dist/decisions.js +4 -0
  33. package/dist/faux-computers.js +4 -2
  34. package/dist/harness-opencode/adapter.js +7 -3
  35. package/dist/harness-opencode/facts.js +0 -2
  36. package/dist/harness-opencode/host/policy.d.ts +2 -5
  37. package/dist/harness-opencode/host/policy.js +8 -32
  38. package/dist/harness-table.d.ts +0 -2
  39. package/dist/harness-table.js +0 -2
  40. package/dist/host-tools.d.ts +1 -5
  41. package/dist/host-tools.js +7 -10
  42. package/dist/hosted-search.d.ts +0 -2
  43. package/dist/hosted-search.js +0 -21
  44. package/dist/key-words.d.ts +3 -2
  45. package/dist/key-words.js +4 -2
  46. package/dist/learn/check.d.ts +6 -1
  47. package/dist/learn/check.js +12 -4
  48. package/dist/learn/commit.d.ts +10 -0
  49. package/dist/learn/commit.js +18 -4
  50. package/dist/learn/compile.d.ts +243 -0
  51. package/dist/learn/compile.js +471 -0
  52. package/dist/learn/general.d.ts +3 -0
  53. package/dist/learn/general.js +4 -2
  54. package/dist/learn/grade.d.ts +1 -1
  55. package/dist/learn/grade.js +7 -6
  56. package/dist/learn/notes.d.ts +8 -0
  57. package/dist/learn/notes.js +18 -0
  58. package/dist/learn/promote.d.ts +253 -0
  59. package/dist/learn/promote.js +428 -0
  60. package/dist/learn/refit.d.ts +39 -0
  61. package/dist/learn/refit.js +236 -0
  62. package/dist/learn/reflect.d.ts +5 -25
  63. package/dist/learn/reflect.js +14 -131
  64. package/dist/learn/replay-calls.d.ts +63 -0
  65. package/dist/learn/replay-calls.js +158 -0
  66. package/dist/learn/skills.d.ts +17 -9
  67. package/dist/learn/skills.js +132 -42
  68. package/dist/learn/workflow-nodes.d.ts +15 -0
  69. package/dist/learn/workflow-nodes.js +44 -0
  70. package/dist/learned-nodes.d.ts +50 -2
  71. package/dist/learned-nodes.js +41 -2
  72. package/dist/learned-workflow.d.ts +19 -3
  73. package/dist/learned-workflow.js +105 -26
  74. package/dist/learning-batch.d.ts +2 -2
  75. package/dist/learning-batch.js +1 -1
  76. package/dist/learning-cost.d.ts +18 -6
  77. package/dist/learning-cost.js +15 -7
  78. package/dist/learning-routes.d.ts +14 -2
  79. package/dist/learning-routes.js +14 -3
  80. package/dist/learning-words.d.ts +7 -0
  81. package/dist/learning-words.js +7 -0
  82. package/dist/learning.d.ts +31 -6
  83. package/dist/learning.js +7 -4
  84. package/dist/llm.js +0 -3
  85. package/dist/mcp-gateway.d.ts +12 -20
  86. package/dist/mcp-gateway.js +16 -44
  87. package/dist/mcp-oauth.d.ts +5 -0
  88. package/dist/mcp-oauth.js +1 -1
  89. package/dist/mcp-pin-first.d.ts +37 -0
  90. package/dist/mcp-pin-first.js +107 -0
  91. package/dist/mcp-probe.d.ts +8 -9
  92. package/dist/mcp-probe.js +16 -33
  93. package/dist/mcp-servers-store.d.ts +89 -22
  94. package/dist/mcp-servers-store.js +131 -25
  95. package/dist/mcp-sources.d.ts +39 -0
  96. package/dist/mcp-sources.js +74 -0
  97. package/dist/mcp-store.d.ts +11 -0
  98. package/dist/mcp-store.js +16 -2
  99. package/dist/mcp-wire.d.ts +22 -0
  100. package/dist/mcp-wire.js +36 -0
  101. package/dist/mcp.js +3 -3
  102. package/dist/meta-tool-names.d.ts +1 -0
  103. package/dist/meta-tool-names.js +3 -0
  104. package/dist/model.d.ts +13 -0
  105. package/dist/model.js +46 -15
  106. package/dist/monid.d.ts +51 -25
  107. package/dist/monid.js +226 -140
  108. package/dist/openapi.js +336 -66
  109. package/dist/paid-calls.d.ts +26 -29
  110. package/dist/paid-calls.js +46 -102
  111. package/dist/propose.d.ts +7 -1
  112. package/dist/propose.js +18 -6
  113. package/dist/provider.js +9 -2
  114. package/dist/reflect-range.js +2 -1
  115. package/dist/rows.d.ts +5 -3
  116. package/dist/rows.js +15 -4
  117. package/dist/run-launch.d.ts +13 -0
  118. package/dist/run-launch.js +6 -0
  119. package/dist/run-learning-served.d.ts +13 -2
  120. package/dist/run-manifest.d.ts +5 -0
  121. package/dist/run-manifest.js +20 -0
  122. package/dist/run-secrets.js +2 -3
  123. package/dist/run-timeline-served.js +5 -2
  124. package/dist/run-view.d.ts +17 -6
  125. package/dist/run-view.js +51 -22
  126. package/dist/runnable.d.ts +0 -3
  127. package/dist/runnable.js +37 -29
  128. package/dist/runner/adapter-loop.d.ts +24 -10
  129. package/dist/runner/adapter-loop.js +852 -314
  130. package/dist/runner/adapter-run-spec.d.ts +12 -6
  131. package/dist/runner/adapter-run-spec.js +97 -46
  132. package/dist/runner/adapters/pi-computer.d.ts +3 -1
  133. package/dist/runner/adapters/pi-computer.js +13 -5
  134. package/dist/runner/adapters/pi.d.ts +16 -7
  135. package/dist/runner/adapters/pi.js +94 -33
  136. package/dist/runner/cli-run-spec.js +67 -27
  137. package/dist/runner/computer-channel.js +2 -1
  138. package/dist/runner/conformance/harness.d.ts +3 -0
  139. package/dist/runner/conformance/harness.js +145 -4
  140. package/dist/runner/conformance/subject.d.ts +11 -4
  141. package/dist/runner/end-of-run.d.ts +6 -5
  142. package/dist/runner/end-of-run.js +9 -6
  143. package/dist/runner/feedback-round.d.ts +52 -0
  144. package/dist/runner/feedback-round.js +79 -0
  145. package/dist/runner/journal-kinds.d.ts +24 -6
  146. package/dist/runner/journal-kinds.js +15 -0
  147. package/dist/runner/learning-end.d.ts +54 -19
  148. package/dist/runner/learning-end.js +272 -99
  149. package/dist/runner/learning-loop.d.ts +19 -1
  150. package/dist/runner/learning-loop.js +5 -2
  151. package/dist/runner/learning-seed.d.ts +4 -0
  152. package/dist/runner/learning-seed.js +14 -0
  153. package/dist/runner/loop-contract.d.ts +19 -3
  154. package/dist/runner/loop.d.ts +16 -1
  155. package/dist/runner/loop.js +21 -1
  156. package/dist/runner/mcp-claim.d.ts +5 -1
  157. package/dist/runner/mcp-claim.js +66 -50
  158. package/dist/runner/mcp-run.d.ts +16 -52
  159. package/dist/runner/mcp-run.js +12 -84
  160. package/dist/runner/meta-tools.d.ts +37 -0
  161. package/dist/runner/meta-tools.js +268 -0
  162. package/dist/runner/metrics.js +14 -3
  163. package/dist/runner/model-route.js +12 -3
  164. package/dist/runner/monid-run.d.ts +16 -0
  165. package/dist/runner/monid-run.js +96 -0
  166. package/dist/runner/promotion.d.ts +80 -0
  167. package/dist/runner/promotion.js +562 -0
  168. package/dist/runner/reflect-hook.d.ts +36 -21
  169. package/dist/runner/reflect-hook.js +138 -49
  170. package/dist/runner/runner.js +26 -4
  171. package/dist/runner/sessions.d.ts +8 -3
  172. package/dist/runner/sessions.js +5 -1
  173. package/dist/runner/step-guard.d.ts +62 -0
  174. package/dist/runner/step-guard.js +93 -0
  175. package/dist/runner/subagent.d.ts +0 -3
  176. package/dist/runner/subagent.js +7 -12
  177. package/dist/runner/workflow-first.d.ts +216 -0
  178. package/dist/runner/workflow-first.js +303 -0
  179. package/dist/runner/workflow-loop.js +17 -10
  180. package/dist/runner/workflow-spec.d.ts +1 -0
  181. package/dist/runner/workflow-spec.js +7 -3
  182. package/dist/runs-over-store.d.ts +11 -2
  183. package/dist/runs-over-store.js +21 -11
  184. package/dist/server.d.ts +88 -16
  185. package/dist/server.js +380 -87
  186. package/dist/settings-wake.d.ts +8 -6
  187. package/dist/settings-wake.js +13 -7
  188. package/dist/store/agent-body.d.ts +14 -3
  189. package/dist/store/agent-body.js +14 -10
  190. package/dist/store/command-wake.d.ts +3 -2
  191. package/dist/store/command-wake.js +4 -4
  192. package/dist/store/postgres/connection.js +3 -1
  193. package/dist/store/postgres/migrations/0010_imported_templates.sql +18 -0
  194. package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
  195. package/dist/store/schema.d.ts +9 -0
  196. package/dist/store/schema.js +28 -8
  197. package/dist/store/sqlite/connection.d.ts +2 -2
  198. package/dist/store/sqlite/connection.js +2 -2
  199. package/dist/store/sqlite/run-patch.js +19 -7
  200. package/dist/store/sqlite/store.js +59 -18
  201. package/dist/store/store.d.ts +46 -14
  202. package/dist/store-reads/journal.d.ts +25 -1
  203. package/dist/store-reads/journal.js +63 -49
  204. package/dist/store-reads/learning.d.ts +101 -15
  205. package/dist/store-reads/learning.js +195 -61
  206. package/dist/store-reads/loop.d.ts +61 -0
  207. package/dist/store-reads/loop.js +111 -0
  208. package/dist/store-view.d.ts +3 -2
  209. package/dist/store-view.js +35 -17
  210. package/dist/template-eval.d.ts +18 -9
  211. package/dist/template-eval.js +91 -66
  212. package/dist/template-github-permissions.d.ts +2 -2
  213. package/dist/template-github-permissions.js +2 -1
  214. package/dist/template-import.d.ts +31 -0
  215. package/dist/template-import.js +121 -0
  216. package/dist/template-source.d.ts +51 -0
  217. package/dist/template-source.js +371 -0
  218. package/dist/templates.d.ts +218 -46
  219. package/dist/templates.js +493 -181
  220. package/dist/timeline/computer.d.ts +48 -0
  221. package/dist/timeline/computer.js +169 -0
  222. package/dist/timeline/index.d.ts +4 -3
  223. package/dist/timeline/index.js +4 -3
  224. package/dist/timeline/labels.d.ts +6 -2
  225. package/dist/timeline/labels.js +93 -2
  226. package/dist/timeline/origin.d.ts +19 -5
  227. package/dist/timeline/origin.js +11 -4
  228. package/dist/timeline/timeline.d.ts +11 -17
  229. package/dist/timeline/timeline.js +24 -9
  230. package/dist/tool-gate.d.ts +73 -46
  231. package/dist/tool-gate.js +133 -66
  232. package/dist/tool-keys.d.ts +4 -1
  233. package/dist/tool-keys.js +8 -3
  234. package/dist/tool-list.d.ts +26 -0
  235. package/dist/tool-list.js +43 -0
  236. package/dist/tool-names.d.ts +71 -0
  237. package/dist/tool-names.js +99 -0
  238. package/dist/tool-plane.d.ts +29 -27
  239. package/dist/tool-plane.js +65 -37
  240. package/dist/tools.d.ts +22 -6
  241. package/dist/tools.js +24 -20
  242. package/dist/validate.d.ts +15 -7
  243. package/dist/validate.js +91 -44
  244. package/dist/web-fetch.d.ts +1 -7
  245. package/dist/web-fetch.js +2 -22
  246. package/dist/workspace/computer-deps.d.ts +3 -0
  247. package/dist/workspace/computer-deps.js +5 -2
  248. package/dist/workspace/computer-for-claim.d.ts +6 -0
  249. package/dist/workspace/computer-for-claim.js +32 -14
  250. package/dist/workspace/computer-hold.js +7 -1
  251. package/dist/workspace/computer-script.d.ts +23 -7
  252. package/dist/workspace/computer-script.js +48 -14
  253. package/dist/workspace/index.d.ts +2 -2
  254. package/dist/workspace/index.js +1 -1
  255. package/dist/workspace/kind-skills/desktop/SKILL.md +13 -0
  256. package/dist/workspace/kind-skills/phone/SKILL.md +4 -0
  257. package/dist/workspace/local.js +2 -2
  258. package/dist/workspace/resolve-computer.d.ts +21 -1
  259. package/dist/workspace/resolve-computer.js +32 -14
  260. package/dist/workspace/run-tools.d.ts +28 -10
  261. package/dist/workspace/run-tools.js +39 -11
  262. package/dist/{tool-budget.d.ts → wrap-up.d.ts} +1 -18
  263. package/dist/wrap-up.js +21 -0
  264. package/launcher/agentrun-serve +4 -2
  265. package/package.json +9 -9
  266. package/templates/README.md +111 -45
  267. package/templates/code-review/agent.md +30 -14
  268. package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
  269. package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
  270. package/templates/code-review/evals/injection/case.yaml +2 -1
  271. package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
  272. package/templates/code-review/evals/mentions-defused/case.yaml +2 -2
  273. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
  274. package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
  275. package/templates/code-review/evals/never-flag/case.yaml +2 -1
  276. package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
  277. package/templates/code-review/evals/null-name/case.yaml +2 -1
  278. package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
  279. package/templates/code-review/evals/off-by-one/case.yaml +2 -1
  280. package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
  281. package/templates/code-review/evals/other-repo/case.yaml +16 -0
  282. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
  283. package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
  284. package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
  285. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
  286. package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
  287. package/templates/code-review/evals/other-repo/prompt.md +10 -0
  288. package/templates/code-review/evals/re-review/case.yaml +2 -1
  289. package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
  290. package/templates/code-review/evals/re-review-open/case.yaml +2 -1
  291. package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
  292. package/templates/code-review/evals/repo-rule/case.yaml +2 -1
  293. package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
  294. package/templates/code-review/evals/two-defects/case.yaml +2 -1
  295. package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
  296. package/templates/code-review/rules/CODEREVIEW.md +1 -1
  297. package/templates/code-review/skills/review/DEEP.md +3 -2
  298. package/templates/code-review/skills/review/REVIEWER.md +3 -2
  299. package/templates/code-review/skills/review/SKILL.md +4 -3
  300. package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
  301. package/templates/inbound-lead/agent.md +26 -16
  302. package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
  303. package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
  304. package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
  305. package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
  306. package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
  307. package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
  308. package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
  309. package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
  310. package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
  311. package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
  312. package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
  313. package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
  314. package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
  315. package/templates/kyb/agent.md +15 -5
  316. package/templates/kyb/evals/adverse-media/prompt.md +2 -7
  317. package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
  318. package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
  319. package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
  320. package/templates/kyb/evals/name-collision/prompt.md +2 -6
  321. package/templates/kyb/evals/no-invention/prompt.md +2 -6
  322. package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
  323. package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
  324. package/templates/kyb/kyb.schema.json +8 -7
  325. package/templates/kyb/skills/kyb/SKILL.md +9 -6
  326. package/templates/market-monitor/agent.md +19 -12
  327. package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
  328. package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
  329. package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
  330. package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
  331. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  332. package/templates/release-notes/agent.md +32 -10
  333. package/templates/release-notes/evals/draft-not-publish/case.yaml +4 -3
  334. package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
  335. package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
  336. package/templates/release-notes/evals/issue-write-refused/case.yaml +4 -3
  337. package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
  338. package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
  339. package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
  340. package/templates/release-notes/evals/learned-style/case.yaml +2 -1
  341. package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
  342. package/templates/release-notes/evals/other-repo/case.yaml +24 -0
  343. package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
  344. package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
  345. package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
  346. package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
  347. package/templates/release-notes/evals/other-repo/prompt.md +32 -0
  348. package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
  349. package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
  350. package/templates/release-notes/notes.schema.json +1 -1
  351. package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
  352. package/dist/console/assets/index-Cn6JX1uH.js +0 -563
  353. package/dist/console/assets/index-DRN62V5v.css +0 -1
  354. package/dist/tool-blurbs.d.ts +0 -4
  355. package/dist/tool-blurbs.js +0 -28
  356. package/dist/tool-budget.js +0 -62
  357. package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
  358. package/templates/code-review/evals/injection/graders/schema.md +0 -5
  359. package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
  360. package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
  361. package/templates/code-review/evals/null-name/graders/schema.md +0 -5
  362. package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
  363. package/templates/code-review/evals/re-review/graders/schema.md +0 -5
  364. package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
  365. package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
  366. package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
  367. package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
  368. package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
  369. package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
  370. package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
  371. package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
  372. package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
  373. package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
  374. package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
  375. package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
  376. package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
  377. package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
  378. package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
  379. package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
  380. package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
  381. package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
  382. package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
  383. package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
  384. package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
  385. package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
  386. package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
  387. package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
  388. package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
  389. package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
  390. package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
  391. package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
  392. package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
  393. package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
  394. package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
  395. package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
  396. package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
  397. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
  398. package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
  399. package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
@@ -107,6 +107,23 @@ export type Learning = {
107
107
  /** A grader's drop on two answers the host could not read: the last, cut of secrets and in size (UNREAD_MAX), kept on the
108
108
  * run's file to diagnose it by, and served by no read. */
109
109
  unread?: string;
110
+ /** The compile turn's record, when the run's end-of-run turn wrote the agent's job as a learned workflow
111
+ * (learn/compile.ts): the workflow, the notes it absorbed, and each attempt with what the checks refused. */
112
+ compiled?: LearningCompiled;
113
+ /** What the checks refused of a compiled draft that never passed: never silent, on the run's learning and its API. */
114
+ draft_errors?: string[];
115
+ };
116
+ /** A compile turn's record (learn/compile.ts CompiledRecord): `digest`, the kept draft's; `promoted`, read from the agent's
117
+ * promotion records when the run's learning is read, absent while undecided. */
118
+ export type LearningCompiled = {
119
+ workflow: string;
120
+ from_notes: string[];
121
+ attempts: {
122
+ ok: boolean;
123
+ errors: string[];
124
+ }[];
125
+ digest?: string;
126
+ promoted?: boolean;
110
127
  };
111
128
  /** A skill or a workflow draft a merge added or changed. */
112
129
  export type LearnedFile = {
@@ -168,8 +185,8 @@ export declare const learningView: (learning: Learning, shown: Shown, settled: b
168
185
  pending?: NoteUsed[];
169
186
  skills?: LearnedFile[];
170
187
  workflows?: LearnedFile[];
171
- state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
172
- reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
188
+ state: "proposed" | "dropped" | "merged" | "seeded" | "reflecting";
189
+ reason: "cancelled" | "no_budget" | "empty" | "unparsed" | "use" | "seed_failed" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
173
190
  detail: string | null;
174
191
  at: string;
175
192
  };
@@ -183,10 +200,10 @@ export declare function shortOf<T extends {
183
200
  detail: string | null;
184
201
  at: string;
185
202
  }>({ state, reason, detail, at: _, ...notes }: T): {
186
- state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
187
- reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
203
+ state: "proposed" | "dropped" | "merged" | "seeded" | "reflecting";
204
+ reason: "cancelled" | "no_budget" | "empty" | "unparsed" | "use" | "seed_failed" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
188
205
  detail: string | null;
189
- } & Omit<T, "at" | "reason" | "detail" | "state">;
206
+ } & Omit<T, "at" | "reason" | "state" | "detail">;
190
207
  /** The label of the end-of-run turn's timeline rows, and the kind and label of a run's learning row. */
191
208
  export declare const LEARNING_LABEL = "learning";
192
209
  /** A run's proposal, in its directory (propose.ts): the seed it was checked against, each new note's file and text, its
@@ -196,9 +213,12 @@ export declare const LEARNING_LABEL = "learning";
196
213
  export declare const PROPOSAL = "learning-proposal.json";
197
214
  /** A run's proposal: its notes, skill and drafts, each draft's dry run by its workflow.json's path (learn/skills.ts
198
215
  * draftDryRun: passed, or not run and why), the skill of each draft's name as the folder holds it at the seed
199
- * (`drafted`, its SKILL.md: shown to the grader beside the draft, never graded or merged), and what was said in the run. */
216
+ * (`drafted`, its SKILL.md: shown to the grader beside the draft, never graded or merged), and what was said in the run.
217
+ * `bases`: a file whose conflict base is not the seed, by its path: a revised workflow's, the commit of main its compile
218
+ * ask read it at. */
200
219
  export type Proposal = {
201
220
  seed: string;
221
+ bases?: Record<string, string>;
202
222
  notes: {
203
223
  file: string;
204
224
  text: string;
@@ -459,6 +479,11 @@ export declare function chooseSkills(work: Workspace, seed: Seed, own: readonly
459
479
  taken: LearnedSkill[];
460
480
  left: string[];
461
481
  }>;
482
+ /** Whether `text` holds a host secret (`shown`): as written, or, read as JSON, in any string it decodes to (its escapes
483
+ * decoded), or nested past the bound. The one check a learned workflow's text passes at a run's start (chooseWorkflows)
484
+ * and every text its compile turn is told (runner/learning-end.ts compileAskOf); a text that is not JSON is read as
485
+ * written. */
486
+ export declare const holdsSecret: (text: string, shown: Shown) => boolean;
462
487
  /** Which of `seed`'s learned workflows a run may run (its `learned_workflow` tool), in the seed's order: each while its
463
488
  * line (workflowLine) fits what is left of the tool's description budget (LEARNED_WORKFLOWS_BUDGET). One that does not,
464
489
  * or holds a host secret (`shown`), is left out and named in `left`, but for one whose name is itself a secret, never
package/dist/learning.js CHANGED
@@ -34,7 +34,7 @@ import { lstat, readFile, rm } from "node:fs/promises";
34
34
  import { join, posix } from "node:path";
35
35
  import { SKILL_BYTES } from "@parcha/agentrun-kernel";
36
36
  import { bm25, queryOf } from "./learn/relevance.js";
37
- import { decodedStrings, frontMatter, INDEX_BYTES, INDEX_FILE, INDEX_LINES, learnedStatus, loadedIndex, NOTE_FILE, parseNoteFile, learnedSecretShapes, redactLearned, servedSkill, servedSkills, SKILLS_DIR, valueMatcher, WORKFLOW_NAME, WORKFLOWS_DIR } from "./learn/index.js";
37
+ import { decodedStrings, frontMatter, INDEX_BYTES, INDEX_FILE, INDEX_LINES, learnedStatus, loadedIndex, NOTE_FILE, parseNoteFile, learnedSecretShapes, redactLearned, servedSkill, servedSkills, SKILL_NAME, SKILLS_DIR, valueMatcher, WORKFLOW_NAME, WORKFLOWS_DIR } from "./learn/index.js";
38
38
  import { learningInit, learningWorkspace, readSnapshot } from "./learn/folder.js";
39
39
  import { readSeed as readFolderSeed } from "./learn/seed-check.js";
40
40
  import { agentFolderOf, serialBy, writeDurable } from "./files.js";
@@ -241,8 +241,6 @@ function compactSchema(schema, schemas, depth = 0, defs = {}) {
241
241
  export const LEARNED_SKILLS_BUDGET = 256 * 1024;
242
242
  /** Where a run's harness finds its skills in its work: the revision's, and the learned ones laid beside them. */
243
243
  const RUN_SKILLS = [".agents", "skills"];
244
- /** A learned skill's folder: the shared skills convention's name (lowercase letters, digits and single dashes). */
245
- const SKILL_NAME = /^(?=.{1,64}$)[a-z0-9]+(?:-[a-z0-9]+)*$/;
246
244
  /** A file's path inside a learned skill, as every adapter takes one (agentrun-kernel skillProblems). */
247
245
  const SKILL_FILE_PATH = /^(?:[A-Za-z0-9_][A-Za-z0-9._-]{0,99}\/){0,4}[A-Za-z0-9_][A-Za-z0-9._-]{0,99}$/;
248
246
  /** The agent's learning folder: `learning/` in its folder on the disk, which only the host writes. The folder is files.ts
@@ -661,6 +659,11 @@ export async function chooseSkills(work, seed, own, shown) {
661
659
  /** Whether a learned workflow's decoded strings (decodedStrings) hold a host secret, or can't be read past the bound:
662
660
  * either way it is never chosen. */
663
661
  const readsHeld = (decoded, shown) => decoded === "too_deep" || decoded.some(shown.holds);
662
+ /** Whether `text` holds a host secret (`shown`): as written, or, read as JSON, in any string it decodes to (its escapes
663
+ * decoded), or nested past the bound. The one check a learned workflow's text passes at a run's start (chooseWorkflows)
664
+ * and every text its compile turn is told (runner/learning-end.ts compileAskOf); a text that is not JSON is read as
665
+ * written. */
666
+ export const holdsSecret = (text, shown) => shown.holds(text) || readsHeld(decodedStrings(text), shown);
664
667
  /** Which of `seed`'s learned workflows a run may run (its `learned_workflow` tool), in the seed's order: each while its
665
668
  * line (workflowLine) fits what is left of the tool's description budget (LEARNED_WORKFLOWS_BUDGET). One that does not,
666
669
  * or holds a host secret (`shown`), is left out and named in `left`, but for one whose name is itself a secret, never
@@ -671,7 +674,7 @@ export function chooseWorkflows(seed, shown) {
671
674
  let room = LEARNED_WORKFLOWS_BUDGET;
672
675
  for (const flow of seed.workflows ?? []) {
673
676
  // Its JSON read as JSON reads it too (decodedStrings: its escapes decoded, as its learned call's run reads it).
674
- if (shown.holds(flow.workflow) || shown.holds(flow.description) || shown.holds(flow.name) || readsHeld(decodedStrings(flow.workflow), shown)) {
677
+ if (holdsSecret(flow.workflow, shown) || shown.holds(flow.description) || shown.holds(flow.name)) {
675
678
  // Named, but for a name that is itself a secret.
676
679
  if (!shown.holds(flow.name))
677
680
  left.push(flow.name);
package/dist/llm.js CHANGED
@@ -1,4 +1,3 @@
1
- import { sideRequests } from "./cap.js";
2
1
  export const LLM_TOOL = "llm";
3
2
  const MAX_PROMPT = 400_000;
4
3
  /** The completer over `models`, each call on `pick(tier)`'s model at `thinking`. An answer names the model as `named`
@@ -26,8 +25,6 @@ export function completer(models, pick, thinking) {
26
25
  if (!model)
27
26
  throw new Error(`llm: the model ${ref.provider}/${ref.modelId} is not known here`);
28
27
  const context = { ...(system ? { systemPrompt: system } : {}), messages: [{ role: "user", content: prompt, timestamp: Date.now() }] };
29
- // A side request of its own (request-start.ts): its marks name it "llm", never the default a compaction's summary takes.
30
- sideRequests.set(context, { label: LLM_TOOL, extraInputTokens: 0, maxFeeUsd: 0, feeUsd: () => 0 });
31
28
  const message = await models.completeSimple(model, context, { signal, reasoning: thinking, ...(maxTokens ? { maxTokens } : {}) });
32
29
  if (message.stopReason === "error" || message.stopReason === "aborted")
33
30
  throw new Error(`llm: ${message.errorMessage ?? message.stopReason}`);
@@ -1,12 +1,8 @@
1
- import type { McpCallResult, McpTool, SessionMcp } from "@parcha/agentrun-kernel";
1
+ import type { McpCallResult, McpTool } from "@parcha/agentrun-kernel";
2
2
  import { type Workspace } from "./workspace/index.js";
3
- /** A catalog name of an MCP tool: `mcp:<server>/<tool>`. A server name has no `_`, so `mcp__<server>__<tool>` splits one way. */
4
- export declare const MCP_NAME: RegExp;
5
3
  /** The longest answer the model reads whole; past it, the rest is filed in the run's work/ as lines read pages through
6
4
  * (filed-answer.ts). Within the host's result bound (HOST_RESULT_MAX_CHARS), so every harness passes it whole. */
7
5
  export declare const MCP_CLIP = 60000;
8
- /** The most of one upstream answer read. */
9
- export declare const MAX_RESPONSE: number;
10
6
  /** The longest one upstream call may take, and its first connection. */
11
7
  export declare const CALL_MS = 120000;
12
8
  export declare const CONNECT_MS = 30000;
@@ -23,7 +19,7 @@ export type McpCredentials = Record<string, {
23
19
  unopened?: string; /** When its credential ends (ms): a token minted for the run's launch (a github_app server's), whose calls past it are refused unsent, in words. */
24
20
  expires_at?: number;
25
21
  }>;
26
- /** The servers saved on this server, as a claim's pin reads them. */
22
+ /** The servers a save pins from: each one's URL, its tools as it lists them now, and its owner's prices. */
27
23
  export interface McpServerSource {
28
24
  server(name: string): {
29
25
  url: string;
@@ -31,11 +27,6 @@ export interface McpServerSource {
31
27
  prices?: Readonly<Record<string, number>>;
32
28
  } | undefined;
33
29
  }
34
- /** `mcp:<server>/<tool>` read, or undefined for a name that is not one. */
35
- export declare const mcpNameOf: (name: string) => {
36
- server: string;
37
- tool: string;
38
- } | undefined;
39
30
  /** The most schema nodes, and the deepest nesting, a tool's declarations are checked through: past either the tool is
40
31
  * refused, never walked further. */
41
32
  export declare const HEADER_SCAN_NODES = 10000;
@@ -49,10 +40,10 @@ export declare const HEADER_SCAN_DEPTH = 64;
49
40
  * data, never a declaration. Each object is visited once, from an explicit stack, within HEADER_SCAN_NODES and
50
41
  * HEADER_SCAN_DEPTH. */
51
42
  export declare function mcpHeaderProblem(inputSchema: unknown): string | undefined;
52
- /** The pin of a run granted `names`: each MCP tool among them, as its server's snapshot holds it. Keyed by server name
53
- * with no prototype, as every map of names here is: a server named `constructor` is a server like any other. A granted
54
- * tool that cannot be pinned (its server no longer saved, the tool gone since a refresh, a header declaration it cannot
55
- * send) throws, naming it and why: the run is refused, never started without it. */
43
+ /** The pin of a revision granted `names`: each MCP tool among them, as its server lists it (the save's listing). Keyed by
44
+ * server name with no prototype, as every map of names here is: a server named `constructor` is a server like any
45
+ * other. A granted tool that cannot be pinned (its server not saved, a tool it does not list, a header declaration it
46
+ * cannot send) throws, naming it and why: the save is refused, never kept without it. */
56
47
  export declare function mcpPinOf(names: readonly string[], source: McpServerSource): McpPin;
57
48
  export interface McpGatewayOptions {
58
49
  pin: McpPin;
@@ -81,18 +72,19 @@ export interface McpGatewayOptions {
81
72
  /** The claim's per-call check of a server's credential (its custody stamp): awaited before each call is checked for
82
73
  * sending, it may drop the credential (`credentials[server].unopened`), which the call then refuses unsent; one that
83
74
  * throws (a store read failed, the call was stopped) refuses the call unsent too, in words, and the run goes on. Only
84
- * the runner's MCP claim step passes it: a github_app token whose App was disconnected or replaced. A CLI harness's
85
- * session proxy ends in the same call. */
75
+ * the runner's MCP claim step passes it: a github_app token whose App was disconnected or replaced. */
86
76
  beforeCall?: (server: string, signal: AbortSignal) => Promise<void>;
87
77
  }
88
78
  /** A run's journal commit. */
89
79
  export type McpCommit = <T>(change: (tx: unknown) => Promise<T>) => Promise<T>;
90
- /** What a call with no call id answers where a gate must know it by one: nothing was sent. */
91
- export declare const noCallId: (name: string) => string;
92
80
  /** The gateway: a session's servers, and their calls. `credentials` is read at every call and every request, never
93
81
  * copied: a change the claim step makes after (a token refreshed behind the claim, a server removed) reaches it, even
94
82
  * through a client already connected. */
95
- export type McpGateway = Omit<SessionMcp, "call"> & {
83
+ export type McpGateway = {
84
+ servers: readonly {
85
+ name: string;
86
+ tools: readonly McpTool[];
87
+ }[];
96
88
  call(server: string, tool: string, args: Record<string, unknown>, context: {
97
89
  signal: AbortSignal;
98
90
  callId?: string;
@@ -1,8 +1,8 @@
1
1
  // A run's remote MCP servers: the one place every harness's MCP call goes through. A claimed run's spec builds one per
2
- // claim from its MCP claim step (runner/mcp-run.ts mcpForClaim); pi calls it through the runner's host tools, and a
3
- // harness with its own MCP client through the session proxy's /mcp/<server> (@parcha/agentrun-kernel/host mcpRoute).
4
- // - What a run may call is pinned (mcpPinOf): each granted tool as the server listed it when its owner saved it, and
5
- // the server's URL then. A later refresh of the server never changes a running agent's tools.
2
+ // claim from its MCP claim step (runner/mcp-run.ts mcpForClaim); every harness calls it through the runner's host tools.
3
+ // - What a run may call is pinned (mcpPinOf) when its agent's revision is saved: each granted tool as its server listed
4
+ // it then, and the server's URL then. A later change or refresh of the server never changes the revision's tools;
5
+ // saving the agent again pins them anew.
6
6
  // - Its credentials come from the claim step, only for the servers it grants, with each server's URL now, read at every
7
7
  // call and every request: one whose URL is not the pinned one is never sent anything.
8
8
  // - One upstream client per server (the official SDK), connected at its first call; no redirect is followed, so a
@@ -22,23 +22,15 @@ import { filedAnswer } from "./filed-answer.js";
22
22
  import { paidLedger, paidStep } from "./paid-calls.js";
23
23
  import { metaToolOf } from "./mcp-meta.js";
24
24
  import { SIGN_IN_AGAIN } from "./mcp-oauth.js";
25
- import { mcpToolName } from "./tool-gate.js";
25
+ import { capped, mcpClient, scrub } from "./mcp-wire.js";
26
+ import { mcpNameOf, mcpToolName } from "./tool-names.js";
26
27
  import { workspaceAt, workspaceErrorWords } from "./workspace/index.js";
27
- /** A catalog name of an MCP tool: `mcp:<server>/<tool>`. A server name has no `_`, so `mcp__<server>__<tool>` splits one way. */
28
- export const MCP_NAME = /^mcp:([a-z][a-z0-9-]{0,31})\/([A-Za-z0-9_-]{1,64})$/;
29
28
  /** The longest answer the model reads whole; past it, the rest is filed in the run's work/ as lines read pages through
30
29
  * (filed-answer.ts). Within the host's result bound (HOST_RESULT_MAX_CHARS), so every harness passes it whole. */
31
30
  export const MCP_CLIP = 60_000;
32
- /** The most of one upstream answer read. */
33
- export const MAX_RESPONSE = 4 * 1024 * 1024;
34
31
  /** The longest one upstream call may take, and its first connection. */
35
32
  export const CALL_MS = 120_000;
36
33
  export const CONNECT_MS = 30_000;
37
- /** `mcp:<server>/<tool>` read, or undefined for a name that is not one. */
38
- export const mcpNameOf = (name) => {
39
- const match = MCP_NAME.exec(name);
40
- return match ? { server: match[1], tool: match[2] } : undefined;
41
- };
42
34
  /** The most schema nodes, and the deepest nesting, a tool's declarations are checked through: past either the tool is
43
35
  * refused, never walked further. */
44
36
  export const HEADER_SCAN_NODES = 10_000;
@@ -107,10 +99,10 @@ export function mcpHeaderProblem(inputSchema) {
107
99
  }
108
100
  return undefined;
109
101
  }
110
- /** The pin of a run granted `names`: each MCP tool among them, as its server's snapshot holds it. Keyed by server name
111
- * with no prototype, as every map of names here is: a server named `constructor` is a server like any other. A granted
112
- * tool that cannot be pinned (its server no longer saved, the tool gone since a refresh, a header declaration it cannot
113
- * send) throws, naming it and why: the run is refused, never started without it. */
102
+ /** The pin of a revision granted `names`: each MCP tool among them, as its server lists it (the save's listing). Keyed by
103
+ * server name with no prototype, as every map of names here is: a server named `constructor` is a server like any
104
+ * other. A granted tool that cannot be pinned (its server not saved, a tool it does not list, a header declaration it
105
+ * cannot send) throws, naming it and why: the save is refused, never kept without it. */
114
106
  export function mcpPinOf(names, source) {
115
107
  const pin = Object.create(null);
116
108
  for (const name of names) {
@@ -119,11 +111,11 @@ export function mcpPinOf(names, source) {
119
111
  const tool = saved?.tools.find((t) => t.name === parsed.tool);
120
112
  if (!parsed)
121
113
  continue;
122
- // Gone since the run's check (deleted, or a refresh removed the tool): the run is refused, never started without it.
114
+ // Gone since the save's check (deleted, or the server stopped listing the tool): the save is refused.
123
115
  if (!saved)
124
- throw new Error(`The MCP tool ${name} cannot be pinned: the MCP server ${parsed.server} is no longer saved.`);
116
+ throw new Error(`The MCP tool ${name} cannot be pinned: no MCP server ${parsed.server} is saved.`);
125
117
  if (!tool)
126
- throw new Error(`The MCP tool ${name} cannot be pinned: ${parsed.tool} is no longer one of its tools since the last refresh.`);
118
+ throw new Error(`The MCP tool ${name} cannot be pinned: the MCP server ${parsed.server} does not list ${parsed.tool}.`);
127
119
  // A meta tool granted before the rule (mcp-meta.ts): refused here, never run.
128
120
  const meta = metaToolOf(saved.url, tool.name);
129
121
  if (meta)
@@ -183,10 +175,6 @@ function unreachable(error) {
183
175
  return deepest;
184
176
  }
185
177
  const said = (text, isError = false) => ({ content: [{ type: "text", text }], ...(isError ? { isError: true } : {}) });
186
- /** `text` with every credential value in `values` replaced, whole and as its bare token (with any one-word scheme, such
187
- * as `Bearer ` or `Basic `, taken off): an upstream answer or error that echoes a header, or only its token, never shows
188
- * it to the model, the harness or the run's files. */
189
- const scrub = (text, values) => [...values].flatMap((value) => [value, value.replace(/^[A-Za-z][A-Za-z0-9_-]*\s+(?=\S+$)/, "")]).sort((a, b) => b.length - a.length).reduce((out, value) => (value.length >= 8 ? out.split(value).join("[redacted]") : out), text);
190
178
  /** `work` until `signal` aborts: a connection shared by calls is never held by one that stopped. */
191
179
  const until = (work, signal) => new Promise((resolve, reject) => {
192
180
  if (signal.aborted)
@@ -195,8 +183,6 @@ const until = (work, signal) => new Promise((resolve, reject) => {
195
183
  signal.addEventListener("abort", stop, { once: true });
196
184
  work.then(resolve, reject).finally(() => signal.removeEventListener("abort", stop));
197
185
  });
198
- /** What a call with no call id answers where a gate must know it by one: nothing was sent. */
199
- export const noCallId = (name) => `The ${name} call was not sent: it came with no call id, so it cannot wait for a person's approval.`;
200
186
  export function mcpGateway(options) {
201
187
  const clients = new Map();
202
188
  const pins = new Map(Object.entries(options.pin));
@@ -256,19 +242,7 @@ export function mcpGateway(options) {
256
242
  status.last = response.status;
257
243
  if (response.status >= 300 && response.status < 400)
258
244
  throw new Error(`it answered a redirect (HTTP ${response.status}), which is never followed`);
259
- if (!response.body)
260
- return response;
261
- let read = 0;
262
- const capped = response.body.pipeThrough(new TransformStream({
263
- transform(chunk, controller) {
264
- read += chunk.byteLength;
265
- if (read > MAX_RESPONSE)
266
- controller.error(new Error(`its answer is longer than ${MAX_RESPONSE} bytes`));
267
- else
268
- controller.enqueue(chunk);
269
- },
270
- }));
271
- return new Response(capped, { status: response.status, statusText: response.statusText, headers: response.headers });
245
+ return capped(response);
272
246
  };
273
247
  const connect = (server, url, headers) => {
274
248
  let upstream = clients.get(server);
@@ -276,10 +250,8 @@ export function mcpGateway(options) {
276
250
  const status = {};
277
251
  statuses.set(server, status);
278
252
  upstream = (async () => {
279
- const { Client, StreamableHTTPClientTransport } = await import("@modelcontextprotocol/client");
280
- // The 2026-07-28 revision first, a 2025-era server through its initialize, as a preview connects.
281
- const client = new Client({ name: "agentrun", version: "1.0.0" }, { capabilities: {}, versionNegotiation: { mode: "auto" } });
282
- await client.connect(new StreamableHTTPClientTransport(new URL(url), { fetch: guarded(server, () => credentials.get(server)?.headers ?? {}, status) }), { timeout: options.bounds?.connectMs ?? CONNECT_MS });
253
+ const { client, transport } = mcpClient(await import("@modelcontextprotocol/client"), { name: "agentrun", version: "1.0.0", url: new URL(url), fetch: guarded(server, () => credentials.get(server)?.headers ?? {}, status) });
254
+ await client.connect(transport, { timeout: options.bounds?.connectMs ?? CONNECT_MS });
283
255
  return client;
284
256
  })();
285
257
  clients.set(server, upstream);
@@ -1,4 +1,5 @@
1
1
  import type { OAuthClientMetadata, OAuthDiscoveryState, OAuthTokens, StoredOAuthClientInformation } from "@modelcontextprotocol/client";
2
+ import type { SourceRecord } from "./mcp-sources.js";
2
3
  /** The authorization server sends the owner's browser back here; it holds no credential, so it takes none. */
3
4
  export declare const OAUTH_CALLBACK = "/v2/settings/mcp-servers/oauth/callback";
4
5
  /** This server's client metadata document, its client id where the authorization server takes one (CIMD). */
@@ -26,6 +27,8 @@ export type TokenSet = {
26
27
  };
27
28
  /** `keptFor`: the authorization server (its issuer) a client kept from an earlier sign-in was registered at; the client is
28
29
  * used again only when discovery finds that same one (else it is dropped, and the sign-in registers anew). */
30
+ /** `source`: what the start said the server is (its source and toolkit, mcp-sources.ts), written for the row the sign-in
31
+ * saves. */
29
32
  export type Pending = {
30
33
  name: string;
31
34
  url: string;
@@ -37,6 +40,7 @@ export type Pending = {
37
40
  verifier?: string;
38
41
  discovery?: OAuthDiscoveryState;
39
42
  resource?: string;
43
+ source?: SourceRecord;
40
44
  expires: number;
41
45
  };
42
46
  /** The authorization server a discovery found, by its issuer (its metadata's, else its URL). */
@@ -189,6 +193,7 @@ export declare class McpSignIns {
189
193
  client?: StoredOAuthClientInformation;
190
194
  kind?: ClientKind;
191
195
  keptFor?: string;
196
+ source?: SourceRecord;
192
197
  }): Promise<string>;
193
198
  /** The callback's sign-in, by its state, from the pending store: once, and only within ten minutes of its start. `was`
194
199
  * is the server's save when it started (null for none), so a sign-in the owner since replaced or forgot is not
package/dist/mcp-oauth.js CHANGED
@@ -358,7 +358,7 @@ export class McpSignIns {
358
358
  async start(name, url, options) {
359
359
  const now = Date.now();
360
360
  const state = randomBytes(32).toString("base64url");
361
- const entry = { name, url: url.href, was: options.was, ...(options.scope ? { scope: options.scope } : {}), kind: options.kind ?? "dynamic", ...(options.client ? { client: options.client } : {}), ...(options.keptFor ? { keptFor: options.keptFor } : {}), expires: now + STATE_MS };
361
+ const entry = { name, url: url.href, was: options.was, ...(options.scope ? { scope: options.scope } : {}), kind: options.kind ?? "dynamic", ...(options.client ? { client: options.client } : {}), ...(options.keptFor ? { keptFor: options.keptFor } : {}), ...(options.source ? { source: options.source } : {}), expires: now + STATE_MS };
362
362
  let opened;
363
363
  const seen = {};
364
364
  const reach = { own: this.own, allowed: await this.allowed(), loopback: this.loopback };
@@ -0,0 +1,37 @@
1
+ import { type McpPin } from "./mcp-gateway.js";
2
+ import type { OAuthNetwork } from "./mcp-oauth.js";
3
+ import { type McpServersOverStore, mcpServersOverStore } from "./mcp-servers-store.js";
4
+ import { type GithubAppAccess } from "./runner/mcp-github.js";
5
+ /** One server's listing as a save pins it (McpServersOverStore.pinListing); undefined when no such server is saved. */
6
+ export type PinListing = Awaited<ReturnType<McpServersOverStore["pinListing"]>>;
7
+ export interface PinFirstDeps {
8
+ /** Whether a server of this name is saved here: a grant of one that is not leaves the revision unpinned, to the run's
9
+ * own refusal, so the pin is made whole once the server is saved again. */
10
+ saved(server: string): boolean | Promise<boolean>;
11
+ /** The server's listing now, as a save lists it; throws when it can't be listed. */
12
+ pinListing(server: string): Promise<PinListing>;
13
+ /** Agents.pinOnce: `pin` written only while the revision has none; the pin it has then. */
14
+ pinOnce(revisionId: string, pin: McpPin): Promise<unknown>;
15
+ }
16
+ /** The revision's MCP pin: its own when it has one; else, when every server it grants a tool of is saved here and lists
17
+ * it, the pin made now of all of them and kept on it (or the one another first run kept first). Undefined when it grants
18
+ * none, or when one such server is not saved, can't be listed or no longer lists a granted tool: nothing is written (a
19
+ * pin of the other servers alone would stand for good, its missing tool never pinned), and the run is refused in the
20
+ * words it was (server.ts runnable at a start, the claim's own at a claim). */
21
+ export declare function pinFirst(revision: {
22
+ readonly id: string;
23
+ readonly kind: string;
24
+ readonly body: unknown;
25
+ readonly mcpPin?: unknown;
26
+ }, deps: PinFirstDeps): Promise<McpPin | undefined>;
27
+ /** A runner's pinListing (PinFirstDeps): the owner's registry over the one store, opened with the runner's seal key (the
28
+ * server's) on the first listing it is asked for, loopback allowed only for a runner beside a local install. `githubApp`:
29
+ * the run's GitHub App access (runner/mcp-github.ts), which lists a `github_app` server with a token of the run's
30
+ * repository, metadata read alone, as a save lists it with one (github-connection.ts tokenForListing); without it such a
31
+ * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). */
32
+ export declare function registryListing(store: Parameters<typeof mcpServersOverStore>[0], sealKey: Buffer, { loopback, network, githubApp, appOrigin }?: {
33
+ loopback?: boolean;
34
+ network?: OAuthNetwork;
35
+ githubApp?: GithubAppAccess;
36
+ appOrigin?: string;
37
+ }): (server: string, stop?: AbortSignal) => Promise<PinListing>;
@@ -0,0 +1,107 @@
1
+ // A revision saved with no MCP pin (before pins were made at save, or an inline agent's version stored then) is pinned
2
+ // once, at its first run, as a save would pin it: each granted server still saved here listed once
3
+ // (McpServersOverStore.pinListing, the save's own listing), the pin made of those listings (mcp-gateway.ts mcpPinOf), and
4
+ // written only while the revision still has none (Agents.pinOnce), the pin that stood read back. One path for a run's
5
+ // start (server.ts, before runnable) and a run's claim (runner/mcp-claim.ts, for a run that already existed when the
6
+ // store was upgraded): two first runs, or a start and a claim, at once agree on one pin. Nothing moves from a run's old
7
+ // per-run pin (mcp_pins, dropped at the upgrade): the revision's pin is the one every run of it reads.
8
+ import { readFile } from "node:fs/promises";
9
+ import { mcpPinOf } from "./mcp-gateway.js";
10
+ import { boundTool } from "./mcp-probe.js";
11
+ import { mcpServersOverStore } from "./mcp-servers-store.js";
12
+ import { SEAL_KEY_ENV } from "./tool-keys.js";
13
+ import { mcpNameOf } from "./tool-names.js";
14
+ import { GITHUB_UNUSABLE } from "./runner/mcp-github.js";
15
+ /** The revision's MCP pin: its own when it has one; else, when every server it grants a tool of is saved here and lists
16
+ * it, the pin made now of all of them and kept on it (or the one another first run kept first). Undefined when it grants
17
+ * none, or when one such server is not saved, can't be listed or no longer lists a granted tool: nothing is written (a
18
+ * pin of the other servers alone would stand for good, its missing tool never pinned), and the run is refused in the
19
+ * words it was (server.ts runnable at a start, the claim's own at a claim). */
20
+ export async function pinFirst(revision, deps) {
21
+ if (revision.mcpPin !== undefined && revision.mcpPin !== null)
22
+ return revision.mcpPin;
23
+ if (revision.kind !== "agentic")
24
+ return undefined;
25
+ const granted = [];
26
+ for (const tool of revision.body.tools ?? []) {
27
+ const named = mcpNameOf(tool);
28
+ if (!named)
29
+ continue;
30
+ if (!(await deps.saved(named.server)))
31
+ return undefined;
32
+ granted.push(tool);
33
+ }
34
+ if (!granted.length)
35
+ return undefined;
36
+ const listings = new Map();
37
+ try {
38
+ await Promise.all([...new Set(granted.map((tool) => mcpNameOf(tool).server))].map(async (server) => {
39
+ const listing = await deps.pinListing(server);
40
+ if (!listing)
41
+ throw new Error(`${server} is no longer saved`);
42
+ listings.set(server, listing);
43
+ }));
44
+ }
45
+ catch {
46
+ return undefined;
47
+ }
48
+ let pin;
49
+ try {
50
+ pin = mcpPinOf(granted, { server: (name) => { const listing = listings.get(name); return listing && { url: listing.url, tools: listing.tools.map(boundTool), prices: listing.prices }; } });
51
+ }
52
+ catch {
53
+ return undefined;
54
+ }
55
+ if (!Object.keys(pin).length)
56
+ return undefined;
57
+ return ((await deps.pinOnce(revision.id, pin)) ?? undefined);
58
+ }
59
+ /** A runner's pinListing (PinFirstDeps): the owner's registry over the one store, opened with the runner's seal key (the
60
+ * server's) on the first listing it is asked for, loopback allowed only for a runner beside a local install. `githubApp`:
61
+ * the run's GitHub App access (runner/mcp-github.ts), which lists a `github_app` server with a token of the run's
62
+ * repository, metadata read alone, as a save lists it with one (github-connection.ts tokenForListing); without it such a
63
+ * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). */
64
+ export function registryListing(store, sealKey, { loopback = false, network, githubApp, appOrigin } = {}) {
65
+ let registry;
66
+ // The listing tokens minted and not yet revoked, and how many listings are under way: no one holds a listing token
67
+ // after its listing (the claim's cleanup reaches only githubTokens' tokens), so once no listing is under way, each is
68
+ // revoked at GitHub, whether the listing answered or failed.
69
+ const minted = [];
70
+ let listing = 0;
71
+ const open = async () => {
72
+ const { version } = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
73
+ const opened = mcpServersOverStore(store, { [SEAL_KEY_ENV]: sealKey.toString("base64") }, version, network);
74
+ opened.attach("", "", loopback);
75
+ if (appOrigin)
76
+ opened.appOrigin = appOrigin;
77
+ if (githubApp)
78
+ opened.appToken = async () => {
79
+ const got = await listingToken(githubApp);
80
+ if ("token" in got)
81
+ minted.push(got.token);
82
+ return got;
83
+ };
84
+ return opened;
85
+ };
86
+ return async (server, stop) => {
87
+ listing += 1;
88
+ try {
89
+ return await (await (registry ??= open())).pinListing(server, stop);
90
+ }
91
+ finally {
92
+ listing -= 1;
93
+ if (!listing)
94
+ await Promise.all(minted.splice(0).map((token) => githubApp?.revoke?.(token).catch(() => undefined)));
95
+ }
96
+ };
97
+ }
98
+ /** A token to list a github_app server's tools with, from the run's App access: its repository, metadata read alone; or
99
+ * why there is none, in the words its calls would be refused in. */
100
+ async function listingToken(access) {
101
+ if (!access.target)
102
+ return { unusable: GITHUB_UNUSABLE.noRepo };
103
+ const minted = await access.mint(access.target, { metadata: "read" });
104
+ if (minted.ok)
105
+ return { token: minted.token };
106
+ return minted.reason === "github_failed" ? { failed: minted.message } : { unusable: minted.message };
107
+ }
@@ -1,5 +1,4 @@
1
1
  import { ApiError, type InputIssue } from "./errors.js";
2
- export declare const MCP_SERVER_NAME: RegExp;
3
2
  /** `per_run`: the server keeps no credential; each run's caller hands one with the run (mcp_auth), held for that run alone. */
4
3
  export declare const MCP_AUTH_TYPES: readonly ["none", "bearer", "headers", "oauth", "github_app", "per_run"];
5
4
  /** Why a saved credential can't be used for a run's calls, each with its own remedy and no other, as the model reads it
@@ -65,18 +64,18 @@ export declare const nameOf: (name: string) => void;
65
64
  export declare function pricesListed(prices: McpPrices | undefined, listed: readonly {
66
65
  name: string;
67
66
  }[]): McpPrices;
68
- /** `listed` with each known meta tool (mcp-meta.ts) marked `grantable: false` with its reason. */
69
- export declare function marked<T extends {
70
- tools: McpTool[];
67
+ /** `listed` with each known meta tool (mcp-meta.ts) marked `grantable: false` with its reason: the one place a listing is
68
+ * marked, in the registry's shape of a tool or the harnesses' (a saved server's tools read by blockersOf). */
69
+ export declare function marked<Tool extends {
70
+ name: string;
71
+ }, T extends {
72
+ tools: Tool[];
71
73
  }>(url: string, listed: T): T & {
72
- tools: (McpTool & {
74
+ tools: (Tool & {
73
75
  grantable?: false;
74
76
  reason?: string;
75
77
  })[];
76
78
  };
77
- /** `text` with every credential value cut out: each header's value, and a bearer's token alone, which a server may
78
- * echo without its scheme. */
79
- export declare const scrub: (text: string, headers: HeaderMap) => string;
80
79
  /** JSON with sorted keys, so two listings of one tool compare equal whatever order the server sends its fields in. */
81
80
  export declare const canonical: (value: unknown) => string;
82
81
  /** The body's prices: each tool's USD a call, a finite number, 0 or more. Which tools the server lists is checked once
@@ -112,7 +111,7 @@ export declare const MAX_OAUTH_VALUE_BYTES = 8192;
112
111
  /** Whether an OAuth client id or secret a sign-in body sends is well formed (text, not empty, no control, within the cap). */
113
112
  export declare const oauthValueValid: (text: unknown) => boolean;
114
113
  /** Connect to `url`, agree a protocol revision, and list every tool (all pages), each request held to REQUEST_MS and
115
- * MAX_RESPONSE_BYTES and the whole to PREVIEW_MS. A failure is an ApiError: 422 auth_required (with the auth the
114
+ * MAX_RESPONSE and the whole to PREVIEW_MS. A failure is an ApiError: 422 auth_required (with the auth the
116
115
  * server asks for), 422 not_mcp, 422 input_invalid for a redirect, else 424 upstream_failed. `send`: how each request
117
116
  * goes, the store-backed registry's dialled at the address its check let through (mcp-oauth.ts mcpServerAt, dialAt). */
118
117
  export declare function listServer(url: URL, headers: HeaderMap, version: string, stop?: AbortSignal, send?: typeof fetch): Promise<Listed>;