explorbot 0.0.1 → 0.1.0
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 +80 -26
- package/bin/explorbot-cli.ts +680 -0
- package/boat/api-tester/src/ai/chief/styles.ts +15 -0
- package/boat/api-tester/src/ai/chief.ts +335 -0
- package/boat/api-tester/src/ai/curler-tools.ts +278 -0
- package/boat/api-tester/src/ai/curler.ts +306 -0
- package/boat/api-tester/src/api-client.ts +28 -0
- package/boat/api-tester/src/apibot.ts +203 -0
- package/boat/api-tester/src/cli.ts +301 -0
- package/boat/api-tester/src/config.ts +190 -0
- package/dist/bin/explorbot-cli.js +23 -101
- package/dist/boat/api-tester/bin/apibot-cli.js +0 -1
- package/dist/boat/api-tester/src/ai/chief/styles.js +0 -1
- package/dist/boat/api-tester/src/ai/chief.js +0 -1
- package/dist/boat/api-tester/src/ai/curler-tools.js +0 -1
- package/dist/boat/api-tester/src/ai/curler.js +0 -1
- package/dist/boat/api-tester/src/api-client.js +0 -1
- package/dist/boat/api-tester/src/apibot.js +0 -1
- package/dist/boat/api-tester/src/cli.js +0 -1
- package/dist/boat/api-tester/src/config.js +0 -1
- package/dist/src/action-result.js +0 -1
- package/dist/src/action.js +14 -12
- package/dist/src/activity.js +0 -1
- package/dist/src/ai/agent.js +0 -1
- package/dist/src/ai/bosun.js +0 -1
- package/dist/src/ai/captain/idle-mode.js +0 -1
- package/dist/src/ai/captain/mixin.js +0 -1
- package/dist/src/ai/captain/test-mode.js +0 -1
- package/dist/src/ai/captain/web-mode.js +0 -1
- package/dist/src/ai/captain.js +0 -1
- package/dist/src/ai/conversation.js +0 -1
- package/dist/src/ai/experience-compactor.js +0 -1
- package/dist/src/ai/fisherman-tools.js +0 -1
- package/dist/src/ai/fisherman.js +0 -1
- package/dist/src/ai/historian.js +0 -1
- package/dist/src/ai/navigator.js +0 -1
- package/dist/src/ai/pilot.js +0 -1
- package/dist/src/ai/planner/session-dedup.js +0 -1
- package/dist/src/ai/planner/styles.js +0 -1
- package/dist/src/ai/planner/subpages.js +42 -7
- package/dist/src/ai/planner.js +15 -4
- package/dist/src/ai/provider.js +0 -1
- package/dist/src/ai/quartermaster.js +0 -1
- package/dist/src/ai/researcher/cache.js +13 -9
- package/dist/src/ai/researcher/coordinates.js +4 -3
- package/dist/src/ai/researcher/deep-analysis.js +16 -20
- package/dist/src/ai/researcher/fingerprint-worker.js +0 -1
- package/dist/src/ai/researcher/focus.js +0 -1
- package/dist/src/ai/researcher/locators.js +1 -2
- package/dist/src/ai/researcher/mixin.js +0 -1
- package/dist/src/ai/researcher/parser.js +4 -4
- package/dist/src/ai/researcher/research-result.js +2 -1
- package/dist/src/ai/researcher.js +6 -6
- package/dist/src/ai/rules.js +0 -1
- package/dist/src/ai/task-agent.js +0 -1
- package/dist/src/ai/tester.js +0 -1
- package/dist/src/ai/tools.js +4 -1
- package/dist/src/api/api-client.js +0 -1
- package/dist/src/api/request-result.js +0 -1
- package/dist/src/api/request-store.js +0 -1
- package/dist/src/api/spec-reader.js +0 -1
- package/dist/src/api/xhr-capture.js +0 -1
- package/dist/src/browser-server.js +0 -1
- package/dist/src/command-handler.js +0 -1
- package/dist/src/commands/add-rule-command.js +0 -1
- package/dist/src/commands/base-command.js +0 -1
- package/dist/src/commands/clean-command.js +0 -1
- package/dist/src/commands/context-aria-command.js +0 -1
- package/dist/src/commands/context-command.js +2 -3
- package/dist/src/commands/context-data-command.js +0 -1
- package/dist/src/commands/context-experience-command.js +0 -1
- package/dist/src/commands/context-html-command.js +0 -1
- package/dist/src/commands/context-knowledge-command.js +0 -1
- package/dist/src/commands/debug-command.js +0 -1
- package/dist/src/commands/drill-command.js +0 -1
- package/dist/src/commands/exit-command.js +0 -1
- package/dist/src/commands/explore-command.js +3 -3
- package/dist/src/commands/freesail-command.js +0 -1
- package/dist/src/commands/help-command.js +0 -1
- package/dist/src/commands/index.js +0 -1
- package/dist/src/commands/init-command.js +117 -0
- package/dist/src/commands/knows-command.js +0 -1
- package/dist/src/commands/learn-command.js +0 -1
- package/dist/src/commands/navigate-command.js +0 -1
- package/dist/src/commands/path-command.js +0 -1
- package/dist/src/commands/plan-clear-command.js +0 -1
- package/dist/src/commands/plan-command.js +6 -2
- package/dist/src/commands/plan-edit-command.js +0 -1
- package/dist/src/commands/plan-load-command.js +0 -1
- package/dist/src/commands/plan-reload-command.js +0 -1
- package/dist/src/commands/plan-save-command.js +0 -1
- package/dist/src/commands/research-command.js +0 -1
- package/dist/src/commands/start-command.js +0 -1
- package/dist/src/commands/status-command.js +0 -1
- package/dist/src/commands/test-command.js +0 -1
- package/dist/src/components/ActivityPane.js +0 -1
- package/dist/src/components/AddKnowledge.js +0 -1
- package/dist/src/components/AddRule.js +0 -1
- package/dist/src/components/App.js +0 -1
- package/dist/src/components/Autocomplete.js +0 -1
- package/dist/src/components/InputPane.js +0 -1
- package/dist/src/components/InputReadline.js +0 -1
- package/dist/src/components/LogPane.js +0 -1
- package/dist/src/components/PlanEditor.js +0 -1
- package/dist/src/components/PlanPane.js +0 -1
- package/dist/src/components/SessionTimer.js +0 -1
- package/dist/src/components/StateTransitionPane.js +0 -1
- package/dist/src/components/StatusPane.js +0 -1
- package/dist/src/components/TaskPane.js +0 -1
- package/dist/src/components/Welcome.js +0 -1
- package/dist/src/components/WelcomeChecklist.js +0 -1
- package/dist/src/components/WelcomeCommands.js +0 -1
- package/dist/src/components/autocomplete-store.js +0 -1
- package/dist/src/components/parse-keypress.js +0 -1
- package/dist/src/config.js +0 -1
- package/dist/src/execution-controller.js +0 -1
- package/dist/src/experience-tracker.js +0 -1
- package/dist/src/explorbot.js +1 -2
- package/dist/src/explorer.js +58 -17
- package/dist/src/index.js +0 -1
- package/dist/src/knowledge-tracker.js +2 -2
- package/dist/src/observability.js +0 -1
- package/dist/src/reporter.js +0 -1
- package/dist/src/state-manager.js +0 -1
- package/dist/src/stats.js +0 -1
- package/dist/src/test-plan.js +0 -1
- package/dist/src/utils/aria.js +0 -1
- package/dist/src/utils/cli-name.js +16 -0
- package/dist/src/utils/code-extractor.js +0 -1
- package/dist/src/utils/context-formatter.js +0 -1
- package/dist/src/utils/error-page.js +0 -1
- package/dist/src/utils/expandable.js +0 -1
- package/dist/src/utils/hooks-runner.js +0 -1
- package/dist/src/utils/html-diff.js +0 -1
- package/dist/src/utils/html.js +0 -1
- package/dist/src/utils/logger.js +0 -1
- package/dist/src/utils/loop.js +0 -1
- package/dist/src/utils/markdown-parser.js +0 -1
- package/dist/src/utils/markdown-query.js +0 -1
- package/dist/src/utils/markdown-terminal.js +0 -1
- package/dist/src/utils/research-parser.js +0 -1
- package/dist/src/utils/retry.js +0 -1
- package/dist/src/utils/rules-loader.js +0 -1
- package/dist/src/utils/strings.js +0 -1
- package/dist/src/utils/test-plan-markdown.js +0 -1
- package/dist/src/utils/throttle.js +0 -1
- package/dist/src/utils/unique-names.js +0 -1
- package/dist/src/utils/url-matcher.js +0 -1
- package/dist/src/utils/web-element.js +6 -5
- package/dist/src/utils/xpath.js +0 -1
- package/package.json +28 -4
- package/src/action-result.ts +694 -0
- package/src/action.ts +449 -0
- package/src/activity.ts +111 -0
- package/src/ai/agent.ts +3 -0
- package/src/ai/bosun.ts +557 -0
- package/src/ai/captain/idle-mode.ts +116 -0
- package/src/ai/captain/mixin.ts +22 -0
- package/src/ai/captain/test-mode.ts +262 -0
- package/src/ai/captain/web-mode.ts +136 -0
- package/src/ai/captain.ts +504 -0
- package/src/ai/conversation.ts +205 -0
- package/src/ai/experience-compactor.ts +284 -0
- package/src/ai/fisherman-tools.ts +181 -0
- package/src/ai/fisherman.ts +223 -0
- package/src/ai/historian.ts +457 -0
- package/src/ai/navigator.ts +572 -0
- package/src/ai/pilot.ts +776 -0
- package/src/ai/planner/session-dedup.ts +35 -0
- package/src/ai/planner/styles.ts +17 -0
- package/src/ai/planner/subpages.ts +171 -0
- package/src/ai/planner.ts +549 -0
- package/src/ai/provider.ts +613 -0
- package/src/ai/quartermaster.ts +286 -0
- package/src/ai/researcher/cache.ts +109 -0
- package/src/ai/researcher/coordinates.ts +239 -0
- package/src/ai/researcher/deep-analysis.ts +412 -0
- package/src/ai/researcher/fingerprint-worker.ts +59 -0
- package/src/ai/researcher/focus.ts +42 -0
- package/src/ai/researcher/locators.ts +282 -0
- package/src/ai/researcher/mixin.ts +4 -0
- package/src/ai/researcher/parser.ts +186 -0
- package/src/ai/researcher/research-result.ts +116 -0
- package/src/ai/researcher.ts +858 -0
- package/src/ai/rules.ts +376 -0
- package/src/ai/task-agent.ts +141 -0
- package/src/ai/tester.ts +939 -0
- package/src/ai/tools.ts +1122 -0
- package/src/api/api-client.ts +109 -0
- package/src/api/request-result.ts +212 -0
- package/src/api/request-store.ts +130 -0
- package/src/api/spec-reader.ts +174 -0
- package/src/api/xhr-capture.ts +100 -0
- package/src/browser-server.ts +74 -0
- package/src/command-handler.ts +454 -0
- package/src/commands/add-rule-command.ts +63 -0
- package/src/commands/base-command.ts +27 -0
- package/src/commands/clean-command.ts +73 -0
- package/src/commands/context-aria-command.ts +22 -0
- package/src/commands/context-command.ts +67 -0
- package/src/commands/context-data-command.ts +30 -0
- package/src/commands/context-experience-command.ts +48 -0
- package/src/commands/context-html-command.ts +33 -0
- package/src/commands/context-knowledge-command.ts +43 -0
- package/src/commands/debug-command.ts +13 -0
- package/src/commands/drill-command.ts +34 -0
- package/src/commands/exit-command.ts +32 -0
- package/src/commands/explore-command.ts +129 -0
- package/src/commands/freesail-command.ts +95 -0
- package/src/commands/help-command.ts +8 -0
- package/src/commands/index.ts +69 -0
- package/src/commands/init-command.ts +131 -0
- package/src/commands/knows-command.ts +68 -0
- package/src/commands/learn-command.ts +44 -0
- package/src/commands/navigate-command.ts +18 -0
- package/src/commands/path-command.ts +83 -0
- package/src/commands/plan-clear-command.ts +14 -0
- package/src/commands/plan-command.ts +46 -0
- package/src/commands/plan-edit-command.ts +9 -0
- package/src/commands/plan-load-command.ts +18 -0
- package/src/commands/plan-reload-command.ts +28 -0
- package/src/commands/plan-save-command.ts +25 -0
- package/src/commands/research-command.ts +45 -0
- package/src/commands/start-command.ts +13 -0
- package/src/commands/status-command.tsx +23 -0
- package/src/commands/test-command.ts +84 -0
- package/src/components/ActivityPane.tsx +80 -0
- package/src/components/AddKnowledge.tsx +169 -0
- package/src/components/AddRule.tsx +174 -0
- package/src/components/App.tsx +377 -0
- package/src/components/Autocomplete.tsx +63 -0
- package/src/components/InputPane.tsx +259 -0
- package/src/components/InputReadline.tsx +704 -0
- package/src/components/LogPane.tsx +187 -0
- package/src/components/PlanEditor.tsx +150 -0
- package/src/components/PlanPane.tsx +71 -0
- package/src/components/SessionTimer.tsx +35 -0
- package/src/components/StateTransitionPane.tsx +149 -0
- package/src/components/StatusPane.tsx +62 -0
- package/src/components/TaskPane.tsx +119 -0
- package/src/components/Welcome.tsx +83 -0
- package/src/components/WelcomeChecklist.tsx +118 -0
- package/src/components/WelcomeCommands.tsx +102 -0
- package/src/components/autocomplete-store.ts +35 -0
- package/src/components/parse-keypress.ts +170 -0
- package/src/config.ts +491 -0
- package/src/execution-controller.ts +109 -0
- package/src/experience-tracker.ts +350 -0
- package/src/explorbot.ts +405 -0
- package/src/explorer.ts +760 -0
- package/src/index.tsx +62 -0
- package/src/knowledge-tracker.ts +230 -0
- package/src/observability.ts +150 -0
- package/src/reporter.ts +224 -0
- package/src/state-manager.ts +556 -0
- package/src/stats.ts +53 -0
- package/src/test-plan.ts +432 -0
- package/src/utils/aria.ts +629 -0
- package/src/utils/cli-name.ts +13 -0
- package/src/utils/code-extractor.ts +22 -0
- package/src/utils/context-formatter.ts +239 -0
- package/src/utils/error-page.ts +23 -0
- package/src/utils/expandable.ts +38 -0
- package/src/utils/hooks-runner.ts +79 -0
- package/src/utils/html-diff.ts +918 -0
- package/src/utils/html.ts +1316 -0
- package/src/utils/logger.ts +534 -0
- package/src/utils/loop.ts +176 -0
- package/src/utils/markdown-parser.ts +127 -0
- package/src/utils/markdown-query.ts +466 -0
- package/src/utils/markdown-terminal.ts +43 -0
- package/src/utils/research-parser.ts +11 -0
- package/src/utils/retry.ts +73 -0
- package/src/utils/rules-loader.ts +118 -0
- package/src/utils/strings.ts +13 -0
- package/src/utils/test-plan-markdown.ts +332 -0
- package/src/utils/throttle.ts +18 -0
- package/src/utils/unique-names.ts +14 -0
- package/src/utils/url-matcher.ts +45 -0
- package/src/utils/web-element.ts +147 -0
- package/src/utils/xpath.ts +129 -0
- package/dist/bin/explorbot-cli.js.map +0 -1
- package/dist/boat/api-tester/bin/apibot-cli.js.map +0 -1
- package/dist/boat/api-tester/example/apibot.config.js +0 -31
- package/dist/boat/api-tester/example/apibot.config.js.map +0 -1
- package/dist/boat/api-tester/src/ai/chief/styles.js.map +0 -1
- package/dist/boat/api-tester/src/ai/chief.js.map +0 -1
- package/dist/boat/api-tester/src/ai/curler-tools.js.map +0 -1
- package/dist/boat/api-tester/src/ai/curler.js.map +0 -1
- package/dist/boat/api-tester/src/api-client.js.map +0 -1
- package/dist/boat/api-tester/src/apibot.js.map +0 -1
- package/dist/boat/api-tester/src/cli.js.map +0 -1
- package/dist/boat/api-tester/src/config.js.map +0 -1
- package/dist/prompts/audit-rules.md +0 -124
- package/dist/src/action-result.js.map +0 -1
- package/dist/src/action.js.map +0 -1
- package/dist/src/activity.js.map +0 -1
- package/dist/src/ai/agent.js.map +0 -1
- package/dist/src/ai/bosun.js.map +0 -1
- package/dist/src/ai/captain/idle-mode.js.map +0 -1
- package/dist/src/ai/captain/mixin.js.map +0 -1
- package/dist/src/ai/captain/test-mode.js.map +0 -1
- package/dist/src/ai/captain/web-mode.js.map +0 -1
- package/dist/src/ai/captain.js.map +0 -1
- package/dist/src/ai/conversation.js.map +0 -1
- package/dist/src/ai/experience-compactor.js.map +0 -1
- package/dist/src/ai/fisherman-tools.js.map +0 -1
- package/dist/src/ai/fisherman.js.map +0 -1
- package/dist/src/ai/historian.js.map +0 -1
- package/dist/src/ai/navigator.js.map +0 -1
- package/dist/src/ai/pilot.js.map +0 -1
- package/dist/src/ai/planner/session-dedup.js.map +0 -1
- package/dist/src/ai/planner/styles.js.map +0 -1
- package/dist/src/ai/planner/subpages.js.map +0 -1
- package/dist/src/ai/planner.js.map +0 -1
- package/dist/src/ai/provider.js.map +0 -1
- package/dist/src/ai/quartermaster.js.map +0 -1
- package/dist/src/ai/researcher/cache.js.map +0 -1
- package/dist/src/ai/researcher/coordinates.js.map +0 -1
- package/dist/src/ai/researcher/deep-analysis.js.map +0 -1
- package/dist/src/ai/researcher/fingerprint-worker.js.map +0 -1
- package/dist/src/ai/researcher/focus.js.map +0 -1
- package/dist/src/ai/researcher/locators.js.map +0 -1
- package/dist/src/ai/researcher/mixin.js.map +0 -1
- package/dist/src/ai/researcher/parser.js.map +0 -1
- package/dist/src/ai/researcher/research-result.js.map +0 -1
- package/dist/src/ai/researcher.js.map +0 -1
- package/dist/src/ai/rules.js.map +0 -1
- package/dist/src/ai/task-agent.js.map +0 -1
- package/dist/src/ai/tester.js.map +0 -1
- package/dist/src/ai/tools.js.map +0 -1
- package/dist/src/api/api-client.js.map +0 -1
- package/dist/src/api/request-result.js.map +0 -1
- package/dist/src/api/request-store.js.map +0 -1
- package/dist/src/api/spec-reader.js.map +0 -1
- package/dist/src/api/xhr-capture.js.map +0 -1
- package/dist/src/browser-server.js.map +0 -1
- package/dist/src/command-handler.js.map +0 -1
- package/dist/src/commands/add-rule-command.js.map +0 -1
- package/dist/src/commands/base-command.js.map +0 -1
- package/dist/src/commands/clean-command.js.map +0 -1
- package/dist/src/commands/context-aria-command.js.map +0 -1
- package/dist/src/commands/context-command.js.map +0 -1
- package/dist/src/commands/context-data-command.js.map +0 -1
- package/dist/src/commands/context-experience-command.js.map +0 -1
- package/dist/src/commands/context-html-command.js.map +0 -1
- package/dist/src/commands/context-knowledge-command.js.map +0 -1
- package/dist/src/commands/debug-command.js.map +0 -1
- package/dist/src/commands/drill-command.js.map +0 -1
- package/dist/src/commands/exit-command.js.map +0 -1
- package/dist/src/commands/explore-command.js.map +0 -1
- package/dist/src/commands/freesail-command.js.map +0 -1
- package/dist/src/commands/help-command.js.map +0 -1
- package/dist/src/commands/index.js.map +0 -1
- package/dist/src/commands/knows-command.js.map +0 -1
- package/dist/src/commands/learn-command.js.map +0 -1
- package/dist/src/commands/navigate-command.js.map +0 -1
- package/dist/src/commands/path-command.js.map +0 -1
- package/dist/src/commands/plan-clear-command.js.map +0 -1
- package/dist/src/commands/plan-command.js.map +0 -1
- package/dist/src/commands/plan-edit-command.js.map +0 -1
- package/dist/src/commands/plan-load-command.js.map +0 -1
- package/dist/src/commands/plan-reload-command.js.map +0 -1
- package/dist/src/commands/plan-save-command.js.map +0 -1
- package/dist/src/commands/research-command.js.map +0 -1
- package/dist/src/commands/start-command.js.map +0 -1
- package/dist/src/commands/status-command.js.map +0 -1
- package/dist/src/commands/test-command.js.map +0 -1
- package/dist/src/components/ActivityPane.js.map +0 -1
- package/dist/src/components/AddKnowledge.js.map +0 -1
- package/dist/src/components/AddRule.js.map +0 -1
- package/dist/src/components/App.js.map +0 -1
- package/dist/src/components/Autocomplete.js.map +0 -1
- package/dist/src/components/InputPane.js.map +0 -1
- package/dist/src/components/InputReadline.js.map +0 -1
- package/dist/src/components/LogPane.js.map +0 -1
- package/dist/src/components/PlanEditor.js.map +0 -1
- package/dist/src/components/PlanPane.js.map +0 -1
- package/dist/src/components/SessionTimer.js.map +0 -1
- package/dist/src/components/StateTransitionPane.js.map +0 -1
- package/dist/src/components/StatusPane.js.map +0 -1
- package/dist/src/components/TaskPane.js.map +0 -1
- package/dist/src/components/Welcome.js.map +0 -1
- package/dist/src/components/WelcomeChecklist.js.map +0 -1
- package/dist/src/components/WelcomeCommands.js.map +0 -1
- package/dist/src/components/autocomplete-store.js.map +0 -1
- package/dist/src/components/parse-keypress.js.map +0 -1
- package/dist/src/config.js.map +0 -1
- package/dist/src/execution-controller.js.map +0 -1
- package/dist/src/experience-tracker.js.map +0 -1
- package/dist/src/explorbot.js.map +0 -1
- package/dist/src/explorer.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/knowledge-tracker.js.map +0 -1
- package/dist/src/observability.js.map +0 -1
- package/dist/src/reporter.js.map +0 -1
- package/dist/src/state-manager.js.map +0 -1
- package/dist/src/stats.js.map +0 -1
- package/dist/src/test-plan.js.map +0 -1
- package/dist/src/utils/aria.js.map +0 -1
- package/dist/src/utils/code-extractor.js.map +0 -1
- package/dist/src/utils/context-formatter.js.map +0 -1
- package/dist/src/utils/error-page.js.map +0 -1
- package/dist/src/utils/expandable.js.map +0 -1
- package/dist/src/utils/hooks-runner.js.map +0 -1
- package/dist/src/utils/html-diff.js.map +0 -1
- package/dist/src/utils/html.js.map +0 -1
- package/dist/src/utils/logger.js.map +0 -1
- package/dist/src/utils/loop.js.map +0 -1
- package/dist/src/utils/markdown-parser.js.map +0 -1
- package/dist/src/utils/markdown-query.js.map +0 -1
- package/dist/src/utils/markdown-terminal.js.map +0 -1
- package/dist/src/utils/research-parser.js.map +0 -1
- package/dist/src/utils/retry.js.map +0 -1
- package/dist/src/utils/rules-loader.js.map +0 -1
- package/dist/src/utils/strings.js.map +0 -1
- package/dist/src/utils/test-plan-markdown.js.map +0 -1
- package/dist/src/utils/throttle.js.map +0 -1
- package/dist/src/utils/unique-names.js.map +0 -1
- package/dist/src/utils/url-matcher.js.map +0 -1
- package/dist/src/utils/web-element.js.map +0 -1
- package/dist/src/utils/xpath.js.map +0 -1
- package/prompts/audit-rules.md +0 -124
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import dedent from 'dedent';
|
|
2
|
+
import type { ActionResult } from '../../action-result.js';
|
|
3
|
+
import type Explorer from '../../explorer.ts';
|
|
4
|
+
import { executionController } from '../../execution-controller.ts';
|
|
5
|
+
import { parseAriaLocator } from '../../utils/aria.ts';
|
|
6
|
+
import { tag } from '../../utils/logger.js';
|
|
7
|
+
import { mdq } from '../../utils/markdown-query.ts';
|
|
8
|
+
import { WebElement } from '../../utils/web-element.ts';
|
|
9
|
+
import { FOCUSED_MARKER } from './focus.ts';
|
|
10
|
+
import type { Conversation } from '../conversation.ts';
|
|
11
|
+
import type { Provider } from '../provider.js';
|
|
12
|
+
import { locatorRule as generalLocatorRuleText } from '../rules.js';
|
|
13
|
+
import { type Constructor, debugLog } from './mixin.ts';
|
|
14
|
+
import { parseResearchSections } from './parser.ts';
|
|
15
|
+
import type { ResearchResult } from './research-result.ts';
|
|
16
|
+
|
|
17
|
+
function firstCssSegment(css: string): string | null {
|
|
18
|
+
const parts = css.split(/\s*>\s*|\s+/);
|
|
19
|
+
return parts.length > 1 ? parts[0] : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const DYNAMIC_ID_PATTERN = /^#ember\d|^\/\/[^[]*\[@id="ember\d|#react-select-|#rc-|#ng-|#cdk-|#mat-|data-ebd-id/;
|
|
23
|
+
export const isForbiddenLocator = (s: string) => DYNAMIC_ID_PATTERN.test(s) || s.includes('data-explorbot-eidx') || /\[eidx=/.test(s);
|
|
24
|
+
|
|
25
|
+
function buildPwLocatorString(loc: Locator): string {
|
|
26
|
+
const base = loc.container ? `locate('${loc.container}')` : 'page';
|
|
27
|
+
if (loc.type === 'aria') {
|
|
28
|
+
const parsed = parseAriaLocator(loc.locator);
|
|
29
|
+
if (!parsed) return `${base}.getByRole('???')`;
|
|
30
|
+
return `${base}.getByRole('${parsed.role}', { name: '${parsed.text}' })`;
|
|
31
|
+
}
|
|
32
|
+
return `${base}.locator('${loc.locator}')`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function WithLocators<T extends Constructor>(Base: T) {
|
|
36
|
+
return class extends Base {
|
|
37
|
+
declare explorer: Explorer;
|
|
38
|
+
declare provider: Provider;
|
|
39
|
+
declare actionResult: ActionResult | undefined;
|
|
40
|
+
|
|
41
|
+
async testLocators(locators: Locator[]): Promise<void> {
|
|
42
|
+
let broken = 0;
|
|
43
|
+
for (const loc of locators) {
|
|
44
|
+
if (executionController.isInterrupted()) break;
|
|
45
|
+
if (loc.type !== 'aria' && isForbiddenLocator(loc.locator)) {
|
|
46
|
+
loc.valid = false;
|
|
47
|
+
loc.error = 'dynamic ID';
|
|
48
|
+
loc.pwLocator = buildPwLocatorString(loc);
|
|
49
|
+
debugLog(`DYNAMIC ID [${loc.section}] ${loc.type} "${loc.element}": ${loc.locator}`);
|
|
50
|
+
broken++;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const count = await this.explorer.playwrightLocatorCount((page) => {
|
|
55
|
+
const base = loc.container ? page.locator(loc.container) : page;
|
|
56
|
+
if (loc.type === 'aria') {
|
|
57
|
+
const parsed = parseAriaLocator(loc.locator);
|
|
58
|
+
if (!parsed) return page.locator('__invalid__');
|
|
59
|
+
return base.getByRole(parsed.role as any, { name: parsed.text });
|
|
60
|
+
}
|
|
61
|
+
const converted = loc.locator.replace(/:contains\(/g, ':has-text(');
|
|
62
|
+
if (converted !== loc.locator) {
|
|
63
|
+
loc.locator = converted;
|
|
64
|
+
}
|
|
65
|
+
return base.locator(loc.locator);
|
|
66
|
+
});
|
|
67
|
+
loc.valid = count === 1;
|
|
68
|
+
loc.pwLocator = buildPwLocatorString(loc);
|
|
69
|
+
if (!loc.valid) {
|
|
70
|
+
loc.error = count === 0 ? '0 elements' : `${count} elements`;
|
|
71
|
+
debugLog(`BROKEN [${loc.section}] ${loc.type} "${loc.element}": ${loc.locator} (${loc.error})`);
|
|
72
|
+
broken++;
|
|
73
|
+
}
|
|
74
|
+
} catch (err) {
|
|
75
|
+
loc.valid = false;
|
|
76
|
+
loc.error = err instanceof Error ? err.message : String(err);
|
|
77
|
+
loc.pwLocator = buildPwLocatorString(loc);
|
|
78
|
+
debugLog(`ERROR [${loc.section}] ${loc.type} "${loc.element}": ${loc.locator} — ${loc.error}`);
|
|
79
|
+
broken++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
tag('substep').log(`Validated ${locators.length} locators: ${locators.length - broken} valid, ${broken} broken`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async fixBrokenSections(result: ResearchResult, conversation: Conversation): Promise<void> {
|
|
87
|
+
const broken = result.locators.filter((l) => l.valid === false);
|
|
88
|
+
if (broken.length === 0) return;
|
|
89
|
+
|
|
90
|
+
const bySection = new Map<string, Locator[]>();
|
|
91
|
+
for (const loc of broken) {
|
|
92
|
+
const list = bySection.get(loc.section) || [];
|
|
93
|
+
list.push(loc);
|
|
94
|
+
bySection.set(loc.section, list);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const allLocsBySection = new Map<string, Locator[]>();
|
|
98
|
+
for (const loc of result.locators) {
|
|
99
|
+
const list = allLocsBySection.get(loc.section) || [];
|
|
100
|
+
list.push(loc);
|
|
101
|
+
allLocsBySection.set(loc.section, list);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const sectionParts: string[] = [];
|
|
105
|
+
const parsedSections = parseResearchSections(result.text);
|
|
106
|
+
for (const [name, sectionBroken] of bySection) {
|
|
107
|
+
const allLocs = allLocsBySection.get(name) || [];
|
|
108
|
+
const section = parsedSections.find((s) => s.name === name);
|
|
109
|
+
const container = section?.containerCss;
|
|
110
|
+
|
|
111
|
+
const isContainerBroken = sectionBroken.some((l) => l.error === 'container broken');
|
|
112
|
+
|
|
113
|
+
let header = `## ${name}\n`;
|
|
114
|
+
if (container) {
|
|
115
|
+
header += isContainerBroken ? `\n> Container: '${container}' ← BROKEN (container not found)\n` : `\n> Container: '${container}'\n`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const testedLines = allLocs.map((loc) => {
|
|
119
|
+
const status = loc.valid === false ? `← BROKEN (${loc.error || 'unknown'})` : '← OK';
|
|
120
|
+
return `- '${loc.element}': ${loc.pwLocator || loc.locator} ${status}`;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
sectionParts.push(`${header}\nTested Elements:\n${testedLines.join('\n')}`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const prompt = dedent`
|
|
127
|
+
Some locators in your research are broken. Please fix the broken sections.
|
|
128
|
+
|
|
129
|
+
${sectionParts.join('\n\n')}
|
|
130
|
+
|
|
131
|
+
Return corrected sections in the same format as the original research.
|
|
132
|
+
Fix broken containers and locators. Keep working ones unchanged.
|
|
133
|
+
${generalLocatorRuleText}
|
|
134
|
+
`;
|
|
135
|
+
|
|
136
|
+
tag('substep').log(`Fixing ${broken.length} broken locators via AI conversation...`);
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
conversation.addUserText(prompt);
|
|
140
|
+
const invocationResult = await this.provider.invokeConversation(conversation, undefined, { agentName: 'researcher' });
|
|
141
|
+
if (!invocationResult) return;
|
|
142
|
+
|
|
143
|
+
const fixedSections = parseResearchSections(invocationResult.response.text);
|
|
144
|
+
if (fixedSections.length === 0) return;
|
|
145
|
+
|
|
146
|
+
for (const fixedSection of fixedSections) {
|
|
147
|
+
const originalSections = parseResearchSections(result.text);
|
|
148
|
+
const original = originalSections.find((s) => s.name === fixedSection.name);
|
|
149
|
+
if (!original || original.elements.length === 0) continue;
|
|
150
|
+
|
|
151
|
+
if (fixedSection.containerCss && fixedSection.containerCss !== original.containerCss) {
|
|
152
|
+
debugLog(`Fixed container for "${fixedSection.name}": '${original.containerCss}' → '${fixedSection.containerCss}'`);
|
|
153
|
+
original.containerCss = fixedSection.containerCss;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const fixedByName = new Map(fixedSection.elements.map((el) => [el.name, el]));
|
|
157
|
+
for (const el of original.elements) {
|
|
158
|
+
const fix = fixedByName.get(el.name);
|
|
159
|
+
if (!fix) continue;
|
|
160
|
+
if (fix.css) el.css = fix.css;
|
|
161
|
+
if (fix.aria) el.aria = fix.aria;
|
|
162
|
+
}
|
|
163
|
+
result.rebuildSectionInText(original);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
result.parseLocators();
|
|
167
|
+
await this.testLocators(result.locators);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
tag('substep').log(`AI fix failed: ${err instanceof Error ? err.message : err}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async backfillBrokenLocators(result: ResearchResult): Promise<void> {
|
|
174
|
+
result.parseLocators();
|
|
175
|
+
await this.testLocators(result.locators);
|
|
176
|
+
|
|
177
|
+
const sections = parseResearchSections(result.text);
|
|
178
|
+
const brokenCss = new Set(result.locators.filter((l) => l.type === 'css' && l.valid === false).map((l) => `${l.section}::${l.element}`));
|
|
179
|
+
|
|
180
|
+
const needsXpath: string[] = [];
|
|
181
|
+
const needsXpathEls = new Map<string, { section: (typeof sections)[0]; el: (typeof sections)[0]['elements'][0] }>();
|
|
182
|
+
|
|
183
|
+
for (const section of sections) {
|
|
184
|
+
for (const el of section.elements) {
|
|
185
|
+
if (el.aria && !/\w/.test(el.aria.text)) el.aria = null;
|
|
186
|
+
if (!el.eidx || el.xpath) continue;
|
|
187
|
+
const hasWorkingCss = el.css && !brokenCss.has(`${section.name}::${el.name}`);
|
|
188
|
+
const hasWorkingAria = el.aria && /\w/.test(el.aria.text);
|
|
189
|
+
if (!hasWorkingCss && !hasWorkingAria) {
|
|
190
|
+
needsXpath.push(el.eidx);
|
|
191
|
+
needsXpathEls.set(el.eidx, { section, el });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (needsXpath.length > 0) {
|
|
197
|
+
const page = this.explorer.playwrightHelper.page;
|
|
198
|
+
const webElements = await WebElement.fromEidxList(page, needsXpath);
|
|
199
|
+
const changedSections = new Set<(typeof sections)[0]>();
|
|
200
|
+
for (const w of webElements) {
|
|
201
|
+
const entry = needsXpathEls.get(w.eidx!);
|
|
202
|
+
if (!entry || !w.clickXPath) continue;
|
|
203
|
+
entry.el.xpath = w.clickXPath;
|
|
204
|
+
changedSections.add(entry.section);
|
|
205
|
+
}
|
|
206
|
+
for (const section of changedSections) result.rebuildSectionInText(section);
|
|
207
|
+
tag('substep').log(`Backfilled XPath for ${webElements.length} elements missing working locators`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
await this.validateContainers(result);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private async validateContainers(result: ResearchResult): Promise<void> {
|
|
214
|
+
const sections = parseResearchSections(result.text);
|
|
215
|
+
|
|
216
|
+
for (const section of sections) {
|
|
217
|
+
if (!section.containerCss) continue;
|
|
218
|
+
|
|
219
|
+
let count = 0;
|
|
220
|
+
try {
|
|
221
|
+
count = await this.explorer.playwrightLocatorCount((page) => page.locator(section.containerCss!));
|
|
222
|
+
} catch {}
|
|
223
|
+
|
|
224
|
+
if (count >= 1) continue;
|
|
225
|
+
|
|
226
|
+
const simplified = firstCssSegment(section.containerCss);
|
|
227
|
+
if (simplified) {
|
|
228
|
+
let simplifiedCount = 0;
|
|
229
|
+
try {
|
|
230
|
+
simplifiedCount = await this.explorer.playwrightLocatorCount((page) => page.locator(simplified));
|
|
231
|
+
} catch {}
|
|
232
|
+
|
|
233
|
+
if (simplifiedCount >= 1) {
|
|
234
|
+
debugLog(`Simplified container: '${section.containerCss}' → '${simplified}'`);
|
|
235
|
+
this.updateSectionContainer(result, section, simplified);
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
debugLog(`Nullified broken container: '${section.containerCss}' in "${section.name}"`);
|
|
241
|
+
this.updateSectionContainer(result, section, null);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
private updateSectionContainer(result: ResearchResult, section: ReturnType<typeof parseResearchSections>[0], newCss: string | null): void {
|
|
246
|
+
const oldCss = section.containerCss;
|
|
247
|
+
const escaped = section.name.replace(/"/g, '\\"');
|
|
248
|
+
let sectionQuery = mdq(result.text).query(`section2(~"${escaped}")`);
|
|
249
|
+
if (sectionQuery.count() === 0) sectionQuery = mdq(result.text).query(`section3(~"${escaped}")`);
|
|
250
|
+
|
|
251
|
+
if (newCss) {
|
|
252
|
+
result.text = sectionQuery.query('blockquote[0]').replace(`Container: '${newCss}'`);
|
|
253
|
+
} else {
|
|
254
|
+
result.text = sectionQuery.query('blockquote[0]').replace('');
|
|
255
|
+
result.text = result.text.replace(`${FOCUSED_MARKER}\n`, '');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
for (const loc of result.locators) {
|
|
259
|
+
if (loc.container === oldCss && loc.section === section.name) {
|
|
260
|
+
loc.container = newCss;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface Locator {
|
|
268
|
+
section: string;
|
|
269
|
+
container: string | null;
|
|
270
|
+
element: string;
|
|
271
|
+
type: 'css' | 'xpath' | 'aria';
|
|
272
|
+
locator: string;
|
|
273
|
+
valid: boolean | null;
|
|
274
|
+
error: string | null;
|
|
275
|
+
pwLocator: string | null;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface LocatorMethods {
|
|
279
|
+
testLocators(locators: Locator[]): Promise<void>;
|
|
280
|
+
fixBrokenSections(result: ResearchResult, conversation: Conversation): Promise<void>;
|
|
281
|
+
backfillBrokenLocators(result: ResearchResult): Promise<void>;
|
|
282
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { parseAriaLocator } from '../../utils/aria.ts';
|
|
2
|
+
import { pluralize } from '../../utils/logger.ts';
|
|
3
|
+
import { jsonToTable, parseSections, tableToJson } from '../../utils/markdown-parser.ts';
|
|
4
|
+
import { mdq } from '../../utils/markdown-query.ts';
|
|
5
|
+
import { FOCUSED_MARKER } from './focus.ts';
|
|
6
|
+
|
|
7
|
+
export interface ResearchElement {
|
|
8
|
+
name: string;
|
|
9
|
+
type: string | null;
|
|
10
|
+
aria: { role: string; text: string } | null;
|
|
11
|
+
css: string | null;
|
|
12
|
+
xpath: string | null;
|
|
13
|
+
coordinates: string | null;
|
|
14
|
+
color: string | null;
|
|
15
|
+
icon: string | null;
|
|
16
|
+
eidx: string | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ResearchSection {
|
|
20
|
+
name: string;
|
|
21
|
+
containerCss: string | null;
|
|
22
|
+
elements: ResearchElement[];
|
|
23
|
+
rawMarkdown: string;
|
|
24
|
+
isExtended: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const SKIP_SECTIONS = new Set(['summary', 'screenshot analysis', 'data', 'primary actions']);
|
|
28
|
+
|
|
29
|
+
export const RESEARCH_COLUMN_ORDER = ['Element', 'Type', 'ARIA', 'CSS', 'XPath', 'Coordinates', 'Color', 'Icon', 'eidx'];
|
|
30
|
+
|
|
31
|
+
function stripQuotes(str: string): string {
|
|
32
|
+
let trimmed = str.trim();
|
|
33
|
+
if (trimmed.startsWith('**') && trimmed.endsWith('**')) {
|
|
34
|
+
trimmed = trimmed.slice(2, -2);
|
|
35
|
+
}
|
|
36
|
+
if ((trimmed.startsWith("'") && trimmed.endsWith("'")) || (trimmed.startsWith('"') && trimmed.endsWith('"'))) {
|
|
37
|
+
return trimmed.slice(1, -1);
|
|
38
|
+
}
|
|
39
|
+
if (trimmed.startsWith('`') && trimmed.endsWith('`')) {
|
|
40
|
+
return trimmed.slice(1, -1);
|
|
41
|
+
}
|
|
42
|
+
return trimmed;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function normalizeLocatorValue(val: string): string | null {
|
|
46
|
+
let s = val.trim();
|
|
47
|
+
let prev = '';
|
|
48
|
+
while (prev !== s) {
|
|
49
|
+
prev = s;
|
|
50
|
+
s = stripQuotes(s).trim();
|
|
51
|
+
}
|
|
52
|
+
if (s === '-' || s === '') return null;
|
|
53
|
+
return s;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function mapRowToElement(row: Record<string, string>): ResearchElement | null {
|
|
57
|
+
const colMap: Record<string, string> = {};
|
|
58
|
+
for (const [key, value] of Object.entries(row)) {
|
|
59
|
+
colMap[key.toLowerCase()] = value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const name = stripQuotes(colMap.element || '');
|
|
63
|
+
if (!name) return null;
|
|
64
|
+
|
|
65
|
+
let eidxRaw = (colMap.eidx || '').trim();
|
|
66
|
+
if (eidxRaw && /^\d+$/.test(eidxRaw)) eidxRaw = `e${eidxRaw}`;
|
|
67
|
+
|
|
68
|
+
const aria = parseAriaLocator(colMap.aria || '-');
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
name,
|
|
72
|
+
type: colMap.type?.trim() || aria?.role || null,
|
|
73
|
+
aria,
|
|
74
|
+
css: normalizeLocatorValue(colMap.css || '-'),
|
|
75
|
+
xpath: normalizeLocatorValue(colMap.xpath || '-'),
|
|
76
|
+
coordinates: (colMap.coordinates || '-').trim() === '-' ? null : colMap.coordinates.trim(),
|
|
77
|
+
color: (colMap.color || '-').trim() === '-' || (colMap.color || '').trim() === '' ? null : colMap.color.trim(),
|
|
78
|
+
icon: (colMap.icon || '-').trim() === '-' || (colMap.icon || '').trim() === '' ? null : colMap.icon.trim(),
|
|
79
|
+
eidx: eidxRaw && eidxRaw !== '-' ? eidxRaw : null,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function extractContainerFromBlockquote(sectionMarkdown: string): string | null {
|
|
84
|
+
const bq = mdq(sectionMarkdown).query('blockquote[0]').text().trim();
|
|
85
|
+
if (!bq) return null;
|
|
86
|
+
const match = bq.match(/Container:\s*(.+)/i);
|
|
87
|
+
if (!match) return null;
|
|
88
|
+
const css = normalizeLocatorValue(match[1]);
|
|
89
|
+
if (!css || !/^[.#\[\w]/.test(css)) return null;
|
|
90
|
+
return css;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function parseResearchSections(markdown: string): ResearchSection[] {
|
|
94
|
+
const hasExtendedResearch = markdown.includes('\n# Extended Research') || markdown.startsWith('# Extended Research');
|
|
95
|
+
|
|
96
|
+
return parseSections(markdown)
|
|
97
|
+
.filter((s) => !SKIP_SECTIONS.has(s.name.toLowerCase()) && !s.name.toLowerCase().includes('data:'))
|
|
98
|
+
.map((section) => {
|
|
99
|
+
const containerCss = extractContainerFromBlockquote(section.rawMarkdown);
|
|
100
|
+
const rows = tableToJson(section.rawMarkdown);
|
|
101
|
+
const elements = rows.map(mapRowToElement).filter(Boolean) as ResearchElement[];
|
|
102
|
+
const isExtended = hasExtendedResearch && section.depth === 3;
|
|
103
|
+
|
|
104
|
+
return { name: section.name, containerCss, elements, rawMarkdown: section.rawMarkdown, isExtended };
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function extractValidContainers(researchText: string, opts?: { exclude?: string[] }): Array<{ css: string; label: string }> {
|
|
109
|
+
const exclude = opts?.exclude || [];
|
|
110
|
+
return parseResearchSections(researchText)
|
|
111
|
+
.filter((s) => s.containerCss && !exclude.includes(s.containerCss))
|
|
112
|
+
.map((s) => ({ css: s.containerCss!, label: s.name }));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function rebuildSectionMarkdown(section: ResearchSection): string {
|
|
116
|
+
const hasEidx = section.elements.some((e) => e.eidx);
|
|
117
|
+
const hasXpath = section.elements.some((e) => e.xpath);
|
|
118
|
+
const hasCoordinates = section.elements.some((e) => e.coordinates);
|
|
119
|
+
const hasColor = section.elements.some((e) => e.color);
|
|
120
|
+
const hasIcon = section.elements.some((e) => e.icon);
|
|
121
|
+
|
|
122
|
+
const presentColumns = new Set(['Element', 'ARIA', 'CSS']);
|
|
123
|
+
if (section.elements.some((e) => e.type || e.aria)) presentColumns.add('Type');
|
|
124
|
+
if (hasXpath) presentColumns.add('XPath');
|
|
125
|
+
if (hasCoordinates) presentColumns.add('Coordinates');
|
|
126
|
+
if (hasColor) presentColumns.add('Color');
|
|
127
|
+
if (hasIcon) presentColumns.add('Icon');
|
|
128
|
+
if (hasEidx) presentColumns.add('eidx');
|
|
129
|
+
|
|
130
|
+
const columns = RESEARCH_COLUMN_ORDER.filter((c) => presentColumns.has(c));
|
|
131
|
+
|
|
132
|
+
const rows = section.elements.map((el) => {
|
|
133
|
+
const row: Record<string, string> = {
|
|
134
|
+
Element: `'${el.name}'`,
|
|
135
|
+
};
|
|
136
|
+
if (presentColumns.has('Type')) row.Type = el.type || el.aria?.role || '-';
|
|
137
|
+
row.ARIA = el.aria ? `{ role: '${el.aria.role}', text: '${el.aria.text}' }` : '-';
|
|
138
|
+
row.CSS = el.css ? `'${el.css}'` : '-';
|
|
139
|
+
if (hasXpath) row.XPath = el.xpath ? `'${el.xpath}'` : '-';
|
|
140
|
+
if (hasCoordinates) row.Coordinates = el.coordinates || '-';
|
|
141
|
+
if (hasColor) row.Color = el.color || '-';
|
|
142
|
+
if (hasIcon) row.Icon = el.icon || '-';
|
|
143
|
+
if (hasEidx) row.eidx = el.eidx ? String(el.eidx) : '-';
|
|
144
|
+
return row;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return jsonToTable(rows, columns);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function formatResearchSummary(text: string, opts?: { visionUsed?: boolean }): string {
|
|
151
|
+
const sections = parseResearchSections(text);
|
|
152
|
+
const coordCount = sections.reduce((sum, s) => sum + s.elements.filter((e) => e.coordinates !== null).length, 0);
|
|
153
|
+
|
|
154
|
+
const mainSections = sections.filter((s) => !s.isExtended);
|
|
155
|
+
const extendedSections = sections.filter((s) => s.isExtended);
|
|
156
|
+
|
|
157
|
+
const lines: string[] = [];
|
|
158
|
+
|
|
159
|
+
for (const s of mainSections) {
|
|
160
|
+
if (s.elements.length === 0 && !s.containerCss) continue;
|
|
161
|
+
lines.push(formatSectionLine(s));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (extendedSections.length > 0) {
|
|
165
|
+
lines.push('', 'Extended Research', '');
|
|
166
|
+
for (const s of extendedSections) {
|
|
167
|
+
if (s.elements.length === 0 && !s.containerCss) continue;
|
|
168
|
+
lines.push(formatSectionLine(s));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
lines.push('', `Chars: ${text.length}`);
|
|
173
|
+
|
|
174
|
+
if (opts?.visionUsed || coordCount > 0) {
|
|
175
|
+
lines.push(`Vision: ${coordCount} elements with coordinates`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return lines.join('\n');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function formatSectionLine(s: ResearchSection): string {
|
|
182
|
+
const parts = [`* ${s.name} (${s.elements.length} ${pluralize(s.elements.length, 'element')})`];
|
|
183
|
+
if (s.containerCss) parts.push(`\`${s.containerCss}\``);
|
|
184
|
+
if (s.rawMarkdown.includes(FOCUSED_MARKER)) parts.push('**Focused**');
|
|
185
|
+
return parts.join(' ');
|
|
186
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { parseAriaLocator } from '../../utils/aria.ts';
|
|
2
|
+
import { jsonToTable } from '../../utils/markdown-parser.ts';
|
|
3
|
+
import { mdq } from '../../utils/markdown-query.ts';
|
|
4
|
+
import type { Locator } from './locators.ts';
|
|
5
|
+
import { RESEARCH_COLUMN_ORDER, type ResearchSection, parseResearchSections, rebuildSectionMarkdown } from './parser.ts';
|
|
6
|
+
|
|
7
|
+
export class ResearchResult {
|
|
8
|
+
text: string;
|
|
9
|
+
url: string;
|
|
10
|
+
createdAt: Date;
|
|
11
|
+
locators: Locator[] = [];
|
|
12
|
+
|
|
13
|
+
constructor(text: string, url: string) {
|
|
14
|
+
this.text = text;
|
|
15
|
+
this.url = url;
|
|
16
|
+
this.createdAt = new Date();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
parseLocators(): void {
|
|
20
|
+
const sections = parseResearchSections(this.text);
|
|
21
|
+
const locators: Locator[] = [];
|
|
22
|
+
for (const section of sections) {
|
|
23
|
+
for (const el of section.elements) {
|
|
24
|
+
if (el.css) locators.push({ section: section.name, container: section.containerCss, element: el.name, type: 'css', locator: el.css, valid: null, error: null, pwLocator: null });
|
|
25
|
+
if (el.xpath) locators.push({ section: section.name, container: section.containerCss, element: el.name, type: 'xpath', locator: el.xpath, valid: null, error: null, pwLocator: null });
|
|
26
|
+
if (el.aria && /\w/.test(el.aria.text)) locators.push({ section: section.name, container: section.containerCss, element: el.name, type: 'aria', locator: `{ role: '${el.aria.role}', text: '${el.aria.text}' }`, valid: null, error: null, pwLocator: null });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
this.locators = locators;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get containers(): string[] {
|
|
33
|
+
return [...new Set(this.locators.map((l) => l.container).filter(Boolean))] as string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get containerLocators(): Locator[] {
|
|
37
|
+
return this.containers.map((css) => ({
|
|
38
|
+
section: '',
|
|
39
|
+
container: null,
|
|
40
|
+
element: css,
|
|
41
|
+
type: 'css' as const,
|
|
42
|
+
locator: css,
|
|
43
|
+
valid: null,
|
|
44
|
+
error: null,
|
|
45
|
+
pwLocator: null,
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
updateSection(sectionName: string, locators: Locator[]): void {
|
|
50
|
+
const sections = parseResearchSections(this.text);
|
|
51
|
+
const section = sections.find((s) => s.name === sectionName);
|
|
52
|
+
if (!section) return;
|
|
53
|
+
|
|
54
|
+
for (const el of section.elements) {
|
|
55
|
+
const elLocators = locators.filter((l) => l.element === el.name);
|
|
56
|
+
for (const loc of elLocators) {
|
|
57
|
+
const value = loc.valid === false ? null : loc.locator || null;
|
|
58
|
+
if (loc.type === 'css') el.css = value;
|
|
59
|
+
if (loc.type === 'xpath') el.xpath = value;
|
|
60
|
+
if (loc.type === 'aria') el.aria = value ? parseAriaLocator(value) : null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.rebuildSectionInText(section);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
rebuildSectionInText(section: ResearchSection): void {
|
|
68
|
+
if (section.elements.length === 0) return;
|
|
69
|
+
const newTable = rebuildSectionMarkdown(section);
|
|
70
|
+
const escaped = section.name.replace(/"/g, '\\"');
|
|
71
|
+
let sectionQuery = mdq(this.text).query(`section2(~"${escaped}")`);
|
|
72
|
+
if (sectionQuery.count() === 0) sectionQuery = mdq(this.text).query(`section3(~"${escaped}")`);
|
|
73
|
+
const updated = sectionQuery.query('table').replace(`${newTable.trimEnd()}\n`);
|
|
74
|
+
if (updated === this.text) return;
|
|
75
|
+
section.rawMarkdown = mdq(section.rawMarkdown).query('table').replace(`${newTable.trimEnd()}\n`);
|
|
76
|
+
this.text = updated;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
cleanup(): void {
|
|
80
|
+
for (const table of mdq(this.text).query('table').each()) {
|
|
81
|
+
const rows = table.toJson();
|
|
82
|
+
if (rows.length === 0) continue;
|
|
83
|
+
|
|
84
|
+
let changed = false;
|
|
85
|
+
|
|
86
|
+
if (!('Type' in rows[0]) && 'ARIA' in rows[0]) {
|
|
87
|
+
for (const row of rows) {
|
|
88
|
+
row.Type = parseAriaLocator(row.ARIA || '-')?.role || '-';
|
|
89
|
+
}
|
|
90
|
+
changed = true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (const row of rows) {
|
|
94
|
+
if (row.ARIA && !parseAriaLocator(row.ARIA)) {
|
|
95
|
+
row.ARIA = '-';
|
|
96
|
+
changed = true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const hasEidx = 'eidx' in rows[0];
|
|
101
|
+
if (!changed && !hasEidx) continue;
|
|
102
|
+
|
|
103
|
+
const rawTable = table.text();
|
|
104
|
+
const baseColumns = Object.keys(rows[0]).filter((c) => c !== 'eidx');
|
|
105
|
+
const columns = this.reorderColumns(baseColumns);
|
|
106
|
+
const cleaned = rows.map(({ eidx, ...rest }) => rest);
|
|
107
|
+
this.text = this.text.replace(rawTable, jsonToTable(cleaned, columns));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private reorderColumns(columns: string[]): string[] {
|
|
112
|
+
const ordered = RESEARCH_COLUMN_ORDER.filter((c) => columns.includes(c));
|
|
113
|
+
const rest = columns.filter((c) => !RESEARCH_COLUMN_ORDER.includes(c));
|
|
114
|
+
return [...ordered, ...rest];
|
|
115
|
+
}
|
|
116
|
+
}
|