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

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 (194) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +188 -106
  3. package/dist/agent-delete.d.ts +6 -9
  4. package/dist/agent-delete.js +5 -3
  5. package/dist/agent-package.js +11 -1
  6. package/dist/api-only.d.ts +2 -2
  7. package/dist/api-only.js +3 -3
  8. package/dist/archil-routes.d.ts +4 -1
  9. package/dist/archil-routes.js +15 -12
  10. package/dist/archil-settings.d.ts +18 -8
  11. package/dist/archil-settings.js +35 -17
  12. package/dist/chatgpt-plan.d.ts +4 -2
  13. package/dist/chatgpt-plan.js +13 -3
  14. package/dist/claude-login-token.d.ts +5 -0
  15. package/dist/claude-login-token.js +8 -0
  16. package/dist/claude-login.d.ts +49 -3
  17. package/dist/claude-login.js +140 -10
  18. package/dist/cli-learning/connections.js +1 -1
  19. package/dist/console/assets/{backend-BztxEAvb.js → backend-QnwGVBeU.js} +1 -1
  20. package/dist/console/assets/index-DZi-muIj.js +629 -0
  21. package/dist/console/assets/{share-L84tlUDW.js → share-pz61zIn9.js} +2 -2
  22. package/dist/console/assets/{styles-CaRKlHke.js → styles-CcceGcu2.js} +31 -31
  23. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  24. package/dist/console/index.html +3 -3
  25. package/dist/console/share.html +3 -3
  26. package/dist/decisions.d.ts +1 -1
  27. package/dist/decisions.js +2 -2
  28. package/dist/factory-activity.d.ts +68 -0
  29. package/dist/factory-activity.js +153 -0
  30. package/dist/factory-runs.d.ts +11 -0
  31. package/dist/factory-runs.js +52 -0
  32. package/dist/filed-tool.d.ts +32 -0
  33. package/dist/filed-tool.js +122 -0
  34. package/dist/harness-keys.d.ts +1 -2
  35. package/dist/harness-keys.js +1 -2
  36. package/dist/harness-table.d.ts +4 -0
  37. package/dist/harness-table.js +4 -0
  38. package/dist/harness.js +6 -2
  39. package/dist/import-worker.js +2 -2
  40. package/dist/import.d.ts +9 -0
  41. package/dist/import.js +11 -1
  42. package/dist/key-refusal.d.ts +5 -0
  43. package/dist/key-refusal.js +25 -15
  44. package/dist/learn/audit.d.ts +20 -22
  45. package/dist/learn/audit.js +72 -55
  46. package/dist/learn/check.js +1 -1
  47. package/dist/learn/commit.d.ts +35 -43
  48. package/dist/learn/commit.js +62 -270
  49. package/dist/learn/compile.d.ts +4 -4
  50. package/dist/learn/compile.js +6 -7
  51. package/dist/learn/corrections.js +1 -1
  52. package/dist/learn/delete.d.ts +5 -12
  53. package/dist/learn/delete.js +17 -30
  54. package/dist/learn/forget-run.d.ts +16 -0
  55. package/dist/learn/forget-run.js +53 -0
  56. package/dist/learn/index.js +1 -1
  57. package/dist/learn/learning-of.d.ts +0 -4
  58. package/dist/learn/learning-of.js +0 -5
  59. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  60. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  61. package/dist/learn/legacy/place.d.ts +16 -0
  62. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  63. package/dist/learn/legacy/scrub.d.ts +28 -0
  64. package/dist/learn/legacy/scrub.js +258 -0
  65. package/dist/learn/promote.d.ts +40 -66
  66. package/dist/learn/promote.js +69 -207
  67. package/dist/learn/reset-ledger.d.ts +18 -0
  68. package/dist/learn/reset-ledger.js +14 -0
  69. package/dist/learn/rows.d.ts +186 -0
  70. package/dist/learn/rows.js +376 -0
  71. package/dist/learn/workflow-draft.d.ts +4 -1
  72. package/dist/learn/workflow-draft.js +12 -2
  73. package/dist/learning-reset.d.ts +1 -1
  74. package/dist/learning-reset.js +9 -11
  75. package/dist/learning-routes.d.ts +60 -81
  76. package/dist/learning-routes.js +187 -360
  77. package/dist/learning-words.d.ts +2 -0
  78. package/dist/learning-words.js +2 -0
  79. package/dist/learning.d.ts +18 -24
  80. package/dist/learning.js +35 -66
  81. package/dist/mcp-gateway.d.ts +6 -0
  82. package/dist/mcp-gateway.js +44 -8
  83. package/dist/mcp-resources.d.ts +1 -1
  84. package/dist/native/discovery.d.ts +6 -0
  85. package/dist/native/discovery.js +14 -1
  86. package/dist/native/remote.d.ts +5 -0
  87. package/dist/native/remote.js +16 -0
  88. package/dist/native/runtime.js +3 -2
  89. package/dist/observation/observer.d.ts +6 -6
  90. package/dist/openapi.js +89 -29
  91. package/dist/place-offers.d.ts +3 -0
  92. package/dist/place-offers.js +3 -0
  93. package/dist/place.d.ts +33 -11
  94. package/dist/place.js +61 -26
  95. package/dist/purged-workflow.d.ts +0 -33
  96. package/dist/purged-workflow.js +3 -71
  97. package/dist/redact/match.d.ts +19 -4
  98. package/dist/redact/match.js +123 -30
  99. package/dist/run-launch.d.ts +3 -3
  100. package/dist/run-learning-served.d.ts +3 -3
  101. package/dist/run-learning-served.js +1 -1
  102. package/dist/run-listing.d.ts +1 -1
  103. package/dist/run-timeline-served.d.ts +1 -1
  104. package/dist/run-timeline-served.js +6 -5
  105. package/dist/runnable.js +25 -8
  106. package/dist/runner/adapter-run-spec.js +11 -20
  107. package/dist/runner/audit.d.ts +2 -4
  108. package/dist/runner/audit.js +28 -51
  109. package/dist/runner/cli-run-spec.js +8 -14
  110. package/dist/runner/compare-end.d.ts +0 -2
  111. package/dist/runner/compare-end.js +6 -2
  112. package/dist/runner/disk-free.d.ts +15 -4
  113. package/dist/runner/disk-free.js +25 -7
  114. package/dist/runner/feedback-round.d.ts +1 -1
  115. package/dist/runner/feedback-round.js +2 -2
  116. package/dist/runner/harness-loops.js +2 -3
  117. package/dist/runner/held.d.ts +0 -10
  118. package/dist/runner/held.js +0 -25
  119. package/dist/runner/journal-kinds.d.ts +4 -1
  120. package/dist/runner/journal-kinds.js +1 -1
  121. package/dist/runner/learned-first.d.ts +0 -2
  122. package/dist/runner/learned-first.js +3 -3
  123. package/dist/runner/learning-end.d.ts +12 -16
  124. package/dist/runner/learning-end.js +41 -75
  125. package/dist/runner/learning-seed.d.ts +13 -16
  126. package/dist/runner/learning-seed.js +13 -23
  127. package/dist/runner/main.js +1 -1
  128. package/dist/runner/mcp-run.d.ts +4 -0
  129. package/dist/runner/mcp-run.js +2 -0
  130. package/dist/runner/native-loop.js +2 -3
  131. package/dist/runner/promotion.d.ts +19 -28
  132. package/dist/runner/promotion.js +50 -69
  133. package/dist/runner/reflect-hook.d.ts +2 -2
  134. package/dist/runner/reflect-hook.js +4 -1
  135. package/dist/runner/run-child-host.d.ts +1 -9
  136. package/dist/runner/run-child-host.js +11 -67
  137. package/dist/runner/runner.d.ts +1 -1
  138. package/dist/runner/sdk-loop.js +2 -4
  139. package/dist/sdk/check.d.ts +1 -4
  140. package/dist/sdk/check.js +2 -3
  141. package/dist/sdk/runs.d.ts +20 -7
  142. package/dist/sdk/runs.js +105 -68
  143. package/dist/secrets.d.ts +4 -0
  144. package/dist/secrets.js +44 -10
  145. package/dist/server-fs.d.ts +1 -1
  146. package/dist/server-fs.js +1 -1
  147. package/dist/server-keys.d.ts +6 -0
  148. package/dist/server-keys.js +12 -0
  149. package/dist/server.d.ts +15 -15
  150. package/dist/server.js +214 -164
  151. package/dist/source-sync/auxiliary.js +2 -2
  152. package/dist/store/index.d.ts +1 -1
  153. package/dist/store/index.js +1 -1
  154. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  155. package/dist/store/schema.d.ts +28 -2
  156. package/dist/store/schema.js +81 -5
  157. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  158. package/dist/store/sqlite/learning-rows.js +559 -0
  159. package/dist/store/sqlite/store.d.ts +7 -1
  160. package/dist/store/sqlite/store.js +84 -18
  161. package/dist/store/store.d.ts +219 -6
  162. package/dist/store/store.js +13 -0
  163. package/dist/store-reads/journal.d.ts +33 -3
  164. package/dist/store-reads/journal.js +99 -4
  165. package/dist/store-reads/learning.d.ts +18 -22
  166. package/dist/store-reads/learning.js +35 -26
  167. package/dist/store-reads/loop.js +1 -1
  168. package/dist/store-view.d.ts +24 -2
  169. package/dist/store-view.js +40 -11
  170. package/dist/templates.d.ts +10 -2
  171. package/dist/templates.js +31 -4
  172. package/dist/tool-plane.d.ts +4 -2
  173. package/dist/tool-plane.js +9 -2
  174. package/dist/web-holds.d.ts +2 -0
  175. package/dist/web-holds.js +5 -2
  176. package/dist/web-run.js +2 -1
  177. package/dist/workspace/archil-exec.js +1 -1
  178. package/dist/workspace/archil.d.ts +1 -1
  179. package/dist/workspace/archil.js +1 -1
  180. package/dist/workspace/computer-deps.js +5 -3
  181. package/dist/workspace/computer-providers.d.ts +11 -1
  182. package/dist/workspace/computer-providers.js +29 -2
  183. package/dist/workspace/index.d.ts +1 -2
  184. package/dist/workspace/index.js +1 -2
  185. package/dist/workspace/paths.d.ts +0 -4
  186. package/dist/workspace/paths.js +0 -6
  187. package/dist/workspace/workspace.d.ts +1 -1
  188. package/dist/workspace/workspace.js +1 -1
  189. package/package.json +13 -13
  190. package/templates/TOOLS.md +46 -0
  191. package/dist/console/assets/index-LwNL4L9q.js +0 -619
  192. package/dist/console/assets/styles-DQo8rzY-.css +0 -1
  193. package/dist/workspace/learning-workspace.d.ts +0 -24
  194. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
