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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/CHANGELOG.md +281 -0
  2. package/README.md +246 -66
  3. package/dist/acp-package.d.ts +2 -0
  4. package/dist/adapters.d.ts +15 -3
  5. package/dist/adapters.js +17 -6
  6. package/dist/agent-package.d.ts +3 -3
  7. package/dist/agent-package.js +17 -8
  8. package/dist/api-keys.d.ts +76 -0
  9. package/dist/api-keys.js +217 -0
  10. package/dist/api-only.d.ts +15 -5
  11. package/dist/api-only.js +32 -8
  12. package/dist/box-paths.d.ts +4 -3
  13. package/dist/box-paths.js +7 -4
  14. package/dist/browser-hold.d.ts +23 -0
  15. package/dist/browser-hold.js +48 -0
  16. package/dist/browser-person.d.ts +3 -0
  17. package/dist/browser-person.js +4 -1
  18. package/dist/chatgpt-plan.d.ts +18 -8
  19. package/dist/chatgpt-plan.js +91 -34
  20. package/dist/claude-login-token.d.ts +117 -0
  21. package/dist/claude-login-token.js +737 -0
  22. package/dist/claude-login.d.ts +120 -22
  23. package/dist/claude-login.js +347 -63
  24. package/dist/claude-sign-in.d.ts +17 -6
  25. package/dist/claude-sign-in.js +42 -39
  26. package/dist/cli.js +33 -10
  27. package/dist/composio-made.d.ts +4 -0
  28. package/dist/composio-made.js +4 -0
  29. package/dist/composio-preset.d.ts +43 -2
  30. package/dist/composio-preset.js +92 -4
  31. package/dist/computer-attach.d.ts +35 -17
  32. package/dist/computer-attach.js +301 -49
  33. package/dist/computer-held-routes.d.ts +5 -4
  34. package/dist/computer-held-routes.js +29 -8
  35. package/dist/computer-held.d.ts +6 -1
  36. package/dist/computer-held.js +14 -0
  37. package/dist/computer-record.js +4 -2
  38. package/dist/computer-viewer.js +4 -1
  39. package/dist/computers.d.ts +10 -10
  40. package/dist/computers.js +5 -5
  41. package/dist/console/assets/{backend-Boh7tC4i.js → backend-CSAWUqtZ.js} +19 -19
  42. package/dist/console/assets/index-Bwn1oTem.css +1 -0
  43. package/dist/console/assets/index-DPh29cyz.js +747 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/decisions.d.ts +1 -1
  46. package/dist/decisions.js +1 -1
  47. package/dist/dial-relay.d.ts +25 -4
  48. package/dist/dial-relay.js +129 -1
  49. package/dist/docker-host-addresses.d.ts +22 -11
  50. package/dist/docker-host-addresses.js +38 -26
  51. package/dist/env-switch.d.ts +8 -0
  52. package/dist/env-switch.js +31 -2
  53. package/dist/errors.d.ts +1 -0
  54. package/dist/errors.js +2 -0
  55. package/dist/fal-price.d.ts +56 -20
  56. package/dist/fal-price.js +400 -90
  57. package/dist/handed-values.d.ts +43 -1
  58. package/dist/handed-values.js +119 -2
  59. package/dist/harness-archive.d.ts +13 -10
  60. package/dist/harness-archive.js +60 -34
  61. package/dist/harness-check.d.ts +3 -1
  62. package/dist/harness-check.js +25 -46
  63. package/dist/harness-keys.d.ts +73 -27
  64. package/dist/harness-keys.js +194 -61
  65. package/dist/harness-recipe-entry.d.ts +8 -7
  66. package/dist/harness-recipe-entry.js +21 -32
  67. package/dist/harness-recipe.d.ts +38 -25
  68. package/dist/harness-recipe.js +49 -36
  69. package/dist/harness-sign-in.js +12 -23
  70. package/dist/harness-table.d.ts +10 -3
  71. package/dist/harness-table.js +26 -21
  72. package/dist/harness.d.ts +1 -0
  73. package/dist/harness.js +17 -5
  74. package/dist/hosted-search.d.ts +1 -1
  75. package/dist/hosted-search.js +1 -2
  76. package/dist/import-worker.d.ts +4 -2
  77. package/dist/import-worker.js +9 -2
  78. package/dist/in-flight.d.ts +26 -0
  79. package/dist/in-flight.js +52 -0
  80. package/dist/key-refusal.d.ts +9 -4
  81. package/dist/key-refusal.js +107 -25
  82. package/dist/learn/ledger.d.ts +170 -0
  83. package/dist/learn/ledger.js +218 -0
  84. package/dist/learn/promote.d.ts +3 -3
  85. package/dist/learn/promote.js +1 -1
  86. package/dist/learn/secrets.d.ts +13 -3
  87. package/dist/learn/secrets.js +118 -17
  88. package/dist/learning-cost.d.ts +28 -23
  89. package/dist/learning-cost.js +19 -23
  90. package/dist/link-check.js +1 -1
  91. package/dist/live-reach.d.ts +2 -0
  92. package/dist/live-reach.js +2 -0
  93. package/dist/llms.txt +1 -1
  94. package/dist/marketplace.d.ts +77 -0
  95. package/dist/marketplace.js +224 -0
  96. package/dist/mcp-api-only-origins.d.ts +35 -0
  97. package/dist/mcp-api-only-origins.js +57 -0
  98. package/dist/mcp-gateway.d.ts +7 -5
  99. package/dist/mcp-gateway.js +9 -12
  100. package/dist/mcp-secret-writes.js +5 -3
  101. package/dist/mcp-servers-store.d.ts +28 -6
  102. package/dist/mcp-servers-store.js +53 -4
  103. package/dist/media-duration.d.ts +3 -0
  104. package/dist/media-duration.js +90 -9
  105. package/dist/micro.d.ts +2 -0
  106. package/dist/micro.js +2 -0
  107. package/dist/model-form.d.ts +5 -4
  108. package/dist/model-form.js +11 -7
  109. package/dist/model.d.ts +10 -6
  110. package/dist/model.js +16 -11
  111. package/dist/monid.d.ts +14 -1
  112. package/dist/monid.js +103 -26
  113. package/dist/ollama-provider.d.ts +7 -1
  114. package/dist/ollama-provider.js +14 -2
  115. package/dist/openapi.js +210 -37
  116. package/dist/otel/genai.d.ts +65 -0
  117. package/dist/otel/genai.js +116 -0
  118. package/dist/otel/tracer.d.ts +55 -0
  119. package/dist/otel/tracer.js +308 -0
  120. package/dist/page.d.ts +2 -0
  121. package/dist/page.js +3 -1
  122. package/dist/paid-calls.d.ts +1 -32
  123. package/dist/paid-calls.js +4 -39
  124. package/dist/place-offers.d.ts +4 -0
  125. package/dist/place-offers.js +7 -4
  126. package/dist/provider.d.ts +11 -2
  127. package/dist/provider.js +59 -8
  128. package/dist/redact/match.d.ts +30 -3
  129. package/dist/redact/match.js +422 -41
  130. package/dist/refusal-words.d.ts +11 -0
  131. package/dist/refusal-words.js +11 -0
  132. package/dist/run-census.d.ts +67 -0
  133. package/dist/run-census.js +240 -0
  134. package/dist/run-computer.d.ts +6 -3
  135. package/dist/run-computer.js +4 -1
  136. package/dist/run-cut.d.ts +15 -6
  137. package/dist/run-cut.js +30 -9
  138. package/dist/run-files.d.ts +3 -0
  139. package/dist/run-files.js +3 -0
  140. package/dist/run-launch.d.ts +12 -1
  141. package/dist/run-launch.js +9 -10
  142. package/dist/run-learning-served.d.ts +4 -2
  143. package/dist/run-model-key.d.ts +8 -0
  144. package/dist/run-model-key.js +31 -1
  145. package/dist/run-reads-over-store.d.ts +24 -6
  146. package/dist/run-reads-over-store.js +67 -23
  147. package/dist/run-recordings.d.ts +5 -1
  148. package/dist/run-recordings.js +39 -14
  149. package/dist/run-timeline-served.d.ts +2 -0
  150. package/dist/run-timeline-served.js +2 -2
  151. package/dist/run-usage.d.ts +1 -0
  152. package/dist/run-view.d.ts +1 -2
  153. package/dist/run-view.js +2 -1
  154. package/dist/runnable.d.ts +10 -1
  155. package/dist/runnable.js +20 -8
  156. package/dist/runner/adapter-loop.d.ts +11 -0
  157. package/dist/runner/adapter-loop.js +58 -26
  158. package/dist/runner/adapter-run-spec.d.ts +55 -11
  159. package/dist/runner/adapter-run-spec.js +183 -52
  160. package/dist/runner/adapters/pi.js +25 -3
  161. package/dist/runner/beside.d.ts +9 -2
  162. package/dist/runner/beside.js +27 -9
  163. package/dist/runner/big-writes.js +1 -10
  164. package/dist/runner/claim-secrets.d.ts +27 -10
  165. package/dist/runner/claim-secrets.js +49 -22
  166. package/dist/runner/cli-run-spec.d.ts +6 -0
  167. package/dist/runner/cli-run-spec.js +97 -38
  168. package/dist/runner/computer-journal.d.ts +9 -1
  169. package/dist/runner/computer-journal.js +26 -0
  170. package/dist/runner/conformance/harness.js +1 -1
  171. package/dist/runner/feedback-round.js +3 -0
  172. package/dist/runner/harness-loops.d.ts +6 -5
  173. package/dist/runner/harness-loops.js +7 -7
  174. package/dist/runner/held.d.ts +24 -6
  175. package/dist/runner/journal-kinds.d.ts +5 -0
  176. package/dist/runner/journal-kinds.js +5 -0
  177. package/dist/runner/main.d.ts +11 -6
  178. package/dist/runner/main.js +19 -9
  179. package/dist/runner/mcp-claim.js +31 -3
  180. package/dist/runner/mcp-run.d.ts +9 -0
  181. package/dist/runner/mcp-run.js +11 -5
  182. package/dist/runner/model-route.d.ts +17 -0
  183. package/dist/runner/model-route.js +120 -2
  184. package/dist/runner/presence.d.ts +11 -1
  185. package/dist/runner/presence.js +7 -0
  186. package/dist/runner/reflect-hook.js +1 -1
  187. package/dist/runner/run-child-host.d.ts +22 -8
  188. package/dist/runner/run-child-host.js +128 -41
  189. package/dist/runner/run-child.js +5 -2
  190. package/dist/runner/runner.d.ts +17 -3
  191. package/dist/runner/runner.js +130 -34
  192. package/dist/runner/save-slots.js +2 -1
  193. package/dist/runner/store-port.d.ts +1 -1
  194. package/dist/runner/store-secrets.d.ts +6 -0
  195. package/dist/runner/store-secrets.js +49 -7
  196. package/dist/runner/subagent.d.ts +11 -0
  197. package/dist/runner/subagent.js +16 -38
  198. package/dist/runner/workflow-first.d.ts +35 -15
  199. package/dist/runner/workflow-first.js +38 -25
  200. package/dist/runner/workflow-spec.js +4 -3
  201. package/dist/runs-over-store.d.ts +15 -6
  202. package/dist/runs-over-store.js +33 -21
  203. package/dist/scrub-command.d.ts +73 -0
  204. package/dist/scrub-command.js +307 -0
  205. package/dist/secret-cut.d.ts +73 -0
  206. package/dist/secret-cut.js +291 -4
  207. package/dist/secret-rules.d.ts +143 -0
  208. package/dist/secret-rules.js +2564 -0
  209. package/dist/secrets.d.ts +7 -0
  210. package/dist/secrets.js +20 -0
  211. package/dist/server-keys.d.ts +20 -0
  212. package/dist/server-keys.js +25 -6
  213. package/dist/server.d.ts +65 -13
  214. package/dist/server.js +470 -157
  215. package/dist/skills/agentrun-serve/SKILL.md +4 -0
  216. package/dist/slots.d.ts +9 -0
  217. package/dist/slots.js +45 -0
  218. package/dist/store/index.d.ts +1 -1
  219. package/dist/store/index.js +1 -1
  220. package/dist/store/journal/storage.js +1 -1
  221. package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
  222. package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
  223. package/dist/store/schema.d.ts +23 -0
  224. package/dist/store/schema.js +58 -2
  225. package/dist/store/seal.d.ts +6 -1
  226. package/dist/store/seal.js +5 -3
  227. package/dist/store/sqlite/run-launch.d.ts +9 -1
  228. package/dist/store/sqlite/run-launch.js +24 -13
  229. package/dist/store/sqlite/run-patch.d.ts +12 -2
  230. package/dist/store/sqlite/run-patch.js +42 -5
  231. package/dist/store/sqlite/store.js +105 -12
  232. package/dist/store/store.d.ts +57 -2
  233. package/dist/store/store.js +20 -0
  234. package/dist/store-reads/learning.d.ts +84 -124
  235. package/dist/store-reads/learning.js +210 -274
  236. package/dist/store-view.d.ts +3 -0
  237. package/dist/store-view.js +3 -3
  238. package/dist/suggestions.js +3 -2
  239. package/dist/template-eval.d.ts +39 -9
  240. package/dist/template-eval.js +191 -60
  241. package/dist/template-import.js +6 -2
  242. package/dist/templates.d.ts +10 -2
  243. package/dist/templates.js +28 -8
  244. package/dist/timeline/labels.d.ts +6 -4
  245. package/dist/timeline/labels.js +18 -6
  246. package/dist/timeline/timeline.d.ts +5 -0
  247. package/dist/timeline/timeline.js +14 -8
  248. package/dist/timeline/util.js +1 -1
  249. package/dist/timeline/web-calls.d.ts +22 -7
  250. package/dist/timeline/web-calls.js +106 -35
  251. package/dist/tool-gate.d.ts +42 -3
  252. package/dist/tool-gate.js +66 -5
  253. package/dist/tool-keys-store.d.ts +2 -4
  254. package/dist/tool-keys-store.js +5 -21
  255. package/dist/tool-keys.d.ts +2 -2
  256. package/dist/tool-keys.js +2 -2
  257. package/dist/tool-list.js +1 -1
  258. package/dist/tool-plane.d.ts +2 -2
  259. package/dist/tool-plane.js +35 -33
  260. package/dist/tools.js +13 -7
  261. package/dist/trigger-targets.d.ts +4 -0
  262. package/dist/trigger-targets.js +9 -2
  263. package/dist/triggers.d.ts +67 -4
  264. package/dist/triggers.js +171 -22
  265. package/dist/until.d.ts +3 -0
  266. package/dist/until.js +11 -0
  267. package/dist/web-fake.d.ts +1 -3
  268. package/dist/web-fake.js +7 -18
  269. package/dist/web-fetch.d.ts +6 -72
  270. package/dist/web-fetch.js +11 -265
  271. package/dist/web-run.d.ts +31 -0
  272. package/dist/web-run.js +90 -0
  273. package/dist/web-save.d.ts +10 -13
  274. package/dist/web-save.js +13 -55
  275. package/dist/web-search.d.ts +9 -127
  276. package/dist/web-search.js +23 -259
  277. package/dist/wires.d.ts +13 -0
  278. package/dist/wires.js +11 -0
  279. package/dist/workflow-run.d.ts +5 -4
  280. package/dist/workflow-run.js +5 -4
  281. package/dist/workspace/attached-computers.d.ts +32 -9
  282. package/dist/workspace/attached-computers.js +77 -13
  283. package/dist/workspace/computer-deps.d.ts +8 -2
  284. package/dist/workspace/computer-deps.js +10 -3
  285. package/dist/workspace/computer-for-claim.d.ts +12 -1
  286. package/dist/workspace/computer-for-claim.js +83 -11
  287. package/dist/workspace/computer-kept.d.ts +3 -0
  288. package/dist/workspace/computer-kept.js +11 -2
  289. package/dist/workspace/index.d.ts +1 -1
  290. package/dist/workspace/index.js +1 -1
  291. package/dist/workspace/kind-skills.d.ts +4 -0
  292. package/dist/workspace/kind-skills.js +9 -0
  293. package/dist/workspace/paired-route.d.ts +91 -0
  294. package/dist/workspace/paired-route.js +153 -0
  295. package/dist/workspace/synced-folder.js +3 -4
  296. package/dist/wrapped.d.ts +20 -6
  297. package/dist/wrapped.js +66 -25
  298. package/package.json +17 -11
  299. package/skills/agentrun-serve/SKILL.md +4 -0
  300. package/templates/README.md +32 -10
  301. package/dist/console/assets/index-CQ3cJRzI.js +0 -746
  302. package/dist/console/assets/index-DKkaS3a0.css +0 -1
  303. package/dist/exa-keyless.d.ts +0 -34
  304. package/dist/exa-keyless.js +0 -118
  305. package/dist/firecrawl-keyless.d.ts +0 -41
  306. package/dist/firecrawl-keyless.js +0 -152
  307. package/dist/keyless-mcp.d.ts +0 -36
  308. package/dist/keyless-mcp.js +0 -127
  309. package/dist/text-urls.d.ts +0 -38
  310. package/dist/text-urls.js +0 -170
  311. package/dist/web-fetch-direct.d.ts +0 -119
  312. package/dist/web-fetch-direct.js +0 -190
