@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.39

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 (410) hide show
  1. package/CHANGELOG.md +418 -0
  2. package/README.md +325 -124
  3. package/dist/adapters.d.ts +4 -1
  4. package/dist/adapters.js +4 -2
  5. package/dist/agent-rows.d.ts +0 -2
  6. package/dist/agents-store.d.ts +5 -5
  7. package/dist/agents-store.js +14 -14
  8. package/dist/bash-read-only.js +2 -1
  9. package/dist/cap-short.d.ts +12 -0
  10. package/dist/cap-short.js +60 -0
  11. package/dist/cap.d.ts +3 -10
  12. package/dist/cap.js +2 -5
  13. package/dist/catalog.d.ts +0 -5
  14. package/dist/catalog.js +1 -5
  15. package/dist/chatgpt-plan.d.ts +163 -0
  16. package/dist/chatgpt-plan.js +549 -0
  17. package/dist/cli.js +26 -6
  18. package/dist/composio-preset.d.ts +8 -0
  19. package/dist/composio-preset.js +8 -7
  20. package/dist/composio-triggers.d.ts +113 -0
  21. package/dist/composio-triggers.js +411 -0
  22. package/dist/computer-calls.js +2 -2
  23. package/dist/computer-commands.d.ts +2 -0
  24. package/dist/computer-commands.js +7 -3
  25. package/dist/computer-live.d.ts +7 -2
  26. package/dist/computer-live.js +9 -5
  27. package/dist/computer-routes.d.ts +2 -2
  28. package/dist/computer-routes.js +2 -2
  29. package/dist/computer-setting.d.ts +3 -3
  30. package/dist/computer-setting.js +5 -5
  31. package/dist/computer-view.d.ts +15 -0
  32. package/dist/computer-view.js +16 -2
  33. package/dist/computer-viewer.js +14 -1
  34. package/dist/computers.d.ts +5 -2
  35. package/dist/computers.js +9 -5
  36. package/dist/console/assets/index-BNhZs-jp.css +1 -0
  37. package/dist/console/assets/index-BQv5aOGB.js +700 -0
  38. package/dist/console/index.html +2 -2
  39. package/dist/console-links.js +3 -3
  40. package/dist/decision-cap.d.ts +2 -5
  41. package/dist/decision-cap.js +3 -6
  42. package/dist/decision-rows.js +11 -11
  43. package/dist/email/account.d.ts +84 -0
  44. package/dist/email/account.js +159 -0
  45. package/dist/email/answer.d.ts +10 -0
  46. package/dist/email/answer.js +182 -0
  47. package/dist/email/email-faux.d.ts +95 -0
  48. package/dist/email/email-faux.js +849 -0
  49. package/dist/email/labels.d.ts +1 -0
  50. package/dist/email/labels.js +84 -0
  51. package/dist/email/mail.d.ts +186 -0
  52. package/dist/email/mail.js +380 -0
  53. package/dist/email/names.d.ts +20 -0
  54. package/dist/email/names.js +40 -0
  55. package/dist/email/routes.d.ts +9 -0
  56. package/dist/email/routes.js +50 -0
  57. package/dist/email/tools.d.ts +20 -0
  58. package/dist/email/tools.js +517 -0
  59. package/dist/environment.d.ts +17 -2
  60. package/dist/environment.js +36 -8
  61. package/dist/errors.d.ts +6 -0
  62. package/dist/errors.js +12 -0
  63. package/dist/eval-mailbox.d.ts +103 -0
  64. package/dist/eval-mailbox.js +236 -0
  65. package/dist/graph-view.d.ts +9 -2
  66. package/dist/graph-view.js +6 -2
  67. package/dist/harness-install.d.ts +28 -2
  68. package/dist/harness-install.js +147 -59
  69. package/dist/harness-opencode/adapter.js +2 -26
  70. package/dist/harness-opencode/facts.js +5 -2
  71. package/dist/harness-opencode/host/policy.d.ts +2 -0
  72. package/dist/harness-opencode/host/policy.js +10 -5
  73. package/dist/harness-opencode/index.d.ts +1 -1
  74. package/dist/harness-opencode/index.js +1 -1
  75. package/dist/harness-opencode/versions.d.ts +6 -0
  76. package/dist/harness-opencode/versions.js +6 -0
  77. package/dist/harness-table.js +8 -5
  78. package/dist/harness.d.ts +12 -0
  79. package/dist/harness.js +15 -3
  80. package/dist/hosted-search.d.ts +3 -1
  81. package/dist/hosted-search.js +51 -11
  82. package/dist/import-sources.d.ts +1 -1
  83. package/dist/import-sources.js +3 -3
  84. package/dist/import.d.ts +21 -0
  85. package/dist/import.js +186 -1
  86. package/dist/key-check.d.ts +0 -2
  87. package/dist/key-check.js +3 -4
  88. package/dist/key-refusal.d.ts +8 -2
  89. package/dist/key-refusal.js +16 -13
  90. package/dist/learn/check.d.ts +18 -3
  91. package/dist/learn/check.js +328 -3
  92. package/dist/learn/compile.d.ts +9 -2
  93. package/dist/learn/compile.js +52 -16
  94. package/dist/learn/grade.d.ts +4 -0
  95. package/dist/learn/grade.js +4 -1
  96. package/dist/learn/promote.d.ts +106 -51
  97. package/dist/learn/promote.js +82 -189
  98. package/dist/learn/refit.d.ts +21 -12
  99. package/dist/learn/refit.js +51 -23
  100. package/dist/learn/replay-calls.js +1 -1
  101. package/dist/learn/skills.d.ts +2 -7
  102. package/dist/learn/skills.js +28 -14
  103. package/dist/learned-nodes.d.ts +15 -7
  104. package/dist/learned-nodes.js +29 -5
  105. package/dist/learned-workflow.d.ts +41 -31
  106. package/dist/learned-workflow.js +122 -63
  107. package/dist/learning-batch.js +3 -3
  108. package/dist/learning-cost.d.ts +26 -8
  109. package/dist/learning-cost.js +17 -7
  110. package/dist/learning-routes.d.ts +2 -4
  111. package/dist/learning-routes.js +20 -3
  112. package/dist/learning-words.d.ts +1 -1
  113. package/dist/learning-words.js +4 -1
  114. package/dist/learning.d.ts +5 -5
  115. package/dist/link-check.d.ts +27 -0
  116. package/dist/link-check.js +164 -0
  117. package/dist/local-models.d.ts +33 -2
  118. package/dist/local-models.js +43 -5
  119. package/dist/mcp-pin-first.js +6 -0
  120. package/dist/mcp-secret-writes.js +3 -0
  121. package/dist/mcp-servers-store.d.ts +25 -16
  122. package/dist/mcp-servers-store.js +23 -3
  123. package/dist/model-form.d.ts +11 -0
  124. package/dist/model-form.js +17 -1
  125. package/dist/model.d.ts +26 -6
  126. package/dist/model.js +126 -18
  127. package/dist/monid.d.ts +26 -31
  128. package/dist/monid.js +84 -79
  129. package/dist/native/binding.d.ts +13 -0
  130. package/dist/native/binding.js +57 -0
  131. package/dist/native/cli.d.ts +2 -0
  132. package/dist/native/cli.js +48 -0
  133. package/dist/native/connection.d.ts +8 -0
  134. package/dist/native/connection.js +94 -0
  135. package/dist/native/context.d.ts +6 -0
  136. package/dist/native/context.js +22 -0
  137. package/dist/native/discovery.d.ts +27 -0
  138. package/dist/native/discovery.js +404 -0
  139. package/dist/native/environment.d.ts +4 -0
  140. package/dist/native/environment.js +18 -0
  141. package/dist/native/history.d.ts +20 -0
  142. package/dist/native/history.js +147 -0
  143. package/dist/native/instructions.d.ts +21 -0
  144. package/dist/native/instructions.js +173 -0
  145. package/dist/native/remote-worker-bridge.d.ts +3 -0
  146. package/dist/native/remote-worker-bridge.js +278 -0
  147. package/dist/native/remote.d.ts +187 -0
  148. package/dist/native/remote.js +492 -0
  149. package/dist/native/runtime.d.ts +17 -0
  150. package/dist/native/runtime.js +316 -0
  151. package/dist/native/runtimes.d.ts +66 -0
  152. package/dist/native/runtimes.js +41 -0
  153. package/dist/native/schema.d.ts +46 -0
  154. package/dist/native/schema.js +41 -0
  155. package/dist/native/types.d.ts +87 -0
  156. package/dist/native/types.js +1 -0
  157. package/dist/observation/http.d.ts +4 -0
  158. package/dist/observation/http.js +140 -0
  159. package/dist/observation/observer.d.ts +301 -0
  160. package/dist/observation/observer.js +919 -0
  161. package/dist/observation/schema.d.ts +52 -0
  162. package/dist/observation/schema.js +154 -0
  163. package/dist/openapi.d.ts +1 -0
  164. package/dist/openapi.js +394 -85
  165. package/dist/paid-calls.d.ts +8 -3
  166. package/dist/paid-calls.js +6 -2
  167. package/dist/place-offers.d.ts +4 -8
  168. package/dist/place-offers.js +4 -9
  169. package/dist/port-models.d.ts +7 -2
  170. package/dist/port-models.js +5 -2
  171. package/dist/print.d.ts +4 -2
  172. package/dist/print.js +4 -3
  173. package/dist/propose.d.ts +1 -2
  174. package/dist/propose.js +10 -1
  175. package/dist/provider.d.ts +5 -1
  176. package/dist/provider.js +8 -0
  177. package/dist/push-handler.d.ts +3 -2
  178. package/dist/push-handler.js +20 -6
  179. package/dist/refusal-words.d.ts +11 -0
  180. package/dist/refusal-words.js +13 -2
  181. package/dist/run-launch.d.ts +10 -1
  182. package/dist/run-launch.js +11 -4
  183. package/dist/run-learning-served.d.ts +75 -2
  184. package/dist/run-manifest.d.ts +3 -0
  185. package/dist/run-manifest.js +13 -1
  186. package/dist/run-reads-over-store.d.ts +3 -3
  187. package/dist/run-reads-over-store.js +13 -10
  188. package/dist/run-timeline-served.d.ts +3 -2
  189. package/dist/run-timeline-served.js +8 -9
  190. package/dist/run-view.d.ts +42 -35
  191. package/dist/run-view.js +79 -44
  192. package/dist/runnable.d.ts +13 -5
  193. package/dist/runnable.js +69 -60
  194. package/dist/runner/adapter-loop.d.ts +42 -11
  195. package/dist/runner/adapter-loop.js +651 -247
  196. package/dist/runner/adapter-run-spec.d.ts +37 -12
  197. package/dist/runner/adapter-run-spec.js +139 -106
  198. package/dist/runner/adapters/pi.d.ts +24 -0
  199. package/dist/runner/adapters/pi.js +59 -9
  200. package/dist/runner/beside.d.ts +3 -1
  201. package/dist/runner/beside.js +24 -8
  202. package/dist/runner/claim-secrets.d.ts +3 -1
  203. package/dist/runner/claim-secrets.js +28 -4
  204. package/dist/runner/cli-run-spec.d.ts +30 -0
  205. package/dist/runner/cli-run-spec.js +94 -50
  206. package/dist/runner/computer-channel.d.ts +5 -2
  207. package/dist/runner/computer-channel.js +3 -2
  208. package/dist/runner/computer-journal.d.ts +6 -0
  209. package/dist/runner/computer-journal.js +8 -10
  210. package/dist/runner/conformance/harness.js +6 -3
  211. package/dist/runner/end-of-run.d.ts +2 -0
  212. package/dist/runner/end-of-run.js +3 -1
  213. package/dist/runner/feedback-round.d.ts +40 -13
  214. package/dist/runner/feedback-round.js +64 -16
  215. package/dist/runner/harness-loops.js +17 -0
  216. package/dist/runner/journal-kinds.d.ts +37 -13
  217. package/dist/runner/journal-kinds.js +9 -5
  218. package/dist/runner/learning-dispatch.d.ts +3 -2
  219. package/dist/runner/learning-dispatch.js +6 -6
  220. package/dist/runner/learning-end.d.ts +4 -0
  221. package/dist/runner/learning-end.js +64 -36
  222. package/dist/runner/learning-factory.d.ts +3 -0
  223. package/dist/runner/learning-factory.js +8 -2
  224. package/dist/runner/learning-loop.d.ts +2 -0
  225. package/dist/runner/learning-loop.js +19 -4
  226. package/dist/runner/loop.d.ts +18 -0
  227. package/dist/runner/loop.js +34 -0
  228. package/dist/runner/main.d.ts +6 -1
  229. package/dist/runner/main.js +26 -4
  230. package/dist/runner/mcp-run.d.ts +4 -1
  231. package/dist/runner/mcp-run.js +11 -5
  232. package/dist/runner/meta-tools.d.ts +10 -3
  233. package/dist/runner/meta-tools.js +112 -36
  234. package/dist/runner/metrics.d.ts +80 -21
  235. package/dist/runner/metrics.js +114 -39
  236. package/dist/runner/model-route.d.ts +12 -3
  237. package/dist/runner/model-route.js +139 -18
  238. package/dist/runner/monid-run.d.ts +8 -6
  239. package/dist/runner/monid-run.js +117 -43
  240. package/dist/runner/native-loop.d.ts +11 -0
  241. package/dist/runner/native-loop.js +438 -0
  242. package/dist/runner/promotion.d.ts +74 -8
  243. package/dist/runner/promotion.js +365 -124
  244. package/dist/runner/redact.js +3 -0
  245. package/dist/runner/reflect-hook.js +9 -0
  246. package/dist/runner/runner.d.ts +7 -1
  247. package/dist/runner/runner.js +8 -4
  248. package/dist/runner/sdk-loop.d.ts +7 -0
  249. package/dist/runner/sdk-loop.js +470 -0
  250. package/dist/runner/spec-holds.d.ts +16 -2
  251. package/dist/runner/spec-holds.js +42 -14
  252. package/dist/runner/store-secrets.js +17 -2
  253. package/dist/runner/workflow-first.d.ts +30 -20
  254. package/dist/runner/workflow-first.js +22 -32
  255. package/dist/runner/workflow-loop.d.ts +1 -1
  256. package/dist/runner/workflow-loop.js +18 -12
  257. package/dist/runner/workflow-spec.d.ts +4 -1
  258. package/dist/runner/workflow-spec.js +56 -45
  259. package/dist/runs-over-store.d.ts +30 -2
  260. package/dist/runs-over-store.js +46 -14
  261. package/dist/sdk/runs.d.ts +115 -0
  262. package/dist/sdk/runs.js +422 -0
  263. package/dist/sdk/schema.d.ts +175 -0
  264. package/dist/sdk/schema.js +138 -0
  265. package/dist/sdk/workflows.d.ts +22 -0
  266. package/dist/sdk/workflows.js +39 -0
  267. package/dist/secrets.d.ts +2 -0
  268. package/dist/secrets.js +19 -1
  269. package/dist/server.d.ts +48 -32
  270. package/dist/server.js +554 -130
  271. package/dist/skill-route.d.ts +3 -0
  272. package/dist/skill-route.js +16 -0
  273. package/dist/skills/agentrun-serve/SKILL.md +368 -0
  274. package/dist/stats.d.ts +10 -10
  275. package/dist/store/agent-body.d.ts +12 -8
  276. package/dist/store/agent-body.js +9 -4
  277. package/dist/store/index.d.ts +1 -1
  278. package/dist/store/native-command-owner.d.ts +10 -0
  279. package/dist/store/native-command-owner.js +47 -0
  280. package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
  281. package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
  282. package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
  283. package/dist/store/postgres/store.js +3 -0
  284. package/dist/store/schema.d.ts +7 -0
  285. package/dist/store/schema.js +20 -1
  286. package/dist/store/sqlite/run-patch.d.ts +8 -1
  287. package/dist/store/sqlite/run-patch.js +14 -3
  288. package/dist/store/sqlite/store.js +133 -18
  289. package/dist/store/store.d.ts +52 -7
  290. package/dist/store-reads/analytics.d.ts +7 -7
  291. package/dist/store-reads/analytics.js +23 -5
  292. package/dist/store-reads/cap.js +8 -6
  293. package/dist/store-reads/journal.d.ts +5 -0
  294. package/dist/store-reads/journal.js +85 -41
  295. package/dist/store-reads/learning.d.ts +85 -5
  296. package/dist/store-reads/learning.js +45 -17
  297. package/dist/store-reads/runs.d.ts +5 -0
  298. package/dist/store-reads/runs.js +3 -2
  299. package/dist/store-view.js +75 -21
  300. package/dist/template-eval.d.ts +73 -11
  301. package/dist/template-eval.js +535 -75
  302. package/dist/templates.d.ts +70 -20
  303. package/dist/templates.js +191 -34
  304. package/dist/text-urls.d.ts +38 -0
  305. package/dist/text-urls.js +170 -0
  306. package/dist/timeline/index.d.ts +3 -2
  307. package/dist/timeline/index.js +3 -2
  308. package/dist/timeline/labels.d.ts +5 -2
  309. package/dist/timeline/labels.js +29 -6
  310. package/dist/timeline/origin.d.ts +1 -1
  311. package/dist/timeline/origin.js +2 -2
  312. package/dist/timeline/render-text.js +1 -1
  313. package/dist/timeline/timeline.d.ts +66 -4
  314. package/dist/timeline/timeline.js +160 -30
  315. package/dist/timeline/util.d.ts +5 -0
  316. package/dist/timeline/util.js +44 -8
  317. package/dist/timeline/web-calls.d.ts +17 -0
  318. package/dist/timeline/web-calls.js +106 -0
  319. package/dist/tool-gate.d.ts +42 -42
  320. package/dist/tool-gate.js +97 -91
  321. package/dist/tool-list.d.ts +4 -1
  322. package/dist/tool-list.js +8 -1
  323. package/dist/tool-names.d.ts +18 -13
  324. package/dist/tool-names.js +19 -17
  325. package/dist/tool-plane.d.ts +17 -13
  326. package/dist/tool-plane.js +12 -5
  327. package/dist/tools.d.ts +44 -16
  328. package/dist/tools.js +28 -28
  329. package/dist/trigger-adapter.d.ts +85 -5
  330. package/dist/trigger-adapter.js +6 -0
  331. package/dist/trigger-adapters.js +3 -1
  332. package/dist/trigger-composio.d.ts +10 -0
  333. package/dist/trigger-composio.js +122 -0
  334. package/dist/trigger-email.d.ts +4 -0
  335. package/dist/trigger-email.js +228 -0
  336. package/dist/trigger-signatures.d.ts +6 -10
  337. package/dist/trigger-signatures.js +16 -16
  338. package/dist/trigger-targets.d.ts +1 -1
  339. package/dist/trigger-targets.js +4 -3
  340. package/dist/trigger-webhook.js +6 -4
  341. package/dist/triggers.d.ts +94 -9
  342. package/dist/triggers.js +263 -62
  343. package/dist/uploads.d.ts +9 -0
  344. package/dist/uploads.js +27 -0
  345. package/dist/validate.js +1 -7
  346. package/dist/web-fake.d.ts +56 -0
  347. package/dist/web-fake.js +102 -0
  348. package/dist/web-fetch-direct.d.ts +3 -0
  349. package/dist/web-fetch-direct.js +4 -1
  350. package/dist/web-fetch.d.ts +5 -1
  351. package/dist/web-fetch.js +8 -31
  352. package/dist/web-search.d.ts +51 -2
  353. package/dist/web-search.js +116 -18
  354. package/dist/webhooks.d.ts +2 -1
  355. package/dist/webhooks.js +5 -1
  356. package/dist/workflow/node-runner.js +10 -2
  357. package/dist/workspace/archil-claim.d.ts +3 -0
  358. package/dist/workspace/archil-claim.js +9 -2
  359. package/dist/workspace/computer-deps.d.ts +22 -9
  360. package/dist/workspace/computer-deps.js +78 -37
  361. package/dist/workspace/computer-for-claim.d.ts +54 -4
  362. package/dist/workspace/computer-for-claim.js +179 -39
  363. package/dist/workspace/computer-janitor.d.ts +10 -3
  364. package/dist/workspace/computer-janitor.js +96 -29
  365. package/dist/workspace/computer-kept.d.ts +82 -0
  366. package/dist/workspace/computer-kept.js +147 -0
  367. package/dist/workspace/computer-mcp.js +4 -3
  368. package/dist/workspace/computer-ports.d.ts +23 -3
  369. package/dist/workspace/computer-ports.js +115 -5
  370. package/dist/workspace/index.d.ts +1 -2
  371. package/dist/workspace/index.js +1 -2
  372. package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
  373. package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
  374. package/dist/workspace/resolve-computer.d.ts +15 -3
  375. package/dist/workspace/resolve-computer.js +10 -7
  376. package/dist/workspace/revision-skills.d.ts +6 -2
  377. package/dist/workspace/revision-skills.js +12 -5
  378. package/dist/workspace/run-end-computers.d.ts +30 -0
  379. package/dist/workspace/run-end-computers.js +137 -0
  380. package/dist/workspace/run-tools.d.ts +28 -29
  381. package/dist/workspace/run-tools.js +29 -30
  382. package/dist/wrap-up.d.ts +19 -5
  383. package/dist/wrap-up.js +31 -4
  384. package/package.json +13 -9
  385. package/skills/agentrun-serve/SKILL.md +248 -10
  386. package/templates/README.md +117 -23
  387. package/templates/TOOLS.md +168 -0
  388. package/templates/code-review/agent.md +18 -4
  389. package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
  390. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
  391. package/templates/code-review/evals/other-repo/case.yaml +1 -1
  392. package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
  393. package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
  394. package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
  395. package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
  396. package/templates/code-review/skills/review/DEEP.md +2 -2
  397. package/templates/code-review/skills/review/REVIEWER.md +2 -2
  398. package/templates/code-review/skills/review/SKILL.md +7 -3
  399. package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
  400. package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
  401. package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
  402. package/templates/release-notes/evals/other-repo/case.yaml +1 -1
  403. package/dist/console/assets/index-CjqQirbo.css +0 -1
  404. package/dist/console/assets/index-b6-XY5A9.js +0 -576
  405. package/dist/host-calls.d.ts +0 -20
  406. package/dist/host-calls.js +0 -12
  407. package/dist/runner/adapters/pi-computer.d.ts +0 -9
  408. package/dist/runner/adapters/pi-computer.js +0 -51
  409. package/dist/workspace/computer-script.d.ts +0 -53
  410. package/dist/workspace/computer-script.js +0 -172
