@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.46

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 (350) hide show
  1. package/CHANGELOG.md +148 -5
  2. package/README.md +385 -305
  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 +62 -19
  28. package/dist/composio-preset.js +69 -7
  29. package/dist/composio-triggers.d.ts +14 -0
  30. package/dist/composio-triggers.js +79 -15
  31. package/dist/computer-attach.d.ts +40 -5
  32. package/dist/computer-attach.js +130 -15
  33. package/dist/computer-keys.d.ts +3 -0
  34. package/dist/computer-keys.js +7 -1
  35. package/dist/computer-live.js +3 -2
  36. package/dist/computers.d.ts +21 -10
  37. package/dist/computers.js +39 -28
  38. package/dist/console/assets/index-C2MYaUBa.css +1 -0
  39. package/dist/console/assets/index-CZZeCReB.js +701 -0
  40. package/dist/console/index.html +2 -2
  41. package/dist/decisions.d.ts +1 -1
  42. package/dist/dial-relay.d.ts +29 -0
  43. package/dist/dial-relay.js +94 -0
  44. package/dist/email/tools.js +10 -5
  45. package/dist/env-proxy.d.ts +2 -0
  46. package/dist/env-proxy.js +35 -0
  47. package/dist/errors.d.ts +3 -1
  48. package/dist/errors.js +7 -4
  49. package/dist/faux-computers.d.ts +8 -2
  50. package/dist/faux-computers.js +83 -6
  51. package/dist/harness-archive.d.ts +67 -0
  52. package/dist/harness-archive.js +177 -0
  53. package/dist/harness-goose.d.ts +34 -0
  54. package/dist/harness-goose.js +87 -0
  55. package/dist/harness-install.d.ts +21 -0
  56. package/dist/harness-install.js +24 -11
  57. package/dist/harness-opencode/adapter.js +1 -1
  58. package/dist/harness-table.d.ts +9 -1
  59. package/dist/harness-table.js +20 -3
  60. package/dist/harness.d.ts +1 -2
  61. package/dist/harness.js +3 -4
  62. package/dist/host.js +2 -1
  63. package/dist/import.d.ts +10 -0
  64. package/dist/import.js +28 -8
  65. package/dist/key-check.js +3 -0
  66. package/dist/learn/audit.d.ts +6 -6
  67. package/dist/learn/audit.js +3 -7
  68. package/dist/learn/check.d.ts +23 -89
  69. package/dist/learn/check.js +57 -335
  70. package/dist/learn/commit.d.ts +63 -90
  71. package/dist/learn/commit.js +124 -316
  72. package/dist/learn/compile.d.ts +53 -50
  73. package/dist/learn/compile.js +89 -104
  74. package/dist/learn/corrections.d.ts +13 -0
  75. package/dist/learn/corrections.js +23 -0
  76. package/dist/learn/delete.d.ts +5 -5
  77. package/dist/learn/delete.js +8 -10
  78. package/dist/learn/folder.d.ts +35 -47
  79. package/dist/learn/folder.js +118 -134
  80. package/dist/learn/index.d.ts +3 -5
  81. package/dist/learn/index.js +6 -9
  82. package/dist/learn/learning.sh +45 -15
  83. package/dist/learn/promote.d.ts +23 -5
  84. package/dist/learn/promote.js +40 -2
  85. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
  86. package/dist/learn/{skills.js → workflow-draft.js} +48 -58
  87. package/dist/learn/workflow-nodes.js +1 -1
  88. package/dist/learned-workflow.js +2 -2
  89. package/dist/learning-cost.d.ts +38 -24
  90. package/dist/learning-cost.js +41 -24
  91. package/dist/learning-routes.d.ts +91 -170
  92. package/dist/learning-routes.js +183 -421
  93. package/dist/learning-run.d.ts +19 -40
  94. package/dist/learning-run.js +23 -93
  95. package/dist/learning-setting.d.ts +21 -10
  96. package/dist/learning-setting.js +47 -11
  97. package/dist/learning-words.d.ts +28 -74
  98. package/dist/learning-words.js +64 -162
  99. package/dist/learning.d.ts +61 -392
  100. package/dist/learning.js +101 -651
  101. package/dist/live-reach.d.ts +25 -2
  102. package/dist/live-reach.js +46 -4
  103. package/dist/llms.txt +1 -1
  104. package/dist/local-models.d.ts +3 -11
  105. package/dist/local-models.js +5 -6
  106. package/dist/mcp-servers-store.d.ts +4 -4
  107. package/dist/model-form.js +6 -5
  108. package/dist/model.d.ts +4 -0
  109. package/dist/model.js +26 -9
  110. package/dist/native/binding.js +1 -1
  111. package/dist/native/connection.js +1 -1
  112. package/dist/native/discovery.js +1 -1
  113. package/dist/native/instructions.d.ts +3 -0
  114. package/dist/native/instructions.js +5 -3
  115. package/dist/native/remote-worker-bridge.js +9 -43
  116. package/dist/native/remote.d.ts +8 -15
  117. package/dist/native/remote.js +3 -3
  118. package/dist/native/schema.js +1 -1
  119. package/dist/native/types.d.ts +2 -2
  120. package/dist/openapi.js +273 -319
  121. package/dist/paid-calls.d.ts +8 -0
  122. package/dist/paid-calls.js +20 -0
  123. package/dist/particle-provider.d.ts +11 -0
  124. package/dist/particle-provider.js +135 -0
  125. package/dist/port-models.d.ts +12 -4
  126. package/dist/port-models.js +28 -11
  127. package/dist/print.d.ts +27 -0
  128. package/dist/print.js +21 -0
  129. package/dist/provider.d.ts +7 -0
  130. package/dist/provider.js +15 -1
  131. package/dist/reflect-range.js +2 -3
  132. package/dist/run-launch.d.ts +14 -28
  133. package/dist/run-launch.js +9 -12
  134. package/dist/run-learning-served.d.ts +15 -89
  135. package/dist/run-listing.d.ts +34 -0
  136. package/dist/run-listing.js +128 -0
  137. package/dist/run-model-key.js +1 -1
  138. package/dist/run-timeline-served.js +5 -3
  139. package/dist/run-trace.d.ts +97 -0
  140. package/dist/run-trace.js +253 -0
  141. package/dist/run-view.d.ts +15 -0
  142. package/dist/run-view.js +9 -0
  143. package/dist/runnable.js +2 -1
  144. package/dist/runner/adapter-loop.d.ts +8 -6
  145. package/dist/runner/adapter-loop.js +16 -12
  146. package/dist/runner/adapter-run-spec.d.ts +16 -4
  147. package/dist/runner/adapter-run-spec.js +64 -58
  148. package/dist/runner/adapters/index.js +22 -0
  149. package/dist/runner/adapters/pi.d.ts +4 -12
  150. package/dist/runner/adapters/pi.js +2 -2
  151. package/dist/runner/audit.d.ts +1 -1
  152. package/dist/runner/audit.js +30 -13
  153. package/dist/runner/beside.d.ts +6 -2
  154. package/dist/runner/beside.js +38 -9
  155. package/dist/runner/claim-secrets.d.ts +18 -2
  156. package/dist/runner/claim-secrets.js +42 -18
  157. package/dist/runner/cli-run-spec.js +55 -51
  158. package/dist/runner/conformance/harness.d.ts +6 -0
  159. package/dist/runner/conformance/harness.js +35 -13
  160. package/dist/runner/conformance/subject.d.ts +6 -0
  161. package/dist/runner/dispatch.d.ts +2 -2
  162. package/dist/runner/end-of-run.d.ts +6 -14
  163. package/dist/runner/end-of-run.js +8 -33
  164. package/dist/runner/feedback-round.d.ts +2 -2
  165. package/dist/runner/feedback-round.js +7 -7
  166. package/dist/runner/github-app.js +3 -1
  167. package/dist/runner/harness-loops.d.ts +0 -8
  168. package/dist/runner/harness-loops.js +11 -59
  169. package/dist/runner/held.d.ts +170 -0
  170. package/dist/runner/held.js +57 -0
  171. package/dist/runner/journal-kinds.d.ts +2 -3
  172. package/dist/runner/journal-kinds.js +2 -3
  173. package/dist/runner/learned-first.d.ts +40 -0
  174. package/dist/runner/learned-first.js +32 -0
  175. package/dist/runner/learning-end.d.ts +77 -69
  176. package/dist/runner/learning-end.js +250 -303
  177. package/dist/runner/learning-seed.d.ts +15 -33
  178. package/dist/runner/learning-seed.js +24 -45
  179. package/dist/runner/loop-contract.d.ts +2 -3
  180. package/dist/runner/main.d.ts +17 -9
  181. package/dist/runner/main.js +82 -20
  182. package/dist/runner/mcp-run.d.ts +11 -0
  183. package/dist/runner/mcp-run.js +67 -0
  184. package/dist/runner/memory-claim.d.ts +10 -5
  185. package/dist/runner/memory-claim.js +12 -6
  186. package/dist/runner/model-route.d.ts +7 -4
  187. package/dist/runner/model-route.js +22 -10
  188. package/dist/runner/native-loop.d.ts +0 -7
  189. package/dist/runner/native-loop.js +9 -101
  190. package/dist/runner/promotion.d.ts +12 -8
  191. package/dist/runner/promotion.js +37 -28
  192. package/dist/runner/reflect-hook.d.ts +64 -95
  193. package/dist/runner/reflect-hook.js +112 -225
  194. package/dist/runner/run-channel.d.ts +43 -0
  195. package/dist/runner/run-channel.js +467 -0
  196. package/dist/runner/run-child-host.d.ts +169 -0
  197. package/dist/runner/run-child-host.js +1230 -0
  198. package/dist/runner/run-child.d.ts +1 -0
  199. package/dist/runner/run-child.js +254 -0
  200. package/dist/runner/run-errors.d.ts +2 -0
  201. package/dist/runner/run-errors.js +20 -0
  202. package/dist/runner/runner.js +1 -5
  203. package/dist/runner/sdk-ask.d.ts +78 -0
  204. package/dist/runner/sdk-ask.js +158 -0
  205. package/dist/runner/sdk-loop.d.ts +2 -4
  206. package/dist/runner/sdk-loop.js +29 -49
  207. package/dist/runner/store-secrets.d.ts +5 -3
  208. package/dist/runner/store-secrets.js +5 -1
  209. package/dist/runner/workflow-first.d.ts +5 -0
  210. package/dist/runner/workflow-first.js +4 -0
  211. package/dist/runner/workflow-spec.js +7 -2
  212. package/dist/runs-over-store.d.ts +16 -28
  213. package/dist/runs-over-store.js +31 -38
  214. package/dist/sdk/runs.d.ts +6 -11
  215. package/dist/sdk/runs.js +20 -41
  216. package/dist/sdk/schema.js +3 -4
  217. package/dist/seal-key.d.ts +5 -0
  218. package/dist/seal-key.js +7 -0
  219. package/dist/secrets.d.ts +3 -0
  220. package/dist/secrets.js +16 -3
  221. package/dist/server.d.ts +55 -33
  222. package/dist/server.js +689 -322
  223. package/dist/sign-ins-store.d.ts +8 -0
  224. package/dist/sign-ins-store.js +36 -1
  225. package/dist/skills.js +1 -1
  226. package/dist/store/index.d.ts +2 -2
  227. package/dist/store/index.js +1 -1
  228. package/dist/store/journal/storage.js +3 -0
  229. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  230. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  231. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  232. package/dist/store/schema.d.ts +53 -4
  233. package/dist/store/schema.js +137 -6
  234. package/dist/store/sqlite/connection.d.ts +2 -0
  235. package/dist/store/sqlite/connection.js +3 -1
  236. package/dist/store/sqlite/run-patch.d.ts +0 -17
  237. package/dist/store/sqlite/run-patch.js +4 -33
  238. package/dist/store/sqlite/store.js +246 -63
  239. package/dist/store/sqlite/worker.js +25 -0
  240. package/dist/store/store.d.ts +193 -36
  241. package/dist/store/store.js +25 -3
  242. package/dist/store-reads/learning.d.ts +102 -204
  243. package/dist/store-reads/learning.js +159 -321
  244. package/dist/store-reads/loop.d.ts +0 -1
  245. package/dist/store-reads/loop.js +1 -1
  246. package/dist/store-view.d.ts +29 -1
  247. package/dist/store-view.js +97 -31
  248. package/dist/template-eval.d.ts +3 -6
  249. package/dist/template-eval.js +22 -36
  250. package/dist/templates.d.ts +8 -4
  251. package/dist/templates.js +44 -6
  252. package/dist/timeline/index.d.ts +1 -1
  253. package/dist/timeline/index.js +1 -1
  254. package/dist/timeline/timeline.d.ts +5 -1
  255. package/dist/timeline/timeline.js +16 -0
  256. package/dist/tool-gate.d.ts +0 -7
  257. package/dist/tool-gate.js +1 -15
  258. package/dist/tool-keys-store.d.ts +1 -1
  259. package/dist/tool-keys.d.ts +6 -4
  260. package/dist/tool-keys.js +12 -6
  261. package/dist/tools.d.ts +2 -2
  262. package/dist/tools.js +11 -4
  263. package/dist/triggers.d.ts +65 -6
  264. package/dist/triggers.js +125 -19
  265. package/dist/validate.js +1 -1
  266. package/dist/webhooks.d.ts +7 -2
  267. package/dist/webhooks.js +12 -5
  268. package/dist/workspace/agent-computer.d.ts +2 -0
  269. package/dist/workspace/agent-computer.js +2 -0
  270. package/dist/workspace/archil-claim.d.ts +7 -0
  271. package/dist/workspace/archil-claim.js +29 -0
  272. package/dist/workspace/archil.d.ts +9 -1
  273. package/dist/workspace/archil.js +165 -3
  274. package/dist/workspace/attach.d.ts +3 -1
  275. package/dist/workspace/attach.js +2 -0
  276. package/dist/workspace/attached-computers.d.ts +16 -5
  277. package/dist/workspace/attached-computers.js +25 -9
  278. package/dist/workspace/computer-deps.js +1 -1
  279. package/dist/workspace/computer-for-claim.d.ts +7 -3
  280. package/dist/workspace/computer-for-claim.js +119 -22
  281. package/dist/workspace/computer-hold.js +2 -1
  282. package/dist/workspace/computer-kept.d.ts +11 -1
  283. package/dist/workspace/computer-kept.js +24 -3
  284. package/dist/workspace/resolve-computer.d.ts +33 -19
  285. package/dist/workspace/resolve-computer.js +172 -64
  286. package/dist/workspace/revision-skills.d.ts +1 -2
  287. package/dist/workspace/revision-skills.js +3 -4
  288. package/dist/workspace/run-workspace.d.ts +1 -1
  289. package/dist/workspace/run-workspace.js +5 -0
  290. package/dist/workspace/synced-folder.d.ts +85 -0
  291. package/dist/workspace/synced-folder.js +230 -0
  292. package/dist/workspace/workspace.d.ts +4 -0
  293. package/launcher/agentrun-serve +1 -1
  294. package/package.json +10 -10
  295. package/templates/README.md +8 -8
  296. package/templates/inbound-lead/agent.md +5 -4
  297. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  298. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  299. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  300. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  301. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  302. package/templates/inbound-lead/lead.schema.json +6 -5
  303. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  304. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  305. package/templates/kyb/agent.md +2 -1
  306. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  307. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  308. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  309. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  310. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  311. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  312. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  313. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  314. package/dist/console/assets/index-BUktRvS-.css +0 -1
  315. package/dist/console/assets/index-nB9kTfIN.js +0 -711
  316. package/dist/learn/grade.d.ts +0 -138
  317. package/dist/learn/grade.js +0 -682
  318. package/dist/learn/notes.d.ts +0 -81
  319. package/dist/learn/notes.js +0 -178
  320. package/dist/learn/reflect.d.ts +0 -77
  321. package/dist/learn/reflect.js +0 -228
  322. package/dist/learn/relevance.d.ts +0 -24
  323. package/dist/learn/relevance.js +0 -91
  324. package/dist/learn/seed-check.d.ts +0 -74
  325. package/dist/learn/seed-check.js +0 -103
  326. package/dist/learning-batch.d.ts +0 -291
  327. package/dist/learning-batch.js +0 -600
  328. package/dist/learning-evals.d.ts +0 -35
  329. package/dist/learning-evals.js +0 -99
  330. package/dist/native/context.d.ts +0 -6
  331. package/dist/native/context.js +0 -22
  332. package/dist/propose.d.ts +0 -52
  333. package/dist/propose.js +0 -224
  334. package/dist/runner/learning-ask.d.ts +0 -47
  335. package/dist/runner/learning-ask.js +0 -128
  336. package/dist/runner/learning-dispatch.d.ts +0 -45
  337. package/dist/runner/learning-dispatch.js +0 -99
  338. package/dist/runner/learning-factory.d.ts +0 -16
  339. package/dist/runner/learning-factory.js +0 -50
  340. package/dist/runner/learning-loop.d.ts +0 -273
  341. package/dist/runner/learning-loop.js +0 -521
  342. package/dist/usage.d.ts +0 -11
  343. package/dist/usage.js +0 -11
  344. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  345. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  346. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  347. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  348. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  349. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  350. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
