@parcha/agentrun-serve 0.1.0-beta.55 → 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 (296) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/README.md +228 -45
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +18 -5
  5. package/dist/adapters.js +23 -9
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/answer-json.d.ts +6 -2
  9. package/dist/answer-json.js +22 -4
  10. package/dist/api-keys.d.ts +76 -0
  11. package/dist/api-keys.js +217 -0
  12. package/dist/api-only.d.ts +17 -5
  13. package/dist/api-only.js +36 -8
  14. package/dist/browser-hold.d.ts +23 -0
  15. package/dist/browser-hold.js +48 -0
  16. package/dist/browser-person.d.ts +3 -0
  17. package/dist/browser-person.js +4 -1
  18. package/dist/calendar/tools.js +3 -2
  19. package/dist/chatgpt-plan.d.ts +28 -3
  20. package/dist/chatgpt-plan.js +182 -21
  21. package/dist/claude-login.d.ts +101 -14
  22. package/dist/claude-login.js +232 -49
  23. package/dist/claude-sign-in.d.ts +46 -0
  24. package/dist/claude-sign-in.js +93 -0
  25. package/dist/cli.js +63 -6
  26. package/dist/composio-made.d.ts +4 -0
  27. package/dist/composio-made.js +4 -0
  28. package/dist/composio-preset.d.ts +43 -2
  29. package/dist/composio-preset.js +92 -4
  30. package/dist/computer-held-routes.d.ts +5 -4
  31. package/dist/computer-held-routes.js +29 -8
  32. package/dist/computer-held.d.ts +6 -1
  33. package/dist/computer-held.js +14 -0
  34. package/dist/computer-record.js +4 -2
  35. package/dist/computer-viewer.js +4 -1
  36. package/dist/console/assets/{backend-D5EmB4N3.js → backend-DVhHzJX2.js} +19 -19
  37. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  38. package/dist/console/assets/index-okP-y8PK.js +747 -0
  39. package/dist/console/index.html +2 -2
  40. package/dist/decisions.d.ts +1 -1
  41. package/dist/decisions.js +1 -1
  42. package/dist/docker-host-addresses.d.ts +22 -11
  43. package/dist/docker-host-addresses.js +38 -26
  44. package/dist/env-switch.d.ts +10 -0
  45. package/dist/env-switch.js +33 -2
  46. package/dist/errors.d.ts +1 -0
  47. package/dist/errors.js +2 -0
  48. package/dist/fal-price.d.ts +58 -20
  49. package/dist/fal-price.js +341 -82
  50. package/dist/handed-values.d.ts +43 -1
  51. package/dist/handed-values.js +119 -2
  52. package/dist/harness-archive.d.ts +13 -10
  53. package/dist/harness-archive.js +60 -34
  54. package/dist/harness-check.d.ts +3 -1
  55. package/dist/harness-check.js +25 -46
  56. package/dist/harness-keys.d.ts +73 -27
  57. package/dist/harness-keys.js +194 -61
  58. package/dist/harness-recipe-entry.d.ts +8 -7
  59. package/dist/harness-recipe-entry.js +21 -32
  60. package/dist/harness-recipe.d.ts +38 -25
  61. package/dist/harness-recipe.js +49 -36
  62. package/dist/harness-sign-in.js +12 -23
  63. package/dist/harness-table.d.ts +10 -3
  64. package/dist/harness-table.js +26 -21
  65. package/dist/harness.d.ts +1 -0
  66. package/dist/harness.js +17 -5
  67. package/dist/host-check.d.ts +4 -0
  68. package/dist/host-check.js +4 -0
  69. package/dist/hosted-search.d.ts +1 -1
  70. package/dist/hosted-search.js +1 -2
  71. package/dist/import-worker.d.ts +4 -2
  72. package/dist/import-worker.js +9 -2
  73. package/dist/in-flight.d.ts +26 -0
  74. package/dist/in-flight.js +52 -0
  75. package/dist/key-refusal.d.ts +26 -5
  76. package/dist/key-refusal.js +313 -37
  77. package/dist/learn/secrets.d.ts +31 -11
  78. package/dist/learn/secrets.js +152 -191
  79. package/dist/learning-cost.d.ts +6 -3
  80. package/dist/learning-cost.js +4 -2
  81. package/dist/link-check.js +1 -1
  82. package/dist/llms.txt +2 -2
  83. package/dist/marketplace.d.ts +77 -0
  84. package/dist/marketplace.js +224 -0
  85. package/dist/mcp-api-only-origins.d.ts +30 -0
  86. package/dist/mcp-api-only-origins.js +57 -0
  87. package/dist/mcp-gateway.d.ts +7 -5
  88. package/dist/mcp-gateway.js +9 -12
  89. package/dist/mcp-secret-writes.js +5 -3
  90. package/dist/mcp-servers-store.d.ts +28 -6
  91. package/dist/mcp-servers-store.js +53 -4
  92. package/dist/media-duration.d.ts +3 -0
  93. package/dist/media-duration.js +90 -9
  94. package/dist/model-form.d.ts +5 -4
  95. package/dist/model-form.js +11 -7
  96. package/dist/model.d.ts +5 -2
  97. package/dist/model.js +9 -5
  98. package/dist/ollama-provider.d.ts +7 -1
  99. package/dist/ollama-provider.js +14 -2
  100. package/dist/openapi.d.ts +3 -3
  101. package/dist/openapi.js +245 -42
  102. package/dist/otel/genai.d.ts +65 -0
  103. package/dist/otel/genai.js +116 -0
  104. package/dist/otel/tracer.d.ts +55 -0
  105. package/dist/otel/tracer.js +308 -0
  106. package/dist/page.d.ts +2 -0
  107. package/dist/page.js +3 -1
  108. package/dist/paid-calls.d.ts +1 -32
  109. package/dist/paid-calls.js +4 -39
  110. package/dist/place-offers.d.ts +14 -6
  111. package/dist/place-offers.js +26 -13
  112. package/dist/provider.d.ts +9 -0
  113. package/dist/provider.js +50 -3
  114. package/dist/redact/match.d.ts +101 -0
  115. package/dist/redact/match.js +1152 -0
  116. package/dist/refusal-words.d.ts +11 -0
  117. package/dist/refusal-words.js +11 -0
  118. package/dist/run-census.d.ts +67 -0
  119. package/dist/run-census.js +240 -0
  120. package/dist/run-computer.d.ts +6 -3
  121. package/dist/run-computer.js +4 -1
  122. package/dist/run-cut.d.ts +15 -6
  123. package/dist/run-cut.js +30 -9
  124. package/dist/run-files.d.ts +3 -0
  125. package/dist/run-files.js +3 -0
  126. package/dist/run-launch.d.ts +12 -1
  127. package/dist/run-launch.js +9 -10
  128. package/dist/run-learning-served.d.ts +2 -0
  129. package/dist/run-model-key.d.ts +8 -0
  130. package/dist/run-model-key.js +31 -1
  131. package/dist/run-reads-over-store.d.ts +24 -6
  132. package/dist/run-reads-over-store.js +67 -23
  133. package/dist/run-recordings.d.ts +5 -1
  134. package/dist/run-recordings.js +39 -14
  135. package/dist/run-timeline-served.d.ts +3 -1
  136. package/dist/run-timeline-served.js +4 -4
  137. package/dist/run-usage.d.ts +1 -0
  138. package/dist/runnable.d.ts +10 -1
  139. package/dist/runnable.js +20 -8
  140. package/dist/runner/adapter-loop.d.ts +14 -0
  141. package/dist/runner/adapter-loop.js +56 -11
  142. package/dist/runner/adapter-run-spec.d.ts +45 -8
  143. package/dist/runner/adapter-run-spec.js +154 -29
  144. package/dist/runner/adapters/pi.js +25 -3
  145. package/dist/runner/beside.js +11 -6
  146. package/dist/runner/big-writes.js +1 -10
  147. package/dist/runner/claim-secrets.d.ts +18 -3
  148. package/dist/runner/claim-secrets.js +35 -6
  149. package/dist/runner/cli-run-spec.d.ts +6 -0
  150. package/dist/runner/cli-run-spec.js +85 -36
  151. package/dist/runner/computer-journal.d.ts +9 -1
  152. package/dist/runner/computer-journal.js +26 -0
  153. package/dist/runner/conformance/harness.js +1 -1
  154. package/dist/runner/feedback-round.js +3 -0
  155. package/dist/runner/harness-loops.d.ts +6 -5
  156. package/dist/runner/harness-loops.js +7 -7
  157. package/dist/runner/held.d.ts +11 -5
  158. package/dist/runner/journal-kinds.d.ts +5 -0
  159. package/dist/runner/journal-kinds.js +5 -0
  160. package/dist/runner/loop-contract.d.ts +4 -0
  161. package/dist/runner/main.js +15 -6
  162. package/dist/runner/mcp-claim.js +30 -3
  163. package/dist/runner/mcp-run.d.ts +12 -0
  164. package/dist/runner/mcp-run.js +12 -5
  165. package/dist/runner/model-route.d.ts +17 -0
  166. package/dist/runner/model-route.js +120 -2
  167. package/dist/runner/presence.d.ts +4 -3
  168. package/dist/runner/presence.js +4 -2
  169. package/dist/runner/run-child-host.d.ts +5 -0
  170. package/dist/runner/run-child-host.js +71 -30
  171. package/dist/runner/run-child.js +5 -2
  172. package/dist/runner/runner.d.ts +18 -3
  173. package/dist/runner/runner.js +162 -36
  174. package/dist/runner/store-port.d.ts +1 -1
  175. package/dist/runner/store-secrets.d.ts +6 -0
  176. package/dist/runner/store-secrets.js +49 -7
  177. package/dist/runner/subagent.js +4 -40
  178. package/dist/runner/workflow-first.d.ts +11 -4
  179. package/dist/runner/workflow-first.js +14 -8
  180. package/dist/runner/workflow-spec.js +3 -2
  181. package/dist/runs-over-store.d.ts +15 -6
  182. package/dist/runs-over-store.js +33 -21
  183. package/dist/scrub-command.d.ts +73 -0
  184. package/dist/scrub-command.js +307 -0
  185. package/dist/secret-cut.d.ts +73 -0
  186. package/dist/secret-cut.js +291 -4
  187. package/dist/secret-rules.d.ts +143 -0
  188. package/dist/secret-rules.js +2564 -0
  189. package/dist/secrets.d.ts +7 -0
  190. package/dist/secrets.js +20 -0
  191. package/dist/server-keys.d.ts +20 -0
  192. package/dist/server-keys.js +25 -6
  193. package/dist/server.d.ts +57 -13
  194. package/dist/server.js +371 -113
  195. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  196. package/dist/store/dialect.d.ts +3 -0
  197. package/dist/store/dialect.js +1 -0
  198. package/dist/store/index.d.ts +1 -1
  199. package/dist/store/index.js +1 -1
  200. package/dist/store/journal/storage.js +1 -1
  201. package/dist/store/postgres/dialect.js +3 -0
  202. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  203. package/dist/store/schema.d.ts +6 -0
  204. package/dist/store/schema.js +11 -1
  205. package/dist/store/seal.d.ts +6 -1
  206. package/dist/store/seal.js +5 -3
  207. package/dist/store/sqlite/run-launch.d.ts +9 -1
  208. package/dist/store/sqlite/run-launch.js +24 -13
  209. package/dist/store/sqlite/run-patch.d.ts +1 -1
  210. package/dist/store/sqlite/run-patch.js +13 -4
  211. package/dist/store/sqlite/store.js +76 -16
  212. package/dist/store/store.d.ts +53 -3
  213. package/dist/store/store.js +27 -0
  214. package/dist/store-reads/learning.d.ts +6 -3
  215. package/dist/store-reads/learning.js +22 -7
  216. package/dist/store-view.d.ts +3 -0
  217. package/dist/store-view.js +4 -4
  218. package/dist/suggestions.js +3 -2
  219. package/dist/template-eval.d.ts +22 -11
  220. package/dist/template-eval.js +124 -41
  221. package/dist/template-import.d.ts +10 -0
  222. package/dist/template-import.js +16 -7
  223. package/dist/templates.d.ts +10 -2
  224. package/dist/templates.js +28 -8
  225. package/dist/timeline/index.d.ts +1 -1
  226. package/dist/timeline/index.js +1 -1
  227. package/dist/timeline/labels.d.ts +6 -4
  228. package/dist/timeline/labels.js +18 -6
  229. package/dist/timeline/timeline.d.ts +17 -7
  230. package/dist/timeline/timeline.js +28 -14
  231. package/dist/timeline/util.js +1 -1
  232. package/dist/timeline/web-calls.d.ts +26 -9
  233. package/dist/timeline/web-calls.js +124 -37
  234. package/dist/tool-gate.d.ts +42 -3
  235. package/dist/tool-gate.js +69 -6
  236. package/dist/tool-keys-store.d.ts +2 -4
  237. package/dist/tool-keys-store.js +5 -21
  238. package/dist/tool-keys.d.ts +2 -2
  239. package/dist/tool-keys.js +2 -2
  240. package/dist/tool-list.js +1 -1
  241. package/dist/tool-plane.d.ts +2 -2
  242. package/dist/tool-plane.js +35 -33
  243. package/dist/tools.js +13 -7
  244. package/dist/trigger-targets.d.ts +4 -0
  245. package/dist/trigger-targets.js +9 -2
  246. package/dist/triggers.d.ts +67 -4
  247. package/dist/triggers.js +171 -22
  248. package/dist/until.d.ts +3 -0
  249. package/dist/until.js +11 -0
  250. package/dist/validate.js +1 -1
  251. package/dist/web-fake.d.ts +1 -3
  252. package/dist/web-fake.js +7 -18
  253. package/dist/web-fetch.d.ts +6 -72
  254. package/dist/web-fetch.js +11 -265
  255. package/dist/web-run.d.ts +31 -0
  256. package/dist/web-run.js +90 -0
  257. package/dist/web-save.d.ts +6 -4
  258. package/dist/web-save.js +9 -12
  259. package/dist/web-search.d.ts +9 -127
  260. package/dist/web-search.js +23 -259
  261. package/dist/wires.d.ts +13 -0
  262. package/dist/wires.js +11 -0
  263. package/dist/workflow-run.d.ts +5 -4
  264. package/dist/workflow-run.js +5 -4
  265. package/dist/workspace/computer-deps.d.ts +3 -1
  266. package/dist/workspace/computer-deps.js +12 -4
  267. package/dist/workspace/computer-for-claim.d.ts +19 -2
  268. package/dist/workspace/computer-for-claim.js +101 -13
  269. package/dist/workspace/computer-janitor.d.ts +15 -7
  270. package/dist/workspace/computer-janitor.js +33 -8
  271. package/dist/workspace/computer-kept.d.ts +55 -4
  272. package/dist/workspace/computer-kept.js +129 -8
  273. package/dist/workspace/index.d.ts +1 -1
  274. package/dist/workspace/index.js +1 -1
  275. package/dist/workspace/kind-skills.d.ts +4 -0
  276. package/dist/workspace/kind-skills.js +9 -0
  277. package/dist/workspace/run-end-computers.d.ts +5 -1
  278. package/dist/workspace/run-end-computers.js +27 -1
  279. package/dist/workspace/synced-folder.js +3 -4
  280. package/dist/wrapped.d.ts +65 -0
  281. package/dist/wrapped.js +77 -0
  282. package/package.json +17 -11
  283. package/skills/agentrun-serve/SKILL.md +4 -0
  284. package/templates/README.md +38 -15
  285. package/dist/console/assets/index-DUYLaqiR.js +0 -746
  286. package/dist/console/assets/index-DYhU4adm.css +0 -1
  287. package/dist/exa-keyless.d.ts +0 -34
  288. package/dist/exa-keyless.js +0 -118
  289. package/dist/firecrawl-keyless.d.ts +0 -41
  290. package/dist/firecrawl-keyless.js +0 -152
  291. package/dist/keyless-mcp.d.ts +0 -36
  292. package/dist/keyless-mcp.js +0 -127
  293. package/dist/text-urls.d.ts +0 -38
  294. package/dist/text-urls.js +0 -170
  295. package/dist/web-fetch-direct.d.ts +0 -119
  296. 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,7 +411,12 @@ 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;
