@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.59

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 (375) hide show
  1. package/CHANGELOG.md +325 -1
  2. package/README.md +332 -88
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/attach-conformance.js +5 -4
  11. package/dist/box-paths.d.ts +3 -2
  12. package/dist/box-paths.js +5 -4
  13. package/dist/browser-computer.d.ts +3 -8
  14. package/dist/browser-computer.js +12 -35
  15. package/dist/browser-cost.js +94 -20
  16. package/dist/capacity.d.ts +1 -1
  17. package/dist/capacity.js +3 -3
  18. package/dist/chatgpt-plan.d.ts +5 -0
  19. package/dist/chatgpt-plan.js +25 -11
  20. package/dist/claude-login-token.d.ts +15 -11
  21. package/dist/claude-login-token.js +167 -107
  22. package/dist/claude-login.d.ts +76 -31
  23. package/dist/claude-login.js +426 -79
  24. package/dist/claude-sign-in.d.ts +3 -0
  25. package/dist/claude-sign-in.js +10 -1
  26. package/dist/cli.js +323 -292
  27. package/dist/composio-made.d.ts +1 -6
  28. package/dist/composio-made.js +1 -6
  29. package/dist/composio-owners.d.ts +26 -0
  30. package/dist/composio-owners.js +36 -0
  31. package/dist/composio-preset.d.ts +56 -23
  32. package/dist/composio-preset.js +173 -77
  33. package/dist/composio-triggers.d.ts +4 -4
  34. package/dist/composio-triggers.js +6 -7
  35. package/dist/compute-cost.js +11 -2
  36. package/dist/computer-attach.d.ts +6 -3
  37. package/dist/computer-attach.js +41 -29
  38. package/dist/computer-held-routes.d.ts +1 -1
  39. package/dist/computer-held-routes.js +9 -4
  40. package/dist/computer-keys.d.ts +11 -1
  41. package/dist/computer-keys.js +26 -1
  42. package/dist/computer-record.js +3 -1
  43. package/dist/computer-view.d.ts +5 -3
  44. package/dist/computer-view.js +10 -6
  45. package/dist/computer-viewer.js +36 -7
  46. package/dist/computers.d.ts +2 -1
  47. package/dist/computers.js +6 -3
  48. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  49. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  50. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  51. package/dist/console/assets/share-L84tlUDW.js +6 -0
  52. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  53. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  54. package/dist/console/index.html +4 -3
  55. package/dist/console/share.html +17 -0
  56. package/dist/decisions.d.ts +17 -7
  57. package/dist/decisions.js +41 -15
  58. package/dist/dial-relay.js +10 -4
  59. package/dist/docker-daemon.js +4 -5
  60. package/dist/docker-host-addresses.js +29 -11
  61. package/dist/email/account.d.ts +6 -0
  62. package/dist/email/account.js +6 -0
  63. package/dist/email/authentication.d.ts +21 -0
  64. package/dist/email/authentication.js +106 -0
  65. package/dist/email/email-faux.d.ts +11 -2
  66. package/dist/email/email-faux.js +21 -5
  67. package/dist/email/mail.d.ts +25 -0
  68. package/dist/email/mail.js +58 -2
  69. package/dist/email/names.js +2 -2
  70. package/dist/email/tools.d.ts +9 -4
  71. package/dist/email/tools.js +95 -13
  72. package/dist/env-switch.d.ts +12 -2
  73. package/dist/env-switch.js +23 -3
  74. package/dist/errors.d.ts +1 -0
  75. package/dist/errors.js +2 -0
  76. package/dist/fal-price.d.ts +11 -1
  77. package/dist/fal-price.js +33 -0
  78. package/dist/faux-computers.js +1 -1
  79. package/dist/filed-answer.d.ts +2 -2
  80. package/dist/filed-answer.js +2 -2
  81. package/dist/graph-served.d.ts +10 -5
  82. package/dist/graph-served.js +40 -10
  83. package/dist/handed-values.js +1 -2
  84. package/dist/harness-check.d.ts +2 -1
  85. package/dist/harness-check.js +45 -12
  86. package/dist/harness-keys.js +9 -6
  87. package/dist/harness-opencode/facts.js +2 -0
  88. package/dist/harness-recipe-entry.d.ts +9 -3
  89. package/dist/harness-recipe-entry.js +18 -9
  90. package/dist/harness-recipe.d.ts +21 -0
  91. package/dist/harness-recipe.js +25 -3
  92. package/dist/harness-table.d.ts +8 -0
  93. package/dist/harness-table.js +17 -6
  94. package/dist/helper-env.d.ts +4 -1
  95. package/dist/helper-env.js +4 -1
  96. package/dist/host-check.d.ts +2 -3
  97. package/dist/host-check.js +13 -7
  98. package/dist/hosted-search.js +1 -1
  99. package/dist/import.d.ts +11 -8
  100. package/dist/import.js +437 -186
  101. package/dist/key-refusal.d.ts +9 -2
  102. package/dist/key-refusal.js +86 -32
  103. package/dist/learn/audit.d.ts +8 -5
  104. package/dist/learn/audit.js +15 -7
  105. package/dist/learn/compile.d.ts +5 -2
  106. package/dist/learn/compile.js +45 -21
  107. package/dist/learn/field-check.d.ts +111 -0
  108. package/dist/learn/field-check.js +174 -0
  109. package/dist/learn/ledger.d.ts +32 -29
  110. package/dist/learn/ledger.js +26 -19
  111. package/dist/learn/promote.d.ts +79 -36
  112. package/dist/learn/promote.js +60 -65
  113. package/dist/learn/secrets.d.ts +4 -0
  114. package/dist/learn/secrets.js +12 -0
  115. package/dist/learned-nodes.d.ts +8 -5
  116. package/dist/learned-nodes.js +8 -5
  117. package/dist/learned-workflow.d.ts +2 -1
  118. package/dist/learned-workflow.js +13 -10
  119. package/dist/learning-cost.d.ts +25 -8
  120. package/dist/learning-cost.js +23 -8
  121. package/dist/learning-setting.d.ts +6 -0
  122. package/dist/learning-setting.js +11 -1
  123. package/dist/listen-first.d.ts +5 -4
  124. package/dist/listen-first.js +4 -5
  125. package/dist/live-reach.d.ts +7 -0
  126. package/dist/live-reach.js +7 -0
  127. package/dist/mcp-api-only-origins.d.ts +15 -0
  128. package/dist/mcp-api-only-origins.js +40 -0
  129. package/dist/mcp-gateway.d.ts +16 -2
  130. package/dist/mcp-gateway.js +41 -3
  131. package/dist/mcp-oauth.d.ts +1 -1
  132. package/dist/mcp-oauth.js +3 -2
  133. package/dist/mcp-probe.d.ts +3 -0
  134. package/dist/mcp-probe.js +3 -0
  135. package/dist/mcp-secret-writes.d.ts +24 -2
  136. package/dist/mcp-secret-writes.js +30 -2
  137. package/dist/mcp-servers-store.d.ts +52 -14
  138. package/dist/mcp-servers-store.js +165 -61
  139. package/dist/mcp-sources.d.ts +1 -2
  140. package/dist/mcp-sources.js +1 -2
  141. package/dist/mcp-store.d.ts +5 -5
  142. package/dist/mcp-store.js +3 -3
  143. package/dist/mcp.js +1 -1
  144. package/dist/model-gateway.d.ts +1 -1
  145. package/dist/model-gateway.js +20 -36
  146. package/dist/ollama-provider.d.ts +23 -9
  147. package/dist/ollama-provider.js +49 -20
  148. package/dist/openapi.js +202 -51
  149. package/dist/otel/genai.d.ts +83 -7
  150. package/dist/otel/genai.js +69 -9
  151. package/dist/otel/tracer.d.ts +42 -13
  152. package/dist/otel/tracer.js +241 -56
  153. package/dist/page.d.ts +7 -1
  154. package/dist/page.js +76 -22
  155. package/dist/paid-calls.d.ts +6 -4
  156. package/dist/paid-calls.js +15 -7
  157. package/dist/place-offers.d.ts +55 -34
  158. package/dist/place-offers.js +93 -54
  159. package/dist/place.d.ts +13 -14
  160. package/dist/place.js +56 -41
  161. package/dist/print.js +1 -1
  162. package/dist/provider.d.ts +3 -2
  163. package/dist/provider.js +17 -8
  164. package/dist/redact/match.d.ts +27 -9
  165. package/dist/redact/match.js +266 -57
  166. package/dist/run-census.d.ts +1 -1
  167. package/dist/run-census.js +4 -5
  168. package/dist/run-cut.js +4 -5
  169. package/dist/run-export-store.d.ts +15 -0
  170. package/dist/run-export-store.js +30 -0
  171. package/dist/run-export.d.ts +139 -0
  172. package/dist/run-export.js +379 -0
  173. package/dist/run-file-cut.d.ts +5 -0
  174. package/dist/run-file-cut.js +13 -0
  175. package/dist/run-launch.js +16 -3
  176. package/dist/run-model-key.d.ts +15 -6
  177. package/dist/run-model-key.js +30 -31
  178. package/dist/run-reads-over-store.js +4 -4
  179. package/dist/run-secrets.js +3 -5
  180. package/dist/run-timeline-served.js +3 -1
  181. package/dist/runnable.js +2 -2
  182. package/dist/runner/adapter-loop.d.ts +35 -18
  183. package/dist/runner/adapter-loop.js +94 -47
  184. package/dist/runner/adapter-run-spec.d.ts +14 -1
  185. package/dist/runner/adapter-run-spec.js +64 -28
  186. package/dist/runner/adapters/pi.js +4 -2
  187. package/dist/runner/audit.d.ts +8 -5
  188. package/dist/runner/audit.js +37 -17
  189. package/dist/runner/beside.js +5 -6
  190. package/dist/runner/claim-secrets.d.ts +10 -3
  191. package/dist/runner/claim-secrets.js +29 -13
  192. package/dist/runner/cli-run-spec.d.ts +18 -0
  193. package/dist/runner/cli-run-spec.js +81 -46
  194. package/dist/runner/compare-end.d.ts +2 -1
  195. package/dist/runner/compare-end.js +25 -10
  196. package/dist/runner/conformance/harness.js +2 -3
  197. package/dist/runner/conformance/subject.d.ts +4 -1
  198. package/dist/runner/harness-loops.js +3 -3
  199. package/dist/runner/held.d.ts +5 -2
  200. package/dist/runner/journal-kinds.d.ts +4 -1
  201. package/dist/runner/journal-kinds.js +22 -4
  202. package/dist/runner/learned-first.js +20 -4
  203. package/dist/runner/learning-end.d.ts +2 -8
  204. package/dist/runner/learning-end.js +11 -19
  205. package/dist/runner/live-ticker.js +7 -5
  206. package/dist/runner/loop-contract.d.ts +0 -2
  207. package/dist/runner/loop.d.ts +7 -0
  208. package/dist/runner/loop.js +1 -0
  209. package/dist/runner/main.js +12 -11
  210. package/dist/runner/mcp-claim.js +21 -5
  211. package/dist/runner/meta-tools.js +3 -2
  212. package/dist/runner/metrics.d.ts +7 -0
  213. package/dist/runner/metrics.js +19 -0
  214. package/dist/runner/model-route.d.ts +10 -7
  215. package/dist/runner/model-route.js +79 -15
  216. package/dist/runner/native-loop.js +10 -8
  217. package/dist/runner/presence.d.ts +1 -4
  218. package/dist/runner/presence.js +6 -8
  219. package/dist/runner/promotion.d.ts +25 -13
  220. package/dist/runner/promotion.js +125 -50
  221. package/dist/runner/redact.d.ts +3 -1
  222. package/dist/runner/redact.js +5 -3
  223. package/dist/runner/responses-fetch.d.ts +36 -0
  224. package/dist/runner/responses-fetch.js +511 -0
  225. package/dist/runner/run-child-host.d.ts +20 -5
  226. package/dist/runner/run-child-host.js +179 -77
  227. package/dist/runner/run-child.js +11 -4
  228. package/dist/runner/runner-check.js +5 -1
  229. package/dist/runner/runner.d.ts +2 -3
  230. package/dist/runner/runner.js +13 -9
  231. package/dist/runner/sdk-loop.js +8 -8
  232. package/dist/runner/spec-holds.d.ts +8 -1
  233. package/dist/runner/spec-holds.js +9 -4
  234. package/dist/runner/workflow-calls.d.ts +9 -0
  235. package/dist/runner/workflow-calls.js +150 -0
  236. package/dist/runner/workflow-first.d.ts +120 -32
  237. package/dist/runner/workflow-first.js +218 -94
  238. package/dist/runner/workflow-spec.js +1 -1
  239. package/dist/runs-over-store.js +8 -7
  240. package/dist/save-once.d.ts +14 -0
  241. package/dist/save-once.js +31 -0
  242. package/dist/scrub-command.d.ts +34 -31
  243. package/dist/scrub-command.js +116 -147
  244. package/dist/sdk/runs.d.ts +6 -0
  245. package/dist/sdk/runs.js +89 -10
  246. package/dist/seal-key.js +4 -4
  247. package/dist/secret-cut.d.ts +3 -0
  248. package/dist/secret-cut.js +7 -1
  249. package/dist/secret-rules.d.ts +8 -1
  250. package/dist/secret-rules.js +482 -53
  251. package/dist/secrets.d.ts +51 -9
  252. package/dist/secrets.js +311 -21
  253. package/dist/server-keys.d.ts +4 -3
  254. package/dist/server-keys.js +4 -3
  255. package/dist/server-secrets-store.js +2 -4
  256. package/dist/server.d.ts +15 -3
  257. package/dist/server.js +312 -80
  258. package/dist/share-context.d.ts +22 -0
  259. package/dist/share-context.js +76 -0
  260. package/dist/shell-lex.d.ts +105 -0
  261. package/dist/shell-lex.js +646 -0
  262. package/dist/sign-ins-store.d.ts +5 -7
  263. package/dist/sign-ins-store.js +12 -16
  264. package/dist/sign-ins.d.ts +7 -11
  265. package/dist/sign-ins.js +40 -41
  266. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  267. package/dist/start-switches.d.ts +6 -5
  268. package/dist/start-switches.js +8 -4
  269. package/dist/stats.d.ts +5 -1
  270. package/dist/stats.js +1 -1
  271. package/dist/store/agent-body.js +2 -2
  272. package/dist/store/dialect.d.ts +4 -0
  273. package/dist/store/dialect.js +1 -0
  274. package/dist/store/index.d.ts +2 -2
  275. package/dist/store/index.js +1 -1
  276. package/dist/store/mcp-record-keys.d.ts +10 -0
  277. package/dist/store/mcp-record-keys.js +13 -0
  278. package/dist/store/postgres/dialect.js +2 -0
  279. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  280. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  281. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  282. package/dist/store/postgres/store.js +4 -0
  283. package/dist/store/schema.d.ts +33 -10
  284. package/dist/store/schema.js +70 -16
  285. package/dist/store/seal.d.ts +4 -1
  286. package/dist/store/sqlite/run-launch.d.ts +3 -10
  287. package/dist/store/sqlite/run-launch.js +12 -23
  288. package/dist/store/sqlite/run-patch.d.ts +17 -10
  289. package/dist/store/sqlite/run-patch.js +50 -13
  290. package/dist/store/sqlite/store.d.ts +3 -0
  291. package/dist/store/sqlite/store.js +116 -34
  292. package/dist/store/store-schema.js +3 -4
  293. package/dist/store/store.d.ts +67 -32
  294. package/dist/store/store.js +14 -11
  295. package/dist/store-reads/analytics.d.ts +2 -1
  296. package/dist/store-reads/analytics.js +7 -5
  297. package/dist/store-reads/learning.d.ts +35 -26
  298. package/dist/store-reads/learning.js +120 -92
  299. package/dist/store-reads/stats.d.ts +2 -2
  300. package/dist/store-reads/stats.js +13 -7
  301. package/dist/store-view.js +10 -7
  302. package/dist/suggestions.d.ts +1 -1
  303. package/dist/suggestions.js +29 -13
  304. package/dist/template-eval.d.ts +72 -9
  305. package/dist/template-eval.js +358 -64
  306. package/dist/timeline/labels.d.ts +1 -1
  307. package/dist/timeline/labels.js +4 -3
  308. package/dist/timeline/timeline.d.ts +23 -11
  309. package/dist/timeline/timeline.js +115 -31
  310. package/dist/timeline/web-calls.d.ts +8 -6
  311. package/dist/timeline/web-calls.js +10 -6
  312. package/dist/tool-gate.d.ts +13 -1
  313. package/dist/tool-gate.js +43 -3
  314. package/dist/tool-keys-store.js +2 -4
  315. package/dist/tool-keys.d.ts +11 -0
  316. package/dist/tool-keys.js +16 -0
  317. package/dist/tool-plane.d.ts +50 -11
  318. package/dist/tool-plane.js +94 -30
  319. package/dist/tools.d.ts +5 -1
  320. package/dist/tools.js +7 -7
  321. package/dist/trigger-email.js +12 -6
  322. package/dist/triggers.d.ts +15 -34
  323. package/dist/triggers.js +119 -126
  324. package/dist/validate.d.ts +8 -1
  325. package/dist/validate.js +163 -23
  326. package/dist/web-fake.d.ts +2 -1
  327. package/dist/web-fake.js +8 -6
  328. package/dist/web-fetch.d.ts +8 -6
  329. package/dist/web-fetch.js +13 -11
  330. package/dist/web-holds.d.ts +32 -0
  331. package/dist/web-holds.js +86 -0
  332. package/dist/web-run.d.ts +32 -5
  333. package/dist/web-run.js +75 -28
  334. package/dist/web-save.js +23 -12
  335. package/dist/web-search.js +14 -25
  336. package/dist/wires.d.ts +4 -3
  337. package/dist/wires.js +5 -4
  338. package/dist/workspace/archil-claim.d.ts +12 -5
  339. package/dist/workspace/archil-claim.js +45 -5
  340. package/dist/workspace/attach.js +52 -19
  341. package/dist/workspace/attached-computers.d.ts +6 -2
  342. package/dist/workspace/attached-computers.js +5 -4
  343. package/dist/workspace/computer-deps.d.ts +23 -6
  344. package/dist/workspace/computer-deps.js +35 -17
  345. package/dist/workspace/computer-for-claim.d.ts +21 -4
  346. package/dist/workspace/computer-for-claim.js +160 -54
  347. package/dist/workspace/computer-intervals.d.ts +2 -0
  348. package/dist/workspace/computer-intervals.js +1 -1
  349. package/dist/workspace/computer-janitor.d.ts +48 -14
  350. package/dist/workspace/computer-janitor.js +153 -44
  351. package/dist/workspace/computer-kept.d.ts +158 -32
  352. package/dist/workspace/computer-kept.js +288 -63
  353. package/dist/workspace/computer-providers.d.ts +8 -3
  354. package/dist/workspace/computer-providers.js +12 -5
  355. package/dist/workspace/index.d.ts +1 -1
  356. package/dist/workspace/index.js +1 -1
  357. package/dist/workspace/local.js +41 -1
  358. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  359. package/dist/workspace/mount-revoke-left.js +72 -0
  360. package/dist/workspace/paired-route.js +4 -5
  361. package/dist/workspace/resolve-computer.d.ts +5 -2
  362. package/dist/workspace/resolve-computer.js +9 -3
  363. package/dist/workspace/run-end-computers.d.ts +11 -5
  364. package/dist/workspace/run-end-computers.js +153 -28
  365. package/dist/workspace/run-tools.d.ts +22 -3
  366. package/dist/workspace/run-tools.js +17 -5
  367. package/dist/workspace/run-workspace.d.ts +14 -1
  368. package/dist/workspace/run-workspace.js +34 -1
  369. package/dist/workspace/workspace.d.ts +6 -0
  370. package/package.json +12 -13
  371. package/skills/agentrun-serve/SKILL.md +5 -2
  372. package/templates/README.md +22 -6
  373. package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
  374. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  375. package/dist/console/assets/index-DPh29cyz.js +0 -747