package/dist/templates.js CHANGED
@@ -29,6 +29,7 @@ import { definitionBodyIssues, inputIssues, inputSchemaOf, isObject, MODEL_REF,
29
29
  import { schemaCheck } from "./answer-json.js";
30
30
  import { webFixtureOf } from "./web-fake.js";
31
31
  import { APPROVALS } from "./approvals.js";
32
+ import { agreeOnOf, learningSettingIssue, learningSettingOf, pathSegments } from "./learning-setting.js";
32
33
  export const TEMPLATES_DIR = fileURLToPath(new URL("../templates/", import.meta.url));
33
34
  export const MANIFEST = "agent.md";
34
35
  /** A package's model tier, mapped to the server's own (model.ts Tier: AGENT_MODEL_FAST, AGENT_MODEL, AGENT_MODEL_STRONG). */
@@ -152,6 +153,26 @@ export class PackageError extends Error {
152
153
  this.problems = problems;
153
154
  }
154
155
  }
156
+ /** Why an agree_on path is not a required field of the answer's JSON Schema at every level, in words; undefined when it
157
+ * is (each segment a property of an object schema's `properties`, named in its `required`, and each parent typed
158
+ * `object` alone: one that may be null or another type holds no path, even on two identical answers). */
159
+ function undeclaredPath(schema, path) {
160
+ let node = schema;
161
+ const segments = pathSegments(path);
162
+ for (const [i, segment] of segments.entries()) {
163
+ const of = i ? segments.slice(0, i).join(".") : "the answer";
164
+ if (!(isObject(node) && node.type === "object"))
165
+ return `does not make ${of} an object only: an answer may give it as null or another type, and a path through it never resolves`;
166
+ const properties = isObject(node) && isObject(node.properties) ? node.properties : undefined;
167
+ if (!properties || !Object.hasOwn(properties, segment))
168
+ return `does not declare: ${segment} is no property of ${of}`;
169
+ const required = node.required;
170
+ if (!(Array.isArray(required) && required.includes(segment)))
171
+ return `does not require: an answer may leave ${segment} out of ${of}, and a path missing on both sides never agrees`;
172
+ node = properties[segment];
173
+ }
174
+ return undefined;
175
+ }
155
176
  /** The source kinds whose accept rules a parameter may fill: a github trigger's, a webhook trigger's (a provider that
156
177
  * sends every trigger of a project to one URL is filtered to the owner's own repository by them), a composio
157
178
  * trigger's, and a feed trigger's (the pull requests of one author, say). */