@@ -1,13 +1,10 @@
1
1
  import { type PurgeKept, type Store } from "./store/index.js";
2
- /** The delete of an agent's learning: the server's is the learning module's deleteLearning over the agent's learning
3
- * folder, and its folder on each Archil disk a launch of its runs named, a purged run's included (learn/delete.ts;
4
- * server.ts learningDisksOf), and its records. Idempotent; refuses with LearningInFlight while learning work of the
5
- * agent is in flight. A reset of the agent's learning (learning-reset.ts), whose agent and runs stay, keeps its reset
6
- * ledger and watermark (`keepResetLedger`) and deletes the folder on the agent's own disk too (`agentDisk`), which the
7
- * agent's delete removes whole in its step 3. */
2
+ /** The delete of an agent's learning: the server's is the learning module's deleteLearning over the store's learning
3
+ * rows (learn/delete.ts). Idempotent; refuses with LearningInFlight while learning work of the agent is in flight. A
4
+ * reset of the agent's learning (learning-reset.ts), whose agent and runs stay, keeps its reset ledger and watermark
5
+ * (`keepResetLedger`). */
8
6
  export type DeleteLearning = (store: Store, agentId: string, options?: {
9
7
  keepResetLedger?: boolean;
10
- agentDisk?: boolean;
11
8
  }) => Promise<unknown>;
