@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.45

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 (388) hide show
  1. package/CHANGELOG.md +231 -0
  2. package/README.md +580 -320
  3. package/dist/acp-package.d.ts +28 -0
  4. package/dist/acp-package.js +23 -0
  5. package/dist/adapter-facts.d.ts +8 -1
  6. package/dist/adapter-facts.js +9 -1
  7. package/dist/adapters.d.ts +5 -0
  8. package/dist/adapters.js +36 -3
  9. package/dist/agent-delete.d.ts +50 -0
  10. package/dist/agent-delete.js +125 -0
  11. package/dist/agents-store.d.ts +9 -3
  12. package/dist/agents-store.js +22 -8
  13. package/dist/agents.d.ts +5 -1
  14. package/dist/agents.js +8 -4
  15. package/dist/api-only.d.ts +8 -3
  16. package/dist/api-only.js +10 -4
  17. package/dist/archil-routes.d.ts +5 -1
  18. package/dist/archil-routes.js +57 -2
  19. package/dist/browser-wait-ended.d.ts +2 -0
  20. package/dist/browser-wait-ended.js +2 -0
  21. package/dist/calendar/ics-faux.d.ts +3 -1
  22. package/dist/calendar/ics-faux.js +12 -2
  23. package/dist/calendar/tools.js +5 -2
  24. package/dist/chatgpt-plan.js +3 -1
  25. package/dist/claude-login.d.ts +135 -0
  26. package/dist/claude-login.js +244 -0
  27. package/dist/cli.js +92 -22
  28. package/dist/composio-preset.d.ts +4 -3
  29. package/dist/composio-preset.js +81 -11
  30. package/dist/composio-triggers.d.ts +34 -2
  31. package/dist/composio-triggers.js +261 -31
  32. package/dist/computer-attach.d.ts +40 -5
  33. package/dist/computer-attach.js +130 -15
  34. package/dist/computer-keys.d.ts +3 -0
  35. package/dist/computer-keys.js +7 -1
  36. package/dist/computer-live.js +3 -2
  37. package/dist/computer-lost.d.ts +11 -0
  38. package/dist/computer-lost.js +19 -0
  39. package/dist/computer-record.d.ts +10 -2
  40. package/dist/computer-record.js +50 -18
  41. package/dist/computer-setting.d.ts +1 -0
  42. package/dist/computer-setting.js +2 -2
  43. package/dist/computers.d.ts +21 -10
  44. package/dist/computers.js +39 -28
  45. package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
  46. package/dist/console/assets/index-DaFsZuzQ.css +1 -0
  47. package/dist/console/index.html +2 -2
  48. package/dist/decisions.d.ts +1 -1
  49. package/dist/dial-relay.d.ts +29 -0
  50. package/dist/dial-relay.js +94 -0
  51. package/dist/email/tools.js +10 -5
  52. package/dist/env-proxy.d.ts +2 -0
  53. package/dist/env-proxy.js +35 -0
  54. package/dist/errors.d.ts +4 -1
  55. package/dist/errors.js +10 -4
  56. package/dist/faux-computers.d.ts +8 -2
  57. package/dist/faux-computers.js +83 -6
  58. package/dist/harness-archive.d.ts +67 -0
  59. package/dist/harness-archive.js +177 -0
  60. package/dist/harness-goose.d.ts +34 -0
  61. package/dist/harness-goose.js +87 -0
  62. package/dist/harness-install.d.ts +21 -0
  63. package/dist/harness-install.js +24 -11
  64. package/dist/harness-opencode/adapter.js +1 -1
  65. package/dist/harness-table.d.ts +59 -3
  66. package/dist/harness-table.js +119 -14
  67. package/dist/harness.d.ts +17 -1
  68. package/dist/harness.js +22 -11
  69. package/dist/host.d.ts +12 -10
  70. package/dist/host.js +19 -16
  71. package/dist/import-worker.d.ts +3 -0
  72. package/dist/import-worker.js +7 -5
  73. package/dist/import.d.ts +22 -1
  74. package/dist/import.js +141 -28
  75. package/dist/key-check.js +3 -0
  76. package/dist/learn/audit.d.ts +6 -6
  77. package/dist/learn/audit.js +3 -7
  78. package/dist/learn/check.d.ts +26 -89
  79. package/dist/learn/check.js +58 -336
  80. package/dist/learn/commit.d.ts +63 -90
  81. package/dist/learn/commit.js +124 -316
  82. package/dist/learn/compile.d.ts +53 -50
  83. package/dist/learn/compile.js +88 -103
  84. package/dist/learn/corrections.d.ts +13 -0
  85. package/dist/learn/corrections.js +23 -0
  86. package/dist/learn/delete.d.ts +17 -0
  87. package/dist/learn/delete.js +42 -0
  88. package/dist/learn/folder.d.ts +35 -47
  89. package/dist/learn/folder.js +118 -134
  90. package/dist/learn/index.d.ts +3 -5
  91. package/dist/learn/index.js +6 -9
  92. package/dist/learn/learning.sh +45 -15
  93. package/dist/learn/promote.d.ts +20 -2
  94. package/dist/learn/promote.js +17 -4
  95. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +34 -38
  96. package/dist/learn/{skills.js → workflow-draft.js} +65 -59
  97. package/dist/learn/workflow-nodes.d.ts +22 -1
  98. package/dist/learn/workflow-nodes.js +29 -10
  99. package/dist/learned-workflow.js +2 -2
  100. package/dist/learning-cost.d.ts +127 -13
  101. package/dist/learning-cost.js +142 -10
  102. package/dist/learning-routes.d.ts +99 -170
  103. package/dist/learning-routes.js +199 -420
  104. package/dist/learning-run.d.ts +19 -40
  105. package/dist/learning-run.js +23 -93
  106. package/dist/learning-setting.d.ts +4 -4
  107. package/dist/learning-setting.js +6 -6
  108. package/dist/learning-words.d.ts +28 -74
  109. package/dist/learning-words.js +64 -162
  110. package/dist/learning.d.ts +62 -393
  111. package/dist/learning.js +101 -651
  112. package/dist/listen-first.d.ts +30 -0
  113. package/dist/listen-first.js +115 -0
  114. package/dist/live-reach.d.ts +25 -2
  115. package/dist/live-reach.js +46 -4
  116. package/dist/llms.txt +2 -1
  117. package/dist/local-models.d.ts +3 -11
  118. package/dist/local-models.js +5 -6
  119. package/dist/mcp-servers-store.d.ts +16 -16
  120. package/dist/model-form.js +6 -5
  121. package/dist/model.d.ts +12 -4
  122. package/dist/model.js +41 -16
  123. package/dist/native/binding.js +1 -1
  124. package/dist/native/connection.js +1 -1
  125. package/dist/native/discovery.js +1 -1
  126. package/dist/native/instructions.d.ts +3 -0
  127. package/dist/native/instructions.js +5 -3
  128. package/dist/native/remote-worker-bridge.js +9 -43
  129. package/dist/native/remote.d.ts +8 -15
  130. package/dist/native/remote.js +3 -3
  131. package/dist/native/schema.js +1 -1
  132. package/dist/native/types.d.ts +2 -2
  133. package/dist/openapi.js +375 -347
  134. package/dist/owner.d.ts +8 -0
  135. package/dist/owner.js +11 -0
  136. package/dist/paid-calls.d.ts +14 -0
  137. package/dist/paid-calls.js +31 -1
  138. package/dist/particle-provider.d.ts +11 -0
  139. package/dist/particle-provider.js +135 -0
  140. package/dist/place.d.ts +8 -3
  141. package/dist/place.js +13 -9
  142. package/dist/port-models.d.ts +12 -4
  143. package/dist/port-models.js +28 -11
  144. package/dist/print.d.ts +27 -0
  145. package/dist/print.js +21 -0
  146. package/dist/provider.d.ts +7 -0
  147. package/dist/provider.js +30 -2
  148. package/dist/reflect-range.js +2 -3
  149. package/dist/run-launch.d.ts +14 -28
  150. package/dist/run-launch.js +9 -12
  151. package/dist/run-learning-served.d.ts +16 -90
  152. package/dist/run-listing.d.ts +34 -0
  153. package/dist/run-listing.js +128 -0
  154. package/dist/run-model-key.d.ts +64 -0
  155. package/dist/run-model-key.js +147 -0
  156. package/dist/run-timeline-served.js +5 -3
  157. package/dist/run-trace.d.ts +97 -0
  158. package/dist/run-trace.js +253 -0
  159. package/dist/run-view.d.ts +15 -0
  160. package/dist/run-view.js +9 -0
  161. package/dist/runnable.js +2 -1
  162. package/dist/runner/adapter-loop.d.ts +14 -6
  163. package/dist/runner/adapter-loop.js +25 -14
  164. package/dist/runner/adapter-run-spec.d.ts +22 -7
  165. package/dist/runner/adapter-run-spec.js +130 -77
  166. package/dist/runner/adapters/index.d.ts +4 -2
  167. package/dist/runner/adapters/index.js +35 -4
  168. package/dist/runner/adapters/pi.d.ts +4 -12
  169. package/dist/runner/adapters/pi.js +2 -2
  170. package/dist/runner/audit.d.ts +5 -1
  171. package/dist/runner/audit.js +31 -12
  172. package/dist/runner/beside.d.ts +7 -2
  173. package/dist/runner/beside.js +41 -9
  174. package/dist/runner/claim-secrets.d.ts +66 -1
  175. package/dist/runner/claim-secrets.js +136 -3
  176. package/dist/runner/cli-run-spec.d.ts +2 -1
  177. package/dist/runner/cli-run-spec.js +82 -59
  178. package/dist/runner/commands.d.ts +3 -6
  179. package/dist/runner/conformance/harness.d.ts +6 -0
  180. package/dist/runner/conformance/harness.js +16 -5
  181. package/dist/runner/dispatch.d.ts +2 -2
  182. package/dist/runner/end-of-run.d.ts +6 -14
  183. package/dist/runner/end-of-run.js +8 -33
  184. package/dist/runner/feedback-round.d.ts +5 -4
  185. package/dist/runner/feedback-round.js +14 -10
  186. package/dist/runner/github-app.js +3 -1
  187. package/dist/runner/harness-loops.d.ts +0 -8
  188. package/dist/runner/harness-loops.js +30 -56
  189. package/dist/runner/held.d.ts +170 -0
  190. package/dist/runner/held.js +57 -0
  191. package/dist/runner/journal-kinds.d.ts +7 -3
  192. package/dist/runner/journal-kinds.js +2 -3
  193. package/dist/runner/learned-first.d.ts +40 -0
  194. package/dist/runner/learned-first.js +32 -0
  195. package/dist/runner/learning-end.d.ts +77 -66
  196. package/dist/runner/learning-end.js +250 -299
  197. package/dist/runner/learning-seed.d.ts +15 -33
  198. package/dist/runner/learning-seed.js +24 -45
  199. package/dist/runner/loop-contract.d.ts +8 -3
  200. package/dist/runner/loop-contract.js +4 -0
  201. package/dist/runner/loop.js +6 -2
  202. package/dist/runner/main.d.ts +18 -9
  203. package/dist/runner/main.js +82 -22
  204. package/dist/runner/mcp-run.d.ts +11 -0
  205. package/dist/runner/mcp-run.js +67 -0
  206. package/dist/runner/memory-claim.d.ts +14 -6
  207. package/dist/runner/memory-claim.js +18 -9
  208. package/dist/runner/model-route.d.ts +7 -4
  209. package/dist/runner/model-route.js +22 -10
  210. package/dist/runner/native-loop.d.ts +0 -7
  211. package/dist/runner/native-loop.js +9 -101
  212. package/dist/runner/promotion.d.ts +13 -6
  213. package/dist/runner/promotion.js +63 -17
  214. package/dist/runner/reflect-hook.d.ts +64 -91
  215. package/dist/runner/reflect-hook.js +112 -206
  216. package/dist/runner/run-channel.d.ts +43 -0
  217. package/dist/runner/run-channel.js +467 -0
  218. package/dist/runner/run-child-host.d.ts +169 -0
  219. package/dist/runner/run-child-host.js +1222 -0
  220. package/dist/runner/run-child.d.ts +1 -0
  221. package/dist/runner/run-child.js +254 -0
  222. package/dist/runner/run-errors.d.ts +2 -0
  223. package/dist/runner/run-errors.js +20 -0
  224. package/dist/runner/runner.js +58 -9
  225. package/dist/runner/sdk-ask.d.ts +78 -0
  226. package/dist/runner/sdk-ask.js +158 -0
  227. package/dist/runner/sdk-loop.d.ts +2 -4
  228. package/dist/runner/sdk-loop.js +29 -49
  229. package/dist/runner/store-secrets.d.ts +5 -3
  230. package/dist/runner/store-secrets.js +14 -6
  231. package/dist/runner/workflow-first.d.ts +5 -0
  232. package/dist/runner/workflow-first.js +4 -0
  233. package/dist/runner/workflow-spec.js +17 -4
  234. package/dist/runs-over-store.d.ts +21 -32
  235. package/dist/runs-over-store.js +44 -41
  236. package/dist/sdk/runs.d.ts +6 -11
  237. package/dist/sdk/runs.js +20 -41
  238. package/dist/sdk/schema.js +3 -4
  239. package/dist/sdk/workflows.d.ts +1 -1
  240. package/dist/seal-key.d.ts +5 -0
  241. package/dist/seal-key.js +7 -0
  242. package/dist/secrets.d.ts +3 -0
  243. package/dist/secrets.js +16 -3
  244. package/dist/server.d.ts +119 -83
  245. package/dist/server.js +1121 -419
  246. package/dist/sign-ins-store.d.ts +8 -0
  247. package/dist/sign-ins-store.js +36 -1
  248. package/dist/skills.js +1 -1
  249. package/dist/store/index.d.ts +3 -3
  250. package/dist/store/index.js +2 -2
  251. package/dist/store/journal/storage.js +3 -0
  252. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  253. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  254. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  255. package/dist/store/schema.d.ts +53 -4
  256. package/dist/store/schema.js +137 -6
  257. package/dist/store/seal.d.ts +20 -2
  258. package/dist/store/seal.js +24 -8
  259. package/dist/store/sqlite/connection.d.ts +2 -0
  260. package/dist/store/sqlite/connection.js +3 -1
  261. package/dist/store/sqlite/run-launch.d.ts +4 -1
  262. package/dist/store/sqlite/run-launch.js +12 -0
  263. package/dist/store/sqlite/run-patch.d.ts +0 -17
  264. package/dist/store/sqlite/run-patch.js +4 -33
  265. package/dist/store/sqlite/store.d.ts +3 -2
  266. package/dist/store/sqlite/store.js +360 -75
  267. package/dist/store/sqlite/worker.js +25 -0
  268. package/dist/store/store.d.ts +231 -39
  269. package/dist/store/store.js +25 -3
  270. package/dist/store-reads/analytics.js +11 -1
  271. package/dist/store-reads/learning.d.ts +131 -194
  272. package/dist/store-reads/learning.js +292 -301
  273. package/dist/store-reads/loop.d.ts +0 -1
  274. package/dist/store-reads/loop.js +1 -1
  275. package/dist/store-reads/stats.js +13 -3
  276. package/dist/store-view.d.ts +34 -2
  277. package/dist/store-view.js +108 -41
  278. package/dist/telemetry.d.ts +59 -0
  279. package/dist/telemetry.js +153 -0
  280. package/dist/template-eval.d.ts +3 -6
  281. package/dist/template-eval.js +22 -36
  282. package/dist/templates.d.ts +2 -1
  283. package/dist/templates.js +6 -3
  284. package/dist/timeline/index.d.ts +1 -1
  285. package/dist/timeline/index.js +1 -1
  286. package/dist/timeline/timeline.d.ts +5 -1
  287. package/dist/timeline/timeline.js +16 -0
  288. package/dist/tool-gate.d.ts +0 -7
  289. package/dist/tool-gate.js +1 -15
  290. package/dist/tool-keys-store.d.ts +1 -1
  291. package/dist/tool-keys.d.ts +6 -4
  292. package/dist/tool-keys.js +12 -6
  293. package/dist/tool-plane.d.ts +12 -12
  294. package/dist/tools.d.ts +13 -13
  295. package/dist/tools.js +29 -9
  296. package/dist/trigger-adapter.d.ts +3 -0
  297. package/dist/trigger-adapters.d.ts +4 -0
  298. package/dist/trigger-adapters.js +13 -0
  299. package/dist/trigger-composio.d.ts +58 -1
  300. package/dist/trigger-composio.js +160 -6
  301. package/dist/triggers.d.ts +64 -5
  302. package/dist/triggers.js +141 -17
  303. package/dist/validate.d.ts +11 -7
  304. package/dist/validate.js +9 -8
  305. package/dist/webhooks.d.ts +4 -1
  306. package/dist/webhooks.js +11 -4
  307. package/dist/workspace/agent-computer.d.ts +2 -0
  308. package/dist/workspace/agent-computer.js +2 -0
  309. package/dist/workspace/archil-claim.d.ts +7 -0
  310. package/dist/workspace/archil-claim.js +29 -0
  311. package/dist/workspace/archil.d.ts +9 -1
  312. package/dist/workspace/archil.js +165 -3
  313. package/dist/workspace/attach.d.ts +3 -1
  314. package/dist/workspace/attach.js +2 -0
  315. package/dist/workspace/attached-computers.d.ts +16 -5
  316. package/dist/workspace/attached-computers.js +25 -9
  317. package/dist/workspace/computer-deps.js +1 -1
  318. package/dist/workspace/computer-for-claim.d.ts +22 -8
  319. package/dist/workspace/computer-for-claim.js +339 -46
  320. package/dist/workspace/computer-hold.js +2 -1
  321. package/dist/workspace/computer-kept.d.ts +11 -1
  322. package/dist/workspace/computer-kept.js +24 -3
  323. package/dist/workspace/resolve-computer.d.ts +41 -21
  324. package/dist/workspace/resolve-computer.js +172 -64
  325. package/dist/workspace/revision-skills.d.ts +1 -2
  326. package/dist/workspace/revision-skills.js +3 -4
  327. package/dist/workspace/run-workspace.d.ts +1 -1
  328. package/dist/workspace/run-workspace.js +5 -0
  329. package/dist/workspace/synced-folder.d.ts +85 -0
  330. package/dist/workspace/synced-folder.js +230 -0
  331. package/dist/workspace/workspace.d.ts +4 -0
  332. package/launcher/agentrun-serve +1 -1
  333. package/package.json +10 -9
  334. package/templates/README.md +7 -7
  335. package/templates/inbound-lead/agent.md +3 -3
  336. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  337. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  338. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  339. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  340. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  341. package/templates/inbound-lead/lead.schema.json +6 -5
  342. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  343. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  344. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  345. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  346. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  347. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  348. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  349. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  350. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  351. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  352. package/dist/console/assets/index-BrcDSBD8.css +0 -1
  353. package/dist/console/assets/index-Bz6IWncl.js +0 -711
  354. package/dist/learn/grade.d.ts +0 -138
  355. package/dist/learn/grade.js +0 -682
  356. package/dist/learn/notes.d.ts +0 -81
  357. package/dist/learn/notes.js +0 -178
  358. package/dist/learn/reflect.d.ts +0 -77
  359. package/dist/learn/reflect.js +0 -228
  360. package/dist/learn/relevance.d.ts +0 -24
  361. package/dist/learn/relevance.js +0 -91
  362. package/dist/learn/seed-check.d.ts +0 -74
  363. package/dist/learn/seed-check.js +0 -103
  364. package/dist/learning-batch.d.ts +0 -291
  365. package/dist/learning-batch.js +0 -600
  366. package/dist/learning-evals.d.ts +0 -33
  367. package/dist/learning-evals.js +0 -98
  368. package/dist/native/context.d.ts +0 -6
  369. package/dist/native/context.js +0 -22
  370. package/dist/propose.d.ts +0 -52
  371. package/dist/propose.js +0 -224
  372. package/dist/runner/learning-ask.d.ts +0 -47
  373. package/dist/runner/learning-ask.js +0 -128
  374. package/dist/runner/learning-dispatch.d.ts +0 -45
  375. package/dist/runner/learning-dispatch.js +0 -99
  376. package/dist/runner/learning-factory.d.ts +0 -16
  377. package/dist/runner/learning-factory.js +0 -50
  378. package/dist/runner/learning-loop.d.ts +0 -273
  379. package/dist/runner/learning-loop.js +0 -521
  380. package/dist/usage.d.ts +0 -11
  381. package/dist/usage.js +0 -11
  382. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  383. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  384. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  385. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  386. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  387. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  388. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -0,0 +1,28 @@
