@parcha/agentrun-serve 0.1.0-beta.52 → 0.1.0-beta.53

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 (261) hide show
  1. package/CHANGELOG.md +122 -1
  2. package/README.md +213 -24
  3. package/dist/agent-delete.d.ts +5 -6
  4. package/dist/agent-delete.js +30 -67
  5. package/dist/agent-package.d.ts +71 -0
  6. package/dist/agent-package.js +345 -0
  7. package/dist/agents-store.d.ts +26 -20
  8. package/dist/agents-store.js +41 -33
  9. package/dist/api-only.d.ts +26 -6
  10. package/dist/api-only.js +35 -13
  11. package/dist/claude-login.d.ts +1 -0
  12. package/dist/claude-login.js +1 -1
  13. package/dist/cli-learning/cli.d.ts +3 -0
  14. package/dist/cli-learning/cli.js +17 -3
  15. package/dist/cli-learning/connections.js +3 -2
  16. package/dist/cli-learning/schema.js +2 -1
  17. package/dist/cli.js +70 -7
  18. package/dist/composio-preset.d.ts +2 -1
  19. package/dist/composio-preset.js +4 -3
  20. package/dist/composio-triggers.d.ts +4 -0
  21. package/dist/composio-triggers.js +4 -1
  22. package/dist/computer-needs.d.ts +32 -0
  23. package/dist/computer-needs.js +80 -0
  24. package/dist/computer-setting.d.ts +1 -0
  25. package/dist/computer-setting.js +8 -1
  26. package/dist/console/assets/index-BFgyZzF_.js +734 -0
  27. package/dist/console/assets/index-DbilxljH.css +1 -0
  28. package/dist/console/index.html +2 -2
  29. package/dist/console-links.d.ts +1 -0
  30. package/dist/console-links.js +2 -0
  31. package/dist/env-switch.d.ts +14 -0
  32. package/dist/env-switch.js +23 -0
  33. package/dist/errors.d.ts +1 -0
  34. package/dist/errors.js +3 -0
  35. package/dist/eval-previous.js +4 -3
  36. package/dist/fal-price.js +10 -13
  37. package/dist/handed-secret.d.ts +4 -0
  38. package/dist/handed-secret.js +10 -0
  39. package/dist/harness-archive.d.ts +15 -5
  40. package/dist/harness-archive.js +71 -34
  41. package/dist/harness-check.d.ts +2 -1
  42. package/dist/harness-check.js +36 -95
  43. package/dist/harness-egress.d.ts +23 -0
  44. package/dist/harness-egress.js +69 -0
  45. package/dist/harness-recipe-entry.d.ts +71 -0
  46. package/dist/harness-recipe-entry.js +184 -0
  47. package/dist/harness-recipe.d.ts +73 -6
  48. package/dist/harness-recipe.js +185 -31
  49. package/dist/harness-sign-in.d.ts +29 -0
  50. package/dist/harness-sign-in.js +122 -0
  51. package/dist/harness-table.d.ts +21 -0
  52. package/dist/harness-table.js +58 -3
  53. package/dist/harness-zip.d.ts +6 -0
  54. package/dist/harness-zip.js +203 -0
  55. package/dist/ids.d.ts +11 -0
  56. package/dist/ids.js +36 -0
  57. package/dist/learn/commit.d.ts +14 -1
  58. package/dist/learn/commit.js +156 -1
  59. package/dist/learn/compile.js +22 -8
  60. package/dist/learn/folder.d.ts +5 -0
  61. package/dist/learn/folder.js +10 -1
  62. package/dist/learn/learning.sh +15 -3
  63. package/dist/learn/promote.d.ts +2 -2
  64. package/dist/learn/secrets.js +30 -7
  65. package/dist/learning-routes.d.ts +23 -11
  66. package/dist/learning-routes.js +110 -20
  67. package/dist/learning.d.ts +9 -6
  68. package/dist/learning.js +9 -4
  69. package/dist/mcp-gateway.js +15 -2
  70. package/dist/mcp-probe.d.ts +3 -0
  71. package/dist/mcp-probe.js +7 -2
  72. package/dist/mcp-resources.d.ts +44 -0
  73. package/dist/mcp-resources.js +100 -0
  74. package/dist/mcp-servers-store.d.ts +16 -12
  75. package/dist/model.d.ts +4 -4
  76. package/dist/model.js +6 -6
  77. package/dist/native/cli.js +9 -2
  78. package/dist/native/connection.d.ts +2 -2
  79. package/dist/native/connection.js +5 -2
  80. package/dist/native/discovery.d.ts +2 -0
  81. package/dist/native/discovery.js +10 -6
  82. package/dist/native/remote-worker-bridge.js +36 -4
  83. package/dist/native/remote.d.ts +18 -1
  84. package/dist/native/remote.js +126 -37
  85. package/dist/native/schema.d.ts +6 -0
  86. package/dist/native/schema.js +31 -6
  87. package/dist/native/source-account.d.ts +13 -0
  88. package/dist/native/source-account.js +114 -0
  89. package/dist/native/source-capture-hooks.d.ts +5 -0
  90. package/dist/native/source-capture-hooks.js +102 -0
  91. package/dist/native/source-mcp-selection.d.ts +13 -0
  92. package/dist/native/source-mcp-selection.js +72 -0
  93. package/dist/native/source-runtime-tools.d.ts +19 -0
  94. package/dist/native/source-runtime-tools.js +103 -0
  95. package/dist/native/source-snapshot-types.d.ts +138 -0
  96. package/dist/native/source-snapshot-types.js +12 -0
  97. package/dist/native/source-snapshot.d.ts +8 -0
  98. package/dist/native/source-snapshot.js +1201 -0
  99. package/dist/observation/learning.js +3 -2
  100. package/dist/openapi.js +167 -36
  101. package/dist/print.js +1 -1
  102. package/dist/purged-workflow.d.ts +12 -0
  103. package/dist/purged-workflow.js +43 -0
  104. package/dist/run-keys.d.ts +46 -0
  105. package/dist/run-keys.js +109 -0
  106. package/dist/run-launch.d.ts +16 -1
  107. package/dist/run-launch.js +30 -1
  108. package/dist/run-learning-served.d.ts +2 -2
  109. package/dist/run-model-key.d.ts +2 -2
  110. package/dist/run-model-key.js +5 -5
  111. package/dist/run-secrets.d.ts +2 -0
  112. package/dist/run-secrets.js +7 -4
  113. package/dist/run-view.d.ts +17 -0
  114. package/dist/run-view.js +25 -1
  115. package/dist/runner/adapter-loop.d.ts +11 -3
  116. package/dist/runner/adapter-loop.js +138 -22
  117. package/dist/runner/adapter-run-spec.js +25 -12
  118. package/dist/runner/audit.d.ts +2 -0
  119. package/dist/runner/audit.js +9 -1
  120. package/dist/runner/beside.js +2 -1
  121. package/dist/runner/claim-secrets.d.ts +29 -3
  122. package/dist/runner/claim-secrets.js +38 -4
  123. package/dist/runner/cli-run-spec.js +23 -12
  124. package/dist/runner/harness-loops.d.ts +6 -0
  125. package/dist/runner/harness-loops.js +11 -1
  126. package/dist/runner/held.d.ts +4 -0
  127. package/dist/runner/journal-kinds.d.ts +2 -0
  128. package/dist/runner/learned-first.d.ts +2 -0
  129. package/dist/runner/learned-first.js +1 -1
  130. package/dist/runner/learning-end.d.ts +7 -2
  131. package/dist/runner/learning-end.js +22 -10
  132. package/dist/runner/learning-seed.d.ts +9 -3
  133. package/dist/runner/learning-seed.js +2 -2
  134. package/dist/runner/main.d.ts +1 -0
  135. package/dist/runner/main.js +20 -13
  136. package/dist/runner/mcp-claim.js +6 -1
  137. package/dist/runner/mcp-run.d.ts +10 -7
  138. package/dist/runner/mcp-run.js +3 -5
  139. package/dist/runner/monid-run.js +9 -11
  140. package/dist/runner/project-checkpoint.d.ts +35 -0
  141. package/dist/runner/project-checkpoint.js +116 -0
  142. package/dist/runner/project-drain.d.ts +8 -0
  143. package/dist/runner/project-drain.js +25 -0
  144. package/dist/runner/project-host.d.ts +10 -0
  145. package/dist/runner/project-host.js +52 -0
  146. package/dist/runner/promotion.d.ts +14 -6
  147. package/dist/runner/promotion.js +98 -41
  148. package/dist/runner/redact.d.ts +13 -0
  149. package/dist/runner/redact.js +67 -1
  150. package/dist/runner/run-channel.d.ts +9 -0
  151. package/dist/runner/run-channel.js +15 -2
  152. package/dist/runner/run-child-host.d.ts +8 -4
  153. package/dist/runner/run-child-host.js +171 -41
  154. package/dist/runner/run-errors.js +2 -2
  155. package/dist/runner/runner-check.js +5 -2
  156. package/dist/runner/runner.js +26 -9
  157. package/dist/runner/store-secrets.js +7 -3
  158. package/dist/runner/workflow-first.d.ts +4 -0
  159. package/dist/runner/workflow-first.js +13 -0
  160. package/dist/runner/workflow-loop.d.ts +2 -1
  161. package/dist/runner/workflow-loop.js +2 -1
  162. package/dist/runner/workflow-spec.js +1 -1
  163. package/dist/runs-over-store.d.ts +34 -6
  164. package/dist/runs-over-store.js +133 -25
  165. package/dist/sdk/runs.d.ts +11 -1
  166. package/dist/sdk/runs.js +117 -26
  167. package/dist/sdk/schema.js +12 -2
  168. package/dist/sdk/workflows.d.ts +1 -1
  169. package/dist/server.d.ts +68 -32
  170. package/dist/server.js +600 -110
  171. package/dist/skills/agentrun-serve/SKILL.md +2 -1
  172. package/dist/source-sync/adoption.d.ts +15 -0
  173. package/dist/source-sync/adoption.js +36 -0
  174. package/dist/source-sync/auxiliary.d.ts +23 -0
  175. package/dist/source-sync/auxiliary.js +64 -0
  176. package/dist/source-sync/capture-git.d.ts +5 -0
  177. package/dist/source-sync/capture-git.js +272 -0
  178. package/dist/source-sync/capture-project.d.ts +53 -0
  179. package/dist/source-sync/capture-project.js +206 -0
  180. package/dist/source-sync/capture-refusal.d.ts +7 -0
  181. package/dist/source-sync/capture-refusal.js +16 -0
  182. package/dist/source-sync/capture.d.ts +11 -0
  183. package/dist/source-sync/capture.js +22 -0
  184. package/dist/source-sync/checkpoint-gate.d.ts +21 -0
  185. package/dist/source-sync/checkpoint-gate.js +52 -0
  186. package/dist/source-sync/checkpoints.d.ts +66 -0
  187. package/dist/source-sync/checkpoints.js +168 -0
  188. package/dist/source-sync/claim.d.ts +11 -0
  189. package/dist/source-sync/claim.js +48 -0
  190. package/dist/source-sync/destination.d.ts +47 -0
  191. package/dist/source-sync/destination.js +239 -0
  192. package/dist/source-sync/io.d.ts +15 -0
  193. package/dist/source-sync/io.js +52 -0
  194. package/dist/source-sync/local.d.ts +43 -0
  195. package/dist/source-sync/local.js +229 -0
  196. package/dist/source-sync/prepare.d.ts +59 -0
  197. package/dist/source-sync/prepare.js +93 -0
  198. package/dist/source-sync/projects.d.ts +61 -0
  199. package/dist/source-sync/projects.js +130 -0
  200. package/dist/source-sync/registry.d.ts +95 -0
  201. package/dist/source-sync/registry.js +226 -0
  202. package/dist/source-sync/service.d.ts +33 -0
  203. package/dist/source-sync/service.js +118 -0
  204. package/dist/source-sync/skill-edits.d.ts +12 -0
  205. package/dist/source-sync/skill-edits.js +122 -0
  206. package/dist/source-sync/snapshots.d.ts +48 -0
  207. package/dist/source-sync/snapshots.js +448 -0
  208. package/dist/source-sync/types.d.ts +9 -0
  209. package/dist/source-sync/types.js +14 -0
  210. package/dist/source-sync/workspace.d.ts +66 -0
  211. package/dist/source-sync/workspace.js +273 -0
  212. package/dist/store/agent-body.d.ts +4 -0
  213. package/dist/store/agent-body.js +16 -5
  214. package/dist/store/index.d.ts +2 -2
  215. package/dist/store/index.js +1 -1
  216. package/dist/store/schema.d.ts +2 -1
  217. package/dist/store/schema.js +2 -1
  218. package/dist/store/seal.d.ts +5 -1
  219. package/dist/store/seal.js +12 -3
  220. package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
  221. package/dist/store/sqlite/project-checkpoints.js +70 -0
  222. package/dist/store/sqlite/run-launch.d.ts +4 -12
  223. package/dist/store/sqlite/run-launch.js +5 -19
  224. package/dist/store/sqlite/store.js +224 -170
  225. package/dist/store/store.d.ts +116 -39
  226. package/dist/store/store.js +14 -1
  227. package/dist/store-reads/learning.d.ts +2 -2
  228. package/dist/store-view.d.ts +3 -1
  229. package/dist/store-view.js +17 -5
  230. package/dist/template-import.d.ts +10 -2
  231. package/dist/template-import.js +116 -13
  232. package/dist/templates.d.ts +26 -5
  233. package/dist/templates.js +62 -10
  234. package/dist/timeline/index.d.ts +1 -1
  235. package/dist/timeline/index.js +1 -1
  236. package/dist/timeline/timeline.d.ts +5 -0
  237. package/dist/timeline/timeline.js +8 -0
  238. package/dist/tool-plane.d.ts +12 -12
  239. package/dist/tools.d.ts +8 -8
  240. package/dist/trigger-launch-hook.d.ts +47 -0
  241. package/dist/trigger-launch-hook.js +90 -0
  242. package/dist/trigger-targets.d.ts +14 -1
  243. package/dist/trigger-targets.js +20 -0
  244. package/dist/triggers.d.ts +54 -5
  245. package/dist/triggers.js +143 -8
  246. package/dist/uploads-archil.js +1 -1
  247. package/dist/uploads.js +1 -1
  248. package/dist/validate.js +1 -2
  249. package/dist/workspace/computer-for-claim.d.ts +2 -0
  250. package/dist/workspace/computer-for-claim.js +43 -0
  251. package/dist/workspace/paths.d.ts +6 -0
  252. package/dist/workspace/paths.js +6 -0
  253. package/dist/workspace/resolve-computer.d.ts +1 -0
  254. package/dist/workspace/run-tools.d.ts +2 -0
  255. package/dist/workspace/run-tools.js +8 -0
  256. package/launcher/agentrun-serve +1 -1
  257. package/package.json +10 -10
  258. package/skills/agentrun-serve/SKILL.md +2 -1
  259. package/templates/README.md +5 -2
  260. package/dist/console/assets/index-B-D0EM3j.js +0 -733
  261. package/dist/console/assets/index-DlQepP2J.css +0 -1
