@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
@@ -2,14 +2,18 @@ import { ApiError } from "./errors.js";
2
2
  import { GRAPH_CACHE_BYTES, PartCache, servedGraphView } from "./graph-served.js";
3
3
  import { runGraph } from "./graph-view.js";
4
4
  import { checkedPath, decodedPath } from "./home-path.js";
5
+ import { redactSecrets } from "./learn/secrets.js";
6
+ import { underCut } from "./run-cut.js";
5
7
  import { usageWordsOf, WITHHELD_SIGN_IN } from "./run-view.js";
6
8
  import { ChangeClock, RowLog } from "./rows.js";
7
- import { listFiles, sendFile } from "./run-files.js";
9
+ import { entryAt, listFiles, RUN_FILE_CUT_MAX, sendFile } from "./run-files.js";
10
+ import { typeOf } from "./file-types.js";
8
11
  import { readLaunchBody } from "./run-launch.js";
9
12
  import { costIsBooked } from "./runner/metrics.js";
10
13
  import { runEntries, runTimeline } from "./store-reads/journal.js";
11
14
  import { StoreLaunchMissing } from "./store/index.js";
12
15
  import { isUnavailable, recheckPlane, whyUnavailable } from "./tool-plane.js";
16
+ import { isWorkspaceError } from "./workspace/index.js";
13
17
  import { RECORDINGS } from "./workspace/paths.js";
14
18
  /** The most files a list answers with (server.ts FILE_LIST_CAP). */
15
19
  export const FILE_LIST_CAP = 2_000;
@@ -26,10 +30,17 @@ export async function listRunFiles(store, runId, deps) {
26
30
  files.sort((a, b) => a.path.localeCompare(b.path));
27
31
  return { run_id: runId, files: files.slice(0, FILE_LIST_CAP), complete: true, truncated: deep || files.length > FILE_LIST_CAP };
28
32
  }
