@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,28 +1,41 @@
1
+ import { HARNESS_KEY_REENTER } from "./server-keys.js";
1
2
  import type { PlanRecipe } from "./harness-table.js";
2
3
  import { type SecretMeta } from "./secret-writes.js";
3
- import { type SealedKeys } from "./store/index.js";
4
+ import { type SealedKeys, type Settings } from "./store/index.js";
4
5
  /** The console's page for these keys (Settings → Harness keys). */
5
6
  export declare const HARNESS_KEYS_PAGE = "/#/settings/harness-keys";
6
7
  /** The plane of a harness key's name (its row's, and its view's: harness:<harness>:<KEY>). */
7
8
  export declare const HARNESS_KEY_PLANE = "harness";
8
9
  /** How many replaced or removed values of one key stay sealed for the cut: the oldest beyond it leaves. */
9
10
  export declare const RETIRED_KEPT = 8;
11
+ /** The settings row each current key row's binding is kept in: { v: 1, rows: { <row>: { seal, recipe, sealed } } }, `seal`
12
+ * the fingerprint of the seal key it was sealed under (server-keys.ts sealFingerprint), `recipe` the sha256 of the recipe
13
+ * file it was saved for (PlanRecipe.digest), `sealed` the sha256 of the sealed bytes written with it (sealedDigest). */
14
+ export declare const HARNESS_KEY_BINDS = "harness-keys";
10
15
  /** The row (and view) name of `key` saved for `harness`. */
11
16
  export declare const harnessKeyRow: (harness: string, key: string) => string;
17
+ export { HARNESS_KEY_REENTER };
18
+ export type HarnessKeyWhy = (typeof HARNESS_KEY_REENTER)[number];
12
19
  type HarnessKeysStore = {
13
20
  readonly sealedKeys: Pick<SealedKeys, "all" | "get" | "put" | "remove">;
21
+ readonly settings: Pick<Settings, "get" | "put">;
14
22
  flush(): Promise<void>;
15
23
  };
16
- /** The keys of `names` saved for `harness` that open under `sealKey`, by name. One that does not open (another seal key, or
17
- * damaged) reads as not saved, never a clear fallback. For a runner's claim, whose run is on that harness. */
24
+ /** The recipe a claim's keys are opened for: its id, the keys it runs on, and its file's digest they must be bound to. */
25
+ type RecipeBound = Pick<PlanRecipe, "id" | "keys" | "digest">;
26
+ /** The keys `recipe` runs on that are saved for it (bound to its digest) and open under `sealKey`, by name. One saved for
27
+ * another recipe file of its id, or that does not open (another seal key, or damaged), reads as not saved, never a clear
28
+ * fallback. For a runner's claim, whose run is on that recipe. */
18
29
  export declare function openHarnessKeys(store: {
19
- sealedKeys: Pick<SealedKeys, "get">;
20
- }, sealKey: Buffer, harness: string, names: readonly string[]): Promise<Record<string, string>>;
21
- /** Whether every key of `names` has a row saved for `harness` (its bytes never opened): a trigger's check, and a runner's
22
- * claim before it opens them. */
30
+ readonly sealedKeys: Pick<SealedKeys, "get">;
31
+ readonly settings: Pick<Settings, "get">;
32
+ }, sealKey: Buffer, recipe: RecipeBound): Promise<Record<string, string>>;
33
+ /** Whether every key `recipe` runs on has a row saved for it, bound to its digest (its bytes never opened): a trigger's
34
+ * check, and a runner's claim before it opens them. */
23
35
  export declare function harnessKeysSaved(store: {
24
- sealedKeys: Pick<SealedKeys, "all">;
25
- }, harness: string, names: readonly string[]): Promise<boolean>;
36
+ readonly sealedKeys: Pick<SealedKeys, "all">;
37
+ readonly settings: Pick<Settings, "get">;
38
+ }, recipe: RecipeBound): Promise<boolean>;
26
39
  /** Whether a claim laid every key of `names` on `env` (layHarnessKeys: own, never enumerable, not empty), which is when
27
40
  * a start takes the keys route (harness-recipe-entry.ts serverRoute). A variable of the same name the environment
28
41
  * carries enumerable (one the operator's shell set) is never one: a run takes the keys saved for its harness alone. */
@@ -40,13 +53,28 @@ export declare const RECIPE_TURN_PERSON_ONLY = "This run started on its owner's
40
53
  /** Lays `keys` on `env` where only a direct read finds them: never enumerable, so no spread, copy or child environment
41
54
  * built from `env` carries them (claim-secrets.ts withModelKeys). */
42
55
  export declare function layHarnessKeys(env: NodeJS.ProcessEnv, keys: Readonly<Record<string, string>>): void;
