@alexkroman1/aai-cli 0.17.0 → 0.18.0

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 (438) hide show
  1. package/dist/{_agent-BopNO5Bq.mjs → _agent-BN21AHsJ.mjs} +4 -4
  2. package/dist/_api-client-Uljj0CQi.mjs +312 -0
  3. package/dist/_api-client.d.ts +69 -1
  4. package/dist/{_bundler-DCuNHjDF.mjs → _bundler-DvZDEu2p.mjs} +67 -7
  5. package/dist/_bundler.d.ts +15 -0
  6. package/dist/_cli-common.d.ts +42 -0
  7. package/dist/{client-bundler-DE-AGdm7.mjs → _client-plugins-kR43nZnb.mjs} +30 -132
  8. package/dist/_client-plugins.d.ts +16 -0
  9. package/dist/{_config-mq1I5Cva.mjs → _config-Dlh8PRRp.mjs} +2 -20
  10. package/dist/_config.d.ts +0 -8
  11. package/dist/{_dev-server-D6VSQbYW.mjs → _dev-server-C_zidzWj.mjs} +15 -10
  12. package/dist/_dev-session-ticket.d.ts +3 -0
  13. package/dist/_dev-tunnel.d.ts +20 -2
  14. package/dist/_dotenv-file.d.ts +6 -0
  15. package/dist/_init.d.ts +2 -11
  16. package/dist/_output.d.ts +47 -20
  17. package/dist/_safe-write.d.ts +38 -0
  18. package/dist/{_server-common-CVXIeWrY.mjs → _server-common-C6j67AcZ.mjs} +37 -2
  19. package/dist/_server-common.d.ts +16 -0
  20. package/dist/{_slug-api-BnmTHtjd.mjs → _slug-api-B9cptz7Q.mjs} +3 -2
  21. package/dist/_start-affinity.d.ts +70 -0
  22. package/dist/_start-log.d.ts +39 -0
  23. package/dist/_start-router.d.ts +85 -0
  24. package/dist/_start-run.d.ts +101 -0
  25. package/dist/_start-worker.d.ts +61 -0
  26. package/dist/_start-workers-BNdOnTal.mjs +529 -0
  27. package/dist/_start-workers.d.ts +262 -0
  28. package/dist/_studio-zympBLlD.mjs +140 -0
  29. package/dist/_studio.d.ts +14 -0
  30. package/dist/_target-bundle.d.ts +4 -0
  31. package/dist/{_templates-BVMVsQh0.mjs → _templates-ChZuhW66.mjs} +110 -8
  32. package/dist/_templates.d.ts +20 -1
  33. package/dist/{_typecheck-gate-CcX2gLJZ.mjs → _typecheck-gate-BNF5cboL.mjs} +2 -2
  34. package/dist/_ui-C0RufoYZ.mjs +147 -0
  35. package/dist/_ui.d.ts +14 -3
  36. package/dist/_utils-ChU85MEg.mjs +486 -0
  37. package/dist/_utils.d.ts +28 -0
  38. package/dist/_vendor-openers.d.ts +87 -0
  39. package/dist/{_vitest-runner-CKI8_K1b.mjs → _vitest-runner-tzyto9IU.mjs} +7 -3
  40. package/dist/_vitest-runner.d.ts +8 -1
  41. package/dist/{build-BnXLgfk-.mjs → build-BHgd-QYb.mjs} +13 -10
  42. package/dist/build.d.ts +21 -0
  43. package/dist/cli-workflow.d.ts +7 -0
  44. package/dist/cli.d.ts +16 -0
  45. package/dist/cli.mjs +243 -70
  46. package/dist/client-bundler-CImhqcp2.mjs +133 -0
  47. package/dist/client-bundler.mjs +1 -1
  48. package/dist/{console-tVBjfKyR.mjs → console-DwycgRkC.mjs} +4 -5
  49. package/dist/delete-ZcA3J_3o.mjs +75 -0
  50. package/dist/delete.d.ts +10 -1
  51. package/dist/{deploy-eWDoiwvn.mjs → deploy-CkfkiZE3.mjs} +9 -9
  52. package/dist/{dev-CT_QHHZL.mjs → dev-BX9g6qcf.mjs} +81 -18
  53. package/dist/{eval-Dl8o91yC.mjs → eval-CUKvfxRq.mjs} +4 -4
  54. package/dist/{init-CidslZZz.mjs → init-B9Uw76-_.mjs} +62 -32
  55. package/dist/{login-oJdBWu2B.mjs → login-Ct73CqU1.mjs} +30 -6
  56. package/dist/login.d.ts +2 -0
  57. package/dist/{logs-CkmFdSbr.mjs → logs-BBsUy96d.mjs} +59 -14
  58. package/dist/logs.d.ts +4 -1
  59. package/dist/project-config.mjs +1 -1
  60. package/dist/scaffold/CLAUDE.md +72 -55
  61. package/dist/scaffold/agent-guide/AGENT-API.md +44 -34
  62. package/dist/scaffold/agent-guide/HOSTING.md +11 -0
  63. package/dist/scaffold/agent-guide/TESTING-EVALS.md +105 -36
  64. package/dist/scaffold/agent-guide/TOOLS.md +189 -33
  65. package/dist/scaffold/agent-guide/UI.md +111 -39
  66. package/dist/scaffold/agent-guide/WORKFLOWS.md +234 -160
  67. package/dist/scaffold/package.json +4 -4
  68. package/dist/{secret-DPdPEet2.mjs → secret-CKjHRrVX.mjs} +112 -35
  69. package/dist/start.d.ts +14 -14
  70. package/dist/start.mjs +840 -40
  71. package/dist/{studio-COjK25Rl.mjs → studio-U6DvBNAx.mjs} +123 -35
  72. package/dist/studio.d.ts +1 -0
  73. package/dist/templates/applicant-screening-agent/agent.eval.test.ts +23 -52
  74. package/dist/templates/applicant-screening-agent/agent.test.ts +821 -826
  75. package/dist/templates/applicant-screening-agent/agent.ts +1 -6
  76. package/dist/templates/applicant-screening-agent/client.tsx +1 -19
  77. package/dist/templates/applicant-screening-agent/shared.ts +8 -18
  78. package/dist/templates/applicant-screening-agent/tools/candidate_details.ts +24 -27
  79. package/dist/templates/applicant-screening-agent/tools/proceed_to_emails.ts +75 -82
  80. package/dist/templates/applicant-screening-agent/tools/read_email.ts +24 -24
  81. package/dist/templates/applicant-screening-agent/tools/rescore_with_feedback.ts +92 -99
  82. package/dist/templates/applicant-screening-agent/tools/screen_candidates.ts +72 -83
  83. package/dist/templates/applicant-screening-agent/tools/screening_status.ts +21 -29
  84. package/dist/templates/call-audit-workflow/agent.eval.test.ts +14 -19
  85. package/dist/templates/call-audit-workflow/agent.test.ts +275 -169
  86. package/dist/templates/call-audit-workflow/agent.ts +12 -30
  87. package/dist/templates/call-audit-workflow/client.tsx +9 -27
  88. package/dist/templates/call-audit-workflow/guards.test.ts +24 -71
  89. package/dist/templates/call-audit-workflow/workflows/audit.ts +24 -52
  90. package/dist/templates/call-audit-workflow/workflows/ingest.ts +32 -59
  91. package/dist/templates/call-audit-workflow/workflows/media.ts +4 -44
  92. package/dist/templates/call-audit-workflow/workflows/summarize.ts +72 -107
  93. package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
  94. package/dist/templates/code-interpreter-agent/agent.test.ts +4 -17
  95. package/dist/templates/code-interpreter-agent/agent.ts +1 -1
  96. package/dist/templates/coding-agent/agent.test.ts +17 -12
  97. package/dist/templates/coding-agent/agent.ts +1 -1
  98. package/dist/templates/custom-pipeline-agent/agent.test.ts +6 -14
  99. package/dist/templates/custom-pipeline-agent/agent.ts +1 -1
  100. package/dist/templates/custom-pipeline-agent/modes.test.ts +0 -1
  101. package/dist/templates/document-redline-workflow/agent.test.ts +88 -221
  102. package/dist/templates/document-redline-workflow/agent.ts +22 -32
  103. package/dist/templates/document-redline-workflow/client.tsx +46 -88
  104. package/dist/templates/document-redline-workflow/workflows/prompts.ts +0 -3
  105. package/dist/templates/document-redline-workflow/workflows/redline.ts +33 -50
  106. package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +22 -71
  107. package/dist/templates/emergency-dispatch-agent/agent.test.ts +466 -495
  108. package/dist/templates/emergency-dispatch-agent/agent.ts +27 -43
  109. package/dist/templates/emergency-dispatch-agent/client.tsx +85 -119
  110. package/dist/templates/emergency-dispatch-agent/shared.ts +51 -88
  111. package/dist/templates/emergency-dispatch-agent/tools/incident_add_note.ts +11 -17
  112. package/dist/templates/emergency-dispatch-agent/tools/incident_create.ts +21 -30
  113. package/dist/templates/emergency-dispatch-agent/tools/incident_escalate.ts +60 -63
  114. package/dist/templates/emergency-dispatch-agent/tools/incident_get.ts +6 -15
  115. package/dist/templates/emergency-dispatch-agent/tools/incident_triage.ts +40 -53
  116. package/dist/templates/emergency-dispatch-agent/tools/incident_update_status.ts +41 -47
  117. package/dist/templates/emergency-dispatch-agent/tools/ops_dashboard.ts +2 -2
  118. package/dist/templates/emergency-dispatch-agent/tools/ops_protocols.ts +1 -1
  119. package/dist/templates/emergency-dispatch-agent/tools/ops_run_scenario.ts +13 -10
  120. package/dist/templates/emergency-dispatch-agent/tools/resources_dispatch.ts +42 -51
  121. package/dist/templates/emergency-dispatch-agent/tools/resources_update_status.ts +40 -41
  122. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +14 -42
  123. package/dist/templates/entertainment-picks-agent/agent.test.ts +174 -221
  124. package/dist/templates/entertainment-picks-agent/agent.ts +1 -6
  125. package/dist/templates/entertainment-picks-agent/client.tsx +1 -12
  126. package/dist/templates/entertainment-picks-agent/shared.ts +12 -6
  127. package/dist/templates/entertainment-picks-agent/tools/recommend.ts +2 -2
  128. package/dist/templates/entertainment-picks-agent/tools/revisit.ts +1 -0
  129. package/dist/templates/executive-inbox-agent/agent.eval.test.ts +15 -22
  130. package/dist/templates/executive-inbox-agent/agent.test.ts +515 -527
  131. package/dist/templates/executive-inbox-agent/agent.ts +4 -8
  132. package/dist/templates/executive-inbox-agent/calendar.test.ts +23 -22
  133. package/dist/templates/executive-inbox-agent/client.tsx +1 -23
  134. package/dist/templates/executive-inbox-agent/review.ts +125 -113
  135. package/dist/templates/executive-inbox-agent/shared.ts +3 -0
  136. package/dist/templates/executive-inbox-agent/tools/ask_question.ts +6 -6
  137. package/dist/templates/executive-inbox-agent/tools/draft_reply.ts +16 -18
  138. package/dist/templates/executive-inbox-agent/tools/inbox_status.ts +1 -0
  139. package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +20 -20
  140. package/dist/templates/executive-inbox-agent/tools/new_email.ts +17 -21
  141. package/dist/templates/executive-inbox-agent/tools/open_email.ts +72 -74
  142. package/dist/templates/executive-inbox-agent/tools/review_memory.ts +1 -0
  143. package/dist/templates/executive-inbox-agent/tools/send_calendar_invite.ts +19 -20
  144. package/dist/templates/executive-inbox-agent/tools/triage_inbox.ts +53 -50
  145. package/dist/templates/front-desk-agent/agent.eval.test.ts +22 -14
  146. package/dist/templates/front-desk-agent/agent.test.ts +139 -123
  147. package/dist/templates/front-desk-agent/agent.ts +4 -7
  148. package/dist/templates/front-desk-agent/shared.ts +88 -74
  149. package/dist/templates/front-door-agent/agent.eval.test.ts +61 -0
  150. package/dist/templates/front-door-agent/agent.test.ts +393 -0
  151. package/dist/templates/front-door-agent/agent.ts +35 -0
  152. package/dist/templates/front-door-agent/client.tsx +250 -0
  153. package/dist/templates/front-door-agent/routes.ts +91 -0
  154. package/dist/templates/front-door-agent/shared.ts +35 -0
  155. package/dist/templates/front-door-agent/system-prompt.md +12 -0
  156. package/dist/templates/front-door-agent/tools/leave_message.ts +39 -0
  157. package/dist/templates/front-door-agent/tools/link_phone.ts +49 -0
  158. package/dist/templates/front-door-agent/workflows/announce.ts +38 -0
  159. package/dist/templates/front-door-agent/workflows/digest.ts +53 -0
  160. package/dist/templates/front-door-agent/workflows/pair.ts +28 -0
  161. package/dist/templates/home-assistant-agent/agent.eval.test.ts +5 -9
  162. package/dist/templates/home-assistant-agent/agent.test.ts +513 -399
  163. package/dist/templates/home-assistant-agent/agent.ts +8 -5
  164. package/dist/templates/home-assistant-agent/client.tsx +48 -9
  165. package/dist/templates/home-assistant-agent/tools/cancel_reminders.ts +1 -0
  166. package/dist/templates/home-assistant-agent/tools/remind_me.ts +2 -1
  167. package/dist/templates/hotel-reception-agent/agent.eval.test.ts +27 -52
  168. package/dist/templates/hotel-reception-agent/agent.test.ts +980 -964
  169. package/dist/templates/hotel-reception-agent/agent.ts +8 -21
  170. package/dist/templates/hotel-reception-agent/booking.ts +2 -2
  171. package/dist/templates/hotel-reception-agent/client.tsx +5 -20
  172. package/dist/templates/hotel-reception-agent/concierge.ts +2 -0
  173. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +285 -275
  174. package/dist/templates/hotel-reception-agent/desk.ts +45 -12
  175. package/dist/templates/hotel-reception-agent/hotel.ts +6 -6
  176. package/dist/templates/hotel-reception-agent/restaurant.ts +3 -4
  177. package/dist/templates/hotel-reception-agent/session.ts +14 -30
  178. package/dist/templates/hotel-reception-agent/shared.ts +33 -46
  179. package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +14 -15
  180. package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +1 -0
  181. package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +1 -0
  182. package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -2
  183. package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +13 -10
  184. package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
  185. package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +6 -7
  186. package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +1 -0
  187. package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +5 -4
  188. package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +6 -5
  189. package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +3 -4
  190. package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +4 -4
  191. package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -0
  192. package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
  193. package/dist/templates/hotel-reception-agent/tools/record_followup.ts +1 -0
  194. package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +1 -0
  195. package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
  196. package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -0
  197. package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +1 -0
  198. package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +4 -4
  199. package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -0
  200. package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +4 -3
  201. package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +1 -0
  202. package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +1 -0
  203. package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
  204. package/dist/templates/hotel-reception-agent/tools/set_stay.ts +1 -1
  205. package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +30 -32
  206. package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +22 -25
  207. package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +1 -0
  208. package/dist/templates/hotel-reception-agent/tools/update_card.ts +5 -4
  209. package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +23 -13
  210. package/dist/templates/kitchen-coach-agent/agent.eval.test.ts +38 -0
  211. package/dist/templates/kitchen-coach-agent/agent.test.ts +204 -0
  212. package/dist/templates/kitchen-coach-agent/agent.ts +22 -0
  213. package/dist/templates/kitchen-coach-agent/client.tsx +232 -0
  214. package/dist/templates/kitchen-coach-agent/history.ts +37 -0
  215. package/dist/templates/kitchen-coach-agent/shared.ts +131 -0
  216. package/dist/templates/kitchen-coach-agent/system-prompt.md +17 -0
  217. package/dist/templates/kitchen-coach-agent/tools/get_kitchen.ts +17 -0
  218. package/dist/templates/kitchen-coach-agent/tools/scale_amount.ts +31 -0
  219. package/dist/templates/kitchen-coach-agent/tools/start_timer.ts +24 -0
  220. package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -40
  221. package/dist/templates/link-digest-workflow/agent.test.ts +84 -164
  222. package/dist/templates/link-digest-workflow/agent.ts +27 -42
  223. package/dist/templates/link-digest-workflow/api-client.ts +3 -2
  224. package/dist/templates/link-digest-workflow/client.tsx +5 -5
  225. package/dist/templates/link-digest-workflow/workflows/digest.ts +53 -95
  226. package/dist/templates/medication-safety-agent/agent.eval.test.ts +10 -30
  227. package/dist/templates/medication-safety-agent/agent.test.ts +16 -46
  228. package/dist/templates/medication-safety-agent/agent.ts +1 -4
  229. package/dist/templates/medication-safety-agent/tools/check_drug_interaction.ts +13 -10
  230. package/dist/templates/meeting-recap-agent/agent.eval.test.ts +238 -396
  231. package/dist/templates/meeting-recap-agent/agent.test.ts +414 -1070
  232. package/dist/templates/meeting-recap-agent/agent.ts +26 -67
  233. package/dist/templates/meeting-recap-agent/system-prompt.md +1 -0
  234. package/dist/templates/meeting-recap-agent/tools/keep_transcript.ts +10 -12
  235. package/dist/templates/meeting-recap-agent/tools/request_recap.ts +9 -20
  236. package/dist/templates/meeting-recap-agent/workflows/recap.ts +224 -547
  237. package/dist/templates/outbound-call-agent/agent.eval.test.ts +10 -12
  238. package/dist/templates/outbound-call-agent/agent.test.ts +419 -453
  239. package/dist/templates/outbound-call-agent/agent.ts +57 -62
  240. package/dist/templates/outbound-call-agent/api.ts +53 -68
  241. package/dist/templates/outbound-call-agent/client.tsx +105 -176
  242. package/dist/templates/outbound-call-agent/shared.ts +10 -39
  243. package/dist/templates/outbound-call-agent/system-prompt.md +3 -4
  244. package/dist/templates/outbound-call-agent/tools/end_call.ts +15 -12
  245. package/dist/templates/outbound-call-agent/tools/press_keys.ts +8 -13
  246. package/dist/templates/outbound-call-agent/workflows/call.ts +89 -62
  247. package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +18 -54
  248. package/dist/templates/pizza-ordering-agent/agent.test.ts +205 -244
  249. package/dist/templates/pizza-ordering-agent/agent.ts +5 -12
  250. package/dist/templates/pizza-ordering-agent/client.tsx +3 -14
  251. package/dist/templates/pizza-ordering-agent/shared.ts +31 -36
  252. package/dist/templates/pizza-ordering-agent/tools/add_pizza.ts +1 -0
  253. package/dist/templates/pizza-ordering-agent/tools/place_order.ts +5 -2
  254. package/dist/templates/pizza-ordering-agent/tools/remove_pizza.ts +1 -0
  255. package/dist/templates/pizza-ordering-agent/tools/update_pizza.ts +2 -3
  256. package/dist/templates/pizza-ordering-agent/tools/view_order.ts +7 -3
  257. package/dist/templates/podcast-digest-workflow/agent.test.ts +53 -102
  258. package/dist/templates/podcast-digest-workflow/agent.ts +11 -17
  259. package/dist/templates/podcast-digest-workflow/client.tsx +29 -51
  260. package/dist/templates/podcast-digest-workflow/workflows/digest.ts +24 -26
  261. package/dist/templates/push-to-talk-agent/agent.eval.test.ts +13 -14
  262. package/dist/templates/push-to-talk-agent/agent.test.ts +30 -23
  263. package/dist/templates/push-to-talk-agent/agent.ts +1 -5
  264. package/dist/templates/push-to-talk-agent/client.tsx +1 -11
  265. package/dist/templates/push-to-talk-agent/shared.ts +12 -6
  266. package/dist/templates/push-to-talk-agent/tools/list_notes.ts +1 -0
  267. package/dist/templates/push-to-talk-agent/tools/save_note.ts +1 -0
  268. package/dist/templates/quickstart-agent/agent.eval.test.ts +0 -10
  269. package/dist/templates/quickstart-agent/agent.test.ts +18 -30
  270. package/dist/templates/quickstart-agent/agent.ts +3 -4
  271. package/dist/templates/research-handoff-agent/agent.eval.test.ts +161 -290
  272. package/dist/templates/research-handoff-agent/agent.test.ts +131 -457
  273. package/dist/templates/research-handoff-agent/agent.ts +26 -86
  274. package/dist/templates/research-handoff-agent/system-prompt.md +1 -0
  275. package/dist/templates/research-handoff-agent/tools/file_it_now.ts +8 -21
  276. package/dist/templates/research-handoff-agent/tools/request_research.ts +7 -16
  277. package/dist/templates/research-handoff-agent/workflows/research.ts +88 -40
  278. package/dist/templates/research-planner-agent/agent.eval.test.ts +15 -40
  279. package/dist/templates/research-planner-agent/agent.test.ts +415 -464
  280. package/dist/templates/research-planner-agent/agent.ts +3 -8
  281. package/dist/templates/research-planner-agent/client.tsx +1 -14
  282. package/dist/templates/research-planner-agent/procedure.ts +9 -3
  283. package/dist/templates/research-planner-agent/shared.ts +30 -33
  284. package/dist/templates/research-planner-agent/tools/plan_status.ts +7 -15
  285. package/dist/templates/research-planner-agent/tools/revise_plan.ts +29 -36
  286. package/dist/templates/research-planner-agent/tools/start_plan.ts +25 -39
  287. package/dist/templates/research-planner-agent/tools/work_next_step.ts +25 -42
  288. package/dist/templates/retail-orders-agent/agent.eval.test.ts +14 -34
  289. package/dist/templates/retail-orders-agent/agent.test.ts +1079 -1073
  290. package/dist/templates/retail-orders-agent/agent.ts +25 -78
  291. package/dist/templates/retail-orders-agent/client.tsx +120 -168
  292. package/dist/templates/retail-orders-agent/pending.test.ts +7 -14
  293. package/dist/templates/retail-orders-agent/registry.test.ts +93 -192
  294. package/dist/templates/retail-orders-agent/shared.test.ts +1 -1
  295. package/dist/templates/retail-orders-agent/shared.ts +10 -20
  296. package/dist/templates/retail-orders-agent/store.test.ts +46 -128
  297. package/dist/templates/retail-orders-agent/store.ts +42 -175
  298. package/dist/templates/retail-orders-agent/tools/cancel_change.ts +3 -6
  299. package/dist/templates/retail-orders-agent/tools/cancel_pending_order.ts +3 -4
  300. package/dist/templates/retail-orders-agent/tools/confirm_change.ts +4 -6
  301. package/dist/templates/retail-orders-agent/tools/exchange_delivered_order_items.ts +3 -4
  302. package/dist/templates/retail-orders-agent/tools/find_user_id_by_email.ts +3 -4
  303. package/dist/templates/retail-orders-agent/tools/find_user_id_by_name_zip.ts +3 -4
  304. package/dist/templates/retail-orders-agent/tools/get_item_details.ts +3 -4
  305. package/dist/templates/retail-orders-agent/tools/get_order_details.ts +3 -4
  306. package/dist/templates/retail-orders-agent/tools/get_product_details.ts +3 -4
  307. package/dist/templates/retail-orders-agent/tools/get_user_details.ts +3 -4
  308. package/dist/templates/retail-orders-agent/tools/list_all_product_types.ts +3 -8
  309. package/dist/templates/retail-orders-agent/tools/modify_pending_order_address.ts +3 -4
  310. package/dist/templates/retail-orders-agent/tools/modify_pending_order_items.ts +3 -4
  311. package/dist/templates/retail-orders-agent/tools/modify_pending_order_payment.ts +3 -4
  312. package/dist/templates/retail-orders-agent/tools/modify_user_address.ts +3 -4
  313. package/dist/templates/retail-orders-agent/tools/return_delivered_order_items.ts +3 -4
  314. package/dist/templates/retail-orders-agent/tools/transfer_to_human_agents.ts +3 -4
  315. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +22 -25
  316. package/dist/templates/roadside-assistance-agent/agent.test.ts +453 -490
  317. package/dist/templates/roadside-assistance-agent/agent.ts +28 -60
  318. package/dist/templates/roadside-assistance-agent/call.ts +16 -22
  319. package/dist/templates/roadside-assistance-agent/shared.ts +24 -54
  320. package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +29 -37
  321. package/dist/templates/roadside-assistance-agent/tools/dispatch_truck.ts +44 -70
  322. package/dist/templates/roadside-assistance-agent/tools/job_status.ts +16 -24
  323. package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +39 -51
  324. package/dist/templates/roadside-assistance-agent/tools/report_location.ts +34 -33
  325. package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +18 -39
  326. package/dist/templates/roadside-assistance-agent/yard.test.ts +22 -19
  327. package/dist/templates/roadside-assistance-agent/yard.ts +3 -3
  328. package/dist/templates/spoken-summary-workflow/agent.eval.test.ts +38 -40
  329. package/dist/templates/spoken-summary-workflow/agent.test.ts +129 -279
  330. package/dist/templates/spoken-summary-workflow/agent.ts +15 -40
  331. package/dist/templates/spoken-summary-workflow/client.tsx +13 -25
  332. package/dist/templates/spoken-summary-workflow/workflows/summarize.ts +52 -92
  333. package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +31 -74
  334. package/dist/templates/tabletop-rpg-agent/agent.test.ts +756 -774
  335. package/dist/templates/tabletop-rpg-agent/agent.ts +9 -46
  336. package/dist/templates/tabletop-rpg-agent/client.tsx +13 -21
  337. package/dist/templates/tabletop-rpg-agent/shared.ts +40 -99
  338. package/dist/templates/tabletop-rpg-agent/tools/action_roll.ts +67 -83
  339. package/dist/templates/tabletop-rpg-agent/tools/burn_momentum.ts +65 -88
  340. package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +8 -27
  341. package/dist/templates/tabletop-rpg-agent/tools/setup_character.ts +18 -36
  342. package/dist/templates/tabletop-rpg-agent/tools/update_state.ts +101 -111
  343. package/dist/templates/technical-support-agent/agent.eval.test.ts +31 -72
  344. package/dist/templates/technical-support-agent/agent.test.ts +231 -260
  345. package/dist/templates/technical-support-agent/agent.ts +4 -10
  346. package/dist/templates/technical-support-agent/client.tsx +4 -18
  347. package/dist/templates/technical-support-agent/shared.ts +15 -25
  348. package/dist/templates/technical-support-agent/tools/answer_question.ts +46 -56
  349. package/dist/templates/technical-support-agent/tools/list_topics.ts +1 -0
  350. package/dist/templates/technical-support-agent/tools/log_ticket.ts +8 -5
  351. package/dist/templates/text-adventure-agent/agent.eval.test.ts +37 -126
  352. package/dist/templates/text-adventure-agent/agent.test.ts +197 -368
  353. package/dist/templates/text-adventure-agent/agent.ts +15 -65
  354. package/dist/templates/text-adventure-agent/client.tsx +38 -98
  355. package/dist/templates/text-adventure-agent/shared.ts +31 -143
  356. package/dist/templates/text-adventure-agent/tools/game_state_drop.ts +6 -12
  357. package/dist/templates/text-adventure-agent/tools/game_state_get.ts +4 -11
  358. package/dist/templates/text-adventure-agent/tools/game_state_move.ts +0 -2
  359. package/dist/templates/text-adventure-agent/tools/game_state_restart.ts +1 -3
  360. package/dist/templates/text-adventure-agent/tools/game_state_score.ts +5 -7
  361. package/dist/templates/topic-briefing-agent/agent.eval.test.ts +12 -50
  362. package/dist/templates/topic-briefing-agent/agent.test.ts +478 -476
  363. package/dist/templates/topic-briefing-agent/agent.ts +3 -3
  364. package/dist/templates/topic-briefing-agent/shared.ts +11 -16
  365. package/dist/templates/topic-briefing-agent/slack.ts +12 -4
  366. package/dist/templates/topic-briefing-agent/tools/briefing_so_far.ts +10 -17
  367. package/dist/templates/topic-briefing-agent/tools/research_topic.ts +21 -24
  368. package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +13 -14
  369. package/dist/templates/topic-briefing-agent/tools/verify_claim.ts +16 -13
  370. package/dist/templates/transcription-workflow/agent.test.ts +114 -259
  371. package/dist/templates/transcription-workflow/agent.ts +6 -9
  372. package/dist/templates/transcription-workflow/client.tsx +100 -258
  373. package/dist/templates/transcription-workflow/recover.test.ts +6 -136
  374. package/dist/templates/transcription-workflow/recover.ts +14 -97
  375. package/dist/templates/transcription-workflow/run-panel.tsx +71 -8
  376. package/dist/templates/transcription-workflow/workflows/batch.ts +28 -159
  377. package/dist/templates/transcription-workflow/workflows/normalize.ts +50 -86
  378. package/dist/templates/transcription-workflow/workflows/stream.ts +2 -2
  379. package/dist/templates/transcription-workflow/workflows/transcribe.ts +16 -23
  380. package/dist/templates/travel-concierge-agent/agent.eval.test.ts +7 -25
  381. package/dist/templates/travel-concierge-agent/agent.test.ts +505 -517
  382. package/dist/templates/travel-concierge-agent/agent.ts +22 -46
  383. package/dist/templates/travel-concierge-agent/client.tsx +1 -22
  384. package/dist/templates/travel-concierge-agent/routing.ts +29 -31
  385. package/dist/templates/travel-concierge-agent/shared.ts +63 -152
  386. package/dist/templates/travel-concierge-agent/tools/book_car_rental.ts +8 -9
  387. package/dist/templates/travel-concierge-agent/tools/book_excursion.ts +8 -8
  388. package/dist/templates/travel-concierge-agent/tools/book_hotel.ts +9 -6
  389. package/dist/templates/travel-concierge-agent/tools/cancel_ticket.ts +10 -10
  390. package/dist/templates/travel-concierge-agent/tools/search_car_rentals.ts +3 -2
  391. package/dist/templates/travel-concierge-agent/tools/search_excursions.ts +3 -2
  392. package/dist/templates/travel-concierge-agent/tools/search_flights.ts +4 -3
  393. package/dist/templates/travel-concierge-agent/tools/search_hotels.ts +3 -2
  394. package/dist/templates/travel-concierge-agent/tools/update_ticket.ts +13 -8
  395. package/dist/templates/web-research-agent/agent.test.ts +19 -30
  396. package/dist/templates/web-research-agent/agent.ts +3 -4
  397. package/dist/templates/word-game-agent/agent.eval.test.ts +47 -67
  398. package/dist/templates/word-game-agent/agent.test.ts +369 -382
  399. package/dist/templates/word-game-agent/agent.ts +2 -5
  400. package/dist/templates/word-game-agent/client.tsx +1 -8
  401. package/dist/templates/word-game-agent/game.ts +15 -27
  402. package/dist/templates/word-game-agent/shared.ts +36 -20
  403. package/dist/templates/word-game-agent/tools/final_score.ts +14 -13
  404. package/dist/templates/word-game-agent/tools/relay_description.ts +90 -66
  405. package/dist/templates/word-game-agent/tools/repeat_word.ts +11 -10
  406. package/dist/templates/word-game-agent/tools/skip_word.ts +17 -21
  407. package/dist/templates/word-game-agent/tools/start_game.ts +26 -30
  408. package/dist/{test-XufelYGW.mjs → test-CW5cw5fy.mjs} +3 -4
  409. package/dist/typecheck.mjs +1 -1
  410. package/dist/worker-bundler-D8uCzpYP.mjs +335 -0
  411. package/dist/worker-bundler.d.ts +39 -0
  412. package/dist/worker-bundler.mjs +2 -155
  413. package/dist/{workflow-CDUlTD5B.mjs → workflow-5gOZMB2M.mjs} +66 -19
  414. package/package.json +4 -4
  415. package/dist/_output-DBP9Op_d.mjs +0 -120
  416. package/dist/_studio-B5m4jBTD.mjs +0 -256
  417. package/dist/_ui-Coe0zwmm.mjs +0 -102
  418. package/dist/_utils-BVLdBvdT.mjs +0 -186
  419. package/dist/delete-DwXCHzTl.mjs +0 -55
  420. package/dist/templates/document-redline-workflow/form.ts +0 -73
  421. package/dist/templates/emergency-dispatch-agent/events.ts +0 -48
  422. package/dist/templates/hotel-reception-agent/events.ts +0 -80
  423. package/dist/templates/meeting-recap-agent/shared.ts +0 -44
  424. package/dist/templates/meeting-recap-agent/tools/cancel_recap.ts +0 -25
  425. package/dist/templates/meeting-recap-agent/tools/recap_progress.ts +0 -24
  426. package/dist/templates/meeting-recap-agent/tools/recap_status.ts +0 -45
  427. package/dist/templates/meeting-recap-agent/workflows/tokens.ts +0 -47
  428. package/dist/templates/outbound-call-agent/call-params.ts +0 -109
  429. package/dist/templates/outbound-call-agent/live-calls.ts +0 -80
  430. package/dist/templates/outbound-call-agent/workflows/tokens.ts +0 -16
  431. package/dist/templates/research-handoff-agent/shared.ts +0 -41
  432. package/dist/templates/research-handoff-agent/tools/research_progress.ts +0 -23
  433. package/dist/templates/research-handoff-agent/tools/research_status.ts +0 -73
  434. package/dist/templates/research-handoff-agent/workflows/review.ts +0 -43
  435. package/dist/templates/roadside-assistance-agent/events.ts +0 -92
  436. package/dist/templates/spoken-summary-workflow/workflows/transcribe.ts +0 -137
  437. package/dist/templates/transcription-workflow/total-latency.tsx +0 -170
  438. package/dist/templates/travel-concierge-agent/call-events.ts +0 -80
