@cohortapp/agent-sdk 2.17.0 → 2.18.5

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 (531) hide show
  1. package/.claude/settings.json +18 -0
  2. package/.env.example +18 -5
  3. package/README.md +1 -0
  4. package/bin/maestro.mjs +62 -0
  5. package/docs/guides/billing-console-keys.md +60 -0
  6. package/docs/guides/front-door-session.md +54 -9
  7. package/docs/guides/mac-mini.md +20 -25
  8. package/docs/guides/setup-wizard.md +1 -1
  9. package/docs/runbooks/fleet-rollout.md +156 -0
  10. package/docs/runbooks/mac-mini-bootstrap.md +12 -14
  11. package/lib/action-executor.js +19 -3
  12. package/lib/budget-guard.mjs +279 -3
  13. package/lib/channels/base-adapter.mjs +3 -1
  14. package/lib/channels/contract.mjs +2 -1
  15. package/lib/channels/inbox-item.mjs +8 -0
  16. package/lib/claude-bin.mjs +5 -6
  17. package/lib/cli/doctor-checks.mjs +141 -10
  18. package/lib/cli/global-setup-extras.mjs +5 -1
  19. package/lib/cli/inbox.mjs +100 -15
  20. package/lib/cli/seat-auth.mjs +463 -0
  21. package/lib/cli/session.mjs +80 -12
  22. package/lib/collective/capture-slots.mjs +234 -0
  23. package/lib/collective/capture.mjs +8 -6
  24. package/lib/collective/config.mjs +2 -0
  25. package/lib/collective/global-config.mjs +63 -1
  26. package/lib/collective/loop-guard.mjs +155 -0
  27. package/lib/collective/presence.mjs +142 -5
  28. package/lib/comms/send-gate.mjs +559 -1
  29. package/lib/diagnostics/alerts.mjs +49 -0
  30. package/lib/diagnostics/cadence-output-freshness.mjs +288 -0
  31. package/lib/engine/agents/definitions.mjs +343 -0
  32. package/lib/engine/agents/persist.mjs +275 -0
  33. package/lib/engine/agents/runtime.mjs +748 -0
  34. package/lib/engine/agents/usage.mjs +95 -0
  35. package/lib/engine/auth-status.mjs +139 -0
  36. package/lib/engine/budget.mjs +194 -0
  37. package/lib/engine/cli.mjs +1204 -0
  38. package/lib/engine/commands/index.mjs +269 -0
  39. package/lib/engine/context/budget.mjs +219 -0
  40. package/lib/engine/context/cache.mjs +125 -0
  41. package/lib/engine/context/child-env.mjs +215 -0
  42. package/lib/engine/context/compaction.mjs +342 -0
  43. package/lib/engine/context/images.mjs +90 -0
  44. package/lib/engine/context/instructions.mjs +327 -0
  45. package/lib/engine/context/lazy-instructions.mjs +169 -0
  46. package/lib/engine/context/manager.mjs +182 -0
  47. package/lib/engine/context/real-path.mjs +91 -0
  48. package/lib/engine/context/secret-values.mjs +163 -0
  49. package/lib/engine/context/settings.mjs +274 -0
  50. package/lib/engine/context/stream-input.mjs +159 -0
  51. package/lib/engine/guard.mjs +152 -0
  52. package/lib/engine/hooks.mjs +713 -0
  53. package/lib/engine/loop.mjs +560 -0
  54. package/lib/engine/mcp/client.mjs +254 -0
  55. package/lib/engine/mcp/config.mjs +301 -0
  56. package/lib/engine/mcp/http.mjs +201 -0
  57. package/lib/engine/mcp/index.mjs +146 -0
  58. package/lib/engine/mcp/jsonrpc.mjs +147 -0
  59. package/lib/engine/mcp/naming.mjs +66 -0
  60. package/lib/engine/mcp/resources.mjs +89 -0
  61. package/lib/engine/mcp/results.mjs +133 -0
  62. package/lib/engine/mcp/stdio.mjs +137 -0
  63. package/lib/engine/mcp/supervisor.mjs +116 -0
  64. package/lib/engine/messages.mjs +104 -0
  65. package/lib/engine/output/json.mjs +164 -0
  66. package/lib/engine/output/stream-json.mjs +266 -0
  67. package/lib/engine/permissions.mjs +845 -0
  68. package/lib/engine/process-identity.mjs +164 -0
  69. package/lib/engine/process-tree.mjs +551 -0
  70. package/lib/engine/prompt.mjs +60 -0
  71. package/lib/engine/session/store.mjs +299 -0
  72. package/lib/engine/session-runtime/args.mjs +97 -0
  73. package/lib/engine/session-runtime/host.mjs +143 -0
  74. package/lib/engine/session-runtime/inbox.mjs +122 -0
  75. package/lib/engine/session-runtime/notifications.mjs +129 -0
  76. package/lib/engine/session-runtime/registry.mjs +328 -0
  77. package/lib/engine/session-runtime/runner.mjs +344 -0
  78. package/lib/engine/session-runtime/socket.mjs +212 -0
  79. package/lib/engine/session-runtime/wakeup.mjs +115 -0
  80. package/lib/engine/skills/index.mjs +321 -0
  81. package/lib/engine/tools/bash-background.mjs +533 -0
  82. package/lib/engine/tools/bash.mjs +216 -0
  83. package/lib/engine/tools/edit.mjs +97 -0
  84. package/lib/engine/tools/glob.mjs +81 -0
  85. package/lib/engine/tools/grep.mjs +224 -0
  86. package/lib/engine/tools/index.mjs +84 -0
  87. package/lib/engine/tools/list-agents.mjs +32 -0
  88. package/lib/engine/tools/ls.mjs +127 -0
  89. package/lib/engine/tools/monitor.mjs +82 -0
  90. package/lib/engine/tools/notebook-edit.mjs +218 -0
  91. package/lib/engine/tools/read.mjs +103 -0
  92. package/lib/engine/tools/schedule-wakeup.mjs +45 -0
  93. package/lib/engine/tools/schema.mjs +144 -0
  94. package/lib/engine/tools/send-message.mjs +77 -0
  95. package/lib/engine/tools/session.mjs +70 -0
  96. package/lib/engine/tools/todo.mjs +144 -0
  97. package/lib/engine/tools/toolsearch.mjs +217 -0
  98. package/lib/engine/tools/walk.mjs +193 -0
  99. package/lib/engine/tools/web-switch.mjs +31 -0
  100. package/lib/engine/tools/webfetch-html.mjs +387 -0
  101. package/lib/engine/tools/webfetch-net.mjs +340 -0
  102. package/lib/engine/tools/webfetch.mjs +198 -0
  103. package/lib/engine/tools/websearch.mjs +91 -0
  104. package/lib/engine/tools/workflow.mjs +95 -0
  105. package/lib/engine/tools/write.mjs +76 -0
  106. package/lib/engine/tui/line-editor.mjs +137 -0
  107. package/lib/engine/tui/render.mjs +86 -0
  108. package/lib/engine/tui/tui.mjs +274 -0
  109. package/lib/engine/wire/anthropic-messages.mjs +263 -0
  110. package/lib/engine/wire/effort.mjs +36 -0
  111. package/lib/engine/wire/errors.mjs +496 -0
  112. package/lib/engine/wire/http.mjs +441 -0
  113. package/lib/engine/wire/index.mjs +76 -0
  114. package/lib/engine/wire/openai-chat.mjs +332 -0
  115. package/lib/engine/wire/prompt-cache.mjs +79 -0
  116. package/lib/engine/wire/search.mjs +140 -0
  117. package/lib/engine/wire/sse.mjs +114 -0
  118. package/lib/engine/wire/stall.mjs +349 -0
  119. package/lib/engine/wire/token-provider.mjs +175 -0
  120. package/lib/engine/wire/usage.mjs +192 -0
  121. package/lib/engine/workflow/host.mjs +524 -0
  122. package/lib/engine/workflow/journal.mjs +188 -0
  123. package/lib/engine/workflow/json-schema.mjs +171 -0
  124. package/lib/engine/workflow/meta.mjs +329 -0
  125. package/lib/engine/workflow/notifications.mjs +52 -0
  126. package/lib/engine/workflow/runtime.mjs +447 -0
  127. package/lib/engine/workflow/sandbox.mjs +534 -0
  128. package/lib/engine/workflow/worker.mjs +141 -0
  129. package/lib/engine/workflow/worktree.mjs +74 -0
  130. package/lib/execution/disposition.mjs +1 -1
  131. package/lib/execution/intake.mjs +10 -0
  132. package/lib/execution/surface-policy.mjs +15 -0
  133. package/lib/learning/curator.mjs +8 -6
  134. package/lib/learning/reflect.mjs +8 -6
  135. package/lib/model-router/catalog/cohort.yaml +137 -0
  136. package/lib/model-router/catalog.mjs +118 -1
  137. package/lib/model-router/failover.mjs +67 -16
  138. package/lib/model-router/llm-task.mjs +39 -3
  139. package/lib/model-router/resolve.mjs +89 -3
  140. package/lib/model-router/spawn.mjs +46 -47
  141. package/lib/model-router/taxonomy.mjs +126 -4
  142. package/lib/org/cost-sync.mjs +141 -11
  143. package/lib/org/inbound/broadcast.mjs +289 -0
  144. package/lib/org/inbound/collective.mjs +375 -0
  145. package/lib/org/inbound/directedness.mjs +96 -8
  146. package/lib/org/inbound/facts.mjs +78 -2
  147. package/lib/org/inbound/project.mjs +22 -0
  148. package/lib/org/inbound/surfaces.mjs +14 -0
  149. package/lib/org/llm-token.mjs +879 -0
  150. package/lib/org/mesh.mjs +61 -0
  151. package/lib/org/messaging.mjs +3 -1
  152. package/lib/org/protocol.checksum +1 -1
  153. package/lib/org/protocol.mjs +15 -0
  154. package/lib/org/quota.mjs +520 -0
  155. package/lib/org/tool-surface.mjs +104 -16
  156. package/lib/org/ui-parity.mjs +16 -1
  157. package/lib/org/work-ledger.mjs +37 -6
  158. package/lib/rate-guard.mjs +114 -1
  159. package/lib/resource-governor.mjs +41 -6
  160. package/lib/runtime/adapter.mjs +833 -0
  161. package/lib/runtime/child-env.mjs +191 -0
  162. package/lib/runtime/legacy-shell-guard.mjs +97 -0
  163. package/lib/runtime/seat-engine.mjs +162 -0
  164. package/lib/session/ask-ledger.mjs +271 -0
  165. package/lib/session/current-work.mjs +676 -0
  166. package/lib/session/feed-core.mjs +40 -3
  167. package/lib/session/launch-args.mjs +56 -4
  168. package/lib/session/status-summary.mjs +26 -9
  169. package/lib/session/upgrade-notice.mjs +42 -0
  170. package/lib/setup/claude-probe.mjs +117 -13
  171. package/lib/setup/enrich.mjs +13 -10
  172. package/lib/setup/sections/model.mjs +39 -13
  173. package/lib/telemetry/collect.mjs +229 -11
  174. package/lib/upgrade/ignored-drift.mjs +105 -0
  175. package/lib/voice/post-call-brief.mjs +30 -17
  176. package/package.json +13 -3
  177. package/plugins/maestro-skills/skills/board-work.md +5 -0
  178. package/plugins/maestro-skills/skills/inbound-triage.md +56 -15
  179. package/plugins/maestro-skills/skills/main-session.md +18 -7
  180. package/scaffold/config/collective.yaml +7 -0
  181. package/scripts/ci/check-durable-write-seam.mjs +3 -1
  182. package/scripts/ci/check-tarball-fidelity.mjs +126 -2
  183. package/scripts/ci/run-tests.mjs +47 -19
  184. package/scripts/cohort-llm/api-key-helper.mjs +92 -0
  185. package/scripts/collective/hook-runner.mjs +142 -19
  186. package/scripts/continuous-monitor.sh +13 -0
  187. package/scripts/cost/track-claude-usage.mjs +15 -0
  188. package/scripts/daemon/agent-daemon.mjs +408 -20
  189. package/scripts/daemon/assurance.mjs +48 -12
  190. package/scripts/daemon/cadence-consumer.mjs +218 -68
  191. package/scripts/daemon/cadence-handlers.mjs +73 -4
  192. package/scripts/daemon/classifier.mjs +75 -26
  193. package/scripts/daemon/context-compiler.mjs +51 -37
  194. package/scripts/daemon/deliver.mjs +30 -1
  195. package/scripts/daemon/dispatcher.mjs +595 -149
  196. package/scripts/daemon/health.mjs +14 -1
  197. package/scripts/daemon/maestro-daemon.mjs +11 -0
  198. package/scripts/daemon/prompt-builder.mjs +24 -0
  199. package/scripts/daemon/responder.mjs +246 -79
  200. package/scripts/daemon/sdk-version.mjs +98 -16
  201. package/scripts/eval/probe-gateway.mjs +635 -0
  202. package/scripts/eval/replay/extract.mjs +270 -0
  203. package/scripts/eval/replay/grade.mjs +260 -0
  204. package/scripts/eval/replay/lib/config.mjs +50 -0
  205. package/scripts/eval/replay/lib/effects.mjs +65 -0
  206. package/scripts/eval/replay/lib/fixture.mjs +188 -0
  207. package/scripts/eval/replay/lib/judge.mjs +72 -0
  208. package/scripts/eval/replay/lib/redact.mjs +136 -0
  209. package/scripts/eval/replay/lib/sandbox.mjs +170 -0
  210. package/scripts/eval/replay/lib/schema-check.mjs +63 -0
  211. package/scripts/eval/replay/lib/transcript.mjs +76 -0
  212. package/scripts/eval/replay/mcp-replay-stub.mjs +101 -0
  213. package/scripts/eval/replay/report.mjs +185 -0
  214. package/scripts/eval/replay/run.mjs +404 -0
  215. package/scripts/fleet/rollout.mjs +1151 -0
  216. package/scripts/hooks/pre-send-audit.sh +36 -245
  217. package/scripts/hooks/pre-write-yaml-validate.mjs +275 -0
  218. package/scripts/hooks/validate-state-yaml.sh +190 -0
  219. package/scripts/huddle/huddle-llm.mjs +361 -0
  220. package/scripts/huddle/huddle-server.mjs +46 -121
  221. package/scripts/local-triggers/autoupdate.sh +465 -81
  222. package/scripts/local-triggers/run-trigger.sh +13 -0
  223. package/scripts/maintenance/pin-integrity.mjs +364 -0
  224. package/scripts/poll-slack-events.sh +41 -9
  225. package/scripts/poller/slack-socket-mode.mjs +28 -3
  226. package/scripts/session/supervisor.mjs +80 -13
  227. package/scripts/spawn-session.sh +13 -0
  228. package/bin/maestro.test.mjs +0 -1574
  229. package/lib/action-executor.test.mjs +0 -871
  230. package/lib/archetype.test.mjs +0 -132
  231. package/lib/assurance/plan-note.test.mjs +0 -234
  232. package/lib/assurance/room-budget.test.mjs +0 -486
  233. package/lib/assurance/tier.test.mjs +0 -174
  234. package/lib/autonomy.test.mjs +0 -66
  235. package/lib/backlog.test.mjs +0 -302
  236. package/lib/backup/policy.test.mjs +0 -305
  237. package/lib/budget-escalate.test.mjs +0 -232
  238. package/lib/budget-guard.envelope.test.mjs +0 -476
  239. package/lib/budget-guard.test.mjs +0 -427
  240. package/lib/cadence-bus-requeue.test.mjs +0 -83
  241. package/lib/cadence-bus-schedule.test.mjs +0 -194
  242. package/lib/cadence-bus.test.mjs +0 -720
  243. package/lib/cadences.test.mjs +0 -230
  244. package/lib/capability/inventory.test.mjs +0 -232
  245. package/lib/capability.test.mjs +0 -78
  246. package/lib/channels/base-adapter.test.mjs +0 -590
  247. package/lib/channels/channels.test.mjs +0 -371
  248. package/lib/channels/contract.test.mjs +0 -162
  249. package/lib/channels/inbox-item.test.mjs +0 -368
  250. package/lib/channels/orgmail/adapter.test.mjs +0 -448
  251. package/lib/channels/pairing.test.mjs +0 -270
  252. package/lib/channels/repeat-suppressor.test.mjs +0 -134
  253. package/lib/channels/slack-adapter.test.mjs +0 -212
  254. package/lib/channels/telegram-adapter.test.mjs +0 -306
  255. package/lib/channels/voice/adapter.test.mjs +0 -278
  256. package/lib/channels/whatsapp/adapter-baileys.test.mjs +0 -359
  257. package/lib/channels/whatsapp/baileys-typing.test.mjs +0 -154
  258. package/lib/charter.test.mjs +0 -89
  259. package/lib/claude-bin.test.mjs +0 -131
  260. package/lib/cli/board.test.mjs +0 -227
  261. package/lib/cli/design.test.mjs +0 -270
  262. package/lib/cli/doctor-checks.test.mjs +0 -336
  263. package/lib/cli/global-setup-extras.test.mjs +0 -462
  264. package/lib/cli/inbox.test.mjs +0 -230
  265. package/lib/cli/session-ack.test.mjs +0 -63
  266. package/lib/cli/session.test.mjs +0 -613
  267. package/lib/collective/capture.test.mjs +0 -121
  268. package/lib/collective/cards.test.mjs +0 -114
  269. package/lib/collective/config.test.mjs +0 -123
  270. package/lib/collective/global-config.test.mjs +0 -220
  271. package/lib/collective/global-skills.test.mjs +0 -126
  272. package/lib/collective/presence.test.mjs +0 -95
  273. package/lib/collective/recall.test.mjs +0 -116
  274. package/lib/collective/vendor-skills.test.mjs +0 -306
  275. package/lib/comms/send-gate.test.mjs +0 -770
  276. package/lib/comms.test.mjs +0 -41
  277. package/lib/context/budget.test.mjs +0 -252
  278. package/lib/context/history-scope.test.mjs +0 -79
  279. package/lib/cost/ledger-row.test.mjs +0 -183
  280. package/lib/design/design-md.test.mjs +0 -318
  281. package/lib/design/fixtures/DESIGN.golden.md +0 -238
  282. package/lib/design/fixtures/PRODUCT.golden.md +0 -67
  283. package/lib/design/fixtures/foundation.json +0 -133
  284. package/lib/design/refresh-gate.test.mjs +0 -144
  285. package/lib/design/write.test.mjs +0 -241
  286. package/lib/diagnostics/alerts.test.mjs +0 -318
  287. package/lib/diagnostics/backup-freshness.test.mjs +0 -185
  288. package/lib/diagnostics/counters.test.mjs +0 -206
  289. package/lib/diagnostics/events.test.mjs +0 -290
  290. package/lib/diagnostics/otel.test.mjs +0 -196
  291. package/lib/diagnostics/trace.test.mjs +0 -251
  292. package/lib/env-compat.test.mjs +0 -104
  293. package/lib/execution/disposition.test.mjs +0 -553
  294. package/lib/execution/drive.test.mjs +0 -270
  295. package/lib/execution/effects.test.mjs +0 -344
  296. package/lib/execution/intake.test.mjs +0 -389
  297. package/lib/execution/journal.test.mjs +0 -261
  298. package/lib/execution/match.test.mjs +0 -235
  299. package/lib/execution/pipeline.test.mjs +0 -392
  300. package/lib/execution/route.test.mjs +0 -186
  301. package/lib/execution/surface-policy.test.mjs +0 -162
  302. package/lib/fs-atomic.test.mjs +0 -72
  303. package/lib/fs-ownership.test.mjs +0 -158
  304. package/lib/goals/admission.test.mjs +0 -164
  305. package/lib/goals/classify.test.mjs +0 -167
  306. package/lib/goals/collaborate.test.mjs +0 -336
  307. package/lib/goals/gaps.test.mjs +0 -284
  308. package/lib/goals/loop.test.mjs +0 -845
  309. package/lib/hooks/bus.test.mjs +0 -387
  310. package/lib/identity/persona.test.mjs +0 -142
  311. package/lib/kpi-sensors.test.mjs +0 -278
  312. package/lib/kpi.test.mjs +0 -244
  313. package/lib/learning/config.test.mjs +0 -75
  314. package/lib/learning/counters.test.mjs +0 -69
  315. package/lib/learning/curator-consolidate.test.mjs +0 -238
  316. package/lib/learning/curator.test.mjs +0 -106
  317. package/lib/learning/reflect.test.mjs +0 -0
  318. package/lib/learning/session-index.test.mjs +0 -125
  319. package/lib/learning/skill-writer.test.mjs +0 -210
  320. package/lib/mandate/audit.test.mjs +0 -195
  321. package/lib/mandate/contract.test.mjs +0 -185
  322. package/lib/mandate/derive.test.mjs +0 -274
  323. package/lib/mandate/model.test.mjs +0 -164
  324. package/lib/mandate/refresh.test.mjs +0 -389
  325. package/lib/mcp/server.test.mjs +0 -426
  326. package/lib/model-router/auth-profiles.test.mjs +0 -580
  327. package/lib/model-router/catalog.test.mjs +0 -385
  328. package/lib/model-router/economics.test.mjs +0 -438
  329. package/lib/model-router/failover.test.mjs +0 -439
  330. package/lib/model-router/health.test.mjs +0 -338
  331. package/lib/model-router/integration-coverage.test.mjs +0 -831
  332. package/lib/model-router/integration.test.mjs +0 -564
  333. package/lib/model-router/ledger.test.mjs +0 -415
  334. package/lib/model-router/llm-task.test.mjs +0 -392
  335. package/lib/model-router/org-credentials.test.mjs +0 -265
  336. package/lib/model-router/pricing-refresh.test.mjs +0 -286
  337. package/lib/model-router/reconcile.test.mjs +0 -316
  338. package/lib/model-router/repair.test.mjs +0 -180
  339. package/lib/model-router/spawn.test.mjs +0 -446
  340. package/lib/model-router/taxonomy.test.mjs +0 -410
  341. package/lib/model-router.test.mjs +0 -1207
  342. package/lib/org/activity.test.mjs +0 -134
  343. package/lib/org/approvals.test.mjs +0 -216
  344. package/lib/org/awareness.test.mjs +0 -159
  345. package/lib/org/board-mine-cache.test.mjs +0 -53
  346. package/lib/org/board.test.mjs +0 -187
  347. package/lib/org/bootstrap-context.test.mjs +0 -153
  348. package/lib/org/client.test.mjs +0 -1206
  349. package/lib/org/cohort-client.test.mjs +0 -126
  350. package/lib/org/cost-sync.test.mjs +0 -153
  351. package/lib/org/doctor.test.mjs +0 -346
  352. package/lib/org/engagement-ledger.test.mjs +0 -112
  353. package/lib/org/engagement.test.mjs +0 -739
  354. package/lib/org/handoff.test.mjs +0 -269
  355. package/lib/org/inbound/directedness.test.mjs +0 -668
  356. package/lib/org/inbound/facts.test.mjs +0 -471
  357. package/lib/org/inbound/hydrate.test.mjs +0 -908
  358. package/lib/org/inbound/index.test.mjs +0 -429
  359. package/lib/org/inbound/project.test.mjs +0 -287
  360. package/lib/org/integration-tools.test.mjs +0 -160
  361. package/lib/org/keys.test.mjs +0 -92
  362. package/lib/org/knowledge.test.mjs +0 -326
  363. package/lib/org/leases.test.mjs +0 -235
  364. package/lib/org/mesh-directives.test.mjs +0 -110
  365. package/lib/org/mesh-integration.test.mjs +0 -127
  366. package/lib/org/mesh.test.mjs +0 -400
  367. package/lib/org/messaging.test.mjs +0 -471
  368. package/lib/org/param-contract.test.mjs +0 -477
  369. package/lib/org/policy.test.mjs +0 -237
  370. package/lib/org/protocol.checksum.test.mjs +0 -90
  371. package/lib/org/protocol.test.mjs +0 -323
  372. package/lib/org/push.test.mjs +0 -792
  373. package/lib/org/registry.test.mjs +0 -100
  374. package/lib/org/resource-tools.test.mjs +0 -361
  375. package/lib/org/tool-access.test.mjs +0 -144
  376. package/lib/org/tool-surface-integration.test.mjs +0 -120
  377. package/lib/org/tool-surface.test.mjs +0 -1268
  378. package/lib/org/typing.test.mjs +0 -291
  379. package/lib/org/ui-parity.test.mjs +0 -560
  380. package/lib/org/verify.test.mjs +0 -194
  381. package/lib/org/work-ledger.test.mjs +0 -273
  382. package/lib/plan/adoption-e2e.test.mjs +0 -366
  383. package/lib/plan/budget-enforcement.test.mjs +0 -400
  384. package/lib/plan/compile.test.mjs +0 -382
  385. package/lib/plan/emit.test.mjs +0 -269
  386. package/lib/plan/explain.test.mjs +0 -188
  387. package/lib/prompts/parallelism.test.mjs +0 -177
  388. package/lib/rag/rag.test.mjs +0 -505
  389. package/lib/rate-guard.test.mjs +0 -272
  390. package/lib/reactive-gate.test.mjs +0 -57
  391. package/lib/render.test.mjs +0 -68
  392. package/lib/resource-governor.test.mjs +0 -488
  393. package/lib/scheduling/dynamic-jobs.test.mjs +0 -344
  394. package/lib/scheduling/jitter.test.mjs +0 -140
  395. package/lib/secrets/broker.test.mjs +0 -280
  396. package/lib/secrets/providers.test.mjs +0 -274
  397. package/lib/security/audit-engine.test.mjs +0 -424
  398. package/lib/security/coerce-args.test.mjs +0 -281
  399. package/lib/security/dangerous-tools.test.mjs +0 -68
  400. package/lib/security/external-content.test.mjs +0 -84
  401. package/lib/security/redact.test.mjs +0 -441
  402. package/lib/security/secret-equal.test.mjs +0 -55
  403. package/lib/session/config.test.mjs +0 -92
  404. package/lib/session/feed-core.test.mjs +0 -198
  405. package/lib/session/first-run.test.mjs +0 -121
  406. package/lib/session/frontdoor.test.mjs +0 -205
  407. package/lib/session/handoffs.test.mjs +0 -183
  408. package/lib/session/identity.test.mjs +0 -180
  409. package/lib/session/inbox-claims.test.mjs +0 -286
  410. package/lib/session/launch-args.test.mjs +0 -157
  411. package/lib/session/liveness.test.mjs +0 -100
  412. package/lib/session/status-summary.test.mjs +0 -118
  413. package/lib/session-permissions.test.mjs +0 -120
  414. package/lib/setup/claude-probe.test.mjs +0 -187
  415. package/lib/setup/completeness.test.mjs +0 -110
  416. package/lib/setup/context-pack.test.mjs +0 -89
  417. package/lib/setup/enrich.test.mjs +0 -115
  418. package/lib/setup/enroll-from-cohort.test.mjs +0 -300
  419. package/lib/setup/integration.test.mjs +0 -162
  420. package/lib/setup/io.test.mjs +0 -77
  421. package/lib/setup/runner.test.mjs +0 -132
  422. package/lib/setup/sections/identity.test.mjs +0 -234
  423. package/lib/setup/sections/inventory.test.mjs +0 -198
  424. package/lib/setup/sections/learning.test.mjs +0 -81
  425. package/lib/setup/sections/mandate.test.mjs +0 -388
  426. package/lib/setup/sections/messaging.test.mjs +0 -127
  427. package/lib/setup/sections/model.test.mjs +0 -240
  428. package/lib/setup/sections/org.test.mjs +0 -346
  429. package/lib/setup/sections/orgmail.test.mjs +0 -118
  430. package/lib/setup/sections/recovery.test.mjs +0 -98
  431. package/lib/setup/sections/subagents.test.mjs +0 -429
  432. package/lib/setup/sections/verify.test.mjs +0 -175
  433. package/lib/setup/sot.test.mjs +0 -81
  434. package/lib/setup/state.test.mjs +0 -115
  435. package/lib/singleton.test.mjs +0 -151
  436. package/lib/subagents/cli.test.mjs +0 -389
  437. package/lib/subagents/client.test.mjs +0 -309
  438. package/lib/subagents/gap.test.mjs +0 -234
  439. package/lib/subagents/lock.test.mjs +0 -248
  440. package/lib/subagents/manifest.test.mjs +0 -175
  441. package/lib/subagents/refs.test.mjs +0 -204
  442. package/lib/subagents/resolve.test.mjs +0 -422
  443. package/lib/subagents/schema.test.mjs +0 -328
  444. package/lib/telemetry/alerts.test.mjs +0 -109
  445. package/lib/telemetry/collect.test.mjs +0 -1274
  446. package/lib/tool-definitions-integration.test.mjs +0 -83
  447. package/lib/tool-definitions.test.mjs +0 -437
  448. package/lib/upgrade/global-refresh.test.mjs +0 -65
  449. package/lib/upgrade/launchd-reconcile.test.mjs +0 -272
  450. package/lib/upgrade/post-steps.test.mjs +0 -200
  451. package/lib/upgrade/verify.test.mjs +0 -164
  452. package/lib/util/fetch-timeout.test.mjs +0 -202
  453. package/lib/util/reconnect.test.mjs +0 -369
  454. package/lib/util/unhandled.test.mjs +0 -216
  455. package/lib/voice/outbound.test.mjs +0 -69
  456. package/lib/voice/session-rotation.test.mjs +0 -114
  457. package/lib/voice/stt.test.mjs +0 -226
  458. package/lib/voice/voice.test.mjs +0 -990
  459. package/scripts/cadence/enqueue-cadence-tick.test.mjs +0 -187
  460. package/scripts/ci/check-docs-accuracy.test.mjs +0 -409
  461. package/scripts/ci/check-durable-write-seam.test.mjs +0 -90
  462. package/scripts/ci/check-no-build-artifacts.test.mjs +0 -71
  463. package/scripts/ci/check-no-residual-identity.test.mjs +0 -202
  464. package/scripts/ci/check-skill-packs.test.mjs +0 -495
  465. package/scripts/ci/check-subagent-frontmatter.test.mjs +0 -124
  466. package/scripts/ci/check.test.mjs +0 -194
  467. package/scripts/ci/conformance-org-api.test.mjs +0 -425
  468. package/scripts/cloud-relay/voice/relay-identity.test.mjs +0 -96
  469. package/scripts/collective/hook-runner.test.mjs +0 -173
  470. package/scripts/cost/fleet-digest.test.mjs +0 -207
  471. package/scripts/cost/track-claude-usage-pricing.test.mjs +0 -183
  472. package/scripts/cost/track-claude-usage.test.mjs +0 -148
  473. package/scripts/daemon/agent-daemon-board-mine.test.mjs +0 -96
  474. package/scripts/daemon/agent-daemon-design.test.mjs +0 -238
  475. package/scripts/daemon/agent-daemon-frontdoor.test.mjs +0 -60
  476. package/scripts/daemon/agent-daemon.test.mjs +0 -995
  477. package/scripts/daemon/assurance-e2e.test.mjs +0 -613
  478. package/scripts/daemon/assurance.test.mjs +0 -1791
  479. package/scripts/daemon/board-mirror.test.mjs +0 -165
  480. package/scripts/daemon/cadence-consumer-frontdoor.test.mjs +0 -393
  481. package/scripts/daemon/cadence-consumer-governance.test.mjs +0 -276
  482. package/scripts/daemon/cadence-consumer.test.mjs +0 -776
  483. package/scripts/daemon/cadence-handlers.test.mjs +0 -837
  484. package/scripts/daemon/classifier-identity.test.mjs +0 -137
  485. package/scripts/daemon/classifier.test.mjs +0 -266
  486. package/scripts/daemon/classify-kind.test.mjs +0 -40
  487. package/scripts/daemon/context-compiler.test.mjs +0 -406
  488. package/scripts/daemon/deliver.test.mjs +0 -564
  489. package/scripts/daemon/dispatcher-cooldown.test.mjs +0 -122
  490. package/scripts/daemon/dispatcher-governance.test.mjs +0 -1013
  491. package/scripts/daemon/dispatcher-resume.test.mjs +0 -166
  492. package/scripts/daemon/dispatcher-session-continuity.test.mjs +0 -365
  493. package/scripts/daemon/execution-ladder.test.mjs +0 -470
  494. package/scripts/daemon/goal-steward-cadence.test.mjs +0 -312
  495. package/scripts/daemon/inbox-deferral-session.test.mjs +0 -49
  496. package/scripts/daemon/inbox-deferral.test.mjs +0 -336
  497. package/scripts/daemon/inbox-wake.test.mjs +0 -199
  498. package/scripts/daemon/integration.test.mjs +0 -149
  499. package/scripts/daemon/lib/self-echo.test.mjs +0 -153
  500. package/scripts/daemon/lib/session-router.test.mjs +0 -554
  501. package/scripts/daemon/prompt-builder-preamble.test.mjs +0 -210
  502. package/scripts/daemon/prompt-builder.test.mjs +0 -556
  503. package/scripts/daemon/responder-cost.test.mjs +0 -68
  504. package/scripts/daemon/responder-history.test.mjs +0 -221
  505. package/scripts/daemon/sdk-version.test.mjs +0 -31
  506. package/scripts/daemon/session-lock.test.mjs +0 -252
  507. package/scripts/daemon/session-outcomes.test.mjs +0 -533
  508. package/scripts/daemon/typing-registry.test.mjs +0 -102
  509. package/scripts/hooks/pre-send-audit.test.mjs +0 -354
  510. package/scripts/huddle/huddle-prompt.test.mjs +0 -176
  511. package/scripts/local-triggers/autoupdate.test.mjs +0 -518
  512. package/scripts/local-triggers/generate-plists.test.mjs +0 -456
  513. package/scripts/media-generation/brand-clause.test.mjs +0 -135
  514. package/scripts/org/send-orgmail.first-contact.test.mjs +0 -102
  515. package/scripts/poller/inbox-privilege-injection.test.mjs +0 -167
  516. package/scripts/poller/inbox-scan-poller.test.mjs +0 -295
  517. package/scripts/poller/lib/cloud-relay-dedup.test.mjs +0 -133
  518. package/scripts/poller/slack-socket-mode.test.mjs +0 -805
  519. package/scripts/poller-launchd/install.test.mjs +0 -243
  520. package/scripts/restore-from-backup.test.mjs +0 -181
  521. package/scripts/session/feed.test.mjs +0 -196
  522. package/scripts/session/supervisor-sh.test.mjs +0 -218
  523. package/scripts/session/supervisor.test.mjs +0 -482
  524. package/scripts/setup/configure-macos.test.mjs +0 -306
  525. package/scripts/setup/gen-subagent-manifest.test.mjs +0 -124
  526. package/scripts/setup/generate-agent-package-json.test.mjs +0 -143
  527. package/scripts/setup/generate-capability.test.mjs +0 -134
  528. package/scripts/setup/init-agent.test.mjs +0 -370
  529. package/scripts/setup/init-skill-marketplace.test.mjs +0 -193
  530. package/scripts/vendor/sync-skill-packs.test.mjs +0 -103
  531. package/scripts/watchdog/memory-watchdog.test.mjs +0 -64
