@alexkroman1/aai-cli 16.1.0 → 17.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 (183) 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/_deno-target.d.ts +15 -14
  5. package/dist/_dev-env.d.ts +19 -13
  6. package/dist/{_dev-server-D1wKiA0_.mjs → _dev-server-CLU9xjH5.mjs} +25 -17
  7. package/dist/_dev-server.d.ts +4 -3
  8. package/dist/_init.d.ts +39 -0
  9. package/dist/_modal-target.d.ts +11 -6
  10. package/dist/_preflight-CnW9QiE7.mjs +116 -0
  11. package/dist/_preflight.d.ts +110 -5
  12. package/dist/_target-bundle.d.ts +112 -0
  13. package/dist/_target-entry.d.ts +81 -0
  14. package/dist/{_templates-CuP74F8D.mjs → _templates-IMeKMVIj.mjs} +1 -1
  15. package/dist/{_vitest-runner-BiAMIir1.mjs → _vitest-runner-CZNGj0ZC.mjs} +21 -16
  16. package/dist/_vitest-runner.d.ts +35 -23
  17. package/dist/{build-O6BT51x_.mjs → build-DrQTSc2R.mjs} +128 -293
  18. package/dist/build.d.ts +34 -4
  19. package/dist/cli.mjs +20 -16
  20. package/dist/{deploy-lldQyJVj.mjs → deploy-B68-x7xM.mjs} +12 -4
  21. package/dist/deploy.d.ts +9 -0
  22. package/dist/{dev-Du8pCWFq.mjs → dev-ChsrNHpK.mjs} +1 -1
  23. package/dist/dev.d.ts +1 -1
  24. package/dist/{eval-Ducmkt1n.mjs → eval-DB07kTxO.mjs} +1 -1
  25. package/dist/init-W-4k-lCF.mjs +559 -0
  26. package/dist/init.d.ts +43 -3
  27. package/dist/scaffold/CLAUDE.md +51 -64
  28. package/dist/scaffold/package.json +6 -6
  29. package/dist/scaffold/vite.config.ts +29 -1
  30. package/dist/{studio-It7SRfUN.mjs → studio-DEAJGBXa.mjs} +19 -9
  31. package/dist/templates/applicant-screening-agent/agent.eval.test.ts +20 -6
  32. package/dist/templates/applicant-screening-agent/agent.ts +28 -0
  33. package/dist/templates/applicant-screening-agent/shared.ts +11 -11
  34. package/dist/templates/call-audit-workflow/agent.ts +2 -0
  35. package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
  36. package/dist/templates/code-interpreter-agent/agent.ts +1 -0
  37. package/dist/templates/coding-agent/agent.eval.test.ts +136 -0
  38. package/dist/templates/coding-agent/agent.test.ts +109 -0
  39. package/dist/templates/coding-agent/agent.ts +45 -0
  40. package/dist/templates/coding-agent/chat.ts +63 -0
  41. package/dist/templates/coding-agent/shared.ts +46 -0
  42. package/dist/templates/coding-agent/system-prompt.md +32 -0
  43. package/dist/templates/coding-agent/tools/bash.ts +6 -0
  44. package/dist/templates/coding-agent/tools/delete_file.ts +6 -0
  45. package/dist/templates/coding-agent/tools/edit_file.ts +6 -0
  46. package/dist/templates/coding-agent/tools/glob.ts +6 -0
  47. package/dist/templates/coding-agent/tools/grep.ts +6 -0
  48. package/dist/templates/coding-agent/tools/list_files.ts +6 -0
  49. package/dist/templates/coding-agent/tools/read_file.ts +6 -0
  50. package/dist/templates/coding-agent/tools/todo_write.ts +6 -0
  51. package/dist/templates/coding-agent/tools/write_file.ts +6 -0
  52. package/dist/templates/custom-pipeline-agent/agent.ts +1 -0
  53. package/dist/templates/document-redline-workflow/agent.ts +2 -0
  54. package/dist/templates/emergency-dispatch-agent/agent.test.ts +103 -0
  55. package/dist/templates/emergency-dispatch-agent/agent.ts +15 -0
  56. package/dist/templates/emergency-dispatch-agent/guardrails.ts +105 -0
  57. package/dist/templates/emergency-dispatch-agent/system-prompt.md +1 -0
  58. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +8 -1
  59. package/dist/templates/entertainment-picks-agent/agent.ts +1 -0
  60. package/dist/templates/entertainment-picks-agent/system-prompt.md +6 -0
  61. package/dist/templates/entertainment-picks-agent/tools/revisit.ts +7 -0
  62. package/dist/templates/executive-inbox-agent/agent.eval.test.ts +84 -23
  63. package/dist/templates/executive-inbox-agent/agent.ts +1 -0
  64. package/dist/templates/executive-inbox-agent/meeting.ts +1 -1
  65. package/dist/templates/executive-inbox-agent/prompts.ts +3 -1
  66. package/dist/templates/executive-inbox-agent/system-prompt.md +3 -3
  67. package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +3 -3
  68. package/dist/templates/executive-inbox-agent/tools/open_email.ts +8 -16
  69. package/dist/templates/hotel-reception-agent/agent.eval.test.ts +85 -21
  70. package/dist/templates/hotel-reception-agent/agent.test.ts +2 -1
  71. package/dist/templates/hotel-reception-agent/agent.ts +6 -3
  72. package/dist/templates/hotel-reception-agent/client.tsx +14 -2
  73. package/dist/templates/hotel-reception-agent/concierge.ts +2 -1
  74. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +2 -1
  75. package/dist/templates/hotel-reception-agent/disputes.ts +9 -11
  76. package/dist/templates/hotel-reception-agent/events.ts +2 -1
  77. package/dist/templates/hotel-reception-agent/session.ts +56 -0
  78. package/dist/templates/hotel-reception-agent/shared.ts +20 -21
  79. package/dist/templates/hotel-reception-agent/system-prompt.md +1 -1
  80. package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +2 -1
  81. package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +2 -1
  82. package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +2 -1
  83. package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -1
  84. package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +2 -1
  85. package/dist/templates/hotel-reception-agent/tools/check_restaurant_availability.ts +1 -1
  86. package/dist/templates/hotel-reception-agent/tools/check_room_availability.ts +1 -1
  87. package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
  88. package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +2 -1
  89. package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +2 -1
  90. package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +2 -1
  91. package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +2 -1
  92. package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +2 -1
  93. package/dist/templates/hotel-reception-agent/tools/lookup_guest_history.ts +1 -1
  94. package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +2 -1
  95. package/dist/templates/hotel-reception-agent/tools/lookup_restaurant_reservation.ts +1 -1
  96. package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -1
  97. package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
  98. package/dist/templates/hotel-reception-agent/tools/record_followup.ts +2 -1
  99. package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +2 -1
  100. package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
  101. package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -1
  102. package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +2 -1
  103. package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +2 -1
  104. package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -1
  105. package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +2 -1
  106. package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +2 -1
  107. package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +2 -1
  108. package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
  109. package/dist/templates/hotel-reception-agent/tools/set_stay.ts +2 -1
  110. package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +2 -1
  111. package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +2 -1
  112. package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +2 -1
  113. package/dist/templates/hotel-reception-agent/tools/transfer_call.ts +2 -1
  114. package/dist/templates/hotel-reception-agent/tools/update_card.ts +2 -1
  115. package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +2 -1
  116. package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -1
  117. package/dist/templates/link-digest-workflow/agent.ts +5 -0
  118. package/dist/templates/medication-safety-agent/agent.test.ts +54 -0
  119. package/dist/templates/medication-safety-agent/agent.ts +48 -1
  120. package/dist/templates/meeting-recap-agent/agent.test.ts +2 -2
  121. package/dist/templates/meeting-recap-agent/agent.ts +4 -0
  122. package/dist/templates/pizza-ordering-agent/agent.ts +3 -0
  123. package/dist/templates/podcast-digest-workflow/agent.ts +4 -0
  124. package/dist/templates/quickstart-agent/agent.eval.test.ts +39 -3
  125. package/dist/templates/quickstart-agent/agent.test.ts +22 -0
  126. package/dist/templates/quickstart-agent/agent.ts +18 -2
  127. package/dist/templates/quickstart-agent/system-prompt.md +8 -0
  128. package/dist/templates/quickstart-agent/tools/get_weather.ts +59 -0
  129. package/dist/templates/research-handoff-agent/agent.ts +4 -0
  130. package/dist/templates/research-planner-agent/agent.eval.test.ts +24 -2
  131. package/dist/templates/research-planner-agent/agent.ts +3 -0
  132. package/dist/templates/research-planner-agent/system-prompt.md +1 -1
  133. package/dist/templates/retail-orders-agent/agent.ts +32 -3
  134. package/dist/templates/retail-orders-agent/keyterms.ts +154 -0
  135. package/dist/templates/retail-orders-agent/resolve.ts +18 -3
  136. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +37 -5
  137. package/dist/templates/roadside-assistance-agent/agent.test.ts +38 -6
  138. package/dist/templates/roadside-assistance-agent/agent.ts +4 -0
  139. package/dist/templates/roadside-assistance-agent/shared.ts +12 -0
  140. package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +14 -0
  141. package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +11 -0
  142. package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +17 -11
  143. package/dist/templates/roadside-assistance-agent/yard.test.ts +4 -0
  144. package/dist/templates/spoken-summary-workflow/agent.ts +4 -0
  145. package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +6 -0
  146. package/dist/templates/tabletop-rpg-agent/agent.test.ts +125 -1
  147. package/dist/templates/tabletop-rpg-agent/agent.ts +30 -1
  148. package/dist/templates/tabletop-rpg-agent/shared.ts +81 -0
  149. package/dist/templates/tabletop-rpg-agent/system-prompt.md +1 -1
  150. package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +16 -7
  151. package/dist/templates/technical-support-agent/agent.test.ts +3 -3
  152. package/dist/templates/technical-support-agent/agent.ts +5 -1
  153. package/dist/templates/technical-support-agent/knowledge.ts +165 -0
  154. package/dist/templates/technical-support-agent/nodes.ts +3 -2
  155. package/dist/templates/technical-support-agent/procedure.ts +4 -3
  156. package/dist/templates/technical-support-agent/shared.ts +10 -146
  157. package/dist/templates/technical-support-agent/tools/list_topics.ts +2 -1
  158. package/dist/templates/text-adventure-agent/agent.eval.test.ts +39 -6
  159. package/dist/templates/text-adventure-agent/agent.test.ts +79 -1
  160. package/dist/templates/text-adventure-agent/agent.ts +30 -1
  161. package/dist/templates/text-adventure-agent/shared.ts +37 -0
  162. package/dist/templates/text-adventure-agent/system-prompt.md +9 -2
  163. package/dist/templates/topic-briefing-agent/agent.eval.test.ts +18 -4
  164. package/dist/templates/topic-briefing-agent/agent.test.ts +23 -11
  165. package/dist/templates/topic-briefing-agent/agent.ts +4 -1
  166. package/dist/templates/topic-briefing-agent/shared.ts +10 -10
  167. package/dist/templates/topic-briefing-agent/system-prompt.md +13 -8
  168. package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +43 -5
  169. package/dist/templates/transcription-workflow/agent.ts +3 -0
  170. package/dist/templates/travel-concierge-agent/agent.ts +4 -0
  171. package/dist/templates/web-research-agent/agent.eval.test.ts +31 -5
  172. package/dist/templates/web-research-agent/agent.test.ts +16 -0
  173. package/dist/templates/web-research-agent/agent.ts +30 -0
  174. package/dist/templates/web-research-agent/system-prompt.md +8 -2
  175. package/dist/templates/word-game-agent/agent.eval.test.ts +79 -18
  176. package/dist/templates/word-game-agent/agent.ts +20 -0
  177. package/dist/test-CjKPQ9_B.mjs +102 -0
  178. package/dist/test.d.ts +37 -12
  179. package/package.json +5 -5
  180. package/dist/_init-Bp1CjRrU.mjs +0 -199
  181. package/dist/_preflight-CcAR577V.mjs +0 -46
  182. package/dist/init-CY4NAXAA.mjs +0 -183
  183. package/dist/test-PHHv0Vj6.mjs +0 -83
