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

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 (250) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +230 -120
  3. package/dist/acp-package.d.ts +4 -0
  4. package/dist/agent-delete.d.ts +6 -9
  5. package/dist/agent-delete.js +5 -3
  6. package/dist/agent-package.js +11 -1
  7. package/dist/api-only.d.ts +21 -3
  8. package/dist/api-only.js +41 -6
  9. package/dist/archil-routes.d.ts +4 -1
  10. package/dist/archil-routes.js +15 -12
  11. package/dist/archil-settings.d.ts +18 -8
  12. package/dist/archil-settings.js +35 -17
  13. package/dist/browser-person.d.ts +1 -1
  14. package/dist/browser-person.js +1 -1
  15. package/dist/calendar/tools.js +1 -1
  16. package/dist/chatgpt-plan.d.ts +4 -2
  17. package/dist/chatgpt-plan.js +13 -3
  18. package/dist/claude-login-token.d.ts +5 -0
  19. package/dist/claude-login-token.js +8 -0
  20. package/dist/claude-login.d.ts +49 -3
  21. package/dist/claude-login.js +140 -10
  22. package/dist/cli-learning/connections.js +1 -1
  23. package/dist/cli.js +42 -10
  24. package/dist/console/assets/{backend-BztxEAvb.js → backend-C9ffXUR5.js} +1 -1
  25. package/dist/console/assets/index-BnZV3lvW.js +639 -0
  26. package/dist/console/assets/{share-L84tlUDW.js → share-B1o5mJ56.js} +2 -2
  27. package/dist/console/assets/{styles-CaRKlHke.js → styles-D_znYrHR.js} +31 -31
  28. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  29. package/dist/console/index.html +3 -3
  30. package/dist/console/share.html +3 -3
  31. package/dist/decisions.d.ts +1 -1
  32. package/dist/decisions.js +2 -2
  33. package/dist/errors.d.ts +1 -0
  34. package/dist/errors.js +2 -0
  35. package/dist/factory-activity.d.ts +68 -0
  36. package/dist/factory-activity.js +153 -0
  37. package/dist/factory-runs.d.ts +11 -0
  38. package/dist/factory-runs.js +52 -0
  39. package/dist/filed-tool.d.ts +32 -0
  40. package/dist/filed-tool.js +122 -0
  41. package/dist/harness-check.js +2 -1
  42. package/dist/harness-keys.d.ts +1 -2
  43. package/dist/harness-keys.js +1 -2
  44. package/dist/harness-recipe.d.ts +13 -2
  45. package/dist/harness-recipe.js +30 -7
  46. package/dist/harness-sign-in.js +2 -1
  47. package/dist/harness-table.d.ts +9 -3
  48. package/dist/harness-table.js +11 -5
  49. package/dist/harness.js +6 -2
  50. package/dist/import-worker.js +2 -2
  51. package/dist/import.d.ts +9 -0
  52. package/dist/import.js +11 -1
  53. package/dist/key-refusal.d.ts +5 -0
  54. package/dist/key-refusal.js +30 -18
  55. package/dist/learn/audit.d.ts +20 -22
  56. package/dist/learn/audit.js +72 -55
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +35 -43
  59. package/dist/learn/commit.js +62 -270
  60. package/dist/learn/compile.d.ts +4 -4
  61. package/dist/learn/compile.js +6 -7
  62. package/dist/learn/corrections.js +1 -1
  63. package/dist/learn/delete.d.ts +5 -12
  64. package/dist/learn/delete.js +17 -30
  65. package/dist/learn/forget-run.d.ts +16 -0
  66. package/dist/learn/forget-run.js +53 -0
  67. package/dist/learn/index.js +1 -1
  68. package/dist/learn/learning-of.d.ts +0 -4
  69. package/dist/learn/learning-of.js +0 -5
  70. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  71. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  72. package/dist/learn/legacy/place.d.ts +16 -0
  73. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  74. package/dist/learn/legacy/scrub.d.ts +28 -0
  75. package/dist/learn/legacy/scrub.js +258 -0
  76. package/dist/learn/promote.d.ts +40 -66
  77. package/dist/learn/promote.js +69 -207
  78. package/dist/learn/reset-ledger.d.ts +18 -0
  79. package/dist/learn/reset-ledger.js +14 -0
  80. package/dist/learn/rows.d.ts +186 -0
  81. package/dist/learn/rows.js +376 -0
  82. package/dist/learn/secrets.d.ts +2 -1
  83. package/dist/learn/secrets.js +2 -2
  84. package/dist/learn/workflow-draft.d.ts +4 -1
  85. package/dist/learn/workflow-draft.js +12 -2
  86. package/dist/learned-nodes.d.ts +36 -0
  87. package/dist/learned-nodes.js +23 -0
  88. package/dist/learning-reset.d.ts +1 -1
  89. package/dist/learning-reset.js +9 -11
  90. package/dist/learning-routes.d.ts +60 -81
  91. package/dist/learning-routes.js +187 -360
  92. package/dist/learning-words.d.ts +2 -0
  93. package/dist/learning-words.js +2 -0
  94. package/dist/learning.d.ts +18 -24
  95. package/dist/learning.js +35 -66
  96. package/dist/local-model.d.ts +144 -0
  97. package/dist/local-model.js +214 -0
  98. package/dist/mcp-gateway.d.ts +6 -0
  99. package/dist/mcp-gateway.js +44 -8
  100. package/dist/mcp-probe.d.ts +7 -0
  101. package/dist/mcp-probe.js +7 -0
  102. package/dist/mcp-resources.d.ts +1 -1
  103. package/dist/native/discovery.d.ts +6 -0
  104. package/dist/native/discovery.js +14 -1
  105. package/dist/native/remote.d.ts +5 -0
  106. package/dist/native/remote.js +16 -0
  107. package/dist/native/runtime.js +3 -2
  108. package/dist/observation/observer.d.ts +6 -6
  109. package/dist/ollama-provider.d.ts +35 -0
  110. package/dist/ollama-provider.js +108 -2
  111. package/dist/openapi.js +147 -35
  112. package/dist/place-offers.d.ts +3 -0
  113. package/dist/place-offers.js +3 -0
  114. package/dist/place.d.ts +35 -12
  115. package/dist/place.js +67 -29
  116. package/dist/print.js +1 -1
  117. package/dist/purged-workflow.d.ts +0 -33
  118. package/dist/purged-workflow.js +3 -71
  119. package/dist/redact/match.d.ts +36 -8
  120. package/dist/redact/match.js +179 -44
  121. package/dist/run-export.js +4 -2
  122. package/dist/run-launch.d.ts +3 -3
  123. package/dist/run-learning-served.d.ts +3 -3
  124. package/dist/run-learning-served.js +1 -1
  125. package/dist/run-listing.d.ts +1 -1
  126. package/dist/run-timeline-served.d.ts +1 -1
  127. package/dist/run-timeline-served.js +6 -5
  128. package/dist/run-usage.js +3 -2
  129. package/dist/runnable.js +25 -8
  130. package/dist/runner/adapter-loop.d.ts +8 -1
  131. package/dist/runner/adapter-loop.js +100 -20
  132. package/dist/runner/adapter-run-spec.d.ts +3 -5
  133. package/dist/runner/adapter-run-spec.js +35 -61
  134. package/dist/runner/adapters/pi.d.ts +3 -2
  135. package/dist/runner/adapters/pi.js +3 -1
  136. package/dist/runner/audit.d.ts +3 -5
  137. package/dist/runner/audit.js +28 -51
  138. package/dist/runner/cli-run-spec.js +19 -22
  139. package/dist/runner/compare-end.d.ts +1 -3
  140. package/dist/runner/compare-end.js +6 -2
  141. package/dist/runner/disk-free.d.ts +15 -4
  142. package/dist/runner/disk-free.js +25 -7
  143. package/dist/runner/dispatch.js +2 -2
  144. package/dist/runner/feedback-round.d.ts +1 -1
  145. package/dist/runner/feedback-round.js +2 -2
  146. package/dist/runner/harness-loops.d.ts +9 -0
  147. package/dist/runner/harness-loops.js +49 -7
  148. package/dist/runner/held.d.ts +4 -11
  149. package/dist/runner/held.js +0 -25
  150. package/dist/runner/journal-kinds.d.ts +4 -1
  151. package/dist/runner/journal-kinds.js +1 -1
  152. package/dist/runner/learned-first.d.ts +0 -2
  153. package/dist/runner/learned-first.js +3 -3
  154. package/dist/runner/learning-end.d.ts +12 -16
  155. package/dist/runner/learning-end.js +41 -75
  156. package/dist/runner/learning-seed.d.ts +13 -16
  157. package/dist/runner/learning-seed.js +13 -23
  158. package/dist/runner/live-ticker.js +3 -4
  159. package/dist/runner/main.js +1 -1
  160. package/dist/runner/mcp-claim.js +3 -2
  161. package/dist/runner/mcp-run.d.ts +23 -4
  162. package/dist/runner/mcp-run.js +31 -2
  163. package/dist/runner/metrics.d.ts +4 -0
  164. package/dist/runner/metrics.js +9 -3
  165. package/dist/runner/monid-run.js +3 -1
  166. package/dist/runner/native-loop.js +3 -4
  167. package/dist/runner/promotion.d.ts +19 -28
  168. package/dist/runner/promotion.js +50 -69
  169. package/dist/runner/redact.d.ts +3 -0
  170. package/dist/runner/redact.js +7 -0
  171. package/dist/runner/reflect-hook.d.ts +2 -2
  172. package/dist/runner/reflect-hook.js +4 -1
  173. package/dist/runner/run-child-host.d.ts +1 -9
  174. package/dist/runner/run-child-host.js +12 -68
  175. package/dist/runner/runner.d.ts +1 -1
  176. package/dist/runner/sdk-loop.js +7 -7
  177. package/dist/runner/workflow-calls.d.ts +4 -1
  178. package/dist/runner/workflow-calls.js +35 -18
  179. package/dist/runner/workflow-loop.d.ts +1 -1
  180. package/dist/runner/workflow-loop.js +3 -1
  181. package/dist/runner/workflow-spec.d.ts +4 -0
  182. package/dist/runner/workflow-spec.js +18 -13
  183. package/dist/runs-over-store.d.ts +2 -2
  184. package/dist/runs-over-store.js +1 -1
  185. package/dist/sdk/check.d.ts +1 -4
  186. package/dist/sdk/check.js +2 -3
  187. package/dist/sdk/runs.d.ts +20 -7
  188. package/dist/sdk/runs.js +105 -68
  189. package/dist/secret-cut.js +7 -4
  190. package/dist/secret-rules.js +97 -83
  191. package/dist/secrets.d.ts +4 -0
  192. package/dist/secrets.js +44 -10
  193. package/dist/server-fs.d.ts +1 -1
  194. package/dist/server-fs.js +1 -1
  195. package/dist/server-keys.d.ts +6 -0
  196. package/dist/server-keys.js +12 -0
  197. package/dist/server.d.ts +22 -15
  198. package/dist/server.js +311 -198
  199. package/dist/slack.js +2 -1
  200. package/dist/source-sync/auxiliary.js +2 -2
  201. package/dist/store/index.d.ts +1 -1
  202. package/dist/store/index.js +1 -1
  203. package/dist/store/postgres/migrate.js +3 -1
  204. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  205. package/dist/store/schema.d.ts +28 -2
  206. package/dist/store/schema.js +81 -5
  207. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  208. package/dist/store/sqlite/learning-rows.js +559 -0
  209. package/dist/store/sqlite/store.d.ts +7 -1
  210. package/dist/store/sqlite/store.js +84 -18
  211. package/dist/store/store.d.ts +219 -6
  212. package/dist/store/store.js +13 -0
  213. package/dist/store-reads/journal.d.ts +33 -3
  214. package/dist/store-reads/journal.js +99 -4
  215. package/dist/store-reads/learning.d.ts +23 -26
  216. package/dist/store-reads/learning.js +42 -30
  217. package/dist/store-reads/loop.js +1 -1
  218. package/dist/store-view.d.ts +24 -2
  219. package/dist/store-view.js +40 -11
  220. package/dist/templates.d.ts +10 -2
  221. package/dist/templates.js +31 -4
  222. package/dist/tool-plane.d.ts +27 -3
  223. package/dist/tool-plane.js +79 -4
  224. package/dist/tools.d.ts +12 -2
  225. package/dist/tools.js +42 -7
  226. package/dist/trigger-launch-hook.d.ts +2 -2
  227. package/dist/trigger-launch-hook.js +1 -1
  228. package/dist/triggers.d.ts +7 -4
  229. package/dist/triggers.js +4 -4
  230. package/dist/web-holds.d.ts +2 -0
  231. package/dist/web-holds.js +5 -2
  232. package/dist/web-run.js +2 -1
  233. package/dist/workspace/archil-exec.js +1 -1
  234. package/dist/workspace/archil.d.ts +1 -1
  235. package/dist/workspace/archil.js +1 -1
  236. package/dist/workspace/computer-deps.js +5 -3
  237. package/dist/workspace/computer-providers.d.ts +11 -1
  238. package/dist/workspace/computer-providers.js +29 -2
  239. package/dist/workspace/index.d.ts +1 -2
  240. package/dist/workspace/index.js +1 -2
  241. package/dist/workspace/paths.d.ts +0 -4
  242. package/dist/workspace/paths.js +0 -6
  243. package/dist/workspace/workspace.d.ts +1 -1
  244. package/dist/workspace/workspace.js +1 -1
  245. package/package.json +13 -13
  246. package/templates/TOOLS.md +46 -0
  247. package/dist/console/assets/index-LwNL4L9q.js +0 -619
  248. package/dist/console/assets/styles-DQo8rzY-.css +0 -1
  249. package/dist/workspace/learning-workspace.d.ts +0 -24
  250. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
