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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (388) hide show
  1. package/CHANGELOG.md +231 -0
  2. package/README.md +580 -320
  3. package/dist/acp-package.d.ts +28 -0
  4. package/dist/acp-package.js +23 -0
  5. package/dist/adapter-facts.d.ts +8 -1
  6. package/dist/adapter-facts.js +9 -1
  7. package/dist/adapters.d.ts +5 -0
  8. package/dist/adapters.js +36 -3
  9. package/dist/agent-delete.d.ts +50 -0
  10. package/dist/agent-delete.js +125 -0
  11. package/dist/agents-store.d.ts +9 -3
  12. package/dist/agents-store.js +22 -8
  13. package/dist/agents.d.ts +5 -1
  14. package/dist/agents.js +8 -4
  15. package/dist/api-only.d.ts +8 -3
  16. package/dist/api-only.js +10 -4
  17. package/dist/archil-routes.d.ts +5 -1
  18. package/dist/archil-routes.js +57 -2
  19. package/dist/browser-wait-ended.d.ts +2 -0
  20. package/dist/browser-wait-ended.js +2 -0
  21. package/dist/calendar/ics-faux.d.ts +3 -1
  22. package/dist/calendar/ics-faux.js +12 -2
  23. package/dist/calendar/tools.js +5 -2
  24. package/dist/chatgpt-plan.js +3 -1
  25. package/dist/claude-login.d.ts +135 -0
  26. package/dist/claude-login.js +244 -0
  27. package/dist/cli.js +92 -22
  28. package/dist/composio-preset.d.ts +4 -3
  29. package/dist/composio-preset.js +81 -11
  30. package/dist/composio-triggers.d.ts +34 -2
  31. package/dist/composio-triggers.js +261 -31
  32. package/dist/computer-attach.d.ts +40 -5
  33. package/dist/computer-attach.js +130 -15
  34. package/dist/computer-keys.d.ts +3 -0
  35. package/dist/computer-keys.js +7 -1
  36. package/dist/computer-live.js +3 -2
  37. package/dist/computer-lost.d.ts +11 -0
  38. package/dist/computer-lost.js +19 -0
  39. package/dist/computer-record.d.ts +10 -2
  40. package/dist/computer-record.js +50 -18
  41. package/dist/computer-setting.d.ts +1 -0
  42. package/dist/computer-setting.js +2 -2
  43. package/dist/computers.d.ts +21 -10
  44. package/dist/computers.js +39 -28
  45. package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
  46. package/dist/console/assets/index-DaFsZuzQ.css +1 -0
  47. package/dist/console/index.html +2 -2
  48. package/dist/decisions.d.ts +1 -1
  49. package/dist/dial-relay.d.ts +29 -0
  50. package/dist/dial-relay.js +94 -0
  51. package/dist/email/tools.js +10 -5
  52. package/dist/env-proxy.d.ts +2 -0
  53. package/dist/env-proxy.js +35 -0
  54. package/dist/errors.d.ts +4 -1
  55. package/dist/errors.js +10 -4
  56. package/dist/faux-computers.d.ts +8 -2
  57. package/dist/faux-computers.js +83 -6
  58. package/dist/harness-archive.d.ts +67 -0
  59. package/dist/harness-archive.js +177 -0
  60. package/dist/harness-goose.d.ts +34 -0
  61. package/dist/harness-goose.js +87 -0
  62. package/dist/harness-install.d.ts +21 -0
  63. package/dist/harness-install.js +24 -11
  64. package/dist/harness-opencode/adapter.js +1 -1
  65. package/dist/harness-table.d.ts +59 -3
  66. package/dist/harness-table.js +119 -14
  67. package/dist/harness.d.ts +17 -1
  68. package/dist/harness.js +22 -11
  69. package/dist/host.d.ts +12 -10
  70. package/dist/host.js +19 -16
  71. package/dist/import-worker.d.ts +3 -0
  72. package/dist/import-worker.js +7 -5
  73. package/dist/import.d.ts +22 -1
  74. package/dist/import.js +141 -28
  75. package/dist/key-check.js +3 -0
  76. package/dist/learn/audit.d.ts +6 -6
  77. package/dist/learn/audit.js +3 -7
  78. package/dist/learn/check.d.ts +26 -89
  79. package/dist/learn/check.js +58 -336
  80. package/dist/learn/commit.d.ts +63 -90
  81. package/dist/learn/commit.js +124 -316
  82. package/dist/learn/compile.d.ts +53 -50
  83. package/dist/learn/compile.js +88 -103
  84. package/dist/learn/corrections.d.ts +13 -0
  85. package/dist/learn/corrections.js +23 -0
  86. package/dist/learn/delete.d.ts +17 -0
  87. package/dist/learn/delete.js +42 -0
  88. package/dist/learn/folder.d.ts +35 -47
  89. package/dist/learn/folder.js +118 -134
  90. package/dist/learn/index.d.ts +3 -5
  91. package/dist/learn/index.js +6 -9
  92. package/dist/learn/learning.sh +45 -15
  93. package/dist/learn/promote.d.ts +20 -2
  94. package/dist/learn/promote.js +17 -4
  95. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +34 -38
  96. package/dist/learn/{skills.js → workflow-draft.js} +65 -59
  97. package/dist/learn/workflow-nodes.d.ts +22 -1
  98. package/dist/learn/workflow-nodes.js +29 -10
  99. package/dist/learned-workflow.js +2 -2
  100. package/dist/learning-cost.d.ts +127 -13
  101. package/dist/learning-cost.js +142 -10
  102. package/dist/learning-routes.d.ts +99 -170
  103. package/dist/learning-routes.js +199 -420
  104. package/dist/learning-run.d.ts +19 -40
  105. package/dist/learning-run.js +23 -93
  106. package/dist/learning-setting.d.ts +4 -4
  107. package/dist/learning-setting.js +6 -6
  108. package/dist/learning-words.d.ts +28 -74
  109. package/dist/learning-words.js +64 -162
  110. package/dist/learning.d.ts +62 -393
  111. package/dist/learning.js +101 -651
  112. package/dist/listen-first.d.ts +30 -0
  113. package/dist/listen-first.js +115 -0
  114. package/dist/live-reach.d.ts +25 -2
  115. package/dist/live-reach.js +46 -4
  116. package/dist/llms.txt +2 -1
  117. package/dist/local-models.d.ts +3 -11
  118. package/dist/local-models.js +5 -6
  119. package/dist/mcp-servers-store.d.ts +16 -16
  120. package/dist/model-form.js +6 -5
  121. package/dist/model.d.ts +12 -4
  122. package/dist/model.js +41 -16
  123. package/dist/native/binding.js +1 -1
  124. package/dist/native/connection.js +1 -1
  125. package/dist/native/discovery.js +1 -1
  126. package/dist/native/instructions.d.ts +3 -0
  127. package/dist/native/instructions.js +5 -3
  128. package/dist/native/remote-worker-bridge.js +9 -43
  129. package/dist/native/remote.d.ts +8 -15
  130. package/dist/native/remote.js +3 -3
  131. package/dist/native/schema.js +1 -1
  132. package/dist/native/types.d.ts +2 -2
  133. package/dist/openapi.js +375 -347
  134. package/dist/owner.d.ts +8 -0
  135. package/dist/owner.js +11 -0
  136. package/dist/paid-calls.d.ts +14 -0
  137. package/dist/paid-calls.js +31 -1
  138. package/dist/particle-provider.d.ts +11 -0
  139. package/dist/particle-provider.js +135 -0
  140. package/dist/place.d.ts +8 -3
  141. package/dist/place.js +13 -9
  142. package/dist/port-models.d.ts +12 -4
  143. package/dist/port-models.js +28 -11
  144. package/dist/print.d.ts +27 -0
  145. package/dist/print.js +21 -0
  146. package/dist/provider.d.ts +7 -0
  147. package/dist/provider.js +30 -2
  148. package/dist/reflect-range.js +2 -3
  149. package/dist/run-launch.d.ts +14 -28
  150. package/dist/run-launch.js +9 -12
  151. package/dist/run-learning-served.d.ts +16 -90
  152. package/dist/run-listing.d.ts +34 -0
  153. package/dist/run-listing.js +128 -0
  154. package/dist/run-model-key.d.ts +64 -0
  155. package/dist/run-model-key.js +147 -0
  156. package/dist/run-timeline-served.js +5 -3
  157. package/dist/run-trace.d.ts +97 -0
  158. package/dist/run-trace.js +253 -0
  159. package/dist/run-view.d.ts +15 -0
  160. package/dist/run-view.js +9 -0
  161. package/dist/runnable.js +2 -1
  162. package/dist/runner/adapter-loop.d.ts +14 -6
  163. package/dist/runner/adapter-loop.js +25 -14
  164. package/dist/runner/adapter-run-spec.d.ts +22 -7
  165. package/dist/runner/adapter-run-spec.js +130 -77
  166. package/dist/runner/adapters/index.d.ts +4 -2
  167. package/dist/runner/adapters/index.js +35 -4
  168. package/dist/runner/adapters/pi.d.ts +4 -12
  169. package/dist/runner/adapters/pi.js +2 -2
  170. package/dist/runner/audit.d.ts +5 -1
  171. package/dist/runner/audit.js +31 -12
  172. package/dist/runner/beside.d.ts +7 -2
  173. package/dist/runner/beside.js +41 -9
  174. package/dist/runner/claim-secrets.d.ts +66 -1
  175. package/dist/runner/claim-secrets.js +136 -3
  176. package/dist/runner/cli-run-spec.d.ts +2 -1
  177. package/dist/runner/cli-run-spec.js +82 -59
  178. package/dist/runner/commands.d.ts +3 -6
  179. package/dist/runner/conformance/harness.d.ts +6 -0
  180. package/dist/runner/conformance/harness.js +16 -5
  181. package/dist/runner/dispatch.d.ts +2 -2
  182. package/dist/runner/end-of-run.d.ts +6 -14
  183. package/dist/runner/end-of-run.js +8 -33
  184. package/dist/runner/feedback-round.d.ts +5 -4
  185. package/dist/runner/feedback-round.js +14 -10
  186. package/dist/runner/github-app.js +3 -1
  187. package/dist/runner/harness-loops.d.ts +0 -8
  188. package/dist/runner/harness-loops.js +30 -56
  189. package/dist/runner/held.d.ts +170 -0
  190. package/dist/runner/held.js +57 -0
  191. package/dist/runner/journal-kinds.d.ts +7 -3
  192. package/dist/runner/journal-kinds.js +2 -3
  193. package/dist/runner/learned-first.d.ts +40 -0
  194. package/dist/runner/learned-first.js +32 -0
  195. package/dist/runner/learning-end.d.ts +77 -66
  196. package/dist/runner/learning-end.js +250 -299
  197. package/dist/runner/learning-seed.d.ts +15 -33
  198. package/dist/runner/learning-seed.js +24 -45
  199. package/dist/runner/loop-contract.d.ts +8 -3
  200. package/dist/runner/loop-contract.js +4 -0
  201. package/dist/runner/loop.js +6 -2
  202. package/dist/runner/main.d.ts +18 -9
  203. package/dist/runner/main.js +82 -22
  204. package/dist/runner/mcp-run.d.ts +11 -0
  205. package/dist/runner/mcp-run.js +67 -0
  206. package/dist/runner/memory-claim.d.ts +14 -6
  207. package/dist/runner/memory-claim.js +18 -9
  208. package/dist/runner/model-route.d.ts +7 -4
  209. package/dist/runner/model-route.js +22 -10
  210. package/dist/runner/native-loop.d.ts +0 -7
  211. package/dist/runner/native-loop.js +9 -101
  212. package/dist/runner/promotion.d.ts +13 -6
  213. package/dist/runner/promotion.js +63 -17
  214. package/dist/runner/reflect-hook.d.ts +64 -91
  215. package/dist/runner/reflect-hook.js +112 -206
  216. package/dist/runner/run-channel.d.ts +43 -0
  217. package/dist/runner/run-channel.js +467 -0
  218. package/dist/runner/run-child-host.d.ts +169 -0
  219. package/dist/runner/run-child-host.js +1222 -0
  220. package/dist/runner/run-child.d.ts +1 -0
  221. package/dist/runner/run-child.js +254 -0
  222. package/dist/runner/run-errors.d.ts +2 -0
  223. package/dist/runner/run-errors.js +20 -0
  224. package/dist/runner/runner.js +58 -9
  225. package/dist/runner/sdk-ask.d.ts +78 -0
  226. package/dist/runner/sdk-ask.js +158 -0
  227. package/dist/runner/sdk-loop.d.ts +2 -4
  228. package/dist/runner/sdk-loop.js +29 -49
  229. package/dist/runner/store-secrets.d.ts +5 -3
  230. package/dist/runner/store-secrets.js +14 -6
  231. package/dist/runner/workflow-first.d.ts +5 -0
  232. package/dist/runner/workflow-first.js +4 -0
  233. package/dist/runner/workflow-spec.js +17 -4
  234. package/dist/runs-over-store.d.ts +21 -32
  235. package/dist/runs-over-store.js +44 -41
  236. package/dist/sdk/runs.d.ts +6 -11
  237. package/dist/sdk/runs.js +20 -41
  238. package/dist/sdk/schema.js +3 -4
  239. package/dist/sdk/workflows.d.ts +1 -1
  240. package/dist/seal-key.d.ts +5 -0
  241. package/dist/seal-key.js +7 -0
  242. package/dist/secrets.d.ts +3 -0
  243. package/dist/secrets.js +16 -3
  244. package/dist/server.d.ts +119 -83
  245. package/dist/server.js +1121 -419
  246. package/dist/sign-ins-store.d.ts +8 -0
  247. package/dist/sign-ins-store.js +36 -1
  248. package/dist/skills.js +1 -1
  249. package/dist/store/index.d.ts +3 -3
  250. package/dist/store/index.js +2 -2
  251. package/dist/store/journal/storage.js +3 -0
  252. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  253. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  254. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  255. package/dist/store/schema.d.ts +53 -4
  256. package/dist/store/schema.js +137 -6
  257. package/dist/store/seal.d.ts +20 -2
  258. package/dist/store/seal.js +24 -8
  259. package/dist/store/sqlite/connection.d.ts +2 -0
  260. package/dist/store/sqlite/connection.js +3 -1
  261. package/dist/store/sqlite/run-launch.d.ts +4 -1
  262. package/dist/store/sqlite/run-launch.js +12 -0
  263. package/dist/store/sqlite/run-patch.d.ts +0 -17
  264. package/dist/store/sqlite/run-patch.js +4 -33
  265. package/dist/store/sqlite/store.d.ts +3 -2
  266. package/dist/store/sqlite/store.js +360 -75
  267. package/dist/store/sqlite/worker.js +25 -0
  268. package/dist/store/store.d.ts +231 -39
  269. package/dist/store/store.js +25 -3
  270. package/dist/store-reads/analytics.js +11 -1
  271. package/dist/store-reads/learning.d.ts +131 -194
  272. package/dist/store-reads/learning.js +292 -301
  273. package/dist/store-reads/loop.d.ts +0 -1
  274. package/dist/store-reads/loop.js +1 -1
  275. package/dist/store-reads/stats.js +13 -3
  276. package/dist/store-view.d.ts +34 -2
  277. package/dist/store-view.js +108 -41
  278. package/dist/telemetry.d.ts +59 -0
  279. package/dist/telemetry.js +153 -0
  280. package/dist/template-eval.d.ts +3 -6
  281. package/dist/template-eval.js +22 -36
  282. package/dist/templates.d.ts +2 -1
  283. package/dist/templates.js +6 -3
  284. package/dist/timeline/index.d.ts +1 -1
  285. package/dist/timeline/index.js +1 -1
  286. package/dist/timeline/timeline.d.ts +5 -1
  287. package/dist/timeline/timeline.js +16 -0
  288. package/dist/tool-gate.d.ts +0 -7
  289. package/dist/tool-gate.js +1 -15
  290. package/dist/tool-keys-store.d.ts +1 -1
  291. package/dist/tool-keys.d.ts +6 -4
  292. package/dist/tool-keys.js +12 -6
  293. package/dist/tool-plane.d.ts +12 -12
  294. package/dist/tools.d.ts +13 -13
  295. package/dist/tools.js +29 -9
  296. package/dist/trigger-adapter.d.ts +3 -0
  297. package/dist/trigger-adapters.d.ts +4 -0
  298. package/dist/trigger-adapters.js +13 -0
  299. package/dist/trigger-composio.d.ts +58 -1
  300. package/dist/trigger-composio.js +160 -6
  301. package/dist/triggers.d.ts +64 -5
  302. package/dist/triggers.js +141 -17
  303. package/dist/validate.d.ts +11 -7
  304. package/dist/validate.js +9 -8
  305. package/dist/webhooks.d.ts +4 -1
  306. package/dist/webhooks.js +11 -4
  307. package/dist/workspace/agent-computer.d.ts +2 -0
  308. package/dist/workspace/agent-computer.js +2 -0
  309. package/dist/workspace/archil-claim.d.ts +7 -0
  310. package/dist/workspace/archil-claim.js +29 -0
  311. package/dist/workspace/archil.d.ts +9 -1
  312. package/dist/workspace/archil.js +165 -3
  313. package/dist/workspace/attach.d.ts +3 -1
  314. package/dist/workspace/attach.js +2 -0
  315. package/dist/workspace/attached-computers.d.ts +16 -5
  316. package/dist/workspace/attached-computers.js +25 -9
  317. package/dist/workspace/computer-deps.js +1 -1
  318. package/dist/workspace/computer-for-claim.d.ts +22 -8
  319. package/dist/workspace/computer-for-claim.js +339 -46
  320. package/dist/workspace/computer-hold.js +2 -1
  321. package/dist/workspace/computer-kept.d.ts +11 -1
  322. package/dist/workspace/computer-kept.js +24 -3
  323. package/dist/workspace/resolve-computer.d.ts +41 -21
  324. package/dist/workspace/resolve-computer.js +172 -64
  325. package/dist/workspace/revision-skills.d.ts +1 -2
  326. package/dist/workspace/revision-skills.js +3 -4
  327. package/dist/workspace/run-workspace.d.ts +1 -1
  328. package/dist/workspace/run-workspace.js +5 -0
  329. package/dist/workspace/synced-folder.d.ts +85 -0
  330. package/dist/workspace/synced-folder.js +230 -0
  331. package/dist/workspace/workspace.d.ts +4 -0
  332. package/launcher/agentrun-serve +1 -1
  333. package/package.json +10 -9
  334. package/templates/README.md +7 -7
  335. package/templates/inbound-lead/agent.md +3 -3
  336. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  337. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  338. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  339. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  340. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  341. package/templates/inbound-lead/lead.schema.json +6 -5
  342. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  343. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  344. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  345. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  346. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  347. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  348. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  349. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  350. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  351. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  352. package/dist/console/assets/index-BrcDSBD8.css +0 -1
  353. package/dist/console/assets/index-Bz6IWncl.js +0 -711
  354. package/dist/learn/grade.d.ts +0 -138
  355. package/dist/learn/grade.js +0 -682
  356. package/dist/learn/notes.d.ts +0 -81
  357. package/dist/learn/notes.js +0 -178
  358. package/dist/learn/reflect.d.ts +0 -77
  359. package/dist/learn/reflect.js +0 -228
  360. package/dist/learn/relevance.d.ts +0 -24
  361. package/dist/learn/relevance.js +0 -91
  362. package/dist/learn/seed-check.d.ts +0 -74
  363. package/dist/learn/seed-check.js +0 -103
  364. package/dist/learning-batch.d.ts +0 -291
  365. package/dist/learning-batch.js +0 -600
  366. package/dist/learning-evals.d.ts +0 -33
  367. package/dist/learning-evals.js +0 -98
  368. package/dist/native/context.d.ts +0 -6
  369. package/dist/native/context.js +0 -22
  370. package/dist/propose.d.ts +0 -52
  371. package/dist/propose.js +0 -224
  372. package/dist/runner/learning-ask.d.ts +0 -47
  373. package/dist/runner/learning-ask.js +0 -128
  374. package/dist/runner/learning-dispatch.d.ts +0 -45
  375. package/dist/runner/learning-dispatch.js +0 -99
  376. package/dist/runner/learning-factory.d.ts +0 -16
  377. package/dist/runner/learning-factory.js +0 -50
  378. package/dist/runner/learning-loop.d.ts +0 -273
  379. package/dist/runner/learning-loop.js +0 -521
  380. package/dist/usage.d.ts +0 -11
  381. package/dist/usage.js +0 -11
  382. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  383. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  384. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  385. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  386. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  387. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  388. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -1,49 +1,23 @@
