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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/NOTICE +2 -0
  3. package/README.md +85 -19
  4. package/dist/agent-rows.d.ts +1 -1
  5. package/dist/agents-store.js +3 -1
  6. package/dist/calendar/address.d.ts +49 -0
  7. package/dist/calendar/address.js +153 -0
  8. package/dist/calendar/fetch.d.ts +24 -0
  9. package/dist/calendar/fetch.js +146 -0
  10. package/dist/calendar/ics-faux.d.ts +39 -0
  11. package/dist/calendar/ics-faux.js +236 -0
  12. package/dist/calendar/labels.d.ts +3 -0
  13. package/dist/calendar/labels.js +61 -0
  14. package/dist/calendar/names.d.ts +52 -0
  15. package/dist/calendar/names.js +54 -0
  16. package/dist/calendar/parse.d.ts +108 -0
  17. package/dist/calendar/parse.js +625 -0
  18. package/dist/calendar/routes.d.ts +17 -0
  19. package/dist/calendar/routes.js +81 -0
  20. package/dist/calendar/tools.d.ts +23 -0
  21. package/dist/calendar/tools.js +124 -0
  22. package/dist/cli.js +3 -1
  23. package/dist/computer-record.d.ts +55 -0
  24. package/dist/computer-record.js +315 -0
  25. package/dist/computer-setting.d.ts +1 -0
  26. package/dist/computer-setting.js +15 -2
  27. package/dist/computers.js +2 -14
  28. package/dist/console/assets/index-BrcDSBD8.css +1 -0
  29. package/dist/console/assets/index-Bz6IWncl.js +711 -0
  30. package/dist/console/index.html +2 -2
  31. package/dist/decisions.js +0 -4
  32. package/dist/eval-feed.d.ts +2 -2
  33. package/dist/eval-feed.js +9 -5
  34. package/dist/feed/parse.d.ts +3 -2
  35. package/dist/feed/parse.js +9 -18
  36. package/dist/feed/pointer.d.ts +2 -0
  37. package/dist/feed/pointer.js +17 -0
  38. package/dist/file-types.js +1 -0
  39. package/dist/host-command.d.ts +3 -0
  40. package/dist/host-command.js +18 -0
  41. package/dist/host.d.ts +3 -0
  42. package/dist/host.js +3 -0
  43. package/dist/import-sources.js +25 -5
  44. package/dist/learn/audit.d.ts +123 -0
  45. package/dist/learn/audit.js +159 -0
  46. package/dist/learn/check.d.ts +14 -0
  47. package/dist/learn/check.js +194 -14
  48. package/dist/learn/compile.d.ts +75 -78
  49. package/dist/learn/compile.js +175 -176
  50. package/dist/learn/folder.d.ts +9 -0
  51. package/dist/learn/folder.js +13 -2
  52. package/dist/learn/promote.d.ts +138 -196
  53. package/dist/learn/promote.js +68 -184
  54. package/dist/learn/replay-calls.d.ts +5 -0
  55. package/dist/learn/replay-calls.js +12 -1
  56. package/dist/learn/secrets.d.ts +8 -0
  57. package/dist/learn/secrets.js +12 -0
  58. package/dist/learn/skills.js +2 -4
  59. package/dist/learn/workflow-nodes.d.ts +1 -2
  60. package/dist/learn/workflow-nodes.js +2 -3
  61. package/dist/learned-nodes.d.ts +9 -34
  62. package/dist/learned-nodes.js +11 -23
  63. package/dist/learned-workflow.d.ts +6 -8
  64. package/dist/learned-workflow.js +18 -57
  65. package/dist/learning-batch.d.ts +13 -5
  66. package/dist/learning-batch.js +34 -8
  67. package/dist/learning-cost.d.ts +11 -4
  68. package/dist/learning-cost.js +4 -2
  69. package/dist/learning-routes.js +1 -1
  70. package/dist/learning-setting.d.ts +38 -0
  71. package/dist/learning-setting.js +83 -0
  72. package/dist/learning-words.d.ts +3 -0
  73. package/dist/learning-words.js +3 -0
  74. package/dist/learning.d.ts +3 -2
  75. package/dist/learning.js +5 -3
  76. package/dist/mcp-oauth.d.ts +8 -0
  77. package/dist/mcp-oauth.js +7 -0
  78. package/dist/mcp-private-hosts.d.ts +13 -0
  79. package/dist/mcp-private-hosts.js +16 -0
  80. package/dist/openapi.d.ts +1 -0
  81. package/dist/openapi.js +195 -59
  82. package/dist/run-files.d.ts +6 -2
  83. package/dist/run-files.js +29 -7
  84. package/dist/run-launch.d.ts +6 -3
  85. package/dist/run-launch.js +2 -0
  86. package/dist/run-learning-served.d.ts +2 -2
  87. package/dist/run-reads-over-store.d.ts +5 -1
  88. package/dist/run-reads-over-store.js +8 -4
  89. package/dist/run-recordings.d.ts +20 -0
  90. package/dist/run-recordings.js +133 -0
  91. package/dist/runner/adapter-loop.d.ts +5 -1
  92. package/dist/runner/adapter-loop.js +20 -8
  93. package/dist/runner/adapter-run-spec.d.ts +16 -1
  94. package/dist/runner/adapter-run-spec.js +36 -11
  95. package/dist/runner/audit.d.ts +64 -0
  96. package/dist/runner/audit.js +338 -0
  97. package/dist/runner/beside.js +2 -2
  98. package/dist/runner/cli-run-spec.js +25 -12
  99. package/dist/runner/feedback-round.d.ts +9 -25
  100. package/dist/runner/feedback-round.js +19 -40
  101. package/dist/runner/harness-loops.js +1 -15
  102. package/dist/runner/journal-kinds.d.ts +0 -7
  103. package/dist/runner/journal-kinds.js +0 -7
  104. package/dist/runner/learning-dispatch.d.ts +0 -16
  105. package/dist/runner/learning-dispatch.js +4 -47
  106. package/dist/runner/learning-end.d.ts +62 -13
  107. package/dist/runner/learning-end.js +180 -74
  108. package/dist/runner/learning-factory.d.ts +1 -1
  109. package/dist/runner/learning-factory.js +1 -4
  110. package/dist/runner/learning-loop.d.ts +2 -38
  111. package/dist/runner/learning-loop.js +8 -116
  112. package/dist/runner/main.d.ts +11 -0
  113. package/dist/runner/main.js +30 -3
  114. package/dist/runner/mcp-run.d.ts +2 -2
  115. package/dist/runner/promotion.d.ts +78 -50
  116. package/dist/runner/promotion.js +371 -503
  117. package/dist/runner/reflect-hook.d.ts +15 -0
  118. package/dist/runner/reflect-hook.js +28 -14
  119. package/dist/runner/store-secrets.js +3 -1
  120. package/dist/runner/workflow-first.d.ts +6 -11
  121. package/dist/runner/workflow-first.js +24 -25
  122. package/dist/runs-over-store.d.ts +1 -1
  123. package/dist/sdk/runs.js +2 -1
  124. package/dist/secrets.js +2 -2
  125. package/dist/server.d.ts +4 -3
  126. package/dist/server.js +132 -26
  127. package/dist/store/agent-body.d.ts +5 -3
  128. package/dist/store/agent-body.js +14 -10
  129. package/dist/store/sqlite/store.js +1 -0
  130. package/dist/store/store.d.ts +3 -0
  131. package/dist/store-reads/learning.d.ts +18 -7
  132. package/dist/store-reads/learning.js +36 -23
  133. package/dist/store-reads/loop.d.ts +5 -39
  134. package/dist/store-reads/loop.js +21 -80
  135. package/dist/store-view.d.ts +5 -0
  136. package/dist/store-view.js +16 -2
  137. package/dist/template-eval.d.ts +7 -0
  138. package/dist/template-eval.js +54 -6
  139. package/dist/templates.d.ts +3 -1
  140. package/dist/templates.js +14 -1
  141. package/dist/timeline/computer.js +2 -1
  142. package/dist/tool-list.js +1 -0
  143. package/dist/tools.d.ts +7 -0
  144. package/dist/tools.js +11 -0
  145. package/dist/trigger-feed.js +67 -18
  146. package/dist/validate.js +7 -2
  147. package/dist/workspace/computer-for-claim.d.ts +7 -0
  148. package/dist/workspace/computer-for-claim.js +12 -2
  149. package/dist/workspace/paths.d.ts +4 -0
  150. package/dist/workspace/paths.js +9 -0
  151. package/dist/workspace/resolve-computer.d.ts +3 -1
  152. package/dist/workspace/run-tools.d.ts +1 -1
  153. package/dist/workspace/run-tools.js +14 -3
  154. package/launcher/agentrun-serve +31 -24
  155. package/package.json +10 -9
  156. package/templates/README.md +11 -2
  157. package/dist/console/assets/index-C3gNPz58.css +0 -1
  158. package/dist/console/assets/index-COGhx_2Z.js +0 -711
  159. package/dist/learn/general.d.ts +0 -69
  160. package/dist/learn/general.js +0 -75
  161. package/dist/learn/refit.d.ts +0 -48
  162. package/dist/learn/refit.js +0 -264
  163. package/dist/runner/step-guard.d.ts +0 -62
  164. package/dist/runner/step-guard.js +0 -93
