@parcha/agentrun-serve 0.1.0-beta.56 → 0.1.0-beta.58

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 (312) hide show
  1. package/CHANGELOG.md +281 -0
  2. package/README.md +246 -66
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +15 -3
  5. package/dist/adapters.js +17 -6
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/api-keys.d.ts +76 -0
  9. package/dist/api-keys.js +217 -0
  10. package/dist/api-only.d.ts +15 -5
  11. package/dist/api-only.js +32 -8
  12. package/dist/box-paths.d.ts +4 -3
  13. package/dist/box-paths.js +7 -4
  14. package/dist/browser-hold.d.ts +23 -0
  15. package/dist/browser-hold.js +48 -0
  16. package/dist/browser-person.d.ts +3 -0
  17. package/dist/browser-person.js +4 -1
  18. package/dist/chatgpt-plan.d.ts +18 -8
  19. package/dist/chatgpt-plan.js +91 -34
  20. package/dist/claude-login-token.d.ts +117 -0
  21. package/dist/claude-login-token.js +737 -0
  22. package/dist/claude-login.d.ts +120 -22
  23. package/dist/claude-login.js +347 -63
  24. package/dist/claude-sign-in.d.ts +17 -6
  25. package/dist/claude-sign-in.js +42 -39
  26. package/dist/cli.js +33 -10
  27. package/dist/composio-made.d.ts +4 -0
  28. package/dist/composio-made.js +4 -0
  29. package/dist/composio-preset.d.ts +43 -2
  30. package/dist/composio-preset.js +92 -4
  31. package/dist/computer-attach.d.ts +35 -17
  32. package/dist/computer-attach.js +301 -49
  33. package/dist/computer-held-routes.d.ts +5 -4
  34. package/dist/computer-held-routes.js +29 -8
  35. package/dist/computer-held.d.ts +6 -1
  36. package/dist/computer-held.js +14 -0
  37. package/dist/computer-record.js +4 -2
  38. package/dist/computer-viewer.js +4 -1
  39. package/dist/computers.d.ts +10 -10
  40. package/dist/computers.js +5 -5
  41. package/dist/console/assets/{backend-Boh7tC4i.js → backend-CSAWUqtZ.js} +19 -19
  42. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  43. package/dist/console/assets/index-DPh29cyz.js +747 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/decisions.d.ts +1 -1
  46. package/dist/decisions.js +1 -1
  47. package/dist/dial-relay.d.ts +25 -4
  48. package/dist/dial-relay.js +129 -1
  49. package/dist/docker-host-addresses.d.ts +22 -11
  50. package/dist/docker-host-addresses.js +38 -26
  51. package/dist/env-switch.d.ts +8 -0
  52. package/dist/env-switch.js +31 -2
  53. package/dist/errors.d.ts +1 -0
  54. package/dist/errors.js +2 -0
  55. package/dist/fal-price.d.ts +56 -20
  56. package/dist/fal-price.js +400 -90
  57. package/dist/handed-values.d.ts +43 -1
  58. package/dist/handed-values.js +119 -2
  59. package/dist/harness-archive.d.ts +13 -10
  60. package/dist/harness-archive.js +60 -34
  61. package/dist/harness-check.d.ts +3 -1
  62. package/dist/harness-check.js +25 -46
  63. package/dist/harness-keys.d.ts +73 -27
  64. package/dist/harness-keys.js +194 -61
  65. package/dist/harness-recipe-entry.d.ts +8 -7
  66. package/dist/harness-recipe-entry.js +21 -32
  67. package/dist/harness-recipe.d.ts +38 -25
  68. package/dist/harness-recipe.js +49 -36
  69. package/dist/harness-sign-in.js +12 -23
  70. package/dist/harness-table.d.ts +10 -3
  71. package/dist/harness-table.js +26 -21
  72. package/dist/harness.d.ts +1 -0
  73. package/dist/harness.js +17 -5
  74. package/dist/hosted-search.d.ts +1 -1
  75. package/dist/hosted-search.js +1 -2
  76. package/dist/import-worker.d.ts +4 -2
  77. package/dist/import-worker.js +9 -2
  78. package/dist/in-flight.d.ts +26 -0
  79. package/dist/in-flight.js +52 -0
  80. package/dist/key-refusal.d.ts +9 -4
  81. package/dist/key-refusal.js +107 -25
  82. package/dist/learn/ledger.d.ts +170 -0
  83. package/dist/learn/ledger.js +218 -0
  84. package/dist/learn/promote.d.ts +3 -3
  85. package/dist/learn/promote.js +1 -1
  86. package/dist/learn/secrets.d.ts +13 -3
  87. package/dist/learn/secrets.js +118 -17
  88. package/dist/learning-cost.d.ts +28 -23
  89. package/dist/learning-cost.js +19 -23
  90. package/dist/link-check.js +1 -1
  91. package/dist/live-reach.d.ts +2 -0
  92. package/dist/live-reach.js +2 -0
  93. package/dist/llms.txt +1 -1
  94. package/dist/marketplace.d.ts +77 -0
  95. package/dist/marketplace.js +224 -0
  96. package/dist/mcp-api-only-origins.d.ts +35 -0
  97. package/dist/mcp-api-only-origins.js +57 -0
  98. package/dist/mcp-gateway.d.ts +7 -5
  99. package/dist/mcp-gateway.js +9 -12
  100. package/dist/mcp-secret-writes.js +5 -3
  101. package/dist/mcp-servers-store.d.ts +28 -6
  102. package/dist/mcp-servers-store.js +53 -4
  103. package/dist/media-duration.d.ts +3 -0
  104. package/dist/media-duration.js +90 -9
  105. package/dist/micro.d.ts +2 -0
  106. package/dist/micro.js +2 -0
  107. package/dist/model-form.d.ts +5 -4
  108. package/dist/model-form.js +11 -7
  109. package/dist/model.d.ts +10 -6
  110. package/dist/model.js +16 -11
  111. package/dist/monid.d.ts +14 -1
  112. package/dist/monid.js +103 -26
  113. package/dist/ollama-provider.d.ts +7 -1
  114. package/dist/ollama-provider.js +14 -2
  115. package/dist/openapi.js +210 -37
  116. package/dist/otel/genai.d.ts +65 -0
  117. package/dist/otel/genai.js +116 -0
  118. package/dist/otel/tracer.d.ts +55 -0
  119. package/dist/otel/tracer.js +308 -0
  120. package/dist/page.d.ts +2 -0
  121. package/dist/page.js +3 -1
  122. package/dist/paid-calls.d.ts +1 -32
  123. package/dist/paid-calls.js +4 -39
  124. package/dist/place-offers.d.ts +4 -0
  125. package/dist/place-offers.js +7 -4
  126. package/dist/provider.d.ts +11 -2
  127. package/dist/provider.js +59 -8
  128. package/dist/redact/match.d.ts +30 -3
  129. package/dist/redact/match.js +422 -41
  130. package/dist/refusal-words.d.ts +11 -0
  131. package/dist/refusal-words.js +11 -0
  132. package/dist/run-census.d.ts +67 -0
  133. package/dist/run-census.js +240 -0
  134. package/dist/run-computer.d.ts +6 -3
  135. package/dist/run-computer.js +4 -1
  136. package/dist/run-cut.d.ts +15 -6
  137. package/dist/run-cut.js +30 -9
  138. package/dist/run-files.d.ts +3 -0
  139. package/dist/run-files.js +3 -0
  140. package/dist/run-launch.d.ts +12 -1
  141. package/dist/run-launch.js +9 -10
  142. package/dist/run-learning-served.d.ts +4 -2
  143. package/dist/run-model-key.d.ts +8 -0
  144. package/dist/run-model-key.js +31 -1
  145. package/dist/run-reads-over-store.d.ts +24 -6
  146. package/dist/run-reads-over-store.js +67 -23
  147. package/dist/run-recordings.d.ts +5 -1
  148. package/dist/run-recordings.js +39 -14
  149. package/dist/run-timeline-served.d.ts +2 -0
  150. package/dist/run-timeline-served.js +2 -2
  151. package/dist/run-usage.d.ts +1 -0
  152. package/dist/run-view.d.ts +1 -2
  153. package/dist/run-view.js +2 -1
  154. package/dist/runnable.d.ts +10 -1
  155. package/dist/runnable.js +20 -8
  156. package/dist/runner/adapter-loop.d.ts +11 -0
  157. package/dist/runner/adapter-loop.js +58 -26
  158. package/dist/runner/adapter-run-spec.d.ts +55 -11
  159. package/dist/runner/adapter-run-spec.js +183 -52
  160. package/dist/runner/adapters/pi.js +25 -3
  161. package/dist/runner/beside.d.ts +9 -2
  162. package/dist/runner/beside.js +27 -9
  163. package/dist/runner/big-writes.js +1 -10
  164. package/dist/runner/claim-secrets.d.ts +27 -10
  165. package/dist/runner/claim-secrets.js +49 -22
  166. package/dist/runner/cli-run-spec.d.ts +6 -0
  167. package/dist/runner/cli-run-spec.js +97 -38
  168. package/dist/runner/computer-journal.d.ts +9 -1
  169. package/dist/runner/computer-journal.js +26 -0
  170. package/dist/runner/conformance/harness.js +1 -1
  171. package/dist/runner/feedback-round.js +3 -0
  172. package/dist/runner/harness-loops.d.ts +6 -5
  173. package/dist/runner/harness-loops.js +7 -7
  174. package/dist/runner/held.d.ts +24 -6
  175. package/dist/runner/journal-kinds.d.ts +5 -0
  176. package/dist/runner/journal-kinds.js +5 -0
  177. package/dist/runner/main.d.ts +11 -6
  178. package/dist/runner/main.js +19 -9
  179. package/dist/runner/mcp-claim.js +31 -3
  180. package/dist/runner/mcp-run.d.ts +9 -0
  181. package/dist/runner/mcp-run.js +11 -5
  182. package/dist/runner/model-route.d.ts +17 -0
  183. package/dist/runner/model-route.js +120 -2
  184. package/dist/runner/presence.d.ts +11 -1
  185. package/dist/runner/presence.js +7 -0
  186. package/dist/runner/reflect-hook.js +1 -1
  187. package/dist/runner/run-child-host.d.ts +22 -8
  188. package/dist/runner/run-child-host.js +128 -41
  189. package/dist/runner/run-child.js +5 -2
  190. package/dist/runner/runner.d.ts +17 -3
  191. package/dist/runner/runner.js +130 -34
  192. package/dist/runner/save-slots.js +2 -1
  193. package/dist/runner/store-port.d.ts +1 -1
  194. package/dist/runner/store-secrets.d.ts +6 -0
  195. package/dist/runner/store-secrets.js +49 -7
  196. package/dist/runner/subagent.d.ts +11 -0
  197. package/dist/runner/subagent.js +16 -38
  198. package/dist/runner/workflow-first.d.ts +35 -15
  199. package/dist/runner/workflow-first.js +38 -25
  200. package/dist/runner/workflow-spec.js +4 -3
  201. package/dist/runs-over-store.d.ts +15 -6
  202. package/dist/runs-over-store.js +33 -21
  203. package/dist/scrub-command.d.ts +73 -0
  204. package/dist/scrub-command.js +307 -0
  205. package/dist/secret-cut.d.ts +73 -0
  206. package/dist/secret-cut.js +291 -4
  207. package/dist/secret-rules.d.ts +143 -0
  208. package/dist/secret-rules.js +2564 -0
  209. package/dist/secrets.d.ts +7 -0
  210. package/dist/secrets.js +20 -0
  211. package/dist/server-keys.d.ts +20 -0
  212. package/dist/server-keys.js +25 -6
  213. package/dist/server.d.ts +65 -13
  214. package/dist/server.js +470 -157
  215. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  216. package/dist/slots.d.ts +9 -0
  217. package/dist/slots.js +45 -0
  218. package/dist/store/index.d.ts +1 -1
  219. package/dist/store/index.js +1 -1
  220. package/dist/store/journal/storage.js +1 -1
  221. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  222. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  223. package/dist/store/schema.d.ts +23 -0
  224. package/dist/store/schema.js +58 -2
  225. package/dist/store/seal.d.ts +6 -1
  226. package/dist/store/seal.js +5 -3
  227. package/dist/store/sqlite/run-launch.d.ts +9 -1
  228. package/dist/store/sqlite/run-launch.js +24 -13
  229. package/dist/store/sqlite/run-patch.d.ts +12 -2
  230. package/dist/store/sqlite/run-patch.js +42 -5
  231. package/dist/store/sqlite/store.js +105 -12
  232. package/dist/store/store.d.ts +57 -2
  233. package/dist/store/store.js +20 -0
  234. package/dist/store-reads/learning.d.ts +84 -124
  235. package/dist/store-reads/learning.js +210 -274
  236. package/dist/store-view.d.ts +3 -0
  237. package/dist/store-view.js +3 -3
  238. package/dist/suggestions.js +3 -2
  239. package/dist/template-eval.d.ts +39 -9
  240. package/dist/template-eval.js +191 -60
  241. package/dist/template-import.js +6 -2
  242. package/dist/templates.d.ts +10 -2
  243. package/dist/templates.js +28 -8
  244. package/dist/timeline/labels.d.ts +6 -4
  245. package/dist/timeline/labels.js +18 -6
  246. package/dist/timeline/timeline.d.ts +5 -0
  247. package/dist/timeline/timeline.js +14 -8
  248. package/dist/timeline/util.js +1 -1
  249. package/dist/timeline/web-calls.d.ts +22 -7
  250. package/dist/timeline/web-calls.js +106 -35
  251. package/dist/tool-gate.d.ts +42 -3
  252. package/dist/tool-gate.js +66 -5
  253. package/dist/tool-keys-store.d.ts +2 -4
  254. package/dist/tool-keys-store.js +5 -21
  255. package/dist/tool-keys.d.ts +2 -2
  256. package/dist/tool-keys.js +2 -2
  257. package/dist/tool-list.js +1 -1
  258. package/dist/tool-plane.d.ts +2 -2
  259. package/dist/tool-plane.js +35 -33
  260. package/dist/tools.js +13 -7
  261. package/dist/trigger-targets.d.ts +4 -0
  262. package/dist/trigger-targets.js +9 -2
  263. package/dist/triggers.d.ts +67 -4
  264. package/dist/triggers.js +171 -22
  265. package/dist/until.d.ts +3 -0
  266. package/dist/until.js +11 -0
  267. package/dist/web-fake.d.ts +1 -3
  268. package/dist/web-fake.js +7 -18
  269. package/dist/web-fetch.d.ts +6 -72
  270. package/dist/web-fetch.js +11 -265
  271. package/dist/web-run.d.ts +31 -0
  272. package/dist/web-run.js +90 -0
  273. package/dist/web-save.d.ts +10 -13
  274. package/dist/web-save.js +13 -55
  275. package/dist/web-search.d.ts +9 -127
  276. package/dist/web-search.js +23 -259
  277. package/dist/wires.d.ts +13 -0
  278. package/dist/wires.js +11 -0
  279. package/dist/workflow-run.d.ts +5 -4
  280. package/dist/workflow-run.js +5 -4
  281. package/dist/workspace/attached-computers.d.ts +32 -9
  282. package/dist/workspace/attached-computers.js +77 -13
  283. package/dist/workspace/computer-deps.d.ts +8 -2
  284. package/dist/workspace/computer-deps.js +10 -3
  285. package/dist/workspace/computer-for-claim.d.ts +12 -1
  286. package/dist/workspace/computer-for-claim.js +83 -11
  287. package/dist/workspace/computer-kept.d.ts +3 -0
  288. package/dist/workspace/computer-kept.js +11 -2
  289. package/dist/workspace/index.d.ts +1 -1
  290. package/dist/workspace/index.js +1 -1
  291. package/dist/workspace/kind-skills.d.ts +4 -0
  292. package/dist/workspace/kind-skills.js +9 -0
  293. package/dist/workspace/paired-route.d.ts +91 -0
  294. package/dist/workspace/paired-route.js +153 -0
  295. package/dist/workspace/synced-folder.js +3 -4
  296. package/dist/wrapped.d.ts +20 -6
  297. package/dist/wrapped.js +66 -25
  298. package/package.json +17 -11
  299. package/skills/agentrun-serve/SKILL.md +4 -0
  300. package/templates/README.md +32 -10
  301. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  302. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  303. package/dist/exa-keyless.d.ts +0 -34
  304. package/dist/exa-keyless.js +0 -118
  305. package/dist/firecrawl-keyless.d.ts +0 -41
  306. package/dist/firecrawl-keyless.js +0 -152
  307. package/dist/keyless-mcp.d.ts +0 -36
  308. package/dist/keyless-mcp.js +0 -127
  309. package/dist/text-urls.d.ts +0 -38
  310. package/dist/text-urls.js +0 -170
  311. package/dist/web-fetch-direct.d.ts +0 -119
  312. package/dist/web-fetch-direct.js +0 -190
