@parcha/agentrun-serve 0.1.0-beta.53 → 0.1.0-beta.55

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 (224) hide show
  1. package/CHANGELOG.md +138 -3
  2. package/README.md +346 -99
  3. package/dist/adapters.d.ts +10 -0
  4. package/dist/adapters.js +46 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +7 -14
  7. package/dist/agent-rows.d.ts +1 -1
  8. package/dist/agents-store.js +7 -6
  9. package/dist/api-only.d.ts +17 -6
  10. package/dist/api-only.js +22 -9
  11. package/dist/cli.js +11 -4
  12. package/dist/composio-made.d.ts +26 -1
  13. package/dist/composio-made.js +39 -2
  14. package/dist/composio-preset.d.ts +6 -4
  15. package/dist/composio-preset.js +50 -17
  16. package/dist/computer-held-routes.js +2 -3
  17. package/dist/computer-needs.d.ts +1 -1
  18. package/dist/computer-needs.js +1 -1
  19. package/dist/computer-setting.d.ts +8 -4
  20. package/dist/computer-setting.js +0 -2
  21. package/dist/computers-running.d.ts +8 -0
  22. package/dist/computers-running.js +27 -0
  23. package/dist/computers.d.ts +0 -2
  24. package/dist/computers.js +1 -1
  25. package/dist/console/assets/backend-D5EmB4N3.js +166 -0
  26. package/dist/console/assets/index-DUYLaqiR.js +746 -0
  27. package/dist/console/assets/index-DYhU4adm.css +1 -0
  28. package/dist/console/index.html +2 -2
  29. package/dist/docker-host-addresses.d.ts +23 -3
  30. package/dist/docker-host-addresses.js +90 -18
  31. package/dist/errors.d.ts +4 -0
  32. package/dist/errors.js +7 -0
  33. package/dist/exa-keyless.d.ts +2 -3
  34. package/dist/exa-keyless.js +43 -127
  35. package/dist/firecrawl-keyless.d.ts +41 -0
  36. package/dist/firecrawl-keyless.js +152 -0
  37. package/dist/github-connection.d.ts +50 -1
  38. package/dist/github-connection.js +96 -3
  39. package/dist/github-faux.d.ts +11 -2
  40. package/dist/github-faux.js +138 -7
  41. package/dist/github-pull-request.d.ts +37 -0
  42. package/dist/github-pull-request.js +110 -0
  43. package/dist/handed-secret.d.ts +3 -1
  44. package/dist/handed-secret.js +4 -2
  45. package/dist/harness-keys.d.ts +98 -0
  46. package/dist/harness-keys.js +247 -0
  47. package/dist/harness-recipe-entry.d.ts +14 -9
  48. package/dist/harness-recipe-entry.js +25 -14
  49. package/dist/harness-table.d.ts +16 -1
  50. package/dist/harness-table.js +19 -7
  51. package/dist/harness.d.ts +4 -0
  52. package/dist/harness.js +12 -1
  53. package/dist/host-check.d.ts +2 -0
  54. package/dist/host-check.js +6 -0
  55. package/dist/import-summary.d.ts +1 -1
  56. package/dist/import-summary.js +1 -1
  57. package/dist/import.d.ts +5 -5
  58. package/dist/import.js +54 -67
  59. package/dist/keyless-mcp.d.ts +36 -0
  60. package/dist/keyless-mcp.js +127 -0
  61. package/dist/learn/audit.d.ts +3 -3
  62. package/dist/learn/audit.js +3 -3
  63. package/dist/learn/commit.d.ts +8 -7
  64. package/dist/learn/commit.js +60 -20
  65. package/dist/learn/compile.d.ts +4 -3
  66. package/dist/learn/compile.js +7 -5
  67. package/dist/learn/folder.d.ts +16 -3
  68. package/dist/learn/folder.js +46 -13
  69. package/dist/learn/promote.d.ts +37 -13
  70. package/dist/learn/promote.js +112 -40
  71. package/dist/learn/secrets.js +10 -2
  72. package/dist/learning-routes.d.ts +22 -17
  73. package/dist/learning-routes.js +40 -39
  74. package/dist/learning.js +2 -2
  75. package/dist/live-reach.d.ts +34 -7
  76. package/dist/live-reach.js +76 -11
  77. package/dist/manifest.d.ts +10 -0
  78. package/dist/manifest.js +30 -0
  79. package/dist/mcp-pin-first.d.ts +4 -2
  80. package/dist/mcp-pin-first.js +5 -2
  81. package/dist/mcp-probe.js +2 -2
  82. package/dist/mcp-secret-writes.d.ts +16 -7
  83. package/dist/mcp-secret-writes.js +35 -27
  84. package/dist/mcp-servers-store.d.ts +30 -6
  85. package/dist/mcp-servers-store.js +112 -28
  86. package/dist/mcp-sources.d.ts +10 -2
  87. package/dist/mcp-sources.js +9 -2
  88. package/dist/mcp-store.d.ts +13 -7
  89. package/dist/mcp-store.js +12 -9
  90. package/dist/model-form.d.ts +3 -2
  91. package/dist/model-form.js +11 -7
  92. package/dist/model.d.ts +20 -4
  93. package/dist/model.js +68 -9
  94. package/dist/native/history.d.ts +1 -1
  95. package/dist/native/history.js +2 -2
  96. package/dist/ollama-provider.d.ts +92 -0
  97. package/dist/ollama-provider.js +495 -0
  98. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  99. package/dist/openapi.js +235 -41
  100. package/dist/page.d.ts +11 -3
  101. package/dist/page.js +22 -7
  102. package/dist/place-offers.d.ts +17 -1
  103. package/dist/place-offers.js +46 -5
  104. package/dist/print.js +1 -1
  105. package/dist/purged-workflow.d.ts +35 -7
  106. package/dist/purged-workflow.js +73 -26
  107. package/dist/run-computer.d.ts +2 -0
  108. package/dist/run-computer.js +2 -0
  109. package/dist/run-files.d.ts +4 -0
  110. package/dist/run-files.js +4 -0
  111. package/dist/run-keys.d.ts +2 -4
  112. package/dist/run-keys.js +6 -7
  113. package/dist/run-launch.d.ts +4 -0
  114. package/dist/run-launch.js +4 -0
  115. package/dist/run-reads-over-store.d.ts +3 -2
  116. package/dist/run-reads-over-store.js +66 -2
  117. package/dist/run-secrets.js +5 -2
  118. package/dist/runner/adapter-loop.d.ts +6 -3
  119. package/dist/runner/adapter-loop.js +34 -15
  120. package/dist/runner/adapter-run-spec.d.ts +3 -0
  121. package/dist/runner/adapter-run-spec.js +6 -4
  122. package/dist/runner/audit.js +8 -4
  123. package/dist/runner/beside.d.ts +2 -1
  124. package/dist/runner/beside.js +6 -2
  125. package/dist/runner/claim-secrets.d.ts +5 -8
  126. package/dist/runner/claim-secrets.js +6 -0
  127. package/dist/runner/cli-run-spec.d.ts +1 -1
  128. package/dist/runner/cli-run-spec.js +39 -7
  129. package/dist/runner/harness-loops.d.ts +22 -9
  130. package/dist/runner/harness-loops.js +21 -11
  131. package/dist/runner/held.d.ts +3 -0
  132. package/dist/runner/learning-end.d.ts +1 -1
  133. package/dist/runner/learning-end.js +8 -3
  134. package/dist/runner/loop-contract.d.ts +5 -4
  135. package/dist/runner/main.js +4 -2
  136. package/dist/runner/mcp-claim.d.ts +3 -0
  137. package/dist/runner/mcp-claim.js +26 -2
  138. package/dist/runner/mcp-run.d.ts +3 -0
  139. package/dist/runner/mcp-run.js +2 -1
  140. package/dist/runner/metrics.d.ts +10 -8
  141. package/dist/runner/metrics.js +20 -27
  142. package/dist/runner/model-route.d.ts +3 -0
  143. package/dist/runner/model-route.js +6 -2
  144. package/dist/runner/pr-checkout.d.ts +21 -4
  145. package/dist/runner/pr-checkout.js +103 -4
  146. package/dist/runner/promotion.d.ts +15 -9
  147. package/dist/runner/promotion.js +25 -15
  148. package/dist/runner/run-child-host.js +24 -11
  149. package/dist/runner/run-child.js +3 -1
  150. package/dist/runner/runner-check.d.ts +3 -0
  151. package/dist/runner/runner-check.js +23 -0
  152. package/dist/runner/sdk-loop.js +2 -0
  153. package/dist/runner/workflow-loop.d.ts +2 -2
  154. package/dist/runner/workflow-loop.js +1 -2
  155. package/dist/runner/workflow-spec.d.ts +1 -1
  156. package/dist/runner/workflow-spec.js +6 -6
  157. package/dist/sdk/check.d.ts +4 -1
  158. package/dist/sdk/check.js +2 -1
  159. package/dist/sdk/runs.d.ts +2 -2
  160. package/dist/sdk/runs.js +8 -6
  161. package/dist/secret-cut.js +2 -1
  162. package/dist/secret-writes.d.ts +3 -2
  163. package/dist/secret-writes.js +1 -1
  164. package/dist/server.d.ts +55 -8
  165. package/dist/server.js +363 -118
  166. package/dist/standard-webhooks.d.ts +11 -0
  167. package/dist/standard-webhooks.js +20 -2
  168. package/dist/store/agent-body.d.ts +2 -2
  169. package/dist/store/agent-body.js +2 -2
  170. package/dist/store/index.d.ts +1 -1
  171. package/dist/store/schema.js +5 -2
  172. package/dist/store/sqlite/store.js +90 -34
  173. package/dist/store/store.d.ts +54 -14
  174. package/dist/store-reads/journal.d.ts +7 -2
  175. package/dist/store-reads/journal.js +9 -6
  176. package/dist/store-reads/learning.d.ts +12 -9
  177. package/dist/store-reads/learning.js +18 -24
  178. package/dist/store-view.d.ts +0 -5
  179. package/dist/store-view.js +9 -8
  180. package/dist/suggestions.d.ts +282 -0
  181. package/dist/suggestions.js +919 -0
  182. package/dist/telemetry.d.ts +8 -1
  183. package/dist/telemetry.js +12 -4
  184. package/dist/template-eval.d.ts +49 -4
  185. package/dist/template-eval.js +168 -45
  186. package/dist/template-import.d.ts +17 -0
  187. package/dist/template-import.js +36 -2
  188. package/dist/templates.d.ts +83 -76
  189. package/dist/templates.js +29 -48
  190. package/dist/timeline/labels.d.ts +2 -2
  191. package/dist/timeline/labels.js +2 -2
  192. package/dist/timeline/timeline.d.ts +2 -2
  193. package/dist/timeline/timeline.js +1 -1
  194. package/dist/tool-plane.d.ts +17 -9
  195. package/dist/tool-plane.js +38 -17
  196. package/dist/tools.js +2 -2
  197. package/dist/trigger-launch-hook.d.ts +19 -9
  198. package/dist/trigger-launch-hook.js +35 -25
  199. package/dist/trigger-targets.d.ts +18 -8
  200. package/dist/trigger-targets.js +42 -19
  201. package/dist/triggers.d.ts +85 -23
  202. package/dist/triggers.js +303 -96
  203. package/dist/validate.d.ts +1 -1
  204. package/dist/validate.js +2 -2
  205. package/dist/web-fake.js +3 -3
  206. package/dist/web-fetch-direct.d.ts +4 -0
  207. package/dist/web-fetch-direct.js +8 -1
  208. package/dist/web-fetch.d.ts +12 -3
  209. package/dist/web-fetch.js +47 -14
  210. package/dist/web-search.d.ts +33 -4
  211. package/dist/web-search.js +100 -41
  212. package/dist/webhooks.js +4 -5
  213. package/dist/workspace/synced-folder.d.ts +1 -1
  214. package/dist/workspace/synced-folder.js +11 -14
  215. package/launcher/agentrun-serve +5 -1
  216. package/package.json +17 -13
  217. package/templates/README.md +5 -4
  218. package/templates/agent-scout/agent.md +46 -0
  219. package/templates/agent-scout/skills/scout/SKILL.md +88 -0
  220. package/templates/agent-scout/skills/scout/suggestions.schema.json +112 -0
  221. package/dist/console/assets/index-BFgyZzF_.js +0 -734
  222. package/dist/console/assets/index-DbilxljH.css +0 -1
  223. package/dist/import-sources.d.ts +0 -116
  224. package/dist/import-sources.js +0 -693
