@alexkroman1/aai-cli 17.0.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 (61) hide show
  1. package/dist/_console-audio.d.ts +17 -0
  2. package/dist/_console-session.d.ts +70 -0
  3. package/dist/{_dev-server-CLU9xjH5.mjs → _dev-server-Dtp4aAlo.mjs} +1 -1
  4. package/dist/_dev-server.d.ts +1 -0
  5. package/dist/_templates-DXadVNsL.mjs +135 -0
  6. package/dist/_templates.d.ts +11 -34
  7. package/dist/cli.mjs +27 -7
  8. package/dist/console-BsyE3DyB.mjs +422 -0
  9. package/dist/console.d.ts +37 -0
  10. package/dist/{dev-ChsrNHpK.mjs → dev-BGWU2zPP.mjs} +1 -1
  11. package/dist/{init-W-4k-lCF.mjs → init-CbOhyNYe.mjs} +1 -1
  12. package/dist/scaffold/CLAUDE.md +110 -102
  13. package/dist/scaffold/package.json +4 -4
  14. package/dist/start.d.ts +3 -3
  15. package/dist/{studio-DEAJGBXa.mjs → studio-BRJsw7lr.mjs} +1 -1
  16. package/dist/templates/applicant-screening-agent/agent.test.ts +17 -13
  17. package/dist/templates/applicant-screening-agent/crews.ts +4 -4
  18. package/dist/templates/code-interpreter-agent/agent.test.ts +2 -2
  19. package/dist/templates/coding-agent/agent.ts +1 -1
  20. package/dist/templates/custom-pipeline-agent/agent.ts +2 -2
  21. package/dist/templates/custom-pipeline-agent/modes.test.ts +4 -4
  22. package/dist/templates/custom-pipeline-agent/stages.test.ts +75 -83
  23. package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +1 -1
  24. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +1 -1
  25. package/dist/templates/executive-inbox-agent/agent.test.ts +35 -25
  26. package/dist/templates/executive-inbox-agent/calendar.test.ts +13 -7
  27. package/dist/templates/executive-inbox-agent/meeting.ts +2 -2
  28. package/dist/templates/front-desk-agent/agent.eval.test.ts +174 -0
  29. package/dist/templates/front-desk-agent/agent.test.ts +150 -0
  30. package/dist/templates/front-desk-agent/agent.ts +22 -0
  31. package/dist/templates/front-desk-agent/shared.ts +234 -0
  32. package/dist/templates/front-desk-agent/system-prompt.md +13 -0
  33. package/dist/templates/front-desk-agent/tools/verify_account.ts +41 -0
  34. package/dist/templates/hotel-reception-agent/agent.test.ts +1 -2
  35. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +1 -2
  36. package/dist/templates/medication-safety-agent/agent.test.ts +3 -4
  37. package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +68 -2
  38. package/dist/templates/push-to-talk-agent/agent.eval.test.ts +74 -0
  39. package/dist/templates/push-to-talk-agent/agent.test.ts +61 -0
  40. package/dist/templates/push-to-talk-agent/agent.ts +22 -0
  41. package/dist/templates/push-to-talk-agent/client.tsx +124 -0
  42. package/dist/templates/push-to-talk-agent/shared.ts +34 -0
  43. package/dist/templates/push-to-talk-agent/system-prompt.md +11 -0
  44. package/dist/templates/push-to-talk-agent/tools/list_notes.ts +15 -0
  45. package/dist/templates/push-to-talk-agent/tools/save_note.ts +26 -0
  46. package/dist/templates/quickstart-agent/agent.eval.test.ts +52 -0
  47. package/dist/templates/research-handoff-agent/agent.eval.test.ts +1 -1
  48. package/dist/templates/research-handoff-agent/agent.test.ts +34 -26
  49. package/dist/templates/research-planner-agent/agent.test.ts +26 -16
  50. package/dist/templates/retail-orders-agent/agent.eval.test.ts +1 -1
  51. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +87 -0
  52. package/dist/templates/roadside-assistance-agent/agent.test.ts +1 -1
  53. package/dist/templates/technical-support-agent/agent.test.ts +26 -20
  54. package/dist/templates/technical-support-agent/procedure.ts +3 -3
  55. package/dist/templates/topic-briefing-agent/agent.test.ts +38 -25
  56. package/dist/templates/topic-briefing-agent/shared.ts +10 -9
  57. package/dist/templates/travel-concierge-agent/agent.eval.test.ts +9 -7
  58. package/dist/templates/travel-concierge-agent/agent.test.ts +1 -2
  59. package/dist/templates/word-game-agent/agent.test.ts +3 -1
  60. package/package.json +4 -4
  61. package/dist/_templates-IMeKMVIj.mjs +0 -291