@@ -1,6 +1,6 @@
1
1
  import { type Handed, type SignInReader } from "./run-view.js";
2
2
  import { type RunLaunch } from "./run-launch.js";
3
- import type { RunRow, Store } from "./store/store.js";
3
+ import { type RunRow, type Store } from "./store/store.js";
4
4
  /** The run's launch body read back, or undefined when it has none (an old run, or one not started with one). */
5
5
  export declare function launchOf(store: Pick<Store, "runs">, runId: string): Promise<RunLaunch | undefined>;
6
6
  /** The pointers a run was handed, as its row kept them (never the pointers, their SHA-256), read by the one rule a
@@ -21,9 +21,51 @@ export declare function handedValuesOf(deps: {
21
21
  }): Promise<{
22
22
  refs: string[];
23
23
  } | "unreadable">;
24
+ /** Run `runId`'s launch row as a cut reads it: its body, its sealed part (null when it holds none) and its census (null when
25
+ * no end erased a sealed part). A run with no launch row (one started before launch rows) holds neither; a read that fails
26
+ * is `unreadable`, so the run is withheld, never cut of a shorter set. */
27
+ export declare function launchRowOf(store: Pick<Store, "runs">, runId: string): Promise<{
28
+ readonly body: RunLaunch | undefined;
29
+ readonly sealed: Uint8Array | null;
30
+ readonly census: string | null;
31
+ } | "unreadable">;
32
+ /** What run `runId`'s launch holds sealed now (`sealed`: its caller's MCP credentials, its own model key and tool keys),
33
+ * opened with this server's `sealKey`: each value as the runner's own cut lists it (runner/store-secrets.ts
34
+ * launchSecrets), in every spelling the server's list has (ServerSecrets), each at least MIN_SECRET long. None when it
35
+ * holds none (none handed, or its end erased them); `unreadable` when its bytes don't open here (no seal key, another
36
+ * key, damaged): what the run was handed can't be known, so it is withheld. */
37
+ export declare function launchValuesOf(sealKey: Buffer | undefined, runId: string, sealed: Uint8Array | null): string[] | "unreadable";
38
+ /** Every value a launch's sealed JSON `plain` holds, as a cut lists them: each as the runner's own cut lists it
39
+ * (runner/store-secrets.ts launchSecrets), in every spelling the server's list has (ServerSecrets), each at least
40
+ * MIN_SECRET long. */
41
+ export declare function launchValuesIn(plain: string): string[];
42
+ /** Each value the launch secrets `before` hold (their `retired` too) that `after` no longer hold, as the runner's cut
43
+ * lists them (launchSecrets): what a message's seal keeps as `retired` (store/seal.ts RunLaunchSecrets), so a value it
44
+ * replaced mid-turn is still cut, live and in the end's census. */
45
+ export declare function retiredValues(before: object, after: object): string[];
46
+ /** The most values a launch keeps as `retired` in one turn. A message past it seals none and marks the launch `lost`
47
+ * instead (store/seal.ts RunLaunchSecrets), so the run is withheld until its end, never cut of fewer values than it held. */
48
+ export declare const RETIRED_MAX = 256;
49
+ /** The values a start or a message hands (`mcp_auth`, `model_key`, `keys`: server.ts Handed), as launchValuesIn lists
50
+ * them from the launch they are sealed in. None when it hands none. */
51
+ export declare function handedSecretValues(handed: {
52
+ readonly mcp?: unknown;
53
+ readonly model?: string;
54
+ readonly keys?: Readonly<Record<string, string>>;
55
+ }): string[];
56
+ /** `value` with every string in it cut of `values` alone (each in every form redactSecrets finds it, learn/secrets.ts
57
+ * heldSpans; a string where one still shows in another form is "[redacted]" whole), and nothing else changed: no secret
58
+ * shape is cut, no length blanks it. What the server writes of a start or a message (its input, which a run's title is
59
+ * read from, its text) is cut so of what that start or message hands, so no read after the run's end erased those
60
+ * values (when no cut holds them) shows them. Its names are left as they are. */
61
+ export declare function cutHanded<T>(value: T, values: readonly string[]): T;
24
62
  /** Why what an agent learned is withheld (403): a pointer of its sign-in can't be read here, so the cut would be shorter
25
63
  * than what a note may hold. */
