@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
@@ -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,
package/dist/start.d.ts CHANGED
@@ -46,7 +46,7 @@ export { CLIENT_ARTIFACT_REL } from "./_artifacts.ts";
46
46
  /** The port `aai start` binds when neither an argument nor `PORT` says otherwise. */
47
47
  export declare const DEFAULT_START_PORT = 3000;
48
48
  /** Options for {@link createProjectServer} and {@link executeStart}. */
49
- export interface StartOptions {
49
+ export interface ProjectServerOptions {
50
50
  /** Project root — the directory holding `agent.ts` and `.aai/`. */
51
51
  cwd: string;
52
52
  /** Port to bind. Defaults to `PORT`, then {@link DEFAULT_START_PORT}. */
@@ -91,7 +91,7 @@ export declare function loadBuiltAgent(cwd: string): Promise<AgentDef>;
91
91
  * }
92
92
  * ```
93
93
  */
94
- export declare function createProjectServer(options: StartOptions): Promise<AgentServer>;
94
+ export declare function createProjectServer(options: ProjectServerOptions): Promise<AgentServer>;
95
95
  /** What {@link executeStart} answers, for `--json` and for tests. */
96
96
  export interface StartResult {
97
97
  ok: true;
@@ -109,4 +109,4 @@ export interface StartResult {
109
109
  * rejected would surface as an unhandled rejection, i.e. a crash with a stack
110
110
  * trace on Ctrl-C, instead of the non-zero exit a failed shutdown should be.
111
111
  */
112
- export declare function executeStart(options: StartOptions): Promise<StartResult>;
112
+ export declare function executeStart(options: ProjectServerOptions): Promise<StartResult>;
@@ -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-DXadVNsL.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");
@@ -23,7 +23,7 @@ import {
23
23
  crewAgentPrompt,
24
24
  crewExpectedOutput,
25
25
  EMAIL_FOLLOWUP_AGENT,
26
- EMAIL_GUARDRAIL_RETRIES,
26
+ EMAIL_GUARDRAIL_REVISIONS,
27
27
  EVALUATOR_SYSTEM,
28
28
  emailGuardrail,
29
29
  emailTask,
@@ -125,19 +125,23 @@ interface Script {
125
125
  function scriptedDesk(script: Script = {}) {
126
126
  const scripted = scriptedToolContext({
127
127
  generate: {
128
- [EVALUATOR_SYSTEM]: (call: StubGenerateCall) => {
129
- const id = candidateIdIn(call.prompt);
130
- if (script.failScoring?.includes(id)) throw new Error(`gateway said no for ${id}`);
131
- const table = script.scores ?? SCORES;
132
- return { object: { score: table[id] ?? 50, reason: `Scripted reasoning for ${id}.` } };
128
+ routes: {
129
+ [EVALUATOR_SYSTEM]: (call: StubGenerateCall) => {
130
+ const id = candidateIdIn(call.prompt);
131
+ if (script.failScoring?.includes(id)) throw new Error(`gateway said no for ${id}`);
132
+ const table = script.scores ?? SCORES;
133
+ return { object: { score: table[id] ?? 50, reason: `Scripted reasoning for ${id}.` } };
134
+ },
133
135
  },
134
136
  },
135
137
  delegate: {
136
- "hr-coordinator": (call) => {
137
- const name = call.task.match(/^Name: (.+)$/m)?.[1] ?? "";
138
- if (script.failEmail?.includes(name)) throw new Error(`coordinator timed out on ${name}`);
139
- const reply = script.email ? script.email(call) : emailFor(call);
140
- return typeof reply === "string" ? { text: reply } : reply;
138
+ routes: {
139
+ "hr-coordinator": (call) => {
140
+ const name = call.task.match(/^Name: (.+)$/m)?.[1] ?? "";
141
+ if (script.failEmail?.includes(name)) throw new Error(`coordinator timed out on ${name}`);
142
+ const reply = script.email ? script.email(call) : emailFor(call);
143
+ return typeof reply === "string" ? { text: reply } : reply;
144
+ },
141
145
  },
142
146
  },
143
147
  });
@@ -900,8 +904,8 @@ describe("the crews", () => {
900
904
  // declaration. Pinned to the NUMBER as well as to the constant, so an SDK
901
905
  // default that moved is a decision this template makes again rather than
902
906
  // one it inherits.
903
- expect(emailWriter.maxRetries).toBe(EMAIL_GUARDRAIL_RETRIES);
904
- expect(EMAIL_GUARDRAIL_RETRIES).toBe(1);
907
+ expect(emailWriter.maxRevisions).toBe(EMAIL_GUARDRAIL_REVISIONS);
908
+ expect(EMAIL_GUARDRAIL_REVISIONS).toBe(1);
905
909
  });
906
910
 
907
911
  test("the guardrail accepts a subject line and a signature, and names what is missing", () => {
@@ -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,
@@ -51,7 +51,7 @@
51
51
  */
52
52
 
53
53
  import {
54
- DEFAULT_GUARDRAIL_MAX_RETRIES,
54
+ DEFAULT_GUARDRAIL_MAX_REVISIONS,
55
55
  type DelegateFn,
56
56
  type DelegateResult,
57
57
  type GenerateFn,
@@ -311,7 +311,7 @@ export const emailGuardrail: SubagentGuardrail = ({ text }) => {
311
311
  * What a complaint buys the coordinator: one more run, and no more.
312
312
  *
313
313
  * CrewAI's task `guardrail` retries three times; the SDK's default is
314
- * {@link DEFAULT_GUARDRAIL_MAX_RETRIES}, which is one, and one is the right
314
+ * {@link DEFAULT_GUARDRAIL_MAX_REVISIONS}, which is one, and one is the right
315
315
  * budget on a phone. A retry is another run of the coordinator inside a
316
316
  * twelve-email fan-out the caller is holding the line through, and the two
317
317
  * things this guardrail checks — a subject line, a signature — are ones a model
@@ -322,7 +322,7 @@ export const emailGuardrail: SubagentGuardrail = ({ text }) => {
322
322
  * Written out rather than inherited, because a retry budget nobody can see at
323
323
  * the declaration is a budget nobody decided.
324
324
  */
325
- export const EMAIL_GUARDRAIL_RETRIES = DEFAULT_GUARDRAIL_MAX_RETRIES;
325
+ export const EMAIL_GUARDRAIL_REVISIONS = DEFAULT_GUARDRAIL_MAX_REVISIONS;
326
326
 
327
327
  /**
328
328
  * Their `LeadResponseCrew`: `email_followup_agent` running
@@ -337,7 +337,7 @@ export const emailWriter = subagent({
337
337
  systemPrompt: crewAgentPrompt(EMAIL_FOLLOWUP_AGENT),
338
338
  expectedOutput: EMAIL_EXPECTED_OUTPUT,
339
339
  guardrail: emailGuardrail,
340
- maxRetries: EMAIL_GUARDRAIL_RETRIES,
340
+ maxRevisions: EMAIL_GUARDRAIL_REVISIONS,
341
341
  maxSteps: 1,
342
342
  });
343
343
 
@@ -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
@@ -39,8 +39,8 @@ describe("code-interpreter-agent template", () => {
39
39
  test("run_code survives into the config a deploy carries", () => {
40
40
  // The template's whole capability, asserted on the CONFIG rather than the
41
41
  // def because that is what a deploy ships. `DEFAULT_BUILTIN_TOOLS` is
42
- // EMPTY — a builtin is something an agent asks for, never something it has
43
- // to notice and switch off — so a dropped `builtinTools` is not a degraded
42
+ // `think` alone — every other builtin is something an agent asks for — so
43
+ // a dropped `builtinTools` is not a degraded
44
44
  // Coda, it is an agent whose prompt forbids mental arithmetic and leaves it
45
45
  // nothing else to do. Adding builtins beside it is fine; losing this one is
46
46
  // the regression.
@@ -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
+ });
@@ -0,0 +1,109 @@
1
+ /**
2
+ * What this template CAN and CANNOT reach.
3
+ *
4
+ * A coding agent's tools take a path from a model, so the claims worth pinning
5
+ * are about the boundary: what `WORKSPACE_DIR` selects, that nothing outside it
6
+ * is reachable by any of the nine, and that a failure comes back as a sentence
7
+ * the model can act on rather than as a thrown `ENOENT`. The behaviour of each
8
+ * tool is the SDK's and is covered there; what belongs to this template is the
9
+ * wiring.
10
+ *
11
+ * `vi.hoisted` runs before the imports below, which is the only way to point
12
+ * `shared.ts` at a scratch directory: it reads the variable once, at module
13
+ * scope, so a `beforeEach` would be far too late.
14
+ */
15
+
16
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
17
+ import path from "node:path";
18
+ import agentDef from "virtual:aai/agent";
19
+ import { expectDeployable, toolRunner } from "@alexkroman1/aai/testing";
20
+ import { afterAll, beforeEach, describe, expect, test, vi } from "vitest";
21
+ import { WORKSPACE_DIR } from "./shared.ts";
22
+
23
+ const workspace = vi.hoisted(() => {
24
+ // Hoisted above the imports, so it cannot use `node:os` — the temp root is
25
+ // read the way `os.tmpdir()` reads it. The directory need not exist yet:
26
+ // `shared.ts` records the path and touches nothing until a tool runs.
27
+ const root = process.env.TMPDIR ?? process.env.TMP ?? "/tmp";
28
+ const dir = `${root}/coding-agent-template-${process.pid}`;
29
+ process.env.WORKSPACE_DIR = dir;
30
+ return dir;
31
+ });
32
+
33
+ afterAll(() => {
34
+ rmSync(workspace, { recursive: true, force: true });
35
+ });
36
+
37
+ const run = toolRunner(agentDef);
38
+
39
+ beforeEach(() => {
40
+ mkdirSync(workspace, { recursive: true });
41
+ writeFileSync(path.join(workspace, "cart.ts"), "export const total = 1;\n", "utf-8");
42
+ });
43
+
44
+ describe("coding-agent template", () => {
45
+ test("is deployable, and is a TEXT agent — no audio stage anywhere", () => {
46
+ const config = expectDeployable(agentDef);
47
+ // The mode is the template's point: `createRuntime` refuses a text agent by
48
+ // name, so this is what says it runs on `createTextAgent` instead. A
49
+ // provider triple appearing here would mean the mode had been lost.
50
+ expect(config.text).toBe(true);
51
+ expect(config.s2s).toBeUndefined();
52
+ });
53
+
54
+ test("declares the nine workspace tools, by the names the model calls", () => {
55
+ expect(Object.keys(agentDef.tools).sort()).toEqual([
56
+ "bash",
57
+ "delete_file",
58
+ "edit_file",
59
+ "glob",
60
+ "grep",
61
+ "list_files",
62
+ "read_file",
63
+ "todo_write",
64
+ "write_file",
65
+ ]);
66
+ });
67
+
68
+ test("the tools work in WORKSPACE_DIR, which is the one thing to configure", async () => {
69
+ expect(WORKSPACE_DIR).toBe(workspace);
70
+ expect(String(await run("list_files", {}))).toContain("cart.ts");
71
+ expect(String(await run("read_file", { path: "cart.ts" }))).toContain("export const total");
72
+ });
73
+
74
+ test("nothing outside the workspace is reachable, by any of the path tools", async () => {
75
+ // A traversal reads as a file that is not there — the same answer a typo
76
+ // gets, which is the recovery the model already knows.
77
+ expect(String(await run("read_file", { path: "../../etc/passwd" }))).toContain(
78
+ "Error: no such file",
79
+ );
80
+ // A WRITE that escapes THROWS rather than answering, which is deliberate:
81
+ // in a real turn the runtime's executor shapes a thrown tool into an error
82
+ // result, so the model sees a refusal it cannot mistake for a file it has
83
+ // yet to create. Here there is no executor, so the throw is what a spec
84
+ // sees.
85
+ await expect(run("write_file", { path: "../escaped.ts", content: "x" })).rejects.toThrow(
86
+ /escapes the workspace/,
87
+ );
88
+ });
89
+
90
+ test("an edit is applied to disk and reported as a diff", async () => {
91
+ const out = String(
92
+ await run("edit_file", {
93
+ path: "cart.ts",
94
+ oldText: "const total = 1;",
95
+ newText: "const total = 2;",
96
+ }),
97
+ );
98
+ expect(out).toContain("Edited cart.ts");
99
+ expect(readFileSync(path.join(workspace, "cart.ts"), "utf-8")).toBe(
100
+ "export const total = 2;\n",
101
+ );
102
+ });
103
+
104
+ test("a failed match is advice, not an exception — the agent can recover", async () => {
105
+ expect(
106
+ String(await run("edit_file", { path: "cart.ts", oldText: "nope", newText: "x" })),
107
+ ).toContain("Could not find that text");
108
+ });
109
+ });