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

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 (275) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/README.md +201 -52
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +15 -3
  5. package/dist/adapters.js +17 -6
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/api-keys.d.ts +76 -0
  9. package/dist/api-keys.js +217 -0
  10. package/dist/api-only.d.ts +17 -5
  11. package/dist/api-only.js +34 -8
  12. package/dist/browser-hold.d.ts +23 -0
  13. package/dist/browser-hold.js +48 -0
  14. package/dist/browser-person.d.ts +3 -0
  15. package/dist/browser-person.js +4 -1
  16. package/dist/chatgpt-plan.d.ts +18 -8
  17. package/dist/chatgpt-plan.js +91 -34
  18. package/dist/claude-login.d.ts +74 -16
  19. package/dist/claude-login.js +215 -56
  20. package/dist/claude-sign-in.d.ts +17 -6
  21. package/dist/claude-sign-in.js +42 -39
  22. package/dist/cli.js +63 -6
  23. package/dist/composio-made.d.ts +4 -0
  24. package/dist/composio-made.js +4 -0
  25. package/dist/composio-preset.d.ts +43 -2
  26. package/dist/composio-preset.js +92 -4
  27. package/dist/computer-held-routes.d.ts +5 -4
  28. package/dist/computer-held-routes.js +29 -8
  29. package/dist/computer-held.d.ts +6 -1
  30. package/dist/computer-held.js +14 -0
  31. package/dist/computer-record.js +4 -2
  32. package/dist/computer-viewer.js +4 -1
  33. package/dist/console/assets/{backend-Boh7tC4i.js → backend-DVhHzJX2.js} +19 -19
  34. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  35. package/dist/console/assets/index-okP-y8PK.js +747 -0
  36. package/dist/console/index.html +2 -2
  37. package/dist/decisions.d.ts +1 -1
  38. package/dist/decisions.js +1 -1
  39. package/dist/docker-host-addresses.d.ts +22 -11
  40. package/dist/docker-host-addresses.js +38 -26
  41. package/dist/env-switch.d.ts +10 -0
  42. package/dist/env-switch.js +33 -2
  43. package/dist/errors.d.ts +1 -0
  44. package/dist/errors.js +2 -0
  45. package/dist/fal-price.d.ts +58 -20
  46. package/dist/fal-price.js +341 -82
  47. package/dist/handed-values.d.ts +43 -1
  48. package/dist/handed-values.js +119 -2
  49. package/dist/harness-archive.d.ts +13 -10
  50. package/dist/harness-archive.js +60 -34
  51. package/dist/harness-check.d.ts +3 -1
  52. package/dist/harness-check.js +25 -46
  53. package/dist/harness-keys.d.ts +73 -27
  54. package/dist/harness-keys.js +194 -61
  55. package/dist/harness-recipe-entry.d.ts +8 -7
  56. package/dist/harness-recipe-entry.js +21 -32
  57. package/dist/harness-recipe.d.ts +38 -25
  58. package/dist/harness-recipe.js +49 -36
  59. package/dist/harness-sign-in.js +12 -23
  60. package/dist/harness-table.d.ts +10 -3
  61. package/dist/harness-table.js +26 -21
  62. package/dist/harness.d.ts +1 -0
  63. package/dist/harness.js +17 -5
  64. package/dist/hosted-search.d.ts +1 -1
  65. package/dist/hosted-search.js +1 -2
  66. package/dist/import-worker.d.ts +4 -2
  67. package/dist/import-worker.js +9 -2
  68. package/dist/in-flight.d.ts +26 -0
  69. package/dist/in-flight.js +52 -0
  70. package/dist/key-refusal.d.ts +9 -4
  71. package/dist/key-refusal.js +107 -25
  72. package/dist/learn/secrets.d.ts +13 -3
  73. package/dist/learn/secrets.js +118 -17
  74. package/dist/learning-cost.d.ts +6 -3
  75. package/dist/learning-cost.js +4 -2
  76. package/dist/link-check.js +1 -1
  77. package/dist/llms.txt +1 -1
  78. package/dist/marketplace.d.ts +77 -0
  79. package/dist/marketplace.js +224 -0
  80. package/dist/mcp-api-only-origins.d.ts +30 -0
  81. package/dist/mcp-api-only-origins.js +57 -0
  82. package/dist/mcp-gateway.d.ts +7 -5
  83. package/dist/mcp-gateway.js +9 -12
  84. package/dist/mcp-secret-writes.js +5 -3
  85. package/dist/mcp-servers-store.d.ts +28 -6
  86. package/dist/mcp-servers-store.js +53 -4
  87. package/dist/media-duration.d.ts +3 -0
  88. package/dist/media-duration.js +90 -9
  89. package/dist/model-form.d.ts +5 -4
  90. package/dist/model-form.js +11 -7
  91. package/dist/model.d.ts +5 -2
  92. package/dist/model.js +9 -5
  93. package/dist/ollama-provider.d.ts +7 -1
  94. package/dist/ollama-provider.js +14 -2
  95. package/dist/openapi.js +178 -27
  96. package/dist/otel/genai.d.ts +65 -0
  97. package/dist/otel/genai.js +116 -0
  98. package/dist/otel/tracer.d.ts +55 -0
  99. package/dist/otel/tracer.js +308 -0
  100. package/dist/page.d.ts +2 -0
  101. package/dist/page.js +3 -1
  102. package/dist/paid-calls.d.ts +1 -32
  103. package/dist/paid-calls.js +4 -39
  104. package/dist/provider.d.ts +9 -0
  105. package/dist/provider.js +50 -3
  106. package/dist/redact/match.d.ts +30 -3
  107. package/dist/redact/match.js +422 -41
  108. package/dist/refusal-words.d.ts +11 -0
  109. package/dist/refusal-words.js +11 -0
  110. package/dist/run-census.d.ts +67 -0
  111. package/dist/run-census.js +240 -0
  112. package/dist/run-computer.d.ts +6 -3
  113. package/dist/run-computer.js +4 -1
  114. package/dist/run-cut.d.ts +15 -6
  115. package/dist/run-cut.js +30 -9
  116. package/dist/run-files.d.ts +3 -0
  117. package/dist/run-files.js +3 -0
  118. package/dist/run-launch.d.ts +12 -1
  119. package/dist/run-launch.js +9 -10
  120. package/dist/run-learning-served.d.ts +2 -0
  121. package/dist/run-model-key.d.ts +8 -0
  122. package/dist/run-model-key.js +31 -1
  123. package/dist/run-reads-over-store.d.ts +24 -6
  124. package/dist/run-reads-over-store.js +67 -23
  125. package/dist/run-recordings.d.ts +5 -1
  126. package/dist/run-recordings.js +39 -14
  127. package/dist/run-timeline-served.d.ts +2 -0
  128. package/dist/run-timeline-served.js +2 -2
  129. package/dist/run-usage.d.ts +1 -0
  130. package/dist/runnable.d.ts +10 -1
  131. package/dist/runnable.js +20 -8
  132. package/dist/runner/adapter-loop.d.ts +11 -0
  133. package/dist/runner/adapter-loop.js +55 -10
  134. package/dist/runner/adapter-run-spec.d.ts +45 -8
  135. package/dist/runner/adapter-run-spec.js +150 -28
  136. package/dist/runner/adapters/pi.js +25 -3
  137. package/dist/runner/beside.js +4 -3
  138. package/dist/runner/big-writes.js +1 -10
  139. package/dist/runner/claim-secrets.d.ts +18 -3
  140. package/dist/runner/claim-secrets.js +35 -6
  141. package/dist/runner/cli-run-spec.d.ts +6 -0
  142. package/dist/runner/cli-run-spec.js +82 -35
  143. package/dist/runner/computer-journal.d.ts +9 -1
  144. package/dist/runner/computer-journal.js +26 -0
  145. package/dist/runner/conformance/harness.js +1 -1
  146. package/dist/runner/feedback-round.js +3 -0
  147. package/dist/runner/harness-loops.d.ts +6 -5
  148. package/dist/runner/harness-loops.js +7 -7
  149. package/dist/runner/held.d.ts +11 -5
  150. package/dist/runner/journal-kinds.d.ts +5 -0
  151. package/dist/runner/journal-kinds.js +5 -0
  152. package/dist/runner/main.js +7 -2
  153. package/dist/runner/mcp-claim.js +30 -3
  154. package/dist/runner/mcp-run.d.ts +12 -0
  155. package/dist/runner/mcp-run.js +12 -5
  156. package/dist/runner/model-route.d.ts +17 -0
  157. package/dist/runner/model-route.js +120 -2
  158. package/dist/runner/run-child-host.d.ts +3 -0
  159. package/dist/runner/run-child-host.js +69 -28
  160. package/dist/runner/run-child.js +5 -2
  161. package/dist/runner/runner.d.ts +14 -3
  162. package/dist/runner/runner.js +129 -33
  163. package/dist/runner/store-port.d.ts +1 -1
  164. package/dist/runner/store-secrets.d.ts +6 -0
  165. package/dist/runner/store-secrets.js +49 -7
  166. package/dist/runner/subagent.js +4 -40
  167. package/dist/runner/workflow-first.d.ts +11 -4
  168. package/dist/runner/workflow-first.js +14 -8
  169. package/dist/runner/workflow-spec.js +3 -2
  170. package/dist/runs-over-store.d.ts +15 -6
  171. package/dist/runs-over-store.js +33 -21
  172. package/dist/scrub-command.d.ts +73 -0
  173. package/dist/scrub-command.js +307 -0
  174. package/dist/secret-cut.d.ts +73 -0
  175. package/dist/secret-cut.js +291 -4
  176. package/dist/secret-rules.d.ts +143 -0
  177. package/dist/secret-rules.js +2564 -0
  178. package/dist/secrets.d.ts +7 -0
  179. package/dist/secrets.js +20 -0
  180. package/dist/server-keys.d.ts +20 -0
  181. package/dist/server-keys.js +25 -6
  182. package/dist/server.d.ts +52 -11
  183. package/dist/server.js +345 -118
  184. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  185. package/dist/store/index.d.ts +1 -1
  186. package/dist/store/index.js +1 -1
  187. package/dist/store/journal/storage.js +1 -1
  188. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  189. package/dist/store/schema.d.ts +6 -0
  190. package/dist/store/schema.js +11 -1
  191. package/dist/store/seal.d.ts +6 -1
  192. package/dist/store/seal.js +5 -3
  193. package/dist/store/sqlite/run-launch.d.ts +9 -1
  194. package/dist/store/sqlite/run-launch.js +24 -13
  195. package/dist/store/sqlite/run-patch.d.ts +1 -1
  196. package/dist/store/sqlite/run-patch.js +13 -4
  197. package/dist/store/sqlite/store.js +34 -4
  198. package/dist/store/store.d.ts +43 -2
  199. package/dist/store/store.js +20 -0
  200. package/dist/store-reads/learning.d.ts +6 -3
  201. package/dist/store-reads/learning.js +22 -7
  202. package/dist/store-view.d.ts +3 -0
  203. package/dist/store-view.js +3 -3
  204. package/dist/suggestions.js +3 -2
  205. package/dist/template-eval.d.ts +20 -9
  206. package/dist/template-eval.js +115 -33
  207. package/dist/template-import.d.ts +10 -0
  208. package/dist/template-import.js +16 -7
  209. package/dist/templates.d.ts +10 -2
  210. package/dist/templates.js +28 -8
  211. package/dist/timeline/labels.d.ts +6 -4
  212. package/dist/timeline/labels.js +18 -6
  213. package/dist/timeline/timeline.d.ts +5 -0
  214. package/dist/timeline/timeline.js +14 -8
  215. package/dist/timeline/util.js +1 -1
  216. package/dist/timeline/web-calls.d.ts +26 -9
  217. package/dist/timeline/web-calls.js +124 -37
  218. package/dist/tool-gate.d.ts +42 -3
  219. package/dist/tool-gate.js +66 -5
  220. package/dist/tool-keys-store.d.ts +2 -4
  221. package/dist/tool-keys-store.js +5 -21
  222. package/dist/tool-keys.d.ts +2 -2
  223. package/dist/tool-keys.js +2 -2
  224. package/dist/tool-list.js +1 -1
  225. package/dist/tool-plane.d.ts +2 -2
  226. package/dist/tool-plane.js +35 -33
  227. package/dist/tools.js +13 -7
  228. package/dist/trigger-targets.d.ts +4 -0
  229. package/dist/trigger-targets.js +9 -2
  230. package/dist/triggers.d.ts +67 -4
  231. package/dist/triggers.js +171 -22
  232. package/dist/until.d.ts +3 -0
  233. package/dist/until.js +11 -0
  234. package/dist/web-fake.d.ts +1 -3
  235. package/dist/web-fake.js +7 -18
  236. package/dist/web-fetch.d.ts +6 -72
  237. package/dist/web-fetch.js +11 -265
  238. package/dist/web-run.d.ts +31 -0
  239. package/dist/web-run.js +90 -0
  240. package/dist/web-save.d.ts +6 -4
  241. package/dist/web-save.js +9 -12
  242. package/dist/web-search.d.ts +9 -127
  243. package/dist/web-search.js +23 -259
  244. package/dist/wires.d.ts +13 -0
  245. package/dist/wires.js +11 -0
  246. package/dist/workflow-run.d.ts +5 -4
  247. package/dist/workflow-run.js +5 -4
  248. package/dist/workspace/computer-deps.d.ts +2 -1
  249. package/dist/workspace/computer-deps.js +9 -2
  250. package/dist/workspace/computer-for-claim.d.ts +12 -1
  251. package/dist/workspace/computer-for-claim.js +77 -8
  252. package/dist/workspace/computer-kept.d.ts +3 -0
  253. package/dist/workspace/computer-kept.js +11 -2
  254. package/dist/workspace/index.d.ts +1 -1
  255. package/dist/workspace/index.js +1 -1
  256. package/dist/workspace/kind-skills.d.ts +4 -0
  257. package/dist/workspace/kind-skills.js +9 -0
  258. package/dist/workspace/synced-folder.js +3 -4
  259. package/dist/wrapped.d.ts +13 -5
  260. package/dist/wrapped.js +52 -26
  261. package/package.json +17 -11
  262. package/skills/agentrun-serve/SKILL.md +4 -0
  263. package/templates/README.md +30 -8
  264. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  265. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  266. package/dist/exa-keyless.d.ts +0 -34
  267. package/dist/exa-keyless.js +0 -118
  268. package/dist/firecrawl-keyless.d.ts +0 -41
  269. package/dist/firecrawl-keyless.js +0 -152
  270. package/dist/keyless-mcp.d.ts +0 -36
  271. package/dist/keyless-mcp.js +0 -127
  272. package/dist/text-urls.d.ts +0 -38
  273. package/dist/text-urls.js +0 -170
  274. package/dist/web-fetch-direct.d.ts +0 -119
  275. package/dist/web-fetch-direct.js +0 -190
