@parcha/agentrun-serve 0.1.0-beta.37 → 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 (620) hide show
  1. package/CHANGELOG.md +700 -0
  2. package/README.md +441 -177
  3. package/dist/adapters.d.ts +4 -1
  4. package/dist/adapters.js +4 -2
  5. package/dist/agent-rows.d.ts +1 -3
  6. package/dist/agents-store.d.ts +35 -3
  7. package/dist/agents-store.js +48 -23
  8. package/dist/answer-json.d.ts +34 -1
  9. package/dist/answer-json.js +91 -9
  10. package/dist/api-only.d.ts +1 -1
  11. package/dist/api-only.js +2 -2
  12. package/dist/bash-read-only.js +2 -1
  13. package/dist/browser-cost.js +52 -93
  14. package/dist/cap-short.d.ts +12 -0
  15. package/dist/cap-short.js +60 -0
  16. package/dist/cap.d.ts +3 -400
  17. package/dist/cap.js +6 -942
  18. package/dist/catalog.d.ts +0 -5
  19. package/dist/catalog.js +2 -6
  20. package/dist/chatgpt-plan.d.ts +163 -0
  21. package/dist/chatgpt-plan.js +549 -0
  22. package/dist/cli.js +26 -6
  23. package/dist/composio-preset.d.ts +25 -0
  24. package/dist/composio-preset.js +51 -8
  25. package/dist/composio-triggers.d.ts +113 -0
  26. package/dist/composio-triggers.js +411 -0
  27. package/dist/computer-calls.d.ts +36 -24
  28. package/dist/computer-calls.js +110 -27
  29. package/dist/computer-commands.d.ts +2 -0
  30. package/dist/computer-commands.js +7 -3
  31. package/dist/computer-live.d.ts +12 -2
  32. package/dist/computer-live.js +21 -5
  33. package/dist/computer-routes.d.ts +2 -2
  34. package/dist/computer-routes.js +2 -2
  35. package/dist/computer-setting.d.ts +15 -2
  36. package/dist/computer-setting.js +20 -4
  37. package/dist/computer-view.d.ts +18 -2
  38. package/dist/computer-view.js +21 -6
  39. package/dist/computer-viewer.js +40 -13
  40. package/dist/computers.d.ts +8 -2
  41. package/dist/computers.js +18 -8
  42. package/dist/console/assets/index-BNhZs-jp.css +1 -0
  43. package/dist/console/assets/index-BQv5aOGB.js +700 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/console-links.d.ts +2 -0
  46. package/dist/console-links.js +6 -3
  47. package/dist/decision-cap.d.ts +2 -5
  48. package/dist/decision-cap.js +3 -6
  49. package/dist/decision-rows.js +11 -11
  50. package/dist/decisions.js +4 -0
  51. package/dist/email/account.d.ts +84 -0
  52. package/dist/email/account.js +159 -0
  53. package/dist/email/answer.d.ts +10 -0
  54. package/dist/email/answer.js +182 -0
  55. package/dist/email/email-faux.d.ts +95 -0
  56. package/dist/email/email-faux.js +849 -0
  57. package/dist/email/labels.d.ts +1 -0
  58. package/dist/email/labels.js +84 -0
  59. package/dist/email/mail.d.ts +186 -0
  60. package/dist/email/mail.js +380 -0
  61. package/dist/email/names.d.ts +20 -0
  62. package/dist/email/names.js +40 -0
  63. package/dist/email/routes.d.ts +9 -0
  64. package/dist/email/routes.js +50 -0
  65. package/dist/email/tools.d.ts +20 -0
  66. package/dist/email/tools.js +517 -0
  67. package/dist/environment.d.ts +17 -2
  68. package/dist/environment.js +36 -8
  69. package/dist/errors.d.ts +6 -0
  70. package/dist/errors.js +12 -0
  71. package/dist/eval-mailbox.d.ts +103 -0
  72. package/dist/eval-mailbox.js +236 -0
  73. package/dist/faux-computers.js +4 -2
  74. package/dist/graph-view.d.ts +9 -2
  75. package/dist/graph-view.js +6 -2
  76. package/dist/harness-install.d.ts +28 -2
  77. package/dist/harness-install.js +147 -59
  78. package/dist/harness-opencode/adapter.js +2 -22
  79. package/dist/harness-opencode/facts.js +5 -4
  80. package/dist/harness-opencode/host/policy.d.ts +4 -5
  81. package/dist/harness-opencode/host/policy.js +14 -33
  82. package/dist/harness-opencode/index.d.ts +1 -1
  83. package/dist/harness-opencode/index.js +1 -1
  84. package/dist/harness-opencode/versions.d.ts +6 -0
  85. package/dist/harness-opencode/versions.js +6 -0
  86. package/dist/harness-table.d.ts +0 -2
  87. package/dist/harness-table.js +8 -7
  88. package/dist/harness.d.ts +12 -0
  89. package/dist/harness.js +15 -3
  90. package/dist/host-tools.d.ts +1 -5
  91. package/dist/host-tools.js +7 -10
  92. package/dist/hosted-search.d.ts +3 -3
  93. package/dist/hosted-search.js +51 -32
  94. package/dist/import-sources.d.ts +1 -1
  95. package/dist/import-sources.js +3 -3
  96. package/dist/import.d.ts +21 -0
  97. package/dist/import.js +186 -1
  98. package/dist/key-check.d.ts +0 -2
  99. package/dist/key-check.js +3 -4
  100. package/dist/key-refusal.d.ts +8 -2
  101. package/dist/key-refusal.js +16 -13
  102. package/dist/key-words.d.ts +3 -2
  103. package/dist/key-words.js +4 -2
  104. package/dist/learn/check.d.ts +24 -4
  105. package/dist/learn/check.js +340 -7
  106. package/dist/learn/commit.d.ts +10 -0
  107. package/dist/learn/commit.js +18 -4
  108. package/dist/learn/compile.d.ts +250 -0
  109. package/dist/learn/compile.js +507 -0
  110. package/dist/learn/general.d.ts +3 -0
  111. package/dist/learn/general.js +4 -2
  112. package/dist/learn/grade.d.ts +5 -1
  113. package/dist/learn/grade.js +11 -7
  114. package/dist/learn/notes.d.ts +8 -0
  115. package/dist/learn/notes.js +18 -0
  116. package/dist/learn/promote.d.ts +308 -0
  117. package/dist/learn/promote.js +321 -0
  118. package/dist/learn/refit.d.ts +48 -0
  119. package/dist/learn/refit.js +264 -0
  120. package/dist/learn/reflect.d.ts +5 -25
  121. package/dist/learn/reflect.js +14 -131
  122. package/dist/learn/replay-calls.d.ts +63 -0
  123. package/dist/learn/replay-calls.js +158 -0
  124. package/dist/learn/skills.d.ts +19 -16
  125. package/dist/learn/skills.js +157 -53
  126. package/dist/learn/workflow-nodes.d.ts +15 -0
  127. package/dist/learn/workflow-nodes.js +44 -0
  128. package/dist/learned-nodes.d.ts +58 -2
  129. package/dist/learned-nodes.js +68 -5
  130. package/dist/learned-workflow.d.ts +58 -32
  131. package/dist/learned-workflow.js +215 -77
  132. package/dist/learning-batch.d.ts +2 -2
  133. package/dist/learning-batch.js +4 -4
  134. package/dist/learning-cost.d.ts +41 -11
  135. package/dist/learning-cost.js +31 -13
  136. package/dist/learning-routes.d.ts +12 -2
  137. package/dist/learning-routes.js +34 -6
  138. package/dist/learning-words.d.ts +8 -1
  139. package/dist/learning-words.js +11 -1
  140. package/dist/learning.d.ts +26 -1
  141. package/dist/learning.js +7 -4
  142. package/dist/link-check.d.ts +27 -0
  143. package/dist/link-check.js +164 -0
  144. package/dist/llm.js +0 -3
  145. package/dist/local-models.d.ts +33 -2
  146. package/dist/local-models.js +43 -5
  147. package/dist/mcp-gateway.d.ts +12 -20
  148. package/dist/mcp-gateway.js +16 -44
  149. package/dist/mcp-oauth.d.ts +5 -0
  150. package/dist/mcp-oauth.js +1 -1
  151. package/dist/mcp-pin-first.d.ts +37 -0
  152. package/dist/mcp-pin-first.js +113 -0
  153. package/dist/mcp-probe.d.ts +8 -9
  154. package/dist/mcp-probe.js +16 -33
  155. package/dist/mcp-secret-writes.js +3 -0
  156. package/dist/mcp-servers-store.d.ts +102 -26
  157. package/dist/mcp-servers-store.js +151 -25
  158. package/dist/mcp-sources.d.ts +39 -0
  159. package/dist/mcp-sources.js +74 -0
  160. package/dist/mcp-store.d.ts +11 -0
  161. package/dist/mcp-store.js +16 -2
  162. package/dist/mcp-wire.d.ts +22 -0
  163. package/dist/mcp-wire.js +36 -0
  164. package/dist/mcp.js +3 -3
  165. package/dist/meta-tool-names.d.ts +1 -0
  166. package/dist/meta-tool-names.js +3 -0
  167. package/dist/model-form.d.ts +11 -0
  168. package/dist/model-form.js +17 -1
  169. package/dist/model.d.ts +39 -6
  170. package/dist/model.js +171 -32
  171. package/dist/monid.d.ts +50 -29
  172. package/dist/monid.js +234 -143
  173. package/dist/native/binding.d.ts +13 -0
  174. package/dist/native/binding.js +57 -0
  175. package/dist/native/cli.d.ts +2 -0
  176. package/dist/native/cli.js +48 -0
  177. package/dist/native/connection.d.ts +8 -0
  178. package/dist/native/connection.js +94 -0
  179. package/dist/native/context.d.ts +6 -0
  180. package/dist/native/context.js +22 -0
  181. package/dist/native/discovery.d.ts +27 -0
  182. package/dist/native/discovery.js +404 -0
  183. package/dist/native/environment.d.ts +4 -0
  184. package/dist/native/environment.js +18 -0
  185. package/dist/native/history.d.ts +20 -0
  186. package/dist/native/history.js +147 -0
  187. package/dist/native/instructions.d.ts +21 -0
  188. package/dist/native/instructions.js +173 -0
  189. package/dist/native/remote-worker-bridge.d.ts +3 -0
  190. package/dist/native/remote-worker-bridge.js +278 -0
  191. package/dist/native/remote.d.ts +187 -0
  192. package/dist/native/remote.js +492 -0
  193. package/dist/native/runtime.d.ts +17 -0
  194. package/dist/native/runtime.js +316 -0
  195. package/dist/native/runtimes.d.ts +66 -0
  196. package/dist/native/runtimes.js +41 -0
  197. package/dist/native/schema.d.ts +46 -0
  198. package/dist/native/schema.js +41 -0
  199. package/dist/native/types.d.ts +87 -0
  200. package/dist/native/types.js +1 -0
  201. package/dist/observation/http.d.ts +4 -0
  202. package/dist/observation/http.js +140 -0
  203. package/dist/observation/observer.d.ts +301 -0
  204. package/dist/observation/observer.js +919 -0
  205. package/dist/observation/schema.d.ts +52 -0
  206. package/dist/observation/schema.js +154 -0
  207. package/dist/openapi.d.ts +1 -0
  208. package/dist/openapi.js +705 -126
  209. package/dist/paid-calls.d.ts +34 -32
  210. package/dist/paid-calls.js +52 -104
  211. package/dist/place-offers.d.ts +4 -8
  212. package/dist/place-offers.js +4 -9
  213. package/dist/port-models.d.ts +7 -2
  214. package/dist/port-models.js +5 -2
  215. package/dist/print.d.ts +4 -2
  216. package/dist/print.js +4 -3
  217. package/dist/propose.d.ts +8 -3
  218. package/dist/propose.js +28 -7
  219. package/dist/provider.d.ts +5 -1
  220. package/dist/provider.js +17 -2
  221. package/dist/push-handler.d.ts +3 -2
  222. package/dist/push-handler.js +20 -6
  223. package/dist/reflect-range.js +2 -1
  224. package/dist/refusal-words.d.ts +11 -0
  225. package/dist/refusal-words.js +13 -2
  226. package/dist/rows.d.ts +5 -3
  227. package/dist/rows.js +15 -4
  228. package/dist/run-launch.d.ts +23 -1
  229. package/dist/run-launch.js +17 -4
  230. package/dist/run-learning-served.d.ts +84 -0
  231. package/dist/run-manifest.d.ts +8 -0
  232. package/dist/run-manifest.js +33 -1
  233. package/dist/run-reads-over-store.d.ts +3 -3
  234. package/dist/run-reads-over-store.js +13 -10
  235. package/dist/run-secrets.js +2 -3
  236. package/dist/run-timeline-served.d.ts +3 -2
  237. package/dist/run-timeline-served.js +12 -10
  238. package/dist/run-view.d.ts +59 -41
  239. package/dist/run-view.js +128 -64
  240. package/dist/runnable.d.ts +13 -8
  241. package/dist/runnable.js +77 -60
  242. package/dist/runner/adapter-loop.d.ts +60 -15
  243. package/dist/runner/adapter-loop.js +1406 -464
  244. package/dist/runner/adapter-run-spec.d.ts +45 -14
  245. package/dist/runner/adapter-run-spec.js +200 -116
  246. package/dist/runner/adapters/pi.d.ts +40 -7
  247. package/dist/runner/adapters/pi.js +149 -38
  248. package/dist/runner/beside.d.ts +3 -1
  249. package/dist/runner/beside.js +24 -8
  250. package/dist/runner/claim-secrets.d.ts +3 -1
  251. package/dist/runner/claim-secrets.js +28 -4
  252. package/dist/runner/cli-run-spec.d.ts +30 -0
  253. package/dist/runner/cli-run-spec.js +150 -66
  254. package/dist/runner/computer-channel.d.ts +5 -2
  255. package/dist/runner/computer-channel.js +5 -3
  256. package/dist/runner/computer-journal.d.ts +6 -0
  257. package/dist/runner/computer-journal.js +8 -10
  258. package/dist/runner/conformance/harness.d.ts +3 -0
  259. package/dist/runner/conformance/harness.js +149 -5
  260. package/dist/runner/conformance/subject.d.ts +11 -4
  261. package/dist/runner/end-of-run.d.ts +8 -5
  262. package/dist/runner/end-of-run.js +11 -6
  263. package/dist/runner/feedback-round.d.ts +79 -0
  264. package/dist/runner/feedback-round.js +127 -0
  265. package/dist/runner/harness-loops.js +17 -0
  266. package/dist/runner/journal-kinds.d.ts +55 -13
  267. package/dist/runner/journal-kinds.js +19 -0
  268. package/dist/runner/learning-dispatch.d.ts +3 -2
  269. package/dist/runner/learning-dispatch.js +6 -6
  270. package/dist/runner/learning-end.d.ts +58 -19
  271. package/dist/runner/learning-end.js +316 -115
  272. package/dist/runner/learning-factory.d.ts +3 -0
  273. package/dist/runner/learning-factory.js +8 -2
  274. package/dist/runner/learning-loop.d.ts +21 -1
  275. package/dist/runner/learning-loop.js +24 -6
  276. package/dist/runner/learning-seed.d.ts +4 -0
  277. package/dist/runner/learning-seed.js +14 -0
  278. package/dist/runner/loop-contract.d.ts +19 -3
  279. package/dist/runner/loop.d.ts +34 -1
  280. package/dist/runner/loop.js +55 -1
  281. package/dist/runner/main.d.ts +6 -1
  282. package/dist/runner/main.js +26 -4
  283. package/dist/runner/mcp-claim.d.ts +5 -1
  284. package/dist/runner/mcp-claim.js +66 -50
  285. package/dist/runner/mcp-run.d.ts +20 -53
  286. package/dist/runner/mcp-run.js +22 -88
  287. package/dist/runner/meta-tools.d.ts +44 -0
  288. package/dist/runner/meta-tools.js +344 -0
  289. package/dist/runner/metrics.d.ts +80 -21
  290. package/dist/runner/metrics.js +128 -42
  291. package/dist/runner/model-route.d.ts +12 -3
  292. package/dist/runner/model-route.js +149 -19
  293. package/dist/runner/monid-run.d.ts +18 -0
  294. package/dist/runner/monid-run.js +170 -0
  295. package/dist/runner/native-loop.d.ts +11 -0
  296. package/dist/runner/native-loop.js +438 -0
  297. package/dist/runner/promotion.d.ts +146 -0
  298. package/dist/runner/promotion.js +803 -0
  299. package/dist/runner/redact.js +3 -0
  300. package/dist/runner/reflect-hook.d.ts +36 -21
  301. package/dist/runner/reflect-hook.js +147 -49
  302. package/dist/runner/runner.d.ts +7 -1
  303. package/dist/runner/runner.js +34 -8
  304. package/dist/runner/sdk-loop.d.ts +7 -0
  305. package/dist/runner/sdk-loop.js +470 -0
  306. package/dist/runner/sessions.d.ts +8 -3
  307. package/dist/runner/sessions.js +5 -1
  308. package/dist/runner/spec-holds.d.ts +16 -2
  309. package/dist/runner/spec-holds.js +42 -14
  310. package/dist/runner/step-guard.d.ts +62 -0
  311. package/dist/runner/step-guard.js +93 -0
  312. package/dist/runner/store-secrets.js +17 -2
  313. package/dist/runner/subagent.d.ts +0 -3
  314. package/dist/runner/subagent.js +7 -12
  315. package/dist/runner/workflow-first.d.ts +226 -0
  316. package/dist/runner/workflow-first.js +293 -0
  317. package/dist/runner/workflow-loop.d.ts +1 -1
  318. package/dist/runner/workflow-loop.js +32 -19
  319. package/dist/runner/workflow-spec.d.ts +5 -1
  320. package/dist/runner/workflow-spec.js +63 -48
  321. package/dist/runs-over-store.d.ts +41 -4
  322. package/dist/runs-over-store.js +64 -22
  323. package/dist/sdk/runs.d.ts +115 -0
  324. package/dist/sdk/runs.js +422 -0
  325. package/dist/sdk/schema.d.ts +175 -0
  326. package/dist/sdk/schema.js +138 -0
  327. package/dist/sdk/workflows.d.ts +22 -0
  328. package/dist/sdk/workflows.js +39 -0
  329. package/dist/secrets.d.ts +2 -0
  330. package/dist/secrets.js +19 -1
  331. package/dist/server.d.ts +108 -20
  332. package/dist/server.js +874 -157
  333. package/dist/settings-wake.d.ts +8 -6
  334. package/dist/settings-wake.js +13 -7
  335. package/dist/skill-route.d.ts +3 -0
  336. package/dist/skill-route.js +16 -0
  337. package/dist/skills/agentrun-serve/SKILL.md +368 -0
  338. package/dist/stats.d.ts +10 -10
  339. package/dist/store/agent-body.d.ts +22 -7
  340. package/dist/store/agent-body.js +23 -14
  341. package/dist/store/command-wake.d.ts +3 -2
  342. package/dist/store/command-wake.js +4 -4
  343. package/dist/store/index.d.ts +1 -1
  344. package/dist/store/native-command-owner.d.ts +10 -0
  345. package/dist/store/native-command-owner.js +47 -0
  346. package/dist/store/postgres/connection.js +3 -1
  347. package/dist/store/postgres/migrations/0010_imported_templates.sql +18 -0
  348. package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
  349. package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
  350. package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
  351. package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
  352. package/dist/store/postgres/store.js +3 -0
  353. package/dist/store/schema.d.ts +16 -0
  354. package/dist/store/schema.js +47 -8
  355. package/dist/store/sqlite/connection.d.ts +2 -2
  356. package/dist/store/sqlite/connection.js +2 -2
  357. package/dist/store/sqlite/run-patch.d.ts +8 -1
  358. package/dist/store/sqlite/run-patch.js +33 -10
  359. package/dist/store/sqlite/store.js +184 -28
  360. package/dist/store/store.d.ts +98 -21
  361. package/dist/store-reads/analytics.d.ts +7 -7
  362. package/dist/store-reads/analytics.js +23 -5
  363. package/dist/store-reads/cap.js +8 -6
  364. package/dist/store-reads/journal.d.ts +30 -1
  365. package/dist/store-reads/journal.js +141 -83
  366. package/dist/store-reads/learning.d.ts +179 -13
  367. package/dist/store-reads/learning.js +230 -68
  368. package/dist/store-reads/loop.d.ts +61 -0
  369. package/dist/store-reads/loop.js +111 -0
  370. package/dist/store-reads/runs.d.ts +5 -0
  371. package/dist/store-reads/runs.js +3 -2
  372. package/dist/store-view.d.ts +3 -2
  373. package/dist/store-view.js +109 -37
  374. package/dist/template-eval.d.ts +87 -16
  375. package/dist/template-eval.js +605 -120
  376. package/dist/template-github-permissions.d.ts +2 -2
  377. package/dist/template-github-permissions.js +2 -1
  378. package/dist/template-import.d.ts +31 -0
  379. package/dist/template-import.js +121 -0
  380. package/dist/template-source.d.ts +51 -0
  381. package/dist/template-source.js +371 -0
  382. package/dist/templates.d.ts +274 -52
  383. package/dist/templates.js +670 -201
  384. package/dist/text-urls.d.ts +38 -0
  385. package/dist/text-urls.js +170 -0
  386. package/dist/timeline/computer.d.ts +48 -0
  387. package/dist/timeline/computer.js +169 -0
  388. package/dist/timeline/index.d.ts +7 -5
  389. package/dist/timeline/index.js +7 -5
  390. package/dist/timeline/labels.d.ts +11 -4
  391. package/dist/timeline/labels.js +122 -8
  392. package/dist/timeline/origin.d.ts +20 -6
  393. package/dist/timeline/origin.js +13 -6
  394. package/dist/timeline/render-text.js +1 -1
  395. package/dist/timeline/timeline.d.ts +76 -20
  396. package/dist/timeline/timeline.js +184 -39
  397. package/dist/timeline/util.d.ts +5 -0
  398. package/dist/timeline/util.js +44 -8
  399. package/dist/timeline/web-calls.d.ts +17 -0
  400. package/dist/timeline/web-calls.js +106 -0
  401. package/dist/tool-gate.d.ts +103 -76
  402. package/dist/tool-gate.js +200 -127
  403. package/dist/tool-keys.d.ts +4 -1
  404. package/dist/tool-keys.js +8 -3
  405. package/dist/tool-list.d.ts +29 -0
  406. package/dist/tool-list.js +50 -0
  407. package/dist/tool-names.d.ts +76 -0
  408. package/dist/tool-names.js +101 -0
  409. package/dist/tool-plane.d.ts +34 -28
  410. package/dist/tool-plane.js +72 -37
  411. package/dist/tools.d.ts +59 -15
  412. package/dist/tools.js +46 -42
  413. package/dist/trigger-adapter.d.ts +85 -5
  414. package/dist/trigger-adapter.js +6 -0
  415. package/dist/trigger-adapters.js +3 -1
  416. package/dist/trigger-composio.d.ts +10 -0
  417. package/dist/trigger-composio.js +122 -0
  418. package/dist/trigger-email.d.ts +4 -0
  419. package/dist/trigger-email.js +228 -0
  420. package/dist/trigger-signatures.d.ts +6 -10
  421. package/dist/trigger-signatures.js +16 -16
  422. package/dist/trigger-targets.d.ts +1 -1
  423. package/dist/trigger-targets.js +4 -3
  424. package/dist/trigger-webhook.js +6 -4
  425. package/dist/triggers.d.ts +94 -9
  426. package/dist/triggers.js +263 -62
  427. package/dist/uploads.d.ts +9 -0
  428. package/dist/uploads.js +27 -0
  429. package/dist/validate.d.ts +15 -7
  430. package/dist/validate.js +91 -50
  431. package/dist/web-fake.d.ts +56 -0
  432. package/dist/web-fake.js +102 -0
  433. package/dist/web-fetch-direct.d.ts +3 -0
  434. package/dist/web-fetch-direct.js +4 -1
  435. package/dist/web-fetch.d.ts +6 -8
  436. package/dist/web-fetch.js +10 -53
  437. package/dist/web-search.d.ts +51 -2
  438. package/dist/web-search.js +116 -18
  439. package/dist/webhooks.d.ts +2 -1
  440. package/dist/webhooks.js +5 -1
  441. package/dist/workflow/node-runner.js +10 -2
  442. package/dist/workspace/archil-claim.d.ts +3 -0
  443. package/dist/workspace/archil-claim.js +9 -2
  444. package/dist/workspace/computer-deps.d.ts +25 -9
  445. package/dist/workspace/computer-deps.js +82 -38
  446. package/dist/workspace/computer-for-claim.d.ts +60 -4
  447. package/dist/workspace/computer-for-claim.js +203 -45
  448. package/dist/workspace/computer-hold.js +7 -1
  449. package/dist/workspace/computer-janitor.d.ts +10 -3
  450. package/dist/workspace/computer-janitor.js +96 -29
  451. package/dist/workspace/computer-kept.d.ts +82 -0
  452. package/dist/workspace/computer-kept.js +147 -0
  453. package/dist/workspace/computer-mcp.js +4 -3
  454. package/dist/workspace/computer-ports.d.ts +23 -3
  455. package/dist/workspace/computer-ports.js +115 -5
  456. package/dist/workspace/index.d.ts +2 -3
  457. package/dist/workspace/index.js +1 -2
  458. package/dist/workspace/kind-skills/desktop/SKILL.md +31 -11
  459. package/dist/workspace/kind-skills/phone/SKILL.md +29 -14
  460. package/dist/workspace/local.js +2 -2
  461. package/dist/workspace/resolve-computer.d.ts +33 -1
  462. package/dist/workspace/resolve-computer.js +37 -16
  463. package/dist/workspace/revision-skills.d.ts +6 -2
  464. package/dist/workspace/revision-skills.js +12 -5
  465. package/dist/workspace/run-end-computers.d.ts +30 -0
  466. package/dist/workspace/run-end-computers.js +137 -0
  467. package/dist/workspace/run-tools.d.ts +40 -23
  468. package/dist/workspace/run-tools.js +46 -19
  469. package/dist/wrap-up.d.ts +35 -0
  470. package/dist/wrap-up.js +48 -0
  471. package/launcher/agentrun-serve +4 -2
  472. package/package.json +13 -9
  473. package/skills/agentrun-serve/SKILL.md +248 -10
  474. package/templates/README.md +220 -60
  475. package/templates/TOOLS.md +168 -0
  476. package/templates/code-review/agent.md +46 -16
  477. package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
  478. package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
  479. package/templates/code-review/evals/injection/case.yaml +2 -1
  480. package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
  481. package/templates/code-review/evals/mentions-defused/case.yaml +3 -3
  482. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
  483. package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
  484. package/templates/code-review/evals/never-flag/case.yaml +2 -1
  485. package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
  486. package/templates/code-review/evals/null-name/case.yaml +2 -1
  487. package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
  488. package/templates/code-review/evals/off-by-one/case.yaml +2 -1
  489. package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
  490. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
  491. package/templates/code-review/evals/other-repo/case.yaml +16 -0
  492. package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
  493. package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
  494. package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
  495. package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
  496. package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
  497. package/templates/code-review/evals/other-repo/prompt.md +10 -0
  498. package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
  499. package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
  500. package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
  501. package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
  502. package/templates/code-review/evals/re-review/case.yaml +2 -1
  503. package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
  504. package/templates/code-review/evals/re-review-open/case.yaml +2 -1
  505. package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
  506. package/templates/code-review/evals/repo-rule/case.yaml +2 -1
  507. package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
  508. package/templates/code-review/evals/two-defects/case.yaml +2 -1
  509. package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
  510. package/templates/code-review/rules/CODEREVIEW.md +1 -1
  511. package/templates/code-review/skills/review/DEEP.md +5 -4
  512. package/templates/code-review/skills/review/REVIEWER.md +5 -4
  513. package/templates/code-review/skills/review/SKILL.md +11 -6
  514. package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
  515. package/templates/inbound-lead/agent.md +26 -16
  516. package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
  517. package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
  518. package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
  519. package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
  520. package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
  521. package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
  522. package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
  523. package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
  524. package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
  525. package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
  526. package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
  527. package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
  528. package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
  529. package/templates/kyb/agent.md +15 -5
  530. package/templates/kyb/evals/adverse-media/prompt.md +2 -7
  531. package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
  532. package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
  533. package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
  534. package/templates/kyb/evals/name-collision/prompt.md +2 -6
  535. package/templates/kyb/evals/no-invention/prompt.md +2 -6
  536. package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
  537. package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
  538. package/templates/kyb/kyb.schema.json +8 -7
  539. package/templates/kyb/skills/kyb/SKILL.md +9 -6
  540. package/templates/market-monitor/agent.md +19 -12
  541. package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
  542. package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
  543. package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
  544. package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
  545. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  546. package/templates/release-notes/agent.md +32 -10
  547. package/templates/release-notes/evals/draft-not-publish/case.yaml +5 -4
  548. package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
  549. package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
  550. package/templates/release-notes/evals/issue-write-refused/case.yaml +5 -4
  551. package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
  552. package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
  553. package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
  554. package/templates/release-notes/evals/learned-style/case.yaml +2 -1
  555. package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
  556. package/templates/release-notes/evals/other-repo/case.yaml +24 -0
  557. package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
  558. package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
  559. package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
  560. package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
  561. package/templates/release-notes/evals/other-repo/prompt.md +32 -0
  562. package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
  563. package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
  564. package/templates/release-notes/notes.schema.json +1 -1
  565. package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
  566. package/dist/console/assets/index-Cn6JX1uH.js +0 -563
  567. package/dist/console/assets/index-DRN62V5v.css +0 -1
  568. package/dist/host-calls.d.ts +0 -20
  569. package/dist/host-calls.js +0 -12
  570. package/dist/runner/adapters/pi-computer.d.ts +0 -7
  571. package/dist/runner/adapters/pi-computer.js +0 -43
  572. package/dist/tool-blurbs.d.ts +0 -4
  573. package/dist/tool-blurbs.js +0 -28
  574. package/dist/tool-budget.d.ts +0 -38
  575. package/dist/tool-budget.js +0 -62
  576. package/dist/workspace/computer-script.d.ts +0 -37
  577. package/dist/workspace/computer-script.js +0 -138
  578. package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
  579. package/templates/code-review/evals/injection/graders/schema.md +0 -5
  580. package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
  581. package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
  582. package/templates/code-review/evals/null-name/graders/schema.md +0 -5
  583. package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
  584. package/templates/code-review/evals/re-review/graders/schema.md +0 -5
  585. package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
  586. package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
  587. package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
  588. package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
  589. package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
  590. package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
  591. package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
  592. package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
  593. package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
  594. package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
  595. package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
  596. package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
  597. package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
  598. package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
  599. package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
  600. package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
  601. package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
  602. package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
  603. package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
  604. package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
  605. package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
  606. package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
  607. package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
  608. package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
  609. package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
  610. package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
  611. package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
  612. package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
  613. package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
  614. package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
  615. package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
  616. package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
  617. package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
  618. package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
  619. package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
  620. package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
