@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.35

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 (227) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +84 -16
  3. package/dist/adapters.d.ts +3 -0
  4. package/dist/adapters.js +7 -0
  5. package/dist/agent-rows.d.ts +1 -0
  6. package/dist/agents-store.js +17 -2
  7. package/dist/archil-settings.d.ts +11 -1
  8. package/dist/archil-settings.js +10 -0
  9. package/dist/bash-read-only.d.ts +13 -0
  10. package/dist/bash-read-only.js +77 -0
  11. package/dist/browser-cost.d.ts +2 -2
  12. package/dist/browser-cost.js +6 -4
  13. package/dist/budget.d.ts +0 -5
  14. package/dist/budget.js +0 -5
  15. package/dist/cap.d.ts +6 -3
  16. package/dist/cap.js +7 -4
  17. package/dist/cli.js +32 -5
  18. package/dist/computer-keys.d.ts +20 -10
  19. package/dist/computer-keys.js +36 -57
  20. package/dist/computer-setting.d.ts +6 -5
  21. package/dist/computer-setting.js +54 -26
  22. package/dist/computers.d.ts +9 -4
  23. package/dist/computers.js +4 -2
  24. package/dist/console/assets/index-B7NKTU8E.css +1 -0
  25. package/dist/console/assets/index-CXZMgJE7.js +550 -0
  26. package/dist/console/index.html +2 -2
  27. package/dist/content-filter.d.ts +7 -0
  28. package/dist/content-filter.js +23 -0
  29. package/dist/decision-cap.d.ts +7 -29
  30. package/dist/decision-cap.js +3 -94
  31. package/dist/errors.d.ts +1 -0
  32. package/dist/errors.js +3 -0
  33. package/dist/explain.js +3 -1
  34. package/dist/github-connection.js +25 -7
  35. package/dist/github-faux.d.ts +26 -0
  36. package/dist/github-faux.js +76 -0
  37. package/dist/github.d.ts +6 -2
  38. package/dist/github.js +5 -3
  39. package/dist/graph-served.d.ts +5 -3
  40. package/dist/graph-served.js +14 -6
  41. package/dist/graph-view.js +5 -2
  42. package/dist/harness-opencode/harness.js +0 -1
  43. package/dist/harness-opencode/host/policy.js +2 -2
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.js +1 -0
  46. package/dist/learn/check.d.ts +3 -1
  47. package/dist/learn/check.js +3 -3
  48. package/dist/learn/folder.d.ts +6 -3
  49. package/dist/learn/folder.js +7 -16
  50. package/dist/learn/grade.d.ts +4 -1
  51. package/dist/learn/grade.js +43 -5
  52. package/dist/learn/index.d.ts +2 -2
  53. package/dist/learn/index.js +2 -2
  54. package/dist/learn/learning.sh +1 -14
  55. package/dist/learn/notes.d.ts +14 -3
  56. package/dist/learn/notes.js +16 -6
  57. package/dist/learn/reflect.js +5 -3
  58. package/dist/learn/skills.d.ts +48 -5
  59. package/dist/learn/skills.js +97 -21
  60. package/dist/learned-nodes.d.ts +14 -0
  61. package/dist/learned-nodes.js +8 -0
  62. package/dist/learned-workflow.d.ts +9 -5
  63. package/dist/learned-workflow.js +53 -9
  64. package/dist/learning-routes.d.ts +41 -0
  65. package/dist/learning-routes.js +94 -26
  66. package/dist/learning-run.d.ts +7 -5
  67. package/dist/learning-run.js +9 -6
  68. package/dist/learning.d.ts +0 -22
  69. package/dist/learning.js +0 -16
  70. package/dist/llm.d.ts +4 -1
  71. package/dist/llm.js +4 -2
  72. package/dist/mcp-gateway.d.ts +6 -0
  73. package/dist/mcp-gateway.js +11 -1
  74. package/dist/mcp-servers-store.d.ts +12 -12
  75. package/dist/model.d.ts +3 -0
  76. package/dist/model.js +8 -0
  77. package/dist/openapi.js +37 -13
  78. package/dist/paid-calls.js +1 -1
  79. package/dist/pause.d.ts +2 -19
  80. package/dist/pause.js +5 -74
  81. package/dist/port-models.d.ts +10 -3
  82. package/dist/port-models.js +26 -6
  83. package/dist/propose.d.ts +2 -0
  84. package/dist/propose.js +1 -10
  85. package/dist/run-launch.d.ts +5 -3
  86. package/dist/run-launch.js +6 -5
  87. package/dist/run-learning-served.d.ts +11 -0
  88. package/dist/run-reads-over-store.d.ts +4 -2
  89. package/dist/run-reads-over-store.js +10 -8
  90. package/dist/run-timeline-served.js +12 -2
  91. package/dist/run-view.d.ts +30 -14
  92. package/dist/run-view.js +60 -32
  93. package/dist/runnable.d.ts +4 -1
  94. package/dist/runnable.js +14 -2
  95. package/dist/runner/adapter-loop.d.ts +30 -4
  96. package/dist/runner/adapter-loop.js +253 -29
  97. package/dist/runner/adapter-run-spec.d.ts +21 -0
  98. package/dist/runner/adapter-run-spec.js +104 -28
  99. package/dist/runner/adapters/pi.d.ts +29 -1
  100. package/dist/runner/adapters/pi.js +95 -23
  101. package/dist/runner/beside.d.ts +8 -0
  102. package/dist/runner/beside.js +18 -0
  103. package/dist/runner/claim-secrets.d.ts +6 -0
  104. package/dist/runner/claim-secrets.js +15 -1
  105. package/dist/runner/cli-run-spec.d.ts +3 -0
  106. package/dist/runner/cli-run-spec.js +123 -34
  107. package/dist/runner/conformance/harness.d.ts +1 -0
  108. package/dist/runner/conformance/harness.js +5 -5
  109. package/dist/runner/github-app.d.ts +7 -2
  110. package/dist/runner/github-app.js +46 -15
  111. package/dist/runner/harness-loops.d.ts +6 -1
  112. package/dist/runner/harness-loops.js +23 -0
  113. package/dist/runner/journal-kinds.d.ts +38 -2
  114. package/dist/runner/journal-kinds.js +23 -0
  115. package/dist/runner/learning-end.js +88 -16
  116. package/dist/runner/learning-loop.d.ts +2 -0
  117. package/dist/runner/learning-loop.js +13 -5
  118. package/dist/runner/learning-seed.d.ts +6 -0
  119. package/dist/runner/learning-seed.js +6 -0
  120. package/dist/runner/loop-contract.d.ts +4 -0
  121. package/dist/runner/main.d.ts +9 -4
  122. package/dist/runner/main.js +26 -11
  123. package/dist/runner/mcp-claim.d.ts +3 -0
  124. package/dist/runner/mcp-claim.js +6 -1
  125. package/dist/runner/mcp-github.d.ts +11 -2
  126. package/dist/runner/mcp-github.js +55 -4
  127. package/dist/runner/mcp-run.js +1 -0
  128. package/dist/runner/metrics.d.ts +14 -1
  129. package/dist/runner/metrics.js +72 -1
  130. package/dist/runner/model-route.d.ts +3 -0
  131. package/dist/runner/model-route.js +1 -1
  132. package/dist/runner/runner.js +90 -8
  133. package/dist/runner/spec-holds.d.ts +7 -2
  134. package/dist/runner/spec-holds.js +4 -3
  135. package/dist/runner/workflow-host.d.ts +7 -2
  136. package/dist/runner/workflow-host.js +3 -1
  137. package/dist/runner/workflow-loop.d.ts +4 -1
  138. package/dist/runner/workflow-loop.js +8 -2
  139. package/dist/runner/workflow-spec.d.ts +3 -0
  140. package/dist/runner/workflow-spec.js +156 -78
  141. package/dist/runs-over-store.d.ts +7 -1
  142. package/dist/runs-over-store.js +42 -11
  143. package/dist/seal-key.d.ts +0 -2
  144. package/dist/seal-key.js +0 -2
  145. package/dist/server-lock.js +4 -5
  146. package/dist/server.d.ts +21 -18
  147. package/dist/server.js +183 -34
  148. package/dist/stop-signals.d.ts +4 -2
  149. package/dist/stop-signals.js +5 -3
  150. package/dist/store/agent-body.d.ts +5 -1
  151. package/dist/store/agent-body.js +11 -5
  152. package/dist/store/deadline.d.ts +18 -0
  153. package/dist/store/deadline.js +45 -0
  154. package/dist/store/postgres/connection.d.ts +4 -0
  155. package/dist/store/postgres/connection.js +55 -9
  156. package/dist/store/sqlite/connection.js +3 -38
  157. package/dist/store-reads/journal.js +39 -4
  158. package/dist/store-reads/learning.d.ts +58 -2
  159. package/dist/store-reads/learning.js +172 -7
  160. package/dist/store-view.d.ts +15 -1
  161. package/dist/store-view.js +45 -12
  162. package/dist/templates.d.ts +9 -4
  163. package/dist/templates.js +14 -9
  164. package/dist/timeline/timeline.d.ts +8 -0
  165. package/dist/tool-budget.d.ts +18 -0
  166. package/dist/tool-budget.js +50 -0
  167. package/dist/tool-gate.d.ts +6 -2
  168. package/dist/tool-gate.js +8 -5
  169. package/dist/tool-plane.d.ts +9 -10
  170. package/dist/tools.d.ts +37 -7
  171. package/dist/tools.js +73 -12
  172. package/dist/uploads.d.ts +28 -5
  173. package/dist/uploads.js +82 -9
  174. package/dist/usage.d.ts +1 -47
  175. package/dist/usage.js +3 -82
  176. package/dist/validate.d.ts +2 -0
  177. package/dist/validate.js +11 -1
  178. package/dist/workspace/archil-claim.d.ts +2 -2
  179. package/dist/workspace/archil-claim.js +4 -3
  180. package/dist/workspace/archil-disk.d.ts +10 -1
  181. package/dist/workspace/archil-disk.js +4 -0
  182. package/dist/workspace/archil-exec.d.ts +12 -2
  183. package/dist/workspace/archil-exec.js +16 -0
  184. package/dist/workspace/archil.d.ts +2 -2
  185. package/dist/workspace/archil.js +25 -5
  186. package/dist/workspace/attach.js +2 -0
  187. package/dist/workspace/computer-deps.d.ts +9 -10
  188. package/dist/workspace/computer-deps.js +53 -40
  189. package/dist/workspace/computer-for-claim.d.ts +5 -3
  190. package/dist/workspace/computer-for-claim.js +28 -16
  191. package/dist/workspace/computer-ledger.d.ts +1 -8
  192. package/dist/workspace/computer-ledger.js +0 -3
  193. package/dist/workspace/computer-providers.d.ts +5 -3
  194. package/dist/workspace/computer-providers.js +11 -9
  195. package/dist/workspace/hands.d.ts +5 -2
  196. package/dist/workspace/hands.js +4 -3
  197. package/dist/workspace/index.d.ts +3 -3
  198. package/dist/workspace/index.js +1 -1
  199. package/dist/workspace/local.d.ts +3 -0
  200. package/dist/workspace/local.js +9 -0
  201. package/dist/workspace/paths.js +3 -2
  202. package/dist/workspace/pi-env.d.ts +4 -0
  203. package/dist/workspace/pi-env.js +3 -2
  204. package/dist/workspace/resolve-computer.d.ts +8 -3
  205. package/dist/workspace/resolve-computer.js +28 -11
  206. package/dist/workspace/run-tools.d.ts +2 -0
  207. package/dist/workspace/run-tools.js +9 -3
  208. package/dist/workspace/workspace.d.ts +5 -0
  209. package/dist/workspace.d.ts +0 -3
  210. package/dist/workspace.js +1 -14
  211. package/package.json +14 -14
  212. package/skills/agentrun-serve/SKILL.md +1 -1
  213. package/templates/README.md +2 -2
  214. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  215. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  216. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  217. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  218. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  219. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  220. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  221. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  222. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  223. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  224. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  225. package/templates/release-notes/agent.md +11 -0
  226. package/dist/console/assets/index-RPHGlXmM.js +0 -540
  227. package/dist/console/assets/index-opTN5Naq.css +0 -1
