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

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 (375) hide show
  1. package/CHANGELOG.md +325 -1
  2. package/README.md +332 -88
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/attach-conformance.js +5 -4
  11. package/dist/box-paths.d.ts +3 -2
  12. package/dist/box-paths.js +5 -4
  13. package/dist/browser-computer.d.ts +3 -8
  14. package/dist/browser-computer.js +12 -35
  15. package/dist/browser-cost.js +94 -20
  16. package/dist/capacity.d.ts +1 -1
  17. package/dist/capacity.js +3 -3
  18. package/dist/chatgpt-plan.d.ts +5 -0
  19. package/dist/chatgpt-plan.js +25 -11
  20. package/dist/claude-login-token.d.ts +15 -11
  21. package/dist/claude-login-token.js +167 -107
  22. package/dist/claude-login.d.ts +76 -31
  23. package/dist/claude-login.js +426 -79
  24. package/dist/claude-sign-in.d.ts +3 -0
  25. package/dist/claude-sign-in.js +10 -1
  26. package/dist/cli.js +323 -292
  27. package/dist/composio-made.d.ts +1 -6
  28. package/dist/composio-made.js +1 -6
  29. package/dist/composio-owners.d.ts +26 -0
  30. package/dist/composio-owners.js +36 -0
  31. package/dist/composio-preset.d.ts +56 -23
  32. package/dist/composio-preset.js +173 -77
  33. package/dist/composio-triggers.d.ts +4 -4
  34. package/dist/composio-triggers.js +6 -7
  35. package/dist/compute-cost.js +11 -2
  36. package/dist/computer-attach.d.ts +6 -3
  37. package/dist/computer-attach.js +41 -29
  38. package/dist/computer-held-routes.d.ts +1 -1
  39. package/dist/computer-held-routes.js +9 -4
  40. package/dist/computer-keys.d.ts +11 -1
  41. package/dist/computer-keys.js +26 -1
  42. package/dist/computer-record.js +3 -1
  43. package/dist/computer-view.d.ts +5 -3
  44. package/dist/computer-view.js +10 -6
  45. package/dist/computer-viewer.js +36 -7
  46. package/dist/computers.d.ts +2 -1
  47. package/dist/computers.js +6 -3
  48. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  49. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  50. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  51. package/dist/console/assets/share-L84tlUDW.js +6 -0
  52. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  53. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  54. package/dist/console/index.html +4 -3
  55. package/dist/console/share.html +17 -0
  56. package/dist/decisions.d.ts +17 -7
  57. package/dist/decisions.js +41 -15
  58. package/dist/dial-relay.js +10 -4
  59. package/dist/docker-daemon.js +4 -5
  60. package/dist/docker-host-addresses.js +29 -11
  61. package/dist/email/account.d.ts +6 -0
  62. package/dist/email/account.js +6 -0
  63. package/dist/email/authentication.d.ts +21 -0
  64. package/dist/email/authentication.js +106 -0
  65. package/dist/email/email-faux.d.ts +11 -2
  66. package/dist/email/email-faux.js +21 -5
  67. package/dist/email/mail.d.ts +25 -0
  68. package/dist/email/mail.js +58 -2
  69. package/dist/email/names.js +2 -2
  70. package/dist/email/tools.d.ts +9 -4
  71. package/dist/email/tools.js +95 -13
  72. package/dist/env-switch.d.ts +12 -2
  73. package/dist/env-switch.js +23 -3
  74. package/dist/errors.d.ts +1 -0
  75. package/dist/errors.js +2 -0
  76. package/dist/fal-price.d.ts +11 -1
  77. package/dist/fal-price.js +33 -0
  78. package/dist/faux-computers.js +1 -1
  79. package/dist/filed-answer.d.ts +2 -2
  80. package/dist/filed-answer.js +2 -2
  81. package/dist/graph-served.d.ts +10 -5
  82. package/dist/graph-served.js +40 -10
  83. package/dist/handed-values.js +1 -2
  84. package/dist/harness-check.d.ts +2 -1
  85. package/dist/harness-check.js +45 -12
  86. package/dist/harness-keys.js +9 -6
  87. package/dist/harness-opencode/facts.js +2 -0
  88. package/dist/harness-recipe-entry.d.ts +9 -3
  89. package/dist/harness-recipe-entry.js +18 -9
  90. package/dist/harness-recipe.d.ts +21 -0
  91. package/dist/harness-recipe.js +25 -3
  92. package/dist/harness-table.d.ts +8 -0
  93. package/dist/harness-table.js +17 -6
  94. package/dist/helper-env.d.ts +4 -1
  95. package/dist/helper-env.js +4 -1
  96. package/dist/host-check.d.ts +2 -3
  97. package/dist/host-check.js +13 -7
  98. package/dist/hosted-search.js +1 -1
  99. package/dist/import.d.ts +11 -8
  100. package/dist/import.js +437 -186
  101. package/dist/key-refusal.d.ts +9 -2
  102. package/dist/key-refusal.js +86 -32
  103. package/dist/learn/audit.d.ts +8 -5
  104. package/dist/learn/audit.js +15 -7
  105. package/dist/learn/compile.d.ts +5 -2
  106. package/dist/learn/compile.js +45 -21
  107. package/dist/learn/field-check.d.ts +111 -0
  108. package/dist/learn/field-check.js +174 -0
  109. package/dist/learn/ledger.d.ts +32 -29
  110. package/dist/learn/ledger.js +26 -19
  111. package/dist/learn/promote.d.ts +79 -36
  112. package/dist/learn/promote.js +60 -65
  113. package/dist/learn/secrets.d.ts +4 -0
  114. package/dist/learn/secrets.js +12 -0
  115. package/dist/learned-nodes.d.ts +8 -5
  116. package/dist/learned-nodes.js +8 -5
  117. package/dist/learned-workflow.d.ts +2 -1
  118. package/dist/learned-workflow.js +13 -10
  119. package/dist/learning-cost.d.ts +25 -8
  120. package/dist/learning-cost.js +23 -8
  121. package/dist/learning-setting.d.ts +6 -0
  122. package/dist/learning-setting.js +11 -1
  123. package/dist/listen-first.d.ts +5 -4
  124. package/dist/listen-first.js +4 -5
  125. package/dist/live-reach.d.ts +7 -0
  126. package/dist/live-reach.js +7 -0
  127. package/dist/mcp-api-only-origins.d.ts +15 -0
  128. package/dist/mcp-api-only-origins.js +40 -0
  129. package/dist/mcp-gateway.d.ts +16 -2
  130. package/dist/mcp-gateway.js +41 -3
  131. package/dist/mcp-oauth.d.ts +1 -1
  132. package/dist/mcp-oauth.js +3 -2
  133. package/dist/mcp-probe.d.ts +3 -0
  134. package/dist/mcp-probe.js +3 -0
  135. package/dist/mcp-secret-writes.d.ts +24 -2
  136. package/dist/mcp-secret-writes.js +30 -2
  137. package/dist/mcp-servers-store.d.ts +52 -14
  138. package/dist/mcp-servers-store.js +165 -61
  139. package/dist/mcp-sources.d.ts +1 -2
  140. package/dist/mcp-sources.js +1 -2
  141. package/dist/mcp-store.d.ts +5 -5
  142. package/dist/mcp-store.js +3 -3
  143. package/dist/mcp.js +1 -1
  144. package/dist/model-gateway.d.ts +1 -1
  145. package/dist/model-gateway.js +20 -36
  146. package/dist/ollama-provider.d.ts +23 -9
  147. package/dist/ollama-provider.js +49 -20
  148. package/dist/openapi.js +202 -51
  149. package/dist/otel/genai.d.ts +83 -7
  150. package/dist/otel/genai.js +69 -9
  151. package/dist/otel/tracer.d.ts +42 -13
  152. package/dist/otel/tracer.js +241 -56
  153. package/dist/page.d.ts +7 -1
  154. package/dist/page.js +76 -22
  155. package/dist/paid-calls.d.ts +6 -4
  156. package/dist/paid-calls.js +15 -7
  157. package/dist/place-offers.d.ts +55 -34
  158. package/dist/place-offers.js +93 -54
  159. package/dist/place.d.ts +13 -14
  160. package/dist/place.js +56 -41
  161. package/dist/print.js +1 -1
  162. package/dist/provider.d.ts +3 -2
  163. package/dist/provider.js +17 -8
  164. package/dist/redact/match.d.ts +27 -9
  165. package/dist/redact/match.js +266 -57
  166. package/dist/run-census.d.ts +1 -1
  167. package/dist/run-census.js +4 -5
  168. package/dist/run-cut.js +4 -5
  169. package/dist/run-export-store.d.ts +15 -0
  170. package/dist/run-export-store.js +30 -0
  171. package/dist/run-export.d.ts +139 -0
  172. package/dist/run-export.js +379 -0
  173. package/dist/run-file-cut.d.ts +5 -0
  174. package/dist/run-file-cut.js +13 -0
  175. package/dist/run-launch.js +16 -3
  176. package/dist/run-model-key.d.ts +15 -6
  177. package/dist/run-model-key.js +30 -31
  178. package/dist/run-reads-over-store.js +4 -4
  179. package/dist/run-secrets.js +3 -5
  180. package/dist/run-timeline-served.js +3 -1
  181. package/dist/runnable.js +2 -2
  182. package/dist/runner/adapter-loop.d.ts +35 -18
  183. package/dist/runner/adapter-loop.js +94 -47
  184. package/dist/runner/adapter-run-spec.d.ts +14 -1
  185. package/dist/runner/adapter-run-spec.js +64 -28
  186. package/dist/runner/adapters/pi.js +4 -2
  187. package/dist/runner/audit.d.ts +8 -5
  188. package/dist/runner/audit.js +37 -17
  189. package/dist/runner/beside.js +5 -6
  190. package/dist/runner/claim-secrets.d.ts +10 -3
  191. package/dist/runner/claim-secrets.js +29 -13
  192. package/dist/runner/cli-run-spec.d.ts +18 -0
  193. package/dist/runner/cli-run-spec.js +81 -46
  194. package/dist/runner/compare-end.d.ts +2 -1
  195. package/dist/runner/compare-end.js +25 -10
  196. package/dist/runner/conformance/harness.js +2 -3
  197. package/dist/runner/conformance/subject.d.ts +4 -1
  198. package/dist/runner/harness-loops.js +3 -3
  199. package/dist/runner/held.d.ts +5 -2
  200. package/dist/runner/journal-kinds.d.ts +4 -1
  201. package/dist/runner/journal-kinds.js +22 -4
  202. package/dist/runner/learned-first.js +20 -4
  203. package/dist/runner/learning-end.d.ts +2 -8
  204. package/dist/runner/learning-end.js +11 -19
  205. package/dist/runner/live-ticker.js +7 -5
  206. package/dist/runner/loop-contract.d.ts +0 -2
  207. package/dist/runner/loop.d.ts +7 -0
  208. package/dist/runner/loop.js +1 -0
  209. package/dist/runner/main.js +12 -11
  210. package/dist/runner/mcp-claim.js +21 -5
  211. package/dist/runner/meta-tools.js +3 -2
  212. package/dist/runner/metrics.d.ts +7 -0
  213. package/dist/runner/metrics.js +19 -0
  214. package/dist/runner/model-route.d.ts +10 -7
  215. package/dist/runner/model-route.js +79 -15
  216. package/dist/runner/native-loop.js +10 -8
  217. package/dist/runner/presence.d.ts +1 -4
  218. package/dist/runner/presence.js +6 -8
  219. package/dist/runner/promotion.d.ts +25 -13
  220. package/dist/runner/promotion.js +125 -50
  221. package/dist/runner/redact.d.ts +3 -1
  222. package/dist/runner/redact.js +5 -3
  223. package/dist/runner/responses-fetch.d.ts +36 -0
  224. package/dist/runner/responses-fetch.js +511 -0
  225. package/dist/runner/run-child-host.d.ts +20 -5
  226. package/dist/runner/run-child-host.js +179 -77
  227. package/dist/runner/run-child.js +11 -4
  228. package/dist/runner/runner-check.js +5 -1
  229. package/dist/runner/runner.d.ts +2 -3
  230. package/dist/runner/runner.js +13 -9
  231. package/dist/runner/sdk-loop.js +8 -8
  232. package/dist/runner/spec-holds.d.ts +8 -1
  233. package/dist/runner/spec-holds.js +9 -4
  234. package/dist/runner/workflow-calls.d.ts +9 -0
  235. package/dist/runner/workflow-calls.js +150 -0
  236. package/dist/runner/workflow-first.d.ts +120 -32
  237. package/dist/runner/workflow-first.js +218 -94
  238. package/dist/runner/workflow-spec.js +1 -1
  239. package/dist/runs-over-store.js +8 -7
  240. package/dist/save-once.d.ts +14 -0
  241. package/dist/save-once.js +31 -0
  242. package/dist/scrub-command.d.ts +34 -31
  243. package/dist/scrub-command.js +116 -147
  244. package/dist/sdk/runs.d.ts +6 -0
  245. package/dist/sdk/runs.js +89 -10
  246. package/dist/seal-key.js +4 -4
  247. package/dist/secret-cut.d.ts +3 -0
  248. package/dist/secret-cut.js +7 -1
  249. package/dist/secret-rules.d.ts +8 -1
  250. package/dist/secret-rules.js +482 -53
  251. package/dist/secrets.d.ts +51 -9
  252. package/dist/secrets.js +311 -21
  253. package/dist/server-keys.d.ts +4 -3
  254. package/dist/server-keys.js +4 -3
  255. package/dist/server-secrets-store.js +2 -4
  256. package/dist/server.d.ts +15 -3
  257. package/dist/server.js +312 -80
  258. package/dist/share-context.d.ts +22 -0
  259. package/dist/share-context.js +76 -0
  260. package/dist/shell-lex.d.ts +105 -0
  261. package/dist/shell-lex.js +646 -0
  262. package/dist/sign-ins-store.d.ts +5 -7
  263. package/dist/sign-ins-store.js +12 -16
  264. package/dist/sign-ins.d.ts +7 -11
  265. package/dist/sign-ins.js +40 -41
  266. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  267. package/dist/start-switches.d.ts +6 -5
  268. package/dist/start-switches.js +8 -4
  269. package/dist/stats.d.ts +5 -1
  270. package/dist/stats.js +1 -1
  271. package/dist/store/agent-body.js +2 -2
  272. package/dist/store/dialect.d.ts +4 -0
  273. package/dist/store/dialect.js +1 -0
  274. package/dist/store/index.d.ts +2 -2
  275. package/dist/store/index.js +1 -1
  276. package/dist/store/mcp-record-keys.d.ts +10 -0
  277. package/dist/store/mcp-record-keys.js +13 -0
  278. package/dist/store/postgres/dialect.js +2 -0
  279. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  280. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  281. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  282. package/dist/store/postgres/store.js +4 -0
  283. package/dist/store/schema.d.ts +33 -10
  284. package/dist/store/schema.js +70 -16
  285. package/dist/store/seal.d.ts +4 -1
  286. package/dist/store/sqlite/run-launch.d.ts +3 -10
  287. package/dist/store/sqlite/run-launch.js +12 -23
  288. package/dist/store/sqlite/run-patch.d.ts +17 -10
  289. package/dist/store/sqlite/run-patch.js +50 -13
  290. package/dist/store/sqlite/store.d.ts +3 -0
  291. package/dist/store/sqlite/store.js +116 -34
  292. package/dist/store/store-schema.js +3 -4
  293. package/dist/store/store.d.ts +67 -32
  294. package/dist/store/store.js +14 -11
  295. package/dist/store-reads/analytics.d.ts +2 -1
  296. package/dist/store-reads/analytics.js +7 -5
  297. package/dist/store-reads/learning.d.ts +35 -26
  298. package/dist/store-reads/learning.js +120 -92
  299. package/dist/store-reads/stats.d.ts +2 -2
  300. package/dist/store-reads/stats.js +13 -7
  301. package/dist/store-view.js +10 -7
  302. package/dist/suggestions.d.ts +1 -1
  303. package/dist/suggestions.js +29 -13
  304. package/dist/template-eval.d.ts +72 -9
  305. package/dist/template-eval.js +358 -64
  306. package/dist/timeline/labels.d.ts +1 -1
  307. package/dist/timeline/labels.js +4 -3
  308. package/dist/timeline/timeline.d.ts +23 -11
  309. package/dist/timeline/timeline.js +115 -31
  310. package/dist/timeline/web-calls.d.ts +8 -6
  311. package/dist/timeline/web-calls.js +10 -6
  312. package/dist/tool-gate.d.ts +13 -1
  313. package/dist/tool-gate.js +43 -3
  314. package/dist/tool-keys-store.js +2 -4
  315. package/dist/tool-keys.d.ts +11 -0
  316. package/dist/tool-keys.js +16 -0
  317. package/dist/tool-plane.d.ts +50 -11
  318. package/dist/tool-plane.js +94 -30
  319. package/dist/tools.d.ts +5 -1
  320. package/dist/tools.js +7 -7
  321. package/dist/trigger-email.js +12 -6
  322. package/dist/triggers.d.ts +15 -34
  323. package/dist/triggers.js +119 -126
  324. package/dist/validate.d.ts +8 -1
  325. package/dist/validate.js +163 -23
  326. package/dist/web-fake.d.ts +2 -1
  327. package/dist/web-fake.js +8 -6
  328. package/dist/web-fetch.d.ts +8 -6
  329. package/dist/web-fetch.js +13 -11
  330. package/dist/web-holds.d.ts +32 -0
  331. package/dist/web-holds.js +86 -0
  332. package/dist/web-run.d.ts +32 -5
  333. package/dist/web-run.js +75 -28
  334. package/dist/web-save.js +23 -12
  335. package/dist/web-search.js +14 -25
  336. package/dist/wires.d.ts +4 -3
  337. package/dist/wires.js +5 -4
  338. package/dist/workspace/archil-claim.d.ts +12 -5
  339. package/dist/workspace/archil-claim.js +45 -5
  340. package/dist/workspace/attach.js +52 -19
  341. package/dist/workspace/attached-computers.d.ts +6 -2
  342. package/dist/workspace/attached-computers.js +5 -4
  343. package/dist/workspace/computer-deps.d.ts +23 -6
  344. package/dist/workspace/computer-deps.js +35 -17
  345. package/dist/workspace/computer-for-claim.d.ts +21 -4
  346. package/dist/workspace/computer-for-claim.js +160 -54
  347. package/dist/workspace/computer-intervals.d.ts +2 -0
  348. package/dist/workspace/computer-intervals.js +1 -1
  349. package/dist/workspace/computer-janitor.d.ts +48 -14
  350. package/dist/workspace/computer-janitor.js +153 -44
  351. package/dist/workspace/computer-kept.d.ts +158 -32
  352. package/dist/workspace/computer-kept.js +288 -63
  353. package/dist/workspace/computer-providers.d.ts +8 -3
  354. package/dist/workspace/computer-providers.js +12 -5
  355. package/dist/workspace/index.d.ts +1 -1
  356. package/dist/workspace/index.js +1 -1
  357. package/dist/workspace/local.js +41 -1
  358. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  359. package/dist/workspace/mount-revoke-left.js +72 -0
  360. package/dist/workspace/paired-route.js +4 -5
  361. package/dist/workspace/resolve-computer.d.ts +5 -2
  362. package/dist/workspace/resolve-computer.js +9 -3
  363. package/dist/workspace/run-end-computers.d.ts +11 -5
  364. package/dist/workspace/run-end-computers.js +153 -28
  365. package/dist/workspace/run-tools.d.ts +22 -3
  366. package/dist/workspace/run-tools.js +17 -5
  367. package/dist/workspace/run-workspace.d.ts +14 -1
  368. package/dist/workspace/run-workspace.js +34 -1
  369. package/dist/workspace/workspace.d.ts +6 -0
  370. package/package.json +12 -13
  371. package/skills/agentrun-serve/SKILL.md +5 -2
  372. package/templates/README.md +22 -6
  373. package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
  374. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  375. package/dist/console/assets/index-DPh29cyz.js +0 -747
