@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
@@ -49,6 +49,10 @@ export type AcpPackage = {
49
49
  }): AcpRecipe;
50
50
  /** The folder Cursor was installed into, from its launcher's path and the pin's `cmd`; undefined when it is not there. */
51
51
  cursorRootOf(binary: string, cmd: string): string | undefined;
52
+ /** The recipes the package ships whole, by name (Google Antigravity's), and the file of each: absent from a package
53
+ * older than them. */
54
+ readonly BUNDLED_RECIPES?: readonly string[];
55
+ bundledRecipePath?(name: string): string | undefined;
52
56
  /** The form a model id an ACP agent lists takes (Cursor's `gpt-5.4-nano[reasoning=medium]` among them). */
53
57
  readonly MODEL_ID: RegExp;
54
58
  /** The forms a recipe's allowFile may take (`goose-permission`). */
@@ -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);
@@ -1,3 +1,4 @@
1
+ import type { InputIssue } from "./errors.js";
1
2
  import { NOT_SET_UP } from "./runnable.js";
2
3
  import type { Route } from "./server.js";
3
4
  /** The routes (server.ts ROUTES, by name) an API-only server serves. Past a run's own, why each group is here:
@@ -7,8 +8,8 @@ import type { Route } from "./server.js";
7
8
  * of an agent made here is purged too (deleteRun): the token may archive and delete that whole agent below, every
8
9
  * run of it purged, so one run of it is no more;
9
10
  * - 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;
11
+ * - a backend reads what its agents learned (loop, promotions, audits, cost per run, a run's learning), cut as the
12
+ * console's, and resets it (deleteAgentLearning: the agent and its runs kept) when it erases what an agent learned;
12
13
  * - 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
14
  * - an operator or a scaler reads the runners' capacity (getCapacity, capacity.ts) from the server whose runners run apart;
14
15
  * - a backend reads the saved MCP servers' names (listMcpServerNames), never a URL or a credential;
@@ -20,7 +21,12 @@ import type { Route } from "./server.js";
20
21
  * agents and revisions that stay, archives and deletes any agent made here and purges any run of one, as the whole
21
22
  * server's token does, and with the launch hook its apply makes schedule and feed triggers. A trigger the apply can't
22
23
  * make here is skipped, and said (apiOnlyTriggerSkipped). One the agent had before the profile stays as it was:
23
- * without the hook, an enabled one still fires here on this server's keys until the agent is archived;
24
+ * without the hook, an enabled one still fires here on this server's keys until it is turned off (below) or the agent
25
+ * is archived;
26
+ * - a backend reads the triggers (their list, one, its firings) and turns one on or off (updateTrigger, `enabled` alone:
27
+ * apiOnlyTriggerEdit), since a trigger whose firings failed FAILURES_TO_PAUSE times in a row turns itself off and
28
+ * there is no console here to turn it on in. It turns one on under the apply's rule: a schedule or a feed, with the
29
+ * launch hook. Making, deleting, firing a trigger and its secret stay refused;
24
30
  * - an API-only server has no owner, so the token is the backend's own, as with take-over: it saves the Composio servers
25
31
  * its agents need through the preset (saveComposioServer), saves over or deletes only a server it saved
26
32
  * (mcp-secret-writes.ts tokenWriteOverRefused), and never writes a secret (secret-writes.ts). A Composio server names
@@ -49,6 +55,18 @@ export declare function apiOnlyTriggerSkipped(packageName: string, trigger: {
49
55
  reason: typeof NOT_SET_UP | "not_an_option";
50
56
  message: string;
51
57
  } | undefined;
58
+ /** Whether an API-only server turns on a trigger whose source is `kind` and whose target is `target` (its PATCH, its
59
+ * agent's unarchive): only one the apply would make, a source of API_ONLY_HOOKED_KINDS aimed at an agent (start_run),
60
+ * with the launch hook `hooked`, so each firing goes to the backend. A message_run firing never goes to the hook
61
+ * (triggers.ts): on, it would open its run on this server's keys. */
62
+ export declare function apiOnlyTurnsOn(kind: string, target: string, hooked: boolean): boolean;
63
+ /** Why an API-only server refuses `body`, a PATCH of a trigger whose source is `kind` and whose target is `target`, each
64
+ * an issue (none: it goes on to the trigger's own checks). It takes `enabled` alone: a new source or target would let
65
+ * the token aim a trigger at an address or an agent of its own choosing (a feed's urls fetched by this server, a run of
66
+ * another agent), which no route here lets it make, and a name or a cap is the console's to edit. Turned off: always,
67
+ * it stops firings. Turned on: only where the apply would make it (apiOnlyTurnsOn), so its firings go to the backend;
68
+ * any other would start or open runs on this server's keys, or wait on a hook or setting this profile refuses. */
69
+ export declare function apiOnlyTriggerEdit(body: unknown, kind: string, hooked: boolean, target: string): InputIssue[];
52
70
  /** Whether an API-only server saves `body` through the generic save (saveMcpServer) over the name its path gives: a
53
71
  * per_run server (no credential kept) whose url's origin is one of `origins`, under a name that is not a Composio
54
72
  * preset's (`preset`; Composio's own route saves those). Checked before anything reaches the address. A body that
package/dist/api-only.js CHANGED
@@ -2,8 +2,8 @@
2
2
  // deploy's routes alone, and refuses every other address before anything else reads the request: the console at "/" and
3
3
  // its assets, sign-in and setup, settings but the MCP servers' names, a Composio server's save and the delete of a server
4
4
  // (the secret-write gate lets the token save over or delete only a server it saved, mcp-secret-writes.ts), the MCP
5
- // endpoint, triggers and their webhook hooks (all but a firing's release, which the launch hook's host sends), the rest
6
- // of agents and templates. Off by default.
5
+ // endpoint, triggers but their reads, their turn on or off (apiOnlyTriggerEdit) and a firing's release (which the launch
6
+ // hook's host sends), their webhook hooks, the rest of agents and templates. Off by default.
7
7
  import { API_ONLY_ENV } from "./env-switch.js";
8
8
  import { NOT_SET_UP } from "./runnable.js";
9
9
  import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-hook.js";
@@ -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;
@@ -27,7 +27,12 @@ import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-ho
27
27
  * agents and revisions that stay, archives and deletes any agent made here and purges any run of one, as the whole
28
28
  * server's token does, and with the launch hook its apply makes schedule and feed triggers. A trigger the apply can't
29
29
  * make here is skipped, and said (apiOnlyTriggerSkipped). One the agent had before the profile stays as it was:
30
- * without the hook, an enabled one still fires here on this server's keys until the agent is archived;
30
+ * without the hook, an enabled one still fires here on this server's keys until it is turned off (below) or the agent
31
+ * is archived;
32
+ * - a backend reads the triggers (their list, one, its firings) and turns one on or off (updateTrigger, `enabled` alone:
33
+ * apiOnlyTriggerEdit), since a trigger whose firings failed FAILURES_TO_PAUSE times in a row turns itself off and
34
+ * there is no console here to turn it on in. It turns one on under the apply's rule: a schedule or a feed, with the
35
+ * launch hook. Making, deleting, firing a trigger and its secret stay refused;
31
36
  * - an API-only server has no owner, so the token is the backend's own, as with take-over: it saves the Composio servers
32
37
  * its agents need through the preset (saveComposioServer), saves over or deletes only a server it saved
33
38
  * (mcp-secret-writes.ts tokenWriteOverRefused), and never writes a secret (secret-writes.ts). A Composio server names
@@ -44,7 +49,7 @@ export const API_ONLY_ROUTES = new Set([
44
49
  "getRunComputer", "takeOverRunComputer", "handBackRunComputer", "createRunComputerViewer",
45
50
  "listComputers", "listRunningComputers", "getWorkspaceArchil",
46
51
  "getAgentArchil", "deleteAgentArchil", "deleteAgent", "deleteAgentLearning", "deleteRun",
47
- "getLearningLoop", "listLearningPromotions", "getLearningCost", "getRunLearning",
52
+ "getLearningLoop", "listLearningPromotions", "listLearningAudits", "getLearningCost", "getRunLearning",
48
53
  "getRun", "getRunUsage", "listRuns", "listAllRuns", "getTimeline",
49
54
  "sendMessage", "stopRun", "cancelRun", "raiseRunCap", "gradeRun",
50
55
  "listRunFiles", "readRunFile",
@@ -52,6 +57,7 @@ export const API_ONLY_ROUTES = new Set([
52
57
  "getCapabilities", "getHealth", "getUsage", "getCapacity", "listMcpServerNames",
53
58
  "importTemplate", "applyTemplate", "getAgent", "listRevisions", "setCurrent", "archiveAgent", "unarchiveAgent",
54
59
  "saveComposioServer", "deleteMcpServer", "releaseTriggerFiring",
60
+ "listTriggers", "getTrigger", "listTriggerFirings", "updateTrigger",
55
61
  // Refused in its own words (403): it reads the machine's session files, which a server behind a backend does not have to give.
56
62
  "getWrapped",
57
63
  ]);
@@ -73,6 +79,35 @@ export function apiOnlyTriggerSkipped(packageName, trigger, hooked) {
73
79
  return undefined;
74
80
  return { reason: NOT_SET_UP, message: `${named} and has no launch hook, so its firings have nowhere to go. Start its runs through the API, or set the launch hook (${LAUNCH_HOOK_URL_ENV} and ${LAUNCH_HOOK_SECRET_ENV}) and apply again: each firing then goes to your backend, which starts its run.` };
75
81
  }
82
+ /** Whether an API-only server turns on a trigger whose source is `kind` and whose target is `target` (its PATCH, its
83
+ * agent's unarchive): only one the apply would make, a source of API_ONLY_HOOKED_KINDS aimed at an agent (start_run),
84
+ * with the launch hook `hooked`, so each firing goes to the backend. A message_run firing never goes to the hook
85
+ * (triggers.ts): on, it would open its run on this server's keys. */
86
+ export function apiOnlyTurnsOn(kind, target, hooked) {
87
+ return hooked && API_ONLY_HOOKED_KINDS.has(kind) && target === "start_run";
88
+ }
89
+ /** Why an API-only server refuses `body`, a PATCH of a trigger whose source is `kind` and whose target is `target`, each
90
+ * an issue (none: it goes on to the trigger's own checks). It takes `enabled` alone: a new source or target would let
91
+ * the token aim a trigger at an address or an agent of its own choosing (a feed's urls fetched by this server, a run of
92
+ * another agent), which no route here lets it make, and a name or a cap is the console's to edit. Turned off: always,
93
+ * it stops firings. Turned on: only where the apply would make it (apiOnlyTurnsOn), so its firings go to the backend;
94
+ * any other would start or open runs on this server's keys, or wait on a hook or setting this profile refuses. */
95
+ export function apiOnlyTriggerEdit(body, kind, hooked, target) {
96
+ if (body === null || typeof body !== "object" || Array.isArray(body))
97
+ return [];
98
+ const issues = Object.keys(body).filter((key) => key !== "enabled").map((field) => ({ field, reason: "not_allowed", message: `This server serves the run API only (${API_ONLY_ENV}=1), where a trigger is turned on or off alone: send {"enabled": true} or {"enabled": false}, without ${field}.` }));
99
+ if (body.enabled !== true || apiOnlyTurnsOn(kind, target, hooked))
100
+ return issues;
101
+ const named = `This server serves the run API only (${API_ONLY_ENV}=1)`;
102
+ if (target !== "start_run") {
103
+ issues.push({ field: "enabled", reason: "not_an_option", message: `${named}, and this trigger messages a run: its firings never go to the launch hook, so each would open that run on this server's keys. It is not turned on here. Send the run its messages through the API instead.` });
104
+ return issues;
105
+ }
106
+ issues.push(API_ONLY_HOOKED_KINDS.has(kind)
107
+ ? { field: "enabled", reason: NOT_SET_UP, message: `${named} and has no launch hook, so this ${kind} trigger's firings would start runs on this server's keys: set the launch hook (${LAUNCH_HOOK_URL_ENV} and ${LAUNCH_HOOK_SECRET_ENV}), then turn it on.` }
108
+ : { field: "enabled", reason: "not_an_option", message: `${named}, which serves no route or setting a ${kind} trigger needs, so it is not turned on here. Start its runs through the API instead.` });
109
+ return issues;
110
+ }
76
111
  /** Whether an API-only server saves `body` through the generic save (saveMcpServer) over the name its path gives: a
77
112
  * per_run server (no credential kept) whose url's origin is one of `origins`, under a name that is not a Composio
78
113
  * preset's (`preset`; Composio's own route saves those). Checked before anything reaches the address. A body that
@@ -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("; ")}.`);
@@ -71,7 +71,7 @@ export declare function personHands(options: {
71
71
  /** For tests: the clock the person's time is measured by. */