@@ -0,0 +1,188 @@
1
+ /**
2
+ * scripts/eval/replay/lib/fixture.mjs — the replay task fixture (schema v1).
3
+ *
4
+ * {
5
+ * schemaVersion: 1,
6
+ * id: "ex-01-board-status", file-name safe
7
+ * synthetic: true, examples only; extracted tasks are false
8
+ * source: { kind: "synthetic"|"dispatcher"|"cadence", sessionId?, recordedAt?, cadence? },
9
+ * lane: "dispatcher"|"cadence", which maestro lane ran it
10
+ * prompt: "…",
11
+ * model?: "sonnet", the lane's --model (the engine maps it to a tier)
12
+ * maxTurns?: 20, timeoutMs?: 180000,
13
+ * agentRoot?: { files: { "CLAUDE.md": "…" } }, written into the sandbox agent root, over a copied seat
14
+ * sandbox?: { permissions?: "scoped"|"bypass", allowTools?: ["Bash(ls:*)"] }, see lib/sandbox.mjs
15
+ * mcp: {
16
+ * server: "cohort",
17
+ * tools: ["board_mine", {name, description, inputSchema}], names resolve against the org tool surface
18
+ * replies: [{ tool: "board_mine", input?: {…partial matcher}, recordedInput?: {…the recorded call}, result: "text" | {text}, isError?: false }]
19
+ * },
20
+ * expect: {
21
+ * toolCalls?: [{ tool: "mcp__cohort__board_mine", input?: {…partial}, min?: 1, max? }],
22
+ * forbidden?: [{ tool: "mcp__cohort__email_send", input?: {…partial} }],
23
+ * finalAnswer?: { contains?: [], notContains?: [], matches?: [], nonEmpty?: true },
24
+ * rubric?: "what a good answer does", reference?: "a redacted recorded answer"
25
+ * }
26
+ * }
27
+ *
28
+ * Pure except `resolveToolDefs`, which reads the org tool table (a module, no I/O).
29
+ *
30
+ * @module scripts/eval/replay/lib/fixture
31
+ */
32
+
33
+ import { SEND_GATE_TOOLS, SEND_GATE_MATCHER } from "../../../../lib/engine/hooks.mjs";
34
+ import { orgToolDef } from "../../../../lib/org/tool-surface.mjs";
35
+ import { DEFAULT_MAX_TURNS, DEFAULT_TASK_TIMEOUT_MS } from "./config.mjs";
36
+
37
+ export const FIXTURE_SCHEMA_VERSION = 1;
38
+ export const OUTBOUND_TOOLS = SEND_GATE_TOOLS;
39
+ const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
40
+
41
+ /** Is this tool name (full `mcp__server__tool` or bare) an outbound send? */
42
+ export function isOutboundTool(/** @type string */ name) {
43
+ return SEND_GATE_MATCHER.test(name) || OUTBOUND_TOOLS.includes(name);
44
+ }
45
+
46
+ /** @param {string} server @param {string} tool */
47
+ export const fullToolName = (server, tool) => (tool.startsWith("mcp__") ? tool : `mcp__${server}__${tool}`);
48
+
49
+ /**
50
+ * Is `partial` contained in `value`? Objects by key, arrays by position,
51
+ * strings exactly (or by a {"$contains": "…"} / {"$regex": "…"} matcher).
52
+ * @param {unknown} partial @param {unknown} value
53
+ */
54
+ export function partialMatch(partial, value) {
55
+ if (partial === undefined) return true;
56
+ if (partial && typeof partial === "object" && !Array.isArray(partial)) {
57
+ const p = /** @type {Record<string, unknown>} */ (partial);
58
+ if (typeof p.$contains === "string") return typeof value === "string" && value.toLowerCase().includes(p.$contains.toLowerCase());
59
+ if (typeof p.$regex === "string") return typeof value === "string" && new RegExp(p.$regex, "i").test(value);
60
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
61
+ return Object.entries(p).every(([k, v]) => partialMatch(v, /** @type {Record<string, unknown>} */ (value)[k]));
62
+ }
63
+ if (Array.isArray(partial)) return Array.isArray(value) && partial.every((v, i) => partialMatch(v, value[i]));
64
+ return JSON.stringify(partial) === JSON.stringify(value);
65
+ }
66
+
67
+ /**
68
+ * @param {any} task
69
+ * @returns {{ok:true, task:any} | {ok:false, errors:string[]}}
70
+ */
71
+ export function validateTask(task) {
72
+ const errors = [];
73
+ if (!task || typeof task !== "object") return { ok: false, errors: ["a task must be an object"] };
74
+ if (task.schemaVersion !== FIXTURE_SCHEMA_VERSION) errors.push(`schemaVersion must be ${FIXTURE_SCHEMA_VERSION}`);
75
+ if (typeof task.id !== "string" || !ID_RE.test(task.id)) errors.push("id must be a file-name-safe string");
76
+ if (task.lane !== "dispatcher" && task.lane !== "cadence") errors.push('lane must be "dispatcher" or "cadence"');
77
+ if (typeof task.prompt !== "string" || task.prompt.trim() === "") errors.push("prompt is required");
78
+ if (task.maxTurns !== undefined && !(Number.isInteger(task.maxTurns) && task.maxTurns > 0)) errors.push("maxTurns must be a positive integer");
79
+ if (task.timeoutMs !== undefined && !(Number.isInteger(task.timeoutMs) && task.timeoutMs > 0)) errors.push("timeoutMs must be a positive integer");
80
+ const mcp = task.mcp ?? {};
81
+ if (typeof mcp.server !== "string" || !/^[A-Za-z0-9_-]+$/.test(mcp.server)) errors.push("mcp.server must be a server name");
82
+ if (!Array.isArray(mcp.tools)) errors.push("mcp.tools must be an array");
83
+ if (mcp.replies !== undefined && !Array.isArray(mcp.replies)) errors.push("mcp.replies must be an array");
84
+ for (const [i, r] of (Array.isArray(mcp.replies) ? mcp.replies : []).entries()) {
85
+ if (typeof r?.tool !== "string") errors.push(`mcp.replies[${i}].tool is required`);
86
+ if (typeof r?.result !== "string" && typeof r?.result?.text !== "string") errors.push(`mcp.replies[${i}].result must be text or {text}`);
87
+ }
88
+ const sb = task.sandbox;
89
+ if (sb !== undefined) {
90
+ if (!sb || typeof sb !== "object") errors.push("sandbox must be an object");
91
+ else {
92
+ if (sb.permissions !== undefined && sb.permissions !== "scoped" && sb.permissions !== "bypass") errors.push('sandbox.permissions must be "scoped" or "bypass"');
93
+ if (sb.allowTools !== undefined && !(Array.isArray(sb.allowTools) && sb.allowTools.every((/** @type unknown */ r) => typeof r === "string"))) errors.push("sandbox.allowTools must be an array of rules");
94
+ }
95
+ }
96
+ const expect = task.expect ?? {};
97
+ for (const key of ["toolCalls", "forbidden"]) {
98
+ if (expect[key] !== undefined && !Array.isArray(expect[key])) errors.push(`expect.${key} must be an array`);
99
+ for (const [i, c] of (Array.isArray(expect[key]) ? expect[key] : []).entries()) if (typeof c?.tool !== "string") errors.push(`expect.${key}[${i}].tool is required`);
100
+ }
101
+ const fa = expect.finalAnswer;
102
+ if (fa !== undefined) {
103
+ for (const key of ["contains", "notContains", "matches"]) if (fa[key] !== undefined && !Array.isArray(fa[key])) errors.push(`expect.finalAnswer.${key} must be an array`);
104
+ for (const re of fa.matches ?? []) {
105
+ try {
106
+ new RegExp(re);
107
+ } catch {
108
+ errors.push(`expect.finalAnswer.matches: ${JSON.stringify(re)} is not a regular expression`);
109
+ }
110
+ }
111
+ }
112
+ if (errors.length > 0) return { ok: false, errors };
113
+ return {
114
+ ok: true,
115
+ task: {
116
+ ...task,
117
+ synthetic: task.synthetic === true,
118
+ model: task.model ?? "sonnet",
119
+ maxTurns: task.maxTurns ?? DEFAULT_MAX_TURNS,
120
+ timeoutMs: task.timeoutMs ?? DEFAULT_TASK_TIMEOUT_MS,
121
+ agentRoot: { files: { ...(task.agentRoot?.files ?? {}) } },
122
+ sandbox: { permissions: sb?.permissions ?? "scoped", allowTools: [...(sb?.allowTools ?? [])] },
123
+ mcp: { server: mcp.server, tools: mcp.tools, replies: mcp.replies ?? [] },
124
+ expect: { toolCalls: expect.toolCalls ?? [], forbidden: expect.forbidden ?? [], finalAnswer: expect.finalAnswer ?? {}, rubric: expect.rubric ?? null, reference: expect.reference ?? null },
125
+ },
126
+ };
127
+ }
128
+
129
+ /**
130
+ * The MCP tool definitions a task's server lists: named org tools take their
131
+ * real schema from lib/org/tool-surface.mjs; inline definitions pass through.
132
+ * @param {{mcp:{tools:Array<string|{name:string, description?:string, inputSchema?:object}>}}} task
133
+ * @returns {Array<{name:string, description:string, inputSchema:object, readOnly:boolean}>}
134
+ */
135
+ export function resolveToolDefs(task) {
136
+ return task.mcp.tools.map((t) => {
137
+ if (typeof t === "object" && t) return { name: t.name, description: t.description ?? "", inputSchema: t.inputSchema ?? { type: "object" }, readOnly: false };
138
+ const def = /** @type any */ (orgToolDef(t));
139
+ if (!def) return { name: t, description: "", inputSchema: { type: "object" }, readOnly: false };
140
+ return { name: t, description: def.description ?? "", inputSchema: def.input_schema ?? def.inputSchema ?? { type: "object" }, readOnly: def.access === "read" };
141
+ });
142
+ }
143
+
144
+ /**
145
+ * Argument keys that pick WHICH record a call reads (ids, channels, threads,
146
+ * deals, invoices …), as opposed to how (paging, filters, free text).
147
+ */
148
+ export const IDENTIFYING_KEY_RE = /^(?:id|ids|ts|thread_ts|number|slug|channel|thread|deal|invoice|bill|person|org|file|folder|doc|mailbox|message|task|item|event|decision|board|contact)$|[a-z0-9]Ids?$|_ids?$/;
149
+
150
+ /**
151
+ * The identifying arguments of a call's input (top-level keys only). Pure.
152
+ * @param {unknown} input
153
+ * @returns {Record<string, unknown>|undefined} undefined when the input is not an object
154
+ */
155
+ export function identifyingArgs(input) {
156
+ if (!input || typeof input !== "object" || Array.isArray(input)) return undefined;
157
+ return Object.fromEntries(Object.entries(input).filter(([k]) => IDENTIFYING_KEY_RE.test(k)));
158
+ }
159
+
160
+ /**
161
+ * Pick the reply for a call. A reply matches EXACTLY when its `input` matcher
162
+ * is contained in the call's arguments (and so is its `recordedInput`, when an
163
+ * extracted reply keeps one), and APPROXIMATELY when only the identifying
164
+ * arguments agree — another engine asked for the same record with different
165
+ * paging, filters or wording. Preference: unused exact, used exact (a repeated
166
+ * read), unused approximate, used approximate; among used replies the last
167
+ * wins. A call whose identifying arguments differ gets nothing. Pure over `used`.
168
+ * @param {Array<{tool:string, input?:any, recordedInput?:any, result:any, isError?:boolean}>} replies
169
+ * @param {string} tool bare tool name
170
+ * @param {any} args
171
+ * @param {Set<number>} used
172
+ * @returns {{index:number, match:'exact'|'approximate'}|null}
173
+ */
174
+ export function pickReply(replies, tool, args, used) {
175
+ /** @type {{index:number, match:'exact'|'approximate', rank:number}|null} */
176
+ let best = null;
177
+ for (const [i, r] of replies.entries()) {
178
+ if (r.tool !== tool) continue;
179
+ /** @type {'exact'|'approximate'} */
180
+ let match;
181
+ if (partialMatch(r.input, args)) match = r.recordedInput === undefined || partialMatch(r.recordedInput, args) ? "exact" : "approximate";
182
+ else if (partialMatch(identifyingArgs(r.input), args)) match = "approximate";
183
+ else continue;
184
+ const rank = (match === "exact" ? 0 : 2) + (used.has(i) ? 1 : 0);
185
+ if (!best || rank < best.rank || (rank === best.rank && used.has(i))) best = { index: i, match, rank };
186
+ }
187
+ return best && { index: best.index, match: best.match };
188
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * scripts/eval/replay/lib/judge.mjs — the optional rubric judge.
3
+ *
4
+ * One request per graded answer to the cohort-llm gateway, on the pinned judge
5
+ * tier (config.mjs JUDGE), through the engine's own OpenAI wire client — the
6
+ * same contract, auth and cost headers as every engine request. Skipped (not
7
+ * failed) when the task has no rubric or reference, or when no gateway URL or
8
+ * token is configured. The prompt below is Cohort's own.
9
+ *
10
+ * @module scripts/eval/replay/lib/judge
11
+ */
12
+
13
+ import { createModelCaller } from "../../../../lib/engine/wire/index.mjs";
14
+ import { blockText } from "./transcript.mjs";
15
+ import { JUDGE } from "./config.mjs";
16
+
17
+ export const JUDGE_SYSTEM = [
18
+ "You grade whether a colleague's final answer accomplished a work task.",
19
+ "You are given the task, a rubric, sometimes a reference answer from an earlier run, and the candidate answer.",
20
+ "Judge substance, not wording or length: the candidate passes when it does what the rubric asks and claims nothing the task contradicts.",
21
+ "A reference answer shows one acceptable outcome, not the only one.",
22
+ 'Reply with one JSON object and nothing else: {"pass": true or false, "score": a number from 0 to 1, "reason": "one sentence"}.',
23
+ ].join("\n");
24
+
25
+ /**
26
+ * @param {any} task @param {string} candidate
27
+ * @returns {{system:string, messages:Array<{role:'user', content:string}>}}
28
+ */
29
+ export function buildJudgeRequest(task, candidate) {
30
+ const parts = [`Task:\n${task.prompt}`];
31
+ if (task.expect?.rubric) parts.push(`Rubric:\n${task.expect.rubric}`);
32
+ if (task.expect?.reference) parts.push(`Reference answer:\n${task.expect.reference}`);
33
+ parts.push(`Candidate answer:\n${candidate || "(empty)"}`);
34
+ return { system: JUDGE_SYSTEM, messages: [{ role: "user", content: parts.join("\n\n") }] };
35
+ }
36
+
37
+ /**
38
+ * @param {string} text
39
+ * @returns {{verdict:'pass'|'fail'|'error', score:number|null, reason:string}}
40
+ */
41
+ export function parseJudgeVerdict(text) {
42
+ const s = String(text ?? "");
43
+ const start = s.indexOf("{");
44
+ const end = s.lastIndexOf("}");
45
+ if (start < 0 || end <= start) return { verdict: "error", score: null, reason: "the judge did not answer with JSON" };
46
+ try {
47
+ const o = JSON.parse(s.slice(start, end + 1));
48
+ if (typeof o.pass !== "boolean") return { verdict: "error", score: null, reason: "the judge's JSON has no boolean pass" };
49
+ const score = typeof o.score === "number" && Number.isFinite(o.score) ? Math.min(1, Math.max(0, o.score)) : null;
50
+ return { verdict: o.pass ? "pass" : "fail", score, reason: typeof o.reason === "string" ? o.reason.slice(0, 500) : "" };
51
+ } catch {
52
+ return { verdict: "error", score: null, reason: "the judge's JSON did not parse" };
53
+ }
54
+ }
55
+
56
+ /**
57
+ * @param {any} task
58
+ * @param {string} candidate
59
+ * @param {{baseUrl:string|null, token:string|null, tier?:string, fetchImpl?:typeof fetch, required?:boolean}} o
60
+ * required: the run asked for the judge, so a missing gateway is an error, not a skip
61
+ * @returns {Promise<{verdict:'pass'|'fail'|'skipped'|'error', score:number|null, reason:string, tier:string}>}
62
+ */
63
+ export async function judgeTask(task, candidate, o) {
64
+ const tier = o.tier ?? JUDGE.tier;
65
+ if (!task.expect?.rubric && !task.expect?.reference) return { verdict: "skipped", score: null, reason: "the task has no rubric or reference", tier };
66
+ if (!o.baseUrl || !o.token) return { verdict: o.required ? "error" : "skipped", score: null, reason: "no gateway URL or token for the judge", tier };
67
+ const call = createModelCaller({ wire: JUDGE.wire, baseUrl: o.baseUrl, token: o.token, model: tier, maxTokens: JUDGE.maxTokens, headers: { "x-cohort-surface": "eval-judge" }, fetchImpl: o.fetchImpl });
68
+ const req = buildJudgeRequest(task, candidate);
69
+ const r = await call({ system: req.system, messages: req.messages, tools: [] });
70
+ if (!r.ok) return { verdict: "error", score: null, reason: `judge request failed: ${r.error?.code ?? "unknown"}`, tier };
71
+ return { ...parseJudgeVerdict(blockText(r.value.message.content)), tier };
72
+ }
@@ -0,0 +1,136 @@
1
+ /**
2
+ * scripts/eval/replay/lib/redact.mjs — scrub a recorded session before it
3
+ * becomes a replay fixture. Pure.
4
+ *
5
+ * Simple patterns, applied in order: credentials first (so a token inside an
6
+ * email-looking string goes), then email addresses, phone numbers and chat
7
+ * ids, users' home directories in paths, then names — the string values of
8
+ * person-shaped JSON keys (name, displayName, author, from, to …, both in
9
+ * objects and in JSON text), the caller's list, the name parts of every email
10
+ * address seen, and a capitalised name after a greeting or sign-off. Known
11
+ * gaps: a name in free prose that is none of those, and JSON that is itself
12
+ * escaped inside a string (\"name\"). Redaction is
13
+ * deliberately greedy; a fixture that reads a little odd is fine, a leaked
14
+ * address is not. It is not a guarantee: fixtures stay private regardless.
15
+ *
16
+ * @module scripts/eval/replay/lib/redact
17
+ */
18
+
19
+ /** @type {ReadonlyArray<{kind:string, re:RegExp, to:string}>} */
20
+ export const SECRET_PATTERNS = Object.freeze([
21
+ { kind: "anthropic-key", re: /sk-ant-[A-Za-z0-9_-]{8,}/g, to: "[secret]" },
22
+ { kind: "seat-token", re: /\b(?:cst|nlk)_[A-Za-z0-9_-]{6,}/g, to: "[secret]" },
23
+ { kind: "slack-token", re: /\bxox[abposr]-[A-Za-z0-9-]{8,}/g, to: "[secret]" },
24
+ { kind: "github-token", re: /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})/g, to: "[secret]" },
25
+ { kind: "aws-key", re: /\bAKIA[0-9A-Z]{16}\b/g, to: "[secret]" },
26
+ { kind: "jwt", re: /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g, to: "[secret]" },
27
+ { kind: "bearer", re: /\bBearer\s+[A-Za-z0-9._~+/=-]{8,}/gi, to: "Bearer [secret]" },
28
+ { kind: "api-key", re: /\b(?:sk|pk|rk)-[A-Za-z0-9_-]{16,}/g, to: "[secret]" },
29
+ { kind: "long-hex", re: /\b[a-f0-9]{32,}\b/gi, to: "[secret]" },
30
+ ]);
31
+
32
+ /** @type {ReadonlyArray<{kind:string, re:RegExp, to:string}>} */
33
+ export const CONTACT_PATTERNS = Object.freeze([
34
+ { kind: "email", re: /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, to: "[email]" },
35
+ { kind: "phone", re: /(?<![\w+])\+\d[\d\s().-]{7,}\d/g, to: "[phone]" },
36
+ { kind: "phone", re: /\(\d{3}\)\s?\d{3}[\s.-]\d{4}\b/g, to: "[phone]" },
37
+ { kind: "chat-id", re: /\b[CUDGW](?=[A-Z0-9]*\d)[A-Z0-9]{8,11}\b/g, to: "[chat-id]" },
38
+ ]);
39
+
40
+ /** A user's directory in a filesystem path: /Users/<x>/ and /home/<x>/. */
41
+ export const HOME_PATH_RE = /(\/(?:Users|home)\/)(?!\[user\])[^/\s"'`]+/g;
42
+
43
+ /** JSON keys whose string values are people: name, displayName, author, from, to … */
44
+ export const NAME_KEY_RE = /^(?:[A-Za-z0-9]+_)?(?:name|displayName|fullName|firstName|lastName|givenName|familyName|userName|username|author|sender|from|to|cc|bcc|assignee|owner|realName)$/i;
45
+ const NAME_KEY_IN_TEXT = /("((?:[A-Za-z0-9]+_)?(?:name|displayName|fullName|firstName|lastName|givenName|familyName|userName|username|author|sender|from|to|cc|bcc|assignee|owner|realName))")(\s*:\s*)"(?:[^"\\\n]|\\.)*"/gi;
46
+
47
+ const GREETING =/\b(Hi|Hello|Hey|Dear|Thanks|Thank you|Cheers|Regards|Best|Morning|Afternoon|Evening)(,?[ \t]+)([A-Z][a-z'’-]+(?:[ \t][A-Z][a-z'’-]+)?)/g;
48
+ const MENTION = /(^|[\s(])@[A-Za-z0-9._-]{2,}/g;
49
+
50
+ /** @param {string} s */
51
+ function escapeRe(s) {
52
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
53
+ }
54
+
55
+ /**
56
+ * Name parts of the email addresses in a text ("jane.doe@x" → jane, doe).
57
+ * @param {string} text
58
+ */
59
+ export function namesFromEmails(text) {
60
+ const out = new Set();
61
+ for (const m of String(text).matchAll(/([A-Za-z0-9._%+-]+)@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g)) {
62
+ for (const part of m[1].split(/[._%+-]+/)) if (/^[A-Za-z]{3,}$/.test(part)) out.add(part);
63
+ }
64
+ return [...out];
65
+ }
66
+
67
+ /**
68
+ * @param {string} text
69
+ * @param {{names?:string[]}} [o]
70
+ * @returns {{text:string, counts:Record<string, number>}}
71
+ */
72
+ export function redactText(text, o = {}) {
73
+ /** @type {Record<string, number>} */
74
+ const counts = {};
75
+ const bump = (/** @type string */ kind) => (counts[kind] = (counts[kind] ?? 0) + 1);
76
+ let s = String(text);
77
+ const names = new Set([...(o.names ?? []), ...namesFromEmails(s)].map((n) => String(n).trim()).filter((n) => n.length >= 2));
78
+ for (const p of [...SECRET_PATTERNS, ...CONTACT_PATTERNS]) {
79
+ s = s.replace(p.re, () => {
80
+ bump(p.kind);
81
+ return p.to;
82
+ });
83
+ }
84
+ s = s.replace(HOME_PATH_RE, (_m, lead) => {
85
+ bump("home-path");
86
+ return `${lead}[user]`;
87
+ });
88
+ s = s.replace(NAME_KEY_IN_TEXT, (m, key, _bare, sep) => {
89
+ if (m.endsWith('"[name]"')) return m;
90
+ bump("name");
91
+ return `${key}${sep}"[name]"`;
92
+ });
93
+ const sorted = [...names].sort((a, b) => b.length - a.length);
94
+ for (const name of sorted) {
95
+ const re = new RegExp(`(?<![A-Za-z0-9])${escapeRe(name)}(?![A-Za-z0-9])`, "gi");
96
+ s = s.replace(re, () => {
97
+ bump("name");
98
+ return "[name]";
99
+ });
100
+ }
101
+ s = s.replace(GREETING, (_m, greet, sep) => {
102
+ bump("name");
103
+ return `${greet}${sep}[name]`;
104
+ });
105
+ s = s.replace(MENTION, (_m, lead) => {
106
+ bump("handle");
107
+ return `${lead}@[handle]`;
108
+ });
109
+ return { text: s, counts };
110
+ }
111
+
112
+ /**
113
+ * Redact every string inside a JSON value (keys are kept).
114
+ * @param {unknown} value
115
+ * @param {{names?:string[]}} [o]
116
+ * @returns {{value:any, counts:Record<string, number>}}
117
+ */
118
+ export function redactDeep(value, o = {}) {
119
+ /** @type {Record<string, number>} */
120
+ const counts = {};
121
+ const walk = (/** @type any */ v, /** @type string */ key = "") => {
122
+ if (typeof v === "string") {
123
+ if (NAME_KEY_RE.test(key) && v.trim() !== "") {
124
+ counts.name = (counts.name ?? 0) + 1;
125
+ return "[name]";
126
+ }
127
+ const r = redactText(v, o);
128
+ for (const [k, n] of Object.entries(r.counts)) counts[k] = (counts[k] ?? 0) + n;
129
+ return r.text;
130
+ }
131
+ if (Array.isArray(v)) return v.map((x) => walk(x, key));
132
+ if (v && typeof v === "object") return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x, k)]));
133
+ return v;
134
+ };
135
+ return { value: walk(value), counts };
136
+ }
@@ -0,0 +1,170 @@
1
+ /**
2
+ * scripts/eval/replay/lib/sandbox.mjs — what a replay sandbox holds and what
3
+ * it may do.
4
+ *
5
+ * A seat's baseline ran with its own instruction and behaviour surface, so a
6
+ * replay copies that surface into the sandbox agent root: CLAUDE.md, the
7
+ * project .claude/ (settings and their hooks, skills, commands, agents),
8
+ * config/agent.json, agents/, skills/, scripts/hooks/ (project hooks run as
9
+ * `./scripts/hooks/…`) and policies/ (the send gate reads them). Never copied:
10
+ * .env files, state/, logs/, memory/, sessions and transcripts, node_modules,
11
+ * .git, settings.local.json, key and credential files, symlinks, and files over
12
+ * 1 MB. The seat's absolute path inside a copied text file becomes the sandbox
13
+ * agent root, and `env` / `apiKeyHelper` are removed from copied settings.
14
+ *
15
+ * The permission posture is scoped, not bypass: dontAsk with the read tools and
16
+ * the replayed org server allowed, and the tools that reach past the stub
17
+ * (Bash, file writes, the web, spawned work) denied. A fixture may open more
18
+ * with `sandbox.allowTools`; `sandbox.permissions: "bypass"` is honoured only
19
+ * when the run passes --allow-bypass.
20
+ *
21
+ * Extracted fixtures carry `{{AGENT_ROOT}}` and `{{HOME}}` where the recording
22
+ * named the seat's root or home; a run fills them with the sandbox's own.
23
+ *
24
+ * Pure except `copySeat` and `seatMcpServerNames`, which read the seat and write the sandbox.
25
+ *
26
+ * @module scripts/eval/replay/lib/sandbox
27
+ */
28
+
29
+ import { copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync } from "node:fs";
30
+ import path from "node:path";
31
+
32
+ export const PLACEHOLDERS = Object.freeze({ agentRoot: "{{AGENT_ROOT}}", home: "{{HOME}}" });
33
+
34
+ /** Seat paths copied into the sandbox agent root (files or directories). */
35
+ export const SEAT_INCLUDE = Object.freeze(["CLAUDE.md", "AGENTS.md", ".claude", "config/agent.json", "agents", "skills", "scripts/hooks", "policies"]);
36
+
37
+ const EXCLUDED_DIRS = new Set(["state", "logs", "memory", "sessions", "transcripts", "projects", "node_modules", ".git", "runtime"]);
38
+ const EXCLUDED_FILE = /^\.env(\..*)?$|^settings\.local\.json$|\.(pem|key|p12|pfx|keychain)$|^id_(rsa|ed25519|ecdsa)|secret|credential|token/i;
39
+ const MAX_COPY_BYTES = 1_000_000;
40
+
41
+ /** Read tools every replay may use, plus `mcp__<server>`. */
42
+ export const REPLAY_ALLOWED_TOOLS = Object.freeze(["Read", "Glob", "Grep", "TodoWrite", "Skill", "ToolSearch", "ListMcpResources", "ReadMcpResource"]);
43
+ /** Tools that reach past the replay stub; denied unless a fixture opens one. */
44
+ export const REPLAY_DENIED_TOOLS = Object.freeze(["Bash", "Write", "Edit", "MultiEdit", "NotebookEdit", "WebFetch", "WebSearch", "Task", "Agent", "Workflow", "Monitor", "SendMessage"]);
45
+
46
+ /** Is a seat-relative path (posix separators) excluded from the copy? */
47
+ export function isExcludedSeatPath(/** @type string */ rel) {
48
+ const parts = rel.split("/");
49
+ if (parts.slice(0, -1).some((d) => EXCLUDED_DIRS.has(d))) return true;
50
+ return EXCLUDED_FILE.test(parts.at(-1) ?? "") || EXCLUDED_DIRS.has(parts.at(-1) ?? "");
51
+ }
52
+
53
+ /** @param {string} p */
54
+ function safeRealpath(p) {
55
+ try {
56
+ return realpathSync(p);
57
+ } catch {
58
+ return p;
59
+ }
60
+ }
61
+
62
+ /** Replace every occurrence of each `from` (longest first) in a string. */
63
+ function replaceRoots(/** @type string */ s, /** @type Array<[string, string]> */ pairs) {
64
+ let out = s;
65
+ for (const [from, to] of [...pairs].filter(([f]) => f && f !== "/").sort((a, b) => b[0].length - a[0].length)) out = out.split(from).join(to);
66
+ return out;
67
+ }
68
+
69
+ /**
70
+ * The seat's root and home written as placeholders (extraction). Pure.
71
+ * @param {string} text @param {{agentRoot:string, home?:string|null, realAgentRoot?:string|null}} o
72
+ */
73
+ export function toPlaceholders(text, o) {
74
+ const pairs = /** @type Array<[string,string]> */ ([[o.agentRoot, PLACEHOLDERS.agentRoot]]);
75
+ if (o.realAgentRoot && o.realAgentRoot !== o.agentRoot) pairs.push([o.realAgentRoot, PLACEHOLDERS.agentRoot]);
76
+ if (o.home) pairs.push([o.home, PLACEHOLDERS.home]);
77
+ return replaceRoots(String(text), pairs);
78
+ }
79
+
80
+ /**
81
+ * Placeholders filled with a sandbox's paths, in every string of a JSON value. Pure.
82
+ * @param {unknown} value @param {{agentRoot:string, home:string}} o
83
+ */
84
+ export function fillPlaceholders(value, o) {
85
+ if (typeof value === "string") return value.split(PLACEHOLDERS.agentRoot).join(o.agentRoot).split(PLACEHOLDERS.home).join(o.home);
86
+ if (Array.isArray(value)) return value.map((v) => fillPlaceholders(v, o));
87
+ if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, fillPlaceholders(v, o)]));
88
+ return value;
89
+ }
90
+
91
+ /**
92
+ * The permission flags for one replay. Pure.
93
+ * @param {{mcp:{server:string}, sandbox?:{permissions?:string, allowTools?:string[]}}} task
94
+ * @param {{allowBypass?:boolean}} [o]
95
+ * @returns {{posture:'scoped'|'bypass', note:string|null, args:string[]}}
96
+ */
97
+ export function replayPermissions(task, o = {}) {
98
+ const sb = task.sandbox ?? {};
99
+ if (sb.permissions === "bypass" && o.allowBypass) return { posture: "bypass", note: "the fixture opted in and the run passed --allow-bypass", args: ["--dangerously-skip-permissions"] };
100
+ const extra = Array.isArray(sb.allowTools) ? sb.allowTools.map(String) : [];
101
+ const opened = new Set(extra.map((r) => r.replace(/\(.*$/s, "")));
102
+ const deny = REPLAY_DENIED_TOOLS.filter((t) => !opened.has(t));
103
+ return {
104
+ posture: "scoped",
105
+ note: sb.permissions === "bypass" ? "the fixture asked for bypass; refused without --allow-bypass" : null,
106
+ args: ["--permission-mode", "dontAsk", "--allowedTools", [...REPLAY_ALLOWED_TOOLS, `mcp__${task.mcp.server}`, ...extra].join(","), ...(deny.length ? ["--disallowedTools", deny.join(",")] : [])],
107
+ };
108
+ }
109
+
110
+ /** The seat's .mcp.json server names, or []. @param {string} seatRoot */
111
+ export function seatMcpServerNames(seatRoot) {
112
+ try {
113
+ return Object.keys(JSON.parse(readFileSync(path.join(seatRoot, ".mcp.json"), "utf8")).mcpServers ?? {});
114
+ } catch {
115
+ return [];
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Copy the seat's instruction and behaviour surface into a sandbox agent root.
121
+ * @param {string} seatRoot
122
+ * @param {string} sandboxAgent
123
+ * @returns {{copied:string[], skipped:string[]}} seat-relative paths
124
+ */
125
+ export function copySeat(seatRoot, sandboxAgent) {
126
+ const root = path.resolve(seatRoot);
127
+ const pairs = /** @type Array<[string,string]> */ ([[root, sandboxAgent], [safeRealpath(root), sandboxAgent]]);
128
+ const copied = [];
129
+ const skipped = [];
130
+ const visit = (/** @type string */ rel) => {
131
+ const abs = path.join(root, rel);
132
+ let st;
133
+ try {
134
+ st = lstatSync(abs);
135
+ } catch {
136
+ return;
137
+ }
138
+ if (st.isSymbolicLink() || isExcludedSeatPath(rel)) return void skipped.push(rel);
139
+ if (st.isDirectory()) {
140
+ for (const name of readdirSync(abs).sort()) visit(`${rel}/${name}`);
141
+ return;
142
+ }
143
+ if (!st.isFile() || st.size > MAX_COPY_BYTES) return void skipped.push(rel);
144
+ const target = path.join(sandboxAgent, rel);
145
+ mkdirSync(path.dirname(target), { recursive: true });
146
+ const buf = readFileSync(abs);
147
+ if (buf.includes(0)) copyFileSync(abs, target);
148
+ else {
149
+ let text = replaceRoots(buf.toString("utf8"), pairs);
150
+ if (/^\.claude\/settings(\.[^/]*)?\.json$/.test(rel)) text = stripSettingsSecrets(text);
151
+ writeFileSync(target, text, { mode: st.mode & 0o777 });
152
+ }
153
+ copied.push(rel);
154
+ };
155
+ for (const inc of SEAT_INCLUDE) if (existsSync(path.join(root, inc))) visit(inc);
156
+ return { copied, skipped };
157
+ }
158
+
159
+ /** A settings file without `env` or `apiKeyHelper` (credentials live there). Pure. */
160
+ export function stripSettingsSecrets(/** @type string */ text) {
161
+ try {
162
+ const o = JSON.parse(text);
163
+ if (!o || typeof o !== "object") return text;
164
+ delete o.env;
165
+ delete o.apiKeyHelper;
166
+ return `${JSON.stringify(o, null, 2)}\n`;
167
+ } catch {
168
+ return text;
169
+ }
170
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * scripts/eval/replay/lib/schema-check.mjs — does a tool call's input satisfy
3
+ * the tool's input schema, strictly? Pure.
4
+ *
5
+ * The engine coerces and repairs inputs before running a tool; the eval must
6
+ * not. This checks the JSON Schema subset tool schemas use — type (or a list
7
+ * of types), required, properties, additionalProperties:false, items, enum,
8
+ * const, anyOf/oneOf — with no coercion: "3" is not a number.
9
+ *
10
+ * @module scripts/eval/replay/lib/schema-check
11
+ */
12
+
13
+ /** @param {unknown} v */
14
+ function typeOf(v) {
15
+ if (v === null) return "null";
16
+ if (Array.isArray(v)) return "array";
17
+ if (typeof v === "number") return Number.isInteger(v) ? "integer" : "number";
18
+ return typeof v;
19
+ }
20
+
21
+ /** @param {string} want @param {string} got */
22
+ const typeMatches = (want, got) => want === got || (want === "number" && got === "integer");
23
+
24
+ /**
25
+ * @param {any} schema
26
+ * @param {unknown} value
27
+ * @param {string} [at]
28
+ * @returns {string[]} errors; empty when valid
29
+ */
30
+ export function checkSchema(schema, value, at = "$") {
31
+ if (!schema || typeof schema !== "object") return [];
32
+ const errors = [];
33
+ const branches = schema.anyOf ?? schema.oneOf;
34
+ if (Array.isArray(branches) && branches.length > 0) {
35
+ if (!branches.some((b) => checkSchema(b, value, at).length === 0)) errors.push(`${at}: matches none of the allowed shapes`);
36
+ }
37
+ if (schema.type !== undefined) {
38
+ const types = Array.isArray(schema.type) ? schema.type : [schema.type];
39
+ const got = typeOf(value);
40
+ if (!types.some((t) => typeMatches(t, got))) {
41
+ errors.push(`${at}: expected ${types.join(" or ")}, got ${got}`);
42
+ return errors;
43
+ }
44
+ }
45
+ if (Array.isArray(schema.enum) && !schema.enum.some((e) => JSON.stringify(e) === JSON.stringify(value))) errors.push(`${at}: not one of ${JSON.stringify(schema.enum)}`);
46
+ if (schema.const !== undefined && JSON.stringify(schema.const) !== JSON.stringify(value)) errors.push(`${at}: must be ${JSON.stringify(schema.const)}`);
47
+ if (typeOf(value) === "object") {
48
+ const obj = /** @type {Record<string, unknown>} */ (value);
49
+ for (const key of Array.isArray(schema.required) ? schema.required : []) {
50
+ if (obj[key] === undefined) errors.push(`${at}.${key}: required`);
51
+ }
52
+ const props = schema.properties && typeof schema.properties === "object" ? schema.properties : {};
53
+ for (const [key, v] of Object.entries(obj)) {
54
+ if (Object.hasOwn(props, key)) errors.push(...checkSchema(props[key], v, `${at}.${key}`));
55
+ else if (schema.additionalProperties === false) errors.push(`${at}.${key}: not allowed`);
56
+ else if (schema.additionalProperties && typeof schema.additionalProperties === "object") errors.push(...checkSchema(schema.additionalProperties, v, `${at}.${key}`));
57
+ }
58
+ }
59
+ if (Array.isArray(value) && schema.items && typeof schema.items === "object") {
60
+ value.forEach((item, i) => errors.push(...checkSchema(schema.items, item, `${at}[${i}]`)));
61
+ }
62
+ return errors;
63
+ }