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

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 (275) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/README.md +201 -52
  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 +17 -5
  11. package/dist/api-only.js +34 -8
  12. package/dist/browser-hold.d.ts +23 -0
  13. package/dist/browser-hold.js +48 -0
  14. package/dist/browser-person.d.ts +3 -0
  15. package/dist/browser-person.js +4 -1
  16. package/dist/chatgpt-plan.d.ts +18 -8
  17. package/dist/chatgpt-plan.js +91 -34
  18. package/dist/claude-login.d.ts +74 -16
  19. package/dist/claude-login.js +215 -56
  20. package/dist/claude-sign-in.d.ts +17 -6
  21. package/dist/claude-sign-in.js +42 -39
  22. package/dist/cli.js +63 -6
  23. package/dist/composio-made.d.ts +4 -0
  24. package/dist/composio-made.js +4 -0
  25. package/dist/composio-preset.d.ts +43 -2
  26. package/dist/composio-preset.js +92 -4
  27. package/dist/computer-held-routes.d.ts +5 -4
  28. package/dist/computer-held-routes.js +29 -8
  29. package/dist/computer-held.d.ts +6 -1
  30. package/dist/computer-held.js +14 -0
  31. package/dist/computer-record.js +4 -2
  32. package/dist/computer-viewer.js +4 -1
  33. package/dist/console/assets/{backend-Boh7tC4i.js → backend-DVhHzJX2.js} +19 -19
  34. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  35. package/dist/console/assets/index-okP-y8PK.js +747 -0
  36. package/dist/console/index.html +2 -2
  37. package/dist/decisions.d.ts +1 -1
  38. package/dist/decisions.js +1 -1
  39. package/dist/docker-host-addresses.d.ts +22 -11
  40. package/dist/docker-host-addresses.js +38 -26
  41. package/dist/env-switch.d.ts +10 -0
  42. package/dist/env-switch.js +33 -2
  43. package/dist/errors.d.ts +1 -0
  44. package/dist/errors.js +2 -0
  45. package/dist/fal-price.d.ts +58 -20
  46. package/dist/fal-price.js +341 -82
  47. package/dist/handed-values.d.ts +43 -1
  48. package/dist/handed-values.js +119 -2
  49. package/dist/harness-archive.d.ts +13 -10
  50. package/dist/harness-archive.js +60 -34
  51. package/dist/harness-check.d.ts +3 -1
  52. package/dist/harness-check.js +25 -46
  53. package/dist/harness-keys.d.ts +73 -27
  54. package/dist/harness-keys.js +194 -61
  55. package/dist/harness-recipe-entry.d.ts +8 -7
  56. package/dist/harness-recipe-entry.js +21 -32
  57. package/dist/harness-recipe.d.ts +38 -25
  58. package/dist/harness-recipe.js +49 -36
  59. package/dist/harness-sign-in.js +12 -23
  60. package/dist/harness-table.d.ts +10 -3
  61. package/dist/harness-table.js +26 -21
  62. package/dist/harness.d.ts +1 -0
  63. package/dist/harness.js +17 -5
  64. package/dist/hosted-search.d.ts +1 -1
  65. package/dist/hosted-search.js +1 -2
  66. package/dist/import-worker.d.ts +4 -2
  67. package/dist/import-worker.js +9 -2
  68. package/dist/in-flight.d.ts +26 -0
  69. package/dist/in-flight.js +52 -0
  70. package/dist/key-refusal.d.ts +9 -4
  71. package/dist/key-refusal.js +107 -25
  72. package/dist/learn/secrets.d.ts +13 -3
  73. package/dist/learn/secrets.js +118 -17
  74. package/dist/learning-cost.d.ts +6 -3
  75. package/dist/learning-cost.js +4 -2
  76. package/dist/link-check.js +1 -1
  77. package/dist/llms.txt +1 -1
  78. package/dist/marketplace.d.ts +77 -0
  79. package/dist/marketplace.js +224 -0
  80. package/dist/mcp-api-only-origins.d.ts +30 -0
  81. package/dist/mcp-api-only-origins.js +57 -0
  82. package/dist/mcp-gateway.d.ts +7 -5
  83. package/dist/mcp-gateway.js +9 -12
  84. package/dist/mcp-secret-writes.js +5 -3
  85. package/dist/mcp-servers-store.d.ts +28 -6
  86. package/dist/mcp-servers-store.js +53 -4
  87. package/dist/media-duration.d.ts +3 -0
  88. package/dist/media-duration.js +90 -9
  89. package/dist/model-form.d.ts +5 -4
  90. package/dist/model-form.js +11 -7
  91. package/dist/model.d.ts +5 -2
  92. package/dist/model.js +9 -5
  93. package/dist/ollama-provider.d.ts +7 -1
  94. package/dist/ollama-provider.js +14 -2
  95. package/dist/openapi.js +178 -27
  96. package/dist/otel/genai.d.ts +65 -0
  97. package/dist/otel/genai.js +116 -0
  98. package/dist/otel/tracer.d.ts +55 -0
  99. package/dist/otel/tracer.js +308 -0
  100. package/dist/page.d.ts +2 -0
  101. package/dist/page.js +3 -1
  102. package/dist/paid-calls.d.ts +1 -32
  103. package/dist/paid-calls.js +4 -39
  104. package/dist/provider.d.ts +9 -0
  105. package/dist/provider.js +50 -3
  106. package/dist/redact/match.d.ts +30 -3
  107. package/dist/redact/match.js +422 -41
  108. package/dist/refusal-words.d.ts +11 -0
  109. package/dist/refusal-words.js +11 -0
  110. package/dist/run-census.d.ts +67 -0
  111. package/dist/run-census.js +240 -0
  112. package/dist/run-computer.d.ts +6 -3
  113. package/dist/run-computer.js +4 -1
  114. package/dist/run-cut.d.ts +15 -6
  115. package/dist/run-cut.js +30 -9
  116. package/dist/run-files.d.ts +3 -0
  117. package/dist/run-files.js +3 -0
  118. package/dist/run-launch.d.ts +12 -1
  119. package/dist/run-launch.js +9 -10
  120. package/dist/run-learning-served.d.ts +2 -0
  121. package/dist/run-model-key.d.ts +8 -0
  122. package/dist/run-model-key.js +31 -1
  123. package/dist/run-reads-over-store.d.ts +24 -6
  124. package/dist/run-reads-over-store.js +67 -23
  125. package/dist/run-recordings.d.ts +5 -1
  126. package/dist/run-recordings.js +39 -14
  127. package/dist/run-timeline-served.d.ts +2 -0
  128. package/dist/run-timeline-served.js +2 -2
  129. package/dist/run-usage.d.ts +1 -0
  130. package/dist/runnable.d.ts +10 -1
  131. package/dist/runnable.js +20 -8
  132. package/dist/runner/adapter-loop.d.ts +11 -0
  133. package/dist/runner/adapter-loop.js +55 -10
  134. package/dist/runner/adapter-run-spec.d.ts +45 -8
  135. package/dist/runner/adapter-run-spec.js +150 -28
  136. package/dist/runner/adapters/pi.js +25 -3
  137. package/dist/runner/beside.js +4 -3
  138. package/dist/runner/big-writes.js +1 -10
  139. package/dist/runner/claim-secrets.d.ts +18 -3
  140. package/dist/runner/claim-secrets.js +35 -6
  141. package/dist/runner/cli-run-spec.d.ts +6 -0
  142. package/dist/runner/cli-run-spec.js +82 -35
  143. package/dist/runner/computer-journal.d.ts +9 -1
  144. package/dist/runner/computer-journal.js +26 -0
  145. package/dist/runner/conformance/harness.js +1 -1
  146. package/dist/runner/feedback-round.js +3 -0
  147. package/dist/runner/harness-loops.d.ts +6 -5
  148. package/dist/runner/harness-loops.js +7 -7
  149. package/dist/runner/held.d.ts +11 -5
  150. package/dist/runner/journal-kinds.d.ts +5 -0
  151. package/dist/runner/journal-kinds.js +5 -0
  152. package/dist/runner/main.js +7 -2
  153. package/dist/runner/mcp-claim.js +30 -3
  154. package/dist/runner/mcp-run.d.ts +12 -0
  155. package/dist/runner/mcp-run.js +12 -5
  156. package/dist/runner/model-route.d.ts +17 -0
  157. package/dist/runner/model-route.js +120 -2
  158. package/dist/runner/run-child-host.d.ts +3 -0
  159. package/dist/runner/run-child-host.js +69 -28
  160. package/dist/runner/run-child.js +5 -2
  161. package/dist/runner/runner.d.ts +14 -3
  162. package/dist/runner/runner.js +129 -33
  163. package/dist/runner/store-port.d.ts +1 -1
  164. package/dist/runner/store-secrets.d.ts +6 -0
  165. package/dist/runner/store-secrets.js +49 -7
  166. package/dist/runner/subagent.js +4 -40
  167. package/dist/runner/workflow-first.d.ts +11 -4
  168. package/dist/runner/workflow-first.js +14 -8
  169. package/dist/runner/workflow-spec.js +3 -2
  170. package/dist/runs-over-store.d.ts +15 -6
  171. package/dist/runs-over-store.js +33 -21
  172. package/dist/scrub-command.d.ts +73 -0
  173. package/dist/scrub-command.js +307 -0
  174. package/dist/secret-cut.d.ts +73 -0
  175. package/dist/secret-cut.js +291 -4
  176. package/dist/secret-rules.d.ts +143 -0
  177. package/dist/secret-rules.js +2564 -0
  178. package/dist/secrets.d.ts +7 -0
  179. package/dist/secrets.js +20 -0
  180. package/dist/server-keys.d.ts +20 -0
  181. package/dist/server-keys.js +25 -6
  182. package/dist/server.d.ts +52 -11
  183. package/dist/server.js +345 -118
  184. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  185. package/dist/store/index.d.ts +1 -1
  186. package/dist/store/index.js +1 -1
  187. package/dist/store/journal/storage.js +1 -1
  188. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  189. package/dist/store/schema.d.ts +6 -0
  190. package/dist/store/schema.js +11 -1
  191. package/dist/store/seal.d.ts +6 -1
  192. package/dist/store/seal.js +5 -3
  193. package/dist/store/sqlite/run-launch.d.ts +9 -1
  194. package/dist/store/sqlite/run-launch.js +24 -13
  195. package/dist/store/sqlite/run-patch.d.ts +1 -1
  196. package/dist/store/sqlite/run-patch.js +13 -4
  197. package/dist/store/sqlite/store.js +34 -4
  198. package/dist/store/store.d.ts +43 -2
  199. package/dist/store/store.js +20 -0
  200. package/dist/store-reads/learning.d.ts +6 -3
  201. package/dist/store-reads/learning.js +22 -7
  202. package/dist/store-view.d.ts +3 -0
  203. package/dist/store-view.js +3 -3
  204. package/dist/suggestions.js +3 -2
  205. package/dist/template-eval.d.ts +20 -9
  206. package/dist/template-eval.js +115 -33
  207. package/dist/template-import.d.ts +10 -0
  208. package/dist/template-import.js +16 -7
  209. package/dist/templates.d.ts +10 -2
  210. package/dist/templates.js +28 -8
  211. package/dist/timeline/labels.d.ts +6 -4
  212. package/dist/timeline/labels.js +18 -6
  213. package/dist/timeline/timeline.d.ts +5 -0
  214. package/dist/timeline/timeline.js +14 -8
  215. package/dist/timeline/util.js +1 -1
  216. package/dist/timeline/web-calls.d.ts +26 -9
  217. package/dist/timeline/web-calls.js +124 -37
  218. package/dist/tool-gate.d.ts +42 -3
  219. package/dist/tool-gate.js +66 -5
  220. package/dist/tool-keys-store.d.ts +2 -4
  221. package/dist/tool-keys-store.js +5 -21
  222. package/dist/tool-keys.d.ts +2 -2
  223. package/dist/tool-keys.js +2 -2
  224. package/dist/tool-list.js +1 -1
  225. package/dist/tool-plane.d.ts +2 -2
  226. package/dist/tool-plane.js +35 -33
  227. package/dist/tools.js +13 -7
  228. package/dist/trigger-targets.d.ts +4 -0
  229. package/dist/trigger-targets.js +9 -2
  230. package/dist/triggers.d.ts +67 -4
  231. package/dist/triggers.js +171 -22
  232. package/dist/until.d.ts +3 -0
  233. package/dist/until.js +11 -0
  234. package/dist/web-fake.d.ts +1 -3
  235. package/dist/web-fake.js +7 -18
  236. package/dist/web-fetch.d.ts +6 -72
  237. package/dist/web-fetch.js +11 -265
  238. package/dist/web-run.d.ts +31 -0
  239. package/dist/web-run.js +90 -0
  240. package/dist/web-save.d.ts +6 -4
  241. package/dist/web-save.js +9 -12
  242. package/dist/web-search.d.ts +9 -127
  243. package/dist/web-search.js +23 -259
  244. package/dist/wires.d.ts +13 -0
  245. package/dist/wires.js +11 -0
  246. package/dist/workflow-run.d.ts +5 -4
  247. package/dist/workflow-run.js +5 -4
  248. package/dist/workspace/computer-deps.d.ts +2 -1
  249. package/dist/workspace/computer-deps.js +9 -2
  250. package/dist/workspace/computer-for-claim.d.ts +12 -1
  251. package/dist/workspace/computer-for-claim.js +77 -8
  252. package/dist/workspace/computer-kept.d.ts +3 -0
  253. package/dist/workspace/computer-kept.js +11 -2
  254. package/dist/workspace/index.d.ts +1 -1
  255. package/dist/workspace/index.js +1 -1
  256. package/dist/workspace/kind-skills.d.ts +4 -0
  257. package/dist/workspace/kind-skills.js +9 -0
  258. package/dist/workspace/synced-folder.js +3 -4
  259. package/dist/wrapped.d.ts +13 -5
  260. package/dist/wrapped.js +52 -26
  261. package/package.json +17 -11
  262. package/skills/agentrun-serve/SKILL.md +4 -0
  263. package/templates/README.md +30 -8
  264. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  265. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  266. package/dist/exa-keyless.d.ts +0 -34
  267. package/dist/exa-keyless.js +0 -118
  268. package/dist/firecrawl-keyless.d.ts +0 -41
  269. package/dist/firecrawl-keyless.js +0 -152
  270. package/dist/keyless-mcp.d.ts +0 -36
  271. package/dist/keyless-mcp.js +0 -127
  272. package/dist/text-urls.d.ts +0 -38
  273. package/dist/text-urls.js +0 -170
  274. package/dist/web-fetch-direct.d.ts +0 -119
  275. package/dist/web-fetch-direct.js +0 -190
