playwright-intelligence-engine 2.0.0 → 2.0.2
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/README.md +229 -229
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/core/version.d.ts +3 -3
- package/dist/index.js +81 -24
- package/package.json +76 -76
- package/src/authoring/author.ts +81 -81
- package/src/authoring/generation-contract.ts +283 -283
- package/src/authoring/hybrid-author.ts +115 -115
- package/src/authoring/index.ts +7 -7
- package/src/authoring/llm-author.ts +282 -282
- package/src/authoring/naming/name-plan.ts +28 -28
- package/src/authoring/naming/name-planner.ts +339 -339
- package/src/authoring/naming/naming-linter.ts +292 -292
- package/src/cli/index.ts +1238 -1172
- package/src/collectors/git-diff-collector.ts +190 -190
- package/src/core/version.ts +25 -25
- package/src/diagnostics/diagnostic-report.ts +204 -204
- package/src/diagnostics/failure-classifier.ts +701 -701
- package/src/evaluation/repository-runner.ts +197 -197
- package/src/gate/quality.ts +101 -101
- package/src/generator/architecture-generator.ts +582 -582
- package/src/generator/assertion-quality-gate.ts +88 -88
- package/src/generator/candidate-writer.ts +288 -288
- package/src/generator/test-generator.ts +52 -52
- package/src/index.ts +107 -107
- package/src/intelligence/evidence-bundle.ts +300 -300
- package/src/intelligence/generation-agent.ts +561 -561
- package/src/intelligence/generation-verifier.ts +1115 -1115
- package/src/intelligence/locator-disambiguation-engine.ts +331 -331
- package/src/intelligence/project-intelligence.ts +140 -140
- package/src/intelligence/repository-profile.ts +796 -796
- package/src/intelligence/trace-proposal-workflow.ts +318 -318
- package/src/intelligence/workflow-planner.ts +966 -966
- package/src/mcp/server.ts +970 -970
- package/src/perception/app-model.ts +32 -32
- package/src/perception/crawler.ts +263 -263
- package/src/perception/index.ts +3 -3
- package/src/repair/assertion-hasher.ts +386 -386
- package/src/repair/diff-allowlist.ts +612 -612
- package/src/repair/intent-validator.ts +761 -761
- package/src/repair/repair-planner.ts +467 -467
- package/src/repair/statement-patcher.ts +544 -544
- package/src/reproduce/interactive-workflow-runner.ts +828 -828
- package/src/sandbox/execution-runner.ts +408 -408
- package/src/selector/abstention-policy.ts +175 -175
- package/src/selector/candidate-extractor.ts +343 -343
- package/src/selector/repair-candidate-ranker.ts +92 -92
- package/src/selector/selector-scorer.ts +344 -344
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import { Author, AuthorInput, CandidateChange } from './author.js';
|
|
2
|
-
import { planArchitecture, toSlug } from '../generator/architecture-generator.js';
|
|
3
|
-
import { NamePlanner } from './naming/name-planner.js';
|
|
4
|
-
import { NamePlanSchema, type NamePlan } from './naming/name-plan.js';
|
|
5
|
-
import { NamingLinter } from './naming/naming-linter.js';
|
|
6
|
-
|
|
7
|
-
export class HybridAuthor implements Author {
|
|
8
|
-
public readonly kind = 'hybrid';
|
|
9
|
-
|
|
10
|
-
public async propose(input: AuthorInput): Promise<CandidateChange> {
|
|
11
|
-
const steps = input.steps ?? [{ action: 'navigate' }, { action: 'assert-visible', role: 'heading', name: input.featureName }];
|
|
12
|
-
|
|
13
|
-
let namePlan: NamePlan;
|
|
14
|
-
// Attempt LLM symbol proposal if API key is present (opt-in under Vitest)
|
|
15
|
-
const liveAllowed = !process.env.VITEST || process.env.PIE_LIVE_LLM_TESTS === '1';
|
|
16
|
-
const apiKey = liveAllowed ? (process.env.PIE_LLM_API_KEY ?? process.env.OPENAI_API_KEY ?? process.env.DEEPSEEK_API_KEY) : undefined;
|
|
17
|
-
const endpoint = process.env.PIE_LLM_ENDPOINT ?? (process.env.OPENAI_API_KEY ? 'https://api.openai.com/v1/chat/completions' : (apiKey ? 'https://api.deepseek.com/chat/completions' : undefined));
|
|
18
|
-
const model = process.env.PIE_LLM_MODEL ?? (process.env.OPENAI_API_KEY ? 'gpt-4o' : (apiKey ? 'deepseek-chat' : undefined));
|
|
19
|
-
|
|
20
|
-
let rationale = 'Hybrid-authored: deterministic template rendering guided by semantic symbol plan.';
|
|
21
|
-
|
|
22
|
-
if (apiKey && endpoint && model) {
|
|
23
|
-
try {
|
|
24
|
-
const exemplarText = (input.exemplars ?? [])
|
|
25
|
-
.slice(0, 2)
|
|
26
|
-
.map((e) => `// Exemplar Page Object: ${e.className} (${e.filePath})\n${e.content.slice(0, 500)}`)
|
|
27
|
-
.join('\n\n');
|
|
28
|
-
|
|
29
|
-
const prompt = [
|
|
30
|
-
'You are an expert Playwright automation engineer. Given the feature and test steps, produce a concise JSON Symbol Table (NamePlan) naming the Page Object class and each element.',
|
|
31
|
-
'Conventions to follow:',
|
|
32
|
-
'- Name Page Object classes after the application page (e.g. LoginPage, CartPage, CheckoutPage), NOT after the test scenario title.',
|
|
33
|
-
'- Property names must be camelCase with role suffix (e.g. emailInput, signInButton, searchInput, orderStatus).',
|
|
34
|
-
'- Method names must be camelCase with verb (e.g. fillEmail, signIn, submitOrder, openPricing). NEVER use raw numbers or index-derived names like actionButton1 or fill2.',
|
|
35
|
-
exemplarText ? `\nSibling Exemplars from target repository:\n${exemplarText}\n` : '',
|
|
36
|
-
`Feature: "${input.featureName}"`,
|
|
37
|
-
`Steps: ${JSON.stringify(steps, null, 2)}`,
|
|
38
|
-
'\nRespond ONLY with valid JSON conforming to this schema:',
|
|
39
|
-
'{',
|
|
40
|
-
' "planVersion": "1",',
|
|
41
|
-
' "pageClassName": "LoginPage",',
|
|
42
|
-
' "pageVariable": "loginPage",',
|
|
43
|
-
' "symbols": [',
|
|
44
|
-
' { "ref": "step-1", "role": "textbox", "accessibleName": "Email", "property": "emailInput", "method": "fillEmail", "verb": "fill", "confidence": 0.95, "source": "llm", "assumptions": [] }',
|
|
45
|
-
' ],',
|
|
46
|
-
' "assumptions": []',
|
|
47
|
-
'}',
|
|
48
|
-
].join('\n');
|
|
49
|
-
|
|
50
|
-
const response = await fetch(endpoint, {
|
|
51
|
-
method: 'POST',
|
|
52
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}` },
|
|
53
|
-
body: JSON.stringify({
|
|
54
|
-
model,
|
|
55
|
-
messages: [{ role: 'user', content: prompt }],
|
|
56
|
-
temperature: 0.1,
|
|
57
|
-
max_tokens: 1000,
|
|
58
|
-
}),
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (response.ok) {
|
|
62
|
-
const json = await response.json() as any;
|
|
63
|
-
const rawContent = json.choices?.[0]?.message?.content ?? '';
|
|
64
|
-
const cleaned = rawContent.replace(/^```(?:json)?\s*/i, '').replace(/\s*```$/i, '').trim();
|
|
65
|
-
const parsed = JSON.parse(cleaned);
|
|
66
|
-
const validated = NamePlanSchema.safeParse(parsed);
|
|
67
|
-
if (validated.success && validated.data.symbols.length === steps.length) {
|
|
68
|
-
const lintReport = NamingLinter.lint(validated.data);
|
|
69
|
-
if (lintReport.passed) {
|
|
70
|
-
namePlan = validated.data;
|
|
71
|
-
rationale = 'Hybrid-authored: LLM semantic naming guided by sibling exemplars, compiled through deterministic template.';
|
|
72
|
-
} else {
|
|
73
|
-
namePlan = NamePlanner.planNames(input.featureName, steps, { source: 'heuristic' });
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
namePlan = NamePlanner.planNames(input.featureName, steps, { source: 'heuristic' });
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
namePlan = NamePlanner.planNames(input.featureName, steps, { source: 'heuristic' });
|
|
80
|
-
}
|
|
81
|
-
} catch {
|
|
82
|
-
namePlan = NamePlanner.planNames(input.featureName, steps, { source: 'heuristic' });
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
namePlan = NamePlanner.planNames(input.featureName, steps, { source: 'heuristic' });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const plan = planArchitecture({
|
|
89
|
-
featureName: input.featureName,
|
|
90
|
-
mode: input.mode,
|
|
91
|
-
baseUrl: input.baseUrl,
|
|
92
|
-
requirements: input.requirements,
|
|
93
|
-
steps,
|
|
94
|
-
profile: input.profile,
|
|
95
|
-
existingFiles: input.existingFiles,
|
|
96
|
-
namePlan,
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
files: plan.files.map((f) => ({
|
|
101
|
-
relativePath: f.relativePath,
|
|
102
|
-
content: f.content,
|
|
103
|
-
purpose: f.purpose,
|
|
104
|
-
action: f.action,
|
|
105
|
-
})),
|
|
106
|
-
symbols: namePlan,
|
|
107
|
-
rationale,
|
|
108
|
-
authorKind: 'hybrid',
|
|
109
|
-
featureName: input.featureName,
|
|
110
|
-
slug: toSlug(input.featureName),
|
|
111
|
-
mode: input.mode,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
1
|
+
import { Author, AuthorInput, CandidateChange } from './author.js';
|
|
2
|
+
import { planArchitecture, toSlug } from '../generator/architecture-generator.js';
|
|
3
|
+
import { NamePlanner } from './naming/name-planner.js';
|
|
4
|
+
import { NamePlanSchema, type NamePlan } from './naming/name-plan.js';
|
|
5
|
+
import { NamingLinter } from './naming/naming-linter.js';
|
|
6
|
+
|
|
7
|
+
export class HybridAuthor implements Author {
|
|
8
|
+
public readonly kind = 'hybrid';
|
|
9
|
+
|
|
10
|
+
public async propose(input: AuthorInput): Promise<CandidateChange> {
|
|
11
|
+
const steps = input.steps ?? [{ action: 'navigate' }, { action: 'assert-visible', role: 'heading', name: input.featureName }];
|
|
12
|
+
|
|
13
|
+
let namePlan: NamePlan;
|
|
14
|
+
// Attempt LLM symbol proposal if API key is present (opt-in under Vitest)
|
|
15
|
+
const liveAllowed = !process.env.VITEST || process.env.PIE_LIVE_LLM_TESTS === '1';
|
|
16
|
+
const apiKey = liveAllowed ? (process.env.PIE_LLM_API_KEY ?? process.env.OPENAI_API_KEY ?? process.env.DEEPSEEK_API_KEY) : undefined;
|
|
17
|
+
const endpoint = process.env.PIE_LLM_ENDPOINT ?? (process.env.OPENAI_API_KEY ? 'https://api.openai.com/v1/chat/completions' : (apiKey ? 'https://api.deepseek.com/chat/completions' : undefined));
|
|
18
|
+
const model = process.env.PIE_LLM_MODEL ?? (process.env.OPENAI_API_KEY ? 'gpt-4o' : (apiKey ? 'deepseek-chat' : undefined));
|
|
19
|
+
|
|
20
|
+
let rationale = 'Hybrid-authored: deterministic template rendering guided by semantic symbol plan.';
|
|
21
|
+
|
|
22
|
+
if (apiKey && endpoint && model) {
|
|
23
|
+
try {
|
|
24
|
+
const exemplarText = (input.exemplars ?? [])
|
|
25
|
+
.slice(0, 2)
|
|
26
|
+
.map((e) => `// Exemplar Page Object: ${e.className} (${e.filePath})\n${e.content.slice(0, 500)}`)
|
|
27
|
+
.join('\n\n');
|
|
28
|
+
|
|
29
|
+
const prompt = [
|
|
30
|
+
'You are an expert Playwright automation engineer. Given the feature and test steps, produce a concise JSON Symbol Table (NamePlan) naming the Page Object class and each element.',
|
|
31
|
+
'Conventions to follow:',
|
|
32
|
+
'- Name Page Object classes after the application page (e.g. LoginPage, CartPage, CheckoutPage), NOT after the test scenario title.',
|
|
33
|
+
'- Property names must be camelCase with role suffix (e.g. emailInput, signInButton, searchInput, orderStatus).',
|
|
34
|
+
'- Method names must be camelCase with verb (e.g. fillEmail, signIn, submitOrder, openPricing). NEVER use raw numbers or index-derived names like actionButton1 or fill2.',
|
|
35
|
+
exemplarText ? `\nSibling Exemplars from target repository:\n${exemplarText}\n` : '',
|
|
36
|
+
`Feature: "${input.featureName}"`,
|
|
37
|
+
`Steps: ${JSON.stringify(steps, null, 2)}`,
|
|
38
|
+
'\nRespond ONLY with valid JSON conforming to this schema:',
|
|
39
|
+
'{',
|
|
40
|
+
' "planVersion": "1",',
|
|
41
|
+
' "pageClassName": "LoginPage",',
|
|
42
|
+
' "pageVariable": "loginPage",',
|
|
43
|
+
' "symbols": [',
|
|
44
|
+
' { "ref": "step-1", "role": "textbox", "accessibleName": "Email", "property": "emailInput", "method": "fillEmail", "verb": "fill", "confidence": 0.95, "source": "llm", "assumptions": [] }',
|
|
45
|
+
' ],',
|
|
46
|
+
' "assumptions": []',
|
|
47
|
+
'}',
|
|
48
|
+
].join('\n');
|
|
49
|
+
|
|
50
|
+
const response = await fetch(endpoint, {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}` },
|
|
53
|
+
body: JSON.stringify({
|
|
54
|
+
model,
|
|
55
|
+
messages: [{ role: 'user', content: prompt }],
|
|
56
|
+
temperature: 0.1,
|
|
57
|
+
max_tokens: 1000,
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (response.ok) {
|
|
62
|
+
const json = await response.json() as any;
|
|
63
|
+
const rawContent = json.choices?.[0]?.message?.content ?? '';
|
|
64
|
+
const cleaned = rawContent.replace(/^```(?:json)?\s*/i, '').replace(/\s*```$/i, '').trim();
|
|
65
|
+
const parsed = JSON.parse(cleaned);
|
|
66
|
+
const validated = NamePlanSchema.safeParse(parsed);
|
|
67
|
+
if (validated.success && validated.data.symbols.length === steps.length) {
|
|
68
|
+
const lintReport = NamingLinter.lint(validated.data);
|
|
69
|
+
if (lintReport.passed) {
|
|
70
|
+
namePlan = validated.data;
|
|
71
|
+
rationale = 'Hybrid-authored: LLM semantic naming guided by sibling exemplars, compiled through deterministic template.';
|
|
72
|
+
} else {
|
|
73
|
+
namePlan = NamePlanner.planNames(input.featureName, steps, { source: 'heuristic' });
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
namePlan = NamePlanner.planNames(input.featureName, steps, { source: 'heuristic' });
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
namePlan = NamePlanner.planNames(input.featureName, steps, { source: 'heuristic' });
|
|
80
|
+
}
|
|
81
|
+
} catch {
|
|
82
|
+
namePlan = NamePlanner.planNames(input.featureName, steps, { source: 'heuristic' });
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
namePlan = NamePlanner.planNames(input.featureName, steps, { source: 'heuristic' });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const plan = planArchitecture({
|
|
89
|
+
featureName: input.featureName,
|
|
90
|
+
mode: input.mode,
|
|
91
|
+
baseUrl: input.baseUrl,
|
|
92
|
+
requirements: input.requirements,
|
|
93
|
+
steps,
|
|
94
|
+
profile: input.profile,
|
|
95
|
+
existingFiles: input.existingFiles,
|
|
96
|
+
namePlan,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
files: plan.files.map((f) => ({
|
|
101
|
+
relativePath: f.relativePath,
|
|
102
|
+
content: f.content,
|
|
103
|
+
purpose: f.purpose,
|
|
104
|
+
action: f.action,
|
|
105
|
+
})),
|
|
106
|
+
symbols: namePlan,
|
|
107
|
+
rationale,
|
|
108
|
+
authorKind: 'hybrid',
|
|
109
|
+
featureName: input.featureName,
|
|
110
|
+
slug: toSlug(input.featureName),
|
|
111
|
+
mode: input.mode,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
package/src/authoring/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './author.js';
|
|
2
|
-
export * from './generation-contract.js';
|
|
3
|
-
export * from './template-author.js';
|
|
4
|
-
export * from './hybrid-author.js';
|
|
5
|
-
export * from './llm-author.js';
|
|
6
|
-
export * from './naming/index.js';
|
|
7
|
-
|
|
1
|
+
export * from './author.js';
|
|
2
|
+
export * from './generation-contract.js';
|
|
3
|
+
export * from './template-author.js';
|
|
4
|
+
export * from './hybrid-author.js';
|
|
5
|
+
export * from './llm-author.js';
|
|
6
|
+
export * from './naming/index.js';
|
|
7
|
+
|