@@ -1,291 +0,0 @@
1
- #!/usr/bin/env node
2
- import { g as writeJson, s as errorMessage$1, u as isEexist } from "./_utils-D5JGcjiW.mjs";
3
- import { t as getMonorepoRoot } from "./_agent-BzUeqOdj.mjs";
4
- import { existsSync } from "node:fs";
5
- import path from "node:path";
6
- import { isRecord } from "@alexkroman1/aai/utils";
7
- import fs from "node:fs/promises";
8
- import { IGNORED_WORKSPACE_DIRS, isLocalOnlyFile } from "@alexkroman1/aai/workspace-files";
9
- const REPO_URL = `https://github.com/alexkroman/agent`;
10
- /**
11
- * Templates as shipped inside the published tarball, copied into `dist/` by
12
- * `bundle-templates.mjs` at build time — so this resolves to `dist/` for a
13
- * published CLI and to the (template-less) package root when running source
14
- * in the monorepo, where the branch above wins.
15
- *
16
- * They used to be fetched at `init` time with giget from
17
- * `github:alexkroman/agent/packages/aai-templates#main`. That required a
18
- * network for every `init`, and pinned templates to `main` regardless of the
19
- * CLI version the user had installed, so a template written against a newer
20
- * SDK could land in a project resolving an older one. Bundling pins the two
21
- * together by construction. It also puts the templates inside the studio's
22
- * guest sandbox, which has the CLI in its baked toolchain but no way to fetch
23
- * anything from GitHub.
24
- */
25
- function bundledTemplatesDir() {
26
- return import.meta.dirname;
27
- }
28
- /** Resolve the templates root — env override, then monorepo, then bundled. */
29
- function resolveTemplatesDir() {
30
- const override = process.env.AAI_TEMPLATES_DIR;
31
- if (override) return override;
32
- const monorepoRoot = getMonorepoRoot();
33
- if (monorepoRoot) return path.join(monorepoRoot, "packages", "aai-templates");
34
- return bundledTemplatesDir();
35
- }
36
- /**
37
- * List the shipped template names (sorted). Backs `aai templates` and the
38
- * unknown-template error, so the discoverable list and the validated list
39
- * can never drift.
40
- */
41
- async function listTemplates(root = resolveTemplatesDir()) {
42
- const templatesDir = path.join(root, "templates");
43
- let available;
44
- try {
45
- available = await fs.readdir(templatesDir, { withFileTypes: true });
46
- } catch (err) {
47
- throw new Error(`Templates directory is missing or unreadable at ${templatesDir} (incomplete @alexkroman1/aai-cli install?): ${errorMessage$1(err)}`, { cause: err });
48
- }
49
- return available.filter((e) => e.isDirectory()).map((e) => e.name).sort();
50
- }
51
- /** package.json fields merged key-by-key rather than whole. */
52
- const MERGED_MANIFEST_FIELDS = [
53
- "dependencies",
54
- "devDependencies",
55
- "scripts"
56
- ];
57
- /**
58
- * Fill a manifest's gaps from the scaffold's, `existing` always winning.
59
- *
60
- * The same rule the file layering uses, one level deeper: a top-level field
61
- * the manifest already declares is left alone, and for the three map fields
62
- * it is each ENTRY that is left alone. Per-entry matters both ways — a
63
- * workspace manifest pins its `dependencies` to exact installed versions and
64
- * must keep them, while a single agent-added `devDependencies` entry must not
65
- * shadow the whole toolchain block.
66
- *
67
- * Returns null when nothing was missing, so the common case writes no file.
68
- */
69
- function mergeScaffoldManifest(existing, scaffold) {
70
- const merged = { ...existing };
71
- let changed = false;
72
- for (const [key, value] of Object.entries(scaffold)) {
73
- const mine = merged[key];
74
- if (mine === void 0) {
75
- merged[key] = value;
76
- changed = true;
77
- continue;
78
- }
79
- if (!MERGED_MANIFEST_FIELDS.includes(key)) continue;
80
- if (!(isRecord(mine) && isRecord(value))) continue;
81
- const entries = { ...mine };
82
- for (const [dep, spec] of Object.entries(value)) {
83
- if (dep in entries) continue;
84
- entries[dep] = spec;
85
- changed = true;
86
- }
87
- merged[key] = entries;
88
- }
89
- return changed ? merged : null;
90
- }
91
- /**
92
- * Merge the scaffold's package.json UNDER the one already in `targetDir`.
93
- *
94
- * The file-level layering below can only skip a manifest that already exists,
95
- * and for `aai pull` that manifest is the studio workspace's — which declares
96
- * its runtime dependencies and nothing else. Toolchain packages are baked into
97
- * the guest sandbox, so the workspace deliberately never names them (see
98
- * aai-guest/studio-project-shape.ts); on a laptop nothing bakes them, so
99
- * `pnpm install` fetched no `vite`, no `@vitejs/plugin-react`, no
100
- * `@tailwindcss/vite`, and `aai dev` died resolving the vite.config.ts the
101
- * very same layering had just written. Completing the manifest is the same job
102
- * as completing the file tree.
103
- */
104
- async function layerScaffoldManifest(scaffoldDir, targetDir) {
105
- const target = path.join(targetDir, "package.json");
106
- const [mine, theirs] = await Promise.all([readJsonFile(target), readJsonFile(path.join(scaffoldDir, "package.json"))]);
107
- if (!(mine && theirs)) return;
108
- const merged = mergeScaffoldManifest(mine, theirs);
109
- if (merged) await writeJson(target, merged);
110
- }
111
- /** Parse a JSON file, or null when it is missing or unparseable. */
112
- async function readJsonFile(file) {
113
- try {
114
- const parsed = JSON.parse(await fs.readFile(file, "utf-8"));
115
- return isRecord(parsed) ? parsed : null;
116
- } catch {
117
- return null;
118
- }
119
- }
120
- /**
121
- * Directory holding the base scaffold — the files every project gets
122
- * underneath its template (package.json, tsconfig, `.gitignore`, …).
123
- *
124
- * The scaffold is the single definition of the self-hosted entrypoint, so a
125
- * caller needing one of its files resolves it here rather than carrying a
126
- * second copy of that file's contents.
127
- */
128
- function scaffoldDir() {
129
- return path.join(resolveTemplatesDir(), "scaffold");
130
- }
131
- /**
132
- * The project-root `CLAUDE.md` a scaffolded project gets — a POINTER at the
133
- * guide inside the resolved SDK, not a copy of it.
134
- *
135
- * `scaffold/CLAUDE.md` is the authoring guide itself: 2,533 lines and 119k
136
- * characters, sitting against the working cap `claude-md-limit.test.ts`
137
- * enforces. It has three consumers, and only one wanted the bytes in a project:
138
- * `sync-agent-guide.mjs` copies it into the `@alexkroman1/aai` tarball as
139
- * `AGENT_GUIDE.md`, `studio-prompt.ts` embeds it in the studio system prompt,
140
- * and — until this file — `fs.cp` wrote all 120KB into every `aai init`
141
- * directory. That third copy is the one that cannot be right:
142
- *
143
- * - **It is stale by design.** The SDK's own shipped skill
144
- * (`packages/aai/skills/aai/SKILL.md`) already says so in as many words:
145
- * the project copy is "correct on day one, but frozen at scaffold time —
146
- * `pnpm update @alexkroman1/aai` moves the SDK and leaves it behind. Prefer
147
- * the file above whenever the two disagree." A file whose own publisher
148
- * tells agents not to trust it is not carrying its weight.
149
- * - **An agent pays for it on every session, whether or not it is writing
150
- * agent code.** Claude Code loads a project-root `CLAUDE.md` in FULL at
151
- * launch and documents a 200-line target; this was 2,533. Splitting it
152
- * behind an `@import` would not have helped — imports are expanded at
153
- * launch too — which is why the pointer below names the path inside a FENCE,
154
- * the documented spelling for "mention, do not import". It is read on
155
- * demand, by the agent that needs it, out of the tarball the project
156
- * actually resolved.
157
- *
158
- * Nothing is lost that was not already duplicated: the guide ships in the SDK
159
- * beside the `.d.ts` files it describes, which is the copy the skill has
160
- * pointed at all along. What a project gets instead is the one thing the
161
- * 120KB could not be — version-matched.
162
- */
163
- const PROJECT_GUIDE_POINTER = `# Agent instructions
164
-
165
- This is an [aai](${REPO_URL}) voice-agent project. An agent is a directory
166
- containing \`agent.ts\`; the \`aai\` CLI bundles it and deploys it.
167
-
168
- ## Read the SDK guide before writing agent code
169
-
170
- The complete authoring guide ships inside the installed package:
171
-
172
- \`\`\`text
173
- node_modules/@alexkroman1/aai/AGENT_GUIDE.md
174
- \`\`\`
175
-
176
- Read it with your file tools. It is version-matched by construction — it lives
177
- in the same tarball as the \`@alexkroman1/aai\` this project resolved, so it
178
- cannot describe a different release than the one being imported. Prefer it over
179
- anything remembered about the SDK, and over anything in this file.
180
-
181
- The types are the second source of truth: the shipped declarations are in
182
- \`node_modules/@alexkroman1/aai/dist/\`. When the guide and the types disagree,
183
- the types are what the compiler enforces.
184
-
185
- ## Commands
186
-
187
- \`\`\`sh
188
- npm run dev # Run locally on http://localhost:3000
189
- npm test # This project's suite, minus the evals
190
- npm run test:agent # Just agent.test.ts, via the CLI
191
- npm run eval # Drive a real session against a live model (spends money)
192
- npm run build # Bundle the agent
193
- npm start # Build, then self-host on http://127.0.0.1:3000
194
- npm run publish:agent # Publish to the managed platform
195
- \`\`\`
196
-
197
- The \`aai\` CLI is a devDependency, so it is in \`node_modules/.bin\` rather than
198
- on \`PATH\`: reach it through these scripts or with \`npx aai <command>\`.
199
-
200
- ## Project-specific notes
201
-
202
- <!-- Add conventions, gotchas and decisions for THIS agent below. -->
203
- `;
204
- /**
205
- * Layer the base scaffold (package.json, tsconfig, …) into targetDir
206
- * WITHOUT overwriting anything already there. Shared by `aai init`
207
- * (underneath a template) and `aai pull` (underneath the studio workspace
208
- * files — the workspace stores source, and the scaffold completes it into a
209
- * runnable project the same way the guest's `ensureProjectShape` does
210
- * before an in-sandbox build).
211
- *
212
- * package.json is the one file merged rather than skipped — see
213
- * {@link layerScaffoldManifest}. `CLAUDE.md` is the one file SUBSTITUTED: the
214
- * scaffold's copy is the authoring guide, and a project gets
215
- * {@link PROJECT_GUIDE_POINTER} instead.
216
- */
217
- async function layerScaffold(targetDir) {
218
- const dir = scaffoldDir();
219
- if (!existsSync(dir)) return;
220
- await fs.cp(dir, targetDir, {
221
- recursive: true,
222
- force: false,
223
- errorOnExist: false,
224
- filter: (src) => scaffoldCopyFilter(src, dir)
225
- });
226
- await Promise.all([layerScaffoldManifest(dir, targetDir), fs.writeFile(path.join(targetDir, "CLAUDE.md"), PROJECT_GUIDE_POINTER, { flag: "wx" }).catch((err) => {
227
- if (!isEexist(err)) throw err;
228
- })]);
229
- }
230
- /**
231
- * `templateCopyFilter` plus the scaffold's own `CLAUDE.md`, which is the
232
- * authoring guide rather than a file a project wants — see
233
- * {@link PROJECT_GUIDE_POINTER}.
234
- *
235
- * Only the scaffold copy filters it. A TEMPLATE's `CLAUDE.md` would be that
236
- * template's own notes and belongs in the project it seeds, so
237
- * {@link downloadAndMergeTemplate} keeps using the unfiltered version. Matched
238
- * on the full path rather than the basename for the same reason.
239
- */
240
- function scaffoldCopyFilter(src, scaffold = scaffoldDir()) {
241
- return templateCopyFilter(src) && path.resolve(src) !== path.join(scaffold, "CLAUDE.md");
242
- }
243
- /**
244
- * `fs.cp` filter for every copy OUT of a template or the scaffold — the runtime
245
- * ones here and the build-time one in `bundle-templates.mjs`.
246
- *
247
- * A template directory is also a runnable project, so a developer who runs
248
- * `aai dev`, `aai build` or `aai publish` inside one leaves build output and
249
- * machine state in it: `.aai/` (which holds `project.json` — a SLUG and a
250
- * `serverUrl` — plus a built client), `.workflow-data/`, `node_modules/`, a
251
- * `.env`. None of it is git-tracked, and an unfiltered `fs.cp` copied all of it
252
- * anyway, to both destinations:
253
- *
254
- * - into every scaffolded project, so `aai init foo --template bar` produced a
255
- * directory already LINKED to `bar`'s last local deploy. `aai init` publishes
256
- * by default, so the first publish either targeted a slug the user never
257
- * chose or — for the `http://localhost:8080` a dev checkout leaves behind —
258
- * failed outright with "Refusing to send your API key to …", the project
259
- * staying mis-linked for every later `push`/`publish`/`secret`.
260
- * - into `packages/aai-cli/dist/templates`, i.e. into the PUBLISHED tarball
261
- * (`files: ["bin.mjs", "dist"]`). Measured on a real build: 26 stray
262
- * `.aai/project.json` files and 9.4 MB of one developer's `.aai/client`
263
- * bundles out of a 12 MB `templates/`.
264
- *
265
- * The vocabulary is the SDK's, not a fourth list: {@link IGNORED_WORKSPACE_DIRS}
266
- * is already "never walk this", and {@link isLocalOnlyFile} already means "this
267
- * exists only on a developer's machine" — including a `.env` that must not ship
268
- * to npm, and deliberately EXCLUDING `.env.example`, which the scaffold ships as
269
- * source and a scaffolded project cannot do without.
270
- */
271
- function templateCopyFilter(src) {
272
- const name = path.basename(src);
273
- return !(IGNORED_WORKSPACE_DIRS.has(name) || isLocalOnlyFile(name));
274
- }
275
- /**
276
- * Copy a template into targetDir, merging scaffold files underneath.
277
- */
278
- async function downloadAndMergeTemplate(template, targetDir) {
279
- const root = resolveTemplatesDir();
280
- const templatesDir = path.join(root, "templates");
281
- const names = await listTemplates(root);
282
- if (!names.includes(template)) throw new Error(`Unknown template "${template}". Available templates: ${names.join(", ")}`);
283
- await fs.cp(path.join(templatesDir, template), targetDir, {
284
- recursive: true,
285
- force: true,
286
- filter: templateCopyFilter
287
- });
288
- await layerScaffold(targetDir);
289
- }
290
- //#endregion
291
- export { REPO_URL, downloadAndMergeTemplate, layerScaffold, listTemplates };