@detiq/crawler 0.1.3
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/Dockerfile +49 -0
- package/README.md +11 -0
- package/dist/accessibility-auditor.d.ts +29 -0
- package/dist/accessibility-auditor.js +57 -0
- package/dist/accessibility-auditor.js.map +7 -0
- package/dist/ai-login.d.ts +32 -0
- package/dist/ai-login.js +177 -0
- package/dist/ai-login.js.map +7 -0
- package/dist/auth-token-rotator.d.ts +47 -0
- package/dist/auth-token-rotator.js +58 -0
- package/dist/auth-token-rotator.js.map +7 -0
- package/dist/auth.d.ts +20 -0
- package/dist/auth.js +329 -0
- package/dist/auth.js.map +7 -0
- package/dist/browser-extension.d.ts +37 -0
- package/dist/browser-extension.js +113 -0
- package/dist/browser-extension.js.map +7 -0
- package/dist/captcha-solver.d.ts +16 -0
- package/dist/captcha-solver.js +105 -0
- package/dist/captcha-solver.js.map +7 -0
- package/dist/color-contrast.d.ts +30 -0
- package/dist/color-contrast.js +78 -0
- package/dist/color-contrast.js.map +7 -0
- package/dist/content-chunker.d.ts +18 -0
- package/dist/content-chunker.js +152 -0
- package/dist/content-chunker.js.map +7 -0
- package/dist/content-dedup.d.ts +23 -0
- package/dist/content-dedup.js +60 -0
- package/dist/content-dedup.js.map +7 -0
- package/dist/cookie-consent.d.ts +25 -0
- package/dist/cookie-consent.js +78 -0
- package/dist/cookie-consent.js.map +7 -0
- package/dist/cookie-jar.d.ts +20 -0
- package/dist/cookie-jar.js +61 -0
- package/dist/cookie-jar.js.map +7 -0
- package/dist/crawler.d.ts +179 -0
- package/dist/crawler.js +3672 -0
- package/dist/crawler.js.map +7 -0
- package/dist/custom-js-injector.d.ts +42 -0
- package/dist/custom-js-injector.js +50 -0
- package/dist/custom-js-injector.js.map +7 -0
- package/dist/dark-mode-capture.d.ts +23 -0
- package/dist/dark-mode-capture.js +75 -0
- package/dist/dark-mode-capture.js.map +7 -0
- package/dist/dead-link-detector.d.ts +37 -0
- package/dist/dead-link-detector.js +50 -0
- package/dist/dead-link-detector.js.map +7 -0
- package/dist/element-hash.d.ts +9 -0
- package/dist/element-hash.js +9 -0
- package/dist/element-hash.js.map +7 -0
- package/dist/email-otp.d.ts +42 -0
- package/dist/email-otp.js +177 -0
- package/dist/email-otp.js.map +7 -0
- package/dist/engine-router.d.ts +47 -0
- package/dist/engine-router.js +94 -0
- package/dist/engine-router.js.map +7 -0
- package/dist/export/bulk-export.d.ts +26 -0
- package/dist/export/bulk-export.js +76 -0
- package/dist/export/bulk-export.js.map +7 -0
- package/dist/export/vector-export.d.ts +76 -0
- package/dist/export/vector-export.js +85 -0
- package/dist/export/vector-export.js.map +7 -0
- package/dist/extractors/advanced.d.ts +54 -0
- package/dist/extractors/advanced.js +245 -0
- package/dist/extractors/advanced.js.map +7 -0
- package/dist/extractors/artifact-envelope.d.ts +63 -0
- package/dist/extractors/artifact-envelope.js +63 -0
- package/dist/extractors/artifact-envelope.js.map +7 -0
- package/dist/failure-analysis-agent.d.ts +16 -0
- package/dist/failure-analysis-agent.js +40 -0
- package/dist/failure-analysis-agent.js.map +7 -0
- package/dist/feature-flag-detector.d.ts +30 -0
- package/dist/feature-flag-detector.js +55 -0
- package/dist/feature-flag-detector.js.map +7 -0
- package/dist/form-detector.d.ts +34 -0
- package/dist/form-detector.js +58 -0
- package/dist/form-detector.js.map +7 -0
- package/dist/frontier.d.ts +32 -0
- package/dist/frontier.js +83 -0
- package/dist/frontier.js.map +7 -0
- package/dist/gap-pass.d.ts +35 -0
- package/dist/gap-pass.js +81 -0
- package/dist/gap-pass.js.map +7 -0
- package/dist/graphql-detector.d.ts +39 -0
- package/dist/graphql-detector.js +86 -0
- package/dist/graphql-detector.js.map +7 -0
- package/dist/http-engine.d.ts +80 -0
- package/dist/http-engine.js +304 -0
- package/dist/http-engine.js.map +7 -0
- package/dist/incremental-diff.d.ts +59 -0
- package/dist/incremental-diff.js +61 -0
- package/dist/incremental-diff.js.map +7 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +7 -0
- package/dist/input-fuzzer.d.ts +30 -0
- package/dist/input-fuzzer.js +105 -0
- package/dist/input-fuzzer.js.map +7 -0
- package/dist/interactive-probe.d.ts +104 -0
- package/dist/interactive-probe.js +442 -0
- package/dist/interactive-probe.js.map +7 -0
- package/dist/job-queue.d.ts +171 -0
- package/dist/job-queue.js +2256 -0
- package/dist/job-queue.js.map +7 -0
- package/dist/js-coverage.d.ts +29 -0
- package/dist/js-coverage.js +56 -0
- package/dist/js-coverage.js.map +7 -0
- package/dist/js-router-detector.d.ts +17 -0
- package/dist/js-router-detector.js +90 -0
- package/dist/js-router-detector.js.map +7 -0
- package/dist/language-detector.d.ts +22 -0
- package/dist/language-detector.js +57 -0
- package/dist/language-detector.js.map +7 -0
- package/dist/link-classifier.d.ts +23 -0
- package/dist/link-classifier.js +40 -0
- package/dist/link-classifier.js.map +7 -0
- package/dist/live-view.d.ts +36 -0
- package/dist/live-view.js +100 -0
- package/dist/live-view.js.map +7 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +10 -0
- package/dist/logger.js.map +7 -0
- package/dist/markdown-extract.d.ts +8 -0
- package/dist/markdown-extract.js +54 -0
- package/dist/markdown-extract.js.map +7 -0
- package/dist/native-crawler.d.ts +69 -0
- package/dist/native-crawler.js +839 -0
- package/dist/native-crawler.js.map +7 -0
- package/dist/network-observer.d.ts +49 -0
- package/dist/network-observer.js +149 -0
- package/dist/network-observer.js.map +7 -0
- package/dist/network-throttle.d.ts +25 -0
- package/dist/network-throttle.js +34 -0
- package/dist/network-throttle.js.map +7 -0
- package/dist/openapi-generator.d.ts +49 -0
- package/dist/openapi-generator.js +89 -0
- package/dist/openapi-generator.js.map +7 -0
- package/dist/pdf-extractor.d.ts +28 -0
- package/dist/pdf-extractor.js +81 -0
- package/dist/pdf-extractor.js.map +7 -0
- package/dist/performance-metrics.d.ts +53 -0
- package/dist/performance-metrics.js +83 -0
- package/dist/performance-metrics.js.map +7 -0
- package/dist/phash.d.ts +38 -0
- package/dist/phash.js +115 -0
- package/dist/phash.js.map +7 -0
- package/dist/pii-scrubber.d.ts +21 -0
- package/dist/pii-scrubber.js +75 -0
- package/dist/pii-scrubber.js.map +7 -0
- package/dist/playwright-recorder.d.ts +39 -0
- package/dist/playwright-recorder.js +123 -0
- package/dist/playwright-recorder.js.map +7 -0
- package/dist/policies/crawl-safety.d.ts +9 -0
- package/dist/policies/crawl-safety.js +37 -0
- package/dist/policies/crawl-safety.js.map +7 -0
- package/dist/profiles/domain-profile.d.ts +19 -0
- package/dist/profiles/domain-profile.js +140 -0
- package/dist/profiles/domain-profile.js.map +7 -0
- package/dist/proxy.d.ts +50 -0
- package/dist/proxy.js +165 -0
- package/dist/proxy.js.map +7 -0
- package/dist/rate-limiter.d.ts +31 -0
- package/dist/rate-limiter.js +64 -0
- package/dist/rate-limiter.js.map +7 -0
- package/dist/redirect-tracker.d.ts +37 -0
- package/dist/redirect-tracker.js +65 -0
- package/dist/redirect-tracker.js.map +7 -0
- package/dist/redis-frontier.d.ts +48 -0
- package/dist/redis-frontier.js +126 -0
- package/dist/redis-frontier.js.map +7 -0
- package/dist/redis-queue.d.ts +48 -0
- package/dist/redis-queue.js +165 -0
- package/dist/redis-queue.js.map +7 -0
- package/dist/response-cache.d.ts +38 -0
- package/dist/response-cache.js +140 -0
- package/dist/response-cache.js.map +7 -0
- package/dist/responsive-detector.d.ts +29 -0
- package/dist/responsive-detector.js +46 -0
- package/dist/responsive-detector.js.map +7 -0
- package/dist/retry-policy.d.ts +20 -0
- package/dist/retry-policy.js +54 -0
- package/dist/retry-policy.js.map +7 -0
- package/dist/robots-txt.d.ts +9 -0
- package/dist/robots-txt.js +77 -0
- package/dist/robots-txt.js.map +7 -0
- package/dist/screen-reader.d.ts +16 -0
- package/dist/screen-reader.js +46 -0
- package/dist/screen-reader.js.map +7 -0
- package/dist/screenshot-masker.d.ts +28 -0
- package/dist/screenshot-masker.js +62 -0
- package/dist/screenshot-masker.js.map +7 -0
- package/dist/seo-checker.d.ts +33 -0
- package/dist/seo-checker.js +91 -0
- package/dist/seo-checker.js.map +7 -0
- package/dist/session-capture.d.ts +35 -0
- package/dist/session-capture.js +267 -0
- package/dist/session-capture.js.map +7 -0
- package/dist/session-export.d.ts +49 -0
- package/dist/session-export.js +117 -0
- package/dist/session-export.js.map +7 -0
- package/dist/sitemap-writer.d.ts +21 -0
- package/dist/sitemap-writer.js +47 -0
- package/dist/sitemap-writer.js.map +7 -0
- package/dist/sitemap.d.ts +51 -0
- package/dist/sitemap.js +152 -0
- package/dist/sitemap.js.map +7 -0
- package/dist/skyvern.d.ts +56 -0
- package/dist/skyvern.js +129 -0
- package/dist/skyvern.js.map +7 -0
- package/dist/sqs-queue.d.ts +2 -0
- package/dist/sqs-queue.js +47 -0
- package/dist/sqs-queue.js.map +7 -0
- package/dist/sso-token.d.ts +29 -0
- package/dist/sso-token.js +76 -0
- package/dist/sso-token.js.map +7 -0
- package/dist/stealth/human-behavior.d.ts +20 -0
- package/dist/stealth/human-behavior.js +168 -0
- package/dist/stealth/human-behavior.js.map +7 -0
- package/dist/telemetry.d.ts +34 -0
- package/dist/telemetry.js +77 -0
- package/dist/telemetry.js.map +7 -0
- package/dist/test-executor.d.ts +67 -0
- package/dist/test-executor.js +311 -0
- package/dist/test-executor.js.map +7 -0
- package/dist/tls-fingerprint.d.ts +50 -0
- package/dist/tls-fingerprint.js +81 -0
- package/dist/tls-fingerprint.js.map +7 -0
- package/dist/url-pattern-completer.d.ts +28 -0
- package/dist/url-pattern-completer.js +87 -0
- package/dist/url-pattern-completer.js.map +7 -0
- package/dist/visual-diff-verdict.d.ts +40 -0
- package/dist/visual-diff-verdict.js +25 -0
- package/dist/visual-diff-verdict.js.map +7 -0
- package/dist/webhook-notifier.d.ts +30 -0
- package/dist/webhook-notifier.js +76 -0
- package/dist/webhook-notifier.js.map +7 -0
- package/dist/websocket-detector.d.ts +24 -0
- package/dist/websocket-detector.js +60 -0
- package/dist/websocket-detector.js.map +7 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +33 -0
- package/dist/worker.js.map +7 -0
- package/package.json +45 -0
- package/src/accessibility-auditor.ts +102 -0
- package/src/ai-login.ts +218 -0
- package/src/auth-token-rotator.ts +89 -0
- package/src/auth.ts +396 -0
- package/src/browser-extension.ts +186 -0
- package/src/captcha-solver.ts +143 -0
- package/src/color-contrast.ts +116 -0
- package/src/content-chunker.ts +170 -0
- package/src/content-dedup.ts +99 -0
- package/src/cookie-consent.ts +106 -0
- package/src/cookie-jar.ts +91 -0
- package/src/crawler.ts +4305 -0
- package/src/custom-js-injector.ts +93 -0
- package/src/dark-mode-capture.ts +110 -0
- package/src/dead-link-detector.ts +76 -0
- package/src/element-hash.ts +16 -0
- package/src/email-otp.ts +252 -0
- package/src/engine-router.ts +141 -0
- package/src/export/bulk-export.ts +85 -0
- package/src/export/vector-export.ts +160 -0
- package/src/extractors/advanced.ts +283 -0
- package/src/extractors/artifact-envelope.ts +111 -0
- package/src/failure-analysis-agent.ts +49 -0
- package/src/feature-flag-detector.ts +97 -0
- package/src/form-detector.ts +103 -0
- package/src/frontier.test.ts +64 -0
- package/src/frontier.ts +112 -0
- package/src/gap-pass.ts +122 -0
- package/src/graphql-detector.ts +129 -0
- package/src/http-engine.ts +433 -0
- package/src/incremental-diff.ts +121 -0
- package/src/index.ts +35 -0
- package/src/input-fuzzer.ts +129 -0
- package/src/interactive-probe.ts +623 -0
- package/src/job-queue.test.ts +120 -0
- package/src/job-queue.ts +2701 -0
- package/src/js-coverage.ts +87 -0
- package/src/js-router-detector.ts +112 -0
- package/src/language-detector.ts +82 -0
- package/src/link-classifier.ts +65 -0
- package/src/live-view.ts +141 -0
- package/src/logger.ts +9 -0
- package/src/markdown-extract.test.ts +73 -0
- package/src/markdown-extract.ts +76 -0
- package/src/native-crawler.ts +1106 -0
- package/src/network-observer.ts +204 -0
- package/src/network-throttle.ts +69 -0
- package/src/openapi-generator.ts +135 -0
- package/src/pdf-extractor.ts +123 -0
- package/src/performance-metrics.ts +134 -0
- package/src/phash.ts +151 -0
- package/src/pii-scrubber.ts +99 -0
- package/src/playwright-recorder.ts +170 -0
- package/src/policies/crawl-safety.ts +46 -0
- package/src/profiles/domain-profile.ts +167 -0
- package/src/proxy.ts +238 -0
- package/src/rate-limiter.ts +87 -0
- package/src/redirect-tracker.ts +97 -0
- package/src/redis-frontier.ts +143 -0
- package/src/redis-queue.ts +208 -0
- package/src/response-cache.ts +150 -0
- package/src/responsive-detector.ts +92 -0
- package/src/retry-policy.ts +87 -0
- package/src/robots-txt.ts +96 -0
- package/src/screen-reader.ts +89 -0
- package/src/screenshot-masker.ts +98 -0
- package/src/seo-checker.ts +134 -0
- package/src/session-capture.ts +325 -0
- package/src/session-export.test.ts +75 -0
- package/src/session-export.ts +172 -0
- package/src/sitemap-writer.ts +65 -0
- package/src/sitemap.test.ts +131 -0
- package/src/sitemap.ts +224 -0
- package/src/skyvern.ts +199 -0
- package/src/sqs-queue.ts +49 -0
- package/src/sso-token.ts +120 -0
- package/src/stealth/human-behavior.ts +191 -0
- package/src/telemetry.ts +122 -0
- package/src/test-executor.test.ts +72 -0
- package/src/test-executor.ts +424 -0
- package/src/tls-fingerprint.ts +111 -0
- package/src/url-pattern-completer.ts +114 -0
- package/src/visual-diff-verdict.test.ts +80 -0
- package/src/visual-diff-verdict.ts +57 -0
- package/src/webhook-notifier.ts +109 -0
- package/src/websocket-detector.ts +83 -0
- package/src/worker.ts +48 -0
- package/tsconfig.json +13 -0
- package/types/accessibility-auditor.d.ts +29 -0
- package/types/ai-login.d.ts +32 -0
- package/types/auth-token-rotator.d.ts +47 -0
- package/types/auth.d.ts +20 -0
- package/types/browser-extension.d.ts +37 -0
- package/types/bull-worker.d.ts +6 -0
- package/types/captcha-solver.d.ts +16 -0
- package/types/color-contrast.d.ts +30 -0
- package/types/content-chunker.d.ts +18 -0
- package/types/content-dedup.d.ts +23 -0
- package/types/cookie-consent.d.ts +25 -0
- package/types/cookie-jar.d.ts +20 -0
- package/types/crawler.d.ts +179 -0
- package/types/custom-js-injector.d.ts +42 -0
- package/types/dark-mode-capture.d.ts +23 -0
- package/types/dead-link-detector.d.ts +37 -0
- package/types/element-hash.d.ts +9 -0
- package/types/email-otp.d.ts +42 -0
- package/types/engine-router.d.ts +47 -0
- package/types/export/bulk-export.d.ts +26 -0
- package/types/export/vector-export.d.ts +76 -0
- package/types/extractors/advanced.d.ts +54 -0
- package/types/extractors/artifact-envelope.d.ts +63 -0
- package/types/failure-analysis-agent.d.ts +16 -0
- package/types/feature-flag-detector.d.ts +30 -0
- package/types/form-detector.d.ts +34 -0
- package/types/frontier.d.ts +32 -0
- package/types/gap-pass.d.ts +35 -0
- package/types/graphql-detector.d.ts +39 -0
- package/types/http-engine.d.ts +80 -0
- package/types/incremental-diff.d.ts +59 -0
- package/types/index.d.ts +35 -0
- package/types/input-fuzzer.d.ts +30 -0
- package/types/interactive-probe.d.ts +104 -0
- package/types/job-queue.d.ts +171 -0
- package/types/js-coverage.d.ts +29 -0
- package/types/js-router-detector.d.ts +17 -0
- package/types/language-detector.d.ts +22 -0
- package/types/link-classifier.d.ts +23 -0
- package/types/live-view.d.ts +36 -0
- package/types/logger.d.ts +2 -0
- package/types/markdown-extract.d.ts +8 -0
- package/types/native-crawler.d.ts +69 -0
- package/types/network-observer.d.ts +49 -0
- package/types/network-throttle.d.ts +25 -0
- package/types/openapi-generator.d.ts +49 -0
- package/types/pdf-extractor.d.ts +28 -0
- package/types/performance-metrics.d.ts +53 -0
- package/types/phash.d.ts +38 -0
- package/types/pii-scrubber.d.ts +21 -0
- package/types/playwright-recorder.d.ts +39 -0
- package/types/policies/crawl-safety.d.ts +9 -0
- package/types/profiles/domain-profile.d.ts +19 -0
- package/types/proxy.d.ts +50 -0
- package/types/rate-limiter.d.ts +31 -0
- package/types/redirect-tracker.d.ts +37 -0
- package/types/redis-frontier.d.ts +48 -0
- package/types/redis-queue.d.ts +48 -0
- package/types/response-cache.d.ts +38 -0
- package/types/responsive-detector.d.ts +29 -0
- package/types/retry-policy.d.ts +20 -0
- package/types/robots-txt.d.ts +9 -0
- package/types/screen-reader.d.ts +16 -0
- package/types/screenshot-masker.d.ts +28 -0
- package/types/seo-checker.d.ts +33 -0
- package/types/session-capture.d.ts +38 -0
- package/types/session-export.d.ts +49 -0
- package/types/sitemap-writer.d.ts +21 -0
- package/types/sitemap.d.ts +51 -0
- package/types/skyvern.d.ts +56 -0
- package/types/sqs-queue.d.ts +2 -0
- package/types/sso-token.d.ts +29 -0
- package/types/stealth/human-behavior.d.ts +20 -0
- package/types/telemetry.d.ts +34 -0
- package/types/test-executor.d.ts +67 -0
- package/types/tls-fingerprint.d.ts +50 -0
- package/types/url-pattern-completer.d.ts +28 -0
- package/types/visual-diff-verdict.d.ts +40 -0
- package/types/webhook-notifier.d.ts +30 -0
- package/types/websocket-detector.d.ts +24 -0
- package/types/worker.d.ts +1 -0
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive Probe — Phase 2 Dynamic Observation
|
|
3
|
+
*
|
|
4
|
+
* The static crawl captures DOM structure at rest. This module runs AFTER the static crawl
|
|
5
|
+
* to observe dynamic behaviour by actually interacting with the UI:
|
|
6
|
+
*
|
|
7
|
+
* 1. Empty submit → captures required-field validation error messages
|
|
8
|
+
* 2. Invalid format → captures format validation errors (bad email, short password)
|
|
9
|
+
* 3. Button clicks → captures modal/dialog contents
|
|
10
|
+
* 4. Select changes → captures conditional reveals (show/hide logic)
|
|
11
|
+
* 5. Success paths → captures toast/banner messages (where input is safe)
|
|
12
|
+
*
|
|
13
|
+
* Results are stored as KnowledgeChunks (sourceType='probe') and update the
|
|
14
|
+
* ERROR_CATALOGUE + INTERACTION_PATTERNS skill files with real observed data
|
|
15
|
+
* instead of LLM inference.
|
|
16
|
+
*
|
|
17
|
+
* Call signature: probeScreen(page, screenId, elements, opts)
|
|
18
|
+
* Called from crawlProject() after static element extraction when opts.interactive=true.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type { Page } from 'playwright';
|
|
22
|
+
import { AppBrain } from '@detiq/app-brain';
|
|
23
|
+
|
|
24
|
+
export interface ProbeElementFact {
|
|
25
|
+
meaning: string;
|
|
26
|
+
role: string;
|
|
27
|
+
expectedData?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ValidationError {
|
|
31
|
+
field: string;
|
|
32
|
+
trigger: 'empty_submit' | 'invalid_format' | 'boundary';
|
|
33
|
+
errorText: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface SuccessMessage {
|
|
37
|
+
type: 'toast' | 'inline_success' | 'redirect';
|
|
38
|
+
content: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ModalObservation {
|
|
42
|
+
triggerElement: string;
|
|
43
|
+
title: string;
|
|
44
|
+
content: string;
|
|
45
|
+
fields: string[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ConditionalReveal {
|
|
49
|
+
triggerElement: string;
|
|
50
|
+
triggerValue: string;
|
|
51
|
+
revealedText: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ProbeResult {
|
|
55
|
+
screenId: string;
|
|
56
|
+
url: string;
|
|
57
|
+
validationErrors: ValidationError[];
|
|
58
|
+
successMessages: SuccessMessage[];
|
|
59
|
+
modals: ModalObservation[];
|
|
60
|
+
conditionals: ConditionalReveal[];
|
|
61
|
+
loadingPatterns: string[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ── CSS selectors that reliably find error messages across frameworks ────────
|
|
65
|
+
const ERROR_SELECTORS = [
|
|
66
|
+
'[role="alert"]',
|
|
67
|
+
'[aria-live="assertive"]',
|
|
68
|
+
'[aria-live="polite"]',
|
|
69
|
+
'.invalid-feedback',
|
|
70
|
+
'.field-error',
|
|
71
|
+
'.error-message',
|
|
72
|
+
'.form-error',
|
|
73
|
+
'.validation-error',
|
|
74
|
+
'[class*="error" i]',
|
|
75
|
+
'[class*="invalid" i]',
|
|
76
|
+
'[class*="Error"]',
|
|
77
|
+
'p.text-red-500', 'p.text-red-600', 'p.text-destructive', 'p.text-danger',
|
|
78
|
+
'[data-error]', '[data-invalid]',
|
|
79
|
+
'.ant-form-item-explain-error', // Ant Design
|
|
80
|
+
'.el-form-item__error', // Element UI
|
|
81
|
+
'.chakra-form__error-message', // Chakra UI
|
|
82
|
+
'.mantine-InputWrapper-error', // Mantine
|
|
83
|
+
].join(', ');
|
|
84
|
+
|
|
85
|
+
// ── Toast / notification selectors ───────────────────────────────────────────
|
|
86
|
+
const TOAST_SELECTORS = [
|
|
87
|
+
'[role="status"]',
|
|
88
|
+
'[data-sonner-toast]',
|
|
89
|
+
'[data-toast]',
|
|
90
|
+
'[data-hot-toast]',
|
|
91
|
+
'.Toastify__toast',
|
|
92
|
+
'.toast-message',
|
|
93
|
+
'.notification-body',
|
|
94
|
+
'.notistack-snackbar',
|
|
95
|
+
'[class*="toast" i]',
|
|
96
|
+
'[class*="Toast"]',
|
|
97
|
+
'[class*="snackbar" i]',
|
|
98
|
+
'[class*="notification" i]',
|
|
99
|
+
].join(', ');
|
|
100
|
+
|
|
101
|
+
/** Wait up to `maxMs` for any selector to appear, then return its text content. */
|
|
102
|
+
async function waitForAny(page: Page, selector: string, maxMs = 2500): Promise<string[]> {
|
|
103
|
+
try {
|
|
104
|
+
await page.waitForSelector(selector, { timeout: maxMs, state: 'visible' });
|
|
105
|
+
} catch { return []; }
|
|
106
|
+
return page.$$eval(selector, (els) =>
|
|
107
|
+
els.map((el) => (el as HTMLElement).innerText?.replace(/\s+/g, ' ').trim()).filter(Boolean)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Collect all currently-visible error messages. */
|
|
112
|
+
async function collectErrors(page: Page): Promise<string[]> {
|
|
113
|
+
try {
|
|
114
|
+
return page.$$eval(ERROR_SELECTORS, (els) =>
|
|
115
|
+
els
|
|
116
|
+
.filter((el) => {
|
|
117
|
+
const style = window.getComputedStyle(el);
|
|
118
|
+
return style.display !== 'none' && style.visibility !== 'hidden' && (el as HTMLElement).innerText?.trim().length > 0;
|
|
119
|
+
})
|
|
120
|
+
.map((el) => (el as HTMLElement).innerText?.replace(/\s+/g, ' ').trim())
|
|
121
|
+
.filter(Boolean)
|
|
122
|
+
);
|
|
123
|
+
} catch { return []; }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Collect any visible toast / notification content. */
|
|
127
|
+
async function collectToasts(page: Page): Promise<string[]> {
|
|
128
|
+
try {
|
|
129
|
+
return page.$$eval(TOAST_SELECTORS, (els) =>
|
|
130
|
+
els
|
|
131
|
+
.filter((el) => {
|
|
132
|
+
const style = window.getComputedStyle(el);
|
|
133
|
+
return style.display !== 'none' && (el as HTMLElement).innerText?.trim().length > 0;
|
|
134
|
+
})
|
|
135
|
+
.map((el) => (el as HTMLElement).innerText?.replace(/\s+/g, ' ').trim())
|
|
136
|
+
.filter(Boolean)
|
|
137
|
+
);
|
|
138
|
+
} catch { return []; }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Find the primary submit button on the page. */
|
|
142
|
+
async function findSubmitButton(page: Page): Promise<string | null> {
|
|
143
|
+
return page.evaluate(() => {
|
|
144
|
+
const SUBMIT_KW = /submit|send|save|create|confirm|continue|proceed|register|sign.?in|log.?in|apply|verify|search|next|finish|complete|order|buy|checkout/i;
|
|
145
|
+
const candidates = Array.from(document.querySelectorAll('button, [role="button"], input[type="submit"]')) as HTMLElement[];
|
|
146
|
+
const primary = candidates.find((el) => {
|
|
147
|
+
const style = window.getComputedStyle(el);
|
|
148
|
+
if (style.display === 'none' || style.visibility === 'hidden') return false;
|
|
149
|
+
const text = el.innerText || (el as HTMLInputElement).value || el.getAttribute('aria-label') || '';
|
|
150
|
+
return SUBMIT_KW.test(text);
|
|
151
|
+
});
|
|
152
|
+
if (!primary) return null;
|
|
153
|
+
return primary.getAttribute('data-testid') || primary.getAttribute('aria-label') || primary.innerText?.trim().slice(0, 60);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Find all modal-trigger buttons (non-submit buttons). */
|
|
158
|
+
async function findModalTriggers(page: Page): Promise<Array<{ selector: string; label: string }>> {
|
|
159
|
+
return page.evaluate(() => {
|
|
160
|
+
const SKIP = /submit|send|save|create|log.?in|sign.?in|register|continue|checkout|buy|order|search|close|cancel|dismiss/i;
|
|
161
|
+
const NAV_PARENTS = new Set(['NAV', 'HEADER', 'FOOTER']);
|
|
162
|
+
return Array.from(document.querySelectorAll('button, [role="button"]'))
|
|
163
|
+
.filter((el) => {
|
|
164
|
+
const style = window.getComputedStyle(el as HTMLElement);
|
|
165
|
+
if (style.display === 'none' || style.visibility === 'hidden') return false;
|
|
166
|
+
const label = (el as HTMLElement).innerText?.trim() || el.getAttribute('aria-label') || '';
|
|
167
|
+
if (!label || SKIP.test(label)) return false;
|
|
168
|
+
// Skip nav chrome
|
|
169
|
+
let p = el.parentElement;
|
|
170
|
+
while (p) { if (NAV_PARENTS.has(p.tagName)) return false; p = p.parentElement; }
|
|
171
|
+
return true;
|
|
172
|
+
})
|
|
173
|
+
.slice(0, 8) // probe at most 8 buttons per screen to keep it fast
|
|
174
|
+
.map((el) => {
|
|
175
|
+
const label = (el as HTMLElement).innerText?.trim() || el.getAttribute('aria-label') || 'button';
|
|
176
|
+
return { selector: `[aria-label="${label}"]`, label: label.slice(0, 60) };
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Try to interact with select elements and observe conditional reveals. */
|
|
182
|
+
async function probeConditionals(page: Page): Promise<ConditionalReveal[]> {
|
|
183
|
+
const results: ConditionalReveal[] = [];
|
|
184
|
+
try {
|
|
185
|
+
const selects = await page.$$('select');
|
|
186
|
+
for (const sel of selects.slice(0, 5)) {
|
|
187
|
+
const label = await sel.getAttribute('aria-label') || await sel.getAttribute('name') || 'select';
|
|
188
|
+
const options = await sel.$$eval('option', (opts) => opts.slice(1, 3).map((o) => ({ value: o.value, text: o.textContent?.trim() })));
|
|
189
|
+
for (const opt of options) {
|
|
190
|
+
if (!opt.value) continue;
|
|
191
|
+
const domBefore = await page.evaluate(() => document.body.innerText.length);
|
|
192
|
+
await sel.selectOption(opt.value);
|
|
193
|
+
await page.waitForTimeout(500);
|
|
194
|
+
const domAfter = await page.evaluate(() => document.body.innerText.length);
|
|
195
|
+
if (Math.abs(domAfter - domBefore) > 50) {
|
|
196
|
+
const revealed = await page.evaluate(() => {
|
|
197
|
+
// Grab text from any newly-visible sections
|
|
198
|
+
return Array.from(document.querySelectorAll('[data-conditional],[data-show],[class*="conditional"]'))
|
|
199
|
+
.filter((el) => window.getComputedStyle(el).display !== 'none')
|
|
200
|
+
.map((el) => (el as HTMLElement).innerText?.trim())
|
|
201
|
+
.filter((t) => t && t.length > 10)
|
|
202
|
+
.slice(0, 3)
|
|
203
|
+
.join(' | ');
|
|
204
|
+
});
|
|
205
|
+
if (revealed) {
|
|
206
|
+
results.push({ triggerElement: label, triggerValue: opt.text || opt.value, revealedText: revealed.slice(0, 200) });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
} catch { /* non-fatal */ }
|
|
212
|
+
return results;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Run interactive probing on a single screen page.
|
|
217
|
+
* The page must already be navigated to the screen URL.
|
|
218
|
+
* `elements` is the output of the static extractElements pass.
|
|
219
|
+
*/
|
|
220
|
+
export async function probeScreen(
|
|
221
|
+
page: Page,
|
|
222
|
+
screenId: string,
|
|
223
|
+
url: string,
|
|
224
|
+
elements: ProbeElementFact[],
|
|
225
|
+
): Promise<ProbeResult> {
|
|
226
|
+
const result: ProbeResult = {
|
|
227
|
+
screenId, url,
|
|
228
|
+
validationErrors: [], successMessages: [], modals: [], conditionals: [], loadingPatterns: [],
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const formInputs = elements.filter((e) =>
|
|
232
|
+
/input|text|email|password|tel|search|textarea|select/i.test(e.role)
|
|
233
|
+
);
|
|
234
|
+
const hasForm = formInputs.length > 0;
|
|
235
|
+
|
|
236
|
+
// ── Probe 1: Empty submit → capture required-field errors ────────────────────
|
|
237
|
+
if (hasForm) {
|
|
238
|
+
try {
|
|
239
|
+
const submitLabel = await findSubmitButton(page);
|
|
240
|
+
if (submitLabel) {
|
|
241
|
+
// Click submit with no data filled in
|
|
242
|
+
const submitBtn = page.locator(`button:has-text("${submitLabel}")`).first();
|
|
243
|
+
await submitBtn.click({ timeout: 2000 });
|
|
244
|
+
await page.waitForTimeout(1500);
|
|
245
|
+
|
|
246
|
+
const errors = await collectErrors(page);
|
|
247
|
+
for (const errorText of errors) {
|
|
248
|
+
// Try to match error back to a field
|
|
249
|
+
const matchedField = formInputs.find((el) =>
|
|
250
|
+
errorText.toLowerCase().includes(el.meaning.toLowerCase().split(' ')[0]) ||
|
|
251
|
+
el.meaning.toLowerCase().includes(errorText.toLowerCase().split(' ')[0])
|
|
252
|
+
);
|
|
253
|
+
result.validationErrors.push({
|
|
254
|
+
field: matchedField?.meaning ?? 'unknown',
|
|
255
|
+
trigger: 'empty_submit',
|
|
256
|
+
errorText: errorText.slice(0, 150),
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Check for loading state text during submit
|
|
261
|
+
const loadingText = await page.evaluate(() => {
|
|
262
|
+
const loading = Array.from(document.querySelectorAll('button, [aria-busy="true"], [class*="loading" i], [class*="spinner" i]'))
|
|
263
|
+
.map((el) => (el as HTMLElement).innerText?.trim())
|
|
264
|
+
.filter((t) => t && /loading|saving|submitting|sending|processing/i.test(t));
|
|
265
|
+
return loading.slice(0, 3);
|
|
266
|
+
});
|
|
267
|
+
result.loadingPatterns.push(...loadingText);
|
|
268
|
+
}
|
|
269
|
+
} catch { /* non-fatal — form probe failed, continue */ }
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ── Probe 2: Invalid format inputs ──────────────────────────────────────────
|
|
273
|
+
if (hasForm) {
|
|
274
|
+
try {
|
|
275
|
+
const emailField = formInputs.find((e) => e.expectedData === 'valid_email' || /email/i.test(e.meaning));
|
|
276
|
+
const passwordField = formInputs.find((e) => e.expectedData === 'password' || /password/i.test(e.meaning));
|
|
277
|
+
|
|
278
|
+
if (emailField) {
|
|
279
|
+
const emailLocator = page.locator('input[type="email"], input[name*="email"], input[placeholder*="email" i]').first();
|
|
280
|
+
try {
|
|
281
|
+
await emailLocator.fill('notanemail', { timeout: 1000 });
|
|
282
|
+
await emailLocator.blur();
|
|
283
|
+
await page.waitForTimeout(600);
|
|
284
|
+
const errors = await collectErrors(page);
|
|
285
|
+
for (const errorText of errors) {
|
|
286
|
+
result.validationErrors.push({ field: emailField.meaning, trigger: 'invalid_format', errorText: errorText.slice(0, 150) });
|
|
287
|
+
}
|
|
288
|
+
} catch { /* locator not found */ }
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (passwordField) {
|
|
292
|
+
const pwLocator = page.locator('input[type="password"]').first();
|
|
293
|
+
try {
|
|
294
|
+
await pwLocator.fill('123', { timeout: 1000 });
|
|
295
|
+
await pwLocator.blur();
|
|
296
|
+
await page.waitForTimeout(600);
|
|
297
|
+
const errors = await collectErrors(page);
|
|
298
|
+
for (const errorText of errors) {
|
|
299
|
+
if (!result.validationErrors.some((e) => e.errorText === errorText)) {
|
|
300
|
+
result.validationErrors.push({ field: passwordField.meaning, trigger: 'invalid_format', errorText: errorText.slice(0, 150) });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
} catch { /* locator not found */ }
|
|
304
|
+
}
|
|
305
|
+
} catch { /* non-fatal */ }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// ── Probe 3: Button clicks → discover modal/dialog contents ─────────────────
|
|
309
|
+
try {
|
|
310
|
+
const triggers = await findModalTriggers(page);
|
|
311
|
+
for (const trigger of triggers) {
|
|
312
|
+
try {
|
|
313
|
+
const btn = page.locator(`button:has-text("${trigger.label}")`).first();
|
|
314
|
+
const domBefore = await page.evaluate(() => document.body.innerText.length);
|
|
315
|
+
|
|
316
|
+
await btn.click({ timeout: 1500 });
|
|
317
|
+
await page.waitForTimeout(1000);
|
|
318
|
+
|
|
319
|
+
// Check if a dialog/modal appeared
|
|
320
|
+
const dialogText = await page.evaluate(() => {
|
|
321
|
+
const DIALOG_SEL = '[role="dialog"], [role="alertdialog"], .modal, .Modal, [class*="modal" i], [class*="dialog" i], [class*="Dialog"]';
|
|
322
|
+
const dialogs = Array.from(document.querySelectorAll(DIALOG_SEL))
|
|
323
|
+
.filter((el) => window.getComputedStyle(el).display !== 'none');
|
|
324
|
+
if (dialogs.length === 0) return null;
|
|
325
|
+
const d = dialogs[0] as HTMLElement;
|
|
326
|
+
const title = d.querySelector('[role="heading"], h1, h2, h3')?.textContent?.trim() || '';
|
|
327
|
+
const content = d.innerText?.replace(/\s+/g, ' ').trim().slice(0, 400);
|
|
328
|
+
const fields = Array.from(d.querySelectorAll('input, select, textarea, button'))
|
|
329
|
+
.map((f) => (f as HTMLElement).getAttribute('aria-label') || (f as HTMLElement).getAttribute('placeholder') || (f as HTMLInputElement).value || '')
|
|
330
|
+
.filter((t) => t.trim().length > 0);
|
|
331
|
+
return { title, content, fields };
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
if (dialogText && dialogText.content.length > 20) {
|
|
335
|
+
result.modals.push({
|
|
336
|
+
triggerElement: trigger.label,
|
|
337
|
+
title: dialogText.title,
|
|
338
|
+
content: dialogText.content,
|
|
339
|
+
fields: dialogText.fields.slice(0, 10),
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Dismiss: Escape key first, then close button
|
|
344
|
+
await page.keyboard.press('Escape');
|
|
345
|
+
await page.waitForTimeout(400);
|
|
346
|
+
|
|
347
|
+
// Check if toast appeared after the click
|
|
348
|
+
const toasts = await collectToasts(page);
|
|
349
|
+
for (const t of toasts) {
|
|
350
|
+
if (t.length > 5) result.successMessages.push({ type: 'toast', content: t.slice(0, 200) });
|
|
351
|
+
}
|
|
352
|
+
} catch { /* this button's probe failed, try next */ }
|
|
353
|
+
}
|
|
354
|
+
} catch { /* non-fatal */ }
|
|
355
|
+
|
|
356
|
+
// ── Probe 4: Select/radio → conditional reveals ──────────────────────────────
|
|
357
|
+
try {
|
|
358
|
+
const conditionals = await probeConditionals(page);
|
|
359
|
+
result.conditionals.push(...conditionals);
|
|
360
|
+
} catch { /* non-fatal */ }
|
|
361
|
+
|
|
362
|
+
return result;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** Phase 5: Convert ProbeResult to typed ProbeObservationFact rows for direct DB storage. */
|
|
366
|
+
export function probeResultToObservations(result: ProbeResult): Array<{
|
|
367
|
+
elementMeaning: string; observationType: string; observedText: string; triggeredBy: string;
|
|
368
|
+
}> {
|
|
369
|
+
const obs: Array<{ elementMeaning: string; observationType: string; observedText: string; triggeredBy: string }> = [];
|
|
370
|
+
for (const ve of result.validationErrors) {
|
|
371
|
+
obs.push({ elementMeaning: ve.field, observationType: 'VALIDATION_ERROR', observedText: ve.errorText, triggeredBy: ve.trigger });
|
|
372
|
+
}
|
|
373
|
+
for (const sm of result.successMessages) {
|
|
374
|
+
obs.push({ elementMeaning: '(page)', observationType: 'SUCCESS_TOAST', observedText: sm.content, triggeredBy: sm.type });
|
|
375
|
+
}
|
|
376
|
+
for (const m of result.modals) {
|
|
377
|
+
obs.push({ elementMeaning: m.triggerElement, observationType: 'MODAL', observedText: [m.title, m.content].filter(Boolean).join(' — ').slice(0, 500), triggeredBy: `button_click:${m.triggerElement}` });
|
|
378
|
+
}
|
|
379
|
+
for (const c of result.conditionals) {
|
|
380
|
+
obs.push({ elementMeaning: c.triggerElement, observationType: 'CONDITIONAL_REVEAL', observedText: c.revealedText, triggeredBy: `select_change:${c.triggerElement}:${c.triggerValue}` });
|
|
381
|
+
}
|
|
382
|
+
for (const lp of result.loadingPatterns) {
|
|
383
|
+
obs.push({ elementMeaning: '(submit button)', observationType: 'LOADING_STATE', observedText: lp, triggeredBy: 'form_submit' });
|
|
384
|
+
}
|
|
385
|
+
return obs;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Convert a ProbeResult into markdown to store as KnowledgeChunks
|
|
390
|
+
* and update ERROR_CATALOGUE + INTERACTION_PATTERNS skill files.
|
|
391
|
+
*/
|
|
392
|
+
export function probeResultToMarkdown(result: ProbeResult): {
|
|
393
|
+
errorCatalogueChunk: string;
|
|
394
|
+
interactionPatternsChunk: string;
|
|
395
|
+
} {
|
|
396
|
+
const lines: string[] = [`## Probe Observations — ${result.url}\n`];
|
|
397
|
+
|
|
398
|
+
if (result.validationErrors.length > 0) {
|
|
399
|
+
lines.push('### Validation Errors (observed)');
|
|
400
|
+
for (const ve of result.validationErrors) {
|
|
401
|
+
lines.push(`- **${ve.field}** (${ve.trigger}): "${ve.errorText}"`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (result.successMessages.length > 0) {
|
|
406
|
+
lines.push('\n### Success / Feedback Messages (observed)');
|
|
407
|
+
for (const sm of result.successMessages) {
|
|
408
|
+
lines.push(`- ${sm.type}: "${sm.content}"`);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (result.modals.length > 0) {
|
|
413
|
+
lines.push('\n### Modal / Dialog Contents (observed)');
|
|
414
|
+
for (const m of result.modals) {
|
|
415
|
+
lines.push(`- **Trigger:** ${m.triggerElement}`);
|
|
416
|
+
if (m.title) lines.push(` - Title: ${m.title}`);
|
|
417
|
+
lines.push(` - Content: ${m.content.slice(0, 200)}`);
|
|
418
|
+
if (m.fields.length > 0) lines.push(` - Fields: ${m.fields.join(', ')}`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (result.conditionals.length > 0) {
|
|
423
|
+
lines.push('\n### Conditional UI (observed)');
|
|
424
|
+
for (const c of result.conditionals) {
|
|
425
|
+
lines.push(`- **${c.triggerElement}** = "${c.triggerValue}" reveals: ${c.revealedText}`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (result.loadingPatterns.length > 0) {
|
|
430
|
+
lines.push('\n### Loading State Text (observed)');
|
|
431
|
+
for (const lp of result.loadingPatterns) lines.push(`- "${lp}"`);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const full = lines.join('\n');
|
|
435
|
+
|
|
436
|
+
const errorSection = result.validationErrors.length > 0
|
|
437
|
+
? `## Real Validation Errors — ${result.url}\n` +
|
|
438
|
+
result.validationErrors.map((e) => `- **${e.field}**: "${e.errorText}"`).join('\n')
|
|
439
|
+
: '';
|
|
440
|
+
|
|
441
|
+
const interactionSection = [
|
|
442
|
+
result.successMessages.length > 0
|
|
443
|
+
? `## Success Messages — ${result.url}\n` + result.successMessages.map((s) => `- ${s.type}: "${s.content}"`).join('\n')
|
|
444
|
+
: '',
|
|
445
|
+
result.loadingPatterns.length > 0
|
|
446
|
+
? `## Loading Patterns — ${result.url}\n` + result.loadingPatterns.map((lp) => `- "${lp}"`).join('\n')
|
|
447
|
+
: '',
|
|
448
|
+
result.modals.length > 0
|
|
449
|
+
? `## Modal Contents — ${result.url}\n` + result.modals.map((m) => `### ${m.triggerElement}\n${m.content}`).join('\n')
|
|
450
|
+
: '',
|
|
451
|
+
].filter(Boolean).join('\n\n');
|
|
452
|
+
|
|
453
|
+
return {
|
|
454
|
+
errorCatalogueChunk: errorSection,
|
|
455
|
+
interactionPatternsChunk: interactionSection,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Run interactive probing for all screens discovered in a crawl session.
|
|
461
|
+
* Called from crawlProject() when opts.interactive = true.
|
|
462
|
+
*/
|
|
463
|
+
export async function probeAllScreens(
|
|
464
|
+
page: any,
|
|
465
|
+
tenantId: string,
|
|
466
|
+
projectId: string,
|
|
467
|
+
discovered: Array<{ url: string; screenId?: string; elements?: any[] }>,
|
|
468
|
+
onProgress?: (pct: number, step: string) => Promise<void>,
|
|
469
|
+
): Promise<void> {
|
|
470
|
+
const probeable = discovered.filter((d) => d.screenId && d.url && !d.url.includes('#'));
|
|
471
|
+
if (probeable.length === 0) return;
|
|
472
|
+
|
|
473
|
+
const errorCatalogueChunks: string[] = [];
|
|
474
|
+
const interactionChunks: string[] = [];
|
|
475
|
+
|
|
476
|
+
for (let i = 0; i < probeable.length; i++) {
|
|
477
|
+
const screen = probeable[i];
|
|
478
|
+
const pct = 88 + Math.round((i / probeable.length) * 10);
|
|
479
|
+
await onProgress?.(pct, `Probing screen ${i + 1}/${probeable.length}: ${screen.url}`);
|
|
480
|
+
|
|
481
|
+
try {
|
|
482
|
+
// Navigate to screen
|
|
483
|
+
if (page.url() !== screen.url) {
|
|
484
|
+
await page.goto(screen.url, { waitUntil: 'domcontentloaded' });
|
|
485
|
+
await page.waitForTimeout(1500); // SPA hydration
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const result = await probeScreen(page, screen.screenId!, screen.url, screen.elements ?? []);
|
|
489
|
+
|
|
490
|
+
// Phase 5: save structured probe observations (replaces per-re-probe)
|
|
491
|
+
const observations = probeResultToObservations(result);
|
|
492
|
+
if (observations.length > 0) {
|
|
493
|
+
await AppBrain.saveProbeObservations(tenantId, projectId, screen.screenId!, observations).catch(console.warn);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Store raw probe result as KnowledgeChunk (kept for BM25 / oversized projects)
|
|
497
|
+
const md = probeResultToMarkdown(result);
|
|
498
|
+
if (md.errorCatalogueChunk) errorCatalogueChunks.push(md.errorCatalogueChunk);
|
|
499
|
+
if (md.interactionPatternsChunk) interactionChunks.push(md.interactionPatternsChunk);
|
|
500
|
+
|
|
501
|
+
const probeMarkdown = [md.errorCatalogueChunk, md.interactionPatternsChunk].filter(Boolean).join('\n\n');
|
|
502
|
+
if (probeMarkdown.length > 50) {
|
|
503
|
+
await AppBrain.saveKnowledgeChunk(tenantId, projectId, 'probe', screen.screenId!, probeMarkdown, `Probe — ${screen.url}`).catch(console.warn);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (result.validationErrors.length > 0) {
|
|
507
|
+
console.log(`[probe] ${screen.url}: ${result.validationErrors.length} validation errors, ${result.modals.length} modals`);
|
|
508
|
+
}
|
|
509
|
+
} catch (err) {
|
|
510
|
+
console.warn(`[probe] ✗ ${screen.url}:`, err instanceof Error ? err.message : err);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// Update ERROR_CATALOGUE skill file with all real observed errors
|
|
515
|
+
if (errorCatalogueChunks.length > 0) {
|
|
516
|
+
const combined = `# Error Catalogue (Real Observed — Interactive Probe)\n\n${errorCatalogueChunks.join('\n\n')}`;
|
|
517
|
+
await AppBrain.upsertSkillFile(tenantId, projectId, 'ERROR_CATALOGUE', combined, {
|
|
518
|
+
summary: `Real validation error messages observed via interactive probe across ${errorCatalogueChunks.length} screens`,
|
|
519
|
+
scope: 'PROJECT',
|
|
520
|
+
}).catch(console.warn);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// Update INTERACTION_PATTERNS skill file with real observed patterns
|
|
524
|
+
if (interactionChunks.length > 0) {
|
|
525
|
+
const combined = `# Interaction Patterns (Real Observed — Interactive Probe)\n\n${interactionChunks.join('\n\n')}`;
|
|
526
|
+
await AppBrain.upsertSkillFile(tenantId, projectId, 'INTERACTION_PATTERNS', combined, {
|
|
527
|
+
summary: `Real loading states, success messages, and modal contents observed via interactive probe`,
|
|
528
|
+
scope: 'PROJECT',
|
|
529
|
+
}).catch(console.warn);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
await onProgress?.(98, 'Interactive probe complete');
|
|
533
|
+
console.log(`[probe] Probed ${probeable.length} screens. Errors: ${errorCatalogueChunks.length}, Interactions: ${interactionChunks.length}`);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// ── Keyboard Navigation Probe ────────────────────────────────────────────────
|
|
537
|
+
|
|
538
|
+
export interface FocusableElement {
|
|
539
|
+
tag: string;
|
|
540
|
+
role: string | null;
|
|
541
|
+
ariaLabel: string | null;
|
|
542
|
+
text: string | null;
|
|
543
|
+
hasFocusIndicator: boolean;
|
|
544
|
+
tabIndex: number | null;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
export interface KeyboardNavResult {
|
|
548
|
+
focusableCount: number;
|
|
549
|
+
elementsWithNoFocusIndicator: number;
|
|
550
|
+
sequence: FocusableElement[];
|
|
551
|
+
issues: string[];
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Probe keyboard navigation accessibility by pressing Tab up to 50 times and
|
|
556
|
+
* recording each focused element's properties and focus-indicator visibility.
|
|
557
|
+
* Stops early if focus wraps back to the start or hits the same element twice.
|
|
558
|
+
*/
|
|
559
|
+
export async function probeKeyboardNav(page: Page): Promise<KeyboardNavResult> {
|
|
560
|
+
const sequence: FocusableElement[] = [];
|
|
561
|
+
const issues: string[] = [];
|
|
562
|
+
const seenKeys = new Set<string>();
|
|
563
|
+
let firstKey: string | null = null;
|
|
564
|
+
|
|
565
|
+
for (let i = 0; i < 50; i++) {
|
|
566
|
+
await page.keyboard.press('Tab');
|
|
567
|
+
|
|
568
|
+
const el = await page.evaluate(() => {
|
|
569
|
+
const active = document.activeElement as HTMLElement | null;
|
|
570
|
+
if (!active || active === document.body) return null;
|
|
571
|
+
const outline = window.getComputedStyle(active).outline;
|
|
572
|
+
return {
|
|
573
|
+
tag: active.tagName.toLowerCase(),
|
|
574
|
+
role: active.getAttribute('role'),
|
|
575
|
+
ariaLabel: active.getAttribute('aria-label'),
|
|
576
|
+
text: (active.innerText ?? '').trim().slice(0, 60) || null,
|
|
577
|
+
outline,
|
|
578
|
+
tabIndex: active.tabIndex ?? null,
|
|
579
|
+
};
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
if (!el) break;
|
|
583
|
+
|
|
584
|
+
const hasFocusIndicator =
|
|
585
|
+
el.outline !== 'none' &&
|
|
586
|
+
el.outline !== '' &&
|
|
587
|
+
!el.outline.startsWith('0px') &&
|
|
588
|
+
!el.outline.startsWith('rgba(0, 0, 0, 0)') &&
|
|
589
|
+
!el.outline.startsWith('rgba(0,0,0,0)');
|
|
590
|
+
|
|
591
|
+
const focusable: FocusableElement = {
|
|
592
|
+
tag: el.tag,
|
|
593
|
+
role: el.role,
|
|
594
|
+
ariaLabel: el.ariaLabel,
|
|
595
|
+
text: el.text,
|
|
596
|
+
hasFocusIndicator,
|
|
597
|
+
tabIndex: el.tabIndex,
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
const key = `${el.tag}|${el.text ?? ''}|${el.role ?? ''}`;
|
|
601
|
+
|
|
602
|
+
if (i === 0) {
|
|
603
|
+
firstKey = key;
|
|
604
|
+
} else if (key === firstKey || seenKeys.has(key)) {
|
|
605
|
+
// Focus wrapped back to start or hit a duplicate — stop probing
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
seenKeys.add(key);
|
|
610
|
+
sequence.push(focusable);
|
|
611
|
+
|
|
612
|
+
if (!hasFocusIndicator) {
|
|
613
|
+
issues.push(`Element #${i + 1} (${el.tag}) has no visible focus indicator`);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
return {
|
|
618
|
+
focusableCount: sequence.length,
|
|
619
|
+
elementsWithNoFocusIndicator: issues.length,
|
|
620
|
+
sequence,
|
|
621
|
+
issues,
|
|
622
|
+
};
|
|
623
|
+
}
|