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

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 (312) hide show
  1. package/CHANGELOG.md +281 -0
  2. package/README.md +246 -66
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +15 -3
  5. package/dist/adapters.js +17 -6
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/api-keys.d.ts +76 -0
  9. package/dist/api-keys.js +217 -0
  10. package/dist/api-only.d.ts +15 -5
  11. package/dist/api-only.js +32 -8
  12. package/dist/box-paths.d.ts +4 -3
  13. package/dist/box-paths.js +7 -4
  14. package/dist/browser-hold.d.ts +23 -0
  15. package/dist/browser-hold.js +48 -0
  16. package/dist/browser-person.d.ts +3 -0
  17. package/dist/browser-person.js +4 -1
  18. package/dist/chatgpt-plan.d.ts +18 -8
  19. package/dist/chatgpt-plan.js +91 -34
  20. package/dist/claude-login-token.d.ts +117 -0
  21. package/dist/claude-login-token.js +737 -0
  22. package/dist/claude-login.d.ts +120 -22
  23. package/dist/claude-login.js +347 -63
  24. package/dist/claude-sign-in.d.ts +17 -6
  25. package/dist/claude-sign-in.js +42 -39
  26. package/dist/cli.js +33 -10
  27. package/dist/composio-made.d.ts +4 -0
  28. package/dist/composio-made.js +4 -0
  29. package/dist/composio-preset.d.ts +43 -2
  30. package/dist/composio-preset.js +92 -4
  31. package/dist/computer-attach.d.ts +35 -17
  32. package/dist/computer-attach.js +301 -49
  33. package/dist/computer-held-routes.d.ts +5 -4
  34. package/dist/computer-held-routes.js +29 -8
  35. package/dist/computer-held.d.ts +6 -1
  36. package/dist/computer-held.js +14 -0
  37. package/dist/computer-record.js +4 -2
  38. package/dist/computer-viewer.js +4 -1
  39. package/dist/computers.d.ts +10 -10
  40. package/dist/computers.js +5 -5
  41. package/dist/console/assets/{backend-Boh7tC4i.js → backend-CSAWUqtZ.js} +19 -19
  42. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  43. package/dist/console/assets/index-DPh29cyz.js +747 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/decisions.d.ts +1 -1
  46. package/dist/decisions.js +1 -1
  47. package/dist/dial-relay.d.ts +25 -4
  48. package/dist/dial-relay.js +129 -1
  49. package/dist/docker-host-addresses.d.ts +22 -11
  50. package/dist/docker-host-addresses.js +38 -26
  51. package/dist/env-switch.d.ts +8 -0
  52. package/dist/env-switch.js +31 -2
  53. package/dist/errors.d.ts +1 -0
  54. package/dist/errors.js +2 -0
  55. package/dist/fal-price.d.ts +56 -20
  56. package/dist/fal-price.js +400 -90
  57. package/dist/handed-values.d.ts +43 -1
  58. package/dist/handed-values.js +119 -2
  59. package/dist/harness-archive.d.ts +13 -10
  60. package/dist/harness-archive.js +60 -34
  61. package/dist/harness-check.d.ts +3 -1
  62. package/dist/harness-check.js +25 -46
  63. package/dist/harness-keys.d.ts +73 -27
  64. package/dist/harness-keys.js +194 -61
  65. package/dist/harness-recipe-entry.d.ts +8 -7
  66. package/dist/harness-recipe-entry.js +21 -32
  67. package/dist/harness-recipe.d.ts +38 -25
  68. package/dist/harness-recipe.js +49 -36
  69. package/dist/harness-sign-in.js +12 -23
  70. package/dist/harness-table.d.ts +10 -3
  71. package/dist/harness-table.js +26 -21
  72. package/dist/harness.d.ts +1 -0
  73. package/dist/harness.js +17 -5
  74. package/dist/hosted-search.d.ts +1 -1
  75. package/dist/hosted-search.js +1 -2
  76. package/dist/import-worker.d.ts +4 -2
  77. package/dist/import-worker.js +9 -2
  78. package/dist/in-flight.d.ts +26 -0
  79. package/dist/in-flight.js +52 -0
  80. package/dist/key-refusal.d.ts +9 -4
  81. package/dist/key-refusal.js +107 -25
  82. package/dist/learn/ledger.d.ts +170 -0
  83. package/dist/learn/ledger.js +218 -0
  84. package/dist/learn/promote.d.ts +3 -3
  85. package/dist/learn/promote.js +1 -1
  86. package/dist/learn/secrets.d.ts +13 -3
  87. package/dist/learn/secrets.js +118 -17
  88. package/dist/learning-cost.d.ts +28 -23
  89. package/dist/learning-cost.js +19 -23
  90. package/dist/link-check.js +1 -1
  91. package/dist/live-reach.d.ts +2 -0
  92. package/dist/live-reach.js +2 -0
  93. package/dist/llms.txt +1 -1
  94. package/dist/marketplace.d.ts +77 -0
  95. package/dist/marketplace.js +224 -0
  96. package/dist/mcp-api-only-origins.d.ts +35 -0
  97. package/dist/mcp-api-only-origins.js +57 -0
  98. package/dist/mcp-gateway.d.ts +7 -5
  99. package/dist/mcp-gateway.js +9 -12
  100. package/dist/mcp-secret-writes.js +5 -3
  101. package/dist/mcp-servers-store.d.ts +28 -6
  102. package/dist/mcp-servers-store.js +53 -4
  103. package/dist/media-duration.d.ts +3 -0
  104. package/dist/media-duration.js +90 -9
  105. package/dist/micro.d.ts +2 -0
  106. package/dist/micro.js +2 -0
  107. package/dist/model-form.d.ts +5 -4
  108. package/dist/model-form.js +11 -7
  109. package/dist/model.d.ts +10 -6
  110. package/dist/model.js +16 -11
  111. package/dist/monid.d.ts +14 -1
  112. package/dist/monid.js +103 -26
  113. package/dist/ollama-provider.d.ts +7 -1
  114. package/dist/ollama-provider.js +14 -2
  115. package/dist/openapi.js +210 -37
  116. package/dist/otel/genai.d.ts +65 -0
  117. package/dist/otel/genai.js +116 -0
  118. package/dist/otel/tracer.d.ts +55 -0
  119. package/dist/otel/tracer.js +308 -0
  120. package/dist/page.d.ts +2 -0
  121. package/dist/page.js +3 -1
  122. package/dist/paid-calls.d.ts +1 -32
  123. package/dist/paid-calls.js +4 -39
  124. package/dist/place-offers.d.ts +4 -0
  125. package/dist/place-offers.js +7 -4
  126. package/dist/provider.d.ts +11 -2
  127. package/dist/provider.js +59 -8
  128. package/dist/redact/match.d.ts +30 -3
  129. package/dist/redact/match.js +422 -41
  130. package/dist/refusal-words.d.ts +11 -0
  131. package/dist/refusal-words.js +11 -0
  132. package/dist/run-census.d.ts +67 -0
  133. package/dist/run-census.js +240 -0
  134. package/dist/run-computer.d.ts +6 -3
  135. package/dist/run-computer.js +4 -1
  136. package/dist/run-cut.d.ts +15 -6
  137. package/dist/run-cut.js +30 -9
  138. package/dist/run-files.d.ts +3 -0
  139. package/dist/run-files.js +3 -0
  140. package/dist/run-launch.d.ts +12 -1
  141. package/dist/run-launch.js +9 -10
  142. package/dist/run-learning-served.d.ts +4 -2
  143. package/dist/run-model-key.d.ts +8 -0
  144. package/dist/run-model-key.js +31 -1
  145. package/dist/run-reads-over-store.d.ts +24 -6
  146. package/dist/run-reads-over-store.js +67 -23
  147. package/dist/run-recordings.d.ts +5 -1
  148. package/dist/run-recordings.js +39 -14
  149. package/dist/run-timeline-served.d.ts +2 -0
  150. package/dist/run-timeline-served.js +2 -2
  151. package/dist/run-usage.d.ts +1 -0
  152. package/dist/run-view.d.ts +1 -2
  153. package/dist/run-view.js +2 -1
  154. package/dist/runnable.d.ts +10 -1
  155. package/dist/runnable.js +20 -8
  156. package/dist/runner/adapter-loop.d.ts +11 -0
  157. package/dist/runner/adapter-loop.js +58 -26
  158. package/dist/runner/adapter-run-spec.d.ts +55 -11
  159. package/dist/runner/adapter-run-spec.js +183 -52
  160. package/dist/runner/adapters/pi.js +25 -3
  161. package/dist/runner/beside.d.ts +9 -2
  162. package/dist/runner/beside.js +27 -9
  163. package/dist/runner/big-writes.js +1 -10
  164. package/dist/runner/claim-secrets.d.ts +27 -10
  165. package/dist/runner/claim-secrets.js +49 -22
  166. package/dist/runner/cli-run-spec.d.ts +6 -0
  167. package/dist/runner/cli-run-spec.js +97 -38
  168. package/dist/runner/computer-journal.d.ts +9 -1
  169. package/dist/runner/computer-journal.js +26 -0
  170. package/dist/runner/conformance/harness.js +1 -1
  171. package/dist/runner/feedback-round.js +3 -0
  172. package/dist/runner/harness-loops.d.ts +6 -5
  173. package/dist/runner/harness-loops.js +7 -7
  174. package/dist/runner/held.d.ts +24 -6
  175. package/dist/runner/journal-kinds.d.ts +5 -0
  176. package/dist/runner/journal-kinds.js +5 -0
  177. package/dist/runner/main.d.ts +11 -6
  178. package/dist/runner/main.js +19 -9
  179. package/dist/runner/mcp-claim.js +31 -3
  180. package/dist/runner/mcp-run.d.ts +9 -0
  181. package/dist/runner/mcp-run.js +11 -5
  182. package/dist/runner/model-route.d.ts +17 -0
  183. package/dist/runner/model-route.js +120 -2
  184. package/dist/runner/presence.d.ts +11 -1
  185. package/dist/runner/presence.js +7 -0
  186. package/dist/runner/reflect-hook.js +1 -1
  187. package/dist/runner/run-child-host.d.ts +22 -8
  188. package/dist/runner/run-child-host.js +128 -41
  189. package/dist/runner/run-child.js +5 -2
  190. package/dist/runner/runner.d.ts +17 -3
  191. package/dist/runner/runner.js +130 -34
  192. package/dist/runner/save-slots.js +2 -1
  193. package/dist/runner/store-port.d.ts +1 -1
  194. package/dist/runner/store-secrets.d.ts +6 -0
  195. package/dist/runner/store-secrets.js +49 -7
  196. package/dist/runner/subagent.d.ts +11 -0
  197. package/dist/runner/subagent.js +16 -38
  198. package/dist/runner/workflow-first.d.ts +35 -15
  199. package/dist/runner/workflow-first.js +38 -25
  200. package/dist/runner/workflow-spec.js +4 -3
  201. package/dist/runs-over-store.d.ts +15 -6
  202. package/dist/runs-over-store.js +33 -21
  203. package/dist/scrub-command.d.ts +73 -0
  204. package/dist/scrub-command.js +307 -0
  205. package/dist/secret-cut.d.ts +73 -0
  206. package/dist/secret-cut.js +291 -4
  207. package/dist/secret-rules.d.ts +143 -0
  208. package/dist/secret-rules.js +2564 -0
  209. package/dist/secrets.d.ts +7 -0
  210. package/dist/secrets.js +20 -0
  211. package/dist/server-keys.d.ts +20 -0
  212. package/dist/server-keys.js +25 -6
  213. package/dist/server.d.ts +65 -13
  214. package/dist/server.js +470 -157
  215. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  216. package/dist/slots.d.ts +9 -0
  217. package/dist/slots.js +45 -0
  218. package/dist/store/index.d.ts +1 -1
  219. package/dist/store/index.js +1 -1
  220. package/dist/store/journal/storage.js +1 -1
  221. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  222. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  223. package/dist/store/schema.d.ts +23 -0
  224. package/dist/store/schema.js +58 -2
  225. package/dist/store/seal.d.ts +6 -1
  226. package/dist/store/seal.js +5 -3
  227. package/dist/store/sqlite/run-launch.d.ts +9 -1
  228. package/dist/store/sqlite/run-launch.js +24 -13
  229. package/dist/store/sqlite/run-patch.d.ts +12 -2
  230. package/dist/store/sqlite/run-patch.js +42 -5
  231. package/dist/store/sqlite/store.js +105 -12
  232. package/dist/store/store.d.ts +57 -2
  233. package/dist/store/store.js +20 -0
  234. package/dist/store-reads/learning.d.ts +84 -124
  235. package/dist/store-reads/learning.js +210 -274
  236. package/dist/store-view.d.ts +3 -0
  237. package/dist/store-view.js +3 -3
  238. package/dist/suggestions.js +3 -2
  239. package/dist/template-eval.d.ts +39 -9
  240. package/dist/template-eval.js +191 -60
  241. package/dist/template-import.js +6 -2
  242. package/dist/templates.d.ts +10 -2
  243. package/dist/templates.js +28 -8
  244. package/dist/timeline/labels.d.ts +6 -4
  245. package/dist/timeline/labels.js +18 -6
  246. package/dist/timeline/timeline.d.ts +5 -0
  247. package/dist/timeline/timeline.js +14 -8
  248. package/dist/timeline/util.js +1 -1
  249. package/dist/timeline/web-calls.d.ts +22 -7
  250. package/dist/timeline/web-calls.js +106 -35
  251. package/dist/tool-gate.d.ts +42 -3
  252. package/dist/tool-gate.js +66 -5
  253. package/dist/tool-keys-store.d.ts +2 -4
  254. package/dist/tool-keys-store.js +5 -21
  255. package/dist/tool-keys.d.ts +2 -2
  256. package/dist/tool-keys.js +2 -2
  257. package/dist/tool-list.js +1 -1
  258. package/dist/tool-plane.d.ts +2 -2
  259. package/dist/tool-plane.js +35 -33
  260. package/dist/tools.js +13 -7
  261. package/dist/trigger-targets.d.ts +4 -0
  262. package/dist/trigger-targets.js +9 -2
  263. package/dist/triggers.d.ts +67 -4
  264. package/dist/triggers.js +171 -22
  265. package/dist/until.d.ts +3 -0
  266. package/dist/until.js +11 -0
  267. package/dist/web-fake.d.ts +1 -3
  268. package/dist/web-fake.js +7 -18
  269. package/dist/web-fetch.d.ts +6 -72
  270. package/dist/web-fetch.js +11 -265
  271. package/dist/web-run.d.ts +31 -0
  272. package/dist/web-run.js +90 -0
  273. package/dist/web-save.d.ts +10 -13
  274. package/dist/web-save.js +13 -55
  275. package/dist/web-search.d.ts +9 -127
  276. package/dist/web-search.js +23 -259
  277. package/dist/wires.d.ts +13 -0
  278. package/dist/wires.js +11 -0
  279. package/dist/workflow-run.d.ts +5 -4
  280. package/dist/workflow-run.js +5 -4
  281. package/dist/workspace/attached-computers.d.ts +32 -9
  282. package/dist/workspace/attached-computers.js +77 -13
  283. package/dist/workspace/computer-deps.d.ts +8 -2
  284. package/dist/workspace/computer-deps.js +10 -3
  285. package/dist/workspace/computer-for-claim.d.ts +12 -1
  286. package/dist/workspace/computer-for-claim.js +83 -11
  287. package/dist/workspace/computer-kept.d.ts +3 -0
  288. package/dist/workspace/computer-kept.js +11 -2
  289. package/dist/workspace/index.d.ts +1 -1
  290. package/dist/workspace/index.js +1 -1
  291. package/dist/workspace/kind-skills.d.ts +4 -0
  292. package/dist/workspace/kind-skills.js +9 -0
  293. package/dist/workspace/paired-route.d.ts +91 -0
  294. package/dist/workspace/paired-route.js +153 -0
  295. package/dist/workspace/synced-folder.js +3 -4
  296. package/dist/wrapped.d.ts +20 -6
  297. package/dist/wrapped.js +66 -25
  298. package/package.json +17 -11
  299. package/skills/agentrun-serve/SKILL.md +4 -0
  300. package/templates/README.md +32 -10
  301. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  302. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  303. package/dist/exa-keyless.d.ts +0 -34
  304. package/dist/exa-keyless.js +0 -118
  305. package/dist/firecrawl-keyless.d.ts +0 -41
  306. package/dist/firecrawl-keyless.js +0 -152
  307. package/dist/keyless-mcp.d.ts +0 -36
  308. package/dist/keyless-mcp.js +0 -127
  309. package/dist/text-urls.d.ts +0 -38
  310. package/dist/text-urls.js +0 -170
  311. package/dist/web-fetch-direct.d.ts +0 -119
  312. package/dist/web-fetch-direct.js +0 -190