@@ -5,7 +5,10 @@ import { withLearning } from "./learning-run.js";
5
5
  import { runLearningEnd } from "./store-reads/learning.js";
6
6
  import { redacted } from "./key-refusal.js";
7
7
  import { runCutValues, runErrorWordsOf } from "./run-cut.js";
8
- import { answersOf, asksOf, shownOf, withApprovalRows, withAsks } from "./run-view.js";
8
+ import { answersOf, asksOf, shownOf, withApprovalRows, withAsks, withBudgetRows, withOverCap } from "./run-view.js";
9
+ import { launchOf } from "./handed-values.js";
10
+ import { capNowOf } from "./runner/journal-kinds.js";
11
+ import { overCapBound } from "./runner/metrics.js";
9
12
  import { journalRecords } from "./runner/journal-reader.js";
10
13
  import { decisionsOverStore } from "./store-reads/decisions.js";
11
14
  import { readRun } from "./store-reads/runs.js";
@@ -35,7 +38,14 @@ export async function servedTimelineRows(deps, store, runId, context) {
35
38
  // is a cost unknown, never one still running.
36
39
  const options = { redact, settled: ended };
37
40
  const timeline = await wholeAnswers(store, runId, context, await runTimeline(store, runId, context, options), options, wholeAnswerFor(values));
38
- const rows = withApprovalRows(withAsks(timeline), asksOf(records.entries), answersOf(records.entries, { final }), redact);
41
+ // A run whose booked spend passed its cap says so, by how much, after its usage row (run-view.ts withOverCap, as main's
42
+ // served Timeline did): at the cap as it stands (a raise taken counts, capNowOf), a cache miss within the bound of the
43
+ // requests since its spend last fit said as one (overCapBound).
44
+ const capNow = capNowOf((await launchOf(store, runId))?.maxCostUsd, records.entries);
45
+ const overCap = capNow === undefined ? timeline : withOverCap(timeline, capNow, overCapBound(records.entries, capNow));
46
+ // Each pause at its cap shown as the server's row, and the one it stands at now as its waiting row (withBudgetRows).
47
+ const capped = withBudgetRows(overCap, records.entries, { ended });
48
+ const rows = withApprovalRows(withAsks(capped), asksOf(records.entries), answersOf(records.entries, { final }), redact);
39
49
  // A workflow's decisions: their rows among the model nodes' by time, each text shown through the cut set, with as many
40
50
  // characters held back from a text stored cut as a held value takes in its widest form (main's decisionShown).
41
51
  const receipts = await decisionsOverStore(store, runId, context).catch(() => null);
@@ -47,9 +47,6 @@ export declare const overByMiss: (usd: number, cap: number, bound: number) => bo
47
47
  * so a run can pass its cap by its last request. The next request is then refused. `bound`: the requests' that ended since the cost last fit,
48
48
  * bound; when the run passed its cap by no more than it, the row says a cache miss did it, and the most it could have. */
49
49
  export declare function withOverCap(rows: TimelineEvent[], cap: number | undefined, bound?: number): TimelineEvent[];
50
- /** The waiting row of a run paused at its cap, after the refusal's row: "Waiting for you to raise the cap", and no
51
- * more: the refusal's words are the pause's (pending.said), which a client shows once, as its banner. */
52
- export declare const BUDGET_WAITING = "Waiting for you to raise the cap";
53
50
  /** The waiting row after each answered `ask_person` call, which the timeline module does not know. The question comes from
54
51
  * the call's row, whose label this module registers. The server fed its rows through this; the store-backed view feeds the
55
52
  * same rows through it, so a run waiting on a question reads the same pending. */
@@ -89,6 +86,7 @@ export type ApprovalAnswer = {
89
86
  export declare const withdrawn: (answer: ApprovalAnswer | undefined) => boolean;
90
87
  /** The least a journal entry a reader here reads is: its kind and its data. */
91
88
  type JournalEntry = {
89
+ id?: unknown;
92
90
  kind?: string;
93
91
  data?: unknown;
94
92
  };
@@ -110,10 +108,27 @@ export declare function asksOf(entries: readonly JournalEntry[]): Map<string, Ap
110
108
  export declare function answersOf(entries: readonly JournalEntry[], { final }?: {
111
109
  final?: "stopped" | "failed";
112
110
  }): Record<string, ApprovalAnswer>;
113
- /** Whether the run stands parked at its cap now (an active agentrun.budget park, no raise since): the store-backed fact the
114
- * status table reads (RunFacts.budgetWaiting), as the file-backed view read a workflow's pause file and an agentic run's
115
- * turn refusal. */
116
- export declare const budgetWaitingOf: (entries: readonly JournalEntry[]) => boolean;
111
+ /** The server's row of a run's pause at its cap, and its waiting row while it stands paused: the pause's own words are
112
+ * its pending budget's `said`, which a client shows once as its banner, so these rows say no more (#1768). */
113
+ export declare const BUDGET_PAUSED = "Paused at the run's cap";
114
+ export declare const BUDGET_WAITING = "Waiting for you to raise the cap";
115
+ /** `rows` with each pause at the run's cap shown (its agentrun.budget entry: the cap refused the next step for room, and
116
+ * nothing was sent): the server's `phase` row "Paused at the run's cap" (origin server, `paused: true`, its id ending
117
+ * NOTE_SUFFIX, so no message any turn took) where the pause came in the journal's order, kept as the run's history once
118
+ * a raise clears it; and, after the pause the run stands at now, its `waiting` row "Waiting for you to raise the cap".
119
+ * Each new row takes its time from the row before it. `ended`: the run is final (cancelled while paused, say), so it
120
+ * waits on nothing and shows no waiting row. */
121
+ export declare function withBudgetRows(rows: readonly TimelineEvent[], entries: readonly (JournalEntry & {
122
+ conversationId?: unknown;
123
+ })[], { ended }?: {
124
+ ended?: boolean;
125
+ }): TimelineEvent[];
126
+ /** The id of the cap park a run stands at now (its agentrun.budget entry's), or undefined when it is not parked: a raise's
127
+ * follow-up is sent as `agentrun:raise:<this>` (raiseFollowUpId), so a raise's answer names that message. */
128
+ export declare const activePauseOf: (entries: readonly JournalEntry[]) => string | undefined;
129
+ /** The id a raised run's follow-up turn is sent under: one per pause, so raises of the same pause (a retry, two at once)
130
+ * name the same message, and the runner's re-claim never sends it twice. */
131
+ export declare const raiseFollowUpId: (pause: string) => string;
117
132
  /** The budget card a run parked at its cap shows (pending, kind budget), from its agentrun.budget entry, the same way the
118
133
  * file-backed view built it from the run's pause mark (runs.ts workflowBudgetPending): its cap (the run's launch cap, else
119
134
  * the park's), what the cap counted as taken and the least the refused step needs, the raise offered (recomputed from
@@ -172,6 +187,8 @@ export interface RunView {
172
187
  * view, from the cap park entry): the moment reads them when `pausedAt` finds no turn refusal, so a run parked at its cap
173
188
  * reads paused either way. The file-backed view leaves this unset and the moment reads `pausedAt`. */
174
189
  pausedWords?: string;
190
+ /** The cap park the run stands at (activePauseOf), when the store-backed view knows it: the moment's `pause`. */
191
+ pause?: string;
175
192
  meta: RunViewMeta;
176
193
  }
177
194
  /** The facts statusOf reads from a run's files (its directory): a workflow paused at its cap, a workflow paused in its
@@ -181,7 +198,7 @@ export interface RunView {
181
198
  export interface RunFacts {
182
199
  /** A workflow run paused at its cap, as its process wrote it (budgetWaiting). */
183
200
  budgetWaiting(): boolean;
184
- /** A workflow run paused in its process (pausedIn(run.dir)). */
201
+ /** A workflow run paused (the store-backed view reads it from the run's journal). */
185
202
  paused(): boolean;
186
203
  /** The ask its agent made for the person in its browser the run waits on (browser-commands.ts browserAsk, over its journal). */
187
204
  browserAsk(): PendingAsk | undefined;
@@ -271,12 +288,6 @@ export type Pending = {
271
288
  export declare const pendingOf: (rows: readonly TimelineEvent[]) => Pending;
272
289
  /** The run's pending approval (`pending`, kind approval): the call that waits; else undefined. */
273
290
  export declare const approvalOf: (run: Pick<RunView, "approvals" | "meta">, redact: (text: string) => string) => PendingApproval | undefined;
274
- /** A run paused at its cap waits on a raise: its cap, what the cap counted as taken and the least the refused request
275
- * needs (its refusal's mark; none from a store written before it kept them), the raise it is offered (suggestedCap),
276
- * the refusal's words, and when it came (its error row's time). The figures are as the cap counts them, never rounded.
277
- * What was taken is the store's spend once its process is gone (`spentNow`), when that is lower: the refusal counted
278
- * requests still answering at what it held for them, and they have settled. */
279
- export declare const budgetPending: (run: RunView, spentNow?: number) => Pending | undefined;
280
291
  /** A run whose agent asked for the person in its browser waits on their hand-back: what it asked them to do, when it is
281
292
  * done, and when the ask expires. Never the session's tag or the live view's link. The two texts are the model's, so
282
293
  * redacted with the run's redactor (`redact`), as a tool call's arguments are: a held value it echoes never shows. */
@@ -326,6 +337,9 @@ export interface RunMoment {
326
337
  readonly pausedWords?: string;
327
338
  /** The run is paused at its cap (pausedAt): raising the cap resumes it. */
328
339
  readonly paused: boolean;
340
+ /** The cap park it stands at (its agentrun.budget entry's id, activePauseOf), when the store knows it: a raise's answer
341
+ * names the follow-up message the runner sends for it (raiseFollowUpId). */
342
+ readonly pause?: string;
329
343
  /** The run has a live process now (a runner holds its claim): a raise's cap holds from its next step, not the one under
330
344
  * way. */
331
345
  readonly live: boolean;
@@ -376,6 +390,8 @@ export declare const servedRunErrorWith: <E extends {
376
390
  * other words are while the run is hidden (`unshown`), as a list row read from disk withholds it. */
377
391
  export declare const servedReviewWith: <R extends {
378
392
  reason: string;
393
+ kind?: string | null;
394
+ node?: string | null;
379
395
  }>(shown: (text: string) => string, unshown: boolean | undefined, review: R | null) => R | null;
380
396
  /** The pointers a run was handed, read back to cut them (sign-ins-store.ts peek and forgotten), by its `sign_in_handed`: none
381
397
  * for a run with no mark (it was never handed one); else, for each hash it names, the live or forgotten pointer whose
package/dist/run-view.js CHANGED
@@ -6,7 +6,7 @@
6
6
  // The pieces here so far: the cost reads (a run's cost, its paid tools' charges, the cost a view shows, what it has cost so
7
7
  // far when the total is unknown) and the served row transforms a view applies to the timeline (the over-cap row, the
8
8
  // paused run's waiting row). All read the same rows the timeline renders.
9
- import { chargedTool, isMessageRow, registerLabel, registerTurnEnding, scrubUrls } from "./timeline/index.js";
9
+ import { chargedTool, isMessageRow, NOTE_SUFFIX, registerLabel, registerTurnEnding, scrubUrls } from "./timeline/index.js";
10
10
  import { CAP_TOLERANCE, FIT_TOLERANCE, money, roomRefusal } from "./cap.js";
11
11
  import { APPROVAL_ROW, previewOf } from "./tool-gate.js";
12
12
  import { ASK_TOOL } from "./tools.js";
@@ -85,9 +85,6 @@ export function withOverCap(rows, cap, bound = 0) {
85
85
  const over = { ...usage, id: `${usage.id}:over_cap`, kind: "phase", summary, text: null };
86
86
  return [...rows.slice(0, at + 1), over, ...rows.slice(at + 1)];
87
87
  }
88
- /** The waiting row of a run paused at its cap, after the refusal's row: "Waiting for you to raise the cap", and no
89
- * more: the refusal's words are the pause's (pending.said), which a client shows once, as its banner. */
90
- export const BUDGET_WAITING = "Waiting for you to raise the cap";
91
88
  /** A text clipped to `max` characters, with an ellipsis where it is cut (runs.ts' clip). */
92
89
  const clip = (text, max) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);
93
90
  const ASKED = "Asked you: ";
@@ -197,19 +194,61 @@ export function answersOf(entries, { final } = {}) {
197
194
  * room, unless an agentrun.raise after it cleared the pause (the run goes on at the raised cap then). A re-park writes a
198
195
  * fresh budget entry, which a raise before it does not clear, so the last of the two in log order decides. */
199
196
  function activeBudget(entries) {
200
- let mark;
197
+ return activePark(entries)?.mark;
198
+ }
199
+ /** The active cap park and its entry's id: the pause the runner keys a raise's follow-up by (adapter-loop raiseStateOf). */
200
+ function activePark(entries) {
201
+ let park;
201
202
  for (const entry of entries) {
202
203
  if (entry.kind === KINDS.budget)
203
- mark = dataOf(entry);
204
+ park = { mark: dataOf(entry), id: String(entry.id) };
204
205
  else if (entry.kind === KINDS.raise)
205
- mark = undefined;
206
+ park = undefined;
206
207
  }
207
- return mark;
208
+ return park;
208
209
  }
209
- /** Whether the run stands parked at its cap now (an active agentrun.budget park, no raise since): the store-backed fact the
210
- * status table reads (RunFacts.budgetWaiting), as the file-backed view read a workflow's pause file and an agentic run's
211
- * turn refusal. */
212
- export const budgetWaitingOf = (entries) => activeBudget(entries) !== undefined;
210
+ /** The server's row of a run's pause at its cap, and its waiting row while it stands paused: the pause's own words are
211
+ * its pending budget's `said`, which a client shows once as its banner, so these rows say no more (#1768). */
212
+ export const BUDGET_PAUSED = "Paused at the run's cap";
213
+ export const BUDGET_WAITING = "Waiting for you to raise the cap";
214
+ /** `rows` with each pause at the run's cap shown (its agentrun.budget entry: the cap refused the next step for room, and
215
+ * nothing was sent): the server's `phase` row "Paused at the run's cap" (origin server, `paused: true`, its id ending
216
+ * NOTE_SUFFIX, so no message any turn took) where the pause came in the journal's order, kept as the run's history once
217
+ * a raise clears it; and, after the pause the run stands at now, its `waiting` row "Waiting for you to raise the cap".
218
+ * Each new row takes its time from the row before it. `ended`: the run is final (cancelled while paused, say), so it
219
+ * waits on nothing and shows no waiting row. */
220
+ export function withBudgetRows(rows, entries, { ended = false } = {}) {
221
+ const parks = entries.filter((entry) => entry.kind === KINDS.budget).map((entry) => ({ id: Number(entry.id), conversation: Number(entry.conversationId ?? 1) }));
222
+ if (parks.length === 0)
223
+ return [...rows];
224
+ const active = ended ? undefined : activePauseOf(entries);
225
+ const entryOf = (row) => Number(row.id.split(":")[1]);
226
+ const out = [...rows];
227
+ for (const park of parks) {
228
+ // Before the first row of a later entry; else before a trailing usage row, the run's last.
229
+ let at = out.findIndex((row) => entryOf(row) > park.id);
230
+ if (at < 0)
231
+ at = out.length > 0 && out[out.length - 1].kind === "usage" ? out.length - 1 : out.length;
232
+ const base = out[at - 1] ?? out[at];
233
+ const timestamp = base?.timestamp ?? new Date(0).toISOString();
234
+ const row = (id, kind, summary, more) => ({
235
+ id, timestamp, created_at: base?.created_at ?? timestamp, kind, summary, agent_label: null, tool_name: null, tool_use_id: null, tool_status: null,
236
+ tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null, text: null, conversation_id: park.conversation,
237
+ ...(base?.seq !== undefined ? { seq: base.seq } : {}), ...more,
238
+ });
239
+ const shown = [row(`${park.conversation}:${park.id}${NOTE_SUFFIX}`, "phase", BUDGET_PAUSED, { origin: "server", paused: true })];
240
+ if (String(park.id) === active)
241
+ shown.push(row(`${park.conversation}:${park.id}:waiting`, "waiting", BUDGET_WAITING, { text: BUDGET_WAITING }));
242
+ out.splice(at, 0, ...shown);
243
+ }
244
+ return out;
245
+ }
246
+ /** The id of the cap park a run stands at now (its agentrun.budget entry's), or undefined when it is not parked: a raise's
247
+ * follow-up is sent as `agentrun:raise:<this>` (raiseFollowUpId), so a raise's answer names that message. */
248
+ export const activePauseOf = (entries) => activePark(entries)?.id;
249
+ /** The id a raised run's follow-up turn is sent under: one per pause, so raises of the same pause (a retry, two at once)
250
+ * name the same message, and the runner's re-claim never sends it twice. */
251
+ export const raiseFollowUpId = (pause) => `agentrun:raise:${pause}`;
213
252
  /** The budget card a run parked at its cap shows (pending, kind budget), from its agentrun.budget entry, the same way the
214
253
  * file-backed view built it from the run's pause mark (runs.ts workflowBudgetPending): its cap (the run's launch cap, else
215
254
  * the park's), what the cap counted as taken and the least the refused step needs, the raise offered (recomputed from
@@ -316,25 +355,6 @@ export const approvalOf = (run, redact) => {
316
355
  const waiting = waitingApproval(run);
317
356
  return waiting ? { kind: "approval", id: waiting.id, tool: waiting.tool, call_id: waiting.call_id, args_preview: shownArgs(waiting, redact), requested_at: waiting.requested_at, ...(waiting.price !== undefined ? { price: waiting.price } : {}) } : undefined;
318
357
  };
319
- /** A run paused at its cap waits on a raise: its cap, what the cap counted as taken and the least the refused request
320
- * needs (its refusal's mark; none from a store written before it kept them), the raise it is offered (suggestedCap),
321
- * the refusal's words, and when it came (its error row's time). The figures are as the cap counts them, never rounded.
322
- * What was taken is the store's spend once its process is gone (`spentNow`), when that is lower: the refusal counted
323
- * requests still answering at what it held for them, and they have settled. */
324
- export const budgetPending = (run, spentNow) => {
325
- const said = pausedAt(run);
326
- const cap = run.meta.max_cost_usd;
327
- if (said === undefined || cap === undefined)
328
- return undefined;
329
- const r = run.capRefusal;
330
- const spent = r && spentNow !== undefined ? Math.min(r.spentUsd, spentNow) : r?.spentUsd;
331
- // Shown as cost.usd is (to a millionth of a dollar), the suggestion from the figures as the cap counts them. The least cap
332
- // that sends the refused request is the one its words name (`said`), carried from the refusal that wrote them, never
333
- // worked out again here from figures that may have moved since. With them, the most a cache miss could make the refused
334
- // request cost beyond what it needs (cap.ts), 0 for none.
335
- const figures = r && spent !== undefined ? { spent_usd: micro(spent), needs_usd: micro(r.needsUsd), least_cap_usd: r.leastCapUsd, suggested_cap_usd: suggestedCap(cap, spent, r.needsUsd), overshoot_bound_usd: microUp(r.boundUsd ?? 0) } : {};
336
- return { kind: "budget", cap_usd: cap, ...figures, said, at: meaningful(run.rows)?.timestamp ?? run.updatedAt };
337
- };
338
358
  /** A run whose agent asked for the person in its browser waits on their hand-back: what it asked them to do, when it is
339
359
  * done, and when the ask expires. Never the session's tag or the live view's link. The two texts are the model's, so
340
360
  * redacted with the run's redactor (`redact`), as a tool call's arguments are: a held value it echoes never shows. */
@@ -433,6 +453,7 @@ export function momentOf(run, facts, live) {
433
453
  ...(run.meta.max_cost_usd !== undefined ? { maxCostUsd: run.meta.max_cost_usd } : {}),
434
454
  ...(pausedWords !== undefined ? { pausedWords } : {}),
435
455
  paused: pausedWords !== undefined,
456
+ ...(pausedWords !== undefined && run.pause !== undefined ? { pause: run.pause } : {}),
436
457
  live,
437
458
  // Whether it waits on a person (runs.ts waitsOnPerson): a parked approval, a pause at its cap (read through a message
438
459
  // counted but not shown), or a question its turn ended on.
@@ -477,7 +498,14 @@ export const shownOf = (values) => (text) => withoutLoopback(redacted(text, valu
477
498
  export const servedRunErrorWith = (shown, error) => ({ ...error, message: shown(error.message), ...(error.details !== undefined ? { details: cutStrings(error.details, shown) } : {}) });
478
499
  /** A run's review as its view serves it: its reason (an escalation's own words) in `shown`'s terms, or withheld as its
479
500
  * other words are while the run is hidden (`unshown`), as a list row read from disk withholds it. */
480
- export const servedReviewWith = (shown, unshown, review) => (review && { ...review, reason: unshown ? WITHHELD_SIGN_IN : shown(review.reason) });
501
+ export const servedReviewWith = (shown, unshown, review) => review && {
502
+ ...review,
503
+ // Every word of it is the run's (its escalate node's kind and label, as the workflow wrote them): cut as the reason is,
504
+ // and withheld with it.
505
+ ...("kind" in review ? { kind: unshown || review.kind == null ? null : shown(review.kind) } : {}),
506
+ ...("node" in review ? { node: unshown || review.node == null ? null : shown(review.node) } : {}),
507
+ reason: unshown ? WITHHELD_SIGN_IN : shown(review.reason),
508
+ };
481
509
  /** The pointers a run was handed, read back to cut them (sign-ins-store.ts peek and forgotten), by its `sign_in_handed`: none
482
510
  * for a run with no mark (it was never handed one); else, for each hash it names, the live or forgotten pointer whose
483
511
  * SHA-256 it is. `unreadable` when what it was handed can't be read back here: a MALFORMED mark, no vendor browser kept
@@ -7,10 +7,12 @@ import type { McpTool } from "@parcha/agentrun-kernel";
7
7
  import type { ShellPlace } from "@parcha/agentrun-kernel/kernel";
8
8
  /** The harnesses an agent's MCP tools run on here. */
9
9
  export declare const MCP_HARNESSES: readonly string[];
10
- /** A revision's computer setting: a kind, its provider, and a sandbox's GPUs (computer-setting.ts). */
10
+ /** A revision's computer setting: a kind, its provider, the image it starts from, and a sandbox's GPUs
11
+ * (computer-setting.ts). */
11
12
  export type RevisionComputer = {
12
13
  kind: string;
13
14
  provider?: string;
15
+ image?: string;
14
16
  gpu?: {
15
17
  type: string;
16
18
  count: number;
@@ -32,6 +34,7 @@ export type RevisionShape = {
32
34
  unnamed?: true;
33
35
  toolSettings?: ToolSettingsMap;
34
36
  approvals?: "never";
37
+ maxToolCalls?: number;
35
38
  } | {
36
39
  kind: "workflow";
37
40
  workflow: unknown;
package/dist/runnable.js CHANGED
@@ -187,6 +187,10 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
187
187
  unavailable(`definition.tools[${index}]`, revision.tools ?? [], tool);
188
188
  }
189
189
  });
190
+ // The tool-call budget is counted from pi's own journal (tool-budget.ts): on another harness it would hold nothing, so
191
+ // the definition is refused, never saved to run without it.
192
+ if (revision.maxToolCalls !== undefined && onAdapter(env, harness))
193
+ out.push({ field: "definition.max_tool_calls", reason: NOT_SET_UP, message: `A tool-call budget is held on pi here; on ${harness} it is not counted yet.`, fix: "Run the agent on pi, or set max_tool_calls to 0.", host: false, harness });
190
194
  const resolved = await harnessModel(env, harness, revision.model, offer?.available === true);
191
195
  if (!resolved)
192
196
  return out;
@@ -201,6 +205,16 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
201
205
  out.push({ field: "definition.model", reason: NOT_SET_UP, message: `The model ${id} has no price here, so a run's spend cap cannot be kept on it.`, fix: PRICE_FIX, host: true, unpriced: true });
202
206
  return out;
203
207
  }
208
+ const { inspectWorkflow } = await import("@parcha/agentrun-dsl");
209
+ // A workflow the DSL cannot read is the definition's fault (422 on the field), never the server's (500).
210
+ let inspection;
211
+ try {
212
+ inspection = inspectWorkflow(revision.workflow);
213
+ }
214
+ catch (error) {
215
+ out.push({ field: "definition.workflow", reason: "not_an_option", message: `The workflow is not one this server can read: ${String(error?.message ?? error).slice(0, 500)}`, host: false });
216
+ return out;
217
+ }
204
218
  // Every MCP tool a workflow grants, at its top level or on a node, is held to the one check (mcpGrant): refused at the
205
219
  // save, never a workflow whose run goes without it or cannot launch.
206
220
  const granted = await grantedTools(revision);
@@ -213,8 +227,6 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
213
227
  // A workflow's model nodes run on pi here; on another harness they are not bound yet, and never run on pi instead.
214
228
  if (onAdapter(env, harness))
215
229
  out.push({ field: "definition.workflow", reason: NOT_SET_UP, message: `A workflow runs on pi here; on ${harness} its model nodes are not bound yet.`, host: true, harness });
216
- const { inspectWorkflow } = await import("@parcha/agentrun-dsl");
217
- const inspection = inspectWorkflow(revision.workflow);
218
230
  const { requires } = inspection;
219
231
  const nodes = workflowNodes(revision.workflow, inspection);
220
232
  const runs = "agentrun-serve runs a workflow's model nodes (agent, decide, extract, report)";
@@ -47,11 +47,17 @@ export type GateAnswer = "allow" | "ask" | "deny" | {
47
47
  readonly deny: string;
48
48
  };
49
49
  /** The gate before a call's intent; `askedAs`, when it has one, names a call as a person is asked about it (its settings
50
- * key, as main's pending approval names it), else the call is asked about by its own name. */
51
- export type SpecGate = ((call: ToolCall) => GateAnswer | Promise<GateAnswer>) & {
50
+ * key, as main's pending approval names it), else the call is asked about by its own name. `replayed`: asked again for a
51
+ * call run again after an earlier attempt that may have been sent, so a refusal's words never say nothing was sent. */
52
+ export type SpecGate = ((call: ToolCall, options?: {
53
+ readonly replayed?: boolean;
54
+ }) => GateAnswer | Promise<GateAnswer>) & {
52
55
  readonly askedAs?: (tool: string) => string;
53
56
  /** What an asked call's card shows beside its input (a learned workflow's MCP calls it would make), if anything. */
54
57
  readonly askedFor?: (tool: string, args: unknown) => Promise<Record<string, unknown> | undefined>;
58
+ /** The revision's tool-call budget (definition.max_tool_calls, tool-budget.ts): the calls each conversation may make. A
59
+ * call past it is refused before anything else is asked; one the adapter counts no calls for (a CLI's) is not held. */
60
+ readonly toolCalls?: number;
55
61
  };
56
62
  /** What one claimed run's adapter loop runs. */
57
63
  export interface AdapterRunSpec {
@@ -113,9 +119,20 @@ export interface AdapterRunSpec {
113
119
  * them): it wins over LoopDeps.endOfRun and is asked where that one is, in the end turn while the claim is held, before
114
120
  * a tool host's beforeRelease and the run's release, its rows in the end's commit. */
115
121
  readonly endOfRun?: EndOfRunTurn;
122
+ /** What the claim laid of the run's learning seed (runner/learning-seed.ts): the learned skills and workflows it was
123
+ * given, by name. The loop writes it on the root (KINDS.learningLaid) as this claim opens. Absent for a run that does
124
+ * not learn. */
125
+ readonly learningLaid?: {
126
+ readonly skills: readonly string[];
127
+ readonly workflows: readonly string[];
128
+ };
116
129
  /** The run's work folder, as its file tools resolve a path: what the end-of-run turn's refusal under work/.learning/
117
130
  * reads an absolute path against. Absent: a relative path, or the box's, still counts. */
118
131
  readonly workRoot?: string;
132
+ /** The harness's working directory (a CLI's, SessionIO.cwd), which the absolute paths its calls name are built from:
133
+ * kept on each call's start in the record (CallStartData.cwd), so the run's rows name such a path by its name in the
134
+ * workspace (store-reads/journal.ts runTimeline). */
135
+ readonly cwd?: string;
119
136
  /** The end's patch beside its state: the run's outcome, cost and metrics, read when the end is written and carried in
120
137
  * its commit. Bounded (CUT_STEP_MS): a reader that stalls gives no patch, and the end is still written. */
121
138
  readonly endPatch?: (end: EndData) => Promise<Pick<EndData, "outcome" | "costUsd" | "metrics">>;
@@ -211,8 +228,9 @@ export interface RunLedger {
211
228
  readonly paid: RunTools;
212
229
  /** The session's proxied models for a request the host sends beside the harness's own, under `label` (portModels on
213
230
  * the session's port), read at each request: a spec may take them at its build, before the session opens; a request
214
- * made while no port is up (no session, or a harness with none) finds no model. */
215
- models(label: string): Promise<PortModels>;
231
+ * made while no port is up (no session, or a harness with none) finds no model. `tier`: the run's model of that tier
232
+ * (AdapterSession.port's `tier`), listed under tierProvider(tier). */
233
+ models(label: string, tier?: string): Promise<PortModels>;
216
234
  /** A paid call the run's cap refused that pauses the run (an agent's ask for a person's browser time: main's paidCall
217
235
  * pause): its pause is journaled at once, as a refused request's is (pauseAtCap), and the run's next request is refused
218
236
  * in its words, so the run parks there with the cap's figures. A take-over's refusal pauses nothing: it is not called. */
@@ -231,6 +249,14 @@ export interface AdapterLoopOptions {
231
249
  /** For tests: awaited as a wait in the claim on the person's answer starts, before it takes their messages. */
232
250
  readonly beforePersonWait?: () => Promise<void>;
233
251
  }
252
+ /** A paid call's refusal an earlier claim kept (KINDS.pausePending) whose pause never landed: the newest one with no
253
+ * pause (KINDS.budget), no end and no park on a person's question (KINDS.personAsked: the turn ended on the ask with no
254
+ * next request, so the refusal is spent, and the person's answer is no retry of the call) after it. Undefined when there
255
+ * is none. */
256
+ export declare function pendingPauseOf(entries: readonly {
257
+ readonly kind?: string;
258
+ readonly data?: unknown;
259
+ }[]): Refusal | undefined;
234
260
  /** The turns a session's records booked (its runner.turn records), in order. */
235
261
  export declare function turnsOf(records: readonly SessionRecord[]): number[];
236
262
  /** What the request that just answered cost, from the session's records, and the bookings that answer gives (`turns`):