26
64
  export declare const WITHHELD_LEARNING = "This server can't read the agent's browser sign-in (its seal key changed or is missing, or the sign-in is damaged), so what it learned is not shown.";
65
+ /** Why a message to a run whose launch's sealed part doesn't open here is refused (409 not_continuable, reason withheld;
66
+ * a trigger's firing skips with these words): it can't be cut of what the run was handed, and once the run's end
67
+ * erases those values, written uncut it would show them. */
68
+ export declare const WITHHELD_MESSAGE = "This server can't read back what this run was handed (its seal key changed or is missing, or what was sealed is damaged), so a message to it can't be cut of those values and was not written. Start a new run of the agent.";
27
69
  /** Every sign-in pointer agent `agentId` ever held, live and forgotten (the store keeps every forgotten one, never only
28
70
  * the newest), at each vendor that keeps one (each at least MIN_SECRET long, as every cut takes them): what the learning
29
71
  * routes cut beside the server's secrets, so a note, a skill or a run's learning that wrote one never shows it. `unreadable` when one does not open under this server's key, or a read
@@ -2,10 +2,17 @@
2
2
  // mark (the SHA-256 of each pointer, never the pointer), the browser vendor its launch's plane kept, and the agent's
3
3
  // sign-ins (live and forgotten) opened to find each pointer the mark names (run-view.ts handedPointers). One read for
4
4
  // every place that must cut a run of what it was handed: the store-backed run view (store-view.ts) and the runner's
5
- // learning end (runner/learning-end.ts), which refuses to learn it.
6
- import { MIN_SECRET } from "./learn/secrets.js";
5
+ // learning end (runner/learning-end.ts), which refuses to learn it. Beside them, what the run's caller handed it at its
6
+ // launch or with a message (its MCP credentials, its own model key and tool keys: store/seal.ts RunLaunchSecrets), opened
7
+ // from the launch's sealed part while the run holds it (launchValuesOf), and once its end erased that, where in its files
8
+ // they sat (the launch's census, run-census.ts).
9
+ import { heldSpans, MIN_SECRET } from "./learn/secrets.js";
10
+ import { launchSecrets } from "./runner/store-secrets.js";
11
+ import { ServerSecrets } from "./server-secrets.js";
12
+ import { sealedAt, unsealColumn } from "./store/seal.js";
7
13
  import { handedMark, handedPointers } from "./run-view.js";
8
14
  import { readLaunchBody } from "./run-launch.js";
15
+ import { StoreLaunchMissing } from "./store/store.js";
9
16
  import { keptVendor } from "./tool-plane.js";
10
17
  /** The run's launch body read back, or undefined when it has none (an old run, or one not started with one). */
