@alexkroman1/aai-cli 0.17.0 → 0.18.1

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
@@ -1,31 +1,25 @@
1
- /** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
2
1
  import agentDef from "virtual:aai/agent";
3
2
  import type { ToolContext } from "@alexkroman1/aai";
4
3
  import {
5
4
  createToolContext,
6
- expectDialogOk,
5
+ expectSlotContract,
7
6
  expectToolOk,
8
7
  runGuardrail,
9
- runTool,
10
8
  type StubDelegateRoute,
11
9
  type StubGenerateRoute,
12
10
  stubDelegate,
13
- toolRunner,
14
11
  } from "@alexkroman1/aai-runtime/testing";
12
+ import { describeAgent } from "@alexkroman1/aai-runtime/testing/vitest";
15
13
  import { describe, expect, test, vi } from "vitest";
16
14
  import { executeStep, executor, MAX_STEP_TURNS, normalizeAct, planNode } from "./procedure.ts";
17
15
  import { PLANNER_SYSTEM, REPLANNER_SYSTEM, REVISE_SYSTEM, type StepAnswer } from "./prompts.ts";
18
- import {
19
- createWebTools,
20
- MAX_PAGE_CHARS,
21
- MAX_PAST_STEPS,
22
- MAX_REVISIONS,
23
- planFlow,
24
- planSlot,
25
- planView,
26
- type WebAccess,
27
- } from "./shared.ts";
16
+ import { createWebTools, MAX_PAGE_CHARS, planFlow, planSlot, type WebAccess } from "./shared.ts";
17
+ // The tool FILES: each default export is the object `agentDef` registers, so
18
+ // `run(startPlan, …)` is typed by the def — arguments and result, gate included.
19
+ import planStatus from "./tools/plan_status.ts";
20
+ import revisePlan from "./tools/revise_plan.ts";
28
21
  import startPlan from "./tools/start_plan.ts";
22
+ import workNextStep from "./tools/work_next_step.ts";
29
23
 
30
24
  /**
31
25
  * The web, faked at the SDK's own seam.
@@ -107,534 +101,491 @@ function scriptedDesk(script: Script = {}) {
107
101
  return { ctx, model: ctx.model, desk: ctx.desk };
108
102
  }
109
103
 
110
- /** A tool by the name the model calls it by, bound to this agent. The lookup,
111
- * its "no such tool" message and the args-or-context shape are all
112
- * `toolRunner`'s (`@alexkroman1/aai-runtime/testing`); what is local is only which
113
- * agent it runs against. */
114
- const run = toolRunner(agentDef);
115
-
116
104
  function stateOf(ctx: ToolContext) {
117
105
  return planSlot.get(ctx);
118
106
  }
119
107
 
120
- // ─── 1. The nodes ────────────────────────────────────────────────────────────
108
+ /** Where the flow is, without going through a tool. */
109
+ const at = (ctx: ToolContext) => planFlow.position(ctx).state;
121
110
 