12
9
  /** A point of a delete a test may stop it at (AgentDeleteHost.at). An agent's: after step 1, after step 2, in step 3
13
10
  * between a trigger's removal upstream and its settings', between its settings' and its row's, and in step 3 once its
@@ -50,8 +47,8 @@ export interface AgentDeleteHost {
50
47
  madeFrom(runId: string): Promise<string[]>;
51
48
  /** What agent `agentId`'s learning copied from run `runId`, gone: the grades it keeps of the run dropped, its promotion
52
49
  * records' disagreements naming the run blanked, their decisions, numbers and run ids kept (learn/promote.ts
53
- * forgetRunCopies), and the run's text off its learning folder's current files (learn/commit.ts forgetRunText).
54
- * Idempotent: a purged run's DELETE runs it again. */
50
+ * forgetRunCopies), and every SDK run's inbox that holds its workflow text emptied of it (sdk/runs.ts forgetSdkCopies).
51
+ * Idempotent: run before the run's purge and again after it commits, and a purged run's DELETE runs it again. */
55
52
  forgetCopies(agentId: string, runId: string): Promise<void>;
56
53
  /** What run `runId`'s spend reads from its journal, read before its purge removes it (store-reads/cap.ts). */
57
54
  kept(runId: string): Promise<PurgeKept>;
@@ -7,9 +7,8 @@
7
7
  // finish; a DELETE of a purged run is 204 again. A live run (not final, or held by a runner) refuses its purge with 409
8
8
  // run_not_final and nothing purged. The runs made from a run are purged before it: one a claim made after the DELETE read
9
9
  // them is found by the store's purge under the run's row lock (RunsMadeFromLeft, 409 naming it), and one made once the run
10
- // is purged is refused at its create (RunPurged). A run's purge takes its text off its agent's learning folder's current
11
- // files (its merges' diff files and feedback lines, forgetCopies) and the folder's history reads serve none of its
12
- // merges, while the folder's git keeps their bytes until a learning reset or the agent's purge deletes it.
10
+ // is purged is refused at its create (RunPurged). A run's purge deletes its agent's learning rows that hold its text (the
11
+ // store's purge, Store.learning purgeRun) and blanks what its agent's records copied from it (forgetCopies).
13
12
  //
14
13
  // Another system's agent is first marked refusing new runs (its archive time, set with its triggers off in one commit, read
15
14
  // by every path that would start a run), then its runs are cancelled and waited for, then its learning goes, then its
@@ -117,6 +116,9 @@ export async function purgeRun(host, runId) {
117
116
  await host.at?.("run_made_from_gone", runId);
118
117
  await host.forgetCopies(run.agentId, runId);
119
118
  await purgeOneOrRefuse(host, run.agentId, runId, runId, true);
119
+ // Again after the purge committed: a copy written meanwhile (an SDK start's inbox, which checks its writers after it is
120
+ // written) is seen by this pass, or saw the purge itself.
121
+ await host.forgetCopies(run.agentId, runId);
120
122
  }
121
123
  /** The one per-run step of both purges: the figures its spend's readers read from its journal, its things outside its
122
124
  * rows, then its rows (a tombstone). Its store's refusal of a run gone live again since it was read (a follow-up opened
@@ -15,6 +15,7 @@ import { toolOf } from "./tools.js";
15
15
  import { configSecrets, SEALED_FIELD, SEALED_MASK } from "./trigger-composio.js";
16
16
  import { CATCHUP_WINDOW_S } from "./triggers.js";
17
17
  import { isObject, MODEL_TIER_NAMES, stable } from "./validate.js";
18
+ import { fileIssues } from "./filed-tool.js";
18
19
  import { PAIRED_ID_PREFIX } from "./workspace/attached-computers.js";
19
20
  /** What an export's note can be about: the document's enum of them (openapi.ts), so a note of a kind not here fails the
20
21
  * build, and an answer the document does not list fails its schema check. */
@@ -145,9 +146,16 @@ export function agentPackage(input) {
145
146
  if (!clear.length)
146
147
  pin[tool] = held;
147
148
  }
149
+ // A file setting travels as it is: a folder of the run's files and the paths the tool's result shows, never a value.
150
+ const file = {};
151
+ for (const tool of granted) {
152
+ const held = settings[mcpToolName(server, tool)]?.file;
153
+ if (held !== undefined && !fileIssues(held, `file.${tool}`).length)
154
+ file[tool] = held;
155
+ }
148
156
  const reason = origin?.mcp.find((need) => need.source === saved.source.source && need.toolkit === toolkit)?.reason;
149
157
  // Required where a composio trigger runs on it (as a package's composio trigger must); else skipped where none matches.
150
- mcp.push({ source: saved.source.source, toolkit, tools: granted, ...(composioServers.has(server) ? { required: true } : {}), ...(reason ? { reason } : {}), ...(Object.keys(pin).length ? { pin } : {}) });
158
+ mcp.push({ source: saved.source.source, toolkit, tools: granted, ...(composioServers.has(server) ? { required: true } : {}), ...(reason ? { reason } : {}), ...(Object.keys(pin).length ? { pin } : {}), ...(Object.keys(file).length ? { file } : {}) });
151
159
  }
152
160
  // What the tool settings hold beyond a pin of a granted MCP tool and bash's policy is this server's.