@@ -28,6 +28,17 @@ export declare const denyPlace: (from?: SettingFrom) => string;
28
28
  /** The refusal of a call whose tool is set to deny; of one held to another tool's setting (`heldTo`, a shell tool's
29
29
  * bash), naming the setting to change and where it was set (`from`: this agent's settings or this server's). */
30
30
  export declare const deniedText: (tool: string, heldTo?: string, from?: SettingFrom, ran?: "no" | "unknown") => string;
31
+ /** What the first deny of a call of the run's computer's own tools (a desktop's or a phone's, a browser's) says after
32
+ * its refusal, once: the computer is off for the rest of the run (tool-gate.ts RunGate.decide). */
33
+ export declare const computerOffWords: (kind: string) => string;
34
+ /** The refusal of a later call of an off computer's tools, short: decided on the runner alone, no setting read. */
35
+ export declare const computerOffText: (kind: string, ran?: "no" | "unknown") => string;
36
+ /** Why a later claim of a run starts no computer: an earlier claim's deny turned it off for the run (runner/
37
+ * computer-journal.ts computerTurnedOff). Said on the run's timeline. */
38
+ export declare const computerStillOffWords: (kind: string) => string;
39
+ /** Why a run never starts the agent's computer: every tool it serves is set to deny (tool-gate.ts computerDenied). A
40
+ * save's warning says it, and the run's timeline. */
41
+ export declare const computerDeniedWords: (kind: string) => string;
31
42
  /** A workflow model node's tool set to ask: a model node cannot wait for a person's approval (the gate parks no workflow
32
43
  * call), so the call is refused unrun and the model reads why (tool-gate.ts RunGate, on main and on the runner). */
