@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
@@ -12,7 +12,12 @@ import { type CostParts } from "@parcha/agentrun-kernel";
12
12
  * gateway priced (`reported`: the proxy's reportedCostOf or usageCostOf, its runner.turn keeping the table's figure beside
13
13
  * it as `tableUsd`) and how many a price table did (`estimated`: its runner.turn's `estimated`, or a cut request's hold,
14
14
  * or a native or SDK task's `aggregate` booking, its harness's own figure).
15
- * A figure that is neither ($0 for a request refused or never sent, a charge settled through the cap) counts in neither. */
15
+ * A figure that is neither ($0 for a request refused or never sent, a charge settled through the cap) counts in neither.
16
+ * `plan`: of its requests, those billed to a person's plan (a ChatGPT plan's, chatgpt-plan.ts, or Claude Code's login's:
17
+ * its runner.turn's `billing` "plan", or, still in flight, its runner.request's `plan`), how many and their tokens (input,
18
+ * output and cache, as each booking reported them; none yet for one in flight). Each is $0 to the run by the kernel's one
19
+ * rule (turnCostOf), however it ended: the plan pays for it, so no reader counts it unpriced. Counted as `requests` is:
20
+ * a request booked twice is one. */
16
21
  export type BookedSpend = {
17
22
  readonly usd: number | null;
18
23
  readonly known: number;
@@ -32,6 +37,10 @@ export type BookedSpend = {
32
37
  readonly reported: number;
33
38
  readonly estimated: number;
34
39
  };
40
+ readonly plan: {
41
+ readonly requests: number;
42
+ readonly tokens: number;
43
+ };
35
44
  readonly free?: true;
36
45
  };
37
46
  /** How a run's cost was reached, by how its model requests were priced: `reported` when every request priced had the
@@ -115,15 +124,6 @@ export type EndCost = {
115
124
  readonly costUpperBound: boolean;
116
125
  };
117
126
  export declare const endCostOf: (cost: RunCost) => EndCost;
118
- /** The run's model requests billed to a person's plan (runner.turn `billing` "plan", booked at no price: a ChatGPT plan's,
119
- * chatgpt-plan.ts, or Claude Code's login's):
120
- * how many and their tokens (input, output and cache, as each booking reported them). Each is $0 to the run by the
121
- * kernel's one rule (turnCostOf), however it ended: the plan pays for it, so no reader counts it unpriced. One still in
122
- * flight (its runner.request marked `plan`, no runner.turn yet) is one of them, with no tokens yet. */
123
- export declare function planSpend(entries: readonly EntryLike[]): {
124
- readonly requests: number;
125
- readonly tokens: number;
126
- };
127
127
  /** Whether a CLI harness's record (`entries`, its root's) shows the model at work: a model message, a tool call it made, or
128
128
  * its end-of-run turn's answer. Each took a model request, so a run that shows one and booked none (its requests went
129
129
  * past its model proxy) spent what no booking read: its cost is unknown, never $0. */
@@ -8,11 +8,13 @@
8
8
  // passes its decisions. `effort` is the level the run ran at and `model`, on a harness other than pi, the model its
9
9
  // revision named — both as storedMetrics added them, resolved by the caller from the run's launch and harness.
10
10
  import { runMetricsWithDecisions, timelineOf } from "../timeline/index.js";
