@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.45

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 (388) hide show
  1. package/CHANGELOG.md +231 -0
  2. package/README.md +580 -320
  3. package/dist/acp-package.d.ts +28 -0
  4. package/dist/acp-package.js +23 -0
  5. package/dist/adapter-facts.d.ts +8 -1
  6. package/dist/adapter-facts.js +9 -1
  7. package/dist/adapters.d.ts +5 -0
  8. package/dist/adapters.js +36 -3
  9. package/dist/agent-delete.d.ts +50 -0
  10. package/dist/agent-delete.js +125 -0
  11. package/dist/agents-store.d.ts +9 -3
  12. package/dist/agents-store.js +22 -8
  13. package/dist/agents.d.ts +5 -1
  14. package/dist/agents.js +8 -4
  15. package/dist/api-only.d.ts +8 -3
  16. package/dist/api-only.js +10 -4
  17. package/dist/archil-routes.d.ts +5 -1
  18. package/dist/archil-routes.js +57 -2
  19. package/dist/browser-wait-ended.d.ts +2 -0
  20. package/dist/browser-wait-ended.js +2 -0
  21. package/dist/calendar/ics-faux.d.ts +3 -1
  22. package/dist/calendar/ics-faux.js +12 -2
  23. package/dist/calendar/tools.js +5 -2
  24. package/dist/chatgpt-plan.js +3 -1
  25. package/dist/claude-login.d.ts +135 -0
  26. package/dist/claude-login.js +244 -0
  27. package/dist/cli.js +92 -22
  28. package/dist/composio-preset.d.ts +4 -3
  29. package/dist/composio-preset.js +81 -11
  30. package/dist/composio-triggers.d.ts +34 -2
  31. package/dist/composio-triggers.js +261 -31
  32. package/dist/computer-attach.d.ts +40 -5
  33. package/dist/computer-attach.js +130 -15
  34. package/dist/computer-keys.d.ts +3 -0
  35. package/dist/computer-keys.js +7 -1
  36. package/dist/computer-live.js +3 -2
  37. package/dist/computer-lost.d.ts +11 -0
  38. package/dist/computer-lost.js +19 -0
  39. package/dist/computer-record.d.ts +10 -2
  40. package/dist/computer-record.js +50 -18
  41. package/dist/computer-setting.d.ts +1 -0
  42. package/dist/computer-setting.js +2 -2
  43. package/dist/computers.d.ts +21 -10
  44. package/dist/computers.js +39 -28
  45. package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
  46. package/dist/console/assets/index-DaFsZuzQ.css +1 -0
  47. package/dist/console/index.html +2 -2
  48. package/dist/decisions.d.ts +1 -1
  49. package/dist/dial-relay.d.ts +29 -0
  50. package/dist/dial-relay.js +94 -0
  51. package/dist/email/tools.js +10 -5
  52. package/dist/env-proxy.d.ts +2 -0
  53. package/dist/env-proxy.js +35 -0
  54. package/dist/errors.d.ts +4 -1
  55. package/dist/errors.js +10 -4
  56. package/dist/faux-computers.d.ts +8 -2
  57. package/dist/faux-computers.js +83 -6
  58. package/dist/harness-archive.d.ts +67 -0
  59. package/dist/harness-archive.js +177 -0
  60. package/dist/harness-goose.d.ts +34 -0
  61. package/dist/harness-goose.js +87 -0
  62. package/dist/harness-install.d.ts +21 -0
  63. package/dist/harness-install.js +24 -11
  64. package/dist/harness-opencode/adapter.js +1 -1
  65. package/dist/harness-table.d.ts +59 -3
  66. package/dist/harness-table.js +119 -14
  67. package/dist/harness.d.ts +17 -1
  68. package/dist/harness.js +22 -11
  69. package/dist/host.d.ts +12 -10
  70. package/dist/host.js +19 -16
  71. package/dist/import-worker.d.ts +3 -0
  72. package/dist/import-worker.js +7 -5
  73. package/dist/import.d.ts +22 -1
  74. package/dist/import.js +141 -28
  75. package/dist/key-check.js +3 -0
  76. package/dist/learn/audit.d.ts +6 -6
  77. package/dist/learn/audit.js +3 -7
  78. package/dist/learn/check.d.ts +26 -89
  79. package/dist/learn/check.js +58 -336
  80. package/dist/learn/commit.d.ts +63 -90
  81. package/dist/learn/commit.js +124 -316
  82. package/dist/learn/compile.d.ts +53 -50
  83. package/dist/learn/compile.js +88 -103
  84. package/dist/learn/corrections.d.ts +13 -0
  85. package/dist/learn/corrections.js +23 -0
  86. package/dist/learn/delete.d.ts +17 -0
  87. package/dist/learn/delete.js +42 -0
  88. package/dist/learn/folder.d.ts +35 -47
  89. package/dist/learn/folder.js +118 -134
  90. package/dist/learn/index.d.ts +3 -5
  91. package/dist/learn/index.js +6 -9
  92. package/dist/learn/learning.sh +45 -15
  93. package/dist/learn/promote.d.ts +20 -2
  94. package/dist/learn/promote.js +17 -4
  95. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +34 -38
  96. package/dist/learn/{skills.js → workflow-draft.js} +65 -59
  97. package/dist/learn/workflow-nodes.d.ts +22 -1
  98. package/dist/learn/workflow-nodes.js +29 -10
  99. package/dist/learned-workflow.js +2 -2
  100. package/dist/learning-cost.d.ts +127 -13
  101. package/dist/learning-cost.js +142 -10
  102. package/dist/learning-routes.d.ts +99 -170
  103. package/dist/learning-routes.js +199 -420
  104. package/dist/learning-run.d.ts +19 -40
  105. package/dist/learning-run.js +23 -93
  106. package/dist/learning-setting.d.ts +4 -4
  107. package/dist/learning-setting.js +6 -6
  108. package/dist/learning-words.d.ts +28 -74
  109. package/dist/learning-words.js +64 -162
  110. package/dist/learning.d.ts +62 -393
  111. package/dist/learning.js +101 -651
  112. package/dist/listen-first.d.ts +30 -0
  113. package/dist/listen-first.js +115 -0
  114. package/dist/live-reach.d.ts +25 -2
  115. package/dist/live-reach.js +46 -4
  116. package/dist/llms.txt +2 -1
  117. package/dist/local-models.d.ts +3 -11
  118. package/dist/local-models.js +5 -6
  119. package/dist/mcp-servers-store.d.ts +16 -16
  120. package/dist/model-form.js +6 -5
  121. package/dist/model.d.ts +12 -4
  122. package/dist/model.js +41 -16
  123. package/dist/native/binding.js +1 -1
  124. package/dist/native/connection.js +1 -1
  125. package/dist/native/discovery.js +1 -1
  126. package/dist/native/instructions.d.ts +3 -0
  127. package/dist/native/instructions.js +5 -3
  128. package/dist/native/remote-worker-bridge.js +9 -43
  129. package/dist/native/remote.d.ts +8 -15
  130. package/dist/native/remote.js +3 -3
  131. package/dist/native/schema.js +1 -1
  132. package/dist/native/types.d.ts +2 -2
  133. package/dist/openapi.js +375 -347
  134. package/dist/owner.d.ts +8 -0
  135. package/dist/owner.js +11 -0
  136. package/dist/paid-calls.d.ts +14 -0
  137. package/dist/paid-calls.js +31 -1
  138. package/dist/particle-provider.d.ts +11 -0
  139. package/dist/particle-provider.js +135 -0
  140. package/dist/place.d.ts +8 -3
  141. package/dist/place.js +13 -9
  142. package/dist/port-models.d.ts +12 -4
  143. package/dist/port-models.js +28 -11
  144. package/dist/print.d.ts +27 -0
  145. package/dist/print.js +21 -0
  146. package/dist/provider.d.ts +7 -0
  147. package/dist/provider.js +30 -2
  148. package/dist/reflect-range.js +2 -3
  149. package/dist/run-launch.d.ts +14 -28
  150. package/dist/run-launch.js +9 -12
  151. package/dist/run-learning-served.d.ts +16 -90
  152. package/dist/run-listing.d.ts +34 -0
  153. package/dist/run-listing.js +128 -0
  154. package/dist/run-model-key.d.ts +64 -0
  155. package/dist/run-model-key.js +147 -0
  156. package/dist/run-timeline-served.js +5 -3
  157. package/dist/run-trace.d.ts +97 -0
  158. package/dist/run-trace.js +253 -0
  159. package/dist/run-view.d.ts +15 -0
  160. package/dist/run-view.js +9 -0
  161. package/dist/runnable.js +2 -1
  162. package/dist/runner/adapter-loop.d.ts +14 -6
  163. package/dist/runner/adapter-loop.js +25 -14
  164. package/dist/runner/adapter-run-spec.d.ts +22 -7
  165. package/dist/runner/adapter-run-spec.js +130 -77
  166. package/dist/runner/adapters/index.d.ts +4 -2
  167. package/dist/runner/adapters/index.js +35 -4
  168. package/dist/runner/adapters/pi.d.ts +4 -12
  169. package/dist/runner/adapters/pi.js +2 -2
  170. package/dist/runner/audit.d.ts +5 -1
  171. package/dist/runner/audit.js +31 -12
  172. package/dist/runner/beside.d.ts +7 -2
  173. package/dist/runner/beside.js +41 -9
  174. package/dist/runner/claim-secrets.d.ts +66 -1
  175. package/dist/runner/claim-secrets.js +136 -3
  176. package/dist/runner/cli-run-spec.d.ts +2 -1
  177. package/dist/runner/cli-run-spec.js +82 -59
  178. package/dist/runner/commands.d.ts +3 -6
  179. package/dist/runner/conformance/harness.d.ts +6 -0
  180. package/dist/runner/conformance/harness.js +16 -5
  181. package/dist/runner/dispatch.d.ts +2 -2
  182. package/dist/runner/end-of-run.d.ts +6 -14
  183. package/dist/runner/end-of-run.js +8 -33
  184. package/dist/runner/feedback-round.d.ts +5 -4
  185. package/dist/runner/feedback-round.js +14 -10
  186. package/dist/runner/github-app.js +3 -1
  187. package/dist/runner/harness-loops.d.ts +0 -8
  188. package/dist/runner/harness-loops.js +30 -56
  189. package/dist/runner/held.d.ts +170 -0
  190. package/dist/runner/held.js +57 -0
  191. package/dist/runner/journal-kinds.d.ts +7 -3
  192. package/dist/runner/journal-kinds.js +2 -3
  193. package/dist/runner/learned-first.d.ts +40 -0
  194. package/dist/runner/learned-first.js +32 -0
  195. package/dist/runner/learning-end.d.ts +77 -66
  196. package/dist/runner/learning-end.js +250 -299
  197. package/dist/runner/learning-seed.d.ts +15 -33
  198. package/dist/runner/learning-seed.js +24 -45
  199. package/dist/runner/loop-contract.d.ts +8 -3
  200. package/dist/runner/loop-contract.js +4 -0
  201. package/dist/runner/loop.js +6 -2
  202. package/dist/runner/main.d.ts +18 -9
  203. package/dist/runner/main.js +82 -22
  204. package/dist/runner/mcp-run.d.ts +11 -0
  205. package/dist/runner/mcp-run.js +67 -0
  206. package/dist/runner/memory-claim.d.ts +14 -6
  207. package/dist/runner/memory-claim.js +18 -9
  208. package/dist/runner/model-route.d.ts +7 -4
  209. package/dist/runner/model-route.js +22 -10
  210. package/dist/runner/native-loop.d.ts +0 -7
  211. package/dist/runner/native-loop.js +9 -101
  212. package/dist/runner/promotion.d.ts +13 -6
  213. package/dist/runner/promotion.js +63 -17
  214. package/dist/runner/reflect-hook.d.ts +64 -91
  215. package/dist/runner/reflect-hook.js +112 -206
  216. package/dist/runner/run-channel.d.ts +43 -0
  217. package/dist/runner/run-channel.js +467 -0
  218. package/dist/runner/run-child-host.d.ts +169 -0
  219. package/dist/runner/run-child-host.js +1222 -0
  220. package/dist/runner/run-child.d.ts +1 -0
  221. package/dist/runner/run-child.js +254 -0
  222. package/dist/runner/run-errors.d.ts +2 -0
  223. package/dist/runner/run-errors.js +20 -0
  224. package/dist/runner/runner.js +58 -9
  225. package/dist/runner/sdk-ask.d.ts +78 -0
  226. package/dist/runner/sdk-ask.js +158 -0
  227. package/dist/runner/sdk-loop.d.ts +2 -4
  228. package/dist/runner/sdk-loop.js +29 -49
  229. package/dist/runner/store-secrets.d.ts +5 -3
  230. package/dist/runner/store-secrets.js +14 -6
  231. package/dist/runner/workflow-first.d.ts +5 -0
  232. package/dist/runner/workflow-first.js +4 -0
  233. package/dist/runner/workflow-spec.js +17 -4
  234. package/dist/runs-over-store.d.ts +21 -32
  235. package/dist/runs-over-store.js +44 -41
  236. package/dist/sdk/runs.d.ts +6 -11
  237. package/dist/sdk/runs.js +20 -41
  238. package/dist/sdk/schema.js +3 -4
  239. package/dist/sdk/workflows.d.ts +1 -1
  240. package/dist/seal-key.d.ts +5 -0
  241. package/dist/seal-key.js +7 -0
  242. package/dist/secrets.d.ts +3 -0
  243. package/dist/secrets.js +16 -3
  244. package/dist/server.d.ts +119 -83
  245. package/dist/server.js +1121 -419
  246. package/dist/sign-ins-store.d.ts +8 -0
  247. package/dist/sign-ins-store.js +36 -1
  248. package/dist/skills.js +1 -1
  249. package/dist/store/index.d.ts +3 -3
  250. package/dist/store/index.js +2 -2
  251. package/dist/store/journal/storage.js +3 -0
  252. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  253. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  254. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  255. package/dist/store/schema.d.ts +53 -4
  256. package/dist/store/schema.js +137 -6
  257. package/dist/store/seal.d.ts +20 -2
  258. package/dist/store/seal.js +24 -8
  259. package/dist/store/sqlite/connection.d.ts +2 -0
  260. package/dist/store/sqlite/connection.js +3 -1
  261. package/dist/store/sqlite/run-launch.d.ts +4 -1
  262. package/dist/store/sqlite/run-launch.js +12 -0
  263. package/dist/store/sqlite/run-patch.d.ts +0 -17
  264. package/dist/store/sqlite/run-patch.js +4 -33
  265. package/dist/store/sqlite/store.d.ts +3 -2
  266. package/dist/store/sqlite/store.js +360 -75
  267. package/dist/store/sqlite/worker.js +25 -0
  268. package/dist/store/store.d.ts +231 -39
  269. package/dist/store/store.js +25 -3
  270. package/dist/store-reads/analytics.js +11 -1
  271. package/dist/store-reads/learning.d.ts +131 -194
  272. package/dist/store-reads/learning.js +292 -301
  273. package/dist/store-reads/loop.d.ts +0 -1
  274. package/dist/store-reads/loop.js +1 -1
  275. package/dist/store-reads/stats.js +13 -3
  276. package/dist/store-view.d.ts +34 -2
  277. package/dist/store-view.js +108 -41
  278. package/dist/telemetry.d.ts +59 -0
  279. package/dist/telemetry.js +153 -0
  280. package/dist/template-eval.d.ts +3 -6
  281. package/dist/template-eval.js +22 -36
  282. package/dist/templates.d.ts +2 -1
  283. package/dist/templates.js +6 -3
  284. package/dist/timeline/index.d.ts +1 -1
  285. package/dist/timeline/index.js +1 -1
  286. package/dist/timeline/timeline.d.ts +5 -1
  287. package/dist/timeline/timeline.js +16 -0
  288. package/dist/tool-gate.d.ts +0 -7
  289. package/dist/tool-gate.js +1 -15
  290. package/dist/tool-keys-store.d.ts +1 -1
  291. package/dist/tool-keys.d.ts +6 -4
  292. package/dist/tool-keys.js +12 -6
  293. package/dist/tool-plane.d.ts +12 -12
  294. package/dist/tools.d.ts +13 -13
  295. package/dist/tools.js +29 -9
  296. package/dist/trigger-adapter.d.ts +3 -0
  297. package/dist/trigger-adapters.d.ts +4 -0
  298. package/dist/trigger-adapters.js +13 -0
  299. package/dist/trigger-composio.d.ts +58 -1
  300. package/dist/trigger-composio.js +160 -6
  301. package/dist/triggers.d.ts +64 -5
  302. package/dist/triggers.js +141 -17
  303. package/dist/validate.d.ts +11 -7
  304. package/dist/validate.js +9 -8
  305. package/dist/webhooks.d.ts +4 -1
  306. package/dist/webhooks.js +11 -4
  307. package/dist/workspace/agent-computer.d.ts +2 -0
  308. package/dist/workspace/agent-computer.js +2 -0
  309. package/dist/workspace/archil-claim.d.ts +7 -0
  310. package/dist/workspace/archil-claim.js +29 -0
  311. package/dist/workspace/archil.d.ts +9 -1
  312. package/dist/workspace/archil.js +165 -3
  313. package/dist/workspace/attach.d.ts +3 -1
  314. package/dist/workspace/attach.js +2 -0
  315. package/dist/workspace/attached-computers.d.ts +16 -5
  316. package/dist/workspace/attached-computers.js +25 -9
  317. package/dist/workspace/computer-deps.js +1 -1
  318. package/dist/workspace/computer-for-claim.d.ts +22 -8
  319. package/dist/workspace/computer-for-claim.js +339 -46
  320. package/dist/workspace/computer-hold.js +2 -1
  321. package/dist/workspace/computer-kept.d.ts +11 -1
  322. package/dist/workspace/computer-kept.js +24 -3
  323. package/dist/workspace/resolve-computer.d.ts +41 -21
  324. package/dist/workspace/resolve-computer.js +172 -64
  325. package/dist/workspace/revision-skills.d.ts +1 -2
  326. package/dist/workspace/revision-skills.js +3 -4
  327. package/dist/workspace/run-workspace.d.ts +1 -1
  328. package/dist/workspace/run-workspace.js +5 -0
  329. package/dist/workspace/synced-folder.d.ts +85 -0
  330. package/dist/workspace/synced-folder.js +230 -0
  331. package/dist/workspace/workspace.d.ts +4 -0
  332. package/launcher/agentrun-serve +1 -1
  333. package/package.json +10 -9
  334. package/templates/README.md +7 -7
  335. package/templates/inbound-lead/agent.md +3 -3
  336. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  337. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  338. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  339. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  340. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  341. package/templates/inbound-lead/lead.schema.json +6 -5
  342. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  343. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  344. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  345. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  346. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  347. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  348. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  349. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  350. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  351. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  352. package/dist/console/assets/index-BrcDSBD8.css +0 -1
  353. package/dist/console/assets/index-Bz6IWncl.js +0 -711
  354. package/dist/learn/grade.d.ts +0 -138
  355. package/dist/learn/grade.js +0 -682
  356. package/dist/learn/notes.d.ts +0 -81
  357. package/dist/learn/notes.js +0 -178
  358. package/dist/learn/reflect.d.ts +0 -77
  359. package/dist/learn/reflect.js +0 -228
  360. package/dist/learn/relevance.d.ts +0 -24
  361. package/dist/learn/relevance.js +0 -91
  362. package/dist/learn/seed-check.d.ts +0 -74
  363. package/dist/learn/seed-check.js +0 -103
  364. package/dist/learning-batch.d.ts +0 -291
  365. package/dist/learning-batch.js +0 -600
  366. package/dist/learning-evals.d.ts +0 -33
  367. package/dist/learning-evals.js +0 -98
  368. package/dist/native/context.d.ts +0 -6
  369. package/dist/native/context.js +0 -22
  370. package/dist/propose.d.ts +0 -52
  371. package/dist/propose.js +0 -224
  372. package/dist/runner/learning-ask.d.ts +0 -47
  373. package/dist/runner/learning-ask.js +0 -128
  374. package/dist/runner/learning-dispatch.d.ts +0 -45
  375. package/dist/runner/learning-dispatch.js +0 -99
  376. package/dist/runner/learning-factory.d.ts +0 -16
  377. package/dist/runner/learning-factory.js +0 -50
  378. package/dist/runner/learning-loop.d.ts +0 -273
  379. package/dist/runner/learning-loop.js +0 -521
  380. package/dist/usage.d.ts +0 -11
  381. package/dist/usage.js +0 -11
  382. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  383. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  384. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  385. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  386. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  387. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  388. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -1,521 +0,0 @@