33
44
  export declare const modelNodeAskText: (tool: string, ran?: "no" | "unknown") => string;
@@ -30,6 +30,17 @@ export const deniedText = (tool, heldTo, from = "server", ran = "no") => {
30
30
  const what = ran === "no" ? NOT_RUN : RAN_UNKNOWN;
31
31
  return heldTo && heldTo !== tool ? `${DENIED_OPENING}${tool} follows ${heldTo}'s setting, which is deny ${denyPlace(from)}. ${what} Don't retry it.` : `${DENIED_OPENING}${tool} is set to deny ${denyPlace(from)}. ${what} Don't retry it.`;
32
32
  };
33
+ /** What the first deny of a call of the run's computer's own tools (a desktop's or a phone's, a browser's) says after
34
+ * its refusal, once: the computer is off for the rest of the run (tool-gate.ts RunGate.decide). */
35
+ export const computerOffWords = (kind) => `The ${kind} is off for the rest of this run, so every later call of its tools is refused too.`;
36
+ /** The refusal of a later call of an off computer's tools, short: decided on the runner alone, no setting read. */
37
+ export const computerOffText = (kind, ran = "no") => `${DENIED_OPENING}the ${kind} is off for this run. ${ran === "no" ? NOT_RUN : RAN_UNKNOWN}`;
38
+ /** Why a later claim of a run starts no computer: an earlier claim's deny turned it off for the run (runner/
39
+ * computer-journal.ts computerTurnedOff). Said on the run's timeline. */
40
+ export const computerStillOffWords = (kind) => `The ${kind} is off for this run: an earlier call of its tools was refused for a deny, so it is not started again.`;
41
+ /** Why a run never starts the agent's computer: every tool it serves is set to deny (tool-gate.ts computerDenied). A
42
+ * save's warning says it, and the run's timeline. */
43
+ export const computerDeniedWords = (kind) => `Every tool for this agent's ${kind} is set to deny, so a run never starts it: allow one, or set the computer to none.`;
33
44
  /** A workflow model node's tool set to ask: a model node cannot wait for a person's approval (the gate parks no workflow
34
45
  * call), so the call is refused unrun and the model reads why (tool-gate.ts RunGate, on main and on the runner). */
35
46
  export const modelNodeAskText = (tool, ran = "no") => `This ${tool} call needs a person's approval, which a workflow's model node cannot wait for; ${ran === "no" ? "it was not run." : `it was not run again. ${RAN_UNKNOWN}`}`;
