explorbot 0.3.1 → 0.3.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/bin/explorbot-cli.ts +16 -5
- package/dist/bin/explorbot-cli.js +14 -4
- package/dist/models.json +2 -0
- package/dist/package.json +1 -1
- package/dist/src/action-result.d.ts +4 -0
- package/dist/src/action-result.js +20 -12
- package/dist/src/action.d.ts +11 -0
- package/dist/src/action.js +28 -11
- package/dist/src/ai/conversation.d.ts +2 -1
- package/dist/src/ai/conversation.js +9 -4
- package/dist/src/ai/driller.js +3 -1
- package/dist/src/ai/navigator.d.ts +3 -0
- package/dist/src/ai/navigator.js +20 -4
- package/dist/src/ai/pilot.js +9 -2
- package/dist/src/ai/provider.d.ts +2 -0
- package/dist/src/ai/provider.js +18 -1
- package/dist/src/ai/researcher/deep-analysis.js +7 -3
- package/dist/src/ai/researcher/sections.js +0 -1
- package/dist/src/ai/researcher.js +0 -1
- package/dist/src/ai/rules.js +0 -1
- package/dist/src/ai/tester.d.ts +1 -0
- package/dist/src/ai/tester.js +9 -11
- package/dist/src/ai/tools.d.ts +2 -0
- package/dist/src/ai/tools.js +21 -4
- package/dist/src/commands/exit-command.js +1 -1
- package/dist/src/commands/init-command.js +74 -24
- package/dist/src/components/InitWizard.d.ts +2 -1
- package/dist/src/components/InitWizard.js +8 -4
- package/dist/src/explorbot.js +1 -0
- package/dist/src/explorer.js +1 -0
- package/dist/src/knowledge-tracker.d.ts +3 -1
- package/dist/src/knowledge-tracker.js +4 -4
- package/dist/src/state-manager.d.ts +2 -0
- package/dist/src/state-manager.js +3 -3
- package/dist/src/utils/aria.js +1 -1
- package/dist/src/utils/html.d.ts +2 -1
- package/dist/src/utils/html.js +10 -4
- package/dist/src/utils/overlay.d.ts +24 -0
- package/dist/src/utils/overlay.js +43 -0
- package/docs/basics/providers.md +2 -4
- package/models.json +2 -0
- package/package.json +1 -1
- package/src/action-result.ts +25 -15
- package/src/action.ts +36 -13
- package/src/ai/conversation.ts +11 -5
- package/src/ai/driller.ts +3 -1
- package/src/ai/navigator.ts +22 -4
- package/src/ai/pilot.ts +9 -2
- package/src/ai/provider.ts +19 -1
- package/src/ai/researcher/deep-analysis.ts +8 -3
- package/src/ai/researcher/sections.ts +0 -1
- package/src/ai/researcher.ts +0 -1
- package/src/ai/rules.ts +0 -1
- package/src/ai/tester.ts +9 -9
- package/src/ai/tools.ts +20 -4
- package/src/commands/exit-command.ts +1 -1
- package/src/commands/init-command.ts +81 -22
- package/src/components/InitWizard.tsx +8 -4
- package/src/explorbot.ts +1 -0
- package/src/explorer.ts +1 -0
- package/src/knowledge-tracker.ts +4 -4
- package/src/state-manager.ts +4 -3
- package/src/utils/aria.ts +1 -1
- package/src/utils/html.ts +13 -4
- package/src/utils/overlay.ts +51 -0
|
@@ -111,7 +111,6 @@ export function WithSections<T extends Constructor>(Base: T) {
|
|
|
111
111
|
- Do not copy global toolbar, navigation, list, or detail elements into this section unless they are descendants of this section container.
|
|
112
112
|
- Every element with eidx inside this section's container MUST appear in the table.
|
|
113
113
|
- Every row needs CSS; ARIA may be "-" for icon-only buttons.
|
|
114
|
-
- ARIA locator JSON uses keys "role" and "text" (NOT "name").
|
|
115
114
|
- Elements marked data-explorbot-hit="covered" or "offscreen" are not directly actionable; describe the covering or focused UI first.
|
|
116
115
|
- In split-pane pages, entity detail panels are active detail context; include close/back/pin controls in the detail panel section when present.
|
|
117
116
|
</rules>
|
package/src/ai/researcher.ts
CHANGED
|
@@ -403,7 +403,6 @@ export class Researcher extends ResearcherBase implements Agent {
|
|
|
403
403
|
- If an element has data-explorbot-hit="covered" or "offscreen", do not present it as directly actionable. Prefer the overlay, drawer, dialog, or focused section covering it, and mention what must be dismissed or revealed first.
|
|
404
404
|
- Every element with an eidx attribute MUST appear in exactly one matching UI map section — describe icon-only buttons by their visual role.
|
|
405
405
|
- Every UI map row needs a CSS selector; ARIA may be "-" for icon-only buttons, CSS must never be "-".
|
|
406
|
-
- ARIA locator JSON uses keys "role" and "text" (NOT "name").
|
|
407
406
|
- Mark elements with likely hover interactions (title, aria-describedby, menu items with submenus) as "(hover)".
|
|
408
407
|
</rules>
|
|
409
408
|
|
package/src/ai/rules.ts
CHANGED
|
@@ -71,7 +71,6 @@ const locatorStrategyRule = dedent`
|
|
|
71
71
|
|
|
72
72
|
<bad_aria_locator_example>
|
|
73
73
|
{ "role": "button", "text": "" } // INVALID - empty text is useless, use "-" instead
|
|
74
|
-
{ "role": "button", "name": "Save" } // WRONG key - use "text", not "name"
|
|
75
74
|
</bad_aria_locator_example>
|
|
76
75
|
|
|
77
76
|
NEVER include \`eidx\` attribute in any locator (ARIA, CSS, XPath). It is an internal annotation.
|
package/src/ai/tester.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { Observability } from '../observability.ts';
|
|
|
11
11
|
import { type StateTransition, normalizeUrl } from '../state-manager.ts';
|
|
12
12
|
import { Stats } from '../stats.ts';
|
|
13
13
|
import { type Test, TestResult, type TestResultType } from '../test-plan.ts';
|
|
14
|
-
import { detectFocusArea } from '../utils/aria.ts';
|
|
15
14
|
import { ErrorPageError, isErrorPage } from '../utils/error-page.ts';
|
|
16
15
|
import { createDebug, tag } from '../utils/logger.ts';
|
|
17
16
|
import { loop } from '../utils/loop.ts';
|
|
@@ -66,6 +65,12 @@ export class Tester extends TaskAgent implements Agent {
|
|
|
66
65
|
private stalledIterations = 0;
|
|
67
66
|
private readonly MAX_STALLED_ITERATIONS = 3;
|
|
68
67
|
|
|
68
|
+
private skipResearch = (err: Error): string => {
|
|
69
|
+
if (err.name === 'AbortError') throw err;
|
|
70
|
+
tag('warning').log(`Research skipped: ${err.message}`);
|
|
71
|
+
return '';
|
|
72
|
+
};
|
|
73
|
+
|
|
69
74
|
constructor(deps: AgentDeps, researcher: Researcher, navigator: Navigator, agentTools?: any) {
|
|
70
75
|
super(deps);
|
|
71
76
|
this.requestStore = deps.requestStore;
|
|
@@ -531,7 +536,7 @@ export class Tester extends TaskAgent implements Agent {
|
|
|
531
536
|
|
|
532
537
|
let context = '';
|
|
533
538
|
|
|
534
|
-
const focusArea =
|
|
539
|
+
const focusArea = currentState.overlay;
|
|
535
540
|
|
|
536
541
|
const focusedElement = currentState.focusedElement;
|
|
537
542
|
if (focusedElement) {
|
|
@@ -582,12 +587,7 @@ export class Tester extends TaskAgent implements Agent {
|
|
|
582
587
|
const alreadySeenUiMap = this.seenUiMapUrls.has(currentUrl);
|
|
583
588
|
let research = '';
|
|
584
589
|
if (!alreadySeenUiMap) {
|
|
585
|
-
|
|
586
|
-
research = await this.researcher.research(currentState);
|
|
587
|
-
} catch (err) {
|
|
588
|
-
if (!(err instanceof ErrorPageError)) throw err;
|
|
589
|
-
tag('warning').log(`Research skipped: ${err.message}`);
|
|
590
|
-
}
|
|
590
|
+
research = await this.researcher.research(currentState).catch(this.skipResearch);
|
|
591
591
|
}
|
|
592
592
|
this.pageStateHash = currentStateHash;
|
|
593
593
|
this.pageActionResult = currentState;
|
|
@@ -628,7 +628,7 @@ export class Tester extends TaskAgent implements Agent {
|
|
|
628
628
|
}
|
|
629
629
|
|
|
630
630
|
if (focusArea.detected && focusArea.name && this.pageStateHash && this.pageActionResult) {
|
|
631
|
-
const overlaySection = await this.researcher.researchOverlay(currentState, this.pageActionResult, this.pageStateHash);
|
|
631
|
+
const overlaySection = await this.researcher.researchOverlay(currentState, this.pageActionResult, this.pageStateHash).catch(this.skipResearch);
|
|
632
632
|
if (overlaySection) {
|
|
633
633
|
context += dedent`
|
|
634
634
|
|
package/src/ai/tools.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { tool } from 'ai';
|
|
2
2
|
import dedent from 'dedent';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import type { ExecutedStep } from '../action.ts';
|
|
4
5
|
import { ActionResult, type PageDiff, type ToolResultMetadata } from '../action-result.ts';
|
|
5
6
|
import { type ExperienceTracker, renderExperienceRecipes } from '../experience-tracker.ts';
|
|
6
7
|
import { Stats } from '../stats.ts';
|
|
@@ -411,7 +412,7 @@ export function createCodeceptJSTools({ explorer, stateManager, ai }: ToolDeps,
|
|
|
411
412
|
const message = errorText(action.lastError);
|
|
412
413
|
await commitNote(activeNote, TestResult.FAILED, toolResult, action);
|
|
413
414
|
|
|
414
|
-
let formSuggestion = '
|
|
415
|
+
let formSuggestion = 'Commands after the failing one never ran. Retry only those, using click() or form().';
|
|
415
416
|
if (message.toLowerCase().includes(MULTIPLE_ELEMENTS_PATTERN)) {
|
|
416
417
|
const disambiguated = await disambiguateElements(action.lastError, explanation, ai);
|
|
417
418
|
if (disambiguated) {
|
|
@@ -421,10 +422,11 @@ export function createCodeceptJSTools({ explorer, stateManager, ai }: ToolDeps,
|
|
|
421
422
|
|
|
422
423
|
return failedToolResult(
|
|
423
424
|
'form',
|
|
424
|
-
`Form execution FAILED! ${message}`,
|
|
425
|
+
`Form execution FAILED! ${message}\n${formatExecutedSteps(action.executedSteps, codeLines.length)}`,
|
|
425
426
|
{
|
|
426
427
|
...toolResult,
|
|
427
428
|
code: codeBlock,
|
|
429
|
+
attempts: action.executedSteps,
|
|
428
430
|
suggestion: formSuggestion,
|
|
429
431
|
},
|
|
430
432
|
action.lastError
|
|
@@ -446,6 +448,7 @@ export function createCodeceptJSTools({ explorer, stateManager, ai }: ToolDeps,
|
|
|
446
448
|
...toolResult,
|
|
447
449
|
message: `Form completed successfully with ${lines.length} commands.`,
|
|
448
450
|
commandsExecuted: lines.length,
|
|
451
|
+
attempts: action.executedSteps,
|
|
449
452
|
code: codeBlock,
|
|
450
453
|
suggestion: 'Verify the form was filled in correctly using see() tool. If needed to submit: try click() tool or form() with I.pressKey("Enter").',
|
|
451
454
|
},
|
|
@@ -806,21 +809,26 @@ export function createAgentTools({ explorer, stateManager, ai, researcher, navig
|
|
|
806
809
|
const actionResult = ActionResult.fromState(currentState);
|
|
807
810
|
const experience = renderExperienceRecipes(explorer.activeTest?.getAppliedExperience(actionResult) ?? []);
|
|
808
811
|
const success = await navigator.resolveState(instruction, actionResult, { experience });
|
|
812
|
+
const attempts = navigator.executedSteps;
|
|
813
|
+
let stepReport = '';
|
|
814
|
+
if (attempts.length) stepReport = `\n${formatExecutedSteps(attempts)}`;
|
|
809
815
|
|
|
810
816
|
const toolResult = await ActionResult.fromState(stateManager.getCurrentState()!).toToolResult(previousState, instruction);
|
|
811
817
|
|
|
812
818
|
if (success) {
|
|
813
819
|
return successToolResult('interact', {
|
|
814
820
|
...toolResult,
|
|
815
|
-
message: `Successfully executed: ${instruction}`,
|
|
821
|
+
message: `Successfully executed: ${instruction}${stepReport}`,
|
|
822
|
+
attempts,
|
|
816
823
|
});
|
|
817
824
|
}
|
|
818
825
|
|
|
819
826
|
let reason = '';
|
|
820
827
|
if (navigator.lastFailureReason) reason = `: ${navigator.lastFailureReason}`;
|
|
821
828
|
|
|
822
|
-
return failedToolResult('interact', `Failed to execute: ${instruction}${reason}`, {
|
|
829
|
+
return failedToolResult('interact', `Failed to execute: ${instruction}${reason}${stepReport}`, {
|
|
823
830
|
...toolResult,
|
|
831
|
+
attempts,
|
|
824
832
|
suggestion: 'The action could not be completed. Try a different instruction or use more specific element descriptions.',
|
|
825
833
|
});
|
|
826
834
|
} catch (error) {
|
|
@@ -1232,6 +1240,14 @@ export function hasFailedRequest(pageDiff: PageDiff): boolean {
|
|
|
1232
1240
|
return (pageDiff.requests ?? []).some((request) => request.status >= 400);
|
|
1233
1241
|
}
|
|
1234
1242
|
|
|
1243
|
+
export function formatExecutedSteps(steps: ExecutedStep[], requestedCount = steps.length): string {
|
|
1244
|
+
if (!steps.length) return `No command ran of ${requestedCount} requested.`;
|
|
1245
|
+
const lines = steps.map((step) => ` ${step.success ? 'OK' : 'FAILED'} ${step.command}`);
|
|
1246
|
+
const notRun = requestedCount - steps.length;
|
|
1247
|
+
if (notRun > 0) lines.push(` NOT RUN ${notRun} more`);
|
|
1248
|
+
return lines.join('\n');
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1235
1251
|
function hasObservablePageChange(data?: Record<string, any>): boolean {
|
|
1236
1252
|
if (!data?.pageDiff) return false;
|
|
1237
1253
|
if (data.pageDiff.urlChanged === true) return true;
|
|
@@ -11,7 +11,7 @@ export class ExitCommand extends BaseCommand {
|
|
|
11
11
|
|
|
12
12
|
async execute(_args: string): Promise<void> {
|
|
13
13
|
await this.explorBot.printSessionAnalysis();
|
|
14
|
-
await this.explorBot.
|
|
14
|
+
await this.explorBot.stop();
|
|
15
15
|
|
|
16
16
|
if (Stats.hasActivity()) {
|
|
17
17
|
await new Promise<void>((resolve) => {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, extname, join, resolve } from 'node:path';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
-
import dedent from 'dedent';
|
|
5
4
|
import { ConfigParser, PROVIDERS } from '../config.ts';
|
|
6
5
|
import { findGlobalConfig, globalConfigPath, globalDir, globalEnvPath } from '../global-config.ts';
|
|
7
6
|
import { getCliName } from '../utils/cli-name.ts';
|
|
8
7
|
import { log, tag } from '../utils/logger.js';
|
|
9
8
|
import { relativeToCwd } from '../utils/next-steps.ts';
|
|
10
9
|
|
|
11
|
-
function defaultConfigTemplate(): string {
|
|
10
|
+
function defaultConfigTemplate(provider: string, esm: boolean): string {
|
|
11
|
+
let moduleExport = 'module.exports = config;';
|
|
12
|
+
if (esm) moduleExport = 'export default config;';
|
|
13
|
+
|
|
12
14
|
return `// 'provider/model-id' uses a bundled provider.
|
|
13
|
-
// It is also possible to import provider as a module from Vercel AI SDK.
|
|
15
|
+
// It is also possible to import provider as a module from Vercel AI SDK.
|
|
14
16
|
// https://github.com/testomatio/explorbot/blob/main/docs/basics/providers.md
|
|
15
17
|
|
|
16
18
|
const config = {
|
|
@@ -20,7 +22,7 @@ const config = {
|
|
|
20
22
|
},
|
|
21
23
|
|
|
22
24
|
ai: {
|
|
23
|
-
${modelLines(
|
|
25
|
+
${modelLines(provider)}
|
|
24
26
|
},
|
|
25
27
|
|
|
26
28
|
reporter: {
|
|
@@ -33,17 +35,18 @@ ${modelLines('openrouter')}
|
|
|
33
35
|
},
|
|
34
36
|
};
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
${moduleExport}
|
|
37
39
|
`;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
function envTemplate(provider: string): string {
|
|
43
|
+
const keyLines = Object.entries(PROVIDERS).map(([name, { envKey }]) => {
|
|
44
|
+
if (name === provider) return `${envKey}=`;
|
|
45
|
+
return `# ${envKey}=`;
|
|
46
|
+
});
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
# GROQ_API_KEY=
|
|
48
|
+
return `# AI provider API keys
|
|
49
|
+
${keyLines.join('\n')}
|
|
47
50
|
|
|
48
51
|
# Langfuse Tracing
|
|
49
52
|
LANGFUSE_SECRET_KEY=
|
|
@@ -51,11 +54,12 @@ LANGFUSE_PUBLIC_KEY=
|
|
|
51
54
|
LANGFUSE_BASE_URL=
|
|
52
55
|
|
|
53
56
|
# Testomat.io API key to publish run results
|
|
54
|
-
TESTOMATIO
|
|
55
|
-
|
|
57
|
+
TESTOMATIO=`;
|
|
58
|
+
}
|
|
56
59
|
|
|
57
60
|
export async function runInit(options: InitCommandOptions): Promise<void> {
|
|
58
|
-
|
|
61
|
+
const localRequested = !!(options.configPath || options.path);
|
|
62
|
+
if (options.global || (options.provider && !localRequested)) {
|
|
59
63
|
await runGlobalInit(options);
|
|
60
64
|
return;
|
|
61
65
|
}
|
|
@@ -66,7 +70,12 @@ export async function runInit(options: InitCommandOptions): Promise<void> {
|
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
const choice = await renderInitWizard('choose');
|
|
69
|
-
if (choice
|
|
73
|
+
if (choice !== 'local') return;
|
|
74
|
+
|
|
75
|
+
const provider = await renderLocalProviderWizard();
|
|
76
|
+
if (!provider) return;
|
|
77
|
+
|
|
78
|
+
runInitCommand({ ...options, provider });
|
|
70
79
|
}
|
|
71
80
|
|
|
72
81
|
export function writeGlobalConfig(provider: string, apiKey?: string): void {
|
|
@@ -97,7 +106,7 @@ export function writeGlobalConfig(provider: string, apiKey?: string): void {
|
|
|
97
106
|
}
|
|
98
107
|
|
|
99
108
|
export function runInitCommand(options: InitCommandOptions): void {
|
|
100
|
-
const
|
|
109
|
+
const provider = options.provider || 'openrouter';
|
|
101
110
|
const force = options.force ?? false;
|
|
102
111
|
const customPath = options.path;
|
|
103
112
|
const originalCwd = process.cwd();
|
|
@@ -112,12 +121,15 @@ export function runInitCommand(options: InitCommandOptions): void {
|
|
|
112
121
|
log(`Working in directory: ${relativeToCwd(dir)}`);
|
|
113
122
|
}
|
|
114
123
|
|
|
124
|
+
const configName = 'explorbot.config.js';
|
|
125
|
+
const configPath = options.configPath ?? `./${configName}`;
|
|
126
|
+
|
|
115
127
|
try {
|
|
116
128
|
let outPath = resolve(configPath);
|
|
117
129
|
if (existsSync(outPath) && statSync(outPath).isDirectory()) {
|
|
118
|
-
outPath = join(outPath,
|
|
130
|
+
outPath = join(outPath, configName);
|
|
119
131
|
} else if (!extname(outPath)) {
|
|
120
|
-
outPath = join(outPath,
|
|
132
|
+
outPath = join(outPath, configName);
|
|
121
133
|
}
|
|
122
134
|
|
|
123
135
|
const dir = dirname(outPath);
|
|
@@ -132,24 +144,30 @@ export function runInitCommand(options: InitCommandOptions): void {
|
|
|
132
144
|
process.exit(1);
|
|
133
145
|
}
|
|
134
146
|
|
|
135
|
-
|
|
147
|
+
const esm = extname(outPath) !== '.js' || isModuleProject(dirname(outPath));
|
|
148
|
+
writeFileSync(outPath, defaultConfigTemplate(provider, esm), 'utf8');
|
|
136
149
|
log(`Created config file: ${relativeToCwd(outPath)}`);
|
|
137
150
|
|
|
138
151
|
const envPath = resolve(process.cwd(), '.env');
|
|
139
152
|
if (!existsSync(envPath)) {
|
|
140
|
-
writeFileSync(envPath, `${
|
|
153
|
+
writeFileSync(envPath, `${envTemplate(provider)}\n`, 'utf8');
|
|
141
154
|
log(`Created env file: ${relativeToCwd(envPath)}`);
|
|
142
155
|
} else {
|
|
143
156
|
log(`Env file already exists: ${relativeToCwd(envPath)}`);
|
|
144
157
|
}
|
|
145
158
|
|
|
159
|
+
const missing = missingRoles(provider);
|
|
160
|
+
if (missing.length) {
|
|
161
|
+
tag('warning').log(`No recommended ${missing.join(' and ')} for ${provider} — set the model ids in ${relativeToCwd(outPath)}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
146
164
|
log('');
|
|
147
165
|
log('Next steps:');
|
|
148
166
|
log('1. Configure AI provider in .env');
|
|
149
167
|
log('2. Set AI models config file');
|
|
150
168
|
log('3. Set web application URL in the config file');
|
|
151
169
|
log('4. Add initial knowledge (how to authorize to the application, etc.)');
|
|
152
|
-
tag('substep').log(chalk.yellow(`${getCliName()} learn * 'to
|
|
170
|
+
tag('substep').log(chalk.yellow(`${getCliName()} learn * 'to authorize use these credentials: admin@example.com / secret123'`));
|
|
153
171
|
tag('substep').log('You can use ${env.LOGIN} and ${env.PASSWORD} to reference environment variables.');
|
|
154
172
|
|
|
155
173
|
log('5. Launch application on a relative URL');
|
|
@@ -213,6 +231,28 @@ async function renderInitWizard(mode: 'choose' | 'global'): Promise<'local' | 'g
|
|
|
213
231
|
});
|
|
214
232
|
}
|
|
215
233
|
|
|
234
|
+
async function renderLocalProviderWizard(): Promise<string | null> {
|
|
235
|
+
const [{ render }, React, InitWizard] = await Promise.all([import('ink'), import('react'), import('../components/InitWizard.js').then((m) => m.default)]);
|
|
236
|
+
|
|
237
|
+
return new Promise((resolve) => {
|
|
238
|
+
const finish = (provider: string | null) => {
|
|
239
|
+
unmount();
|
|
240
|
+
resolve(provider);
|
|
241
|
+
};
|
|
242
|
+
const { unmount } = render(
|
|
243
|
+
React.createElement(InitWizard, {
|
|
244
|
+
mode: 'local',
|
|
245
|
+
globalConfigExists: !!findGlobalConfig(),
|
|
246
|
+
onLocal: () => finish(null),
|
|
247
|
+
onComplete: () => finish(null),
|
|
248
|
+
onCancel: () => finish(null),
|
|
249
|
+
onLocalProvider: (provider: string) => finish(provider),
|
|
250
|
+
}),
|
|
251
|
+
{ exitOnCtrlC: false, patchConsole: false }
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
216
256
|
function modelLines(provider: string): string {
|
|
217
257
|
const recommended = ConfigParser.recommendedModels()[provider] || {};
|
|
218
258
|
const roles: Array<[ModelRoleName, string]> = [
|
|
@@ -245,10 +285,29 @@ ${modelLines(provider)}
|
|
|
245
285
|
},
|
|
246
286
|
};
|
|
247
287
|
|
|
248
|
-
|
|
288
|
+
module.exports = config;
|
|
249
289
|
`;
|
|
250
290
|
}
|
|
251
291
|
|
|
292
|
+
function isModuleProject(configDir: string): boolean {
|
|
293
|
+
let currentDir = resolve(configDir);
|
|
294
|
+
|
|
295
|
+
while (true) {
|
|
296
|
+
const packagePath = join(currentDir, 'package.json');
|
|
297
|
+
if (existsSync(packagePath)) {
|
|
298
|
+
try {
|
|
299
|
+
return JSON.parse(readFileSync(packagePath, 'utf8')).type === 'module';
|
|
300
|
+
} catch {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const parentDir = dirname(currentDir);
|
|
306
|
+
if (parentDir === currentDir) return false;
|
|
307
|
+
currentDir = parentDir;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
252
311
|
function missingRoles(provider: string): string[] {
|
|
253
312
|
const recommended = ConfigParser.recommendedModels()[provider] || {};
|
|
254
313
|
return ['model', 'visionModel', 'agenticModel'].filter((role) => !recommended[role]);
|
|
@@ -10,14 +10,15 @@ import InputReadline from './InputReadline.js';
|
|
|
10
10
|
const PROVIDER_NAMES = Object.keys(PROVIDERS);
|
|
11
11
|
|
|
12
12
|
interface InitWizardProps {
|
|
13
|
-
mode: 'choose' | 'global';
|
|
13
|
+
mode: 'choose' | 'global' | 'local';
|
|
14
14
|
globalConfigExists: boolean;
|
|
15
15
|
onLocal: () => void;
|
|
16
16
|
onComplete: () => void;
|
|
17
17
|
onCancel: () => void;
|
|
18
|
+
onLocalProvider?: (provider: string) => void;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
const InitWizard: React.FC<InitWizardProps> = ({ mode, globalConfigExists, onLocal, onComplete, onCancel }) => {
|
|
21
|
+
const InitWizard: React.FC<InitWizardProps> = ({ mode, globalConfigExists, onLocal, onComplete, onCancel, onLocalProvider }) => {
|
|
21
22
|
const [step, setStep] = useState<'target' | 'provider' | 'key' | 'validate'>(mode === 'choose' ? 'target' : 'provider');
|
|
22
23
|
const [targetIndex, setTargetIndex] = useState(0);
|
|
23
24
|
const [providerIndex, setProviderIndex] = useState(0);
|
|
@@ -78,7 +79,10 @@ const InitWizard: React.FC<InitWizardProps> = ({ mode, globalConfigExists, onLoc
|
|
|
78
79
|
if (step === 'provider') {
|
|
79
80
|
if (key.upArrow) setProviderIndex((index) => Math.max(0, index - 1));
|
|
80
81
|
if (key.downArrow) setProviderIndex((index) => Math.min(PROVIDER_NAMES.length - 1, index + 1));
|
|
81
|
-
if (key.return)
|
|
82
|
+
if (key.return) {
|
|
83
|
+
if (mode === 'local') onLocalProvider?.(provider);
|
|
84
|
+
else setStep('key');
|
|
85
|
+
}
|
|
82
86
|
return;
|
|
83
87
|
}
|
|
84
88
|
|
|
@@ -151,7 +155,7 @@ const InitWizard: React.FC<InitWizardProps> = ({ mode, globalConfigExists, onLoc
|
|
|
151
155
|
|
|
152
156
|
<Box marginTop={1}>
|
|
153
157
|
<Text dimColor>
|
|
154
|
-
Config goes to {globalDir()} | {step === 'key' ? 'Enter: continue' : '↑↓: select | Enter: confirm'} | Ctrl+C: exit
|
|
158
|
+
Config goes to {mode === 'local' ? 'the current directory' : globalDir()} | {step === 'key' ? 'Enter: continue' : '↑↓: select | Enter: confirm'} | Ctrl+C: exit
|
|
155
159
|
</Text>
|
|
156
160
|
</Box>
|
|
157
161
|
</Box>
|
package/src/explorbot.ts
CHANGED
package/src/explorer.ts
CHANGED
|
@@ -255,6 +255,7 @@ class Explorer {
|
|
|
255
255
|
const projectRoot = configParser.getProjectRoot();
|
|
256
256
|
(global as any).output_dir = configParser.getStatesDir();
|
|
257
257
|
(global as any).codecept_dir = projectRoot;
|
|
258
|
+
(global as any).codeceptjs = codeceptjs;
|
|
258
259
|
|
|
259
260
|
configParser.validateConfig(this.config);
|
|
260
261
|
|
package/src/knowledge-tracker.ts
CHANGED
|
@@ -95,7 +95,7 @@ export class KnowledgeTracker {
|
|
|
95
95
|
return this.applicationSpec?.renderFor(state) || '';
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
addKnowledge(urlPattern: string, description: string): { filename: string; filePath: string; isNewFile: boolean } {
|
|
98
|
+
addKnowledge(urlPattern: string, description: string, opts?: { replace?: boolean }): { filename: string; filePath: string; isNewFile: boolean } {
|
|
99
99
|
const configParser = ConfigParser.getInstance();
|
|
100
100
|
const configPath = configParser.getConfigPath();
|
|
101
101
|
|
|
@@ -130,10 +130,10 @@ export class KnowledgeTracker {
|
|
|
130
130
|
|
|
131
131
|
// Append new knowledge with separator
|
|
132
132
|
let newContent;
|
|
133
|
-
if (existingDescription) {
|
|
134
|
-
newContent = `${existingDescription}\n\n---\n\n${description}`;
|
|
135
|
-
} else {
|
|
133
|
+
if (opts?.replace || !existingDescription) {
|
|
136
134
|
newContent = description;
|
|
135
|
+
} else {
|
|
136
|
+
newContent = `${existingDescription}\n\n---\n\n${description}`;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
const fileContent = matter.stringify(newContent, frontmatter);
|
package/src/state-manager.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ActionResult, type FocusedElement } from './action-result.js';
|
|
2
2
|
import type { ExperienceTracker } from './experience-tracker.js';
|
|
3
3
|
import type { Knowledge, KnowledgeTracker } from './knowledge-tracker.js';
|
|
4
|
-
import { detectFocusArea } from './utils/aria.js';
|
|
5
4
|
import { createDebug, tag } from './utils/logger.js';
|
|
5
|
+
import { Overlay } from './utils/overlay.js';
|
|
6
6
|
import { slugify } from './utils/strings.js';
|
|
7
7
|
import { extractStatePath } from './utils/url-matcher.js';
|
|
8
8
|
|
|
@@ -49,6 +49,7 @@ export interface WebPageState {
|
|
|
49
49
|
focusedElement?: FocusedElement | null;
|
|
50
50
|
links?: Link[];
|
|
51
51
|
verifications?: Record<string, boolean>;
|
|
52
|
+
overlay?: Overlay;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export interface StateTransition {
|
|
@@ -206,8 +207,8 @@ export class StateManager {
|
|
|
206
207
|
}
|
|
207
208
|
|
|
208
209
|
private hasDialogAppeared(previousState: WebPageState | null, newState: WebPageState): boolean {
|
|
209
|
-
const prevFocus =
|
|
210
|
-
const newFocus =
|
|
210
|
+
const prevFocus = previousState?.overlay ?? Overlay.fromAria(previousState?.ariaSnapshot ?? null);
|
|
211
|
+
const newFocus = newState.overlay ?? Overlay.fromAria(newState.ariaSnapshot ?? null);
|
|
211
212
|
return !prevFocus.detected && newFocus.detected;
|
|
212
213
|
}
|
|
213
214
|
|
package/src/utils/aria.ts
CHANGED
|
@@ -586,7 +586,7 @@ export function parseAriaLocator(ariaStr: string): { role: string; text: string
|
|
|
586
586
|
const trimmed = ariaStr.trim();
|
|
587
587
|
if (trimmed === '-' || trimmed === '' || trimmed === '"-"') return null;
|
|
588
588
|
|
|
589
|
-
const match = trimmed.match(/\{\s*["']?role["']?\s*:\s*['"]([^'"]+)['"]\s*,\s*["']?text["']?\s*:\s*['"]([^'"]*)['"]\s*\}/);
|
|
589
|
+
const match = trimmed.match(/\{\s*["']?role["']?\s*:\s*['"]([^'"]+)['"]\s*,\s*["']?(?:text|name)["']?\s*:\s*['"]([^'"]*)['"]\s*\}/);
|
|
590
590
|
if (!match) return null;
|
|
591
591
|
|
|
592
592
|
return { role: match[1], text: match[2] };
|
package/src/utils/html.ts
CHANGED
|
@@ -98,7 +98,6 @@ export const HTML_SELECTORS = {
|
|
|
98
98
|
interactiveControl: 'button, a[href], input, select, textarea, [role="button"], [role="link"], [role="checkbox"], [role="radio"], [role="switch"], [role="tab"], [role="menuitem"]',
|
|
99
99
|
labelLike: 'h1, h2, h3, h4, h5, h6, legend, caption, label, [role="heading"], [class*="title"], [class*="label"], [class*="header"], [class*="name"]',
|
|
100
100
|
semanticContextContainer: 'section, article, form, fieldset, li, tr, td, th, [role="group"], [role="tabpanel"], [role="region"], [class*="card"], [class*="panel"], [class*="item"], [class*="usage"], [class*="group"]',
|
|
101
|
-
semanticOverlays: ['[role="dialog"]', '[role="listbox"]', '[role="menu"]', '[role="tooltip"]:not([style*="display: none"]):not([style*="visibility: hidden"])'],
|
|
102
101
|
} as const;
|
|
103
102
|
|
|
104
103
|
export const HTML_VISIBILITY_LIMITS = {
|
|
@@ -163,7 +162,9 @@ export type VisibleOverlayExtractionConfig = {
|
|
|
163
162
|
interactiveContentSelector: string;
|
|
164
163
|
limits: typeof HTML_EXTRACTION_LIMITS;
|
|
165
164
|
overlaySelectors: readonly string[];
|
|
165
|
+
overlaySemanticSelector: string;
|
|
166
166
|
visibilityLimits: typeof HTML_VISIBILITY_LIMITS;
|
|
167
|
+
geometryFallback?: boolean;
|
|
167
168
|
};
|
|
168
169
|
export type ComponentScopeExtractionConfig = {
|
|
169
170
|
eidxAttr: string;
|
|
@@ -479,20 +480,28 @@ export function extractVisibleOverlayHtml(config: VisibleOverlayExtractionConfig
|
|
|
479
480
|
return interactiveCount > 0 || text.length > 0;
|
|
480
481
|
}
|
|
481
482
|
|
|
482
|
-
|
|
483
|
+
function isFloatingOverlay(element: Element): boolean {
|
|
484
|
+
const style = window.getComputedStyle(element as HTMLElement);
|
|
485
|
+
return style.position === 'fixed' || style.position === 'absolute' || Number.parseInt(style.zIndex || '0', 10) > 0;
|
|
486
|
+
}
|
|
487
|
+
|
|
483
488
|
const seen = new Set<Element>();
|
|
489
|
+
const collected: Element[] = [];
|
|
484
490
|
for (const selector of config.overlaySelectors) {
|
|
485
491
|
for (const element of Array.from(document.querySelectorAll(selector))) {
|
|
486
492
|
if (seen.has(element)) continue;
|
|
487
493
|
seen.add(element);
|
|
488
494
|
if (!isVisible(element)) continue;
|
|
495
|
+
if (!element.matches(config.overlaySemanticSelector) && !isFloatingOverlay(element)) continue;
|
|
489
496
|
const { interactiveCount, text } = getUsefulContent(element);
|
|
490
497
|
if (interactiveCount === 0 && text.length === 0) continue;
|
|
491
|
-
|
|
498
|
+
collected.push(element);
|
|
492
499
|
}
|
|
493
500
|
}
|
|
494
501
|
|
|
495
|
-
|
|
502
|
+
const overlays = collected.filter((element) => !collected.some((other) => other !== element && element.contains(other))).map((element) => (element as HTMLElement).outerHTML.slice(0, config.limits.overlayHtmlLength));
|
|
503
|
+
|
|
504
|
+
if (overlays.length === 0 && config.geometryFallback !== false) {
|
|
496
505
|
const floatingCandidates = Array.from(document.body.querySelectorAll('*'))
|
|
497
506
|
.filter((element) => !seen.has(element) && isVisible(element) && isLikelyFloatingOverlay(element))
|
|
498
507
|
.sort((left, right) => {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { detectFocusArea } from './aria.js';
|
|
2
|
+
import { HTML_EXTRACTION_LIMITS, HTML_SELECTORS, HTML_VISIBILITY_LIMITS, type VisibleOverlayExtractionConfig, extractHeadings } from './html.js';
|
|
3
|
+
|
|
4
|
+
export const OVERLAY_SELECTORS = {
|
|
5
|
+
semanticOverlays: ['[role="dialog"]', '[role="listbox"]', '[role="menu"]', '[role="tooltip"]:not([style*="display: none"]):not([style*="visibility: hidden"])', '[class*="modal"]', '[class*="dialog"]', '[class*="overlay"]', '[class*="popup"]', '[class*="drawer"]', '[class*="lightbox"]'],
|
|
6
|
+
modalOverlays: ['[role="dialog"]', '[role="alertdialog"]', '[aria-modal="true"]', '[class*="modal"]', '[class*="dialog"]', '[class*="overlay"]', '[class*="popup"]', '[class*="drawer"]', '[class*="lightbox"]'],
|
|
7
|
+
overlaySemanticSelector: '[role="dialog"], [role="alertdialog"], [aria-modal="true"], [role="listbox"], [role="menu"], [role="tooltip"]',
|
|
8
|
+
} as const;
|
|
9
|
+
|
|
10
|
+
export type OverlayData = { type?: 'dialog' | 'modal' | null; name?: string | null };
|
|
11
|
+
|
|
12
|
+
export class Overlay {
|
|
13
|
+
readonly type: 'dialog' | 'modal' | null;
|
|
14
|
+
readonly name: string | null;
|
|
15
|
+
|
|
16
|
+
constructor(data: OverlayData = {}) {
|
|
17
|
+
this.type = data.type ?? null;
|
|
18
|
+
this.name = data.name ?? null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get detected(): boolean {
|
|
22
|
+
return this.type !== null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static fromHtml(html: string): Overlay {
|
|
26
|
+
const headings = extractHeadings(html);
|
|
27
|
+
const name = [headings.h1, headings.h2, headings.h3, headings.h4].filter(Boolean).join(' ');
|
|
28
|
+
return new Overlay({ type: 'modal', name: name || null });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static fromAria(snapshot: string | null): Overlay {
|
|
32
|
+
return new Overlay(detectFocusArea(snapshot));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static resolve(data: { overlayHtml?: string; overlay?: OverlayData | null; ariaSnapshot?: string | null }): Overlay {
|
|
36
|
+
if (data.overlayHtml) return Overlay.fromHtml(data.overlayHtml);
|
|
37
|
+
if (data.overlay) return new Overlay(data.overlay);
|
|
38
|
+
return Overlay.fromAria(data.ariaSnapshot ?? null);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static captureConfig(): VisibleOverlayExtractionConfig {
|
|
42
|
+
return {
|
|
43
|
+
interactiveContentSelector: HTML_SELECTORS.interactiveContent,
|
|
44
|
+
limits: HTML_EXTRACTION_LIMITS,
|
|
45
|
+
overlaySelectors: OVERLAY_SELECTORS.modalOverlays,
|
|
46
|
+
overlaySemanticSelector: OVERLAY_SELECTORS.overlaySemanticSelector,
|
|
47
|
+
visibilityLimits: HTML_VISIBILITY_LIMITS,
|
|
48
|
+
geometryFallback: false,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|