@alexkroman1/aai-cli 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{_agent-BopNO5Bq.mjs → _agent-BN21AHsJ.mjs} +4 -4
- package/dist/_api-client-Uljj0CQi.mjs +312 -0
- package/dist/_api-client.d.ts +69 -1
- package/dist/{_bundler-DCuNHjDF.mjs → _bundler-DvZDEu2p.mjs} +67 -7
- package/dist/_bundler.d.ts +15 -0
- package/dist/_cli-common.d.ts +42 -0
- package/dist/{client-bundler-DE-AGdm7.mjs → _client-plugins-kR43nZnb.mjs} +30 -132
- package/dist/_client-plugins.d.ts +16 -0
- package/dist/{_config-mq1I5Cva.mjs → _config-Dlh8PRRp.mjs} +2 -20
- package/dist/_config.d.ts +0 -8
- package/dist/{_dev-server-D6VSQbYW.mjs → _dev-server-C_zidzWj.mjs} +15 -10
- package/dist/_dev-session-ticket.d.ts +3 -0
- package/dist/_dev-tunnel.d.ts +20 -2
- package/dist/_dotenv-file.d.ts +6 -0
- package/dist/_init.d.ts +2 -11
- package/dist/_output.d.ts +47 -20
- package/dist/_safe-write.d.ts +38 -0
- package/dist/{_server-common-CVXIeWrY.mjs → _server-common-C6j67AcZ.mjs} +37 -2
- package/dist/_server-common.d.ts +16 -0
- package/dist/{_slug-api-BnmTHtjd.mjs → _slug-api-B9cptz7Q.mjs} +3 -2
- package/dist/_start-affinity.d.ts +70 -0
- package/dist/_start-log.d.ts +39 -0
- package/dist/_start-router.d.ts +85 -0
- package/dist/_start-run.d.ts +101 -0
- package/dist/_start-worker.d.ts +61 -0
- package/dist/_start-workers-BNdOnTal.mjs +529 -0
- package/dist/_start-workers.d.ts +262 -0
- package/dist/_studio-zympBLlD.mjs +140 -0
- package/dist/_studio.d.ts +14 -0
- package/dist/_target-bundle.d.ts +4 -0
- package/dist/{_templates-BVMVsQh0.mjs → _templates-ChZuhW66.mjs} +110 -8
- package/dist/_templates.d.ts +20 -1
- package/dist/{_typecheck-gate-CcX2gLJZ.mjs → _typecheck-gate-BNF5cboL.mjs} +2 -2
- package/dist/_ui-C0RufoYZ.mjs +147 -0
- package/dist/_ui.d.ts +14 -3
- package/dist/_utils-ChU85MEg.mjs +486 -0
- package/dist/_utils.d.ts +28 -0
- package/dist/_vendor-openers.d.ts +87 -0
- package/dist/{_vitest-runner-CKI8_K1b.mjs → _vitest-runner-tzyto9IU.mjs} +7 -3
- package/dist/_vitest-runner.d.ts +8 -1
- package/dist/{build-BnXLgfk-.mjs → build-BHgd-QYb.mjs} +13 -10
- package/dist/build.d.ts +21 -0
- package/dist/cli-workflow.d.ts +7 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.mjs +243 -70
- package/dist/client-bundler-CImhqcp2.mjs +133 -0
- package/dist/client-bundler.mjs +1 -1
- package/dist/{console-tVBjfKyR.mjs → console-DwycgRkC.mjs} +4 -5
- package/dist/delete-ZcA3J_3o.mjs +75 -0
- package/dist/delete.d.ts +10 -1
- package/dist/{deploy-eWDoiwvn.mjs → deploy-CkfkiZE3.mjs} +9 -9
- package/dist/{dev-CT_QHHZL.mjs → dev-BX9g6qcf.mjs} +81 -18
- package/dist/{eval-Dl8o91yC.mjs → eval-CUKvfxRq.mjs} +4 -4
- package/dist/{init-CidslZZz.mjs → init-B9Uw76-_.mjs} +62 -32
- package/dist/{login-oJdBWu2B.mjs → login-Ct73CqU1.mjs} +30 -6
- package/dist/login.d.ts +2 -0
- package/dist/{logs-CkmFdSbr.mjs → logs-BBsUy96d.mjs} +59 -14
- package/dist/logs.d.ts +4 -1
- package/dist/project-config.mjs +1 -1
- package/dist/scaffold/CLAUDE.md +72 -55
- package/dist/scaffold/agent-guide/AGENT-API.md +44 -34
- package/dist/scaffold/agent-guide/HOSTING.md +11 -0
- package/dist/scaffold/agent-guide/TESTING-EVALS.md +105 -36
- package/dist/scaffold/agent-guide/TOOLS.md +189 -33
- package/dist/scaffold/agent-guide/UI.md +111 -39
- package/dist/scaffold/agent-guide/WORKFLOWS.md +234 -160
- package/dist/scaffold/package.json +4 -4
- package/dist/{secret-DPdPEet2.mjs → secret-CKjHRrVX.mjs} +112 -35
- package/dist/start.d.ts +14 -14
- package/dist/start.mjs +840 -40
- package/dist/{studio-COjK25Rl.mjs → studio-U6DvBNAx.mjs} +123 -35
- package/dist/studio.d.ts +1 -0
- package/dist/templates/applicant-screening-agent/agent.eval.test.ts +23 -52
- package/dist/templates/applicant-screening-agent/agent.test.ts +821 -826
- package/dist/templates/applicant-screening-agent/agent.ts +1 -6
- package/dist/templates/applicant-screening-agent/client.tsx +1 -19
- package/dist/templates/applicant-screening-agent/shared.ts +8 -18
- package/dist/templates/applicant-screening-agent/tools/candidate_details.ts +24 -27
- package/dist/templates/applicant-screening-agent/tools/proceed_to_emails.ts +75 -82
- package/dist/templates/applicant-screening-agent/tools/read_email.ts +24 -24
- package/dist/templates/applicant-screening-agent/tools/rescore_with_feedback.ts +92 -99
- package/dist/templates/applicant-screening-agent/tools/screen_candidates.ts +72 -83
- package/dist/templates/applicant-screening-agent/tools/screening_status.ts +21 -29
- package/dist/templates/call-audit-workflow/agent.eval.test.ts +14 -19
- package/dist/templates/call-audit-workflow/agent.test.ts +275 -169
- package/dist/templates/call-audit-workflow/agent.ts +12 -30
- package/dist/templates/call-audit-workflow/client.tsx +9 -27
- package/dist/templates/call-audit-workflow/guards.test.ts +24 -71
- package/dist/templates/call-audit-workflow/workflows/audit.ts +24 -52
- package/dist/templates/call-audit-workflow/workflows/ingest.ts +32 -59
- package/dist/templates/call-audit-workflow/workflows/media.ts +4 -44
- package/dist/templates/call-audit-workflow/workflows/summarize.ts +72 -107
- package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
- package/dist/templates/code-interpreter-agent/agent.test.ts +4 -17
- package/dist/templates/code-interpreter-agent/agent.ts +1 -1
- package/dist/templates/coding-agent/agent.test.ts +17 -12
- package/dist/templates/coding-agent/agent.ts +1 -1
- package/dist/templates/custom-pipeline-agent/agent.test.ts +6 -14
- package/dist/templates/custom-pipeline-agent/agent.ts +1 -1
- package/dist/templates/custom-pipeline-agent/modes.test.ts +0 -1
- package/dist/templates/document-redline-workflow/agent.test.ts +88 -221
- package/dist/templates/document-redline-workflow/agent.ts +22 -32
- package/dist/templates/document-redline-workflow/client.tsx +46 -88
- package/dist/templates/document-redline-workflow/workflows/prompts.ts +0 -3
- package/dist/templates/document-redline-workflow/workflows/redline.ts +33 -50
- package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +22 -71
- package/dist/templates/emergency-dispatch-agent/agent.test.ts +466 -495
- package/dist/templates/emergency-dispatch-agent/agent.ts +27 -43
- package/dist/templates/emergency-dispatch-agent/client.tsx +85 -119
- package/dist/templates/emergency-dispatch-agent/shared.ts +51 -88
- package/dist/templates/emergency-dispatch-agent/tools/incident_add_note.ts +11 -17
- package/dist/templates/emergency-dispatch-agent/tools/incident_create.ts +21 -30
- package/dist/templates/emergency-dispatch-agent/tools/incident_escalate.ts +60 -63
- package/dist/templates/emergency-dispatch-agent/tools/incident_get.ts +6 -15
- package/dist/templates/emergency-dispatch-agent/tools/incident_triage.ts +40 -53
- package/dist/templates/emergency-dispatch-agent/tools/incident_update_status.ts +41 -47
- package/dist/templates/emergency-dispatch-agent/tools/ops_dashboard.ts +2 -2
- package/dist/templates/emergency-dispatch-agent/tools/ops_protocols.ts +1 -1
- package/dist/templates/emergency-dispatch-agent/tools/ops_run_scenario.ts +13 -10
- package/dist/templates/emergency-dispatch-agent/tools/resources_dispatch.ts +42 -51
- package/dist/templates/emergency-dispatch-agent/tools/resources_update_status.ts +40 -41
- package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +14 -42
- package/dist/templates/entertainment-picks-agent/agent.test.ts +174 -221
- package/dist/templates/entertainment-picks-agent/agent.ts +1 -6
- package/dist/templates/entertainment-picks-agent/client.tsx +1 -12
- package/dist/templates/entertainment-picks-agent/shared.ts +12 -6
- package/dist/templates/entertainment-picks-agent/tools/recommend.ts +2 -2
- package/dist/templates/entertainment-picks-agent/tools/revisit.ts +1 -0
- package/dist/templates/executive-inbox-agent/agent.eval.test.ts +15 -22
- package/dist/templates/executive-inbox-agent/agent.test.ts +515 -527
- package/dist/templates/executive-inbox-agent/agent.ts +4 -8
- package/dist/templates/executive-inbox-agent/calendar.test.ts +23 -22
- package/dist/templates/executive-inbox-agent/client.tsx +1 -23
- package/dist/templates/executive-inbox-agent/review.ts +125 -113
- package/dist/templates/executive-inbox-agent/shared.ts +3 -0
- package/dist/templates/executive-inbox-agent/tools/ask_question.ts +6 -6
- package/dist/templates/executive-inbox-agent/tools/draft_reply.ts +16 -18
- package/dist/templates/executive-inbox-agent/tools/inbox_status.ts +1 -0
- package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +20 -20
- package/dist/templates/executive-inbox-agent/tools/new_email.ts +17 -21
- package/dist/templates/executive-inbox-agent/tools/open_email.ts +72 -74
- package/dist/templates/executive-inbox-agent/tools/review_memory.ts +1 -0
- package/dist/templates/executive-inbox-agent/tools/send_calendar_invite.ts +19 -20
- package/dist/templates/executive-inbox-agent/tools/triage_inbox.ts +53 -50
- package/dist/templates/front-desk-agent/agent.eval.test.ts +22 -14
- package/dist/templates/front-desk-agent/agent.test.ts +139 -123
- package/dist/templates/front-desk-agent/agent.ts +4 -7
- package/dist/templates/front-desk-agent/shared.ts +88 -74
- package/dist/templates/front-door-agent/agent.eval.test.ts +61 -0
- package/dist/templates/front-door-agent/agent.test.ts +393 -0
- package/dist/templates/front-door-agent/agent.ts +35 -0
- package/dist/templates/front-door-agent/client.tsx +250 -0
- package/dist/templates/front-door-agent/routes.ts +91 -0
- package/dist/templates/front-door-agent/shared.ts +35 -0
- package/dist/templates/front-door-agent/system-prompt.md +12 -0
- package/dist/templates/front-door-agent/tools/leave_message.ts +39 -0
- package/dist/templates/front-door-agent/tools/link_phone.ts +49 -0
- package/dist/templates/front-door-agent/workflows/announce.ts +38 -0
- package/dist/templates/front-door-agent/workflows/digest.ts +53 -0
- package/dist/templates/front-door-agent/workflows/pair.ts +28 -0
- package/dist/templates/home-assistant-agent/agent.eval.test.ts +5 -9
- package/dist/templates/home-assistant-agent/agent.test.ts +513 -399
- package/dist/templates/home-assistant-agent/agent.ts +8 -5
- package/dist/templates/home-assistant-agent/client.tsx +48 -9
- package/dist/templates/home-assistant-agent/tools/cancel_reminders.ts +1 -0
- package/dist/templates/home-assistant-agent/tools/remind_me.ts +2 -1
- package/dist/templates/hotel-reception-agent/agent.eval.test.ts +27 -52
- package/dist/templates/hotel-reception-agent/agent.test.ts +980 -964
- package/dist/templates/hotel-reception-agent/agent.ts +8 -21
- package/dist/templates/hotel-reception-agent/booking.ts +2 -2
- package/dist/templates/hotel-reception-agent/client.tsx +5 -20
- package/dist/templates/hotel-reception-agent/concierge.ts +2 -0
- package/dist/templates/hotel-reception-agent/desk-seams.test.ts +285 -275
- package/dist/templates/hotel-reception-agent/desk.ts +45 -12
- package/dist/templates/hotel-reception-agent/hotel.ts +6 -6
- package/dist/templates/hotel-reception-agent/restaurant.ts +3 -4
- package/dist/templates/hotel-reception-agent/session.ts +14 -30
- package/dist/templates/hotel-reception-agent/shared.ts +33 -46
- package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +14 -15
- package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -2
- package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +13 -10
- package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +6 -7
- package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +5 -4
- package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +6 -5
- package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +3 -4
- package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +4 -4
- package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/record_followup.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +4 -4
- package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +4 -3
- package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/set_stay.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +30 -32
- package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +22 -25
- package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/update_card.ts +5 -4
- package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +23 -13
- package/dist/templates/kitchen-coach-agent/agent.eval.test.ts +38 -0
- package/dist/templates/kitchen-coach-agent/agent.test.ts +204 -0
- package/dist/templates/kitchen-coach-agent/agent.ts +22 -0
- package/dist/templates/kitchen-coach-agent/client.tsx +232 -0
- package/dist/templates/kitchen-coach-agent/history.ts +37 -0
- package/dist/templates/kitchen-coach-agent/shared.ts +131 -0
- package/dist/templates/kitchen-coach-agent/system-prompt.md +17 -0
- package/dist/templates/kitchen-coach-agent/tools/get_kitchen.ts +17 -0
- package/dist/templates/kitchen-coach-agent/tools/scale_amount.ts +31 -0
- package/dist/templates/kitchen-coach-agent/tools/start_timer.ts +24 -0
- package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -40
- package/dist/templates/link-digest-workflow/agent.test.ts +84 -164
- package/dist/templates/link-digest-workflow/agent.ts +27 -42
- package/dist/templates/link-digest-workflow/api-client.ts +3 -2
- package/dist/templates/link-digest-workflow/client.tsx +5 -5
- package/dist/templates/link-digest-workflow/workflows/digest.ts +53 -95
- package/dist/templates/medication-safety-agent/agent.eval.test.ts +10 -30
- package/dist/templates/medication-safety-agent/agent.test.ts +16 -46
- package/dist/templates/medication-safety-agent/agent.ts +1 -4
- package/dist/templates/medication-safety-agent/tools/check_drug_interaction.ts +13 -10
- package/dist/templates/meeting-recap-agent/agent.eval.test.ts +238 -396
- package/dist/templates/meeting-recap-agent/agent.test.ts +414 -1070
- package/dist/templates/meeting-recap-agent/agent.ts +26 -67
- package/dist/templates/meeting-recap-agent/system-prompt.md +1 -0
- package/dist/templates/meeting-recap-agent/tools/keep_transcript.ts +10 -12
- package/dist/templates/meeting-recap-agent/tools/request_recap.ts +9 -20
- package/dist/templates/meeting-recap-agent/workflows/recap.ts +224 -547
- package/dist/templates/outbound-call-agent/agent.eval.test.ts +10 -12
- package/dist/templates/outbound-call-agent/agent.test.ts +419 -453
- package/dist/templates/outbound-call-agent/agent.ts +57 -62
- package/dist/templates/outbound-call-agent/api.ts +53 -68
- package/dist/templates/outbound-call-agent/client.tsx +105 -176
- package/dist/templates/outbound-call-agent/shared.ts +10 -39
- package/dist/templates/outbound-call-agent/system-prompt.md +3 -4
- package/dist/templates/outbound-call-agent/tools/end_call.ts +15 -12
- package/dist/templates/outbound-call-agent/tools/press_keys.ts +8 -13
- package/dist/templates/outbound-call-agent/workflows/call.ts +89 -62
- package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +18 -54
- package/dist/templates/pizza-ordering-agent/agent.test.ts +205 -244
- package/dist/templates/pizza-ordering-agent/agent.ts +5 -12
- package/dist/templates/pizza-ordering-agent/client.tsx +3 -14
- package/dist/templates/pizza-ordering-agent/shared.ts +31 -36
- package/dist/templates/pizza-ordering-agent/tools/add_pizza.ts +1 -0
- package/dist/templates/pizza-ordering-agent/tools/place_order.ts +5 -2
- package/dist/templates/pizza-ordering-agent/tools/remove_pizza.ts +1 -0
- package/dist/templates/pizza-ordering-agent/tools/update_pizza.ts +2 -3
- package/dist/templates/pizza-ordering-agent/tools/view_order.ts +7 -3
- package/dist/templates/podcast-digest-workflow/agent.test.ts +53 -102
- package/dist/templates/podcast-digest-workflow/agent.ts +11 -17
- package/dist/templates/podcast-digest-workflow/client.tsx +29 -51
- package/dist/templates/podcast-digest-workflow/workflows/digest.ts +24 -26
- package/dist/templates/push-to-talk-agent/agent.eval.test.ts +13 -14
- package/dist/templates/push-to-talk-agent/agent.test.ts +30 -23
- package/dist/templates/push-to-talk-agent/agent.ts +1 -5
- package/dist/templates/push-to-talk-agent/client.tsx +1 -11
- package/dist/templates/push-to-talk-agent/shared.ts +12 -6
- package/dist/templates/push-to-talk-agent/tools/list_notes.ts +1 -0
- package/dist/templates/push-to-talk-agent/tools/save_note.ts +1 -0
- package/dist/templates/quickstart-agent/agent.eval.test.ts +0 -10
- package/dist/templates/quickstart-agent/agent.test.ts +18 -30
- package/dist/templates/quickstart-agent/agent.ts +3 -4
- package/dist/templates/research-handoff-agent/agent.eval.test.ts +161 -290
- package/dist/templates/research-handoff-agent/agent.test.ts +131 -457
- package/dist/templates/research-handoff-agent/agent.ts +26 -86
- package/dist/templates/research-handoff-agent/system-prompt.md +1 -0
- package/dist/templates/research-handoff-agent/tools/file_it_now.ts +8 -21
- package/dist/templates/research-handoff-agent/tools/request_research.ts +7 -16
- package/dist/templates/research-handoff-agent/workflows/research.ts +88 -40
- package/dist/templates/research-planner-agent/agent.eval.test.ts +15 -40
- package/dist/templates/research-planner-agent/agent.test.ts +415 -464
- package/dist/templates/research-planner-agent/agent.ts +3 -8
- package/dist/templates/research-planner-agent/client.tsx +1 -14
- package/dist/templates/research-planner-agent/procedure.ts +9 -3
- package/dist/templates/research-planner-agent/shared.ts +30 -33
- package/dist/templates/research-planner-agent/tools/plan_status.ts +7 -15
- package/dist/templates/research-planner-agent/tools/revise_plan.ts +29 -36
- package/dist/templates/research-planner-agent/tools/start_plan.ts +25 -39
- package/dist/templates/research-planner-agent/tools/work_next_step.ts +25 -42
- package/dist/templates/retail-orders-agent/agent.eval.test.ts +14 -34
- package/dist/templates/retail-orders-agent/agent.test.ts +1079 -1073
- package/dist/templates/retail-orders-agent/agent.ts +25 -78
- package/dist/templates/retail-orders-agent/client.tsx +120 -168
- package/dist/templates/retail-orders-agent/pending.test.ts +7 -14
- package/dist/templates/retail-orders-agent/registry.test.ts +93 -192
- package/dist/templates/retail-orders-agent/shared.test.ts +1 -1
- package/dist/templates/retail-orders-agent/shared.ts +10 -20
- package/dist/templates/retail-orders-agent/store.test.ts +46 -128
- package/dist/templates/retail-orders-agent/store.ts +42 -175
- package/dist/templates/retail-orders-agent/tools/cancel_change.ts +3 -6
- package/dist/templates/retail-orders-agent/tools/cancel_pending_order.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/confirm_change.ts +4 -6
- package/dist/templates/retail-orders-agent/tools/exchange_delivered_order_items.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/find_user_id_by_email.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/find_user_id_by_name_zip.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/get_item_details.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/get_order_details.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/get_product_details.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/get_user_details.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/list_all_product_types.ts +3 -8
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_address.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_items.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_payment.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/modify_user_address.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/return_delivered_order_items.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/transfer_to_human_agents.ts +3 -4
- package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +22 -25
- package/dist/templates/roadside-assistance-agent/agent.test.ts +453 -490
- package/dist/templates/roadside-assistance-agent/agent.ts +28 -60
- package/dist/templates/roadside-assistance-agent/call.ts +16 -22
- package/dist/templates/roadside-assistance-agent/shared.ts +24 -54
- package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +29 -37
- package/dist/templates/roadside-assistance-agent/tools/dispatch_truck.ts +44 -70
- package/dist/templates/roadside-assistance-agent/tools/job_status.ts +16 -24
- package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +39 -51
- package/dist/templates/roadside-assistance-agent/tools/report_location.ts +34 -33
- package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +18 -39
- package/dist/templates/roadside-assistance-agent/yard.test.ts +22 -19
- package/dist/templates/roadside-assistance-agent/yard.ts +3 -3
- package/dist/templates/spoken-summary-workflow/agent.eval.test.ts +38 -40
- package/dist/templates/spoken-summary-workflow/agent.test.ts +129 -279
- package/dist/templates/spoken-summary-workflow/agent.ts +15 -40
- package/dist/templates/spoken-summary-workflow/client.tsx +13 -25
- package/dist/templates/spoken-summary-workflow/workflows/summarize.ts +52 -92
- package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +31 -74
- package/dist/templates/tabletop-rpg-agent/agent.test.ts +756 -774
- package/dist/templates/tabletop-rpg-agent/agent.ts +9 -46
- package/dist/templates/tabletop-rpg-agent/client.tsx +13 -21
- package/dist/templates/tabletop-rpg-agent/shared.ts +40 -99
- package/dist/templates/tabletop-rpg-agent/tools/action_roll.ts +67 -83
- package/dist/templates/tabletop-rpg-agent/tools/burn_momentum.ts +65 -88
- package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +8 -27
- package/dist/templates/tabletop-rpg-agent/tools/setup_character.ts +18 -36
- package/dist/templates/tabletop-rpg-agent/tools/update_state.ts +101 -111
- package/dist/templates/technical-support-agent/agent.eval.test.ts +31 -72
- package/dist/templates/technical-support-agent/agent.test.ts +231 -260
- package/dist/templates/technical-support-agent/agent.ts +4 -10
- package/dist/templates/technical-support-agent/client.tsx +4 -18
- package/dist/templates/technical-support-agent/shared.ts +15 -25
- package/dist/templates/technical-support-agent/tools/answer_question.ts +46 -56
- package/dist/templates/technical-support-agent/tools/list_topics.ts +1 -0
- package/dist/templates/technical-support-agent/tools/log_ticket.ts +8 -5
- package/dist/templates/text-adventure-agent/agent.eval.test.ts +37 -126
- package/dist/templates/text-adventure-agent/agent.test.ts +197 -368
- package/dist/templates/text-adventure-agent/agent.ts +15 -65
- package/dist/templates/text-adventure-agent/client.tsx +38 -98
- package/dist/templates/text-adventure-agent/shared.ts +31 -143
- package/dist/templates/text-adventure-agent/tools/game_state_drop.ts +6 -12
- package/dist/templates/text-adventure-agent/tools/game_state_get.ts +4 -11
- package/dist/templates/text-adventure-agent/tools/game_state_move.ts +0 -2
- package/dist/templates/text-adventure-agent/tools/game_state_restart.ts +1 -3
- package/dist/templates/text-adventure-agent/tools/game_state_score.ts +5 -7
- package/dist/templates/topic-briefing-agent/agent.eval.test.ts +12 -50
- package/dist/templates/topic-briefing-agent/agent.test.ts +478 -476
- package/dist/templates/topic-briefing-agent/agent.ts +3 -3
- package/dist/templates/topic-briefing-agent/shared.ts +11 -16
- package/dist/templates/topic-briefing-agent/slack.ts +12 -4
- package/dist/templates/topic-briefing-agent/tools/briefing_so_far.ts +10 -17
- package/dist/templates/topic-briefing-agent/tools/research_topic.ts +21 -24
- package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +13 -14
- package/dist/templates/topic-briefing-agent/tools/verify_claim.ts +16 -13
- package/dist/templates/transcription-workflow/agent.test.ts +114 -259
- package/dist/templates/transcription-workflow/agent.ts +6 -9
- package/dist/templates/transcription-workflow/client.tsx +100 -258
- package/dist/templates/transcription-workflow/recover.test.ts +6 -136
- package/dist/templates/transcription-workflow/recover.ts +14 -97
- package/dist/templates/transcription-workflow/run-panel.tsx +71 -8
- package/dist/templates/transcription-workflow/workflows/batch.ts +28 -159
- package/dist/templates/transcription-workflow/workflows/normalize.ts +50 -86
- package/dist/templates/transcription-workflow/workflows/stream.ts +2 -2
- package/dist/templates/transcription-workflow/workflows/transcribe.ts +16 -23
- package/dist/templates/travel-concierge-agent/agent.eval.test.ts +7 -25
- package/dist/templates/travel-concierge-agent/agent.test.ts +505 -517
- package/dist/templates/travel-concierge-agent/agent.ts +22 -46
- package/dist/templates/travel-concierge-agent/client.tsx +1 -22
- package/dist/templates/travel-concierge-agent/routing.ts +29 -31
- package/dist/templates/travel-concierge-agent/shared.ts +63 -152
- package/dist/templates/travel-concierge-agent/tools/book_car_rental.ts +8 -9
- package/dist/templates/travel-concierge-agent/tools/book_excursion.ts +8 -8
- package/dist/templates/travel-concierge-agent/tools/book_hotel.ts +9 -6
- package/dist/templates/travel-concierge-agent/tools/cancel_ticket.ts +10 -10
- package/dist/templates/travel-concierge-agent/tools/search_car_rentals.ts +3 -2
- package/dist/templates/travel-concierge-agent/tools/search_excursions.ts +3 -2
- package/dist/templates/travel-concierge-agent/tools/search_flights.ts +4 -3
- package/dist/templates/travel-concierge-agent/tools/search_hotels.ts +3 -2
- package/dist/templates/travel-concierge-agent/tools/update_ticket.ts +13 -8
- package/dist/templates/web-research-agent/agent.test.ts +19 -30
- package/dist/templates/web-research-agent/agent.ts +3 -4
- package/dist/templates/word-game-agent/agent.eval.test.ts +47 -67
- package/dist/templates/word-game-agent/agent.test.ts +369 -382
- package/dist/templates/word-game-agent/agent.ts +2 -5
- package/dist/templates/word-game-agent/client.tsx +1 -8
- package/dist/templates/word-game-agent/game.ts +15 -27
- package/dist/templates/word-game-agent/shared.ts +36 -20
- package/dist/templates/word-game-agent/tools/final_score.ts +14 -13
- package/dist/templates/word-game-agent/tools/relay_description.ts +90 -66
- package/dist/templates/word-game-agent/tools/repeat_word.ts +11 -10
- package/dist/templates/word-game-agent/tools/skip_word.ts +17 -21
- package/dist/templates/word-game-agent/tools/start_game.ts +26 -30
- package/dist/{test-XufelYGW.mjs → test-CW5cw5fy.mjs} +3 -4
- package/dist/typecheck.mjs +1 -1
- package/dist/worker-bundler-D8uCzpYP.mjs +335 -0
- package/dist/worker-bundler.d.ts +39 -0
- package/dist/worker-bundler.mjs +2 -155
- package/dist/{workflow-CDUlTD5B.mjs → workflow-5gOZMB2M.mjs} +66 -19
- package/package.json +4 -4
- package/dist/_output-DBP9Op_d.mjs +0 -120
- package/dist/_studio-B5m4jBTD.mjs +0 -256
- package/dist/_ui-Coe0zwmm.mjs +0 -102
- package/dist/_utils-BVLdBvdT.mjs +0 -186
- package/dist/delete-DwXCHzTl.mjs +0 -55
- package/dist/templates/document-redline-workflow/form.ts +0 -73
- package/dist/templates/emergency-dispatch-agent/events.ts +0 -48
- package/dist/templates/hotel-reception-agent/events.ts +0 -80
- package/dist/templates/meeting-recap-agent/shared.ts +0 -44
- package/dist/templates/meeting-recap-agent/tools/cancel_recap.ts +0 -25
- package/dist/templates/meeting-recap-agent/tools/recap_progress.ts +0 -24
- package/dist/templates/meeting-recap-agent/tools/recap_status.ts +0 -45
- package/dist/templates/meeting-recap-agent/workflows/tokens.ts +0 -47
- package/dist/templates/outbound-call-agent/call-params.ts +0 -109
- package/dist/templates/outbound-call-agent/live-calls.ts +0 -80
- package/dist/templates/outbound-call-agent/workflows/tokens.ts +0 -16
- package/dist/templates/research-handoff-agent/shared.ts +0 -41
- package/dist/templates/research-handoff-agent/tools/research_progress.ts +0 -23
- package/dist/templates/research-handoff-agent/tools/research_status.ts +0 -73
- package/dist/templates/research-handoff-agent/workflows/review.ts +0 -43
- package/dist/templates/roadside-assistance-agent/events.ts +0 -92
- package/dist/templates/spoken-summary-workflow/workflows/transcribe.ts +0 -137
- package/dist/templates/transcription-workflow/total-latency.tsx +0 -170
- package/dist/templates/travel-concierge-agent/call-events.ts +0 -80
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aai start --workers` — serve one built agent from several processes.
|
|
3
|
+
*
|
|
4
|
+
* A single `aai start` process runs every session on one JavaScript thread, so
|
|
5
|
+
* it tops out at one core no matter how many the machine has. Measured with
|
|
6
|
+
* the real provider adapters against a local fake, one process held ~1000
|
|
7
|
+
* concurrent browser sessions with flat latency and fell over by ~1500 while
|
|
8
|
+
* the rest of the machine idled. The ceiling is the event loop, so the fix is
|
|
9
|
+
* more event loops — one per worker, each owning a SLOT.
|
|
10
|
+
*
|
|
11
|
+
* ## The shape
|
|
12
|
+
*
|
|
13
|
+
* The primary owns the public port and routes every request by affinity
|
|
14
|
+
* (`_start-affinity.ts`, `_start-router.ts`): a WebSocket upgrade is handed to
|
|
15
|
+
* its worker as a raw socket, so audio never passes through the primary again;
|
|
16
|
+
* plain HTTP is proxied per request to the worker's private loopback port.
|
|
17
|
+
* A worker never binds the public port. Because a client's session, inbox and
|
|
18
|
+
* route calls all reach its own worker, nothing about a live call has to be
|
|
19
|
+
* shared — so more than one worker does NOT need a database. A `DATABASE_URL`
|
|
20
|
+
* adds what memory cannot: a session that survives its worker crashing, and
|
|
21
|
+
* durable workflow runs (a worker refuses workflows without one — `_start-run.ts`).
|
|
22
|
+
*
|
|
23
|
+
* The one cross-worker path is an `/inbox` notice from a workflow step, which
|
|
24
|
+
* runs wherever the engine runs it: the step's worker forwards it here and this
|
|
25
|
+
* supervisor hands it to the worker owning the client (`inbox/relay.ts` in the
|
|
26
|
+
* runtime).
|
|
27
|
+
*
|
|
28
|
+
* ## Supervision
|
|
29
|
+
*
|
|
30
|
+
* The primary owns no sessions and never imports the agent. A worker reports
|
|
31
|
+
* LISTENING over IPC — that report, not a timer, is what "booted" means. A
|
|
32
|
+
* worker that dies after reporting is respawned into the SAME slot, so every
|
|
33
|
+
* key keeps routing where it did. One that dies before reporting failed to
|
|
34
|
+
* boot, which a respawn would only repeat, so the primary stops every worker
|
|
35
|
+
* and fails the command instead of looping.
|
|
36
|
+
*/
|
|
37
|
+
import type { Cluster } from "node:cluster";
|
|
38
|
+
import type { Socket } from "node:net";
|
|
39
|
+
import type { ClientNotifier } from "@alexkroman1/aai/host-internal";
|
|
40
|
+
/** Process-env override for the worker count, for a container that cannot pass flags. */
|
|
41
|
+
export declare const WORKERS_ENV = "AAI_WORKERS";
|
|
42
|
+
/** The env a worker learns its place from. Read only under `cluster.isWorker`. */
|
|
43
|
+
export declare const SLOT_ENV = "AAI_START_SLOT";
|
|
44
|
+
export declare const SLOTS_ENV = "AAI_START_SLOTS";
|
|
45
|
+
/**
|
|
46
|
+
* Parse a worker count: a positive integer, or `auto` for one per available CPU.
|
|
47
|
+
*
|
|
48
|
+
* @throws when the value is neither — named, so the CLI error says which input.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseWorkers(value: string, source: string, cpus?: () => number): number;
|
|
51
|
+
/** Env overrides for the drain timeout (seconds) and the per-worker call cap. */
|
|
52
|
+
export declare const DRAIN_TIMEOUT_ENV = "AAI_DRAIN_TIMEOUT";
|
|
53
|
+
export declare const MAX_CALLS_ENV = "AAI_MAX_CALLS_PER_WORKER";
|
|
54
|
+
/** How long a drain lets calls finish by default: most calls end well inside it. */
|
|
55
|
+
export declare const DEFAULT_DRAIN_TIMEOUT_S = 300;
|
|
56
|
+
/**
|
|
57
|
+
* A positive integer from a flag, else its env var, else `fallback` — named on
|
|
58
|
+
* error, with its `unit` when it has one: `--drain-timeout 5m` is the natural
|
|
59
|
+
* thing to type, and "must be a positive integer" alone does not say seconds.
|
|
60
|
+
*/
|
|
61
|
+
export declare function resolvePositiveInt(flag: string | undefined, flagName: string, envName: string, fallback: number, env?: Readonly<Record<string, string | undefined>>, unit?: string): number;
|
|
62
|
+
/** The worker count: the flag, then {@link WORKERS_ENV}, then 1. */
|
|
63
|
+
export declare function resolveWorkers(flag: string | undefined, env?: Readonly<Record<string, string | undefined>>, cpus?: () => number): number;
|
|
64
|
+
/** An inbox notice in transit: everything `notifyClientHere` takes but the signal. */
|
|
65
|
+
export interface RelayedNotify {
|
|
66
|
+
op: "notify";
|
|
67
|
+
clientId: string;
|
|
68
|
+
notice: Parameters<ClientNotifier>[1];
|
|
69
|
+
ackTimeoutMs: number;
|
|
70
|
+
}
|
|
71
|
+
/** The outcome of a relayed notice — the inbox's own vocabulary. */
|
|
72
|
+
export type RelayOutcome = Awaited<ReturnType<ClientNotifier>>;
|
|
73
|
+
/** How often the primary pings each listening worker. */
|
|
74
|
+
export declare const PING_INTERVAL_MS = 2500;
|
|
75
|
+
/**
|
|
76
|
+
* A worker that has not answered a ping for this long has a wedged event loop:
|
|
77
|
+
* it is killed and respawned into its slot.
|
|
78
|
+
*
|
|
79
|
+
* Shorter than LiveKit's 60 s on purpose. Theirs guards ONE call per process;
|
|
80
|
+
* a worker here holds hundreds, and a loop blocked for this long has already
|
|
81
|
+
* stopped every one of them — their audio stalled at the first missed frame —
|
|
82
|
+
* so waiting longer only lengthens the outage before the respawn.
|
|
83
|
+
*/
|
|
84
|
+
export declare const LIVENESS_TIMEOUT_MS = 15000;
|
|
85
|
+
/**
|
|
86
|
+
* How long a worker may take to start listening before it is killed as hung —
|
|
87
|
+
* a boot stuck on a database that never answers (`ensure*Schema` behind the
|
|
88
|
+
* schema lock, a silently partitioned Postgres) would otherwise hold the
|
|
89
|
+
* server at "starting", or a rolling restart open, forever. Generous: an
|
|
90
|
+
* agent's import and its schema DDL are seconds, not minutes.
|
|
91
|
+
*/
|
|
92
|
+
export declare const BOOT_TIMEOUT_MS = 120000;
|
|
93
|
+
/** How long a worker told to stop (or done draining) gets before it is SIGKILLed. */
|
|
94
|
+
export declare const STOP_GRACE_MS = 10000;
|
|
95
|
+
/** A pong slower than this is logged (LiveKit's `highPingThreshold`), at most once per {@link SLOW_PONG_LOG_EVERY_MS} per worker. */
|
|
96
|
+
export declare const SLOW_PONG_MS = 500;
|
|
97
|
+
export declare const SLOW_PONG_LOG_EVERY_MS = 30000;
|
|
98
|
+
/** Worker → primary. */
|
|
99
|
+
export type WorkerMessage = {
|
|
100
|
+
type: "aai-start:listening";
|
|
101
|
+
name: string;
|
|
102
|
+
port: number;
|
|
103
|
+
}
|
|
104
|
+
/** `received`: call sockets handed to it so far — the primary's in-transit count is what it sent minus this. */
|
|
105
|
+
| {
|
|
106
|
+
type: "aai-start:pong";
|
|
107
|
+
calls: number;
|
|
108
|
+
elu: number;
|
|
109
|
+
received: number;
|
|
110
|
+
} | {
|
|
111
|
+
type: "aai-start:fatal";
|
|
112
|
+
message: string;
|
|
113
|
+
} | {
|
|
114
|
+
type: "aai-start:relay";
|
|
115
|
+
id: number;
|
|
116
|
+
target: number;
|
|
117
|
+
payload: RelayedNotify;
|
|
118
|
+
} | {
|
|
119
|
+
type: "aai-start:relay-cancel";
|
|
120
|
+
id: number;
|
|
121
|
+
target: number;
|
|
122
|
+
} | {
|
|
123
|
+
type: "aai-start:relay-result";
|
|
124
|
+
id: number;
|
|
125
|
+
outcome: RelayOutcome;
|
|
126
|
+
};
|
|
127
|
+
/** Primary → worker. */
|
|
128
|
+
export type PrimaryMessage =
|
|
129
|
+
/** `call`: the primary's classification (`isCallPath`), so the worker counts it for the drain. */
|
|
130
|
+
{
|
|
131
|
+
type: "aai-start:upgrade";
|
|
132
|
+
bytes: Uint8Array;
|
|
133
|
+
call: boolean;
|
|
134
|
+
} | {
|
|
135
|
+
type: "aai-start:ping";
|
|
136
|
+
} | {
|
|
137
|
+
type: "aai-start:drain";
|
|
138
|
+
timeoutMs: number;
|
|
139
|
+
} | {
|
|
140
|
+
type: "aai-start:stop";
|
|
141
|
+
}
|
|
142
|
+
/** `id` is the PRIMARY's, unique across the server — see `relays` in the supervisor. */
|
|
143
|
+
| {
|
|
144
|
+
type: "aai-start:relay";
|
|
145
|
+
id: number;
|
|
146
|
+
payload: RelayedNotify;
|
|
147
|
+
} | {
|
|
148
|
+
type: "aai-start:relay-cancel";
|
|
149
|
+
id: number;
|
|
150
|
+
} | {
|
|
151
|
+
type: "aai-start:relay-result";
|
|
152
|
+
id: number;
|
|
153
|
+
outcome: RelayOutcome;
|
|
154
|
+
};
|
|
155
|
+
/** One of this protocol's messages (every type is `aai-start:`-prefixed) — either direction. */
|
|
156
|
+
export declare function isProtocolMessage<M extends WorkerMessage | PrimaryMessage>(message: unknown): message is M;
|
|
157
|
+
/** One worker process, as the supervisor and router see it. */
|
|
158
|
+
export interface WorkerLike {
|
|
159
|
+
readonly pid: number | undefined;
|
|
160
|
+
kill(signal?: NodeJS.Signals): void;
|
|
161
|
+
/** `false` when the worker is gone and nothing was sent (its socket, if any, is still the caller's). */
|
|
162
|
+
send(message: PrimaryMessage, socket?: Socket): boolean;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Is this process a `--workers` worker? The slot only our fork sets, plus the
|
|
166
|
+
* IPC channel `cluster.fork` opens — without importing `node:cluster`.
|
|
167
|
+
*
|
|
168
|
+
* Not `NODE_UNIQUE_ID`, though `cluster.fork` sets it: Node's bootstrap
|
|
169
|
+
* deletes it from a worker's `process.env` before any user code runs.
|
|
170
|
+
*/
|
|
171
|
+
export declare function isStartWorker(env?: NodeJS.ProcessEnv, hasIpc?: boolean): boolean;
|
|
172
|
+
/** `node:cluster`, loaded on demand — see the import note at the top. */
|
|
173
|
+
export declare function loadCluster(): Promise<Cluster>;
|
|
174
|
+
/** The slice of `node:cluster` the supervisor drives — a seam, so the unit tier forks nothing. */
|
|
175
|
+
export interface ClusterLike {
|
|
176
|
+
fork(env: Record<string, string>): WorkerLike;
|
|
177
|
+
onExit(listener: (worker: WorkerLike, code: number | null, signal: string | null) => void): void;
|
|
178
|
+
onMessage(listener: (worker: WorkerLike, message: unknown) => void): void;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* A worker's stdio: stdin and stderr inherited, stdout pointed at the
|
|
182
|
+
* primary's STDERR. The primary owns stdout's one `--json` result line, and a
|
|
183
|
+
* worker runs this same command, so anything it prints there would be a
|
|
184
|
+
* second one.
|
|
185
|
+
*/
|
|
186
|
+
export declare const WORKER_STDIO: readonly ["inherit", 2, "inherit", "ipc"];
|
|
187
|
+
/**
|
|
188
|
+
* `node:cluster` behind {@link ClusterLike}. Structured-clone IPC, because a
|
|
189
|
+
* relayed notice can carry audio (`Uint8Array`), which JSON would mangle.
|
|
190
|
+
*/
|
|
191
|
+
export declare function nodeCluster(cluster: Cluster): ClusterLike;
|
|
192
|
+
/** A slot's current worker: where its new traffic goes. */
|
|
193
|
+
export interface ReadyWorker {
|
|
194
|
+
worker: WorkerLike;
|
|
195
|
+
/** Its private loopback port, the target for proxied HTTP. */
|
|
196
|
+
port: number;
|
|
197
|
+
}
|
|
198
|
+
/** One worker as `/workers` reports it. */
|
|
199
|
+
export interface WorkerStatus {
|
|
200
|
+
slot: number;
|
|
201
|
+
pid: number | undefined;
|
|
202
|
+
state: "starting" | "serving" | "draining";
|
|
203
|
+
/** Live calls, as last reported plus admissions since. */
|
|
204
|
+
calls: number;
|
|
205
|
+
/** Event-loop utilization over the last ping interval, 0–1. */
|
|
206
|
+
elu: number;
|
|
207
|
+
}
|
|
208
|
+
/** Whether a call may go to a slot's worker now — the router's 503 reason when not. */
|
|
209
|
+
export type Admission = "ok" | "draining" | "full";
|
|
210
|
+
/** The running supervisor. */
|
|
211
|
+
export interface SupervisedWorkers {
|
|
212
|
+
/**
|
|
213
|
+
* Every slot is listening: the agent's name, from the first to report.
|
|
214
|
+
* REJECTS — once every worker has exited — when one failed to boot.
|
|
215
|
+
*/
|
|
216
|
+
ready: Promise<{
|
|
217
|
+
name: string;
|
|
218
|
+
}>;
|
|
219
|
+
/** Every worker has exited after a drain or stop: 0, or 1 if any exited non-zero. */
|
|
220
|
+
exited: Promise<number>;
|
|
221
|
+
/** The slot's current worker, or `undefined` while it is (re)starting. */
|
|
222
|
+
target(slot: number): ReadyWorker | undefined;
|
|
223
|
+
/** Whether new calls are being placed at all (`false` once draining or stopping). */
|
|
224
|
+
accepting(): boolean;
|
|
225
|
+
/**
|
|
226
|
+
* Admit a call socket to the slot's current worker, counting it until the
|
|
227
|
+
* worker's next load report (LiveKit's reserved slots) — a reconnect is a new
|
|
228
|
+
* live socket too. The cap covers EVERY call; only the drain lets a reconnect
|
|
229
|
+
* through, so live calls survive a deploy. `resume` is the client's CLAIM to
|
|
230
|
+
* continue a call (`isResume`: any well-formed id), so it never buys past the cap.
|
|
231
|
+
*/
|
|
232
|
+
admit(slot: number, resume: boolean): Admission;
|
|
233
|
+
/** Every live worker, for `/workers`. */
|
|
234
|
+
status(): WorkerStatus[];
|
|
235
|
+
/** Stop placing calls; each worker finishes its calls (up to `timeoutMs`) and exits. */
|
|
236
|
+
drain(timeoutMs: number): void;
|
|
237
|
+
/** Stop now: every worker closes at once; SIGKILL after {@link STOP_GRACE_MS}. Idempotent. */
|
|
238
|
+
stop(): void;
|
|
239
|
+
/**
|
|
240
|
+
* Replace every worker one slot at a time without dropping a call: start the
|
|
241
|
+
* replacement, move the slot's new traffic to it once it listens, and drain
|
|
242
|
+
* the old one. Ignored while one is already running or the server is stopping.
|
|
243
|
+
*/
|
|
244
|
+
roll(drainTimeoutMs: number): void;
|
|
245
|
+
}
|
|
246
|
+
/** Timer seams — real ones unless a spec says otherwise. */
|
|
247
|
+
interface Timers {
|
|
248
|
+
now: () => number;
|
|
249
|
+
every: (ms: number, tick: () => void) => () => void;
|
|
250
|
+
after: (ms: number, fire: () => void) => void;
|
|
251
|
+
}
|
|
252
|
+
/** Fork one worker per slot and keep each slot served — see the module doc. */
|
|
253
|
+
export declare function superviseWorkers(opts: {
|
|
254
|
+
slots: number;
|
|
255
|
+
cluster: ClusterLike;
|
|
256
|
+
/** Log one line; the supervisor never throws for a worker's sake. */
|
|
257
|
+
log: (message: string) => void;
|
|
258
|
+
/** Calls a worker may hold before `admit` answers `full`. Default unlimited. */
|
|
259
|
+
maxCallsPerWorker?: number | undefined;
|
|
260
|
+
timers?: Partial<Timers>;
|
|
261
|
+
}): SupervisedWorkers;
|
|
262
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { o as resolveDeployTarget } from "./_agent-BN21AHsJ.mjs";
|
|
3
|
+
import { a as apiRequest, s as checkedResponse, u as isStringArray } from "./_api-client-Uljj0CQi.mjs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { isRecord } from "@alexkroman1/aai/utils";
|
|
6
|
+
import { MAX_SLUG_LENGTH, PREVIEW_SLUG_SUFFIX, VALID_SLUG_RE } from "@alexkroman1/aai/internal";
|
|
7
|
+
import { isLocalOnlyFile, snapshotWorkspaceFiles } from "@alexkroman1/aai/workspace-files";
|
|
8
|
+
import { slugifyName } from "@alexkroman1/aai/slugify";
|
|
9
|
+
//#region src/_studio.ts
|
|
10
|
+
/**
|
|
11
|
+
* Internals of the studio-workspace commands (`aai list/pull/push/publish`):
|
|
12
|
+
* the local source-file walk and the thin clients for the platform's
|
|
13
|
+
* `/studio/projects` routes. The workspace is the single source of truth —
|
|
14
|
+
* these helpers only move files between a local directory and the project's
|
|
15
|
+
* workspace row; production deploys happen exclusively through the studio's
|
|
16
|
+
* Publish route (which runs the deploy machinery in the project's sandbox).
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Snapshot the local project into a workspace file map.
|
|
20
|
+
*
|
|
21
|
+
* The walk, the caps, the skip rules and the strict UTF-8 decode all come
|
|
22
|
+
* from the SDK (`@alexkroman1/aai/workspace-files`), which is also what the
|
|
23
|
+
* guest's end-of-turn sync uses — the two write the same map from opposite
|
|
24
|
+
* ends, and a disagreement between them is not an error but a file silently
|
|
25
|
+
* dropped here and resurrected there.
|
|
26
|
+
*
|
|
27
|
+
* `isLocalOnlyFile` is the one rule this side adds: `.env` rides the secret
|
|
28
|
+
* routes and lockfiles are install output, so neither belongs in a row.
|
|
29
|
+
*/
|
|
30
|
+
function collectSourceFiles(dir) {
|
|
31
|
+
return snapshotWorkspaceFiles(dir, {
|
|
32
|
+
subject: "Project",
|
|
33
|
+
skipFile: isLocalOnlyFile
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A studio project name derived from a directory name, or null if unusable.
|
|
38
|
+
*
|
|
39
|
+
* The normalization is the platform's own (`slugifyName`), not a local
|
|
40
|
+
* regex. This used to strip `[^a-z0-9-_]` by hand, which differs from the
|
|
41
|
+
* studio's slugifier on exactly the names people give agents: `Café
|
|
42
|
+
* Ordering` reduced to `caf-ordering` here and `cafe-ordering` there, so the
|
|
43
|
+
* same directory produced a different project depending on whether it was
|
|
44
|
+
* created by `aai push` or by typing the name into the studio.
|
|
45
|
+
*
|
|
46
|
+
* A `-preview` suffix is deliberately unusable. Publishing a project deploys
|
|
47
|
+
* it under the project's own name, so a `*-preview` project would claim a
|
|
48
|
+
* slug the studio's orphan-preview sweep reaps hourly — deleting the agent,
|
|
49
|
+
* its app-database schema, and its secrets on a schedule the user never
|
|
50
|
+
* asked for. Refusing the name is recoverable (rename the directory); losing
|
|
51
|
+
* a published agent to the reaper is not.
|
|
52
|
+
*/
|
|
53
|
+
function projectNameFromDir(dir) {
|
|
54
|
+
const name = slugifyName(path.basename(dir), MAX_SLUG_LENGTH);
|
|
55
|
+
return isUsableProjectName(name) ? name : null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The rule {@link projectNameFromDir} applies, for a name that did NOT come
|
|
59
|
+
* from a directory: `studioProject` (or an older `slug`) read out of
|
|
60
|
+
* `.aai/project.json`. That file is in the working tree, i.e. it arrives with
|
|
61
|
+
* a cloned repo, and the name it holds picks which studio project a push
|
|
62
|
+
* overwrites — so it gets the slug grammar and the `-preview` refusal too.
|
|
63
|
+
*/
|
|
64
|
+
function isUsableProjectName(name) {
|
|
65
|
+
return !name.endsWith(PREVIEW_SLUG_SUFFIX) && isSlugShaped(name);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Slug grammar alone — what a slug the SERVER hands back must satisfy before
|
|
69
|
+
* it is written into `.aai/project.json`. A preview slug is legitimate there
|
|
70
|
+
* (it names an agent, not a project), so this is not {@link isUsableProjectName}.
|
|
71
|
+
*/
|
|
72
|
+
function isSlugShaped(value) {
|
|
73
|
+
return typeof value === "string" && VALID_SLUG_RE.test(value);
|
|
74
|
+
}
|
|
75
|
+
/** The shareable studio URL for a project — what every command prints. */
|
|
76
|
+
function studioProjectUrl(serverUrl, project) {
|
|
77
|
+
return `${serverUrl}/studio/chat/${project}`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The `/studio/projects/:project` base every project-scoped route hangs off —
|
|
81
|
+
* the source, the deploy, the secret fan-out, the delete.
|
|
82
|
+
*
|
|
83
|
+
* One definition because of the `encodeURIComponent`: the project name comes
|
|
84
|
+
* from `.aai/project.json` or from a directory name, i.e. from the working
|
|
85
|
+
* tree, and every request built on it carries the user's API key. Six call
|
|
86
|
+
* sites spelled this template out by hand, so "did that one encode?" was a
|
|
87
|
+
* question the reader had to answer six times.
|
|
88
|
+
*/
|
|
89
|
+
function studioProjectApiUrl(serverUrl, project) {
|
|
90
|
+
return `${serverUrl}/studio/projects/${encodeURIComponent(project)}`;
|
|
91
|
+
}
|
|
92
|
+
const REAL_STUDIO_DEPS = {
|
|
93
|
+
resolveDeployTarget,
|
|
94
|
+
apiRequest
|
|
95
|
+
};
|
|
96
|
+
function listStudioProjects(serverUrl, apiKey, request = apiRequest) {
|
|
97
|
+
return request(`${serverUrl}/studio/projects`, {
|
|
98
|
+
apiKey,
|
|
99
|
+
action: "list"
|
|
100
|
+
}).then((res) => checkedResponse(res, (value) => isRecord(value) && isStringArray(value.projects), `the studio project list at ${serverUrl}`).projects);
|
|
101
|
+
}
|
|
102
|
+
/** Fetch a project, or null when it doesn't exist (the push existence probe). */
|
|
103
|
+
function fetchStudioProject(serverUrl, apiKey, project, request = apiRequest) {
|
|
104
|
+
return request(studioProjectApiUrl(serverUrl, project), {
|
|
105
|
+
apiKey,
|
|
106
|
+
action: "pull",
|
|
107
|
+
allow404: true
|
|
108
|
+
}).then((res) => res === null ? null : checkedResponse(res, isStudioProject, `the studio project ${project} at ${serverUrl}`));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A pulled workspace, as the wire must actually carry it. `deployedSlug` is
|
|
112
|
+
* written into `.aai/project.json` and later joined into request URLs, so it
|
|
113
|
+
* must be slug-shaped: a `../../admin` from a hostile or broken server used to
|
|
114
|
+
* be persisted verbatim.
|
|
115
|
+
*/
|
|
116
|
+
function isStudioProject(value) {
|
|
117
|
+
return isRecord(value) && isRecord(value.files) && Object.values(value.files).every((v) => typeof v === "string") && typeof value.sourceHash === "string" && (value.deployedSlug === void 0 || isSlugShaped(value.deployedSlug));
|
|
118
|
+
}
|
|
119
|
+
/** `PUT /studio/projects/:project/source` — the atomic whole-tree push. */
|
|
120
|
+
function pushStudioSource(serverUrl, apiKey, project, body, request = apiRequest) {
|
|
121
|
+
return request(`${studioProjectApiUrl(serverUrl, project)}/source`, {
|
|
122
|
+
apiKey,
|
|
123
|
+
action: "push",
|
|
124
|
+
method: "PUT",
|
|
125
|
+
body,
|
|
126
|
+
hints: { 409: "The studio has newer changes. Run `aai pull` to fetch them, or `aai push --force` to overwrite." }
|
|
127
|
+
}).then((res) => checkedResponse(res, (value) => isRecord(value) && typeof value.sourceHash === "string" && typeof value.created === "boolean", `the studio push route at ${serverUrl}`));
|
|
128
|
+
}
|
|
129
|
+
/** `POST /studio/projects/:project/deploy` — Publish, in the project's sandbox. */
|
|
130
|
+
function publishStudioProject(serverUrl, apiKey, project, opts = {}, request = apiRequest) {
|
|
131
|
+
return request(`${studioProjectApiUrl(serverUrl, project)}/deploy`, {
|
|
132
|
+
apiKey,
|
|
133
|
+
action: "publish",
|
|
134
|
+
method: "POST",
|
|
135
|
+
body: { skipTypecheck: opts.skipTypecheck === true },
|
|
136
|
+
retry: 0
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { isUsableProjectName as a, publishStudioProject as c, studioProjectUrl as d, isSlugShaped as i, pushStudioSource as l, collectSourceFiles as n, listStudioProjects as o, fetchStudioProject as r, projectNameFromDir as s, REAL_STUDIO_DEPS as t, studioProjectApiUrl as u };
|
package/dist/_studio.d.ts
CHANGED
|
@@ -40,6 +40,20 @@ export declare function collectSourceFiles(dir: string): Promise<WorkspaceSnapsh
|
|
|
40
40
|
* a published agent to the reaper is not.
|
|
41
41
|
*/
|
|
42
42
|
export declare function projectNameFromDir(dir: string): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* The rule {@link projectNameFromDir} applies, for a name that did NOT come
|
|
45
|
+
* from a directory: `studioProject` (or an older `slug`) read out of
|
|
46
|
+
* `.aai/project.json`. That file is in the working tree, i.e. it arrives with
|
|
47
|
+
* a cloned repo, and the name it holds picks which studio project a push
|
|
48
|
+
* overwrites — so it gets the slug grammar and the `-preview` refusal too.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isUsableProjectName(name: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Slug grammar alone — what a slug the SERVER hands back must satisfy before
|
|
53
|
+
* it is written into `.aai/project.json`. A preview slug is legitimate there
|
|
54
|
+
* (it names an agent, not a project), so this is not {@link isUsableProjectName}.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isSlugShaped(value: unknown): value is string;
|
|
43
57
|
/** The shareable studio URL for a project — what every command prints. */
|
|
44
58
|
export declare function studioProjectUrl(serverUrl: string, project: string): string;
|
|
45
59
|
/**
|
package/dist/_target-bundle.d.ts
CHANGED
|
@@ -128,6 +128,10 @@ export declare const PORTABLE_NODE_BUILTINS: readonly string[];
|
|
|
128
128
|
* inside a `try` that tolerates `ERR_UNKNOWN_BUILTIN_MODULE`, and
|
|
129
129
|
* `SqliteCacheStore` requires it lazily in a constructor nothing here calls.
|
|
130
130
|
*
|
|
131
|
+
* `cluster` is `aai start --workers`'s (`loadCluster` in `_start-workers.ts`):
|
|
132
|
+
* a dynamic import reached only when a primary forks, which a `--target` entry
|
|
133
|
+
* never does — Deno and Bun do not implement it.
|
|
134
|
+
*
|
|
131
135
|
* The spec pins the guard rather than trusting this comment: a name here must
|
|
132
136
|
* never appear as a STATIC import in the bundle, which is what would make it a
|
|
133
137
|
* load-time dependency again.
|
|
@@ -1,9 +1,73 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { s as errorMessage } from "./_utils-
|
|
3
|
-
import { t as getMonorepoRoot } from "./_agent-
|
|
2
|
+
import { C as CliError, d as lstatOrNull, s as errorMessage } from "./_utils-ChU85MEg.mjs";
|
|
3
|
+
import { t as getMonorepoRoot } from "./_agent-BN21AHsJ.mjs";
|
|
4
|
+
import { constants } from "node:fs";
|
|
4
5
|
import path from "node:path";
|
|
5
|
-
import fs from "node:fs/promises";
|
|
6
|
-
import { IGNORED_WORKSPACE_DIRS, isLocalOnlyFile, layerScaffoldFiles, readScaffoldFiles,
|
|
6
|
+
import fs, { mkdir, open } from "node:fs/promises";
|
|
7
|
+
import { IGNORED_WORKSPACE_DIRS, isLocalOnlyFile, layerScaffoldFiles, readScaffoldFiles, walkWorkspaceFiles } from "@alexkroman1/aai/workspace-files";
|
|
8
|
+
//#region src/_safe-write.ts
|
|
9
|
+
/**
|
|
10
|
+
* Writing into a directory the CLI does not own — a `--force` pull, an
|
|
11
|
+
* `aai init` into a directory that already has things in it — without
|
|
12
|
+
* writing THROUGH a symlink into somewhere else.
|
|
13
|
+
*
|
|
14
|
+
* Both commands decide where a file goes by joining a relative path onto a
|
|
15
|
+
* target directory, and a lexical containment check (`isPathInside`) cannot
|
|
16
|
+
* see what is on disk: `agent.ts -> ../outside/victim.txt`, a `tools/` that is
|
|
17
|
+
* a link to another tree, or a DANGLING `.gitignore -> ~/x` (an existence
|
|
18
|
+
* probe that reads through it sees ENOENT, and the write that follows creates
|
|
19
|
+
* the link's target) all pass it. So every target is screened with `lstat`,
|
|
20
|
+
* component by component, before anything is written, and the write itself
|
|
21
|
+
* opens with `O_NOFOLLOW` so the last component cannot be swapped for a link
|
|
22
|
+
* in between.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Refuse `rel` under `root` when any EXISTING part of it is a symlink, or
|
|
26
|
+
* when what exists disagrees with the shape the write needs (a file where a
|
|
27
|
+
* parent directory must go, a directory where the file must go).
|
|
28
|
+
*
|
|
29
|
+
* `root` itself is not screened: it is the directory the user named, and a
|
|
30
|
+
* symlinked project directory is an ordinary thing to have. Everything below
|
|
31
|
+
* it is the write's own business. The walk stops at the first component that
|
|
32
|
+
* does not exist — nothing below it can be a link yet.
|
|
33
|
+
*/
|
|
34
|
+
async function refuseUnsafeTarget(root, rel) {
|
|
35
|
+
const segments = rel.split(/[\\/]/).filter((s) => s !== "");
|
|
36
|
+
let current = path.resolve(root);
|
|
37
|
+
for (const [i, segment] of segments.entries()) {
|
|
38
|
+
current = path.join(current, segment);
|
|
39
|
+
const stat = await lstatOrNull(current);
|
|
40
|
+
if (stat === null) return;
|
|
41
|
+
const shown = path.relative(root, current);
|
|
42
|
+
if (stat.isSymbolicLink()) throw new CliError("symlink_in_path", `Refusing to write ${rel}: ${shown} is a symlink, and writing through it would land outside ${root}.`, "Remove the link (or move it aside), or use a fresh directory.");
|
|
43
|
+
const isLast = i === segments.length - 1;
|
|
44
|
+
if (stat.isDirectory() === isLast) throw new CliError("path_conflict", `Refusing to write ${rel}: ${shown} already exists as a ${isLast ? "directory" : "file"}.`, "Move it aside, or use a fresh directory.");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* `O_NOFOLLOW` where the platform has one. Windows does not, and there a
|
|
49
|
+
* symlink needs a privilege a project directory's author rarely holds; the
|
|
50
|
+
* `lstat` screen above still runs.
|
|
51
|
+
*/
|
|
52
|
+
const NOFOLLOW = constants.O_NOFOLLOW ?? 0;
|
|
53
|
+
/**
|
|
54
|
+
* Write `content` at `abs`, creating parents, refusing to follow a symlink at
|
|
55
|
+
* the file itself. `exclusive` refuses an existing file (EEXIST) instead of
|
|
56
|
+
* replacing it; `mode` is the CREATE mode — what a fresh `.env` is born with.
|
|
57
|
+
*
|
|
58
|
+
* Call {@link refuseUnsafeTarget} first: this guards only the last component,
|
|
59
|
+
* because `mkdir -p` and `open` both follow a link in a parent.
|
|
60
|
+
*/
|
|
61
|
+
async function writeFileNoFollow(abs, content, opts = {}) {
|
|
62
|
+
await mkdir(path.dirname(abs), { recursive: true });
|
|
63
|
+
const flags = constants.O_WRONLY | constants.O_CREAT | NOFOLLOW | (opts.exclusive ? constants.O_EXCL : constants.O_TRUNC);
|
|
64
|
+
const handle = await open(abs, flags, opts.mode ?? 438);
|
|
65
|
+
try {
|
|
66
|
+
await handle.writeFile(content, "utf-8");
|
|
67
|
+
} finally {
|
|
68
|
+
await handle.close();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
7
71
|
const REPO_URL = `https://github.com/alexkroman/agent`;
|
|
8
72
|
/**
|
|
9
73
|
* Templates as shipped inside the published tarball, copied into `dist/` by
|
|
@@ -76,9 +140,27 @@ function scaffoldDir() {
|
|
|
76
140
|
* read from the target: whether a project already has a given file is the one
|
|
77
141
|
* thing the rule asks about it, and `package.json`'s content the one thing it
|
|
78
142
|
* merges.
|
|
143
|
+
*
|
|
144
|
+
* Only the paths the rule will WRITE are screened ({@link refuseUnsafeTarget}),
|
|
145
|
+
* after the existence probe: a file the project already has is left alone, so
|
|
146
|
+
* a `CLAUDE.md -> AGENTS.md` link is fine, while a DANGLING one reads as
|
|
147
|
+
* missing, lands in the write set, and is refused rather than written through.
|
|
79
148
|
*/
|
|
80
149
|
async function layerScaffold(targetDir) {
|
|
81
|
-
const
|
|
150
|
+
const writes = await planScaffold(targetDir);
|
|
151
|
+
await Promise.all(Object.entries(writes).map(([rel, content]) => writeFileNoFollow(path.join(targetDir, rel), content)));
|
|
152
|
+
}
|
|
153
|
+
/** Each scaffold directory, read once per process — it cannot change under a run. */
|
|
154
|
+
const scaffoldReads = /* @__PURE__ */ new Map();
|
|
155
|
+
/** What {@link layerScaffold} would write into `targetDir`, every path screened. */
|
|
156
|
+
async function planScaffold(targetDir) {
|
|
157
|
+
const dir = scaffoldDir();
|
|
158
|
+
let read = scaffoldReads.get(dir);
|
|
159
|
+
if (!read) {
|
|
160
|
+
read = readScaffoldFiles(dir);
|
|
161
|
+
scaffoldReads.set(dir, read);
|
|
162
|
+
}
|
|
163
|
+
const scaffold = await read;
|
|
82
164
|
const existing = {};
|
|
83
165
|
await Promise.all([...Object.keys(scaffold), "CLAUDE.md"].map(async (rel) => {
|
|
84
166
|
try {
|
|
@@ -86,7 +168,17 @@ async function layerScaffold(targetDir) {
|
|
|
86
168
|
} catch {}
|
|
87
169
|
}));
|
|
88
170
|
const writes = layerScaffoldFiles(existing, scaffold);
|
|
89
|
-
await Promise.all(Object.
|
|
171
|
+
await Promise.all(Object.keys(writes).map((rel) => refuseUnsafeTarget(targetDir, rel)));
|
|
172
|
+
return writes;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Screen `targetDir` for what {@link layerScaffold} would write, without
|
|
176
|
+
* writing anything — for a caller that writes OTHER files first (`aai pull`,
|
|
177
|
+
* `aai init`) and must refuse before the first of them rather than leave a
|
|
178
|
+
* half-written tree. Its own writes only shrink the set the later layer adds.
|
|
179
|
+
*/
|
|
180
|
+
async function refuseUnsafeScaffoldTargets(targetDir) {
|
|
181
|
+
await planScaffold(targetDir);
|
|
90
182
|
}
|
|
91
183
|
/**
|
|
92
184
|
* `fs.cp` filter for every copy OUT of a template or the scaffold — the runtime
|
|
@@ -123,11 +215,21 @@ function templateCopyFilter(src) {
|
|
|
123
215
|
/**
|
|
124
216
|
* Copy a template into targetDir, merging scaffold files underneath. `root` is
|
|
125
217
|
* the templates root, resolved by {@link resolveTemplatesDir} unless given.
|
|
218
|
+
*
|
|
219
|
+
* `extraTargets` are the paths the CALLER will write afterwards (`aai init`'s
|
|
220
|
+
* `.env` and README): they are screened with the template's and the
|
|
221
|
+
* scaffold's, before the copy, so a symlink or a file/directory clash
|
|
222
|
+
* anywhere in the target is refused while the directory is still untouched.
|
|
223
|
+
* It used to surface midway — a `tools/` symlinked to a directory failed the
|
|
224
|
+
* copy with EISDIR and left a half-scaffolded project behind.
|
|
126
225
|
*/
|
|
127
|
-
async function downloadAndMergeTemplate(template, targetDir, root = resolveTemplatesDir()) {
|
|
226
|
+
async function downloadAndMergeTemplate(template, targetDir, root = resolveTemplatesDir(), extraTargets = []) {
|
|
128
227
|
const templatesDir = path.join(root, "templates");
|
|
129
228
|
const names = await listTemplates(root);
|
|
130
229
|
if (!names.includes(template)) throw new Error(`Unknown template "${template}". Available templates: ${names.join(", ")}`);
|
|
230
|
+
const templateFiles = await walkWorkspaceFiles(path.join(templatesDir, template), { skipFile: isLocalOnlyFile });
|
|
231
|
+
await Promise.all([...templateFiles, ...extraTargets].map((rel) => refuseUnsafeTarget(targetDir, rel)));
|
|
232
|
+
await refuseUnsafeScaffoldTargets(targetDir);
|
|
131
233
|
await fs.cp(path.join(templatesDir, template), targetDir, {
|
|
132
234
|
recursive: true,
|
|
133
235
|
force: true,
|
|
@@ -136,4 +238,4 @@ async function downloadAndMergeTemplate(template, targetDir, root = resolveTempl
|
|
|
136
238
|
await layerScaffold(targetDir);
|
|
137
239
|
}
|
|
138
240
|
//#endregion
|
|
139
|
-
export { REPO_URL, downloadAndMergeTemplate, layerScaffold, listTemplates };
|
|
241
|
+
export { REPO_URL, downloadAndMergeTemplate, layerScaffold, listTemplates, writeFileNoFollow as n, refuseUnsafeScaffoldTargets, refuseUnsafeTarget as t };
|
package/dist/_templates.d.ts
CHANGED
|
@@ -51,8 +51,20 @@ export declare function scaffoldDir(): string;
|
|
|
51
51
|
* read from the target: whether a project already has a given file is the one
|
|
52
52
|
* thing the rule asks about it, and `package.json`'s content the one thing it
|
|
53
53
|
* merges.
|
|
54
|
+
*
|
|
55
|
+
* Only the paths the rule will WRITE are screened ({@link refuseUnsafeTarget}),
|
|
56
|
+
* after the existence probe: a file the project already has is left alone, so
|
|
57
|
+
* a `CLAUDE.md -> AGENTS.md` link is fine, while a DANGLING one reads as
|
|
58
|
+
* missing, lands in the write set, and is refused rather than written through.
|
|
54
59
|
*/
|
|
55
60
|
export declare function layerScaffold(targetDir: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Screen `targetDir` for what {@link layerScaffold} would write, without
|
|
63
|
+
* writing anything — for a caller that writes OTHER files first (`aai pull`,
|
|
64
|
+
* `aai init`) and must refuse before the first of them rather than leave a
|
|
65
|
+
* half-written tree. Its own writes only shrink the set the later layer adds.
|
|
66
|
+
*/
|
|
67
|
+
export declare function refuseUnsafeScaffoldTargets(targetDir: string): Promise<void>;
|
|
56
68
|
/**
|
|
57
69
|
* `fs.cp` filter for every copy OUT of a template or the scaffold — the runtime
|
|
58
70
|
* ones here and the build-time one in `bundle-templates.mjs`.
|
|
@@ -85,5 +97,12 @@ export declare function templateCopyFilter(src: string): boolean;
|
|
|
85
97
|
/**
|
|
86
98
|
* Copy a template into targetDir, merging scaffold files underneath. `root` is
|
|
87
99
|
* the templates root, resolved by {@link resolveTemplatesDir} unless given.
|
|
100
|
+
*
|
|
101
|
+
* `extraTargets` are the paths the CALLER will write afterwards (`aai init`'s
|
|
102
|
+
* `.env` and README): they are screened with the template's and the
|
|
103
|
+
* scaffold's, before the copy, so a symlink or a file/directory clash
|
|
104
|
+
* anywhere in the target is refused while the directory is still untouched.
|
|
105
|
+
* It used to surface midway — a `tools/` symlinked to a directory failed the
|
|
106
|
+
* copy with EISDIR and left a half-scaffolded project behind.
|
|
88
107
|
*/
|
|
89
|
-
export declare function downloadAndMergeTemplate(template: string, targetDir: string, root?: string): Promise<void>;
|
|
108
|
+
export declare function downloadAndMergeTemplate(template: string, targetDir: string, root?: string, extraTargets?: readonly string[]): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { t as defaultUi } from "./_ui-
|
|
2
|
+
import { C as CliError } from "./_utils-ChU85MEg.mjs";
|
|
3
|
+
import { t as defaultUi } from "./_ui-C0RufoYZ.mjs";
|
|
4
4
|
import { typecheckProject } from "./typecheck.mjs";
|
|
5
5
|
//#region src/_typecheck-gate.ts
|
|
6
6
|
/**
|