1
- // The checker of what a run proposes for its agent's learning folder (SPEC.md): its notes, a skill and workflow drafts,
2
- // each a change against the commit the run started from. Structure only, never whether a note is any good,
3
- // which is the grader's. The host reads the copy itself (regular files only, never a link followed) and hands each change
4
- // here with its bytes; nothing the checker refuses is ever written to git. Every problem it reports is printable: its
5
- // path and detail are cut of the host's secrets and of text shaped like one, and a field over PRINT_MAX is redacted whole.
1
+ // The checker of a workflow draft a run's compile turn gives its agent's learning folder (SPEC.md): its workflow.json and
2
+ // README.md, each a change against what the folder holds. Structure only, and what must never be stored; nothing the
3
+ // checker refuses is ever written to git. Every problem it reports is printable: its path and detail are cut of the
4
+ // host's secrets and of text shaped like one, and a field over PRINT_MAX is redacted whole.
6
5
  import { placeholdersOf, placeholderValue } from "@parcha/agentrun-dsl";
7
6
  import { hiddenCharacter } from "./invisible.js";
8
- import { compiledLineBytes, INDEX_FILE, INDEX_LINES, NOTE_FILE, parseNoteFile, ruleOf } from "./notes.js";
9
7
  import { learnedSecretShapes, redactLearned, valueMatcher } from "./secrets.js";