@@ -33,9 +33,10 @@ export declare function remoteDockerOnce(env: NodeJS.ProcessEnv): Promise<string
33
33
  /** Why this server can't run a Docker computer, or undefined when it can: on its Docker's own host (`here`), or in a
34
34
  * container of that Docker's with its data on a named volume (`paths`: the computer mounts the run's folder and its
35
35
  * daemon as that volume's subpaths, workspace/computer-deps.ts dockerVolumeOf). Any other layout says why (`reason`,
36
- * dockerPathsOf), and so does a daemon of another machine (`remote`, remoteDockerOf's endpoint). The one check every
37
- * reader of Docker's offer takes. */
38
- export declare function dockerComputerRefusal(paths: DockerPaths, remote: string | undefined): string | undefined;
36
+ * dockerPathsOf), and so does a daemon of another machine (`remote`, remoteDockerOf's endpoint), and then a computerd
37
+ * build missing for Docker's architecture (`noDaemon`: the computer package's dockerDaemonOf words, the ones its
38
+ * create() would fail with). The one check every reader of Docker's offer takes. */
39
+ export declare function dockerComputerRefusal(paths: DockerPaths, remote: string | undefined, noDaemon?: string): string | undefined;
39
40
  /** Where a runner's Docker has the data directory `data`, read once by the runner that makes a Docker computer: as the
40
41
  * server reads it at its start (dockerPathsOf), on Linux alone; under `--faux` from the mountinfo file the tests name
41
42
  * (FAUX_MOUNTINFO_ENV), else as a host. */
