explorbot 0.2.3 → 0.2.4
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 +1 -1
- package/bin/explorbot-cli.ts +7 -1
- package/boat/api-tester/src/config.ts +4 -2
- package/boat/doc-collector/bin/doc-collector-cli.ts +2 -0
- package/boat/doc-collector/src/ai/documentarian.ts +61 -31
- package/boat/doc-collector/src/config.ts +4 -2
- package/boat/prima/bin/prima-cli.ts +0 -0
- package/boat/prima/src/activity-line.ts +33 -0
- package/boat/prima/src/cli.ts +115 -86
- package/boat/prima/src/envelope.ts +80 -52
- package/boat/prima/src/prima.ts +547 -128
- package/boat/prima/src/pw-parser.ts +11 -1
- package/boat/prima/src/pw-registry.ts +4 -5
- package/boat/prima/src/session-log.ts +126 -0
- package/dist/bin/explorbot-cli.js +7 -1
- package/dist/boat/api-tester/bin/apibot-cli.js +2 -0
- package/dist/boat/api-tester/src/config.js +4 -2
- package/dist/boat/doc-collector/bin/doc-collector-cli.js +2 -0
- package/dist/boat/doc-collector/src/ai/documentarian.js +44 -19
- package/dist/boat/doc-collector/src/config.js +4 -2
- package/dist/boat/prima/src/activity-line.js +30 -0
- package/dist/boat/prima/src/cli.js +97 -77
- package/dist/boat/prima/src/envelope.js +70 -44
- package/dist/boat/prima/src/prima.js +515 -119
- package/dist/boat/prima/src/pw-parser.js +13 -1
- package/dist/boat/prima/src/pw-registry.js +4 -5
- package/dist/boat/prima/src/session-log.js +108 -0
- package/dist/package.json +3 -2
- package/dist/rules/navigator/verification-actions.md +20 -0
- package/dist/src/action-result.d.ts +7 -0
- package/dist/src/action-result.js +4 -0
- package/dist/src/action.d.ts +2 -0
- package/dist/src/action.js +36 -1
- package/dist/src/ai/captain/web-mode.js +6 -3
- package/dist/src/ai/captain.js +2 -0
- package/dist/src/ai/navigator.d.ts +7 -0
- package/dist/src/ai/navigator.js +10 -6
- package/dist/src/ai/pilot.d.ts +4 -0
- package/dist/src/ai/pilot.js +48 -2
- package/dist/src/ai/provider.js +2 -2
- package/dist/src/ai/rerunner.js +2 -1
- package/dist/src/ai/researcher.js +1 -1
- package/dist/src/ai/rules.js +17 -10
- package/dist/src/ai/task-agent.js +4 -1
- package/dist/src/ai/tester.d.ts +1 -1
- package/dist/src/ai/tester.js +33 -33
- package/dist/src/ai/tools.d.ts +14 -0
- package/dist/src/ai/tools.js +113 -36
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.js +13 -4
- package/dist/src/execution-controller.d.ts +2 -0
- package/dist/src/execution-controller.js +6 -0
- package/dist/src/explorbot.d.ts +2 -1
- package/dist/src/explorbot.js +3 -1
- package/dist/src/explorer.js +2 -3
- package/dist/src/playwright-recorder.js +30 -0
- package/dist/src/remote.d.ts +54 -0
- package/dist/src/remote.js +229 -0
- package/dist/src/reporter.d.ts +1 -0
- package/dist/src/reporter.js +7 -1
- package/dist/src/state-manager.d.ts +2 -1
- package/dist/src/stats.d.ts +1 -0
- package/dist/src/stats.js +1 -0
- package/dist/src/test-plan.d.ts +2 -0
- package/dist/src/test-plan.js +7 -0
- package/dist/src/utils/aria.d.ts +2 -8
- package/dist/src/utils/aria.js +69 -40
- package/dist/src/utils/html.js +1 -0
- package/dist/src/utils/logger.d.ts +6 -0
- package/dist/src/utils/logger.js +24 -0
- package/dist/src/utils/page-readiness.js +18 -1
- package/dist/src/utils/url-matcher.js +3 -0
- package/dist/src/utils/web-element.d.ts +2 -0
- package/dist/src/utils/web-element.js +8 -0
- package/dist/src/utils/web-sandbox.d.ts +1 -1
- package/dist/src/utils/web-sandbox.js +2 -3
- package/docs/api-testing/basics.md +90 -0
- package/docs/api-testing/planning.md +57 -0
- package/docs/api-testing/running-tests.md +55 -0
- package/docs/assets/cloud-report.png +0 -0
- package/docs/assets/html-report.png +0 -0
- package/docs/assets/langfuse-trace.png +0 -0
- package/docs/assets/successful-explore-run.png +0 -0
- package/docs/basics/getting-started.md +140 -0
- package/docs/basics/prerequisites.md +63 -0
- package/docs/basics/providers.md +362 -0
- package/docs/basics/running.md +78 -0
- package/docs/contributing/ai-integration-tests.md +57 -0
- package/docs/contributing/contributing.md +90 -0
- package/docs/contributing/demo-videos.md +36 -0
- package/docs/contributing/npm-package.md +138 -0
- package/docs/contributing/observability.md +227 -0
- package/docs/contributing/regression-tests.md +103 -0
- package/docs/contributing/testing.md +95 -0
- package/docs/doc-collection/basics.md +128 -0
- package/docs/doc-collection/crawling.md +67 -0
- package/docs/doc-collection/interactive-mode.md +99 -0
- package/docs/index.json +86 -0
- package/docs/reference/commands.md +994 -0
- package/docs/reference/configuration.md +569 -0
- package/docs/reference/scripting.md +303 -0
- package/docs/superpowers/plans/2026-08-01-actor-boat.md +925 -0
- package/docs/superpowers/plans/2026-08-01-prima-boat.md +1120 -0
- package/docs/superpowers/reviews/2026-08-06-prima-vs-playwright-cli.md +268 -0
- package/docs/superpowers/specs/2026-08-01-actor-boat-design.md +204 -0
- package/docs/superpowers/specs/2026-08-01-prima-boat-design.md +242 -0
- package/docs/superpowers/specs/2026-08-03-global-config-design.md +138 -0
- package/docs/superpowers/specs/2026-08-07-prima-fixes-design.md +394 -0
- package/docs/web-testing/agents.md +158 -0
- package/docs/web-testing/automated-tests.md +134 -0
- package/docs/web-testing/basics.md +91 -0
- package/docs/web-testing/customization.md +131 -0
- package/docs/web-testing/hooks.md +238 -0
- package/docs/web-testing/page-interaction.md +84 -0
- package/docs/web-testing/planner.md +122 -0
- package/docs/web-testing/rerun.md +164 -0
- package/docs/web-testing/researcher.md +380 -0
- package/docs/workflow/agentic-usage.md +233 -0
- package/docs/workflow/application-spec.md +73 -0
- package/docs/workflow/ci.md +202 -0
- package/docs/workflow/knowledge.md +310 -0
- package/docs/workflow/planning-styles.md +67 -0
- package/docs/workflow/reporting.md +133 -0
- package/docs/workflow/test-plans.md +90 -0
- package/package.json +3 -2
- package/rules/navigator/verification-actions.md +20 -0
- package/src/action-result.ts +11 -0
- package/src/action.ts +38 -2
- package/src/ai/captain/web-mode.ts +6 -3
- package/src/ai/captain.ts +3 -0
- package/src/ai/navigator.ts +14 -8
- package/src/ai/pilot.ts +53 -2
- package/src/ai/provider.ts +2 -4
- package/src/ai/rerunner.ts +2 -1
- package/src/ai/researcher.ts +1 -1
- package/src/ai/rules.ts +17 -10
- package/src/ai/task-agent.ts +3 -1
- package/src/ai/tester.ts +32 -33
- package/src/ai/tools.ts +132 -36
- package/src/config.ts +15 -4
- package/src/execution-controller.ts +8 -0
- package/src/explorbot.ts +4 -2
- package/src/explorer.ts +2 -2
- package/src/playwright-recorder.ts +23 -0
- package/src/remote.ts +238 -0
- package/src/reporter.ts +7 -1
- package/src/state-manager.ts +2 -1
- package/src/stats.ts +1 -0
- package/src/test-plan.ts +9 -0
- package/src/utils/aria.ts +65 -45
- package/src/utils/html.ts +1 -0
- package/src/utils/logger.ts +24 -1
- package/src/utils/page-readiness.ts +24 -1
- package/src/utils/url-matcher.ts +3 -0
- package/src/utils/web-element.ts +9 -0
- package/src/utils/web-sandbox.ts +3 -4
package/src/ai/tools.ts
CHANGED
|
@@ -3,8 +3,9 @@ import dedent from 'dedent';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { ActionResult, type PageDiff, type ToolResultMetadata } from '../action-result.ts';
|
|
5
5
|
import type { ExperienceTracker } from '../experience-tracker.ts';
|
|
6
|
+
import { Stats } from '../stats.ts';
|
|
6
7
|
import { type Task, TestResult } from '../test-plan.js';
|
|
7
|
-
import { LARGE_ARIA_CHANGE_THRESHOLD
|
|
8
|
+
import { LARGE_ARIA_CHANGE_THRESHOLD } from '../utils/aria.ts';
|
|
8
9
|
import { isFatalBrowserError } from '../utils/browser-errors.ts';
|
|
9
10
|
import { createDebug, tag } from '../utils/logger.js';
|
|
10
11
|
import { pause } from '../utils/loop.js';
|
|
@@ -33,6 +34,10 @@ export function createCodeceptJSTools({ explorer, stateManager, ai }: ToolDeps,
|
|
|
33
34
|
description: dedent`
|
|
34
35
|
Click an element by trying multiple CodeceptJS commands in order until one succeeds.
|
|
35
36
|
|
|
37
|
+
Use this only for elements the page context gives you no ref for. When the element shows a ref such as [ref=e14],
|
|
38
|
+
call clickRef with that ref instead — composing a locator for an element that already has a ref is wasted work,
|
|
39
|
+
and a locator can match several elements where a ref cannot.
|
|
40
|
+
|
|
36
41
|
Follow <locator_priority> from system prompt for locator selection.
|
|
37
42
|
|
|
38
43
|
I.click(locator) - click element matching locator
|
|
@@ -51,14 +56,13 @@ export function createCodeceptJSTools({ explorer, stateManager, ai }: ToolDeps,
|
|
|
51
56
|
commands: z.array(z.string()).describe(dedent`
|
|
52
57
|
FALLBACK LOCATORS for ONE element. All commands must click the SAME element.
|
|
53
58
|
Never mix different elements — use separate click() calls instead.
|
|
59
|
+
REQUIRED: include at least one command WITHOUT a container — a wrong or stale container always fails.
|
|
54
60
|
Order by reliability:
|
|
55
|
-
1. I.click(text, container) -
|
|
61
|
+
1. I.click(text, container) - when the container is verified - e.g. I.click("Save", ".modal")
|
|
56
62
|
2. I.click(ARIA, container) - e.g. I.click({"role":"button","text":"Save"}, ".modal")
|
|
57
63
|
3. I.click(CSS, container) - e.g. I.click("#btn", ".modal")
|
|
58
64
|
4. I.click(CSS) or I.click(XPath) - when locator already includes context (ID, XPath)
|
|
59
65
|
5. I.clickXY(x, y) - coordinates fallback
|
|
60
|
-
IMPORTANT: Always include at least one command WITHOUT a container as fallback,
|
|
61
|
-
in case the element moved to a different section (e.g. I.click("Save") without container).
|
|
62
66
|
`),
|
|
63
67
|
explanation: z.string().describe('Why you are clicking this element'),
|
|
64
68
|
}),
|
|
@@ -132,13 +136,7 @@ export function createCodeceptJSTools({ explorer, stateManager, ai }: ToolDeps,
|
|
|
132
136
|
const toolResult = await ActionResult.fromState(stateManager.getCurrentState()!).toToolResult(previousState, commands[0]);
|
|
133
137
|
await commitNote(activeNote, TestResult.FAILED, toolResult, action);
|
|
134
138
|
|
|
135
|
-
|
|
136
|
-
const lastError = attempts[attempts.length - 1]?.error || '';
|
|
137
|
-
if (lastError.includes('was not found') || lastError.includes('not found by text')) {
|
|
138
|
-
suggestion = 'Element was not found in the DOM. Use xpathCheck() to locate it, context() to refresh snapshot, or visualClick() to click by visual appearance.';
|
|
139
|
-
} else if (lastError.includes('Timeout') || lastError.includes('intercept')) {
|
|
140
|
-
suggestion = 'Element exists but could not be clicked (possibly covered by overlay or not interactable). Try closing overlapping panels first, or use visualClick().';
|
|
141
|
-
}
|
|
139
|
+
const suggestion = clickFailureSuggestion(attempts);
|
|
142
140
|
|
|
143
141
|
return failedToolResult(
|
|
144
142
|
'click',
|
|
@@ -153,6 +151,41 @@ export function createCodeceptJSTools({ explorer, stateManager, ai }: ToolDeps,
|
|
|
153
151
|
},
|
|
154
152
|
}),
|
|
155
153
|
|
|
154
|
+
clickRef: tool({
|
|
155
|
+
description: dedent`
|
|
156
|
+
Click an element by the ref the page context gave it, e.g. [ref=e14].
|
|
157
|
+
|
|
158
|
+
Prefer this over click() whenever the element you want carries a ref. A ref names one exact element, so it
|
|
159
|
+
cannot match several by mistake and never needs disambiguating — it is the fastest way to click.
|
|
160
|
+
Only pass a ref that appears in the page context you were given. Never invent or guess one.
|
|
161
|
+
If it reports the ref is gone, the page has been rebuilt: get fresh context and use the new ref.
|
|
162
|
+
`,
|
|
163
|
+
inputSchema: z.object({
|
|
164
|
+
ref: z.string().describe('The ref exactly as it appears in the page context, e.g. "e14"'),
|
|
165
|
+
element: z.string().describe('Role and name of the element you are clicking, for the record'),
|
|
166
|
+
}),
|
|
167
|
+
execute: async ({ ref, element }) => {
|
|
168
|
+
const activeNote = task.startNote(`Click ${element}`);
|
|
169
|
+
const previousState = ActionResult.fromState(stateManager.getCurrentState()!);
|
|
170
|
+
const action = explorer.action();
|
|
171
|
+
const named = await describeRef(explorer, ref);
|
|
172
|
+
const run = `I.usePlaywrightTo(${JSON.stringify(`click ${element}`)}, async ({ page }) => page.locator(${JSON.stringify(`aria-ref=${ref}`)}).click())`;
|
|
173
|
+
|
|
174
|
+
if (!(await action.attempt(run, `Click ${element}`))) {
|
|
175
|
+
activeNote.commit(TestResult.FAILED);
|
|
176
|
+
return failedToolResult('clickRef', `Ref ${ref} could not be clicked: ${errorText(action.lastError)}`, {
|
|
177
|
+
suggestion: 'The ref may belong to an older version of the page. Get fresh context and use the ref it gives, or fall back to click() with a locator.',
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// a ref belongs to this session only, so the run is reported as the locator a later test can replay
|
|
182
|
+
const code = named ? `I.click(${JSON.stringify(named)})` : run;
|
|
183
|
+
const toolResult = await ActionResult.fromState(stateManager.getCurrentState()!).toToolResult(previousState, code);
|
|
184
|
+
await commitNote(activeNote, TestResult.PASSED, toolResult, action);
|
|
185
|
+
return successToolResult('clickRef', { ...toolResult, code }, action);
|
|
186
|
+
},
|
|
187
|
+
}),
|
|
188
|
+
|
|
156
189
|
hover: tool({
|
|
157
190
|
description: dedent`
|
|
158
191
|
Move the mouse cursor to an element to reveal hover-only controls.
|
|
@@ -299,15 +332,11 @@ export function createCodeceptJSTools({ explorer, stateManager, ai }: ToolDeps,
|
|
|
299
332
|
const focusFreeKeys = new Set(['Escape', 'Esc', 'Tab', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12']);
|
|
300
333
|
const needsFocus = !focusFreeKeys.has(keyToUse) && !modifier;
|
|
301
334
|
|
|
302
|
-
if (needsFocus) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return failedToolResult('pressKey', `No element is focused. Key '${keyToUse}' requires a focused element.`, {
|
|
308
|
-
suggestion: 'Click the target element first, then press the key.',
|
|
309
|
-
});
|
|
310
|
-
}
|
|
335
|
+
if (needsFocus && !(await hasFocusedElement(explorer))) {
|
|
336
|
+
activeNote.commit(TestResult.FAILED);
|
|
337
|
+
return failedToolResult('pressKey', `No element is focused. Key '${keyToUse}' requires a focused element.`, {
|
|
338
|
+
suggestion: 'Click the target element first, then press the key.',
|
|
339
|
+
});
|
|
311
340
|
}
|
|
312
341
|
|
|
313
342
|
const previousState = ActionResult.fromState(stateManager.getCurrentState()!);
|
|
@@ -358,6 +387,8 @@ export function createCodeceptJSTools({ explorer, stateManager, ai }: ToolDeps,
|
|
|
358
387
|
Execute raw CodeceptJS code block with multiple commands.
|
|
359
388
|
USE THIS TOOL for typing text into fields: I.fillField, I.type
|
|
360
389
|
|
|
390
|
+
Do not put a click on a ref-bearing element in here — clickRef with its ref is cheaper and cannot mis-target.
|
|
391
|
+
|
|
361
392
|
Follow <actions> from system prompt for available commands.
|
|
362
393
|
Follow <locator_priority> from system prompt for locator selection.
|
|
363
394
|
|
|
@@ -539,26 +570,25 @@ export function createLearnExperienceTool({ getExperienceTracker, getState }: {
|
|
|
539
570
|
}
|
|
540
571
|
|
|
541
572
|
export function createAgentTools({ explorer, stateManager, ai, researcher, navigator, supervisor, withExperience }: AgentToolDeps): any {
|
|
542
|
-
let visionDisabled = false;
|
|
543
|
-
|
|
544
573
|
const tools: Record<string, any> = {
|
|
545
574
|
see: tool({
|
|
546
575
|
description: dedent`
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
576
|
+
Answer a question about the page from a screenshot, for things its structure cannot express:
|
|
577
|
+
layout and position, what an image or canvas depicts, colour, and whether something is covered or cut off.
|
|
578
|
+
This runs a second model and is the slowest tool here, so reach for it only when the question is genuinely visual.
|
|
579
|
+
Do NOT use it to confirm an action landed — every action already reports what changed on the page.
|
|
550
580
|
Input schema has exactly one field: request. Do not pass text, reason, assertion, or other fields.
|
|
551
581
|
|
|
552
582
|
<example>
|
|
553
|
-
request: "
|
|
554
|
-
result: "
|
|
583
|
+
request: "Is the save button covered by anything, and does the chart show any plotted data?"
|
|
584
|
+
result: "The save button is partly behind a cookie banner at the bottom. The chart area is empty apart from its axes."
|
|
555
585
|
</example>
|
|
556
586
|
`,
|
|
557
587
|
inputSchema: z.object({
|
|
558
588
|
request: z.string().describe('LLM-friendly description of the page contents to look for. 1-3 sentences. No more than 100 words.'),
|
|
559
589
|
}),
|
|
560
590
|
execute: async ({ request }) => {
|
|
561
|
-
if (visionDisabled) {
|
|
591
|
+
if (Stats.visionDisabled) {
|
|
562
592
|
return failedToolResult('see', 'Vision tools are disabled for this session. Use context() to get fresh ARIA snapshot and analyze page state from ARIA data.');
|
|
563
593
|
}
|
|
564
594
|
|
|
@@ -583,8 +613,7 @@ export function createAgentTools({ explorer, stateManager, ai, researcher, navig
|
|
|
583
613
|
} catch (error) {
|
|
584
614
|
throwIfFatalBrowserError(error);
|
|
585
615
|
const errorMessage = errorText(error);
|
|
586
|
-
|
|
587
|
-
tag('warning').log('⚠️ Vision model is not available. Visual checks are disabled for this session.');
|
|
616
|
+
disableVision();
|
|
588
617
|
return failedToolResult('see', `See tool failed: ${errorMessage}`, {
|
|
589
618
|
suggestion: 'Vision is now disabled. Use context() to get fresh ARIA snapshot and analyze page state from ARIA data.',
|
|
590
619
|
});
|
|
@@ -676,6 +705,13 @@ export function createAgentTools({ explorer, stateManager, ai, researcher, navig
|
|
|
676
705
|
);
|
|
677
706
|
}
|
|
678
707
|
|
|
708
|
+
if (result.inexpressible) {
|
|
709
|
+
return failedToolResult('verify', `No assertion could express this claim: ${assertion}`, {
|
|
710
|
+
inexpressible: true,
|
|
711
|
+
suggestion: 'This is not evidence the page is wrong — the claim could not be turned into an assertion. Restate it in terms of what is visible or of a control state, or check it with see().',
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
|
|
679
715
|
return failedToolResult('verify', `Verification failed: ${assertion}`, {
|
|
680
716
|
suggestion: 'The assertion could not be verified. Check if the condition is actually present on the page or try a different assertion.',
|
|
681
717
|
});
|
|
@@ -804,7 +840,7 @@ export function createAgentTools({ explorer, stateManager, ai, researcher, navig
|
|
|
804
840
|
context: z.string().describe('What you already tried and why it failed - helps with accurate identification'),
|
|
805
841
|
}),
|
|
806
842
|
execute: async ({ element, context }) => {
|
|
807
|
-
if (visionDisabled) {
|
|
843
|
+
if (Stats.visionDisabled) {
|
|
808
844
|
return failedToolResult('visualClick', 'Vision tools are disabled for this session. Use xpathCheck() to find the element, then click() with the discovered locator.');
|
|
809
845
|
}
|
|
810
846
|
|
|
@@ -860,8 +896,7 @@ export function createAgentTools({ explorer, stateManager, ai, researcher, navig
|
|
|
860
896
|
} catch (error) {
|
|
861
897
|
throwIfFatalBrowserError(error);
|
|
862
898
|
const errorMessage = errorText(error);
|
|
863
|
-
|
|
864
|
-
tag('warning').log('⚠️ Vision model is not available. Visual clicks are disabled for this session.');
|
|
899
|
+
disableVision();
|
|
865
900
|
return failedToolResult('visualClick', `visualClick tool failed: ${errorMessage}`, {
|
|
866
901
|
suggestion: 'Vision is now disabled. Use xpathCheck() to find the element, then click() with the discovered locator.',
|
|
867
902
|
});
|
|
@@ -1011,6 +1046,12 @@ export function createAgentTools({ explorer, stateManager, ai, researcher, navig
|
|
|
1011
1046
|
}),
|
|
1012
1047
|
};
|
|
1013
1048
|
|
|
1049
|
+
const disableVision = (): void => {
|
|
1050
|
+
Stats.visionDisabled = true;
|
|
1051
|
+
withdrawVisionTools(tools);
|
|
1052
|
+
tag('warning').log('⚠️ Vision model is not available. Visual tools are disabled for this session.');
|
|
1053
|
+
};
|
|
1054
|
+
|
|
1014
1055
|
if (withExperience !== false) {
|
|
1015
1056
|
tools.learnExperience = createLearnExperienceTool({
|
|
1016
1057
|
getExperienceTracker: () => stateManager.getExperienceTracker(),
|
|
@@ -1063,6 +1104,8 @@ export function createAgentTools({ explorer, stateManager, ai, researcher, navig
|
|
|
1063
1104
|
});
|
|
1064
1105
|
}
|
|
1065
1106
|
|
|
1107
|
+
withdrawVisionTools(tools);
|
|
1108
|
+
|
|
1066
1109
|
return tools;
|
|
1067
1110
|
}
|
|
1068
1111
|
|
|
@@ -1112,14 +1155,33 @@ function errorText(error: unknown): string {
|
|
|
1112
1155
|
return 'Unknown error occurred';
|
|
1113
1156
|
}
|
|
1114
1157
|
|
|
1115
|
-
async function commitNote(activeNote: any, result: TestResult, toolResult: any, action: any): Promise<void> {
|
|
1158
|
+
export async function commitNote(activeNote: any, result: TestResult, toolResult: any, action: any): Promise<void> {
|
|
1116
1159
|
if (toolResult?.pageDiff?.ariaChanges || toolResult?.pageDiff?.urlChanged) {
|
|
1117
1160
|
activeNote.screenshot = await action.saveScreenshot();
|
|
1118
1161
|
}
|
|
1119
1162
|
activeNote.commit(result);
|
|
1120
1163
|
}
|
|
1121
1164
|
|
|
1122
|
-
function
|
|
1165
|
+
async function describeRef(explorer: any, ref: string): Promise<{ role: string; text: string } | null> {
|
|
1166
|
+
return Promise.resolve(
|
|
1167
|
+
explorer?.withPage?.((page: any) =>
|
|
1168
|
+
page.locator(`aria-ref=${ref}`).evaluate((el: any) => {
|
|
1169
|
+
const tag = el.tagName.toLowerCase();
|
|
1170
|
+
const roles: Record<string, string> = { a: 'link', button: 'button', select: 'combobox', textarea: 'textbox' };
|
|
1171
|
+
const role = el.getAttribute('role') || roles[tag] || tag;
|
|
1172
|
+
const text = (el.getAttribute('aria-label') || el.innerText || el.value || '').trim().split('\n')[0];
|
|
1173
|
+
if (!text) return null;
|
|
1174
|
+
return { role, text };
|
|
1175
|
+
})
|
|
1176
|
+
)
|
|
1177
|
+
).catch(() => null);
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
async function hasFocusedElement(explorer: any): Promise<boolean> {
|
|
1181
|
+
return explorer.withPage((page: any) => page.evaluate(() => !!document.activeElement && document.activeElement !== document.body)).catch(() => true);
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
export function successToolResult(action: string, data?: Record<string, any>, source?: { playwrightGroupId?: string | null; assertionSteps?: any[] }) {
|
|
1123
1185
|
const result: Record<string, any> = { success: true, action, ...data };
|
|
1124
1186
|
if (source?.playwrightGroupId) {
|
|
1125
1187
|
result.playwrightGroupId = source.playwrightGroupId;
|
|
@@ -1155,7 +1217,7 @@ function hasObservablePageChange(data?: Record<string, any>): boolean {
|
|
|
1155
1217
|
return Array.isArray(data.pageDiff.htmlParts) && data.pageDiff.htmlParts.length > 0;
|
|
1156
1218
|
}
|
|
1157
1219
|
|
|
1158
|
-
async function failedToolResult(action: string, message: string, data?: Record<string, any>, error?: Error | null) {
|
|
1220
|
+
export async function failedToolResult(action: string, message: string, data?: Record<string, any>, error?: Error | null) {
|
|
1159
1221
|
const result: Record<string, any> = { success: false, action, message, ...data };
|
|
1160
1222
|
if (data?.pageDiff) {
|
|
1161
1223
|
result.suggestion = data.suggestion ? `${data.suggestion} ${PAGE_DIFF_SUGGESTION}` : PAGE_DIFF_SUGGESTION;
|
|
@@ -1192,6 +1254,40 @@ function getMultipleElementsSuggestion(): string {
|
|
|
1192
1254
|
`;
|
|
1193
1255
|
}
|
|
1194
1256
|
|
|
1257
|
+
export function withdrawVisionTools(tools: Record<string, any>): void {
|
|
1258
|
+
if (!Stats.visionDisabled) return;
|
|
1259
|
+
Reflect.deleteProperty(tools, 'see');
|
|
1260
|
+
Reflect.deleteProperty(tools, 'visualClick');
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
export function clickFailureSuggestion(attempts: Array<{ error?: string }>): string {
|
|
1264
|
+
const errors = attempts.map((a) => a.error || '');
|
|
1265
|
+
|
|
1266
|
+
if (errors.some((e) => e.includes('not enabled'))) {
|
|
1267
|
+
return 'Element exists but is DISABLED — clicking it again cannot work. A precondition is unmet: a required field is empty, nothing is selected, or a dialog is blocking. Satisfy it, then retry.';
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
if (errors.some((e) => e.includes('intercepts pointer events'))) {
|
|
1271
|
+
return 'Element exists but another element covers it. Close the overlapping panel or dialog, then retry.';
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
if (errors.some((e) => e.includes('is not visible'))) {
|
|
1275
|
+
return 'Element is in the DOM but not visible. Reveal it first — scroll to it, expand its section, or open the panel holding it.';
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
const notFound = errors.filter((e) => e.includes('was not found'));
|
|
1279
|
+
|
|
1280
|
+
if (notFound.length && notFound.every((e) => e.includes('was not found inside element'))) {
|
|
1281
|
+
return 'Element was not found inside that container — the container is wrong or stale, and the element may exist elsewhere on the page. Retry the same locator WITHOUT a container, or verify the container with xpathCheck().';
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
if (notFound.length) {
|
|
1285
|
+
return 'Element was not found in the DOM. Use xpathCheck() to locate it, context() to refresh snapshot, or visualClick() to click by visual appearance.';
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
return "Try xpathCheck() to find the element's actual position, see() for visual analysis, or visualClick() to click by visual appearance.";
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1195
1291
|
const MAX_DISAMBIGUATE_ELEMENTS = 10;
|
|
1196
1292
|
const MULTIPLE_ELEMENTS_PATTERN = 'multiple elements';
|
|
1197
1293
|
|
package/src/config.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import path, { basename, dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
4
5
|
import { parseEnv } from 'node:util';
|
|
5
6
|
import dedent from 'dedent';
|
|
6
7
|
import matter from 'gray-matter';
|
|
7
8
|
import { type SiteRecord, findGlobalConfig, globalEnvPath, isGlobalConfigPath, registerSite, resolveSiteTarget } from './global-config.js';
|
|
8
9
|
import { getCliName } from './utils/cli-name.js';
|
|
9
|
-
import { log } from './utils/logger.js';
|
|
10
|
+
import { log, tag } from './utils/logger.js';
|
|
10
11
|
|
|
11
12
|
export const PROVIDERS: Record<string, ProviderInfo> = {
|
|
12
13
|
openai: { envKey: 'OPENAI_API_KEY', load: async () => (await import('@ai-sdk/openai')).createOpenAI() },
|
|
@@ -197,6 +198,7 @@ interface HtmlConfig {
|
|
|
197
198
|
interface ActionConfig {
|
|
198
199
|
delay?: number;
|
|
199
200
|
retries?: number;
|
|
201
|
+
timeout?: number;
|
|
200
202
|
}
|
|
201
203
|
|
|
202
204
|
interface ReporterConfig {
|
|
@@ -455,7 +457,15 @@ export class ConfigParser {
|
|
|
455
457
|
}
|
|
456
458
|
|
|
457
459
|
public resolveTargetPath(target?: string): string {
|
|
458
|
-
if (!this.site)
|
|
460
|
+
if (!this.site) {
|
|
461
|
+
const configured = this.config?.playwright?.url || this.config?.web?.url;
|
|
462
|
+
const targetOrigin = target ? URL.parse(target)?.origin : null;
|
|
463
|
+
const baseOrigin = configured ? URL.parse(configured)?.origin : null;
|
|
464
|
+
if (targetOrigin && baseOrigin && targetOrigin !== baseOrigin) {
|
|
465
|
+
tag('warning').log(`Exploring ${targetOrigin} but base URL is ${baseOrigin}. Relative navigation resolves against the base URL — set web.url to ${targetOrigin} to avoid it.`);
|
|
466
|
+
}
|
|
467
|
+
return target || '/';
|
|
468
|
+
}
|
|
459
469
|
if (!target) return this.siteStartPath;
|
|
460
470
|
|
|
461
471
|
const resolved = resolveSiteTarget(target, this.site.url);
|
|
@@ -610,17 +620,18 @@ export class ConfigParser {
|
|
|
610
620
|
|
|
611
621
|
private async loadConfigModule(configPath: string): Promise<any> {
|
|
612
622
|
const ext = configPath.split('.').pop();
|
|
623
|
+
const moduleUrl = pathToFileURL(resolve(configPath)).href;
|
|
613
624
|
|
|
614
625
|
if (ext === 'ts') {
|
|
615
626
|
try {
|
|
616
|
-
const module = await import(
|
|
627
|
+
const module = await import(moduleUrl);
|
|
617
628
|
return module;
|
|
618
629
|
} catch (error) {
|
|
619
630
|
const require = (await import('node:module')).createRequire(import.meta.url);
|
|
620
631
|
return require(configPath);
|
|
621
632
|
}
|
|
622
633
|
} else if (ext === 'js' || ext === 'mjs') {
|
|
623
|
-
const module = await import(
|
|
634
|
+
const module = await import(moduleUrl);
|
|
624
635
|
return module;
|
|
625
636
|
} else {
|
|
626
637
|
const content = readFileSync(configPath, 'utf8');
|
|
@@ -27,6 +27,14 @@ export class ExecutionController extends EventEmitter {
|
|
|
27
27
|
this.inputCallback = callback;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
hasInputCallback(): boolean {
|
|
31
|
+
return !!this.inputCallback;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
clearInputCallback(): void {
|
|
35
|
+
this.inputCallback = null;
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
startExecution(): void {
|
|
31
39
|
this.interrupted = false;
|
|
32
40
|
this.abortController = new AbortController();
|
package/src/explorbot.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { createAgentTools } from './ai/tools.ts';
|
|
|
20
20
|
import { ApiClient } from './api/api-client.ts';
|
|
21
21
|
import { RequestStore } from './api/request-store.ts';
|
|
22
22
|
import { loadSpec } from './api/spec-reader.ts';
|
|
23
|
-
import type { ExplorbotConfig } from './config.js';
|
|
23
|
+
import type { ExplorbotConfig, ReporterConfig } from './config.js';
|
|
24
24
|
import { ConfigParser } from './config.ts';
|
|
25
25
|
import { ExperienceTracker } from './experience-tracker.ts';
|
|
26
26
|
import Explorer from './explorer.ts';
|
|
@@ -49,6 +49,7 @@ export interface ExplorBotOptions {
|
|
|
49
49
|
session?: string | boolean;
|
|
50
50
|
instance?: string;
|
|
51
51
|
optionalAi?: boolean;
|
|
52
|
+
reporter?: ReporterConfig;
|
|
52
53
|
attachedBrowser?: Browser;
|
|
53
54
|
applicationSpec?: string;
|
|
54
55
|
}
|
|
@@ -128,6 +129,7 @@ export class ExplorBot {
|
|
|
128
129
|
if (this.provider) return;
|
|
129
130
|
this.config = await this.configParser.loadConfig(this.options);
|
|
130
131
|
if (this.options.session === true) this.options.session = path.join(this.configParser.getOutputDir(), 'session.json');
|
|
132
|
+
if (typeof this.options.session === 'string') this.options.session = path.resolve(this.options.path || '.', this.options.session);
|
|
131
133
|
if (this.options.optionalAi) return this.bootstrapOptionalProvider();
|
|
132
134
|
this.provider = new AIProvider(this.config.ai);
|
|
133
135
|
await this.provider.validateConnection();
|
|
@@ -175,7 +177,7 @@ export class ExplorBot {
|
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
reporter(): Reporter {
|
|
178
|
-
return (this._reporter ||= new Reporter(this.config.reporter, this.stateManager()));
|
|
180
|
+
return (this._reporter ||= new Reporter(this.options.reporter || this.config.reporter, this.stateManager()));
|
|
179
181
|
}
|
|
180
182
|
|
|
181
183
|
requestStore(): RequestStore {
|
package/src/explorer.ts
CHANGED
|
@@ -721,11 +721,11 @@ class Explorer {
|
|
|
721
721
|
if (this.observedTestPages.has(page)) return;
|
|
722
722
|
|
|
723
723
|
this.testPageErrorHandler ||= (err: Error) => {
|
|
724
|
-
this._activeTest?.
|
|
724
|
+
this._activeTest?.addObservation(`Console error: ${err.message}`);
|
|
725
725
|
};
|
|
726
726
|
this.testConsoleHandler ||= (msg: any) => {
|
|
727
727
|
if (msg.type() !== 'error') return;
|
|
728
|
-
this._activeTest?.
|
|
728
|
+
this._activeTest?.addObservation(`Console error: ${msg.text()}`);
|
|
729
729
|
};
|
|
730
730
|
this.testDialogHandler ||= (dialog: any) => {
|
|
731
731
|
const dialogType = dialog.type();
|
|
@@ -287,8 +287,31 @@ function formatSelectOption(options: any): string {
|
|
|
287
287
|
return `[${values.map((v) => quote(v)).join(', ')}]`;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
+
function assertionLocator(target: any): string | null {
|
|
291
|
+
if (typeof target === 'string') return `page.locator(${JSON.stringify(target)})`;
|
|
292
|
+
if (!target || typeof target !== 'object') return null;
|
|
293
|
+
|
|
294
|
+
const role = target.role || target.aria;
|
|
295
|
+
const name = target.text ?? target.name ?? target.label;
|
|
296
|
+
if (role && name) return `page.getByRole(${JSON.stringify(String(role))}, { name: ${JSON.stringify(String(name))} })`;
|
|
297
|
+
if (role) return `page.getByRole(${JSON.stringify(String(role))})`;
|
|
298
|
+
if (name) return `page.getByText(${JSON.stringify(String(name))})`;
|
|
299
|
+
if (target.css) return `page.locator(${JSON.stringify(String(target.css))})`;
|
|
300
|
+
if (target.xpath) return `page.locator(${JSON.stringify(`xpath=${target.xpath}`)})`;
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
|
|
290
304
|
export function renderAssertion(assertion: { name: string; args: any[] }): string {
|
|
291
305
|
const args = assertion.args;
|
|
306
|
+
const target = assertionLocator(args[0]);
|
|
307
|
+
|
|
308
|
+
if (target) {
|
|
309
|
+
if (assertion.name === 'seeElement') return `await expect(${target}).toBeVisible();`;
|
|
310
|
+
if (assertion.name === 'dontSeeElement') return `await expect(${target}).toBeHidden();`;
|
|
311
|
+
if (assertion.name === 'seeInField' && args[1] !== undefined) return `await expect(${target}).toHaveValue(${JSON.stringify(String(args[1]))});`;
|
|
312
|
+
if (assertion.name === 'dontSeeInField' && args[1] !== undefined) return `await expect(${target}).not.toHaveValue(${JSON.stringify(String(args[1]))});`;
|
|
313
|
+
}
|
|
314
|
+
|
|
292
315
|
if (assertion.name === 'see' && typeof args[0] === 'string') {
|
|
293
316
|
return `await expect(page).toContainText(${JSON.stringify(args[0])});`;
|
|
294
317
|
}
|