@parcha/agentrun-serve 0.1.0-beta.41 → 0.1.0-beta.43

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 (164) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/NOTICE +2 -0
  3. package/README.md +85 -19
  4. package/dist/agent-rows.d.ts +1 -1
  5. package/dist/agents-store.js +3 -1
  6. package/dist/calendar/address.d.ts +49 -0
  7. package/dist/calendar/address.js +153 -0
  8. package/dist/calendar/fetch.d.ts +24 -0
  9. package/dist/calendar/fetch.js +146 -0
  10. package/dist/calendar/ics-faux.d.ts +39 -0
  11. package/dist/calendar/ics-faux.js +236 -0
  12. package/dist/calendar/labels.d.ts +3 -0
  13. package/dist/calendar/labels.js +61 -0
  14. package/dist/calendar/names.d.ts +52 -0
  15. package/dist/calendar/names.js +54 -0
  16. package/dist/calendar/parse.d.ts +108 -0
  17. package/dist/calendar/parse.js +625 -0
  18. package/dist/calendar/routes.d.ts +17 -0
  19. package/dist/calendar/routes.js +81 -0
  20. package/dist/calendar/tools.d.ts +23 -0
  21. package/dist/calendar/tools.js +124 -0
  22. package/dist/cli.js +3 -1
  23. package/dist/computer-record.d.ts +55 -0
  24. package/dist/computer-record.js +315 -0
  25. package/dist/computer-setting.d.ts +1 -0
  26. package/dist/computer-setting.js +15 -2
  27. package/dist/computers.js +2 -14
  28. package/dist/console/assets/index-BrcDSBD8.css +1 -0
  29. package/dist/console/assets/index-Bz6IWncl.js +711 -0
  30. package/dist/console/index.html +2 -2
  31. package/dist/decisions.js +0 -4
  32. package/dist/eval-feed.d.ts +2 -2
  33. package/dist/eval-feed.js +9 -5
  34. package/dist/feed/parse.d.ts +3 -2
  35. package/dist/feed/parse.js +9 -18
  36. package/dist/feed/pointer.d.ts +2 -0
  37. package/dist/feed/pointer.js +17 -0
  38. package/dist/file-types.js +1 -0
  39. package/dist/host-command.d.ts +3 -0
  40. package/dist/host-command.js +18 -0
  41. package/dist/host.d.ts +3 -0
  42. package/dist/host.js +3 -0
  43. package/dist/import-sources.js +25 -5
  44. package/dist/learn/audit.d.ts +123 -0
  45. package/dist/learn/audit.js +159 -0
  46. package/dist/learn/check.d.ts +14 -0
  47. package/dist/learn/check.js +194 -14
  48. package/dist/learn/compile.d.ts +75 -78
  49. package/dist/learn/compile.js +175 -176
  50. package/dist/learn/folder.d.ts +9 -0
  51. package/dist/learn/folder.js +13 -2
  52. package/dist/learn/promote.d.ts +138 -196
  53. package/dist/learn/promote.js +68 -184
  54. package/dist/learn/replay-calls.d.ts +5 -0
  55. package/dist/learn/replay-calls.js +12 -1
  56. package/dist/learn/secrets.d.ts +8 -0
  57. package/dist/learn/secrets.js +12 -0
  58. package/dist/learn/skills.js +2 -4
  59. package/dist/learn/workflow-nodes.d.ts +1 -2
  60. package/dist/learn/workflow-nodes.js +2 -3
  61. package/dist/learned-nodes.d.ts +9 -34
  62. package/dist/learned-nodes.js +11 -23
  63. package/dist/learned-workflow.d.ts +6 -8
  64. package/dist/learned-workflow.js +18 -57
  65. package/dist/learning-batch.d.ts +13 -5
  66. package/dist/learning-batch.js +34 -8
  67. package/dist/learning-cost.d.ts +11 -4
  68. package/dist/learning-cost.js +4 -2
  69. package/dist/learning-routes.js +1 -1
  70. package/dist/learning-setting.d.ts +38 -0
  71. package/dist/learning-setting.js +83 -0
  72. package/dist/learning-words.d.ts +3 -0
  73. package/dist/learning-words.js +3 -0
  74. package/dist/learning.d.ts +3 -2
  75. package/dist/learning.js +5 -3
  76. package/dist/mcp-oauth.d.ts +8 -0
  77. package/dist/mcp-oauth.js +7 -0
  78. package/dist/mcp-private-hosts.d.ts +13 -0
  79. package/dist/mcp-private-hosts.js +16 -0
  80. package/dist/openapi.d.ts +1 -0
  81. package/dist/openapi.js +195 -59
  82. package/dist/run-files.d.ts +6 -2
  83. package/dist/run-files.js +29 -7
  84. package/dist/run-launch.d.ts +6 -3
  85. package/dist/run-launch.js +2 -0
  86. package/dist/run-learning-served.d.ts +2 -2
  87. package/dist/run-reads-over-store.d.ts +5 -1
  88. package/dist/run-reads-over-store.js +8 -4
  89. package/dist/run-recordings.d.ts +20 -0
  90. package/dist/run-recordings.js +133 -0
  91. package/dist/runner/adapter-loop.d.ts +5 -1
  92. package/dist/runner/adapter-loop.js +20 -8
  93. package/dist/runner/adapter-run-spec.d.ts +16 -1
  94. package/dist/runner/adapter-run-spec.js +36 -11
  95. package/dist/runner/audit.d.ts +64 -0
  96. package/dist/runner/audit.js +338 -0
  97. package/dist/runner/beside.js +2 -2
  98. package/dist/runner/cli-run-spec.js +25 -12
  99. package/dist/runner/feedback-round.d.ts +9 -25
  100. package/dist/runner/feedback-round.js +19 -40
  101. package/dist/runner/harness-loops.js +1 -15
  102. package/dist/runner/journal-kinds.d.ts +0 -7
  103. package/dist/runner/journal-kinds.js +0 -7
  104. package/dist/runner/learning-dispatch.d.ts +0 -16
  105. package/dist/runner/learning-dispatch.js +4 -47
  106. package/dist/runner/learning-end.d.ts +62 -13
  107. package/dist/runner/learning-end.js +180 -74
  108. package/dist/runner/learning-factory.d.ts +1 -1
  109. package/dist/runner/learning-factory.js +1 -4
  110. package/dist/runner/learning-loop.d.ts +2 -38
  111. package/dist/runner/learning-loop.js +8 -116
  112. package/dist/runner/main.d.ts +11 -0
  113. package/dist/runner/main.js +30 -3
  114. package/dist/runner/mcp-run.d.ts +2 -2
  115. package/dist/runner/promotion.d.ts +78 -50
  116. package/dist/runner/promotion.js +371 -503
  117. package/dist/runner/reflect-hook.d.ts +15 -0
  118. package/dist/runner/reflect-hook.js +28 -14
  119. package/dist/runner/store-secrets.js +3 -1
  120. package/dist/runner/workflow-first.d.ts +6 -11
  121. package/dist/runner/workflow-first.js +24 -25
  122. package/dist/runs-over-store.d.ts +1 -1
  123. package/dist/sdk/runs.js +2 -1
  124. package/dist/secrets.js +2 -2
  125. package/dist/server.d.ts +4 -3
  126. package/dist/server.js +132 -26
  127. package/dist/store/agent-body.d.ts +5 -3
  128. package/dist/store/agent-body.js +14 -10
  129. package/dist/store/sqlite/store.js +1 -0
  130. package/dist/store/store.d.ts +3 -0
  131. package/dist/store-reads/learning.d.ts +18 -7
  132. package/dist/store-reads/learning.js +36 -23
  133. package/dist/store-reads/loop.d.ts +5 -39
  134. package/dist/store-reads/loop.js +21 -80
  135. package/dist/store-view.d.ts +5 -0
  136. package/dist/store-view.js +16 -2
  137. package/dist/template-eval.d.ts +7 -0
  138. package/dist/template-eval.js +54 -6
  139. package/dist/templates.d.ts +3 -1
  140. package/dist/templates.js +14 -1
  141. package/dist/timeline/computer.js +2 -1
  142. package/dist/tool-list.js +1 -0
  143. package/dist/tools.d.ts +7 -0
  144. package/dist/tools.js +11 -0
  145. package/dist/trigger-feed.js +67 -18
  146. package/dist/validate.js +7 -2
  147. package/dist/workspace/computer-for-claim.d.ts +7 -0
  148. package/dist/workspace/computer-for-claim.js +12 -2
  149. package/dist/workspace/paths.d.ts +4 -0
  150. package/dist/workspace/paths.js +9 -0
  151. package/dist/workspace/resolve-computer.d.ts +3 -1
  152. package/dist/workspace/run-tools.d.ts +1 -1
  153. package/dist/workspace/run-tools.js +14 -3
  154. package/launcher/agentrun-serve +31 -24
  155. package/package.json +10 -9
  156. package/templates/README.md +11 -2
  157. package/dist/console/assets/index-C3gNPz58.css +0 -1
  158. package/dist/console/assets/index-COGhx_2Z.js +0 -711
  159. package/dist/learn/general.d.ts +0 -69
  160. package/dist/learn/general.js +0 -75
  161. package/dist/learn/refit.d.ts +0 -48
  162. package/dist/learn/refit.js +0 -264
  163. package/dist/runner/step-guard.d.ts +0 -62
  164. package/dist/runner/step-guard.js +0 -93
package/dist/openapi.js CHANGED
@@ -20,11 +20,13 @@ import { LAUNCH_LOST, SETUP_LOST } from "./files.js";
20
20
  import { HARNESSES } from "./harness.js";
21
21
  import { LEARNING_LABEL, LEARNING_MODES, LEARNING_REASONS, LEARNING_STATES, RUN_LEARNING_USE } from "./learning.js";
22
22
  import { BATCH_CELL_MAX, BATCH_ROWS_MAX } from "./learning-batch.js";
23
+ import { AUDIT_DEFAULTS, AUDIT_MAX } from "./learning-setting.js";
23
24
  import { AFTER_STATES, CHEAPER_AFTER_RUNS, COST_CSV_COLUMNS, COST_WINDOW, COST_RUNS_DEFAULT, COST_RUNS_MAX, RUN_PATHS } from "./learning-cost.js";
24
25
  import { FEEDBACK_ROUNDS, FEEDBACK_STATUSES } from "./runner/feedback-round.js";
25
26
  import { EVAL_JOBS_MAX, EVAL_TEXT_MAX, EVALS_KEPT } from "./learning-evals.js";
26
- import { LOOP_COMPILES_MAX, LOOP_POINTS_MAX } from "./store-reads/loop.js";
27
- import { GRADE_SOURCES, GRADES_KEPT, LABEL_MAX, PROMOTE_BAR, REFIT_EVERY, REPLAY_INPUTS, REPLAY_MIN } from "./learn/promote.js";
27
+ import { COMPILE_AFTER_MAX } from "./learning-setting.js";
28
+ import { LOOP_COMPILES_MAX } from "./store-reads/loop.js";
29
+ import { GRADE_SOURCES, GRADES_KEPT, LABEL_MAX } from "./learn/promote.js";
28
30
  import { MODEL_SOURCES, THINKING_LEVELS } from "./model.js";
