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

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 (116) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/NOTICE +2 -0
  3. package/README.md +77 -12
  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-DYJ_wj27.js +711 -0
  29. package/dist/console/index.html +1 -1
  30. package/dist/eval-feed.d.ts +2 -2
  31. package/dist/eval-feed.js +9 -5
  32. package/dist/feed/parse.d.ts +3 -2
  33. package/dist/feed/parse.js +9 -18
  34. package/dist/feed/pointer.d.ts +2 -0
  35. package/dist/feed/pointer.js +17 -0
  36. package/dist/file-types.js +1 -0
  37. package/dist/host-command.d.ts +3 -0
  38. package/dist/host-command.js +18 -0
  39. package/dist/host.d.ts +3 -0
  40. package/dist/host.js +3 -0
  41. package/dist/learn/check.d.ts +14 -0
  42. package/dist/learn/check.js +194 -14
  43. package/dist/learn/compile.d.ts +48 -27
  44. package/dist/learn/compile.js +134 -101
  45. package/dist/learn/promote.d.ts +61 -5
  46. package/dist/learn/promote.js +12 -2
  47. package/dist/learning-setting.d.ts +23 -0
  48. package/dist/learning-setting.js +51 -0
  49. package/dist/learning-words.d.ts +3 -0
  50. package/dist/learning-words.js +3 -0
  51. package/dist/learning.d.ts +3 -2
  52. package/dist/learning.js +5 -3
  53. package/dist/mcp-oauth.d.ts +8 -0
  54. package/dist/mcp-oauth.js +7 -0
  55. package/dist/mcp-private-hosts.d.ts +13 -0
  56. package/dist/mcp-private-hosts.js +16 -0
  57. package/dist/openapi.d.ts +1 -0
  58. package/dist/openapi.js +105 -9
  59. package/dist/run-files.d.ts +6 -2
  60. package/dist/run-files.js +29 -7
  61. package/dist/run-learning-served.d.ts +1 -1
  62. package/dist/run-reads-over-store.d.ts +5 -1
  63. package/dist/run-reads-over-store.js +8 -4
  64. package/dist/run-recordings.d.ts +20 -0
  65. package/dist/run-recordings.js +133 -0
  66. package/dist/runner/adapter-loop.d.ts +1 -1
  67. package/dist/runner/adapter-loop.js +3 -6
  68. package/dist/runner/adapter-run-spec.d.ts +16 -1
  69. package/dist/runner/adapter-run-spec.js +20 -6
  70. package/dist/runner/beside.js +1 -1
  71. package/dist/runner/cli-run-spec.js +10 -7
  72. package/dist/runner/feedback-round.d.ts +9 -25
  73. package/dist/runner/feedback-round.js +22 -40
  74. package/dist/runner/learning-end.d.ts +17 -7
  75. package/dist/runner/learning-end.js +79 -53
  76. package/dist/runner/main.d.ts +11 -0
  77. package/dist/runner/main.js +29 -2
  78. package/dist/runner/mcp-run.d.ts +2 -2
  79. package/dist/runner/promotion.d.ts +36 -4
  80. package/dist/runner/promotion.js +280 -20
  81. package/dist/runner/reflect-hook.d.ts +5 -0
  82. package/dist/runner/reflect-hook.js +22 -14
  83. package/dist/runner/store-secrets.js +3 -1
  84. package/dist/runner/workflow-first.d.ts +0 -6
  85. package/dist/runner/workflow-first.js +7 -13
  86. package/dist/runs-over-store.d.ts +1 -1
  87. package/dist/sdk/runs.js +2 -1
  88. package/dist/secrets.js +2 -2
  89. package/dist/server.d.ts +4 -3
  90. package/dist/server.js +72 -11
  91. package/dist/store/agent-body.d.ts +5 -3
  92. package/dist/store/agent-body.js +14 -10
  93. package/dist/store-reads/learning.d.ts +1 -1
  94. package/dist/store-reads/loop.d.ts +1 -0
  95. package/dist/store-reads/loop.js +14 -4
  96. package/dist/store-view.d.ts +5 -0
  97. package/dist/store-view.js +4 -0
  98. package/dist/template-eval.d.ts +7 -0
  99. package/dist/template-eval.js +54 -6
  100. package/dist/templates.d.ts +3 -1
  101. package/dist/templates.js +14 -1
  102. package/dist/timeline/computer.js +2 -1
  103. package/dist/tool-list.js +1 -0
  104. package/dist/tools.d.ts +7 -0
  105. package/dist/tools.js +11 -0
  106. package/dist/trigger-feed.js +67 -18
  107. package/dist/validate.js +7 -2
  108. package/dist/workspace/computer-for-claim.d.ts +7 -0
  109. package/dist/workspace/computer-for-claim.js +12 -2
  110. package/dist/workspace/paths.d.ts +4 -0
  111. package/dist/workspace/paths.js +9 -0
  112. package/dist/workspace/resolve-computer.d.ts +3 -1
  113. package/launcher/agentrun-serve +31 -24
  114. package/package.json +10 -9
  115. package/templates/README.md +11 -2
  116. package/dist/console/assets/index-COGhx_2Z.js +0 -711
package/dist/sdk/runs.js CHANGED
@@ -7,6 +7,7 @@ import { canonical, isObject } from "../store/agent-body.js";
7
7
  import { uuidv7 } from "../agents-store.js";
8
8
  import { launchBody } from "../run-launch.js";
9
9
  import { learningStartFor } from "../runs-over-store.js";
10
+ import { learnsWorkflowsOf } from "../learning-setting.js";
10
11
  import { chooseWorkflows, chooseSkills, learningFolderOf, readerOf, seedFrom, secretsShown } from "../learning.js";
11
12
  import { NATIVE_GRADE_INSTRUCTION_BYTES } from "../learn/grade.js";