43
- /** What one plan-billed recipe's keys look like in Settings → Harness keys: each key's SecretMeta (never a value), and
44
- * whether every one is saved, which is when its runs take the keys route. */
56
+ /** What one harness's keys look like in Settings → Harness keys, never a value. `named`: a plan-billed recipe this
57
+ * server is started with; else an id whose recipe it no longer names, its keys kept until removed. `keys`: each key its
58
+ * recipe runs on (none when not named), set once saved for this recipe file. `kept`: each key saved for this id that its
59
+ * recipe runs on no more (or no recipe does): no run gets it, and DELETE removes it. `ready`: every one of `keys` saved,
60
+ * which is when its runs take the keys route. `reenter`: each of `keys` saved but not one its runs get, and why. */
45
61
  export type HarnessKeysView = {
46
62
  readonly id: string;
47
63
  readonly label: string;
64
+ readonly named: boolean;
48
65
  readonly keys: SecretMeta[];
66
+ readonly kept: SecretMeta[];
49
67
  readonly ready: boolean;
68
+ readonly reenter: {
69
+ readonly name: string;
70
+ readonly why: HarnessKeyWhy;
71
+ }[];
72
+ };
73
+ /** What a DELETE may remove: a named recipe's keys and those kept for it, or the kept keys of an id no recipe names. */
74
+ export type HarnessKeysHeld = {
75
+ readonly id: string;
76
+ readonly label: string;
77
+ readonly keys: readonly string[];
50
78
  };
51
79
  /** The saved harness keys over the one store, for the server (the one writer of these rows): a snapshot loaded once at
52
80
  * start (load()) and kept in step with every write, so a read answers without a round trip. */
@@ -57,37 +85,56 @@ export declare class HarnessKeysOverStore {
57
85
  private readonly data;
58
86
  private current;
59
87
  private retired;
88
+ private binds;
89
+ private readonly seal;
60
90
  /** The last write in flight (save, remove): each waits for the one before it, so two that overlap never read the same
61
- * value as the one they replace, and every value a claim may have opened is retired. */
91
+ * value as the one they replace, every value a claim may have opened is retired, and the binding row is written whole
92
+ * by one at a time. */
62
93
  private writing;
63
- /** `work` once every write before it has settled, its failure its own. */
94
+ /** `work` once every write before it has settled, its failure its own. A write that fails partway (a value put and its
95
+ * binding not) reads the store again before the next one, so the snapshot, and the cut it gives (values()), holds
96
+ * every value the store does. */
64
97
  private serial;
65
98
  /** `recipes`: the plan-billed recipes this server is started with (harness-table.ts planRecipesOf), the only harnesses
66
- * whose keys it saves or shows. `data`: its data directory, which its registry (harnessKeysSavedHere) is kept under. */
99
+ * whose keys it saves. `data`: its data directory, which its registry (harnessKeysSavedHere) is kept under. */
67
100
  constructor(store: HarnessKeysStore, sealKey: Buffer, recipes: readonly PlanRecipe[], data: string);
68
101
  /** This server's registry (harnessKeysSavedHere) set from the snapshot: each recipe whose every key is saved. */
69
102
  private mark;
70
- /** Reads every harness key row once: each current one opened, each retired one opened for the cut. A row that does not
71
- * open reads as not saved. */
103
+ /** Reads every harness key row once, and their bindings: each current one opened (or why not), each retired one opened
104
+ * for the cut. */
72
105
  load(): Promise<void>;
106
+ /** `key`'s row for `recipe` when its runs get it: it opens, and is bound to this recipe file. */
107
+ private bound;
73
108
  /** Whether every key `recipe` runs on is saved for it. */
74
- saved(recipe: Pick<PlanRecipe, "id" | "keys">): boolean;
75
- /** Every value to cut: each saved key's, and each retired one's still kept. */
109
+ saved(recipe: Pick<PlanRecipe, "id" | "keys" | "digest">): boolean;
110
+ /** Every value to cut: each saved key's that opens, whatever recipe it is bound to (or none), and each retired one's
111
+ * still kept. */
76
112
  values(): string[];
77
- /** GET: `recipe`'s keys, each by name, whether saved and when it changed: never a value. */
113
+ /** The keys saved for `id` that `named` does not hold, each as its view says it. */
114
+ private kept;
115
+ /** GET: `recipe`'s keys, each by name, whether saved for it and when it changed, and those to enter again: never a value. */
78
116
  view(recipe: PlanRecipe): HarnessKeysView;
79
- /** GET /settings/harness-keys: every plan-billed recipe this server is started with, its keys by name. */
117
+ /** Each id with keys saved whose recipe this server does not name, sorted: capabilities' harness_keys.kept, so the
118
+ * console offers the page that removes them. */
119
+ unnamed(): string[];
120
+ /** GET /settings/harness-keys: every plan-billed recipe this server is started with, its keys by name; then each id
121
+ * with keys saved whose recipe it no longer names (unnamed), its keys kept. */
80
122
  list(): {
81
123
  harnesses: HarnessKeysView[];
82
124
  };
83
- /** The plan-billed recipe `id` names on this server, else 404. */
125
+ /** The plan-billed recipe `id` names on this server, else 404: what a PUT saves for. */
84
126
  recipe(id: string): PlanRecipe;
85
- /** PUT: `value` sealed as `key` for `recipe`'s harness alone; a value it replaces kept as a retired row. Durable before it
86
- * resolves, so a 204 never outruns the store. */
127
+ /** What a DELETE of `id`'s keys may remove: a named recipe's keys and those kept for it, or the keys kept for an id no
128
+ * recipe on this server names; else 404. */
129
+ held(id: string): HarnessKeysHeld;
130
+ /** PUT: `value` sealed as `key` for `recipe`'s harness alone, bound to its file; a value it replaces kept as a retired
131
+ * row. Durable before it resolves, so a 204 never outruns the store. */
87
132
  save(recipe: PlanRecipe, key: string, body: unknown): Promise<void>;
88
- /** DELETE: `key`'s value for `recipe`'s harness gone from its runs, kept as a retired row for the cut. A row the snapshot
89
- * does not hold (one that does not open under this server's seal key) is removed too, so no claim counts it saved. */
90
- remove(recipe: PlanRecipe, key: string): Promise<void>;
133
+ /** DELETE: `key`'s value for `held`'s harness gone from its runs, kept as a retired row for the cut. A row that does not
134
+ * open under this server's seal key is removed too, so no claim counts it saved. */
135
+ remove(held: HarnessKeysHeld, key: string): Promise<void>;
136
+ /** The bindings written back as one settings row. */
137
+ private writeBinds;
91
138
  /** `value`, which `key` held, sealed as a retired row of its own; the oldest beyond RETIRED_KEPT leaves. */
92
139
  private retire;
93
140
  }