10
- import { childNodes, draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, learnedName, learnedPlace, setsStatus, skillProblems, WORKFLOWS_DIR } from "./skills.js";
11
- /** The most the host adds to a run's note as it merges it: `origin: you` and `status: pending`, a front matter line
12
- * each (notes.ts mergedNote). */
13
- const HOST_LINES = Buffer.byteLength("origin: you\nstatus: pending\n");
14
- /** A note's bytes as the note cap counts them: all of `text` but the `compiled_into` line the host adds when a learned
15
- * workflow is compiled from it (notes.ts compiledLineBytes). A note at the cap stays one once marked: it retires,
16
- * restores, and a later note supersedes it through the grader, each checked against `note`. A run never sets the line
17
- * (checkProposal refuses it), so a run's note is counted whole. */
18
- export const noteBytes = (text) => Buffer.byteLength(text) - compiledLineBytes(text);
19
- /** Byte caps (UTF-8) and counts. Over a cap is refused, never cut. */
8
+ import { childNodes, draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, learnedPlace, readmeProblems, WORKFLOW_NAME, WORKFLOWS_DIR } from "./workflow-draft.js";
9
+ /** Byte caps (UTF-8). Over a cap is refused, never cut. */
20
10
  export const CAPS = Object.freeze({
21
- /** One note's file, as noteBytes counts it: the host's `compiled_into` line on top. */
22
- note: 4096,
23
- /** One note a run proposes: the note cap less HOST_LINES, so a run's note stays within `note` once the host merges
24
- * it, and a person can still retire it and a later run supersede it, each read and checked against `note`. */
25
- runNote: 4096 - HOST_LINES,
26
- /** New notes in one run. */
27
- newNotes: 8,
28
- /** Notes one run's new notes supersede, together. */
29
- supersedes: 8,
30
- /** Changed paths in one run; over it nothing else is read. */
31
- changes: 64,
32
- /** One skill's SKILL.md, or one workflow draft's workflow.json: one grader reads each whole beside the notes, so the
33
- * most a run proposes stays within its prompt (grade.ts GRADE_CAPS.prompt). */
11
+ /** One draft's workflow.json. */
34
12
  file: 16_384,
35
13
  /** One draft's README.md, which the host writes from the one-line description its block gives. */
36
14
  readme: 1_024,
37
- /** Skills one run adds or changes. */
38
- skills: 1,
39
- /** Workflow drafts one run adds or changes. */
40
- workflows: 1,
41
15
  });
