e2e-ai 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,10 +1,14 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ loadAgent,
4
+ scanCodebase
5
+ } from "./cli-g7cc13w2.js";
2
6
  import {
3
7
  getPackageRoot,
4
8
  getProjectRoot,
5
9
  loadConfig
6
- } from "./cli-2rnyej02.js";
7
- import"./cli-qnzwv17s.js";
10
+ } from "./cli-ba9d3pdp.js";
11
+ import"./cli-ph82pe4b.js";
8
12
  import {
9
13
  __commonJS,
10
14
  __export,
@@ -6436,101 +6440,7 @@ function formatTime(sec) {
6436
6440
  }
6437
6441
 
6438
6442
  // src/commands/scenario.ts
6439
- import { join as join7 } from "node:path";
6440
-
6441
- // src/agents/loadAgent.ts
6442
- import { readFileSync as readFileSync2, existsSync as existsSync2 } from "node:fs";
6443
- import { join as join5 } from "node:path";
6444
- function loadAgent(agentName, config) {
6445
- const agentDir = join5(getPackageRoot(), "agents");
6446
- const filePath = join5(agentDir, `${agentName}.md`);
6447
- let content;
6448
- try {
6449
- content = readFileSync2(filePath, "utf-8");
6450
- } catch {
6451
- throw new Error(`Agent file not found: ${filePath}`);
6452
- }
6453
- const { frontmatter, body } = parseFrontmatter(content);
6454
- const agentConfig = extractConfig(frontmatter);
6455
- let systemPrompt = body;
6456
- if (config) {
6457
- const contextPath = join5(getProjectRoot(), config.contextFile);
6458
- if (existsSync2(contextPath)) {
6459
- const projectContext = readFileSync2(contextPath, "utf-8").trim();
6460
- if (projectContext) {
6461
- systemPrompt = `${body}
6462
-
6463
- ## Project Context
6464
-
6465
- ${projectContext}`;
6466
- }
6467
- }
6468
- if (config.llm.agentModels[agentName]) {
6469
- agentConfig.model = config.llm.agentModels[agentName];
6470
- }
6471
- }
6472
- const sections = parseSections(body);
6473
- return {
6474
- name: frontmatter.agent ?? agentName,
6475
- systemPrompt,
6476
- inputSchema: sections["Input Schema"],
6477
- outputSchema: sections["Output Schema"],
6478
- rules: sections["Rules"],
6479
- example: sections["Example"],
6480
- config: agentConfig
6481
- };
6482
- }
6483
- function parseFrontmatter(content) {
6484
- const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
6485
- if (!match)
6486
- return { frontmatter: {}, body: content };
6487
- const frontmatter = {};
6488
- for (const line of match[1].split(`
6489
- `)) {
6490
- const colonIdx = line.indexOf(":");
6491
- if (colonIdx === -1)
6492
- continue;
6493
- const key = line.slice(0, colonIdx).trim();
6494
- let value = line.slice(colonIdx + 1).trim();
6495
- if (value.startsWith('"') && value.endsWith('"'))
6496
- value = value.slice(1, -1);
6497
- if (value === "true")
6498
- value = true;
6499
- if (value === "false")
6500
- value = false;
6501
- if (!isNaN(Number(value)) && value !== "")
6502
- value = Number(value);
6503
- frontmatter[key] = value;
6504
- }
6505
- return { frontmatter, body: match[2] };
6506
- }
6507
- function extractConfig(frontmatter) {
6508
- return {
6509
- model: frontmatter.model,
6510
- maxTokens: frontmatter.max_tokens ?? 4096,
6511
- temperature: frontmatter.temperature ?? 0.2
6512
- };
6513
- }
6514
- function parseSections(body) {
6515
- const sections = {};
6516
- const headingRegex = /^##\s+(.+)$/gm;
6517
- const headings = [];
6518
- let match;
6519
- while ((match = headingRegex.exec(body)) !== null) {
6520
- headings.push({ title: match[1].trim(), index: match.index });
6521
- }
6522
- const systemMatch = body.match(/^#\s+System Prompt\n([\s\S]*?)(?=\n##\s|$)/m);
6523
- if (systemMatch) {
6524
- sections["System Prompt"] = systemMatch[1].trim();
6525
- }
6526
- for (let i = 0;i < headings.length; i++) {
6527
- const start = headings[i].index + body.slice(headings[i].index).indexOf(`
6528
- `) + 1;
6529
- const end = i + 1 < headings.length ? headings[i + 1].index : body.length;
6530
- sections[headings[i].title] = body.slice(start, end).trim();
6531
- }
6532
- return sections;
6533
- }
6443
+ import { join as join6 } from "node:path";
6534
6444
 
6535
6445
  // src/agents/callLLM.ts
6536
6446
  var DEFAULT_MODELS = {
@@ -6676,9 +6586,9 @@ function extractYAML(content) {
6676
6586
  import { dirname as dirname3 } from "node:path";
6677
6587
 
6678
6588
  // src/integrations/jira.ts
6679
- import { join as join6 } from "node:path";
6589
+ import { join as join5 } from "node:path";
6680
6590
  async function fetchJiraContext(key, config, workingDir) {
6681
- const jsonPath = join6(workingDir, key, `${key}-zephyr-test-case.json`);
6591
+ const jsonPath = join5(workingDir, key, `${key}-zephyr-test-case.json`);
6682
6592
  if (!fileExists(jsonPath))
6683
6593
  return null;
6684
6594
  const data = JSON.parse(readFile(jsonPath));
@@ -6839,8 +6749,8 @@ function registerScenario(program2) {
6839
6749
  let codegenContent;
6840
6750
  let transcriptContent;
6841
6751
  if (ctx.key) {
6842
- const keyDir = join7(ctx.paths.workingDir, ctx.key);
6843
- const recordingsDir = join7(keyDir, "recordings");
6752
+ const keyDir = join6(ctx.paths.workingDir, ctx.key);
6753
+ const recordingsDir = join6(keyDir, "recordings");
6844
6754
  const codegenFile = findFileWithPattern(keyDir, /codegen-.*\.ts$/);
6845
6755
  const transcriptFile = findFileWithPattern(keyDir, /transcript\.json$/) ?? findFileWithPattern(recordingsDir, /voice-.*\.json$/) ?? findFileWithPattern(keyDir, /voice-.*\.json$/);
6846
6756
  if (codegenFile)
@@ -6848,8 +6758,8 @@ function registerScenario(program2) {
6848
6758
  if (transcriptFile)
6849
6759
  transcriptContent = readFile(transcriptFile);
6850
6760
  } else if (session) {
6851
- const codegenPath = join7(ctx.paths.recordingsDir, `${session}.ts`);
6852
- const transcriptPath = join7(ctx.paths.transcriptsDir, `${session}-transcript.json`);
6761
+ const codegenPath = join6(ctx.paths.recordingsDir, `${session}.ts`);
6762
+ const transcriptPath = join6(ctx.paths.transcriptsDir, `${session}-transcript.json`);
6853
6763
  if (fileExists(codegenPath))
6854
6764
  codegenContent = readFile(codegenPath);
6855
6765
  if (fileExists(transcriptPath))
@@ -6914,8 +6824,8 @@ function registerScenario(program2) {
6914
6824
  spinner2.stop();
6915
6825
  const scenarioYaml = extractYAML(scenarioResponse.content);
6916
6826
  const scenarioName = ctx.key ?? session ?? "scenario";
6917
- const scenarioDir = join7(ctx.paths.testsDir, scenarioName);
6918
- const scenarioPath = join7(scenarioDir, `${scenarioName}.yaml`);
6827
+ const scenarioDir = join6(ctx.paths.testsDir, scenarioName);
6828
+ const scenarioPath = join6(scenarioDir, `${scenarioName}.yaml`);
6919
6829
  ensureDir(scenarioDir);
6920
6830
  writeFile(scenarioPath, scenarioYaml);
6921
6831
  success(`Scenario saved: ${scenarioPath}`);
@@ -6923,18 +6833,18 @@ function registerScenario(program2) {
6923
6833
  }
6924
6834
 
6925
6835
  // src/commands/generate.ts
6926
- import { join as join8, basename as basename2 } from "node:path";
6836
+ import { join as join7, basename as basename2 } from "node:path";
6927
6837
  function registerGenerate(program2) {
6928
6838
  program2.command("generate [scenario]").description("Generate Playwright test from YAML scenario").action(async (scenarioArg) => {
6929
6839
  const ctx = await resolveCommandContext(program2);
6930
6840
  const root = ctx.paths.projectRoot;
6931
6841
  let scenarioPath;
6932
- if (scenarioArg && fileExists(join8(root, scenarioArg))) {
6933
- scenarioPath = join8(root, scenarioArg);
6842
+ if (scenarioArg && fileExists(join7(root, scenarioArg))) {
6843
+ scenarioPath = join7(root, scenarioArg);
6934
6844
  } else if (ctx.key) {
6935
- scenarioPath = join8(ctx.paths.testsDir, ctx.key, `${ctx.key}.yaml`);
6845
+ scenarioPath = join7(ctx.paths.testsDir, ctx.key, `${ctx.key}.yaml`);
6936
6846
  } else if (scenarioArg) {
6937
- scenarioPath = join8(ctx.paths.testsDir, scenarioArg, `${scenarioArg}.yaml`);
6847
+ scenarioPath = join7(ctx.paths.testsDir, scenarioArg, `${scenarioArg}.yaml`);
6938
6848
  } else {
6939
6849
  error("Provide a scenario file path or --key");
6940
6850
  process.exit(1);
@@ -6966,8 +6876,8 @@ function registerGenerate(program2) {
6966
6876
  testContent = testContent.replace(/^```\w*\n/, "").replace(/\n```$/, "");
6967
6877
  }
6968
6878
  const testName = scenario.issueKey ?? ctx.key ?? basename2(scenarioPath, ".yaml");
6969
- const testDir = join8(ctx.paths.testsDir, testName);
6970
- const testPath = join8(testDir, `${testName}.test.ts`);
6879
+ const testDir = join7(ctx.paths.testsDir, testName);
6880
+ const testPath = join7(testDir, `${testName}.test.ts`);
6971
6881
  ensureDir(testDir);
6972
6882
  writeFile(testPath, testContent);
6973
6883
  success(`Test generated: ${testPath}`);
@@ -6992,16 +6902,16 @@ function registerGenerate(program2) {
6992
6902
  }
6993
6903
 
6994
6904
  // src/commands/refine.ts
6995
- import { join as join9 } from "node:path";
6905
+ import { join as join8 } from "node:path";
6996
6906
  function registerRefine(program2) {
6997
6907
  program2.command("refine [test]").description("Refactor/improve test with AI").action(async (testArg) => {
6998
6908
  const ctx = await resolveCommandContext(program2);
6999
6909
  const root = ctx.paths.projectRoot;
7000
6910
  let testPath;
7001
- if (testArg && fileExists(join9(root, testArg))) {
7002
- testPath = join9(root, testArg);
6911
+ if (testArg && fileExists(join8(root, testArg))) {
6912
+ testPath = join8(root, testArg);
7003
6913
  } else if (ctx.key) {
7004
- testPath = join9(ctx.paths.testsDir, ctx.key, `${ctx.key}.test.ts`);
6914
+ testPath = join8(ctx.paths.testsDir, ctx.key, `${ctx.key}.test.ts`);
7005
6915
  } else {
7006
6916
  error("Provide a test file path or --key");
7007
6917
  process.exit(1);
@@ -7038,16 +6948,16 @@ function registerRefine(program2) {
7038
6948
  }
7039
6949
 
7040
6950
  // src/commands/test.ts
7041
- import { join as join10 } from "node:path";
6951
+ import { join as join9 } from "node:path";
7042
6952
  function registerTest(program2) {
7043
6953
  program2.command("test [test]").description("Run Playwright test with traces").action(async (testArg) => {
7044
6954
  const ctx = await resolveCommandContext(program2);
7045
6955
  const root = ctx.paths.projectRoot;
7046
6956
  let testPath;
7047
- if (testArg && fileExists(join10(root, testArg))) {
7048
- testPath = join10(root, testArg);
6957
+ if (testArg && fileExists(join9(root, testArg))) {
6958
+ testPath = join9(root, testArg);
7049
6959
  } else if (ctx.key) {
7050
- testPath = join10(ctx.paths.testsDir, ctx.key, `${ctx.key}.test.ts`);
6960
+ testPath = join9(ctx.paths.testsDir, ctx.key, `${ctx.key}.test.ts`);
7051
6961
  } else {
7052
6962
  error("Provide a test file path or --key");
7053
6963
  process.exit(1);
@@ -7082,7 +6992,7 @@ async function runPlaywrightTest(testPath, root) {
7082
6992
  "--project",
7083
6993
  config.playwright.browser
7084
6994
  ];
7085
- const pkgConfigPath = join10(projectRoot, "packages", "e2e-ai", "playwright.e2e-ai.config.ts");
6995
+ const pkgConfigPath = join9(projectRoot, "packages", "e2e-ai", "playwright.e2e-ai.config.ts");
7086
6996
  if (fileExists(pkgConfigPath)) {
7087
6997
  args.push("--config", pkgConfigPath);
7088
6998
  }
@@ -7109,17 +7019,17 @@ async function runPlaywrightTest(testPath, root) {
7109
7019
  }
7110
7020
 
7111
7021
  // src/commands/heal.ts
7112
- import { join as join11 } from "node:path";
7022
+ import { join as join10 } from "node:path";
7113
7023
  var MAX_HEAL_RETRIES = 3;
7114
7024
  function registerHeal(program2) {
7115
7025
  program2.command("heal [test]").description("Self-heal a failing test").action(async (testArg) => {
7116
7026
  const ctx = await resolveCommandContext(program2);
7117
7027
  const root = ctx.paths.projectRoot;
7118
7028
  let testPath;
7119
- if (testArg && fileExists(join11(root, testArg))) {
7120
- testPath = join11(root, testArg);
7029
+ if (testArg && fileExists(join10(root, testArg))) {
7030
+ testPath = join10(root, testArg);
7121
7031
  } else if (ctx.key) {
7122
- testPath = join11(ctx.paths.testsDir, ctx.key, `${ctx.key}.test.ts`);
7032
+ testPath = join10(ctx.paths.testsDir, ctx.key, `${ctx.key}.test.ts`);
7123
7033
  } else {
7124
7034
  error("Provide a test file path or --key");
7125
7035
  process.exit(1);
@@ -7192,16 +7102,16 @@ function registerHeal(program2) {
7192
7102
  }
7193
7103
 
7194
7104
  // src/commands/qa.ts
7195
- import { join as join12 } from "node:path";
7105
+ import { join as join11 } from "node:path";
7196
7106
  function registerQa(program2) {
7197
7107
  program2.command("qa [test]").description("Generate QA documentation").action(async (testArg) => {
7198
7108
  const ctx = await resolveCommandContext(program2);
7199
7109
  const root = ctx.paths.projectRoot;
7200
7110
  let testPath;
7201
- if (testArg && fileExists(join12(root, testArg))) {
7202
- testPath = join12(root, testArg);
7111
+ if (testArg && fileExists(join11(root, testArg))) {
7112
+ testPath = join11(root, testArg);
7203
7113
  } else if (ctx.key) {
7204
- testPath = join12(ctx.paths.testsDir, ctx.key, `${ctx.key}.test.ts`);
7114
+ testPath = join11(ctx.paths.testsDir, ctx.key, `${ctx.key}.test.ts`);
7205
7115
  } else {
7206
7116
  error("Provide a test file path or --key");
7207
7117
  process.exit(1);
@@ -7213,7 +7123,7 @@ function registerQa(program2) {
7213
7123
  const testContent = readFile(testPath);
7214
7124
  let scenario;
7215
7125
  if (ctx.key) {
7216
- const scenarioPath = join12(ctx.paths.testsDir, ctx.key, `${ctx.key}.yaml`);
7126
+ const scenarioPath = join11(ctx.paths.testsDir, ctx.key, `${ctx.key}.yaml`);
7217
7127
  if (fileExists(scenarioPath)) {
7218
7128
  const yaml = await import("./index-54ycasgv.js");
7219
7129
  scenario = yaml.parse(readFile(scenarioPath));
@@ -7223,7 +7133,7 @@ function registerQa(program2) {
7223
7133
  let existingTestCase;
7224
7134
  if (ctx.key) {
7225
7135
  issueContext = await fetchIssueContext(ctx.key, ctx.config, ctx.paths);
7226
- const existingJsonPath = join12(ctx.paths.workingDir, ctx.key, `${ctx.key}-zephyr-test-case.json`);
7136
+ const existingJsonPath = join11(ctx.paths.workingDir, ctx.key, `${ctx.key}-zephyr-test-case.json`);
7227
7137
  if (fileExists(existingJsonPath)) {
7228
7138
  existingTestCase = JSON.parse(readFile(existingJsonPath));
7229
7139
  }
@@ -7261,7 +7171,7 @@ function registerQa(program2) {
7261
7171
  if (qaResult.markdown && ctx.config.outputTarget !== "zephyr") {
7262
7172
  const qaDir = ctx.paths.qaDir;
7263
7173
  const testId = ctx.key ?? "test";
7264
- const qaMdPath = join12(qaDir, `${testId}.md`);
7174
+ const qaMdPath = join11(qaDir, `${testId}.md`);
7265
7175
  ensureDir(qaDir);
7266
7176
  writeFile(qaMdPath, qaResult.markdown);
7267
7177
  success(`QA document: ${qaMdPath}`);
@@ -7271,7 +7181,7 @@ function registerQa(program2) {
7271
7181
  }
7272
7182
 
7273
7183
  // src/commands/run.ts
7274
- import { join as join13 } from "node:path";
7184
+ import { join as join12 } from "node:path";
7275
7185
 
7276
7186
  // src/pipeline/runPipeline.ts
7277
7187
  async function runPipeline(steps, ctx, options) {
@@ -7383,7 +7293,7 @@ function buildSteps() {
7383
7293
  args.push("--no-voice");
7384
7294
  if (ctx.config.noTrace)
7385
7295
  args.push("--no-trace");
7386
- const scriptPath = join13(pkgRoot, "scripts", "codegen-env.mjs");
7296
+ const scriptPath = join12(pkgRoot, "scripts", "codegen-env.mjs");
7387
7297
  const child = spawnInteractive("node", [scriptPath, ...args], {
7388
7298
  cwd: ctx.projectRoot,
7389
7299
  env: {
@@ -7397,8 +7307,8 @@ function buildSteps() {
7397
7307
  if (exitCode !== 0)
7398
7308
  return { success: false, output: null, error: new Error(`Recording exited with code ${exitCode}`) };
7399
7309
  if (ctx.key) {
7400
- ctx.codegenPath = findFileWithPattern(join13(ctx.paths.workingDir, ctx.key), /codegen-.*\.ts$/);
7401
- ctx.audioPath = findFileWithPattern(join13(ctx.paths.workingDir, ctx.key, "recordings"), /\.wav$/);
7310
+ ctx.codegenPath = findFileWithPattern(join12(ctx.paths.workingDir, ctx.key), /codegen-.*\.ts$/);
7311
+ ctx.audioPath = findFileWithPattern(join12(ctx.paths.workingDir, ctx.key, "recordings"), /\.wav$/);
7402
7312
  }
7403
7313
  return { success: true, output: { codegenPath: ctx.codegenPath, audioPath: ctx.audioPath } };
7404
7314
  }
@@ -7413,16 +7323,16 @@ function buildSteps() {
7413
7323
  if (!ctx.audioPath)
7414
7324
  return { success: true, output: null, nonBlocking: true };
7415
7325
  const pkgRoot = getPackageRoot();
7416
- const transcriber = await import(join13(pkgRoot, "scripts", "voice", "transcriber.mjs"));
7326
+ const transcriber = await import(join12(pkgRoot, "scripts", "voice", "transcriber.mjs"));
7417
7327
  const segments = await transcriber.transcribe(ctx.audioPath);
7418
7328
  if (!segments?.length)
7419
7329
  return { success: true, output: { segments: [] }, nonBlocking: true };
7420
- const outputDir = ctx.key ? join13(ctx.paths.workingDir, ctx.key) : ctx.paths.transcriptsDir;
7421
- const jsonPath = join13(outputDir, `${ctx.sessionName}-transcript.json`);
7330
+ const outputDir = ctx.key ? join12(ctx.paths.workingDir, ctx.key) : ctx.paths.transcriptsDir;
7331
+ const jsonPath = join12(outputDir, `${ctx.sessionName}-transcript.json`);
7422
7332
  writeFile(jsonPath, JSON.stringify(segments, null, 2));
7423
7333
  ctx.transcriptPath = jsonPath;
7424
7334
  if (ctx.codegenPath) {
7425
- const merger = await import(join13(pkgRoot, "scripts", "voice", "merger.mjs"));
7335
+ const merger = await import(join12(pkgRoot, "scripts", "voice", "merger.mjs"));
7426
7336
  const content = readFile(ctx.codegenPath);
7427
7337
  const merged = merger.merge(content, segments, segments[segments.length - 1].end);
7428
7338
  writeFile(ctx.codegenPath, merged);
@@ -7473,9 +7383,9 @@ function buildSteps() {
7473
7383
  maxTokens: agent.config.maxTokens,
7474
7384
  temperature: agent.config.temperature
7475
7385
  });
7476
- const scenarioDir = join13(ctx.paths.testsDir, ctx.sessionName);
7386
+ const scenarioDir = join12(ctx.paths.testsDir, ctx.sessionName);
7477
7387
  ensureDir(scenarioDir);
7478
- const scenarioPath = join13(scenarioDir, `${ctx.sessionName}.yaml`);
7388
+ const scenarioPath = join12(scenarioDir, `${ctx.sessionName}.yaml`);
7479
7389
  writeFile(scenarioPath, resp.content.trim());
7480
7390
  ctx.scenarioPath = scenarioPath;
7481
7391
  return { success: true, output: { scenarioPath } };
@@ -7502,8 +7412,8 @@ function buildSteps() {
7502
7412
  if (testContent.startsWith("```"))
7503
7413
  testContent = testContent.replace(/^```\w*\n/, "").replace(/\n```$/, "");
7504
7414
  const testName = ctx.key ?? ctx.sessionName;
7505
- const testDir = join13(ctx.paths.testsDir, testName);
7506
- ctx.testPath = join13(testDir, `${testName}.test.ts`);
7415
+ const testDir = join12(ctx.paths.testsDir, testName);
7416
+ ctx.testPath = join12(testDir, `${testName}.test.ts`);
7507
7417
  ensureDir(testDir);
7508
7418
  writeFile(ctx.testPath, testContent);
7509
7419
  return { success: true, output: { testPath: ctx.testPath } };
@@ -7633,7 +7543,8 @@ function buildSteps() {
7633
7543
  }
7634
7544
 
7635
7545
  // src/commands/init.ts
7636
- import { join as join14 } from "node:path";
7546
+ import { join as join13 } from "node:path";
7547
+ import { readdirSync as readdirSync2, readFileSync as readFileSync2, existsSync as existsSync2 } from "node:fs";
7637
7548
  // node_modules/@inquirer/core/dist/lib/key.js
7638
7549
  var isUpKey = (key, keybindings = []) => key.name === "up" || keybindings.includes("vim") && key.name === "k" || keybindings.includes("emacs") && key.ctrl && key.name === "p";
7639
7550
  var isDownKey = (key, keybindings = []) => key.name === "down" || keybindings.includes("vim") && key.name === "j" || keybindings.includes("emacs") && key.ctrl && key.name === "n";
@@ -9149,7 +9060,7 @@ function registerInit(program2) {
9149
9060
  header("e2e-ai init");
9150
9061
  const answers = cmdOpts?.nonInteractive ? getDefaultAnswers() : await askConfigQuestions();
9151
9062
  const config = buildConfigFromAnswers(answers);
9152
- const configPath = join14(projectRoot, "e2e-ai.config.ts");
9063
+ const configPath = join13(projectRoot, "e2e-ai.config.ts");
9153
9064
  if (fileExists(configPath)) {
9154
9065
  warn(`Config already exists: ${configPath}`);
9155
9066
  const overwrite = cmdOpts?.nonInteractive ? false : await dist_default4({ message: "Overwrite existing config?", default: false });
@@ -9163,29 +9074,28 @@ function registerInit(program2) {
9163
9074
  writeFile(configPath, generateConfigFile(config));
9164
9075
  success(`Config written: ${configPath}`);
9165
9076
  }
9166
- if (!cmdOpts?.nonInteractive) {
9167
- const opts = program2.opts();
9168
- const provider = opts.provider ?? process.env.AI_PROVIDER ?? answers.provider ?? "openai";
9169
- const model = opts.model ?? process.env.AI_MODEL;
9170
- const spinner = createSpinner();
9171
- spinner.start("Scanning codebase for test patterns...");
9172
- const scan = await scanCodebase(projectRoot);
9173
- spinner.stop();
9174
- if (scan.testFiles.length === 0 && scan.configFiles.length === 0) {
9175
- warn("No test files found. Skipping context generation.");
9176
- info("You can create e2e-ai.context.md manually later.");
9177
- } else {
9178
- info(`Found ${scan.testFiles.length} test files, ${scan.configFiles.length} config files`);
9179
- const contextContent = await runInitConversation(scan, provider, model);
9180
- if (contextContent) {
9181
- const contextPath = join14(projectRoot, config.contextFile ?? "e2e-ai.context.md");
9182
- writeFile(contextPath, contextContent);
9183
- success(`Context file written: ${contextPath}`);
9184
- }
9185
- }
9186
- }
9187
- success(`
9188
- Initialization complete!`);
9077
+ const spinner = createSpinner();
9078
+ spinner.start("Scanning codebase for test patterns...");
9079
+ const scan = await scanCodebase(projectRoot);
9080
+ spinner.stop();
9081
+ if (scan.testFiles.length === 0 && scan.configFiles.length === 0) {
9082
+ warn("No test files found. Scan results will be minimal.");
9083
+ } else {
9084
+ info(`Found ${scan.testFiles.length} test files, ${scan.configFiles.length} config files`);
9085
+ }
9086
+ const instructionsContent = generateInstructionsFile(scan);
9087
+ const instructionsPath = join13(projectRoot, "e2e-ai.instructions.md");
9088
+ writeFile(instructionsPath, instructionsContent);
9089
+ success(`Instructions written: ${instructionsPath}`);
9090
+ const copiedCount = await copyAgentsToLocal(projectRoot, !!cmdOpts?.nonInteractive);
9091
+ console.log("");
9092
+ success(`Initialization complete!
9093
+ `);
9094
+ console.log(import_picocolors2.default.bold("Next steps:"));
9095
+ console.log(` 1. Open ${import_picocolors2.default.cyan("e2e-ai.instructions.md")} with your AI tool`);
9096
+ console.log(` 2. Review the generated ${import_picocolors2.default.cyan(".e2e-ai/context.md")}`);
9097
+ console.log(` 3. Customize agents in ${import_picocolors2.default.cyan(".e2e-ai/agents/")} if needed`);
9098
+ console.log(` 4. Run: ${import_picocolors2.default.cyan("e2e-ai run --key PROJ-101")}`);
9189
9099
  });
9190
9100
  }
9191
9101
  function getDefaultAnswers() {
@@ -9248,7 +9158,7 @@ function buildConfigFromAnswers(answers) {
9248
9158
  outputTarget: answers.outputTarget,
9249
9159
  voice: { enabled: answers.voiceEnabled },
9250
9160
  llm: { provider: answers.provider },
9251
- contextFile: "e2e-ai.context.md"
9161
+ contextFile: ".e2e-ai/context.md"
9252
9162
  };
9253
9163
  if (answers.baseUrl) {
9254
9164
  config.baseUrl = answers.baseUrl;
@@ -9280,124 +9190,165 @@ function generateConfigFile(config) {
9280
9190
  return lines.join(`
9281
9191
  `);
9282
9192
  }
9283
- async function scanCodebase(root) {
9284
- const { readdirSync: readdirSync2, existsSync: existsSync3, readFileSync: readFileSync3, statSync } = await import("node:fs");
9285
- const { join: join15, relative } = await import("node:path");
9286
- const scan = {
9287
- testFiles: [],
9288
- configFiles: [],
9289
- fixtureFiles: [],
9290
- featureFiles: [],
9291
- tsconfigPaths: {},
9292
- playwrightConfig: null,
9293
- sampleTestContent: null
9294
- };
9295
- function walk(dir, depth = 0) {
9296
- if (depth > 5)
9297
- return [];
9298
- const files = [];
9299
- try {
9300
- for (const entry of readdirSync2(dir, { withFileTypes: true })) {
9301
- if (entry.name.startsWith(".") || entry.name === "node_modules" || entry.name === "dist")
9302
- continue;
9303
- const full = join15(dir, entry.name);
9304
- if (entry.isDirectory()) {
9305
- files.push(...walk(full, depth + 1));
9306
- } else {
9307
- files.push(full);
9308
- }
9309
- }
9310
- } catch {}
9311
- return files;
9312
- }
9313
- const allFiles = walk(root);
9314
- for (const file of allFiles) {
9315
- const rel = relative(root, file);
9316
- if (rel.endsWith(".test.ts") || rel.endsWith(".spec.ts")) {
9317
- scan.testFiles.push(rel);
9318
- if (!scan.sampleTestContent && scan.testFiles.length <= 3) {
9319
- try {
9320
- scan.sampleTestContent = readFileSync3(file, "utf-8").slice(0, 3000);
9321
- } catch {}
9322
- }
9323
- }
9324
- if (rel.endsWith(".feature.ts"))
9325
- scan.featureFiles.push(rel);
9326
- if (rel.includes("fixture") && rel.endsWith(".ts"))
9327
- scan.fixtureFiles.push(rel);
9328
- if (rel === "playwright.config.ts" || rel === "playwright.config.js")
9329
- scan.playwrightConfig = rel;
9330
- if (rel === "tsconfig.json" || rel.endsWith("/tsconfig.json")) {
9331
- try {
9332
- const tsconfig = JSON.parse(readFileSync3(file, "utf-8"));
9333
- if (tsconfig.compilerOptions?.paths) {
9334
- scan.tsconfigPaths = { ...scan.tsconfigPaths, ...tsconfig.compilerOptions.paths };
9335
- }
9336
- } catch {}
9193
+ function generateInstructionsFile(scan) {
9194
+ const packageRoot = getPackageRoot();
9195
+ const sections = [];
9196
+ sections.push(`# e2e-ai: Context Generation Instructions
9197
+
9198
+ This file was generated by \`e2e-ai init\`. It contains everything an AI tool needs to generate \`.e2e-ai/context.md\` for your project.
9199
+
9200
+ ## How to Use
9201
+
9202
+ 1. Open this file in your AI tool (Claude Code, Cursor, Gemini CLI, etc.)
9203
+ 2. Ask it to follow these instructions to generate \`.e2e-ai/context.md\`
9204
+ 3. Review the generated file and adjust as needed
9205
+
9206
+ Alternatively, if the e2e-ai MCP server is configured, your AI tool can call \`e2e_ai_scan_codebase\` and \`e2e_ai_validate_context\` directly.
9207
+
9208
+ ---`);
9209
+ sections.push(`## Task
9210
+
9211
+ Scan this codebase and generate a file at \`.e2e-ai/context.md\` that documents the project's test infrastructure, conventions, and patterns. This context file is consumed by downstream AI agents (scenario, generator, refiner, healer, QA) to produce Playwright tests that match the project's existing style.`);
9212
+ sections.push(`## Codebase Scan Results
9213
+
9214
+ The following was pre-computed during \`e2e-ai init\`:
9215
+
9216
+ ### Test Files (${scan.testFiles.length} found)
9217
+ ${scan.testFiles.length > 0 ? scan.testFiles.slice(0, 20).map((f) => `- \`${f}\``).join(`
9218
+ `) : "_No test files found_"}
9219
+ ${scan.testFiles.length > 20 ? `
9220
+ _(${scan.testFiles.length - 20} more not shown)_` : ""}
9221
+
9222
+ ### Config Files
9223
+ ${scan.configFiles.length > 0 ? scan.configFiles.map((f) => `- \`${f}\``).join(`
9224
+ `) : "_None found_"}
9225
+
9226
+ ### Fixture Files
9227
+ ${scan.fixtureFiles.length > 0 ? scan.fixtureFiles.slice(0, 10).map((f) => `- \`${f}\``).join(`
9228
+ `) : "_None found_"}
9229
+
9230
+ ### Feature Files
9231
+ ${scan.featureFiles.length > 0 ? scan.featureFiles.slice(0, 20).map((f) => `- \`${f}\``).join(`
9232
+ `) : "_None found_"}
9233
+
9234
+ ### Path Aliases (from tsconfig.json)
9235
+ ${Object.keys(scan.tsconfigPaths).length > 0 ? Object.entries(scan.tsconfigPaths).map(([alias, targets]) => `- \`${alias}\` -> \`${targets.join(", ")}\``).join(`
9236
+ `) : "_None configured_"}
9237
+
9238
+ ### Playwright Config
9239
+ ${scan.playwrightConfig ? `Found: \`${scan.playwrightConfig}\`` : "_Not found_"}
9240
+
9241
+ ### Sample Test Content
9242
+ ${scan.sampleTestContent ? "```typescript\n" + scan.sampleTestContent + "\n```" : "_No sample available_"}`);
9243
+ let agentChecklist = "";
9244
+ try {
9245
+ const agentContent = readFileSync2(join13(packageRoot, "agents", "init-agent.md"), "utf-8");
9246
+ const bodyMatch = agentContent.match(/^---\n[\s\S]*?\n---\n([\s\S]*)$/);
9247
+ if (bodyMatch) {
9248
+ agentChecklist = bodyMatch[1].trim();
9337
9249
  }
9250
+ } catch {}
9251
+ if (agentChecklist) {
9252
+ sections.push(`## What to Look For
9253
+
9254
+ The following guidance comes from the e2e-ai init agent:
9255
+
9256
+ ${agentChecklist}`);
9338
9257
  }
9339
- for (const name of ["playwright.config.ts", "vitest.config.ts", "jest.config.ts", "tsconfig.json", "package.json"]) {
9340
- if (existsSync3(join15(root, name)))
9341
- scan.configFiles.push(name);
9342
- }
9343
- return scan;
9344
- }
9345
- async function runInitConversation(scan, provider, model) {
9346
- const agent = loadAgent("init-agent");
9347
- const separator = import_picocolors2.default.dim("─".repeat(60));
9348
- const messages = [];
9349
- const scanMessage = JSON.stringify({
9350
- testFiles: scan.testFiles.slice(0, 20),
9351
- configFiles: scan.configFiles,
9352
- fixtureFiles: scan.fixtureFiles.slice(0, 10),
9353
- featureFiles: scan.featureFiles.slice(0, 20),
9354
- tsconfigPaths: scan.tsconfigPaths,
9355
- playwrightConfig: scan.playwrightConfig,
9356
- sampleTestContent: scan.sampleTestContent
9357
- }, null, 2);
9358
- messages.push({ role: "user", content: `Here are the scan results from the project:
9258
+ sections.push(`## Output Format
9359
9259
 
9360
- ${scanMessage}` });
9361
- const MAX_TURNS = 5;
9362
- for (let turn = 0;turn < MAX_TURNS; turn++) {
9363
- const userContent = messages.filter((m) => m.role === "user").map((m) => m.content).join(`
9260
+ The generated \`.e2e-ai/context.md\` MUST contain these sections:
9364
9261
 
9365
- ---
9262
+ \`\`\`markdown
9263
+ # Project Context for e2e-ai
9264
+
9265
+ ## Application
9266
+ <name, description, tech stack, base URL>
9267
+
9268
+ ## Test Infrastructure
9269
+ <fixtures, helpers, auth pattern>
9270
+
9271
+ ## Feature Methods
9272
+ <method signatures grouped by module>
9273
+
9274
+ ## Import Conventions
9275
+ <path aliases, standard imports>
9276
+
9277
+ ## Selector Conventions
9278
+ <preferred selector strategies, patterns>
9279
+
9280
+ ## Test Structure Template
9281
+ <code template showing standard test layout>
9282
+
9283
+ ## Utility Patterns
9284
+ <timeouts, waits, assertion patterns>
9285
+ \`\`\`
9286
+
9287
+ All sections are required. The file should be 100-300 lines, self-contained, and use actual code from the project (not generic Playwright examples).`);
9288
+ sections.push(`## How Context is Used
9289
+
9290
+ Each pipeline agent reads \`.e2e-ai/context.md\` to understand project conventions:
9291
+
9292
+ | Agent | Uses context for |
9293
+ |-------|-----------------|
9294
+ | **scenario-agent** | Structuring test steps to match project patterns |
9295
+ | **playwright-generator-agent** | Generating code with correct imports, fixtures, selectors |
9296
+ | **refactor-agent** | Applying project-specific refactoring patterns |
9297
+ | **self-healing-agent** | Understanding expected test structure when fixing failures |
9298
+ | **qa-testcase-agent** | Formatting QA documentation to match conventions |`);
9299
+ let exampleContent = "";
9300
+ try {
9301
+ exampleContent = readFileSync2(join13(packageRoot, "templates", "e2e-ai.context.example.md"), "utf-8");
9302
+ } catch {}
9303
+ if (exampleContent) {
9304
+ sections.push(`## Complete Example
9305
+
9306
+ Below is a full example of a well-structured context file:
9307
+
9308
+ ${exampleContent}`);
9309
+ }
9310
+ return sections.join(`
9366
9311
 
9367
9312
  `);
9368
- const spinner = createSpinner();
9369
- spinner.start("Thinking...");
9370
- const resp = await callLLM({
9371
- provider,
9372
- model: model ?? agent.config.model,
9373
- systemPrompt: agent.systemPrompt,
9374
- userMessage: userContent,
9375
- maxTokens: agent.config.maxTokens,
9376
- temperature: agent.config.temperature
9377
- });
9378
- spinner.stop();
9379
- const assistantContent = resp.content.trim();
9380
- messages.push({ role: "assistant", content: assistantContent });
9381
- const contextMatch = assistantContent.match(/<context>([\s\S]*?)<\/context>/);
9382
- if (contextMatch) {
9383
- return contextMatch[1].trim();
9384
- }
9385
- console.log(`
9386
- ` + separator);
9387
- console.log(assistantContent);
9388
- console.log(separator + `
9389
- `);
9390
- const answer = await dist_default5({
9391
- message: 'Your answer (or "done" to let the agent finalize)'
9392
- });
9393
- if (answer.toLowerCase() === "done") {
9394
- messages.push({ role: "user", content: "Please produce the final context document now based on what you know. Wrap it in <context> tags." });
9395
- } else {
9396
- messages.push({ role: "user", content: answer });
9313
+ }
9314
+ async function copyAgentsToLocal(projectRoot, nonInteractive) {
9315
+ const packageRoot = getPackageRoot();
9316
+ const sourceDir = join13(packageRoot, "agents");
9317
+ const targetDir = join13(projectRoot, ".e2e-ai", "agents");
9318
+ let agentFiles;
9319
+ try {
9320
+ agentFiles = readdirSync2(sourceDir).filter((f) => f.endsWith(".md"));
9321
+ } catch {
9322
+ warn("Could not read package agents directory");
9323
+ return 0;
9324
+ }
9325
+ if (agentFiles.length === 0)
9326
+ return 0;
9327
+ const targetExists = existsSync2(targetDir);
9328
+ if (targetExists) {
9329
+ const existingFiles = readdirSync2(targetDir).filter((f) => f.endsWith(".md"));
9330
+ if (existingFiles.length > 0) {
9331
+ if (nonInteractive) {
9332
+ info("Agent files already exist in .e2e-ai/agents/, skipping");
9333
+ return 0;
9334
+ }
9335
+ const overwrite = await dist_default4({
9336
+ message: `Agent files already exist in .e2e-ai/agents/ (${existingFiles.length} files). Overwrite?`,
9337
+ default: false
9338
+ });
9339
+ if (!overwrite) {
9340
+ info("Skipping agent copy");
9341
+ return 0;
9342
+ }
9397
9343
  }
9398
9344
  }
9399
- warn("Max conversation turns reached. Context may be incomplete.");
9400
- return null;
9345
+ ensureDir(targetDir);
9346
+ for (const file of agentFiles) {
9347
+ const content = readFileSync2(join13(sourceDir, file), "utf-8");
9348
+ writeFile(join13(targetDir, file), content);
9349
+ }
9350
+ success(`Agents copied to .e2e-ai/agents/ (${agentFiles.length} files)`);
9351
+ return agentFiles.length;
9401
9352
  }
9402
9353
 
9403
9354
  // src/cli.ts