@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.51

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 (216) hide show
  1. package/CHANGELOG.md +173 -9
  2. package/README.md +246 -39
  3. package/dist/agent-delete.d.ts +3 -2
  4. package/dist/agent-delete.js +29 -4
  5. package/dist/agents-store.js +7 -3
  6. package/dist/api-only.d.ts +8 -10
  7. package/dist/api-only.js +11 -12
  8. package/dist/capacity.d.ts +50 -0
  9. package/dist/capacity.js +49 -0
  10. package/dist/cli-learning/claude-wire.d.ts +41 -0
  11. package/dist/cli-learning/claude-wire.js +258 -0
  12. package/dist/cli-learning/cli.d.ts +11 -0
  13. package/dist/cli-learning/cli.js +241 -0
  14. package/dist/cli-learning/codex-worktree.d.ts +10 -0
  15. package/dist/cli-learning/codex-worktree.js +119 -0
  16. package/dist/cli-learning/connections.d.ts +62 -0
  17. package/dist/cli-learning/connections.js +87 -0
  18. package/dist/cli-learning/entry.d.ts +1 -0
  19. package/dist/cli-learning/entry.js +4 -0
  20. package/dist/cli-learning/evidence.d.ts +78 -0
  21. package/dist/cli-learning/evidence.js +492 -0
  22. package/dist/cli-learning/hook.d.ts +33 -0
  23. package/dist/cli-learning/hook.js +544 -0
  24. package/dist/cli-learning/install.d.ts +33 -0
  25. package/dist/cli-learning/install.js +335 -0
  26. package/dist/cli-learning/observation-proof.d.ts +14 -0
  27. package/dist/cli-learning/observation-proof.js +10 -0
  28. package/dist/cli-learning/policy.d.ts +48 -0
  29. package/dist/cli-learning/policy.js +363 -0
  30. package/dist/cli-learning/schema.d.ts +16 -0
  31. package/dist/cli-learning/schema.js +27 -0
  32. package/dist/cli-learning/state.d.ts +23 -0
  33. package/dist/cli-learning/state.js +61 -0
  34. package/dist/cli.js +24 -2
  35. package/dist/compute-cost.d.ts +101 -0
  36. package/dist/compute-cost.js +250 -0
  37. package/dist/console/assets/index-Bt1B51b7.js +733 -0
  38. package/dist/console/assets/index-sVftE9Ht.css +1 -0
  39. package/dist/console/index.html +2 -2
  40. package/dist/email/email-faux.d.ts +3 -1
  41. package/dist/email/email-faux.js +3 -2
  42. package/dist/email/routes.js +22 -12
  43. package/dist/eval-previous.d.ts +52 -0
  44. package/dist/eval-previous.js +164 -0
  45. package/dist/file-types.d.ts +2 -0
  46. package/dist/file-types.js +3 -1
  47. package/dist/harness-install.d.ts +6 -2
  48. package/dist/harness-install.js +40 -8
  49. package/dist/harness.d.ts +1 -1
  50. package/dist/harness.js +3 -2
  51. package/dist/learn/check.d.ts +8 -5
  52. package/dist/learn/check.js +25 -24
  53. package/dist/learn/repick.d.ts +22 -13
  54. package/dist/learn/repick.js +57 -56
  55. package/dist/learn/secrets.js +14 -3
  56. package/dist/learn/workflow-draft.d.ts +4 -0
  57. package/dist/learn/workflow-draft.js +10 -7
  58. package/dist/learned-workflow.js +8 -8
  59. package/dist/learning-setting.js +2 -2
  60. package/dist/learning-words.d.ts +1 -1
  61. package/dist/learning-words.js +1 -1
  62. package/dist/mcp-pin-first.js +2 -1
  63. package/dist/mcp-private-hosts.d.ts +24 -3
  64. package/dist/mcp-private-hosts.js +53 -3
  65. package/dist/model-gateway.d.ts +2 -0
  66. package/dist/model-gateway.js +3 -1
  67. package/dist/native/runtimes.d.ts +2 -0
  68. package/dist/native/runtimes.js +2 -0
  69. package/dist/observation/learning.d.ts +32 -0
  70. package/dist/observation/learning.js +66 -0
  71. package/dist/observation/observer.d.ts +8 -1
  72. package/dist/observation/observer.js +89 -9
  73. package/dist/observation/schema.js +12 -4
  74. package/dist/observation/usage-identity.d.ts +9 -0
  75. package/dist/observation/usage-identity.js +11 -0
  76. package/dist/openapi.js +113 -29
  77. package/dist/paid-calls.d.ts +13 -6
  78. package/dist/paid-calls.js +14 -8
  79. package/dist/run-launch.d.ts +16 -2
  80. package/dist/run-launch.js +6 -1
  81. package/dist/run-timeline-served.js +5 -3
  82. package/dist/run-usage.d.ts +23 -8
  83. package/dist/run-usage.js +100 -18
  84. package/dist/run-view.d.ts +2 -0
  85. package/dist/run-view.js +12 -7
  86. package/dist/runner/adapter-loop.d.ts +4 -0
  87. package/dist/runner/adapter-loop.js +44 -27
  88. package/dist/runner/adapter-run-spec.d.ts +8 -3
  89. package/dist/runner/adapter-run-spec.js +15 -8
  90. package/dist/runner/beside.d.ts +13 -0
  91. package/dist/runner/beside.js +27 -8
  92. package/dist/runner/big-writes.d.ts +33 -0
  93. package/dist/runner/big-writes.js +105 -0
  94. package/dist/runner/cli-run-spec.js +16 -8
  95. package/dist/runner/disk-free.d.ts +44 -0
  96. package/dist/runner/disk-free.js +96 -0
  97. package/dist/runner/feedback-round.d.ts +12 -8
  98. package/dist/runner/feedback-round.js +16 -30
  99. package/dist/runner/harness-loops.js +3 -1
  100. package/dist/runner/held.d.ts +4 -1
  101. package/dist/runner/journal-kinds.d.ts +1 -1
  102. package/dist/runner/learning-end.js +13 -4
  103. package/dist/runner/main.d.ts +17 -6
  104. package/dist/runner/main.js +187 -45
  105. package/dist/runner/metrics.d.ts +4 -0
  106. package/dist/runner/metrics.js +9 -0
  107. package/dist/runner/presence.d.ts +11 -2
  108. package/dist/runner/presence.js +31 -3
  109. package/dist/runner/run-child-host.d.ts +27 -17
  110. package/dist/runner/run-child-host.js +70 -116
  111. package/dist/runner/run-child.js +3 -0
  112. package/dist/runner/run-errors.js +2 -0
  113. package/dist/runner/runner-check.d.ts +51 -0
  114. package/dist/runner/runner-check.js +206 -0
  115. package/dist/runner/runner-metrics.d.ts +19 -0
  116. package/dist/runner/runner-metrics.js +49 -0
  117. package/dist/runner/runner.d.ts +37 -0
  118. package/dist/runner/runner.js +43 -3
  119. package/dist/runner/save-slots.d.ts +9 -0
  120. package/dist/runner/save-slots.js +91 -0
  121. package/dist/runner/sdk-loop.js +34 -22
  122. package/dist/runs-over-store.d.ts +8 -1
  123. package/dist/runs-over-store.js +57 -9
  124. package/dist/sdk/runs.d.ts +25 -6
  125. package/dist/sdk/runs.js +107 -35
  126. package/dist/sdk/runtimes.d.ts +19 -0
  127. package/dist/sdk/runtimes.js +23 -0
  128. package/dist/sdk/schema.d.ts +14 -8
  129. package/dist/sdk/schema.js +18 -6
  130. package/dist/server.d.ts +7 -0
  131. package/dist/server.js +151 -28
  132. package/dist/skills/agentrun-serve/SKILL.md +52 -7
  133. package/dist/start-switches.js +2 -0
  134. package/dist/stats.d.ts +4 -0
  135. package/dist/stats.js +1 -1
  136. package/dist/store/agent-body.d.ts +13 -2
  137. package/dist/store/agent-body.js +19 -4
  138. package/dist/store/dialect.d.ts +2 -0
  139. package/dist/store/dialect.js +1 -0
  140. package/dist/store/index.d.ts +3 -3
  141. package/dist/store/index.js +2 -2
  142. package/dist/store/postgres/connection.d.ts +5 -2
  143. package/dist/store/postgres/connection.js +19 -7
  144. package/dist/store/postgres/dialect.js +1 -0
  145. package/dist/store/postgres/migrate.d.ts +30 -0
  146. package/dist/store/postgres/migrate.js +72 -5
  147. package/dist/store/postgres/migration-lint.d.ts +8 -0
  148. package/dist/store/postgres/migration-lint.js +119 -0
  149. package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
  150. package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
  151. package/dist/store/postgres/store.d.ts +8 -3
  152. package/dist/store/postgres/store.js +31 -11
  153. package/dist/store/schema.d.ts +26 -4
  154. package/dist/store/schema.js +45 -4
  155. package/dist/store/sqlite/connection.d.ts +3 -3
  156. package/dist/store/sqlite/connection.js +3 -3
  157. package/dist/store/sqlite/run-launch.d.ts +9 -1
  158. package/dist/store/sqlite/run-launch.js +44 -0
  159. package/dist/store/sqlite/store.d.ts +19 -4
  160. package/dist/store/sqlite/store.js +180 -93
  161. package/dist/store/store-schema.d.ts +34 -0
  162. package/dist/store/store-schema.js +125 -0
  163. package/dist/store/store.d.ts +61 -2
  164. package/dist/store/store.js +13 -0
  165. package/dist/store-reads/analytics.d.ts +3 -2
  166. package/dist/store-reads/analytics.js +20 -8
  167. package/dist/store-reads/cap.d.ts +9 -5
  168. package/dist/store-reads/cap.js +28 -2
  169. package/dist/store-reads/decisions.d.ts +21 -0
  170. package/dist/store-reads/decisions.js +22 -0
  171. package/dist/store-reads/journal.d.ts +8 -2
  172. package/dist/store-reads/journal.js +27 -8
  173. package/dist/store-view.d.ts +9 -4
  174. package/dist/store-view.js +48 -25
  175. package/dist/template-eval.d.ts +15 -1
  176. package/dist/template-eval.js +92 -13
  177. package/dist/templates.d.ts +4 -3
  178. package/dist/templates.js +4 -3
  179. package/dist/timeline/labels.js +17 -0
  180. package/dist/tool-gate.d.ts +4 -2
  181. package/dist/tool-list.js +1 -0
  182. package/dist/tools.d.ts +6 -2
  183. package/dist/tools.js +13 -1
  184. package/dist/trigger-targets.d.ts +21 -5
  185. package/dist/trigger-targets.js +13 -10
  186. package/dist/unified-usage.d.ts +24 -0
  187. package/dist/unified-usage.js +400 -0
  188. package/dist/uploads-archil.d.ts +100 -0
  189. package/dist/uploads-archil.js +430 -0
  190. package/dist/uploads.d.ts +55 -1
  191. package/dist/uploads.js +185 -98
  192. package/dist/validate.js +1 -1
  193. package/dist/web-fake.d.ts +25 -0
  194. package/dist/web-fake.js +38 -1
  195. package/dist/web-save.d.ts +75 -0
  196. package/dist/web-save.js +235 -0
  197. package/dist/workspace/archil-claim.d.ts +5 -2
  198. package/dist/workspace/archil-claim.js +5 -2
  199. package/dist/workspace/archil-disk.d.ts +11 -1
  200. package/dist/workspace/archil-disk.js +43 -10
  201. package/dist/workspace/archil.d.ts +3 -0
  202. package/dist/workspace/archil.js +102 -16
  203. package/dist/workspace/computer-for-claim.d.ts +14 -0
  204. package/dist/workspace/computer-for-claim.js +46 -7
  205. package/dist/workspace/computer-intervals.d.ts +9 -3
  206. package/dist/workspace/computer-intervals.js +17 -8
  207. package/dist/workspace/pieced.d.ts +14 -0
  208. package/dist/workspace/pieced.js +23 -0
  209. package/dist/workspace/run-disk.js +32 -12
  210. package/dist/workspace/run-workspace.d.ts +1 -1
  211. package/dist/workspace/run-workspace.js +11 -6
  212. package/package.json +10 -10
  213. package/skills/agentrun-serve/SKILL.md +52 -7
  214. package/templates/README.md +36 -7
  215. package/dist/console/assets/index-Bzn4eUYF.js +0 -715
  216. package/dist/console/assets/index-CR2ZGei1.css +0 -1
