@parcha/agentrun-serve 0.1.0-beta.52 → 0.1.0-beta.54

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 (287) hide show
  1. package/CHANGELOG.md +149 -1
  2. package/README.md +295 -37
  3. package/dist/agent-delete.d.ts +5 -6
  4. package/dist/agent-delete.js +30 -67
  5. package/dist/agent-package.d.ts +71 -0
  6. package/dist/agent-package.js +345 -0
  7. package/dist/agent-rows.d.ts +1 -1
  8. package/dist/agents-store.d.ts +26 -20
  9. package/dist/agents-store.js +42 -34
  10. package/dist/api-only.d.ts +25 -6
  11. package/dist/api-only.js +34 -13
  12. package/dist/claude-login.d.ts +1 -0
  13. package/dist/claude-login.js +1 -1
  14. package/dist/cli-learning/cli.d.ts +3 -0
  15. package/dist/cli-learning/cli.js +17 -3
  16. package/dist/cli-learning/connections.js +3 -2
  17. package/dist/cli-learning/schema.js +2 -1
  18. package/dist/cli.js +76 -8
  19. package/dist/composio-preset.d.ts +3 -1
  20. package/dist/composio-preset.js +5 -3
  21. package/dist/composio-triggers.d.ts +4 -0
  22. package/dist/composio-triggers.js +4 -1
  23. package/dist/computer-needs.d.ts +32 -0
  24. package/dist/computer-needs.js +80 -0
  25. package/dist/computer-setting.d.ts +5 -2
  26. package/dist/computer-setting.js +8 -1
  27. package/dist/computers.d.ts +0 -2
  28. package/dist/computers.js +1 -1
  29. package/dist/console/assets/index-B_85An2t.js +745 -0
  30. package/dist/console/assets/index-n1YsbnYh.css +1 -0
  31. package/dist/console/index.html +2 -2
  32. package/dist/console-links.d.ts +1 -0
  33. package/dist/console-links.js +2 -0
  34. package/dist/env-switch.d.ts +14 -0
  35. package/dist/env-switch.js +23 -0
  36. package/dist/errors.d.ts +5 -0
  37. package/dist/errors.js +10 -0
  38. package/dist/eval-previous.js +4 -3
  39. package/dist/fal-price.js +10 -13
  40. package/dist/github-connection.d.ts +50 -1
  41. package/dist/github-connection.js +96 -3
  42. package/dist/github-faux.d.ts +11 -2
  43. package/dist/github-faux.js +138 -7
  44. package/dist/github-pull-request.d.ts +37 -0
  45. package/dist/github-pull-request.js +110 -0
  46. package/dist/handed-secret.d.ts +4 -0
  47. package/dist/handed-secret.js +10 -0
  48. package/dist/harness-archive.d.ts +15 -5
  49. package/dist/harness-archive.js +71 -34
  50. package/dist/harness-check.d.ts +2 -1
  51. package/dist/harness-check.js +36 -95
  52. package/dist/harness-egress.d.ts +23 -0
  53. package/dist/harness-egress.js +69 -0
  54. package/dist/harness-recipe-entry.d.ts +71 -0
  55. package/dist/harness-recipe-entry.js +184 -0
  56. package/dist/harness-recipe.d.ts +73 -6
  57. package/dist/harness-recipe.js +185 -31
  58. package/dist/harness-sign-in.d.ts +29 -0
  59. package/dist/harness-sign-in.js +122 -0
  60. package/dist/harness-table.d.ts +21 -0
  61. package/dist/harness-table.js +58 -3
  62. package/dist/harness-zip.d.ts +6 -0
  63. package/dist/harness-zip.js +203 -0
  64. package/dist/ids.d.ts +11 -0
  65. package/dist/ids.js +36 -0
  66. package/dist/learn/commit.d.ts +14 -1
  67. package/dist/learn/commit.js +156 -1
  68. package/dist/learn/compile.js +22 -8
  69. package/dist/learn/folder.d.ts +5 -0
  70. package/dist/learn/folder.js +10 -1
  71. package/dist/learn/learning.sh +15 -3
  72. package/dist/learn/promote.d.ts +2 -2
  73. package/dist/learn/secrets.js +30 -7
  74. package/dist/learning-routes.d.ts +23 -11
  75. package/dist/learning-routes.js +110 -20
  76. package/dist/learning.d.ts +9 -6
  77. package/dist/learning.js +9 -4
  78. package/dist/live-reach.d.ts +34 -7
  79. package/dist/live-reach.js +76 -11
  80. package/dist/mcp-gateway.js +15 -2
  81. package/dist/mcp-probe.d.ts +3 -0
  82. package/dist/mcp-probe.js +8 -3
  83. package/dist/mcp-resources.d.ts +44 -0
  84. package/dist/mcp-resources.js +100 -0
  85. package/dist/mcp-servers-store.d.ts +16 -12
  86. package/dist/model.d.ts +4 -4
  87. package/dist/model.js +6 -6
  88. package/dist/native/cli.js +9 -2
  89. package/dist/native/connection.d.ts +2 -2
  90. package/dist/native/connection.js +5 -2
  91. package/dist/native/discovery.d.ts +2 -0
  92. package/dist/native/discovery.js +10 -6
  93. package/dist/native/remote-worker-bridge.js +36 -4
  94. package/dist/native/remote.d.ts +18 -1
  95. package/dist/native/remote.js +126 -37
  96. package/dist/native/schema.d.ts +6 -0
  97. package/dist/native/schema.js +31 -6
  98. package/dist/native/source-account.d.ts +13 -0
  99. package/dist/native/source-account.js +114 -0
  100. package/dist/native/source-capture-hooks.d.ts +5 -0
  101. package/dist/native/source-capture-hooks.js +102 -0
  102. package/dist/native/source-mcp-selection.d.ts +13 -0
  103. package/dist/native/source-mcp-selection.js +72 -0
  104. package/dist/native/source-runtime-tools.d.ts +19 -0
  105. package/dist/native/source-runtime-tools.js +103 -0
  106. package/dist/native/source-snapshot-types.d.ts +138 -0
  107. package/dist/native/source-snapshot-types.js +12 -0
  108. package/dist/native/source-snapshot.d.ts +8 -0
  109. package/dist/native/source-snapshot.js +1201 -0
  110. package/dist/observation/learning.js +3 -2
  111. package/dist/openapi.js +275 -40
  112. package/dist/print.js +1 -1
  113. package/dist/purged-workflow.d.ts +12 -0
  114. package/dist/purged-workflow.js +43 -0
  115. package/dist/run-keys.d.ts +46 -0
  116. package/dist/run-keys.js +109 -0
  117. package/dist/run-launch.d.ts +16 -1
  118. package/dist/run-launch.js +30 -1
  119. package/dist/run-learning-served.d.ts +2 -2
  120. package/dist/run-model-key.d.ts +2 -2
  121. package/dist/run-model-key.js +5 -5
  122. package/dist/run-secrets.d.ts +2 -0
  123. package/dist/run-secrets.js +7 -4
  124. package/dist/run-view.d.ts +17 -0
  125. package/dist/run-view.js +25 -1
  126. package/dist/runner/adapter-loop.d.ts +11 -3
  127. package/dist/runner/adapter-loop.js +138 -22
  128. package/dist/runner/adapter-run-spec.js +26 -13
  129. package/dist/runner/audit.d.ts +2 -0
  130. package/dist/runner/audit.js +9 -1
  131. package/dist/runner/beside.js +2 -1
  132. package/dist/runner/claim-secrets.d.ts +29 -3
  133. package/dist/runner/claim-secrets.js +38 -4
  134. package/dist/runner/cli-run-spec.js +24 -13
  135. package/dist/runner/harness-loops.d.ts +6 -0
  136. package/dist/runner/harness-loops.js +11 -1
  137. package/dist/runner/held.d.ts +4 -0
  138. package/dist/runner/journal-kinds.d.ts +2 -0
  139. package/dist/runner/learned-first.d.ts +2 -0
  140. package/dist/runner/learned-first.js +1 -1
  141. package/dist/runner/learning-end.d.ts +7 -2
  142. package/dist/runner/learning-end.js +22 -10
  143. package/dist/runner/learning-seed.d.ts +9 -3
  144. package/dist/runner/learning-seed.js +2 -2
  145. package/dist/runner/main.d.ts +1 -0
  146. package/dist/runner/main.js +20 -13
  147. package/dist/runner/mcp-claim.js +6 -1
  148. package/dist/runner/mcp-run.d.ts +10 -7
  149. package/dist/runner/mcp-run.js +3 -5
  150. package/dist/runner/metrics.d.ts +4 -2
  151. package/dist/runner/metrics.js +15 -3
  152. package/dist/runner/monid-run.js +9 -11
  153. package/dist/runner/pr-checkout.d.ts +21 -4
  154. package/dist/runner/pr-checkout.js +103 -4
  155. package/dist/runner/project-checkpoint.d.ts +35 -0
  156. package/dist/runner/project-checkpoint.js +116 -0
  157. package/dist/runner/project-drain.d.ts +8 -0
  158. package/dist/runner/project-drain.js +25 -0
  159. package/dist/runner/project-host.d.ts +10 -0
  160. package/dist/runner/project-host.js +52 -0
  161. package/dist/runner/promotion.d.ts +14 -6
  162. package/dist/runner/promotion.js +98 -41
  163. package/dist/runner/redact.d.ts +13 -0
  164. package/dist/runner/redact.js +67 -1
  165. package/dist/runner/run-channel.d.ts +9 -0
  166. package/dist/runner/run-channel.js +15 -2
  167. package/dist/runner/run-child-host.d.ts +8 -4
  168. package/dist/runner/run-child-host.js +178 -45
  169. package/dist/runner/run-errors.js +2 -2
  170. package/dist/runner/runner-check.d.ts +3 -0
  171. package/dist/runner/runner-check.js +28 -2
  172. package/dist/runner/runner.js +26 -9
  173. package/dist/runner/store-secrets.js +7 -3
  174. package/dist/runner/workflow-first.d.ts +4 -0
  175. package/dist/runner/workflow-first.js +13 -0
  176. package/dist/runner/workflow-loop.d.ts +2 -1
  177. package/dist/runner/workflow-loop.js +2 -1
  178. package/dist/runner/workflow-spec.js +1 -1
  179. package/dist/runs-over-store.d.ts +34 -6
  180. package/dist/runs-over-store.js +133 -25
  181. package/dist/sdk/runs.d.ts +11 -1
  182. package/dist/sdk/runs.js +117 -26
  183. package/dist/sdk/schema.js +12 -2
  184. package/dist/sdk/workflows.d.ts +1 -1
  185. package/dist/server.d.ts +79 -32
  186. package/dist/server.js +673 -113
  187. package/dist/skills/agentrun-serve/SKILL.md +2 -1
  188. package/dist/source-sync/adoption.d.ts +15 -0
  189. package/dist/source-sync/adoption.js +36 -0
  190. package/dist/source-sync/auxiliary.d.ts +23 -0
  191. package/dist/source-sync/auxiliary.js +64 -0
  192. package/dist/source-sync/capture-git.d.ts +5 -0
  193. package/dist/source-sync/capture-git.js +272 -0
  194. package/dist/source-sync/capture-project.d.ts +53 -0
  195. package/dist/source-sync/capture-project.js +206 -0
  196. package/dist/source-sync/capture-refusal.d.ts +7 -0
  197. package/dist/source-sync/capture-refusal.js +16 -0
  198. package/dist/source-sync/capture.d.ts +11 -0
  199. package/dist/source-sync/capture.js +22 -0
  200. package/dist/source-sync/checkpoint-gate.d.ts +21 -0
  201. package/dist/source-sync/checkpoint-gate.js +52 -0
  202. package/dist/source-sync/checkpoints.d.ts +66 -0
  203. package/dist/source-sync/checkpoints.js +168 -0
  204. package/dist/source-sync/claim.d.ts +11 -0
  205. package/dist/source-sync/claim.js +48 -0
  206. package/dist/source-sync/destination.d.ts +47 -0
  207. package/dist/source-sync/destination.js +239 -0
  208. package/dist/source-sync/io.d.ts +15 -0
  209. package/dist/source-sync/io.js +52 -0
  210. package/dist/source-sync/local.d.ts +43 -0
  211. package/dist/source-sync/local.js +229 -0
  212. package/dist/source-sync/prepare.d.ts +59 -0
  213. package/dist/source-sync/prepare.js +93 -0
  214. package/dist/source-sync/projects.d.ts +61 -0
  215. package/dist/source-sync/projects.js +130 -0
  216. package/dist/source-sync/registry.d.ts +95 -0
  217. package/dist/source-sync/registry.js +226 -0
  218. package/dist/source-sync/service.d.ts +33 -0
  219. package/dist/source-sync/service.js +118 -0
  220. package/dist/source-sync/skill-edits.d.ts +12 -0
  221. package/dist/source-sync/skill-edits.js +122 -0
  222. package/dist/source-sync/snapshots.d.ts +48 -0
  223. package/dist/source-sync/snapshots.js +448 -0
  224. package/dist/source-sync/types.d.ts +9 -0
  225. package/dist/source-sync/types.js +14 -0
  226. package/dist/source-sync/workspace.d.ts +66 -0
  227. package/dist/source-sync/workspace.js +273 -0
  228. package/dist/store/agent-body.d.ts +6 -2
  229. package/dist/store/agent-body.js +18 -7
  230. package/dist/store/index.d.ts +2 -2
  231. package/dist/store/index.js +1 -1
  232. package/dist/store/schema.d.ts +2 -1
  233. package/dist/store/schema.js +2 -1
  234. package/dist/store/seal.d.ts +5 -1
  235. package/dist/store/seal.js +12 -3
  236. package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
  237. package/dist/store/sqlite/project-checkpoints.js +70 -0
  238. package/dist/store/sqlite/run-launch.d.ts +4 -12
  239. package/dist/store/sqlite/run-launch.js +5 -19
  240. package/dist/store/sqlite/store.js +224 -170
  241. package/dist/store/store.d.ts +116 -39
  242. package/dist/store/store.js +14 -1
  243. package/dist/store-reads/learning.d.ts +2 -2
  244. package/dist/store-view.d.ts +3 -1
  245. package/dist/store-view.js +17 -5
  246. package/dist/suggestions.d.ts +282 -0
  247. package/dist/suggestions.js +919 -0
  248. package/dist/telemetry.d.ts +8 -1
  249. package/dist/telemetry.js +12 -4
  250. package/dist/template-import.d.ts +27 -2
  251. package/dist/template-import.js +148 -13
  252. package/dist/templates.d.ts +103 -77
  253. package/dist/templates.js +71 -17
  254. package/dist/timeline/index.d.ts +1 -1
  255. package/dist/timeline/index.js +1 -1
  256. package/dist/timeline/timeline.d.ts +5 -0
  257. package/dist/timeline/timeline.js +8 -0
  258. package/dist/tool-plane.d.ts +12 -12
  259. package/dist/tools.d.ts +8 -8
  260. package/dist/trigger-launch-hook.d.ts +49 -0
  261. package/dist/trigger-launch-hook.js +91 -0
  262. package/dist/trigger-targets.d.ts +14 -1
  263. package/dist/trigger-targets.js +20 -0
  264. package/dist/triggers.d.ts +54 -5
  265. package/dist/triggers.js +143 -8
  266. package/dist/uploads-archil.js +1 -1
  267. package/dist/uploads.js +1 -1
  268. package/dist/validate.d.ts +1 -1
  269. package/dist/validate.js +3 -4
  270. package/dist/workspace/computer-for-claim.d.ts +2 -0
  271. package/dist/workspace/computer-for-claim.js +43 -0
  272. package/dist/workspace/paths.d.ts +6 -0
  273. package/dist/workspace/paths.js +6 -0
  274. package/dist/workspace/resolve-computer.d.ts +1 -0
  275. package/dist/workspace/run-tools.d.ts +2 -0
  276. package/dist/workspace/run-tools.js +8 -0
  277. package/dist/workspace/synced-folder.d.ts +1 -1
  278. package/dist/workspace/synced-folder.js +11 -14
  279. package/launcher/agentrun-serve +1 -1
  280. package/package.json +10 -10
  281. package/skills/agentrun-serve/SKILL.md +2 -1
  282. package/templates/README.md +8 -4
  283. package/templates/agent-scout/agent.md +46 -0
  284. package/templates/agent-scout/skills/scout/SKILL.md +88 -0
  285. package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
  286. package/dist/console/assets/index-B-D0EM3j.js +0 -733
  287. package/dist/console/assets/index-DlQepP2J.css +0 -1
