@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
@@ -39,6 +39,21 @@ export function browserPrice(provider, env) {
39
39
  /** Up to the millionth of a dollar, so the cap's words name a figure never below the hold. */
40
40
  const microUsd = (usd) => Math.ceil(Math.round(usd * 1e12) / 1e6) / 1e6;
41
41
  export { BROWSER_CHARGED };
42
+ /** Each browser step that is owed, by name: booked and held past the cap's rule (kernel/cap port.ts), for money its
43
+ * provider is already owed outside any call. The one place this file sets owed (owed-pin.test.mjs pins the list and
44
+ * each name's one use): a new owed step is named here, and reviewed there. */
45
+ const OWED = {
46
+ /** A charge's time, as charged (bookOnLedger): under no call too (a release, its top-up). */
47
+ charge: { owed: true },
48
+ /** A kept session's reserve, held from the reopen (its time since its last charge and its next stretch). */
49
+ reopenReserve: { owed: true },
50
+ /** That reserve held again at one stretch once its charge booked the time before it. */
51
+ reserveAgain: { owed: true },
52
+ /** A delayed release's hold, until its release is billed. */
53
+ delayedRelease: { owed: true },
54
+ /** A person's carried time, until the session's next charge books it. */
55
+ personTime: { owed: true },
56
+ };
42
57
  /** The tool a browser step on the run's one ledger names (main's charge's `tool`, the timeline's BROWSER_CHARGE): the run
43
58
  * view folds its charge into its call's row, as main's. */
44
59
  const BROWSER_TOOL = "browser";
@@ -62,13 +77,16 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
62
77
  * it held being booked by the session's own charge). `admitted`: the ledger's answer (refused in the cap's words when
63
78
  * it has no room; refused with no ledger, where nothing is held). `owed`: time its provider is already owed, run
64
79
  * outside any call (a person's carried time, a session held from a reopen, a delayed release): never refused. A fresh
65
- * session's reserve and a person's time to come (personTime) are not owed: the cap may refuse them. */
80
+ * session's reserve and a person's time to come (personTime) are not owed: the cap may refuse them. `after`: the hold
81
+ * this one takes the place of, given back (its drop's promise): this one is asked only once that has landed, so the
82
+ * ledger never judges the two side by side, whatever order it books them in. */
66
83
  const holdOf = (name, usd, basis, options = {}) => {
67
84
  if (!paid)
68
85
  return { hold: { usd, drop: () => { } }, admitted: Promise.resolve({ refused: unbookedRefusal(name) }) };
69
86
  const booking = paid;
70
87
  const id = `browser:${name}#${(ledgerSeq += 1)}`;
71
- const admitted = booking.admit({ id, name, holdUsd: usd, basis, chargedBy: provider, tool: BROWSER_TOOL, hold: true, ...(options.tag ? { tag: options.tag } : {}), ...(options.owed ? { owed: true } : {}) }).then(() => ({}), (error) => {
88
+ const ask = () => booking.admit({ id, name, holdUsd: usd, basis, chargedBy: provider, tool: BROWSER_TOOL, hold: true, ...(options.tag ? { tag: options.tag } : {}), ...(options.owed ? { owed: true } : {}) });
89
+ const admitted = (options.after ? options.after.then(ask, ask) : ask()).then(() => ({}), (error) => {
72
90
  const capped = error?.code === "spend_cap_reached";
73
91
  const refused = capped ? String(error.message) : `${name} could not be held: ${String(error?.message ?? error)}`;
74
92
  // The cap's own refusal, as the run's pause reads it (a room refusal's figures; a refusal for good).
@@ -78,17 +96,18 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
78
96
  });
79
97
  pending.add(admitted);
80
98
  void admitted.finally(() => pending.delete(admitted));
81
- let dropped = false;
99
+ let settled;
82
100
  const hold = {
83
101
  usd,
84
102
  drop: () => {
85
- if (dropped)
86
- return;
87
- dropped = true;
103
+ if (settled)
104
+ return settled;
88
105
  // Given back: a hold is no charge (its time, when it ran, is booked by the session's own charge), never a $0 one.
89
- const settled = admitted.then((answer) => (answer.refused === undefined ? booking.settle(id, 0, { givenBack: true }) : undefined)).catch(() => undefined);
90
- pending.add(settled);
91
- void settled.finally(() => pending.delete(settled));
106
+ const giving = admitted.then((answer) => (answer.refused === undefined ? booking.settle(id, 0, { givenBack: true }) : undefined)).then(() => undefined, () => undefined);
107
+ settled = giving;
108
+ pending.add(giving);
109
+ void giving.finally(() => pending.delete(giving));
110
+ return giving;
92
111
  },
93
112
  };
94
113
  return { hold, admitted };
@@ -138,9 +157,36 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
138
157
  const carriedSince = (tag, since, now) => (carried.get(tag) ?? []).reduce((sum, { from, to }) => sum + usdOf(Math.max(0, to - Math.max(from, since)) / 1000), 0) +
139
158
  // A person who has the browser now: what of their held time has run is held already, as carried time is.
140
159
  [...(active.get(tag) ?? [])].reduce((sum, { from, to }) => sum + usdOf(Math.max(0, Math.min(to, now) - Math.max(from, since)) / 1000), 0);
141
- /** Each call under way, by its id: its conversation and its hold. */
160
+ /** Each call under way, by its id: its conversation, its hold, `givenBack` (settles once its hold on the run's ledger
161
+ * is given back) and `reserves`, the reserves of the sessions it opened, each asked on the ledger once that has landed
162
+ * (the call returns only once they are held, or refused and acted on). */
142
163
  const calls = new Map();
143
164
  const take = (hold, usd) => void (hold && (hold.usd = Math.max(0, hold.usd - usd)));
165
+ /** Session `tag`'s reserve, one stretch, asked of the cap and not owed: a new session's, or one whose reserve the cap
166
+ * refused before, asked again. Under `call` it is asked once the call's hold is given back (after), in the room that
167
+ * hold kept for it, and the call returns only once it is held, or refused and acted on (reserves): until then the
168
+ * call's own hold covers the session. Refused, its next stretch is held nowhere: that is said, and the cap's own
169
+ * refusal pauses the run, as an ask's refused time does (personTime), so its next request is refused in the cap's words
170
+ * and it parks for a raise. The session is then marked (Open.refused) while this is still its reserve, so its next
171
+ * charge asks again, and once the cap is raised its next stretch is held. A refusal that is not the cap's (a lost
172
+ * claim's) marks nothing: no raise mends it, and the next claim's reopen holds the session. */
173
+ const askReserve = (tag, basis, call) => {
174
+ const reserve = holdOf("this browser session's reserve", stretch, basis, { tag, ...(call ? { after: call.givenBack } : {}) });
175
+ const acted = reserve.admitted.then(async (answer) => {
176
+ if (answer.refused === undefined)
177
+ return;
178
+ const open = sessions.get(tag);
179
+ if (answer.refusal && open?.reserve === reserve.hold)
180
+ open.refused = true;
181
+ log(logLine("browser_reserve_refused", { said: `the reserve of browser session ${tag} was not held on the run's ledger (${answer.refused.slice(0, 200)}): its next stretch is held nowhere` }));
182
+ if (answer.refusal && ledger.pause)
183
+ await ledger.pause(answer.refusal);
184
+ }).catch((error) => void log(logLine("browser_reserve_refused", { said: `the run could not be paused on the refused reserve of browser session ${tag} (${String(error?.message ?? error).slice(0, 200)})` })));
185
+ pending.add(acted);
186
+ void acted.finally(() => pending.delete(acted));
187
+ call?.reserves.push(acted);
188
+ return reserve.hold;
189
+ };
144
190
  /** Recorded in the commit that bills it: a BROWSER_CHARGED under the call that ran it (a release's, under its session's
145
191
  * last call), its money the ledger step's (booked), what it cost or null when its time has no price, and the seconds it
146
192
  * was for, with what `booked` needs. A free provider's time books nothing and holds nothing. */
@@ -161,7 +207,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
161
207
  // Held at its charge (known: it was billed): a claim lost before its settle leaves it booked at that, never unknown
162
208
  // (the kernel's bookCut books an owed step at its hold). A charge of an unknown amount holds nothing.
163
209
  const owes = typeof data.usd === "number" && Number.isFinite(data.usd) && data.usd > 0 ? data.usd : 0;
164
- const step = paidStep(booking, data.call ?? undefined, { name: "this browser session's time", holdUsd: owes, basis: `${provider}'s session time, billed as it was charged`, by: data.charged_by, tool: BROWSER_TOOL, tag: data.tag, owed: true, ref: chargeRef(data) }, async () => undefined, () => data.usd).then((stepped) => void ("refused" in stepped && log(logLine("browser_spend_unbooked", { said: `a browser charge of ${data.tag} was not booked on the run's ledger (${stepped.refused.slice(0, 200)}): the next claim's reopen books it` }))), (error) => void log(logLine("browser_spend_unbooked", { said: `a browser charge of ${data.tag} was not booked on the run's ledger (${String(error?.message ?? error).slice(0, 200)}): the next claim's reopen books it` })));
210
+ const step = paidStep(booking, data.call ?? undefined, { name: "this browser session's time", holdUsd: owes, basis: `${provider}'s session time, billed as it was charged`, by: data.charged_by, tool: BROWSER_TOOL, tag: data.tag, ...OWED.charge, ref: chargeRef(data) }, async () => undefined, () => data.usd).then((stepped) => void ("refused" in stepped && log(logLine("browser_spend_unbooked", { said: `a browser charge of ${data.tag} was not booked on the run's ledger (${stepped.refused.slice(0, 200)}): the next claim's reopen books it` }))), (error) => void log(logLine("browser_spend_unbooked", { said: `a browser charge of ${data.tag} was not booked on the run's ledger (${String(error?.message ?? error).slice(0, 200)}): the next claim's reopen books it` })));
165
211
  pending.add(step);
166
212
  void step.finally(() => pending.delete(step));
167
213
  return step;
@@ -194,13 +240,33 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
194
240
  }
195
241
  else if (session) {
196
242
  take(data.call === null ? undefined : calls.get(data.call)?.hold, Math.max(0, usd - personBooked));
197
- // Its reserve is one stretch again: a kept session's held what it ran before this charge, which booked it.
198
- session.reserve.usd = stretch;
243
+ // Its reserve is one stretch again: a kept session's (a reopen's, a delayed release's) held what it ran before this
244
+ // charge, which booked it. On the run's ledger too, where a hold keeps the figure it was admitted at: that hold is
245
+ // given back for one of a stretch, so the time this charge booked is never held beside it. Owed, as the reserve it
246
+ // takes the place of was: the session is open and its provider bills its time whatever the cap says, so a refusal
247
+ // would only leave that time unheld (a new session's reserve is the cap's to refuse: its room is its call's hold's).
248
+ // Asked once the old one is given back on the ledger (after), so the two are never held side by side there.
249
+ // A session whose reserve the cap refused holds nothing on the ledger: its reserve is asked again (askReserve), not
250
+ // owed, as a new session's is, so a raise since holds its next stretch, and a cap still full refuses it again.
251
+ if (session.refused) {
252
+ session.refused = false;
253
+ session.reserve = askReserve(data.tag, `${provider}'s next stretch of session time, asked again once the cap refused it`, data.call === null ? undefined : calls.get(data.call));
254
+ }
255
+ else if (session.reserve.usd !== stretch) {
256
+ const givenBack = session.reserve.drop();
257
+ session.reserve = holdOf("this browser session's reserve", stretch, `${provider}'s next stretch of session time, held again once its charge booked the time before it`, { ...OWED.reserveAgain, tag: data.tag, after: givenBack }).hold;
258
+ }
199
259
  Object.assign(session, { at: through, call: data.call ?? session.call });
200
260
  }
201
261
  else {
202
- take(data.call === null ? undefined : calls.get(data.call)?.hold, usd + stretch);
203
- sessions.set(data.tag, { cid: data.conversation, reserve: holdOf("this browser session's reserve", stretch, `${provider}'s next stretch of session time, held until its release is booked`, { tag: data.tag }).hold, at: through, call: data.call });
262
+ const call = data.call === null ? undefined : calls.get(data.call);
263
+ take(call?.hold, usd + stretch);
264
+ // Its call's hold is two stretches, one of them for this reserve, but on the run's ledger that hold keeps its
265
+ // admitted figure until the call returns: asked beside it, the reserve would be judged twice and refused for room
266
+ // the run has. So it is asked once the call's hold is given back, in the room that hold kept for it (askReserve). A
267
+ // charge under no call still running asks at once. A new session's reserve is the cap's to refuse (starting a
268
+ // session is a choice).
269
+ sessions.set(data.tag, { cid: data.conversation, reserve: askReserve(data.tag, `${provider}'s next stretch of session time, held until its release is booked`, call), at: through, call: data.call });
204
270
  }
205
271
  }
206
272
  /** The one booking a charge names on the ledger: its session, its time, and whether it was the session's last. */
@@ -244,7 +310,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
244
310
  continue;
245
311
  // Its reserve carries the down time, so its calls count what it runs from here (`at` now), not the down time again.
246
312
  const now = Date.now();
247
- sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's reserve", stretch + usdOf(Math.max(0, now - at) / 1000), `${provider}'s session time since its last charge and its next stretch, held from the reopen`, { owed: true, tag: row.tag }).hold, at: now, call: null });
313
+ sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's reserve", stretch + usdOf(Math.max(0, now - at) / 1000), `${provider}'s session time since its last charge and its next stretch, held from the reopen`, { ...OWED.reopenReserve, tag: row.tag }).hold, at: now, call: null });
248
314
  }
249
315
  }
250
316
  /** The open-session inventory as committed: a session it no longer holds lets go of its reserve (released, billed or
@@ -263,7 +329,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
263
329
  continue;
264
330
  const usd = usdOf(CREATE_DEADLINE_S + stretchS);
265
331
  take([...calls.values()].find((c) => c.cid === row.conversationId)?.hold, usd);
266
- sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's delayed release", usd, `${provider}'s session time for its create's deadline and a stretch, until its release is billed`, { owed: true, tag: row.tag }).hold, at: Date.now(), call: null });
332
+ sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's delayed release", usd, `${provider}'s session time for its create's deadline and a stretch, until its release is billed`, { ...OWED.delayedRelease, tag: row.tag }).hold, at: Date.now(), call: null });
267
333
  }
268
334
  }
269
335
  /** Applies each browser charge `harness` commits, and each change of pi-browser's inventory (the document of kind
@@ -327,13 +393,21 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
327
393
  const basis = `${provider}'s session time at $${rate} an hour: the ${Math.round(ranS)} s its session ran since its last charge, and twice the next stretch of ${stretchS} s (its ${price.minimumS} s minimum, the ${idleS} s idle window and ${RELEASE_ALLOWANCE_S} s for its release)`;
328
394
  // One hold-only step, held at that figure and given back when the call returns (or its claim is lost): the call's
329
395
  // charges are each their own step (booked).
330
- calls.set(api.callId, { cid: api.conversationId, hold: { usd, drop: () => { } } });
396
+ let landed;
397
+ const entry = { cid: api.conversationId, hold: { usd, drop: () => { } }, givenBack: new Promise((resolve) => (landed = resolve)), reserves: [] };
398
+ calls.set(api.callId, entry);
331
399
  try {
332
400
  // A provider whose time has no price is held at no figure: the cap's rule refuses it for good, as main does.
333
401
  // One refused for room pauses the run (ledger.pause, the run's own: a native tool task runs in no host tool
334
402
  // call's ledger), in the cap's words and figures, as an ask's person time does: its next request is refused
335
403
  // and the run parks for a raise.
336
- const stepped = await paidStep(paid, api.callId, { name: "this browser call", holdUsd: rate === null ? Number.NaN : usd, basis, by: provider, tool: BROWSER_TOOL, hold: true }, () => tool.execute(args, api, context), () => 0, ledger.pause);
404
+ // paidStep returns once the call's hold is given back on the ledger (its settle): the reserves of the sessions
405
+ // the call opened are asked then, and the call returns once they are held, so nothing the run does next is judged
406
+ // while the session is held nowhere.
407
+ const stepped = await paidStep(paid, api.callId, { name: "this browser call", holdUsd: rate === null ? Number.NaN : usd, basis, by: provider, tool: BROWSER_TOOL, hold: true }, () => tool.execute(args, api, context), () => 0, ledger.pause).finally(async () => {
408
+ landed();
409
+ await Promise.all(entry.reserves);
410
+ });
337
411
  return "refused" in stepped ? await refuse(stepped.refused, api, context) : stepped.result;
338
412
  }
339
413
  finally {
@@ -408,7 +482,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
408
482
  if (!(to > from))
409
483
  return;
410
484
  // Spent at the provider already: held on the run's ledger until a charge books it.
411
- const { hold } = holdOf("a person's time in the browser", microUsd(usdOf((to - from) / 1000)), `${provider}'s session time a person used, until the session's next charge books it`, { owed: true, tag });
485
+ const { hold } = holdOf("a person's time in the browser", microUsd(usdOf((to - from) / 1000)), `${provider}'s session time a person used, until the session's next charge books it`, { ...OWED.personTime, tag });
412
486
  carried.set(tag, [...(carried.get(tag) ?? []), { hold, from, to }]);
413
487
  }
414
488
  /** Once every ledger step of a charge under no call is written. */
@@ -1,4 +1,4 @@
1
- import type { Runners } from "./store/store.js";
1
+ import { type Runners } from "./store/store.js";
2
2
  /** The hand-back window when none is asked, in minutes. */
3
3
  export declare const CAPACITY_WINDOW_MINUTES = 15;
4
4
  /** The longest window, in minutes: the hand-backs the store keeps (schema.ts HAND_BACKS_KEPT_MS). */
package/dist/capacity.js CHANGED
@@ -1,10 +1,10 @@
1
1
  // GET /v2/capacity: what an operator, or an autoscaler, reads to size the runners. Read from the store alone, so a server
2
2
  // with no runner beside it (--no-runner, the API-only profile) answers for every runner on its store: the runs waiting for
3
- // a runner and the runs a claim holds, each live runner (its row seen within PRESENCE_STALE_MS) with its version, its
3
+ // a runner and the runs a claim holds, each live runner (its row seen within RUNNER_STALE_MS) with its version, its
4
4
  // slots and how many are free, and the hand-backs within a window. Counts, runner names and versions only: no run id,
5
5
  // agent, prompt, address or customer's word. Behind the server's token, as every route but capabilities and health.
6
6
  import { ApiError } from "./errors.js";
7
- import { PRESENCE_STALE_MS } from "./runner/presence.js";
7
+ import { RUNNER_STALE_MS } from "./store/store.js";
8
8
  /** The hand-back window when none is asked, in minutes. */
9
9
  export const CAPACITY_WINDOW_MINUTES = 15;
10
10
  /** The longest window, in minutes: the hand-backs the store keeps (schema.ts HAND_BACKS_KEPT_MS). */
@@ -21,7 +21,7 @@ export function capacityWindowOf(url) {
21
21
  return minutes;
22
22
  }
23
23
  /** The capacity read over `runners` (the store's), with hand-backs over the last `windowMinutes`. */
24
- export async function capacityOverStore(runners, windowMinutes, staleMs = PRESENCE_STALE_MS) {
24
+ export async function capacityOverStore(runners, windowMinutes, staleMs = RUNNER_STALE_MS) {
25
25
  const [counts, live] = await Promise.all([runners.capacity(windowMinutes * 60_000), runners.live(staleMs)]);
26
26
  const shown = live.map((row) => {
27
27
  const executing = counts.held.get(row.runner) ?? 0;
@@ -96,6 +96,11 @@ export declare class ChatGPTPlan implements PlanReader {
96
96
  private read;
97
97
  /** The row as sealed now, opened, with the bytes it was read as (what a compare-and-set on it compares). */
98
98
  private readSealed;
99
+ /** The row as sealed now (readSealed), taken as the snapshot unless a write moved the snapshot while the read was out:
100
+ * a load or token() that read the row before a sign-in was kept, or before a sign-out removed it, leaves their state. */
101
+ private readTaken;
102
+ /** `row` as the snapshot, by a write that knows it is the row's latest (a sign-in kept, a renewal, a sign-out). */
103
+ private wrote;
99
104
  /** The row sealed as `bytes`, opened (its tokens held for redaction); none when they do not open. */
100
105
  private open;
101
106
  /** `row` sealed as the store keeps it: fresh bytes at each seal. */
@@ -179,6 +179,9 @@ const flights = new Map();
179
179
  * never shows a token when logged. */
180
180
  export class ChatGPTPlan {
181
181
  #snapshot;
182
+ /** Moved on by each write of the snapshot (wrote: a sign-in kept, a renewal, an expiry, a sign-out): a read of the row
183
+ * that was out across one never takes its row over it (readTaken). */
184
+ #writes = 0;
182
185
  #pending;
183
186
  /** An access token OpenAI refused (refused): token() renews rather than send it again. */
184
187
  #refusedAccess;
@@ -248,6 +251,20 @@ export class ChatGPTPlan {
248
251
  const row = this.open(bytes);
249
252
  return row ? { row, bytes } : undefined;
250
253
  }
254
+ /** The row as sealed now (readSealed), taken as the snapshot unless a write moved the snapshot while the read was out:
255
+ * a load or token() that read the row before a sign-in was kept, or before a sign-out removed it, leaves their state. */
256
+ async readTaken() {
257
+ const writes = this.#writes;
258
+ const read = await this.readSealed();
259
+ if (this.#writes === writes)
260
+ this.#snapshot = read?.row;
261
+ return read;
262
+ }
263
+ /** `row` as the snapshot, by a write that knows it is the row's latest (a sign-in kept, a renewal, a sign-out). */
264
+ wrote(row) {
265
+ this.#snapshot = row;
266
+ this.#writes += 1;
267
+ }
251
268
  /** The row sealed as `bytes`, opened (its tokens held for redaction); none when they do not open. */
252
269
  open(bytes) {
253
270
  try {
@@ -273,7 +290,7 @@ export class ChatGPTPlan {
273
290
  }
274
291
  /** Reads the sealed row into the state a reader sees. Returns this. */
275
292
  async load() {
276
- this.#snapshot = await this.read();
293
+ await this.readTaken();
277
294
  return this;
278
295
  }
279
296
  view() {
@@ -460,7 +477,7 @@ export class ChatGPTPlan {
460
477
  if (await this.swap(was, row))
461
478
  break;
462
479
  }
463
- this.#snapshot = row;
480
+ this.wrote(row);
464
481
  this.#problem = undefined;
465
482
  this.#deps.log?.({ chatgpt: "signed_in", ...(previousRevoked === undefined ? {} : { previous_revoked: String(previousRevoked) }) });
466
483
  // Saved: no longer waiting, so it reads signed in while the server takes the change (`saved`, the sign-in's settle).
@@ -519,8 +536,7 @@ export class ChatGPTPlan {
519
536
  /** The access token to send now: the sealed one, renewed first when it ends within 5 minutes. Throws PlanUnavailable,
520
537
  * in words, when there is none. */
521
538
  async token() {
522
- const row = await this.read();
523
- this.#snapshot = row;
539
+ const row = (await this.readTaken())?.row;
524
540
  if (!row)
525
541
  throw new PlanUnavailable(SIGNED_OUT);
526
542
  if (row.state === "expired")
@@ -558,11 +574,10 @@ export class ChatGPTPlan {
558
574
  const holder = randomUUID();
559
575
  const giveUp = this.now() + REFRESH_LEASE_MS + REFRESH_CALL_MS;
560
576
  for (;;) {
561
- const read = await this.readSealed();
577
+ const read = await this.readTaken();
562
578
  if (!read)
563
579
  throw new PlanUnavailable(SIGNED_OUT);
564
580
  const { row, bytes } = read;
565
- this.#snapshot = row;
566
581
  if (row.state === "expired")
567
582
  throw new PlanUnavailable(EXPIRED);
568
583
  // A peer renewed it since: its pair is the row's now.
@@ -605,7 +620,7 @@ export class ChatGPTPlan {
605
620
  }
606
621
  const expired = { ...bare, state: "expired" };
607
622
  if (await this.swap(bytes, expired)) {
608
- this.#snapshot = expired;
623
+ this.wrote(expired);
609
624
  this.#deps.log?.({ chatgpt: "expired" });
610
625
  await this.tellChanged();
611
626
  throw new PlanUnavailable(EXPIRED);
@@ -615,7 +630,7 @@ export class ChatGPTPlan {
615
630
  const renewed = { ...bare, credential: { ...bare.credential, ...next } };
616
631
  this.hold(renewed.credential);
617
632
  if (await this.swap(bytes, renewed)) {
618
- this.#snapshot = renewed;
633
+ this.wrote(renewed);
619
634
  return renewed.credential.access;
620
635
  }
621
636
  // The owner signed out or in again while OpenAI renewed it: the new pair is the sign-in's no longer, and no one
@@ -626,8 +641,7 @@ export class ChatGPTPlan {
626
641
  /** After a renewal whose write back lost its compare-and-set (the owner signed out or in again meanwhile): its result
627
642
  * is dropped, and the row's state wins. */
628
643
  async adopt() {
629
- const now = await this.read();
630
- this.#snapshot = now;
644
+ const now = (await this.readTaken())?.row;
631
645
  if (!now)
632
646
  throw new PlanUnavailable(SIGNED_OUT);
633
647
  if (now.state === "expired")
@@ -665,7 +679,7 @@ export class ChatGPTPlan {
665
679
  revoked = revoked && removed;
666
680
  break;
667
681
  }
668
- this.#snapshot = undefined;
682
+ this.wrote(undefined);
669
683
  this.#deps.log?.({ chatgpt: "signed_out", revoked: String(revoked) });
670
684
  await this.tellChanged();
671
685
  return { revoked };
@@ -1,5 +1,5 @@
1
1
  import type { ClaudeAgentLogin, ClaudeLoginToken } from "@parcha/agentrun-harness-claude";
2
- import type { Runners } from "./store/index.js";
2
+ import { type Runners } from "./store/index.js";
3
3
  /** The pinned CLI's credentials file in its credentials directory (CLAUDE_SECURESTORAGE_CONFIG_DIR). */
4
4
  export declare const LOGIN_FILE = ".credentials.json";
5
5
  /** The least a token handed to a run has left: the pinned CLI's own margin before it calls a token expired (its
@@ -66,15 +66,16 @@ export interface RenewLoginOptions {
66
66
  readonly callMs?: number;
67
67
  /** Default LOCK_WAIT_MS. */
68
68
  readonly lockWaitMs?: number;
69
- /** The refresh locks' file operations. Default: fs/promises' own. */
70
- readonly lockFs?: LockFs;
69
+ /** The renewal's file operations: its refresh locks', and its reads of the login's file. Each one not given is
70
+ * fs/promises' own (a test's watches, pauses or fails one on cue). */
71
+ readonly lockFs?: Partial<LockFs>;
71
72
  /** How often a held lock is read and touched (its heartbeat). Default: the pinned CLI's (`update:5000`). */
72
73
  readonly lockUpdateMs?: number;
73
74
  }
74
75
  /** The pinned CLI's renewal of a login (the adapter's login-refresh.ts), as the runner does it in the CLI's place. */
75
76
  export declare function renewLogin(options?: RenewLoginOptions): Renew;
76
- /** The file operations a refresh lock is taken, touched and released with: fs/promises' own, or a test's that watches
77
- * or pauses them (RenewLoginOptions.lockFs). */
77
+ /** The file operations a renewal makes: a refresh lock taken, touched and released, and the login's file read as text.
78
+ * fs/promises' own, or a test's that watches, pauses or fails them (RenewLoginOptions.lockFs). */
78
79
  export interface LockFs {
79
80
  mkdir(path: string): Promise<unknown>;
80
81
  stat(path: string): Promise<LockIdentity>;
@@ -83,6 +84,7 @@ export interface LockFs {
83
84
  readonly recursive: boolean;
84
85
  readonly force: boolean;
85
86
  }): Promise<void>;
87
+ readFile(path: string): Promise<string>;
86
88
  }
87
89
  /** A lock directory as read: which directory it is (its device and inode) and its mtime. */
88
90
  type LockIdentity = {
@@ -90,16 +92,18 @@ type LockIdentity = {
90
92
  readonly ino: number;
91
93
  readonly mtimeMs: number;
92
94
  };
93
- /** Whether `login` is AgentRun's own login folder in `data` (claude-login.ts loginAt "agentrun"), the one login a run
95
+ /** Whether `login` is AgentRun's own login folder in `data` (claude-login.ts agentRunLoginDir), the one login a run
94
96
  * under a user of its own is handed a token of; this machine's own Claude Code login is not. */
95
97
  export declare const agentRunLogin: (login: ClaudeAgentLogin, data: string) => boolean;
96
- export declare function loginTokensFor(login: ClaudeAgentLogin): LoginTokens;
97
- /** The words a run's claim is refused in by its runner (held.ts claudeLogin) when the claim goes on a login the runner
98
- * hands no reader of to a run's own process: one not on AgentRun's own login folder. */
99
- export declare const LOGIN_NOT_HANDED = "This run's runner handed it no Claude Code login: it runs each run as a user of its own and hands such a run only AgentRun's own login folder's token. Switch to that folder under Settings \u2192 Model keys, set AGENTRUN_RUN_USER=same, or give the run a model_key.";
98
+ export declare function loginTokensFor(login: ClaudeAgentLogin, log: (fields: Record<string, string>) => void): LoginTokens;
99
+ /** The words a run's start is refused in by its runner (held.ts claudeLogin) when its claim read Claude Code's login and
100
+ * the runner's second read of the setting, at the start, names none or another folder: the run is put on no login its
101
+ * start did not read, and never falls to a model key it was not claimed on. They name no folder. */
102
+ export declare const LOGIN_CHANGED_SINCE_CLAIM = "This run's runner handed it no Claude Code login: the login was turned off or moved to another folder since this run's claim, and a run claimed on the login does not fall back to the model keys. Start the run again to run it as the login is now, or give it a model_key.";
100
103
  /** A run's own process's login (held.ts claudeLogin's reader): each token it reads held by `hold` (the run's redactors)
101
104
  * and this process's own (secrets.ts holdSecret) before the run's CLI is handed it, and a token Anthropic refused told
102
- * to the runner, which renews it at the next ask. */
105
+ * to the runner, which renews it at the next ask. A process its runner hands no reader runs on no login (cli-run-spec.ts):
106
+ * its claim read the login as off for it, or its run brought its own model key. */
103
107
  export declare function heldTokenLogin(reader: {
104
108
  token(): Promise<string>;
105
109
  refused?(sent: string): Promise<void>;