package/dist/templates.js CHANGED
@@ -9,37 +9,57 @@ import { basename, join } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
10
10
  import { parseDocument } from "yaml";
11
11
  import { invalid } from "./errors.js";
12
+ // Where a package's MCP tools come from (a Composio toolkit, GitHub's MCP server, or any other server by its address): a
13
+ // saved MCP server records one too, and apply maps each need to a server whose record matches.
14
+ import { MCP_SOURCES } from "./mcp-sources.js";
12
15
  import { HARNESSES } from "./harness.js";
13
16
  import { TOOL_KEY_ROWS } from "./key-words.js";
14
- import { MCP_SERVER_NAME } from "./mcp-probe.js";
15
- import { chooseModel, harnessRuns, hostModel, MODEL_KEYS, THINKING_LEVELS } from "./model.js";
16
- import { mcpToolName } from "./tool-gate.js";
17
+ import { harnessOf } from "./harness-table.js";
18
+ import { chooseModel, FAUX_ENV, harnessRuns, hostModel, MODEL_KEYS, providerModels, THINKING_LEVELS } from "./model.js";
19
+ import { harnessModel } from "./runnable.js";
20
+ import { isPinKeys } from "./tool-gate.js";
21
+ import { formatToolName, isMcpName, isMonidName, MCP_SERVER_NAME, MCP_TOOL_NAME, mcpToolName, MONID_NAME_WORDS, parseToolName } from "./tool-names.js";
17
22
  import { pinIssues, sortedPin } from "./tool-plane.js";
18
23
  import { BASH_POLICIES } from "./bash-read-only.js";
19
24
  import { BOUND_TOOLS, toolOf } from "./tools.js";
20
25
  import { TRIGGER_ADAPTERS } from "./trigger-adapters.js";
26
+ import { MOVE_FIELD } from "./trigger-composio.js";
21
27
  import { triggerBodyIssues } from "./triggers.js";
22
- import { DEFAULT_INPUT_SCHEMA, definitionBodyIssues, inputIssues, isObject, MAX_TOOL_CALLS, MODEL_REF, MODEL_TIER_NAMES, unknownFields } from "./validate.js";
28
+ import { definitionBodyIssues, inputIssues, inputSchemaOf, isObject, MODEL_REF, MODEL_TIER_NAMES, unknownFields } from "./validate.js";
29
+ import { schemaCheck } from "./answer-json.js";
23
30
  import { APPROVALS } from "./approvals.js";
24
31
  export const TEMPLATES_DIR = fileURLToPath(new URL("../templates/", import.meta.url));
25
32
  export const MANIFEST = "agent.md";
26
33
  /** A package's model tier, mapped to the server's own (model.ts Tier: AGENT_MODEL_FAST, AGENT_MODEL, AGENT_MODEL_STRONG). */
27
34
  export const MODEL_TIERS = { fast: "fast", balanced: "default", strong: "strong" };