391
- const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, claim, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place }, deps.store,
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);
417
+ const computer = await deps.computerForClaim(
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.
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,
392
420
  // revokeMount removes the run's Archil mount credential at the computer's release (and if a start fails after a mint); the
393
421
  // run's end revokes it too, so it goes on every outcome even with no computer. Idempotent. As the pi spec does, with
394
422
  // what became of the agent's own computer said on the run's timeline.
@@ -398,7 +426,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
398
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
399
427
  // spec asks it. The computer a park kept, attached again, brings its mount credential with it (inheritMount). Its
400
428
  // screen's recording (computer.record) goes in the run's recordings folder, as the pi spec's does.
401
- { ...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) } : {}) });
402
430
  holds.hold({ computer });
403
431
  const loopComputer = loopComputerOf(computer.computer, computer.held, computer.made);
404
432
  const heldComputer = heldSpecOf(launch, loopComputer);
@@ -435,7 +463,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
435
463
  // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
436
464
  const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
437
465
  const check = movedProject ? undefined : await entry.skillCheck?.();
438
- 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) });
439
469
  const guidance = effortGuidance(launch.effort);
440
470
  // The run's model (the launch's, pinned at start, else the revision's) and its adapter, as main builds them, on the
441
471
  // environment main's server gives its runs: the server's data directory named (DATA_ENV), so the CLI's install is
