@parcha/agentrun-serve 0.1.0-beta.29 → 0.1.0-beta.31

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 (172) hide show
  1. package/CHANGELOG.md +238 -0
  2. package/README.md +739 -116
  3. package/dist/adapters.d.ts +35 -6
  4. package/dist/adapters.js +152 -26
  5. package/dist/agents.d.ts +18 -7
  6. package/dist/agents.js +19 -10
  7. package/dist/app.js +101 -26
  8. package/dist/background.d.ts +29 -0
  9. package/dist/background.js +397 -0
  10. package/dist/box-egress-vm.d.ts +125 -0
  11. package/dist/box-egress-vm.js +350 -0
  12. package/dist/box-egress.d.ts +99 -0
  13. package/dist/box-egress.js +259 -0
  14. package/dist/box-image.d.ts +1 -1
  15. package/dist/box-image.js +9 -7
  16. package/dist/box-relay-vm.d.ts +84 -0
  17. package/dist/box-relay-vm.js +410 -0
  18. package/dist/box-relay.d.ts +8 -5
  19. package/dist/box-relay.js +14 -9
  20. package/dist/boxes.d.ts +28 -5
  21. package/dist/boxes.js +44 -18
  22. package/dist/browser-cost.d.ts +41 -0
  23. package/dist/browser-cost.js +158 -0
  24. package/dist/cap.d.ts +130 -21
  25. package/dist/cap.js +339 -67
  26. package/dist/cli.js +30 -4
  27. package/dist/coding-tools.d.ts +7 -3
  28. package/dist/coding-tools.js +16 -10
  29. package/dist/console/THIRD-PARTY-NOTICES.txt +580 -0
  30. package/dist/console/assets/index-CnJBf7Lc.js +486 -0
  31. package/dist/console/assets/index-DUHbWcIP.css +1 -0
  32. package/dist/console/index.html +2 -2
  33. package/dist/content-filter.d.ts +7 -0
  34. package/dist/content-filter.js +23 -0
  35. package/dist/decision-rows.d.ts +11 -3
  36. package/dist/decision-rows.js +18 -11
  37. package/dist/decisions.d.ts +3 -3
  38. package/dist/decisions.js +4 -3
  39. package/dist/errors.d.ts +2 -0
  40. package/dist/errors.js +5 -2
  41. package/dist/files.d.ts +9 -1
  42. package/dist/files.js +10 -2
  43. package/dist/grade.d.ts +11 -11
  44. package/dist/grade.js +43 -55
  45. package/dist/graph-served.d.ts +23 -0
  46. package/dist/graph-served.js +75 -0
  47. package/dist/graph-view.d.ts +7 -5
  48. package/dist/graph-view.js +10 -3
  49. package/dist/harness-app.d.ts +4 -2
  50. package/dist/harness-app.js +110 -19
  51. package/dist/harness-opencode/adapter.d.ts +45 -0
  52. package/dist/harness-opencode/adapter.js +272 -0
  53. package/dist/harness-opencode/binary.d.ts +18 -0
  54. package/dist/harness-opencode/binary.js +87 -0
  55. package/dist/harness-opencode/config.d.ts +24 -0
  56. package/dist/harness-opencode/config.js +61 -0
  57. package/dist/harness-opencode/harness.d.ts +77 -0
  58. package/dist/harness-opencode/harness.js +620 -0
  59. package/dist/harness-opencode/host/mcp.d.ts +40 -0
  60. package/dist/harness-opencode/host/mcp.js +208 -0
  61. package/dist/harness-opencode/host/policy.d.ts +71 -0
  62. package/dist/harness-opencode/host/policy.js +419 -0
  63. package/dist/harness-opencode/host/server.d.ts +55 -0
  64. package/dist/harness-opencode/host/server.js +165 -0
  65. package/dist/harness-opencode/index.d.ts +9 -0
  66. package/dist/harness-opencode/index.js +6 -0
  67. package/dist/harness-opencode/verify.d.ts +32 -0
  68. package/dist/harness-opencode/verify.js +75 -0
  69. package/dist/harness-opencode/versions.d.ts +33 -0
  70. package/dist/harness-opencode/versions.js +64 -0
  71. package/dist/harness.d.ts +4 -1
  72. package/dist/harness.js +5 -2
  73. package/dist/host-check.d.ts +12 -0
  74. package/dist/host-check.js +34 -0
  75. package/dist/host-tools.d.ts +12 -2
  76. package/dist/host-tools.js +26 -12
  77. package/dist/host.js +6 -2
  78. package/dist/hosted-search.js +5 -1
  79. package/dist/import.d.ts +2 -2
  80. package/dist/import.js +4 -3
  81. package/dist/key-check.d.ts +3 -2
  82. package/dist/key-check.js +7 -3
  83. package/dist/key-refusal.js +8 -4
  84. package/dist/key-words.d.ts +37 -0
  85. package/dist/key-words.js +40 -0
  86. package/dist/learn/check.d.ts +10 -1
  87. package/dist/learn/check.js +19 -1
  88. package/dist/learn/grade.d.ts +6 -2
  89. package/dist/learn/grade.js +28 -14
  90. package/dist/learn/index.d.ts +3 -3
  91. package/dist/learn/index.js +3 -3
  92. package/dist/learn/notes.js +2 -1
  93. package/dist/learn/reflect.d.ts +2 -2
  94. package/dist/learn/reflect.js +53 -5
  95. package/dist/learn/secrets.js +28 -8
  96. package/dist/learn/skills.d.ts +19 -4
  97. package/dist/learn/skills.js +95 -6
  98. package/dist/learned-workflow.d.ts +59 -0
  99. package/dist/learned-workflow.js +191 -0
  100. package/dist/learning-routes.d.ts +30 -1
  101. package/dist/learning-routes.js +173 -19
  102. package/dist/learning-run.d.ts +8 -6
  103. package/dist/learning-run.js +70 -27
  104. package/dist/learning-words.d.ts +12 -5
  105. package/dist/learning-words.js +34 -13
  106. package/dist/learning.d.ts +52 -3
  107. package/dist/learning.js +204 -4
  108. package/dist/mcp-gateway.d.ts +96 -0
  109. package/dist/mcp-gateway.js +408 -0
  110. package/dist/mcp-meta.d.ts +17 -0
  111. package/dist/mcp-meta.js +38 -0
  112. package/dist/mcp-servers.d.ts +33 -9
  113. package/dist/mcp-servers.js +58 -10
  114. package/dist/mcp.js +5 -5
  115. package/dist/model.d.ts +13 -11
  116. package/dist/model.js +11 -10
  117. package/dist/openapi/agentrun-v2.openapi.json +1 -0
  118. package/dist/openapi.js +407 -54
  119. package/dist/page.d.ts +2 -0
  120. package/dist/page.js +3 -0
  121. package/dist/paid-calls.d.ts +5 -1
  122. package/dist/paid-calls.js +1 -1
  123. package/dist/pause.d.ts +2 -0
  124. package/dist/place.d.ts +29 -5
  125. package/dist/place.js +51 -11
  126. package/dist/print.d.ts +7 -0
  127. package/dist/print.js +13 -0
  128. package/dist/propose.d.ts +2 -0
  129. package/dist/propose.js +38 -8
  130. package/dist/request-start.d.ts +12 -4
  131. package/dist/request-start.js +139 -15
  132. package/dist/run-box.d.ts +56 -4
  133. package/dist/run-box.js +183 -23
  134. package/dist/runnable.d.ts +13 -3
  135. package/dist/runnable.js +63 -6
  136. package/dist/runs.d.ts +266 -37
  137. package/dist/runs.js +884 -90
  138. package/dist/secrets.d.ts +27 -0
  139. package/dist/secrets.js +38 -2
  140. package/dist/server.d.ts +141 -36
  141. package/dist/server.js +562 -118
  142. package/dist/sign-ins.d.ts +99 -0
  143. package/dist/sign-ins.js +288 -0
  144. package/dist/skills.d.ts +16 -4
  145. package/dist/skills.js +35 -7
  146. package/dist/stats.d.ts +7 -2
  147. package/dist/stats.js +28 -7
  148. package/dist/tool-gate.d.ts +281 -0
  149. package/dist/tool-gate.js +585 -0
  150. package/dist/tool-keys.d.ts +48 -11
  151. package/dist/tool-keys.js +46 -8
  152. package/dist/tool-plane.d.ts +116 -27
  153. package/dist/tool-plane.js +232 -50
  154. package/dist/tools.d.ts +69 -14
  155. package/dist/tools.js +148 -26
  156. package/dist/trigger-secrets.d.ts +32 -0
  157. package/dist/trigger-secrets.js +143 -0
  158. package/dist/triggers.d.ts +439 -0
  159. package/dist/triggers.js +863 -0
  160. package/dist/turn-end.d.ts +3 -2
  161. package/dist/turn-end.js +3 -2
  162. package/dist/usage-lines.d.ts +26 -0
  163. package/dist/usage-lines.js +28 -0
  164. package/dist/validate.d.ts +2 -0
  165. package/dist/validate.js +11 -2
  166. package/dist/web-fetch.js +3 -3
  167. package/dist/webhooks.d.ts +11 -4
  168. package/dist/webhooks.js +17 -1
  169. package/launcher/agentrun-serve +1 -1
  170. package/package.json +16 -14
  171. package/dist/console/assets/index-BN7oVcO4.js +0 -445
  172. package/dist/console/assets/index-By-jkqki.css +0 -1