@@ -26,9 +26,16 @@ const CANDIDATES = [...new Set([...RUN_SECRETS, ...DECISION_KEYS])];
26
26
  /** The environment a claimed run's tools run under: the runner's base (its secrets stripped), with the keys the run's
27
27
  * revision needs read from the store on top — the tool keys its tools unlock, the model keys its model needs, and its
28
28
  * decision provider keys — and, for claim `runId`, the run's own tool keys its revision declares (run-keys.ts) over the
29
- * server's by the same name. A fresh object per claim, so no run's keys reach another's. `redact`: the runner's one
29
+ * server's by the same name. Its model keys are readable by name and never enumerable (MODEL_KEY_NAMES): its model
30
+ * routes read them by name (claimModelEnv), and a spread or a spawn of the tools' environment carries none. A fresh
31
+ * object per claim, so no run's keys reach another's. `redact`: the runner's one
30
32
  * redactor, which the run's own tool keys are carried into before they are laid, so its journal is cut of them as it is
31
- * written (no one holds them after the turn); a plain JS caller that passes none lays no run key, and throws. */
33
+ * written (no one holds them after the turn); a plain JS caller that passes none lays no run key, and throws. A held run
34
+ * its model kept from running at its create (hold.refused) is laid no model key and no plan sign-in: its model runs
35
+ * nowhere. Its tools' keys, its decision keys and its own tool keys are laid as any run's. The one tool key row that names
36
+ * a model key's name, TypeSafe's (key-words.ts; model.ts PROVIDER_KEYS typesafe), is a decision key (secrets.ts
37
+ * DECISION_KEYS): keysFor never names one, so the model key filter below never sees it, and decisionKeysFor lays it
38
+ * apart, as it lays OpenRouter's for a decision node that runs on it. */
32
39
  export async function claimSecrets(deps, revision, launch, runId) {
33
40
  const base = withoutSecrets(deps.env ?? {});
34
41
  const working = await workingEnv(deps);
@@ -37,16 +44,20 @@ export async function claimSecrets(deps, revision, launch, runId) {
37
44
  // the host's default now: a key saved since the run started (another provider's, now first) would otherwise be opened
38
45
  // in its place, and the run would hold a key its model never sends and lack the one it does.
39
46
  const scoped = launch.model && !needs.tiers ? { ...needs, model: `${launch.model.provider}/${launch.model.modelId}` } : needs;
47
+ const modelRefused = launch.hold?.refused !== undefined;
40
48
  const env = { ...base };
41
49
  // The key of a gateway saved in the console (model-gateway.ts) stays on the run environment its model routes read, never
42
50
  // on the tools': it is read there by name alone (claimModelEnv), as a run's own model key is.
43
51
  const savedGateway = savedGatewayIn(deps.env ?? {});
52
+ // A model key is never enumerable, as withModelKeys lays a route's, but unlike a route's it stays writable and deletable
53
+ // (withoutModelKeys drops it); a tool key is a plain value, which its tools read and hand on.
44
54
  for (const name of keysFor(scoped, working))
45
- if (working[name] !== undefined && !(savedGateway && name === GATEWAY_KEY_ENV))
46
- env[name] = working[name];
55
+ if (working[name] !== undefined && !(savedGateway && name === GATEWAY_KEY_ENV) && !(modelRefused && MODEL_KEY_NAMES.includes(name)))
56
+ Object.defineProperty(env, name, { value: working[name], enumerable: !MODEL_KEY_NAMES.includes(name), writable: true, configurable: true });
47
57
  const decision = decisionKeysFor(working, { providers: needs.decisionProviders, parallelWeb: launch.plane ? handsParallel(launch.plane) : false });
58
+ // A decision key is a plain value, as before, under a model key's name too (OpenRouter's, which Jev's nodes use).
48
59
  for (const [name, value] of Object.entries(decision))
49
- env[name] = value;
60
+ Object.defineProperty(env, name, { value, enumerable: true, writable: true, configurable: true });
50
61
  // The run's own tool keys, sealed with its launch: each one its revision declares, over the server's by the same name.
51
62
  // Opened by a runner, which holds the seal key; a run's own process is handed them with the rest of its claim's keys.
52
63
  if (runId !== undefined && deps.sealKey && deps.store.runs) {
@@ -65,7 +76,7 @@ export async function claimSecrets(deps, revision, launch, runId) {
65
76
  // proxy sends (chatgpt-plan.ts), never put on the environment its tools run under (a symbol no spawn copies). Only for
66
77
  // a run that can reach a plan model: one pinned to a key's model (and its tiers on keys) never holds the sign-in, which
67
78
  // renews and spends the person's plan for any process that holds it.
68
- const plan = await planReaderOf(deps.store, deps.sealKey);
79
+ const plan = modelRefused ? undefined : await planReaderOf(deps.store, deps.sealKey);
69
80
  return plan && reachesPlan(withPlan({ ...working }, plan), scoped, revision) ? withPlan(env, plan) : env;
70
81
  }
71
82
  const onPlan = (model) => model?.startsWith(`${PLAN_PROVIDER}/`) === true;
@@ -211,6 +222,19 @@ export async function savedModelKeys(deps) {
211
222
  }
212
223
  return out;
213
224
  }
225
+ /** Of `saved` (savedModelKeys'), the keys a route to `model` (`provider/model-id`) reads and no other: its provider's
226
+ * (PROVIDER_KEYS), or through a gateway (`env`'s AGENT_MODEL_BASE_URL, as modelKeys reads it) the gateway's key alone.
227
+ * None for no model, or one whose provider names no key. What a runner hands a run's process for one route of its
228
+ * (run-child-host.ts savedModelKeys): never every key the server holds. */
229
+ export function routeModelKeys(saved, env, model) {
230
+ const out = {};
231
+ if (model === undefined)
232
+ return out;
233
+ for (const name of modelKeys(env, model))
234
+ if (saved[name] !== undefined)
235
+ out[name] = saved[name];
236
+ return out;
237
+ }
214
238
  /** How many times fresh() reads a run's launch before it gives up, and the first wait between reads (doubled each time). */
215
239
  const FRESH_TRIES = 3;
216
240
  const FRESH_WAIT_MS = 50;
@@ -344,3 +368,8 @@ export function withoutModelKeys(toolEnv) {
344
368
  delete toolEnv[name];
345
369
  return toolEnv;
346
370
  }
371
+ /** `under` and `over` as one set of opened keys for claimModelEnv, `over`'s value winning by name: every property as it
372
+ * is, so a claim's model keys (claimSecrets: never enumerable), which a spread would drop, reach the route. */
373
+ export function keysOver(under, over) {
374
+ return Object.defineProperties({}, { ...Object.getOwnPropertyDescriptors(under), ...Object.getOwnPropertyDescriptors(over) });
375
+ }
@@ -1,6 +1,7 @@
1
1
  import { type CapModel } from "@parcha/agentrun-kernel/kernel/cap";
2
2
  import { type AdapterFacts } from "@parcha/agentrun-kernel";
3
3
  import { type HarnessEntry } from "../harness-table.js";
4
+ import { type ModelRef } from "../model.js";
4
5
  import { type RunLaunch } from "../run-launch.js";
5
6
  import { type AdapterRun, type AdapterRunSpec } from "./adapter-loop.js";
6
7
  import { type AdapterSpecDeps } from "./adapter-run-spec.js";
@@ -13,6 +14,11 @@ export type { ClaimComputer, ClaimDeps, ClaimLaunch, ComputerForClaim } from "./
13
14
  export type CliSpecDeps = AdapterSpecDeps;
14
15
  /** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
15
16
  export declare const cliRefusesKind: (kind: string) => string | undefined;
17
+ /** A harness's facts for a run on `model`: on a model the route translates onto its wire (an Ollama model), its own tool
18
+ * search is not its (AdapterFacts.ownToolSearch dropped): what it sends (deferred tools, a tool search's references) is
19
+ * the provider's to read, and the translation's model has none. The host's own tools_search and tools_call are offered
20
+ * in its place, as to a harness with none of its own. */
21
+ export declare const factsOn: <T extends AdapterFacts | undefined>(facts: T, model: ModelRef) => T;
16
22
  /** The model a CLI run is capped at: the catalog entry that bills it (its entry's priceModel), its cost WITH TIERS (the
17
23
  * money rule: a request past a tier is held and booked at it, as main's calculateCost does), on the harness's wire. A
18
24
  * model the catalog does not price is held at no price: its requests are unknown, never $0. A ChatGPT plan's model
@@ -20,21 +20,22 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
20
20
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
21
21
  import { checkRaise, followUpOf, freeRequestLimitOf, maxRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
22
22
  import { PLAN_LIMIT_WORDS } from "@parcha/agentrun-kernel";
23
- import { modelWire } from "../wires.js";
24
- import { confineOf, noNewPrivsPrefix, standsIn, thinkingFor } from "../adapters.js";
23
+ import { modelWire, routed } from "../wires.js";
24
+ import { confineOf, noNewPrivsPrefix, ownSearchRuns, standsIn, thinkingFor } from "../adapters.js";
25
25
  import { claimSettled, claudeCliIn, installDirOf, installForClaim, installingWords } from "../harness-install.js";
26
26
  import { HarnessUnavailable } from "../provider.js";
27
27
  import { effortGuidance } from "../effort-guidance.js";
28
28
  import { outputContract } from "../answer-json.js";
29
29
  import { wireName } from "../catalog.js";
30
30
  import { environmentLine, runZone } from "../environment.js";
31
- import { factsOf, harnessOf, recipeKeysOf } from "../harness-table.js";
31
+ import { factsOf, harnessOf, planRecipeOf } from "../harness-table.js";
32
32
  import { layHarnessKeys, openHarnessKeys, RECIPE_SIGN_IN_PERSON_ONLY, RECIPE_TURN_PERSON_ONLY } from "../harness-keys.js";
33
33
  import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
34
34
  import { laidOf, layLearningSeed } from "./learning-seed.js";
35
35
  import { learningWorkspace } from "../learn/folder.js";
36
36
  import { learningEndOfRun, spentBesideOf } from "./learning-end.js";
37
37
  import { ollamaTagsOf, providerModels, runModels } from "../model.js";
38
+ import { OLLAMA_PROVIDER } from "../ollama-provider.js";
38
39
  import { firstMessage, inputMessage, messageText } from "../run-manifest.js";
39
40
  import { learningStartOf, personStarted, seedFailed } from "../run-launch.js";
40
41
  import { readsFiles, systemOf } from "../skills.js";
@@ -42,23 +43,24 @@ import { DATA_ENV } from "../server-fs.js";
42
43
  import { filesToCopy, placeRunInputs } from "../uploads.js";
43
44
  import { recordingsFolder, runFolder, scratchFolder } from "../workspace/paths.js";
44
45
  import { openRunWorkspace } from "../workspace/run-workspace.js";
46
+ import { withoutKindSkill } from "../workspace/kind-skills.js";
45
47
  import { layOwnSkills } from "../workspace/revision-skills.js";
46
48
  import { runTools, withKindTools } from "../workspace/run-tools.js";
47
49
  import { archilWhereHeld, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
48
50
  import { loadArchilSettings } from "../archil-settings.js";
49
51
  import { settingOfDefinition } from "../computer-setting.js";
50
52
  import { computerKeptWords, computerReadyWords, computerReplacedNote, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
51
- import { hadComputer } from "./computer-journal.js";
53
+ import { computerTurnedOff, hadComputer, recordComputerOff } from "./computer-journal.js";
52
54
  import { hostLifecycle } from "./adapter-loop.js";
53
- import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, claimLiveAt, graderRouteOf, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, mcpReachOf, modelAskOf, PI_WIRES, webHostTools } from "./adapter-run-spec.js";
55
+ import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, claimLiveAt, graderRouteOf, heldModelOf, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, mcpReachOf, modelAskOf, PI_WIRES, seedEvalFiles, webHostTools } from "./adapter-run-spec.js";
54
56
  import { openTierProxies } from "./adapters/pi.js";
55
57
  import { signInReads } from "../sign-ins-store.js";
56
58
  import { isWebHostTool } from "../tool-list.js";
57
59
  import { hostToolOf } from "../host-tools.js";
58
60
  import { ASK_TOOL, askPerson } from "../tools.js";
59
61
  import { fakedPlane } from "../web-fake.js";
60
- import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, tierModelKeys, underClaimed, withoutModelKeys } from "./claim-secrets.js";
61
- import { mcpWhereHeld } from "./mcp-run.js";
62
+ import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, keysOver, learnedDecisionKeys, tierModelKeys, underClaimed, withoutModelKeys } from "./claim-secrets.js";
63
+ import { claimMetering, mcpWhereHeld } from "./mcp-run.js";
62
64
  import { held as runnerSeam, heldSignInReads } from "./held.js";
63
65
  import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
64
66
  import { decisionProvidersIn } from "../decisions.js";
@@ -88,6 +90,7 @@ import { monidForClaim, withMonid } from "./monid-run.js";
88
90
  import { verifyPlacedProject, movedSkillFiles } from "../source-sync/claim.js";
89
91
  import { projectCheckpointForRun } from "./project-checkpoint.js";
90
92
  import { sourceAuxiliaryAdmitter } from "../source-sync/auxiliary.js";
93
+ import { routeTrace } from "../otel/genai.js";
91
94
  /** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
92
95
  export const cliRefusesKind = (kind) => kind === "browser" ? "This agent's computer is a browser, which only the pi harness drives here: pick pi for this agent, or another kind of computer in Settings → Computers." : undefined;
93
96
  /** The run's model and the catalog that prices it, as main chooses a CLI run's (app.ts wireModels and runModels): on the
@@ -107,6 +110,22 @@ async function modelsOf(entry, env, ref) {
107
110
  throw new Error(`${entry.id} has no model here.`);
108
111
  return { model: chosen.model, models: chosen.models, unpriced: chosen.unpriced };
109
112
  }
113
+ /** A held run's model, its model refused at its create (hold.refused): named as its revision names it (heldModelOf),
114
+ * chosen by nothing, in no catalog, unpriced. */
115
+ function heldChoice(ref) {
116
+ const model = heldModelOf(ref);
117
+ return { model, models: { getModel: () => undefined }, unpriced: new Set([model.modelId]) };
118
+ }
119
+ /** A harness's facts for a run on `model`: on a model the route translates onto its wire (an Ollama model), its own tool
120
+ * search is not its (AdapterFacts.ownToolSearch dropped): what it sends (deferred tools, a tool search's references) is
121
+ * the provider's to read, and the translation's model has none. The host's own tools_search and tools_call are offered
122
+ * in its place, as to a harness with none of its own. */
123
+ export const factsOn = (facts, model) => {
124
+ if (!facts?.ownToolSearch || !routed(facts.wire, model))
125
+ return facts;
126
+ const { ownToolSearch: _own, ...rest } = facts;
127
+ return rest;
128
+ };
110
129
  /** The model a CLI run is capped at: the catalog entry that bills it (its entry's priceModel), its cost WITH TIERS (the
111
130
  * money rule: a request past a tier is held and booked at it, as main's calculateCost does), on the harness's wire. A
112
131
  * model the catalog does not price is held at no price: its requests are unknown, never $0. A ChatGPT plan's model
@@ -132,7 +151,10 @@ export function capModelOf(id, wire, listed, unpriced, plan = false) {
132
151
  function chosenCapModel(entry, env, chosen, wire) {
133
152
  const priced = entry.priceModel(env, chosen.model);
134
153
  const listed = chosen.models.getModel(priced.provider, priced.modelId);
135
- return capModelOf(priced.modelId, wire, listed, chosen.unpriced.has(priced.modelId) || listed === undefined, priced.provider === PLAN_PROVIDER || priced.provider === CLAUDE_LOGIN_PROVIDER || !modelWire(wire));
154
+ const capped = capModelOf(priced.modelId, wire, listed, chosen.unpriced.has(priced.modelId) || listed === undefined, priced.provider === PLAN_PROVIDER || priced.provider === CLAUDE_LOGIN_PROVIDER || !modelWire(wire));
155
+ // A model of this machine's own Ollama (the route's translation, provider.ts routedProvider): its requests never count
156
+ // toward the run's free-model limit, as pi's on the same route do (model-route.ts ModelRoute.local).
157
+ return priced.provider === OLLAMA_PROVIDER ? { ...capped, local: true } : capped;
136
158
  }
137
159
  /** The model a run of the CLI harness `entry` on `ref` (a revision's model; none, this host's default for it) is capped
138
160
  * at here, as its run's spec prices it (modelsOf, chosenCapModel), before any run: a save's cap warning (cap-short.ts)
@@ -337,7 +359,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
337
359
  // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
338
360
  const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
339
361
  redact.hold(values); };
340
- const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, capped: launch.maxCostUsd !== undefined, media: { env: deps.env, web, slots: deps.saveSlots } });
362
+ const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, runRow.agentId, launch) });
341
363
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
342
364
  holds.hold({ passed: mcp });
343
365
  // The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
@@ -369,6 +391,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
369
391
  // A run's own process copies nothing: its runner placed them before the process started (run-child-host.ts).
370
392
  if (!(deps.sealKey === undefined && runnerSeam()))
371
393
  await placeRunInputs(deps.data, claim.runId, ws.workspace, filesToCopy(launch), messageText(launch.input));
394
+ await seedEvalFiles(ws.workspace, fakes?.files);
372
395
  // The run's skills and its learning seed laid before its computer exists, as the pi spec lays them (adapter-run-spec.ts):
373
396
  // on Archil the computer's mount takes the disk's write delegation, and a lay over the disk's file API after it is
374
397
  // refused (409) while the mount holds it.
@@ -388,6 +411,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
388
411
  // The run's computer, from the one shared claim-time function (the pi spec takes the same): none for a runner place.
389
412
  // It throws computer_unavailable (nothing made) when the computer cannot be had: the run fails in its words.
390
413
  const claimSignal = run.stopped ?? run.signal;
414
+ // An earlier claim's deny turned the run's computer off for the run (computerTurnedOff): this claim starts none, and
415
+ // ends the one a park kept (turnedOff).
416
+ const offAlready = await computerTurnedOff(deps.journal(claim), context);
391
417
  const computer = await deps.computerForClaim(
392
418
  // The runner holding the claim, as the pi spec hands it: a computer kept that only it can reach again is pinned to it.
393
419
  { 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,
@@ -400,7 +426,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
400
426
  // Whether an earlier claim made the run a computer of its own is the run's journal's to say (hadComputer), as the pi
401
427
  // spec asks it. The computer a park kept, attached again, brings its mount credential with it (inheritMount). Its
402
428
  // screen's recording (computer.record) goes in the run's recordings folder, as the pi spec's does.
403
- { ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(run.ledger ? { compute: { ledger: { paid: run.ledger.paid, pause: (refusal) => run.ledger.pause(refusal), judges: () => run.ledger.judges?.() ?? true }, env: deps.env } } : {}), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
429
+ { ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, ...(offAlready ? { turnedOff: offAlready } : {}), recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(run.ledger ? { compute: { ledger: { paid: run.ledger.paid, pause: (refusal) => run.ledger.pause(refusal), judges: () => run.ledger.judges?.() ?? true }, env: deps.env } } : {}), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
404
430
  holds.hold({ computer });
405
431
  const loopComputer = loopComputerOf(computer.computer, computer.held, computer.made);
406
432
  const heldComputer = heldSpecOf(launch, loopComputer);
@@ -437,7 +463,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
437
463
  // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
438
464
  const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
439
465
  const check = movedProject ? undefined : await entry.skillCheck?.();
440
- const { system: instructions, native } = await systemOf(laid, currentSkills, ws.workspace, check, { onDemand: movedProject || readsFiles(granted) });
466
+ // A computer the claim did not start (every tool of it set to deny: ClaimComputer.off) has its kind's skill named to no one.
467
+ const skills = computer.off ? withoutKindSkill(currentSkills, body.skills ?? {}, settingOfDefinition(body)?.computer.kind) : currentSkills;
468
+ const { system: instructions, native } = await systemOf(laid, skills, ws.workspace, check, { onDemand: movedProject || readsFiles(granted) });
441
469
  const guidance = effortGuidance(launch.effort);
442
470
  // The run's model (the launch's, pinned at start, else the revision's) and its adapter, as main builds them, on the
443
471
  // environment main's server gives its runs: the server's data directory named (DATA_ENV), so the CLI's install is
@@ -476,12 +504,13 @@ async function cliSpec(launch, run, deps, claim, holds) {
476
504
  // is chosen, so it never falls to its owner's sign-in (a row counted at its claim may be gone, or not open, by now).
477
505
  // A person's claim that laid none keeps its session on the sign-in (or on nothing) for good: a trigger's message the
478
506
  // claim takes later is refused in it (personOnly), keys saved since or not, as no new claim opens them.
479
- const recipeKeys = name === undefined ? undefined : recipeKeysOf(deps.env ?? {}, name);
507
+ const recipe = name === undefined ? undefined : planRecipeOf(deps.env ?? {}, name);
508
+ const recipeKeys = recipe?.keys;
480
509
  let personOnly;
481
- if (name !== undefined && recipeKeys?.length) {
510
+ if (recipe !== undefined && recipeKeys?.length) {
482
511
  for (const key of recipeKeys)
483
512
  delete env[key];
484
- const opened = deps.sealKey ? await openHarnessKeys(deps.store, deps.sealKey, name, recipeKeys) : ((await runnerSeam()?.harnessKeys()) ?? {});
513
+ const opened = deps.sealKey ? await openHarnessKeys(deps.store, deps.sealKey, recipe) : ((await runnerSeam()?.harnessKeys(recipe.digest)) ?? {});
485
514
  hold(Object.values(opened));
486
515
  if (recipeKeys.every((key) => typeof opened[key] === "string" && opened[key] !== ""))
487
516
  layHarnessKeys(env, opened);
@@ -490,11 +519,20 @@ async function cliSpec(launch, run, deps, claim, holds) {
490
519
  else
491
520
  personOnly = RECIPE_TURN_PERSON_ONLY;
492
521
  }
493
- const chosen = await modelsOf(entry, env, modelAskOf(launch.model, body.model));
494
- await planBeforeRun(env, chosen.model);
495
- if (login && entry.priceModel(env, chosen.model).provider === CLAUDE_LOGIN_PROVIDER) {
496
- const claude = await import("@parcha/agentrun-harness-claude");
497
- await loginBeforeRun(login, loginCli(claudeCliIn(installDirOf(deps.data, name), claude.claudeAgentPlatform()), env), (cli, at) => claude.claudeLoginStatus(cli, at, env.PATH ? { path: env.PATH } : {}));
522
+ // A held run its model kept from running at its create (hold.refused) chooses no model here, and no plan or login is
523
+ // asked before it: its model's route chooses no model and reads no key, its adapter's provider being the stand-in that
524
+ // refuses every request in the create's words (adapters.ts providerOf), never a key or the Claude login. Its claim lays
525
+ // only the keys any claim of the run lays (its tools', a key handed with it: claimSecrets lays it no model key) and
526
+ // takes no learning step (below), so it holds the computer on a host with no key for its model, and a key saved since
527
+ // runs a new run, never this one.
528
+ const heldRefusal = launch.hold?.refused?.message;
529
+ const chosen = heldRefusal !== undefined ? heldChoice(body.model) : await modelsOf(entry, env, modelAskOf(launch.model, body.model));
530
+ if (heldRefusal === undefined) {
531
+ await planBeforeRun(env, chosen.model);
532
+ if (login && entry.priceModel(env, chosen.model).provider === CLAUDE_LOGIN_PROVIDER) {
533
+ const claude = await import("@parcha/agentrun-harness-claude");
534
+ await loginBeforeRun(login, loginCli(claudeCliIn(installDirOf(deps.data, name), claude.claudeAgentPlatform()), env), (cli, at) => claude.claudeLoginStatus(cli, at, env.PATH ? { path: env.PATH } : {}));
535
+ }
498
536
  }
499
537
  // The CLI's own process (the Claude CLI, Codex, OpenCode) starts under the no_new_privs pi's commands start under
500
538
  // (adapters.ts' noNewPrivsPrefix): on Linux, setpriv --no-new-privs, so a setuid program or file capability it
@@ -506,7 +544,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
506
544
  // A run's own process reads no trigger's row: its runner answers the zone (held.ts runZone).
507
545
  const seam = deps.sealKey ? undefined : runnerSeam();
508
546
  const zone = seam ? await seam.runZone() : await runZone(deps.store, launch.inputOrigin);
509
- const built = await entry.adapter(env, { zone, model: chosen.model, models: chosen.models, unpriced: chosen.unpriced, ...(confine ? { confine } : {}), ...(native.length ? { skills: native } : {}), ...(now ? { now: () => now } : {}) });
547
+ const built = await entry.adapter(env, { zone, model: chosen.model, models: chosen.models, unpriced: chosen.unpriced, ...(heldRefusal !== undefined ? { heldRefusal } : {}), ...(confine ? { confine } : {}), ...(native.length ? { skills: native } : {}), ...(now ? { now: () => now } : {}) });
510
548
  // The harness's own session options, its private directory and its working directory (SessionIO's dir and cwd, which
511
549
  // every CLI adapter reads), set on its open here, so the loop lends the session nothing of its own. A turn that ends on
512
550
  // the CLI's own error names the harness first, as main words it (harness-app.ts: `<harness>: <error>`), so the run's
@@ -590,7 +628,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
590
628
  // A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf). The harness's
591
629
  // native tools are named by its facts on the owner's table (factsOf: a module's harness's too).
592
630
  const ownerFacts = factsOf(deps.env, name);
593
- const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, { ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}), facts: ownerFacts });
631
+ const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, { ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}), facts: ownerFacts, turnedOff: offAlready !== undefined, onComputerOff: (kind) => recordComputerOff(run.harness, kind) });
594
632
  // The run's tools: the kernel registry's hands on its Workspace (and computer); the web host tools it is granted
595
633
  // (web_fetch, web_search, monid), bound by the binding the pi spec uses (webHostTools) on the ToolHost the pi spec builds
596
634
  // (buildToolHost); and the learned_workflow tool when the run has it (learnsWorkflows: its revision is agentic and the
@@ -609,7 +647,10 @@ async function cliSpec(launch, run, deps, claim, holds) {
609
647
  // its MCP tools in the loop's one catalog seam; their answers pass the redactors as the web tools' do.
610
648
  const monid = monidForClaim(revisionRow.monidPin ?? undefined, { ...claimed }, () => ws.workspace, claim.runId, () => launch.maxCostUsd !== undefined, fakes?.monid);
611
649
  const catalog = withMonid(mcp, monid && { ...monid, tools: monid.tools.map((tool) => answersCut(tool, held)) });
612
- const webNames = granted.filter(isWebHostTool);
650
+ // A run whose web_search is the harness's own search (ownSearchRuns: native on its plane, Claude's WebSearch, Codex's
651
+ // live search) is not handed the host's web_search beside it.
652
+ const webGranted = ownSearchRuns(ownerFacts, launch.plane) ? granted.filter((name) => name !== "web_search") : granted;
653
+ const webNames = webGranted.filter(isWebHostTool);
613
654
  let learnedTool;
614
655
  let webTools = [];
615
656
  let life;
@@ -629,19 +670,20 @@ async function cliSpec(launch, run, deps, claim, holds) {
629
670
  // five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
630
671
  // (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the agent takes the run.
631
672
  // The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
632
- // Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit and a replay check
633
- // are skipped, in words, where the run brought its own key or the server holds none.
634
- const spendOff = await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey);
635
673
  const admitAuxiliary = runnerSeam() ? undefined : sourceAuxiliaryAdmitter(deps.store, { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } });
636
- const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff, admitAuxiliary };
674
+ // None for a held run, so its claim reads no saved key for spend beside it (claimSpendOff).
675
+ const audits = heldRefusal === undefined ? { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff: await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey), admitAuxiliary } : undefined;
637
676
  // A replay run's or a shadow's grader (runner/compare-end.ts), on a proxy of its own beside the CLI session's, as pi's
638
677
  // is (adapter-run-spec.ts graderRouteOf), reached through the session's port while it is up. None: compared whole.
639
- const graderRoute = launch.replay || launch.audit ? await graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, [held, cut], claim) : undefined;
678
+ // None for a held run its model kept from running, whose model runs nowhere.
679
+ const graderRoute = (launch.replay || launch.audit) && heldRefusal === undefined ? await graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, [held, cut], claim) : undefined;
640
680
  if (graderRoute)
641
681
  tierRoutes.set(GRADER, graderRoute);
642
682
  // Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
643
- // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself.
644
- const learned = await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, folder: learningFolder, shown, spendOff, admitAuxiliary }, seedLaid?.workflows ?? []);
683
+ // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself. A held run its model kept from
684
+ // running takes none of them, as on pi: it settles no audit and starts no replay run, starts on no workflow, and its
685
+ // tool runs none (so no learned tier is routed, below).
686
+ const learned = audits ? await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, folder: learningFolder, shown, spendOff: audits.spendOff, admitAuxiliary }, seedLaid?.workflows ?? []) : { choice: {}, workflows: [] };
645
687
  const firstChoice = learned.choice;
646
688
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
647
689
  // answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
@@ -651,7 +693,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
651
693
  const workflows = learned.workflows;
652
694
  const learns = learnsWorkflows(revision.kind, workflows);
653
695
  if (webNames.length || learns) {
654
- // The claim's keys (above, already held by the redactors), a copy of its own for the tools' plane below.
696
+ // The claim's keys (above, already held by the redactors), a copy of its own for the tools' plane below: its tool and
697
+ // decision keys alone, since its model keys are not enumerable (claimSecrets), so no spread or spawn of it carries one.
655
698
  const toolEnv = { ...claimed };
656
699
  // The decision keys its learned workflows' typed questions need, as the pi spec reads them (claim-secrets.ts
657
700
  // learnedDecisionKeys): onto this copy alone, never the CLI's own environment or its model's (cliRunEnv, above), and
@@ -662,7 +705,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
662
705
  holdClaimed(redact, learnedKeys);
663
706
  underClaimed(toolEnv, learnedKeys);
664
707
  }
665
- handedKeys = runnerSecrets(toolEnv);
708
+ // The model keys the claim opened among them, read by name from `claimed`: the run never learns those either.
709
+ handedKeys = runnerSecrets(toolEnv, runnerSecrets(claimed));
666
710
  // The run's resolved tool plane (its web tools' providers), as the pi spec hands it its web tools.
667
711
  delete toolEnv[TOOL_PLANE_ENV];
668
712
  if (launch.plane && Object.keys(launch.plane).length)
@@ -672,7 +716,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
672
716
  const liveAt = await claimLiveAt(deps, claim.runId);
673
717
  const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: held, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach, ...(liveAt ? { liveAt } : {}), ...(deps.saveSlots ? { saveSlots: deps.saveSlots } : {}) });
674
718
  gate.askedOn(host);
675
- webTools = await webHostTools(host, granted, ctx);
719
+ webTools = await webHostTools(host, webGranted, ctx);
676
720
  }
677
721
  if (learns) {
678
722
  // A tier the learned workflows name that the host has a model of, routed as pi's are (learnedTierRoutes: the run's
@@ -683,7 +727,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
683
727
  const tierKeys = keyed ? {} : await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
684
728
  for (const redact of new Set([held, cut]))
685
729
  holdClaimed(redact, tierKeys);
686
- const modelEnv = claimModelEnv(deps.env, { ...claimed, ...tierKeys }, runKey, claim);
730
+ const modelEnv = claimModelEnv(deps.env, keysOver(claimed, tierKeys), runKey, claim);
687
731
  const tiers = new Map();
688
732
  for (const [tier, routed] of await learnedTierRoutes(workflows, modelEnv, (tier) => deps.routeOf(undefined, modelEnv, tier, PI_WIRES, undefined, cut))) {
689
733
  if ("why" in routed)
@@ -722,7 +766,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
722
766
  // from. With a grader it compares its answer with the other one (runner/compare-end.ts), on its own cap.
723
767
  // A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
724
768
  // withAudit): at its end, so the shadow's cap is what the run's own left.
725
- const endOfRun = launch.replay || launch.audit ? withGrader(compareEndOfRun(launch, { store: deps.store, folder: learningFolder, log, ...(run.redact ? { redact: run.redact } : {}) }), graderRoute ? { model: graderRoute.model, models: () => run.ledger.models(GRADER, GRADER) } : undefined) : withAudit(learningEndOfRun(launch, {
769
+ // A held run (no audits) takes none, as on pi.
770
+ const endOfRun = audits === undefined ? undefined : launch.replay || launch.audit ? withGrader(compareEndOfRun(launch, { store: deps.store, folder: learningFolder, log, ...(run.redact ? { redact: run.redact } : {}) }), graderRoute ? { model: graderRoute.model, models: () => run.ledger.models(GRADER, GRADER) } : undefined) : withAudit(learningEndOfRun(launch, {
726
771
  store: deps.store,
727
772
  data: deps.data,
728
773
  ...(deps.env ? { env: deps.env } : {}),
@@ -741,7 +786,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
741
786
  }), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
742
787
  return {
743
788
  adapter,
744
- facts: ownerFacts,
789
+ facts: factsOn(ownerFacts, chosen.model),
745
790
  session,
746
791
  input,
747
792
  // A trigger's first input is its origin's, the launch's own owner flag kept (run-launch.ts keepInputOrigin).
@@ -752,6 +797,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
752
797
  // The answer's schema: a miss is asked again once (adapter-loop.ts, the output contract's retry), as on pi.
753
798
  ...(body.outputSchema !== undefined ? { outputSchema: body.outputSchema } : {}),
754
799
  ...(cap ? { cap } : {}),
800
+ // Its model, as its GenAI trace names it (otel/genai.ts); its requests' host is its CLI's own to choose.
801
+ trace: routeTrace({ named: `${chosen.model.provider}/${chosen.model.modelId}`, model: chosen.model.modelId }),
755
802
  // The run's MCP for a harness with its own client (mcp-run.ts), with its monid endpoints beside it (monid-run.ts):
756
803
  // the catalog tools the session mounts; absent when none.
757
804
  ...(catalog ? { mcp: catalog } : {}),
@@ -1,4 +1,5 @@
1
- import type { Context } from "@earendil-works/chord/context";
1
+ import { type Context } from "@earendil-works/chord/context";
2
+ import { type Harness } from "@earendil-works/pi-durable";
2
3
  import type { JournalReads } from "../store/store.js";
3
4
  import type { HeldComputer, HoldEnd, HoldState } from "../workspace/computer-hold.js";
4
5
  import type { Command, CommandOutcome } from "./loop-contract.js";
@@ -6,6 +7,13 @@ import type { Command, CommandOutcome } from "./loop-contract.js";
6
7
  * claim's pass writes): what a later claim asks (computerForClaim's hadComputer) before it makes a fresh one, so it
7
8
  * says it replaces one even when nothing of the earlier claim's is left to let go (a server's stop, a park). */
8
9
  export declare function hadComputer(journal: JournalReads, context: Context): Promise<boolean>;
10
+ /** The kind of the run's computer when an earlier claim's deny turned it off for the rest of the run (KINDS.computerOff,
11
+ * recordComputerOff): a claim that finds it starts no computer, and its gate refuses each call of that computer's tools
12
+ * short (RunGate.turnOff). Undefined while the run's computer is on. */
13
+ export declare function computerTurnedOff(journal: JournalReads, context: Context): Promise<string | undefined>;
14
+ /** Writes on the run's root, through the claim's Harness, that the run's `kind` computer is off for the rest of the run:
15
+ * what computerTurnedOff reads back at a later claim. */
16
+ export declare function recordComputerOff(harness: Pick<Harness, "commit">, kind: string): Promise<void>;
9
17
  /** One root entry, as the run's journal takes it. */
10
18
  export type RootEntry = {
11
19
  readonly kind: string;
@@ -1,3 +1,16 @@
1
+ // The run's desktop or phone hold, on the runner: every change of the hold (workspace/computer-hold.ts) is committed to the
2
+ // run's journal with its Timeline row, which is what the server reads (computer-commands.ts, computer-routes.ts); and the
3
+ // person's take-over and hand-back rows are applied to the hold. The adapter loop calls this once the run's Harness is
4
+ // open, for a spec that carries a computer (AdapterRunSpec.computer).
5
+ //
6
+ // Commits go one at a time, in the order the hold changed, each at the change's own time. A row the hold took or ended a
7
+ // take for is taken by the commit that writes that change (its `by`); one the hold refuses is refused in words.
8
+ //
9
+ // onComputerHold is the change signal for whoever else in the runner's process shows the hold (tl-browser's run-side
10
+ // viewer and its bar): it fires after each computer.hold change entry is committed, with that change's Timeline words.
11
+ // A run in a process of its own commits there and its viewer is its runner's: the change crosses to the runner first.
12
+ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
13
+ import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
1
14
  import { HOST_PHASE } from "../timeline/index.js";
2
15
  import { COMPUTER_HAND_BACK, COMPUTER_HANDOVER_KIND, COMPUTER_HOLD_KIND, COMPUTER_TAKE_OVER, ENDS, holdIn, holdWords, STATES, takeEndedWords, } from "../computer-commands.js";
3
16
  import { held } from "./held.js";
@@ -9,6 +22,19 @@ import { journalEntries } from "./journal-reader.js";
9
22
  export async function hadComputer(journal, context) {
10
23
  return (await journalEntries(journal, context)).some((entry) => entry.kind === KINDS.computerMade);
11
24
  }
25
+ /** The kind of the run's computer when an earlier claim's deny turned it off for the rest of the run (KINDS.computerOff,
26
+ * recordComputerOff): a claim that finds it starts no computer, and its gate refuses each call of that computer's tools
27
+ * short (RunGate.turnOff). Undefined while the run's computer is on. */
28
+ export async function computerTurnedOff(journal, context) {
29
+ const off = (await journalEntries(journal, context)).find((entry) => entry.kind === KINDS.computerOff);
30
+ const kind = off?.data?.computer;
31
+ return typeof kind === "string" ? kind : undefined;
32
+ }
33
+ /** Writes on the run's root, through the claim's Harness, that the run's `kind` computer is off for the rest of the run:
34
+ * what computerTurnedOff reads back at a later claim. */
35
+ export async function recordComputerOff(harness, kind) {
36
+ await harness.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: KINDS.computerOff, data: { computer: kind } })), BACKGROUND_CONTEXT);
37
+ }
12
38
  const listeners = new Map();
