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-ba9d3pdp.js +64 -0
- package/dist/cli-g7cc13w2.js +165 -0
- package/dist/cli-ph82pe4b.js +13589 -0
- package/dist/cli.js +231 -280
- package/dist/config/schema.js +1 -1
- package/dist/index.js +2 -2
- package/dist/mcp.js +14978 -0
- package/package.json +5 -3
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-
|
|
7
|
-
import"./cli-
|
|
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
|
|
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
|
|
6589
|
+
import { join as join5 } from "node:path";
|
|
6680
6590
|
async function fetchJiraContext(key, config, workingDir) {
|
|
6681
|
-
const jsonPath =
|
|
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 =
|
|
6843
|
-
const recordingsDir =
|
|
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 =
|
|
6852
|
-
const transcriptPath =
|
|
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 =
|
|
6918
|
-
const scenarioPath =
|
|
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
|
|
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(
|
|
6933
|
-
scenarioPath =
|
|
6842
|
+
if (scenarioArg && fileExists(join7(root, scenarioArg))) {
|
|
6843
|
+
scenarioPath = join7(root, scenarioArg);
|
|
6934
6844
|
} else if (ctx.key) {
|
|
6935
|
-
scenarioPath =
|
|
6845
|
+
scenarioPath = join7(ctx.paths.testsDir, ctx.key, `${ctx.key}.yaml`);
|
|
6936
6846
|
} else if (scenarioArg) {
|
|
6937
|
-
scenarioPath =
|
|
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 =
|
|
6970
|
-
const testPath =
|
|
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
|
|
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(
|
|
7002
|
-
testPath =
|
|
6911
|
+
if (testArg && fileExists(join8(root, testArg))) {
|
|
6912
|
+
testPath = join8(root, testArg);
|
|
7003
6913
|
} else if (ctx.key) {
|
|
7004
|
-
testPath =
|
|
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
|
|
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(
|
|
7048
|
-
testPath =
|
|
6957
|
+
if (testArg && fileExists(join9(root, testArg))) {
|
|
6958
|
+
testPath = join9(root, testArg);
|
|
7049
6959
|
} else if (ctx.key) {
|
|
7050
|
-
testPath =
|
|
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 =
|
|
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
|
|
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(
|
|
7120
|
-
testPath =
|
|
7029
|
+
if (testArg && fileExists(join10(root, testArg))) {
|
|
7030
|
+
testPath = join10(root, testArg);
|
|
7121
7031
|
} else if (ctx.key) {
|
|
7122
|
-
testPath =
|
|
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
|
|
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(
|
|
7202
|
-
testPath =
|
|
7111
|
+
if (testArg && fileExists(join11(root, testArg))) {
|
|
7112
|
+
testPath = join11(root, testArg);
|
|
7203
7113
|
} else if (ctx.key) {
|
|
7204
|
-
testPath =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
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 =
|
|
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(
|
|
7401
|
-
ctx.audioPath = findFileWithPattern(
|
|
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(
|
|
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 ?
|
|
7421
|
-
const jsonPath =
|
|
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(
|
|
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 =
|
|
7386
|
+
const scenarioDir = join12(ctx.paths.testsDir, ctx.sessionName);
|
|
7477
7387
|
ensureDir(scenarioDir);
|
|
7478
|
-
const scenarioPath =
|
|
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 =
|
|
7506
|
-
ctx.testPath =
|
|
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
|
|
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 =
|
|
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
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
}
|
|
9187
|
-
|
|
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
|
|
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
|
-
|
|
9284
|
-
const
|
|
9285
|
-
const
|
|
9286
|
-
|
|
9287
|
-
|
|
9288
|
-
|
|
9289
|
-
|
|
9290
|
-
|
|
9291
|
-
|
|
9292
|
-
|
|
9293
|
-
|
|
9294
|
-
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
9306
|
-
|
|
9307
|
-
|
|
9308
|
-
|
|
9309
|
-
|
|
9310
|
-
|
|
9311
|
-
|
|
9312
|
-
|
|
9313
|
-
|
|
9314
|
-
|
|
9315
|
-
|
|
9316
|
-
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
|
|
9331
|
-
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
|
|
9336
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9378
|
-
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9384
|
-
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
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
|
-
|
|
9400
|
-
|
|
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
|