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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/CHANGELOG.md +131 -5
  2. package/README.md +371 -300
  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 +52 -16
  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-3O2Yl6hZ.js +701 -0
  39. package/dist/console/assets/index-DaFsZuzQ.css +1 -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/key-check.js +3 -0
  64. package/dist/learn/audit.d.ts +6 -6
  65. package/dist/learn/audit.js +3 -7
  66. package/dist/learn/check.d.ts +23 -89
  67. package/dist/learn/check.js +57 -335
  68. package/dist/learn/commit.d.ts +63 -90
  69. package/dist/learn/commit.js +124 -316
  70. package/dist/learn/compile.d.ts +53 -50
  71. package/dist/learn/compile.js +87 -102
  72. package/dist/learn/corrections.d.ts +13 -0
  73. package/dist/learn/corrections.js +23 -0
  74. package/dist/learn/delete.d.ts +5 -5
  75. package/dist/learn/delete.js +8 -10
  76. package/dist/learn/folder.d.ts +35 -47
  77. package/dist/learn/folder.js +118 -134
  78. package/dist/learn/index.d.ts +3 -5
  79. package/dist/learn/index.js +6 -9
  80. package/dist/learn/learning.sh +45 -15
  81. package/dist/learn/promote.d.ts +13 -1
  82. package/dist/learn/promote.js +9 -0
  83. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
  84. package/dist/learn/{skills.js → workflow-draft.js} +48 -58
  85. package/dist/learn/workflow-nodes.js +1 -1
  86. package/dist/learned-workflow.js +2 -2
  87. package/dist/learning-cost.d.ts +38 -24
  88. package/dist/learning-cost.js +41 -24
  89. package/dist/learning-routes.d.ts +91 -170
  90. package/dist/learning-routes.js +183 -421
  91. package/dist/learning-run.d.ts +19 -40
  92. package/dist/learning-run.js +23 -93
  93. package/dist/learning-setting.d.ts +4 -4
  94. package/dist/learning-setting.js +6 -6
  95. package/dist/learning-words.d.ts +28 -74
  96. package/dist/learning-words.js +64 -162
  97. package/dist/learning.d.ts +61 -392
  98. package/dist/learning.js +101 -651
  99. package/dist/live-reach.d.ts +25 -2
  100. package/dist/live-reach.js +46 -4
  101. package/dist/llms.txt +1 -1
  102. package/dist/local-models.d.ts +3 -11
  103. package/dist/local-models.js +5 -6
  104. package/dist/mcp-servers-store.d.ts +4 -4
  105. package/dist/model-form.js +6 -5
  106. package/dist/model.d.ts +4 -0
  107. package/dist/model.js +26 -9
  108. package/dist/native/binding.js +1 -1
  109. package/dist/native/connection.js +1 -1
  110. package/dist/native/discovery.js +1 -1
  111. package/dist/native/instructions.d.ts +3 -0
  112. package/dist/native/instructions.js +5 -3
  113. package/dist/native/remote-worker-bridge.js +9 -43
  114. package/dist/native/remote.d.ts +8 -15
  115. package/dist/native/remote.js +3 -3
  116. package/dist/native/schema.js +1 -1
  117. package/dist/native/types.d.ts +2 -2
  118. package/dist/openapi.js +268 -316
  119. package/dist/paid-calls.d.ts +8 -0
  120. package/dist/paid-calls.js +20 -0
  121. package/dist/particle-provider.d.ts +11 -0
  122. package/dist/particle-provider.js +135 -0
  123. package/dist/port-models.d.ts +12 -4
  124. package/dist/port-models.js +28 -11
  125. package/dist/print.d.ts +27 -0
  126. package/dist/print.js +21 -0
  127. package/dist/provider.d.ts +7 -0
  128. package/dist/provider.js +15 -1
  129. package/dist/reflect-range.js +2 -3
  130. package/dist/run-launch.d.ts +14 -28
  131. package/dist/run-launch.js +9 -12
  132. package/dist/run-learning-served.d.ts +15 -89
  133. package/dist/run-listing.d.ts +34 -0
  134. package/dist/run-listing.js +128 -0
  135. package/dist/run-model-key.js +1 -1
  136. package/dist/run-timeline-served.js +5 -3
  137. package/dist/run-trace.d.ts +97 -0
  138. package/dist/run-trace.js +253 -0
  139. package/dist/run-view.d.ts +15 -0
  140. package/dist/run-view.js +9 -0
  141. package/dist/runnable.js +2 -1
  142. package/dist/runner/adapter-loop.d.ts +8 -6
  143. package/dist/runner/adapter-loop.js +16 -12
  144. package/dist/runner/adapter-run-spec.d.ts +16 -4
  145. package/dist/runner/adapter-run-spec.js +64 -58
  146. package/dist/runner/adapters/index.js +22 -0
  147. package/dist/runner/adapters/pi.d.ts +4 -12
  148. package/dist/runner/adapters/pi.js +2 -2
  149. package/dist/runner/audit.d.ts +1 -1
  150. package/dist/runner/audit.js +16 -8
  151. package/dist/runner/beside.d.ts +6 -2
  152. package/dist/runner/beside.js +38 -9
  153. package/dist/runner/claim-secrets.d.ts +18 -2
  154. package/dist/runner/claim-secrets.js +42 -18
  155. package/dist/runner/cli-run-spec.js +55 -51
  156. package/dist/runner/conformance/harness.d.ts +6 -0
  157. package/dist/runner/conformance/harness.js +16 -5
  158. package/dist/runner/dispatch.d.ts +2 -2
  159. package/dist/runner/end-of-run.d.ts +6 -14
  160. package/dist/runner/end-of-run.js +8 -33
  161. package/dist/runner/feedback-round.d.ts +2 -2
  162. package/dist/runner/feedback-round.js +7 -7
  163. package/dist/runner/github-app.js +3 -1
  164. package/dist/runner/harness-loops.d.ts +0 -8
  165. package/dist/runner/harness-loops.js +11 -59
  166. package/dist/runner/held.d.ts +170 -0
  167. package/dist/runner/held.js +57 -0
  168. package/dist/runner/journal-kinds.d.ts +2 -3
  169. package/dist/runner/journal-kinds.js +2 -3
  170. package/dist/runner/learned-first.d.ts +40 -0
  171. package/dist/runner/learned-first.js +32 -0
  172. package/dist/runner/learning-end.d.ts +77 -69
  173. package/dist/runner/learning-end.js +250 -303
  174. package/dist/runner/learning-seed.d.ts +15 -33
  175. package/dist/runner/learning-seed.js +24 -45
  176. package/dist/runner/loop-contract.d.ts +2 -3
  177. package/dist/runner/main.d.ts +17 -9
  178. package/dist/runner/main.js +63 -20
  179. package/dist/runner/mcp-run.d.ts +11 -0
  180. package/dist/runner/mcp-run.js +67 -0
  181. package/dist/runner/memory-claim.d.ts +10 -5
  182. package/dist/runner/memory-claim.js +12 -6
  183. package/dist/runner/model-route.d.ts +7 -4
  184. package/dist/runner/model-route.js +22 -10
  185. package/dist/runner/native-loop.d.ts +0 -7
  186. package/dist/runner/native-loop.js +9 -101
  187. package/dist/runner/promotion.d.ts +8 -6
  188. package/dist/runner/promotion.js +19 -12
  189. package/dist/runner/reflect-hook.d.ts +64 -95
  190. package/dist/runner/reflect-hook.js +112 -225
  191. package/dist/runner/run-channel.d.ts +43 -0
  192. package/dist/runner/run-channel.js +467 -0
  193. package/dist/runner/run-child-host.d.ts +169 -0
  194. package/dist/runner/run-child-host.js +1222 -0
  195. package/dist/runner/run-child.d.ts +1 -0
  196. package/dist/runner/run-child.js +254 -0
  197. package/dist/runner/run-errors.d.ts +2 -0
  198. package/dist/runner/run-errors.js +20 -0
  199. package/dist/runner/runner.js +1 -5
  200. package/dist/runner/sdk-ask.d.ts +78 -0
  201. package/dist/runner/sdk-ask.js +158 -0
  202. package/dist/runner/sdk-loop.d.ts +2 -4
  203. package/dist/runner/sdk-loop.js +29 -49
  204. package/dist/runner/store-secrets.d.ts +5 -3
  205. package/dist/runner/store-secrets.js +5 -1
  206. package/dist/runner/workflow-first.d.ts +5 -0
  207. package/dist/runner/workflow-first.js +4 -0
  208. package/dist/runner/workflow-spec.js +7 -2
  209. package/dist/runs-over-store.d.ts +16 -28
  210. package/dist/runs-over-store.js +31 -38
  211. package/dist/sdk/runs.d.ts +6 -11
  212. package/dist/sdk/runs.js +20 -41
  213. package/dist/sdk/schema.js +3 -4
  214. package/dist/seal-key.d.ts +5 -0
  215. package/dist/seal-key.js +7 -0
  216. package/dist/secrets.d.ts +3 -0
  217. package/dist/secrets.js +16 -3
  218. package/dist/server.d.ts +55 -33
  219. package/dist/server.js +685 -320
  220. package/dist/sign-ins-store.d.ts +8 -0
  221. package/dist/sign-ins-store.js +36 -1
  222. package/dist/skills.js +1 -1
  223. package/dist/store/index.d.ts +2 -2
  224. package/dist/store/index.js +1 -1
  225. package/dist/store/journal/storage.js +3 -0
  226. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  227. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  228. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  229. package/dist/store/schema.d.ts +53 -4
  230. package/dist/store/schema.js +137 -6
  231. package/dist/store/sqlite/connection.d.ts +2 -0
  232. package/dist/store/sqlite/connection.js +3 -1
  233. package/dist/store/sqlite/run-patch.d.ts +0 -17
  234. package/dist/store/sqlite/run-patch.js +4 -33
  235. package/dist/store/sqlite/store.js +246 -63
  236. package/dist/store/sqlite/worker.js +25 -0
  237. package/dist/store/store.d.ts +193 -36
  238. package/dist/store/store.js +25 -3
  239. package/dist/store-reads/learning.d.ts +102 -204
  240. package/dist/store-reads/learning.js +159 -321
  241. package/dist/store-reads/loop.d.ts +0 -1
  242. package/dist/store-reads/loop.js +1 -1
  243. package/dist/store-view.d.ts +29 -1
  244. package/dist/store-view.js +97 -31
  245. package/dist/template-eval.d.ts +3 -6
  246. package/dist/template-eval.js +22 -36
  247. package/dist/templates.d.ts +2 -1
  248. package/dist/templates.js +6 -3
  249. package/dist/timeline/index.d.ts +1 -1
  250. package/dist/timeline/index.js +1 -1
  251. package/dist/timeline/timeline.d.ts +5 -1
  252. package/dist/timeline/timeline.js +16 -0
  253. package/dist/tool-gate.d.ts +0 -7
  254. package/dist/tool-gate.js +1 -15
  255. package/dist/tool-keys-store.d.ts +1 -1
  256. package/dist/tool-keys.d.ts +6 -4
  257. package/dist/tool-keys.js +12 -6
  258. package/dist/tools.d.ts +2 -2
  259. package/dist/tools.js +11 -4
  260. package/dist/triggers.d.ts +60 -5
  261. package/dist/triggers.js +123 -18
  262. package/dist/validate.js +1 -1
  263. package/dist/webhooks.d.ts +4 -1
  264. package/dist/webhooks.js +11 -4
  265. package/dist/workspace/agent-computer.d.ts +2 -0
  266. package/dist/workspace/agent-computer.js +2 -0
  267. package/dist/workspace/archil-claim.d.ts +7 -0
  268. package/dist/workspace/archil-claim.js +29 -0
  269. package/dist/workspace/archil.d.ts +9 -1
  270. package/dist/workspace/archil.js +165 -3
  271. package/dist/workspace/attach.d.ts +3 -1
  272. package/dist/workspace/attach.js +2 -0
  273. package/dist/workspace/attached-computers.d.ts +16 -5
  274. package/dist/workspace/attached-computers.js +25 -9
  275. package/dist/workspace/computer-deps.js +1 -1
  276. package/dist/workspace/computer-for-claim.d.ts +7 -3
  277. package/dist/workspace/computer-for-claim.js +119 -22
  278. package/dist/workspace/computer-hold.js +2 -1
  279. package/dist/workspace/computer-kept.d.ts +11 -1
  280. package/dist/workspace/computer-kept.js +24 -3
  281. package/dist/workspace/resolve-computer.d.ts +33 -19
  282. package/dist/workspace/resolve-computer.js +172 -64
  283. package/dist/workspace/revision-skills.d.ts +1 -2
  284. package/dist/workspace/revision-skills.js +3 -4
  285. package/dist/workspace/run-workspace.d.ts +1 -1
  286. package/dist/workspace/run-workspace.js +5 -0
  287. package/dist/workspace/synced-folder.d.ts +85 -0
  288. package/dist/workspace/synced-folder.js +230 -0
  289. package/dist/workspace/workspace.d.ts +4 -0
  290. package/launcher/agentrun-serve +1 -1
  291. package/package.json +10 -10
  292. package/templates/README.md +7 -7
  293. package/templates/inbound-lead/agent.md +3 -3
  294. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  295. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  296. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  297. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  298. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  299. package/templates/inbound-lead/lead.schema.json +6 -5
  300. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  301. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  302. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  303. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  304. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  305. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  306. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  307. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  308. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  309. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  310. package/dist/console/assets/index-BUktRvS-.css +0 -1
  311. package/dist/console/assets/index-nB9kTfIN.js +0 -711
  312. package/dist/learn/grade.d.ts +0 -138
  313. package/dist/learn/grade.js +0 -682
  314. package/dist/learn/notes.d.ts +0 -81
  315. package/dist/learn/notes.js +0 -178
  316. package/dist/learn/reflect.d.ts +0 -77
  317. package/dist/learn/reflect.js +0 -228
  318. package/dist/learn/relevance.d.ts +0 -24
  319. package/dist/learn/relevance.js +0 -91
  320. package/dist/learn/seed-check.d.ts +0 -74
  321. package/dist/learn/seed-check.js +0 -103
  322. package/dist/learning-batch.d.ts +0 -291
  323. package/dist/learning-batch.js +0 -600
  324. package/dist/learning-evals.d.ts +0 -35
  325. package/dist/learning-evals.js +0 -99
  326. package/dist/native/context.d.ts +0 -6
  327. package/dist/native/context.js +0 -22
  328. package/dist/propose.d.ts +0 -52
  329. package/dist/propose.js +0 -224
  330. package/dist/runner/learning-ask.d.ts +0 -47
  331. package/dist/runner/learning-ask.js +0 -128
  332. package/dist/runner/learning-dispatch.d.ts +0 -45
  333. package/dist/runner/learning-dispatch.js +0 -99
  334. package/dist/runner/learning-factory.d.ts +0 -16
  335. package/dist/runner/learning-factory.js +0 -50
  336. package/dist/runner/learning-loop.d.ts +0 -273
  337. package/dist/runner/learning-loop.js +0 -521
  338. package/dist/usage.d.ts +0 -11
  339. package/dist/usage.js +0 -11
  340. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  341. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  342. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  343. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  344. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  345. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  346. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -7,24 +7,15 @@ export declare function servedRunLearning(deps: {
7
7
  signIns?: SignInReader;
8
8
  statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
9
9
  }, store: Store, runId: string): Promise<{
10
+ run: string;
11
+ state: "dropped" | "merged" | "seeded" | "reflecting";
12
+ reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
13
+ detail: string | null;
14
+ at: string;
15
+ workflows: import("./learning.js").LearnedFile[];
16
+ corrections: number;
10
17
  seed: string | null;
11
18
  merged: string | null;
12
- pending: {
13
- file: string;
14
- name: string;
15
- }[];
16
- verdict: {
17
- merge: boolean;
18
- reason: string;
19
- items: {
20
- why: string;
21
- question?: string | undefined;
22
- origin?: "run" | "you" | undefined;
23
- pending?: boolean | undefined;
24
- file: string;
25
- keep: boolean;
26
- }[];
27
- } | null;
28
19
  problems: {
29
20
  detail: string;
30
21
  path?: string | undefined;
@@ -32,7 +23,6 @@ export declare function servedRunLearning(deps: {
32
23
  }[];
33
24
  compiled: {
34
25
  workflow: string;
35
- from_notes: string[];
36
26
  attempts: {
37
27
  ok: boolean;
38
28
  errors: string[];
@@ -41,33 +31,13 @@ export declare function servedRunLearning(deps: {
41
31
  promoted: boolean | null;
42
32
  } | null;
43
33
  draft_errors: string[];
44
- cost_usd: {
45
- grade: number | null;
46
- };
47
- tokens: {
48
- grade: import("./learning.js").Tokens | null;
49
- };
50
34
  used: {
51
- skills: {
52
- name: string;
53
- read: boolean;
54
- }[];
55
35
  workflows: {
56
36
  name: string;
57
37
  calls: number;
58
38
  failed: number;
59
39
  }[];
60
40
  };
61
- given?: import("./learning.js").NoteUsed[];
62
- read?: import("./learning.js").NoteUsed[];
63
- learned?: import("./learning.js").NoteLearned[];
64
- skills?: import("./learning.js").LearnedFile[];
65
- workflows?: import("./learning.js").LearnedFile[];
66
- run: string;
67
- state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
68
- reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
69
- detail: string | null;
70
- at: string;
71
41
  } | {
72
42
  graded: {
73
43
  workflow: string | null;
@@ -76,28 +46,19 @@ export declare function servedRunLearning(deps: {
76
46
  graded_at: string;
77
47
  path: "agent" | "workflow" | "replay" | "handed_back" | "audit";
78
48
  workflow_digest: string | null;
79
- feedback: "look_back" | null;
49
+ feedback: "correction" | null;
80
50
  run_id: string;
81
51
  correct: boolean;
82
52
  };
53
+ run: string;
54
+ state: "dropped" | "merged" | "seeded" | "reflecting";
55
+ reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
56
+ detail: string | null;
57
+ at: string;
58
+ workflows: import("./learning.js").LearnedFile[];
59
+ corrections: number;
83
60
  seed: string | null;
84
61
  merged: string | null;
85
- pending: {
86
- file: string;
87
- name: string;
88
- }[];
89
- verdict: {
90
- merge: boolean;
91
- reason: string;
92
- items: {
93
- why: string;
94
- question?: string | undefined;
95
- origin?: "run" | "you" | undefined;
96
- pending?: boolean | undefined;
97
- file: string;
98
- keep: boolean;
99
- }[];
100
- } | null;
101
62
  problems: {
102
63
  detail: string;
103
64
  path?: string | undefined;
@@ -105,7 +66,6 @@ export declare function servedRunLearning(deps: {
105
66
  }[];
106
67
  compiled: {
107
68
  workflow: string;
108
- from_notes: string[];
109
69
  attempts: {
110
70
  ok: boolean;
111
71
  errors: string[];
@@ -114,33 +74,13 @@ export declare function servedRunLearning(deps: {
114
74
  promoted: boolean | null;
115
75
  } | null;
116
76
  draft_errors: string[];
117
- cost_usd: {
118
- grade: number | null;
119
- };
120
- tokens: {
121
- grade: import("./learning.js").Tokens | null;
122
- };
123
77
  used: {
124
- skills: {
125
- name: string;
126
- read: boolean;
127
- }[];
128
78
  workflows: {
129
79
  name: string;
130
80
  calls: number;
131
81
  failed: number;
132
82
  }[];
133
83
  };
134
- given?: import("./learning.js").NoteUsed[];
135
- read?: import("./learning.js").NoteUsed[];
136
- learned?: import("./learning.js").NoteLearned[];
137
- skills?: import("./learning.js").LearnedFile[];
138
- workflows?: import("./learning.js").LearnedFile[];
139
- run: string;
140
- state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
141
- reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
142
- detail: string | null;
143
- at: string;
144
84
  } | null>;
145
85
  /** Run `runId`'s learning diff as GET /runs/{id}/learning/diff serves it (learning-routes.ts runDiffOverStore), cut as its
146
86
  * learning is, or ApiError forbidden for a withheld run. */
@@ -161,20 +101,6 @@ export declare function servedRunDiff(deps: {
161
101
  patch: string;
162
102
  withheld?: undefined;
163
103
  })[];
164
- } | {
165
- base: string;
166
- head: null;
167
- files: ({
168
- path: string;
169
- status: string;
170
- withheld: string;
171
- patch?: undefined;
172
- } | {
173
- path: string;
174
- status: string;
175
- patch: string;
176
- withheld?: undefined;
177
- })[];
178
104
  } | {
179
105
  base: string | null;
180
106
  head: null;
@@ -0,0 +1,34 @@
1
+ import type { RunListing, Store } from "./store/store.js";
2
+ import { type ViewDeps } from "./store-view.js";
3
+ /** How often an idle lister looks again (ms). */
4
+ export declare const LISTER_IDLE_MS = 400;
5
+ export interface Lister {
6
+ /** Starts its own passes: the first at once, then one each idle time (none with an idle time of Infinity). */
7
+ start(): void;
8
+ /** Builds run `runId`'s listing over `deps` and writes it at `mark`, the mark read before the build (Runs.putListing:
9
+ * not written when a write moved it since). A listing that read a workflow held for its owner's OK puts its agent's
10
+ * folder among those each pass reads, with the statuses this build read: an approval that lands after that read is
11
+ * then seen by the next pass, whoever built the listing (a pass, or a list). Undefined for an unknown run. */
12
+ build(runId: string, mark: number, deps: ViewDeps): Promise<{
13
+ listing: RunListing | undefined;
14
+ written: boolean;
15
+ }>;
16
+ /** Resolves once a pass finds nothing it may build now: every run's listing is current, but for a held run built within
17
+ * its rebuild time. For tests and benchmarks; the server never waits on it. */
18
+ settled(): Promise<void>;
19
+ /** The server's keys or settings changed: every failed run's listing (its error words) is marked behind before this
20
+ * resolves, so the next list builds it again. */
21
+ keysChanged(): Promise<void>;
22
+ /** A person changed agent `agentId`'s learning folder (a workflow approved, retired or restored): each of its runs
23
+ * whose listing read a workflow held for the owner's OK is marked behind before this resolves, so the next list says what
24
+ * the folder says now. A change made outside the server is read by the next pass. */
25
+ learningChanged(agentId: string): Promise<void>;
26
+ /** Stops after the pass under way. */
27
+ stop(): Promise<void>;
28
+ }
29
+ /** The lister over `store`, its passes not started (Lister.start): a list may build through it before they are. */
30
+ export declare function createLister(store: Store, depsOf: () => ViewDeps, options?: {
31
+ readonly log?: (line: string, error: Error) => void;
32
+ readonly now?: () => number;
33
+ readonly idleMs?: number;
34
+ }): Lister;
@@ -0,0 +1,128 @@
1
+ import { LISTING_HELD, LISTING_KEYED } from "./store/schema.js";
2
+ import { LISTING_RETRY_MS, listingOverStore } from "./store-view.js";
3
+ /** Most rows one read of a pass reads. */
4
+ const PASS_ROWS = 32;
5
+ /** How often an idle lister looks again (ms). */
6
+ export const LISTER_IDLE_MS = 400;
7
+ /** The least time between two builds of one run a runner holds (ms). */
8
+ const HELD_REBUILD_MS = 1_000;
9
+ /** The lister over `store`, its passes not started (Lister.start): a list may build through it before they are. */
10
+ export function createLister(store, depsOf, options = {}) {
11
+ const now = options.now ?? Date.now;
12
+ /** Infinity: no pass of its own, only those settled() asks for. */
13
+ const idleMs = options.idleMs ?? LISTER_IDLE_MS;
14
+ let closing = false;
15
+ let timer;
16
+ let pass = Promise.resolve(0);
17
+ /** A held run's last build: when, and how long it took. */
18
+ const built = new Map();
19
+ /** The agents with a run whose learning holds items for the owner's OK, with their folder's statuses as last read (for an
20
+ * agent first met in a build, as that build read them). */
21
+ const folders = new Map();
22
+ /** When each run whose view failed to build last failed. */
23
+ const failed = new Map();
24
+ /** The first pass marks behind every listing that read outside its run: the keys or folders may have moved while no
25
+ * server ran. */
26
+ let relistKeys = true;
27
+ const say = (what, error) => options.log?.(what, error instanceof Error ? error : new Error(String(error)));
28
+ /** Lister.build: the one build of a listing, a pass's or a list's. */
29
+ async function build(id, mark, deps) {
30
+ // The folder statuses this build read, by agent: the baseline a later pass compares against, never a read made after
31
+ // it, which a person's approval landing before this listing's write would already hold.
32
+ const read = new Map();
33
+ const statuses = deps.statuses;
34
+ const buildDeps = statuses ? { ...deps, statuses: async (agentId) => { const seen = await statuses(agentId); if (!read.has(agentId))
35
+ read.set(agentId, seen); return seen; } } : deps;
36
+ const listing = await listingOverStore(store, id, buildDeps);
37
+ const written = listing ? await store.runs.putListing(id, mark, listing) : false;
38
+ const agentId = listing ? String(listing.item.agent_id) : "";
39
+ if (listing && listing.flags & LISTING_HELD && !folders.has(agentId))
40
+ folders.set(agentId, read.get(agentId));
41
+ return { listing, written };
42
+ }
43
+ /** One pass: what moved outside the runs' writes, then each behind row this pass may build. The rows it built. */
44
+ async function once() {
45
+ const deps = depsOf();
46
+ if (relistKeys) {
47
+ relistKeys = false;
48
+ await store.runs.relist({ flags: LISTING_HELD | LISTING_KEYED });
49
+ }
50
+ for (const [agentId, seen] of folders) {
51
+ const statuses = await deps.statuses?.(agentId);
52
+ if (statuses === seen)
53
+ continue;
54
+ folders.set(agentId, statuses);
55
+ await store.runs.relist({ flags: LISTING_HELD, agentId });
56
+ }
57
+ // PASS_ROWS rows at a time, until a read builds one or none is left. A row passed over (a held run built within its
58
+ // rebuild time, a run whose view failed to build and waits for its retry, one written meanwhile) stays behind, so
59
+ // the next read starts after every row passed over so far: such rows never hold up the rows after them.
60
+ let count = 0;
61
+ let passed = 0;
62
+ for (;;) {
63
+ const rows = await store.runs.behind({ limit: PASS_ROWS, offset: passed });
64
+ for (const { id, mark, held } of rows) {
65
+ if (closing)
66
+ break;
67
+ const last = built.get(id);
68
+ if ((held && last && now() - last.at < Math.max(HELD_REBUILD_MS, 4 * last.ms)) || (failed.get(id) ?? -Infinity) > now() - LISTING_RETRY_MS) {
69
+ passed++;
70
+ continue;
71
+ }
72
+ const start = now();
73
+ let listing;
74
+ let written;
75
+ try {
76
+ ({ listing, written } = await build(id, mark, deps));
77
+ failed.delete(id);
78
+ }
79
+ catch (error) {
80
+ failed.set(id, now());
81
+ say("run_listing_unbuilt", error);
82
+ passed++;
83
+ continue;
84
+ }
85
+ if (!written)
86
+ passed++;
87
+ if (!listing)
88
+ continue;
89
+ count++;
90
+ if (held)
91
+ built.set(id, { at: now(), ms: now() - start });
92
+ else
93
+ built.delete(id);
94
+ }
95
+ if (closing || count > 0 || rows.length < PASS_ROWS)
96
+ return count;
97
+ }
98
+ }
99
+ /** A pass after the one under way: one at a time, whoever asks. */
100
+ const turn = () => (pass = pass.then(() => (closing ? 0 : once())).catch((error) => (say("run_listing_unbuilt", error), 0)));
101
+ function next(delay) {
102
+ if (closing || !Number.isFinite(idleMs))
103
+ return;
104
+ timer = setTimeout(() => void turn().then((count) => next(count > 0 ? 0 : idleMs)), delay);
105
+ timer.unref();
106
+ }
107
+ return {
108
+ start() {
109
+ next(0);
110
+ },
111
+ build,
112
+ async settled() {
113
+ while ((await turn()) > 0)
114
+ ;
115
+ },
116
+ async keysChanged() {
117
+ await store.runs.relist({ flags: LISTING_KEYED });
118
+ },
119
+ async learningChanged(agentId) {
120
+ await store.runs.relist({ flags: LISTING_HELD, agentId });
121
+ },
122
+ async stop() {
123
+ closing = true;
124
+ clearTimeout(timer);
125
+ await pass;
126
+ },
127
+ };
128
+ }
@@ -9,7 +9,7 @@
9
9
  // alone, read at each request, never enumerable and never on the env a tool, a harness or a sandbox runs under.
10
10
  //
11
11
  // No setting: what the server holds decides. A run with a model_key spends on it alone, outside its turn too (its
12
- // subagents, learned nodes, end-of-run look-back), never on the server's key. A run without one spends on the server's
12
+ // subagents, learned nodes, end-of-run compile turn), never on the server's key. A run without one spends on the server's
13
13
  // key for its route, as before. A server that holds no key for a run's route (no AGENT_MODEL_API_KEY, nothing saved in
14
14
  // Settings) is an operator saying "callers bring their own": a start or a message that would start a turn with no key
15
15
  // to spend is 422 model_key_required, never a failure at the first model call. Spend after a run's turn ended (its key
@@ -5,7 +5,7 @@ import { withLearning } from "./learning-run.js";
5
5
  import { runLearningEnd } from "./store-reads/learning.js";
6
6
  import { heldNumber, redacted } from "./key-refusal.js";
7
7
  import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
8
- import { answersOf, asksOf, shownOf, withApprovalRows, withAsks, withBudgetRows, withOverCap } from "./run-view.js";
8
+ import { answersOf, asksOf, shownOf, stopAsked, withApprovalRows, withAsks, withBudgetRows, withOverCap } from "./run-view.js";
9
9
  import { launchOf } from "./handed-values.js";
10
10
  import { capNowOf } from "./runner/journal-kinds.js";
11
11
  import { journalRecords } from "./runner/journal-reader.js";
@@ -34,7 +34,6 @@ export async function servedTimelineRows(deps, store, runId, context, calls = fa
34
34
  const run = await snapshot.runs.get(runId);
35
35
  const ended = run ? FINAL_STATES.includes(run.state) : false;
36
36
  const records = await journalRecords(snapshot.readJournal(runId), context);
37
- const final = run?.state === "stopped" || run?.state === "failed" ? run.state : undefined;
38
37
  // A question the agent asked (ask_person) and waits on: its waiting row after the call's result (run-view.ts withAsks), as
39
38
  // the run's view carries it and main's served Timeline did, so the console's "The agent asks" box reads that question,
40
39
  // never an earlier wait's words.
@@ -44,6 +43,9 @@ export async function servedTimelineRows(deps, store, runId, context, calls = fa
44
43
  // Over is not final: an agentic run a person stopped is final in the store but reads running in its view (readRun: its
45
44
  // turn is over, the run can go on), and its usage row says what it has cost so far there, so here too.
46
45
  const view = await readRun(snapshot, runId, context);
46
+ // And every call still waiting once a stop is asked and not yet taken, as the run's view reads it (stopAsked).
47
+ const final = run?.state === "stopped" || run?.state === "failed" ? run.state
48
+ : stopAsked(view, run, await snapshot.commands(runId, 0)) ? "stopped" : undefined;
47
49
  const options = { redact, settled: ended, ended: view ? view.state !== "running" : false, ...(calls ? { calls: { result: CALL_RESULT_CHARS, redact: (text) => redacted(text, values, CALL_RESULT_CHARS), held: (value) => heldNumber(value, values) } } : {}) };
48
50
  const timeline = await wholeAnswers(snapshot, runId, context, await runTimeline(snapshot, runId, context, options), options, wholeAnswerFor(values));
49
51
  // A run whose booked spend passed its cap says so, by how much, after its usage row (run-view.ts withOverCap, as main's
@@ -58,7 +60,7 @@ export async function servedTimelineRows(deps, store, runId, context, calls = fa
58
60
  const receipts = await decisionsOverStore(snapshot, runId, context).catch(() => null);
59
61
  const decisionShown = { redact: (text) => redacted(text, values), hold: 6 * values.reduce((most, value) => Math.max(most, value.length), 0) + 16 };
60
62
  const own = receipts === null || receipts.length ? withDecisions(rows, receipts, decisionShown, { ended }) : rows;
61
- // The run's learning end, once its learning was proposed, merged or dropped (runLearningEnd).
63
+ // The run's learning end, once its learning merged or dropped (runLearningEnd).
62
64
  const end = await runLearningEnd(snapshot, runId);
63
65
  // Each trigger the rows name, read once for this read: its name now, or none for one gone.
64
66
  const names = new Map();
@@ -0,0 +1,97 @@
1
+ import type { Context } from "@earendil-works/chord/context";
2
+ import { type ServedTimelineDeps } from "./run-timeline-served.js";
3
+ import { type ApprovalAnswer } from "./run-view.js";
4
+ import type { Store } from "./store/store.js";
5
+ import { type EntryLike, type TimelineEvent } from "./timeline/index.js";
6
+ /** The most spans one read serves: the run's first, in the order they started. `dropped` counts the rest. */
7
+ export declare const TRACE_SPANS_MAX = 2000;
8
+ /** `reasoning`: the thinking tokens among `output`, where the provider reports them. */
9
+ export type TraceTokens = {
10
+ input: number;
11
+ cache_read: number;
12
+ cache_write: number;
13
+ output: number;
14
+ reasoning?: number;
15
+ };
16
+ /** How a span ended. `waiting`: a tool call held for its owner's approval, which has not run. `running`: a tool call
17
+ * with no result yet. `refused`: a call refused before it ran (a deny). `interrupted`: a request or a call cut before
18
+ * its end, or a call whose approval was withdrawn with its run. A model request is a span once it answered, so it is
19
+ * never waiting or running. */
20
+ export type TraceStatus = "ok" | "failed" | "refused" | "interrupted" | "waiting" | "running";
21
+ export type TraceSpan = {
22
+ /** The span's id in this trace: stable across reads of the run. */
23
+ id: string;
24
+ kind: "model" | "tool";
25
+ /** The span this one ran under: a tool call's, the model request that called it, or the call it nested in; a subagent's
26
+ * model request's, the call that started the subagent. Null at the top. */
27
+ parent_id: string | null;
28
+ /** A model request's model, as its answer names it (a decision's, the model its provider answered with, else the
29
+ * provider); a tool call's tool. */
30
+ name: string;
31
+ /** The subagent the span ran in, as the Timeline labels it; a workflow decision's node. */
32
+ agent_label: string | null;
33
+ started_at: string;
34
+ /** Null while a tool call runs or waits, and for a span whose end the record does not keep (a request with no
35
+ * duration, a call cut with no result). */
36
+ ended_at: string | null;
37
+ status: TraceStatus;
38
+ /** A model request's stop reason, as pi names it (`stop`, `toolUse`, `length`, `error`, `aborted`). Null on a tool call. */
39
+ stop_reason: string | null;
40
+ /** A model request's tokens: `input` not read from cache, `cache_read`, `cache_write`, `output`. A decision's receipt
41
+ * keeps its input whole, so all of it is `input`. Null when the answer reported none (a cut request), and on a tool call. */
42
+ tokens: TraceTokens | null;
43
+ /** A model request's cost; a tool call's, the sum of the charges booked under it. Null when it is not known (a cut
44
+ * request, a charge of an unknown amount, a request whose run's cost is its booking's: `model_requests`), and on a
45
+ * call nothing was charged under (`charged`). */
46
+ usd: number | null;
47
+ /** Whether anything was charged under a tool call (a browser session's time, a paid tool's fee): `usd` is their sum.
48
+ * False on a model request. */
49
+ charged: boolean;
50
+ /** A workflow decision's request (a judge's, a route's, a verify's), which has a cost of its own whatever
51
+ * `model_requests` says of the run's other requests. False on every other span. */
52
+ decision: boolean;
53
+ /** A tool call whose tool has no price set: it ran outside the run's cost. */
54
+ not_metered: boolean;
55
+ /** The tool call's id, as its Timeline rows carry it. Null on a model request. */
56
+ tool_use_id: string | null;
57
+ input_preview: string | null;
58
+ result_preview: string | null;
59
+ result_size_bytes: number | null;
60
+ };
61
+ export type RunTrace = {
62
+ run_id: string;
63
+ /** What the run's record keeps of its model requests. `priced`: each is a span with its tokens and its cost.
64
+ * `tokens_only`: a workflow run. Each model node's request is a span with its tokens and no cost (the run's cost is
65
+ * its booking's); each decision is a span with its own cost. `not_recorded`: the harness's record keeps no request,
66
+ * so the spans are its tool calls alone. */
67
+ model_requests: "priced" | "tokens_only" | "not_recorded";
68
+ spans: TraceSpan[];
69
+ /** Spans left out past TRACE_SPANS_MAX. */
70
+ dropped: number;
71
+ };
72
+ /** What came of a call's approval, by the call's id: `decision` absent while it still waits; `answered_at`, when it was
73
+ * answered or withdrawn, where the journal says. */
74
+ export type TraceApprovals = ReadonlyMap<string, {
75
+ decision?: ApprovalAnswer["decision"];
76
+ answered_at?: string;
77
+ }>;
78
+ /** The approvals of a run's calls, from its journal's asks and answers (run-view.ts asksOf, answersOf), as its served
79
+ * Timeline reads them. `final`: the run's state where it is stopped or failed, whose end its journal may not hold. */
80
+ export declare function traceApprovals(entries: readonly {
81
+ kind?: string;
82
+ data?: unknown;
83
+ }[], final?: "stopped" | "failed"): TraceApprovals;
84
+ /** The spans of a run whose served Timeline rows are `rows` and whose journal entries are `entries` (as the store keeps
85
+ * them: runEntries). `redact`: the run's cut, for the one text taken from an entry (a model's name); every other word is
86
+ * a row's, cut already. `approvals`: what came of each call that asked for one (traceApprovals): how such a call ended
87
+ * is read from there, never from its rows, which the Timeline rewords while it waits. `decisions`: a workflow run's
88
+ * decision receipts (store-reads/decisions.ts), each a model request of its own: a judge's, a route's, a verify's. */
89
+ export declare function traceSpans(rows: readonly TimelineEvent[], entries: readonly EntryLike[], options?: {
90
+ redact?: (text: string) => string;
91
+ approvals?: TraceApprovals;
92
+ decisions?: readonly Record<string, unknown>[];
93
+ }): Pick<RunTrace, "model_requests" | "spans" | "dropped">;
94
+ /** Run `runId`'s trace as served: its spans over its served Timeline rows and its journal, the model's name through the
95
+ * run's cut. A run withheld (its sign-in can't be read back here) is refused (403), as its graph and its files are:
96
+ * none of its words is served, and an empty trace would read as a run that did nothing. */
97
+ export declare function servedRunTrace(deps: ServedTimelineDeps, store: Store, runId: string, context: Context): Promise<RunTrace>;