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

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 (234) hide show
  1. package/CHANGELOG.md +142 -2
  2. package/README.md +310 -98
  3. package/dist/adapters.d.ts +11 -0
  4. package/dist/adapters.js +49 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +6 -13
  7. package/dist/agents-store.js +6 -5
  8. package/dist/answer-json.d.ts +6 -2
  9. package/dist/answer-json.js +22 -4
  10. package/dist/api-only.d.ts +16 -4
  11. package/dist/api-only.js +23 -7
  12. package/dist/calendar/tools.js +3 -2
  13. package/dist/chatgpt-plan.d.ts +16 -1
  14. package/dist/chatgpt-plan.js +116 -12
  15. package/dist/claude-login.d.ts +34 -5
  16. package/dist/claude-login.js +31 -7
  17. package/dist/claude-sign-in.d.ts +35 -0
  18. package/dist/claude-sign-in.js +90 -0
  19. package/dist/cli.js +5 -3
  20. package/dist/composio-made.d.ts +26 -1
  21. package/dist/composio-made.js +39 -2
  22. package/dist/composio-preset.d.ts +3 -2
  23. package/dist/composio-preset.js +46 -14
  24. package/dist/computer-held-routes.js +2 -3
  25. package/dist/computer-setting.d.ts +4 -2
  26. package/dist/computer-setting.js +0 -2
  27. package/dist/computers-running.d.ts +8 -0
  28. package/dist/computers-running.js +27 -0
  29. package/dist/console/assets/backend-Boh7tC4i.js +166 -0
  30. package/dist/console/assets/index-CQ3cJRzI.js +746 -0
  31. package/dist/console/assets/index-DKkaS3a0.css +1 -0
  32. package/dist/console/index.html +2 -2
  33. package/dist/docker-host-addresses.d.ts +23 -3
  34. package/dist/docker-host-addresses.js +90 -18
  35. package/dist/exa-keyless.d.ts +2 -3
  36. package/dist/exa-keyless.js +43 -127
  37. package/dist/firecrawl-keyless.d.ts +41 -0
  38. package/dist/firecrawl-keyless.js +152 -0
  39. package/dist/handed-secret.d.ts +3 -1
  40. package/dist/handed-secret.js +4 -2
  41. package/dist/harness-keys.d.ts +98 -0
  42. package/dist/harness-keys.js +247 -0
  43. package/dist/harness-recipe-entry.d.ts +14 -9
  44. package/dist/harness-recipe-entry.js +25 -14
  45. package/dist/harness-table.d.ts +16 -1
  46. package/dist/harness-table.js +19 -7
  47. package/dist/harness.d.ts +4 -0
  48. package/dist/harness.js +12 -1
  49. package/dist/host-check.d.ts +6 -0
  50. package/dist/host-check.js +10 -0
  51. package/dist/import-summary.d.ts +1 -1
  52. package/dist/import-summary.js +1 -1
  53. package/dist/import.d.ts +5 -5
  54. package/dist/import.js +54 -67
  55. package/dist/key-refusal.d.ts +21 -5
  56. package/dist/key-refusal.js +231 -37
  57. package/dist/keyless-mcp.d.ts +36 -0
  58. package/dist/keyless-mcp.js +127 -0
  59. package/dist/learn/audit.d.ts +3 -3
  60. package/dist/learn/audit.js +3 -3
  61. package/dist/learn/commit.d.ts +8 -7
  62. package/dist/learn/commit.js +60 -20
  63. package/dist/learn/compile.d.ts +4 -3
  64. package/dist/learn/compile.js +7 -5
  65. package/dist/learn/folder.d.ts +16 -3
  66. package/dist/learn/folder.js +46 -13
  67. package/dist/learn/promote.d.ts +37 -13
  68. package/dist/learn/promote.js +112 -40
  69. package/dist/learn/secrets.d.ts +20 -10
  70. package/dist/learn/secrets.js +44 -176
  71. package/dist/learning-routes.d.ts +22 -17
  72. package/dist/learning-routes.js +40 -39
  73. package/dist/learning.js +2 -2
  74. package/dist/llms.txt +1 -1
  75. package/dist/manifest.d.ts +10 -0
  76. package/dist/manifest.js +30 -0
  77. package/dist/mcp-pin-first.d.ts +4 -2
  78. package/dist/mcp-pin-first.js +5 -2
  79. package/dist/mcp-secret-writes.d.ts +16 -7
  80. package/dist/mcp-secret-writes.js +35 -27
  81. package/dist/mcp-servers-store.d.ts +30 -6
  82. package/dist/mcp-servers-store.js +112 -28
  83. package/dist/mcp-sources.d.ts +10 -2
  84. package/dist/mcp-sources.js +9 -2
  85. package/dist/mcp-store.d.ts +13 -7
  86. package/dist/mcp-store.js +12 -9
  87. package/dist/model-form.d.ts +3 -2
  88. package/dist/model-form.js +11 -7
  89. package/dist/model.d.ts +20 -4
  90. package/dist/model.js +68 -9
  91. package/dist/native/history.d.ts +1 -1
  92. package/dist/native/history.js +2 -2
  93. package/dist/ollama-provider.d.ts +92 -0
  94. package/dist/ollama-provider.js +495 -0
  95. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  96. package/dist/openapi.d.ts +3 -3
  97. package/dist/openapi.js +197 -55
  98. package/dist/page.d.ts +11 -3
  99. package/dist/page.js +22 -7
  100. package/dist/place-offers.d.ts +25 -1
  101. package/dist/place-offers.js +62 -8
  102. package/dist/print.js +1 -1
  103. package/dist/purged-workflow.d.ts +35 -7
  104. package/dist/purged-workflow.js +73 -26
  105. package/dist/redact/match.d.ts +74 -0
  106. package/dist/redact/match.js +771 -0
  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/run-timeline-served.d.ts +1 -1
  119. package/dist/run-timeline-served.js +4 -4
  120. package/dist/runner/adapter-loop.d.ts +9 -3
  121. package/dist/runner/adapter-loop.js +34 -15
  122. package/dist/runner/adapter-run-spec.d.ts +3 -0
  123. package/dist/runner/adapter-run-spec.js +9 -4
  124. package/dist/runner/audit.js +8 -4
  125. package/dist/runner/beside.d.ts +2 -1
  126. package/dist/runner/beside.js +13 -5
  127. package/dist/runner/claim-secrets.d.ts +5 -8
  128. package/dist/runner/claim-secrets.js +6 -0
  129. package/dist/runner/cli-run-spec.d.ts +1 -1
  130. package/dist/runner/cli-run-spec.js +41 -7
  131. package/dist/runner/harness-loops.d.ts +22 -9
  132. package/dist/runner/harness-loops.js +21 -11
  133. package/dist/runner/held.d.ts +3 -0
  134. package/dist/runner/learning-end.d.ts +1 -1
  135. package/dist/runner/learning-end.js +8 -3
  136. package/dist/runner/loop-contract.d.ts +9 -4
  137. package/dist/runner/main.js +12 -6
  138. package/dist/runner/mcp-claim.d.ts +3 -0
  139. package/dist/runner/mcp-claim.js +26 -2
  140. package/dist/runner/mcp-run.d.ts +3 -0
  141. package/dist/runner/mcp-run.js +2 -1
  142. package/dist/runner/metrics.d.ts +10 -10
  143. package/dist/runner/metrics.js +19 -38
  144. package/dist/runner/model-route.d.ts +3 -0
  145. package/dist/runner/model-route.js +6 -2
  146. package/dist/runner/presence.d.ts +4 -3
  147. package/dist/runner/presence.js +4 -2
  148. package/dist/runner/promotion.d.ts +15 -9
  149. package/dist/runner/promotion.js +25 -15
  150. package/dist/runner/run-child-host.d.ts +2 -0
  151. package/dist/runner/run-child-host.js +19 -9
  152. package/dist/runner/run-child.js +3 -1
  153. package/dist/runner/runner.d.ts +4 -0
  154. package/dist/runner/runner.js +33 -3
  155. package/dist/runner/sdk-loop.js +2 -0
  156. package/dist/runner/workflow-loop.d.ts +2 -2
  157. package/dist/runner/workflow-loop.js +1 -2
  158. package/dist/runner/workflow-spec.d.ts +1 -1
  159. package/dist/runner/workflow-spec.js +6 -6
  160. package/dist/sdk/check.d.ts +4 -1
  161. package/dist/sdk/check.js +2 -1
  162. package/dist/sdk/runs.d.ts +2 -2
  163. package/dist/sdk/runs.js +8 -6
  164. package/dist/secret-cut.js +2 -1
  165. package/dist/secret-writes.d.ts +3 -2
  166. package/dist/secret-writes.js +1 -1
  167. package/dist/server.d.ts +49 -10
  168. package/dist/server.js +324 -118
  169. package/dist/standard-webhooks.d.ts +11 -0
  170. package/dist/standard-webhooks.js +20 -2
  171. package/dist/store/dialect.d.ts +3 -0
  172. package/dist/store/dialect.js +1 -0
  173. package/dist/store/index.d.ts +2 -2
  174. package/dist/store/index.js +1 -1
  175. package/dist/store/postgres/dialect.js +3 -0
  176. package/dist/store/schema.js +5 -2
  177. package/dist/store/sqlite/store.js +133 -47
  178. package/dist/store/store.d.ts +64 -15
  179. package/dist/store/store.js +7 -0
  180. package/dist/store-reads/journal.d.ts +7 -2
  181. package/dist/store-reads/journal.js +9 -6
  182. package/dist/store-reads/learning.d.ts +12 -9
  183. package/dist/store-reads/learning.js +18 -24
  184. package/dist/store-view.d.ts +0 -5
  185. package/dist/store-view.js +10 -9
  186. package/dist/template-eval.d.ts +51 -6
  187. package/dist/template-eval.js +177 -53
  188. package/dist/template-import.js +4 -2
  189. package/dist/templates.d.ts +5 -3
  190. package/dist/templates.js +19 -40
  191. package/dist/timeline/index.d.ts +1 -1
  192. package/dist/timeline/index.js +1 -1
  193. package/dist/timeline/labels.d.ts +2 -2
  194. package/dist/timeline/labels.js +2 -2
  195. package/dist/timeline/timeline.d.ts +14 -9
  196. package/dist/timeline/timeline.js +15 -7
  197. package/dist/tool-gate.js +3 -1
  198. package/dist/tool-plane.d.ts +17 -9
  199. package/dist/tool-plane.js +38 -17
  200. package/dist/tools.js +2 -2
  201. package/dist/trigger-launch-hook.d.ts +16 -8
  202. package/dist/trigger-launch-hook.js +32 -23
  203. package/dist/trigger-targets.d.ts +18 -8
  204. package/dist/trigger-targets.js +42 -19
  205. package/dist/triggers.d.ts +85 -23
  206. package/dist/triggers.js +303 -96
  207. package/dist/validate.js +1 -1
  208. package/dist/web-fake.js +3 -3
  209. package/dist/web-fetch-direct.d.ts +4 -0
  210. package/dist/web-fetch-direct.js +8 -1
  211. package/dist/web-fetch.d.ts +12 -3
  212. package/dist/web-fetch.js +47 -14
  213. package/dist/web-search.d.ts +33 -4
  214. package/dist/web-search.js +100 -41
  215. package/dist/webhooks.js +4 -5
  216. package/dist/workspace/computer-deps.d.ts +2 -1
  217. package/dist/workspace/computer-deps.js +5 -4
  218. package/dist/workspace/computer-for-claim.d.ts +8 -2
  219. package/dist/workspace/computer-for-claim.js +28 -9
  220. package/dist/workspace/computer-janitor.d.ts +15 -7
  221. package/dist/workspace/computer-janitor.js +33 -8
  222. package/dist/workspace/computer-kept.d.ts +52 -4
  223. package/dist/workspace/computer-kept.js +118 -6
  224. package/dist/workspace/run-end-computers.d.ts +5 -1
  225. package/dist/workspace/run-end-computers.js +27 -1
  226. package/dist/wrapped.d.ts +57 -0
  227. package/dist/wrapped.js +51 -0
  228. package/launcher/agentrun-serve +5 -1
  229. package/package.json +17 -13
  230. package/templates/README.md +10 -9
  231. package/dist/console/assets/index-B_85An2t.js +0 -745
  232. package/dist/console/assets/index-n1YsbnYh.css +0 -1
  233. package/dist/import-sources.d.ts +0 -116
  234. package/dist/import-sources.js +0 -693