1
+ import type { AdapterFacts, AgentAdapter } from "@parcha/agentrun-kernel";
2
+ export declare const ACP_PACKAGE = "@parcha/agentrun-harness-acp";
3
+ /** One platform's Goose release, as the pin holds it (the package's AcpArchivePin). */
4
+ export type AcpRelease = {
5
+ readonly url: string;
6
+ readonly format: string;
7
+ readonly sha256: string;
8
+ readonly cmd: string;
9
+ readonly binarySha256?: string;
10
+ };
11
+ /** What serve reads of the package. */
12
+ export type AcpPackage = {
13
+ readonly gooseFacts: AdapterFacts;
14
+ readonly GOOSE_PIN: {
15
+ readonly id: string;
16
+ readonly version: string;
17
+ readonly archives: Readonly<Partial<Record<string, AcpRelease>>>;
18
+ };
19
+ readonly GOOSE_INSTALL: string;
20
+ readonly GOOSE_NOT_INSTALLED: string;
21
+ acpPlatform(): string | undefined;
22
+ gooseAdapter(options: Record<string, unknown>): AgentAdapter;
23
+ verifyPinnedBinary(path: string, sha256: string): void;
24
+ verifyPinnedBinaryAsync(path: string, sha256: string): Promise<void>;
25
+ };
26
+ /** The package, or undefined where it is not installed beside serve. Only its absence is: a package that is there and
27
+ * fails to load throws. */
28
+ export declare function acpPackage(): AcpPackage | undefined;
@@ -0,0 +1,23 @@
1
+ // The ACP harnesses' package (@parcha/agentrun-harness-acp: Goose's adapter, its pin and its facts), loaded here alone, by
2
+ // name, when serve first asks for it. The package is held from npm for now (its manifest is private), so a serve
3
+ // installed from npm runs without it, and its harness table has no goose row; in this repository it is always beside
4
+ // serve. A leaf: the harness table's own imports (adapter-facts.ts) read it in any import order.
5
+ import { createRequire } from "node:module";
6
+ export const ACP_PACKAGE = "@parcha/agentrun-harness-acp";
7
+ const requireHere = createRequire(import.meta.url);
8
+ let loaded;
9
+ /** The package, or undefined where it is not installed beside serve. Only its absence is: a package that is there and
10
+ * fails to load throws. */
11
+ export function acpPackage() {
12
+ if (loaded === undefined) {
13
+ let found = true;
14
+ try {
15
+ requireHere.resolve(ACP_PACKAGE);
16
+ }
17
+ catch {
18
+ found = false;
19
+ }
20
+ loaded = found ? requireHere(ACP_PACKAGE) : null;
21
+ }
22
+ return loaded ?? undefined;
23
+ }
@@ -1,3 +1,10 @@
1
1
  import type { AdapterFacts } from "@parcha/agentrun-kernel";