package/dist/box-paths.js CHANGED
@@ -74,12 +74,15 @@ export function remoteDockerOnce(env) {
74
74
  /** Why this server can't run a Docker computer, or undefined when it can: on its Docker's own host (`here`), or in a
75
75
  * container of that Docker's with its data on a named volume (`paths`: the computer mounts the run's folder and its
76
76
  * daemon as that volume's subpaths, workspace/computer-deps.ts dockerVolumeOf). Any other layout says why (`reason`,
77
- * dockerPathsOf), and so does a daemon of another machine (`remote`, remoteDockerOf's endpoint). The one check every
78
- * reader of Docker's offer takes. */
79
- export function dockerComputerRefusal(paths, remote) {
77
+ * dockerPathsOf), and so does a daemon of another machine (`remote`, remoteDockerOf's endpoint), and then a computerd
78
+ * build missing for Docker's architecture (`noDaemon`: the computer package's dockerDaemonOf words, the ones its
79
+ * create() would fail with). The one check every reader of Docker's offer takes. */
80
+ export function dockerComputerRefusal(paths, remote, noDaemon) {
80
81
  if ("reason" in paths)
81
82
  return paths.reason;
82
- return remote !== undefined ? remoteDockerWords(remote) : undefined;
83
+ if (remote !== undefined)
84
+ return remoteDockerWords(remote);
85
+ return noDaemon === undefined ? undefined : `${noDaemon}, then restart AgentRun`;
83
86
  }
84
87
  /** Where a runner's Docker has the data directory `data`, read once by the runner that makes a Docker computer: as the
85
88
  * server reads it at its start (dockerPathsOf), on Linux alone; under `--faux` from the mountinfo file the tests name
@@ -0,0 +1,23 @@
1
+ import type { WaitEndedSettings } from "./browser-wait-ended.js";
2
+ /** A take of the run's browser in force: the session's tag and when it went live (ISO). */
3
+ export type BrowserHeld = {
4
+ session: string;
5
+ at: string;
6
+ };
7
+ /** The settings key a run's browser take is kept under (the run's delete removes it: server.ts). */
8
+ export declare const browserHoldKey: (runId: string) => string;
9
+ /** The run's process, as a take of its browser goes live. */
10
+ export declare function markBrowserHeld(settings: WaitEndedSettings, runId: string, held: BrowserHeld, epoch?: number): Promise<void>;
11
+ /** The run's process, as a take ends (given back, idle, away, the cap, the session gone, an answered ask), as a browser
12
+ * session opens, or at the run's end. Given the claim's `epoch`, a take a later claim wrote stays. Given `session`, only
13
+ * that session's take goes (another session's take, live meanwhile, stays). */
14
+ export declare function clearBrowserHeld(settings: WaitEndedSettings, runId: string, epoch?: number, session?: string): Promise<void>;
15
+ /** Whether the owner holds the run's browser now: one settings read; a value of another shape is no take. */
16
+ export declare function browserHeld(settings: Pick<WaitEndedSettings, "get">, runId: string): Promise<boolean>;
17
+ /** The run's process's writes of its browser's take, each after the one before it, so a quick take and hand-back can never
18
+ * land backward (the hand-back's removal reading before the take's write is in). The first removes any take an earlier
19
+ * process of the run left: this process's viewers start with nobody holding the browser. A write that fails leaves the
20
+ * ones after it to run. */
21
+ export declare function browserHoldWriter(settings: WaitEndedSettings, runId: string, epoch?: number): {
22
+ held(tag: string, on: boolean, at: number): Promise<void>;
23
+ };
@@ -0,0 +1,48 @@
1
+ // Whether the owner drives a run's browser now, for the run read's `computer.state` (`taken_over`) and so for Running now's
2
+ // "You drive". A browser is taken over in its live view, in the run's process (browser-person.ts personHands.take), not
3
+ // through the server's command rows as a desktop or a phone is (computer-commands.ts), so the server learns it from one
4
+ // small setting per run (`browser_hold:<run id>`: { session, at, epoch }), as it learns an ended wait
5
+ // (browser-wait-ended.ts). The run's process writes it as a take goes live and removes it as the take ends, however it
6
+ // ends, one change after another (browserHoldWriter); it removes any row an earlier process of the run left as it
7
+ // starts, since its viewers start with nobody holding the browser, so a take a crashed process never ended is not read as
8
+ // still in force. The runner removes it at the run's end.
9
+ const keyOf = (runId) => `browser_hold:${runId}`;
10
+ /** The settings key a run's browser take is kept under (the run's delete removes it: server.ts). */
11
+ export const browserHoldKey = keyOf;
12
+ /** The run's process, as a take of its browser goes live. */
13
+ export async function markBrowserHeld(settings, runId, held, epoch) {
14
+ await settings.put(keyOf(runId), epoch === undefined ? held : { ...held, epoch });
15
+ }
16
+ /** The run's process, as a take ends (given back, idle, away, the cap, the session gone, an answered ask), as a browser
17
+ * session opens, or at the run's end. Given the claim's `epoch`, a take a later claim wrote stays. Given `session`, only
18
+ * that session's take goes (another session's take, live meanwhile, stays). */
19
+ export async function clearBrowserHeld(settings, runId, epoch, session) {
20
+ if (epoch !== undefined || session !== undefined) {
21
+ const written = (await settings.get(keyOf(runId)));
22
+ if (!written)
23
+ return;
24
+ if (epoch !== undefined && typeof written.epoch === "number" && written.epoch > epoch)
25
+ return;
26
+ if (session !== undefined && written.session !== session)
27
+ return;
28
+ }
29
+ await settings.remove(keyOf(runId));
30
+ }
31
+ /** Whether the owner holds the run's browser now: one settings read; a value of another shape is no take. */
32
+ export async function browserHeld(settings, runId) {
33
+ const value = await settings.get(keyOf(runId));
34
+ if (!value || typeof value !== "object")
35
+ return false;
36
+ const { session, at } = value;
37
+ return typeof session === "string" && typeof at === "string";
38
+ }
39
+ /** The run's process's writes of its browser's take, each after the one before it, so a quick take and hand-back can never
40
+ * land backward (the hand-back's removal reading before the take's write is in). The first removes any take an earlier
41
+ * process of the run left: this process's viewers start with nobody holding the browser. A write that fails leaves the
42
+ * ones after it to run. */
43
+ export function browserHoldWriter(settings, runId, epoch) {
44
+ let last = clearBrowserHeld(settings, runId, epoch).catch(() => undefined);
45
+ return {
46
+ held: (tag, on, at) => (last = last.then(() => (on ? markBrowserHeld(settings, runId, { session: tag, at: new Date(at).toISOString() }, epoch) : clearBrowserHeld(settings, runId, epoch, tag))).catch(() => undefined)),
47
+ };
48
+ }
@@ -58,6 +58,9 @@ export declare function personHands(options: {
58
58
  /** A wait on the person's answer ended with its browser let go (its window, the cap, its session gone): when (ms) and
59
59
  * the timeline row's words, for the Screen tab's ended state (browser-wait-ended.ts). Never throws out. */
60
60
  waitEnded?(at: number, why: string): void;
61
+ /** A take of session `tag` went live (`on`, at `at` ms) or ended, however it ended: for the run read's
62
+ * `computer.state` (browser-hold.ts). Never throws out. */
63
+ held?(tag: string, on: boolean, at: number): void;
61
64
  holdMs?: number;
62
65
  pollMs?: number;
63
66
  /** For tests: the timer functions the person's time is held again by. */
@@ -413,7 +413,9 @@ export function personHands(options) {
413
413
  if (ended || live)
414
414
  return;
415
415
  live = true;
416
- void note(HOST_PHASE, { summary: TAKEN, at: now() });
416
+ const at = now();
417
+ options.held?.(tag, true, at);
418
+ void note(HOST_PHASE, { summary: TAKEN, at });
417
419
  },
418
420
  // No hold started after all: what was held for it goes, and no row was written for it.
419
421
  cancel: () => {
@@ -432,6 +434,7 @@ export function personHands(options) {
432
434
  // they took it, so none says how it came back. An answered ask writes its own row.
433
435
  if (!live)
434
436
  return Promise.resolve();
437
+ options.held?.(tag, false, now());
435
438
  // Handed back by the person (the viewer's Hand back): their word that they are done, so the agent's open ask on
436
439
  // this session is answered done, as the hand-back route would answer it (first answer wins). Never on any other
437
440
  // end (cap, idle, away, released, answered): the person did not say they were done. The answer's own row
@@ -12,7 +12,8 @@ export declare const PLAN_FALLBACK_MODELS: readonly string[];
12
12
  /** The model a run on the plan gets when it names none. */
13
13
  export declare const PLAN_DEFAULT_MODEL = "gpt-6.1-sol";
14
14
  export type PlanState = "signed_out" | "pending" | "signed_in" | "expired";
15
- /** GET /settings/chatgpt: never a token. `problem`: why the last sign-in ended without signing in, in words. */
15
+ /** GET /settings/chatgpt: never a token. `problem`: why the last sign-in ended without signing in, in words. `hint`: on a
16
+ * sign-in waiting past its first minute, why it may be stuck (STILL_WAITING). */
16
17
  export type PlanView = {
17
18
  state: PlanState;
18
19
  email?: string;
@@ -21,6 +22,7 @@ export type PlanView = {
21
22
  expires_at?: string;
22
23
  models?: string[];
23
24
  problem?: string;
25
+ hint?: string;
24
26
  };
25
27
  /** The words a run or a request gets when there is no plan token to send. */
26
28
  export declare const SIGNED_OUT = "This server is not signed in to ChatGPT: sign in under Settings \u2192 Model keys, or name a model on a key.";
@@ -107,8 +109,9 @@ export declare class ChatGPTPlan implements PlanReader {
107
109
  /** This server's id at OpenAI (its agent host id): a UUID made once and kept in the store's settings. Not a credential. */
108
110
  private hostId;
109
111
  private cancel;
110
- /** Ends the sign-in waiting past its 10 minutes: a cancel, which says nothing by itself, that says it timed out. One
111
- * whose code OpenAI answered is past waiting (it is being kept) and never times out. */
112
+ /** Ends the sign-in waiting past its 10 minutes: a cancel, which says nothing by itself, that says it timed out (with
113
+ * no admin guess when a code came back and its exchange was cut off). One whose code OpenAI answered is past waiting
114
+ * (it is being kept) and never times out. */
112
115
  private expire;
113
116
  /** Starts a sign-in (one at a time: a new start cancels the one waiting) and gives the address to open. It lasts 10
114
117
  * minutes: the loopback callback finishes it where the browser runs on this machine; elsewhere finishSignIn does. */
@@ -124,9 +127,15 @@ export declare class ChatGPTPlan implements PlanReader {
124
127
  * of is revoked first, then replaced only while the row still holds it (a renewal of it that wrote back meanwhile is
125
128
  * read, revoked and replaced in turn), so no earlier pair is left alive. */
126
129
  private keep;
127
- /** Takes again a sign-in's change the server failed to take (changed_failed), at the server's read of the sign-in, so
128
- * what it offers does not wait for a restart. Nothing when none is owed; a failure again stays owed, said once. */
129
- changeAgain(): Promise<void>;
130
+ /** Tells the server the sign-in changed (its change callback: env read again, the listings relisted, the offers
131
+ * probed). What the server does with it is not the change's to fail: a failure is owed, said in the log (once: not
132
+ * again for `again`, a retry of one owed), and taken again at the server's next read (refresh). */
133
+ private tellChanged;
134
+ /** The sign-in as the store holds it now, read at the server's read of it: a runner may have renewed it, found it
135
+ * expired, or another server signed in or out. A change is told to the server, and so is one it failed to take, so
136
+ * what it offers does not wait for a restart. One at a time: a read while one is out waits for that one (the console
137
+ * polls, and each change relists and probes). */
138
+ refresh(): Promise<void>;
130
139
  /** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families; the fallback
131
140
  * list when it can't be read. */
132
141
  private listModels;
@@ -166,8 +175,9 @@ export declare class ChatGPTPlan implements PlanReader {
166
175
  * confirmed it. The endpoint is taken from OpenAI's discovery document only when it is https on auth.openai.com, so a
167
176
  * refresh token goes nowhere else. Never throws. */
168
177
  private revoke;
169
- /** Stops the sign-in waiting, at the server's close. */
170
- close(): void;
178
+ /** Stops the sign-in waiting, at the server's close. Resolves once every sign-in cancelled (by this, a newer start, a
179
+ * sign-out or its 10 minutes) has ended, whatever its end said in the log. */
180
+ close(): Promise<void>;
171
181
  }
172
182
  /** For a run on a plan model (`model`, the one its claim chose): the plan's token read once before anything starts, so a
173
183
  * sign-in that is gone, or that OpenAI refuses to renew, fails the run at once, in words (PlanUnavailable). */
@@ -38,6 +38,8 @@ const DIRECT_SCOPE = "chatgpt.tokens.use.direct";
38
38
  const AGENT_NAME = "AgentRun";
39
39
  const HOST_ID_SETTING = "chatgpt_host_id";
40
40
  const PENDING_MS = 10 * 60_000;
41
+ /** How long a sign-in waits before its view says why it may be stuck (STILL_WAITING): long before PENDING_MS ends it. */
42
+ const HINT_AFTER_MS = 60_000;
41
43
  const REFRESH_MARGIN_MS = 5 * 60_000;
42
44
  /** The longest one refresh call at OpenAI may take: its holder gives it up by then. */
43
45
  const REFRESH_CALL_MS = 15_000;
@@ -114,10 +116,20 @@ const PLAN_NOT_USABLE = "This ChatGPT plan can't be used here: OpenAI's sign-in
114
116
  /** What a refusal whose reason OpenAI doesn't name ends with: a Free plan's sign-in has ended in one, and nothing tells it
115
117
  * apart. It never says Free can't be used: OpenAI changes which plans can. */
116
118
  const FREE_OR_AGAIN = "a Free ChatGPT plan may be the reason; with a paid plan, start it again.";
117
- const TIMED_OUT = "The sign-in timed out before OpenAI sent the code back: start it again.";
119
+ /** The likely cause of a sign-in OpenAI never sends back: a workspace whose admin has turned off open-source apps gets
120
+ * OpenAI's refusal on OpenAI's own page, with no way back to this server, so nothing here can tell it from a tab left
121
+ * open. Named first in a sign-in still waiting (STILL_WAITING) and in its timeout. */
122
+ const ADMIN_LIKELY = "If OpenAI's page showed an error instead of signing you in, your ChatGPT workspace's admin has likely turned off open-source apps (External access → OSS → Use ChatGPT plan): ask them to turn it on, or sign in with another account.";
123
+ const TIMED_OUT = `The sign-in timed out: OpenAI never sent the code back. ${ADMIN_LIKELY} Otherwise, start it again.`;
124
+ /** A pending view's `hint` from HINT_AFTER_MS into its wait on, while no code is in: a sign-in that goes through is back
125
+ * well within it. */
126
+ const STILL_WAITING = `OpenAI hasn't sent the code back yet. ${ADMIN_LIKELY}`;
127
+ /** The timeout of a sign-in whose code came back (the browser's return or a paste) while OpenAI was still answering it:
128
+ * no admin guess, since OpenAI's page did send the browser back. */
129
+ const CUT_OFF = "The sign-in timed out while OpenAI was still answering its code: start it again.";
118
130
  /** The words for OpenAI's refusal `code` at its sign-in page: fixed words, never the code. Anything on this machine can
119
131
  * send the loopback callback an `error` while a sign-in waits, so the code goes to the log alone. */
120
- const deniedWords = (code) => (tag(code) === WORKSPACE_DENIED ? ADMIN_OFF : `ChatGPT did not sign you in: ${FREE_OR_AGAIN}`);
132
+ const deniedWords = (code) => (code === WORKSPACE_DENIED ? ADMIN_OFF : `ChatGPT did not sign you in: ${FREE_OR_AGAIN}`);
121
133
  /** Why a sign-in past its browser step ended without signing in, from what pi-ai's flow or keep threw: `reason` for the
122
134
  * log (OpenAI's status and error code, a missing field's name, a network error's code; never a token or a code) and
123
135
  * `words` a person reads. pi-ai's page says the sign-in completed before it exchanges the code, so these are the only
@@ -137,8 +149,9 @@ export function signInFailure(error) {
137
149
  return { reason, words: ADMIN_OFF };
138
150
  if (message.includes(DIRECT_SCOPE))
139
151
  return { reason: "no_direct_scope", words: PLAN_NOT_USABLE };
152
+ const unsaved = notKept ? tag(cause?.code) : "";
140
153
  if (notKept)
141
- return { reason: `not_saved${tag(cause?.code) ? `_${tag(cause.code)}` : ""}`, words: "OpenAI signed you in, but this server could not save the sign-in: start it again. The server's log says why." };
154
+ return { reason: `not_saved${unsaved ? `_${unsaved}` : ""}`, words: "OpenAI signed you in, but this server could not save the sign-in: start it again. The server's log says why." };
142
155
  if (denied)
143
156
  return { reason, words: deniedWords(code) };
144
157
  if (refused)
@@ -178,8 +191,15 @@ export class ChatGPTPlan {
178
191
  /** Why the last sign-in ended without signing in (signInFailure's words past its browser step, or its timeout), until a
179
192
  * sign-in starts, finishes or a sign-out. A cancelled one leaves none. */
180
193
  #problem;
181
- /** Set when the server's change callback failed after a sign-in was saved; cleared once it takes (changeAgain). */
194
+ /** Set when the server's change callback failed (tellChanged); cleared once one that started after it takes. */
182
195
  #changeOwed = false;
196
+ /** Moved on by each change callback that fails: one that takes clears what is owed only if none failed since it began,
197
+ * so a change that read an earlier sign-in never clears a later one's. */
198
+ #failedChanges = 0;
199
+ /** The server's read in flight (refresh), which a read while it is out waits for. */
200
+ #refreshing;
201
+ /** The ends of the sign-ins cancelled and not yet ended (close waits for them). */
202
+ #ending = new Set();
183
203
  #watchers = new Set();
184
204
  #deps;
185
205
  constructor(deps) {
@@ -261,8 +281,12 @@ export class ChatGPTPlan {
261
281
  this.expire();
262
282
  const row = this.#snapshot;
263
283
  const who = row ? { ...(row.email ? { email: row.email } : {}), ...(row.plan ? { plan: row.plan } : {}) } : {};
264
- if (this.#pending)
265
- return { state: "pending", authorize_url: this.#pending.authorizeUrl, expires_at: new Date(this.#pending.expiresAt).toISOString(), ...who };
284
+ if (this.#pending) {
285
+ // Past its first minute with no code back, it says why it may be stuck. Once a code is in (the browser's return or a
286
+ // paste), OpenAI is answering it, and one it answered is being kept: neither is stuck at OpenAI's page.
287
+ const stuck = !this.#pending.codeIn && !this.#pending.answered && this.now() >= this.#pending.startedAt + HINT_AFTER_MS;
288
+ return { state: "pending", authorize_url: this.#pending.authorizeUrl, expires_at: new Date(this.#pending.expiresAt).toISOString(), ...who, ...(stuck ? { hint: STILL_WAITING } : {}) };
289
+ }
266
290
  const problem = this.#problem ? { problem: this.#problem } : {};
267
291
  if (!row)
268
292
  return { state: "signed_out", ...problem };
@@ -284,14 +308,19 @@ export class ChatGPTPlan {
284
308
  this.#pending = undefined;
285
309
  clearTimeout(pending.timer);
286
310
  pending.abort.abort();
311
+ const ended = pending.result.then(() => undefined, () => undefined);
312
+ this.#ending.add(ended);
313
+ void ended.then(() => this.#ending.delete(ended));
287
314
  }
288
- /** Ends the sign-in waiting past its 10 minutes: a cancel, which says nothing by itself, that says it timed out. One
289
- * whose code OpenAI answered is past waiting (it is being kept) and never times out. */
315
+ /** Ends the sign-in waiting past its 10 minutes: a cancel, which says nothing by itself, that says it timed out (with
316
+ * no admin guess when a code came back and its exchange was cut off). One whose code OpenAI answered is past waiting
317
+ * (it is being kept) and never times out. */
290
318
  expire() {
291
319
  if (!this.#pending || this.#pending.answered)
292
320
  return;
321
+ const codeIn = this.#pending.codeIn;
293
322
  this.cancel();
294
- this.#problem = TIMED_OUT;
323
+ this.#problem = codeIn ? CUT_OFF : TIMED_OUT;
295
324
  this.#deps.log?.({ chatgpt: "sign_in_failed", reason: "timed_out" });
296
325
  }
297
326
  /** Starts a sign-in (one at a time: a new start cancels the one waiting) and gives the address to open. It lasts 10
@@ -315,7 +344,13 @@ export class ChatGPTPlan {
315
344
  const link = new Promise((resolve) => (linked = resolve));
316
345
  const login = oauth.login({
317
346
  signal: abort.signal,
318
- notify: (event) => void (event.type === "auth_url" ? linked(event.url) : undefined),
347
+ // pi-ai's progress note comes as a code is in, from the browser's return or a paste, before it asks OpenAI for tokens.
348
+ notify: (event) => {
349
+ if (event.type === "auth_url")
350
+ linked(event.url);
351
+ else if (event.type === "progress" && this.#pending?.abort === abort)
352
+ this.#pending.codeIn = true;
353
+ },
319
354
  prompt: (prompt) => (prompt.type === "manual_code" ? Promise.race([pasted, new Promise((_, reject) => prompt.signal?.addEventListener("abort", () => reject(new Error("closed")), { once: true }))]) : Promise.reject(new Error("not asked here"))),
320
355
  }, { getDeviceId: () => hostId, agentName: AGENT_NAME });
321
356
  const settle = () => {
@@ -328,7 +363,7 @@ export class ChatGPTPlan {
328
363
  const result = login.then((credential) => {
329
364
  if (this.#pending?.abort === abort)
330
365
  this.#pending.answered = true;
331
- return this.keep(credential, epoch).catch((error) => {
366
+ return this.keep(credential, epoch, settle).catch((error) => {
332
367
  throw new NotKept("not kept", { cause: error });
333
368
  });
334
369
  }).finally(settle);
@@ -347,10 +382,11 @@ export class ChatGPTPlan {
347
382
  })]);
348
383
  if (!authorizeUrl)
349
384
  throw new PlanSignInRefused("The sign-in could not start: try again.");
350
- const expiresAt = this.now() + PENDING_MS;
385
+ const startedAt = this.now();
386
+ const expiresAt = startedAt + PENDING_MS;
351
387
  const timer = setTimeout(() => (this.#pending?.abort === abort ? this.expire() : undefined), PENDING_MS);
352
388
  timer.unref();
353
- this.#pending = { abort, state: new URL(authorizeUrl).searchParams.get("state") ?? "", authorizeUrl, expiresAt, paste, result, timer };
389
+ this.#pending = { abort, state: new URL(authorizeUrl).searchParams.get("state") ?? "", authorizeUrl, startedAt, expiresAt, paste, result, timer };
354
390
  waiting = true;
355
391
  return { authorize_url: authorizeUrl, expires_at: new Date(expiresAt).toISOString() };
356
392
  }
@@ -372,16 +408,22 @@ export class ChatGPTPlan {
372
408
  throw new PlanSignInRefused(shape);
373
409
  const error = url.searchParams.get("error");
374
410
  if (error)
375
- throw new PlanSignInRefused(deniedWords(error));
411
+ throw new PlanSignInRefused(deniedWords(tag(error)));
376
412
  if (url.searchParams.get("state") !== pending.state)
377
413
  throw new PlanSignInRefused("That address is from another sign-in: paste the one from the sign-in you started last, or start again.");
378
414
  if (!url.searchParams.get("code") || !url.searchParams.get("client_id"))
379
415
  throw new PlanSignInRefused(`That address has no sign-in code in it. ${shape}`);
416
+ // A code is in from here (pi-ai's progress note says the same a moment later): a view meanwhile shows no hint.
417
+ pending.codeIn = true;
380
418
  pending.paste(url.href);
381
419
  try {
382
420
  await pending.result;
383
421
  }
384
422
  catch (error) {
423
+ // Cancelled while its code's exchange was out (a newer start, a sign-out, the 10 minutes): the log has no line of
424
+ // it, so the words say what the view says, or that it was cancelled.
425
+ if (pending.abort.signal.aborted)
426
+ throw new PlanSignInRefused(this.#problem ?? "That sign-in was replaced or signed out: start it again.");
385
427
  throw new PlanSignInRefused(signInFailure(error).words);
386
428
  }
387
429
  return this.view();
@@ -390,7 +432,7 @@ export class ChatGPTPlan {
390
432
  * sign-in since then wins: the credential is dropped, never written, and revoked at OpenAI. A sign-in it takes the place
391
433
  * of is revoked first, then replaced only while the row still holds it (a renewal of it that wrote back meanwhile is
392
434
  * read, revoked and replaced in turn), so no earlier pair is left alive. */
393
- async keep(credential, epoch) {
435
+ async keep(credential, epoch, saved) {
394
436
  if (credential.scopes && !credential.scopes.includes(DIRECT_SCOPE))
395
437
  throw new Error(`the grant did not include ${DIRECT_SCOPE}`);
396
438
  this.hold(credential);
@@ -421,30 +463,43 @@ export class ChatGPTPlan {
421
463
  this.#snapshot = row;
422
464
  this.#problem = undefined;
423
465
  this.#deps.log?.({ chatgpt: "signed_in", ...(previousRevoked === undefined ? {} : { previous_revoked: String(previousRevoked) }) });
424
- // Saved: what the server does with the change after it is not the sign-in's to fail. One it failed to take is owed,
425
- // and taken again at its next read (changeAgain).
466
+ // Saved: no longer waiting, so it reads signed in while the server takes the change (`saved`, the sign-in's settle).
467
+ saved?.();
468
+ await this.tellChanged();
469
+ }
470
+ /** Tells the server the sign-in changed (its change callback: env read again, the listings relisted, the offers
471
+ * probed). What the server does with it is not the change's to fail: a failure is owed, said in the log (once: not
472
+ * again for `again`, a retry of one owed), and taken again at the server's next read (refresh). */
473
+ async tellChanged(again = false) {
474
+ const failed = this.#failedChanges;
426
475
  try {
427
476
  await this.#deps.changed?.();
428
- this.#changeOwed = false;
477
+ if (this.#failedChanges === failed)
478
+ this.#changeOwed = false;
429
479
  }
430
480
  catch (error) {
481
+ this.#failedChanges += 1;
431
482
  this.#changeOwed = true;
483
+ if (again)
484
+ return;
432
485
  const code = error?.code;
433
- this.#deps.log?.({ chatgpt: "changed_failed", reason: String(typeof code === "string" ? code : error?.name ?? "error").replace(/[^A-Za-z0-9_]/g, "").slice(0, 40) || "error" });
486
+ this.#deps.log?.({ chatgpt: "changed_failed", reason: tag(typeof code === "string" ? code : error?.name) || "error" });
434
487
  }
435
488
  }
436
- /** Takes again a sign-in's change the server failed to take (changed_failed), at the server's read of the sign-in, so
437
- * what it offers does not wait for a restart. Nothing when none is owed; a failure again stays owed, said once. */
438
- async changeAgain() {
439
- if (!this.#changeOwed)
440
- return;
441
- try {
442
- await this.#deps.changed?.();
443
- this.#changeOwed = false;
444
- }
445
- catch {
446
- // Owed still: the next read takes it again.
447
- }
489
+ /** The sign-in as the store holds it now, read at the server's read of it: a runner may have renewed it, found it
490
+ * expired, or another server signed in or out. A change is told to the server, and so is one it failed to take, so
491
+ * what it offers does not wait for a restart. One at a time: a read while one is out waits for that one (the console
492
+ * polls, and each change relists and probes). */
493
+ refresh() {
494
+ // Cleared in a reaction, never inside the function: a read that throws at once would run a `finally` there before
495
+ // the assignment, and leave a settled promise in flight for good.
496
+ return (this.#refreshing ??= (async () => {
497
+ const was = this.state;
498
+ if ((await this.load()).state !== was)
499
+ await this.tellChanged();
500
+ else if (this.#changeOwed)
501
+ await this.tellChanged(true);
502
+ })().finally(() => (this.#refreshing = undefined)));
448
503
  }
449
504
  /** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families; the fallback
450
505
  * list when it can't be read. */
@@ -552,7 +607,7 @@ export class ChatGPTPlan {
552
607
  if (await this.swap(bytes, expired)) {
553
608
  this.#snapshot = expired;
554
609
  this.#deps.log?.({ chatgpt: "expired" });
555
- await this.#deps.changed?.();
610
+ await this.tellChanged();
556
611
  throw new PlanUnavailable(EXPIRED);
557
612
  }
558
613
  return this.adopt();
@@ -612,7 +667,7 @@ export class ChatGPTPlan {
612
667
  }
613
668
  this.#snapshot = undefined;
614
669
  this.#deps.log?.({ chatgpt: "signed_out", revoked: String(revoked) });
615
- await this.#deps.changed?.();
670
+ await this.tellChanged();
616
671
  return { revoked };
617
672
  }
618
673
  /** `credential`'s session revoked at OpenAI (its documented revocation endpoint, with the refresh token): whether OpenAI
@@ -631,9 +686,11 @@ export class ChatGPTPlan {
631
686
  return false;
632
687
  }
633
688
  }
634
- /** Stops the sign-in waiting, at the server's close. */
689
+ /** Stops the sign-in waiting, at the server's close. Resolves once every sign-in cancelled (by this, a newer start, a
690
+ * sign-out or its 10 minutes) has ended, whatever its end said in the log. */
635
691
  close() {
636
692
  this.cancel();
693
+ return Promise.all([...this.#ending]).then(() => undefined);
637
694
  }
638
695
  }
639
696
  /** For a run on a plan model (`model`, the one its claim chose): the plan's token read once before anything starts, so a
@@ -0,0 +1,117 @@
1
+ import type { ClaudeAgentLogin, ClaudeLoginToken } from "@parcha/agentrun-harness-claude";
2
+ import type { Runners } from "./store/index.js";
3
+ /** The pinned CLI's credentials file in its credentials directory (CLAUDE_SECURESTORAGE_CONFIG_DIR). */
4
+ export declare const LOGIN_FILE = ".credentials.json";
5
+ /** The least a token handed to a run has left: the pinned CLI's own margin before it calls a token expired (its
6
+ * `n+300000>=e`), and when the runner renews it. */
7
+ export declare const LOGIN_MARGIN_MS: number;
8
+ /** The longest one renewal request may take: the runner gives it up then (chatgpt-plan.ts's own). */
9
+ export declare const REFRESH_CALL_MS = 15000;
10
+ /** How long an ask waits while another holder (the CLI, another runner) holds the login's refresh lock: the CLI's own
11
+ * request timeout (30 s) and its write back. Then it refuses, having posted nothing. */
12
+ export declare const LOCK_WAIT_MS = 35000;
13
+ /** The words a run gets when the login's token has less than the margin left and the runner could not renew it. */
14
+ export declare const LOGIN_RUNNING_OUT = "Claude Code's login on this machine runs out in less than 5 minutes, and the runner could not renew it: open Claude Code on this login once to renew it, or sign in again under Settings \u2192 Model keys, then start the run again.";
15
+ /** The words a run gets when Anthropic refused the login's token (the run's CLI's 401), whatever time it had left, and
16
+ * the runner could not renew it. */
17
+ export declare const LOGIN_REFUSED_NOT_RENEWED = "Claude refused this login and it could not be renewed; open Claude Code once to sign in again.";
18
+ /** The words a run gets when the runner renewed the login but could not write the renewal to the login's file, and the
19
+ * renewed token it holds in memory has less than the margin left: Anthropic took the file's refresh token, so only that
20
+ * held pair can be renewed, and the runner renews only from the file. */
21
+ export declare const LOGIN_NOT_SAVED = "Claude Code's login on this machine was renewed, but the runner could not save the renewal to the login's file, and the renewed token runs out in less than 5 minutes: make room on the disk (or fix the login folder's permissions) and start the run again; if the runner restarted meanwhile, sign in again under Settings \u2192 Model keys.";
22
+ /** The words a run gets when the login is kept in a form this runner does not read (not the pinned CLI's plaintext file). */
23
+ export declare const LOGIN_SEALED = "Claude Code's login on this machine is kept in a form this runner cannot hand to a run of its own user: set AGENTRUN_RUN_USER=same, or give the run a model_key.";
24
+ /** What a renewal hands back: the token it got and its end, for the one ask whose re-read still finds the old token (a
25
+ * write back that did not land); the file's own read wins otherwise. */
26
+ export type Renewed = {
27
+ readonly access: string;
28
+ readonly expiresAt: number;
29
+ };
30
+ /** Renews `login` in its own file, the one whose access token was read as `seen`, unless the file holds another by then
31
+ * (another holder renewed it: nothing to do). Throws when it could not. `refused`: the token Anthropic refused (the
32
+ * run's CLI's 401), when there is one: a held pair holding it is renewed once saved, never handed again. */
33
+ export type Renew = (login: ClaudeAgentLogin, seen: string, refused?: string) => Promise<Renewed | undefined>;
34
+ export interface LoginTokensOptions {
35
+ /** The login's directories (claude-login.ts loginAt): its file is LOGIN_FILE in `dir`. */
36
+ readonly login: ClaudeAgentLogin;
37
+ readonly now?: () => number;
38
+ /** The renewal. Default: the pinned CLI's own (renewLogin), with `fetch`, `now` and `log` below. */
39
+ readonly renew?: Renew;
40
+ /** What the default renewal posts with (a test's fake endpoint). Default: the global fetch, as it is at the post. */
41
+ readonly fetch?: typeof fetch;
42
+ /** Told each renewal's outcome, in fields that hold no token. */
43
+ readonly log?: (fields: Record<string, string>) => void;
44
+ }
45
+ /** The runner's reader of one login's access token, and its renewer. */
46
+ export declare class LoginTokens {
47
+ #private;
48
+ constructor(options: LoginTokensOptions);
49
+ /** Tells `listener` each token as it is handed, for a redactor. */
50
+ watch(listener: (tokens: string[]) => void): void;
51
+ /** The login's access token, read from its file now, with at least LOGIN_MARGIN_MS left: renewed first (once) when
52
+ * it has less, or when Anthropic refused it (refused). Else it throws in words (signed out, a form not read here, or
53
+ * near its end and not renewed), never with a value of the file in them. */
54
+ token(): Promise<string>;
55
+ /** Anthropic refused `sent` (the run's CLI's 401): the next ask renews it, unless the file holds another token by
56
+ * then (another holder renewed it, and that one is handed). */
57
+ refused(sent: string): Promise<void>;
58
+ }
59
+ export interface RenewLoginOptions {
60
+ /** What it posts with. Default: the global fetch, as it is at the post. */
61
+ readonly fetch?: typeof fetch;
62
+ /** The clock a renewed token's end is counted on (the reader's). A lock's age is the wall clock's, as the CLI's. */
63
+ readonly now?: () => number;
64
+ readonly log?: (fields: Record<string, string>) => void;
65
+ /** Default REFRESH_CALL_MS. */
66
+ readonly callMs?: number;
67
+ /** Default LOCK_WAIT_MS. */
68
+ readonly lockWaitMs?: number;
69
+ /** The refresh locks' file operations. Default: fs/promises' own. */
70
+ readonly lockFs?: LockFs;
71
+ /** How often a held lock is read and touched (its heartbeat). Default: the pinned CLI's (`update:5000`). */
72
+ readonly lockUpdateMs?: number;
73
+ }
74
+ /** 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
+ 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). */
78
+ export interface LockFs {
79
+ mkdir(path: string): Promise<unknown>;
80
+ stat(path: string): Promise<LockIdentity>;
81
+ utimes(path: string, atime: Date, mtime: Date): Promise<void>;
82
+ rm(path: string, options: {
83
+ readonly recursive: boolean;
84
+ readonly force: boolean;
85
+ }): Promise<void>;
86
+ }
87
+ /** A lock directory as read: which directory it is (its device and inode) and its mtime. */
88
+ type LockIdentity = {
89
+ readonly dev: number;
90
+ readonly ino: number;
91
+ readonly mtimeMs: number;
92
+ };
93
+ /** Whether `login` is AgentRun's own login folder in `data` (claude-login.ts loginAt "agentrun"), the one login a run
94
+ * under a user of its own is handed a token of; this machine's own Claude Code login is not. */
95
+ 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.";
100
+ /** A run's own process's login (held.ts claudeLogin's reader): each token it reads held by `hold` (the run's redactors)
101
+ * 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. */
103
+ export declare function heldTokenLogin(reader: {
104
+ token(): Promise<string>;
105
+ refused?(sent: string): Promise<void>;
106
+ }, hold: (values: string[]) => void): ClaudeLoginToken;
107
+ /** Where the runners on a data folder say whether their runs on the login stay in their own process: one file per
108
+ * runner, named by the sha256 of its whole name, so two names never share a file and no name is a folder (`.`,
109
+ * `..`). The file holds the name itself, which loginRunnerInProcess reads. */
110
+ export declare const loginRunnersDir: (data: string) => string;
111
+ /** Runner `runner` says, at its start, how its runs on the login run: `process` (in its own process, its CLI on the
112
+ * login folder), or `uid` (each a user of its own, on a token), which takes back what an earlier start of that name said. */
113
+ export declare function sayLoginRunner(data: string, runner: string, isolation: "uid" | "process"): void;
114
+ /** The name of a runner on data folder `data` whose runs on the login stay in its own process, and whose word in the
115
+ * store is fresh (presence.ts); none when there is no such runner. */
116
+ export declare function loginRunnerInProcess(data: string, runners: Pick<Runners, "live">): Promise<string | undefined>;
117
+ export {};