@@ -0,0 +1,122 @@
1
+ // `agentrun harness sign-in --recipe FILE`: the owner signs a recipe's agent in to their own account with the agent's own
2
+ // sign-in, in their own terminal, as T3 Code signs Google Antigravity in (`agy acp --login --gemini-dir DIR`). The
3
+ // installed binary (its pins checked, as a check's are) starts with its release's args, then signIn.args, then
4
+ // signIn.homeArg naming <data>/harnesses/<id>.sign-in, on this terminal's own stdin, stdout and stderr: the agent prints
5
+ // where to sign in, reads the code the person pastes, and writes its sign-in into that folder. Nothing of AgentRun's sits
6
+ // between the person and the agent: this command reads none of what the agent prints or is given, never lists or opens
7
+ // the folder, and judges the sign-in by the agent's exit status alone. AgentRun never reads, refreshes or sends the
8
+ // sign-in (HARNESS.md#sign-in).
9
+ import { spawn } from "node:child_process";
10
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+ import { ACP_PACKAGE, acpPackage } from "./acp-package.js";
14
+ import { ARCHIVE_CODES, archivePlatform, digestOf } from "./harness-archive.js";
15
+ import { installDirOf } from "./harness-install.js";
16
+ import { AGENT_VARS, loadRecipe, pinnedDigest, pinnedTree, recipeBinaryOf, recipeInstallLine, RecipeRefused, releaseFor, signedInNoteOf, signInHomeOf } from "./harness-recipe.js";
17
+ /** A recipe with no signIn: it runs on its keys alone, and has nothing to sign in. */
18
+ export const HARNESS_NO_SIGN_IN = "HARNESS_NO_SIGN_IN";
19
+ /** The agent's own sign-in did not end well: its exit status, a signal, or the time ran out. */
20
+ export const HARNESS_SIGN_IN_FAILED = "HARNESS_SIGN_IN_FAILED";
21
+ /** How long the person has to sign in. */
22
+ export const SIGN_IN_MS = 10 * 60_000;
23
+ /** The one line each sign-in says first: a person's own sign-in used through AgentRun may be outside what its vendor's
24
+ * terms (the recipe's signIn.terms) cover, and the choice is theirs. A warning, never a refusal. */
25
+ export const signInWarning = (label, terms) => `${label}'s own sign-in: its vendor's terms may not cover use through AgentRun${terms ? ` (${terms})` : ""}. Your choice, on your own machine, at your own account's risk.`;
26
+ /** Signs the recipe's agent in: `{ ok: true, home }`, or `{ ok: false, code, message }` with the command's own words. */
27
+ export async function signInHarness(options) {
28
+ const say = options.say ?? (() => { });
29
+ const refuse = (code, words) => ({ ok: false, code, message: `${code}: ${words}` });
30
+ let loaded;
31
+ try {
32
+ loaded = loadRecipe(options.recipe);
33
+ }
34
+ catch (error) {
35
+ if (!(error instanceof RecipeRefused))
36
+ throw error;
37
+ return { ok: false, code: error.code, message: error.message };
38
+ }
39
+ const { recipe, file } = loaded;
40
+ if (!recipe.signIn)
41
+ return refuse(HARNESS_NO_SIGN_IN, `${recipe.label}'s recipe names no signIn: it runs on its keys (${recipe.keys.join(", ") || "none"}), and has nothing to sign in`);
42
+ // The installed binary and every file beside it, the pinned ones, as a check finds them: nothing is downloaded here.
43
+ const platform = options.platform ?? archivePlatform();
44
+ const release = releaseFor(recipe, platform);
45
+ if (!platform || !release)
46
+ return refuse("HARNESS_PLATFORM_UNSUPPORTED", `${recipe.label} ${recipe.release.version} has no release for ${platform ?? `${process.platform}-${process.arch}`}`);
47
+ const line = recipeInstallLine(file, options.data, options.env);
48
+ const binary = recipeBinaryOf(options.data, recipe, release);
49
+ const pin = pinnedDigest(options.data, recipe, release, platform);
50
+ const treePin = pinnedTree(options.data, recipe, release, platform);
51
+ if (!existsSync(binary) || !pin || !treePin)
52
+ return refuse("HARNESS_NOT_INSTALLED", `${recipe.label} ${recipe.release.version} is not installed in ${installDirOf(options.data, recipe.id)}. Install it with: ${line}`);
53
+ const acp = acpPackage();
54
+ if (!acp)
55
+ return refuse("HARNESS_NOT_INSTALLED", `the ACP adapter (${ACP_PACKAGE}) beside this server is not installed`);
56
+ const found = await digestOf(binary).catch(() => undefined);
57
+ const tree = await acp.treeDigest(installDirOf(options.data, recipe.id)).catch(() => undefined);
58
+ if (found !== pin.sha256 || tree !== treePin.sha256)
59
+ return refuse(ARCHIVE_CODES.binary, `${recipe.label}'s installed files are not the pinned ones. Install it again with: ${line}`);
60
+ const home = signInHomeOf(options.data, recipe.id);
61
+ mkdirSync(home, { recursive: true, mode: 0o700 });
62
+ chmodSync(home, 0o700);
63
+ // Its own HOME and TMPDIR for whatever else the agent writes, gone with it; its sign-in goes to `home` alone, by the flag.
64
+ const scratch = mkdtempSync(join(tmpdir(), "agentrun-sign-in-"));
65
+ const env = {};
66
+ for (const name of AGENT_VARS.inherited)
67
+ if (options.env[name] !== undefined)
68
+ env[name] = options.env[name];
69
+ Object.assign(env, recipe.env, { HOME: scratch, TMPDIR: scratch });
70
+ const args = [...(release.args ?? recipe.args), ...recipe.signIn.args, recipe.signIn.homeArg, home];
71
+ // The one warning, never a refusal (HARNESS.md#vendor-terms): the vendor's terms are the recipe's to name, the choice
72
+ // the person's.
73
+ say(signInWarning(recipe.label, recipe.signIn.terms));
74
+ say(`${recipe.label} signs you in with its own sign-in, here: it prints the address to open and asks you for the code. AgentRun reads none of it.`);
75
+ const timeoutMs = options.timeoutMs ?? SIGN_IN_MS;
76
+ let timedOut = false;
77
+ const ended = await new Promise((done) => {
78
+ // In a process group of its own, so that whatever it starts (a launcher that does not exec the agent, a helper the
79
+ // agent forks) ends with it: on the timeout, and when this command is interrupted (Ctrl-C reaches this process alone
80
+ // now, and is passed on to the group). The terminal's stdin, stdout and stderr stay the agent's.
81
+ const child = spawn(binary, args, { cwd: scratch, env, stdio: "inherit", detached: true });
82
+ const group = (signal) => {
83
+ try {
84
+ if (child.pid !== undefined)
85
+ process.kill(-child.pid, signal);
86
+ }
87
+ catch {
88
+ // The group is gone already.
89
+ }
90
+ };
91
+ const stop = () => {
92
+ group("SIGTERM");
93
+ setTimeout(() => group("SIGKILL"), 5_000).unref();
94
+ };
95
+ const passOn = ["SIGINT", "SIGTERM", "SIGHUP"];
96
+ for (const signal of passOn)
97
+ process.on(signal, stop);
98
+ const timer = setTimeout(() => {
99
+ timedOut = true;
100
+ stop();
101
+ }, timeoutMs);
102
+ const settle = (result) => {
103
+ clearTimeout(timer);
104
+ for (const signal of passOn)
105
+ process.off(signal, stop);
106
+ // Whatever it left behind in its group goes with it.
107
+ group("SIGKILL");
108
+ done(result);
109
+ };
110
+ child.once("error", (error) => settle({ error: error.code ?? error.message }));
111
+ child.once("exit", (code, signal) => settle({ code, signal }));
112
+ });
113
+ rmSync(scratch, { recursive: true, force: true });
114
+ if ("error" in ended)
115
+ return refuse(HARNESS_SIGN_IN_FAILED, `${recipe.label} could not be started (${ended.error})`);
116
+ if (timedOut)
117
+ return refuse(HARNESS_SIGN_IN_FAILED, `${recipe.label} was not signed in within ${Math.round(timeoutMs / 60_000)} minutes`);
118
+ if (ended.code !== 0)
119
+ return refuse(HARNESS_SIGN_IN_FAILED, `${recipe.label}'s sign-in ended with ${ended.signal ? `signal ${ended.signal}` : `exit status ${ended.code}`}, so it is not signed in`);
120
+ writeFileSync(signedInNoteOf(options.data, recipe.id), `${JSON.stringify({ at: new Date().toISOString(), version: recipe.release.version })}\n`, { mode: 0o600 });
121
+ return { ok: true, home };
122
+ }
@@ -196,6 +196,20 @@ export declare const BUILTIN_HARNESS_IDS: readonly string[];
196
196
  export declare function builtinOwns(id: string, key: string): boolean;