28
- export const PARAMETER_TYPES = ["string", "number", "integer", "boolean"];
29
- /** What a string parameter's value is, for a form to ask for it as such: a schedule's cron line, or an IANA time zone
30
- * (market-monitor's schedule). A form shows a schedule picker and a time-zone choice; the value is the same text. */
31
- export const PARAMETER_FORMATS = ["cron", "timezone"];
32
- export const GRADER_TYPES = ["llm", "regex", "tool_used", "file_exists", "schema"];
35
+ const SCALAR_TYPES = ["string", "number", "integer", "boolean"];
36
+ /** A case's grader types. The answer's output schema is no grader's: every graded run of a package with `output` is held
37
+ * to it by the server's own verdict (template-eval.ts outputVerdict). */
38
+ export const GRADER_TYPES = ["llm", "regex", "tool_used", "file_exists", "mailbox"];
33
39
  /** The entries of a package's `computer` preference list: `shell`, a computer that gives the agent a shell here (bash);
34
40
  * `none`, no shell, the file tools alone. Apply takes the first this server meets now (pickComputer). */
35
41
  export const COMPUTER_ENTRIES = ["shell", "none"];
36
- const FIELDS = ["name", "display_name", "version", "description", "license", "author", "repository", "harness", "model", "effort", "tools", "mcp", "tool_policy", "computer", "checkout", "parameters", "secrets", "budget", "learning", "approvals", "triggers", "output", "checks"];
42
+ const FIELDS = ["name", "display_name", "version", "description", "license", "author", "repository", "category", "tags", "harness", "model", "effort", "tools", "mcp", "tool_policy", "computer", "checkout", "parameters", "inputs", "secrets", "budget", "learning", "approvals", "triggers", "output"];
43
+ /** What a package is for, shown on a marketplace page and the console's list: display only, never applied. */
44
+ export const CATEGORIES = ["engineering", "security", "sales", "marketing", "research", "finance", "operations", "compliance", "personal"];
45
+ const TAG = /^[a-z0-9-]{1,32}$/;
46
+ const MAX_TAGS = 8;
47
+ /** An MCP need's reason: one line, shown on the apply screen beside its tools. */
48
+ const MAX_REASON = 280;
49
+ /** An input's or a parameter's types: a scalar, or a list of one. */
50
+ export const INPUT_TYPES = [...SCALAR_TYPES, "array"];
51
+ /** What a string input's or parameter's value is: a form asks for it as such, and the server checks the JSON Schema
52
+ * formats it knows. cron and timezone are for the form alone (a schedule picker, a zone choice); where a parameter fills
53
+ * a schedule, the schedule's own check reads the value at apply. */
54
+ export const INPUT_FORMATS = ["uri", "email", "hostname", "date", "date-time", "uuid", "cron", "timezone"];
55
+ /** An input's or a parameter's keys: what a form and a JSON Schema say of one field. */
56
+ const INPUT_KEYS = ["type", "required", "pattern", "enum", "format", "default", "description", "title", "examples", "minimum", "maximum", "minLength", "maxLength", "items"];
57
+ /** A list input's `items`: a scalar's keys alone. */
58
+ const ITEM_KEYS = ["type", "pattern", "enum", "format", "minimum", "maximum", "minLength", "maxLength"];
37
59
  const NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
38
60
  const PARAMETER = /^[a-z][a-z0-9_]{0,63}$/;
39
61
  /** The keys a package may need: those Settings saves (a tool's or a model provider's), each one a run is handed. */
40
62
  export const PACKAGE_SECRETS = [...new Set([...TOOL_KEY_ROWS.flatMap((row) => row.fields), ...MODEL_KEYS.map((row) => row.field)])];
41
- /** An MCP tool's name: one tool, never the server's wildcard `*`. */
42
- const MCP_TOOL = /^[A-Za-z0-9_.-]{1,128}$/;
43
63
  /** A package's bounds: each file, all its files together (POST /agents' own body limit), and how many it holds. */
44
64
  export const MAX_FILE_BYTES = 256 << 10;
45
65
  export const MAX_PACKAGE_BYTES = 1 << 20;
@@ -49,23 +69,76 @@ export const MAX_PACKAGE_FILES = 256;
49
69
  export const MAX_EVAL_FILE_BYTES = 32 << 20;
50
70
  /** A parameter's sample, of its type, for the check that compiles a package before any apply. */
51
71
  const SAMPLES = { string: "x", number: 1, integer: 1, boolean: true };
72
+ /** A string of each format a parameter (or a list parameter's items) may say, for that check. */
73
+ const FORMAT_SAMPLES = { uri: "https://example.com", email: "someone@example.com", hostname: "example.com", date: "2026-01-01", "date-time": "2026-01-01T00:00:00Z", uuid: "00000000-0000-4000-8000-000000000000", cron: "0 9 * * *", timezone: "UTC" };
74
+ /** A scalar's sample: its first choice, else one of its format, else one of its type. */
75
+ const sampleOf = (spec) => (Array.isArray(spec.enum) ? spec.enum[0] : FORMAT_SAMPLES[spec.format] ?? SAMPLES[spec.type]);
76
+ /** A composio trigger's fields this server sets when it makes the trigger on Composio (composio-triggers.ts). */
77
+ const COMPOSIO_SET = ["instance_id", "hook", MOVE_FIELD];
52
78
  /** An agent id in the shape an apply gives a trigger's target, for that check. */
53
79
  const SAMPLE_AGENT = `agt_${"0".repeat(24)}`;
54
80
  // semver.org's own expression, SemVer 2.0.0.
55
81
  const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
56
82
  const PLACEHOLDER = /\$\{parameters\.([^}]*)\}/g;
83
+ /** Text that is one placeholder alone: it takes the parameter's value with its type (a pin's, a trigger's input's). */
84
+ const WHOLE = /^\$\{parameters\.([^}]*)\}$/;
57
85
  const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
58
- /** Whether `value` is of the parameter type `type`. */
86
+ /** A package's model choices at most, a choice label's length, and a warning's or a note's. */
87
+ const MAX_CHOICES = 3;
88
+ const MAX_CHOICE_LABEL = 40;
89
+ const MAX_CHOICE_TEXT = 300;
90
+ const CHOICE_FIELDS = ["id", "label", "model", "harness", "warning", "note", "secrets"];
91
+ const CHOICE_WORDS = "{id, label, model, harness, warning?, note?, secrets?}";
92
+ /** A manifest's `model.choices`, checked: each problem said through `bad`, in words that say the rule. A choice's harness
93
+ * is one of the package's `harness` list (`harness`), or any this server knows when the package names none. */
94
+ function modelChoices(given, harness, bad) {
95
+ if (!Array.isArray(given) || !given.length || given.length > MAX_CHOICES)
96
+ return bad(`model.choices is a list of 1 to ${MAX_CHOICES} choices, each ${CHOICE_WORDS}: the models an owner may pick one of at install`), [];
97
+ const text = (value, max) => typeof value === "string" && value.trim() !== "" && value.length <= max;
98
+ const ids = new Set();
99
+ const out = [];
100
+ given.forEach((choice, i) => {
101
+ const at = `model.choices[${i}]`;
102
+ if (!isObject(choice))
103
+ return bad(`${at} is ${CHOICE_WORDS}`);
104
+ let ok = true;
105
+ const no = (message) => { ok = false; bad(message); };
106
+ for (const issue of unknownFields(choice, CHOICE_FIELDS))
107
+ no(`${at} has no field ${issue.field}: a choice is ${CHOICE_WORDS}`);
108
+ if (typeof choice.id !== "string" || !NAME.test(choice.id) || choice.id.length > 64)
109
+ no(`${at}.id is lowercase letters, digits and dashes, at most 64: what an apply's overrides.choice names`);
110
+ else if (ids.has(choice.id))
111
+ no(`${at}.id ${choice.id} is an earlier choice's: each choice has its own id`);
112
+ ids.add(choice.id);
113
+ if (!text(choice.label, MAX_CHOICE_LABEL))
114
+ no(`${at}.label is text of 1 to ${MAX_CHOICE_LABEL} characters, shown beside the choice at install`);
115
+ if (typeof choice.model !== "string" || !MODEL_REF.test(choice.model))
116
+ no(`${at}.model is "provider/model-id"`);
117
+ const harnesses = harness ?? HARNESSES;
118
+ if (typeof choice.harness !== "string" || !harnesses.includes(choice.harness))
119
+ no(`${at}.harness is one of ${harness ? `the package's harness list (${harness.join(", ")})` : HARNESSES.join(", ")}: the choice runs on it`);
120
+ if (choice.warning !== undefined && !text(choice.warning, MAX_CHOICE_TEXT))
121
+ no(`${at}.warning is text of 1 to ${MAX_CHOICE_TEXT} characters, shown word for word beside the choice at install`);
122
+ if (choice.note !== undefined && !text(choice.note, MAX_CHOICE_TEXT))
123
+ no(`${at}.note is text of 1 to ${MAX_CHOICE_TEXT} characters, a setup line shown beside the choice at install`);
124
+ const secrets = choice.secrets ?? [];
125
+ if (!Array.isArray(secrets) || !secrets.every((name) => typeof name === "string" && /^[A-Z][A-Z0-9_]{0,127}$/.test(name)))
126
+ no(`${at}.secrets is a list of key names, as the package's secrets`);
127
+ else {
128
+ if (new Set(secrets).size !== secrets.length)
129
+ no(`${at}.secrets names one key twice`);
130
+ for (const name of secrets.filter((one) => !PACKAGE_SECRETS.includes(one)))
131
+ no(`${at}.secrets names ${name}, a key this server cannot hold: a choice needs the keys Settings saves and a run is handed (${PACKAGE_SECRETS.join(", ")})`);
132
+ }
133
+ if (ok)
134
+ out.push({ id: choice.id, label: choice.label, model: choice.model, harness: choice.harness, ...(typeof choice.warning === "string" ? { warning: choice.warning } : {}), ...(typeof choice.note === "string" ? { note: choice.note } : {}), secrets: secrets });
135
+ });
136
+ return out;
137
+ }
138
+ /** Whether `value` is of the scalar type `type`. */
59
139
  const ofType = (type, value) => (type === "integer" ? Number.isSafeInteger(value) : type === "number" ? typeof value === "number" && Number.isFinite(value) : typeof value === type);
60
- /** Whether `text` matches `pattern`; a pattern that does not compile matches nothing (it is reported on its own). */
61
- const safeTest = (pattern, text) => {
62
- try {
63
- return new RegExp(pattern, "u").test(text);
64
- }
65
- catch {
66
- return false;
67
- }
68
- };
140
+ /** A compiled field schema's (fieldsSchema's) properties, by name. */
141
+ export const fieldsOf = (schema) => schema.properties;
69
142
  /** A schedule's fields a parameter may fill: its time, read by the server as the schedule, and checked at apply. */
70
143
  const SCHEDULE_FIELDS = ["cron", "timezone"];
71
144
  /** A package that does not check: every problem, each naming its file. */
@@ -78,7 +151,10 @@ export class PackageError extends Error {
78
151
  this.problems = problems;
79
152
  }
80
153
  }
81
- /** A github source split at its where conditions' `in` values, the one place a parameter may fill it: `ins`, each
154
+ /** The source kinds whose accept rules a parameter may fill: a github trigger's, and a webhook trigger's (a provider that
155
+ * sends every trigger of a project to one URL, as Composio does, is filtered to the owner's own repository by them). */
156
+ const FILTERED_KINDS = ["github", "webhook"];
157
+ /** A github or webhook source split at its where conditions' `in` values, the one place a parameter may fill it: `ins`, each
82
158
  * condition's list, and `rest`, the source without them. */
83
159
  function whereIns(source) {
84
160
  const ins = [];
@@ -107,19 +183,52 @@ const GITHUB_EVENT_WORDS = { pull_request: "pull request", pull_request_review:
107
183
  export const githubTriggerUnconnected = (packageName, source) => `Connect GitHub in Settings, then apply again so it runs by itself: ${githubTriggerWords(packageName, source)}`;
108
184
  /** Every string in `value`, deep. */
109
185
  const strings = (value) => (typeof value === "string" ? [value] : Array.isArray(value) ? value.flatMap(strings) : isObject(value) ? Object.values(value).flatMap(strings) : []);
110
- /** `value` with each `${parameters.x}` in its strings replaced by the value given for x (its own: never an inherited
111
- * name such as constructor), else nothing. */
112
- const filled = (value, given) => typeof value === "string" ? value.replace(PLACEHOLDER, (_, name) => String(Object.hasOwn(given, name) ? given[name] ?? "" : ""))
186
+ /** The value given for the parameter `name` (its own: never an inherited name such as constructor), else undefined. */
187
+ const givenOf = (given, name) => (Object.hasOwn(given, name) ? given[name] ?? undefined : undefined);
188
+ /** Whether a pin's parameter was given no value it can pin: none, "", or an empty list. */
189
+ const unset = (value) => value === undefined || value === "" || (Array.isArray(value) && !value.length);
190
+ /** A parameter's value as text: a list's items joined by ", " (an empty one, ""), nothing as "". */
191
+ const asText = (value) => (value === undefined ? "" : Array.isArray(value) ? value.map(asText).join(", ") : String(value));
192
+ /** `value` with each `${parameters.x}` in its strings replaced by the value given for x as text (asText). */
193
+ const filled = (value, given) => typeof value === "string" ? value.replace(PLACEHOLDER, (_, name) => asText(givenOf(given, name)))
113
194
  : Array.isArray(value) ? value.map((item) => filled(item, given))
114
195
  : isObject(value) ? Object.fromEntries(Object.entries(value).map(([key, item]) => [key, filled(item, given)]))
115
196
  : value;
197
+ /** Text filled from `given`, the one rule a trigger's input and a pin share: text that is one placeholder alone takes the
198
+ * parameter's value with its type (a list stays a list, an integer an integer), undefined when it was given none; other
199
+ * text is filled as text. Each caller keeps its own rule for a value given none. */
200
+ const typedFilled = (text, given) => {
201
+ const whole = WHOLE.exec(text);
202
+ return whole ? givenOf(given, whole[1]) : filled(text, given);
203
+ };
204
+ /** A trigger's target.input filled (typedFilled): a whole placeholder given no value is dropped, so the input schema
205
+ * sees the field absent. */
206
+ const inputFilled = (value, given) => {
207
+ if (typeof value === "string")
208
+ return typedFilled(value, given);
209
+ if (Array.isArray(value))
210
+ return value.map((item) => inputFilled(item, given)).filter((item) => item !== undefined);
211
+ if (isObject(value))
212
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, inputFilled(item, given)]).filter(([, item]) => item !== undefined));
213
+ return value;
214
+ };
215
+ /** A trigger filled from the apply's parameters: its target.input typed (inputFilled), its enabled the boolean its one
216
+ * placeholder names, the rest as text. */
217
+ const triggerFilled = (trigger, given) => {
218
+ const out = filled(trigger, given);
219
+ if (isObject(trigger.target) && trigger.target.input !== undefined)
220
+ out.target = { ...out.target, input: inputFilled(trigger.target.input, given) };
221
+ if (typeof trigger.enabled === "string" && WHOLE.test(trigger.enabled))
222
+ out.enabled = typedFilled(trigger.enabled, given);
223
+ return out;
224
+ };
116
225
  /** An mcp entry's `pin` read: by tool, each one of the entry's `tools`, its arguments checked by the one rule every pin
117
226
  * is (tool-plane.ts pinIssues, on the tool's gate name), text in it may hold `${parameters.<name>}` (checked with the
118
227
  * other placeholders). Each problem is told through `bad`; a tool whose pin reads is kept. */
