@autonoma-ai/planner 0.1.2 → 0.1.3-canary.23ca19e

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.
package/dist/index.js CHANGED
@@ -20,13 +20,13 @@ var init_esm_shims = __esm({
20
20
 
21
21
  // src/core/context.ts
22
22
  import { readFile, writeFile } from "fs/promises";
23
- import { join as join2 } from "path";
23
+ import { join as join3 } from "path";
24
24
  async function saveContext(outputDir, ctx) {
25
- await writeFile(join2(outputDir, CONTEXT_FILE), JSON.stringify(ctx, null, 2), "utf-8");
25
+ await writeFile(join3(outputDir, CONTEXT_FILE), JSON.stringify(ctx, null, 2), "utf-8");
26
26
  }
27
27
  async function loadContext(outputDir) {
28
28
  try {
29
- const raw = await readFile(join2(outputDir, CONTEXT_FILE), "utf-8");
29
+ const raw = await readFile(join3(outputDir, CONTEXT_FILE), "utf-8");
30
30
  return JSON.parse(raw);
31
31
  } catch {
32
32
  return null;
@@ -39,9 +39,9 @@ function formatContext(ctx) {
39
39
 
40
40
  **Why they want testing:** ${ctx.testingGoal}
41
41
 
42
- **Critical flows to prioritize:** ${ctx.criticalFlows}
42
+ **Critical flows (user-declared \u2014 these MUST be covered):** ${ctx.criticalFlows}
43
43
 
44
- Use this context to prioritize your exploration. Start with the critical flows the user mentioned, then expand to cover the rest of the application.`;
44
+ These are flows the user explicitly said cannot break. Treat them as authoritative: every one of them must be represented faithfully in your output \u2014 never drop or downplay them. Start with these, then expand to cover the rest of the application.`;
45
45
  if (ctx.pages?.length) {
46
46
  output += `
47
47
 
@@ -150,7 +150,7 @@ function createStepLogger(agentId, maxSteps) {
150
150
  function writeSpinner(message) {
151
151
  const frame = SPINNER_FRAMES[frameIdx % SPINNER_FRAMES.length];
152
152
  frameIdx++;
153
- process.stderr.write(`${CLEAR_LINE} ${DIM}${frame} ${message}${RESET}`);
153
+ process.stderr.write(`${CLEAR_LINE} ${DIM2}${frame} ${message}${RESET2}`);
154
154
  lastSpinnerLine = true;
155
155
  }
156
156
  function writePermanent(message) {
@@ -182,52 +182,52 @@ function createStepLogger(agentId, maxSteps) {
182
182
  case "write_file": {
183
183
  stats.filesWritten++;
184
184
  const path3 = String(tc.input.path ?? tc.input.file_path ?? "");
185
- writePermanent(` ${GREEN}\u270E write ${path3}${RESET}`);
185
+ writePermanent(` ${GREEN}\u270E write ${path3}${RESET2}`);
186
186
  break;
187
187
  }
188
188
  case "write_test":
189
189
  stats.filesWritten++;
190
- writePermanent(` ${GREEN}\u270E test ${summary2}${RESET}`);
190
+ writePermanent(` ${GREEN}\u270E test ${summary2}${RESET2}`);
191
191
  break;
192
192
  case "finish":
193
- writePermanent(` ${GREEN}${BOLD}\u2713 finish${RESET}`);
193
+ writePermanent(` ${GREEN}${BOLD}\u2713 done:${RESET2} ${GREEN}${agentId}${RESET2}`);
194
194
  break;
195
195
  case "subagent":
196
196
  case "spawn_researcher":
197
- writePermanent(` ${CYAN}\u2295 subagent: ${summary2}${RESET}`);
197
+ writePermanent(` ${CYAN}\u2295 subagent: ${summary2}${RESET2}`);
198
198
  break;
199
199
  default:
200
200
  writeSpinner(`${stepPrefix} \u2014 ${tc.name}${summary2 ? " " + summary2 : ""}`);
201
201
  }
202
202
  }
203
203
  for (const te of info.toolErrors) {
204
- writePermanent(` ${RED}\u2717 ${te.name}: ${te.error}${RESET}`);
204
+ writePermanent(` ${RED}\u2717 ${te.name}: ${te.error}${RESET2}`);
205
205
  }
206
206
  for (const f of info.writtenFiles) {
207
- writePermanent(` ${GREEN}\u{1F4C4} wrote: ${f}${RESET}`);
207
+ writePermanent(` ${GREEN}\u{1F4C4} wrote: ${f}${RESET2}`);
208
208
  }
209
209
  }
210
210
  function checkpoint(message) {
211
- writePermanent(` ${YELLOW}\u25B8 ${message}${RESET}`);
211
+ writePermanent(` ${YELLOW}\u25B8 ${message}${RESET2}`);
212
212
  }
213
213
  function summary() {
214
214
  clearSpinner();
215
215
  if (stats.filesRead > 0 || stats.filesWritten > 0) {
216
- console.log(` ${DIM}\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500${RESET}`);
216
+ console.log(` ${DIM2}\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500${RESET2}`);
217
217
  console.log(
218
- ` ${DIM}files read: ${stats.filesRead} | files written: ${stats.filesWritten}${RESET}`
218
+ ` ${DIM2}files read: ${stats.filesRead} | files written: ${stats.filesWritten}${RESET2}`
219
219
  );
220
220
  }
221
221
  }
222
222
  return { log: log8, checkpoint, summary, stats };
223
223
  }
224
- var DIM, RESET, CYAN, GREEN, RED, YELLOW, BOLD, SPINNER_FRAMES, CLEAR_LINE;
224
+ var DIM2, RESET2, CYAN, GREEN, RED, YELLOW, BOLD, SPINNER_FRAMES, CLEAR_LINE;
225
225
  var init_display = __esm({
226
226
  "src/core/display.ts"() {
227
227
  "use strict";
228
228
  init_esm_shims();
229
- DIM = "\x1B[2m";
230
- RESET = "\x1B[0m";
229
+ DIM2 = "\x1B[2m";
230
+ RESET2 = "\x1B[0m";
231
231
  CYAN = "\x1B[36m";
232
232
  GREEN = "\x1B[32m";
233
233
  RED = "\x1B[31m";
@@ -286,8 +286,8 @@ function buildStepHandler(config) {
286
286
  async function runAgent(config, prompt, extractResult) {
287
287
  const stepTimeout = config.stepTimeoutMs ?? STEP_TIMEOUT_MS;
288
288
  const modelsToTry = [config.model, ...FALLBACK_MODELS.map((id) => getModel(id))];
289
- const YELLOW2 = "\x1B[33m";
290
- const RESET4 = "\x1B[0m";
289
+ const YELLOW3 = "\x1B[33m";
290
+ const RESET6 = "\x1B[0m";
291
291
  for (let modelIdx = 0; modelIdx < modelsToTry.length; modelIdx++) {
292
292
  const model = modelsToTry[modelIdx];
293
293
  for (let retry = 0; retry < RETRIES_BEFORE_FALLBACK; retry++) {
@@ -312,17 +312,17 @@ async function runAgent(config, prompt, extractResult) {
312
312
  const msg = err instanceof Error ? err.message : String(err);
313
313
  const isTimeout = msg.includes("timed out") || msg.includes("timeout") || msg.includes("abort");
314
314
  if (!isTimeout) throw err;
315
- console.log(` ${YELLOW2}[${config.id}] step timed out after ${stepTimeout / 1e3}s${RESET4}`);
315
+ console.log(` ${YELLOW3}[${config.id}] step timed out after ${stepTimeout / 1e3}s${RESET6}`);
316
316
  if (retry < RETRIES_BEFORE_FALLBACK - 1) {
317
317
  console.log(
318
- ` ${YELLOW2}[${config.id}] retrying (${retry + 1}/${RETRIES_BEFORE_FALLBACK})...${RESET4}`
318
+ ` ${YELLOW3}[${config.id}] retrying (${retry + 1}/${RETRIES_BEFORE_FALLBACK})...${RESET6}`
319
319
  );
320
320
  continue;
321
321
  }
322
322
  if (modelIdx < modelsToTry.length - 1) {
323
323
  const nextModel = FALLBACK_MODELS[modelIdx];
324
324
  console.log(
325
- ` ${YELLOW2}[${config.id}] ${RETRIES_BEFORE_FALLBACK} timeouts, switching to ${nextModel}${RESET4}`
325
+ ` ${YELLOW3}[${config.id}] ${RETRIES_BEFORE_FALLBACK} timeouts, switching to ${nextModel}${RESET6}`
326
326
  );
327
327
  break;
328
328
  }
@@ -351,7 +351,7 @@ var init_agent = __esm({
351
351
 
352
352
  // src/core/gitignore.ts
353
353
  import { readFile as readFile3 } from "fs/promises";
354
- import { join as join5, relative } from "path";
354
+ import { join as join7, relative } from "path";
355
355
  import { glob } from "glob";
356
356
  async function loadGitignorePatterns(projectRoot) {
357
357
  const patterns = [
@@ -371,10 +371,10 @@ async function loadGitignorePatterns(projectRoot) {
371
371
  ];
372
372
  const matches = await glob("**/.gitignore", { cwd: projectRoot, dot: true });
373
373
  for (const match of matches) {
374
- const fullPath = join5(projectRoot, match);
374
+ const fullPath = join7(projectRoot, match);
375
375
  try {
376
376
  const content = await readFile3(fullPath, "utf-8");
377
- const prefix = relative(projectRoot, join5(projectRoot, match, ".."));
377
+ const prefix = relative(projectRoot, join7(projectRoot, match, ".."));
378
378
  const parsed = parseGitignore(content, prefix);
379
379
  patterns.push(...parsed);
380
380
  } catch (err) {
@@ -598,7 +598,7 @@ var init_grep = __esm({
598
598
  // src/tools/list-directory.ts
599
599
  import { readdir } from "fs/promises";
600
600
  import { stat } from "fs/promises";
601
- import { join as join6, relative as relative2 } from "path";
601
+ import { join as join8, relative as relative2 } from "path";
602
602
  import { tool as tool4 } from "ai";
603
603
  import { z as z4 } from "zod";
604
604
  import { minimatch } from "minimatch";
@@ -623,7 +623,7 @@ async function buildTree(dirPath, maxDepth, currentDepth, isIgnored, relativeBas
623
623
  const withTypes = [];
624
624
  for (const name of rawEntries) {
625
625
  try {
626
- const s = await stat(join6(dirPath, name));
626
+ const s = await stat(join8(dirPath, name));
627
627
  withTypes.push({ name, isDir: s.isDirectory() });
628
628
  } catch {
629
629
  withTypes.push({ name, isDir: false });
@@ -643,7 +643,7 @@ async function buildTree(dirPath, maxDepth, currentDepth, isIgnored, relativeBas
643
643
  }
644
644
  if (entry.isDir) {
645
645
  const children = await buildTree(
646
- join6(dirPath, entry.name),
646
+ join8(dirPath, entry.name),
647
647
  maxDepth,
648
648
  currentDepth + 1,
649
649
  isIgnored,
@@ -694,7 +694,7 @@ async function buildListDirectoryTool(workingDirectory) {
694
694
  };
695
695
  }
696
696
  seen.add(cacheKey);
697
- const targetDir = input.path === "." ? workingDirectory : join6(workingDirectory, input.path);
697
+ const targetDir = input.path === "." ? workingDirectory : join8(workingDirectory, input.path);
698
698
  try {
699
699
  const s = await stat(targetDir);
700
700
  if (!s.isDirectory()) {
@@ -800,7 +800,7 @@ import {
800
800
  import { z as z6 } from "zod";
801
801
  function buildSubagentTools(workingDirectory, onFileRead) {
802
802
  const baseReadFile = buildReadFileTool(workingDirectory);
803
- const readFile18 = onFileRead ? tool6({
803
+ const readFile19 = onFileRead ? tool6({
804
804
  description: baseReadFile.description,
805
805
  inputSchema: baseReadFile.inputSchema,
806
806
  execute: async (input, options) => {
@@ -813,7 +813,7 @@ function buildSubagentTools(workingDirectory, onFileRead) {
813
813
  bash: buildBashTool(workingDirectory),
814
814
  glob: buildGlobTool(workingDirectory),
815
815
  grep: buildGrepTool(workingDirectory),
816
- read_file: readFile18
816
+ read_file: readFile19
817
817
  };
818
818
  }
819
819
  function buildSubagentTool(model, workingDirectory, onHeartbeat, onFileRead) {
@@ -1091,12 +1091,12 @@ var init_notify = __esm({
1091
1091
  // src/core/review.ts
1092
1092
  import * as p2 from "@clack/prompts";
1093
1093
  import { access } from "fs/promises";
1094
- import { join as join7, isAbsolute } from "path";
1094
+ import { join as join9, isAbsolute } from "path";
1095
1095
  import { spawn } from "child_process";
1096
1096
  import which from "which";
1097
1097
  function resolvePath(artifact, outputDir) {
1098
1098
  if (isAbsolute(artifact)) return artifact;
1099
- return join7(outputDir, artifact);
1099
+ return join9(outputDir, artifact);
1100
1100
  }
1101
1101
  async function detectEditors() {
1102
1102
  if (cachedEditors) return cachedEditors;
@@ -1122,7 +1122,7 @@ async function openInEditor(files) {
1122
1122
  const editors = await detectEditors();
1123
1123
  if (editors.length === 0) {
1124
1124
  p2.log.warn("No editors found. Review the files manually:");
1125
- for (const f of files) console.log(` ${CYAN2}${f}${RESET2}`);
1125
+ for (const f of files) console.log(` ${CYAN2}${f}${RESET3}`);
1126
1126
  return;
1127
1127
  }
1128
1128
  if (preferredEditor) {
@@ -1164,11 +1164,11 @@ async function openInEditor(files) {
1164
1164
  }
1165
1165
  async function showResults(result, options) {
1166
1166
  console.log("");
1167
- console.log(` ${GREEN2}[${options.agentId}] Step complete.${RESET2}`);
1167
+ console.log(` ${GREEN2}[${options.agentId}] Step complete.${RESET3}`);
1168
1168
  if (result.artifacts.length === 0) {
1169
1169
  const knownFiles = ["AUTONOMA.md", "entity-audit.md", "scenarios.md"];
1170
1170
  for (const f of knownFiles) {
1171
- const fullPath = join7(options.outputDir, f);
1171
+ const fullPath = join9(options.outputDir, f);
1172
1172
  try {
1173
1173
  await access(fullPath);
1174
1174
  result.artifacts.push(f);
@@ -1178,17 +1178,24 @@ async function showResults(result, options) {
1178
1178
  }
1179
1179
  const resolvedPaths = [];
1180
1180
  if (result.artifacts.length > 0) {
1181
- console.log(` ${DIM2}Output files:${RESET2}`);
1181
+ console.log(` ${DIM3}Output files:${RESET3}`);
1182
1182
  for (const a of result.artifacts) {
1183
1183
  const fullPath = resolvePath(a, options.outputDir);
1184
1184
  resolvedPaths.push(fullPath);
1185
- console.log(` ${CYAN2}${fullPath}${RESET2}`);
1185
+ console.log(` ${CYAN2}${fullPath}${RESET3}`);
1186
1186
  }
1187
1187
  }
1188
1188
  if (result.summary) {
1189
1189
  console.log(` ${result.summary}`);
1190
1190
  }
1191
1191
  console.log("");
1192
+ if (options.renderSummary) {
1193
+ const rendered = await options.renderSummary();
1194
+ if (rendered) {
1195
+ console.log(rendered);
1196
+ console.log("");
1197
+ }
1198
+ }
1192
1199
  if (options.reviewGuidance) {
1193
1200
  p2.note(options.reviewGuidance, "What to check");
1194
1201
  }
@@ -1226,16 +1233,16 @@ async function reviewLoop(result, options) {
1226
1233
  await showResults(result, options);
1227
1234
  }
1228
1235
  }
1229
- var DIM2, CYAN2, GREEN2, RESET2, EDITORS, cachedEditors, preferredEditor;
1236
+ var DIM3, CYAN2, GREEN2, RESET3, EDITORS, cachedEditors, preferredEditor;
1230
1237
  var init_review = __esm({
1231
1238
  "src/core/review.ts"() {
1232
1239
  "use strict";
1233
1240
  init_esm_shims();
1234
1241
  init_notify();
1235
- DIM2 = "\x1B[2m";
1242
+ DIM3 = "\x1B[2m";
1236
1243
  CYAN2 = "\x1B[36m";
1237
1244
  GREEN2 = "\x1B[32m";
1238
- RESET2 = "\x1B[0m";
1245
+ RESET3 = "\x1B[0m";
1239
1246
  EDITORS = [
1240
1247
  { command: "cursor", label: "Cursor", args: (f) => f },
1241
1248
  { command: "code", label: "VS Code", args: (f) => f },
@@ -1339,6 +1346,7 @@ pages:
1339
1346
  BAD mission: "Shows analytics charts" (just restates the feature name)
1340
1347
  - coreReason (required when core: true): WHY breakage of this feature makes the product unusable.
1341
1348
  - At least one flow must have core: true
1349
+ - Any flow the user explicitly named as critical in the Project Context MUST appear as a feature in core_flows AND be marked core: true with a coreReason. Map the user's wording to the matching feature(s) \u2014 never drop a user-declared critical flow or leave it as core: false.
1342
1350
  - feature_count: total features identified (positive integer)
1343
1351
  - pages: a list of all pages discovered, with their path and brief description
1344
1352
 
@@ -1391,6 +1399,77 @@ After the frontmatter, include:
1391
1399
  }
1392
1400
  });
1393
1401
 
1402
+ // src/agents/01-kb-generator/flows.ts
1403
+ import { readFile as readFile5 } from "fs/promises";
1404
+ import { join as join10 } from "path";
1405
+ import matter from "gray-matter";
1406
+ async function parseCoreFlows(outputDir) {
1407
+ let raw;
1408
+ try {
1409
+ raw = await readFile5(join10(outputDir, "AUTONOMA.md"), "utf-8");
1410
+ } catch {
1411
+ return [];
1412
+ }
1413
+ try {
1414
+ const parsed = matter(raw);
1415
+ const flows = parsed.data.core_flows;
1416
+ if (!Array.isArray(flows)) return [];
1417
+ return flows.filter((f) => !!f && typeof f === "object").map((f) => ({
1418
+ feature: String(f.feature ?? "").trim(),
1419
+ description: f.description != null ? String(f.description) : void 0,
1420
+ mission: f.mission != null ? String(f.mission) : void 0,
1421
+ core: f.core === true,
1422
+ coreReason: f.coreReason != null ? String(f.coreReason) : void 0
1423
+ })).filter((f) => f.feature.length > 0);
1424
+ } catch {
1425
+ return [];
1426
+ }
1427
+ }
1428
+ function truncate(s, max) {
1429
+ if (s.length <= max) return s;
1430
+ return s.slice(0, max - 1).trimEnd() + "\u2026";
1431
+ }
1432
+ function pad(s, width) {
1433
+ return s + " ".repeat(Math.max(0, width - s.length));
1434
+ }
1435
+ function renderFlowsTable(flows) {
1436
+ if (flows.length === 0) return "";
1437
+ const DESC_MAX = 60;
1438
+ const NAME_MAX = 32;
1439
+ const rows = flows.map((f, i) => ({
1440
+ num: String(i + 1),
1441
+ name: truncate(f.feature, NAME_MAX),
1442
+ crit: f.core ? "core" : "normal",
1443
+ desc: truncate((f.description ?? "").replace(/\s+/g, " ").trim(), DESC_MAX)
1444
+ }));
1445
+ const numW = Math.max(1, ...rows.map((r) => r.num.length));
1446
+ const nameW = Math.max("Flow".length, ...rows.map((r) => r.name.length));
1447
+ const critW = Math.max("Criticality".length, ...rows.map((r) => r.crit.length));
1448
+ const coreCount = flows.filter((f) => f.core).length;
1449
+ const header = `${BOLD2}${pad("#", numW)} ${pad("Flow", nameW)} ${pad("Criticality", critW)} Description${RESET4}`;
1450
+ const sep = `${DIM4}${"\u2500".repeat(numW + nameW + critW + DESC_MAX + 6)}${RESET4}`;
1451
+ const body = rows.map((r) => {
1452
+ const line = `${pad(r.num, numW)} ${pad(r.name, nameW)} ${pad(r.crit, critW)} ${r.desc}`;
1453
+ return r.crit === "core" ? `${YELLOW2}${line}${RESET4}` : line;
1454
+ }).join("\n");
1455
+ const caption = `${DIM4}${flows.length} flows \xB7 ${coreCount} marked core${RESET4}`;
1456
+ return `${header}
1457
+ ${sep}
1458
+ ${body}
1459
+ ${caption}`;
1460
+ }
1461
+ var RESET4, DIM4, YELLOW2, BOLD2;
1462
+ var init_flows = __esm({
1463
+ "src/agents/01-kb-generator/flows.ts"() {
1464
+ "use strict";
1465
+ init_esm_shims();
1466
+ RESET4 = "\x1B[0m";
1467
+ DIM4 = "\x1B[2m";
1468
+ YELLOW2 = "\x1B[33m";
1469
+ BOLD2 = "\x1B[1m";
1470
+ }
1471
+ });
1472
+
1394
1473
  // src/agents/01-kb-generator/index.ts
1395
1474
  var kb_generator_exports = {};
1396
1475
  __export(kb_generator_exports, {
@@ -1398,8 +1477,8 @@ __export(kb_generator_exports, {
1398
1477
  });
1399
1478
  import { tool as tool10 } from "ai";
1400
1479
  import { z as z10 } from "zod";
1401
- import { readFile as readFile5 } from "fs/promises";
1402
- import { join as join8 } from "path";
1480
+ import { readFile as readFile6 } from "fs/promises";
1481
+ import { join as join11 } from "path";
1403
1482
  function buildRegisterPagesTool(tracker) {
1404
1483
  return tool10({
1405
1484
  description: "Register ALL page/route files discovered via glob. Call this ONCE after globbing for page files. The system will track which ones you've read and block finish until all are covered.",
@@ -1513,11 +1592,34 @@ Output files:
1513
1592
  };
1514
1593
  await runAgent(agentConfig, prompt, () => result);
1515
1594
  logger.summary();
1595
+ const declaredCriticalFlows = input.projectContext?.criticalFlows?.trim();
1596
+ if (result?.success && declaredCriticalFlows) {
1597
+ const beforeSelfReview = result;
1598
+ result = void 0;
1599
+ const selfReviewPrompt = `Before this knowledge base is shown to the user, verify it honors the critical flows they explicitly declared.
1600
+
1601
+ The user said these flows are critical and cannot break:
1602
+ "${declaredCriticalFlows}"
1603
+
1604
+ Read your AUTONOMA.md output. For EACH critical flow the user named:
1605
+ - Confirm it appears as a feature in core_flows (map the user's wording to the matching feature).
1606
+ - Confirm that feature is marked core: true with a coreReason.
1607
+
1608
+ If any declared critical flow is missing, mismatched, or left core: false, FIX AUTONOMA.md now \u2014 add the feature if it is genuinely absent, or flip core to true with a coreReason. Do not downgrade or drop anything the user declared critical.
1609
+
1610
+ When AUTONOMA.md correctly reflects every declared critical flow, call finish.`;
1611
+ await runAgent(agentConfig, selfReviewPrompt, () => result);
1612
+ if (!result) result = beforeSelfReview;
1613
+ }
1516
1614
  const reviewed = await reviewLoop(result, {
1517
1615
  agentId: "kb-generator",
1518
1616
  outputDir: input.outputDir,
1519
1617
  nonInteractive: input.nonInteractive,
1520
- reviewGuidance: "Check that every page/route in your app appears in core_flows.\nVerify the mission for each feature describes the ONE thing it must do correctly.\nLook for missing features or incorrectly grouped pages.\nA complex app should have 20-40 features \u2014 if you see fewer than 15, features are probably grouped too aggressively.",
1618
+ renderSummary: async () => {
1619
+ const flows = await parseCoreFlows(input.outputDir);
1620
+ return flows.length ? renderFlowsTable(flows) : void 0;
1621
+ },
1622
+ reviewGuidance: "Check that every page/route in your app appears in core_flows.\nVerify that every flow the user named as critical in the Project Context appears in core_flows and is marked core: true with a coreReason.\nVerify the mission for each feature describes the ONE thing it must do correctly.\nLook for missing features or incorrectly grouped pages.\nA complex app should have 20-40 features \u2014 if you see fewer than 15, features are probably grouped too aggressively.",
1521
1623
  onFeedback: async (feedback) => {
1522
1624
  result = void 0;
1523
1625
  const feedbackPrompt = `The user reviewed your knowledge base output and has this feedback:
@@ -1532,9 +1634,9 @@ Call page_coverage to see current state. When done with changes, call finish aga
1532
1634
  }
1533
1635
  });
1534
1636
  if (!reviewed) {
1535
- const autonomaPath = join8(input.outputDir, "AUTONOMA.md");
1637
+ const autonomaPath = join11(input.outputDir, "AUTONOMA.md");
1536
1638
  try {
1537
- await readFile5(autonomaPath, "utf-8");
1639
+ await readFile6(autonomaPath, "utf-8");
1538
1640
  return {
1539
1641
  success: true,
1540
1642
  artifacts: ["AUTONOMA.md"],
@@ -1560,6 +1662,7 @@ var init_kb_generator = __esm({
1560
1662
  init_review();
1561
1663
  init_tools();
1562
1664
  init_prompt();
1665
+ init_flows();
1563
1666
  PageTracker = class {
1564
1667
  registered = /* @__PURE__ */ new Set();
1565
1668
  read = /* @__PURE__ */ new Set();
@@ -1729,8 +1832,8 @@ var entity_audit_exports = {};
1729
1832
  __export(entity_audit_exports, {
1730
1833
  runEntityAudit: () => runEntityAudit
1731
1834
  });
1732
- import { readFile as readFile6, writeFile as writeFile4 } from "fs/promises";
1733
- import { join as join9 } from "path";
1835
+ import { readFile as readFile7, writeFile as writeFile4 } from "fs/promises";
1836
+ import { join as join12 } from "path";
1734
1837
  import { tool as tool11 } from "ai";
1735
1838
  import { z as z11 } from "zod";
1736
1839
  import { glob as glob3 } from "glob";
@@ -1859,7 +1962,7 @@ async function findPrismaSchema(projectRoot) {
1859
1962
  return candidates[0] ?? null;
1860
1963
  }
1861
1964
  async function extractPrismaModels(schemaPath) {
1862
- const content = await readFile6(schemaPath, "utf-8");
1965
+ const content = await readFile7(schemaPath, "utf-8");
1863
1966
  return content.split("\n").filter((line) => line.startsWith("model ")).map((line) => line.split(/\s+/)[1]).filter((name) => name != null);
1864
1967
  }
1865
1968
  async function detectFrameworkAndModels(projectRoot) {
@@ -1941,7 +2044,7 @@ write_file already targets the output directory \u2014 use just the filename.`;
1941
2044
  logger.summary();
1942
2045
  if (!result && tracker.auditedModels.size > 0) {
1943
2046
  const markdown = tracker.generateAuditMarkdown();
1944
- const auditPath = join9(input.outputDir, "entity-audit.md");
2047
+ const auditPath = join12(input.outputDir, "entity-audit.md");
1945
2048
  await writeFile4(auditPath, markdown, "utf-8");
1946
2049
  const cov = tracker.coverage();
1947
2050
  result = {
@@ -1970,9 +2073,9 @@ When done with changes, call finish again.`;
1970
2073
  }
1971
2074
  });
1972
2075
  if (!reviewed) {
1973
- const auditPath = join9(input.outputDir, "entity-audit.md");
2076
+ const auditPath = join12(input.outputDir, "entity-audit.md");
1974
2077
  try {
1975
- await readFile6(auditPath, "utf-8");
2078
+ await readFile7(auditPath, "utf-8");
1976
2079
  return {
1977
2080
  success: true,
1978
2081
  artifacts: ["entity-audit.md"],
@@ -2109,11 +2212,11 @@ ${duals.length > 0 ? duals.map((m) => `- **${m.name}** \u2014 standalone: ${m.cr
2109
2212
  });
2110
2213
 
2111
2214
  // src/core/parse-entity-audit.ts
2112
- import { readFile as readFile7 } from "fs/promises";
2113
- import { join as join10 } from "path";
2215
+ import { readFile as readFile8 } from "fs/promises";
2216
+ import { join as join13 } from "path";
2114
2217
  async function parseEntityNames(outputDir) {
2115
2218
  try {
2116
- const content = await readFile7(join10(outputDir, "entity-audit.md"), "utf-8");
2219
+ const content = await readFile8(join13(outputDir, "entity-audit.md"), "utf-8");
2117
2220
  const names = [];
2118
2221
  for (const line of content.split("\n")) {
2119
2222
  const match = line.match(/^\s+-\s+name:\s+(.+)$/);
@@ -2196,8 +2299,8 @@ __export(scenario_recipe_exports, {
2196
2299
  feedbackToScenario: () => feedbackToScenario,
2197
2300
  runScenarioRecipe: () => runScenarioRecipe
2198
2301
  });
2199
- import { readFile as readFile8 } from "fs/promises";
2200
- import { join as join11 } from "path";
2302
+ import { readFile as readFile9 } from "fs/promises";
2303
+ import { join as join14 } from "path";
2201
2304
  import { tool as tool12 } from "ai";
2202
2305
  import { z as z12 } from "zod";
2203
2306
  function buildFinishTool3(requiredEntities, outputDir, onFinish) {
@@ -2211,7 +2314,7 @@ function buildFinishTool3(requiredEntities, outputDir, onFinish) {
2211
2314
  execute: async (input) => {
2212
2315
  if (requiredEntities.length > 0) {
2213
2316
  try {
2214
- const content = await readFile8(join11(outputDir, "scenarios.md"), "utf-8");
2317
+ const content = await readFile9(join14(outputDir, "scenarios.md"), "utf-8");
2215
2318
  const missing = requiredEntities.filter(
2216
2319
  (e) => !content.includes(e)
2217
2320
  );
@@ -2294,9 +2397,9 @@ When done with changes, call finish again.`;
2294
2397
  }
2295
2398
  });
2296
2399
  if (!reviewed) {
2297
- const scenariosPath = join11(input.outputDir, "scenarios.md");
2400
+ const scenariosPath = join14(input.outputDir, "scenarios.md");
2298
2401
  try {
2299
- await readFile8(scenariosPath, "utf-8");
2402
+ await readFile9(scenariosPath, "utf-8");
2300
2403
  return {
2301
2404
  success: true,
2302
2405
  artifacts: ["scenarios.md"],
@@ -2349,8 +2452,8 @@ var init_scenario_recipe = __esm({
2349
2452
  });
2350
2453
 
2351
2454
  // src/agents/04-recipe-builder/state.ts
2352
- import { readFile as readFile9, writeFile as writeFile5 } from "fs/promises";
2353
- import { join as join12 } from "path";
2455
+ import { readFile as readFile10, writeFile as writeFile5 } from "fs/promises";
2456
+ import { join as join15 } from "path";
2354
2457
  function adapterKey(a) {
2355
2458
  return `${a.language}:${a.framework}`;
2356
2459
  }
@@ -2377,14 +2480,14 @@ function initialRecipeState() {
2377
2480
  }
2378
2481
  async function loadRecipeState(outputDir) {
2379
2482
  try {
2380
- const raw = await readFile9(join12(outputDir, STATE_FILE2), "utf-8");
2483
+ const raw = await readFile10(join15(outputDir, STATE_FILE2), "utf-8");
2381
2484
  return JSON.parse(raw);
2382
2485
  } catch {
2383
2486
  return null;
2384
2487
  }
2385
2488
  }
2386
2489
  async function saveRecipeState(outputDir, state) {
2387
- await writeFile5(join12(outputDir, STATE_FILE2), JSON.stringify(state, null, 2), "utf-8");
2490
+ await writeFile5(join15(outputDir, STATE_FILE2), JSON.stringify(state, null, 2), "utf-8");
2388
2491
  }
2389
2492
  var ALL_ADAPTERS, ADAPTER_HINTS, STATE_FILE2;
2390
2493
  var init_state = __esm({
@@ -2430,10 +2533,10 @@ var init_state = __esm({
2430
2533
  });
2431
2534
 
2432
2535
  // src/agents/04-recipe-builder/entity-order.ts
2433
- import { readFile as readFile10 } from "fs/promises";
2434
- import { join as join13 } from "path";
2536
+ import { readFile as readFile11 } from "fs/promises";
2537
+ import { join as join16 } from "path";
2435
2538
  async function parseEntityAudit(outputDir) {
2436
- const raw = await readFile10(join13(outputDir, "entity-audit.md"), "utf-8");
2539
+ const raw = await readFile11(join16(outputDir, "entity-audit.md"), "utf-8");
2437
2540
  const fmMatch = raw.match(/^---\n([\s\S]*?)\n---/);
2438
2541
  if (!fmMatch) throw new Error("entity-audit.md has no YAML frontmatter");
2439
2542
  const yaml = fmMatch[1];
@@ -2690,11 +2793,11 @@ When done, call finish with your findings.`;
2690
2793
 
2691
2794
  // src/core/detect-pkg-manager.ts
2692
2795
  import { existsSync as existsSync2 } from "fs";
2693
- import { join as join14 } from "path";
2796
+ import { join as join17 } from "path";
2694
2797
  function detectPackageManager(projectRoot) {
2695
- if (existsSync2(join14(projectRoot, "bun.lock")) || existsSync2(join14(projectRoot, "bun.lockb"))) return "bun";
2696
- if (existsSync2(join14(projectRoot, "pnpm-lock.yaml"))) return "pnpm";
2697
- if (existsSync2(join14(projectRoot, "yarn.lock"))) return "yarn";
2798
+ if (existsSync2(join17(projectRoot, "bun.lock")) || existsSync2(join17(projectRoot, "bun.lockb"))) return "bun";
2799
+ if (existsSync2(join17(projectRoot, "pnpm-lock.yaml"))) return "pnpm";
2800
+ if (existsSync2(join17(projectRoot, "yarn.lock"))) return "yarn";
2698
2801
  return "npm";
2699
2802
  }
2700
2803
  function installCommand(pm, ...packages) {
@@ -2724,7 +2827,7 @@ function spanReplacer(_match, cls) {
2724
2827
  return ANSI[mainCls] ?? "";
2725
2828
  }
2726
2829
  function htmlToAnsi(html) {
2727
- return html.replace(/<span class="hljs-([^"]+)">/g, spanReplacer).replace(/<\/span>/g, RESET3).replace(/&#x27;/g, "'").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"');
2830
+ return html.replace(/<span class="hljs-([^"]+)">/g, spanReplacer).replace(/<\/span>/g, RESET5).replace(/&#x27;/g, "'").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"');
2728
2831
  }
2729
2832
  function highlightCode(code, language = "typescript") {
2730
2833
  try {
@@ -2738,14 +2841,14 @@ function codeNoteFormat(line) {
2738
2841
  if (line.includes("\x1B[")) return line;
2739
2842
  return highlightCode(line);
2740
2843
  }
2741
- var RESET3, ANSI;
2844
+ var RESET5, ANSI;
2742
2845
  var init_highlight = __esm({
2743
2846
  "src/core/highlight.ts"() {
2744
2847
  "use strict";
2745
2848
  init_esm_shims();
2746
- RESET3 = "\x1B[0m";
2849
+ RESET5 = "\x1B[0m";
2747
2850
  ANSI = {
2748
- reset: RESET3,
2851
+ reset: RESET5,
2749
2852
  keyword: "\x1B[35m",
2750
2853
  string: "\x1B[32m",
2751
2854
  number: "\x1B[33m",
@@ -2770,8 +2873,8 @@ var init_highlight = __esm({
2770
2873
  });
2771
2874
 
2772
2875
  // src/agents/04-recipe-builder/recipe.ts
2773
- import { readFile as readFile11, writeFile as writeFile6 } from "fs/promises";
2774
- import { join as join15 } from "path";
2876
+ import { readFile as readFile12, writeFile as writeFile6 } from "fs/promises";
2877
+ import { join as join18 } from "path";
2775
2878
  function buildSingleEntityRecipe(entityName, models, entityOrder, allEntities) {
2776
2879
  const chain = getEntityDependencyChain(entityName, models, entityOrder);
2777
2880
  const recipe = {};
@@ -2815,7 +2918,7 @@ function buildSubmittableRecipe(create, description) {
2815
2918
  };
2816
2919
  }
2817
2920
  async function saveRecipe(outputDir, recipe) {
2818
- await writeFile6(join15(outputDir, RECIPE_FILE), JSON.stringify(recipe, null, 2), "utf-8");
2921
+ await writeFile6(join18(outputDir, RECIPE_FILE), JSON.stringify(recipe, null, 2), "utf-8");
2819
2922
  }
2820
2923
  var RECIPE_FILE;
2821
2924
  var init_recipe = __esm({
@@ -2875,12 +2978,15 @@ var init_http_client = __esm({
2875
2978
 
2876
2979
  // src/agents/04-recipe-builder/phases/entity-loop.ts
2877
2980
  import * as p4 from "@clack/prompts";
2878
- import { writeFile as writeFile7, readFile as readFile12 } from "fs/promises";
2879
- import { join as join16 } from "path";
2981
+ import { writeFile as writeFile7, readFile as readFile13 } from "fs/promises";
2982
+ import { join as join19 } from "path";
2880
2983
  import { tmpdir } from "os";
2881
2984
  import { spawn as spawn2 } from "child_process";
2882
2985
  import { tool as tool14 } from "ai";
2883
2986
  import { z as z14 } from "zod";
2987
+ function summarizeCompletedAliases(completedEntities, excludeName) {
2988
+ return Object.entries(completedEntities).filter(([name, e]) => name !== excludeName && e.recipeData && e.recipeData.length > 0).map(([name, e]) => `${name}: aliases ${e.recipeData.map((r) => r._alias ?? "?").join(", ")}`).join("\n");
2989
+ }
2884
2990
  async function proposeRecipeData(entityName, entityIndex, totalEntities, model, outputDir, _projectRoot, completedEntities) {
2885
2991
  let result;
2886
2992
  const { logger, onStepFinish } = buildDefaultStepLogger(`propose:${entityName}`, 20);
@@ -2894,7 +3000,7 @@ async function proposeRecipeData(entityName, entityIndex, totalEntities, model,
2894
3000
  return { accepted: true };
2895
3001
  }
2896
3002
  });
2897
- const completedAliases = Object.entries(completedEntities).filter(([, e]) => e.recipeData && e.recipeData.length > 0).map(([name, e]) => `${name}: aliases ${e.recipeData.map((r) => r._alias ?? "?").join(", ")}`).join("\n");
3003
+ const completedAliases = summarizeCompletedAliases(completedEntities, entityName);
2898
3004
  const prompt = `[${entityIndex + 1}/${totalEntities}] Propose recipe data for entity "${entityName}".
2899
3005
 
2900
3006
  Read scenarios.md and entity-audit.md from the output directory. Design records that match the scenario data.
@@ -2924,7 +3030,7 @@ Call finish with the JSON array of records.`;
2924
3030
  logger.summary();
2925
3031
  return result ?? [];
2926
3032
  }
2927
- async function reviseRecipeData(entityName, entityIndex, totalEntities, current, feedback, model, outputDir) {
3033
+ async function reviseRecipeData(entityName, entityIndex, totalEntities, current, feedback, model, outputDir, completedEntities) {
2928
3034
  let revised;
2929
3035
  const finishTool = tool14({
2930
3036
  description: "Submit the fixed recipe data.",
@@ -2937,14 +3043,19 @@ async function reviseRecipeData(entityName, entityIndex, totalEntities, current,
2937
3043
  }
2938
3044
  });
2939
3045
  const { logger, onStepFinish } = buildDefaultStepLogger(`fix:${entityName}`, 15);
3046
+ const completedAliases = summarizeCompletedAliases(completedEntities, entityName);
3047
+ const aliasBlock = completedAliases ? `Aliases declared by already-created parent entities (these are the ONLY valid _ref targets):
3048
+ ${completedAliases}
3049
+ ` : `This is a root entity \u2014 it has no parent entities to _ref.
3050
+ `;
2940
3051
  await runAgent(
2941
3052
  {
2942
3053
  id: `fix-${entityName}`,
2943
- systemPrompt: `You are fixing recipe data that failed validation. Read the error, the current data, and the user's feedback. Read scenarios.md and entity-audit.md if needed. Fix the data and call finish.
3054
+ systemPrompt: `You are fixing recipe data based on user feedback (or a validation failure). Read the error, the current data, and the user's feedback. Read scenarios.md and entity-audit.md if needed. Fix the data and call finish.
2944
3055
 
2945
3056
  Rules:
2946
3057
  - _alias fields must be unique identifiers (e.g., "card_1", "transaction_1")
2947
- - _ref fields reference aliases from OTHER entities that were already created
3058
+ - _ref fields must reference an alias that ALREADY EXISTS on a parent entity \u2014 see the list of valid targets below. Never invent a _ref to an alias that isn't listed.
2948
3059
  - Read scenarios.md to verify you're using correct alias names from parent entities
2949
3060
  - Field names must match the entity's schema from entity-audit.md`,
2950
3061
  model,
@@ -2957,13 +3068,14 @@ Rules:
2957
3068
  },
2958
3069
  `[${entityIndex + 1}/${totalEntities}] Fix recipe data for "${entityName}".
2959
3070
 
2960
- Current data that failed:
3071
+ Current data:
2961
3072
  ${JSON.stringify(current, null, 2)}
2962
3073
 
2963
- Problem:
3074
+ What's wrong / what to change:
2964
3075
  ${feedback}
2965
3076
 
2966
- Read scenarios.md and entity-audit.md to understand the correct aliases and schema. Fix the data and call finish.`,
3077
+ ${aliasBlock}
3078
+ Read scenarios.md and entity-audit.md to understand the correct aliases and schema. Apply the change and call finish.`,
2967
3079
  () => revised
2968
3080
  );
2969
3081
  logger.summary();
@@ -3037,7 +3149,7 @@ Read the creation file from the project to understand the existing service/funct
3037
3149
  logger.summary();
3038
3150
  return result ?? "No instructions generated. Check the entity audit for creation_file and creation_function.";
3039
3151
  }
3040
- async function reviewRecipeData(entityName, entityIndex, totalEntities, proposed, model, outputDir) {
3152
+ async function reviewRecipeData(entityName, entityIndex, totalEntities, proposed, model, outputDir, completedEntities) {
3041
3153
  p4.log.info(
3042
3154
  `Legend for recipe fields:
3043
3155
  _alias \u2014 Internal ID used to reference this record from other entities (e.g., { "_ref": "org_1" })
@@ -3060,7 +3172,7 @@ async function reviewRecipeData(entityName, entityIndex, totalEntities, proposed
3060
3172
  if (p4.isCancel(action)) throw new Error("Recipe review cancelled");
3061
3173
  if (action === "keep") return proposed;
3062
3174
  if (action === "edit") {
3063
- const tmpPath = join16(tmpdir(), `autonoma-recipe-${entityName}.json`);
3175
+ const tmpPath = join19(tmpdir(), `autonoma-recipe-${entityName}.json`);
3064
3176
  await writeFile7(tmpPath, JSON.stringify(proposed, null, 2), "utf-8");
3065
3177
  const editor = process.env.EDITOR ?? process.env.VISUAL ?? "vi";
3066
3178
  p4.log.info(`Opening ${editor}... Save and close when done.`);
@@ -3069,7 +3181,7 @@ async function reviewRecipeData(entityName, entityIndex, totalEntities, proposed
3069
3181
  proc.on("close", () => resolve5());
3070
3182
  proc.on("error", reject);
3071
3183
  });
3072
- const edited = await readFile12(tmpPath, "utf-8");
3184
+ const edited = await readFile13(tmpPath, "utf-8");
3073
3185
  try {
3074
3186
  proposed = JSON.parse(edited);
3075
3187
  p4.note(JSON.stringify(proposed, null, 2), `Updated data for ${entityName}`, { format: codeNoteFormat });
@@ -3084,43 +3196,16 @@ async function reviewRecipeData(entityName, entityIndex, totalEntities, proposed
3084
3196
  placeholder: "e.g., add more records, change field values, fix references..."
3085
3197
  });
3086
3198
  if (p4.isCancel(feedback) || !feedback.trim()) continue;
3087
- let revised;
3088
- const finishTool = tool14({
3089
- description: "Submit revised recipe data.",
3090
- inputSchema: z14.object({
3091
- records: z14.array(z14.record(z14.string(), z14.unknown()))
3092
- }),
3093
- execute: async (input) => {
3094
- revised = input.records;
3095
- return { done: true };
3096
- }
3097
- });
3098
- const { logger, onStepFinish } = buildDefaultStepLogger(`revise:${entityName}`, 10);
3099
- await runAgent(
3100
- {
3101
- id: `revise-${entityName}`,
3102
- systemPrompt: "You are revising recipe data based on user feedback. Read the current data, apply the feedback, and call finish with the updated records.",
3103
- model,
3104
- maxSteps: 10,
3105
- tools: (_heartbeat) => ({
3106
- read_output: buildReadFileTool(outputDir),
3107
- finish: finishTool
3108
- }),
3109
- onStepFinish
3110
- },
3111
- `Current data for ${entityName}:
3112
- ${JSON.stringify(proposed, null, 2)}
3113
-
3114
- User feedback: "${feedback}"
3115
-
3116
- Revise the data and call finish.`,
3117
- () => revised
3199
+ proposed = await reviseRecipeData(
3200
+ entityName,
3201
+ entityIndex,
3202
+ totalEntities,
3203
+ proposed,
3204
+ feedback.trim(),
3205
+ model,
3206
+ outputDir,
3207
+ completedEntities
3118
3208
  );
3119
- logger.summary();
3120
- if (revised) {
3121
- proposed = revised;
3122
- p4.note(JSON.stringify(proposed, null, 2), `Revised data for ${entityName}`, { format: codeNoteFormat });
3123
- }
3124
3209
  }
3125
3210
  }
3126
3211
  }
@@ -3247,7 +3332,7 @@ async function runEntityLoop(state, models, model, projectRoot, outputDir, nonIn
3247
3332
  );
3248
3333
  }
3249
3334
  if (!nonInteractive) {
3250
- recipeData = await reviewRecipeData(entityName, i, total, recipeData, model, outputDir);
3335
+ recipeData = await reviewRecipeData(entityName, i, total, recipeData, model, outputDir, state.entities);
3251
3336
  }
3252
3337
  state.entities[entityName] = {
3253
3338
  entityName,
@@ -3270,20 +3355,21 @@ async function runEntityLoop(state, models, model, projectRoot, outputDir, nonIn
3270
3355
  projectRoot,
3271
3356
  outputDir
3272
3357
  );
3273
- p4.note(instructions, `Implementation guide for ${entityName}`, { format: codeNoteFormat });
3274
3358
  const DOCS_BASE2 = "https://docs.agent.autonoma.app";
3275
3359
  p4.log.info(
3276
- `Copy the instructions above into Claude Code or your AI coding assistant.
3277
- They can implement the factory directly in your codebase.
3278
-
3279
- Autonoma SDK docs: ${DOCS_BASE2}/sdk/environment-factory`
3360
+ `Next: implement the ${entityName} factory. The block below is a copy-paste guide \u2014
3361
+ paste it into Claude Code (or your AI assistant) and it will write the factory in your codebase.
3362
+ A factory teaches the Autonoma SDK how to create and tear down ${entityName} records using your app's own code.
3363
+ Keep it local for now: implement it, run your app on localhost, and we'll test it live here. You deploy later.`
3280
3364
  );
3365
+ p4.note(instructions, `Implementation guide for ${entityName} (paste into your AI assistant)`, { format: codeNoteFormat });
3366
+ p4.log.info(`Autonoma SDK docs: ${DOCS_BASE2}/sdk/environment-factory`);
3281
3367
  if (i === 0) {
3282
- p4.log.info("This is your first factory \u2014 the instructions include one-time SDK setup. Subsequent entities will only need the factory function.");
3368
+ p4.log.info("This is your first factory \u2014 the guide includes one-time SDK setup. Later entities only need the factory function.");
3283
3369
  }
3284
3370
  notify("Autonoma", `${entityName} \u2014 implementation ready, waiting for you`);
3285
3371
  const ready = await p4.confirm({
3286
- message: `[${i + 1}/${total}] Is your server running with the ${entityName} factory?`
3372
+ message: `[${i + 1}/${total}] Is your app running locally with the ${entityName} factory wired up?`
3287
3373
  });
3288
3374
  if (p4.isCancel(ready)) throw new Error("Entity loop cancelled");
3289
3375
  if (!ready) {
@@ -3299,7 +3385,7 @@ async function runEntityLoop(state, models, model, projectRoot, outputDir, nonIn
3299
3385
  state.sharedSecret = secret;
3300
3386
  await saveRecipeState(outputDir, state);
3301
3387
  await writeFile7(
3302
- join16(outputDir, "autonoma-config.json"),
3388
+ join19(outputDir, "autonoma-config.json"),
3303
3389
  JSON.stringify({ sharedSecret: secret, endpointUrl: state.sdkEndpointUrl }, null, 2),
3304
3390
  "utf-8"
3305
3391
  );
@@ -3310,7 +3396,7 @@ Add this to your server's .env file and restart it.
3310
3396
  This is a 64-character hex key used for HMAC-SHA256 request signing.
3311
3397
  The same value must be set in both your server and the Autonoma dashboard.
3312
3398
 
3313
- Saved to: ${join16(outputDir, "autonoma-config.json")}`,
3399
+ Saved to: ${join19(outputDir, "autonoma-config.json")}`,
3314
3400
  "Shared secret generated"
3315
3401
  );
3316
3402
  const secretReady = await p4.confirm({
@@ -3332,7 +3418,7 @@ Saved to: ${join16(outputDir, "autonoma-config.json")}`,
3332
3418
  state.sdkEndpointUrl = url.trim() || "http://localhost:3000/api/autonoma";
3333
3419
  await saveRecipeState(outputDir, state);
3334
3420
  await writeFile7(
3335
- join16(outputDir, "autonoma-config.json"),
3421
+ join19(outputDir, "autonoma-config.json"),
3336
3422
  JSON.stringify({ sharedSecret: state.sharedSecret, endpointUrl: state.sdkEndpointUrl }, null, 2),
3337
3423
  "utf-8"
3338
3424
  );
@@ -3363,7 +3449,8 @@ Saved to: ${join16(outputDir, "autonoma-config.json")}`,
3363
3449
  state.entities[entityName].recipeData,
3364
3450
  testResult.feedback,
3365
3451
  model,
3366
- outputDir
3452
+ outputDir,
3453
+ state.entities
3367
3454
  );
3368
3455
  state.entities[entityName].recipeData = revised;
3369
3456
  await saveRecipeState(outputDir, state);
@@ -3423,7 +3510,79 @@ When done, call finish with the instructions text.`;
3423
3510
 
3424
3511
  // src/agents/04-recipe-builder/phases/full-validation.ts
3425
3512
  import * as p5 from "@clack/prompts";
3426
- async function runFullValidation(state, _models, outputDir) {
3513
+ import { tool as tool15 } from "ai";
3514
+ import { z as z15 } from "zod";
3515
+ async function reviseFullRecipe(current, feedback, model, outputDir, entityOrder) {
3516
+ let revised;
3517
+ const finishTool = tool15({
3518
+ description: "Submit the revised full recipe: an object mapping each entity name to its array of records.",
3519
+ inputSchema: z15.object({
3520
+ recipe: z15.record(z15.string(), z15.array(z15.record(z15.string(), z15.unknown())))
3521
+ }),
3522
+ execute: async (input) => {
3523
+ revised = input.recipe;
3524
+ return { done: true };
3525
+ }
3526
+ });
3527
+ const { logger, onStepFinish } = buildDefaultStepLogger("revise:full-recipe", 20);
3528
+ await runAgent(
3529
+ {
3530
+ id: "revise-full-recipe",
3531
+ systemPrompt: `You are revising a full test-data recipe based on user feedback after they reviewed the app populated with this data.
3532
+
3533
+ The recipe is an object mapping entity names to arrays of records. Records use:
3534
+ - _alias: a unique id for a record so other records can point to it
3535
+ - _ref: { "_ref": "alias" } points to a parent record's _alias
3536
+
3537
+ Rules:
3538
+ - Apply the user's feedback across whatever entities it touches.
3539
+ - Keep _ref values pointing to aliases that actually exist in the recipe. Never invent a _ref to a missing alias.
3540
+ - Entities are created in this order (parents first): ${entityOrder.join(" \u2192 ")}. A record may only _ref an alias declared by an entity earlier in that order.
3541
+ - Field names/types must match the schema in entity-audit.md.
3542
+ - Read scenarios.md and entity-audit.md from the output directory as needed.
3543
+
3544
+ Return the COMPLETE revised recipe (all entities, not just the changed ones) via finish.`,
3545
+ model,
3546
+ maxSteps: 20,
3547
+ tools: (_heartbeat) => ({
3548
+ read_output: buildReadFileTool(outputDir),
3549
+ finish: finishTool
3550
+ }),
3551
+ onStepFinish
3552
+ },
3553
+ `The user reviewed the app with this test data and said it doesn't look right.
3554
+
3555
+ Current full recipe:
3556
+ ${JSON.stringify(current, null, 2)}
3557
+
3558
+ User feedback:
3559
+ "${feedback}"
3560
+
3561
+ Revise the recipe to address the feedback, then call finish with the complete updated recipe.`,
3562
+ () => revised
3563
+ );
3564
+ logger.summary();
3565
+ return revised;
3566
+ }
3567
+ async function teardown(sdkConfig, refsToken, successMessage) {
3568
+ if (!refsToken) return true;
3569
+ p5.log.step("[Full validation] Tearing down all entities...");
3570
+ let downResult;
3571
+ try {
3572
+ downResult = await down(sdkConfig, refsToken);
3573
+ } catch (err) {
3574
+ p5.log.error(`Full DOWN request failed: ${err instanceof Error ? err.message : String(err)}`);
3575
+ return false;
3576
+ }
3577
+ if (!downResult.ok) {
3578
+ p5.log.error(`Full DOWN failed (HTTP ${downResult.status}):`);
3579
+ console.log(JSON.stringify(downResult.body, null, 2));
3580
+ return false;
3581
+ }
3582
+ p5.log.success(successMessage);
3583
+ return true;
3584
+ }
3585
+ async function runFullValidation(state, _models, outputDir, model) {
3427
3586
  const total = state.entityOrder.length;
3428
3587
  p5.log.info(
3429
3588
  `All individual factories work. Now let's create EVERYTHING together and verify the app looks right with a full dataset. This is the recipe that will run before every test execution.`
@@ -3442,7 +3601,7 @@ async function runFullValidation(state, _models, outputDir) {
3442
3601
  endpointUrl: state.sdkEndpointUrl,
3443
3602
  sharedSecret: state.sharedSecret ?? ""
3444
3603
  };
3445
- const fullRecipe = buildFullRecipe(state.entityOrder, state.entities);
3604
+ let fullRecipe = buildFullRecipe(state.entityOrder, state.entities);
3446
3605
  while (true) {
3447
3606
  const testRunId = `full-${Date.now()}`;
3448
3607
  p5.log.step(`[Full validation] Creating all ${total} entities...`);
@@ -3500,26 +3659,35 @@ async function runFullValidation(state, _models, outputDir) {
3500
3659
  message: "Does the app look right with the test data?"
3501
3660
  });
3502
3661
  if (p5.isCancel(looksGood)) throw new Error("Cancelled");
3503
- if (!looksGood) {
3504
- p5.log.info("You can adjust the recipe by editing recipe.json or re-running individual entities with --resume.");
3662
+ const torndown = await teardown(
3663
+ sdkConfig,
3664
+ refsToken,
3665
+ looksGood ? "Full lifecycle works. All data was created and torn down cleanly." : "Tore down the test data so we can regenerate it."
3666
+ );
3667
+ if (!torndown) return false;
3668
+ if (looksGood) return true;
3669
+ const feedback = await p5.text({
3670
+ message: "What's wrong with the test data? Describe what to change.",
3671
+ placeholder: "e.g. accounts need realistic balances, transactions should reference the right account..."
3672
+ });
3673
+ if (p5.isCancel(feedback) || !feedback.trim()) {
3674
+ p5.log.info("No feedback given. You can edit recipe.json manually and re-run with --resume.");
3675
+ return false;
3505
3676
  }
3506
- if (refsToken) {
3507
- p5.log.step("[Full validation] Tearing down all entities...");
3508
- let downResult;
3509
- try {
3510
- downResult = await down(sdkConfig, refsToken);
3511
- } catch (err) {
3512
- p5.log.error(`Full DOWN request failed: ${err instanceof Error ? err.message : String(err)}`);
3513
- return false;
3514
- }
3515
- if (!downResult.ok) {
3516
- p5.log.error(`Full DOWN failed (HTTP ${downResult.status}):`);
3517
- console.log(JSON.stringify(downResult.body, null, 2));
3518
- return false;
3677
+ p5.log.info("Revising the full recipe based on your feedback...");
3678
+ const revised = await reviseFullRecipe(fullRecipe, feedback.trim(), model, outputDir, state.entityOrder);
3679
+ if (!revised) {
3680
+ p5.log.warn("Couldn't revise automatically. Edit recipe.json manually and re-run with --resume.");
3681
+ return false;
3682
+ }
3683
+ for (const [name, records] of Object.entries(revised)) {
3684
+ if (state.entities[name]) {
3685
+ state.entities[name].recipeData = records;
3519
3686
  }
3520
- p5.log.success("Full lifecycle works. All data was created and torn down cleanly.");
3521
3687
  }
3522
- return true;
3688
+ await saveRecipeState(outputDir, state);
3689
+ fullRecipe = buildFullRecipe(state.entityOrder, state.entities);
3690
+ p5.note(JSON.stringify(fullRecipe, null, 2), "Revised recipe \u2014 re-running full validation", { format: codeNoteFormat });
3523
3691
  }
3524
3692
  }
3525
3693
  var init_full_validation = __esm({
@@ -3527,6 +3695,9 @@ var init_full_validation = __esm({
3527
3695
  "use strict";
3528
3696
  init_esm_shims();
3529
3697
  init_notify();
3698
+ init_agent();
3699
+ init_tools();
3700
+ init_highlight();
3530
3701
  init_state();
3531
3702
  init_recipe();
3532
3703
  init_http_client();
@@ -3632,7 +3803,7 @@ async function runRecipeBuilder(input) {
3632
3803
  }
3633
3804
  }
3634
3805
  if (state.phase === "full-validation") {
3635
- const success = await runFullValidation(state, models, input.outputDir);
3806
+ const success = await runFullValidation(state, models, input.outputDir, model);
3636
3807
  if (success) {
3637
3808
  state.phase = "submit";
3638
3809
  await saveRecipeState(input.outputDir, state);
@@ -3682,22 +3853,22 @@ var init_recipe_builder = __esm({
3682
3853
  });
3683
3854
 
3684
3855
  // src/agents/05-test-generator/rubrics.ts
3685
- import { z as z15 } from "zod";
3856
+ import { z as z16 } from "zod";
3686
3857
  var dimensionResultSchema, structuralIntentRubric, flowCompletenessRubric, uiTextRubric, dataAccuracyRubric, ALL_RUBRICS;
3687
3858
  var init_rubrics = __esm({
3688
3859
  "src/agents/05-test-generator/rubrics.ts"() {
3689
3860
  "use strict";
3690
3861
  init_esm_shims();
3691
- dimensionResultSchema = z15.object({
3692
- pass: z15.boolean(),
3693
- evidence: z15.string().describe("What you checked and found \u2014 cite file paths, line content, or specific strings"),
3694
- suggestion: z15.string().optional().describe("What the planner agent should fix, if failing")
3862
+ dimensionResultSchema = z16.object({
3863
+ pass: z16.boolean(),
3864
+ evidence: z16.string().describe("What you checked and found \u2014 cite file paths, line content, or specific strings"),
3865
+ suggestion: z16.string().optional().describe("What the planner agent should fix, if failing")
3695
3866
  });
3696
3867
  structuralIntentRubric = {
3697
3868
  name: "structural-intent",
3698
3869
  maxSteps: 8,
3699
3870
  dimensions: ["structuralValidity", "intentQuality", "missionAlignment"],
3700
- resultSchema: z15.object({
3871
+ resultSchema: z16.object({
3701
3872
  structuralValidity: dimensionResultSchema.describe(
3702
3873
  "Are all step verbs valid (click/type/scroll/assert/hover/drag/read/refresh)? Are asserts visual-only (no URLs, network, console)? No code selectors? No login steps?"
3703
3874
  ),
@@ -3738,7 +3909,7 @@ When done reviewing, call finish with your structured evaluation.`
3738
3909
  name: "flow-completeness",
3739
3910
  maxSteps: 12,
3740
3911
  dimensions: ["actionCompletion", "mutationVerification"],
3741
- resultSchema: z15.object({
3912
+ resultSchema: z16.object({
3742
3913
  actionCompletion: dimensionResultSchema.describe(
3743
3914
  "Does the test complete a core action and reach an OUTCOME? Not just opening a modal or clicking a tab."
3744
3915
  ),
@@ -3774,7 +3945,7 @@ When done reviewing, call finish with your structured evaluation.`
3774
3945
  name: "ui-text",
3775
3946
  maxSteps: 20,
3776
3947
  dimensions: ["uiTextAuthenticity"],
3777
- resultSchema: z15.object({
3948
+ resultSchema: z16.object({
3778
3949
  uiTextAuthenticity: dimensionResultSchema.describe(
3779
3950
  "Do all quoted strings in steps reference text a human would actually see on screen? Not translation keys, config paths, component names, enum identifiers, or CSS classes."
3780
3951
  )
@@ -3813,7 +3984,7 @@ When done reviewing, call finish with your structured evaluation.`
3813
3984
  name: "data-accuracy",
3814
3985
  maxSteps: 20,
3815
3986
  dimensions: ["dataAccuracy"],
3816
- resultSchema: z15.object({
3987
+ resultSchema: z16.object({
3817
3988
  dataAccuracy: dimensionResultSchema.describe(
3818
3989
  "Do the referenced UI elements (buttons, labels, fields, headings, toasts) actually exist in the source code for this page? Are default states correct? Does all test data (names, values, entities) come from the scenario data \u2014 NOT from other tests?"
3819
3990
  )
@@ -3866,12 +4037,12 @@ When done reviewing, call finish with your structured evaluation.`
3866
4037
  // src/agents/05-test-generator/review-pass.ts
3867
4038
  import { basename } from "path";
3868
4039
  import "ai";
3869
- import { tool as tool15 } from "ai";
4040
+ import { tool as tool16 } from "ai";
3870
4041
  async function runReviewPass(testContent, testPath, rubric, projectRoot, model, scenarioData) {
3871
4042
  let result;
3872
4043
  const agentLabel = `review:${rubric.name}:${basename(testPath)}`;
3873
4044
  const { onStepFinish } = buildDefaultStepLogger(agentLabel, rubric.maxSteps);
3874
- const finishTool = tool15({
4045
+ const finishTool = tool16({
3875
4046
  description: "Submit your structured review. Every dimension must have evidence from your investigation.",
3876
4047
  inputSchema: rubric.resultSchema,
3877
4048
  execute: async (input) => {
@@ -3928,8 +4099,8 @@ var init_review_pass = __esm({
3928
4099
  });
3929
4100
 
3930
4101
  // src/agents/05-test-generator/review.ts
3931
- import { readFile as readFile13 } from "fs/promises";
3932
- import { join as join17, relative as relative5, basename as basename2 } from "path";
4102
+ import { readFile as readFile14 } from "fs/promises";
4103
+ import { join as join20, relative as relative5, basename as basename2 } from "path";
3933
4104
  import { glob as glob4 } from "glob";
3934
4105
  import "ai";
3935
4106
  async function reviewSingleTest(testContent, testPath, projectRoot, model, scenarioData) {
@@ -3956,19 +4127,19 @@ async function reviewSingleTest(testContent, testPath, projectRoot, model, scena
3956
4127
  return merged;
3957
4128
  }
3958
4129
  async function runConsolidatedReview(outputDir, projectRoot, model) {
3959
- const testsDir = join17(outputDir, "qa-tests");
4130
+ const testsDir = join20(outputDir, "qa-tests");
3960
4131
  const logger = createStepLogger("review", 5);
3961
4132
  let scenarioData;
3962
4133
  try {
3963
- scenarioData = await readFile13(join17(outputDir, "scenarios.md"), "utf-8");
4134
+ scenarioData = await readFile14(join20(outputDir, "scenarios.md"), "utf-8");
3964
4135
  } catch {
3965
4136
  }
3966
- const testFiles = await glob4(join17(testsDir, "**/*.md"));
4137
+ const testFiles = await glob4(join20(testsDir, "**/*.md"));
3967
4138
  const tests = [];
3968
4139
  for (const testPath of testFiles) {
3969
4140
  if (basename2(testPath) === "INDEX.md") continue;
3970
4141
  if (testPath.includes("/_invalid/")) continue;
3971
- const content = await readFile13(testPath, "utf-8");
4142
+ const content = await readFile14(testPath, "utf-8");
3972
4143
  const flowMatch = content.match(/^---\n[\s\S]*?flow:\s*["']?([^"'\n]+)["']?\s*\n[\s\S]*?---/m);
3973
4144
  tests.push({
3974
4145
  path: testPath,
@@ -4045,16 +4216,16 @@ var init_review2 = __esm({
4045
4216
  });
4046
4217
 
4047
4218
  // src/agents/05-test-generator/graph.ts
4048
- import { readFile as readFile14, writeFile as writeFile8 } from "fs/promises";
4049
- import { join as join18 } from "path";
4219
+ import { readFile as readFile15, writeFile as writeFile8 } from "fs/promises";
4220
+ import { join as join21 } from "path";
4050
4221
  async function saveBfsState(outputDir, state) {
4051
- const path3 = join18(outputDir, STATE_FILE3);
4222
+ const path3 = join21(outputDir, STATE_FILE3);
4052
4223
  await writeFile8(path3, JSON.stringify(state.serialize(), null, 2), "utf-8");
4053
4224
  }
4054
4225
  async function loadBfsState(outputDir) {
4055
- const path3 = join18(outputDir, STATE_FILE3);
4226
+ const path3 = join21(outputDir, STATE_FILE3);
4056
4227
  try {
4057
- const raw = await readFile14(path3, "utf-8");
4228
+ const raw = await readFile15(path3, "utf-8");
4058
4229
  return CoverageState.deserialize(JSON.parse(raw));
4059
4230
  } catch {
4060
4231
  return null;
@@ -4146,17 +4317,17 @@ var init_graph = __esm({
4146
4317
  });
4147
4318
 
4148
4319
  // src/agents/00b-feature-discovery/index.ts
4149
- import { readFile as readFile15, writeFile as writeFile9 } from "fs/promises";
4150
- import { join as join19 } from "path";
4151
- import { z as z16 } from "zod";
4152
- import { tool as tool16 } from "ai";
4320
+ import { readFile as readFile16, writeFile as writeFile9 } from "fs/promises";
4321
+ import { join as join22 } from "path";
4322
+ import { z as z17 } from "zod";
4323
+ import { tool as tool17 } from "ai";
4153
4324
  async function saveFeatures(outputDir, features) {
4154
4325
  const obj = Object.fromEntries(features);
4155
- await writeFile9(join19(outputDir, FEATURES_FILE), JSON.stringify(obj, null, 2), "utf-8");
4326
+ await writeFile9(join22(outputDir, FEATURES_FILE), JSON.stringify(obj, null, 2), "utf-8");
4156
4327
  }
4157
4328
  async function loadFeatures(outputDir) {
4158
4329
  try {
4159
- const raw = await readFile15(join19(outputDir, FEATURES_FILE), "utf-8");
4330
+ const raw = await readFile16(join22(outputDir, FEATURES_FILE), "utf-8");
4160
4331
  const obj = JSON.parse(raw);
4161
4332
  return new Map(Object.entries(obj));
4162
4333
  } catch {
@@ -4187,10 +4358,10 @@ Process every page. Call add_feature for each sub-feature you discover. When don
4187
4358
  const tools = await buildCodebaseTools(model, input.projectRoot, input.outputDir, heartbeat);
4188
4359
  return {
4189
4360
  ...tools,
4190
- add_feature: tool16({
4361
+ add_feature: tool17({
4191
4362
  description: "Add a discovered sub-feature",
4192
4363
  inputSchema: Feature.extend({
4193
- id: z16.string().min(1).describe("Unique kebab-case ID (e.g. 'settings-notifications-tab')")
4364
+ id: z17.string().min(1).describe("Unique kebab-case ID (e.g. 'settings-notifications-tab')")
4194
4365
  }),
4195
4366
  execute: (featureInput) => {
4196
4367
  const { id, ...rest } = featureInput;
@@ -4202,19 +4373,19 @@ Process every page. Call add_feature for each sub-feature you discover. When don
4202
4373
  return `Feature "${id}" added (${collector.features.size} total)`;
4203
4374
  }
4204
4375
  }),
4205
- view_features: tool16({
4376
+ view_features: tool17({
4206
4377
  description: "View all discovered features so far",
4207
- inputSchema: z16.object({}),
4378
+ inputSchema: z17.object({}),
4208
4379
  execute: () => collector.viewFeatures()
4209
4380
  }),
4210
- view_pages: tool16({
4381
+ view_pages: tool17({
4211
4382
  description: "View the pages list to know what to analyze",
4212
- inputSchema: z16.object({}),
4383
+ inputSchema: z17.object({}),
4213
4384
  execute: () => pagesDescription
4214
4385
  }),
4215
- finish: tool16({
4386
+ finish: tool17({
4216
4387
  description: "Signal that feature discovery is complete",
4217
- inputSchema: z16.object({ summary: z16.string() }),
4388
+ inputSchema: z17.object({ summary: z17.string() }),
4218
4389
  execute: async (finishInput) => {
4219
4390
  result = {
4220
4391
  success: true,
@@ -4245,13 +4416,13 @@ var init_b_feature_discovery = __esm({
4245
4416
  init_model();
4246
4417
  init_tools();
4247
4418
  FEATURES_FILE = "features.json";
4248
- Feature = z16.object({
4249
- name: z16.string().min(1).describe("Human-readable name (e.g. 'Settings > Notifications Tab', 'Create Project Modal')"),
4250
- type: z16.enum(["tab", "modal", "form", "table", "wizard", "nested-route", "complex-component"]),
4251
- parentPagePath: z16.string().min(1).describe("The page path this feature belongs to (from the pages list)"),
4252
- sourceFiles: z16.array(z16.string()).min(1).describe("Relative paths to the source files for this sub-feature"),
4253
- interactiveElements: z16.number().int().min(0).describe("Count of interactive elements found (buttons, inputs, toggles, etc.)"),
4254
- description: z16.string().min(10).describe("What this sub-feature does")
4419
+ Feature = z17.object({
4420
+ name: z17.string().min(1).describe("Human-readable name (e.g. 'Settings > Notifications Tab', 'Create Project Modal')"),
4421
+ type: z17.enum(["tab", "modal", "form", "table", "wizard", "nested-route", "complex-component"]),
4422
+ parentPagePath: z17.string().min(1).describe("The page path this feature belongs to (from the pages list)"),
4423
+ sourceFiles: z17.array(z17.string()).min(1).describe("Relative paths to the source files for this sub-feature"),
4424
+ interactiveElements: z17.number().int().min(0).describe("Count of interactive elements found (buttons, inputs, toggles, etc.)"),
4425
+ description: z17.string().min(10).describe("What this sub-feature does")
4255
4426
  });
4256
4427
  FeatureCollector = class {
4257
4428
  features = /* @__PURE__ */ new Map();
@@ -4332,14 +4503,14 @@ Use kebab-case IDs that indicate the parent page and feature type:
4332
4503
  });
4333
4504
 
4334
4505
  // src/agents/05-test-generator/validation.ts
4335
- import matter from "gray-matter";
4506
+ import matter2 from "gray-matter";
4336
4507
  function validateTestContent(content) {
4337
4508
  const errors = [];
4338
4509
  if (!/^---\n[\s\S]*?\n---/.test(content)) {
4339
4510
  errors.push("Missing frontmatter");
4340
4511
  } else {
4341
4512
  try {
4342
- const { data } = matter(content);
4513
+ const { data } = matter2(content);
4343
4514
  if (!data.verification || typeof data.verification !== "string" || data.verification.length < 20) {
4344
4515
  errors.push("Missing or insufficient 'verification' field in frontmatter \u2014 must describe WHERE to navigate and WHAT to assert at the source of truth");
4345
4516
  }
@@ -4394,18 +4565,18 @@ var init_validation = __esm({
4394
4565
 
4395
4566
  // src/agents/05-test-generator/tools.ts
4396
4567
  import { mkdir as mkdir3, writeFile as writeFile10 } from "fs/promises";
4397
- import { dirname as dirname2, join as join20 } from "path";
4398
- import { hasToolCall as hasToolCall3, stepCountIs as stepCountIs3, tool as tool17, ToolLoopAgent as ToolLoopAgent3 } from "ai";
4399
- import matter2 from "gray-matter";
4400
- import { z as z17 } from "zod";
4568
+ import { dirname as dirname2, join as join23 } from "path";
4569
+ import { hasToolCall as hasToolCall3, stepCountIs as stepCountIs3, tool as tool18, ToolLoopAgent as ToolLoopAgent3 } from "ai";
4570
+ import matter3 from "gray-matter";
4571
+ import { z as z18 } from "zod";
4401
4572
  function buildWriteTestTool(state, outputDir) {
4402
- return tool17({
4573
+ return tool18({
4403
4574
  description: "Write a test file to qa-tests/{folder}/{filename}.md. Validates frontmatter before writing. Returns error if frontmatter is invalid.",
4404
- inputSchema: z17.object({
4405
- folder: z17.string().describe("Subfolder name under qa-tests/"),
4406
- filename: z17.string().describe("File name (e.g. login-valid-credentials.md)"),
4407
- content: z17.string().describe("Full file content including YAML frontmatter"),
4408
- nodeId: z17.string().describe("The FeatureNode ID this test belongs to")
4575
+ inputSchema: z18.object({
4576
+ folder: z18.string().describe("Subfolder name under qa-tests/"),
4577
+ filename: z18.string().describe("File name (e.g. login-valid-credentials.md)"),
4578
+ content: z18.string().describe("Full file content including YAML frontmatter"),
4579
+ nodeId: z18.string().describe("The FeatureNode ID this test belongs to")
4409
4580
  }),
4410
4581
  execute: async (input) => {
4411
4582
  const frontmatter = extractFrontmatter(input.content);
@@ -4454,8 +4625,8 @@ function buildWriteTestTool(state, outputDir) {
4454
4625
  };
4455
4626
  }
4456
4627
  }
4457
- const relPath = join20("qa-tests", input.folder, input.filename);
4458
- const absPath = join20(outputDir, relPath);
4628
+ const relPath = join23("qa-tests", input.folder, input.filename);
4629
+ const absPath = join23(outputDir, relPath);
4459
4630
  try {
4460
4631
  await mkdir3(dirname2(absPath), { recursive: true });
4461
4632
  await writeFile10(absPath, input.content, "utf-8");
@@ -4470,16 +4641,16 @@ function buildWriteTestTool(state, outputDir) {
4470
4641
  });
4471
4642
  }
4472
4643
  function buildCreateFolderTool(outputDir) {
4473
- return tool17({
4644
+ return tool18({
4474
4645
  description: "Create a folder under qa-tests/ for organizing tests.",
4475
- inputSchema: z17.object({
4476
- folder: z17.string().describe("Folder name (kebab-case)")
4646
+ inputSchema: z18.object({
4647
+ folder: z18.string().describe("Folder name (kebab-case)")
4477
4648
  }),
4478
4649
  execute: async (input) => {
4479
- const absPath = join20(outputDir, "qa-tests", input.folder);
4650
+ const absPath = join23(outputDir, "qa-tests", input.folder);
4480
4651
  try {
4481
4652
  await mkdir3(absPath, { recursive: true });
4482
- return { path: join20("qa-tests", input.folder) };
4653
+ return { path: join23("qa-tests", input.folder) };
4483
4654
  } catch (err) {
4484
4655
  const message = err instanceof Error ? err.message : String(err);
4485
4656
  return { error: `Failed to create folder: ${message}` };
@@ -4488,9 +4659,9 @@ function buildCreateFolderTool(outputDir) {
4488
4659
  });
4489
4660
  }
4490
4661
  function buildNextNodeTool(state, outputDir) {
4491
- return tool17({
4662
+ return tool18({
4492
4663
  description: "Get the next node to write tests for. If you called next_node before without writing any tests (via write_test), the previous node is auto-skipped. Returns done:true when all nodes are processed.",
4493
- inputSchema: z17.object({}),
4664
+ inputSchema: z18.object({}),
4494
4665
  execute: async () => {
4495
4666
  const next = state.nextNode();
4496
4667
  await saveBfsState(outputDir, state);
@@ -4517,9 +4688,9 @@ function buildNextNodeTool(state, outputDir) {
4517
4688
  });
4518
4689
  }
4519
4690
  function buildGetProgressTool(state) {
4520
- return tool17({
4691
+ return tool18({
4521
4692
  description: "Check how many nodes have been tested vs how many remain.",
4522
- inputSchema: z17.object({}),
4693
+ inputSchema: z18.object({}),
4523
4694
  execute: async () => {
4524
4695
  const stats = state.summary();
4525
4696
  const nodes = [...state.nodes.values()].map((n) => ({
@@ -4533,14 +4704,14 @@ function buildGetProgressTool(state) {
4533
4704
  });
4534
4705
  }
4535
4706
  function buildSpawnResearcherTool(model, workingDirectory, onHeartbeat) {
4536
- return tool17({
4707
+ return tool18({
4537
4708
  description: "Spawn a research subagent to read and analyze source files without polluting your context. Use for complex sub-features where you don't want to read 20 files yourself.",
4538
- inputSchema: z17.object({
4539
- instruction: z17.string().describe("What to research \u2014 be specific about files and what to look for")
4709
+ inputSchema: z18.object({
4710
+ instruction: z18.string().describe("What to research \u2014 be specific about files and what to look for")
4540
4711
  }),
4541
4712
  execute: async (input) => {
4542
- const resultSchema2 = z17.object({
4543
- findings: z17.string().describe("Summary of what was found")
4713
+ const resultSchema2 = z18.object({
4714
+ findings: z18.string().describe("Summary of what was found")
4544
4715
  });
4545
4716
  let result;
4546
4717
  const subagent = new ToolLoopAgent3({
@@ -4551,7 +4722,7 @@ function buildSpawnResearcherTool(model, workingDirectory, onHeartbeat) {
4551
4722
  glob: buildGlobTool(workingDirectory),
4552
4723
  grep: buildGrepTool(workingDirectory),
4553
4724
  read_file: buildReadFileTool(workingDirectory),
4554
- finish: tool17({
4725
+ finish: tool18({
4555
4726
  description: "Report your findings.",
4556
4727
  inputSchema: resultSchema2,
4557
4728
  execute: async (output) => {
@@ -4578,7 +4749,7 @@ function buildSpawnResearcherTool(model, workingDirectory, onHeartbeat) {
4578
4749
  }
4579
4750
  function extractFrontmatter(content) {
4580
4751
  try {
4581
- const { data } = matter2(content);
4752
+ const { data } = matter3(content);
4582
4753
  return data && Object.keys(data).length > 0 ? data : null;
4583
4754
  } catch {
4584
4755
  return null;
@@ -4592,14 +4763,14 @@ var init_tools2 = __esm({
4592
4763
  init_tools();
4593
4764
  init_graph();
4594
4765
  init_validation();
4595
- testFrontmatterSchema = z17.object({
4596
- title: z17.string().min(1),
4597
- description: z17.string().min(1),
4598
- intent: z17.string().min(30, "Intent must be at least 30 characters \u2014 describe the BEHAVIOR being tested, not the steps"),
4599
- criticality: z17.enum(["critical", "high", "mid", "low"]),
4600
- scenario: z17.string().min(1),
4601
- flow: z17.string().min(1),
4602
- verification: z17.string().min(20, "Verification must describe WHERE to navigate and WHAT to assert at the source of truth \u2014 not UI acknowledgments like toasts")
4766
+ testFrontmatterSchema = z18.object({
4767
+ title: z18.string().min(1),
4768
+ description: z18.string().min(1),
4769
+ intent: z18.string().min(30, "Intent must be at least 30 characters \u2014 describe the BEHAVIOR being tested, not the steps"),
4770
+ criticality: z18.enum(["critical", "high", "mid", "low"]),
4771
+ scenario: z18.string().min(1),
4772
+ flow: z18.string().min(1),
4773
+ verification: z18.string().min(20, "Verification must describe WHERE to navigate and WHAT to assert at the source of truth \u2014 not UI acknowledgments like toasts")
4603
4774
  });
4604
4775
  }
4605
4776
  });
@@ -4995,10 +5166,10 @@ var test_generator_exports = {};
4995
5166
  __export(test_generator_exports, {
4996
5167
  runTestGenerator: () => runTestGenerator
4997
5168
  });
4998
- import { mkdir as mkdir4, readFile as readFile16, rmdir, unlink, writeFile as writeFile11 } from "fs/promises";
4999
- import { basename as basename3, join as join21 } from "path";
5000
- import { tool as tool18 } from "ai";
5001
- import { z as z18 } from "zod";
5169
+ import { mkdir as mkdir4, readFile as readFile17, rmdir, unlink, writeFile as writeFile11 } from "fs/promises";
5170
+ import { basename as basename3, join as join24 } from "path";
5171
+ import { tool as tool19 } from "ai";
5172
+ import { z as z19 } from "zod";
5002
5173
  import { glob as glob5 } from "glob";
5003
5174
  async function preseedQueue(state, projectRoot, pages, features) {
5004
5175
  let seeded = 0;
@@ -5046,10 +5217,10 @@ async function runTestGenerator(input) {
5046
5217
  const existingState = await loadBfsState(input.outputDir);
5047
5218
  const state = existingState ?? new CoverageState();
5048
5219
  let result;
5049
- const finishTool = tool18({
5220
+ const finishTool = tool19({
5050
5221
  description: "Call when the BFS queue is empty and all routes have been explored.",
5051
- inputSchema: z18.object({
5052
- summary: z18.string().describe("Coverage summary")
5222
+ inputSchema: z19.object({
5223
+ summary: z19.string().describe("Coverage summary")
5053
5224
  }),
5054
5225
  execute: async (finishInput) => {
5055
5226
  const stats = state.summary();
@@ -5078,8 +5249,8 @@ async function runTestGenerator(input) {
5078
5249
  });
5079
5250
  let kbContext = "";
5080
5251
  try {
5081
- const autonomaMd = await readFile16(
5082
- join21(input.outputDir, "AUTONOMA.md"),
5252
+ const autonomaMd = await readFile17(
5253
+ join24(input.outputDir, "AUTONOMA.md"),
5083
5254
  "utf-8"
5084
5255
  );
5085
5256
  kbContext += `
@@ -5090,8 +5261,8 @@ ${autonomaMd}
5090
5261
  } catch {
5091
5262
  }
5092
5263
  try {
5093
- const scenariosMd = await readFile16(
5094
- join21(input.outputDir, "scenarios.md"),
5264
+ const scenariosMd = await readFile17(
5265
+ join24(input.outputDir, "scenarios.md"),
5095
5266
  "utf-8"
5096
5267
  );
5097
5268
  kbContext += `
@@ -5287,18 +5458,18 @@ IMPORTANT: Do NOT try to finish early. Process every node via next_node until it
5287
5458
  console.log(` Fix pass complete`);
5288
5459
  }
5289
5460
  const allTestFiles = await glob5(
5290
- join21(input.outputDir, "qa-tests", "**/*.md")
5461
+ join24(input.outputDir, "qa-tests", "**/*.md")
5291
5462
  );
5292
5463
  let markedInvalid = 0;
5293
5464
  for (const testPath of allTestFiles) {
5294
5465
  if (basename3(testPath) === "INDEX.md") continue;
5295
5466
  if (testPath.includes("/_invalid/")) continue;
5296
- const content = await readFile16(testPath, "utf-8");
5467
+ const content = await readFile17(testPath, "utf-8");
5297
5468
  const validation = validateTestContent(content);
5298
5469
  if (!validation.valid) {
5299
- const invalidDir = join21(input.outputDir, "qa-tests", "_invalid");
5470
+ const invalidDir = join24(input.outputDir, "qa-tests", "_invalid");
5300
5471
  await mkdir4(invalidDir, { recursive: true });
5301
- const dest = join21(invalidDir, basename3(testPath));
5472
+ const dest = join24(invalidDir, basename3(testPath));
5302
5473
  const annotated = `<!-- VALIDATION ERRORS: ${validation.errors.join("; ")} -->
5303
5474
  ${content}`;
5304
5475
  await writeFile11(dest, annotated, "utf-8");
@@ -5311,7 +5482,7 @@ ${content}`;
5311
5482
  ` ${markedInvalid} tests still invalid after review cycles \u2014 moved to _invalid/`
5312
5483
  );
5313
5484
  }
5314
- const dirs = await glob5(join21(input.outputDir, "qa-tests", "**/"), {
5485
+ const dirs = await glob5(join24(input.outputDir, "qa-tests", "**/"), {
5315
5486
  dot: false
5316
5487
  });
5317
5488
  for (const dir of dirs.sort((a, b) => b.length - a.length)) {
@@ -5403,7 +5574,7 @@ async function generateIndex(outputDir, state) {
5403
5574
  for (const paths of state.testsWritten.values()) {
5404
5575
  for (const p9 of paths) {
5405
5576
  try {
5406
- const content2 = await readFile16(join21(outputDir, p9), "utf-8");
5577
+ const content2 = await readFile17(join24(outputDir, p9), "utf-8");
5407
5578
  const critMatch = content2.match(/criticality:\s*(\w+)/);
5408
5579
  const critVal = critMatch?.[1] ?? "";
5409
5580
  if (critCounts.has(critVal))
@@ -5454,26 +5625,26 @@ ${folders.map((f) => `| ${f.name} | ${f.test_count} |`).join("\n")}
5454
5625
 
5455
5626
  ${[...testsByFolder.entries()].flatMap(([_folder, tests]) => tests.map((t) => `- \`${t}\``)).join("\n")}
5456
5627
  `;
5457
- await writeFile11(join21(outputDir, "qa-tests", "INDEX.md"), content, "utf-8");
5628
+ await writeFile11(join24(outputDir, "qa-tests", "INDEX.md"), content, "utf-8");
5458
5629
  }
5459
5630
  async function generateJourneyTests(outputDir, model, projectRoot) {
5460
5631
  const logger = createStepLogger("journeys", 50);
5461
5632
  let autonomaMd = "";
5462
5633
  let scenariosMd = "";
5463
5634
  try {
5464
- autonomaMd = await readFile16(join21(outputDir, "AUTONOMA.md"), "utf-8");
5635
+ autonomaMd = await readFile17(join24(outputDir, "AUTONOMA.md"), "utf-8");
5465
5636
  } catch {
5466
5637
  }
5467
5638
  try {
5468
- scenariosMd = await readFile16(join21(outputDir, "scenarios.md"), "utf-8");
5639
+ scenariosMd = await readFile17(join24(outputDir, "scenarios.md"), "utf-8");
5469
5640
  } catch {
5470
5641
  }
5471
5642
  if (!autonomaMd) return 0;
5472
- const existingTests = await glob5(join21(outputDir, "qa-tests", "**/*.md"));
5643
+ const existingTests = await glob5(join24(outputDir, "qa-tests", "**/*.md"));
5473
5644
  const existingTitles = [];
5474
5645
  for (const t of existingTests) {
5475
5646
  if (basename3(t) === "INDEX.md") continue;
5476
- const content = await readFile16(t, "utf-8");
5647
+ const content = await readFile17(t, "utf-8");
5477
5648
  const titleMatch = content.match(/title:\s*"([^"]+)"/);
5478
5649
  if (titleMatch) existingTitles.push(titleMatch[1]);
5479
5650
  }
@@ -5516,9 +5687,9 @@ Write 5-8 journey tests using the write_test tool with folder "journeys". Then c
5516
5687
  status: "queued"
5517
5688
  });
5518
5689
  let journeyResult;
5519
- const journeyFinish = tool18({
5690
+ const journeyFinish = tool19({
5520
5691
  description: "Signal journey generation is complete.",
5521
- inputSchema: z18.object({ summary: z18.string() }),
5692
+ inputSchema: z19.object({ summary: z19.string() }),
5522
5693
  execute: async (finishInput) => {
5523
5694
  journeyResult = {
5524
5695
  success: true,
@@ -5578,17 +5749,90 @@ var init_test_generator = __esm({
5578
5749
  // src/index.ts
5579
5750
  init_esm_shims();
5580
5751
  import * as p8 from "@clack/prompts";
5581
- import { readFile as readFile17, writeFile as writeFile12 } from "fs/promises";
5582
- import { join as join22 } from "path";
5752
+ import { readFile as readFile18, writeFile as writeFile12 } from "fs/promises";
5753
+ import { join as join25 } from "path";
5583
5754
 
5584
5755
  // src/config.ts
5585
5756
  init_esm_shims();
5586
- import { resolve, join } from "path";
5587
- import { readFileSync } from "fs";
5757
+ import { resolve, join as join2 } from "path";
5758
+ import { readFileSync as readFileSync2 } from "fs";
5759
+
5760
+ // src/core/global-env.ts
5761
+ init_esm_shims();
5762
+ import { readFileSync, writeFileSync, mkdirSync } from "fs";
5763
+ import { join } from "path";
5764
+ import { homedir } from "os";
5765
+ var AUTONOMA_HOME = join(homedir(), ".autonoma");
5766
+ var GLOBAL_ENV_PATH = join(AUTONOMA_HOME, ".env");
5767
+ function getGlobalEnvPath() {
5768
+ return GLOBAL_ENV_PATH;
5769
+ }
5770
+ function parseEnvContent(content) {
5771
+ const out = {};
5772
+ for (const line of content.split("\n")) {
5773
+ const trimmed = line.trim();
5774
+ if (!trimmed || trimmed.startsWith("#")) continue;
5775
+ const eqIdx = trimmed.indexOf("=");
5776
+ if (eqIdx === -1) continue;
5777
+ const key = trimmed.slice(0, eqIdx).trim();
5778
+ let value = trimmed.slice(eqIdx + 1).trim();
5779
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
5780
+ value = value.slice(1, -1);
5781
+ }
5782
+ out[key] = value;
5783
+ }
5784
+ return out;
5785
+ }
5786
+ function loadGlobalEnv() {
5787
+ let content;
5788
+ try {
5789
+ content = readFileSync(GLOBAL_ENV_PATH, "utf-8");
5790
+ } catch {
5791
+ return;
5792
+ }
5793
+ for (const [key, value] of Object.entries(parseEnvContent(content))) {
5794
+ if (!(key in process.env)) {
5795
+ process.env[key] = value;
5796
+ }
5797
+ }
5798
+ }
5799
+ function setGlobalEnv(key, value) {
5800
+ mkdirSync(AUTONOMA_HOME, { recursive: true });
5801
+ let lines = [];
5802
+ try {
5803
+ lines = readFileSync(GLOBAL_ENV_PATH, "utf-8").split("\n");
5804
+ } catch {
5805
+ lines = [];
5806
+ }
5807
+ const serialized = `${key}=${value}`;
5808
+ let replaced = false;
5809
+ lines = lines.map((line) => {
5810
+ const trimmed = line.trim();
5811
+ if (trimmed.startsWith("#") || !trimmed.includes("=")) return line;
5812
+ const lineKey = trimmed.slice(0, trimmed.indexOf("=")).trim();
5813
+ if (lineKey === key) {
5814
+ replaced = true;
5815
+ return serialized;
5816
+ }
5817
+ return line;
5818
+ });
5819
+ if (!replaced) {
5820
+ if (lines.length > 0 && lines[lines.length - 1].trim() === "") {
5821
+ lines.splice(lines.length - 1, 0, serialized);
5822
+ } else {
5823
+ lines.push(serialized);
5824
+ }
5825
+ }
5826
+ const output = lines.join("\n").replace(/\n*$/, "\n");
5827
+ writeFileSync(GLOBAL_ENV_PATH, output, { encoding: "utf-8", mode: 384 });
5828
+ process.env[key] = value;
5829
+ }
5830
+
5831
+ // src/config.ts
5588
5832
  function loadProjectEnv(projectRoot) {
5589
5833
  let content;
5590
5834
  try {
5591
- content = readFileSync(join(projectRoot, ".env"), "utf-8");
5835
+ content = readFileSync2(join2(projectRoot, ".env"), "utf-8");
5592
5836
  } catch {
5593
5837
  return;
5594
5838
  }
@@ -5610,6 +5854,7 @@ function loadProjectEnv(projectRoot) {
5610
5854
  function loadConfig(args) {
5611
5855
  const projectRoot = resolve(args.project ?? process.cwd());
5612
5856
  loadProjectEnv(projectRoot);
5857
+ loadGlobalEnv();
5613
5858
  const projectSlug = args.slug ?? projectRoot.split("/").pop()?.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") ?? "default";
5614
5859
  return {
5615
5860
  projectRoot,
@@ -5632,11 +5877,11 @@ init_model();
5632
5877
  // src/core/output.ts
5633
5878
  init_esm_shims();
5634
5879
  import { mkdir } from "fs/promises";
5635
- import { join as join3 } from "path";
5636
- import { homedir } from "os";
5637
- var AUTONOMA_HOME = join3(homedir(), ".autonoma");
5880
+ import { join as join4 } from "path";
5881
+ import { homedir as homedir2 } from "os";
5882
+ var AUTONOMA_HOME2 = join4(homedir2(), ".autonoma");
5638
5883
  function getOutputDir(projectSlug) {
5639
- return join3(AUTONOMA_HOME, projectSlug);
5884
+ return join4(AUTONOMA_HOME2, projectSlug);
5640
5885
  }
5641
5886
  async function ensureOutputDir(projectSlug) {
5642
5887
  const dir = getOutputDir(projectSlug);
@@ -5644,10 +5889,140 @@ async function ensureOutputDir(projectSlug) {
5644
5889
  return dir;
5645
5890
  }
5646
5891
 
5892
+ // src/core/interrupt.ts
5893
+ init_esm_shims();
5894
+ import readline from "readline";
5895
+ import { settings } from "@clack/core";
5896
+ var DIM = "\x1B[2m";
5897
+ var RESET = "\x1B[0m";
5898
+ var SHOW_CURSOR = "\x1B[?25h";
5899
+ var EXIT_HINT = `${DIM}(press Ctrl+C again to exit)${RESET}`;
5900
+ var ARM_WINDOW_MS = 3e3;
5901
+ var installed = false;
5902
+ var armed = false;
5903
+ var armTimer = null;
5904
+ var onExit = null;
5905
+ function disarm() {
5906
+ if (armTimer) clearTimeout(armTimer);
5907
+ armTimer = null;
5908
+ armed = false;
5909
+ }
5910
+ function handleInterrupt() {
5911
+ if (armed) {
5912
+ disarm();
5913
+ onExit?.();
5914
+ return;
5915
+ }
5916
+ armed = true;
5917
+ process.stderr.write(`
5918
+ ${EXIT_HINT}
5919
+ `);
5920
+ armTimer = setTimeout(disarm, ARM_WINDOW_MS);
5921
+ }
5922
+ function installInterruptHandler(opts) {
5923
+ onExit = opts.onExit;
5924
+ if (installed) return;
5925
+ installed = true;
5926
+ settings.aliases.delete("escape");
5927
+ process.on("SIGINT", handleInterrupt);
5928
+ const original = readline.createInterface.bind(readline);
5929
+ readline.createInterface = ((...args) => {
5930
+ const iface = original(...args);
5931
+ iface.on("SIGINT", handleInterrupt);
5932
+ return iface;
5933
+ });
5934
+ }
5935
+ function restoreTerminal() {
5936
+ try {
5937
+ if (process.stdin.isTTY) process.stdin.setRawMode(false);
5938
+ } catch {
5939
+ }
5940
+ process.stdout.write(SHOW_CURSOR);
5941
+ }
5942
+
5943
+ // src/core/analytics.ts
5944
+ init_esm_shims();
5945
+ import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2 } from "fs";
5946
+ import { join as join5 } from "path";
5947
+ import { homedir as homedir3 } from "os";
5948
+ import { randomUUID } from "crypto";
5949
+ var AUTONOMA_HOME3 = join5(homedir3(), ".autonoma");
5950
+ var DEVICE_ID_PATH = join5(AUTONOMA_HOME3, ".device-id");
5951
+ var POSTHOG_PUBLIC_KEY = "phc_mUOwUj62r8vyiisFPvXLC3G5RftETIBMnKNSHqTBdka";
5952
+ var DEFAULT_HOST = "https://us.i.posthog.com";
5953
+ function resolveKey() {
5954
+ return (process.env.AUTONOMA_POSTHOG_KEY ?? POSTHOG_PUBLIC_KEY).trim();
5955
+ }
5956
+ function resolveHost() {
5957
+ return (process.env.AUTONOMA_POSTHOG_HOST ?? DEFAULT_HOST).replace(/\/+$/, "");
5958
+ }
5959
+ function trackingDisabled() {
5960
+ const v = process.env.DONT_TRACK;
5961
+ return v === "1" || v === "true";
5962
+ }
5963
+ function getIdentity() {
5964
+ const id = process.env.AUTONOMA_DISTINCT_ID?.trim();
5965
+ return id && id.length > 0 ? id : void 0;
5966
+ }
5967
+ var cachedDeviceId = null;
5968
+ function getDeviceId() {
5969
+ if (cachedDeviceId) return cachedDeviceId;
5970
+ try {
5971
+ cachedDeviceId = readFileSync3(DEVICE_ID_PATH, "utf-8").trim();
5972
+ if (cachedDeviceId) return cachedDeviceId;
5973
+ } catch {
5974
+ }
5975
+ cachedDeviceId = randomUUID();
5976
+ try {
5977
+ mkdirSync2(AUTONOMA_HOME3, { recursive: true });
5978
+ writeFileSync2(DEVICE_ID_PATH, cachedDeviceId, { encoding: "utf-8", mode: 384 });
5979
+ } catch {
5980
+ }
5981
+ return cachedDeviceId;
5982
+ }
5983
+ var enabled = null;
5984
+ function isEnabled() {
5985
+ if (enabled === null) {
5986
+ enabled = !trackingDisabled() && resolveKey().length > 0;
5987
+ }
5988
+ return enabled;
5989
+ }
5990
+ var pending = /* @__PURE__ */ new Set();
5991
+ function track(event, properties = {}) {
5992
+ if (!isEnabled()) return;
5993
+ const identity = getIdentity();
5994
+ const body = JSON.stringify({
5995
+ api_key: resolveKey(),
5996
+ event,
5997
+ distinct_id: identity ?? getDeviceId(),
5998
+ properties: {
5999
+ ...properties,
6000
+ // Only build a person profile when we have a real identity from the app,
6001
+ // so the CLI joins the existing funnel person instead of creating a new one.
6002
+ $process_person_profile: identity != null,
6003
+ cli_version: process.env.npm_package_version
6004
+ }
6005
+ });
6006
+ const promise = fetch(`${resolveHost()}/capture/`, {
6007
+ method: "POST",
6008
+ headers: { "Content-Type": "application/json" },
6009
+ body
6010
+ }).catch(() => {
6011
+ }).finally(() => pending.delete(promise));
6012
+ pending.add(promise);
6013
+ }
6014
+ async function flushAnalytics(timeoutMs = 1500) {
6015
+ if (pending.size === 0) return;
6016
+ await Promise.race([
6017
+ Promise.allSettled([...pending]),
6018
+ new Promise((resolve5) => setTimeout(resolve5, timeoutMs))
6019
+ ]);
6020
+ }
6021
+
5647
6022
  // src/core/state.ts
5648
6023
  init_esm_shims();
5649
6024
  import { readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
5650
- import { join as join4 } from "path";
6025
+ import { join as join6 } from "path";
5651
6026
  var STATE_FILE = ".pipeline-state.json";
5652
6027
  function initialState() {
5653
6028
  return {
@@ -5662,7 +6037,7 @@ function initialState() {
5662
6037
  };
5663
6038
  }
5664
6039
  async function loadState(outputDir) {
5665
- const path3 = join4(outputDir, STATE_FILE);
6040
+ const path3 = join6(outputDir, STATE_FILE);
5666
6041
  try {
5667
6042
  const raw = await readFile2(path3, "utf-8");
5668
6043
  return JSON.parse(raw);
@@ -5671,7 +6046,7 @@ async function loadState(outputDir) {
5671
6046
  }
5672
6047
  }
5673
6048
  async function saveState(outputDir, state) {
5674
- const path3 = join4(outputDir, STATE_FILE);
6049
+ const path3 = join6(outputDir, STATE_FILE);
5675
6050
  await writeFile2(path3, JSON.stringify(state, null, 2), "utf-8");
5676
6051
  }
5677
6052
  async function markStep(outputDir, state, step, status) {
@@ -5691,11 +6066,11 @@ function nextPendingStep(state) {
5691
6066
  var PAGES_FILE = "pages.json";
5692
6067
  async function savePages(outputDir, pages) {
5693
6068
  const obj = Object.fromEntries(pages);
5694
- await writeFile12(join22(outputDir, PAGES_FILE), JSON.stringify(obj, null, 2), "utf-8");
6069
+ await writeFile12(join25(outputDir, PAGES_FILE), JSON.stringify(obj, null, 2), "utf-8");
5695
6070
  }
5696
6071
  async function loadPages(outputDir) {
5697
6072
  try {
5698
- const raw = await readFile17(join22(outputDir, PAGES_FILE), "utf-8");
6073
+ const raw = await readFile18(join25(outputDir, PAGES_FILE), "utf-8");
5699
6074
  const obj = JSON.parse(raw);
5700
6075
  return new Map(Object.entries(obj));
5701
6076
  } catch {
@@ -5732,12 +6107,14 @@ var STEP_INTROS = {
5732
6107
  kb: "Reading every page file to build a knowledge base (AUTONOMA.md). This gives the AI context about your features, flows, and UI patterns.",
5733
6108
  entityAudit: "Identifying every database model and tracing how each gets created \u2014 which service function, what side effects. This determines which entities need test data factories.",
5734
6109
  scenarioRecipe: "Designing test data scenarios with realistic values from your entity audit. The scenario defines exactly WHAT data will exist in the database during tests.",
5735
- recipeBuilder: "Guiding you through implementing Autonoma SDK factories for each entity. You'll implement each factory and we'll test them live (create + teardown) before moving on.",
6110
+ recipeBuilder: "Guiding you through implementing Autonoma SDK factories for each entity. For each one we give you a copy-paste guide to hand to Claude (or your AI assistant), which implements the factory in your codebase. Work locally: run your app on localhost and we'll test each factory live (create + teardown) against it. You deploy later, once everything passes.",
5736
6111
  testGenerator: "Generating exhaustive E2E test cases by exploring every page and feature. Each area gets test coverage proportional to its complexity."
5737
6112
  };
5738
6113
  async function runStep(step, outputDir, state, config, projectContext, nonInteractive) {
5739
6114
  const label = STEP_LABELS[step];
5740
6115
  p8.note(STEP_INTROS[step], `Step: ${label}`);
6116
+ const stepStartedAt = Date.now();
6117
+ track("cli_step_started", { step });
5741
6118
  state = await markStep(outputDir, state, step, "running");
5742
6119
  if (step !== "pagesFinder" && projectContext && !projectContext.pages) {
5743
6120
  const pages = await loadPages(outputDir);
@@ -5837,6 +6214,11 @@ async function runStep(step, outputDir, state, config, projectContext, nonIntera
5837
6214
  const message = err instanceof Error ? err.message : String(err);
5838
6215
  p8.log.error(`Failed: ${label} \u2014 ${message}`);
5839
6216
  }
6217
+ track("cli_step_completed", {
6218
+ step,
6219
+ status: state.steps[step],
6220
+ duration_ms: Date.now() - stepStartedAt
6221
+ });
5840
6222
  return state;
5841
6223
  }
5842
6224
  async function showStatus(outputDir) {
@@ -5849,15 +6231,33 @@ async function showStatus(outputDir) {
5849
6231
  }
5850
6232
  }
5851
6233
  var BANNER = `
5852
- \x1B[36m\x1B[1m ___ _
5853
- / _ \\ | |
5854
- / /_\\ \\_ _| |_ ___ _ __ ___ _ __ ___ __ _
5855
- | _ | | | | __/ _ \\| '_ \\ / _ \\| '_ \` _ \\ / _\` |
5856
- | | | | |_| | || (_) | | | | (_) | | | | | | (_| |
5857
- \\_| |_/\\__,_|\\__\\___/|_| |_|\\___/|_| |_| |_|\\__,_|
6234
+ \x1B[36m\x1B[1m \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557
6235
+ \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
6236
+ \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551
6237
+ \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551
6238
+ \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551
6239
+ \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D
5858
6240
  \x1B[0m
5859
6241
  \x1B[2m E2E Test Planner \u2014 Generate exhaustive test suites from your codebase\x1B[0m
5860
6242
  `;
6243
+ async function ensureOpenRouterKey(nonInteractive) {
6244
+ if (process.env.OPENROUTER_API_KEY) return true;
6245
+ if (nonInteractive) {
6246
+ p8.log.error(
6247
+ "OPENROUTER_API_KEY is not set. Set it in your environment or run interactively once to save it."
6248
+ );
6249
+ return false;
6250
+ }
6251
+ p8.log.info("You'll need an OpenRouter API key to run the planner. Get one at https://openrouter.ai/keys");
6252
+ const key = await p8.password({
6253
+ message: "Paste your OpenRouter API key",
6254
+ validate: (value) => (value ?? "").trim().length === 0 ? "API key cannot be empty" : void 0
6255
+ });
6256
+ if (p8.isCancel(key)) return false;
6257
+ setGlobalEnv("OPENROUTER_API_KEY", key.trim());
6258
+ p8.log.success(`Saved your API key to ${getGlobalEnvPath()} \u2014 you won't be asked again.`);
6259
+ return true;
6260
+ }
5861
6261
  async function gatherProjectContext() {
5862
6262
  const description = await p8.text({
5863
6263
  message: "What is this project? (a short description so the agent knows what it's looking at)",
@@ -5905,18 +6305,34 @@ async function main() {
5905
6305
  }
5906
6306
  console.log(BANNER);
5907
6307
  p8.intro("Let's generate your test suite");
6308
+ const resumeCommand = `autonoma-planner --resume` + (args.project ? ` --project ${args.project}` : "");
6309
+ installInterruptHandler({
6310
+ onExit: () => {
6311
+ track("cli_run_exited");
6312
+ restoreTerminal();
6313
+ console.log("");
6314
+ p8.log.warn(`Your progress is saved. To resume, run:
6315
+ ${resumeCommand}`);
6316
+ void flushAnalytics().finally(() => process.exit(0));
6317
+ }
6318
+ });
5908
6319
  const config = loadConfig({
5909
6320
  project: args.project,
5910
6321
  model: args.model,
5911
6322
  slug: args.slug
5912
6323
  });
6324
+ const nonInteractive = !!args["non-interactive"];
6325
+ if (!await ensureOpenRouterKey(nonInteractive)) {
6326
+ p8.log.warn("Cancelled.");
6327
+ return;
6328
+ }
5913
6329
  const modelName = config.modelId ?? process.env.OPENROUTER_MODEL ?? DEFAULT_MODEL;
5914
6330
  if (!args.project) {
5915
6331
  p8.log.info(`No --project flag passed; using current working directory.`);
5916
6332
  }
5917
6333
  p8.log.info(`Project: ${config.projectRoot}`);
5918
6334
  p8.log.info(`Model: ${modelName}`);
5919
- const nonInteractive = !!args["non-interactive"];
6335
+ track("cli_run_started", { model: modelName, non_interactive: nonInteractive });
5920
6336
  const outputDir = await ensureOutputDir(config.projectSlug);
5921
6337
  let state = await loadState(outputDir);
5922
6338
  let isResuming = !!(args.resume || args.step);
@@ -5956,7 +6372,14 @@ async function main() {
5956
6372
  }
5957
6373
  await saveContext(outputDir, projectContext);
5958
6374
  }
5959
- p8.log.step(`Output: ${outputDir}`);
6375
+ p8.note(
6376
+ `${outputDir}
6377
+
6378
+ All generated files (knowledge base, scenarios, recipe, tests) live here.
6379
+ It's a hidden folder in your home directory \u2014 in Finder/Explorer use "Go to folder"
6380
+ or reveal hidden files (macOS: Cmd+Shift+. ) to see it.`,
6381
+ "Output folder"
6382
+ );
5960
6383
  console.log("");
5961
6384
  p8.log.info(
5962
6385
  `Got it. I'll focus on: ${projectContext.criticalFlows}
@@ -5991,7 +6414,8 @@ async function main() {
5991
6414
  p8.log.error("Pipeline stopped due to failure.");
5992
6415
  break;
5993
6416
  }
5994
- if (i < steps.length - 1 && !nonInteractive) {
6417
+ const skipConfirmAfter = ["pagesFinder"];
6418
+ if (i < steps.length - 1 && !nonInteractive && !skipConfirmAfter.includes(step)) {
5995
6419
  const nextStep = steps[i + 1];
5996
6420
  const shouldContinue = await p8.confirm({
5997
6421
  message: `Continue to ${STEP_LABELS[nextStep]}?`
@@ -6009,10 +6433,13 @@ async function main() {
6009
6433
  }
6010
6434
  throw err;
6011
6435
  }
6436
+ const stepsDone = Object.values(state.steps).filter((s) => s === "done").length;
6437
+ track("cli_run_completed", { steps_done: stepsDone });
6012
6438
  p8.outro("Done");
6013
6439
  }
6014
- main().catch((err) => {
6440
+ main().then(() => flushAnalytics()).catch(async (err) => {
6015
6441
  console.error(err);
6442
+ await flushAnalytics();
6016
6443
  process.exit(1);
6017
6444
  });
6018
6445
  //# sourceMappingURL=index.js.map