12
13
  import { secretRedactor } from "../runner/redact.js";
@@ -185,7 +186,7 @@ export class SdkRuns {
185
186
  const revisionBody = entry.revision.body;
186
187
  if (revisionBody.maxCostUsd !== undefined)
187
188
  throw new ApiError("agent_not_runnable", "AgentRun cannot enforce a spend cap on an external SDK. Configure the budget in the backend SDK and remove this managed run cap.");
188
- const learning = await learningStartFor(deps, entry, pinned.revision, { ...revisionBody, ...(!workflow && revisionBody.learning === true ? { learning: "notes" } : {}) }, { content: cleanedInput });
189
+ const learning = await learningStartFor(deps, entry, pinned.revision, { ...revisionBody, ...(!workflow && learnsWorkflowsOf(revisionBody.learning) ? { learning: "notes" } : {}) }, { content: cleanedInput });
189
190
  if (learning) {
190
191
  if (Buffer.byteLength(instructions) > NATIVE_GRADE_INSTRUCTION_BYTES)
191
192
  refuse("Original SDK instructions exceed the 64 KiB grading evidence limit. Keep learning off or provide a complete policy within that limit.");
package/dist/secrets.js CHANGED
@@ -50,8 +50,8 @@ function decode(bytes) {
50
50
  signIn = pair.slice(at + 1);
51
51
  }
52
52
  }
53
- /** Exactly `length` bytes of `fd`: the writer keeps its end open (the launcher's FIFO is open read-write), so there is
54
- * no end of file to wait for. */
53
+ /** Exactly `length` bytes of `fd`, read as the launcher's writer writes them: the end of file before then is a writer
54
+ * gone short, and refused. */
55
55
  function readExactly(fd, length) {
56
56
  const bytes = Buffer.alloc(length);
57
57
  for (let read = 0; read < length;) {
package/dist/server.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type ModelNeeds } from "./model.js";
2
2
  import { type HarnessCapability } from "./harness.js";
3
3
  import { type HarnessInstaller } from "./harness-install.js";
4
+ import { DEFAULT_PORT } from "./host.js";
4
5
  import { type LearningMode } from "./learning.js";
5
6
  import { type Place } from "./place.js";
6
7
  import { type ApiToken } from "./api-token.js";
@@ -13,7 +14,7 @@ import { type TriggerClock } from "./triggers.js";
13
14
  import { type ToolSettingsMap } from "./tool-plane.js";
14
15
  import { AttachHub, type HostedDial } from "@parcha/agentrun-computer";
15
16
  export declare const CONTRACT = "agentrun.v2/0";
16
- export declare const DEFAULT_PORT = 7340;
17
+ export { DEFAULT_PORT };
17
18
  export type ServeOptions = {
18
19
  /** The data directory: the agent store (`store.sqlite`) and its runs (`runs/<id>/`). */
19
20
  data: string;
@@ -239,7 +240,8 @@ export type Serve = {
239
240
  dial: HostedDial;
240
241
  /** Whether this server is a local install (listening on loopback, reached at no address off it): the one kind whose own
241
242
  * runner beside it may reach an MCP server's URL on loopback (runner/beside.ts mcpLoopback). Only that runner is told:
242
- * it is this process's finding, never a store's, so another host's runner on a shared store never inherits it. */
243
+ * it is this process's finding, never a store's, so another runner on a shared store never inherits it. A runner in
244
+ * its own process takes its own operator's opt-in from its own environment (runner/main.ts runnerLoopback). */
243
245
  localInstall: boolean;
244
246
  /** This server's own addresses (McpServersOverStore.own): where it listens, and its public address when that is on
245
247
  * loopback. The runner beside it is told them with localInstall (runner/beside.ts mcpOwn), so its runs' loopback reads
@@ -907,4 +909,3 @@ export declare function forCaller<T extends {
907
909
  learning: LearningCaps;
908
910
  }>(caps: T, ownerSession: boolean): T;
909
911
  export declare function startServe(options: ServeOptions): Promise<Serve>;
910
- export {};
package/dist/server.js CHANGED
@@ -41,7 +41,7 @@ import { chooseModel, EFFORTS, FAUX_ENV, FAUX_UPSTREAM_ENV, MODEL_NODES, modelSo
41
41
  import { DEFAULT_HARNESS, HARNESSES, harnessOfBody, harnessOffers } from "./harness.js";
42
42
  import { HARNESS_TABLE_ENV, harnessOf } from "./harness-table.js";
43
43
  import { HarnessInstall, installDirOf, NPM_STOP_GRACE_MS, npmInstall } from "./harness-install.js";
44
- import { healthOf, hostMemory, maxRunsOf, MIN_FREE_MIB, runsThatFit } from "./host.js";
44
+ import { DEFAULT_PORT, healthOf, hostMemory, maxRunsOf, MIN_FREE_MIB, runsThatFit } from "./host.js";
45
45
  import { IMPORT_ASKED } from "./import.js";
46
46
  import { answerStoreCall } from "./import-proxy.js";
47
47
  import { gradeModelOf, LEARNING_LABEL, learningBudgetOf, learningFolderOf, learningOf, learnsOf, RUN_LEARNING_USE, seedOf } from "./learning.js";
@@ -117,12 +117,12 @@ import { signInsOverStore } from "./sign-ins-store.js";
117
117
  import { boundTool, MCP_AUTH_TYPES, marked, mcpAuthOf, nameOf as mcpNameOf } from "./mcp-probe.js";
118
118
  import { composioForget, composioNote, composioSave, composioTools } from "./composio-preset.js";
119
119
  import { ComposioTriggers } from "./composio-triggers.js";
120
- import { mcpServersOverStore } from "./mcp-servers-store.js";
120
+ import { loopbackWords, mcpServersOverStore } from "./mcp-servers-store.js";
121
121
  import { getMcpServer, listMcpServers } from "./mcp-store.js";
122
- import { privateHostsRoute } from "./mcp-private-hosts.js";
122
+ import { privateHostsRoute, saveServerOwn } from "./mcp-private-hosts.js";
123
123
  import { metaToolOf } from "./mcp-meta.js";
124
124
  import { mcpPinOf } from "./mcp-gateway.js";
125
- import { MCP_SETTINGS_PAGE, signInCookie, startedHere } from "./mcp-oauth.js";
125
+ import { LOOPBACK, MCP_SETTINGS_PAGE, signInCookie, startedHere } from "./mcp-oauth.js";
126
126
  import { WEBHOOK_EVENTS, WEBHOOK_FILE, waitMarkerOf, Webhooks } from "./webhooks.js";
127
127
  import { appPermissionWarnings } from "./template-github-permissions.js";
128
128
  import { templateApplied, templateTriggerSecret, templateWebhookSecrets, triggerMade, triggerRotated, webhookSaved, withTriggerSecret } from "./trigger-secrets-shown.js";
@@ -151,6 +151,8 @@ import { toolSettingsOverStore } from "./tool-settings-store.js";
151
151
  import { readApprovers, writeApprovers } from "./server-approvers.js";
152
152
  import { MAX_FILES_PER_RUN, MAX_UPLOAD_BYTES, Uploads, UPLOADS_DIR } from "./uploads.js";
153
153
  import { entryAt, listFiles, sendFile as sendWorkspaceFile, viewOf } from "./run-files.js";
154
+ import { recordingsOf, recordingsWorkspace } from "./run-recordings.js";
155
+ import { recordingsFolder } from "./workspace/paths.js";
154
156
  import { heldRoute, holdIssues, runComputerRead } from "./computer-held-routes.js";
155
157
  import { COMPUTER_ROUTES, computerHoldOf, computerRoute, runComputerKind } from "./computer-routes.js";
156
158
  import { ATTACH_PATH, AttachHub, PROVIDERS as COMPUTER_PROVIDERS, SETTING_KINDS, servingRefusals } from "@parcha/agentrun-computer";
@@ -161,6 +163,8 @@ import { freeModelRequestsOf } from "@parcha/agentrun-kernel/kernel/cap";
161
163
  import { archilRoute, createArchilRoutes, liveRunsOnDisk } from "./archil-routes.js";
162
164
  import { noAccount, openAccount } from "./email/account.js";
163
165
  import { emailRoute } from "./email/routes.js";
166
+ import { addressForms, openCalendar } from "./calendar/address.js";
167
+ import { calendarRoute } from "./calendar/routes.js";
164
168
  import { agentDiskOf, ARCHIL_DISK_ID, archilSettingsFromEnv, inArchilMode } from "./archil-settings.js";
165
169
  import { computerOfPlace } from "./computer-setting.js";
166
170
  import { computerCapabilities, createComputerRoutes, folderModeOf, hostCommandRefusals, settingsComputerRoute } from "./computers.js";
@@ -171,7 +175,7 @@ import { keyReader } from "./key-meta.js";
171
175
  export const CONTRACT = "agentrun.v2/0";
172
176
  /** A process's flags for a worker of it: without --input-type and the code string given with -e, --eval, -p or --print. */
173
177
  const workerArgs = (args) => args.filter((arg, i) => !arg.startsWith("--input-type") && !/^(?:-e|--eval|-p|--print)(?:=|$)/.test(arg) && !/^(?:-e|--eval|-p|--print)$/.test(args[i - 1] ?? ""));
174
- export const DEFAULT_PORT = 7340;
178
+ export { DEFAULT_PORT };
175
179
  const VERSION = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8")).version;
176
180
  const IDEMPOTENCY_FILE = ".idempotency.json";
177
181
  /** A run's live viewer, under the run's path (browser-live.ts): its run id, the family's address (`computer`, one for every
@@ -334,6 +338,11 @@ export const ROUTES = [
334
338
  { method: "PUT", pattern: /^\/settings\/email$/, name: "saveEmailAccount" },
335
339
  { method: "DELETE", pattern: /^\/settings\/email$/, name: "deleteEmailAccount" },
336
340
  { method: "POST", pattern: /^\/settings\/email\/test$/, name: "testEmailAccount" },
341
+ // The server's calendar (calendar/routes.ts): the owner's session's alone, its address in no answer.
342
+ { method: "GET", pattern: /^\/settings\/calendar$/, name: "getCalendar" },
343
+ { method: "PUT", pattern: /^\/settings\/calendar$/, name: "saveCalendar" },
344
+ { method: "DELETE", pattern: /^\/settings\/calendar$/, name: "deleteCalendar" },
345
+ { method: "POST", pattern: /^\/settings\/calendar\/test$/, name: "testCalendar" },
337
346
  { method: "GET", pattern: /^\/settings\/chatgpt$/, name: "getChatGPTSignIn" },
338
347
  { method: "DELETE", pattern: /^\/settings\/chatgpt$/, name: "signOutChatGPT" },
339
348
  { method: "POST", pattern: /^\/settings\/chatgpt\/sign-in$/, name: "startChatGPTSignIn" },
@@ -583,7 +592,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced },
583
592
  runs: { stop: true, cancel: true, kill: false, list: true, kinds: ["agentic", "workflow"], pause_workflow_runs: true, graph: true },
584
593
  messages: { steer: true, answer: true, follow_up: true, steer_workflow_runs: false },
585
594
  timeline: { long_poll: true, sse: true, live_rows: true, live_workflow_rows: false },
586
- files: { upload: true, read: true, range: false, during_run: true },
595
+ files: { upload: true, read: true, range: true, during_run: true },
587
596
  quotes: false,
588
597
  usage: { basis: "estimate", meters: ["tokens", "tools", "browser_time", "learning"] },
589
598
  efforts: [...EFFORTS],
@@ -1147,6 +1156,17 @@ async function startHolding(options, data, checked, stops) {
1147
1156
  };
1148
1157
  await heldEmailPassword();
1149
1158
  secretStores.add("email", () => [...emailPasswords]);
1159
+ // The calendar's iCal address (calendar/address.ts), in each of its forms, and each one saved since this server started:
1160
+ // the address reads the calendar, so it is cut from everything the server shows, as a password is.
1161
+ const calendarAddresses = new Set();
1162
+ const heldCalendar = async () => {
1163
+ const url = (await openCalendar(store, sealKey).catch(() => undefined))?.url;
1164
+ if (url)
1165
+ for (const form of addressForms(url))
1166
+ calendarAddresses.add(form);
1167
+ };
1168
+ await heldCalendar();
1169
+ secretStores.add("calendar", () => [...calendarAddresses]);
1150
1170
  // Each agent's saved sign-ins, over the one store (module A, sign-ins-store): the vendor's calls on the server's keys
1151
1171
  // (under faux, the vendor's fake alone), under this server's seal key. The store holds whether a sign-in is still held
1152
1172
  // (a live run's sign_in_handed) and who was handed it, so this takes no `holds`/`handedTo` callback — one store, one lock.
@@ -1354,6 +1374,10 @@ async function startHolding(options, data, checked, stops) {
1354
1374
  // What a run held for its owner's OK reads as it stands on its agent's learning folder's main (statusesOf).
1355
1375
  const statuses = (agentId) => statusesOf(data, agentId);
1356
1376
  const viewDepsFor = (origin) => ({ origin, serverSecrets, signIns, keyEnv: () => own(withSecrets(process.env, "all", storedKeys)), statuses });
1377
+ // A run read as a whole (its own read, its archive) lists its recordings too, from its recordings folder on this machine
1378
+ // (run-recordings.ts), where the runner beside it wrote them; every other read of the view opens no file.
1379
+ const recordings = (agentId, runId, endedAt) => recordingsOf(recordingsFolder(data, agentId, runId), endedAt);
1380
+ const runReadDepsFor = (origin) => ({ ...viewDepsFor(origin), recordings });
1357
1381
  const ownOriginOf = () => options.publicUrl ?? url;
1358
1382
  // The run read routes (a run's files, its browser state, its workflow graph) over the one store (run-reads-over-store):
1359
1383
  // a run's files through the server's read-only Workspace of its folder (serverRunWorkspace, no runner claim), its view
@@ -1362,6 +1386,10 @@ async function startHolding(options, data, checked, stops) {
1362
1386
  // timeline route keeps its own stub (store-reads journal + SSE) until E2c's timeline lands.
1363
1387
  const runReadsDeps = {
1364
1388
  runWorkspace: (_store, runId) => serverRunWorkspace(store, runId, { data, sealKey, env: withSecrets(process.env, "own") }),
1389
+ recordings: async (_store, runId) => {
1390
+ const run = await store.runs.get(runId);
1391
+ return run ? recordingsWorkspace(recordingsFolder(data, run.agentId, runId)) : null;
1392
+ },
1365
1393
  env,
1366
1394
  runFacts: (_store, runId) => factsOverStore(store, runId, viewDepsFor(ownOriginOf())),
1367
1395
  withheld: (_store, runId) => withheldOverStore(store, runId, viewDepsFor(ownOriginOf())),
@@ -1871,7 +1899,14 @@ async function startHolding(options, data, checked, stops) {
1871
1899
  if (!named || !mcpMeta.has(named.server))
1872
1900
  return [];
1873
1901
  const pinned = Object.hasOwn(pin, named.server) && pin[named.server].tools.some((one) => one.name === named.tool);
1874
- return pinned ? [] : [{ field: `definition.tools[${index}]`, reason: "not_an_option", message: `The MCP tool ${tool} was not pinned when this revision was saved: save the agent again to pin it.`, tool }];
1902
+ if (pinned)
1903
+ return [];
1904
+ // Its first run could not pin it (mcp-pin-first.ts) because this server refuses its server's address: a loopback
1905
+ // one on a server whose operator never said it is a local install. Saving again is refused the same way, so the
1906
+ // words say the cause, as the save's refusal does (mcp-servers-store.ts reached).
1907
+ const at = URL.parse(mcpMeta.get(named.server).url)?.hostname ?? "";
1908
+ const why = options.mcpLoopback !== true && LOOPBACK.test(at) ? `its server ${named.server} can't be listed here to pin it: ${loopbackWords(at)}` : "save the agent again to pin it.";
1909
+ return [{ field: `definition.tools[${index}]`, reason: "not_an_option", message: `The MCP tool ${tool} was not pinned when this revision was saved: ${why}`, tool }];
1875
1910
  });
1876
1911
  if (unpinned.length)
1877
1912
  throw new ApiError("agent_not_runnable", unpinned.map((one) => one.message).join(" "), { fields: unpinned.map(({ tool: _tool, ...issue }) => issue), details: { unbound: unpinned.map((one) => one.tool), missing: {} } });
@@ -3385,7 +3420,7 @@ async function startHolding(options, data, checked, stops) {
3385
3420
  return send(res, 200, await runsPage(url, { ...(agent ? { agent } : {}), ...(revision ? { revision } : {}) }, linkOrigin(req)));
3386
3421
  }
3387
3422
  case "getRun": {
3388
- const view = await viewOverStore(store, id, viewDepsFor(linkOrigin(req)));
3423
+ const view = await viewOverStore(store, id, runReadDepsFor(linkOrigin(req)));
3389
3424
  if (!view)
3390
3425
  throw new ApiError("not_found", `no run ${id}`);
3391
3426
  return send(res, 200, { ...view, ...(await runComputerOf(id, view)) });
@@ -3494,7 +3529,7 @@ async function startHolding(options, data, checked, stops) {
3494
3529
  ...(typeof m.workflow === "string" ? { workflow: m.workflow } : {}), ...(typeof m.workflow_digest === "string" ? { digest: m.workflow_digest } : {}),
3495
3530
  ...(typeof m.workflow_promotion === "number" ? { promotion: m.workflow_promotion } : {}),
3496
3531
  };
3497
- // Kept with what it asks of the run's learning (runner/feedback-round.ts): nothing, a revision ask, or a look-back.
3532
+ // Kept with what it asks of the run's learning (runner/feedback-round.ts): nothing, or a look-back.
3498
3533
  const kept = gradeView(await keepGrade(store, row.agentId, grade, typeof body.label === "string" ? body.label : undefined));
3499
3534
  // Its workflow's name cut as GET /runs/{id}/learning cuts it (learningShown); withheld whole when that cut can't be
3500
3535
  // read (the grade is kept by then: never a shorter cut, never a refusal of a grade it kept).
@@ -3505,7 +3540,7 @@ async function startHolding(options, data, checked, stops) {
3505
3540
  case "unarchiveRun": {
3506
3541
  const run = await needRun(id);
3507
3542
  await archiveRun(store, run.id, found.name === "archiveRun");
3508
- return send(res, 200, await viewOverStore(store, run.id, viewDepsFor(linkOrigin(req))));
3543
+ return send(res, 200, await viewOverStore(store, run.id, runReadDepsFor(linkOrigin(req))));
3509
3544
  }
3510
3545
  case "getRunBrowser":
3511
3546
  case "getRunComputer": {
@@ -3801,6 +3836,24 @@ async function startHolding(options, data, checked, stops) {
3801
3836
  return void res.writeHead(204, { "cache-control": "no-store" }).end();
3802
3837
  return send(res, 200, answer, { "cache-control": "no-store" });
3803
3838
  }
3839
+ // Never through `idempotent` either: its record keeps the body, and the body holds the calendar's address. A read
3840
+ // reaches loopback only on a local install (its fakes), and a private host only where the owner allows it.
3841
+ case "getCalendar":
3842
+ case "saveCalendar":
3843
+ case "deleteCalendar":
3844
+ case "testCalendar": {
3845
+ const body = found.name === "saveCalendar" || found.name === "testCalendar" ? await bodyOf(req) : undefined;
3846
+ if (found.name === "saveCalendar" && stopping.signal.aborted)
3847
+ throw new ApiError("unavailable", "The server is shutting down: the calendar was not saved.");
3848
+ // The MCP servers' network and reach (mcp-oauth.ts calendarAt is mcpServerAt's rule), and their stop with the server's.
3849
+ const outbound = await mcpServers.outboundReach();
3850
+ const answer = await calendarRoute({ store, sealKey, reach: async () => outbound.reach, network: outbound.network, signal: AbortSignal.any([outbound.signal, stopping.signal]) }, found.name, body);
3851
+ if (found.name === "saveCalendar")
3852
+ await heldCalendar();
3853
+ if (answer === undefined)
3854
+ return void res.writeHead(204, { "cache-control": "no-store" }).end();
3855
+ return send(res, 200, answer, { "cache-control": "no-store" });
3856
+ }
3804
3857
  // The ChatGPT sign-in (chatgpt-plan.ts): a step it refuses is 400 in its words; its token is in no answer.
3805
3858
  case "getChatGPTSignIn":
3806
3859
  await planNow();
@@ -4038,7 +4091,7 @@ async function startHolding(options, data, checked, stops) {
4038
4091
  return { ...one, workflow, from_notes: one.from_notes.map(shown.name), attempts: one.attempts.map(({ ok, errors }) => ({ ok, errors: errors.map(said) })), draft_errors: one.draft_errors.map(said), withheld: false };
4039
4092
  }));
4040
4093
  const guards = read.guards.map((one) => ({ ...one, workflow: shown.name(one.workflow), node: shown.text(one.node) }));
4041
- return send(res, 200, { agent: id, compiles, guards });
4094
+ return send(res, 200, { agent: id, completed_runs: read.completed_runs, compiles, guards });
4042
4095
  }
4043
4096
  case "listLearningNotes":
4044
4097
  case "listLearningLog":
@@ -4435,6 +4488,14 @@ async function startHolding(options, data, checked, stops) {
4435
4488
  // listens: a hosted container listens on loopback behind its proxy too.
4436
4489
  const localInstall = options.mcpLoopback === true;
4437
4490
  mcpServers.attach(options.publicUrl ?? url, url, localInstall);
4491
+ // Its own addresses, kept in the store for a runner in its own process whose own opt-in lets it reach loopback: its runs
4492
+ // never reach this server's ports there either (mcp-private-hosts.ts saveServerOwn). It listens already: a write that
4493
+ // fails stops the start and lets go of the port, as the start's other stops let go of the store and the locks.
4494
+ await saveServerOwn(store, mcpServers.own).catch(async (error) => {
4495
+ server.closeAllConnections();
4496
+ await new Promise((done) => server.close(() => done()));
4497
+ throw error;
4498
+ });
4438
4499
  // A run's end and its wait are the outbound webhook's run.ended and run.needs_input (webhooks.ts). The runners write them
4439
4500
  // to the store and this server runs no run, so it follows the store's run-change feed (Store.runs.changedSince): every
4440
4501
  // run reaching a final state, or let go by its runner (parked, or running with none), once, in order, under a cursor
@@ -1,4 +1,5 @@
1
1
  import type { NativeBinding } from "../native/types.js";
2
+ import { type LearningSetting } from "../learning-setting.js";
2
3
  /** A revision's body the store refuses: its content is not one the store keeps. The server maps it to an input refusal. */
3
4
  export declare class AgentBodyInvalid extends Error {
4
5
  constructor(message: string);
@@ -30,7 +31,7 @@ export type RevisionPlace = {
30
31
  /** A revision's computer (computer-setting.ts): its kind and the provider that serves it, ids its host knows, and a
31
32
  * sandbox's GPUs, a type its provider names and how many; `place` is its v2 view. `image`: one the provider offers for
32
33
  * the kind, absent for its default. A desktop's or a phone's surface and exec: how the agent drives it, and whether it
33
- * may run programs on it. */
34
+ * may run programs on it, and whether each run records a video of its screen. */
34
35
  export type RevisionComputer = {
35
36
  kind: string;
36
37
  provider?: string;
@@ -42,6 +43,7 @@ export type RevisionComputer = {
42
43
  persistent?: boolean;
43
44
  surface?: "code" | "tools";
44
45
  exec?: boolean;
46
+ record?: boolean;
45
47
  };
46
48
  /** A revision's tool settings as its body keeps them: a map of a tool's key to its settings ({provider?, permission?,
47
49
  * pin?}), checked and made canonical by the caller (agents-store.ts, through tool-plane's settingsIssues +
@@ -73,7 +75,7 @@ export type AgenticBody = {
73
75
  harness?: string;
74
76
  place?: RevisionPlace;
75
77
  computer?: RevisionComputer;
76
- learning?: boolean | "notes";
78
+ learning?: LearningSetting;
77
79
  toolSettings?: ToolSettings;
78
80
  maxCostUsd?: number;
79
81
  approvals?: "ask" | "never";
@@ -108,7 +110,7 @@ export type RevisionBodyInput = {
108
110
  harness?: string;
109
111
  place?: unknown;
110
112
  computer?: unknown;
111
- learning?: boolean | "notes";
113
+ learning?: LearningSetting;
112
114
  toolSettings?: ToolSettings;
113
115
  maxCostUsd?: number;
114
116
  approvals?: "ask" | "never";
@@ -7,6 +7,7 @@
7
7
  // two equal pins are one revision.
8
8
  import { createHash } from "node:crypto";
9
9
  import { nativeBindingOf } from "../native/binding.js";
10
+ import { learningSettingIssue, learningSettingOf } from "../learning-setting.js";
10
11
  /** A revision's body the store refuses: its content is not one the store keeps. The server maps it to an input refusal. */
11
12
  export class AgentBodyInvalid extends Error {
12
13
  constructor(message) {
@@ -46,24 +47,24 @@ function placeOf(place) {
46
47
  /** A GPU type as a body keeps it: the vendor's own name ("T4", "A100-80GB", "RTX-PRO-6000"). */
47
48
  const GPU_TYPE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
48
49
  /** The keys a body's computer keeps. */
49
- const COMPUTER_KEYS = new Set(["kind", "provider", "image", "gpu", "persistent", "surface", "exec"]);
50
- /** A computer as a body keeps it: `{kind, provider?, image?, gpu?, persistent?, surface?, exec?}`, nothing else: kind
51
- * and provider ids, image a name with no spaces around it, gpu `{type, count}`, a GPU type name and a whole count from
52
- * 1, persistent and exec booleans, and surface code or tools. */
50
+ const COMPUTER_KEYS = new Set(["kind", "provider", "image", "gpu", "persistent", "surface", "exec", "record"]);
51
+ /** A computer as a body keeps it: `{kind, provider?, image?, gpu?, persistent?, surface?, exec?, record?}`, nothing
52
+ * else: kind and provider ids, image a name with no spaces around it, gpu `{type, count}`, a GPU type name and a whole
53
+ * count from 1, persistent, exec and record booleans, and surface code or tools. */
53
54
  function computerOf(computer) {
54
55
  const image = isObject(computer) ? computer.image : undefined;
55
56
  const named = (value) => typeof value === "string" && value !== "" && value === value.trim();
56
57
  const flag = (value) => value === undefined || typeof value === "boolean";
57
58
  const surface = isObject(computer) ? computer.surface : undefined;
58
- if (!isObject(computer) || !hostId(computer.kind) || (computer.provider !== undefined && !hostId(computer.provider)) || (image !== undefined && !named(image)) || !flag(computer.persistent) || !flag(computer.exec) || (surface !== undefined && surface !== "code" && surface !== "tools") || Object.keys(computer).some((key) => !COMPUTER_KEYS.has(key)))
59
- invalid("the computer is not {kind, provider?, image?, gpu?, persistent?, surface?, exec?}, kind and provider each an id (lowercase letters, digits and dashes), image a name, persistent a boolean, surface code or tools, exec a boolean");
59
+ if (!isObject(computer) || !hostId(computer.kind) || (computer.provider !== undefined && !hostId(computer.provider)) || (image !== undefined && !named(image)) || !flag(computer.persistent) || !flag(computer.exec) || !flag(computer.record) || (surface !== undefined && surface !== "code" && surface !== "tools") || Object.keys(computer).some((key) => !COMPUTER_KEYS.has(key)))
60
+ invalid("the computer is not {kind, provider?, image?, gpu?, persistent?, surface?, exec?, record?}, kind and provider each an id (lowercase letters, digits and dashes), image a name, persistent a boolean, surface code or tools, exec a boolean, record a boolean");
60
61
  const ok = computer;
61
62
  const gpu = ok.gpu;
62
63
  if (gpu !== undefined && (!isObject(gpu) || Object.keys(gpu).some((key) => key !== "type" && key !== "count") || typeof gpu.type !== "string" || !GPU_TYPE.test(gpu.type) || !Number.isSafeInteger(gpu.count) || gpu.count < 1)) {
63
64
  invalid("the computer's gpu is not {type, count}: a GPU type name (letters, digits, dots, underscores and dashes) and a whole count from 1");
64
65
  }
65
66
  const kept = gpu;
66
- return { kind: ok.kind, ...(ok.provider !== undefined ? { provider: ok.provider } : {}), ...(ok.image !== undefined ? { image: ok.image } : {}), ...(kept !== undefined ? { gpu: { type: kept.type, count: kept.count } } : {}), ...(ok.persistent !== undefined ? { persistent: ok.persistent } : {}), ...(ok.surface !== undefined ? { surface: ok.surface } : {}), ...(ok.exec !== undefined ? { exec: ok.exec } : {}) };
67
+ return { kind: ok.kind, ...(ok.provider !== undefined ? { provider: ok.provider } : {}), ...(ok.image !== undefined ? { image: ok.image } : {}), ...(kept !== undefined ? { gpu: { type: kept.type, count: kept.count } } : {}), ...(ok.persistent !== undefined ? { persistent: ok.persistent } : {}), ...(ok.surface !== undefined ? { surface: ok.surface } : {}), ...(ok.exec !== undefined ? { exec: ok.exec } : {}), ...(ok.record !== undefined ? { record: ok.record } : {}) };
67
68
  }
68
69
  /** The body of a new revision and the text of each skill it names (path to text), everything checked here, before any
69
70
  * write. The body keeps each skill path to its text's SHA-256; `skills` is the texts, for the revision's row. */
@@ -113,8 +114,11 @@ export function bodyOf(input) {
113
114
  for (const field of ["model", "thinking"])
114
115
  if (input[field] !== undefined && (typeof input[field] !== "string" || input[field] === ""))
115
116
  invalid(`the ${field} is not a non-empty string`);
116
- if (input.learning !== undefined && typeof input.learning !== "boolean" && input.learning !== "notes")
117
- invalid("learning is not true, false or \"notes\"");
117
+ if (input.learning !== undefined) {
118
+ const wrong = learningSettingIssue(input.learning);
119
+ if (wrong)
120
+ invalid(wrong);
121
+ }
118
122
  if (input.inputSchema !== undefined && !isObject(input.inputSchema))
119
123
  invalid("the inputSchema is not a JSON object");
120
124
  if (input.outputSchema !== undefined && !isObject(input.outputSchema))
@@ -138,7 +142,7 @@ export function bodyOf(input) {
138
142
  ...(input.thinking !== undefined ? { thinking: input.thinking } : {}),
139
143
  ...(input.prompts !== undefined ? { prompts: structuredClone(input.prompts) } : {}),
140
144
  ...host,
141
- ...(input.learning !== undefined ? { learning: input.learning } : {}),
145
+ ...(input.learning !== undefined ? { learning: learningSettingOf(input.learning) } : {}),
142
146
  // The JSON Schema each run's input meets (definition.input_schema), checked at every start (validate.ts inputSchemaOf).
143
147
  ...(input.inputSchema !== undefined ? { inputSchema: structuredClone(input.inputSchema) } : {}),
144
148
  // The JSON Schema its final answer's structured part meets (definition.output_schema): a completed run's result.output.
@@ -311,7 +311,7 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
311
311
  graded_at: string;
312
312
  path: "agent" | "workflow" | "handed_back" | "replay";
313
313
  workflow_digest: string | null;
314
- feedback: "revise" | "look_back" | null;
314
+ feedback: "look_back" | null;
315
315
  run_id: string;
316
316
  correct: boolean;
317
317
  };
@@ -58,4 +58,5 @@ export type LoopGuard = {
58
58
  export declare function agentLoopOverStore(store: Store, agentId: string): Promise<{
59
59
  compiles: LoopCompile[];
60
60
  guards: LoopGuard[];
61
+ completed_runs: number;
61
62
  }>;
@@ -5,8 +5,9 @@
5
5
  // how often it handed the run back, and each run's p, with the run's grade when the workflow's own answer was graded.
6
6
  // Aggregates and the checks' own words only: no input, no answer.
7
7
  import { FINAL_STATES } from "../store/store.js";
8
- import { GRADES_KEPT, gradesOf, promotionsOf } from "../learn/promote.js";
9
- import { promotedOf } from "../learn/compile.js";
8
+ import { GRADES_KEPT, gradesOf, promotionOf, promotionsOf } from "../learn/promote.js";
9
+ import { lastOwnRuns, promotedOf } from "../learn/compile.js";
10
+ import { loopOf } from "../learning-setting.js";
10
11
  import { roundsOf } from "./learning.js";
11
12
  /** How many compile turns the read gives, the newest. */
12
13
  export const LOOP_COMPILES_MAX = 50;
@@ -49,6 +50,11 @@ function perStep(rows) {
49
50
  * hand-back's answer was the agent's, and a replay run is never graded. */
50
51
  export async function agentLoopOverStore(store, agentId) {
51
52
  const ended = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId && FINAL_STATES.includes(run.state) && !run.importedFrom && run.archivedAt === null).sort((a, b) => a.startedAt - b.startedAt || (a.id < b.id ? -1 : 1));
53
+ // The completed runs of the agent's own toward its compile (what compileDue counts), at most compile_after: the tab
54
+ // says "N of compile_after" from this, never from the one page of runs it reads.
55
+ const current = (await store.agents.get(agentId))?.currentRevision;
56
+ const body = current ? (await store.agents.revision(current))?.body : undefined;
57
+ const completed_runs = (await lastOwnRuns(store, agentId, loopOf(body?.learning).compile_after)).length;
52
58
  const [grades, promotions] = await Promise.all([gradesOf(store.settings, agentId).catch(() => []), promotionsOf(store.settings, agentId).catch(() => [])]);
53
59
  const graded = new Map(grades.map((grade) => [grade.run, grade.correct]));
54
60
  // The grades kept are the newest GRADES_KEPT (putGrade trims the oldest): once full, a run that ended before the oldest
@@ -97,9 +103,13 @@ export async function agentLoopOverStore(store, agentId) {
97
103
  continue;
98
104
  const attempts = Array.isArray(named?.attempts) ? named.attempts.filter((one) => one && typeof one === "object" && typeof one.ok === "boolean").map((one) => ({ ok: one.ok, errors: texts(one.errors) })) : [];
99
105
  const kept16 = typeof named?.digest === "string" && /^[0-9a-f]{16}$/.test(named.digest) ? named.digest : null;
106
+ // A draft its check had nothing to run on stopped (runner/promotion.ts stopUnchecked): its record's reason is one
107
+ // of the draft's errors, never silent.
108
+ const own = named && kept16 ? promotionOf(promotions, named.workflow, kept16) : undefined;
109
+ const unchecked = own?.decided === "hold" && own.source === "check" && own.check?.stopped && own.check.n === 0 ? [own.reason] : [];
100
110
  compiles.push({
101
111
  createdAt: kept.createdAt, run_id: run.id, round: kept.round, at: new Date(kept.createdAt).toISOString(), workflow: named ? named.workflow : null, from_notes: texts(named?.from_notes), attempts,
102
- digest: kept16, promoted: named && kept16 ? (promotedOf(promotions, named.workflow, kept16) ?? null) : null, draft_errors: errors,
112
+ digest: kept16, promoted: named && kept16 ? (promotedOf(promotions, named.workflow, kept16) ?? null) : null, draft_errors: [...errors, ...unchecked],
103
113
  });
104
114
  }
105
115
  }
@@ -107,5 +117,5 @@ export async function agentLoopOverStore(store, agentId) {
107
117
  // Newest first by when each round kept it (a later round of an earlier run can be newer than a later run's), the run's
108
118
  // start and its round breaking a tie.
109
119
  const newest = compiles.map((one, i) => ({ one, i })).sort((a, b) => b.one.createdAt - a.one.createdAt || b.i - a.i).slice(0, LOOP_COMPILES_MAX);
110
- return { compiles: newest.map(({ one: { createdAt: _createdAt, ...one } }) => one), guards };
120
+ return { compiles: newest.map(({ one: { createdAt: _createdAt, ...one } }) => one), guards, completed_runs };
111
121
  }
@@ -2,6 +2,7 @@ import { type TimelineEvent } from "./timeline/index.js";
2
2
  import { type ItemStatus } from "./learning.js";
3
3
  import { type RunMoment, type SignInReader } from "./run-view.js";
4
4
  import { type Store } from "./store/store.js";
5
+ import type { RecordingView } from "./run-recordings.js";
5
6
  /** What the store-backed view needs beside the store: where its console lives, every secret it never shows (read now, so
6
7
  * one rotated is cut at once), and the agents' saved sign-ins (for the handed-pointer cut). The server passes the same it
7
8
  * passes the file path. */
@@ -19,6 +20,10 @@ export interface ViewDeps {
19
20
  /** Each learned item's status on agent `agentId`'s learning folder's main (learning-routes.ts statusesOf): what a run held
20
21
  * for its owner's OK reads as it stands there. None: as the merge wrote it. */
21
22
  readonly statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
23
+ /** Run `runId`'s screen recordings (run-recordings.ts recordingsOf), the run ended at `endedAt` (null: it has not). Only
24
+ * the reads that answer a run as a whole pass it (a run's own read, its archive): absent, the view has no `recordings`,
25
+ * so a list, a poll or a status read opens no file. */
26
+ readonly recordings?: (agentId: string, runId: string, endedAt: number | null) => Promise<RecordingView[]>;
22
27
  }
23
28
  /** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's, and
24
29
  * never an earlier turn's: a final answer row before the person's last message belongs to the turn that message
@@ -463,6 +463,10 @@ export async function viewOverStore(store, runId, deps) {
463
463
  labels: runRow.labels,
464
464
  // Cut by the run's one cut (the pointers it was handed among them), and none for a withheld run, as its words.
465
465
  learning: unshown ? null : learningViewOf(run.learningEnd, secretsShown(values), settled),
466
+ // Its screen recordings (computer.record), from the files on this machine, where its read asks for them; none for a
467
+ // withheld run, whose files are refused. A run that left running with no end stamped (parked) ends now, each read: only
468
+ // a file's trailer finishes it there.
469
+ ...(deps.recordings ? { recordings: unshown ? [] : await deps.recordings(row.agent, row.id, ended ? (runRow.endedAt ?? Date.now()) : null) } : {}),
466
470
  poll_after_ms: settled ? 0 : 1000,
467
471
  last_progress_at: run.lastProgressAt,
468
472
  };
@@ -122,6 +122,13 @@ export type EvalCase = {
122
122
  /** The case's fake mailbox (eval-mailbox.ts): each run on each of its layouts gets a fake account seeded from it, and is
123
123
  * started by the package's trigger as it would be. Absent: the server's account, if any. */
124
124
  email?: MailboxFixture;
125
+ /** The case's calendar (`calendar:`, an .ics file in the case): served on loopback by a fake calendar server
126
+ * (calendar/ics-faux.ts) and saved as the eval's own server's calendar for the case's runs, read by calendar_events with
127
+ * the case's `now` as its clock. Absent: the server's calendar, if any. */
128
+ calendar?: {
129
+ file: string;
130
+ text: string;
131
+ };
125
132
  /** The case's fake feed (eval-feed.ts): each run gets fake feeds served from it, read in place of the URLs the
126
133
  * package's feed trigger names, and is started by that trigger as it would be. */
127
134
  feed?: FeedFixture;