@@ -22,7 +22,7 @@
22
22
  // tools can read the change instead. The checkout is removed when the claim lets go (spec-holds.ts), and made again by
23
23
  // the next claim of the same run.
24
24
  import { randomUUID } from "node:crypto";
25
- import { GITHUB_WEB, githubPullOf } from "../github.js";
25
+ import { GITHUB_WEB, githubPullOf, githubTargetOf } from "../github.js";
26
26
  import { isObject } from "../validate.js";
27
27
  import { COMMAND_MAX_MS } from "../workspace/archil-exec.js";
28
28
  import { shellEnv } from "../workspace/hands.js";
@@ -168,9 +168,108 @@ function checkoutNote(pull, mergeBase) {
168
168
  }
169
169
  /** The checkout a claim's spec makes (the pi and the CLI spec alike) for its launch: the server's GitHub App opened as the
170
170
  * MCP step opens it (github-app.ts, its payload tag read only for a github trigger's run), its secrets held by the run's redactor `redact`, its removal by the spec's holds (`held`) from the
171
- * moment the fetch starts, and `signal` (the claim's, a person's stop included) ending the fetch. */
172
- export async function prCheckoutForClaim(deps, workspace, launch, redact, signal, held) {
171
+ * moment the fetch starts, and `signal` (the claim's, a person's stop included) ending the fetch. `kind` is the revision's
172
+ * checkout: the pull request the run's event names, or the repository the run names (repoCheckout). */
173
+ export async function prCheckoutForClaim(deps, workspace, launch, redact, signal, held, kind = "pull_request") {
173
174
  const fromGitHub = launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github";
174
175
  const access = await githubAppAccess(deps.store, deps.sealKey, launch.input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub, hold: (values) => redact.hold(values), ...(launch.repo !== undefined ? { repo: launch.repo } : {}) });
175
- return prCheckout({ workspace, input: launch.input, fromGitHub, ...(access ? { mint: access.mint } : {}), ...(access?.revoke ? { revoke: access.revoke } : {}), hold: (secrets) => redact.hold(secrets), ...(deps.githubWeb ? { web: deps.githubWeb } : {}), ...(signal ? { signal } : {}), ...(held ? { held } : {}) });
176
+ const common = { workspace, input: launch.input, fromGitHub, ...(access ? { mint: access.mint } : {}), ...(access?.revoke ? { revoke: access.revoke } : {}), hold: (secrets) => redact.hold(secrets), ...(deps.githubWeb ? { web: deps.githubWeb } : {}), ...(signal ? { signal } : {}), ...(held ? { held } : {}) };
177
+ if (kind === "repository")
178
+ return repoCheckout({ ...common, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) });
179
+ return prCheckout(common);
176
180
  }