13
39
  /** Calls `listener` after each change of run `runId`'s hold is committed to its journal, in order, in this process.
14
40
  * Returns the unsubscribe. */
@@ -385,7 +385,7 @@ async function world(subject, t, timing = STEADY) {
385
385
  return reducer.rows();
386
386
  };
387
387
  /** The run's Timeline rows as GET /runs/{id}/timeline serves them (run-timeline-served.ts), its approval rows among them. */
388
- const servedRows = () => servedTimelineRows({ serverSecrets: () => [], keyEnv: () => ({}) }, server, RUN, BACKGROUND_CONTEXT);
388
+ const servedRows = () => servedTimelineRows({ serverSecrets: () => [], sealKey: undefined, keyEnv: () => ({}) }, server, RUN, BACKGROUND_CONTEXT);
389
389
  const commandRow = async (id) => (await server.commands(RUN, id - 1)).find((row) => row.id === id);
390
390
  /** The call the run asked a person about: its ask entry's callId, which an approve or deny names as its approval. */
391
391
  const askedCall = async () => {
@@ -113,6 +113,9 @@ export async function openFeedbackRound(store, grade, label, canTurn = () => tru
113
113
  // Source sessions and application-owned SDK tasks cannot consume a managed feedback steer.
114
114
  if (launch?.native || launch?.sdk || launch?.cli_learning)
115
115
  return null;
116
+ // A held run its model kept from running at its create never runs a turn (computer-held.ts): no round opens it again.
117
+ if (launch?.hold?.refused)
118
+ return null;
116
119
  const learning = launch?.learning;
117
120
  if (!learning || learning.use)
118
121
  return null;
@@ -1,5 +1,5 @@
1
1
  import { RECIPE_SIGN_IN_PERSON_ONLY } from "../harness-keys.js";
2
- import type { SealedKeys } from "../store/index.js";
2
+ import type { SealedKeys, Settings } from "../store/index.js";
3
3
  import { type RunLaunch } from "../run-launch.js";
4
4
  import { type AdapterSpecDeps } from "./adapter-run-spec.js";
5
5
  import { ClaimRefused, type LoopFactory } from "./loop-contract.js";
@@ -10,14 +10,15 @@ export declare class NeverFits extends ClaimRefused {
10
10
  }
11
11
  export { RECIPE_SIGN_IN_PERSON_ONLY };
12
12
  /** Refuses at its claim a run no person started (a schedule's, a trigger's, a learned workflow's audit shadow or replay:
13
- * personStarted) on a plan-billed recipe's harness (harness-table.ts recipeKeysOf) unless every key it runs on is saved for that harness (harness-keys.ts), on
14
- * every path a claim takes (run-child-host.ts staysInRunner, and here): the early word, before a process is made. Rows
15
- * are counted, never opened; the claim's spec opens them and refuses it again if not every one opened, since a row
16
- * counted here can be gone or not open by then (cli-run-spec.ts). */
13
+ * personStarted) on a plan-billed recipe's harness (harness-table.ts planRecipeOf) unless every key it runs on is saved
14
+ * for that recipe (harness-keys.ts), on every path a claim takes (run-child-host.ts staysInRunner, and here): the early
15
+ * word, before a process is made. Rows and their bindings are counted, never opened; the claim's spec opens them and
16
+ * refuses it again if not every one opened, since a row counted here can be gone or not open by then (cli-run-spec.ts). */
17
17
  export declare function refuseRecipeTriggerRun(deps: {
18
18
  readonly env?: NodeJS.ProcessEnv;
19
19
  readonly store: {
20
20
  readonly sealedKeys: Pick<SealedKeys, "all">;
21
+ readonly settings: Pick<Settings, "get">;
21
22
  };
22
23
  }, harness: string, launch: Pick<RunLaunch, "trigger" | "audit" | "replay">): Promise<void>;
23
24
  /** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
@@ -13,7 +13,7 @@ import { createNativeLoop } from "./native-loop.js";
13
13
  // module adds with no adapter facts of its own, on its runner's adapter;
14
14
  // - a CLI harness (claude-agent, codex, opencode) runs on the adapter loop with its own adapter;
15
15
  // - anything else fails the run in words (the dispatch's UnknownHarness).
16
- import { harnessOf, recipeKeysOf } from "../harness-table.js";
16
+ import { harnessOf, planRecipeOf } from "../harness-table.js";
17
17
  import { harnessKeysSaved, RECIPE_SIGN_IN_PERSON_ONLY } from "../harness-keys.js";
18
18
  import { hostMemory, neverFits } from "../host.js";
19
19
  import { personStarted } from "../run-launch.js";
@@ -36,15 +36,15 @@ export class NeverFits extends ClaimRefused {
36
36
  }
37
37
  export { RECIPE_SIGN_IN_PERSON_ONLY };
38
38
  /** Refuses at its claim a run no person started (a schedule's, a trigger's, a learned workflow's audit shadow or replay:
39
- * personStarted) on a plan-billed recipe's harness (harness-table.ts recipeKeysOf) unless every key it runs on is saved for that harness (harness-keys.ts), on
40
- * every path a claim takes (run-child-host.ts staysInRunner, and here): the early word, before a process is made. Rows
41
- * are counted, never opened; the claim's spec opens them and refuses it again if not every one opened, since a row
42
- * counted here can be gone or not open by then (cli-run-spec.ts). */
39
+ * personStarted) on a plan-billed recipe's harness (harness-table.ts planRecipeOf) unless every key it runs on is saved
40
+ * for that recipe (harness-keys.ts), on every path a claim takes (run-child-host.ts staysInRunner, and here): the early
41
+ * word, before a process is made. Rows and their bindings are counted, never opened; the claim's spec opens them and
42
+ * refuses it again if not every one opened, since a row counted here can be gone or not open by then (cli-run-spec.ts). */
43
43
  export async function refuseRecipeTriggerRun(deps, harness, launch) {
44
44
  if (personStarted(launch))
45
45
  return;
46
- const keys = recipeKeysOf(deps.env ?? {}, harness);
47
- if (keys !== undefined && !(await harnessKeysSaved(deps.store, harness, keys)))
46
+ const recipe = planRecipeOf(deps.env ?? {}, harness);
47
+ if (recipe !== undefined && !(await harnessKeysSaved(deps.store, recipe)))
48
48
  throw new ClaimRefused(RECIPE_SIGN_IN_PERSON_ONLY);
49
49
  }
50
50
  /** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and