@alexkroman1/aai-cli 16.1.0 → 18.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 (220) hide show
  1. package/README.md +2 -1
  2. package/dist/{_build-target-ClEEuUuW.mjs → _build-target-C08aM-Es.mjs} +504 -43
  3. package/dist/_build-target.d.ts +98 -19
  4. package/dist/_console-audio.d.ts +17 -0
  5. package/dist/_console-session.d.ts +70 -0
  6. package/dist/_deno-target.d.ts +15 -14
  7. package/dist/_dev-env.d.ts +19 -13
  8. package/dist/{_dev-server-D1wKiA0_.mjs → _dev-server-Dtp4aAlo.mjs} +26 -18
  9. package/dist/_dev-server.d.ts +5 -3
  10. package/dist/_init.d.ts +39 -0
  11. package/dist/_modal-target.d.ts +11 -6
  12. package/dist/_preflight-CnW9QiE7.mjs +116 -0
  13. package/dist/_preflight.d.ts +110 -5
  14. package/dist/_target-bundle.d.ts +112 -0
  15. package/dist/_target-entry.d.ts +81 -0
  16. package/dist/_templates-DXadVNsL.mjs +135 -0
  17. package/dist/_templates.d.ts +11 -34
  18. package/dist/{_vitest-runner-BiAMIir1.mjs → _vitest-runner-CZNGj0ZC.mjs} +21 -16
  19. package/dist/_vitest-runner.d.ts +35 -23
  20. package/dist/{build-O6BT51x_.mjs → build-DrQTSc2R.mjs} +128 -293
  21. package/dist/build.d.ts +34 -4
  22. package/dist/cli.mjs +40 -16
  23. package/dist/console-BsyE3DyB.mjs +422 -0
  24. package/dist/console.d.ts +37 -0
  25. package/dist/{deploy-lldQyJVj.mjs → deploy-B68-x7xM.mjs} +12 -4
  26. package/dist/deploy.d.ts +9 -0
  27. package/dist/{dev-Du8pCWFq.mjs → dev-BGWU2zPP.mjs} +1 -1
  28. package/dist/dev.d.ts +1 -1
  29. package/dist/{eval-Ducmkt1n.mjs → eval-DB07kTxO.mjs} +1 -1
  30. package/dist/init-CbOhyNYe.mjs +559 -0
  31. package/dist/init.d.ts +43 -3
  32. package/dist/scaffold/CLAUDE.md +161 -166
  33. package/dist/scaffold/package.json +6 -6
  34. package/dist/scaffold/vite.config.ts +29 -1
  35. package/dist/start.d.ts +3 -3
  36. package/dist/{studio-It7SRfUN.mjs → studio-BRJsw7lr.mjs} +19 -9
  37. package/dist/templates/applicant-screening-agent/agent.eval.test.ts +20 -6
  38. package/dist/templates/applicant-screening-agent/agent.test.ts +17 -13
  39. package/dist/templates/applicant-screening-agent/agent.ts +28 -0
  40. package/dist/templates/applicant-screening-agent/crews.ts +4 -4
  41. package/dist/templates/applicant-screening-agent/shared.ts +11 -11
  42. package/dist/templates/call-audit-workflow/agent.ts +2 -0
  43. package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
  44. package/dist/templates/code-interpreter-agent/agent.test.ts +2 -2
  45. package/dist/templates/code-interpreter-agent/agent.ts +1 -0
  46. package/dist/templates/coding-agent/agent.eval.test.ts +136 -0
  47. package/dist/templates/coding-agent/agent.test.ts +109 -0
  48. package/dist/templates/coding-agent/agent.ts +45 -0
  49. package/dist/templates/coding-agent/chat.ts +63 -0
  50. package/dist/templates/coding-agent/shared.ts +46 -0
  51. package/dist/templates/coding-agent/system-prompt.md +32 -0
  52. package/dist/templates/coding-agent/tools/bash.ts +6 -0
  53. package/dist/templates/coding-agent/tools/delete_file.ts +6 -0
  54. package/dist/templates/coding-agent/tools/edit_file.ts +6 -0
  55. package/dist/templates/coding-agent/tools/glob.ts +6 -0
  56. package/dist/templates/coding-agent/tools/grep.ts +6 -0
  57. package/dist/templates/coding-agent/tools/list_files.ts +6 -0
  58. package/dist/templates/coding-agent/tools/read_file.ts +6 -0
  59. package/dist/templates/coding-agent/tools/todo_write.ts +6 -0
  60. package/dist/templates/coding-agent/tools/write_file.ts +6 -0
  61. package/dist/templates/custom-pipeline-agent/agent.ts +3 -2
  62. package/dist/templates/custom-pipeline-agent/modes.test.ts +4 -4
  63. package/dist/templates/custom-pipeline-agent/stages.test.ts +75 -83
  64. package/dist/templates/document-redline-workflow/agent.ts +2 -0
  65. package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +1 -1
  66. package/dist/templates/emergency-dispatch-agent/agent.test.ts +103 -0
  67. package/dist/templates/emergency-dispatch-agent/agent.ts +15 -0
  68. package/dist/templates/emergency-dispatch-agent/guardrails.ts +105 -0
  69. package/dist/templates/emergency-dispatch-agent/system-prompt.md +1 -0
  70. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +9 -2
  71. package/dist/templates/entertainment-picks-agent/agent.ts +1 -0
  72. package/dist/templates/entertainment-picks-agent/system-prompt.md +6 -0
  73. package/dist/templates/entertainment-picks-agent/tools/revisit.ts +7 -0
  74. package/dist/templates/executive-inbox-agent/agent.eval.test.ts +84 -23
  75. package/dist/templates/executive-inbox-agent/agent.test.ts +35 -25
  76. package/dist/templates/executive-inbox-agent/agent.ts +1 -0
  77. package/dist/templates/executive-inbox-agent/calendar.test.ts +13 -7
  78. package/dist/templates/executive-inbox-agent/meeting.ts +3 -3
  79. package/dist/templates/executive-inbox-agent/prompts.ts +3 -1
  80. package/dist/templates/executive-inbox-agent/system-prompt.md +3 -3
  81. package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +3 -3
  82. package/dist/templates/executive-inbox-agent/tools/open_email.ts +8 -16
  83. package/dist/templates/front-desk-agent/agent.eval.test.ts +174 -0
  84. package/dist/templates/front-desk-agent/agent.test.ts +150 -0
  85. package/dist/templates/front-desk-agent/agent.ts +22 -0
  86. package/dist/templates/front-desk-agent/shared.ts +234 -0
  87. package/dist/templates/front-desk-agent/system-prompt.md +13 -0
  88. package/dist/templates/front-desk-agent/tools/verify_account.ts +41 -0
  89. package/dist/templates/hotel-reception-agent/agent.eval.test.ts +85 -21
  90. package/dist/templates/hotel-reception-agent/agent.test.ts +3 -3
  91. package/dist/templates/hotel-reception-agent/agent.ts +6 -3
  92. package/dist/templates/hotel-reception-agent/client.tsx +14 -2
  93. package/dist/templates/hotel-reception-agent/concierge.ts +2 -1
  94. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +3 -3
  95. package/dist/templates/hotel-reception-agent/disputes.ts +9 -11
  96. package/dist/templates/hotel-reception-agent/events.ts +2 -1
  97. package/dist/templates/hotel-reception-agent/session.ts +56 -0
  98. package/dist/templates/hotel-reception-agent/shared.ts +20 -21
  99. package/dist/templates/hotel-reception-agent/system-prompt.md +1 -1
  100. package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +2 -1
  101. package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +2 -1
  102. package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +2 -1
  103. package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -1
  104. package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +2 -1
  105. package/dist/templates/hotel-reception-agent/tools/check_restaurant_availability.ts +1 -1
  106. package/dist/templates/hotel-reception-agent/tools/check_room_availability.ts +1 -1
  107. package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
  108. package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +2 -1
  109. package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +2 -1
  110. package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +2 -1
  111. package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +2 -1
  112. package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +2 -1
  113. package/dist/templates/hotel-reception-agent/tools/lookup_guest_history.ts +1 -1
  114. package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +2 -1
  115. package/dist/templates/hotel-reception-agent/tools/lookup_restaurant_reservation.ts +1 -1
  116. package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -1
  117. package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
  118. package/dist/templates/hotel-reception-agent/tools/record_followup.ts +2 -1
  119. package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +2 -1
  120. package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
  121. package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -1
  122. package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +2 -1
  123. package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +2 -1
  124. package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -1
  125. package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +2 -1
  126. package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +2 -1
  127. package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +2 -1
  128. package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
  129. package/dist/templates/hotel-reception-agent/tools/set_stay.ts +2 -1
  130. package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +2 -1
  131. package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +2 -1
  132. package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +2 -1
  133. package/dist/templates/hotel-reception-agent/tools/transfer_call.ts +2 -1
  134. package/dist/templates/hotel-reception-agent/tools/update_card.ts +2 -1
  135. package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +2 -1
  136. package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -1
  137. package/dist/templates/link-digest-workflow/agent.ts +5 -0
  138. package/dist/templates/medication-safety-agent/agent.test.ts +57 -4
  139. package/dist/templates/medication-safety-agent/agent.ts +48 -1
  140. package/dist/templates/meeting-recap-agent/agent.test.ts +2 -2
  141. package/dist/templates/meeting-recap-agent/agent.ts +4 -0
  142. package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +68 -2
  143. package/dist/templates/pizza-ordering-agent/agent.ts +3 -0
  144. package/dist/templates/podcast-digest-workflow/agent.ts +4 -0
  145. package/dist/templates/push-to-talk-agent/agent.eval.test.ts +74 -0
  146. package/dist/templates/push-to-talk-agent/agent.test.ts +61 -0
  147. package/dist/templates/push-to-talk-agent/agent.ts +22 -0
  148. package/dist/templates/push-to-talk-agent/client.tsx +124 -0
  149. package/dist/templates/push-to-talk-agent/shared.ts +34 -0
  150. package/dist/templates/push-to-talk-agent/system-prompt.md +11 -0
  151. package/dist/templates/push-to-talk-agent/tools/list_notes.ts +15 -0
  152. package/dist/templates/push-to-talk-agent/tools/save_note.ts +26 -0
  153. package/dist/templates/quickstart-agent/agent.eval.test.ts +91 -3
  154. package/dist/templates/quickstart-agent/agent.test.ts +22 -0
  155. package/dist/templates/quickstart-agent/agent.ts +18 -2
  156. package/dist/templates/quickstart-agent/system-prompt.md +8 -0
  157. package/dist/templates/quickstart-agent/tools/get_weather.ts +59 -0
  158. package/dist/templates/research-handoff-agent/agent.eval.test.ts +1 -1
  159. package/dist/templates/research-handoff-agent/agent.test.ts +34 -26
  160. package/dist/templates/research-handoff-agent/agent.ts +4 -0
  161. package/dist/templates/research-planner-agent/agent.eval.test.ts +24 -2
  162. package/dist/templates/research-planner-agent/agent.test.ts +26 -16
  163. package/dist/templates/research-planner-agent/agent.ts +3 -0
  164. package/dist/templates/research-planner-agent/system-prompt.md +1 -1
  165. package/dist/templates/retail-orders-agent/agent.eval.test.ts +1 -1
  166. package/dist/templates/retail-orders-agent/agent.ts +32 -3
  167. package/dist/templates/retail-orders-agent/keyterms.ts +154 -0
  168. package/dist/templates/retail-orders-agent/resolve.ts +18 -3
  169. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +124 -5
  170. package/dist/templates/roadside-assistance-agent/agent.test.ts +39 -7
  171. package/dist/templates/roadside-assistance-agent/agent.ts +4 -0
  172. package/dist/templates/roadside-assistance-agent/shared.ts +12 -0
  173. package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +14 -0
  174. package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +11 -0
  175. package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +17 -11
  176. package/dist/templates/roadside-assistance-agent/yard.test.ts +4 -0
  177. package/dist/templates/spoken-summary-workflow/agent.ts +4 -0
  178. package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +6 -0
  179. package/dist/templates/tabletop-rpg-agent/agent.test.ts +125 -1
  180. package/dist/templates/tabletop-rpg-agent/agent.ts +30 -1
  181. package/dist/templates/tabletop-rpg-agent/shared.ts +81 -0
  182. package/dist/templates/tabletop-rpg-agent/system-prompt.md +1 -1
  183. package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +16 -7
  184. package/dist/templates/technical-support-agent/agent.test.ts +29 -23
  185. package/dist/templates/technical-support-agent/agent.ts +5 -1
  186. package/dist/templates/technical-support-agent/knowledge.ts +165 -0
  187. package/dist/templates/technical-support-agent/nodes.ts +3 -2
  188. package/dist/templates/technical-support-agent/procedure.ts +7 -6
  189. package/dist/templates/technical-support-agent/shared.ts +10 -146
  190. package/dist/templates/technical-support-agent/tools/list_topics.ts +2 -1
  191. package/dist/templates/text-adventure-agent/agent.eval.test.ts +39 -6
  192. package/dist/templates/text-adventure-agent/agent.test.ts +79 -1
  193. package/dist/templates/text-adventure-agent/agent.ts +30 -1
  194. package/dist/templates/text-adventure-agent/shared.ts +37 -0
  195. package/dist/templates/text-adventure-agent/system-prompt.md +9 -2
  196. package/dist/templates/topic-briefing-agent/agent.eval.test.ts +18 -4
  197. package/dist/templates/topic-briefing-agent/agent.test.ts +61 -36
  198. package/dist/templates/topic-briefing-agent/agent.ts +4 -1
  199. package/dist/templates/topic-briefing-agent/shared.ts +19 -18
  200. package/dist/templates/topic-briefing-agent/system-prompt.md +13 -8
  201. package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +43 -5
  202. package/dist/templates/transcription-workflow/agent.ts +3 -0
  203. package/dist/templates/travel-concierge-agent/agent.eval.test.ts +9 -7
  204. package/dist/templates/travel-concierge-agent/agent.test.ts +1 -2
  205. package/dist/templates/travel-concierge-agent/agent.ts +4 -0
  206. package/dist/templates/web-research-agent/agent.eval.test.ts +31 -5
  207. package/dist/templates/web-research-agent/agent.test.ts +16 -0
  208. package/dist/templates/web-research-agent/agent.ts +30 -0
  209. package/dist/templates/web-research-agent/system-prompt.md +8 -2
  210. package/dist/templates/word-game-agent/agent.eval.test.ts +79 -18
  211. package/dist/templates/word-game-agent/agent.test.ts +3 -1
  212. package/dist/templates/word-game-agent/agent.ts +20 -0
  213. package/dist/test-CjKPQ9_B.mjs +102 -0
  214. package/dist/test.d.ts +37 -12
  215. package/package.json +5 -5
  216. package/dist/_init-Bp1CjRrU.mjs +0 -199
  217. package/dist/_preflight-CcAR577V.mjs +0 -46
  218. package/dist/_templates-CuP74F8D.mjs +0 -291
  219. package/dist/init-CY4NAXAA.mjs +0 -183
  220. package/dist/test-PHHv0Vj6.mjs +0 -83