181
+ /** The file in the checkout's .git that lists its files, one path a line (git ls-tree), so an agent with `read` and no
182
+ * shell can still find what to open. */
183
+ export const FILE_LIST = "agentrun-files";
184
+ /** The exec's script for a repository's checkout: $1 the remote's URL (no credential), $2 the folder, $3 the URL prefix
185
+ * the header is for, $4 this claim's checkout id. Its stdin's first line is an Authorization header, or empty. It fetches
186
+ * the remote's HEAD (its default branch) one commit deep, and checks it out detached (ref repo/head). Its exit codes name
187
+ * the step that failed (10 the folder, 11 the fetch, 12 the checkout); on success it lists the files in
188
+ * .git/${FILE_LIST} and prints the commit, how many files there are and the default branch's name (empty when the
189
+ * remote did not say). */
190
+ const REPO_SCRIPT = `set -u
191
+ url=$1 dir=$2 scope=$3 claim=$4
192
+ IFS= read -r auth || true
193
+ export GIT_TERMINAL_PROMPT=0 GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null
194
+ if [ -n "\${auth:-}" ]; then export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.$scope.extraheader" GIT_CONFIG_VALUE_0="$auth"; fi
195
+ auth=
196
+ rm -rf "\${dir:?}"
197
+ git init -q "$dir" >/dev/null 2>&1 && cd "$dir" && printf '%s\\n' "$claim" > .git/${OWNER_FILE} && git remote add origin "$url" || exit 10
198
+ branch=$(git ls-remote --symref origin HEAD 2>/dev/null | awk '$1 == "ref:" { sub("^refs/heads/", "", $2); print $2; exit }')
199
+ git -c maintenance.auto=false -c gc.auto=0 fetch -q --no-tags --no-recurse-submodules --depth=1 origin HEAD || exit 11
200
+ git update-ref refs/repo/head FETCH_HEAD || exit 12
201
+ git -c advice.detachedHead=false checkout -q --detach FETCH_HEAD || exit 12
202
+ git ls-tree -r --name-only HEAD > .git/${FILE_LIST} || exit 12
203
+ printf '%s %s %s\\n' "$(git rev-parse HEAD)" "$(wc -l < .git/${FILE_LIST} | tr -d ' ')" "$branch"
204
+ `;
205
+ /** The repository the run names, checked out in the run's folder at the head of its default branch, one commit deep: the
206
+ * server's own fetch, with the App's token for that one repository and `contents: read` alone (or none: anonymous, which
207
+ * a public repository answers), revoked once the fetch is done, never kept. Never throws for a checkout that could not be
208
+ * made: the run is told why. */
209
+ export async function repoCheckout(options) {
210
+ const { workspace } = options;
211
+ const named = options.repo !== undefined ? { repo: options.repo } : githubTargetOf(isObject(options.input) ? options.input.content : options.input, { payload: options.fromGitHub === true });
212
+ const [owner, name, extra] = (named?.repo ?? "").split("/");
213
+ if (!named || !owner || !name || extra !== undefined || !REPO_OWNER.test(owner) || !REPO_NAME_PART.test(name) || name === "." || name === "..")
214
+ return noCheckout("No checkout was made: this run names no GitHub repository (https://github.com/<owner>/<repo> in its first message), so there is no repo/ folder.");
215
+ const repo = `${owner}/${name}`;
216
+ const web = (options.web ?? GITHUB_WEB).replace(/\/+$/, "");
217
+ let token;
218
+ let anonymous = "";
219
+ if (options.mint) {
220
+ try {
221
+ const got = await options.mint({ repo, ...("installation" in named && named.installation !== undefined ? { installation: named.installation } : {}) }, { contents: "read" });
222
+ if (got.ok)
223
+ token = got.token;
224
+ else
225
+ anonymous = got.reason === "not_installed" ? `the GitHub App is not installed on ${repo}` : got.message;
226
+ }
227
+ catch (error) {
228
+ anonymous = `GitHub did not make a token (${error?.message ?? error})`;
229
+ }
230
+ }
231
+ else
232
+ anonymous = "this server has no GitHub App";
233
+ const header = token ? `Authorization: Basic ${Buffer.from(`x-access-token:${token}`, "utf8").toString("base64")}` : "";
234
+ const secrets = token ? [token, header, header.slice("Authorization: Basic ".length)] : [];
235
+ if (secrets.length)
236
+ options.hold?.(secrets);
237
+ const claim = randomUUID();
238
+ const removal = async () => {
239
+ const result = await workspace.exec(["sh", "-c", `[ "$(cat "\${1:?}/.git/${OWNER_FILE}" 2>/dev/null)" = "$2" ] || exit 0; rm -rf -- "\${1:?}"`, "sh", CHECKOUT_DIR, claim], { env: shellEnv(), timeoutMs: CHECKOUT_MS });
240
+ if (result.code !== 0)
241
+ throw new Error(`the run's ${CHECKOUT_DIR}/ checkout could not be removed (exit ${result.code ?? result.signal}): ${tail(result.stderr, secrets)}`);
242
+ };
243
+ const failed = async (why) => {
244
+ await removal().catch(() => { });
245
+ return noCheckout(`The repository ${repo} could not be checked out (${why}), so there is no ${CHECKOUT_DIR}/ folder: read it through the GitHub tools if you have them, else say that you could not read it.`);
246
+ };
247
+ options.held?.({ end: removal });
248
+ let result;
249
+ try {
250
+ result = await workspace.exec(["sh", "-c", REPO_SCRIPT, "sh", `${web}/${repo}.git`, CHECKOUT_DIR, `${web}/`, claim], { env: shellEnv(), stdin: Buffer.from(`${header}\n`, "utf8"), timeoutMs: options.timeoutMs ?? CHECKOUT_MS, ...(options.signal ? { signal: options.signal } : {}) });
251
+ }
252
+ catch (error) {
253
+ if (options.signal?.aborted)
254
+ throw error;
255
+ return failed(`the fetch could not run: ${tail(String(error?.message ?? error), secrets)}`);
256
+ }
257
+ finally {
258
+ if (token && options.revoke)
259
+ await options.revoke(token).catch(() => { });
260
+ }
261
+ if (result.timedOut)
262
+ return failed(`the fetch took more than ${Math.round((options.timeoutMs ?? CHECKOUT_MS) / 1000)} s`);
263
+ if (result.code !== 0) {
264
+ const step = result.code === 10 ? "its folder could not be made" : result.code === 11 ? `${web}/${repo} did not give its default branch${token ? "" : `, fetched with no token: ${anonymous}`}` : result.code === 12 ? "its head could not be checked out" : `git ended with ${result.code ?? result.signal}`;
265
+ const said = tail(result.stderr, secrets);
266
+ return failed(said ? `${step}: ${said}` : step);
267
+ }
268
+ const [sha = "", count = "", branch = ""] = Buffer.from(result.stdout).toString("utf8").trim().split(/\s+/);
269
+ const at = /^[0-9a-f]{40}$/.test(sha) ? sha : "its head";
270
+ const named_ = /^[A-Za-z0-9._\/-]{1,255}$/.test(branch) ? ` ${branch}` : "";
271
+ const files = /^\d{1,9}$/.test(count) ? `Its ${count} ${count === "1" ? "file is" : "files are"} listed in ${CHECKOUT_DIR}/.git/${FILE_LIST}, one path a line. ` : "";
272
+ return { note: `The repository ${repo} is checked out in ${CHECKOUT_DIR}/ at the head of its default branch${named_}, commit ${at} (ref repo/head), by the server before this run began. ${files}It is a shallow clone (that one commit, no history), and no credential is kept in it.`, end: removal };
273
+ }
274
+ const REPO_OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/;
275
+ const REPO_NAME_PART = /^[A-Za-z0-9._-]{1,100}$/;
@@ -5,7 +5,7 @@ import { type RunLaunch } from "../run-launch.js";
5
5
  import { type Store } from "../store/store.js";