@@ -474,12 +504,13 @@ async function cliSpec(launch, run, deps, claim, holds) {
474
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).
475
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
476
506
  // claim takes later is refused in it (personOnly), keys saved since or not, as no new claim opens them.
477
- const recipeKeys = name === undefined ? undefined : recipeKeysOf(deps.env ?? {}, name);
507
+ const recipe = name === undefined ? undefined : planRecipeOf(deps.env ?? {}, name);
508
+ const recipeKeys = recipe?.keys;
478
509
  let personOnly;
479
- if (name !== undefined && recipeKeys?.length) {
510
+ if (recipe !== undefined && recipeKeys?.length) {
480
511
  for (const key of recipeKeys)
481
512
  delete env[key];
482
- 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)) ?? {});
483
514
  hold(Object.values(opened));
484
515
  if (recipeKeys.every((key) => typeof opened[key] === "string" && opened[key] !== ""))
485
516
  layHarnessKeys(env, opened);
@@ -488,11 +519,20 @@ async function cliSpec(launch, run, deps, claim, holds) {
488
519
  else
489
520
  personOnly = RECIPE_TURN_PERSON_ONLY;
490
521
  }
491
- const chosen = await modelsOf(entry, env, modelAskOf(launch.model, body.model));
492
- await planBeforeRun(env, chosen.model);
493
- if (login && entry.priceModel(env, chosen.model).provider === CLAUDE_LOGIN_PROVIDER) {
494
- const claude = await import("@parcha/agentrun-harness-claude");
495
- 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
+ }
496
536
  }