11
- import { costOfParts, rebooked, RUNNER_RECORDS, sessionSpendOf, turnCostOf } from "@parcha/agentrun-kernel";
11
+ import { billedToPlan, costOfParts, rebooked, RUNNER_RECORDS, sessionSpendOf, turnCostOf } from "@parcha/agentrun-kernel";
12
12
  import { DECISION_SESSION, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
13
13
  import { KINDS, WORKFLOW_SESSION } from "./journal-kinds.js";
14
14
  import { anthropicModelId } from "../provider.js";
15
15
  import { WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
16
+ /** A booking record's request, as every reader of a booking names it: its conversation and its turn. */
17
+ const turnOf = (e) => `${String(e.conversationId)}:${String(e.data?.turn)}`;
16
18
  /** How a run's cost was reached, by how its model requests were priced: `reported` when every request priced had the
17
19
  * provider's or its gateway's own figure (LiteLLM's `x-litellm-response-cost`, OpenRouter's usage `cost`); `estimate`
18
20
  * when any was priced from a price table (the catalog, AGENT_MODEL_PRICE, a cut request's hold); `unpriced` when no
@@ -71,7 +73,6 @@ export function bookedSpend(entries, which) {
71
73
  const paidConv = keyed.get(TOOL_SESSION);
72
74
  const decisionsConv = keyed.get(DECISION_SESSION);
73
75
  const conv = (e) => Number(e.conversationId);
74
- const turnOf = (e) => `${String(e.conversationId)}:${String(e.data?.turn)}`;
75
76
  const model = (e) => conv(e) !== paidConv && conv(e) !== decisionsConv;
76
77
  // The side calls among the model requests: each request that says so, by its conversation and turn.
77
78
  const sides = new Set(entries.filter((e) => e.kind === RUNNER_RECORDS.request && model(e) && (e.data?.side === true || typeof e.data?.host === "string")).map(turnOf));
@@ -95,6 +96,7 @@ export function bookedSpend(entries, which) {
95
96
  let reported = 0;
96
97
  let estimated = 0;
97
98
  const tokens = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
99
+ const plan = { requests: 0, tokens: 0 };
98
100
  // Each request is booked once, as the kernel's sessionSpendOf reads it: a second runner.turn of a turn already booked
99
101
  // (two bookings of one session that each read it open, a cut written twice) counts no money and no request again.
100
102
  const booked = new Set();
@@ -104,9 +106,11 @@ export function bookedSpend(entries, which) {
104
106
  if (e.kind === RUNNER_RECORDS.request && !answered.has(turnOf(e))) {
105
107
  requests += 1;
106
108
  count(e);
107
- // One billed to a person's plan (its record's `plan`, Admitted.plan) is $0 to the run however it ends, as the cap's
108
- // reader (the kernel's sessionSpendOf) holds it: in flight it is a known $0, never unpriced.
109
- if (e.data?.plan !== true)
109
+ // One billed to a person's plan (its record's `plan`, Admitted.plan) is $0 to the run however it ends, as the
110
+ // kernel's sessionSpendOf holds it: in flight it is a known $0 and one of the plan's requests, never unpriced.
111
+ if (billedToPlan(e.data))
112
+ plan.requests += 1;
113
+ else
110
114
  unpriced += 1;
111
115
  unmetered += 1;
112
116
  continue;
@@ -145,17 +149,22 @@ export function bookedSpend(entries, which) {
145
149
  // The booking keeps a request's usage only when it reported some (runner.ts tokensOf): one with none is unmetered.
146
150
  if (d.usage === undefined)
147
151
  unmetered += 1;
148
- for (const key of Object.keys(tokens))
149
- if (typeof d.usage?.[key] === "number")
150
- tokens[key] += d.usage[key];
152
+ if (d.billing === "plan")
153
+ plan.requests += 1;
154
+ for (const key of Object.keys(tokens)) {
155
+ if (typeof d.usage?.[key] !== "number")
156
+ continue;
157
+ tokens[key] += d.usage[key];
158
+ if (d.billing === "plan")
159
+ plan.tokens += d.usage[key];
160
+ }
151
161
  }
152
- return { usd: unpriced ? null : known + bounded, known, bounded, unpriced, atMost, requests, unmetered, models, tokens, priced: { reported, estimated }, ...(requests > 0 && free === requests ? { free: true } : {}) };
162
+ return { usd: unpriced ? null : known + bounded, known, bounded, unpriced, atMost, requests, unmetered, models, tokens, priced: { reported, estimated }, plan, ...(requests > 0 && free === requests ? { free: true } : {}) };
153
163
  }
154
164
  /** The run's decisions whose ids are in `ids` (each booked as `decision:<id>`), as bookedSpend reads its decisions, with
155
165
  * every other decision left out: the ones a vendor charged as a paid call (store-reads/decisions.ts
156
166
  * parallelChargedDecisions), which the run's tools figures count beside its paid tool calls. */
157
167
  export function bookedDecisionsOf(entries, ids) {
158
- const turnOf = (e) => `${String(e.conversationId)}:${String(e.data?.turn)}`;
159
168
  const named = (e) => e.data?.model;
160
169
  const kept = new Set(entries.filter((e) => e.kind === RUNNER_RECORDS.request && typeof named(e) === "string" && named(e).startsWith("decision:") && ids.has(named(e).slice("decision:".length))).map(turnOf));
161
170
  return bookedSpend(entries.filter((e) => !(e.kind === RUNNER_RECORDS.request || e.kind === RUNNER_RECORDS.turn) || kept.has(turnOf(e))), "decisions");
@@ -202,34 +211,6 @@ export function runCostOf(entries, { unbooked = false } = {}) {
202
211
  return { usd, known, bounded: usd === null ? 0 : Math.max(0, round(usd - known)), unpriced: cost.unpriced, atMost: cost.atMost ?? 0, requests: parts.reduce((sum, part) => sum + part.requests, 0) };
203
212
  }
204
213
  export const endCostOf = (cost) => ({ costUsd: cost.usd, costUpperBound: cost.usd !== null && cost.atMost > 0 });
205
- /** The run's model requests billed to a person's plan (runner.turn `billing` "plan", booked at no price: a ChatGPT plan's,
206
- * chatgpt-plan.ts, or Claude Code's login's):
207
- * how many and their tokens (input, output and cache, as each booking reported them). Each is $0 to the run by the
208
- * kernel's one rule (turnCostOf), however it ended: the plan pays for it, so no reader counts it unpriced. One still in
209
- * flight (its runner.request marked `plan`, no runner.turn yet) is one of them, with no tokens yet. */
210
- export function planSpend(entries) {
211
- const turnOf = (e) => `${String(e.conversationId)}:${String(e.data?.turn)}`;
212
- const answered = new Set(entries.filter((e) => e.kind === RUNNER_RECORDS.turn).map(turnOf));
213
- let requests = 0;
214
- let tokens = 0;
215
- for (const e of entries) {
216
- if (e.kind === RUNNER_RECORDS.request) {
217
- if (e.data?.plan === true && !answered.has(turnOf(e)))
218
- requests += 1;
219
- continue;
220
- }
221
- if (e.kind !== RUNNER_RECORDS.turn)
222
- continue;
223
- const d = (e.data ?? {});
224
- if (d.billing !== "plan" || d.givenBack === true || d.unsent === true)
225
- continue;
226
- requests += 1;
227
- for (const key of ["input", "output", "cacheRead", "cacheWrite"])
228
- if (typeof d.usage?.[key] === "number")
229
- tokens += d.usage[key];
230
- }
231
- return { requests, tokens };
232
- }
233
214
  /** Whether a CLI harness's record (`entries`, its root's) shows the model at work: a model message, a tool call it made, or
234
215
  * its end-of-run turn's answer. Each took a model request, so a run that shows one and booked none (its requests went
235
216
  * past its model proxy) spent what no booking read: its cost is unknown, never $0. */
@@ -73,6 +73,9 @@ export interface ModelRoute {
73
73
  readonly unpriced?: boolean;
74
74
  /** The model's most output tokens (its catalog ceiling): the cap's output bound, null when the catalog names none. */
75
75
  readonly outputCeiling?: number | null;
76
+ /** A model on this machine's own Ollama (ollama-provider.ts): $0, and its requests never count toward the run's
77
+ * free-model limit (the cap's CapModel.local), which guards a provider's shared quota this model has none of. */
78
+ readonly local?: boolean;
76
79
  }
77
80
  type PiModel = {
78
81
  id: string;
@@ -17,6 +17,7 @@ import { randomUUID } from "node:crypto";
17
17
  import { calculateCost } from "@earendil-works/pi-ai";
18
18
  import { onOpenRouter, openRouterAttribution, ROUTE_ORIGIN, streamErrorOf } from "@parcha/agentrun-kernel/host";
19
19
  import { chooseModel, MODEL_PROVIDER, runModels } from "../model.js";
20
+ import { OLLAMA_PROVIDER } from "../ollama-provider.js";
20
21
  import { gatewayHeadersAt, providerFor } from "../provider.js";
21
22
  import { keepText, runnerSecrets, secretRedactor } from "./redact.js";
22
23
  import { callsOfText, toolsAsText } from "./text-tools.js";
@@ -80,8 +81,11 @@ export async function routeOf(model, env = process.env, tier = "default", wires
80
81
  // thinking level by name (LEVELS_BY_NAME), which the translation hands to pi-ai (levelOf): the run's effort reaches the
81
82
  // model, mapped and clamped by its own catalog entry. Direct Particle states no cost (its usage is priced from the
82
83
  // catalog), and its session also takes the model's window and ceiling and replays unsigned reasoning.
83
- const like = target.provider === "particle" ? { ...settings, ...LEVELS_BY_NAME, translatedChatCompletions: true } : target.reasoning ? { ...sees, ...LEVELS_BY_NAME } : undefined;
84
- return { ...route, ...(like ? { like } : {}), provider: { api: "anthropic-messages", origin: ROUTE_ORIGIN, credential: () => "model-route" }, fetch: messagesFetch(models, target, redact ?? secretRedactor(runnerSecrets(env)), upstream, env) };
84
+ // An Ollama model's session also takes its window, the context every request asks Ollama for (num_ctx), so pi compacts
85
+ // before Ollama would cut the prompt.
86
+ const local = target.provider === OLLAMA_PROVIDER;
87
+ const like = target.provider === "particle" ? { ...settings, ...LEVELS_BY_NAME, translatedChatCompletions: true } : local ? { ...settings, ...(target.reasoning ? LEVELS_BY_NAME : {}) } : target.reasoning ? { ...sees, ...LEVELS_BY_NAME } : undefined;
88
+ return { ...route, ...(like ? { like } : {}), ...(local ? { local: true } : {}), provider: { api: "anthropic-messages", origin: ROUTE_ORIGIN, credential: () => "model-route" }, fetch: messagesFetch(models, target, redact ?? secretRedactor(runnerSecrets(env)), upstream, env) };
85
89
  }
86
90
  /** Whether pi-ai sends `target`'s requests to OpenRouter (pi-ai's own test, utils/openrouter-cost.js isOpenRouterModel). */
87
91
  const piOnOpenRouter = (target) => target.provider === "openrouter" || onOpenRouter(target.baseUrl ?? "");
@@ -1,8 +1,9 @@
1
- import type { Runners } from "../store/store.js";
1
+ import { type Runners } from "../store/store.js";
2
2
  /** How often a runner says again that it is there. */
3
3
  export declare const PRESENCE_RENEW_MS = 10000;
4
- /** How old a runner's word can be and still count: three renewals missed. */
5
- export declare const PRESENCE_STALE_MS: number;
4
+ /** How old a runner's word can be and still count: three renewals missed. The store's (RUNNER_STALE_MS), which its claim
5
+ * rule reads for a kept computer's pin. */
6
+ export declare const PRESENCE_STALE_MS = 30000;
6
7
  /** This build's version (the serve package's), which every runner says on its row (runners.version) for the server's
7
8
  * capacity read (GET /v2/capacity). */
8
9
  export declare const RUNNER_VERSION: string;
@@ -12,10 +12,12 @@
12
12
  import { randomUUID } from "node:crypto";
13
13
  import { readFileSync } from "node:fs";
14
14
  import { ApiError } from "../errors.js";
15
+ import { RUNNER_STALE_MS } from "../store/store.js";
15
16
  /** How often a runner says again that it is there. */
16
17
  export const PRESENCE_RENEW_MS = 10_000;
17
- /** How old a runner's word can be and still count: three renewals missed. */
18
- export const PRESENCE_STALE_MS = 3 * PRESENCE_RENEW_MS;
18
+ /** How old a runner's word can be and still count: three renewals missed. The store's (RUNNER_STALE_MS), which its claim
19
+ * rule reads for a kept computer's pin. */
20
+ export const PRESENCE_STALE_MS = RUNNER_STALE_MS;
19
21
  /** This build's version (the serve package's), which every runner says on its row (runners.version) for the server's
20
22
  * capacity read (GET /v2/capacity). */
21
23
  export const RUNNER_VERSION = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
@@ -5,7 +5,7 @@ import { type RunLaunch } from "../run-launch.js";
5
5
  import { type Store } from "../store/store.js";
6
6
  import { type Recorded, type ReplayCalls, type Skipped } from "../learn/replay-calls.js";
7
7
  import { type Json } from "../validate.js";
8
- import { type CheckBar, type CheckRecord, type CheckTurns, type Compared, type PromotionRecord, recordPromotion, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
8
+ import { type CheckBar, type CheckRecord, type CheckTurns, type Compared, type PromotionRecord, recordPromotion, type Refused, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
9
9
  import { type FirstChoice, type Promoted, type ReplayOutcome } from "./workflow-first.js";
10
10
  import type { LearningFolder } from "../learn/folder.js";
11
11
  import type { Shown } from "../learning.js";
@@ -32,9 +32,13 @@ export interface PromotionDeps {
32
32
  readonly context: Context;
33
33
  readonly log: (line: string) => void;
34
34
  /** The learned workflow `name` as the learning folder held it active at `commit` (a champion's text), or undefined when
35
- * it held none by that name, or a purged run wrote it (learning.ts seedAt): a purged champion is no champion's text,
36
- * and the agent takes the run. Absent: no champion serves. */
35
+ * it held none by that name, or a purged run wrote it (learning.ts seedAt): a purged run's text is never served (the
36
+ * champion skips it first, `refused`). Absent: no champion serves. */
37
37
  readonly champion?: (name: string, commit: string) => Promise<LearnedWorkflow | undefined>;
38
+ /** The records of `workflows` (all, when absent) championOf skips (purged-workflow.ts refusedIn over the learning
39
+ * folder): a champion the purge gate refuses at its commit, so the newest promotion it lets through serves, and the
40
+ * promotions trim keeps that one (recordPromotion). Absent: none skipped. */
41
+ readonly refused?: (records: readonly PromotionRecord[], workflows?: Iterable<string>) => Promise<Refused>;
38
42
  /** The digest of the learned workflow `name` the learning folder's main holds now (the newest revision), or undefined
39
43
  * when it holds none by that name. Absent: every revision is the newest. */
40
44
  readonly newest?: (name: string) => Promise<string | undefined>;
@@ -55,7 +59,7 @@ export interface PromotionDeps {
55
59
  }
56
60
  /** What deciding a check needs (decideCheck, stopUnchecked): a claim's ports, or those of a connected agent's start or
57
61
  * run end, whose record names its commit (no claimed launch to read a seed from). */
58
- type DecideDeps = Pick<PromotionDeps, "store" | "agentId" | "log" | "shown"> & Partial<Pick<PromotionDeps, "launch" | "now">>;
62
+ type DecideDeps = Pick<PromotionDeps, "store" | "agentId" | "log" | "shown"> & Partial<Pick<PromotionDeps, "launch" | "now" | "refused">>;
59
63
  /** The claim's promotion ports: `folder`, the agent's learning folder where the run's place keeps it, a champion read
60
64
  * from it at its record's commit, cut of the server's secrets (`shown`) as the claim's lay is; and the workflow an earlier
61
65
  * claim of this run served (`kept`, from its journal: none on a first claim). */
@@ -79,12 +83,13 @@ export declare function replayLaid(launch: RunLaunch, laid: readonly LearnedWork
79
83
  * promoted yet, or the champion held): a revision replaying, held or never decided is never handed to the agent to run
80
84
  * in its place. One the records never named is an unchecked draft and is not offered. A replay run's as
81
85
  * laid (replayLaid). The records unread: only the chosen one, as the gate leaves a run to its agent. */
82
- export declare function toolFlowsFor(deps: Pick<PromotionDeps, "store" | "agentId" | "champion" | "log">, launch: RunLaunch, laid: readonly LearnedWorkflow[], choice: FirstChoice): Promise<LearnedWorkflow[]>;
86
+ export declare function toolFlowsFor(deps: Pick<PromotionDeps, "store" | "agentId" | "champion" | "refused" | "log">, launch: RunLaunch, laid: readonly LearnedWorkflow[], choice: FirstChoice): Promise<LearnedWorkflow[]>;
83
87
  /** `flow`'s champion (championOf) and the text it serves from: `flow` itself when it is the champion, else the
84
88
  * champion's text read at its record's commit (`read`), kept only when its digest is the champion's. No text: none is
85
- * promoted, or its text cannot be read. The one champion lookup a claim's gate (servingNow), the learned_workflow tool
86
- * (toolFlowsFor) and a connected agent's start (sdk/runs.ts) share. */
87
- export declare function championTextOf(records: readonly PromotionRecord[], flow: LearnedWorkflow, read?: (name: string, commit: string) => Promise<LearnedWorkflow | undefined>): Promise<{
89
+ * promoted, or its text cannot be read. The champion skips what `refused` says the purge gate refuses (PromotionDeps
90
+ * refused), so after a purge of its run the newest promotion the gate lets through serves. The one champion lookup a
91
+ * claim's gate (servingNow), the learned_workflow tool (toolFlowsFor) and a connected agent's start (sdk/runs.ts) share. */
92
+ export declare function championTextOf(records: readonly PromotionRecord[], flow: LearnedWorkflow, read?: (name: string, commit: string) => Promise<LearnedWorkflow | undefined>, refused?: PromotionDeps["refused"]): Promise<{
88
93
  champion?: PromotionRecord;
89
94
  text?: LearnedWorkflow;
90
95
  }>;
@@ -127,7 +132,8 @@ export type CheckRow = {
127
132
  readonly compared?: Compared;
128
133
  };
129
134
  /** Decides a check on its rows, with a connected agent's turns checked before them (`before`), scored on its bar
130
- * (scoreRows). Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
135
+ * (scoreRows). Promoted when it clears the bar (checkPasses) and the purge gate lets its revision through at its commit
136
+ * (`refused`: else held, a purged run's text); else held with the inputs it did not agree on, which the
131
137
  * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
132
138
  * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
133
139
  * (the one write: of two claims at once, one decides). */
@@ -56,6 +56,7 @@ import { listed } from "../learning-words.js";
56
56
  import { isObject } from "../validate.js";
57
57
  import { agentRun, lastOwnRuns, newCompileAttempt, sinceReset } from "../learn/compile.js";
58
58
  import { checkPasses, checkShares, CHECK_TEXT_MAX, championOf, compareAnswers, comparedOf, promotionOf, promotionsOf, recordPromotion, replayingOf, skippedToolsOf } from "../learn/promote.js";
59
+ import { refusedIn } from "../purged-workflow.js";
59
60
  import { sendCommand } from "./commands.js";
60
61
  import { ClaimRefused } from "./loop-contract.js";
61
62
  import { readSnapshot } from "../learn/folder.js";
@@ -78,6 +79,7 @@ export function claimPromotion(deps) {
78
79
  ...deps,
79
80
  kept: async () => (deps.runId ? servedOf(await runEntries(deps.store, deps.runId, deps.context).catch(() => [])) : undefined),
80
81
  champion: async (name, commit) => (await workflowsAt({ folder: deps.folder, store: deps.store, shown: deps.shown }, commit)).find((one) => one.name === name),
82
+ refused: refusedIn(deps.folder, deps.store, deps.log),
81
83
  newest: async (name) => {
82
84
  const folder = deps.folder();
83
85
  let main;
@@ -145,7 +147,7 @@ export async function toolFlowsFor(deps, launch, laid, choice) {
145
147
  continue;
146
148
  }
147
149
  const digest = workflowDigest(one);
148
- const { champion, text } = await championTextOf(records, one, deps.champion);
150
+ const { champion, text } = await championTextOf(records, one, deps.champion, deps.refused);
149
151
  if (text === one)
150
152
  out.push(one);
151
153
  else if (text) {
@@ -159,10 +161,11 @@ export async function toolFlowsFor(deps, launch, laid, choice) {
159
161
  }
160
162
  /** `flow`'s champion (championOf) and the text it serves from: `flow` itself when it is the champion, else the
161
163
  * champion's text read at its record's commit (`read`), kept only when its digest is the champion's. No text: none is
162
- * promoted, or its text cannot be read. The one champion lookup a claim's gate (servingNow), the learned_workflow tool
163
- * (toolFlowsFor) and a connected agent's start (sdk/runs.ts) share. */
164
- export async function championTextOf(records, flow, read) {
165
- const champion = championOf(records, flow.name);
164
+ * promoted, or its text cannot be read. The champion skips what `refused` says the purge gate refuses (PromotionDeps
165
+ * refused), so after a purge of its run the newest promotion the gate lets through serves. The one champion lookup a
166
+ * claim's gate (servingNow), the learned_workflow tool (toolFlowsFor) and a connected agent's start (sdk/runs.ts) share. */
167
+ export async function championTextOf(records, flow, read, refused) {
168
+ const champion = championOf(records, flow.name, refused ? await refused(records, [flow.name]) : undefined);
166
169
  if (!champion)
167
170
  return {};
168
171
  if (champion.digest === workflowDigest(flow))
@@ -217,7 +220,7 @@ export const promotionGate = (deps) => {
217
220
  * serves: none promoted, the champion held, or its text cannot be read (the agent takes the run). */
218
221
  async function servingNow(deps, workflow, digest, laid) {
219
222
  const records = await promotionsOf(deps.store.settings, deps.agentId);
220
- const { champion, text } = await championTextOf(records, workflow, deps.champion);
223
+ const { champion, text } = await championTextOf(records, workflow, deps.champion, deps.refused);
221
224
  const own = promotionOf(records, workflow.name, digest);
222
225
  if (!champion) {
223
226
  if (own?.decided === "promote")
@@ -259,7 +262,7 @@ async function holdRefused(deps, serving) {
259
262
  return serving;
260
263
  const reason = excerptShown(`${DSL_REFUSES}: ${refused}`, await deps.shown(), CHECK_TEXT_MAX);
261
264
  const record = { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, ...(current.commit ? { commit: current.commit } : {}) };
262
- const kept = await recordPromotion(deps.store.settings, deps.agentId, record, (was) => was?.decided === "promote" && was.at === current.at);
265
+ const kept = await recordPromotion(deps.store.settings, deps.agentId, record, (was) => was?.decided === "promote" && was.at === current.at, deps.refused);
263
266
  if (kept.won)
264
267
  deps.log(`workflow-first: ${name} at ${digest} is held: ${reason}; the agent's next run recompiles it once`);
265
268
  return serving;
@@ -440,7 +443,7 @@ export const differentDecisionWords = (k, n, example) => `its answers reached a
440
443
  * or its owner acts, and `extra` on the record (a connected agent's check: what its reservation carries). Kept only while
441
444
  * `still` holds of the digest's record (the one write), and logged. */
442
445
  async function holdUnchecked(deps, name, digest, bar, reason, still, { stopped = false, check = {}, extra = {} } = {}) {
443
- const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, of: [], ...check, ...(stopped ? { stopped: true } : {}) }, ...seedOf(deps), ...extra }, still);
446
+ const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, of: [], ...check, ...(stopped ? { stopped: true } : {}) }, ...seedOf(deps), ...extra }, still, deps.refused);
444
447
  if (decided.won)
445
448
  deps.log(`workflow-first: ${name} at ${digest} ${stopped ? "stopped" : "held"}: ${reason}`);
446
449
  return decided;
@@ -563,7 +566,8 @@ async function scoreRows(deps, bar, rows, before) {
563
566
  /** Two outcome counts added. */
564
567
  const outcomesAdded = (a, b) => b ? { answered: a.answered + b.answered, handed_back: a.handed_back + b.handed_back, failed: a.failed + b.failed, skipped_write: a.skipped_write + b.skipped_write } : a;
565
568
  /** Decides a check on its rows, with a connected agent's turns checked before them (`before`), scored on its bar
566
- * (scoreRows). Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
569
+ * (scoreRows). Promoted when it clears the bar (checkPasses) and the purge gate lets its revision through at its commit
570
+ * (`refused`: else held, a purged run's text); else held with the inputs it did not agree on, which the
567
571
  * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
568
572
  * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
569
573
  * (the one write: of two claims at once, one decides). */
@@ -604,9 +608,15 @@ export async function decideCheck(deps, name, digest, bar, read, still, extra) {
604
608
  const verbatim = ok || bar.agree_on?.length ? "" : grader ? (differed > 0 ? `; ${differentDecisionWords(differed, score.alone, example)}` : "") : score.alone > 0 && score.agreed === 0 ? `; ${read.exactMismatchReason ?? NEVER_WORD_FOR_WORD}` : "";
605
609
  const reason = ok ? `${said}: promoted` : stopped ? `${said}: held${verbatim}, and this was the recompile's check, so it stops: nothing compiles again until a hold or its owner acts` : `${said}: held${verbatim}; the agent's next run recompiles it once with the inputs it did not agree on`;
606
610
  const check = { ...bar, ...score, ...numbers, ...(disagreements.length ? { disagreements } : {}), ...(stopped ? { stopped: true } : {}), ...(grader ? { grader } : {}) };
607
- const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso(now()), decided: ok ? "promote" : "hold", reason, check, ...seedOf(deps), ...extra }, still);
611
+ const record = { workflow: name, digest, at: iso(now()), decided: ok ? "promote" : "hold", reason, check, ...seedOf(deps), ...extra };
612
+ // A check that outlives its revision's run: the run's purge never stops it (it replays other runs' inputs), and the
613
+ // purge gate refuses the revision at the commit it was checked at (purged-workflow.ts refusedOf). It is held, never
614
+ // promoted, so no promotion of the purged run's text lands.
615
+ const gone = ok && deps.refused !== undefined && (await deps.refused([record], [name]))(record);
616
+ const kept = gone ? { ...record, decided: "hold", reason: `${said}: held, never promoted: a purged run wrote this revision, and its text is gone` } : record;
617
+ const decided = await recordPromotion(deps.store.settings, deps.agentId, kept, still, deps.refused);
608
618
  if (decided.won)
609
- deps.log(`workflow-first: ${name} at ${digest} ${ok ? "promoted" : "held"}: ${reason}`);
619
+ deps.log(`workflow-first: ${name} at ${digest} ${kept.decided === "promote" ? "promoted" : "held"}: ${kept.reason}`);
610
620
  return decided;
611
621
  }
612
622
  /** Reserves a check of `workflow` at `digest` on `inputs`, then starts its runs: its replaying record names the replay
@@ -618,7 +628,7 @@ async function reserve(deps, workflow, digest, inputs, reason, still, check) {
618
628
  const now = deps.now ?? Date.now;
619
629
  const ids = inputs.map(() => uuidv7());
620
630
  const launch = replayLaunchOf(deps);
621
- const reserved = await recordPromotion(deps.store.settings, deps.agentId, { workflow: workflow.name, digest, at: iso(now()), decided: "replaying", reason, runs: ids, inputs: inputs.map((one) => one.run), replay_id: uuidv7(), launch, ...seedOf(deps), check }, (was, items) => still(was) && replayingOf(items, workflow.name, digest).length === 0);
631
+ const reserved = await recordPromotion(deps.store.settings, deps.agentId, { workflow: workflow.name, digest, at: iso(now()), decided: "replaying", reason, runs: ids, inputs: inputs.map((one) => one.run), replay_id: uuidv7(), launch, ...seedOf(deps), check }, (was, items) => still(was) && replayingOf(items, workflow.name, digest).length === 0, deps.refused);
622
632
  if (reserved.won)
623
633
  for (const [i, one] of inputs.entries())
624
634
  await startReplay(deps, workflow, digest, one.run, one.launch, ids[i], launch);
@@ -699,7 +709,7 @@ export async function reserveSdkCheck(deps, turn) {
699
709
  workflow: flow.name, digest, at: iso(now()), decided: "replaying", via: "sdk",
700
710
  reason: `Checking it in the connected agent against an independent native turn before it can be reused: ${sdkTurnsWords(check)}.`,
701
711
  replay_id: id, runs: [turn.runId], inputs: [turn.runId], commit: revision, check,
702
- }, (was, current) => (own ? waitingSdk(was) && was.replay_id === own.replay_id : was === undefined) && blocking(current, flow.name, digest).length === 0);
712
+ }, (was, current) => (own ? waitingSdk(was) && was.replay_id === own.replay_id : was === undefined) && blocking(current, flow.name, digest).length === 0, deps.refused);
703
713
  if (reserved.won)
704
714
  return { id, revision, digest, workflow: flow };
705
715
  }
@@ -743,7 +753,7 @@ export async function sdkCheckTurn(deps, record, row, still, read = {}) {
743
753
  * as waiting: a turn's row (sdkCheckTurn) and a give-back (releaseSdkCheck). */
744
754
  function waitAgain(deps, record, check, reason, still = () => true) {
745
755
  const { runs: _runs, inputs: _inputs, ...rest } = record;
746
- return recordPromotion(deps.store.settings, deps.agentId, { ...rest, at: iso((deps.now ?? Date.now)()), check, reason }, (was, current) => still(was, current) && sameReplay(was, record) && heldTurn(was, record) && !overtaken(current, was));
756
+ return recordPromotion(deps.store.settings, deps.agentId, { ...rest, at: iso((deps.now ?? Date.now)()), check, reason }, (was, current) => still(was, current) && sameReplay(was, record) && heldTurn(was, record) && !overtaken(current, was), deps.refused);
747
757
  }
748
758
  /** A connected agent's check whose native turn did not settle it by REPLAY_DEADLINE_MS (the backend never completed the
749
759
  * turn, or the server stopped before the run's end): one failed row of its turns (sdkCheckTurn), as a managed check's
@@ -1052,7 +1062,7 @@ export async function askReplay(ask, name, digest, inputs) {
1052
1062
  throw new ReplayRefused("conflict", PROJECT_REPLAY_REFUSED);
1053
1063
  if (!launch.learning || launch.learning.noWorkflows)
1054
1064
  throw new ReplayRefused("conflict", `A replay runs ${name} as a run of the agent that learns does, and the agent's runs do not take learned workflows here (its learning is off, it takes no workflows, or this server's is off).`);
1055
- const deps = { store: ask.store, agentId: ask.agentId, revisionId, launch: { ...launch, learning: { ...launch.learning, seed: found.commit } }, context: ask.context, log: ask.log, shown: ask.shown, ...(ask.admitAuxiliary ? { admitAuxiliary: ask.admitAuxiliary } : {}), ...(ask.now ? { now: ask.now } : {}) };
1065
+ const deps = { store: ask.store, agentId: ask.agentId, revisionId, launch: { ...launch, learning: { ...launch.learning, seed: found.commit } }, context: ask.context, log: ask.log, shown: ask.shown, refused: refusedIn(ask.folder, ask.store, ask.log), ...(ask.admitAuxiliary ? { admitAuxiliary: ask.admitAuxiliary } : {}), ...(ask.now ? { now: ask.now } : {}) };
1056
1066
  const bar = { ...loop, attempt: attemptOf(records, name, digest) };
1057
1067
  const said = `checking it on ${plural(picked.length, "input")} of the agent's own runs, as its owner asked`;
1058
1068
  // Kept only while the revision's newest record is still the one read here: each record write stamps a new `at`.
@@ -117,6 +117,8 @@ interface ClaimReads {
117
117
  };
118
118
  readonly claimed: NodeJS.ProcessEnv;
119
119
  readonly signal?: AbortSignal;
120
+ /** The runner's presence incarnation (LoopDeps.incarnation): with the claim's runner, who keeps a computer a park pins. */
121
+ readonly incarnation?: string;
120
122
  }
121
123
  /** Held (held.ts) for one claim, on the runner: each answer the claim's own, read with the runner's seal key from the
122
124
  * runner's own reads of the claim; every argument from the run's process is checked or ignored. `bigs`: the run's pieced
@@ -22,7 +22,8 @@ import { putLiveViewer, dropLiveViewer } from "../browser-live.js";
22
22
  import { CALENDAR_EVENTS } from "../calendar/names.js";
23
23
  import { openCalendar } from "../calendar/address.js";
24
24
  import { openAccount } from "../email/account.js";
25
- import { harnessOf, recipeHarness } from "../harness-table.js";
25
+ import { harnessOf, recipeHarness, recipeKeysOf } from "../harness-table.js";
26
+ import { openHarnessKeys } from "../harness-keys.js";
26
27
  import { installDirOf, installForClaim, shareInstall } from "../harness-install.js";
27
28
  import { loadArchilSettings } from "../archil-settings.js";
28
29
  import { planOf } from "../chatgpt-plan.js";
@@ -31,7 +32,7 @@ import { vendorsOver } from "../sign-ins.js";
31
32
  import { decisionProvidersIn, fauxFetch } from "../decisions.js";
32
33
  import { DECISION_PROVIDER_KEYS } from "../tool-plane.js";
33
34
  import { learningEndOfRun } from "./learning-end.js";
34
- import { cutDeep, heldRedactor, runnerSecrets } from "./redact.js";
35
+ import { cutDeep, runnerSecrets } from "./redact.js";
35
36
  import { storeSecrets } from "./store-secrets.js";
36
37
  import { FAUX_ENV, GATEWAY_KEY_ENV } from "../model.js";
37
38
  import { SAVED_GATEWAY_ENV, savedGatewayIn } from "../model-gateway.js";
@@ -709,7 +710,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
709
710
  mcp: (ask) => projectCall(async () => {
710
711
  const reach = await mcpReachOf(deps);
711
712
  const harness = { commit: (change) => change({ appendEntry: async (_conversation, entry) => void (await ask.appendRoot(dataOnly(entry))) }) };
712
- const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, work: () => runFolder(deps.data, run.agentId, claim.runId), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web: deps.evalFakes?.(run.agentId)?.web, slots: deps.saveSlots } });
713
+ const made = await mcpForClaim({ claim, store, sealKey, grants: granted, harness: harness, work: () => runFolder(deps.data, run.agentId, claim.runId), launchInput: launch.input, githubAppAccess: () => github(), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web: deps.evalFakes?.(run.agentId)?.web, slots: deps.saveSlots } });
713
714
  if (!made)
714
715
  return undefined;
715
716
  releases.push(() => made.release());
@@ -770,6 +771,13 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
770
771
  serverKeyless: () => serverKeyless(keys),
771
772
  // The zone alone, from the claim's own launch's trigger: the process never reads a trigger's row.
772
773
  runZone: () => runZone(store, launch.inputOrigin),
774
+ // The keys saved for the claim's own harness alone (harness-keys.ts), whatever the process names: none unless that
775
+ // harness is a plan-billed recipe on this runner's table, and never another harness's.
776
+ harnessKeys: async () => {
777
+ const harness = launch.harness ?? revision.body.harness;
778
+ const names = harness === undefined ? undefined : recipeKeysOf(deps.env, harness);
779
+ return harness !== undefined && names?.length ? openHarnessKeys(store, sealKey, harness, names) : {};
780
+ },
773
781
  liveViewerPut: (handover) => putLiveViewer(store, sealKey, claim, handover),
774
782
  liveViewerDrop: (tag) => dropLiveViewer(store, claim, tag),
775
783
  // The claim's own run, whatever the process names: its view on this runner hears the change.
@@ -804,7 +812,7 @@ export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
804
812
  ? await openRunWorkspace({ mode: 1, agentId: run.agentId, runId: claim.runId, data: deps.data, log })
805
813
  : await openRunWorkspace({ mode: 2, agentId: run.agentId, runId: claim.runId, archil: made, log });
806
814
  const say = typeof ask.say === "function" ? ask.say : undefined;
807
- const got = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, claim, agentId: run.agentId, revisionId: run.revisionId, place: launch.place }, store, {
815
+ const got = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, claim, agentId: run.agentId, revisionId: run.revisionId, place: launch.place, ...(reads.incarnation ? { holder: { runner: claim.runner, incarnation: reads.incarnation } } : {}) }, store, {
808
816
  ...deps.computerDeps, mode, workspace: ws.workspace, sealKey,
809
817
  recordings: { folder: recordingsFolder(deps.data, run.agentId, claim.runId), say: (words) => say?.(cut(words)) },
810
818
  hadComputer: async () => (await ask.hadComputer()) === true,
@@ -1021,10 +1029,11 @@ export { RECIPE_SIGN_IN_PERSON_ONLY } from "./harness-loops.js";
1021
1029
  export async function staysInRunner(deps, harness, launch, runId, isolation) {
1022
1030
  // A recipe's harness reads its install, its check's note and its owner's sign-in, each the server user's alone: never
1023
1031
  // opened to a slot's user (the sign-in least of all), so where each run is a user of its own it is refused here. And a
1024
- // plan-billed one's run that no person started (a schedule's, a trigger's) never runs on its owner's sign-in.
1032
+ // plan-billed one's run that no person started (a schedule's, a trigger's) never runs on its owner's sign-in: only on
1033
+ // keys saved for its harness.
1025
1034
  if (isolation.kind === "uid" && recipeHarness(deps.env ?? {}, harness))
1026
1035
  throw new ClaimRefused(RECIPE_NEEDS_SERVER_USER);
1027
- refuseRecipeTriggerRun(deps.env ?? {}, harness, launch);
1036
+ await refuseRecipeTriggerRun(deps, harness, launch);
1028
1037
  if (runsInRunner(harness, launch))
1029
1038
  return true;
1030
1039
  if (launch.documents !== undefined) {
@@ -1165,10 +1174,10 @@ function childLoop(options, slots, loopDeps) {
1165
1174
  }
1166
1175
  const savedGateway = savedGatewayIn(claimEnv);
1167
1176
  // The run's own keys: those its claim opens (claim-secrets.ts), the one list its loop in this process read.
1168
- const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv, redact: loopDeps.redact ? heldRedactor(loopDeps.redact) : undefined }, revisionRow, launch, claim.runId);
1177
+ const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv, redact: loopDeps.redact }, revisionRow, launch, claim.runId);
1169
1178
  // With them, its revision's own model's (a launch pinned at its start to another model, a --faux start's, is still
1170
1179
  // handed its agent's model's key, as a run's own process was handed it before: run-secrets.ts secretsFor).
1171
- const ofRevision = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }, revisionRow, { ...(launch.plane ? { plane: launch.plane } : {}) });
1180
+ const ofRevision = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv, redact: loopDeps.redact }, revisionRow, { ...(launch.plane ? { plane: launch.plane } : {}) });
1172
1181
  // A run that holds a model key of its own (model_key, its launch's) spends that key alone: its process is handed
1173
1182
  // none of the server's model keys, as its spec drops them from its tools' (claim-secrets.ts withoutModelKeys).
1174
1183
  // Copies: the runner's own reads (heldFor's `claimed`: what the run's learning must never keep) stay whole.
@@ -1204,7 +1213,7 @@ function childLoop(options, slots, loopDeps) {
1204
1213
  const tops = runTops(deps.data, runRow.agentId, claim.runId);
1205
1214
  // The run's pieced writes (big-writes.ts): let go when its channel ends, or at the claim's release.
1206
1215
  const bigs = runBigWrites();
1207
- const heldSide = heldFor({ ...deps, env: claimEnv }, { claim, run: runRow, launch, revision, claimed: gatewayKey ? withGatewayKey(claimed, gatewayKey) : claimed, signal: loopDeps.signal }, cut, log, bigs);
1216
+ const heldSide = heldFor({ ...deps, env: claimEnv }, { claim, run: runRow, launch, revision, claimed: gatewayKey ? withGatewayKey(claimed, gatewayKey) : claimed, signal: loopDeps.signal, ...(loopDeps.incarnation ? { incarnation: loopDeps.incarnation } : {}) }, cut, log, bigs);
1208
1217
  try {
1209
1218
  let extra = {};
1210
1219
  let argv = [...(options.argv ?? childArgv())];
@@ -1277,6 +1286,7 @@ function childLoop(options, slots, loopDeps) {
1277
1286
  ...(deps.githubApi ? { githubApi: deps.githubApi } : {}),
1278
1287
  ...(deps.githubWeb ? { githubWeb: deps.githubWeb } : {}),
1279
1288
  ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}),
1289
+ ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}),
1280
1290
  };
1281
1291
  const ended = channel.call("loop", "start", [init]);
1282
1292
  // From here a command or a stop goes to the run's process, after its start on the channel.
@@ -185,6 +185,7 @@ function childDeps(init, store, journal, held) {
185
185
  ...(init.githubApi ? { githubApi: init.githubApi } : {}),
186
186
  ...(init.githubWeb ? { githubWeb: init.githubWeb } : {}),
187
187
  ...(init.githubMcpOrigin ? { githubMcpOrigin: init.githubMcpOrigin } : {}),
188
+ ...(init.composioMcpOrigin ? { composioMcpOrigin: init.composioMcpOrigin } : {}),
188
189
  ...(init.mcpLoopback ? { mcpLoopback: true, mcpOwn: init.mcpOwn ?? [] } : {}),
189
190
  };
190
191
  }
@@ -215,7 +216,8 @@ channel.expose("loop", async (method, args) => {
215
216
  live: (reader) => void (read = reader),
216
217
  redact: heldRedactor(processSecretRedactor()),
217
218
  };
218
- loop = createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) })(loopDeps);
219
+ // Its runner counted the harness's key rows before it made this process (staysInRunner): never again here.
220
+ loop = createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps, { keysCounted: true }) })(loopDeps);
219
221
  made(loop);
220
222
  // The loop's held state and whether a plain stop keeps its computer, posted when either moved.
221
223
  let last = "";
@@ -197,6 +197,10 @@ export type RunnerEvent = {
197
197
  export type HandBackCause = "drain" | "interrupted" | "end_retry" | "give_back";
198
198
  export interface Runner {
199
199
  readonly name: string;
200
+ /** The incarnation of its word in the store (presence.ts: its caller's, else its own), which its loops hand each claim's
201
+ * computer (LoopDeps.incarnation): a computer a park keeps pinned to this runner names it. Absent with no store
202
+ * runners, where no word is kept. */
203
+ readonly incarnation?: string;
200
204
  /** The claims this runner holds and has not lost. */
201
205
  held(): Claim[];
202
206
  /** Stops claiming, lets each held run go on to its own end for up to drainMs, then stops every loop left where it can