@@ -674,8 +695,9 @@ export function readPackage(from, { evalFixtures = true } = {}) {
674
695
  const perRun = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
675
696
  if (f.budget !== undefined && !(isObject(f.budget) && !unknownFields(f.budget, ["per_run_usd"]).length && perRun(f.budget.per_run_usd)))
676
697
  bad(MANIFEST, "budget is {per_run_usd: a number above 0}");
677
- if (f.learning !== undefined && typeof f.learning !== "boolean")
678
- bad(MANIFEST, "learning is true or false");
698
+ const learningIssue = f.learning === undefined ? undefined : learningSettingIssue(f.learning, "learning");
699
+ if (learningIssue)
700
+ bad(MANIFEST, learningIssue);
679
701
  if (f.approvals !== undefined && f.approvals !== "ask" && f.approvals !== "never")
680
702
  bad(MANIFEST, "approvals is ask (the agent asks its person before a tool runs) or never (it runs unattended; deny and pins still hold)");
681
703
  const triggers = f.triggers === undefined ? [] : Array.isArray(f.triggers) ? f.triggers : (bad(MANIFEST, "triggers is a list of POST /v2/triggers bodies"), []);
@@ -731,6 +753,19 @@ export function readPackage(from, { evalFixtures = true } = {}) {
731
753
  }
732
754
  }