@@ -1,18 +1,19 @@
1
- # aai Voice Agent
1
+ # AssemblyAI Agent SDK
2
2
 
3
- You are helping build a voice agent using the **aai** framework.
3
+ You are helping build a voice agent with the **AssemblyAI Agent SDK**.
4
4
 
5
5
  ## Workflow
6
6
 
7
7
  The fast loop: edit → `pnpm dev` (browser, talk to it) →
8
8
  `pnpm test` (logic) → `pnpm build` (validate bundle).
9
9
 
10
- 1. **Iterate in `pnpm dev`** — browser UI, and `pnpm dev -- --watch` to
11
- rebuild and restart on every save. Speak to the agent to verify behavior
12
- end-to-end. This is the primary feedback loop. Watching is OPT-IN because a
13
- restart ends in-flight voice sessions, which is right while you are editing
14
- and wrong while something is driving the agent for twenty minutes;
15
- `AAI_DEV_WATCH=1` is the same switch for a process supervisor.
10
+ 1. **Iterate in `pnpm dev`** — browser UI, and it rebuilds and restarts on
11
+ every save when you are at a terminal. Speak to the agent to verify behavior
12
+ end-to-end. This is the primary feedback loop. Watching is on for a PERSON
13
+ and off for everything else: a restart ends in-flight voice sessions, which
14
+ is right while you are editing and wrong while something drives the agent
15
+ for twenty minutes, and a harness or supervisor has no TTY. `AAI_DEV_WATCH=0`
16
+ turns it off at a terminal, `AAI_DEV_WATCH=1` on for a process supervisor.
16
17
  2. **Run `pnpm test` after logic changes** — vitest. Co-locate tests as