119
228
  function pinOf(pin, server, tools, at, bad) {
120
229
  const out = {};
121
230
  if (!isObject(pin))
122
- return bad(`${at} is {<tool>: {<argument>: <value or \${parameters.<name>}, or a list of them>}}, by the entry's tools`), out;
231
+ return bad(`${at} is {<tool>: {<argument>: <value or \${parameters.<name>}, a list of them, or {keys: [<key or \${parameters.<name>}>]}>}}, by the entry's tools`), out;
123
232
  for (const [tool, args] of Object.entries(pin)) {
124
233
  if (!tools.includes(tool)) {
125
234
  bad(`${at}.${tool}: ${tool} is not one of this entry's tools (${tools.join(", ")}): a pin fixes the arguments of a tool the package lists`);
@@ -133,36 +242,213 @@ function pinOf(pin, server, tools, at, bad) {
133
242
  }
134
243
  return out;
135
244
  }
136
- /** A pin's scalar filled from the apply's `given` parameters: text that is one placeholder alone takes the parameter's
137
- * value as given (its type kept: an integer pins an integer); other text is filled as text. `empty`: the parameters its
138
- * placeholders name that were given no value (absent, or ""), so the pin cannot hold what the owner meant. */
245
+ /** A pin's scalar filled from the apply's `given` parameters (typedFilled: an integer pins an integer), a list's items
246
+ * as text. `empty`: the parameters its placeholders name that were given no value (absent, or ""), so the pin cannot
247
+ * hold what the owner meant. */
139
248
  function scalarFilled(value, given) {
140
249
  if (typeof value !== "string")
141
250
  return { value, empty: [] };
142
- const named = [...value.matchAll(PLACEHOLDER)].map((match) => match[1]);
143
- const empty = named.filter((name) => !Object.hasOwn(given, name) || given[name] === undefined || given[name] === null || given[name] === "");
144
- const whole = /^\$\{parameters\.([^}]*)\}$/.exec(value);
145
- if (whole && !empty.length) {
146
- const one = given[whole[1]];
147
- if (typeof one === "string" || typeof one === "number" || typeof one === "boolean")
148
- return { value: one, empty };
149
- }
150
- return { value: filled(value, given), empty };
251
+ const empty = [...value.matchAll(PLACEHOLDER)].map((match) => match[1]).filter((name) => unset(givenOf(given, name)));
252
+ const one = typedFilled(value, given);
253
+ return { value: !empty.length && (typeof one === "string" || typeof one === "number" || typeof one === "boolean") ? one : filled(value, given), empty };
151
254
  }
152
- /** A pin's value filled (scalarFilled), each of a one-of list's in its order. */
255
+ /** A keys pin's keys filled as text (scalarFilled), in their order; a key that is one placeholder alone of a list
256
+ * parameter adds each of its items: any of the fields the owner named. */
257
+ function keysFilled(keys, given) {
258
+ const each = keys.map((key) => {
259
+ const whole = WHOLE.exec(key);
260
+ const list = whole ? givenOf(given, whole[1]) : undefined;
261
+ if (Array.isArray(list) && list.length)
262
+ return { value: list.map(asText), empty: [] };
263
+ const one = scalarFilled(key, given);
264
+ return { value: [asText(one.value)], empty: one.empty };
265
+ });
266
+ return { value: { keys: each.flatMap((one) => one.value) }, empty: each.flatMap((one) => one.empty) };
267
+ }
268
+ /** A pin's value filled (scalarFilled), each of a one-of list's in its order, a keys pin's keys (keysFilled). One
269
+ * placeholder alone of a list parameter pins the list as a one-of: any of the values the owner gave. */
153
270
  function pinFilled(value, given) {
271
+ if (isPinKeys(value))
272
+ return keysFilled(value.keys, given);
273
+ const list = typeof value === "string" ? typedFilled(value, given) : undefined;
274
+ if (Array.isArray(list) && list.length)
275
+ return { value: list, empty: [] };
154
276
  if (!Array.isArray(value))
155
277
  return scalarFilled(value, given);
156
278
  const each = value.map((one) => scalarFilled(one, given));
157
279
  return { value: each.map((one) => one.value), empty: each.flatMap((one) => one.empty) };
158
280
  }
159
- /** Reads `dir` checked whole: a valid package, or PackageError with every problem found. */
160
- export function readPackage(dir) {
281
+ /** A package's folder on disk: each entry as lstat sees it, so a link is an entry of its own kind, never followed. */
282
+ export function folderFiles(dir) {
283
+ return {
284
+ name: basename(dir),
285
+ where: dir,
286
+ entries: (sub) => readdirSync(join(dir, sub), { withFileTypes: true }),
287
+ kind: (path) => {
288
+ const stat = lstatSync(join(dir, path), { throwIfNoEntry: false });
289
+ return stat?.isDirectory() ? "dir" : stat?.isFile() ? "file" : stat ? "other" : undefined;
290
+ },
291
+ size: (path) => lstatSync(join(dir, path)).size,
292
+ text: (path) => readFileSync(join(dir, path), "utf8"),
293
+ };
294
+ }
295
+ /** A package held in memory, by path (template-source.ts keeps regular files alone): its folders are those its files'
296
+ * paths name. */
297
+ export function memoryFiles(name, where, files) {
298
+ const kind = (path) => (files.has(path) ? "file" : path === "" || [...files.keys()].some((one) => one.startsWith(`${path}/`)) ? "dir" : undefined);
299
+ return {
300
+ name,
301
+ where,
302
+ entries: (sub) => {
303
+ const prefix = sub ? `${sub}/` : "";
304
+ const names = new Set([...files.keys()].filter((path) => path.startsWith(prefix)).map((path) => path.slice(prefix.length).split("/")[0]));
305
+ return [...names].map((one) => {
306
+ const at = `${prefix}${one}`;
307
+ return { name: one, isDirectory: () => kind(at) === "dir", isFile: () => kind(at) === "file" };
308
+ });
309
+ },
310
+ kind,
311
+ size: (path) => files.get(path)?.length ?? 0,
312
+ text: (path) => files.get(path)?.toString("utf8") ?? "",
313
+ };
314
+ }
315
+ /** A scalar input's (or a list's item's) JSON Schema from its manifest keys, each checked by `bad` (said at `at`):
316
+ * pattern, format and lengths for a string, bounds for a number, an enum of distinct values of its type. */
317
+ function scalarSchema(type, f, at, bad) {
318
+ const out = { type };
319
+ const text = type === "string";
320
+ const numeric = type === "number" || type === "integer";
321
+ if (f.pattern !== undefined) {
322
+ if (!text || typeof f.pattern !== "string")
323
+ bad(`${at}.pattern is a regular expression, on a string`);
324
+ else {
325
+ try {
326
+ new RegExp(f.pattern, "u");
327
+ out.pattern = f.pattern;
328
+ }
329
+ catch {
330
+ bad(`${at}.pattern is not a regular expression`);
331
+ }
332
+ }
333
+ }
334
+ if (f.format !== undefined) {
335
+ if (!text || !INPUT_FORMATS.includes(f.format))
336
+ bad(`${at}.format is one of ${INPUT_FORMATS.join(", ")}, on a string`);
337
+ else
338
+ out.format = f.format;
339
+ }
340
+ for (const key of ["minLength", "maxLength"]) {
341
+ if (f[key] === undefined)
342
+ continue;
343
+ if (!text || !(Number.isSafeInteger(f[key]) && f[key] >= 0))
344
+ bad(`${at}.${key} is a whole number of 0 or more, on a string`);
345
+ else
346
+ out[key] = f[key];
347
+ }
348
+ for (const key of ["minimum", "maximum"]) {
349
+ if (f[key] === undefined)
350
+ continue;
351
+ if (!numeric || !(typeof f[key] === "number" && Number.isFinite(f[key])))
352
+ bad(`${at}.${key} is a number, on a number or an integer`);
353
+ else
354
+ out[key] = f[key];
355
+ }
356
+ if (f.enum !== undefined) {
357
+ if (Array.isArray(f.enum) && f.enum.length > 0 && f.enum.every((one) => ofType(type, one)) && new Set(f.enum).size === f.enum.length)
358
+ out.enum = f.enum;
359
+ else
360
+ bad(`${at}.enum is a list of one or more distinct ${type} values`);
361
+ }
362
+ return out;
363
+ }
364
+ /**
365
+ * A package's `inputs` (each run's typed input, the agent's input_schema) or `parameters` (the setup an apply takes),
366
+ * compiled: a closed object schema of each field by its machine name, required unless it says `required: false`. The
367
+ * vocabulary: type, required, title, description, examples, default, enum, pattern, format, minimum/maximum,
368
+ * minLength/maxLength, and `type: array` of a scalar (`items`); nothing else. A default (on a field that is not
369
+ * required) and each example meet their own field. An input named `content` is the run's message: a string. Undefined
370
+ * when the package names none.
371
+ */
372
+ function fieldsSchema(value, of, bad) {
373
+ if (value === undefined)
374
+ return undefined;
375
+ if (!isObject(value) || !Object.keys(value).length)
376
+ return bad(`${of} is a mapping of each field, by its name`), undefined;
377
+ const properties = {};
378
+ const required = [];
379
+ for (const [key, f] of Object.entries(value)) {
380
+ const at = `${of}.${key}`;
381
+ if (!PARAMETER.test(key)) {
382
+ bad(`${at}: a name is lowercase letters, digits and _, starting with a letter, at most 64`);
383
+ continue;
384
+ }
385
+ if (!isObject(f) || !INPUT_TYPES.includes(f.type)) {
386
+ bad(`${at} is {type: ${INPUT_TYPES.join(" | ")}, required?, title?, description?, examples?, default?, enum?, pattern?, format?, minimum?, maximum?, minLength?, maxLength?, items? (an array's scalar)}`);
387
+ continue;
388
+ }
389
+ for (const issue of unknownFields(f, INPUT_KEYS))
390
+ bad(`${at} has no field ${issue.field}: the fields are ${INPUT_KEYS.join(", ")}`);
391
+ if (of === "inputs" && key === "content" && f.type !== "string")
392
+ bad(`${at} is a string: content is the run's message`);
393
+ if (f.required !== undefined && typeof f.required !== "boolean")
394
+ bad(`${at}.required is true or false`);
395
+ for (const word of ["title", "description"])
396
+ if (f[word] !== undefined && !(typeof f[word] === "string" && f[word].trim()))
397
+ bad(`${at}.${word} is text`);
398
+ let schema;
399
+ if (f.type === "array") {
400
+ const items = f.items;
401
+ for (const word of ["pattern", "format", "enum", "minimum", "maximum", "minLength", "maxLength"])
402
+ if (f[word] !== undefined)
403
+ bad(`${at}.${word} goes on its items: a list's keys are type, items and the words`);
404
+ if (!isObject(items) || !SCALAR_TYPES.includes(items.type) || unknownFields(items, ITEM_KEYS).length) {
405
+ bad(`${at}.items is {type: ${SCALAR_TYPES.join(" | ")}} and that scalar's keys: a list is a list of a scalar`);
406
+ continue;
407
+ }
408
+ schema = { type: "array", items: scalarSchema(items.type, items, `${at}.items`, bad) };
409
+ }
410
+ else {
411
+ if (f.items !== undefined)
412
+ bad(`${at}.items is for type: array`);
413
+ schema = scalarSchema(f.type, f, at, bad);
414
+ }
415
+ if (typeof f.title === "string")
416
+ schema.title = f.title;
417
+ if (typeof f.description === "string")
418
+ schema.description = f.description;
419
+ // A default and each example meet the field they are of, as the server checks a value given for it.
420
+ const compiled = schemaCheck(schema);
421
+ const meets = (one) => !("why" in compiled) && !compiled.check(one).length;
422
+ if (f.examples !== undefined) {
423
+ if (Array.isArray(f.examples) && f.examples.length && f.examples.every(meets))
424
+ schema.examples = f.examples;
425
+ else
426
+ bad(`${at}.examples is a list of one or more values it takes`);
427
+ }
428
+ if (f.default !== undefined) {
429
+ if (f.required !== false)
430
+ bad(`${at} is required and has a default: a default is for one that may be left out (required: false)`);
431
+ else if (!meets(f.default))
432
+ bad(`${at}.default is not a value it takes`);
433
+ else
434
+ schema.default = f.default;
435
+ }
436
+ properties[key] = schema;
437
+ if (f.required !== false)
438
+ required.push(key);
439
+ }
440
+ return { type: "object", additionalProperties: false, ...(required.length ? { required } : {}), properties };
441
+ }
442
+ /** Reads the package at `from` (its folder, or its files: PackageFiles) checked whole: a valid package, or PackageError
443
+ * with every problem found. */
444
+ export function readPackage(from) {
445
+ const src = typeof from === "string" ? folderFiles(from) : from;
446
+ const dir = src.where;
161
447
  const problems = [];
162
448
  const bad = (where, message) => void problems.push(`${where}: ${message}`);
163
449
  /** The regular files under `sub`, by path from it with forward slashes; a link or any other kind of entry is a
164
450
  * problem (a package is read from disk, and a link would carry a file from outside it into an agent). */
165
- const files = (sub) => readdirSync(join(dir, sub), { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : 1)).flatMap((entry) => {
451
+ const files = (sub) => src.entries(sub).sort((a, b) => (a.name < b.name ? -1 : 1)).flatMap((entry) => {
166
452
  const path = sub ? `${sub}/${entry.name}` : entry.name;
167
453
  if (entry.isDirectory())
168
454
  return files(path);
@@ -170,11 +456,8 @@ export function readPackage(dir) {
170
456
  return bad(path, "is not a regular file or a folder (links are refused)"), [];
171
457
  return [path];
172
458
  });
173
- const kind = (path) => {
174
- const stat = lstatSync(join(dir, path), { throwIfNoEntry: false });
175
- return stat?.isDirectory() ? "dir" : stat?.isFile() ? "file" : stat ? "other" : undefined;
176
- };
177
- const text = (path) => readFileSync(join(dir, path), "utf8");
459
+ const kind = (path) => src.kind(path);
460
+ const text = (path) => src.text(path);
178
461
  /** A file's YAML front matter and body. */
179
462
  const front = (path, required = true) => {
180
463
  const content = text(path);
@@ -209,26 +492,26 @@ export function readPackage(dir) {
209
492
  };
210
493
  /** `path` is a regular file inside the package. */
211
494
  const inside = (path) => typeof path === "string" && !path.startsWith("/") && !path.split("/").some((part) => part === ".." || part === "." || part === "") && kind(path) === "file";
212
- const name = basename(dir);
213
- if (!lstatSync(dir, { throwIfNoEntry: false })?.isDirectory())
495
+ const name = src.name;
496
+ if (src.kind("") !== "dir")
214
497
  throw new PackageError(dir, ["it is not a folder: a package is one"]);
215
498
  if (kind(MANIFEST) !== "file")
216
499
  throw new PackageError(dir, [`${MANIFEST}: missing: a package is a folder with agent.md (its manifest in the front matter, the agent's instructions in the body)`]);
217
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
500
+ for (const entry of src.entries("")) {
218
501
  if (entry.isDirectory() && !["skills", "rules", "evals"].includes(entry.name))
219
502
  bad(`${entry.name}/`, "a package's folders are skills/, rules/ and evals/");
220
503
  }
221
504
  // Bounded before anything is read: a file, the files together, and how many there are.
222
505
  // The agent's files' bytes (evals/ is the package's own test data, never part of an agent) under POST /v2/agents'
223
506
  // limits, an eval's file under MAX_EVAL_FILE_BYTES alone; every file, evals/ too, counts toward MAX_PACKAGE_FILES. A
224
- // file under evals/ an agent is given all the same (the answer's schema, which ships beside each SKILL.md) keeps the
225
- // agent's limits: checked once the manifest names it, before it is read.
507
+ // file under evals/ an agent is given all the same (the answer's schema, which becomes its output_schema and is in its
508
+ // instructions) keeps the agent's limits: checked once the manifest names it, before it is read.
226
509
  const listed = files("");
227
510
  const all = listed.filter((path) => !path.startsWith("evals/"));
228
- const sizes = all.map((path) => [path, lstatSync(join(dir, path)).size]);
511
+ const sizes = all.map((path) => [path, src.size(path)]);
229
512
  const agentBytes = sizes.reduce((sum, [, size]) => sum + size, 0);
230
513
  const limits = [
231
- ...listed.filter((path) => path.startsWith("evals/") && lstatSync(join(dir, path)).size > MAX_EVAL_FILE_BYTES).map((path) => `${path}: is over ${MAX_EVAL_FILE_BYTES} bytes, an eval file's limit`),
514
+ ...listed.filter((path) => path.startsWith("evals/") && src.size(path) > MAX_EVAL_FILE_BYTES).map((path) => `${path}: is over ${MAX_EVAL_FILE_BYTES} bytes, an eval file's limit`),
232
515
  ...sizes.filter(([, size]) => size > MAX_FILE_BYTES).map(([path]) => `${path}: is over ${MAX_FILE_BYTES} bytes, a package file's limit`),
233
516
  ...(agentBytes > MAX_PACKAGE_BYTES ? [`the package's files are over ${MAX_PACKAGE_BYTES} bytes together, POST /v2/agents' own limit`] : []),
234
517
  ...(listed.length > MAX_PACKAGE_FILES ? [`the package holds over ${MAX_PACKAGE_FILES} files`] : []),
@@ -255,33 +538,51 @@ export function readPackage(dir) {
255
538
  bad(MANIFEST, "author is {name, email?, url?}");
256
539
  if (f.repository !== undefined && !(typeof f.repository === "string" && URL.canParse(f.repository) && /^https?:$/.test(new URL(f.repository).protocol)))
257
540
  bad(MANIFEST, "repository is an http(s) URL");
541
+ // Display only: what a marketplace page and the console's list file it under, and its tags.
542
+ if (f.category !== undefined && !CATEGORIES.includes(f.category))
543
+ bad(MANIFEST, `category is one of ${CATEGORIES.join(", ")}`);
544
+ const tags = f.tags === undefined ? [] : Array.isArray(f.tags) && f.tags.length <= MAX_TAGS && f.tags.every((tag) => typeof tag === "string" && TAG.test(tag)) && new Set(f.tags).size === f.tags.length ? f.tags : (bad(MANIFEST, `tags is a list of at most ${MAX_TAGS} tags, each once, each lowercase letters, digits and dashes (${TAG.source})`), []);
258
545
  const harness = f.harness === undefined ? undefined : list(f.harness, "harness", (id) => HARNESSES.includes(id));
259
546
  if (harness && !harness.length)
260
547
  bad(MANIFEST, `harness is a non-empty preference list of ${HARNESSES.join(", ")}; leave it out for any`);
261
548
  const ref = (value) => value === undefined || (typeof value === "string" && MODEL_REF.test(value));
262
- if (f.model !== undefined && !(isObject(f.model) && !unknownFields(f.model, ["tier", "prefer", ...MODEL_TIER_NAMES]).length && typeof f.model.tier === "string" && Object.hasOwn(MODEL_TIERS, f.model.tier) && ref(f.model.prefer) && MODEL_TIER_NAMES.every((tier) => ref(f.model[tier]))))
263
- bad(MANIFEST, `model is {tier: ${Object.keys(MODEL_TIERS).join(" | ")}, prefer?: "provider/model-id", ${MODEL_TIER_NAMES.map((tier) => `${tier}?: "provider/model-id"`).join(", ")}}`);
549
+ if (f.model !== undefined && !(isObject(f.model) && !unknownFields(f.model, ["tier", "prefer", ...MODEL_TIER_NAMES, "choices"]).length && typeof f.model.tier === "string" && Object.hasOwn(MODEL_TIERS, f.model.tier) && ref(f.model.prefer) && MODEL_TIER_NAMES.every((tier) => ref(f.model[tier]))))
550
+ bad(MANIFEST, `model is {tier: ${Object.keys(MODEL_TIERS).join(" | ")}, prefer?: "provider/model-id", ${MODEL_TIER_NAMES.map((tier) => `${tier}?: "provider/model-id"`).join(", ")}, choices?: [${CHOICE_WORDS}]}`);
551
+ // The named models an owner may pick one of at install; the package's own tier and preference stay the default.
552
+ const choices = isObject(f.model) && f.model.choices !== undefined ? modelChoices(f.model.choices, harness, (message) => bad(MANIFEST, message)) : undefined;
264
553
  if (f.effort !== undefined && !THINKING_LEVELS.includes(f.effort))
265
554
  bad(MANIFEST, `effort is one of ${THINKING_LEVELS.join(", ")}`);
266
555
  const tools = f.tools === undefined ? undefined : list(f.tools, "tools");
267
- if (tools?.some((tool) => tool.startsWith("mcp:")))
556
+ if (tools?.some(isMcpName))
268
557
  bad(MANIFEST, "tools grants no MCP tool: mcp lists them, by server");
269
- for (const tool of tools?.filter((tool) => !tool.startsWith("mcp:") && !BOUND_TOOLS.includes(tool)) ?? [])
270
- bad(MANIFEST, `tools: ${tool} is not a tool this server binds (${BOUND_TOOLS.join(", ")})`);
558
+ // A monid endpoint (monid:<provider>/<endpoint> or monid:<provider>/*) is granted as written and pinned at the apply's save.
559
+ for (const tool of tools?.filter((tool) => !isMcpName(tool) && !(isMonidName(tool) && parseToolName(tool)) && !BOUND_TOOLS.includes(tool)) ?? [])
560
+ bad(MANIFEST, isMonidName(tool) ? `tools: ${MONID_NAME_WORDS(tool)}` : `tools: ${tool} is not a tool this server binds (${BOUND_TOOLS.join(", ")})`);
271
561
  const mcp = [];
272
- for (const [i, need] of (f.mcp === undefined ? [] : Array.isArray(f.mcp) ? f.mcp : (bad(MANIFEST, "mcp is a list of {server, tools, required?}"), [])).entries()) {
562
+ // Each need by where its tools come from (source, toolkit), never by a saved server's name: the package names its tools
563
+ // mcp:<toolkit>/<tool>, and apply maps the toolkit to the server the owner saved for it.
564
+ for (const [i, need] of (f.mcp === undefined ? [] : Array.isArray(f.mcp) ? f.mcp : (bad(MANIFEST, "mcp is a list of {source, toolkit, tools, required?, reason?, allow?, pin?}"), [])).entries()) {
273
565
  const names = isObject(need) && Array.isArray(need.tools) ? need.tools : [];
274
566
  const allow = isObject(need) && need.allow !== undefined ? need.allow : [];
275
567
  const pin = isObject(need) && need.pin !== undefined ? need.pin : {};
276
- const ok = isObject(need) && !unknownFields(need, ["server", "tools", "required", "allow", "pin"]).length && typeof need.server === "string" && MCP_SERVER_NAME.test(need.server) && names.length > 0 && names.every((tool) => typeof tool === "string" && MCP_TOOL.test(tool)) && new Set(names).size === names.length && (need.required === undefined || typeof need.required === "boolean")
568
+ const reason = isObject(need) ? need.reason : undefined;
569
+ const ok = isObject(need) && !unknownFields(need, ["source", "toolkit", "tools", "required", "reason", "allow", "pin"]).length && MCP_SOURCES.includes(need.source) && typeof need.toolkit === "string" && MCP_SERVER_NAME.test(need.toolkit)
570
+ && names.length > 0 && names.every((tool) => typeof tool === "string" && MCP_TOOL_NAME.test(tool)) && new Set(names).size === names.length && (need.required === undefined || typeof need.required === "boolean")
571
+ && (reason === undefined || (typeof reason === "string" && reason.trim() !== "" && reason.length <= MAX_REASON && !/[\r\n]/.test(reason)))
277
572
  && Array.isArray(allow) && allow.every((tool) => names.includes(tool)) && new Set(allow).size === allow.length;
278
- if (!ok)
279
- bad(MANIFEST, `mcp[${i}] is {server: an MCP server's name (${MCP_SERVER_NAME.source}), tools: its tool names (${MCP_TOOL.source}), none twice, required?: true or false, allow?: the tools of its tools it asks the owner to allow, pin?: {<tool>: {<argument>: <value>}}}`);
280
- else if (mcp.some((m) => m.server === need.server))
281
- bad(MANIFEST, `mcp[${i}]: the server ${need.server} is listed twice`);
573
+ // A toolkit is held to the MCP server name rule (tool-names.ts), so mcp:<toolkit>/<tool> inside the package is a catalog
574
+ // name every place that checks one (an agent's grant, a tool setting, a learned workflow) takes.
575
+ if (isObject(need) && need.toolkit !== undefined && (typeof need.toolkit !== "string" || !MCP_SERVER_NAME.test(need.toolkit)))
576
+ bad(MANIFEST, `mcp[${i}].toolkit ${JSON.stringify(need.toolkit)} is not a toolkit name: ${MCP_SERVER_NAME.source}, the MCP server name rule, since the package names its tools mcp:<toolkit>/<tool>`);
577
+ else if (!ok)
578
+ bad(MANIFEST, `mcp[${i}] is {source: ${MCP_SOURCES.join(" | ")}, toolkit: the toolkit its tools come from, the name the package calls them by (mcp:<toolkit>/<tool>, ${MCP_SERVER_NAME.source}), tools: its tool names (${MCP_TOOL_NAME.source}), none twice, required?: true or false, reason?: one line of at most ${MAX_REASON} characters on why the agent needs them, allow?: the tools of its tools it asks the owner to allow, pin?: {<tool>: {<argument>: <value>}}}`);
579
+ else if (need.source === "github" && need.toolkit !== "github")
580
+ bad(MANIFEST, `mcp[${i}]: a github source's toolkit is github (GitHub's MCP server), not ${need.toolkit}`);
581
+ else if (mcp.some((m) => m.toolkit === need.toolkit))
582
+ bad(MANIFEST, `mcp[${i}]: the toolkit ${need.toolkit} is listed twice: its tools are all mcp:${need.toolkit}/<tool>, so they are one entry`);
282
583
  else {
283
- const pinned = pinOf(pin, need.server, names, `mcp[${i}].pin`, (message) => bad(MANIFEST, message));
284
- mcp.push({ server: need.server, tools: names, required: need.required === true, allow: allow, pin: pinned });
584
+ const pinned = pinOf(pin, need.toolkit, names, `mcp[${i}].pin`, (message) => bad(MANIFEST, message));
585
+ mcp.push({ source: need.source, toolkit: need.toolkit, tools: names, required: need.required === true, ...(typeof reason === "string" ? { reason } : {}), allow: allow, pin: pinned });
285
586
  }
286
587
  }
287
588
  // A policy by tool: bash's alone (bash-read-only.ts), on a package that grants bash or names no tools (a new agent's
@@ -316,47 +617,17 @@ export function readPackage(dir) {
316
617
  // The server's checkout before each run's first turn: the pull request the run's GitHub event names, at its head.
317
618
  if (f.checkout !== undefined && f.checkout !== "pull_request")
318
619
  bad(MANIFEST, "checkout is pull_request: the server checks out the pull request the run's GitHub event names, at its head, in repo/ before the first turn");
319
- const parameters = {};
320
- for (const [key, p] of Object.entries(f.parameters === undefined ? {} : isObject(f.parameters) ? f.parameters : (bad(MANIFEST, "parameters is a mapping of names"), {}))) {
321
- const ok = PARAMETER.test(key) && isObject(p) && !unknownFields(p, ["type", "required", "pattern", "enum", "format", "description", "default"]).length && PARAMETER_TYPES.includes(p.type) && (p.required === undefined || typeof p.required === "boolean") && typeof p.description === "string" && p.description.trim() !== "" && (p.pattern === undefined || (p.type === "string" && typeof p.pattern === "string"));
322
- if (!ok) {
323
- bad(MANIFEST, `parameters.${key} is {type: ${PARAMETER_TYPES.join(" | ")}, required?, pattern? (strings), enum?, format? (strings), default?, description}, its name lowercase`);
324
- continue;
325
- }
326
- try {
327
- if (typeof p.pattern === "string")
328
- new RegExp(p.pattern, "u");
329
- }
330
- catch {
331
- bad(MANIFEST, `parameters.${key}.pattern is not a regular expression`);
332
- }
333
- // What a string's value is (a cron line, a time zone), for a form to ask for it as such.
334
- const format = p.format === undefined ? undefined : p.type === "string" && PARAMETER_FORMATS.includes(p.format) ? p.format : (bad(MANIFEST, `parameters.${key}.format is one of ${PARAMETER_FORMATS.join(", ")}, on a string parameter`), undefined);
335
- // A closed set of values (a form shows a choice, never a pattern): one or more, each of the parameter's type, once.
336
- const choices = p.enum === undefined ? undefined : Array.isArray(p.enum) && p.enum.length > 0 && p.enum.every((one) => ofType(p.type, one)) && new Set(p.enum).size === p.enum.length ? p.enum : (bad(MANIFEST, `parameters.${key}.enum is a list of one or more distinct ${p.type} values`), undefined);
337
- if (choices && typeof p.pattern === "string")
338
- bad(MANIFEST, `parameters.${key} has an enum and a pattern: the enum says the values, so leave the pattern out`);
339
- if (choices && p.default !== undefined && !choices.includes(p.default))
340
- bad(MANIFEST, `parameters.${key}.default is not one of its enum`);
341
- if (p.default !== undefined) {
342
- if (!ofType(p.type, p.default))
343
- bad(MANIFEST, `parameters.${key}.default is a ${p.type}, as the parameter is`);
344
- else if (typeof p.pattern === "string" && typeof p.default === "string" && !safeTest(p.pattern, p.default))
345
- bad(MANIFEST, `parameters.${key}.default does not match its pattern`);
346
- if (p.required === true)
347
- bad(MANIFEST, `parameters.${key} is required and has a default: a default is for a parameter apply may leave out`);
348
- }
349
- parameters[key] = { type: p.type, required: p.required === true, description: p.description, ...(typeof p.pattern === "string" ? { pattern: p.pattern } : {}), ...(choices ? { enum: choices } : {}), ...(format ? { format } : {}), ...(p.default !== undefined && ofType(p.type, p.default) ? { default: p.default } : {}) };
350
- }
620
+ // The setup an apply takes, in the inputs' grammar, by the same compiler; none, a schema of no fields.
621
+ const parameters = fieldsSchema(f.parameters, "parameters", (message) => bad(MANIFEST, message)) ?? { type: "object", additionalProperties: false, properties: {} };
622
+ const fields = fieldsOf(parameters);
623
+ const inputSchema = fieldsSchema(f.inputs, "inputs", (message) => bad(MANIFEST, message));
351
624
  const secrets = list(f.secrets, "secrets", (secret) => /^[A-Z][A-Z0-9_]{0,127}$/.test(secret));
352
625
  for (const secret of secrets.filter((name) => !PACKAGE_SECRETS.includes(name)))
353
626
  bad(MANIFEST, `secrets names ${secret}, a key this server cannot hold: a package needs the keys Settings saves and a run is handed (${PACKAGE_SECRETS.join(", ")})`);
354
- // Each run's limits: its spend cap (per_run_usd, the agent's max_cost_usd) and its tool-call budget (tool_calls, the
355
- // agent's max_tool_calls: each conversation's calls), one of them at least.
627
+ // Each run's limit: its spend cap (per_run_usd, the agent's max_cost_usd), required once a budget is given.
356
628
  const perRun = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
357
- const toolCalls = (value) => Number.isSafeInteger(value) && value > 0 && value <= MAX_TOOL_CALLS;
358
- if (f.budget !== undefined && !(isObject(f.budget) && Object.keys(f.budget).length && !unknownFields(f.budget, ["per_run_usd", "tool_calls"]).length && (f.budget.per_run_usd === undefined || perRun(f.budget.per_run_usd)) && (f.budget.tool_calls === undefined || toolCalls(f.budget.tool_calls))))
359
- bad(MANIFEST, `budget is {per_run_usd?: a number above 0, tool_calls?: a whole number from 1 to ${MAX_TOOL_CALLS}}, one of them at least`);
629
+ if (f.budget !== undefined && !(isObject(f.budget) && !unknownFields(f.budget, ["per_run_usd"]).length && perRun(f.budget.per_run_usd)))
630
+ bad(MANIFEST, "budget is {per_run_usd: a number above 0}");
360
631
  if (f.learning !== undefined && typeof f.learning !== "boolean")
361
632
  bad(MANIFEST, "learning is true or false");
362
633
  if (f.approvals !== undefined && f.approvals !== "ask" && f.approvals !== "never")
@@ -375,19 +646,23 @@ export function readPackage(dir) {
375
646
  triggerNames.add(name);
376
647
  if (!isObject(target) || target.kind !== "start_run" || target.agent_id !== undefined)
377
648
  bad(MANIFEST, `triggers[${i}].target is a start_run with no agent_id: the agent is the one the package makes`);
649
+ // What makes a composio trigger on Composio is this server's to set, at the create: a package carrying it would run on
650
+ // an instance made elsewhere, or move the project's subscription here unasked.
651
+ const source = isObject(trigger) ? trigger.source : undefined;
652
+ const set = isObject(source) && source.kind === "composio" ? COMPOSIO_SET.filter((field) => source[field] !== undefined) : [];
653
+ if (set.length)
654
+ bad(MANIFEST, `triggers[${i}].source holds ${set.join(" and ")}, which this server sets when it makes a composio trigger on Composio: a template can't carry ${set.length > 1 ? "them" : "it"}. Leave ${set.length > 1 ? "them" : "it"} out, or make the trigger from the console on this server (Triggers → New app trigger) once the agent is made.`);
378
655
  });
379
656
  if (triggers.length && !(isObject(f.budget) && f.budget.per_run_usd !== undefined))
380
657
  bad(MANIFEST, "budget is required when the package has triggers: {per_run_usd}, each run's cap");
381
658
  let outputSchema;
382
- let schemaBounded = true;
383
659
  if (f.output !== undefined) {
384
660
  const at = isObject(f.output) ? f.output.schema : undefined;
385
- const evalSize = typeof at === "string" && at.startsWith("evals/") && inside(at) ? lstatSync(join(dir, at)).size : 0;
661
+ const evalSize = typeof at === "string" && at.startsWith("evals/") && inside(at) ? src.size(at) : 0;
386
662
  if (!isObject(f.output) || unknownFields(f.output, ["schema"]).length || !inside(at))
387
663
  bad(MANIFEST, "output is {schema: a JSON Schema file in the package}");
388
664
  else if (evalSize > MAX_FILE_BYTES || agentBytes + evalSize > MAX_PACKAGE_BYTES) {
389
- schemaBounded = false;
390
- bad(at, evalSize > MAX_FILE_BYTES ? `is over ${MAX_FILE_BYTES} bytes, a package file's limit: the answer's schema ships beside each SKILL.md, so it keeps an agent file's limits, under evals/ too` : `takes the agent's files over ${MAX_PACKAGE_BYTES} bytes together, POST /v2/agents' own limit: the answer's schema ships beside each SKILL.md, so it counts as an agent file, under evals/ too`);
665
+ bad(at, evalSize > MAX_FILE_BYTES ? `is over ${MAX_FILE_BYTES} bytes, a package file's limit: the answer's schema is given to the agent, so it keeps an agent file's limits, under evals/ too` : `takes the agent's files over ${MAX_PACKAGE_BYTES} bytes together, POST /v2/agents' own limit: the answer's schema is given to the agent, so it counts as an agent file, under evals/ too`);
391
666
  }
392
667
  else {
393
668
  try {
@@ -400,49 +675,63 @@ export function readPackage(dir) {
400
675
  }
401
676
  }
402
677
  }
403
- const checks = list(f.checks, "checks", (check) => NAME.test(check));
404
678
  const instructions = manifest?.body.trim() ?? "";
405
679
  if (manifest && !instructions)
406
680
  bad(MANIFEST, "its body is empty: the body is the agent's instructions");
407
681
  for (const value of strings([instructions, triggers, f.display_name, mcp.map((need) => need.pin)])) {
408
682
  for (const [, used] of value.matchAll(PLACEHOLDER))
409
- if (!Object.hasOwn(parameters, used))
683
+ if (!Object.hasOwn(fields, used))
410
684
  bad(MANIFEST, `\${parameters.${used}} names no parameter`);
411
685
  }
412
686
  // A placeholder fills text a run reads, a schedule's time (its cron and timezone, read as the schedule at apply), and a
413
- // github trigger's where `in` values (the repository it takes, say); a trigger's other settings are the package's own,
414
- // checked here. A parameter that sets a time has a default, so the schedule the package ships is checked here too; one
415
- // a github trigger takes is required or has a default, so the trigger never fills empty and takes no event.
687
+ // github or webhook trigger's where `in` values (the repository it takes, say); a trigger's other settings are the
688
+ // package's own, checked here. A parameter that sets a time has a default, so the schedule the package ships is checked
689
+ // here too; one a github or webhook trigger's where takes is required or has a default, so the trigger never fills
690
+ // empty and takes no event.
416
691
  triggers.forEach((trigger, i) => {
417
692
  if (!isObject(trigger))
418
693
  return;
419
694
  const timed = isObject(trigger.source) && trigger.source.kind === "schedule";
420
- const github = isObject(trigger.source) && trigger.source.kind === "github";
695
+ const filtered = isObject(trigger.source) && FILTERED_KINDS.includes(trigger.source.kind);
421
696
  const fixed = Object.entries(trigger).flatMap(([key, value]) => key === "target" && isObject(value) ? Object.entries(value).filter(([k]) => k !== "input").map(([k, v]) => [`target.${k}`, v])
422
697
  : key === "source" && timed && isObject(value) ? Object.entries(value).filter(([k]) => !SCHEDULE_FIELDS.includes(k)).map(([k, v]) => [`source.${k}`, v])
423
- : key === "source" && github && isObject(value) ? [[key, whereIns(value).rest]]
424
- : [[key, value]]);
698
+ : key === "source" && filtered && isObject(value) ? [[key, whereIns(value).rest]]
699
+ : key === "enabled" && typeof value === "string" ? []
700
+ : [[key, value]]);
425
701
  for (const [at, value] of fixed)
426
702
  for (const [used] of strings(value).flatMap((text) => [...text.matchAll(PLACEHOLDER)]))
427
- bad(MANIFEST, `triggers[${i}].${at} holds ${used}: a placeholder goes in display_name, the instructions, a trigger's target.input, a schedule's cron and timezone, a github trigger's where in values, or an mcp pin's values`);
428
- if (github) {
703
+ bad(MANIFEST, `triggers[${i}].${at} holds ${used}: a placeholder goes in display_name, the instructions, a trigger's target.input, a schedule's cron and timezone, a github or webhook trigger's where in values, or an mcp pin's values`);
704
+ // enabled is true, false, or one boolean parameter with a default, filled at apply (triggerFilled): the trigger is on
705
+ // or off by the owner's answer, and by the package's default when the apply leaves it out.
706
+ if (typeof trigger.enabled === "string") {
707
+ const rule = `triggers[${i}].enabled is true, false, or one placeholder alone, "\${parameters.<name>}", naming a boolean parameter with a default`;
708
+ const whole = WHOLE.exec(trigger.enabled);
709
+ const spec = whole && Object.hasOwn(fields, whole[1]) ? fields[whole[1]] : undefined;
710
+ if (!whole)
711
+ bad(MANIFEST, rule);
712
+ else if (spec && spec.type !== "boolean")
713
+ bad(MANIFEST, `${rule}: parameters.${whole[1]} is a ${spec.type}`);
714
+ else if (spec && spec.default === undefined)
715
+ bad(MANIFEST, `${rule}: parameters.${whole[1]} has no default, and the trigger is on or off even when the apply leaves it out`);
716
+ }
717
+ if (filtered) {
429
718
  for (const used of new Set(strings(whereIns(trigger.source).ins).flatMap((text) => [...text.matchAll(PLACEHOLDER)].map((m) => m[1])))) {
430
- if (Object.hasOwn(parameters, used) && !parameters[used].required && parameters[used].default === undefined)
431
- bad(MANIFEST, `parameters.${used} is used in triggers[${i}].source.accept, so it is required or has a default: a github trigger filled empty takes no event`);
719
+ if (Object.hasOwn(fields, used) && !parameters.required?.includes(used) && fields[used].default === undefined)
720
+ bad(MANIFEST, `parameters.${used} is used in triggers[${i}].source.accept, so it is required or has a default: a ${trigger.source.kind} trigger filled empty takes no event`);
432
721
  }
433
722
  }
434
723
  if (!timed)
435
724
  return;
436
725
  for (const field of SCHEDULE_FIELDS) {
437
726
  for (const [, used] of strings(trigger.source[field]).flatMap((text) => [...text.matchAll(PLACEHOLDER)])) {
438
- if (Object.hasOwn(parameters, used) && parameters[used].default === undefined)
727
+ if (Object.hasOwn(fields, used) && fields[used].default === undefined)
439
728
  bad(MANIFEST, `parameters.${used} is used in triggers[${i}].source.${field}, so it needs a default: the schedule the package ships is checked with it`);
440
729
  }
441
730
  }
442
731
  });
443
732
  // skills/<name>/SKILL.md, each named as its folder and described, as Agent Skills are; rules/*.md beside each.
444
733
  const skills = {};
445
- const skillDirs = kind("skills") === "dir" ? readdirSync(join(dir, "skills"), { withFileTypes: true }) : [];
734
+ const skillDirs = kind("skills") === "dir" ? src.entries("skills") : [];
446
735
  for (const entry of skillDirs) {
447
736
  if (!entry.isDirectory() || !NAME.test(entry.name)) {
448
737
  bad(`skills/${entry.name}`, "skills/ holds only skill folders, each named in lowercase letters, digits and dashes");
@@ -459,7 +748,7 @@ export function readPackage(dir) {
459
748
  for (const path of own)
460
749
  skills[`${entry.name}/${path}`] = text(`skills/${entry.name}/${path}`);
461
750
  }
462
- const rules = kind("rules") === "dir" ? readdirSync(join(dir, "rules"), { withFileTypes: true }) : [];
751
+ const rules = kind("rules") === "dir" ? src.entries("rules") : [];
463
752
  if (rules.length && !skillDirs.length)
464
753
  bad("rules/", "rules ship beside each skill's SKILL.md, and the package has no skill");
465
754
  for (const entry of rules) {
@@ -475,19 +764,13 @@ export function readPackage(dir) {
475
764
  skills[path] = text(`rules/${entry.name}`);
476
765
  }
477
766
  }
478
- // The answer's schema ships beside each SKILL.md too, as a rule does: the agent reads it there, and the skill names it.
479
- const schemaFile = schemaBounded && isObject(f.output) && inside(f.output.schema) ? f.output.schema : undefined;
480
- for (const skill of schemaFile ? skillDirs.filter((d) => d.isDirectory()) : []) {
481
- const path = `${skill.name}/${basename(schemaFile)}`;
482
- if (Object.hasOwn(skills, path))
483
- bad(schemaFile, `skills/${path} has the same name, and the answer's schema ships beside each SKILL.md`);
484
- else
485
- skills[path] = text(schemaFile);
486
- }
767
+ // The answer's schema is not copied beside each SKILL.md: it becomes the agent's output_schema, which the runner puts in
768
+ // the instructions on every harness (answer-json.ts outputContract). A skill that reads the file itself (a reviewer
769
+ // subagent's guide) keeps it in its own folder.
487
770
  // evals/<case>/: prompt.md (the run's input), graders/*.md (each its type in its front matter), case.yaml and
488
771
  // fixtures/ if it has them. The layout only: no eval runs here.
489
772
  const evals = [];
490
- for (const entry of kind("evals") === "dir" ? readdirSync(join(dir, "evals"), { withFileTypes: true }) : []) {
773
+ for (const entry of kind("evals") === "dir" ? src.entries("evals") : []) {
491
774
  const at = `evals/${entry.name}`;
492
775
  if (!entry.isDirectory() || !NAME.test(entry.name)) {
493
776
  bad(at, "evals/ holds only case folders, each named in lowercase letters, digits and dashes");
@@ -497,12 +780,15 @@ export function readPackage(dir) {
497
780
  const own = files(at).map((path) => path.slice(at.length + 1));
498
781
  for (const path of own.filter((p) => !(p === "prompt.md" || p === "case.yaml" || /^graders\/[^/]+\.md$/.test(p) || p.startsWith("fixtures/"))))
499
782
  bad(`${at}/${path}`, "a case holds prompt.md, graders/*.md, case.yaml and fixtures/ only");
783
+ const caseDoc = own.includes("case.yaml") ? parseDocument(text(`${at}/case.yaml`), { uniqueKeys: true }) : undefined;
784
+ if (caseDoc?.errors.length)
785
+ bad(`${at}/case.yaml`, "is not YAML");
786
+ // An email case's run is its trigger's, on the trigger's input (template-eval.ts): its prompt.md has no body.
787
+ const emailCase = !!caseDoc && !caseDoc.errors.length && isObject(caseDoc.toJS()) && caseDoc.toJS().email !== undefined;
500
788
  if (!own.includes("prompt.md"))
501
789
  bad(at, "has no prompt.md");
502
- else if (!front(`${at}/prompt.md`, false)?.body.trim())
790
+ else if (!emailCase && !front(`${at}/prompt.md`, false)?.body.trim())
503
791
  bad(`${at}/prompt.md`, "its body is empty: the body is the run's input");
504
- if (own.includes("case.yaml") && parseDocument(text(`${at}/case.yaml`), { uniqueKeys: true }).errors.length)
505
- bad(`${at}/case.yaml`, "is not YAML");
506
792
  const graders = own.filter((p) => p.startsWith("graders/"));
507
793
  if (!graders.length)
508
794
  bad(at, "has no graders/*.md");
@@ -512,44 +798,64 @@ export function readPackage(dir) {
512
798
  continue;
513
799
  if (!GRADER_TYPES.includes(grader.data.type))
514
800
  bad(`${at}/${path}`, `type is one of ${GRADER_TYPES.join(", ")}`);
515
- else if (grader.data.type === "schema" && !inside(grader.data.schema))
516
- bad(`${at}/${path}`, "a schema grader names its schema: a JSON Schema file in the package");
517
801
  }
518
802
  }
519
803
  if (problems.length)
520
804
  throw new PackageError(dir, [...new Set(problems)]);
521
805
  const p = {
522
- name, ...(typeof f.display_name === "string" ? { displayName: f.display_name } : {}), version: f.version, description: f.description,
806
+ id: name, origin: null, name, ...(typeof f.display_name === "string" ? { displayName: f.display_name } : {}), version: f.version, description: f.description,
523
807
  ...(typeof f.license === "string" ? { license: f.license } : {}), ...(isObject(f.author) ? { author: f.author } : {}), ...(typeof f.repository === "string" ? { repository: f.repository } : {}),
524
- ...(harness ? { harness } : {}), ...(isObject(f.model) ? { model: f.model } : {}), ...(typeof f.effort === "string" ? { effort: f.effort } : {}),
525
- ...(tools ? { tools } : {}), mcp, ...(computer ? { computer } : {}), ...(toolPolicy ? { toolPolicy } : {}), ...(f.checkout === "pull_request" ? { checkout: "pull_request" } : {}), parameters, secrets, ...(isObject(f.budget) ? { budget: { ...(typeof f.budget.per_run_usd === "number" ? { per_run_usd: f.budget.per_run_usd } : {}), ...(typeof f.budget.tool_calls === "number" ? { tool_calls: f.budget.tool_calls } : {}) } } : {}), ...(typeof f.learning === "boolean" ? { learning: f.learning } : {}), ...(f.approvals === "ask" || f.approvals === "never" ? { approvals: f.approvals } : {}),
526
- triggers: triggers, ...(isObject(f.output) ? { output: { schema: f.output.schema } } : {}), ...(isObject(outputSchema) ? { outputSchema } : {}), checks, instructions, skills, evals,
808
+ ...(typeof f.category === "string" ? { category: f.category } : {}), tags,
809
+ ...(harness ? { harness } : {}), ...(isObject(f.model) ? { model: { ...f.model, ...(choices ? { choices } : {}) } } : {}), ...(typeof f.effort === "string" ? { effort: f.effort } : {}),
810
+ ...(tools ? { tools } : {}), mcp, ...(computer ? { computer } : {}), ...(toolPolicy ? { toolPolicy } : {}), ...(f.checkout === "pull_request" ? { checkout: "pull_request" } : {}), parameters, ...(inputSchema ? { inputSchema } : {}), secrets, ...(isObject(f.budget) ? { budget: { per_run_usd: f.budget.per_run_usd } } : {}), ...(typeof f.learning === "boolean" ? { learning: f.learning } : {}), ...(f.approvals === "ask" || f.approvals === "never" ? { approvals: f.approvals } : {}),
811
+ triggers: triggers, ...(isObject(f.output) ? { output: { schema: f.output.schema } } : {}), ...(isObject(outputSchema) ? { outputSchema } : {}), instructions, skills, evals,
527
812
  };
528
813
  // What an apply makes, made here with each parameter's default, else a sample of its type, and checked as POST
529
814
  // /v2/agents and POST /v2/triggers check their bodies (all but the agent the trigger names, which an apply makes). A
530
815
  // trigger's times are read as of the epoch, so its form is checked here and a date that has passed is the apply's
531
816
  // refusal, never a server's start.
532
- const samples = Object.fromEntries(Object.entries(parameters).map(([key, spec]) => [key, spec.default ?? SAMPLES[spec.type]]));
817
+ const samples = Object.fromEntries(Object.entries(fields).map(([key, spec]) => [key, spec.default ?? (spec.type === "array" ? [sampleOf(spec.items)] : sampleOf(spec))]));
533
818
  const declared = Object.fromEntries(MODEL_TIER_NAMES.flatMap((tier) => (p.model?.[tier] ? [[tier, p.model[tier]]] : [])));
534
- const made = compiled(p, samples, { ...(harness ? { harness: harness[0] } : {}), ...(p.model?.prefer ? { model: p.model.prefer } : {}), ...(Object.keys(declared).length ? { modelTiers: declared } : {}), mcp, defaultTools: [], grants: [] });
819
+ // Every MCP tool ticked, each served under its toolkit's name: the widest agent an apply can make, so each tool the
820
+ // package lists is checked as a grant.
821
+ const every = mcp.flatMap(({ toolkit, tools: listed }) => listed.map((tool) => mcpToolName(toolkit, tool)));
822
+ const made = compiled(p, samples, { ...(harness ? { harness: harness[0] } : {}), ...(p.model?.prefer ? { model: p.model.prefer } : {}), ...(Object.keys(declared).length ? { modelTiers: declared } : {}), mcp: mcp.map((need) => ({ ...need, server: need.toolkit })), defaultTools: [], grants: every });
535
823
  for (const issue of definitionBodyIssues(made.agent))
536
824
  bad(issue.field.startsWith("skills.") ? `skills/${issue.field.slice("skills.".length)}` : MANIFEST, `${issue.field.startsWith("skills.") ? "" : `the agent it makes: ${issue.field}: `}${issue.message}`);
537
- for (const issue of madeTriggerIssues(made.triggers, 0))
538
- bad(MANIFEST, `${issue.field.replace(/^triggers\.(\d+)\./, "triggers[$1].")}: ${issue.message}`);
825
+ // A sample stands in for a value apply is given: at a target.input field a parameter with no default fills whole, what
826
+ // hangs on the value (a pattern, a bound, a choice) is the apply's, on the value given. Its type, and whether the
827
+ // inputs name the field at all, are checked here.
828
+ const sampled = (field) => {
829
+ const at = /^triggers\.(\d+)\.target\.input\.([^.]+)/.exec(field);
830
+ const target = at ? p.triggers[Number(at[1])]?.target : undefined;
831
+ const value = at && isObject(target) && isObject(target.input) ? target.input[at[2]] : undefined;
832
+ const whole = typeof value === "string" ? WHOLE.exec(value) : null;
833
+ return !!whole && Object.hasOwn(fields, whole[1]) && fields[whole[1]].default === undefined;
834
+ };
835
+ // A trigger's enabled given as text is said above, by its own rule, not again as POST /v2/triggers words it.
836
+ const saidEnabled = (field) => {
837
+ const at = /^triggers\.(\d+)\.enabled$/.exec(field);
838
+ return !!at && typeof p.triggers[Number(at[1])]?.enabled === "string";
839
+ };
840
+ for (const issue of madeTriggerIssues(made.triggers, 0, p.inputSchema))
841
+ if (!saidEnabled(issue.field) && (["wrong_type", "not_allowed", "missing"].includes(issue.reason) || !sampled(issue.field)))
842
+ bad(MANIFEST, `${issue.field.replace(/^triggers\.(\d+)\./, "triggers[$1].")}: ${issue.message}`);
539
843
  if (problems.length)
540
844
  throw new PackageError(dir, [...new Set(problems)]);
541
845
  return p;
542
846
  }
543
847
  /** What is wrong with the trigger bodies an apply makes (compiled's `triggers`), as POST /v2/triggers checks a body, all
544
848
  * but the agent each names (the one the apply makes), as of `now`, each field under `triggers.<i>`. A trigger's input is
545
- * its runs' input, and a package's agent is agentic, so each input is checked against DEFAULT_INPUT_SCHEMA too. The
546
- * validator runs it as of the epoch (a time's form only); an apply runs it before it makes anything. */
547
- export function madeTriggerIssues(made, now) {
849
+ * its runs' input, and a package's agent is agentic, so each input is checked against the package's input schema in
850
+ * force too (`inputSchema`, its `inputs` compiled: inputSchemaOf). The validator runs it as of the epoch (a time's form
851
+ * only); an apply runs it before it makes anything. */
852
+ export function madeTriggerIssues(made, now, inputSchema) {
853
+ const schema = inputSchemaOf(inputSchema);
548
854
  return made.flatMap((trigger, i) => {
549
855
  const issues = triggerBodyIssues(TRIGGER_ADAPTERS, { ...trigger, target: { ...trigger.target, agent_id: SAMPLE_AGENT } }, now);
550
856
  const input = isObject(trigger.target) ? trigger.target.input : undefined;
551
857
  if (isObject(input))
552
- issues.push(...inputIssues(input, DEFAULT_INPUT_SCHEMA, "target.input"));
858
+ issues.push(...inputIssues(input, schema, "target.input"));
553
859
  return issues.map((issue) => ({ ...issue, field: `triggers.${i}.${issue.field}` }));
554
860
  });
555
861
  }
@@ -560,22 +866,77 @@ export function readPackages(dir = TEMPLATES_DIR) {
560
866
  /** A package as GET /v2/templates lists it: what an apply asks for and makes. */
561
867
  export function packageView(p) {
562
868
  return {
869
+ id: p.id, bundled: p.origin === null, source: p.origin?.source ?? null, sha: p.origin?.sha ?? null, publisher: p.origin?.publisher ?? null,
563
870
  name: p.name, display_name: p.displayName ?? null, version: p.version, description: p.description, license: p.license ?? null, author: p.author ?? null, repository: p.repository ?? null,
871
+ category: p.category ?? null, tags: p.tags,
564
872
  output: p.output ? { schema: p.output.schema, json_schema: p.outputSchema ?? null } : null,
565
- harness: p.harness ?? null, model: p.model ?? null, effort: p.effort ?? null, tools: p.tools ?? null, tool_policy: p.toolPolicy ?? null, computer: p.computer ?? null, checkout: p.checkout ?? null,
566
- mcp: p.mcp.map(({ server, tools, required, allow, pin }) => ({ server, required, tools: tools.map((name) => ({ name, tool: mcpToolName(server, name), asks: allow.includes(name) ? "allow" : "ask", ...(Object.hasOwn(pin, name) ? { pin: pin[name] } : {}) })) })), parameters: p.parameters, secrets: p.secrets,
873
+ harness: p.harness ?? null, model: modelView(p.model), effort: p.effort ?? null, tools: p.tools ?? null, tool_policy: p.toolPolicy ?? null, computer: p.computer ?? null, checkout: p.checkout ?? null,
874
+ mcp: p.mcp.map(({ source, toolkit, tools, required, reason, allow, pin }) => ({ source, toolkit, required, reason: reason ?? null, tools: tools.map((name) => ({ name, tool: mcpToolName(toolkit, name), asks: allow.includes(name) ? "allow" : "ask", ...(Object.hasOwn(pin, name) ? { pin: pin[name] } : {}) })) })), parameters: p.parameters, input_schema: p.inputSchema ?? null, secrets: p.secrets,
567
875
  budget: p.budget ?? null, learning: p.learning ?? false, approvals_default: p.approvals ?? "ask", triggers: p.triggers, skills: Object.keys(p.skills).filter((path) => /^[^/]+\/SKILL\.md$/.test(path)).map((path) => path.slice(0, -"/SKILL.md".length)), evals: p.evals,
568
876
  };
569
877
  }
570
- /** POST /v2/templates/{name}/apply's body (`{parameters, grants?, overrides?: {model}}`), checked against the package:
571
- * the parameters as given, the MCP tools the owner allows (each one the package lists, by its gate name), and the model
572
- * asked for in place of the package's. 422 naming every field that is wrong. */
878
+ /** A package's model as GET /v2/templates lists it: each choice whole, a warning or note it has none of null. */
879
+ function modelView(model) {
880
+ if (!model)
881
+ return null;
882
+ const { choices, ...rest } = model;
883
+ return { ...rest, ...(choices ? { choices: choices.map(({ id, label, model: ref, harness, warning, note, secrets }) => ({ id, label, model: ref, harness, warning: warning ?? null, note: note ?? null, secrets })) } : {}) };
884
+ }
885
+ /** A package as an import answers it: its listing, and every text its agent would be given, the instructions and each
886
+ * skill file by path (a rule and the answer's schema beside each SKILL.md among them), so a person reads what a third
887
+ * party's package would tell their agent before it is installed. */
888
+ export function packageDetail(p) {
889
+ return { ...packageView(p), instructions: p.instructions, skill_files: { ...p.skills } };
890
+ }
891
+ /** The packages this server serves: the ones it ships, read at its start, and the ones imported here (the store keeps
892
+ * them; the server loads them beside the bundled ones at its start). An id is one package; a bundled one is never
893
+ * replaced or removed, and an imported id (`github:…`) is never a bundled one's name. */
894
+ export class TemplateRegistry {
895
+ bundled;
896
+ imported = new Map();
897
+ constructor(bundled) {
898
+ this.bundled = bundled;
899
+ }
900
+ /** The bundled packages by name, then the imported ones by id. */
901
+ list() {
902
+ return [...this.bundled, ...[...this.imported.values()].sort((a, b) => a.id.localeCompare(b.id))];
903
+ }
904
+ get(id) {
905
+ return this.bundled.find((p) => p.id === id) ?? this.imported.get(id);
906
+ }
907
+ /** An imported package, in place of the one under its id. */
908
+ put(p) {
909
+ if (p.origin === null || this.bundled.some((one) => one.id === p.id))
910
+ throw new TypeError(`${p.id} is a bundled package's id`);
911
+ this.imported.set(p.id, p);
912
+ }
913
+ /** Whether an imported package of that id was there to remove. */
914
+ remove(id) {
915
+ return this.imported.delete(id);
916
+ }
917
+ }
918
+ /** POST /v2/templates/{name}/apply's body (`{parameters, grants?, overrides?: {model?, choice?, approvals?}}`), checked
919
+ * against the package: the parameters as given (a blank one at its default), the MCP tools the owner allows (each one the
920
+ * package lists, by its gate name), and the model asked for in place of the package's: one of its own (`model`), or one
921
+ * of the package's model choices by id (`choice`), never both. 422 naming every field that is wrong. */
573
922
  export function applyBodyOf(p, body) {
574
- const issues = unknownFields(body, ["parameters", "grants", "overrides"]);
575
- const listed = p.mcp.flatMap(({ server, tools }) => tools.map((tool) => mcpToolName(server, tool)));
923
+ const issues = unknownFields(body, ["parameters", "grants", "servers", "overrides"]);
924
+ const listed = p.mcp.flatMap(({ toolkit, tools }) => tools.map((tool) => mcpToolName(toolkit, tool)));
576
925
  const grants = [];
577
926
  if (body.grants !== undefined && !Array.isArray(body.grants))
578
- issues.push({ field: "grants", reason: "wrong_type", message: "grants is a list of the package's MCP tools, by gate name (mcp:<server>/<tool>), the owner allows" });
927
+ issues.push({ field: "grants", reason: "wrong_type", message: "grants is a list of the package's MCP tools, by the package's own names (mcp:<toolkit>/<tool>), the owner allows" });
928
+ // The owner's pick of a saved server for a toolkit (when several match): checked against what is saved at apply.
929
+ const servers = {};
930
+ if (body.servers !== undefined && !isObject(body.servers))
931
+ issues.push({ field: "servers", reason: "wrong_type", message: "servers is an object: {<toolkit>: <the saved MCP server's name>}, for a need several saved servers match" });
932
+ for (const [toolkit, name] of Object.entries(isObject(body.servers) ? body.servers : {})) {
933
+ if (!p.mcp.some((need) => need.toolkit === toolkit))
934
+ issues.push({ field: `servers.${toolkit}`, reason: "not_allowed", message: `The package ${p.name} uses no toolkit ${toolkit}: its MCP needs are ${p.mcp.map((need) => need.toolkit).join(", ") || "none"}.` });
935
+ else if (typeof name !== "string" || !MCP_SERVER_NAME.test(name))
936
+ issues.push({ field: `servers.${toolkit}`, reason: "wrong_type", message: `servers.${toolkit} is the name of a saved MCP server` });
937
+ else
938
+ servers[toolkit] = name;
939
+ }
579
940
  for (const [i, grant] of (Array.isArray(body.grants) ? body.grants : []).entries()) {
580
941
  if (typeof grant !== "string" || !listed.includes(grant))
581
942
  issues.push({ field: `grants.${i}`, reason: "not_allowed", message: `grants.${i} is not a tool of the package ${p.name}: it grants ${listed.join(", ") || "no MCP tool"}.` });
@@ -585,46 +946,43 @@ export function applyBodyOf(p, body) {
585
946
  const given = body.parameters ?? {};
586
947
  if (!isObject(given))
587
948
  issues.push({ field: "parameters", reason: "wrong_type", message: "parameters is an object of the package's parameters, by name" });
588
- const parameters = {};
589
- for (const [key, value] of Object.entries(isObject(given) ? given : {})) {
590
- const spec = Object.hasOwn(p.parameters, key) ? p.parameters[key] : undefined;
591
- const typed = spec && ofType(spec.type, value);
592
- if (!spec)
593
- issues.push({ field: `parameters.${key}`, reason: "not_allowed", message: `The package ${p.name} takes no parameter ${key}.` });
594
- else if (!typed)
595
- issues.push({ field: `parameters.${key}`, reason: "wrong_type", message: `parameters.${key} is a ${spec.type}: ${spec.description}` });
596
- else if (spec.enum && !spec.enum.includes(value))
597
- issues.push({ field: `parameters.${key}`, reason: "not_an_option", message: `parameters.${key} is one of ${spec.enum.join(", ")}: ${spec.description}` });
598
- else if (spec.pattern && !new RegExp(spec.pattern, "u").test(value))
599
- issues.push({ field: `parameters.${key}`, reason: "bad_format", message: `parameters.${key} is ${spec.description}` });
600
- else
601
- parameters[key] = value;
602
- }
603
- for (const [key, spec] of Object.entries(p.parameters)) {
604
- const absent = isObject(given) && (!Object.hasOwn(given, key) || given[key] === undefined || given[key] === "");
605
- if (spec.required && absent)
606
- issues.push({ field: `parameters.${key}`, reason: "missing", message: `parameters.${key} is required: ${spec.description}` });
607
- else if (absent && spec.default !== undefined)
608
- parameters[key] = spec.default;
609
- }
949
+ // A parameter left blank (left out, or "") takes its default; then they are checked as a run's input is (the same
950
+ // compiler, the same words), so a blank required one is missing.
951
+ // A declared parameter given blank is left out (its default filled); an undeclared one stays, for the check to refuse.
952
+ const fields = fieldsOf(p.parameters);
953
+ const blank = (key) => !isObject(given) || givenOf(given, key) === undefined || given[key] === "";
954
+ const parameters = Object.fromEntries([
955
+ ...Object.entries(isObject(given) ? given : {}).filter(([key]) => !blank(key) || !Object.hasOwn(fields, key)),
956
+ ...Object.entries(fields).filter(([key, spec]) => blank(key) && spec.default !== undefined).map(([key, spec]) => [key, spec.default]),
957
+ ]);
958
+ if (isObject(given))
959
+ issues.push(...inputIssues(parameters, p.parameters, "parameters"));
610
960
  const overrides = body.overrides ?? {};
611
961
  if (!isObject(overrides))
612
- issues.push({ field: "overrides", reason: "wrong_type", message: "overrides is an object: {model?, approvals?}" });
613
- else {
614
- issues.push(...unknownFields(overrides, ["model", "approvals"]).map((i) => ({ ...i, field: `overrides.${i.field}`, message: "An apply overrides the model and the approvals alone." })));
962
+ issues.push({ field: "overrides", reason: "wrong_type", message: "overrides is an object: {model?, choice?, approvals?}" });
963
+ const choices = p.model?.choices ?? [];
964
+ const choice = isObject(overrides) ? choices.find((one) => one.id === overrides.choice) : undefined;
965
+ if (isObject(overrides)) {
966
+ issues.push(...unknownFields(overrides, ["model", "choice", "approvals"]).map((i) => ({ ...i, field: `overrides.${i.field}`, message: "An apply overrides the model (one of its own, or one of the package's choices) and the approvals alone." })));
615
967
  if (overrides.approvals !== undefined && !APPROVALS.includes(overrides.approvals))
616
968
  issues.push({ field: "overrides.approvals", reason: "not_an_option", message: `overrides.approvals is one of ${APPROVALS.join(", ")}: never runs the agent unattended, while a deny still refuses` });
617
969
  if (overrides.model !== undefined && !(typeof overrides.model === "string" && MODEL_REF.test(overrides.model)))
618
970
  issues.push({ field: "overrides.model", reason: "bad_format", message: 'overrides.model is "provider/model-id"' });
971
+ // A choice is the package's model and harness together; a model of the owner's own says something else: never both.
972
+ if (overrides.choice !== undefined && overrides.model !== undefined)
973
+ issues.push({ field: "overrides.choice", reason: "not_allowed", message: "overrides.choice and overrides.model say different things: send one, a choice of the package's by its id or a model of your own." });
974
+ else if (overrides.choice !== undefined && !choice)
975
+ issues.push({ field: "overrides.choice", reason: "not_an_option", message: choices.length ? `overrides.choice is one of ${choices.map((one) => one.id).join(", ")}: the package's model choices, by id.` : `The package ${p.name} offers no model choices: leave overrides.choice out.` });
619
976
  }
620
977
  if (issues.length)
621
978
  throw invalid(issues);
622
- return { parameters, grants, ...(isObject(overrides) && typeof overrides.model === "string" ? { model: overrides.model } : {}), ...(isObject(overrides) && (overrides.approvals === "ask" || overrides.approvals === "never") ? { approvals: overrides.approvals } : {}) };
979
+ return { parameters, grants, servers, ...(isObject(overrides) && typeof overrides.model === "string" ? { model: overrides.model } : {}), ...(choice ? { choice } : {}), ...(isObject(overrides) && (overrides.approvals === "ask" || overrides.approvals === "never") ? { approvals: overrides.approvals } : {}) };
623
980
  }
624
981
  /** The model a package's agent gets here, as `{model?, warning?}`: its `prefer` when this server runs it on `harness`
625
- * with a key for its provider, but never through a gateway (AGENT_MODEL_BASE_URL), which never said it serves it: then
626
- * a warning says so. Else the server's model for its tier (hostModel: AGENT_MODEL_FAST, AGENT_MODEL or
627
- * AGENT_MODEL_STRONG, else the default of a model key it holds), unless that is a gateway's own id with no provider,
982
+ * with a key for its provider, else `refused` (preferUnrunnable): apply makes nothing, never the tier's model in its
983
+ * place. Through a gateway (AGENT_MODEL_BASE_URL), which never said it serves `prefer`, it is not used and a warning says
984
+ * so. With no `prefer`, or one skipped there, the server's model for its tier (hostModel: AGENT_MODEL_FAST, AGENT_MODEL
985
+ * or AGENT_MODEL_STRONG, else the default of a model key it holds), unless that is a gateway's own id with no provider,
628
986
  * which no definition can name: then no model, and the agent runs on the server's default (a warning when the tier's
629
987
  * model is not that default). No model either when the package names none or the server has none. */
630
988
  export async function packageModel(env, model, harness) {
@@ -634,8 +992,10 @@ export async function packageModel(env, model, harness) {
634
992
  // owner is told (overrides.model picks one it serves).
635
993
  const gateway = Boolean(env.AGENT_MODEL_BASE_URL);
636
994
  const skipped = model.prefer && gateway ? `model.prefer ${model.prefer} is not used: this server reaches its models through a gateway, which has not said it serves that model.` : undefined;
637
- if (!skipped && model.prefer && harnessRuns(env, model.prefer, harness) && !("why" in (await chooseModel(env, model.prefer, "default", harness))))
638
- return { model: model.prefer };
995
+ if (model.prefer && !gateway) {
996
+ const refused = await preferUnrunnable(env, model.prefer, harness, Boolean(model.choices?.length));
997
+ return refused ? { refused } : { model: model.prefer };
998
+ }
639
999
  const tier = MODEL_TIERS[model.tier];
640
1000
  const id = hostModel(env, tier, harness);
641
1001
  // A gateway's own id (no provider) is no "provider/model-id" a definition can name: the agent is left to the server's
@@ -648,6 +1008,54 @@ export async function packageModel(env, model, harness) {
648
1008
  const warning = [skipped, runsOn, skipped ? "overrides.model picks another the gateway serves." : undefined].filter(Boolean).join(" ");
649
1009
  return { ...(id && !bare ? { model: id } : {}), ...(warning ? { warning } : {}) };
650
1010
  }
1011
+ /** `model` on `harness` as a save and a run take it (runnable.ts harnessModel, on the harness's own route), and where it
1012
+ * runs, refused all the same when no catalog here lists the entry its runs are priced by (the harness's priceModel):
1013
+ * claude-agent takes any Anthropic id on its own, and a package's model no catalog knows makes an agent whose runs fail
1014
+ * at the provider. A faux model server runs any. */
1015
+ async function modelHere(env, harness, model) {
1016
+ const chosen = await harnessModel(env, harness, model, true);
1017
+ if (!chosen || !("model" in chosen) || env[FAUX_ENV])
1018
+ return chosen;
1019
+ const priced = harnessOf(env, harness)?.priceModel(env, chosen.model) ?? chosen.model;
1020
+ if ((await providerModels(env)).getModel(priced.provider, priced.modelId))
1021
+ return chosen;
1022
+ return { why: `${model} is not a model ${harness} runs here: no model catalog here lists it`, host: false, needs: "model" };
1023
+ }
1024
+ /** Why this server can't run a package's `prefer` on `harness`, and what the owner does about it, as `{why, fix}` in
1025
+ * words; undefined when it can. Asked as a save and a run ask it (runnable.ts harnessModel), on the harness's own
1026
+ * route: codex reaches an OpenAI model through OpenRouter's key alone. A missing key names its provider and Settings → Model keys; a model no catalog here
1027
+ * lists, or one the harness does not run, only another model: overrides.model, or a model choice where the package
1028
+ * has them (`choices`). */
1029
+ async function preferUnrunnable(env, prefer, harness, choices) {
1030
+ const other = `apply with overrides.model${choices ? " or one of the package's model choices (overrides.choice)" : ""}.`;
1031
+ const another = `${other[0].toUpperCase()}${other.slice(1)}`;
1032
+ if (!harnessRuns(env, prefer, harness))
1033
+ return { why: `${harness} does not run it`, fix: another };
1034
+ const chosen = await modelHere(env, harness, prefer);
1035
+ if (chosen && "model" in chosen)
1036
+ return undefined;
1037
+ if (chosen && "why" in chosen && chosen.needs === "model")
1038
+ return { why: "no model catalog here lists it", fix: another };
1039
+ const row = MODEL_KEYS.find((one) => one.id === prefer.slice(0, prefer.indexOf("/")));
1040
+ if (chosen && "why" in chosen && chosen.needs === "key" && row && !env[row.field])
1041
+ return { why: `no ${row.label} key is saved here`, fix: `Save ${/^[AEIOU]/.test(row.label) ? "an" : "a"} ${row.label} key in Settings → Model keys, or ${other}` };
1042
+ return { why: (chosen === undefined ? `${harness} does not run here` : "refused" in chosen ? chosen.refused : chosen.why).replace(/\.$/, ""), fix: another };
1043
+ }
1044
+ /** Why this server can't run a model choice's model on its harness, in words; undefined when it can. As with `prefer`
1045
+ * (packageModel), a choice is never swapped for the tier's model: the owner who picked it gets it, or apply refuses. The
1046
+ * harness is the server's offer of it (`offer`, capabilities' harnesses): one not available here runs nothing. The model
1047
+ * is asked of the harness's own route, as a save and a run ask it (runnable.ts harnessModel). A gateway
1048
+ * (AGENT_MODEL_BASE_URL) never said it serves the model, so a choice is refused there, as `prefer` is skipped. */
1049
+ export async function choiceUnrunnable(env, choice, offer) {
1050
+ if (!offer?.available)
1051
+ return `${choice.harness} is not available here${offer?.reason ? `: ${offer.reason.replace(/\.$/, "")}` : ""}`;
1052
+ if (env.AGENT_MODEL_BASE_URL)
1053
+ return "this server reaches its models through a gateway, which has not said it serves that model; overrides.model picks one it serves";
1054
+ if (!harnessRuns(env, choice.model, choice.harness))
1055
+ return `${choice.harness} does not run that model here`;
1056
+ const chosen = await modelHere(env, choice.harness, choice.model);
1057
+ return chosen === undefined ? `${choice.harness} does not run here` : "refused" in chosen ? chosen.refused : "why" in chosen ? chosen.why : undefined;
1058
+ }
651
1059
  /** What to do where a package's computer list has no shell to take: in the apply's refusal and its fallback warning. */
652
1060
  export const COMPUTER_FIX = "Turn on Archil in Settings → Workspace, or run AgentRun where Docker answers, then apply again to give it a shell.";
653
1061
  /** The first entry of a package's computer list (`[shell, none]`) this server meets now, given the shell it has
@@ -704,23 +1112,28 @@ export async function packageTiers(env, model, harness, own) {
704
1112
  return { ...(Object.keys(tiers).length ? { modelTiers: tiers } : {}), ...(skipped.length ? { warning: skipped.join(" ") } : {}) };
705
1113
  }
706
1114
  /** The bodies an apply makes: POST /v2/agents' (its definition and skill files) and each trigger's, with no agent_id,
707
- * every `${parameters.x}` filled. `mcp`: the package's MCP servers this server has saved, whose tools are granted beside
708
- * the package's tools (or, when it names none, `defaultTools`, those this server gives a new agent), each at the
709
- * owner's own setting; `grants`, the owner's answer at apply, alone are set to allow. A tool the package pins gets its
710
- * pin, filled, in the agent's tool settings, whatever its permission; one whose pin fills empty (its parameter not
711
- * given) is set to deny instead, granted or not, and named in `unpinned` (by gate name, with the parameters not given):
712
- * a send with no destination set never runs. */
1115
+ * every `${parameters.x}` filled. `grants`, the owner's answer at apply (the tools ticked, by the saved servers' names):
1116
+ * of the package's tools on `mcp`, its needs each served by a saved server, those alone are granted, beside the package's
1117
+ * tools (or, when it names none, `defaultTools`, those this server gives a new agent). A grant writes no permission: each
1118
+ * call follows this server's tool settings, so under approvals ask a write asks the owner unless the owner allowed it
1119
+ * there, a read runs where the owner turned on Allow reads for its server and asks otherwise, and a deny the owner set on this server still holds; approvals
1120
+ * never lifts those asks. A tool left unticked is not the agent's at all, so no harness offers it and approvals never,
1121
+ * which lifts an ask of a tool the agent has, has nothing to lift: the owner grants it later in the agent's tools. A
1122
+ * tool the package pins gets its pin, filled, in the agent's tool settings, ticked or not (it holds once the tool is
1123
+ * granted later); one whose pin fills empty (its parameter not given) is set to deny instead, and named in `unpinned`
1124
+ * (by gate name, with the parameters not given): a send with no destination set never runs. */
713
1125
  export function compiled(p, parameters, chosen, _deps) {
714
1126
  const skills = Object.keys(p.skills).filter((path) => /^[^/]+\/SKILL\.md$/.test(path)).map((path) => path.slice(0, -"/SKILL.md".length));
715
- const granted = chosen.mcp.flatMap(({ server, tools }) => tools.map((tool) => mcpToolName(server, tool)));
716
- const allowed = chosen.grants.filter((tool) => granted.includes(tool));
1127
+ // The ticks, in the package's order: never a tool of a server not saved here, nor one the owner did not tick.
1128
+ const granted = chosen.mcp.flatMap(({ server, tools }) => tools.map((tool) => mcpToolName(server, tool))).filter((tool) => chosen.grants.includes(tool));
717
1129
  // The computer its list picked (pickComputer): its tools less the shell tools that computer does not run; a package
718
1130
  // that names none is given that computer's shell tools, as a new agent in a box is given the box's.
719
1131
  const pick = chosen.computer;
720
1132
  const own = pick ? (p.tools ?? pick.defaults).filter((tool) => !pick.dropped.includes(tool)) : p.tools;
721
1133
  const named = own && (p.tools || own.length) ? own : undefined;
722
1134
  const tools = granted.length ? [...(named ?? (pick ? [] : chosen.defaultTools)), ...granted] : named;
723
- const settings = Object.fromEntries(allowed.map((tool) => [tool, { permission: "allow" }]));
1135
+ // No permission for a tick: a grant is no allow (this server's tool settings decide). Only a pin, or a pin's empty fill's deny.
1136
+ const settings = {};
724
1137
  // A tool's policy (bash's read-only), written as its setting, whatever its permission: never one an apply grants. With
725
1138
  // a picked computer, only where the agent's tools hold bash: none for a bash the computer dropped, or never gave.
726
1139
  if (p.toolPolicy && (!pick || tools?.includes("bash")))
@@ -738,15 +1151,17 @@ export function compiled(p, parameters, chosen, _deps) {
738
1151
  name: p.displayName ? filled(p.displayName, parameters) : p.name, description: p.description, instructions: filled(p.instructions, parameters),
739
1152
  ...(chosen.harness ? { harness: chosen.harness } : {}), ...(chosen.model ? { model: chosen.model } : {}), ...(chosen.modelTiers && Object.keys(chosen.modelTiers).length ? { model_tiers: chosen.modelTiers } : {}), ...(p.effort ? { thinking: p.effort } : {}),
740
1153
  ...(pick ? { computer: pick.computer } : {}), ...(tools ? { tools } : {}), ...(Object.keys(settings).length ? { tool_settings: settings } : {}),
741
- ...(p.learning !== undefined ? { learning: p.learning } : {}), ...(p.budget?.per_run_usd ? { max_cost_usd: p.budget.per_run_usd } : {}), ...(p.budget?.tool_calls ? { max_tool_calls: p.budget.tool_calls } : {}), skills,
1154
+ ...(p.learning !== undefined ? { learning: p.learning } : {}), ...(p.budget?.per_run_usd ? { max_cost_usd: p.budget.per_run_usd } : {}), skills,
742
1155
  // The apply's choice: unattended only when it says never (none given: the agent asks).
743
1156
  ...(chosen.approvals === "never" ? { approvals: "never" } : {}),
1157
+ // The package's typed input (manifest `inputs`): what each run's input is checked against, and how the model reads it.
1158
+ ...(isObject(p.inputSchema) ? { input_schema: p.inputSchema } : {}),
744
1159
  // The package's answer schema (manifest `output`): each completed run's structured answer, checked, is its result.output.
745
1160
  ...(isObject(p.outputSchema) ? { output_schema: p.outputSchema } : {}),
746
1161
  // The package's checkout (manifest `checkout`): the server fetches it before each run's first turn.
747
1162
  ...(p.checkout ? { checkout: p.checkout } : {}),
748
1163
  };
749
- return { agent: { definition, skills: { ...p.skills } }, triggers: p.triggers.map((trigger) => filled(trigger, parameters)), unpinned };
1164
+ return { agent: { definition, skills: { ...p.skills } }, triggers: p.triggers.map((trigger) => triggerFilled(trigger, parameters)), unpinned };
750
1165
  }
751
1166
  /** Each pin the package's MCP servers (`mcp`) set, by the tool's gate name, its values filled from `parameters`, and the
752
1167
  * parameters it names that were not given (`empty`, none when it fills whole). */
@@ -756,3 +1171,57 @@ export function filledPins(mcp, parameters) {
756
1171
  return { tool: mcpToolName(server, tool), pin: Object.fromEntries(each.map(([arg, one]) => [arg, one.value])), empty: [...new Set(each.flatMap(([, one]) => one.empty))] };
757
1172
  }));
758
1173
  }
1174
+ /** How the owner sets up a need no saved server matches, in words: the Composio preset with its toolkit and actions,
1175
+ * GitHub's MCP on the App, or any server marked with the toolkit in Settings. */
1176
+ export function mcpSetUp(need) {
1177
+ const tools = need.tools.join(", ");
1178
+ return need.source === "composio" ? `Add it in Settings → MCP servers → Add from Composio, toolkit ${need.toolkit}, actions ${tools}, then apply the template again.`
1179
+ : need.source === "github" ? "Connect GitHub in Settings, then add GitHub's MCP server in Settings → MCP servers with GitHub App access, and apply the template again."
1180
+ : `Add the MCP server that serves ${tools} in Settings → MCP servers and set its toolkit to ${need.toolkit}, then apply the template again.`;
1181
+ }
1182
+ /** Each MCP need of `p` mapped to a saved server here: `candidates`, those whose record is the need's {source, toolkit},
1183
+ * by name; `server`, the owner's pick among them (`picks`, by toolkit), else the one candidate, else none. Never picked
1184
+ * silently: several candidates and no pick is refused (422 under servers.<toolkit>, naming them), and so is a pick that
1185
+ * is not a candidate (an owner never maps a need to a server that says it is something else). */
1186
+ export function serversFor(p, saved, picks) {
1187
+ const issues = [];
1188
+ const mapped = p.mcp.map((need) => {
1189
+ const candidates = saved.filter((one) => one.source === need.source && one.toolkit === need.toolkit).map((one) => one.name).sort();
1190
+ const pick = Object.hasOwn(picks, need.toolkit) ? picks[need.toolkit] : undefined;
1191
+ if (pick !== undefined && !candidates.includes(pick))
1192
+ issues.push({ field: `servers.${need.toolkit}`, reason: "not_an_option", message: `${pick} is not a saved MCP server that is ${need.source} ${need.toolkit}: ${candidates.length ? `${candidates.join(", ")} ${candidates.length === 1 ? "is" : "are"}` : "none is saved here"}.` });
1193
+ else if (pick === undefined && candidates.length > 1)
1194
+ issues.push({ field: `servers.${need.toolkit}`, reason: "missing", message: `Saved MCP servers ${new Intl.ListFormat("en", { type: "conjunction" }).format(candidates)} are each ${need.source} ${need.toolkit}: servers.${need.toolkit} says which one the agent uses.` });
1195
+ const server = pick ?? (candidates.length === 1 ? candidates[0] : null);
1196
+ return { need, server, candidates };
1197
+ });
1198
+ if (issues.length)
1199
+ throw invalid(issues);
1200
+ return mapped;
1201
+ }
1202
+ const SERVER_PART = MCP_SERVER_NAME.source.slice(1, -1);
1203
+ const TOOL_PART = MCP_TOOL_NAME.source.slice(1, -1);
1204
+ /** A catalog MCP name in prose (`mcp:<server>/<tool>` or `mcp:<server>/*`), whole: not the tail of a longer word
1205
+ * (`xmcp:gmail/x`), nor cut short of a longer tool name. */
1206
+ const MCP_NAME_IN_TEXT = new RegExp(`(?<![A-Za-z0-9_.:/-])mcp:${SERVER_PART}/(?:\\*|${TOOL_PART}(?![A-Za-z0-9_-]))`, "g");
1207
+ /** Catalog name `name` on the saved servers of `servers` ({toolkit: saved name}): read (parseToolName), its server swapped
1208
+ * when it is one of the package's toolkits, and written again (formatToolName); a wildcard `mcp:<toolkit>/*` the same
1209
+ * way. Any other name, or one outside the grammar, as it is. */
1210
+ export function onServerName(name, servers) {
1211
+ const parsed = parseToolName(name);
1212
+ if (!parsed || (parsed.kind !== "mcp" && parsed.kind !== "mcp-server") || !Object.hasOwn(servers, parsed.server))
1213
+ return name;
1214
+ return formatToolName({ ...parsed, server: servers[parsed.server] });
1215
+ }
1216
+ /** `text` with each whole catalog MCP name in it on the saved servers' (onServerName), in one pass, so a server named as
1217
+ * another of the package's toolkits is never rewritten twice. */
1218
+ export function onServerNames(text, servers) {
1219
+ if (!Object.keys(servers).some((toolkit) => servers[toolkit] !== toolkit))
1220
+ return text;
1221
+ return text.replace(MCP_NAME_IN_TEXT, (name) => onServerName(name, servers));
1222
+ }
1223
+ /** `p` as the agent an apply makes on `servers` sees it: its instructions and each skill file with the package's tool
1224
+ * names on the saved servers' (onServerNames). Nothing else of it names a server: its pins and allow are by tool. */
1225
+ export function onServers(p, servers) {
1226
+ return { ...p, instructions: onServerNames(p.instructions, servers), skills: Object.fromEntries(Object.entries(p.skills).map(([path, text]) => [path, onServerNames(text, servers)])) };
1227
+ }