@@ -2,53 +2,38 @@
2
2
  /// <reference types="vite/client" />
3
3
 
4
4
  /**
5
- * Specs for the research desk's four tools.
5
+ * Specs for the research desk.
6
6
  *
7
- * All are exercised against a STUBBED `ctx.workflows`, which is the honest way
8
- * to unit-test a TOOL: what a tool owns is the call it makes, not what the run
9
- * does afterwards.
10
- * What these assert is the agent's half of the contract — that the handoff tool
11
- * passes the correlation key, that the status tool narrows a snapshot correctly
12
- * before reading it aloud, and that the two tools reaching PAST a status (the
13
- * progress stream, the early wake) ask for what a voice reply can use.
14
- *
15
- * The WORKFLOW half is `workflows.test.ts` beside this file: the steps driven
16
- * directly, the body on the real replay engine, and what a finished pass files.
17
- * The split is where the subject changes rather than where the line count did —
18
- * a tool's subject is the call it makes with a `ToolContext`, and a step's is
19
- * what it does with none.
7
+ * Three tiers: the two tools against a stubbed `ctx.workflows` (what a tool owns
8
+ * is the call it makes), the desk's configuration and delivery through
9
+ * `createWorkflowContext`, and the whole run on the real replay engine
10
+ * (`runWorkflow`). The pass itself — the brief's fallback, the planner's width
11
+ * cap, the researcher's cite-else-opened sources — is asserted in the SDK's own
12
+ * `sdk/deep-research.test.ts`; what is asserted here is this desk's half.
20
13
  */