733
755
  }
756
+ // Each agree_on path is a required field of the answer's schema at every level: one an answer may leave out is
757
+ // missing on both sides, and a missing path never agrees, so the check could never promote on it.
758
+ // With no output schema there is nothing to check the paths against, and nothing makes an answer hold them: refused.
759
+ if (!learningIssue && f.output === undefined && (agreeOnOf(f.learning) ?? []).length) {
760
+ bad(MANIFEST, "learning.agree_on names fields of the answer, so the package declares the answer's schema (output: {schema}) that holds them");
761
+ }
762
+ if (!learningIssue && isObject(outputSchema)) {
763
+ for (const [i, path] of (agreeOnOf(f.learning) ?? []).entries()) {
764
+ const why = undeclaredPath(outputSchema, path);
765
+ if (why)
766
+ bad(MANIFEST, `learning.agree_on[${i}] is ${path}, which ${f.output.schema} ${why}`);
767
+ }
768
+ }
734
769
  const instructions = manifest?.body.trim() ?? "";
735
770
  if (manifest && !instructions)
736
771
  bad(MANIFEST, "its body is empty: the body is the agent's instructions");
@@ -904,7 +939,7 @@ export function readPackage(from, { evalFixtures = true } = {}) {
904
939
  ...(typeof f.license === "string" ? { license: f.license } : {}), ...(isObject(f.author) ? { author: f.author } : {}), ...(typeof f.repository === "string" ? { repository: f.repository } : {}),
905
940
  ...(typeof f.category === "string" ? { category: f.category } : {}), tags,
906
941
  ...(harness ? { harness } : {}), ...(isObject(f.model) ? { model: { ...f.model, ...(choices ? { choices } : {}) } } : {}), ...(typeof f.effort === "string" ? { effort: f.effort } : {}),
907
- ...(tools ? { tools } : {}), mcp, ...(computer ? { computer } : {}), ...(toolPolicy ? { toolPolicy } : {}), ...(f.checkout === "pull_request" ? { checkout: "pull_request" } : {}), parameters, ...(inputSchema ? { inputSchema } : {}), secrets, ...(isObject(f.budget) ? { budget: { per_run_usd: f.budget.per_run_usd } } : {}), ...(typeof f.learning === "boolean" ? { learning: f.learning } : {}), ...(f.approvals === "ask" || f.approvals === "never" ? { approvals: f.approvals } : {}),
942
+ ...(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.learning !== undefined ? { learning: learningSettingOf(f.learning) } : {}), ...(f.approvals === "ask" || f.approvals === "never" ? { approvals: f.approvals } : {}),
908
943
  triggers: triggers, ...(isObject(f.output) ? { output: { schema: f.output.schema } } : {}), ...(isObject(outputSchema) ? { outputSchema } : {}), instructions, skills, evals,
909
944
  };
910
945
  // What an apply makes, made here with each parameter's default, else a sample of its type, and checked as POST
@@ -1027,12 +1062,15 @@ export class TemplateRegistry {
1027
1062
  return this.imported.delete(id);
1028
1063
  }
1029
1064
  }
1030
- /** POST /v2/templates/{name}/apply's body (`{parameters, grants?, overrides?: {model?, choice?, approvals?}}`), checked
1065
+ /** POST /v2/templates/{name}/apply's body (`{parameters, grants?, servers?, overrides?: {model?, choice?, approvals?}, agent_id?}`), checked
1031
1066
  * against the package: the parameters as given (a blank one at its default), the MCP tools the owner allows (each one the
1032
1067
  * package lists, by its gate name), and the model asked for in place of the package's: one of its own (`model`), or one
1033
1068
  * of the package's model choices by id (`choice`), never both. 422 naming every field that is wrong. */