42
16
  const MODES = { "120000": "a link: never followed", "040000": "a folder: nothing in it was read" };
43
- /** Why a draft from a run of a revision that learns notes alone (`learning: "notes"`) is left out. */
44
- const NOTES_ONLY = "this agent learns notes and skills alone (learning: \"notes\"): it keeps no workflow draft";
45
- /** Why a run's path is none of what it may propose. */
46
- const OUTSIDE = "a run proposes notes at the folder's top, skills/<name>/SKILL.md, and workflows/<name>/ with its workflow.json and README.md";
17
+ /** Why a path is none of what a draft may write. */
18
+ const OUTSIDE = "a draft writes workflows/<name>/ with its workflow.json and README.md";
19
+ /** Why a workflow.json checked with no workflow DSL is refused. */
20
+ const NO_DSL = "no workflow DSL to read it with: it was not checked";
47
21
  /** `problem` as it may be printed: its path and detail cut of `values` and of every shape learning refuses, a bank's
48
22
  * numbers too (redactLearned: a name refused for one never prints it), whole when over PRINT_MAX. */
49
23
  export const printable = (problem, values) => ({
@@ -60,33 +34,6 @@ function nameScanned(path, refused, add) {
60
34
  if (refused(path))
61
35
  add("secret_value", "its name holds a value the host named as secret", path);
62
36
  }
63
- /** A note's file name, whoever writes it: nameScanned, and a note's own (a `.md` file at the folder's top). False when
64
- * it is not a note's name, and nothing else is read. */
65
- function nameChecked(path, refused, add, outside = "only a .md file at the folder's top is a note") {
66
- nameScanned(path, refused, add);
67
- if (path.includes("/") || !path.endsWith(".md"))
68
- return add("outside", outside, path), false;
69
- if (!NOTE_FILE.test(path))
70
- return add("file_name", "a note's name is letters, digits, dots, dashes and underscores, starting with a letter or digit, and ends .md", path), false;
71
- return true;
72
- }
73
- /** A note's text by itself, whoever writes it: within the cap, UTF-8, no hidden character, no secret's shape or the host's
74
- * values, its front matter in shape. The note when it is. */
75
- function textChecked(path, size, bytes, refused, add, run = false) {
76
- const cap = run ? CAPS.runNote : CAPS.note;
77
- // A person's note (or one main holds) is counted without the host's compiled_into line; a run's whole (it may not set it).
78
- if (!run && bytes)
79
- size -= compiledLineBytes(Buffer.from(bytes).toString("utf8"));
80
- if (size > cap)
81
- return void add("too_large", `${size} bytes; the cap is ${cap}${run ? " for a run's note" : ""}`, path);
82
- const text = textOf(path, bytes, refused, add);
83
- if (text === undefined)
84
- return undefined;
85
- const note = parseNoteFile(path, text);
86
- if (Array.isArray(note))
87
- return void note.forEach((reason) => add("note", reason, path));
88
- return { ...note, text };
89
- }
90
37
  /** A file's text, whatever it holds: UTF-8, no hidden character, no secret's shape or the host's values. Undefined,
91
38
  * with why, when it is not. */
92
39
  function textOf(path, bytes, refused, add) {
@@ -109,9 +56,9 @@ function textOf(path, bytes, refused, add) {
109
56
  found = (add("secret_value", "it holds a value the host named as secret", path), true);
110
57
  return found ? undefined : text;
111
58
  }
112
- /** A learned file at `path` as it is read later, its escapes decoded: a skill's SKILL.md or a draft's README.md, its front
113
- * matter read as YAML reads it (skills.ts frontValues, the value a harness is served); a draft's workflow.json, every
114
- * string it decodes to, keys too, as JSON.parse reads it (skills.ts decodedStrings, what draftProblems and a learned
59
+ /** A learned file at `path` as it is read later, its escapes decoded: a draft's README.md, its front matter read as YAML
60
+ * reads it (workflow-draft.ts frontValues, the value a harness is served); a draft's workflow.json, every string it
61
+ * decodes to, keys too, as JSON.parse reads it (workflow-draft.ts decodedStrings, what draftProblems and a learned
115
62
  * call's run read). A hidden character, a secret's shape or the host's value there is refused as one in its text is,
116
63
  * though the text as stored spells it in escapes. True when it found one. */
117
64
  function decodedScanned(path, text, refused, add, deep = true) {
@@ -139,7 +86,7 @@ function decodedScanned(path, text, refused, add, deep = true) {
139
86
  }
140
87
  /** The model node kinds a tier routes (model.ts MODEL_NODES); a decision node (judge, pick, sift) goes to its decision
141
88
  * provider, never a tier. */
142
- const TIERED_KINDS = new Set(["agent", "decide", "extract", "report"]);
89
+ export const TIERED_KINDS = new Set(["agent", "decide", "extract", "report"]);
143
90
  const isNode = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.node === "string";
144
91
  /** The state key a step writes (the DSL's writeKeyOf): a report's `report_markdown`, else its `as`, else an agent's,
145
92
  * decide's or extract's label. */
@@ -686,38 +633,34 @@ function quoteRule(workflow, schemasAround, depth = 0) {
686
633
  return { applies: true, checked: [], problems: child.problems.map((problem) => `the composed workflow step ${JSON.stringify(String(writer.label ?? "(no label)").slice(0, 64))} writes the answer: ${problem}`) };
687
634
  return problems.length ? { applies: true, problems, checked: [] } : passed;
688
635
  }
689
- /** What a run may write of a skill or a workflow draft (`place`), by itself: a good folder name, never a deletion, a
690
- * regular file within CAPS.file (a README within CAPS.readme), its text as textOf takes it, and in shape: a skill's
691
- * front matter (skillProblems), with no `status`, which is the host's; a draft the DSL validates against `tools` with
692
- * no node that runs code (draftProblems), whose answering step runs on the agent's model (answerTierProblems), whose
693
- * steps there read no page (compactStateProblems), whose quotes of the pages it fetched are checked in code
694
- * (quoteCheckProblems); a README that names its folder and says what
695
- * the draft is for. */
636
+ /** What a draft may write of a workflow (`place`), by itself: a good folder name, never a deletion, a regular file
637
+ * within CAPS.file (a README within CAPS.readme), its text as textOf takes it, and in shape: a draft the DSL validates
638
+ * against `tools` with no node that runs code (draftProblems), whose answering step runs on the agent's model
639
+ * (answerTierProblems), whose steps there read no page (compactStateProblems), whose quotes of the pages it fetched are
640
+ * checked in code (quoteCheckProblems); a README that names its folder and says what the draft is for. */
696
641
  function learnedChecked(change, place, refused, input, add) {
697
642
  const { path } = change;
698
643
  nameScanned(path, refused, add);
699
- if (!learnedName(place.kind, place.name))
700
- return add("file_name", place.kind === "skill" ? "a skill's name is lowercase letters, digits and single dashes, at most 64" : "a workflow's name is lowercase letters, digits, dashes and underscores, at most 64, starting with a letter or digit", path);
644
+ if (!WORKFLOW_NAME.test(place.name))
645
+ return add("file_name", "a workflow's name is lowercase letters, digits, dashes and underscores, at most 64, starting with a letter or digit", path);
701
646
  if (change.status === "deleted")
702
- return add("deleted", "a run never deletes a skill or a workflow", path);
703
- if (place.kind === "workflow" && input.workflows === false)
704
- return add("workflow", NOTES_ONLY, path);
647
+ return add("deleted", "a run never deletes a workflow", path);
705
648
  if (change.mode !== undefined && change.mode !== "100644")
706
649
  return add("file_mode", MODES[change.mode] ?? "not a regular file: never read", path);
707
650
  const size = change.size ?? change.bytes?.length ?? 0;
708
651
  const cap = place.kind === "readme" ? CAPS.readme : CAPS.file;
709
652
  if (size > cap)
710
653
  return add("too_large", `${size} bytes; the cap is ${cap}`, path);
711
- // A person's call stands: a skill or a draft whose seed text has a status (retired, or waiting for its owner's OK).
654
+ // A person's call stands: a draft whose text on main has a status (retired, or waiting for its owner's OK).
712
655
  const readmeOf = `${path.slice(0, path.lastIndexOf("/"))}/README.md`;
713
656
  if (input.kept?.includes(path) || (place.kind === "workflow" && input.kept?.includes(readmeOf)))
714
- return add("skill_status", "a person retired it, or it waits for its owner's OK: a run never changes it", path);
657
+ return add("kept", "a person retired it, or it waits for its owner's OK: a run never changes it", path);
715
658
  const text = textOf(path, change.bytes, refused, add);
716
659
  if (text === undefined || decodedScanned(path, text, refused, add))
717
660
  return;
718
661
  if (place.kind === "workflow") {
719
662
  if (!input.dsl)
720
- throw new TypeError(`${path}: a workflow draft is read with the workflow DSL, which was not given`);
663
+ return add("workflow", NO_DSL, path);
721
664
  const problems = draftProblems(input.dsl, text, input.tools, input.gated, input.deniedBy, input.decisions, input.workflowAdapters);
722
665
  // A draft the DSL reads parses: its answering step is held to the agent's model, its steps there to compact state
723
666
  // (the SDK bridge's runNode picks every model itself: it names no tier), and its quote check to code.
@@ -734,41 +677,23 @@ function learnedChecked(change, place, refused, input, add) {
734
677
  add("workflow", dry.detail ?? DRY_RUN_FAILED, path);
735
678
  return;
736
679
  }
737
- for (const reason of skillProblems(text, place.name))
738
- add(place.kind === "skill" ? "skill" : "workflow", reason, path);
739
- // Its front matter says what it is and nothing more: Claude Code reads directives (a hook is a shell command) from any
740
- // other key. `status` has its own rule.
680
+ for (const reason of readmeProblems(text, place.name))
681
+ add("workflow", reason, path);
682
+ // Its front matter says what it is and nothing more: a reader takes directives from any other key. `status` is the
683
+ // host's (`kept`).
741
684
  const extra = (frontKeys(text) ?? []).filter((key) => !LEARNED_KEYS.includes(key) && key !== "status");
742
685
  if (extra.length)
743
- add("skill_front_matter", `its front matter sets ${extra.join(", ")}: a learned ${place.kind === "skill" ? "skill" : "workflow"} sets name and description alone`, path);
744
- if (place.kind === "skill" && setsStatus(text))
745
- add("status", "a run never sets a skill's status: the host does, when it holds one for its owner's OK", path);
746
- }
747
- /** The checks one note's file passes by itself (SPEC.md), as a person writes it through the host: its name, the note cap,
748
- * UTF-8, hidden characters, secret shapes and the host's values in its name and text, and its front matter. A person
749
- * may set `status` and `superseded_by`; what a run may not do (edit, delete, set status) is checkProposal's. Every
750
- * problem is printable. */
751
- export function checkNote(path, bytes, refuseValues = []) {
752
- const problems = [];
753
- const add = (rule, detail, at) => void problems.push(printable(at === undefined ? { rule, detail } : { rule, path: at, detail }, refuseValues));
754
- const refused = valueMatcher(refuseValues);
755
- const note = nameChecked(path, refused, add) ? textChecked(path, bytes.length, bytes, refused, add) : undefined;
756
- return problems.length || !note ? { problems } : { problems, note };
686
+ add("front_matter", `its front matter sets ${extra.join(", ")}: a learned workflow sets name and description alone`, path);
757
687
  }
758
- /** Checks what a run proposes against SPEC.md: its notes, and a skill or workflow drafts beside them (learnedChecked).
759
- * `MEMORY.md` is the host's: a change to it is ignored, never refused. */
760
688
  /** What must never be stored, in every change's name and text, whatever the checks would refuse it for first: the
761
- * name and text scans (nameScanned, textOf) of each change, its text read whole (an edit, a file over its cap, one not
762
- * a regular file included), printable as checkProposal's are. A text that is not UTF-8 is `encoding`: unread, so
763
- * never trusted. Empty when nothing in them must be refused. Ahead of keeping some items of a proposal the checks
764
- * refuse (propose.ts): an item refused before its text was read hides nothing. */
689
+ * name and text scans (nameScanned, textOf) of each change, its text read whole (a file over its cap, one not a regular
690
+ * file included), printable as checkDraft's are. A text that is not UTF-8 is `encoding`: unread, so never trusted.
691
+ * Empty when nothing in them must be refused. */
765
692
  export function unstorable(changes, refuseValues = []) {
766
693
  const problems = [];
767
694
  const add = (rule, detail, path) => void problems.push(printable(path === undefined ? { rule, detail } : { rule, path, detail }, refuseValues));
768
695
  const refused = valueMatcher(refuseValues);
769
696
  for (const change of changes) {
770
- if (change.path === INDEX_FILE)
771
- continue;
772
697
  nameScanned(change.path, refused, add);
773
698
  const text = change.bytes ? textOf(change.path, change.bytes, refused, add) : undefined;
774
699
  if (text !== undefined)
@@ -776,242 +701,39 @@ export function unstorable(changes, refuseValues = []) {
776
701
  }
777
702
  return problems;
778
703
  }
779
- export function checkProposal(input) {
704
+ /** Checks one workflow draft (its workflow.json and README.md, given together by draftFiles) against SPEC.md: each file
705
+ * under workflows/<name>/ (learnedChecked), nothing else, and the two together (a workflow whose files are otherwise in
706
+ * shape with one of them missing names it: restore reads the README). Never throws: a draft it could not read (no
707
+ * workflow DSL, a check that threw) is a problem in words. Every problem printable; none when it passes. */
708
+ export function checkDraft(input) {
780
709
  const values = input.refuseValues ?? [];
781
710
  const problems = [];
782
711
  const add = (rule, detail, path) => void problems.push(printable(path === undefined ? { rule, detail } : { rule, path, detail }, values));
783
- const given = input.changes.filter((change) => change.path !== INDEX_FILE);
784
712
  const refused = valueMatcher(values);
785
- // Each count cap names the items past it, in the order the answer gave them, so they alone are left out (propose.ts)
786
- // and the rest is kept. The changed paths past CAPS.changes are named unread; but what refuses the whole answer by its
787
- // path alone (a path outside what a run may write, a deletion, a name holding a secret) is read on every path first,
788
- // past the cap too, so the cap never turns a whole refusal into one item left out.
789
- for (const change of given.slice(CAPS.changes)) {
790
- nameScanned(change.path, refused, add);
791
- if (!learnedPlace(change.path) && (change.path.includes("/") || !change.path.endsWith(".md")))
713
+ /** Each workflow's files given, by its name. */
714
+ const given = new Map();
715
+ for (const change of input.changes) {
716
+ const place = learnedPlace(change.path);
717
+ if (!place) {
718
+ nameScanned(change.path, refused, add);
792
719
  add("outside", OUTSIDE, change.path);
793
- else if (change.status === "deleted")
794
- add("deleted", "a run never deletes a note, a skill or a workflow", change.path);
795
- add("too_many_files", `${given.length} changed paths; the cap is ${CAPS.changes} a run, and this one, past it, was not read`, change.path);
796
- }
797
- const changes = given.slice(0, CAPS.changes);
798
- const base = new Set(input.base.files);
799
- // The new notes that pass their own checks, in the answer's order. Which of them is a duplicate is settled after,
800
- // with the merge's checks (settled below).
801
- const candidates = [];
802
- const skills = [];
803
- const workflows = new Set();
804
- const added = [];
805
- const one = (change) => {
806
- const { path } = change;
807
- const place = learnedPlace(path);
808
- if (place) {
809
- // What the run writes, under a good name, is counted: a skill against the run's, a draft's file against its pair.
810
- if (change.status !== "deleted" && learnedName(place.kind, place.name)) {
811
- if (place.kind === "skill")
812
- skills.push(path);
813
- else
814
- workflows.add(place.name);
815
- }
816
- return learnedChecked(change, place, refused, input, add);
817
- }
818
- if (change.status === "added")
819
- added.push(path);
820
- if (!nameChecked(path, refused, add, OUTSIDE))
821
- return;
822
- if (change.status === "deleted")
823
- return add("deleted", "a run never deletes a note", path);
824
- if (change.mode !== undefined && change.mode !== "100644")
825
- return add("file_mode", MODES[change.mode] ?? "not a regular file: never read", path);
826
- if (change.status === "modified")
827
- return add("edited", "a run never edits a note: to replace one, it adds a new note that supersedes it", path);
828
- if (base.has(path))
829
- return add("exists", "the folder has a note by this name", path);
830
- const note = textChecked(path, change.size ?? change.bytes?.length ?? 0, change.bytes, refused, add, true);
831
- if (!note)
832
- return;
833
- if (["status", "superseded_by", "retired_from", "origin", "compiled_into"].some((key) => note.keys.includes(key)))
834
- return add("status", "a run never sets status, superseded_by, retired_from, origin or compiled_into: the host does, when it merges the note, a later one supersedes it, a learned workflow is compiled from it or a person retires it", path);
835
- candidates.push(note);
836
- };
837
- for (const change of changes)
838
- one(change);
839
- for (const path of added.slice(CAPS.newNotes))
840
- add("too_many_notes", `${added.length} new notes; the cap is ${CAPS.newNotes} a run, and this one is past it`, path);
841
- for (const path of skills.slice(CAPS.skills))
842
- add("too_many_skills", `${skills.length} skills added or changed; a run adds or changes at most ${CAPS.skills}, and this one is past it`, path);
843
- for (const name of [...workflows].slice(CAPS.workflows))
844
- add("too_many_workflows", `${workflows.size} workflow drafts added or changed; a run adds or changes at most ${CAPS.workflows}, and this one is past it`, `${WORKFLOWS_DIR}/${name}/workflow.json`);
845
- // A skill is what every later run reads as how to do the job: only a run that did it writes one.
846
- if (input.outcome !== "completed")
847
- for (const path of skills)
848
- add("skill_outcome", `the run's outcome is ${input.outcome ?? "not known"}: only a completed run adds or changes a skill`, path);
849
- // A draft is its workflow.json and its README.md, together, as the folder will hold them.
850
- const gone = new Set(changes.filter((change) => change.status === "deleted").map((change) => change.path));
851
- const after = new Set([...base, ...changes.filter((change) => change.status !== "deleted").map((change) => change.path)].filter((path) => !gone.has(path)));
852
- for (const name of workflows) {
853
- const [json, readme] = ["workflow.json", "README.md"].map((file) => `${WORKFLOWS_DIR}/${name}/${file}`);
854
- if (after.has(json) !== after.has(readme))
855
- add("workflow", `the folder holds ${after.has(json) ? "workflow.json" : "README.md"} without the other file`, after.has(json) ? readme : json);
856
- }
857
- const notes = problems.length ? [] : settled(candidates);
858
- return { ok: problems.length === 0, problems, notes: problems.length ? [] : notes };
859
- /** `candidates` once nothing else is wrong, settled in one order, so no note is ever lost to another's failure:
860
- * 1. Each note alone against the base (ownProblems): what it supersedes, active there, and how many. One that fails
861
- * is left out with its own reason.
862
- * 2. The survivors by rule: the first of a rule holds it, the rest are its alternates. A rule the seed's active
863
- * notes hold is held already (an alternate that supersedes its holder is an update, and holds it).
864
- * 3. The holders' shared checks (sharedProblems): two notes superseding one note, the supersedes cap over the run,
865
- * the index's lines, each counted in order, after the duplicates are out. A holder they refuse is left out with
866
- * that reason, and its next alternate holds the rule in its place; then 3 again, until nothing changes (each
867
- * round leaves one note out or more: bounded by the count).
868
- * 4. Only then the alternates no rule needed are left out, each as the duplicate of its rule's holder.
869
- * The notes that pass, in the answer's order. */
870
- function settled(all) {
871
- const survivors = all.filter((note) => {
872
- const own = ownProblems(input.base, note);
873
- for (const problem of own)
874
- add(problem.rule, problem.detail, problem.path);
875
- return own.length === 0;
876
- });
877
- const out = new Set();
878
- for (;;) {
879
- const { holders } = byRule(survivors.filter((note) => !out.has(note.file)));
880
- const shared = sharedProblems(input.base, holders);
881
- if (!shared.length) {
882
- const { holders: kept, alternates } = byRule(survivors.filter((note) => !out.has(note.file)));
883
- for (const [note, holder] of alternates)
884
- add("duplicate", `it says what ${holder} says`, note.file);
885
- return kept;
886
- }
887
- for (const problem of shared) {
888
- add(problem.rule, problem.detail, problem.path);
889
- out.add(problem.path);
890
- }
891
- }
892
- }
893
- /** `notes` by rule, in order: the first of a rule holds it, the rest are its alternates (each with its holder). A
894
- * rule the seed's active notes hold is held by that note, unless the new note supersedes it (an update), or any of
895
- * `notes` does: a note this proposal supersedes keeps no rule after it, so a copy of its rule under another name is
896
- * no duplicate, and the rule is never left with no active note. */
897
- function byRule(notes) {
898
- const going = new Set(notes.flatMap((note) => note.supersedes));
899
- const rules = new Map([...(input.base.rules ?? [])].filter(([, holder]) => !going.has(holder)));
900
- const holders = [];
901
- const alternates = [];
902
- for (const note of notes) {
903
- const rule = ruleOf(note.body);
904
- const holder = rules.get(rule);
905
- if (holder !== undefined && !note.supersedes.includes(holder)) {
906
- // An update of the holder the seed has, after a copy of its rule: the update holds the rule, the copy is its
907
- // alternate (else the update is dropped as the copy's duplicate, and the copy as the seed's, on the next pass).
908
- const original = input.base.rules?.get(rule);
909
- const at = holders.findIndex((one) => one.file === holder);
910
- if (original !== undefined && holder !== original && at >= 0 && note.supersedes.includes(original)) {
911
- // At its own place in the answer (the end of the holders so far), not the copy's: the shared checks name notes
912
- // in answer order, so an update must not jump ahead of a note between the two.
913
- alternates.push([holders.splice(at, 1)[0], note.file]);
914
- holders.push(note);
915
- rules.set(rule, note.file);
916
- continue;
917
- }
918
- alternates.push([note, holder]);
919
- continue;
920
- }
921
- rules.set(rule, note.file);
922
- holders.push(note);
923
- }
924
- return { holders, alternates };
925
- }
926
- }
927
- /** What `note` alone cannot join `base` with, needing no other note: a `supersedes` that names no active note of `base`,
928
- * or more of them than CAPS.supersedes. */
929
- function ownProblems(base, note) {
930
- const active = new Set(base.active.map((one) => one.file));
931
- const out = note.supersedes.filter((old) => !active.has(old)).map((old) => ({ rule: "supersedes", path: note.file, detail: `it supersedes ${old}, which is not an active note` }));
932
- if (note.supersedes.length > CAPS.supersedes)
933
- out.push({ rule: "supersedes", path: note.file, detail: `it supersedes ${note.supersedes.length} notes; the cap is ${CAPS.supersedes} a run` });
934
- return out;
935
- }
936
- /** What stops the holders `notes` (one a rule, each passing ownProblems) from joining `base` together, each named by the
937
- * note it falls on. In the answer's order: a note that supersedes one an earlier note supersedes, or that takes the
938
- * notes superseded past CAPS.supersedes (a note named counts toward neither, so a later one that fits is kept). Then
939
- * the index over the rest, whole (each active new note a line, each note it supersedes one fewer), so a note that frees
940
- * lines counts wherever it stands: past INDEX_LINES, the notes that add lines are named from the answer's end until
941
- * it fits. */
942
- function sharedProblems(base, notes) {
943
- const out = [];
944
- const replaced = new Set();
945
- const fits = [];
946
- for (const note of notes) {
947
- const twice = note.supersedes.find((old) => replaced.has(old));
948
- if (twice) {
949
- out.push({ rule: "supersedes", path: note.file, detail: `${twice} is superseded by another new note too` });
950
720
  continue;
951
721
  }
952
- const would = new Set([...replaced, ...note.supersedes]);
953
- if (would.size > CAPS.supersedes) {
954
- out.push({ rule: "supersedes", path: note.file, detail: `with it the new notes supersede ${would.size} notes; the cap is ${CAPS.supersedes} a run` });
955
- continue;
722
+ if (change.status !== "deleted")
723
+ given.set(place.name, (given.get(place.name) ?? new Set()).add(place.kind));
724
+ try {
725
+ learnedChecked(change, place, refused, input, add);
726
+ }
727
+ catch (error) {
728
+ add("workflow", `it could not be checked: ${String(error?.message ?? error).slice(0, 200)}`, change.path);
956
729
  }
957
- for (const old of note.supersedes)
958
- replaced.add(old);
959
- fits.push(note);
960
730
  }
961
- const net = (note) => (note.status === "active" ? 1 : 0) - note.supersedes.length;
962
- let lines = base.active.length + fits.reduce((sum, note) => sum + net(note), 0);
963
- for (const note of [...fits].reverse()) {
964
- if (lines <= INDEX_LINES)
965
- break;
966
- if (net(note) <= 0)
731
+ for (const [name, kinds] of given) {
732
+ const dir = `${WORKFLOWS_DIR}/${name}/`;
733
+ if (kinds.size === 2 || problems.some((problem) => problem.path?.startsWith(dir)))
967
734
  continue;
968
- out.push({ rule: "index_full", path: note.file, detail: `with it the index would hold ${lines} lines; it holds at most ${INDEX_LINES}, so supersede a note rather than add one` });
969
- lines -= net(note);
735
+ const missing = kinds.has("workflow") ? "README.md" : "workflow.json";
736
+ add("workflow", `${OUTSIDE}: its ${missing} is missing`, `${dir}${missing}`);
970
737
  }
971
- return out;
972
- }
973
- /** The notes the active ones of `notes` supersede, each by the note that supersedes it. A note that waits for its
974
- * owner's OK (`status: pending`) supersedes nothing until it is approved: what it names stays active. The one rule the
975
- * merge writes by (runner/learning-loop.ts mergeChangeOf) and its index is counted by (mergeProblems). */
976
- export function supersededBy(notes) {
977
- return new Map(notes.filter((note) => note.status === "active").flatMap((note) => note.supersedes.map((old) => [old, note.file])));
978
- }
979
- /** What stops `notes` from joining `base` as they are: a name `base` holds (`exists`), a `supersedes` that names no
980
- * active note of `base` or one another new note supersedes too, or more than CAPS.supersedes notes superseded, and an
981
- * index past INDEX_LINES, counted as the merge makes it (supersededBy: a pending note adds no line and replaces none).
982
- * The checker asks it of the run's seed, where every new note is active; the host asks it again of main at merge time,
983
- * with each note as it merges it, since other runs may have merged meanwhile. */
984
- export function mergeProblems(base, notes, refuseValues = []) {
985
- const files = new Set(base.files);
986
- const active = new Set(base.active.map((note) => note.file));
987
- const out = [];
988
- const replaced = new Set();
989
- // The grader reads each note superseded in full (grade.ts): their count is capped, as the new notes' is. Counted in
990
- // the order the notes come: a note that would take the count past the cap is named (and left out), and what it
991
- // supersedes is neither counted nor held as superseded for the notes after it, so a later one that fits is kept.
992
- const counted = new Set();
993
- for (const note of notes) {
994
- if (files.has(note.file))
995
- out.push({ rule: "exists", path: note.file, detail: "the folder has a note by this name" });
996
- const would = new Set([...counted, ...note.supersedes]);
997
- const over = would.size > CAPS.supersedes;
998
- for (const old of note.supersedes) {
999
- if (!active.has(old))
1000
- out.push({ rule: "supersedes", path: note.file, detail: `it supersedes ${old}, which is not an active note` });
1001
- else if (replaced.has(old))
1002
- out.push({ rule: "supersedes", path: note.file, detail: `${old} is superseded by another new note too` });
1003
- if (!over)
1004
- replaced.add(old);
1005
- }
1006
- if (over)
1007
- out.push({ rule: "supersedes", path: note.file, detail: `with it the new notes supersede ${would.size} notes; the cap is ${CAPS.supersedes} a run` });
1008
- else
1009
- for (const old of note.supersedes)
1010
- counted.add(old);
1011
- }
1012
- const gone = supersededBy(notes);
1013
- const lines = [...active].filter((file) => !gone.has(file)).length + notes.filter((note) => note.status === "active").length;
1014
- if (lines > INDEX_LINES)
1015
- out.push({ rule: "index_full", detail: `the index would hold ${lines} lines; it holds at most ${INDEX_LINES}, so supersede a note rather than add one` });
1016
- return out.map((problem) => printable(problem, refuseValues));
738
+ return problems;
1017
739
  }