@@ -6,6 +6,7 @@ import type { Store } from "../store/index.js";
6
6
  import type { MountCheck } from "./attach.js";
7
7
  import { type AttachedComputers } from "./attached-computers.js";
8
8
  import { type HeldComputer } from "./computer-hold.js";
9
+ import { type ComputeLedger, type ComputeMeterOptions } from "../compute-cost.js";
9
10
  import { type Kept, type ParkCause, type ParkedEnd } from "./computer-kept.js";
10
11
  import { type ProviderLedger } from "./computer-ledger.js";
11
12
  import { type ClaimBrowser, type ClaimSide, type ComputerSetting, type ComputerSettingKind, type KindRegistry, type ProviderEntry } from "./resolve-computer.js";
@@ -173,6 +174,15 @@ export interface ComputerForClaimDeps {
173
174
  readonly now?: () => number;
174
175
  /** Where a computer interval that could not be written is said (computer-intervals.ts). Default the runner's stderr. */
175
176
  readonly log?: (line: string) => void;
177
+ /** The run's one ledger and the server's environment, for its computers' time (compute-cost.ts): each computer the
178
+ * claim makes or takes back is metered there, priced by the operator's per-resource settings, its next stretch held
179
+ * under the run's cap. Absent (a runner of its own with no ledger here), nothing is held or booked: its time is on the
180
+ * usage read alone. */
181
+ readonly compute?: {
182
+ readonly ledger: ComputeLedger;
183
+ readonly env: NodeJS.ProcessEnv;
184
+ readonly every?: ComputeMeterOptions["every"];
185
+ };
176
186
  readonly signal?: AbortSignal;
177
187
  }
178
188
  /** The run's computer at its claim: what runTools takes, the person's hold on a desktop's or phone's ports, the hold
@@ -194,6 +204,10 @@ export interface ClaimComputer {
194
204
  /** The kind of computer a park of this claim keeps (`park`): a desktop, a phone or a sandbox the claim made through its
195
205
  * provider, or took back from an earlier claim's park. Absent: a park lets the computer go as the run's end does. */