@@ -95,4 +142,3 @@ export declare class HarnessKeysOverStore {
95
142
  export declare function planRecipeOr404(recipes: readonly PlanRecipe[], id: string): PlanRecipe;
96
143
  /** The bytes a value would be sealed as, for a test that checks a key is sealed at rest. */
97
144
  export declare const sealedHarnessKeyBytes: (key: Buffer, harness: string, name: string, value: string) => Uint8Array;
98
- export {};
@@ -5,13 +5,25 @@
5
5
  // cut (the server's secretStores, and a runner's storeSecrets, which reads every sealed_keys row) still holds it, and a
6
6
  // timeline written while it was live stays cut after it changes.
7
7
  //
8
+ // Each current row is bound to the recipe it was saved for and the seal key it was sealed under, in one settings row
9
+ // beside them (HARNESS_KEY_BINDS: the recipe file's sha256, the seal key's fingerprint, the sha256 of the sealed bytes it
10
+ // was written with, none a secret). A row opens for a run only on the recipe it was saved for: a later recipe file of the
11
+ // same id (another agent, another vendor) never takes it, and a row whose seal key changed says so. The binding is kept
12
+ // outside the sealed value and its AAD, since the cut opens every row as a bare key; the digest of the sealed bytes ties
13
+ // the two reads together, so a claim that reads one value's binding and then, after a save, another value's bytes never
14
+ // opens them. A recipe the server no longer names keeps its keys (still sealed, still cut, run by
15
+ // nothing): listed by its id, and removed by DELETE.
16
+ //
8
17
  // The server reads and writes them through HarnessKeysOverStore (its Settings → Harness keys routes, owner only). A
9
- // runner opens a claim's own at its claim (openHarnessKeys), for that run's harness alone, and lays them on its adapter's
18
+ // runner opens a claim's own at its claim (openHarnessKeys), for that run's recipe alone, and lays them on its adapter's
10
19
  // environment where only the agent's start reads them (runner/cli-run-spec.ts): never on its tools, never another run's.
20
+ import { createHash } from "node:crypto";
11
21
  import { ApiError, invalid } from "./errors.js";
12
- import { getSealedKey, putSealedKey, removeSealedKey } from "./server-keys.js";
22
+ import { HARNESS_KEY_REENTER, openSealed, putSealedKey, removeSealedKey, sealFingerprint } from "./server-keys.js";
13
23
  import { registerSecretPage, registerSecretWrite, secretMeta, secretName } from "./secret-writes.js";
14
- import { sealColumn, sealedAt, unsealColumn } from "./store/index.js";
24
+ // isObject from the store, never validate.ts: this module loads while model.ts does (harness-table.ts →
25
+ // harness-recipe-entry.ts), and validate.ts reaches key-words.ts, which reads model.ts's MODEL_KEYS before it is set.
26
+ import { isObject, sealColumn, sealedAt } from "./store/index.js";
15
27
  // Every value saved here is a secret: saving one or removing it takes the owner's session (secret-writes.ts), never the
16
28
  // token, and the token's refusal names the console's page.
17
29
  registerSecretWrite("saveHarnessKey", () => true);
@@ -24,31 +36,77 @@ export const HARNESS_KEY_PLANE = "harness";
24
36
  const RETIRED_PLANE = "harness-retired";
25
37
  /** How many replaced or removed values of one key stay sealed for the cut: the oldest beyond it leaves. */
26
38
  export const RETIRED_KEPT = 8;
39
+ /** The settings row each current key row's binding is kept in: { v: 1, rows: { <row>: { seal, recipe, sealed } } }, `seal`
40
+ * the fingerprint of the seal key it was sealed under (server-keys.ts sealFingerprint), `recipe` the sha256 of the recipe
41
+ * file it was saved for (PlanRecipe.digest), `sealed` the sha256 of the sealed bytes written with it (sealedDigest). */
42
+ export const HARNESS_KEY_BINDS = "harness-keys";
27
43
  /** A value's bounds: under 8 characters or holding whitespace, no cut could hold it whole (server-secrets.ts' floor). */
28
44
  const MIN_VALUE = 8;
29
45
  const MAX_VALUE_BYTES = 1024;
30
- const UNFIT = /[\s\u0000-\u001f\u007f-\u009f]/;
46
+ const UNFIT = /[\s\x00-\x1f\x7f-\x9f]/;
31
47
  /** The row (and view) name of `key` saved for `harness`. */
32
48
  export const harnessKeyRow = (harness, key) => secretName(HARNESS_KEY_PLANE, harness, key);
33
49
  const retiredPrefix = (harness, key) => `${secretName(RETIRED_PLANE, harness, key)}:`;
34
- /** The keys of `names` saved for `harness` that open under `sealKey`, by name. One that does not open (another seal key, or
35
- * damaged) reads as not saved, never a clear fallback. For a runner's claim, whose run is on that harness. */
36
- export async function openHarnessKeys(store, sealKey, harness, names) {
50
+ /** The harness and key a current row's name holds, else undefined (a retired row, or another layer's). */
51
+ const rowParts = (name) => {
52
+ if (!name.startsWith(`${HARNESS_KEY_PLANE}:`))
53
+ return undefined;
54
+ const rest = name.slice(HARNESS_KEY_PLANE.length + 1);
55
+ const at = rest.lastIndexOf(":");
56
+ return at > 0 && at < rest.length - 1 ? { harness: rest.slice(0, at), key: rest.slice(at + 1) } : undefined;
57
+ };
58
+ export { HARNESS_KEY_REENTER };
59
+ /** The sha256 of a row's sealed bytes (base64url): a binding holds the one its value was written with, so bytes read
60
+ * apart from it open only when they are those bytes. Of ciphertext, never of a value. */
61
+ const sealedDigest = (sealed) => createHash("sha256").update(sealed).digest("base64url");
62
+ /** The recipe `bind` binds `sealed` to: none when there is no binding, or it was written with other bytes (a save landed
63
+ * between the reads of one and the other, or the row was put by hand). */
64
+ const boundRecipe = (bind, sealed) => (bind !== undefined && bind.sealed === sealedDigest(sealed) ? bind.recipe : undefined);
65
+ /** The bindings the settings row holds, failing closed: an unreadable row, or a binding with no digest of its bytes,
66
+ * reads as none, so no key opens until saved again. */
67
+ function bindsOf(read) {
68
+ const binds = new Map();
69
+ if (isObject(read) && read.v === 1 && isObject(read.rows)) {
70
+ for (const [row, bind] of Object.entries(read.rows)) {
71
+ if (isObject(bind) && typeof bind.seal === "string" && typeof bind.recipe === "string" && typeof bind.sealed === "string")
72
+ binds.set(row, { seal: bind.seal, recipe: bind.recipe, sealed: bind.sealed });
73
+ }
74
+ }
75
+ return binds;
76
+ }
77
+ const readBinds = async (store) => bindsOf(await store.settings.get(HARNESS_KEY_BINDS));
78
+ /** The keys `recipe` runs on that are saved for it (bound to its digest) and open under `sealKey`, by name. One saved for
79
+ * another recipe file of its id, or that does not open (another seal key, or damaged), reads as not saved, never a clear
80
+ * fallback. For a runner's claim, whose run is on that recipe. */
81
+ export async function openHarnessKeys(store, sealKey, recipe) {
82
+ const binds = await readBinds(store);
37
83
  const opened = {};
38
- for (const name of names) {
39
- const value = await getSealedKey(store, sealKey, harnessKeyRow(harness, name));
40
- if (value !== undefined)
41
- opened[name] = value;
84
+ for (const name of recipe.keys) {
85
+ const row = harnessKeyRow(recipe.id, name);
86
+ const bind = binds.get(row);
87
+ if (bind?.recipe !== recipe.digest)
88
+ continue;
89
+ const sealed = await store.sealedKeys.get(row);
90
+ // The bytes read after the binding are the ones it was written with, or a save came between: never another value.
91
+ if (sealed === undefined || boundRecipe(bind, sealed) !== recipe.digest)
92
+ continue;
93
+ const open = openSealed(sealKey, row, sealed, bind.seal);
94
+ if ("value" in open)
95
+ opened[name] = open.value;
42
96
  }
43
97
  return opened;
44
98
  }
45
- /** Whether every key of `names` has a row saved for `harness` (its bytes never opened): a trigger's check, and a runner's
46
- * claim before it opens them. */
47
- export async function harnessKeysSaved(store, harness, names) {
48
- if (!names.length)
99
+ /** Whether every key `recipe` runs on has a row saved for it, bound to its digest (its bytes never opened): a trigger's
100
+ * check, and a runner's claim before it opens them. */
101
+ export async function harnessKeysSaved(store, recipe) {
102
+ if (!recipe.keys.length)
49
103
  return false;
50
104
  const rows = new Set((await store.sealedKeys.all()).map((row) => row.name));
51
- return names.every((name) => rows.has(harnessKeyRow(harness, name)));
105
+ const binds = await readBinds(store);
106
+ return recipe.keys.every((name) => {
107
+ const row = harnessKeyRow(recipe.id, name);
108
+ return rows.has(row) && binds.get(row)?.recipe === recipe.digest;
109
+ });
52
110
  }
53
111
  /** Whether a claim laid every key of `names` on `env` (layHarnessKeys: own, never enumerable, not empty), which is when
54
112
  * a start takes the keys route (harness-recipe-entry.ts serverRoute). A variable of the same name the environment
@@ -91,113 +149,188 @@ export class HarnessKeysOverStore {
91
149
  data;
92
150
  current = new Map();
93
151
  retired = new Map();
152
+ binds = new Map();
153
+ seal;
94
154
  /** The last write in flight (save, remove): each waits for the one before it, so two that overlap never read the same
95
- * value as the one they replace, and every value a claim may have opened is retired. */
155
+ * value as the one they replace, every value a claim may have opened is retired, and the binding row is written whole
156
+ * by one at a time. */
96
157
  writing = Promise.resolve();
97
- /** `work` once every write before it has settled, its failure its own. */
158
+ /** `work` once every write before it has settled, its failure its own. A write that fails partway (a value put and its
159
+ * binding not) reads the store again before the next one, so the snapshot, and the cut it gives (values()), holds
160
+ * every value the store does. */
98
161
  serial(work) {
99
- const next = this.writing.then(work);
162
+ const next = this.writing.then(async () => {
163
+ try {
164
+ await work();
165
+ }
166
+ catch (error) {
167
+ await this.load().catch(() => undefined);
168
+ throw error;
169
+ }
170
+ });
100
171
  this.writing = next.catch(() => undefined);
101
172
  return next;
102
173
  }
103
174
  /** `recipes`: the plan-billed recipes this server is started with (harness-table.ts planRecipesOf), the only harnesses
104
- * whose keys it saves or shows. `data`: its data directory, which its registry (harnessKeysSavedHere) is kept under. */
175
+ * whose keys it saves. `data`: its data directory, which its registry (harnessKeysSavedHere) is kept under. */
105
176
  constructor(store, sealKey, recipes, data) {
106
177
  this.store = store;
107
178
  this.sealKey = sealKey;
108
179
  this.recipes = recipes;
109
180
  this.data = data;
181
+ this.seal = sealFingerprint(sealKey);
110
182
  }
111
183
  /** This server's registry (harnessKeysSavedHere) set from the snapshot: each recipe whose every key is saved. */
112
184
  mark() {
113
185
  savedHere.set(this.data, new Set(this.recipes.filter((recipe) => this.saved(recipe)).map((recipe) => recipe.id)));
114
186
  }
115
- /** Reads every harness key row once: each current one opened, each retired one opened for the cut. A row that does not
116
- * open reads as not saved. */
187
+ /** Reads every harness key row once, and their bindings: each current one opened (or why not), each retired one opened
188
+ * for the cut. */
117
189
  async load() {
190
+ const binds = await readBinds(this.store);
118
191
  const current = new Map();
119
192
  const retired = new Map();
120
193
  for (const row of await this.store.sealedKeys.all()) {
121
- const isCurrent = row.name.startsWith(`${HARNESS_KEY_PLANE}:`);
122
- if (!isCurrent && !row.name.startsWith(`${RETIRED_PLANE}:`))
194
+ if (rowParts(row.name)) {
195
+ const bind = binds.get(row.name);
196
+ current.set(row.name, { opened: openSealed(this.sealKey, row.name, row.sealed, bind?.seal), recipe: boundRecipe(bind, row.sealed), changedAt: row.updatedAt });
123
197
  continue;
124
- let value;
125
- try {
126
- value = unsealColumn(this.sealKey, sealedAt.sealedKey(row.name), row.sealed).toString("utf8");
127
198
  }
128
- catch {
199
+ if (!row.name.startsWith(`${RETIRED_PLANE}:`))
129
200
  continue;
130
- }
131
- if (isCurrent)
132
- current.set(row.name, { value, changedAt: row.updatedAt });
133
- else {
134
- const of = row.name.slice(0, row.name.lastIndexOf(":") + 1);
135
- retired.set(of, [...(retired.get(of) ?? []), { row: row.name, value, at: row.updatedAt }]);
136
- }
201
+ const opened = openSealed(this.sealKey, row.name, row.sealed, undefined);
202
+ if (!("value" in opened))
203
+ continue;
204
+ const of = row.name.slice(0, row.name.lastIndexOf(":") + 1);
205
+ retired.set(of, [...(retired.get(of) ?? []), { row: row.name, value: opened.value, at: row.updatedAt }]);
137
206
  }
138
207
  for (const list of retired.values())
139
208
  list.sort((a, b) => a.at - b.at);
209
+ this.binds = binds;
140
210
  this.current = current;
141
211
  this.retired = retired;
142
212
  this.mark();
143
213
  }
214
+ /** `key`'s row for `recipe` when its runs get it: it opens, and is bound to this recipe file. */
215
+ bound(recipe, key) {
216
+ const entry = this.current.get(harnessKeyRow(recipe.id, key));
217
+ return entry && "value" in entry.opened && entry.recipe === recipe.digest ? entry : undefined;
218
+ }
144
219
  /** Whether every key `recipe` runs on is saved for it. */
145
220
  saved(recipe) {
146
- return recipe.keys.length > 0 && recipe.keys.every((name) => this.current.has(harnessKeyRow(recipe.id, name)));
221
+ return recipe.keys.length > 0 && recipe.keys.every((name) => this.bound(recipe, name) !== undefined);
147
222
  }
148
- /** Every value to cut: each saved key's, and each retired one's still kept. */
223
+ /** Every value to cut: each saved key's that opens, whatever recipe it is bound to (or none), and each retired one's
224
+ * still kept. */
149
225
  values() {
150
- return [...[...this.current.values()].map((entry) => entry.value), ...[...this.retired.values()].flat().map((entry) => entry.value)];
226
+ return [
227
+ ...[...this.current.values()].flatMap((entry) => ("value" in entry.opened ? [entry.opened.value] : [])),
228
+ ...[...this.retired.values()].flat().map((entry) => entry.value),
229
+ ];
151
230
  }
152
- /** GET: `recipe`'s keys, each by name, whether saved and when it changed: never a value. */
231
+ /** The keys saved for `id` that `named` does not hold, each as its view says it. */
232
+ kept(id, named) {
233
+ return [...this.current].flatMap(([row, entry]) => {
234
+ const parts = rowParts(row);
235
+ if (parts?.harness !== id || named.includes(parts.key))
236
+ return [];
237
+ return [secretMeta(row, "value" in entry.opened ? { set: true, source: "console", changedAt: new Date(entry.changedAt) } : { set: false })];
238
+ });
239
+ }
240
+ /** GET: `recipe`'s keys, each by name, whether saved for it and when it changed, and those to enter again: never a value. */
153
241
  view(recipe) {
154
242
  const keys = recipe.keys.map((name) => {
243
+ const saved = this.bound(recipe, name);
244
+ return secretMeta(harnessKeyRow(recipe.id, name), saved ? { set: true, source: "console", changedAt: new Date(saved.changedAt) } : { set: false });
245
+ });
246
+ const reenter = recipe.keys.flatMap((name) => {
155
247
  const row = harnessKeyRow(recipe.id, name);
156
- const saved = this.current.get(row);
157
- return secretMeta(row, saved ? { set: true, source: "console", changedAt: new Date(saved.changedAt) } : { set: false });
248
+ const entry = this.current.get(row);
249
+ if (!entry || this.bound(recipe, name))
250
+ return [];
251
+ const why = "unreadable" in entry.opened ? entry.opened.unreadable : "recipe_changed";
252
+ return [{ name: row, why }];
158
253
  });
159
- return { id: recipe.id, label: recipe.label, keys, ready: this.saved(recipe) };
254
+ return { id: recipe.id, label: recipe.label, named: true, keys, kept: this.kept(recipe.id, recipe.keys), ready: this.saved(recipe), reenter };
160
255
  }
161
- /** GET /settings/harness-keys: every plan-billed recipe this server is started with, its keys by name. */
256
+ /** Each id with keys saved whose recipe this server does not name, sorted: capabilities' harness_keys.kept, so the
257
+ * console offers the page that removes them. */
258
+ unnamed() {
259
+ const named = new Set(this.recipes.map((recipe) => recipe.id));
260
+ return [...new Set([...this.current.keys()].flatMap((row) => rowParts(row)?.harness ?? []))].filter((id) => !named.has(id)).sort();
261
+ }
262
+ /** GET /settings/harness-keys: every plan-billed recipe this server is started with, its keys by name; then each id
263
+ * with keys saved whose recipe it no longer names (unnamed), its keys kept. */
162
264
  list() {
163
- return { harnesses: this.recipes.map((recipe) => this.view(recipe)) };
265
+ return {
266
+ harnesses: [
267
+ ...this.recipes.map((recipe) => this.view(recipe)),
268
+ ...this.unnamed().map((id) => ({ id, label: id, named: false, keys: [], kept: this.kept(id, []), ready: false, reenter: [] })),
269
+ ],
270
+ };
164
271
  }
165
- /** The plan-billed recipe `id` names on this server, else 404. */
272
+ /** The plan-billed recipe `id` names on this server, else 404: what a PUT saves for. */
166
273
  recipe(id) {
167
274
  return planRecipeOr404(this.recipes, id);
168
275
  }
169
- /** PUT: `value` sealed as `key` for `recipe`'s harness alone; a value it replaces kept as a retired row. Durable before it
170
- * resolves, so a 204 never outruns the store. */
276
+ /** What a DELETE of `id`'s keys may remove: a named recipe's keys and those kept for it, or the keys kept for an id no
277
+ * recipe on this server names; else 404. */
278
+ held(id) {
279
+ const recipe = this.recipes.find((entry) => entry.id === id);
280
+ const kept = [...this.current.keys()].flatMap((row) => {
281
+ const parts = rowParts(row);
282
+ return parts?.harness === id && !recipe?.keys.includes(parts.key) ? [parts.key] : [];
283
+ });
284
+ if (!recipe && !kept.length)
285
+ return planRecipeOr404(this.recipes, id);
286
+ return { id, label: recipe?.label ?? id, keys: [...(recipe?.keys ?? []), ...kept] };
287
+ }
288
+ /** PUT: `value` sealed as `key` for `recipe`'s harness alone, bound to its file; a value it replaces kept as a retired
289
+ * row. Durable before it resolves, so a 204 never outruns the store. */
171
290
  async save(recipe, key, body) {
172
291
  const value = admit(recipe, key, body);
173
292
  const row = harnessKeyRow(recipe.id, key);
174
293
  await this.serial(async () => {
175
294
  const was = this.current.get(row);
176
- if (was?.value === value)
295
+ const wasValue = was && "value" in was.opened ? was.opened.value : undefined;
296
+ if (wasValue === value && was?.recipe === recipe.digest && this.binds.get(row)?.seal === this.seal)
177
297
  return;
178
- if (was)
179
- await this.retire(recipe.id, key, was.value);
180
- await putSealedKey(this.store, this.sealKey, row, value);
181
- this.current.set(row, { value, changedAt: Date.now() });
298
+ if (wasValue !== undefined && wasValue !== value)
299
+ await this.retire(recipe.id, key, wasValue);
300
+ // Unbound before the new value is written, bound after: a write cut short leaves a row bound to no recipe (opened by
301
+ // none), never a value bound to a recipe it was not saved for.
302
+ if (this.binds.delete(row))
303
+ await this.writeBinds();
304
+ const sealed = sealColumn(this.sealKey, sealedAt.sealedKey(row), value);
305
+ await this.store.sealedKeys.put(row, sealed);
306
+ this.binds.set(row, { seal: this.seal, recipe: recipe.digest, sealed: sealedDigest(sealed) });
307
+ await this.writeBinds();
308
+ this.current.set(row, { opened: { value }, recipe: recipe.digest, changedAt: Date.now() });
182
309
  this.mark();
183
310
  await this.store.flush();
184
311
  });
185
312
  }
186
- /** DELETE: `key`'s value for `recipe`'s harness gone from its runs, kept as a retired row for the cut. A row the snapshot
187
- * does not hold (one that does not open under this server's seal key) is removed too, so no claim counts it saved. */
188
- async remove(recipe, key) {
189
- known(recipe, key);
190
- const row = harnessKeyRow(recipe.id, key);
313
+ /** DELETE: `key`'s value for `held`'s harness gone from its runs, kept as a retired row for the cut. A row that does not
314
+ * open under this server's seal key is removed too, so no claim counts it saved. */
315
+ async remove(held, key) {
316
+ known(held, key);
317
+ const row = harnessKeyRow(held.id, key);
191
318
  await this.serial(async () => {
192
319
  const was = this.current.get(row);
193
- if (was)
194
- await this.retire(recipe.id, key, was.value);
320
+ if (was && "value" in was.opened)
321
+ await this.retire(held.id, key, was.opened.value);
195
322
  await removeSealedKey(this.store, row);
323
+ if (this.binds.delete(row))
324
+ await this.writeBinds();
196
325
  this.current.delete(row);
197
326
  this.mark();
198
327
  await this.store.flush();
199
328
  });
200
329
  }
330
+ /** The bindings written back as one settings row. */
331
+ async writeBinds() {
332
+ await this.store.settings.put(HARNESS_KEY_BINDS, { v: 1, rows: Object.fromEntries(this.binds) });
333
+ }
201
334
  /** `value`, which `key` held, sealed as a retired row of its own; the oldest beyond RETIRED_KEPT leaves. */
202
335
  async retire(harness, key, value) {
203
336
  const of = retiredPrefix(harness, key);
@@ -211,7 +344,7 @@ export class HarnessKeysOverStore {
211
344
  this.retired.set(of, list);
212
345
  }
213
346
  }
214
- /** 422 unless `key` is one `recipe` runs on (recipe.keys): a key no recipe names is never saved for it. */
347
+ /** 422 unless `key` is one `recipe` runs on (or, for a DELETE, one kept for it): a key no recipe names is never saved. */
215
348
  function known(recipe, key) {
216
349
  if (!recipe.keys.includes(key))
217
350
  throw invalid([{ field: "key", reason: "not_an_option", message: `${recipe.label} runs on ${recipe.keys.join(", ")}.` }]);
@@ -240,7 +373,7 @@ function admit(recipe, key, body) {
240
373
  export function planRecipeOr404(recipes, id) {
241
374
  const recipe = recipes.find((entry) => entry.id === id);
242
375
  if (!recipe)
243
- throw new ApiError("not_found", `No harness recipe billed to its vendor's plan is named ${id} on this server: its keys are saved for a recipe the server is started with (--harness-recipe).`);
376
+ throw new ApiError("not_found", `No harness recipe billed to its vendor's plan is named ${id} on this server, and no key is kept for it: its keys are saved for a recipe the server is started with (--harness-recipe).`);
244
377
  return recipe;
245
378
  }
246
379
  /** The bytes a value would be sealed as, for a test that checks a key is sealed at rest. */
@@ -1,5 +1,5 @@
1
1
  import type { AcpRecipe } from "@parcha/agentrun-harness-acp";
2
- import { type Recipe, type RecipeArchive } from "./harness-recipe.js";
2
+ import { loadRecipe, type Recipe, type RecipeArchive } from "./harness-recipe.js";
3
3
  import { type AcpEntryHost, type HarnessEntry } from "./harness-table.js";
4
4
  /** A recipe with a sign-in on a server started with --harness-sign-in, whose owner has not signed its agent in on this
5
5
  * data directory. */
@@ -65,12 +65,13 @@ export interface RecipeEntryOptions extends AcpEntryHost {
65
65
  * session's model proxy (the one on Anthropic's Messages there is, Goose's policy, its address under the variable the
66
66
  * recipe names). Billed to its plan: as Cursor's, on the model the recipe names or its vendor's own default. */
67
67
  export declare function recipeEntryOf(options: RecipeEntryOptions): HarnessEntry;
68
- /** The entry of the recipe at `file` on a server whose data directory is `data` (harness-table.ts HARNESS_RECIPES_ENV),
69
- * loaded under its five rules when the table is (a refused one refuses the start, in words). It runs only on the
70
- * install its owner made and checked: hidden, and each run refused, with the command that fixes it, until the binary
71
- * and every file beside it are the pinned ones and a harness-check passed for this very recipe, binary and tree
72
- * (HARNESS_NOT_CHECKED). Each start of its agent checks the binary and the tree against their pins again. It runs on
68
+ /** The entry of the recipe `loaded` (loadRecipe: read once, so the entry and the digest its keys are bound to are of the
69
+ * same bytes) on a server whose data directory is `data` (harness-table.ts HARNESS_RECIPES_ENV), loaded under its five
70
+ * rules when the table is (a refused one refuses the start, in words). It runs only on the
71
+ * install its owner made and checked: hidden, and each run refused, with the command that fixes it, until a harness-check
72
+ * passed for this very recipe and this install's tree, the binary among it (HARNESS_NOT_CHECKED). Each start of its
73
+ * agent digests the tree again and holds it to its pin (harness-recipe.ts installHolds). It runs on
73
74
  * the route serverRoute gives, its owner's sign-in only where `signIn` (--harness-sign-in). */
74
- export declare function recipeServerEntry(file: string, data: string, { signIn }?: {
75
+ export declare function recipeServerEntry(loaded: ReturnType<typeof loadRecipe>, data: string, { signIn }?: {
75
76
  signIn?: boolean;
76
77
  }): HarnessEntry;