29
31
  import { BOX_IDS, BOX_NETWORKS, BOX_STATES } from "./place-offers.js";
30
32
  import { PLACE_MODES } from "./place.js";
@@ -37,6 +39,9 @@ import "./mcp-secret-writes.js";
37
39
  // The email account's routes (email/routes.ts), each marked x-agentrun-secret whole, registered with the one gate as it
38
40
  // loads: the view among them, so the API token never reads the account.
39
41
  import "./email/routes.js";
42
+ // The calendar's routes (calendar/routes.ts), each marked x-agentrun-secret whole, registered the same way: the view
43
+ // among them, so the API token never reads which calendar is saved.
44
+ import "./calendar/routes.js";
40
45
  import { MCP_SETTINGS_PAGE } from "./mcp-oauth.js";
41
46
  import { ATTEMPTS_KEPT, MESSAGE_TYPES, WEBHOOK_EVENTS } from "./webhooks.js";
42
47
  import { DEFAULT_SCHEME, SCHEME_NAMES, SIGNATURE_SCHEMES } from "./trigger-signatures.js";
@@ -232,6 +237,20 @@ const EMAIL_ACCOUNT_BODY = {
232
237
  };
233
238
  /** One half of an email account test. */
234
239
  const MAIL_CHECK = closed({ ok: { type: "boolean" }, message: { type: "string", description: "In plain words: \"Signed in to <host>.\", with INBOX's count for IMAP, or why not." } });
240
+ /** GET and PUT /settings/calendar's answer (calendar/address.ts calendarView): the calendar, never its address. */
241
+ const CALENDAR_VIEW = closed({
242
+ configured: { type: "boolean", description: "A calendar is saved and its address opens with this server's seal key: calendar_events reads it." },
243
+ host: { type: ["string", "null"], description: "The host its address reads from (calendar.google.com), never the address." },
244
+ name: { type: ["string", "null"], description: "The calendar's own name (its X-WR-CALNAME), as the save read it; null when that read failed or it has none." },
245
+ time_zone: { type: ["string", "null"], description: "The calendar's own time zone (its X-WR-TIMEZONE, else the server's), as the save read it; null when that read failed." },
246
+ }, "The server's one calendar, never its iCal address.");
247
+ /** PUT /settings/calendar's and POST /settings/calendar/test's body: the calendar's iCal address. */
248
+ const CALENDAR_BODY = {
249
+ type: "object", additionalProperties: false,
250
+ properties: {
251
+ url: { type: "string", minLength: 1, maxLength: 2048, "x-agentrun-secret": true, description: "The calendar's secret iCal address (https://… or webcal://…, read as https://): Google Calendar's \"Secret address in iCal format\", Outlook's ICS link, iCloud's public calendar link. Sealed, never answered or shown again." },
252
+ },
253
+ };
235
254
  /** GET /settings/chatgpt's answer (chatgpt-plan.ts PlanView): the sign-in's state, never a token. */
236
255
  const CHATGPT_SIGN_IN = {
237
256
  type: "object", additionalProperties: false, required: ["state"],
@@ -1164,7 +1183,7 @@ const GRADE_FIELDS = {
1164
1183
  path: { enum: [...RUN_PATHS], description: "The path the run took, read from its record when it was graded." },
1165
1184
  workflow: { ...NULL_STRING, description: "The learned workflow that served it, when one did." },
1166
1185
  workflow_digest: { ...NULL_STRING, description: "That workflow's digest (the first 16 hex of its workflow.json's sha256), when it was served first." },
1167
- feedback: { enum: [...FEEDBACK_ROUNDS, null], description: "What the grade asked of the run's learning, a round the run opened again on (no turn of the job's: its end-of-run turn alone, learning spend): `revise`, a wrong grade of a run its learned workflow answered alone, a revision ask for that workflow with the job, its answer and the grade's words; `look_back`, a run the agent finished graded with a `label`, a look-back on it. null: nothing more (a right grade of a run its workflow answered alone costs $0), or a run that does not learn or that can't be opened again. Kept with the grade once the round opened, so a later read still says it." },
1186
+ feedback: { enum: [...FEEDBACK_ROUNDS, null], description: "What the grade asked of the run's learning, a round the run opened again on (no turn of the job's: its end-of-run turn alone, learning spend): `look_back`, a run the agent finished graded with a `label`, a look-back on it. null: nothing more (a grade of a run its learned workflow answered alone, right or wrong, is kept and costs $0: the workflow's graded hold reads it), or a run that does not learn or that can't be opened again. Kept with the grade once the round opened, so a later read still says it." },
1168
1187
  };
1169
1188
  const RUN_LEARNING = {
1170
1189
  oneOf: [
@@ -1181,7 +1200,7 @@ const RUN_LEARNING = {
1181
1200
  from_notes: { type: "array", items: { type: "string" }, description: "The notes it absorbed, by file name: once merged, each carries `compiled_into: <workflow>` in its front matter and is still served on the by-hand path." },
1182
1201
  attempts: { type: "array", items: closed({ ok: { type: "boolean" }, errors: { type: "array", items: { type: "string" }, description: "What the static checks and the dry run refused of this attempt, sent back to the model for the next one." } }), description: "Each attempt in order: the first, then a retry for each refusal, at most 4." },
1183
1202
  digest: { type: ["string", "null"], description: "The kept draft's digest (the first 16 hex of its workflow.json's sha256): what a run serving it records as `workflow_digest`, and its promotion records' `digest`; null when no attempt passed." },
1184
- promoted: { type: ["boolean", "null"], description: "Whether the kept draft serves the agent's runs, from its promotion records (GET /agents/{agent_id}/learning/promotions): true once promoted (or a threshold refit of it was), false while held, null while it is replayed, before its first claim decides it, or when no attempt passed." },
1203
+ promoted: { type: ["boolean", "null"], description: "Whether the kept draft serves the agent's runs, from its promotion records (GET /agents/{agent_id}/learning/promotions): true once promoted, false while held, null while it is checked, before its first claim decides it, or when no attempt passed." },
1185
1204
  }), { type: "null" }], description: "The run's compile turn, when its end-of-run look-back wrote the agent's job as a learned workflow (the agent kept enough notes or ran the job enough, and has none yet; or its workflow handed a run back, cost more than by hand, or its promotion held it); null when the run compiled nothing." },
1186
1205
  draft_errors: { type: "array", items: { type: "string" }, description: "What the checks refused of a compiled draft that never passed after its retries, cut of the host's secrets; empty when none." },
1187
1206
  cost_usd: closed({ grade: { type: ["number", "null"], description: "The grade's, outside the run (GET /usage's `learning` meter); null before a grade ran, or when its cost is unknown. The end-of-run turn's cost is in the run's own totals." } }),
@@ -1231,12 +1250,12 @@ const COST_RUN = closed({
1231
1250
  n: { type: "integer", minimum: 1, description: "The run's number among the agent's runs counted here, oldest first: 1 is its first." },
1232
1251
  run_id: { type: "string" },
1233
1252
  started_at: DATE_TIME,
1234
- path: { enum: [...RUN_PATHS], description: "The path the run took: `workflow`, a learned workflow finished it alone (its job's only tool calls were learned_workflow calls, each answering, and nothing was said after its first message, so it was not asked to look back); `handed_back`, a learned workflow ran and the agent went on (it failed or escalated, or the agent worked on after it); `agent`, no learned workflow ran; `replay`, a replay run: a learned workflow's new revision run alone on one of the agent's graded inputs, at workflow cost, to decide whether it serves first (its cost is learning's, shown as its own run)." },
1253
+ path: { enum: [...RUN_PATHS], description: "The path the run took: `workflow`, a learned workflow finished it alone (its job's only tool calls were learned_workflow calls, each answering, and nothing was said after its first message, so it was not asked to look back); `handed_back`, a learned workflow ran and the agent went on (it failed or escalated, or the agent worked on after it); `agent`, no learned workflow ran; `replay`, a replay run: a learned workflow's new revision run alone on one of the agent's graded inputs, at workflow cost, to decide whether it serves first (its cost is learning's, shown as its own run); `audit`, never a row here: a shadow run auditing a served run is no run of the series, its cost that run's `learning_usd`." },
1235
1254
  workflow: { ...NULL_STRING, description: "The learned workflow the job called last, by name; null when it called none." },
1236
1255
  learned_revision: { ...NULL_STRING, description: "The commit of the agent's learning folder the run started from: the learned revision that served it. Null for a run that does not learn." },
1237
1256
  cost_usd: COST_USD("The job's own cost: what the run had cost when its answer was final, before it looked back; for a run that did not look back, its whole cost."),
1238
1257
  cost_upper_bound: { type: "boolean", description: "The run's stored cost is only a bound (its row's `costAtMostUsd`: a model request cut at its cap hold): `cost_usd` and `total_usd` are null, never a known cost. `summary` counts such a run as `at_most`, not `unknown`." },
1239
- learning_usd: COST_USD("What learning cost for the run: its end-of-run look-back and the grade of what it proposed, outside the run. 0 for a run that does not learn or kept nothing to grade; a grade still running adds nothing yet."),
1258
+ learning_usd: COST_USD("What learning cost for the run: its end-of-run look-back and the grade of what it proposed, outside the run. 0 for a run that does not learn or kept nothing to grade; a grade still running adds nothing yet. An audit's shadow run of it is its learning too: null while that shadow is queued or running, never $0."),
1240
1259
  total_usd: COST_USD("The run's all-in cost, `cost_usd` and `learning_usd` together; null when either is."),
1241
1260
  });
