@alexkroman1/aai-cli 13.2.0 → 14.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 (152) hide show
  1. package/bin.mjs +1 -1
  2. package/dist/{_agent-BTwZJu4P.mjs → _agent-BzUeqOdj.mjs} +33 -10
  3. package/dist/_agent.d.ts +23 -0
  4. package/dist/{_bundler-C31rlcYz.mjs → _bundler-DolUCMxu.mjs} +9 -8
  5. package/dist/_cli-common.d.ts +45 -6
  6. package/dist/{_config-CmJOFsAP.mjs → _config-DYzC6WMD.mjs} +7 -4
  7. package/dist/_config.d.ts +25 -1
  8. package/dist/_dev-env.d.ts +1 -1
  9. package/dist/{_dev-server-DWvkNoIS.mjs → _dev-server-CSMqF8PN.mjs} +28 -30
  10. package/dist/_dev-vite-config.d.ts +3 -3
  11. package/dist/_e2e-test-utils.d.ts +15 -7
  12. package/dist/{_init-BURbdHNM.mjs → _init-CQ8idAwo.mjs} +64 -30
  13. package/dist/{_output-CKkmWs7i.mjs → _output-DBP9Op_d.mjs} +43 -3
  14. package/dist/_output.d.ts +24 -7
  15. package/dist/{_preflight-Co1G9Jww.mjs → _preflight-CcAR577V.mjs} +3 -3
  16. package/dist/_resource-commands.d.ts +9 -9
  17. package/dist/{_server-common-6e0QI4mq.mjs → _server-common-vILJp3it.mjs} +3 -3
  18. package/dist/{_slug-api-CfGQq1Tt.mjs → _slug-api-CGvc2YSQ.mjs} +19 -10
  19. package/dist/_slug-api.d.ts +19 -0
  20. package/dist/{_studio-B1waXMuR.mjs → _studio-DnR_BqFp.mjs} +9 -5
  21. package/dist/_studio-commands.d.ts +13 -13
  22. package/dist/{_templates-0Zr2z6yA.mjs → _templates-CK4oKoeX.mjs} +3 -3
  23. package/dist/{_typecheck-gate-BXvUNnfs.mjs → _typecheck-gate-U3jcil8L.mjs} +5 -4
  24. package/dist/_typecheck-gate.d.ts +3 -1
  25. package/dist/{_ui-u7T4YooX.mjs → _ui-DCt4qZrk.mjs} +1 -1
  26. package/dist/{_utils-B8QmtFhK.mjs → _utils-D5JGcjiW.mjs} +44 -2
  27. package/dist/_utils.d.ts +35 -0
  28. package/dist/{_vite-env-D9Qj6KPX.mjs → _vite-env-kejF0p2L.mjs} +1 -1
  29. package/dist/{_workflow-determinism-f9J-5Zlj.mjs → _workflow-determinism-CvpqMpdh.mjs} +19 -27
  30. package/dist/_workflow-determinism.d.ts +3 -3
  31. package/dist/build-Mxk8gWvX.mjs +108 -0
  32. package/dist/build.d.ts +5 -0
  33. package/dist/cli.mjs +172 -116
  34. package/dist/{client-bundler-j5c46x0G.mjs → client-bundler-BJgREAh6.mjs} +4 -4
  35. package/dist/client-bundler.mjs +1 -1
  36. package/dist/{delete-X_CRgCf6.mjs → delete-BdFnbnVR.mjs} +6 -6
  37. package/dist/{deploy-BzZ-r4iM.mjs → deploy-uAJ4NukN.mjs} +14 -14
  38. package/dist/{dev-BDykFvcc.mjs → dev-DApPSaE_.mjs} +5 -5
  39. package/dist/{eval-0qEOdm0l.mjs → eval-BK47A_K5.mjs} +27 -11
  40. package/dist/eval.d.ts +2 -0
  41. package/dist/{init-BtJI306C.mjs → init-DukDxECd.mjs} +13 -21
  42. package/dist/{login-DeUETobb.mjs → login-DaLrPOFg.mjs} +6 -8
  43. package/dist/{logs-hWnJ66Bl.mjs → logs-7BRwq0cG.mjs} +22 -15
  44. package/dist/project-config.mjs +1 -1
  45. package/dist/scaffold/.env.example +17 -1
  46. package/dist/scaffold/CLAUDE.md +84 -56
  47. package/dist/scaffold/package.json +6 -5
  48. package/dist/scaffold/server.mjs +129 -25
  49. package/dist/secret-Cjp912yF.mjs +162 -0
  50. package/dist/secret.d.ts +48 -13
  51. package/dist/{studio-BxAS_FQQ.mjs → studio-CpHlNHUZ.mjs} +15 -17
  52. package/dist/templates/briefing-desk/agent.test.ts +7 -3
  53. package/dist/templates/call-audit/agent.test.ts +25 -9
  54. package/dist/templates/call-audit/agent.ts +2 -2
  55. package/dist/templates/call-audit/client.tsx +40 -58
  56. package/dist/templates/call-audit/workflows/audit.ts +7 -5
  57. package/dist/templates/call-audit/workflows/ingest.ts +7 -7
  58. package/dist/templates/call-audit/workflows/media.ts +12 -37
  59. package/dist/templates/call-audit/workflows/summarize.ts +8 -8
  60. package/dist/templates/call-audit/workflows/sync-api.ts +3 -3
  61. package/dist/templates/dispatch-center/agent.test.ts +7 -7
  62. package/dist/templates/dispatch-center/client.tsx +53 -61
  63. package/dist/templates/dispatch-center/shared.ts +0 -8
  64. package/dist/templates/dispatch-center/tools/ops_dashboard.ts +4 -1
  65. package/dist/templates/embedded-assets/agent.eval.test.ts +4 -2
  66. package/dist/templates/embedded-assets/agent.test.ts +7 -1
  67. package/dist/templates/health-assistant/agent.eval.test.ts +4 -2
  68. package/dist/templates/health-assistant/agent.test.ts +8 -4
  69. package/dist/templates/infocom-adventure/client.tsx +40 -36
  70. package/dist/templates/link-digest/agent.test.ts +10 -4
  71. package/dist/templates/link-digest/agent.ts +2 -2
  72. package/dist/templates/link-digest/client.tsx +42 -36
  73. package/dist/templates/link-digest/workflows/digest.ts +13 -16
  74. package/dist/templates/night-owl/agent.eval.test.ts +4 -2
  75. package/dist/templates/night-owl/agent.test.ts +6 -1
  76. package/dist/templates/night-owl/client.tsx +8 -2
  77. package/dist/templates/pipeline-simple/agent.test.ts +33 -16
  78. package/dist/templates/pizza-ordering/client.tsx +5 -4
  79. package/dist/templates/pizza-ordering/shared.ts +3 -8
  80. package/dist/templates/pizza-ordering/tools/add_pizza.ts +3 -2
  81. package/dist/templates/pizza-ordering/tools/place_order.ts +3 -2
  82. package/dist/templates/pizza-ordering/tools/remove_pizza.ts +3 -2
  83. package/dist/templates/pizza-ordering/tools/update_pizza.ts +3 -2
  84. package/dist/templates/pizza-ordering/tools/view_order.ts +3 -2
  85. package/dist/templates/plan-and-execute/agent.test.ts +10 -5
  86. package/dist/templates/plan-and-execute/client.tsx +2 -2
  87. package/dist/templates/podcast-digest/agent.test.ts +33 -14
  88. package/dist/templates/podcast-digest/client.tsx +27 -36
  89. package/dist/templates/podcast-digest/workflows/digest.ts +21 -19
  90. package/dist/templates/podcast-digest/workflows/feeds.ts +61 -33
  91. package/dist/templates/podcast-digest/workflows/slack.ts +7 -7
  92. package/dist/templates/recap-workflow/agent.eval.test.ts +21 -13
  93. package/dist/templates/recap-workflow/agent.test.ts +49 -32
  94. package/dist/templates/recap-workflow/workflows/recap.ts +24 -28
  95. package/dist/templates/redline/agent.eval.test.ts +5 -8
  96. package/dist/templates/redline/agent.test.ts +8 -2
  97. package/dist/templates/redline/client.tsx +47 -48
  98. package/dist/templates/redline/workflows/redline.ts +17 -17
  99. package/dist/templates/research-workflow/agent.eval.test.ts +5 -5
  100. package/dist/templates/research-workflow/agent.test.ts +17 -8
  101. package/dist/templates/research-workflow/workflows/research.ts +28 -30
  102. package/dist/templates/retail/agent.test.ts +17 -15
  103. package/dist/templates/retail/cancel.ts +7 -6
  104. package/dist/templates/retail/client.tsx +39 -58
  105. package/dist/templates/retail/payment.ts +4 -3
  106. package/dist/templates/retail/pending.test.ts +19 -19
  107. package/dist/templates/retail/registry.test.ts +99 -58
  108. package/dist/templates/retail/store.test.ts +5 -5
  109. package/dist/templates/retail/swap.ts +8 -11
  110. package/dist/templates/simple/agent.test.ts +39 -6
  111. package/dist/templates/solo-rpg/agent.eval.test.ts +2 -16
  112. package/dist/templates/solo-rpg/agent.test.ts +12 -12
  113. package/dist/templates/solo-rpg/client.tsx +3 -3
  114. package/dist/templates/spoken-summary/agent.test.ts +21 -12
  115. package/dist/templates/spoken-summary/agent.ts +3 -3
  116. package/dist/templates/spoken-summary/client.tsx +36 -47
  117. package/dist/templates/spoken-summary/workflows/summarize.ts +11 -11
  118. package/dist/templates/spoken-summary/workflows/transcribe.ts +14 -14
  119. package/dist/templates/support-line/client.tsx +4 -3
  120. package/dist/templates/support-line/prompts.ts +0 -2
  121. package/dist/templates/transcription-workflow/agent.test.ts +36 -20
  122. package/dist/templates/transcription-workflow/agent.ts +2 -2
  123. package/dist/templates/transcription-workflow/client.tsx +34 -40
  124. package/dist/templates/transcription-workflow/recover.ts +1 -1
  125. package/dist/templates/transcription-workflow/run-panel.tsx +34 -14
  126. package/dist/templates/transcription-workflow/total-latency.tsx +46 -20
  127. package/dist/templates/transcription-workflow/workflows/batch.ts +15 -15
  128. package/dist/templates/transcription-workflow/workflows/downsample.ts +1 -1
  129. package/dist/templates/transcription-workflow/workflows/normalize.ts +15 -19
  130. package/dist/templates/transcription-workflow/workflows/stream.ts +12 -12
  131. package/dist/templates/transcription-workflow/workflows/sync-api.ts +3 -3
  132. package/dist/templates/transcription-workflow/workflows/transcribe.ts +23 -34
  133. package/dist/templates/travel-concierge/agent.eval.test.ts +2 -2
  134. package/dist/templates/travel-concierge/agent.test.ts +15 -7
  135. package/dist/templates/travel-concierge/client.tsx +2 -2
  136. package/dist/templates/travel-concierge/shared.ts +10 -14
  137. package/dist/templates/travel-concierge/tools/lookup_booking.ts +4 -3
  138. package/dist/templates/travel-concierge/tools/search_car_rentals.ts +3 -2
  139. package/dist/templates/travel-concierge/tools/search_excursions.ts +3 -2
  140. package/dist/templates/travel-concierge/tools/search_flights.ts +3 -2
  141. package/dist/templates/travel-concierge/tools/search_hotels.ts +3 -2
  142. package/dist/test-D032V2cA.mjs +242 -0
  143. package/dist/test.d.ts +97 -31
  144. package/dist/typecheck.mjs +2 -2
  145. package/dist/worker-bundler.mjs +3 -3
  146. package/dist/{workflow-BBu5oEDw.mjs → workflow-CVioyO3V.mjs} +8 -7
  147. package/package.json +10 -10
  148. package/dist/bin.d.mts +0 -2
  149. package/dist/build-BLlLOrng.mjs +0 -66
  150. package/dist/secret-B-3T5tvr.mjs +0 -61
  151. package/dist/test-CiLab-AA.mjs +0 -182
  152. package/dist/tsdown.config.d.ts +0 -2
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import path from "node:path";
3
3
  import { readFile, readdir } from "node:fs/promises";