@@ -0,0 +1,67 @@
1
+ import type { Span } from "./redact/match.js";
2
+ import { type RunPatch, type Store } from "./store/store.js";
3
+ import type { Workspace } from "./workspace/index.js";
4
+ import { type ServerRunWorkspaceOptions } from "./workspace/server-run-workspace.js";
5
+ /** The most files one census counts. A run with more has the rest uncounted (`partial`), and each of those is withheld
6
+ * after its end. */
7
+ export declare const CENSUS_FILES_MAX = 2000;
8
+ /** The most bytes one census reads, its files' together (each at most RUN_FILE_CUT_MAX, the most a cut read answers):
9
+ * 64 MiB. Past it the rest are uncounted, as past CENSUS_FILES_MAX. */
10
+ export declare const CENSUS_BYTES_MAX: number;
11
+ /** The most byte ranges one file's entry keeps: 256. A file with more is cut whole ("whole"), so a file that repeats a
12
+ * value (a log that echoes a header on each line) can't grow the census past what a read parses at once. */
13
+ export declare const CENSUS_RANGES_MAX = 256;
14
+ /** The most one census's JSON text holds, in UTF-16 code units: 512 KiB. A file whose entry would take it past is left
15
+ * uncounted (`partial`), so withheld after the end. Every read of the run's launch carries the census. */
16
+ export declare const CENSUS_JSON_MAX: number;
17
+ /** One file as the census counted it: its bytes' MAC (fileMac, hex), and what the cut does to it for the handed secrets:
18
+ * the byte ranges [start, end) of its UTF-8 bytes cut in place, in order, or "whole" (the text is cut whole). */
19
+ export type CensusFile = {
20
+ readonly mac: string;
21
+ readonly cut: readonly (readonly [number, number])[] | "whole";
22
+ };
23
+ /** A census: every file counted, by the MAC of its path under the run's folder (pathMac), never the path; `partial` when files went uncounted (past a cap, a
24
+ * folder deeper than the list goes, a read that failed). */
25
+ export type Census = {
26
+ readonly v: 1;
27
+ readonly files: Readonly<Record<string, CensusFile>>;
28
+ readonly partial?: true;
29
+ };
30
+ /** The MAC of a file's `bytes` in a census: HMAC-SHA256 under a key derived from the server's seal key `sealKey`, so a file
31
+ * that is a handed value alone (or with a newline) leaves no plain hash of the value a reader could match. A seal key
32
+ * restored to another reads no entry as its file's: the files are withheld. */
33
+ export declare function fileMac(sealKey: Buffer, bytes: Uint8Array): string;
34
+ /** What names a file's entry in a census: the MAC of its `path` under the run's folder, HMAC-SHA256 under a key derived
35
+ * from the seal key `sealKey` (apart from fileMac's), so a run that named a file by a handed value (`cache/<key>.json`)
36
+ * leaves the value nowhere in the census once its end erased the seal, nor a plain hash of the path. A read finds the
37
+ * file's entry by the MAC of the path it was asked for. */
38
+ export declare function pathMac(sealKey: Buffer, path: string): string;
39
+ /** The census of the run's files in `workspace` for `values` (the handed secrets, as the cut lists them): each file a
40
+ * cut read would answer (text by its type, UTF-8 with no NUL, at most RUN_FILE_CUT_MAX bytes; a byte order mark kept as
41
+ * a character, as the cut read keeps it, so each byte range falls where the text's cut does) counted with where
42
+ * redactSecrets would cut the values in it (heldSpans), up to CENSUS_FILES_MAX files and CENSUS_BYTES_MAX bytes, each
43
+ * keyed by its path's MAC and holding its bytes' MAC under `sealKey` (pathMac, fileMac), within the entry limits (bounded). A file a cut read refuses (415, 413)
44
+ * is left out: it is refused after the end too. */
45
+ export declare function censusOf(workspace: Workspace, values: readonly string[], sealKey: Buffer): Promise<Census>;
46
+ /** What a run's census (its launch's census JSON text) says of file `path`, whose bytes are `bytes` and text `text`: the
47
+ * spans (UTF-16 offsets of `text`) to cut in place, "whole", or "unreadable" when the census can't say (the marker
48
+ * "unscanned", a census that doesn't parse or is past CENSUS_JSON_MAX, no entry for the file, bytes whose MAC under
49
+ * `sealKey` is not the one counted, no seal key, ranges that don't fall on the text's characters): the file is withheld. */
50
+ export declare function censusCut(census: string, path: string, bytes: Uint8Array, text: string, sealKey: Buffer | undefined): Span[] | "whole" | "unreadable";
51
+ /** What names census text `census` (a run's launch's census) in a run's cut (run-cut.ts RunCut): its SHA-256, so a read
52
+ * that never cuts a file by it carries and compares a digest, not the census (cutRunFile reads the census itself). */
53
+ export declare const censusDigest: (census: string) => string;
54
+ /** The census an end writes over `prior`, its launch's census before it (RunLaunchRow.census), given `next`, the one it
55
+ * made for the secrets the launch holds now: `next` when no end counted any before (null, CENSUS_PENDING); each file of
56
+ * `next` still byte for byte as an earlier end counted it, with both counts' cuts; and no entry for a file written or
57
+ * changed since (it may hold what that earlier turn was handed, which this end can't name, so it is withheld), within
58
+ * the entry limits (bounded).
59
+ * Undefined when an earlier end left no census (a marker): nothing says where those sat, and the end writes the marker. */
60
+ export declare function censusAfter(prior: string | null, next: Census): Census | undefined;
61
+ /** A runner's census of each run it ends (runner.ts RunnerOptions.census): run `runId`'s launch's sealed part opened with
62
+ * `options.sealKey` (handed-values.ts launchValuesOf), and the run's files counted for it (censusOf) through the
63
+ * Workspace the cut read reads them through (serverRunWorkspace), with the sealed bytes it was made under. Undefined for
64
+ * a run whose launch holds none, whose sealed part doesn't open here, or whose earlier end left no census (its end writes
65
+ * the marker); over an earlier end's census, what both counted (censusAfter). A run with no folder yet has none to
66
+ * count. */
67
+ export declare function runCensus(store: Pick<Store, "runs" | "settings" | "sealedKeys">, options: ServerRunWorkspaceOptions): (runId: string) => Promise<RunPatch["census"] | undefined>;
@@ -0,0 +1,240 @@
1
+ // A run's census: where in each of its files the secrets its caller handed it sat when its end erased them (its launch's
2
+ // sealed part: its MCP credentials, its own model key and tool keys, store/seal.ts), never the secrets, nor a hash of one
3
+ // (each file's bytes are named by a MAC under a key derived from the server's seal key, so a file that is a value alone
4
+ // has no hash of the value in the census, and each file by a MAC of its path, so a file named by a value leaves no trace
5
+ // of it: pathMac).
6
+ // The runner makes it just before its final patch, while the launch still holds them, over the run's files as the cut
7
+ // read serves them (GET /v2/runs/{id}/files/{path}?cut=run: the same Workspace, the same text rule, the same cap), and
8
+ // the end's commit writes it in the erased secrets' place (store/sqlite/run-patch.ts refuseLeftovers). A cut read after
9
+ // the end cuts a file by its entry when the file's bytes are still the ones counted (their MAC), and withholds it
10
+ // otherwise: a file with no entry (written after the end, past the census's caps, or one the census couldn't read), one
11
+ // changed since, or a run whose end erased its secrets with no census made under them ("unscanned", or "pending" left by
12
+ // a runner from before the census: store.ts CENSUS_UNSCANNED, CENSUS_PENDING). A later turn handed secrets anew keeps an
13
+ // earlier end's count of each file it left as it was (censusAfter).
14
+ import { createHash, createHmac } from "node:crypto";
15
+ import { launchValuesOf } from "./handed-values.js";
16
+ import { heldSpans } from "./learn/secrets.js";
17
+ import { cutsAsText, listFiles, RUN_FILE_CUT_MAX } from "./run-files.js";
18
+ import { typeOf } from "./file-types.js";
19
+ import { CENSUS_PENDING } from "./store/store.js";
20
+ import { RECORDINGS } from "./workspace/paths.js";
21
+ import { serverRunWorkspace } from "./workspace/server-run-workspace.js";
22
+ /** The most files one census counts. A run with more has the rest uncounted (`partial`), and each of those is withheld
23
+ * after its end. */
24
+ export const CENSUS_FILES_MAX = 2000;
25
+ /** The most bytes one census reads, its files' together (each at most RUN_FILE_CUT_MAX, the most a cut read answers):
26
+ * 64 MiB. Past it the rest are uncounted, as past CENSUS_FILES_MAX. */
27
+ export const CENSUS_BYTES_MAX = 64 * 1024 * 1024;
28
+ /** The most byte ranges one file's entry keeps: 256. A file with more is cut whole ("whole"), so a file that repeats a
29
+ * value (a log that echoes a header on each line) can't grow the census past what a read parses at once. */
30
+ export const CENSUS_RANGES_MAX = 256;
31
+ /** The most one census's JSON text holds, in UTF-16 code units: 512 KiB. A file whose entry would take it past is left
32
+ * uncounted (`partial`), so withheld after the end. Every read of the run's launch carries the census. */
33
+ export const CENSUS_JSON_MAX = 512 * 1024;
34
+ /** The MAC of a file's `bytes` in a census: HMAC-SHA256 under a key derived from the server's seal key `sealKey`, so a file
35
+ * that is a handed value alone (or with a newline) leaves no plain hash of the value a reader could match. A seal key
36
+ * restored to another reads no entry as its file's: the files are withheld. */
37
+ export function fileMac(sealKey, bytes) {
38
+ const key = createHmac("sha256", sealKey).update("agentrun-serve run census file mac v1").digest();
39
+ return createHmac("sha256", key).update(bytes).digest("hex");
40
+ }
41
+ /** What names a file's entry in a census: the MAC of its `path` under the run's folder, HMAC-SHA256 under a key derived
42
+ * from the seal key `sealKey` (apart from fileMac's), so a run that named a file by a handed value (`cache/<key>.json`)
43
+ * leaves the value nowhere in the census once its end erased the seal, nor a plain hash of the path. A read finds the
44
+ * file's entry by the MAC of the path it was asked for. */
45
+ export function pathMac(sealKey, path) {
46
+ const key = createHmac("sha256", sealKey).update("agentrun-serve run census path mac v1").digest();
47
+ return createHmac("sha256", key).update(path).digest("hex");
48
+ }
49
+ /** A census of `counted` (each file's entry, in order), its entries cut to the limits: a file's ranges past
50
+ * CENSUS_RANGES_MAX made "whole", and past CENSUS_JSON_MAX in all, the rest left out and the census `partial`. */
51
+ function bounded(counted, partial) {
52
+ const files = {};
53
+ let size = JSON.stringify({ v: 1, files: {}, partial: true }).length;
54
+ for (const [path, file] of counted) {
55
+ const entry = file.cut !== "whole" && file.cut.length > CENSUS_RANGES_MAX ? { mac: file.mac, cut: "whole" } : file;
56
+ const more = JSON.stringify(path).length + JSON.stringify(entry).length + 2;
57
+ if (size + more > CENSUS_JSON_MAX) {
58
+ partial = true;
59
+ continue;
60
+ }
61
+ size += more;
62
+ files[path] = entry;
63
+ }
64
+ return { v: 1, files, ...(partial ? { partial: true } : {}) };
65
+ }
66
+ /** `spans` of `text` (UTF-16 offsets, in order, apart) as byte ranges of its UTF-8 bytes. */
67
+ function byteRanges(text, spans) {
68
+ const out = [];
69
+ let at = 0;
70
+ let byte = 0;
71
+ for (const [start, end] of spans) {
72
+ byte += Buffer.byteLength(text.slice(at, start));
73
+ const from = byte;
74
+ byte += Buffer.byteLength(text.slice(start, end));
75
+ out.push([from, byte]);
76
+ at = end;
77
+ }
78
+ return out;
79
+ }
80
+ /** The census of the run's files in `workspace` for `values` (the handed secrets, as the cut lists them): each file a
81
+ * cut read would answer (text by its type, UTF-8 with no NUL, at most RUN_FILE_CUT_MAX bytes; a byte order mark kept as
82
+ * a character, as the cut read keeps it, so each byte range falls where the text's cut does) counted with where
83
+ * redactSecrets would cut the values in it (heldSpans), up to CENSUS_FILES_MAX files and CENSUS_BYTES_MAX bytes, each
84
+ * keyed by its path's MAC and holding its bytes' MAC under `sealKey` (pathMac, fileMac), within the entry limits (bounded). A file a cut read refuses (415, 413)
85
+ * is left out: it is refused after the end too. */
86
+ export async function censusOf(workspace, values, sealKey) {
87
+ const { files, deep } = await listFiles(workspace, CENSUS_FILES_MAX, { owned: (name) => name === RECORDINGS });
88
+ let partial = deep || files.length > CENSUS_FILES_MAX;
89
+ let read = 0;
90
+ const counted = [];
91
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
92
+ for (const file of files.slice(0, CENSUS_FILES_MAX)) {
93
+ if (!cutsAsText(typeOf(file.path)) || file.size_bytes > RUN_FILE_CUT_MAX)
94
+ continue;
95
+ if (file.unreadable) {
96
+ partial = true;
97
+ continue;
98
+ }
99
+ if (read + file.size_bytes > CENSUS_BYTES_MAX) {
100
+ partial = true;
101
+ break;
102
+ }
103
+ read += file.size_bytes;
104
+ let bytes;
105
+ try {
106
+ bytes = file.size_bytes === 0 ? new Uint8Array(0) : await workspace.read(file.path, { offset: 0, length: file.size_bytes });
107
+ }
108
+ catch {
109
+ partial = true;
110
+ continue;
111
+ }
112
+ let text;
113
+ try {
114
+ text = decoder.decode(bytes);
115
+ }
116
+ catch {
117
+ continue;
118
+ }
119
+ if (text.includes("\u0000"))
120
+ continue;
121
+ const spans = heldSpans(text, values);
122
+ counted.push([pathMac(sealKey, file.path), { mac: fileMac(sealKey, bytes), cut: spans === "whole" || spans.length > CENSUS_RANGES_MAX ? "whole" : byteRanges(text, spans) }]);
123
+ }
124
+ return bounded(counted, partial);
125
+ }
126
+ /** What a run's census (its launch's census JSON text) says of file `path`, whose bytes are `bytes` and text `text`: the
127
+ * spans (UTF-16 offsets of `text`) to cut in place, "whole", or "unreadable" when the census can't say (the marker
128
+ * "unscanned", a census that doesn't parse or is past CENSUS_JSON_MAX, no entry for the file, bytes whose MAC under
129
+ * `sealKey` is not the one counted, no seal key, ranges that don't fall on the text's characters): the file is withheld. */
130
+ export function censusCut(census, path, bytes, text, sealKey) {
131
+ if (!sealKey || census.length > CENSUS_JSON_MAX)
132
+ return "unreadable";
133
+ let parsed;
134
+ try {
135
+ parsed = JSON.parse(census);
136
+ }
137
+ catch {
138
+ return "unreadable";
139
+ }
140
+ if (typeof parsed !== "object" || parsed === null || parsed.v !== 1)
141
+ return "unreadable";
142
+ const files = parsed.files;
143
+ const named = pathMac(sealKey, path);
144
+ if (typeof files !== "object" || files === null || !Object.hasOwn(files, named))
145
+ return "unreadable";
146
+ const entry = files[named];
147
+ if (typeof entry !== "object" || entry === null || entry.mac !== fileMac(sealKey, bytes))
148
+ return "unreadable";
149
+ if (entry.cut === "whole")
150
+ return "whole";
151
+ if (!Array.isArray(entry.cut))
152
+ return "unreadable";
153
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
154
+ const out = [];
155
+ let byte = 0;
156
+ let char = 0;
157
+ try {
158
+ for (const range of entry.cut) {
159
+ if (!Array.isArray(range) || range.length !== 2)
160
+ return "unreadable";
161
+ const [from, to] = range;
162
+ if (!Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < byte || to <= from || to > bytes.length)
163
+ return "unreadable";
164
+ const start = char + decoder.decode(bytes.subarray(byte, from)).length;
165
+ const end = start + decoder.decode(bytes.subarray(from, to)).length;
166
+ out.push([start, end]);
167
+ byte = to;
168
+ char = end;
169
+ }
170
+ }
171
+ catch {
172
+ return "unreadable";
173
+ }
174
+ return char <= text.length ? out : "unreadable";
175
+ }
176
+ /** What names census text `census` (a run's launch's census) in a run's cut (run-cut.ts RunCut): its SHA-256, so a read
177
+ * that never cuts a file by it carries and compares a digest, not the census (cutRunFile reads the census itself). */
178
+ export const censusDigest = (census) => createHash("sha256").update(census).digest("hex");
179
+ /** A census parsed, or undefined for text that is no census (a marker, damaged). */
180
+ function parsedCensus(text) {
181
+ try {
182
+ const parsed = JSON.parse(text);
183
+ return typeof parsed === "object" && parsed !== null && parsed.v === 1 && typeof parsed.files === "object" && parsed.files !== null ? parsed : undefined;
184
+ }
185
+ catch {
186
+ return undefined;
187
+ }
188
+ }
189
+ /** Byte ranges `a` and `b` (each in order, apart) as one list, in order, overlapping ones joined. */
190
+ function unionRanges(a, b) {
191
+ const out = [];
192
+ for (const [from, to] of [...a, ...b].sort((x, y) => x[0] - y[0] || x[1] - y[1])) {
193
+ const last = out.at(-1);
194
+ if (last && from <= last[1])
195
+ last[1] = Math.max(last[1], to);
196
+ else
197
+ out.push([from, to]);
198
+ }
199
+ return out;
200
+ }
201
+ /** The census an end writes over `prior`, its launch's census before it (RunLaunchRow.census), given `next`, the one it
202
+ * made for the secrets the launch holds now: `next` when no end counted any before (null, CENSUS_PENDING); each file of
203
+ * `next` still byte for byte as an earlier end counted it, with both counts' cuts; and no entry for a file written or
204
+ * changed since (it may hold what that earlier turn was handed, which this end can't name, so it is withheld), within
205
+ * the entry limits (bounded).
206
+ * Undefined when an earlier end left no census (a marker): nothing says where those sat, and the end writes the marker. */
207
+ export function censusAfter(prior, next) {
208
+ if (prior === null || prior === CENSUS_PENDING)
209
+ return next;
210
+ const before = parsedCensus(prior);
211
+ if (!before)
212
+ return undefined;
213
+ const files = [];
214
+ for (const [path, file] of Object.entries(next.files)) {
215
+ const was = Object.hasOwn(before.files, path) ? before.files[path] : undefined;
216
+ if (!was || was.mac !== file.mac)
217
+ continue;
218
+ files.push([path, { mac: file.mac, cut: was.cut === "whole" || file.cut === "whole" ? "whole" : unionRanges(was.cut, file.cut) }]);
219
+ }
220
+ return bounded(files, next.partial === true);
221
+ }
222
+ /** A runner's census of each run it ends (runner.ts RunnerOptions.census): run `runId`'s launch's sealed part opened with
223
+ * `options.sealKey` (handed-values.ts launchValuesOf), and the run's files counted for it (censusOf) through the
224
+ * Workspace the cut read reads them through (serverRunWorkspace), with the sealed bytes it was made under. Undefined for
225
+ * a run whose launch holds none, whose sealed part doesn't open here, or whose earlier end left no census (its end writes
226
+ * the marker); over an earlier end's census, what both counted (censusAfter). A run with no folder yet has none to
227
+ * count. */
228
+ export function runCensus(store, options) {
229
+ return async (runId) => {
230
+ const row = await store.runs.launch(runId);
231
+ if (row.sealed === null || !options.sealKey)
232
+ return undefined;
233
+ const values = launchValuesOf(options.sealKey, runId, row.sealed);
234
+ if (values === "unreadable")
235
+ return undefined;
236
+ const workspace = await serverRunWorkspace(store, runId, options);
237
+ const census = censusAfter(row.census, workspace ? await censusOf(workspace, values, options.sealKey) : { v: 1, files: {} });
238
+ return census ? { json: JSON.stringify(census), sealed: row.sealed } : undefined;
239
+ };
240
+ }
@@ -1,12 +1,13 @@
1
1
  import type { ComputerKind, ComputerSetting } from "./computer-setting.js";
