@alexkroman1/aai-cli 15.1.0 → 16.0.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 (362) 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 +12 -11
  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-CQbj3ycf.mjs → init-D363Ls5u.mjs} +2 -2
  26. package/dist/scaffold/CLAUDE.md +185 -35
  27. package/dist/scaffold/package.json +4 -4
  28. package/dist/start.mjs +3 -1
  29. package/dist/{studio-C_zuRC_z.mjs → studio-CtRBVVFR.mjs} +1 -1
  30. package/dist/templates/briefing-desk/agent.eval.test.ts +34 -6
  31. package/dist/templates/briefing-desk/agent.test.ts +347 -55
  32. package/dist/templates/briefing-desk/agent.ts +12 -0
  33. package/dist/templates/briefing-desk/shared.ts +220 -31
  34. package/dist/templates/briefing-desk/slack.ts +108 -0
  35. package/dist/templates/briefing-desk/system-prompt.md +12 -2
  36. package/dist/templates/briefing-desk/tools/briefing_so_far.ts +15 -7
  37. package/dist/templates/briefing-desk/tools/research_topic.ts +20 -28
  38. package/dist/templates/briefing-desk/tools/send_briefing.ts +77 -0
  39. package/dist/templates/briefing-desk/tools/verify_claim.ts +60 -14
  40. package/dist/templates/call-audit/agent.eval.test.ts +5 -0
  41. package/dist/templates/call-audit/agent.test.ts +6 -1
  42. package/dist/templates/call-audit/agent.ts +10 -23
  43. package/dist/templates/call-audit/client.tsx +30 -55
  44. package/dist/templates/call-audit/guards.test.ts +233 -0
  45. package/dist/templates/call-audit/workflows/audit.ts +95 -16
  46. package/dist/templates/call-audit/workflows/ingest.ts +107 -88
  47. package/dist/templates/call-audit/workflows/media.ts +98 -7
  48. package/dist/templates/call-audit/workflows/summarize.ts +35 -31
  49. package/dist/templates/call-audit/workflows/sync-api.ts +15 -6
  50. package/dist/templates/code-interpreter/agent.eval.test.ts +104 -56
  51. package/dist/templates/code-interpreter/agent.test.ts +44 -56
  52. package/dist/templates/code-interpreter/system-prompt.md +1 -1
  53. package/dist/templates/dispatch-center/agent.eval.test.ts +61 -24
  54. package/dist/templates/dispatch-center/agent.test.ts +253 -48
  55. package/dist/templates/dispatch-center/agent.ts +28 -1
  56. package/dist/templates/dispatch-center/client.tsx +126 -201
  57. package/dist/templates/dispatch-center/events.ts +48 -0
  58. package/dist/templates/dispatch-center/shared.ts +42 -1
  59. package/dist/templates/dispatch-center/tools/incident_create.ts +3 -2
  60. package/dist/templates/dispatch-center/tools/incident_escalate.ts +2 -1
  61. package/dist/templates/dispatch-center/tools/ops_dashboard.ts +35 -15
  62. package/dist/templates/dispatch-center/tools/ops_run_scenario.ts +3 -1
  63. package/dist/templates/dispatch-center/tools/resources_dispatch.ts +2 -2
  64. package/dist/templates/executive-assistant/agent.eval.test.ts +233 -0
  65. package/dist/templates/executive-assistant/agent.test.ts +672 -0
  66. package/dist/templates/executive-assistant/agent.ts +50 -0
  67. package/dist/templates/executive-assistant/calendar.test.ts +198 -0
  68. package/dist/templates/executive-assistant/client.tsx +195 -0
  69. package/dist/templates/executive-assistant/inbox.ts +233 -0
  70. package/dist/templates/executive-assistant/meeting.ts +138 -0
  71. package/dist/templates/executive-assistant/nodes.ts +152 -0
  72. package/dist/templates/executive-assistant/prompts.ts +331 -0
  73. package/dist/templates/executive-assistant/review.ts +425 -0
  74. package/dist/templates/executive-assistant/shared.ts +490 -0
  75. package/dist/templates/executive-assistant/system-prompt.md +15 -0
  76. package/dist/templates/executive-assistant/tools/accept.ts +10 -0
  77. package/dist/templates/executive-assistant/tools/ask_question.ts +30 -0
  78. package/dist/templates/executive-assistant/tools/draft_reply.ts +67 -0
  79. package/dist/templates/executive-assistant/tools/edit.ts +10 -0
  80. package/dist/templates/executive-assistant/tools/ignore.ts +10 -0
  81. package/dist/templates/executive-assistant/tools/inbox_status.ts +27 -0
  82. package/dist/templates/executive-assistant/tools/meeting_assistant.ts +52 -0
  83. package/dist/templates/executive-assistant/tools/new_email.ts +50 -0
  84. package/dist/templates/executive-assistant/tools/open_email.ts +165 -0
  85. package/dist/templates/executive-assistant/tools/respond.ts +10 -0
  86. package/dist/templates/executive-assistant/tools/review_memory.ts +22 -0
  87. package/dist/templates/executive-assistant/tools/send_calendar_invite.ts +68 -0
  88. package/dist/templates/executive-assistant/tools/triage_inbox.ts +75 -0
  89. package/dist/templates/health-assistant/agent.test.ts +134 -15
  90. package/dist/templates/health-assistant/agent.ts +8 -1
  91. package/dist/templates/health-assistant/fda.test.ts +130 -0
  92. package/dist/templates/health-assistant/fda.ts +75 -16
  93. package/dist/templates/health-assistant/system-prompt.md +9 -0
  94. package/dist/templates/health-assistant/tools/check_drug_interaction.ts +5 -2
  95. package/dist/templates/health-assistant/tools/medication_lookup.ts +16 -11
  96. package/dist/templates/hiring-desk/agent.eval.test.ts +242 -0
  97. package/dist/templates/hiring-desk/agent.test.ts +1021 -0
  98. package/dist/templates/hiring-desk/agent.ts +38 -0
  99. package/dist/templates/hiring-desk/client.tsx +154 -0
  100. package/dist/templates/hiring-desk/crews.ts +432 -0
  101. package/dist/templates/hiring-desk/leads.json +86 -0
  102. package/dist/templates/hiring-desk/screening-lock.test.ts +77 -0
  103. package/dist/templates/hiring-desk/screening-lock.ts +51 -0
  104. package/dist/templates/hiring-desk/shared.ts +480 -0
  105. package/dist/templates/hiring-desk/system-prompt.md +21 -0
  106. package/dist/templates/hiring-desk/tools/candidate_details.ts +49 -0
  107. package/dist/templates/hiring-desk/tools/proceed_to_emails.ts +127 -0
  108. package/dist/templates/hiring-desk/tools/read_email.ts +50 -0
  109. package/dist/templates/hiring-desk/tools/rescore_with_feedback.ts +140 -0
  110. package/dist/templates/hiring-desk/tools/screen_candidates.ts +128 -0
  111. package/dist/templates/hiring-desk/tools/screening_status.ts +51 -0
  112. package/dist/templates/hotel-desk/agent.eval.test.ts +177 -0
  113. package/dist/templates/hotel-desk/agent.test.ts +1128 -0
  114. package/dist/templates/hotel-desk/agent.ts +63 -0
  115. package/dist/templates/hotel-desk/booking.ts +159 -0
  116. package/dist/templates/hotel-desk/card.ts +92 -0
  117. package/dist/templates/hotel-desk/catalogs.ts +219 -0
  118. package/dist/templates/hotel-desk/client.tsx +137 -0
  119. package/dist/templates/hotel-desk/concierge.ts +99 -0
  120. package/dist/templates/hotel-desk/desk-seams.test.ts +334 -0
  121. package/dist/templates/hotel-desk/desk.ts +224 -0
  122. package/dist/templates/hotel-desk/disputes.ts +216 -0
  123. package/dist/templates/hotel-desk/events.ts +79 -0
  124. package/dist/templates/hotel-desk/hotel.ts +412 -0
  125. package/dist/templates/hotel-desk/policies.ts +209 -0
  126. package/dist/templates/hotel-desk/records.ts +384 -0
  127. package/dist/templates/hotel-desk/restaurant.ts +147 -0
  128. package/dist/templates/hotel-desk/seed.ts +955 -0
  129. package/dist/templates/hotel-desk/shared.ts +354 -0
  130. package/dist/templates/hotel-desk/system-prompt.md +76 -0
  131. package/dist/templates/hotel-desk/tools/abandon_booking.ts +30 -0
  132. package/dist/templates/hotel-desk/tools/add_to_waitlist.ts +41 -0
  133. package/dist/templates/hotel-desk/tools/book_airport_car.ts +57 -0
  134. package/dist/templates/hotel-desk/tools/book_business_center.ts +44 -0
  135. package/dist/templates/hotel-desk/tools/book_spa_appointment.ts +39 -0
  136. package/dist/templates/hotel-desk/tools/book_tour.ts +35 -0
  137. package/dist/templates/hotel-desk/tools/cancel_restaurant_reservation.ts +25 -0
  138. package/dist/templates/hotel-desk/tools/cancel_room_booking.ts +63 -0
  139. package/dist/templates/hotel-desk/tools/check_restaurant_availability.ts +24 -0
  140. package/dist/templates/hotel-desk/tools/check_room_availability.ts +40 -0
  141. package/dist/templates/hotel-desk/tools/choose_room.ts +93 -0
  142. package/dist/templates/hotel-desk/tools/confirm_booking.ts +153 -0
  143. package/dist/templates/hotel-desk/tools/dispatch_emergency.ts +61 -0
  144. package/dist/templates/hotel-desk/tools/dispute_charge.ts +90 -0
  145. package/dist/templates/hotel-desk/tools/flag_late_arrival.ts +26 -0
  146. package/dist/templates/hotel-desk/tools/lookup_booking.ts +48 -0
  147. package/dist/templates/hotel-desk/tools/lookup_guest_history.ts +28 -0
  148. package/dist/templates/hotel-desk/tools/lookup_invoice.ts +26 -0
  149. package/dist/templates/hotel-desk/tools/lookup_policy.ts +20 -0
  150. package/dist/templates/hotel-desk/tools/lookup_restaurant_reservation.ts +27 -0
  151. package/dist/templates/hotel-desk/tools/modify_restaurant_reservation.ts +75 -0
  152. package/dist/templates/hotel-desk/tools/order_flowers.ts +40 -0
  153. package/dist/templates/hotel-desk/tools/record_card.ts +46 -0
  154. package/dist/templates/hotel-desk/tools/record_followup.ts +50 -0
  155. package/dist/templates/hotel-desk/tools/record_group_inquiry.ts +44 -0
  156. package/dist/templates/hotel-desk/tools/record_guest_details.ts +71 -0
  157. package/dist/templates/hotel-desk/tools/reinstate_booking.ts +65 -0
  158. package/dist/templates/hotel-desk/tools/request_flight_reconfirmation.ts +54 -0
  159. package/dist/templates/hotel-desk/tools/resend_confirmation.ts +39 -0
  160. package/dist/templates/hotel-desk/tools/reserve_table.ts +87 -0
  161. package/dist/templates/hotel-desk/tools/resolve_room_conflict.ts +48 -0
  162. package/dist/templates/hotel-desk/tools/schedule_wakeup_call.ts +48 -0
  163. package/dist/templates/hotel-desk/tools/set_do_not_disturb.ts +28 -0
  164. package/dist/templates/hotel-desk/tools/set_extras.ts +51 -0
  165. package/dist/templates/hotel-desk/tools/set_stay.ts +97 -0
  166. package/dist/templates/hotel-desk/tools/start_booking_modification.ts +57 -0
  167. package/dist/templates/hotel-desk/tools/start_room_booking.ts +49 -0
  168. package/dist/templates/hotel-desk/tools/take_guest_message.ts +71 -0
  169. package/dist/templates/hotel-desk/tools/transfer_call.ts +47 -0
  170. package/dist/templates/hotel-desk/tools/update_card.ts +45 -0
  171. package/dist/templates/hotel-desk/tools/verify_booking.ts +95 -0
  172. package/dist/templates/infocom-adventure/agent.eval.test.ts +33 -1
  173. package/dist/templates/infocom-adventure/agent.test.ts +207 -52
  174. package/dist/templates/infocom-adventure/agent.ts +14 -3
  175. package/dist/templates/infocom-adventure/client.tsx +138 -176
  176. package/dist/templates/infocom-adventure/shared.ts +126 -6
  177. package/dist/templates/infocom-adventure/system-prompt.md +4 -4
  178. package/dist/templates/infocom-adventure/tools/game_state_drop.ts +20 -4
  179. package/dist/templates/infocom-adventure/tools/game_state_get.ts +6 -5
  180. package/dist/templates/infocom-adventure/tools/game_state_score.ts +9 -3
  181. package/dist/templates/link-digest/agent.eval.test.ts +8 -0
  182. package/dist/templates/link-digest/agent.test.ts +285 -29
  183. package/dist/templates/link-digest/agent.ts +9 -0
  184. package/dist/templates/link-digest/api-client.ts +144 -0
  185. package/dist/templates/link-digest/client.tsx +11 -30
  186. package/dist/templates/link-digest/workflows/digest.ts +72 -24
  187. package/dist/templates/night-owl/agent.eval.test.ts +55 -40
  188. package/dist/templates/night-owl/agent.test.ts +146 -12
  189. package/dist/templates/night-owl/client.tsx +50 -17
  190. package/dist/templates/night-owl/shared.ts +33 -2
  191. package/dist/templates/night-owl/system-prompt.md +3 -0
  192. package/dist/templates/night-owl/tools/recommend.ts +4 -1
  193. package/dist/templates/night-owl/tools/revisit.ts +49 -0
  194. package/dist/templates/pipeline-simple/agent.eval.test.ts +7 -6
  195. package/dist/templates/pipeline-simple/agent.test.ts +48 -91
  196. package/dist/templates/pipeline-simple/modes.test.ts +151 -0
  197. package/dist/templates/pipeline-simple/stages.test.ts +332 -0
  198. package/dist/templates/pizza-ordering/agent.test.ts +94 -38
  199. package/dist/templates/pizza-ordering/client.tsx +10 -5
  200. package/dist/templates/pizza-ordering/shared.ts +65 -6
  201. package/dist/templates/pizza-ordering/tools/add_pizza.ts +2 -7
  202. package/dist/templates/pizza-ordering/tools/place_order.ts +9 -6
  203. package/dist/templates/pizza-ordering/tools/remove_pizza.ts +6 -11
  204. package/dist/templates/pizza-ordering/tools/update_pizza.ts +8 -9
  205. package/dist/templates/pizza-ordering/tools/view_order.ts +2 -3
  206. package/dist/templates/plan-and-execute/agent.eval.test.ts +14 -6
  207. package/dist/templates/plan-and-execute/agent.test.ts +300 -113
  208. package/dist/templates/plan-and-execute/client.tsx +18 -7
  209. package/dist/templates/plan-and-execute/procedure.ts +162 -64
  210. package/dist/templates/plan-and-execute/prompts.ts +51 -15
  211. package/dist/templates/plan-and-execute/shared.ts +151 -45
  212. package/dist/templates/plan-and-execute/tools/plan_status.ts +15 -6
  213. package/dist/templates/plan-and-execute/tools/revise_plan.ts +2 -2
  214. package/dist/templates/plan-and-execute/tools/start_plan.ts +2 -2
  215. package/dist/templates/plan-and-execute/tools/work_next_step.ts +15 -13
  216. package/dist/templates/podcast-digest/agent.eval.test.ts +12 -7
  217. package/dist/templates/podcast-digest/agent.test.ts +126 -51
  218. package/dist/templates/podcast-digest/client.tsx +104 -68
  219. package/dist/templates/podcast-digest/workflows/digest.ts +71 -48
  220. package/dist/templates/podcast-digest/workflows/feeds.ts +5 -7
  221. package/dist/templates/podcast-digest/workflows/slack.ts +82 -17
  222. package/dist/templates/recap-workflow/agent.eval.test.ts +193 -209
  223. package/dist/templates/recap-workflow/agent.test.ts +207 -26
  224. package/dist/templates/recap-workflow/tools/recap_status.ts +2 -2
  225. package/dist/templates/recap-workflow/workflows/recap.ts +39 -28
  226. package/dist/templates/redline/agent.eval.test.ts +40 -3
  227. package/dist/templates/redline/agent.test.ts +216 -6
  228. package/dist/templates/redline/agent.ts +54 -34
  229. package/dist/templates/redline/client.tsx +82 -126
  230. package/dist/templates/redline/form.ts +74 -0
  231. package/dist/templates/redline/workflows/prompts.ts +3 -3
  232. package/dist/templates/redline/workflows/redline.ts +73 -4
  233. package/dist/templates/research-workflow/agent.eval.test.ts +152 -150
  234. package/dist/templates/research-workflow/agent.test.ts +436 -126
  235. package/dist/templates/research-workflow/agent.ts +20 -5
  236. package/dist/templates/research-workflow/tools/file_it_now.ts +11 -1
  237. package/dist/templates/research-workflow/tools/research_status.ts +39 -4
  238. package/dist/templates/research-workflow/workflows/filing.ts +164 -0
  239. package/dist/templates/research-workflow/workflows/notes.ts +69 -0
  240. package/dist/templates/research-workflow/workflows/prompts.ts +45 -31
  241. package/dist/templates/research-workflow/workflows/research.ts +227 -280
  242. package/dist/templates/research-workflow/workflows/review.ts +43 -0
  243. package/dist/templates/retail/address.ts +29 -35
  244. package/dist/templates/retail/agent.eval.test.ts +36 -16
  245. package/dist/templates/retail/agent.test.ts +104 -26
  246. package/dist/templates/retail/agent.ts +12 -0
  247. package/dist/templates/retail/cancel.ts +39 -42
  248. package/dist/templates/retail/client.tsx +111 -176
  249. package/dist/templates/retail/payment.ts +38 -43
  250. package/dist/templates/retail/pending.test.ts +16 -8
  251. package/dist/templates/retail/registry.test.ts +108 -49
  252. package/dist/templates/retail/resolve.test.ts +2 -63
  253. package/dist/templates/retail/resolve.ts +16 -56
  254. package/dist/templates/retail/returns.ts +53 -54
  255. package/dist/templates/retail/seed.test.ts +2 -1
  256. package/dist/templates/retail/shared.ts +58 -14
  257. package/dist/templates/retail/store.test.ts +40 -29
  258. package/dist/templates/retail/store.ts +60 -23
  259. package/dist/templates/retail/swap.ts +78 -81
  260. package/dist/templates/retail/tools/find_user_id_by_name_zip.ts +2 -1
  261. package/dist/templates/roadside-assist/agent.eval.test.ts +164 -0
  262. package/dist/templates/roadside-assist/agent.test.ts +617 -0
  263. package/dist/templates/roadside-assist/agent.ts +85 -0
  264. package/dist/templates/roadside-assist/call.ts +237 -0
  265. package/dist/templates/roadside-assist/events.ts +92 -0
  266. package/dist/templates/roadside-assist/shared.ts +334 -0
  267. package/dist/templates/roadside-assist/system-prompt.md +37 -0
  268. package/dist/templates/roadside-assist/tools/acknowledge_disclosure.ts +47 -0
  269. package/dist/templates/roadside-assist/tools/dispatch_truck.ts +148 -0
  270. package/dist/templates/roadside-assist/tools/job_status.ts +38 -0
  271. package/dist/templates/roadside-assist/tools/lookup_coverage.ts +72 -0
  272. package/dist/templates/roadside-assist/tools/report_location.ts +79 -0
  273. package/dist/templates/roadside-assist/tools/service_disclosure.ts +45 -0
  274. package/dist/templates/roadside-assist/yard.test.ts +158 -0
  275. package/dist/templates/roadside-assist/yard.ts +183 -0
  276. package/dist/templates/simple/agent.eval.test.ts +4 -1
  277. package/dist/templates/simple/agent.test.ts +54 -31
  278. package/dist/templates/solo-rpg/agent.eval.test.ts +19 -11
  279. package/dist/templates/solo-rpg/agent.test.ts +402 -175
  280. package/dist/templates/solo-rpg/agent.ts +14 -3
  281. package/dist/templates/solo-rpg/client.tsx +10 -10
  282. package/dist/templates/solo-rpg/shared.ts +198 -79
  283. package/dist/templates/solo-rpg/tools/action_roll.ts +7 -3
  284. package/dist/templates/solo-rpg/tools/burn_momentum.ts +16 -8
  285. package/dist/templates/solo-rpg/tools/oracle.ts +7 -7
  286. package/dist/templates/solo-rpg/tools/setup_character.ts +5 -5
  287. package/dist/templates/solo-rpg/tools/update_state.ts +29 -18
  288. package/dist/templates/spoken-summary/agent.test.ts +70 -15
  289. package/dist/templates/spoken-summary/agent.ts +25 -21
  290. package/dist/templates/spoken-summary/client.tsx +68 -88
  291. package/dist/templates/spoken-summary/workflows/summarize.ts +26 -8
  292. package/dist/templates/support-line/agent.test.ts +167 -36
  293. package/dist/templates/support-line/client.tsx +21 -9
  294. package/dist/templates/support-line/nodes.ts +74 -32
  295. package/dist/templates/support-line/procedure.ts +66 -21
  296. package/dist/templates/support-line/prompts.ts +9 -0
  297. package/dist/templates/support-line/shared.ts +55 -17
  298. package/dist/templates/support-line/tools/answer_question.ts +14 -14
  299. package/dist/templates/transcription-workflow/agent.test.ts +135 -13
  300. package/dist/templates/transcription-workflow/client.tsx +30 -23
  301. package/dist/templates/transcription-workflow/recover.test.ts +93 -12
  302. package/dist/templates/transcription-workflow/recover.ts +29 -5
  303. package/dist/templates/transcription-workflow/run-panel.tsx +40 -51
  304. package/dist/templates/transcription-workflow/workflows/normalize.ts +125 -24
  305. package/dist/templates/transcription-workflow/workflows/stream.ts +4 -1
  306. package/dist/templates/transcription-workflow/workflows/transcribe.ts +7 -5
  307. package/dist/templates/transcription-workflow/workflows/wav.ts +42 -117
  308. package/dist/templates/travel-concierge/agent.eval.test.ts +6 -4
  309. package/dist/templates/travel-concierge/agent.test.ts +209 -40
  310. package/dist/templates/travel-concierge/agent.ts +24 -4
  311. package/dist/templates/travel-concierge/call-events.ts +80 -0
  312. package/dist/templates/travel-concierge/client.tsx +3 -2
  313. package/dist/templates/travel-concierge/routing.ts +5 -7
  314. package/dist/templates/travel-concierge/shared.ts +202 -41
  315. package/dist/templates/travel-concierge/tools/book_car_rental.ts +2 -4
  316. package/dist/templates/travel-concierge/tools/book_excursion.ts +2 -4
  317. package/dist/templates/travel-concierge/tools/book_hotel.ts +2 -4
  318. package/dist/templates/travel-concierge/tools/cancel_ticket.ts +6 -4
  319. package/dist/templates/travel-concierge/tools/search_car_rentals.ts +3 -5
  320. package/dist/templates/travel-concierge/tools/search_excursions.ts +3 -5
  321. package/dist/templates/travel-concierge/tools/search_flights.ts +20 -9
  322. package/dist/templates/travel-concierge/tools/search_hotels.ts +3 -5
  323. package/dist/templates/travel-concierge/tools/update_ticket.ts +2 -4
  324. package/dist/templates/web-researcher/agent.eval.test.ts +3 -6
  325. package/dist/templates/web-researcher/agent.test.ts +102 -65
  326. package/dist/templates/web-researcher/agent.ts +93 -1
  327. package/dist/templates/web-researcher/system-prompt.md +7 -1
  328. package/dist/templates/word-wrangler/agent.eval.test.ts +157 -0
  329. package/dist/templates/word-wrangler/agent.test.ts +432 -0
  330. package/dist/templates/word-wrangler/agent.ts +35 -0
  331. package/dist/templates/word-wrangler/client.tsx +211 -0
  332. package/dist/templates/word-wrangler/game.ts +107 -0
  333. package/dist/templates/word-wrangler/guess.ts +63 -0
  334. package/dist/templates/word-wrangler/player.ts +68 -0
  335. package/dist/templates/word-wrangler/shared.ts +263 -0
  336. package/dist/templates/word-wrangler/system-prompt.md +15 -0
  337. package/dist/templates/word-wrangler/tools/final_score.ts +37 -0
  338. package/dist/templates/word-wrangler/tools/relay_description.ts +137 -0
  339. package/dist/templates/word-wrangler/tools/repeat_word.ts +19 -0
  340. package/dist/templates/word-wrangler/tools/skip_word.ts +31 -0
  341. package/dist/templates/word-wrangler/tools/start_game.ts +47 -0
  342. package/dist/templates/word-wrangler/words.ts +278 -0
  343. package/dist/test-Cllnx81G.mjs +83 -0
  344. package/dist/test.d.ts +9 -114
  345. package/package.json +5 -5
  346. package/dist/build-BhEaxBPu.mjs +0 -481
  347. package/dist/templates/embedded-assets/agent.eval.test.ts +0 -130
  348. package/dist/templates/embedded-assets/agent.test.ts +0 -79
  349. package/dist/templates/embedded-assets/agent.ts +0 -7
  350. package/dist/templates/embedded-assets/knowledge.json +0 -20
  351. package/dist/templates/embedded-assets/shared.ts +0 -17
  352. package/dist/templates/embedded-assets/system-prompt.md +0 -13
  353. package/dist/templates/embedded-assets/tools/list_topics.ts +0 -9
  354. package/dist/templates/embedded-assets/tools/search_knowledge.ts +0 -26
  355. package/dist/templates/math-buddy/agent.eval.test.ts +0 -128
  356. package/dist/templates/math-buddy/agent.test.ts +0 -126
  357. package/dist/templates/math-buddy/agent.ts +0 -15
  358. package/dist/templates/math-buddy/system-prompt.md +0 -12
  359. package/dist/templates/personal-finance/agent.eval.test.ts +0 -149
  360. package/dist/templates/personal-finance/agent.test.ts +0 -127
  361. package/dist/templates/personal-finance/agent.ts +0 -8
  362. package/dist/templates/personal-finance/system-prompt.md +0 -21