153
161
  for (const [tool, setting] of Object.entries(settings)) {
@@ -161,6 +169,8 @@ export function agentPackage(input) {
161
169
  else
162
170
  blocked.push({ kind: "tool_setting", name: tool, reason: "Its arguments are pinned, and a package pins MCP tools alone: without the pin the agent would get more than it has here." });
163
171
  }
172
+ if (setting.file !== undefined && !ofNeed)
173
+ remade.push({ kind: "tool_setting", name: tool, reason: "Its answers are filed (a file setting) on a tool the agent is not granted: set it again on the target if the tool is granted there." });
164
174
  if (setting.permission === "allow")
165
175
  remade.push({ kind: "tool_setting", name: tool, reason: "It runs without asking here: allow it again on the target." });
166
176
  const own = ["provider", "scope"].filter((key) => setting[key] !== undefined);
@@ -7,8 +7,8 @@ import type { Route } from "./server.js";
7
7
  * of an agent made here is purged too (deleteRun): the token may archive and delete that whole agent below, every
8
8
  * run of it purged, so one run of it is no more;
9
9
  * - a run's computer, take-over, hand-back and viewer link go to the backend, which has no owner's session here;
10
- * - a backend reads what its agents learned (loop, promotions, cost per run, a run's learning), cut as the console's,
11
- * and resets it (deleteAgentLearning: the agent and its runs kept) when it erases what an agent learned;
10
+ * - a backend reads what its agents learned (loop, promotions, audits, cost per run, a run's learning), cut as the
11
+ * console's, and resets it (deleteAgentLearning: the agent and its runs kept) when it erases what an agent learned;
12
12
  * - a run's usage lines (what its cost.usd joins, by meter) are a read of that run alone, cut as the run's read is;
13
13
  * - an operator or a scaler reads the runners' capacity (getCapacity, capacity.ts) from the server whose runners run apart;
14
14
  * - a backend reads the saved MCP servers' names (listMcpServerNames), never a URL or a credential;
package/dist/api-only.js CHANGED
@@ -14,8 +14,8 @@ import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-ho
14
14
  * of an agent made here is purged too (deleteRun): the token may archive and delete that whole agent below, every
15
15
  * run of it purged, so one run of it is no more;
16
16
  * - a run's computer, take-over, hand-back and viewer link go to the backend, which has no owner's session here;
17
- * - a backend reads what its agents learned (loop, promotions, cost per run, a run's learning), cut as the console's,
18
- * and resets it (deleteAgentLearning: the agent and its runs kept) when it erases what an agent learned;
17
+ * - a backend reads what its agents learned (loop, promotions, audits, cost per run, a run's learning), cut as the
18
+ * console's, and resets it (deleteAgentLearning: the agent and its runs kept) when it erases what an agent learned;
19
19
  * - a run's usage lines (what its cost.usd joins, by meter) are a read of that run alone, cut as the run's read is;
20
20
  * - an operator or a scaler reads the runners' capacity (getCapacity, capacity.ts) from the server whose runners run apart;
21
21
  * - a backend reads the saved MCP servers' names (listMcpServerNames), never a URL or a credential;
@@ -44,7 +44,7 @@ export const API_ONLY_ROUTES = new Set([
44
44
  "getRunComputer", "takeOverRunComputer", "handBackRunComputer", "createRunComputerViewer",
45
45
  "listComputers", "listRunningComputers", "getWorkspaceArchil",
46
46
  "getAgentArchil", "deleteAgentArchil", "deleteAgent", "deleteAgentLearning", "deleteRun",
47
- "getLearningLoop", "listLearningPromotions", "getLearningCost", "getRunLearning",
47
+ "getLearningLoop", "listLearningPromotions", "listLearningAudits", "getLearningCost", "getRunLearning",
48
48
  "getRun", "getRunUsage", "listRuns", "listAllRuns", "getTimeline",
49
49
  "sendMessage", "stopRun", "cancelRun", "raiseRunCap", "gradeRun",
50
50
  "listRunFiles", "readRunFile",
@@ -6,13 +6,16 @@ export declare const ARCHIL_ROUTES: ReadonlySet<string>;
6
6
  /** The key names the Archil settings take, as the document names them. */
7
7
  export declare const ARCHIL_KEY_NAMES: readonly string[];
8
8
  /** The Archil settings as the owner reads them, with `source` while on (the server's environment, or saved through the
9
- * PUT, "console"): the account key as `secret`, its SecretMeta, never a value. */
9
+ * PUT, "console") and `s3UrlFrom` (the region's own S3 URL, or one given): the account key as `secret`, its SecretMeta,
10
+ * never a value. `regions`: each region serve knows, with its S3 URL, which a PUT naming it may leave out. */
10
11
  export type ArchilView = {
11
12
  on: boolean;
12
13
  source?: "env" | "console";
13
14
  region?: string;
14
15
  s3Url?: string;
16
+ s3UrlFrom?: "region" | "given";
15
17
  image?: string;
18
+ regions: Readonly<Record<string, string>>;
16
19
  secret: KeyMeta;
17
20
  };
18
21
  export type ArchilTest = {
@@ -3,11 +3,13 @@
3
3
  // disk: each agent has its own, made on its first run that needs one (workspace/run-disk.ts), and a run's launch may
4
4
  // name another. The one kept credential is the account key, sealed under the claim's row name ("archil.api_key"). No
5
5
  // disk token is kept: a computer's mount credential is minted per run from the account key.
6
- // GET /v2/workspace/archil on or off, the settings and where from (the server's environment, else saved), and
6
+ // GET /v2/workspace/archil on or off, the settings and where from (the server's environment, else saved), the
7
+ // S3 URL's (the region's, or given), each region serve knows with its S3 URL, and
7
8
  // the account key as the shared secret shape: set or not, where from, when changed
8
9
  // (never a value)
9
10
  // PUT /v2/workspace/archil the settings row replaced, and the account key sealed when given (null removes it);
10
- // the exec image, when given, pinned by digest
11
+ // the S3 URL, left out, the region's (one serve knows); the exec image, when given,
12
+ // pinned by digest
11
13
  // DELETE /v2/workspace/archil off (the settings row removed; the key is kept, for turning it on again)
12
14
  // POST /v2/workspace/archil/test one listing of the account's disks at the region's control plane, with the
13
15
  // account key opened as a claim opens it: { ok, detail } or { ok: false, why }
@@ -20,7 +22,7 @@
20
22
  // key_set_by_server: they are changed where the server is started, as a tool key its launcher sets is, never saved here
21
23
  // to no effect.
22
24
  // archilRoute holds the routes' rules, so serve's dispatch only calls it and sends the answer, or the ApiError's status.
23
- import { agentDiskOf, ARCHIL_API_KEY_ROW, ARCHIL_SETTINGS_ENV, archilSettingsFromEnv, archilSettingsIssues, archilSettingsOf, clearArchilSettings, forgetAgentDisk, loadArchilSettings, saveArchilSettings, storeAgentDisk } from "./archil-settings.js";
25
+ import { agentDiskOf, ARCHIL_API_KEY_ROW, ARCHIL_S3_URLS, ARCHIL_SETTINGS_ENV, archilSettingsFromEnv, archilSettingsIssues, archilSettingsOf, clearArchilSettings, forgetAgentDisk, loadArchilSettings, s3UrlFromOf, saveArchilSettings, storeAgentDisk } from "./archil-settings.js";
24
26
  import { ApiError, invalid } from "./errors.js";
25
27
  import { envValue, keyMetaOf } from "./key-meta.js";
26
28
  import { registerNotSecretWrite, registerSecretPage, registerSecretWrite, secretName } from "./secret-writes.js";
@@ -67,7 +69,7 @@ export async function liveRunsOnDisk(runs, agentId, diskId) {
67
69
  }
68
70
  return count;
69
71
  }
70
- const OFF = `Archil is off on this server: save its region, S3 URL and account key (PUT /v2/workspace/archil), or start the server with ${ARCHIL_SETTINGS_ENV.region}, ${ARCHIL_SETTINGS_ENV.s3Url} and ARCHIL_API_KEY`;
72
+ const OFF = `Archil is off on this server: save its region and account key (PUT /v2/workspace/archil), or start the server with ${ARCHIL_SETTINGS_ENV.region} and ARCHIL_API_KEY; a region serve doesn't know needs its S3 URL too (s3Url, ${ARCHIL_SETTINGS_ENV.s3Url})`;
71
73
  const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
72
74
  const describe = (error) => String(error?.message ?? error).replace(/\s+/g, " ").slice(0, 300);
73
75
  const statusOf = (error) => {
@@ -81,8 +83,8 @@ export function createArchilRoutes(options) {
81
83
  const removals = new Map();
82
84
  async function view() {
83
85
  const settings = await loadArchilSettings(store, env);
84
- const shown = settings === undefined ? {} : { source: archilSettingsFromEnv(env) ? "env" : "console", region: settings.region, s3Url: settings.s3Url, ...(settings.image !== undefined ? { image: settings.image } : {}) };
85
- return { on: settings !== undefined, ...shown, secret: (await keyMetaOf(store, [SECRET], env))[0] };
86
+ const shown = settings === undefined ? {} : { source: archilSettingsFromEnv(env) ? "env" : "console", region: settings.region, s3Url: settings.s3Url, s3UrlFrom: s3UrlFromOf(settings), ...(settings.image !== undefined ? { image: settings.image } : {}) };
87
+ return { on: settings !== undefined, ...shown, regions: ARCHIL_S3_URLS, secret: (await keyMetaOf(store, [SECRET], env))[0] };
86
88
  }
87
89
  /** A change refused while the server's environment sets the settings: nothing saved would take effect. */
88
90
  function refuseWhileEnv() {
@@ -95,7 +97,7 @@ export function createArchilRoutes(options) {
95
97
  async function save(body) {
96
98
  refuseWhileEnv();
97
99
  if (typeof body !== "object" || body === null || Array.isArray(body))
98
- throw new ApiError("input_invalid", "the body is a JSON object: { region, s3Url, image?, keys? }");
100
+ throw new ApiError("input_invalid", "the body is a JSON object: { region, s3Url?, image?, keys? }");
99
101
  const given = body;
100
102
  const issues = unknownFields(given, ["region", "s3Url", "image", "keys"]).map((issue) => issue.field === "diskId" ? { ...issue, message: "There is no server-wide disk: each agent has its own, made on its first run, and a run may name another (archil_disk on its start)." } : issue);
101
103
  issues.push(...archilSettingsIssues(given));
@@ -286,11 +288,12 @@ export function createArchilRoutes(options) {
286
288
  }
287
289
  }
288
290
  /** Agent `agentId`'s learning folder on disk `diskId` deleted over the disk's file API: agents/<agent>/learning and
289
- * everything under it (paths.ts learningKey), which a Mode 2 run's end writes on the disk its claim mounted, the
290
- * agent's own or one its launch named (the caller's: never made, renamed or removed here), and the folder a learning
291
- * exec spills beside it (workspace/archil.ts spillFolderOf: a write's input text, left by a failed cleanup). Nothing
292
- * else on the disk is touched: the agent's runs' folders stay. Done again, it does nothing: a folder not there is gone, and so is the
293
- * folder of a disk Archil says is gone. Archil off, or no account key, is 503 unavailable; a delete Archil refuses
291
+ * everything under it, which a Mode 2 run's end wrote, before learning moved to the store's rows, on the disk its
292
+ * claim mounted, the agent's own or one its launch named (the caller's: never made, renamed or removed here), and the
293
+ * folder a learning exec spilled beside it (workspace/archil.ts spillFolderOf). Nothing reads it any more; a run's
294
+ * purge removes it from a disk the run's launch named, as it did before (server.ts forgetRun). Nothing else on the
295
+ * disk is touched: the agent's runs' folders stay. Done again, it does nothing: a folder not there is gone, and so is
296
+ * the folder of a disk Archil says is gone. Archil off, or no account key, is 503 unavailable; a delete Archil refuses
294
297
  * (a computer that still holds the folder, Archil not reached) is 424 upstream_failed, what was not deleted left for
295
298
  * the next call. */
296
299
  async function removeLearningFolder(agentId, diskId) {
@@ -19,13 +19,19 @@ export declare const DEFAULT_ARCHIL_EXEC_IMAGE = "buildpack-deps@sha256:4f34e1d6
19
19
  export interface ArchilSettings {
20
20
  /** The account key's region: the control plane every disk is made, read and minted on. */
21
21
  readonly region: string;
22
- /** The region's S3 endpoint (the disks' file API). */
22
+ /** The region's S3 endpoint (the disks' file API): the one given, else the region's (regionS3Url). */
23
23
  readonly s3Url: string;
24
24
  /** A pinned image for the disk's exec, when the owner set one; absent, DEFAULT_ARCHIL_EXEC_IMAGE. */
25
25
  readonly image?: string;
26
26
  }
27
+ /** The S3 endpoint of each region serve knows: its control plane's host (ARCHIL_CONTROL_URLS, Archil's SDK's own table)
28
+ * with its leading `control.` made `s3.`, as the SDK derives it (`disk` 1.12.0, src/regions.ts deriveS3BaseUrl). */
29
+ export declare const ARCHIL_S3_URLS: Readonly<Record<string, string>>;
30
+ /** Region `region`'s S3 endpoint, or undefined when serve doesn't know the region. */
31
+ export declare const regionS3Url: (region: string) => string | undefined;
27
32
  /** The environment variable that sets each field, for a server whose operator sets Mode 2 where it is started (a headless
28
- * deploy, where no owner's session can save it). The region and S3 URL are both set or neither; the image is optional. */
33
+ * deploy, where no owner's session can save it). The region is required; the S3 URL only for a region serve doesn't know
34
+ * (regionS3Url), and one given for a known region is used over the region's; the image is optional. */
29
35
  export declare const ARCHIL_SETTINGS_ENV: {
30
36
  readonly region: "AGENTRUN_ARCHIL_REGION";
31
37
  readonly s3Url: "AGENTRUN_ARCHIL_S3_URL";
@@ -36,13 +42,17 @@ export declare class ArchilSettingsEnvInvalid extends Error {
36
42
  readonly name = "ArchilSettingsEnvInvalid";
37
43
  }
38
44
  /** What is wrong with each settings field given, by the one rule the PUT and the environment share: a region, an https
39
- * S3 URL, and an image, when given, pinned by digest. Empty when every field is right. */
45
+ * S3 URL (left out, the region's, for a region serve knows), and an image, when given, pinned by digest. Empty when every
46
+ * field is right. */
40
47
  export declare function archilSettingsIssues(given: Readonly<Record<string, unknown>>): InputIssue[];
41
- /** The settings of fields archilSettingsIssues found right. */
42
- export declare const archilSettingsOf: (given: Readonly<Record<string, unknown>>) => ArchilSettings;
43
- /** The Archil settings the server's environment sets, or undefined when it sets none of ARCHIL_SETTINGS_ENV. One required
44
- * variable without the other, or a value the PUT would refuse, is ArchilSettingsEnvInvalid naming each variable, never a
45
- * half-configured Mode 2. The environment is passed in: process.env is never read here. */
48
+ /** The settings of fields archilSettingsIssues found right: an S3 URL left out is the region's. */
49
+ export declare function archilSettingsOf(given: Readonly<Record<string, unknown>>): ArchilSettings;
50
+ /** Where settings' S3 URL came from: "region" when it is the region's own (regionS3Url), else "given". */
51
+ export declare const s3UrlFromOf: (settings: ArchilSettings) => "region" | "given";
52
+ /** The Archil settings the server's environment sets, or undefined when it sets none of ARCHIL_SETTINGS_ENV. A variable
53
+ * set without the region, or a value the PUT would refuse (no S3 URL for a region serve doesn't know), is
54
+ * ArchilSettingsEnvInvalid naming each variable, never a half-configured Mode 2. The environment is passed in:
55
+ * process.env is never read here. */
46
56
  export declare function archilSettingsFromEnv(env: KeyEnv): ArchilSettings | undefined;
47
57
  /** The Archil settings in force, or undefined when there are none (Mode 1): the server's environment's (`env`), else the
48
58
  * row the owner saved. A row that is not the expected shape reads as undefined, never a half-configured Mode 2; a field
@@ -12,6 +12,7 @@
12
12
  import { createHash, randomBytes } from "node:crypto";
13
13
  import { envValue } from "./key-meta.js";
14
14
  import { pinnedImage } from "./workspace/archil-disk.js";
15
+ import { ARCHIL_CONTROL_URLS } from "./workspace/archil-mount-credential.js";
15
16
  /** The settings key the Archil configuration lives under in store.settings. */
16
17
  export const ARCHIL_SETTINGS_KEY = "archil";
17
18
  /** The sealed-key row of the Archil account key (the file API and exec), saved through server-keys.ts. Named *_ROW: a
@@ -27,23 +28,38 @@ export const ARCHIL_API_KEY_ROW = "archil.api_key";
27
28
  * registry-1.docker.io/v2/library/buildpack-deps/manifests/trixie-scm accepting an OCI index: its
28
29
  * `docker-content-digest`), check the git its layers hold, and put it here. An image the owner saved replaces it. */
29
30
  export const DEFAULT_ARCHIL_EXEC_IMAGE = "buildpack-deps@sha256:4f34e1d673fdb65371de9f88bdd32c4e30152fe692b35604aef5c0b3c0e6da10";
31
+ /** The S3 endpoint of each region serve knows: its control plane's host (ARCHIL_CONTROL_URLS, Archil's SDK's own table)
32
+ * with its leading `control.` made `s3.`, as the SDK derives it (`disk` 1.12.0, src/regions.ts deriveS3BaseUrl). */
33
+ export const ARCHIL_S3_URLS = Object.freeze(Object.fromEntries(Object.entries(ARCHIL_CONTROL_URLS).map(([region, control]) => [region, control.replace(/^https:\/\/control\./, "https://s3.")])));
34
+ /** Region `region`'s S3 endpoint, or undefined when serve doesn't know the region. */
35
+ export const regionS3Url = (region) => (Object.hasOwn(ARCHIL_S3_URLS, region) ? ARCHIL_S3_URLS[region] : undefined);
36
+ /** The known regions, as a refusal names them: "a, b and c". */
37
+ const KNOWN_REGIONS = Object.keys(ARCHIL_S3_URLS).join(", ").replace(/, ([^,]+)$/, " and $1");
30
38
  /** The environment variable that sets each field, for a server whose operator sets Mode 2 where it is started (a headless
31
- * deploy, where no owner's session can save it). The region and S3 URL are both set or neither; the image is optional. */
39
+ * deploy, where no owner's session can save it). The region is required; the S3 URL only for a region serve doesn't know
40
+ * (regionS3Url), and one given for a known region is used over the region's; the image is optional. */
32
41
  export const ARCHIL_SETTINGS_ENV = { region: "AGENTRUN_ARCHIL_REGION", s3Url: "AGENTRUN_ARCHIL_S3_URL", image: "AGENTRUN_ARCHIL_IMAGE" };
33
- const REQUIRED = ["region", "s3Url"];
34
42
  /** The Archil settings in the server's environment are not whole or not right: the start stops, in these words. */
35
43
  export class ArchilSettingsEnvInvalid extends Error {
36
44
  name = "ArchilSettingsEnvInvalid";
37
45
  }
38
46
  const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
39
47
  /** What is wrong with each settings field given, by the one rule the PUT and the environment share: a region, an https
40
- * S3 URL, and an image, when given, pinned by digest. Empty when every field is right. */
48
+ * S3 URL (left out, the region's, for a region serve knows), and an image, when given, pinned by digest. Empty when every
49
+ * field is right. */
41
50
  export function archilSettingsIssues(given) {
42
51
  const issues = [];
43
- if (!nonEmpty(given.region))
52
+ const region = nonEmpty(given.region) ? given.region.trim() : undefined;
53
+ if (region === undefined)
44
54
  issues.push({ field: "region", reason: "required", message: "region is the account key's Archil region, a non-empty string" });
45
- if (!nonEmpty(given.s3Url) || !URL.canParse(given.s3Url) || new URL(given.s3Url).protocol !== "https:")
46
- issues.push({ field: "s3Url", reason: "invalid", message: "s3Url is the region's S3 endpoint, an https URL" });
55
+ const known = region === undefined ? undefined : regionS3Url(region);
56
+ if (given.s3Url === undefined) {
57
+ if (region !== undefined && known === undefined)
58
+ issues.push({ field: "s3Url", reason: "required", message: `s3Url is needed for the region ${region}: serve knows the S3 URL of ${KNOWN_REGIONS} only, so give this region's https S3 URL` });
59
+ }
60
+ else if (!nonEmpty(given.s3Url) || !URL.canParse(given.s3Url) || new URL(given.s3Url).protocol !== "https:") {
61
+ issues.push({ field: "s3Url", reason: "invalid", message: `s3Url is the region's S3 endpoint, an https URL${known === undefined ? "" : `: for ${region} it is ${known}`}` });
62
+ }
47
63
  if (given.image !== undefined) {
48
64
  try {
49
65
  pinnedImage({ baseImage: given.image });
@@ -54,14 +70,17 @@ export function archilSettingsIssues(given) {
54
70
  }
55
71
  return issues;
56
72
  }
57
- /** The settings of fields archilSettingsIssues found right. */
58
- export const archilSettingsOf = (given) => ({
59
- region: given.region.trim(), s3Url: given.s3Url,
60
- ...(given.image !== undefined ? { image: given.image } : {}),
61
- });
62
- /** The Archil settings the server's environment sets, or undefined when it sets none of ARCHIL_SETTINGS_ENV. One required
63
- * variable without the other, or a value the PUT would refuse, is ArchilSettingsEnvInvalid naming each variable, never a
64
- * half-configured Mode 2. The environment is passed in: process.env is never read here. */
73
+ /** The settings of fields archilSettingsIssues found right: an S3 URL left out is the region's. */
74
+ export function archilSettingsOf(given) {
75
+ const region = given.region.trim();
76
+ return { region, s3Url: given.s3Url !== undefined ? given.s3Url : regionS3Url(region), ...(given.image !== undefined ? { image: given.image } : {}) };
77
+ }
78
+ /** Where settings' S3 URL came from: "region" when it is the region's own (regionS3Url), else "given". */
79
+ export const s3UrlFromOf = (settings) => (settings.s3Url === regionS3Url(settings.region) ? "region" : "given");
80
+ /** The Archil settings the server's environment sets, or undefined when it sets none of ARCHIL_SETTINGS_ENV. A variable
81
+ * set without the region, or a value the PUT would refuse (no S3 URL for a region serve doesn't know), is
82
+ * ArchilSettingsEnvInvalid naming each variable, never a half-configured Mode 2. The environment is passed in:
83
+ * process.env is never read here. */
65
84
  export function archilSettingsFromEnv(env) {
66
85
  const given = {};
67
86
  for (const [field, name] of Object.entries(ARCHIL_SETTINGS_ENV)) {
@@ -72,10 +91,9 @@ export function archilSettingsFromEnv(env) {
72
91
  const set = Object.keys(given);
73
92
  if (set.length === 0)
74
93
  return undefined;
75
- const missing = REQUIRED.filter((field) => given[field] === undefined).map((field) => ARCHIL_SETTINGS_ENV[field]);
76
94
  const named = set.map((field) => ARCHIL_SETTINGS_ENV[field]);
77
- if (missing.length)
78
- throw new ArchilSettingsEnvInvalid(`This server is started with ${named.join(", ")} but not ${missing.join(", ")}: set ${REQUIRED.map((field) => ARCHIL_SETTINGS_ENV[field]).join(" and ")} together to keep run folders on Archil (Mode 2), or none of them.`);
95
+ if (given.region === undefined)
96
+ throw new ArchilSettingsEnvInvalid(`This server is started with ${named.join(", ")} but not ${ARCHIL_SETTINGS_ENV.region}: set ${ARCHIL_SETTINGS_ENV.region} (and ${ARCHIL_SETTINGS_ENV.s3Url} for a region other than ${KNOWN_REGIONS}) to keep run folders on Archil (Mode 2), or none of them.`);
79
97
  const issues = archilSettingsIssues(given);
80
98
  if (issues.length)
81
99
  throw new ArchilSettingsEnvInvalid(`This server's Archil settings in its environment are not right: ${issues.map((issue) => issue.message.replace(/^\w+/, ARCHIL_SETTINGS_ENV[issue.field])).join("; ")}.`);
@@ -96,8 +96,10 @@ export declare class ChatGPTPlan implements PlanReader {
96
96
  private read;
97
97
  /** The row as sealed now, opened, with the bytes it was read as (what a compare-and-set on it compares). */
98
98
  private readSealed;
99
- /** The row as sealed now (readSealed), taken as the snapshot unless a write moved the snapshot while the read was out:
100
- * a load or token() that read the row before a sign-in was kept, or before a sign-out removed it, leaves their state. */
99
+ /** The row as sealed now (readSealed), taken as the snapshot unless a write moved the snapshot while the read was out
100
+ * (a load or token() that read the row before a sign-in was kept, or before a sign-out removed it, leaves their state),
101
+ * or a read that started after it was taken first (reads that overlap can answer oldest last: the newest one's row,
102
+ * an expiry another process wrote, stays). */
101
103
  private readTaken;
102
104
  /** `row` as the snapshot, by a write that knows it is the row's latest (a sign-in kept, a renewal, a sign-out). */
103
105
  private wrote;
@@ -182,6 +182,11 @@ export class ChatGPTPlan {
182
182
  /** Moved on by each write of the snapshot (wrote: a sign-in kept, a renewal, an expiry, a sign-out): a read of the row
183
183
  * that was out across one never takes its row over it (readTaken). */
184
184
  #writes = 0;
185
+ /** Moved on by each read of the row as it starts (readTaken). */
186
+ #reads = 0;
187
+ /** The read whose row is the snapshot (its #reads at its start): an older read that answers after it never takes its
188
+ * row over it. */
189
+ #takenRead = 0;
185
190
  #pending;
186
191
  /** An access token OpenAI refused (refused): token() renews rather than send it again. */
187
192
  #refusedAccess;
@@ -251,13 +256,18 @@ export class ChatGPTPlan {
251
256
  const row = this.open(bytes);
252
257
  return row ? { row, bytes } : undefined;
253
258
  }
254
- /** The row as sealed now (readSealed), taken as the snapshot unless a write moved the snapshot while the read was out:
255
- * a load or token() that read the row before a sign-in was kept, or before a sign-out removed it, leaves their state. */
259
+ /** The row as sealed now (readSealed), taken as the snapshot unless a write moved the snapshot while the read was out
260
+ * (a load or token() that read the row before a sign-in was kept, or before a sign-out removed it, leaves their state),
261
+ * or a read that started after it was taken first (reads that overlap can answer oldest last: the newest one's row,
262
+ * an expiry another process wrote, stays). */
256
263
  async readTaken() {
257
264
  const writes = this.#writes;
265
+ const started = ++this.#reads;
258
266
  const read = await this.readSealed();
259
- if (this.#writes === writes)
267
+ if (this.#writes === writes && started > this.#takenRead) {
260
268
  this.#snapshot = read?.row;
269
+ this.#takenRead = started;
270
+ }
261
271
  return read;
262
272
  }
263
273
  /** `row` as the snapshot, by a write that knows it is the row's latest (a sign-in kept, a renewal, a sign-out). */
@@ -96,6 +96,11 @@ type LockIdentity = {
96
96
  * under a user of its own is handed a token of; this machine's own Claude Code login is not. */
97
97
  export declare const agentRunLogin: (login: ClaudeAgentLogin, data: string) => boolean;
98
98
  export declare function loginTokensFor(login: ClaudeAgentLogin, log: (fields: Record<string, string>) => void): LoginTokens;
99
+ /** What this process keeps of the login in folder `dir`, dropped at its sign-out (claude-login.ts signOutClaudeLogin):
100
+ * its reader (with the token Anthropic refused) and a renewed pair still held unsaved, so nothing of the old login is
101
+ * handed or written back over a fresh sign-in. A runner in another process keeps its own until its next read finds
102
+ * the file gone, and then refuses as signed out. */
103
+ export declare function forgetLoginTokens(dir: string): void;
99
104
  /** The words a run's start is refused in by its runner (held.ts claudeLogin) when its claim read Claude Code's login and
100
105
  * the runner's second read of the setting, at the start, names none or another folder: the run is put on no login its
101
106
  * start did not read, and never falls to a model key it was not claimed on. They name no folder. */
@@ -735,6 +735,14 @@ export function loginTokensFor(login, log) {
735
735
  readers.set(login.dir, (reader = new LoginTokens({ login, log })));
736
736
  return reader;
737
737
  }
738
+ /** What this process keeps of the login in folder `dir`, dropped at its sign-out (claude-login.ts signOutClaudeLogin):
739
+ * its reader (with the token Anthropic refused) and a renewed pair still held unsaved, so nothing of the old login is
740
+ * handed or written back over a fresh sign-in. A runner in another process keeps its own until its next read finds
741
+ * the file gone, and then refuses as signed out. */
742
+ export function forgetLoginTokens(dir) {
743
+ readers.delete(dir);
744
+ heldPairs.delete(join(dir, LOGIN_FILE));
745
+ }
738
746
  /** The words a run's start is refused in by its runner (held.ts claudeLogin) when its claim read Claude Code's login and
739
747
  * the runner's second read of the setting, at the start, names none or another folder: the run is put on no login its
740
748
  * start did not read, and never falls to a model key it was not claimed on. They name no folder. */
@@ -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