@@ -4,7 +4,8 @@
4
4
  // or in a process of its own (runner/main.ts), so a server in another process, or on another host over one Postgres, reads
5
5
  // it. A runner in a process of its own with a relay (dial-relay.ts) says on the same row where its relay answers, under the
6
6
  // same incarnation (runner/main.ts makes one per process), so the server relays a dial only to a runner this row says is
7
- // there. Each row is renewed every PRESENCE_RENEW_MS and read as gone once it is PRESENCE_STALE_MS old: a runner that died
7
+ // there. Each row is renewed every PRESENCE_RENEW_MS and read as gone once it is the store's RUNNER_STALE_MS old (three
8
+ // renewals missed, the age the claim rule reads for a kept computer's pin too): a runner that died
8
9
  // without its close stops counting within that. While every runner still there refused, and one at least is, the server
9
10
  // refuses a launch in their words (runs-over-store.ts prepareLaunch), says so in capabilities and health, and fails the
10
11
  // runs still queued (server.ts). With no runner there at all (a server with --no-runner and its runner not started yet),
@@ -15,15 +16,12 @@ import { ApiError } from "../errors.js";
15
16
  import { RUNNER_STALE_MS } from "../store/store.js";
16
17
  /** How often a runner says again that it is there. */
17
18
  export const PRESENCE_RENEW_MS = 10_000;