2
- /** The adapter harnesses' facts: claude-agent's, codex's and opencode's. */
2
+ /** The adapter harnesses' facts: claude-agent's, codex's and opencode's, the built-in harnesses the API names (HARNESSES). */
3
3
  export declare const ADAPTER_FACTS: readonly AdapterFacts[];
4
+ /** Goose's facts (its package's, acp-package.ts), or undefined where that package is not beside serve: then the table has
5
+ * no goose row. Goose is listed only while its owner has installed it, so it is not one of HARNESSES. */
6
+ export declare const GOOSE_FACTS: AdapterFacts | undefined;
7
+ /** Every adapter harness's facts: the built-in ones, then Goose's where its package is. */
8
+ export declare const EVERY_ADAPTER_FACTS: readonly AdapterFacts[];
9
+ /** The facts of the adapter harness `id`, built-in or Goose; undefined for pi and for an id no adapter states. */
10
+ export declare const adapterFactsOf: (id: string) => AdapterFacts | undefined;
@@ -1,5 +1,13 @@
1
1
  import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
2
2
  import { facts as codexFacts } from "@parcha/agentrun-harness-codex/facts";
3
3
  import { facts as openCodeFacts } from "./harness-opencode/facts.js";
4
- /** The adapter harnesses' facts: claude-agent's, codex's and opencode's. */
4
+ import { acpPackage } from "./acp-package.js";
5
+ /** The adapter harnesses' facts: claude-agent's, codex's and opencode's, the built-in harnesses the API names (HARNESSES). */
5
6
  export const ADAPTER_FACTS = Object.freeze([claudeFacts, codexFacts, openCodeFacts]);
