@parcha/agentrun-serve 0.1.0-beta.46 → 0.1.0-beta.47

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 (247) hide show
  1. package/CHANGELOG.md +164 -1
  2. package/NOTICE +4 -0
  3. package/README.md +267 -40
  4. package/dist/acp-package.d.ts +35 -6
  5. package/dist/acp-package.js +3 -3
  6. package/dist/adapter-facts.d.ts +5 -2
  7. package/dist/adapter-facts.js +6 -3
  8. package/dist/adapters.d.ts +7 -0
  9. package/dist/adapters.js +39 -0
  10. package/dist/agents-store.d.ts +5 -3
  11. package/dist/agents-store.js +13 -8
  12. package/dist/api-only.d.ts +7 -10
  13. package/dist/api-only.js +7 -10
  14. package/dist/archil-routes.js +2 -1
  15. package/dist/cap.js +12 -2
  16. package/dist/chatgpt-plan.js +2 -1
  17. package/dist/cli.js +109 -41
  18. package/dist/composio-made.d.ts +19 -2
  19. package/dist/composio-made.js +17 -5
  20. package/dist/composio-preset.d.ts +42 -7
  21. package/dist/composio-preset.js +106 -70
  22. package/dist/composio-triggers.d.ts +9 -4
  23. package/dist/composio-triggers.js +20 -13
  24. package/dist/computer-attach.d.ts +11 -10
  25. package/dist/computer-attach.js +13 -14
  26. package/dist/computer-commands.d.ts +3 -0
  27. package/dist/computer-commands.js +3 -2
  28. package/dist/computer-lost.d.ts +4 -0
  29. package/dist/computer-lost.js +8 -3
  30. package/dist/computer-setting.d.ts +2 -0
  31. package/dist/computer-setting.js +2 -0
  32. package/dist/computers.d.ts +9 -75
  33. package/dist/computers.js +20 -66
  34. package/dist/console/assets/index-BBFzAxLB.js +715 -0
  35. package/dist/console/assets/index-BRi-Rgq6.css +1 -0
  36. package/dist/console/index.html +2 -2
  37. package/dist/cost-heal.d.ts +13 -0
  38. package/dist/cost-heal.js +27 -0
  39. package/dist/dial-relay.d.ts +6 -2
  40. package/dist/dial-relay.js +9 -12
  41. package/dist/email/routes.js +2 -1
  42. package/dist/errors.d.ts +2 -0
  43. package/dist/errors.js +5 -0
  44. package/dist/exa-keyless.d.ts +1 -1
  45. package/dist/exa-keyless.js +1 -1
  46. package/dist/faux-computers.d.ts +2 -3
  47. package/dist/faux-computers.js +9 -31
  48. package/dist/github-connection.js +2 -1
  49. package/dist/harness-archive.d.ts +19 -2
  50. package/dist/harness-archive.js +49 -15
  51. package/dist/harness-check.d.ts +73 -0
  52. package/dist/harness-check.js +489 -0
  53. package/dist/harness-cursor.d.ts +45 -0
  54. package/dist/harness-cursor.js +121 -0
  55. package/dist/harness-recipe.d.ts +127 -0
  56. package/dist/harness-recipe.js +357 -0
  57. package/dist/harness-table.d.ts +12 -0
  58. package/dist/harness-table.js +62 -2
  59. package/dist/harness.d.ts +2 -0
  60. package/dist/harness.js +3 -2
  61. package/dist/host-check.d.ts +6 -0
  62. package/dist/host-check.js +14 -0
  63. package/dist/host.d.ts +10 -3
  64. package/dist/host.js +17 -3
  65. package/dist/import-sources.d.ts +2 -0
  66. package/dist/import-sources.js +2 -0
  67. package/dist/import-summary.d.ts +15 -5
  68. package/dist/import-summary.js +24 -8
  69. package/dist/import.d.ts +24 -4
  70. package/dist/import.js +108 -26
  71. package/dist/key-refusal.d.ts +1 -0
  72. package/dist/key-refusal.js +8 -3
  73. package/dist/key-words.d.ts +1 -1
  74. package/dist/key-words.js +4 -4
  75. package/dist/learn/check.d.ts +3 -0
  76. package/dist/learn/check.js +31 -20
  77. package/dist/learn/compile.js +12 -5
  78. package/dist/learn/promote.d.ts +69 -2
  79. package/dist/learn/promote.js +95 -3
  80. package/dist/learned-nodes.d.ts +4 -3
  81. package/dist/learned-workflow.js +4 -1
  82. package/dist/learning-cost.d.ts +6 -16
  83. package/dist/learning-cost.js +6 -12
  84. package/dist/learning-words.d.ts +2 -0
  85. package/dist/learning-words.js +1 -1
  86. package/dist/listen-first.d.ts +10 -0
  87. package/dist/listen-first.js +25 -1
  88. package/dist/llms.txt +1 -1
  89. package/dist/mcp-gateway.d.ts +2 -1
  90. package/dist/mcp-gateway.js +31 -15
  91. package/dist/mcp-probe.d.ts +18 -6
  92. package/dist/mcp-probe.js +41 -8
  93. package/dist/mcp-secret-writes.d.ts +8 -0
  94. package/dist/mcp-secret-writes.js +104 -4
  95. package/dist/mcp-servers-store.d.ts +11 -5
  96. package/dist/mcp-servers-store.js +46 -20
  97. package/dist/model-form.d.ts +2 -1
  98. package/dist/model-form.js +22 -8
  99. package/dist/model-gateway.d.ts +113 -0
  100. package/dist/model-gateway.js +433 -0
  101. package/dist/model.d.ts +2 -1
  102. package/dist/model.js +9 -7
  103. package/dist/monid.js +1 -1
  104. package/dist/native/binding.d.ts +4 -0
  105. package/dist/native/binding.js +9 -0
  106. package/dist/native/cli.d.ts +3 -2
  107. package/dist/native/cli.js +6 -5
  108. package/dist/openapi.d.ts +2 -0
  109. package/dist/openapi.js +322 -39
  110. package/dist/owner.d.ts +4 -2
  111. package/dist/owner.js +10 -4
  112. package/dist/page.d.ts +8 -0
  113. package/dist/page.js +9 -1
  114. package/dist/port-models.js +17 -10
  115. package/dist/provider.d.ts +3 -3
  116. package/dist/provider.js +12 -3
  117. package/dist/public-address.d.ts +28 -0
  118. package/dist/public-address.js +62 -0
  119. package/dist/run-launch.d.ts +1 -1
  120. package/dist/run-launch.js +1 -1
  121. package/dist/run-secrets.d.ts +3 -2
  122. package/dist/run-secrets.js +6 -4
  123. package/dist/runner/adapter-loop.d.ts +10 -7
  124. package/dist/runner/adapter-loop.js +57 -22
  125. package/dist/runner/adapter-run-spec.d.ts +12 -0
  126. package/dist/runner/adapter-run-spec.js +40 -6
  127. package/dist/runner/adapters/index.js +16 -0
  128. package/dist/runner/adapters/pi.d.ts +5 -2
  129. package/dist/runner/adapters/pi.js +7 -4
  130. package/dist/runner/audit.d.ts +7 -0
  131. package/dist/runner/audit.js +15 -6
  132. package/dist/runner/claim-secrets.js +5 -1
  133. package/dist/runner/cli-run-spec.js +15 -7
  134. package/dist/runner/compare-end.d.ts +43 -0
  135. package/dist/runner/compare-end.js +95 -0
  136. package/dist/runner/computer-journal.d.ts +3 -0
  137. package/dist/runner/computer-journal.js +22 -2
  138. package/dist/runner/harness-loops.d.ts +6 -1
  139. package/dist/runner/harness-loops.js +94 -54
  140. package/dist/runner/held.d.ts +5 -4
  141. package/dist/runner/journal-kinds.d.ts +4 -1
  142. package/dist/runner/journal-kinds.js +3 -0
  143. package/dist/runner/loop-contract.d.ts +10 -0
  144. package/dist/runner/main.d.ts +5 -5
  145. package/dist/runner/main.js +62 -11
  146. package/dist/runner/mcp-claim.js +40 -12
  147. package/dist/runner/metrics.d.ts +26 -0
  148. package/dist/runner/metrics.js +44 -1
  149. package/dist/runner/presence.d.ts +41 -0
  150. package/dist/runner/presence.js +89 -0
  151. package/dist/runner/promotion.d.ts +9 -4
  152. package/dist/runner/promotion.js +33 -14
  153. package/dist/runner/run-child-host.js +40 -10
  154. package/dist/runner/runner.d.ts +5 -0
  155. package/dist/runner/runner.js +8 -0
  156. package/dist/runner/store-port.d.ts +3 -0
  157. package/dist/runner/store-secrets.js +19 -7
  158. package/dist/runner/workflow-first.d.ts +5 -2
  159. package/dist/runner/workflow-first.js +6 -3
  160. package/dist/runs-over-store.d.ts +6 -2
  161. package/dist/runs-over-store.js +14 -4
  162. package/dist/sdk/runs.d.ts +1 -1
  163. package/dist/sdk/runs.js +6 -1
  164. package/dist/sdk/schema.js +1 -1
  165. package/dist/secret-writes.d.ts +16 -3
  166. package/dist/secret-writes.js +28 -3
  167. package/dist/server-secrets-store.js +5 -0
  168. package/dist/server.d.ts +31 -2
  169. package/dist/server.js +322 -51
  170. package/dist/sign-ins-secrets.js +4 -1
  171. package/dist/skills/agentrun-serve/SKILL.md +11 -0
  172. package/dist/slack-url.d.ts +5 -0
  173. package/dist/slack-url.js +11 -0
  174. package/dist/slack.d.ts +107 -0
  175. package/dist/slack.js +292 -0
  176. package/dist/start-switches.d.ts +28 -0
  177. package/dist/start-switches.js +37 -0
  178. package/dist/stats.d.ts +1 -1
  179. package/dist/stats.js +2 -1
  180. package/dist/stop-signals.d.ts +11 -0
  181. package/dist/stop-signals.js +22 -0
  182. package/dist/store/agent-body.d.ts +1 -1
  183. package/dist/store/agent-body.js +2 -2
  184. package/dist/store/index.d.ts +3 -3
  185. package/dist/store/index.js +1 -1
  186. package/dist/store/postgres/migrations/0020_runners.sql +18 -0
  187. package/dist/store/postgres/store.d.ts +1 -1
  188. package/dist/store/postgres/store.js +4 -2
  189. package/dist/store/schema.d.ts +13 -5
  190. package/dist/store/schema.js +20 -11
  191. package/dist/store/seal.d.ts +16 -4
  192. package/dist/store/sqlite/store.d.ts +1 -1
  193. package/dist/store/sqlite/store.js +106 -27
  194. package/dist/store/store.d.ts +75 -23
  195. package/dist/store/store.js +11 -0
  196. package/dist/store-reads/analytics.js +3 -2
  197. package/dist/store-reads/cap.d.ts +7 -0
  198. package/dist/store-reads/cap.js +11 -1
  199. package/dist/store-reads/journal.js +27 -1
  200. package/dist/store-reads/learning.d.ts +23 -2
  201. package/dist/store-reads/learning.js +29 -8
  202. package/dist/store-reads/runs.d.ts +9 -0
  203. package/dist/store-reads/runs.js +19 -6
  204. package/dist/store-reads/stats.d.ts +4 -1
  205. package/dist/store-reads/stats.js +15 -6
  206. package/dist/store-view.d.ts +123 -14
  207. package/dist/store-view.js +154 -21
  208. package/dist/telemetry.d.ts +7 -7
  209. package/dist/telemetry.js +38 -15
  210. package/dist/timeline/timeline.js +18 -0
  211. package/dist/tool-keys-store.js +2 -2
  212. package/dist/tool-keys.js +2 -1
  213. package/dist/tool-plane.js +2 -2
  214. package/dist/trigger-adapter.d.ts +3 -4
  215. package/dist/trigger-adapter.js +2 -2
  216. package/dist/trigger-composio.js +3 -3
  217. package/dist/trigger-email.js +0 -2
  218. package/dist/trigger-feed.js +0 -2
  219. package/dist/trigger-schedule.js +3 -0
  220. package/dist/trigger-secrets-shown.d.ts +6 -3
  221. package/dist/trigger-secrets-shown.js +22 -13
  222. package/dist/trigger-targets.d.ts +1 -1
  223. package/dist/trigger-targets.js +19 -8
  224. package/dist/triggers.d.ts +2 -2
  225. package/dist/webhooks.d.ts +82 -8
  226. package/dist/webhooks.js +128 -45
  227. package/dist/wires.d.ts +6 -1
  228. package/dist/wires.js +5 -0
  229. package/dist/workspace/attach.d.ts +3 -2
  230. package/dist/workspace/attach.js +2 -1
  231. package/dist/workspace/attached-computers.d.ts +6 -8
  232. package/dist/workspace/attached-computers.js +27 -24
  233. package/dist/workspace/computer-deps.d.ts +2 -3
  234. package/dist/workspace/computer-deps.js +3 -6
  235. package/dist/workspace/computer-for-claim.js +72 -96
  236. package/dist/workspace/computer-kept.d.ts +0 -7
  237. package/dist/workspace/computer-kept.js +0 -17
  238. package/dist/workspace/resolve-computer.d.ts +18 -14
  239. package/dist/workspace/resolve-computer.js +47 -60
  240. package/dist/workspace/synced-folder.d.ts +20 -15
  241. package/dist/workspace/synced-folder.js +33 -43
  242. package/launcher/agentrun-serve +4 -1
  243. package/package.json +10 -10
  244. package/skills/agentrun-serve/SKILL.md +11 -0
  245. package/templates/README.md +1 -1
  246. package/dist/console/assets/index-C2MYaUBa.css +0 -1
  247. package/dist/console/assets/index-CZZeCReB.js +0 -701