18
- /** How old a runner's word can be and still count: three renewals missed. The store's (RUNNER_STALE_MS), which its claim
19
- * rule reads for a kept computer's pin. */
20
- export const PRESENCE_STALE_MS = RUNNER_STALE_MS;
21
- /** The runners whose relay takes dials now: their rows seen within PRESENCE_STALE_MS on the store's clock (Runners.live,
19
+ /** The runners whose relay takes dials now: their rows seen within RUNNER_STALE_MS on the store's clock (Runners.live,
22
20
  * the database's on Postgres), never one process's, that say where their relay answers. The server relays a dial only
23
21
  * to one of these (computer-attach.ts), says a dial provider is served while one answers at a host it dials (server.ts
24
22
  * relayed), and a paired computer's route to a runner not among them is stale (workspace/paired-route.ts). */
25
23
  export async function liveRelays(runners) {
26
- return (await runners.live(PRESENCE_STALE_MS)).filter((row) => row.host !== null && row.port !== null);
24
+ return (await runners.live(RUNNER_STALE_MS)).filter((row) => row.host !== null && row.port !== null);
27
25
  }
28
26
  /** This build's version (the serve package's), which every runner says on its row (runners.version) for the server's
29
27
  * capacity read (GET /v2/capacity). */
@@ -49,7 +47,7 @@ export function keepPresence(runners, runner, refused, { renewMs = PRESENCE_RENE
49
47
  // one Runners.renew, with the place it holds now) touches its own row only, or puts one where no other process of the
50
48
  // name is live (Runners.put unlessLiveMs): an older process overlapping a restart never takes the later one's row back,
51
49
  // nor clears its relay.
52
- const again = () => runners.put(row(), { unlessLiveMs: PRESENCE_STALE_MS });
50
+ const again = () => runners.put(row(), { unlessLiveMs: RUNNER_STALE_MS });
53
51
  // A refusal changed (refuse) and not yet on the row: a renewal only marks the row seen, so until a put of the row lands
54
52
  // each renewal is that put. A put that fails leaves it unsaid, for the next renewal.
55
53
  let unsaid = false;
@@ -110,7 +108,7 @@ export function keepPresence(runners, runner, refused, { renewMs = PRESENCE_RENE
110
108
  }
111
109
  /** Why no runner here can take a run, in the runners' own words, or undefined while one can (or none is there): the rows
112
110
  * seen within `staleMs` on the store's clock (Runners.live), when there is one at least and every one refused. */
113
- export async function runnersRefused(runners, staleMs = PRESENCE_STALE_MS) {
111
+ export async function runnersRefused(runners, staleMs = RUNNER_STALE_MS) {
114
112
  const live = await runners.live(staleMs);
115
113
  if (live.length === 0 || live.some((row) => row.refused === null))
116
114
  return undefined;
@@ -77,12 +77,13 @@ export declare function replayClaimed(store: Pick<Store, "settings">, agentId: s
77
77
  * laid one is not the digest it replays (the replay then fails, never scoring another revision). Any other run's, as laid. */
78
78
  export declare function replayLaid(launch: RunLaunch, laid: readonly LearnedWorkflow[]): LearnedWorkflow[];
79
79
  /** The learned workflows a run's learned_workflow tool runs, once its first choice is made: what serves, never a
80
- * revision its promotion has not promoted. The one its first choice served or the money rule stopped (laidFor: its
81
- * champion in place of the laid revision) as chosen; any other the records name, its champion (championOf: the laid
82
- * text when that is the champion, else its text at its record's commit), and none while nothing of it serves (none
83
- * promoted yet, or the champion held): a revision replaying, held or never decided is never handed to the agent to run
84
- * in its place. One the records never named is an unchecked draft and is not offered. A replay run's as
85
- * laid (replayLaid). The records unread: only the chosen one, as the gate leaves a run to its agent. */
80
+ * revision its promotion has not promoted. The one its first choice served (laidFor: its champion in place of the laid
81
+ * revision) as chosen; any other the records name, its champion (championOf: the laid text when that is the champion,
82
+ * else its text at its record's commit), and none while nothing of it serves (none promoted yet, or the champion
83
+ * held): a revision replaying, held or never decided is never handed to the agent to run in its place. One the records
84
+ * never named is an unchecked draft and is not offered. A replay run's as laid (replayLaid). The records unread: only
85
+ * the one served first, as the gate leaves a run to its agent. The money rule over what this hands the tool, the one
86
+ * its first choice stopped included, is runner/learned-first.ts's (workflow-first.ts toolStopsOf). */
86
87
  export declare function toolFlowsFor(deps: Pick<PromotionDeps, "store" | "agentId" | "champion" | "refused" | "log">, launch: RunLaunch, laid: readonly LearnedWorkflow[], choice: FirstChoice): Promise<LearnedWorkflow[]>;
87
88
  /** `flow`'s champion (championOf) and the text it serves from: `flow` itself when it is the champion, else the
88
89
  * champion's text read at its record's commit (`read`), kept only when its digest is the champion's. No text: none is
@@ -119,7 +120,9 @@ export declare const differentDecisionWords: (k: number, n: number, example: str
119
120
  /** One input a check ran its draft on: the agent's run (`of`) and its input, the agent's recorded answer, and what the
120
121
  * draft did: its answer when it answered alone, why it handed the input back, or failed (or skipped a write). A
121
122
  * reserved input whose replay run was never created, or never ended, by the check's deadline failed (`unstarted` for
122
- * the first). */
123
+ * the first). `expected` and `correct`: the agent run's newest grade (learn/promote.ts Grade), when it has one: its
124
+ * expected answer is the known answer (written over the agent's, or at each agree_on path it holds); and whether
125
+ * the agent's answer was right. */
123
126
  export type CheckRow = {
124
127
  readonly of: string;
125
128
  readonly input: string;
@@ -130,13 +133,22 @@ export type CheckRow = {
130
133
  readonly skipped?: Skipped;
131
134
  readonly unstarted?: true;
132
135
  readonly compared?: Compared;
136
+ readonly expected?: Readonly<Record<string, unknown>>;
137
+ readonly correct?: boolean;
133
138
  };
134
- /** Decides a check on its rows, with a connected agent's turns checked before them (`before`), scored on its bar
135
- * (scoreRows). Promoted when it clears the bar (checkPasses) and the purge gate lets its revision through at its commit
136
- * (`refused`: else held, a purged run's text); else held with the inputs it did not agree on, which the
137
- * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
138
- * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
139
- * (the one write: of two claims at once, one decides). */
139
+ /** The field a check judges a whole answer as, with no agree_on. */
140
+ export declare const WHOLE_ANSWER = "answer";
141
+ /** One answer judged as the check judges an input it answered alone (checkInputOf, learn/field-check.ts): `answer`
142
+ * against its known answer, a grade's expected answer (`expected`, written over `agent`'s, whose rightness `correct`
143
+ * says) where one exists, else `agent`'s. True: right on every field. False: wrong on one. Null: a field had no known
144
+ * answer and none was wrong (a grade that contradicts itself). The audit's one verdict (runner/audit.ts). */
145
+ export declare function answerJudged(row: Pick<CheckRow, "agent" | "answer" | "compared" | "expected" | "correct">, on: readonly string[] | undefined): boolean | null;
146
+ /** Decides a check on its rows, with a connected agent's turns checked before them (`before`), judged field by field on
147
+ * its bar (judgeRows). Promoted when it serves (learn/field-check.ts: enough answered alone, every field passes) and the
148
+ * purge gate lets its revision through at its commit (`refused`: else held, a purged run's text); else held on its
149
+ * failing fields with the inputs it did not agree on, which the agent's next run's compile turn reads as data (its one
150
+ * recompile); a recompile's check that holds it too stops: nothing compiles again. No refit, queue or second replay.
151
+ * Kept only while `still` holds of the digest's record (the one write: of two claims at once, one decides). */
140
152
  export declare function decideCheck(deps: DecideDeps, name: string, digest: string, bar: CheckBar, read: {
141
153
  rows: readonly CheckRow[];
142
154
  cost: number | null;
@@ -2,10 +2,11 @@
2
2
  // serves first only when its digest is promoted (learn/promote.ts). Promote once: a digest with no record yet, the learning
3
3
  // folder's newest revision, is checked once (startCheck): a replay run of it (RunLaunch.replay, at workflow cost) on the
4
4
  // input of each of the agent's last compile_after completed runs of its own (its definition's `learning`,
5
- // learning-setting.ts), the agent taking the runs meanwhile. A later claim that finds every check run ended scores each
6
- // against the agent's own recorded answer (learn/promote.ts sameAnswer; no grade is read) and promotes the digest when,
7
- // of the inputs it ran on, it answered at least alone_min alone and at least agree_min of those said what the agent said
8
- // (checkPasses); else it is held, its record keeping the inputs it disagreed on, which the agent's next run's compile
5
+ // learning-setting.ts), the agent taking the runs meanwhile. A later claim that finds every check run ended judges each
6
+ // field (agree_on's, else the whole answer) against its best known answer, the agent run's grade's expected answer, else
7
+ // the agent's own recorded answer (learn/field-check.ts check), and promotes the digest when, of the inputs it ran on, it
8
+ // answered at least alone_min alone and every field passes; else it is held, its record naming the failing fields and
9
+ // keeping the inputs it disagreed on, which the agent's next run's compile
9
10
  // turn reads to write its one recompile (learn/compile.ts); that revision is checked the same way, once, and a hold of
10
11
  // it stops (nothing compiles again). A check-promoted digest is never checked again: no grade, no refit, no queue, no
11
12
  // second replay. Every reserved input counts: one whose replay run was never created, or never ended, by the check's
@@ -55,7 +56,8 @@ import { pinAnnotations, recordedCalls, replayCalls, SKIPPED_WRITE, toolClassOf,
55
56
  import { listed } from "../learning-words.js";
56
57
  import { isObject } from "../validate.js";
57
58
  import { agentRun, lastOwnRuns, newCompileAttempt, sinceReset } from "../learn/compile.js";
58
- import { checkPasses, checkShares, CHECK_TEXT_MAX, championOf, compareAnswers, comparedOf, promotionOf, promotionsOf, recordPromotion, replayingOf, skippedToolsOf } from "../learn/promote.js";
59
+ import { answerAt, answerValue, checkShares, CHECK_TEXT_MAX, championOf, compareAnswers, comparedGrade, comparedOf, gradesOf, knownAnswerText, promotionOf, promotionsOf, recordPromotion, replayingOf, sameAnswer, skippedToolsOf, valueAtPath } from "../learn/promote.js";
60
+ import { check as checkFields, jointSaid, KNOWN, tallyOf } from "../learn/field-check.js";
59
61
  import { refusedIn } from "../purged-workflow.js";
60
62
  import { sendCommand } from "./commands.js";
61
63
  import { ClaimRefused } from "./loop-contract.js";
@@ -121,17 +123,18 @@ export function replayLaid(launch, laid) {
121
123
  return laid.filter((one) => one.name !== workflow || workflowDigest(one) === digest);
122
124
  }
123
125
  /** The learned workflows a run's learned_workflow tool runs, once its first choice is made: what serves, never a
124
- * revision its promotion has not promoted. The one its first choice served or the money rule stopped (laidFor: its
125
- * champion in place of the laid revision) as chosen; any other the records name, its champion (championOf: the laid
126
- * text when that is the champion, else its text at its record's commit), and none while nothing of it serves (none
127
- * promoted yet, or the champion held): a revision replaying, held or never decided is never handed to the agent to run
128
- * in its place. One the records never named is an unchecked draft and is not offered. A replay run's as
129
- * laid (replayLaid). The records unread: only the chosen one, as the gate leaves a run to its agent. */
126
+ * revision its promotion has not promoted. The one its first choice served (laidFor: its champion in place of the laid
127
+ * revision) as chosen; any other the records name, its champion (championOf: the laid text when that is the champion,
128
+ * else its text at its record's commit), and none while nothing of it serves (none promoted yet, or the champion
129
+ * held): a revision replaying, held or never decided is never handed to the agent to run in its place. One the records
130
+ * never named is an unchecked draft and is not offered. A replay run's as laid (replayLaid). The records unread: only
131
+ * the one served first, as the gate leaves a run to its agent. The money rule over what this hands the tool, the one
132
+ * its first choice stopped included, is runner/learned-first.ts's (workflow-first.ts toolStopsOf). */
130
133
  export async function toolFlowsFor(deps, launch, laid, choice) {
131
134
  const chosen = laidFor(laid, choice);
132
135
  if (launch.replay || !chosen.length)
133
136
  return chosen;
134
- const name = choice.serve?.name ?? choice.revise?.workflow;
137
+ const name = choice.serve?.name;
135
138
  let records;
136
139
  try {
137
140
  records = await promotionsOf(deps.store.settings, deps.agentId);
@@ -443,7 +446,7 @@ export const differentDecisionWords = (k, n, example) => `its answers reached a
443
446
  * or its owner acts, and `extra` on the record (a connected agent's check: what its reservation carries). Kept only while
444
447
  * `still` holds of the digest's record (the one write), and logged. */
445
448
  async function holdUnchecked(deps, name, digest, bar, reason, still, { stopped = false, check = {}, extra = {} } = {}) {
446
- const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, of: [], ...check, ...(stopped ? { stopped: true } : {}) }, ...seedOf(deps), ...extra }, still, deps.refused);
449
+ const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso((deps.now ?? Date.now)()), decided: "hold", reason, check: { ...bar, n: 0, agreed: 0, alone: 0, agent_agreed: 0, of: [], ...check, ...(stopped ? { stopped: true } : {}) }, ...seedOf(deps), ...extra }, still, deps.refused);
447
450
  if (decided.won)
448
451
  deps.log(`workflow-first: ${name} at ${digest} ${stopped ? "stopped" : "held"}: ${reason}`);
449
452
  return decided;
@@ -454,6 +457,46 @@ async function holdUnchecked(deps, name, digest, bar, reason, still, { stopped =
454
457
  * would have nothing to be checked on either, and a stop with nothing checked never counts as a compile's first check
455
458
  * (attemptOf). */
456
459
  const stopUnchecked = (deps, name, digest, bar, why, still, check = {}, extra = {}) => holdUnchecked(deps, name, digest, bar, `${NOTHING_TO_CHECK}: ${why}. It is not promoted, and it stops: nothing compiles again until a hold or its owner acts`, still, { stopped: true, check, extra });
460
+ /** The field a check judges a whole answer as, with no agree_on. */
461
+ export const WHOLE_ANSWER = "answer";
462
+ /** A check row as learn/field-check.ts judges it, the one comparison a check and an audit make: an input answered alone
463
+ * with one field per agree_on path (the draft's, the agent's and the grade's value there, compared as values: a path
464
+ * that does not resolve on a side is never right), else one field, the whole answer (`answer`), right as compareAnswers
465
+ * says (`compared`, answered with it: equal, or the same decision by the grader's verdict its run kept) against its
466
+ * best known answer: a grade's expected answer written over the agent's (learn/promote.ts knownAnswerText), the grade
467
+ * saying whether the agent's was right; else the agent's answer, known wrong when a grade with no expected answer said
468
+ * so. The field's `grade` is the grade's own expected answer, the part its owner gave, which a disagreement shows the
469
+ * recompile (and a purge blanks). Field names are never taken from a grade: its keys are a person's data, which a
470
+ * run's purge must leave nowhere. Under agree_on a grade that said the answer was wrong, with no expected answer, names
471
+ * no field, so it changes nothing there. */
472
+ function checkInputOf(row, on) {
473
+ const outcome = row.outcome === "skipped_write" ? "skipped" : row.outcome;
474
+ if (outcome !== "answered")
475
+ return { input: { input_id: row.of, outcome } };
476
+ if (on?.length) {
477
+ return { input: { input_id: row.of, outcome, fields: Object.fromEntries(on.map((path) => {
478
+ const grade = row.expected ? valueAtPath(row.expected, path) : undefined;
479
+ return [path, { workflow: answerAt(row.answer, path), agent: answerAt(row.agent, path), ...(grade !== undefined ? { grade } : {}) }];
480
+ })) } };
481
+ }
482
+ // A grade that marked the agent's answer wrong, yet whose expected answer written over it is that answer, contradicts
483
+ // itself: no known answer there, neither right nor wrong (unjudged).
484
+ const contradicts = row.correct === false && row.expected !== undefined && row.agent !== null && sameAnswer(knownAnswerText(row.agent, row.expected), row.agent);
485
+ const graded = contradicts ? { no_known: true } : row.expected ? { grade: row.expected, ...(row.correct !== undefined ? { agent_correct: row.correct } : {}) } : row.correct === false ? { agent_correct: false } : {};
486
+ const compared = compareAnswers(row.answer, row.expected ? knownAnswerText(row.agent, row.expected) : row.agent, row.compared);
487
+ // The answers as sameAnswer reads them, so a draft that says the agent's answer in another dress repeats it.
488
+ return { input: { input_id: row.of, outcome, fields: { [WHOLE_ANSWER]: { workflow: answerValue(row.answer), agent: answerValue(row.agent), agrees: compared.same, ...graded } } }, compared };
489
+ }
490
+ /** One answer judged as the check judges an input it answered alone (checkInputOf, learn/field-check.ts): `answer`
491
+ * against its known answer, a grade's expected answer (`expected`, written over `agent`'s, whose rightness `correct`
492
+ * says) where one exists, else `agent`'s. True: right on every field. False: wrong on one. Null: a field had no known
493
+ * answer and none was wrong (a grade that contradicts itself). The audit's one verdict (runner/audit.ts). */
494
+ export function answerJudged(row, on) {
495
+ const { agreed, fields } = tallyOf([checkInputOf({ of: "", input: "", outcome: "answered", ...row }, on).input]);
496
+ if (agreed)
497
+ return true;
498
+ return Object.values(fields).some((by) => KNOWN.some((known) => (by[known]?.workflow_right ?? 0) < (by[known]?.n ?? 0))) ? false : null;
499
+ }
457
500
  /** Decides `ahead`, the check at work for a revision older than the laid (newest) one, as a claim laying it would
458
501
  * (relaunch, then settleCheck) once its runs ended: its text read at its record's commit, its verdict standing (promote
459
502
  * or hold) though a newer revision waits. Left replaying while a run of it is at work, or when its text cannot be read
@@ -471,14 +514,19 @@ async function settleAhead(deps, name, ahead) {
471
514
  * created yet. One row per reserved input, so every one counts: a run not ended by the deadline failed, and so did one
472
515
  * never created by then (`unstarted`: the server stopped after reserving it, say), its input read from the agent's run
473
516
  * the record names for it. With what its runs cost, the rows' outcomes (one per row, the never created failed), and how
474
- * many were never created by the deadline.
475
- * No grade is read: the label is the agent's own recorded answer. */
517
+ * many were never created by the deadline. Each row carries its agent run's newest grade's expected answer (when not
518
+ * empty) and whether it was right (CheckRow.expected, correct). */
476
519
  async function checkRows(deps, record) {
477
520
  const { store, context } = deps;
478
521
  const runs = await Promise.all((record.runs ?? []).map((id) => store.runs.get(id)));
479
522
  const late = (deps.now ?? Date.now)() - Date.parse(record.at) > REPLAY_DEADLINE_MS;
480
523
  if (!late && runs.some((row) => !row || !FINAL_STATES.includes(row.state)))
481
524
  return undefined;
525
+ // The newest grade of each run (gradesOf keeps them oldest first): a re-grade replaces what an earlier one said.
526
+ const grades = new Map((await gradesOf(store.settings, deps.agentId)).map((grade) => [grade.run, grade]));
527
+ // An input whose grader was asked is judged on the grade it was asked against (Compared.graded): a grade given after
528
+ // that is not the pair's, so it counts from the next check, never makes this verdict stale.
529
+ const graded = (of, compared) => (compared?.graded !== undefined ? compared.graded : comparedGrade(grades.get(of))) ?? {};
482
530
  const rows = [];
483
531
  for (const [i, run] of runs.entries()) {
484
532
  const reservedOf = record.inputs?.[i];
@@ -501,6 +549,7 @@ async function checkRows(deps, record) {
501
549
  answer: outcome === "answered" ? await answerOf(store, run.id, context) : null,
502
550
  ...(outcome === "handed_back" ? { escalated: (await handedBackOf(store, run.id, context)) ?? "" } : {}),
503
551
  ...(stoppedAt ? { skipped: stoppedAt } : {}),
552
+ ...graded(replayed, compared),
504
553
  });
505
554
  }
506
555
  // The outcomes are the rows', so they add up to its n: a reserved run never created is a failed input there too.
@@ -536,46 +585,66 @@ async function settleCheck(deps, workflow, digest, record) {
536
585
  }
537
586
  return decided.record?.decided === "replaying" ? undefined : decided.record;
538
587
  }
539
- /** A check's rows scored on its bar, added to `before` (a connected agent's turns checked so far): each input it ran on
540
- * (a skipped write is none) agreed when the draft answered it alone with the agent's recorded answer (learn/promote.ts
541
- * compareAnswers, the audit's one comparison: on the bar's agree_on when it names fields, else equal, or the same
542
- * decision by the grader's verdict its replay run kept), alone when it answered it with no escalate and no failed step;
543
- * the inputs it did not agree on, each text cut of the host's secrets whole, then shortened (learn/secrets.ts
544
- * excerptShown); and the fast model that compared, when it read any input's answers. */
545
- async function scoreRows(deps, bar, rows, before) {
588
+ /** A check's rows judged field by field (learn/field-check.ts check) on its bar, added to `before` (a connected agent's
589
+ * turns checked so far): each field of agree_on, else the whole answer (checkInputOf), against its best known answer;
590
+ * the inputs it did not agree on (not answered alone, or a field wrong), each naming the fields it had wrong, each text
591
+ * cut of the host's secrets whole, then shortened (learn/secrets.ts excerptShown); and the fast model that compared,
592
+ * when it read any input's answers. */
593
+ async function judgeRows(deps, bar, rows, before) {
546
594
  const ran = rows.filter((row) => row.outcome !== "skipped_write");
547
- const alone = (row) => row.outcome === "answered";
548
- // Compared on the bar's agree_on when it names paths (the definition's), else equal answers agree and the grader's
549
- // verdict decides the rest; with no grader (no fast model), the whole answer.
550
- const compared = new Map(ran.map((row) => [row, compareAnswers(row.answer, row.agent, bar.agree_on, row.compared)]));
551
- const agrees = (row) => alone(row) && compared.get(row).same;
552
- const score = { n: (before?.n ?? 0) + ran.length, agreed: (before?.agreed ?? 0) + ran.filter(agrees).length, alone: (before?.alone ?? 0) + ran.filter(alone).length };
553
- const grader = [...compared.values()].find((one) => one.grader !== undefined)?.grader;
595
+ // With no agree_on, the draft's answer is compared whole with its known answer: equal, else the grader's verdict on
596
+ // that pair, which its replay run asked (with no grader, no fast model, they differ). Under agree_on, fields and
597
+ // grades are compared as values (checkInputOf).
598
+ const on = bar.agree_on?.length ? bar.agree_on : undefined;
599
+ const judged = new Map(rows.map((row) => [row, checkInputOf(row, on)]));
600
+ const verdict = checkFields([...judged.values()].map((one) => one.input), bar, before);
601
+ const missed = new Map();
602
+ for (const miss of verdict.misses)
603
+ missed.set(miss.input_id, [...(missed.get(miss.input_id) ?? []), miss.field]);
604
+ const grader = [...judged.values()].find((one) => one.compared?.grader !== undefined)?.compared?.grader;
554
605
  const shown = await deps.shown();
555
606
  const cut = (text) => excerptShown(text, shown, CHECK_TEXT_MAX);
556
- const disagreements = [...(before?.disagreements ?? []), ...ran.filter((row) => !agrees(row)).map((row) => {
557
- const differs = row.outcome === "answered" ? compared.get(row).differs_on : undefined;
607
+ // The known answers (a grade's) each input's draft missed, for the recompile: never the agent's own (shown);
608
+ // where a grade marked the agent's answer wrong without the right one ("unknown") or contradicts itself
609
+ // ("contradicts"), that it did, no value made up.
610
+ const known = new Map();
611
+ for (const miss of verdict.misses) {
612
+ if (miss.known === "agent")
613
+ continue;
614
+ const value = miss.known !== "grade" ? undefined : cut(typeof miss.expected === "string" ? miss.expected : JSON.stringify(miss.expected) ?? "");
615
+ known.set(miss.input_id, [...(known.get(miss.input_id) ?? []), { field: miss.field, known: miss.known, ...(value !== undefined ? { value } : {}) }]);
616
+ }
617
+ const disagreements = [...(before?.disagreements ?? []), ...ran.filter((row) => row.outcome !== "answered" || missed.has(row.of)).map((row) => {
618
+ const differs = judged.get(row).compared?.differs_on;
619
+ const fields = row.outcome === "answered" ? missed.get(row.of) : undefined;
620
+ const expected = row.outcome === "answered" ? known.get(row.of) : undefined;
558
621
  return {
559
622
  run: row.of, input: cut(row.input), agent: row.agent === null ? null : cut(row.agent),
560
623
  ...(row.outcome === "answered" ? { draft: cut(row.answer ?? "") } : row.outcome === "handed_back" ? { escalated: cut(row.escalated ?? "") } : { failed: true }),
561
624
  ...(differs ? { differs_on: cut(differs) } : {}),
625
+ ...(fields ? { fields } : {}),
626
+ ...(expected ? { expected } : {}),
562
627
  };
563
628
  })];
564
- return { score, disagreements, grader };
629
+ return { verdict, disagreements, grader };
565
630
  }
566
631
  /** Two outcome counts added. */
567
632
  const outcomesAdded = (a, b) => b ? { answered: a.answered + b.answered, handed_back: a.handed_back + b.handed_back, failed: a.failed + b.failed, skipped_write: a.skipped_write + b.skipped_write } : a;
568
- /** Decides a check on its rows, with a connected agent's turns checked before them (`before`), scored on its bar
569
- * (scoreRows). Promoted when it clears the bar (checkPasses) and the purge gate lets its revision through at its commit
570
- * (`refused`: else held, a purged run's text); else held with the inputs it did not agree on, which the
571
- * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
572
- * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
573
- * (the one write: of two claims at once, one decides). */
633
+ /** Decides a check on its rows, with a connected agent's turns checked before them (`before`), judged field by field on
634
+ * its bar (judgeRows). Promoted when it serves (learn/field-check.ts: enough answered alone, every field passes) and the
635
+ * purge gate lets its revision through at its commit (`refused`: else held, a purged run's text); else held on its
636
+ * failing fields with the inputs it did not agree on, which the agent's next run's compile turn reads as data (its one
637
+ * recompile); a recompile's check that holds it too stops: nothing compiles again. No refit, queue or second replay.
638
+ * Kept only while `still` holds of the digest's record (the one write: of two claims at once, one decides). */
574
639
  export async function decideCheck(deps, name, digest, bar, read, still, extra) {
575
640
  const now = deps.now ?? Date.now;
576
641
  const { before } = read;
577
- const { score, disagreements, grader } = await scoreRows(deps, bar, read.rows, before);
578
- const ok = checkPasses(score, bar);
642
+ const { verdict, disagreements, grader } = await judgeRows(deps, bar, read.rows, before);
643
+ const { tally, fields, failing, joint } = verdict;
644
+ const score = { n: tally.n, agreed: tally.agreed, alone: tally.alone };
645
+ const fieldCount = Object.keys(fields).length;
646
+ const saysJoint = jointSaid(Object.values(fields).map((one) => one.pass), joint.pass);
647
+ const ok = verdict.verdict === "serve";
579
648
  const stopped = !ok && bar.attempt === 2;
580
649
  const pct = (value) => `${(value * 100).toFixed(1)}%`;
581
650
  const shares = checkShares(score);
@@ -600,14 +669,17 @@ export async function decideCheck(deps, name, digest, bar, read, still, extra) {
600
669
  // and the words say none ran.
601
670
  const said = read.unstarted === score.n
602
671
  ? `none of its ${plural(score.n, "check run")} started by the check's deadline (its launch was interrupted: the server stopped after reserving it, say): nothing was checked`
603
- : `checked on ${score.n} of the agent's inputs: answered ${score.alone} alone (${pct(shares.alone)}, the bar ${pct(bar.alone_min)}), and ${score.agreed} of those said what the agent said${bar.agree_on?.length ? ` on ${listed(bar.agree_on)}` : grader ? `, compared by the fast model (${grader})` : ""} (${pct(shares.agreement)}, the bar ${pct(bar.agree_min)})${aside ? ` (${aside})` : ""}`;
604
- // The grader compared: how many answered alone reached another decision, with one it named. Compared whole and never
605
- // once the same (no grader): free text two runs never repeat, most likely, so the owner is told what to set.
606
- const differed = score.alone - score.agreed;
672
+ : `checked on ${score.n} of the agent's inputs: answered ${score.alone} alone (${pct(shares.alone)}, the bar ${pct(bar.alone_min)})${Object.keys(fields).length ? `; ${Object.values(fields).map((one) => one.reason).join("; ")}` : ""}${saysJoint ? `; right on every field at once: ${joint.agreed} of ${joint.alone} (${pct(shares.agreement)}, the bar ${pct(bar.agree_min)})` : ""}${grader ? `; compared by the fast model (${grader})` : ""}${aside ? ` (${aside})` : ""}`;
673
+ // The whole answer compared with the agent's: with the grader, how many answered alone reached another decision, with
674
+ // one it named; never once the same and no grader: free text two runs never repeat, most likely, so the owner is told
675
+ // what to set.
676
+ const whole = bar.agree_on?.length ? undefined : fields[WHOLE_ANSWER]?.by.agent;
677
+ const differed = whole ? whole.n - whole.workflow_right : 0;
607
678
  const example = disagreements.find((one) => one.differs_on !== undefined)?.differs_on;
608
- const verbatim = ok || bar.agree_on?.length ? "" : grader ? (differed > 0 ? `; ${differentDecisionWords(differed, score.alone, example)}` : "") : score.alone > 0 && score.agreed === 0 ? `; ${read.exactMismatchReason ?? NEVER_WORD_FOR_WORD}` : "";
609
- const reason = ok ? `${said}: promoted` : stopped ? `${said}: held${verbatim}, and this was the recompile's check, so it stops: nothing compiles again until a hold or its owner acts` : `${said}: held${verbatim}; the agent's next run recompiles it once with the inputs it did not agree on`;
610
- const check = { ...bar, ...score, ...numbers, ...(disagreements.length ? { disagreements } : {}), ...(stopped ? { stopped: true } : {}), ...(grader ? { grader } : {}) };
679
+ const verbatim = ok || !whole ? "" : grader ? (differed > 0 ? `; ${differentDecisionWords(differed, whole.n, example)}` : "") : whole.workflow_right === 0 ? `; ${read.exactMismatchReason ?? NEVER_WORD_FOR_WORD}` : "";
680
+ const heldOn = `held${failing.length ? ` on ${listed(failing)}` : !joint.pass && fieldCount ? " on its fields together" : ""}${verbatim}`;
681
+ const reason = ok ? `${said}: promoted` : stopped ? `${said}: ${heldOn}, and this was the recompile's check, so it stops: nothing compiles again until a hold or its owner acts` : `${said}: ${heldOn}; the agent's next run recompiles it once with the inputs it did not agree on`;
682
+ const check = { ...bar, ...score, agent_agreed: tally.agent_agreed, joint: joint.pass, ...(fieldCount ? { fields } : {}), ...numbers, ...(disagreements.length ? { disagreements } : {}), ...(stopped ? { stopped: true } : {}), ...(grader ? { grader } : {}) };
611
683
  const record = { workflow: name, digest, at: iso(now()), decided: ok ? "promote" : "hold", reason, check, ...seedOf(deps), ...extra };
612
684
  // A check that outlives its revision's run: the run's purge never stops it (it replays other runs' inputs), and the
613
685
  // purge gate refuses the revision at the commit it was checked at (purged-workflow.ts refusedOf). It is held, never
@@ -737,9 +809,9 @@ export async function sdkCheckTurn(deps, record, row, still, read = {}) {
737
809
  deps.log(`workflow-first: ${record.workflow} at ${record.digest} checked a native turn; a newer revision has a record since, so it is left as it is`);
738
810
  return;
739
811
  }
740
- const { score, disagreements } = await scoreRows(deps, bar, [row], before);
812
+ const { verdict: { tally }, disagreements } = await judgeRows(deps, bar, [row], before);
741
813
  const fresh = (before?.fresh_reads ?? 0) + (read.fresh_reads ?? 0);
742
- const turns = { ...score, of: [row.of, ...(before?.of ?? [])], outcomes: outcomesAdded(outcomes, before?.outcomes), ...(disagreements.length ? { disagreements } : {}), ...(fresh ? { fresh_reads: fresh } : {}) };
814
+ const turns = { n: tally.n, agreed: tally.agreed, alone: tally.alone, agent_agreed: tally.agent_agreed, fields: tally.fields, of: [row.of, ...(before?.of ?? [])], outcomes: outcomesAdded(outcomes, before?.outcomes), ...(disagreements.length ? { disagreements } : {}), ...(fresh ? { fresh_reads: fresh } : {}) };
743
815
  const check = { ...bar, turns };
744
816
  const kept = await waitAgain(deps, record, check, `Waiting for the next native turn of the connected agent that it takes: ${sdkTurnsWords(check)}. Nothing was promoted.`, still);
745
817
  if (kept.won)
@@ -1083,8 +1155,11 @@ async function checkView(ask, record, id, name, digest) {
1083
1155
  const n = check.n ?? 0;
1084
1156
  const handedBack = check.outcomes.handed_back;
1085
1157
  const wf = n ? Math.round(((check.agreed ?? 0) + handedBack) / n * 1e4) / 1e4 : 0;
1158
+ // The agent's misses are counted where the workflow's are, on the inputs it answered alone (agent_agreed).
1159
+ const alone = check.alone ?? 0;
1160
+ const agent = n ? Math.round((n - (alone - (check.agent_agreed ?? 0))) / n * 1e4) / 1e4 : 0;
1086
1161
  const neverStarted = inputs > 0 && check.unstarted === inputs;
1087
- return { replay: id, workflow: name, digest, status: neverStarted ? "failed" : "done", inputs, outcomes: check.outcomes, score: { n, agree: check.agreed ?? 0, agent_acc: n ? 1 : 0, wf_acc: wf, delta: n ? Math.round((wf - 1) * 1e4) / 1e4 : 0, handed_back: handedBack }, cost_usd: check.cost_usd ?? null, decided, reason: record.reason };
1162
+ return { replay: id, workflow: name, digest, status: neverStarted ? "failed" : "done", inputs, outcomes: check.outcomes, score: { n, agree: check.agreed ?? 0, agent_acc: agent, wf_acc: wf, delta: n ? Math.round((wf - agent) * 1e4) / 1e4 : 0, handed_back: handedBack }, cost_usd: check.cost_usd ?? null, decided, reason: record.reason };
1088
1163
  }
1089
1164
  const runs = await Promise.all((record.runs ?? []).map((run) => ask.store.runs.get(run)));
1090
1165
  return { replay: id, workflow: name, digest, status: decided ? "done" : "running", inputs, outcomes: outcomesOf(runs, false), score: NO_SCORE, cost_usd: replayCost(runs, false), ...(decided ? { decided, reason: record.reason } : {}) };
@@ -11,7 +11,9 @@ export declare const keepText: Redact;
11
11
  /** Every secret value `env` holds for the runner: the server's held secrets, the MCP credentials and every key-, token-,
12
12
  * secret- or password-named value (secrets.ts hostSecrets), and the value `env` itself gives each launcher name (a
13
13
  * runner's key comes in its env, which hostSecrets reads only for names off the launcher's list), with any `extra` a
14
- * caller holds. One shorter than MIN_SECRET, whitespace aside, matches too much text by chance and is left out. */
14
+ * caller holds, and each OTLP header value. One shorter than MIN_SECRET, whitespace aside, matches too much text by
15
+ * chance and is left out, an OTLP header value's too (secrets.ts keptSecrets); the tracer's own lines cut a short
16
+ * header value as well (secrets.ts otlpHeaderCut). */
15
17
  export declare function runnerSecrets(env: NodeJS.ProcessEnv, extra?: readonly string[]): string[];
16
18
  /** The redactor over `values`: each one, in every form, replaced with "[redacted]". With none, text is left as it is. */
17
19
  export declare function secretRedactor(values: readonly string[]): Redact;
@@ -5,7 +5,7 @@
5
5
  // can take in text (key-refusal.ts redactedAnswer: as written, JSON-escaped, base64, hex and percent-encoded).
6
6
  import { heldNumber, redactedAnswer } from "../key-refusal.js";
7
7
  import { MIN_SECRET } from "../learn/secrets.js";
8
- import { hostSecrets, SECRET_NAMES } from "../secrets.js";
8
+ import { hostSecrets, keptSecrets, SECRET_NAMES } from "../secrets.js";
9
9
  import { planOf } from "../chatgpt-plan.js";
10
10
  /** `cut` answering `heldValues()`, the function defined not enumerable: JSON.stringify and util.inspect of the redactor,
11
11
  * or of an object holding it, show no value it holds. */
@@ -17,10 +17,12 @@ export const keepText = withHeldValues((text) => text, () => []);
17
17
  /** Every secret value `env` holds for the runner: the server's held secrets, the MCP credentials and every key-, token-,
18
18
  * secret- or password-named value (secrets.ts hostSecrets), and the value `env` itself gives each launcher name (a
19
19
  * runner's key comes in its env, which hostSecrets reads only for names off the launcher's list), with any `extra` a
20
- * caller holds. One shorter than MIN_SECRET, whitespace aside, matches too much text by chance and is left out. */
20
+ * caller holds, and each OTLP header value. One shorter than MIN_SECRET, whitespace aside, matches too much text by
21
+ * chance and is left out, an OTLP header value's too (secrets.ts keptSecrets); the tracer's own lines cut a short
22
+ * header value as well (secrets.ts otlpHeaderCut). */
21
23
  export function runnerSecrets(env, extra = []) {
22
24
  const own = SECRET_NAMES.map((name) => env[name] ?? "");
23
- return [...new Set([...hostSecrets(env), ...own, ...extra])].filter((value) => value.replace(/\s+/g, "").length >= MIN_SECRET);
25
+ return keptSecrets([...hostSecrets(env), ...own, ...extra], env);
24
26
  }
25
27
  /** The redactor over `values`: each one, in every form, replaced with "[redacted]". With none, text is left as it is. */
26
28
  export function secretRedactor(values) {
@@ -0,0 +1,36 @@
1
+ type Json = Record<string, unknown>;
2
+ /** A request this translation does not take: answered 400 with `message`, in OpenAI's error shape. */
3
+ export declare class ResponsesRefusal extends Error {
4
+ }
5
+ /**
6
+ * A Responses request as one Messages request (see the head of this file). `reasons`: whether the model reasons, so a
7
+ * `reasoning.effort` reaches it as the Messages translation's named level; a model that does not is asked none.
8
+ * Returns the Messages body and what it asks Ollama past it (EdgeAsks). Throws a ResponsesRefusal for what it does not take.
9
+ */
10
+ export declare function messagesOfResponses(body: Json, reasons: boolean): {
11
+ request: Json;
12
+ asks: EdgeAsks;
13
+ };
14
+ /** What this edge asks an Ollama model past the Messages body: the JSON schema its answer is held to (Ollama's `format`),
15
+ * its temperature and top_p, and no thinking (effort "none"). Handed to the route's Messages fetch on the in-process
16
+ * call's init (`edgeAsks`; model-route.ts messagesFetch reads it on an Ollama model alone), never in the body, so the
17
+ * Messages body a Messages client sends is never rewritten. That client's output schema rides the same field
18
+ * (model-route.ts forMessagesClients); its own temperature, top_p and thinking reach Ollama as before, not at all. */
19
+ export type EdgeAsks = {
20
+ format?: Json;
21
+ temperature?: number;
22
+ top_p?: number;
23
+ think?: false;
24
+ };
25
+ /**
26
+ * A fetch that answers OpenAI Responses requests through `messages` (a Messages fetch: the route's own translation,
27
+ * model-route.ts messagesFetch). `reasons`: whether the model reasons (messagesOfResponses). A request it does not take
28
+ * is answered 400 and never reaches `messages`. `warn`: where a line on what the edge did to an answer goes (the calls
29
+ * parallel_tool_calls false kept from the client, by count and tool name, never their arguments); stderr by default,
30
+ * which the run's own log keeps.
31
+ */
32
+ export declare function responsesFetch(messages: typeof fetch, { reasons, warn }?: {
33
+ reasons?: boolean;
34
+ warn?: (line: string) => void;
35
+ }): typeof fetch;
36
+ export {};