@@ -41,17 +41,22 @@ async function executeDeploy(opts) {
41
41
  const { cwd } = opts;
42
42
  const { config: projectConfig, serverUrl, apiKey } = await resolveDeployTarget(cwd, opts.server);
43
43
  await assertTypechecks(cwd, { skip: opts.skipTypecheck });
44
- const preflightModule = import("./_preflight-CcAR577V.mjs");
44
+ const preflightModule = import("./_preflight-CnW9QiE7.mjs");
45
45
  const bundle = await buildAgentBundle(cwd, { minify: true });
46
46
  const slug = projectConfig?.slug ?? projectNameFromDir(cwd) ?? void 0;
47
47
  const uploadEnv = {
48
48
  ASSEMBLYAI_API_KEY: apiKey,
49
49
  ...await resolveServerEnv(cwd)
50
50
  };
51
- const { missingCredentialMessage, missingCredentials } = await preflightModule;
51
+ const { missingCredentialMessage, missingCredentials, missingTelephonySecretWarnings, missingTelephonySecrets, telephonyWebhooks } = await preflightModule;
52
52
  const config = await evalWorkerConfig(bundle.worker);
53
53
  const missing = config ? missingCredentials(config, uploadEnv) : [];
54
- const warnings = [...missing.length > 0 ? [missingCredentialMessage(missing)] : [], ...determinismWarnings(await scanWorkflowDeterminism(cwd))];
54
+ const missingPhone = config ? missingTelephonySecrets(config, uploadEnv) : [];
55
+ const warnings = [
56
+ ...missing.length > 0 ? [missingCredentialMessage(missing)] : [],
57
+ ...missingTelephonySecretWarnings(missingPhone),
58
+ ...determinismWarnings(await scanWorkflowDeterminism(cwd))
59
+ ];
55
60
  for (const warning of warnings) notify("warn", warning);
56
61
  log.step(`Deploying${slug ? ` ${slug}` : ""}…`);
57
62
  const deployed = await runDeploy({
@@ -76,10 +81,13 @@ async function executeDeploy(opts) {
76
81
  })}`);
77
82
  }
78
83
  log.success(`Deployed ${fmtUrl(agentUrl)}`);
84
+ const webhooks = config ? telephonyWebhooks(config, agentUrl) : [];
85
+ for (const { carrier, url } of webhooks) log.info(`${carrier} webhook (paste into the phone number's config): ${fmtUrl(url)}`);
79
86
  return ok({
80
87
  slug: deployed.slug,
81
88
  url: agentUrl,
82
- ...warnings.length > 0 ? { warnings } : {}
89
+ ...warnings.length > 0 ? { warnings } : {},
90
+ ...webhooks.length > 0 ? { webhooks } : {}
83
91
  });
84
92
  }
85
93
  //#endregion
package/dist/deploy.d.ts CHANGED
@@ -3,6 +3,15 @@ type DeployData = {
3
3
  slug: string;
4
4
  url: string;
5
5
  warnings?: string[];
6
+ /**
7
+ * One entry per carrier this agent's `telephony` declares, carrying the
8
+ * webhook URL to configure the phone number with. Omitted when it declares
9
+ * none, so a voice-only deploy's result stays exactly as it was.
10
+ */
11
+ webhooks?: {
12
+ carrier: string;
13
+ url: string;
14
+ }[];
6
15
  };
7
16
  export declare function executeDeploy(opts: {
8
17
  cwd: string;
@@ -13,7 +13,7 @@ import { startTracing } from "@alexkroman1/aai-runtime/tracing";
13
13
  async function executeDev(opts) {
14
14
  const port = parsePort(opts.port);
15
15
  const agentName = path.basename(path.resolve(opts.cwd));
16
- const { startDevServer } = await import("./_dev-server-D1wKiA0_.mjs");
16
+ const { startDevServer } = await import("./_dev-server-Dtp4aAlo.mjs");
17
17
  let cleanup;
18
18
  let shuttingDown = false;
19
19
  const onSignal = () => {
package/dist/dev.d.ts CHANGED
@@ -9,7 +9,7 @@ type DevData = {
9
9
  export declare function executeDev(opts: {
10
10
  cwd: string;
11
11
  port: string;
12
- /** `--watch`. Undefined leaves the decision to `AAI_DEV_WATCH`. */
12
+ /** `--watch`. Undefined leaves it to `AAI_DEV_WATCH`, then to the TTY pair. */
13
13
  watch?: boolean | undefined;
14
14
  }): Promise<CommandResult<DevData>>;
15
15
  export {};
@@ -2,7 +2,7 @@
2
2
  import { a as ok, n as fail } from "./_output-DBP9Op_d.mjs";
3
3
  import { n as log } from "./_ui-DCt4qZrk.mjs";
4
4
  import { i as resolveServerEnv } from "./_server-common-DAcv1nC5.mjs";
5
- import { n as classifyVitestError, r as runVitest } from "./_vitest-runner-BiAMIir1.mjs";
5
+ import { n as classifyVitestError, r as runVitest } from "./_vitest-runner-CZNGj0ZC.mjs";
6
6
  //#region src/eval.ts
7
7
  /**
8
8
  * `aai eval` — run the agent's behaviour evals via vitest.
@@ -0,0 +1,559 @@
1
+ #!/usr/bin/env node
2
+ import { a as ok } from "./_output-DBP9Op_d.mjs";
3
+ import { n as log, s as unwrapCancel } from "./_ui-DCt4qZrk.mjs";
4
+ import { c as fileExists, d as readJson, g as writeJson, i as compareCodeUnits, p as resolveCwd, s as errorMessage, t as AGENT_ENTRY, u as isEexist } from "./_utils-D5JGcjiW.mjs";
5
+ import { r as isDevMode, t as getMonorepoRoot } from "./_agent-BzUeqOdj.mjs";
6
+ import { REPO_URL, downloadAndMergeTemplate, listTemplates } from "./_templates-DXadVNsL.mjs";
7
+ import path from "node:path";
8
+ import { styleText } from "node:util";
9
+ import * as p from "@clack/prompts";
10
+ import fs from "node:fs/promises";
11
+ import { execa } from "execa";
12
+ //#region src/_init.ts
13
+ /**
14
+ * The package managers `aai init` can install a project with, in PREFERENCE
15
+ * order — which is also the order `detectPackageManager` (`init.ts`) probes
16
+ * `PATH` in.
17
+ *
18
+ * pnpm first because it stays the preference where it is present (the scaffold
19
+ * is a pnpm workspace root and its lockfile is pnpm's), but it is no longer the
20
+ * only answer: the install instructions everywhere teach
21
+ * `npm i -g @alexkroman1/aai-cli`, and `init` then installed with pnpm alone —
22
+ * reaching it through `corepack enable`, which does not exist on Node >= 25,
23
+ * i.e. half the range `scaffold/package.json` declares.
24
+ *
25
+ * The list lives here, beside {@link PM_COMMANDS}, so the ORDER and the
26
+ * per-manager command spellings cannot disagree about which managers exist: a
27
+ * fifth entry fails to compile until that record has a row for it.
28
+ */
29
+ const PACKAGE_MANAGERS = [
30
+ "pnpm",
31
+ "npm",
32
+ "bun",
33
+ "yarn"
34
+ ];
35
+ /**
36
+ * The three spellings the generated README needs per manager.
37
+ *
38
+ * Everything a project's README tells an author to type is one of these: the
39
+ * install, a package script, or the local `aai` binary. `run` carries the
40
+ * explicit `run` in every row (`pnpm run dev` as well as `npm run dev`) rather
41
+ * than each manager's shorthand — every one of the four accepts it, so the
42
+ * table stays a table.
43
+ */
44
+ const PM_COMMANDS = {
45
+ pnpm: {
46
+ install: "pnpm install",
47
+ run: "pnpm run",
48
+ exec: "pnpm exec"
49
+ },
50
+ npm: {
51
+ install: "npm install",
52
+ run: "npm run",
53
+ exec: "npx"
54
+ },
55
+ bun: {
56
+ install: "bun install",
57
+ run: "bun run",
58
+ exec: "bunx"
59
+ },
60
+ yarn: {
61
+ install: "yarn install",
62
+ run: "yarn run",
63
+ exec: "yarn run"
64
+ }
65
+ };
66
+ /**
67
+ * The README every scaffolded project gets, and the first thing a new author
68
+ * reads. Four things in it are corrections rather than prose:
69
+ *
70
+ * - **`<pm> run dev`, never a bare `aai dev`.** The CLI is a devDependency, so
71
+ * after the install the binary is in `node_modules/.bin` and NOT on
72
+ * `PATH`. The old quickstart said `aai dev`, which fails with
73
+ * `command not found` for everyone who has not installed the CLI globally.
74
+ * - **Every command names the manager the install actually used.** It said
75
+ * `npm install` unconditionally, directly beside the pnpm lockfile `init`
76
+ * had just written — so the one file a new author reads disagreed with the
77
+ * directory it describes.
78
+ * - **The key `aai dev` needs is named, with the two LOCAL ways first.** No
79
+ * step of local development needs a platform account; a twenty-persona DX
80
+ * audit read the account-shaped failure it used to get and concluded the
81
+ * opposite, then stopped using the loop this file documents.
82
+ * - **`aai login` appears where it is actually required.** It was in no
83
+ * user-facing doc at all, while the quickstart's own publish step needs it.
84
+ */
85
+ function readmeContent(slug, pm) {
86
+ const { install, run, exec } = PM_COMMANDS[pm];
87
+ return `# ${slug}
88
+
89
+ A voice agent built with [aai](${REPO_URL}).
90
+
91
+ ## Getting started
92
+
93
+ \`\`\`sh
94
+ ${install.padEnd(18)}# Install dependencies
95
+ ${`${run} dev`.padEnd(18)}# Run locally on http://localhost:3000 (opens browser)
96
+ \`\`\`
97
+
98
+ The \`aai\` CLI is a devDependency of this project, so it lives in
99
+ \`node_modules/.bin\` rather than on your \`PATH\`. Run it through ${pm}
100
+ (\`${run} dev\`, \`${run} test\`, \`${run} build\`) or with \`${exec} aai <command>\`.
101
+ Installing it globally (\`npm i -g @alexkroman1/aai-cli\`) also works, and is
102
+ what the project docs assume.
103
+
104
+ ### The one key local development needs
105
+
106
+ The default pipeline (speech-to-text → LLM → text-to-speech) runs on a single
107
+ AssemblyAI key. **Any one of these is enough, and the first two need no aai
108
+ account** — nothing about running this agent locally is gated on one:
109
+
110
+ 1. Put \`ASSEMBLYAI_API_KEY=<your key>\` in \`.env\` (this project's \`.env.example\`
111
+ documents it, and it is the same file \`aai publish\` uploads as secrets).
112
+ 2. Or export it in your shell: \`export ASSEMBLYAI_API_KEY=<your key>\`.
113
+ 3. Or run \`${exec} aai login\`, and \`${run} dev\` will use your account's key.
114
+
115
+ Get a key at <https://www.assemblyai.com/dashboard>.
116
+
117
+ ## Publishing
118
+
119
+ Publishing (and the studio it syncs to) is the one part that does need an
120
+ account:
121
+
122
+ \`\`\`sh
123
+ ${`${exec} aai login`.padEnd(23)}# Link your account — once per machine
124
+ ${`${run} publish:agent`.padEnd(23)}# Publish to production (and sync to the studio)
125
+ \`\`\`
126
+
127
+ You can also run this agent as a plain Node server, with no aai account and
128
+ nothing managed:
129
+
130
+ \`\`\`sh
131
+ ${`${run} start`.padEnd(23)}# Builds, then serves on http://127.0.0.1:3000
132
+ \`\`\`
133
+
134
+ ## Secrets
135
+
136
+ Access secrets in your agent via \`ctx.env.MY_KEY\`.
137
+
138
+ **Local development** — add secrets to \`.env\` (auto-loaded by \`aai dev\`):
139
+
140
+ \`\`\`sh
141
+ ALPHA_VANTAGE_KEY=sk-abc123
142
+ MY_API_KEY=secret-value
143
+ \`\`\`
144
+
145
+ **Production** — set secrets on the server:
146
+
147
+ \`\`\`sh
148
+ ${`${exec} aai secret put MY_KEY`.padEnd(29)}# Set a secret (prompts for value)
149
+ ${`${exec} aai secret list`.padEnd(29)}# List secret names
150
+ ${`${exec} aai secret delete MY_KEY`.padEnd(29)}# Remove a secret
151
+ \`\`\`
152
+
153
+ `;
154
+ }
155
+ /**
156
+ * Map from npm package name to directory name under packages/.
157
+ * Used to rewrite published version ranges to link: paths in dev mode.
158
+ */
159
+ const WORKSPACE_PKG_DIRS = {
160
+ "@alexkroman1/aai": "aai",
161
+ "@alexkroman1/aai-cli": "aai-cli",
162
+ "@alexkroman1/aai-runtime": "aai-runtime",
163
+ "@alexkroman1/aai-ui": "aai-ui"
164
+ };
165
+ /** Rewrite workspace deps to link: paths so pnpm links to local source. */
166
+ async function patchPackageJsonForWorkspace(targetDir) {
167
+ const pkgPath = path.join(targetDir, "package.json");
168
+ const pkgJson = await readJson(pkgPath);
169
+ if (!pkgJson) return;
170
+ pkgJson.name = path.basename(targetDir);
171
+ delete pkgJson.packageManager;
172
+ const root = getMonorepoRoot();
173
+ if (!root) return;
174
+ const packagesDir = path.join(root, "packages");
175
+ for (const field of ["dependencies", "devDependencies"]) {
176
+ const deps = pkgJson[field];
177
+ if (!deps) continue;
178
+ for (const key of Object.keys(deps)) {
179
+ const dir = WORKSPACE_PKG_DIRS[key];
180
+ if (dir) deps[key] = `link:${path.relative(targetDir, path.join(packagesDir, dir))}`;
181
+ }
182
+ }
183
+ await writeJson(pkgPath, pkgJson);
184
+ await pinSharedDeps(targetDir, packagesDir, pkgJson);
185
+ }
186
+ /**
187
+ * Pin every THIRD-PARTY dependency this project shares with a linked workspace
188
+ * package to the copy that workspace package resolved.
189
+ *
190
+ * Linking is what makes this necessary, and it only bites in dev mode. The
191
+ * project's `@alexkroman1/*` deps become `link:` paths, so the SDK's types come
192
+ * out of the WORKSPACE's `node_modules` — while the project installs its own
193
+ * copy of anything it also declares. Two copies of a structurally identical
194
+ * library are two NOMINALLY different types to TypeScript, and the error runs to
195
+ * a hundred lines of `Type 'AnyActorLogic' is not assignable to type
196
+ * 'AnyActorLogic'` with two absolute paths in it.
197
+ *
198
+ * Measured: `aai init --template technical-support-agent` produced exactly that. The
199
+ * workspace lockfile pinned `xstate@5.32.5`, the fresh project resolved
200
+ * `^5.32.5` to `5.32.6`, the CLI's typecheck gate failed, and the deploy was
201
+ * REFUSED — `"deployed": false` with the whole error as a warning. One
202
+ * `overrides` entry fixes it; verified end to end.
203
+ *
204
+ * A published install has no such problem, which is why this is dev-mode only:
205
+ * a user's project and the published SDK both ask for `^5.32.5` and pnpm
206
+ * resolves ONE copy. Nothing here changes what a user gets.
207
+ *
208
+ * Written to `pnpm-workspace.yaml` rather than `pnpm.overrides` in the manifest:
209
+ * the scaffold ships that file, which makes the project its own workspace root,
210
+ * and pnpm 10+ reads overrides from there. Verified both ways — the manifest
211
+ * spelling installed `5.32.6` anyway.
212
+ */
213
+ async function pinSharedDeps(targetDir, packagesDir, pkgJson) {
214
+ const declared = {
215
+ ...pkgJson.dependencies,
216
+ ...pkgJson.devDependencies
217
+ };
218
+ const linked = Object.entries(WORKSPACE_PKG_DIRS).filter(([name]) => name in declared).map(([, dir]) => dir);
219
+ const resolved = await Promise.all(Object.keys(declared).filter((name) => !(name in WORKSPACE_PKG_DIRS)).map(async (name) => {
220
+ for (const dir of linked) {
221
+ const manifest = await readJson(path.join(packagesDir, dir, "node_modules", name, "package.json"));
222
+ if (typeof manifest?.version === "string") return [name, manifest.version];
223
+ }
224
+ return null;
225
+ }));
226
+ const pins = new Map(resolved.filter((entry) => entry !== null));
227
+ if (pins.size === 0) return;
228
+ const file = path.join(targetDir, "pnpm-workspace.yaml");
229
+ let existing;
230
+ try {
231
+ existing = await fs.readFile(file, "utf-8");
232
+ } catch {
233
+ return;
234
+ }
235
+ const block = [...pins].sort(([a], [b]) => compareCodeUnits(a, b)).map(([name, version]) => ` "${name}": "${version}"`).join("\n");
236
+ await fs.writeFile(file, `${existing.trimEnd()}\n\n# Added by \`aai init\` in DEV MODE only — see pinSharedDeps in\n# packages/aai-cli/src/_init.ts. The @alexkroman1/* packages above are LINKED to
237
+ # this checkout, so anything they and this project both depend on has to be
238
+ # ONE copy: two copies of xstate are two incompatible sets of types, and the
239
+ # typecheck gate refuses the deploy.\noverrides:\n${block}\n`);
240
+ }
241
+ /**
242
+ * Pin the manifest's `packageManager` to the manager that actually installed —
243
+ * or REMOVE the field when there is no version to pin.
244
+ *
245
+ * The scaffold ships `packageManager: pnpm@<v>` because it is a pnpm workspace
246
+ * root in this repo, and it used to be copied verbatim into a project installed
247
+ * with something else. That is not inert: pnpm and Yarn both READ the field and
248
+ * refuse to run when it names another manager ("This project is configured to
249
+ * use pnpm"), so a project installed with npm could not later be touched by
250
+ * yarn without editing a field nobody chose. Stamping the manager that ran is
251
+ * the whole fix, and dropping it when the version is unknown is the honest
252
+ * fallback — a bare name is not a valid value for that field.
253
+ */
254
+ async function stampPackageManager(targetDir, pm) {
255
+ const pkgPath = path.join(targetDir, "package.json");
256
+ const pkgJson = await readJson(pkgPath);
257
+ if (!pkgJson) return;
258
+ const pin = pm.version === void 0 ? void 0 : `${pm.name}@${pm.version}`;
259
+ if (pkgJson.packageManager === pin) return;
260
+ if (pin === void 0) delete pkgJson.packageManager;
261
+ else pkgJson.packageManager = pin;
262
+ await writeJson(pkgPath, pkgJson);
263
+ }
264
+ async function runInit(opts) {
265
+ const { targetDir, template } = opts;
266
+ const pm = opts.packageManager ?? { name: "npm" };
267
+ await downloadAndMergeTemplate(template, targetDir);
268
+ if (isDevMode()) {
269
+ await patchPackageJsonForWorkspace(targetDir);
270
+ try {
271
+ await fs.unlink(path.join(targetDir, ".npmrc"));
272
+ } catch {}
273
+ } else await stampPackageManager(targetDir, pm);
274
+ try {
275
+ await fs.copyFile(path.join(targetDir, ".env.example"), path.join(targetDir, ".env"), fs.constants.COPYFILE_EXCL);
276
+ } catch {}
277
+ const readmePath = path.join(targetDir, "README.md");
278
+ const slug = path.basename(path.resolve(targetDir));
279
+ try {
280
+ await fs.writeFile(readmePath, readmeContent(slug, pm.name), { flag: "wx" });
281
+ } catch (err) {
282
+ if (!isEexist(err)) throw err;
283
+ }
284
+ }
285
+ //#endregion
286
+ //#region src/init.ts
287
+ /**
288
+ * Run `fn` behind a clack spinner, stopping it in EVERY outcome.
289
+ *
290
+ * The naked form (`s?.start(); await work(); s?.stop()`) leaks the spinner on a
291
+ * failure: clack keeps its interval and its raw-mode stdin hook, so a throw
292
+ * left a spinner ticking under the error message with the cursor hidden. The
293
+ * `catch` label is what the terminal is left showing, so it names the step.
294
+ */
295
+ async function withSpinner(silent, labels, fn) {
296
+ const s = silent ? void 0 : p.spinner();
297
+ s?.start(labels.start);
298
+ let succeeded = false;
299
+ try {
300
+ const value = await fn();
301
+ succeeded = true;
302
+ return value;
303
+ } finally {
304
+ s?.stop(succeeded ? labels.done : labels.failed);
305
+ }
306
+ }
307
+ const DEFAULT_PROJECT_NAME = "my-voice-agent";
308
+ /** Prompt for project name or return default when --yes is set. */
309
+ async function promptProjectName(yes) {
310
+ if (yes) return DEFAULT_PROJECT_NAME;
311
+ return unwrapCancel(await p.text({
312
+ message: "What is your project named?",
313
+ placeholder: DEFAULT_PROJECT_NAME,
314
+ defaultValue: DEFAULT_PROJECT_NAME
315
+ }), "Setup cancelled") || DEFAULT_PROJECT_NAME;
316
+ }
317
+ /**
318
+ * The template a non-interactive `init` gets, and the entry the selector opens
319
+ * on — so an author who just presses Enter lands where they used to.
320
+ */
321
+ const DEFAULT_TEMPLATE = "quickstart-agent";
322
+ /**
323
+ * Ask which template to scaffold, listing what this CLI actually ships.
324
+ *
325
+ * The options are derived from {@link listTemplates} rather than a roster kept
326
+ * here: that function already backs `aai templates` AND the unknown-template
327
+ * error, so a template added to the package shows up in the picker with no
328
+ * second list to update. {@link DEFAULT_TEMPLATE} is hoisted to the top and
329
+ * pre-selected, which is what keeps a bare `aai init` a single Enter away from
330
+ * the project it produced before there was a picker.
331
+ *
332
+ * Callers must not reach here when there is nobody to answer — `--yes` and
333
+ * JSON mode (auto-detected on a pipe) resolve the default without prompting.
334
+ */
335
+ async function promptTemplate(list = listTemplates) {
336
+ const [first, ...rest] = await list();
337
+ if (first === void 0) return DEFAULT_TEMPLATE;
338
+ if (rest.length === 0) return first;
339
+ const names = [first, ...rest];
340
+ const hasDefault = names.includes(DEFAULT_TEMPLATE);
341
+ const ordered = hasDefault ? [DEFAULT_TEMPLATE, ...names.filter((name) => name !== DEFAULT_TEMPLATE)] : names;
342
+ return unwrapCancel(await p.select({
343
+ message: "Which template?",
344
+ maxItems: 12,
345
+ initialValue: hasDefault ? DEFAULT_TEMPLATE : first,
346
+ options: ordered.map((name) => name === DEFAULT_TEMPLATE ? {
347
+ value: name,
348
+ hint: "the default starting point"
349
+ } : { value: name })
350
+ }), "Setup cancelled");
351
+ }
352
+ /** Check if the project has any dependencies to install. */
353
+ async function hasDeps(cwd) {
354
+ if (await fileExists(path.join(cwd, "node_modules"))) return false;
355
+ const pkgJson = await readJson(path.join(cwd, "package.json")) ?? {};
356
+ const deps = Object.keys(pkgJson.dependencies ?? {});
357
+ const devDeps = Object.keys(pkgJson.devDependencies ?? {});
358
+ return deps.length > 0 || devDeps.length > 0;
359
+ }
360
+ /**
361
+ * A version string fit for the manifest's `packageManager` field.
362
+ *
363
+ * That field takes `name@version` and corepack REFUSES a value it cannot parse,
364
+ * so anything a `--version` probe prints that is not a plain version (a banner,
365
+ * a warning line, `?`) must produce no pin rather than an unusable one.
366
+ */
367
+ const VERSION_RE = /^\d+\.\d+\.\d+\S*$/;
368
+ /** The first token of an `npm_config_user_agent`: `pnpm/10.29.3 npm/? node/v24…`. */
369
+ const USER_AGENT_HEAD = /^([a-z]+)\/(\S+)/;
370
+ function isPackageManager(name) {
371
+ return PACKAGE_MANAGERS.includes(name);
372
+ }
373
+ /**
374
+ * The manager that INVOKED this process, from `npm_config_user_agent`.
375
+ *
376
+ * Every one of the four sets it when it runs a binary or a script, so this is
377
+ * the strongest signal available and it is checked first: a user who followed
378
+ * the documented `npm i -g @alexkroman1/aai-cli` and then ran `npx aai init`
379
+ * has said which manager they use, and the old code installed with pnpm
380
+ * regardless. An unrecognized head (`deno/…`, nothing at all) falls through to
381
+ * the PATH probe rather than guessing.
382
+ */
383
+ function packageManagerFromUserAgent(ua = process.env.npm_config_user_agent) {
384
+ const match = USER_AGENT_HEAD.exec(ua?.trim() ?? "");
385
+ const name = match?.[1];
386
+ if (!isPackageManager(name)) return void 0;
387
+ const version = match?.[2];
388
+ return version !== void 0 && VERSION_RE.test(version) ? {
389
+ name,
390
+ version
391
+ } : { name };
392
+ }
393
+ /**
394
+ * A manager's own version, or `undefined` when it is not on PATH at all.
395
+ *
396
+ * An empty string means "present, but it did not print a version I can pin" —
397
+ * the two outcomes have to stay distinguishable, because the first decides
398
+ * which manager RUNS and the second only decides whether the manifest gets a
399
+ * `packageManager` pin.
400
+ */
401
+ async function binVersion(cmd) {
402
+ const { failed, stdout } = await execa(cmd, ["--version"], { reject: false }).catch(() => void 0) ?? {
403
+ failed: true,
404
+ stdout: ""
405
+ };
406
+ if (failed) return void 0;
407
+ const first = String(stdout ?? "").trim().split("\n", 1)[0]?.trim();
408
+ return first !== void 0 && VERSION_RE.test(first) ? first : "";
409
+ }
410
+ /**
411
+ * Which package manager `aai init` installs with.
412
+ *
413
+ * It used to be pnpm, unconditionally, reached through `corepack enable` — and
414
+ * corepack is absent from Node >= 25, half the range the scaffold's `engines`
415
+ * allow, so on a current Node the documented install path (`npm i -g
416
+ * @alexkroman1/aai-cli`) produced a scaffold whose install step needed a
417
+ * manager the user had never been asked to have. The generated README then said
418
+ * `npm install` beside the pnpm lockfile.
419
+ *
420
+ * Two signals, in order, and pnpm stays the preference in the second: the
421
+ * manager that invoked us, then the first of {@link PACKAGE_MANAGERS} that is
422
+ * really on PATH. npm is the last resort because every Node install ships one,
423
+ * so the install command is at worst attempted rather than skipped.
424
+ *
425
+ * Note what this does NOT do: enable corepack, or install a manager. Running
426
+ * only something that answered `--version` is what makes the corepack call
427
+ * unnecessary, and it is the whole reason this function exists.
428
+ */
429
+ async function detectPackageManager(ua = process.env.npm_config_user_agent, probe = binVersion) {
430
+ const declared = packageManagerFromUserAgent(ua);
431
+ if (declared) return declared;
432
+ for (const name of PACKAGE_MANAGERS) {
433
+ const version = await probe(name);
434
+ if (version === void 0) continue;
435
+ return version ? {
436
+ name,
437
+ version
438
+ } : { name };
439
+ }
440
+ return { name: "npm" };
441
+ }
442
+ /** Check whether the safe-chain binary is on PATH. */
443
+ async function hasSafeChain() {
444
+ const { failed } = await execa("safe-chain", ["--version"], { reject: false });
445
+ return !failed;
446
+ }
447
+ /**
448
+ * Build the command + args that install `pm`'s dependencies.
449
+ *
450
+ * The safe-chain routing is pnpm-only and stays that way: it is what this repo
451
+ * installs with, `--safe-chain-skip-minimum-package-age` exists because the
452
+ * scaffold pins freshly published `@alexkroman1/*` versions, and safe-chain's
453
+ * other wrappers are not what anything here was verified against. npm has no
454
+ * such quarantine to skip, so nothing is lost on that path.
455
+ */
456
+ async function resolveInstallCommand(pm, checkSafeChain = hasSafeChain) {
457
+ if (pm !== "pnpm") return {
458
+ cmd: pm,
459
+ args: []
460
+ };
461
+ if (await checkSafeChain()) return {
462
+ cmd: "safe-chain",
463
+ args: ["pnpm", "--safe-chain-skip-minimum-package-age"]
464
+ };
465
+ return {
466
+ cmd: "pnpm",
467
+ args: []
468
+ };
469
+ }
470
+ /** Run the install and warn on failure. */
471
+ async function runInstall(cwd, pm) {
472
+ const { cmd, args } = await resolveInstallCommand(pm);
473
+ const workspaceArgs = pm === "pnpm" && !isDevMode() ? ["--ignore-workspace"] : [];
474
+ await execa(cmd, [
475
+ ...args,
476
+ "install",
477
+ ...workspaceArgs
478
+ ], { cwd });
479
+ }
480
+ /**
481
+ * Install deps with `pm`, reporting a failure through `warn` rather than
482
+ * throwing: the project is scaffolded either way, and the two warnings say how
483
+ * to finish the install by hand. Nothing downstream branches on the outcome —
484
+ * `init` stops here — so it returns nothing.
485
+ */
486
+ async function installDeps(cwd, pm, warn, silent) {
487
+ if (!await hasDeps(cwd)) return;
488
+ try {
489
+ await withSpinner(silent, {
490
+ start: `Installing dependencies with ${pm}`,
491
+ done: "Dependencies installed",
492
+ failed: "Dependency install failed"
493
+ }, () => runInstall(cwd, pm));
494
+ } catch (err) {
495
+ warn(`${pm} install failed: ${errorMessage(err)}`);
496
+ warn(`Finish the install by hand: cd ${cwd} && ${pm} install`);
497
+ }
498
+ }
499
+ /** Resolve target directory relative to the user's current directory. */
500
+ function resolveTargetDir(dir) {
501
+ return path.resolve(resolveCwd(), dir);
502
+ }
503
+ function collectWarnings() {
504
+ const warnings = [];
505
+ return {
506
+ warnings,
507
+ warn: (message) => {
508
+ warnings.push(message);
509
+ log.warn(message);
510
+ }
511
+ };
512
+ }
513
+ /**
514
+ * Scaffold the project, optionally showing a spinner.
515
+ *
516
+ * `packageManager` is passed rather than re-detected inside `runInit`: the two
517
+ * files it writes that name a manager — the README and the manifest's
518
+ * `packageManager` pin — have to name the one {@link installDeps} is about to
519
+ * run, and a second detection is a second chance to disagree.
520
+ */
521
+ async function scaffoldProject(dir, cwd, template, pm, silent) {
522
+ await withSpinner(silent, {
523
+ start: `Creating ${dir}`,
524
+ done: "Project created",
525
+ failed: `Could not create ${dir}`
526
+ }, () => runInit({
527
+ targetDir: cwd,
528
+ template,
529
+ packageManager: pm
530
+ }));
531
+ }
532
+ /** Print post-init instructions. */
533
+ function printPostInitInfo(cwd, monorepoRoot) {
534
+ log.success(`Created ${cwd}`);
535
+ if (monorepoRoot) log.info("Dev mode: project linked to workspace packages");
536
+ log.info(`Next: cd ${cwd} && aai dev`);
537
+ }
538
+ async function executeInit(opts, extra) {
539
+ const suppressUi = extra?.silent;
540
+ if (!suppressUi) p.intro(styleText("cyanBright", "Create a new voice agent"));
541
+ const dir = opts.dir ?? await promptProjectName(opts.yes);
542
+ const monorepoRoot = getMonorepoRoot();
543
+ const cwd = resolveTargetDir(dir);
544
+ if (!opts.force && await fileExists(path.join(cwd, "agent.ts"))) throw new Error(`${AGENT_ENTRY} already exists in this directory. Use ${styleText("cyanBright", "--force")} to overwrite.`);
545
+ const template = opts.template ?? (opts.yes || suppressUi ? DEFAULT_TEMPLATE : await promptTemplate());
546
+ const { warn, warnings } = collectWarnings();
547
+ const pm = await detectPackageManager();
548
+ await scaffoldProject(dir, cwd, template, pm, suppressUi);
549
+ await installDeps(cwd, pm.name, warn, suppressUi);
550
+ if (!suppressUi) printPostInitInfo(cwd, monorepoRoot);
551
+ const data = {
552
+ dir: cwd,
553
+ template
554
+ };
555
+ if (warnings.length > 0) data.warnings = warnings;
556
+ return ok(data);
557
+ }
558
+ //#endregion
559
+ export { executeInit };