@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
@@ -17,15 +17,13 @@ import { held, held as runnerSeam } from "./held.js";
17
17
  import { savedGatewayIn } from "../model-gateway.js";
18
18
  import { noServerKeyWords, runKeyEndedFor, runModelOrigin, withRunModelKey, withRunModelKeyLater } from "../run-model-key.js";
19
19
  import { openRunLaunch } from "../store/seal.js";
20
+ import { declaredFrom } from "../run-keys.js";
20
21
  import { StoreLaunchMissing } from "../store/store.js";
21
22
  import { withRequestMetadata } from "../request-metadata.js";
22
23
  /** Every server secret a run might be handed (runs.ts RUN_SECRETS is the tool and model keys; the decision keys go beside
23
24
  * them). Read from the store into a working environment, then scoped to the run below. */
24
25
  const CANDIDATES = [...new Set([...RUN_SECRETS, ...DECISION_KEYS])];
25
- /** The environment a claimed run's tools run under: the runner's base (its secrets stripped), with the keys the run's
26
- * revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
27
- * decision provider keys. A fresh object per claim, so no run's keys reach another's. */
28
- export async function claimSecrets(deps, revision, launch) {
26
+ export async function claimSecrets(deps, revision, launch, runId) {
29
27
  const base = withoutSecrets(deps.env ?? {});
30
28
  const working = await workingEnv(deps);
31
29
  const needs = await needsOf(revision);
@@ -43,6 +41,20 @@ export async function claimSecrets(deps, revision, launch) {
43
41
  const decision = decisionKeysFor(working, { providers: needs.decisionProviders, parallelWeb: launch.plane ? handsParallel(launch.plane) : false });
44
42
  for (const [name, value] of Object.entries(decision))
45
43
  env[name] = value;
44
+ // The run's own tool keys, sealed with its launch: each one its revision declares, over the server's by the same name.
45
+ // Opened by a runner, which holds the seal key; a run's own process is handed them with the rest of its claim's keys.
46
+ if (runId !== undefined && deps.sealKey && deps.store.runs) {
47
+ const carried = await openRunKeys({ runs: deps.store.runs, sealKey: deps.sealKey }, runId);
48
+ const declared = carried ? declaredFrom(needs, revision) : [];
49
+ const laid = Object.entries(carried ?? {}).filter(([name]) => declared.includes(name));
50
+ if (laid.length) {
51
+ if (!deps.redact)
52
+ throw new Error(`Run ${runId} carries its own tool keys (${laid.map(([name]) => name).join(", ")}), and this claim has no redactor to cut them from what the run writes: none is laid.`);
53
+ deps.redact.carry(runId, laid.map(([, value]) => value));
54
+ }
55
+ for (const [name, value] of laid)
56
+ env[name] = value;
57
+ }
46
58
  // The server's ChatGPT sign-in, read from the store for this claim: its token is asked at each request the run's model
47
59
  // proxy sends (chatgpt-plan.ts), never put on the environment its tools run under (a symbol no spawn copies). Only for
48
60
  // a run that can reach a plan model: one pinned to a key's model (and its tiers on keys) never holds the sign-in, which
@@ -77,6 +89,13 @@ async function workingEnv(deps) {
77
89
  }
78
90
  return working;
79
91
  }
92
+ /** `keys` (learnedDecisionKeys') laid onto `env`, a claim's environment, where it holds no value of that name: what the
93
+ * claim laid stays, a run's own tool key over the server's above all. A name both read holds the same server key. */
94
+ export function underClaimed(env, keys) {
95
+ for (const [name, value] of Object.entries(keys))
96
+ if (!env[name])
97
+ env[name] = value;
98
+ }
80
99
  /** The decision keys a run's learned workflows need, beside those claimSecrets scoped to its revision (whose own nodes
81
100
  * are all needsOf reads, so an agentic run gets none there): the keys of the providers the chosen workflows' typed
82
101
  * questions name (decisions.ts providersNamed, Jev for a node that names none), but any provider `allowed` refuses (the
@@ -204,6 +223,21 @@ export async function openRunModelKey(deps, runId) {
204
223
  throw new Error("This run's launch secrets do not open with this runner's seal key: its model key is not sent.");
205
224
  return opened.model;
206
225
  }
226
+ /** Run `runId`'s own tool keys as its launch's sealed column holds them (run-keys.ts), opened under `deps.sealKey`: none
227
+ * for a launch that holds none (or no launch row). Throws, in words, where the launch does not open. */
228
+ export async function openRunKeys(deps, runId) {
229
+ const sealed = await deps.runs.launch(runId).then((launch) => launch.sealed, (error) => {
230
+ if (error instanceof StoreLaunchMissing)
231
+ return null;
232
+ throw error;
233
+ });
234
+ if (sealed === null)
235
+ return undefined;
236
+ const opened = openRunLaunch(deps.sealKey, runId, sealed);
237
+ if (!opened)
238
+ throw new Error("This run's launch secrets do not open with this runner's seal key: its keys are not sent.");
239
+ return opened.keys;
240
+ }
207
241
  /**
208
242
  * The run's own model key for claim `runId`, opened from its launch's sealed column under the runner's seal key (the
209
243
  * server sealed it there with mcp_auth, store/seal.ts). Undefined only where the server has no gateway and the run holds
@@ -56,8 +56,8 @@ import { isWebHostTool } from "../tool-list.js";
56
56
  import { hostToolOf } from "../host-tools.js";
57
57
  import { ASK_TOOL, askPerson } from "../tools.js";
58
58
  import { fakedPlane } from "../web-fake.js";
59
- import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
60
- import { mcpWhereHeld, mediaForClaim } from "./mcp-run.js";
59
+ import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, tierModelKeys, underClaimed, withoutModelKeys } from "./claim-secrets.js";
60
+ import { mcpWhereHeld } from "./mcp-run.js";
61
61
  import { held as runnerSeam, heldSignInReads } from "./held.js";
62
62
  import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
63
63
  import { decisionProvidersIn } from "../decisions.js";
@@ -83,6 +83,9 @@ import { prCheckoutForClaim } from "./pr-checkout.js";
83
83
  import { holdStored, storeSecrets } from "./store-secrets.js";
84
84
  import { bashPolicyOf } from "../bash-read-only.js";
85
85
  import { monidForClaim, withMonid } from "./monid-run.js";
86
+ import { verifyPlacedProject, movedSkillFiles } from "../source-sync/claim.js";
87
+ import { projectCheckpointForRun } from "./project-checkpoint.js";
88
+ import { sourceAuxiliaryAdmitter } from "../source-sync/auxiliary.js";
86
89
  /** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
87
90
  export const cliRefusesKind = (kind) => kind === "browser" ? "This agent's computer is a browser, which only the pi harness drives here: pick pi for this agent, or another kind of computer in Settings → Computers." : undefined;
88
91
  /** The run's model and the catalog that prices it, as main chooses a CLI run's (app.ts wireModels and runModels): on the
@@ -277,6 +280,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
277
280
  if (!revisionRow)
278
281
  throw new Error(`run ${claim.runId}: its revision ${runRow.revisionId} is gone from the store`);
279
282
  const body = (revisionRow.body ?? {});
283
+ const movedProject = await verifyPlacedProject(deps.store, runRow, revisionRow, launch, { data: deps.data, sealKey: deps.sealKey, env: deps.env, ...(run.signal ? { signal: run.signal } : {}), control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
280
284
  const revision = { kind: revisionRow.kind, body };
281
285
  const granted = body.tools ?? [];
282
286
  // The harness: the launch's, else the revision's. Its table entry (facts, model choice, adapter, skill check), read from
@@ -331,7 +335,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
331
335
  // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
332
336
  const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
333
337
  redact.hold(values); };
334
- const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped: () => launch.maxCostUsd !== undefined, media: mediaForClaim(deps.env, web, deps.saveSlots) });
338
+ const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web, slots: deps.saveSlots } });
335
339
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
336
340
  holds.hold({ passed: mcp });
337
341
  // The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
@@ -358,7 +362,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
358
362
  : await openRunWorkspace({ mode: 2, agentId: runRow.agentId, runId: claim.runId, archil, log });
359
363
  holds.hold({ ws });
360
364
  // The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts).
361
- const checkout = body.checkout === "pull_request" ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part })) : undefined;
365
+ const checkout = body.checkout ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part }), body.checkout) : undefined;
362
366
  holds.hold({ checkout });
363
367
  // A run's own process copies nothing: its runner placed them before the process started (run-child-host.ts).
364
368
  if (!(deps.sealKey === undefined && runnerSeam()))
@@ -370,13 +374,14 @@ async function cliSpec(launch, run, deps, claim, holds) {
370
374
  const start = learningStartOf(launch);
371
375
  // The revision's own skills laid before they are read, as the pi spec lays them (adapter-run-spec.ts), with the kind's
372
376
  // skill of a desktop or a phone (the revision's computer setting), in the harness's skill list beside the revision's.
373
- const kindSkills = await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
377
+ const kindSkills = movedProject ? [] : await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
378
+ const currentSkills = movedProject ? await movedSkillFiles(ws.workspace, body.skills ?? {}, settingOfDefinition(body)?.computer.kind) : [...Object.keys(body.skills ?? {}), ...kindSkills];
374
379
  // A learning run's seed read as the pi spec reads it (runner/learning-seed.ts): its learned workflows, the ones
375
380
  // learned_workflow runs.
376
381
  const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
377
382
  const learningFolder = () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil }));
378
383
  const seedLaid = start && !seedFailed(start)
379
- ? await layLearningSeed({ seed: start.seed, folder: learningFolder, shown, log, ...(start.noWorkflows ? { workflows: false } : {}) })
384
+ ? await layLearningSeed({ seed: start.seed, folder: learningFolder, store: deps.sealKey ? deps.store : null, shown, log, ...(start.noWorkflows ? { workflows: false } : {}) })
380
385
  : undefined;
381
386
  // The run's computer, from the one shared claim-time function (the pi spec takes the same): none for a runner place.
382
387
  // It throws computer_unavailable (nothing made) when the computer cannot be had: the run fails in its words.
@@ -417,7 +422,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
417
422
  const bashPolicy = bashPolicyOf(body.toolSettings);
418
423
  // A computer that replaced an earlier claim's holds its acts to what it showed, as the pi spec's does.
419
424
  const tools = await runTools(ws.workspace, computer.computer, { mode, context, aliases: [scratch], ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }), ...(computer.replaced ? { replaced: true } : {}) });
420
- holds.hold({ tools });
425
+ let remoteProjectCapture = false;
426
+ holds.hold({ tools: { end: () => remoteProjectCapture ? Promise.resolve() : tools.end() } });
421
427
  const root = runFolder(deps.data, runRow.agentId, claim.runId);
422
428
  // The system prompt, as main's harness branch builds it: the environment line, the instructions with what the agent
423
429
  // learned laid in (learning.ts laidLearned, from the launch's learning start, so the runner reads no learning folder), its
@@ -426,8 +432,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
426
432
  // pi spec gives it), then the effort guidance.
427
433
  // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
428
434
  const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
429
- const check = await entry.skillCheck?.();
430
- const { system: instructions, native } = await systemOf(laid, [...Object.keys(body.skills ?? {}), ...kindSkills], ws.workspace, check, { onDemand: readsFiles(granted) });
435
+ const check = movedProject ? undefined : await entry.skillCheck?.();
436
+ const { system: instructions, native } = await systemOf(laid, currentSkills, ws.workspace, check, { onDemand: movedProject || readsFiles(granted) });
431
437
  const guidance = effortGuidance(launch.effort);
432
438
  // The run's model (the launch's, pinned at start, else the revision's) and its adapter, as main builds them, on the
433
439
  // environment main's server gives its runs: the server's data directory named (DATA_ENV), so the CLI's install is
@@ -436,7 +442,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
436
442
  // store's), held by the runner's one redactor and this spec's log cut before anything can echo one. Its model's key goes
437
443
  // to the model choice and the adapter's provider (withModelKeys, never enumerable), so a key saved in
438
444
  // Settings → Model keys runs the next run with no restart, as one set where AgentRun starts does.
439
- const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, revisionRow, launch);
445
+ const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: deps.env, redact: run.redact }, revisionRow, launch, claim.runId);
440
446
  // The run's own model key, when its caller handed one (model_key): opened at every claim, held by the redactors, read by
441
447
  // its model route alone; the CLI's process and its tools never carry it, nor any other model key then.
442
448
  // A run that starts on the server's key holds the claim's key holder too: a message's first key reaches its next request.
@@ -594,7 +600,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
594
600
  // Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit and a replay check
595
601
  // are skipped, in words, where the run brought its own key or the server holds none.
596
602
  const spendOff = await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey);
597
- const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff };
603
+ const admitAuxiliary = runnerSeam() ? undefined : sourceAuxiliaryAdmitter(deps.store, { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
604
+ const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff, admitAuxiliary };
598
605
  // A replay run's or a shadow's grader (runner/compare-end.ts), on a proxy of its own beside the CLI session's, as pi's
599
606
  // is (adapter-run-spec.ts graderRouteOf), reached through the session's port while it is up. None: compared whole.
600
607
  const graderRoute = launch.replay || launch.audit ? await graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, [held, cut], claim) : undefined;
@@ -602,7 +609,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
602
609
  tierRoutes.set(GRADER, graderRoute);
603
610
  // Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
604
611
  // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself.
605
- const learned = await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, folder: learningFolder, shown, spendOff }, seedLaid?.workflows ?? []);
612
+ const learned = await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, folder: learningFolder, shown, spendOff, admitAuxiliary }, seedLaid?.workflows ?? []);
606
613
  const firstChoice = learned.choice;
607
614
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
608
615
  // answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
@@ -621,7 +628,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
621
628
  const learnedKeys = await learnedDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, workflows, (provider) => gate.permissions.policy(provider) !== "deny");
622
629
  for (const redact of new Set([held, cut]))
623
630
  holdClaimed(redact, learnedKeys);
624
- Object.assign(toolEnv, learnedKeys);
631
+ underClaimed(toolEnv, learnedKeys);
625
632
  }
626
633
  handedKeys = runnerSecrets(toolEnv);
627
634
  // The run's resolved tool plane (its web tools' providers), as the pi spec hands it its web tools.
@@ -770,6 +777,10 @@ async function cliSpec(launch, run, deps, claim, holds) {
770
777
  // resume instead, its mount credential with it, as the pi spec's.
771
778
  ...(computer.keeps ? { keptWords: computerKeptWords(computer.keeps) } : {}),
772
779
  release: (how) => holds.release(how),
780
+ ...(movedProject ? { projectCheckpoint: projectCheckpointForRun({ store: deps.store, agentId: runRow.agentId, claim, launch, tools, computer,
781
+ workspace: { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } },
782
+ secrets: async () => runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)),
783
+ }, () => { remoteProjectCapture = true; }) } : {}),
773
784
  endCheckout: () => holds.endCheckout(),
774
785
  };
775
786
  }
@@ -6,6 +6,12 @@ import { ClaimRefused, type LoopFactory } from "./loop-contract.js";
6
6
  export declare class NeverFits extends ClaimRefused {
7
7
  name: string;
8
8
  }
9
+ /** The words a scheduled or triggered run on a plan-billed harness recipe is refused in (harness-recipe-entry.ts
10
+ * serverRoute): such a run takes keys saved for that harness, never its owner's own sign-in, and none are saved yet. */
11
+ export declare const RECIPE_SIGN_IN_PERSON_ONLY = "A scheduled or triggered run on a harness recipe billed to its vendor's plan runs on keys saved for that harness, never on its owner's own sign-in, and this server saves no harness's keys yet: start this run yourself, or run the agent on a harness billed through this server's model proxy.";
12
+ /** Refuses at its claim a run no person started (a schedule's, a trigger's: launch.trigger) on a plan-billed recipe's
13
+ * harness (harness-table.ts recipeHarness), on every path a claim takes (run-child-host.ts staysInRunner, and here). */
14
+ export declare function refuseRecipeTriggerRun(env: NodeJS.ProcessEnv, harness: string, launch: Pick<RunLaunch, "trigger">): void;
9
15
  /** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
10
16
  * returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
11
17
  export declare function resolveRunnerLoop(given: AdapterSpecDeps): (harness: string, launch: RunLaunch, runId: string) => Promise<LoopFactory | undefined>;
@@ -13,7 +13,7 @@ import { createNativeLoop } from "./native-loop.js";
13
13
  // module adds with no adapter facts of its own, on its runner's adapter;
14
14
  // - a CLI harness (claude-agent, codex, opencode) runs on the adapter loop with its own adapter;
15
15
  // - anything else fails the run in words (the dispatch's UnknownHarness).
16
- import { harnessOf } from "../harness-table.js";
16
+ import { harnessOf, recipeHarness } from "../harness-table.js";
17
17
  import { hostMemory, neverFits } from "../host.js";
18
18
  import { resolveHarness } from "./adapters/index.js";
19
19
  import { adapterRunSpecFromLaunch, PI_WIRES } from "./adapter-run-spec.js";
@@ -32,10 +32,20 @@ import { workflowSpecOf } from "./workflow-spec.js";
32
32
  export class NeverFits extends ClaimRefused {
33
33
  name = "NeverFits";
34
34
  }
35
+ /** The words a scheduled or triggered run on a plan-billed harness recipe is refused in (harness-recipe-entry.ts
36
+ * serverRoute): such a run takes keys saved for that harness, never its owner's own sign-in, and none are saved yet. */
37
+ export const RECIPE_SIGN_IN_PERSON_ONLY = "A scheduled or triggered run on a harness recipe billed to its vendor's plan runs on keys saved for that harness, never on its owner's own sign-in, and this server saves no harness's keys yet: start this run yourself, or run the agent on a harness billed through this server's model proxy.";
38
+ /** Refuses at its claim a run no person started (a schedule's, a trigger's: launch.trigger) on a plan-billed recipe's
39
+ * harness (harness-table.ts recipeHarness), on every path a claim takes (run-child-host.ts staysInRunner, and here). */
40
+ export function refuseRecipeTriggerRun(env, harness, launch) {
41
+ if (launch.trigger !== undefined && recipeHarness(env, harness) === "plan")
42
+ throw new ClaimRefused(RECIPE_SIGN_IN_PERSON_ONLY);
43
+ }
35
44
  /** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
36
45
  * returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
37
46
  export function resolveRunnerLoop(given) {
38
47
  return async (harness, launch, runId) => {
48
+ refuseRecipeTriggerRun(given.env ?? {}, harness, launch);
39
49
  // The model gateway saved in the console (model-gateway.ts), read from the store at each claim and laid over the run
40
50
  // environment as its variables would be, so a gateway saved or removed since reaches the next run with no restart. A
41
51
  // gateway the runner's environment names wins, and nothing saved is read over it.
@@ -13,6 +13,7 @@ import type { HarnessInstallEntry, HarnessPins } from "../harness-install.js";
13
13
  import type { RunModelKey } from "../store/seal.js";
14
14
  import type { EndOfRunKept, EndOfRunTurn } from "./loop-contract.js";
15
15
  import type { LearnedFirst } from "./learned-first.js";
16
+ import type { ProjectCheckpoint } from "../source-sync/checkpoints.js";
16
17
  /** One MCP tool of the claim, its call made by the runner (mcp-run.ts mcpForClaim), with what the gate reads of it. */
17
18
  export interface HeldMcpTool {
18
19
  readonly name: string;
@@ -54,6 +55,9 @@ export interface HeldComputerAsk {
54
55
  readonly onComputerNote?: (words: string) => void;
55
56
  }
56
57
  export interface Held {
58
+ /** The host captures this claim's placed project once after draining its exported capabilities. No child-selected
59
+ * identifiers, paths, callbacks, workspace or secret values cross this boundary. */
60
+ projectCheckpoint(signal?: AbortSignal): Promise<ProjectCheckpoint>;
57
61
  /** The ChatGPT sign-in's reader (chatgpt-plan.ts planReaderOf), for a run whose models reach the plan; else none. */
58
62
  plan(): Promise<PlanReader | undefined>;
59
63
  /** Whether a browser sign-in handed to the run reads back here (sign-ins-store.ts handedSignInReadsBack). */
@@ -325,6 +325,8 @@ export declare function withdrawnAnswers(entries: readonly {
325
325
  readonly model?: unknown;
326
326
  }[], answeredAt: string, decision?: "withdrawn" | "canceled"): AnswerData[];
327
327
  export interface EndData {
328
+ /** Immutable moved-project candidate or explicit uncertainty, committed atomically with this run end. */
329
+ readonly projectCheckpoint?: import("../source-sync/checkpoints.js").ProjectCheckpoint;
328
330
  readonly state: "ended" | "stopped" | "failed";
329
331
  readonly summary?: string;
330
332
  /** How the run ended beside its state (the store's RunOutcome): an escalation's 'escalated'; a stopped end's 'stopped'
@@ -4,10 +4,12 @@ import type { LearningFolder } from "../learn/folder.js";
4
4
  import type { Recorded } from "../learn/replay-calls.js";
5
5
  import type { RunLaunch } from "../run-launch.js";
6
6
  import type { Store } from "../store/store.js";
7
+ import type { AuxiliaryAdmitter } from "../source-sync/auxiliary.js";
7
8
  import { type FirstChoice } from "./workflow-first.js";
8
9
  /** The claim, as the runner read it, for learnedFirst. */
9
10
  export interface LearnedFirstDeps {
10
11
  readonly store: Store;
12
+ readonly admitAuxiliary?: AuxiliaryAdmitter;
11
13
  readonly sealKey?: Buffer;
12
14
  readonly agentId: string;
13
15
  readonly runId: string;
@@ -8,7 +8,7 @@ import { workflowFirstOf } from "./workflow-first.js";
8
8
  * claim that is refused throws ClaimRefused, as replayClaimed does. */
9
9
  export async function learnedFirst(deps, laid) {
10
10
  const { store, agentId, runId, revisionId, launch, context, log, folder, shown } = deps;
11
- const own = { ...(deps.sealKey ? { sealKey: deps.sealKey } : {}), ...(deps.spendOff ? { spendOff: deps.spendOff } : {}) };
11
+ const own = { ...(deps.sealKey ? { sealKey: deps.sealKey } : {}), ...(deps.spendOff ? { spendOff: deps.spendOff } : {}), ...(deps.admitAuxiliary ? { admitAuxiliary: deps.admitAuxiliary } : {}) };
12
12
  // A replay run lays only the workflow it replays (promotion.ts replayLaid).
13
13
  const laidFlows = replayLaid(launch, laid);
14
14
  if (launch.learning && !launch.replay && !launch.audit)
@@ -131,6 +131,8 @@ export declare function checkDraftOf(deps: LearningEndDeps, input: {
131
131
  readonly base: string;
132
132
  };
133
133
  }): Promise<DraftChecked<DraftCommit>>;
134
+ /** The digest of the failed-draft record run `runId`'s compile keeps (recordDraftFailed): one per run. */
135
+ export declare const draftFailedDigest: (runId: string) => string;
134
136
  /** Compile once: run `runId`'s compile turn whose drafts all failed their checks is the compile's attempt, kept as a
135
137
  * promotion record of the shape a check's stop has (runner/promotion.ts stopUnchecked): a hold with nothing checked,
136
138
  * its reason (DRAFT_FAILED) naming the failed checks. A first compile's earns the one recompile, as a check's hold
@@ -159,7 +161,8 @@ export declare function traceFrom(timeline: readonly TimelineEvent[], refuse: re
159
161
  * that fits the run's input and whose promotion holds it at main's digest (runner/promotion.ts: its one check on the
160
162
  * agent's own runs fell under the bar; its champion served the run, or the agent did by hand), its text as main holds
161
163
  * it, with the check's numbers and the inputs it disagreed on, once per hold (none when any run since the hold compiled
162
- * it, read from the agent's kept learning; a stopped check's none); else, when the job is due (compileDue: the run
164
+ * it, read from the agent's kept learning; a stopped check's none; a connected agent's hold on give-backs only once it
165
+ * is due, as a first compile is, on its runs since the hold); else, when the job is due (compileDue: the run
163
166
  * completed, the agent has no learned workflow active or waiting, and it has its definition's compile_after completed
164
167
  * agent runs), a new one, compiled once: one more after a first compile whose drafts all failed their checks, and none
165
168
  * after a recompile's (recordDraftFailed). A draft that passes is on main at once (a learned workflow then), so nothing
@@ -169,7 +172,8 @@ export declare function traceFrom(timeline: readonly TimelineEvent[], refuse: re
169
172
  * run's input (`input`, its fields for the workflow's input schema), the agent's output schema when it has one (its
170
173
  * final output's shape) and the DSL's language with this host's addendum. An SDK run's compile, asked outside its
171
174
  * session, also carries the owner's standing corrections it was laid with (`corrections`, its # Learned section), as an
172
- * in-session compile reads them in its session. Undefined when it compiles nothing, or when the folder can't be read. */
175
+ * in-session compile reads them in its session; its held workflow is the one its task fits (`sdkTask`: sdkTakes, as its
176
+ * start reserves a check). Undefined when it compiles nothing, or when the folder can't be read. */
173
177
  export declare function compileAskOf(deps: LearningEndDeps, input: {
174
178
  runId: string;
175
179
  agentId: string;
@@ -177,6 +181,7 @@ export declare function compileAskOf(deps: LearningEndDeps, input: {
177
181
  refuse: readonly string[];
178
182
  round?: number;
179
183
  input?: unknown;
184
+ sdkTask?: string;
180
185
  seedWorkflows?: number;
181
186
  corrections?: string;
182
187
  }): Promise<CompileAsk | undefined>;
@@ -29,7 +29,7 @@ import { repickSiteOf } from "../learn/check.js";
29
29
  import { repickLabelOf, repickRewrite } from "../learn/repick.js";
30
30
  import { folderAt, holdsCommit, readLearning, readSnapshot, runMergeOf, snapshotAt, textsAt } from "../learn/folder.js";
31
31
  import { completedRun, compileStoppedOf, lastOwnRuns, sinceReset, compileDue, compilePrompt, compileReference, COMPILE_TRACES, DRAFT_FAILED, draftFailedOf, heldNamesOf, newCompileAttempt } from "../learn/compile.js";
32
- import { reviseAttemptOf } from "./promotion.js";
32
+ import { heldOnGiveBacks, reviseAttemptOf, sdkInputText } from "./promotion.js";
33
33
  import { loopOf, repickOf } from "../learning-setting.js";
34
34
  import { CHECK_TEXT_MAX, promotionOf, promotionsOf, recordPromotion, resetAtOf } from "../learn/promote.js";
35
35
  import { draftDecisionProviders, draftDryRun, draftFiles, draftMcpTools, unpricedCalls, WORKFLOWS_DIR } from "../learn/workflow-draft.js";
@@ -48,7 +48,7 @@ import { readApprovers } from "../server-approvers.js";
48
48
  import { isCliRecord, runEntries, runTimeline, withoutFeedbackRounds } from "../store-reads/journal.js";
49
49
  import { capNowOf, KINDS } from "./journal-kinds.js";
50
50
  import { bookedCapSpend, cliModelWorked, runCostOf } from "./metrics.js";
51
- import { fits, workflowDigest } from "./workflow-first.js";
51
+ import { fits, sdkTakes, workflowDigest } from "./workflow-first.js";
52
52
  import { pendingFeedbackOf } from "./feedback-round.js";
53
53
  import { createReflectHook } from "./reflect-hook.js";
54
54
  import { sdkDraftTools } from "../sdk/workflows.js";
@@ -107,7 +107,7 @@ export function learningEndOfRun(launch, deps) {
107
107
  correctionRefused: ({ runId, agentId, round: at, text, refuse }) => withFolder(deps, agentId, (folder) => correctionRefused(folder.workspace, text, refuse, { runId, round: at })),
108
108
  // A run with no workflow binding (an SDK run's `noWorkflows`) compiles nothing.
109
109
  ...(start.noWorkflows ? {} : {
110
- compileFacts: (input) => compileAskOf(deps, { ...input, input: launch.input, seedWorkflows: start.workflows?.length ?? 0, corrections: start.section }),
110
+ compileFacts: (input) => compileAskOf(deps, { ...input, input: launch.input, ...(launch.sdk ? { sdkTask: sdkInputText(launch) } : {}), seedWorkflows: start.workflows?.length ?? 0, corrections: start.section }),
111
111
  compileFailed: (input) => recordDraftFailed(deps, input),
112
112
  }),
113
113
  // The run's secrets, what the claim handed it, every secret the server keeps sealed, and the sign-in pointers it was
@@ -479,7 +479,7 @@ const workflowText = (doc) => {
479
479
  return Buffer.byteLength(text) <= CAPS.file ? text : `${JSON.stringify(doc)}\n`;
480
480
  };
481
481
  /** The digest of the failed-draft record run `runId`'s compile keeps (recordDraftFailed): one per run. */
482
- const draftFailedDigest = (runId) => createHash("sha256").update(`draft-failed\n${runId}`).digest("hex").slice(0, 16);
482
+ export const draftFailedDigest = (runId) => createHash("sha256").update(`draft-failed\n${runId}`).digest("hex").slice(0, 16);
483
483
  /** Compile once: run `runId`'s compile turn whose drafts all failed their checks is the compile's attempt, kept as a
484
484
  * promotion record of the shape a check's stop has (runner/promotion.ts stopUnchecked): a hold with nothing checked,
485
485
  * its reason (DRAFT_FAILED) naming the failed checks. A first compile's earns the one recompile, as a check's hold
@@ -535,7 +535,8 @@ export function traceFrom(timeline, refuse) {
535
535
  * that fits the run's input and whose promotion holds it at main's digest (runner/promotion.ts: its one check on the
536
536
  * agent's own runs fell under the bar; its champion served the run, or the agent did by hand), its text as main holds
537
537
  * it, with the check's numbers and the inputs it disagreed on, once per hold (none when any run since the hold compiled
538
- * it, read from the agent's kept learning; a stopped check's none); else, when the job is due (compileDue: the run
538
+ * it, read from the agent's kept learning; a stopped check's none; a connected agent's hold on give-backs only once it
539
+ * is due, as a first compile is, on its runs since the hold); else, when the job is due (compileDue: the run
539
540
  * completed, the agent has no learned workflow active or waiting, and it has its definition's compile_after completed
540
541
  * agent runs), a new one, compiled once: one more after a first compile whose drafts all failed their checks, and none
541
542
  * after a recompile's (recordDraftFailed). A draft that passes is on main at once (a learned workflow then), so nothing
@@ -545,7 +546,8 @@ export function traceFrom(timeline, refuse) {
545
546
  * run's input (`input`, its fields for the workflow's input schema), the agent's output schema when it has one (its
546
547
  * final output's shape) and the DSL's language with this host's addendum. An SDK run's compile, asked outside its
547
548
  * session, also carries the owner's standing corrections it was laid with (`corrections`, its # Learned section), as an
548
- * in-session compile reads them in its session. Undefined when it compiles nothing, or when the folder can't be read. */
549
+ * in-session compile reads them in its session; its held workflow is the one its task fits (`sdkTask`: sdkTakes, as its
550
+ * start reserves a check). Undefined when it compiles nothing, or when the folder can't be read. */
549
551
  export async function compileAskOf(deps, input) {
550
552
  const { agentId } = input;
551
553
  // A revision is asked only of a workflow its promotion holds, once per hold. The workflows whose newest revision other
@@ -563,8 +565,10 @@ export async function compileAskOf(deps, input) {
563
565
  const since = await sinceReset(deps.store, agentId);
564
566
  const earlier = (at < 0 ? listed : listed.slice(at + 1)).filter((run) => run.agentId === agentId && since(run));
565
567
  const done = earlier.filter(completedRun);
566
- const byHand = (await lastOwnRuns(deps.store, agentId, compileAfter, input.runId)).length;
567
- const dueWith = (workflows) => compileDue({ completed: input.outcome === "completed", runs: byHand + (input.outcome === "completed" ? 1 : 0), workflows, compileAfter });
568
+ const own = await lastOwnRuns(deps.store, agentId, compileAfter, input.runId);
569
+ // Due on the agent's own completed runs, the ending one counted.
570
+ const ending = input.outcome === "completed" ? 1 : 0;
571
+ const dueWith = (workflows) => compileDue({ completed: ending === 1, runs: own.length + ending, workflows, compileAfter });
568
572
  const compiledOf = (kept) => kept?.proposal?.compiled;
569
573
  // Compile once: a recompile whose drafts failed their checks stopped the agent's new compiles (recordDraftFailed).
570
574
  const stopped = compileStoppedOf(records);
@@ -596,7 +600,8 @@ export async function compileAskOf(deps, input) {
596
600
  let current;
597
601
  let held;
598
602
  if (heldNames.size) {
599
- // The one active workflow that fits the run's input (the one workflow-first would serve), held at main's digest.
603
+ // The one active workflow that fits the run's input (the one workflow-first would serve; an SDK run's, the one its
604
+ // task fits as its start reserves a check), held at main's digest.
600
605
  const active = [];
601
606
  for (const one of workflows)
602
607
  if (one.status === "active" && heldNames.has(one.name)) {
@@ -604,7 +609,8 @@ export async function compileAskOf(deps, input) {
604
609
  if (text !== undefined)
605
610
  active.push({ name: one.name, workflow: text });
606
611
  }
607
- const fitting = active.filter((one) => fits(one, input.input, dsl.resolveSchemaForWorkflow));
612
+ const resolve = dsl.resolveSchemaForWorkflow;
613
+ const fitting = active.filter((one) => input.sdkTask !== undefined ? sdkTakes(one, input.sdkTask, resolve) : fits(one, input.input, resolve));
608
614
  const record = fitting.length === 1 ? promotionOf(records, fitting[0].name, workflowDigest(fitting[0])) : undefined;
609
615
  if (record?.decided === "hold" && !record.check?.stopped && !record.audit?.stopped)
610
616
  [held, current] = [record, fitting[0].workflow];
@@ -636,6 +642,12 @@ export async function compileAskOf(deps, input) {
636
642
  };
637
643
  let held;
638
644
  if (read.held) {
645
+ // A give-back hold revises at a first compile's cadence: compile_after own completed runs started after the hold (the turn that wrote it is not one).
646
+ const heldAt = Date.parse(read.held.at);
647
+ const after = (run) => run !== undefined && run.startedAt > heldAt;
648
+ const sinceHold = own.filter(after).length + (after(listed[at]) ? ending : 0);
649
+ if (heldOnGiveBacks(read.held.check) && !(ending === 1 && sinceHold >= compileAfter))
650
+ return sayLeftOut(), undefined;
639
651
  // Once per hold: a run since it that compiled this workflow asked already, whatever came of it (its revision is on its
640
652
  // way to a replay, or its draft failed its checks), however many runs ago. Read from the agent's kept learning since
641
653
  // the hold, never a window of its last runs; one that can't be read asks nothing. A draft that failed since, not stopped
@@ -1,11 +1,15 @@
1
1
  import { type LearnedWorkflow, type Seed, type Shown } from "../learning.js";
2
2
  import type { LearningFolder } from "../learn/folder.js";
3
+ import type { Store } from "../store/index.js";
3
4
  /** What a claim reads its seed with: the commit, the agent's learning folder where the run's place keeps it (opened for
4
- * the read and ended after it), the server's secrets as cuts (`shown`), its log, and `workflows: false` for a run that
5
- * takes none (an SDK run with no workflow binding). */
5
+ * the read and ended after it), the store whose runs say which are purged (a purged run's workflow is no seed's:
6
+ * learning.ts seedAt; null in a run's own process, which reads no other run: its lay only tells its runner whether it
7
+ * laid any, and the runner reads the seed again with its store, workflowsAt), the server's secrets as cuts (`shown`),
8
+ * its log, and `workflows: false` for a run that takes none (an SDK run with no workflow binding). */
6
9
  export interface LearningSeedLay {
7
10
  readonly seed: string | null;
8
11
  readonly folder: () => LearningFolder;
12
+ readonly store: Pick<Store, "runs"> | null;
9
13
  readonly shown: () => Promise<Shown>;
10
14
  readonly log: (line: string) => void;
11
15
  readonly workflows?: false;
@@ -28,4 +32,6 @@ export declare function layLearningSeed(lay: LearningSeedLay): Promise<LaidSeed
28
32
  * (chooseWorkflows): what a champion serves from while a newer revision of it is on main (runner/promotion.ts), and
29
33
  * what a run's process is laid at its claim's seed (run-child-host.ts). Throws when the folder cannot answer or the
30
34
  * commit is gone. */
31
- export declare function workflowsAt(read: Pick<LearningSeedLay, "folder" | "shown">, commit: string | null): Promise<LearnedWorkflow[]>;
35
+ export declare function workflowsAt(read: Pick<LearningSeedLay, "folder" | "shown"> & {
36
+ readonly store: Pick<Store, "runs">;
37
+ }, commit: string | null): Promise<LearnedWorkflow[]>;
@@ -14,7 +14,7 @@ export async function layLearningSeed(lay) {
14
14
  let seed;
15
15
  const folder = lay.folder();
16
16
  try {
17
- seed = await seedAt(folder.workspace, lay.seed);
17
+ seed = await seedAt(folder.workspace, lay.seed, lay.store);
18
18
  }
19
19
  catch (error) {
20
20
  lay.log(`the run starts with no learned workflow: ${message(error)}`);
@@ -44,7 +44,7 @@ export async function workflowsAt(read, commit) {
44
44
  const folder = read.folder();
45
45
  let seed;
46
46
  try {
47
- seed = await seedAt(folder.workspace, commit);
47
+ seed = await seedAt(folder.workspace, commit, read.store);
48
48
  }
49
49
  finally {
50
50
  await folder.end().catch(() => undefined);
@@ -167,6 +167,7 @@ export declare function runnerArgs(argv: readonly string[]): {
167
167
  envOnly?: true;
168
168
  heartbeatOnly?: true;
169
169
  harnessModules?: string[];
170
+ harnessRecipes?: string[];
170
171
  };
171
172
  /** Runs until SIGTERM or SIGINT, or until the store's runner floor rises above this runner (RunnerProcess.outdated),
172
173
  * then closes: nothing more claimed, the drain, its runs handed back. Answers the floor's words when that was the stop,