@@ -12,8 +12,8 @@ import { watchCommandsAt, wakeCommands } from "../command-wake.js";
12
12
  import { claimFence, storeNow } from "../fence.js";
13
13
  import { JOURNAL_FIRST_ID, RunStorage } from "../journal/storage.js";
14
14
  import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
15
- import { COMMANDS_ONE_ANSWER, COMPUTER_INTERVALS, COMPUTER_INTERVALS_ADDED, COMPUTER_INTERVALS_RUN, DDL, diskUpgrade, HAND_BACKS, HAND_BACKS_AT, HAND_BACKS_KEPT_MS, HAND_BACKS_RUN, IMPORTED_TEMPLATES, listingUpgrade, MINTED_TOKENS, purgeUpgrade, relayUpgrade, NATIVE_COMMANDS_INDEX, PI_TABLE, PI_TABLES, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUN_ATTEMPTS, RUNNERS, RUNNERS_ADDED, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION, SETTLED_LIST_STATUS, TRIGGERS_TEMPLATE_ID } from "../schema.js";
16
- import { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, RunPurged, RunsMadeFromLeft, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreAwaitsServer, StoreBusy, StoreConstraint, StoreFromEarlierVersion, TriggerFull, TriggersLeft, UPLOAD_PREFIX, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, KEPT_PREFIX, RUNNER_ROWS_KEPT_MS, RUNNER_STALE_MS, tombstoneMetrics, } from "../store.js";
15
+ import { COMMANDS_ONE_ANSWER, COMPUTER_INTERVALS, COMPUTER_INTERVALS_ADDED, COMPUTER_INTERVALS_RUN, DDL, diskUpgrade, HAND_BACKS, HAND_BACKS_AT, HAND_BACKS_KEPT_MS, HAND_BACKS_RUN, IMPORTED_TEMPLATES, LEARNING_LEDGER, LEARNING_LEDGER_AGENT, LEARNING_SPEND, LEARNING_SPEND_AGENT, LEARNING_SPEND_OF_RUN, listingUpgrade, MINTED_TOKENS, purgeUpgrade, relayUpgrade, NATIVE_COMMANDS_INDEX, PI_TABLE, PI_TABLES, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUN_ATTEMPTS, RUNNERS, RUNNERS_ADDED, RUN_LAUNCH_CENSUS, RUN_LAUNCH_CENSUS_PENDING, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION, SETTLED_LIST_STATUS, TRIGGERS_TEMPLATE_ID } from "../schema.js";
16
+ import { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, CommandTaken, ExternalBodyConflict, Fenced, FiringMoved, RunFinal, RunPurged, RunsMadeFromLeft, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreAwaitsServer, StoreBusy, StoreConstraint, StoreFromEarlierVersion, TriggerFull, TriggersLeft, UPLOAD_PREFIX, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, KEPT_PREFIX, RUNNER_ROWS_KEPT_MS, RUNNER_STALE_MS, tombstoneMetrics, } from "../store.js";
17
17
  /** The run a launch body is made from (Runs.madeFrom): the run whose input it replays (`replay.of`) or audits (`audit.of`). */