@@ -15,6 +15,24 @@ export const OPENAI_SEARCH_LIMIT = Object.freeze({ max_tool_calls: HOSTED_MAX_US
15
15
  const ANSWER_TOKENS = 2_048;
16
16
  /** As Exa's and Parallel's searches stop. */
17
17
  const TIMEOUT_MS = 60_000;
18
+ /** A provider's answer that the run's key is out of quota, by the status or the error code it names: a 402, Anthropic's
19
+ * billing_error, OpenAI's insufficient_quota (which OpenAI answers as a 429, so it is read first). */
20
+ const QUOTA = /(?<![\w.])402(?![\w.])|\b(?:billing_error|insufficient_quota)\b/;
21
+ /** A provider's answer that the run's key is rate-limited: a 429, Anthropic's rate_limit_error, OpenAI's
22
+ * rate_limit_exceeded, Anthropic's hosted search's own too_many_requests. Never its other failures (an overload, a 5xx),
23
+ * which pass. */
24
+ const RATE = /(?<![\w.])429(?![\w.])|\b(?:rate_limit_error|rate_limit_exceeded|too_many_requests)\b/;
25
+ /** The limit `said` names, with the Retry-After `error` carries when the provider's client kept its headers (none: the
26
+ * breaker's 60 s). */
27
+ function limitOf(said, error) {
28
+ if (QUOTA.test(said))
29
+ return { kind: "quota" };
30
+ if (!RATE.test(said))
31
+ return undefined;
32
+ const headers = error?.headers;
33
+ const header = headers instanceof Headers ? headers.get("retry-after") : headers && typeof headers === "object" ? headers["retry-after"] : undefined;
34
+ return { kind: "rate", ...(typeof header === "string" && header ? { retryAfter: header } : {}) };
35
+ }
18
36
  const list = (value) => (Array.isArray(value) ? value.filter((item) => typeof item === "object" && item !== null) : []);
19
37
  const text = (value) => (typeof value === "string" ? value : undefined);
20
38
  /** What a provider's events say of the search: its results by URL, first seen first, and how many searches it ran. */
@@ -27,11 +45,18 @@ function reader(anthropic) {
27
45
  hits.set(url, { ...found, ...Object.fromEntries(Object.entries(hit).filter(([, value]) => value)) });
28
46
  };
29
47
  let failed;
48
+ // Every search's error code, kept whether or not another search found results: a later search rate-limited after an
49
+ // early one's hits still says the run's key is limited.
50
+ const codes = [];
30
51
  const anthropicEvent = (event) => {
31
52
  const block = event.content_block;
32
53
  if (event.type === "content_block_start" && block?.type === "web_search_tool_result") {
33
- if (!Array.isArray(block.content))
34
- failed = text(block.content?.error_code) ?? "the search failed";
54
+ if (!Array.isArray(block.content)) {
55
+ const code = text(block.content?.error_code);
56
+ if (code)
57
+ codes.push(code);
58
+ failed = code ?? "the search failed";
59
+ }
35
60
  for (const result of list(block.content))
36
61
  if (result.type === "web_search_result")
37
62
  add(result.url, { title: text(result.title), published: text(result.page_age) });
@@ -62,12 +87,21 @@ function reader(anthropic) {
62
87
  return {
63
88
  event: (event) => (anthropic ? anthropicEvent : openaiEvent)((event ?? {})),
64
89
  failed: () => (hits.size ? undefined : failed),
90
+ codes: () => codes,
65
91
  hits: () => [...hits].map(([url, hit]) => ({ url, title: clip(hit.title ?? "", TITLE_CAP), snippet: snippetOf(hit.snippet ?? ""), ...(hit.published ? { published: hit.published } : {}) })),
66
92
  };
67
93
  }
68
94
  /** `query` searched by `ref`'s provider (`provider/model-id`, the model the server resolved web_search on) through the
69
95
  * run's models (`models`: its own, handed by the run; none, no model to search on), at most `n` results: a Search. */
70
96
  export async function hostedSearch(query, n, ref, signal, models) {
97
+ return (await hostedSearched(query, n, ref, signal, models)).answer;
98
+ }
99
+ /** hostedSearch, and the limit the provider answered for the run's key, if any (QUOTA, RATE). */
100
+ export async function hostedSearched(query, n, ref, signal, models) {
101
+ const failed = (error, said = "", thrown) => {
102
+ const limit = limitOf(said, thrown);
103
+ return { answer: { error }, ...(limit ? { limit } : {}) };
104
+ };
71
105
  const slash = ref?.indexOf("/") ?? -1;
72
106
  const provider = ref && slash > 0 ? ref.slice(0, slash) : undefined;
73
107
  const id = ref && slash > 0 ? ref.slice(slash + 1) : undefined;
@@ -75,10 +109,10 @@ export async function hostedSearch(query, n, ref, signal, models) {
75
109
  // provider.ts anthropicModelId), the one the run's models hold.
76
110
  const model = models && provider && id ? (models.getModel(provider, id) ?? (provider === "anthropic" ? models.getModel(provider, id.replaceAll(".", "-")) : undefined)) : undefined;
77
111
  if (!models || !model)
78
- return { error: `web_search has no model to search on in this run${ref ? ` (${ref})` : ""}` };
112
+ return failed(`web_search has no model to search on in this run${ref ? ` (${ref})` : ""}`);
79
113
  const anthropic = model.api === "anthropic-messages";
80
114
  if (!anthropic && model.api !== "openai-responses")
81
- return { error: `web_search: ${ref} has no hosted web search here` };
115
+ return failed(`web_search: ${ref} has no hosted web search here`);
82
116
  const read = reader(anthropic);
83
117
  const context = { messages: [{ role: "user", content: [{ type: "text", text: `Search the web for: ${query}\n\nAnswer briefly from what the search finds, and name each source by its URL.` }], timestamp: Date.now() }] };
84
118
  let answer;
@@ -97,13 +131,19 @@ export async function hostedSearch(query, n, ref, signal, models) {
97
131
  });
98
132
  }
99
133
  catch (error) {
100
- return { error: `the provider's search failed: ${String(error?.message ?? error).slice(0, 300)}` };
134
+ const said = String(error?.message ?? error);
135
+ return failed(`the provider's search failed: ${said.slice(0, 300)}`, `${error?.status ?? ""} ${said}`, error);
101
136
  }
102
- if (answer.stopReason === "error" || answer.stopReason === "aborted")
103
- return { error: answer.stopReason === "aborted" ? "the search was stopped" : `the provider's search failed: ${(answer.errorMessage ?? "no detail").slice(0, 300)}` };
104
- const failed = read.failed();
105
- if (failed)
106
- return { error: `the provider's search failed: ${failed}` };
137
+ if (answer.stopReason === "aborted")
138
+ return failed("the search was stopped");
139
+ if (answer.stopReason === "error")
140
+ return failed(`the provider's search failed: ${(answer.errorMessage ?? "no detail").slice(0, 300)}`, answer.errorMessage);
141
+ const refused = read.failed();
142
+ if (refused)
143
+ return failed(`the provider's search failed: ${refused}`, refused);
107
144
  const said = answer.content.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("").trim();
108
- return { provider: "native", query, results: read.hits().slice(0, n), ...(said ? { text: clip(said, ANSWER_MAX) } : {}) };
145
+ // Results found, and a later search of the same request failing all the same (too_many_requests after hits): the run
146
+ // gets the results, and the breaker the limit its codes name (no Retry-After reaches here: 60 s).
147
+ const limit = limitOf(read.codes().join(" "));
148
+ return { answer: { provider: "native", query, results: read.hits().slice(0, n), ...(said ? { text: clip(said, ANSWER_MAX) } : {}) }, ...(limit ? { limit } : {}) };
109
149
  }
@@ -90,7 +90,7 @@ export type Session = {
90
90
  effort?: string;
91
91
  };
92
92
  /** The session files of `source` under `home`, never through a link. */
93
- export declare function sessionFiles(home: string, source: Source): Promise<string[]>;
93
+ export declare function sessionFiles(home: string, source: Source, configRoot?: string): Promise<string[]>;
94
94
  /** Claude Code's subagents' session files under `home`, in <session id>/subagents/ (a workflow's a folder deeper), each
95
95
  * with the session file it ran under (`of`): the one beside the folder it sits in. A session moved to another project
96
96
  * folder keeps its id there, with copies of its subagents' files: each folder's are its own file's. Never through a
@@ -19,11 +19,11 @@ export const HARNESS_OF = {
19
19
  * open and counts nothing. Claude Code's Bash tool runs a call for up to 10 minutes with nothing written. */
20
20
  export const ACTIVE_GAP_MS = 15 * 60_000;
21
21
  /** The session files of `source` under `home`, never through a link. */
22
- export async function sessionFiles(home, source) {
22
+ export async function sessionFiles(home, source, configRoot) {
23
23
  const entries = async (dir) => readdir(dir, { withFileTypes: true }).catch(() => []);
24
24
  const out = [];
25
25
  if (source === "claude-code") {
26
- const root = join(home, ".claude", "projects");
26
+ const root = join(configRoot ?? join(home, ".claude"), "projects");
27
27
  for (const project of await entries(root)) {
28
28
  if (!project.isDirectory())
29
29
  continue;
@@ -41,7 +41,7 @@ export async function sessionFiles(home, source) {
41
41
  out.push(join(dir, entry.name));
42
42
  }
43
43
  };
44
- await walk(join(home, ".codex", "sessions"), 0);
44
+ await walk(join(configRoot ?? join(home, ".codex"), "sessions"), 0);
45
45
  }
46
46
  else {
47
47
  const root = join(home, ".pi", "agent", "sessions");
package/dist/import.d.ts CHANGED
@@ -12,6 +12,27 @@ export type ImportStore = {
12
12
  importRun: Store["importRun"];
13
13
  readJournal: Store["readJournal"];
14
14
  };
15
+ /** Read only the explicitly selected project's historical sessions for an outbound connector. Metadata enumeration
16
+ * locates project sessions; unrelated transcripts are never exported or scanned for keys. No model is called and no
17
+ * source file is changed. Each page is independently redacted, bounded and safe to retry at the destination. */
18
+ export declare function exportRemoteHistory(target: Pick<import('./native/types.js').NativeTarget, 'runtime' | 'project' | 'selector'>, options?: {
19
+ home?: string;
20
+ env?: NodeJS.ProcessEnv;
21
+ own?: readonly string[];
22
+ now?: number;
23
+ cursor?: number;
24
+ inventory?: string;
25
+ preview?: boolean;
26
+ }): Promise<{
27
+ sessions: import('./native/history.js').RemoteHistorySession[];
28
+ skipped: {
29
+ reason: string;
30
+ count: number;
31
+ }[];
32
+ next_cursor: number | null;
33
+ total: number;
34
+ inventory: string;
35
+ }>;
15
36
  /** In the data directory while an import the owner asked for at setup has not ended: the server's next start goes on with it. */
16
37
  export declare const IMPORT_ASKED = ".import-at-setup";
17
38
  /** A session file written to this recently may still be running: it is left for a later import. */
package/dist/import.js CHANGED
@@ -6,7 +6,7 @@
6
6
  // the owner's only. Read again, it imports only the sessions it has not.
7
7
  import { createHash, randomUUID } from "node:crypto";
8
8
  import { existsSync } from "node:fs";
9
- import { lstat, realpath, stat } from "node:fs/promises";
9
+ import { lstat, open, realpath, stat } from "node:fs/promises";
10
10
  import { homedir, tmpdir } from "node:os";
11
11
  import { basename, dirname, join, sep } from "node:path";
12
12
  import { parseArgs } from "node:util";
@@ -32,6 +32,189 @@ import { journalEntries } from "./runner/journal-reader.js";
32
32
  import { bodyOf, openStore, SchemaVersionUnknown, StoreFromEarlierVersion, StoreOwned, storeTarget } from "./store/index.js";
33
33
  import { STORE_FILE } from "./store/sqlite/store.js";
34
34
  import { foundOverStore } from "./store-reads/import-summary.js";
35
+ /** Read only the explicitly selected project's historical sessions for an outbound connector. Metadata enumeration
36
+ * locates project sessions; unrelated transcripts are never exported or scanned for keys. No model is called and no
37
+ * source file is changed. Each page is independently redacted, bounded and safe to retry at the destination. */
38
+ export async function exportRemoteHistory(target, options = {}) {
39
+ if (target.selector.kind !== 'project')
40
+ throw new Error('Session logs do not reliably identify named agents or profiles. Select the project to import its history.');
41
+ const now = options.now ?? Date.now(), cursor = options.cursor ?? 0;
42
+ if (!Number.isSafeInteger(cursor) || cursor < 0)
43
+ throw new Error('Invalid history cursor.');
44
+ const project = await realpath(target.project), selected = [], skipped = new Map(), stamps = new Map();
45
+ const sourceEnv = options.env ?? process.env, configRoot = target.runtime === 'claude-code' ? sourceEnv.CLAUDE_CONFIG_DIR : sourceEnv.CODEX_HOME;
46
+ const skip = (reason) => skipped.set(reason, (skipped.get(reason) ?? 0) + 1);
47
+ for (const { file, stats } of await inOrder(await sessionFiles(options.home ?? homedir(), target.runtime, configRoot), target.runtime)) {
48
+ if (stats.size > MAX_SESSION_BYTES) {
49
+ skip('Source session project could not be checked: file exceeds the metadata limit.');
50
+ continue;
51
+ }
52
+ // Stop once a complete metadata record names its project. An opening prompt may itself be over 128 KiB;
53
+ // the probe is bounded by the same byte limit as a remotely importable session, without scanning its secrets.
54
+ const header = await remoteHistoryMetadata(file, target.runtime).catch(() => undefined);
55
+ if (!header) {
56
+ skip('Source session project could not be checked: unreadable metadata or metadata size limit exceeded.');
57
+ continue;
58
+ }
59
+ if ((await realpath(header.cwd).catch(() => header.cwd)) !== project)
60
+ continue;
61
+ // Metadata identifies the project without parsing a transcript that cannot fit in any export page.
62
+ if (stats.size > REMOTE_HISTORY_SOURCE_BYTES) {
63
+ skip('Source session file exceeds the remote import size limit.');
64
+ continue;
65
+ }
66
+ if (header.child) {
67
+ skip('Subagent history is not a separate session.');
68
+ continue;
69
+ }
70
+ if (now - stats.mtimeMs < LIVE_MS) {
71
+ skip('Still being written or modified within ten minutes.');
72
+ continue;
73
+ }
74
+ selected.push({ source: target.runtime, id: header.id, file });
75
+ stamps.set(file, remoteHistoryStamp(stats));
76
+ }
77
+ const groups = byRun(selected).sort((a, b) => a[0].id.localeCompare(b[0].id));
78
+ const inventory = hash(JSON.stringify({ project, runtime: target.runtime, groups: groups.map(files => ({ id: files[0].id, files: files.map(file => ({ path: file.file, stamp: stamps.get(file.file) })).sort((a, b) => a.path.localeCompare(b.path)) })) }));
79
+ if ((cursor > 0 && options.inventory === undefined) || (options.inventory !== undefined && options.inventory !== inventory))
80
+ throw new Error('The selected history inventory changed or is missing. Restart the import from its preview; previously imported sessions are safe to retry.');
81
+ const report = () => [...skipped].map(([reason, count]) => ({ reason, count }));
82
+ if (options.preview)
83
+ return { sessions: [], skipped: report(), next_cursor: null, total: groups.length, inventory };
84
+ if (cursor > 0)
85
+ skipped.clear(); // enumeration skips are reported once; each page still reports its own skips
86
+ const sessions = [], cut = secretCut([process.env, options.env ?? {}], SECRET_NAMES);
87
+ cut.add(options.own ?? []);
88
+ let bytes = 0, index = cursor;
89
+ for (; index < groups.length && sessions.length < 20; index++) {
90
+ const parts = [], seen = new Set();
91
+ let changed = false, child = false;
92
+ for (const listed of groups[index]) {
93
+ const before = await stat(listed.file).catch(() => undefined);
94
+ const approvedStamp = stamps.get(listed.file);
95
+ if (!before || remoteHistoryStamp(before) !== approvedStamp || now - before.mtimeMs < LIVE_MS || before.size > REMOTE_HISTORY_SOURCE_BYTES) {
96
+ changed = true;
97
+ break;
98
+ }
99
+ const part = await readSession(listed.file, target.runtime, { seen }).catch(() => undefined), after = await stat(listed.file).catch(() => undefined);
100
+ if (!part || !after || remoteHistoryStamp(after) !== approvedStamp || !part.cwd || (await realpath(part.cwd).catch(() => part.cwd)) !== project || part.id !== listed.id) {
101
+ changed = true;
102
+ break;
103
+ }
104
+ // Opening metadata is only a candidate: a later record can identify a child session.
105
+ // The full parser remains authoritative before any transcript can leave the machine.
106
+ if (part.child) {
107
+ child = true;
108
+ break;
109
+ }
110
+ parts.push(part);
111
+ }
112
+ if (child) {
113
+ skip('Subagent history is not a separate session.');
114
+ continue;
115
+ }
116
+ if (changed || !parts.length) {
117
+ skip('Source session changed during export or became unreadable.');
118
+ continue;
119
+ }
120
+ const session = merged(parts);
121
+ if (!session.startedAt || !session.endedAt || Date.parse(session.endedAt) > now - LIVE_MS) {
122
+ skip('Session has no stable historical completion time.');
123
+ continue;
124
+ }
125
+ if (session.turns.length > 2000) {
126
+ skip('Session exceeds 2000 turns; it was not truncated.');
127
+ continue;
128
+ }
129
+ cut.add(await keysInSessions(parts));
130
+ // Include current and older connector/enrollment credentials, even when no longer present in the environment.
131
+ cut.add(JSON.stringify(parts).match(/ar_(?:connector|enroll|local)_[A-Za-z0-9_-]{20,}/g) ?? []);
132
+ const packet = JSON.parse(JSON.stringify(cut.json({ source: session.source, id: session.id, startedAt: session.startedAt, endedAt: session.endedAt, state: session.state, model: session.model, costUsd: session.costUsd, firstPrompt: session.firstPrompt, activeMs: session.activeMs, turns: session.turns })));
133
+ if (packet.id !== session.id)
134
+ packet.id = redactedId(session.id);
135
+ const size = Buffer.byteLength(JSON.stringify(packet));
136
+ if (size > 1_000_000) {
137
+ skip('Session exceeds 1 MB after redaction; it was not truncated.');
138
+ continue;
139
+ }
140
+ try {
141
+ (await import('./native/history.js')).remoteHistorySessions({ sessions: [packet] }, target.runtime, now);
142
+ }
143
+ catch {
144
+ skip('Session contains unsupported or excessive fields; it was not truncated.');
145
+ continue;
146
+ }
147
+ if (bytes + size > 1_800_000)
148
+ break;
149
+ sessions.push(packet);
150
+ bytes += size;
151
+ }
152
+ return { sessions, skipped: report(), next_cursor: index < groups.length ? index : null, total: groups.length, inventory };
153
+ }
154
+ const REMOTE_HISTORY_SOURCE_BYTES = 8_000_000;
155
+ /** Candidate identity only, matching readSession's source metadata fields. Stop once both id and project are known;
156
+ * do not parse every transcript on every page. The requested page still fully parses and checks each candidate's
157
+ * id, project and child status under its approved file stamp. Preview counts candidates, not guaranteed exports.
158
+ * Keep at most one bounded JSONL record and never read past the remote source limit, even if a file grows. */
159
+ async function remoteHistoryMetadata(file, source) {
160
+ const handle = await open(file, 'r');
161
+ let id, cwd, child = false;
162
+ const str = (value) => typeof value === 'string' && value !== '' ? value : undefined;
163
+ const metadataOf = (parts) => {
164
+ try {
165
+ const row = JSON.parse(Buffer.concat(parts).toString('utf8'));
166
+ if (!row || typeof row !== 'object' || Array.isArray(row))
167
+ return;
168
+ if (source === 'claude-code') {
169
+ id ??= str(row.sessionId);
170
+ cwd ??= str(row.cwd);
171
+ child ||= row.isSidechain === true;
172
+ }
173
+ else if (row.type === 'session_meta') {
174
+ const payload = row.payload;
175
+ if (!payload || typeof payload !== 'object' || Array.isArray(payload))
176
+ return;
177
+ id = str(payload.id) ?? id;
178
+ cwd = str(payload.cwd) ?? cwd;
179
+ child ||= !!str(payload.parent_thread_id) || !!(payload.source && typeof payload.source === 'object' && payload.source.subagent && typeof payload.source.subagent === 'object');
180
+ }
181
+ else if (row.type === 'turn_context')
182
+ cwd ??= str(row.payload?.cwd);
183
+ }
184
+ catch { /* An unreadable record supplies no identity, as in readSession. */ }
185
+ };
186
+ const metadata = () => id && cwd ? { id, cwd, child } : undefined;
187
+ let position = 0, parts = [];
188
+ try {
189
+ while (position < REMOTE_HISTORY_SOURCE_BYTES) {
190
+ const bytes = Buffer.alloc(Math.min(64 * 1024, REMOTE_HISTORY_SOURCE_BYTES - position));
191
+ const { bytesRead } = await handle.read(bytes, 0, bytes.length, position);
192
+ if (!bytesRead) {
193
+ metadataOf(parts);
194
+ // readSession uses the file name only when no source record supplied an id. That is known only at EOF.
195
+ id ??= basename(file, '.jsonl');
196
+ return metadata();
197
+ }
198
+ position += bytesRead;
199
+ let start = 0;
200
+ for (let end = bytes.indexOf(10); end >= 0 && end < bytesRead; end = bytes.indexOf(10, start)) {
201
+ parts.push(bytes.subarray(start, end));
202
+ metadataOf(parts);
203
+ const found = metadata();
204
+ if (found)
205
+ return found;
206
+ parts = [];
207
+ start = end + 1;
208
+ }
209
+ if (start < bytesRead)
210
+ parts.push(bytes.subarray(start, bytesRead));
211
+ }
212
+ return undefined; // Do not parse a record cut short by the byte limit.
213
+ }
214
+ finally {
215
+ await handle.close();
216
+ }
217
+ }
35
218
  /** In the data directory while an import the owner asked for at setup has not ended: the server's next start goes on with it. */
36
219
  export const IMPORT_ASKED = ".import-at-setup";
37
220
  /** A session file written to this recently may still be running: it is left for a later import. */
@@ -56,6 +239,8 @@ const hash = (text) => createHash("sha256").update(text).digest("hex");
56
239
  const redactedId = (id) => `redacted-${hash(id).slice(0, 16)}`;
57
240
  /** A file's size and time, as an import read it: the same after means the same content was read. */
58
241
  const stampOf = (stats) => `${stats.size}:${stats.mtimeMs}`;
242
+ /** Bind remote consent to the enumerated source, including archive replacements that preserve size and mtime. */
243
+ const remoteHistoryStamp = (stats) => `${stats.dev}:${stats.ino}:${stats.size}:${stats.mtimeMs}:${stats.ctimeMs}`;
59
244
  const keptId = (envs, own = []) => {
60
245
  const { text, add } = secretCut(envs, SECRET_NAMES);
61
246
  add(own);
@@ -17,9 +17,7 @@ export type CheckOutcome = KeyCheck | {
17
17
  };
18
18
  type Call = {
19
19
  url: string;
20
- method?: "POST";
21
20
  headers: Record<string, string>;
22
- body?: string;
23
21
  };
24
22
  /** Each provider's check, by key id (tool-keys.ts' TOOL_KEYS, and a model provider's key where the server keeps one),
25
23
  * made with the key and the server's environment, at the base this server sends that provider's calls to. */
package/dist/key-check.js CHANGED
@@ -19,10 +19,9 @@ const base = (set, fallback) => (set?.trim() || fallback).replace(/\/+$/, "");
19
19
  /** Each provider's check, by key id (tool-keys.ts' TOOL_KEYS, and a model provider's key where the server keeps one),
20
20
  * made with the key and the server's environment, at the base this server sends that provider's calls to. */
21
21
  export const KEY_CHECKS = {
22
- // A discover of one result, as every monid tool call starts. That discover costs nothing is read from monid's pricing
23
- // page, not stated there: it prices running an endpoint, and shows that price in discover's results
24
- // (https://docs.monid.ai/guide/pricing.html, https://docs.monid.ai/api/discover.html).
25
- monid: (key) => ({ url: `${MONID_API}/v1/discover`, method: "POST", headers: { authorization: `Bearer ${key}`, "content-type": "application/json" }, body: JSON.stringify({ query: "company data", limit: 1 }) }),
22
+ // One endpoint of monid's listing, the read a save pins grants from (monid.ts pinMonid): monid prices running an
23
+ // endpoint, never its listing (https://docs.monid.ai/guide/pricing.html).
24
+ monid: (key) => ({ url: `${MONID_API}/v1/endpoints?limit=1`, headers: { authorization: `Bearer ${key}` } }),
26
25
  // A list of the key's monitors: Parallel prices searches, extracts, decisions, task runs and a monitor's executions,
27
26
  // never a list (https://docs.parallel.ai/api-reference/monitor/list-monitors, https://docs.parallel.ai/getting-started/pricing).
28
27
  parallel: (key) => ({ url: "https://api.parallel.ai/v1/monitors?limit=1", headers: { "x-api-key": key } }),
@@ -15,8 +15,9 @@ export declare function runKeyOf(env: NodeJS.ProcessEnv, harness?: string, ref?:
15
15
  * Only the head serve can show is read: SHOWN characters, plus room for the longest held value in its widest encoded
16
16
  * form (6 times it, for JSON's \uXXXX; percent is 3, hex 2, base64 4/3) and 16 more. A key whose start the cut can show
17
17
  * starts before SHOWN, so it ends inside that head and is found whole; one that starts later is never shown. So a long
18
- * error costs no more to redact than a short one, whatever it holds. */
19
- export declare function redacted(text: string, secrets: readonly string[]): string;
18
+ * error costs no more to redact than a short one, whatever it holds. `shown`: a head of another length, for a reader
19
+ * that is shown more (a template eval's grader reads a call's result to CALL_RESULT_CHARS). */
20
+ export declare function redacted(text: string, secrets: readonly string[], shown?: number): string;
20
21
  /** How many texts redactedAnswer has read in this process: a test reads it to see a run's view served from what an
21
22
  * earlier view redacted (runs.ts servedOnce). */
22
23
  export declare const answerPasses: {
@@ -30,6 +31,11 @@ export declare const answerPasses: {
30
31
  * by whitespace across a cut, or a form only found across pieces, still shows to one valueMatcher pass over the joined
31
32
  * output, and then the whole answer is "[redacted]", as redactSecrets does with a text that still holds a value. */
32
33
  export declare function redactedAnswer(text: string, secrets: readonly string[]): string;
34
+ /** Whether a number shows a held value. A held value can be all digits (a gateway's key), and a record or a call's
35
+ * arguments can quote it as a number: one whose digits hold a held value, by the same rule as a string's, is held. A
36
+ * number can also EQUAL a held value whose text differs from its own (a leading zero, 1e21, a long key read lossy). A
37
+ * boolean's text is shorter than any held value. */
38
+ export declare function heldNumber(value: number | bigint, secrets: readonly string[]): boolean;
33
39
  /** `value`, a run's workflow output, with redactedAnswer applied to each string and number in it, property NAMES
34
40
  * included (a dictionary field can be keyed by anything a run wrote), its shape kept. Two names of one object that come
35
41
  * out the same would merge one value over the other: that object is withheld whole, as "[redacted]". */
@@ -53,18 +53,19 @@ const SHOWN = 2000;
53
53
  * Only the head serve can show is read: SHOWN characters, plus room for the longest held value in its widest encoded
54
54
  * form (6 times it, for JSON's \uXXXX; percent is 3, hex 2, base64 4/3) and 16 more. A key whose start the cut can show
55
55
  * starts before SHOWN, so it ends inside that head and is found whole; one that starts later is never shown. So a long
56
- * error costs no more to redact than a short one, whatever it holds. */
57
- export function redacted(text, secrets) {
56
+ * error costs no more to redact than a short one, whatever it holds. `shown`: a head of another length, for a reader
57
+ * that is shown more (a template eval's grader reads a call's result to CALL_RESULT_CHARS). */
58
+ export function redacted(text, secrets, shown = SHOWN) {
58
59
  const longest = secrets.reduce((most, value) => Math.max(most, value.length), 0);
59
- const window = SHOWN + 6 * longest + 16;
60
+ const window = shown + 6 * longest + 16;
60
61
  if (text.length <= window)
61
62
  return redactSecrets(text, secrets, Buffer.byteLength(text));
62
63
  const out = redactSecrets(text.slice(0, window), secrets, window * 4);
63
64
  // A replacement moves what follows it left by at most S characters in all: the shortening, plus 2 for each "[redacted]"
64
- // (a value of 8 or 9 characters grows into it). So output[0, SHOWN - S) comes from raw text before SHOWN, where every
65
+ // (a value of 8 or 9 characters grows into it). So output[0, shown - S) comes from raw text before `shown`, where every
65
66
  // key that starts ends inside the window and was found whole; past that, a copy the window cut could come into view.
66
67
  const shift = window - out.length + 2 * out.split("[redacted]").length - 2;
67
- const keep = SHOWN - shift;
68
+ const keep = shown - shift;
68
69
  return keep <= 0 ? "[redacted]" : `${out.slice(0, keep)}...`;
69
70
  }
70
71
  /** The most of a run's answer one redaction pass reads: learning's redactSecrets restarts after each overlapping match,
@@ -106,20 +107,22 @@ export function redactedAnswer(text, secrets) {
106
107
  const out = parts.join("");
107
108
  return valueMatcher(secrets)(out) ? "[redacted]" : out;
108
109
  }
110
+ /** Whether a number shows a held value. A held value can be all digits (a gateway's key), and a record or a call's
111
+ * arguments can quote it as a number: one whose digits hold a held value, by the same rule as a string's, is held. A
112
+ * number can also EQUAL a held value whose text differs from its own (a leading zero, 1e21, a long key read lossy). A
113
+ * boolean's text is shorter than any held value. */
114
+ export function heldNumber(value, secrets) {
115
+ const text = String(value);
116
+ return redactedAnswer(text, secrets) !== text || secrets.some((secret) => secret.trim() !== "" && Number(secret) === Number(value));
117
+ }
109
118
  /** `value`, a run's workflow output, with redactedAnswer applied to each string and number in it, property NAMES
110
119
  * included (a dictionary field can be keyed by anything a run wrote), its shape kept. Two names of one object that come
111
120
  * out the same would merge one value over the other: that object is withheld whole, as "[redacted]". */
112
121
  export function redactedOutput(value, secrets) {
113
122
  if (typeof value === "string")
114
123
  return redactedAnswer(value, secrets);
115
- // A held value can be all digits (a gateway's key), and a record can quote it as a number: one whose digits hold a held
116
- // value, by the same rule as a string's, is withheld as "[redacted]". A boolean's text is shorter than any held value.
117
- // A number can also EQUAL a held value whose text differs from its own (a leading zero, 1e21, a long key read lossy).
118
- if (typeof value === "number" || typeof value === "bigint") {
119
- const text = String(value);
120
- const held = redactedAnswer(text, secrets) !== text || secrets.some((secret) => secret.trim() !== "" && Number(secret) === Number(value));
121
- return held ? "[redacted]" : value;
122
- }
124
+ if (typeof value === "number" || typeof value === "bigint")
125
+ return heldNumber(value, secrets) ? "[redacted]" : value;
123
126
  if (Array.isArray(value))
124
127
  return value.map((item) => redactedOutput(item, secrets));
125
128
  if (value && typeof value === "object") {
@@ -1,5 +1,5 @@
1
1
  import { type LearnedNote } from "./notes.js";
2
- import { type DraftAsk, type DraftDecisions, type DraftDryRun, type DraftReader } from "./skills.js";
2
+ import { type DraftDecisions, type DraftDryRun, type DraftReader } from "./skills.js";
3
3
  /** A note's bytes as the note cap counts them: all of `text` but the `compiled_into` line the host adds when a learned
4
4
  * workflow is compiled from it (notes.ts compiledLineBytes). A note at the cap stays one once marked: it retires,
5
5
  * restores, and a later note supersedes it through the grader, each checked against `note`. A run never sets the line
@@ -73,13 +73,13 @@ export type CheckInput = {
73
73
  /** The agent's granted tools the gate does not allow, with what each is set to (tools.ts learnedDraftTools): a draft
74
74
  * whose call node calls one is refused, in the words a workflow revision's is (learn/skills.ts gatedNodes). */
75
75
  readonly gated?: Readonly<Record<string, string>>;
76
- /** The MCP tools set to ask a learned call would ask about, and the gate's card rule (skills.ts DraftAsk, #2424). */
77
- readonly ask?: DraftAsk;
78
76
  /** Where each of `gated`'s denies was set (this agent's settings or this server's), for the refusal's words. */
79
77
  readonly deniedBy?: Readonly<Record<string, "agent" | "server" | "default">>;
80
78
  /** False for a run of a revision that says `learning: "notes"`: a workflow draft it gives is left out (rule `workflow`,
81
79
  * NOTES_ONLY), and its notes and skill go on. */
82
80
  readonly workflows?: false;
81
+ /** Explicit host adapter capabilities; absent keeps the managed runner defaults. */
82
+ readonly workflowAdapters?: readonly ("runNode" | "runJudge")[];
83
83
  /** The workflow DSL a draft is read with; a proposal that holds a draft is checked with it, never without. */
84
84
  readonly dsl?: DraftReader;
85
85
  /** The decision providers a draft's decision nodes may ask, and the gate's setting of each (learn/skills.ts
@@ -101,6 +101,21 @@ export type ProposalCheck = {
101
101
  /** `problem` as it may be printed: its path and detail cut of `values` and of every shape learning refuses, a bank's
102
102
  * numbers too (redactLearned: a name refused for one never prints it), whole when over PRINT_MAX. */
103
103
  export declare const printable: (problem: Problem, values: readonly string[]) => Problem;
104
+ /** Why a draft's answer is not written on the agent's own model: each model node that writes the state key its
105
+ * output.path reads (its answering step) and names tier "fast", one line each, in words the compile retry acts on. A
106
+ * composed workflow node that writes it answers with its own workflow's answering step, held to the same; a map that
107
+ * writes it collects each item's result (the DSL's map: its resultPath's key in the item's state, else its body's `as`,
108
+ * else the item's whole state), so the body's step writing that is the answering one. A map body's other writes stay in
109
+ * its item and are never the answer; a loop's body writes the state around it. Legwork on fast and an answer on strong
110
+ * pass. Out of sample (H1), the same answering step on the fast model scored 8.5-9.6 points lower than on the agent's. */
111
+ export declare function answerTierProblems(doc: unknown): string[];
112
+ /** Why a draft's quote check is not code: its answer carries quotes (a `quote` or `quotes` property in its output schema)
113
+ * and it fetches pages (a call step), yet some place in the answer holding quotes has no escalate on quote_missing
114
+ * reading it after the answer is written (quoteRule), or that escalate reads as a page a key holding no page as fetched
115
+ * (a model's summary of a page is no page). A judge or an `ask` is never the quote check:
116
+ * H5's judge flagged 149 of 170 answers while 416 of 429 quotes were in the pages, and could not tell the 8 answers
117
+ * quoting text no page held from the rest; code can. One line each, in words the compile retry acts on. */
118
+ export declare function quoteCheckProblems(doc: unknown): string[];
104
119
  /** The checks one note's file passes by itself (SPEC.md), as a person writes it through the host: its name, the note cap,
105
120
  * UTF-8, hidden characters, secret shapes and the host's values in its name and text, and its front matter. A person
106
121
  * may set `status` and `superseded_by`; what a run may not do (edit, delete, set status) is checkProposal's. Every