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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +230 -120
  3. package/dist/acp-package.d.ts +4 -0
  4. package/dist/agent-delete.d.ts +6 -9
  5. package/dist/agent-delete.js +5 -3
  6. package/dist/agent-package.js +11 -1
  7. package/dist/api-only.d.ts +21 -3
  8. package/dist/api-only.js +41 -6
  9. package/dist/archil-routes.d.ts +4 -1
  10. package/dist/archil-routes.js +15 -12
  11. package/dist/archil-settings.d.ts +18 -8
  12. package/dist/archil-settings.js +35 -17
  13. package/dist/browser-person.d.ts +1 -1
  14. package/dist/browser-person.js +1 -1
  15. package/dist/calendar/tools.js +1 -1
  16. package/dist/chatgpt-plan.d.ts +4 -2
  17. package/dist/chatgpt-plan.js +13 -3
  18. package/dist/claude-login-token.d.ts +5 -0
  19. package/dist/claude-login-token.js +8 -0
  20. package/dist/claude-login.d.ts +49 -3
  21. package/dist/claude-login.js +140 -10
  22. package/dist/cli-learning/connections.js +1 -1
  23. package/dist/cli.js +42 -10
  24. package/dist/console/assets/{backend-BztxEAvb.js → backend-C9ffXUR5.js} +1 -1
  25. package/dist/console/assets/index-BnZV3lvW.js +639 -0
  26. package/dist/console/assets/{share-L84tlUDW.js → share-B1o5mJ56.js} +2 -2
  27. package/dist/console/assets/{styles-CaRKlHke.js → styles-D_znYrHR.js} +31 -31
  28. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  29. package/dist/console/index.html +3 -3
  30. package/dist/console/share.html +3 -3
  31. package/dist/decisions.d.ts +1 -1
  32. package/dist/decisions.js +2 -2
  33. package/dist/errors.d.ts +1 -0
  34. package/dist/errors.js +2 -0
  35. package/dist/factory-activity.d.ts +68 -0
  36. package/dist/factory-activity.js +153 -0
  37. package/dist/factory-runs.d.ts +11 -0
  38. package/dist/factory-runs.js +52 -0
  39. package/dist/filed-tool.d.ts +32 -0
  40. package/dist/filed-tool.js +122 -0
  41. package/dist/harness-check.js +2 -1
  42. package/dist/harness-keys.d.ts +1 -2
  43. package/dist/harness-keys.js +1 -2
  44. package/dist/harness-recipe.d.ts +13 -2
  45. package/dist/harness-recipe.js +30 -7
  46. package/dist/harness-sign-in.js +2 -1
  47. package/dist/harness-table.d.ts +9 -3
  48. package/dist/harness-table.js +11 -5
  49. package/dist/harness.js +6 -2
  50. package/dist/import-worker.js +2 -2
  51. package/dist/import.d.ts +9 -0
  52. package/dist/import.js +11 -1
  53. package/dist/key-refusal.d.ts +5 -0
  54. package/dist/key-refusal.js +30 -18
  55. package/dist/learn/audit.d.ts +20 -22
  56. package/dist/learn/audit.js +72 -55
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +35 -43
  59. package/dist/learn/commit.js +62 -270
  60. package/dist/learn/compile.d.ts +4 -4
  61. package/dist/learn/compile.js +6 -7
  62. package/dist/learn/corrections.js +1 -1
  63. package/dist/learn/delete.d.ts +5 -12
  64. package/dist/learn/delete.js +17 -30
  65. package/dist/learn/forget-run.d.ts +16 -0
  66. package/dist/learn/forget-run.js +53 -0
  67. package/dist/learn/index.js +1 -1
  68. package/dist/learn/learning-of.d.ts +0 -4
  69. package/dist/learn/learning-of.js +0 -5
  70. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  71. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  72. package/dist/learn/legacy/place.d.ts +16 -0
  73. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  74. package/dist/learn/legacy/scrub.d.ts +28 -0
  75. package/dist/learn/legacy/scrub.js +258 -0
  76. package/dist/learn/promote.d.ts +40 -66
  77. package/dist/learn/promote.js +69 -207
  78. package/dist/learn/reset-ledger.d.ts +18 -0
  79. package/dist/learn/reset-ledger.js +14 -0
  80. package/dist/learn/rows.d.ts +186 -0
  81. package/dist/learn/rows.js +376 -0
  82. package/dist/learn/secrets.d.ts +2 -1
  83. package/dist/learn/secrets.js +2 -2
  84. package/dist/learn/workflow-draft.d.ts +4 -1
  85. package/dist/learn/workflow-draft.js +12 -2
  86. package/dist/learned-nodes.d.ts +36 -0
  87. package/dist/learned-nodes.js +23 -0
  88. package/dist/learning-reset.d.ts +1 -1
  89. package/dist/learning-reset.js +9 -11
  90. package/dist/learning-routes.d.ts +60 -81
  91. package/dist/learning-routes.js +187 -360
  92. package/dist/learning-words.d.ts +2 -0
  93. package/dist/learning-words.js +2 -0
  94. package/dist/learning.d.ts +18 -24
  95. package/dist/learning.js +35 -66
  96. package/dist/local-model.d.ts +144 -0
  97. package/dist/local-model.js +214 -0
  98. package/dist/mcp-gateway.d.ts +6 -0
  99. package/dist/mcp-gateway.js +44 -8
  100. package/dist/mcp-probe.d.ts +7 -0
  101. package/dist/mcp-probe.js +7 -0
  102. package/dist/mcp-resources.d.ts +1 -1
  103. package/dist/native/discovery.d.ts +6 -0
  104. package/dist/native/discovery.js +14 -1
  105. package/dist/native/remote.d.ts +5 -0
  106. package/dist/native/remote.js +16 -0
  107. package/dist/native/runtime.js +3 -2
  108. package/dist/observation/observer.d.ts +6 -6
  109. package/dist/ollama-provider.d.ts +35 -0
  110. package/dist/ollama-provider.js +108 -2
  111. package/dist/openapi.js +147 -35
  112. package/dist/place-offers.d.ts +3 -0
  113. package/dist/place-offers.js +3 -0
  114. package/dist/place.d.ts +35 -12
  115. package/dist/place.js +67 -29
  116. package/dist/print.js +1 -1
  117. package/dist/purged-workflow.d.ts +0 -33
  118. package/dist/purged-workflow.js +3 -71
  119. package/dist/redact/match.d.ts +36 -8
  120. package/dist/redact/match.js +179 -44
  121. package/dist/run-export.js +4 -2
  122. package/dist/run-launch.d.ts +3 -3
  123. package/dist/run-learning-served.d.ts +3 -3
  124. package/dist/run-learning-served.js +1 -1
  125. package/dist/run-listing.d.ts +1 -1
  126. package/dist/run-timeline-served.d.ts +1 -1
  127. package/dist/run-timeline-served.js +6 -5
  128. package/dist/run-usage.js +3 -2
  129. package/dist/runnable.js +25 -8
  130. package/dist/runner/adapter-loop.d.ts +8 -1
  131. package/dist/runner/adapter-loop.js +100 -20
  132. package/dist/runner/adapter-run-spec.d.ts +3 -5
  133. package/dist/runner/adapter-run-spec.js +35 -61
  134. package/dist/runner/adapters/pi.d.ts +3 -2
  135. package/dist/runner/adapters/pi.js +3 -1
  136. package/dist/runner/audit.d.ts +3 -5
  137. package/dist/runner/audit.js +28 -51
  138. package/dist/runner/cli-run-spec.js +19 -22
  139. package/dist/runner/compare-end.d.ts +1 -3
  140. package/dist/runner/compare-end.js +6 -2
  141. package/dist/runner/disk-free.d.ts +15 -4
  142. package/dist/runner/disk-free.js +25 -7
  143. package/dist/runner/dispatch.js +2 -2
  144. package/dist/runner/feedback-round.d.ts +1 -1
  145. package/dist/runner/feedback-round.js +2 -2
  146. package/dist/runner/harness-loops.d.ts +9 -0
  147. package/dist/runner/harness-loops.js +49 -7
  148. package/dist/runner/held.d.ts +4 -11
  149. package/dist/runner/held.js +0 -25
  150. package/dist/runner/journal-kinds.d.ts +4 -1
  151. package/dist/runner/journal-kinds.js +1 -1
  152. package/dist/runner/learned-first.d.ts +0 -2
  153. package/dist/runner/learned-first.js +3 -3
  154. package/dist/runner/learning-end.d.ts +12 -16
  155. package/dist/runner/learning-end.js +41 -75
  156. package/dist/runner/learning-seed.d.ts +13 -16
  157. package/dist/runner/learning-seed.js +13 -23
  158. package/dist/runner/live-ticker.js +3 -4
  159. package/dist/runner/main.js +1 -1
  160. package/dist/runner/mcp-claim.js +3 -2
  161. package/dist/runner/mcp-run.d.ts +23 -4
  162. package/dist/runner/mcp-run.js +31 -2
  163. package/dist/runner/metrics.d.ts +4 -0
  164. package/dist/runner/metrics.js +9 -3
  165. package/dist/runner/monid-run.js +3 -1
  166. package/dist/runner/native-loop.js +3 -4
  167. package/dist/runner/promotion.d.ts +19 -28
  168. package/dist/runner/promotion.js +50 -69
  169. package/dist/runner/redact.d.ts +3 -0
  170. package/dist/runner/redact.js +7 -0
  171. package/dist/runner/reflect-hook.d.ts +2 -2
  172. package/dist/runner/reflect-hook.js +4 -1
  173. package/dist/runner/run-child-host.d.ts +1 -9
  174. package/dist/runner/run-child-host.js +12 -68
  175. package/dist/runner/runner.d.ts +1 -1
  176. package/dist/runner/sdk-loop.js +7 -7
  177. package/dist/runner/workflow-calls.d.ts +4 -1
  178. package/dist/runner/workflow-calls.js +35 -18
  179. package/dist/runner/workflow-loop.d.ts +1 -1
  180. package/dist/runner/workflow-loop.js +3 -1
  181. package/dist/runner/workflow-spec.d.ts +4 -0
  182. package/dist/runner/workflow-spec.js +18 -13
  183. package/dist/runs-over-store.d.ts +2 -2
  184. package/dist/runs-over-store.js +1 -1
  185. package/dist/sdk/check.d.ts +1 -4
  186. package/dist/sdk/check.js +2 -3
  187. package/dist/sdk/runs.d.ts +20 -7
  188. package/dist/sdk/runs.js +105 -68
  189. package/dist/secret-cut.js +7 -4
  190. package/dist/secret-rules.js +97 -83
  191. package/dist/secrets.d.ts +4 -0
  192. package/dist/secrets.js +44 -10
  193. package/dist/server-fs.d.ts +1 -1
  194. package/dist/server-fs.js +1 -1
  195. package/dist/server-keys.d.ts +6 -0
  196. package/dist/server-keys.js +12 -0
  197. package/dist/server.d.ts +22 -15
  198. package/dist/server.js +311 -198
  199. package/dist/slack.js +2 -1
  200. package/dist/source-sync/auxiliary.js +2 -2
  201. package/dist/store/index.d.ts +1 -1
  202. package/dist/store/index.js +1 -1
  203. package/dist/store/postgres/migrate.js +3 -1
  204. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  205. package/dist/store/schema.d.ts +28 -2
  206. package/dist/store/schema.js +81 -5
  207. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  208. package/dist/store/sqlite/learning-rows.js +559 -0
  209. package/dist/store/sqlite/store.d.ts +7 -1
  210. package/dist/store/sqlite/store.js +84 -18
  211. package/dist/store/store.d.ts +219 -6
  212. package/dist/store/store.js +13 -0
  213. package/dist/store-reads/journal.d.ts +33 -3
  214. package/dist/store-reads/journal.js +99 -4
  215. package/dist/store-reads/learning.d.ts +23 -26
  216. package/dist/store-reads/learning.js +42 -30
  217. package/dist/store-reads/loop.js +1 -1
  218. package/dist/store-view.d.ts +24 -2
  219. package/dist/store-view.js +40 -11
  220. package/dist/templates.d.ts +10 -2
  221. package/dist/templates.js +31 -4
  222. package/dist/tool-plane.d.ts +27 -3
  223. package/dist/tool-plane.js +79 -4
  224. package/dist/tools.d.ts +12 -2
  225. package/dist/tools.js +42 -7
  226. package/dist/trigger-launch-hook.d.ts +2 -2
  227. package/dist/trigger-launch-hook.js +1 -1
  228. package/dist/triggers.d.ts +7 -4
  229. package/dist/triggers.js +4 -4
  230. package/dist/web-holds.d.ts +2 -0
  231. package/dist/web-holds.js +5 -2
  232. package/dist/web-run.js +2 -1
  233. package/dist/workspace/archil-exec.js +1 -1
  234. package/dist/workspace/archil.d.ts +1 -1
  235. package/dist/workspace/archil.js +1 -1
  236. package/dist/workspace/computer-deps.js +5 -3
  237. package/dist/workspace/computer-providers.d.ts +11 -1
  238. package/dist/workspace/computer-providers.js +29 -2
  239. package/dist/workspace/index.d.ts +1 -2
  240. package/dist/workspace/index.js +1 -2
  241. package/dist/workspace/paths.d.ts +0 -4
  242. package/dist/workspace/paths.js +0 -6
  243. package/dist/workspace/workspace.d.ts +1 -1
  244. package/dist/workspace/workspace.js +1 -1
  245. package/package.json +13 -13
  246. package/templates/TOOLS.md +46 -0
  247. package/dist/console/assets/index-LwNL4L9q.js +0 -619
  248. package/dist/console/assets/styles-DQo8rzY-.css +0 -1
  249. package/dist/workspace/learning-workspace.d.ts +0 -24
  250. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