@@ -1,15 +1,74 @@
1
- // POST /v2/templates/import and the imported packages' life here: read from GitHub (template-source.ts), checked by the one
2
- // checker (templates.ts readPackage, over the files held in memory), stored (store `imported_templates`) and loaded beside
3
- // the bundled packages at each start. The first import stored from a GitHub account needs its owner's "I trust <account>",
4
- // remembered server-side (settings TRUSTED_PUBLISHERS). Nothing in a package runs.
1
+ // POST /v2/templates/import and the imported packages' life here: read from GitHub (template-source.ts), or uploaded whole
2
+ // as its files ({files}, by `agentrun deploy`), checked by the one checker (templates.ts readPackage, over the files held
3
+ // in memory), stored (store `imported_templates`) and loaded beside the bundled packages at each start. The first import
4
+ // stored from a GitHub account needs its owner's "I trust <account>", remembered server-side (settings
5
+ // TRUSTED_PUBLISHERS); an upload needs none, as only this server's owner (its session or its token) sends one, and it
6
+ // goes with the last agent applied from it (store Agents.purge). Nothing in a package runs.
7
+ import { packageSha256 } from "./agent-package.js";
5
8
  import { ApiError, invalid } from "./errors.js";
9
+ import { UPLOAD_PREFIX } from "./store/index.js";
6
10
  import { fetchPackageFiles, ImportRefused, IMPORT_LIMITS, parseSource, resolveSha } from "./template-source.js";