2
2
  /** What a computer is doing, as a run reads it. */
3
- export type ComputerState = "starting" | "ready" | "taken_over" | "ended" | "failed";
3
+ export type ComputerState = "starting" | "ready" | "taken_over" | "released" | "ended" | "failed";
4
4
  /** The states of a computer its run still has. */
5
5
  export declare const COMPUTER_UP: ReadonlySet<ComputerState>;
6
6
  /** The port the run read's computer field reads: run `runId`'s computer state with the owner's hold, "taken_over" while
7
7
  * the owner holds it, else `state` as given. */
8
8
  export type ComputerStateOf = (runId: string, state: ComputerState) => ComputerState;
9
- /** A run, as much of it as its computer's field reads. */
9
+ /** A run, as much of it as its computer's field reads. `released`: the run waits on its person (parked) and its claim let
10
+ * its computer go, none kept for its resume (workspace/computer-kept.ts). */
10
11
  export type RunStateRead = {
11
12
  id: string;
12
13
  status: string;
@@ -14,6 +15,7 @@ export type RunStateRead = {
14
15
  code: string;
15
16
  message: string;
16
17
  };
18
+ released?: boolean;
17
19
  };
18
20
  export type RunComputerField = {
19
21
  kind: ComputerKind;
@@ -22,5 +24,6 @@ export type RunComputerField = {
22
24
  why?: string;
23
25
  };
24
26
  /** The run's `computer` field: absent for a run with none; failed with why when its computer could not be had; ended
25
- * once the run is over; else starting (queued) or ready (going), taken_over while the owner holds it (`stateOf`). */
27
+ * once the run is over; released while it waits with its computer let go; else starting (queued) or ready (going),
28
+ * taken_over while the owner holds it (`stateOf`). */
26
29
  export declare function runComputerField(setting: ComputerSetting, run: RunStateRead, stateOf?: ComputerStateOf): RunComputerField | undefined;
@@ -3,7 +3,8 @@ import { COMPUTER_UNAVAILABLE } from "./computers.js";
3
3
  export const COMPUTER_UP = new Set(["starting", "ready", "taken_over"]);
4
4
  const ENDED = new Set(["completed", "failed", "cancelled", "expired"]);
5
5
  /** The run's `computer` field: absent for a run with none; failed with why when its computer could not be had; ended
6
- * once the run is over; else starting (queued) or ready (going), taken_over while the owner holds it (`stateOf`). */
6
+ * once the run is over; released while it waits with its computer let go; else starting (queued) or ready (going),
7
+ * taken_over while the owner holds it (`stateOf`). */
7
8
  export function runComputerField(setting, run, stateOf) {
8
9
  if (setting.kind === "none")
9
10
  return undefined;
@@ -12,6 +13,8 @@ export function runComputerField(setting, run, stateOf) {
12
13
  return { ...base, state: "failed", why: run.error.message };
13
14
  if (ENDED.has(run.status))
14
15
  return { ...base, state: "ended" };
16
+ if (run.released)
17
+ return { ...base, state: "released" };
15
18
  const state = run.status === "queued" ? "starting" : "ready";
16
19
  return { ...base, state: stateOf ? stateOf(run.id, state) : state };
17
20
  }
package/dist/run-cut.d.ts CHANGED
@@ -1,23 +1,31 @@
1
1
  import { type RunLaunch } from "./run-launch.js";
2
2
  import { type SignInReader } from "./run-view.js";
3
- import type { RunRow, Store } from "./store/store.js";
3
+ import { type RunRow, type Store } from "./store/store.js";
4
4
  /** Run `runId`'s cut set: the values everything served of it is cut of (its view's words, its title, its Timeline's
5
- * rows, its error), or `unreadable` when what it was handed can't be read back here (handed-values.ts handedValuesOf),
6
- * so it is withheld. `known`: its row and launch, when the caller has read them. */
5
+ * rows, its error, its files), and `censusDigest`, its launch's census's digest when an end erased what its caller
6
+ * handed it (the census is the one cut of its files that says where those sat, run-census.ts censusCut, read by the one
7
+ * read that cuts a file by it); or `unreadable` when what it was handed
8
+ * can't be read back here (a sign-in's pointer, handed-values.ts handedValuesOf; its launch's sealed part, which
9
+ * doesn't open under `sealKey`, launchValuesOf; a launch row that can't be read), so it is withheld. `known`: its row
10
+ * and launch, when the caller has read them. */
7
11
  export declare function runCutValues(deps: {
8
12
  serverSecrets: () => string[];
9
13
  signIns?: SignInReader;
14
+ sealKey: Buffer | undefined;
10
15
  }, store: Pick<Store, "runs">, runId: string, known?: {
11
16
  readonly runRow: RunRow;
12
17
  readonly launch: RunLaunch | undefined;
13
- }): Promise<{
18
+ }): Promise<RunCut>;
19
+ /** A run's cut (runCutValues): `censusDigest` names the census its files are cut by (run-census.ts censusDigest). */
20
+ export type RunCut = {
14
21
  values: string[];
15
- } | "unreadable">;
22
+ censusDigest?: string;
23
+ } | "unreadable";
16
24
  /** `build` against run `runId`'s cut, and the cut read again once it is built: `build` is made again, under the cut as it then
17
25
  * stood, until the cut it ran under is the cut after it. The cut only grows (a value saved stays held), so a cut that is the
18
26
  * same after a build holds every value saved before that build's reads, and what `build` rendered under it is cut of all
19
27
  * of them. A cut that keeps growing past CUT_TRIES builds fails closed: `build` is made under `unreadable`, the run withheld. */
