@parcha/agentrun-serve 0.0.0-bootstrap.0 → 0.1.0-beta.29

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 (229) hide show
  1. package/CHANGELOG.md +560 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/README.md +1724 -0
  5. package/dist/adapters.d.ts +205 -0
  6. package/dist/adapters.js +459 -0
  7. package/dist/agents.d.ts +124 -0
  8. package/dist/agents.js +302 -0
  9. package/dist/app.d.ts +7 -0
  10. package/dist/app.js +324 -0
  11. package/dist/bound-files.d.ts +4 -0
  12. package/dist/bound-files.js +164 -0
  13. package/dist/box/record.d.ts +6 -0
  14. package/dist/box/record.js +41 -0
  15. package/dist/box/sweep.d.ts +53 -0
  16. package/dist/box/sweep.js +193 -0
  17. package/dist/box-image.d.ts +98 -0
  18. package/dist/box-image.js +283 -0
  19. package/dist/box-relay.d.ts +42 -0
  20. package/dist/box-relay.js +222 -0
  21. package/dist/boxes.d.ts +54 -0
  22. package/dist/boxes.js +182 -0
  23. package/dist/cap.d.ts +224 -0
  24. package/dist/cap.js +721 -0
  25. package/dist/catalog.d.ts +20 -0
  26. package/dist/catalog.js +53 -0
  27. package/dist/cli.d.ts +2 -0
  28. package/dist/cli.js +167 -0
  29. package/dist/coding-tools.d.ts +31 -0
  30. package/dist/coding-tools.js +81 -0
  31. package/dist/console/THIRD-PARTY-NOTICES.txt +1141 -0
  32. package/dist/console/assets/index-BN7oVcO4.js +445 -0
  33. package/dist/console/assets/index-By-jkqki.css +1 -0
  34. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  35. package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
  36. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
  37. package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
  38. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
  39. package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
  40. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
  41. package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
  42. package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  43. package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
  44. package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
  45. package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
  46. package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
  47. package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  48. package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
  49. package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
  50. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  51. package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
  52. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
  53. package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
  54. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
  55. package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
  56. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
  57. package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
  58. package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
  59. package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
  60. package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
  61. package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
  62. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
  63. package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
  64. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
  65. package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
  66. package/dist/console/index.html +15 -0
  67. package/dist/daytona-api.d.ts +21 -0
  68. package/dist/daytona-api.js +101 -0
  69. package/dist/decision-rows.d.ts +11 -0
  70. package/dist/decision-rows.js +116 -0
  71. package/dist/decisions.d.ts +94 -0
  72. package/dist/decisions.js +184 -0
  73. package/dist/effort-guidance.d.ts +5 -0
  74. package/dist/effort-guidance.js +14 -0
  75. package/dist/environment.d.ts +5 -0
  76. package/dist/environment.js +11 -0
  77. package/dist/errors.d.ts +72 -0
  78. package/dist/errors.js +66 -0
  79. package/dist/exa-keyless.d.ts +35 -0
  80. package/dist/exa-keyless.js +202 -0
  81. package/dist/fetch-page.d.ts +114 -0
  82. package/dist/fetch-page.js +182 -0
  83. package/dist/files.d.ts +60 -0
  84. package/dist/files.js +153 -0
  85. package/dist/grade.d.ts +96 -0
  86. package/dist/grade.js +348 -0
  87. package/dist/graph-view.d.ts +100 -0
  88. package/dist/graph-view.js +212 -0
  89. package/dist/harness-app.d.ts +38 -0
  90. package/dist/harness-app.js +626 -0
  91. package/dist/harness.d.ts +53 -0
  92. package/dist/harness.js +74 -0
  93. package/dist/home-path.d.ts +27 -0
  94. package/dist/home-path.js +78 -0
  95. package/dist/host-tools.d.ts +20 -0
  96. package/dist/host-tools.js +140 -0
  97. package/dist/host.d.ts +39 -0
  98. package/dist/host.js +81 -0
  99. package/dist/hosted-search.d.ts +27 -0
  100. package/dist/hosted-search.js +129 -0
  101. package/dist/import-sources.d.ts +104 -0
  102. package/dist/import-sources.js +629 -0
  103. package/dist/import-summary.d.ts +25 -0
  104. package/dist/import-summary.js +75 -0
  105. package/dist/import-worker.d.ts +26 -0
  106. package/dist/import-worker.js +41 -0
  107. package/dist/import.d.ts +145 -0
  108. package/dist/import.js +1221 -0
  109. package/dist/index.d.ts +7 -0
  110. package/dist/index.js +6 -0
  111. package/dist/key-check.d.ts +36 -0
  112. package/dist/key-check.js +108 -0
  113. package/dist/key-refusal.d.ts +51 -0
  114. package/dist/key-refusal.js +187 -0
  115. package/dist/learn/check.d.ts +99 -0
  116. package/dist/learn/check.js +259 -0
  117. package/dist/learn/grade.d.ts +79 -0
  118. package/dist/learn/grade.js +433 -0
  119. package/dist/learn/index.d.ts +7 -0
  120. package/dist/learn/index.js +11 -0
  121. package/dist/learn/invisible.d.ts +5 -0
  122. package/dist/learn/invisible.js +42 -0
  123. package/dist/learn/notes.d.ts +59 -0
  124. package/dist/learn/notes.js +146 -0
  125. package/dist/learn/reflect.d.ts +49 -0
  126. package/dist/learn/reflect.js +167 -0
  127. package/dist/learn/secrets.d.ts +18 -0
  128. package/dist/learn/secrets.js +111 -0
  129. package/dist/learn/skills.d.ts +84 -0
  130. package/dist/learn/skills.js +198 -0
  131. package/dist/learning-routes.d.ts +196 -0
  132. package/dist/learning-routes.js +609 -0
  133. package/dist/learning-run.d.ts +304 -0
  134. package/dist/learning-run.js +797 -0
  135. package/dist/learning-words.d.ts +73 -0
  136. package/dist/learning-words.js +171 -0
  137. package/dist/learning.d.ts +377 -0
  138. package/dist/learning.js +801 -0
  139. package/dist/llm.d.ts +40 -0
  140. package/dist/llm.js +37 -0
  141. package/dist/llms.txt +37 -0
  142. package/dist/mcp-servers.d.ts +115 -0
  143. package/dist/mcp-servers.js +445 -0
  144. package/dist/mcp.d.ts +51 -0
  145. package/dist/mcp.js +392 -0
  146. package/dist/model.d.ts +184 -0
  147. package/dist/model.js +484 -0
  148. package/dist/monid.d.ts +74 -0
  149. package/dist/monid.js +277 -0
  150. package/dist/openapi/agentrun-v2.openapi.json +4805 -0
  151. package/dist/openapi.d.ts +10 -0
  152. package/dist/openapi.js +1417 -0
  153. package/dist/owner.d.ts +55 -0
  154. package/dist/owner.js +222 -0
  155. package/dist/packs.d.ts +71 -0
  156. package/dist/packs.js +180 -0
  157. package/dist/page.d.ts +32 -0
  158. package/dist/page.js +133 -0
  159. package/dist/paid-calls.d.ts +46 -0
  160. package/dist/paid-calls.js +110 -0
  161. package/dist/pause.d.ts +68 -0
  162. package/dist/pause.js +97 -0
  163. package/dist/pdf-pages.d.ts +44 -0
  164. package/dist/pdf-pages.js +147 -0
  165. package/dist/place.d.ts +46 -0
  166. package/dist/place.js +105 -0
  167. package/dist/print.d.ts +20 -0
  168. package/dist/print.js +29 -0
  169. package/dist/propose.d.ts +38 -0
  170. package/dist/propose.js +82 -0
  171. package/dist/quiet-sqlite-warning.d.ts +1 -0
  172. package/dist/quiet-sqlite-warning.js +14 -0
  173. package/dist/request-start.d.ts +14 -0
  174. package/dist/request-start.js +226 -0
  175. package/dist/result.d.ts +3 -0
  176. package/dist/result.js +5 -0
  177. package/dist/rows.d.ts +46 -0
  178. package/dist/rows.js +121 -0
  179. package/dist/run-box.d.ts +134 -0
  180. package/dist/run-box.js +440 -0
  181. package/dist/run-manifest.d.ts +27 -0
  182. package/dist/run-manifest.js +60 -0
  183. package/dist/runnable.d.ts +80 -0
  184. package/dist/runnable.js +162 -0
  185. package/dist/runs.d.ts +840 -0
  186. package/dist/runs.js +2279 -0
  187. package/dist/secret-cut.d.ts +27 -0
  188. package/dist/secret-cut.js +109 -0
  189. package/dist/secrets.d.ts +50 -0
  190. package/dist/secrets.js +140 -0
  191. package/dist/server-lock.d.ts +44 -0
  192. package/dist/server-lock.js +140 -0
  193. package/dist/server.d.ts +626 -0
  194. package/dist/server.js +1756 -0
  195. package/dist/sessions.d.ts +4 -0
  196. package/dist/sessions.js +105 -0
  197. package/dist/skills.d.ts +31 -0
  198. package/dist/skills.js +68 -0
  199. package/dist/stats.d.ts +101 -0
  200. package/dist/stats.js +82 -0
  201. package/dist/tool-keys.d.ts +151 -0
  202. package/dist/tool-keys.js +273 -0
  203. package/dist/tool-plane.d.ts +143 -0
  204. package/dist/tool-plane.js +242 -0
  205. package/dist/tools.d.ts +147 -0
  206. package/dist/tools.js +253 -0
  207. package/dist/turn-end.d.ts +23 -0
  208. package/dist/turn-end.js +14 -0
  209. package/dist/turns.d.ts +34 -0
  210. package/dist/turns.js +202 -0
  211. package/dist/uploads.d.ts +104 -0
  212. package/dist/uploads.js +474 -0
  213. package/dist/usage.d.ts +29 -0
  214. package/dist/usage.js +58 -0
  215. package/dist/validate.d.ts +55 -0
  216. package/dist/validate.js +175 -0
  217. package/dist/web-fetch.d.ts +64 -0
  218. package/dist/web-fetch.js +262 -0
  219. package/dist/web-search.d.ts +54 -0
  220. package/dist/web-search.js +136 -0
  221. package/dist/webhooks.d.ts +182 -0
  222. package/dist/webhooks.js +487 -0
  223. package/dist/workspace-paths.d.ts +33 -0
  224. package/dist/workspace-paths.js +104 -0
  225. package/dist/workspace.d.ts +88 -0
  226. package/dist/workspace.js +369 -0
  227. package/launcher/agentrun-serve +109 -0
  228. package/package.json +96 -1
  229. package/skills/agentrun-serve/SKILL.md +128 -0