197
197
  /** The code a harness module's entry is refused by when its ownKeys names a key a built-in harness owns (BUILTIN_OWN_KEYS). */
198
198
  export declare const HARNESS_KEY_OWNED = "HARNESS_KEY_OWNED";
199
+ /** The setting that names the recipes a server's table adds and the data directory they are installed in, as a run's
200
+ * process carries it (HARNESS_RECIPES_SETTING, `--harness-recipe`): JSON `{ "data": dir, "files": [absolute paths],
201
+ * "signIn": true }`, `signIn` only from a server whose start proved --harness-sign-in (server.ts harnessSignInRefusal),
202
+ * never from the owner's setting, so a runner apart never runs a recipe on its owner's sign-in. */
203
+ export declare const HARNESS_RECIPES_ENV = "AGENTRUN_HARNESS_RECIPES";
204
+ /** The owner's setting that names harness recipes when no option does: recipe files, comma-separated. */
205
+ export declare const HARNESS_RECIPES_SETTING = "AGENTRUN_SERVE_HARNESS_RECIPES";
206
+ /** The recipe files `given` names (a server's or a runner's `--harness-recipe`, else HARNESS_RECIPES_SETTING). */
207
+ export declare const harnessRecipesOf: (given: readonly string[] | undefined, env: NodeJS.ProcessEnv) => string[];
208
+ /** HARNESS_RECIPES_ENV for the recipe files `files` names, installed into `data`: none for none. `signIn` only where the
209
+ * server's start proved --harness-sign-in. */
210
+ export declare const harnessRecipesEnv: (files: readonly string[], data: string, { signIn }?: {
211
+ signIn?: boolean;
212
+ }) => NodeJS.ProcessEnv;
199
213
  /** The table `env` runs on: the built-in entries; then, only under a test runner (node --test's NODE_TEST_CONTEXT, which a
200
214
  * server's and a run's processes there carry), a test's module's (HARNESS_TABLE_ENV) merged over them by id; then the
201
215
  * harnesses each of the owner's harness modules adds (HARNESS_MODULES_ENV), under a test runner or not. A module adds
@@ -205,6 +219,11 @@ export declare const HARNESS_KEY_OWNED = "HARNESS_KEY_OWNED";
205
219
  * id another module adds, or an entry missing a member is refused by name, so no module changes what a built-in harness
206
220
  * is (grep pins claude-agent). Loaded once per setting. */
