@alexkroman1/aai-cli 15.0.0 → 16.0.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 (363) hide show
  1. package/README.md +8 -5
  2. package/bin.mjs +12 -3
  3. package/dist/_build-target-55dJisQ-.mjs +649 -0
  4. package/dist/_build-target.d.ts +105 -108
  5. package/dist/_deno-output.d.ts +23 -0
  6. package/dist/_deno-target.d.ts +73 -0
  7. package/dist/{_init-Bsi3DZNJ.mjs → _init-BzQbV8Zh.mjs} +3 -1
  8. package/dist/_modal-app.d.ts +77 -0
  9. package/dist/_modal-output.d.ts +31 -0
  10. package/dist/_modal-target.d.ts +64 -0
  11. package/dist/_target-bundle.d.ts +27 -0
  12. package/dist/_target-drain.d.ts +44 -0
  13. package/dist/_target-output.d.ts +63 -0
  14. package/dist/{_templates-CIlJ3Vay.mjs → _templates-CuP74F8D.mjs} +94 -4
  15. package/dist/_templates.d.ts +14 -1
  16. package/dist/_vercel-output.d.ts +4 -19
  17. package/dist/_vercel-target.d.ts +169 -0
  18. package/dist/{test-D032V2cA.mjs → _vitest-runner-AVR9VtXh.mjs} +28 -68
  19. package/dist/_vitest-runner.d.ts +154 -0
  20. package/dist/build-ButI2IKc.mjs +689 -0
  21. package/dist/build.d.ts +11 -0
  22. package/dist/cli.mjs +14 -20
  23. package/dist/{dev-Bx9gYBHM.mjs → dev-kodAY23K.mjs} +7 -1
  24. package/dist/{eval-B3I7FqN9.mjs → eval-DvoSz7SZ.mjs} +1 -1
  25. package/dist/{init-CFyusRbq.mjs → init-D363Ls5u.mjs} +13 -39
  26. package/dist/init.d.ts +5 -10
  27. package/dist/scaffold/CLAUDE.md +185 -35
  28. package/dist/scaffold/package.json +4 -4
  29. package/dist/start.mjs +3 -1
  30. package/dist/{studio-C_zuRC_z.mjs → studio-CtRBVVFR.mjs} +1 -1
  31. package/dist/templates/briefing-desk/agent.eval.test.ts +34 -6
  32. package/dist/templates/briefing-desk/agent.test.ts +347 -55
  33. package/dist/templates/briefing-desk/agent.ts +12 -0
  34. package/dist/templates/briefing-desk/shared.ts +220 -31
  35. package/dist/templates/briefing-desk/slack.ts +108 -0
  36. package/dist/templates/briefing-desk/system-prompt.md +12 -2
  37. package/dist/templates/briefing-desk/tools/briefing_so_far.ts +15 -7
  38. package/dist/templates/briefing-desk/tools/research_topic.ts +20 -28
  39. package/dist/templates/briefing-desk/tools/send_briefing.ts +77 -0
  40. package/dist/templates/briefing-desk/tools/verify_claim.ts +60 -14
  41. package/dist/templates/call-audit/agent.eval.test.ts +5 -0
  42. package/dist/templates/call-audit/agent.test.ts +6 -1
  43. package/dist/templates/call-audit/agent.ts +10 -23
  44. package/dist/templates/call-audit/client.tsx +30 -55
  45. package/dist/templates/call-audit/guards.test.ts +233 -0
  46. package/dist/templates/call-audit/workflows/audit.ts +95 -16
  47. package/dist/templates/call-audit/workflows/ingest.ts +107 -88
  48. package/dist/templates/call-audit/workflows/media.ts +98 -7
  49. package/dist/templates/call-audit/workflows/summarize.ts +35 -31
  50. package/dist/templates/call-audit/workflows/sync-api.ts +15 -6
  51. package/dist/templates/code-interpreter/agent.eval.test.ts +104 -56
  52. package/dist/templates/code-interpreter/agent.test.ts +44 -56
  53. package/dist/templates/code-interpreter/system-prompt.md +1 -1
  54. package/dist/templates/dispatch-center/agent.eval.test.ts +61 -24
  55. package/dist/templates/dispatch-center/agent.test.ts +253 -48
  56. package/dist/templates/dispatch-center/agent.ts +28 -1
  57. package/dist/templates/dispatch-center/client.tsx +126 -201
  58. package/dist/templates/dispatch-center/events.ts +48 -0
  59. package/dist/templates/dispatch-center/shared.ts +42 -1
  60. package/dist/templates/dispatch-center/tools/incident_create.ts +3 -2
  61. package/dist/templates/dispatch-center/tools/incident_escalate.ts +2 -1
  62. package/dist/templates/dispatch-center/tools/ops_dashboard.ts +35 -15
  63. package/dist/templates/dispatch-center/tools/ops_run_scenario.ts +3 -1
  64. package/dist/templates/dispatch-center/tools/resources_dispatch.ts +2 -2
  65. package/dist/templates/executive-assistant/agent.eval.test.ts +233 -0
  66. package/dist/templates/executive-assistant/agent.test.ts +672 -0
  67. package/dist/templates/executive-assistant/agent.ts +50 -0
  68. package/dist/templates/executive-assistant/calendar.test.ts +198 -0
  69. package/dist/templates/executive-assistant/client.tsx +195 -0
  70. package/dist/templates/executive-assistant/inbox.ts +233 -0
  71. package/dist/templates/executive-assistant/meeting.ts +138 -0
  72. package/dist/templates/executive-assistant/nodes.ts +152 -0
  73. package/dist/templates/executive-assistant/prompts.ts +331 -0
  74. package/dist/templates/executive-assistant/review.ts +425 -0
  75. package/dist/templates/executive-assistant/shared.ts +490 -0
  76. package/dist/templates/executive-assistant/system-prompt.md +15 -0
  77. package/dist/templates/executive-assistant/tools/accept.ts +10 -0
  78. package/dist/templates/executive-assistant/tools/ask_question.ts +30 -0
  79. package/dist/templates/executive-assistant/tools/draft_reply.ts +67 -0
  80. package/dist/templates/executive-assistant/tools/edit.ts +10 -0
  81. package/dist/templates/executive-assistant/tools/ignore.ts +10 -0
  82. package/dist/templates/executive-assistant/tools/inbox_status.ts +27 -0
  83. package/dist/templates/executive-assistant/tools/meeting_assistant.ts +52 -0
  84. package/dist/templates/executive-assistant/tools/new_email.ts +50 -0
  85. package/dist/templates/executive-assistant/tools/open_email.ts +165 -0
  86. package/dist/templates/executive-assistant/tools/respond.ts +10 -0
  87. package/dist/templates/executive-assistant/tools/review_memory.ts +22 -0
  88. package/dist/templates/executive-assistant/tools/send_calendar_invite.ts +68 -0
  89. package/dist/templates/executive-assistant/tools/triage_inbox.ts +75 -0
  90. package/dist/templates/health-assistant/agent.test.ts +134 -15
  91. package/dist/templates/health-assistant/agent.ts +8 -1
  92. package/dist/templates/health-assistant/fda.test.ts +130 -0
  93. package/dist/templates/health-assistant/fda.ts +75 -16
  94. package/dist/templates/health-assistant/system-prompt.md +9 -0
  95. package/dist/templates/health-assistant/tools/check_drug_interaction.ts +5 -2
  96. package/dist/templates/health-assistant/tools/medication_lookup.ts +16 -11
  97. package/dist/templates/hiring-desk/agent.eval.test.ts +242 -0
  98. package/dist/templates/hiring-desk/agent.test.ts +1021 -0
  99. package/dist/templates/hiring-desk/agent.ts +38 -0
  100. package/dist/templates/hiring-desk/client.tsx +154 -0
  101. package/dist/templates/hiring-desk/crews.ts +432 -0
  102. package/dist/templates/hiring-desk/leads.json +86 -0
  103. package/dist/templates/hiring-desk/screening-lock.test.ts +77 -0
  104. package/dist/templates/hiring-desk/screening-lock.ts +51 -0
  105. package/dist/templates/hiring-desk/shared.ts +480 -0
  106. package/dist/templates/hiring-desk/system-prompt.md +21 -0
  107. package/dist/templates/hiring-desk/tools/candidate_details.ts +49 -0
  108. package/dist/templates/hiring-desk/tools/proceed_to_emails.ts +127 -0
  109. package/dist/templates/hiring-desk/tools/read_email.ts +50 -0
  110. package/dist/templates/hiring-desk/tools/rescore_with_feedback.ts +140 -0
  111. package/dist/templates/hiring-desk/tools/screen_candidates.ts +128 -0
  112. package/dist/templates/hiring-desk/tools/screening_status.ts +51 -0
  113. package/dist/templates/hotel-desk/agent.eval.test.ts +177 -0
  114. package/dist/templates/hotel-desk/agent.test.ts +1128 -0
  115. package/dist/templates/hotel-desk/agent.ts +63 -0
  116. package/dist/templates/hotel-desk/booking.ts +159 -0
  117. package/dist/templates/hotel-desk/card.ts +92 -0
  118. package/dist/templates/hotel-desk/catalogs.ts +219 -0
  119. package/dist/templates/hotel-desk/client.tsx +137 -0
  120. package/dist/templates/hotel-desk/concierge.ts +99 -0
  121. package/dist/templates/hotel-desk/desk-seams.test.ts +334 -0
  122. package/dist/templates/hotel-desk/desk.ts +224 -0
  123. package/dist/templates/hotel-desk/disputes.ts +216 -0
  124. package/dist/templates/hotel-desk/events.ts +79 -0
  125. package/dist/templates/hotel-desk/hotel.ts +412 -0
  126. package/dist/templates/hotel-desk/policies.ts +209 -0
  127. package/dist/templates/hotel-desk/records.ts +384 -0
  128. package/dist/templates/hotel-desk/restaurant.ts +147 -0
  129. package/dist/templates/hotel-desk/seed.ts +955 -0
  130. package/dist/templates/hotel-desk/shared.ts +354 -0
  131. package/dist/templates/hotel-desk/system-prompt.md +76 -0
  132. package/dist/templates/hotel-desk/tools/abandon_booking.ts +30 -0
  133. package/dist/templates/hotel-desk/tools/add_to_waitlist.ts +41 -0
  134. package/dist/templates/hotel-desk/tools/book_airport_car.ts +57 -0
  135. package/dist/templates/hotel-desk/tools/book_business_center.ts +44 -0
  136. package/dist/templates/hotel-desk/tools/book_spa_appointment.ts +39 -0
  137. package/dist/templates/hotel-desk/tools/book_tour.ts +35 -0
  138. package/dist/templates/hotel-desk/tools/cancel_restaurant_reservation.ts +25 -0
  139. package/dist/templates/hotel-desk/tools/cancel_room_booking.ts +63 -0
  140. package/dist/templates/hotel-desk/tools/check_restaurant_availability.ts +24 -0
  141. package/dist/templates/hotel-desk/tools/check_room_availability.ts +40 -0
  142. package/dist/templates/hotel-desk/tools/choose_room.ts +93 -0
  143. package/dist/templates/hotel-desk/tools/confirm_booking.ts +153 -0
  144. package/dist/templates/hotel-desk/tools/dispatch_emergency.ts +61 -0
  145. package/dist/templates/hotel-desk/tools/dispute_charge.ts +90 -0
  146. package/dist/templates/hotel-desk/tools/flag_late_arrival.ts +26 -0
  147. package/dist/templates/hotel-desk/tools/lookup_booking.ts +48 -0
  148. package/dist/templates/hotel-desk/tools/lookup_guest_history.ts +28 -0
  149. package/dist/templates/hotel-desk/tools/lookup_invoice.ts +26 -0
  150. package/dist/templates/hotel-desk/tools/lookup_policy.ts +20 -0
  151. package/dist/templates/hotel-desk/tools/lookup_restaurant_reservation.ts +27 -0
  152. package/dist/templates/hotel-desk/tools/modify_restaurant_reservation.ts +75 -0
  153. package/dist/templates/hotel-desk/tools/order_flowers.ts +40 -0
  154. package/dist/templates/hotel-desk/tools/record_card.ts +46 -0
  155. package/dist/templates/hotel-desk/tools/record_followup.ts +50 -0
  156. package/dist/templates/hotel-desk/tools/record_group_inquiry.ts +44 -0
  157. package/dist/templates/hotel-desk/tools/record_guest_details.ts +71 -0
  158. package/dist/templates/hotel-desk/tools/reinstate_booking.ts +65 -0
  159. package/dist/templates/hotel-desk/tools/request_flight_reconfirmation.ts +54 -0
  160. package/dist/templates/hotel-desk/tools/resend_confirmation.ts +39 -0
  161. package/dist/templates/hotel-desk/tools/reserve_table.ts +87 -0
  162. package/dist/templates/hotel-desk/tools/resolve_room_conflict.ts +48 -0
  163. package/dist/templates/hotel-desk/tools/schedule_wakeup_call.ts +48 -0
  164. package/dist/templates/hotel-desk/tools/set_do_not_disturb.ts +28 -0
  165. package/dist/templates/hotel-desk/tools/set_extras.ts +51 -0
  166. package/dist/templates/hotel-desk/tools/set_stay.ts +97 -0
  167. package/dist/templates/hotel-desk/tools/start_booking_modification.ts +57 -0
  168. package/dist/templates/hotel-desk/tools/start_room_booking.ts +49 -0
  169. package/dist/templates/hotel-desk/tools/take_guest_message.ts +71 -0
  170. package/dist/templates/hotel-desk/tools/transfer_call.ts +47 -0
  171. package/dist/templates/hotel-desk/tools/update_card.ts +45 -0
  172. package/dist/templates/hotel-desk/tools/verify_booking.ts +95 -0
  173. package/dist/templates/infocom-adventure/agent.eval.test.ts +33 -1
  174. package/dist/templates/infocom-adventure/agent.test.ts +207 -52
  175. package/dist/templates/infocom-adventure/agent.ts +14 -3
  176. package/dist/templates/infocom-adventure/client.tsx +138 -176
  177. package/dist/templates/infocom-adventure/shared.ts +126 -6
  178. package/dist/templates/infocom-adventure/system-prompt.md +4 -4
  179. package/dist/templates/infocom-adventure/tools/game_state_drop.ts +20 -4
  180. package/dist/templates/infocom-adventure/tools/game_state_get.ts +6 -5
  181. package/dist/templates/infocom-adventure/tools/game_state_score.ts +9 -3
  182. package/dist/templates/link-digest/agent.eval.test.ts +8 -0
  183. package/dist/templates/link-digest/agent.test.ts +285 -29
  184. package/dist/templates/link-digest/agent.ts +9 -0
  185. package/dist/templates/link-digest/api-client.ts +144 -0
  186. package/dist/templates/link-digest/client.tsx +11 -30
  187. package/dist/templates/link-digest/workflows/digest.ts +72 -24
  188. package/dist/templates/night-owl/agent.eval.test.ts +55 -40
  189. package/dist/templates/night-owl/agent.test.ts +146 -12
  190. package/dist/templates/night-owl/client.tsx +50 -17
  191. package/dist/templates/night-owl/shared.ts +33 -2
  192. package/dist/templates/night-owl/system-prompt.md +3 -0
  193. package/dist/templates/night-owl/tools/recommend.ts +4 -1
  194. package/dist/templates/night-owl/tools/revisit.ts +49 -0
  195. package/dist/templates/pipeline-simple/agent.eval.test.ts +7 -6
  196. package/dist/templates/pipeline-simple/agent.test.ts +48 -91
  197. package/dist/templates/pipeline-simple/modes.test.ts +151 -0
  198. package/dist/templates/pipeline-simple/stages.test.ts +332 -0
  199. package/dist/templates/pizza-ordering/agent.test.ts +94 -38
  200. package/dist/templates/pizza-ordering/client.tsx +10 -5
  201. package/dist/templates/pizza-ordering/shared.ts +65 -6
  202. package/dist/templates/pizza-ordering/tools/add_pizza.ts +2 -7
  203. package/dist/templates/pizza-ordering/tools/place_order.ts +9 -6
  204. package/dist/templates/pizza-ordering/tools/remove_pizza.ts +6 -11
  205. package/dist/templates/pizza-ordering/tools/update_pizza.ts +8 -9
  206. package/dist/templates/pizza-ordering/tools/view_order.ts +2 -3
  207. package/dist/templates/plan-and-execute/agent.eval.test.ts +14 -6
  208. package/dist/templates/plan-and-execute/agent.test.ts +300 -113
  209. package/dist/templates/plan-and-execute/client.tsx +18 -7
  210. package/dist/templates/plan-and-execute/procedure.ts +162 -64
  211. package/dist/templates/plan-and-execute/prompts.ts +51 -15
  212. package/dist/templates/plan-and-execute/shared.ts +151 -45
  213. package/dist/templates/plan-and-execute/tools/plan_status.ts +15 -6
  214. package/dist/templates/plan-and-execute/tools/revise_plan.ts +2 -2
  215. package/dist/templates/plan-and-execute/tools/start_plan.ts +2 -2
  216. package/dist/templates/plan-and-execute/tools/work_next_step.ts +15 -13
  217. package/dist/templates/podcast-digest/agent.eval.test.ts +12 -7
  218. package/dist/templates/podcast-digest/agent.test.ts +126 -51
  219. package/dist/templates/podcast-digest/client.tsx +104 -68
  220. package/dist/templates/podcast-digest/workflows/digest.ts +71 -48
  221. package/dist/templates/podcast-digest/workflows/feeds.ts +5 -7
  222. package/dist/templates/podcast-digest/workflows/slack.ts +82 -17
  223. package/dist/templates/recap-workflow/agent.eval.test.ts +193 -209
  224. package/dist/templates/recap-workflow/agent.test.ts +207 -26
  225. package/dist/templates/recap-workflow/tools/recap_status.ts +2 -2
  226. package/dist/templates/recap-workflow/workflows/recap.ts +39 -28
  227. package/dist/templates/redline/agent.eval.test.ts +40 -3
  228. package/dist/templates/redline/agent.test.ts +216 -6
  229. package/dist/templates/redline/agent.ts +54 -34
  230. package/dist/templates/redline/client.tsx +82 -126
  231. package/dist/templates/redline/form.ts +74 -0
  232. package/dist/templates/redline/workflows/prompts.ts +3 -3
  233. package/dist/templates/redline/workflows/redline.ts +73 -4
  234. package/dist/templates/research-workflow/agent.eval.test.ts +152 -150
  235. package/dist/templates/research-workflow/agent.test.ts +436 -126
  236. package/dist/templates/research-workflow/agent.ts +20 -5
  237. package/dist/templates/research-workflow/tools/file_it_now.ts +11 -1
  238. package/dist/templates/research-workflow/tools/research_status.ts +39 -4
  239. package/dist/templates/research-workflow/workflows/filing.ts +164 -0
  240. package/dist/templates/research-workflow/workflows/notes.ts +69 -0
  241. package/dist/templates/research-workflow/workflows/prompts.ts +45 -31
  242. package/dist/templates/research-workflow/workflows/research.ts +227 -280
  243. package/dist/templates/research-workflow/workflows/review.ts +43 -0
  244. package/dist/templates/retail/address.ts +29 -35
  245. package/dist/templates/retail/agent.eval.test.ts +36 -16
  246. package/dist/templates/retail/agent.test.ts +104 -26
  247. package/dist/templates/retail/agent.ts +12 -0
  248. package/dist/templates/retail/cancel.ts +39 -42
  249. package/dist/templates/retail/client.tsx +111 -176
  250. package/dist/templates/retail/payment.ts +38 -43
  251. package/dist/templates/retail/pending.test.ts +16 -8
  252. package/dist/templates/retail/registry.test.ts +108 -49
  253. package/dist/templates/retail/resolve.test.ts +2 -63
  254. package/dist/templates/retail/resolve.ts +16 -56
  255. package/dist/templates/retail/returns.ts +53 -54
  256. package/dist/templates/retail/seed.test.ts +2 -1
  257. package/dist/templates/retail/shared.ts +58 -14
  258. package/dist/templates/retail/store.test.ts +40 -29
  259. package/dist/templates/retail/store.ts +60 -23
  260. package/dist/templates/retail/swap.ts +78 -81
  261. package/dist/templates/retail/tools/find_user_id_by_name_zip.ts +2 -1
  262. package/dist/templates/roadside-assist/agent.eval.test.ts +164 -0
  263. package/dist/templates/roadside-assist/agent.test.ts +617 -0
  264. package/dist/templates/roadside-assist/agent.ts +85 -0
  265. package/dist/templates/roadside-assist/call.ts +237 -0
  266. package/dist/templates/roadside-assist/events.ts +92 -0
  267. package/dist/templates/roadside-assist/shared.ts +334 -0
  268. package/dist/templates/roadside-assist/system-prompt.md +37 -0
  269. package/dist/templates/roadside-assist/tools/acknowledge_disclosure.ts +47 -0
  270. package/dist/templates/roadside-assist/tools/dispatch_truck.ts +148 -0
  271. package/dist/templates/roadside-assist/tools/job_status.ts +38 -0
  272. package/dist/templates/roadside-assist/tools/lookup_coverage.ts +72 -0
  273. package/dist/templates/roadside-assist/tools/report_location.ts +79 -0
  274. package/dist/templates/roadside-assist/tools/service_disclosure.ts +45 -0
  275. package/dist/templates/roadside-assist/yard.test.ts +158 -0
  276. package/dist/templates/roadside-assist/yard.ts +183 -0
  277. package/dist/templates/simple/agent.eval.test.ts +4 -1
  278. package/dist/templates/simple/agent.test.ts +54 -31
  279. package/dist/templates/solo-rpg/agent.eval.test.ts +19 -11
  280. package/dist/templates/solo-rpg/agent.test.ts +402 -175
  281. package/dist/templates/solo-rpg/agent.ts +14 -3
  282. package/dist/templates/solo-rpg/client.tsx +10 -10
  283. package/dist/templates/solo-rpg/shared.ts +198 -79
  284. package/dist/templates/solo-rpg/tools/action_roll.ts +7 -3
  285. package/dist/templates/solo-rpg/tools/burn_momentum.ts +16 -8
  286. package/dist/templates/solo-rpg/tools/oracle.ts +7 -7
  287. package/dist/templates/solo-rpg/tools/setup_character.ts +5 -5
  288. package/dist/templates/solo-rpg/tools/update_state.ts +29 -18
  289. package/dist/templates/spoken-summary/agent.test.ts +70 -15
  290. package/dist/templates/spoken-summary/agent.ts +25 -21
  291. package/dist/templates/spoken-summary/client.tsx +68 -88
  292. package/dist/templates/spoken-summary/workflows/summarize.ts +26 -8
  293. package/dist/templates/support-line/agent.test.ts +167 -36
  294. package/dist/templates/support-line/client.tsx +21 -9
  295. package/dist/templates/support-line/nodes.ts +74 -32
  296. package/dist/templates/support-line/procedure.ts +66 -21
  297. package/dist/templates/support-line/prompts.ts +9 -0
  298. package/dist/templates/support-line/shared.ts +55 -17
  299. package/dist/templates/support-line/tools/answer_question.ts +14 -14
  300. package/dist/templates/transcription-workflow/agent.test.ts +135 -13
  301. package/dist/templates/transcription-workflow/client.tsx +30 -23
  302. package/dist/templates/transcription-workflow/recover.test.ts +93 -12
  303. package/dist/templates/transcription-workflow/recover.ts +29 -5
  304. package/dist/templates/transcription-workflow/run-panel.tsx +40 -51
  305. package/dist/templates/transcription-workflow/workflows/normalize.ts +125 -24
  306. package/dist/templates/transcription-workflow/workflows/stream.ts +4 -1
  307. package/dist/templates/transcription-workflow/workflows/transcribe.ts +7 -5
  308. package/dist/templates/transcription-workflow/workflows/wav.ts +42 -117
  309. package/dist/templates/travel-concierge/agent.eval.test.ts +6 -4
  310. package/dist/templates/travel-concierge/agent.test.ts +209 -40
  311. package/dist/templates/travel-concierge/agent.ts +24 -4
  312. package/dist/templates/travel-concierge/call-events.ts +80 -0
  313. package/dist/templates/travel-concierge/client.tsx +3 -2
  314. package/dist/templates/travel-concierge/routing.ts +5 -7
  315. package/dist/templates/travel-concierge/shared.ts +202 -41
  316. package/dist/templates/travel-concierge/tools/book_car_rental.ts +2 -4
  317. package/dist/templates/travel-concierge/tools/book_excursion.ts +2 -4
  318. package/dist/templates/travel-concierge/tools/book_hotel.ts +2 -4
  319. package/dist/templates/travel-concierge/tools/cancel_ticket.ts +6 -4
  320. package/dist/templates/travel-concierge/tools/search_car_rentals.ts +3 -5
  321. package/dist/templates/travel-concierge/tools/search_excursions.ts +3 -5
  322. package/dist/templates/travel-concierge/tools/search_flights.ts +20 -9
  323. package/dist/templates/travel-concierge/tools/search_hotels.ts +3 -5
  324. package/dist/templates/travel-concierge/tools/update_ticket.ts +2 -4
  325. package/dist/templates/web-researcher/agent.eval.test.ts +3 -6
  326. package/dist/templates/web-researcher/agent.test.ts +102 -65
  327. package/dist/templates/web-researcher/agent.ts +93 -1
  328. package/dist/templates/web-researcher/system-prompt.md +7 -1
  329. package/dist/templates/word-wrangler/agent.eval.test.ts +157 -0
  330. package/dist/templates/word-wrangler/agent.test.ts +432 -0
  331. package/dist/templates/word-wrangler/agent.ts +35 -0
  332. package/dist/templates/word-wrangler/client.tsx +211 -0
  333. package/dist/templates/word-wrangler/game.ts +107 -0
  334. package/dist/templates/word-wrangler/guess.ts +63 -0
  335. package/dist/templates/word-wrangler/player.ts +68 -0
  336. package/dist/templates/word-wrangler/shared.ts +263 -0
  337. package/dist/templates/word-wrangler/system-prompt.md +15 -0
  338. package/dist/templates/word-wrangler/tools/final_score.ts +37 -0
  339. package/dist/templates/word-wrangler/tools/relay_description.ts +137 -0
  340. package/dist/templates/word-wrangler/tools/repeat_word.ts +19 -0
  341. package/dist/templates/word-wrangler/tools/skip_word.ts +31 -0
  342. package/dist/templates/word-wrangler/tools/start_game.ts +47 -0
  343. package/dist/templates/word-wrangler/words.ts +278 -0
  344. package/dist/test-Cllnx81G.mjs +83 -0
  345. package/dist/test.d.ts +9 -114
  346. package/package.json +5 -5
  347. package/dist/build-BhEaxBPu.mjs +0 -481
  348. package/dist/templates/embedded-assets/agent.eval.test.ts +0 -130
  349. package/dist/templates/embedded-assets/agent.test.ts +0 -79
  350. package/dist/templates/embedded-assets/agent.ts +0 -7
  351. package/dist/templates/embedded-assets/knowledge.json +0 -20
  352. package/dist/templates/embedded-assets/shared.ts +0 -17
  353. package/dist/templates/embedded-assets/system-prompt.md +0 -13
  354. package/dist/templates/embedded-assets/tools/list_topics.ts +0 -9
  355. package/dist/templates/embedded-assets/tools/search_knowledge.ts +0 -26
  356. package/dist/templates/math-buddy/agent.eval.test.ts +0 -128
  357. package/dist/templates/math-buddy/agent.test.ts +0 -126
  358. package/dist/templates/math-buddy/agent.ts +0 -15
  359. package/dist/templates/math-buddy/system-prompt.md +0 -12
  360. package/dist/templates/personal-finance/agent.eval.test.ts +0 -149
  361. package/dist/templates/personal-finance/agent.test.ts +0 -127
  362. package/dist/templates/personal-finance/agent.ts +0 -8
  363. package/dist/templates/personal-finance/system-prompt.md +0 -21