122
- describe("planNode", () => {
123
- test("returns the steps the planner produced", async () => {
124
- const { model } = scriptedDesk({ steps: ["Check prices", "Book it"] });
125
- expect(await planNode(model.generate, "get me to Lisbon in May")).toEqual([
126
- "Check prices",
127
- "Book it",
128
- ]);
129
- expect(model.calls[0]?.prompt).toContain("get me to Lisbon in May");
130
- });
131
- });
111
+ describeAgent(agentDef, (run) => {
112
+ // ─── 1. The nodes ────────────────────────────────────────────────────────────
132
113
 
133
- describe("executeStep", () => {
134
- test("hands the step to the executor, with the objective and the history as context", async () => {
135
- const desk = stubDelegate({
136
- routes: { executor: stepReply("Flights are around 180 return.") },
137
- });
138
-
139
- const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", [
140
- { step: "Pick dates", result: "Mid-May", settled: true, searches: [] },
141
- ]);
142
-
143
- // `finding` off the schema's own output, not the raw final message: the
144
- // executor is a TYPED subagent, so what crosses back is a parsed object.
145
- expect(outcome.result).toBe("Flights are around 180 return.");
146
- expect(outcome.settled).toBe(true);
147
- // The STEP is the task; everything the executor needs to do it in context
148
- // rides in `context`, because a subagent has not heard the call.
149
- expect(desk.calls[0]?.task).toBe("Check prices");
150
- expect(desk.calls[0]?.options.context).toContain("get to Lisbon");
151
- expect(desk.calls[0]?.options.context).toContain("Mid-May");
114
+ describe("planNode", () => {
115
+ test("returns the steps the planner produced", async () => {
116
+ const { model } = scriptedDesk({ steps: ["Check prices", "Book it"] });
117
+ expect(await planNode(model.generate, "get me to Lisbon in May")).toEqual([
118
+ "Check prices",
119
+ "Book it",
120
+ ]);
121
+ expect(model.calls[0]?.prompt).toContain("get me to Lisbon in May");
122
+ });
152
123
  });
153
124
 
154
- test("reports what it searched, read off the calls the run made", async () => {
155
- // A search's RESULTS stayed inside the executor's context — that is the
156
- // delegation — so the calls are the only honest source for the desk's
157
- // "what the wait bought" line.
158
- const desk = stubDelegate({
159
- routes: {
160
- executor: {
161
- text: stepReply("Flights are around 180 return."),
162
- toolCalls: [
163
- { name: "search", input: { query: "lisbon flights may" } },
164
- { name: "search", input: { query: "lisbon flights june" } },
165
- ],
166
- },
167
- },
125
+ describe("executeStep", () => {
126
+ test("hands the step to the executor, with the objective and the history as context", async () => {
127
+ const desk = stubDelegate({
128
+ routes: { executor: stepReply("Flights are around 180 return.") },
129
+ });
130
+
131
+ const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", [
132
+ { step: "Pick dates", result: "Mid-May", settled: true, searches: [] },
133
+ ]);
134
+
135
+ // `finding` off the schema's own output, not the raw final message: the
136
+ // executor is a TYPED subagent, so what crosses back is a parsed object.
137
+ expect(outcome.result).toBe("Flights are around 180 return.");
138
+ expect(outcome.settled).toBe(true);
139
+ // The STEP is the task; everything the executor needs to do it in context
140
+ // rides in `context`, because a subagent has not heard the call.
141
+ expect(desk.calls[0]?.task).toBe("Check prices");
142
+ expect(desk.calls[0]?.options.context).toContain("get to Lisbon");
143
+ expect(desk.calls[0]?.options.context).toContain("Mid-May");
168
144
  });
169
145
 
170
- const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
146
+ test("reports what it searched, read off the calls the run made", async () => {
147
+ // A search's RESULTS stayed inside the executor's context — that is the
148
+ // delegation — so the calls are the only honest source for the desk's
149
+ // "what the wait bought" line.
150
+ const desk = stubDelegate({
151
+ routes: {
152
+ executor: {
153
+ text: stepReply("Flights are around 180 return."),
154
+ toolCalls: [
155
+ { name: "search", input: { query: "lisbon flights may" } },
156
+ { name: "search", input: { query: "lisbon flights june" } },
157
+ ],
158
+ },
159
+ },
160
+ });
171
161
 
172
- expect(outcome.searches).toEqual(["lisbon flights may", "lisbon flights june"]);
173
- });
162
+ const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
174
163
 
175
- test("the executor is given its two tools and a bounded budget", async () => {
176
- // What this template still OWNS now that the loop is the runtime's: which
177
- // capabilities the step is worth, and how long it may spend.
178
- const desk = stubDelegate({ routes: { executor: stepReply("done") } });
179
- await executeStep(desk.delegate, "objective", "step", []);
180
-
181
- const executor = desk.calls[0]?.subagent;
182
- expect(Object.keys(executor?.tools ?? {})).toEqual(["search", "read"]);
183
- expect(executor?.maxSteps).toBe(MAX_STEP_TURNS);
184
- // No `builtinTools`: both are this template's own tools over
185
- // `@alexkroman1/aai/tools`, which is the example that outlived the loop.
186
- expect(executor?.builtinTools).toBeUndefined();
187
- });
164
+ expect(outcome.searches).toEqual(["lisbon flights may", "lisbon flights june"]);
165
+ });
188
166
 
189
- test("an unsettled step is carried as a FIELD, not inferred from the wording", async () => {
190
- // `settled` is what a prompt could not hold: "say plainly rather than
191
- // inventing a result" was in `EXECUTOR_OUTPUT` from the start, and the desk
192
- // read one string, so a step that found nothing and a step that answered
193
- // arrived in the same shape.
194
- const desk = stubDelegate({
195
- routes: {
196
- executor: stepReply({ finding: "Nothing current on that route.", settled: false }),
197
- },
167
+ test("the executor is given its two tools and a bounded budget", async () => {
168
+ // What this template still OWNS now that the loop is the runtime's: which
169
+ // capabilities the step is worth, and how long it may spend.
170
+ const desk = stubDelegate({ routes: { executor: stepReply("done") } });
171
+ await executeStep(desk.delegate, "objective", "step", []);
172
+
173
+ const executor = desk.calls[0]?.subagent;
174
+ expect(Object.keys(executor?.tools ?? {})).toEqual(["search", "read"]);
175
+ expect(executor?.maxSteps).toBe(MAX_STEP_TURNS);
176
+ // No `builtinTools`: both are this template's own tools over
177
+ // `@alexkroman1/aai/tools`, which is the example that outlived the loop.
178
+ expect(executor?.builtinTools).toBeUndefined();
198
179
  });
199
180
 
200
- const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
181
+ test("an unsettled step is carried as a FIELD, not inferred from the wording", async () => {
182
+ // `settled` is what a prompt could not hold: "say plainly rather than
183
+ // inventing a result" was in `EXECUTOR_OUTPUT` from the start, and the desk
184
+ // read one string, so a step that found nothing and a step that answered
185
+ // arrived in the same shape.
186
+ const desk = stubDelegate({
187
+ routes: {
188
+ executor: stepReply({ finding: "Nothing current on that route.", settled: false }),
189
+ },
190
+ });
201
191
 
202
- expect(outcome.settled).toBe(false);
203
- expect(outcome.result).toBe("Nothing current on that route.");
204
- });
192
+ const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
205
193
 
206
- test("an answer the guardrail never accepted is not a settled step", async () => {
207
- // The run had its revision and still reported a step it never looked into,
208
- // so `accepted` is false — and a `settled: true` from an answer the runtime
209
- // refused is exactly the claim not to take at face value.
210
- const desk = stubDelegate({
211
- routes: {
212
- executor: {
213
- text: stepReply({ finding: "Flights are cheap in May.", settled: true }),
214
- complaint: "You reported the step as unsettled without searching for anything.",
215
- },
216
- },
194
+ expect(outcome.settled).toBe(false);
195
+ expect(outcome.result).toBe("Nothing current on that route.");
217
196
  });
218
197
 
219
- const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
198
+ test("an answer the guardrail never accepted is not a settled step", async () => {
199
+ // The run had its revision and still reported a step it never looked into,
200
+ // so `accepted` is false — and a `settled: true` from an answer the runtime
201
+ // refused is exactly the claim not to take at face value.
202
+ const desk = stubDelegate({
203
+ routes: {
204
+ executor: {
205
+ text: stepReply({ finding: "Flights are cheap in May.", settled: true }),
206
+ complaint: "You reported the step as unsettled without searching for anything.",
207
+ },
208
+ },
209
+ });
220
210
 
221
- expect(outcome.settled).toBe(false);
222
- expect(outcome.result).toBe("Flights are cheap in May.");
223
- });
224
- });
211
+ const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
225
212
 
226
- describe("the executor's guardrail", () => {
227
- // Driven through `runGuardrail` rather than by calling the function, so what
228
- // is under test is the DEF: a guardrail dropped from `subagent()` fails here.
229
- const verdict = (answer: StepAnswer, searched: number) =>
230
- runGuardrail(executor, JSON.stringify(answer), {
231
- toolCalls: Array.from({ length: searched }, () => ({
232
- name: "search",
233
- input: { query: "anything" },
234
- })),
235
- });
236
-
237
- test("a settled step needs no search", () => {
238
- // Plenty of steps are summaries of what earlier ones found. A general "did
239
- // you search enough" would reject those and cost a whole extra run.
240
- expect(verdict({ finding: "Two of the three are already booked.", settled: true }, 0)).toBe(
241
- true,
242
- );
213
+ expect(outcome.settled).toBe(false);
214
+ expect(outcome.result).toBe("Flights are cheap in May.");
215
+ });
243
216
  });
244
217
 
245
- test("an unsettled step that really looked is accepted", () => {
246
- expect(verdict({ finding: "Could not find a fare for that date.", settled: false }, 2)).toBe(
247
- true,
248
- );
249
- });
218
+ describe("the executor's guardrail", () => {
219
+ // Driven through `runGuardrail` rather than by calling the function, so what
220
+ // is under test is the DEF: a guardrail dropped from `subagent()` fails here.
221
+ const verdict = (answer: StepAnswer, searched: number) =>
222
+ runGuardrail(executor, JSON.stringify(answer), {
223
+ toolCalls: Array.from({ length: searched }, () => ({
224
+ name: "search",
225
+ input: { query: "anything" },
226
+ })),
227
+ });
228
+
229
+ test("a settled step needs no search", () => {
230
+ // Plenty of steps are summaries of what earlier ones found. A general "did
231
+ // you search enough" would reject those and cost a whole extra run.
232
+ expect(verdict({ finding: "Two of the three are already booked.", settled: true }, 0)).toBe(
233
+ true,
234
+ );
235
+ });
250
236
 
251
- test("giving up without looking is sent back", () => {
252
- // The failure this template's headline claim is exposed to: reporting a
253
- // step unsettled from memory is cheaper than either honest move.
254
- expect(verdict({ finding: "I do not know what that costs.", settled: false }, 0)).toMatch(
255
- /without searching/,
256
- );
257
- });
258
- });
237
+ test("an unsettled step that really looked is accepted", () => {
238
+ expect(verdict({ finding: "Could not find a fare for that date.", settled: false }, 2)).toBe(
239
+ true,
240
+ );
241
+ });
259
242
 
260
- describe("the executor's search tool", () => {
261
- test("renders the hits the model reasons over", async () => {
262
- fakeSearch.mockResolvedValueOnce({
263
- results: [{ title: "Fares to Lisbon", url: "https://example.test/fares" }],
243
+ test("giving up without looking is sent back", () => {
244
+ // The failure this template's headline claim is exposed to: reporting a
245
+ // step unsettled from memory is cheaper than either honest move.
246
+ expect(verdict({ finding: "I do not know what that costs.", settled: false }, 0)).toMatch(
247
+ /without searching/,
248
+ );
264
249
  });
250
+ });
265
251
 
266
- const rendered = await searchTool.execute({ query: "lisbon flights" }, createToolContext());
252
+ describe("the executor's search tool", () => {
253
+ test("renders the hits the model reasons over", async () => {
254
+ fakeSearch.mockResolvedValueOnce({
255
+ results: [{ title: "Fares to Lisbon", url: "https://example.test/fares" }],
256
+ });
267
257
 
268
- expect(rendered).toContain("Fares to Lisbon");
269
- expect(rendered).toContain("https://example.test/fares");
270
- });
258
+ const rendered = await searchTool.execute({ query: "lisbon flights" }, createToolContext());
271
259
 
272
- test("a REFUSED search comes back as a failure, not as an empty web", async () => {
273
- // `webSearch` answers with `{ error }` rather than throwing, and measured,
274
- // DuckDuckGo answers 403 often enough to be the ordinary case. `orFail`
275
- // carries the refusal out as the tool's own `ToolFailure` — an empty list
276
- // would tell the executor there is nothing out there, and a thrown `Error`
277
- // would have the runtime log an ordinary 403 as an uncaught tool bug.
278
- fakeSearch.mockResolvedValueOnce({ error: "403 Forbidden" });
260
+ expect(rendered).toContain("Fares to Lisbon");
261
+ expect(rendered).toContain("https://example.test/fares");
262
+ });
279
263
 
280
- expect(await searchTool.execute({ query: "anything" }, createToolContext())).toEqual({
281
- error: "403 Forbidden",
264
+ test("a REFUSED search comes back as a failure, not as an empty web", async () => {
265
+ // `webSearch` answers with `{ error }` rather than throwing, and measured,
266
+ // DuckDuckGo answers 403 often enough to be the ordinary case. `orFail`
267
+ // carries the refusal out as the tool's own `ToolFailure` — an empty list
268
+ // would tell the executor there is nothing out there, and a thrown `Error`
269
+ // would have the runtime log an ordinary 403 as an uncaught tool bug.
270
+ fakeSearch.mockResolvedValueOnce({ error: "403 Forbidden" });
271
+
272
+ expect(await searchTool.execute({ query: "anything" }, createToolContext())).toEqual({
273
+ error: "403 Forbidden",
274
+ });
282
275
  });
283
- });
284
276
 
285
- test("the caller's signal reaches the fetch", async () => {
286
- // A tool body gets a signal and `CallOptions` takes one; until they were
287
- // joined, a caller who hung up mid-step left a search running against a
288
- // third party.
289
- fakeSearch.mockResolvedValueOnce({ results: [] });
290
- const ctx = createToolContext();
277
+ test("the caller's signal reaches the fetch", async () => {
278
+ // A tool body gets a signal and `CallOptions` takes one; until they were
279
+ // joined, a caller who hung up mid-step left a search running against a
280
+ // third party.
281
+ fakeSearch.mockResolvedValueOnce({ results: [] });
282
+ const ctx = createToolContext();
291
283
 
292
- await searchTool.execute({ query: "anything" }, ctx);
284
+ await searchTool.execute({ query: "anything" }, ctx);
293
285
 
294
- expect(fakeSearch.mock.calls[0]?.[0]).toMatchObject({ signal: ctx.signal });
295
- });
286
+ expect(fakeSearch.mock.calls[0]?.[0]).toMatchObject({ signal: ctx.signal });
287
+ });
296
288
 
297
- test("says so when the web really had nothing", async () => {
298
- fakeSearch.mockResolvedValueOnce({ results: [] });
299
- expect(await searchTool.execute({ query: "anything" }, createToolContext())).toBe(
300
- "No results.",
301
- );
289
+ test("says so when the web really had nothing", async () => {
290
+ fakeSearch.mockResolvedValueOnce({ results: [] });
291
+ expect(await searchTool.execute({ query: "anything" }, createToolContext())).toBe(
292
+ "No results.",
293
+ );
294
+ });
302
295
  });
303
- });
304
-
305
- describe("the executor's read tool", () => {
306
- test("hands back the page body, capped", async () => {
307
- fakeVisit.mockResolvedValueOnce({ content: "x".repeat(MAX_PAGE_CHARS + 500) });
308
296
 
309
- const body = await readTool.execute({ url: "https://example.test/fares" }, createToolContext());
297
+ describe("the executor's read tool", () => {
298
+ test("hands back the page body, capped", async () => {
299
+ fakeVisit.mockResolvedValueOnce({ content: "x".repeat(MAX_PAGE_CHARS + 500) });
310
300
 
311
- // A step is answered from a page's substance; the rest is context the run
312
- // pays for and the executor does not read.
313
- expect(String(body)).toHaveLength(MAX_PAGE_CHARS);
314
- });
301
+ const body = await readTool.execute(
302
+ { url: "https://example.test/fares" },
303
+ createToolContext(),
304
+ );
315
305
 
316
- test("a page that would not load is not a page that said nothing", async () => {
317
- fakeVisit.mockResolvedValueOnce({ error: "404 Not Found" });
306
+ // A step is answered from a page's substance; the rest is context the run
307
+ // pays for and the executor does not read.
308
+ expect(String(body)).toHaveLength(MAX_PAGE_CHARS);
309
+ });
318
310
 
319
- expect(
320
- await readTool.execute({ url: "https://example.test/gone" }, createToolContext()),
321
- ).toEqual({ error: "404 Not Found" });
322
- });
311
+ test("a page that would not load is not a page that said nothing", async () => {
312
+ fakeVisit.mockResolvedValueOnce({ error: "404 Not Found" });
323
313
 
324
- test("the caller's signal reaches the fetch here too", async () => {
325
- fakeVisit.mockResolvedValueOnce({ content: "anything" });
326
- const ctx = createToolContext();
314
+ expect(
315
+ await readTool.execute({ url: "https://example.test/gone" }, createToolContext()),
316
+ ).toEqual({ error: "404 Not Found" });
317
+ });
327
318
 
328
- await readTool.execute({ url: "https://example.test/fares" }, ctx);
319
+ test("the caller's signal reaches the fetch here too", async () => {
320
+ fakeVisit.mockResolvedValueOnce({ content: "anything" });
321
+ const ctx = createToolContext();
329
322
 
330
- expect(fakeVisit.mock.calls[0]?.[1]).toMatchObject({ signal: ctx.signal });
331
- });
332
- });
323
+ await readTool.execute({ url: "https://example.test/fares" }, ctx);
333
324
 
334
- describe("normalizeAct", () => {
335
- test("a plan with steps is a plan", () => {
336
- expect(normalizeAct({ kind: "plan", steps: ["Do X"] }, "fallback")).toEqual({
337
- kind: "plan",
338
- steps: ["Do X"],
325
+ expect(fakeVisit.mock.calls[0]?.[1]).toMatchObject({ signal: ctx.signal });
339
326
  });
340
327
  });
341
328
 
342
- test("'respond' with no response falls back rather than looping", () => {
343
- // The failure mode that matters on a phone call is a desk that never stops.
344
- expect(normalizeAct({ kind: "respond" }, "the last thing we know")).toEqual({
345
- kind: "respond",
346
- response: "the last thing we know",
329
+ describe("normalizeAct", () => {
330
+ test("a plan with steps is a plan", () => {
331
+ expect(normalizeAct({ kind: "plan", steps: ["Do X"] }, "fallback")).toEqual({
332
+ kind: "plan",
333
+ steps: ["Do X"],
334
+ });
347
335
  });
348
- });
349
336
 
350
- test("'plan' with no usable steps is read as an answer", () => {
351
- expect(normalizeAct({ kind: "plan", steps: [" "] }, "nothing left")).toEqual({
352
- kind: "respond",
353
- response: "nothing left",
337
+ test("'respond' with no response falls back rather than looping", () => {
338
+ // The failure mode that matters on a phone call is a desk that never stops.
339
+ expect(normalizeAct({ kind: "respond" }, "the last thing we know")).toEqual({
340
+ kind: "respond",
341
+ response: "the last thing we know",
342
+ });
354
343
  });
355
- expect(normalizeAct({ kind: "plan", response: "here it is" }, "nothing left")).toEqual({
356
- kind: "respond",
357
- response: "here it is",
344
+
345
+ test("'plan' with no usable steps is read as an answer", () => {
346
+ expect(normalizeAct({ kind: "plan", steps: [" "] }, "nothing left")).toEqual({
347
+ kind: "respond",
348
+ response: "nothing left",
349
+ });
350
+ expect(normalizeAct({ kind: "plan", response: "here it is" }, "nothing left")).toEqual({
351
+ kind: "respond",
352
+ response: "here it is",
353
+ });
358
354
  });
359
355
  });
360
- });
361
356
 
362
- // ─── 2. The tools ────────────────────────────────────────────────────────────
357
+ // ─── 2. The tools ────────────────────────────────────────────────────────────
363
358
 
364
- describe("start_plan", () => {
365
- test("stores the objective and the steps", async () => {
366
- const { ctx } = scriptedDesk({
367
- steps: ["Check prices", "Compare hotels", "Book"],
368
- });
369
- const result = expectToolOk(
370
- await runTool(startPlan, { objective: "a weekend in Lisbon" }, ctx),
371
- );
372
- expect(result.steps).toHaveLength(3);
373
-
374
- const state = stateOf(ctx);
375
- expect(state.objective).toBe("a weekend in Lisbon");
376
- expect(state.plan).toEqual(["Check prices", "Compare hotels", "Book"]);
377
- expect(state.pastSteps).toEqual([]);
378
- expect(state.revisions[0]).toContain("Planned 3 step(s)");
379
- });
359
+ describe("start_plan", () => {
360
+ test("stores the objective and the steps", async () => {
361
+ const { ctx } = scriptedDesk({
362
+ steps: ["Check prices", "Compare hotels", "Book"],
363
+ });
364
+ const result = expectToolOk(await run(startPlan, { objective: "a weekend in Lisbon" }, ctx));
365
+ expect(result.steps).toHaveLength(3);
366
+ // The flow moved with the data: one tool call did both.
367
+ expect(at(ctx)).toBe("working");
380
368
 
381
- test("a broken model call is reported rather than thrown at the turn", async () => {
382
- // The default `createToolContext` generate rejects — a bad key looks the
383
- // same from here.
384
- const ctx = createToolContext({});
385
- expect(await run("start_plan", { objective: "anything" }, ctx)).toMatchObject({
386
- error: expect.stringContaining("planner failed"),
369
+ const state = stateOf(ctx);
370
+ expect(state.objective).toBe("a weekend in Lisbon");
371
+ expect(state.plan).toEqual(["Check prices", "Compare hotels", "Book"]);
372
+ expect(state.pastSteps).toEqual([]);
373
+ expect(state.revisions[0]).toContain("Planned 3 step(s)");
387
374
  });
388
- });
389
- });
390
375
 
391
- describe("work_next_step", () => {
392
- test("is refused before there is a plan, by the flow rather than by the body", async () => {
393
- const { ctx } = scriptedDesk();
394
- // The gate is `when: "working"`, so the refusal names the state the call is
395
- // actually in and quotes that state's instruction — which is what the model
396
- // needs in order to do the right thing on its own next turn.
397
- expect(await run("work_next_step", ctx)).toMatchObject({
398
- error: expect.stringContaining('this conversation is at "idle"'),
376
+ test("a broken model call is reported rather than thrown at the turn", async () => {
377
+ // The default `createToolContext` generate rejects — a bad key looks the
378
+ // same from here.
379
+ const ctx = createToolContext({});
380
+ expect(await run(startPlan, { objective: "anything" }, ctx)).toMatchObject({
381
+ error: expect.stringContaining("planner failed"),
382
+ });
383
+ // A failed `prepare` opens no window and sends nothing: still idle.
384
+ expect(at(ctx)).toBe("idle");
399
385
  });
400
- expect(await run("work_next_step", ctx)).toMatchObject({
401
- error: expect.stringContaining("use start_plan"),
402
- });
403
- // Refused means the body did not run: nothing was claimed off the plan.
404
- expect(stateOf(ctx).pastSteps).toEqual([]);
405
386
  });
406
387
 
407
- test("does the head step, records it, and takes the replanner's next plan", async () => {
408
- const { ctx } = scriptedDesk({
409
- steps: ["Check prices", "Compare hotels"],
410
- answers: ["Fares are about 180 return."],
411
- acts: [{ kind: "plan", steps: ["Compare hotels"] }],
412
- });
413
- await run("start_plan", { objective: "a weekend in Lisbon" }, ctx);
414
-
415
- const first = expectDialogOk<{
416
- finished: boolean;
417
- step: string;
418
- result: string;
419
- remaining: string[];
420
- }>(await run("work_next_step", ctx));
421
- expect(first.result.finished).toBe(false);
422
- expect(first.result.step).toBe("Check prices");
423
- expect(first.result.result).toContain("180");
424
- expect(first.result.remaining).toEqual(["Compare hotels"]);
425
- // Still working: nothing was concluded, so the flow has not moved on.
426
- expect(first.state).toBe("working");
427
-
428
- const state = stateOf(ctx);
429
- expect(state.pastSteps).toHaveLength(1);
430
- expect(state.plan).toEqual(["Compare hotels"]);
431
- expect(state.response).toBeNull();
432
- });
388
+ describe("work_next_step", () => {
389
+ test("is refused before there is a plan, by the flow rather than by the body", async () => {
390
+ const { ctx } = scriptedDesk();
391
+ // The gate is `when: "working"`, so the refusal names the state the call is
392
+ // actually in and quotes that state's instruction — which is what the model
393
+ // needs in order to do the right thing on its own next turn.
394
+ expect(await run(workNextStep, ctx)).toMatchObject({
395
+ error: expect.stringContaining('this conversation is at "idle"'),
396
+ });
397
+ expect(await run(workNextStep, ctx)).toMatchObject({
398
+ error: expect.stringContaining("use start_plan"),
399
+ });
400
+ // Refused means the body did not run: nothing was claimed off the plan.
401
+ expect(stateOf(ctx).pastSteps).toEqual([]);
402
+ });
433
403
 
434
- test("a 'respond' act finishes the plan and clears what is left", async () => {
435
- const { ctx } = scriptedDesk({
436
- steps: ["Check prices", "Compare hotels"],
437
- answers: ["Fares are about 180 return."],
438
- acts: [{ kind: "respond", response: "Go in May — flights are about 180 return." }],
439
- });
440
- await run("start_plan", { objective: "a weekend in Lisbon" }, ctx);
441
- const answered = expectDialogOk<{ finished: boolean; response: string }>(
442
- await run("work_next_step", ctx),
443
- );
444
-
445
- expect(answered.result.finished).toBe(true);
446
- expect(answered.result.response).toContain("180");
447
- // A response is what sends ANSWERED — the flow and the data agree because
448
- // one tool call moved both.
449
- expect(answered.state).toBe("answered");
450
- expect(planFlow.position(ctx).state).toBe("answered");
451
-
452
- const state = stateOf(ctx);
453
- // The replanner deciding early is a good outcome, so the pending step goes.
454
- expect(state.plan).toEqual([]);
455
- expect(state.response).toBe(answered.result.response);
456
-
457
- // A finished plan is not worked again, and now it CANNOT be: the tool is
458
- // gated out of `answered` rather than returning a done-shaped result.
459
- expect(await run("work_next_step", ctx)).toMatchObject({
460
- error: expect.stringContaining('this conversation is at "answered"'),
461
- });
462
- expect(stateOf(ctx).pastSteps).toHaveLength(1);
463
- });
404
+ test("does the head step, records it, and takes the replanner's next plan", async () => {
405
+ const { ctx } = scriptedDesk({
406
+ steps: ["Check prices", "Compare hotels"],
407
+ answers: ["Fares are about 180 return."],
408
+ acts: [{ kind: "plan", steps: ["Compare hotels"] }],
409
+ });
410
+ await run(startPlan, { objective: "a weekend in Lisbon" }, ctx);
411
+
412
+ expect(expectToolOk(await run(workNextStep, ctx))).toMatchObject({
413
+ finished: false,
414
+ step: "Check prices",
415
+ result: expect.stringContaining("180"),
416
+ remaining: ["Compare hotels"],
417
+ });
418
+ // Still working: nothing was concluded, so the flow has not moved on.
419
+ expect(at(ctx)).toBe("working");
420
+
421
+ const state = stateOf(ctx);
422
+ expect(state.pastSteps).toHaveLength(1);
423
+ expect(state.plan).toEqual(["Compare hotels"]);
424
+ expect(state.response).toBeNull();
425
+ });
464
426
 
465
- test("the completed-step trail is capped, so the executor's prompt cannot grow forever", async () => {
466
- // `historyOf` renders every past step into the executor's prompt AND the
467
- // replanner's, so an uncapped list is a model bill that grows linearly with
468
- // the plan — the reason `planSlot` caps `pastSteps` at MAX_PAST_STEPS.
469
- const total = MAX_PAST_STEPS + 3;
470
- const { ctx } = scriptedDesk({
471
- steps: Array.from({ length: total }, (_, i) => `Step ${i + 1}`),
472
- answers: Array.from({ length: total }, (_, i) => `Found ${i + 1}.`),
473
- acts: Array.from({ length: total }, (_, i) => ({
474
- kind: "plan" as const,
475
- steps: Array.from({ length: total - i - 1 }, (_, j) => `Step ${i + j + 2}`),
476
- })),
477
- });
478
- await run("start_plan", { objective: "a long one" }, ctx);
479
- for (let i = 0; i < total; i++) await run("work_next_step", ctx);
480
-
481
- const state = stateOf(ctx);
482
- expect(state.pastSteps).toHaveLength(MAX_PAST_STEPS);
483
- // The OLDEST go: the replanner decides from what was just found, and its
484
- // fallback answer is the last entry.
485
- expect(state.pastSteps[0]?.step).toBe(`Step ${total - MAX_PAST_STEPS + 1}`);
486
- expect(state.pastSteps.at(-1)?.step).toBe(`Step ${total}`);
487
- });
427
+ test("a 'respond' act finishes the plan and clears what is left", async () => {
428
+ const { ctx } = scriptedDesk({
429
+ steps: ["Check prices", "Compare hotels"],
430
+ answers: ["Fares are about 180 return."],
431
+ acts: [{ kind: "respond", response: "Go in May — flights are about 180 return." }],
432
+ });
433
+ await run(startPlan, { objective: "a weekend in Lisbon" }, ctx);
434
+ const answered = expectToolOk(await run(workNextStep, ctx));
435
+ if (!("response" in answered)) throw new Error("expected an answer");
436
+
437
+ expect(answered.finished).toBe(true);
438
+ expect(answered.response).toContain("180");
439
+ // A response is what sends ANSWERED — the flow and the data agree because
440
+ // one tool call moved both.
441
+ expect(at(ctx)).toBe("answered");
442
+
443
+ const state = stateOf(ctx);
444
+ // The replanner deciding early is a good outcome, so the pending step goes.
445
+ expect(state.plan).toEqual([]);
446
+ expect(state.response).toBe(answered.response);
447
+
448
+ // A finished plan is not worked again, and now it CANNOT be: the tool is
449
+ // gated out of `answered` rather than returning a done-shaped result.
450
+ expect(await run(workNextStep, ctx)).toMatchObject({
451
+ error: expect.stringContaining('this conversation is at "answered"'),
452
+ });
453
+ expect(stateOf(ctx).pastSteps).toHaveLength(1);
454
+ });
488
455
 
489
- test("two independent contexts never share a plan", async () => {
490
- // What this really checks: the state lives in the SLOT and not in a
491
- // module-level variable. `createToolContext()` hands each call its own
492
- // detached slot store, so the isolation is per CONTEXT — two distinct
493
- // session ids would prove nothing extra, and `sessionSlot` could stop
494
- // keying by session with this still passing.
495
- const { ctx: first } = scriptedDesk({ steps: ["Only step"] });
496
- const { ctx: second } = scriptedDesk({ steps: ["Only step"] });
497
-
498
- await run("start_plan", { objective: "mine" }, first);
499
- expect(stateOf(second).objective).toBeNull();
500
- // The FLOW is per-session too, not just the plan — `second` is still idle.
501
- expect(planFlow.position(second).state).toBe("idle");
502
- expect(await run("work_next_step", second)).toMatchObject({
503
- error: expect.stringContaining('this conversation is at "idle"'),
456
+ test("the plan is per session, and both trails are capped, dropping the OLDEST", () => {
457
+ // `historyOf` renders every past step into the executor's prompt AND the
458
+ // replanner's, and `revisions` rides in every `syncState` frame — so both
459
+ // are bounded on the slot, and the oldest go: the replanner decides from
460
+ // what was just found, and a caller wants recent history read back.
461
+ expectSlotContract(planSlot, {
462
+ write: (plan) => {
463
+ plan.objective = "mine";
464
+ },
465
+ });
504
466
  });
505
- });
506
- });
507
467
 
508
- describe("revise_plan", () => {
509
- test("rewrites what is left, keeps what is done, and reopens a finished plan", async () => {
510
- const { ctx, model } = scriptedDesk({
511
- steps: ["Check Lisbon prices", "Book Lisbon"],
512
- answers: ["Lisbon is about 180 return."],
513
- acts: [
514
- { kind: "respond", response: "Lisbon in May, about 180." },
515
- { kind: "plan", steps: ["Check Porto prices"] },
516
- ],
517
- });
518
- await run("start_plan", { objective: "a weekend in Lisbon" }, ctx);
519
- await run("work_next_step", ctx);
520
- expect(stateOf(ctx).response).not.toBeNull();
521
-
522
- const revised = expectDialogOk<{ finished: boolean; remaining: string[] }>(
523
- await run("revise_plan", { instruction: "make it Porto instead" }, ctx),
524
- );
525
- expect(revised.result.finished).toBe(false);
526
- expect(revised.result.remaining).toEqual(["Check Porto prices"]);
527
- // REOPENED: the one transition that goes backwards, and the reason
528
- // `revise_plan` is legal in `answered` at all.
529
- expect(revised.state).toBe("working");
530
-
531
- const state = stateOf(ctx);
532
- // The old answer is no longer the answer — the caller moved the goalposts.
533
- expect(state.response).toBeNull();
534
- // Completed work survives a revision; that is what "only add steps that
535
- // still NEED to be done" means.
536
- expect(state.pastSteps).toHaveLength(1);
537
- expect(state.revisions.at(-1)).toContain("make it Porto instead");
538
- // The caller's words reach the replanner, which is the whole node.
539
- expect(model.calls.at(-1)?.prompt).toContain("make it Porto instead");
540
- });
468
+ test("the FLOW is per session too, not just the plan", async () => {
469
+ const { ctx: first } = scriptedDesk({ steps: ["Only step"] });
470
+ const { ctx: second } = scriptedDesk({ steps: ["Only step"] });
541
471
 
542
- test("is refused before there is a plan", async () => {
543
- const { ctx } = scriptedDesk();
544
- expect(await run("revise_plan", { instruction: "change it" }, ctx)).toMatchObject({
545
- error: expect.stringContaining('this conversation is at "idle"'),
472
+ await run(startPlan, { objective: "mine" }, first);
473
+ expect(at(second)).toBe("idle");
474
+ expect(await run(workNextStep, second)).toMatchObject({
475
+ error: expect.stringContaining('this conversation is at "idle"'),
476
+ });
546
477
  });
547
478
  });
548
479
 
549
- test("the revision trail is capped, because it rides in every syncState frame", async () => {
550
- // The other cap `planSlot` declares, and the one nothing used to exercise:
551
- // `revisions` is pushed to by every tool that changes the plan and is sent
552
- // to the browser on each of them, so an uncapped trail is a frame that grows
553
- // for the whole call.
554
- const { ctx } = scriptedDesk({ steps: ["Only step"] });
555
- await run("start_plan", { objective: "a weekend in Lisbon" }, ctx);
556
- for (let index = 0; index < MAX_REVISIONS; index++) {
557
- await run("revise_plan", { instruction: `change ${index}` }, ctx);
558
- }
559
-
560
- const state = stateOf(ctx);
561
- expect(state.revisions).toHaveLength(MAX_REVISIONS);
562
- // The OLDEST goes, so `start_plan`'s own entry is the one pushed out — the
563
- // trail a caller wants read back is what has happened lately.
564
- expect(state.revisions[0]).toContain("change 0");
565
- expect(state.revisions.at(-1)).toContain(`change ${MAX_REVISIONS - 1}`);
566
- });
480
+ describe("revise_plan", () => {
481
+ test("rewrites what is left, keeps what is done, and reopens a finished plan", async () => {
482
+ const { ctx, model } = scriptedDesk({
483
+ steps: ["Check Lisbon prices", "Book Lisbon"],
484
+ answers: ["Lisbon is about 180 return."],
485
+ acts: [
486
+ { kind: "respond", response: "Lisbon in May, about 180." },
487
+ { kind: "plan", steps: ["Check Porto prices"] },
488
+ ],
489
+ });
490
+ await run(startPlan, { objective: "a weekend in Lisbon" }, ctx);
491
+ await run(workNextStep, ctx);
492
+ expect(stateOf(ctx).response).not.toBeNull();
493
+
494
+ const revised = expectToolOk(
495
+ await run(revisePlan, { instruction: "make it Porto instead" }, ctx),
496
+ );
497
+ expect(revised).toMatchObject({ finished: false, remaining: ["Check Porto prices"] });
498
+ // REOPENED: the one transition that goes backwards, and the reason
499
+ // `revise_plan` is legal in `answered` at all.
500
+ expect(at(ctx)).toBe("working");
501
+
502
+ const state = stateOf(ctx);
503
+ // The old answer is no longer the answer — the caller moved the goalposts.
504
+ expect(state.response).toBeNull();
505
+ // Completed work survives a revision; that is what "only add steps that
506
+ // still NEED to be done" means.
507
+ expect(state.pastSteps).toHaveLength(1);
508
+ expect(state.revisions.at(-1)).toContain("make it Porto instead");
509
+ // The caller's words reach the replanner, which is the whole node.
510
+ expect(model.calls.at(-1)?.prompt).toContain("make it Porto instead");
511
+ });
567
512
 
568
- test("a revision that answers outright lands in `answered`", async () => {
569
- const { ctx } = scriptedDesk({
570
- steps: ["Check Lisbon prices"],
571
- acts: [{ kind: "respond", response: "Nothing to do — you already booked it." }],
572
- });
573
- await run("start_plan", { objective: "a weekend in Lisbon" }, ctx);
574
- const revised = expectDialogOk<{ finished: boolean }>(
575
- await run("revise_plan", { instruction: "never mind, it is booked" }, ctx),
576
- );
577
- expect(revised.result.finished).toBe(true);
578
- expect(revised.state).toBe("answered");
579
- });
580
- });
513
+ test("is refused before there is a plan", async () => {
514
+ const { ctx } = scriptedDesk();
515
+ expect(await run(revisePlan, { instruction: "change it" }, ctx)).toMatchObject({
516
+ error: expect.stringContaining('this conversation is at "idle"'),
517
+ });
518
+ });
581
519
 
582
- describe("plan_status", () => {
583
- test("reports done, remaining and the answer", async () => {
584
- const { ctx } = scriptedDesk({
585
- steps: ["Check prices", "Book"],
586
- answers: ["About 180 return."],
587
- acts: [{ kind: "plan", steps: ["Book"] }],
588
- });
589
- // Legal in every state, so it READS the position rather than being gated on
590
- // one — and "no plan yet" is the flow's own answer, not a third derivation
591
- // of `!objective`.
592
- expect(await run("plan_status", ctx)).toMatchObject({
593
- stage: "idle",
594
- next: expect.stringContaining("start_plan"),
595
- objective: null,
596
- });
597
-
598
- await run("start_plan", { objective: "a weekend in Lisbon" }, ctx);
599
- await run("work_next_step", ctx);
600
- expect(await run("plan_status", ctx)).toMatchObject({
601
- stage: "working",
602
- objective: "a weekend in Lisbon",
603
- remaining: ["Book"],
604
- response: null,
520
+ test("a revision that answers outright lands in `answered`", async () => {
521
+ const { ctx } = scriptedDesk({
522
+ steps: ["Check Lisbon prices"],
523
+ acts: [{ kind: "respond", response: "Nothing to do — you already booked it." }],
524
+ });
525
+ await run(startPlan, { objective: "a weekend in Lisbon" }, ctx);
526
+ const revised = expectToolOk(
527
+ await run(revisePlan, { instruction: "never mind, it is booked" }, ctx),
528
+ );
529
+ expect(revised.finished).toBe(true);
530
+ expect(at(ctx)).toBe("answered");
605
531
  });
606
532
  });
607
- });
608
533
 
609
- // ─── 3. The projection contract with client.tsx ─────────────────────────────
610
-
611
- describe("planView projection", () => {
612
- test("an untouched call projects an empty plan, not undefined", () => {
613
- // Exactly the frame `client.tsx` renders before the first push — it passes
614
- // this same projection to `useAgentState`.
615
- expect(planSlot.projected()).toEqual({
616
- objective: null,
617
- plan: [],
618
- done: [],
619
- response: null,
620
- revisions: [],
621
- progress: 0,
534
+ describe("plan_status", () => {
535
+ test("reports done, remaining and the answer", async () => {
536
+ const { ctx } = scriptedDesk({
537
+ steps: ["Check prices", "Book"],
538
+ answers: ["About 180 return."],
539
+ acts: [{ kind: "plan", steps: ["Book"] }],
540
+ });
541
+ // Legal in every state (no `when`), and the envelope carries the flow's
542
+ // own position — "no plan yet" is the flow's answer, not a third
543
+ // derivation of `!objective`.
544
+ expect(await run(planStatus, ctx)).toMatchObject({
545
+ state: "idle",
546
+ instruction: expect.stringContaining("start_plan"),
547
+ result: { reads: "no plan yet", objective: null },
548
+ });
549
+
550
+ await run(startPlan, { objective: "a weekend in Lisbon" }, ctx);
551
+ await run(workNextStep, ctx);
552
+ expect(await run(planStatus, ctx)).toMatchObject({
553
+ state: "working",
554
+ result: { objective: "a weekend in Lisbon", remaining: ["Book"], response: null },
555
+ });
622
556
  });
623
557
  });
624
558
 
625
- test("progress is derived once, so the bar and any spoken count agree", async () => {
626
- const { ctx } = scriptedDesk({
627
- steps: ["One", "Two", "Three"],
628
- answers: ["Done one."],
629
- acts: [{ kind: "plan", steps: ["Two", "Three"] }],
559
+ // ─── 3. The projection contract with client.tsx ─────────────────────────────
560
+
561
+ describe("the plan projection", () => {
562
+ test("an untouched call projects an empty plan, not undefined", () => {
563
+ // Exactly the frame `client.tsx` renders before the first push — it passes
564
+ // this same projection to `useAgentState`.
565
+ expect(planSlot.projected()).toEqual({
566
+ objective: null,
567
+ plan: [],
568
+ done: [],
569
+ response: null,
570
+ revisions: [],
571
+ progress: 0,
572
+ });
630
573
  });
631
- await run("start_plan", { objective: "three things" }, ctx);
632
- expect(planView(stateOf(ctx)).progress).toBe(0);
633
574
 
634
- await run("work_next_step", ctx);
635
- const view = planView(stateOf(ctx));
636
- expect(view.progress).toBeCloseTo(1 / 3, 5);
637
- expect(view.done[0]?.step).toBe("One");
638
- expect(view.plan).toEqual(["Two", "Three"]);
575
+ test("progress is derived once, so the bar and any spoken count agree", async () => {
576
+ const { ctx } = scriptedDesk({
577
+ steps: ["One", "Two", "Three"],
578
+ answers: ["Done one."],
579
+ acts: [{ kind: "plan", steps: ["Two", "Three"] }],
580
+ });
581
+ await run(startPlan, { objective: "three things" }, ctx);
582
+ expect(planSlot.projected(stateOf(ctx)).progress).toBe(0);
583
+
584
+ await run(workNextStep, ctx);
585
+ const view = planSlot.projected(stateOf(ctx));
586
+ expect(view.progress).toBeCloseTo(1 / 3, 5);
587
+ expect(view.done[0]?.step).toBe("One");
588
+ expect(view.plan).toEqual(["Two", "Three"]);
589
+ });
639
590
  });
640
591
  });