@@ -111,7 +111,7 @@ export type LoginAt = {
111
111
  * runs on a copy of the account file (the harness's claudeLoginStatus). Every login carries the person's home as
112
112
  * `userHome`, read here once (homeOf), so the status check, the sign-in and a run on macOS all run in that one home
113
113
  * whatever reads it later (the harness's personHome), and `homeApart` where the env's HOME was not that home (homeOf's
114
- * `apart`). The home and the folders the env gives are the real paths the walk ended in. */
114
+ * `apart`). AgentRun's carries `own`. The home and the folders the env gives are the real paths the walk ended in. */
115
115
  export declare function loginAt(place: LoginPlace, data: string, env?: Readonly<Record<string, string | undefined>>, uid?: number | undefined): LoginAt;
116
116
  /** The setting as saved, or undefined when the mode is not on (or the row is not one this reads). */
117
117
  export declare function claudeLoginSetting(settings: Pick<Settings, "get">): Promise<Setting | undefined>;
@@ -128,7 +128,8 @@ export declare const loginByToken: (login: RunLogin) => login is ClaudeLoginToke
128
128
  * it (it is no variable), and it holds two directory names or a token reader, never a token. */
129
129
  export declare function withClaudeLogin<T extends object>(env: T, login: RunLogin | undefined): T;
130
130
  /** `env` as a run at `place` reads it: a runner place keeps the login; any other place (a sandbox) gets a copy without it,
131
- * so a revision's checks there ask for a key, as its run will. */
131
+ * so a revision's checks there ask for a key, as its run will. The copy is copyEnv's, which keeps withSecrets' keys
132
+ * (read by name, never enumerated), where a spread would keep none. */
132
133
  export declare function envAtPlace<T extends object>(env: T, place: {
133
134
  readonly mode: string;
134
135
  } | undefined): T;
@@ -262,6 +263,9 @@ export declare class ClaudeLoginRefused extends Error {
262
263
  }
263
264
  /** GET /settings/claude-login: the mode's state and, when on, what the CLI says of its login. */
264
265
  export declare function claudeLoginView(deps: ClaudeLoginDeps): Promise<ClaudeLoginView>;
266
+ /** Why a turn-on is refused where AgentRun's own login folder (`dir`) is a link (to `to`). A sign-out removes that folder
267
+ * whole, so it is one AgentRun keeps itself, and no link leads a sign-out into a folder elsewhere. */
268
+ export declare const loginFolderIsLink: (dir: string, to: string) => string;
265
269
  /** PUT /settings/claude-login: turned on, refused in one line where more than one person can start runs. A turn-on that
266
270
  * moves the login to another place first ends a sign-in this server started that still waits: its CLI signs in at the
267
271
  * old place, which the login no longer reads. One at the same place leaves it waiting, as it still signs in there. */
@@ -269,6 +273,48 @@ export declare function turnOnClaudeLogin(deps: ClaudeLoginDeps, body: unknown):
269
273
  /** DELETE /settings/claude-login: turned off, and a sign-in this server started that still waits is ended. The login
270
274
  * itself stays as the CLI keeps it; nothing here signs it out. */
271
275
  export declare function turnOffClaudeLogin(deps: ClaudeLoginDeps): Promise<ClaudeLoginView>;
276
+ /** What a sign-out answers beside `confirmed: false`: the login is gone here, and the CLI said nothing of its own copy. */
277
+ export declare const LOGIN_SIGN_OUT_UNCONFIRMED: string;
278
+ /** What a sign-out answers beside `confirmed: false` where the CLI's step threw (`failed`, the error's words): the login is
279
+ * gone here all the same, and the CLI's own copy may remain. */
280
+ export declare const signOutCliFailed: (failed: string) => string;
281
+ /** What a sign-out answers beside `confirmed: false` where some of the login is still there (`left`: each thing, its path
282
+ * and why), and the Keychain's words too where the CLI didn't confirm its own sign-out (`keychain`), naming the CLI
283
+ * step's failure where it threw (`failed`). */
284
+ export declare const signOutLeft: (left: readonly string[], keychain: boolean, failed?: string) => string;
285
+ /** Why a sign-out of this machine's own login (`folder`, the person's `~/.claude` or CLAUDE_CONFIG_DIR) is refused. */
286
+ export declare const machineSignOutRefused: (folder: string) => string;
287
+ /** POST /settings/claude-login/sign-out's answer: whether all of the login is gone (the CLI confirmed its own sign-out and
288
+ * every removal landed, whether or not a folder was there), else words saying what may remain
289
+ * (LOGIN_SIGN_OUT_UNCONFIRMED, signOutLeft), and the view after it (`off`). */
290
+ export type ClaudeLoginSignOut = {
291
+ confirmed: boolean;
292
+ message?: string;
293
+ login: ClaudeLoginView;
294
+ };
295
+ /** POST /settings/claude-login/sign-out: AgentRun's own login (`<data>/claude-login`) signed out and removed, so the next
296
+ * turn-on finds none and the person signs in fresh, to the same account or another. In one turn on the sign-ins' queue
297
+ * (no sign-in or turn-on lands in between): a sign-in this server started that still waits is ended; the mode is turned
298
+ * off, so no new run goes on the login while it goes; the pinned CLI's own sign-out (the harness's claudeLogout) runs on
299
+ * the folder, so it removes its credentials file and, on macOS, the Keychain item named from the folder. It runs where
300
+ * the folder is gone too: a retry after a sign-out the CLI didn't confirm finds no folder, and the Keychain item may
301
+ * remain, so the answer is confirmed only where the CLI confirms. Then the folder is removed whatever the CLI said (a
302
+ * folder the CLI made as it signed out too) (credentials, account, profiles, the CLI's refresh lock, and
303
+ * the CLI's older lock beside it), with the login's signed-in note (noteAnswer) and this process's token reader of it
304
+ * (claude-login-token.ts forgetLoginTokens). Each removal stands alone: one that fails is named in the answer
305
+ * (signOutLeft, `confirmed` false), and the others, the reader's drop and the server's reread of the keys still happen.
306
+ * So with the CLI's step: a throw finding the CLI or loading the harness is named in the answer (signOutCliFailed), and
307
+ * every removal still runs.
308
+ * Where the folder is a link (put there after the turn-on, which refuses one), the link alone is removed, with the
309
+ * login's signed-in note: no CLI runs through it, nothing it leads to is touched, and the answer names it. Runs already going are left as a turn-off
310
+ * leaves them: each keeps the token its CLI holds, and fails in
311
+ * LOGIN_SIGNED_OUT's words at its next read of the login; one claimed on it and started while the mode is off is refused
312
+ * at its start (claude-login-token.ts LOGIN_CHANGED_SINCE_CLAIM). That check is of the folder, not the account, so one
313
+ * started after a turn-on and a new sign-in runs on that sign-in. A run whose CLI reads the folder itself (in the
314
+ * runner's process) holds the refresh token and may write a renewed pair back after the folder goes; nothing here
315
+ * removes it again. A login on this machine's own folder (`machine`) is the person's:
316
+ * refused (machineSignOutRefused), with nothing touched. */
317
+ export declare function signOutClaudeLogin(deps: ClaudeLoginDeps): Promise<ClaudeLoginSignOut>;
272
318
  /** POST /settings/claude-login/login: the CLI's own sign-in, started on this machine, where it opens a browser, with the
273
319
  * shown line's own variables (the harness's signInEnv), so it signs in where the status reads. A sign-in that
274
320
  * still waits is ended first (deps.signIns). The browser code goes to the CLI, never here; the answer is the view as it
@@ -283,7 +329,7 @@ export declare function startLoginHere(deps: ClaudeLoginDeps): Promise<ClaudeLog
283
329
  * every change of the setting is. */
284
330
  export declare function dropRefusedLogin(signIns: Pick<ClaudeSignIns, "serial">, settings: Pick<Settings, "get" | "remove">, why: string | undefined, env: Readonly<Record<string, string | undefined>>, log: (line: string) => void): Promise<void>;
285
331
  /** What the routes and a run's check use of the harness (its login.ts), loaded only when asked. */
286
- export type ClaudeLoginCli = Pick<typeof import("@parcha/agentrun-harness-claude"), "claudeLoginStatus" | "startClaudeLogin" | "claudeLoginCommand">;
332
+ export type ClaudeLoginCli = Pick<typeof import("@parcha/agentrun-harness-claude"), "claudeLoginStatus" | "startClaudeLogin" | "claudeLoginCommand" | "claudeLogout">;
287
333
  /** How long a signed-in answer stands in for a check that gives none (loginBeforeRun). */
288
334
  export declare const LOGIN_ANSWER_STANDS_MS: number;
289
335
  /** The folder in the data folder that holds, per login, when it last answered signed in (noteAnswer). The server and its
@@ -13,15 +13,17 @@
13
13
  // for a server one person runs: it is refused where more than one person can start runs, `on` included, and the owner
14
14
  // confirms they alone run agents here. It runs only in a runner place, on the machine the owner turned it on for.
15
15
  import { createHash, randomBytes } from "node:crypto";
16
- import { accessSync, chmodSync, closeSync, constants, existsSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readlinkSync, readSync, renameSync, rmSync, writeFileSync } from "node:fs";
16
+ import { accessSync, chmodSync, closeSync, constants, existsSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readlinkSync, readSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
17
17
  import { homedir, userInfo } from "node:os";
18
- import { delimiter, dirname, isAbsolute, join } from "node:path";
19
- import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
20
- import { registerSecretWrite } from "./secret-writes.js";
18
+ import { basename, delimiter, dirname, isAbsolute, join } from "node:path";
19
+ import { facts as claudeFacts, loginRefresh } from "@parcha/agentrun-harness-claude/facts";
20
+ import { registerSecretPage, registerSecretWrite } from "./secret-writes.js";
21
+ import { copyEnv } from "./secrets.js";
21
22
  // Every operation here is the owner's session's alone (secret-writes.ts): no answer holds a credential, but turning a
22
23
  // person's plan on for this server's runs, and starting its sign-in, are the owner's to do.
23
- for (const operation of ["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin"])
24
+ for (const operation of ["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin", "signOutClaudeLogin"])
24
25
  registerSecretWrite(operation, () => true);
26
+ registerSecretPage("signOutClaudeLogin", "/#/settings/keys");
25
27
  /** The switch: `off` (or 0, false, no) turns the mode off on this server, `on` (or 1, true, yes) leaves it there past
26
28
  * loopback; unset, the listen address decides (claudeLoginSwitchedOff). */
27
29
  export const CLAUDE_LOGIN_ENV = "AGENTRUN_CLAUDE_CODE_LOGIN";
@@ -435,15 +437,17 @@ export function loginRefused(place, env, uid = process.geteuid?.()) {
435
437
  * runs on a copy of the account file (the harness's claudeLoginStatus). Every login carries the person's home as
436
438
  * `userHome`, read here once (homeOf), so the status check, the sign-in and a run on macOS all run in that one home
437
439
  * whatever reads it later (the harness's personHome), and `homeApart` where the env's HOME was not that home (homeOf's
438
- * `apart`). The home and the folders the env gives are the real paths the walk ended in. */
440
+ * `apart`). AgentRun's carries `own`. The home and the folders the env gives are the real paths the walk ended in. */
439
441
  export function loginAt(place, data, env = process.env, uid = process.geteuid?.()) {
440
442
  const checked = homeOf(env, uid);
441
443
  if (checked.refused !== undefined)
442
444
  return { refused: checked.refused };
443
445
  const { home, apart } = checked;
444
446
  const homeAt = { userHome: home, ...(apart ? { homeApart: true } : {}) };
447
+ // `own`: no CLI of the person's uses AgentRun's folder, so the harness may delete the Keychain item a sign-in left
448
+ // there under "unknown" (its dropUnknownItem).
445
449
  if (place === "agentrun")
446
- return { login: { dir: agentRunLoginDir(data), profiles: join(agentRunLoginDir(data), "anthropic"), ...homeAt }, toMake: [] };
450
+ return { login: { dir: agentRunLoginDir(data), profiles: join(agentRunLoginDir(data), "anthropic"), ...homeAt, own: true }, toMake: [] };
447
451
  const real = new Map();
448
452
  const toMake = [];
449
453
  for (const [name, folder] of envFolders(env)) {
@@ -497,11 +501,12 @@ export function withClaudeLogin(env, login) {
497
501
  return env;
498
502
  }
499
503
  /** `env` as a run at `place` reads it: a runner place keeps the login; any other place (a sandbox) gets a copy without it,
500
- * so a revision's checks there ask for a key, as its run will. */
504
+ * so a revision's checks there ask for a key, as its run will. The copy is copyEnv's, which keeps withSecrets' keys
505
+ * (read by name, never enumerated), where a spread would keep none. */
501
506
  export function envAtPlace(env, place) {
502
507
  if (place?.mode === "runner" || env[LOGIN] === undefined)
503
508
  return env;
504
- return withClaudeLogin({ ...env }, undefined);
509
+ return withClaudeLogin(copyEnv(env), undefined);
505
510
  }
506
511
  /** The login `env` carries, unless the switch is off. */
507
512
  export function claudeLoginOf(env) {
@@ -589,7 +594,7 @@ export async function loginForRun(settings, data, env, harness, place, uid = pro
589
594
  return loginOf(await claudeLoginSetting(settings), data, env, uid);
590
595
  }
591
596
  /** The routes here (server.ts): every one answers 404, by its name, while the mode is off (`why`). */
592
- export const CLAUDE_LOGIN_ROUTES = new Set(["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin"]);
597
+ export const CLAUDE_LOGIN_ROUTES = new Set(["getClaudeLogin", "turnOnClaudeLogin", "turnOffClaudeLogin", "startClaudeLogin", "signOutClaudeLogin"]);
593
598
  /** Whether the claude-login routes answer here, the one rule the routes and capabilities' `features.claude_login` both
594
599
  * read: none while the mode is switched off (`off`, claudeLoginSwitchedOff's reason), and none on an API-only server
595
600
  * (`apiOnly`), whose route list holds none of them, so it refuses them before routing (server.ts). */
@@ -668,6 +673,20 @@ export async function claudeLoginView(deps) {
668
673
  return { state: "unknown", ...base };
669
674
  }
670
675
  }
676
+ /** What AgentRun's own login folder (`<data>/claude-login`) leads to where it is a link (the link's text); else
677
+ * undefined, a folder or nothing there. */
678
+ function loginFolderLink(data) {
679
+ const dir = agentRunLoginDir(data);
680
+ try {
681
+ return lstatSync(dir, { throwIfNoEntry: false })?.isSymbolicLink() ? readlinkSync(dir) : undefined;
682
+ }
683
+ catch {
684
+ return undefined;
685
+ }
686
+ }
687
+ /** Why a turn-on is refused where AgentRun's own login folder (`dir`) is a link (to `to`). A sign-out removes that folder
688
+ * whole, so it is one AgentRun keeps itself, and no link leads a sign-out into a folder elsewhere. */
689
+ export const loginFolderIsLink = (dir, to) => `AgentRun's own Claude login folder ${dir} is a link (to ${to}). AgentRun keeps its login in a folder of its own, which a sign-out removes whole, so it never follows a link there: remove the link, then turn it on again.`;
671
690
  /** PUT /settings/claude-login: turned on, refused in one line where more than one person can start runs. A turn-on that
672
691
  * moves the login to another place first ends a sign-in this server started that still waits: its CLI signs in at the
673
692
  * old place, which the login no longer reads. One at the same place leaves it waiting, as it still signs in there. */
@@ -703,6 +722,9 @@ export async function turnOnClaudeLogin(deps, body) {
703
722
  const at = loginAt(asked.place, deps.data, deps.env, deps.uid);
704
723
  if (at.refused !== undefined)
705
724
  throw new ClaudeLoginRefused("forbidden", at.refused);
725
+ const linked = asked.place === "agentrun" ? loginFolderLink(deps.data) : undefined;
726
+ if (linked !== undefined)
727
+ throw new ClaudeLoginRefused("forbidden", loginFolderIsLink(agentRunLoginDir(deps.data), linked));
706
728
  // Its folders still to make are made here (madeLogin), so a sign-in from the line shown finds them made 0700.
707
729
  const login = madeLogin(at, asked.place, deps);
708
730
  const setting = settingFor(asked.place, deps.data);
@@ -724,6 +746,114 @@ export async function turnOffClaudeLogin(deps) {
724
746
  await deps.changed();
725
747
  return claudeLoginView(deps);
726
748
  }
749
+ /** What may remain where the CLI didn't confirm its own sign-out (`why`, the CLI's step as it went). */
750
+ const keychainMayRemain = (why) => `${why}, so on macOS its Keychain item for this login may remain: remove it in Keychain Access (its name starts with "Claude Code-credentials").`;
751
+ const KEYCHAIN_MAY_REMAIN = keychainMayRemain("Claude Code's own sign-out didn't confirm");
752
+ /** The Keychain's words where the CLI's step threw before the CLI ran (`failed`, the error's words), else where it didn't confirm. */
753
+ const keychainWords = (failed) => failed === undefined ? KEYCHAIN_MAY_REMAIN : keychainMayRemain(`Claude Code's own sign-out could not run (${failed})`);
754
+ /** What a sign-out answers beside `confirmed: false`: the login is gone here, and the CLI said nothing of its own copy. */
755
+ export const LOGIN_SIGN_OUT_UNCONFIRMED = `Signed out here: AgentRun's copy of the login is removed. ${KEYCHAIN_MAY_REMAIN}`;
756
+ /** What a sign-out answers beside `confirmed: false` where the CLI's step threw (`failed`, the error's words): the login is
757
+ * gone here all the same, and the CLI's own copy may remain. */
758
+ export const signOutCliFailed = (failed) => `Signed out here: AgentRun's copy of the login is removed. ${keychainWords(failed)}`;
759
+ /** What a sign-out answers beside `confirmed: false` where some of the login is still there (`left`: each thing, its path
760
+ * and why), and the Keychain's words too where the CLI didn't confirm its own sign-out (`keychain`), naming the CLI
761
+ * step's failure where it threw (`failed`). */
762
+ export const signOutLeft = (left, keychain, failed) => `Signed out here, and the mode is off, but some of AgentRun's copy of the login remains: ${left.join("; ")}. Remove it by hand before turning the mode on again.${keychain ? ` ${keychainWords(failed)}` : ""}`;
763
+ /** Why a sign-out of this machine's own login (`folder`, the person's `~/.claude` or CLAUDE_CONFIG_DIR) is refused. */
764
+ export const machineSignOutRefused = (folder) => `This is your own Claude Code login on this machine (${folder}), which AgentRun only uses: it never signs it out. Run \`claude auth logout\` in a terminal there to sign it out, or turn the mode off here.`;
765
+ /** POST /settings/claude-login/sign-out: AgentRun's own login (`<data>/claude-login`) signed out and removed, so the next
766
+ * turn-on finds none and the person signs in fresh, to the same account or another. In one turn on the sign-ins' queue
767
+ * (no sign-in or turn-on lands in between): a sign-in this server started that still waits is ended; the mode is turned
768
+ * off, so no new run goes on the login while it goes; the pinned CLI's own sign-out (the harness's claudeLogout) runs on
769
+ * the folder, so it removes its credentials file and, on macOS, the Keychain item named from the folder. It runs where
770
+ * the folder is gone too: a retry after a sign-out the CLI didn't confirm finds no folder, and the Keychain item may
771
+ * remain, so the answer is confirmed only where the CLI confirms. Then the folder is removed whatever the CLI said (a
772
+ * folder the CLI made as it signed out too) (credentials, account, profiles, the CLI's refresh lock, and
773
+ * the CLI's older lock beside it), with the login's signed-in note (noteAnswer) and this process's token reader of it
774
+ * (claude-login-token.ts forgetLoginTokens). Each removal stands alone: one that fails is named in the answer
775
+ * (signOutLeft, `confirmed` false), and the others, the reader's drop and the server's reread of the keys still happen.
776
+ * So with the CLI's step: a throw finding the CLI or loading the harness is named in the answer (signOutCliFailed), and
777
+ * every removal still runs.
778
+ * Where the folder is a link (put there after the turn-on, which refuses one), the link alone is removed, with the
779
+ * login's signed-in note: no CLI runs through it, nothing it leads to is touched, and the answer names it. Runs already going are left as a turn-off
780
+ * leaves them: each keeps the token its CLI holds, and fails in
781
+ * LOGIN_SIGNED_OUT's words at its next read of the login; one claimed on it and started while the mode is off is refused
782
+ * at its start (claude-login-token.ts LOGIN_CHANGED_SINCE_CLAIM). That check is of the folder, not the account, so one
783
+ * started after a turn-on and a new sign-in runs on that sign-in. A run whose CLI reads the folder itself (in the
784
+ * runner's process) holds the refresh token and may write a renewed pair back after the folder goes; nothing here
785
+ * removes it again. A login on this machine's own folder (`machine`) is the person's:
786
+ * refused (machineSignOutRefused), with nothing touched. */
787
+ export async function signOutClaudeLogin(deps) {
788
+ let off = false;
789
+ let signedOut = true;
790
+ let cliFailed;
791
+ const left = [];
792
+ const remove = (what, path, options) => {
793
+ try {
794
+ rmSync(path, options);
795
+ }
796
+ catch (error) {
797
+ left.push(`${what} ${path} (${error.code ?? String(error)})`);
798
+ }
799
+ };
800
+ try {
801
+ await deps.signIns.serial(async (turn) => {
802
+ if ((await claudeLoginSetting(deps.settings))?.place === "machine")
803
+ throw new ClaudeLoginRefused("forbidden", machineSignOutRefused(machineFolder(deps.env, deps.uid).folder));
804
+ await turn.stop();
805
+ await deps.settings.remove(CLAUDE_LOGIN_SETTING);
806
+ deps.saved(undefined);
807
+ off = true;
808
+ const dir = agentRunLoginDir(deps.data);
809
+ const linked = loginFolderLink(deps.data);
810
+ const note = answerFile(deps.data, { dir, profiles: join(dir, "anthropic") });
811
+ try {
812
+ if (linked !== undefined) {
813
+ // A link put there after the turn-on (which refuses one, loginFolderIsLink): the link alone goes, no CLI runs
814
+ // through it, and nothing it leads to is touched. The login's signed-in note, in the data folder, goes too.
815
+ signedOut = false;
816
+ remove("the link", dir, { force: true });
817
+ remove("the login's signed-in note", note, { force: true });
818
+ left.push(`${linked}, where the link ${dir} led, left as it was`);
819
+ return;
820
+ }
821
+ // The CLI's step in its own try: a throw finding the CLI or loading the harness skips no removal below, and the
822
+ // answer names it.
823
+ try {
824
+ const { login } = loginAt("agentrun", deps.data, deps.env, deps.uid);
825
+ const cli = loginCli(await deps.pinned(), deps.env);
826
+ signedOut = login && cli ? await (await deps.claude()).claudeLogout(cli, login, pathOf(deps.env)) : false;
827
+ }
828
+ catch (error) {
829
+ signedOut = false;
830
+ cliFailed = error instanceof Error ? error.message : String(error);
831
+ }
832
+ // The older lock sits beside the folder in the data folder's real path. The folder's own real path is never
833
+ // followed: a link swapped in during the CLI's await would lead the lock's removal outside the data folder.
834
+ let beside = dir;
835
+ try {
836
+ beside = join(realpathSync(dirname(dir)), basename(dir));
837
+ }
838
+ catch {
839
+ // The folder as named.
840
+ }
841
+ remove("the login's folder", dir, { recursive: true, force: true });
842
+ remove("the CLI's older lock", `${beside}${loginRefresh.legacyLockSuffix}`, { recursive: true, force: true });
843
+ remove("the login's signed-in note", note, { force: true });
844
+ }
845
+ finally {
846
+ (await import("./claude-login-token.js")).forgetLoginTokens(dir);
847
+ }
848
+ });
849
+ }
850
+ finally {
851
+ if (off)
852
+ await deps.changed();
853
+ }
854
+ const message = left.length > 0 ? signOutLeft(left, !signedOut, cliFailed) : signedOut ? undefined : cliFailed !== undefined ? signOutCliFailed(cliFailed) : LOGIN_SIGN_OUT_UNCONFIRMED;
855
+ return { confirmed: message === undefined, ...(message ? { message } : {}), login: await claudeLoginView(deps) };
856
+ }
727
857
  /** POST /settings/claude-login/login: the CLI's own sign-in, started on this machine, where it opens a browser, with the
728
858
  * shown line's own variables (the harness's signInEnv), so it signs in where the status reads. A sign-in that
729
859
  * still waits is ended first (deps.signIns). The browser code goes to the CLI, never here; the answer is the view as it
@@ -32,7 +32,7 @@ export class CliLearningConnections {
32
32
  const native = await launchNative({ ...target, connected: true });
33
33
  const id = createHash('sha256').update(`${target.runtime}\0${target.machine_id}\0${target.project}`).digest('hex').slice(0, 32);
34
34
  const agentId = `cli-${id}`;
35
- // Agent creation is deterministic. Concurrent enrollments keep the winner's revision and learning folder.
35
+ // Agent creation is deterministic. Concurrent enrollments keep the winner's revision and learning.
36
36
  if (!await getAgent(this.store, agentId))
37
37
  try {
38
38
  await createAgent(this.store, { definition: { id: agentId, name: typeof body.name === 'string' ? body.name : `${basename(target.project)} (${target.runtime})`, instructions: '', tools: [], learning: true, cli_learning: { runtime: target.runtime, connection_id: id, project: target.project } } });
package/dist/cli.js CHANGED
@@ -32,7 +32,7 @@ installEnvProxy();
32
32
  const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--faux-github] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--no-runner] [--harness-module MODULE ...] [--harness-recipe FILE ...] [--harness-sign-in]
33
33
  agentrun-serve reset-password [--data DIR]
34
34
  agentrun-serve validate-template DIR
35
- agentrun-serve install-harness goose|cursor [--data DIR]
35
+ agentrun-serve install-harness goose|cursor|antigravity [--data DIR]
36
36
  agentrun-serve install-harness --recipe FILE [--data DIR]
37
37
  agentrun-serve sign-in-harness --recipe FILE [--data DIR]
38
38
  agentrun-serve check-harness --recipe FILE [--model PROVIDER/MODEL] [--data DIR] [--report FILE] [--cap USD]
@@ -84,7 +84,8 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
84
84
  separated), installed into DIR with agentrun harness install --recipe FILE. Its harness runs once a
85
85
  harness-check of it passed on DIR, through this server's model proxy (a plan-billed one's keys are
86
86
  not saved on a server yet); a recipe the loader refuses, or whose id another harness has, refuses
87
- the start
87
+ the start. FILE may be the name of a recipe AgentRun ships (antigravity), unless a file of that
88
+ name is in this directory (./NAME names the file)
88
89
  --harness-sign-in run a person's runs of a plan-billed recipe with a sign-in on your own sign-in (agentrun harness
89
90
  sign-in), never a schedule's or a trigger's. One owner's own machine alone: the start is refused
90
91
  unless the server listens on loopback with no public address, keeps its store in DIR (no
@@ -238,21 +239,26 @@ if (process.argv[2] === "install-harness") {
238
239
  }
239
240
  };
240
241
  const { values, positionals } = read();
242
+ if (values.recipe !== undefined && positionals.length)
243
+ usage("it takes a harness's name or --recipe FILE, not both.");
244
+ // A recipe AgentRun ships (the ACP package's: Google Antigravity's), by its name, is installed as its file is.
245
+ const { acpPackage: shipping } = await import("./acp-package.js");
246
+ const shipped = positionals.length === 1 ? shipping()?.bundledRecipePath?.(positionals[0]) : undefined;
241
247
  // A recipe's harness (harness-recipe.ts): the recipe loaded under its five rules first, so a refused one downloads
242
- // nothing; then its release for this platform, as the Goose install does it.
243
- if (values.recipe !== undefined) {
244
- if (positionals.length)
245
- usage("it takes a harness's name or --recipe FILE, not both.");
246
- const [{ ArchiveInstallFailed }, { installRecipe, loadRecipe, recipeCheckLine, RecipeRefused }] = await Promise.all([import("./harness-archive.js"), import("./harness-recipe.js")]);
248
+ // nothing; then its release for this platform, as the Goose install does it. Which recipe resolved is said first.
249
+ if (values.recipe !== undefined || shipped) {
250
+ const [{ ArchiveInstallFailed }, { installRecipe, loadRecipe, recipeCheckLine, RecipeRefused, recipeSaid }] = await Promise.all([import("./harness-archive.js"), import("./harness-recipe.js")]);
247
251
  const data = resolve(values.data ?? defaultData());
248
252
  try {
249
- const { recipe, file } = loadRecipe(values.recipe);
253
+ // A shipped recipe by the name given, never by its path: a file of that name in the directory refuses it (resolveRecipe).
254
+ const { recipe, file, bundled } = loadRecipe(shipped ? positionals[0] : values.recipe);
255
+ console.error(recipeSaid(recipe.label, file, bundled));
250
256
  const said = { downloaded: "the archive is downloaded and its sha256 matches the recipe", unpacked: "unpacked", verified: "its files are checked" };
251
257
  const { version, installed, binary, pinnedBy } = await installRecipe(recipe, file, data, { onStep: (step) => console.error(`${recipe.label}: ${said[step]}`) });
252
258
  const held = { recipe: "the recipe's tree pin", "first-seen": "the tree an earlier install recorded", recorded: "their tree recorded now, as the first one; a later binary or file beside it that differs is refused" }[pinnedBy];
253
259
  console.log(installed === "already"
254
260
  ? `${recipe.label} ${version} is installed in ${dirname(binary)} (already: the pinned files are there, so nothing was downloaded; held to ${held}).`
255
- : `${recipe.label} ${version} is installed in ${dirname(binary)} (now; the binary and every file beside it held to ${held}). Check it with: ${recipeCheckLine(file, data)} --model PROVIDER/MODEL`);
261
+ : `${recipe.label} ${version} is installed in ${dirname(binary)} (now; the binary and every file beside it held to ${held}). Check it with: ${recipeCheckLine(file, data)}${recipe.model.billing === "proxy" ? " --model PROVIDER/MODEL" : ""}`);
256
262
  process.exit(0);
257
263
  }
258
264
  catch (error) {
@@ -264,7 +270,7 @@ if (process.argv[2] === "install-harness") {
264
270
  }
265
271
  // The owner-installed harnesses (harness-owned.ts), each one's id, label, install and what its install checks.
266
272
  const installers = await Promise.all([import("./harness-goose.js").then((m) => m.GOOSE), import("./harness-cursor.js").then((m) => m.CURSOR)]);
267
- const names = installers.map((each) => each.id).join(" or ");
273
+ const names = [...installers.map((each) => each.id), ...(shipping()?.BUNDLED_RECIPES ?? [])].join(" or ");
268
274
  if (positionals.length !== 1)
269
275
  usage(`it takes one harness: ${names}.`);
270
276
  const chosen = installers.find((each) => each.id === positionals[0]);
@@ -610,6 +616,32 @@ else {
610
616
  console.error(`agentrun-serve: ${error.message}`);
611
617
  process.exit(2);
612
618
  }
619
+ // Which recipe each --harness-recipe NAME resolved to, said before the start: one AgentRun ships (resolveRecipe), and a
620
+ // name a file here also holds refuses the start, saying both.
621
+ if (harnessRecipesOf(values["harness-recipe"], process.env).length) {
622
+ const { loadRecipe, RecipeRefused, recipeSaid, resolveRecipe } = await import("./harness-recipe.js");
623
+ for (const given of harnessRecipesOf(values["harness-recipe"], process.env)) {
624
+ let resolved;
625
+ try {
626
+ resolved = resolveRecipe(given);
627
+ }
628
+ catch (error) {
629
+ if (!(error instanceof RecipeRefused))
630
+ throw error;
631
+ console.error(`agentrun-serve: --harness-recipe ${given}: ${error.message}`);
632
+ process.exit(2);
633
+ }
634
+ // A refused recipe's words are the start's own, as for a file (the harness table loads each).
635
+ if (resolved.bundled) {
636
+ let label = given;
637
+ try {
638
+ label = loadRecipe(resolved.file).recipe.label;
639
+ }
640
+ catch { }
641
+ console.error(recipeSaid(label, resolved.file, true));
642
+ }
643
+ }
644
+ }
613
645
  const accounts = !apiOnly && process.env.AGENTRUN_ACCOUNTS !== "0";
614
646
  // The address first (listen-first.ts): the port bound and named before the rest of the server loads, then answering that
615
647
  // the server is warming until it takes the socket over. A port already taken is left to the start's own listen below,
@@ -1,4 +1,4 @@
1
- import{d as It,D as Yn}from"./index-LwNL4L9q.js";import{az as bt}from"./styles-CaRKlHke.js";const we=t=>({type:"boolean",description:t}),Yt={type:"object",required:["name","pageCount","pages","text"],properties:{name:{type:"string"},pageCount:{type:"integer"},pages:{type:"array"},text:{type:"string"}}},Jn={type:"object",required:["status","text"],properties:{status:{type:"integer"},url:{type:"string"},title:{type:"string"},text:{type:"string"}}},vt={type:"object"},Ke={type:"object",additionalProperties:!1,required:["altered","seal","signature","legible"],properties:{altered:we("Does the page show signs of digital alteration: mismatched fonts, misaligned lines, pasted regions or an edited date?"),seal:we("Is a state seal or a filing stamp visible on the page?"),signature:we("Is the certificate signed by a state official?"),legible:we("Is the entity's full legal name legible on the page?")}},mt={v:2,name:"coi-batch-review",schemas:{Input:{type:"object",required:["documents"],properties:{documents:{type:"array",items:{type:"string"},minItems:1,maxItems:50}}},DocChecks:Ke,Pages:Yt,Report:vt},input:{schemaId:"Input"},output:{schemaId:"Report",path:"report"},root:{node:"chain",steps:[{node:"map",label:"each-document",itemsPath:"documents",as:"rows",maxConcurrency:4,onItemFailure:"collect",failedAs:"failed",body:{node:"chain",steps:[{node:"call",label:"render-pages",via:"tool",tool:"pdf_pages",args:{path:"{item}",maxPages:2},out:"Pages",as:"pages",deadline_s:60},{node:"judge",label:"inspect-certificate",provider:"jev",state:{document:"{item}",page:"<page1>",text:"{pages.text}"},images:{"<page1>":"{pages.pages.0.image}"},out:"DocChecks",as:"checks"},{node:"code",label:"grade",code:"(s) => ({ document: s.item, verdict: s.checks.altered || !s.checks.seal || !s.checks.legible ? 'doubtful' : 'valid', checks: s.checks })",as:"row"}]}},{node:"code",label:"batch-report",code:"(s) => ({ valid: s.rows.filter((r) => r && r.verdict === 'valid').length, doubtful: s.rows.filter((r) => r && r.verdict === 'doubtful').map((r) => r.document), failed: s.failed })",as:"report"}]}},xe={v:2,name:"kyb-onboarding",schemas:{Pages:Yt,Result:vt,Input:{type:"object",required:["company","state","registration_number","documents"],properties:{company:{type:"string"},state:{type:"string"},registration_number:{type:"string"},documents:{type:"array",items:{type:"string"}}}},Registry:{type:"object",additionalProperties:!1,required:["registered","active","name_matches"],properties:{registered:we("Is a company with this exact registration number on file with the named state's business registry?"),active:we("Is that registration currently active (in good standing, not dissolved, forfeited or revoked)?"),name_matches:we("Does the registry's legal name match the applicant's name, ignoring punctuation and suffix style?")}},CertLook:{type:"object",additionalProperties:!1,required:["altered","seal","legible"],properties:{altered:Ke.properties.altered,seal:Ke.properties.seal,legible:Ke.properties.legible}},CrossCheck:{type:"object",additionalProperties:!1,required:["same_entity","same_state","dates_consistent"],properties:{same_entity:we("Do the registry record and the certificate name the same legal entity?"),same_state:we("Do they name the same state of incorporation?"),dates_consistent:we("Is the certificate's filing date consistent with the registry's formation date (within 3 days)?")}}},input:{schemaId:"Input"},root:{node:"chain",steps:[{node:"call",label:"render-certificate",via:"tool",tool:"pdf_pages",args:{path:"{documents.0}",maxPages:1},out:"Pages",as:"cert",deadline_s:60},{node:"parallel",label:"checks",branches:[{node:"judge",label:"registry-lookup",provider:"parallel",model:"standard",state:{company:"{company}",state:"{state}",registration_number:"{registration_number}"},out:"Registry",as:"registry"},{node:"judge",label:"certificate-look",provider:"jev",state:{page:"<cert>",text:"{cert.text}"},images:{"<cert>":"{cert.pages.0.image}"},out:"CertLook",as:"look"}]},{node:"judge",label:"cross-check",provider:"jev",state:{applicant:{company:"{company}",state:"{state}"},registry:"{registry$answers}",certificate_text:"{cert.text}"},out:"CrossCheck",as:"cross"},{node:"route",label:"decide",provider:"jev",state:{registry:"{registry}",look:"{look}",cross:"{cross}"},instructions:"Decide the onboarding outcome for this business from the registry check, the certificate's look and the cross-check.",branches:{approve:{criteria:"Registered, active, the certificate looks genuine, and every cross-check agrees.",body:{node:"code",label:"record-approval",code:"(s) => ({ outcome: 'approved' })",as:"outcome"}},review:{criteria:"Mostly consistent, but one check is doubtful or the evidence disagrees on a detail.",body:{node:"code",label:"open-review-case",code:"(s) => ({ outcome: 'review', reasons: s.cross })",as:"outcome"}},reject:{criteria:"Not registered, dissolved, or the certificate is altered.",body:{node:"code",label:"record-rejection",code:"(s) => ({ outcome: 'rejected' })",as:"outcome"}}},unsure:{branch:"review",gte:.75}}]},output:{schemaId:"Result",path:"outcome"}},Vn={type:"object",additionalProperties:!1,required:["prohibited"],properties:{prohibited:we("Does this merchant sell goods the card networks prohibit: weapons, controlled substances, counterfeit goods, or unlicensed nicotine products?")}},Ve=(t,s,o)=>({node:"judge",label:t,provider:s,...o?{model:o}:{},state:{merchant:"{merchant}",url:"{url}",page_text:"{page.text}"},out:"Prohibited",as:t.replace(/-/g,"_")}),Ze={v:2,name:"prohibited-goods-jury",schemas:{Page:Jn,Result:vt,Input:{type:"object",required:["merchant","url"],properties:{merchant:{type:"string"},url:{type:"string"}}},Prohibited:Vn},input:{schemaId:"Input"},root:{node:"chain",steps:[{node:"call",label:"fetch-storefront",via:"tool",tool:"web_fetch",args:{url:"{url}"},out:"Page",as:"page",deadline_s:30},{node:"parallel",label:"jury",branches:[Ve("jev","jev"),Ve("pplx-decider","openrouter","perplexity/pplx-decider-v1.2"),Ve("liquid-d1","openrouter","liquid/d1"),Ve("clef","openrouter","cloudflare/clef")]},{node:"code",label:"aggregate",code:"(s) => { const p = [s.jev$answers, s.pplx_decider$answers, s.liquid_d1$answers, s.clef$answers].map((a) => a.answers.prohibited.noul); const mean = p.reduce((x, y) => x + y, 0) / p.length; const spread = Math.max(...p) - Math.min(...p); return { mean, spread, outcome: spread > 0.3 ? 'disagree' : 'agree' }; }",as:"agreement"},{node:"route",label:"agreement",valuePath:"agreement.outcome",branches:{agree:{body:{node:"code",label:"auto-decide",code:"(s) => ({ decision: s.agreement.mean >= 0.5 ? 'decline' : 'approve' })",as:"decision"}},disagree:{body:{node:"code",label:"human-review",code:"(s) => ({ decision: 'review', spread: s.agreement.spread })",as:"decision"}}}}]},output:{schemaId:"Result",path:"decision"}},re=6e4,le=60*re,W=24*le,se={default:"anthropic/claude-sonnet-5-5",fast:"openai/gpt-6-luna",strong:"anthropic/claude-opus-5-5",codex:"openai/gpt-6.1-sol"},Qn={v:2,name:"ticket-triage",schemas:{Ticket:{type:"object",required:["subject","body"],properties:{subject:{type:"string"},body:{type:"string"}}},Triage:{type:"object",required:["queue","urgency"],properties:{queue:{type:"string"},urgency:{type:"integer"}}}},input:{schemaId:"Ticket"},output:{schemaId:"Triage",path:"triage"},root:{node:"chain",steps:[{node:"call",label:"read the playbook",tool:"read",args:{path:"playbooks/triage.md"},as:"playbook"},{node:"pick",label:"which queue",from:"playbook.queues",instructions:"Which queue does this ticket belong to, by what the buyer or seller asks for?",as:"queue",none:"hand back"},{node:"code",label:"score the urgency",as:"triage"}]}},Zn=`# ticket-triage
1
+ import{d as It,D as Yn}from"./index-BnZV3lvW.js";import{az as bt}from"./styles-D_znYrHR.js";const we=t=>({type:"boolean",description:t}),Yt={type:"object",required:["name","pageCount","pages","text"],properties:{name:{type:"string"},pageCount:{type:"integer"},pages:{type:"array"},text:{type:"string"}}},Jn={type:"object",required:["status","text"],properties:{status:{type:"integer"},url:{type:"string"},title:{type:"string"},text:{type:"string"}}},vt={type:"object"},Ke={type:"object",additionalProperties:!1,required:["altered","seal","signature","legible"],properties:{altered:we("Does the page show signs of digital alteration: mismatched fonts, misaligned lines, pasted regions or an edited date?"),seal:we("Is a state seal or a filing stamp visible on the page?"),signature:we("Is the certificate signed by a state official?"),legible:we("Is the entity's full legal name legible on the page?")}},mt={v:2,name:"coi-batch-review",schemas:{Input:{type:"object",required:["documents"],properties:{documents:{type:"array",items:{type:"string"},minItems:1,maxItems:50}}},DocChecks:Ke,Pages:Yt,Report:vt},input:{schemaId:"Input"},output:{schemaId:"Report",path:"report"},root:{node:"chain",steps:[{node:"map",label:"each-document",itemsPath:"documents",as:"rows",maxConcurrency:4,onItemFailure:"collect",failedAs:"failed",body:{node:"chain",steps:[{node:"call",label:"render-pages",via:"tool",tool:"pdf_pages",args:{path:"{item}",maxPages:2},out:"Pages",as:"pages",deadline_s:60},{node:"judge",label:"inspect-certificate",provider:"jev",state:{document:"{item}",page:"<page1>",text:"{pages.text}"},images:{"<page1>":"{pages.pages.0.image}"},out:"DocChecks",as:"checks"},{node:"code",label:"grade",code:"(s) => ({ document: s.item, verdict: s.checks.altered || !s.checks.seal || !s.checks.legible ? 'doubtful' : 'valid', checks: s.checks })",as:"row"}]}},{node:"code",label:"batch-report",code:"(s) => ({ valid: s.rows.filter((r) => r && r.verdict === 'valid').length, doubtful: s.rows.filter((r) => r && r.verdict === 'doubtful').map((r) => r.document), failed: s.failed })",as:"report"}]}},xe={v:2,name:"kyb-onboarding",schemas:{Pages:Yt,Result:vt,Input:{type:"object",required:["company","state","registration_number","documents"],properties:{company:{type:"string"},state:{type:"string"},registration_number:{type:"string"},documents:{type:"array",items:{type:"string"}}}},Registry:{type:"object",additionalProperties:!1,required:["registered","active","name_matches"],properties:{registered:we("Is a company with this exact registration number on file with the named state's business registry?"),active:we("Is that registration currently active (in good standing, not dissolved, forfeited or revoked)?"),name_matches:we("Does the registry's legal name match the applicant's name, ignoring punctuation and suffix style?")}},CertLook:{type:"object",additionalProperties:!1,required:["altered","seal","legible"],properties:{altered:Ke.properties.altered,seal:Ke.properties.seal,legible:Ke.properties.legible}},CrossCheck:{type:"object",additionalProperties:!1,required:["same_entity","same_state","dates_consistent"],properties:{same_entity:we("Do the registry record and the certificate name the same legal entity?"),same_state:we("Do they name the same state of incorporation?"),dates_consistent:we("Is the certificate's filing date consistent with the registry's formation date (within 3 days)?")}}},input:{schemaId:"Input"},root:{node:"chain",steps:[{node:"call",label:"render-certificate",via:"tool",tool:"pdf_pages",args:{path:"{documents.0}",maxPages:1},out:"Pages",as:"cert",deadline_s:60},{node:"parallel",label:"checks",branches:[{node:"judge",label:"registry-lookup",provider:"parallel",model:"standard",state:{company:"{company}",state:"{state}",registration_number:"{registration_number}"},out:"Registry",as:"registry"},{node:"judge",label:"certificate-look",provider:"jev",state:{page:"<cert>",text:"{cert.text}"},images:{"<cert>":"{cert.pages.0.image}"},out:"CertLook",as:"look"}]},{node:"judge",label:"cross-check",provider:"jev",state:{applicant:{company:"{company}",state:"{state}"},registry:"{registry$answers}",certificate_text:"{cert.text}"},out:"CrossCheck",as:"cross"},{node:"route",label:"decide",provider:"jev",state:{registry:"{registry}",look:"{look}",cross:"{cross}"},instructions:"Decide the onboarding outcome for this business from the registry check, the certificate's look and the cross-check.",branches:{approve:{criteria:"Registered, active, the certificate looks genuine, and every cross-check agrees.",body:{node:"code",label:"record-approval",code:"(s) => ({ outcome: 'approved' })",as:"outcome"}},review:{criteria:"Mostly consistent, but one check is doubtful or the evidence disagrees on a detail.",body:{node:"code",label:"open-review-case",code:"(s) => ({ outcome: 'review', reasons: s.cross })",as:"outcome"}},reject:{criteria:"Not registered, dissolved, or the certificate is altered.",body:{node:"code",label:"record-rejection",code:"(s) => ({ outcome: 'rejected' })",as:"outcome"}}},unsure:{branch:"review",gte:.75}}]},output:{schemaId:"Result",path:"outcome"}},Vn={type:"object",additionalProperties:!1,required:["prohibited"],properties:{prohibited:we("Does this merchant sell goods the card networks prohibit: weapons, controlled substances, counterfeit goods, or unlicensed nicotine products?")}},Ve=(t,s,o)=>({node:"judge",label:t,provider:s,...o?{model:o}:{},state:{merchant:"{merchant}",url:"{url}",page_text:"{page.text}"},out:"Prohibited",as:t.replace(/-/g,"_")}),Ze={v:2,name:"prohibited-goods-jury",schemas:{Page:Jn,Result:vt,Input:{type:"object",required:["merchant","url"],properties:{merchant:{type:"string"},url:{type:"string"}}},Prohibited:Vn},input:{schemaId:"Input"},root:{node:"chain",steps:[{node:"call",label:"fetch-storefront",via:"tool",tool:"web_fetch",args:{url:"{url}"},out:"Page",as:"page",deadline_s:30},{node:"parallel",label:"jury",branches:[Ve("jev","jev"),Ve("pplx-decider","openrouter","perplexity/pplx-decider-v1.2"),Ve("liquid-d1","openrouter","liquid/d1"),Ve("clef","openrouter","cloudflare/clef")]},{node:"code",label:"aggregate",code:"(s) => { const p = [s.jev$answers, s.pplx_decider$answers, s.liquid_d1$answers, s.clef$answers].map((a) => a.answers.prohibited.noul); const mean = p.reduce((x, y) => x + y, 0) / p.length; const spread = Math.max(...p) - Math.min(...p); return { mean, spread, outcome: spread > 0.3 ? 'disagree' : 'agree' }; }",as:"agreement"},{node:"route",label:"agreement",valuePath:"agreement.outcome",branches:{agree:{body:{node:"code",label:"auto-decide",code:"(s) => ({ decision: s.agreement.mean >= 0.5 ? 'decline' : 'approve' })",as:"decision"}},disagree:{body:{node:"code",label:"human-review",code:"(s) => ({ decision: 'review', spread: s.agreement.spread })",as:"decision"}}}}]},output:{schemaId:"Result",path:"decision"}},re=6e4,le=60*re,W=24*le,se={default:"anthropic/claude-sonnet-5-5",fast:"openai/gpt-6-luna",strong:"anthropic/claude-opus-5-5",codex:"openai/gpt-6.1-sol"},Qn={v:2,name:"ticket-triage",schemas:{Ticket:{type:"object",required:["subject","body"],properties:{subject:{type:"string"},body:{type:"string"}}},Triage:{type:"object",required:["queue","urgency"],properties:{queue:{type:"string"},urgency:{type:"integer"}}}},input:{schemaId:"Ticket"},output:{schemaId:"Triage",path:"triage"},root:{node:"chain",steps:[{node:"call",label:"read the playbook",tool:"read",args:{path:"playbooks/triage.md"},as:"playbook"},{node:"pick",label:"which queue",from:"playbook.queues",instructions:"Which queue does this ticket belong to, by what the buyer or seller asks for?",as:"queue",none:"hand back"},{node:"code",label:"score the urgency",as:"triage"}]}},Zn=`# ticket-triage
2
2
 
3
3
  Files a ticket under its queue (billing, shipping, account, merchant, abuse) and scores its urgency from the playbook: a chargeback, a locked account or a safety problem is 4 or more.
4
4