@@ -4,66 +4,100 @@ import type { ToolContext } from "@alexkroman1/aai";
4
4
  import {
5
5
  createToolContext,
6
6
  expectDialogOk,
7
- stubGenerate,
7
+ runGuardrail,
8
+ type ScriptedToolContext,
9
+ type StubDelegateRoute,
10
+ type StubGenerateRoute,
11
+ scriptedToolContext,
12
+ stubDelegate,
8
13
  toolRunner,
9
14
  } from "@alexkroman1/aai/testing";
10
- import { describe, expect, test } from "vitest";
15
+ import { visitWebpage, webSearch } from "@alexkroman1/aai/tools";
16
+ import { describe, expect, test, vi } from "vitest";
11
17
 
12
- import { executeStep, MAX_STEP_SEARCHES, normalizeAct, planNode } from "./procedure.ts";
13
- import { EXECUTOR_SYSTEM, PLANNER_SYSTEM, REPLANNER_SYSTEM, REVISE_SYSTEM } from "./prompts.ts";
14
- import type { SearchFn } from "./shared.ts";
15
- import { MAX_PAST_STEPS, planFlow, planProjection, planSlot, planView } from "./shared.ts";
16
-
17
- // ─── A scripted model ────────────────────────────────────────────────────────
18
+ import { executeStep, executor, MAX_STEP_TURNS, normalizeAct, planNode } from "./procedure.ts";
19
+ import { PLANNER_SYSTEM, REPLANNER_SYSTEM, REVISE_SYSTEM, type StepAnswer } from "./prompts.ts";
20
+ import {
21
+ MAX_PAGE_CHARS,
22
+ MAX_PAST_STEPS,
23
+ MAX_REVISIONS,
24
+ planFlow,
25
+ planProjection,
26
+ planSlot,
27
+ planView,
28
+ readTool,
29
+ searchTool,
30
+ } from "./shared.ts";
31
+
32
+ /**
33
+ * The web, faked at the SDK's own seam.
34
+ *
35
+ * `webSearch` screens a URL and then really fetches it, through an undici
36
+ * dispatcher a `globalThis.fetch` stub cannot reach — so mocking the module is
37
+ * the only honest way to keep this suite offline. The EXECUTOR's own tests need
38
+ * none of it: they stub the delegation, which is the seam a subagent is reached
39
+ * through.
40
+ */
41
+ vi.mock("@alexkroman1/aai/tools", () => ({ webSearch: vi.fn(), visitWebpage: vi.fn() }));
42
+
43
+ // ─── A scripted desk ─────────────────────────────────────────────────────────
18
44
  //