1034
1069
  export function applyBodyOf(p, body) {
1035
- const issues = unknownFields(body, ["parameters", "grants", "servers", "overrides"]);
1070
+ const issues = unknownFields(body, ["parameters", "grants", "servers", "overrides", "agent_id"]);
1071
+ // The agent an update writes onto (the server checks it was made from this package): text, else a 422 with the rest.
1072
+ if (body.agent_id !== undefined && !(typeof body.agent_id === "string" && body.agent_id.trim()))
1073
+ 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` });
1036
1074
  const listed = p.mcp.flatMap(({ toolkit, tools }) => tools.map((tool) => mcpToolName(toolkit, tool)));
1037
1075
  const grants = [];
1038
1076
  if (body.grants !== undefined && !Array.isArray(body.grants))
@@ -1088,7 +1126,7 @@ export function applyBodyOf(p, body) {
1088
1126
  }
1089
1127
  if (issues.length)
1090
1128
  throw invalid(issues);
1091
- return { parameters, grants, servers, ...(isObject(overrides) && typeof overrides.model === "string" ? { model: overrides.model } : {}), ...(choice ? { choice } : {}), ...(isObject(overrides) && (overrides.approvals === "ask" || overrides.approvals === "never") ? { approvals: overrides.approvals } : {}) };
1129
+ 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 } : {}) };
1092
1130
  }
1093
1131
  /** The model a package's agent gets here, as `{model?, warning?}`: its `prefer` when this server runs it on `harness`
1094
1132
  * with a key for its provider, else `refused` (preferUnrunnable): apply makes nothing, never the tier's model in its
@@ -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 { BROWSER_CHARGE, CALL_ENDED_WITH_RUN, 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, 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";
@@ -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 { BROWSER_CHARGE, CALL_ENDED_WITH_RUN, 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, 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";
@@ -5,7 +5,7 @@ import type { ComputerCallRow } from "./computer.js";
5
5
  export type TimelineKind = "thinking" | "text_block" | "tool_use" | "tool_result" | "phase" | "subagent_started" | "subagent_progress" | "subagent_completed" | "final_answer" | "error" | "user_message" | "waiting" | "usage"
6
6
  /** A workflow decision: a judge's answers or a route's branch (serve's decision rows). */
7
7
  | "decision"
8
- /** Where a run's learning ended: proposed, merged or dropped (serve's learning row). */
8
+ /** Where a run's learning ended: merged or dropped (serve's learning row). */
9
9
  | "learning"
10
10
  /** A tool call that waited for a person's approval, after its result's row (serve's tool gate). */
11
11
  | "tool_approval_requested";
@@ -365,3 +365,7 @@ export declare function timelineReducer(options?: TimelineOptions): {
365
365
  * conversation no longer holds it. */
366
366
  isLive: (id: string) => boolean;
367
367
  };
368
+ /** The run's model requests that an answer of pi's carries, in log order: each `pi.assistant` entry the usage row counts
369
+ * as a request (createMeter's "answer"). A request the cap or the proxy refused before it left, a continuation of the
370
+ * answer before it and a call the loop's record kept (`recordedCall`) are none. An entry seen twice counts once. */
371
+ export declare function answeredRequests(entries: readonly EntryLike[]): EntryLike[];
@@ -1467,3 +1467,19 @@ export function timelineReducer(options = {}) {
1467
1467
  isLive: (id) => liveIds.has(id),
1468
1468
  };
1469
1469
  }
1470
+ /** The run's model requests that an answer of pi's carries, in log order: each `pi.assistant` entry the usage row counts
1471
+ * as a request (createMeter's "answer"). A request the cap or the proxy refused before it left, a continuation of the
1472
+ * answer before it and a call the loop's record kept (`recordedCall`) are none. An entry seen twice counts once. */
1473
+ export function answeredRequests(entries) {
1474
+ const meter = createMeter();
1475
+ const seen = new Set();
1476
+ return entries.filter((entry) => {
1477
+ if (entry.id !== undefined) {
1478
+ const key = `${entry.conversationId ?? 0}:${entry.id}`;
1479
+ if (seen.has(key))
1480
+ return false;
1481
+ seen.add(key);
1482
+ }
1483
+ return meter.push(entry) === "answer";
1484
+ });
1485
+ }
@@ -157,13 +157,6 @@ export declare const noApproverText: (tool: string, ran?: "no" | "unknown", beca
157
157
  export declare const APPROVAL_ROW: "tool_approval_requested";
158
158
  /** A call's arguments shown on its approval, at most this many bytes. */
159
159
  export declare const ARGS_PREVIEW_BYTES = 2048;
160
- /** The refusal of the end-of-run turn's write or edit under work/.learning/: its notes are kept only from its answer's
161
- * note blocks (learn/reflect.ts parseReflection), which the host merges in its own store; a file there is never kept. */
162
- export declare const NOTE_ONLY_TEXT = "A note is kept only from your answer: write it in a ```note block, not to a file.";
163
- /** Whether `args.path`, as a file tool resolves it (a leading `@` dropped, Unicode spaces made plain, then the port's
164
- * path of it, portPath), names .learning/ in the run's folder or a path under it: by the folder's path here (`work`)
165
- * or a computer's name for it (COMPUTER_ROOT). */
166
- export declare function underLearning(work: string, args: unknown): boolean;
167
160
  /** One call that waits for approval, as the run's store keeps it. */
168
161
  export type ApprovalRequest = {
169
162
  id: string;
package/dist/tool-gate.js CHANGED
@@ -26,8 +26,7 @@
26
26
  // in words, never parked.
27
27
  import { COMPUTER_OP_TOOL, computerToolDefs, defaultPermissionOf, SHELL_FAMILY, SHELL_WATCHERS, shellPermission, shellToolOf } from "@parcha/agentrun-kernel/kernel";
28
28
  import { READ_SKILL_FILE } from "@parcha/agentrun-kernel";
29
- import { LEARNED_DIR } from "./learning.js";
30
- import { COMPUTER_ROOT, portPath } from "./workspace/paths.js";
29
+ import { COMPUTER_ROOT } from "./workspace/paths.js";
31
30
  import { builtinHarness } from "./harness-table.js";
32
31
  import { META_TOOLS } from "./meta-tool-names.js";
33
32
  import { DEFAULT_HARNESS } from "./harness.js";
@@ -338,19 +337,6 @@ export const noApproverText = (tool, ran = "no", because) => because === undefin
338
337
  export const APPROVAL_ROW = "tool_approval_requested";
339
338
  /** A call's arguments shown on its approval, at most this many bytes. */
340
339
  export const ARGS_PREVIEW_BYTES = 2048;
341
- /** The refusal of the end-of-run turn's write or edit under work/.learning/: its notes are kept only from its answer's
342
- * note blocks (learn/reflect.ts parseReflection), which the host merges in its own store; a file there is never kept. */
343
- export const NOTE_ONLY_TEXT = "A note is kept only from your answer: write it in a ```note block, not to a file.";
344
- /** Whether `args.path`, as a file tool resolves it (a leading `@` dropped, Unicode spaces made plain, then the port's
345
- * path of it, portPath), names .learning/ in the run's folder or a path under it: by the folder's path here (`work`)
346
- * or a computer's name for it (COMPUTER_ROOT). */
347
- export function underLearning(work, args) {
348
- const path = args?.path;
349
- if (typeof path !== "string")
350
- return false;
351
- const plain = path.replace(/[\u00A0\u2002-\u200A\u202F\u205F\u3000]/g, " ").replace(/^@/, "");
352
- return portPath(plain, [work, COMPUTER_ROOT])?.split("/")[0] === LEARNED_DIR;
353
- }
354
340
  /** `text` cut to at most ARGS_PREVIEW_BYTES. What is shown of a call's arguments is the whole of them redacted first, then
355
341
  * cut (runs.ts), so a cut never leaves the head of a key no redaction recognizes. */
356
342
  export function previewOf(text) {
@@ -69,7 +69,7 @@ declare class ToolKeysOverStore {
69
69
  at: string;
70
70
  } | null;
71
71
  unlocks: string[];
72
- harnesses: ("opencode" | "codex" | "claude-agent" | "pi")[];
72
+ harnesses: string[];
73
73
  id: string;
74
74
  kind: "model" | "tool";
75
75
  label: string;
@@ -50,7 +50,8 @@ export declare const TOOL_KEYS: readonly [{
50
50
  export declare const TOOL_FIELDS: readonly string[];
51
51
  /** What `candidates` unlock here, as capabilities show it: the tools of `tools` (capabilities' `tools`, available or
52
52
  * not) and the providers of `providers` (its `workflows.decisions.providers`) named among them, and the harnesses
53
- * that run those tools. A name neither holds is left out; a key that unlocks none of its names lists nothing. */
53
+ * that run those tools: the built-in ones first, then any other the tools run on (Goose once its owner installs it). A
54
+ * name neither holds is left out; a key that unlocks none of its names lists nothing. */
54
55
  export declare function unlockedBy(candidates: readonly string[], tools: readonly {
55
56
  name: string;
56
57
  harnesses: readonly string[];
@@ -58,14 +59,15 @@ export declare function unlockedBy(candidates: readonly string[], tools: readonl
58
59
  id: string;
59
60
  }[]): {
60
61
  unlocks: string[];
61
- harnesses: ("opencode" | "codex" | "claude-agent" | "pi")[];
62
+ harnesses: string[];
62
63
  };
63
64
  /** What a row unlocks here: a `tool` row's, its tools and providers as capabilities bind them (unlockedBy); any other
64
65
  * kind's (a model's), no tool, on those that run on it (its `harnesses`, when it names them) that this server runs
65
66
  * (`offers`, harness.ts' harnessOffers) on the row's key: one whose `keys` (the model keys that run it here, available
66
67
  * now or once one is saved) include the row's (its first field). So OpenRouter's row names all three before any key
67
68
  * is saved, and no row changes when another provider's key is saved; a harness not installed, off its pins or too big
68
- * for this host is left out. */
69
+ * for this host is left out. A harness the server lists beyond the built-in ones (Goose once its owner installs it: it
70
+ * has no offer before) is named, after them, where its own offer's `keys` name the row's. */
69
71
  export declare function rowUnlocks(row: {
70
72
  kind: string;
71
73
  unlocks: readonly string[];
@@ -77,7 +79,7 @@ export declare function rowUnlocks(row: {
77
79
  keys?: readonly string[];
78
80
  }[]): {
79
81
  unlocks: string[];
80
- harnesses: ("opencode" | "codex" | "claude-agent" | "pi")[];
82
+ harnesses: string[];
81
83
  };
82
84
  /** Whether a key row's `unlock` unlocks the tool `name`: by its name, or `<source>:*` for every tool of a catalog source
83
85
  * (`monid:*`: `monid:apollo/people/match`, `monid:apollo/*`). */
package/dist/tool-keys.js CHANGED
@@ -29,21 +29,25 @@ export const TOOL_KEYS = [
29
29
  export const TOOL_FIELDS = TOOL_KEYS.filter((row) => row.kind === "tool").flatMap((row) => row.fields);
30
30
  /** What `candidates` unlock here, as capabilities show it: the tools of `tools` (capabilities' `tools`, available or
31
31
  * not) and the providers of `providers` (its `workflows.decisions.providers`) named among them, and the harnesses
32
- * that run those tools. A name neither holds is left out; a key that unlocks none of its names lists nothing. */
32
+ * that run those tools: the built-in ones first, then any other the tools run on (Goose once its owner installs it). A
33
+ * name neither holds is left out; a key that unlocks none of its names lists nothing. */
33
34
  export function unlockedBy(candidates, tools, providers) {
34
35
  const bound = new Set([...tools.map((tool) => tool.name), ...providers.map((provider) => `decisions.${provider.id}`)]);
35
36
  // A catalog source's tools (`monid:*`) are granted by name, never listed: the source is shown as it is, and its tools are
36
- // host tools, run on every harness.
37
+ // host tools, run on every harness: the built-in ones and any other a tool here runs on.
37
38
  const unlocks = candidates.filter((name) => bound.has(name) || name.endsWith(":*"));
38
- const run = new Set(tools.filter((tool) => unlocks.includes(tool.name)).flatMap((tool) => tool.harnesses));
39
- return { unlocks, harnesses: HARNESSES.filter((harness) => run.has(harness) || unlocks.some((name) => name.endsWith(":*"))) };
39
+ const every = unlocks.some((name) => name.endsWith(":*"));
40
+ const run = new Set(tools.filter((tool) => every || unlocks.includes(tool.name)).flatMap((tool) => tool.harnesses));
41
+ const listed = [...run].filter((harness) => !HARNESSES.includes(harness));
42
+ return { unlocks, harnesses: [...HARNESSES.filter((harness) => every || run.has(harness)), ...listed] };
40
43
  }
41
44
  /** What a row unlocks here: a `tool` row's, its tools and providers as capabilities bind them (unlockedBy); any other
42
45
  * kind's (a model's), no tool, on those that run on it (its `harnesses`, when it names them) that this server runs
43
46
  * (`offers`, harness.ts' harnessOffers) on the row's key: one whose `keys` (the model keys that run it here, available
44
47
  * now or once one is saved) include the row's (its first field). So OpenRouter's row names all three before any key
45
48
  * is saved, and no row changes when another provider's key is saved; a harness not installed, off its pins or too big
46
- * for this host is left out. */
49
+ * for this host is left out. A harness the server lists beyond the built-in ones (Goose once its owner installs it: it
50
+ * has no offer before) is named, after them, where its own offer's `keys` name the row's. */
47
51
  export function rowUnlocks(row, tools, providers, offers) {
48
52
  if (row.kind === "tool")
49
53
  return unlockedBy(row.unlocks, tools, providers);
@@ -51,7 +55,9 @@ export function rowUnlocks(row, tools, providers, offers) {
51
55
  // Where an offer knows which model keys run it (its `keys`), the row's key must be one of them, available now or not;
52
56
  // else (no key runs it: pi on any, or one unavailable for another reason) whether it runs here now.
53
57
  const runs = (harness) => offers.some((offer) => offer.id === harness && (offer.keys ? key !== undefined && offer.keys.includes(key) : offer.available));
54
- return { unlocks: [], harnesses: HARNESSES.filter((harness) => (row.harnesses ?? HARNESSES).includes(harness) && runs(harness)) };
58
+ const builtin = HARNESSES.filter((harness) => (row.harnesses ?? HARNESSES).includes(harness) && runs(harness));
59
+ const listed = offers.filter((offer) => !HARNESSES.includes(offer.id) && key !== undefined && offer.keys?.includes(key)).map((offer) => offer.id);
60
+ return { unlocks: [], harnesses: [...builtin, ...listed] };
55
61
  }
56
62
  /** Whether a key row's `unlock` unlocks the tool `name`: by its name, or `<source>:*` for every tool of a catalog source
57
63
  * (`monid:*`: `monid:apollo/people/match`, `monid:apollo/*`). */
package/dist/tools.d.ts CHANGED
@@ -261,7 +261,7 @@ export declare const savedOnRelease: (row: {
261
261
  /** On the runner, the per-session hook that verifies the run's saved sign-in: a session that saved to it (savedOnRelease,
262
262
  * in a run handed it to save) verifies it under the run's claim, at the session's own end (its time, else now), as the
263
263
  * saved mark main reads at the lease's end. Answers whether it verified (sign-ins-store.ts verifyRunSignIn). */
264
- export declare const runSignInSaved: (store: Pick<Store, "runs" | "signIns">, sealKey: Buffer, claim: Claim, kept: RunSignIn) => (row: {
264
+ export declare const runSignInSaved: (store: Pick<Store, "runs" | "signIns">, sealKey: Buffer | undefined, claim: Claim, kept: RunSignIn) => (row: {
265
265
  session: {
266
266
  resourceId: string | null;
267
267
  releaseReason: string | null;
@@ -279,7 +279,7 @@ export declare const allows: (allowed: readonly string[], name: string) => boole
279
279
  * agent's `granted` tools a workflow's call node runs here (CALL_TOOLS, and each MCP tool granted by its own name,
280
280
  * tool-names.ts mcpNameOf), and with the run's `plane`, none it resolves unavailable (its agent's own tool of the name
281
281
  * does not run either). A
282
- * learned model node runs without tools (learn/skills.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
282
+ * learned model node runs without tools (learn/workflow-draft.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
283
283
  * exec_command, apply_patch) is never one, so the DSL refuses a draft that names it. */
284
284
  export declare const learnedWorkflowTools: (granted: readonly string[], plane?: Plane, options?: LearnedMcp) => string[];
285
285
  /** `mcp: true` at learn time (the end-of-run step's draft tools, a person's write): an MCP tool the revision grants by its
package/dist/tools.js CHANGED
@@ -47,6 +47,7 @@ import { HANDOVER_WAITING } from "./runner/journal-kinds.js";
47
47
  import { provenFor } from "./live-reach.js";
48
48
  import { clearWaitEnded, markWaitEnded } from "./browser-wait-ended.js";
49
49
  import { runSignIn, verifyRunSignIn } from "./sign-ins-store.js";
50
+ import { held } from "./runner/held.js";
50
51
  export const ASK_TOOL = "ask_person";
51
52
  /** Under `--faux` only: a module whose default export gives the browser's `{ computer, driver }` for the run's
52
53
  * environment, the vendor its plane names and the saved sign-in it was handed for that vendor (`{ provider, ref, save }`,
@@ -262,7 +263,11 @@ export const runSignInSaved = (store, sealKey, claim, kept) => async (row, chang
262
263
  if (!kept.save || !savedOnRelease(row, change))
263
264
  return false;
264
265
  const ended = row.session.endedAt ? Date.parse(row.session.endedAt) : Number.NaN;
265
- return verifyRunSignIn(store, sealKey, claim, kept, Number.isFinite(ended) ? ended : Date.now());
266
+ const at = Number.isFinite(ended) ? ended : Date.now();
267
+ // A run's own process holds no seal key: its runner marks it under the claim (held.ts verifySignIn).
268
+ if (!sealKey)
269
+ return (await held()?.verifySignIn(kept, at)) ?? false;
270
+ return verifyRunSignIn(store, sealKey, claim, kept, at);
266
271
  };
267
272
  /** A browser on pi-browser's durable adapter, its sessions a browser computer provider's of the computer registry
268
273
  * (browser-computer.ts), each driven over its CDP URL by pi-browser's raw-CDP driver: the agent's computer, where it is
@@ -309,7 +314,9 @@ const browserTool = {
309
314
  // launch makes it: never the process's environment, so one run's keys never make another's.
310
315
  const runLog = (line) => void process.stderr.write(`agentrun-serve: run ${host.where.ref.id}: ${line}\n`);
311
316
  const vendorFetch = async () => (host.env[FAUX_ENV] ? fauxFetch(host.env, FAUX_VENDOR_API_ENV) : fetch);
312
- const handed = computer ? undefined : host.claim ? (planeRefused || !host.store || !host.sealKey ? undefined : await runSignIn(host.store, host.sealKey, host.claim, vendor, { vendors: vendorsOver(() => host.env, vendorFetch), log: runLog })) : handedSignIn();
317
+ // A run's own process holds no seal key: its runner opens the run's sign-in under the claim (held.ts runSignIn).
318
+ const atRunner = held();
319
+ const handed = computer ? undefined : host.claim ? (planeRefused || !host.store ? undefined : host.sealKey ? await runSignIn(host.store, host.sealKey, host.claim, vendor, { vendors: vendorsOver(() => host.env, vendorFetch), log: runLog }) : await atRunner?.runSignIn(vendor)) : handedSignIn();
313
320
  const kept = !planeRefused && handed?.provider === vendor ? handed : undefined;
314
321
  // Tests only (--faux): the faux browser's computer provider and driver stand in for the plane vendor's and the raw-CDP
315
322
  // driver. The agent's browser computer is still the claim's, so a test hands the claim a faux provider of its own.
@@ -445,7 +452,7 @@ const browserTool = {
445
452
  const files = { files: uploadsFrom(work, MAX_UPLOAD_BYTES, uploadMime), ...(folder !== undefined && keepsDownloads ? { workspace: () => folder } : {}) };
446
453
  // A session that saved to the sign-in, let go: its time, for the sign-in's verified_at when the run's lease ends.
447
454
  // On the runner, the store's verified_at under the run's claim (runSignInSaved), never a mark in the run's directory.
448
- const verify = kept?.save && host.claim && host.store && host.sealKey ? runSignInSaved(host.store, host.sealKey, host.claim, kept) : undefined;
455
+ const verify = kept?.save && host.claim && host.store && (host.sealKey || held()) ? runSignInSaved(host.store, host.sealKey, host.claim, kept) : undefined;
449
456
  // Awaited by the session's change, so the release that lets a run's sessions go (beforeRelease) returns only once its
450
457
  // last save is verified: the run's end commit, which ends the claim, never fences it.
451
458
  const saved = verify
@@ -649,7 +656,7 @@ export const allows = (allowed, name) => allowed.includes(name);
649
656
  * agent's `granted` tools a workflow's call node runs here (CALL_TOOLS, and each MCP tool granted by its own name,
650
657
  * tool-names.ts mcpNameOf), and with the run's `plane`, none it resolves unavailable (its agent's own tool of the name
651
658
  * does not run either). A
652
- * learned model node runs without tools (learn/skills.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
659
+ * learned model node runs without tools (learn/workflow-draft.ts MODEL_NODE_TOOLS), and a harness's own tool (Bash,
653
660
  * exec_command, apply_patch) is never one, so the DSL refuses a draft that names it. */
654
661
  export const learnedWorkflowTools = (granted, plane, options = {}) => [...new Set(granted.filter((name) => (options.mcp === true && mcpNameOf(name) !== undefined) || (allows(CALL_TOOLS, name) && !isUnavailable(plane?.[name]))))];
655
662
  /** The tools a learned draft may name (learnedWorkflowTools) that the gate allows: `permission` is what the gate holds a
@@ -50,8 +50,15 @@ export type TriggerUpstream = {
50
50
  patched(was: Source, given: Source): Source;
51
51
  /** The trigger `id` of `source`, turned on or off here: the same there. */
52
52
  turned(source: Source, id: string, on: boolean): Promise<Json | undefined>;
53
- /** The trigger `id` of `source`, deleted here: removed there. */
53
+ /** The trigger `id` of `source`, deleted here: removed there, with what it keeps here for it (a sealed config). */
54
54
  removed(source: Source, id: string): Promise<Json | undefined>;
55
+ /** The trigger `id` of `source`, still here: removed there, then `here` (its delete here) in the same step, so no other
56
+ * trigger's removal there reads it as still holding what they share; what it keeps here for it is left (`forgotten`
57
+ * drops that once the trigger is gone). Undefined when it is gone there and `here` is done; what could not be done
58
+ * there, said, with `here` not run. A refusal of `here`'s is thrown. */
59
+ removedThere(source: Source, id: string, here: () => Promise<void>): Promise<Json | undefined>;
60
+ /** What it keeps here for the trigger `id` of `source` (a sealed config), dropped once the trigger is gone here. */
61
+ forgotten(source: Source, id: string): Promise<void>;
55
62
  };
56
63
  /** `max_cost_usd`: each run's cap; absent, the agent's default as it stands when the firing starts (one of the two is
57
64
  * required: server.ts targetIssues and start). */
@@ -68,10 +75,14 @@ export type Target = {
68
75
  };
69
76
  /** What the webhook did with a trigger.failed message (webhooks.ts emitTrigger). */
70
77
  type Told = "queued" | "unsaved" | "off" | "closed";
71
- /** What a trigger.failed webhook message says (webhooks.ts). */
78
+ /** What a trigger.failed webhook message says (webhooks.ts). `agent_id`: the agent the trigger runs as (its row's: a
79
+ * start_run's agent, or the agent of the run a message_run names), so every trigger has one; `agent_name`, that agent's
80
+ * name as the message is built, its id when it has none (an agent no longer in the store). */
72
81
  export type TriggerFailed = {
73
82
  trigger_id: string;
74
83
  name: string;
84
+ agent_id: string;
85
+ agent_name: string;
75
86
  firing_key: string;
76
87
  nominal_at: string;
77
88
  error: {
@@ -176,6 +187,11 @@ export declare class Triggers {
176
187
  /** Each trigger's firings, driven one after another in the order asked: a firing's overlap check reads what the one
177
188
  * before it settled to. */
178
189
  private readonly turns;
190
+ /** Each trigger's removals and the edits that name a target (the one way it moves to another agent), one after another
191
+ * on this server: a move never lands between a template update's delete of its Composio instance and its conditional
192
+ * delete of the row (remove), so a moved trigger never stands on an instance that delete took. Across servers the
193
+ * store's conditional write holds the row. Removed from the map once idle. */
194
+ private readonly edits;
179
195
  /** Whether a firing waits for its trigger's room (max_active_runs): the timer then reads the store every WAIT_POLL_MS. */
180
196
  private waiting;
181
197
  /** The triggers whose day-kept keys are at their cap, said once until they are under it again. */
@@ -295,7 +311,7 @@ export declare class Triggers {
295
311
  } | null;
296
312
  }[];
297
313
  }>;
298
- create(body: Json): Promise<{
314
+ create(body: Json, own?: TriggerOwn): Promise<{
299
315
  secret?: string;
300
316
  id: string;
301
317
  name: string;
@@ -378,6 +394,9 @@ export declare class Triggers {
378
394
  }[]>;
379
395
  /** Refused (409 agent_archived) when agent `agentId` is archived: a trigger made on, turned on or aimed at it. */
380
396
  private needAgentOn;
397
+ /** Refused (409 agent_not_runnable, agents.ts agentDeleting) when agent `agentId` is being deleted: another system's
398
+ * agent with an archive time, which only its delete writes (agent-delete.ts). */
399
+ private needNotDeleting;
381
400
  /** The store's refusal of a trigger left on for an archived agent (an archive that committed past needAgentOn) as the
382
401
  * same 409; undefined for any other error. */
383
402
  private archivedRefusal;
@@ -402,7 +421,7 @@ export declare class Triggers {
402
421
  /** PATCH: any of name, enabled, source, target, catchup_window_s and max_active_runs. Enabled again, or its source changed, a trigger goes on from now: a
403
422
  * paused range is skipped, never caught up. Only the fields named change, applied to the trigger as it stands once
404
423
  * the target's check is done: an edit made meanwhile keeps its own. */
405
- update(id: string, body: Json): Promise<{
424
+ update(id: string, body: Json, own?: TriggerOwn): Promise<{
406
425
  id: string;
407
426
  name: string;
408
427
  enabled: boolean;
@@ -440,11 +459,37 @@ export declare class Triggers {
440
459
  } | null | undefined;
441
460
  hook_url?: string | undefined;
442
461
  }>;
462
+ private updating;
443
463
  /** One try of `update`: undefined when its source write was refused because the trigger changed since it was read and
444
464
  * `retry` (try again); refused on the last try, precondition_failed. */
445
465
  private updateOnce;
446
- /** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds). */
447
- remove(id: string): Promise<Json | undefined>;
466
+ /** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds).
467
+ * On its agent's condition (`onAgent`: a template update's removal), what its sender keeps goes first: one its sender
468
+ * did not remove is said, and the trigger is kept here as it was (its row, its package mark, its sealed config and
469
+ * whether it is on), for the next update to remove; once it is gone there, the trigger goes here while it is still that
470
+ * agent's, then what its sender kept here for it. */
471
+ remove(id: string, own?: Pick<TriggerOwn, "onAgent">): Promise<Json | undefined>;
472
+ private removing;
473
+ /** `value` as a create keeps a source (its adapter's defaults filled in: a feed's every_s), or undefined when a create
474
+ * would refuse it. */
475
+ sourceAsKept(value: unknown): Source | undefined;
476
+ /** A deleted agent's trigger (agent-delete.ts), its first half: what its sender keeps of it removed there, the trigger
477
+ * kept here, so a failure, or a stop before the second half (removeHere), leaves the row that names what is left to
478
+ * remove for the next delete to find. Throws `unavailable` with what could not be done there. */
479
+ removeThere(id: string): Promise<void>;
480
+ /** The second half's first part, once removeThere is done: the trigger's adapter settings removed, its row kept. */
481
+ removeSettings(id: string): Promise<void>;
482
+ /** The second half, once removeThere is done: the trigger deleted here, its adapter settings and then its row. */
483
+ removeHere(id: string): Promise<void>;
484
+ /** A trigger's adapter settings (a webhook's secret, a poll's cursor) removed; nothing else of it. */
485
+ private dropSettings;
486
+ /** The trigger's settings and row removed. Without `onAgent`, its settings first, then its row: the settings have no
487
+ * link to the row, so a failure or a stop between the two leaves the row, which the next remove finds, never settings
488
+ * with no trigger left to name them. With `onAgent` (a template update's removal), the row first, on its agent's
489
+ * condition compared in the delete, then its settings: a trigger moved to another agent meanwhile keeps both. A stop
490
+ * between the two there leaves settings no row names (keyed by an id never used again), never a moved trigger
491
+ * without its own. */
492
+ private dropHere;
448
493
  /** Run now: one firing per Idempotency-Key, driven before the answer. `created` false: the key's firing, as it stands. */
449
494
  fire(id: string, idempotencyKey: string): Promise<{
450
495
  created: boolean;
@@ -454,6 +499,12 @@ export declare class Triggers {
454
499
  * then each failure's trigger.failed queued that is not yet, each due firing whose time has come driven, each waiting
455
500
  * firing whose trigger has room again driven (one read for all of them), and the timer armed again. */
456
501
  private tick;
502
+ /** `work` on trigger `id` once every edit or removal of it asked before has settled (edits). Neither update nor remove
503
+ * calls the other, so a turn never waits on itself. Only a target edit takes a turn: any other edit runs beside one, as
504
+ * concurrent edits each keep their change (trigger-engine.test.mjs, two edits at once, one a target whose check is
505
+ * slow: the source edit lands while the target's check waits). One racing a removal writes its row while the row is
506
+ * there, or finds it gone (not_found): the store's update changes no row a delete took. */
507
+ private one;
457
508
  /** `key`'s firing driven after every firing of its trigger asked before it. */
458
509
  private inTurn;
459
510
  /** Each of `triggers` turned off, with why its source no longer reads, and said. */
@@ -571,6 +622,14 @@ export declare class Triggers {
571
622
  * source says of it), then a line saying what fired it and when, in the trigger's zone. */
572
623
  private inputOf;
573
624
  }
625
+ /** What a template apply alone gives a trigger write, never an API body: `templateId`, the package mark it makes the
626
+ * trigger with or sets on one it keeps in place (TriggerRow.templateId); `onAgent`, the agent it read the trigger on, so
627
+ * the write (an update, a removal) is made only while the trigger is still that agent's, compared in the store's
628
+ * statement: one moved to another agent meanwhile is not_found, and nothing is written. */
629
+ export interface TriggerOwn {
630
+ readonly templateId?: string;
631
+ readonly onAgent?: string;
632
+ }
574
633
  declare function firingView(firing: FiringRow): {
575
634
  attempts?: number | undefined;
576
635
  retry_at?: string | undefined;