20
- export declare function underCut<T>(read: () => Promise<Awaited<ReturnType<typeof runCutValues>>>, build: (cut: Awaited<ReturnType<typeof runCutValues>>) => Promise<T>): Promise<T>;
28
+ export declare function underCut<T>(read: () => Promise<RunCut>, build: (cut: RunCut) => Promise<T>): Promise<T>;
21
29
  /** Run `runId`'s error words: how its error text reads wherever it is served (its view's error, its Timeline's error
22
30
  * rows), main's errorWords: a refused key in plain words (key-refusal.ts keyRefusal, the key its harness's route sends
23
31
  * by this server's settings and keys), else the text by the one rule (shownOf); `unreadable` when the run is withheld.
@@ -26,6 +34,7 @@ export declare function underCut<T>(read: () => Promise<Awaited<ReturnType<typeo
26
34
  export declare function runErrorWordsOf(deps: {
27
35
  serverSecrets: () => string[];
28
36
  signIns?: SignInReader;
37
+ sealKey: Buffer | undefined;
29
38
  keyEnv: () => NodeJS.ProcessEnv;
30
39
  }, store: Pick<Store, "runs">, runId: string, { workflow }: {
31
40
  workflow: boolean;
package/dist/run-cut.js CHANGED
@@ -1,22 +1,43 @@
1
1
  // A run's cut over the store: the ONE set of values everything served of a run is cut of (its view's words, its title,
2
2
  // its Timeline's rows, its error), or `unreadable` when what the run was handed of its agent's browser sign-in can't be read back
3
3
  // here, so nothing it said may be shown. The set is every secret this server never shows (serverSecrets: its own keys,
4
- // the tool and model keys it keeps, trigger and source secrets) and every sign-in pointer the run was handed, live or
5
- // forgotten, read back by the hashes its row keeps (handed-values.ts). Read anew at each call: a key rotated or a seal key restored is
6
- // honoured at once.
7
- import { handedValuesOf } from "./handed-values.js";
4
+ // the tool and model keys it keeps, trigger and source secrets), every sign-in pointer the run was handed, live or
5
+ // forgotten, read back by the hashes its row keeps, and what its caller handed it (its MCP credentials, its own model key
6
+ // and tool keys) while its launch holds them sealed (handed-values.ts launchValuesOf). Its end erases those, so from then
7
+ // its files are cut by its census instead (`census`, run-census.ts), which says where in each file they sat. Read anew at
8
+ // each call: a key rotated or a seal key restored is honoured at once.
9
+ import { handedValuesOf, launchRowOf, launchValuesOf } from "./handed-values.js";
8
10
  import { keyRefusal, runKeyOf } from "./key-refusal.js";
9
11
  import { MIN_SECRET } from "./learn/secrets.js";
12
+ import { censusDigest } from "./run-census.js";
10
13
  import { readLaunchBody } from "./run-launch.js";
11
14
  import { shownOf } from "./run-view.js";
15
+ import { CENSUS_PENDING } from "./store/store.js";
12
16
  /** Run `runId`'s cut set: the values everything served of it is cut of (its view's words, its title, its Timeline's
13
- * rows, its error), or `unreadable` when what it was handed can't be read back here (handed-values.ts handedValuesOf),
14
- * so it is withheld. `known`: its row and launch, when the caller has read them. */
17
+ * rows, its error, its files), and `censusDigest`, its launch's census's digest when an end erased what its caller
18
+ * handed it (the census is the one cut of its files that says where those sat, run-census.ts censusCut, read by the one
19
+ * read that cuts a file by it); or `unreadable` when what it was handed
20
+ * can't be read back here (a sign-in's pointer, handed-values.ts handedValuesOf; its launch's sealed part, which
21
+ * doesn't open under `sealKey`, launchValuesOf; a launch row that can't be read), so it is withheld. `known`: its row
22
+ * and launch, when the caller has read them. */
15
23
  export async function runCutValues(deps, store, runId, known) {
16
- const handed = await handedValuesOf(deps, store, runId, known);
24
+ const row = await launchRowOf(store, runId);
25
+ if (row === "unreadable")
26
+ return "unreadable";
27
+ const runRow = known ? known.runRow : await store.runs.get(runId).catch(() => undefined);
28
+ if (!runRow)
29
+ return "unreadable";
30
+ const handed = await handedValuesOf(deps, store, runId, { runRow, launch: known ? known.launch : row.body });
17
31
  if (handed === "unreadable")
18
32
  return "unreadable";
19
- return { values: [...deps.serverSecrets(), ...handed.refs.filter((ref) => ref.length >= MIN_SECRET)] };
33
+ const launch = launchValuesOf(deps.sealKey, runId, row.sealed);
34
+ if (launch === "unreadable")
35
+ return "unreadable";
36
+ // A launch whose secrets no end has erased yet (CENSUS_PENDING, sealed bytes held) has no census to cut its files by: the
37
+ // values cut them. Every other census does, live or ended: an earlier turn's, which says where what that turn's caller
38
+ // handed sat; or a marker, which says nothing, so the files are withheld (censusCut).
39
+ const census = row.census === null || (row.census === CENSUS_PENDING && row.sealed !== null) ? undefined : row.census;
40
+ return { values: [...deps.serverSecrets(), ...handed.refs.filter((ref) => ref.length >= MIN_SECRET), ...launch], ...(census !== undefined ? { censusDigest: censusDigest(census) } : {}) };
20
41
  }