1
- // The built-in learning run: a run of harness "learning" that grades what another run's end-of-run turn kept (its
2
- // learning_proposals row) and merges what the grader keeps into the agent's learning folder, through the folder's one
3
- // write script (learningCommit). The runner claims it like any run; this loop is on the same contract as the others, so
4
- // the claim, the fence, a stop and the end commit are the runner's.
5
- //
6
- // Its journal says what happened, one entry each, on its root conversation:
7
- // agentrun.learning.graded the verdict and what the grade spent, written BEFORE the merge, so a resumed run never
8
- // asks the grader twice;
9
- // agentrun.learning.merged what the merge wrote (the new main and its commit), with the run's end;
10
- // agentrun.learning.dropped why nothing was merged (the grader kept nothing, main moved under it, the checker refused
11
- // it), with the run's end.
12
- // The merge is idempotent on the learning's source run (the script finds its Run-Id on main), so a run resumed after the
13
- // merge's call merges once.
14
- import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
15
- import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
16
- import { CONTRADICTED_REASON, CONTRADICTED_TWICE_REASON, CONTRADICTION_ASK, gradedItems, gradePrompt, parseVerdict, UNREADABLE_REASON } from "../learn/grade.js";
17
- import { mergedNote, parseNoteFile, ruleOf } from "../learn/notes.js";
18
- import { learnedPlace } from "../learn/skills.js";
19
- import { blobOid } from "../learn/folder.js";
20
- import { notKept, SAME_NOTE, said, STOPPED } from "../learning-words.js";
21
- import { journalEntries } from "./journal-reader.js";
22
- import { KINDS } from "./journal-kinds.js";
23
- /** The grader's bounds, as the server's grade had them (grade.ts): one ask, its answer cut at GRADE_MAX_TOKENS. */
24
- export const GRADE_TIMEOUT_MS = 180_000;
25
- export const GRADE_MAX_TOKENS = 16_000;
26
- /** A folder the merge could not reach (the workspace or its exec down): the run parks and is retried after this, doubling
27
- * per try up to the last. */
28
- export const UNAVAILABLE_BACKOFF_MS = [30_000, 120_000, 600_000, 1_800_000];
29
- /** A grader call its learning run's cap refused before it was sent (learning-ask.ts bookedAsk: the run's cap left, its
30
- * launch's max_cost_usd): nothing of it was spent, and the grade is skipped, said so (said.noRoomToGrade), never run past
31
- * the cap, never a failure. `forGood`: no room could ever send it (its spend or price unknown), not only none now. */
32
- export class GradeOverCap extends Error {
33
- forGood;
34
- booked;
35
- /** `booked`: the grade's records when it was refused (GradeBooked), what it spent before it. */
36
- constructor(message, forGood, booked) {
37
- super(message);
38
- this.forGood = forGood;
39
- this.booked = booked;
40
- this.name = "GradeOverCap";
41
- }
42
- }
43
- const ROOT = ROOT_CONVERSATION_ID;
44
- /** The graded item a proposal's file is judged as (grade.ts itemOf): a draft's README.md with its workflow.json, every
45
- * other file as itself. */
46
- const itemOf = (file) => {
47
- const place = learnedPlace(file);
48
- return place?.kind === "readme" ? `workflows/${place.name}/workflow.json` : file;
49
- };
50
- /** The why of a note whose name main already holds with other text, which it does not supersede: never written over,
51
- * and the rest of what the run learned merges. */
52
- export const NOTE_NAME_TAKEN = (name) => `A note named ${name} was added since this run started, or was there already; this one wasn't kept.`;
53
- /** The why of a skill re-filed as a note whose file this run's own kept note (or another re-filed skill) takes: the run's
54
- * own stands, and the skill is not written over it. */
55
- export const NOTE_NAME_IN_RUN = (name) => `This run also kept a note named ${name}, so the rule was not re-filed over it.`;
56
- /** What `verdict` merges once each note it keeps (a new note's, or a skill's re-filed as one: its item's `note`) is set
57
- * beside the run's other kept notes and what main holds at that file (`onMain`, by path), one item at a time, never a
58
- * refusal of the whole merge. One file is one item's: a skill re-filed as a note whose file the run's own kept note
59
- * (or an earlier re-filed skill) takes is dropped, saying so (NOTE_NAME_IN_RUN), so one text is written and the item
60
- * that holds it is the one whose hold it keeps. Against main: a note main holds the same is no change, dropped unsaid
61
- * (SAME_NOTE); one whose own front matter supersedes the note of its name is a modification, written over it
62
- * (`replace`, main's blob in `graded`, so a change since is a conflict); any other is dropped, saying so
63
- * (NOTE_NAME_TAKEN), and main's note stands. No suffixed name: it would hold the same rule twice. A rule another note
64
- * holds is the merge's own to settle, against the main it commits on (learn/commit.ts mergeOf). Merge when the grader
65
- * said so and it still keeps an item. */
66
- /** Whether `held`, the note main holds at `file`, says the same rule as `text`: their bodies, whitespace and case aside
67
- * (notes.ts ruleOf), as readMain and the merge's own settle (learn/commit.ts) read it, whatever their front matter. A
68
- * text that is no note is the same only when it is the same text. */
69
- /** The rule a re-filed note says (notes.ts ruleOf), "" when its text is no note: what the merge checks main still holds
70
- * before it retires the skill that note replaces. */
71
- const ruleOfText = (file, text) => {
72
- const note = parseNoteFile(file, text);
73
- return Array.isArray(note) ? "" : ruleOf(note.body);
74
- };
75
- const sameRule = (file, held, text) => {
76
- const [theirs, ours] = [parseNoteFile(file, held), parseNoteFile(file, text)];
77
- return !Array.isArray(theirs) && !Array.isArray(ours) ? ruleOf(theirs.body) === ruleOf(ours.body) : held === text;
78
- };
79
- export function takenOnMain(proposal, verdict, onMain) {
80
- const texts = new Map(proposal.notes.map(({ file, text }) => [file, text]));
81
- const replace = [];
82
- const graded = {};
83
- const items = oneItemAFile(proposal, verdict).items.map((item) => {
84
- const note = item.note ?? (texts.has(item.file) ? { file: item.file, text: texts.get(item.file) } : undefined);
85
- const held = item.keep && note ? onMain[note.file] : undefined;
86
- if (!note || held === undefined)
87
- return item;
88
- const identical = held === note.text || held === mergedNote(note.text, { origin: item.origin ?? "run", ...(item.pending ? { pending: true } : {}) });
89
- const parsed = parseNoteFile(note.file, note.text);
90
- // One that supersedes the note of its own name and is not the very text main holds: a modification, written over it.
91
- if (!identical && !item.note && !Array.isArray(parsed) && parsed.supersedes.includes(note.file)) {
92
- replace.push(note.file);
93
- graded[note.file] = blobOid(held);
94
- return item;
95
- }
96
- // Else the same rule an active note of main keeps (whatever its front matter, case or spacing) is no change, dropped
97
- // unsaid, and a skill re-filed as it retired (mergeChangeOf); a retired or superseded note of that rule keeps it out
98
- // of every run, so it is a name main holds, and nothing is retired: the rule never vanishes. Any other is a name main
99
- // holds with another rule.
100
- const theirs = parseNoteFile(note.file, held);
101
- const same = !Array.isArray(theirs) && theirs.status === "active" && (identical || sameRule(note.file, held, note.text));
102
- return { file: item.file, keep: false, question: "Duplicate", why: same ? SAME_NOTE : NOTE_NAME_TAKEN(note.file.replace(/\.md$/, "")), ...(item.note ? { note: item.note } : {}) };
103
- });
104
- return { verdict: { ...verdict, items, merge: verdict.merge && items.some((item) => item.keep) }, replace, graded };
105
- }
106
- /** `verdict` with one item per file a kept note is written as, within the run: the files the run's own kept notes are,
107
- * then each re-filed skill's as it is kept; a re-filed skill whose note file one of those takes is left out, saying so
108
- * (NOTE_NAME_IN_RUN). The merge (takenOnMain) and its resume (resumedOf, from the saved grade) settle it the one way. */
109
- export function oneItemAFile(proposal, verdict) {
110
- const own = new Set(proposal.notes.map(({ file }) => file));
111
- const claimed = new Set(verdict.items.filter((item) => item.keep && !item.note && own.has(item.file)).map((item) => item.file));
112
- const items = verdict.items.map((item) => {
113
- if (!item.keep || !item.note)
114
- return item;
115
- if (claimed.has(item.note.file))
116
- return { file: item.file, keep: false, question: "Duplicate", why: NOTE_NAME_IN_RUN(item.note.file.replace(/\.md$/, "")) };
117
- claimed.add(item.note.file);
118
- return item;
119
- });
120
- return { ...verdict, items, merge: verdict.merge && items.some((item) => item.keep) };
121
- }
122
- /** `proposal` with only what `verdict` keeps (a verdict per item): a note or file its item keeps or holds; a skill its
123
- * item re-filed (`note`: a standing rule for every reply) is kept as that note instead, never as a skill. */
124
- export function keptOf(proposal, verdict) {
125
- if (!verdict.items.length)
126
- return proposal;
127
- const kept = new Set(verdict.items.filter((item) => item.keep && !item.note).map((item) => item.file));
128
- const refiled = verdict.items.flatMap((item) => (item.keep && item.note ? [item.note] : []));
129
- return { ...proposal, notes: [...proposal.notes.filter(({ file }) => kept.has(file)), ...refiled], files: (proposal.files ?? []).filter(({ file }) => kept.has(itemOf(file))) };
130
- }
131
- /** Each item the verdict keeps by the file it is merged as: a re-filed skill's item by its note's file too. A dropped
132
- * item names no file it merges as; of two kept items for one file (takenOnMain lets none through), the held one stands,
133
- * so a hold is never lost to the order of the items. */
134
- const itemsByFile = (verdict) => {
135
- const byFile = new Map();
136
- for (const item of verdict.items.filter((one) => one.keep)) {
137
- for (const file of [item.file, ...(item.note ? [item.note.file] : [])])
138
- if (!byFile.get(file)?.pending)
139
- byFile.set(file, item);
140
- }
141
- return byFile;
142
- };
143
- /** The merge of `merging` (what the verdict kept), the one rule learningCommit's merge is made by: each note with
144
- * the origin its item gives (`you` for the user's own words, else the run's) and held for its owner's OK when its item
145
- * is pending; a skill's SKILL.md or a draft's README.md held when its item is (a draft's workflow.json is held by its
146
- * README); and the seed the source run started from, so a skill's or draft's file changed on main since is a conflict
147
- * (a revised workflow's file: changed since the commit its compile ask read it at, `bases`). */
148
- export function mergeChangeOf(runId, merging, verdict, graded, round = 1) {
149
- const judged = itemsByFile(verdict);
150
- const notes = merging.notes.map(({ file, text }) => ({ path: file, text: mergedNote(text, { origin: judged.get(file)?.origin ?? "run" }) }));
151
- const files = (merging.files ?? []).map(({ file, text }) => ({ path: file, text }));
152
- const held = [
153
- ...merging.notes.filter(({ file }) => judged.get(file)?.pending === true).map(({ file }) => file),
154
- ...files.filter(({ path }) => learnedPlace(path)?.kind !== "workflow" && judged.get(itemOf(path))?.pending === true).map(({ path }) => path),
155
- ];
156
- // Each skill re-filed as a note is retired on main in the same write (learn/commit.ts mergeOf): a kept one, and one
157
- // main already holds the same rule of as a note (dropped unsaid), so no old skill stays served beside its note.
158
- const retire = verdict.items.flatMap((item) => (item.note && (item.keep || item.why === SAME_NOTE) && learnedPlace(item.file)?.kind === "skill" ? [{ skill: item.file, note: item.note.file, rule: ruleOfText(item.note.file, item.note.text) }] : []));
159
- // The compiled draft, when the verdict keeps it: the notes it does the work of are marked as it merges.
160
- const compiled = merging.compiled && files.some(({ path }) => path === `workflows/${merging.compiled.workflow}/workflow.json`) && merging.compiled.from_notes.length ? { workflow: merging.compiled.workflow, notes: [...merging.compiled.from_notes] } : undefined;
161
- return {
162
- kind: "merge", runId, ...(round > 1 ? { round } : {}), reason: verdict.reason || "The grader kept every new note.", files: [...notes, ...files],
163
- ...(held.length ? { held } : {}), graded, ...(merging.seed ? { seed: merging.seed } : {}), ...(merging.bases && Object.keys(merging.bases).length ? { bases: { ...merging.bases } } : {}), ...(retire.length ? { retire } : {}), ...(compiled ? { compiled } : {}),
164
- };
165
- }
166
- /** What a merge of `merging` learned, as the server's grade named it on the run (learning-run.ts grade): the notes it
167
- * added that runs read, with what each supersedes; the ones waiting for their owner's OK; its skills and workflow
168
- * drafts, each pending when it waits. The merge's words and the reader of a run's learning end (store-reads/learning.ts)
169
- * both name it so. */
170
- export function learnedOf(merging, verdict) {
171
- const waiting = new Set(verdict.items.filter((item) => item.pending).flatMap((item) => [item.file, ...(item.note ? [item.note.file] : [])]));
172
- const notes = merging.notes.flatMap(({ file, text }) => {
173
- const note = parseNoteFile(file, text);
174
- return Array.isArray(note) ? [] : [{ file, name: note.name, supersedes: note.supersedes }];
175
- });
176
- const made = (suffix) => (merging.files ?? []).filter(({ file }) => file.endsWith(suffix)).map(({ file }) => ({ file, name: file.split("/")[1], ...(waiting.has(file) ? { pending: true } : {}) }));
177
- return {
178
- learned: notes.filter(({ file }) => !waiting.has(file)),
179
- pending: notes.filter(({ file }) => waiting.has(file)).map(({ file, name }) => ({ file, name })),
180
- skills: made("/SKILL.md"),
181
- workflows: made("/workflow.json"),
182
- };
183
- }
184
- /** The merge's words, as the server's grade said them: what it learned (learnedOf), what the grader left out, and what
185
- * the checks left out (the kept row's `left`). */
186
- function mergedWords(merging, verdict, checked) {
187
- const { learned, pending, skills, workflows } = learnedOf(merging, verdict);
188
- // A re-filed rule main already holds the same is no change: never said.
189
- const left = verdict.items.filter((item) => !item.keep && item.why !== SAME_NOTE).map((item) => ({ why: item.why }));
190
- return said.merged(learned, pending, [...skills, ...workflows], left, checked);
191
- }
192
- /** `merging` and `verdict` once the merge left out `left` (learn/commit.ts LeftNote): each note it left out is no longer
193
- * merged, and its item is dropped, unsaid when its rule is held already (SAME_NOTE), else saying its name is taken. */
194
- export function leftOf(merging, verdict, left) {
195
- if (!left.length)
196
- return { merging, verdict };
197
- const why = new Map(left.map(({ path, reason }) => [path, reason === "same" ? SAME_NOTE : NOTE_NAME_TAKEN(path.replace(/\.md$/, ""))]));
198
- const items = verdict.items.map((item) => {
199
- const file = item.note?.file ?? item.file;
200
- return item.keep && why.has(file) ? { file: item.file, keep: false, question: "Duplicate", why: why.get(file), ...(item.note ? { note: item.note } : {}) } : item;
201
- });
202
- return { merging: { ...merging, notes: merging.notes.filter(({ file }) => !why.has(file)) }, verdict: { ...verdict, items } };
203
- }
204
- /** What a merge already on main settled (learn/commit.ts: its files, and `left`, the new notes it did not write): each
205
- * note the grade kept is kept when the merge wrote it, its path changed and main holding its rule there now (`onMain`,
206
- * the texts main holds at the kept notes' paths), else left out, saying why as takenOnMain said it (`taken`, its
207
- * verdict after main was read), or by main's text there (the same rule, or a name it holds with another), else as the
208
- * commit does. Skills and drafts as the grade kept them. */
209
- export function resumedOf(proposal, graded, taken, result, onMain) {
210
- const written = new Set(result.files);
211
- const texts = new Map(proposal.notes.map(({ file, text }) => [file, text]));
212
- const said = new Map((result.left ?? []).map(({ path, reason }) => [path, reason]));
213
- const notes = new Set(proposal.notes.map(({ file }) => file));
214
- // One item per file, as the first attempt's takenOnMain settled it: the saved grade keeps both a run's note and a skill
215
- // re-filed as a note of its file, and only one of them was written.
216
- const settled = oneItemAFile(proposal, graded);
217
- const items = settled.items.map((item, i) => {
218
- const file = item.note?.file ?? item.file;
219
- if (!item.keep || !(item.note || notes.has(file)))
220
- return item;
221
- // Saved: the merge changed its path and main holds its rule there now (`onMain`, read after the merge). A path the
222
- // merge changed for another reason (a note it marked superseded) holds another rule, and saves no item of its own.
223
- const text = item.note?.text ?? texts.get(file);
224
- const held = onMain[file];
225
- if (written.has(file) && (held === undefined || text === undefined || sameRule(file, held, text)))
226
- return item;
227
- const before = taken.items[i];
228
- if (before && !before.keep && before.why !== SAME_NOTE)
229
- return before;
230
- const same = held !== undefined && text !== undefined ? sameRule(file, held, text) : said.get(file) !== "taken";
231
- const why = same ? SAME_NOTE : NOTE_NAME_TAKEN(file.replace(/\.md$/, ""));
232
- return { file: item.file, keep: false, question: "Duplicate", why, ...(item.note ? { note: item.note } : {}) };
233
- });
234
- const verdict = { ...settled, items };
235
- return { merging: keptOf(proposal, verdict), verdict };
236
- }
237
- /** The skills and drafts a proposal names, by their item's file: what a merge the grader refused loses (notKept). */
238
- export const lostOf = (proposal) => (proposal.files ?? []).flatMap(({ file }) => {
239
- const place = learnedPlace(file);
240
- return place && place.kind !== "readme" ? [{ file, name: place.name }] : [];
241
- });
242
- export function createLearningLoop(learning) {
243
- return (deps) => {
244
- let stopped = null;
245
- const now = learning.now ?? Date.now;
246
- /** Aborted by a person's stop (a stop row): the grade's request is cut at once, never left running past it, while the
247
- * claim's signal stays whole so the stopped end is still written. */
248
- const stopAsk = new AbortController();
249
- return {
250
- async command(_command) {
251
- return { refused: "a learning run takes no messages or answers" };
252
- },
253
- async stop(reason) {
254
- stopped = reason;
255
- if (reason.kind === "command")
256
- stopAsk.abort(new Error("the run was stopped"));
257
- },
258
- async start(claim) {
259
- const context = withAbortSignal(deps.signal, BACKGROUND_CONTEXT);
260
- const journal = deps.journal(claim);
261
- let rooted = false;
262
- /** What the grade spent, as the run's learning end reads it (store-reads/learning.ts runLearningEnd): the graded
263
- * entry's, a failed or cut grade's (null: unknown), else nothing graded, 0. Kept as the learning run's cost when it
264
- * ends ended, failed or stopped, so what learning spent reads from the run rows alone (store learning.spend): a
265
- * stop seen after a paid grade never hides it. */
266
- let spend = 0;
267
- /** One entry on the root, committed; `end` stages the run's state with it (keyed to this entry, its effect), and
268
- * `take` the stop row it applies. An end that ends, fails or stops the run keeps what the grade spent as its cost. */
269
- const append = async (kind, data, end, take) => {
270
- const writes = [];
271
- if (kind === KINDS.learningDropped && data !== null && typeof data === "object" && "usd" in data)
272
- spend = data.usd ?? null;
273
- if (!rooted && !(await journal.conversation(ROOT, context)))
274
- writes.push({ type: "conversation", value: { id: ROOT } });
275
- const id = await journal.mintId();
276
- writes.push({ type: "entry", value: { id, conversationId: ROOT, kind, data } });
277
- if (end)
278
- journal.stage({ run: { state: end, ...(end === "parked" ? {} : { costUsd: spend }) }, effect: id, ...(take !== undefined ? { take: [{ command: take, effect: id }] } : {}) });
279
- const result = await journal.commit([writes], () => { }, context);
280
- if (result.stored === 0)
281
- throw result.refused;
282
- rooted = true;
283
- };
284
- /** A stop row ends the run stopped, its row taken in that end; a lost claim or a shutdown writes nothing more. */
285
- const halted = async () => {
286
- if (!stopped)
287
- return null;
288
- if (stopped.kind !== "command")
289
- return { state: "interrupted" };
290
- await append(KINDS.end, { state: "stopped" }, "stopped", stopped.commandId);
291
- return { state: "stopped" };
292
- };
293
- const source = await learning.sourceOf(claim.runId);
294
- if (!source) {
295
- await append(KINDS.learningDropped, { source: "", reason: "no_source", detail: said.stopped(STOPPED.notChecked) }, "failed");
296
- return { state: "failed", error: { code: "learning_no_source", message: "the learning run names no run that learned" } };
297
- }
298
- if (source.policyError) {
299
- await append(KINDS.learningDropped, { source: source.runId, reason: "checker", detail: source.policyError }, "ended");
300
- return { state: "ended" };
301
- }
302
- const round = source.round ?? 1;
303
- const kept = await learning.proposal(source.runId, round);
304
- if (!kept) {
305
- await append(KINDS.learningDropped, { source: source.runId, reason: "no_proposal", detail: said.stopped(STOPPED.notChecked) }, "ended");
306
- return { state: "ended" };
307
- }
308
- // The row as the end-of-run hook keeps it: its state and words, the kept Proposal inside (a drop queues no learning
309
- // run, so a row that isn't proposed is read as nothing to grade).
310
- const row = kept.proposal;
311
- if (row?.state !== "proposed" || !row.proposal) {
312
- await append(KINDS.learningDropped, { source: source.runId, reason: "no_proposal", detail: said.stopped(STOPPED.notChecked) }, "ended");
313
- return { state: "ended" };
314
- }
315
- const proposal = row.proposal;
316
- // What the checks left out of the proposal (propose.ts Proposed `left`), said with the merge.
317
- const checked = Array.isArray(row.left) ? row.left : [];
318
- /** The grade and the merge, on the agent's learning folder `ws`. */
319
- const onFolder = async (ws) => {
320
- const entries = await journalEntries(journal, context);
321
- rooted = entries.length > 0;
322
- const unavailable = entries.filter((entry) => entry.kind === KINDS.learningUnavailable).length;
323
- // The grade: once. A verdict already in the journal is the one the merge goes on.
324
- let graded = entries.find((entry) => entry.kind === KINDS.learningGraded)?.data;
325
- if (graded)
326
- spend = graded.usd;
327
- if (!graded) {
328
- const main = await learning.readMain(ws, proposal);
329
- if ("problems" in main) {
330
- await append(KINDS.learningDropped, { source: source.runId, reason: "checker", detail: said.stale(main.problems), problems: main.problems }, "ended");
331
- return { state: "ended" };
332
- }
333
- // A note named like one main holds now is settled alone, out of the grade (readMain's `taken`); the rest is
334
- // graded. Nothing left to grade keeps nothing.
335
- const taken = new Map((main.taken ?? []).map(({ path, reason }) => [path, reason]));
336
- let grading = proposal.notes.filter(({ file }) => !taken.has(file));
337
- const settledItems = [...taken].map(([file, reason]) => ({ file, keep: false, question: "Duplicate", why: reason === "same" ? SAME_NOTE : NOTE_NAME_TAKEN(file.replace(/\.md$/, "")) }));
338
- // What the grader spends, as the server's grade counted it (grade.ts counter): each ask's dollars and tokens
339
- // added, either unknown (null) once any ask's is, and an ask that fails spent what nobody knows.
340
- let usd = 0;
341
- let tokens = { input: 0, cache_read: 0, cache_write: 0, output: 0 };
342
- // The notes the graded ones supersede, of those main gave: a dropped note's are not the grade's.
343
- const replacing = new Set(grading.flatMap((note) => { const parsed = parseNoteFile(note.file, note.text); return Array.isArray(parsed) ? [] : parsed.supersedes; }));
344
- const superseded = main.superseded.filter(({ file }) => replacing.has(file));
345
- if (!grading.length && !proposal.files?.length) {
346
- const verdict = { merge: false, reason: "Every new note is named like one the agent holds now.", items: settledItems };
347
- await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(verdict, lostOf(proposal)), usd, tokens }, "ended");
348
- return { state: "ended" };
349
- }
350
- const items = gradedItems(grading, (proposal.files ?? []));
351
- let prompt;
352
- try {
353
- prompt = gradePrompt({
354
- run: source.runId, ...(source.instructions ? { instructions: source.instructions } : {}), active: main.active, superseded, proposed: grading,
355
- ...(source.nativeInstructions ? { nativeInstructions: true } : {}),
356
- ...(proposal.files?.length ? { files: proposal.files } : {}), ...(proposal.dryRuns ? { dryRuns: proposal.dryRuns } : {}), ...(proposal.drafted?.length ? { drafted: proposal.drafted } : {}), ...(proposal.asked ? { asked: proposal.asked } : {}), ...(proposal.triggered ? { triggered: proposal.triggered } : {}), ...(proposal.held ? { held: proposal.held } : {}),
357
- });
358
- }
359
- catch (error) {
360
- // A full native policy can fill the remaining prompt budget. Refuse the whole proposal visibly;
361
- // no grader was called and no standing instruction or proposal is silently omitted.
362
- await append(KINDS.learningDropped, { source: source.runId, reason: "checker", detail: error instanceof Error ? error.message : "The grading evidence exceeds the supported prompt budget.", usd, tokens }, "ended");
363
- return { state: "ended" };
364
- }
365
- /** The asks of this attempt that answered: the records holding more requests than these is an earlier attempt's. */
366
- let answered = 0;
367
- // Once an ask read the grade's records (`booked`), its dollars are theirs: an earlier attempt's requests counted too.
368
- const fromRecords = (booked) => {
369
- if (!booked)
370
- return;
371
- usd = booked.usd;
372
- // A request an earlier attempt sent (a restart before the grade was saved): its dollars are in the records,
373
- // its tokens in nothing this attempt read, so they are unknown, never none.
374
- if (booked.turns > answered)
375
- tokens = null;
376
- };
377
- // `again`: what the grade is told after its last answer, below the same prompt.
378
- const ask = async (again) => {
379
- // Stopped before this ask: nothing is sent, so nothing of it is spent (what it spent stays as it was).
380
- if (stopAsk.signal.aborted)
381
- throw stopAsk.signal.reason;
382
- const timer = AbortSignal.timeout(GRADE_TIMEOUT_MS);
383
- let answer;
384
- try {
385
- answer = await learning.ask({ prompt: again ? `${prompt}\n\n${again}` : prompt, maxTokens: GRADE_MAX_TOKENS }, AbortSignal.any([deps.signal, timer, stopAsk.signal]), { journal: () => deps.journal(claim), flush: () => deps.flush() });
386
- }
387
- catch (error) {
388
- // A call the cap refused was never sent: it spent nothing, and what the grade spent before it stands, as its
389
- // records hold it (an earlier attempt's included).
390
- if (error instanceof GradeOverCap)
391
- fromRecords(error.booked);
392
- else {
393
- usd = null;
394
- tokens = null;
395
- }
396
- throw error;
397
- }
398
- answered += 1;
399
- usd = usd === null || answer.usd === null || !Number.isFinite(answer.usd) ? null : usd + answer.usd;
400
- const more = answer.tokens ?? null;
401
- tokens = tokens === null || more === null ? null : { input: tokens.input + more.input, cache_read: tokens.cache_read + more.cache_read, cache_write: tokens.cache_write + more.cache_write, output: tokens.output + more.output };
402
- fromRecords(answer.booked);
403
- return answer.text;
404
- };
405
- let verdict;
406
- try {
407
- verdict = parseVerdict(await ask(), items, proposal.held);
408
- // An answer the host cannot read is asked once more, as the server's grade did.
409
- if (verdict.reason === UNREADABLE_REASON && !verdict.items.length)
410
- verdict = parseVerdict(await ask(), items, proposal.held);
411
- // One that kept every item and said no merge contradicts itself: asked once more, the contradiction named. A
412
- // second contradiction stands as no merge, said in the host's words as twice (learning-words.ts notKept); a
413
- // contradiction after an unreadable answer is one, and is said so.
414
- else if (verdict.reason === CONTRADICTED_REASON) {
415
- const again = parseVerdict(await ask(CONTRADICTION_ASK), items, proposal.held);
416
- verdict = again.reason === CONTRADICTED_REASON ? { ...again, reason: CONTRADICTED_TWICE_REASON } : again;
417
- }
418
- }
419
- catch (error) {
420
- // What the asks spent (and the check before them): a cut one's unknown (null), kept on a stopped run's row as
421
- // on a dropped one's.
422
- spend = usd;
423
- const end = await halted();
424
- if (end)
425
- return end;
426
- // No room under the run's cap for the grade (a call the cap refused): skipped, said so, with what it spent
427
- // before (an earlier ask's), never a failure and never past the cap.
428
- if (error instanceof GradeOverCap) {
429
- await append(KINDS.learningDropped, { source: source.runId, reason: "no_budget", detail: error.forGood ? said.gradeUncapped : said.noRoomToGrade, usd, tokens }, "ended");
430
- return { state: "ended" };
431
- }
432
- await append(KINDS.learningDropped, { source: source.runId, reason: "grade_failed", detail: said.stopped(STOPPED.noReview), usd, tokens }, "ended");
433
- void error;
434
- return { state: "ended" };
435
- }
436
- if (settledItems.length)
437
- verdict = { ...verdict, items: [...verdict.items, ...settledItems] };
438
- graded = { source: source.runId, verdict, usd, tokens, graded: main.graded };
439
- spend = graded.usd;
440
- await append(KINDS.learningGraded, graded);
441
- // The verdict is durable before the merge, its side effect.
442
- await deps.flush();
443
- }
444
- const halt = await halted();
445
- if (halt)
446
- return halt;
447
- // Each note it keeps whose file main already holds (another run merged one by that name since, or a skill
448
- // re-filed as one) is settled alone (takenOnMain): never written over unless it supersedes it, and never a
449
- // refusal of everything else the run learned. Not when this run's own merge is on main already (the runner
450
- // stopped after its commit, before it recorded it): the notes there are that merge's, never "already there", so
451
- // the grade's verdict goes to the commit, which answers with that merge, and each item is settled by the text that
452
- // merge's own commit holds at its file (resumedOf: its rule there, not only a changed path, and never main's
453
- // text now, which a person may have edited since).
454
- const notePaths = graded.verdict.items.flatMap((item) => (!item.keep ? [] : item.note ? [item.note.file] : proposal.notes.some(({ file }) => file === item.file) ? [item.file] : []));
455
- let onMain = {};
456
- let already = false;
457
- try {
458
- const merge = await learning.merged(ws, source.runId, notePaths, source.round);
459
- already = merge !== undefined;
460
- onMain = merge ? merge.texts : notePaths.length ? await learning.mainTexts(ws, notePaths) : {};
461
- }
462
- catch (error) {
463
- // Main could not be read: parked as for a write that could not reach the folder, tried again after a backoff.
464
- await append(KINDS.learningUnavailable, { source: source.runId, error: error?.message ?? String(error) }, "parked");
465
- return { state: "parked", wakeAt: now() + UNAVAILABLE_BACKOFF_MS[Math.min(unavailable, UNAVAILABLE_BACKOFF_MS.length - 1)] };
466
- }
467
- const taken = already ? { verdict: oneItemAFile(proposal, graded.verdict), replace: [], graded: {} } : takenOnMain(proposal, graded.verdict, onMain);
468
- const verdict = taken.verdict;
469
- const merging = keptOf(proposal, verdict);
470
- const change = mergeChangeOf(source.runId, merging, verdict, { ...graded.graded, ...taken.graded }, round);
471
- // Nothing new left to merge: dropped, unless the grader kept a re-filed skill whose rule main already holds as a
472
- // note (takenOnMain's SAME_NOTE). Its old SKILL.md is still retired (mergeChangeOf's retire), in a write of that
473
- // alone, so no old skill stays served beside the note.
474
- if (!verdict.merge && !(graded.verdict.merge && change.retire?.length)) {
475
- await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(verdict, lostOf(proposal)) }, "ended");
476
- return { state: "ended" };
477
- }
478
- const result = await learning.commit(ws, taken.replace.length ? { ...change, replace: taken.replace } : change);
479
- if (result.ok) {
480
- // What the merge left out against the main it committed on (a rule a note holds, a name one holds), each
481
- // item alone: said as takenOnMain says it, and nothing of it learned.
482
- // A merge already on main (a resume after its commit): what it wrote is what its files say, so each note is
483
- // settled by the files: one written is kept as the grade kept it, one not written is left out (as takenOnMain
484
- // or the commit says why).
485
- const settled = result.already ? resumedOf(proposal, graded.verdict, verdict, result, onMain) : leftOf(merging, verdict, result.left ?? []);
486
- if (!settled.verdict.items.some((item) => item.keep) && !result.files.length) {
487
- await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(settled.verdict, lostOf(proposal)) }, "ended");
488
- return { state: "ended" };
489
- }
490
- // A write that retired a skill alone learned nothing new: said so.
491
- const detail = mergedWords(settled.merging, settled.verdict, checked) || said.empty;
492
- await append(KINDS.learningMerged, { source: source.runId, main: result.main, commit: result.commit, files: result.files, detail, verdict: settled.verdict }, "ended");
493
- return { state: "ended" };
494
- }
495
- if (result.reason === "conflict") {
496
- await append(KINDS.learningDropped, { source: source.runId, reason: "checker", detail: said.stale(result.problems), problems: result.problems }, "ended");
497
- return { state: "ended" };
498
- }
499
- if (result.reason === "refused") {
500
- await append(KINDS.learningDropped, { source: source.runId, reason: "checker", detail: said.stale(result.problems), problems: result.problems }, "failed");
501
- return { state: "failed", error: { code: "learning_refused", message: result.problems.map((problem) => problem.detail).join("; ") } };
502
- }
503
- // The folder could not be reached: parked, and tried again after a backoff, never in a hot loop.
504
- const error = "error" in result ? result.error : "the learning folder could not be reached";
505
- await append(KINDS.learningUnavailable, { source: source.runId, error }, "parked");
506
- const wait = UNAVAILABLE_BACKOFF_MS[Math.min(unavailable, UNAVAILABLE_BACKOFF_MS.length - 1)];
507
- return { state: "parked", wakeAt: now() + wait };
508
- };
509
- // The folder is ended once the run is done with it, whichever way it goes out. Its end only sweeps what an exec
510
- // left behind (on Archil, the spill), after the run's own end is committed: a failed sweep changes no end.
511
- const folder = learning.folder(source.agentId);
512
- try {
513
- return await onFolder(folder.workspace);
514
- }
515
- finally {
516
- await folder.end().catch(() => { });
517
- }
518
- },
519
- };
520
- };
521
- }
package/dist/usage.d.ts DELETED
@@ -1,11 +0,0 @@
1
- /** The files of the notes a run was given and read; a list left with none is absent. */
2
- export type NoteFiles = {
3
- given?: string[];
4
- read?: string[];
5
- };
6
- /** A learning's notes ({file, name}) as files: an entry without a string `file` is skipped, so a learning saved out of
7
- * shape never stops a reader. */
8
- export declare const notesOf: (learning: {
9
- given?: unknown;
10
- read?: unknown;
11
- }) => NoteFiles;
package/dist/usage.js DELETED
@@ -1,11 +0,0 @@
1
- // A learning's notes as files: the notes a run was given and read (learning.ts Learning), each by its file, as the store's
2
- // learning reads (store-reads/learning.ts) and a learning run (learning-run.ts) count them.
3
- import { isObject } from "./validate.js";
4
- const filesOf = (source, fileOf) => {
5
- const files = (list) => (Array.isArray(list) ? list.flatMap((entry) => { const file = fileOf(entry); return typeof file === "string" ? [file] : []; }) : []);
6
- const [given, read] = [files(source.given), files(source.read)];
7
- return { ...(given.length ? { given } : {}), ...(read.length ? { read } : {}) };
8
- };
9
- /** A learning's notes ({file, name}) as files: an entry without a string `file` is skipped, so a learning saved out of
10
- * shape never stops a reader. */
11
- export const notesOf = (learning) => filesOf(learning, (entry) => (isObject(entry) ? entry.file : undefined));
@@ -1 +0,0 @@
1
- - [We don't sell to agencies](no-agencies.md) — agencies are never customers, even ones that build for fintechs
@@ -1,14 +0,0 @@
1
- ---
2
- name: We don't sell to agencies
3
- description: Agencies are never customers, even ones that build for fintechs
4
- type: feedback
5
- origin: you
6
- ---
7
- We don't sell to agencies: marketing, design, development or consulting shops that build products for clients. Treat
8
- being one as a disqualifier, even when their clients are fintechs and even when they want to embed or resell our checks.
9
-
10
- **Why:** the owner marked an agency lead scored 78 as wrong (2026-10-30): an agency doesn't run its own KYB, its
11
- clients do, and we sell to them directly.
12
-
13
- **How to apply:** add a disqualifier criterion "marketing, design, development or consulting agencies"; a lead whose
14
- company is one is disqualified, and the reason names this note.
@@ -1,21 +0,0 @@
1
- ---
2
- type: llm
3
- ---
4
- The run starts with one learned note under `# Learned`, `no-agencies.md`: "We don't sell to agencies ... a
5
- disqualifier, even when their clients are fintechs and even when they want to embed or resell our checks." The lead is
6
- Riley Vantongeren, Director of Client Engagements at thoughtbot (thoughtbot.com), a design and development consultancy
7
- that, per the message, builds onboarding flows for US fintech clients and wants to embed the owner's KYB checks. The
8
- ICP alone, without the note, could read this lead as fintech-adjacent.
9
-
10
- Pass only if all of these hold in the brief (the last fenced `json` block):
11
-
12
- 1. `fit.criteria` holds a criterion with `origin` `learned`, `note` `no-agencies.md`, `kind` `disqualifier`, about
13
- agencies, with `weight` 0 and `met` `true`, and `fit.computation.caps` holds `disqualifier_met`.
14
- 2. Its evidence says thoughtbot is a design, development or consulting agency that builds for clients, with a source (a
15
- thoughtbot.com page or another URL; `submission` alone passes only if it quotes the lead's own words "build ...
16
- for several US fintech clients").
17
- 3. `fit.score` is 10 or less and `next_step.action` is `disqualify`, its reason naming the agency rule or the learned
18
- note.
19
- 4. The brief doesn't treat the agency's fintech clients as the lead's own industry to lift the score.
20
- 5. Nothing about Riley Vantongeren is stated beyond the submission unless a cited source shows this same person at
21
- thoughtbot.
@@ -1 +0,0 @@
1
- - [Skip junior job posts](skip-junior-job-posts.md) — the owner doesn't want junior or entry-level postings in the digest
@@ -1,8 +0,0 @@
1
- ---
2
- name: Skip junior job posts
3
- description: Leave junior, entry-level and intern job postings out of every digest
4
- type: feedback
5
- ---
6
- The owner said: "Skip junior job posts. I don't care who they hire at the junior level, even in a new country."
7
- Leave junior, entry-level, graduate and intern postings out of the digest, whatever the rules file says about first
8
- roles in a new country.
@@ -1 +0,0 @@
1
- - [We say agent, not bot](say-agent-not-bot.md) — in release notes the product is an "agent", never a "bot", even where a PR says bot
@@ -1,13 +0,0 @@
1
- ---
2
- name: We say agent, not bot
3
- description: In release notes the product is an "agent", never a "bot", even where a PR says bot
4
- type: feedback
5
- origin: you
6
- ---
7
- We say "agent", not "bot", everywhere in release notes: the top sections and the table's summaries alike. Rewrite a PR
8
- title or body that says "bot" in its own words with "agent"; keep commands, flags and names exactly as they are.
9
-
10
- **Why:** the owner edited the v1.5.0 draft (2026-10-28), replacing every "bot" with "agent": the product is sold as an
11
- agent, and "bot" reads as a toy.
12
-
13
- **How to apply:** before posting, read the draft for "bot" or "bots" and say "agent" or "agents" instead.