explorbot 0.1.11 → 0.1.13
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 +12 -2
- package/bin/explorbot-cli.ts +21 -21
- package/dist/bin/explorbot-cli.js +3 -3
- package/dist/package.json +4 -3
- package/dist/rules/researcher/container-rules.md +2 -0
- package/dist/src/action-result.js +2 -1
- package/dist/src/action.js +5 -10
- package/dist/src/ai/captain.js +0 -2
- package/dist/src/ai/driller.js +1108 -0
- package/dist/src/ai/historian/codeceptjs.js +2 -2
- package/dist/src/ai/historian/experience.js +1 -0
- package/dist/src/ai/historian/playwright.js +4 -4
- package/dist/src/ai/historian/screencast.js +121 -0
- package/dist/src/ai/historian.js +5 -3
- package/dist/src/ai/pilot.js +31 -22
- package/dist/src/ai/rules.js +3 -5
- package/dist/src/ai/session-analyst.js +117 -0
- package/dist/src/ai/tester.js +13 -2
- package/dist/src/commands/base-command.js +6 -6
- package/dist/src/commands/drill-command.js +3 -2
- package/dist/src/commands/exit-command.js +1 -0
- package/dist/src/commands/explore-command.js +20 -3
- package/dist/src/components/AddRule.js +1 -1
- package/dist/src/explorbot.js +52 -9
- package/dist/src/explorer.js +11 -9
- package/dist/src/reporter.js +68 -4
- package/dist/src/state-manager.js +4 -3
- package/dist/src/stats.js +5 -0
- package/dist/src/utils/aria.js +354 -529
- package/dist/src/utils/hooks-runner.js +2 -8
- package/dist/src/utils/html.js +371 -0
- package/dist/src/utils/strings.js +15 -0
- package/dist/src/utils/unique-names.js +12 -1
- package/dist/src/utils/url-matcher.js +6 -1
- package/dist/src/utils/web-element.js +27 -24
- package/dist/src/utils/xpath.js +1 -1
- package/package.json +4 -3
- package/rules/researcher/container-rules.md +2 -0
- package/src/action-result.ts +2 -1
- package/src/action.ts +5 -12
- package/src/ai/captain.ts +0 -2
- package/src/ai/driller.ts +1194 -0
- package/src/ai/historian/codeceptjs.ts +2 -2
- package/src/ai/historian/experience.ts +3 -2
- package/src/ai/historian/playwright.ts +5 -5
- package/src/ai/historian/screencast.ts +133 -0
- package/src/ai/historian.ts +7 -5
- package/src/ai/pilot.ts +31 -21
- package/src/ai/rules.ts +3 -5
- package/src/ai/session-analyst.ts +133 -0
- package/src/ai/tester.ts +15 -2
- package/src/commands/base-command.ts +6 -6
- package/src/commands/drill-command.ts +3 -2
- package/src/commands/exit-command.ts +1 -0
- package/src/commands/explore-command.ts +22 -3
- package/src/components/AddRule.tsx +1 -1
- package/src/config.ts +10 -0
- package/src/explorbot.ts +59 -11
- package/src/explorer.ts +11 -9
- package/src/reporter.ts +68 -4
- package/src/state-manager.ts +4 -3
- package/src/stats.ts +7 -0
- package/src/utils/aria.ts +367 -537
- package/src/utils/hooks-runner.ts +2 -6
- package/src/utils/html.ts +381 -0
- package/src/utils/strings.ts +17 -0
- package/src/utils/unique-names.ts +13 -0
- package/src/utils/url-matcher.ts +5 -1
- package/src/utils/web-element.ts +31 -28
- package/src/utils/xpath.ts +1 -1
- package/dist/src/ai/bosun.js +0 -456
- package/src/ai/bosun.ts +0 -571
|
@@ -6,6 +6,7 @@ import { KnowledgeTracker } from '../../knowledge-tracker.ts';
|
|
|
6
6
|
import type { Plan } from '../../test-plan.ts';
|
|
7
7
|
import { tag } from '../../utils/logger.ts';
|
|
8
8
|
import { relativeToCwd } from '../../utils/next-steps.ts';
|
|
9
|
+
import { safeFilename } from '../../utils/strings.ts';
|
|
9
10
|
import type { Conversation } from '../conversation.ts';
|
|
10
11
|
import { ASSERTION_TOOLS, CODECEPT_TOOLS } from '../tools.ts';
|
|
11
12
|
import type { Constructor } from './mixin.ts';
|
|
@@ -97,8 +98,7 @@ export function WithCodeceptJS<T extends Constructor>(Base: T) {
|
|
|
97
98
|
const testsDir = ConfigParser.getInstance().getTestsDir();
|
|
98
99
|
mkdirSync(testsDir, { recursive: true });
|
|
99
100
|
|
|
100
|
-
const
|
|
101
|
-
const filePath = join(testsDir, `${filename}.js`);
|
|
101
|
+
const filePath = join(testsDir, safeFilename(plan.title, '.js'));
|
|
102
102
|
writeFileSync(filePath, lines.join('\n'));
|
|
103
103
|
this.savedFiles.add(filePath);
|
|
104
104
|
|
|
@@ -2,7 +2,6 @@ import dedent from 'dedent';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { ActionResult } from '../../action-result.ts';
|
|
4
4
|
import { ExperienceTracker, type SessionStep } from '../../experience-tracker.ts';
|
|
5
|
-
import type { PlaywrightRecorder } from '../../playwright-recorder.ts';
|
|
6
5
|
import type { Reporter, ReporterStep } from '../../reporter.ts';
|
|
7
6
|
import type { StateManager } from '../../state-manager.ts';
|
|
8
7
|
import { type Task, Test } from '../../test-plan.ts';
|
|
@@ -24,10 +23,10 @@ export function WithExperience<T extends Constructor>(Base: T) {
|
|
|
24
23
|
declare experienceTracker: ExperienceTracker;
|
|
25
24
|
declare reporter: Reporter | undefined;
|
|
26
25
|
declare stateManager: StateManager | undefined;
|
|
27
|
-
declare recorder: PlaywrightRecorder | undefined;
|
|
28
26
|
declare isPlaywrightFramework: () => boolean;
|
|
29
27
|
declare toCode: (conversation: Conversation, scenario: string) => string;
|
|
30
28
|
declare toPlaywrightCode: (conversation: Conversation, scenario: string) => Promise<string>;
|
|
29
|
+
declare stopScreencast: () => Promise<void>;
|
|
31
30
|
|
|
32
31
|
async saveSession(task: Task, initialState: ActionResult, conversation: Conversation): Promise<void> {
|
|
33
32
|
debugLog('Saving session experience');
|
|
@@ -55,6 +54,8 @@ export function WithExperience<T extends Constructor>(Base: T) {
|
|
|
55
54
|
await this.reportSession(task, steps);
|
|
56
55
|
}
|
|
57
56
|
|
|
57
|
+
await this.stopScreencast();
|
|
58
|
+
|
|
58
59
|
tag('substep').log(`Historian saved session for: ${task.description}`);
|
|
59
60
|
}
|
|
60
61
|
|
|
@@ -7,6 +7,7 @@ import { type PlaywrightRecorder, type TraceCall, renderAssertion, renderCall }
|
|
|
7
7
|
import type { Plan } from '../../test-plan.ts';
|
|
8
8
|
import { tag } from '../../utils/logger.ts';
|
|
9
9
|
import { relativeToCwd } from '../../utils/next-steps.ts';
|
|
10
|
+
import { safeFilename } from '../../utils/strings.ts';
|
|
10
11
|
import type { Conversation } from '../conversation.ts';
|
|
11
12
|
import { ASSERTION_TOOLS, CODECEPT_TOOLS } from '../tools.ts';
|
|
12
13
|
import type { Constructor } from './mixin.ts';
|
|
@@ -21,14 +22,14 @@ export interface PlaywrightMethods {
|
|
|
21
22
|
|
|
22
23
|
export function WithPlaywright<T extends Constructor>(Base: T) {
|
|
23
24
|
return class extends Base {
|
|
24
|
-
declare recorder: PlaywrightRecorder | undefined;
|
|
25
|
+
declare playwright: { recorder: PlaywrightRecorder; helper: any } | undefined;
|
|
25
26
|
declare savedFiles: Set<string>;
|
|
26
27
|
|
|
27
28
|
async toPlaywrightCode(conversation: Conversation, scenario: string): Promise<string> {
|
|
28
29
|
const toolExecutions = conversation.getToolExecutions();
|
|
29
30
|
const successfulSteps = toolExecutions.filter((exec) => exec.wasSuccessful && PLAYWRIGHT_EMITTED_TOOLS.includes(exec.toolName as any));
|
|
30
31
|
|
|
31
|
-
const callsByGroup = this.recorder ? await this.recorder.exportChunk() : new Map<string, TraceCall[]>();
|
|
32
|
+
const callsByGroup = this.playwright?.recorder ? await this.playwright.recorder.exportChunk() : new Map<string, TraceCall[]>();
|
|
32
33
|
|
|
33
34
|
const stepLines: string[] = [];
|
|
34
35
|
for (const exec of successfulSteps) {
|
|
@@ -59,7 +60,7 @@ export function WithPlaywright<T extends Constructor>(Base: T) {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
const pilotVerifications = this.recorder ? this.recorder.drainVerifications() : [];
|
|
63
|
+
const pilotVerifications = this.playwright?.recorder ? this.playwright.recorder.drainVerifications() : [];
|
|
63
64
|
if (pilotVerifications.length > 0) {
|
|
64
65
|
const assertionLines: string[] = [];
|
|
65
66
|
for (const step of pilotVerifications) {
|
|
@@ -135,8 +136,7 @@ export function WithPlaywright<T extends Constructor>(Base: T) {
|
|
|
135
136
|
const testsDir = ConfigParser.getInstance().getTestsDir();
|
|
136
137
|
mkdirSync(testsDir, { recursive: true });
|
|
137
138
|
|
|
138
|
-
const
|
|
139
|
-
const filePath = join(testsDir, `${filename}.spec.ts`);
|
|
139
|
+
const filePath = join(testsDir, safeFilename(plan.title, '.spec.ts'));
|
|
140
140
|
writeFileSync(filePath, lines.join('\n'));
|
|
141
141
|
this.savedFiles.add(filePath);
|
|
142
142
|
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { mkdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import * as codeceptjs from 'codeceptjs';
|
|
5
|
+
import { outputPath } from '../../config.ts';
|
|
6
|
+
import type { ExplorbotConfig } from '../../config.ts';
|
|
7
|
+
import type { PlaywrightRecorder } from '../../playwright-recorder.ts';
|
|
8
|
+
import { tag } from '../../utils/logger.ts';
|
|
9
|
+
import { relativeToCwd } from '../../utils/next-steps.ts';
|
|
10
|
+
import { safeFilename } from '../../utils/strings.ts';
|
|
11
|
+
import { type Constructor, debugLog } from './mixin.ts';
|
|
12
|
+
|
|
13
|
+
export interface ScreencastMethods {
|
|
14
|
+
attachScreencast(): void;
|
|
15
|
+
isScreencastActive(): boolean;
|
|
16
|
+
stopScreencast(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function WithScreencast<T extends Constructor>(Base: T) {
|
|
20
|
+
return class extends Base {
|
|
21
|
+
declare config: ExplorbotConfig | undefined;
|
|
22
|
+
declare savedFiles: Set<string>;
|
|
23
|
+
declare playwright: { recorder: PlaywrightRecorder; helper: any } | undefined;
|
|
24
|
+
|
|
25
|
+
private screencastPage: any = null;
|
|
26
|
+
private screencastActive = false;
|
|
27
|
+
private screencastPath: string | null = null;
|
|
28
|
+
private screencastListenersInstalled = false;
|
|
29
|
+
private screencastTask: any = null;
|
|
30
|
+
private screencastLastChapter: string | null = null;
|
|
31
|
+
private onTestBefore?: (test: any) => void;
|
|
32
|
+
private onStepPassed?: (step: any) => void;
|
|
33
|
+
private onTestAfter?: () => void;
|
|
34
|
+
|
|
35
|
+
isScreencastActive(): boolean {
|
|
36
|
+
return this.screencastActive;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
attachScreencast(): void {
|
|
40
|
+
if (this.screencastListenersInstalled) return;
|
|
41
|
+
if (!this.config?.ai?.agents?.historian?.screencast) return;
|
|
42
|
+
if (!this.playwright?.helper) return;
|
|
43
|
+
|
|
44
|
+
this.onTestBefore = (test: any) => {
|
|
45
|
+
void this.startScreencast(test);
|
|
46
|
+
};
|
|
47
|
+
this.onStepPassed = (step: any) => {
|
|
48
|
+
void this.emitChapter(step);
|
|
49
|
+
};
|
|
50
|
+
this.onTestAfter = () => {
|
|
51
|
+
void this.stopScreencast();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
codeceptjs.event.dispatcher.on('test.before', this.onTestBefore);
|
|
55
|
+
codeceptjs.event.dispatcher.on('step.passed', this.onStepPassed);
|
|
56
|
+
codeceptjs.event.dispatcher.on('test.after', this.onTestAfter);
|
|
57
|
+
|
|
58
|
+
this.screencastListenersInstalled = true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private async startScreencast(test: any): Promise<void> {
|
|
62
|
+
if (this.screencastActive) return;
|
|
63
|
+
const page = this.playwright?.helper?.page;
|
|
64
|
+
if (!page?.screencast?.start) return;
|
|
65
|
+
|
|
66
|
+
const task = test?._explorbotTest;
|
|
67
|
+
const scenarioName = task?.scenario || test?.title || 'scenario';
|
|
68
|
+
const planTitle: string | undefined = task?.plan?.title;
|
|
69
|
+
const planTests: any[] | undefined = task?.plan?.tests;
|
|
70
|
+
const index = planTests && task ? planTests.indexOf(task) + 1 : 0;
|
|
71
|
+
|
|
72
|
+
const parts: string[] = [];
|
|
73
|
+
if (planTitle) parts.push(safeFilename(planTitle));
|
|
74
|
+
if (index > 0) parts.push(String(index));
|
|
75
|
+
parts.push(safeFilename(scenarioName));
|
|
76
|
+
|
|
77
|
+
const dir = outputPath('screencasts');
|
|
78
|
+
mkdirSync(dir, { recursive: true });
|
|
79
|
+
const filePath = join(dir, `${parts.join('-')}.webm`);
|
|
80
|
+
|
|
81
|
+
const screencastConfig = this.config?.ai?.agents?.historian?.screencast;
|
|
82
|
+
const screencastOpts = typeof screencastConfig === 'object' ? screencastConfig : {};
|
|
83
|
+
const size = screencastOpts.size ?? page.viewportSize?.() ?? undefined;
|
|
84
|
+
const quality = screencastOpts.quality ?? 95;
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
await page.screencast.start({ path: filePath, quality, size });
|
|
88
|
+
await page.screencast.showActions({ position: 'top-left' });
|
|
89
|
+
this.screencastPage = page;
|
|
90
|
+
this.screencastPath = filePath;
|
|
91
|
+
this.screencastActive = true;
|
|
92
|
+
this.screencastTask = test?._explorbotTest || null;
|
|
93
|
+
this.screencastLastChapter = null;
|
|
94
|
+
} catch (err) {
|
|
95
|
+
tag('substep').log(`Screencast start failed: ${(err as Error).message}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private async emitChapter(_step: any): Promise<void> {
|
|
100
|
+
if (!this.screencastActive) return;
|
|
101
|
+
const explanation = this.screencastTask?.activeNote?.getMessage?.();
|
|
102
|
+
if (!explanation) return;
|
|
103
|
+
if (explanation === this.screencastLastChapter) return;
|
|
104
|
+
this.screencastLastChapter = explanation;
|
|
105
|
+
try {
|
|
106
|
+
await this.screencastPage.screencast.showChapter(explanation);
|
|
107
|
+
} catch (err) {
|
|
108
|
+
debugLog('screencast.showChapter failed:', err);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async stopScreencast(): Promise<void> {
|
|
113
|
+
if (!this.screencastActive) return;
|
|
114
|
+
const path = this.screencastPath;
|
|
115
|
+
const task = this.screencastTask;
|
|
116
|
+
try {
|
|
117
|
+
await this.screencastPage.screencast.stop();
|
|
118
|
+
} catch (err) {
|
|
119
|
+
tag('substep').log(`Screencast stop failed: ${(err as Error).message}`);
|
|
120
|
+
}
|
|
121
|
+
this.screencastActive = false;
|
|
122
|
+
this.screencastPage = null;
|
|
123
|
+
this.screencastPath = null;
|
|
124
|
+
this.screencastTask = null;
|
|
125
|
+
this.screencastLastChapter = null;
|
|
126
|
+
if (path) {
|
|
127
|
+
this.savedFiles.add(path);
|
|
128
|
+
task?.addArtifact?.(path);
|
|
129
|
+
tag('substep').log(`Saved screencast: ${relativeToCwd(path)}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
package/src/ai/historian.ts
CHANGED
|
@@ -10,13 +10,14 @@ import { relativeToCwd } from '../utils/next-steps.ts';
|
|
|
10
10
|
import { type CodeceptJSMethods, WithCodeceptJS } from './historian/codeceptjs.ts';
|
|
11
11
|
import { type ExperienceMethods, WithExperience } from './historian/experience.ts';
|
|
12
12
|
import { type PlaywrightMethods, WithPlaywright } from './historian/playwright.ts';
|
|
13
|
+
import { type ScreencastMethods, WithScreencast } from './historian/screencast.ts';
|
|
13
14
|
import type { Provider } from './provider.ts';
|
|
14
15
|
|
|
15
16
|
export { isNonReusableCode } from './historian/utils.ts';
|
|
16
17
|
|
|
17
|
-
const HistorianBase = WithPlaywright(WithCodeceptJS(WithExperience(Object as unknown as new (...args: any[]) => object)));
|
|
18
|
+
const HistorianBase = WithScreencast(WithPlaywright(WithCodeceptJS(WithExperience(Object as unknown as new (...args: any[]) => object))));
|
|
18
19
|
|
|
19
|
-
export interface Historian extends ExperienceMethods, CodeceptJSMethods, PlaywrightMethods {}
|
|
20
|
+
export interface Historian extends ExperienceMethods, CodeceptJSMethods, PlaywrightMethods, ScreencastMethods {}
|
|
20
21
|
|
|
21
22
|
export class Historian extends HistorianBase {
|
|
22
23
|
declare provider: Provider;
|
|
@@ -24,18 +25,19 @@ export class Historian extends HistorianBase {
|
|
|
24
25
|
declare reporter: Reporter | undefined;
|
|
25
26
|
declare stateManager: StateManager | undefined;
|
|
26
27
|
declare config: ExplorbotConfig | undefined;
|
|
27
|
-
declare recorder: PlaywrightRecorder | undefined;
|
|
28
|
+
declare playwright: { recorder: PlaywrightRecorder; helper: any } | undefined;
|
|
28
29
|
declare savedFiles: Set<string>;
|
|
29
30
|
|
|
30
|
-
constructor(provider: Provider, experienceTracker?: ExperienceTracker, reporter?: Reporter, stateManager?: StateManager, config?: ExplorbotConfig,
|
|
31
|
+
constructor(provider: Provider, experienceTracker?: ExperienceTracker, reporter?: Reporter, stateManager?: StateManager, config?: ExplorbotConfig, playwright?: { recorder: PlaywrightRecorder; helper: any }) {
|
|
31
32
|
super();
|
|
32
33
|
this.provider = provider;
|
|
33
34
|
this.experienceTracker = experienceTracker || new ExperienceTracker();
|
|
34
35
|
this.reporter = reporter;
|
|
35
36
|
this.stateManager = stateManager;
|
|
36
37
|
this.config = config;
|
|
37
|
-
this.
|
|
38
|
+
this.playwright = playwright;
|
|
38
39
|
this.savedFiles = new Set();
|
|
40
|
+
this.attachScreencast();
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
isPlaywrightFramework(): boolean {
|
package/src/ai/pilot.ts
CHANGED
|
@@ -89,15 +89,16 @@ export class Pilot implements Agent {
|
|
|
89
89
|
const notes = task.notesToString() || 'No notes recorded.';
|
|
90
90
|
|
|
91
91
|
let visualAnalysis = '';
|
|
92
|
+
let screenshotState: ActionResult | null = null;
|
|
92
93
|
if (this.provider.hasVision()) {
|
|
93
94
|
try {
|
|
94
95
|
const action = this.explorer.createAction();
|
|
95
|
-
|
|
96
|
+
screenshotState = await action.caputrePageWithScreenshot();
|
|
96
97
|
if (screenshotState.screenshot) {
|
|
97
98
|
visualAnalysis = (await this.researcher.answerQuestionAboutScreenshot(screenshotState, `Describe current page state relevant to: ${task.scenario}`)) || '';
|
|
98
99
|
}
|
|
99
100
|
} catch {
|
|
100
|
-
|
|
101
|
+
screenshotState = null;
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
|
|
@@ -167,26 +168,23 @@ export class Pilot implements Agent {
|
|
|
167
168
|
return false;
|
|
168
169
|
}
|
|
169
170
|
|
|
170
|
-
if (result.requestVerification && navigator) {
|
|
171
|
+
if (result.decision === 'pass' && result.requestVerification && navigator) {
|
|
171
172
|
tag('substep').log(`Pilot requesting verification: ${result.requestVerification}`);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (verifyResult.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
173
|
+
const verifyResult = await navigator.verifyState(result.requestVerification, currentState).catch(() => null);
|
|
174
|
+
if (verifyResult?.verified) {
|
|
175
|
+
if (verifyResult.assertionSteps?.length) {
|
|
176
|
+
this.explorer.getPlaywrightRecorder().recordVerification(verifyResult.assertionSteps);
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
let answer: string | null = null;
|
|
180
|
+
if (screenshotState?.screenshot) {
|
|
181
|
+
answer = await this.researcher.answerQuestionAboutScreenshot(screenshotState, `Does the screen confirm: "${result.requestVerification}"? Answer YES or NO only.`);
|
|
182
|
+
}
|
|
183
|
+
if (!(answer || '').trim().toUpperCase().startsWith('YES')) {
|
|
184
|
+
task.addNote(`Pilot: verification failed — ${result.requestVerification}`, TestResult.FAILED);
|
|
185
|
+
task.finish(TestResult.FAILED);
|
|
186
|
+
return false;
|
|
187
187
|
}
|
|
188
|
-
} catch (verifyErr: any) {
|
|
189
|
-
tag('warning').log(`Pilot verification errored: ${verifyErr.message}`);
|
|
190
188
|
}
|
|
191
189
|
}
|
|
192
190
|
|
|
@@ -389,6 +387,8 @@ export class Pilot implements Agent {
|
|
|
389
387
|
- If no verification was done → prefer "continue" with guidance telling tester what to verify.
|
|
390
388
|
- If verify assertion describes a state that was ALREADY TRUE before the test started, the verification proves nothing — reject with "continue".
|
|
391
389
|
|
|
390
|
+
requestVerification — pick assertions DOM can actually express. Some content is not assertable via DOM (iframe text, canvas, custom widgets, Monaco/CodeMirror editors). When the scenario goal lives in such a region, target a STABLE LANDMARK (container element, ARIA role, the parent that wraps the widget) rather than literal text inside it. Your "pass" verdict is honored even if the DOM assertion can't be made — pick the strongest landmark you can.
|
|
391
|
+
|
|
392
392
|
GUIDANCE FIELD: When decision is "continue", you MUST provide "guidance" — a specific actionable instruction:
|
|
393
393
|
- If evidence is insufficient: tell tester to verify with see()/verify(), specify WHAT to check
|
|
394
394
|
- If approach was wrong: tell tester to try a different method, suggest which one
|
|
@@ -470,7 +470,7 @@ export class Pilot implements Agent {
|
|
|
470
470
|
);
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
-
async reviewNewPage(task: Test, currentState: ActionResult): Promise<string> {
|
|
473
|
+
async reviewNewPage(task: Test, currentState: ActionResult, testerConversation: Conversation): Promise<string> {
|
|
474
474
|
if (!this.conversation) return '';
|
|
475
475
|
|
|
476
476
|
tag('substep').log('Pilot reviewing new page...');
|
|
@@ -481,8 +481,14 @@ export class Pilot implements Agent {
|
|
|
481
481
|
if (!pageSummary) return '';
|
|
482
482
|
|
|
483
483
|
const stateContext = this.buildStateContext(currentState);
|
|
484
|
+
const toolCalls = testerConversation
|
|
485
|
+
.getToolExecutions()
|
|
486
|
+
.filter((t: any) => t.wasSuccessful)
|
|
487
|
+
.slice(-this.stepsToReview);
|
|
488
|
+
const actionsContext = this.formatActions(toolCalls);
|
|
484
489
|
|
|
485
490
|
this.conversation.cleanupTag('page_summary', '...trimmed...', 1);
|
|
491
|
+
this.conversation.cleanupTag('recent_actions', '...trimmed...', 2);
|
|
486
492
|
|
|
487
493
|
return this.sendToPilot(
|
|
488
494
|
dedent`
|
|
@@ -497,6 +503,10 @@ export class Pilot implements Agent {
|
|
|
497
503
|
${pageSummary}
|
|
498
504
|
</page_summary>
|
|
499
505
|
|
|
506
|
+
<recent_actions>
|
|
507
|
+
${actionsContext || 'None'}
|
|
508
|
+
</recent_actions>
|
|
509
|
+
|
|
500
510
|
${this.formatExpectations(task)}
|
|
501
511
|
|
|
502
512
|
First: evaluate whether this navigation makes sense for the scenario goal. If the page is unrelated, instruct Tester to back() or reset(). Then plan next steps.
|
package/src/ai/rules.ts
CHANGED
|
@@ -282,11 +282,9 @@ export const actionRule = dedent`
|
|
|
282
282
|
I.fillField('Description', 'Hello world', '.editor'); // works for rich text / code editors too
|
|
283
283
|
</example>
|
|
284
284
|
|
|
285
|
-
I.fillField handles plain inputs, textareas, contenteditable regions, and rich text / code editors
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
Do NOT open the editor with raw JS (executeScript, page.evaluate), do NOT dispatch synthetic events,
|
|
289
|
-
do NOT call the editor's own API (monaco.editor.setValue, view.dispatch, etc.) to write text.
|
|
285
|
+
I.fillField handles plain inputs, textareas, contenteditable regions, and rich text / code editors transparently.
|
|
286
|
+
ALWAYS use I.fillField for rich text / code editors — target the editor container or its nearest label/heading with a normal locator.
|
|
287
|
+
If I.fillField does not work, I.type into the focused element is the fallback.
|
|
290
288
|
|
|
291
289
|
### I.type
|
|
292
290
|
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import dedent from 'dedent';
|
|
4
|
+
import { outputPath } from '../config.ts';
|
|
5
|
+
import { Stats } from '../stats.ts';
|
|
6
|
+
import type { Test } from '../test-plan.ts';
|
|
7
|
+
import type { Agent } from './agent.ts';
|
|
8
|
+
import type { Provider } from './provider.ts';
|
|
9
|
+
|
|
10
|
+
export class SessionAnalyst implements Agent {
|
|
11
|
+
emoji = '🧐';
|
|
12
|
+
private provider: Provider;
|
|
13
|
+
|
|
14
|
+
constructor(provider: Provider) {
|
|
15
|
+
this.provider = provider;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async analyze(tests: Test[]): Promise<string> {
|
|
19
|
+
const eligible = tests.filter((t) => t.startTime != null);
|
|
20
|
+
if (eligible.length === 0) return '';
|
|
21
|
+
|
|
22
|
+
const model = this.provider.getModelForAgent('analyst');
|
|
23
|
+
const customPrompt = this.provider.getSystemPromptForAgent('analyst', undefined);
|
|
24
|
+
|
|
25
|
+
const systemPrompt = dedent`
|
|
26
|
+
You write a brief end-of-session report after autonomous exploratory testing. Your reader is a developer who needs to know in seconds: what is broken, how to reproduce it, and which results were inconclusive.
|
|
27
|
+
|
|
28
|
+
Output MARKDOWN. No JSON, no preamble, no closing remarks. Start with the heading.
|
|
29
|
+
|
|
30
|
+
## Clustering
|
|
31
|
+
Group by ROOT CAUSE, not by scenario. If three tests fail for the same dropdown, that is ONE defect listing all three test refs (#3, #5, #7). Do not produce one cluster per test.
|
|
32
|
+
|
|
33
|
+
## Bucketing
|
|
34
|
+
Use the FINAL verdict (the test's \`result\` field) as the starting point. Mid-test errors that the automation recovered from do NOT make a passed test unreliable.
|
|
35
|
+
|
|
36
|
+
- **Defect** — real product bug. \`result: failed\` AND the failure reflects the app misbehaving (not the automation). The automation completed its interactions, the app contradicted the expected outcome. Severity required.
|
|
37
|
+
- **UX issue** — app works but the UI is ambiguous, controls are hidden, or labels are unclear. Worth flagging to design.
|
|
38
|
+
- **Execution issue** — the FINAL verdict is unreliable. Only two cases:
|
|
39
|
+
1. \`result: failed\` AND the failure was automation, environment, or UI/UX (locator missing, timeout, AI loop, navigation stuck, modal trapped focus, no accessible label) — i.e. the test could not conclude whether the app works.
|
|
40
|
+
2. \`result: passed\` AND clear evidence in the log shows the user-visible goal was NOT achieved (no confirmation visible, no state change verified, the assertion was vacuous).
|
|
41
|
+
|
|
42
|
+
A test that passed and shows no contrary evidence belongs in NO section. Do not list passed tests just because the log contains intermediate retries or recovered failures.
|
|
43
|
+
|
|
44
|
+
## Severity emoji (defects only)
|
|
45
|
+
- 🔴 critical or high — core flow blocked, data loss, security
|
|
46
|
+
- 🟡 medium — partial breakage with workaround
|
|
47
|
+
- 🟢 low — cosmetic
|
|
48
|
+
|
|
49
|
+
## Required format
|
|
50
|
+
|
|
51
|
+
# Session Analysis
|
|
52
|
+
|
|
53
|
+
<one sentence: total tests, defect count, headline finding>
|
|
54
|
+
|
|
55
|
+
## Defects
|
|
56
|
+
|
|
57
|
+
### 🔴 <plain-English title of the BUG, not the scenario name>
|
|
58
|
+
Affects: #3, #5, #7
|
|
59
|
+
Reproduce:
|
|
60
|
+
1. <concrete UI step a person can replay>
|
|
61
|
+
2. <next step>
|
|
62
|
+
Evidence: <one short observation from the test log>
|
|
63
|
+
|
|
64
|
+
### 🟡 <next defect>
|
|
65
|
+
...
|
|
66
|
+
|
|
67
|
+
## UX issues
|
|
68
|
+
|
|
69
|
+
- **<title>** — #4
|
|
70
|
+
<one short evidence line>
|
|
71
|
+
|
|
72
|
+
## Execution Issues
|
|
73
|
+
|
|
74
|
+
- **<short test name or scenario phrase>** — <plain-English one-liner: what made the result unreliable>
|
|
75
|
+
- **<…>** — <…>
|
|
76
|
+
|
|
77
|
+
## Rules
|
|
78
|
+
- Defects first, sorted by severity descending. Omit any section that has zero entries.
|
|
79
|
+
- Defect title describes the BUG ("Run-type dropdown does not filter"), never the scenario name.
|
|
80
|
+
- Reproduce steps are concrete UI actions derived from the log: URL + clicks + inputs. Imperative, one short line each.
|
|
81
|
+
- Evidence is the smallest factual observation from notes/steps that supports the claim — what was OBSERVED in the page (HTML, message, missing element). Never quote the test's \`result\` field as evidence; that is a tautology.
|
|
82
|
+
- **Execution Issues** entries must explain what actually went wrong in concrete terms a human understands: "could not find a Submit button after navigation", "page reloaded before the assertion ran", "passed without ever seeing a confirmation message", "marked failed but the new item appears in the list", "modal trapped focus and tests could not click outside", "ARIA tree had no labelled controls". Avoid jargon like "locator failed" without context. Never write category prefixes ("execution:", "false-positive:") — the section header already says it. No emoji on these entries.
|
|
83
|
+
- Do NOT include a passed test in any section unless evidence proves its goal was not achieved. Intermediate retries or recovered errors in the log are not grounds for listing a passed test.
|
|
84
|
+
- No editorialising, no restating the scenario verbatim, no closing summary.
|
|
85
|
+
|
|
86
|
+
${customPrompt || ''}
|
|
87
|
+
`;
|
|
88
|
+
|
|
89
|
+
const userPayload = dedent`
|
|
90
|
+
${eligible.length} tests were executed in this session.
|
|
91
|
+
|
|
92
|
+
${eligible.map((t, i) => this.serializeTest(t, i + 1)).join('\n\n')}
|
|
93
|
+
`;
|
|
94
|
+
|
|
95
|
+
const response = await this.provider.chat(
|
|
96
|
+
[
|
|
97
|
+
{ role: 'system', content: systemPrompt },
|
|
98
|
+
{ role: 'user', content: userPayload },
|
|
99
|
+
],
|
|
100
|
+
model,
|
|
101
|
+
{ agentName: 'analyst' }
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return (response?.text || '').trim();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
writeReport(markdown: string): string {
|
|
108
|
+
const filePath = outputPath('reports', `${Stats.sessionLabel()}.md`);
|
|
109
|
+
const dir = path.dirname(filePath);
|
|
110
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
111
|
+
writeFileSync(filePath, markdown);
|
|
112
|
+
return filePath;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private serializeTest(test: Test, ref: number): string {
|
|
116
|
+
const log = test
|
|
117
|
+
.getLog()
|
|
118
|
+
.slice(-30)
|
|
119
|
+
.map((entry) => ` - [${entry.type}] ${entry.content}`)
|
|
120
|
+
.join('\n');
|
|
121
|
+
|
|
122
|
+
return dedent`
|
|
123
|
+
<test ref="#${ref}">
|
|
124
|
+
url: ${test.startUrl || '/'}
|
|
125
|
+
scenario: ${test.scenario}
|
|
126
|
+
result: ${test.result || 'unknown'}
|
|
127
|
+
expected: ${test.expected.join(' | ') || '(none)'}
|
|
128
|
+
log:
|
|
129
|
+
${log}
|
|
130
|
+
</test>
|
|
131
|
+
`;
|
|
132
|
+
}
|
|
133
|
+
}
|
package/src/ai/tester.ts
CHANGED
|
@@ -268,7 +268,7 @@ export class Tester extends TaskAgent implements Agent {
|
|
|
268
268
|
nextStep += await this.prepareInstructionsForNextStep(task);
|
|
269
269
|
|
|
270
270
|
if (isNewPage && this.pilot) {
|
|
271
|
-
const guidance = await this.pilot.reviewNewPage(task, currentState);
|
|
271
|
+
const guidance = await this.pilot.reviewNewPage(task, currentState, conversation);
|
|
272
272
|
if (guidance) nextStep += `\n\n${guidance}`;
|
|
273
273
|
} else if ((iteration % this.progressCheckInterval === 0 || this.consecutiveFailures >= 3 || this.consecutiveEmptyResults >= 2) && this.pilot) {
|
|
274
274
|
const guidance = await this.pilot.analyzeProgress(task, currentState, conversation);
|
|
@@ -463,6 +463,8 @@ export class Tester extends TaskAgent implements Agent {
|
|
|
463
463
|
|
|
464
464
|
let context = '';
|
|
465
465
|
|
|
466
|
+
const focusArea = detectFocusArea(currentState.ariaSnapshot);
|
|
467
|
+
|
|
466
468
|
const focusedElement = extractFocusedElement(currentState.ariaSnapshot);
|
|
467
469
|
if (focusedElement) {
|
|
468
470
|
const isTextInput = ['textbox', 'combobox', 'searchbox'].includes(focusedElement.role);
|
|
@@ -480,6 +482,18 @@ export class Tester extends TaskAgent implements Agent {
|
|
|
480
482
|
`;
|
|
481
483
|
}
|
|
482
484
|
|
|
485
|
+
if (focusArea.detected) {
|
|
486
|
+
const areaName = focusArea.name ? ` "${focusArea.name}"` : '';
|
|
487
|
+
context += dedent`
|
|
488
|
+
<focus_scope>
|
|
489
|
+
A ${focusArea.type}${areaName} is currently open above the page.
|
|
490
|
+
Scope all interactions to elements inside this ${focusArea.type}.
|
|
491
|
+
Page navigation, filters, and tabs that exist outside it are not actionable while it is open and may share names or roles with elements inside it — prefer the locator inside the ${focusArea.type}.
|
|
492
|
+
Use <page_aria> to confirm the element you target is actually inside the ${focusArea.type}.
|
|
493
|
+
</focus_scope>
|
|
494
|
+
`;
|
|
495
|
+
}
|
|
496
|
+
|
|
483
497
|
if (currentState.isInsideIframe) {
|
|
484
498
|
const iframeInfo = currentState.iframeURL || this.explorer.getCurrentIframeInfo() || 'iframe context active';
|
|
485
499
|
context += dedent`
|
|
@@ -539,7 +553,6 @@ export class Tester extends TaskAgent implements Agent {
|
|
|
539
553
|
return context;
|
|
540
554
|
}
|
|
541
555
|
|
|
542
|
-
const focusArea = detectFocusArea(currentState.ariaSnapshot);
|
|
543
556
|
if (focusArea.detected && focusArea.name && this.pageStateHash && this.pageActionResult) {
|
|
544
557
|
const overlaySection = await this.researcher.researchOverlay(currentState, this.pageActionResult, this.pageStateHash);
|
|
545
558
|
if (overlaySection) {
|
|
@@ -38,17 +38,17 @@ export abstract class BaseCommand {
|
|
|
38
38
|
printSuggestions(): void {
|
|
39
39
|
if (this.suggestions.length === 0) return;
|
|
40
40
|
const prefix = isInteractive() ? '/' : `${getCliName()} `;
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const commandWidth = this.suggestions.reduce((max, s) => (s.command ? Math.max(max, prefix.length + s.command.length) : max), 0);
|
|
42
|
+
const lines = [chalk.bold('Suggested:')];
|
|
43
43
|
for (const { command, hint } of this.suggestions) {
|
|
44
|
-
tag('info').log('');
|
|
45
44
|
if (!command) {
|
|
46
|
-
|
|
45
|
+
lines.push(` ${chalk.dim(hint)}`);
|
|
47
46
|
continue;
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
const cmd = `${prefix}${command}`.padEnd(commandWidth);
|
|
49
|
+
lines.push(` ${chalk.yellow(cmd)} ${chalk.dim(hint)}`);
|
|
51
50
|
}
|
|
51
|
+
tag('info').log(lines.join('\n'));
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
protected parseArgs(args: string): { opts: Record<string, string | boolean>; args: string[] } {
|
|
@@ -3,6 +3,7 @@ import { BaseCommand, type Suggestion } from './base-command.js';
|
|
|
3
3
|
export class DrillCommand extends BaseCommand {
|
|
4
4
|
name = 'drill';
|
|
5
5
|
description = 'Drill all components on current page to learn interactions';
|
|
6
|
+
aliases = ['driller'];
|
|
6
7
|
suggestions: Suggestion[] = [
|
|
7
8
|
{ command: 'research', hint: 'see UI map first' },
|
|
8
9
|
{ command: 'navigate <page>', hint: 'go to another page' },
|
|
@@ -17,7 +18,7 @@ export class DrillCommand extends BaseCommand {
|
|
|
17
18
|
throw new Error('No active page to drill');
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
await this.explorBot.
|
|
21
|
+
await this.explorBot.agentDriller().drill({
|
|
21
22
|
knowledgePath,
|
|
22
23
|
maxComponents,
|
|
23
24
|
interactive: true,
|
|
@@ -30,7 +31,7 @@ export class DrillCommand extends BaseCommand {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
private parseMaxArg(args: string): number | undefined {
|
|
33
|
-
const match = args.match(/--max\s+(\d+)/);
|
|
34
|
+
const match = args.match(/--max-components\s+(\d+)/);
|
|
34
35
|
return match ? Number.parseInt(match[1], 10) : undefined;
|
|
35
36
|
}
|
|
36
37
|
}
|