package/dist/runs.d.ts CHANGED
@@ -1,20 +1,26 @@
1
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";
2
+ import { type Revision, type RevisionKind, type RunOrigin, type RunRow } from "@parcha/pi-durable-agent";
3
+ import { type MessageOrigin, type RunMetrics, type TimelineEvent } from "@parcha/pi-durable-agent/timeline";
4
+ import type { RUN_EVENTS, RunNotice } from "./webhooks.js";
5
+ import type { RunTrigger } from "./triggers.js";
5
6
  import { type AgentEntry, type Agents } from "./agents.js";
7
+ import { type McpServerSource } from "./mcp-gateway.js";
6
8
  import { type DaytonaApi } from "./daytona-api.js";
7
9
  import { type Learning, type LearningMode, type LearningReason, type LearningState } from "./learning.js";
8
10
  import { LearningRuns, type Reflect } from "./learning-run.js";
9
11
  import { type BoxHost, type Quarantine } from "./box/sweep.js";
12
+ import { type RefusalFigures } from "./cap.js";
10
13
  import { type Tier } from "./model.js";
11
14
  import { type Plane, type Tooling, type ToolSettingsMap } from "./tool-plane.js";
15
+ import { type PendingApproval } from "./tool-gate.js";
12
16
  import { type Page, RowLog } from "./rows.js";
13
17
  import { type Json } from "./validate.js";
14
18
  import { Turns } from "./turns.js";
15
19
  import { type StoredKeys } from "./secrets.js";
