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

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