11
18
  export async function launchOf(store, runId) {
@@ -35,11 +42,121 @@ export async function handedValuesOf(deps, store, runId, known) {
35
42
  const browser = launch?.plane ? keptVendor(launch.plane).browser : undefined;
36
43
  return handedPointers(deps.signIns, runRow.agentId, browser, handedOf(runRow));
37
44
  }
45
+ /** Run `runId`'s launch row as a cut reads it: its body, its sealed part (null when it holds none) and its census (null when
46
+ * no end erased a sealed part). A run with no launch row (one started before launch rows) holds neither; a read that fails
47
+ * is `unreadable`, so the run is withheld, never cut of a shorter set. */
48
+ export async function launchRowOf(store, runId) {
49
+ try {
50
+ const row = await store.runs.launch(runId);
51
+ let body;
52
+ try {
53
+ body = readLaunchBody(row.body);
54
+ }
55
+ catch {
56
+ body = undefined;
57
+ }
58
+ return { body, sealed: row.sealed, census: row.census };
59
+ }
60
+ catch (error) {
61
+ return error instanceof StoreLaunchMissing ? { body: undefined, sealed: null, census: null } : "unreadable";
62
+ }
63
+ }
64
+ /** What run `runId`'s launch holds sealed now (`sealed`: its caller's MCP credentials, its own model key and tool keys),
65
+ * opened with this server's `sealKey`: each value as the runner's own cut lists it (runner/store-secrets.ts
66
+ * launchSecrets), in every spelling the server's list has (ServerSecrets), each at least MIN_SECRET long. None when it
67
+ * holds none (none handed, or its end erased them); `unreadable` when its bytes don't open here (no seal key, another
68
+ * key, damaged): what the run was handed can't be known, so it is withheld. */
69
+ export function launchValuesOf(sealKey, runId, sealed) {
70
+ if (sealed === null)
71
+ return [];
72
+ if (!sealKey)
73
+ return "unreadable";
74
+ let plain;
75
+ try {
76
+ plain = unsealColumn(sealKey, sealedAt.runLaunch(runId), sealed).toString("utf8");
77
+ }
78
+ catch {
79
+ return "unreadable";
80
+ }
81
+ // A message sealed over bytes that did not open here (store/seal.ts RunLaunchSecrets.lost): what they held is unknown.
82
+ if (lostIn(plain))
83
+ return "unreadable";
84
+ return launchValuesIn(plain);
85
+ }
86
+ /** Whether a launch's sealed JSON `plain` says a message sealed over bytes that did not open (RunLaunchSecrets.lost). */
87
+ function lostIn(plain) {
88
+ try {
89
+ return JSON.parse(plain)?.lost === true;
90
+ }
91
+ catch {
92
+ return false;
93
+ }
94
+ }
95
+ /** Every value a launch's sealed JSON `plain` holds, as a cut lists them: each as the runner's own cut lists it
96
+ * (runner/store-secrets.ts launchSecrets), in every spelling the server's list has (ServerSecrets), each at least
97
+ * MIN_SECRET long. */
98
+ export function launchValuesIn(plain) {
99
+ const list = new ServerSecrets();
100
+ list.add("handed", () => (plain.trimStart().startsWith("{") ? launchSecrets(plain) : [plain]));
101
+ return list.values().filter((value) => value.length >= MIN_SECRET);
102
+ }
103
+ /** Each value the launch secrets `before` hold (their `retired` too) that `after` no longer hold, as the runner's cut
104
+ * lists them (launchSecrets): what a message's seal keeps as `retired` (store/seal.ts RunLaunchSecrets), so a value it
105
+ * replaced mid-turn is still cut, live and in the end's census. */
106
+ export function retiredValues(before, after) {
107
+ const kept = new Set(launchSecrets(JSON.stringify(after)));
108
+ return [...new Set(launchSecrets(JSON.stringify(before)).filter((value) => !kept.has(value)))];
109
+ }
110
+ /** The most values a launch keeps as `retired` in one turn. A message past it seals none and marks the launch `lost`
111
+ * instead (store/seal.ts RunLaunchSecrets), so the run is withheld until its end, never cut of fewer values than it held. */
112
+ export const RETIRED_MAX = 256;
113
+ /** The values a start or a message hands (`mcp_auth`, `model_key`, `keys`: server.ts Handed), as launchValuesIn lists
114
+ * them from the launch they are sealed in. None when it hands none. */
115
+ export function handedSecretValues(handed) {
116
+ if (handed.mcp === undefined && handed.model === undefined && handed.keys === undefined)
117
+ return [];
118
+ return launchValuesIn(JSON.stringify({ ...(handed.mcp !== undefined ? { mcp: handed.mcp } : {}), ...(handed.model !== undefined ? { model: { key: handed.model } } : {}), ...(handed.keys !== undefined ? { keys: handed.keys } : {}) }));
119
+ }
120
+ /** `value` with every string in it cut of `values` alone (each in every form redactSecrets finds it, learn/secrets.ts
121
+ * heldSpans; a string where one still shows in another form is "[redacted]" whole), and nothing else changed: no secret
122
+ * shape is cut, no length blanks it. What the server writes of a start or a message (its input, which a run's title is
123
+ * read from, its text) is cut so of what that start or message hands, so no read after the run's end erased those
124
+ * values (when no cut holds them) shows them. Its names are left as they are. */
125
+ export function cutHanded(value, values) {
126
+ if (!values.length)
127
+ return value;
128
+ const cutText = (text) => {
129
+ const spans = heldSpans(text, values);
130
+ if (spans === "whole")
131
+ return "[redacted]";
132
+ let out = "";
133
+ let from = 0;
134
+ for (const [start, end] of spans) {
135
+ out += `${text.slice(from, start)}[redacted]`;
136
+ from = end;
137
+ }
138
+ return out + text.slice(from);
139
+ };
140
+ const walk = (one) => {
141
+ if (typeof one === "string")
142
+ return cutText(one);
143
+ if (Array.isArray(one))
144
+ return one.map(walk);
145
+ if (one !== null && typeof one === "object")
146
+ return Object.fromEntries(Object.entries(one).map(([name, inner]) => [name, walk(inner)]));
147
+ return one;
148
+ };
149
+ return walk(value);
150
+ }
38
151
  /** The browser vendors that keep a sign-in (sign-ins-store.ts vendorOf). */
39
152
  const SIGN_IN_VENDORS = ["browserbase", "kernel"];
40
153
  /** Why what an agent learned is withheld (403): a pointer of its sign-in can't be read here, so the cut would be shorter
41
154
  * than what a note may hold. */
42
155
  export const WITHHELD_LEARNING = "This server can't read the agent's browser sign-in (its seal key changed or is missing, or the sign-in is damaged), so what it learned is not shown.";
156
+ /** Why a message to a run whose launch's sealed part doesn't open here is refused (409 not_continuable, reason withheld;
157
+ * a trigger's firing skips with these words): it can't be cut of what the run was handed, and once the run's end
158
+ * erases those values, written uncut it would show them. */
159
+ export const WITHHELD_MESSAGE = "This server can't read back what this run was handed (its seal key changed or is missing, or what was sealed is damaged), so a message to it can't be cut of those values and was not written. Start a new run of the agent.";
43
160
  /** Every sign-in pointer agent `agentId` ever held, live and forgotten (the store keeps every forgotten one, never only
44
161
  * the newest), at each vendor that keeps one (each at least MIN_SECRET long, as every cut takes them): what the learning
45
162
  * routes cut beside the server's secrets, so a note, a skill or a run's learning that wrote one never shows it. `unreadable` when one does not open under this server's key, or a read
@@ -56,6 +56,14 @@ export declare const ARCHIVE_TIMEOUT_MS: number;
56
56
  export declare function archivePlatform(platform?: string, arch?: string): string | undefined;
57
57
  /** The sha256 of the file at `path`, read a chunk at a time. */
58
58
  export declare function digestOf(path: string): Promise<string>;
59
+ /** The first link under `root` (its path from `root`) that leads outside `root`, or to nothing; undefined when none does.
60
+ * The tree digest holds a link by its words, never the bytes it leads to, so a file reached through one (the binary
61
+ * behind a linked folder, code a launcher loads from `lib` linked elsewhere) would be checked by nothing. Each link is
62
+ * resolved by the filesystem (realpath), as opening it would be, never by its words alone: in a chain such as
63
+ * `sub/up -> ..` and `sub/code -> up/../outside`, the `..` is taken after the link before it is followed, so the words
64
+ * read inside while the path leads out. A link that leads to nothing is refused too, since what its last step names
65
+ * could be made outside later. */
66
+ export declare function linkOutOf(root: string): Promise<string | undefined>;
59
67
  export interface ArchiveInstallOptions {
60
68
  /** The platform, as the registry names it. Default this host's (archivePlatform). */
61
69
  platform?: string;
@@ -69,16 +77,11 @@ export interface ArchiveInstallOptions {
69
77
  maxBytes?: number;
70
78
  /** Hears each step once it holds: `downloaded` (and its digest checked), `unpacked`, `verified` (the binary's digest). */
71
79
  onStep?: (step: "downloaded" | "unpacked" | "verified") => void | Promise<void>;
72
- /** For a release whose binary has no sha256 pinned (a recipe's, where the registry lists only the archive's): the record
73
- * of the first one unpacked from its verified archive. With none recorded, this install records its binary's; with one,
74
- * a binary that differs is refused (HARNESS_BINARY_MISMATCH). Without it, such a release is refused. */
75
- binaryRecord?: {
76
- read(): string | undefined;
77
- write(sha256: string): void;
78
- };
79
- /** For a release with no tree digest pinned (a recipe's): the record of the first tree (every file beside the binary,
80
- * harness.tree's digest) unpacked from its verified archive, kept as binaryRecord keeps the binary's, so a sidecar
81
- * that differs is refused (HARNESS_BINARY_MISMATCH) as the binary is. Needs harness.tree. */
80
+ /** For a release with no tree digest pinned (a recipe's, where the registry lists only the archive's): the record of the
81
+ * first tree (every file it unpacks to, the binary among them: harness.tree's digest) unpacked from its verified
82
+ * archive. With none recorded, this install records its tree's; with one, a tree that differs (a binary or a sidecar)
83
+ * is refused (HARNESS_BINARY_MISMATCH). Needs harness.tree. A release that pins neither its binary nor its tree, with
84
+ * no record, is refused. */
82
85
  treeRecord?: {
83
86
  read(): string | undefined;
84
87
  write(sha256: string): void;
@@ -10,8 +10,8 @@
10
10
  // repository carries none. A zip (Google Antigravity's) is unpacked by node itself (harness-zip.ts), no tool needed;
11
11
  // - the binary's sha256 is checked there against the pin, and where the pin holds one the digest of every file beside
12
12
  // it (Cursor's launcher runs its own node on a hundred files of code; Antigravity's server runs a sidecar), and only
13
- // then is the folder renamed into place and made read-only. A recipe's release pins neither: the first binary and
14
- // tree unpacked from its verified archive are recorded, and a later install that differs is refused. What was there
13
+ // then is the folder renamed into place and made read-only. A recipe's release may pin neither: the first tree
14
+ // unpacked from its verified archive (the binary among it) is recorded, and a later install that differs is refused. What was there
15
15
  // before goes aside first, then away;
16
16
  // - a crash part way leaves that fresh folder (its name the sweep's) and never a half install: the next install removes it.
17
17
  // One install at a time on a data directory, under the hold first-use installs take (takeHold). The installer is handed no
@@ -19,8 +19,8 @@
19
19
  import { createHash } from "node:crypto";
20
20
  import { execFile } from "node:child_process";
21
21
  import { createReadStream, createWriteStream, existsSync } from "node:fs";
22
- import { lstat, mkdir, mkdtemp, rename } from "node:fs/promises";
23
- import { dirname, join, relative, resolve, sep } from "node:path";
22
+ import { lstat, mkdir, mkdtemp, readdir, realpath, rename } from "node:fs/promises";
23
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
24
24
  import { Readable, Transform } from "node:stream";
25
25
  import { pipeline } from "node:stream/promises";
26
26
  import { leftoverPrefix, releaseHold, removeLeftover, sweepLeftovers, takeHold, writable } from "./harness-install.js";
@@ -76,6 +76,35 @@ function binaryUnder(root, cmd) {
76
76
  const inside = relative(root, path);
77
77
  return inside && inside !== ".." && !inside.startsWith(`..${sep}`) ? path : undefined;
78
78
  }
79
+ /** The first link under `root` (its path from `root`) that leads outside `root`, or to nothing; undefined when none does.
80
+ * The tree digest holds a link by its words, never the bytes it leads to, so a file reached through one (the binary
81
+ * behind a linked folder, code a launcher loads from `lib` linked elsewhere) would be checked by nothing. Each link is
82
+ * resolved by the filesystem (realpath), as opening it would be, never by its words alone: in a chain such as
83
+ * `sub/up -> ..` and `sub/code -> up/../outside`, the `..` is taken after the link before it is followed, so the words
84
+ * read inside while the path leads out. A link that leads to nothing is refused too, since what its last step names
85
+ * could be made outside later. */
86
+ export async function linkOutOf(root) {
87
+ const base = await realpath(resolve(root));
88
+ const within = (path) => path === base || path.startsWith(`${base}${sep}`);
89
+ const walk = async (dir) => {
90
+ for (const name of await readdir(dir)) {
91
+ const path = join(dir, name);
92
+ const entry = await lstat(path);
93
+ if (entry.isSymbolicLink()) {
94
+ const target = await realpath(path).catch(() => undefined);
95
+ if (target === undefined || !within(target))
96
+ return relative(base, path);
97
+ }
98
+ else if (entry.isDirectory()) {
99
+ const found = await walk(path);
100
+ if (found !== undefined)
101
+ return found;
102
+ }
103
+ }
104
+ return undefined;
105
+ };
106
+ return walk(base);
107
+ }
79
108
  /** Installs `harness` into `dir` (`<data>/harnesses/<id>`) from its pin's archive for this platform: downloaded, checked,
80
109
  * unpacked beside `dir`, its binary checked, then renamed into place and made read-only. `already` when the pinned binary
81
110
  * is in place (nothing is downloaded); `now` once this install put it there. Rejects with ArchiveInstallFailed, `dir` as it
@@ -92,27 +121,29 @@ export async function installArchive(harness, dir, options = {}) {
92
121
  const want = release.sha256 ?? release.sha512;
93
122
  if (!want)
94
123
  throw fail(ARCHIVE_CODES.platform, `${named}'s archive on ${platform} has no sha256 or sha512 pinned, so it cannot be checked`);
95
- if (!release.binarySha256 && !options.binaryRecord)
96
- throw fail(ARCHIVE_CODES.platform, `${named}'s binary on ${platform} has no sha256 pinned, so what its archive unpacks to cannot be checked`);
97
124
  const flag = UNPACK[release.format];
98
125
  if (!flag || !Object.hasOwn(UNPACK, release.format))
99
126
  throw fail(ARCHIVE_CODES.platform, `${named}'s archive on ${platform} is ${release.format}, and this installer unpacks ${ARCHIVE_FORMATS.slice(0, -1).join(", ")} and ${ARCHIVE_FORMATS.at(-1)} alone`);
100
127
  const treeRecord = release.treeSha256 ? undefined : options.treeRecord;
128
+ if (!release.binarySha256 && !release.treeSha256 && !treeRecord)
129
+ throw fail(ARCHIVE_CODES.platform, `${named}'s binary on ${platform} has no sha256 pinned, so what its archive unpacks to cannot be checked`);
101
130
  if ((release.treeSha256 || treeRecord) && !harness.tree)
102
131
  throw fail(ARCHIVE_CODES.platform, `${named}'s files on ${platform} are ${release.treeSha256 ? "pinned" : "recorded"} by a tree digest, and this install was given no way to take one`);
103
132
  const binary = binaryUnder(dir, release.cmd);
104
133
  if (!binary)
105
134
  throw fail(ARCHIVE_CODES.platform, `${named}'s pinned path ${release.cmd} is not inside its folder`);
106
- // The pin's digests, else the first ones recorded (none before the first install).
107
- const pinned = release.binarySha256 ?? options.binaryRecord?.read();
135
+ // The pin's digests, else the first tree recorded (none before the first install).
136
+ const pinned = release.binarySha256;
108
137
  const pinnedTree = release.treeSha256 ?? treeRecord?.read();
109
- /** Whether the pinned binary is in place: a file whose sha256 is the pin's, in a folder whose tree is the pin's (or the
110
- * one recorded) where it pins or records one. A recipe's install from before trees were recorded is not: it is
111
- * installed again, and its tree recorded. */
112
- const inPlace = async () => pinned !== undefined &&
113
- (!treeRecord || pinnedTree !== undefined) &&
138
+ /** Whether the pinned install is in place: a binary there, its sha256 the pin's where it pins one, in a folder whose
139
+ * tree is the pin's (or the one recorded) where it pins or records one. One whose tree is to be recorded and is not
140
+ * yet (a recipe's install from before trees were recorded) is installed again, and its tree recorded. */
141
+ const inPlace = async () => (!treeRecord || pinnedTree !== undefined) &&
114
142
  (await lstat(binary).catch(() => undefined)) !== undefined &&
115
- (await digestOf(binary).catch(() => undefined)) === pinned &&
143
+ // One placed before links out were refused is installed again, where the unpack's own check says why, never
144
+ // "already" (which every start would then refuse).
145
+ (await linkOutOf(dir).catch(() => "unreadable")) === undefined &&
146
+ (pinned === undefined || (await digestOf(binary).catch(() => undefined)) === pinned) &&
116
147
  (pinnedTree === undefined || (await harness.tree(dir).catch(() => undefined)) === pinnedTree);
117
148
  if (await inPlace())
118
149
  return { installed: "already", binary };
@@ -163,8 +194,10 @@ export async function installArchive(harness, dir, options = {}) {
163
194
  if (got !== want)
164
195
  throw fail(ARCHIVE_CODES.archive, `${named}'s archive from ${release.url} has ${algorithm} ${got}, and the pin is ${want}; it was not unpacked`);
165
196
  await options.onStep?.("downloaded");
166
- // Unpacked, verified archive only, into a folder of its own inside the fresh one: a zip by node, a tarball by tar.
167
- const tree = join(work, "tree");
197
+ // Unpacked, verified archive only, into a folder of its own inside the fresh one: a zip by node, a tarball by tar. It
198
+ // takes the name the install's folder has, so a link is read (linkOutOf) where it leads once renamed into place: a
199
+ // link `a -> ../tree/b` would lead inside a folder named tree and outside the installed one.
200
+ const tree = join(work, basename(dir));
168
201
  await mkdir(tree);
169
202
  if (release.format === "zip") {
170
203
  try {
@@ -191,25 +224,18 @@ export async function installArchive(harness, dir, options = {}) {
191
224
  const found = await lstat(unpacked).catch(() => undefined);
192
225
  if (!found?.isFile())
193
226
  throw fail(ARCHIVE_CODES.unpack, `${named}'s archive holds no file at ${release.cmd}`);
194
- const binarySha = await digestOf(unpacked);
195
- if (pinned === undefined) {
196
- // The first binary unpacked from the verified archive: recorded, so a later one that differs is refused. A record
197
- // another install wrote first holds.
198
- try {
199
- options.binaryRecord.write(binarySha);
200
- }
201
- catch (error) {
202
- if (error?.code !== "EEXIST")
203
- throw error;
204
- const first = options.binaryRecord.read();
205
- if (first !== binarySha)
206
- throw fail(ARCHIVE_CODES.binary, `${named}'s binary from its archive has sha256 ${binarySha}, and the first one recorded is ${first}; it was not put in place`);
207
- }
227
+ // A link out of the tree anywhere in it (on the binary's path, or to code the binary loads): refused (linkOutOf).
228
+ const outward = await linkOutOf(tree);
229
+ if (outward !== undefined)
230
+ throw fail(ARCHIVE_CODES.unpack, `${named}'s archive holds a link out of its files (${outward}), so what it leads to would be checked by nothing; it was not put in place`);
231
+ if (pinned !== undefined) {
232
+ const binarySha = await digestOf(unpacked);
233
+ if (binarySha !== pinned)
234
+ throw fail(ARCHIVE_CODES.binary, `${named}'s binary from its archive has sha256 ${binarySha}, and the pin is ${pinned}; it was not put in place`);
208
235
  }
209
- else if (binarySha !== pinned)
210
- throw fail(ARCHIVE_CODES.binary, `${named}'s binary from its archive has sha256 ${binarySha}, and the ${release.binarySha256 ? "pin" : "first one recorded"} is ${pinned}; it was not put in place`);
211
- // Every file beside it, where the pin holds their digest or a record keeps the first: a launcher's code, or a server's
212
- // sidecar, is as much the harness as the binary.
236
+ // Every file it unpacked to, where the pin holds their digest or a record keeps the first (a record another install
237
+ // wrote first holds): a launcher's code, or a server's sidecar, is as much the harness as the binary, which is among
238
+ // them.
213
239
  if (release.treeSha256 || treeRecord) {
214
240
  const treeSha = await harness.tree(tree);
215
241
  let first = pinnedTree;
@@ -38,9 +38,11 @@ export interface HarnessCheckReport {
38
38
  };
39
39
  platform?: string;
40
40
  model?: string;
41
+ /** The installed binary, and the tree digest it and every file beside it were held to: the recipe's or the first one
42
+ * its install recorded. */
41
43
  binary?: {
42
44
  path: string;
43
- sha256: string;
45
+ tree: string;
44
46
  pinnedBy: "recipe" | "first-seen";
45
47
  };
46
48
  stage2?: Record<string, Check>;
@@ -15,17 +15,15 @@
15
15
  // The check spends: four short turns on the run's model, under a cap (default $0.25).
16
16
  import { spawnSync } from "node:child_process";
17
17
  import { randomBytes } from "node:crypto";
18
- import { existsSync, readFileSync } from "node:fs";
18
+ import { readFileSync } from "node:fs";
19
19
  import { mkdtemp, rm, writeFile } from "node:fs/promises";
20
20
  import { tmpdir } from "node:os";
21
21
  import { join } from "node:path";
22
22
  import { modelPortFor, SessionFenced } from "@parcha/agentrun-kernel";
23
23
  import { beforeRequestOf } from "@parcha/agentrun-kernel/kernel/cap";
24
- import { ACP_PACKAGE, acpPackage } from "./acp-package.js";
25
- import { ARCHIVE_CODES, archivePlatform, digestOf } from "./harness-archive.js";
24
+ import { archivePlatform } from "./harness-archive.js";
26
25
  import { egressProxy, egressVars } from "./harness-egress.js";
27
- import { installDirOf } from "./harness-install.js";
28
- import { AGENT_VARS, loadRecipe, pinnedDigest, pinnedTree, recipeBinaryOf, recipeInstallLine, RecipeRefused, releaseFor, writeChecked } from "./harness-recipe.js";
26
+ import { AGENT_VARS, installHolds, loadRecipe, recipeInstall, RecipeRefused, writeChecked } from "./harness-recipe.js";
29
27
  import { recipeEntryOf } from "./harness-recipe-entry.js";
30
28
  import { providerModels } from "./model.js";
31
29
  import { capModelOf } from "./runner/cli-run-spec.js";
@@ -160,34 +158,17 @@ async function checkRun(options, held) {
160
158
  // A check never runs on its owner's own sign-in, which a schedule, a check and a shared server never take
161
159
  // (HARNESS.md#sign-in): a plan-billed recipe whose key is not set here is refused before its agent starts.
162
160
  const route = { on: "keys" };
163
- // Stage 2's pins: the installed binary, the one the owner's install put there. Nothing is downloaded here.
164
- const platform = options.platform ?? archivePlatform();
165
- const release = releaseFor(recipe, platform);
166
- if (!platform || !release)
167
- return refuse("HARNESS_PLATFORM_UNSUPPORTED", `${recipe.label} ${recipe.release.version} has no release for ${platform ?? `${process.platform}-${process.arch}`}`);
168
- const binary = recipeBinaryOf(options.data, recipe, release);
169
- const line = recipeInstallLine(loaded.file, options.data, options.env);
170
- const pin = pinnedDigest(options.data, recipe, release, platform);
171
- if (!existsSync(binary) || !pin)
172
- return refuse("HARNESS_NOT_INSTALLED", `${recipe.label} ${recipe.release.version} is not installed in ${installDirOf(options.data, recipe.id)}; a check never downloads it. Install it with: ${line}`);
173
- const found = await digestOf(binary).catch(() => undefined);
174
- if (found !== pin.sha256)
175
- return refuse(ARCHIVE_CODES.binary, `${binary} has sha256 ${found ?? "(unreadable)"}, and ${pin.by === "recipe" ? "the recipe pins" : "its first install recorded"} ${pin.sha256}. Install it again with: ${line}`);
176
- say(`${recipe.label}: the binary is the pinned one (${pin.by === "recipe" ? "the recipe's sha256" : "the first sha256 its install recorded"})`);
177
- const acp = acpPackage();
178
- if (!acp)
179
- return refuse("HARNESS_NOT_INSTALLED", `the ACP adapter (${ACP_PACKAGE}) is not installed beside this server`);
180
- // Every file beside the binary (a launcher's code, a server's sidecar): the recipe's treeSha256, else the tree its
181
- // install recorded. One installed before trees were recorded is installed again, so nothing in it runs unpinned.
182
- const installed = installDirOf(options.data, recipe.id);
183
- const treePin = pinnedTree(options.data, recipe, release, platform);
184
- if (!treePin)
185
- return refuse("HARNESS_NOT_INSTALLED", `${recipe.label} ${recipe.release.version}'s files beside its binary were never recorded by its install, so they cannot be checked. Install it again with: ${line}`);
186
- const treeNow = async () => acp.treeDigest(installed).catch(() => undefined);
187
- const treeFound = await treeNow();
188
- if (treeFound !== treePin.sha256)
189
- return refuse(ARCHIVE_CODES.binary, `${installed} has the tree sha256 ${treeFound ?? "(unreadable)"}, and ${treePin.by === "recipe" ? "the recipe pins" : "its first install recorded"} ${treePin.sha256}. Install it again with: ${line}`);
190
- say(`${recipe.label}: every file beside the binary is the pinned tree (${treePin.by === "recipe" ? "the recipe's treeSha256" : "the tree its install recorded"})`);
161
+ // Stage 2's pins: every file the owner's install put there, the binary among them, the recipe's treeSha256 or the tree
162
+ // its install recorded (recipeInstall). Nothing is downloaded here; one installed before trees were recorded is
163
+ // installed again, so nothing in it runs unpinned.
164
+ const install = recipeInstall(options.data, recipe, loaded.file, options.env, options.platform ?? archivePlatform());
165
+ if ("code" in install)
166
+ return refuse(install.code, install.message);
167
+ const { platform, release, binary } = install;
168
+ const off = await installHolds(install);
169
+ if (off)
170
+ return refuse(off.code, off.message);
171
+ say(`${recipe.label}: the binary and every file beside it are the pinned tree (${install.tree.by === "recipe" ? "the recipe's treeSha256" : "the tree its install recorded"})`);
191
172
  // The run's model, for a recipe billed through the proxy: named here; its key, the login refusal and its price are its
192
173
  // entry's (below), as a server's are.
193
174
  const env = options.env;
@@ -248,16 +229,14 @@ async function checkRun(options, held) {
248
229
  const modelVar = recipe.model.billing === "proxy" ? recipe.model.env : undefined;
249
230
  // The plan's model, where the recipe names one: chosen among those the agent lists (session/set_model).
250
231
  const planModel = recipe.model.billing === "plan" ? recipe.model.id : undefined;
251
- const starts = [];
252
- // Each start of the agent's process checks the pin again: a binary swapped after the check began never runs.
232
+ // Each start of the agent's process checks the pin again (installHolds): a binary or a file beside it swapped after the
233
+ // check began never runs. `starts`: the starts that held.
234
+ let starts = 0;
253
235
  const beforeStart = async (command) => {
254
- const now = await digestOf(command);
255
- starts.push(now);
256
- if (now !== pin.sha256)
257
- throw new Error(`${ARCHIVE_CODES.binary}: ${command} changed after the check began (sha256 ${now})`);
258
- const tree = await treeNow();
259
- if (tree !== treePin.sha256)
260
- throw new Error(`${ARCHIVE_CODES.binary}: the files beside ${command} changed after the check began (tree sha256 ${tree ?? "(unreadable)"})`);
236
+ const off = await installHolds(install);
237
+ if (off)
238
+ throw new Error(`${off.code}: ${command} or a file beside it changed after the check began: ${off.message}`);
239
+ starts += 1;
261
240
  };
262
241
  // The recipe's entry as a server builds it (harness-recipe-entry.ts), on this check's route, log, variables (its egress
263
242
  // proxy) and recording fetch.
@@ -390,7 +369,7 @@ async function checkRun(options, held) {
390
369
  stage2.limits = { ok: true, billing: "plan", maxTurns: recipe.model.maxTurns, maxToolCalls: recipe.model.maxToolCalls, why: "the adapter stops the run at these; the vendor bills the owner's plan" };
391
370
  await other.session.close();
392
371
  // Stage 2: the pin held at every start; no side request.
393
- stage2.pins = { ok: starts.length > 0 && starts.every((sha) => sha === pin.sha256), binary, sha256: pin.sha256, pinnedBy: pin.by, archiveSha256: release.sha256, starts: starts.length };
372
+ stage2.pins = { ok: starts > 0, binary, tree: install.tree.sha256, pinnedBy: install.tree.by, archiveSha256: release.sha256, starts };
394
373
  if (recipe.model.billing === "proxy") {
395
374
  const paths = [...new Set(forwarded.map((r) => `${r.method} ${r.path}`))];
396
375
  // What the agent asked the proxy for beyond the Messages route: refused there, never sent on.
@@ -420,15 +399,15 @@ async function checkRun(options, held) {
420
399
  if (!(name in stage3) && !failures.some((f) => f.startsWith("the check stopped")))
421
400
  failures.push(`stage3.${name} did not run`);
422
401
  // A pass is noted on the data directory, by digest, for a server that names the recipe (harness-recipe-entry.ts
423
- // recipeServerEntry): it runs this recipe, binary and tree, and no other.
402
+ // recipeServerEntry): it runs this recipe and this install's tree, and no other.
424
403
  if (failures.length === 0)
425
- writeChecked(options.data, recipe.id, { recipe: loaded.sha256, binary: pin.sha256, tree: treePin.sha256, version: recipe.release.version, platform });
404
+ writeChecked(options.data, recipe.id, { recipe: loaded.sha256, tree: install.tree.sha256, platform });
426
405
  return {
427
406
  ok: failures.length === 0,
428
407
  ...head,
429
408
  platform,
430
409
  ...(options.model ? { model: options.model } : {}),
431
- binary: { path: binary, sha256: pin.sha256, pinnedBy: pin.by },
410
+ binary: { path: binary, tree: install.tree.sha256, pinnedBy: install.tree.by },
432
411
  stage2,
433
412
  stage3,
434
413
  facts: { resume: resumeFact, tool_gate: asked().length > 0 ? "permission" : "config", billing: recipe.model.billing },