6
6
  import { type Recorded, type ReplayCalls, type Skipped } from "../learn/replay-calls.js";
7
7
  import { type Json } from "../validate.js";
8
- import { type CheckBar, type CheckRecord, type CheckTurns, type Compared, type PromotionRecord, recordPromotion, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
8
+ import { type CheckBar, type CheckRecord, type CheckTurns, type Compared, type PromotionRecord, recordPromotion, type Refused, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
9
9
  import { type FirstChoice, type Promoted, type ReplayOutcome } from "./workflow-first.js";
10
10
  import type { LearningFolder } from "../learn/folder.js";
11
11
  import type { Shown } from "../learning.js";
@@ -32,9 +32,13 @@ export interface PromotionDeps {
32
32
  readonly context: Context;
33
33
  readonly log: (line: string) => void;
34
34
  /** The learned workflow `name` as the learning folder held it active at `commit` (a champion's text), or undefined when
35
- * it held none by that name, or a purged run wrote it (learning.ts seedAt): a purged champion is no champion's text,
36
- * and the agent takes the run. Absent: no champion serves. */
35
+ * it held none by that name, or a purged run wrote it (learning.ts seedAt): a purged run's text is never served (the
36
+ * champion skips it first, `refused`). Absent: no champion serves. */
37
37
  readonly champion?: (name: string, commit: string) => Promise<LearnedWorkflow | undefined>;
38
+ /** The records of `workflows` (all, when absent) championOf skips (purged-workflow.ts refusedIn over the learning
39
+ * folder): a champion the purge gate refuses at its commit, so the newest promotion it lets through serves, and the
40
+ * promotions trim keeps that one (recordPromotion). Absent: none skipped. */
41
+ readonly refused?: (records: readonly PromotionRecord[], workflows?: Iterable<string>) => Promise<Refused>;
38
42
  /** The digest of the learned workflow `name` the learning folder's main holds now (the newest revision), or undefined
39
43
  * when it holds none by that name. Absent: every revision is the newest. */
40
44
  readonly newest?: (name: string) => Promise<string | undefined>;
@@ -55,7 +59,7 @@ export interface PromotionDeps {
55
59
  }
56
60
  /** What deciding a check needs (decideCheck, stopUnchecked): a claim's ports, or those of a connected agent's start or
57
61
  * run end, whose record names its commit (no claimed launch to read a seed from). */
58
- type DecideDeps = Pick<PromotionDeps, "store" | "agentId" | "log" | "shown"> & Partial<Pick<PromotionDeps, "launch" | "now">>;
62
+ type DecideDeps = Pick<PromotionDeps, "store" | "agentId" | "log" | "shown"> & Partial<Pick<PromotionDeps, "launch" | "now" | "refused">>;
59
63
  /** The claim's promotion ports: `folder`, the agent's learning folder where the run's place keeps it, a champion read
60
64
  * from it at its record's commit, cut of the server's secrets (`shown`) as the claim's lay is; and the workflow an earlier
61
65
  * claim of this run served (`kept`, from its journal: none on a first claim). */
@@ -79,12 +83,13 @@ export declare function replayLaid(launch: RunLaunch, laid: readonly LearnedWork
79
83
  * promoted yet, or the champion held): a revision replaying, held or never decided is never handed to the agent to run
80
84
  * in its place. One the records never named is an unchecked draft and is not offered. A replay run's as
81
85
  * laid (replayLaid). The records unread: only the chosen one, as the gate leaves a run to its agent. */
82
- export declare function toolFlowsFor(deps: Pick<PromotionDeps, "store" | "agentId" | "champion" | "log">, launch: RunLaunch, laid: readonly LearnedWorkflow[], choice: FirstChoice): Promise<LearnedWorkflow[]>;
86
+ export declare function toolFlowsFor(deps: Pick<PromotionDeps, "store" | "agentId" | "champion" | "refused" | "log">, launch: RunLaunch, laid: readonly LearnedWorkflow[], choice: FirstChoice): Promise<LearnedWorkflow[]>;
83
87
  /** `flow`'s champion (championOf) and the text it serves from: `flow` itself when it is the champion, else the
84
88
  * champion's text read at its record's commit (`read`), kept only when its digest is the champion's. No text: none is
85
- * promoted, or its text cannot be read. The one champion lookup a claim's gate (servingNow), the learned_workflow tool
86
- * (toolFlowsFor) and a connected agent's start (sdk/runs.ts) share. */
87
- export declare function championTextOf(records: readonly PromotionRecord[], flow: LearnedWorkflow, read?: (name: string, commit: string) => Promise<LearnedWorkflow | undefined>): Promise<{
89
+ * promoted, or its text cannot be read. The champion skips what `refused` says the purge gate refuses (PromotionDeps
90
+ * refused), so after a purge of its run the newest promotion the gate lets through serves. The one champion lookup a
91
+ * claim's gate (servingNow), the learned_workflow tool (toolFlowsFor) and a connected agent's start (sdk/runs.ts) share. */
92
+ export declare function championTextOf(records: readonly PromotionRecord[], flow: LearnedWorkflow, read?: (name: string, commit: string) => Promise<LearnedWorkflow | undefined>, refused?: PromotionDeps["refused"]): Promise<{
88
93
  champion?: PromotionRecord;
89
94
  text?: LearnedWorkflow;
90
95
  }>;
@@ -127,7 +132,8 @@ export type CheckRow = {
127
132
  readonly compared?: Compared;
128
133
  };
129
134
  /** Decides a check on its rows, with a connected agent's turns checked before them (`before`), scored on its bar
130
- * (scoreRows). Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
135
+ * (scoreRows). Promoted when it clears the bar (checkPasses) and the purge gate lets its revision through at its commit
136
+ * (`refused`: else held, a purged run's text); else held with the inputs it did not agree on, which the
131
137
  * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
132
138
  * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
133
139
  * (the one write: of two claims at once, one decides). */
@@ -56,6 +56,7 @@ import { listed } from "../learning-words.js";
56
56
  import { isObject } from "../validate.js";
57
57
  import { agentRun, lastOwnRuns, newCompileAttempt, sinceReset } from "../learn/compile.js";
58
58
  import { checkPasses, checkShares, CHECK_TEXT_MAX, championOf, compareAnswers, comparedOf, promotionOf, promotionsOf, recordPromotion, replayingOf, skippedToolsOf } from "../learn/promote.js";
59
+ import { refusedIn } from "../purged-workflow.js";
59
60
  import { sendCommand } from "./commands.js";
60
61
  import { ClaimRefused } from "./loop-contract.js";
61
62
  import { readSnapshot } from "../learn/folder.js";
@@ -78,6 +79,7 @@ export function claimPromotion(deps) {
78
79
  ...deps,
79
80
  kept: async () => (deps.runId ? servedOf(await runEntries(deps.store, deps.runId, deps.context).catch(() => [])) : undefined),
80
81
  champion: async (name, commit) => (await workflowsAt({ folder: deps.folder, store: deps.store, shown: deps.shown }, commit)).find((one) => one.name === name),
82
+ refused: refusedIn(deps.folder, deps.store, deps.log),
81
83
  newest: async (name) => {
82
84
  const folder = deps.folder();
83
85
  let main;
@@ -145,7 +147,7 @@ export async function toolFlowsFor(deps, launch, laid, choice) {
145
147
  continue;
146
148
  }
147
149
  const digest = workflowDigest(one);
148
- const { champion, text } = await championTextOf(records, one, deps.champion);
150
+ const { champion, text } = await championTextOf(records, one, deps.champion, deps.refused);
149
151
  if (text === one)
150
152
  out.push(one);
151
153
  else if (text) {
@@ -159,10 +161,11 @@ export async function toolFlowsFor(deps, launch, laid, choice) {
159
161
  }
160
162
  /** `flow`'s champion (championOf) and the text it serves from: `flow` itself when it is the champion, else the
161
163
  * champion's text read at its record's commit (`read`), kept only when its digest is the champion's. No text: none is
162
- * promoted, or its text cannot be read. The one champion lookup a claim's gate (servingNow), the learned_workflow tool
163
- * (toolFlowsFor) and a connected agent's start (sdk/runs.ts) share. */
164
- export async function championTextOf(records, flow, read) {
165
- const champion = championOf(records, flow.name);
164
+ * promoted, or its text cannot be read. The champion skips what `refused` says the purge gate refuses (PromotionDeps
165
+ * refused), so after a purge of its run the newest promotion the gate lets through serves. The one champion lookup a
166
+ * claim's gate (servingNow), the learned_workflow tool (toolFlowsFor) and a connected agent's start (sdk/runs.ts) share. */
167
+ export async function championTextOf(records, flow, read, refused) {
168
+ const champion = championOf(records, flow.name, refused ? await refused(records, [flow.name]) : undefined);
166
169
  if (!champion)
167
170
  return {};
168
171
  if (champion.digest === workflowDigest(flow))
@@ -217,7 +220,7 @@ export const promotionGate = (deps) => {
217
220
  * serves: none promoted, the champion held, or its text cannot be read (the agent takes the run). */
218
221
  async function servingNow(deps, workflow, digest, laid) {
219
222
  const records = await promotionsOf(deps.store.settings, deps.agentId);
220
- const { champion, text } = await championTextOf(records, workflow, deps.champion);
223
+ const { champion, text } = await championTextOf(records, workflow, deps.champion, deps.refused);
221
224
  const own = promotionOf(records, workflow.name, digest);
222
225
  if (!champion) {
223
226
  if (own?.decided === "promote")
@@ -259,7 +262,7 @@ async function holdRefused(deps, serving) {
259
262
  return serving;
260
263
  const reason = excerptShown(`${DSL_REFUSES}: ${refused}`, await deps.shown(), CHECK_TEXT_MAX);
261
264
  const record = { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, ...(current.commit ? { commit: current.commit } : {}) };
262
- const kept = await recordPromotion(deps.store.settings, deps.agentId, record, (was) => was?.decided === "promote" && was.at === current.at);
265
+ const kept = await recordPromotion(deps.store.settings, deps.agentId, record, (was) => was?.decided === "promote" && was.at === current.at, deps.refused);
263
266
  if (kept.won)
264
267
  deps.log(`workflow-first: ${name} at ${digest} is held: ${reason}; the agent's next run recompiles it once`);
265
268
  return serving;
@@ -440,7 +443,7 @@ export const differentDecisionWords = (k, n, example) => `its answers reached a
440
443
  * or its owner acts, and `extra` on the record (a connected agent's check: what its reservation carries). Kept only while
441
444
  * `still` holds of the digest's record (the one write), and logged. */
442
445
  async function holdUnchecked(deps, name, digest, bar, reason, still, { stopped = false, check = {}, extra = {} } = {}) {
443
- const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, of: [], ...check, ...(stopped ? { stopped: true } : {}) }, ...seedOf(deps), ...extra }, still);
446
+ const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, of: [], ...check, ...(stopped ? { stopped: true } : {}) }, ...seedOf(deps), ...extra }, still, deps.refused);
444
447
  if (decided.won)
445
448
  deps.log(`workflow-first: ${name} at ${digest} ${stopped ? "stopped" : "held"}: ${reason}`);
446
449
  return decided;
@@ -563,7 +566,8 @@ async function scoreRows(deps, bar, rows, before) {
563
566
  /** Two outcome counts added. */
564
567
  const outcomesAdded = (a, b) => b ? { answered: a.answered + b.answered, handed_back: a.handed_back + b.handed_back, failed: a.failed + b.failed, skipped_write: a.skipped_write + b.skipped_write } : a;
565
568
  /** Decides a check on its rows, with a connected agent's turns checked before them (`before`), scored on its bar
566
- * (scoreRows). Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
569
+ * (scoreRows). Promoted when it clears the bar (checkPasses) and the purge gate lets its revision through at its commit
570
+ * (`refused`: else held, a purged run's text); else held with the inputs it did not agree on, which the
567
571
  * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
568
572
  * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
569
573
  * (the one write: of two claims at once, one decides). */
@@ -604,9 +608,15 @@ export async function decideCheck(deps, name, digest, bar, read, still, extra) {
604
608
  const verbatim = ok || bar.agree_on?.length ? "" : grader ? (differed > 0 ? `; ${differentDecisionWords(differed, score.alone, example)}` : "") : score.alone > 0 && score.agreed === 0 ? `; ${read.exactMismatchReason ?? NEVER_WORD_FOR_WORD}` : "";
605
609
  const reason = ok ? `${said}: promoted` : stopped ? `${said}: held${verbatim}, and this was the recompile's check, so it stops: nothing compiles again until a hold or its owner acts` : `${said}: held${verbatim}; the agent's next run recompiles it once with the inputs it did not agree on`;
606
610
  const check = { ...bar, ...score, ...numbers, ...(disagreements.length ? { disagreements } : {}), ...(stopped ? { stopped: true } : {}), ...(grader ? { grader } : {}) };
607
- const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso(now()), decided: ok ? "promote" : "hold", reason, check, ...seedOf(deps), ...extra }, still);
611
+ const record = { workflow: name, digest, at: iso(now()), decided: ok ? "promote" : "hold", reason, check, ...seedOf(deps), ...extra };
612
+ // A check that outlives its revision's run: the run's purge never stops it (it replays other runs' inputs), and the
613
+ // purge gate refuses the revision at the commit it was checked at (purged-workflow.ts refusedOf). It is held, never
614
+ // promoted, so no promotion of the purged run's text lands.
615
+ const gone = ok && deps.refused !== undefined && (await deps.refused([record], [name]))(record);
616
+ const kept = gone ? { ...record, decided: "hold", reason: `${said}: held, never promoted: a purged run wrote this revision, and its text is gone` } : record;
617
+ const decided = await recordPromotion(deps.store.settings, deps.agentId, kept, still, deps.refused);
608
618
  if (decided.won)
609
- deps.log(`workflow-first: ${name} at ${digest} ${ok ? "promoted" : "held"}: ${reason}`);
619
+ deps.log(`workflow-first: ${name} at ${digest} ${kept.decided === "promote" ? "promoted" : "held"}: ${kept.reason}`);
610
620
  return decided;
611
621
  }
612
622
  /** Reserves a check of `workflow` at `digest` on `inputs`, then starts its runs: its replaying record names the replay
@@ -618,7 +628,7 @@ async function reserve(deps, workflow, digest, inputs, reason, still, check) {
618
628
  const now = deps.now ?? Date.now;
619
629
  const ids = inputs.map(() => uuidv7());
620
630
  const launch = replayLaunchOf(deps);
621
- const reserved = await recordPromotion(deps.store.settings, deps.agentId, { workflow: workflow.name, digest, at: iso(now()), decided: "replaying", reason, runs: ids, inputs: inputs.map((one) => one.run), replay_id: uuidv7(), launch, ...seedOf(deps), check }, (was, items) => still(was) && replayingOf(items, workflow.name, digest).length === 0);
631
+ const reserved = await recordPromotion(deps.store.settings, deps.agentId, { workflow: workflow.name, digest, at: iso(now()), decided: "replaying", reason, runs: ids, inputs: inputs.map((one) => one.run), replay_id: uuidv7(), launch, ...seedOf(deps), check }, (was, items) => still(was) && replayingOf(items, workflow.name, digest).length === 0, deps.refused);
622
632
  if (reserved.won)
623
633
  for (const [i, one] of inputs.entries())
624
634
  await startReplay(deps, workflow, digest, one.run, one.launch, ids[i], launch);
@@ -699,7 +709,7 @@ export async function reserveSdkCheck(deps, turn) {
699
709
  workflow: flow.name, digest, at: iso(now()), decided: "replaying", via: "sdk",
700
710
  reason: `Checking it in the connected agent against an independent native turn before it can be reused: ${sdkTurnsWords(check)}.`,
701
711
  replay_id: id, runs: [turn.runId], inputs: [turn.runId], commit: revision, check,
702
- }, (was, current) => (own ? waitingSdk(was) && was.replay_id === own.replay_id : was === undefined) && blocking(current, flow.name, digest).length === 0);
712
+ }, (was, current) => (own ? waitingSdk(was) && was.replay_id === own.replay_id : was === undefined) && blocking(current, flow.name, digest).length === 0, deps.refused);
703
713
  if (reserved.won)
704
714
  return { id, revision, digest, workflow: flow };
705
715
  }
@@ -743,7 +753,7 @@ export async function sdkCheckTurn(deps, record, row, still, read = {}) {
743
753
  * as waiting: a turn's row (sdkCheckTurn) and a give-back (releaseSdkCheck). */
744
754
  function waitAgain(deps, record, check, reason, still = () => true) {
745
755
  const { runs: _runs, inputs: _inputs, ...rest } = record;
746
- return recordPromotion(deps.store.settings, deps.agentId, { ...rest, at: iso((deps.now ?? Date.now)()), check, reason }, (was, current) => still(was, current) && sameReplay(was, record) && heldTurn(was, record) && !overtaken(current, was));
756
+ return recordPromotion(deps.store.settings, deps.agentId, { ...rest, at: iso((deps.now ?? Date.now)()), check, reason }, (was, current) => still(was, current) && sameReplay(was, record) && heldTurn(was, record) && !overtaken(current, was), deps.refused);
747
757
  }
748
758
  /** A connected agent's check whose native turn did not settle it by REPLAY_DEADLINE_MS (the backend never completed the
749
759
  * turn, or the server stopped before the run's end): one failed row of its turns (sdkCheckTurn), as a managed check's
@@ -1052,7 +1062,7 @@ export async function askReplay(ask, name, digest, inputs) {
1052
1062
  throw new ReplayRefused("conflict", PROJECT_REPLAY_REFUSED);
1053
1063
  if (!launch.learning || launch.learning.noWorkflows)
1054
1064
  throw new ReplayRefused("conflict", `A replay runs ${name} as a run of the agent that learns does, and the agent's runs do not take learned workflows here (its learning is off, it takes no workflows, or this server's is off).`);
1055
- const deps = { store: ask.store, agentId: ask.agentId, revisionId, launch: { ...launch, learning: { ...launch.learning, seed: found.commit } }, context: ask.context, log: ask.log, shown: ask.shown, ...(ask.admitAuxiliary ? { admitAuxiliary: ask.admitAuxiliary } : {}), ...(ask.now ? { now: ask.now } : {}) };
1065
+ const deps = { store: ask.store, agentId: ask.agentId, revisionId, launch: { ...launch, learning: { ...launch.learning, seed: found.commit } }, context: ask.context, log: ask.log, shown: ask.shown, refused: refusedIn(ask.folder, ask.store, ask.log), ...(ask.admitAuxiliary ? { admitAuxiliary: ask.admitAuxiliary } : {}), ...(ask.now ? { now: ask.now } : {}) };
1056
1066
  const bar = { ...loop, attempt: attemptOf(records, name, digest) };
1057
1067
  const said = `checking it on ${plural(picked.length, "input")} of the agent's own runs, as its owner asked`;
1058
1068
  // Kept only while the revision's newest record is still the one read here: each record write stamps a new `at`.
@@ -22,7 +22,8 @@ import { putLiveViewer, dropLiveViewer } from "../browser-live.js";
22
22
  import { CALENDAR_EVENTS } from "../calendar/names.js";
23
23
  import { openCalendar } from "../calendar/address.js";
24
24
  import { openAccount } from "../email/account.js";
25
- import { harnessOf, recipeHarness } from "../harness-table.js";
25
+ import { harnessOf, recipeHarness, recipeKeysOf } from "../harness-table.js";
26
+ import { openHarnessKeys } from "../harness-keys.js";
26
27
  import { installDirOf, installForClaim, shareInstall } from "../harness-install.js";
27
28
  import { loadArchilSettings } from "../archil-settings.js";
28
29
  import { planOf } from "../chatgpt-plan.js";
@@ -31,7 +32,7 @@ import { vendorsOver } from "../sign-ins.js";
31
32
  import { decisionProvidersIn, fauxFetch } from "../decisions.js";
32
33
  import { DECISION_PROVIDER_KEYS } from "../tool-plane.js";
33
34
  import { learningEndOfRun } from "./learning-end.js";
34
- import { cutDeep, heldRedactor, runnerSecrets } from "./redact.js";
35
+ import { cutDeep, runnerSecrets } from "./redact.js";
35
36
  import { storeSecrets } from "./store-secrets.js";
36
37
  import { FAUX_ENV, GATEWAY_KEY_ENV } from "../model.js";
37
38
  import { SAVED_GATEWAY_ENV, savedGatewayIn } from "../model-gateway.js";
@@ -47,7 +48,7 @@ import { agentDirName, recordingsFolder, runFolder, scratchFolder } from "../wor
47
48
  import { keptKeyOf } from "../workspace/computer-kept.js";
48
49
  import { claimModelKey, claimSecrets, claimSpendOff, hostDecisionKeys, learnedDecisionKeys, openRunModelKey, savedModelKeys, serverKeyless, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
49
50
  import { githubAppAccess } from "./github-app.js";
50
- import { githubPullOf } from "../github.js";
51
+ import { githubPullOf, githubTargetOf } from "../github.js";
51
52
  import { isObject } from "../validate.js";
52
53
  import { liveForRun, runnerLiveOf } from "../live-reach.js";
53
54
  import { learningFolderOf, secretsShown } from "../learning.js";
@@ -709,7 +710,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
709
710
  mcp: (ask) => projectCall(async () => {
710
711
  const reach = await mcpReachOf(deps);
711
712
  const harness = { commit: (change) => change({ appendEntry: async (_conversation, entry) => void (await ask.appendRoot(dataOnly(entry))) }) };
712
- const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, work: () => runFolder(deps.data, run.agentId, claim.runId), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web: deps.evalFakes?.(run.agentId)?.web, slots: deps.saveSlots } });
713
+ const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, work: () => runFolder(deps.data, run.agentId, claim.runId), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web: deps.evalFakes?.(run.agentId)?.web, slots: deps.saveSlots } });
713
714
  if (!made)
714
715
  return undefined;
715
716
  releases.push(() => made.release());
@@ -720,15 +721,18 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
720
721
  // A run's process mints for one thing alone: its revision's pull-request checkout (pr-checkout.ts), of the pull
721
722
  // request its launch's payload names, contents read. Its MCP mints on the runner (mcp above). So the mint handed
722
723
  // here makes that token and no other, whatever repository or permissions the process names.
723
- if (revision.body.checkout !== "pull_request")
724
+ // A repository checkout's is the repository the run names (its start's repo, else the first https://github.com
725
+ // URL its owner's words name): the same one repository, contents read.
726
+ if (revision.body.checkout !== "pull_request" && revision.body.checkout !== "repository")
724
727
  return undefined;
725
- const pull = githubPullOf(isObject(launch.input) ? launch.input.content : launch.input, { payload: fromGitHub });
728
+ const content = isObject(launch.input) ? launch.input.content : launch.input;
729
+ const pull = revision.body.checkout === "pull_request" ? githubPullOf(content, { payload: fromGitHub }) : launch.repo !== undefined ? { repo: launch.repo } : githubTargetOf(content, { payload: fromGitHub });
726
730
  if (!pull)
727
731
  return undefined;
728
732
  const access = await github();
729
733
  if (!access)
730
734
  return undefined;
731
- const bound = { repo: pull.repo, ...(pull.installation !== undefined ? { installation: pull.installation } : {}) };
735
+ const bound = { repo: pull.repo, ...("installation" in pull && pull.installation !== undefined ? { installation: pull.installation } : {}) };
732
736
  const mint = async (to) => {
733
737
  if (to?.repo !== bound.repo || to.installation !== bound.installation) {
734
738
  log(`run ${claim.runId}: its process asked for a GitHub token of another repository than its pull request's, which a run's process may not`);
@@ -767,6 +771,13 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
767
771
  serverKeyless: () => serverKeyless(keys),
768
772
  // The zone alone, from the claim's own launch's trigger: the process never reads a trigger's row.
769
773
  runZone: () => runZone(store, launch.inputOrigin),
774
+ // The keys saved for the claim's own harness alone (harness-keys.ts), whatever the process names: none unless that
775
+ // harness is a plan-billed recipe on this runner's table, and never another harness's.
776
+ harnessKeys: async () => {
777
+ const harness = launch.harness ?? revision.body.harness;
778
+ const names = harness === undefined ? undefined : recipeKeysOf(deps.env, harness);
779
+ return harness !== undefined && names?.length ? openHarnessKeys(store, sealKey, harness, names) : {};
780
+ },
770
781
  liveViewerPut: (handover) => putLiveViewer(store, sealKey, claim, handover),
771
782
  liveViewerDrop: (tag) => dropLiveViewer(store, claim, tag),
772
783
  // The claim's own run, whatever the process names: its view on this runner hears the change.
@@ -1018,10 +1029,11 @@ export { RECIPE_SIGN_IN_PERSON_ONLY } from "./harness-loops.js";
1018
1029
  export async function staysInRunner(deps, harness, launch, runId, isolation) {
1019
1030
  // A recipe's harness reads its install, its check's note and its owner's sign-in, each the server user's alone: never
1020
1031
  // opened to a slot's user (the sign-in least of all), so where each run is a user of its own it is refused here. And a
1021
- // plan-billed one's run that no person started (a schedule's, a trigger's) never runs on its owner's sign-in.
1032
+ // plan-billed one's run that no person started (a schedule's, a trigger's) never runs on its owner's sign-in: only on
1033
+ // keys saved for its harness.
1022
1034
  if (isolation.kind === "uid" && recipeHarness(deps.env ?? {}, harness))
1023
1035
  throw new ClaimRefused(RECIPE_NEEDS_SERVER_USER);
1024
- refuseRecipeTriggerRun(deps.env ?? {}, harness, launch);
1036
+ await refuseRecipeTriggerRun(deps, harness, launch);
1025
1037
  if (runsInRunner(harness, launch))
1026
1038
  return true;
1027
1039
  if (launch.documents !== undefined) {
@@ -1162,10 +1174,10 @@ function childLoop(options, slots, loopDeps) {
1162
1174
  }
1163
1175
  const savedGateway = savedGatewayIn(claimEnv);
1164
1176
  // The run's own keys: those its claim opens (claim-secrets.ts), the one list its loop in this process read.
1165
- const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv, redact: loopDeps.redact ? heldRedactor(loopDeps.redact) : undefined }, revisionRow, launch, claim.runId);
1177
+ const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv, redact: loopDeps.redact }, revisionRow, launch, claim.runId);
1166
1178
  // With them, its revision's own model's (a launch pinned at its start to another model, a --faux start's, is still
1167
1179
  // handed its agent's model's key, as a run's own process was handed it before: run-secrets.ts secretsFor).
1168
- const ofRevision = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }, revisionRow, { ...(launch.plane ? { plane: launch.plane } : {}) });
1180
+ const ofRevision = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv, redact: loopDeps.redact }, revisionRow, { ...(launch.plane ? { plane: launch.plane } : {}) });
1169
1181
  // A run that holds a model key of its own (model_key, its launch's) spends that key alone: its process is handed
1170
1182
  // none of the server's model keys, as its spec drops them from its tools' (claim-secrets.ts withoutModelKeys).
1171
1183
  // Copies: the runner's own reads (heldFor's `claimed`: what the run's learning must never keep) stay whole.
@@ -1274,6 +1286,7 @@ function childLoop(options, slots, loopDeps) {
1274
1286
  ...(deps.githubApi ? { githubApi: deps.githubApi } : {}),
1275
1287
  ...(deps.githubWeb ? { githubWeb: deps.githubWeb } : {}),
1276
1288
  ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}),
1289
+ ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}),
1277
1290
  };