33
+ /** A type the cut read takes as text: one the table names text, JSON or NDJSON, or one it doesn't know (its bytes are
34
+ * then read as UTF-8, and a file that isn't is 415). */
35
+ const cutsAsText = (type) => type === undefined || type.startsWith("text/") || type === "application/json" || type === "application/x-ndjson";
29
36
  /** One of a run's files, through its Workspace (readRunFile): streamed to `res` as the route streams it, with the route's
30
37
  * path check and its 404 words; a withheld run refuses (403) before anything is streamed. A path under recordings/ is
31
- * one of the run's recordings (its recordings folder, beside its Workspace's), never a file the run made. */
38
+ * one of the run's recordings (its recordings folder, beside its Workspace's), never a file the run made. With
39
+ * `?cut=run`, the file's text under the run's own cut instead (cutRunFile). */
32
40
  export async function readRunFile(store, runId, rawPath, req, res, url, deps) {
41
+ const cut = url.searchParams.get("cut");
42
+ if (cut !== null && cut !== "run")
43
+ throw new ApiError("bad_request", `cut must be "run", not ${JSON.stringify(cut)}`);
33
44
  if (await deps.withheld(store, runId))
34
45
  throw new ApiError("forbidden", WITHHELD_SIGN_IN);
35
46
  const rel = checkedPath(decodedPath(rawPath), "the run's own, not a file it wrote");
@@ -37,8 +48,61 @@ export async function readRunFile(store, runId, rawPath, req, res, url, deps) {
37
48
  const workspace = await (recording === undefined ? deps.runWorkspace : deps.recordings)(store, runId);
38
49
  if (!workspace)
39
50
  throw new ApiError("not_found", "no such file");
51
+ if (cut === "run")
52
+ return cutRunFile(store, runId, workspace, recording ?? rel, req, res, deps);
40
53
  return sendFile(req, res, url, workspace, recording ?? rel, "a tool in the run's box");
41
54
  }
55
+ /** File `rel` of the run's `workspace` as UTF-8 text cut of everything the run's own cut holds (deps.cutValues, the set its
56
+ * timeline's calls are cut of: the server's keys, the keys a person saved, its secret stores' values and the sign-in
57
+ * refs the run was handed), through redactSecrets over the whole text, each value and secret shape replaced by
58
+ * "[redacted]" in place, and the text "[redacted]" whole when a value still shows in another form. A long run with no
59
+ * whitespace (compact JSON) is never blanked for its length. The cut holds this server's values, not every secret: a
60
+ * value handed to the run alone at its launch (a key of its own, an MCP server's headers) is not in it. The cut is
61
+ * read again after the text is cut (underCut), so a value saved meanwhile is cut too. An unreadable cut (the run withheld) is 403; a type that isn't text, or bytes that
62
+ * aren't UTF-8 or hold a NUL, 415; a file over RUN_FILE_CUT_MAX, 413. A Range header is not read: the answer is the
63
+ * whole file. */
64
+ async function cutRunFile(store, runId, workspace, rel, req, res, deps) {
65
+ const unreadable = () => new ApiError("system_file_forbidden", "This file was created private by a tool in the run's box: this server cannot read it.", { details: { reason: "unreadable" } });
66
+ const entry = await entryAt(workspace, rel);
67
+ if (entry?.kind !== "file")
68
+ throw new ApiError("not_found", "no such file");
69
+ if (entry.unreadable)
70
+ throw unreadable();
71
+ const type = typeOf(rel);
72
+ if (!cutsAsText(type))
73
+ throw new ApiError("unsupported_media_type", `a cut read answers text, and this file is ${type}`);
74
+ if (entry.size > RUN_FILE_CUT_MAX)
75
+ throw new ApiError("payload_too_large", `a cut read answers a file of at most ${RUN_FILE_CUT_MAX} bytes, and this one is ${entry.size}`);
76
+ const bytes = entry.size === 0 ? new Uint8Array(0) : await workspace.read(rel, { offset: 0, length: entry.size }).catch((error) => {
77
+ if (isWorkspaceError(error, "REFUSED"))
78
+ throw unreadable();
79
+ if (isWorkspaceError(error) && (error.code === "NOT_FOUND" || error.code === "ESCAPE"))
80
+ throw new ApiError("not_found", "no such file");
81
+ throw error;
82
+ });
83
+ let text;
84
+ try {
85
+ text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
86
+ }
87
+ catch {
88
+ throw new ApiError("unsupported_media_type", "a cut read answers UTF-8 text, and this file's bytes are not");
89
+ }
90
+ if (text.includes("\u0000"))
91
+ throw new ApiError("unsupported_media_type", "a cut read answers text, and this file holds a NUL byte");
92
+ const shown = await underCut(() => deps.cutValues(store, runId), async (cut) => (cut === "unreadable" ? undefined : redactSecrets(text, cut.values, Buffer.byteLength(text))));
93
+ if (shown === undefined)
94
+ throw new ApiError("forbidden", WITHHELD_SIGN_IN);
95
+ const body = Buffer.from(shown);
96
+ res.writeHead(200, {
97
+ "content-type": "text/plain; charset=utf-8",
98
+ "content-length": body.length,
99
+ "x-content-type-options": "nosniff",
100
+ "cache-control": "no-store",
101
+ // The mark that this answer is the cut text: a server that doesn't know `cut` serves the raw bytes, without it.
102
+ "x-agentrun-cut": "run",
103
+ });
104
+ res.end(req.method === "HEAD" ? undefined : body);
105
+ }
42
106
  /** Whether the run's revision grants the browser tool: an agentic revision whose tools name it. */
43
107
  async function grantsBrowser(store, revisionId) {
44
108
  const revision = await store.agents.revision(revisionId);
@@ -1,4 +1,5 @@
1
1
  import { harnessModelKeys } from "./adapters.js";
2
+ import { COMPOSIO_KEY_ENV } from "./composio-made.js";
2
3
  import { COMPUTER_KEY_NAMES } from "./computer-keys.js";
3
4
  import { BOX_KEYS } from "./place-offers.js";
4
5
  import { providersNamed } from "./decisions.js";
@@ -18,8 +19,10 @@ const COMPUTER_ACCOUNT_KEYS = COMPUTER_KEY_NAMES.filter((name) => !TOOL_FIELDS.i
18
19
  * kept under (tool-keys.ts), the store's URL (it may hold the database's password), the remote boxes' keys
19
20
  * (place-offers.ts BOX_KEYS) and every other computer provider's account key, which only the server's and the runner's
20
21
  * computer providers use, the Archil account key (archil-key.ts), from which the claim mints each run's own mount
21
- * credential, and the launch hook's signing secret (trigger-launch-hook.ts). */
22
- const SERVER_ONLY = new Set(["AGENTRUN_TOKEN", "AGENTRUN_TOKENS", "AGENTRUN_API_KEY", "AGENTRUN_SEAL_KEY", "AGENTRUN_STORE_URL", ...BOX_KEYS, ...COMPUTER_ACCOUNT_KEYS, ARCHIL_API_KEY_ENV, LAUNCH_HOOK_SECRET_ENV]);
22
+ * credential, the launch hook's signing secret (trigger-launch-hook.ts), and the Composio account key a Composio MCP
23
+ * server saved with api_key_env reads (composio-made.ts), which reaches a run only as the MCP header of a Composio
24
+ * server its revision is granted, sent by the runner. */
25
+ const SERVER_ONLY = new Set(["AGENTRUN_TOKEN", "AGENTRUN_TOKENS", "AGENTRUN_API_KEY", "AGENTRUN_SEAL_KEY", "AGENTRUN_STORE_URL", ...BOX_KEYS, ...COMPUTER_ACCOUNT_KEYS, ARCHIL_API_KEY_ENV, LAUNCH_HOOK_SECRET_ENV, COMPOSIO_KEY_ENV]);
23
26
  /** The secrets a run may be handed: every one but the server's own and the decision keys, which go apart. */
24
27
  export const RUN_SECRETS = SECRET_NAMES.filter((name) => !SERVER_ONLY.has(name) && !DECISION_KEYS.includes(name));
25
28
  /** The fields a run gets only when its revision names what they unlock: a `tool` key's. Any other kind's (a model key's)
@@ -6,7 +6,7 @@ import { type BudgetData, type EndData, type ToolCalls } from "./journal-kinds.j
6
6
  import { type MessageOrigin } from "../timeline/index.js";
7
7
  type EndCost = Required<Pick<EndData, "costUsd" | "costUpperBound">>;
8
8
  import { type Claim, type EndOfRunTurn, type LoopFactory } from "./loop-contract.js";
9
- import { type HeldRedact } from "./redact.js";
9
+ import type { HeldRedact } from "./redact.js";
10
10
  import { Parked } from "./loop.js";
11
11
  import type { PiRun } from "./adapters/pi.js";
12
12
  import { type HeldSpec } from "./held-run.js";
@@ -226,6 +226,9 @@ export interface AdapterRunSpec {
226
226
  * raise of its cap, a person's answer) it ends failed at once in these words, saying what it would wait on, every call
227
227
  * still waiting withdrawn in the end's commit (parkClaim). Absent: it parks. */
228
228
  readonly neverWaits?: string;
229
+ /** The session runs on its owner's own sign-in, a plan-billed recipe's claim having laid not every key saved for it
230
+ * (cli-run-spec.ts): a trigger's message is refused in these words, never sent into it (steer). Absent: taken. */
231
+ readonly personOnly?: string;
229
232
  /** What the spec's tool host bindings registered (tools.ts ToolHost's onConversation, beforeResume, beforeRelease),
230
233
  * run where main's per-run process runs them (app.ts): each agent conversation's creating commit, once the claim's
231
234
  * Harness is open and before anything in it resumes, and when the claim lets the run go (its end, a park, a
@@ -294,8 +297,8 @@ export type AdapterRun = PiRun & {
294
297
  readonly ledger: RunLedger;
295
298
  /** The runner's one redactor (LoopDeps.redact; runner.ts), the same instance: the spec gives it to every place a secret
296
299
  * could reach text (the session's model proxy, the model route's translation, its log lines), and its claim carries the
297
- * run's own tool keys into (claim-secrets.ts). Absent where no runner gave one (a spec built alone). */
298
- readonly redact?: HeldRedact;
300
+ * run's own tool keys into (claim-secrets.ts). */
301
+ readonly redact: HeldRedact;
299
302
  /** The claim's signal (LoopDeps.signal): aborted on a lost claim or the runner's shutdown, never on a person's stop. A
300
303
  * spec's per-claim resources let go of what they hold at once on it (the run's Archil mount credential). Absent where
301
304
  * no loop gave one (a spec built alone). */
@@ -41,7 +41,6 @@ const outputRetried = (entries) => {
41
41
  return at >= 0 && entries.slice(at + 1).some((entry) => entry.kind === "pi.assistant" || (entry.kind === KINDS.message && entry.data?.role === "model"));
42
42
  };
43
43
  import { ClaimRefused, deniedText, noteOf, stopEnd } from "./loop-contract.js";
44
- import { heldRedactor } from "./redact.js";
45
44
  import { deniedText as setToDenyText, ENDED_WHILE_WAITING, refusedText, STOPPED_WHILE_WAITING } from "../refusal-words.js";
46
45
  import { ADAPTER_API } from "../turn-end.js";
47
46
  import { answerText, REFLECT_PREFIX, reflectRequestId } from "./end-of-run.js";
@@ -56,7 +55,7 @@ import { COMPUTER_CALLS, recordingCalls } from "../computer-calls.js";
56
55
  import { channelCallOf, runChannelCall } from "./computer-channel.js";
57
56
  import { COMPUTER_HANDOVER_KIND, COMPUTER_HOLD_KIND } from "../computer-commands.js";
58
57
  import { journalSessions } from "./sessions.js";
59
- import { DECISION_SESSION, FIT_TOLERANCE, freeModel, freeRequestsIn, freeWrapUpDue, freeWrapUpWords, noteFor, overCapEnd, overCapOf, paidRefusal, requestFigures, runCap, SERVER_NOTE_LABEL, typicalCost, wrapUpWords, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
58
+ import { DECISION_SESSION, FIT_TOLERANCE, freeLimitNearest, freeRequestsIn, freeWrapUpDue, freeWrapUpWords, localRequestsIn, noteFor, overCapEnd, overCapOf, paidRefusal, requestFigures, runCap, SERVER_NOTE_LABEL, typicalCost, wrapUpWords, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
60
59
  import { PORT_PROVIDER, portModels, tierProvider } from "../port-models.js";
61
60
  import { bookedIn, stopRunWith } from "../paid-calls.js";
62
61
  import { sideEffect } from "./side-effects.js";
@@ -1068,6 +1067,12 @@ function adapterLoop(specOf, options, deps) {
1068
1067
  // untaken for the next claim, which hands it on again; never refused for good.
1069
1068
  if (!gate || !session || gate.sealed)
1070
1069
  return { later: "the run is parking: the steer waits for its resume" };
1070
+ // A trigger's message into a session on its owner's sign-in (personOnly): refused for good, before it is queued or
1071
+ // placed, so no turn of it reaches the vendor on that sign-in. Known by its origin's kind as written (an origin whose
1072
+ // source originOf does not know is still a trigger's), or by answering nothing (answers: false, a trigger's message).
1073
+ const sent = command.body;
1074
+ if (specNow?.personOnly && (sent?.origin?.kind === "trigger" || sent?.answers === false))
1075
+ return { refused: specNow.personOnly };
1071
1076
  // The session is still new and this is no reopen's message (the claim has yet to send the run's input), or the run's
1072
1077
  // learned workflow runs first, or a message before it still waits for either: it waits for the input, off the runner's
1073
1078
  // delivery, as a computer channel's call does (channelCommand). The runner hands the run's rows on one at a time, each
@@ -1215,12 +1220,15 @@ function adapterLoop(specOf, options, deps) {
1215
1220
  }
1216
1221
  // Who wrote it, when the person did not (a trigger's message): carried on its input, as the Timeline shows it.
1217
1222
  const origin = originOf(command.body?.origin);
1218
- // A harness that takes no message mid-turn, or a CLI's message that is no steer of the turn in flight (a trigger's that
1219
- // answers nothing, or the person's answer to the question its last turn ended on, whose session is idle): the API
1220
- // answered it `follow_up` (it waits for the turn's end), so it is the run's next turn, after any taken before it
1221
- // (afterTurn). Taken now as the dispatch takes a row it buffers: the store's take is the commit of its submission, once
1222
- // sent.
1223
- if (!session.steer || (cliRecord && (followUp || askedLast))) {
1223
+ // A harness that takes no message mid-turn, a trigger's message (it answers nothing) while a turn is open, or a CLI's
1224
+ // message that is no steer of the turn in flight (a trigger's, or the person's answer to the question its last turn
1225
+ // ended on, whose session is idle): the API answered it `follow_up` (it waits for the turn's end), so it is the run's
1226
+ // next turn, after any taken before it (afterTurn). Taken now as the dispatch takes a row it buffers: the store's take
1227
+ // is the commit of its submission, once sent. A trigger's message is never pi's own follow-up: pi runs one as soon as
1228
+ // its turn would end, before this loop reads that end, so one that met a turn ending on ask_person ran in place of the
1229
+ // person's answer and the run ended with its question unasked. Held here, that turn's end parks on the question first,
1230
+ // and the row, untaken, runs as a turn of its own after the answer.
1231
+ if (!session.steer || (followUp && session.state === "open_turn") || (cliRecord && (followUp || askedLast))) {
1224
1232
  if (turnsOver)
1225
1233
  return { later: "the run has answered and is ending: the message waits for the run's end" };
1226
1234
  afterTurn.push({ commandId: command.id, text, requestId, ...(origin ? { origin } : {}) });
@@ -1410,6 +1418,8 @@ function adapterLoop(specOf, options, deps) {
1410
1418
  * between a request's admission and its leaving: that wait let a cancel close the session before the request was
1411
1419
  * booked, its cost left unknown. */
1412
1420
  let freeMade = 0;
1421
+ /** Its requests on local models (free.ts localRequestsIn), kept the same way: the agent's own limit adds them. */
1422
+ let localMade = 0;
1413
1423
  const theCap = () => {
1414
1424
  if (!specNow?.runCap)
1415
1425
  throw new Error("the run's spec gives no cap (AdapterRunSpec.runCap)");
@@ -1421,6 +1431,8 @@ function adapterLoop(specOf, options, deps) {
1421
1431
  config.judged?.(request, answer);
1422
1432
  if (request.freeRequestsMade !== undefined)
1423
1433
  freeMade = request.freeRequestsMade + (answer && !("refuse" in answer) && answer.freeRequest === true ? 1 : 0);
1434
+ if (request.localRequestsMade !== undefined)
1435
+ localMade = request.localRequestsMade + (answer && !("refuse" in answer) && answer.localRequest === true ? 1 : 0);
1424
1436
  };
1425
1437
  // A step waiting for room leaves once the run has a pause (pendingPause, below): nothing more is sent until a
1426
1438
  // raise, and it is refused in the pause's words (beforeRequest). It leaves at the run's stop too, unsent.
@@ -1498,7 +1510,7 @@ function adapterLoop(specOf, options, deps) {
1498
1510
  return;
1499
1511
  passGate.expect(writesEntry(kind, test), { run: { summary } }).catch(() => undefined);
1500
1512
  };
1501
- const runOf = { harness, registry, setModels: (given) => (models = given), ledger, ...(deps.redact ? { redact: heldRedactor(deps.redact) } : {}), signal: deps.signal, stopped: AbortSignal.any([deps.signal, stopAbort.signal]), phase, rowSummaryOn };
1513
+ const runOf = { harness, registry, setModels: (given) => (models = given), ledger, redact: deps.redact, signal: deps.signal, stopped: AbortSignal.any([deps.signal, stopAbort.signal]), phase, rowSummaryOn };
1502
1514
  // The spec, its MCP claim step among it (mcpForClaim, before the session opens). A refusal there ends the run in its
1503
1515
  // words with nothing sent; a claim lost during its refresh ends the loop with nothing more written. A claim the spec
1504
1516
  // refuses (ClaimRefused: a handed sign-in that won't read back) ends the run in its words too.
@@ -1789,9 +1801,14 @@ function adapterLoop(specOf, options, deps) {
1789
1801
  }
1790
1802
  // The free requests the run made before this claim, in every session (freeMade: each admission's from here on).
1791
1803
  let madeBefore = 0;
1792
- for (const key of await sessions.keys())
1793
- madeBefore += freeRequestsIn(await sessions.read(key));
1804
+ let localBefore = 0;
1805
+ for (const key of await sessions.keys()) {
1806
+ const records = await sessions.read(key);
1807
+ madeBefore += freeRequestsIn(records);
1808
+ localBefore += localRequestsIn(records);
1809
+ }
1794
1810
  freeMade = madeBefore;
1811
+ localMade = localBefore;
1795
1812
  const capNote = {
1796
1813
  costs: claimRecords.flatMap((record) => {
1797
1814
  if (record.kind !== RUNNER_RECORDS.turn)
@@ -1904,12 +1921,14 @@ function adapterLoop(specOf, options, deps) {
1904
1921
  // The free-model limit's wrap-up (free.ts): the same note and offer, one per run and limit, on a request of a free
1905
1922
  // model. The dollar cap's note, when it is due on this request, goes first: one note per request, and it is told
1906
1923
  // once, so the free one waits for the next request (or never comes, the run having answered).
1924
+ // It counts down to the nearer limit (freeLimitNearest): the agent's own over its free and local requests together,
1925
+ // the run's free limit over its free ones alone (none on a local model, CapModel.local).
1907
1926
  const freeNote = () => {
1908
- const limit = config.freeRequests;
1909
- if (limit === undefined || toldFreeLimits.has(limit) || !freeModel(capModel))
1927
+ const near = freeLimitNearest(capModel, { ...(config.maxRequests !== undefined ? { own: config.maxRequests } : {}), ...(config.freeRequests !== undefined ? { server: config.freeRequests } : {}) }, { free: freeMade, local: localMade });
1928
+ if (near === undefined || toldFreeLimits.has(near.limit))
1910
1929
  return undefined;
1911
- const due = freeWrapUpDue(limit, freeMade);
1912
- return due ? { words: freeWrapUpWords(due.left), freeLimit: limit } : undefined;
1930
+ const due = freeWrapUpDue(near.limit, near.made);
1931
+ return due ? { words: freeWrapUpWords(due.left), freeLimit: near.limit } : undefined;
1913
1932
  };
1914
1933
  if (capUsd === undefined || toldAt(capUsd) || sessionSpent == null || decided === null || paidSpent === null || rest === null || inFlight == null)
1915
1934
  return freeNote();
@@ -136,6 +136,9 @@ export interface AdapterSpecDeps {
136
136
  /** A test runner's fake GitHub MCP origin, the one a github_app server may be at (mcp-claim.ts githubMcpOrigin):
137
137
  * for tests only: no environment variable, flag or setting maps onto it; absent, GitHub's hosted MCP (github.ts GITHUB_MCP_ORIGIN). Only a test's in-process runner sets it; the CLI's runner never does. */
138
138
  readonly githubMcpOrigin?: string;
139
+ /** A test runner's fake Composio MCP origin, the one a key read from the environment is sent to (mcp-claim.ts
140
+ * composioMcpOrigin): for tests only, as githubMcpOrigin; absent, Composio's (composio-made.ts COMPOSIO_ORIGIN). */
141
+ readonly composioMcpOrigin?: string;
139
142
  /** Whether this runner's runs may reach an MCP server whose URL is on loopback: only a runner beside a local-install
140
143
  * server (runner/beside.ts, Serve.localInstall) is told so, by that server in its own process. Absent, never: a hosted
141
144
  * or standalone runner's loopback is its host's other services. */
@@ -14,7 +14,7 @@ import { dirname, join } from "node:path";
14
14
  import { stopRunWith } from "../paid-calls.js";
15
15
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
16
16
  import { defineExtension, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
17
- import { checkRaise, followUpOf, freeRequestLimitOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
17
+ import { checkRaise, followUpOf, freeRequestLimitOf, maxRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
18
18
  import { inspectWorkflow } from "@parcha/agentrun-dsl";
19
19
  import { factsOf } from "../harness-table.js";
20
20
  import { decisionProvidersIn } from "../decisions.js";
@@ -116,7 +116,7 @@ export function capModelOf(route) {
116
116
  }
117
117
  : null;
118
118
  // The cap reads a request's provider overhead by the route's own wire (providerInputOverhead).
119
- return { id: route.model, api: route.provider.api, price, outputCeiling: route.outputCeiling ?? null };
119
+ return { id: route.model, api: route.provider.api, price, outputCeiling: route.outputCeiling ?? null, ...(route.local ? { local: true } : {}) };
120
120
  }
121
121
  /** Particle requests are never automatically replayed after an uncertain failure. Retry is a harness-wide setting,
122
122
  * so a claim with any Particle route disables it for all its conversations, including subagents on other tiers. */
@@ -320,7 +320,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
320
320
  // turn, with the GitHub App's read-only token for that one repository (or none); the run is told what it holds, or why
321
321
  // there is none. Held from the fetch's start, so the release (after the tools' end) removes it however the claim ends; a
322
322
  // person's stop ends the fetch at once (run.stopped).
323
- const checkout = body.checkout === "pull_request" ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part })) : undefined;
323
+ const checkout = body.checkout ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part }), body.checkout) : undefined;
324
324
  holds.hold({ checkout });
325
325
  // The run's skills and its learning seed, laid in its folder through the run's Workspace now, before its computer
326
326
  // exists: on Archil the computer's mount of the folder takes the disk's write delegation, and from then on every write
@@ -351,7 +351,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
351
351
  // words before the session opens. The seal key is the runner's own (deps.sealKey), not re-read from the environment.
352
352
  // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactor.
353
353
  const hold = (values) => cut.hold(values);
354
- const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, 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: deps.evalFakes?.(runRow.agentId)?.web, slots: deps.saveSlots } });
354
+ const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, 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 } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web: deps.evalFakes?.(runRow.agentId)?.web, slots: deps.saveSlots } });
355
355
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
356
356
  holds.hold({ passed: mcp });
357
357
  // The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
@@ -508,6 +508,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
508
508
  ...(besideOf ? { beside: besideOf } : {}),
509
509
  // The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS, or the agent's lower max_requests).
510
510
  freeRequests: freeRequestLimitOf(deps.env, body.maxRequests),
511
+ // The agent's own limit alone, which a local model's requests count toward too (run-cap.ts maxRequests).
512
+ ...(maxRequestsOf(body.maxRequests) === undefined ? {} : { maxRequests: maxRequestsOf(body.maxRequests) }),
511
513
  };
512
514
  // The run's cap figure and what a refusal does to it (parkOf, with the kernel's raise rule): present only when the run
513
515
  // has a cap. A park names the cap the loop holds the run to then (a raise's, else this one).
@@ -38,6 +38,7 @@ import { auditableLaunch, auditChange, auditEveryOf, auditDrawn, auditsOffWords,
38
38
  import { lastRunsOf, sinceReset } from "../learn/compile.js";
39
39
  import { readLearning, writeLearning } from "../learn/folder.js";
40
40
  import { CHECK_TEXT_MAX, compareAnswers, comparedOf, promotionOf, promotionsOf, promotionStartOf, recordPromotion, servingOf } from "../learn/promote.js";
41
+ import { refusedIn } from "../purged-workflow.js";
41
42
  import { excerptShown } from "../learn/secrets.js";
42
43
  import { auditRoomOf } from "./learning-end.js";
43
44
  import { answerOf, answerRowOf } from "./promotion.js";
@@ -345,13 +346,16 @@ async function addLines(deps, lines, agreed, again = false) {
345
346
  await folder.end().catch(() => undefined);
346
347
  }
347
348
  }
348
- /** The hold rule over the ledger's rows `all` for each workflow that serves now (its champion's digest), whether or not
349
- * a row was just added: idempotent (applyHold holds only a digest whose newest record still promotes it). */
349
+ /** The hold rule over the ledger's rows `all` for each workflow that serves now (its champion's digest, skipping a
350
+ * record the purge gate refuses as a claim's does: purged-workflow.ts refusedOf), whether or not a row was just added:
351
+ * idempotent (applyHold holds only a digest whose newest record still promotes it). */
350
352
  async function holdByLedger(deps, all) {
351
353
  if (!all.length)
352
354
  return;
353
355
  const loop = await auditLoopOfRevision(deps.store, deps.revisionId);
354
- for (const { workflow, digest } of servingOf(await promotionsOf(deps.store.settings, deps.agentId))) {
356
+ const records = await promotionsOf(deps.store.settings, deps.agentId);
357
+ const refused = await refusedIn(deps.folder, deps.store, deps.log)(records);
358
+ for (const { workflow, digest } of servingOf(records, refused)) {
355
359
  if (digest !== null)
356
360
  await applyHold(deps, all, loop, workflow, digest);
357
361
  }
@@ -392,7 +396,7 @@ async function applyHold(deps, rows, loop, workflow, digest) {
392
396
  audit: { window: loop.hold_window, disagree: loop.hold_disagree, rows: hold.rows.length, disagreements, ...(stopped ? { stopped: true } : {}) },
393
397
  ...(current.commit ? { commit: current.commit } : {}),
394
398
  };
395
- const kept = await recordPromotion(store.settings, agentId, record, (was) => was?.decided === "promote" && was.at === current.at);
399
+ const kept = await recordPromotion(store.settings, agentId, record, (was) => was?.decided === "promote" && was.at === current.at, refusedIn(deps.folder, store, log));
396
400
  if (kept.won)
397
401
  log(`workflow-first: ${workflow} at ${digest} ${stopped ? `stopped (${said}, a second hold within ${loop.stop_window} served runs)` : reason}`);
398
402
  }
@@ -33,11 +33,12 @@ export declare function besideStopping(server: {
33
33
  * a remote provider's create takes, so a machine that dials the server lands in this process's hub. Returns the runner
34
34
  * and a close() that stops both and closes its store. `loopsTold`: `loops` was given (besideRunnerOptions), so on uid
35
35
  * isolation a number past the helper's slots is refused rather than cut. */
36
- export declare function runnerBeside(dataDir: string, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, dial, mcpLoopback, mcpOwn, evalFakes, harnessInstall, onLine, onRunEnded }?: {
36
+ export declare function runnerBeside(dataDir: string, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, dial, mcpLoopback, mcpOwn, ollamaHost, evalFakes, harnessInstall, onLine, onRunEnded }?: {
37
37
  loops?: number;
38
38
  loopsTold?: boolean;
39
39
  drainMs?: number;
40
40
  env?: NodeJS.ProcessEnv;
41
+ ollamaHost?: string;
41
42
  janitor?: boolean;
42
43
  ownProcesses?: boolean;
43
44
  hub?: import("@parcha/agentrun-computer").AttachHub;
@@ -33,7 +33,7 @@ export function besideStopping(server, held, drainMs) {
33
33
  * a remote provider's create takes, so a machine that dials the server lands in this process's hub. Returns the runner
34
34
  * and a close() that stops both and closes its store. `loopsTold`: `loops` was given (besideRunnerOptions), so on uid
35
35
  * isolation a number past the helper's slots is refused rather than cut. */
36
- export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, dial, mcpLoopback, mcpOwn, evalFakes, harnessInstall, onLine, onRunEnded } = {}) {
36
+ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, dial, mcpLoopback, mcpOwn, ollamaHost, evalFakes, harnessInstall, onLine, onRunEnded } = {}) {
37
37
  const { runnerName, startRunner } = await import("./runner.js");
38
38
  const { dispatchRunner } = await import("./harness-loops.js");
39
39
  const { routeOf } = await import("./model-route.js");
@@ -58,7 +58,11 @@ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, ja
58
58
  // a --faux server reaches the faux gateway and its computers. The run's claim-time computer is composed once, the one way
59
59
  // (main.ts runnerComputers, a desktop's or a phone's live view with it), from that same environment; a Docker computer's
60
60
  // mounts by where this process's Docker has the data directory (box-paths.ts), read once.
61
+ // `ollamaHost`: the Ollama the server beside it asks (Serve.ollamaHost), the default address on one owner's own machine
62
+ // that names none, so its runs ask the same one; a runner in its own process asks the one its environment names alone.
61
63
  const runs = env ?? runEnv(process.env);
64
+ if (ollamaHost && !runs.OLLAMA_HOST?.trim())
65
+ runs.OLLAMA_HOST = ollamaHost;
62
66
  const { dockerPathsForRuns } = await import("../box-paths.js");
63
67
  const { hostAddressesOnce } = await import("../docker-host-addresses.js");
64
68
  const { PROVIDERS } = await import("@parcha/agentrun-computer");
@@ -163,7 +167,7 @@ export async function serveWithRunner(options) {
163
167
  const serve = await startServe(options);
164
168
  // Each run a process of its own, as a user of its own where the image's helper can switch, as the CLI's start runs
165
169
  // them (cli.ts): the isolation the server's capabilities say (runIsolationOf over the same helper) is the runner's.
166
- const beside = await runnerBeside(options.data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)), ownProcesses: true, hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ...(options.log ? { onLine: options.log } : {}) }).catch(async (error) => {
170
+ const beside = await runnerBeside(options.data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)), ownProcesses: true, hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ollamaHost: serve.ollamaHost, ...(options.log ? { onLine: options.log } : {}) }).catch(async (error) => {
167
171
  await serve.close();
168
172
  throw error;
169
173
  });
@@ -20,10 +20,6 @@ export interface ClaimSecretsDeps {
20
20
  /** The runner's seal key: with none, no saved key is opened, and only the environment's values are read. */
21
21
  readonly sealKey: Buffer | undefined;
22
22
  readonly env?: NodeJS.ProcessEnv;
23
- /** The runner's one redactor (redact.ts), for a claim given its run's id: the run's own tool keys it lays are carried
24
- * there first, cut from the run's journal as it is written, since no one holds them after the turn. A claim with run
25
- * keys to lay and no redactor lays none, and throws. */
26
- readonly redact?: HeldRedact;
27
23
  }
28
24
  /** What reads a run's launch sealed column. */
29
25
  type RunLaunchReader = {
@@ -34,11 +30,12 @@ type RunLaunchReader = {
34
30
  /** The environment a claimed run's tools run under: the runner's base (its secrets stripped), with the keys the run's
35
31
  * revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
36
32
  * decision provider keys — and, for claim `runId`, the run's own tool keys its revision declares (run-keys.ts) over the
37
- * server's by the same name. A fresh object per claim, so no run's keys reach another's. */
33
+ * server's by the same name. A fresh object per claim, so no run's keys reach another's. `redact`: the runner's one
34
+ * redactor, which the run's own tool keys are carried into before they are laid, so its journal is cut of them as it is
35
+ * written (no one holds them after the turn); a plain JS caller that passes none lays no run key, and throws. */
38
36
  export declare function claimSecrets(deps: ClaimSecretsDeps & {
39
- readonly redact: HeldRedact | undefined;
40
- }, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">, runId: string): Promise<NodeJS.ProcessEnv>;
41
- export declare function claimSecrets(deps: ClaimSecretsDeps, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">): Promise<NodeJS.ProcessEnv>;
37
+ readonly redact: HeldRedact;
38
+ }, revision: Revision, launch: Pick<RunLaunch, "plane" | "model">, runId?: string): Promise<NodeJS.ProcessEnv>;
42
39
  /** `keys` (learnedDecisionKeys') laid onto `env`, a claim's environment, where it holds no value of that name: what the
43
40
  * claim laid stays, a run's own tool key over the server's above all. A name both read holds the same server key. */
44
41
  export declare function underClaimed(env: NodeJS.ProcessEnv, keys: Readonly<Record<string, string>>): void;
@@ -23,6 +23,12 @@ import { withRequestMetadata } from "../request-metadata.js";
23
23
  /** Every server secret a run might be handed (runs.ts RUN_SECRETS is the tool and model keys; the decision keys go beside
24
24
  * them). Read from the store into a working environment, then scoped to the run below. */
25
25
  const CANDIDATES = [...new Set([...RUN_SECRETS, ...DECISION_KEYS])];
26
+ /** The environment a claimed run's tools run under: the runner's base (its secrets stripped), with the keys the run's
27
+ * revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
28
+ * decision provider keys — and, for claim `runId`, the run's own tool keys its revision declares (run-keys.ts) over the
29
+ * server's by the same name. A fresh object per claim, so no run's keys reach another's. `redact`: the runner's one
30
+ * redactor, which the run's own tool keys are carried into before they are laid, so its journal is cut of them as it is
31
+ * written (no one holds them after the turn); a plain JS caller that passes none lays no run key, and throws. */
26
32
  export async function claimSecrets(deps, revision, launch, runId) {
27
33
  const base = withoutSecrets(deps.env ?? {});
28
34
  const working = await workingEnv(deps);
@@ -5,7 +5,7 @@ import { type RunLaunch } from "../run-launch.js";
5
5
  import { type AdapterRun, type AdapterRunSpec } from "./adapter-loop.js";
6
6
  import { type AdapterSpecDeps } from "./adapter-run-spec.js";
7
7
  import { type ClaimModelKey } from "./claim-secrets.js";
8
- import type { Claim } from "./loop-contract.js";
8
+ import { type Claim } from "./loop-contract.js";
9
9
  /** The shared claim-time computer types live on the base spec (adapter-run-spec.ts), re-exported for this module's API. */
10
10
  export type { ClaimComputer, ClaimDeps, ClaimLaunch, ComputerForClaim } from "./adapter-run-spec.js";
11
11
  /** What the runner hands the CLI spec builder: the same deps the pi spec takes (computerForClaim, computerDeps and
@@ -18,7 +18,7 @@ import { stopRunWith } from "../paid-calls.js";
18
18
  import { dirname, join } from "node:path";
19
19
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
20
20
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
21
- import { checkRaise, followUpOf, freeRequestLimitOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
21
+ import { checkRaise, followUpOf, freeRequestLimitOf, maxRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
22
22
  import { PLAN_LIMIT_WORDS } from "@parcha/agentrun-kernel";
23
23
  import { modelWire } from "../wires.js";
24
24
  import { confineOf, noNewPrivsPrefix, standsIn, thinkingFor } from "../adapters.js";
@@ -28,14 +28,15 @@ import { effortGuidance } from "../effort-guidance.js";
28
28
  import { outputContract } from "../answer-json.js";
29
29
  import { wireName } from "../catalog.js";
30
30
  import { environmentLine, runZone } from "../environment.js";
31
- import { factsOf, harnessOf } from "../harness-table.js";
31
+ import { factsOf, harnessOf, recipeKeysOf } from "../harness-table.js";
32
+ import { layHarnessKeys, openHarnessKeys, RECIPE_SIGN_IN_PERSON_ONLY, RECIPE_TURN_PERSON_ONLY } from "../harness-keys.js";
32
33
  import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
33
34
  import { laidOf, layLearningSeed } from "./learning-seed.js";
34
35
  import { learningWorkspace } from "../learn/folder.js";
35
36
  import { learningEndOfRun, spentBesideOf } from "./learning-end.js";
36
- import { providerModels, runModels } from "../model.js";
37
+ import { ollamaTagsOf, providerModels, runModels } from "../model.js";
37
38
  import { firstMessage, inputMessage, messageText } from "../run-manifest.js";
38
- import { learningStartOf, seedFailed } from "../run-launch.js";
39
+ import { learningStartOf, personStarted, seedFailed } from "../run-launch.js";
39
40
  import { readsFiles, systemOf } from "../skills.js";
40
41
  import { DATA_ENV } from "../server-fs.js";
41
42
  import { filesToCopy, placeRunInputs } from "../uploads.js";
@@ -63,6 +64,7 @@ import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
63
64
  import { decisionProvidersIn } from "../decisions.js";
64
65
  import { resolveHarness } from "./adapters/index.js";
65
66
  import { entriesOf } from "./loop.js";
67
+ import { ClaimRefused } from "./loop-contract.js";
66
68
  import { bookedSpend, cliModelWorked, cliRunMetrics, costBasisOf, endCostOf, runCostOf } from "./metrics.js";
67
69
  import { journalEntries } from "./journal-reader.js";
68
70
  import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
@@ -98,7 +100,7 @@ async function modelsOf(entry, env, ref) {
98
100
  throw new Error(`${entry.id} does not run here.`);
99
101
  if ("why" in choice)
100
102
  throw new Error(choice.why);
101
- return { model: choice.model, models: await providerModels(env), unpriced: new Set() };
103
+ return { model: choice.model, models: await providerModels(env, { ollama: ollamaTagsOf([choice.model]) }), unpriced: new Set() };
102
104
  }
103
105
  const chosen = await runModels(env, ref, ["default"], entry.id);
104
106
  if (!chosen.model)
@@ -335,7 +337,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
335
337
  // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
336
338
  const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
337
339
  redact.hold(values); };
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 } });
340
+ 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 } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web, slots: deps.saveSlots } });
339
341
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
340
342
  holds.hold({ passed: mcp });
341
343
  // The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
@@ -362,7 +364,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
362
364
  : await openRunWorkspace({ mode: 2, agentId: runRow.agentId, runId: claim.runId, archil, log });
363
365
  holds.hold({ ws });
364
366
  // The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts).
365
- const checkout = body.checkout === "pull_request" ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part })) : undefined;
367
+ const checkout = body.checkout ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part }), body.checkout) : undefined;
366
368
  holds.hold({ checkout });
367
369
  // A run's own process copies nothing: its runner placed them before the process started (run-child-host.ts).
368
370
  if (!(deps.sealKey === undefined && runnerSeam()))
@@ -460,6 +462,32 @@ async function cliSpec(launch, run, deps, claim, holds) {
460
462
  // runs on that key, and a run in a sandbox place on the model keys.
461
463
  const login = keyed ? undefined : await loginForRun(deps.store.settings, deps.data, deps.env ?? {}, name, launch.place);
462
464
  const env = withClaudeLogin(cliRunEnv(deps.env, deps.data, claimed, launch.plane, runKey, claim), login);
465
+ // A plan-billed recipe's keys saved for its harness alone (harness-keys.ts), opened at each claim for this run's harness
466
+ // and no other (a run's own process asks its runner, which opens its claim's own: held.ts harnessKeys), held by the
467
+ // redactors, and laid on the adapter's environment alone, never enumerable (layHarnessKeys): the tools' plane copies
468
+ // `claimed`, never `env`, and no spread or child environment built from `env` carries them. The ACP adapter reads each
469
+ // by name for the agent's start, and only keys laid here take a run onto the keys route (harness-recipe-entry.ts).
470
+ // The run environment copies the runner's own (cliRunEnv), so a key's name the operator's shell exported is dropped
471
+ // first: the agent reads a saved key or none. All or nothing: a claim that opened not every key lays none, and a run
472
+ // no person started (a schedule's, a trigger's, a trigger's turn into a run, a learned workflow's audit shadow or
473
+ // replay: personStarted) is refused then, before any route
474
+ // is chosen, so it never falls to its owner's sign-in (a row counted at its claim may be gone, or not open, by now).
475
+ // A person's claim that laid none keeps its session on the sign-in (or on nothing) for good: a trigger's message the
476
+ // claim takes later is refused in it (personOnly), keys saved since or not, as no new claim opens them.
477
+ const recipeKeys = name === undefined ? undefined : recipeKeysOf(deps.env ?? {}, name);
478
+ let personOnly;
479
+ if (name !== undefined && recipeKeys?.length) {
480
+ for (const key of recipeKeys)
481
+ delete env[key];
482
+ const opened = deps.sealKey ? await openHarnessKeys(deps.store, deps.sealKey, name, recipeKeys) : ((await runnerSeam()?.harnessKeys()) ?? {});
483
+ hold(Object.values(opened));
484
+ if (recipeKeys.every((key) => typeof opened[key] === "string" && opened[key] !== ""))
485
+ layHarnessKeys(env, opened);
486
+ else if (!personStarted(launch))
487
+ throw new ClaimRefused(RECIPE_SIGN_IN_PERSON_ONLY);
488
+ else
489
+ personOnly = RECIPE_TURN_PERSON_ONLY;
490
+ }
463
491
  const chosen = await modelsOf(entry, env, modelAskOf(launch.model, body.model));
464
492
  await planBeforeRun(env, chosen.model);
465
493
  if (login && entry.priceModel(env, chosen.model).provider === CLAUDE_LOGIN_PROVIDER) {
@@ -542,6 +570,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
542
570
  ...(besideOf ? { beside: besideOf } : {}),
543
571
  // The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS, or the agent's lower max_requests).
544
572
  freeRequests: freeRequestLimitOf(deps.env, body.maxRequests),
573
+ // The agent's own limit alone, which a local model's requests count toward too (run-cap.ts maxRequests).
574
+ ...(maxRequestsOf(body.maxRequests) === undefined ? {} : { maxRequests: maxRequestsOf(body.maxRequests) }),
545
575
  };
546
576
  const cap = capUsd === undefined
547
577
  ? undefined
@@ -735,6 +765,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
735
765
  agentId: runRow.agentId,
736
766
  // An audit's shadow run waits on no one, as the pi spec's (runner/audit.ts AUDIT_PARKED).
737
767
  ...(launch.audit ? { neverWaits: AUDIT_PARKED } : {}),
768
+ // A plan-billed recipe's session its claim laid no key on: a trigger's message is refused in it (adapter-loop.ts).
769
+ ...(personOnly ? { personOnly } : {}),
738
770
  // The run's computer and the person's hold on a desktop or phone, as the claim made them (as the pi spec gives them).
739
771
  ...(loopComputer ? { computer: loopComputer } : {}),
740
772
  // A desktop or a phone as a codemode script gets it: the script's `computer`, over the run's computer tools.