7
- import { memoryFiles, PackageError, readPackage } from "./templates.js";
11
+ import { MANIFEST, manifestName, memoryFiles, PackageError, readPackage } from "./templates.js";
8
12
  import { isObject, unknownFields } from "./validate.js";
9
13
  /** The settings key that holds the GitHub accounts this server's owner trusts as publishers, lower-cased. */
10
14
  export const TRUSTED_PUBLISHERS = "templates.trusted_publishers";
11
- /** The folder name a package's id ends in: its path's last part, else the repository's name (agent.md's `name` is it). */
12
- const nameOf = (id) => id.slice("github:".length).split("/").at(-1);
15
+ /** An uploaded package's id is this and its manifest's name: the next upload of that name replaces it. */
16
+ export { UPLOAD_PREFIX };
17
+ /** The folder name a package's id ends in: an upload's name, else its path's last part, else the repository's name
18
+ * (agent.md's `name` is it). */
19
+ const nameOf = (id) => (id.startsWith(UPLOAD_PREFIX) ? id.slice(UPLOAD_PREFIX.length) : id.slice("github:".length).split("/").at(-1));
20
+ /** An upload's sha: the digest an export names (agent-package.ts packageSha256), which `agentrun deploy` locks. */
21
+ const uploadSha = (files) => packageSha256([...files].map(([path, data]) => ({ path, encoding: "base64", content: data.toString("base64") })));
22
+ const BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
23
+ /** A path part that is not plain, or a character no package path holds (a control character, a backslash). */
24
+ const NOT_PLAIN = (path) => /[\0-\x1f\x7f\\]/.test(path) || path.split("/").some((part) => part === "" || part === "." || part === "..");
25
+ /** An upload's files ({path, encoding, content}) as the package's bytes by path: 422 under files.<i> for one that is not
26
+ * that shape; the GitHub import's own refusals (ImportRefused "package") for a path that is not plain or is there twice,
27
+ * over its count and over the bytes it keeps. */
28
+ function uploadFiles(raw) {
29
+ const shape = "files is a list of {path, encoding, content}: each file of the package, its encoding utf8 or base64";
30
+ if (!Array.isArray(raw) || raw.length === 0)
31
+ throw invalid([{ field: "files", reason: "wrong_type", message: shape }]);
32
+ if (raw.length > IMPORT_LIMITS.files)
33
+ throw new ImportRefused("package", `The package holds over ${IMPORT_LIMITS.files} files.`);
34
+ const issues = [];
35
+ const read = [];
36
+ raw.forEach((one, i) => {
37
+ if (!isObject(one) || typeof one.path !== "string" || typeof one.content !== "string")
38
+ return void issues.push({ field: `files.${i}`, reason: "wrong_type", message: shape });
39
+ for (const issue of unknownFields(one, ["path", "encoding", "content"]))
40
+ issues.push({ ...issue, field: `files.${i}.${issue.field}` });
41
+ if (one.encoding !== "utf8" && one.encoding !== "base64")
42
+ return void issues.push({ field: `files.${i}.encoding`, reason: "not_an_option", message: "encoding is utf8 or base64" });
43
+ if (one.encoding === "base64" && !BASE64.test(one.content))
44
+ return void issues.push({ field: `files.${i}.content`, reason: "invalid", message: `${JSON.stringify(one.path)}'s content is not base64` });
45
+ read.push([one.path, Buffer.from(one.content, one.encoding)]);
46
+ });
47
+ if (issues.length)
48
+ throw invalid(issues);
49
+ const files = new Map();
50
+ let kept = 0;
51
+ for (const [path, data] of read) {
52
+ if (NOT_PLAIN(path))
53
+ throw new ImportRefused("package", `The package holds ${JSON.stringify(path)}, a path that is not plain: refused.`);
54
+ if (files.has(path))
55
+ throw new ImportRefused("package", `The package holds ${JSON.stringify(path)} twice: refused.`);
56
+ kept += data.length;
57
+ if (kept > IMPORT_LIMITS.packageBytes)
58
+ throw new ImportRefused("package", `The package's files are over the ${IMPORT_LIMITS.packageBytes} bytes an import keeps.`);
59
+ files.set(path, data);
60
+ }
61
+ // A path that is a file and a folder's name at once (agent.md and agent.md/x) is no folder a package could be.
62
+ for (const path of files.keys()) {
63
+ const parts = path.split("/");
64
+ for (let end = 1; end < parts.length; end++) {
65
+ const folder = parts.slice(0, end).join("/");
66
+ if (files.has(folder))
67
+ throw new ImportRefused("package", `The package holds ${JSON.stringify(folder)} as a file and as a folder: refused.`);
68
+ }
69
+ }
70
+ return files;
71
+ }
13
72
  /** An imported package read from its files, checked whole, with its id and origin: PackageError when it does not check. */
14
73
  export function importedPackage(id, origin, files) {
15
74
  const read = readPackage(memoryFiles(nameOf(id), `${id}@${origin.sha}`, files));
@@ -28,6 +87,17 @@ export async function loadImported(deps, skipped) {
28
87
  }
29
88
  }
30
89
  }
90
+ /** The uploads served here whose row the store no longer keeps (an agent's purge removed it: Agents.purge), no longer
91
+ * served. Only the package read before the store is removed, so an upload put in meanwhile stays served. */
92
+ export async function dropRemovedUploads(deps) {
93
+ const served = deps.registry.list().filter((pkg) => pkg.origin !== null && pkg.id.startsWith(UPLOAD_PREFIX));
94
+ if (!served.length)
95
+ return;
96
+ const stored = new Set(await deps.store.importedTemplates.ids());
97
+ for (const pkg of served)
98
+ if (!stored.has(pkg.id) && deps.registry.get(pkg.id) === pkg)
99
+ deps.registry.remove(pkg.id);
100
+ }
31
101
  /** Whether `publisher` is one the owner trusts (case-insensitive, as GitHub's account names are). */
32
102
  async function trusted(deps, publisher) {
33
103
  const list = await deps.store.settings.get(TRUSTED_PUBLISHERS);
@@ -64,25 +134,58 @@ function refusalOf(error) {
64
134
  }
65
135
  throw error;
66
136
  }