207
221
  export declare function harnessTable(env: NodeJS.ProcessEnv): Readonly<Record<string, HarnessEntry>>;
222
+ /** How `id` on `env`'s table is billed when it is a recipe's harness, else undefined. A recipe's install, its check's
223
+ * note and its owner's sign-in are the server user's alone (0700 and 0600 under `<data>/harnesses`), so its runs run as
224
+ * that user, never a slot's; and a plan-billed one runs on keys saved for it or, for a person's run alone, its owner's
225
+ * own sign-in (harness-recipe-entry.ts serverRoute). */
226
+ export declare const recipeHarness: (env: NodeJS.ProcessEnv, id: string) => "proxy" | "plan" | undefined;
208
227
  /** The owner's setting that names harness modules when no option does: package names or paths, comma-separated. */
209
228
  export declare const HARNESS_MODULES_SETTING = "AGENTRUN_SERVE_HARNESS_MODULES";
210
229
  /** The harness modules `given` names (a server's or a runner's `--harness-module`, else HARNESS_MODULES_SETTING): none
@@ -242,3 +261,5 @@ export declare const harnessOf: (env: NodeJS.ProcessEnv, id: string | undefined)
242
261
  export declare const onAdapter: (env: NodeJS.ProcessEnv, id: string | undefined) => boolean;
243
262
  /** The harness a definition stores: none for the default, which is never stored. */