@@ -1,6 +1,8 @@
1
1
  import type { ComputerKind, ComputerSetting } from "./computer-setting.js";
2
2
  /** What a computer is doing, as a run reads it. */
3
3
  export type ComputerState = "starting" | "ready" | "taken_over" | "ended" | "failed";
4
+ /** The states of a computer its run still has. */
5
+ export declare const COMPUTER_UP: ReadonlySet<ComputerState>;
4
6
  /** The port the run read's computer field reads: run `runId`'s computer state with the owner's hold, "taken_over" while
5
7
  * the owner holds it, else `state` as given. */
6
8
  export type ComputerStateOf = (runId: string, state: ComputerState) => ComputerState;
@@ -1,4 +1,6 @@
1
1
  import { COMPUTER_UNAVAILABLE } from "./computers.js";
2
+ /** The states of a computer its run still has. */
3
+ export const COMPUTER_UP = new Set(["starting", "ready", "taken_over"]);
2
4
  const ENDED = new Set(["completed", "failed", "cancelled", "expired"]);
3
5
  /** The run's `computer` field: absent for a run with none; failed with why when its computer could not be had; ended
4
6
  * once the run is over; else starting (queued) or ready (going), taken_over while the owner holds it (`stateOf`). */
@@ -4,6 +4,10 @@ import { type Entry, type Workspace } from "./workspace/index.js";
4
4
  export declare const WALK_DEPTH = 16;