package/dist/runs.d.ts ADDED
@@ -0,0 +1,840 @@
1
+ import { type ChildProcess } from "node:child_process";
2
+ import { type Revision, type RevisionKind, type RunRow } from "@parcha/pi-durable-agent";
3
+ import { type RunMetrics, type TimelineEvent } from "@parcha/pi-durable-agent/timeline";
4
+ import type { RunNotice, WEBHOOK_EVENTS } from "./webhooks.js";
5
+ import { type AgentEntry, type Agents } from "./agents.js";
6
+ import { type DaytonaApi } from "./daytona-api.js";
7
+ import { type Learning, type LearningMode, type LearningReason, type LearningState } from "./learning.js";
8
+ import { LearningRuns, type Reflect } from "./learning-run.js";
9
+ import { type BoxHost, type Quarantine } from "./box/sweep.js";
10
+ import { type Tier } from "./model.js";
11
+ import { type Plane, type Tooling, type ToolSettingsMap } from "./tool-plane.js";
12
+ import { type Page, RowLog } from "./rows.js";
13
+ import { type Json } from "./validate.js";
14
+ import { Turns } from "./turns.js";
15
+ import { type StoredKeys } from "./secrets.js";
16
+ import { type Place } from "./place.js";
17
+ import type { BoxProvider } from "@parcha/pi-transport";
18
+ import type { Emitted } from "./webhooks.js";
19
+ export type Status = "queued" | "working" | "paused" | "input_required" | "completed" | "failed" | "cancelled";
20
+ export type State = "working" | "waiting" | "idle";
21
+ export declare const STATUSES: readonly Status[];
22
+ type RunMeta = {
23
+ title: string;
24
+ created_at: string;
25
+ /** The run's input: an agentic run's first message is its `content`, a workflow run's input is the whole of it. */
26
+ input?: Json;
27
+ effort?: string;
28
+ max_cost_usd?: number;
29
+ error?: {
30
+ code: string;
31
+ message: string;
32
+ details?: {
33
+ reason: string;
34
+ };
35
+ };
36
+ /** A workflow run's output, once it completed. */
37
+ output?: unknown;
38
+ /** A workflow run that escalated: what a person is to look at. Its time is the run's saved end, read with it. */
39
+ review?: SavedReview;
40
+ /** Where the run stood when its turn was stopped: the person's last message, by its timeline row's id (its store
41
+ * entry's), or the root conversation's place 0 before any. It stays stopped until a message newer than that is shown. */
42
+ stopped_at?: string;
43
+ /** A run stopped by an older server: how many messages the person had sent then. Read only when `stopped_at` is not. */
44
+ stopped_after?: number;
45
+ /** What its newest process took its thinking level from (app.ts's thinkingOf), as its environment had them: `effort`,
46
+ * the run's effort, and `host`, the host's AGENT_THINKING. Absent for a process an older server started. */
47
+ launch_thinking?: {
48
+ effort?: string;
49
+ host?: string;
50
+ };
51
+ /** Its tools' providers, resolved at its first launch and kept for its life (tool-plane.ts). */
52
+ tool_plane?: Plane;
53
+ /** Where it runs, as its start resolved it (place.ts): its process reads it. Absent for a run an older server started,
54
+ * which ran on the runner. */
55
+ place?: Place;
56
+ /** Where the run's learning stands (learning.ts); absent for a run that does not learn. */
57
+ learning?: Learning;
58
+ /** The run's end-of-run turn, saved before it is asked. */
59
+ reflect?: Reflect;
60
+ /** A run whose cost was unknown when it ended: the sum of its charges whose cost is known, and how many have none
61
+ * (costsofar/1), as its view said then, so a list row read from the store says it too. */
62
+ cost_so_far?: SoFar;
63
+ };
64
+ type RunError = {
65
+ code: string;
66
+ message: string;
67
+ retryable: boolean;
68
+ details?: {
69
+ reason: string;
70
+ };
71
+ };
72
+ /** Why an escalated workflow run waits for a person: the escalation's kind, the escalate node's label, its summary,
73
+ * and when the run ended (`at`, the run's `ended_at`). */
74
+ export type RunReview = {
75
+ kind: string | null;
76
+ node: string | null;
77
+ reason: string;
78
+ at: string;
79
+ };
80
+ /** A review as serve.json keeps it: `at` is not kept, as it is the run's saved end, which the store stamps. */
81
+ type SavedReview = Omit<RunReview, "at">;
82
+ /** One run as this server holds it. */
83
+ /** A run's answer or output as a view served it: `out`, redacted from `input` over the held values whose digest is `keys`. */
84
+ type Served = {
85
+ keys: string;
86
+ input: unknown;
87
+ out: unknown;
88
+ };
89
+ export type Run = {
90
+ id: string;
91
+ /** The values of the secrets each launch handed its process: what its errors never show, a key rotated since included. */
92
+ handed?: Set<string>;
93
+ /** What a view last served of its answer and its workflow output (runs.ts servedOnce), with what it was made from. */
94
+ served?: {
95
+ answer?: Served;
96
+ output?: Served;
97
+ };
98
+ agentId: string;
99
+ kind: RevisionKind;
100
+ revision: string;
101
+ /** The harness its revision names (pi when it names none, or its revision is gone). */
102
+ harness: string;
103
+ /** The newest store entry the run has shown. */
104
+ lastEntry?: number;
105
+ /** What the live path's rows keep served (keepCommitted), for a learning row shown between its snapshots. */
106
+ keep?: (id: string) => boolean;
107
+ /** What its pinned revision's tools resolve from (tool-plane.ts), resolved again at each launch. */
108
+ tooling?: Tooling;
109
+ /** Imported history (`agentrun-serve import`): the source it was run in, and its id there. It takes no message, and a
110
+ * stop or a cancel moves nothing. */
111
+ imported?: {
112
+ source: string;
113
+ session: string;
114
+ };
115
+ /** The revision's number among its agent's. */
116
+ version: number;
117
+ dir: string;
118
+ meta: RunMeta;
119
+ log: RowLog;
120
+ /** The run's rows as they come in (before the log names them), with each `ask_person` answer's waiting row. */
121
+ rows: TimelineEvent[];
122
+ /** The person's messages the run took, and how each one's turn ended (turns.ts): its end is read from them. */
123
+ turns: Turns;
124
+ /** The whole text of each assistant message of its end-of-run turn, by store entry: what the turn answered, whose
125
+ * notes learning reads (learning-run.ts). */
126
+ turnText?: Map<number, string>;
127
+ child?: ChildProcess;
128
+ /** The pid of a run process an earlier server started that still serves the run: supervised by its run.json. */
129
+ orphan?: number;
130
+ /** Adopted with a saved stop: its first snapshot is checked once, and a turn still working is aborted. */
131
+ finishStop?: boolean;
132
+ /** A completed run opening again for a follow-up: every follow-up meanwhile waits for this one, never a second. */
133
+ reopening?: Promise<void>;
134
+ /** A follow-up to a run whose turn had ended is on its way: a launch it makes opens the run for it (FOLLOW_UP_OPEN_ENV). */
135
+ followUpOpen?: true;
136
+ feed?: AbortController;
137
+ /** An agentic run's turn is running; a workflow run's process serves. */
138
+ working: boolean;
139
+ /** Messages this server sent the run that its rows do not show yet. */
140
+ submitted: number;
141
+ /** The user_message rows the run has shown, by id: one shown for the first time is a submitted message arriving. */
142
+ users: Set<string>;
143
+ /** The rows the live path has shown as live, by id, over every connection to the run's door. */
144
+ live: Set<string>;
145
+ cancel: boolean;
146
+ /** Set when the run has answered or failed and is being let go; the outcome it gets. */
147
+ finishing?: Status;
148
+ /** A stop on its way: from its mark to its abort's answer, or a server's abort of a saved stop's turn that outlived the
149
+ * server before it (finishStop). The abort withdraws every input queued behind that turn, so a message meanwhile waits
150
+ * for it (message). */
151
+ stopping?: true;
152
+ endedAt?: string;
153
+ outcome?: Status;
154
+ error?: RunError;
155
+ /** The cost the store recorded when it carried the run back; null when it recorded none (unknown). */
156
+ costUsd?: number | null;
157
+ /** A workflow run's decisions' cost, from its receipts once its end is read: null when one is unknown. */
158
+ decisionCost?: number | null;
159
+ /** The same decisions, apart: the sum of the costs that are known, and how many are not. */
160
+ decisionsPriced?: {
161
+ known: number;
162
+ unpriced: number;
163
+ };
164
+ /** A workflow run's decision rows, from its released store: its timeline shows one row each (decision-rows.ts). Null
165
+ * when they cannot be read: its timeline's usage row then reads unknown. */
166
+ decisions?: Record<string, unknown>[] | null;
167
+ /** How many of a workflow run's llm calls' answers its node log held when its rows were last read: their cost is in its
168
+ * rows (each a REQUEST_COST entry, committed before its answer is logged), so its graph counts only the later ones. */
169
+ llmRead?: number;
170
+ /** What every conversation of its store says it used, as the settle that ends it read them. */
171
+ metrics?: RunMetrics;
172
+ relaunches: number;
173
+ /** Its newest launch has not reported back: its mark (RUN_LAUNCHING) is on disk. */
174
+ launching?: boolean;
175
+ /** Its files being copied into its work/ before its first launch, until they are: nothing launches it meanwhile (a
176
+ * request that would waits for it), and nothing but a cancel settles it. */
177
+ preparing?: Promise<void>;
178
+ settled: boolean;
179
+ settling?: Promise<void>;
180
+ /** The newest write of its serve.json: one at a time, in order. */
181
+ saving?: Promise<void>;
182
+ /** Settles of this run not yet done: while any is, nothing starts its process again. */
183
+ settles: number;
184
+ updatedAt: string;
185
+ /** Its own door token (RUN_DOOR_TOKEN), once read or made; absent for a run an older server started, whose door takes
186
+ * the server-wide one. */
187
+ doorToken?: string;
188
+ /** A remote box's making and seed, asked by the run's process through the relay: one at a time. */
189
+ boxing?: Promise<{
190
+ id: string;
191
+ made: boolean;
192
+ }>;
193
+ /** Its remote box's newest pull: a read of its files waits for it. */
194
+ pulling?: Promise<void>;
195
+ /** It stood waiting for the person when last marked: a turn's end is the change into that. */
196
+ waited?: boolean;
197
+ };
198
+ /** The waiting row after each answered `ask_person` call, which the timeline module does not know. The question comes
199
+ * from the call's row, whose label this module registers. */
200
+ export declare function withAsks(rows: readonly TimelineEvent[]): TimelineEvent[];
201
+ /** The row that says a run's booked spend passed its cap, and by how much, after its usage row: a request's cost is
202
+ * booked once it answers, and one carrying a native web search is held at an allowance, not a bound (cap.ts), so a run
203
+ * can pass its cap by its last request. The next request is then refused, and the run ends spend_cap_reached. */
204
+ export declare function withOverCap(rows: TimelineEvent[], cap: number | undefined): TimelineEvent[];
205
+ /** What a run waits on, as `pending` says it (one field for every kind; a tool call waiting on approval is another):
206
+ * the question a waiting run asked, read from its last meaningful row (withAsks' waiting row), the same row its
207
+ * status reads, never from a scan of its timeline. */
208
+ type Pending = {
209
+ kind: "question";
210
+ question: string;
211
+ asked_at: string;
212
+ } | null;
213
+ /** The run's cost from its usage row: null when a response's cost is unknown, 0 before any request. */
214
+ export declare const costOf: (rows: readonly TimelineEvent[]) => number | null;
215
+ /** What a run's paid tools charged, from the same rows its cost is read from: each charge's line carries it (`usage` on a
216
+ * `phase` row); null when one is unknown. A call still marked, in flight or cut, is no charge here. */
217
+ export declare const toolCostOf: (rows: readonly TimelineEvent[]) => number | null;
218
+ /** A run's cost for its views: its usage row's, else what the store kept when it carried the run back (0 before any
219
+ * request). A usage row that says unknown, or says nothing, stays unknown: what the store kept dates from before a
220
+ * follow-up. */
221
+ export declare function costView(rows: readonly TimelineEvent[], stored: number | null | undefined, decisions?: number | null): number | null;
222
+ /** What a run whose cost is unknown has cost so far (costsofar/1): the sum of its charges whose cost is known, and how many
223
+ * have none, from its usage row, plus a workflow's decisions (`decisions`: their known sum and how many are not known;
224
+ * null when they could not be read, which says nothing). Undefined while the cost is known, when the row says neither
225
+ * (an older run's), or when a workflow's decisions are unreadable. No ceiling is claimed. */
226
+ export type SoFar = {
227
+ so_far_usd: number;
228
+ unpriced: number;
229
+ };
230
+ export declare function soFarOf(rows: readonly TimelineEvent[], decisions?: {
231
+ known: number;
232
+ unpriced: number;
233
+ } | null): SoFar | undefined;
234
+ /** Whether the turn a stop ended is still where the run stands: no message shown is newer than the stop's. By order,
235
+ * never by a count or by the stopped message itself, which a compaction can take off the rows. */
236
+ export declare const stoppedAt: (meta: {
237
+ stopped_at?: string;
238
+ stopped_after?: number;
239
+ }, rows: readonly TimelineEvent[]) => boolean;
240
+ /** What a stop keeps of where the run stands: the person's last message, by its id, or the place before any. */
241
+ export declare const stopMark: (rows: readonly TimelineEvent[]) => {
242
+ stopped_at: string;
243
+ };
244
+ /** The rows a snapshot that no longer holds them leaves served: those committed entries made. A row any connection
245
+ * showed live is not one (`live` holds them for the run), so a live row that ended while the door was away goes. */
246
+ export declare function keepCommitted(live: Set<string>, rows: readonly TimelineEvent[], isLive: (id: string) => boolean): (id: string) => boolean;
247
+ /** A run's status and state, by the contract's table. */
248
+ export declare function statusOf(run: Run): {
249
+ status: Status;
250
+ state: State;
251
+ };
252
+ /** The waits between carry backs that found the store busy, and a hook called at each such refusal. */
253
+ export type CarryBackRetry = {
254
+ delaysMs?: readonly number[];
255
+ onBusy?: (runId: string, attempt: number) => void;
256
+ };
257
+ /** How a run is asked to start: its input and title, its effort and cap, and what puts its files in its work/. */
258
+ export type StartOptions = {
259
+ input: Json;
260
+ title: string;
261
+ place: Place;
262
+ effort?: string;
263
+ maxCostUsd?: number;
264
+ inputs?: (work: string) => Promise<unknown>;
265
+ };
266
+ /** `token` is the server's own: no run's process sees it. */
267
+ /** `maxRuns`: the most runs with a live process at once; `settleRetryMs`: how often a carry back the store refused is
268
+ * tried again; `readyTimeoutMs`: how long a request to a run waits for its door (a run's first message, sent by its
269
+ * start, always waits READY_TIMEOUT_MS); `log` takes a run's start and end (print.ts). */
270
+ export type RunsOptions = {
271
+ agents: Agents;
272
+ token: string; /** The server's saved tool keys, read by name for its runs alone (secrets.ts). */
273
+ storedKeys?: StoredKeys;
274
+ documents?: string;
275
+ doorTokenFile: string;
276
+ doorToken: string; /** The test switches a run's process gets (server.ts fauxEnvOf): empty outside tests. */
277
+ fauxEnv?: NodeJS.ProcessEnv;
278
+ runBoxes?: BoxProvider; /** The server's Daytona provider, with its key: remote boxes are made, seeded, pulled and destroyed with it, here alone (box-relay.ts). */
279
+ remoteBoxes?: BoxProvider; /** Daytona's API and the same key, for what the provider does not do: a kept box's idle stop, and its wake at a start (daytona-api.ts). */
280
+ remoteApi?: DaytonaApi;
281
+ toolSettings?: () => ToolSettingsMap;
282
+ drainTimeout?: string;
283
+ carryBackRetry?: CarryBackRetry;
284
+ maxRuns?: number;
285
+ box?: {
286
+ host: BoxHost;
287
+ quarantine: Quarantine;
288
+ };
289
+ settleRetryMs?: number;
290
+ readyTimeoutMs?: number;
291
+ reflectTimeoutMs?: number;
292
+ gradeTimeoutMs?: number; /** The grader's model (`--grade-model`), before AGENTRUN_SERVE_GRADE_MODEL and the strong tier (grade.ts gradeModelOf). */
293
+ gradeModel?: string; /** How much of what a run learned its instructions hold, in bytes (`--learning-budget`, learning.ts learnedOf). */
294
+ learningBudget?: number;
295
+ log?: (event: string, fields: Record<string, string | number>) => void;
296
+ notify?: RunNotify;
297
+ learning?: LearningMode;
298
+ };
299
+ /** Told of a run's moment each time it is seen (webhooks.ts' emit, which queues each one once): a wait it reached, and an
300
+ * end once the agent store has it. `marker` names the moment (the person's turn it waits at, the end's time), the same
301
+ * when another server sees it again. It says what came of it: `unsaved`, not in the outbox on disk yet. */
302
+ export type RunNotify = (event: (typeof WEBHOOK_EVENTS)[number], run: RunNotice & {
303
+ status: Status;
304
+ }, marker: string) => Emitted;
305
+ /** The secrets a run's process is handed over its pipe (secrets.ts): every one but the server's own and the decision
306
+ * keys, which go on their own descriptor. */
307
+ export declare const RUN_SECRETS: string[];
308
+ type KeyRow = {
309
+ kind: string;
310
+ fields: readonly string[];
311
+ unlocks: readonly string[];
312
+ };
313
+ /** What of a revision decides the secrets its runs are handed, none of it a key, read once per revision (a revision
314
+ * never changes): its harness, the model it names, the tools it binds (named as its process binds them, app.ts: an
315
+ * agentic revision's `tools`, a workflow's on its model nodes and its `call` nodes), a workflow's tiers (those its model
316
+ * nodes and `llm` calls run on), and its decision providers (decisions.ts' decisionKeysFor: a workflow's decision
317
+ * nodes', providersNamed, Jev for a node that names none; an agentic revision's, none). Names only: no instruction and
318
+ * no skill. */
319
+ export type RunNeeds = {
320
+ harness: string;
321
+ model?: string;
322
+ tools: readonly string[];
323
+ tiers?: readonly Tier[];
324
+ decisionProviders: readonly string[];
325
+ };
326
+ /** `revision`'s RunNeeds. */
327
+ export declare function needsOf(revision: Revision): Promise<RunNeeds>;
328
+ /** The secrets a run of `needs` is handed over its pipe, by the keys `env` holds now: RUN_SECRETS but each field of a
329
+ * `tool` row of `rows` (TOOL_KEYS) that unlocks none of the tools the run binds; and but each model key its model does
330
+ * not need, from the host's model settings and the keys in `env`: a pi run's, its models' providers' keys or the
331
+ * gateway's (model.ts' modelKeys: its own model, or the host's of each tier it runs); codex's and claude-agent's, the
332
+ * one key their route sends for the revision's model (adapters.ts' harnessModelKeys). Read at each launch, so a key
333
+ * saved with no restart counts at the next. */
334
+ export declare function keysFor(needs: RunNeeds, env: NodeJS.ProcessEnv, rows?: readonly KeyRow[]): string[];
335
+ /** The secrets a run of `revision` is handed with the keys `env` holds (needsOf, then keysFor). */
336
+ export declare function secretsFor(revision: Revision, rows?: readonly KeyRow[], env?: NodeJS.ProcessEnv): Promise<string[]>;
337
+ /** The decision providers a run of `revision` needs keys for (needsOf). Its web tools' need, Parallel's where one
338
+ * resolves to Parallel, is its tool plane's (tool-plane.ts' handsParallel), read at each launch. */
339
+ export declare function decisionProvidersFor(revision: Revision): Promise<readonly string[]>;
340
+ /** A run's process's environment: no secret in it (they go over its pipe), nor the token by value; the AGENT_MODEL
341
+ * variables and the rest pass, and the door token goes by file. A test hook's name passes never (withoutFaux): the run
342
+ * gets one only from startServe's options. */
343
+ export declare const childEnv: (env: NodeJS.ProcessEnv, token: string) => NodeJS.ProcessEnv;
344
+ /** The line of the run process's log a failure's message is made of: its last, past any harness's own lines (a proxy's
345
+ * refusal just before a crash says nothing of why the process went). */
346
+ export declare function failureLine(log: string): string;
347
+ /** The last line of the run process's log, in words, for a failure's message. */
348
+ export declare function lastLogLine(run: Pick<Run, "dir">): Promise<string>;
349
+ export declare class Runs {
350
+ private readonly options;
351
+ private readonly runs;
352
+ /** Each workflow revision's workflow, by revision id, as a graph read it: a revision never changes. */
353
+ private readonly workflows;
354
+ /** What decides the secrets each revision's runs are handed (needsOf), by revision id: read once, from the revision the
355
+ * run is pinned to, never from a request. The keys themselves are read at each launch (keysFor). */
356
+ private readonly needs;
357
+ /** Each workflow run's last graph read whole: what a poll that met a busy store answers, marked stale. */
358
+ private readonly graphs;
359
+ private readonly adopting;
360
+ private readonly clock;
361
+ private readonly cli;
362
+ private readonly app;
363
+ private closing;
364
+ /** Set once `close` is done: the store is closed, so nothing settles after it. */
365
+ private closed;
366
+ /** Runs past the cap's check whose process is not started yet. */
367
+ private starting;
368
+ /** The memory the starts counted in `starting` reserve, in MiB. */
369
+ private startingMib;
370
+ /** This host's memory, out of which each live run reserves what its harness takes (host.ts), beside `maxRuns`. */
371
+ private readonly memory;
372
+ /** The start sweep of the boxes runs left: once, before any run opens a box (sweepOnce). */
373
+ private swept?;
374
+ /** The runs' learning (learning-run.ts): a step this file calls as a run starts, ends, settles, opens again and is
375
+ * recovered, handed what it moves of a run. */
376
+ readonly learning: LearningRuns;
377
+ constructor(options: RunsOptions);
378
+ /** A test's seam (startServe's `beforeAbort`): awaited by a stop between its mark and its abort, so a test can hold a
379
+ * stop in flight there. */
380
+ beforeAbort?: (runId: string) => Promise<void> | void;
381
+ /** A test's seam (startServe's `beforeReopenLaunch`): awaited by a reopen after the run reads open again and before its
382
+ * launch, so a test can hold a reopen there. */
383
+ beforeReopenLaunch?: (runId: string) => Promise<void> | void;
384
+ /** A test's seam (startServe's `beforeSubmit`): awaited by a message before it goes to the run's door. */
385
+ beforeSubmit?: (runId: string, content: string) => Promise<void> | void;
386
+ private get store();
387
+ /** Run `id` when this process holds it, never read from disk. */
388
+ held(id: string): Run | undefined;
389
+ /** Run `id`, read from the agent store the first time this process sees it. */
390
+ get(id: string): Promise<Run | null>;
391
+ /** One Run per run id, however many requests ask for it at once. */
392
+ private adopt;
393
+ private load;
394
+ private blank;
395
+ /** Writes the run's serve.json as it is when its turn comes; then tells learning what it now holds (the ledger's line
396
+ * once the run's learning ended). */
397
+ private saveMeta;
398
+ private record;
399
+ /** The door a live run serves, from its run.json: running, a fresh heartbeat, and a loopback address. */
400
+ private doorOf;
401
+ private storeFile;
402
+ /** The run's rows from its store, opened read-only; only once its claim is released. An agentic run's rows are its
403
+ * root conversation's; a workflow run's are its model nodes'. `atEnd`: a settle's read, which reads every
404
+ * conversation (a workflow's nodes, a harness's session) once and counts the run's metrics from all of them. */
405
+ private readStore;
406
+ /** New rows in: into the log, then the run's status, then whatever the status asks for. */
407
+ /** `keep`: rows that stay served though `rows` no longer holds them (the live path's committed rows). */
408
+ private take;
409
+ /** The run's rows into its log, as served: a workflow run's decisions and the run's learning row are the served view's
410
+ * only, never the run's own rows, which its cost and its answer are read from. */
411
+ private show;
412
+ /** A live process: the child this server started, or one an earlier server started that still serves the run. */
413
+ private live;
414
+ /** How an agentic run ends: over its cap, or as the turn of the person's newest message ended (turns.ts), once every
415
+ * message the run took has had its turn. Undefined while one is open, or when the run stopped, waits, or its turn
416
+ * ended interrupted (the run then waits for the person), or while its records name no message (a live process of an
417
+ * older server: the run's next process writes its turn's end as it opens). Never from the order of its rows, or from
418
+ * when its door said idle. A workflow run ends when its workflow does. */
419
+ private decide;
420
+ /** A run's error as a person reads it, in its error box and on its Timeline row alike: a refused key in plain words
421
+ * (plainKey), else the harness's text with no loopback address (withoutLoopback: Codex names serve's own proxy). */
422
+ private errorWords;
423
+ /** An error row as served: its summary and text in errorWords' terms. The run's own rows, which its status reads, keep
424
+ * what the harness said. */
425
+ private servedError;
426
+ /** What serve shows of a run's error text, for every run kind: no held secret (redacted, key-refusal.ts' one rule) and
427
+ * no loopback address. */
428
+ private shown;
429
+ /** A run's answer as serve serves it: no held secret, never cut (redactedAnswer). Loopback addresses stay: an answer is
430
+ * the model's own words, and a local address there can be what the person asked about. */
431
+ private servedAnswer;
432
+ /** A workflow run's output as serve serves it: each string in it as servedAnswer, its shape kept. */
433
+ private servedOutput;
434
+ /** `redact(values)` over the values `run` holds, read once per input and held value set: a console polls a run's
435
+ * view, and an answer a run was made to write can be large. The run keeps the one it served last, of each slot; a key
436
+ * saved or deleted changes the values' digest, and the next view redacts again. */
437
+ private servedOnce;
438
+ /** The timeline's redaction of `run`'s error rows and of what a tool's result shows (its summary and preview), applied
439
+ * before a row is cut (timelineOf's `redact`), so a cut never leaves the head of a key. Every such cut is within
440
+ * redacted()'s SHOWN, so its window holds. */
441
+ private redactor;
442
+ /** Every secret value `run`'s errors never show, as learning's checker holds them (learning-run.ts refused): this
443
+ * server's secrets wherever its launcher put them and the keys saved on it, what each launch handed the run, and the
444
+ * server's own tokens. */
445
+ private refusedValues;
446
+ /** A run's model error in a person's words when its provider refused the run's key (key-refusal.ts): the key its
447
+ * harness's route sends, by this server's settings and keys, and no secret's value. */
448
+ private plainKey;
449
+ /** Records the run's status as a change when it moves, and lets go of a live run that answered, failed or is over its cap. */
450
+ private refresh;
451
+ /** The test hooks startServe's options name, as a run's process and this server's own calls get them. */
452
+ private fauxEnv;
453
+ /** Let go of a live run with `outcome`: SIGTERM, after aborting its turn when it is still working. */
454
+ private finish;
455
+ /** SIGTERM to the run's process: it drains, releases the run and exits. */
456
+ private terminate;
457
+ /** Supervise a run process an earlier server started: follow its door, and settle the run once its run.json says it
458
+ * let go (released, or its lease lapsed) or the process is gone. */
459
+ private adoptProcess;
460
+ /** At start: every run the store says is running is read, supervised when its process lives, carried back when it
461
+ * already ended, and opened again when its process went before it ended. */
462
+ /** Every run's box let go that nothing owns, and every run cgroup no record names: once, before any run of this server
463
+ * starts, opens again or relaunches, so a box or cgroup being made is never swept away. */
464
+ private sweepOnce;
465
+ /** A sandbox run's box (run-box.ts), destroyed by its label: at every settle, a cancel included, and at archive. A
466
+ * remote box's work/ is pulled first, and its box goes only once that pull brought it back whole (or there is no box).
467
+ * A copy that stopped for good (an archive the extractor cannot read, a limit it cannot pass) keeps the box, said in
468
+ * the log, its lifetime bounding it, and the run ends. Any other failure at a run's end (`ending`) throws
469
+ * PullPending, and the end is tried again; at an archive it only warns, the box kept for the run's end or the next
470
+ * start's sweep. A destroy that fails only warns: the next start's sweep tries again, and the box's lifetime bounds it. */
471
+ private dropBox;
472
+ /** A remote box kept because its copy back is not whole: said in the log, and set to stop once idle, so it costs its
473
+ * disk alone until the next start's pull (which wakes it) or its lifetime. */
474
+ private keepBox;
475
+ /** What wakes run `runId`'s remote box when Daytona stopped or paused it (a class that pauses when idle, while the run
476
+ * waited for a person): how many it woke. */
477
+ private wakeOf;
478
+ /** Pulls run `run`'s remote box into its work/, after any pull already running: at a turn's end in the background (a
479
+ * failure warns, and the next pull brings it), or awaited (`strict`: a failure throws). */
480
+ private pullBox;
481
+ /** Waits for the pull run `id`'s turn's end began, if any, up to PULL_WAIT_MS: its files then show what its box wrote. */
482
+ pulled(id: string): Promise<void>;
483
+ /** Whether run `id` is one this server holds in a remote box and has not ended: the relay serves no other. */
484
+ servesBox(id: string): boolean;
485
+ /** Run `id`'s remote box, found or made and seeded: what its process asks the relay for at its first tool call. */
486
+ ensureBox(id: string): Promise<{
487
+ id: string;
488
+ made: boolean;
489
+ }>;
490
+ /** The run's box let go (archive, or its process gone after an archive): reaped by the box's own count. */
491
+ private teardown;
492
+ /** After an archive (a run's, or an agent's, which archives its runs): the box of every run now archived is let go,
493
+ * now when its process is gone, else when it exits. */
494
+ archived(): Promise<void>;
495
+ recover(): Promise<void>;
496
+ /** The run's status, state and whether its rows are all in, as one more change of its log when any of them moves. A wait
497
+ * is told each time it is seen: webhooks.ts queues each wait once, whichever server sees it first. */
498
+ private mark;
499
+ /** Tells webhooks.ts (`notify`) of a moment of the run under `marker`: a wait it reached (mark), or an end the agent store
500
+ * has (settle, persistLater, reopen). What it already queued it queues no more. */
501
+ private notice;
502
+ /** A call to run `run`'s door: with its own door token, or, for a process an older server started, the server-wide one. */
503
+ private headers;
504
+ /** Run `id`'s own door token, the one its calls to the box relay carry; none for a run it does not hold or that has none. */
505
+ relayToken(id: string): string | undefined;
506
+ /** Follow the door's events into an agentic run's rows, again after each drop while the process lives. A workflow
507
+ * run is only watched: the door's events are a root conversation's, and a workflow run has none. */
508
+ private connect;
509
+ private follow;
510
+ /** The door of a run that is not finished, starting or waking its process when it is not live. */
511
+ private ensureLive;
512
+ /** The refusal of a message to an imported run: it was run elsewhere, and is kept as history. */
513
+ private importedRefusal;
514
+ private finished;
515
+ /** Abort an agentic run's turn running now through the door, when there is one; never wakes the run. A workflow run
516
+ * has no turn: the door's abort would give it a root conversation. */
517
+ private abortTurn;
518
+ /** One request to the door of a run whose process lives, never waking it (toDoor wakes no run that is finishing): again
519
+ * while it opens or parks. `turnOrigin`: who sent a turn this request sends (learning-run.ts's REFLECT_ORIGIN), for
520
+ * the per-tool gate to take once this server has one; nothing reads it until then. */
521
+ private toLiveDoor;
522
+ private toDoor;
523
+ /** Reads what decides the secrets runs of `run`'s revision are handed (needsOf), once per revision: from `given` (a
524
+ * start's, read from the store), else from the agent store, waiting out a busy one as a run's end does. */
525
+ private pinNeeds;
526
+ private launch;
527
+ /** Writes the run's launch mark before its process is spawned: a spawn that takes the server down leaves it, and the
528
+ * next start fails the run rather than launch it again and go down with it. The file exists once the call returns,
529
+ * which a server's death does not undo; no fsync, which would hold the event loop on the disk at every launch. */
530
+ private markLaunching;
531
+ /** The run's newest launch came through with the server up: its process serves, or exited while it was watched. Its
532
+ * callers are event handlers, so a mark that cannot be removed is logged, never thrown: a throw there stops the
533
+ * server and every run on it. The mark left behind fails the run at the next start, which never launches it again. */
534
+ private reportedBack;
535
+ /** Opens the run again on its directory after its process went before the run ended: it resumes from its store. An
536
+ * agentic run whose first message never landed gets it again, under the same request id. */
537
+ private relaunch;
538
+ /** After the run's process exited, or was found gone: its rows from its released store, then, when it is over, its
539
+ * carry back. One at a time per run, and none once the run has its outcome. */
540
+ private settle;
541
+ /** `exited`: the process this server supervised exited. Exiting on an error before it released fails the run; going
542
+ * any other way before the run ended (killed, or found gone at a start) opens it again. */
543
+ private settleOnce;
544
+ /** A workflow run's carry back, `workflowCarry` of @parcha/pi-durable-agent/workflow on its released store, and its
545
+ * output when it completed; undefined while its workflow has not ended. */
546
+ private workflowEnd;
547
+ /** A workflow run's decisions' cost, from their receipts in its released store: a receipt whose cost is unknown leaves
548
+ * the run's unknown, never $0. Read at its end and again when a restarted server adopts it as ended. */
549
+ private readDecisionCost;
550
+ /** Ends the run in the agent store, once: how it ended, its cost, a line for the list and its metrics. A store held by
551
+ * another writer is tried again with backoff; past the last try the run stays unsettled, and the next start carries it back. */
552
+ private carryBack;
553
+ /** The run's metrics as the store keeps them: what its entries say it used, the effort its newest process ran at (unknown
554
+ * for one an older server started), and on a harness other than pi the model its revision names (its entries name the
555
+ * harness). A busy store throws, for the write's retries; a revision that cannot be read otherwise adds nothing. */
556
+ private storedMetrics;
557
+ /** Tries `persist` again every settleRetryMs while the server lives, until it lands. */
558
+ private persistLater;
559
+ /** How long a run's end waits for a busy store, step by step. */
560
+ private busyDelays;
561
+ /** Hears that `what` was busy for run `runId`, and says so when another try follows. */
562
+ private onBusy;
563
+ /** The run's store, read again while another connection holds it, within the same retries. */
564
+ private storeWhenFree;
565
+ /** Start a run of `revision` (number `version`) of `entry`'s agent: `startRun` in the store, then its process, then an
566
+ * agentic run's first message, `input.content`. */
567
+ /** A place for one more live run of `harness`, taken for this start (counted in `starting` and `startingMib` from
568
+ * here, so two starts at once cannot both take the last place), or 429 rate_limited; the function returned gives it
569
+ * back once the run holds it as a live run, or did not start. A place is one under the cap on the count and the
570
+ * memory a run of its harness reserves (host.ts): both must be free. A run that has ended (failed, completed,
571
+ * cancelled) still holds its place until its process exits; a start that needs that place waits for it, up to that
572
+ * process's drain and kill, never refused for a place already being given back. A harness whose one run is more than
573
+ * the whole memory for runs is refused at once, never a 429 (capabilities say so too). From the read of what is held
574
+ * to the reservation nothing awaits, so two starts at once never both take the last of it. */
575
+ private takePlace;
576
+ /** `inputs` copies the run's files into its work/ (uploads.ts), after the store made it and before its process starts. */
577
+ create(entry: AgentEntry, revision: Revision, version: number, options: StartOptions): Promise<Run>;
578
+ /** Writes the serve.json of a run being set up. When it fails, the store has the run as running and no process will
579
+ * run it: it ends failed here, never left for a later start to open with half its files. */
580
+ private setUp;
581
+ private start;
582
+ /** Copies the run's files into its work/ under the launch mark: a server that goes down while it copies leaves the
583
+ * mark, and the next start fails the run rather than run it on part of its files. Copied whole, the mark goes, and the
584
+ * launch makes its own. False when the copy failed, and the run ended so (or was cancelled meanwhile). */
585
+ private prepare;
586
+ private submit;
587
+ /** Whether the run's harness takes a message mid-turn. */
588
+ private steers;
589
+ /** One message to an agentic run, its mode chosen by the run's state (the contract's table). */
590
+ message(run: Run, content: string): Promise<{
591
+ mode: "steer" | "answer" | "follow_up";
592
+ messageId: string;
593
+ }>;
594
+ /** Waits, up to a request's deadline, while `holds` (checked every `everyMs`): else 503 `unavailable`, saying `why`. */
595
+ private waitWhile;
596
+ /** A completed agentic run that gets a follow-up opens again: the same run on its own store and session, under its
597
+ * cap, taking a place under the server's. Launched here, with no wait after the place is taken, so no start takes
598
+ * it meanwhile. An archived run, or a run of an archived agent, stays closed. */
599
+ private reopen;
600
+ /** Waits, up to a request's deadline, until a live run's rows show every message sent to it, and any rows at all: its
601
+ * record has caught up with its process. Its end, a cancel or its process going ends the wait. */
602
+ private caughtUp;
603
+ /** Abort the turn that is running; the run stays open, `input_required` and idle. A workflow run has no turn to stop. */
604
+ stop(run: Run): Promise<boolean>;
605
+ /** stop()'s mark and abort, once it took the stop. */
606
+ private stopTurn;
607
+ /** Record the cancel and signal the run. An agentic run reads `cancelled` from here on (the first end a run comes to is
608
+ * its last: nothing its turn writes later moves it), and is carried back so once its process has exited; a workflow
609
+ * run reads it once it is carried back, with how its workflow stopped. */
610
+ cancel(run: Run): Promise<boolean>;
611
+ /** Pause a workflow run (`paused` true) or resume it: the mark in its directory, which its process reads before each
612
+ * node starts. A run that has ended is not continuable. */
613
+ pause(run: Run, paused: boolean): Promise<{
614
+ run_id: string;
615
+ paused: boolean;
616
+ status: Status;
617
+ }>;
618
+ /** A workflow run's graph as it stands (graph-view.ts), live while it runs. */
619
+ graph(run: Run): Promise<{
620
+ stale: boolean;
621
+ read_at: string;
622
+ run: {
623
+ id: string;
624
+ agent: string;
625
+ revision: string;
626
+ status: string;
627
+ paused: boolean;
628
+ startedAt: string;
629
+ endedAt: string | null;
630
+ };
631
+ workflow: unknown;
632
+ graph: import("@parcha/agentrun-dsl/graph").WorkflowGraph;
633
+ nodes: Record<string, {
634
+ status: import("./graph-view.js").GraphNodeStatus;
635
+ startedAt?: string;
636
+ endedAt?: string;
637
+ branch?: string;
638
+ items?: {
639
+ index: number;
640
+ status: import("./graph-view.js").GraphNodeStatus;
641
+ executionPath: string;
642
+ label?: string;
643
+ branches?: Record<string, string>;
644
+ }[];
645
+ }>;
646
+ decisions: {
647
+ id: {} | null;
648
+ node: string | null;
649
+ executionPath: {} | null;
650
+ item: {} | null;
651
+ kind: {} | null;
652
+ provider: {} | null;
653
+ model: {} | null;
654
+ status: {} | null;
655
+ questions: {} | null;
656
+ answers: {} | null;
657
+ evidence: {};
658
+ rule: {} | null;
659
+ action: {} | null;
660
+ cost_usd: number | null;
661
+ cost_basis: {} | null;
662
+ latency_ms: {} | null;
663
+ state: {} | null;
664
+ state_truncated: boolean;
665
+ error: string | null;
666
+ images: {
667
+ token: {} | null;
668
+ ref: {} | null;
669
+ url: string | null;
670
+ }[];
671
+ }[];
672
+ effects: {
673
+ node: string | null;
674
+ executionPath: string | null;
675
+ item: number | null;
676
+ tool: string;
677
+ status: string;
678
+ input: unknown;
679
+ output: unknown;
680
+ error: string | null;
681
+ startedAt: string;
682
+ endedAt: string | null;
683
+ }[];
684
+ totals: {
685
+ cost_usd: number | null;
686
+ decisions: number;
687
+ effects: number;
688
+ elapsed_ms: number | null;
689
+ };
690
+ } | {
691
+ run: {
692
+ id: string;
693
+ agent: string;
694
+ revision: string;
695
+ status: Status;
696
+ paused: boolean;
697
+ startedAt: string;
698
+ endedAt: string | null;
699
+ };
700
+ stale: boolean;
701
+ }>;
702
+ /** How long a run's process gets after SIGTERM before SIGKILL: its drain and a second to exit. */
703
+ private killAfterMs;
704
+ /** What close() will wait on: the runs whose processes are left to finish their turn (those this server started, and
705
+ * those it adopted), and the longest it can wait on them: a kill bound for the started ones, and one more for the
706
+ * adopted ones, which it stops after them. */
707
+ stopping(): {
708
+ runs: number;
709
+ boundMs: number;
710
+ };
711
+ close(): Promise<void>;
712
+ /** A run's cost from its rows, else what the store recorded when it carried the run back. */
713
+ cost(run: Run): {
714
+ so_far_usd?: number | undefined;
715
+ unpriced?: number | undefined;
716
+ usd: number | null;
717
+ basis: string;
718
+ charge_state: null;
719
+ cap_usd: number | null;
720
+ };
721
+ /** `Run`, as the contract shows it. `known`: its stored row as the caller already has it, so nothing is read; a run
722
+ * just written has none worth reading (`{ stored: null }`: it is neither archived nor ended), and its start's answer
723
+ * must not read the store once the run exists, since a busy store would then refuse a run that runs. */
724
+ view(run: Run, known?: {
725
+ stored: RunRow | null;
726
+ }): Promise<{
727
+ created_at: string;
728
+ updated_at: string;
729
+ ended_at: string | null;
730
+ result: {
731
+ output: unknown;
732
+ final_answer: string | null;
733
+ } | null;
734
+ error: RunError | null;
735
+ review: RunReview | null;
736
+ pending: Pending;
737
+ cost: {
738
+ so_far_usd?: number | undefined;
739
+ unpriced?: number | undefined;
740
+ usd: number | null;
741
+ basis: string;
742
+ charge_state: null;
743
+ cap_usd: number | null;
744
+ };
745
+ archived_at: string | null;
746
+ imported_from: {
747
+ source: string;
748
+ session: string;
749
+ } | null;
750
+ learning: {
751
+ used?: import("./learning.js").NoteUsed[];
752
+ learned?: import("./learning.js").NoteLearned[];
753
+ pending?: import("./learning.js").NoteUsed[];
754
+ skills?: import("./learning.js").LearnedFile[];
755
+ workflows?: import("./learning.js").LearnedFile[];
756
+ state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
757
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "no_write_tool" | "tool_denied" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "screen" | "screen_down" | "grader" | "grade_failed" | null;
758
+ detail: string | null;
759
+ at: string;
760
+ } | null;
761
+ poll_after_ms: number;
762
+ last_progress_at: string | null;
763
+ effort?: string | undefined;
764
+ run_id: string;
765
+ agent_id: string;
766
+ agent_version: number;
767
+ revision: string;
768
+ kind: RevisionKind;
769
+ sha: null;
770
+ status: Status;
771
+ state: State;
772
+ title: string;
773
+ place: Place;
774
+ }>;
775
+ summary(run: Run): Promise<{
776
+ created_at: string;
777
+ ended_at: string | null;
778
+ error: RunError | null;
779
+ review: RunReview | null;
780
+ pending: Pending;
781
+ cost: {
782
+ so_far_usd?: number | undefined;
783
+ unpriced?: number | undefined;
784
+ usd: number | null;
785
+ basis: string;
786
+ charge_state: null;
787
+ cap_usd: number | null;
788
+ };
789
+ archived_at: string | null;
790
+ imported_from: {
791
+ source: string;
792
+ session: string;
793
+ } | null;
794
+ learning: ({
795
+ state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
796
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "no_write_tool" | "tool_denied" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "screen" | "screen_down" | "grader" | "grade_failed" | null;
797
+ detail: string | null;
798
+ } & Omit<{
799
+ used?: import("./learning.js").NoteUsed[];
800
+ learned?: import("./learning.js").NoteLearned[];
801
+ pending?: import("./learning.js").NoteUsed[];
802
+ skills?: import("./learning.js").LearnedFile[];
803
+ workflows?: import("./learning.js").LearnedFile[];
804
+ state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
805
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "no_write_tool" | "tool_denied" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "screen" | "screen_down" | "grader" | "grade_failed" | null;
806
+ detail: string | null;
807
+ at: string;
808
+ }, "at" | "reason" | "state" | "detail">) | null;
809
+ effort?: string | undefined;
810
+ run_id: string;
811
+ agent_id: string;
812
+ agent_version: number;
813
+ revision: string;
814
+ kind: RevisionKind;
815
+ sha: null;
816
+ status: Status;
817
+ state: State;
818
+ title: string;
819
+ }>;
820
+ /** A run's status for a list: an ended run's from its row, a running one's from the run itself. */
821
+ statusOfRow(row: RunRow): Promise<Status>;
822
+ /** A run's summary for a list. An ended run this server holds no Run for is read from its row and its serve.json alone,
823
+ * not its store; `versions` numbers its agent's revisions. */
824
+ summaryOfRow(row: RunRow, versions: Map<string, number>): Promise<Awaited<ReturnType<Runs["summary"]>>>;
825
+ /** A key was saved on this server or deleted from it: each held run's learning row shown again, cut of the keys as
826
+ * they are now (learning-run.ts shown), as its view and its lists already are from the next read on. */
827
+ keysChanged(): void;
828
+ /** A held run's learning, in short (learning-run.ts heldLearning). */
829
+ heldLearning(runId: string): {
830
+ state: LearningState;
831
+ reason: LearningReason | null;
832
+ } | null | undefined;
833
+ /** The timeline from change `after`, held up to `waitMs` for a change when there is none. */
834
+ page(run: Run, after: number, waitMs: number, limit: number): Promise<Page & {
835
+ status: Status;
836
+ state: State;
837
+ final: boolean;
838
+ }>;
839
+ }
840
+ export {};