21
14
 
22
- /** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
23
15
  import agentDef from "virtual:aai/agent";
24
- import { DEFAULT_STEP_MAX_ATTEMPTS, type WorkflowClient } from "@alexkroman1/aai";
16
+ import { describeRun } from "@alexkroman1/aai";
25
17
  import { renderSlackPlainText } from "@alexkroman1/aai/channels";
26
18
  import {
27
19
  DEFAULT_DEEP_RESEARCH_BUDGET,
28
20
  DEFAULT_DEEP_RESEARCH_PROMPTS,
29
21
  } from "@alexkroman1/aai/experimental";
30
22
  import { FatalError, RetryableError } from "@alexkroman1/aai/step-errors";
31
- import type { WorkflowRunSnapshot } from "@alexkroman1/aai/workflow-api";
32
- import type {
33
- RunWorkflowOptions,
34
- WorkflowTestRun,
35
- WorkflowTestStep,
36
- WorkflowTestWait,
37
- } from "@alexkroman1/aai-runtime/testing";
23
+ import type { WorkflowTestRun, WorkflowTestWait } from "@alexkroman1/aai-runtime/testing";
38
24
  import {
39
25
  createRunSnapshot,
40
26
  createToolContext,
41
27
  createWorkflowContext,
42
28
  parseSchemaInput,
43
- runTool,
44
29
  runWorkflow,
45
30
  type StubStepAnswer,
46
31
  type StubStepFetch,
47
32
  type StubStepRequest,
48
33
  schemaInputIssues,
49
- toolRunner,
50
34
  } from "@alexkroman1/aai-runtime/testing";
51
35
  import {
36
+ describeAgent,
52
37
  installStubGateway,
53
38
  installStubReporter,
54
39
  installStubStepDelegate,
@@ -56,8 +41,8 @@ import {
56
41
  installStubWorkflows,
57
42
  } from "@alexkroman1/aai-runtime/testing/vitest";
58
43
  import { beforeEach, describe, expect, test, vi } from "vitest";
59
- import { research } from "./shared.ts";
60
- import researchStatus from "./tools/research_status.ts";
44
+ import fileItNow from "./tools/file_it_now.ts";
45
+ import requestResearch from "./tools/request_research.ts";
61
46
  import {
62
47
  FILING_TEXT_PARAM_ENV,
63
48
  FILING_WEBHOOK_ENV,
@@ -67,312 +52,110 @@ import {
67
52
  renderFiling,
68
53
  } from "./workflows/filing.ts";
69
54
  import { BRIEF_SUMMARY_SYSTEM, BRIEF_SYSTEM } from "./workflows/prompts.ts";
70
- import { deliverResearch } from "./workflows/research.ts";
71
- import { REVIEW_DELAY_MS, REVIEW_SLEEP_ID } from "./workflows/review.ts";
72
-
73
- /**
74
- * Every tool here is driven through the agent's own table, by the name the model
75
- * calls.
76
- *
77
- * The second parameter is args-or-context, which is `runTool`'s own shape: three
78
- * of this desk's four tools take no arguments, and the `{}` those calls were
79
- * obliged to pass sat between the two values a reader cares about.
80
- */
81
- const run = toolRunner(agentDef);
82
-
83
- /**
84
- * A `ctx.workflows` that records `start` and answers `find` from a fixture.
85
- *
86
- * Returned WITHOUT a cast, which is the property worth keeping: a cast would
87
- * also stop reporting the day `WorkflowClient` grows a method, and this stub is
88
- * how the template's tools reach the client at all. `installStubWorkflows`
89
- * (`@alexkroman1/aai-runtime/testing/vitest`) is what keeps that affordable — a `vi.fn`
90
- * per method over one `runs` list, filling in what this desk does not drive, so
91
- * the day the client does grow a method only the tests using it change.
92
- * `stream`/`streamTail` are left rejecting on purpose: `research_progress` reads
93
- * progress through `lastLine`, and composing those two by hand is the hazard
94
- * `lastLine` exists to remove.
95
- */
96
- function stubWorkflows(runs: WorkflowRunSnapshot[] = []): WorkflowClient {
97
- // Name only: `WorkflowSummary.description` is optional, so passing this
98
- // desk's through would mean handing `description: undefined` to a field that
99
- // does not accept it. Nothing here reads the description anyway.
100
- return installStubWorkflows({ runs, names: ["research"] });
55
+ import research, { deliverResearch, REVIEW_DELAY_MS } from "./workflows/research.ts";
56
+
57
+ /** A finished pass, as the status line reads it. */
58
+ function findings(over: { summary?: string; sources?: number } = {}) {
59
+ return {
60
+ topic: "otters",
61
+ summary: "Otters use tools.",
62
+ report: "# Otters",
63
+ sources: 3,
64
+ angles: ["Tool use"],
65
+ filedAt: "2026-01-01T00:00:00.000Z",
66
+ ...over,
67
+ };
101
68
  }
102
69
 
103
- describe("the agent declares its workflow", () => {
104
- test("under the name ctx.workflows.start resolves it by", () => {
105
- // `toContain` rather than an exact key list: a second workflow is an
106
- // invited edit and must not redden a test the author did not write. The
107
- // NAME is still pinned, deliberately — this key is a STRING to everything
108
- // outside this file (the REST route, `ctx.workflows.get`, a schedule), so
109
- // renaming it is a runtime 404 rather than a compile error, and nothing
110
- // else says so.
111
- expect(Object.keys(agentDef.workflows ?? {})).toContain("research");
70
+ describeAgent(agentDef, (run) => {
71
+ test("declares its workflow by its file name, with an input schema", async () => {
72
+ // `workflows/research.ts` is discovered the way `tools/` is, so the name the
73
+ // run API and the builtins use is the file's.
112
74
  expect(agentDef.workflows?.research).toBe(research);
113
- });
114
-
115
- test("with an input schema, so a bad topic fails at the call site", async () => {
116
- // `parseSchemaInput` / `schemaInputIssues` rather than a reach through
117
- // `["~standard"].validate`: that is the vendor WIRE contract, and whether it
118
- // answers synchronously or with a promise is the vendor's business — a
119
- // missing `await` there leaves `.issues` undefined and the refusing half
120
- // passes for the wrong reason.
121
75
  const parsed = await parseSchemaInput(research.input, { topic: "otters", requestedBy: "s" });
122
76
  expect(parsed).toMatchObject({ topic: "otters" });
123
77
  expect(
124
78
  await schemaInputIssues(research.input, { topic: "no", requestedBy: "s" }),
125
79
  ).toBeDefined();
126
80
  });
127
- });
128
81
 
129
- /**
130
- * The options `request_research` starts its run with.
131
- *
132
- * AWAITED rather than `void`-ed. Reading a mock's call list off a floating
133
- * promise worked only because the tool body happens to reach `start` before its
134
- * first `await`; anything async landing ahead of that would have made this
135
- * return `undefined` and the reader throw a `TypeError` instead of failing on
136
- * the option it is about — and the dropped promise is an unhandled rejection
137
- * either way.
138
- *
139
- * The return type is inferred from the mock, so `notify` arrives typed and the
140
- * caller needs no cast.
141
- */
142
- async function workflowsStartOptions() {
143
- const workflows = stubWorkflows();
144
- const ctx = createToolContext({ workflows });
145
- await run("request_research", { topic: "otters" }, ctx);
146
- return vi.mocked(workflows.start).mock.calls[0]?.[2];
147
- }
148
-
149
- describe("request_research", () => {
150
- test("starts a run keyed by the session, so a later turn can find it", async () => {
151
- const workflows = stubWorkflows();
152
- const ctx = createToolContext({ workflows });
153
- const result = await run("request_research", { topic: "otters" }, ctx);
154
-
155
- expect(workflows.start).toHaveBeenCalledWith(
156
- research,
157
- { topic: "otters", requestedBy: ctx.sessionId },
158
- // `key` is the DURABLE handle — a later call finds the run by it — and
159
- // `notify` is the live one: this session is told when the run lands, which
160
- // is what makes the agent's "I'll let you know" true.
161
- { key: ctx.sessionId, notify: expect.stringContaining("read the summary") },
162
- );
163
- expect(result).toMatchObject({ started: true, runId: "wrun_stub", topic: "otters" });
164
- });
165
-
166
- test("asks to be TOLD when the run lands, rather than waiting to be asked", async () => {
167
- // The gap this closes: the agent promised an update, the run finished, and
168
- // nothing made it speak — so the caller had to think to ask again. A voice
169
- // agent that starts durable work and never announces it is the shape to
170
- // avoid, and one option is the whole fix.
171
- const options = await workflowsStartOptions();
172
- expect(options, "request_research started no run").toBeDefined();
173
- expect(typeof options?.notify).toBe("string");
174
- });
175
-
176
- test("passes the definition rather than its name", async () => {
177
- const workflows = stubWorkflows();
178
- await run("request_research", { topic: "otters" }, createToolContext({ workflows }));
179
- // The def overload is what types the input and turns a rename into a compile
180
- // error; a string would still work at runtime and lose both.
181
- expect(vi.mocked(workflows.start).mock.calls[0]?.[0]).toBe(research);
182
- });
183
- });
184
-
185
- describe("research_status", () => {
186
- test("says nothing was started when the key has no runs", async () => {
187
- const ctx = createToolContext({ workflows: stubWorkflows([]) });
188
- const result = await run("research_status", ctx);
189
- expect(result).toMatchObject({ runs: [], note: "Nothing started yet." });
190
- });
191
-
192
- test("reads a completed run's summary and source count back", async () => {
193
- const runs = [
194
- createRunSnapshot({
195
- workflow: "research",
196
- status: "completed",
197
- output: { topic: "otters", summary: "Otters use tools.", sources: 3, filedAt: "now" },
198
- }),
199
- ];
200
- const ctx = createToolContext({ workflows: stubWorkflows(runs) });
201
- const result = await runTool(researchStatus, ctx);
202
- expect(result.runs[0]).toContain("Otters use tools.");
203
- expect(result.runs[0]).toContain("3 sources");
204
- });
205
-
206
- test("says WHEN it was asked for, so two requests can be told apart", async () => {
207
- // What a caller ringing back needs. It replaces the workflow NAME, which
208
- // was the same word on every line and read aloud as noise.
209
- const runs = [
210
- createRunSnapshot({
211
- workflow: "research",
212
- status: "running",
213
- createdAt: Date.now() - 12 * 60_000,
214
- }),
215
- ];
216
- const ctx = createToolContext({ workflows: stubWorkflows(runs) });
217
- const result = await runTool(researchStatus, ctx);
218
- expect(result.runs[0]).toContain("12 minutes ago");
219
- expect(result.runs[0]).not.toContain("research:");
220
- });
221
-
222
- test("a run started moments ago is not reported as zero minutes old", async () => {
223
- const ctx = createToolContext({
224
- workflows: stubWorkflows([
225
- createRunSnapshot({ workflow: "research", status: "running", createdAt: Date.now() }),
226
- ]),
82
+ describe("request_research", () => {
83
+ test("starts a run on the session's key, and asks to be TOLD when it lands", async () => {
84
+ const workflows = installStubWorkflows({ agent: agentDef });
85
+ const ctx = createToolContext({ workflows });
86
+ const result = await run(requestResearch, { topic: "otters" }, ctx);
87
+
88
+ // The def, not its name, so the input is typed; no `key`, because a
89
+ // tool's start is keyed by the session by default; and `notify` is what
90
+ // makes the agent's "I'll let you know" true.
91
+ expect(workflows.start).toHaveBeenCalledWith(
92
+ research,
93
+ { topic: "otters", requestedBy: ctx.sessionId },
94
+ { notify: expect.stringContaining("read the summary") },
95
+ );
96
+ expect(result).toEqual({ started: true, runId: "wrun_stub", topic: "otters" });
227
97
  });
228
- const result = await runTool(researchStatus, ctx);
229
- expect(result.runs[0]).toContain("Just now");
230
98
  });
231
99
 
232
- test("reports a live run as still working rather than as empty", async () => {
233
- const ctx = createToolContext({
234
- workflows: stubWorkflows([createRunSnapshot({ workflow: "research", status: "running" })]),
100
+ describe("file_it_now", () => {
101
+ test("wakes the REVIEW wait by its label, not whatever the run happens to hold", async () => {
102
+ const workflows = installStubWorkflows({
103
+ agent: agentDef,
104
+ runs: [createRunSnapshot(research, { status: "running" })],
105
+ });
106
+ vi.mocked(workflows.wakeUp).mockResolvedValue(1);
107
+ const result = await run(fileItNow, createToolContext({ workflows }));
108
+ expect(workflows.wakeUp).toHaveBeenCalledWith("wrun_1", {
109
+ correlationIds: ["reviewWindow"],
110
+ });
111
+ expect(result).toMatchObject({ filed: true });
235
112
  });
236
- const result = await runTool(researchStatus, ctx);
237
- expect(result.runs[0]).toContain("Still working on it.");
238
- });
239
113
 
240
- test("surfaces a failed run's message instead of swallowing it", async () => {
241
- const runs = [
242
- createRunSnapshot({ workflow: "research", status: "failed", error: "model unavailable" }),
243
- ];
244
- const ctx = createToolContext({ workflows: stubWorkflows(runs) });
245
- const result = await runTool(researchStatus, ctx);
246
- expect(result.runs[0]).toContain("model unavailable");
247
- });
114
+ test("a run that was not waiting is reported honestly, not as a failure", async () => {
115
+ const workflows = installStubWorkflows({
116
+ agent: agentDef,
117
+ runs: [createRunSnapshot(research, { status: "running" })],
118
+ });
119
+ const result = await run(fileItNow, createToolContext({ workflows }));
120
+ expect(result).toMatchObject({ filed: false, note: expect.stringContaining("moved on") });
121
+ });
248
122
 
249
- test("bounds how many past runs it reads aloud", async () => {
250
- const workflows = stubWorkflows([]);
251
- const ctx = createToolContext({ workflows });
252
- await run("research_status", ctx);
253
- // A voice reply cannot be a list of twenty runs.
254
- expect(workflows.find).toHaveBeenCalledWith(research, ctx.sessionId, { limit: 3 });
123
+ test("says nothing is in flight when the session's runs have all finished", async () => {
124
+ const workflows = installStubWorkflows({
125
+ agent: agentDef,
126
+ runs: [createRunSnapshot(research, { status: "completed", output: findings() })],
127
+ });
128
+ const result = await run(fileItNow, createToolContext({ workflows }));
129
+ expect(result).toMatchObject({ filed: false, note: expect.stringContaining("in flight") });
130
+ expect(workflows.wakeUp).not.toHaveBeenCalled();
131
+ });
255
132
  });
256
133
  });
257
134
 
258
- describe("research_progress", () => {
259
- test("reads the run's own progress line rather than its status", async () => {
260
- const workflows = stubWorkflows([
261
- createRunSnapshot({ workflow: "research", status: "running" }),
262
- ]);
263
- vi.mocked(workflows.lastLine).mockResolvedValue("Found 3 sources.");
264
- const result = await run("research_progress", createToolContext({ workflows }));
265
- expect(result).toMatchObject({ progress: "Found 3 sources." });
266
- });
267
-
268
- test("asks for the LAST line, not the whole log", async () => {
269
- // A voice reply cannot recite every line the run has written. `lastLine` is
270
- // the whole request — the bound that keeps an empty channel from hanging
271
- // belongs to the method, so nothing here composes `streamTail` and `stream`.
272
- const workflows = stubWorkflows([
273
- createRunSnapshot({ workflow: "research", status: "running" }),
274
- ]);
275
- vi.mocked(workflows.lastLine).mockResolvedValue("a");
276
- await run("research_progress", createToolContext({ workflows }));
277
- expect(workflows.lastLine).toHaveBeenCalledWith("wrun_1");
278
- });
279
-
280
- test("a run that has written nothing yet says so", async () => {
281
- // `lastLine` resolves `undefined` for an empty channel, and this is the arm
282
- // the tool branches on. That an empty channel does not HANG — it is never
283
- // closed, so a stream opened on one waits for a line that may never come —
284
- // is `lastLine`'s own guarantee now, and `aai`'s to test.
285
- const workflows = stubWorkflows([
286
- createRunSnapshot({ workflow: "research", status: "running" }),
287
- ]);
288
- const result = await run("research_progress", createToolContext({ workflows }));
289
- expect(result).toMatchObject({ note: "Started, nothing to report yet." });
290
- });
291
-
292
- test("says nothing was started when the key has no runs", async () => {
293
- const workflows = stubWorkflows([]);
294
- const result = await run("research_progress", createToolContext({ workflows }));
295
- expect(result).toMatchObject({ note: "Nothing started yet." });
296
- expect(workflows.lastLine).not.toHaveBeenCalled();
135
+ describe("what the status builtin says per run", () => {
136
+ test("reads a completed run's summary and source count back", () => {
137
+ const run = createRunSnapshot(research, { status: "completed", output: findings() });
138
+ expect(describeRun(research, run)).toContain("Otters use tools.");
139
+ expect(describeRun(research, run)).toContain("3 sources");
297
140
  });
298
- });
299
141
 
300
- describe("file_it_now", () => {
301
- test("wakes the sleeping run so the review wait ends early", async () => {
302
- const workflows = stubWorkflows([
303
- createRunSnapshot({ workflow: "research", status: "running" }),
304
- ]);
305
- vi.mocked(workflows.wakeUp).mockResolvedValue(1);
306
- const result = await run("file_it_now", createToolContext({ workflows }));
307
- expect(workflows.wakeUp).toHaveBeenCalledWith("wrun_1", {
308
- correlationIds: [REVIEW_SLEEP_ID],
142
+ test("says WHEN it was asked for, so two requests can be told apart", () => {
143
+ const twelveMinutesAgo = createRunSnapshot(research, {
144
+ status: "running",
145
+ createdAt: Date.now() - 12 * 60_000,
309
146
  });
310
- expect(result).toMatchObject({ filed: true });
311
- });
312
-
313
- test("wakes the REVIEW wait by name, not whatever the run happens to hold", async () => {
314
- // The tool's description is "skip the review wait", and an un-named
315
- // `wakeUp(runId)` ends every suspension the run has — including an approval
316
- // waitpoint a later body might open, which would file a report that was
317
- // still waiting on a person. `review.ts` is where both sides read the id.
318
- const workflows = stubWorkflows([
319
- createRunSnapshot({ workflow: "research", status: "running" }),
320
- ]);
321
- vi.mocked(workflows.wakeUp).mockResolvedValue(1);
322
- await run("file_it_now", createToolContext({ workflows }));
323
- expect(vi.mocked(workflows.wakeUp).mock.calls[0]?.[1]?.correlationIds).toEqual([
324
- REVIEW_SLEEP_ID,
325
- ]);
326
- });
327
-
328
- test("a run that was not waiting is reported honestly, not as a failure", async () => {
329
- // `wakeUp` answering 0 means the run had already moved past its sleep — the
330
- // same shape as `cancel` answering false.
331
- const workflows = stubWorkflows([
332
- createRunSnapshot({ workflow: "research", status: "running" }),
333
- ]);
334
- vi.mocked(workflows.wakeUp).mockResolvedValue(0);
335
- const result = await run("file_it_now", createToolContext({ workflows }));
336
- expect(result).toMatchObject({ filed: false });
147
+ expect(describeRun(research, twelveMinutesAgo)).toMatch(/^12 minutes ago: still working/);
148
+ const justNow = createRunSnapshot(research, { status: "running", createdAt: Date.now() });
149
+ expect(describeRun(research, justNow)).toMatch(/^Just now/);
337
150
  });
338
151
 
339
- test("says nothing was started when the key has no runs", async () => {
340
- const workflows = stubWorkflows([]);
341
- const result = await run("file_it_now", createToolContext({ workflows }));
342
- expect(result).toMatchObject({ note: "Nothing started yet." });
343
- expect(workflows.wakeUp).not.toHaveBeenCalled();
152
+ test("surfaces a failed run's message instead of swallowing it", () => {
153
+ const run = createRunSnapshot(research, { status: "failed", error: "model unavailable" });
154
+ expect(describeRun(research, run)).toContain("model unavailable");
344
155
  });
345
156
  });
346
157
 
347
- /**
348
- * The WORKFLOW half of the research desk: what it configures, what it files,
349
- * and the run itself.
350
- *
351
- * The pass is `deepResearchWorkflow()`'s, and its stages — the brief's
352
- * fallback, the planner's width cap, the researcher's cite-else-opened
353
- * sources, the report's one numbering, the gateway's retry classification —
354
- * are asserted in the SDK's own spec (`sdk/deep-research.test.ts`), where they
355
- * live. What is asserted HERE is this desk's half: the prompts it overrides,
356
- * the researcher and budget it keeps, the review wait and filing its `deliver`
357
- * adds, and — on the REAL replay engine — that the whole run keeps the desk's
358
- * promise: **answer the caller now, finish the work later**.
359
- *
360
- * The body is driven twice, once through `createWorkflowContext`, which records
361
- * what it asked for and replays nothing, and once through `runWorkflow`
362
- * (`@alexkroman1/aai-runtime/testing`), which reads the journal directly for
363
- * the three things the run's own snapshot cannot show (which sleep is open and
364
- * under what name, what an `investigate` left behind for a resume to reuse, and
365
- * whether a boot sweep would still find a run whose worker died).
366
- * `aai-cli`'s `dev-workflow.scenario.test.ts` is the tier above both, with a
367
- * built project and a real queue.
368
- */
369
158
  describe("the desk's research configuration", () => {
370
- beforeEach(() => {
371
- // `stepEnv` falls back to the process env when no host has published one,
372
- // which is exactly the case a spec is. `unstubEnvs` clears it per test.
373
- vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
374
- });
375
-
376
159
  const INPUT = { topic: "Tool use", requestedBy: "Ada" };
377
160
  const brief = { brief: "How otters use tools", criteria: ["Which species"] };
378
161
 
@@ -418,37 +201,7 @@ describe("the desk's research configuration", () => {
418
201
  expect(desk.calls[0]?.options.context).toContain("How otters use tools");
419
202
  });
420
203
 
421
- test("both investigate waves are called with more attempts than the default", async () => {
422
- // With `runSteps: false` nothing runs, so this is the skeleton of a run: no
423
- // page, no model and no search, in exchange for spelling the shape out.
424
- const ctx = createWorkflowContext({
425
- runSteps: false,
426
- results: {
427
- writeBrief: brief,
428
- planAngles: ["Adoption", "Tooling"],
429
- findGaps: ["Cost"],
430
- investigate: { angle: "Adoption", findings: "f", sources: [] },
431
- investigateGap: { angle: "Cost", findings: "f", sources: [] },
432
- writeReport: { summary: "s", report: "r" },
433
- },
434
- });
435
- await research.run(INPUT, ctx);
436
-
437
- const investigations = ctx.steps.filter((step) => step.name.startsWith("investigate"));
438
- expect(investigations.map((step) => step.name)).toEqual([
439
- "investigate",
440
- "investigate",
441
- "investigateGap",
442
- ]);
443
- for (const step of investigations) {
444
- expect(step.maxAttempts).toBeGreaterThan(DEFAULT_STEP_MAX_ATTEMPTS);
445
- }
446
- });
447
-
448
- test("the review wait is opened under the name file_it_now wakes", async () => {
449
- // The two halves of one agreement, and the only place a spec can see both:
450
- // the delivery's `correlationId` here, and the tool's `correlationIds` in
451
- // the `file_it_now` block. `review.ts` is the module that keeps them equal.
204
+ test("the review wait comes after the report and before filing, under the label file_it_now wakes", async () => {
452
205
  const ctx = createWorkflowContext({
453
206
  runSteps: false,
454
207
  results: {
@@ -461,13 +214,11 @@ describe("the desk's research configuration", () => {
461
214
  });
462
215
  await research.run(INPUT, ctx);
463
216
 
464
- expect(ctx.slept).toHaveLength(1);
465
- expect(ctx.slept[0]?.correlationId).toBe(REVIEW_SLEEP_ID);
466
- // The wait comes AFTER the report, and filing after the wait.
217
+ expect(ctx.slept).toMatchObject([{ label: "reviewWindow", until: REVIEW_DELAY_MS }]);
467
218
  expect(ctx.steps.map((step) => step.name).slice(-2)).toEqual(["writeReport", "file"]);
468
219
  });
469
220
 
470
- test("deliverResearch answers with what research_status reads back", async () => {
221
+ test("deliverResearch answers with what the status line reads back", async () => {
471
222
  const ctx = createWorkflowContext({ results: { file: "2026-01-01T00:00:00.000Z" } });
472
223
  const source = { title: "Otters", url: "https://otters.example" };
473
224
  const out = await deliverResearch(
@@ -494,7 +245,7 @@ describe("the desk's research configuration", () => {
494
245
 
495
246
  test("a missing key is FATAL, naming the key, and fails the run rather than filing", async () => {
496
247
  vi.stubEnv("ASSEMBLYAI_API_KEY", "");
497
- installStubGateway(["anything"]);
248
+ installStubGateway(["anything"], { apiKey: false });
498
249
  const ctx = createWorkflowContext();
499
250
  const err = await Promise.resolve(research.run(INPUT, ctx)).catch((thrown: unknown) => thrown);
500
251
  expect(FatalError.is(err)).toBe(true);
@@ -512,13 +263,9 @@ describe("the desk's research configuration", () => {
512
263
  });
513
264
 
514
265
  /**
515
- * The last step, which used to be a promise.
516
- *
517
- * What is asserted here is this template's half — what a filed report SAYS, and
518
- * that the channel is resolved from the env rather than assumed. The 4xx/5xx
519
- * split, the Block Kit assembly and the mrkdwn escaping are
520
- * `@alexkroman1/aai/channels`' and have their own specs; a template asserting
521
- * them again would pin the SDK's rendering from the outside.
266
+ * The last step. What is asserted here is this template's half — what a filed
267
+ * report SAYS, and that the channel is resolved from the env rather than
268
+ * assumed; the 4xx/5xx split and the rendering are `@alexkroman1/aai/channels`'.
522
269
  */
523
270
  describe("filing the findings", () => {
524
271
  const WEBHOOK = "https://hooks.slack.com/services/T000/B000/abc";
@@ -536,15 +283,7 @@ describe("filing the findings", () => {
536
283
  ],
537
284
  };
538
285
 
539
- /**
540
- * The webhook, answered without a network.
541
- *
542
- * `installStubStepFetch` rather than a `fetch` global stub: a channel post
543
- * goes out through the published `stepFetch` slot like every other step
544
- * request, and stubbing the global would test a path production does not
545
- * take. Anything that is not the webhook is a finding rather than a 200 —
546
- * an unexpected request answered emptily reads to the run as a refusal.
547
- */
286
+ /** The webhook, answered without a network; anything else is a finding. */
548
287
  function stubPost(answer: StubStepAnswer): StubStepFetch {
549
288
  return installStubStepFetch((request: StubStepRequest): StubStepAnswer => {
550
289
  if (!request.url.startsWith("https://hooks.slack.com/")) {
@@ -563,15 +302,12 @@ describe("filing the findings", () => {
563
302
  expect(posted.calls[0]?.method).toBe("POST");
564
303
  expect(posted.calls[0]?.url).toBe(WEBHOOK);
565
304
  expect(String(posted.calls[0]?.body)).toContain("crack shellfish");
566
- // `filedAt` is a TIME now. It was the literal string "filed" under a field
567
- // named for a timestamp, which was two claims and neither was true.
568
305
  expect(Number.isNaN(Date.parse(filedAt))).toBe(false);
569
306
  });
570
307
 
571
308
  test("with no webhook it files nowhere, says so, and does not fail the run", async () => {
572
309
  // The last step of a five-minute pass is the worst place to discover a
573
- // missing credential, so the channel is optional by construction — this is
574
- // the arm that keeps `aai dev` runnable before anything is configured.
310
+ // missing credential, so the channel is optional by construction.
575
311
  const reported = installStubReporter();
576
312
  const posted = stubPost({ body: "ok" });
577
313
 
@@ -588,8 +324,7 @@ describe("filing the findings", () => {
588
324
 
589
325
  test("a text param is carried only where it means something", () => {
590
326
  // It names a Slack WORKFLOW variable, so it does something on a trigger URL
591
- // and quietly nothing on an incoming webhook — and a setting that looks
592
- // configured and is ignored is the worse of the two.
327
+ // and quietly nothing on an incoming webhook.
593
328
  vi.stubEnv(FILING_TEXT_PARAM_ENV, "report");
594
329
  vi.stubEnv(FILING_WEBHOOK_ENV, WEBHOOK);
595
330
  expect(filingChannel()?.options.textParam).toBeUndefined();
@@ -604,7 +339,6 @@ describe("filing the findings", () => {
604
339
  expect(message.heading).toBe("Research: how otters use tools");
605
340
  expect(message.subtitle).toContain("Requested by sess_1");
606
341
  expect(message.subtitle).toContain("1 source across 1 angle");
607
- // The answer first, then one section per angle.
608
342
  expect(message.sections?.[0]).toMatchObject({ title: "In short" });
609
343
  expect(message.sections?.[1]).toMatchObject({
610
344
  title: "Tool use",
@@ -614,9 +348,7 @@ describe("filing the findings", () => {
614
348
 
615
349
  test("the message still answers where a destination renders no sections", () => {
616
350
  // A Slack workflow trigger takes ONE string, so the SDK folds the whole
617
- // message down to text — `renderSlackPlainText` is that folding. What has to
618
- // survive it is the answer and the sources, which is what a reader who never
619
- // opens the run gets.
351
+ // message down to text; the answer and the sources must survive it.
620
352
  const flat = renderSlackPlainText(renderFiling(FILING));
621
353
 
622
354
  expect(flat).toContain("crack shellfish");
@@ -625,27 +357,12 @@ describe("filing the findings", () => {
625
357
  });
626
358
 
627
359
  /**
628
- * The whole run — `deepResearchWorkflow`'s pass plus this desk's delivery — on
629
- * the real replay engine.
630
- *
631
- * The block above drives this body through `createWorkflowContext`, which records
632
- * what it ASKED for and replays nothing — right for the retry policy and the
633
- * step order, and silent about the desk's actual promise: **answer the caller
634
- * now, finish the work later**. `runWorkflow`
635
- * (`@alexkroman1/aai-runtime/testing`) is the engine `aai dev` runs, over an
636
- * in-memory journal, so the review wait really suspends and the resume really
637
- * comes off the journal.
638
- *
639
- * The model is scripted POSITIONALLY, which is only safe because the run is made
640
- * sequential: one angle, and a researcher that stops on its first turn, so the
641
- * `mapConcurrent` fan-out has a single item and nothing races. A case that wants
642
- * two angles at once wants a router keyed on the system prompt instead — the
643
- * shape `link-digest-workflow` uses — because the order two concurrent step bodies reach
644
- * the gateway in is the scheduler's business.
360
+ * The whole run on the real replay engine, which is the only tier that can
361
+ * reach the desk's promise: **answer the caller now, finish the work later**.
645
362
  *
646
- * Five calls make a whole run: the brief, the angles, the researcher's first
647
- * action, the gap pass, and the report — plus its summary, which is a second
648
- * call on the same step.
363
+ * The model is scripted POSITIONALLY, which is only safe because the run is
364
+ * made sequential: one angle, and a researcher that stops on its first turn,
365
+ * so the `mapConcurrent` fan-out has a single item and nothing races.
649
366
  */
650
367
  describe("the run is DURABLE", () => {
651
368
  const SCRIPT = [
@@ -653,9 +370,8 @@ describe("the run is DURABLE", () => {
653
370
  JSON.stringify({ brief: "How otters use tools", criteria: ["Which species"] }),
654
371
  // planAngles — ONE, so the fan-out is sequential and the script positional.
655
372
  JSON.stringify({ angles: ["Tool use"] }),
656
- // `investigate` is NOT in this script any more: it delegates, so its model
657
- // calls are the subagent's and are answered by `installStubStepDelegate`
658
- // below rather than by the gateway.
373
+ // `investigate` delegates: its model calls are the subagent's, answered by
374
+ // `installStubStepDelegate` below rather than by the gateway.
659
375
  // findGaps — none, so there is no second wave.
660
376
  JSON.stringify({ angles: [] }),
661
377
  // writeReport, then its summary.
@@ -664,20 +380,7 @@ describe("the run is DURABLE", () => {
664
380
  ];
665
381
  const INPUT = { topic: "otters", requestedBy: "sess_1" };
666
382
 
667
- /**
668
- * How every case here starts the run.
669
- *
670
- * `name` is the key the engine registers the run under and has to match the
671
- * one `agent.ts` declares — a string five call sites repeated, which is the
672
- * kind that drifts in four of them. The annotation is what says what else
673
- * belongs in this bag (`crashAt` below, and a `journal` of your own).
674
- */
675
- const RUN = { name: "research" } satisfies RunWorkflowOptions;
676
-
677
383
  beforeEach(() => {
678
- // `unstubEnvs` (set by `defineAgentTestConfig`) undoes the webhook an
679
- // earlier case stubbed, so these cases start with none configured.
680
- vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
681
384
  // No `RESEARCH_SLACK_WEBHOOK_URL`, so the filing step posts nothing — which
682
385
  // is why the gateway counts below are the run's model calls and only those.
683
386
  installStubStepDelegate({ routes: { researcher: "Nothing was found on this angle." } });
@@ -688,25 +391,15 @@ describe("the run is DURABLE", () => {
688
391
  return run.steps.map((step) => step.key);
689
392
  }
690
393
 
691
- /**
692
- * The one suspension a research run takes, read off the journal itself.
693
- *
694
- * The run's snapshot carries `wakeAt` and nothing about WHICH wait it is, so
695
- * the correlation id `file_it_now` names is only visible here.
696
- */
394
+ /** The one suspension a research run takes, read off the journal itself. */
697
395
  function reviewSleep(run: WorkflowTestRun<unknown>): WorkflowTestWait | undefined {
698
- return run.waits.find((wait) => wait.correlationId === REVIEW_SLEEP_ID);
699
- }
700
-
701
- /** What an `investigate` left in the journal for a resume to reuse. */
702
- function journaledResearch(run: WorkflowTestRun<unknown>): WorkflowTestStep | undefined {
703
- return run.steps.find((step) => step.name === "investigate");
396
+ return run.waits.find((wait) => wait.correlationId === "reviewWindow");
704
397
  }
705
398
 
706
399
  test("suspends on the review wait with the whole report already journaled", async () => {
707
400
  const started = Date.now();
708
401
  const model = installStubGateway(SCRIPT);
709
- const run = await runWorkflow(research, INPUT, RUN);
402
+ const run = await runWorkflow(agentDef, "research", INPUT);
710
403
 
711
404
  // Not blocked — suspended. The sandbox is free here, which is the whole
712
405
  // reason a caller can hang up.
@@ -720,41 +413,29 @@ describe("the run is DURABLE", () => {
720
413
  "writeBrief#0",
721
414
  "writeReport#0",
722
415
  ]);
723
- // FIVE gateway calls for six steps, and the missing one is `investigate`:
724
- // its model turns belong to the subagent now and go through the delegate
725
- // slot instead. The STEP is still journaled — it is in the list above.
416
+ // FIVE gateway calls for six steps: `investigate`'s turns went to the
417
+ // subagent through the delegate slot.
726
418
  expect(model).toHaveLength(5);
727
- });
728
-
729
- test("the open wait is the REVIEW wait, by the name the tool wakes", async () => {
730
- installStubGateway(SCRIPT);
731
- const run = await runWorkflow(research, INPUT, RUN);
732
-
733
- const sleep = reviewSleep(run);
734
- expect(sleep, "the run holds no sleep under the review correlation id").toBeDefined();
735
- expect(sleep?.woken).toBe(false);
736
- expect(sleep?.kind).toBe("sleep");
419
+ // The open wait is the REVIEW wait, by the label `file_it_now` wakes.
420
+ expect(reviewSleep(run)).toMatchObject({ kind: "sleep", woken: false });
737
421
  });
738
422
 
739
423
  test("makes no decision a replay could not reproduce", async () => {
740
424
  // `reads` records every `ctx.now`/`ctx.random`/`ctx.uuid` the body took, and
741
425
  // this body takes none: the fan-out's width comes from a journaled step, and
742
- // the filing timestamp is a step RESULT. An empty list is the determinism
743
- // rule this template's doc states, asserted rather than described.
426
+ // the filing timestamp is a step RESULT.
744
427
  installStubGateway(SCRIPT);
745
- const run = await runWorkflow(research, INPUT, RUN);
428
+ const run = await runWorkflow(agentDef, "research", INPUT);
746
429
 
747
430
  expect(run.reads).toEqual([]);
748
431
  });
749
432
 
750
433
  test("resumes past the review wait and files, without researching again", async () => {
751
434
  const model = installStubGateway(SCRIPT);
752
- const run = await runWorkflow(research, INPUT, RUN);
753
- // `advanceSleep` is `ctx.workflows.wakeUp`'s own mechanism, which is what
754
- // the `file_it_now` tool calls to cut the review short — and it is given the
755
- // SAME correlation id that tool passes, so what this drives is that tool's
756
- // effect rather than a blanket wake nothing in the desk performs.
757
- await run.advanceSleep([REVIEW_SLEEP_ID]);
435
+ const run = await runWorkflow(agentDef, "research", INPUT);
436
+ // `advanceSleep` is `ctx.workflows.wakeUp`'s own mechanism, given the same
437
+ // label `file_it_now` passes.
438
+ await run.advanceSleep(["reviewWindow"]);
758
439
 
759
440
  expect(run.status).toBe("completed");
760
441
  expect(run.output).toMatchObject({
@@ -762,9 +443,9 @@ describe("the run is DURABLE", () => {
762
443
  summary: "Otters use tools.",
763
444
  report: "The report about otters.",
764
445
  angles: ["Tool use"],
446
+ // A real timestamp: the filing step really ran.
447
+ filedAt: expect.stringMatching(/^\d{4}-\d{2}-\d{2}T/),
765
448
  });
766
- // A real timestamp, and the filing step really ran.
767
- expect(Number.isNaN(Date.parse(run.output?.filedAt ?? ""))).toBe(false);
768
449
  expect(run.deliveries).toBe(2);
769
450
  // The second walk re-entered the body from the top and paid the model
770
451
  // NOTHING: every step above the wait came back out of the journal.
@@ -775,32 +456,25 @@ describe("the run is DURABLE", () => {
775
456
  // The expensive claim. A deep-research pass is five to twelve model calls
776
457
  // and as many searches; a resume that redid them would cost the run twice.
777
458
  const model = installStubGateway(SCRIPT);
778
- const run = await runWorkflow(research, INPUT, { ...RUN, crashAt: "writeReport" });
459
+ const run = await runWorkflow(agentDef, "research", INPUT, { crashAt: "writeReport" });
779
460
 
780
461
  expect(run.crashed).toBe(true);
781
462
  expect(stepKeys(run)).toEqual(["findGaps#0", "investigate#0", "planAngles#0", "writeBrief#0"]);
782
- // THREE, not four: `investigate` is one of the four steps above and paid
783
- // the gateway nothing — its turns went to the subagent.
784
- const spentBeforeTheCrash = model.length;
785
- expect(spentBeforeTheCrash).toBe(3);
786
-
787
- // WHY the resume is free, read off the store rather than inferred from a
788
- // call count: the finished angle's own result is sitting in the journal,
789
- // which is what the second walk answers `investigate#0` from.
790
- const done = journaledResearch(run);
463
+ // THREE, not four: `investigate` paid the gateway nothing.
464
+ expect(model).toHaveLength(3);
465
+ // The finished angle's own result is sitting in the journal, which is what
466
+ // the second walk answers `investigate#0` from; and the run is still
467
+ // FINDABLE, so a boot sweep resumes it.
468
+ const done = run.steps.find((step) => step.name === "investigate");
791
469
  expect(done?.status).toBe("ok");
792
470
  expect(done?.output).toMatchObject({ angle: "Tool use" });
793
- // And the run is still FINDABLE: a dead worker leaves it for a boot sweep,
794
- // which is what makes "resume" a platform behaviour rather than a promise
795
- // this handle keeps.
796
471
  expect(run.resumable).toBe(true);
797
472
 
798
473
  await run.restart();
799
- await run.advanceSleep([REVIEW_SLEEP_ID]);
474
+ await run.advanceSleep(["reviewWindow"]);
800
475
  expect(run.status).toBe("completed");
801
- // Five in total: the three the crash already paid for came back out of the
802
- // journal, and only the report and its summary were re-issued.
476
+ // Five in total: only the report and its summary were re-issued.
803
477
  expect(model).toHaveLength(5);
804
- expect(run.output?.report).toBe("The report about otters.");
478
+ expect(run.output).toMatchObject({ report: "The report about otters." });
805
479
  });
806
480
  });