@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
@@ -8,7 +8,6 @@ export type LoopCompile = {
8
8
  round: number;
9
9
  at: string;
10
10
  workflow: string | null;
11
- from_notes: string[];
12
11
  attempts: {
13
12
  ok: boolean;
14
13
  errors: string[];
@@ -40,7 +40,7 @@ export async function agentLoopOverStore(store, agentId) {
40
40
  const own = named && kept16 ? promotionOf(promotions, named.workflow, kept16) : undefined;
41
41
  const unchecked = own?.decided === "hold" && own.check?.stopped && own.check.n === 0 ? [own.reason] : [];
42
42
  compiles.push({
43
- createdAt: kept.createdAt, run_id: run.id, round: kept.round, at: new Date(kept.createdAt).toISOString(), workflow: named ? named.workflow : null, from_notes: texts(named?.from_notes), attempts,
43
+ createdAt: kept.createdAt, run_id: run.id, round: kept.round, at: new Date(kept.createdAt).toISOString(), workflow: named ? named.workflow : null, attempts,
44
44
  digest: kept16, promoted: named && kept16 ? (promotedOf(promotions, named.workflow, kept16) ?? null) : null, draft_errors: [...errors, ...unchecked],
45
45
  });
46
46
  }
@@ -2,7 +2,7 @@ import { type TimelineEvent } from "./timeline/index.js";
2
2
  import { type ItemStatus } from "./learning.js";
3
3
  import { type RunMoment, type SignInReader, type Status } from "./run-view.js";
4
4
  import { type RunReadState } from "./store-reads/runs.js";
5
- import { type Store } from "./store/store.js";
5
+ import { type RunListing, type Store } from "./store/store.js";
6
6
  import type { RecordingView } from "./run-recordings.js";
7
7
  /** What the store-backed view needs beside the store: where its console lives, every secret it never shows (read now, so
8
8
  * one rotated is cut at once), and the agents' saved sign-ins (for the handed-pointer cut). The server passes the same it
@@ -29,6 +29,10 @@ export interface ViewDeps {
29
29
  /** A settled run's v2 status from its row alone (STATUS_OF), the status its view reads (statusOf returns the outcome
30
30
  * first); undefined for a run still going, whose status only its journal says. */
31
31
  export declare const settledStatusOf: (state: RunReadState) => Status | undefined;
32
+ /** How long a run's listing waits before it is built again when its build could not read what it needed (ms): a listing
33
+ * that withheld the run for a sign-in it could not read back (listingOverStore), and the lister's build that failed
34
+ * (run-listing.ts). */
35
+ export declare const LISTING_RETRY_MS = 30000;
32
36
  /** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's, and
33
37
  * never an earlier turn's: a final answer row before the person's last message belongs to the turn that message
34
38
  * followed, so a follow-up whose own stop said nothing (no text block: a thinking-only stop) has no answer, null, not
@@ -39,6 +43,30 @@ export declare const answerOf: (timeline: readonly TimelineEvent[]) => string |
39
43
  export declare function viewOverStore(store: Store, runId: string, deps: ViewDeps): Promise<Record<string, unknown> | undefined>;
40
44
  /** The run list's answer from the store, byte-identical to runs.ts's summary: the view's subset a list shows. */
41
45
  export declare function summaryOverStore(store: Store, runId: string, deps: ViewDeps): Promise<Record<string, unknown> | undefined>;
46
+ /** What a list shows of a run's view (summaryOverStore). */
47
+ export declare function summaryOfView(view: Record<string, unknown>): Record<string, unknown>;
48
+ /** A runs list's item for a run, as its listing keeps it on the run's row (store/schema.ts RUN_LISTING_COLUMNS), built from
49
+ * the run's view once per change and read by every list after: its list item (summaryOverStore's) with the parts a list
50
+ * fills in when it reads it (console_url: the origin the request reached; archived_at: the run's or its agent's archive
51
+ * now) kept empty; the digest of the server's secrets it was cut of (`cut`, so a list cuts it again of any saved since);
52
+ * its status; whether a runner held the run (its status reads otherwise once that claim runs out); when it goes stale by
53
+ * the clock alone (the ask it waits on expires, or LISTING_RETRY_MS after a build that withheld the run because the
54
+ * sign-in it was handed could not be read: that read may fail only for now, and the run reads whole once it recovers);
55
+ * and what outside the run it read (LISTING_HELD, LISTING_KEYED). Undefined for an unknown run. */
56
+ export declare function listingOverStore(store: Store, runId: string, deps: ViewDeps): Promise<RunListing | undefined>;
57
+ /** Whether `listing` was cut of the server's secrets as they are now. A list builds one cut of others again before it
58
+ * shows it (server.ts runsPage): the run's view cuts a value whole where it holds a secret (a note's name reads
59
+ * [redacted]), which cutting the built item again could not do. */
60
+ export declare function cutOfNow(listing: {
61
+ readonly cut: string;
62
+ }, serverSecrets: readonly string[]): boolean;
63
+ /** A listing's list item as a list serves it (listingOverStore): its console link at `origin`, its archive time now
64
+ * (`archivedAt`, ms, the run's or its agent's), and, when the server's secrets moved between its build and this (within
65
+ * one list), every string in it cut again of them (redactedOutput), so a secret saved since never shows. */
66
+ export declare function listedItem(listing: {
67
+ readonly item: Record<string, unknown>;
68
+ readonly cut: string;
69
+ }, origin: string, archivedAt: number | null, serverSecrets: readonly string[]): Record<string, unknown>;
42
70
  /** A run's facts as its view states them, and none of its words: its kind, revision, agent, status and times, and whether
43
71
  * its output is withheld (`unshown`). What a read that serves its own parts (the graph) needs of the run: read off the
44
72
  * run as viewOverStore reads it, with nothing of it served, so nothing is redacted here. Undefined for an unknown run. */
@@ -16,22 +16,26 @@ import { CONTENT_FILTER_WORDS, contentFiltered, MODERATED } from "./content-filt
16
16
  import { COMPUTER_UNAVAILABLE_CODE, lostEndMessage } from "./computer-lost.js";
17
17
  import { launchOf } from "./handed-values.js";
18
18
  import { learningStartOf, seedFailed } from "./run-launch.js";
19
- import { momentOf, pendingOf, stoppedTurn, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costWordsOfView, freeOf, usersOf, withAsks, withApprovalRows, } from "./run-view.js";
19
+ import { momentOf, pendingOf, stoppedTurn, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costWordsOfView, freeOf, stopAsked, usersOf, withAsks, withApprovalRows, } from "./run-view.js";
20
20
  import { reflects } from "./reflect-range.js";
21
21
  import { freeCeilingMessage, overCapMessage, SPEND_CAP_REACHED } from "@parcha/agentrun-kernel/kernel/cap";
22
22
  import { bookedSpend, cliModelWorked, costWordsOf, planSpend, runCostOf } from "./runner/metrics.js";
23
23
  import { journalRecords, recordOf } from "./runner/journal-reader.js";
24
24
  import { capNowOf, KINDS } from "./runner/journal-kinds.js";
25
- import { laidOf, notesReadOf, runLearningEnd, usedOnly, withNotes } from "./store-reads/learning.js";
25
+ import { laidOf, runLearningEnd, usedOnly } from "./store-reads/learning.js";
26
+ import { correctionCount } from "./learn/corrections.js";
26
27
  import { isCliRecord, runReflect, runTimeline, wholeAnswerFor, wholeAnswers, withoutFeedbackRounds } from "./store-reads/journal.js";
27
28
  import { readRun } from "./store-reads/runs.js";
28
29
  import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
29
30
  import { Turns } from "./turns.js";
30
31
  import { harnessOfBody } from "./harness.js";
32
+ import { LOGIN_HARNESS } from "./claude-login.js";
31
33
  import { browserAsk as browserAskOf, BROWSER_HANDOVER_KIND } from "./browser-commands.js";
32
34
  import { computerAsk as computerAskOf, COMPUTER_HANDOVER_KIND } from "./computer-commands.js";
33
35
  import { approvalsOf } from "./approvals.js";
34
36
  import { FINAL_STATES, stoppedByPerson } from "./store/store.js";
37
+ import { LISTING_HELD, LISTING_KEYED } from "./store/schema.js";
38
+ import { createHash } from "node:crypto";
35
39
  /** A run that has ended reads one of these (the old RunRow state → the v2 status: an escalation is a completion with a
36
40
  * review; a stopped run is a cancellation), as runs.ts's STATUS_OF mapped them. A running run reads its status from the
37
41
  * journal, and so does an agentic run a person stopped, which reads running (runReadState). */
@@ -41,6 +45,10 @@ const STATUS_OF = { completed: "completed", failed: "failed", escalated: "comple
41
45
  export const settledStatusOf = (state) => (state === "running" ? undefined : STATUS_OF[state]);
42
46
  /** A run that has reached a last state (its view is its ended shape). */
43
47
  const TERMINAL = new Set(["completed", "failed", "cancelled"]);
48
+ /** How long a run's listing waits before it is built again when its build could not read what it needed (ms): a listing
49
+ * that withheld the run for a sign-in it could not read back (listingOverStore), and the lister's build that failed
50
+ * (run-listing.ts). */
51
+ export const LISTING_RETRY_MS = 30_000;
44
52
  const iso = (ms) => new Date(ms).toISOString();
45
53
  /** What a view last made of a run's text, by store and slot (a run's answer, or its input): the text it read (`input`),
46
54
  * the digest of the values it was redacted of (`key`) and what that gave (`out`), so a second view of the same text and
@@ -206,14 +214,11 @@ async function storeRunIn(store, runId, deps, cut) {
206
214
  const nativeSession = records.entries.findLast(e => e.kind === "agentrun.native.session")?.data;
207
215
  const native = launch?.native ? { runtime: launch.native.runtime, project: launch.native.project, selector: launch.native.selector, machine_id: launch.native.machine_id, fingerprint: nativeConfiguration?.fingerprint ?? launch.native.fingerprint, session_id: nativeSession?.session_id ?? null, model: nativeEvents.at(-1)?.model ?? launch.native.model, learning_revision: launch.learning?.seed ?? null, usage: { task: nativeTaskUsage, reflection: nativeEvents.filter(e => e.phase === "reflection").map(e => e.usage) }, model_requests: null } : undefined;
208
216
  const skip = reflectRange ? (id) => reflects(reflectRange, id) : undefined;
209
- // The run's learning end with the notes its start gave it and those its job read (its own reads, keyed on the given, read
210
- // from its rows uncut: a note whose name holds a secret is cut where it is shown, after it is matched). Before its end, a
211
- // run that learns is seeded, then looking back once its end-of-run turn starts (main's seeded and reflecting).
217
+ // The run's learning end. Before its end, a run that learns is seeded, then looking back once its end-of-run turn starts
218
+ // (main's seeded and reflecting).
212
219
  const started = launch ? learningStartOf(launch) : undefined;
213
- const read = started?.given.length ? notesReadOf(started.given, reflectRange, await runTimeline(store, runId, context, { settled: terminal })) : [];
214
220
  const under = !ended && started && started.use ? usedOnly(started, terminal, iso(runRow.endedAt ?? runRow.startedAt)) : !ended && started && !seedFailed(started) ? underWay(started, laidOf(records.entries), reflectRange, iso(runRow.startedAt)) : null;
215
- const sofar = ended ?? under;
216
- const shownEnd = sofar && withNotes(sofar, started, read);
221
+ const shownEnd = ended ?? under;
217
222
  const turns = new Turns();
218
223
  turns.note(recordOf(records.entries), records.submissions ?? [], skip, liveRow?.updatedAt ?? deps.now?.() ?? Date.now());
219
224
  const working = live && turns.open > 0;
@@ -223,21 +228,32 @@ async function storeRunIn(store, runId, deps, cut) {
223
228
  // the answers given, which the status, pending and moment views read the same as the file path read them from the run's
224
229
  // store entries.
225
230
  const approvals = asksOf(records.entries);
231
+ // The run's command rows, read once for what needs them: a stop or a cancel asked for, a hand-over's answers, and the
232
+ // person's messages not yet taken.
233
+ let commandRows;
234
+ const commandsNow = async () => (commandRows ??= await store.commands(runId, 0));
235
+ // A person's stop of an agentic run (stoppedByPerson: its row reads running, readRun) is main's stop mark: the run is
236
+ // stopped while no message is newer than the stop (statusOf: input_required and idle), and a message reopens it. A stop
237
+ // asked for and not yet taken (stopAsked) is the mark too once nothing works: between the turn's cut and the end that
238
+ // takes the stop, a read would otherwise see the cut turn's input_required with nothing pending; a run waiting (on an
239
+ // approval, a person, a browser) reads stopped from the stop's answer on. While its turn still works it reads working:
240
+ // the cut is what books the request it cuts (its cost unknown), so a run read stopped before the cut would say the known
241
+ // sum as its cost.
242
+ const asked = !terminal && !working && stopAsked(row, runRow, await commandsNow());
226
243
  // A call asked before an end in the journal reads withdrawn in that end's words; a stopped or failed run's (states no
227
- // reopen leaves) whose journal holds no end, by its row (answersOf `final`).
228
- const answers = answersOf(records.entries, { final: runRow.state === "stopped" || runRow.state === "failed" ? runRow.state : undefined });
244
+ // reopen leaves) whose journal holds no end, by its row (answersOf `final`); every call still waiting once a stop is
245
+ // asked (stopAsked).
246
+ const answers = answersOf(records.entries, { final: runRow.state === "stopped" || runRow.state === "failed" ? runRow.state : asked ? "stopped" : undefined });
229
247
  // The rows a person reads: each call that waited for approval in order (held, your approval, what came of it), its
230
248
  // arguments and the person's notes through the run's redactor, as the file path's withApprovals served them.
231
249
  const rows = withApprovalRows(timeline, approvals, answers, redactorOf(values));
232
250
  // The run's cap as it stands, through the one reader the runner's gate reads too (capNowOf): a raise taken shows in the
233
251
  // run's cost.cap_usd and its budget card, never the old cap.
234
252
  const capUsd = capNowOf(launch?.maxCostUsd, records.entries);
235
- // A person's stop of an agentic run (stoppedByPerson: its row reads running, readRun) is main's stop mark: the run is
236
- // stopped while no message is newer than the stop (statusOf: input_required and idle), and a message reopens it.
237
253
  const meta = {
238
254
  ...(capUsd !== undefined ? { max_cost_usd: capUsd } : {}),
239
255
  ...(Object.keys(answers).length ? { approvals: answers } : {}),
240
- ...(stoppedByPerson(runRow, row.kind) ? { stopped_after: usersOf(rows) } : {}),
256
+ ...(stoppedByPerson(runRow, row.kind) || asked ? { stopped_after: usersOf(rows) } : {}),
241
257
  };
242
258
  // The budget card the run shows while it stands parked at its cap, from its journal's agentrun.budget park (none once a
243
259
  // raise clears it). Read over the same meta cap and rows the card's figures and time come from.
@@ -248,10 +264,7 @@ async function storeRunIn(store, runId, deps, cut) {
248
264
  const paused = pausedOf(runRow, records.entries);
249
265
  // The browser hand-over the agent waits on (E2c's reader over the run's hand-over entries and hand-back commands), read
250
266
  // against the server's clock. Only a run with a hand-over entry fetches its commands, so a run with none reads none and
251
- // makes no extra store read.
252
- // The run's command rows, read once for what needs them: a hand-over's answers, and the person's messages not yet taken.
253
- let commandRows;
254
- const commandsNow = async () => (commandRows ??= await store.commands(runId, 0));
267
+ // makes no extra store read beyond the one a running run's stop and cancel already make.
255
268
  const browserAsk = records.entries.some((e) => e.kind === BROWSER_HANDOVER_KIND)
256
269
  ? browserAskOf(records.entries, await commandsNow(), deps.now?.() ?? Date.now())
257
270
  : undefined;
@@ -316,16 +329,16 @@ async function storeRunIn(store, runId, deps, cut) {
316
329
  return { ...(sdk ? { sdk } : {}), ...(native ? { native } : {}), row, runRow, launch, rows, version, harness, learningEnd: shownEnd, shownEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, ...(review ? { review } : {}), structured, decisions, plan, ...(endCost ? { endCost, endSaidCost } : {}) };
317
330
  }
318
331
  /** A run's learning as the view shows it: its end from the store (what it held for the owner's OK as it reads now), in a
319
- * person's words cut of the host's secrets now, and, for an ended run, the notes it read. */
320
- function learningViewOf(learningEnd, shown, settled) {
332
+ * person's words cut of the host's secrets now. */
333
+ function learningViewOf(learningEnd, shown) {
321
334
  if (!learningEnd)
322
335
  return null;
323
- return learningView(learningEnd, shown, settled);
336
+ return learningView(learningEnd, shown);
324
337
  }
325
- /** A run's learning before its end: its seed's notes and the learned skills/workflows its claims actually laid,
326
- * until its end-of-run turn starts; then looking back. Merely offered skills are not counted as supplied. */
338
+ /** A run's learning before its end: the corrections its # Learned section holds and the learned workflows its claims
339
+ * laid, until its end-of-run turn starts; then looking back. */
327
340
  function underWay(started, laid, reflect, at) {
328
- return reflect ? { state: "reflecting", reason: null, detail: said.reflecting, at } : { state: "seeded", reason: null, detail: said.seeded(started.seedNotes ?? 0, laid.skills.length, laid.workflows.length), at };
341
+ return reflect ? { state: "reflecting", reason: null, detail: said.reflecting, at } : { state: "seeded", reason: null, detail: said.seeded(correctionCount(started.section), laid.workflows.length), at };
329
342
  }
330
343
  /** The cost a run's view shows (runs.ts cost): its rows' cost, else what the store kept, and its cap. */
331
344
  function costOfView(run) {
@@ -358,21 +371,26 @@ function costOfView(run) {
358
371
  const usd = words.usd;
359
372
  const counted = words.so_far_usd !== undefined && words.unpriced !== undefined ? { so_far_usd: words.so_far_usd, unpriced: words.unpriced } : undefined;
360
373
  const upper = words.upper_bound ? { upper_bound: true } : undefined;
361
- // A request billed to a ChatGPT plan costs no dollars, however it ended (the kernel's turnCostOf): every reader counts it
362
- // $0, so it is in no unpriced count; what it used on the plan is said beside the figure.
374
+ // A request billed to a person's plan costs no dollars, however it ended (the kernel's turnCostOf): every reader counts it
375
+ // $0, so it is in no unpriced count; what it used on the plan is said beside the figure, and which plan: a run on the
376
+ // login's harness was on Claude Code's login (claude-login.ts), any other on the ChatGPT sign-in.
363
377
  const plan = run.plan;
378
+ const on = run.harness === LOGIN_HARNESS ? "claude_code" : "chatgpt";
364
379
  // Beside its figure: while it is unknown, what is known so far; at $0 with every model request on a free model (and no
365
380
  // decision of its own), that it is free.
366
381
  const soFar = counted ?? (imported || decisions?.requests ? undefined : freeOf(run.rows, usd));
367
382
  // The run's cap as it stands (its view's meta: the newest raise's, else the launch's).
368
383
  const cap = run.view.meta.max_cost_usd;
369
- return { usd, basis: "estimate", charge_state: null, cap_usd: cap ?? null, ...(soFar ?? {}), ...(upper ?? {}), ...(plan ? { plan: { requests: plan.requests, tokens: plan.tokens } } : {}) };
384
+ return { usd, basis: "estimate", charge_state: null, cap_usd: cap ?? null, ...(soFar ?? {}), ...(upper ?? {}), ...(plan ? { plan: { requests: plan.requests, tokens: plan.tokens, on } } : {}) };
370
385
  }
371
386
  /** GET /runs/{id}'s answer from the store, byte-identical to runs.ts's view for the same run. Undefined for an unknown run. */
372
387
  export async function viewOverStore(store, runId, deps) {
373
388
  const run = await storeRunOf(store, runId, deps);
374
- if (!run)
375
- return undefined;
389
+ return run && viewOfRun(store, runId, deps, run);
390
+ }
391
+ /** GET /runs/{id}'s answer for a run already read (storeRunOf). `read.withheld` is set to whether the answer withholds the
392
+ * run because this server could not read back the sign-in it was handed (its cut, or its error's words). */
393
+ async function viewOfRun(store, runId, deps, run, read) {
376
394
  const { row, runRow, launch, view, unshown, values, output, review: kept, structured } = run;
377
395
  const { status, state } = statusOf(view, factsOf(run));
378
396
  const terminal = TERMINAL.has(status);
@@ -417,6 +435,8 @@ export async function viewOverStore(store, runId, deps) {
417
435
  const failedReason = run.rows.findLast((r) => r.kind === "error")?.text ?? row.summary ?? null;
418
436
  const errorWords = status === "failed" && !unshown ? await runErrorWordsOf({ ...deps, keyEnv: deps.keyEnv ?? (() => process.env) }, store, runId, { workflow: row.kind === "workflow" }) : undefined;
419
437
  const withheld = unshown || errorWords === "unreadable";
438
+ if (read)
439
+ read.withheld = withheld;
420
440
  const error = status === "failed" ? (withheld ? { code: "run_failed", message: WITHHELD_SIGN_IN, retryable: false } : servedRunErrorWith(errorWords ?? shownWords, errorOfRow(failedReason))) : null;
421
441
  const review = endedAtMs === null ? null : servedReviewWith(shownWords, unshown, reviewAt(reviewOfRow(row.state, row.summary ?? null, kept), iso(endedAtMs)));
422
442
  // The card the run shows while it waits, in the order the file-backed view (runs.ts) picks them: a tool call parked for a
@@ -473,7 +493,7 @@ export async function viewOverStore(store, runId, deps) {
473
493
  // The caller's labels, as given at the start ({} when none): its own strings, never cut.
474
494
  labels: runRow.labels,
475
495
  // Cut by the run's one cut (the pointers it was handed among them), and none for a withheld run, as its words.
476
- learning: unshown ? null : learningViewOf(run.learningEnd, secretsShown(values), settled),
496
+ learning: unshown ? null : learningViewOf(run.learningEnd, secretsShown(values)),
477
497
  // Its screen recordings (computer.record), from the files on this machine, where its read asks for them; none for a
478
498
  // withheld run, whose files are refused. A run that left running with no end stamped (parked) ends now, each read: only
479
499
  // a file's trailer finishes it there.
@@ -485,8 +505,10 @@ export async function viewOverStore(store, runId, deps) {
485
505
  /** The run list's answer from the store, byte-identical to runs.ts's summary: the view's subset a list shows. */
486
506
  export async function summaryOverStore(store, runId, deps) {
487
507
  const view = await viewOverStore(store, runId, deps);
488
- if (!view)
489
- return undefined;
508
+ return view && summaryOfView(view);
509
+ }
510
+ /** What a list shows of a run's view (summaryOverStore). */
511
+ export function summaryOfView(view) {
490
512
  const { run_id, agent_id, agent_version, console_url, revision, kind, sha, status, state, title, effort, created_at, ended_at, error, review, pending, cost, archived_at, imported_from, trigger, labels, learning } = view;
491
513
  return {
492
514
  run_id, agent_id, agent_version, console_url, revision, kind, sha, status, state, title,
@@ -497,6 +519,50 @@ export async function summaryOverStore(store, runId, deps) {
497
519
  learning: learning ? shortOf(learning) : null,
498
520
  };
499
521
  }
522
+ /** A runs list's item for a run, as its listing keeps it on the run's row (store/schema.ts RUN_LISTING_COLUMNS), built from
523
+ * the run's view once per change and read by every list after: its list item (summaryOverStore's) with the parts a list
524
+ * fills in when it reads it (console_url: the origin the request reached; archived_at: the run's or its agent's archive
525
+ * now) kept empty; the digest of the server's secrets it was cut of (`cut`, so a list cuts it again of any saved since);
526
+ * its status; whether a runner held the run (its status reads otherwise once that claim runs out); when it goes stale by
527
+ * the clock alone (the ask it waits on expires, or LISTING_RETRY_MS after a build that withheld the run because the
528
+ * sign-in it was handed could not be read: that read may fail only for now, and the run reads whole once it recovers);
529
+ * and what outside the run it read (LISTING_HELD, LISTING_KEYED). Undefined for an unknown run. */
530
+ export async function listingOverStore(store, runId, deps) {
531
+ const cut = secretsDigest(deps.serverSecrets());
532
+ const run = await storeRunOf(store, runId, deps);
533
+ if (!run)
534
+ return undefined;
535
+ const read = { withheld: false };
536
+ const summary = summaryOfView(await viewOfRun(store, runId, deps, run, read));
537
+ const status = String(summary.status);
538
+ const terminal = TERMINAL.has(status);
539
+ const asks = terminal ? [] : [run.browserAsk?.expires_at, run.computerAsk?.expires_at].map((at) => (typeof at === "string" ? Date.parse(at) : Number.NaN)).filter((at) => Number.isFinite(at));
540
+ const expiries = read.withheld ? [...asks, (deps.now ?? Date.now)() + LISTING_RETRY_MS] : asks;
541
+ const flags = (run.shownEnd && holdsForOk(run.shownEnd) ? LISTING_HELD : 0) | (status === "failed" && run.row.kind !== "workflow" ? LISTING_KEYED : 0);
542
+ return {
543
+ item: { ...summary, console_url: null, archived_at: null },
544
+ cut,
545
+ status,
546
+ live: run.live,
547
+ until: expiries.length ? Math.min(...expiries) : null,
548
+ flags,
549
+ };
550
+ }
551
+ /** Whether `listing` was cut of the server's secrets as they are now. A list builds one cut of others again before it
552
+ * shows it (server.ts runsPage): the run's view cuts a value whole where it holds a secret (a note's name reads
553
+ * [redacted]), which cutting the built item again could not do. */
554
+ export function cutOfNow(listing, serverSecrets) {
555
+ return listing.cut === secretsDigest(serverSecrets);
556
+ }
557
+ /** A listing's list item as a list serves it (listingOverStore): its console link at `origin`, its archive time now
558
+ * (`archivedAt`, ms, the run's or its agent's), and, when the server's secrets moved between its build and this (within
559
+ * one list), every string in it cut again of them (redactedOutput), so a secret saved since never shows. */
560
+ export function listedItem(listing, origin, archivedAt, serverSecrets) {
561
+ const item = { ...listing.item, console_url: runLink(origin, String(listing.item.run_id)), archived_at: archivedAt === null ? null : iso(archivedAt) };
562
+ return listing.cut === secretsDigest(serverSecrets) ? item : redactedOutput(item, [...serverSecrets]);
563
+ }
564
+ /** A set of secrets' digest, the same for the same set in any order: what a listing was cut of. */
565
+ const secretsDigest = (values) => createHash("sha256").update([...new Set(values)].sort().join("\0")).digest("hex");
500
566
  /** A run's facts as its view states them, and none of its words: its kind, revision, agent, status and times, and whether
501
567
  * its output is withheld (`unshown`). What a read that serves its own parts (the graph) needs of the run: read off the
502
568
  * run as viewOverStore reads it, with nothing of it served, so nothing is redacted here. Undefined for an unknown run. */
@@ -110,11 +110,8 @@ export type EvalCase = {
110
110
  /** How the case's runs' monid endpoints answer in place of monid (runner/monid-run.ts): `unavailable`, as monid
111
111
  * unreachable does, never sent. The eval's own server's runner alone binds it. Absent: monid. */
112
112
  monid?: MonidFake;
113
- /** The notes a run's agent starts with (not MEMORY.md, which the server builds from them). */
114
- learning: {
115
- file: string;
116
- text: string;
117
- }[];
113
+ /** The owner's corrections a run's agent starts with (its corrections.md, whole). Absent: none. */
114
+ learning?: string;
118
115
  graders: Grader[];
119
116
  /** The case's clock (`now:`, an RFC 3339 date-time with its offset, as written): each run's current date and time,
120
117
  * which the eval's own runner alone sets, and its llm graders are told. Absent: the real clock. */
@@ -141,7 +138,7 @@ export declare class CaseError extends Error {
141
138
  }
142
139
  /** The package in `dir`, checked as the server checks it, and its eval cases (all, or those `names` lists), each read and
143
140
  * checked whole: the prompt, case.yaml against the package (an apply's parameters and grants), each fake MCP server's
144
- * fixture, each learned note as the learning API checks one, and each grader's fields. Nothing runs. PackageError or
141
+ * fixture, its corrections as the learning API checks them, and each grader's fields. Nothing runs. PackageError or
145
142
  * CaseError with every problem found. */
146
143
  export declare function readCases(dir: string, names?: readonly string[]): {
147
144
  pkg: Package;
@@ -3,7 +3,7 @@
3
3
  // Everything goes through the v2 API alone, on an in-process server over a temp data directory by default (an eval never
4
4
  // touches the owner's server) or on one named by its address and token. Per case: a fake MCP server per `mcp` fixture,
5
5
  // saved under its name with no credential and recording every call; the package applied with the case's parameters and
6
- // grants, a fresh agent per run, its learning seeded from the case's notes; one run per `runs` with the prompt's body as
6
+ // grants, a fresh agent per run, its learning seeded from the case's corrections; one run per `runs` with the prompt's body as
7
7
  // its input and the case's cap, on the case's clock when it sets one (`now`), waited for; then its answer, its tool calls (its timeline read with calls=whole, each
8
8
  // call's arguments and its output's head through the run's redaction, and the fakes' own logs) and its files, graded, and held to the package's output schema when it declares one (outputVerdict,
9
9
  // the server's own verdict). Every grader is deterministic but `llm`, which is itself a run on the same
@@ -16,8 +16,7 @@ import { tmpdir } from "node:os";
16
16
  import { join } from "node:path";
17
17
  import { parseDocument } from "yaml";
18
18
  import { answerJson, lastJsonBlock } from "./answer-json.js";
19
- import { checkNote } from "./learn/index.js";
20
- import { NOTE_FILE } from "./learn/notes.js";
19
+ import { correctionsProblems } from "./learn/index.js";
21
20
  import { linkCheck } from "./link-check.js";
22
21
  import { inputMessage } from "./run-manifest.js";
23
22
  import { shownUrl } from "./mcp-probe.js";
@@ -272,7 +271,7 @@ function graderOfType(p, file, text, bad) {
272
271
  }
273
272
  /** The package in `dir`, checked as the server checks it, and its eval cases (all, or those `names` lists), each read and
274
273
  * checked whole: the prompt, case.yaml against the package (an apply's parameters and grants), each fake MCP server's
275
- * fixture, each learned note as the learning API checks one, and each grader's fields. Nothing runs. PackageError or
274
+ * fixture, its corrections as the learning API checks them, and each grader's fields. Nothing runs. PackageError or
276
275
  * CaseError with every problem found. */
277
276
  export function readCases(dir, names) {
278
277
  // The cases are read below, each fixture checked there in the case's own words (a CaseError), not by the package read.
@@ -471,29 +470,18 @@ export function readCases(dir, names) {
471
470
  if (body || fields || f.max_cost_usd !== undefined)
472
471
  bad(`${at}/prompt.md: a feed case's run is started by the package's trigger, on the trigger's input and cap: its prompt.md holds description and runs alone`);
473
472
  }
474
- const learning = [];
473
+ let learning;
475
474
  if (c.learning !== undefined) {
476
- const folder = inside(root, c.learning, "dir");
477
- if (!folder)
478
- bad(`${at}/case.yaml: learning names ${JSON.stringify(c.learning)}, not a folder in the case`);
475
+ const file = inside(root, c.learning, "file");
476
+ if (!file)
477
+ bad(`${at}/case.yaml: learning names ${JSON.stringify(c.learning)}, not a file in the case`);
479
478
  else {
480
- for (const entry of readdirSync(join(root, folder), { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : 1))) {
481
- if (entry.name === "MEMORY.md")
482
- continue;
483
- const path = `${at}/${folder}/${entry.name}`;
484
- if (!entry.isFile() || !NOTE_FILE.test(entry.name)) {
485
- bad(`${path}: a learning folder holds MEMORY.md and notes (<name>.md) only`);
486
- continue;
487
- }
488
- const bytes = readFileSync(join(root, folder, entry.name));
489
- const checked = checkNote(entry.name, bytes);
490
- if (!checked.note)
491
- for (const problem of checked.problems)
492
- bad(`${path}: ${problem.detail}`);
493
- learning.push({ file: entry.name, text: bytes.toString("utf8") });
494
- }
495
- if (!learning.length)
496
- bad(`${at}/${folder}: holds no note`);
479
+ // The owner's corrections as the learning API takes them (PUT .../learning/corrections): one file, within its cap.
480
+ learning = readFileSync(join(root, file), "utf8");
481
+ for (const problem of correctionsProblems(learning))
482
+ bad(`${at}/${file}: ${problem.detail}`);
483
+ if (!learning.trim())
484
+ bad(`${at}/${file}: holds no correction`);
497
485
  }
498
486
  }
499
487
  const graders = [];
@@ -516,7 +504,7 @@ export function readCases(dir, names) {
516
504
  cases.push({
517
505
  name, description: typeof f.description === "string" ? f.description : "", runs: typeof f.runs === "number" ? f.runs : 1,
518
506
  ...(typeof f.max_cost_usd === "number" ? { maxCostUsd: f.max_cost_usd } : {}), input: body, ...(fields ? { fields } : {}),
519
- parameters, grants, mcp, ...(web ? { web } : {}), ...(monid ? { monid } : {}), learning, graders, ...(typeof c.now === "string" ? { now: c.now } : {}), ...(email ? { email } : {}), ...(calendar ? { calendar } : {}), ...(feed ? { feed } : {}),
507
+ parameters, grants, mcp, ...(web ? { web } : {}), ...(monid ? { monid } : {}), ...(learning !== undefined ? { learning } : {}), graders, ...(typeof c.now === "string" ? { now: c.now } : {}), ...(email ? { email } : {}), ...(calendar ? { calendar } : {}), ...(feed ? { feed } : {}),
520
508
  });
521
509
  }
522
510
  if (problems.length)
@@ -1034,7 +1022,7 @@ export async function evalTemplate(options) {
1034
1022
  const work = await workOf(options.data).catch((error) => (removeTree(scratch), Promise.reject(error)));
1035
1023
  if (work) {
1036
1024
  removeTree(scratch);
1037
- throw new Error(`the server on ${options.data} has work of its own: ${work}, which the eval's server and runner would take up: disable its triggers and let its runs and learning batches end (or stop them), then run the eval; or run it without --on-data`);
1025
+ throw new Error(`the server on ${options.data} has work of its own: ${work}, which the eval's server and runner would take up: disable its triggers and let its runs end (or stop them), then run the eval; or run it without --on-data`);
1038
1026
  }
1039
1027
  }
1040
1028
  const { startServe } = await import("./server.js");
@@ -1257,18 +1245,14 @@ async function workOf(data) {
1257
1245
  const store = await openStore({ dataDir: data, role: "server" });
1258
1246
  try {
1259
1247
  const triggers = (await store.triggers.all()).filter((one) => one.enabled && !one.disabled).length;
1260
- // The runs not ended a list shows, and every run a runner would claim: the list leaves out built-in learning runs
1261
- // (a kept learning's), which the eval's runner claims as any other.
1248
+ // The runs not ended a list shows, and every run a runner would claim.
1262
1249
  const runs = new Set();
1263
1250
  for (const state of ["queued", "running", "parked"])
1264
1251
  for (const run of await store.runs.list({ state }))
1265
1252
  runs.add(run.id);
1266
1253
  for (const id of await store.runs.claimable())
1267
1254
  runs.add(id);
1268
- // A learning batch still running, which the eval's server would resume at its start (learning-batch.ts resume), its
1269
- // next rows' runs with it.
1270
- const batches = (await store.settings.all()).filter(({ key, value }) => /^learning_batch\/lb_[0-9a-f]{16}$/.test(key) && isObject(value) && value.status === "running").length;
1271
- const said = [triggers ? `${triggers} enabled trigger${triggers === 1 ? "" : "s"}` : "", runs.size ? `${runs.size} run${runs.size === 1 ? "" : "s"} not ended` : "", batches ? `${batches} learning batch${batches === 1 ? "" : "es"} running` : ""].filter(Boolean);
1255
+ const said = [triggers ? `${triggers} enabled trigger${triggers === 1 ? "" : "s"}` : "", runs.size ? `${runs.size} run${runs.size === 1 ? "" : "s"} not ended` : ""].filter(Boolean);
1272
1256
  return said.length ? said.join(", ") : undefined;
1273
1257
  }
1274
1258
  finally {
@@ -1357,7 +1341,7 @@ async function triggerRun(ctx, name, agentId, triggerId, deliver, hint) {
1357
1341
  await sleep(200);
1358
1342
  }
1359
1343
  }
1360
- /** One run of a case: a fresh agent (so one run's learning never reaches the next), its notes, the run, its grades. An
1344
+ /** One run of a case: a fresh agent (so one run's learning never reaches the next), its corrections, the run, its grades. An
1361
1345
  * email case's run (`mail`) is its trigger's (triggerRun). */
1362
1346
  async function runOnce(ctx, one, n, fakes, mail, feeds) {
1363
1347
  const { api, pkg, options, made } = ctx;
@@ -1400,8 +1384,10 @@ async function runOnce(ctx, one, n, fakes, mail, feeds) {
1400
1384
  const used = Object.fromEntries(Object.entries(isObject(applied.servers) ? applied.servers : {}).filter((entry) => typeof entry[1] === "string"));
1401
1385
  await sameAsLocal(ctx, one, agent, used);
1402
1386
  stopped();
1403
- for (const note of one.learning) {
1404
- expectOk(`seeding the note ${note.file}`, await api("PUT", `/agents/${encodeURIComponent(agentId)}/learning/files/${encodeURIComponent(note.file)}`, note.text, { "if-none-match": "*" }));
1387
+ if (one.learning !== undefined) {
1388
+ const corrections = `/agents/${encodeURIComponent(agentId)}/learning/corrections`;
1389
+ const read = expectOk("reading the agent's corrections", await api("GET", corrections));
1390
+ expectOk("seeding the agent's corrections", await api("PUT", corrections, { text: one.learning }, { "if-match": String(read.etag) }));
1405
1391
  }
1406
1392
  stopped();
1407
1393
  // The case's fakes, for this run's agent alone, before its run can be claimed.
@@ -6,6 +6,7 @@ import { type PinValue } from "./tool-gate.js";
6
6
  import { type BashPolicy } from "./bash-read-only.js";
7
7
  import { type Json } from "./validate.js";
8
8
  import { type Approvals } from "./approvals.js";
9
+ import { type LearningSetting } from "./learning-setting.js";
9
10
  /** The packages this server ships. */
10
11
  /** What applying a template reads of the server beyond its package (server.ts wires it): the GitHub connection, the
11
12
  * App's id, slug and installations (github-connection.ts), never a secret; undefined when GitHub is not connected. */
@@ -139,7 +140,9 @@ export type Package = {
139
140
  budget?: {
140
141
  per_run_usd: number;
141
142
  };
142
- learning?: boolean;
143
+ /** The agent's `learning`, as a definition takes it: true, false, or the loop's settings (agree_on, each path a required
144
+ * field of the output schema). */
145
+ learning?: LearningSetting;
143
146
  /** Whether the agent asks its person before a tool runs (`ask`) or runs unattended (`never`): the package's default,
144
147
  * shown to the owner at apply. A template whose job runs on triggers says never. Deny and pins hold either way. */
145
148
  approvals?: "ask" | "never";
@@ -289,7 +292,7 @@ export declare function packageView(p: Package): {
289
292
  budget: {
290
293
  per_run_usd: number;
291
294
  } | null;
292
- learning: boolean;
295
+ learning: LearningSetting;
293
296
  approvals_default: "ask" | "never";
294
297
  triggers: Json[];
295
298
  skills: string[];
@@ -362,7 +365,7 @@ export declare function packageDetail(p: Package): {
362
365
  budget: {
363
366
  per_run_usd: number;
364
367
  } | null;
365
- learning: boolean;
368
+ learning: LearningSetting;
366
369
  approvals_default: "ask" | "never";
367
370
  triggers: Json[];
368
371
  skills: string[];
@@ -383,7 +386,7 @@ export declare class TemplateRegistry {
383
386
  /** Whether an imported package of that id was there to remove. */
384
387
  remove(id: string): boolean;
385
388
  }
386
- /** POST /v2/templates/{name}/apply's body (`{parameters, grants?, overrides?: {model?, choice?, approvals?}}`), checked
389
+ /** POST /v2/templates/{name}/apply's body (`{parameters, grants?, servers?, overrides?: {model?, choice?, approvals?}, agent_id?}`), checked
387
390
  * against the package: the parameters as given (a blank one at its default), the MCP tools the owner allows (each one the
388
391
  * package lists, by its gate name), and the model asked for in place of the package's: one of its own (`model`), or one
389
392
  * of the package's model choices by id (`choice`), never both. 422 naming every field that is wrong. */
@@ -394,6 +397,7 @@ export declare function applyBodyOf(p: Package, body: Json): {
394
397
  model?: string;
395
398
  choice?: ModelChoice;
396
399
  approvals?: Approvals;
400
+ agentId?: string;
397
401
  };
398
402
  /** The model a package's agent gets here, as `{model?, warning?}`: its `prefer` when this server runs it on `harness`
399
403
  * with a key for its provider, else `refused` (preferUnrunnable): apply makes nothing, never the tier's model in its