1278
1291
  const ended = channel.call("loop", "start", [init]);
1279
1292
  // From here a command or a stop goes to the run's process, after its start on the channel.
@@ -185,6 +185,7 @@ function childDeps(init, store, journal, held) {
185
185
  ...(init.githubApi ? { githubApi: init.githubApi } : {}),
186
186
  ...(init.githubWeb ? { githubWeb: init.githubWeb } : {}),
187
187
  ...(init.githubMcpOrigin ? { githubMcpOrigin: init.githubMcpOrigin } : {}),
188
+ ...(init.composioMcpOrigin ? { composioMcpOrigin: init.composioMcpOrigin } : {}),
188
189
  ...(init.mcpLoopback ? { mcpLoopback: true, mcpOwn: init.mcpOwn ?? [] } : {}),
189
190
  };
190
191
  }
@@ -215,7 +216,8 @@ channel.expose("loop", async (method, args) => {
215
216
  live: (reader) => void (read = reader),
216
217
  redact: heldRedactor(processSecretRedactor()),
217
218
  };
218
- loop = createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) })(loopDeps);
219
+ // Its runner counted the harness's key rows before it made this process (staysInRunner): never again here.
220
+ loop = createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps, { keysCounted: true }) })(loopDeps);
219
221
  made(loop);