1242
1261
  const LEARNING_COST = closed({
@@ -1248,7 +1267,7 @@ const LEARNING_COST = closed({
1248
1267
  workflows: { type: "array", items: closed({
1249
1268
  workflow: { type: "string", description: "The learned workflow, by name." },
1250
1269
  digest: { type: "string", description: "The version of it its newest run served first ran: the first 16 hex characters of its workflow.json's sha256. A new version starts its count from zero." },
1251
- state: { enum: ["serving", "needs_revision"], description: `\`serving\`: it runs first on every run it fits. \`needs_revision\`: over its newest ${COST_WINDOW} priced runs served at this version, its mean all-in cost (\`served\`) is at or over the agent's cost by hand (\`by_hand\`), so it no longer runs first; each run it would have served asks the agent for a new version, which runs first again.` },
1270
+ state: { enum: ["serving", "needs_revision"], description: `\`serving\`: it runs first on every run it fits. \`needs_revision\`: over its newest ${COST_WINDOW} priced runs served at this version, its mean all-in cost (\`served\`) is at or over the agent's cost by hand (\`by_hand\`), so it no longer runs first: the agent takes each run it would have served, and the stop asks for no new version. A new version (a new digest) runs first again.` },
1252
1271
  served: COST_MEAN(`The mean all-in cost (\`total_usd\`: the run's own cost, the workflow's nodes and, after a handback, the agent's work, with every learning round booked for it) of its newest ${COST_WINDOW} runs served first at this version whose all-in cost is known (a window, never how many runs it served: \`runs\` stops at ${COST_WINDOW}); null when none is.`),
1253
1272
  by_hand: COST_MEAN("The agent's cost by hand: the mean all-in cost (`total_usd`) of its runs on the `agent` path whose all-in cost is known or, with none, of its runs before the workflow first ran; null when there are none: the workflow then keeps serving."),
1254
1273
  unknown_cost_runs: { ...COUNT, description: "How many runs `served` and `by_hand` would have read have no known all-in cost: left out of their means, never read as 0." },
@@ -1262,11 +1281,14 @@ const LEARNING_COST = closed({
1262
1281
  hand_backs: { oneOf: [closed({ ran: COUNT, back: COUNT }), { type: "null" }], description: "Of the runs a learned workflow ran first on from the takeover on (`path` `workflow` or `handed_back`), how many (`ran`) and how many it handed back to the agent (`back`); null before a takeover." },
1263
1282
  withheld: { oneOf: [closed({ unknown: { ...COUNT, description: "Runs whose cost is unknown." }, at_most: { ...COUNT, description: "Runs whose cost is known only as at most (`cost_upper_bound`)." } }), { type: "null" }], description: "After a takeover, the runs `before` and `after` would read whose cost is not known exactly: while any is, `times_cheaper` is null, so the ratio is never over a partial set. Null when every one is known, and before a takeover." },
1264
1283
  replay: { oneOf: [closed({
1265
- n: { ...COUNT, description: "The graded inputs it replayed." },
1266
- workflow_pct: { type: "number", minimum: 0, maximum: 100, description: "The workflow's accuracy on them, in percent to a tenth (a hand-back counts as the agent's answer)." },
1267
- agent_pct: { type: "number", minimum: 0, maximum: 100, description: "The agent's accuracy on them, in percent to a tenth." },
1268
- cleared: { type: "boolean", description: "The workflow was at most the promotion bar under the agent: the same accuracy, as promotion reads it." },
1269
- }), { type: "null" }], description: "The replay the serving promotion was decided on: the current champion of the learned workflow the newest served run ran. Null when none serves, or it was promoted with no replay (a dry run)." },
1284
+ n: { ...COUNT, description: "The inputs its check ran on." },
1285
+ workflow_pct: { type: "number", minimum: 0, maximum: 100, description: "The share of them it answered alone with the agent's own recorded answer, in percent to a tenth." },
1286
+ agent_pct: { type: "number", minimum: 0, maximum: 100, description: "The agent's accuracy on them, in percent: 100, its own answers being the label." },
1287
+ cleared: { type: "boolean", description: "The check passed: a serving champion was promoted on it." },
1288
+ agreed: { ...COUNT, description: "Of the inputs it answered alone (`alone`), how many said what the agent's own recorded answer said." },
1289
+ alone: { ...COUNT, description: "The inputs it answered alone (no hand-back, no failed step)." },
1290
+ agree_min: { type: "number", minimum: 0, maximum: 1, description: "The agreement bar it passed (the definition's `learning.agree_min`): `agreed` over `alone` at least this. Passing it says the workflow agreed with the agent that often, never that it is as accurate." },
1291
+ }), { type: "null" }], description: "The check the serving promotion was decided on: the current champion of the learned workflow the newest served run ran. Null when none serves." },
1270
1292
  }, "What the series shows, over every run it counts, `limit` aside."),
1271
1293
  });
1272
1294
  const EVAL_TEXT = (description, example) => ({ type: "string", minLength: 1, maxLength: EVAL_TEXT_MAX, description, example });
@@ -1292,43 +1314,93 @@ const LEARNING_EVAL = closed({
1292
1314
  /** PUT /runs/{run_id}/grade and GET /agents/{agent_id}/learning/promotions (learn/promote.ts, runner/promotion.ts). */
1293
1315
  const GRADE = closedWith(GRADE_FIELDS, { expected: { type: "object", description: "The fields a right answer's JSON holds, when the grade gave them." } });
1294
1316
  const REPLAY_SCORE = {
1295
- n: { ...COUNT, description: "The graded inputs it was decided on." },
1296
- agree: { ...COUNT, description: "How many of them the workflow answered alone with the agent's recorded answer." },
1297
- agent_acc: { type: "number", minimum: 0, maximum: 1, description: "The agent's accuracy on them: each graded run's grade when the agent answered it; on one a learned workflow answered alone and was graded wrong, the agent counts right (it never answered it), so a revision held on runs it served wrong serves again only by answering them right." },
1298
- wf_acc: { type: "number", minimum: 0, maximum: 1, description: "The workflow's accuracy on them, at its serving thresholds: an input it handed back counts as the agent's recorded answer, never as a failure. On an input graded wrong it is right only by the grade: the expected answer when the grade gave one; with none, on a run a learned workflow served, any answer but the one graded wrong, and on a run the agent answered, never (a different answer proves nothing)." },
1299
- delta: { type: "number", description: `\`wf_acc\` - \`agent_acc\`; it serves at ${-PROMOTE_BAR} or more.` },
1300
- handed_back: { ...COUNT, description: "How many of them it handed back; it answered `n` - `handed_back` alone. A revision that answered none alone is held: it would never serve." },
1317
+ n: { ...COUNT, description: "The inputs it was decided on (a replay stopped at a write is none)." },
1318
+ agree: { ...COUNT, description: "How many of them the workflow answered alone with the agent's own recorded answer." },
1319
+ agent_acc: { type: "number", minimum: 0, maximum: 1, description: "The agent's accuracy on them: 1, the agent's own recorded answers being the label." },
1320
+ wf_acc: { type: "number", minimum: 0, maximum: 1, description: "The workflow's accuracy on them: the share it answered alone as the agent did, plus the ones it handed back (a hand-back is the agent's answer), over `n`." },
1321
+ delta: { type: "number", description: "`wf_acc` - `agent_acc`." },
1322
+ handed_back: { ...COUNT, description: "How many of them it handed back; it answered `n` - `handed_back` alone." },
1301
1323
  };
1302
1324
  /** A replay's runs' outcomes, the one count of them: on its promotion record (`replay.outcomes`) and its read. */
1325
+ const SKIPPED_TOOLS = { type: "array", items: closed({ tool: { type: "string", description: "The tool's catalog name." }, inputs: { ...COUNT, description: "How many skipped inputs it stopped." }, no_read_only_hint: { type: "boolean", description: "An MCP tool its server lists with no `readOnlyHint` (and not `destructiveHint`): replay treats it as a write only because nothing says it reads. The hold's `reason` names these: if they only read, mark them read-only in the MCP server and the next replay runs them." } }), description: "The tools that stopped its skipped inputs, most inputs first." };
1303
1326
  const REPLAY_OUTCOMES = closed({
1304
- answered: { ...COUNT, description: "Replay runs the workflow answered alone, as each run did (guards read record-only: one answered under a guard's threshold counts here, and the score hands it back)." },
1327
+ answered: { ...COUNT, description: "Replay runs the workflow answered alone, as each run did." },
1305
1328
  handed_back: { ...COUNT, description: "Replay runs it handed back on." },
1306
1329
  failed: { ...COUNT, description: "Replay runs a step failed in, or still at work past the replay's deadline: no evidence either way, never scored." },
1307
1330
  skipped_write: { ...COUNT, description: "Replay runs stopped at a write (an MCP tool its server does not mark read-only, or any tool not known to read) that the graded run's recording does not have with the same arguments: a replay never runs a write, so these are neither scored nor wrong; a replay whose every input was skipped holds the revision." },
1308
- }, "How many of its replay runs ended each way: what each run did, never the serving thresholds' reading of it.");
1331
+ }, "How many of its replay runs ended each way: what each run did.");
1309
1332
  const PROMOTION = closedWith({
1310
1333
  workflow: { type: "string" },
1311
1334
  digest: { type: "string", description: "The revision the record decides: the first 16 hex of its workflow.json's sha256." },
1312
1335
  at: DATE_TIME,
1313
- decided: { enum: ["promote", "hold", "replaying", "queued", "skipped"], description: "`promote`: it serves first on the runs it fits. `hold`: it does not; the champion (the revision promoted last) takes them, else the agent, until a new revision. `replaying`: its replay runs are at work; the champion serves meanwhile, else the agent. `queued`: it came while another revision replayed; one revision replays at a time and a running replay finishes, so it replays next, at the first run's claim once that replay is decided (the finished replay's verdict stands). `skipped`: a newer revision (`skipped_by`) came while it was queued; only the newest queued revision replays next, so it never replayed and never serves." },
1314
- source: { enum: ["replay", "dry_run", "refit", "graded"], description: `\`replay\`: decided on a replay of it on the agent's last ${REPLAY_INPUTS} graded inputs it fits, or those its owner asked for (POST .../revisions/{digest}/replays). \`dry_run\`: fewer than ${REPLAY_MIN} graded inputs, promoted on its passing dry run. \`refit\`: a threshold refit wrote this revision, decided on the rows it was fit on. \`graded\`: the graded runs it served fell more than ${PROMOTE_BAR * 100} points under the agent's accuracy by hand.` },
1336
+ decided: { enum: ["promote", "hold", "replaying"], description: "`promote`: it serves first on the runs it fits. `hold`: it does not; the champion (the revision promoted last) takes them, else the agent, until a new revision. A hold with `audit` is its audits' (a serving revision: at least the definition's `learning.hold_disagree` of its newest `learning.hold_window` audit rows, GET .../learning/audits, disagreed); one without it, its check's (`check`). `replaying`: its check's replay runs are at work; the champion serves meanwhile, else the agent. One revision of a workflow is checked at a time, and a running check finishes." },
1315
1337
  reason: { type: "string", description: "Why, in words, with the numbers." },
1316
1338
  }, {
1317
- replay: { ...closedWith(REPLAY_SCORE, { of: { type: "array", items: { type: "string" }, description: "The graded runs replayed." }, cost_usd: { type: ["number", "null"], minimum: 0, description: "What its replay runs cost together; null when one's cost is unknown." }, skipped_tools: { type: "array", items: closed({ tool: { type: "string", description: "The tool's catalog name." }, inputs: { ...COUNT, description: "How many skipped inputs it stopped." }, no_read_only_hint: { type: "boolean", description: "An MCP tool its server lists with no `readOnlyHint` (and not `destructiveHint`): replay treats it as a write only because nothing says it reads. The hold's `reason` names these: if they only read, mark them read-only in the MCP server and the next replay runs them." } }), description: "The tools that stopped its skipped inputs, most inputs first." }, outcomes: REPLAY_OUTCOMES }), description: "The numbers it was decided on. A replay runs each read live (through a cache seeded from the graded run's recorded calls) and answers each write from that recording, never sending one." },
1339
+ check: closedWith({
1340
+ compile_after: { type: "integer", minimum: 1, description: "The agent definition's `learning.compile_after` when the check began: how many of the agent's newest completed runs it read inputs from." },
1341
+ agree_min: { type: "number", minimum: 0, maximum: 1, description: "The bar on agreement: of the inputs it answered alone, the least share that must say what the agent's recorded answer said." },
1342
+ alone_min: { type: "number", minimum: 0, maximum: 1, description: "The bar on answering alone: the least share of the inputs it ran on that it must answer with no escalate and no failed step." },
1343
+ attempt: { enum: [1, 2], description: "1: the compile's first check. 2: the check of its one recompile, after the first held it; held again, it stops (`stopped`)." },
1344
+ }, {
1345
+ n: { ...COUNT, description: "The inputs it ran on (a replay stopped at a write is none; one never created, or not ended, by the check's deadline counts, as failed). 0 with nothing to run on: never promoted, it stops (`stopped`) and `reason` says why." },
1346
+ agreed: { ...COUNT, description: "How many of them it answered alone with the agent's recorded answer." },
1347
+ alone: { ...COUNT, description: "How many of them it answered alone. Promoted when `alone`/`n` >= `alone_min` and `agreed`/`alone` >= `agree_min`." },
1348
+ of: { type: "array", items: { type: "string" }, description: "The agent's runs whose inputs it ran on, newest first." },
1349
+ cost_usd: { type: ["number", "null"], minimum: 0, description: "What its replay runs cost together; null when one's cost is unknown." },
1350
+ outcomes: { ...REPLAY_OUTCOMES, description: "How each input it ran on came out, one per input: a replay run never created, or not ended, by the check's deadline is `failed`." },
1351
+ unstarted: { ...COUNT, minimum: 1, description: "How many of its replay runs were never created by the check's deadline (the server stopped after reserving them, say), each a `failed` input. Left out when none. Every one: its replay's read is `failed`." },
1352
+ skipped_tools: SKIPPED_TOOLS,
1353
+ disagreements: { type: "array", items: closedWith({ run: { type: "string" }, input: { type: "string", description: "The run's input, as text or JSON, cut at 1200 characters." }, agent: NULL_STRING }, { draft: { type: "string", description: "What it answered instead." }, escalated: { type: "string", description: "Why it handed the input back." }, failed: { const: true, description: "A step failed on it, or its run was still at work past the check's deadline, or never created by then." } }), description: "On a hold: each input it did not agree on, which the agent's next run reads as data in its one recompile." },
1354
+ stopped: { const: true, description: "The recompile's check held it too, or there was nothing to check it on (no input of the agent's it takes, or every input skipped at a write: `n` 0, `reason` starting \"nothing to check it on\", which asks no recompile): nothing compiles again until a hold or its owner acts; the agent keeps the runs." },
1355
+ }),
1318
1356
  runs: { type: "array", items: { type: "string" }, description: "Its replay runs (path `replay`)." },
1319
1357
  inputs: { type: "array", items: { type: "string" }, description: "On a replaying record: the graded run each of `runs` replays, in the same order. Its runs are reserved before they are created; one not created a few minutes on is created by the next claim." },
1320
1358
  replay_id: { type: "string", description: "The replay's id, on its replaying record and the one that decided it: GET .../revisions/{digest}/replays/{replay_id} reads it, whether a run's claim or its owner started it." },
1321
- refit: { ...closed({ from: { type: "string", description: "The digest it was refit from." }, guards: { type: "array", items: closedWith({ node: { type: "string" }, was: { type: ["number", "null"], description: "The guard's threshold before; null for an escalate." }, threshold: { type: ["number", "null"], description: "Its threshold after; null when it was switched off (the revision has no guard on that step, or no escalate by that label)." } }, { fit: { type: "object" }, escalate: { const: true, description: "An escalate node the replay recorded instead of obeying (its `when` reads a judge's field), switched off: the revision drops it." } }) } }), description: "What a refit changed: each guarded step's threshold before and after (null after: switched off), its new fit (`both` guards), and each escalate it switched off." },
1322
- checked: { ...COUNT, description: `The place among the agent's grades (each grade's order, one more than the grade before it) of the newest grade its last refit check read; it is checked again once ${REFIT_EVERY} more graded runs it served come after it.` },
1323
- since: { ...COUNT, description: "On a replay's promote: the place among the agent's grades of the newest grade when this promotion began, which names it. Its checks count only the graded runs this promotion served, so a revision promoted again after a hold is never held again on the grades it was held on, nor on a run served before it and graded after." },
1324
- held_on: { type: "array", items: { type: "string" }, description: `The runs it served that were graded wrong when its graded runs held it (newest first, at most ${REPLAY_INPUTS}), kept on that hold, on its next replay (those still graded that it fits, each among its inputs) and on that replay's hold. A replay promotes it only once it answered or handed back on each of them, and is within the bar on them alone (gains on other inputs never pay for repeating their wrong answers).` },
1325
1359
  commit: { type: "string", description: "The learning commit whose workflow.json is this revision's text: what it serves from as the champion while a newer revision replays." },
1326
- skipped_by: { type: "string", description: "A skipped revision's newer one: the digest that came while it was queued, and replays in its place." },
1360
+ audit: closedWith({
1361
+ window: { type: "integer", minimum: 1, description: "The definition's `learning.hold_window` when it was held." },
1362
+ disagree: { type: "integer", minimum: 1, description: "The definition's `learning.hold_disagree` when it was held." },
1363
+ rows: { ...COUNT, description: "The audit rows it was decided on: the newest `window` with a verdict." },
1364
+ disagreements: { type: "array", items: closedWith({
1365
+ run: { type: "string", description: "The run whose answer is the agent's: the shadow run, or the served run for a grade." },
1366
+ served: { type: "string", description: "The run the workflow served." },
1367
+ input: { type: "string", description: "The served run's input, as text or JSON, cut at 1200 characters." },
1368
+ agent: { ...NULL_STRING, description: "The agent's answer (the shadow run's), cut at 1200 characters; null for a grade's row." },
1369
+ draft: { ...NULL_STRING, description: "The served answer, cut at 1200 characters; null when it could not be read." },
1370
+ }, { graded: { const: true, description: "An owner's grade wrote this row: the served answer was graded wrong." } }), description: "Its disagreeing rows: the data its one recompile reads." },
1371
+ }, { stopped: { const: true, description: "A second audit hold within the definition's `learning.stop_window` served runs of the first: it stopped, no compile is asked, nothing serves again until a new revision lands." } }),
1372
+ });
1373
+ const AUDIT_LINE = closed({
1374
+ window: { type: "integer", minimum: 1, description: "The definition's `learning.hold_window`." },
1375
+ disagree: { type: "integer", minimum: 1, description: "The definition's `learning.hold_disagree`." },
1376
+ rows: { ...COUNT, description: "The serving revision's newest audit rows with a verdict, at most `window`." },
1377
+ disagreed: { ...COUNT, description: "How many of them disagreed: it is held once this reaches `disagree`." },
1327
1378
  });
1328
1379
  const SERVING = closed({
1329
1380
  workflow: { type: "string" },
1330
1381
  digest: { ...NULL_STRING, description: "The revision that serves first (the champion: the one promoted last, while its newest record still says promote); null when none does and the agent takes the runs." },
1331
1382
  replaying: { ...NULL_STRING, description: "A newer revision whose replay is at work, when there is one: it serves only once its replay promotes it; the champion serves meanwhile." },
1383
+ state: { enum: ["serving", "checking", "held", "stopped"], description: "`serving`: a revision serves first. `checking`: its newest revision's check is at work (the agent takes the runs meanwhile, or the champion). `held`: none serves, its newest record holds it (a check's or an audit's hold: the agent's next run recompiles it once). `stopped`: none serves and nothing compiles again (a recompile's check held it too, or a second audit hold within `learning.stop_window`, or a check whose every input stopped at a write) until a new revision lands." },
1384
+ check: { anyOf: [closed({ n: COUNT, agreed: COUNT, alone: COUNT, attempt: { enum: [1, 2] } }), { type: "null" }], description: "The numbers of the workflow's newest decided check: its inputs, those it agreed on, those it answered alone, which check of its compile it was; null when none was decided." },
1385
+ audit: { anyOf: [AUDIT_LINE, { type: "null" }], description: "Its audit line: the serving (else the newest) revision's newest audit rows against the hold bar; null when no revision has a record." },
1386
+ audits_off: { ...NULL_STRING, description: "Why none of the agent's runs is audited, e.g. `audits off: send_email can write`: its definition can call a tool that is not read-only (an MCP tool its server lists without `readOnlyHint`, or a built-in other than web_fetch, web_search, pdf_pages and llm, its computer's tools among them), which a shadow run would call a second time. Null when every tool it can call only reads: its served runs are audited." },
1387
+ not_auditable: { ...COUNT, description: "Of the serving revision's newest `learning.stop_window` served runs, those a trigger started: never audited (a shadow run gets none of a trigger's context, and could answer where it answers). 0 when none serves." },
1388
+ });
1389
+ const AUDIT_ROW = closedWith({
1390
+ run: { type: "string", description: "The served run." },
1391
+ shadow_run: { ...NULL_STRING, description: "Its shadow run (the same agent on the same input with learning off, GET /runs/{id}'s `audit_of` names the served run); null for a grade's row, or when none was started (`skipped`)." },
1392
+ workflow: { type: "string" },
1393
+ digest: { type: "string", description: "The revision that served it." },
1394
+ promoted_at: { type: ["string", "null"], format: "date-time", description: "The promotion of that revision the row counts for: its promote record's `at` (GET .../learning/promotions), the one serving when the shadow started or the grade was given. The hold rule counts only the rows of the revision's promotion now, so a revision its owner's replay promotes again after a hold starts on none. Null: none." },
1395
+ source: { enum: ["shadow", "grade"], description: "`shadow`: the shadow run's answer compared with the served one. `grade`: an owner's grade of a run the workflow answered alone (PUT /runs/{id}/grade)." },
1396
+ agreed: { type: ["boolean", "null"], description: "Whether the two answers say the same (a grade's: whether it was graded right); null when either answer is missing (a shadow that failed or `parked`, or none was started): no evidence, not counted." },
1397
+ served_cost: { type: ["number", "null"], minimum: 0, description: "What the served run cost; null when unknown." },
1398
+ shadow_cost: { type: ["number", "null"], minimum: 0, description: "What the shadow run cost (the agent's learning cost); null for a grade's row, or when unknown." },
1399
+ at: DATE_TIME,
1400
+ }, {
1401
+ turn: { type: "string", description: "The served run's answer the row is of: the id of its answer row in the run's timeline (GET /runs/{id}/timeline), its newest final answer when the audit began (or at the grade). A follow-up's later answer is never the one compared. Absent when the run had no answer." },
1402
+ skipped: { const: "no allowance", description: "No shadow was started: the served run's cap left less than a run's smallest cap ($0.01), or what it spent under it is not known. `agreed` is null: not counted." },
1403
+ parked: { const: true, description: "The shadow came to wait on a person (an approval its tool settings ask, a question, a raise of its cap: what the served run's cap left) and ended there at once, no one asked, so it has no answer. `agreed` is null: not counted." },
1332
1404
  });
1333
1405
  const BATCH_LESSONS = closed({ notes: { type: "array", items: { type: "string" } }, skills: { type: "array", items: { type: "string" } }, workflows: { type: "array", items: { type: "string" } } });
1334
1406
  const BATCH_ROW = closedWith({ n: { type: "integer", minimum: 1, description: "The row's number, 1 the first: rows run in this order." }, state: { enum: ["pending", "running", "done", "failed"], description: "`done`: the run answered, was told the reference, and that turn completed and its learning settled; `failed`: its run failed, was cancelled or waited on a person, its review was not sent, or its review's turn did not complete (`error` says). A row is failed only once its run has stopped." }, reference: { type: "string", description: "The reference answer, as the person gave it." } }, {
@@ -1336,7 +1408,7 @@ const BATCH_ROW = closedWith({ n: { type: "integer", minimum: 1, description: "T
1336
1408
  answer: { ...NULL_STRING, description: "The run's answer as compared (the `answer_field` of a JSON answer when the batch names one), cut at 2000 characters (compared whole: the review quotes it to 2000 characters and says when it was cut); null when it gave none." },
1337
1409
  right: { type: "boolean", description: "Whether the answer equals the reference once trimmed, case-folded and whitespace-collapsed (two numbers by value). A display: the learning grade is the judge." },
1338
1410
  reviewed: { type: "boolean", description: "The reference was sent to the run as a review, once." },
1339
- path: { enum: RUN_PATHS.filter((path) => path !== "replay"), description: "The path the run's job took, read when it answered, before its review (GET /agents/{agent_id}/learning/cost's `path`): whoever wrote its answer." },
1411
+ path: { enum: RUN_PATHS.filter((path) => path !== "replay" && path !== "audit"), description: "The path the run's job took, read when it answered, before its review (GET /agents/{agent_id}/learning/cost's `path`): whoever wrote its answer." },
1340
1412
  cost_usd: COST_USD("The job's own cost."), learning_usd: COST_USD("What learning cost for the run."), total_usd: COST_USD("Their sum; for a failed row, what its run cost."),
1341
1413
  learned: { ...BATCH_LESSONS, description: "The notes, skills and workflow drafts the run's learning kept, by name." },
1342
1414
  merged: { ...NULL_STRING, description: "The commit of the agent's learning folder its learning last merged (its job's round or its review's)." },
@@ -1368,20 +1440,21 @@ const LEARNING_EXTENSIONS = {
1368
1440
  "/runs/{run_id}/grade": {
1369
1441
  put: {
1370
1442
  operationId: "gradeRun", tags: ["runs"], summary: "Grade an ended run's answer: right or wrong, and the fields a right answer holds",
1371
- description: `A person's feedback or an eval's label on a run that ended, kept for its agent (one grade a run: a later one replaces it; the newest ${GRADES_KEPT} are kept). Promotion by replay reads them: a learned workflow's new revision serves first only after a replay on the agent's last ${REPLAY_INPUTS} graded inputs it fits is within ${PROMOTE_BAR * 100} points of the agent's own answers on them; with fewer than ${REPLAY_MIN}, on its passing dry run. With \`expected\`, a replay's answer is right when its JSON holds each of those fields; else when it says what the graded answer said. A replay run is never graded. The run's path never changes on a grade: a right grade of a run its learned workflow answered alone is kept and nothing more ($0); a wrong one opens the run again on a revision ask for that workflow; a run the agent finished, graded with a \`label\`, opens again on a look-back on it. Either round asks the agent no turn of the job's, only its end-of-run turn, and its spend is the run's learning (\`feedback\`).`,
1443
+ description: `A person's feedback or an eval's label on a run that ended, kept for its agent (one grade a run: a later one replaces it; the newest ${GRADES_KEPT} are kept). Promotion reads none: a revision's check is scored against the agent's own recorded answers. A replay run is never graded. The run's path never changes on a grade: a grade of a run its learned workflow answered alone, right or wrong, is kept and nothing more ($0); a run the agent finished, graded with a \`label\`, opens again on a look-back on it. That round asks the agent no turn of the job's, only its end-of-run turn, and its spend is the run's learning (\`feedback\`).`,
1372
1444
  parameters: [ref("parameters/RunId")],
1373
- requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["correct"], properties: { correct: { type: "boolean" }, expected: { type: "object", description: "The fields a right answer's JSON holds." }, source: { enum: [...GRADE_SOURCES], default: "feedback" }, label: { type: "string", maxLength: LABEL_MAX, description: "The grade's words (a teacher's label, a reviewer's note): what the run's look-back or its workflow's revision ask reads." } } } } } },
1445
+ requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["correct"], properties: { correct: { type: "boolean" }, expected: { type: "object", description: "The fields a right answer's JSON holds." }, source: { enum: [...GRADE_SOURCES], default: "feedback" }, label: { type: "string", maxLength: LABEL_MAX, description: "The grade's words (a teacher's label, a reviewer's note): what the run's look-back reads." } } } } } },
1374
1446
  responses: { "200": json(GRADE, "The run's grade."), ...errors(400, 401, 404, 429, 500) },
1375
1447
  "x-agentrun-serve": "promotion/1",
1376
1448
  },