497
537
  // The CLI's own process (the Claude CLI, Codex, OpenCode) starts under the no_new_privs pi's commands start under
498
538
  // (adapters.ts' noNewPrivsPrefix): on Linux, setpriv --no-new-privs, so a setuid program or file capability it
@@ -504,7 +544,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
504
544
  // A run's own process reads no trigger's row: its runner answers the zone (held.ts runZone).
505
545
  const seam = deps.sealKey ? undefined : runnerSeam();
506
546
  const zone = seam ? await seam.runZone() : await runZone(deps.store, launch.inputOrigin);
507
- 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 } : {}) });
508
548
  // The harness's own session options, its private directory and its working directory (SessionIO's dir and cwd, which
509
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
510
550
  // the CLI's own error names the harness first, as main words it (harness-app.ts: `<harness>: <error>`), so the run's
@@ -588,7 +628,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
588
628
  // A pinned MCP tool is held to the arguments its listing in the run's pin declares (mcp.argumentsOf). The harness's
589
629
  // native tools are named by its facts on the owner's table (factsOf: a module's harness's too).
590
630
  const ownerFacts = factsOf(deps.env, name);
591
- 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) });
592
632
  // The run's tools: the kernel registry's hands on its Workspace (and computer); the web host tools it is granted
593
633
  // (web_fetch, web_search, monid), bound by the binding the pi spec uses (webHostTools) on the ToolHost the pi spec builds