196
206
  readonly keeps?: KeptKind;
207
+ /** Books the time of every computer this claim holds up to now on the run's ledger, its holds let go, its meter
208
+ * stopped (compute-cost.ts): run before the run's end or park is written (the spec's beforeRelease), so the end's
209
+ * cost holds it. Absent where nothing is metered. */
210
+ settle?(): Promise<void>;
197
211
  release(why?: ViewEnd): Promise<void>;
198
212
  /** The claim's release at the run's park, for `cause`: a computer it `keeps` is kept for KEEP_MS (computer-kept.ts),
199
213
  * its live view closed with the park's cause and the keep's time (ParkedEnd) and its hold ended, but the machine left
@@ -48,7 +48,8 @@ import { getSealedKey } from "../server-keys.js";
48
48
  import { agentComputerOf, forgetAgentComputer, holdAgentComputer, keepAgentComputer, liveHolderOf, reconcileAgentComputer, serverIdOf } from "./agent-computer.js";
49
49
  import { pairedProvider, withPaired } from "./attached-computers.js";
50
50
  import { computerHold, heldHands } from "./computer-hold.js";
51
- import { endingDeletes, intervalWrites } from "./computer-intervals.js";
51
+ import { endingDeletes, figuresOf, intervalWrites } from "./computer-intervals.js";
52
+ import { computeMeter } from "../compute-cost.js";
52
53
  import { deleteKept, endKept, KEEP_MS, readKept, takeKept, writeKept } from "./computer-kept.js";
53
54
  import { storeLedger } from "./computer-ledger.js";
54
55
  import { providerKeys, registryHere, resolveComputer } from "./resolve-computer.js";
@@ -255,12 +256,19 @@ function providerComputer(provider, ref, connection, ended) {
255
256
  async function providerLaunch(provider, claim, spec, signal, interval) {
256
257
  const { writes, entry } = interval;
257
258
  const releasedOlder = await releaseOlderClaims(provider, claim, signal, { entry, writes });
259
+ // Its first stretch held under the run's cap at what the create asks for, before anything is made: refused, nothing is.
260
+ const ahead = await interval.meter?.before(entry, figuresOf(spec));
258
261
  // The claim is the request: a retry of this launch under the same epoch gets the computer it made, never a second.
259
262
  const created = await provider.create(spec, { requestId: claimRequestId(claim), ...(signal ? { signal } : {}) });
260
- if (!created.ok)
263
+ if (!created.ok) {
264
+ void ahead?.drop();
261
265
  throw new Error(created.error.message);
266
+ }
262
267
  const ref = { id: created.value.id, name: created.value.name };
263
- await writes.opened(entry, ref.id, claim.runId, interval.kind, spec);
268
+ // What it was made with: its provider's figures where it said them, else what was asked. Metered from here.
269
+ const figures = figuresOf(spec, created.value.resources);
270
+ await writes.opened(entry, ref.id, claim.runId, interval.kind, figures);
271
+ interval.meter?.start(entry, ref.id, figures, ahead);
264
272
  const ended = () => writes.ended(entry, ref.id);
265
273
  const connected = await provider.connect(ref);
266
274
  if (!connected.ok) {
@@ -618,7 +626,23 @@ store, deps) {
618
626
  let ownKind;
619
627
  const now = deps.now ?? Date.now;
620
628
  /** Each computer this claim makes through its provider, from its create to its proven delete. */
621
- const writes = intervalWrites(store, deps.log, now);
629
+ const written = intervalWrites(store, deps.log, now);
630
+ /** Its time on the run's ledger (compute-cost.ts), while this claim holds it; none with no ledger here. */
631
+ const meter = deps.compute ? computeMeter({ env: deps.compute.env, ledger: deps.compute.ledger, booked: written.booked, now, ...(deps.compute.every ? { every: deps.compute.every } : {}), ...(deps.log ? { log: deps.log } : {}) }) : undefined;
632
+ /** The writes, each computer's meter stopped (its time booked up to now) before it is kept or its end written. */
633
+ const writes = meter
634
+ ? {
635
+ ...written,
636
+ kept: async (provider, providerId) => {
637
+ await meter.stop(provider, providerId);
638
+ await written.kept(provider, providerId);
639
+ },
640
+ ended: async (provider, providerId) => {
641
+ await meter.stop(provider, providerId);
642
+ await written.ended(provider, providerId);
643
+ },
644
+ }
645
+ : written;
622
646
  /** The computer an earlier claim of the run kept at its park (computer-kept.ts), read once: attached again when it is
623
647
  * the setting's and its time is not over (reattach), else left to the launch's releaseOlderClaims. A read that fails
624
648
  * is none. A run's first claim follows no park. */
@@ -687,11 +711,16 @@ store, deps) {
687
711
  mount = await deps.workspace.mountSpec();
688
712
  }
689
713
  const call = deps.signal ? { signal: deps.signal } : {};
714
+ const ahead = await meter?.before(entry.id, figuresOf(spec));
690
715
  const created = await provider.create({ ...spec, ...(mount ? { mount } : {}) }, { requestId: `${claimRequestId(launch)}#lost-${times}`, ...call });
691
- if (!created.ok)
716
+ if (!created.ok) {
717
+ void ahead?.drop();
692
718
  throw new Error(created.error.message);
719
+ }
693
720
  const ref = { id: created.value.id, name: created.value.name };
694
- await writes.opened(entry.id, ref.id, launch.runId, "sandbox", spec);
721
+ const figures = figuresOf(spec, created.value.resources);
722
+ await writes.opened(entry.id, ref.id, launch.runId, "sandbox", figures);
723
+ meter?.start(entry.id, ref.id, figures, ahead);
695
724
  const ended = () => writes.ended(entry.id, ref.id);
696
725
  const connected = await provider.connect(ref);
697
726
  if (!connected.ok) {
@@ -750,6 +779,10 @@ store, deps) {
750
779
  const taken = await keptLaunch(provider, record, signal, () => writes.ended(entry.id, record.id));
751
780
  if (!taken)
752
781
  return undefined;
782
+ // Metered again from here, with what its interval says it was made with: the time it was kept is no claim's.
783
+ const row = meter ? (await store.computerIntervals?.forRun(launch.runId).catch(() => undefined))?.find((one) => one.provider === entry.id && one.providerId === record.id) : undefined;
784
+ if (row)
785
+ meter?.start(entry.id, record.id, row);
753
786
  deps.inheritMount?.();
754
787
  // A sandbox taken back is started again when it is lost as one this claim made (lostAware): the new one is this
755
788
  // claim's, made from this claim's spec, its folder mounted.
@@ -818,7 +851,7 @@ store, deps) {
818
851
  // go. A paired computer is the same one at every claim, and is no computer of the run's own.
819
852
  const journalSays = !pairedRow && launch.epoch > 1 && (await deps.hadComputer?.()) === true;
820
853
  // A paired computer is no computer of the run's own: it has no interval.
821
- const fresh = await providerLaunch(provider, launch, spec, signal, pairedRow ? { writes: intervalWrites(undefined), entry: entry.id, kind } : { writes, entry: entry.id, kind });
854
+ const fresh = await providerLaunch(provider, launch, spec, signal, pairedRow ? { writes: intervalWrites(undefined), entry: entry.id, kind } : { writes, entry: entry.id, kind, ...(meter ? { meter } : {}) });
822
855
  // A sandbox the claim made is started again when its provider loses it mid-run (lostAware): never a paired
823
856
  // computer, nor a desktop or a phone (a person may hold or watch it), nor the agent's own (persistent, above).
824
857
  const { releasedOlder } = fresh;
@@ -861,6 +894,8 @@ store, deps) {
861
894
  started = await resolved.start({ workspace: deps.workspace, check: { ...deps.check, epoch: deps.check.epoch ?? launch.epoch }, ...(disk ? { store: disk } : {}), held: folderHeld, ...(deps.signal ? { signal: deps.signal } : {}) });
862
895
  }