1377
1449
  },
1378
1450
  "/agents/{agent_id}/learning/loop": {
1379
1451
  get: {
1380
- operationId: "getLearningLoop", tags: ["agents"], summary: "The self-learning loop's own record: each compile turn, and each guarded step of the learned workflows",
1381
- description: `What the console's Learning tab tells of the loop beside the cost series. \`compiles\`: the agent's compile turns, newest first (the newest ${LOOP_COMPILES_MAX}): the workflow a run's compile turn wrote, the notes it absorbed, each attempt and what the checks refused, its draft's digest and whether that revision was promoted; a follow-up's round compiles on its own, so a run can list one turn a round; a turn whose draft never passed is listed with its \`draft_errors\`, never silent. \`guards\`: each guarded step of each learned workflow revision that ran (served first or replayed), with its signal and threshold, how many runs it served first on and how many it handed back, how many the workflow answered alone were graded right and wrong (each over every run), and each run's p (its newest ${LOOP_POINTS_MAX}), with whether the run was right when its answer was the workflow's own and was graded. A replay run reads its guards at a record-only threshold, so it is counted apart (\`replays\`) and in none of the others. Aggregates and the checks' own words only: no input or answer. Each text cut of the host's secrets and of its run's handed values; a run whose handed values can't be read here shows no error text (\`withheld\`).`,
1452
+ operationId: "getLearningLoop", tags: ["agents"], summary: "The self-learning loop's own record: each compile turn",
1453
+ description: `What the console's Learning tab tells of the loop beside the cost series. \`compiles\`: the agent's compile turns, newest first (the newest ${LOOP_COMPILES_MAX}): the workflow a run's compile turn wrote, the notes it absorbed, each attempt and what the checks refused, its draft's digest and whether that revision was promoted; a follow-up's round compiles on its own, so a run can list one turn a round; a turn whose draft never passed is listed with its \`draft_errors\`, never silent. Aggregates and the checks' own words only: no input or answer. Each text cut of the host's secrets and of its run's handed values; a run whose handed values can't be read here shows no error text (\`withheld\`).`,
1382
1454
  parameters: [AGENT_ID],
1383
1455
  responses: { "200": json(closed({
1384
1456
  agent: { type: "string" },
1457
+ completed_runs: { ...COUNT, description: "The agent's completed runs of its own (never one a learned workflow answered alone, a replay, an imported or an archived run) toward its first compile, at most its definition's `learning.compile_after`." },
1385
1458
  compiles: { type: "array", items: closed({
1386
1459
  run_id: { type: "string", description: "The run whose end compiled it." },
1387
1460
  round: { type: "integer", minimum: 1, description: "The run's round that compiled it: 1 its first end, more for an end after a follow-up opened it again." },
@@ -1390,34 +1463,29 @@ const LEARNING_EXTENSIONS = {
1390
1463
  from_notes: { type: "array", items: { type: "string" }, description: "The notes it absorbed, by file name (each marked \`compiled_into\` once it merged)." },
1391
1464
  attempts: { type: "array", items: closed({ ok: { type: "boolean" }, errors: { type: "array", items: { type: "string" } } }), description: "Each attempt in order: whether its checks and dry run passed, and what they refused." },
1392
1465
  digest: { ...NULL_STRING, description: "The kept draft's digest; null when none passed." },
1393
- promoted: { type: ["boolean", "null"], description: "Whether that revision was promoted, as its records say now: true promoted (or a refit of it was), false held or skipped, null queued, undecided or none passed. It may no longer serve: the promotions read's \`serving\` says which revision does." },
1394
- draft_errors: { type: "array", items: { type: "string" }, description: "A draft that never passed: its last errors. Empty when one passed." },
1466
+ promoted: { type: ["boolean", "null"], description: "Whether that revision was promoted, as its records say now: true promoted, false held, null undecided or none passed. It may no longer serve: the promotions read's \`serving\` says which revision does." },
1467
+ draft_errors: { type: "array", items: { type: "string" }, description: "A draft that never passed: its last errors. A draft its check had nothing to run on (its promotion `check.stopped` with `n` 0): its record's reason, starting \"nothing to check it on\". Empty otherwise." },
1395
1468
  withheld: { type: "boolean", description: "The run's handed values can't be read here: its error texts are left out (the counts stand)." },
1396
1469
  }), description: "Newest first." },
1397
- guards: { type: "array", items: closed({
1398
- workflow: { type: "string" },
1399
- digest: { type: "string", description: "The revision the step ran in." },
1400
- node: { type: "string", description: "The step's label." },
1401
- signal: { enum: ["self", "jev", "both"], description: "\`self\`: the step's own confidence; \`jev\`: one Jev call over its input and output; \`both\`: their fitted logistic (min of the two before a fit)." },
1402
- threshold: { type: ["number", "null"], minimum: 0, maximum: 1, description: "Under it the step hands the run back to the agent, as the runs it served first on read it; null when only replays ran it." },
1403
- runs: { ...COUNT, description: "Runs this revision served first on that this step guarded, each once however many checks a map made of it (replays left out, and checks of another workflow's call in the same run)." },
1404
- escalated: { ...COUNT, description: "How many of them it handed back (one of the run's checks of it did)." },
1405
- right: { ...COUNT, description: "How many of them the workflow answered alone and were graded right." },
1406
- wrong: { ...COUNT, description: "How many of them the workflow answered alone and were graded wrong." },
1407
- grades_past: { ...COUNT, description: `How many of them the workflow answered alone whose grade, if one was given, is no longer kept (the agent keeps its newest ${GRADES_KEPT} grades): in neither \`right\` nor \`wrong\`, and not known to be ungraded.` },
1408
- replays: { ...COUNT, description: "Replay runs of this revision that read this step: in none of the other counts, nor in \`points\` (a replay reads its guards at a record-only threshold, so its row says nothing of a hand-back)." },
1409
- points: { type: "array", items: closed({ run_id: { type: "string" }, p: { type: ["number", "null"], minimum: 0, maximum: 1, description: "The least p the run's checks of this step read, to 4 places; null when a signal was missing on one (always handed back)." }, escalated: { type: "boolean" }, correct: { type: ["boolean", "null"], description: "The run's grade, on a run the workflow answered alone; null otherwise." } }), description: `The runs it served first on, oldest first: the newest ${LOOP_POINTS_MAX}.` },
1410
- }) },
1411
- }), "The loop's compile turns and guarded steps."), ...errors(401, 403, 404, 429, 500) },
1470
+ }), "The loop's compile turns."), ...errors(401, 403, 404, 429, 500) },
1412
1471
  "x-agentrun-serve": "learningloop/1",