@@ -24,8 +24,8 @@ import { journalEntries } from "../runner/journal-reader.js";
24
24
  import { KINDS } from "../runner/journal-kinds.js";
25
25
  import { keptOf, learnedOf, lostOf } from "../runner/learning-loop.js";
26
26
  import { promotedOf } from "../learn/compile.js";
27
- import { championOf, gradesOf, gradeView, promotionsOf, withinBar } from "../learn/promote.js";
28
- import { GENERAL_NO_BUDGET, GENERAL_NO_ROOM, GENERAL_UNCHECKED } from "../learn/general.js";
27
+ import { isShadowRun, shadowRunId } from "../learn/audit.js";
28
+ import { championOf, checkShares, gradesOf, gradeView, promotionsOf } from "../learn/promote.js";
29
29
  const timeOf = (ms) => new Date(ms).toISOString();
30
30
  const usdOrNull = (value) => (typeof value === "number" && Number.isFinite(value) ? value : null);
31
31
  /** What a kept row says of a run that looked back (learning-run.ts closeLearning's fields): none for one that did not. */
@@ -37,7 +37,8 @@ function answeredOf(row) {
37
37
  /** Agent `agentId`'s runs' records read at once, whatever their number: its runs' launches (Store.runs.launches) and every
38
38
  * round its runs' learning kept with the learning runs they name (Store.learning.kept), two reads beside `listed` (its
39
39
  * runs, as runs.list read them). Each answers as the store's per-run read does: a run of `listed` with no launch row is
40
- * StoreLaunchMissing, one that kept no learning has no round. A run not of `listed` is read from the store. */
40
+ * StoreLaunchMissing, one that kept no learning has no round. A run not of `listed` is read from the store, but for an
41
+ * audit's shadow run: `listed` is every run of the agent, its shadows among them. */
41
42
  export async function agentRecordsOf(store, agentId, listed) {
42
43
  const [starts, kept] = await Promise.all([store.runs.learningStarts(agentId), store.learning.kept(agentId)]);
43
44
  const ours = new Set(listed.map((run) => run.id));
@@ -57,7 +58,9 @@ export async function agentRecordsOf(store, agentId, listed) {
57
58
  throw new StoreLaunchMissing(runId);
58
59
  return learningStartOfStored(startOf.get(runId));
59
60
  },
60
- get: async (id) => rows.get(id) ?? store.runs.get(id),
61
+ // An audit's shadow run is the agent's: one not among `listed` (every run of the agent) was never started, so a
62
+ // run's shadow (allInOf) is no read a run.
63
+ get: async (id) => rows.get(id) ?? (isShadowRun(id) ? undefined : store.runs.get(id)),
61
64
  },
62
65
  learning: {
63
66
  proposal: async (runId, round) => {
@@ -118,26 +121,20 @@ async function endOfKept(store, kept, row, records = store) {
118
121
  // What the grade spent: the graded entry's, or what a grade that failed spent before it did.
119
122
  const spent = graded ?? (dropped && "usd" in dropped ? { usd: dropped.usd ?? null, tokens: dropped.tokens ?? null } : undefined);
120
123
  const cost = spent ? { cost_usd: { grade: spent.usd }, tokens: { grade: spent.tokens ?? null } } : {};
121
- // A generality check that could not run (learning-loop.ts `unchecked`) is said after the end's words: the grader read
122
- // every note. Its provider's error stays in the journal.
123
- // One skipped for no room under the cap (GENERAL_NO_BUDGET) says so.
124
- const unchecked = graded?.unchecked ?? dropped?.unchecked;
125
- const skip = unchecked === undefined ? undefined : unchecked === GENERAL_NO_BUDGET ? GENERAL_NO_ROOM : GENERAL_UNCHECKED;
126
- const withSkip = (detail) => (skip ? [detail, skip].filter(Boolean).join(" ") : detail);
127
124
  if (merged && graded) {
128
125
  // Each item as the merge settled it: its record's verdict (a note it left out is no longer kept, and says why). A merge
129
126
  // recorded with none (before the record kept it) reads no item decisions.
130
127
  const verdict = merged.verdict;
131
128
  const what = verdict ? learnedOf(keptOf(row.proposal, verdict), verdict) : { learned: [], pending: [], skills: [], workflows: [] };
132
129
  return {
133
- state: "merged", reason: null, detail: withSkip(merged.detail), at: endedAt, ...left, ...(verdict ? { verdict } : {}), graded: { ...graded.graded }, ...cost, merged: merged.commit,
130
+ state: "merged", reason: null, detail: merged.detail, at: endedAt, ...left, ...(verdict ? { verdict } : {}), graded: { ...graded.graded }, ...cost, merged: merged.commit,
134
131
  learned: what.learned, ...(what.pending.length ? { pending: what.pending } : {}), ...(what.skills.length ? { skills: what.skills } : {}), ...(what.workflows.length ? { workflows: what.workflows } : {}),
135
132
  };
136
133
  }
137
134
  const reason = (dropped?.reason ?? null);
138
135
  const lost = reason === "grader" ? lostOf(row.proposal) : [];
139
136
  return {
140
- state: "dropped", reason, detail: withSkip(dropped?.detail ?? null), at: endedAt,
137
+ state: "dropped", reason, detail: dropped?.detail ?? null, at: endedAt,
141
138
  ...(dropped?.problems?.length ? { problems: [...dropped.problems] } : left),
142
139
  // The verdict, when one was given; the blobs it read only go with a merge (the server kept them for its merge alone).
143
140
  ...(graded ? { verdict: graded.verdict } : {}), ...cost, ...(lost.length ? { lost } : {}),
@@ -265,7 +262,8 @@ export async function agentCostOverStore(store, agentId, limit = Infinity) {
265
262
  const listed = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId);
266
263
  // Every run's launch and learning in a few reads (agentRecordsOf), never a read a run.
267
264
  const records = await agentRecordsOf(store, agentId, listed);
268
- const ended = listed.filter((run) => FINAL_STATES.includes(run.state) && !run.importedFrom && run.archivedAt === null).sort((a, b) => a.startedAt - b.startedAt || (a.id < b.id ? -1 : 1));
265
+ // An audit's shadow run is no run of the series: its cost is its served run's learning (allInOf).
266
+ const ended = listed.filter((run) => FINAL_STATES.includes(run.state) && !run.importedFrom && run.archivedAt === null && !isShadowRun(run.id)).sort((a, b) => a.startedAt - b.startedAt || (a.id < b.id ? -1 : 1));
269
267
  const runs = [];
270
268
  let unknownPath = 0;
271
269
  for (const run of ended) {
@@ -287,17 +285,18 @@ export async function agentCostOverStore(store, agentId, limit = Infinity) {
287
285
  const replay = servingReplayOf(await promotionsOf(store.settings, agentId), runs);
288
286
  return { runs: runs.slice(Math.max(0, runs.length - limit)), summary: costSummary(runs, replay), total_runs: runs.length, unknown_cost_runs: runs.filter((run) => run.total_usd === null).length, unknown_path_runs: unknownPath, workflows };
289
287
  }
290
- /** The replay the serving promotion was decided on, as the cost summary says it: the champion (championOf) of the learned
291
- * workflow the newest run a learned workflow ran first on ran (`workflow` or `handed_back`), its record's `replay` numbers
292
- * and whether they cleared the bar (withinBar, promotion's own). Null when no run was served, nothing serves now (held,
293
- * or never promoted), or it was promoted with no replay (a dry run). */
288
+ /** The check the serving promotion was decided on, as the cost summary says it: the champion (championOf) of the learned
289
+ * workflow the newest run a learned workflow ran first on ran (`workflow` or `handed_back`), its record's check numbers
290
+ * (the share of the inputs it ran on that said what the agent said, against the agent's own 100%). `cleared`: it passed
291
+ * (a champion is promoted), with the agreement check it passed (`agreed` of `alone`, its bar `agree_min`). Null when no run was served, nothing serves now (held, or never promoted), or it was promoted
292
+ * on no input (a dry run). */
294
293
  export function servingReplayOf(records, runs) {
295
294
  const name = runs.findLast((run) => (run.path === "workflow" || run.path === "handed_back") && run.workflow !== null)?.workflow;
296
- const score = name ? championOf(records, name)?.replay : undefined;
297
- if (!score)
295
+ const check = name ? championOf(records, name)?.check : undefined;
296
+ if (!check?.n)
298
297
  return null;
299
- const pct = (acc) => Math.round(acc * 1000) / 10;
300
- return { n: score.n, workflow_pct: pct(score.wf_acc), agent_pct: pct(score.agent_acc), cleared: withinBar(score) };
298
+ const agreed = check.agreed ?? 0, alone = check.alone ?? 0;
299
+ return { n: check.n, workflow_pct: Math.round(checkShares({ n: check.n, agreed, alone }).agreement * 1000) / 10, agent_pct: 100, cleared: true, agreed, alone, agree_min: check.agree_min };
301
300
  }
302
301
  /** What run `runId`'s learning spent, as its cost per run counts it, over every round a follow-up opened (roundsOf): what
303
302
  * it kept as it answered (`looked`: answeredOf), and its grades' spend (`grade`): each round's learning run's cost once
@@ -355,7 +354,21 @@ async function roundsSpentOf(store, rounds) {
355
354
  export async function allInOf(store, run) {
356
355
  // Every round's (learningSpendOf over the rounds: what its row spent after its job answered is learning, roundsLooked).
357
356
  const { looked, grade } = await learningSpendOf(store, run.id, run.costUsd);
358
- return runCostOf(run.costUsd, looked, grade);
357
+ // An audit's shadow run of it (runner/audit.ts) is its learning too (shadowSpendOf): unknown while it is queued or
358
+ // running, never $0.
359
+ const audited = (await shadowSpendOf(store, run.id)).usd;
360
+ return runCostOf(run.costUsd, looked, grade === null || audited === null ? null : grade + audited);
361
+ }
362
+ /** What run `runId`'s audit shadow run (runner/audit.ts) adds to its all-in cost: `open` while it is queued or running
363
+ * (its cost not known yet: `usd` null, never $0), else its cost once it ended, stopped or failed (null: unknown); 0 when
364
+ * none was started, and for a shadow itself. */
365
+ export async function shadowSpendOf(store, runId) {
366
+ if (isShadowRun(runId))
367
+ return { open: false, usd: 0 };
368
+ const shadow = await store.runs.get(shadowRunId(runId));
369
+ if (!shadow)
370
+ return { open: false, usd: 0 };
371
+ return FINAL_STATES.includes(shadow.state) ? { open: false, usd: shadow.costUsd ?? null } : { open: true, usd: null };
359
372
  }
360
373
  /** One run of the cost series, as number `n` of it: its figures (allInOf) and its path (agentCostOverStore's loop body,
361
374
  * and a learning batch's row once the run's learning has settled). */
@@ -376,7 +389,7 @@ export async function pastRunsOverStore(store, agentId, known, records = store)
376
389
  const kinds = new Map();
377
390
  const kept = [];
378
391
  for (const run of await store.runs.list({ agentId, limit: PAST_RUNS })) {
379
- if (run.agentId !== agentId || !FINAL_STATES.includes(run.state) || run.importedFrom || run.archivedAt !== null)
392
+ if (run.agentId !== agentId || !FINAL_STATES.includes(run.state) || run.importedFrom || run.archivedAt !== null || isShadowRun(run.id))
380
393
  continue;
381
394
  if (!kinds.has(run.revisionId))
382
395
  kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind);
@@ -1,9 +1,6 @@
1
1
  import { type Store } from "../store/store.js";
2
- import type { GuardRow } from "../learned-nodes.js";
3
2
  /** How many compile turns the read gives, the newest. */
4
3
  export declare const LOOP_COMPILES_MAX = 50;
5
- /** How many runs' p a guarded step gives, its newest. */
6
- export declare const LOOP_POINTS_MAX = 200;
7
4
  /** One compile turn of a run, in the round of it that compiled (a follow-up opens a round past the first, and each
8
5
  * round's end may compile): `errors` its draft's when none passed (never silent). */
9
6
  export type LoopCompile = {
@@ -20,42 +17,11 @@ export type LoopCompile = {
20
17
  promoted: boolean | null;
21
18
  draft_errors: string[];
22
19
  };
23
- /** One run's guard outcome on a step: its p (the least its checks read, a step in a map checking once per item; null
24
- * when a signal was missing on one: it handed back), whether one of its checks handed back, and, when the run's answer
25
- * was the workflow's own and it was graded, whether that was right. */
26
- export type LoopPoint = {
27
- run_id: string;
28
- p: number | null;
29
- escalated: boolean;
30
- correct: boolean | null;
31
- };
32
- /** One guarded step of one revision of a learned workflow, over the runs it served first on (each run once, however many
33
- * checks a map made of it): its threshold as those runs read it (null when only replays ran it), how many it guarded and
34
- * handed back, how many of those the workflow answered
35
- * alone were graded right and wrong, each over every such run, and the newest runs' p. A replay run reads its guards at
36
- * RECORD_ONLY_THRESHOLD (learn/promote.ts: it hands back on nothing it reads), so its row says nothing of a hand-back
37
- * at the serving threshold: it is counted apart (`replays`) and in none of the others. */
38
- export type LoopGuard = {
39
- workflow: string;
40
- digest: string;
41
- node: string;
42
- signal: GuardRow["signal"];
43
- threshold: number | null;
44
- runs: number;
45
- escalated: number;
46
- right: number;
47
- wrong: number;
48
- /** Runs it answered alone whose grade, if one was given, is no longer kept (the agent keeps its newest GRADES_KEPT
49
- * grades): in neither `right` nor `wrong`, never read as "not graded". */
50
- grades_past: number;
51
- replays: number;
52
- points: LoopPoint[];
53
- };
54
- /** The agent's compile turns (every round of each run, roundsOf: newest first, LOOP_COMPILES_MAX) and its learned
55
- * workflows' guarded steps, over its ended runs (not imported, not archived). A compile's `promoted` is its revision's
56
- * promotion as the records say now (null while undecided): whether it serves now is the promotions read's `serving`. A step's `correct` is the run's grade only on a run its workflow answered alone (path `workflow`): a
57
- * hand-back's answer was the agent's, and a replay run is never graded. */
20
+ /** The agent's compile turns (every round of each run, roundsOf: newest first, LOOP_COMPILES_MAX), over its ended runs
21
+ * (not imported, not archived), and how many completed runs of its own count toward its compile. A compile's `promoted`
22
+ * is its revision's promotion as the records say now (null while undecided): whether it serves now is the promotions
23
+ * read's `serving`. */
58
24
  export declare function agentLoopOverStore(store: Store, agentId: string): Promise<{
59
25
  compiles: LoopCompile[];
60
- guards: LoopGuard[];
26
+ completed_runs: number;
61
27
  }>;
@@ -1,91 +1,29 @@
1
1
  // GET /agents/{id}/learning/loop from the one store: what the console's Learning tab tells of the self-learning loop
2
2
  // beside the cost series. Each compile turn the agent's runs took (learn/compile.ts: the workflow it wrote, the notes it
3
- // absorbed, each attempt and what the checks refused, the draft's digest and whether that revision serves), and each
4
- // guarded step of its learned workflows (runner/step-guard.ts rows on a run's metrics.guards): its signal and threshold,
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
- // Aggregates and the checks' own words only: no input, no answer.
3
+ // absorbed, each attempt and what the checks refused, the draft's digest and whether that revision serves). The checks'
4
+ // own words only: no input, no answer.
7
5
  import { FINAL_STATES } from "../store/store.js";
8
- import { GRADES_KEPT, gradesOf, promotionsOf } from "../learn/promote.js";
9
- import { promotedOf } from "../learn/compile.js";
6
+ import { promotionOf, promotionsOf } from "../learn/promote.js";
7
+ import { lastOwnRuns, promotedOf } from "../learn/compile.js";
8
+ import { loopOf } from "../learning-setting.js";
10
9
  import { roundsOf } from "./learning.js";
11
10
  /** How many compile turns the read gives, the newest. */
12
11
  export const LOOP_COMPILES_MAX = 50;
13
- /** How many runs' p a guarded step gives, its newest. */
14
- export const LOOP_POINTS_MAX = 200;
15
12
  const texts = (list) => (Array.isArray(list) ? list.filter((one) => typeof one === "string") : []);
16
- const round4 = (value) => Math.round(value * 1e4) / 1e4;
17
- /** A run's guard rows of `workflow`'s calls as its record keeps them (metrics.guards), read as untrusted: a row out of
18
- * shape is left out, and so is one another workflow's call made (the agent can call one after the first hands back: the
19
- * run's digest is the first's, so the other's revision is not known here). */
20
- function guardRowsOf(metrics, workflow) {
21
- const rows = metrics?.guards;
22
- if (!Array.isArray(rows))
23
- return [];
24
- return rows.filter((row) => {
25
- const r = row;
26
- return !!r && r.workflow === workflow && typeof r.node === "string" && (r.signal === "self" || r.signal === "jev" || r.signal === "both") && typeof r.threshold === "number" && typeof r.escalated === "boolean" && (r.p === null || typeof r.p === "number");
27
- });
28
- }
29
- /** A run's checks of each step, one outcome per step (a step in a map checks once per item): handed back when any check
30
- * did, its p the least one read (null when one read none), its threshold the last check's; in the order each step first
31
- * checked. */
32
- function perStep(rows) {
33
- const steps = new Map();
34
- for (const row of rows) {
35
- const was = steps.get(row.node);
36
- if (!was) {
37
- steps.set(row.node, { node: row.node, signal: row.signal, threshold: row.threshold, p: row.p, escalated: row.escalated });
38
- continue;
39
- }
40
- was.threshold = row.threshold;
41
- was.escalated ||= row.escalated;
42
- was.p = was.p === null || row.p === null ? null : Math.min(was.p, row.p);
43
- }
44
- return [...steps.values()];
45
- }
46
- /** The agent's compile turns (every round of each run, roundsOf: newest first, LOOP_COMPILES_MAX) and its learned
47
- * workflows' guarded steps, over its ended runs (not imported, not archived). A compile's `promoted` is its revision's
48
- * promotion as the records say now (null while undecided): whether it serves now is the promotions read's `serving`. A step's `correct` is the run's grade only on a run its workflow answered alone (path `workflow`): a
49
- * hand-back's answer was the agent's, and a replay run is never graded. */
13
+ /** The agent's compile turns (every round of each run, roundsOf: newest first, LOOP_COMPILES_MAX), over its ended runs
14
+ * (not imported, not archived), and how many completed runs of its own count toward its compile. A compile's `promoted`
15
+ * is its revision's promotion as the records say now (null while undecided): whether it serves now is the promotions
16
+ * read's `serving`. */
50
17
  export async function agentLoopOverStore(store, agentId) {
51
18
  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));
52
- const [grades, promotions] = await Promise.all([gradesOf(store.settings, agentId).catch(() => []), promotionsOf(store.settings, agentId).catch(() => [])]);
53
- const graded = new Map(grades.map((grade) => [grade.run, grade.correct]));
54
- // The grades kept are the newest GRADES_KEPT (putGrade trims the oldest): once full, a run that ended before the oldest
55
- // grade kept and has none kept may have had one trimmed, so its grade is unknown. A run that ended after it with none
56
- // kept was never graded (a grade of it would be newer than one kept). Not full: nothing was trimmed.
57
- const kept = grades.map((grade) => Date.parse(grade.at)).filter(Number.isFinite);
58
- const keptSince = grades.length >= GRADES_KEPT ? (kept.length ? Math.min(...kept) : Infinity) : -Infinity;
19
+ // The completed runs of the agent's own toward its compile (what compileDue counts), at most compile_after: the tab
20
+ // says "N of compile_after" from this, never from the one page of runs it reads.
21
+ const current = (await store.agents.get(agentId))?.currentRevision;
22
+ const body = current ? (await store.agents.revision(current))?.body : undefined;
23
+ const completed_runs = (await lastOwnRuns(store, agentId, loopOf(body?.learning).compile_after)).length;
24
+ const promotions = await promotionsOf(store.settings, agentId).catch(() => []);
59
25
  const compiles = [];
60
- const steps = new Map();
61
26
  for (const run of ended) {
62
- const metrics = run.metrics;
63
- const workflow = typeof metrics?.workflow === "string" ? metrics.workflow : null;
64
- const digest = typeof metrics?.workflow_digest === "string" ? metrics.workflow_digest : null;
65
- if (workflow && digest) {
66
- const alone = metrics?.path === "workflow";
67
- for (const row of perStep(guardRowsOf(run.metrics, workflow))) {
68
- const key = `${workflow}\u0000${digest}\u0000${row.node}`;
69
- const step = steps.get(key) ?? { workflow, digest, node: row.node, signal: row.signal, threshold: null, runs: 0, escalated: 0, right: 0, wrong: 0, grades_past: 0, replays: 0, points: [] };
70
- steps.set(key, step);
71
- if (metrics?.path === "replay") {
72
- step.replays += 1;
73
- continue;
74
- }
75
- const correct = alone ? (graded.get(run.id) ?? null) : null;
76
- step.threshold = row.threshold;
77
- step.runs += 1;
78
- if (row.escalated)
79
- step.escalated += 1;
80
- if (correct === true)
81
- step.right += 1;
82
- if (correct === false)
83
- step.wrong += 1;
84
- if (alone && correct === null && (run.endedAt ?? run.startedAt) < keptSince)
85
- step.grades_past += 1;
86
- step.points.push({ run_id: run.id, p: row.p === null ? null : round4(row.p), escalated: row.escalated, correct });
87
- }
88
- }
89
27
  for (const kept of await roundsOf(store, run.id).catch(() => [])) {
90
28
  const row = (kept.proposal ?? null);
91
29
  if (!row)
@@ -97,15 +35,18 @@ export async function agentLoopOverStore(store, agentId) {
97
35
  continue;
98
36
  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
37
  const kept16 = typeof named?.digest === "string" && /^[0-9a-f]{16}$/.test(named.digest) ? named.digest : null;
38
+ // A draft its check had nothing to run on stopped (runner/promotion.ts stopUnchecked): its record's reason is one
39
+ // of the draft's errors, never silent.
40
+ const own = named && kept16 ? promotionOf(promotions, named.workflow, kept16) : undefined;
41
+ const unchecked = own?.decided === "hold" && own.check?.stopped && own.check.n === 0 ? [own.reason] : [];
100
42
  compiles.push({
101
43
  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,
44
+ digest: kept16, promoted: named && kept16 ? (promotedOf(promotions, named.workflow, kept16) ?? null) : null, draft_errors: [...errors, ...unchecked],
103
45
  });
104
46
  }
105
47
  }
106
- const guards = [...steps.values()].map((step) => ({ ...step, points: step.points.slice(-LOOP_POINTS_MAX) }));
107
48
  // 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
49
  // start and its round breaking a tie.
109
50
  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 };
51
+ return { compiles: newest.map(({ one: { createdAt: _createdAt, ...one } }) => one), completed_runs };
111
52
  }
@@ -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
@@ -21,7 +21,7 @@ import { freeCeilingMessage, overCapMessage, SPEND_CAP_REACHED } from "@parcha/a
21
21
  import { bookedSpend, cliModelWorked, costWordsOf, planSpend, runCostOf } from "./runner/metrics.js";
22
22
  import { journalRecords, recordOf } from "./runner/journal-reader.js";
23
23
  import { capNowOf, KINDS } from "./runner/journal-kinds.js";
24
- import { laidOf, notesReadOf, runLearningEnd, usedOnly, withNotes } from "./store-reads/learning.js";
24
+ import { laidOf, notesReadOf, runLearningEnd, shadowSpendOf, usedOnly, withNotes } from "./store-reads/learning.js";
25
25
  import { isCliRecord, runReflect, runTimeline, wholeAnswerFor, wholeAnswers, withoutFeedbackRounds } from "./store-reads/journal.js";
26
26
  import { readRun } from "./store-reads/runs.js";
27
27
  import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
@@ -319,6 +319,14 @@ function learningViewOf(learningEnd, shown, settled) {
319
319
  function underWay(started, laid, reflect, at) {
320
320
  return reflect ? { state: "reflecting", reason: null, detail: said.reflecting, at } : { state: "seeded", reason: null, detail: said.seeded(started.seedNotes ?? 0, laid.skills.length, laid.workflows.length), at };
321
321
  }
322
+ /** A view's cost with its audit shadow run's (store-reads/learning.ts shadowSpendOf: unknown while it is queued or
323
+ * running, 0 when none was started) added to `usd` (unknown once either is). */
324
+ function withShadowCost(cost, shadow) {
325
+ if (shadow === 0)
326
+ return cost;
327
+ const usd = typeof cost.usd === "number" && shadow !== null ? Math.round((cost.usd + shadow) * 1e6) / 1e6 : null;
328
+ return { ...cost, usd };
329
+ }
322
330
  /** The cost a run's view shows (runs.ts cost): its rows' cost, else what the store kept, and its cap. */
323
331
  function costOfView(run) {
324
332
  const imported = Boolean(run.row.importedFrom);
@@ -452,7 +460,9 @@ export async function viewOverStore(store, runId, deps) {
452
460
  error,
453
461
  review,
454
462
  pending,
455
- cost: costOfView(run),
463
+ cost: withShadowCost(costOfView(run), (await shadowSpendOf(store, runId)).usd),
464
+ // The run an audit's shadow run audits (launch.audit, runner/audit.ts); null for any other run.
465
+ audit_of: launch?.audit?.of ?? null,
456
466
  // Whether it ran unattended (its revision's approvals, as it started): never, an ask allowed at its gate; ask, the default.
457
467
  approvals: run.approvalsMode,
458
468
  archived_at: row.archivedAt ?? null,
@@ -463,6 +473,10 @@ export async function viewOverStore(store, runId, deps) {
463
473
  labels: runRow.labels,
464
474
  // Cut by the run's one cut (the pointers it was handed among them), and none for a withheld run, as its words.
465
475
  learning: unshown ? null : learningViewOf(run.learningEnd, secretsShown(values), settled),
476
+ // Its screen recordings (computer.record), from the files on this machine, where its read asks for them; none for a
477
+ // withheld run, whose files are refused. A run that left running with no end stamped (parked) ends now, each read: only
478
+ // a file's trailer finishes it there.
479
+ ...(deps.recordings ? { recordings: unshown ? [] : await deps.recordings(row.agent, row.id, ended ? (runRow.endedAt ?? Date.now()) : null) } : {}),
466
480
  poll_after_ms: settled ? 0 : 1000,
467
481
  last_progress_at: run.lastProgressAt,
468
482
  };
@@ -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;
@@ -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. */