7
+ /** Goose's facts (its package's, acp-package.ts), or undefined where that package is not beside serve: then the table has
8
+ * no goose row. Goose is listed only while its owner has installed it, so it is not one of HARNESSES. */
9
+ export const GOOSE_FACTS = acpPackage()?.gooseFacts;
10
+ /** Every adapter harness's facts: the built-in ones, then Goose's where its package is. */
11
+ export const EVERY_ADAPTER_FACTS = Object.freeze([...ADAPTER_FACTS, ...(GOOSE_FACTS ? [GOOSE_FACTS] : [])]);
12
+ /** The facts of the adapter harness `id`, built-in or Goose; undefined for pi and for an id no adapter states. */
13
+ export const adapterFactsOf = (id) => EVERY_ADAPTER_FACTS.find((facts) => facts.id === id);
@@ -148,6 +148,11 @@ export declare function codexOf(env: NodeJS.ProcessEnv, needs: AdapterNeeds, loa
148
148
  * its wire's do (providerFor): serve's gateway (AGENT_MODEL_BASE_URL), OpenAI or OpenRouter, on the Responses API,
149
149
  * through the adapter's proxy. */
150
150
  export declare function opencodeOf(env: NodeJS.ProcessEnv, needs: AdapterNeeds, load?: () => Promise<typeof import("./harness-opencode/index.js")>, npx?: boolean): Promise<AgentAdapter>;
151
+ /** Goose's adapter (its package's gooseAdapter, acp-package.ts), on the binary its owner installed into the data's
152
+ * harnesses directory (`agentrun harness install goose`, harness-goose.ts) and from nowhere else: not there, or not the
153
+ * pinned binary, it says that command, and nothing here installs it. Its model goes where claude-agent's does (the host's
154
+ * Anthropic Messages provider, providerFor), through a model proxy of its own, priced and capped as every run is. */
155
+ export declare function gooseOf(env: NodeJS.ProcessEnv, needs: AdapterNeeds): Promise<AgentAdapter>;
151
156
  /** Why `harness` cannot run here, or undefined when it can (its entry's refusal): its package and pins, its provider, and
152
157
  * the adapter's own check of the model `given` names (with none, a model of its wire's vendor: whether it runs here at
153
158
  * all). `atStart`: asked by the start's probe, whose offers hold until a restart, so a reason installing fixes ends
package/dist/adapters.js CHANGED
@@ -15,7 +15,7 @@ import { DATA_ENV, defaultData } from "./files.js";
15
15
  import { harnessOf, onAdapter } from "./harness-table.js";
16
16
  import { HarnessUnavailable, providerFor } from "./provider.js";
17
17
  import { keyShaped } from "./secret-cut.js";
18
- import { servedSkills } from "./learn/skills.js";
18
+ import { servedSkills } from "./learn/workflow-draft.js";
19
19
  import { runKeyOf } from "./key-refusal.js";
20
20
  import { planeOf } from "./tool-plane.js";
21
21
  import { NATIVE_SEARCH_ALLOWANCE_TOKENS } from "./cap.js";
@@ -291,7 +291,10 @@ export async function claudeOf(env, needs, load = loadClaude, sdkOf = (version,
291
291
  // order (the SDK before the CLI).
292
292
  await claude.verifyClaudeAgentCliAsync(sdk.cliPath);
293
293
  // The skills only when there are some: with none, the adapter keeps its Skill tool off.
294
- adapter = claude.claudeAgentAdapter({ model: { default: provider?.modelId ?? native.model.modelId }, provider: endpoint, price: priceOf(priced), log: harnessLog(claudeFacts.id, env), sdk: sdk.sdk, sdkVersion: sdk.sdkVersion, cliPath: sdk.cliPath, mcp: sdk.mcp, ...(needs.confine ? { confine: needs.confine } : {}), ...(needs.skills?.length ? { skills: needs.skills } : {}), ...(needs.now ? { now: needs.now } : {}), ...(needs.zone ? { zone: needs.zone } : {}), ...nativeOptions(claudeFacts, env) });
294
+ // On Claude Code's login on this machine: the login's directories in place of a provider, billed to the plan, never
295
+ // priced here.
296
+ const source = provider?.login ? { login: provider.login, price: () => null } : { provider: endpoint, price: priceOf(priced) };
297
+ adapter = claude.claudeAgentAdapter({ model: { default: provider?.modelId ?? native.model.modelId }, ...source, log: harnessLog(claudeFacts.id, env), sdk: sdk.sdk, sdkVersion: sdk.sdkVersion, cliPath: sdk.cliPath, mcp: sdk.mcp, ...(needs.confine ? { confine: needs.confine } : {}), ...(needs.skills?.length ? { skills: needs.skills } : {}), ...(needs.now ? { now: needs.now } : {}), ...(needs.zone ? { zone: needs.zone } : {}), ...nativeOptions(claudeFacts, env) });
295
298
  }
296
299
  catch (error) {
297
300
  // The adapter's own install line is a project's; here Claude Code is installed into the data's harnesses directory.
@@ -362,10 +365,40 @@ export async function opencodeOf(env, needs, load = () => import("./harness-open
362
365
  const provider = providerFor(openCodeFacts.wire, env, needs.model, openCodeFacts.id);
363
366
  // Its instructions list each skill by the description its SKILL.md's front matter gives on one LF line, which is all the
364
367
  // adapter reads: each SKILL.md goes as servedSkill writes it (its name and description, as a prompt reads them, on one
365
- // line each), as a learned skill already does, so a CRLF file or a folded description is listed by its own words.
368
+ // line each), so a CRLF file or a folded description is listed by its own words.
366
369
  const skills = needs.skills && servedSkills(needs.skills);
367
370
  return opencode.openCodeAdapter({ model: provider.modelId, provider: { origin: provider.origin, credential: provider.credential }, price: priceOf({ ...needs, model: provider.priceModel }), log: harnessLog(openCodeFacts.id, env), ...(needs.confine ? { confine: needs.confine } : {}), ...(skills?.length ? { skills } : {}), ...(standIn ? { standIn } : {}) });
368
371
  }
372
+ /** Goose's adapter (its package's gooseAdapter, acp-package.ts), on the binary its owner installed into the data's
373
+ * harnesses directory (`agentrun harness install goose`, harness-goose.ts) and from nowhere else: not there, or not the
374
+ * pinned binary, it says that command, and nothing here installs it. Its model goes where claude-agent's does (the host's
375
+ * Anthropic Messages provider, providerFor), through a model proxy of its own, priced and capped as every run is. */
376
+ export async function gooseOf(env, needs) {
377
+ const [{ acpPackage }, { gooseMissing, GOOSE_ID }] = await Promise.all([import("./acp-package.js"), import("./harness-goose.js")]);
378
+ const acp = acpPackage();
379
+ // What no key fixes is said first, as claudeOf does: the binary, checked off the event loop.
380
+ const found = await gooseMissing(env);
381
+ if ("missing" in found)
382
+ throw new HarnessUnavailable(found.missing.message, acp && fixOf(acp.gooseFacts, found.missing));
383
+ if (!acp)
384
+ throw new HarnessUnavailable("Goose's adapter is not installed beside this server");
385
+ const facts = acp.gooseFacts;
386
+ const provider = providerFor(facts.wire, env, needs.model, GOOSE_ID);
387
+ // A person's Claude Code login is its CLI's alone (claude-login.ts): Goose's requests never go on it.
388
+ if (provider.login)
389
+ throw new HarnessUnavailable("Goose runs on a model key: Claude Code's login on this machine is its CLI's alone.", undefined, ["ANTHROPIC_API_KEY", "OPENROUTER_API_KEY"]);
390
+ try {
391
+ return acp.gooseAdapter({
392
+ binary: found.binary, sha256: found.sha256, model: provider.modelId,
393
+ provider: { origin: provider.origin, credential: provider.credential, ...(provider.auth ? { auth: provider.auth } : {}) },
394
+ price: priceOf({ ...needs, model: provider.priceModel }), log: harnessLog(GOOSE_ID, env),
395
+ ...(needs.confine ? { confine: needs.confine } : {}),
396
+ });
397
+ }
398
+ catch (error) {
399
+ throw new HarnessUnavailable(error.message, fixOf(facts, error));
400
+ }
401
+ }
369
402
  /** Why `harness` cannot run here, or undefined when it can (its entry's refusal): its package and pins, its provider, and
370
403
  * the adapter's own check of the model `given` names (with none, a model of its wire's vendor: whether it runs here at
371
404
  * all). `atStart`: asked by the start's probe, whose offers hold until a restart, so a reason installing fixes ends
@@ -0,0 +1,50 @@
1
+ import { type Store } from "./store/index.js";
2
+ /** The delete of an agent's learning: the server's is the learning module's deleteLearning over the agent's learning
3
+ * folder (learn/delete.ts). Idempotent; refuses with LearningInFlight while learning work of the agent is in flight. */
4
+ export type DeleteLearning = (store: Store, agentId: string) => Promise<unknown>;
5
+ /** A point of a delete a test may stop it at (AgentDeleteHost.at): after step 1, after step 2, in step 3 between a
6
+ * trigger's removal upstream and its settings', between its settings' and its row's, and in step 3 once its triggers
7
+ * and the agent's first run are gone. */
8
+ export type AgentDeleteStep = "after_step_1" | "after_step_2" | "in_step_3_trigger" | "in_step_3_trigger_settings" | "in_step_3";
9
+ /** What a delete does outside the store's own rows, as the server does it. */
10
+ export interface AgentDeleteHost {
11
+ readonly store: Store;
12
+ readonly deleteLearning: DeleteLearning;
13
+ /** Step 1's mark: the agent archived, its triggers off in the same commit (the trigger engine's agentArchived). */
14
+ refuse(agentId: string): Promise<void>;
15
+ /** The cancel path, for one run that is not final: true once a cancel stands for it (written now, or the run is ending
16
+ * already), false when this server cannot end it (an SDK run, which only its application ends; an imported run). */
17
+ cancel(runId: string): Promise<boolean>;
18
+ /** One trigger's registration upstream removed, the trigger kept (the trigger engine's removeThere); an ApiError
19
+ * (503 unavailable) while it is not. */
20
+ removeTriggerThere(triggerId: string): Promise<void>;
21
+ /** Then its adapter settings, the trigger kept (the engine's removeSettings): they have no link to its row. */
22
+ removeTriggerSettings(triggerId: string): Promise<void>;
23
+ /** Then the trigger itself, its row (the engine's removeHere, which removes any settings left first). */
24
+ removeTrigger(triggerId: string): Promise<void>;
25
+ /** Every saved sign-in of the agent forgotten, its object at the vendor deleted; an ApiError (503 unavailable) while a
26
+ * vendor has not deleted one, each kept as a tombstone for the next call. */
27
+ forgetSignIns(agentId: string): Promise<void>;
28
+ /** The agent's own computer deleted at its provider, and its record with it; an ApiError while it cannot be yet. */
29
+ removeOwnComputer(agentId: string): Promise<void>;
30
+ /** The agent's Archil disk deleted, when one is stored on it, whatever the server's Archil settings are now
31
+ * (archil-routes.ts removeAgentDisk); an ApiError (503 unavailable) while it is not, Archil off included. */
32
+ removeDisk(agentId: string): Promise<void>;
33
+ /** A final run's things outside its rows: its folders (its own folder on an Archil disk its launch named, read from its
34
+ * launch record, which goes with its rows after; an ApiError (503 unavailable) while that folder is not deleted
35
+ * there), its settings, the answers kept under its idempotency keys. */
36
+ forgetRun(agentId: string, runId: string): Promise<void>;
37
+ /** The agent's things outside its rows: its folders, its settings, the answers kept under its idempotency keys. */
38
+ forgetAgent(agentId: string): Promise<void>;
39
+ /** How long step 1 waits for the agent's runs to be final, and how often it reads them meanwhile. */
40
+ readonly waitMs: number;
41
+ readonly pollMs: number;
42
+ /** A test's seam: awaited at each step's point, so a throw there stops the delete as a crash would. */
43
+ at?(step: AgentDeleteStep, agentId: string): void | Promise<void>;
44
+ }
45
+ /** Deletes agent `agentId` (another system's, as the route checked) in the three steps above. Throws ApiError
46
+ * runs_in_flight while a run of it is not final by the wait's end, learning_busy while its learning refuses. */
47
+ export declare function deleteExternalAgent(host: AgentDeleteHost, agentId: string): Promise<void>;
48
+ /** One delete of an agent at a time: a second DELETE of the same agent waits for the first, then finds it gone (404) or
49
+ * finishes what the first left. */
50
+ export declare function oneAtATime(): <T>(agentId: string, work: () => Promise<T>) => Promise<T>;
@@ -0,0 +1,125 @@
1
+ // DELETE /v2/agents/{agent_id}: an agent another system owns (made by an inline run, POST /runs with `external`) deleted
2
+ // whole, for a host that must delete what it sent. An agent made here is archived instead (409 agent_not_external).
3
+ //
4
+ // In order, each step finished before the next:
5
+ // 1. The agent refuses new runs, as a mark in the store that outlives a restart: its archive time, which only this
6
+ // delete writes on an agent another system owns (its archive route is refused), set by the trigger engine with its
7
+ // triggers off in the same commit. From that commit a person's run, an inline run, a trigger's firing, an SDK run and
8
+ // a follow-up that would open one of its runs again are refused (store AgentDeleting / AgentArchived, each read in
9
+ // the transaction that would start the run). Then each of its runs not yet final, its learning runs included, is
10
+ // cancelled through the cancel path, and waited for until it is final.
11
+ // 2. Its learning, by the learning module's deleteLearning (learn/delete.ts: its learning folder's files, then its
12
+ // promotions and grades; idempotent; it refuses with LearningInFlight while learning work
13
+ // is in flight, which answers 409 learning_busy with the agent left refusing runs).
14
+ // 3. Its things: its triggers through the trigger engine (each one's registration upstream first, then its adapter
15
+ // settings, then its row), its saved sign-ins (each vendor object too), its own computer, its Archil disk; then each
16
+ // run's folders (on a disk its launch named, the caller's, too: the run's own folder there, never the disk), settings
17
+ // and kept answers, and its rows (store runs.remove); then the agent's folders, settings and kept answers, and its
18
+ // rows (store agents.remove, which commits last).
19
+ // A DELETE stopped at any step finds the agent still there, marked, and does every step again: each is idempotent, so the
20
+ // next DELETE finishes it. Once the agent's row is gone the agent is unknown: 404. Nothing the agent owns elsewhere (a
21
+ // trigger's registration upstream, a saved sign-in at its vendor, its own computer, its Archil disk, a run's folder on a
22
+ // disk its launch named) is left with the agent's row gone: the record here that names it (for a run's folder, its launch
23
+ // record) is removed only once it is deleted there, and while it is not, the
24
+ // delete stops with 503 unavailable, the agent kept and refusing runs, for the next DELETE to finish. From step 1's mark
25
+ // the agent takes no new trigger, off or on (the trigger engine and the store refuse it), and no write to its home or its
26
+ // learning (the server's, in the delete's turn); a trigger that reached it anyway keeps its row (store TriggersLeft): the
27
+ // same 503, and the next DELETE removes that trigger as it removes the others.
28
+ import { ApiError } from "./errors.js";
29
+ import { LearningInFlight } from "./learn/delete.js";
30
+ import { FINAL_STATES, TriggersLeft } from "./store/index.js";
31
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
32
+ const isFinal = (state) => FINAL_STATES.includes(state);
33
+ /** Deletes agent `agentId` (another system's, as the route checked) in the three steps above. Throws ApiError
34
+ * runs_in_flight while a run of it is not final by the wait's end, learning_busy while its learning refuses. */
35
+ export async function deleteExternalAgent(host, agentId) {
36
+ // 1. No new run, then none in flight.
37
+ await host.refuse(agentId);
38
+ await stopRuns(host, agentId);
39
+ await host.at?.("after_step_1", agentId);
40
+ // 2. Its learning. Its refusal while learning work is in flight is learning_busy; any other failure is the server's own.
41
+ try {
42
+ await host.deleteLearning(host.store, agentId);
43
+ }
44
+ catch (error) {
45
+ if (!(error instanceof LearningInFlight))
46
+ throw error;
47
+ throw new ApiError("learning_busy", `The agent ${agentId}'s learning could not be deleted yet (${error.message}). The agent starts no run meanwhile: send the DELETE again later to finish it.`, { details: { runs: [...error.runs] }, retry_after_ms: 5_000 });
48
+ }
49
+ await host.at?.("after_step_2", agentId);
50
+ // 3. Its things, then its rows; the agent's row last.
51
+ for (const trigger of await host.store.triggers.list(agentId)) {
52
+ // Upstream first, then its settings, then its row: the row names what is left to remove until each is gone.
53
+ await host.removeTriggerThere(trigger.id);
54
+ await host.at?.("in_step_3_trigger", agentId);
55
+ await host.removeTriggerSettings(trigger.id);
56
+ await host.at?.("in_step_3_trigger_settings", agentId);
57
+ await host.removeTrigger(trigger.id);
58
+ }
59
+ await host.forgetSignIns(agentId);
60
+ await host.removeOwnComputer(agentId);
61
+ await host.removeDisk(agentId);
62
+ let first = true;
63
+ for (const run of await host.store.runs.every(agentId)) {
64
+ await host.forgetRun(agentId, run.id);
65
+ await host.store.runs.remove(run.id);
66
+ if (first)
67
+ await host.at?.("in_step_3", agentId);
68
+ first = false;
69
+ }
70
+ await host.forgetAgent(agentId);
71
+ try {
72
+ await host.store.agents.remove(agentId);
73
+ }
74
+ catch (error) {
75
+ // A trigger that reached the agent after the listing above (the store refuses one once the agent is marked; this is
76
+ // its backstop): the agent is kept, refusing, for the next DELETE to remove it upstream, its settings, then its row.
77
+ if (!(error instanceof TriggersLeft))
78
+ throw error;
79
+ throw new ApiError("unavailable", `The agent ${agentId} has ${error.triggerIds.length === 1 ? "a trigger" : "triggers"} made while it was being deleted (${error.triggerIds.join(", ")}), not removed yet. It starts no run meanwhile: send the DELETE again to finish it.`, { details: { triggers: error.triggerIds }, retry_after_ms: 5_000 });
80
+ }
81
+ }
82
+ /** Step 1's second half: each run of the agent not final cancelled once, then read again until every one is final. A run's
83
+ * end may queue its learning run, so the runs are listed again on each read. A run this server cannot end, or one still
84
+ * going at the wait's end, is 409 runs_in_flight, the agent left refusing runs. */
85
+ async function stopRuns(host, agentId) {
86
+ const deadline = Date.now() + host.waitMs;
87
+ const asked = new Set();
88
+ for (;;) {
89
+ const live = (await host.store.runs.every(agentId)).filter((run) => !isFinal(run.state));
90
+ if (live.length === 0)
91
+ return;
92
+ const unended = [];
93
+ for (const run of live) {
94
+ if (asked.has(run.id))
95
+ continue;
96
+ if (await host.cancel(run.id))
97
+ asked.add(run.id);
98
+ else
99
+ unended.push(run.id);
100
+ }
101
+ if (unended.length) {
102
+ throw new ApiError("runs_in_flight", `The agent ${agentId} has ${unended.length === 1 ? "a run" : "runs"} this server cannot end (${unended.join(", ")}): an SDK run is ended by its application. It starts no run meanwhile: send the DELETE again once ${unended.length === 1 ? "it has" : "they have"} ended.`, { details: { runs: unended }, retry_after_ms: 5_000 });
103
+ }
104
+ if (Date.now() >= deadline) {
105
+ throw new ApiError("runs_in_flight", `The agent ${agentId}'s runs were cancelled and ${live.length === 1 ? "one has" : `${live.length} have`} not ended yet (${live.map((run) => run.id).join(", ")}). It starts no run meanwhile: send the DELETE again to finish it.`, { details: { runs: live.map((run) => run.id) }, retry_after_ms: 2_000 });
106
+ }
107
+ await sleep(host.pollMs);
108
+ }
109
+ }
110
+ /** One delete of an agent at a time: a second DELETE of the same agent waits for the first, then finds it gone (404) or
111
+ * finishes what the first left. */
112
+ export function oneAtATime() {
113
+ const turns = new Map();
114
+ return (agentId, work) => {
115
+ const before = turns.get(agentId) ?? Promise.resolve();
116
+ const turn = before.then(work, work);
117
+ const settled = turn.then(() => undefined, () => undefined);
118
+ turns.set(agentId, settled);
119
+ void settled.then(() => {
120
+ if (turns.get(agentId) === settled)
121
+ turns.delete(agentId);
122
+ });
123
+ return turn;
124
+ };
125
+ }
@@ -16,7 +16,8 @@ export type AgentEntry = {
16
16
  version: number;
17
17
  revisions: number;
18
18
  sizes: Map<string, number>;
19
- /** The template package it was applied from, as its first revision keeps it; absent or null for one made otherwise. */
19
+ /** The template package it was last applied from, as the newest revision an apply wrote keeps it (its first, until an
20
+ * apply with agent_id updates it); absent or null for one made otherwise. */
20
21
  template?: TemplatePackage | null;
21
22
  };
22
23
  /** Refuses a write to an externally owned agent: one that mirrors an agent in another system (its `externalRef` set) is
@@ -77,11 +78,16 @@ export declare function makeRevision(definition: Json, files: Record<string, str
77
78
  * holds across every server on the store. `check` may refuse the revision before a write; it runs outside the write, so
78
79
  * another request may move the current revision meanwhile: an edit with If-Match is then precondition_failed, and one
79
80
  * without is built and checked again on the new current revision, so what it leaves out (skill files, harness, place, learning, cap) is never carried over from a
80
- * revision it does not follow. `contract`: an edit that always makes a new revision, even one equal to the current. */
81
- export declare function commitAgent(store: AgentsStore, read: AgentEntry, { definition, skills, note }: DefinitionBody, { ifCurrent, check, contract }?: {
81
+ * revision it does not follow. `contract`: an edit that always makes a new revision, even one equal to the current.
82
+ * `template`: the package an apply with agent_id wrote it from, kept on the revision (getAgent's `template`).
83
+ * `fromPackage`: the definition is a whole package's (an apply with agent_id), so what it leaves out is not carried over
84
+ * (editOn). */
85
+ export declare function commitAgent(store: AgentsStore, read: AgentEntry, { definition, skills, note }: DefinitionBody, { ifCurrent, check, contract, template, fromPackage }?: {
82
86
  ifCurrent?: string | null;
83
87
  check?: SaveCheck;
84
88
  contract?: boolean;
89
+ template?: TemplatePackage;
90
+ fromPackage?: boolean;
85
91
  }): Promise<AgentEntry>;
86
92
  /** Makes `revisionId`, one of the agent's own, its current one (POST /agents/{id}/current). */
87
93
  export declare function setCurrentRevision(store: AgentsStore, entry: AgentEntry, revisionId: string): Promise<AgentEntry>;
@@ -103,7 +103,7 @@ function revisionInputOf(definition, files) {
103
103
  // permissionOf with the revision's approvals): a call node on a tool set to ask runs under never, as on main.
104
104
  if (isObject(definition.workflow))
105
105
  return { kind: "workflow", workflow: definition.workflow, ...(definition.approvals === "never" ? { approvals: "never" } : {}), ...common, ...capped };
106
- // true, false, "notes" or the loop's numbers (learning-setting.ts), checked by validate.ts and again by the body.
106
+ // true, false or the loop's numbers (learning-setting.ts), checked by validate.ts and again by the body.
107
107
  const learning = definition.learning !== undefined && learningSettingIssue(definition.learning) === undefined ? { learning: definition.learning } : {};
108
108
  return {
109
109
  kind: "agentic",
@@ -145,7 +145,9 @@ function checkPast(definition, current) {
145
145
  * and the same pins: a save after a server changed a granted tool (or monid an endpoint) is a new revision, pinned anew
146
146
  * (that is how a person takes a server's changed tools). */
147
147
  function sameRevision(current, next) {
148
- return current.kind === next.kind && canonical(current.body) === canonical(next.body) && canonical(current.mcpPin ?? null) === canonical(next.mcpPin ?? null) && canonical(current.monidPin ?? null) === canonical(next.monidPin ?? null);
148
+ // A template's update (next.package) that changes only the package (its version, its parameters) is a new revision too.
149
+ return current.kind === next.kind && canonical(current.body) === canonical(next.body) && canonical(current.mcpPin ?? null) === canonical(next.mcpPin ?? null) && canonical(current.monidPin ?? null) === canonical(next.monidPin ?? null)
150
+ && (next.package === undefined || canonical(current.package ?? null) === canonical(next.package));
149
151
  }
150
152
  /** `revision` with what its check stamped. */
151
153
  const stamped = (revision, stamp) => ({ ...revision, ...(stamp?.mcpPin === undefined ? {} : { mcpPin: stamp.mcpPin }), ...(stamp?.monidPin === undefined ? {} : { monidPin: stamp.monidPin }) });
@@ -172,7 +174,7 @@ export async function getAgent(store, id) {
172
174
  const revisions = await store.agents.revisions(id); // oldest first (created_at, id)
173
175
  const at = agent.currentRevision === null ? -1 : revisions.findIndex((r) => r.id === agent.currentRevision);
174
176
  const revision = at < 0 ? null : revisions[at];
175
- return { agent, revision, version: at < 0 ? 0 : at + 1, revisions: revisions.length, sizes: sizesOf(revision), template: revisions[0]?.package ?? null };
177
+ return { agent, revision, version: at < 0 ? 0 : at + 1, revisions: revisions.length, sizes: sizesOf(revision), template: revisions.findLast((r) => r.package)?.package ?? null };
176
178
  }
177
179
  /** Every agent here, newest first (its creation, then its id). Archived agents are left out by default. */
178
180
  export async function listAgents(store, options = {}) {
@@ -234,8 +236,11 @@ const EDIT_TRIES = 5;
234
236
  * holds across every server on the store. `check` may refuse the revision before a write; it runs outside the write, so
235
237
  * another request may move the current revision meanwhile: an edit with If-Match is then precondition_failed, and one
236
238
  * without is built and checked again on the new current revision, so what it leaves out (skill files, harness, place, learning, cap) is never carried over from a
237
- * revision it does not follow. `contract`: an edit that always makes a new revision, even one equal to the current. */
238
- export async function commitAgent(store, read, { definition, skills, note }, { ifCurrent, check, contract = false } = {}) {
239
+ * revision it does not follow. `contract`: an edit that always makes a new revision, even one equal to the current.
240
+ * `template`: the package an apply with agent_id wrote it from, kept on the revision (getAgent's `template`).
241
+ * `fromPackage`: the definition is a whole package's (an apply with agent_id), so what it leaves out is not carried over
242
+ * (editOn). */
243
+ export async function commitAgent(store, read, { definition, skills, note }, { ifCurrent, check, contract = false, template, fromPackage = false } = {}) {
239
244
  const stale = () => new ApiError("precondition_failed", "the agent's current revision moved since the If-Match it was read at: read the agent again");
240
245
  const held = (entry) => {
241
246
  if (ifCurrent !== undefined && (entry.revision?.id ?? null) !== ifCurrent)
@@ -257,7 +262,9 @@ export async function commitAgent(store, read, { definition, skills, note }, { i
257
262
  for (let tries = 1;; tries++) {
258
263
  if (tries > 1)
259
264
  entry = held((await getAgent(store, agent.id)) ?? entry);
260
- const edit = editOn(entry, definition, skills, note);
265
+ // A template applied onto the agent (apply with agent_id) keeps its package on the revision it writes, as a create does.
266
+ const made = editOn(entry, definition, skills, note, fromPackage);
267
+ const edit = template ? { ...made, package: template } : made;
261
268
  const revision = stamped(edit, await check?.(edit, entry.revision));
262
269
  const base = entry.revision?.id ?? null;
263
270
  const now = held((await getAgent(store, agent.id)) ?? entry);
@@ -290,7 +297,7 @@ export async function commitAgent(store, read, { definition, skills, note }, { i
290
297
  }
291
298
  /** The revision an edit makes on `entry`'s current one: what the edit leaves out keeps the current revision's, its skill
292
299
  * files, harness, place, learning switch and default cap. Absent here is unchanged, not the default. */
293
- function editOn(entry, definition, skills, note) {
300
+ function editOn(entry, definition, skills, note, fromPackage = false) {
294
301
  const current = entry.revision;
295
302
  const currentBody = (current?.body ?? {});
296
303
  let files = skills;
@@ -303,6 +310,13 @@ function editOn(entry, definition, skills, note) {
303
310
  ...(definition.harness === undefined && currentBody.harness ? { harness: currentBody.harness } : {}),
304
311
  // The computer and its place go together: an edit naming neither keeps both (the computer, else the place).
305
312
  ...(definition.place === undefined && definition.computer === undefined ? (currentBody.computer ? { computer: currentBody.computer } : currentBody.place ? { place: currentBody.place } : {}) : {}),
313
+ }
314
+ : {};
315
+ // A template's update (fromPackage) replaces what the package owns: the learning switch, the default cap, the input and
316
+ // answer schemas and the checkout it leaves out are gone, never carried from the revision the package wrote before.
317
+ // What the host owns (the sdk and native references, the harness, the computer and place) carries as an edit's does.
318
+ const owned = current && !fromPackage
319
+ ? {
306
320
  ...(definition.learning === undefined && current.kind === "agentic" && !isObject(definition.workflow) && currentBody.learning !== undefined ? { learning: currentBody.learning } : {}),
307
321
  // No approvals here: an edit that leaves them out asks (openapi.ts DefinitionInput.approvals),
308
322
  // so no edit makes an agent unattended by saying nothing. The console's edit sends back the approvals it read.
@@ -315,7 +329,7 @@ function editOn(entry, definition, skills, note) {
315
329
  ...(definition.checkout === undefined && current.kind === "agentic" && !isObject(definition.workflow) && currentBody.checkout !== undefined ? { checkout: currentBody.checkout } : {}),
316
330
  }
317
331
  : {};
318
- return makeRevision({ ...definition, ...carried }, files, note);
332
+ return makeRevision({ ...definition, ...carried, ...owned }, files, note);
319
333
  }
320
334
  /** Makes `revisionId`, one of the agent's own, its current one (POST /agents/{id}/current). */
321
335
  export async function setCurrentRevision(store, entry, revisionId) {
package/dist/agents.d.ts CHANGED
@@ -13,8 +13,12 @@ export declare function whenFree<T>(act: () => T | Promise<T>, delaysMs: readonl
13
13
  export declare const storeBusy: (error: unknown) => boolean;
14
14
  /** The answer to a request the agent store stayed busy for. */
15
15
  export declare const homeBusy: () => ApiError;
16
+ /** The answer to a run, a trigger or a write refused because its agent is being deleted (the store's AgentDeleting, read
17
+ * in the transaction that would start or reopen the run or write the trigger; the server's own check for a write). */
18
+ export declare const agentDeleting: (agentId: string) => ApiError;
16
19
  /** What a request's error answers, over HTTP and through an MCP tool alike (server.ts, mcp.ts dispatch): an ApiError as
17
- * it is; a busy store home_busy (409, retryable), never 500; anything else internal, its message kept. */
20
+ * it is; a busy store home_busy (409, retryable), never 500; a run of an agent being deleted agent_not_runnable (409);
21
+ * anything else internal, its message kept. */
18
22
  export declare const answerOf: (error: unknown) => ApiError;
19
23
  /** Whether a request's error goes to the server's log: every fault the server did not answer on purpose. A busy wait
20
24
  * is not one; a transaction past its deadline is (something held the store that long). */
package/dist/agents.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // (whenFree), then answered home_busy. The agents themselves are over the one store (agents-store.ts).
3
3
  import { ApiError } from "./errors.js";
4
4
  import { isObject } from "./validate.js";
5
- import { StoreBusy, StoreDeadline } from "./store/index.js";
5
+ import { AgentDeleting, StoreBusy, StoreDeadline } from "./store/index.js";
6
6
  /** SQLITE_BUSY or SQLITE_LOCKED: another connection holds the database. */
7
7
  export const sqliteBusy = (error) => isObject(error) && error.code === "ERR_SQLITE_ERROR" && typeof error.errcode === "number" && [5, 6].includes(error.errcode & 0xff);
8
8
  /** How long a request waits for a busy agent store, step by step: short first, so a reader's overlap costs
@@ -33,9 +33,13 @@ export async function whenFree(act, delaysMs, onBusy) {
33
33
  export const storeBusy = (error) => sqliteBusy(error) || error instanceof StoreBusy || error instanceof StoreDeadline;
34
34
  /** The answer to a request the agent store stayed busy for. */
35
35
  export const homeBusy = () => new ApiError("home_busy", "the agent store is busy with another write; try again", { retry_after_ms: 500 });
36
+ /** The answer to a run, a trigger or a write refused because its agent is being deleted (the store's AgentDeleting, read
37
+ * in the transaction that would start or reopen the run or write the trigger; the server's own check for a write). */
38
+ export const agentDeleting = (agentId) => new ApiError("agent_not_runnable", `The agent ${agentId} is being deleted (DELETE /v2/agents/${agentId}): it starts no run, opens none again and takes no new trigger or write. Send the DELETE again to finish it.`);
36
39
  /** What a request's error answers, over HTTP and through an MCP tool alike (server.ts, mcp.ts dispatch): an ApiError as
37
- * it is; a busy store home_busy (409, retryable), never 500; anything else internal, its message kept. */
38
- export const answerOf = (error) => error instanceof ApiError ? error : storeBusy(error) ? homeBusy() : new ApiError("internal", error?.message ?? String(error));
40
+ * it is; a busy store home_busy (409, retryable), never 500; a run of an agent being deleted agent_not_runnable (409);
41
+ * anything else internal, its message kept. */
42
+ export const answerOf = (error) => error instanceof ApiError ? error : storeBusy(error) ? homeBusy() : error instanceof AgentDeleting ? agentDeleting(error.agentId) : new ApiError("internal", error?.message ?? String(error));
39
43
  /** Whether a request's error goes to the server's log: every fault the server did not answer on purpose. A busy wait
40
44
  * is not one; a transaction past its deadline is (something held the store that long). */
41
- export const logged = (error) => !(error instanceof ApiError) && (!storeBusy(error) || error instanceof StoreDeadline);
45
+ export const logged = (error) => !(error instanceof ApiError) && !(error instanceof AgentDeleting) && (!storeBusy(error) || error instanceof StoreDeadline);
@@ -3,9 +3,14 @@ import type { Route } from "./server.js";
3
3
  export declare const API_ONLY_ENV = "AGENTRUN_API_ONLY";
4
4
  /** The routes (server.ts ROUTES, by name) an API-only server serves: a run's launch, read, list, timeline, messages,
5
5
  * stop, cancel, cap raise and grade; its files and the uploads a launch names; an agent's Archil disk, read and removed (the
6
- * agent layer of a run's disk, archil-routes.ts); capabilities, health and usage; and a run's hosted machine that dials
7
- * fetching this server's computerd with its own token (computer-attach.ts), as it dials the attach socket, which the
8
- * upgrade takes for such a machine alone (a paired computer is the console's). */
6
+ * agent layer of a run's disk, archil-routes.ts); the delete of an agent its inline runs made (agent-delete.ts), which
7
+ * the backend that made it is the one to send; capabilities, health and usage; the two reads of the computer settings a
8
+ * backend checks before it launches, each by the token and naming keys and whether each is saved, never a value: the
9
+ * computer providers and whether each is ready (GET /computers, computers.ts) and the Archil settings, whether runs'
10
+ * folders are on Archil (GET /workspace/archil, archil-routes.ts), while their writes, tests and key choices stay the
11
+ * console's; and a run's hosted machine that dials fetching this server's computerd with its own token
12
+ * (computer-attach.ts), as it dials the attach socket, which the upgrade takes for such a machine alone (a paired
13
+ * computer is the console's). */
9
14
  export declare const API_ONLY_ROUTES: ReadonlySet<string>;
10
15
  /** Whether `env` turns the profile on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused in
11
16
  * words (a TypeError), so a typo never leaves the console open on a server meant to be API-only. */
package/dist/api-only.js CHANGED
@@ -2,12 +2,18 @@
2
2
  export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
3
3
  /** The routes (server.ts ROUTES, by name) an API-only server serves: a run's launch, read, list, timeline, messages,
4
4
  * stop, cancel, cap raise and grade; its files and the uploads a launch names; an agent's Archil disk, read and removed (the
5
- * agent layer of a run's disk, archil-routes.ts); capabilities, health and usage; and a run's hosted machine that dials
6
- * fetching this server's computerd with its own token (computer-attach.ts), as it dials the attach socket, which the
7
- * upgrade takes for such a machine alone (a paired computer is the console's). */
5
+ * agent layer of a run's disk, archil-routes.ts); the delete of an agent its inline runs made (agent-delete.ts), which
6
+ * the backend that made it is the one to send; capabilities, health and usage; the two reads of the computer settings a
7
+ * backend checks before it launches, each by the token and naming keys and whether each is saved, never a value: the
8
+ * computer providers and whether each is ready (GET /computers, computers.ts) and the Archil settings, whether runs'
9
+ * folders are on Archil (GET /workspace/archil, archil-routes.ts), while their writes, tests and key choices stay the
10
+ * console's; and a run's hosted machine that dials fetching this server's computerd with its own token
11
+ * (computer-attach.ts), as it dials the attach socket, which the upgrade takes for such a machine alone (a paired
12
+ * computer is the console's). */
8
13
  export const API_ONLY_ROUTES = new Set([
9
14
  "createRun", "createInlineRun", "getComputerDaemon",
10
- "getAgentArchil", "deleteAgentArchil",
15
+ "listComputers", "getWorkspaceArchil",
16
+ "getAgentArchil", "deleteAgentArchil", "deleteAgent",
11
17
  "getRun", "listRuns", "listAllRuns", "getTimeline",
12
18
  "sendMessage", "stopRun", "cancelRun", "raiseRunCap", "gradeRun",
13
19
  "listRunFiles", "readRunFile",
@@ -1,5 +1,6 @@
1
1
  import { type KeyEnv, type KeyMeta } from "./key-meta.js";
2
2
  import type { Store } from "./store/index.js";
3
+ import { type ArchilDisk, type ArchilDiskOptions } from "./workspace/archil-disk.js";
3
4
  /** The routes, by their operation names. */
4
5
  export declare const ARCHIL_ROUTES: ReadonlySet<string>;
5
6
  /** The key names the Archil settings take, as the document names them. */
@@ -46,10 +47,12 @@ export interface ArchilRoutesOptions {
46
47
  readonly store: Pick<Store, "settings" | "sealedKeys">;
47
48
  /** The server's seal key: there is always one (seal-key.ts bootSealKey, at the start). */
48
49
  readonly sealKey: Buffer;
49
- /** Another control plane than the region's, and its fetch: a test's fake. */
50
+ /** Another control plane than the region's, and its fetch, and another maker of a disk's file API than archilDisk:
51
+ * a test's fakes. */
50
52
  readonly control?: {
51
53
  readonly baseUrl?: string;
52
54
  readonly fetch?: typeof fetch;
55
+ readonly makeDisk?: (options: ArchilDiskOptions) => ArchilDisk;
53
56
  };
54
57
  /** The server's environment: an ARCHIL_API_KEY variable overrides the saved key, and ARCHIL_SETTINGS_ENV the saved
55
58
  * settings (source "env"). */
@@ -67,6 +70,7 @@ export declare function createArchilRoutes(options: ArchilRoutesOptions): {
67
70
  } | null;
68
71
  }>;
69
72
  checkLaunchDisk: (diskId: string, signal?: AbortSignal) => Promise<void>;
73
+ removeRunFolder: (agentId: string, runId: string, diskId: string) => Promise<void>;
70
74
  };
71
75
  export type ArchilRoutes = ReturnType<typeof createArchilRoutes>;
72
76
  /** One of the owner's Archil routes at its handler: its answer (sent 200), or an ApiError (sent with its status). An