@@ -1,36 +1,81 @@
1
- import type { ToolContext, ToolDef, ToolInputSchema } from "@alexkroman1/aai";
2
- import { isToolFailure } from "@alexkroman1/aai";
3
- import { createToolContext, expectToolOk } from "@alexkroman1/aai/testing";
4
- import { describe, expect, test, vi } from "vitest";
1
+ /** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
2
+ import agentDef from "virtual:aai/agent";
3
+ import type { InferToolInput, RandomSource, SlotHolder } from "@alexkroman1/aai";
4
+ import { createSeededRandom, isToolFailure } from "@alexkroman1/aai";
5
+ import {
6
+ createToolContext,
7
+ expectDialogRefused,
8
+ expectToolOk,
9
+ parseToolInput,
10
+ toolInputIssues,
11
+ toolRunner,
12
+ } from "@alexkroman1/aai/testing";
13
+ import { describe, expect, test } from "vitest";
5
14
  import {
6
15
  applyConsequences,
7
16
  DEFAULT_STATE,
17
+ findClock,
8
18
  type GameState,
9
19
  gameSlot,
20
+ gameView,
10
21
  inCrisis,
11
22
  isGameOver,
23
+ MAX_LOG_ENTRIES,
12
24
  MAX_NPCS,
13
25
  MIN_MOMENTUM,
14
26
  makeNpc,
15
27
  rollAction,
16
28
  storyFlow,
17
29
  } from "./shared.ts";
18
- import actionRoll from "./tools/action_roll.ts";
19
- import burnMomentum from "./tools/burn_momentum.ts";
20
- import checkState from "./tools/check_state.ts";
21
- import oracle from "./tools/oracle.ts";
22
- import setupCharacter from "./tools/setup_character.ts";
23
- import updateState from "./tools/update_state.ts";
24
-
25
- // ── Test doubles ─────────────────────────────────────────────────────────────
26
-
27
- /** Each call gets its own slot store, which is what makes two contexts two
28
- * games. `send` is the recorder `createToolContext` installs — no test here
29
- * asserts on it, and overriding it would only throw the recording away. */
30
- function makeCtx(): ToolContext {
31
- return createToolContext();
30
+ import type setupCharacter from "./tools/setup_character.ts";
31
+
32
+ // ── Harness ──────────────────────────────────────────────────────────────────
33
+
34
+ /**
35
+ * A tool by the NAME the model calls it by, bound to this agent.
36
+ *
37
+ * The lookup, its "no such tool" message and the args-or-context shape are all
38
+ * `toolRunner`'s (`@alexkroman1/aai/testing`); what is local is only which agent
39
+ * it runs against. It replaces both the direct `tools/*.ts` imports and a local
40
+ * `callNoArgs<R>(def, ctx)` that cast its way past `ToolDef["execute"]`'s first
41
+ * parameter — a tool declaring no `inputSchema` types that as a shape no object
42
+ * literal satisfies, and `runTool` takes the context in the arguments' place for
43
+ * exactly that case. Driving by name is also the half a direct `.execute` call
44
+ * cannot check: a renamed `tools/` file is what the MODEL would stop finding.
45
+ */
46
+ const run = toolRunner(agentDef);
47
+
48
+ /**
49
+ * The dice `rollAction` draws, in the order it draws them: d1, d2 (d6), then
50
+ * c1, c2 (d10).
51
+ *
52
+ * `randomInt(sides, random)` is `Math.floor(random() * sides)`, so a face is
53
+ * produced by returning `(face - 0.5) / sides`. This used to be
54
+ * `vi.spyOn(Math, "random")` — a GLOBAL patch every other test in the file then
55
+ * had to be trusted not to depend on, and one the teardown had to remember to
56
+ * restore. The dice are a PARAMETER (`rollAction`'s fourth), which is the same
57
+ * seam `ctx.random` gives a tool, so nothing here touches the process.
58
+ */
59
+ function dice(...faces: readonly [number, number, number, number]): RandomSource {
60
+ const sides = [6, 6, 10, 10] as const;
61
+ let draw = 0;
62
+ return () => {
63
+ const face = faces[draw] ?? 1;
64
+ const side = sides[draw] ?? 6;
65
+ draw++;
66
+ return (face - 0.5) / side;
67
+ };
32
68
  }
33
69
 
70
+ /**
71
+ * Every field `setup_character` requires, pinned to the tool's OWN schema.
72
+ *
73
+ * `satisfies InferToolInput<typeof setupCharacter>` rather than a bare literal:
74
+ * a required field added to that schema, or an enum member renamed under one of
75
+ * these values, is a compile error HERE — where the alternative is a spec that
76
+ * still passes while the shape it seeds no longer exists. The import is
77
+ * type-only, so nothing about the runner's by-name lookup is undone by it.
78
+ */
34
79
  const SETUP_ARGS = {
35
80
  genre: "dark_fantasy",
36
81
  tone: "dark_gritty",
@@ -40,14 +85,43 @@ const SETUP_ARGS = {
40
85
  settingDescription: "A city of fog and iron.",
41
86
  startingLocation: "The Docks",
42
87
  locationDesc: "Rotting piers under gaslight.",
43
- timeOfDay: "night" as const,
88
+ timeOfDay: "night",
44
89
  openingSituation: "A body washes ashore bearing your family crest.",
45
90
  npc1Name: "Mira",
46
91
  npc1Desc: "A wary informant",
47
- npc1Disposition: "distrustful" as const,
92
+ npc1Disposition: "distrustful",
48
93
  npc1Agenda: "Pay off her debts",
49
94
  threatClockName: "The Syndicate Closes In",
50
95
  threatClockDesc: "Assassins find the player",
96
+ } satisfies InferToolInput<typeof setupCharacter>;
97
+
98
+ const SWING = {
99
+ move: "clash",
100
+ stat: "iron",
101
+ position: "risky",
102
+ effect: "standard",
103
+ purpose: "swing",
104
+ } as const;
105
+
106
+ /**
107
+ * What the two ungated tools answer with.
108
+ *
109
+ * A plain `tool()` returns its own value, so there is no envelope to unwrap and
110
+ * `expectToolOk` would (correctly) refuse one. The by-name lookup is a STRING,
111
+ * so the author's return type cannot be recovered from it — the SDK says so in
112
+ * `expectToolOk`'s own doc — and naming the fields a spec reads is the honest
113
+ * substitute. Only what is asserted below is listed.
114
+ */
115
+ type Answered = {
116
+ state: string;
117
+ instruction?: string;
118
+ done: boolean;
119
+ initialized: boolean;
120
+ playerName: string;
121
+ gameOver: boolean;
122
+ health: number;
123
+ momentum: number;
124
+ chaosFactor: number;
51
125
  };
52
126
 
53
127
  function playingState(): GameState {
@@ -67,45 +141,31 @@ function playingState(): GameState {
67
141
  }
68
142
 
69
143
  /**
70
- * Seed a context with a mid-game campaign AND the matching flow position.
144
+ * Seed a session with a mid-game campaign AND the matching flow position.
71
145
  *
72
- * Writing the slot alone is no longer enough: `action_roll`, `update_state`,
73
- * `burn_momentum` and `save_game` gate on `storyFlow`, so a campaign installed
74
- * behind the machine's back leaves every one of them refusing. That is the point
75
- * of the gate, and it is what this helper exists to satisfy honestly — through
76
- * the flow's own event, not by writing its snapshot.
146
+ * Writing the slot alone is not enough: `action_roll`, `update_state` and
147
+ * `burn_momentum` gate on `storyFlow`, so a campaign installed behind the
148
+ * machine's back leaves every one of them refusing. That is the point of the
149
+ * gate, and it is what this helper exists to satisfy honestly — through the
150
+ * flow's own event, not by writing its snapshot.
151
+ *
152
+ * Typed `SlotHolder` rather than `ToolContext`, which is what both calls below
153
+ * really take: this seeds a session's SLOTS, and needs nothing else a tool body
154
+ * is handed.
77
155
  */
78
- function seedPlaying(ctx: ToolContext, state: GameState = playingState()): GameState {
156
+ function seedPlaying(ctx: SlotHolder, state: GameState = playingState()): GameState {
79
157
  gameSlot.set(ctx, state);
80
158
  storyFlow.send(ctx, { type: "SETUP" });
81
159
  return state;
82
160
  }
83
161
 
84
- /**
85
- * Call a tool that declares no `inputSchema`.
86
- *
87
- * `ToolDef["execute"]`'s first parameter is derived from the schema, so a tool
88
- * with none types it as a shape no object literal satisfies — and nine call
89
- * sites here had each cast their way past it. This is the one narrowing they all
90
- * wanted: `check_state` and `burn_momentum` really do take no arguments, and a
91
- * helper says that once where a cast per call site said nothing.
92
- *
93
- * It is generic in `R` because the three tool builders thread their result type
94
- * out now, so the ARGUMENT is the only thing here that needs laundering — where
95
- * every call site used to follow this one with a second cast of its own to
96
- * recover a return type the erasure had thrown away.
97
- */
98
- function callNoArgs<R>(def: ToolDef<ToolInputSchema, R>, ctx: ToolContext): Promise<Awaited<R>> {
99
- return Promise.resolve((def.execute as (args: unknown, c: ToolContext) => R)({}, ctx));
100
- }
101
-
102
162
  // ── setup_character ──────────────────────────────────────────────────────────
103
163
 
104
164
  describe("setup_character", () => {
105
165
  test("running setup twice starts fresh: no duplicate ids, no stale resources, truthful return", async () => {
106
- const ctx = makeCtx();
166
+ const ctx = createToolContext();
107
167
 
108
- await setupCharacter.execute(SETUP_ARGS, ctx);
168
+ await run("setup_character", SETUP_ARGS, ctx);
109
169
 
110
170
  // Simulate a played, damaged game between setups.
111
171
  gameSlot.update(ctx, (played) => {
@@ -115,10 +175,11 @@ describe("setup_character", () => {
115
175
  played.sceneCount = 42;
116
176
  });
117
177
 
118
- const result = (await setupCharacter.execute(
178
+ const result = (await run(
179
+ "setup_character",
119
180
  { ...SETUP_ARGS, playerName: "Luna" },
120
181
  ctx,
121
- )) as Record<string, unknown>;
182
+ )) as Answered;
122
183
 
123
184
  const state = gameSlot.get(ctx);
124
185
  expect(state.npcs).toHaveLength(1);
@@ -140,8 +201,8 @@ describe("setup_character", () => {
140
201
  });
141
202
 
142
203
  test("stats are a permutation of [3,2,2,1,1] with the archetype's stat at 3", async () => {
143
- const ctx = makeCtx();
144
- await setupCharacter.execute(SETUP_ARGS, ctx);
204
+ const ctx = createToolContext();
205
+ await run("setup_character", SETUP_ARGS, ctx);
145
206
  const state = gameSlot.get(ctx);
146
207
  const stats = [state.edge, state.heart, state.iron, state.shadow, state.wits];
147
208
  expect([...stats].sort()).toEqual([1, 1, 2, 2, 3]);
@@ -155,8 +216,8 @@ describe("setup_character", () => {
155
216
  // detached slot store, so the isolation is per CONTEXT — two distinct
156
217
  // session ids would prove nothing extra, and `sessionSlot` could stop
157
218
  // keying by session with this still passing.
158
- await setupCharacter.execute(SETUP_ARGS, makeCtx());
159
- const other = await callNoArgs(checkState, makeCtx());
219
+ await run("setup_character", SETUP_ARGS, createToolContext());
220
+ const other = (await run("check_state", createToolContext())) as Answered;
160
221
  expect(other.initialized).toBe(false);
161
222
  });
162
223
  });
@@ -243,7 +304,7 @@ describe("applyConsequences MISS matrix", () => {
243
304
  // ── burn_momentum ────────────────────────────────────────────────────────────
244
305
 
245
306
  describe("burn_momentum", () => {
246
- function seedRolledState(momentum: number, ctx: ToolContext) {
307
+ function seedRolledState(momentum: number, ctx: SlotHolder) {
247
308
  const state = playingState();
248
309
  // A MISS was applied: health -2, momentum -2, clock +1.
249
310
  state.health = 3;
@@ -285,10 +346,12 @@ describe("burn_momentum", () => {
285
346
  }
286
347
 
287
348
  test("a legal burn reverts the miss's consequences, upgrades, and resets momentum", async () => {
288
- const ctx = makeCtx();
349
+ const ctx = createToolContext();
289
350
  seedRolledState(8, ctx); // 8 beats both dice (3, 5)
290
351
 
291
- const result = expectToolOk<Record<string, unknown>>(await callNoArgs(burnMomentum, ctx));
352
+ const result = expectToolOk<{ burned: boolean; newResultCode: string }>(
353
+ await run("burn_momentum", ctx),
354
+ );
292
355
  expect(result.burned).toBe(true);
293
356
  expect(result.newResultCode).toBe("STRONG_HIT");
294
357
 
@@ -300,48 +363,50 @@ describe("burn_momentum", () => {
300
363
  });
301
364
 
302
365
  test("momentum beating only one die upgrades a MISS to WEAK_HIT", async () => {
303
- const ctx = makeCtx();
366
+ const ctx = createToolContext();
304
367
  seedRolledState(4, ctx); // beats 3, not 5
305
- const result = expectToolOk<{ newResultCode: string }>(await callNoArgs(burnMomentum, ctx));
368
+ const result = expectToolOk<{ newResultCode: string }>(await run("burn_momentum", ctx));
306
369
  expect(result.newResultCode).toBe("WEAK_HIT");
307
370
  });
308
371
 
309
372
  test("burn is refused with no roll standing, insufficient momentum, or a strong hit", async () => {
310
- const ctx = makeCtx();
373
+ const ctx = createToolContext();
311
374
 
312
- // No roll yet — and this refusal is now the FLOW's rather than a null check
375
+ // No roll yet — and this refusal is the FLOW's rather than a null check
313
376
  // inside the body: nothing has rolled, so the game is in
314
- // `playing.awaitingRoll` and this tool is not available there. The message
315
- // names the position and quotes what that state expects.
377
+ // `playing.awaitingRoll` and this tool is not available there.
378
+ // `expectDialogRefused` is the SDK's reader for that: it pins the STATE the
379
+ // refusal names against the sentence `dialog()` writes, and throws naming
380
+ // where the dialog actually landed if the call SUCCEEDED — where an
381
+ // `isToolFailure(...) && ...` expression let a success through as a `false`
382
+ // that merely failed the next matcher.
316
383
  seedPlaying(ctx);
317
- // The flow's refusal, so it arrives as a `ToolFailure` rather than under
318
- // the position envelope — which the narrowing now says out loud.
319
- let result = await callNoArgs(burnMomentum, ctx);
320
- expect(isToolFailure(result) && result.error).toMatch(/awaitingRoll/);
321
- expect(isToolFailure(result) && result.error).toMatch(/action_roll/);
322
-
323
- // Momentum too low to beat either die — a DATA rule, so it stays in the
324
- // body and the tool still runs.
384
+ const outOfState = expectDialogRefused(await run("burn_momentum", ctx), "playing.awaitingRoll");
385
+ // The state's own instruction rides in the refusal, which is what the model
386
+ // recovers from.
387
+ expect(outOfState.error).toContain("action_roll");
388
+
389
+ // The two below are DATA rules — the momentum is too low, the roll was
390
+ // already a strong hit — so they stay in the body, the tool really runs,
391
+ // and what comes back is the body's own `toolFailure(...)` rather than the
392
+ // gate's sentence. `isToolFailure` is the right reader for exactly that
393
+ // difference.
325
394
  seedRolledState(2, ctx);
326
- result = await callNoArgs(burnMomentum, ctx);
327
- expect(isToolFailure(result) && result.error).toMatch(/not high enough/);
395
+ let refused = await run("burn_momentum", ctx);
396
+ expect(isToolFailure(refused) && refused.error).toMatch(/not high enough/);
328
397
 
329
- // Strong hits cannot be upgraded
330
398
  seedRolledState(8, ctx);
331
399
  gameSlot.update(ctx, (state) => {
332
400
  state.lastRoll!.result = "STRONG_HIT";
333
401
  });
334
- result = await callNoArgs(burnMomentum, ctx);
335
- expect(isToolFailure(result) && result.error).toMatch(/already a Strong Hit/);
402
+ refused = await run("burn_momentum", ctx);
403
+ expect(isToolFailure(refused) && refused.error).toMatch(/already a Strong Hit/);
336
404
  });
337
405
 
338
406
  test("action_roll persists the roll so burn needs no dice arguments", async () => {
339
- const ctx = makeCtx();
407
+ const ctx = createToolContext();
340
408
  seedPlaying(ctx);
341
- await actionRoll.execute(
342
- { move: "clash", stat: "iron", position: "risky", effect: "standard", purpose: "attack" },
343
- ctx,
344
- );
409
+ await run("action_roll", SWING, ctx);
345
410
  const state = gameSlot.get(ctx);
346
411
  expect(state.lastRoll).not.toBeNull();
347
412
  expect(state.lastRoll?.move).toBe("clash");
@@ -352,43 +417,77 @@ describe("burn_momentum", () => {
352
417
  // ── rollAction dice boundaries ───────────────────────────────────────────────
353
418
 
354
419
  describe("rollAction", () => {
355
- // Math.random call order inside rollAction: d1, d2, c1, c2.
356
- function mockDice(d1: number, d2: number, c1: number, c2: number) {
357
- const spy = vi.spyOn(Math, "random");
358
- for (const [value, sides] of [
359
- [d1, 6],
360
- [d2, 6],
361
- [c1, 10],
362
- [c2, 10],
363
- ] as const) {
364
- spy.mockReturnValueOnce((value - 0.5) / sides);
365
- }
366
- return spy;
367
- }
368
-
369
420
  test("tying a challenge die is NOT a beat — equal on both dice is a MISS with match", () => {
370
- mockDice(3, 3, 8, 8); // action score 3+3+2 = 8 vs 8, 8
371
- const roll = rollAction("wits", 2, "face_danger");
421
+ // action score 3+3+2 = 8 vs 8, 8
422
+ const roll = rollAction("wits", 2, "face_danger", dice(3, 3, 8, 8));
372
423
  expect(roll.actionScore).toBe(8);
373
424
  expect(roll.result).toBe("MISS");
374
425
  expect(roll.match).toBe(true);
375
426
  });
376
427
 
377
428
  test("action score caps at 10 even when dice + stat exceed it", () => {
378
- mockDice(6, 6, 1, 1); // 6+6+4 = 16 → capped to 10
379
- const roll = rollAction("iron", 4, "clash");
429
+ const roll = rollAction("iron", 4, "clash", dice(6, 6, 1, 1)); // 6+6+4 = 16 → 10
380
430
  expect(roll.actionScore).toBe(10);
381
431
  expect(roll.result).toBe("STRONG_HIT");
382
432
  });
383
433
 
384
434
  test("beating exactly one die is a WEAK_HIT", () => {
385
- mockDice(4, 2, 5, 9); // 4+2+2 = 8: beats 5, not 9
386
- const roll = rollAction("edge", 2, "face_danger");
435
+ const roll = rollAction("edge", 2, "face_danger", dice(4, 2, 5, 9)); // 8: beats 5, not 9
387
436
  expect(roll.result).toBe("WEAK_HIT");
388
437
  expect(roll.match).toBe(false);
389
438
  });
390
439
  });
391
440
 
441
+ // ── a scene is a function of its random source ───────────────────────────────
442
+
443
+ describe("action_roll draws everything from ctx.random", () => {
444
+ /** One roll from a fresh session whose randomness is `createSeededRandom(seed)`. */
445
+ async function playOneScene(seed: number) {
446
+ const ctx = createToolContext({ random: createSeededRandom(seed) });
447
+ seedPlaying(ctx);
448
+ return expectToolOk<Record<string, unknown>>(await run("action_roll", SWING, ctx));
449
+ }
450
+
451
+ test("every draw a roll makes comes off the context's source", async () => {
452
+ // The DETERMINISTIC half, and the one that names the defect: a roll draws
453
+ // five times — d1, d2, c1, c2, and then the chaos check's own d10 (a sixth
454
+ // when the interrupt lands and its type is picked). The fifth used to reach
455
+ // `Math.random`, because `checkChaosInterrupt`'s source parameter was simply
456
+ // omitted at the call, so the count was four.
457
+ let draws = 0;
458
+ const seeded = createSeededRandom(2026);
459
+ const ctx = createToolContext({
460
+ random: () => {
461
+ draws++;
462
+ return seeded();
463
+ },
464
+ });
465
+ seedPlaying(ctx);
466
+
467
+ expectToolOk(await run("action_roll", SWING, ctx));
468
+ expect(draws).toBeGreaterThanOrEqual(5);
469
+ });
470
+
471
+ test("the same seed replays the same scene, chaos interrupt included", async () => {
472
+ // The property a player would notice, over the WHOLE result rather than the
473
+ // dice: with the missing source above, this comparison disagreed on
474
+ // `chaosInterrupt` for roughly three runs in five — intermittently, and only
475
+ // ever on the field nobody looks at. A seeded campaign replays or it does
476
+ // not.
477
+ expect(await playOneScene(2026)).toEqual(await playOneScene(2026));
478
+ });
479
+
480
+ test("a different seed is a different scene", async () => {
481
+ // The other half, and the reason `createSeededRandom` rather than a
482
+ // constant source: `() => 0.5` is deterministic and degenerate, and every
483
+ // roll under it would be identical. Compared on the dice alone, since two
484
+ // seeds may legitimately agree on a derived label.
485
+ const a = await playOneScene(1);
486
+ const b = await playOneScene(99);
487
+ expect([a.actionDice, a.challengeDice]).not.toEqual([b.actionDice, b.challengeDice]);
488
+ });
489
+ });
490
+
392
491
  // ── oracle ───────────────────────────────────────────────────────────────────
393
492
  //
394
493
  // `chaos_check` is the one oracle branch that WRITES: `checkChaosInterrupt`
@@ -401,19 +500,23 @@ describe("rollAction", () => {
401
500
  // private copy would pass every check on its own return value.
402
501
 
403
502
  describe("oracle", () => {
404
- /** Force `d(sides)` to roll `value` on the next call. */
405
- function mockRoll(value: number, sides: number) {
406
- return vi.spyOn(Math, "random").mockReturnValue((value - 0.5) / sides);
503
+ /**
504
+ * A context whose `d(sides)` rolls `value`.
505
+ *
506
+ * `ctx.random` is the seam, so the dice a scene is resolved on are an
507
+ * argument to the tool rather than a property of the process.
508
+ */
509
+ function rolling(value: number, sides: number) {
510
+ return createToolContext({ random: () => (value - 0.5) / sides });
407
511
  }
408
512
 
409
513
  test("a chaos interrupt that LANDS lowers the stored chaos factor", async () => {
410
- const ctx = makeCtx();
514
+ const ctx = rolling(1, 10);
411
515
  const state = playingState();
412
516
  state.chaosFactor = 9; // threshold 6 — a roll of 1 lands
413
517
  seedPlaying(ctx, state);
414
- mockRoll(1, 10);
415
518
 
416
- const result = (await oracle.execute({ type: "chaos_check" }, ctx)) as {
519
+ const result = (await run("oracle", { type: "chaos_check" }, ctx)) as {
417
520
  interrupted: boolean;
418
521
  interruptType: string | null;
419
522
  chaosFactor: number;
@@ -427,12 +530,12 @@ describe("oracle", () => {
427
530
  });
428
531
 
429
532
  test("the chaos factor floors at 3, where no roll is taken at all", async () => {
430
- const ctx = makeCtx();
533
+ const ctx = createToolContext();
431
534
  const state = playingState();
432
535
  state.chaosFactor = 3; // threshold 0 — `checkChaosInterrupt` returns early
433
536
  seedPlaying(ctx, state);
434
537
 
435
- const result = (await oracle.execute({ type: "chaos_check" }, ctx)) as {
538
+ const result = (await run("oracle", { type: "chaos_check" }, ctx)) as {
436
539
  interrupted: boolean;
437
540
  chaosFactor: number;
438
541
  };
@@ -441,13 +544,12 @@ describe("oracle", () => {
441
544
  });
442
545
 
443
546
  test("a chaos check that MISSES changes nothing", async () => {
444
- const ctx = makeCtx();
547
+ const ctx = rolling(10, 10); // past the threshold
445
548
  const state = playingState();
446
549
  state.chaosFactor = 5; // threshold 2
447
550
  seedPlaying(ctx, state);
448
- mockRoll(10, 10); // past the threshold
449
551
 
450
- const result = (await oracle.execute({ type: "chaos_check" }, ctx)) as {
552
+ const result = (await run("oracle", { type: "chaos_check" }, ctx)) as {
451
553
  interrupted: boolean;
452
554
  chaosFactor: number;
453
555
  };
@@ -457,15 +559,14 @@ describe("oracle", () => {
457
559
  });
458
560
 
459
561
  test("a chaos check on an untouched session starts from the default factor", async () => {
460
- const ctx = makeCtx();
461
- mockRoll(1, 10); // DEFAULT_STATE.chaosFactor is 5, so threshold 2 — lands
462
- const result = (await oracle.execute({ type: "chaos_check" }, ctx)) as { chaosFactor: number };
562
+ // DEFAULT_STATE.chaosFactor is 5, so threshold 2 — a roll of 1 lands.
563
+ const ctx = rolling(1, 10);
564
+ const result = (await run("oracle", { type: "chaos_check" }, ctx)) as { chaosFactor: number };
463
565
  expect(result.chaosFactor).toBe(DEFAULT_STATE.chaosFactor - 1);
464
566
  expect(gameSlot.get(ctx).chaosFactor).toBe(DEFAULT_STATE.chaosFactor - 1);
465
567
  });
466
568
 
467
569
  test("yes_no maps the d6 onto its three answers", async () => {
468
- const ctx = makeCtx();
469
570
  for (const [roll, answer] of [
470
571
  [1, "No"],
471
572
  [2, "No"],
@@ -474,8 +575,7 @@ describe("oracle", () => {
474
575
  [5, "Yes"],
475
576
  [6, "Yes"],
476
577
  ] as const) {
477
- mockRoll(roll, 6);
478
- const result = (await oracle.execute({ type: "yes_no" }, ctx)) as {
578
+ const result = (await run("oracle", { type: "yes_no" }, rolling(roll, 6))) as {
479
579
  roll: number;
480
580
  answer: string;
481
581
  };
@@ -484,13 +584,13 @@ describe("oracle", () => {
484
584
  });
485
585
 
486
586
  test("the four inspiration branches answer without touching the game", async () => {
487
- const ctx = makeCtx();
587
+ const ctx = createToolContext();
488
588
  seedPlaying(ctx);
489
589
  const before = structuredClone(gameSlot.get(ctx));
490
590
 
491
- const reaction = (await oracle.execute({ type: "npc_reaction" }, ctx)) as { reaction: string };
492
- const twist = (await oracle.execute({ type: "scene_twist" }, ctx)) as { twist: string };
493
- const theme = (await oracle.execute({ type: "action_theme" }, ctx)) as {
591
+ const reaction = (await run("oracle", { type: "npc_reaction" }, ctx)) as { reaction: string };
592
+ const twist = (await run("oracle", { type: "scene_twist" }, ctx)) as { twist: string };
593
+ const theme = (await run("oracle", { type: "action_theme" }, ctx)) as {
494
594
  action: string;
495
595
  theme: string;
496
596
  seed: string;
@@ -505,16 +605,45 @@ describe("oracle", () => {
505
605
  });
506
606
  });
507
607
 
608
+ // ── which clock the player meant ─────────────────────────────────────────────
609
+
610
+ describe("findClock", () => {
611
+ // Deliberately ordered so the two rules disagree: "The First Light" contains
612
+ // an ordinal word and sits SECOND.
613
+ const clocks = [
614
+ { id: "clock_1", name: "The Syndicate Closes In" },
615
+ { id: "clock_2", name: "The First Light" },
616
+ ];
617
+
618
+ test("an exact name wins over the ordinal it happens to contain", () => {
619
+ // Resolving the ordinal first would answer `clock_1` here, silently
620
+ // retargeting a clock the player named outright.
621
+ expect(findClock(clocks, "The First Light")?.id).toBe("clock_2");
622
+ expect(findClock(clocks, " the first light ")?.id).toBe("clock_2");
623
+ });
624
+
625
+ test("an ordinal picks by the position the sidebar renders", () => {
626
+ expect(findClock(clocks, "the second clock")?.id).toBe("clock_2");
627
+ expect(findClock(clocks, "the 1st one")?.id).toBe("clock_1");
628
+ });
629
+
630
+ test("neither a name nor an ordinal resolves to nothing", () => {
631
+ expect(findClock(clocks, "The Reckoning")).toBeUndefined();
632
+ // An ordinal past the end is not a wrap-around.
633
+ expect(findClock(clocks, "the ninth clock")).toBeUndefined();
634
+ });
635
+ });
636
+
508
637
  // ── update_state: clocks, caps, validation ───────────────────────────────────
509
638
 
510
639
  describe("update_state", () => {
511
640
  test("clock ids never collide after a removal (max-scan, not length+1)", async () => {
512
- const ctx = makeCtx();
641
+ const ctx = createToolContext();
513
642
  seedPlaying(ctx); // has clock_1
514
643
 
515
- await updateState.execute({ addClockName: "Second" }, ctx); // clock_2
516
- await updateState.execute({ removeClockName: "Doom" }, ctx); // removes clock_1
517
- await updateState.execute({ addClockName: "Third" }, ctx);
644
+ await run("update_state", { addClockName: "Second" }, ctx); // clock_2
645
+ await run("update_state", { removeClockName: "Doom" }, ctx); // removes clock_1
646
+ await run("update_state", { addClockName: "Third" }, ctx);
518
647
 
519
648
  const state = gameSlot.get(ctx);
520
649
  const ids = state.clocks.map((c) => c.id);
@@ -523,19 +652,65 @@ describe("update_state", () => {
523
652
  });
524
653
 
525
654
  test("advancing a clock to full reports its trigger event", async () => {
526
- const ctx = makeCtx();
655
+ const ctx = createToolContext();
527
656
  const state = playingState();
528
657
  state.clocks[0]!.filled = 3; // 3 of 4
529
658
  seedPlaying(ctx, state);
530
659
 
531
660
  const result = expectToolOk<{ clockEvents: { clock: string; trigger: string }[] }>(
532
- await updateState.execute({ advanceClockName: "Doom" }, ctx),
661
+ await run("update_state", { advanceClockName: "Doom" }, ctx),
533
662
  );
534
663
  expect(result.clockEvents).toEqual([{ clock: "Doom", trigger: "The doom arrives" }]);
535
664
  });
536
665
 
666
+ test("a clock can be advanced by the ordinal the player used", async () => {
667
+ const ctx = createToolContext();
668
+ const state = playingState();
669
+ state.clocks.push({
670
+ id: "clock_2",
671
+ name: "The Long Night",
672
+ clockType: "progress",
673
+ segments: 2,
674
+ filled: 1,
675
+ triggerDescription: "Dawn breaks",
676
+ });
677
+ seedPlaying(ctx, state);
678
+
679
+ const result = expectToolOk<{ clockEvents: { clock: string; trigger: string }[] }>(
680
+ await run("update_state", { advanceClockName: "the second one" }, ctx),
681
+ );
682
+ expect(result.clockEvents).toEqual([{ clock: "The Long Night", trigger: "Dawn breaks" }]);
683
+ expect(gameSlot.get(ctx).clocks[1]?.filled).toBe(2);
684
+ });
685
+
686
+ test("removing by ordinal drops exactly that clock", async () => {
687
+ const ctx = createToolContext();
688
+ const state = playingState();
689
+ state.clocks.push({
690
+ id: "clock_2",
691
+ name: "The Long Night",
692
+ clockType: "progress",
693
+ segments: 2,
694
+ filled: 0,
695
+ triggerDescription: "Dawn breaks",
696
+ });
697
+ seedPlaying(ctx, state);
698
+
699
+ expectToolOk(await run("update_state", { removeClockName: "the first clock" }, ctx));
700
+ expect(gameSlot.get(ctx).clocks.map((c) => c.id)).toEqual(["clock_2"]);
701
+ });
702
+
703
+ test("a clock nobody has warns instead of silently doing nothing", async () => {
704
+ const ctx = createToolContext();
705
+ seedPlaying(ctx);
706
+ const result = expectToolOk<{ warnings?: string[] }>(
707
+ await run("update_state", { advanceClockName: "The Reckoning" }, ctx),
708
+ );
709
+ expect(result.warnings?.[0]).toMatch(/No clock matching/);
710
+ });
711
+
537
712
  test("NPC count is capped at MAX_NPCS with a warning", async () => {
538
- const ctx = makeCtx();
713
+ const ctx = createToolContext();
539
714
  const state = playingState();
540
715
  while (state.npcs.length < MAX_NPCS) {
541
716
  state.npcs.push(makeNpc({ id: `npc_${state.npcs.length + 1}`, name: "Extra" }));
@@ -543,24 +718,56 @@ describe("update_state", () => {
543
718
  seedPlaying(ctx, state);
544
719
 
545
720
  const result = expectToolOk<{ warnings?: string[] }>(
546
- await updateState.execute({ addNpcName: "One Too Many" }, ctx),
721
+ await run("update_state", { addNpcName: "One Too Many" }, ctx),
547
722
  );
548
723
  expect(result.warnings?.[0]).toMatch(/NPC limit/);
549
724
  const after = gameSlot.get(ctx);
550
725
  expect(after.npcs).toHaveLength(MAX_NPCS);
551
726
  });
552
727
 
553
- test("zod schemas reject out-of-range and malformed inputs", () => {
554
- const params = updateState.inputSchema!;
555
- expect(() => params.parse({ addClockSegments: 1 })).toThrow(); // below min
556
- expect(() => params.parse({ addClockSegments: 13 })).toThrow(); // above max
557
- expect(() => params.parse({ addClockSegments: 2.5 })).toThrow(); // non-integer
558
- expect(() => params.parse({ updateNpcBond: 5 })).toThrow(); // above MAX_BOND
559
- expect(() => params.parse({ updateNpcBond: -1 })).toThrow();
560
- expect(() => params.parse({ timeOfDay: "noonish" })).toThrow(); // not a phase
561
- expect(
562
- params.parse({ addClockSegments: 6, updateNpcBond: 4, timeOfDay: "night" }),
563
- ).toBeTruthy();
728
+ test("the chronicle is capped by the SLOT, keeping the newest entries", async () => {
729
+ // The bound is declared as `caps` on `gameSlot` and enforced by nothing in
730
+ // this tool, which is exactly why it is worth a test: `update_state` pushes
731
+ // unconditionally, so a dropped `caps` key would leave the log growing into
732
+ // every `syncState` frame with nothing red.
733
+ const ctx = createToolContext();
734
+ seedPlaying(ctx);
735
+ for (let i = 1; i <= MAX_LOG_ENTRIES + 5; i++) {
736
+ await run("update_state", { logEntry: `scene ${i}` }, ctx);
737
+ }
738
+
739
+ const log = gameSlot.get(ctx).sessionLog;
740
+ expect(log).toHaveLength(MAX_LOG_ENTRIES);
741
+ expect(log[0]?.summary).toBe("scene 6");
742
+ expect(log.at(-1)?.summary).toBe(`scene ${MAX_LOG_ENTRIES + 5}`);
743
+ });
744
+
745
+ test("the input schema rejects out-of-range and malformed values", async () => {
746
+ // `toolInputIssues` / `parseToolInput` (`@alexkroman1/aai/testing`) rather
747
+ // than reaching for `inputSchema!["~standard"]` — the reach eighteen sites
748
+ // across ten templates had re-derived. They also take the tool by NAME, so
749
+ // this asks the agent's own registry the same question the runner above
750
+ // does, and the rejection reports WHICH field failed instead of "it threw".
751
+ for (const bad of [
752
+ { addClockSegments: 1 }, // below min
753
+ { addClockSegments: 13 }, // above max
754
+ { addClockSegments: 2.5 }, // non-integer
755
+ { updateNpcBond: 5 }, // above MAX_BOND
756
+ { updateNpcBond: -1 },
757
+ { timeOfDay: "noonish" }, // not a phase
758
+ ]) {
759
+ expect
760
+ .soft(await toolInputIssues(agentDef, "update_state", bad), JSON.stringify(bad))
761
+ .toBeDefined();
762
+ }
763
+
764
+ await expect(
765
+ parseToolInput(agentDef, "update_state", {
766
+ addClockSegments: 6,
767
+ updateNpcBond: 4,
768
+ timeOfDay: "night",
769
+ }),
770
+ ).resolves.toMatchObject({ addClockSegments: 6, timeOfDay: "night" });
564
771
  });
565
772
  });
566
773
 
@@ -573,26 +780,19 @@ describe("update_state", () => {
573
780
 
574
781
  describe("the story flow", () => {
575
782
  test("a fresh session is awaiting setup, and the play tools refuse there", async () => {
576
- const ctx = makeCtx();
783
+ const ctx = createToolContext();
577
784
  expect(storyFlow.position(ctx).state).toBe("awaitingSetup");
578
785
 
579
786
  // All of these used to RUN before a character existed: `action_roll` rolled
580
787
  // 2d6 against the stats of nobody and applied consequences to a game that was
581
- // not there. (`save_game` was in this list too, writing an empty campaign to a
582
- // slot `load_game` would later restore over a real one — both are gone with
583
- // `ctx.db`.)
788
+ // not there.
584
789
  for (const call of [
585
- actionRoll.execute(
586
- { move: "clash", stat: "iron", position: "risky", effect: "standard", purpose: "swing" },
587
- ctx,
588
- ),
589
- updateState.execute({ location: "Nowhere" }, ctx),
590
- callNoArgs(burnMomentum, ctx),
790
+ run("action_roll", SWING, ctx),
791
+ run("update_state", { location: "Nowhere" }, ctx),
792
+ run("burn_momentum", ctx),
591
793
  ]) {
592
- const refusal = await call;
593
- expect(isToolFailure(refusal)).toBe(true);
594
- expect(isToolFailure(refusal) && refusal.error).toMatch(/awaitingSetup/);
595
- expect(isToolFailure(refusal) && refusal.error).toMatch(/setup_character/);
794
+ const refusal = expectDialogRefused(await call, "awaitingSetup");
795
+ expect(refusal.error).toContain("setup_character");
596
796
  }
597
797
 
598
798
  // And nothing ran.
@@ -600,32 +800,27 @@ describe("the story flow", () => {
600
800
  });
601
801
 
602
802
  test("setup opens play, a roll leaves one standing, and settling closes the window", async () => {
603
- const ctx = makeCtx();
803
+ const ctx = createToolContext();
604
804
  // `state`/`instruction`, not `at`/`next`: the ungated tools spread the
605
805
  // `DialogPosition` verbatim now, so they report their position under the
606
806
  // same keys every gated tool's result carries — which is what the system
607
807
  // prompt already claimed.
608
- const created = await setupCharacter.execute(SETUP_ARGS, ctx);
808
+ const created = (await run("setup_character", SETUP_ARGS, ctx)) as Answered;
609
809
  expect(created.state).toBe("playing.awaitingRoll");
610
810
  expect(created.instruction).toMatch(/action_roll/);
611
811
 
612
- expectToolOk(
613
- await actionRoll.execute(
614
- { move: "clash", stat: "iron", position: "risky", effect: "standard", purpose: "swing" },
615
- ctx,
616
- ),
617
- );
812
+ expectToolOk(await run("action_roll", SWING, ctx));
618
813
  expect(storyFlow.position(ctx).state).toBe("playing.rollResolved");
619
814
 
620
815
  // Moving the scene on SPENDS the roll: the burn window is closed.
621
- expectToolOk(await updateState.execute({ location: "The Bridge" }, ctx));
816
+ expectToolOk(await run("update_state", { location: "The Bridge" }, ctx));
622
817
  expect(storyFlow.position(ctx).state).toBe("playing.awaitingRoll");
623
- expect(isToolFailure(await callNoArgs(burnMomentum, ctx))).toBe(true);
818
+ expectDialogRefused(await run("burn_momentum", ctx), "playing.awaitingRoll");
624
819
  });
625
820
 
626
821
  test("check_state reports the position and is legal before setup", async () => {
627
- const ctx = makeCtx();
628
- const before = await callNoArgs(checkState, ctx);
822
+ const ctx = createToolContext();
823
+ const before = (await run("check_state", ctx)) as Answered;
629
824
  expect(before.state).toBe("awaitingSetup");
630
825
  expect(before.instruction).toMatch(/setup_character/);
631
826
  expect(before.done).toBe(false);
@@ -633,7 +828,7 @@ describe("the story flow", () => {
633
828
  });
634
829
 
635
830
  test("a game over is terminal: nothing rolls, and setup starts a new story", async () => {
636
- const ctx = makeCtx();
831
+ const ctx = createToolContext();
637
832
  const dead = playingState();
638
833
  dead.health = 0;
639
834
  dead.spirit = 0;
@@ -644,23 +839,55 @@ describe("the story flow", () => {
644
839
  // act on it, so a player could keep rolling after both tracks emptied. The
645
840
  // WRITE is `gameSlot`'s `after` hook; this tool no longer calls it, which
646
841
  // is the point of moving it there.
647
- expectToolOk(await updateState.execute({ health: 0, spirit: 0 }, ctx));
842
+ expectToolOk(await run("update_state", { health: 0, spirit: 0 }, ctx));
648
843
  const at = storyFlow.position(ctx);
649
844
  expect(at.state).toBe("gameOver");
650
845
  expect(at.done).toBe(true);
651
846
 
652
- const refused = await actionRoll.execute(
653
- { move: "clash", stat: "iron", position: "risky", effect: "standard", purpose: "swing" },
654
- ctx,
655
- );
656
- expect(isToolFailure(refused)).toBe(true);
657
- expect(isToolFailure(refused) && refused.error).toMatch(/gameOver/);
847
+ expectDialogRefused(await run("action_roll", SWING, ctx), "gameOver");
658
848
 
659
849
  // Starting over is legal from anywhere, the ending included.
660
- const restarted = await setupCharacter.execute(SETUP_ARGS, ctx);
850
+ const restarted = (await run("setup_character", SETUP_ARGS, ctx)) as Answered;
661
851
  expect(restarted.state).toBe("playing.awaitingRoll");
662
852
  });
663
853
 
854
+ test("the projection withholds the plot the player has not reached", () => {
855
+ const game: GameState = {
856
+ ...structuredClone(DEFAULT_STATE),
857
+ backstory: "SPOILER backstory",
858
+ playerWishes: "SPOILER wishes",
859
+ contentLines: "SPOILER lines",
860
+ settingTone: "SPOILER tone",
861
+ settingArchetype: "SPOILER archetype",
862
+ settingDescription: "SPOILER description",
863
+ storyBlueprint: {
864
+ structureType: "3act",
865
+ centralConflict: "c",
866
+ antagonistForce: "a",
867
+ thematicThread: "t",
868
+ currentAct: 1,
869
+ storyComplete: false,
870
+ acts: [
871
+ { phase: "setup", title: "One", goal: "g1", mood: "m1", transitionTrigger: "SPOILER1" },
872
+ { phase: "turn", title: "Two", goal: "g2", mood: "m2", transitionTrigger: "SPOILER2" },
873
+ ],
874
+ },
875
+ };
876
+
877
+ const view = gameView(game);
878
+ // The sidebar needs how far along and which phase, and nothing else about
879
+ // the arc: an act's goal, mood and transition trigger are the twists the
880
+ // player has not reached, and slot state is otherwise server-side, so this
881
+ // projection is the only thing standing between them and devtools.
882
+ expect(view.storyArc).toEqual({
883
+ currentAct: 1,
884
+ totalActs: 2,
885
+ phase: "setup",
886
+ storyComplete: false,
887
+ });
888
+ expect(JSON.stringify(view)).not.toMatch(/SPOILER/);
889
+ });
890
+
664
891
  // Two resume tests stood here — a saved game reopening in play, and one saved
665
892
  // after the ending reopening as over. Both drove `save_game`/`load_game`, which
666
893
  // are gone with `ctx.db`. What they proved about the FLOW (a resumed position is