863
896
  catch (error) {
897
+ // A computer made before the start failed is the claim's no more: its time booked up to now.
898
+ await meter?.stopAll().catch(() => undefined);
864
899
  await revoke().catch(() => undefined);
865
900
  throw error;
866
901
  }
@@ -890,6 +925,7 @@ store, deps) {
890
925
  const opened = await deps.openComputerView({ store, sealKey: deps.sealKey, claim: launch.claim ?? { runId: launch.runId, epoch: launch.epoch }, kind: computer.kind, input, tag: made.id, watch, hold: theHold, ...(made.gone ? { gone: made.gone } : {}) });
891
926
  if (!opened.ok) {
892
927
  await started.release().catch(() => undefined);
928
+ await meter?.stopAll().catch(() => undefined);
893
929
  await revoke().catch(() => undefined);
894
930
  if (opened.refused === "fenced")
895
931
  throw claimLost(`run ${launch.runId}'s claim (epoch ${launch.epoch}) is no longer this runner's, so its ${computer.kind} was released: ${opened.message}`);
@@ -914,6 +950,8 @@ store, deps) {
914
950
  await started.release();
915
951
  }
916
952
  finally {
953
+ // A computer whose delete failed is held by no claim from here: its time is booked up to now, and no more.
954
+ await meter?.stopAll();
917
955
  await revoke();
918
956
  }
919
957
  })());