594
634
  // (buildToolHost); and the learned_workflow tool when the run has it (learnsWorkflows: its revision is agentic and the
@@ -607,7 +647,10 @@ async function cliSpec(launch, run, deps, claim, holds) {
607
647
  // its MCP tools in the loop's one catalog seam; their answers pass the redactors as the web tools' do.
608
648
  const monid = monidForClaim(revisionRow.monidPin ?? undefined, { ...claimed }, () => ws.workspace, claim.runId, () => launch.maxCostUsd !== undefined, fakes?.monid);
609
649
  const catalog = withMonid(mcp, monid && { ...monid, tools: monid.tools.map((tool) => answersCut(tool, held)) });
610
- 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);
611
654
  let learnedTool;
612
655
  let webTools = [];
613
656
  let life;
@@ -627,19 +670,20 @@ async function cliSpec(launch, run, deps, claim, holds) {
627
670
  // five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
628
671
  // (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the agent takes the run.
629
672
  // The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
630
- // Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit and a replay check
631
- // are skipped, in words, where the run brought its own key or the server holds none.
632
- const spendOff = await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey);
633
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 } : {}) } });
634
- 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;
635
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
636
677
  // is (adapter-run-spec.ts graderRouteOf), reached through the session's port while it is up. None: compared whole.