244
263
  export declare const storedHarness: (id: string | undefined) => string | undefined;
264
+ /** The managed adapter for an imported native protocol. Source discovery never chooses execution by a bare runtime string. */
265
+ export declare const harnessForSourceProtocol: (protocol: "codex-json" | "claude-json") => string;
@@ -22,6 +22,8 @@ import { chooseModel } from "./model.js";
22
22
  import { HarnessUnavailable, modelOn, openRouterOnly, priceModelFor, providerFor } from "./provider.js";
23
23
  import { modelWire, wireOf, WIRES } from "./wires.js";
24
24
  import { PLAN_PROVIDER, signedIn } from "./chatgpt-plan.js";
25
+ import { loadRecipe } from "./harness-recipe.js";
26
+ import { recipeServerEntry } from "./harness-recipe-entry.js";
25
27
  /** A module of entries a test merges over the built-in ones (HarnessTableModule), by absolute path. */
26
28
  export const HARNESS_TABLE_ENV = "AGENTRUN_HARNESS_TABLE";
27
29
  /** The harness modules the owner names (the server's `harnessModules`), as a JSON array of absolute paths: each adds
@@ -429,6 +431,35 @@ function modulesOf(env) {
429
431
  return paths;
430
432
  }
431
433
  const harnessId = new RegExp(HARNESS_ID_PATTERN);
434
+ /** The setting that names the recipes a server's table adds and the data directory they are installed in, as a run's
435
+ * process carries it (HARNESS_RECIPES_SETTING, `--harness-recipe`): JSON `{ "data": dir, "files": [absolute paths],
436
+ * "signIn": true }`, `signIn` only from a server whose start proved --harness-sign-in (server.ts harnessSignInRefusal),
437
+ * never from the owner's setting, so a runner apart never runs a recipe on its owner's sign-in. */
438
+ export const HARNESS_RECIPES_ENV = "AGENTRUN_HARNESS_RECIPES";
439
+ /** The recipes `env` names (HARNESS_RECIPES_ENV): none when it names none. */
440
+ function recipesOf(env) {
441
+ const given = env[HARNESS_RECIPES_ENV];
442
+ if (!given)
443
+ return undefined;
444
+ const shape = `${HARNESS_RECIPES_ENV} is JSON { "data": the data directory, "files": recipe paths, "signIn": true or absent }`;
445
+ let parsed;
446
+ try {
447
+ parsed = JSON.parse(given);
448
+ }
449
+ catch {
450
+ throw new Error(shape);
451
+ }
452
+ if (!parsed || typeof parsed.data !== "string" || !Array.isArray(parsed.files) || !parsed.files.every((file) => typeof file === "string") || (parsed.signIn !== undefined && parsed.signIn !== true))
453
+ throw new Error(shape);
454
+ return parsed.files.length ? { data: parsed.data, files: parsed.files, signIn: parsed.signIn === true } : undefined;
455
+ }
456
+ /** The owner's setting that names harness recipes when no option does: recipe files, comma-separated. */
457
+ export const HARNESS_RECIPES_SETTING = "AGENTRUN_SERVE_HARNESS_RECIPES";
458
+ /** The recipe files `given` names (a server's or a runner's `--harness-recipe`, else HARNESS_RECIPES_SETTING). */
459
+ export const harnessRecipesOf = (given, env) => given?.length ? [...given] : (env[HARNESS_RECIPES_SETTING] ?? "").split(",").map((name) => name.trim()).filter(Boolean);
460
+ /** HARNESS_RECIPES_ENV for the recipe files `files` names, installed into `data`: none for none. `signIn` only where the
461
+ * server's start proved --harness-sign-in. */
462
+ export const harnessRecipesEnv = (files, data, { signIn = false } = {}) => (files.length ? { [HARNESS_RECIPES_ENV]: JSON.stringify({ data: resolve(data), files: files.map((file) => resolve(file)), ...(signIn ? { signIn: true } : {}) }) } : {});
432
463
  /** The table `env` runs on: the built-in entries; then, only under a test runner (node --test's NODE_TEST_CONTEXT, which a
433
464
  * server's and a run's processes there carry), a test's module's (HARNESS_TABLE_ENV) merged over them by id; then the
434
465
  * harnesses each of the owner's harness modules adds (HARNESS_MODULES_ENV), under a test runner or not. A module adds
@@ -440,9 +471,10 @@ const harnessId = new RegExp(HARNESS_ID_PATTERN);
440
471
  export function harnessTable(env) {
441
472
  const path = env.NODE_TEST_CONTEXT ? env[HARNESS_TABLE_ENV] : undefined;
442
473
  const modules = modulesOf(env);
443
- if (!path && !modules.length)
474
+ const recipes = recipesOf(env);
475
+ if (!path && !modules.length && !recipes)
444
476
  return BUILTIN;
445
- const key = JSON.stringify([path ?? null, modules]);
477
+ const key = JSON.stringify([path ?? null, modules, recipes ?? null]);
446
478
  let table = loaded.get(key);
447
479
  if (!table) {
448
480
  const built = { ...BUILTIN };
@@ -468,11 +500,30 @@ export function harnessTable(env) {
468
500
  built[id] = Object.freeze({ ...entry, id });
469
501
  }
470
502
  }
503
+ // Then each recipe the owner names (HARNESS_RECIPES_ENV): loaded under its five rules, so a refused one, or one whose
504
+ // id a module or another recipe already adds, refuses the start in words (a recipe never takes a built-in's id).
505
+ for (const file of recipes?.files ?? []) {
506
+ const entry = recipeServerEntry(file, recipes.data, { signIn: recipes.signIn });
507
+ if (Object.hasOwn(built, entry.id))
508
+ throw new Error(`harness recipe ${file} names ${entry.id}, which a harness module or another recipe already adds`);
509
+ built[entry.id] = entry;
510
+ madeByRecipe.set(entry, loadRecipe(file).recipe.model.billing);
511
+ }
471
512
  table = Object.freeze(built);
472
513
  loaded.set(key, table);
473
514
  }
474
515
  return table;
475
516
  }
517
+ /** The entries harnessTable made from a recipe (HARNESS_RECIPES_ENV), with the recipe's billing. */
518
+ const madeByRecipe = new WeakMap();
519
+ /** How `id` on `env`'s table is billed when it is a recipe's harness, else undefined. A recipe's install, its check's
520
+ * note and its owner's sign-in are the server user's alone (0700 and 0600 under `<data>/harnesses`), so its runs run as
521
+ * that user, never a slot's; and a plan-billed one runs on keys saved for it or, for a person's run alone, its owner's
522
+ * own sign-in (harness-recipe-entry.ts serverRoute). */
523
+ export const recipeHarness = (env, id) => {
524
+ const entry = Object.hasOwn(harnessTable(env), id) ? harnessTable(env)[id] : undefined;
525
+ return entry === undefined ? undefined : madeByRecipe.get(entry);
526
+ };
476
527
  /** The owner's setting that names harness modules when no option does: package names or paths, comma-separated. */