@@ -1,6 +1,6 @@
1
- export { AgentArchived, AgentDeleting, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft } from "./store.js";
2
- export type { ConstraintRule, AgentRow, Agents, AlsoRow, ChannelPost, Claim, Command, ComputerLedger, ComputerLedgerRow, Firing, FiringChange, FiringRow, FiringStatus, FiringStreak, Journal, Live, LiveRow, Mcp, McpCredentialMark, McpRemoved, McpOauth, McpOauthPendingRow, McpPinRow, McpServerRow, McpServerStamp, McpServerWrite, MintedTokenRow, MintedTokens, NewFiring, NewPairedComputer, NewRevision, NewTrigger, PairedComputerRow, PairedComputers, ReleasedState, RevisionRow, RunnerRelayRow, RunnerRelays, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, TemplatePackage, Templates, TriggerDef, TriggerPatch, TriggerRow, Triggers, TriggerScope, TriggerSettingRow, TriggerSettings, Channels, ChannelAttemptRow, ChannelPostRow, ChannelToldRow, ImportedFrom, ImportSource, ImportRunInput, JournalReads, RunLabels, RunOrigin, RunOutcome, RunLaunchInput, RunLaunchRow, LaunchSealed, LaunchSealedWrite, Learning, LearningProposal, LiveViewerRow, LiveViewers, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
3
- export { aadOf, type McpCredential, type OpenedMcpCredential, openMcpCredential, openRunLaunch, openRunMcpAuth, type RunLaunchSecrets, type RunMcpAuth, type RunModelKey, sealColumn, type SealedAt, sealedAt, sealMcpCredential, sealRunLaunch, sealRunMcpAuth, unsealColumn } from "./seal.js";
1
+ export { AgentArchived, AgentDeleting, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreAwaitsServer, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft } from "./store.js";
2
+ export type { ConstraintRule, AgentRow, Agents, AlsoRow, ChannelPost, Claim, Command, ComputerLedger, ComputerLedgerRow, Firing, FiringChange, FiringRow, FiringStatus, FiringStreak, Journal, Live, LiveRow, Mcp, McpCredentialMark, McpRemoved, McpOauth, McpOauthPendingRow, McpPinRow, McpServerRow, McpServerStamp, McpServerWrite, MintedTokenRow, MintedTokens, NewFiring, NewPairedComputer, NewRevision, NewTrigger, PairedComputerRow, PairedComputers, ReleasedState, RevisionRow, RunnerRow, Runners, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, TemplatePackage, Templates, TriggerDef, TriggerPatch, TriggerRow, Triggers, TriggerScope, TriggerSettingRow, TriggerSettings, Channels, ChannelAttemptRow, ChannelPostRow, ChannelToldRow, ImportedFrom, ImportSource, ImportRunInput, JournalReads, RunLabels, RunOrigin, RunOutcome, RunLaunchInput, RunLaunchRow, LaunchSealed, LaunchSealedWrite, Learning, LearningProposal, LiveViewerRow, LiveViewers, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
3
+ export { aadOf, type McpCredential, type OpenedMcpCredential, openMcpCredential, openRunLaunch, openRunMcpAuth, type RunLaunchSecrets, type ComposioBinding, type RunMcpAuth, type RunMcpEntry, type RunModelKey, sealColumn, type SealedAt, sealedAt, sealMcpCredential, sealRunLaunch, sealRunMcpAuth, unsealColumn } from "./seal.js";
4
4
  export { AgentBodyInvalid, type AgenticBody, bodyOf, canonical, isObject, isSkillPath, type PromptVariant, type ModelTiers, type MonidPinBody, type RevisionBodyInput, type RevisionComputer, type RevisionPlace, sha256, type ToolSettings, type WorkflowBody, } from "./agent-body.js";
5
5
  export { checkPrompts, OTHER_OPTION, PromptsInvalid } from "./prompts.js";
6
6
  export { DDL, PI_DDL, PI_TABLE, PI_TABLES, SCHEMA_VERSION, STORE_DDL } from "./schema.js";
@@ -1,5 +1,5 @@
1
1
  // The one store (design 2.1), for the cutover: nothing on main imports it until then.
2
- export { AgentArchived, AgentDeleting, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft } from "./store.js";
2
+ export { AgentArchived, AgentDeleting, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreAwaitsServer, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft } from "./store.js";
3
3
  export { aadOf, openMcpCredential, openRunLaunch, openRunMcpAuth, sealColumn, sealedAt, sealMcpCredential, sealRunLaunch, sealRunMcpAuth, unsealColumn } from "./seal.js";
4
4
  export { AgentBodyInvalid, bodyOf, canonical, isObject, isSkillPath, sha256, } from "./agent-body.js";
5
5
  export { checkPrompts, OTHER_OPTION, PromptsInvalid } from "./prompts.js";
@@ -0,0 +1,18 @@
1
+ -- The store's schema on Postgres, version 20: each runner's word that it is there (runner/presence.ts) and its relay
2
+ -- (dial-relay.ts) in one table, as store/schema.ts keeps it on SQLite (RUNNERS). Applied once, after 0019, inside the
3
+ -- transaction migrate.ts opens. Never edit this file once applied: a change is a new file.
4
+ --
5
+ -- runners (runner_relays until now): one row per runner, beside a server or in a process of its own: its name, its
6
+ -- incarnation (its process since its start, the one its relay's minted tokens and proofs name), why it refused to claim
7
+ -- any run (`refused`, its words; null for a runner that claims), where its relay's attach listener answers (`host` and
8
+ -- `port`; null for a runner with no relay) and when it last said it was there. The server reads them for whether any
9
+ -- runner here can take a run, and where to relay a dial. In place: every relay's row is kept, refusing nothing, and
10
+ -- reads as gone 30 s after its last renewal, as any runner's row does.
11
+
12
+ ALTER TABLE runner_relays RENAME TO runners;
13
+ ALTER TABLE runners RENAME CONSTRAINT runner_relays_pkey TO runners_pkey;
14
+ ALTER TABLE runners ALTER COLUMN host DROP NOT NULL;
15
+ ALTER TABLE runners ALTER COLUMN port DROP NOT NULL;
16
+ ALTER TABLE runners ADD COLUMN refused TEXT;
17
+
18
+ UPDATE store_meta SET schema_version = 20 WHERE singleton = 1;
@@ -44,5 +44,5 @@ export interface PostgresStoreOptions {
44
44
  /** Opens the store in `schema` on the Postgres at `url`. As the server (the default): takes the owner lock (StoreOwned when
45
45
  * another server holds the schema) and applies the pending migrations. As a runner: sets nothing up, and warns when its
46
46
  * clock is far from the database's. Either refuses a schema version this build does not know (SchemaVersionUnknown), a
47
- * runner also a schema not set up yet. */
47
+ * runner also a schema not set up yet, and one this build's server has yet to migrate (StoreAwaitsServer). */
48
48
  export declare function openPostgresStore(options: PostgresStoreOptions): Promise<Store>;
@@ -1,7 +1,7 @@
1
1
  // The Store on Postgres: the same domain code as SQLite's (sqlite/store.ts storeOver) over a Postgres connection
2
2
  // (connection.ts) in the store's own schema (default "agentrun"). The server sets the schema up (migrate.ts) and holds the
3
3
  // owner lock, one server per schema; runners are many, set nothing up, and refuse a schema version they do not know.
4
- import { SchemaVersionUnknown } from "../store.js";
4
+ import { SchemaVersionUnknown, StoreAwaitsServer } from "../store.js";
5
5
  import { backfillNativeCommandOwners } from '../native-command-owner.js';
6
6
  import { storeOver } from "../sqlite/store.js";
7
7
  import { PgConnection, SCHEMA_NAME } from "./connection.js";
@@ -15,7 +15,7 @@ export { postgresWhere } from "./connection.js";
15
15
  /** Opens the store in `schema` on the Postgres at `url`. As the server (the default): takes the owner lock (StoreOwned when
16
16
  * another server holds the schema) and applies the pending migrations. As a runner: sets nothing up, and warns when its
17
17
  * clock is far from the database's. Either refuses a schema version this build does not know (SchemaVersionUnknown), a
18
- * runner also a schema not set up yet. */
18
+ * runner also a schema not set up yet, and one this build's server has yet to migrate (StoreAwaitsServer). */
19
19
  export async function openPostgresStore(options) {
20
20
  const schema = options.schema ?? DEFAULT_SCHEMA;
21
21
  if (!SCHEMA_NAME.test(schema))
@@ -42,6 +42,8 @@ export async function openPostgresStore(options) {
42
42
  });
43
43
  try {
44
44
  const found = await connection.withClient((client) => (role === "server" ? migrate(client, schema, now(), migrations) : versionOf(client, schema)));
45
+ if (role === "runner" && found !== null && found < known)
46
+ throw new StoreAwaitsServer(`bring this store from version ${found} to ${known}`);
45
47
  if (found !== known)
46
48
  throw new SchemaVersionUnknown(placeOf(schema), found, known);
47
49
  if (role === "server")
@@ -40,12 +40,20 @@ export declare const IMPORTED_TEMPLATES: string;
40
40
  * end its wait; null while none was, and again at a mint. In STORE_DDL, and added at a server open to a store an earlier
41
41
  * build of this version made. */
42
42
  export declare const MINTED_TOKENS = "CREATE TABLE IF NOT EXISTS minted_tokens (\n machine TEXT PRIMARY KEY,\n token_sha256 TEXT NOT NULL UNIQUE,\n kind TEXT NOT NULL,\n os TEXT NOT NULL,\n arch TEXT NOT NULL,\n expires_at INTEGER NOT NULL,\n revoked_at INTEGER,\n created_at INTEGER NOT NULL,\n runner TEXT,\n incarnation TEXT,\n run TEXT,\n refused TEXT\n ) STRICT";
43
- /** Where each runner in a process of its own takes the dials the server relays to it (version 13, dial-relay.ts): its
44
- * attach listener's host and port under its name, with its incarnation and when it last said it was there. */
45
- export declare const RUNNER_RELAYS = "CREATE TABLE IF NOT EXISTS runner_relays (\n runner TEXT PRIMARY KEY,\n incarnation TEXT NOT NULL,\n host TEXT NOT NULL,\n port INTEGER NOT NULL,\n seen_at INTEGER NOT NULL\n ) STRICT";
43
+ /** Each runner's word that it is there (runner/presence.ts), every runner's, beside a server or in a process of its own:
44
+ * its name, its incarnation (its process since its start, the one its relay's minted tokens and proofs name), why it
45
+ * refused to claim any run (`refused`, its words; null for one that claims), where its relay's attach listener takes the
46
+ * dials the server relays to it (`host` and `port`, dial-relay.ts; null for a runner with no relay) and when it last said
47
+ * it was there. The server reads them for whether any runner here can take a run (a launch's 503 runner_refused,
48
+ * capabilities' runner_refused, health's runner check) and where to relay a dial (computer-attach.ts liveRelays). In
49
+ * STORE_DDL. A store an earlier build of version 13 made kept the relays in a table of their own (runner_relays): the
50
+ * server's open drops it and makes this one (sqlite/store.ts), as it drops browser_viewers, with no version: the rows
51
+ * are heartbeats renewed every 10 s, so none is copied, and a runner waits for that server (StoreAwaitsServer). */
52
+ export declare const RUNNERS = "CREATE TABLE IF NOT EXISTS runners (\n runner TEXT PRIMARY KEY,\n incarnation TEXT NOT NULL,\n refused TEXT,\n host TEXT,\n port INTEGER,\n seen_at INTEGER NOT NULL\n ) STRICT";
46
53
  /** Version 12 → 13 on SQLite (the server's open, sqlite/store.ts), given minted_tokens' columns now: the minting runner,
47
54
  * its incarnation, the machine's run and a refused relay's words on each token's row (none of the rows there has one: the
48
- * server's own process minted them, naming no run), the runners' relays, and the version, in one durable write. */
55
+ * server's own process minted them, naming no run), the runners (where their relays answer), and the version, in one
56
+ * durable write. */
49
57
  export declare function relayUpgrade(mintedColumns: ReadonlySet<string>): readonly string[];
50
58
  /** A run's listing on its row (version 12): what a runs list shows of the run, so a list reads rows alone and never builds
51
59
  * a run's view. `list_mark` moves (+1) in the transaction of every write that can change what the run's view shows: its
@@ -56,7 +64,7 @@ export declare function relayUpgrade(mintedColumns: ReadonlySet<string>): readon
56
64
  * that lands meanwhile keeps the row as it left it (its list_status too), behind (listing_mark < list_mark), and it is
57
65
  * built again: a crash between a write and its listing leaves a row that says
58
66
  * it is behind, never one that says it is current. `listing` is the list item without the parts read when it is listed
59
- * (console_url, archived_at); `list_status` its status, which a status filter reads in SQL; `listing_live` whether a runner
67
+ * (console_url, archived_at), with the secrets it was cut of (a list builds one cut of other secrets again: store-view.ts builtOfNow); `list_status` its status, which a status filter reads in SQL; `listing_live` whether a runner
60
68
  * held the run when it was built (its status reads otherwise once that claim runs out); `listing_until` when it goes stale
61
69
  * by the clock alone (an ask that expires, or the retry of a build that withheld the run for a sign-in it could not read
62
70
  * back); `listing_flags` what outside the run it read (LISTING_HELD: learning held for
@@ -18,7 +18,7 @@
18
18
  // The template packages imported from GitHub (imported_templates) are a table of their own that nothing
19
19
  // else reads, so it needs no version: the server adds it at its open to a store an earlier build of this version made
20
20
  // (IMPORTED_TEMPLATES), as it does the one-answer index. A hosted machine's minted token (minted_tokens, MINTED_TOKENS) is
21
- // added the same way.
21
+ // added the same way, and so is each runner's word that it is there and whether it refused to claim (runners, RUNNERS).
22
22
  // Conventions: every time is INTEGER epoch milliseconds; JSON is TEXT checked by json_valid; money is REAL US dollars;
23
23
  // sealed columns hold ciphertext only (sealed with the server's key outside the store), so the store never sees a secret
24
24
  // in the clear. Foreign keys are on (the connection's pragma).
@@ -32,7 +32,7 @@
32
32
  // Version 12 keeps each run's listing on its row (RUN_LISTING_COLUMNS): what a runs list shows of it, so a list reads rows
33
33
  // alone. Version 13 names the runner in a process of its own that minted a hosted machine's token (minted_tokens.runner,
34
34
  // .incarnation), the run the machine works for (.run), why the server refused to relay its dial (.refused), and where each
35
- // such runner takes the dials the server relays to it (runner_relays, dial-relay.ts). The server upgrades these two in place at its open (listingUpgrade from 11, then relayUpgrade from 12); a runner waits for it.
35
+ // such runner takes the dials the server relays to it (runners.host and .port, dial-relay.ts). The server upgrades these two in place at its open (listingUpgrade from 11, then relayUpgrade from 12); a runner waits for it.
36
36
  export const SCHEMA_VERSION = 13;
37
37
  /** One answer per approval of a run: a second approve or deny command naming the same approval is refused
38
38
  * (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
@@ -100,22 +100,31 @@ export const MINTED_TOKENS = `CREATE TABLE IF NOT EXISTS minted_tokens (
100
100
  run TEXT,
101
101
  refused TEXT
102
102
  ) STRICT`;
103
- /** Where each runner in a process of its own takes the dials the server relays to it (version 13, dial-relay.ts): its
104
- * attach listener's host and port under its name, with its incarnation and when it last said it was there. */
105
- export const RUNNER_RELAYS = `CREATE TABLE IF NOT EXISTS runner_relays (
103
+ /** Each runner's word that it is there (runner/presence.ts), every runner's, beside a server or in a process of its own:
104
+ * its name, its incarnation (its process since its start, the one its relay's minted tokens and proofs name), why it
105
+ * refused to claim any run (`refused`, its words; null for one that claims), where its relay's attach listener takes the
106
+ * dials the server relays to it (`host` and `port`, dial-relay.ts; null for a runner with no relay) and when it last said
107
+ * it was there. The server reads them for whether any runner here can take a run (a launch's 503 runner_refused,
108
+ * capabilities' runner_refused, health's runner check) and where to relay a dial (computer-attach.ts liveRelays). In
109
+ * STORE_DDL. A store an earlier build of version 13 made kept the relays in a table of their own (runner_relays): the
110
+ * server's open drops it and makes this one (sqlite/store.ts), as it drops browser_viewers, with no version: the rows
111
+ * are heartbeats renewed every 10 s, so none is copied, and a runner waits for that server (StoreAwaitsServer). */
112
+ export const RUNNERS = `CREATE TABLE IF NOT EXISTS runners (
106
113
  runner TEXT PRIMARY KEY,
107
114
  incarnation TEXT NOT NULL,
108
- host TEXT NOT NULL,
109
- port INTEGER NOT NULL,
115
+ refused TEXT,
116
+ host TEXT,
117
+ port INTEGER,
110
118
  seen_at INTEGER NOT NULL
111
119
  ) STRICT`;
112
120
  /** Version 12 → 13 on SQLite (the server's open, sqlite/store.ts), given minted_tokens' columns now: the minting runner,
113
121
  * its incarnation, the machine's run and a refused relay's words on each token's row (none of the rows there has one: the
114
- * server's own process minted them, naming no run), the runners' relays, and the version, in one durable write. */
122
+ * server's own process minted them, naming no run), the runners (where their relays answer), and the version, in one
123
+ * durable write. */
115
124
  export function relayUpgrade(mintedColumns) {
116
125
  return [
117
126
  ...["runner", "incarnation", "run", "refused"].filter((column) => !mintedColumns.has(column)).map((column) => `ALTER TABLE minted_tokens ADD COLUMN ${column} TEXT`),
118
- RUNNER_RELAYS,
127
+ RUNNERS,
119
128
  "UPDATE store_meta SET schema_version = 13 WHERE singleton = 1",
120
129
  ];
121
130
  }
@@ -128,7 +137,7 @@ export function relayUpgrade(mintedColumns) {
128
137
  * that lands meanwhile keeps the row as it left it (its list_status too), behind (listing_mark < list_mark), and it is
129
138
  * built again: a crash between a write and its listing leaves a row that says
130
139
  * it is behind, never one that says it is current. `listing` is the list item without the parts read when it is listed
131
- * (console_url, archived_at); `list_status` its status, which a status filter reads in SQL; `listing_live` whether a runner
140
+ * (console_url, archived_at), with the secrets it was cut of (a list builds one cut of other secrets again: store-view.ts builtOfNow); `list_status` its status, which a status filter reads in SQL; `listing_live` whether a runner
132
141
  * held the run when it was built (its status reads otherwise once that claim runs out); `listing_until` when it goes stale
133
142
  * by the clock alone (an ask that expires, or the retry of a build that withheld the run for a sign-in it could not read
134
143
  * back); `listing_flags` what outside the run it read (LISTING_HELD: learning held for
@@ -538,7 +547,7 @@ export const STORE_DDL = [
538
547
  ) STRICT`,
539
548
  IMPORTED_TEMPLATES,
540
549
  MINTED_TOKENS,
541
- RUNNER_RELAYS,
550
+ RUNNERS,
542
551
  // An agent's saved browser sign-ins (design 2.1, the browser sign-in rules): one live row per agent and browser provider, its
543
552
  // pointer (the vendor's context or profile id) sealed with the store's one rule (store/seal.ts, AAD
544
553
  // sign_ins|<agent>:<provider>|pointer), which the store never opens. The owner sees its name ("default") and saved_at,
@@ -49,12 +49,24 @@ export declare function openMcpCredential(key: Buffer, row: {
49
49
  readonly url: string;
50
50
  readonly sealed: Uint8Array | null;
51
51
  }): OpenedMcpCredential;
52
- /** The MCP credentials a run's caller handed it (`mcp_auth` at its start or with a message), by server name: each one's
53
- * headers and the origin of the server's url when it was handed, so a server moved since never receives them. */
54
- export type RunMcpAuth = Readonly<Record<string, {
52
+ /** A run's binding of a per-run Composio server: the Composio user its calls run as, and the connected account when the
53
+ * caller names one. Never kept on the server's row: sealed in the run's launch alone. */
54
+ export type ComposioBinding = {
55
+ readonly user_id: string;
56
+ readonly connected_account_id?: string;
57
+ };
58
+ /** What a run's caller handed one MCP server (`mcp_auth.<server>`): a per_run server's headers, or a per-run Composio
59
+ * server's binding (its key stays the server's own); each with the origin of the server's url when it was handed, so a
60
+ * server moved since never receives them. */
61
+ export type RunMcpEntry = ({
55
62
  readonly headers: Readonly<Record<string, string>>;
63
+ } | {
64
+ readonly composio: ComposioBinding;
65
+ }) & {
56
66
  readonly origin: string;
57
- }>>;
67
+ };
68
+ /** The MCP credentials a run's caller handed it (`mcp_auth` at its start or with a message), by server name. */
69
+ export type RunMcpAuth = Readonly<Record<string, RunMcpEntry>>;
58
70
  /** A run's own model key (`model_key` at its start or with a message): the key its model requests carry, and the origin
59
71
  * of the gateway it was handed for (AGENT_MODEL_BASE_URL's then), so a gateway moved since never receives it. */
60
72
  export type RunModelKey = {
@@ -26,7 +26,7 @@ export type SqliteStoreOptions = (
26
26
  * default): makes the data directory, takes the owner lock (StoreOwned when another server holds it) and, on a store with
27
27
  * no schema yet, sets schema SCHEMA_VERSION up in one durable commit. As a runner: makes and sets up nothing. Either
28
28
  * refuses a schema version this build does not know (SchemaVersionUnknown); a runner refuses no schema (or no data
29
- * directory) too. */
29
+ * directory) too, and a store this build's server has yet to upgrade (StoreAwaitsServer). */
30
30
  export declare function openSqliteStore(options: SqliteStoreOptions): Promise<Store>;
31
31
  /** The Store over `connection`, on whichever database it is (SQLite here, Postgres in postgres/store.ts), on the store's
32
32
  * clock `now` (ms), its identity `where` (Store.where). The opener sets the schema up and checks its version first.
@@ -11,8 +11,8 @@ import { backfillNativeCommandOwners, nativeCommandOwner, validConnectorId } fro
11
11
  import { watchCommandsAt, wakeCommands } from "../command-wake.js";
12
12
  import { claimFence, storeNow } from "../fence.js";
13
13
  import { RunStorage } from "../journal/storage.js";
14
- import { COMMANDS_ONE_ANSWER, DDL, IMPORTED_TEMPLATES, listingUpgrade, MINTED_TOKENS, relayUpgrade, NATIVE_COMMANDS_INDEX, PI_TABLES, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION, SETTLED_LIST_STATUS, TRIGGERS_TEMPLATE_ID } from "../schema.js";
15
- import { AgentArchived, AgentDeleting, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreBusy, StoreConstraint, StoreFromEarlierVersion, TriggerFull, TriggersLeft, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, } from "../store.js";
14
+ import { COMMANDS_ONE_ANSWER, DDL, IMPORTED_TEMPLATES, listingUpgrade, MINTED_TOKENS, relayUpgrade, NATIVE_COMMANDS_INDEX, PI_TABLES, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUNNERS, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION, SETTLED_LIST_STATUS, TRIGGERS_TEMPLATE_ID } from "../schema.js";
15
+ import { AgentArchived, AgentDeleting, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreAwaitsServer, StoreBusy, StoreConstraint, StoreFromEarlierVersion, TriggerFull, TriggersLeft, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, RUNNER_ROWS_KEPT_MS, } from "../store.js";
16
16
  /** The seq a run-change cursor names (Runs.changedSince): only a cursor this store handed back, a whole number. */
17
17
  const seqOf = (cursor) => {
18
18
  if (!/^(0|[1-9][0-9]{0,15})$/.test(cursor))
@@ -158,7 +158,7 @@ const sealedKeyOf = (r) => ({ name: r.name, sealed: Uint8Array.from(r.sealed), u
158
158
  const ledgerRowOf = (r) => ({ provider: r.provider, sessionId: r.session_id, labels: JSON.parse(r.labels), detail: JSON.parse(r.detail), updatedAt: r.updated_at });
159
159
  const pairedOf = (r) => ({ id: r.id, name: r.name, hello: JSON.parse(r.hello), driver: r.driver, labels: JSON.parse(r.labels), pairingId: r.pairing_id, createdAt: r.created_at, seenAt: r.seen_at, revokedAt: r.revoked_at });
160
160
  const mintedOf = (r) => ({ machine: r.machine, kind: r.kind, os: r.os, arch: r.arch, expiresAt: r.expires_at, revokedAt: r.revoked_at, createdAt: r.created_at, runner: r.runner, incarnation: r.incarnation, run: r.run, refused: r.refused });
161
- const relayOf = (r) => ({ runner: r.runner, incarnation: r.incarnation, host: r.host, port: Number(r.port), seenAt: Number(r.seen_at) });
161
+ const runnerOf = (r) => ({ runner: r.runner, incarnation: r.incarnation, refused: r.refused, host: r.host, port: r.port === null ? null : Number(r.port), seenAt: Number(r.seen_at) });
162
162
  const triggerSettingOf = (r) => ({ adapter: r.adapter, scope: r.scope, field: r.field, sealed: r.sealed, updatedAt: r.updated_at });
163
163
  const mcpOauthOf = (r) => ({ state: r.state, server: r.server, sealed: Uint8Array.from(r.sealed), working: r.working === null ? null : JSON.parse(r.working), expiresAt: r.expires_at });
164
164
  const SIGN_IN_COLUMNS = "agent_id, provider, name, pointer_sealed, saved_at, save, verified_at";
@@ -268,7 +268,7 @@ function isThisVersionsStore(file, busyTimeoutMs) {
268
268
  * default): makes the data directory, takes the owner lock (StoreOwned when another server holds it) and, on a store with
269
269
  * no schema yet, sets schema SCHEMA_VERSION up in one durable commit. As a runner: makes and sets up nothing. Either
270
270
  * refuses a schema version this build does not know (SchemaVersionUnknown); a runner refuses no schema (or no data
271
- * directory) too. */
271
+ * directory) too, and a store this build's server has yet to upgrade (StoreAwaitsServer). */
272
272
  export async function openSqliteStore(options) {
273
273
  // No in-memory store: a caller that names neither place (an undefined passed through) is refused before anything is
274
274
  // opened or made, never left to open a path built from "undefined" (its owner lock in the working directory).
@@ -300,22 +300,22 @@ export async function openSqliteStore(options) {
300
300
  await connection.write([...DDL.map((sql) => ({ sql })), { sql: "INSERT INTO store_meta (singleton, schema_version) VALUES (1, ?) ON CONFLICT (singleton) DO NOTHING", params: [SCHEMA_VERSION] }], { full: true });
301
301
  found = await versionOf(connection);
302
302
  }
303
- // Version 11 (0.1.0-beta.43 and before) keeps no listing on a run's row: the server adds it (schema.ts listingUpgrade)
303
+ // Version 11 (0.1.0-beta.44 and before) keeps no listing on a run's row: the server adds it (schema.ts listingUpgrade)
304
304
  // in one durable write once the columns an earlier build of 11 lacked are in, every run behind until its lister builds
305
305
  // it. Version 12 names no minting runner on a machine's token and keeps no runner's relay: the server adds them
306
306
  // (schema.ts relayUpgrade). A runner refuses 11 and 12 until that server has.
307
307
  const upgrading = found === SCHEMA_VERSION - 2 || found === SCHEMA_VERSION - 1;
308
308
  if (upgrading && role === "runner")
309
- throw new Error(`Start the AgentRun server to bring this store from version ${found} to ${SCHEMA_VERSION} before opening a runner. The runner does not upgrade this store.`);
309
+ throw new StoreAwaitsServer(`bring this store from version ${found} to ${SCHEMA_VERSION}`);
310
310
  if (found !== SCHEMA_VERSION && !upgrading)
311
311
  throw new SchemaVersionUnknown(file, found, SCHEMA_VERSION);
312
312
  const columns = new Set((await connection.all("SELECT name FROM pragma_table_info('revisions')")).map((column) => column.name));
313
313
  if (role === "runner" && (!columns.has("mcp_pin") || !columns.has("monid_pin")))
314
- throw new Error("Start the AgentRun server to install MCP and Monid revision metadata before opening a runner. The runner does not upgrade this store.");
314
+ throw new StoreAwaitsServer("install MCP and Monid revision metadata");
315
315
  const nativeOwners = (await connection.all("PRAGMA table_info(settings)")).some(column => column.name === 'connector_id');
316
316
  if (!nativeOwners) {
317
317
  if (role === 'runner')
318
- throw new Error('Native command ownership metadata is not prepared. Start this build’s server before its runners.');
318
+ throw new StoreAwaitsServer('add native command ownership metadata');
319
319
  await connection.write([{ sql: 'ALTER TABLE settings ADD COLUMN connector_id TEXT' }], { full: true });
320
320
  }
321
321
  // An earlier build of this version kept no bound beside a run's cost (schema.ts RUNS_COST_UPPER_BOUND): the server adds
@@ -323,14 +323,14 @@ export async function openSqliteStore(options) {
323
323
  const runColumns = new Set((await connection.all("SELECT name FROM pragma_table_info('runs')")).map((column) => column.name));
324
324
  if (!runColumns.has("cost_upper_bound")) {
325
325
  if (role === "runner")
326
- throw new Error("Start the AgentRun server to add the bound beside each run's cost before opening a runner. The runner does not upgrade this store.");
326
+ throw new StoreAwaitsServer("add the bound beside each run's cost");
327
327
  await connection.write([{ sql: RUNS_COST_UPPER_BOUND }], { full: true });
328
328
  }
329
329
  // An earlier build of this version kept no labels on a run (schema.ts RUNS_LABELS): the server adds the column, nullable,
330
330
  // every run it started reading as given none. A runner reads each run through it, so it waits for that server.
331
331
  if (!runColumns.has("labels")) {
332
332
  if (role === "runner")
333
- throw new Error("Start the AgentRun server to add each run's labels before opening a runner. The runner does not upgrade this store.");
333
+ throw new StoreAwaitsServer("add each run's labels");
334
334
  await connection.write([{ sql: RUNS_LABELS }], { full: true });
335
335
  }
336
336
  // An earlier build of this version kept no package mark on a trigger (schema.ts TRIGGERS_TEMPLATE_ID): the server adds
@@ -338,9 +338,15 @@ export async function openSqliteStore(options) {
338
338
  // it waits for that server.
339
339
  if (!(await connection.all("SELECT name FROM pragma_table_info('triggers')")).some((column) => column.name === "template_id")) {
340
340
  if (role === "runner")
341
- throw new Error("Start the AgentRun server to add each trigger's package mark before opening a runner. The runner does not upgrade this store.");
341
+ throw new StoreAwaitsServer("add each trigger's package mark");
342
342
  await connection.write([{ sql: TRIGGERS_TEMPLATE_ID }], { full: true });
343
343
  }
344
+ // An earlier build of version 13 kept each runner's relay in a table of its own (runner_relays), which the server's
345
+ // open below drops for runners (schema.ts RUNNERS). A runner says it is there, and where its relay answers, through
346
+ // runners alone, so it waits for that server.
347
+ if (role === "runner" && !(await connection.all("SELECT name FROM pragma_table_info('runners')")).some((column) => column.name === "host")) {
348
+ throw new StoreAwaitsServer("keep each runner's word that it is there and its relay in one table (runners)");
349
+ }
344
350
  // The per-run viewer table was renamed browser_viewers → computer_viewers (schema.ts). Its rows are ephemeral, so none
345
351
  // migrate; the server drops a stale browser_viewers an earlier build of this version left, so none lingers beside it.
346
352
  // An earlier build of this version made no one-answer index on commands (schema.ts COMMANDS_ONE_ANSWER), or one that
@@ -364,6 +370,10 @@ export async function openSqliteStore(options) {
364
370
  { sql: IMPORTED_TEMPLATES },
365
371
  // Nor any hosted machine's minted token (schema.ts MINTED_TOKENS).
366
372
  { sql: MINTED_TOKENS },
373
+ // Nor any runner's word that it is there (schema.ts RUNNERS), and it kept each runner's relay in runner_relays:
374
+ // dropped, its rows heartbeats that each relay's runner writes again within its renewal, so none is copied.
375
+ { sql: "DROP TABLE IF EXISTS runner_relays" },
376
+ { sql: RUNNERS },
367
377
  { sql: NATIVE_COMMANDS_INDEX },
368
378
  ], { full: true });
369
379
  await backfillNativeCommandOwners(connection);
@@ -484,7 +494,7 @@ class SqliteStore {
484
494
  computerLedger;
485
495
  pairedComputers;
486
496
  mintedTokens;
487
- runnerRelays;
497
+ runners;
488
498
  importedTemplates;
489
499
  triggerSettings;
490
500
  channels;
@@ -615,8 +625,13 @@ class SqliteStore {
615
625
  await writeScopes(tx, t.id, []);
616
626
  return off.map(({ id: triggerId, name }) => ({ id: triggerId, name })).sort((a, b) => a.name.localeCompare(b.name));
617
627
  }),
618
- addRevision: async ({ agentId, ifCurrent, ...revision }) => {
619
- await db.transaction((tx) => insertRevision(tx, agentId, revision, now(), ifCurrent));
628
+ addRevision: async ({ agentId, ifCurrent, description, ...revision }) => {
629
+ await db.transaction(async (tx) => {
630
+ await insertRevision(tx, agentId, revision, now(), ifCurrent);
631
+ // Under the row lock insertRevision took, after its ifCurrent passed: the revision and the description, or neither.
632
+ if (description !== undefined)
633
+ await tx.run("UPDATE agents SET description = ? WHERE id = ?", description, agentId);
634
+ });
620
635
  },
621
636
  setCurrent: async (agentId, revisionId) => {
622
637
  const changed = await db.transaction((tx) => tx.runCounted("UPDATE agents SET current_revision = ? WHERE id = ? AND EXISTS (SELECT 1 FROM revisions WHERE id = ? AND agent_id = ?)", revisionId, agentId, revisionId, agentId));
@@ -1079,6 +1094,21 @@ class SqliteStore {
1079
1094
  const row = await db.get("SELECT list_mark FROM runs WHERE id = ?", runId);
1080
1095
  return row === undefined ? undefined : Number(row.list_mark);
1081
1096
  },
1097
+ // A heal of an ended run's unknown cost from its priced booking: one conditional UPDATE, only null to a figure, only
1098
+ // at the end it was read at (a reopen or a later end moves ended_at or the epoch), so it never overwrites a figure.
1099
+ healCost: async (runId, { epoch, endedAt }, usd) => {
1100
+ if (!Number.isFinite(usd) || usd < 0)
1101
+ throw new TypeError(`a healed cost is a figure of $0 or more (got ${usd})`);
1102
+ const [result] = await db.write([{
1103
+ sql: `UPDATE runs SET cost_usd = ?, cost_upper_bound = 0 WHERE id = ? AND cost_usd IS NULL AND state IN (${FINAL}) AND imported_from IS NULL AND epoch = ? AND ended_at = ? RETURNING id`,
1104
+ params: [usd, runId, epoch, endedAt],
1105
+ }]);
1106
+ return (result?.rows.length ?? 0) > 0;
1107
+ },
1108
+ costUnknown: async ({ limit, after }) => {
1109
+ const rows = await db.all(`SELECT id FROM runs WHERE cost_usd IS NULL AND state IN (${FINAL}) AND imported_from IS NULL${after === undefined ? "" : " AND id > ?"} ORDER BY id LIMIT ?`, ...(after === undefined ? [] : [after]), limit);
1110
+ return rows.map((row) => row.id);
1111
+ },
1082
1112
  relist: async ({ flags, agentId }) => {
1083
1113
  const [result] = await db.write([{
1084
1114
  sql: `UPDATE runs SET list_mark = list_mark + 1 WHERE listing_flags <> 0 AND (listing_flags & ?) <> 0${agentId === undefined ? "" : " AND agent_id = ?"} RETURNING id`,
@@ -1165,6 +1195,30 @@ class SqliteStore {
1165
1195
  const rows = await db.all(`SELECT id FROM runs WHERE ${claimable.sql} ORDER BY started_at, id${bounded ? " LIMIT ?" : ""}`, ...claimable.params, ...(bounded ? [limit] : []));
1166
1196
  return rows.map((row) => row.id);
1167
1197
  },
1198
+ failUnclaimed: async (summary) => {
1199
+ // Queued is only ever written at a run's insert (epoch 0); a claim moves it to running and its epoch on. Each run
1200
+ // in a transaction of its own, fenced on that, so a claim that takes one meanwhile leaves it to its runner.
1201
+ const queued = await db.all("SELECT id FROM runs WHERE state = 'queued' AND epoch = 0 AND runner IS NULL ORDER BY started_at, id");
1202
+ const failed = [];
1203
+ for (const { id } of queued) {
1204
+ const ended = await db.transaction(async (tx) => {
1205
+ await d.lockRow(tx, "runs", "id", id, "update");
1206
+ const at = now();
1207
+ const n = storeNow(d, () => at);
1208
+ const row = await tx.get(`UPDATE runs SET state = 'failed', summary = ?, ended_at = ?, left_running_at = ${n.sql}, epoch = epoch + 1 WHERE id = ? AND state = 'queued' AND epoch = 0 AND runner IS NULL RETURNING id`, summary, at, ...n.params, id);
1209
+ if (!row)
1210
+ return false;
1211
+ // As an end does: its untaken commands refused, its launch's secrets erased, in this same commit.
1212
+ await refuseLeftovers(tx, id, "failed", at, d);
1213
+ return true;
1214
+ });
1215
+ if (!ended)
1216
+ continue;
1217
+ failed.push(id);
1218
+ wakeCommands(this.where, { runId: id, what: "answered" });
1219
+ }
1220
+ return failed;
1221
+ },
1168
1222
  heldAt: async (runId) => {
1169
1223
  const n = clock();
1170
1224
  const row = await db.get(`SELECT epoch FROM runs WHERE id = ? AND runner IS NOT NULL AND claimed_until >= ${n.sql}`, runId, ...n.params);
@@ -1635,25 +1689,50 @@ class SqliteStore {
1635
1689
  await db.write([{ sql: "UPDATE minted_tokens SET refused = ? WHERE token_sha256 = ?", params: [words, tokenSha256] }]);
1636
1690
  },
1637
1691
  };
1638
- const RELAYS = "SELECT runner, incarnation, host, port, seen_at FROM runner_relays";
1639
- this.runnerRelays = {
1640
- put: async ({ runner, incarnation, host, port }) => {
1641
- await db.write([{
1642
- sql: "INSERT INTO runner_relays (runner, incarnation, host, port, seen_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT (runner) DO UPDATE SET incarnation = excluded.incarnation, host = excluded.host, port = excluded.port, seen_at = excluded.seen_at",
1643
- params: [runner, incarnation, host, port, now()],
1644
- }]);
1692
+ // Stamped and judged on the deadlines' clock (fence.ts storeNow: the database's on Postgres), the one a claim's lease
1693
+ // runs on, so a runner on another host whose own clock is behind the server's never reads as gone (nor its relay).
1694
+ const RUNNERS_SELECT = "SELECT runner, incarnation, refused, host, port, seen_at FROM runners";
1695
+ this.runners = {
1696
+ put: async ({ runner, incarnation, refused, host = null, port = null }) => {
1697
+ const n = clock();
1698
+ await db.write([
1699
+ { sql: `DELETE FROM runners WHERE seen_at < ${n.sql} - ${d.bigintParam}`, params: [...n.params, RUNNER_ROWS_KEPT_MS] },
1700
+ {
1701
+ sql: `INSERT INTO runners (runner, incarnation, refused, host, port, seen_at) VALUES (?, ?, ?, ?, ?, ${n.sql}) ON CONFLICT (runner) DO UPDATE SET incarnation = excluded.incarnation, refused = excluded.refused, host = excluded.host, port = excluded.port, seen_at = excluded.seen_at`,
1702
+ params: [runner, incarnation, refused, host, port, ...n.params],
1703
+ },
1704
+ ]);
1705
+ },
1706
+ putUnlessLive: async ({ runner, incarnation, refused, host = null, port = null }, staleMs) => {
1707
+ const n = clock();
1708
+ // The upsert's WHERE leaves a row another incarnation renewed within staleMs as it is, in the same statement: no
1709
+ // read between, so a later process's put can never land between a look and this write.
1710
+ const [, result] = await db.write([
1711
+ { sql: `DELETE FROM runners WHERE seen_at < ${n.sql} - ${d.bigintParam}`, params: [...n.params, RUNNER_ROWS_KEPT_MS] },
1712
+ {
1713
+ sql: `INSERT INTO runners (runner, incarnation, refused, host, port, seen_at) VALUES (?, ?, ?, ?, ?, ${n.sql}) ON CONFLICT (runner) DO UPDATE SET incarnation = excluded.incarnation, refused = excluded.refused, host = excluded.host, port = excluded.port, seen_at = excluded.seen_at WHERE runners.incarnation = excluded.incarnation OR runners.seen_at < excluded.seen_at - ${d.bigintParam}`,
1714
+ params: [runner, incarnation, refused, host, port, ...n.params, staleMs],
1715
+ },
1716
+ ]);
1717
+ return (result?.changes ?? 0) === 1;
1718
+ },
1719
+ relayAt: async (runner, incarnation, at) => {
1720
+ const n = clock();
1721
+ const [result] = await db.write([{ sql: `UPDATE runners SET host = ?, port = ?, seen_at = ${n.sql} WHERE runner = ? AND incarnation = ?`, params: [at?.host ?? null, at?.port ?? null, ...n.params, runner, incarnation] }]);
1722
+ return (result?.changes ?? 0) === 1;
1645
1723
  },
1646
1724
  seen: async (runner, incarnation) => {
1647
- const [result] = await db.write([{ sql: "UPDATE runner_relays SET seen_at = ? WHERE runner = ? AND incarnation = ?", params: [now(), runner, incarnation] }]);
1725
+ const n = clock();
1726
+ const [result] = await db.write([{ sql: `UPDATE runners SET seen_at = ${n.sql} WHERE runner = ? AND incarnation = ?`, params: [...n.params, runner, incarnation] }]);
1648
1727
  return (result?.changes ?? 0) === 1;
1649
1728
  },
1650
- get: async (runner) => {
1651
- const row = await db.get(`${RELAYS} WHERE runner = ?`, runner);
1652
- return row === undefined ? undefined : relayOf(row);
1729
+ list: async () => (await db.all(`${RUNNERS_SELECT} ORDER BY runner`)).map(runnerOf),
1730
+ live: async (staleMs) => {
1731
+ const n = clock();
1732
+ return (await db.all(`${RUNNERS_SELECT} WHERE seen_at >= ${n.sql} - ${d.bigintParam} ORDER BY runner`, ...n.params, staleMs)).map(runnerOf);
1653
1733
  },
1654
- list: async () => (await db.all(`${RELAYS} ORDER BY runner`)).map(relayOf),
1655
1734
  remove: async (runner, incarnation) => {
1656
- await db.write([{ sql: "DELETE FROM runner_relays WHERE runner = ? AND incarnation = ?", params: [runner, incarnation] }]);
1735
+ await db.write([{ sql: "DELETE FROM runners WHERE runner = ? AND incarnation = ?", params: [runner, incarnation] }]);
1657
1736
  },
1658
1737
  };
1659
1738
  this.importedTemplates = {