19
- // Each node is one `ctx.generate` call carrying its own system prompt, so
20
- // `stubGenerate` — whose script IS keyed by system prompt — drives the whole
21
- // loop with no model and no network. `calls` is every call the fake took, which
22
- // is how the "a failed search goes back to the model" assertion is made: it
23
- // asserts on the PROMPT the next turn carried.
45
+ // TWO fakes, because the desk reaches a model two ways. The planner and the
46
+ // replanner are `ctx.generate` calls carrying their own system prompt, so the
47
+ // `generate` script — keyed by system prompt — drives them; the EXECUTOR is a
48
+ // subagent, so the `delegate` script drives it, routed by subagent name. That
49
+ // split is the conversion showing through in the test file, and it is the
50
+ // honest one: a spec that scripted the executor's turns was scripting a loop
51
+ // this template no longer owns. `scriptedToolContext` builds both fakes and
52
+ // the context they are wired into, so every test below starts from one call.
24
53
 
25
54
  interface Script {
26
55
  steps?: string[];
27
- /** One entry per executor turn: search that query, or answer with that text. */
28
- turns?: ({ search: string } | { answer: string })[];
56
+ /** One entry per executed step: what the executor concluded. */
57
+ answers?: (string | StepAnswer)[];
58
+ /** Searches to report on each executed step, as the run's tool calls. */
59
+ searches?: string[];
29
60
  /** One entry per replan/revise call. */
30
61
  acts?: { kind: "respond" | "plan"; response?: string; steps?: string[] }[];
31
62
  }