20
+ import type { HandedSignIn, SignIns } from "./sign-ins.js";
16
21
  import { type Place } from "./place.js";
17
22
  import type { BoxProvider } from "@parcha/pi-transport";
23
+ import type { RemoteLimits } from "./run-box.js";
18
24
  import type { Emitted } from "./webhooks.js";
19
25
  export type Status = "queued" | "working" | "paused" | "input_required" | "completed" | "failed" | "cancelled";
20
26
  export type State = "working" | "waiting" | "idle";
@@ -26,6 +32,24 @@ type RunMeta = {
26
32
  input?: Json;
27
33
  effort?: string;
28
34
  max_cost_usd?: number;
35
+ /** Each raise of its cap (PATCH /runs/{id}): from what, to what, when, and the pause it answers (pauseOf), if any. */
36
+ cap_raised?: {
37
+ from: number;
38
+ to: number;
39
+ at: string;
40
+ pause?: string;
41
+ }[];
42
+ /** The one follow-up that sends a run paused at its cap on once its cap is raised (resumeRaised): for which pause, by
43
+ * what id, whether it went, how many tries failed and why, and which process was being let go when it was asked for
44
+ * (its pid and start ticks): it goes once that process is gone, here or after a restart. */
45
+ cap_continue?: {
46
+ pause: string;
47
+ message_id: string;
48
+ sent: boolean;
49
+ tries: number;
50
+ error?: string;
51
+ paused?: string;
52
+ };
29
53
  error?: {
30
54
  code: string;
31
55
  message: string;
@@ -60,6 +84,41 @@ type RunMeta = {
60
84
  /** A run whose cost was unknown when it ended: the sum of its charges whose cost is known, and how many have none
61
85
  * (costsofar/1), as its view said then, so a list row read from the store says it too. */
62
86
  cost_so_far?: SoFar;
87
+ /** A person's answer to each tool call that waited for approval (tool-gate.ts), by its id: the first one wins, and
88
+ * the run's process reads it here. A cancel marks one still waiting canceled. */
89
+ approvals?: Record<string, ApprovalAnswer>;
90
+ /** A cancel that waits for the run's gate to cut the approved calls it overrode (Runs.cancel): their ids, kept so an
91
+ * operator (and a test) reads that it did, never how long it took. Absent on a cancel that waits on nothing. */
92
+ cancel_waits_for?: string[];
93
+ /** The trigger that started it, and its firing's key (triggers.ts); absent for a run a caller started. */
94
+ trigger?: RunTrigger;
95
+ };
96
+ /** A tool call that waited for a person's approval, as the run's store has it (tool-gate.ts): `resolved` once the run's
97
+ * process acted on the answer. */
98
+ type Approval = {
99
+ id: string;
100
+ tool: string;
101
+ call_id: string;
102
+ args_json: string;
103
+ requested_at: string;
104
+ price?: number | "not metered";
105
+ resolved?: true;
106
+ };
107
+ /** `args_shown`: the call's arguments as the server shows them (shownArgs), which the gate's resume message names. */
108
+ /** `by`: "message", a deny a person's message gave while the call waited (Runs.message). */
109
+ /** `superseded`: the answer a stop or a cancel overrode before the run's process acted on it, kept as it was given. */
110
+ type ApprovalAnswer = {
111
+ decision: "allow" | "deny" | "canceled" | "withdrawn";
112
+ note?: string;
113
+ answered_at: string;
114
+ args_shown?: string;
115
+ by?: "message";
116
+ superseded?: {
117
+ decision: string;
118
+ answered_at: string;
119
+ note?: string;
120
+ by?: "message";
121
+ };
63
122
  };
64
123
  type RunError = {
65
124
  code: string;
@@ -121,6 +180,8 @@ export type Run = {
121
180
  rows: TimelineEvent[];
122
181
  /** The person's messages the run took, and how each one's turn ended (turns.ts): its end is read from them. */
123
182
  turns: Turns;
183
+ /** Its tool calls that waited for a person's approval, read from its store's entries, by id. */
184
+ approvals?: Map<string, Approval>;
124
185
  /** The whole text of each assistant message of its end-of-run turn, by store entry: what the turn answered, whose
125
186
  * notes learning reads (learning-run.ts). */
126
187
  turnText?: Map<number, string>;
@@ -138,6 +199,8 @@ export type Run = {
138
199
  working: boolean;
139
200
  /** Messages this server sent the run that its rows do not show yet. */
140
201
  submitted: number;
202
+ /** The write of its end-of-run turn's origin (toLiveDoor), which a person's turn waits for before it removes it. */
203
+ originWrite?: Promise<unknown>;
141
204
  /** The user_message rows the run has shown, by id: one shown for the first time is a submitted message arriving. */
142
205
  users: Set<string>;
143
206
  /** The rows the live path has shown as live, by id, over every connection to the run's door. */
@@ -161,6 +224,10 @@ export type Run = {
161
224
  known: number;
162
225
  unpriced: number;
163
226
  };
227
+ /** The saved sign-in its next launch hands its browser (pinSignIn), never kept on disk by the run. */
228
+ signIn?: HandedSignIn;
229
+ /** Whether its process, as last settled, let the run go (and its browser's sessions with it), or went without. */
230
+ letGo?: boolean;
164
231
  /** A workflow run's decision rows, from its released store: its timeline shows one row each (decision-rows.ts). Null
165
232
  * when they cannot be read: its timeline's usage row then reads unknown. */
166
233
  decisions?: Record<string, unknown>[] | null;
@@ -170,8 +237,13 @@ export type Run = {
170
237
  /** What every conversation of its store says it used, as the settle that ends it read them. */
171
238
  metrics?: RunMetrics;
172
239
  relaunches: number;
240
+ /** Its start's launch is next: the one a deny is told as under ask (relaunchPlane's `first`). */
241
+ firstLaunch?: true;
173
242
  /** Its newest launch has not reported back: its mark (RUN_LAUNCHING) is on disk. */
174
243
  launching?: boolean;
244
+ /** The store has it running and its serve.json holds no input: its server went down before it set the run up (whose
245
+ * first write is the input), so it never launched. A serve.json written since (its failure, a stop) never adds one. */
246
+ notSetUp?: boolean;
175
247
  /** Its files being copied into its work/ before its first launch, until they are: nothing launches it meanwhile (a
176
248
  * request that would waits for it), and nothing but a cancel settles it. */
177
249
  preparing?: Promise<void>;
@@ -194,6 +266,22 @@ export type Run = {
194
266
  pulling?: Promise<void>;
195
267
  /** It stood waiting for the person when last marked: a turn's end is the change into that. */
196
268
  waited?: boolean;
269
+ /** The pause at its cap (its mark) whose process was let go: once per pause. */
270
+ parked?: string;
271
+ /** A raise of its cap being taken (raiseCap): the next one waits for it, so two at once resume it once. */
272
+ raising?: Promise<unknown>;
273
+ /** Its raise's follow-up is being sent (resumeRaised), or waits to be tried again (its time): never two at once. */
274
+ resuming?: "sending" | number;
275
+ /** Its newest refusal for room's figures, from that refusal's own start mark (cap.ts RefusalFigures). */
276
+ capRefusal?: RefusalFigures;
277
+ /** That refusal's own start mark (its entry): the pause a raise answers is keyed to it (pauseOf). */
278
+ capMark?: number;
279
+ /** What it has spent paused at that refusal (its row), its process gone: the store's spend (spentNow), read once. */
280
+ capSpent?: {
281
+ mark: string;
282
+ usd: number | null;
283
+ at?: number;
284
+ };
197
285
  };
198
286
  /** The waiting row after each answered `ask_person` call, which the timeline module does not know. The question comes
199
287
  * from the call's row, whose label this module registers. */
@@ -209,12 +297,30 @@ type Pending = {
209
297
  kind: "question";
210
298
  question: string;
211
299
  asked_at: string;
300
+ } | PendingApproval | {
301
+ kind: "budget";
302
+ cap_usd: number;
303
+ spent_usd?: number;
304
+ needs_usd?: number;
305
+ suggested_cap_usd?: number;
306
+ said: string;
307
+ at: string;
212
308
  } | null;
309
+ /** How many of the refused request's least a run paused at its cap is offered on top of what was taken (suggestedCap). */
310
+ export declare const SUGGESTED_RAISE_FACTOR = 10;
311
+ /** The raise a run paused at its cap is offered: what the cap counted as taken plus SUGGESTED_RAISE_FACTOR times the
312
+ * refused request's least, rounded up to a whole dollar, and always above the cap (the next dollar above it, if not),
313
+ * so a PATCH with it is a raise. */
314
+ export declare const suggestedCap: (cap: number, spentUsd: number, needsUsd: number) => number;
213
315
  /** The run's cost from its usage row: null when a response's cost is unknown, 0 before any request. */
214
316
  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;
317
+ /** What a run's paid tools charged (`tool`'s alone, when given; every other tool's with `others`), from the same rows its
318
+ * cost is read from: each charge's line carries it (`usage` on a `phase` row), and a browser call's row what its charges
319
+ * came to; null when one is unknown. A call still marked, in flight or cut, is no charge here. */
320
+ export declare const toolCostOf: (rows: readonly TimelineEvent[], tool?: string, others?: boolean) => number | null;
321
+ /** What a run's paid tools are known to have charged (`tool`'s alone, when given; every other tool's with `others`): each
322
+ * charge's line that names its cost, a charge of unknown cost adding nothing (a browser call's row, what is known of it). */
323
+ export declare const knownToolCostOf: (rows: readonly TimelineEvent[], tool?: string, others?: boolean) => number;
218
324
  /** 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
325
  * request). A usage row that says unknown, or says nothing, stays unknown: what the store kept dates from before a
220
326
  * follow-up. */
@@ -254,31 +360,46 @@ export type CarryBackRetry = {
254
360
  delaysMs?: readonly number[];
255
361
  onBusy?: (runId: string, attempt: number) => void;
256
362
  };
257
- /** How a run is asked to start: its input and title, its effort and cap, and what puts its files in its work/. */
363
+ /** How a run is asked to start: its input and title, its effort and cap, and what puts its files in its work/. `origin`:
364
+ * the store's key for what asked (an Idempotency-Key's, a trigger's firing): a key that already started a run gets that
365
+ * run. `trigger`: the trigger and firing that started it. */
258
366
  export type StartOptions = {
259
367
  input: Json;
260
368
  title: string;
261
369
  place: Place;
262
370
  effort?: string;
263
371
  maxCostUsd?: number;
372
+ trigger?: RunTrigger;
264
373
  inputs?: (work: string) => Promise<unknown>;
374
+ origin?: RunOrigin;
265
375
  };
266
376
  /** `token` is the server's own: no run's process sees it. */
267
377
  /** `maxRuns`: the most runs with a live process at once; `settleRetryMs`: how often a carry back the store refused is
268
378
  * tried again; `readyTimeoutMs`: how long a request to a run waits for its door (a run's first message, sent by its
269
379
  * start, always waits READY_TIMEOUT_MS); `log` takes a run's start and end (print.ts). */
270
380
  export type RunsOptions = {
381
+ dockerAllow?: readonly string[] | "none"; /** On a Mac, the server's proxy container's volume a run's Docker box mounts (box-egress-vm.ts). */
382
+ dockerVolume?: string;
271
383
  agents: Agents;
272
384
  token: string; /** The server's saved tool keys, read by name for its runs alone (secrets.ts). */
273
- storedKeys?: StoredKeys;
385
+ storedKeys?: StoredKeys; /** The server's saved MCP servers (mcp-servers.ts): a run's pin and its credentials come from them at each launch. */
386
+ mcpServers?: McpServerSource;
274
387
  documents?: string;
275
388
  doorTokenFile: string;
276
389
  doorToken: string; /** The test switches a run's process gets (server.ts fauxEnvOf): empty outside tests. */
277
390
  fauxEnv?: NodeJS.ProcessEnv;
278
391
  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
392
  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;
393
+ remoteApi?: DaytonaApi; /** The server's VM box provider, with its client: a VM run's box is made, seeded, pulled and ended with it, here alone, as a Daytona one is (box-relay-vm.ts); it has no network. */
394
+ vmBoxes?: BoxProvider; /** A VM box's limits (run-box.ts RemoteLimits), from the box settings. */
395
+ vmLimits?: RemoteLimits; /** The relay's VM half, which lets go of a run's programs at its end. */
396
+ vmRelay?: {
397
+ drop(runId: string): void;
398
+ }; /** The hosts a remote box may reach (run-box.ts boxAllowOf); `none`, or absent, for none. */
399
+ boxAllow?: readonly string[] | "none"; /** Called once, with the provider's refusal's code and words, when it cannot keep that list here: from then on each remote box is made with no network. */
400
+ onNoBoxList?: (code: string, message: string) => void;
401
+ toolSettings?: () => ToolSettingsMap; /** Whether anyone can answer a tool call's approval here (accounts on); false, the run's gate refuses each ask (tool-gate.ts). */
402
+ approvers?: boolean;
282
403
  drainTimeout?: string;
283
404
  carryBackRetry?: CarryBackRetry;
284
405
  maxRuns?: number;
@@ -294,14 +415,18 @@ export type RunsOptions = {
294
415
  learningBudget?: number;
295
416
  log?: (event: string, fields: Record<string, string | number>) => void;
296
417
  notify?: RunNotify;
297
- learning?: LearningMode;
418
+ learning?: LearningMode; /** Each agent's saved sign-ins (sign-ins.ts): absent, no run gets one. */
419
+ signIns?: SignIns; /** The secrets this server makes and keeps sealed while it runs (each webhook trigger's), read at each check, so a rotation is seen at once: what a run's learning refuses and cuts, as it does the saved keys. */
420
+ ownSecrets?: () => readonly string[];
298
421
  };
299
422
  /** 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
423
  * 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
424
  * 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 & {
425
+ export type RunNotify = (event: (typeof RUN_EVENTS)[number], run: RunNotice & {
303
426
  status: Status;
304
427
  }, marker: string) => Emitted;
428
+ /** Why a message that may not answer a person's question is not sent. */
429
+ export declare const WAITS_ON_A_PERSON = "The run is waiting on a person.";
305
430
  /** The secrets a run's process is handed over its pipe (secrets.ts): every one but the server's own and the decision
306
431
  * keys, which go on their own descriptor. */
307
432
  export declare const RUN_SECRETS: string[];
@@ -346,6 +471,10 @@ export declare const childEnv: (env: NodeJS.ProcessEnv, token: string) => NodeJS
346
471
  export declare function failureLine(log: string): string;
347
472
  /** The last line of the run process's log, in words, for a failure's message. */
348
473
  export declare function lastLogLine(run: Pick<Run, "dir">): Promise<string>;
474
+ /** Seams for tests, each unset in a server: `personsTurn` holds a person's turn just after its origin went. */
475
+ export declare const runsTestHooks: {
476
+ personsTurn?: (runDir: string) => Promise<void> | void;
477
+ };
349
478
  export declare class Runs {
350
479
  private readonly options;
351
480
  private readonly runs;
@@ -354,9 +483,12 @@ export declare class Runs {
354
483
  /** What decides the secrets each revision's runs are handed (needsOf), by revision id: read once, from the revision the
355
484
  * run is pinned to, never from a request. The keys themselves are read at each launch (keysFor). */
356
485
  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;
486
+ /** Every run's graph as served, part by part (servedGraph), and each workflow run's last graph read whole, which a
487
+ * poll that met a busy store answers, marked stale: one LRU by bytes across runs (graph-served.ts PartCache). */
488
+ private readonly graphCache;
359
489
  private readonly adopting;
490
+ /** The hosts this server's next remote box asks for: the setting's, until the provider cannot keep a list here, then none. */
491
+ private remoteAllow;
360
492
  private readonly clock;
361
493
  private readonly cli;
362
494
  private readonly app;
@@ -374,6 +506,8 @@ export declare class Runs {
374
506
  /** The runs' learning (learning-run.ts): a step this file calls as a run starts, ends, settles, opens again and is
375
507
  * recovered, handed what it moves of a run. */
376
508
  readonly learning: LearningRuns;
509
+ /** When this server took the data root (one server a root): a run started since is its own, never one to recover. */
510
+ private readonly bootedAt;
377
511
  constructor(options: RunsOptions);
378
512
  /** A test's seam (startServe's `beforeAbort`): awaited by a stop between its mark and its abort, so a test can hold a
379
513
  * stop in flight there. */
@@ -381,8 +515,15 @@ export declare class Runs {
381
515
  /** A test's seam (startServe's `beforeReopenLaunch`): awaited by a reopen after the run reads open again and before its
382
516
  * launch, so a test can hold a reopen there. */
383
517
  beforeReopenLaunch?: (runId: string) => Promise<void> | void;
518
+ /** A test's seam (startServe's `onRunLoad`): told each run read in from its store, its timeline with it. */
519
+ onRunLoad?: (runId: string) => void;
384
520
  /** A test's seam (startServe's `beforeSubmit`): awaited by a message before it goes to the run's door. */
385
521
  beforeSubmit?: (runId: string, content: string) => Promise<void> | void;
522
+ /** A test's seam (startServe's `beforeMetaSave`): awaited before a run's serve.json is written; one that throws fails
523
+ * the write, as a full disk would. */
524
+ beforeMetaSave?: (runId: string, meta: Readonly<RunMeta>) => Promise<void> | void;
525
+ /** A test's seam (startServe's `messageOrigin`): the origin a message sent through the messages route carries. */
526
+ messageOrigin?: (runId: string, content: string) => MessageOrigin | undefined;
386
527
  private get store();
387
528
  /** Run `id` when this process holds it, never read from disk. */
388
529
  held(id: string): Run | undefined;
@@ -394,6 +535,8 @@ export declare class Runs {
394
535
  private blank;
395
536
  /** 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
537
  * once the run's learning ended). */
538
+ /** Writes the run's serve.json, after any write already under way: `meta`, a copy its caller publishes to run.meta
539
+ * only once this resolves (a raise, takeRaise), else run.meta, each as it stands when the write starts. */
397
540
  private saveMeta;
398
541
  private record;
399
542
  /** The door a live run serves, from its run.json: running, a fresh heartbeat, and a loopback address. */
@@ -406,6 +549,9 @@ export declare class Runs {
406
549
  /** New rows in: into the log, then the run's status, then whatever the status asks for. */
407
550
  /** `keep`: rows that stay served though `rows` no longer holds them (the live path's committed rows). */
408
551
  private take;
552
+ /** The approval rows as the run's answers say them now (a stop or a cancel withdraws a call, an answer settles one),
553
+ * shown at once: an answer takes no new rows. */
554
+ private restate;
409
555
  /** 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
556
  * only, never the run's own rows, which its cost and its answer are read from. */
411
557
  private show;
@@ -435,10 +581,23 @@ export declare class Runs {
435
581
  * 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
582
  * saved or deleted changes the values' digest, and the next view redacts again. */
437
583
  private servedOnce;
584
+ /** A workflow run's graph as serve serves it: its nodes, each decision and each call (its input, output and error) with
585
+ * no held secret, by its answer's rule (redactedOutput), and only then cut: a map item's label at 200 characters, a
586
+ * call's error at 2000, and a text stored cut (a decision's state past 64 KB, an error logged cut) less its last 6
587
+ * times the longest held value plus 16 characters, where a value the stored cut split would sit. The view a busy
588
+ * store's read keeps is the one graph-view.ts made, whole, so a key saved after it is still found. Each part is
589
+ * served once per content and held value set: a console polls the graph while the run goes. */
590
+ private servedGraph;
438
591
  /** The timeline's redaction of `run`'s error rows and of what a tool's result shows (its summary and preview), applied
439
592
  * before a row is cut (timelineOf's `redact`), so a cut never leaves the head of a key. Every such cut is within
440
593
  * redacted()'s SHOWN, so its window holds. */
594
+ /** How a run's decision rows show a text (decision-rows.ts Shown): the run's redactor, and as many characters held back
595
+ * from a text stored cut as a held value takes in its widest form. */
596
+ private decisionShown;
441
597
  private redactor;
598
+ /** The last line of the run process's log (lastLogLine) for a failure's message, with every value its errors never
599
+ * show cut out: its process may have written a secret or its sign-in's pointer there. */
600
+ private lastLine;
442
601
  /** Every secret value `run`'s errors never show, as learning's checker holds them (learning-run.ts refused): this
443
602
  * server's secrets wherever its launcher put them and the keys saved on it, what each launch handed the run, and the
444
603
  * server's own tokens. */
@@ -447,6 +606,12 @@ export declare class Runs {
447
606
  * harness's route sends, by this server's settings and keys, and no secret's value. */
448
607
  private plainKey;
449
608
  /** 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. */
609
+ /** What a run paused at its cap has spent once its process is gone: its store's spend as the cap reads it (spentIn),
610
+ * read once per pause (its refusal's row). None while its process lives, nor when the store says unknown or cannot
611
+ * be read: the refusal's own figure stands then. */
612
+ private spentNow;
613
+ /** The run's live process, by its pid and start ticks (processIdentity). */
614
+ private liveIdentity;
450
615
  private refresh;
451
616
  /** The test hooks startServe's options name, as a run's process and this server's own calls get them. */
452
617
  private fauxEnv;
@@ -482,6 +647,8 @@ export declare class Runs {
482
647
  pulled(id: string): Promise<void>;
483
648
  /** Whether run `id` is one this server holds in a remote box and has not ended: the relay serves no other. */
484
649
  servesBox(id: string): boolean;
650
+ /** The server's provider of a remote place's boxes: the VM box's, or Daytona's. */
651
+ private remoteOf;
485
652
  /** Run `id`'s remote box, found or made and seeded: what its process asks the relay for at its first tool call. */
486
653
  ensureBox(id: string): Promise<{
487
654
  id: string;
@@ -516,13 +683,24 @@ export declare class Runs {
516
683
  * has no turn: the door's abort would give it a root conversation. */
517
684
  private abortTurn;
518
685
  /** 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. */
686
+ * while it opens or parks. `turnOrigin`: who sent a turn this request sends (learning-run.ts's REFLECT_ORIGIN), kept in
687
+ * the run's directory before it goes, where the tool gate reads it (tool-gate.ts NOTE_ONLY_TEXT); a person's message
688
+ * removes it. */
521
689
  private toLiveDoor;
522
690
  private toDoor;
523
691
  /** Reads what decides the secrets runs of `run`'s revision are handed (needsOf), once per revision: from `given` (a
524
692
  * start's, read from the store), else from the agent store, waiting out a busy one as a run's end does. */
525
693
  private pinNeeds;
694
+ /** `run`'s pinned MCP tools: read from its directory, or at its first launch made from the granted `tools` and the
695
+ * servers saved now, and written before its process starts. Undefined when it grants none. */
696
+ private mcpPin;
697
+ /** The saved sign-in the run's browser starts from (sign-ins.ts), resolved before each launch: made at the vendor when
698
+ * its agent has none, and leased to this run to save unless another run of the agent holds the lease. One that cannot
699
+ * be had (the vendor not answering, a seal key changed) leaves its browser signed out, said in its log. */
700
+ private pinSignIn;
701
+ /** Lets go of the save lease the run holds on its agent's sign-in, if any: at once when its process let its sessions go
702
+ * (`clean`), else by the gone rule (sign-ins.ts). */
703
+ private releaseSignIn;
526
704
  private launch;
527
705
  /** Writes the run's launch mark before its process is spawned: a spawn that takes the server down leaves it, and the
528
706
  * next start fails the run rather than launch it again and go down with it. The file exists once the call returns,
@@ -583,14 +761,53 @@ export declare class Runs {
583
761
  * 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
762
  * launch makes its own. False when the copy failed, and the run ended so (or was cancelled meanwhile). */
585
763
  private prepare;
764
+ /** One message to the run's door. `origin`: who wrote it when the person did not (a raised cap's follow-up, an
765
+ * approval's resume), carried to its user entry so the Timeline shows it as the server's (pi-durable-agent's
766
+ * MessageOrigin); the model reads the same text either way. `answers: false`: the run's door refuses the message
767
+ * (WAITING) when the run's turn ended on ask_person or a tool call of it waits for its owner's approval (the gate's
768
+ * park, APPROVAL_ENTRY), and when the run is busy (BUSY), so it is never queued behind a
769
+ * turn that may end so; decided at the door's admission, past every wait here. */
586
770
  private submit;
587
771
  /** Whether the run's harness takes a message mid-turn. */
588
772
  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<{
773
+ /** Whether the run's store already took a message under `requestId`: a trigger's firing sent it, and the server went
774
+ * down before it wrote so. Read before sending it again, so a completed run is not opened again for a message it
775
+ * already has. Only for a run with no live process: a live one holds its store, and takes the message through its
776
+ * door, which takes one per id anyway. The store keeps the id as JSON text, as pi submits it, or as a harness's door
777
+ * keeps its journal (doorKey), where a busy refusal is not a message taken (doorTook). A store held past the retries
778
+ * throws as busy. */
779
+ tookMessage(run: Run, requestId: string): Promise<boolean>;
780
+ /** Raises the cap of an agentic run that names one, to `cap`: above its own (by more than CAP_TOLERANCE), or the same as
781
+ * its newest raise (a retry, which changes nothing). serve.json keeps it before any answer, and a raise it could not keep
782
+ * is undone, so the run's next process opens under it (CAP_ENV), as does a server started again. A run paused at its
783
+ * cap goes on: the raise names the pause it answers, and the pause gets one follow-up, "The cap was raised to $X;
784
+ * continue the task." under an id fixed now, which refresh sends once the paused process is gone (resumeRaised), here
785
+ * or after a restart; a second raise before it goes raises what it says. A run working keeps the cap its process was
786
+ * opened with until its next process. Raises of one run are taken one at a time. */
787
+ raiseCap(run: Run, cap: number): Promise<{
788
+ resumed: boolean;
789
+ messageId?: string;
790
+ note?: string;
791
+ }>;
792
+ private takeRaise;
793
+ /** Sends a raised run its pause's follow-up, under its id (the door takes one id once), at the run's cap now: as a
794
+ * follow-up to a run whose process has gone (message()), so the process it starts resumes nothing and opens under the
795
+ * new cap, or to the process another launch started. Marked sent in serve.json. One that cannot be sent is tried
796
+ * again (CONTINUE_RETRY_MS), and after CONTINUE_TRIES the run fails, saying why: never a pause stuck in silence. */
797
+ private resumeRaised;
798
+ /** Ends a raised run whose follow-up could not be sent: failed, in words a person can act on. */
799
+ private failRaised;
800
+ /** One message to an agentic run, its mode chosen by the run's state (the contract's table). `requestId`: the message's
801
+ * id in the run's store, which takes one message per id (a trigger's firing key); default a new one. */
802
+ message(run: Run, content: string, requestId?: string, { answers }?: {
803
+ answers?: boolean;
804
+ }): Promise<{
591
805
  mode: "steer" | "answer" | "follow_up";
592
806
  messageId: string;
593
807
  }>;
808
+ /** A person's turn is sent next: no turn from here on is the server's own end-of-run turn (tool-gate.ts NOTE_ONLY_TEXT),
809
+ * so its origin goes, right before the turn is sent. */
810
+ private personsTurn;
594
811
  /** Waits, up to a request's deadline, while `holds` (checked every `everyMs`): else 503 `unavailable`, saying `why`. */
595
812
  private waitWhile;
596
813
  /** A completed agentic run that gets a follow-up opens again: the same run on its own store and session, under its
@@ -602,8 +819,26 @@ export declare class Runs {
602
819
  private caughtUp;
603
820
  /** Abort the turn that is running; the run stays open, `input_required` and idle. A workflow run has no turn to stop. */
604
821
  stop(run: Run): Promise<boolean>;
822
+ /** message()'s decline of the tool call that waits for approval: a deny with the message as its note, which the
823
+ * run's gate acts on as any deny, resuming the session with the refusal and the person's words in one message. */
824
+ private declineBy;
825
+ /** The answers given and not acted on yet (the run's process has not resolved them), overridden by a stop or a cancel:
826
+ * `withdrawn` or `canceled`, each keeping the answer it superseded, so nothing runs and nothing resumes, and the
827
+ * history shows what was given. The run's gate reads the answer again just before it acts (tool-gate.ts). */
828
+ private supersede;
829
+ /** Until every tool call of the run that waited for approval is resolved in its store (its process acted on its answer,
830
+ * or cut it), or `ms` pass. */
831
+ private untilResolved;
832
+ /** stop()'s withdrawal of the tool call that waits for approval: never run, and an answer after is 409. */
833
+ private withdraw;
834
+ /** stop() of a run with no turn to abort (parked on an approval it withdrew): the stop's mark, as a stop saves it. */
835
+ private stopIdle;
605
836
  /** stop()'s mark and abort, once it took the stop. */
606
837
  private stopTurn;
838
+ /** A person's answer to the tool call `id` that waits for approval (tool-gate.ts): kept in the run's serve.json before
839
+ * it returns, the first answer winning (the same one again changes nothing; another is 409, `already_answered`). The
840
+ * run's process reads it there, runs or refuses the call, and resumes; a run with no process gets one. */
841
+ approve(run: Run, id: string, decision: "allow" | "deny", note?: string): Promise<void>;
607
842
  /** Record the cancel and signal the run. An agentic run reads `cancelled` from here on (the first end a run comes to is
608
843
  * its last: nothing its turn writes later moves it), and is carried back so once its process has exited; a workflow
609
844
  * run reads it once it is carried back, with how its workflow stopped. */
@@ -644,6 +879,12 @@ export declare class Runs {
644
879
  }[];
645
880
  }>;
646
881
  decisions: {
882
+ images: {
883
+ token: {} | null;
884
+ ref: {} | null;
885
+ url: string | null;
886
+ }[];
887
+ error_cut?: boolean | undefined;
647
888
  id: {} | null;
648
889
  node: string | null;
649
890
  executionPath: {} | null;
@@ -663,11 +904,6 @@ export declare class Runs {
663
904
  state: {} | null;
664
905
  state_truncated: boolean;
665
906
  error: string | null;
666
- images: {
667
- token: {} | null;
668
- ref: {} | null;
669
- url: string | null;
670
- }[];
671
907
  }[];
672
908
  effects: {
673
909
  node: string | null;
@@ -678,6 +914,7 @@ export declare class Runs {
678
914
  input: unknown;
679
915
  output: unknown;
680
916
  error: string | null;
917
+ error_cut?: boolean;
681
918
  startedAt: string;
682
919
  endedAt: string | null;
683
920
  }[];
@@ -687,17 +924,6 @@ export declare class Runs {
687
924
  effects: number;
688
925
  elapsed_ms: number | null;
689
926
  };
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
927
  }>;
702
928
  /** How long a run's process gets after SIGTERM before SIGKILL: its drain and a second to exit. */
703
929
  private killAfterMs;
@@ -747,6 +973,7 @@ export declare class Runs {
747
973
  source: string;
748
974
  session: string;
749
975
  } | null;
976
+ trigger: RunTrigger | null;
750
977
  learning: {
751
978
  used?: import("./learning.js").NoteUsed[];
752
979
  learned?: import("./learning.js").NoteLearned[];
@@ -791,6 +1018,7 @@ export declare class Runs {
791
1018
  source: string;
792
1019
  session: string;
793
1020
  } | null;
1021
+ trigger: RunTrigger | null;
794
1022
  learning: ({
795
1023
  state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
796
1024
  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;
@@ -805,7 +1033,7 @@ export declare class Runs {
805
1033
  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
1034
  detail: string | null;
807
1035
  at: string;
808
- }, "at" | "reason" | "state" | "detail">) | null;
1036
+ }, "at" | "state" | "reason" | "detail">) | null;
809
1037
  effort?: string | undefined;
810
1038
  run_id: string;
811
1039
  agent_id: string;
@@ -822,8 +1050,9 @@ export declare class Runs {
822
1050
  /** 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
1051
  * not its store; `versions` numbers its agent's revisions. */
824
1052
  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. */
1053
+ /** A key was saved on this server or deleted from it: each held run's learning row and decision rows shown again, cut
1054
+ * of the keys as they are now (learning-run.ts shown, decision-rows.ts), as its view and its lists already are from
1055
+ * the next read on. */
827
1056
  keysChanged(): void;
828
1057
  /** A held run's learning, in short (learning-run.ts heldLearning). */
829
1058
  heldLearning(runId: string): {