4
- //#region _workflow-determinism.ts
4
+ //#region src/_workflow-determinism.ts
5
5
  /**
6
6
  * A COMPUTED step identity in the project's own `workflows/`.
7
7
  *
@@ -24,12 +24,12 @@ import { readFile, readdir } from "node:fs/promises";
24
24
  * compiling every fence in this repo's shipped docs:
25
25
  *
26
26
  * ```ts
27
- * import type { WorkflowCtx } from "@alexkroman1/aai";
27
+ * import type { WorkflowContext } from "@alexkroman1/aai";
28
28
  *
29
29
  * declare const charge: () => Promise<string>;
30
30
  *
31
- * export async function body(ctx: WorkflowCtx, coin: string): Promise<void> {
32
- * // No error. The banned shape, against the real `WorkflowCtx`.
31
+ * export async function body(ctx: WorkflowContext, coin: string): Promise<void> {
32
+ * // No error. The banned shape, against the real `WorkflowContext`.
33
33
  * await ctx.step(`charge-${coin}`, charge);
34
34
  * }
35
35
  * ```
@@ -81,19 +81,6 @@ import { readFile, readdir } from "node:fs/promises";
81
81
  * @module
82
82
  */
83
83
  /**
84
- * The three `ctx` methods whose first argument is a journal identity.
85
- *
86
- * All three key a journal row by it — `name#occurrence` for a step,
87
- * `sleep!<label>#<n>` and `hook!<token>#<n>` for the waits — so a computed one
88
- * mints a row no earlier walk reached in exactly the same way. Kept as a list
89
- * so the message can name the method that was called.
90
- */
91
- const IDENTITY_METHODS = [
92
- "step",
93
- "sleep",
94
- "waitFor"
95
- ];
96
- /**
97
84
  * A `ctx.<method>(` immediately followed by a BACKTICK.
98
85
  *
99
86
  * The whole check, and its narrowness is the point. A quoted literal is
@@ -104,8 +91,17 @@ const IDENTITY_METHODS = [
104
91
  * The receiver is not pinned to `ctx` — a body may destructure or rename it —
105
92
  * and a `.step(` on anything else taking a template-literal first argument is
106
93
  * not a shape worth excluding.
94
+ *
95
+ * Shared rather than built per call, which is safe ONLY because the single
96
+ * reader is `matchAll`: that method species-constructs its own clone and never
97
+ * advances this object's `lastIndex`. A `.exec` or `.test` added against a `/g`
98
+ * regex would carry state between lines — build a fresh one there.
107
99
  */