1413
1472
  },
1414
1473
  },
1415
1474
  "/agents/{agent_id}/learning/promotions": {
1416
1475
  get: {
1417
1476
  operationId: "listLearningPromotions", tags: ["agents"], summary: "Each learned workflow revision's promotion: its replay's numbers and whether it serves",
1418
- description: "Every promotion record of the agent's learned workflows, oldest first: a new revision's replay on the agent's graded inputs (replaying, then promoted or held, with its numbers), one promoted on its dry run, a threshold refit's new revision, a serving revision held on its graded runs. A revision serves only once its replay promotes it; the champion (the revision promoted last) keeps serving while a newer one replays or after it is held, and `serving` says which digest serves and which replays. One revision replays at a time and a running replay finishes: a newer one that comes meanwhile is queued, and replays next; one queued before it is skipped, its record naming the newer one. Aggregates only: no input or answer. What the console's Learning tab marks on its cost chart.",
1477
+ description: "Every promotion record of the agent's learned workflows, oldest first: a new revision's one check, a replay of it on the inputs of the agent's last completed runs scored against the agent's own recorded answers (replaying, then promoted or held, with its numbers), a draft held with nothing to check it on, a compile whose drafts all failed their checks (a hold with nothing checked, its reason naming the failed checks: the compile's attempt; a recompile's stops), or a serving revision held by its audits (GET .../learning/audits; the hold's `audit` holds the rows). A revision serves only once its check promotes it; the champion (the revision promoted last) keeps serving while a newer one is checked or after it is held, and `serving` says which digest serves and which is checked, each workflow's state, its newest check's numbers and its audit line. One revision of a workflow is checked at a time and a running check finishes. A hold's disagreements (a check's, an audit's) quote inputs and answers, cut as the agent's other learning reads cut them. What the console's Learning tab marks on its cost chart.",
1419
1478
  parameters: [AGENT_ID],
1420
- responses: { "200": json(closed({ agent: { type: "string" }, promotions: { type: "array", items: PROMOTION }, serving: { type: "array", items: SERVING, description: "Each learned workflow with a record: the revision that serves and the one replaying." } }), "The agent's promotion records, and what serves."), ...errors(401, 403, 404, 429, 500) },
1479
+ responses: { "200": json(closed({ agent: { type: "string" }, promotions: { type: "array", items: PROMOTION }, serving: { type: "array", items: SERVING, description: "Each learned workflow with a record: the revision that serves, the one replaying, its state, its check's numbers and its audit line." } }), "The agent's promotion records, and what serves."), ...errors(401, 403, 404, 429, 500) },
1480
+ "x-agentrun-serve": "promotion/1",
1481
+ },
1482
+ },
1483
+ "/agents/{agent_id}/learning/audits": {
1484
+ get: {
1485
+ operationId: "listLearningAudits", tags: ["agents"], summary: "The audit ledger of the agent's serving learned workflows",
1486
+ description: "One row per finished audit, oldest first, as the agent's learning folder keeps them (audits.jsonl): a run a promoted learned workflow served first (answered alone or handed back) is audited at 1 in `learning.audit_every` (drawn from its id): its shadow run, the same agent on the same input with learning off, answers it again, and the row says whether the two answers say the same and what each run cost (the shadow's is the agent's learning cost; the shadow is no row of the run list, and GET /runs/{id} reads it with `audit_of`). A capped run's shadow starts at its end, capped at what its cap left, so the two never spend past it: with less than a run's smallest cap left, none starts (`skipped`). A shadow never waits on a person: one that would (an approval, a question, a raise of its cap) ends there at once with no answer (`parked`); neither is counted. Each row compares the served run's answer at the audit's start (`turn`), never a follow-up's. An owner's grade of a run the workflow answered alone is a row too. The hold rule reads them (`learning.hold_window`, `learning.hold_disagree`).",
1487
+ parameters: [AGENT_ID],
1488
+ responses: { "200": json(closed({ agent: { type: "string" }, audits: { type: "array", items: AUDIT_ROW } }), "The agent's audit rows."), ...errors(401, 403, 404, 429, 500) },
1421
1489
  "x-agentrun-serve": "promotion/1",
1422
1490
  },
1423
1491
  },