@@ -928,6 +966,7 @@ store, deps) {
928
966
  ...(replaced ? { replaced } : {}),
929
967
  ...(ownKind ? { made: ownKind } : {}),
930
968
  ...(keeps ? { keeps: keeps.kind } : {}),
969
+ ...(meter ? { settle: () => meter.stopAll() } : {}),
931
970
  release,
932
971
  async park(cause) {
933
972
  if (!keeps || !settings || released) {
@@ -1,4 +1,5 @@
1
- import type { ComputerProvider, ComputerSpec } from "@parcha/agentrun-computer";
1
+ import type { ComputerProvider, ComputerResources, ComputerSpec } from "@parcha/agentrun-computer";
2
+ import type { ComputeFigures } from "../compute-cost.js";
2
3
  import type { ComputerIntervals } from "../store/index.js";
3
4
  /** The store as these writes need it: its intervals, where it keeps them (a test's store or an older caller's may not). */
4
5
  export type IntervalsStore = {
@@ -6,13 +7,18 @@ export type IntervalsStore = {
6
7
  };
7
8
  /** The writes of one process, each safe: a failure is said on `log` and never thrown. */
8
9
  export interface IntervalWrites {
9
- /** Run `runId`'s computer `providerId` on `provider` was made with `spec`, of `kind`. */
10
- opened(provider: string, providerId: string, runId: string, kind: string | null, spec: Pick<ComputerSpec, "gpu" | "cpus" | "memoryMb">): Promise<void>;
10
+ /** Run `runId`'s computer `providerId` on `provider` was made with `figures` (figuresOf), of `kind`. */
11
+ opened(provider: string, providerId: string, runId: string, kind: string | null, figures: ComputeFigures): Promise<void>;
11
12
  /** The run's park kept it past its claim. */
12
13
  kept(provider: string, providerId: string): Promise<void>;
13
14
  /** Its provider's delete answered ok, now. */
14
15
  ended(provider: string, providerId: string): Promise<void>;
16
+ /** A claim booked `ms` more of its time on the run's ledger (compute-cost.ts). */
17
+ booked(provider: string, providerId: string, ms: number): Promise<void>;
15
18
  }
19
+ /** What a computer was made with: each of `given`'s figures (its provider's answer), else `spec`'s (what its create
20
+ * asked), else null. A GPU's type and count are taken together, from one or the other. */
21
+ export declare function figuresOf(spec: Pick<ComputerSpec, "gpu" | "cpus" | "memoryMb">, given?: ComputerResources): ComputeFigures;
16
22
  /** The interval writes over `store` (none written where it keeps none), on the clock `now`, failures said on `log`. */
17
23
  export declare function intervalWrites(store: IntervalsStore | undefined, log?: (line: string) => void, now?: () => number): IntervalWrites;
18
24
  /** `provider` with each delete that answers ok ended in `writes` under `id` (the provider's registry id): the janitor's
@@ -1,6 +1,20 @@
1
1
  /** The default log: the runner's stderr, as its other lines. */
2
2
  const stderrLog = (line) => void process.stderr.write(`agentrun-serve runner: ${line}\n`);
3
3
  const count = (value) => (typeof value === "number" && Number.isFinite(value) ? value : null);
4
+ const wholeMb = (mb) => (mb === null ? null : Math.round(mb));
5
+ /** What a computer was made with: each of `given`'s figures (its provider's answer), else `spec`'s (what its create
6
+ * asked), else null. A GPU's type and count are taken together, from one or the other. */
7
+ export function figuresOf(spec, given) {
8
+ const gpu = given?.gpu ?? spec.gpu;
9
+ return {
10
+ cpus: count(given?.cpus) ?? count(spec.cpus),
11
+ // Whole MB, as the store keeps it: a provider that counts memory in GiB may give a fraction of one.
12
+ memoryMb: wholeMb(count(given?.memoryMb) ?? count(spec.memoryMb)),
13
+ gpuType: typeof gpu?.type === "string" ? gpu.type : null,
14
+ gpuCount: gpu ? count(gpu.count) : null,
15
+ diskGb: count(given?.diskGb),
16
+ };
17
+ }
4
18
  /** The interval writes over `store` (none written where it keeps none), on the clock `now`, failures said on `log`. */
5
19
  export function intervalWrites(store, log = stderrLog, now = Date.now) {
6
20
  const intervals = store?.computerIntervals;
@@ -15,16 +29,11 @@ export function intervalWrites(store, log = stderrLog, now = Date.now) {
15
29
  }
16
30
  };
17
31
  return {
18
- opened: (provider, providerId, runId, kind, spec) => safely(`${provider} ${providerId} (run ${runId})`, (to) => to.opened({
19
- runId, provider, providerId, kind,
20
- gpuType: typeof spec.gpu?.type === "string" ? spec.gpu.type : null,
21
- gpuCount: spec.gpu ? count(spec.gpu.count) : null,
22
- cpus: count(spec.cpus),
23
- memoryMb: count(spec.memoryMb),
24
- startedAt: now(),
25
- })),
32
+ opened: (provider, providerId, runId, kind, figures) => safely(`${provider} ${providerId} (run ${runId})`, (to) => to.opened({ runId, provider, providerId, kind, ...figures, startedAt: now() })),
26
33
  kept: (provider, providerId) => safely(`${provider} ${providerId}`, (to) => to.kept(provider, providerId)),
27
34
  ended: (provider, providerId) => safely(`${provider} ${providerId}`, (to) => to.ended(provider, providerId, now())),
35
+ // A store with no booked writes (an older test's) keeps none.
36
+ booked: (provider, providerId, ms) => safely(`${provider} ${providerId}'s booked time`, async (to) => void (await to.booked?.(provider, providerId, ms))),
28
37
  };
29
38
  }
30
39
  /** `provider` with each delete that answers ok ended in `writes` under `id` (the provider's registry id): the janitor's
@@ -0,0 +1,14 @@
1
+ import type { Workspace } from "./workspace.js";
2
+ /** The run's bytes from `offset`, `length` of them: what the runner pulls. */
3
+ export type PullPiece = (offset: number, length: number) => Promise<Uint8Array>;
4
+ /** A pieced write of `size` bytes at `path`, pulled through `pull`, under `signal`. */
5
+ export type WritePieces = (path: string, size: number, pull: PullPiece, signal?: AbortSignal) => Promise<void>;
6
+ /** What the runner hands beside a Workspace: its pieced write, and the piece size it pulls (a write of more is pieced). */
7
+ export type Pieces = {
8
+ readonly write: WritePieces;
9
+ readonly piece: number;
10
+ };
11
+ /** `remote` (a runner's Workspace held by handle in a run's process: a plain object of its stand-ins, as the channel
12
+ * decodes it) with a write of more than `pieces.piece` bytes made through `pieces.write`, under `signal`: the runner pulls
13
+ * it a piece at a time. A smaller write is one call, as before. No `pieces` (a runner that hands none): `remote` itself. */
14
+ export declare function piecedWorkspace(remote: Workspace, pieces: Pieces | undefined, signal?: AbortSignal): Workspace;
@@ -0,0 +1,23 @@
1
+ /** `remote` (a runner's Workspace held by handle in a run's process: a plain object of its stand-ins, as the channel
2
+ * decodes it) with a write of more than `pieces.piece` bytes made through `pieces.write`, under `signal`: the runner pulls
3
+ * it a piece at a time. A smaller write is one call, as before. No `pieces` (a runner that hands none): `remote` itself. */
4
+ export function piecedWorkspace(remote, pieces, signal) {
5
+ if (!pieces || typeof pieces.write !== "function" || !Number.isSafeInteger(pieces.piece) || pieces.piece < 1)
6
+ return remote;
7
+ const { write: writePieces, piece } = pieces;
8
+ return {
9
+ ...remote,
10
+ async write(path, data) {
11
+ const over = typeof data === "string" ? Buffer.byteLength(data, "utf8") > piece : data.length > piece;
12
+ if (!over)
13
+ return remote.write(path, data);
14
+ const bytes = typeof data === "string" ? Buffer.from(data, "utf8") : data;
15
+ const pull = async (offset, length) => {
16
+ if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(length) || offset < 0 || length < 0 || offset + length > bytes.length)
17
+ throw new RangeError("a piece past the write's bytes");
18
+ return bytes.subarray(offset, offset + length);
19
+ };
20
+ return writePieces(path, bytes.length, pull, signal);
21
+ },
22
+ };
23
+ }
@@ -8,9 +8,11 @@
8
8
  // - The agent's disk is stored on the agent (archil-settings.ts agentDiskOf). An agent with none yet has it made now, on
9
9
  // its first run that uses it (never at the agent's creation: an agent whose runs all name a disk never has one), named
10
10
  // agentrun-<server id>-i-<agent id> (diskNameOf), idempotent by that name. The plan's disk limit refuses the run in words.
11
+ // One it has is read at Archil at every claim (one GET), as a launch's is: a disk Archil no longer has, or one in
12
+ // another region, refuses the run in words naming the disk, the region and the way out, before any call on the disk.
11
13
  import { agentDiskOf, diskNameOf, keepRunDisk, runDiskKept, serverIdOf, storeAgentDisk } from "../archil-settings.js";
12
14
  import { ArchilClaimRefused } from "./archil-claim.js";
13
- import { ArchilDiskLimit, availableDisk, ensureDisk, getDisk } from "./archil-disks.js";
15
+ import { ArchilDiskError, ArchilDiskLimit, availableDisk, ensureDisk, getDisk } from "./archil-disks.js";
14
16
  /** The words of the plan's disk limit, its number when Archil said it. */
15
17
  export const diskLimitWords = (limit) => limit === undefined ? "your Archil plan's disk limit is reached; upgrade or delete an agent" : `your Archil plan allows ${limit} disks; upgrade or delete an agent`;
16
18
  /** Why disk `diskId`, named by a launch, can't hold a run here, in words naming the region; undefined when it can. A call
@@ -38,16 +40,36 @@ export async function runDiskOf(options) {
38
40
  return { diskId: launch.diskId, kind: "launch" };
39
41
  }
40
42
  const stored = await agentDiskOf(options.store, options.agentId);
41
- /** Waits for a pending disk to read available, then clears its pending mark (unless it was removed or replaced meanwhile). */
42
- const ready = async (diskId) => {
43
- await availableDisk(control, diskId, { ...(options.availableMs !== undefined ? { timeoutMs: options.availableMs } : {}), ...(signal ? { signal } : {}) });
43
+ /** Waits for the disk to read available at Archil (one just made reads `creating` for a while; one made before reads
44
+ * available at once, one read), then clears a pending mark (unless it was removed or replaced meanwhile). */
45
+ const ready = async (diskId, pending) => {
46
+ const disk = await availableDisk(control, diskId, { ...(options.availableMs !== undefined ? { timeoutMs: options.availableMs } : {}), ...(signal ? { signal } : {}) });
47
+ if (!pending)
48
+ return disk;
44
49
  const now = await agentDiskOf(options.store, options.agentId);
45
50
  if (now?.diskId === diskId && !now.removing)
46
51
  await storeAgentDisk(options.store, options.agentId, { diskId });
52
+ return disk;
53
+ };
54
+ /** The agent's disk made at an earlier claim, read at Archil again at this one, as a launch's is: one Archil no longer
55
+ * has, or one in another region than the key's, refuses the run in words before any call on it. A disk that is gone is
56
+ * never made again in its place: the agent's learning and its runs' folders were on it, and a new empty disk would
57
+ * hide that they are lost. Its owner drops it, and the next run makes a new one. */
58
+ const readyReused = async (diskId, pending) => {
59
+ let disk;
60
+ try {
61
+ disk = await ready(diskId, pending);
62
+ }
63
+ catch (error) {
64
+ if (error instanceof ArchilDiskError && error.status === 404) {
65
+ const agent = options.agentId;
66
+ throw new ArchilClaimRefused(`This agent's Archil disk ${diskId} is gone: Archil has no disk ${diskId} in region ${region}. The agent's learning and its runs' folders were on it, so no new disk is made in its place. DELETE /v2/agents/${agent}/archil drops it (an agent made here is archived first, POST /v2/agents/${agent}/archive, and unarchived after), and the agent's next run makes a new one.`, { cause: error });
67
+ }
68
+ throw new ArchilClaimRefused(`This agent's Archil disk ${diskId} is not ready in region ${region}: ${error.message}`, { cause: error });
69
+ }
70
+ if (disk.region !== "" && disk.region !== region)
71
+ throw new ArchilClaimRefused(`This agent's Archil disk ${diskId} is in region ${disk.region}, and this server's Archil key is for region ${region}: a run's folder is only on a disk in the key's region.`);
47
72
  };
48
- const readyReused = (diskId) => ready(diskId).catch((error) => {
49
- throw new ArchilClaimRefused(`This agent's Archil disk ${diskId} is not ready in region ${region}: ${error.message}`, { cause: error });
50
- });
51
73
  // A launch that names no disk resolved to its agent's on its first claim, and that disk was kept for the run: a later
52
74
  // claim of the same run (a reopened one) mounts it or is refused, never another disk.
53
75
  const kept = launch === undefined && options.runId !== undefined ? await runDiskKept(options.store, options.runId) : undefined;
@@ -57,8 +79,7 @@ export async function runDiskOf(options) {
57
79
  if (bound !== undefined) {
58
80
  if (stored?.diskId !== bound || stored.removing)
59
81
  throw new ArchilClaimRefused(`This run's Archil disk ${bound} was its agent's, and it ${stored?.diskId === bound ? "is being" : "has been"} removed: start a new run, and it gets the agent's new disk.`);
60
- if (stored.pending)
61
- await readyReused(bound);
82
+ await readyReused(bound, stored.pending === true);
62
83
  return { diskId: bound, kind: "agent" };
63
84
  }
64
85
  const keep = async (diskId) => {
@@ -69,8 +90,7 @@ export async function runDiskOf(options) {
69
90
  if (stored?.removing)
70
91
  throw new ArchilClaimRefused(`This agent's Archil disk ${stored.diskId} is being removed: start a new run once that is done, and it gets a new disk.`);
71
92
  if (stored !== undefined) {
72
- if (stored.pending)
73
- await readyReused(stored.diskId);
93
+ await readyReused(stored.diskId, stored.pending === true);
74
94
  return keep(stored.diskId);
75
95
  }
76
96
  const name = diskNameOf(await serverIdOf(options.store), options.agentId);
@@ -80,7 +100,7 @@ export async function runDiskOf(options) {
80
100
  // Stored before the wait, as pending, so a disk that never becomes available is still the agent's (DELETE
81
101
  // /v2/agents/{id}/archil finds it, and the plan's slot it takes is never lost) and a claim that finds it waits.
82
102
  await storeAgentDisk(options.store, options.agentId, { diskId: id, pending: true });
83
- await ready(id);
103
+ await ready(id, true);
84
104
  }
85
105
  catch (error) {
86
106
  if (error instanceof ArchilDiskLimit)
@@ -1,5 +1,5 @@
1
1
  import { type ArchilClaim } from "./archil-claim.js";
2
- import type { Workspace } from "./workspace.js";
2
+ import { type Workspace } from "./workspace.js";
3
3
  export type RunWorkspaceOptions = {
4
4
  readonly agentId: string;
5
5
  readonly runId: string;
@@ -3,15 +3,18 @@
3
3
  // tools' own end.
4
4
  //
5
5
  // Mode 2: the run's folder on the claim's Archil disk (archil-claim.ts), at runKey, in the image the server's Archil
6
- // settings name. Its exec spill folder is swept when the run starts (what a killed exec, a crash or a failed cleanup left)
7
- // and again at its end. A cleanup that leaves spill files (onCleanupFailed), or a sweep that fails, goes to the run's
8
- // log in words and never fails the run: the next sweep takes what is left.
6
+ // settings name. The folder is made at the claim when it is not there yet; a folder that can't be made fails the claim
7
+ // in Archil's words, as everything the run does is in it. Its exec spill folder is swept when the run starts (what a
8
+ // killed exec, a crash or a failed cleanup left) and again at its end. A cleanup that leaves spill files
9
+ // (onCleanupFailed), or a sweep that fails, goes to the run's log in words and never fails the run: the spill folder is
10
+ // beside the run's folder, each exec's files are its own, and the next sweep takes what is left.
9
11
  // Mode 1: the run's local folder (runFolder). Its end does nothing here; the tools' end clears what they keep in it.
10
12
  import { mkdir } from "node:fs/promises";
11
13
  import { HELD_ARCHIL } from "./archil-claim.js";
12
14
  import { archilWorkspace } from "./archil.js";
13
15
  import { localWorkspace } from "./local.js";
14
16
  import { runFolder, runKey } from "./paths.js";
17
+ import { WorkspaceError } from "./workspace.js";
15
18
  /** The Workspace of run `runId` of agent `agentId` for this claim: Mode 2's spill folder swept first. */
16
19
  export async function openRunWorkspace(options) {
17
20
  const { agentId, runId, log } = options;
@@ -52,9 +55,11 @@ export async function openRunWorkspace(options) {
52
55
  say(`the run's exec spill folder could not be swept at the run's ${when} (the next sweep takes what is left): ${error?.message ?? error}`);
53
56
  }
54
57
  };
55
- // The run's folder on the disk (its run key), ensured at the claim as Mode 1's is: a fresh run has none yet. A write would
56
- // make its prefix anyway, so a failure here never fails the run; it is the next write's.
57
- await workspace.mkdir("").catch((error) => say(`the run's folder could not be made on the disk (a write will make it): ${error?.message ?? error}`));
58
+ // The run's folder on the disk (its run key), ensured at the claim as Mode 1's is: a fresh run has none yet. One already
59
+ // there (a later claim's, its kept computer perhaps holding it) is left as it is.
60
+ await workspace.ensureRoot().catch((error) => {
61
+ throw new WorkspaceError(error.code, `the run's folder on its Archil disk could not be made: ${error.message}`, { cause: error });
62
+ });
58
63
  await sweep("start");
59
64
  let ended;
60
65
  return { workspace, end: () => (ended ??= sweep("end")) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-serve",
3
- "version": "0.1.0-beta.49",
3
+ "version": "0.1.0-beta.51",
4
4
  "description": "The AgentRun server: the /v2 API and console over one store, with runners that run your agents; the deployable process of the AgentRun platform.",
5
5
  "keywords": [
6
6
  "agentrun",
@@ -62,15 +62,15 @@
62
62
  "@earendil-works/pi-coding-agent": "1.5.2",
63
63
  "@modelcontextprotocol/client": "2.4.0",
64
64
  "@modelcontextprotocol/server": "2.4.0",
65
- "@parcha/agentrun-computer": "0.1.0-beta.49",
66
- "@parcha/agentrun-decisions": "0.1.0-beta.49",
67
- "@parcha/agentrun-dsl": "0.1.0-beta.49",
68
- "@parcha/agentrun-harness-acp": "0.1.0-beta.49",
69
- "@parcha/agentrun-harness-claude": "0.1.0-beta.49",
70
- "@parcha/agentrun-harness-codex": "0.1.0-beta.49",
71
- "@parcha/agentrun-jev": "0.1.0-beta.49",
72
- "@parcha/agentrun-kernel": "0.1.0-beta.49",
73
- "@parcha/pi-browser": "0.1.0-beta.49",
65
+ "@parcha/agentrun-computer": "0.1.0-beta.51",
66
+ "@parcha/agentrun-decisions": "0.1.0-beta.51",
67
+ "@parcha/agentrun-dsl": "0.1.0-beta.51",
68
+ "@parcha/agentrun-harness-acp": "0.1.0-beta.51",
69
+ "@parcha/agentrun-harness-claude": "0.1.0-beta.51",
70
+ "@parcha/agentrun-harness-codex": "0.1.0-beta.51",
71
+ "@parcha/agentrun-jev": "0.1.0-beta.51",
72
+ "@parcha/agentrun-kernel": "0.1.0-beta.51",
73
+ "@parcha/pi-browser": "0.1.0-beta.51",
74
74
  "@secretlint/core": "13.1.0",
75
75
  "@secretlint/profiler": "13.1.0",
76
76
  "@secretlint/secretlint-rule-preset-recommend": "13.1.0",
@@ -30,7 +30,7 @@ Inspect configured models before asking for a key. For an existing setup, follow
30
30
  and history import need no destination model key. Live jobs use the source runtime's existing sign-in.
31
31
 
32
32
  Finish with the first requested run's result and console link, or imported history and counts. Offer optional
33
- self-improvement separately, and verify accepted notes or skills in a fresh later run when requested.
33
+ self-improvement separately, and verify owner corrections in a fresh later run when requested.
34
34
 
35
35
  ## Connect agent
36
36
 
@@ -108,11 +108,56 @@ reported model/harness and activity/usage. CLI `configured` or `delivery_state:
108
108
  delivery. Observed sessions are read-only: idle is not proof of completion, and missing telemetry is not proof of
109
109
  an agent failure. No prompts, transcripts or tool contents are uploaded through this metadata path.
110
110
 
111
- If the user also wants self-improvement for application-owned jobs, follow the supported backend SDK learning
111
+ For independently started **Codex CLI or Claude Code** sessions, use the existing CLI learning path below.
112
+ For SDK application-owned jobs, follow the supported backend SDK learning
112
113
  integration and verify accepted-revision delivery in a fresh run. Observation alone cannot enable it. The current
113
114
  Claude Agent SDK and Codex SDK wrappers are TypeScript integrations; do not claim a Python SDK backend is wrapped
114
115
  by setting OTEL variables. Do not fabricate a runnable native agent or use a copied prompt as proof.
115
116
 
117
+ ### Learning in existing CLI sessions
118
+
119
+ For a connected-session card handoff, read its exact `GET /v2/observations?session_id=...` record.
120
+ On the source machine, resolve `external_session_id` through the collector's private identity map to the
121
+ native session, then inspect that session's actual project through its harness. Never print the identity
122
+ map or credentials, and never select a project from a display name or basename. A verified
123
+ `learning.agent_id` links to the existing shared project/runtime learning profile; reuse it. If the
124
+ source is unavailable, ask the user to open the original session. Run and Edit continue or change that
125
+ original setup, not a managed run or a replacement definition. Delegated children cannot enable independent
126
+ hook learning. Only offer enrollment for the selected root session's project, with its shared scope clear.
127
+
128
+ When requested, use the matching build's `learning connect` on the source machine. This path keeps the
129
+ original CLI in control of task execution and does not require an SDK wrapper. The initial integration
130
+ requires AgentRun on that same machine; identify its loopback port and actual data directory. Do not
131
+ silently replace a remote destination with a new local server. Enrollment uses the local owner credential
132
+ privately and leaves a scoped connection credential for hooks, never an owner key in project files.
133
+
134
+ ```sh
135
+ agentrun-serve learning connect --project /absolute/project --runtime codex \
136
+ --url http://127.0.0.1:7340 --data /absolute/server-data
137
+ ```
138
+
139
+ Use `claude-code` for Claude Code. Scope enrollment to the selected project/runtime. Installation merges
140
+ source hooks without replacing other hooks or changing tools, permissions, instructions or sign-in.
141
+ Codex linked worktrees append exact project-scoped hooks to the corresponding main-checkout
142
+ `.codex/hooks.json`, following native discovery. They keep separate local receipts and a local `.codex`
143
+ directory; disconnect preserves surviving native hook positions. If `learning status` reports `migration-required`,
144
+ rerun the same connect command to migrate unchanged owned hooks without replacing the connection.
145
+ Verify `/hooks`; Codex must trust the current declaration. Project configuration does not hot reload:
146
+ open a new session or close and resume it after the current task finishes. Reloading user settings alone
147
+ does not reload these project hooks. Do not interrupt the user's running task to activate them.
148
+ Do not claim merely writing a configuration file activated a running session. Begin on the next complete
149
+ prompt after activation, without importing earlier conversations or learning from an in-flight turn.
150
+
151
+ The prompt hook supplies pinned owner corrections; completion hooks record bounded role-preserving evidence
152
+ and reported usage. Source dialogue never becomes a standing correction automatically. Source hooks do not
153
+ provide a workflow execution bridge or make extra native reflection calls. Missing policy, truncated evidence
154
+ and cancellation stay explicit. This is not metadata-only observation.
155
+
156
+ Use `learning status` with the same project/runtime/data arguments and open the returned agent's Learning
157
+ tab. Save a correction explicitly, then verify an actual completed source run and its delivery and use
158
+ on a later prompt. Report incomplete evidence accurately. Learning Off controls guidance for future prompts;
159
+ `learning disconnect` revokes enrollment and removes only its installed hooks, retaining prior history.
160
+
116
161
  ### Live connection on this server
117
162
 
118
163
  Verify that the coding agent, source project and AgentRun server are on the same machine. A browser's loopback
@@ -210,11 +255,11 @@ target; duplicates are skipped. The worker does not continuously upload historic
210
255
 
211
256
  ### Optional self-improvement
212
257
 
213
- When requested, verify the imported agent and enable its existing **Self-improving** control. Notes and skills are
214
- additive, pinned to a learning revision for each run. Reflection resumes the exact task session with tools disabled;
215
- the existing checker, grader and merge rules decide what becomes active. Risky proposals await owner review in
216
- Learning Dojo; a connector cannot approve them. Reflection and grading add model usage. Off means later runs
217
- receive and create no AgentRun learning. Do not start a paid run unless authorized, and do not promise enforcement
258
+ When requested, verify the imported agent and enable its existing **Self-improving** control. Owner corrections
259
+ are additive, pinned to a learning revision for each run. Eligible jobs compile into workflow drafts by resuming
260
+ the exact task session with tools disabled; checks and a dry run decide whether to keep a draft. Compilation
261
+ adds model usage. Learned workflows do not serve native runs in this release. Off means later runs receive
262
+ and create no AgentRun learning. Do not start a paid run unless authorized, and do not promise enforcement
218
263
  of native dollar caps, interactive approvals, learned workflows or unsupported desktop tools.
219
264
 
220
265
  ### Historical import into a local store
@@ -14,7 +14,7 @@ code-review/
14
14
  skills/<name>/SKILL.md Agent Skills: front matter names the skill (= its folder) and describes it
15
15
  rules/*.md rules each skill reads: apply puts a copy beside each SKILL.md
16
16
  evals/<case>/prompt.md a case's run input (front matter: description, runs, max_cost_usd, ...)
17
- evals/<case>/graders/*.md front matter `type`: llm, regex, tool_used or file_exists
17
+ evals/<case>/graders/*.md front matter `type`: llm, regex, tool_used, file_exists, mailbox or handed
18
18
  evals/<case>/case.yaml, evals/<case>/fixtures/ optional
19
19
  skills/review/findings.schema.json any other file the manifest names (here the answer's schema, which the
20
20
  reviewers' guides beside it read too)
@@ -101,11 +101,12 @@ Each `evals/<case>/` is one test of the package's agent. No eval runs on the ser
101
101
  server writes them, under `Input:`; a body that holds its own `Input:` block is refused.
102
102
  - `case.yaml`, optional: `parameters` (the apply's parameters), `grants` (the gate names the apply grants, always a
103
103
  list), `mcp` (an `mcp` need's toolkit to a fixture file in the case that fakes it), `learning` (a file in the case holding
104
- the corrections the agent starts with, as its `corrections.md`: one line each), `web` (fakes `web_search` and `web_fetch` for the case's runs),
104
+ the corrections the agent starts with, as its `corrections.md`: one line each), `web` (fakes `web_search`, `web_fetch` and `web_save` for the case's runs),
105
105
  `monid` (fakes the package's monid endpoints for the case's runs), `now` (the case's clock), `email` (a fake mailbox
106
- for the case's runs), `calendar` (a fake calendar for the case's runs).
106
+ for the case's runs), `calendar` (a fake calendar for the case's runs), `feed` (fake feeds for the case's runs),
107
+ `previous` (the earlier results the schedule's run is handed).
107
108
  - `web: unavailable`: every `web_search` answers with the words a rate-limited free search answers with, and every
108
- `web_fetch` fails as a page that never answers does; no call reaches the network. `web:` a fixture file in the case
109
+ `web_fetch` and `web_save` fails as a host that never answers does; no call reaches the network. `web:` a fixture file in the case
109
110
  answers from that file instead:
110
111
  ```json
111
112
  { "search": { "answers": [ { "query": "robot", "results": [ { "url": "https://...", "title": "...", "snippet": "...", "published": "2026-11-10" } ] },
@@ -113,13 +114,17 @@ Each `evals/<case>/` is one test of the package's agent. No eval runs on the ser
113
114
  "default": { "results": [] } },
114
115
  "fetch": { "answers": [ { "url": "https://.../post", "title": "...", "text": "the page's text" },
115
116
  { "url": "https://.../gone", "status": 404, "text": "" } ],
116
- "default": { "error": "fetch failed" } } }
117
+ "default": { "error": "fetch failed" } },
118
+ "save": { "answers": [ { "url": "https://.../out.png", "content_type": "image/png", "base64": "iVBORw0KGgo..." },
119
+ { "url": "https://.../gone.png", "error": "connect ETIMEDOUT" } ] } }
117
120
  ```
118
121
  A search answer's `query` is a regular expression over the call's query (case-insensitive), a fetch answer's `url`
119
122
  the exact URL; the first answer that matches is taken, else `default`. A `status` of 400 or more fails the fetch as
120
- that answer would. The calls show in the run's timeline as any other, so a `tool_used` grader counts them. Each
123
+ that answer would. `save` is optional: each `web_save` file is the answer for exactly its URL (its body as `text` or
124
+ `base64`, with `content_type` and `status` optional), else `save.default` where there is one, else a refused
125
+ connection; the file goes through `web_save`'s own checks (its type against its bytes, the path, the cap). The calls show in the run's timeline as any other, so a `tool_used` grader counts them. Each
121
126
  harness gets the same fake: on claude-agent and codex their own web search is never offered to a `web:` case's runs.
122
- The package's `tools` must name `web_search` or `web_fetch`. Only the eval's own server honours `web`, so a case with
127
+ The package's `tools` must name `web_search`, `web_fetch` or `web_save`. Only the eval's own server honours `web`, so a case with
123
128
  it refuses to run with `--server`.
124
129
  - `monid: unavailable`: every call of a monid endpoint the package grants answers as it does when monid can't be
125
130
  reached (`... was not sent: monid's price for it could not be read before the call (monid could not be reached: fetch
@@ -199,6 +204,26 @@ Each `evals/<case>/` is one test of the package's agent. No eval runs on the ser
199
204
  `prompt.md` holds `description` and `runs` alone: the run's input and cap are the trigger's, and its graders' task is
200
205
  that input, the item's payload in its tag. Only the eval's own server honours `feed`, so a case with it refuses
201
206
  `--server`.
207
+ - `previous: fixtures/previous.json`, a fixture file in the case: the earlier completed results of the package's
208
+ schedule trigger, which its next run is handed after its message. The fixture:
209
+ ```json
210
+ { "description": "Last week's digest listed two jobs; this week's leaves them out.",
211
+ "results": [ { "output": { "items": ["https://jobs.example.com/1"] } },
212
+ { "output": { "items": ["https://jobs.example.com/2", "https://jobs.example.com/3"] },
213
+ "output_schema": { "type": "object", "x-carried": ["items"], "properties": { "items": { "type": "array" } } } } ],
214
+ "trigger": "Weekly" }
215
+ ```
216
+ `results` are oldest first, at least one; each `output` is that run's `result.output`, checked when the case is read
217
+ against its own `output_schema` (the schema the run that made it had, `x-carried` included), else the package's
218
+ `output` schema. Each run's agent gets them written in the server's store as completed runs of that agent, a day
219
+ apart, each started by a firing of the trigger; then the trigger fires on the eval's clock, as a schedule does, and the
220
+ run is handed what a scheduled run is handed: the last result whole up to 32 KiB, else the fields its run's schema
221
+ names in `x-carried` (the first entries of the largest carried array dropped until they fit, and how many said), else
222
+ nothing, said so. `trigger` names the trigger when the package has more than one schedule. The case's `prompt.md`
223
+ holds `description` and `runs` alone; `previous` goes with neither `email` nor `feed`. What the run was handed is on
224
+ its report as `handed_previous` (`kind`: `whole`, `carried`, `too_large` or `none`; `text`, as handed; `run_id`; and
225
+ for carried fields, `fields` and `dropped`, the count each carried array gave up, 0 for none). Only the eval's own server honours
226
+ `previous`, so a case with it refuses `--server`.
202
227
  - A fake MCP server's fixture, one shape for every package:
203
228
  ```json
204
229
  { "server": "github", "description": "what the fake holds",
@@ -224,6 +249,10 @@ Each `evals/<case>/` is one test of the package's agent. No eval runs on the ser
224
249
  - `mailbox`, on an `email` case: `message_id` is `in` a mailbox (or, on gmail, under a label) after the run, and in
225
250
  none of `not_in` (a list); `INBOX`, `Drafts` and `Sent` name the account's own on either layout. `in: INBOX` is
226
251
  the check that a message stayed in the inbox on both layouts: a gmail label keeps it there, a folders move does not.
252
+ - `handed`, on a `previous` case: the run was handed its trigger's last result as `expect` says (`whole`, `carried`,
253
+ `too_large` or `none`), and, with `expect: carried`, `dropped` (`{items: 192}`) is how many first entries each
254
+ named carried array gave up (0 for none); a name that is no carried array the run was handed (a typo, a scalar)
255
+ fails the grader.
227
256
 
228
257
  On an `email` case any grader may say `layouts` (`[gmail]`, `[folders]`): it grades the runs of those layouts alone,
229
258
  where a package's right behaviour differs by server (on folders, `tool_used` `email_file` `not_called`; on gmail,