@alexkroman1/aai-cli 15.1.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 (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,5 +1,5 @@
1
1
  /**
2
- * The desk's two subagents, and the board of what they have found.
2
+ * The desk's subagents, and the board of what they have found.
3
3
  *
4
4
  * **This template is the worked example for `ctx.delegate`.** Everything here
5
5
  * exists to show the three things a subagent buys that `ctx.generate` cannot:
@@ -16,6 +16,26 @@
16
16
  * `factChecker` can only search it, on a cheaper model with a third of the
17
17
  * budget. Neither can reach the other's tools, and the DESK — the voice
18
18
  * agent the caller is talking to — has no web tools at all.
19
+ *
20
+ * **And it is the worked example for the two ways to CHOOSE one**, which is the
21
+ * split to read this file for:
22
+ *
23
+ * - `researcher` and `factChecker` are chosen in CODE, by the tool that names
24
+ * them. `research_topic` runs ONE subagent N times in parallel and
25
+ * `verify_claim` reads the board to turn "the second thing you told me" into
26
+ * a sentence — neither is a choice a model could make, and neither is a shape
27
+ * a roster can express.
28
+ * - `explainer` and `counterpoint` are on the ROSTER (`agent({ subagents })`),
29
+ * because choosing between them IS reading what the caller asked: "what does
30
+ * curtailment mean" and "who says otherwise" want different specialists and
31
+ * nothing else about them differs. They reach the model as one `delegate`
32
+ * tool whose `coworker` argument is the two names, described by their own
33
+ * {@link SubagentDef.description}s.
34
+ *
35
+ * The rule that follows: **name a subagent in code when the tool IS the choice;
36
+ * put it on the roster when the caller's words are.** An agent that grew a
37
+ * fourth `tools/ask_the_<x>.ts` whose body was one `ctx.delegate` line has been
38
+ * hand-rolling the roster.
19
39
  */
20
40
 
21
41
  import {
@@ -23,12 +43,34 @@ import {
23
43
  type DelegateFn,
24
44
  type DelegateOptions,
25
45
  type DelegateResult,
26
- pushCapped,
46
+ resolveOne,
47
+ type SubagentRoster,
27
48
  type SubagentToolCall,
28
49
  sessionSlot,
29
50
  subagent,
51
+ type ToolFailure,
52
+ type TypedSubagentDef,
53
+ toolFailure,
30
54
  } from "@alexkroman1/aai";
31
- import { assemblyAILlm } from "@alexkroman1/aai/llm";
55
+ import { type AssemblyAIGatewayModel, assemblyAILlm } from "@alexkroman1/aai/llm";
56
+ import { z } from "zod";
57
+
58
+ /**
59
+ * The model the three NARROW specialists share.
60
+ *
61
+ * Named once because it is a fact about the DESK — checking one sentence,
62
+ * defining one word and finding one objection are not the job `researcher`
63
+ * does, so all three run somewhere cheaper — and each subagent still declares
64
+ * its own `llm`, because which model a specialist runs on is part of what
65
+ * declaring a specialist means.
66
+ *
67
+ * Annotated as {@link AssemblyAIGatewayModel} rather than left as three string
68
+ * literals: `AssemblyAILlmOptions.model` widens to `string` so the gateway
69
+ * accepts a name it has never heard of, and a typo in one of three copies is a
70
+ * refusal from ONE specialist while the other two answer — the hardest shape of
71
+ * failure to notice on a live call. Here it is a compile error.
72
+ */
73
+ export const CHEAP_MODEL: AssemblyAIGatewayModel = "gemini-2.5-flash-lite";
32
74
 
33
75
  /**
34
76
  * Steps one angle may take. A budget, not a limit to be raised when an answer
@@ -40,12 +82,13 @@ import { assemblyAILlm } from "@alexkroman1/aai/llm";
40
82
  export const MAX_RESEARCH_STEPS = 6;
41
83
 
42
84
  /**
43
- * The researcher, and the one line that decides whether any of this works.
85
+ * The researcher, and the field that decides whether any of this works.
44
86
  *
45
- * "Finish with a summary" is not politeness. The parent gets the subagent's
46
- * FINAL message, so a run that ends by saying "Done." has thrown away
47
- * everything it read and no budget recovers it — this is the failure mode the
48
- * `SubagentDef.systemPrompt` contract warns about, stated once, here.
87
+ * `expectedOutput` is not politeness. The parent gets the subagent's FINAL
88
+ * message, so a run that ends by saying "Done." has thrown away everything it
89
+ * read and no budget recovers it. That used to be a paragraph of `systemPrompt`
90
+ * every author had to remember to write; declaring it is what makes the runtime
91
+ * responsible for putting it in front of the model instead.
49
92
  */
50
93
  export const researcher = subagent({
51
94
  name: "researcher",
@@ -55,11 +98,11 @@ export const researcher = subagent({
55
98
  "Search, then open the two or three most promising pages and read them.",
56
99
  "Prefer primary sources and recent ones. If the sources disagree, say so",
57
100
  "rather than picking a side.",
58
- "",
59
- "IMPORTANT: your FINAL message is the only thing the desk receives — it",
60
- "does not see your searches, the pages you opened, or your reasoning. End",
61
- "with a self-contained paragraph of what you found, naming the sources you",
62
- "trusted. Three sentences is plenty; do not write a report.",
101
+ ].join("\n"),
102
+ expectedOutput: [
103
+ "A self-contained paragraph of what you found, naming the sources you",
104
+ "trusted. Three sentences is plenty; do not write a report. The desk does",
105
+ "not see your searches, the pages you opened, or your reasoning — only this.",
63
106
  ].join("\n"),
64
107
  // Read/browse. Independent of the desk's own builtins, which are none: the
65
108
  // agent the caller talks to never touches the network.
@@ -67,6 +110,22 @@ export const researcher = subagent({
67
110
  maxSteps: MAX_RESEARCH_STEPS,
68
111
  });
69
112
 
113
+ /**
114
+ * The three verdicts a check may come back with — see {@link factChecker}.
115
+ *
116
+ * A SCHEMA rather than a sentence prefix. The desk branches on which of the
117
+ * three it is (`tools/verify_claim.ts` tells it to correct itself on
118
+ * `contradicted`), so this is a value the caller reads, not prose it forwards —
119
+ * and a value the caller reads is what `SubagentDef.schema` is for.
120
+ */
121
+ export const VerdictSchema = z.object({
122
+ verdict: z.enum(["confirmed", "contradicted", "unclear"]),
123
+ /** One sentence of what was found, in the checker's own words. */
124
+ detail: z.string().min(1),
125
+ });
126
+
127
+ export type Verdict = z.infer<typeof VerdictSchema>;
128
+
70
129
  /**
71
130
  * The fact-checker: a second ROLE, deliberately narrower than the first.
72
131
  *
@@ -74,21 +133,107 @@ export const researcher = subagent({
74
133
  * `researcher` does), its own budget, and search only. That split is the third
75
134
  * reason to reach for a subagent: a capability a run does not need is one it
76
135
  * cannot misuse.
136
+ *
137
+ * **And it is the worked example for `SubagentDef.schema`.** The verdict is not
138
+ * a style preference — `tools/verify_claim.ts` tells the desk to CORRECT itself
139
+ * when a claim comes back contradicted, and the desk can only act on that if it
140
+ * can READ which of the three it is. This used to be an English sentence prefix
141
+ * (`"Confirmed:"`), restated in `expectedOutput` and re-checked by a
142
+ * `guardrail` doing `startsWith` — three layers carrying one enum, and a model
143
+ * that wrote `"Confirmed - "` was wrong in a way only prose could describe.
144
+ * The schema makes it a parse, and the runtime sends a mis-shaped answer back
145
+ * on the same retry budget the guardrail used.
146
+ *
147
+ * The `guardrail` is gone with it, and that is the split worth remembering: a
148
+ * guardrail is for the judgement a shape cannot express — a missing citation,
149
+ * sources that are all one publisher — and this was never that.
150
+ *
151
+ * **The annotation is what the schema BUYS, said out loud.** `subagent()`
152
+ * answers a {@link TypedSubagentDef} for a def that declares one, and that is
153
+ * the overload `ctx.delegate` reads to hand `tools/verify_claim.ts` a parsed
154
+ * `object` instead of a string. Writing it down means dropping the schema fails
155
+ * HERE, naming the type, rather than three files away at the `.object` read.
77
156
  */
78
- export const factChecker = subagent({
157
+ export const factChecker: TypedSubagentDef<Verdict> = subagent({
79
158
  name: "fact-checker",
80
159
  systemPrompt: [
81
160
  "You check ONE claim against what you can find on the web.",
82
161
  "",
83
- "Search for it. Answer in one sentence, starting with one of",
84
- "'Confirmed:', 'Contradicted:' or 'Unclear:', and name what you found.",
85
- "'Unclear' is a real answer — say it rather than guessing.",
162
+ "Search for it. 'Unclear' is a real answer — say it rather than guessing.",
86
163
  ].join("\n"),
87
- llm: assemblyAILlm({ model: "gemini-2.5-flash-lite" }),
164
+ // The SHAPE comes from `schema`; what stays here is what a schema cannot say —
165
+ // that `detail` is one sentence and names the evidence.
166
+ expectedOutput: "`detail` is one sentence naming what you found and where.",
167
+ schema: VerdictSchema,
168
+ llm: assemblyAILlm({ model: CHEAP_MODEL }),
88
169
  builtinTools: ["web_search"],
89
170
  maxSteps: 2,
90
171
  });
91
172
 
173
+ /**
174
+ * The ROSTER's first specialist: what a word means.
175
+ *
176
+ * No tools at all, which is legal and is the point — a definition is a
177
+ * reasoning pass, and giving this one a search would let it wander off into
178
+ * researching the thing rather than explaining it.
179
+ *
180
+ * The `description` is what the model reads when it picks; the `systemPrompt`
181
+ * is what this subagent reads once it has been picked. Keeping them apart is
182
+ * the difference between a roster the model can route and a list of names.
183
+ */
184
+ export const explainer = subagent({
185
+ name: "explainer",
186
+ description: "Explains a term, unit or concept in plain language, from general knowledge",
187
+ systemPrompt: [
188
+ "You explain one thing to someone who is LISTENING, not reading, and who",
189
+ "asked because they did not want to look it up.",
190
+ "",
191
+ "Use no jargon to explain jargon. If a number makes it concrete, give one.",
192
+ "If you are not sure what the term means in this context, say so — a wrong",
193
+ "definition is worse than an admitted gap.",
194
+ ].join("\n"),
195
+ expectedOutput: "Two sentences, spoken plainly. No preamble and no list.",
196
+ llm: assemblyAILlm({ model: CHEAP_MODEL }),
197
+ maxSteps: 1,
198
+ });
199
+
200
+ /**
201
+ * The roster's second: who argues the other way.
202
+ *
203
+ * Searches, like the fact-checker, and is told to do a different job with the
204
+ * results — which is exactly the case a roster is for. Nothing about
205
+ * `counterpoint` differs from `explainer` except what the caller wanted, so a
206
+ * tool file per specialist would be two bodies differing in one identifier.
207
+ */
208
+ export const counterpoint = subagent({
209
+ name: "counterpoint",
210
+ description: "Finds the strongest argument AGAINST something the desk has said",
211
+ systemPrompt: [
212
+ "You are given a claim and you look for the best case against it.",
213
+ "",
214
+ "Search for the objection, not for the claim. Report the strongest version",
215
+ "you find, and say who makes it. If the objection is weak or fringe, say",
216
+ "that plainly rather than inflating it — the caller is deciding something.",
217
+ ].join("\n"),
218
+ expectedOutput:
219
+ "Two or three sentences: the objection, who makes it, and how seriously to take it.",
220
+ llm: assemblyAILlm({ model: CHEAP_MODEL }),
221
+ builtinTools: ["web_search"],
222
+ maxSteps: 3,
223
+ });
224
+
225
+ /**
226
+ * The roster `agent({ subagents })` publishes — the specialists the MODEL picks
227
+ * between.
228
+ *
229
+ * Declared here rather than inline in `agent.ts` so that membership sits beside
230
+ * the definitions, which is where the question "should this one be routable?"
231
+ * gets answered. `researcher` and `factChecker` are deliberately absent: each is
232
+ * reached by a tool that does real work around the delegation, and a specialist
233
+ * reachable both ways gives the model a second, worse route to it.
234
+ */
235
+ export const roster: SubagentRoster = [explainer, counterpoint];
236
+
92
237
  /** One angle, as the desk holds it. */
93
238
  export interface Finding {
94
239
  /** The angle the researcher was given. */
@@ -137,6 +282,25 @@ export function countWork(toolCalls: readonly SubagentToolCall[]): AngleWork {
137
282
  return { searches, reads };
138
283
  }
139
284
 
285
+ /**
286
+ * What the whole board cost, added up.
287
+ *
288
+ * Here rather than in `tools/briefing_so_far.ts`, where the two `reduce`s used
289
+ * to live, because `slack.ts` says the same number in writing: a recap that
290
+ * counts one way and a Slack post that counts another is the drift a shared
291
+ * helper exists to prevent, and it is the same argument the SDK's own
292
+ * `formatDuration` settles one layer up.
293
+ */
294
+ export function totalWork(findings: readonly DeepReadonly<Finding>[]): AngleWork {
295
+ let searches = 0;
296
+ let reads = 0;
297
+ for (const finding of findings) {
298
+ searches += finding.work.searches;
299
+ reads += finding.work.reads;
300
+ }
301
+ return { searches, reads };
302
+ }
303
+
140
304
  /**
141
305
  * Run one angle and reduce it to what the board holds.
142
306
  *
@@ -173,12 +337,11 @@ export function emptyBriefing(): BriefingState {
173
337
  return { topic: null, findings: [] };
174
338
  }
175
339
 
176
- export const briefingSlot = sessionSlot("briefing", emptyBriefing);
177
-
178
- /** Record a finding, holding {@link MAX_FINDINGS}. */
179
- export function recordFinding(state: BriefingState, finding: Finding): void {
180
- pushCapped(state.findings, finding, MAX_FINDINGS);
181
- }
340
+ export const briefingSlot = sessionSlot("briefing", emptyBriefing, {
341
+ // Held by the slot rather than by a `recordFinding` wrapper, so a tool that
342
+ // pushes to the board directly is bounded too.
343
+ caps: { findings: MAX_FINDINGS },
344
+ });
182
345
 
183
346
  /**
184
347
  * The board as a READ hands it out — deep-frozen, and typed to say so, which is
@@ -186,15 +349,41 @@ export function recordFinding(state: BriefingState, finding: Finding): void {
186
349
  */
187
350
  export type FrozenBriefing = DeepReadonly<BriefingState>;
188
351
 
189
- /** A finding named by what the caller would say: its angle, loosely matched. */
352
+ /**
353
+ * A finding named by what the caller would say: its angle, loosely matched.
354
+ *
355
+ * `resolveOne`'s, and this is the one place on the board where that contract is
356
+ * the right one. Every other lookup in this template — and in almost every
357
+ * template — is an exact id the model already chose off a list, where "no such
358
+ * id" is the whole answer. Here the argument is the caller's OWN WORDS about
359
+ * something already on the board, so two findings can match one phrase.
360
+ *
361
+ * What it replaces guessed. The `.find()` here took the FIRST angle whose text
362
+ * overlapped the phrase in either direction, so "lead times" quietly picked one
363
+ * of "install lead times" and "battery lead times" by board order — and
364
+ * answered `undefined` for both "nothing matches" and "several do", which is
365
+ * the distinction the caller needs. It now returns a `ToolFailure` LISTING the
366
+ * candidates, so the desk asks which one instead of fact-checking against the
367
+ * wrong context.
368
+ *
369
+ * The scorer is the overlap that was inline before, scored rather than
370
+ * booleaned: a longer shared prefix of words wins, and a tie FAILS.
371
+ */
190
372
  export function findByAngle(
191
373
  state: FrozenBriefing,
192
374
  angle: string,
193
- ): DeepReadonly<Finding> | undefined {
375
+ ): DeepReadonly<Finding> | ToolFailure {
194
376
  const wanted = angle.trim().toLowerCase();
195
- if (wanted === "") return undefined;
196
- return state.findings.find(
197
- (finding) =>
198
- finding.angle.toLowerCase().includes(wanted) || wanted.includes(finding.angle.toLowerCase()),
199
- );
377
+ if (wanted === "") return toolFailure("Say which angle on the board this claim came from.");
378
+ return resolveOne(state.findings, wanted, {
379
+ label: "angle",
380
+ describe: (finding) => finding.angle,
381
+ // Word overlap in either direction, which is what the substring test was
382
+ // approximating — counted, so "install lead times" beats "lead times" for
383
+ // the phrase "install lead times" instead of both merely being true.
384
+ score: (finding, text) => {
385
+ const words = finding.angle.toLowerCase().split(/\s+/).filter(Boolean);
386
+ return words.filter((word) => text.includes(word)).length;
387
+ },
388
+ });
200
389
  }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Where a briefing GOES when the call ends.
3
+ *
4
+ * A phone call is the worst place to keep anything: the caller hangs up and
5
+ * four researchers' work goes with it. `tools/send_briefing.ts` posts the board
6
+ * to the desk's Slack channel, and this module is the half of that which is
7
+ * about BRIEFINGS.
8
+ *
9
+ * **Everything else belongs to `@alexkroman1/aai/channels`, and that is the
10
+ * point of the split.** Slack has two things people call a webhook URL and they
11
+ * take different bodies; one of them cannot render structure at all; mrkdwn
12
+ * reserves three characters; a 4xx and a 5xx deserve opposite advice. Not one
13
+ * of those rules is about briefings, and a template is the wrong place to learn
14
+ * them — so `slackChannel()` names the destination and `sendToChannel` posts to
15
+ * it, leaving {@link briefingMessage} as the only thing here that a reader of
16
+ * THIS template has to think about.
17
+ *
18
+ * It is a pure function for the same reason `podcast-digest`'s is: a spec
19
+ * asserts what the desk would post without a network and without knowing
20
+ * Slack's payload shape. Asserting the payload itself — `renderChannelPayload`,
21
+ * the Block Kit, the escaping — would pin the SDK's rendering from the outside,
22
+ * which is exactly the duplication moving it there removed.
23
+ */
24
+
25
+ import { type DeepReadonly, type ToolFailure, toolFailure } from "@alexkroman1/aai";
26
+ import {
27
+ type ChannelMessage,
28
+ type ChannelSection,
29
+ isSlackWebhookUrl,
30
+ type SlackChannel,
31
+ slackChannel,
32
+ } from "@alexkroman1/aai/channels";
33
+ import { plural } from "@alexkroman1/aai/utils";
34
+ import { type Finding, type FrozenBriefing, totalWork } from "./shared.ts";
35
+
36
+ /**
37
+ * The variable holding the desk's channel.
38
+ *
39
+ * A webhook URL IS the credential — anyone holding it can post — so it is a
40
+ * deployment secret (`aai secret put SLACK_WEBHOOK_URL`) and never a tool
41
+ * argument. A destination the MODEL can name is a destination a caller can talk
42
+ * it into, and what would go there is everything the desk researched.
43
+ *
44
+ * Deliberately NOT on `agent({ requiredEnv })`, which is the other half of that
45
+ * decision: `requiredEnv` refuses the DEPLOY, and a desk with no Slack channel
46
+ * is still a desk. What it costs is that the miss surfaces mid-call instead, so
47
+ * it has to surface well — see `tools/send_briefing.ts`.
48
+ */
49
+ export const DESTINATION_ENV = "SLACK_WEBHOOK_URL";
50
+
51
+ /**
52
+ * The destination, or a refusal to post to it.
53
+ *
54
+ * `isSlackWebhookUrl` is a SECURITY boundary here and not a typo check: the
55
+ * value becomes the target of a POST carrying everything the desk was told, so
56
+ * anything that is not Slack is an exfiltration endpoint somebody put in a
57
+ * secret. Refusing it before the post is also the only moment at which the
58
+ * refusal is cheap.
59
+ *
60
+ * `SlackChannel | ToolFailure` is this template's own Result idiom, the one
61
+ * `findByAngle` already answers with, so the tool forwards a sentence the desk
62
+ * can say rather than throwing at a caller who is on the line.
63
+ */
64
+ export function briefingChannel(webhookUrl: string): SlackChannel | ToolFailure {
65
+ if (!isSlackWebhookUrl(webhookUrl)) {
66
+ return toolFailure(
67
+ `${DESTINATION_ENV} is not a Slack webhook URL, so the desk will not post to it. ` +
68
+ "Tell the caller the briefing cannot be sent and that the destination needs fixing.",
69
+ );
70
+ }
71
+ return slackChannel({ webhookUrl });
72
+ }
73
+
74
+ /**
75
+ * The board as a message — one section per angle, in the order they were
76
+ * researched.
77
+ *
78
+ * `text` is the notification line, and on a Slack workflow trigger it is the
79
+ * WHOLE message, so it stands on its own rather than repeating a heading that
80
+ * arm will never render.
81
+ */
82
+ export function briefingMessage(board: FrozenBriefing): ChannelMessage {
83
+ const topic = board.topic ?? "an unnamed subject";
84
+ const angles = board.findings.length;
85
+ return {
86
+ text: `Briefing on ${topic}: ${angles} ${plural(angles, "angle")}`,
87
+ heading: `Briefing: ${topic}`,
88
+ subtitle: costLine(board),
89
+ sections: board.findings.map(findingSection),
90
+ };
91
+ }
92
+
93
+ /**
94
+ * One angle, written out.
95
+ *
96
+ * The summary goes in whole here, which is the one place in this template it
97
+ * does: everywhere else the desk is told to shorten it, because the caller is
98
+ * LISTENING. A reader can skim, so the section keeps what the researcher wrote.
99
+ */
100
+ function findingSection(finding: DeepReadonly<Finding>): ChannelSection {
101
+ return { title: finding.angle, body: finding.summary };
102
+ }
103
+
104
+ /** What the briefing cost, as the desk is willing to say it in writing. */
105
+ function costLine(board: FrozenBriefing): string {
106
+ const { searches, reads } = totalWork(board.findings);
107
+ return `${searches} ${plural(searches, "search", "searches")}, ${reads} ${plural(reads, "page")} read`;
108
+ }
@@ -4,7 +4,11 @@ and you have a small team of researchers you can put on it.
4
4
  ## How you work
5
5
 
6
6
  - You have no way to look anything up yourself. Everything you know about the
7
- outside world comes back from `research_topic` or `verify_claim`.
7
+ outside world comes back from `research_topic`, `verify_claim` or `delegate`.
8
+ - `delegate` hands one question to a specialist: the explainer for "what does
9
+ that word mean", the counterpoint for "who says otherwise". Use it for a
10
+ question that stands on its own — a subject worth several angles is
11
+ `research_topic`, and a fact to check is `verify_claim`.
8
12
  - When the caller names a subject, decide the two or three ANGLES worth
9
13
  researching and call `research_topic` once with all of them. Do not call it
10
14
  once per angle — they run in parallel, and that is why the caller is not
@@ -14,6 +18,11 @@ and you have a small team of researchers you can put on it.
14
18
  "how European home battery prices moved in 2025" is.
15
19
  - Say you are looking it up BEFORE you call the tool. A silent line is the
16
20
  worst thing that can happen on a phone call, and a briefing takes a moment.
21
+ - `send_briefing` posts what is on the board to the team's channel. Offer it
22
+ when the caller wants the briefing in writing or wants it passed on to
23
+ someone who was not on the call, and say you are sending it before you call
24
+ it. If it comes back refusing, say plainly that it has not sent — never let
25
+ them hang up believing it did.
17
26
 
18
27
  ## How you talk
19
28
 
@@ -26,7 +35,8 @@ and you have a small team of researchers you can put on it.
26
35
  figures say", "one industry blog says") and say when your researchers
27
36
  disagreed. A briefing that flattens a disagreement is worse than no briefing.
28
37
  - If the caller pushes back on a fact, check it with `verify_claim` rather than
29
- defending it. If it comes back contradicted, correct yourself plainly.
38
+ defending it. If it comes back contradicted, correct yourself plainly. If it
39
+ comes back `unusable`, say it is unresolved — do not round it up to confirmed.
30
40
  - `briefing_so_far` is for a recap. It costs nothing, so use it rather than
31
41
  reciting from memory.
32
42
 
@@ -1,6 +1,5 @@
1
- import { tool } from "@alexkroman1/aai";
2
1
  import { z } from "zod";
3
- import { briefingSlot } from "../shared.ts";
2
+ import { briefingSlot, totalWork } from "../shared.ts";
4
3
 
5
4
  /**
6
5
  * Read the board back.
@@ -9,14 +8,19 @@ import { briefingSlot } from "../shared.ts";
9
8
  * that reason: a caller who says "what have you got so far" after four
10
9
  * delegated runs should not cost a fifth. What the desk knows is on the slot;
11
10
  * this hands it over.
11
+ *
12
+ * **Declared as `briefingSlot.tool`**, which is the SDK's way of saying "this
13
+ * one reads": the board arrives as an argument, deep-frozen, so nothing here
14
+ * can quietly write to it and a body that tried would not compile. It used to
15
+ * be a `tool()` opening with `briefingSlot.get(ctx)` — the same behaviour with
16
+ * the declaration doing none of the work.
12
17
  */
13
- export default tool({
18
+ export default briefingSlot.tool({
14
19
  description:
15
20
  "List the angles researched on this call and what each one found. Use it " +
16
21
  "when the caller asks for a recap, or before you offer to dig further.",
17
22
  inputSchema: z.object({}),
18
- execute: (_args, ctx) => {
19
- const board = briefingSlot.get(ctx);
23
+ execute: (_args, board) => {
20
24
  if (board.findings.length === 0) {
21
25
  return {
22
26
  topic: null,
@@ -24,11 +28,15 @@ export default tool({
24
28
  message: "Nothing researched yet — ask what they want looked into.",
25
29
  };
26
30
  }
31
+ // `totalWork` rather than two `reduce`s here: `slack.ts` says the same
32
+ // numbers in writing, and a recap that counts one way while the Slack post
33
+ // counts another is a disagreement nobody would think to test for.
34
+ const { searches, reads } = totalWork(board.findings);
27
35
  return {
28
36
  topic: board.topic,
29
37
  findings: board.findings,
30
- totalSearches: board.findings.reduce((sum, finding) => sum + finding.work.searches, 0),
31
- totalReads: board.findings.reduce((sum, finding) => sum + finding.work.reads, 0),
38
+ totalSearches: searches,
39
+ totalReads: reads,
32
40
  message: "Recap the through-line in one breath, then offer to go deeper on one angle.",
33
41
  };
34
42
  },
@@ -1,23 +1,25 @@
1
- import { errorMessage, tool, toolFailure } from "@alexkroman1/aai";
1
+ import { tool, toolFailure } from "@alexkroman1/aai";
2
+ import { mapSettled, partitionSettled } from "@alexkroman1/aai/step";
2
3
  import { z } from "zod";
3
- import type { Finding } from "../shared.ts";
4
- import { briefingSlot, MAX_ANGLES, recordFinding, researchAngle } from "../shared.ts";
4
+ import { briefingSlot, MAX_ANGLES, researchAngle } from "../shared.ts";
5
5
 
6
6
  /**
7
7
  * Fan a topic out across angles, one researcher subagent each, in PARALLEL.
8
8
  *
9
- * **The `Promise.allSettled` is the template's whole point.** Each angle is an
9
+ * **The settled fan-out is the template's whole point.** Each angle is an
10
10
  * independent run with its own context window, so four of them cost the caller
11
11
  * the SLOWEST one rather than the sum — and nothing they read reaches this
12
12
  * conversation, only what each one concluded. Running the same four angles as
13
13
  * four `ctx.generate` calls in one loop would be slower and would put every
14
14
  * intermediate page in the desk's own prompt.
15
15
  *
16
- * **`allSettled`, not `all`.** One angle that fails (a provider hiccup, a
17
- * subagent that ran out of budget with nothing to say) must not sink a
18
- * briefing whose other three came back — a caller on the phone would rather
19
- * hear three answers and one apology than an error. The failures are reported
20
- * BY ANGLE so the desk can say which one is missing and offer to retry it.
16
+ * **Settled, not raced.** One angle that fails (a provider hiccup, a subagent
17
+ * that ran out of budget with nothing to say) must not sink a briefing whose
18
+ * other three came back — a caller on the phone would rather hear three answers
19
+ * and one apology than an error. `mapSettled` keeps each angle beside its
20
+ * outcome, so the failures are reported BY ANGLE and the desk can say which one
21
+ * is missing and offer to retry it. `Infinity` is the width `allSettled` had:
22
+ * `MAX_ANGLES` already bounds the fan-out at the schema.
21
23
  *
22
24
  * **The await comes first, then the mutation.** `slot.update`'s window is
23
25
  * synchronous by contract, so the fan-out finishes before the board is touched
@@ -46,32 +48,22 @@ export default tool({
46
48
  return toolFailure("No angles to research — say what the caller wants looked up.");
47
49
  }
48
50
 
49
- const settled = await Promise.allSettled(
50
- angles.map((angle) => researchAngle(ctx.delegate, args.topic, angle)),
51
+ const { ok, failed } = partitionSettled(
52
+ await mapSettled(angles, Number.POSITIVE_INFINITY, (angle) =>
53
+ researchAngle(ctx.delegate, args.topic, angle),
54
+ ),
51
55
  );
52
-
53
- // Two typed lists rather than one union filtered twice: `"summary" in one`
54
- // reads fine and narrows nothing a `.filter` result keeps, so the union
55
- // version needs a cast — the laundering this repo's ratchet counts.
56
- const summaries: Finding[] = [];
57
- const failures: { angle: string; error: string }[] = [];
58
- settled.forEach((outcome, index) => {
59
- if (outcome.status === "fulfilled") {
60
- summaries.push(outcome.value);
61
- return;
62
- }
63
- failures.push({ angle: angles[index] ?? "", error: errorMessage(outcome.reason) });
64
- });
65
-
66
- if (summaries.length === 0) {
56
+ if (ok.length === 0) {
67
57
  return toolFailure(
68
- `Every angle failed. The first said: ${failures[0]?.error ?? "no reason given"}`,
58
+ `Every angle failed. The first said: ${failed[0]?.error ?? "no reason given"}`,
69
59
  );
70
60
  }
61
+ const summaries = ok.map((one) => one.value);
62
+ const failures = failed.map((one) => ({ angle: one.item, error: one.error }));
71
63
 
72
64
  return briefingSlot.update(ctx, (board) => {
73
65
  board.topic = args.topic;
74
- for (const finding of summaries) recordFinding(board, finding);
66
+ board.findings.push(...summaries);
75
67
  return {
76
68
  topic: args.topic,
77
69
  findings: summaries,