@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
@@ -1,99 +0,0 @@
1
- // The runner's dispatch for a launch of harness "learning" (learning-factory.ts LEARNING_HARNESS): the learning loop, its
2
- // grade asked through the runner's one model route. Per learning run, from its launch: the grade model (`model`, the
3
- // server's gradeModelOf, written when the run that learned ended), else the agent's own model, as main grades. The
4
- // grade is booked as the grade's (learning-ask.ts bookedAsk: the learning run's own records, the kernel's model proxy).
5
- // A run with a cap never goes past it by its grade: its learning run's launch carries what the cap left once the run's
6
- // own spend (its job, its follow-ups, each look-back) and its earlier rounds' grades are counted (max_cost_usd,
7
- // learning-end.ts gradeCapOf), and each grader call is judged against it before it leaves by the kernel's one rule
8
- // (beforeRequestOf, over the learning run's one booking) at its worst case: its input uncached and its whole output bound
9
- // (GRADE_MAX_TOKENS), never cut down to fit, so a verdict is never lost to a short answer. A call that doesn't fit is
10
- // never sent, and the grade is skipped, said so (learning-loop.ts GradeOverCap). An uncapped run's grade is capped by nothing. A
11
- // grader that never answers is cut at the grade's bound, and what it spent is unknown (null).
12
- import { beforeRequestOf } from "@parcha/agentrun-kernel/kernel/cap";
13
- import { FAUX_ENV } from "../model.js";
14
- import { anthropicModelId, openRouterOnly, providerFor } from "../provider.js";
15
- import { capModelOf } from "./adapter-run-spec.js";
16
- import { bookedAsk } from "./learning-ask.js";
17
- import { learningLoopFactory } from "./learning-factory.js";
18
- import { GRADE_TIMEOUT_MS } from "./learning-loop.js";
19
- /** The model a grade runs on, main's order: the grade model the server names, else the agent's own (the model its
20
- * revision names), else none (the host's default, which the route picks). */
21
- export const gradeModelFor = (grade) => grade.model ?? grade.own;
22
- const objectOf = (value) => (value !== null && typeof value === "object" ? value : {});
23
- /** The grade's route for `model` (the grade model the server names; undefined, the agent's own), from the runner's one
24
- * route (`routeOf`), but where this host reaches the model's vendor only through OpenRouter (provider.ts
25
- * openRouterOnly: its one key for that wire is OpenRouter's, no gateway), as main's grade reaches it there:
26
- * - an Anthropic model, at OpenRouter's Messages endpoint as a claude-agent run's requests go (providerFor: Anthropic's
27
- * own id on the wire, OpenRouter's key as a bearer token, its one credential), priced at OpenRouter's catalog price of
28
- * the model (its priceModel, through the runner's route);
29
- * - an OpenAI model, the same model on OpenRouter (`openrouter/openai/<id>`, the route's own translation).
30
- * A faux host (FAUX_ENV) and a gateway take the model as named: a faux grade never reaches a real provider, whatever
31
- * key the host inherited. Every other Anthropic model goes by Anthropic's own id (anthropicModelId: OpenRouter's
32
- * dotted name dashed), as its harness's model selection names it (provider.ts modelOn), so the catalog finds it. */
33
- export async function gradeRouteOf(model, env, routeOf) {
34
- const slash = model?.indexOf("/") ?? -1;
35
- if (model === undefined || slash < 1 || env.AGENT_MODEL_BASE_URL || env[FAUX_ENV])
36
- return routeOf(model);
37
- const [vendor, id] = [model.slice(0, slash), model.slice(slash + 1)];
38
- if (vendor === "anthropic" && openRouterOnly("anthropic-messages", env)) {
39
- const sent = providerFor("anthropic-messages", env, { provider: "anthropic", modelId: id }, "the grader");
40
- const priced = await routeOf(`${sent.priceModel.provider}/${sent.priceModel.modelId}`);
41
- // Priced as OpenRouter lists it, for the booking and for the cap's judgement before it leaves alike.
42
- const capped = { ...(priced.cost ? { cost: priced.cost } : {}), ...(priced.unpriced ? { unpriced: true } : {}), ...(priced.outputCeiling !== undefined ? { outputCeiling: priced.outputCeiling } : {}) };
43
- return { model: sent.modelId, provider: { api: "anthropic-messages", origin: sent.origin, credential: sent.credential, auth: sent.auth }, ...(priced.like ? { like: priced.like } : {}), ...(priced.price ? { price: priced.price } : {}), ...capped };
44
- }
45
- if (vendor === "openai" && openRouterOnly("openai-responses", env))
46
- return routeOf(`openrouter/openai/${id}`);
47
- if (vendor === "anthropic")
48
- return routeOf(`anthropic/${anthropicModelId({ provider: "anthropic", modelId: id })}`);
49
- return routeOf(model);
50
- }
51
- /** The learning run's grade route: its launch's grade model, the model the revision of the run that learned names (its
52
- * `model`, as main's grade reads agent.model), and that run's agent; and the cap its launch carries (`capUsd`: what the
53
- * run's cap left for the grade; none for an uncapped run). A cap that is not a figure of 0 or more is no room ($0). */
54
- async function gradeOf(store, learningRunId) {
55
- const body = objectOf((await store.runs.launch(learningRunId)).body);
56
- const sourceId = objectOf(body.input).runId;
57
- const source = typeof sourceId === "string" ? await store.runs.get(sourceId) : undefined;
58
- if (!source)
59
- throw new Error(`the learning run ${learningRunId} names no run it learns from`);
60
- const own = objectOf((await store.agents.revision(source.revisionId))?.body).model;
61
- const route = { ...(typeof body.model === "string" && body.model !== "" ? { model: body.model } : {}), ...(typeof own === "string" && own !== "" ? { own } : {}), agentId: source.agentId };
62
- if (!("max_cost_usd" in body))
63
- return { route };
64
- const cap = body.max_cost_usd;
65
- return { route, capUsd: typeof cap === "number" && Number.isFinite(cap) && cap > 0 ? cap : 0 };
66
- }
67
- /** The learning run's cap on its grade (`capUsd`), the kernel's one rule over its booking (bookedAsk's runBooking): each
68
- * grader call on `route` judged at its worst case before it leaves, every input token uncached and its whole
69
- * output bound as the least it may be sent with, so a grade never runs on a cut answer. Another model than the route's is
70
- * priced by nothing here: refused. */
71
- export function gradeCap(capUsd, route) {
72
- const model = capModelOf(route);
73
- const judge = beforeRequestOf({ capUsd: () => capUsd, modelOf: (id) => (id === route.model ? model : undefined) });
74
- return (request) => judge({ ...request, ...(request.outputTokensAsked !== undefined ? { outputTokensLeast: request.outputTokensAsked } : {}) });
75
- }
76
- /** The loop for a launch of harness "learning": the runner's dispatch calls it for each such run it claims. */
77
- export function learningLoopOf(deps) {
78
- return (loopDeps) => {
79
- let claimed;
80
- const ask = async (request, signal, run) => {
81
- if (claimed === undefined)
82
- throw new Error("the learning run's grade was asked before its claim");
83
- const grade = await gradeOf(deps.store, claimed);
84
- const route = await deps.routeOf(grade.route);
85
- // The loop's own signal (a stop, a lost claim, its bound) and the grade's bound, both: whichever ends first cuts it.
86
- const bound = deps.gradeBound ? deps.gradeBound() : AbortSignal.timeout(GRADE_TIMEOUT_MS);
87
- return bookedAsk({ ...route, ...(grade.capUsd !== undefined ? { beforeRequest: gradeCap(grade.capUsd, route) } : {}) })(request, AbortSignal.any([signal, bound]), run);
88
- };
89
- const loop = learningLoopFactory({ store: deps.store, data: deps.data, ask, ...(deps.sourceInstructions ? { sourceInstructions: deps.sourceInstructions } : {}), ...(deps.log ? { log: deps.log } : {}), ...(deps.now ? { now: deps.now } : {}) })(loopDeps);
90
- return {
91
- start: (claim) => {
92
- claimed = claim.runId;
93
- return loop.start(claim);
94
- },
95
- command: (command) => loop.command(command),
96
- stop: (reason) => loop.stop(reason),
97
- };
98
- };
99
- }
@@ -1,16 +0,0 @@
1
- import type { Store } from "../store/store.js";
2
- import { type LearningLoopDeps } from "./learning-loop.js";
3
- import type { LoopFactory } from "./loop-contract.js";
4
- /** The harness a learning run's launch names (store/sqlite/run-patch.ts learningLaunchOf). */
5
- export declare const LEARNING_HARNESS = "learning";
6
- export interface LearningFactoryDeps extends Pick<LearningLoopDeps, "ask" | "now"> {
7
- readonly store: Pick<Store, "runs" | "agents" | "learning">;
8
- /** The server's data directory: where each agent's learning folder is. */
9
- readonly data: string;
10
- /** Optional immutable source-run policy snapshot (native jobs). This is quoted as task policy data by gradePrompt,
11
- * never installed as the grader's own native instructions. */
12
- readonly sourceInstructions?: (runId: string) => Promise<string>;
13
- /** Where the folder's script says what it did (learningWorkspace's log). */
14
- readonly log?: (line: string) => void;
15
- }
16
- export declare function learningLoopFactory(deps: LearningFactoryDeps): LoopFactory;
@@ -1,50 +0,0 @@
1
- // The loop factory for a launch of harness "learning" (the runner's main factory picks it by the launch row's harness):
2
- // the learning loop (learning-loop.ts) with its source read from the store, the run's launch row naming the run that
3
- // learned, and that run's agent and its revision's instructions. It grades through the call it is given, and reads and
4
- // writes the agent's learning folder through the folder's own API:
5
- // ask the grader's one call, through the kernel's model proxy and the cap, booked to the agent's learning meter
6
- // (passed in by the runner's wiring);
7
- // folder the agent's learning folder in the server's data (learn/folder.ts learningWorkspace), ended after each run;
8
- // readMain main as the grader reads it, from the folder's snapshot (learn/commit.ts readMain);
9
- // commit the folder's one write (learn/commit.ts learningCommit);
10
- // merged the run's merge when it is on main already, with the texts its own commit holds (learn/commit.ts mergedAt),
11
- // for a resume after its commit.
12
- import { learningCommit, mainTexts, mergedAt, readMain } from "../learn/commit.js";
13
- import { learningWorkspace } from "../learn/folder.js";
14
- import { createLearningLoop } from "./learning-loop.js";
15
- /** The harness a learning run's launch names (store/sqlite/run-patch.ts learningLaunchOf). */
16
- export const LEARNING_HARNESS = "learning";
17
- const objectOf = (value) => (value !== null && typeof value === "object" ? value : {});
18
- export function learningLoopFactory(deps) {
19
- const { store } = deps;
20
- return createLearningLoop({
21
- sourceOf: async (learningRunId) => {
22
- const launch = await store.runs.launch(learningRunId);
23
- const input = objectOf(objectOf(launch.body).input);
24
- const runId = input.runId;
25
- if (typeof runId !== "string")
26
- return undefined;
27
- const source = await store.runs.get(runId);
28
- if (!source)
29
- return undefined;
30
- const round = Number.isSafeInteger(input.round) && input.round > 1 ? { round: input.round } : {};
31
- let instructions;
32
- try {
33
- instructions = deps.sourceInstructions ? await deps.sourceInstructions(runId) : objectOf((await store.agents.revision(source.revisionId))?.body).instructions;
34
- }
35
- catch (error) {
36
- return { runId, ...round, agentId: source.agentId, policyError: error instanceof Error ? error.message : String(error) };
37
- }
38
- return { runId, ...round, agentId: source.agentId, ...(typeof instructions === "string" ? { instructions } : {}), ...(deps.sourceInstructions ? { nativeInstructions: true } : {}) };
39
- },
40
- proposal: (runId, round) => store.learning.proposal(runId, round),
41
- ask: deps.ask,
42
- folder: (agentId) => learningWorkspace({ mode: "local", agentId, data: deps.data, ...(deps.log ? { log: deps.log } : {}) }),
43
- readMain: async (ws, proposal) => (await readMain(ws, { notes: proposal.notes })),
44
- commit: async (ws, change) => (await learningCommit(ws, change)),
45
- mainTexts: (ws, paths) => mainTexts(ws, paths),
46
- merged: (ws, runId, paths, round) => mergedAt(ws, runId, paths, round),
47
- ...(deps.now ? { now: deps.now } : {}),
48
- ...(deps.log ? { log: deps.log } : {}),
49
- });
50
- }
@@ -1,273 +0,0 @@
1
- import type { LearningProposal } from "../store/store.js";
2
- import { type IndexEntry, type NoteText, type Verdict } from "../learn/grade.js";
3
- import type { LearnedFile, NoteLearned, Tokens } from "../learning.js";
4
- import type { Journal, Loop, LoopDeps } from "./loop-contract.js";
5
- /** The grader's bounds, as the server's grade had them (grade.ts): one ask, its answer cut at GRADE_MAX_TOKENS. */
6
- export declare const GRADE_TIMEOUT_MS = 180000;
7
- export declare const GRADE_MAX_TOKENS = 16000;
8
- /** A folder the merge could not reach (the workspace or its exec down): the run parks and is retried after this, doubling
9
- * per try up to the last. */
10
- export declare const UNAVAILABLE_BACKOFF_MS: readonly [30000, 120000, 600000, 1800000];
11
- /** What the source run proposed (learning.ts Proposal), as kept in its learning_proposals row. */
12
- export interface KeptProposal {
13
- readonly notes: readonly NoteText[];
14
- readonly files?: readonly NoteText[];
15
- /** Each kept draft's dry run, by its workflow.json's path (learn/skills.ts draftDryRun), which the grader is told. */
16
- readonly dryRuns?: Readonly<Record<string, {
17
- readonly status: string;
18
- readonly detail?: string;
19
- }>>;
20
- /** The skill of each draft's name as the folder held it at the seed, which the grader is shown beside the draft. */
21
- readonly drafted?: readonly NoteText[];
22
- readonly asked?: readonly string[];
23
- /** Why each draft waits for its owner's OK whatever the grade (the learning end's: skills.ts unpricedCalls). */
24
- readonly held?: Readonly<Record<string, readonly string[]>>;
25
- readonly triggered?: readonly {
26
- readonly source: string;
27
- readonly text: string;
28
- }[];
29
- /** The commit of the learning folder's main the run started from (its pin's seed). */
30
- readonly seed?: string;
31
- /** A file whose conflict base is not the seed, by its path (learning.ts Proposal): a revised workflow's, the commit of
32
- * main its compile ask read it at. */
33
- readonly bases?: Readonly<Record<string, string>>;
34
- /** The draft the run's compile turn wrote (learn/compile.ts), by its name, and the notes it does the work of: marked
35
- * `compiled_into` when the draft merges. */
36
- readonly compiled?: {
37
- readonly workflow: string;
38
- readonly from_notes: readonly string[];
39
- };
40
- }
41
- /** Main as the grader reads it: every active note's index line, the text of each note the proposal supersedes, and the
42
- * blob each of those was read at (a merge on a main where one moved is a conflict). */
43
- export interface GradeMain {
44
- readonly active: readonly IndexEntry[];
45
- readonly superseded: readonly NoteText[];
46
- readonly graded: Readonly<Record<string, string>>;
47
- /** The proposal's notes named like a note main holds, left out of the grade and settled alone (learn/commit.ts
48
- * readMain): `same` when main's note says its rule, else `taken`. */
49
- readonly taken?: readonly {
50
- readonly path: string;
51
- readonly reason: "same" | "taken";
52
- }[];
53
- }
54
- export type Problem = {
55
- readonly rule: string;
56
- readonly path?: string;
57
- readonly detail: string;
58
- };
59
- /** A grader call its learning run's cap refused before it was sent (learning-ask.ts bookedAsk: the run's cap left, its
60
- * launch's max_cost_usd): nothing of it was spent, and the grade is skipped, said so (said.noRoomToGrade), never run past
61
- * the cap, never a failure. `forGood`: no room could ever send it (its spend or price unknown), not only none now. */
62
- export declare class GradeOverCap extends Error {
63
- readonly forGood: boolean;
64
- readonly booked?: GradeBooked | undefined;
65
- /** `booked`: the grade's records when it was refused (GradeBooked), what it spent before it. */
66
- constructor(message: string, forGood: boolean, booked?: GradeBooked | undefined);
67
- }
68
- /** The grade's own records after an ask (learning-ask.ts bookedAsk: its session's booking): what every grade request of
69
- * the learning run spent, an earlier attempt's included (null: unknown, as a cut one's), and how many left. What the
70
- * grade ends with is read from these, never summed in memory alone: a runner that restarted before the grade was saved
71
- * holds no sum of what its earlier attempt spent. */
72
- export type GradeBooked = {
73
- readonly usd: number | null;
74
- readonly turns: number;
75
- };
76
- /** The folder's one write (learn/commit.ts learningCommit), a merge. */
77
- export interface MergeChange {
78
- readonly kind: "merge";
79
- readonly runId: string;
80
- /** The round of the run's looks back it merges, past the first (learn/folder.ts runDiffKey). */
81
- readonly round?: number;
82
- readonly reason: string;
83
- readonly files: readonly {
84
- readonly path: string;
85
- readonly text: string;
86
- }[];
87
- readonly held?: readonly string[];
88
- readonly graded: Readonly<Record<string, string>>;
89
- /** The run's seed: a skill's or a draft's file not on main as it was on it is a conflict, never written over. */
90
- readonly seed?: string;
91
- /** A file checked against another commit than the seed, by its path: a revised workflow's, the commit its compile ask
92
- * read it at. */
93
- readonly bases?: Readonly<Record<string, string>>;
94
- /** New notes written over main's note of the same name, each superseding it by name (takenOnMain). */
95
- readonly replace?: readonly string[];
96
- /** Each skill re-filed as a note, retired on main in the same write (its SKILL.md, and the note that replaces it). */
97
- readonly retire?: readonly {
98
- readonly skill: string;
99
- readonly note: string;
100
- }[];
101
- /** A compiled draft this merge writes, and the notes it marks `compiled_into` (learn/commit.ts). */
102
- readonly compiled?: {
103
- readonly workflow: string;
104
- readonly notes: readonly string[];
105
- };
106
- }
107
- export type LearningCommitResult = {
108
- readonly ok: true;
109
- readonly main: string;
110
- readonly commit: string;
111
- readonly files: readonly string[];
112
- readonly left?: readonly {
113
- readonly path: string;
114
- readonly reason: "same" | "taken";
115
- }[];
116
- readonly already?: true;
117
- } | {
118
- readonly ok: false;
119
- readonly reason: "conflict" | "refused";
120
- readonly problems: readonly Problem[];
121
- } | {
122
- readonly ok: false;
123
- readonly reason: "unavailable";
124
- readonly error: string;
125
- };
126
- /** What the grader's call is lent for one claim: a journal of the learning run under that claim, its own to open and
127
- * close (where its request is booked: runBooking over the run's sessions), and the flush that makes a request's record
128
- * durable before it leaves. */
129
- export interface GraderRun {
130
- journal(): Journal;
131
- flush(): Promise<void>;
132
- }
133
- export interface LearningLoopDeps {
134
- /** The run that learned, from the learning run's launch row (its input's runId), and the round of its looks back the
135
- * learning run grades (its input's round; absent, the first). */
136
- sourceOf(learningRunId: string): Promise<{
137
- readonly runId: string;
138
- readonly round?: number;
139
- readonly agentId: string;
140
- readonly instructions?: string;
141
- readonly policyError?: string;
142
- readonly nativeInstructions?: true;
143
- } | undefined>;
144
- /** Its kept proposal of that round (store.learning.proposal). */
145
- proposal(runId: string, round: number): Promise<LearningProposal | undefined>;
146
- /** The agent's learning folder (learn/folder.ts learningWorkspace): its Workspace, and its end, called once the run is
147
- * done with it, whichever way it goes out. */
148
- folder(agentId: string): {
149
- readonly workspace: unknown;
150
- end(): Promise<void>;
151
- };
152
- /** Main as the grader reads it, from the folder's snapshot; problems when the proposal can't be graded on it. */
153
- readMain(ws: unknown, proposal: KeptProposal): Promise<GradeMain | {
154
- readonly problems: readonly Problem[];
155
- }>;
156
- /** One grader call, through the kernel's model proxy and the cap, booked to the agent's learning meter. */
157
- ask(request: {
158
- readonly prompt: string;
159
- readonly maxTokens: number;
160
- }, signal: AbortSignal, run: GraderRun): Promise<{
161
- readonly text: unknown;
162
- readonly usd: number | null;
163
- readonly tokens?: Tokens | null;
164
- readonly booked?: GradeBooked;
165
- }>;
166
- /** The folder's one write. */
167
- commit(ws: unknown, change: MergeChange): Promise<LearningCommitResult>;
168
- /** The texts main holds at these note paths (learn/commit.ts mainTexts): a note the merge keeps whose name main
169
- * already holds is settled alone (takenOnMain). */
170
- mainTexts(ws: unknown, paths: readonly string[]): Promise<Readonly<Record<string, string>>>;
171
- /** Run `runId`'s merge, when it is on main already (learn/folder.ts readRunDiff: its diff file, named by the run as its
172
- * commit's Run-Id trailer names it; a resume after its commit, before its end was recorded): the texts its own commit
173
- * holds at these note paths, as that merge saved them, whatever main says of them since. Undefined when it is not. */
174
- merged(ws: unknown, runId: string, paths: readonly string[], round?: number): Promise<{
175
- readonly texts: Readonly<Record<string, string>>;
176
- } | undefined>;
177
- /** The clock (epoch ms), for a parked run's wake. */
178
- now?(): number;
179
- /** One line of the runner's log. */
180
- log?(line: string): void;
181
- }
182
- /** The journal's learning entries' data (journal-kinds.ts learningGraded, learningDropped, learningMerged), as the reader
183
- * of a run's learning end reads them (store-reads/learning.ts). What a grade spent: its dollars and tokens, each null when
184
- * any ask's are unknown. */
185
- export type GradedData = {
186
- readonly source: string;
187
- readonly verdict: Verdict;
188
- readonly usd: number | null;
189
- readonly tokens?: Tokens | null;
190
- readonly graded: Readonly<Record<string, string>>;
191
- };
192
- export type DroppedData = {
193
- readonly source: string;
194
- readonly reason: string;
195
- readonly detail: string;
196
- readonly problems?: readonly Problem[];
197
- readonly usd?: number | null;
198
- readonly tokens?: Tokens | null;
199
- };
200
- /** `verdict`: each item's final decision once the merge settled it (takenOnMain's and the commit's left-out notes dropped,
201
- * with their words), which the run's learning end reads in place of the grade's (store-reads/learning.ts). */
202
- export type MergedData = {
203
- readonly source: string;
204
- readonly main: string;
205
- readonly commit: string;
206
- readonly files: readonly string[];
207
- readonly detail: string;
208
- readonly verdict: Verdict;
209
- };
210
- /** The why of a note whose name main already holds with other text, which it does not supersede: never written over,
211
- * and the rest of what the run learned merges. */
212
- export declare const NOTE_NAME_TAKEN: (name: string) => string;
213
- /** The why of a skill re-filed as a note whose file this run's own kept note (or another re-filed skill) takes: the run's
214
- * own stands, and the skill is not written over it. */
215
- export declare const NOTE_NAME_IN_RUN: (name: string) => string;
216
- export declare function takenOnMain(proposal: Pick<KeptProposal, "notes">, verdict: Verdict, onMain: Readonly<Record<string, string>>): {
217
- verdict: Verdict;
218
- replace: string[];
219
- graded: Record<string, string>;
220
- };
221
- /** `verdict` with one item per file a kept note is written as, within the run: the files the run's own kept notes are,
222
- * then each re-filed skill's as it is kept; a re-filed skill whose note file one of those takes is left out, saying so
223
- * (NOTE_NAME_IN_RUN). The merge (takenOnMain) and its resume (resumedOf, from the saved grade) settle it the one way. */
224
- export declare function oneItemAFile(proposal: Pick<KeptProposal, "notes">, verdict: Verdict): Verdict;
225
- /** `proposal` with only what `verdict` keeps (a verdict per item): a note or file its item keeps or holds; a skill its
226
- * item re-filed (`note`: a standing rule for every reply) is kept as that note instead, never as a skill. */
227
- export declare function keptOf(proposal: KeptProposal, verdict: Verdict): KeptProposal;
228
- /** The merge of `merging` (what the verdict kept), the one rule learningCommit's merge is made by: each note with
229
- * the origin its item gives (`you` for the user's own words, else the run's) and held for its owner's OK when its item
230
- * is pending; a skill's SKILL.md or a draft's README.md held when its item is (a draft's workflow.json is held by its
231
- * README); and the seed the source run started from, so a skill's or draft's file changed on main since is a conflict
232
- * (a revised workflow's file: changed since the commit its compile ask read it at, `bases`). */
233
- export declare function mergeChangeOf(runId: string, merging: KeptProposal, verdict: Verdict, graded: Readonly<Record<string, string>>, round?: number): MergeChange;
234
- /** What a merge of `merging` learned, as the server's grade named it on the run (learning-run.ts grade): the notes it
235
- * added that runs read, with what each supersedes; the ones waiting for their owner's OK; its skills and workflow
236
- * drafts, each pending when it waits. The merge's words and the reader of a run's learning end (store-reads/learning.ts)
237
- * both name it so. */
238
- export declare function learnedOf(merging: KeptProposal, verdict: Verdict): {
239
- learned: NoteLearned[];
240
- pending: {
241
- file: string;
242
- name: string;
243
- }[];
244
- skills: LearnedFile[];
245
- workflows: LearnedFile[];
246
- };
247
- /** `merging` and `verdict` once the merge left out `left` (learn/commit.ts LeftNote): each note it left out is no longer
248
- * merged, and its item is dropped, unsaid when its rule is held already (SAME_NOTE), else saying its name is taken. */
249
- export declare function leftOf(merging: KeptProposal, verdict: Verdict, left: readonly {
250
- readonly path: string;
251
- readonly reason: "same" | "taken";
252
- }[]): {
253
- merging: KeptProposal;
254
- verdict: Verdict;
255
- };
256
- /** What a merge already on main settled (learn/commit.ts: its files, and `left`, the new notes it did not write): each
257
- * note the grade kept is kept when the merge wrote it, its path changed and main holding its rule there now (`onMain`,
258
- * the texts main holds at the kept notes' paths), else left out, saying why as takenOnMain said it (`taken`, its
259
- * verdict after main was read), or by main's text there (the same rule, or a name it holds with another), else as the
260
- * commit does. Skills and drafts as the grade kept them. */
261
- export declare function resumedOf(proposal: KeptProposal, graded: Verdict, taken: Verdict, result: {
262
- readonly files: readonly string[];
263
- readonly left?: readonly {
264
- readonly path: string;
265
- readonly reason: "same" | "taken";
266
- }[];
267
- }, onMain: Readonly<Record<string, string>>): {
268
- merging: KeptProposal;
269
- verdict: Verdict;
270
- };
271
- /** The skills and drafts a proposal names, by their item's file: what a merge the grader refused loses (notKept). */
272
- export declare const lostOf: (proposal: KeptProposal) => LearnedFile[];
273
- export declare function createLearningLoop(learning: LearningLoopDeps): (deps: LoopDeps) => Loop;