67
- /** The body POST /v2/templates/import takes, checked: 422 naming each field that is wrong. */
68
- function bodyOf(body) {
69
- const issues = unknownFields(body, ["source", "dry_run", "trust_publisher"]);
137
+ /** The body POST /v2/templates/import takes, checked: 422 naming each field that is wrong. A GitHub source ({source}), or
138
+ * the package's files ({files}, an upload); on an API-only server, the files alone. */
139
+ function bodyOf(body, apiOnly) {
140
+ const issues = unknownFields(body, ["source", "files", "dry_run", "trust_publisher"]);
70
141
  if (body.dry_run !== undefined && typeof body.dry_run !== "boolean")
71
142
  issues.push({ field: "dry_run", reason: "wrong_type", message: "dry_run is true or false" });
72
143
  if (body.trust_publisher !== undefined && typeof body.trust_publisher !== "boolean")
73
144
  issues.push({ field: "trust_publisher", reason: "wrong_type", message: "trust_publisher is true or false" });
74
145
  if (typeof body.source === "string" && body.source.length > 1024)
75
146
  issues.push({ field: "source", reason: "too_long", message: "source is at most 1024 characters" });
147
+ if (body.files !== undefined && body.source !== undefined)
148
+ issues.push({ field: "files", reason: "not_allowed", message: "The body is {source} or {files}: source or files, not both." });
149
+ if (body.files !== undefined && body.trust_publisher !== undefined)
150
+ issues.push({ field: "trust_publisher", reason: "not_allowed", message: "An upload is this server's owner's own package, so an upload asks no publisher's trust: trust_publisher goes with a source alone." });
151
+ if (apiOnly && body.source !== undefined)
152
+ issues.push({ field: "source", reason: "not_allowed", message: "This server serves the API alone: a package is uploaded here as {files}, never read from GitHub." });
76
153
  if (issues.length)
77
154
  throw invalid(issues);
155
+ if (body.files !== undefined)
156
+ return { files: body.files, dryRun: body.dry_run === true };
78
157
  return { source: parseSource(body.source), dryRun: body.dry_run === true, trustPublisher: body.trust_publisher === true };
79
158
  }
159
+ /** An upload: its files checked as an import's are, its id `upload:<name>` (its manifest's name), its sha the package's
160
+ * sha256; a dry run answers it, storing nothing; else it is stored and served (201), in place of the one of its name. */
161
+ async function uploadTemplate(deps, raw, dryRun) {
162
+ let pkg;
163
+ let files;
164
+ try {
165
+ files = uploadFiles(raw);
166
+ const id = `${UPLOAD_PREFIX}${manifestName(files.get(MANIFEST)?.toString("utf8") ?? "") ?? ""}`;
167
+ pkg = importedPackage(id, { source: id, sha: uploadSha(files), publisher: "" }, files);
168
+ }
169
+ catch (error) {
170
+ refusalOf(error);
171
+ }
172
+ const replaced = deps.registry.get(pkg.id)?.origin?.sha ?? null;
173
+ if (dryRun)
174
+ return { status: 200, pkg, trusted: true, replaced };
175
+ await deps.store.importedTemplates.put({ id: pkg.id, source: pkg.origin.source, sha: pkg.origin.sha, publisher: "", files: Object.fromEntries([...files].map(([path, data]) => [path, data.toString("base64")])) });
176
+ deps.registry.put(pkg);
177
+ return { status: 201, pkg, trusted: true, replaced };
178
+ }
80
179
  /** POST /v2/templates/import: the package read at its source's commit and checked; a dry run answers it, storing nothing;
81
- * else it is stored and served (201), in place of the one under its id. `signal` ends the read (the request's). */
180
+ * else it is stored and served (201), in place of the one under its id. `signal` ends the read (the request's). An
181
+ * upload ({files}) is uploadTemplate's. */
82
182
  export async function importTemplate(deps, raw, signal) {
83
183
  if (!isObject(raw))
84
- throw invalid([{ field: "body", reason: "wrong_type", message: "The body is {source, dry_run?, trust_publisher?}." }]);
85
- const { source, dryRun, trustPublisher } = bodyOf(raw);
184
+ throw invalid([{ field: "body", reason: "wrong_type", message: "The body is {source, dry_run?, trust_publisher?} or {files, dry_run?}." }]);
185
+ const body = bodyOf(raw, deps.apiOnly === true);
186
+ if ("files" in body)
187
+ return uploadTemplate(deps, body.files, body.dryRun);
188
+ const { source, dryRun, trustPublisher } = body;
86
189
  const read = AbortSignal.any([signal, AbortSignal.timeout(IMPORT_LIMITS.ms)]);
87
190
  let pkg;
88
191
  let files;
@@ -41,6 +41,9 @@ export declare const MAX_PACKAGE_FILES = 256;
41
41
  /** A file of a package's evals/ (a case's fake MCP server fixture, say), which no agent is given: its own bound, apart
42
42
  * from the agent's files' limits above. The answer's schema is given to the agent, so under evals/ too it keeps those. */
43
43
  export declare const MAX_EVAL_FILE_BYTES: number;
44
+ /** The `name` agent.md's front matter gives (`text`), as text, or undefined: what an upload's folder is named before
45
+ * readPackage checks it whole (the name read as readPackage's front matter reads it). */
46
+ export declare function manifestName(text: string): string | undefined;
44
47
  /** An MCP server a package uses, by where it comes from (`source`, `toolkit`), never by the name an owner saves it under:
45
48
  * inside the package its tools are `mcp:<toolkit>/<tool>`. `tools`, those the agent uses and the package asks the owner to
46
49
  * grant (a consent screen shows each, with `reason`), and `allow`, those of them expected to run without asking (reads);
@@ -79,7 +82,7 @@ export type McpServed = McpNeed & {
79
82
  export declare const fieldsOf: (schema: Json) => Record<string, Json>;
80
83
  /** Where an imported package came from (POST /v2/templates/import): its source as given, ref and all (the ref an upgrade
81
84
  * reads again), the full commit SHA that ref was at when it was read, which is what was imported, and the GitHub account
82
- * that publishes it. */
85
+ * that publishes it. An upload's source is its id, its sha the package's sha256, its publisher empty. */
83
86
  export type PackageOrigin = {
84
87
  source: string;
85
88
  sha: string;
@@ -87,7 +90,8 @@ export type PackageOrigin = {
87
90
  };
88
91
  export type Package = {
89
92
  /** Its identity here, the one apply and delete take: a bundled package's name (`kyb`); an imported one's source without
90
- * its ref (`github:<owner>/<repo>[/<path>]`), so the bundled kyb and an imported kyb are two packages. */
93
+ * its ref (`github:<owner>/<repo>[/<path>]`), so the bundled kyb and an imported kyb are two packages; an upload's
94
+ * `upload:<name>`. */
91
95
  id: string;
92
96
  /** Null for a package this server ships. */
93
97
  origin: PackageOrigin | null;
@@ -123,6 +127,10 @@ export type Package = {
123
127
  /** The computers it prefers, in order (`[shell, none]`): apply takes the first this server meets now (pickComputer)
124
128
  * and writes it as the agent's computer. Absent (or `default` in the manifest): where this server puts a new agent. */
125
129
  computer?: ComputerEntry[];
130
+ /** The programs its sandbox must have on its PATH, or libraries its code loads (`needs`, beside `computer: [shell]` alone): apply writes them onto
131
+ * the sandbox it picks as the agent's `computer.needs`, which each run checks in its box before any model request
132
+ * (computer-needs.ts); it names no image, which stays the server's (AGENTRUN_DOCKER_IMAGE). */
133
+ needs?: string[];
126
134
  /** A policy by tool (bash only: `read-only`, bash-read-only.ts), which apply writes as the tool's `policy` in the
127
135
  * agent's tool settings, so the gate holds its runs to it whatever the tool's permission. */
128
136
  toolPolicy?: {
@@ -158,6 +166,8 @@ export type Package = {
158
166
  instructions: string;
159
167
  /** Skill files by path under the agent's skills folder (`review/SKILL.md`), each rule beside each SKILL.md. */
160
168
  skills: Record<string, string>;
169
+ /** The names of its rules/ files (each one in `skills` beside every SKILL.md), so an export writes them as rules/ again. */
170
+ rules?: string[];
161
171
  evals: string[];
162
172
  };
163
173
  /** A package that does not check: every problem, each naming its file. */
@@ -275,6 +285,7 @@ export declare function packageView(p: Package): {
275
285
  bash: BashPolicy;
276
286
  } | null;
277
287
  computer: ("none" | "shell")[] | null;
288
+ needs: string[] | null;
278
289
  checkout: "pull_request" | null;
279
290
  mcp: {
280
291
  source: "url" | "github" | "composio";
@@ -349,6 +360,7 @@ export declare function packageDetail(p: Package): {
349
360
  bash: BashPolicy;
350
361
  } | null;
351
362
  computer: ("none" | "shell")[] | null;
363
+ needs: string[] | null;
352
364
  checkout: "pull_request" | null;
353
365
  mcp: {
354
366
  source: "url" | "github" | "composio";
@@ -390,10 +402,12 @@ export declare class TemplateRegistry {
390
402
  /** Whether an imported package of that id was there to remove. */
391
403
  remove(id: string): boolean;
392
404
  }
393
- /** POST /v2/templates/{name}/apply's body (`{parameters, grants?, servers?, overrides?: {model?, choice?, approvals?}, agent_id?}`), checked
405
+ /** POST /v2/templates/{name}/apply's body (`{parameters, grants?, servers?, overrides?: {model?, choice?, approvals?}, agent_id?, revision?, sha?, dry_run?}`), checked
394
406
  * against the package: the parameters as given (a blank one at its default), the MCP tools the owner allows (each one the
395
407
  * package lists, by its gate name), and the model asked for in place of the package's: one of its own (`model`), or one
396
- * of the package's model choices by id (`choice`), never both. 422 naming every field that is wrong. */
408
+ * of the package's model choices by id (`choice`), never both. `revision` (with agent_id) and `sha` are what the caller
409
+ * read: the agent's current revision and the package's sha, each held to them (412 when another). 422 naming every field
410
+ * that is wrong. */
397
411
  export declare function applyBodyOf(p: Package, body: Json): {
398
412
  parameters: Json;
399
413
  grants: string[];
@@ -402,6 +416,9 @@ export declare function applyBodyOf(p: Package, body: Json): {
402
416
  choice?: ModelChoice;
403
417
  approvals?: Approvals;
404
418
  agentId?: string;
419
+ revision?: string;
420
+ sha?: string;
421
+ dryRun: boolean;
405
422
  };
406
423
  /** The model a package's agent gets here, as `{model?, warning?}`: its `prefer` when this server runs it on `harness`
407
424
  * with a key for its provider, else `refused` (preferUnrunnable): apply makes nothing, never the tier's model in its
@@ -431,6 +448,7 @@ export declare function choiceUnrunnable(env: NodeJS.ProcessEnv, choice: ModelCh
431
448
  export type PickedSetting = {
432
449
  kind: string;
433
450
  provider?: string;
451
+ needs?: string[];
434
452
  };
435
453
  /** The shell this server can give an agent now (server.ts shellHere): the computer setting that gives it, the shell
436
454
  * tools a run there has (tools.ts shellTools), and the shell in words; else, `none`, why it has none. */
@@ -454,13 +472,16 @@ export type ComputerPick = {
454
472
  };
455
473
  /** What to do where a package's computer list has no shell to take: in the apply's refusal and its fallback warning. */
456
474
  export declare const COMPUTER_FIX = "Turn on Archil in Settings \u2192 Workspace, or run AgentRun where Docker answers, then apply again to give it a shell.";
475
+ /** What to do where a package that needs programs (`needs`) has no sandbox to take: a Docker box whose image has them. */
476
+ export declare const NEEDS_FIX = "Run AgentRun where Docker answers, with Archil off in Settings \u2192 Workspace. Set AGENTRUN_DOCKER_IMAGE to an image that has them and restart the server. For video (chrome, ffmpeg, ffprobe, hyperframes), build the media image: docker build -t agentrun-media:<first 12 hex of its sha256> - < packages/computer/media/Dockerfile, and name that tag. For decks, documents and sheets (python-pptx, python-docx, openpyxl, pptxgenjs, docx, exceljs), build the documents image: docker build -t agentrun-documents:<first 12 hex of the sha256 of its Dockerfile and documents.sh> packages/computer/documents, and name that tag. Then apply again.";
457
477
  /** The first entry of a package's computer list (`[shell, none]`) this server meets now, given the shell it has
458
478
  * (`here`): shell, where it has one; none, always (kind none, and no shell tool: a run on the runner in Mode 2 has bash,
459
479
  * so a shell tool is dropped rather than left to it). Undefined for a package with no list (it runs where a new agent
460
480
  * does); `refused`, in words, when no entry is met. The rule is the package's preference alone: nothing here knows a
461
481
  * template. */
462
- export declare function pickComputer(p: Pick<Package, "name" | "computer" | "tools">, here: ShellHere): ComputerPick | {
482
+ export declare function pickComputer(p: Pick<Package, "name" | "computer" | "tools" | "needs">, here: ShellHere): ComputerPick | {
463
483
  refused: string;
484
+ fix?: string;
464
485
  } | undefined;
465
486
  /** The model of each tier a package's subagents run on here (the definition's model_tiers), as `{modelTiers?, warning?}`:
466
487
  * a tier's model the package names (`model.fast`, `model.strong`) when this server runs it on `harness` with a key for its
package/dist/templates.js CHANGED
@@ -9,6 +9,7 @@ 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
+ import { DOCKER_IMAGE_FIX, needsIssues } from "./computer-needs.js";
12
13
  // Where a package's MCP tools come from (a Composio toolkit, GitHub's MCP server, or any other server by its address): a
13
14
  // saved MCP server records one too, and apply maps each need to a server whose record matches.
14
15
  import { MCP_SOURCES } from "./mcp-sources.js";
@@ -41,7 +42,7 @@ export const GRADER_TYPES = ["llm", "regex", "tool_used", "file_exists", "mailbo
41
42
  /** The entries of a package's `computer` preference list: `shell`, a computer that gives the agent a shell here (bash);
42
43
  * `none`, no shell, the file tools alone. Apply takes the first this server meets now (pickComputer). */
43
44
  export const COMPUTER_ENTRIES = ["shell", "none"];
44
- 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"];
45
+ const FIELDS = ["name", "display_name", "version", "description", "license", "author", "repository", "category", "tags", "harness", "model", "effort", "tools", "mcp", "tool_policy", "computer", "needs", "checkout", "parameters", "inputs", "secrets", "budget", "learning", "approvals", "triggers", "output"];
45
46
  /** What a package is for, shown on a marketplace page and the console's list: display only, never applied. */
46
47
  export const CATEGORIES = ["engineering", "security", "sales", "marketing", "research", "finance", "operations", "compliance", "personal"];
47
48
  const TAG = /^[a-z0-9-]{1,32}$/;
@@ -85,6 +86,23 @@ const PLACEHOLDER = /\$\{parameters\.([^}]*)\}/g;
85
86
  /** Text that is one placeholder alone: it takes the parameter's value with its type (a pin's, a trigger's input's). */
86
87
  const WHOLE = /^\$\{parameters\.([^}]*)\}$/;
87
88
  const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
89
+ /** The `name` agent.md's front matter gives (`text`), as text, or undefined: what an upload's folder is named before
90
+ * readPackage checks it whole (the name read as readPackage's front matter reads it). */
91
+ export function manifestName(text) {
92
+ const match = FRONT.exec(text);
93
+ if (!match)
94
+ return undefined;
95
+ const doc = parseDocument(match[1], { schema: "core", merge: false, uniqueKeys: true, strict: true });
96
+ if (doc.errors.length)
97
+ return undefined;
98
+ try {
99
+ const data = doc.toJS({ maxAliasCount: 0 });
100
+ return isObject(data) && typeof data.name === "string" ? data.name : undefined;
101
+ }
102
+ catch {
103
+ return undefined;
104
+ }
105
+ }
88
106
  /** A package's model choices at most, a choice label's length, and a warning's or a note's. */
89
107
  const MAX_CHOICES = 3;
90
108
  const MAX_CHOICE_LABEL = 40;
@@ -681,6 +699,18 @@ export function readPackage(from, { evalFixtures = true } = {}) {
681
699
  bad(MANIFEST, `computer: [none] gives no shell, so ${shellOnly.join(", ")} would never be granted: add shell to computer, or take ${shellOnly.length === 1 ? "it" : "them"} out of tools`);
682
700
  }
683
701
  }
702
+ // The programs its sandbox must have, checked as a sandbox's computer.needs is: only beside [shell] alone, so a package
703
+ // that needs them is a sandbox's or nothing, never a fallback to no computer.
704
+ let needs;
705
+ if (f.needs !== undefined) {
706
+ const issues = needsIssues(f.needs, "needs");
707
+ for (const issue of issues)
708
+ bad(MANIFEST, issue.message);
709
+ if (computer?.length !== 1 || computer[0] !== "shell")
710
+ bad(MANIFEST, "needs: the programs a sandbox must have, so computer is [shell]: a template that needs them never falls back to no computer, nor runs where a new agent does");
711
+ else if (!issues.length)
712
+ needs = [...f.needs];
713
+ }
684
714
  // The server's checkout before each run's first turn: the pull request the run's GitHub event names, at its head.
685
715
  if (f.checkout !== undefined && f.checkout !== "pull_request")
686
716
  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");
@@ -872,11 +902,13 @@ export function readPackage(from, { evalFixtures = true } = {}) {
872
902
  const rules = kind("rules") === "dir" ? src.entries("rules") : [];
873
903
  if (rules.length && !skillDirs.length)
874
904
  bad("rules/", "rules ship beside each skill's SKILL.md, and the package has no skill");
905
+ const ruleNames = [];
875
906
  for (const entry of rules) {
876
907
  if (!entry.isFile() || !entry.name.endsWith(".md")) {
877
908
  bad(`rules/${entry.name}`, "rules/ holds only .md files");
878
909
  continue;
879
910
  }
911
+ ruleNames.push(entry.name);
880
912
  for (const skill of skillDirs.filter((d) => d.isDirectory())) {
881
913
  const path = `${skill.name}/${entry.name}`;
882
914
  if (Object.hasOwn(skills, path))
@@ -942,8 +974,8 @@ export function readPackage(from, { evalFixtures = true } = {}) {
942
974
  ...(typeof f.license === "string" ? { license: f.license } : {}), ...(isObject(f.author) ? { author: f.author } : {}), ...(typeof f.repository === "string" ? { repository: f.repository } : {}),
943
975
  ...(typeof f.category === "string" ? { category: f.category } : {}), tags,
944
976
  ...(harness ? { harness } : {}), ...(isObject(f.model) ? { model: { ...f.model, ...(choices ? { choices } : {}) } } : {}), ...(typeof f.effort === "string" ? { effort: f.effort } : {}),
945
- ...(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, ...(f.budget.max_requests !== undefined ? { max_requests: f.budget.max_requests } : {}) } } : {}), ...(f.learning !== undefined ? { learning: learningSettingOf(f.learning) } : {}), ...(f.approvals === "ask" || f.approvals === "never" ? { approvals: f.approvals } : {}),
946
- triggers: triggers, ...(isObject(f.output) ? { output: { schema: f.output.schema } } : {}), ...(isObject(outputSchema) ? { outputSchema } : {}), instructions, skills, evals,
977
+ ...(tools ? { tools } : {}), mcp, ...(computer ? { computer } : {}), ...(needs ? { needs } : {}), ...(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, ...(f.budget.max_requests !== undefined ? { max_requests: f.budget.max_requests } : {}) } } : {}), ...(f.learning !== undefined ? { learning: learningSettingOf(f.learning) } : {}), ...(f.approvals === "ask" || f.approvals === "never" ? { approvals: f.approvals } : {}),
978
+ triggers: triggers, ...(isObject(f.output) ? { output: { schema: f.output.schema } } : {}), ...(isObject(outputSchema) ? { outputSchema } : {}), instructions, skills, ...(ruleNames.length ? { rules: ruleNames.sort() } : {}), evals,
947
979
  };
948
980
  // What an apply makes, made here with each parameter's default, else a sample of its type, and checked as POST
949
981
  // /v2/agents and POST /v2/triggers check their bodies (all but the agent the trigger names, which an apply makes). A
@@ -1016,11 +1048,12 @@ export function readPackages(dir = TEMPLATES_DIR) {
1016
1048
  /** A package as GET /v2/templates lists it: what an apply asks for and makes. */
1017
1049
  export function packageView(p) {
1018
1050
  return {
1019
- id: p.id, bundled: p.origin === null, source: p.origin?.source ?? null, sha: p.origin?.sha ?? null, publisher: p.origin?.publisher ?? null,
1051
+ // An upload has no publisher: its own owner sent it.
1052
+ id: p.id, bundled: p.origin === null, source: p.origin?.source ?? null, sha: p.origin?.sha ?? null, publisher: p.origin?.publisher || null,
1020
1053
  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,
1021
1054
  category: p.category ?? null, tags: p.tags,
1022
1055
  output: p.output ? { schema: p.output.schema, json_schema: p.outputSchema ?? null } : null,
1023
- 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,
1056
+ 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, needs: p.needs ?? null, checkout: p.checkout ?? null,
1024
1057
  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,
1025
1058
  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,
1026
1059
  };
@@ -1065,15 +1098,25 @@ export class TemplateRegistry {
1065
1098
  return this.imported.delete(id);
1066
1099
  }
1067
1100
  }
1068
- /** POST /v2/templates/{name}/apply's body (`{parameters, grants?, servers?, overrides?: {model?, choice?, approvals?}, agent_id?}`), checked
1101
+ /** POST /v2/templates/{name}/apply's body (`{parameters, grants?, servers?, overrides?: {model?, choice?, approvals?}, agent_id?, revision?, sha?, dry_run?}`), checked
1069
1102
  * against the package: the parameters as given (a blank one at its default), the MCP tools the owner allows (each one the
1070
1103
  * package lists, by its gate name), and the model asked for in place of the package's: one of its own (`model`), or one
1071
- * of the package's model choices by id (`choice`), never both. 422 naming every field that is wrong. */
1104
+ * of the package's model choices by id (`choice`), never both. `revision` (with agent_id) and `sha` are what the caller
1105
+ * read: the agent's current revision and the package's sha, each held to them (412 when another). 422 naming every field
1106
+ * that is wrong. */
1072
1107
  export function applyBodyOf(p, body) {
1073
- const issues = unknownFields(body, ["parameters", "grants", "servers", "overrides", "agent_id"]);
1108
+ const issues = unknownFields(body, ["parameters", "grants", "servers", "overrides", "agent_id", "revision", "sha", "dry_run"]);
1109
+ if (body.dry_run !== undefined && typeof body.dry_run !== "boolean")
1110
+ issues.push({ field: "dry_run", reason: "wrong_type", message: "dry_run is true or false: true answers the apply's plan and writes nothing" });
1074
1111
  // The agent an update writes onto (the server checks it was made from this package): text, else a 422 with the rest.
1075
1112
  if (body.agent_id !== undefined && !(typeof body.agent_id === "string" && body.agent_id.trim()))
1076
1113
  issues.push({ field: "agent_id", reason: "wrong_type", message: `agent_id is the id of an agent the ${p.name} template made: the apply writes a new revision of it in place of making another` });
1114
+ if (body.revision !== undefined && !(typeof body.revision === "string" && body.revision))
1115
+ issues.push({ field: "revision", reason: "wrong_type", message: "revision is the id of the agent's revision you read (GET /agents/{agent_id} `revision`): the apply writes only while it is still the current one" });
1116
+ else if (body.revision !== undefined && body.agent_id === undefined)
1117
+ issues.push({ field: "revision", reason: "not_allowed", message: "revision is the agent's current revision as you read it, so it goes with agent_id: an apply without one makes a new agent" });
1118
+ if (body.sha !== undefined && !(typeof body.sha === "string" && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(body.sha)))
1119
+ issues.push({ field: "sha", reason: "bad_format", message: "sha is the package's sha as you read it (GET /templates `sha`): a commit's 40 hex characters, or an upload's 64" });
1077
1120
  const listed = p.mcp.flatMap(({ toolkit, tools }) => tools.map((tool) => mcpToolName(toolkit, tool)));
1078
1121
  const grants = [];
1079
1122
  if (body.grants !== undefined && !Array.isArray(body.grants))
@@ -1129,7 +1172,7 @@ export function applyBodyOf(p, body) {
1129
1172
  }
1130
1173
  if (issues.length)
1131
1174
  throw invalid(issues);
1132
- return { parameters, grants, servers, ...(typeof body.agent_id === "string" ? { agentId: body.agent_id.trim() } : {}), ...(isObject(overrides) && typeof overrides.model === "string" ? { model: overrides.model } : {}), ...(choice ? { choice } : {}), ...(isObject(overrides) && (overrides.approvals === "ask" || overrides.approvals === "never") ? { approvals: overrides.approvals } : {}) };
1175
+ return { parameters, grants, servers, dryRun: body.dry_run === true, ...(typeof body.agent_id === "string" ? { agentId: body.agent_id.trim() } : {}), ...(typeof body.revision === "string" ? { revision: body.revision } : {}), ...(typeof body.sha === "string" ? { sha: body.sha } : {}), ...(isObject(overrides) && typeof overrides.model === "string" ? { model: overrides.model } : {}), ...(choice ? { choice } : {}), ...(isObject(overrides) && (overrides.approvals === "ask" || overrides.approvals === "never") ? { approvals: overrides.approvals } : {}) };
1133
1176
  }
1134
1177
  /** The model a package's agent gets here, as `{model?, warning?}`: its `prefer` when this server runs it on `harness`
1135
1178
  * with a key for its provider, else `refused` (preferUnrunnable): apply makes nothing, never the tier's model in its
@@ -1211,6 +1254,8 @@ export async function choiceUnrunnable(env, choice, offer) {
1211
1254
  }
1212
1255
  /** What to do where a package's computer list has no shell to take: in the apply's refusal and its fallback warning. */
1213
1256
  export const COMPUTER_FIX = "Turn on Archil in Settings → Workspace, or run AgentRun where Docker answers, then apply again to give it a shell.";
1257
+ /** What to do where a package that needs programs (`needs`) has no sandbox to take: a Docker box whose image has them. */
1258
+ export const NEEDS_FIX = `Run AgentRun where Docker answers, with Archil off in Settings → Workspace. ${DOCKER_IMAGE_FIX} Then apply again.`;
1214
1259
  /** The first entry of a package's computer list (`[shell, none]`) this server meets now, given the shell it has
1215
1260
  * (`here`): shell, where it has one; none, always (kind none, and no shell tool: a run on the runner in Mode 2 has bash,
1216
1261
  * so a shell tool is dropped rather than left to it). Undefined for a package with no list (it runs where a new agent
@@ -1226,6 +1271,13 @@ export function pickComputer(p, here) {
1226
1271
  const clash = found && found.computer.kind === "sandbox" && runnerOnly.length ? `${found.words} runs ${runnerOnly.join(", ")} nowhere` : undefined;
1227
1272
  const shell = clash ? undefined : found;
1228
1273
  const lack = "none" in here ? here.none : clash ?? "this server has none";
1274
+ // A package that needs programs (its list is [shell] alone) takes a sandbox, whose box each run checks for them: a
1275
+ // shell that is no sandbox (Archil's serverless exec runs on the runner, whose programs no run checks) is refused.
1276
+ if (p.needs && !(shell && shell.computer.kind === "sandbox")) {
1277
+ const why = shell ? `the shell here is ${shell.words}, which is no sandbox` : lack;
1278
+ const list = new Intl.ListFormat("en", { type: "conjunction" }).format(p.needs);
1279
+ return { refused: `The ${p.name} template needs a sandbox that has ${list}, and ${why}. Nothing was created. ${NEEDS_FIX}`, fix: NEEDS_FIX };
1280
+ }
1229
1281
  const entry = p.computer.find((one) => one === "none" || shell);
1230
1282
  if (!entry)
1231
1283
  return { refused: `The ${p.name} template needs a shell, and ${lack}. Nothing was created.` };
@@ -1236,7 +1288,7 @@ export function pickComputer(p, here) {
1236
1288
  ? `${lack.charAt(0).toUpperCase()}${lack.slice(1)}, so the agent was made with the template's next choice, no computer${dropped.length ? `, and without ${without}` : ""}. ${COMPUTER_FIX}`
1237
1289
  : dropped.length && shell ? `The shell here is ${shell.words}, which runs ${runs.join(", ")} alone, so the agent was made without ${without}.` : null;
1238
1290
  return entry === "shell" && shell
1239
- ? { entry, computer: { ...shell.computer }, shell: shell.words, dropped, defaults: [...shell.tools], note }
1291
+ ? { entry, computer: { ...shell.computer, ...(p.needs ? { needs: [...p.needs] } : {}) }, shell: shell.words, dropped, defaults: [...shell.tools], note }
1240
1292
  : { entry, computer: { kind: "none" }, shell: null, dropped, defaults: [], note };
1241
1293
  }
1242
1294
  /** The model of each tier a package's subagents run on here (the definition's model_tiers), as `{modelTiers?, warning?}`:
@@ -6,4 +6,4 @@ export { costLabel, endedUsage, PAGE_CHANGED_ROW, RUN_RESUMED, toolCallWords, TU
6
6
  export { FEEDBACK_SUFFIX, isFeedbackRow, isMessageRow, isUserEntry, MESSAGE_ORIGIN, messageOrigins, NOTE_SUFFIX, originMatcher, originOf, TRIGGER_LABELS, TRIGGER_SOURCES, type MessageOrigin, type TriggerSource } from "./origin.js";
7
7
  export { cut, scrubUrl, scrubUrls } from "./util.js";
8
8
  export { webCut, webShownOf, webWithin, type WebShown } from "./web-calls.js";
9
- export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, type AgentEventLike, type DecisionLike, type EntryLike, type RunMetrics, type SideSpend, type TimelineEvent, type TimelineKind, type TimelineOptions, type ToolMetrics, } from "./timeline.js";
9
+ export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_REFUSED, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, type AgentEventLike, type DecisionLike, type EntryLike, type RunMetrics, type SideSpend, type TimelineEvent, type TimelineKind, type TimelineOptions, type ToolMetrics, } from "./timeline.js";
@@ -6,4 +6,4 @@ export { costLabel, endedUsage, PAGE_CHANGED_ROW, RUN_RESUMED, toolCallWords, TU
6
6
  export { FEEDBACK_SUFFIX, isFeedbackRow, isMessageRow, isUserEntry, MESSAGE_ORIGIN, messageOrigins, NOTE_SUFFIX, originMatcher, originOf, TRIGGER_LABELS, TRIGGER_SOURCES } from "./origin.js";
7
7
  export { cut, scrubUrl, scrubUrls } from "./util.js";
8
8
  export { webCut, webShownOf, webWithin } from "./web-calls.js";
9
- export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, } from "./timeline.js";
9
+ export { answeredRequests, BROWSER_CHARGE, CALL_ENDED_WITH_RUN, compactionAnswers, CALL_REFUSED, CALL_RESULT_CHARS, CAP_REFUSED, CAP_WRAPUP, CAPS, chargedTool, COMPUTER_NOTE, endedOnTurnEndingTool, HOST_PHASE, METRIC_NAMES, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, runMetricsOf, runMetricsWithDecisions, timelineOf, timelineReducer, TOOL_COST, TOOL_STARTED, TOOL_UNMETERED, } from "./timeline.js";
@@ -180,6 +180,11 @@ export declare const chargedTool: (row: TimelineEvent) => string | undefined;
180
180
  * told after the note's "AgentRun server note:" label). A row of its own, the server's ("AgentRun: …", labelled once);
181
181
  * no request, no cost. */
182
182
  export declare const CAP_WRAPUP = "agentrun.cap_wrapup";
183
+ /** A tool call the spend cap's wrap-up refused (serve's wrap-up.ts, the runner's gate): `callId` and the cap it was
184
+ * refused under (`capUsd`), on the run's root. The call's own refused row is its result's; this one is data only, for the
185
+ * run's view (`stopped_for`, `budget_refused_calls`): no row, no request, no cost. A call refused twice (a replay) is
186
+ * one call. */
187
+ export declare const CAP_REFUSED = "agentrun.cap_refused";
183
188
  /** The run's model was told once, on its first request after its claim gave it a computer in place of an earlier
184
189
  * claim's, that the old one is gone with what was on it (`words`, what it was told after the label, as the wrap-up's).
185
190
  * A row of its own, the server's, as the wrap-up's; no request, no cost. */
@@ -101,6 +101,11 @@ export const chargedTool = (row) => !row.usage ? undefined : row.kind === "phase
101
101
  * told after the note's "AgentRun server note:" label). A row of its own, the server's ("AgentRun: …", labelled once);
102
102
  * no request, no cost. */
103
103
  export const CAP_WRAPUP = "agentrun.cap_wrapup";
104
+ /** A tool call the spend cap's wrap-up refused (serve's wrap-up.ts, the runner's gate): `callId` and the cap it was
105
+ * refused under (`capUsd`), on the run's root. The call's own refused row is its result's; this one is data only, for the
106
+ * run's view (`stopped_for`, `budget_refused_calls`): no row, no request, no cost. A call refused twice (a replay) is
107
+ * one call. */
108
+ export const CAP_REFUSED = "agentrun.cap_refused";
104
109
  /** The run's model was told once, on its first request after its claim gave it a computer in place of an earlier
105
110
  * claim's, that the old one is gone with what was on it (`words`, what it was told after the label, as the wrap-up's).
106
111
  * A row of its own, the server's, as the wrap-up's; no request, no cost. */
@@ -788,6 +793,9 @@ function createProjector(options) {
788
793
  const add = (row) => { rows.push(row); out.push(row); };
789
794
  const touch = (row) => { if (!out.includes(row))
790
795
  out.push(row); };
796
+ // The wrap-up's refusal of a call, kept for the run's view: its result row is the call's own.
797
+ if (entry.kind === CAP_REFUSED)
798
+ return out;
791
799
  if (entry.kind === CAP_WRAPUP || entry.kind === COMPUTER_NOTE) {
792
800
  // What the run's model was told near its cap, or after its computer was replaced: the server's row (`origin:
793
801
  // "server"`, in the words of its other rows), no request, no cost, and no message any turn took (its id ends in
@@ -40,11 +40,11 @@ export declare const permissionsOf: (name: string) => readonly Permission[];
40
40
  * give it: the one in force under the server's settings (`permission`), the owner's default (`default_permission`) and
41
41
  * those it may be set to. An agent's read gives the same, the agent's own layer over it (agentTools). */
42
42
  export declare const serverGate: (name: string, settings: ToolSettingsMap, effect?: ToolEffect) => {
43
- default_permission: "ask" | "allow" | "deny";
44
- permissions: ("ask" | "allow" | "deny")[];
43
+ default_permission: "ask" | "deny" | "allow";
44
+ permissions: ("ask" | "deny" | "allow")[];
45
45
  fallback_allow_reads?: true | undefined;
46
46
  allow_reads?: true | undefined;
47
- permission: "ask" | "allow" | "deny";
47
+ permission: "ask" | "deny" | "allow";
48
48
  };
49
49
  /** The run's own tools beyond the table, each its own settings key, allowed by default like a table tool: the learned
50
50
  * workflow a run's pin names runs as `learned_workflow` (learned-workflow.ts LEARNED_WORKFLOW_TOOL), and the host's
@@ -289,17 +289,17 @@ export declare function shellUnavailable(name: string, shell: ShellPlace): Resol
289
289
  * computer setting); a tool of bash's family that leaves out resolves unavailable, saying why (shellUnavailable). */
290
290
  export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSettingsMap, agent: Tooling, order: readonly string[], shell?: ShellPlace, effectOf?: (name: string) => ToolEffect | undefined): ({
291
291
  resolved: Resolution;
292
- permission: "ask" | "allow" | "deny";
292
+ permission: "ask" | "deny" | "allow";
293
293
  permission_from: import("./refusal-words.js").SettingFrom;
294
- default_permission: "ask" | "allow" | "deny";
295
- permissions: ("ask" | "allow" | "deny")[];
294
+ default_permission: "ask" | "deny" | "allow";
295
+ permissions: ("ask" | "deny" | "allow")[];
296
296
  blurb?: string | undefined;
297
297
  name: string;
298
298
  } | {
299
- permission: "ask" | "allow" | "deny";
299
+ permission: "ask" | "deny" | "allow";
300
300
  permission_from: import("./refusal-words.js").SettingFrom;
301
- default_permission: "ask" | "allow" | "deny";
302
- permissions: ("ask" | "allow" | "deny")[];
301
+ default_permission: "ask" | "deny" | "allow";
302
+ permissions: ("ask" | "deny" | "allow")[];
303
303
  blurb?: string | undefined;
304
304
  name: string;
305
305
  } | {
@@ -307,10 +307,10 @@ export declare function agentTools(env: NodeJS.ProcessEnv, settings: ToolSetting
307
307
  provider_from: string;
308
308
  default_provider: string;
309
309
  resolved: Resolution;
310
- permission: "ask" | "allow" | "deny";
310
+ permission: "ask" | "deny" | "allow";
311
311
  permission_from: import("./refusal-words.js").SettingFrom;
312
- default_permission: "ask" | "allow" | "deny";
313
- permissions: ("ask" | "allow" | "deny")[];
312
+ default_permission: "ask" | "deny" | "allow";
313
+ permissions: ("ask" | "deny" | "allow")[];
314
314
  blurb?: string | undefined;
315
315
  name: string;
316
316
  })[];
package/dist/tools.d.ts CHANGED
@@ -341,13 +341,13 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
341
341
  providers?: string[] | undefined;
342
342
  provider?: string | undefined;
343
343
  default_provider?: string | undefined;
344
- resolves?: Record<"opencode" | "codex" | "claude-agent" | "pi", Resolution> | undefined;
345
- why?: Record<"opencode" | "codex" | "claude-agent" | "pi", string> | undefined;
346
- default_permission: "ask" | "allow" | "deny";
347
- permissions: ("ask" | "allow" | "deny")[];
344
+ resolves?: Record<"opencode" | "codex" | "pi" | "claude-agent", Resolution> | undefined;
345
+ why?: Record<"opencode" | "codex" | "pi" | "claude-agent", string> | undefined;
346
+ default_permission: "ask" | "deny" | "allow";
347
+ permissions: ("ask" | "deny" | "allow")[];
348
348
  fallback_allow_reads?: true | undefined;
349
349
  allow_reads?: true | undefined;
350
- permission: "ask" | "allow" | "deny";
350
+ permission: "ask" | "deny" | "allow";
351
351
  harnesses: string[];
352
352
  missing?: string[] | undefined;
353
353
  reason?: string | undefined;
@@ -360,11 +360,11 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
360
360
  name: string;
361
361
  summary: string;
362
362
  } | {
363
- default_permission: "ask" | "allow" | "deny";
364
- permissions: ("ask" | "allow" | "deny")[];
363
+ default_permission: "ask" | "deny" | "allow";
364
+ permissions: ("ask" | "deny" | "allow")[];
365
365
  fallback_allow_reads?: true | undefined;
366
366
  allow_reads?: true | undefined;
367
- permission: "ask" | "allow" | "deny";
367
+ permission: "ask" | "deny" | "allow";
368
368
  name: string;
369
369
  summary: string;
370
370
  blurb: string;