108
- const identityPattern = () => new RegExp(`\\.(${IDENTITY_METHODS.join("|")})\\(\``, "g");
100
+ const IDENTITY_PATTERN = new RegExp(`\\.(${[
101
+ "step",
102
+ "sleep",
103
+ "waitFor"
104
+ ].join("|")})\\(\``, "g");
109
105
  /** Whether a template literal actually INTERPOLATES, or is merely quoted oddly. */
110
106
  const INTERPOLATES = /\$\{/;
111
107
  /**
@@ -132,7 +128,7 @@ function findComputedIdentities(source, file) {
132
128
  const findings = [];
133
129
  for (const [n, line] of source.split("\n").entries()) {
134
130
  if (isCommentOnly(line)) continue;
135
- for (const match of line.matchAll(identityPattern())) {
131
+ for (const match of line.matchAll(IDENTITY_PATTERN)) {
136
132
  const method = match[1];
137
133
  if (method === void 0) continue;
138
134
  if (!INTERPOLATES.test(line.slice((match.index ?? 0) + match[0].length))) continue;
@@ -169,17 +165,13 @@ async function workflowFiles(cwd) {
169
165
  * warning pass beside a typecheck that has already run on the same tree.
170
166
  */
171
167
  async function scanWorkflowDeterminism(cwd) {
172
- const findings = [];
173
- for (const rel of await workflowFiles(cwd)) {
174
- let source;
168
+ return (await Promise.all((await workflowFiles(cwd)).map(async (rel) => {
175
169
  try {
176
- source = await readFile(path.join(cwd, rel), "utf-8");
170
+ return findComputedIdentities(await readFile(path.join(cwd, rel), "utf-8"), rel);
177
171
  } catch {
178
- continue;
172
+ return [];
179
173
  }
180
- findings.push(...findComputedIdentities(source, rel));
181
- }
182
- return findings;
174
+ }))).flat();
183
175
  }
184
176
  /**
185
177
  * The remedy, once, however many findings there are.
@@ -20,12 +20,12 @@
20
20
  * compiling every fence in this repo's shipped docs:
21
21
  *
22
22
  * ```ts
23
- * import type { WorkflowCtx } from "@alexkroman1/aai";
23
+ * import type { WorkflowContext } from "@alexkroman1/aai";
24
24
  *
25
25
  * declare const charge: () => Promise<string>;
26
26
  *
27
- * export async function body(ctx: WorkflowCtx, coin: string): Promise<void> {
28
- * // No error. The banned shape, against the real `WorkflowCtx`.
27
+ * export async function body(ctx: WorkflowContext, coin: string): Promise<void> {
28
+ * // No error. The banned shape, against the real `WorkflowContext`.
29
29
  * await ctx.step(`charge-${coin}`, charge);
30
30
  * }
31
31
  * ```
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env node
2
+ import { a as ok, t as CliError } from "./_output-DBP9Op_d.mjs";
3
+ import { n as log, r as notify } from "./_ui-DCt4qZrk.mjs";
4
+ import { r as evalWorkerBundle, t as buildAgentBundle } from "./_bundler-DolUCMxu.mjs";
5
+ import { assertTypechecks } from "./_typecheck-gate-U3jcil8L.mjs";
6
+ import { n as scanWorkflowDeterminism, t as determinismWarnings } from "./_workflow-determinism-CvpqMpdh.mjs";
7
+ import { TEST_FILES, classifyVitestError, runVitest } from "./test-D032V2cA.mjs";
8
+ import path from "node:path";
9
+ import fs from "node:fs/promises";
10
+ import { agentConfigWarnings } from "@alexkroman1/aai/manifest";
11
+ import { DEFAULT_SYSTEM_PROMPT } from "@alexkroman1/aai";
12
+ //#region src/build.ts
13
+ /**
14
+ * `aai build` — bundle the agent without deploying, behind the same gates
15
+ * deploy runs (tests, then typecheck), so the command previews the deploy
16
+ * artifact and its failures alike.
17
+ *
18
+ * It also LEAVES that artifact on disk, at {@link WORKER_ARTIFACT_REL}, which is
19
+ * what makes self-hosting work: `server.mjs` loads the built worker rather than
20
+ * `agent.ts`, because a tool is discovered by the bundler enumerating `tools/`
21
+ * and no un-bundled loader can see that directory. See the scaffold's own
22
+ * `server.mjs` and "Self-hosting runs the built worker" in
23
+ * `packages/aai-templates/CLAUDE.md`.
24
+ */
25
+ /**
26
+ * Where the built worker lands, relative to the project root — under `.aai/`,
27
+ * beside the built client, so one gitignore rule covers every build output.
28
+ *
29
+ * `server.mjs` hardcodes this path: it is a plain `.mjs` file in a user's
30
+ * project and may not import from the CLI (which a deployed project does not
31
+ * install at all). The pair is covered end-to-end by the `npm start` leg of
32
+ * `e2e.test.ts` — the only tier that runs both halves as a user does.
33
+ */
34
+ const WORKER_ARTIFACT_REL = path.join(".aai", "worker.mjs");
35
+ /**
36
+ * The prose slot, named by convention. Mirrors `worker-bundler.ts`'s constant of
37
+ * the same name — the two cannot share one without an import cycle
38
+ * (`build.ts` → `_bundler.ts` → `worker-bundler.ts`), so `_build.test.ts` pins
39
+ * the pair end to end instead: a build whose prompt really came from the file
40
+ * has to report the file.
41
+ */
42
+ const SYSTEM_PROMPT_FILE = "system-prompt.md";
43
+ /** What {@link systemPromptSource} reports when nothing declared a prompt. */
44
+ const FRAMEWORK_DEFAULT_PROMPT_SOURCE = "the framework default (DEFAULT_SYSTEM_PROMPT)";
45
+ /**
46
+ * Which of the three possible authors of this agent's system prompt actually
47
+ * wrote the one in the bundle.
48
+ *
49
+ * `aai build` reported `name` and `workerBytes` and nothing about the prompt,
50
+ * and the prompt is the one field that can change COMPLETELY without any
51
+ * config changing: deleting `system-prompt.md` swaps in
52
+ * `DEFAULT_SYSTEM_PROMPT` — a total personality change — with exit 0 and no
53
+ * line anywhere. `withSystemPrompt` refuses the case where a file exists and
54
+ * nothing reads it; it cannot refuse a file that is simply GONE, because that
55
+ * is what an agent with no file legitimately looks like. So this is a report
56
+ * rather than a check.
57
+ *
58
+ * Decided by comparing VALUES against the built agent's resolved prompt, which
59
+ * is the same method `withSystemPrompt` uses and for the same reason — the
60
+ * alternative asks the bundler's module graph a question, and the author may
61
+ * have imported the file and composed it, which is neither "the file" nor
62
+ * "agent.ts" alone.
63
+ */
64
+ async function systemPromptSource(cwd, resolved) {
65
+ if (resolved === DEFAULT_SYSTEM_PROMPT) return FRAMEWORK_DEFAULT_PROMPT_SOURCE;
66
+ const trimmed = (await fs.readFile(path.join(cwd, SYSTEM_PROMPT_FILE), "utf-8").catch(() => void 0))?.trim();
67
+ if (trimmed === void 0 || trimmed === "" || !resolved.includes(trimmed)) return "agent.ts";
68
+ return resolved.trim() === trimmed ? SYSTEM_PROMPT_FILE : `agent.ts (composing ${SYSTEM_PROMPT_FILE})`;
69
+ }
70
+ /**
71
+ * Map a {@link runVitest} failure to a CliError — distinguishing a real test
72
+ * failure (test_failed) from the runner not spawning (spawn_failed) instead
73
+ * of a generic command_failed.
74
+ */
75
+ function testGateError(err) {
76
+ const { code, message } = classifyVitestError(err);
77
+ return new CliError(code, message, "Re-run with --skipTests to build without tests", { cause: err });
78
+ }
79
+ async function executeBuild(opts) {
80
+ const { cwd } = opts;
81
+ if (!opts.skipTests) try {
82
+ runVitest(cwd, {
83
+ candidates: TEST_FILES,
84
+ all: true
85
+ });
86
+ } catch (err) {
87
+ throw testGateError(err);
88
+ }
89
+ await assertTypechecks(cwd, { skip: opts.skipTypecheck });
90
+ const bundle = await buildAgentBundle(cwd, { minify: true });
91
+ const agentDef = await evalWorkerBundle(bundle.worker);
92
+ for (const warning of agentConfigWarnings(agentDef)) notify("warn", warning);
93
+ for (const warning of determinismWarnings(await scanWorkflowDeterminism(cwd))) notify("warn", warning);
94
+ const worker = path.join(cwd, WORKER_ARTIFACT_REL);
95
+ await fs.mkdir(path.dirname(worker), { recursive: true });
96
+ await fs.writeFile(worker, bundle.worker, "utf-8");
97
+ const systemPrompt = await systemPromptSource(cwd, agentDef.systemPrompt);
98
+ log.info(`System prompt: ${systemPrompt}`);
99
+ log.success("Build complete");
100
+ return ok({
101
+ name: agentDef.name,
102
+ workerBytes: bundle.worker.length,
103
+ worker,
104
+ systemPrompt
105
+ });
106
+ }
107
+ //#endregion
108
+ export { executeBuild };
package/dist/build.d.ts CHANGED
@@ -26,6 +26,11 @@ type BuildData = {
26
26
  workerBytes: number;
27
27
  /** Absolute path of the worker written — what `npm start` boots. */
28
28
  worker: string;
29
+ /**
30
+ * WHERE the prompt this bundle carries came from — see
31
+ * {@link systemPromptSource}.
32
+ */
33
+ systemPrompt: string;
29
34
  };
30
35
  export declare function executeBuild(opts: {
31
36
  cwd: string;