72
72
  now?: () => number;
73
73
  /** The run's held values cut from the ask's words, whole, before they are cut to their bound and written. */
74
- redact?: (text: string) => string;
74
+ redact: (text: string) => string;
75
75
  /** The person's time on a session that just ended, `seconds` of it, to hold until a charge books it (browser-cost.ts
76
76
  * carry): the up-front holds go as it ends, the time it took stays counted. */
77
77
  carry?(tag: string, seconds: number): void;
@@ -475,7 +475,7 @@ export function personHands(options) {
475
475
  const hold = { drop: () => release(ask.sessionTag, user) };
476
476
  const at = Date.now();
477
477
  // Redacted whole, then cut to their bound: a held value the cut would split never leaves its head in the record.
478
- const shown = (text) => (options.redact ? options.redact(text) : text).slice(0, MAX_TEXT);
478
+ const shown = (text) => options.redact(text).slice(0, MAX_TEXT);
479
479
  const record = { id, tag: ask.sessionTag, instruction: shown(ask.instruction), completion_condition: shown(ask.completionCondition), asked_at: new Date(at).toISOString(), expires_at: new Date(at + holdMs).toISOString() };
480
480
  open.set(id, { tag: ask.sessionTag, expiresAt: at + holdMs, drop: () => hold.drop() });
481
481
  watch();
@@ -76,7 +76,7 @@ function calendarTool(host) {
76
76
  let secret = [saved.url];
77
77
  const clean = (text) => {
78
78
  const cut = scrubAddress(text, secret);
79
- return host.redact ? host.redact(cut) : cut;
79
+ return host.redact(cut);
80
80
  };
81
81
  const failed = (words) => forModel(clean(calendarError(`${CALENDAR_EVENTS}: ${words}`)), { isError: true });
82
82
  const given = (isObject(args) ? args : {});
@@ -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. */