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.
Files changed (156) hide show
  1. package/README.md +1 -1
  2. package/bin/explorbot-cli.ts +7 -1
  3. package/boat/api-tester/src/config.ts +4 -2
  4. package/boat/doc-collector/bin/doc-collector-cli.ts +2 -0
  5. package/boat/doc-collector/src/ai/documentarian.ts +61 -31
  6. package/boat/doc-collector/src/config.ts +4 -2
  7. package/boat/prima/bin/prima-cli.ts +0 -0
  8. package/boat/prima/src/activity-line.ts +33 -0
  9. package/boat/prima/src/cli.ts +115 -86
  10. package/boat/prima/src/envelope.ts +80 -52
  11. package/boat/prima/src/prima.ts +547 -128
  12. package/boat/prima/src/pw-parser.ts +11 -1
  13. package/boat/prima/src/pw-registry.ts +4 -5
  14. package/boat/prima/src/session-log.ts +126 -0
  15. package/dist/bin/explorbot-cli.js +7 -1
  16. package/dist/boat/api-tester/bin/apibot-cli.js +2 -0
  17. package/dist/boat/api-tester/src/config.js +4 -2
  18. package/dist/boat/doc-collector/bin/doc-collector-cli.js +2 -0
  19. package/dist/boat/doc-collector/src/ai/documentarian.js +44 -19
  20. package/dist/boat/doc-collector/src/config.js +4 -2
  21. package/dist/boat/prima/src/activity-line.js +30 -0
  22. package/dist/boat/prima/src/cli.js +97 -77
  23. package/dist/boat/prima/src/envelope.js +70 -44
  24. package/dist/boat/prima/src/prima.js +515 -119
  25. package/dist/boat/prima/src/pw-parser.js +13 -1
  26. package/dist/boat/prima/src/pw-registry.js +4 -5
  27. package/dist/boat/prima/src/session-log.js +108 -0
  28. package/dist/package.json +3 -2
  29. package/dist/rules/navigator/verification-actions.md +20 -0
  30. package/dist/src/action-result.d.ts +7 -0
  31. package/dist/src/action-result.js +4 -0
  32. package/dist/src/action.d.ts +2 -0
  33. package/dist/src/action.js +36 -1
  34. package/dist/src/ai/captain/web-mode.js +6 -3
  35. package/dist/src/ai/captain.js +2 -0
  36. package/dist/src/ai/navigator.d.ts +7 -0
  37. package/dist/src/ai/navigator.js +10 -6
  38. package/dist/src/ai/pilot.d.ts +4 -0
  39. package/dist/src/ai/pilot.js +48 -2
  40. package/dist/src/ai/provider.js +2 -2
  41. package/dist/src/ai/rerunner.js +2 -1
  42. package/dist/src/ai/researcher.js +1 -1
  43. package/dist/src/ai/rules.js +17 -10
  44. package/dist/src/ai/task-agent.js +4 -1
  45. package/dist/src/ai/tester.d.ts +1 -1
  46. package/dist/src/ai/tester.js +33 -33
  47. package/dist/src/ai/tools.d.ts +14 -0
  48. package/dist/src/ai/tools.js +113 -36
  49. package/dist/src/config.d.ts +1 -0
  50. package/dist/src/config.js +13 -4
  51. package/dist/src/execution-controller.d.ts +2 -0
  52. package/dist/src/execution-controller.js +6 -0
  53. package/dist/src/explorbot.d.ts +2 -1
  54. package/dist/src/explorbot.js +3 -1
  55. package/dist/src/explorer.js +2 -3
  56. package/dist/src/playwright-recorder.js +30 -0
  57. package/dist/src/remote.d.ts +54 -0
  58. package/dist/src/remote.js +229 -0
  59. package/dist/src/reporter.d.ts +1 -0
  60. package/dist/src/reporter.js +7 -1
  61. package/dist/src/state-manager.d.ts +2 -1
  62. package/dist/src/stats.d.ts +1 -0
  63. package/dist/src/stats.js +1 -0
  64. package/dist/src/test-plan.d.ts +2 -0
  65. package/dist/src/test-plan.js +7 -0
  66. package/dist/src/utils/aria.d.ts +2 -8
  67. package/dist/src/utils/aria.js +69 -40
  68. package/dist/src/utils/html.js +1 -0
  69. package/dist/src/utils/logger.d.ts +6 -0
  70. package/dist/src/utils/logger.js +24 -0
  71. package/dist/src/utils/page-readiness.js +18 -1
  72. package/dist/src/utils/url-matcher.js +3 -0
  73. package/dist/src/utils/web-element.d.ts +2 -0
  74. package/dist/src/utils/web-element.js +8 -0
  75. package/dist/src/utils/web-sandbox.d.ts +1 -1
  76. package/dist/src/utils/web-sandbox.js +2 -3
  77. package/docs/api-testing/basics.md +90 -0
  78. package/docs/api-testing/planning.md +57 -0
  79. package/docs/api-testing/running-tests.md +55 -0
  80. package/docs/assets/cloud-report.png +0 -0
  81. package/docs/assets/html-report.png +0 -0
  82. package/docs/assets/langfuse-trace.png +0 -0
  83. package/docs/assets/successful-explore-run.png +0 -0
  84. package/docs/basics/getting-started.md +140 -0
  85. package/docs/basics/prerequisites.md +63 -0
  86. package/docs/basics/providers.md +362 -0
  87. package/docs/basics/running.md +78 -0
  88. package/docs/contributing/ai-integration-tests.md +57 -0
  89. package/docs/contributing/contributing.md +90 -0
  90. package/docs/contributing/demo-videos.md +36 -0
  91. package/docs/contributing/npm-package.md +138 -0
  92. package/docs/contributing/observability.md +227 -0
  93. package/docs/contributing/regression-tests.md +103 -0
  94. package/docs/contributing/testing.md +95 -0
  95. package/docs/doc-collection/basics.md +128 -0
  96. package/docs/doc-collection/crawling.md +67 -0
  97. package/docs/doc-collection/interactive-mode.md +99 -0
  98. package/docs/index.json +86 -0
  99. package/docs/reference/commands.md +994 -0
  100. package/docs/reference/configuration.md +569 -0
  101. package/docs/reference/scripting.md +303 -0
  102. package/docs/superpowers/plans/2026-08-01-actor-boat.md +925 -0
  103. package/docs/superpowers/plans/2026-08-01-prima-boat.md +1120 -0
  104. package/docs/superpowers/reviews/2026-08-06-prima-vs-playwright-cli.md +268 -0
  105. package/docs/superpowers/specs/2026-08-01-actor-boat-design.md +204 -0
  106. package/docs/superpowers/specs/2026-08-01-prima-boat-design.md +242 -0
  107. package/docs/superpowers/specs/2026-08-03-global-config-design.md +138 -0
  108. package/docs/superpowers/specs/2026-08-07-prima-fixes-design.md +394 -0
  109. package/docs/web-testing/agents.md +158 -0
  110. package/docs/web-testing/automated-tests.md +134 -0
  111. package/docs/web-testing/basics.md +91 -0
  112. package/docs/web-testing/customization.md +131 -0
  113. package/docs/web-testing/hooks.md +238 -0
  114. package/docs/web-testing/page-interaction.md +84 -0
  115. package/docs/web-testing/planner.md +122 -0
  116. package/docs/web-testing/rerun.md +164 -0
  117. package/docs/web-testing/researcher.md +380 -0
  118. package/docs/workflow/agentic-usage.md +233 -0
  119. package/docs/workflow/application-spec.md +73 -0
  120. package/docs/workflow/ci.md +202 -0
  121. package/docs/workflow/knowledge.md +310 -0
  122. package/docs/workflow/planning-styles.md +67 -0
  123. package/docs/workflow/reporting.md +133 -0
  124. package/docs/workflow/test-plans.md +90 -0
  125. package/package.json +3 -2
  126. package/rules/navigator/verification-actions.md +20 -0
  127. package/src/action-result.ts +11 -0
  128. package/src/action.ts +38 -2
  129. package/src/ai/captain/web-mode.ts +6 -3
  130. package/src/ai/captain.ts +3 -0
  131. package/src/ai/navigator.ts +14 -8
  132. package/src/ai/pilot.ts +53 -2
  133. package/src/ai/provider.ts +2 -4
  134. package/src/ai/rerunner.ts +2 -1
  135. package/src/ai/researcher.ts +1 -1
  136. package/src/ai/rules.ts +17 -10
  137. package/src/ai/task-agent.ts +3 -1
  138. package/src/ai/tester.ts +32 -33
  139. package/src/ai/tools.ts +132 -36
  140. package/src/config.ts +15 -4
  141. package/src/execution-controller.ts +8 -0
  142. package/src/explorbot.ts +4 -2
  143. package/src/explorer.ts +2 -2
  144. package/src/playwright-recorder.ts +23 -0
  145. package/src/remote.ts +238 -0
  146. package/src/reporter.ts +7 -1
  147. package/src/state-manager.ts +2 -1
  148. package/src/stats.ts +1 -0
  149. package/src/test-plan.ts +9 -0
  150. package/src/utils/aria.ts +65 -45
  151. package/src/utils/html.ts +1 -0
  152. package/src/utils/logger.ts +24 -1
  153. package/src/utils/page-readiness.ts +24 -1
  154. package/src/utils/url-matcher.ts +3 -0
  155. package/src/utils/web-element.ts +9 -0
  156. 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, extractFocusedElement } from '../utils/aria.ts';
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) - PREFERRED when container is known - e.g. I.click("Save", ".modal")
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
- let suggestion = "Try xpathCheck() to find the element's actual position, see() for visual analysis, or visualClick() to click by visual appearance.";
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
- const currentAriaState = stateManager.getCurrentState()?.ariaSnapshot;
304
- const focused = extractFocusedElement(currentAriaState ?? null);
305
- if (!focused) {
306
- activeNote.commit(TestResult.FAILED);
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
- Check the page contents based on current page state and screenshot.
548
- This tool will trigger visual research to check the page contents on request.
549
- Use it to verify the actions were performed correctly and the page is in the expected state.
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: "Check current state of the Login form"
554
- result: "Login form is visible with username and password fields, username is filled with 'testuser' and password is empty'
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
- visionDisabled = true;
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
- visionDisabled = true;
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 successToolResult(action: string, data?: Record<string, any>, source?: { playwrightGroupId?: string | null; assertionSteps?: any[] }) {
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) return target || '/';
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(configPath);
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(configPath);
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?.addNote(`Console error: ${err.message}`, TestResult.FAILED);
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?.addNote(`Console error: ${msg.text()}`, TestResult.FAILED);
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
  }