17
18
  `agent.test.ts` (see `custom-pipeline-agent` template for a reference).
18
19
  **When the project has an `agent.test.ts` (the default `quickstart-agent`
@@ -117,8 +118,8 @@ Then:
117
118
  aai init # Scaffold a new agent
118
119
  aai templates # List available templates
119
120
  aai dev # Start local dev server
120
- aai test # Run agent.test.ts via vitest
121
- aai test --all # ...or every spec in the project
121
+ aai test # Run the project's specs via vitest
122
+ aai test --only # ...or agent.test.ts alone
122
123
  aai eval # Run agent.eval.test.ts against a model
123
124
  aai build # Bundle and validate
124
125
  aai deploy # Deploy to production
@@ -132,12 +133,11 @@ The scaffold's `package.json` exposes `dev`, `build`, `test`, `eval` and
132
133
  `deploy` as `pnpm <name>` shortcuts, which run the project's own copy of the
133
134
  CLI. Other commands (`init`, `templates`, `delete`, `secret`) are CLI-only.
134
135
 
135
- **`aai test` targets `agent.test.ts` and nothing else**, which `--all` widens.
136
- What matters is that a narrowed run does not report itself as a pass: when the
137
- project holds spec files the run did not cover, it FAILS and names them rather
138
- than printing a green line that says nothing about `tools/*.test.ts`. `pnpm
139
- test` (the scaffold's own script) already runs the whole suite, and so does the
140
- gate in front of `aai build`.
136
+ **`aai test` runs every non-eval spec in the project**, which `--only` narrows
137
+ to `agent.test.ts` for the fast inner loop. A narrowed run does not report
138
+ itself as a pass: it names the spec files it did not cover and answers
139
+ `complete: false`. `pnpm test` (the scaffold's own script) is `aai test`, and so
140
+ is the gate in front of `aai build`.
141
141
 
142
142
  ## Running it yourself (`npm start`)
143
143
 
@@ -312,6 +312,8 @@ export default agent({
312
312
  // all four types are on "@alexkroman1/aai",
313
313
  // and on their own stage subpath
314
314
  sttPrompt?: string; // STT guidance for jargon/acronyms
315
+ voicePresets?: VoicePresetName[]; // opt-in prompt presets — see below; each one
316
+ // costs tokens on EVERY model request
315
317
  builtinTools?: BuiltinTool[]; // see built-in tools table
316
318
  // (there is no `tools` field — a tool is a FILE;
317
319
  // see "A file in tools/ IS a tool")
@@ -411,18 +413,12 @@ import { agent } from "@alexkroman1/aai";
411
413
  export default agent({ name: "My Agent" });
412
414
  ```
413
415
 
414
- Declare neither and the agent runs on `DEFAULT_SYSTEM_PROMPT`, exported from
415
- `@alexkroman1/aai` so you can read what you are replacing — or compose against
416
- it, rather than restating the voice rules at the bottom of this guide:
417
-
418
- ```ts
419
- import { DEFAULT_SYSTEM_PROMPT, agent } from "@alexkroman1/aai";
420
-
421
- export default agent({
422
- name: "My Agent",
423
- systemPrompt: `${DEFAULT_SYSTEM_PROMPT}\n\nYou only ever discuss pizza.`,
424
- });
425
- ```
416
+ **Your prompt is ADDED to the defaults, never a replacement** — the framework
417
+ emits its voice sections and appends yours last, yours winning on conflict.
418
+ Write ONLY your own domain rules; never interpolate `DEFAULT_SYSTEM_PROMPT`
419
+ (exported to be READ). Nothing is replaced, so composing sends ~10,000
420
+ characters twice a turn; a leading copy is dropped with a warning, one
421
+ elsewhere is sent.
426
422
 
427
423
  ```markdown
428
424
  <!-- system-prompt.md -->
@@ -1394,9 +1390,7 @@ bridge transcodes in both directions, so the agent, its tools and its slots
1394
1390
  behave exactly as they do in the browser — a phone call is a transport, not a
1395
1391
  mode. Nothing else about `agent.ts` changes to support one.
1396
1392
 
1397
- **An agent that declares nothing answers no carrier**, which is a change from
1398
- earlier releases: every voice agent used to serve both carriers' framing from
1399
- the moment it booted, whether or not it had a phone number. `/phone` is the one
1393
+ **An agent that declares nothing answers no carrier.** `/phone` is the one
1400
1394
  door dialled from OUTSIDE your deployment, by a carrier following a number, so
1401
1395
  it is opened by a sentence in `agent.ts` rather than inherited. `aai dev` and a
1402
1396
  deployed sandbox honour the same declaration, so a call refused after a deploy
@@ -2118,10 +2112,8 @@ before this subpath existed.
2118
2112
 
2119
2113
  ## Persisting data — bring your own client
2120
2114
 
2121
- **There is no `ctx.db`.** It was a SQL handle on the tool context, backed first
2122
- by a Postgres the platform provisioned per app and later by a `DATABASE_URL` an
2123
- author set. The platform provisions no database, and no longer hands tool code
2124
- one either.
2115
+ **There is no `ctx.db`.** The platform provisions no database and hands tool
2116
+ code none.
2125
2117
 
2126
2118
  So a tool that needs to persist anything uses a client of its own:
2127
2119
 
@@ -2448,14 +2440,24 @@ Never hardcode secrets in agent code.
2448
2440
 
2449
2441
  ## Voice rules for systemPrompt
2450
2442
 
2451
- - Short, punchy sentences — optimize for speech, not text
2452
- - Never mention "search results" or "sources" — speak as if knowledge is
2453
- your own
2454
- - No visual formatting (bullets, bold) — use "First", "Next", "Finally"
2455
- - Lead with the most important information
2456
- - Keep answers to 1-3 sentences
2457
- - No exclamation points — calm, conversational tone
2458
- - No hedging ("It seems that", "I believe")
2443
+ **Don't restate the voice rules — the framework always emits them** (read
2444
+ `DEFAULT_SYSTEM_PROMPT`; your own prompt is APPENDED to it). Write only what
2445
+ the defaults cannot say: "use run_code for ANY math", "you ARE the game".
2446
+ "Search first" and "don't guess" they already say.
2447
+
2448
+ ### Opt-in prompt presets
2449
+
2450
+ `agent({ voicePresets: ["echoVerification", "natoAlphabet"] })` switches on
2451
+ named behaviours instead of writing them. They compose, each is removable on
2452
+ its own, and each is paid for on EVERY model request: `echoVerification`
2453
+ (~190 tokens — read critical values back and get a yes), `speechNormalization`
2454
+ (~920 — money, dates, phone numbers and emails as spoken words, `"$758.08"`
2455
+ as "seven fifty-eight dollars and eight cents") and `natoAlphabet` (~190 —
2456
+ "That's B as in Bravo, 7, K as in Kilo, 2 — correct?"). `VOICE_PRESETS` holds
2457
+ the exact text. The two spelling presets override the default "don't spell
2458
+ things back", so use them where a wrong value costs more than a slow call;
2459
+ `speechNormalization` is the PROMPT layer only, and for the agent's OWN data
2460
+ the renderers below do it in code for free.
2459
2461
 
2460
2462
  **Speech goes both ways, and `@alexkroman1/aai` publishes both conversions.**
2461
2463
  Inbound: `spokenDigits("four one five")` is `"415"`, `spokenOrdinal("the third
@@ -2464,7 +2466,7 @@ phrase meant — answering a `ToolFailure` when nothing matches or several do, t
2464
2466
  case a hand-written `.find()` gets wrong.
2465
2467
 
2466
2468
  Outbound: an engine handed `$240.50` may read "dollar sign two hundred forty
2467
- point five zero", and `19:30` as "nineteen thirty" — right text, wrong call.
2469
+ point five zero" — right text, wrong call.
2468
2470
  Render the words first: `spokenMoney(240.5)` is `"240 dollars and 50 cents"`,
2469
2471
  `spokenDate("2026-06-08")` is `"Monday, June 8"`, `spokenTime("18:30")` is
2470
2472
  `"6:30 PM"`. `mintCode("HTL")` mints a reference with no `0`/`O`, `1`/`I` or
@@ -2481,19 +2483,9 @@ substitute, so a dice roll or a minted code is something a spec can assert.
2481
2483
  `randomInt`, `pickOne` and `shuffled` take it last. A WORKFLOW body wants its
2482
2484
  own journaled `ctx.random()` instead.
2483
2485
 
2484
- Patterns by agent type:
2485
-
2486
- - **Code execution:** "You MUST use run_code for ANY math, counting, or
2487
- data processing. NEVER do mental math."
2488
- - **Research:** "Search first. Never guess or rely on memory for factual
2489
- questions."
2490
- - **FAQ/support:** "Base answers strictly on your knowledge — don't guess."
2491
- - **Game/interactive:** "You ARE the game. Keep descriptions to 2-4
2492
- sentences. No visual formatting."
2493
-
2494
2486
  ## Gotchas
2495
2487
 
2496
- Common mistakes when working in aai projects:
2488
+ Common mistakes when working in agent projects:
2497
2489
 
2498
2490
  - **Tool execute must return a value.** A missing return = `undefined` in
2499
2491
  LLM context = the model thinks the tool failed.
@@ -2513,20 +2505,15 @@ Common mistakes when working in aai projects:
2513
2505
  `client.tsx`. Missing this = unstyled UI.
2514
2506
  - **Don't create `tailwind.config.js`.** Tailwind v4 is configured via
2515
2507
  CSS; the config file is ignored.
2516
- - **Voice prompts ≠ chat prompts.** No bullets, no bold, no exclamation
2517
- points. See "Voice rules" above.
2518
2508
  - **`fetch` to private IPs is blocked** (SSRF protection). Use public URLs.
2519
2509
  - **`run_code` only executes on the deployed platform.** It runs inside the
2520
2510
  platform's Modal/Deno sandbox; the self-hosted `aai dev` server has no
2521
2511
  sandbox, so there `run_code` refuses with an error result. Deploy to test
2522
2512
  it end-to-end, or use the `calculate` builtin for simple arithmetic in dev.
2523
- - **There is no `ctx.db`.** The platform provisions no database and hands tool
2524
- code none, so a tool that persists brings its own client — see "Persisting
2525
- data". Two consequences worth knowing before you do: a deployed agent reads a
2526
- secret when its sandbox is BUILT, so a newly set `DATABASE_URL` reaches it on
2527
- the next deploy rather than immediately; and a database you bring is shared by
2528
- every session of the deployment, so key rows yourself if sessions must not see
2529
- each other's data (or keep session-scoped data in a `sessionSlot`).
2513
+ - **There is no `ctx.db`.** A tool that persists brings its own client — see
2514
+ "Persisting data". A secret is read when the sandbox is BUILT, so a newly set
2515
+ `DATABASE_URL` arrives on the next deploy rather than immediately, and the
2516
+ database is shared by every session, so key rows yourself.
2530
2517
  - **Rime language codes are ISO 639-3** (3-letter, e.g. `"eng"`), not
2531
2518
  ISO 639-1 (`"en"`).
2532
2519
 
@@ -9,16 +9,16 @@
9
9
  "prestart": "aai build --skip-tests",
10
10
  "start": "aai start",
11
11
  "build": "aai build",
12
- "test": "vitest run --exclude \"**/*.eval.test.*\"",
13
- "test:agent": "aai test",
12
+ "test": "aai test",
13
+ "test:agent": "aai test --only",
14
14
  "eval": "aai eval",
15
15
  "publish:agent": "aai publish"
16
16
  },
17
17
  "dependencies": {
18
- "@alexkroman1/aai": "^16.1.0",
19
- "@alexkroman1/aai-cli": "^16.1.0",
20
- "@alexkroman1/aai-runtime": "^16.1.0",
21
- "@alexkroman1/aai-ui": "^16.1.0",
18
+ "@alexkroman1/aai": "^17.0.0",
19
+ "@alexkroman1/aai-cli": "^17.0.0",
20
+ "@alexkroman1/aai-runtime": "^17.0.0",
21
+ "@alexkroman1/aai-ui": "^17.0.0",
22
22
  "react": "^19.2.8",
23
23
  "react-dom": "^19.2.8",
24
24
  "tailwindcss": "^4.0.0",
@@ -3,7 +3,35 @@ import react from "@vitejs/plugin-react";
3
3
  import { defineConfig } from "vite";
4
4
 
5
5
  export default defineConfig({
6
- plugins: [react(), tailwindcss()],
6
+ plugins: [
7
+ react({
8
+ // React Fast Refresh makes any module that DECLARES a component a
9
+ // boundary, but can only refresh one whose every EXPORT is a component.
10
+ // A module that is a boundary and cannot be refreshed is the worst case:
11
+ // it gets re-executed, and only then discarded for a page reload. Two
12
+ // kinds of file here are exactly that, and both must be named because
13
+ // passing `exclude` replaces the plugin's default — hence node_modules
14
+ // below, which is that default.
15
+ //
16
+ // `dist/`: a prebuilt dependency. A bundled chunk mixes components with
17
+ // constants, so it can never be a valid boundary. The node_modules
18
+ // default normally hides this, and does NOT when a package is LINKED,
19
+ // because the symlink resolves to a real path outside node_modules.
20
+ // Measured against a linked `@alexkroman1/aai-ui`: one rebuild of it
21
+ // produced 33 partial updates, 12 invalidations and 8 throws of "Session
22
+ // hooks must be used within <SessionProvider>" — a re-executed context
23
+ // module mints a fresh context while the mounted tree holds the old one.
24
+ //
25
+ // `client.tsx`: the entry MOUNTS. Re-executing it is a second
26
+ // `mountClient()` on the same element ("ReactDOMClient.createRoot() on a
27
+ // container that has already been passed to createRoot()"), and since it
28
+ // exports nothing it could never have refreshed anyway. Excluded, an edit
29
+ // to it is one clean page reload — and a component in its OWN file still
30
+ // fast-refreshes, which is the reason to put it there.
31
+ exclude: [/\/node_modules\//, /\/dist\//, /\/client\.tsx$/],
32
+ }),
33
+ tailwindcss(),
34
+ ],
7
35
  build: {
8
36
  target: "es2022",
9
37
  minify: true,
@@ -5,7 +5,7 @@ import { l as formatCappedList } from "./_utils-D5JGcjiW.mjs";
5
5
  import { s as updateProjectConfig } from "./_config-DYzC6WMD.mjs";
6
6
  import { i as resolveServerEnv } from "./_server-common-DAcv1nC5.mjs";
7
7
  import { o as resolveDeployTarget } from "./_agent-BzUeqOdj.mjs";
8
- import { layerScaffold } from "./_templates-CuP74F8D.mjs";
8
+ import { layerScaffold } from "./_templates-IMeKMVIj.mjs";
9
9
  import { a as publishStudioProject, c as studioProjectUrl, f as checkedResponse, i as projectNameFromDir, n as fetchStudioProject, o as pushStudioSource, r as listStudioProjects, s as studioProjectApiUrl, t as collectSourceFiles, u as apiRequest } from "./_studio-DnR_BqFp.mjs";
10
10
  import { existsSync } from "node:fs";
11
11
  import path from "node:path";
@@ -145,10 +145,23 @@ async function executePush(opts) {
145
145
  });
146
146
  }
147
147
  /**
148
- * Mirror `.env` into the deployed agent's secrets (the same `/:slug/secret`
149
- * routes `aai secret` uses). Secrets are merged into the agent env at
150
- * deploy time, which is why publish syncs them BEFORE deploying when the
151
- * slug is already known.
148
+ * Mirror `.env` into the project's secrets, which is what makes this callable
149
+ * BEFORE anything has been deployed.
150
+ *
151
+ * The route is the PROJECT's (`/studio/projects/:project/secret`), and that is
152
+ * the whole reason publish syncs unconditionally rather than only once a slug
153
+ * exists. A project holds its own secret record — `studio-secrets.ts` argues
154
+ * it, and the argument is exactly this failure: writing only to the slugs that
155
+ * exist forces "deploy it broken, then attach the key, then deploy again",
156
+ * which was the shortest path to a working agent and is not an order anybody
157
+ * should have to learn. `reconcileProjectSecrets` is wired as the broker's
158
+ * post-deploy hook and FLOORS a newly minted slug from that record, so the
159
+ * deploy this call precedes picks the values up as it claims its slug — and
160
+ * the preview agent, auto-deployed on the first edit, gets them too.
161
+ *
162
+ * Only the project row has to exist, and `pushProject` has already created it:
163
+ * server-side, a project with nothing deployed resolves to an empty target set
164
+ * and the record write is the whole operation.
152
165
  */
153
166
  async function syncEnvSecrets(cwd, serverUrl, apiKey, project) {
154
167
  const env = await resolveServerEnv(cwd);
@@ -168,7 +181,7 @@ async function executePublish(opts) {
168
181
  await assertTypechecks(opts.cwd, { skip: opts.skipTypecheck });
169
182
  const pushed = await pushProject(opts);
170
183
  const { project, serverUrl, apiKey } = pushed;
171
- if (pushed.slug) await syncEnvSecrets(opts.cwd, serverUrl, apiKey, project);
184
+ await syncEnvSecrets(opts.cwd, serverUrl, apiKey, project);
172
185
  log.step(`Publishing ${project} (builds in the project's sandbox)…`);
173
186
  const result = checkedResponse(await publishStudioProject(serverUrl, apiKey, project, { skipTypecheck: opts.skipTypecheck }), (value) => isRecord(value) && typeof value.slug === "string" && typeof value.output === "string", `the publish route at ${serverUrl}`);
174
187
  if (result.output.trim()) log.message(result.output.trim());
@@ -176,9 +189,6 @@ async function executePublish(opts) {
176
189
  serverUrl,
177
190
  slug: result.slug
178
191
  });
179
- if (!pushed.slug) {
180
- if ((await syncEnvSecrets(opts.cwd, serverUrl, apiKey, result.slug)).length > 0) log.info("They apply on the next `aai publish`.");
181
- }
182
192
  const agentUrl = `${serverUrl}/${result.slug}`;
183
193
  const studioUrl = studioProjectUrl(serverUrl, project);
184
194
  log.success(`Published ${fmtUrl(agentUrl)}`);
@@ -28,6 +28,7 @@ import { countWords } from "@alexkroman1/aai/utils";
28
28
  import {
29
29
  describeTurn,
30
30
  type EvalSession,
31
+ expectCalled,
31
32
  lastStateIn,
32
33
  toolNames,
33
34
  toolResultIn,
@@ -165,7 +166,11 @@ describeEval(agentDef, (test) => {
165
166
  // The browser was sent the whole table, not the three the caller heard.
166
167
  const view = hiringState(session);
167
168
  expect(view?.leaderboard).toHaveLength(LEADS.length);
168
- expect(view?.jobTitle).toBe("Junior React Developer");
169
+ // CONTAINS, not equals: the title is whatever the desk passed through from
170
+ // the caller, who said "the Junior React Developer contract" — so a model
171
+ // that carried the word "contract" across was being faithful, and pinning
172
+ // the exact string failed it for that.
173
+ expect(view?.jobTitle).toContain("Junior React Developer");
169
174
  // Nothing outside the desk's own six tools was called: the evaluator is a
170
175
  // `ctx.generate` inside a tool, never a tool the desk holds.
171
176
  expect(toolNames(turn.toolCalls).filter((name) => !DESK_TOOLS.includes(name))).toEqual([]);
@@ -190,11 +195,20 @@ describeEval(agentDef, (test) => {
190
195
  const calls = turn.toolCalls.filter((call) => call.name === "screen_candidates");
191
196
  expect(calls, describeTurn(turn)).toHaveLength(1);
192
197
  const screened = toolResultIn(turn.toolCalls, "screen_candidates", Screened);
193
- // Their "don't use numbers like 100, 75, or 50" rule, measured: a live
194
- // evaluator that ties three applicants at 75 has produced a list, not a
195
- // ranking, and the desk cannot read back "who stands out" from a tie.
198
+ // Their "don't use numbers like 100, 75, or 50" rule, measured — but only
199
+ // as far as the rule can reach. Each candidate is a SEPARATE
200
+ // `ctx.generate` that never sees the others' numbers, so two independent
201
+ // evaluations landing on the same score is arithmetic rather than a
202
+ // failure, and demanding all three distinct failed this case on a 2-of-3
203
+ // collision. What the rule actually buys is numbers specific enough that
204
+ // the sort is a RANKING and not the three-way tie at 75 it was written
205
+ // against.
196
206
  const scores = screened.top.map((one) => one.score);
197
- expect(new Set(scores).size).toBe(scores.length);
207
+ expect(new Set(scores).size, JSON.stringify(scores)).toBeGreaterThan(1);
208
+ for (const score of scores) expect([50, 75, 100]).not.toContain(score);
209
+ // And the read-back order IS those numbers sorted — not the desk's own
210
+ // view of twelve bios.
211
+ expect([...scores].sort((a, b) => b - a)).toEqual(scores);
198
212
  for (const one of screened.top) expect(one.reason.length).toBeGreaterThan(30);
199
213
  // What the caller HEARS names the evaluator's top pick. A desk that read
200
214
  // twelve bios and formed its own view would name whoever it fancied.
@@ -221,7 +235,7 @@ describeEval(agentDef, (test) => {
221
235
  // it has no scores of its own to re-order by — and it must not screen from
222
236
  // scratch, which would throw the ranking the caller just heard away.
223
237
  const names = toolNames(turn.toolCalls);
224
- expect(names, describeTurn(turn)).toContain("rescore_with_feedback");
238
+ expectCalled(turn, "rescore_with_feedback");
225
239
  expect(names).not.toContain("screen_candidates");
226
240
  const rescored = toolResultIn(turn.toolCalls, "rescore_with_feedback", Rescored);
227
241
  expect(rescored.state).toBe("reviewing");
@@ -29,6 +29,34 @@ import { hiringProjection } from "./shared.ts";
29
29
  */
30
30
  export default agent({
31
31
  name: "Hiring Desk",
32
+ description:
33
+ "Screens a stack of applicants against a role and drafts each of them a follow-up email",
34
+ /**
35
+ * A ceiling on what one hiring call may spend.
36
+ *
37
+ * **This is the template where a budget has to cover DELEGATION, and until
38
+ * the meter did, it could not.** Almost nothing this desk spends is spent in
39
+ * the conversation: one screening round is twelve `ctx.generate({ schema })`
40
+ * calls through `scoreCandidates`, the caller may ask for up to
41
+ * `MAX_FEEDBACK_ROUNDS` more (`shared.ts`), and `proceed_to_emails` then runs twelve
42
+ * `ctx.delegate` subagents — each a full tool loop with a guardrail that may
43
+ * send an answer back. A cap that counted only the turns would bound the
44
+ * cheapest part of the call while reading as though it bounded the call;
45
+ * `UsageLimits` says which calls count, and all of the above do.
46
+ *
47
+ * The number is an ORDER OF MAGNITUDE rather than a measurement — nobody has
48
+ * run this against a real model and totalled it. It is sized from the shape:
49
+ * four scoring rounds of twelve, plus twelve emails and their revisions, plus
50
+ * the conversation around them, then multiplied to leave a legitimate call
51
+ * comfortably clear. What it catches is a desk left in a loop, not a hiring
52
+ * manager who is thorough. Pick yours from what `usage.updated` reports on a
53
+ * real screening.
54
+ *
55
+ * Reaching it ends the session at the next turn; a `ctx.generate` or
56
+ * `ctx.delegate` in between is refused with the same reason, which
57
+ * `mapSettled` reports per candidate rather than losing the whole fan-out.
58
+ */
59
+ usageLimits: { totalTokens: 750_000 },
32
60
  // The ranking, the feedback trail and the drafts' subject lines, pushed after
33
61
  // every tool call — a leaderboard is the one thing here nobody can hold by ear.
34
62
  syncState: hiringProjection,
@@ -327,21 +327,21 @@ export function describeRanked(candidate: RankedCandidate): string {
327
327
  * How a caller names one of twelve applicants — the desk's own vocabulary,
328
328
  * which is the half {@link resolveOne} does not own.
329
329
  *
330
- * A name matches on WHOLE parts: every part of the candidate's name the
331
- * utterance contains scores one, so "Priya" and "Raman" each resolve and
332
- * "Priya Raman" outscores both — a substring test would let "an" match Raman,
333
- * Tanaka and Kowalski at once. Declared as a constant rather than inline
334
- * because the annotation is what types `candidate` and `text` here; the three
335
- * tools that resolve a candidate all reach it through the one function below.
330
+ * A name matches on WHOLE parts, which is `resolveOne`'s `match`: every part of
331
+ * the candidate's name the utterance also says scores one, so "Priya" and
332
+ * "Raman" each resolve and "Priya Raman" outscores both. The hand-written
333
+ * version this replaces argued for exactly that and did not deliver it — it
334
+ * tested each part as a SUBSTRING of the utterance with a two-character floor,
335
+ * which is the shape that lets "an" match Raman, Tanaka and Kowalski at once.
336
+ * It also split on whitespace, so `Liam O'Connor` matched only an utterance
337
+ * STT punctuated identically. Declared as a constant rather than inline
338
+ * because the annotation is what types `candidate` here; the three tools that
339
+ * resolve a candidate all reach it through the one function below.
336
340
  */
337
341
  const CANDIDATE_MATCH: ResolveOneOptions<RankedCandidate> = {
338
342
  label: "candidate",
339
343
  describe: describeRanked,
340
- score: (candidate, text) =>
341
- candidate.name
342
- .toLowerCase()
343
- .split(/\s+/)
344
- .filter((part) => part.length > 1 && text.includes(part)).length,
344
+ match: (candidate) => candidate.name,
345
345
  };
346
346
 
347
347
  /**
@@ -147,6 +147,8 @@ export const audit: WorkflowDef<typeof auditInput, CallAudit> = workflow({
147
147
 
148
148
  export default workflowApp({
149
149
  name: "Call Audit",
150
+ description:
151
+ "Turns a recorded call into a written and spoken audit — headline, risks and follow-up actions",
150
152
  workflows: { audit },
151
153
  // Checked at deploy time, so a missing key is a warning naming it rather than a run
152
154
  // that fails on its third step. A workflow app declares no providers, so this is the
@@ -29,6 +29,7 @@ import agentDef from "virtual:aai/agent";
29
29
  import {
30
30
  createVmRunCode,
31
31
  describeTurn,
32
+ expectCalled,
32
33
  expectToolBeforeSpeech,
33
34
  type RunCodeExecutor,
34
35
  runCodeIn,
@@ -82,7 +83,7 @@ describeEval(
82
83
  // The template's CRITICAL RULE, and the whole reason it declares
83
84
  // run_code: a model that answers this one directly has regressed, and it
84
85
  // is the easiest question in the file to answer wrongly with confidence.
85
- expect(toolNames(turn.toolCalls), describeTurn(turn)).toContain("run_code");
86
+ expectCalled(turn, "run_code");
86
87
  const code = runCodeIn(turn.toolCalls);
87
88
  expect(code).toContain("127");
88
89
  expect(code).toContain("849");
@@ -110,7 +111,7 @@ describeEval(
110
111
  // The prompt lists this exact question under "you MUST use code for".
111
112
  // It is the case a narrower reading of the rule ("code is for maths")
112
113
  // silently drops.
113
- expect(toolNames(turn.toolCalls), describeTurn(turn)).toContain("run_code");
114
+ expectCalled(turn, "run_code");
114
115
  expect(runCodeIn(turn.toolCalls)).toMatch(/Date|2000/);
115
116
  // The code RAN rather than being refused (`runCodeOutput` throws on the
116
117
  // refusal) — but the ANSWER is deliberately not asserted here, and the
@@ -2,6 +2,7 @@ import { agent } from "@alexkroman1/aai";
2
2
 
3
3
  export default agent({
4
4
  name: "Coda",
5
+ description: "Answers questions by writing and running code",
5
6
  greeting:
6
7
  "Hey, I'm Coda. I solve problems by writing and running code. Try asking me something like, what's the 50th fibonacci number, or what day of the week was January 1st 2000.",
7
8
  builtinTools: ["run_code"],
@@ -0,0 +1,136 @@
1
+ // An EVAL: does the agent actually behave? Run it with `aai eval`.
2
+ //
3
+ // A test asserts about the config and the tools (see agent.test.ts — it never
4
+ // calls a model). An eval drives the real thing: a real `createTextAgent`, the
5
+ // real tool executor, the real event stream, over a real directory on disk.
6
+ //
7
+ // `describeTextEval` is `describeEval`'s text-mode sibling — the same two modes
8
+ // and the same announce line, over `openEvalTextAgent` rather than a session,
9
+ // because `createRuntime` refuses a text agent by name:
10
+ //
11
+ // * with a provider key — a LIVE model. This spends tokens, takes a few
12
+ // seconds a case, and is a NOISY instrument: one failure is a question, not
13
+ // a verdict.
14
+ // * without one — a SCRIPTED model answering each case's `stubReply`. The
15
+ // agent, its tools and this file all really run, and the files really
16
+ // change, so what it proves is that the wiring works. It proves nothing
17
+ // about what the model CHOSE.
18
+ //
19
+ // The claims below are all about tool CHOICE — did it look before it edited,
20
+ // did it edit rather than rewrite — because that is what a coding agent's
21
+ // system prompt is for and the only thing a transcript cannot show you.
22
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
23
+ import path from "node:path";
24
+ import agentDef from "virtual:aai/agent";
25
+ import { toolNames } from "@alexkroman1/aai-runtime/eval";
26
+ import { describeTextEval } from "@alexkroman1/aai-runtime/eval/vitest";
27
+ import { beforeEach, expect, vi } from "vitest";
28
+
29
+ const workspace = vi.hoisted(() => {
30
+ // Hoisted above the imports, because `shared.ts` reads this once at module
31
+ // scope — see the same note in `agent.test.ts`.
32
+ const root = process.env.TMPDIR ?? process.env.TMP ?? "/tmp";
33
+ const dir = `${root}/coding-agent-eval-${process.pid}`;
34
+ process.env.WORKSPACE_DIR = dir;
35
+ return dir;
36
+ });
37
+
38
+ /** The tiny project each case gets a fresh copy of. */
39
+ beforeEach(() => {
40
+ rmSync(workspace, { recursive: true, force: true });
41
+ mkdirSync(workspace, { recursive: true });
42
+ writeFileSync(
43
+ path.join(workspace, "cart.ts"),
44
+ "export function total(prices: number[]): number {\n" +
45
+ " return prices.reduce((sum, price) => sum + price, 0);\n" +
46
+ "}\n",
47
+ "utf-8",
48
+ );
49
+ writeFileSync(path.join(workspace, "README.md"), "# Shop\n\nA very small shop.\n", "utf-8");
50
+ });
51
+
52
+ const read = (rel: string): string => readFileSync(path.join(workspace, rel), "utf-8");
53
+
54
+ describeTextEval(agentDef, (test) => {
55
+ test(
56
+ "answers a question about the code by READING it, and changes nothing",
57
+ async ({ agent }) => {
58
+ const turn = await agent.send("what does total() in cart.ts do?");
59
+
60
+ // The finding this case exists for: an agent that answers from the name
61
+ // alone sounds exactly like one that read the file.
62
+ expect(toolNames(turn.toolCalls)).toContain("read_file");
63
+ expect(turn.text).toMatch(/sum|add|total/i);
64
+ // A question is not a change. Any write here is a real finding.
65
+ expect(toolNames(turn.toolCalls)).not.toContain("write_file");
66
+ expect(toolNames(turn.toolCalls)).not.toContain("edit_file");
67
+ expect(read("cart.ts")).toContain("reduce");
68
+ },
69
+ {
70
+ stubReply: [
71
+ { tool: "read_file", args: { path: "cart.ts" } },
72
+ "It sums an array of prices and returns the total.",
73
+ ],
74
+ },
75
+ );
76
+
77
+ test(
78
+ "edits the file rather than rewriting it, and the change lands on disk",
79
+ async ({ agent }) => {
80
+ const turn = await agent.send("rename the `sum` parameter in cart.ts to `running`");
81
+
82
+ expect(toolNames(turn.toolCalls)).toContain("edit_file");
83
+ // `write_file` would also produce a correct file, and it is the shape
84
+ // that silently drops the code a model forgot to repeat — which is the
85
+ // whole reason the prompt names `edit_file` as the primary tool.
86
+ expect(toolNames(turn.toolCalls)).not.toContain("write_file");
87
+ expect(read("cart.ts")).toContain("running");
88
+ expect(read("cart.ts")).not.toContain("sum");
89
+ },
90
+ {
91
+ stubReply: [
92
+ { tool: "read_file", args: { path: "cart.ts" } },
93
+ {
94
+ tool: "edit_file",
95
+ args: {
96
+ path: "cart.ts",
97
+ oldText: "(sum, price) => sum + price",
98
+ newText: "(running, price) => running + price",
99
+ replaceAll: false,
100
+ },
101
+ },
102
+ "Renamed it.",
103
+ ],
104
+ },
105
+ );
106
+
107
+ test(
108
+ "finds a symbol with a SEARCH rather than by reading the tree",
109
+ async ({ agent }) => {
110
+ const turn = await agent.send("where is total defined?");
111
+
112
+ // Either search tool is a right answer; reading every file is not, and
113
+ // on a real repository it is the difference between one call and fifty.
114
+ expect(toolNames(turn.toolCalls).some((name) => name === "grep" || name === "glob")).toBe(
115
+ true,
116
+ );
117
+ expect(turn.text).toContain("cart.ts");
118
+ },
119
+ {
120
+ // A live model may reach for either; the script picks one so the case
121
+ // still runs, and the assertion above stays true of both.
122
+ stubReply: [{ tool: "grep", args: { pattern: "function total" } }, "In cart.ts, line 1."],
123
+ },
124
+ );
125
+
126
+ test(
127
+ "runs a command when asked, instead of describing one",
128
+ async ({ agent }) => {
129
+ const turn = await agent.send("how many lines does cart.ts have? use the shell");
130
+
131
+ expect(toolNames(turn.toolCalls)).toContain("bash");
132
+ expect(turn.text).toMatch(/3/);
133
+ },
134
+ { stubReply: [{ tool: "bash", args: { command: "wc -l < cart.ts" } }, "3 lines."] },
135
+ );
136
+ });