package/dist/slack.js CHANGED
@@ -277,7 +277,8 @@ export function slackMessage(type, data, { agent, base }) {
277
277
  const lines = [
278
278
  `Trigger ${link(triggerUrl, name)} could not start its run${agent ? ` of ${who}` : ""}.`,
279
279
  `\`${esc(code || "error")}\`${message ? `: ${esc(message)}` : ""}`,
280
- ...(data.auto_paused === true ? ["It failed too many times in a row, so it is off now: turn it on again in the console."] : []),
280
+ // The console's way, the CLI's and the API's: a server with no console (the API-only profile) takes the last two.
281
+ ...(data.auto_paused === true ? [`It failed too many times in a row, so it is off now: turn it on again in the console, with \`agentrun triggers update ${esc(str(data.trigger_id))} --enabled\`, or with \`PATCH /v2/triggers/${esc(str(data.trigger_id))}\` and \`{"enabled": true}\`.`] : []),
281
282
  ];
282
283
  return {
283
284
  text: esc(`Trigger ${name} could not start its run${code ? `: ${code}` : ""}`),
@@ -1,7 +1,7 @@
1
1
  /** Host-only admission of learning work. Every auxiliary project is a fresh copy of its reserved revision, never the
2
2
  * served run's mutable files or private placement marker. Its execution settles without publishing project changes. */
3
3
  import { ApiError } from "../errors.js";
4
- import { withAgentRepo } from "../learning.js";
4
+ import { inLearningQueue } from "../learning.js";
5
5
  import { resetAtOf } from "../learn/promote.js";
6
6
  import { launchBody, readLaunchBody } from "../run-launch.js";
7
7
  import { withHeldFiles } from "../runs-over-store.js";
@@ -41,7 +41,7 @@ export function auxiliaryAdmitter(store, options) {
41
41
  return { run: existing, created: false };
42
42
  if (source && !options.project)
43
43
  throw refused("This auxiliary learning run needs project placement before it can start.");
44
- return withAgentRepo(options.data, agentId, async () => {
44
+ return inLearningQueue(options.data, agentId, async () => {
45
45
  const existing = await admitted();
46
46
  if (existing)
47
47
  return { run: existing, created: false };
@@ -1,4 +1,4 @@
1
- export { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, AnswerTaken, CENSUS_UNSCANNED, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, FiringMoved, Fenced, KEPT_PREFIX, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, RunPurged, RunnerBelowFloor, RUNNER_STALE_MS, RunsMadeFromLeft, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreAwaitsServer, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft, UPLOAD_PREFIX } from "./store.js";
1
+ export { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, AnswerTaken, CENSUS_UNSCANNED, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, FiringMoved, Fenced, KEPT_PREFIX, LearningRecordRefused, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, RunPurged, RunnerBelowFloor, RUNNER_STALE_MS, RunsMadeFromLeft, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreAwaitsServer, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft, UPLOAD_PREFIX } from "./store.js";
2
2
  export type { ConstraintRule, SettingsGuard, McpGuard, AgentRow, Agents, AlsoRow, AttemptCause, ChannelPost, Claim, Command, ComputerIntervalRow, ComputerIntervals, ComputerLedger, ComputerLedgerRow, Firing, FiringChange, FiringRow, FiringStatus, FiringStreak, Journal, Live, LiveRow, Mcp, McpCredentialMark, McpRemoved, McpOauth, McpOauthPendingRow, McpPinRow, McpTokensMark, McpOwnersMark, McpRewriteSeen, McpServerRow, McpServerStamp, McpServerWrite, MintedTokenRow, MintedTokens, NewFiring, NewPairedComputer, NewRevision, NewTrigger, PairedComputerRow, PairedComputers, ReleasedState, RevisionRow, RunAttemptRow, RunAttempts, RunnerRow, Runners, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, StoreSchemaState, 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, PurgeKept, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
3
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";
@@ -1,5 +1,5 @@
1
1
  // The one store (design 2.1), for the cutover: nothing on main imports it until then.
2
- export { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, AnswerTaken, CENSUS_UNSCANNED, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, FiringMoved, Fenced, KEPT_PREFIX, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, RunPurged, RunnerBelowFloor, RUNNER_STALE_MS, RunsMadeFromLeft, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreAwaitsServer, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft, UPLOAD_PREFIX } from "./store.js";
2
+ export { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, AnswerTaken, CENSUS_UNSCANNED, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, FiringMoved, Fenced, KEPT_PREFIX, LearningRecordRefused, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, RunPurged, RunnerBelowFloor, RUNNER_STALE_MS, RunsMadeFromLeft, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreAwaitsServer, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft, UPLOAD_PREFIX } 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";
@@ -174,8 +174,10 @@ export async function migrate(client, schema, at, migrations = migrationsIn()) {
174
174
  throw new SchemaVersionUnknown(placeOf(schema), top, known);
175
175
  for (const row of applied) {
176
176
  const mine = migrations[Number(row.version) - 1];
177
+ // Both files named, the schema's and this build's, so a migration renamed or renumbered on one side is plain.
177
178
  if (mine && mine.sha256 !== row.sha256) {
178
- throw new Error(`${placeOf(schema)} applied migration ${String(mine.version).padStart(4, "0")}_${mine.name}.sql with other text than this build's: an applied migration is never edited, a change is a new file`);
179
+ const file = (version, name, sha256) => `${String(version).padStart(4, "0")}_${name}.sql (sha256 ${sha256.slice(0, 12)})`;
180
+ throw new Error(`${placeOf(schema)} applied ${file(row.version, row.name, row.sha256)} where this build has ${file(mine.version, mine.name, mine.sha256)}: an applied migration is never edited, renumbered or renamed, a change is a new file`);
179
181
  }
180
182
  }
181
183
  for (const migration of migrations.slice(top ?? 0)) {
@@ -0,0 +1,65 @@
1
+ -- runners: breaking
2
+ -- The store's schema on Postgres, version 32: each agent's learning as versioned rows, as store/schema.ts keeps it on
3
+ -- SQLite (LEARNING_ROWS). Applied once, after 0031, inside the transaction migrate.ts opens. Never edit this file once
4
+ -- applied: a change is a new file. No table or column an earlier build reads changes, but it is breaking for runners
5
+ -- all the same: a runner of an earlier build keeps a run's learning in a git folder and settings keys, which this
6
+ -- release neither reads nor purges, so the floor rises to 32 and every earlier runner stops (RunnerBelowFloor).
7
+ --
8
+ -- learning_saves: each save of an agent's learning, one version, its random id (what a run's seed and the log name),
9
+ -- its kind (init, run, person, purged), who saved it and why (`change`), and a run's merge key (one merge a run's
10
+ -- round). A purged run's save keeps its version, id and merge key and loses its words.
11
+ -- learning_items: each item's versions, never updated by a save: a note (one line of corrections.md, `pos` its place)
12
+ -- or a workflow (its files as one JSON object, `digest` its workflow.json's, `writers` each file's writing run). The
13
+ -- item at a version is its newest row at or before it; a null body is gone. `by_run`: a note's run, a workflow's
14
+ -- workflow.json's writer. A run's purge deletes its notes and takes each workflow file it wrote back to its text before.
15
+ -- learning_records: the agent's promotion records, grades and audit rows, each its data whole; its run, workflow and
16
+ -- digest read out for a purge.
17
+ -- Made only where missing, so a store whose record of this file was lost applies it again unharmed.
18
+
19
+ CREATE TABLE IF NOT EXISTS learning_saves (
20
+ agent_id TEXT COLLATE "C" NOT NULL,
21
+ version BIGINT NOT NULL CHECK (version >= 1),
22
+ id TEXT COLLATE "C" NOT NULL,
23
+ at BIGINT NOT NULL,
24
+ kind TEXT COLLATE "C" NOT NULL CHECK (kind IN ('init', 'run', 'person', 'purged')),
25
+ by_run TEXT COLLATE "C",
26
+ merge_key TEXT COLLATE "C",
27
+ change TEXT COLLATE "C" NOT NULL CHECK (change::json IS NOT NULL),
28
+ PRIMARY KEY (agent_id, version)
29
+ );
30
+ CREATE UNIQUE INDEX IF NOT EXISTS learning_saves_id ON learning_saves (agent_id, id);
31
+ CREATE UNIQUE INDEX IF NOT EXISTS learning_saves_merge ON learning_saves (agent_id, merge_key);
32
+ CREATE INDEX IF NOT EXISTS learning_saves_run ON learning_saves (by_run);
33
+
34
+ CREATE TABLE IF NOT EXISTS learning_items (
35
+ agent_id TEXT COLLATE "C" NOT NULL,
36
+ kind TEXT COLLATE "C" NOT NULL CHECK (kind IN ('note', 'workflow', 'label')),
37
+ name TEXT COLLATE "C" NOT NULL,
38
+ version BIGINT NOT NULL CHECK (version >= 1),
39
+ body TEXT COLLATE "C",
40
+ by_run TEXT COLLATE "C",
41
+ change TEXT COLLATE "C" NOT NULL,
42
+ person BIGINT NOT NULL,
43
+ pos BIGINT NOT NULL,
44
+ digest TEXT COLLATE "C",
45
+ writers TEXT COLLATE "C" CHECK (writers IS NULL OR writers::json IS NOT NULL),
46
+ at BIGINT NOT NULL,
47
+ PRIMARY KEY (agent_id, kind, name, version)
48
+ );
49
+ CREATE INDEX IF NOT EXISTS learning_items_version ON learning_items (agent_id, version);
50
+ CREATE INDEX IF NOT EXISTS learning_items_run ON learning_items (by_run);
51
+
52
+ CREATE TABLE IF NOT EXISTS learning_records (
53
+ agent_id TEXT COLLATE "C" NOT NULL,
54
+ kind TEXT COLLATE "C" NOT NULL CHECK (kind IN ('promotion', 'grade', 'audit', 'lifecycle', 'note')),
55
+ seq BIGINT NOT NULL,
56
+ run_id TEXT COLLATE "C",
57
+ workflow TEXT COLLATE "C",
58
+ digest TEXT COLLATE "C",
59
+ data TEXT COLLATE "C" NOT NULL CHECK (data::json IS NOT NULL),
60
+ at BIGINT NOT NULL,
61
+ PRIMARY KEY (agent_id, kind, seq)
62
+ );
63
+ CREATE INDEX IF NOT EXISTS learning_records_run ON learning_records (run_id);
64
+
65
+ UPDATE store_meta SET schema_version = 32 WHERE singleton = 1;
@@ -1,4 +1,4 @@
1
- export declare const SCHEMA_VERSION = 16;
1
+ export declare const SCHEMA_VERSION = 17;
2
2
  /** One answer per approval of a run: a second approve or deny command naming the same approval is refused
3
3
  * (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
4
4
  * (runs-over-store.ts approve). In STORE_DDL, and added at a server open to a store an earlier build of this version made. */
@@ -24,6 +24,10 @@ export declare const RUNS_LABELS: string;
24
24
  * version, in one durable write. A run whose launch named no disk of its own reads as the default disk's, and so does a
25
25
  * run purged before (its launch body gone): nothing of it is left to learn from. */
26
26
  export declare function diskUpgrade(runColumns: ReadonlySet<string>): readonly string[];
27
+ /** Version 16 → 17 on SQLite (the server's open, sqlite/store.ts, after ledgerUpgrade, which writes 16): each agent's
28
+ * learning as rows (LEARNING_ROWS, made at the same open) and the version, so no runner of an earlier build (which knows
29
+ * 16 or before) opens the store again. */
30
+ export declare function learningRowsUpgrade(): readonly string[];
27
31
  /** A trigger's package mark (TriggerRow.templateId): the id of the template package whose apply made or last kept it, null
28
32
  * for one a person made. In STORE_DDL, and added at a server open to a store an earlier build of this version made, as
29
33
  * RUNS_LABELS is (a trigger made before reads as no package's). */
@@ -103,6 +107,28 @@ export declare const HAND_BACKS_AT = "CREATE INDEX IF NOT EXISTS hand_backs_at O
103
107
  export declare const HAND_BACKS_RUN = "CREATE INDEX IF NOT EXISTS hand_backs_run ON hand_backs (run_id)";
104
108
  /** How long a hand-back's row is kept: the longest window the capacity read takes. */
105
109
  export declare const HAND_BACKS_KEPT_MS: number;
110
+ /** An agent's learning as versioned rows (store.learning: seed, itemsAt, save, purgeRun, reset, erase, diff).
111
+ * - learning_saves: each save of the agent's learning, one version (1, 2, ...), its id (40 hex, random: what a run's
112
+ * seed and the log name), its kind (`init`, the empty first one a run's seed makes; a `run`'s merge; a `person`'s
113
+ * change; `purged`, a purged run's), who saved it and why (`change`: its reason and the paths it changed), and a
114
+ * run's merge key (one merge a run's round). A purged run's save keeps its version, id and merge key (a seed read
115
+ * from it stays held, and the round never merges again) and loses its words (`by_run`, `change`).
116
+ * - learning_items: each item's versions, never updated by a save (a run's purge rewrites the workflow versions that
117
+ * held its files): a note (one line of corrections.md, `pos` its place) or a
118
+ * workflow (its folder's files as one JSON object of path to text, `digest` its workflow.json's). The item at a
119
+ * version is its newest row at or before it; a null body is gone. A workflow's `writers`: each file's writer, the run
120
+ * whose merge changed it to its text (a merge that gives a file unchanged, and a person's edit of it, keep the writer
121
+ * before; null: a person's own file), so a run's purge takes each file it wrote back to its text before, file by
122
+ * file. `by_run`: a note's run; a workflow's, its workflow.json's writer (what its promotions are of).
123
+ * - learning_records: the agent's promotion records, grades and audit rows, each its data whole, never trimmed; its
124
+ * run, workflow and digest read out for a purge.
125
+ * The CHECKs also allow kinds no code writes yet: a `label` item, and `lifecycle` and `note` records (the follow-up
126
+ * PRs write them; Postgres 0032_learning_rows.sql has the same CHECKs). A run's purge deletes every item of
127
+ * the run's but a workflow, a label too, and every record whose run is the run (learning-rows.ts dropRunLearning). A PR
128
+ * that first writes a lifecycle or note record whose data names another run extends the purge's scrub
129
+ * (learning-rows.ts forgetRunRecords) in the same PR.
130
+ * In STORE_DDL, and made at a server open on a store an earlier build of this version made. */
131
+ export declare const LEARNING_ROWS: readonly string[];
106
132
  /** Each claim of a run (store.runAttempts, RunAttemptRow): the turn it works and its attempt at it, why the attempt before
107
133
  * was cut (`cause`: drain, crash, lease_lapse, retry; null on a turn's first), why this one let the run go unfinished
108
134
  * (`cut`), its runner, the run's state it took the run from, the first journal entry id it could write
@@ -160,7 +186,7 @@ export declare function relayUpgrade(mintedColumns: ReadonlySet<string>): readon
160
186
  * that lands meanwhile keeps the row as it left it (its list_status too), behind (listing_mark < list_mark), and it is
161
187
  * built again: a crash between a write and its listing leaves a row that says
162
188
  * it is behind, never one that says it is current. `listing` is the list item without the parts read when it is listed
163
- * (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
189
+ * (console_url, archived_at), with the secrets it was cut of (a list builds one cut of other secrets again: store-view.ts builtOfNow) and, beside the item, what the same build kept for the Agent Factory's scoped lists (store-view.ts KeptFactory); `list_status` its status, which a status filter reads in SQL; `listing_live` whether a runner
164
190
  * held the run when it was built (its status reads otherwise once that claim runs out); `listing_until` when it goes stale
165
191
  * 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
166
192
  * back); `listing_flags` what outside the run it read (LISTING_HELD: learning held for
@@ -40,10 +40,13 @@
40
40
  // an agent was purged (runs.purged_at, agents.purged_at; DELETE /runs/{id} and /agents/{id}, agent-delete.ts): its row is
41
41
  // then a tombstone, its content gone and its cost kept. Version 15 keeps the disk a run's launch named as its own
42
42
  // (runs.disk; a run on one learns nothing, learn/learning-of.ts). Version 16 keeps no epoch on a learning ledger row
43
- // (learning_ledger; 15 kept one, which a runner of 15 writes at each end and this build's end does not). The server
44
- // upgrades these in place at its open (listingUpgrade from 11, relayUpgrade from 12, purgeUpgrade from 13, diskUpgrade
45
- // from 14, then ledgerUpgrade from 15); a runner waits for it.
46
- export const SCHEMA_VERSION = 16;
43
+ // (learning_ledger; 15 kept one, which a runner of 15 writes at each end and this build's end does not). Version 17 keeps
44
+ // each agent's learning as rows (LEARNING_ROWS) in place of a git folder and settings keys: a runner of an earlier build
45
+ // would still write learning where this server neither reads nor purges it, so it must not open the store (it opens only
46
+ // its own version). The server upgrades these in place at its open (listingUpgrade from 11, relayUpgrade from 12,
47
+ // purgeUpgrade from 13, diskUpgrade from 14, ledgerUpgrade from 15, then learningRowsUpgrade from 16); a runner of this
48
+ // build waits for it.
49
+ export const SCHEMA_VERSION = 17;
47
50
  /** One answer per approval of a run: a second approve or deny command naming the same approval is refused
48
51
  * (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
49
52
  * (runs-over-store.ts approve). In STORE_DDL, and added at a server open to a store an earlier build of this version made. */
@@ -80,6 +83,12 @@ export function diskUpgrade(runColumns) {
80
83
  "UPDATE store_meta SET schema_version = 15 WHERE singleton = 1",
81
84
  ];
82
85
  }
86
+ /** Version 16 → 17 on SQLite (the server's open, sqlite/store.ts, after ledgerUpgrade, which writes 16): each agent's
87
+ * learning as rows (LEARNING_ROWS, made at the same open) and the version, so no runner of an earlier build (which knows
88
+ * 16 or before) opens the store again. */
89
+ export function learningRowsUpgrade() {
90
+ return [...LEARNING_ROWS, "UPDATE store_meta SET schema_version = 17 WHERE singleton = 1"];
91
+ }
83
92
  /** A trigger's package mark (TriggerRow.templateId): the id of the template package whose apply made or last kept it, null
84
93
  * for one a person made. In STORE_DDL, and added at a server open to a store an earlier build of this version made, as
85
94
  * RUNS_LABELS is (a trigger made before reads as no package's). */
@@ -216,6 +225,72 @@ export const HAND_BACKS_AT = "CREATE INDEX IF NOT EXISTS hand_backs_at ON hand_b
216
225
  export const HAND_BACKS_RUN = "CREATE INDEX IF NOT EXISTS hand_backs_run ON hand_backs (run_id)";
217
226
  /** How long a hand-back's row is kept: the longest window the capacity read takes. */
218
227
  export const HAND_BACKS_KEPT_MS = 24 * 60 * 60_000;
228
+ /** An agent's learning as versioned rows (store.learning: seed, itemsAt, save, purgeRun, reset, erase, diff).
229
+ * - learning_saves: each save of the agent's learning, one version (1, 2, ...), its id (40 hex, random: what a run's
230
+ * seed and the log name), its kind (`init`, the empty first one a run's seed makes; a `run`'s merge; a `person`'s
231
+ * change; `purged`, a purged run's), who saved it and why (`change`: its reason and the paths it changed), and a
232
+ * run's merge key (one merge a run's round). A purged run's save keeps its version, id and merge key (a seed read
233
+ * from it stays held, and the round never merges again) and loses its words (`by_run`, `change`).
234
+ * - learning_items: each item's versions, never updated by a save (a run's purge rewrites the workflow versions that
235
+ * held its files): a note (one line of corrections.md, `pos` its place) or a
236
+ * workflow (its folder's files as one JSON object of path to text, `digest` its workflow.json's). The item at a
237
+ * version is its newest row at or before it; a null body is gone. A workflow's `writers`: each file's writer, the run
238
+ * whose merge changed it to its text (a merge that gives a file unchanged, and a person's edit of it, keep the writer
239
+ * before; null: a person's own file), so a run's purge takes each file it wrote back to its text before, file by
240
+ * file. `by_run`: a note's run; a workflow's, its workflow.json's writer (what its promotions are of).
241
+ * - learning_records: the agent's promotion records, grades and audit rows, each its data whole, never trimmed; its
242
+ * run, workflow and digest read out for a purge.
243
+ * The CHECKs also allow kinds no code writes yet: a `label` item, and `lifecycle` and `note` records (the follow-up
244
+ * PRs write them; Postgres 0032_learning_rows.sql has the same CHECKs). A run's purge deletes every item of
245
+ * the run's but a workflow, a label too, and every record whose run is the run (learning-rows.ts dropRunLearning). A PR
246
+ * that first writes a lifecycle or note record whose data names another run extends the purge's scrub
247
+ * (learning-rows.ts forgetRunRecords) in the same PR.
248
+ * In STORE_DDL, and made at a server open on a store an earlier build of this version made. */
249
+ export const LEARNING_ROWS = [
250
+ `CREATE TABLE IF NOT EXISTS learning_saves (
251
+ agent_id TEXT NOT NULL,
252
+ version INTEGER NOT NULL,
253
+ id TEXT NOT NULL,
254
+ at INTEGER NOT NULL,
255
+ kind TEXT NOT NULL CHECK (kind IN ('init', 'run', 'person', 'purged')),
256
+ by_run TEXT,
257
+ merge_key TEXT,
258
+ ${json("change")},
259
+ PRIMARY KEY (agent_id, version)
260
+ ) STRICT`,
261
+ "CREATE UNIQUE INDEX IF NOT EXISTS learning_saves_id ON learning_saves (agent_id, id)",
262
+ "CREATE UNIQUE INDEX IF NOT EXISTS learning_saves_merge ON learning_saves (agent_id, merge_key)",
263
+ "CREATE INDEX IF NOT EXISTS learning_saves_run ON learning_saves (by_run)",
264
+ `CREATE TABLE IF NOT EXISTS learning_items (
265
+ agent_id TEXT NOT NULL,
266
+ kind TEXT NOT NULL CHECK (kind IN ('note', 'workflow', 'label')),
267
+ name TEXT NOT NULL,
268
+ version INTEGER NOT NULL,
269
+ body TEXT,
270
+ by_run TEXT,
271
+ change TEXT NOT NULL,
272
+ person INTEGER NOT NULL,
273
+ pos INTEGER NOT NULL,
274
+ digest TEXT,
275
+ writers TEXT,
276
+ at INTEGER NOT NULL,
277
+ PRIMARY KEY (agent_id, kind, name, version)
278
+ ) STRICT`,
279
+ "CREATE INDEX IF NOT EXISTS learning_items_version ON learning_items (agent_id, version)",
280
+ "CREATE INDEX IF NOT EXISTS learning_items_run ON learning_items (by_run)",
281
+ `CREATE TABLE IF NOT EXISTS learning_records (
282
+ agent_id TEXT NOT NULL,
283
+ kind TEXT NOT NULL CHECK (kind IN ('promotion', 'grade', 'audit', 'lifecycle', 'note')),
284
+ seq INTEGER NOT NULL,
285
+ run_id TEXT,
286
+ workflow TEXT,
287
+ digest TEXT,
288
+ ${json("data")},
289
+ at INTEGER NOT NULL,
290
+ PRIMARY KEY (agent_id, kind, seq)
291
+ ) STRICT`,
292
+ "CREATE INDEX IF NOT EXISTS learning_records_run ON learning_records (run_id)",
293
+ ];
219
294
  /** Each claim of a run (store.runAttempts, RunAttemptRow): the turn it works and its attempt at it, why the attempt before
220
295
  * was cut (`cause`: drain, crash, lease_lapse, retry; null on a turn's first), why this one let the run go unfinished
221
296
  * (`cut`), its runner, the run's state it took the run from, the first journal entry id it could write
@@ -345,7 +420,7 @@ export function relayUpgrade(mintedColumns) {
345
420
  * that lands meanwhile keeps the row as it left it (its list_status too), behind (listing_mark < list_mark), and it is
346
421
  * built again: a crash between a write and its listing leaves a row that says
347
422
  * it is behind, never one that says it is current. `listing` is the list item without the parts read when it is listed
348
- * (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
423
+ * (console_url, archived_at), with the secrets it was cut of (a list builds one cut of other secrets again: store-view.ts builtOfNow) and, beside the item, what the same build kept for the Agent Factory's scoped lists (store-view.ts KeptFactory); `list_status` its status, which a status filter reads in SQL; `listing_live` whether a runner
349
424
  * held the run when it was built (its status reads otherwise once that claim runs out); `listing_until` when it goes stale
350
425
  * 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
351
426
  * back); `listing_flags` what outside the run it read (LISTING_HELD: learning held for
@@ -767,6 +842,7 @@ export const STORE_DDL = [
767
842
  updated_at INTEGER NOT NULL,
768
843
  PRIMARY KEY (agent_id, key)
769
844
  ) STRICT`,
845
+ ...LEARNING_ROWS,
770
846
  IMPORTED_TEMPLATES,
771
847
  MINTED_TOKENS,
772
848
  RUNNERS,
@@ -0,0 +1,23 @@
1
+ import { type Learning } from "../store.js";
2
+ import type { StoreConnection, Tx } from "./connection.js";
3
+ /** Run `runId`'s learning rows gone from its agent `agentId`'s, inside the caller's transaction (its purge, its
4
+ * delete), every statement scoped to that agent: each workflow it wrote a file of rewritten without its files
5
+ * (rewriteWorkflow), with the promotions and audits of each digest no version holds then (each such revision another
6
+ * run is still billed against kept first in the agent's reset ledger, its workflow, digest and K alone: keptRevision,
7
+ * so the runs that carry its spend read the same share after; and each revision the ledger holds that the run was
8
+ * billed against and no other run is after it, taken out of the ledger: changeResetLedger); its notes; its records (its
9
+ * grades and audits, a failed draft's hold); every other promotion's copies of it (forgetRunIn); and its saves' words (each save's version, id and merge key stay), a person's save left with no item (an
10
+ * approve of its draft, a removal of its line) with them: that save's words name what the run wrote. Every other save
11
+ * names none of the paths only it wrote, nor a workflow gone with it. When any row changed, the purge is a save of its
12
+ * own at the agent's newest version + 1 (the host's, kind `purged`, at `at`): a save computed before it is stale, and a
13
+ * run's merge read at a save before it is refused (save's `readAt`). Callers hold the agent's learning lock
14
+ * (`learning:<agent>`); this takes its records' lock (`learning.records:<agent>`) after it. */
15
+ export declare function dropRunLearning(tx: Tx, agentId: string, runId: string, at: number): Promise<void>;
16
+ /** Every learning row of agent `agentId` gone, inside the caller's transaction (a reset, its purge, its delete), under
17
+ * the agent's learning lock and then its records' lock, the order a run's purge takes them: a records write that read
18
+ * before it is in before it, never written after. */
19
+ export declare function dropAgentLearning(tx: Tx, agentId: string): Promise<void>;
20
+ type Rows = Pick<Learning, "seed" | "newest" | "newestPurge" | "newestSave" | "itemsAt" | "saves" | "saveOf" | "versions" | "diff" | "save" | "purgeRun" | "reset" | "erase" | "records" | "addRecord" | "changeRecords">;
21
+ /** Store.learning's rows, over `db`; `now`, the store's clock. */
22
+ export declare function learningRows(db: StoreConnection, now: () => number): Rows;
23
+ export {};