@@ -22,6 +22,7 @@ import { CAP_REFUSED, CAP_WRAPUP, COMPUTER_NOTE, endsTurn, HOST_PHASE, MESSAGE_O
22
22
  import { raiseFollowUpId } from "../run-view.js";
23
23
  import { durableWait } from "../workflow/pi-versions.js";
24
24
  import { genAiTracing } from "../otel/tracer.js";
25
+ import { tracedAgent, tracedEvent, tracedModel } from "../otel/genai.js";
25
26
  /** The root entries a claim writes before its turn, whatever the run's turns are (its session's key, a phase row, a
26
27
  * takeover's note, its computer's hold, the learning seed it laid, the computer it made): read past when a claim asks
27
28
  * whether the run's root ends on its end (a fresh reopen). */
@@ -45,7 +46,7 @@ import { ClaimRefused, deniedText, noteOf, stopEnd } from "./loop-contract.js";
45
46
  import { deniedText as setToDenyText, ENDED_WHILE_WAITING, refusedText, STOPPED_WHILE_WAITING } from "../refusal-words.js";
46
47
  import { ADAPTER_API } from "../turn-end.js";
47
48
  import { answerText, REFLECT_PREFIX, reflectRequestId } from "./end-of-run.js";
48
- import { agentEntriesOf, approvalOf, BOOKING_WRITE_MS, CLOSE_MS, CUT_STEP_MS, END_PATCH_MS, END_PATCH_UNKNOWN, PARK_SIBLINGS_MS, readAgain, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, INPUT_REQUEST, Interrupted, KernelFault, lastAnswerText, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
49
+ import { agentEntriesOf, approvalOf, BOOKING_WRITE_MS, CLOSE_MS, CUT_STEP_MS, END_PATCH_MS, END_PATCH_UNKNOWN, PARK_SIBLINGS_MS, REAL_TIMER, readAgain, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, INPUT_REQUEST, Interrupted, KernelFault, lastAnswerText, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
49
50
  import { outputMiss, outputRetryWords } from "../answer-json.js";
50
51
  import { answerOnce, HAND_BACK, handBackOf } from "./hand-back.js";
51
52
  import { isComputerCommand, journalHold } from "./computer-journal.js";
@@ -67,6 +68,7 @@ import { Fenced } from "../store/index.js";
67
68
  import { answerAsServed } from "../answer-json.js";
68
69
  import { reserveFor, stepAndAnswerFor, wrappingUp, wrapUpText } from "../wrap-up.js";
69
70
  import { LEARNED_CARD_FIELDS, LEARNED_CLIP, LEARNED_WORKFLOW_TOOL, learnedApprovedTools } from "../learned-workflow.js";
71
+ import { LEARNED_NODES } from "../learned-nodes.js";
70
72
  import { warnHoldShort } from "../print.js";
71
73
  import { feedbackAsk, feedbackOf, jobEndOpen, pendingFeedbackOf } from "./feedback-round.js";
72
74
  import { handbackText, servedAnswerOf, servedAnswerText, WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
@@ -826,11 +828,11 @@ function adapterLoop(specOf, options, deps) {
826
828
  * input's user entry left as pi writes it (its submission, which a re-claim answers from, unchanged), so the Timeline
827
829
  * shows the next user entry with exactly this text as "AgentRun: …". Once per follow-up: the marker names its request
828
830
  * id, and a re-claim that finds one under it writes none (a second would stay open, and could take a person's later
829
- * message of the same words for the server's). A CLI's run records its follow-up through its own record, which carries
830
- * the origin itself. */
831
+ * message of the same words for the server's). A CLI's run records its follow-up in its own record, written here with
832
+ * the origin (once under its request id, as the output retry's is), since the CLI's session keeps no user entry. */
831
833
  const markServerFollowUp = async (theHarness, theRoot, text, requestId) => {
832
834
  if (cliRecord)
833
- return;
835
+ return await cliRecord.followUp(text, requestId, CAP_RAISED_ORIGIN);
834
836
  const marked = (await entriesOf(gate.journal, theRoot.id, context)).some((entry) => entry.kind === MESSAGE_ORIGIN && entry.data?.requestId === requestId);
835
837
  if (marked)
836
838
  return;
@@ -1345,7 +1347,7 @@ function adapterLoop(specOf, options, deps) {
1345
1347
  };
1346
1348
  /** run(claim), its trace ended with it: every span still open ends, with the claim's failure where it failed, handed to
1347
1349
  * the exporter, which sends it in the background (tracer.ts: the claim's end never waits on a collector, and never
1348
- * throws). */
1350
+ * throws). In a run's own process the end is posted to its runner, which exports; neither side flushes for it. */
1349
1351
  async function traced(claim) {
1350
1352
  try {
1351
1353
  const end = await run(claim);
@@ -1555,8 +1557,10 @@ function adapterLoop(specOf, options, deps) {
1555
1557
  }
1556
1558
  // The run's trace, from its claim's start, once its spec says what runs (a restart's spec changes nothing of it).
1557
1559
  // The tracing is made long before (as the loop is): waited for only on the rare claim whose spec beat it.
1558
- trace ??= (tracing ?? (await tracingMade)).now?.open({ startedAt: claimedAt, mcp: (name) => mcp?.catalogOf(specNow?.facts?.hostName?.(name) ?? name) !== undefined });
1559
- trace?.known({ runId: claim.runId, harness: spec.adapter.id, ...(spec.facts?.wire === "plan" ? { plan: true } : {}), ...spec.trace });
1560
+ trace ??= (tracing ?? (await tracingMade)).now?.open({ startedAt: claimedAt });
1561
+ // Its agent, as the spec read it from the store, cut by the runner's redactor and of every secret shape (tracedAgent).
1562
+ const { agent, ...route } = spec.trace ?? {};
1563
+ trace?.known({ runId: claim.runId, ...(agent ? { agent: tracedAgent(agent, deps.redact) } : {}), harness: spec.adapter.id, ...(spec.facts?.wire === "plan" ? { plan: true } : {}), ...route });
1560
1564
  mcp = spec.mcp;
1561
1565
  specNow = spec;
1562
1566
  specKnown = true;
@@ -1861,9 +1865,16 @@ function adapterLoop(specOf, options, deps) {
1861
1865
  return reserveOf(requestFigures(asked));
1862
1866
  };
1863
1867
  let bookingNow;
1864
- // The replaced computer's note (spec.computerNote), until a request carrying it is answered. It goes before the
1865
- // wrap-up: one note per request, so the wrap-up waits a request.
1866
- let computerWords = spec.computerNote;
1868
+ // The computer's notes, in order, each until a request carrying it is answered: the replaced computer's
1869
+ // (spec.computerNote), then where the run's files are (spec.computerFilesNote), unless a COMPUTER_NOTE row marked
1870
+ // `files` says an earlier claim told it. One note per request: the replaced computer's goes before the wrap-up, so
1871
+ // the wrap-up waits a request; the files note goes after a wrap-up that is due, so it never holds one back.
1872
+ const filesTold = spec.computerFilesNote !== undefined && (await entriesOf(gate.journal, wrapUpRoot.id, context))
1873
+ .some((entry) => entry.kind === COMPUTER_NOTE && entry.data?.files === true);
1874
+ const computerNotes = [
1875
+ ...(spec.computerNote !== undefined ? [{ words: spec.computerNote }] : []),
1876
+ ...(spec.computerFilesNote !== undefined && !filesTold ? [{ words: spec.computerFilesNote, files: true }] : []),
1877
+ ];
1867
1878
  // The server's note a request carries (the replaced computer's, else the cap's wrap-up; `cap` says the wrap-up's
1868
1879
  // figures), one request at a time: from its take until that request's admission ends, then, admitted carrying it
1869
1880
  // (`turn`), until that request ends. Told once that request is answered (afterRequest); given back for the next
@@ -1876,7 +1887,8 @@ function adapterLoop(specOf, options, deps) {
1876
1887
  const takeNote = (model, asked) => {
1877
1888
  if (carried && (carried.turn !== undefined || Date.now() - carried.at < WRAP_UP_OFFER_MS))
1878
1889
  return undefined;
1879
- const note = computerWords !== undefined && !reflecting ? { words: computerWords } : wrapUpNote(model, asked);
1890
+ const first = reflecting ? undefined : computerNotes[0];
1891
+ const note = first !== undefined && !first.files ? first : (wrapUpNote(model, asked) ?? first);
1880
1892
  carried = note ? { ...note, at: Date.now() } : undefined;
1881
1893
  return note?.words;
1882
1894
  };
@@ -1894,10 +1906,11 @@ function adapterLoop(specOf, options, deps) {
1894
1906
  what = "the free-limit wrap-up's row";
1895
1907
  }
1896
1908
  else if (told.cap === undefined) {
1897
- computerWords = undefined;
1909
+ if (computerNotes[0]?.words === told.words)
1910
+ computerNotes.shift();
1898
1911
  kind = COMPUTER_NOTE;
1899
- data = { words: rowWords(told.words) };
1900
- what = "the replaced computer's note row";
1912
+ data = { words: rowWords(told.words), ...(told.files ? { files: true } : {}) };
1913
+ what = told.files ? "the computer files note's row" : "the replaced computer's note row";
1901
1914
  }
1902
1915
  else {
1903
1916
  const { leftUsd, capUsd } = told.cap;
@@ -2182,8 +2195,9 @@ function adapterLoop(specOf, options, deps) {
2182
2195
  },
2183
2196
  });
2184
2197
  // A call a stop cut answers whatever its tool said of the abort: it ends interrupted, never as its outcome.
2198
+ // A nesting tool that ended at a refused nested call (a script stopped there) ends refused, as that call did.
2185
2199
  if (record)
2186
- await record.end(toolContext.callId, stopAbort.signal.aborted ? "interrupted" : answer.isError ? "failed" : "done", answer.text);
2200
+ await record.end(toolContext.callId, stopAbort.signal.aborted ? "interrupted" : answer.refused && answer.isError ? "refused" : answer.isError ? "failed" : "done", answer.text);
2187
2201
  // A CLI's question to the person (a turn-ending tool's call, answered): its turn is cut at its next request,
2188
2202
  // as pi's ends here (TurnCut). Any other call's end after it lets the turn go on.
2189
2203
  if (record && endsTurn(tool.name) && !answer.isError && !stopAbort.signal.aborted)
@@ -2283,8 +2297,16 @@ function adapterLoop(specOf, options, deps) {
2283
2297
  carried = undefined;
2284
2298
  }
2285
2299
  unbooked += 1;
2286
- if (ticket && trace && request.paid === undefined)
2287
- chats.set(ticket.turn, trace.request(request.model, request.route));
2300
+ // Its chat span names the model asked only when the run knows it (a route's model, or one its price table names by
2301
+ // that same id: a CLI's table prices every id as the session's model, so a priced id alone proves nothing, and a
2302
+ // body's model is the client's words), else its route's model; whichever, cut (genai.ts tracedModel).
2303
+ if (ticket && trace && request.paid === undefined) {
2304
+ const traced = specNow?.trace;
2305
+ const routed = request.route === undefined ? traced?.model : traced?.routes?.get(request.route)?.model;
2306
+ const known = (asked) => asked === traced?.model || [...(traced?.routes?.values() ?? [])].some((via) => via.model === asked) || specNow?.runCap.modelOf(asked)?.id === asked;
2307
+ const model = tracedModel(request.model, { known, ...(routed ? { routed } : {}), ...(deps.redact ? { redact: deps.redact } : {}) });
2308
+ chats.set(ticket.turn, trace.request(model, request.route));
2309
+ }
2288
2310
  // The conversation that asked, as its client named it (pi's, one of several asking at once): whose answer reads
2289
2311
  // this request's booking (bookedCost).
2290
2312
  const conversation = request.conversation;
@@ -2458,7 +2480,7 @@ function adapterLoop(specOf, options, deps) {
2458
2480
  // Every harness's events reach its trace first (its tool calls, a plan harness's turns), with a record or without.
2459
2481
  const recorded = record ? onEvent(record) : undefined;
2460
2482
  const traceAnd = (event) => {
2461
- trace?.event(event);
2483
+ trace?.event(tracedEvent(event, { mcp: (name) => mcp?.catalogOf(specNow?.facts?.hostName?.(name) ?? name) !== undefined, ...(deps.redact ? { redact: deps.redact } : {}) }));
2462
2484
  recorded?.(event);
2463
2485
  };
2464
2486
  const io = { writer, models: counted, signal: deps.signal, onEvent: traceAnd, gate: bridgeGate, ...(permission ? { permission } : {}), hostTool: hosted, ...(ownCalls ? { ownCalls } : {}), bookedCost, keepCalls, ...(record ? {} : { nestedEnded }) };
@@ -2736,13 +2758,6 @@ function adapterLoop(specOf, options, deps) {
2736
2758
  memo: async (_key, value) => (typeof value === "function" ? value() : value),
2737
2759
  });
2738
2760
  const serveFirst = async (first) => {
2739
- // The session's learned_workflow as this loop wraps a tool, but nesting nothing of the harness's: a call a crash
2740
- // cut is ended interrupted and handed back, never run again (its record's start is not marked `nests`).
2741
- const bare = spec.session.tools.find((tool) => tool.name === LEARNED_WORKFLOW_TOOL);
2742
- if (!bare || !tools.some((tool) => tool.name === LEARNED_WORKFLOW_TOOL))
2743
- return undefined;
2744
- const { nests: _nests, ...plain } = bare;
2745
- const learned = hosted(plain);
2746
2761
  const [on, theRoot, theGate] = [harness, root, gate];
2747
2762
  const args = { name: first.name, input: first.input };
2748
2763
  const call = { callId: WORKFLOW_FIRST_CALL, tool: LEARNED_WORKFLOW_TOOL, args };
@@ -2766,9 +2781,17 @@ function adapterLoop(specOf, options, deps) {
2766
2781
  if (kept?.outcome === "answered")
2767
2782
  return { outcome: "answered", text: ended?.output ?? "" };
2768
2783
  // Handed back on an earlier claim whose handback never reached the agent (the session is still new): sent now, in
2769
- // the words that claim would have sent (its why included).
2784
+ // the words that claim would have sent (its why included), with or without the tool now (the money rule may have
2785
+ // taken the workflow off it since: workflow-first.ts toolStopsOf).
2770
2786
  if (kept)
2771
2787
  return job(ended ? taken(recorded(ended)).text : "");
2788
+ // The session's learned_workflow as this loop wraps a tool, but nesting nothing of the harness's: a call a crash
2789
+ // cut is ended interrupted and handed back, never run again (its record's start is not marked `nests`).
2790
+ const bare = spec.session.tools.find((tool) => tool.name === LEARNED_WORKFLOW_TOOL);
2791
+ if (!bare || !tools.some((tool) => tool.name === LEARNED_WORKFLOW_TOOL))
2792
+ return undefined;
2793
+ const { nests: _nests, ...plain } = bare;
2794
+ const learned = hosted(plain);
2772
2795
  if (!ended) {
2773
2796
  // A deny before anything is written leaves the run its agent's, as if the workflow were not there.
2774
2797
  const before = await spec.gate?.({ callId: call.callId, tool: call.tool, args });
@@ -2780,6 +2803,8 @@ function adapterLoop(specOf, options, deps) {
2780
2803
  await rec.person(spec.input);
2781
2804
  }
2782
2805
  let answer;
2806
+ // Refused at its gate, on this claim or the one before: it ran nothing.
2807
+ let refused = ended?.status === "refused";
2783
2808
  if (ended)
2784
2809
  answer = recorded(ended);
2785
2810
  else {
@@ -2794,6 +2819,7 @@ function adapterLoop(specOf, options, deps) {
2794
2819
  else
2795
2820
  await rec.refused(WORKFLOW_FIRST_CALL, LEARNED_WORKFLOW_TOOL, args, false, verdict.deny);
2796
2821
  answer = { text: verdict.deny, isError: true };
2822
+ refused = true;
2797
2823
  }
2798
2824
  else {
2799
2825
  // A CLI's record takes the call's start and end inside the wrapper; pi's step record here.
@@ -2810,9 +2836,14 @@ function adapterLoop(specOf, options, deps) {
2810
2836
  answer = taken(answer);
2811
2837
  const outcome = answer.isError ? "handed_back" : "answered";
2812
2838
  const data = { workflow: first.name, digest: first.digest, ...(first.promotion !== undefined ? { promotion: first.promotion } : {}), revision: first.revision, call: WORKFLOW_FIRST_CALL, outcome };
2839
+ // A call refused at its gate keeps its record as one the tool refused does (learned-nodes.ts LEARNED_NODES
2840
+ // `refused`): no workflow ran it, so the money rule charges none and the run names none.
2841
+ const refusal = refused ? { call: WORKFLOW_FIRST_CALL, workflow: first.name, digest: first.digest, caller: "platform", nodes: [], ended: "failed", refused: true } : undefined;
2813
2842
  await on.commit(async (tx) => {
2814
2843
  if (outcome === "answered")
2815
2844
  await tx.appendEntry(theRoot.id, { kind: KINDS.message, data: { role: "model", text: answer.text, at: now() } });
2845
+ if (refusal)
2846
+ await tx.appendEntry(theRoot.id, { kind: LEARNED_NODES, data: refusal });
2816
2847
  await tx.appendEntry(theRoot.id, { kind: WORKFLOW_FIRST, data: data });
2817
2848
  }, context);
2818
2849
  return outcome === "answered" ? { outcome, text: answer.text } : job(answer.text);
@@ -2822,9 +2853,10 @@ function adapterLoop(specOf, options, deps) {
2822
2853
  // under way (the handback sent) never runs it again.
2823
2854
  let served;
2824
2855
  // A workflow this run already served or handed back on an earlier claim (its end on the root): recovered whatever the
2825
- // money rule says now, so a crash before the handback never makes the agent redo finished work.
2826
- const keptFirst = spec.workflowFirst || !spec.workflowRevise || followedUp || firstUnplaced || session.state !== "new" ? undefined : findData(await entriesOf(gate.journal, root.id, context), WORKFLOW_FIRST, () => true);
2827
- const recovered = keptFirst && keptFirst.outcome !== "needs_revision" ? { name: keptFirst.workflow, digest: keptFirst.digest, revision: keptFirst.revision, input: {}, ...(spec.workflowRevise?.outputSchema !== undefined ? { outputSchema: spec.workflowRevise.outputSchema } : {}) } : undefined;
2856
+ // money rule says now (its stop, or its fail-closed read of an unreadable past), so a crash before the handback never
2857
+ // makes the agent redo finished work. Only a run that learns keeps one.
2858
+ const keptFirst = spec.workflowFirst || !spec.learningLaid || followedUp || firstUnplaced || session.state !== "new" ? undefined : findData(await entriesOf(gate.journal, root.id, context), WORKFLOW_FIRST, () => true);
2859
+ const recovered = keptFirst && keptFirst.outcome !== "needs_revision" ? { name: keptFirst.workflow, digest: keptFirst.digest, revision: keptFirst.revision, input: {}, ...(spec.outputSchema !== undefined ? { outputSchema: spec.outputSchema } : {}) } : undefined;
2828
2860
  const firstToServe = spec.workflowFirst ?? recovered;
2829
2861
  // A fitting workflow the money rule stopped: why, on the root, once for the run, as the agent takes it.
2830
2862
  if (spec.workflowRevise && !followedUp && !firstUnplaced && session.state === "new") {
@@ -3216,7 +3248,7 @@ function adapterLoop(specOf, options, deps) {
3216
3248
  return { deny: wrapUpDeny };
3217
3249
  // A CLI bridge's call run again after an attempt that may have been sent: its refusals say so (RAN_UNKNOWN).
3218
3250
  const replayed = call.replayed === true;
3219
- const given = (await spec.gate?.(kernelCall, { ...(replayed ? { replayed } : {}), ran: ranOf })) ?? "allow";
3251
+ const given = (await spec.gate?.(kernelCall, { ...(replayed ? { replayed } : {}), ran: ranOf, approved: approvedOf })) ?? "allow";
3220
3252
  // An ask with its card's own fields (a learned workflow's MCP actions set to ask, each with its arguments' shape), or
3221
3253
  // with the reason a call its setting allows asks anyway (`because`).
3222
3254
  const shown = typeof given === "object" && "ask" in given ? given.ask : undefined;
@@ -3410,6 +3442,17 @@ function adapterLoop(specOf, options, deps) {
3410
3442
  async function ranOf(tool) {
3411
3443
  return toolCalls(await agentEntriesOf(gate.journal, context), tool);
3412
3444
  }
3445
+ /** Whether a person approved the call `callId`, as answerOf reads it: its answer in the journal stands; else the
3446
+ * approve or deny for it among the claim's commands (read once they are all with the loop, deps.delivered), which
3447
+ * answerOf takes next. */
3448
+ async function approvedOf(callId) {
3449
+ const conversation = await harness.root(context);
3450
+ const known = findData(await entriesOf(gate.journal, conversation.id, context), KINDS.answer, (data) => data.callId === callId);
3451
+ if (known)
3452
+ return known.approved;
3453
+ await (deps.delivered ?? Promise.resolve());
3454
+ return inbox.find((command) => (command.kind === "approve" || command.kind === "deny") && approvalOf(command) === callId)?.kind === "approve";
3455
+ }
3413
3456
  async function askStands(callId) {
3414
3457
  standing ??= (async () => {
3415
3458
  const conversation = await harness.root(context);
@@ -3550,10 +3593,10 @@ function adapterLoop(specOf, options, deps) {
3550
3593
  return turnOfRequest(on, conversation, last.requestId);
3551
3594
  }
3552
3595
  /** How the job's own turn ended (`data`, and a CLI's error answer `failedWith`), as this claim decided it, kept on the
3553
- * root before the end-of-run step asks its first turn (KINDS.jobEnd), for a run with a step to ask (stepOf). Kept with
3554
- * its time, now, which it answers; with no step to ask, nothing is kept. */
3596
+ * root before the end-of-run step asks its first turn (KINDS.jobEnd), for a run with a step to ask (its spec's endOfRun).
3597
+ * Kept with its time, now, which it answers; with no step to ask, nothing is kept. */
3555
3598
  async function keepJobEnd(on, conversation, spec, data, failedWith) {
3556
- if (!stepOf(spec))
3599
+ if (!spec.endOfRun)
3557
3600
  return undefined;
3558
3601
  const kept = jobEndOf(data, failedWith, now());
3559
3602
  await on.commit((tx) => tx.appendEntry(conversation.id, { kind: KINDS.jobEnd, data: kept }), context);
@@ -3727,9 +3770,7 @@ function adapterLoop(specOf, options, deps) {
3727
3770
  return kept && typeof kept === "object" && !Array.isArray(kept) ? kept : undefined;
3728
3771
  };
3729
3772
  }
3730
- /** The run's end-of-run step: its spec's (AdapterRunSpec.endOfRun) when it has one, else the loop's deps'. */
3731
- const stepOf = (spec) => spec.endOfRun ?? deps.endOfRun;
3732
- /** The end-of-run step (stepOf: the spec's, else LoopDeps.endOfRun), asked once: the rows to stage with the end; `stopped` when a person's stop
3773
+ /** The end-of-run step (its spec's endOfRun; none without one), asked once: the rows to stage with the end; `stopped` when a person's stop
3733
3774
  * came during it; `interrupted` when the claim was lost or the runner is closing (no end is written, and the next claim
3734
3775
  * asks it again). A step that throws on its own writes the end without rows: the run's end never waits on it. `over`:
3735
3776
  * the claim's overCap, read after each turn the step asks (askEndOfRun). */
@@ -3741,7 +3782,7 @@ function adapterLoop(specOf, options, deps) {
3741
3782
  return { kind: "interrupted" };
3742
3783
  return undefined;
3743
3784
  };
3744
- const step = stepOf(spec);
3785
+ const step = spec.endOfRun;
3745
3786
  if (!step)
3746
3787
  return { kind: "rows", also: [] };
3747
3788
  if (!spec.agentId)
@@ -3767,11 +3808,11 @@ function adapterLoop(specOf, options, deps) {
3767
3808
  return cut() ?? (console.warn(`[runner] ${claim.runId}: its end-of-run step failed: ${said(error)}`), { kind: "rows", also: [] });
3768
3809
  }
3769
3810
  }
3770
- /** What a run cut before it could look back keeps beside its end (LoopDeps.endOfRun with `cut`, never asking): a
3811
+ /** What a run cut before it could look back keeps beside its end (its spec's endOfRun with `cut`, never asking): a
3771
3812
  * person's stop, before or during the end-of-run turn, or a fault. Bounded (CUT_STEP_MS): a step that reads a stalled
3772
3813
  * store, or throws, keeps nothing, and the end is never held up by it. */
3773
3814
  async function cutRows(claim, spec, cut) {
3774
- const step = stepOf(spec);
3815
+ const step = spec.endOfRun;
3775
3816
  if (!step || !spec.agentId)
3776
3817
  return [];
3777
3818
  const refuse = () => Promise.reject(new Error("a cut run's end-of-run step asks nothing"));
@@ -3886,9 +3927,9 @@ function adapterLoop(specOf, options, deps) {
3886
3927
  const spec = specNow;
3887
3928
  if (!spec?.endPatch && !spec?.endCost)
3888
3929
  return {};
3930
+ const bound = spec.endPatchTimer ?? REAL_TIMER;
3889
3931
  let timer;
3890
- const boundMs = spec.endPatchMs ?? END_PATCH_MS;
3891
- const late = new Promise((resolve) => (timer = setTimeout(() => resolve("late"), boundMs)));
3932
+ const late = new Promise((resolve) => (timer = bound.setTimeout(() => resolve("late"), END_PATCH_MS)));
3892
3933
  // The cost, read apart (AdapterRunSpec.endCost): a patch whose metrics run late or fail never takes it with them. A
3893
3934
  // read that fails is read again within the same bound (END_COST_TRIES): the stored cost is every reader's answer
3894
3935
  // (the list, the view, usage), so a null there is kept only when the booking could not be read at all.
@@ -3896,7 +3937,7 @@ function adapterLoop(specOf, options, deps) {
3896
3937
  const cost = endCost
3897
3938
  ? readAgain(endCost, late, (error, tries, last) => console.warn(last ? `[runner] its end's cost failed ${tries} times, last: ${said(error)}; the end is written with its cost unknown` : `[runner] its end's cost failed: ${said(error)}; read again`)).then((answer) => {
3898
3939
  if (answer === "late")
3899
- console.warn(`[runner] its end's cost gave no answer within ${boundMs / 1000} s; the end is written with its cost unknown`);
3940
+ console.warn(`[runner] its end's cost gave no answer within ${END_PATCH_MS / 1000} s; the end is written with its cost unknown`);
3900
3941
  return answer === "late" || answer === "failed" ? { costUsd: null, costUpperBound: false } : answer;
3901
3942
  })
3902
3943
  : undefined;
@@ -3906,7 +3947,7 @@ function adapterLoop(specOf, options, deps) {
3906
3947
  try {
3907
3948
  const patch = await Promise.race([spec.endPatch(data), late]);
3908
3949
  if (patch === "late") {
3909
- console.warn(`[runner] its end's patch gave no answer within ${boundMs / 1000} s; the end is written with its ${cost ? "metrics" : "cost and metrics"} unknown`);
3950
+ console.warn(`[runner] its end's patch gave no answer within ${END_PATCH_MS / 1000} s; the end is written with its ${cost ? "metrics" : "cost and metrics"} unknown`);
3910
3951
  return END_PATCH_UNKNOWN;
3911
3952
  }
3912
3953
  return patch ?? {};
@@ -3921,7 +3962,7 @@ function adapterLoop(specOf, options, deps) {
3921
3962
  return read ? { ...patch, ...read } : patch;
3922
3963
  }
3923
3964
  finally {
3924
- clearTimeout(timer);
3965
+ bound.clearTimeout(timer);
3925
3966
  }
3926
3967
  }
3927
3968
  /** The run parked at its cap: its pending budget as an agentrun.budget entry, in one commit with the run parked in the
@@ -4022,12 +4063,18 @@ function adapterLoop(specOf, options, deps) {
4022
4063
  }
4023
4064
  /** At a park for `cause`, before its seal: a pass whose spec keeps its computer (AdapterRunSpec.keptWords) has it kept
4024
4065
  * for the resume at its release (closeSession), once the run's timeline says so, for the person deciding; its owner's
4025
- * live view is closed saying the cause. A write that fails (the fence's refusal: a lost claim, whose run a later claim
4026
- * may hold already) keeps nothing: the computer goes as at the run's end. */
4066
+ * live view is closed saying the cause. The keep's row is written first (AdapterRunSpec.keep), under the claim's
4067
+ * fence: a park that keeps nothing (another runner's row still there, a write that failed, a claim that lost the run
4068
+ * and so writes nothing) says nothing of a keep, and its computer goes as at
4069
+ * the run's end. A commit that fails (the fence's refusal: a lost claim, whose run a later claim may hold already)
4070
+ * keeps nothing either: the computer goes as at the run's end, and its row with it. */
4027
4071
  async function keepAtPark(on, cause) {
4028
- const summary = specNow?.keptWords;
4072
+ const summary = specNow?.keptWords?.();
4029
4073
  if (!summary)
4030
4074
  return;
4075
+ const keep = specNow?.keep;
4076
+ if (keep && !(await keep().catch(() => false)))
4077
+ return;
4031
4078
  parkedNow = await on.commit((tx) => tx.appendEntry(ROOT_CONVERSATION_ID, { kind: HOST_PHASE, data: { summary, at: Date.now() } }), context).then(() => cause, () => undefined);
4032
4079
  }
4033
4080
  /** The run's pause at its cap: its agentrun.budget entry, in one commit with the run parked in the cap's words. */
@@ -20,6 +20,7 @@ import { type ClaimModelKey } from "./claim-secrets.js";
20
20
  import { type ClaimMcp } from "./mcp-run.js";
21
21
  import { type AdapterLoopOptions, type AdapterRun, type AdapterRunSpec, hostLifecycle } from "./adapter-loop.js";
22
22
  import { type RunnerHarness } from "./adapters/index.js";
23
+ import { type BoundTimer } from "./loop.js";
23
24
  import { type SubagentTier } from "./subagent.js";
24
25
  import { type Claim, type Journal } from "./loop-contract.js";
25
26
  import type { ReplayCalls } from "../learn/replay-calls.js";
@@ -67,6 +68,8 @@ export interface ClaimComputer {
67
68
  release(): Promise<void>;
68
69
  /** The release at the run's park, which keeps the computer it `keeps` (computer-for-claim.ts ClaimComputer.park). */
69
70
  park?(): Promise<boolean>;
71
+ /** The park's keep written before the run's timeline says it (computer-for-claim.ts ClaimComputer.keepRow). */
72
+ keepRow?(): Promise<boolean>;
70
73
  }
71
74
  /** The one shared claim-time computer every spec takes (computer-for-claim.ts), passed in by the runner: the composer's
72
75
  * (workspace/computer-deps.ts computerDepsFrom), or a test's stand-in. */
@@ -102,6 +105,9 @@ export interface AdapterSpecDeps {
102
105
  readonly log?: (message: string) => void;
103
106
  /** For tests: a learning run's grade bound, as a signal (learning-dispatch.ts gradeBound). Default: GRADE_TIMEOUT_MS. */
104
107
  readonly gradeBound?: () => AbortSignal;
108
+ /** For tests: the timer a native or SDK run's end arms its bound on (END_PATCH_MS, loop.ts) while it waits on its cost
109
+ * and metrics read, as the adapter loop's spec.endPatchTimer. Default: the real one (REAL_TIMER). */
110
+ readonly endPatchTimer?: BoundTimer;
105
111
  /** The one shared claim-time computer (computer-for-claim.ts), for both the pi and the CLI spec: none for a runner place.
106
112
  * The runner gives it; a test gives its own. */
107
113
  readonly computerForClaim: ComputerForClaim;
@@ -159,6 +165,9 @@ export interface AdapterSpecDeps {
159
165
  * on purpose does not wait out MODEL_RETRY's two and a half minutes. No environment variable, flag or setting maps onto
160
166
  * it; absent, MODEL_RETRY and MODEL_STREAM. */
161
167
  readonly modelRetry?: Pick<AdapterLoopOptions, "retry" | "stream">;
168
+ /** The runs' GenAI tracing (AdapterLoopOptions.tracing): in a run's own process, the one posted to its runner
169
+ * (run-child.ts); absent, this process's own. */
170
+ readonly tracing?: AdapterLoopOptions["tracing"];
162
171
  /** web_save's download slots (ToolHost.saveSlots): in a run's own process, its runner's (run-child.ts). */
163
172
  readonly saveSlots?: SaveSlots;
164
173
  }
@@ -257,7 +266,8 @@ export declare function modelAskOf(pinned: {
257
266
  * The run's computer once off for the run (RunGate.computerOff): a call of its tools is refused before any settings read.
258
267
  * `turnedOff`: an earlier claim turned it off (computer-journal.ts computerTurnedOff), so this claim's gate starts off.
259
268
  * `onComputerOff`: told the computer's kind, and awaited, when this claim's first deny of a call of its tools turns it off,
260
- * for the run's journal (computer-journal.ts recordComputerOff), so a later claim starts it off too.
269
+ * for the run's journal (computer-journal.ts recordComputerOff), so a later claim starts it off too. The gate's
270
+ * `computerOff` says whether it is off now, so a park lets it go instead of keeping it (spec-holds.ts Held.computerOff).
261
271
  */
262
272
  /** The run's tool permissions as a learned workflow's call nodes are held to them (learned-workflow.ts policy, denyFrom,
263
273
  * refresh): the same gate as the run's own calls, its settings read again from the store before each call node. */
@@ -269,6 +279,7 @@ export type RunPermissions = {
269
279
  export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pick<Claim, "runId">, revision: {
270
280
  kind: string;
271
281
  body: {
282
+ tools?: readonly string[];
272
283
  toolSettings?: unknown;
273
284
  harness?: string;
274
285
  approvals?: Approvals;
@@ -283,6 +294,8 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
283
294
  readonly permissions: RunPermissions;
284
295
  readonly learn: (flows: readonly LearnedWorkflow[]) => void;
285
296
  readonly askedOn: (host: ToolHost) => void;
297
+ readonly computerOff: () => boolean; /** Whether the run can write a file now, as its gate decides a save_as (RunGate.writeBar): what its files note and computer_screenshot's save_as are offered by. */
298
+ readonly writes: () => boolean;
286
299
  }>;
287
300
  /** The server's tool settings from the store now; a read that throws is unread (no value of it said). A workflow's call
288
301
  * and model nodes read theirs through it too (workflow-spec.ts callPolicyOf), so both gates fail closed alike. */