477
528
  export const HARNESS_MODULES_SETTING = "AGENTRUN_SERVE_HARNESS_MODULES";
478
529
  /** The harness modules `given` names (a server's or a runner's `--harness-module`, else HARNESS_MODULES_SETTING): none
@@ -510,7 +561,7 @@ export const builtinHarness = (id) => BUILTIN[id ?? DEFAULT_HARNESS];
510
561
  /** The owner's table on `env`: the built-in entries and those its harness modules add (HARNESS_MODULES_ENV), never a test
511
562
  * table's. What a run weighs and whether one fits (host.ts, runner/memory-claim.ts) read it, so a test's stand-in admits
512
563
  * as the built-in harness it stands in for, and a module's harness as its entry declares. */
513
- export const ownerTable = (env) => harnessTable(env[HARNESS_MODULES_ENV] ? { [HARNESS_MODULES_ENV]: env[HARNESS_MODULES_ENV] } : {});
564
+ export const ownerTable = (env) => harnessTable({ ...(env[HARNESS_MODULES_ENV] ? { [HARNESS_MODULES_ENV]: env[HARNESS_MODULES_ENV] } : {}), ...(env[HARNESS_RECIPES_ENV] ? { [HARNESS_RECIPES_ENV]: env[HARNESS_RECIPES_ENV] } : {}) });
514
565
  /** The entry of harness `id` (none: the default, pi) on the owner's table (ownerTable); undefined for one it has not. */