@@ -1579,23 +1647,23 @@ const LEARNING_EXTENSIONS = {
1579
1647
  },
1580
1648
  "/agents/{agent_id}/learning/workflows/{name}/revisions/{digest}/replays": {
1581
1649
  post: {
1582
- operationId: "startLearnedWorkflowReplay", tags: ["agents"], summary: "Replay a learned workflow's revision on the agent's graded inputs: re-check a held revision, or an edited one",
1583
- description: `Starts the replay a run's claim starts for a new revision (GET /agents/{agent_id}/learning/promotions explains them): one replay run of the agent per graded input, each the workflow alone at workflow cost, its reads live and its writes answered only from the graded run's recording, never sent. \`inputs\`: \`held\` (the default), the graded runs the revision's last replay or hold was decided on, or, with none, the agent's newest ${REPLAY_INPUTS}; a number from 1 to ${GRADES_KEPT}, that many of the agent's newest graded runs. Either way, a revision held on runs it served that were graded wrong is replayed on those too (its hold's \`held_on\`), and promoted only once it answered or handed back on each and is within the bar on them alone. Each is a graded run the agent answered (path \`agent\` or \`handed_back\`) or the workflow answered alone (\`workflow\`), with no uploaded file, whose input the revision takes. Its record is a replay's (\`source: replay\`, \`replaying\` then promoted or held, with its numbers, as a claim-started one is), decided once every replay run ended: at a run's claim that lays the revision, or at its read (GET .../replays/{replay_id}). A promoted revision serves first, and a held one may be refit, as after any replay. Its replay runs are handed no per-run MCP credentials. The revision is \`digest\`, the first 16 hex of its workflow.json's sha256: one a promotion record names (read at its commit), or the one on the learning folder's main. 404 for an unknown agent, workflow or revision. 409 \`replay_conflict\` when it is replaying already, another revision of the workflow replays (one at a time, and a running replay finishes: a revision queued behind it, \`queued\` in the promotions, replays at the first run's claim once it ends, no POST needed), it is promoted (it serves already), fewer than ${REPLAY_MIN} of the graded inputs asked for fit it (a replay on fewer could only hold it, so nothing is reserved and no run starts), or the agent's runs take no learned workflow here. 409 \`agent_not_runnable\` for an archived agent, as a run's start is: nothing is reserved. 400 for any other \`inputs\`. Only the owner, signed in with their password, starts one: the console's password session alone, from this server's own origin with a JSON body; every token is 403 \`forbidden\`.`,
1650
+ operationId: "startLearnedWorkflowReplay", tags: ["agents"], summary: "Re-check a learned workflow's revision on the agent's own runs: a held revision, or an edited one",
1651
+ description: `Starts the one check a run's claim starts for a new revision (GET /agents/{agent_id}/learning/promotions explains it): one replay run of the agent per input, each the workflow alone at workflow cost, its reads live and its writes answered only from the agent's own run's recording, never sent, scored against the agent's own recorded answers. \`inputs\`: \`held\` (the default), the runs the revision's last check ran on, or, with none, the agent's last \`compile_after\` completed runs; a number from 1 to ${COMPILE_AFTER_MAX}, that many of the agent's newest completed runs. Each is a completed run of the agent's own (path \`agent\` or \`handed_back\`), with no uploaded file, whose input the revision takes. Its record is a check's (\`replaying\` then promoted or held, with its numbers, as a claim-started one is), decided once every replay run ended: at a run's claim that lays the revision, or at its read (GET .../replays/{replay_id}). Its replay runs are handed no per-run MCP credentials. The revision is \`digest\`, the first 16 hex of its workflow.json's sha256: one a promotion record names (read at its commit), or the one on the learning folder's main. 404 for an unknown agent, workflow or revision. 409 \`replay_conflict\` when it is replaying already, another revision of the workflow replays (one at a time, and a running check finishes), it is promoted (it serves already), none of the inputs asked for fits it (nothing is reserved and no run starts), or the agent's runs take no learned workflow here. 409 \`agent_not_runnable\` for an archived agent, as a run's start is: nothing is reserved. 400 for any other \`inputs\`. Only the owner, signed in with their password, starts one: the console's password session alone, from this server's own origin with a JSON body; every token is 403 \`forbidden\`.`,
1584
1652
  security: [{ ownerSession: [] }],
1585
1653
  parameters: [AGENT_ID, { name: "name", in: "path", required: true, description: "The learned workflow's folder name, `workflows/<name>/`.", schema: { type: "string" } }, { name: "digest", in: "path", required: true, description: "The revision: the first 16 hex of its workflow.json's sha256.", schema: { type: "string" } }],
1586
- requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, properties: { inputs: { oneOf: [{ const: "held" }, { type: "integer", minimum: 1, maximum: GRADES_KEPT }], default: "held", description: "`held`: the graded inputs it was last decided on; a number: the agent's newest that many." } } } } } },
1654
+ requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, properties: { inputs: { oneOf: [{ const: "held" }, { type: "integer", minimum: 1, maximum: COMPILE_AFTER_MAX }], default: "held", description: "`held`: the runs it was last checked on; a number: the agent's newest that many completed runs." } } } } } },
1587
1655
  responses: { "202": { description: "The replay started: its runs are queued.", headers: { Location: ref("headers/Location") }, content: { "application/json": { schema: closed({ replay: { type: "string", description: "The replay's id." }, inputs: { ...COUNT, description: "How many graded inputs it replays: one replay run each." } }) } } }, ...errors(400, 401, 403, 404, 409, 422, 429, 500) }, ...MARK,
1588
1656
  },
1589
1657
  },