21
42
  /** How many times `underCut` builds again against a cut that grew while it built, before it gives up and withholds. */
22
43
  const CUT_TRIES = 5;
@@ -25,7 +46,7 @@ const CUT_TRIES = 5;
25
46
  * same after a build holds every value saved before that build's reads, and what `build` rendered under it is cut of all
26
47
  * of them. A cut that keeps growing past CUT_TRIES builds fails closed: `build` is made under `unreadable`, the run withheld. */
27
48
  export async function underCut(read, build) {
28
- const same = (a, b) => a === "unreadable" || b === "unreadable" ? a === b : new Set(a.values).size === new Set([...a.values, ...b.values]).size && new Set(b.values).size === new Set(a.values).size;
49
+ const same = (a, b) => a === "unreadable" || b === "unreadable" ? a === b : a.censusDigest === b.censusDigest && new Set(a.values).size === new Set([...a.values, ...b.values]).size && new Set(b.values).size === new Set(a.values).size;
29
50
  let cut = await read();
30
51
  for (let tries = 1;; tries++) {
31
52
  const built = await build(cut);
@@ -8,6 +8,9 @@ export declare const FILE_CSP = "default-src 'none'; style-src 'unsafe-inline';
8
8
  * text, on the server's event loop. At this size each shape's adversarial input (its prefix repeated with no end, in
9
9
  * secrets-linear.test.mjs) takes under 100 ms here, and prose with 100 held values at most 162 ms. A bigger file is 413. */
10
10
  export declare const RUN_FILE_CUT_MAX: number;
11
+ /** A type the cut read (?cut=run) and a run's census (run-census.ts) take as text: one the table names text, JSON or NDJSON, or one it doesn't know (its bytes are
12
+ * then read as UTF-8, and a file that isn't is 415). */
13
+ export declare const cutsAsText: (type: string | undefined) => boolean;
11
14
  export type FileView = {
12
15
  path: string;
13
16
  size_bytes: number;
package/dist/run-files.js CHANGED
@@ -11,6 +11,9 @@ export const FILE_CSP = "default-src 'none'; style-src 'unsafe-inline'; img-src
11
11
  * text, on the server's event loop. At this size each shape's adversarial input (its prefix repeated with no end, in
12
12
  * secrets-linear.test.mjs) takes under 100 ms here, and prose with 100 held values at most 162 ms. A bigger file is 413. */
13
13
  export const RUN_FILE_CUT_MAX = 256 * 1024;
14
+ /** A type the cut read (?cut=run) and a run's census (run-census.ts) take as text: one the table names text, JSON or NDJSON, or one it doesn't know (its bytes are
15
+ * then read as UTF-8, and a file that isn't is 415). */
16
+ export const cutsAsText = (type) => type === undefined || type.startsWith("text/") || type === "application/json" || type === "application/x-ndjson";
14
17
  /** File `path` as the API lists it, from its Workspace listing entry. */
15
18
  export const viewOf = (path, entry) => ({
16
19
  path, size_bytes: entry.size, modified_at: new Date(entry.mtimeMs).toISOString(), content_type: typeOf(path) ?? null, ...(entry.unreadable ? { unreadable: true } : {}),
@@ -1,6 +1,7 @@
1
1
  import { type SdkBinding } from "./sdk/runtimes.js";
2
2
  import type { SdkWorkflowTool, SdkWorkflowAdapter } from "./sdk/workflows.js";
3
3
  import type { NativeBinding } from "./native/types.js";
4
+ import type { InputIssue } from "./errors.js";
4
5
  import { type MessageOrigin } from "./timeline/index.js";
5
6
  import type { Plane } from "./tool-plane.js";
6
7
  import type { RunTrigger } from "./triggers.js";
@@ -108,11 +109,21 @@ export interface RunLaunch {
108
109
  * claim, revoke and reclaim of the run, after a restart too, acts on that one disk. */
109
110
  readonly archilDisk?: LaunchDisk;
110
111
  /** A run started with `hold: true` (computer-held.ts): its computer waits for its owner's start, and stays the owner's
111
- * after the agent's end until released, each wait for at most `minutes` with no call. */
112
+ * after the agent's end until released, each wait for at most `minutes` with no call. `refused`: its model kept it from
113
+ * running when it was created (a key, the harness, a price), which a held run's create does not refuse: its computer is
114
+ * the owner's to call, and its agent never starts, every start and message refused in these words. */
112
115
  readonly hold?: {
113
116
  readonly minutes: number;
117
+ readonly refused?: HeldRefusal;
114
118
  };
115
119
  }
120
+ /** A held run's model refusal, as its create would have answered it (409 agent_not_runnable): its message, its fields and
121
+ * its details, kept in its launch for its start to answer the same. */
122
+ export type HeldRefusal = {
123
+ readonly message: string;
124
+ readonly fields: readonly InputIssue[];
125
+ readonly details: Record<string, unknown>;
126
+ };
116
127
  /** Immutable placement identity for a project copied before admission. */
117
128
  export interface SourceProjectLaunch {
118
129
  readonly version: 1;
@@ -1,13 +1,5 @@
1
1
  import { sdkBindingOf } from "./sdk/runtimes.js";
2
2
  import { nativeOf } from "./native/binding.js";
3
- // A run's launch record: the one JSON body the server writes when it starts a run (start = INSERT run, design 2.1), and
4
- // the runner reads at its claim to build the run's spec. It replaces the per-run `serve.json` the old per-run process read
5
- // (app.ts meta.input, place, effort, cap): no process, no door, no marker file, one body written once. What a person sees
6
- // (the v2 start request) is unchanged; this is only where its fields live.
7
- //
8
- // The input's origin keeps its fail-safe on read (#1856): a run started by a trigger keeps an origin only when it names
9
- // the run's own trigger with owner === (the source is a schedule, whose words its owner wrote when they set it up), else
10
- // that trigger's own with owner false, so a forged or lost origin never reads as the person's or the owner's.
11
3
  import { originOf } from "./timeline/index.js";
12
4
  import { ID, isObject } from "./validate.js";
13
5
  import { relativeSegments } from "./workspace/paths.js";
@@ -103,7 +95,7 @@ export function launchBody(launch) {
103
95
  ...(launch.inputOrigin ? { input_origin: launch.inputOrigin } : {}),
104
96
  ...(launch.followUp ? { follow_up: true } : {}),
105
97
  ...(launch.archilDisk ? { archil_disk: { disk_id: launch.archilDisk.diskId, kind: launch.archilDisk.kind } } : {}),
106
- ...(launch.hold ? { hold: { minutes: launch.hold.minutes } } : {}),
98
+ ...(launch.hold ? { hold: { minutes: launch.hold.minutes, ...(launch.hold.refused ? { refused: launch.hold.refused } : {}) } } : {}),
107
99
  };
108
100
  }
109
101
  /** The learning start a launch body names, as read back: its seed sha, its # Learned section text, the learned workflows
@@ -148,6 +140,7 @@ export function readLaunchBody(stored) {
148
140
  const model = readModel(stored.model);
149
141
  const boxAllow = readBoxAllow(stored.box_allow);
150
142
  const archilDisk = readDisk(stored.archil_disk);
143
+ const refused = isObject(stored.hold) ? readRefusal(stored.hold.refused) : undefined;
151
144
  return {
152
145
  input: stored.input,
153
146
  ...(isObject(stored.sdk) && sdkBindingOf(stored.sdk) && typeof stored.sdk.instructions === "string" ? { sdk: stored.sdk } : {}),
@@ -176,9 +169,15 @@ export function readLaunchBody(stored) {
176
169
  ...(inputOrigin ? { inputOrigin } : {}),
177
170
  ...(stored.follow_up === true ? { followUp: true } : {}),
178
171
  ...(archilDisk ? { archilDisk } : {}),
179
- ...(isObject(stored.hold) && typeof stored.hold.minutes === "number" ? { hold: { minutes: stored.hold.minutes } } : {}),
172
+ ...(isObject(stored.hold) && typeof stored.hold.minutes === "number" ? { hold: { minutes: stored.hold.minutes, ...(refused ? { refused } : {}) } } : {}),
180
173
  };
181
174
  }
175
+ /** A held run's model refusal as its launch keeps it, else undefined. */
176
+ function readRefusal(value) {
177
+ if (!isObject(value) || typeof value.message !== "string" || !Array.isArray(value.fields) || !isObject(value.details))
178
+ return undefined;
179
+ return { message: value.message, fields: value.fields, details: value.details };
180
+ }
182
181
  /** The run's learning start (its seed sha, its # Learned section and its learned workflows), read from one place by learning's
183
182
  * routes and the runner; undefined when the run does not learn. */
184
183
  export const learningStartOf = (launch) => launch.learning;
@@ -5,6 +5,7 @@ import type { Store } from "./store/store.js";
5
5
  export declare function servedRunLearning(deps: {
6
6
  serverSecrets: () => string[];
7
7
  signIns?: SignInReader;
8
+ sealKey: Buffer | undefined;
8
9
  statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
9
10
  }, store: Store, runId: string): Promise<{
10
11
  run: string;
@@ -87,6 +88,7 @@ export declare function servedRunLearning(deps: {
87
88
  export declare function servedRunDiff(deps: {
88
89
  serverSecrets: () => string[];
89
90
  signIns?: SignInReader;
91
+ sealKey: Buffer | undefined;
90
92
  }, store: Store, data: string, runId: string): Promise<{
91
93
  base: string;
92
94
  head: string;