220
222
  // The loop's held state and whether a plain stop keeps its computer, posted when either moved.
221
223
  let last = "";
@@ -1,3 +1,4 @@
1
+ import { type Interfaces } from "../live-reach.js";
1
2
  import type { Settings } from "../store/store.js";
2
3
  /** The store.settings key a server keeps the names of its run-facing environment under at each start: `{ v: 1, names }`. */
3
4
  export declare const RUN_ENV_KEY = "server.run_env";
@@ -31,6 +32,8 @@ export interface RunnerEnvCheckOptions {
31
32
  readonly read: (name: string) => string | undefined;
32
33
  /** Whether a TCP connect to `host`:`port` is answered within `ms` (a test's stand-in). */
33
34
  readonly answers?: (host: string, port: number, ms: number) => Promise<boolean>;
35
+ /** This machine's network interfaces (a test's stand-in), for AGENTRUN_RUNNER_LIVE_HOST given as an IPv4 block. */
36
+ readonly interfaces?: Interfaces;
34
37
  }
35
38
  /** How long a forwarder has to answer the check's connect. */
36
39
  export declare const FORWARDER_MS = 2000;
@@ -25,6 +25,7 @@ import { HARNESS_MODULES_SETTING, HARNESS_RECIPES_SETTING } from "../harness-tab
25
25
  import { GATEWAY_IDS_ENV } from "../model-gateway.js";