32
63
 
33
- function scriptedModel(script: Script = {}) {
34
- const turns = [...(script.turns ?? [{ answer: "Settled it." }])];
64
+ /**
65
+ * One executor run's final message.
66
+ *
67
+ * The executor declares a `schema`, so its reply really is JSON on the wire and
68
+ * `stubDelegate` really parses it against that schema — a script that drifted
69
+ * from the shape fails HERE naming the subagent, rather than handing
70
+ * `executeStep` an `object` it never had. A bare string is the settled case,
71
+ * which is what most of these tests want to say.
72
+ */
73
+ function stepReply(answer: string | StepAnswer): string {
74
+ return JSON.stringify(typeof answer === "string" ? { finding: answer, settled: true } : answer);
75
+ }
76
+
77
+ function scriptedDesk(script: Script = {}): ScriptedToolContext {
78
+ const answers = [...(script.answers ?? [])];
35
79
  const acts = [...(script.acts ?? [])];
36
80
  // The replanner and the reviser are the same node with a different brief, so
37
81
  // they share one queue — which is what the "revise then carry on" test rests on.
38
- const act = () => ({ object: acts.shift() ?? { kind: "respond", response: "All done." } });
39
-
40
- return stubGenerate({
41
- [PLANNER_SYSTEM]: { object: { steps: script.steps ?? ["Only step"] } },
42
- [EXECUTOR_SYSTEM]: () => {
43
- const turn = turns.shift() ?? { answer: "Settled it." };
44
- return "search" in turn
45
- ? { object: { action: "search", query: turn.search } }
46
- : { object: { action: "answer", answer: turn.answer } };
47
- },
48
- [REPLANNER_SYSTEM]: act,
49
- [REVISE_SYSTEM]: act,
82
+ // Annotated as the SDK's own route type: a route is a reply or a function of
83
+ // the call, and naming it is what keeps this queue honest about being the
84
+ // second form rather than a value computed once.
85
+ const act: StubGenerateRoute = () => ({
86
+ object: acts.shift() ?? { kind: "respond", response: "All done." },
87
+ });
88
+ const worksTheStep: StubDelegateRoute = () => ({
89
+ text: stepReply(answers.shift() ?? "Settled it."),
90
+ toolCalls: (script.searches ?? []).map((query) => ({ name: "search", input: { query } })),
50
91
  });
51
- }
52
92
 
53
- /** A searcher that never touches the network. The tools use `liveSearch`, so
54
- * every tool-level test below scripts the executor to answer without one. */
55
- function fakeSearch(hits: Record<string, { title: string; url: string }[]>): {
56
- search: SearchFn;
57
- queries: string[];
58
- } {
59
- const queries: string[] = [];
60
- const search: SearchFn = async (query) => {
61
- queries.push(query);
62
- const found = hits[query];
63
- if (!found) throw new Error("search backend unavailable");
64
- return found;
65
- };
66
- return { search, queries };
93
+ return scriptedToolContext({
94
+ generate: {
95
+ [PLANNER_SYSTEM]: { object: { steps: script.steps ?? ["Only step"] } },
96
+ [REPLANNER_SYSTEM]: act,
97
+ [REVISE_SYSTEM]: act,
98
+ },
99
+ delegate: { executor: worksTheStep },
100
+ });
67
101
  }
68
102
 
69
103
  /** A tool by the name the model calls it by, bound to this agent. The lookup,
@@ -80,62 +114,205 @@ function stateOf(ctx: ToolContext) {
80
114
 
81
115
  describe("planNode", () => {
82
116
  test("returns the steps the planner produced", async () => {
83
- const { generate, calls } = scriptedModel({ steps: ["Check prices", "Book it"] });
84
- expect(await planNode(generate, "get me to Lisbon in May")).toEqual([
117
+ const { model } = scriptedDesk({ steps: ["Check prices", "Book it"] });
118
+ expect(await planNode(model.generate, "get me to Lisbon in May")).toEqual([
85
119
  "Check prices",
86
120
  "Book it",
87
121
  ]);
88
- expect(calls[0]?.prompt).toContain("get me to Lisbon in May");
122
+ expect(model.calls[0]?.prompt).toContain("get me to Lisbon in May");
89
123
  });
90
124
  });
91
125
 
92
126
  describe("executeStep", () => {
93
- test("searches, reads the results, then answers — and reports what it searched", async () => {
94
- const { generate, calls } = scriptedModel({
95
- turns: [{ search: "lisbon flights may" }, { answer: "Flights are around 180 return." }],
127
+ test("hands the step to the executor, with the objective and the history as context", async () => {
128
+ const desk = stubDelegate({ executor: stepReply("Flights are around 180 return.") });
129
+
130
+ const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", [
131
+ { step: "Pick dates", result: "Mid-May", settled: true, searches: [] },
132
+ ]);
133
+
134
+ // `finding` off the schema's own output, not the raw final message: the
135
+ // executor is a TYPED subagent, so what crosses back is a parsed object.
136
+ expect(outcome.result).toBe("Flights are around 180 return.");
137
+ expect(outcome.settled).toBe(true);
138
+ // The STEP is the task; everything the executor needs to do it in context
139
+ // rides in `context`, because a subagent has not heard the call.
140
+ expect(desk.calls[0]?.task).toBe("Check prices");
141
+ expect(desk.calls[0]?.options.context).toContain("get to Lisbon");
142
+ expect(desk.calls[0]?.options.context).toContain("Mid-May");
143
+ });
144
+
145
+ test("reports what it searched, read off the calls the run made", async () => {
146
+ // A search's RESULTS stayed inside the executor's context — that is the
147
+ // delegation — so the calls are the only honest source for the desk's
148
+ // "what the wait bought" line.
149
+ const desk = stubDelegate({
150
+ executor: {
151
+ text: stepReply("Flights are around 180 return."),
152
+ toolCalls: [
153
+ { name: "search", input: { query: "lisbon flights may" } },
154
+ { name: "search", input: { query: "lisbon flights june" } },
155
+ ],
156
+ },
96
157
  });
97
- const { search, queries } = fakeSearch({
98
- "lisbon flights may": [{ title: "Fares to Lisbon", url: "https://example.test/fares" }],
158
+
159
+ const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
160
+
161
+ expect(outcome.searches).toEqual(["lisbon flights may", "lisbon flights june"]);
162
+ });
163
+
164
+ test("the executor is given its two tools and a bounded budget", async () => {
165
+ // What this template still OWNS now that the loop is the runtime's: which
166
+ // capabilities the step is worth, and how long it may spend.
167
+ const desk = stubDelegate({ executor: stepReply("done") });
168
+ await executeStep(desk.delegate, "objective", "step", []);
169
+
170
+ const executor = desk.calls[0]?.subagent;
171
+ expect(Object.keys(executor?.tools ?? {})).toEqual(["search", "read"]);
172
+ expect(executor?.maxSteps).toBe(MAX_STEP_TURNS);
173
+ // No `builtinTools`: both are this template's own tools over
174
+ // `@alexkroman1/aai/tools`, which is the example that outlived the loop.
175
+ expect(executor?.builtinTools).toBeUndefined();
176
+ });
177
+
178
+ test("an unsettled step is carried as a FIELD, not inferred from the wording", async () => {
179
+ // `settled` is what a prompt could not hold: "say plainly rather than
180
+ // inventing a result" was in `EXECUTOR_OUTPUT` from the start, and the desk
181
+ // read one string, so a step that found nothing and a step that answered
182
+ // arrived in the same shape.
183
+ const desk = stubDelegate({
184
+ executor: stepReply({ finding: "Nothing current on that route.", settled: false }),
99
185
  });
100
186
 
101
- const outcome = await executeStep(generate, search, "get to Lisbon", "Check prices", []);
102
- expect(queries).toEqual(["lisbon flights may"]);
103
- expect(outcome.result).toContain("180");
104
- expect(outcome.searches).toEqual(["lisbon flights may"]);
105
- // The results are what the second turn reasons over, not a note in a log.
106
- expect(calls[1]?.prompt).toContain("https://example.test/fares");
187
+ const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
188
+
189
+ expect(outcome.settled).toBe(false);
190
+ expect(outcome.result).toBe("Nothing current on that route.");
107
191
  });
108
192
 
109
- test("a failed search goes back to the model rather than only to a log", async () => {
110
- // Told nothing, the model reads silence as "no such pages exist" and burns
111
- // the rest of its budget re-asking the same question.
112
- const { generate, calls } = scriptedModel({
113
- turns: [{ search: "unindexed thing" }, { answer: "Could not confirm that." }],
193
+ test("an answer the guardrail never accepted is not a settled step", async () => {
194
+ // The run had its revision and still reported a step it never looked into,
195
+ // so `accepted` is false — and a `settled: true` from an answer the runtime
196
+ // refused is exactly the claim not to take at face value.
197
+ const desk = stubDelegate({
198
+ executor: {
199
+ text: stepReply({ finding: "Flights are cheap in May.", settled: true }),
200
+ complaint: "You reported the step as unsettled without searching for anything.",
201
+ },
114
202
  });
115
- const { search } = fakeSearch({});
116
203
 
117
- const outcome = await executeStep(generate, search, "objective", "Check the thing", []);
118
- expect(calls[1]?.prompt).toContain("search backend unavailable");
119
- expect(outcome.result).toBe("Could not confirm that.");
204
+ const outcome = await executeStep(desk.delegate, "get to Lisbon", "Check prices", []);
205
+
206
+ expect(outcome.settled).toBe(false);
207
+ expect(outcome.result).toBe("Flights are cheap in May.");
120
208
  });
209
+ });
121
210
 
122
- test("the search budget is a bound, not a suggestion", async () => {
123
- const { generate, calls } = scriptedModel({
124
- // Three searches asked for, two allowed.
125
- turns: [{ search: "a" }, { search: "b" }, { search: "c" }],
211
+ describe("the executor's guardrail", () => {
212
+ // Driven through `runGuardrail` rather than by calling the function, so what
213
+ // is under test is the DEF: a guardrail dropped from `subagent()` fails here.
214
+ const verdict = (answer: StepAnswer, searched: number) =>
215
+ runGuardrail(executor, JSON.stringify(answer), {
216
+ toolCalls: Array.from({ length: searched }, () => ({
217
+ name: "search",
218
+ input: { query: "anything" },
219
+ })),
126
220
  });
127
- const { search, queries } = fakeSearch({
128
- a: [{ title: "A", url: "https://example.test/a" }],
129
- b: [{ title: "B", url: "https://example.test/b" }],
130
- c: [{ title: "C", url: "https://example.test/c" }],
221
+
222
+ test("a settled step needs no search", () => {
223
+ // Plenty of steps are summaries of what earlier ones found. A general "did
224
+ // you search enough" would reject those and cost a whole extra run.
225
+ expect(verdict({ finding: "Two of the three are already booked.", settled: true }, 0)).toBe(
226
+ true,
227
+ );
228
+ });
229
+
230
+ test("an unsettled step that really looked is accepted", () => {
231
+ expect(verdict({ finding: "Could not find a fare for that date.", settled: false }, 2)).toBe(
232
+ true,
233
+ );
234
+ });
235
+
236
+ test("giving up without looking is sent back", () => {
237
+ // The failure this template's headline claim is exposed to: reporting a
238
+ // step unsettled from memory is cheaper than either honest move.
239
+ expect(verdict({ finding: "I do not know what that costs.", settled: false }, 0)).toMatch(
240
+ /without searching/,
241
+ );
242
+ });
243
+ });
244
+
245
+ describe("the executor's search tool", () => {
246
+ test("renders the hits the model reasons over", async () => {
247
+ vi.mocked(webSearch).mockResolvedValueOnce({
248
+ results: [{ title: "Fares to Lisbon", url: "https://example.test/fares" }],
249
+ });
250
+
251
+ const rendered = await searchTool.execute({ query: "lisbon flights" }, createToolContext());
252
+
253
+ expect(rendered).toContain("Fares to Lisbon");
254
+ expect(rendered).toContain("https://example.test/fares");
255
+ });
256
+
257
+ test("a REFUSED search comes back as a failure, not as an empty web", async () => {
258
+ // `webSearch` answers with `{ error }` rather than throwing, and measured,
259
+ // DuckDuckGo answers 403 often enough to be the ordinary case. `orFail`
260
+ // carries the refusal out as the tool's own `ToolFailure` — an empty list
261
+ // would tell the executor there is nothing out there, and a thrown `Error`
262
+ // would have the runtime log an ordinary 403 as an uncaught tool bug.
263
+ vi.mocked(webSearch).mockResolvedValueOnce({ error: "403 Forbidden" });
264
+
265
+ expect(await searchTool.execute({ query: "anything" }, createToolContext())).toEqual({
266
+ error: "403 Forbidden",
131
267
  });
268
+ });
269
+
270
+ test("the caller's signal reaches the fetch", async () => {
271
+ // A tool body gets a signal and `CallOptions` takes one; until they were
272
+ // joined, a caller who hung up mid-step left a search running against a
273
+ // third party.
274
+ vi.mocked(webSearch).mockResolvedValueOnce({ results: [] });
275
+ const ctx = createToolContext();
276
+
277
+ await searchTool.execute({ query: "anything" }, ctx);
278
+
279
+ expect(vi.mocked(webSearch).mock.calls[0]?.[0]).toMatchObject({ signal: ctx.signal });
280
+ });
281
+
282
+ test("says so when the web really had nothing", async () => {
283
+ vi.mocked(webSearch).mockResolvedValueOnce({ results: [] });
284
+ expect(await searchTool.execute({ query: "anything" }, createToolContext())).toBe(
285
+ "No results.",
286
+ );
287
+ });
288
+ });
289
+
290
+ describe("the executor's read tool", () => {
291
+ test("hands back the page body, capped", async () => {
292
+ vi.mocked(visitWebpage).mockResolvedValueOnce({ content: "x".repeat(MAX_PAGE_CHARS + 500) });
293
+
294
+ const body = await readTool.execute({ url: "https://example.test/fares" }, createToolContext());
295
+
296
+ // A step is answered from a page's substance; the rest is context the run
297
+ // pays for and the executor does not read.
298
+ expect(String(body)).toHaveLength(MAX_PAGE_CHARS);
299
+ });
300
+
301
+ test("a page that would not load is not a page that said nothing", async () => {
302
+ vi.mocked(visitWebpage).mockResolvedValueOnce({ error: "404 Not Found" });
303
+
304
+ expect(
305
+ await readTool.execute({ url: "https://example.test/gone" }, createToolContext()),
306
+ ).toEqual({ error: "404 Not Found" });
307
+ });
132
308
 
133
- const outcome = await executeStep(generate, search, "objective", "step", []);
134
- expect(queries).toHaveLength(MAX_STEP_SEARCHES);
135
- // The last turn is told the budget is gone, which is what turns a search
136
- // loop into an answer.
137
- expect(calls.at(-1)?.prompt).toContain("search budget");
138
- expect(outcome.result).toBe("This step could not be settled within its budget.");
309
+ test("the caller's signal reaches the fetch here too", async () => {
310
+ vi.mocked(visitWebpage).mockResolvedValueOnce({ content: "anything" });
311
+ const ctx = createToolContext();
312
+
313
+ await readTool.execute({ url: "https://example.test/fares" }, ctx);
314
+
315
+ expect(vi.mocked(visitWebpage).mock.calls[0]?.[1]).toMatchObject({ signal: ctx.signal });
139
316
  });
140
317
  });
141
318
 
@@ -171,8 +348,9 @@ describe("normalizeAct", () => {
171
348
 
172
349
  describe("start_plan", () => {
173
350
  test("stores the objective and the steps", async () => {
174
- const { generate } = scriptedModel({ steps: ["Check prices", "Compare hotels", "Book"] });
175
- const ctx = createToolContext({ generate });
351
+ const { ctx } = scriptedDesk({
352
+ steps: ["Check prices", "Compare hotels", "Book"],
353
+ });
176
354
  const result = (await run("start_plan", { objective: "a weekend in Lisbon" }, ctx)) as {
177
355
  steps: string[];
178
356
  };
@@ -197,8 +375,7 @@ describe("start_plan", () => {
197
375
 
198
376
  describe("work_next_step", () => {
199
377
  test("is refused before there is a plan, by the flow rather than by the body", async () => {
200
- const { generate } = scriptedModel();
201
- const ctx = createToolContext({ generate });
378
+ const { ctx } = scriptedDesk();
202
379
  // The gate is `when: "working"`, so the refusal names the state the call is
203
380
  // actually in and quotes that state's instruction — which is what the model
204
381
  // needs in order to do the right thing on its own next turn.
@@ -213,12 +390,11 @@ describe("work_next_step", () => {
213
390
  });
214
391
 
215
392
  test("does the head step, records it, and takes the replanner's next plan", async () => {
216
- const { generate } = scriptedModel({
393
+ const { ctx } = scriptedDesk({
217
394
  steps: ["Check prices", "Compare hotels"],
218
- turns: [{ answer: "Fares are about 180 return." }],
395
+ answers: ["Fares are about 180 return."],
219
396
  acts: [{ kind: "plan", steps: ["Compare hotels"] }],
220
397
  });
221
- const ctx = createToolContext({ generate });
222
398
  await run("start_plan", { objective: "a weekend in Lisbon" }, ctx);
223
399
 
224
400
  const first = expectDialogOk<{
@@ -241,12 +417,11 @@ describe("work_next_step", () => {
241
417
  });
242
418
 
243
419
  test("a 'respond' act finishes the plan and clears what is left", async () => {
244
- const { generate } = scriptedModel({
420
+ const { ctx } = scriptedDesk({
245
421
  steps: ["Check prices", "Compare hotels"],
246
- turns: [{ answer: "Fares are about 180 return." }],
422
+ answers: ["Fares are about 180 return."],
247
423
  acts: [{ kind: "respond", response: "Go in May — flights are about 180 return." }],
248
424
  });
249
- const ctx = createToolContext({ generate });
250
425
  await run("start_plan", { objective: "a weekend in Lisbon" }, ctx);
251
426
  const answered = expectDialogOk<{ finished: boolean; response: string }>(
252
427
  await run("work_next_step", ctx),
@@ -275,17 +450,16 @@ describe("work_next_step", () => {
275
450
  test("the completed-step trail is capped, so the executor's prompt cannot grow forever", async () => {
276
451
  // `historyOf` renders every past step into the executor's prompt AND the
277
452
  // replanner's, so an uncapped list is a model bill that grows linearly with
278
- // the plan — the reason `recordStep` holds MAX_PAST_STEPS.
453
+ // the plan — the reason `planSlot` caps `pastSteps` at MAX_PAST_STEPS.
279
454
  const total = MAX_PAST_STEPS + 3;
280
- const { generate } = scriptedModel({
455
+ const { ctx } = scriptedDesk({
281
456
  steps: Array.from({ length: total }, (_, i) => `Step ${i + 1}`),
282
- turns: Array.from({ length: total }, (_, i) => ({ answer: `Found ${i + 1}.` })),
457
+ answers: Array.from({ length: total }, (_, i) => `Found ${i + 1}.`),
283
458
  acts: Array.from({ length: total }, (_, i) => ({
284
459
  kind: "plan" as const,
285
460
  steps: Array.from({ length: total - i - 1 }, (_, j) => `Step ${i + j + 2}`),
286
461
  })),
287
462
  });
288
- const ctx = createToolContext({ generate });
289
463
  await run("start_plan", { objective: "a long one" }, ctx);
290
464
  for (let i = 0; i < total; i++) await run("work_next_step", ctx);
291
465
 
@@ -299,13 +473,12 @@ describe("work_next_step", () => {
299
473
 
300
474
  test("two independent contexts never share a plan", async () => {
301
475
  // What this really checks: the state lives in the SLOT and not in a
302
- // module-level variable. `createToolContext()` hands each call its own
476
+ // module-level variable. `scriptedToolContext()` hands each call its own
303
477
  // detached slot store, so the isolation is per CONTEXT — two distinct
304
478
  // session ids would prove nothing extra, and `sessionSlot` could stop
305
479
  // keying by session with this still passing.
306
- const { generate } = scriptedModel({ steps: ["Only step"] });
307
- const first = createToolContext({ generate });
308
- const second = createToolContext({ generate });
480
+ const { ctx: first } = scriptedDesk({ steps: ["Only step"] });
481
+ const { ctx: second } = scriptedDesk({ steps: ["Only step"] });
309
482
 
310
483
  await run("start_plan", { objective: "mine" }, first);
311
484
  expect(stateOf(second).objective).toBeNull();
@@ -319,15 +492,14 @@ describe("work_next_step", () => {
319
492
 
320
493
  describe("revise_plan", () => {
321
494
  test("rewrites what is left, keeps what is done, and reopens a finished plan", async () => {
322
- const { generate, calls } = scriptedModel({
495
+ const { ctx, model } = scriptedDesk({
323
496
  steps: ["Check Lisbon prices", "Book Lisbon"],
324
- turns: [{ answer: "Lisbon is about 180 return." }],
497
+ answers: ["Lisbon is about 180 return."],
325
498
  acts: [
326
499
  { kind: "respond", response: "Lisbon in May, about 180." },
327
500
  { kind: "plan", steps: ["Check Porto prices"] },
328
501
  ],
329
502
  });
330
- const ctx = createToolContext({ generate });
331
503
  await run("start_plan", { objective: "a weekend in Lisbon" }, ctx);
332
504
  await run("work_next_step", ctx);
333
505
  expect(stateOf(ctx).response).not.toBeNull();
@@ -349,23 +521,40 @@ describe("revise_plan", () => {
349
521
  expect(state.pastSteps).toHaveLength(1);
350
522
  expect(state.revisions.at(-1)).toContain("make it Porto instead");
351
523
  // The caller's words reach the replanner, which is the whole node.
352
- expect(calls.at(-1)?.prompt).toContain("make it Porto instead");
524
+ expect(model.calls.at(-1)?.prompt).toContain("make it Porto instead");
353
525
  });
354
526
 
355
527
  test("is refused before there is a plan", async () => {
356
- const { generate } = scriptedModel();
357
- const ctx = createToolContext({ generate });
528
+ const { ctx } = scriptedDesk();
358
529
  expect(await run("revise_plan", { instruction: "change it" }, ctx)).toMatchObject({
359
530
  error: expect.stringContaining('this conversation is at "idle"'),
360
531
  });
361
532
  });
362
533
 
534
+ test("the revision trail is capped, because it rides in every syncState frame", async () => {
535
+ // The other cap `planSlot` declares, and the one nothing used to exercise:
536
+ // `revisions` is pushed to by every tool that changes the plan and is sent
537
+ // to the browser on each of them, so an uncapped trail is a frame that grows
538
+ // for the whole call.
539
+ const { ctx } = scriptedDesk({ steps: ["Only step"] });
540
+ await run("start_plan", { objective: "a weekend in Lisbon" }, ctx);
541
+ for (let index = 0; index < MAX_REVISIONS; index++) {
542
+ await run("revise_plan", { instruction: `change ${index}` }, ctx);
543
+ }
544
+
545
+ const state = stateOf(ctx);
546
+ expect(state.revisions).toHaveLength(MAX_REVISIONS);
547
+ // The OLDEST goes, so `start_plan`'s own entry is the one pushed out — the
548
+ // trail a caller wants read back is what has happened lately.
549
+ expect(state.revisions[0]).toContain("change 0");
550
+ expect(state.revisions.at(-1)).toContain(`change ${MAX_REVISIONS - 1}`);
551
+ });
552
+
363
553
  test("a revision that answers outright lands in `answered`", async () => {
364
- const { generate } = scriptedModel({
554
+ const { ctx } = scriptedDesk({
365
555
  steps: ["Check Lisbon prices"],
366
556
  acts: [{ kind: "respond", response: "Nothing to do — you already booked it." }],
367
557
  });
368
- const ctx = createToolContext({ generate });
369
558
  await run("start_plan", { objective: "a weekend in Lisbon" }, ctx);
370
559
  const revised = expectDialogOk<{ finished: boolean }>(
371
560
  await run("revise_plan", { instruction: "never mind, it is booked" }, ctx),
@@ -377,12 +566,11 @@ describe("revise_plan", () => {
377
566
 
378
567
  describe("plan_status", () => {
379
568
  test("reports done, remaining and the answer", async () => {
380
- const { generate } = scriptedModel({
569
+ const { ctx } = scriptedDesk({
381
570
  steps: ["Check prices", "Book"],
382
- turns: [{ answer: "About 180 return." }],
571
+ answers: ["About 180 return."],
383
572
  acts: [{ kind: "plan", steps: ["Book"] }],
384
573
  });
385
- const ctx = createToolContext({ generate });
386
574
  // Legal in every state, so it READS the position rather than being gated on
387
575
  // one — and "no plan yet" is the flow's own answer, not a third derivation
388
576
  // of `!objective`.
@@ -420,12 +608,11 @@ describe("planView projection", () => {
420
608
  });
421
609
 
422
610
  test("progress is derived once, so the bar and any spoken count agree", async () => {
423
- const { generate } = scriptedModel({
611
+ const { ctx } = scriptedDesk({
424
612
  steps: ["One", "Two", "Three"],
425
- turns: [{ answer: "Done one." }],
613
+ answers: ["Done one."],
426
614
  acts: [{ kind: "plan", steps: ["Two", "Three"] }],
427
615
  });
428
- const ctx = createToolContext({ generate });
429
616
  await run("start_plan", { objective: "three things" }, ctx);
430
617
  expect(planView(stateOf(ctx)).progress).toBe(0);
431
618
 
@@ -1,5 +1,5 @@
1
1
  import "@alexkroman1/aai-ui/styles.css";
2
- import { AutoScroll, mountClient, useAgentState } from "@alexkroman1/aai-ui";
2
+ import { AutoScroll, Facts, mountClient, useAgentState } from "@alexkroman1/aai-ui";
3
3
  import { planProjection } from "./shared.ts";
4
4
 
5
5
  /**
@@ -36,9 +36,10 @@ function PlanSidebar() {
36
36
  style={{ width: `${Math.round(plan.progress * 100)}%` }}
37
37
  />
38
38
  </div>
39
- <p className="text-xs opacity-50">
40
- {plan.done.length} done · {plan.plan.length} to go
41
- </p>
39
+ {/* The `·` line, its separator and the space either side of it are
40
+ `Facts`' rather than this file's — the one place a hand-written
41
+ version reliably gets wrong is the spacing around the separator. */}
42
+ <Facts size="xs" items={[`${plan.done.length} done`, `${plan.plan.length} to go`]} />
42
43
  </div>
43
44
 
44
45
  <AutoScroll
@@ -51,9 +52,19 @@ function PlanSidebar() {
51
52
  <span className="text-aai-primary">✓</span> {past.step}
52
53
  </p>
53
54
  <p className="mt-1 text-xs opacity-70">{past.result}</p>
54
- {past.searches.length > 0 && (
55
- <p className="mt-1 text-[11px] opacity-40">searched: {past.searches.join(" · ")}</p>
56
- )}
55
+ {/* Every fact here is conditional — an unsettled step may have
56
+ searched, a settled one may not have — and `Facts` drops the
57
+ falsy ones AND renders nothing at all when none survive, which
58
+ is the branch this line used to carry. */}
59
+ <Facts
60
+ size="xs"
61
+ className="mt-1"
62
+ items={[
63
+ !past.settled && "not settled",
64
+ past.searches.length > 0 && "searched",
65
+ ...past.searches,
66
+ ]}
67
+ />
57
68
  </div>
58
69
  ))}
59
70
  {plan.plan.map((step, index) => (