18
18
  const madeOf = (body) => {
19
19
  for (const link of ["replay", "audit"]) {
@@ -32,7 +32,7 @@ const seqOf = (cursor) => {
32
32
  import { cleanText, settledBody } from "../dialect.js";
33
33
  import { inMemory } from "./memory.js";
34
34
  import { Connection, DEFAULT_BUSY_TIMEOUT_MS } from "./connection.js";
35
- import { applyRunPatch, EXACT_COST_USD, NOT_A_LEARNING_RUN, refuseLeftovers, REOPEN_SET, reopenableWhere, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
35
+ import { applyRunPatch, EXACT_COST_USD, NOT_A_LEARNING_RUN, recordLedger, refuseLeftovers, REOPEN_SET, reopenableWhere, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
36
36
  import { launchDiskOf, readableJson, readLaunch, readLearningStarts, readSeededBefore, readUsageMetadata, writeLaunch, writeLaunchSealed } from "./run-launch.js";
37
37
  import { canonical } from "../agent-body.js";
38
38
  import { readProjectCheckpoints } from "./project-checkpoints.js";
@@ -275,11 +275,15 @@ export const SQLITE_RUNNER_NEEDS = [
275
275
  { table: "settings", columns: ["connector_id"], why: "add native command ownership metadata" },
276
276
  { table: "runs", columns: ["cost_upper_bound"], why: "add the bound beside each run's cost" },
277
277
  { table: "runs", columns: ["labels"], why: "add each run's labels" },
278
+ { table: "run_launch", columns: ["census"], why: "add each run's census" },
278
279
  { table: "triggers", columns: ["template_id"], why: "add each trigger's package mark" },
279
280
  { table: "runners", columns: ["host"], why: "keep each runner's word that it is there and its relay in one table (runners)" },
280
281
  { table: "runners", columns: Object.keys(RUNNERS_ADDED), why: "keep each runner's version and slots, and each hand-back (runners.version, runners.slots, hand_backs)" },
281
282
  { table: "hand_backs", columns: ["run_id"], why: "keep each runner's version and slots, and each hand-back (runners.version, runners.slots, hand_backs)" },
282
283
  { table: "run_attempts", columns: ["run_id"], why: "keep each claim's turn and attempt (run_attempts)" },
284
+ // A run's end writes its ledger row and spend rows (run-patch.ts applyRunPatch) in its own transaction.
285
+ { table: "learning_ledger", columns: ["run_id"], why: "write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)" },
286
+ { table: "learning_spend", columns: ["run_id"], why: "write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)" },
283
287
  ];
284
288
  /** What a runner of this build waits for on a file of this version (SQLITE_RUNNER_NEEDS' first missing column's `why`),
285
289
  * or undefined when it opens; `columnsOf` reads a table's columns. */
@@ -453,6 +457,14 @@ export async function openSqliteStore(options) {
453
457
  throw new StoreAwaitsServer("add each run's labels");
454
458
  await connection.write([{ sql: RUNS_LABELS }], { full: true });
455
459
  }
460
+ // An earlier build of this version kept no census on a run's launch (schema.ts RUN_LAUNCH_CENSUS): the server adds the
461
+ // column, nullable, every run ended before reading as never handed a secret, and marks each launch that holds one now
462
+ // as pending (store.ts CENSUS_PENDING). A runner writes it at each end, so it waits for that server.
463
+ if (!(await connection.all("SELECT name FROM pragma_table_info('run_launch')")).some((column) => column.name === "census")) {
464
+ if (role === "runner")
465
+ throw new StoreAwaitsServer("add each run's census");
466
+ await connection.write([{ sql: RUN_LAUNCH_CENSUS }, { sql: RUN_LAUNCH_CENSUS_PENDING }], { full: true });
467
+ }
456
468
  // An earlier build of this version kept no package mark on a trigger (schema.ts TRIGGERS_TEMPLATE_ID): the server adds
457
469
  // the column, nullable, every trigger made before reading as no package's. A runner reads each trigger through it, so
458
470
  // it waits for that server.
@@ -478,6 +490,11 @@ export async function openSqliteStore(options) {
478
490
  if (role === "runner" && (await connection.all("SELECT name FROM pragma_table_info('run_attempts')")).length === 0) {
479
491
  throw new StoreAwaitsServer("keep each claim's turn and attempt (run_attempts)");
480
492
  }
493
+ // A run's end writes its ledger row and spend rows (schema.ts LEARNING_LEDGER, LEARNING_SPEND) in its own transaction:
494
+ // a runner waits for the server that adds the tables (STORE_DDL at its start).
495
+ if (role === "runner" && (await connection.all("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name IN ('learning_ledger', 'learning_spend')")).length < 2) {
496
+ throw new StoreAwaitsServer("write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)");
497
+ }
481
498
  // The per-run viewer table was renamed browser_viewers → computer_viewers (schema.ts). Its rows are ephemeral, so none
482
499
  // migrate; the server drops a stale browser_viewers an earlier build of this version left, so none lingers beside it.
483
500
  // An earlier build of this version made no one-answer index on commands (schema.ts COMMANDS_ONE_ANSWER), or one that
@@ -514,6 +531,13 @@ export async function openSqliteStore(options) {
514
531
  { sql: COMPUTER_INTERVALS_RUN },
515
532
  // Nor any claim's turn and attempt (schema.ts RUN_ATTEMPTS): a claim made before it has no row.
516
533
  { sql: RUN_ATTEMPTS },
534
+ // Nor any learning ledger (schema.ts LEARNING_LEDGER, LEARNING_SPEND): a run that ended before it has no row, and
535
+ // its reader records it from its run row.
536
+ { sql: LEARNING_LEDGER },
537
+ { sql: LEARNING_LEDGER_AGENT },
538
+ { sql: LEARNING_SPEND },
539
+ { sql: LEARNING_SPEND_AGENT },
540
+ { sql: LEARNING_SPEND_OF_RUN },
517
541
  { sql: NATIVE_COMMANDS_INDEX },
518
542
  ], { full: true });
519
543
  // A computer_intervals an earlier build of this version made has no disk or booked time (schema.ts
@@ -624,6 +648,12 @@ export function storeOver(connection, now, file) {
624
648
  /** How long a purge's checkpoint waits for another connection's reader or writer before it leaves the log to the next
625
649
  * start's scrub: short, since every other request of the store's connection queues behind it. */
626
650
  const PURGE_CHECKPOINT_BUSY_MS = 20;
651
+ /** Run `runId`'s learning ledger (learn/ledger.ts), gone: its row, each spend row it booked, and an audit's spend row of
652
+ * it (its shadow's, of_run). What a run's purge (Runs.purge) and its delete (Runs.remove) both drop. */
653
+ async function dropLedger(tx, runId) {
654
+ await tx.run("DELETE FROM learning_ledger WHERE run_id = ?", runId);
655
+ await tx.run("DELETE FROM learning_spend WHERE run_id = ? OR of_run = ?", runId, runId);
656
+ }
627
657
  /** A run's content in every table that keeps it by the run's id, gone: what a run's purge (Runs.purge) and its delete
628
658
  * (Runs.remove) both drop. A table added for a run's content goes here, so neither path leaves it behind. */
629
659
  async function dropRunContent(tx, runId) {
@@ -707,6 +737,8 @@ class SqliteStore {
707
737
  where;
708
738
  /** The deadlines' clock now (fence.ts storeNow): the database's on Postgres, this store's clock bound on SQLite. */
709
739
  #clock;
740
+ /** Store.leaseClock: this store's clock when the deadlines are stamped on it (no database clock: SQLite, or a test's). */
741
+ leaseClock;
710
742
  /** Each claim's one journal, until it is closed. */
711
743
  #journals = new Map();
712
744
  /** Each run's claim this store released last (its epoch): journal() refuses that claim, or an older one, rather than
@@ -730,6 +762,8 @@ class SqliteStore {
730
762
  const d = db.dialect;
731
763
  const clock = () => storeNow(d, now);
732
764
  this.#clock = clock;
765
+ if (!d.nowSql)
766
+ this.leaseClock = now;
733
767
  const insertAgent = (tx, agent, at) => tx.run("INSERT INTO agents (id, name, description, created_at) VALUES (?, ?, ?, ?)", agent.id, agent.name, agent.description ?? null, at);
734
768
  /** Agent `agentId`'s row, held (a writer's row lock, as its purge takes it), or undefined when there is none; refused
735
769
  * (AgentPurged) once it is purged: a write that waited on the purge's lock reads its purge time, and one that took the
@@ -910,6 +944,8 @@ class SqliteStore {
910
944
  if (left.length)
911
945
  throw new TriggersLeft(agentId, left.map((one) => one.id));
912
946
  await tx.run("DELETE FROM learning_proposals WHERE agent_id = ?", agentId);
947
+ await tx.run("DELETE FROM learning_ledger WHERE agent_id = ?", agentId);
948
+ await tx.run("DELETE FROM learning_spend WHERE agent_id = ?", agentId);
913
949
  await dropAgentPrivate(tx, agentId);
914
950
  // Its revisions in one statement (a revision's parent is the same agent's, checked at the statement's end), the
915
951
  // agent's pointer at its current one cleared first.
@@ -1087,6 +1123,8 @@ class SqliteStore {
1087
1123
  return undefined;
1088
1124
  if (change.startByWas !== undefined && !(was.status === "sent" && was.run_id === null && was.retry_at === change.startByWas))
1089
1125
  return undefined;
1126
+ if (change.noRun && was.run_id !== null)
1127
+ return undefined;
1090
1128
  const settled = change.status !== undefined && change.status !== "due";
1091
1129
  // Out of due, a firing keeps no retry, wait, payload or attrs (unless keepAttrs), nor the reason its last try gave
1092
1130
  // (unless it gives one). One exception: a sent firing keeps its startBy in retry_at (firingOf reads it back as
@@ -1252,8 +1290,21 @@ class SqliteStore {
1252
1290
  return runOf(row);
1253
1291
  })),
1254
1292
  };
1293
+ /** Firing `firing` started with run `runId`, in the run's own transaction, under its trigger's row lock (as settle
1294
+ * takes it): only while it has no run and is due, or sent with a start_by (its host took it); else FiringMoved,
1295
+ * which rolls the run back. Its trigger's last run and failure streak move as a started firing's do (settle). */
1296
+ const startFiring = async (tx, { triggerId, key }, runId, at) => {
1297
+ await d.lockRow(tx, "triggers", "id", triggerId);
1298
+ const moved = await tx.runCounted("UPDATE trigger_firings SET status = 'started', run_id = ?, retry_at = NULL, waits_on = NULL, payload = NULL, attrs = NULL, reason = NULL, attempts = 0 WHERE trigger_id = ? AND key = ? AND run_id IS NULL AND (status = 'due' OR (status = 'sent' AND retry_at IS NOT NULL))", runId, triggerId, key);
1299
+ if (moved === 0)
1300
+ throw new FiringMoved(triggerId, key);
1301
+ const trigger = await tx.get("SELECT last_run_id FROM triggers WHERE id = ?", triggerId);
1302
+ // Run ids are UUIDv7s, sorted by when the run started: an older run never takes a later one's place (settle).
1303
+ const last = trigger?.last_run_id && trigger.last_run_id > runId ? trigger.last_run_id : runId;
1304
+ await tx.run("UPDATE triggers SET last_run_id = ?, failures_in_a_row = 0, updated_at = ? WHERE id = ?", last, at, triggerId);
1305
+ };
1255
1306
  this.runs = {
1256
- create: async ({ id, agentId, revisionId, origin, labels, expectedCurrent, settingsGuards, startedAt }, launch) => {
1307
+ create: async ({ id, agentId, revisionId, origin, labels, expectedCurrent, settingsGuards, startedAt, firing }, launch) => {
1257
1308
  // sign_in_handed is not written here: the runner writes it at its claim (runs.update under the epoch fence).
1258
1309
  const insert = `INSERT INTO runs (id, agent_id, revision_id, state, epoch, labels, disk, started_at) VALUES (?, ?, ?, 'queued', 0, ?, ?, ?) RETURNING ${RUN_COLUMNS}`;
1259
1310
  const labelled = labelsColumn(labels);
@@ -1279,6 +1330,8 @@ class SqliteStore {
1279
1330
  await tx.run("INSERT INTO run_origins (key, run_id, fingerprint, created_at) VALUES (?, ?, ?, ?)", origin.key, id, origin.fingerprint ?? null, at);
1280
1331
  if (launch)
1281
1332
  await writeLaunch(tx, id, launch, at);
1333
+ if (firing)
1334
+ await startFiring(tx, firing, id, at);
1282
1335
  return runOf(row);
1283
1336
  }));
1284
1337
  },
@@ -1353,7 +1406,7 @@ class SqliteStore {
1353
1406
  },
1354
1407
  // A list's page from the rows alone: filtered, ordered and cut to the page in the query, one read whatever the number
1355
1408
  // of runs, each row with its listing (schema.ts RUN_LISTING_COLUMNS) and its agent's archive time.
1356
- listed: async ({ agentId, revisionId, labels, archived, status, going, after, limit, offset = 0 }) => {
1409
+ listed: async ({ agentId, revisionId, labels, source, archived, status, going, after, limit, offset = 0 }) => {
1357
1410
  const n = clock();
1358
1411
  const behind = listingBehind(n.sql);
1359
1412
  // Neither a built-in learning run nor an audit's shadow run (learn/audit.ts SHADOW_PREFIX, matched as it is, case and all).
@@ -1365,6 +1418,10 @@ class SqliteStore {
1365
1418
  (where.push("runs.revision_id = ?"), params.push(revisionId));
1366
1419
  for (const [key, value] of Object.entries(labels ?? {}))
1367
1420
  (where.push(d.jsonObjectHas("runs.labels")), params.push(key, value));
1421
+ if (source === "live")
1422
+ where.push("runs.imported_from IS NULL");
1423
+ else if (source !== undefined)
1424
+ (where.push(`${d.jsonText("runs.imported_from", ["source"])} = ?`), params.push(source));
1368
1425
  where.push(`COALESCE(runs.archived_at, agents.archived_at) IS ${archived ? "NOT NULL" : "NULL"}`, "runs.purged_at IS NULL");
1369
1426
  if (status !== undefined)
1370
1427
  (where.push("runs.list_status = ?"), params.push(status));
@@ -1420,11 +1477,14 @@ class SqliteStore {
1420
1477
  healCost: async (runId, { epoch, endedAt }, { costUsd, costUpperBound }) => {
1421
1478
  if (!Number.isFinite(costUsd) || costUsd < 0)
1422
1479
  throw new TypeError(`a healed cost is a figure of $0 or more (got ${costUsd})`);
1423
- const [result] = await db.write([{
1424
- sql: `UPDATE runs SET cost_usd = ?, cost_upper_bound = ? WHERE id = ? AND ${COST_UNKNOWN} AND epoch = ? AND ended_at = ? RETURNING id`,
1425
- params: [costUsd, costUpperBound ? 1 : 0, runId, epoch, endedAt],
1426
- }]);
1427
- return (result?.rows.length ?? 0) > 0;
1480
+ // Its ledger row is recorded again with it, in the same transaction: the job's cost it reads is the healed one.
1481
+ return db.transaction(async (tx) => {
1482
+ const row = await tx.get(`UPDATE runs SET cost_usd = ?, cost_upper_bound = ? WHERE id = ? AND ${COST_UNKNOWN} AND epoch = ? AND ended_at = ? RETURNING ${RUN_COLUMNS}`, costUsd, costUpperBound ? 1 : 0, runId, epoch, endedAt);
1483
+ if (!row)
1484
+ return false;
1485
+ await recordLedger(tx, runOf(row), now());
1486
+ return true;
1487
+ });
1428
1488
  },
1429
1489
  // The runs healCost may write that the heal's rule (store-view.ts bookedCostOf, healOf) does not refuse by its
1430
1490
  // columns alone, so the start sweep never reads one that cannot heal again at each start: left out are a person's
@@ -1507,6 +1567,9 @@ class SqliteStore {
1507
1567
  const state = JSON.parse(row.proposal)?.state;
1508
1568
  await tx.run("UPDATE learning_proposals SET turn = '{}', proposal = ? WHERE run_id = ? AND round = ?", json(typeof state === "string" ? { state } : {}), runId, row.round);
1509
1569
  }
1570
+ // Its ledger row and every spend row it booked or that audits it, as a remove takes them: what it cost stays on its
1571
+ // tombstone (cost_usd, the metrics' figures), which the readers of money (usage, stats) read; no series shows it.
1572
+ await dropLedger(tx, runId);
1510
1573
  // Its row's content, its metrics cut to their figures and names (tombstoneMetrics), with what its spend's readers
1511
1574
  // read from its journal folded in. Its outcome stays: a code (RunOutcome), never words.
1512
1575
  const metrics = tombstoneMetrics(run.metrics === null ? null : JSON.parse(run.metrics), kept);
@@ -1526,6 +1589,8 @@ class SqliteStore {
1526
1589
  throw new StoreConstraint(`run ${runId} is ${run.state}: only a final run is removed`);
1527
1590
  await dropRunContent(tx, runId);
1528
1591
  await tx.run("DELETE FROM learning_proposals WHERE run_id = ?", runId);
1592
+ // Its ledger row and every spend row it booked or that audits it, as a purge takes them.
1593
+ await dropLedger(tx, runId);
1529
1594
  // Its computers' usage, which a purge keeps (figures, no words).
1530
1595
  await tx.run("DELETE FROM computer_intervals WHERE run_id = ?", runId);
1531
1596
  await tx.run("DELETE FROM runs WHERE id = ?", runId);
@@ -1576,9 +1641,11 @@ class SqliteStore {
1576
1641
  await d.lockRow(tx, "runs", "id", id, "update");
1577
1642
  const at = now();
1578
1643
  const n = storeNow(d, () => at);
1579
- 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);
1644
+ 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 ${RUN_COLUMNS}`, summary, at, ...n.params, id);
1580
1645
  if (!row)
1581
1646
  return false;
1647
+ // Its ledger row, as an end writes one (applyRunPatch).
1648
+ await recordLedger(tx, runOf(row), at);
1582
1649
  // As an end does: its untaken commands refused, its launch's secrets erased, in this same commit.
1583
1650
  await refuseLeftovers(tx, id, "failed", at, d);
1584
1651
  return true;
@@ -1616,7 +1683,7 @@ class SqliteStore {
1616
1683
  }
1617
1684
  }
1618
1685
  // An update that made the run final: its other untaken rows are refused in this transaction, after its own takes.
1619
- await refuseLeftovers(tx, claim.runId, patch.state, at, d, patch.keepsEnd === true);
1686
+ await refuseLeftovers(tx, claim.runId, patch.state, at, d, patch.keepsEnd === true, patch.census);
1620
1687
  // The bind's save lease, in this same transaction as the sign_in_handed write just made (applyRunPatch, under
1621
1688
  // SIGN_IN_HANDED_LOCK): this run saves unless another run already holds one of the handed pointers (a running run,
1622
1689
  // or — within signInSettleMs of leaving running, a vendor's settle window — one that left running less than that
@@ -1898,6 +1965,32 @@ class SqliteStore {
1898
1965
  return kept?.state === "proposed" ? [] : [{ agentId: row.agent_id, at: row.created_at, costUsd: 0 }];
1899
1966
  });
1900
1967
  },
1968
+ ledger: async (agentId, runIds) => {
1969
+ if (runIds !== undefined && runIds.length === 0)
1970
+ return { rows: [], spend: [] };
1971
+ const list = runIds === undefined ? "" : runIds.map(() => "?").join(", ");
1972
+ const rowsOf = runIds === undefined ? { sql: "", params: [] } : { sql: ` AND run_id IN (${list})`, params: [...runIds] };
1973
+ const spendOf = runIds === undefined ? { sql: "", params: [] } : { sql: ` AND (run_id IN (${list}) OR of_run IN (${list}))`, params: [...runIds, ...runIds] };
1974
+ const text = "CAST(NULL AS TEXT)", whole = "CAST(NULL AS BIGINT)", usd = "CAST(NULL AS DOUBLE PRECISION)";
1975
+ const parts = await db.all(`SELECT 'row' AS part, run_id, agent_id, started_at, path, workflow, digest, not_served, job_usd, look_back_usd, cost, epoch, ${text} AS kind, ${whole} AS round, ${text} AS of_run, ${usd} AS usd
1976
+ FROM learning_ledger WHERE agent_id = ?${rowsOf.sql}
1977
+ UNION ALL
1978
+ SELECT 'spend' AS part, run_id, agent_id, ${whole}, ${text}, workflow, digest, ${text}, ${usd}, ${usd}, ${text}, ${whole}, kind, round, of_run, usd
1979
+ FROM learning_spend WHERE agent_id = ?${spendOf.sql}`, agentId, ...rowsOf.params, agentId, ...spendOf.params);
1980
+ const usdOf = (value) => (value === null ? null : Number(value));
1981
+ const rows = parts.filter((one) => one.part === "row").map((row) => ({
1982
+ runId: row.run_id, agentId: row.agent_id, startedAt: Number(row.started_at), path: row.path, workflow: row.workflow, digest: row.digest,
1983
+ notServed: row.not_served, jobUsd: usdOf(row.job_usd), lookBackUsd: usdOf(row.look_back_usd), cost: row.cost, epoch: Number(row.epoch),
1984
+ }));
1985
+ const spend = parts.filter((one) => one.part === "spend").map((row) => ({
1986
+ runId: row.run_id, round: Number(row.round), agentId: row.agent_id, kind: row.kind, ofRun: row.of_run, workflow: row.workflow, digest: row.digest, usd: usdOf(row.usd),
1987
+ }));
1988
+ const byText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
1989
+ return {
1990
+ rows: rows.sort((a, b) => a.startedAt - b.startedAt || byText(a.runId, b.runId)),
1991
+ spend: spend.sort((a, b) => byText(a.runId, b.runId) || byText(a.kind, b.kind) || a.round - b.round),
1992
+ };
1993
+ },
1901
1994
  };
1902
1995
  this.settings = {
1903
1996
  get: async (key) => {
@@ -2,6 +2,7 @@ import type { Context } from "@earendil-works/chord/context";
2
2
  import type { Storage, StorageWrite } from "@earendil-works/pi-durable";
3
3
  import type { JournalPage } from "./journal/storage.js";
4
4
  import type { MonidPinBody } from "./agent-body.js";
5
+ import type { LedgerRow, SpendRow } from "../learn/ledger.js";
5
6
  /** A run's state. queued: a row, no runner yet. running: a runner holds the claim. parked: waiting for a person (an
6
7
  * approval, a raised cap) with no claim held; a command row or its wake_at makes it claimable again. ended, stopped and
7
8
  * failed are final. A running run whose runner died is claimable once its claim runs out. */
@@ -163,6 +164,8 @@ export interface ListedFilter {
163
164
  readonly agentId?: string;
164
165
  readonly revisionId?: string;
165
166
  readonly labels?: RunLabels;
167
+ /** Only runs imported from this source (imported_from.source), or with "live" the runs not imported. */
168
+ readonly source?: string;
166
169
  readonly archived: boolean;
167
170
  readonly status?: string;
168
171
  /** Only runs still going (no settled status on the row) whose listing is behind. */
@@ -314,6 +317,13 @@ export interface RunPatch {
314
317
  * cancel waiting at its commit cut the look-back, never the job's end, and is refused (refuseLeftovers), unless a
315
318
  * person's message waits too: that message's run is the one they stop or cancel. */
316
319
  readonly keepsEnd?: boolean;
320
+ /** A final patch's census (run-census.ts): where in the run's files the secrets its launch holds sit, made under the
321
+ * launch's `sealed` bytes as they were then. The end that erases them writes it as the launch's census when its sealed
322
+ * bytes are still those, else the marker "unscanned" (refuseLeftovers), as it does for an end with none. */
323
+ readonly census?: {
324
+ readonly json: string;
325
+ readonly sealed: Uint8Array;
326
+ };
317
327
  }
318
328
  /** The row runs.update answers. When the patch wrote `signInHanded` (the runner's bind at its claim), `save` rides with it:
319
329
  * whether this run holds the sign-in's save lease — true unless another run already holds one of the handed pointers,
@@ -331,12 +341,24 @@ export interface RunLaunchInput {
331
341
  readonly body: unknown;
332
342
  readonly sealed?: Uint8Array | null;
333
343
  }
344
+ /** The census a launch takes when sealed bytes are first written on it (RunLaunchRow.census): it holds secrets its caller
345
+ * handed it, and no end has counted where they sit. An end erases them and writes its census in its place; an end that
346
+ * wrote none (a runner from before the census, during a rolling deploy) leaves it, and an ended run's files under it are
347
+ * withheld from a cut read, as under CENSUS_UNSCANNED. */
348
+ export declare const CENSUS_PENDING: string;
349
+ /** The census an end that erased a launch's sealed bytes writes when it has none made under them (RunLaunchRow.census), and
350
+ * a message's seal writes over CENSUS_PENDING left by such an end: what the run was handed may be in its files, and
351
+ * nothing says where. */
352
+ export declare const CENSUS_UNSCANNED: string;
334
353
  /** A run's launch as the store holds it: the body the runner reads at its claim, and its sealed bytes, which the store never
335
- * opens. */
354
+ * opens. `census`: null when its launch never held sealed bytes (none handed, or a run ended before the census was kept);
355
+ * CENSUS_PENDING from when they were first written until an end counted them; then the JSON text the last end that
356
+ * erased them wrote (RunPatch.census, run-census.ts), or CENSUS_UNSCANNED when that end had none made under them. */
336
357
  export interface RunLaunchRow {
337
358
  readonly runId: string;
338
359
  readonly body: unknown;
339
360
  readonly sealed: Uint8Array | null;
361
+ readonly census: string | null;
340
362
  readonly createdAt: number;
341
363
  }
342
364
  /** A message's new launch secrets (runs.command, runs.reopen): `launchSealed` replaces the run's launch `sealed` in the
@@ -447,6 +469,17 @@ export interface Learning {
447
469
  from: number;
448
470
  to: number;
449
471
  }): Promise<LearningSpend[]>;
472
+ /** Agent `agentId`'s ledger (learn/ledger.ts), in one read (one snapshot of both tables): every run's row its end
473
+ * recorded, oldest first, each with the end it was recorded for (`epoch`, its run's epoch then), and every spend row.
474
+ * With `runIds`, those runs' rows alone and the spend rows they booked or that audit them (none for none). Written
475
+ * only beside a run's end and a heal of its cost (run-patch.ts recordLedger); a purge or a delete of the run takes its
476
+ * row and its spend. */
477
+ ledger(agentId: string, runIds?: readonly string[]): Promise<{
478
+ rows: (LedgerRow & {
479
+ readonly epoch: number;
480
+ })[];
481
+ spend: SpendRow[];
482
+ }>;
450
483
  }
451
484
  /** One run's learning end as GET /usage's learning meter counts it (Learning.spend). */
452
485
  export interface LearningSpend {
@@ -745,6 +778,10 @@ export interface FiringChange {
745
778
  * transaction: a host start that pushed a startBy out and wrote no run puts it back (triggers.ts handedStart), unless
746
779
  * its run started, or another start moved it, meanwhile. */
747
780
  readonly startByWas?: number;
781
+ /** Written only while the firing has no run, read in the settle's own transaction (with `from`, a firing's start by a
782
+ * run written apart from it, triggers.ts handedRan): one a release failed, or another run started, meanwhile is left
783
+ * as it is. */
784
+ readonly noRun?: true;
748
785
  }
749
786
  /** What a settle does to the firing's trigger besides: `reset` its failure streak (a run started, a message sent), or
750
787
  * count a `failure` toward it, turning it off at `pauseAt` in a row (auto-pause, the firing marked paused). */
@@ -1020,7 +1057,10 @@ export interface Runs {
1020
1057
  * `expectedCurrent` checks the agent's current revision under its lock (RevisionMoved on mismatch); this is separate
1021
1058
  * from the pinned revisionId. Settings guards are locked before the agent. Refusal writes no run, origin or launch.
1022
1059
  * `startedAt` (ms) is when the run began, for one reported after it began elsewhere (a backend SDK run's
1023
- * `started_at`); absent, now. */
1060
+ * `started_at`); absent, now. With `firing` (a launch hook's host starting the firing it was handed), that firing is
1061
+ * started with the run in the same transaction, its trigger's last run and failure streak as a started firing's
1062
+ * are, only while it has no run and is still due or sent with a start_by: any other (released, failed, settled) is
1063
+ * refused (FiringMoved), and nothing is written. */
1024
1064
  create(run: {
1025
1065
  id: string;
1026
1066
  agentId: string;
@@ -1030,6 +1070,10 @@ export interface Runs {
1030
1070
  expectedCurrent?: string | null;
1031
1071
  settingsGuards?: readonly SettingsGuard[];
1032
1072
  startedAt?: number;
1073
+ firing?: {
1074
+ triggerId: string;
1075
+ key: string;
1076
+ };
1033
1077
  }, launch?: RunLaunchInput): Promise<RunRow>;
1034
1078
  /** A run whose agent is given inline and mapped to a source system by `agent.ref` and `revision.version`. In one
1035
1079
  * transaction: the agent (one per `ref`, written on its first run, its name and description brought up to the version
@@ -2111,6 +2155,11 @@ export interface Store {
2111
2155
  /** Reads the store's schema version and its runner floor now, without a lock or a write: a runner reads it at each
2112
2156
  * renewal (runner/main.ts), and stops once the floor is above the version its build knows. */
2113
2157
  schemaState?(): Promise<StoreSchemaState>;
2158
+ /** The clock a claim's lease is judged and stamped on (its `until`), when it is this process's own: the store's clock on
2159
+ * SQLite (one host), or a test's. A runner reckons a claim's deadline from its `until` on it, so a claim or renew that
2160
+ * waited for the writer lock keeps the lease the store granted from the lock. Absent when the lease is the database's
2161
+ * clock (Postgres), which this process cannot read: the runner reckons from when it asked. */
2162
+ readonly leaseClock?: () => number;
2114
2163
  /** Claims the run for `runner` until now + `leaseMs`: the run's epoch + 1 when it is claimable (runs.claimable); null when
2115
2164
  * another claim holds it, or it is final, or parked with nothing to wake it. A queued or parked run becomes running. */
2116
2165
  claim(runId: string, runner: string, options?: {
@@ -2322,6 +2371,12 @@ export declare class RunsMadeFromLeft extends StoreConstraint {
2322
2371
  readonly runs: readonly string[];
2323
2372
  constructor(runId: string, runs: readonly string[]);
2324
2373
  }
2374
+ /** A run's firing (Runs.create `firing`) that no longer takes it: no longer due or sent with a start_by, or it has a run. */
2375
+ export declare class FiringMoved extends Error {
2376
+ readonly triggerId: string;
2377
+ readonly key: string;
2378
+ constructor(triggerId: string, key: string);
2379
+ }
2325
2380
  /** A run made from a purged run (its launch's `replay.of` or `audit.of` names it): refused, nothing written. Its source's
2326
2381
  * input is gone, and a copy of it is never made again (Runs.create). `runId`: the purged run. */
2327
2382
  export declare class RunPurged extends Error {
@@ -30,6 +30,15 @@ export function tombstoneMetrics(metrics, kept) {
30
30
  out.purged = kept;
31
31
  return out;
32
32
  }
33
+ /** The census a launch takes when sealed bytes are first written on it (RunLaunchRow.census): it holds secrets its caller
34
+ * handed it, and no end has counted where they sit. An end erases them and writes its census in its place; an end that
35
+ * wrote none (a runner from before the census, during a rolling deploy) leaves it, and an ended run's files under it are
36
+ * withheld from a cut read, as under CENSUS_UNSCANNED. */
37
+ export const CENSUS_PENDING = JSON.stringify("pending");
38
+ /** The census an end that erased a launch's sealed bytes writes when it has none made under them (RunLaunchRow.census), and
39
+ * a message's seal writes over CENSUS_PENDING left by such an end: what the run was handed may be in its files, and
40
+ * nothing says where. */
41
+ export const CENSUS_UNSCANNED = JSON.stringify("unscanned");
33
42
  /** A firing a trigger has no room for: `due` firings are DUE_KEPT already. Nothing was written. */
34
43
  export class TriggerFull extends Error {
35
44
  triggerId;
@@ -308,6 +317,17 @@ export class RunsMadeFromLeft extends StoreConstraint {
308
317
  this.name = "RunsMadeFromLeft";
309
318
  }
310
319
  }
320
+ /** A run's firing (Runs.create `firing`) that no longer takes it: no longer due or sent with a start_by, or it has a run. */
321
+ export class FiringMoved extends Error {
322
+ triggerId;
323
+ key;
324
+ constructor(triggerId, key) {
325
+ super(`firing ${key} of trigger ${triggerId} no longer takes a run: nothing was written`);
326
+ this.triggerId = triggerId;
327
+ this.key = key;
328
+ this.name = "FiringMoved";
329
+ }
330
+ }
311
331
  /** A run made from a purged run (its launch's `replay.of` or `audit.of` names it): refused, nothing written. Its source's
312
332
  * input is gone, and a copy of it is never made again (Runs.create). `runId`: the purged run. */
313
333
  export class RunPurged extends Error {