@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
@@ -25,6 +25,7 @@ import { isMonidName, MCP_SERVER_NAME, MCP_TOOL_NAME, mcpNameOf, mcpToolName, mo
25
25
  import { evalClock, LAYOUTS, mailboxAfter, mailboxFixtureOf, mailboxText, mailboxVerdict, seed, seededFaux, snapshot } from "./eval-mailbox.js";
26
26
  import { caseFeeds, feedFixtureOf } from "./eval-feed.js";
27
27
  import { EMAIL_TOOLS } from "./email/names.js";
28
+ import { CALENDAR_EVENTS } from "./calendar/names.js";
28
29
  import { settingsKeyOf, shellToolOf } from "./tool-gate.js";
29
30
  import { webShownOf } from "./timeline/index.js";
30
31
  import { ASK_TOOL, BOUND_TOOLS } from "./tools.js";
@@ -64,7 +65,7 @@ export const EVAL_HARNESSES = "agentrun-eval-harnesses";
64
65
  export const ON_DATA_WITH_SERVER = "--on-data is the data folder of the eval's own server, and --server names another server: give one of them";
65
66
  const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
66
67
  const PROMPT_FIELDS = ["description", "runs", "max_cost_usd", "input"];
67
- const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning", "now", "email", "feed"];
68
+ const CASE_FIELDS = ["parameters", "grants", "mcp", "web", "monid", "learning", "now", "email", "calendar", "feed"];
68
69
  const GRADER_FIELDS = {
69
70
  llm: ["type", "target"],
70
71
  regex: ["type", "pattern", "flags", "expect", "target"],
@@ -80,7 +81,7 @@ const LOOPBACK = "127.0.0.1"; // key-gate: loopback-rule each fake MCP server li
80
81
  /** A host name on this machine: a case with fake MCP servers needs a server here, which reaches them on loopback. */
81
82
  const LOOPBACK_HOST = /^(?:127\.\d+\.\d+\.\d+|localhost|\[::1\])$/; // key-gate: loopback-rule a server on this machine reaches the fakes
82
83
  /** A case's fields that the eval's own runner alone binds (EvalFakes), each with what it does: a named server refuses them. */
83
- const OWN_SERVER_FAKES = [["web", "web fakes the web tools"], ["now", "now sets its runs' clock"], ["monid", "monid fakes the package's monid endpoints"], ["email", "email fakes the server's email account"], ["feed", "feed fakes the package's feeds"]];
84
+ const OWN_SERVER_FAKES = [["web", "web fakes the web tools"], ["now", "now sets its runs' clock"], ["monid", "monid fakes the package's monid endpoints"], ["email", "email fakes the server's email account"], ["calendar", "calendar fakes the server's calendar"], ["feed", "feed fakes the package's feeds"]];
84
85
  /** A case's run input: its prompt's body as content (none when empty), then its typed fields. */
85
86
  export const runInput = (content, fields) => ({ ...(content ? { content } : {}), ...fields });
86
87
  /** Cases that do not check: every problem, each naming its file. */
@@ -274,7 +275,8 @@ function graderOfType(p, file, text, bad) {
274
275
  * fixture, each learned note as the learning API checks one, and each grader's fields. Nothing runs. PackageError or
275
276
  * CaseError with every problem found. */
276
277
  export function readCases(dir, names) {
277
- const pkg = readPackage(dir);
278
+ // The cases are read below, each fixture checked there in the case's own words (a CaseError), not by the package read.
279
+ const pkg = readPackage(dir, { evalFixtures: false });
278
280
  const problems = [];
279
281
  const missing = (names ?? []).filter((name) => !pkg.evals.includes(name));
280
282
  if (missing.length)
@@ -420,6 +422,22 @@ export function readCases(dir, names) {
420
422
  if (body || fields || f.max_cost_usd !== undefined)
421
423
  bad(`${at}/prompt.md: an email case's run is started by the package's trigger, on the trigger's input and cap: its prompt.md holds description and runs alone`);
422
424
  }
425
+ // The case's calendar: an iCalendar file in the case, served by a fake calendar server as the server's calendar.
426
+ let calendar;
427
+ if (c.calendar !== undefined) {
428
+ const path = inside(root, c.calendar, "file");
429
+ if (!path || !path.endsWith(".ics"))
430
+ bad(`${at}/case.yaml: calendar is an iCalendar file (.ics) in the case (not ${JSON.stringify(c.calendar)})`);
431
+ else {
432
+ const text = readFileSync(join(root, path), "utf8");
433
+ if (!/^\uFEFF?\s*BEGIN:VCALENDAR\b/i.test(text))
434
+ bad(`${at}/${path}: is not an iCalendar file (one that starts BEGIN:VCALENDAR)`);
435
+ else
436
+ calendar = { file: path, text };
437
+ }
438
+ if (!(pkg.tools ?? []).includes(CALENDAR_EVENTS))
439
+ bad(`${at}/case.yaml: calendar fakes the server's calendar, and the package's tools don't name ${CALENDAR_EVENTS}`);
440
+ }
423
441
  // The case's fake feed: its fixture, and the package's feed trigger its runs start from (eval-feed.ts).
424
442
  let feed;
425
443
  if (c.feed !== undefined) {
@@ -498,7 +516,7 @@ export function readCases(dir, names) {
498
516
  cases.push({
499
517
  name, description: typeof f.description === "string" ? f.description : "", runs: typeof f.runs === "number" ? f.runs : 1,
500
518
  ...(typeof f.max_cost_usd === "number" ? { maxCostUsd: f.max_cost_usd } : {}), input: body, ...(fields ? { fields } : {}),
501
- parameters, grants, mcp, ...(web ? { web } : {}), ...(monid ? { monid } : {}), learning, graders, ...(typeof c.now === "string" ? { now: c.now } : {}), ...(email ? { email } : {}), ...(feed ? { feed } : {}),
519
+ parameters, grants, mcp, ...(web ? { web } : {}), ...(monid ? { monid } : {}), learning, graders, ...(typeof c.now === "string" ? { now: c.now } : {}), ...(email ? { email } : {}), ...(calendar ? { calendar } : {}), ...(feed ? { feed } : {}),
502
520
  });
503
521
  }
504
522
  if (problems.length)
@@ -1059,7 +1077,9 @@ export async function evalTemplate(options) {
1059
1077
  // An email case saves its fake mailbox as the server's email account, a secret write, which the API token never
1060
1078
  // makes: the eval owns its own scratch server, so it opens that server's console from its launch link, as the owner
1061
1079
  // who started it would, and makes those writes from that session.
1062
- if (clock && serve.launchCode) {
1080
+ // A calendar case saves its fake calendar as the server's calendar, a secret write too.
1081
+ const calendarCase = cases.some((one) => one.calendar);
1082
+ if ((clock || calendarCase) && serve.launchCode) {
1063
1083
  const origin = new URL(serve.baseUrl).origin;
1064
1084
  const opened = await fetch(`${origin}/?launch=${encodeURIComponent(serve.launchCode)}`, { redirect: "manual" }).catch(() => undefined);
1065
1085
  const cookie = opened?.headers.getSetCookie().map((line) => line.split(";")[0]).join("; ");
@@ -1080,6 +1100,19 @@ export async function evalTemplate(options) {
1080
1100
  : `the server on ${options.data} did not say whether it keeps an email account (GET /settings/email ${kept?.status ?? "failed"}), which an email case's fake mailbox would replace: nothing ran`);
1081
1101
  }
1082
1102
  }
1103
+ // On the owner's folder, a calendar case's fake calendar would replace the calendar its server keeps: refused before
1104
+ // anything runs, the calendar as it was.
1105
+ if (calendarCase && options.data !== undefined) {
1106
+ const kept = await api("GET", "/settings/calendar", undefined, owner).catch(() => undefined);
1107
+ const configured = kept?.status === 200 && isObject(kept.body) && kept.body.configured === true;
1108
+ if (configured || kept?.status !== 200) {
1109
+ await close();
1110
+ removeTree(scratch);
1111
+ throw new Error(configured
1112
+ ? `the server on ${options.data} keeps a calendar${isObject(kept.body) && typeof kept.body.name === "string" ? ` (${kept.body.name})` : ""}, and a calendar case saves its fake calendar as the server's calendar in its place: remove it (DELETE /v2/settings/calendar), run the eval, and save it again; or run the eval without --on-data`
1113
+ : `the server on ${options.data} did not say whether it keeps a calendar (GET /settings/calendar ${kept?.status ?? "failed"}), which a calendar case's fake calendar would replace: nothing ran`);
1114
+ }
1115
+ }
1083
1116
  }
1084
1117
  const results = [];
1085
1118
  let grader;
@@ -1140,6 +1173,7 @@ async function runCase(ctx, one) {
1140
1173
  const saved = [];
1141
1174
  const runs = [];
1142
1175
  const total = options.runs ?? one.runs;
1176
+ let calendarFaux;
1143
1177
  // A server an owner keeps (--server, or the owner's folder with --on-data): its MCP servers are the owner's.
1144
1178
  const owners = Boolean(options.server) || options.data !== undefined;
1145
1179
  try {
@@ -1164,6 +1198,13 @@ async function runCase(ctx, one) {
1164
1198
  if (owners && !(await ownsFake(api, name, fake.url)))
1165
1199
  throw new ApiFailure(`another eval saved its own MCP server named ${name} on this server meanwhile: run one eval of this package at a time on a server`);
1166
1200
  }
1201
+ // A calendar case's fake calendar, on loopback, saved as the server's calendar for all its runs (a read-only fake: no
1202
+ // run changes it).
1203
+ if (one.calendar) {
1204
+ const { startIcsFaux } = await import("./calendar/ics-faux.js");
1205
+ calendarFaux = await startIcsFaux({ text: one.calendar.text });
1206
+ expectOk("saving the case's fake calendar as the server's calendar", await api("PUT", "/settings/calendar", { url: calendarFaux.address }, ctx.owner));
1207
+ }
1167
1208
  // An email case's runs repeat on each of its mailbox's layouts, each run on a fake account of its own.
1168
1209
  const layouts = one.email ? one.email.layouts : [undefined];
1169
1210
  for (const layout of layouts) {
@@ -1199,6 +1240,13 @@ async function runCase(ctx, one) {
1199
1240
  if (removed.status !== 204 && removed.status !== 404)
1200
1241
  ctx.log(`case ${one.name}: the server's email account (the case's fake mailbox) was not removed: DELETE /settings/email ${removed.status} ${JSON.stringify(removed.body).slice(0, 200)}`);
1201
1242
  }
1243
+ // The eval's own server's calendar was the case's fake calendar, gone with it; a removal that fails is said.
1244
+ if (one.calendar) {
1245
+ const removed = await api("DELETE", "/settings/calendar", undefined, ctx.owner).catch((error) => ({ status: 0, body: error.message }));
1246
+ if (removed.status !== 204 && removed.status !== 404)
1247
+ ctx.log(`case ${one.name}: the server's calendar (the case's fake calendar) was not removed: DELETE /settings/calendar ${removed.status} ${JSON.stringify(removed.body).slice(0, 200)}`);
1248
+ await calendarFaux?.close();
1249
+ }
1202
1250
  }
1203
1251
  }
1204
1252
  /** What the stopped server on `data` would do on its own once started, said ("1 enabled trigger, 2 runs not ended"), or
@@ -1253,7 +1301,7 @@ async function feedRun(ctx, one, n, fakes) {
1253
1301
  const urls = Array.isArray(source?.urls) ? source.urls.filter((url) => typeof url === "string") : [];
1254
1302
  if (!urls.length)
1255
1303
  throw new ApiFailure(`the package's trigger ${fixture.trigger} names no feed URL with the case's parameters`);
1256
- const feeds = await caseFeeds(fixture, urls, typeof source?.items === "string" ? source.items : undefined);
1304
+ const feeds = await caseFeeds(fixture, urls, typeof source?.items === "string" ? source.items : undefined, typeof source?.id === "string" ? source.id : undefined);
1257
1305
  ctx.feedRoutes.route = feeds.route;
1258
1306
  try {
1259
1307
  return await runOnce(ctx, one, n, fakes, undefined, feeds);
@@ -217,7 +217,9 @@ export declare function folderFiles(dir: string): PackageFiles;
217
217
  export declare function memoryFiles(name: string, where: string, files: ReadonlyMap<string, Buffer>): PackageFiles;
218
218
  /** Reads the package at `from` (its folder, or its files: PackageFiles) checked whole: a valid package, or PackageError
219
219
  * with every problem found. */
220
- export declare function readPackage(from: string | PackageFiles): Package;
220
+ export declare function readPackage(from: string | PackageFiles, { evalFixtures }?: {
221
+ evalFixtures?: boolean;
222
+ }): Package;
221
223
  /** What is wrong with the trigger bodies an apply makes (compiled's `triggers`), as POST /v2/triggers checks a body, all
222
224
  * but the agent each names (the one the apply makes), as of `now`, each field under `triggers.<i>`. A trigger's input is
223
225
  * its runs' input, and a package's agent is agentic, so each input is checked against the package's input schema in
package/dist/templates.js CHANGED
@@ -27,6 +27,7 @@ import { MOVE_FIELD } from "./trigger-composio.js";
27
27
  import { triggerBodyIssues } from "./triggers.js";
28
28
  import { definitionBodyIssues, inputIssues, inputSchemaOf, isObject, MODEL_REF, MODEL_TIER_NAMES, unknownFields } from "./validate.js";
29
29
  import { schemaCheck } from "./answer-json.js";
30
+ import { webFixtureOf } from "./web-fake.js";
30
31
  import { APPROVALS } from "./approvals.js";
31
32
  export const TEMPLATES_DIR = fileURLToPath(new URL("../templates/", import.meta.url));
32
33
  export const MANIFEST = "agent.md";
@@ -486,7 +487,7 @@ function fieldsSchema(value, of, bad) {
486
487
  }
487
488
  /** Reads the package at `from` (its folder, or its files: PackageFiles) checked whole: a valid package, or PackageError
488
489
  * with every problem found. */
489
- export function readPackage(from) {
490
+ export function readPackage(from, { evalFixtures = true } = {}) {
490
491
  const src = typeof from === "string" ? folderFiles(from) : from;
491
492
  const dir = src.where;
492
493
  const problems = [];
@@ -873,6 +874,18 @@ export function readPackage(from) {
873
874
  bad(at, "has no prompt.md");
874
875
  else if (!triggeredCase && !front(`${at}/prompt.md`, false)?.body.trim())
875
876
  bad(`${at}/prompt.md`, "its body is empty: the body is the run's input");
877
+ // A case's web fixture is checked as eval-template checks it, in the same words (web-fake.ts).
878
+ if (evalFixtures && caseJs !== undefined && typeof caseJs.web === "string" && caseJs.web !== "unavailable" && own.includes(caseJs.web) && caseJs.web.startsWith("fixtures/")) {
879
+ let parsed;
880
+ try {
881
+ parsed = JSON.parse(text(`${at}/${caseJs.web}`));
882
+ }
883
+ catch (error) {
884
+ bad(`${at}/${caseJs.web}`, `is not JSON (${error.message})`);
885
+ }
886
+ if (parsed !== undefined)
887
+ webFixtureOf(parsed, `${at}/${caseJs.web}`, (message) => void problems.push(message));
888
+ }
876
889
  const graders = own.filter((p) => p.startsWith("graders/"));
877
890
  if (!graders.length)
878
891
  bad(at, "has no graders/*.md");
@@ -8,7 +8,8 @@
8
8
  /** Apps whose id says little of the name a person knows them by. Any other id's last part is its name, capitalized. */
9
9
  const APP_NAMES = {
10
10
  "com.apple.systempreferences": "System Settings", "com.apple.iCal": "Calendar", "com.apple.finder": "Finder",
11
- "com.android.settings": "Settings", "com.android.chrome": "Chrome", "xfce4-terminal": "Terminal", "org.xfce.terminal": "Terminal", xterm: "XTerm",
11
+ "com.android.settings": "Settings", "com.android.chrome": "Chrome", "com.android.deskclock": "Clock", "com.android.contacts": "Contacts",
12
+ "com.android.documentsui": "Files", "org.wikipedia": "Wikipedia", "xfce4-terminal": "Terminal", "org.xfce.terminal": "Terminal", xterm: "XTerm",
12
13
  "firefox-esr": "Firefox", "google-chrome": "Chrome",
13
14
  };
14
15
  /** An app's id as a person names it: "com.apple.TextEdit" is TextEdit, "org.xfce.mousepad" Mousepad. */
package/dist/tool-list.js CHANGED
@@ -11,6 +11,7 @@ export const TOOL_LIST = Object.freeze({
11
11
  email_draft: { table: true, askable: true, replay: "never", host: true, blurb: "Save an email draft" },
12
12
  email_send: { table: true, askable: true, replay: "never", host: true, asks: true, blurb: "Send an email" },
13
13
  email_file: { table: true, askable: true, replay: "never", host: true, blurb: "File an email under a folder or label" },
14
+ calendar_events: { table: true, askable: true, replay: "safe", host: true, blurb: "Read the calendar's events" },
14
15
  browser: { table: true, blurb: "Browse websites in a hosted browser" },
15
16
  subagent: { table: true, blurb: "Run a task in a fresh helper conversation" },
16
17
  pdf_pages: { table: true, blurb: "Turn a PDF's pages into images" },
package/dist/tools.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import "./email/labels.js";
2
+ import "./calendar/labels.js";
2
3
  import type { TSchema } from "typebox";
3
4
  import { type Extension, type Harness, type ToolRegistration, type Tx } from "@earendil-works/pi-durable";
4
5
  import type { Revision } from "./agent-rows.js";
@@ -130,6 +131,12 @@ export type ToolHost = {
130
131
  /** A template eval case's fake mail account (eval-mailbox.ts), the only account the run's email tools open: one saved
131
132
  * elsewhere is refused. Only the eval's own runner sets it (runner/beside.ts evalFakes). */
132
133
  emailFake?: EmailFake;
134
+ /** The server is a local install (its operator's mcpLoopback, runner/beside.ts): calendar_events may read a calendar on
135
+ * loopback, as a template eval's fake calendar is. Absent: never. */
136
+ calendarLoopback?: boolean;
137
+ /** That server's own addresses (Serve.own, AdapterSpecDeps.mcpOwn): calendar_events never reads on loopback at their
138
+ * ports, a redirect's hop included, as the server's own read (calendar/routes.ts) never does. */
139
+ serverOwn?: readonly string[];
133
140
  };
134
141
  /** A fake mail account's servers, on loopback (email/email-faux.ts), and the kind of server it plays: what email_file's
135
142
  * description says, which a loopback account saved as `other` would otherwise read as folders. */
package/dist/tools.js CHANGED
@@ -8,6 +8,9 @@ import { blurbOf, isHostTool } from "./tool-list.js";
8
8
  import { EMAIL_DESCRIPTIONS, EMAIL_DRAFT, EMAIL_FILE, EMAIL_READ, EMAIL_SEARCH, EMAIL_SEND, fileSummary, sendSummary } from "./email/names.js";
9
9
  // The email tools' timeline lines (registerLabel), registered as this module loads.
10
10
  import "./email/labels.js";
11
+ import { CALENDAR_EVENTS, CALENDAR_SUMMARY } from "./calendar/names.js";
12
+ // calendar_events' timeline line (registerLabel), registered as this module loads.
13
+ import "./calendar/labels.js";
11
14
  import { mcpNameOf } from "./tool-names.js";
12
15
  import { appendFileSync } from "node:fs";
13
16
  import { pathToFileURL } from "node:url";
@@ -604,6 +607,14 @@ export const TOOLS = Object.freeze({
604
607
  [EMAIL_DRAFT]: emailTool(EMAIL_DRAFT),
605
608
  [EMAIL_SEND]: emailTool(EMAIL_SEND),
606
609
  [EMAIL_FILE]: emailTool(EMAIL_FILE),
610
+ // The server's calendar (calendar/tools.ts, saved with PUT /v2/settings/calendar), every harness's as web_fetch is; ical.js loads at the
611
+ // first bind.
612
+ [CALENDAR_EVENTS]: {
613
+ summary: CALENDAR_SUMMARY,
614
+ needs: [],
615
+ nodes: false,
616
+ bind: async (host) => (await import("./calendar/tools.js")).bindCalendar(host),
617
+ },
607
618
  browser: browserTool,
608
619
  // A pi run's subagent (runner/subagent.ts): a native tool of the run's root agent, bound by the runner's pi spec
609
620
  // (adapter-run-spec.ts), never by this table; not a host tool (tool-list.ts `replay`), so another harness refuses it.
@@ -1,3 +1,4 @@
1
+ import { pointed } from "./feed/pointer.js";
1
2
  import { ACCEPT_SCHEMA, acceptOf, acceptRefusal } from "./trigger-accept.js";
2
3
  import { closedSchema, PAYLOAD_KEPT_BYTES, unknownSourceFields } from "./trigger-adapter.js";
3
4
  import { MAX_EVERY_S, MIN_EVERY_S } from "./trigger-schedule.js";
@@ -22,6 +23,8 @@ const LAST_CHECK = "last_check";
22
23
  const URL_CHARS = 2000;
23
24
  const POINTER = /^(\/([^~]|~[01])*)?$/;
24
25
  const POINTER_CHARS = 300;
26
+ /** The most fields a JSON list's `fields` keeps of each item. */
27
+ const MAX_FIELDS = 50;
25
28
  /** The source's own fields, checked: each issue through `bad`. Undefined when one does not read. */
26
29
  function fieldsOf(value, bad) {
27
30
  let failed = false;
@@ -47,15 +50,22 @@ function fieldsOf(value, bad) {
47
50
  const every = value.every_s ?? DEFAULT_EVERY_S;
48
51
  if (!Number.isSafeInteger(every) || every < MIN_EVERY_S || every > MAX_EVERY_S)
49
52
  fail("every_s", "invalid", `every_s is a whole number of seconds, ${MIN_EVERY_S} to ${MAX_EVERY_S}`);
50
- for (const name of ["items", "id"]) {
53
+ for (const name of ["items", "id", "updated"]) {
51
54
  const pointer = value[name];
52
55
  if (pointer === undefined)
53
56
  continue;
54
57
  const whole = name === "items";
55
58
  if (typeof pointer !== "string" || pointer.length > POINTER_CHARS || !POINTER.test(pointer) || (!whole && !pointer)) {
56
- fail(name, "invalid", whole ? `items is a JSON Pointer to a JSON list's array of items ("" for the whole document, /data/items): for a feed that is a JSON list` : `id is a JSON Pointer into a JSON list's item to its id (/id, /number): for a feed that is a JSON list`);
59
+ if (name === "updated")
60
+ fail(name, "invalid", "updated is a JSON Pointer into a JSON list's item to the date it last changed (/updated_at): for a feed that is a JSON list");
61
+ else
62
+ fail(name, "invalid", whole ? `items is a JSON Pointer to a JSON list's array of items ("" for the whole document, /data/items): for a feed that is a JSON list` : `id is a JSON Pointer into a JSON list's item to its id (/id, /number): for a feed that is a JSON list`);
57
63
  }
58
64
  }
65
+ const fields = value.fields;
66
+ if (fields !== undefined && (!Array.isArray(fields) || fields.length < 1 || fields.length > MAX_FIELDS || fields.some((one) => typeof one !== "string" || !one || one.length > POINTER_CHARS || !POINTER.test(one)))) {
67
+ fail("fields", "invalid", `fields is a list of 1 to ${MAX_FIELDS} JSON Pointers into a JSON list's item (/number, /user/login): the payload's item keeps only these, for a feed that is a JSON list`);
68
+ }
59
69
  const accept = value.accept === undefined ? undefined : acceptOf(value.accept, fail);
60
70
  accept?.forEach((rule, i) => {
61
71
  if (rule.event !== EVENT)
@@ -65,7 +75,7 @@ function fieldsOf(value, bad) {
65
75
  });
66
76
  if (failed)
67
77
  return undefined;
68
- return { kind: "feed", urls: urls, every_s: every, ...(value.items !== undefined ? { items: value.items } : {}), ...(value.id !== undefined ? { id: value.id } : {}), ...(accept ? { accept } : {}) };
78
+ return { kind: "feed", urls: urls, every_s: every, ...(value.items !== undefined ? { items: value.items } : {}), ...(value.id !== undefined ? { id: value.id } : {}), ...(value.updated !== undefined ? { updated: value.updated } : {}), ...(value.fields !== undefined ? { fields: value.fields } : {}), ...(accept ? { accept } : {}) };
69
79
  }
70
80
  /** Why `url` is no feed URL a trigger reads, or undefined: an http(s) URL, with no user or password in it. */
71
81
  export function urlProblem(url) {
@@ -106,7 +116,7 @@ async function readOne(url, state, source, reach) {
106
116
  if (!("body" in read))
107
117
  return { url, ok: false, status: read.status, problem: `Couldn't read ${url}: HTTP ${read.status}.` };
108
118
  try {
109
- const feed = parseFeed(read.body, { ...(source.items !== undefined ? { items: source.items } : {}), ...(source.id !== undefined ? { id: source.id } : {}) });
119
+ const feed = parseFeed(read.body, { ...(source.items !== undefined ? { items: source.items } : {}), ...(source.id !== undefined ? { id: source.id } : {}), ...(source.updated !== undefined ? { updated: source.updated } : {}) });
110
120
  return { url, ok: true, changed: true, feed, validators: { ...(read.etag ? { etag: read.etag } : {}), ...(read.modified ? { modified: read.modified } : {}) } };
111
121
  }
112
122
  catch (error) {
@@ -133,6 +143,9 @@ async function pooled(items, n, work) {
133
143
  }));
134
144
  return out;
135
145
  }
146
+ /** `state`'s seen set as a map, a missing date null. A set saved before dates were told apart (no \`dates\`) holds 0 for one:
147
+ * read as missing for a JSON list, whose items had no dates then; an RSS, Atom or JSON Feed item's 0 stays a number. */
148
+ const seenOf = (state, list) => new Map((state.seen ?? []).map(([key, at]) => [key, at === 0 && list && state.dates !== 2 ? null : at]));
136
149
  /** One feed's items, oldest first: as it serves them reversed (a feed lists newest first), then by date when every one
137
150
  * has one. Each key once (its first, the newest). */
138
151
  function oldestFirst(items) {
@@ -147,14 +160,16 @@ function oldestFirst(items) {
147
160
  /** The payload an item fires with, within PAYLOAD_KEPT_BYTES: a JSON list's {id, link, title, item, update}, its raw item
148
161
  * cut shallower until it fits; any other's {id, link, title, published, updated, author, summary, categories, feed,
149
162
  * update}, its summary cut until it fits. */
150
- function payloadOf(c, list, title) {
163
+ function payloadOf(c, list, title, fields) {
151
164
  const { item, update } = c;
152
165
  if (list) {
153
- const whole = { id: item.id, link: item.link, title: item.title, item: item.raw, update };
166
+ // `fields`, when the source names some, keep only those of the item, before the cap.
167
+ const raw = fields ? keeping(item.raw, fields) : item.raw;
168
+ const whole = { id: item.id, link: item.link, title: item.title, item: raw, update };
154
169
  if (fits(whole))
155
170
  return whole;
156
171
  for (const [depth, chars] of [[3, 2000], [3, 300], [2, 2000], [2, 300], [1, 300], [1, 100]]) {
157
- const cut = { ...whole, item: shallow(item.raw, depth, chars), item_truncated: true };
172
+ const cut = { ...whole, item: shallow(raw, depth, chars), item_truncated: true };
158
173
  if (fits(cut))
159
174
  return cut;
160
175
  }
@@ -170,6 +185,35 @@ function payloadOf(c, list, title) {
170
185
  }
171
186
  return { id: clipped(item.id, 200), link: clipped(item.link, 200), title: clipped(item.title, 200), published: iso(item.published), updated: iso(item.updated), author: null, summary: null, categories: [], feed: { title: null, url: c.url }, update };
172
187
  }
188
+ /** `raw` with only the values at `pointers` kept, each at its own place (a list's kept entries compacted). Every
189
+ * container is built bare and every key set as an own property, so no name (\`__proto__\` too) reaches a prototype; only
190
+ * own keys of the item are read. */
191
+ function keeping(raw, pointers) {
192
+ const bare = (like) => (Array.isArray(like) ? [] : Object.create(null));
193
+ const own = (from, key) => (from !== null && typeof from === "object" && Object.hasOwn(from, key) ? from[key] : undefined);
194
+ const out = bare(raw);
195
+ for (const pointer of pointers) {
196
+ const value = pointed(raw, pointer);
197
+ if (value === undefined)
198
+ continue;
199
+ const keys = pointer.split("/").slice(1).map((part) => part.replace(/~1/g, "/").replace(/~0/g, "~"));
200
+ let from = raw;
201
+ let into = out;
202
+ keys.forEach((key, i) => {
203
+ const source = own(from, key);
204
+ if (i === keys.length - 1)
205
+ Object.defineProperty(into, key, { value, enumerable: true, writable: true, configurable: true });
206
+ else {
207
+ if (!Object.hasOwn(into, key))
208
+ Object.defineProperty(into, key, { value: bare(source), enumerable: true, writable: true, configurable: true });
209
+ into = into[key];
210
+ }
211
+ from = source;
212
+ });
213
+ }
214
+ const dense = (value) => (Array.isArray(value) ? value.filter(() => true).map(dense) : value !== null && typeof value === "object" ? Object.fromEntries(Object.entries(value).map(([k, v]) => [k, dense(v)])) : value);
215
+ return dense(out);
216
+ }
173
217
  const fits = (value) => Buffer.byteLength(JSON.stringify(value), "utf8") <= PAYLOAD_KEPT_BYTES;
174
218
  const clipped = (text, n) => (text !== null && text.length > n ? `${text.slice(0, n - 1)}…` : text);
175
219
  /** `value` with its objects and lists `depth` deep (deeper ones dropped), a list's first 20, its strings `chars` long. */
@@ -221,18 +265,19 @@ async function poll(source, reach, cursor) {
221
265
  lists.set(read.url, feed.list);
222
266
  if (!state.seen) {
223
267
  // Its start: every item there now is seen, and starts nothing.
224
- state.seen = items.map((item) => [hashed(item.key), item.updated ?? 0]);
268
+ state.seen = items.map((item) => [hashed(item.key), item.updated]);
269
+ state.dates = 2;
225
270
  started.push({ url: read.url, count: items.length });
226
271
  continue;
227
272
  }
228
273
  present.set(read.url, items);
229
- const seen = new Map(state.seen);
274
+ const seen = seenOf(state, feed.list);
230
275
  const fresh = [];
231
276
  for (const item of items) {
232
277
  const was = seen.get(hashed(item.key));
233
278
  if (was === undefined)
234
279
  fresh.push({ url: read.url, item, update: false, at: item.updated ?? item.published, n: 0 });
235
- else if (item.updated !== null && item.updated > was)
280
+ else if (item.updated !== null && (was === null ? !feed.list : item.updated > was))
236
281
  fresh.push({ url: read.url, item, update: true, at: item.updated, n: 0 });
237
282
  }
238
283
  candidates.push(fresh);
@@ -273,27 +318,29 @@ async function poll(source, reach, cursor) {
273
318
  feeds[url] = state;
274
319
  continue;
275
320
  }
276
- const seen = new Map(state.seen);
321
+ const list = lists.get(url) ?? false;
322
+ const seen = seenOf(state, list);
277
323
  for (const item of items) {
278
324
  const key = hashed(item.key);
279
325
  const was = seen.get(key);
280
326
  const mark = marks.get(`${url}\n${item.key}`);
281
327
  seen.delete(key);
282
328
  if (mark && mark.n < upTo)
283
- seen.set(key, item.updated ?? 0);
329
+ seen.set(key, item.updated);
330
+ // A JSON list's item first seen with no date takes the one it gains, fired on never.
284
331
  else if (was !== undefined)
285
- seen.set(key, was);
332
+ seen.set(key, was === null && list ? item.updated : was);
286
333
  }
287
334
  const whole = !left.has(url) && !taken.slice(upTo).some((c) => c.url === url);
288
335
  const { etag, modified, ...rest } = state;
289
- feeds[url] = { ...rest, ...(whole && etag ? { etag } : {}), ...(whole && modified ? { modified } : {}), seen: [...seen.entries()].slice(-Math.max(SEEN_KEPT, 2 * items.length)) };
336
+ feeds[url] = { ...rest, dates: 2, ...(whole && etag ? { etag } : {}), ...(whole && modified ? { modified } : {}), seen: [...seen.entries()].slice(-Math.max(SEEN_KEPT, 2 * items.length)) };
290
337
  }
291
338
  return { [CURSOR]: JSON.stringify({ feeds }) };
292
339
  };
293
340
  const name = (url) => states[url]?.title ?? url;
294
341
  const named = (urls) => (urls.length === 1 ? name(urls[0]) : `${urls.length} feeds`);
295
342
  const events = taken.map((c) => {
296
- const body = payloadOf(c, lists.get(c.url) ?? false, states[c.url]?.title ?? null);
343
+ const body = payloadOf(c, lists.get(c.url) ?? false, states[c.url]?.title ?? null, source.fields);
297
344
  const key = `${c.url}\n${c.item.key}${c.item.updated !== null ? `\n${iso(c.item.updated)}` : ""}`;
298
345
  // Its cursor made only when the engine asks for it (the last event it records, when the poll is cut short): never one
299
346
  // whole cursor per item taken.
@@ -331,7 +378,7 @@ export const feed = {
331
378
  // Each item is its own: one run's answer is never handed to the next.
332
379
  previousResult: false,
333
380
  settings: { scope: "trigger", fields: { [CURSOR]: { public: true }, [LAST_CHECK]: { public: true } } },
334
- describe: `{kind: "feed", urls: ["https://..."], every_s?: ${DEFAULT_EVERY_S}, items?: "/data/items", id?: "/id", accept?: [{event: "${EVENT}", where?}]}`,
381
+ describe: `{kind: "feed", urls: ["https://..."], every_s?: ${DEFAULT_EVERY_S}, items?: "/data/items", id?: "/id", updated?: "/updated_at", fields?: ["/number", "/title"], accept?: [{event: "${EVENT}", where?}]}`,
335
382
  fires: "each new or updated item in its feeds (`feed`: RSS, Atom, JSON Feed or a JSON list), read every every_s seconds, that its `accept` takes",
336
383
  firedBy: "`feed`: an item new to one of its feeds, or one seen before with a later updated time, its key from the trigger, the feed's URL, the item's key and its updated time.",
337
384
  schemas: [
@@ -339,14 +386,16 @@ export const feed = {
339
386
  every_s: { type: "integer", minimum: MIN_EVERY_S, maximum: MAX_EVERY_S, default: DEFAULT_EVERY_S, description: "How often it reads its feeds, in seconds, on a grid from the epoch." },
340
387
  items: { type: "string", maxLength: POINTER_CHARS, pattern: "^(/([^~]|~[01])*)?$", description: "For a JSON list: a JSON Pointer to its array of items. Absent: the whole document." },
341
388
  id: { type: "string", minLength: 1, maxLength: POINTER_CHARS, pattern: "^/([^~]|~[01])*$", description: "For a JSON list: a JSON Pointer into each item to its id. Absent: /id." },
389
+ updated: { type: "string", minLength: 1, maxLength: POINTER_CHARS, pattern: "^/([^~]|~[01])*$", description: "For a JSON list: a JSON Pointer into each item to the date it last changed (/updated_at). An item whose date moves on fires again with update: true. Absent: a JSON list's item fires once." },
390
+ fields: { type: "array", minItems: 1, maxItems: MAX_FIELDS, items: { type: "string", minLength: 1, maxLength: POINTER_CHARS, pattern: "^/([^~]|~[01])*$" }, description: "For a JSON list: JSON Pointers into each item; the payload's item keeps only these, each at its own place, before the payload's size cap (a pull request that is large whole fits). Absent: the whole item, cut shallower when it is over the cap." },
342
391
  accept: { ...ACCEPT_SCHEMA, description: `The items that start a run: each rule's event is "${EVENT}", its where reads the payload (/title, /link, /feed/url; a JSON list's /item/...). None: every item.` },
343
392
  }),
344
393
  ],
345
394
  sent: [
346
- closedSchema({ kind: { const: "feed" }, urls: { type: "array", minItems: 1, maxItems: MAX_FEEDS, items: { type: "string" } }, every_s: { type: "integer", minimum: MIN_EVERY_S, maximum: MAX_EVERY_S } }, { items: { type: "string" }, id: { type: "string" }, accept: ACCEPT_SCHEMA }),
395
+ closedSchema({ kind: { const: "feed" }, urls: { type: "array", minItems: 1, maxItems: MAX_FEEDS, items: { type: "string" } }, every_s: { type: "integer", minimum: MIN_EVERY_S, maximum: MAX_EVERY_S } }, { items: { type: "string" }, id: { type: "string" }, updated: { type: "string" }, fields: { type: "array", items: { type: "string" } }, accept: ACCEPT_SCHEMA }),
347
396
  ],
348
397
  parse(value, _now, bad, issues) {
349
- issues.push(...unknownSourceFields(value, ["kind", "urls", "every_s", "items", "id", "accept"]));
398
+ issues.push(...unknownSourceFields(value, ["kind", "urls", "every_s", "items", "id", "updated", "fields", "accept"]));
350
399
  return fieldsOf(value, bad);
351
400
  },
352
401
  wellFormed: (source) => fieldsOf(source, () => { }) !== undefined,
package/dist/validate.js CHANGED
@@ -8,6 +8,7 @@ import { computerIssues, settingConflict } from "./computer-setting.js";
8
8
  import { settingsIssues } from "./tool-plane.js";
9
9
  import { APPROVALS } from "./approvals.js";
10
10
  import { schemaCheck } from "./answer-json.js";
11
+ import { learningSettingIssue } from "./learning-setting.js";
11
12
  export const ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
12
13
  /** An inline agent's source or kind in its external reference (POST /runs): no colon, which the reference's key splits on. */
13
14
  export const EXTERNAL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
@@ -119,8 +120,12 @@ export function definitionIssues(definition, { at = "definition", creating = tru
119
120
  if (d.learning !== undefined) {
120
121
  if (d.workflow !== undefined)
121
122
  out.push(issue(`${at}.learning`, "not_allowed", "A workflow revision does not learn: only an agentic run reflects on its work.", `Remove ${at}.learning.`));
122
- else if (typeof d.learning !== "boolean" && d.learning !== "notes")
123
- out.push(issue(`${at}.learning`, "wrong_type", `${at}.learning is true, false or "notes": true learns notes, skills and workflows, "notes" notes and skills alone`));
123
+ else {
124
+ // true learns notes, skills and workflows, "notes" notes and skills alone; an object is on, with the loop's numbers.
125
+ const wrong = learningSettingIssue(d.learning, `${at}.learning`);
126
+ if (wrong)
127
+ out.push(issue(`${at}.learning`, "wrong_type", wrong));
128
+ }
124
129
  }
125
130
  // An agentic revision's structured answer: the JSON Schema its final answer's last fenced json block meets, read into a
126
131
  // completed run's result.output (answer-json.ts structuredAnswer). A workflow's output is its workflow's own.
@@ -1,4 +1,5 @@
1
1
  import type { ComputerProvider, ComputerSpec, HelloResult, Result, ScreenWatch, ScreenWatchHandlers, WatchOptions } from "@parcha/agentrun-computer";
2
+ import { type RecordInput } from "../computer-record.js";
2
3
  import { type PlaceView } from "../computer-setting.js";
3
4
  import { type KeyTable, type ProviderSettings } from "../computer-keys.js";
4
5
  import type { Store } from "../store/index.js";
@@ -114,6 +115,12 @@ export interface ComputerForClaimDeps {
114
115
  readonly revokeMount?: () => Promise<void>;
115
116
  /** The live view's registration for a desktop or a phone (proxy-only). Absent: no view is opened. */
116
117
  readonly openComputerView?: OpenComputerView;
118
+ /** Where the agent's setting asks for a video of its desktop's or phone's screen (computer.record): the run's
119
+ * recordings folder on this machine (paths.ts recordingsFolder) and where its lines on the run's timeline go
120
+ * (computer-record.ts startRecording; for tests, the program in ffmpeg's place and the bounds). The computer this claim
121
+ * attaches is recorded through a watch of its own, with or without a viewer, until its release, the run's end or its
122
+ * park. Absent: nothing is recorded. */
123
+ readonly recordings?: Pick<RecordInput, "folder" | "say" | "ffmpeg" | "limits">;
117
124
  /** Told once, before the claim waits on its computer's image (a provider that makes its own: Docker's recipe built on
118
125
  * a host that lacks it, or a named image pulled); never when the host has it. The run's caller says it on the run's
119
126
  * timeline. Absent: nothing is said. */
@@ -3,7 +3,8 @@
3
3
  // for this run under this claim (labels agentrun.run and agentrun.epoch, the run's folder mounted only where the provider
4
4
  // mounts it), with a hold and its live view when it is a desktop or a phone, and released once at the run's end. The hold
5
5
  // goes back to the spec (`held`), whose adapter loop journals it and applies the owner's take-over and hand-back rows to it
6
- // (runner/computer-journal.ts); the live view (computer-live.ts openClaimView) drives the same hold. A computer that cannot
6
+ // (runner/computer-journal.ts); the live view (computer-live.ts openClaimView) drives the same hold. Where the setting
7
+ // asks for it (computer.record), the screen is recorded too (computer-record.ts), until the release or a park. A computer that cannot
7
8
  // be had is refused in words with code computer_unavailable; kind none, or no setting where the server's default is none,
8
9
  // is no computer.
9
10
  //
@@ -31,6 +32,7 @@
31
32
  // deleted, at the run's end. A run that finds it held by another run still going is refused, naming that run.
32
33
  import { randomUUID } from "node:crypto";
33
34
  import { isBrowserProvider, ownerFilter, releaseOlder, RUN_LABEL, runLabels } from "@parcha/agentrun-computer";
35
+ import { startRecording } from "../computer-record.js";
34
36
  import { computerOfPlace } from "../computer-setting.js";
35
37
  import { KEY_TABLE, providerOptions } from "../computer-keys.js";
36
38
  import { getSealedKey } from "../server-keys.js";
@@ -558,7 +560,8 @@ store, deps) {
558
560
  return launched;
559
561
  },
560
562
  };
561
- const resolved = await resolveComputer(await settingOf(launch, store), deps.mode, kinds, side);
563
+ const setting = await settingOf(launch, store);
564
+ const resolved = await resolveComputer(setting, deps.mode, kinds, side);
562
565
  if ("refused" in resolved)
563
566
  throw unavailable(resolved.refused);
564
567
  if (resolved.kind === "none")
@@ -589,6 +592,7 @@ store, deps) {
589
592
  let hold;
590
593
  let held;
591
594
  let view;
595
+ let recording;
592
596
  if (computer && (computer.kind === "desktop" || computer.kind === "phone")) {
593
597
  const theHold = computerHold();
594
598
  if (deps.openComputerView && made?.watch) {
@@ -604,6 +608,9 @@ store, deps) {
604
608
  }
605
609
  view = opened.view;
606
610
  }
611
+ // The agent asks for a video of the screen (computer.record): a watch of the recorder's own, while this claim holds it.
612
+ if (deps.recordings && made?.watch && setting?.record === true)
613
+ recording = startRecording({ ...deps.recordings, watch: made.watch, tag: made.id, kind: computer.kind });
607
614
  // The run's end closes the hold (workspace/computer-hold.ts close()): a take in force ends `released` (the computer
608
615
  // goes; the composer's `ended` ViewEnd maps onto it), the agent's open ask is let go at once, and nothing is taken after.
609
616
  endHold = () => theHold.close();
@@ -612,6 +619,7 @@ store, deps) {
612
619
  }
613
620
  let released;
614
621
  const release = (why = "released") => (released ??= (async () => {
622
+ await recording?.stop(typeof why === "object" ? "parked" : why);
615
623
  await Promise.resolve(view?.close(why)).catch(() => undefined);
616
624
  endHold();
617
625
  try {
@@ -651,6 +659,8 @@ store, deps) {
651
659
  // The live view ends (its frames and any take-over), saying what the run waits for and until when the computer is
652
660
  // kept, never that it ended; the hold with it; the machine and its mount stay.
653
661
  released = (async () => {
662
+ // The recording pauses: the claim that resumes the run goes on in a new file.
663
+ await recording?.stop("parked");
654
664
  await Promise.resolve(view?.close({ parked: cause, until: row.until })).catch(() => undefined);
655
665
  endHold();
656
666
  await keeps.computer.close();
@@ -10,6 +10,10 @@ export declare const runKey: (agentId: string, runId: string) => string;
10
10
  export declare const learningKey: (agentId: string) => string;
11
11
  /** Run `runId`'s folder, the root of its Workspace: `<data>/disk/agents/<agent>/runs/<run>/work`. */
12
12
  export declare const runFolder: (dataDir: string, agentId: string, runId: string) => string;
13
+ /** The recordings folder's name: beside a run's folder on this machine, and the run files route's path to it. */
14
+ export declare const RECORDINGS = "recordings";
15
+ /** Run `runId`'s recordings on this machine, beside its folder: `<data>/disk/agents/<agent>/runs/<run>/recordings`. */
16
+ export declare const recordingsFolder: (dataDir: string, agentId: string, runId: string) => string;
13
17
  /** Agent `agentId`'s learning folder, the root of its learning Workspace: `<data>/disk/agents/<agent>/learning`. */
14
18
  export declare const agentLearningFolder: (dataDir: string, agentId: string) => string;
15
19
  /** Agent `agentId`'s home as a key from a disk's root: `agents/<agent>/home`. */
@@ -11,6 +11,11 @@
11
11
  // no Workspace: a harness's working directory, and its private files
12
12
  // in harness/<claim's epoch>, swept at that claim's end
13
13
  // (runner/cli-run-spec.ts)
14
+ // <data>/disk/agents/<agent>/runs/<run>/recordings
15
+ // a run's screen recordings (recordingsFolder): beside work/, never in
16
+ // its Workspace, so the agent neither reads nor changes them; on this
17
+ // machine in either mode, as the runner records them
18
+ // (computer-record.ts)
14
19
  // <agent> is the id in lower case, a dash, and 16 hex digits of the id's SHA-256, so ids that differ only in case never
15
20
  // share a folder on a disk that folds case.
16
21
  //
@@ -40,6 +45,10 @@ export const runKey = (agentId, runId) => `agents/${agentDirName(agentId)}/runs/
40
45
  export const learningKey = (agentId) => `agents/${agentDirName(agentId)}/learning`;
41
46
  /** Run `runId`'s folder, the root of its Workspace: `<data>/disk/agents/<agent>/runs/<run>/work`. */
42
47
  export const runFolder = (dataDir, agentId, runId) => join(dataDir, DISK_DIR, runKey(agentId, runId));
48
+ /** The recordings folder's name: beside a run's folder on this machine, and the run files route's path to it. */
49
+ export const RECORDINGS = "recordings";
50
+ /** Run `runId`'s recordings on this machine, beside its folder: `<data>/disk/agents/<agent>/runs/<run>/recordings`. */
51
+ export const recordingsFolder = (dataDir, agentId, runId) => join(dirname(runFolder(dataDir, agentId, runId)), RECORDINGS);
43
52
  /** Agent `agentId`'s learning folder, the root of its learning Workspace: `<data>/disk/agents/<agent>/learning`. */
44
53
  export const agentLearningFolder = (dataDir, agentId) => join(dataDir, DISK_DIR, learningKey(agentId));
45
54
  /** Agent `agentId`'s home as a key from a disk's root: `agents/<agent>/home`. */