637
- 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;
638
680
  if (graderRoute)
639
681
  tierRoutes.set(GRADER, graderRoute);
640
682
  // Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
641
- // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself.
642
- 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: [] };
643
687
  const firstChoice = learned.choice;
644
688
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
645
689
  // answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
@@ -649,7 +693,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
649
693
  const workflows = learned.workflows;
650
694
  const learns = learnsWorkflows(revision.kind, workflows);
651
695
  if (webNames.length || learns) {
652
- // 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.
653
698
  const toolEnv = { ...claimed };
654
699
  // The decision keys its learned workflows' typed questions need, as the pi spec reads them (claim-secrets.ts
655
700
  // learnedDecisionKeys): onto this copy alone, never the CLI's own environment or its model's (cliRunEnv, above), and
@@ -660,7 +705,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
660
705
  holdClaimed(redact, learnedKeys);
661
706
  underClaimed(toolEnv, learnedKeys);
662
707
  }
663
- 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));
664
710
  // The run's resolved tool plane (its web tools' providers), as the pi spec hands it its web tools.
665
711
  delete toolEnv[TOOL_PLANE_ENV];
666
712
  if (launch.plane && Object.keys(launch.plane).length)
@@ -670,7 +716,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
670
716
  const liveAt = await claimLiveAt(deps, claim.runId);
671
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 } : {}) });
672
718
  gate.askedOn(host);
673
- webTools = await webHostTools(host, granted, ctx);
719
+ webTools = await webHostTools(host, webGranted, ctx);
674
720
  }
675
721
  if (learns) {
676
722
  // A tier the learned workflows name that the host has a model of, routed as pi's are (learnedTierRoutes: the run's
@@ -681,7 +727,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
681
727
  const tierKeys = keyed ? {} : await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
682
728
  for (const redact of new Set([held, cut]))
683
729
  holdClaimed(redact, tierKeys);
684
- const modelEnv = claimModelEnv(deps.env, { ...claimed, ...tierKeys }, runKey, claim);
730
+ const modelEnv = claimModelEnv(deps.env, keysOver(claimed, tierKeys), runKey, claim);
685
731
  const tiers = new Map();
686
732
  for (const [tier, routed] of await learnedTierRoutes(workflows, modelEnv, (tier) => deps.routeOf(undefined, modelEnv, tier, PI_WIRES, undefined, cut))) {
687
733
  if ("why" in routed)
@@ -720,7 +766,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
720
766
  // from. With a grader it compares its answer with the other one (runner/compare-end.ts), on its own cap.
721
767
  // A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
722
768
  // withAudit): at its end, so the shadow's cap is what the run's own left.
723
- 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, {
724
771
  store: deps.store,
725
772
  data: deps.data,
726
773
  ...(deps.env ? { env: deps.env } : {}),
@@ -739,7 +786,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
739
786
  }), { ...audits, launch, ...(run.redact ? { redact: run.redact } : {}) });
740
787
  return {
741
788
  adapter,
742
- facts: ownerFacts,
789
+ facts: factsOn(ownerFacts, chosen.model),
743
790
  session,
744
791
  input,
745
792
  // A trigger's first input is its origin's, the launch's own owner flag kept (run-launch.ts keepInputOrigin).
@@ -750,6 +797,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
750
797
  // The answer's schema: a miss is asked again once (adapter-loop.ts, the output contract's retry), as on pi.
751
798
  ...(body.outputSchema !== undefined ? { outputSchema: body.outputSchema } : {}),
752
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 }),
753
802
  // The run's MCP for a harness with its own client (mcp-run.ts), with its monid endpoints beside it (monid-run.ts):
754
803
  // the catalog tools the session mounts; absent when none.
755
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