26
26
  import { BOX_CPUS_ENV, BOX_MEMORY_ENV, BOX_PIDS_ENV, MCP_ALLOW_LOOPBACK_ENV } from "../start-switches.js";
27
27
  import { DOCKER_IMAGE_ENV } from "../box-image.js";
28
+ import { RunnerLiveRefused, runnerLiveOf } from "../live-reach.js";
28
29
  import { bootSealKey } from "../seal-key.js";
29
30
  import { SECRET_NAMES } from "../secrets.js";
30
31
  import { SEAL_KEY_ENV } from "../tool-keys.js";
@@ -197,8 +198,30 @@ export async function checkRunnerEnv(options) {
197
198
  for (const name of SERVER_ONLY)
198
199
  if (read(name)?.trim())
199
200
  rows.push({ state: "warn", name, why: "the server's own secret: a runner never needs it, so leave it off the runner" });
201
+ const liveRow = liveHostRow(env, options.interfaces);
202
+ if (liveRow)
203
+ rows.push(liveRow);
200
204
  return rows;
201
205
  }
206
+ /** AGENTRUN_RUNNER_LIVE_HOST's row, where it is set: the host the server reaches this runner at (an address, never a
207
+ * secret); warn where it names no host; bad where an IPv4 block holds none or several of this machine's addresses (live-reach.ts runnerLiveOf). */
208
+ function liveHostRow(env, interfaces) {
209
+ const name = "AGENTRUN_RUNNER_LIVE_HOST";
210
+ if (!env[name]?.trim())
211
+ return undefined;
212
+ try {
213
+ // The key is not read here: the host alone is.
214
+ const live = runnerLiveOf(env, Buffer.alloc(32), interfaces);
215
+ return live
216
+ ? { state: "ok", name, why: `the server reaches this runner's relay and viewers at ${live.host}` }
217
+ : { state: "warn", name, why: "not a host name, an IPv4 address or an IPv4 block other than loopback: this runner's relay and viewers stay on loopback, where a server on another host cannot reach them" };
218
+ }
219
+ catch (error) {
220
+ if (error instanceof RunnerLiveRefused)
221
+ return { state: "bad", name, why: error.message };
222
+ throw error;
223
+ }
224
+ }
202
225
  /** The check's lines: one per row (its state, its name, why), then the outcome. */