515
566
  export const ownerHarness = (env, id) => {
516
567
  const table = ownerTable(env);
@@ -528,3 +579,7 @@ export const harnessOf = (env, id) => harnessTable(env)[id ?? DEFAULT_HARNESS];
528
579
  export const onAdapter = (env, id) => harnessOf(env, id)?.facts !== undefined;
529
580
  /** The harness a definition stores: none for the default, which is never stored. */
530
581
  export const storedHarness = (id) => (id === undefined || id === DEFAULT_HARNESS ? undefined : id);
582
+ /** The managed adapter for an imported native protocol. Source discovery never chooses execution by a bare runtime string. */
583
+ export const harnessForSourceProtocol = (protocol) => ({
584
+ "codex-json": "codex", "claude-json": "claude-agent",
585
+ })[protocol];
@@ -0,0 +1,6 @@
1
+ /** The most a zip may unpack to, all its files together: Antigravity's 274 MB zip unpacks to 853 MB. */
2
+ export declare const ZIP_MAX_UNPACKED: number;
3
+ /** Unpacks the zip at `archive` into `root` (an empty folder): see the header for what it refuses. */
4
+ export declare function unzipInto(archive: string, root: string, options?: {
5
+ maxUnpacked?: number;
6
+ }): Promise<void>;
@@ -0,0 +1,203 @@
1
+ // A zip archive unpacked by node alone (Google Antigravity's release is a zip on every platform): no unzip on the host is
2
+ // needed or run. Only a verified archive reaches it (harness-archive.ts checks its sha256 first), and still it trusts
3
+ // nothing the archive says:
4
+ // - its central directory is read from the end (zip64 too), and each entry's data is found from its own local header;
5
+ // - a name that is absolute, holds `..`, a backslash, a drive letter or a NUL is refused, as is any name twice;
6
+ // - a symlink, a device or any type but a file or a folder is refused, as is an encrypted entry or a method other than
7
+ // stored and deflate;
8
+ // - each file is written new (never over another), its size and CRC-32 checked against the directory's, its execute
9
+ // bits kept (0755, else 0644), and the sum of what it unpacks is held under a limit, checked before and while writing.
10
+ // A refusal throws before or while writing into `root`, which is the caller's fresh folder to remove.
11
+ import { createReadStream, createWriteStream } from "node:fs";
12
+ import { chmod, mkdir, open } from "node:fs/promises";
13
+ import { dirname, join } from "node:path";
14
+ import { Transform } from "node:stream";
15
+ import { pipeline } from "node:stream/promises";
16
+ import { crc32, createInflateRaw } from "node:zlib";
17
+ /** The most a zip may unpack to, all its files together: Antigravity's 274 MB zip unpacks to 853 MB. */
18
+ export const ZIP_MAX_UNPACKED = 4 * 1024 * 1024 * 1024;
19
+ /** The most entries a zip may hold. */
20
+ const ZIP_MAX_ENTRIES = 100_000;
21
+ const EOCD = 0x06054b50;
22
+ const ZIP64_LOCATOR = 0x07064b50;
23
+ const ZIP64_EOCD = 0x06064b50;
24
+ const CENTRAL = 0x02014b50;
25
+ const LOCAL = 0x04034b50;
26
+ const MAX32 = 0xffffffff;
27
+ const MAX16 = 0xffff;
28
+ /** `name` as a path inside the root (forward slashes, no trailing one), or why it is refused. */
29
+ function safeName(name) {
30
+ if (name.includes("\0"))
31
+ return { why: "holds a NUL" };
32
+ if (name.includes("\\"))
33
+ return { why: "holds a backslash" };
34
+ if (name.startsWith("/") || /^[A-Za-z]:/.test(name))
35
+ return { why: "is absolute" };
36
+ const parts = name.split("/").filter((part, i, all) => !(part === "" && i === all.length - 1));
37
+ if (!parts.length || parts.some((part) => part === "" || part === "." || part === ".."))
38
+ return { why: "leaves the archive's folder or is empty" };
39
+ return { path: parts.join("/") };
40
+ }
41
+ async function readAt(file, position, length) {
42
+ const buffer = Buffer.alloc(length);
43
+ const { bytesRead } = await file.read(buffer, 0, length, position);
44
+ if (bytesRead !== length)
45
+ throw new Error(`the zip ends at byte ${position + bytesRead}, before what its directory points at`);
46
+ return buffer;
47
+ }
48
+ /** The central directory of the zip `file` (`size` bytes long): its entries, each name and type checked. */
49
+ async function directory(file, size) {
50
+ // The end record: 22 bytes, then a comment of at most 65535.
51
+ const tailLength = Math.min(size, 22 + MAX16);
52
+ const tail = await readAt(file, size - tailLength, tailLength);
53
+ let at = -1;
54
+ for (let i = tail.length - 22; i >= 0; i--)
55
+ if (tail.readUInt32LE(i) === EOCD) {
56
+ at = i;
57
+ break;
58
+ }
59
+ if (at < 0)
60
+ throw new Error("it is not a zip: no end of central directory");
61
+ let count = tail.readUInt16LE(at + 10);
62
+ let cdSize = tail.readUInt32LE(at + 12);
63
+ let cdOffset = tail.readUInt32LE(at + 16);
64
+ if (count === MAX16 || cdSize === MAX32 || cdOffset === MAX32) {
65
+ const locatorAt = size - tailLength + at - 20;
66
+ if (locatorAt < 0)
67
+ throw new Error("its zip64 end record is missing");
68
+ const locator = await readAt(file, locatorAt, 20);
69
+ if (locator.readUInt32LE(0) !== ZIP64_LOCATOR)
70
+ throw new Error("its zip64 end record is missing");
71
+ const record = await readAt(file, Number(locator.readBigUInt64LE(8)), 56);
72
+ if (record.readUInt32LE(0) !== ZIP64_EOCD)
73
+ throw new Error("its zip64 end record is not one");
74
+ count = Number(record.readBigUInt64LE(32));
75
+ cdSize = Number(record.readBigUInt64LE(40));
76
+ cdOffset = Number(record.readBigUInt64LE(48));
77
+ }
78
+ if (count > ZIP_MAX_ENTRIES)
79
+ throw new Error(`it holds ${count} entries, past the ${ZIP_MAX_ENTRIES} one may`);
80
+ if (cdOffset + cdSize > size)
81
+ throw new Error("its central directory runs past its end");
82
+ const cd = await readAt(file, cdOffset, cdSize);
83
+ const entries = [];
84
+ const seen = new Set();
85
+ let p = 0;
86
+ for (let n = 0; n < count; n++) {
87
+ if (p + 46 > cd.length || cd.readUInt32LE(p) !== CENTRAL)
88
+ throw new Error(`its central directory's entry ${n + 1} is not one`);
89
+ const madeBy = cd.readUInt16LE(p + 4);
90
+ const flags = cd.readUInt16LE(p + 8);
91
+ const method = cd.readUInt16LE(p + 10);
92
+ const crc = cd.readUInt32LE(p + 16);
93
+ let compressed = cd.readUInt32LE(p + 20);
94
+ let length = cd.readUInt32LE(p + 24);
95
+ const nameLength = cd.readUInt16LE(p + 28);
96
+ const extraLength = cd.readUInt16LE(p + 30);
97
+ const commentLength = cd.readUInt16LE(p + 32);
98
+ const external = cd.readUInt32LE(p + 38);
99
+ let local = cd.readUInt32LE(p + 42);
100
+ const raw = cd.subarray(p + 46, p + 46 + nameLength);
101
+ const name = raw.toString(flags & 0x800 ? "utf8" : "latin1");
102
+ // zip64: the sizes and offset that read 0xffffffff are in the extra field 0x0001, in that order.
103
+ let e = p + 46 + nameLength;
104
+ const extraEnd = e + extraLength;
105
+ while (e + 4 <= extraEnd) {
106
+ const id = cd.readUInt16LE(e);
107
+ const dataLength = cd.readUInt16LE(e + 2);
108
+ if (id === 0x0001) {
109
+ let q = e + 4;
110
+ if (length === MAX32) {
111
+ length = Number(cd.readBigUInt64LE(q));
112
+ q += 8;
113
+ }
114
+ if (compressed === MAX32) {
115
+ compressed = Number(cd.readBigUInt64LE(q));
116
+ q += 8;
117
+ }
118
+ if (local === MAX32) {
119
+ local = Number(cd.readBigUInt64LE(q));
120
+ q += 8;
121
+ }
122
+ }
123
+ e += 4 + dataLength;
124
+ }
125
+ p = extraEnd + commentLength;
126
+ const checked = safeName(name);
127
+ const said = JSON.stringify(name.slice(0, 200));
128
+ if ("why" in checked)
129
+ throw new Error(`its entry ${said} ${checked.why}`);
130
+ if (seen.has(checked.path))
131
+ throw new Error(`its entry ${said} is in it twice`);
132
+ seen.add(checked.path);
133
+ if (flags & 0x1)
134
+ throw new Error(`its entry ${said} is encrypted`);
135
+ // A Unix-made entry's type and mode are in the high half of its external attributes; others are files or folders.
136
+ const unixMode = madeBy >> 8 === 3 ? external >>> 16 : 0;
137
+ const type = unixMode & 0o170000;
138
+ const dir = name.endsWith("/") || type === 0o040000 || (madeBy >> 8 !== 3 && (external & 0x10) !== 0);
139
+ if (type === 0o120000)
140
+ throw new Error(`its entry ${said} is a symlink`);
141
+ if (type !== 0 && type !== 0o100000 && type !== 0o040000)
142
+ throw new Error(`its entry ${said} is neither a file nor a folder`);
143
+ if (!dir && method !== 0 && method !== 8)
144
+ throw new Error(`its entry ${said} is compressed with method ${method}, and only stored and deflate are read`);
145
+ entries.push({ name: checked.path, dir, mode: unixMode & 0o777, method, crc, compressed, size: length, local });
146
+ }
147
+ return entries;
148
+ }
149
+ /** Unpacks the zip at `archive` into `root` (an empty folder): see the header for what it refuses. */
150
+ export async function unzipInto(archive, root, options = {}) {
151
+ const maxUnpacked = options.maxUnpacked ?? ZIP_MAX_UNPACKED;
152
+ const file = await open(archive, "r");
153
+ try {
154
+ const entries = await directory(file, (await file.stat()).size);
155
+ const total = entries.reduce((sum, entry) => sum + (entry.dir ? 0 : entry.size), 0);
156
+ if (total > maxUnpacked)
157
+ throw new Error(`it unpacks to ${total} bytes, past the ${maxUnpacked} a zip may`);
158
+ let written = 0;
159
+ for (const entry of entries) {
160
+ const target = join(root, ...entry.name.split("/"));
161
+ if (entry.dir) {
162
+ await mkdir(target, { recursive: true, mode: 0o755 });
163
+ continue;
164
+ }
165
+ await mkdir(dirname(target), { recursive: true, mode: 0o755 });
166
+ // Its data: after its own local header, whose name and extra lengths may differ from the directory's.
167
+ const header = await readAt(file, entry.local, 30);
168
+ if (header.readUInt32LE(0) !== LOCAL)
169
+ throw new Error(`its entry ${JSON.stringify(entry.name)} has no local header where its directory says`);
170
+ const start = entry.local + 30 + header.readUInt16LE(26) + header.readUInt16LE(28);
171
+ let crc = 0;
172
+ let got = 0;
173
+ const counted = new Transform({
174
+ transform(chunk, _encoding, done) {
175
+ got += chunk.length;
176
+ written += chunk.length;
177
+ if (got > entry.size || written > maxUnpacked)
178
+ return done(new Error(`its entry ${JSON.stringify(entry.name)} unpacks past the size its directory says`));
179
+ crc = crc32(chunk, crc);
180
+ done(null, chunk);
181
+ },
182
+ });
183
+ const source = entry.compressed ? createReadStream(archive, { start, end: start + entry.compressed - 1 }) : undefined;
184
+ const sink = createWriteStream(target, { flags: "wx", mode: 0o600 });
185
+ if (!source)
186
+ sink.end();
187
+ else if (entry.method === 0)
188
+ await pipeline(source, counted, sink);
189
+ else
190
+ await pipeline(source, createInflateRaw(), counted, sink);
191
+ if (!source)
192
+ await new Promise((done, reject) => sink.once("close", done).once("error", reject));
193
+ if (got !== entry.size)
194
+ throw new Error(`its entry ${JSON.stringify(entry.name)} unpacks to ${got} bytes, and its directory says ${entry.size}`);
195
+ if (crc >>> 0 !== entry.crc >>> 0)
196
+ throw new Error(`its entry ${JSON.stringify(entry.name)} fails its CRC-32`);
197
+ await chmod(target, entry.mode & 0o111 ? 0o755 : 0o644);
198
+ }
199
+ }
200
+ finally {
201
+ await file.close();
202
+ }
203
+ }
package/dist/ids.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /** A UUIDv7: time-ordered, so a listing by (time, id) is stable. Two minted in one millisecond keep their order: the 12
2
+ * bits after the time count them up (RFC 9562's monotonic counter), and a clock that steps back keeps the last
3
+ * millisecond, so each id sorts after the one before it. Without that, two runs started in one millisecond tie on
4
+ * started_at, and their random ids list and claim them in either order; two edits tie on created_at, and the newer
5
+ * revision can be numbered first.
6
+ * `{ at }`: the id of that instant, outside the count: its time is `at` (one in the past is kept, never moved to the last
7
+ * millisecond minted), the 12 bits after it random. For a record written as of an earlier time (eval-previous.ts seeds
8
+ * runs that started a day apart), whose id must sort by that time. */
9
+ export declare function uuidv7(when?: number | {
10
+ at: number;
11
+ }): string;
package/dist/ids.js ADDED
@@ -0,0 +1,36 @@
1
+ // The one UUIDv7 minter: every run id (a managed run's, an SDK run's, a promotion's replays, an eval's seeded runs), the
2
+ // ids of agents, revisions and tentative inline agents, and upload ids. No imports, so any module takes it alone.
3
+ /** The last millisecond a UUIDv7 was minted in, and how many were minted in it. */
4
+ let mintedMs = -1;
5
+ let mintedInMs = 0;
6
+ /** A UUIDv7: time-ordered, so a listing by (time, id) is stable. Two minted in one millisecond keep their order: the 12
7
+ * bits after the time count them up (RFC 9562's monotonic counter), and a clock that steps back keeps the last
8
+ * millisecond, so each id sorts after the one before it. Without that, two runs started in one millisecond tie on
9
+ * started_at, and their random ids list and claim them in either order; two edits tie on created_at, and the newer
10
+ * revision can be numbered first.
11
+ * `{ at }`: the id of that instant, outside the count: its time is `at` (one in the past is kept, never moved to the last
12
+ * millisecond minted), the 12 bits after it random. For a record written as of an earlier time (eval-previous.ts seeds
13
+ * runs that started a day apart), whose id must sort by that time. */
14
+ export function uuidv7(when = Date.now()) {
15
+ const bytes = Buffer.from(crypto.getRandomValues(new Uint8Array(16)));
16
+ if (typeof when === "number") {
17
+ if (when > mintedMs) {
18
+ mintedMs = when;
19
+ mintedInMs = 0;
20
+ }
21
+ else if (++mintedInMs > 0xfff) {
22
+ mintedMs += 1;
23
+ mintedInMs = 0;
24
+ }
25
+ bytes.writeUIntBE(mintedMs, 0, 6);
26
+ bytes[6] = 0x70 | (mintedInMs >> 8);
27
+ bytes[7] = mintedInMs & 0xff;
28
+ }
29
+ else {
30
+ bytes.writeUIntBE(when.at, 0, 6);
31
+ bytes[6] = 0x70 | (bytes[6] & 0x0f);
32
+ }
33
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
34
+ const hex = bytes.toString("hex");
35
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
36
+ }
@@ -1,4 +1,4 @@
1
- import type { Workspace } from "../workspace/index.js";
1
+ import { type Workspace } from "../workspace/index.js";
2
2
  import type { Problem } from "./check.js";
3
3
  import { type Snapshot } from "./folder.js";
4
4
  /** A run's merge, one a round: its compiled draft's files, already checked, and its owner's correction. */
@@ -108,3 +108,16 @@ export declare function putCorrections(ws: Workspace, input: {
108
108
  reason: "conflict" | "refused";
109
109
  problems: Problem[];
110
110
  }>;
111
+ /**
112
+ * Run `runId`'s text taken off the folder's current files, at its purge (agent-delete.ts purgeRun): first its learned
113
+ * workflows (forgetRunWorkflows), whether or not it left a diff file; then the lines each of its merges added to
114
+ * corrections.md, as its diff file keeps them, dropped from main in one host commit per merge (a line a person edited
115
+ * since is theirs and stays); each other merge's diff that shows such a line as context written without it; then the
116
+ * run's diff files deleted, last, so a call stopped part way finds what it has left to do. Its merges stay in the
117
+ * folder's git history until a learning reset or its agent's purge deletes the folder. Idempotent: each merge's scrub
118
+ * lands once, nothing left to drop makes no commit, and a run with no diff file and no workflow here is no work.
119
+ * `commit`: the host's last commit, when one was made.
120
+ */
121
+ export declare function forgetRunText(ws: Workspace, runId: string): Promise<{
122
+ commit?: string;
123
+ }>;