5
5
  /** The CSP a served HTML file runs under: an opaque origin, no scripts, no network. */
6
6
  export declare const FILE_CSP = "default-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox; form-action 'none'";
7
+ /** The largest file a cut read (`?cut=run`) answers, in bytes: 256 KiB. redactSecrets runs synchronously over the whole
8
+ * text, on the server's event loop. At this size each shape's adversarial input (its prefix repeated with no end, in
9
+ * secrets-linear.test.mjs) takes under 100 ms here, and prose with 100 held values at most 162 ms. A bigger file is 413. */
10
+ export declare const RUN_FILE_CUT_MAX: number;
7
11
  export type FileView = {
8
12
  path: string;
9
13
  size_bytes: number;
package/dist/run-files.js CHANGED
@@ -7,6 +7,10 @@ export const WALK_DEPTH = 16;
7
7
  const SEND_CHUNK = 4 * 1024 * 1024;
8
8
  /** The CSP a served HTML file runs under: an opaque origin, no scripts, no network. */
9
9
  export const FILE_CSP = "default-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox; form-action 'none'";
10
+ /** The largest file a cut read (`?cut=run`) answers, in bytes: 256 KiB. redactSecrets runs synchronously over the whole
11
+ * text, on the server's event loop. At this size each shape's adversarial input (its prefix repeated with no end, in
12
+ * secrets-linear.test.mjs) takes under 100 ms here, and prose with 100 held values at most 162 ms. A bigger file is 413. */
13
+ export const RUN_FILE_CUT_MAX = 256 * 1024;
10
14
  /** File `path` as the API lists it, from its Workspace listing entry. */
11
15
  export const viewOf = (path, entry) => ({
12
16
  path, size_bytes: entry.size, modified_at: new Date(entry.mtimeMs).toISOString(), content_type: typeOf(path) ?? null, ...(entry.unreadable ? { unreadable: true } : {}),
@@ -3,8 +3,6 @@ import type { Revision } from "./agent-rows.js";
3
3
  import { type RunNeeds } from "./run-secrets.js";
4
4
  /** A run's own tool keys, by name. */
5
5
  export type RunKeys = Readonly<Record<string, string>>;
6
- /** The tool keys a run of `tools` reads (run-secrets.ts unlockedFields, over tool-keys.ts TOOL_KEYS). */
7
- export declare const keysOfTools: (tools: readonly string[]) => string[];
8
6
  /** The tool keys a template's apply made `revision` with (its package's `secrets`, kept on the revision): the ones a run
9
7
  * can carry. A model key is not one. */
10
8
  export declare const packageKeysOf: (revision: object) => string[];
@@ -28,8 +26,8 @@ export declare function withCarried(env: NodeJS.ProcessEnv, names: readonly stri
28
26
  /** Under the run-keys setting, each tool key `revision`'s template declared that `env` (the server's) does not hold and
29
27
  * the run does not carry, as a 409 issue at keys.<NAME>: the apply made it on the promise each run brings it. */
30
28
  export declare function keysOwed(revision: object, env: NodeJS.ProcessEnv, carried: readonly string[]): InputIssue[];
31
- /** The 409 a run that owes `owed` (keysOwed) gets at its start, and a trigger that could only start or message such runs
32
- * gets when it is made or moved (firingsOwe). */
29
+ /** The 409 a run that owes `owed` (keysOwed) gets at its start or a message, and a trigger that could only start or
30
+ * message such runs gets when it is made or moved, and at a message_run firing (firingsOwe). */
33
31
  export declare const keysOwedRefusal: (owed: readonly InputIssue[]) => ApiError;
34
32
  /** Under the run-keys setting, whether a trigger's firings could never bring the keys runs of its agent owe (`owed`,
35
33
  * keysOwed with nothing carried): a message_run's never do, hook or not; a start_run's do only through the launch hook,
package/dist/run-keys.js CHANGED
@@ -7,8 +7,9 @@
7
7
  //
8
8
  // AGENTRUN_RUN_KEYS=1 (env-switch.ts): an install whose runs bring the tool keys it does not hold. A template's
9
9
  // apply then makes its agent though a tool key the template declares is not set here, and says so in a warning; a run of
10
- // that revision that does not carry the key is refused (409 agent_not_runnable, at keys.<NAME>), and no trigger is made
11
- // whose firings could not carry it (firingsOwe). Off, nothing changes.
10
+ // that revision that does not carry the key is refused (409 agent_not_runnable, at keys.<NAME>), no trigger is made
11
+ // whose firings could not carry it (firingsOwe), and a firing of one made before is refused the same. Off, nothing
12
+ // changes.
12
13
  import { ApiError } from "./errors.js";
13
14
  import { handedSecretOf } from "./handed-secret.js";
14
15
  import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-hook.js";
@@ -16,15 +17,13 @@ import { needsOf, unlockedFields } from "./run-secrets.js";
16
17
  import { TOOL_FIELDS } from "./tool-keys.js";
17
18
  import { isObject } from "./validate.js";
18
19
  import { RUN_KEYS_ENV } from "./env-switch.js";
19
- /** The tool keys a run of `tools` reads (run-secrets.ts unlockedFields, over tool-keys.ts TOOL_KEYS). */
20
- export const keysOfTools = (tools) => unlockedFields(tools);
21
20
  /** The tool keys a template's apply made `revision` with (its package's `secrets`, kept on the revision): the ones a run
22
21
  * can carry. A model key is not one. */
23
22
  export const packageKeysOf = (revision) => (revision.package?.secrets ?? []).filter((name) => TOOL_FIELDS.includes(name));
24
23
  /** The names a run of `revision`, whose needs are `needs` (run-secrets.ts needsOf), may carry in `keys`: each tool key its
25
24
  * tools read (an agentic revision's tools, a workflow's on its nodes and calls, and its decision providers'), and its
26
25
  * template's tool keys. */
27
- export const declaredFrom = (needs, revision) => [...new Set([...keysOfTools([...needs.tools, ...needs.decisionProviders.map((provider) => `decisions.${provider}`)]), ...packageKeysOf(revision)])];
26
+ export const declaredFrom = (needs, revision) => [...new Set([...unlockedFields([...needs.tools, ...needs.decisionProviders.map((provider) => `decisions.${provider}`)]), ...packageKeysOf(revision)])];
28
27
  /** The names a run of `revision` may carry in `keys` (declaredFrom). */
29
28
  export async function declaredKeys(revision) {
30
29
  return declaredFrom(await needsOf(revision), revision);
@@ -89,8 +88,8 @@ export function keysOwed(revision, env, carried) {
89
88
  fix: `Send keys.${name} with the run.`,
90
89
  }));
91
90
  }
92
- /** The 409 a run that owes `owed` (keysOwed) gets at its start, and a trigger that could only start or message such runs
93
- * gets when it is made or moved (firingsOwe). */
91
+ /** The 409 a run that owes `owed` (keysOwed) gets at its start or a message, and a trigger that could only start or
92
+ * message such runs gets when it is made or moved, and at a message_run firing (firingsOwe). */
94
93
  export const keysOwedRefusal = (owed) => new ApiError("agent_not_runnable", owed.map((one) => one.message).join(" "), { fields: [...owed], details: { unbound: [], missing: {} } });
95
94
  /** Under the run-keys setting, whether a trigger's firings could never bring the keys runs of its agent owe (`owed`,
96
95
  * keysOwed with nothing carried): a message_run's never do, hook or not; a start_run's do only through the launch hook,
@@ -149,6 +149,10 @@ export declare function launchBody(launch: RunLaunch): Json;
149
149
  * disk's (learn/learning-of.ts): the run starts with nothing learned (`other_disk`), its flags kept. Any other launch as
150
150
  * read. readLaunchBody keeps the body as written: a finished run's views show what it ran. */
151
151
  export declare function launchOnItsDisk(launch: RunLaunch): RunLaunch;
152
+ /** Whether a person started the run: no trigger fired it (a schedule's, a webhook's, a trigger's turn into a run), and it
153
+ * is no learned workflow's audit shadow (runner/audit.ts) or replay (runner/promotion.ts), which the server starts
154
+ * itself. Only such a run goes on its owner's own sign-in (runner/harness-loops.ts, cli-run-spec.ts). */
155
+ export declare const personStarted: (launch: Pick<RunLaunch, "trigger" | "audit" | "replay">) => boolean;
152
156
  /** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
153
157
  * undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
154
158
  export declare function readLaunchBody(stored: unknown): RunLaunch | undefined;
@@ -128,6 +128,10 @@ export function launchOnItsDisk(launch) {
128
128
  const { noWorkflows, model, use } = launch.learning;
129
129
  return { ...launch, learning: { seed: null, section: "", seedFailed: "other_disk", ...(noWorkflows ? { noWorkflows } : {}), ...(model ? { model } : {}), ...(use ? { use } : {}) } };
130
130
  }
131
+ /** Whether a person started the run: no trigger fired it (a schedule's, a webhook's, a trigger's turn into a run), and it
132
+ * is no learned workflow's audit shadow (runner/audit.ts) or replay (runner/promotion.ts), which the server starts
133
+ * itself. Only such a run goes on its owner's own sign-in (runner/harness-loops.ts, cli-run-spec.ts). */
134
+ export const personStarted = (launch) => launch.trigger === undefined && launch.audit === undefined && launch.replay === undefined;
131
135
  /** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
132
136
  * undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
133
137
  export function readLaunchBody(stored) {
@@ -5,7 +5,7 @@ import { type Page } from "./rows.js";
5
5
  import { type FileView } from "./run-files.js";
6
6
  import type { RunStated } from "./store-view.js";
7
7
  import { type Store } from "./store/index.js";
8
- import type { Workspace } from "./workspace/index.js";
8
+ import { type Workspace } from "./workspace/index.js";
9
9
  /** The most files a list answers with (server.ts FILE_LIST_CAP). */
10
10
  export declare const FILE_LIST_CAP = 2000;
11
11
  /** The store slice these reads need. */
@@ -51,7 +51,8 @@ export declare function listRunFiles(store: RunReadsStore, runId: string, deps:
51
51
  }>;
52
52
  /** One of a run's files, through its Workspace (readRunFile): streamed to `res` as the route streams it, with the route's
53
53
  * path check and its 404 words; a withheld run refuses (403) before anything is streamed. A path under recordings/ is
54
- * one of the run's recordings (its recordings folder, beside its Workspace's), never a file the run made. */
54
+ * one of the run's recordings (its recordings folder, beside its Workspace's), never a file the run made. With
55
+ * `?cut=run`, the file's text under the run's own cut instead (cutRunFile). */
55
56
  export declare function readRunFile(store: RunReadsStore, runId: string, rawPath: string, req: IncomingMessage, res: ServerResponse, url: URL, deps: RunReadsDeps): Promise<void>;
56
57
  /** A run's browser state (getRunBrowser): `live` with its viewer's link when its runner serves one; else `off` with why
57
58
  * when the run has no browser or its browser is unavailable here now (the kept plane re-checked, as a launch would); else
@@ -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)
@@ -13,6 +13,6 @@ export type ServedTimelineDeps = {
13
13
  readonly statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
14
14
  };
15
15
  /** Run `runId`'s Timeline rows as served: cut by its one cut set, its decision rows among them, its error rows in the
16
- * run's error's words; none for a run withheld. `calls`: each call's arguments whole and its output's head to
16
+ * run's error's words; none for a run withheld. `calls`: each call's arguments whole and its output whole to
17
17
  * CALL_RESULT_CHARS too (TimelineOptions.calls), through the same cut, for a reader that grades the run. */
18
18
  export declare function servedTimelineRows(deps: ServedTimelineDeps, store: Store, runId: string, context: Context, calls?: boolean): Promise<TimelineEvent[]>;
@@ -1,9 +1,9 @@
1
- import { CALL_RESULT_CHARS, TRIGGER_LABELS } from "./timeline/index.js";
1
+ import { CALL_RESULT_CHARS, scrubUrls, TRIGGER_LABELS } from "./timeline/index.js";
2
2
  import { withDecisions } from "./decision-rows.js";
3
3
  import { currentLearning, holdsForOk, secretsShown } from "./learning.js";
4
4
  import { withLearning } from "./learning-run.js";
5
5
  import { runLearningEnd } from "./store-reads/learning.js";
6
- import { heldNumber, redacted } from "./key-refusal.js";
6
+ import { heldNumber, redacted, redactedCall } from "./key-refusal.js";
7
7
  import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
8
8
  import { answersOf, asksOf, shownOf, stopAsked, withApprovalRows, withAsks, withBudgetRows, withOverCap } from "./run-view.js";
9
9
  import { launchOf } from "./handed-values.js";
@@ -14,7 +14,7 @@ import { readRun } from "./store-reads/runs.js";
14
14
  import { runTimeline, servedSince, wholeAnswerFor, wholeAnswers } from "./store-reads/journal.js";
15
15
  import { FINAL_STATES } from "./store/store.js";
16
16
  /** Run `runId`'s Timeline rows as served: cut by its one cut set, its decision rows among them, its error rows in the
17
- * run's error's words; none for a run withheld. `calls`: each call's arguments whole and its output's head to
17
+ * run's error's words; none for a run withheld. `calls`: each call's arguments whole and its output whole to
18
18
  * CALL_RESULT_CHARS too (TimelineOptions.calls), through the same cut, for a reader that grades the run. */
19
19
  export async function servedTimelineRows(deps, store, runId, context, calls = false) {
20
20
  // The run's rows, its decisions, its learning end and the triggers' names, all read in one snapshot of the store (one
@@ -48,7 +48,7 @@ export async function servedTimelineRows(deps, store, runId, context, calls = fa
48
48
  // And every call still waiting once a stop is asked and not yet taken, as the run's view reads it (stopAsked).
49
49
  const final = run?.state === "stopped" || run?.state === "failed" ? run.state
50
50
  : stopAsked(view, run, await snapshot.commands(runId, 0)) ? "stopped" : undefined;
51
- const options = { redact, settled: ended, ended: view ? view.state !== "running" : false, ...(calls ? { calls: { result: CALL_RESULT_CHARS, redact: (text) => redacted(text, values, CALL_RESULT_CHARS), held: (value) => heldNumber(value, values) } } : {}) };
51
+ const options = { redact, settled: ended, ended: view ? view.state !== "running" : false, ...(calls ? { calls: { result: CALL_RESULT_CHARS, redact: (text) => redactedCall(text, values, CALL_RESULT_CHARS, scrubUrls), held: (value) => heldNumber(value, values) } } : {}) };
52
52
  const timeline = await wholeAnswers(snapshot, runId, context, await runTimeline(snapshot, runId, context, options), options, wholeAnswerFor(values), since);
53
53
  // A run whose booked spend passed its cap says so, by how much, after its usage row (run-view.ts withOverCap, as main's
54
54
  // served Timeline did): at the cap as it stands (a raise taken counts, capNowOf).
@@ -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). */
@@ -304,6 +307,9 @@ export type AdapterRun = PiRun & {
304
307
  * while it is built (a CLI harness's first-use install), so a stop ends that wait at once and never the work it waits
305
308
  * for. Absent where no loop gave one. */
306
309
  readonly stopped?: AbortSignal;
310
+ /** The runner's presence incarnation (LoopDeps.incarnation): with the claim's runner, who keeps a computer a park pins
311
+ * to its runner (computer-for-claim.ts ClaimLaunch.holder). Absent where no loop gave one. */
312
+ readonly incarnation?: string;
307
313
  /** Stages the run row's `summary` on the next commit of this pass that writes a root entry of `kind` whose data `test`
308
314
  * takes, in that commit (a tool host's wait on the person, its claim held: the server tells run.needs_input by the
309
315
  * summary). Absent where no loop gave one. */
@@ -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, ...(deps.incarnation ? { incarnation: deps.incarnation } : {}) };
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. */
@@ -351,14 +351,17 @@ 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
358
358
  // Docker container for a sandbox, under the claim's epoch (the one fence). It throws computer_unavailable (nothing made)
359
359
  // when the computer cannot be had: the run fails in its words.
360
360
  const claimSignal = run.stopped ?? run.signal;
361
- const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, claim, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place }, deps.store,
361
+ const computer = await deps.computerForClaim(
362
+ // The runner holding the claim (its name, its presence incarnation): a computer a park keeps that only it can reach
363
+ // again is pinned to it.
364
+ { runId: claim.runId, epoch: claim.epoch, claim, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place, ...(run.incarnation ? { holder: { runner: claim.runner, incarnation: run.incarnation } } : {}) }, deps.store,
362
365
  // revokeMount removes the run's Archil mount credential when the computer is released (and if a start fails after a mint);
363
366
  // the run's end revokes it too (below), so it goes on every outcome even when no computer is made. Idempotent. What
364
367
  // became of the agent's own computer (a persistent setting) is said on the run's timeline.
@@ -508,6 +511,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
508
511
  ...(besideOf ? { beside: besideOf } : {}),
509
512
  // The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS, or the agent's lower max_requests).
510
513
  freeRequests: freeRequestLimitOf(deps.env, body.maxRequests),
514
+ // The agent's own limit alone, which a local model's requests count toward too (run-cap.ts maxRequests).
515
+ ...(maxRequestsOf(body.maxRequests) === undefined ? {} : { maxRequests: maxRequestsOf(body.maxRequests) }),
511
516
  };
512
517
  // 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
518
  // 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;