203
226
  export function checkLines(rows) {
204
227
  const width = Math.max(0, ...rows.map((row) => row.name.length));
@@ -6,6 +6,7 @@ import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/conte
6
6
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
7
7
  import { freeRequestLimitOf } from "@parcha/agentrun-kernel/kernel/cap";
8
8
  import { learningFolderOf, secretsShown } from "../learning.js";
9
+ import { refusedIn } from "../purged-workflow.js";
9
10
  import { said, STOPPED } from "../learning-words.js";
10
11
  import { cliPolicyOf, closeSdkInbox, sdkInbox } from "../sdk/runs.js";
11
12
  import { settleSdkCheck } from "../sdk/check.js";
@@ -103,6 +104,7 @@ export function createSdkLoop(launch, host, route) {
103
104
  store: host.store, agentId: agent, launch, inbox,
104
105
  shown: async () => secretsShown(Object.values(await storeSecrets(host.store, host.sealKey, host.data)), { local: true }),
105
106
  log: (line) => host.log?.(line),
107
+ refused: refusedIn(() => learningFolderOf(host.data, agent), host.store, (line) => host.log?.(line)),
106
108
  });
107
109
  }
108
110
  catch (error) {
@@ -5,7 +5,7 @@ import type { Workflow } from "@parcha/agentrun-dsl";
5
5
  import { type WorkflowTaskHost } from "../workflow/task.js";
6
6
  import { type BudgetData, type EndData } from "./journal-kinds.js";
7
7
  import { type Claim, type Journal, type LoopFactory } from "./loop-contract.js";
8
- import { type HeldRedact } from "./redact.js";
8
+ import type { HeldRedact } from "./redact.js";
9
9
  /** A cap refusal, as the kernel cap hands one to parkOf/checkRaise (the loop never imports the cap; its rule is handed in
10
10
  * via the spec, so flat or tiered pricing is the cap's, not this loop's). */
11
11
  /** `node`: the label of the workflow node whose step the cap held (a model node's request, a call node's call, a
@@ -130,7 +130,7 @@ export declare const isWorkflowRevision: (revision: {
130
130
  /** What a claim's spec is built from beside the claim: the runner's one redactor (LoopDeps.redact), which holds the keys
131
131
  * the claim opens from the store (redact.ts holdClaimed). */
132
132
  export interface WorkflowSpecRun {
133
- readonly redact?: HeldRedact;
133
+ readonly redact: HeldRedact;
134
134
  /** A fresh journal of the claim, for what the spec reads from the run's records at its end (its decisions' booked
135
135
  * cost): a fresh one, since the Harness closes its own before the end is written. */
136
136
  readonly journal?: () => Journal;
@@ -23,7 +23,6 @@ import { createWorkflowExtension } from "../workflow/task.js";
23
23
  import { readWorkflowRun, startWorkflowRevision, workflowCarry } from "../workflow-run.js";
24
24
  import { KINDS } from "./journal-kinds.js";
25
25
  import { stopEnd } from "./loop-contract.js";
26
- import { heldRedactor } from "./redact.js";
27
26
  import { END_PATCH_MS, END_PATCH_UNKNOWN, readAgain } from "./loop.js";
28
27
  /** A paused run's words, its row's summary while it waits for a resume. */
29
28
  export const PAUSED_WORDS = "Paused.";
@@ -218,7 +217,7 @@ function workflowLoop(specOf, deps) {
218
217
  const parkController = new AbortController();
219
218
  let heldRefusal;
220
219
  const context = withAbortSignal(AbortSignal.any([deps.signal, parkController.signal]), BACKGROUND_CONTEXT);
221
- spec = await specOf(claim, { ...(deps.redact ? { redact: heldRedactor(deps.redact) } : {}), journal: () => deps.journal(claim) });
220
+ spec = await specOf(claim, { redact: deps.redact, journal: () => deps.journal(claim) });
222
221
  claimNow = claim;
223
222
  specReady();
224
223
  const revision = { id: spec.revisionId, kind: "workflow", body: { workflow: spec.workflow, tools: [...spec.tools] } };
@@ -83,7 +83,7 @@ interface DecisionProviders {
83
83
  export declare function workflowSpecOf(deps: WorkflowSpecDeps): (claim: {
84
84
  runId: string;
85
85
  runner?: string;
86
- }, run?: WorkflowSpecRun) => Promise<WorkflowRunSpec>;
86
+ }, run: WorkflowSpecRun) => Promise<WorkflowRunSpec>;
87
87
  /** The run's rule with a park on a refusal: `before` (runCap's one rule for the model session) is asked, and on a refusal
88
88
  * the run parks through the loop's hook (parkOf decides room vs for good from the refusal), the same as the pi adapter's
89
89
  * parkAtCap. It still returns the refusal, so the proxy refuses the request and the node's turn ends. */