1590
1658
  "/agents/{agent_id}/learning/workflows/{name}/revisions/{digest}/replays/{replay_id}": {
1591
1659
  get: {
1592
1660
  operationId: "getLearnedWorkflowReplay", tags: ["agents"], summary: "Read a replay's result: running, done or failed, its counts and its score (start one from the console's Learning tab)",
1593
- description: "A replay a run's claim or the agent's owner started. This read decides it as a claim would, once every replay run ended or its deadline passed (promoted within 2 points of the agent, else held, then one refit), so a replay of a revision no run lays is decided too. It never starts a run: a replay whose launch was interrupted (the server stopped before creating its runs) reads `running` until its deadline. `status`: `running` while it replays, `done` once promoted or held (`decided`, with its `reason`; a newer revision that came meanwhile queued behind it, never cancelling it), `failed` when none of its runs started by its deadline (held, nothing replayed; its `reason` says so and to start it again with POST). `outcomes` counts its replay runs so far (once decided, those it was decided on, as its promotion record keeps them): `answered` alone, `handed_back` (the agent's recorded answer), `failed` (no evidence either way), `skipped_write` (a write its recording does not have). `score` is the decided record's, else the runs ended so far at the revision's serving thresholds. Aggregates only, its words cut as the promotions list's are.",
1661
+ description: "A replay a run's claim or the agent's owner started. This read decides it as a claim would, once every replay run ended or its deadline passed (promoted when it clears the check's bar, else held), so a replay of a revision no run lays is decided too. It never starts a run: a replay whose launch was interrupted (the server stopped before creating its runs) reads `running` until its deadline. `status`: `running` while it replays, `done` once promoted or held (`decided`, with its `reason`), `failed` when none of its runs started by its deadline (held, nothing replayed; its `reason` says so and to start it again with POST). `outcomes` counts its replay runs so far (once decided, those it was decided on, as its promotion record keeps them): `answered` alone, `handed_back` (the agent's recorded answer), `failed` (no evidence either way), `skipped_write` (a write its recording does not have). `score` is the decided record's. Aggregates only, its words cut as the promotions list's are.",
1594
1662
  parameters: [AGENT_ID, { name: "name", in: "path", required: true, description: "The learned workflow's folder name.", schema: { type: "string" } }, { name: "digest", in: "path", required: true, description: "The revision's digest.", schema: { type: "string" } }, { name: "replay_id", in: "path", required: true, description: "The replay's id: POST .../replays answered it, and its promotion records carry it (`replay_id`).", schema: { type: "string" } }],
1595
1663
  responses: { "200": json(closedWith({
1596
1664
  replay: { type: "string" }, workflow: { type: "string" }, digest: { type: "string" },
1597
1665
  status: { enum: ["running", "done", "failed"] },
1598
- inputs: { ...COUNT, description: "Its replay runs: one per graded input." },
1666
+ inputs: { ...COUNT, description: "Its replay runs: one per input." },
1599
1667
  outcomes: REPLAY_OUTCOMES,
1600
1668
  score: closed(REPLAY_SCORE),
1601
1669
  cost_usd: { type: ["number", "null"], minimum: 0, description: "What its replay runs cost together; null while one's cost is unknown (one not created or not ended yet), never a part of it." },
@@ -2142,6 +2210,44 @@ const EXTENSIONS = {
2142
2210
  "x-agentrun-serve": "email/1",
2143
2211
  },
2144
2212
  },
2213
+ "/settings/calendar": {
2214
+ get: {
2215
+ operationId: "getCalendar", tags: ["local"], summary: "This server's calendar: its host, name and time zone, never its address",
2216
+ description: "The one calendar calendar_events reads. The owner's signed-in session alone (ownerSession), never the token, which is 403 forbidden in words.",
2217
+ "x-agentrun-secret": true,
2218
+ security: [{ ownerSession: [] }],
2219
+ responses: { "200": json(CALENDAR_VIEW, "The calendar."), ...errors(401, 403, 429, 500) },
2220
+ "x-agentrun-serve": "calendar/1",
2221
+ },
2222
+ put: {
2223
+ operationId: "saveCalendar", tags: ["local"], summary: "Save this server's calendar, its iCal address sealed",
2224
+ description: "Replaces the calendar. The address is https (webcal:// is read as https://; plain http, another scheme, or a user and password in it is refused in words), sealed under the server's seal key, and in no answer, event, log line or run input. The calendar is read once for its own name and time zone; a read that fails saves the address all the same (name and time_zone null): POST /settings/calendar/test says why. 422 by field for a body that does not read. A secret write: the owner's signed-in session alone (ownerSession), never the token, which is 403 forbidden in words.",
2225
+ "x-agentrun-secret": true,
2226
+ security: [{ ownerSession: [] }],
2227
+ requestBody: { required: true, content: { "application/json": { schema: { ...CALENDAR_BODY, required: ["url"] } } } },
2228
+ responses: { "200": json(CALENDAR_VIEW, "Saved."), ...errors(400, 401, 403, 415, 422, 429, 500, 503) },
2229
+ "x-agentrun-serve": "calendar/1",
2230
+ },
2231
+ delete: {
2232
+ operationId: "deleteCalendar", tags: ["local"], summary: "Forget this server's calendar",
2233
+ description: "Removes the calendar and its sealed address. calendar_events then answers that no calendar is saved. A secret write: the owner's signed-in session alone (ownerSession), never the token, which is 403 forbidden in words.",
2234
+ "x-agentrun-secret": true,
2235
+ security: [{ ownerSession: [] }],
2236
+ responses: { "204": { description: "Forgotten." }, ...errors(401, 403, 429, 500) },
2237
+ "x-agentrun-serve": "calendar/1",
2238
+ },
2239
+ },
2240
+ "/settings/calendar/test": {
2241
+ post: {
2242
+ operationId: "testCalendar", tags: ["local"], summary: "Read the calendar and say what it holds",
2243
+ description: "Reads the saved calendar with an empty body, or the address in the body (saved nowhere), as calendar_events reads it (https only; a private address refused unless its host is allowed in Settings → MCP servers; 10 MB, 20 s, 5 redirects), and answers in words: \"Work: 214 events, time zone America/New_York, next: Standup, Mon Nov 17 09:30\" (its name, its events and series, its time zone, and its next event in the next 62 days), or why it couldn't be read, never the address. 422 for a body that does not read, or an empty body with no calendar saved. A secret write: the owner's signed-in session alone (ownerSession), never the token, which is 403 forbidden in words.",
2244
+ "x-agentrun-secret": true,
2245
+ security: [{ ownerSession: [] }],
2246
+ requestBody: { required: false, content: { "application/json": { schema: CALENDAR_BODY } } },
2247
+ responses: { "200": json(closed({ ok: { type: "boolean", description: "The calendar was read." }, message: { type: "string", description: "In plain words: what it holds, or why it couldn't be read." } }), "The test's answer."), ...errors(400, 401, 403, 415, 422, 429, 500) },
2248
+ "x-agentrun-serve": "calendar/1",
2249
+ },
2250
+ },
2145
2251
  "/settings/chatgpt": {
2146
2252
  get: {
2147
2253
  operationId: "getChatGPTSignIn", tags: ["local"], summary: "This server's ChatGPT sign-in: its state, who and which plan, never a token",
@@ -2886,6 +2992,18 @@ const FIELD_EXTENSIONS = {
2886
2992
  description: "While a message the run took is still open (an agentic run, working or queued): when its turn last wrote anything, a request's start included; it holds still while a tool or a model request runs, and moves as the turn writes. Null once every message has had its turn, and on a workflow run.",
2887
2993
  "x-agentrun-serve": "turnend/1",
2888
2994
  },
2995
+ recordings: {
2996
+ type: "array",
2997
+ items: closed({
2998
+ path: { type: "string", description: "Where it is read: `GET /runs/{run_id}/files/{path}` with this path (`recordings/<computer>.mp4`), `video/mp4`, its byte ranges answered; `?download=1` for an attachment." },
2999
+ computer: { type: "string", description: "The computer it recorded: its id, as the file is named. A computer's later files (a resumed run's, a phone's frames that changed format) are `<computer>-2.mp4` and on." },
3000
+ seconds: { type: "number", minimum: 0, description: "How long it plays, to a tenth of a second, as far as it is written." },
3001
+ bytes: { type: "integer", minimum: 0, description: "Its size now." },
3002
+ finished: { type: "boolean", description: "false while it is still being written: it plays up to its last whole fragment. true once its recording stopped, and for every file once the run has ended and the file has stopped changing (a few seconds after the end)." },
3003
+ }, "One video of a computer's screen during the run (H.264 in fragmented MP4)."),
3004
+ description: "On the run read (and an archive's or unarchive's answer) alone, never in a list: the videos of the run's screen, where its agent's computer says `record: true` (a desktop or a phone), each computer's files in the order they were recorded; empty when nothing was recorded, and for a run whose words are withheld. Read from the files on the machine whose runner recorded them. The video shows everything on the screen: see the agent's `computer.record`.",
3005
+ "x-agentrun-serve": "runvideo/1",
3006
+ },
2889
3007
  input: {
2890
3008
  type: ["object", "null"],
2891
3009
  additionalProperties: true,
@@ -2919,6 +3037,7 @@ const FIELD_EXTENSIONS = {
2919
3037
  "x-agentrun-serve": "imported/1",
2920
3038
  },
2921
3039
  trigger: RUN_TRIGGER,
3040
+ audit_of: { ...NULL_STRING, description: "On the run read: a shadow run's served run. A run a promoted learned workflow served first may be audited (the agent definition's `learning.audit_every`): its shadow, the same agent on the same input with learning off, started at the served run's end and capped at what the served run's cap left, is no row of the run list, and its cost is in the served run's `cost.usd` (null while the shadow is queued or running: never $0) and the agent's learning cost (GET /agents/{agent_id}/learning/audits). Null for any other run.", "x-agentrun-serve": "promotion/1" },
2922
3041
  },
2923
3042
  InputIssue: {
2924
3043
  code: { type: "string", description: "A workflow definition's issue: the DSL's validation code (`STATE_PATH_UNPRODUCED`, say), with `field` the path to it under `definition.workflow`.", "x-agentrun-serve": "validate/1" },
@@ -3070,13 +3189,24 @@ const FIELD_EXTENSIONS = {
3070
3189
  persistent: { type: "boolean", description: "Whether the agent keeps its own computer between runs: true makes one at its first run, detaches it (not deletes it) at each run's end, and attaches it again at the next, with what was on it; false or absent, a fresh computer for each run. Only where the provider keeps one for the kind and image (GET /computers: the provider's `persistent`), else 422 not_allowed; never one that mounts the run's folder. One run at a time: a run that finds the computer held by another run still going is refused at its start, naming that run. Archiving the agent, turning this off, or a setting on another provider or image deletes the computer (GET /agents/{agent_id}'s `own_computer` shows it)." },
3071
3190
  surface: { enum: ["code", "tools"], description: "How the agent drives a desktop or a phone. `code`: by `codemode` scripts alone, whose `tools.computer_observe`, `tools.computer_act` and `tools.computer_screenshot` are each a gated, recorded call of its own; the model is offered `codemode` and the hand-over (`computer_request_handoff`), not the step tools (a harness with its own code mode, Codex, is still handed them). `tools`: the step tools and the hand-over, listed; a `codemode` script calls them too. Absent, as `tools`. Only a desktop or a phone takes it (422 not_allowed on another kind)." },
3072
3191
  exec: { type: "boolean", description: "`false`: the agent gets no shell and starts no program on its desktop or phone. Its computer's `exec` and `processes` groups are taken out of what its tools and scripts see (no `computer.shell`, no `computer.processes`; a script that reaches for one is refused in words), no folder is mounted in the computer, and the run gets no `bash` or background tool, wherever its folder is. The run's own computer channel (`POST /runs/{run_id}/computer/call`, the owner's) keeps every group. `true` or absent: as the computer offers. Only a desktop or a phone takes it (422 not_allowed on another kind)." },
3192
+ record: { type: "boolean", description: "`true`: each run records a video of its desktop's or phone's screen (H.264, fragmented MP4, at most 10 frames a second and 1280 pixels on the long side, no audio) into its run folder's `recordings/`, beside `work/`, where the agent can neither read nor change it. The video shows everything on the screen, including whatever a person types while they take over and any secret that appears on screen; pixels can't be redacted the way the run's logs are. It records while the run holds the computer, with or without a viewer, pauses while the run is parked (a resumed run goes on in a new file) and stops at the computer's release, the run's end, or its cap (500 MB across the run's files, or 2 hours from its start or the run's resume), which the run's timeline says. A server without ffmpeg refuses it (422 not_allowed). `false` or absent: nothing is recorded. Only a desktop or a phone takes it (422 not_allowed on another kind)." },
3073
3193
  },
3074
- description: "The computer the revision's runs are given (Settings → Computers): its kind, the provider that serves it, the image it starts from, a sandbox's GPUs, whether the agent keeps it between runs, and, for a desktop or a phone, how the agent drives it and whether it may run programs on it. `place` is its v2 view where it can say it: `{kind: none}` is `place {mode: runner}`, `{kind: sandbox, provider: X}` is `place {mode: sandbox, box: X}`; a desktop, phone or browser computer leaves the run's folder on the runner, so its place reads runner. Writing either sets both, and both given must agree (422). Absent on a create, the server's default (as `place`); an edit that names neither keeps the agent's.",
3194
+ description: "The computer the revision's runs are given (Settings → Computers): its kind, the provider that serves it, the image it starts from, a sandbox's GPUs, whether the agent keeps it between runs, and, for a desktop or a phone, how the agent drives it, whether it may run programs on it and whether its runs record its screen. `place` is its v2 view where it can say it: `{kind: none}` is `place {mode: runner}`, `{kind: sandbox, provider: X}` is `place {mode: sandbox, box: X}`; a desktop, phone or browser computer leaves the run's folder on the runner, so its place reads runner. Writing either sets both, and both given must agree (422). Absent on a create, the server's default (as `place`); an edit that names neither keeps the agent's.",
3075
3195
  "x-agentrun-serve": "computer/1",
3076
3196
  },
3077
3197
  tool_settings: { ...AGENT_TOOL_SETTINGS, description: "The agent's own tool settings (web_search's, web_fetch's and browser's provider, any tool's permission, an MCP server's wildcard mcp:<server>/*, an MCP tool's pin, bash's policy), over the server's (GET /settings/tools), except a deny set on the server, which is absolute: the tool is refused on this server whatever this agent sets; absent, the server's. A pin is not over the server's: both hold. A grant in tools names the capability, never a provider.", "x-agentrun-serve": "providers/1" },
3078
3198
  approvals: { enum: ["ask", "never"], default: "ask", description: "Whether the agent's runs ask a person or run unattended. `ask`, the default: a tool set to ask parks the run for an approval, as its tool settings say. `never`: the agent runs unattended, and each tool that would ask is allowed instead, decided by the tool gate at each call, so a tool granted later and an MCP tool (`mcp:<server>/<tool>`, which asks by default) are covered on every harness. It never lifts a deny, whether set on this server or in the agent's own tool_settings, nor a pin, nor anything else the gate refuses before it decides between running and asking. A workflow's call node on a tool set to ask runs under `never`. Absent on a request: ask. An edit that leaves it out asks, so no edit makes an agent unattended by saying nothing. Every answer names it.", "x-agentrun-serve": "unattended/1" },
3079
- learning: { enum: [true, false, "notes"], default: false, description: "Whether an agentic revision's runs learn, and what: `true`, notes, skills and learned workflows; `\"notes\"`, notes and skills alone (a run is never given a learned workflow nor asked to draft one); `false`, nothing. A run that learns starts from what its agent has learned, its notes in its instructions under `# Learned` (each whole within the server's learning budget, else the index and the notes changed last, whole) and in `.learning/` in its working directory, and once it answers or fails is asked one more turn to add notes there, which are checked, graded and merged. Kept when a definition says so, true, false or `\"notes\"`; absent, off, and an answer shows none. An edit that leaves it out keeps the agent's. A workflow revision keeps none. On a server whose learning is off (`capabilities.features.learning`), no run learns, whatever this says.", "x-agentrun-serve": "learning/1" },
3199
+ learning: { oneOf: [{ enum: [true, false, "notes"] }, { type: "object", additionalProperties: false, properties: {
3200
+ compile_after: { type: "integer", minimum: 1, maximum: 200, default: 20, description: "The job compiles into a learned workflow once the agent has this many completed runs of its own." },
3201
+ agree_min: { type: "number", minimum: 0, maximum: 1, default: 0.8, description: "The draft's one check replays it on the inputs of those runs: promoted only when, of the inputs it answered alone, at least this share say what the agent's own recorded answer said." },
3202
+ alone_min: { type: "number", minimum: 0, maximum: 1, default: 0.7, description: "...and only when it answered at least this share of them alone (no escalate, no failed step). Under either bar it is recompiled once with the inputs it did not agree on, checked the same way, then promoted or stopped: nothing compiles again." },
3203
+ audit_every: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.audit_every, description: "Once a learned workflow serves, 1 in this many of the runs it serves (answered alone or handed back) is audited: drawn from the run's id, the same agent runs the same input again with learning off (a shadow run, hidden from the run list, its cost the agent's learning cost), and the two answers are compared (one row of GET .../learning/audits)." },
3204
+ audit_every_later: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.audit_every_later, description: "1 in this many once the workflow's revision served `audit_later_after` runs." },
3205
+ audit_later_after: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.audit_later_after, description: "The served runs after which `audit_every_later` applies." },
3206
+ hold_window: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.hold_window, description: "The audit rows of the serving revision the hold rule reads: its newest this many (an owner's grade on a served run is one too)." },
3207
+ hold_disagree: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.hold_disagree, description: "When at least this many of those rows disagree, the workflow stops serving (a hold, source `audit`) and is recompiled once with them as data, then checked again: promoted serves again, otherwise it stops. At most `hold_window`." },
3208
+ stop_window: { type: "integer", minimum: 1, maximum: AUDIT_MAX, default: AUDIT_DEFAULTS.stop_window, description: "A second hold within this many served runs of the first stops the workflow for good, asking no compile." },
3209
+ } }], default: false, description: "Whether an agentic revision's runs learn, and what: `true`, notes, skills and learned workflows; an object, the same with the loop's numbers set on it (`compile_after`, `agree_min`, `alone_min`, `audit_every`, `audit_every_later`, `audit_later_after`, `hold_window`, `hold_disagree`, `stop_window`, each optional: one left out is its default; `true` is every default); `\"notes\"`, notes and skills alone (a run is never given a learned workflow nor asked to draft one); `false`, nothing. A run that learns starts from what its agent has learned, its notes in its instructions under `# Learned` (each whole within the server's learning budget, else the index and the notes changed last, whole) and in `.learning/` in its working directory, and once it answers or fails is asked one more turn to add notes there, which are checked, graded and merged. Kept when a definition says so, true, false, `\"notes\"` or an object (its numbers in one order); a number out of range or an unknown key is a 422 `wrong_type`; absent, off, and an answer shows none. An edit that leaves it out keeps the agent's. A workflow revision keeps none. On a server whose learning is off (`capabilities.features.learning`), no run learns, whatever this says.", "x-agentrun-serve": "learning/1" },
3080
3210
  checkout: { enum: ["pull_request", "none"], description: "What the server checks out in each run's folder before its first turn, an agentic definition's alone. `pull_request`: the pull request the run's GitHub event names (a GitHub trigger's firing: its repository, number, head and base), at its head, detached, in `repo/`, with its base and their merge base fetched beside it (refs `pr/head`, `pr/base`, `pr/merge-base`). The fetch is the server's own, one command on the run's folder, with an installation token of the server's GitHub App narrowed to that repository and `contents: read`, which the agent never holds: it is never in the folder, the checkout's git config, its remote's URL, the agent's environment or the log. With no App, or one not installed there, the fetch is anonymous, which a public repository answers. The run's system prompt says what was checked out, or why nothing was (no pull request named, the fetch failed), so it can read the change another way, such as the GitHub MCP. The checkout is removed when the run's claim ends. An edit that leaves it out keeps the agent's; `none` clears it. A template sets it from its manifest's `checkout`.", "x-agentrun-serve": "checkout/1" },
3081
3211
  },
3082
3212
  AgentCreate: {
@@ -3615,6 +3745,12 @@ export function openapiDocument(capabilityOf, adapters = TRIGGER_ADAPTERS) {
3615
3745
  files["x-agentrun-serve-changed"] = { description: "signins/1", ...(added ? { responses: "signins/1" } : {}) };
3616
3746
  changed.push(`GET ${path}`);
3617
3747
  }
3748
+ // runvideo/1: a run's screen recordings are read under recordings/, as video/mp4, their byte ranges answered.
3749
+ const readFile = doc.paths["/runs/{run_id}/files/{path}"].get;
3750
+ readFile.description = `${String(readFile.description).trimEnd()}\nHere a path under \`recordings/\` is one of the run's screen recordings (the run read's \`recordings\`, made where its agent's computer says \`record: true\`), never a file the run made: \`video/mp4\`, inline unless \`?download=1\`, read-only, to whoever may read the run's other files. A folder the run made named \`recordings\` is neither listed nor served. A recording still being written is served as it stands: a fragmented MP4 plays up to its last whole fragment. \`Range\` is honoured for every file (\`features.files.range\`): one byte range, \`206\` with \`Content-Range\`, so a \`<video>\` can seek; one that starts past the end is \`416 range_not_satisfiable\`.\n`;
3751
+ for (const code of ["200", "206"])
3752
+ readFile.responses[code].content = { "video/mp4": { schema: { type: "string", contentMediaType: "video/mp4" } }, ...readFile.responses[code].content };
3753
+ readFile["x-agentrun-serve-changed"] = { ...readFile["x-agentrun-serve-changed"], responses: "runvideo/1" };
3618
3754
  // An agentic run's cancel is its end at once: the 202 reads `cancelled`, and no later end of its turn moves it.
3619
3755
  const cancel = doc.paths["/runs/{run_id}/cancel"].post;
3620
3756
  cancel.description = `${String(cancel.description).trimEnd()}\nHere an agentic run reads \`cancelled\` from the 202 on, \`final\` once it has stopped: a run's first terminal status is its last, so nothing its cut turn writes later (an answer, a cost over its cap) moves it. A workflow run reads \`cancelled\` once its workflow has stopped.\n`;
@@ -26,6 +26,10 @@ export declare function listFiles(workspace: Workspace, cap: number, { owned: is
26
26
  /** The listing entry at `rel`, a file's or a folder's, or undefined when there is none: not there, or a link (never
27
27
  * listed). */
28
28
  export declare function entryAt(workspace: Workspace, rel: string): Promise<Entry | undefined>;
29
- /** File `rel` of `workspace`, raw, in reads of SEND_CHUNK: its length from the listing, so HEAD reads no byte. `who`
30
- * names who makes a file private, in the words of a 403. */
29
+ /** The one byte range a Range header asks of a file of `size` bytes, first and last byte; undefined for the whole file (no
30
+ * Range, or one this server does not take: another unit, several ranges, or a last byte before the first);
31
+ * "unsatisfiable" when it starts past the file's end. */
32
+ export declare function rangeOf(header: string | undefined, size: number): [number, number] | "unsatisfiable" | undefined;
33
+ /** File `rel` of `workspace`, raw, in reads of SEND_CHUNK, whole or the one byte range its Range header asks (206): its
34
+ * length from the listing, so HEAD reads no byte. `who` names who makes a file private, in the words of a 403. */
31
35
  export declare function sendFile(req: IncomingMessage, res: ServerResponse, url: URL, workspace: Workspace, rel: string, who: string): Promise<void>;