Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Keep an Ask answer while the person uses the page

Claude4faddc70ee00
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee94cbfad..74bb1f6d3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ This changelog was generated from the repository Git history and release tags. V
## [Unreleased]
### Fixed
+- Ask mode: an answer being written no longer disappears and starts over when you use the page meanwhile. In a WhatsApp trace, typing a draft and clicking in the chat while the answer was written threw the answer away twice and wrote it again each time, and the answer that finally stayed, written after you stopped, was the shortest. Scrolling, selecting, clicking and typing on the page, and the page's changes from them, now leave the answer as it is: it is about the page as you asked about it. Navigating the page to another address still starts the answer over.
- Posting on another site after a correction: after a Mastodon post, "ok now on X" no longer leaves WebBrain going back and forth between the two sites, typing the X post again each time. It counted X as the same platform as Mastodon, because it reads account names only on X and Bluesky, and asked to find the Mastodon post on X itself, which can never happen. The site a post was made on now names its platform when no account name was read, and a post on another site goes ahead once a page has been read since the correction, provided the task made no earlier post on that site. What the task attempted is saved with the conversation, and just before each action that may post or submit something, so this still holds when the task continues after WebBrain restarted, and a post already sent on X under the correction is not sent again by a later run of the task. When the task did post on that site before, or WebBrain has no full record of its earlier attempts, it stops once and says so, instead of searching for a post it cannot find. A search, a settings save or consent click on X, a click that sent nothing or a form the page rejected is not such a post; a click that Stop interrupted after it was sent counts. On the other hosts and clients of X and Bluesky, such as X Pro, whose Post buttons WebBrain does not recognize, anything sent that may have been a post counts as one, so a post from X Pro is not repeated on x.com; this includes a Post button whose caption no model read in time, which looked like a harmless button, while Enter in the post editor there edits the draft and is not a post. If that record cannot be saved just before a possible post on X or Bluesky, the post is not sent and WebBrain says why, as it already does when a run's recovery checkpoint cannot be saved. x.com and twitter.com are one platform.
- Chrome: a page's "Leave site?" prompt no longer waits for you when WebBrain navigates away during a task that started on a page the debugger cannot attach to, such as chrome://extensions, or whose debugger connection dropped. WebBrain arms its dialog handling again at the next debugger attach and around each of its own navigations, and answers Leave for its own navigation as it already did on other runs. If you cancel the debugger, prompts stay yours to answer. Firefox offers extensions no way to answer these prompts.
- Chat sites such as WhatsApp: a request that points at the open chat instead of naming the person, such as "send some test messages to this one" or "message this user", now sends there instead of asking "which contact, and what text?". The planner never sees the page, and its rules counted only words like "reply here" as the open chat, so it asked the same question every time without reading the page. WebBrain still reads the open chat's header itself and binds every send to that one contact, and stops if no single chat is open. The planner is also told it cannot see the page, no longer reads a note about a screenshot it is never given, and leaves the wording of described messages, such as test messages or a thank-you, to the agent. One request can now cover the open chat and someone named besides it, as in "test messages here, then thank Rustem Bey": the open chat needs no confirmation, the reviewed plan shows the named person, and that person is confirmed once on WebBrain's card before the first send to them. Words that refer back to someone named earlier still mean that person, and on mail sites the people named besides "reply here" are handled as before. On WhatsApp, where a contact is confirmed through its contact drawer, one run still confirms only one chat's contact, so the second chat of such a request needs a request of its own; the agent is now told so, instead of being sent to re-read the page and retry.
diff --git a/docs/architecture.md b/docs/architecture.md
index 5179dca8d..2e9cdc172 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -455,6 +455,14 @@ to the older full `processMessageStream()` loop. Attachments, detached-run
ownership, reconnect replay, persistence, traces, tool guards, and completion
invariants therefore keep one production lifecycle.
+An Ask answer is about the page as the person asked about it. What they do on
+the page while it is written (scrolling, selecting, clicking, typing, and the
+page's changes from those), and any scroll or viewport resize, does not make
+it stale: the answer already shown is kept and is not written again. A
+navigation of the page to another address, a new document, a correction, and
+the page's own changes are weighed as before, so a page-dependent answer still
+refreshes after automatic churn within its retry budget.
+
### Selected-text source scopes
Selected-text runs always carry an explicit, durable `source_grounding` policy.
diff --git a/package.json b/package.json
index 5dc8716de..9b26b5468 100644
--- a/package.json
+++ b/package.json
@@ -59,7 +59,7 @@
"benchmark:relevance": "node scripts/benchmark-offline-relevance.mjs --verbose",
"test:social-contract": "node --test test/social-publish-contract.mjs test/publication-quote-markup.mjs",
"test:social-contract:dom": "node test/social-publish-contract-dom.mjs",
- "test:runtime-lifecycle": "node test/bot-memory-dom.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/form-validation-alert-readings.mjs test/control-effect-readings.mjs test/trusted-retry-readings.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/chat-steering.mjs test/lifecycle-steering-restart.mjs test/resource-mutation-guards.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/release-publication-completion.mjs test/workflow-implicit-metadata.mjs test/workflow-field-readings.mjs test/workflow-field-anchors.mjs test/user-turn-kind.mjs test/completion-current-execution-evidence.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/lifecycle-terminal-done.mjs test/lifecycle-planner-digest.mjs test/lifecycle-vision-fallback.mjs test/guards-control-classification.mjs test/guards-unbound-deletion.mjs test/guards-steering-receipts.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/native-resource-deletion-binding.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/message-control-readings.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/ask-completion-churn-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/cloud-bot-memory-mv3.mjs && node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/upload-release-binding-mv3.mjs && node test/quality/release-review-world-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs && node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/unbound-deletion-mv3.mjs && node test/quality/recipient-clarify-mv3.mjs && node test/quality/open-chat-recipients-mv3.mjs && node test/quality/correction-cross-site-mv3.mjs && node test/quality/anchored-action-mv3.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs && node test/quality/steering-worker-restart-mv3.mjs",
+ "test:runtime-lifecycle": "node test/bot-memory-dom.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/form-validation-alert-readings.mjs test/control-effect-readings.mjs test/trusted-retry-readings.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/chat-steering.mjs test/lifecycle-steering-restart.mjs test/resource-mutation-guards.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/release-publication-completion.mjs test/workflow-implicit-metadata.mjs test/workflow-field-readings.mjs test/workflow-field-anchors.mjs test/user-turn-kind.mjs test/completion-current-execution-evidence.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/lifecycle-terminal-done.mjs test/lifecycle-planner-digest.mjs test/lifecycle-vision-fallback.mjs test/guards-control-classification.mjs test/guards-unbound-deletion.mjs test/guards-steering-receipts.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/native-resource-deletion-binding.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/message-control-readings.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/ask-completion-churn-mv3.mjs && node test/quality/ask-person-activity-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/cloud-bot-memory-mv3.mjs && node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/upload-release-binding-mv3.mjs && node test/quality/release-review-world-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs && node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/unbound-deletion-mv3.mjs && node test/quality/recipient-clarify-mv3.mjs && node test/quality/open-chat-recipients-mv3.mjs && node test/quality/correction-cross-site-mv3.mjs && node test/quality/anchored-action-mv3.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs && node test/quality/steering-worker-restart-mv3.mjs",
"test:page-feedback": "node --test test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/delivery-click-ax-response-loss.mjs test/delivery-stop-compound.mjs test/delivery-cdp-input.mjs test/delivery-click-locks.mjs test/delivery-native-button-geometry.mjs test/delivery-hover-transition.mjs test/delivery-dispatch-boundary.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs",
"test:chat-steering": "node --test test/chat-steering.mjs test/chat-steering-ui.mjs test/recipient-confirmation-ui.mjs test/lifecycle-steering-latency.mjs test/lifecycle-steering-restart.mjs test/lifecycle-run-ui.mjs test/lifecycle-menu-prompts-held.mjs",
"test:rich-text-dom": "node test/ui-content-lifecycle.mjs --dom",
@@ -93,7 +93,7 @@
"test:shard:quick": "npm run test:cms && npm run test:markdown && npm run test:generative-media && npm run test:systemone && npm run test:systemone:fast && node --test test/browser-dialogs.mjs test/capsolver-cloud-broker.mjs test/captcha-providers.mjs test/captcha-weighted-fallback.mjs test/captcha-hcaptcha-providers.mjs test/captcha-native-providers.mjs test/captcha-runtime-policy.mjs test/captcha-callback-bridge.mjs test/captcha-bridge-registration.mjs test/captcha-aws-recovery.mjs test/captcha-documented-contracts.mjs test/huggingface-signup-recovery.mjs test/trace-full-export.mjs test/feedback-traces.mjs && npm run test:firefox-bidi && npm run test:billing-notice && npm run test:compass-quota && npm run test:provider-limits && npm run test:provider-catalog && npm run test:provider-instances:ui && npm run test:openrouter-capabilities && npm run test:anthropic && npm run test:accessibility-tree-benchmark && npm run test:toolbar-guard && npm run test:cloud-bridge-approval && npm run test:discord && npm run test:pdf-read && npm run test:pdf-selection && npm run test:social-contract && npm run test:safesocial && npm run test:build-unpacked && npm run test:attachment-drop && npm run test:workflow-editor && node --test test/profile-sync-stats.mjs && node --test test/memcode-recall.mjs",
"test:shard:runtime-unit": "node --test test/skill-download-wait.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-click-guard.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/form-validation-alert-readings.mjs test/control-effect-readings.mjs test/trusted-retry-readings.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/chat-steering.mjs test/resource-mutation-guards.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/release-publication-completion.mjs test/workflow-implicit-metadata.mjs test/workflow-field-readings.mjs test/workflow-field-anchors.mjs test/user-turn-kind.mjs test/completion-current-execution-evidence.mjs test/video-upload-attachment.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/lifecycle-terminal-done.mjs test/lifecycle-planner-digest.mjs test/lifecycle-steering-latency.mjs test/lifecycle-steering-restart.mjs test/lifecycle-vision-fallback.mjs test/delivery-click-locks.mjs test/guards-steering-receipts.mjs test/terminal-user-messages.mjs",
"test:shard:browser-a": "node test/bot-memory-dom.mjs && node test/bot-memory-click-dom.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/native-button-preparation.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/page-monitor-ui.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/native-resource-deletion-binding.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/lifecycle-run-ui.mjs test/lifecycle-menu-prompts-held.mjs test/delivery-cdp-input.mjs test/delivery-click-ax-response-loss.mjs test/delivery-native-button-geometry.mjs test/delivery-hover-transition.mjs test/delivery-dispatch-boundary.mjs test/delivery-stop-compound.mjs test/guards-control-classification.mjs test/guards-unbound-deletion.mjs test/submit-probe-readings.mjs",
- "test:shard:browser-b1": "node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/message-control-readings.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/ask-completion-churn-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/cloud-bot-memory-mv3.mjs",
+ "test:shard:browser-b1": "node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/message-control-readings.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/ask-completion-churn-mv3.mjs && node test/quality/ask-person-activity-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/cloud-bot-memory-mv3.mjs",
"test:shard:browser-b2": "node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/upload-release-binding-mv3.mjs && node test/quality/release-review-world-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs && node test/quality/shared-action-guards-mv3.mjs && node test/quality/video-upload-attachment-mv3.mjs",
"test:shard:browser-c": "node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/unbound-deletion-mv3.mjs && node test/quality/recipient-clarify-mv3.mjs && node test/quality/open-chat-recipients-mv3.mjs && node test/quality/correction-cross-site-mv3.mjs && node test/quality/anchored-action-mv3.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs && node test/quality/steering-worker-restart-mv3.mjs",
"test:shard:tail": "node test/run.js && node test/selection-scope-restoration.mjs && node scripts/benchmark-offline-relevance.mjs && npm run test:security",
diff --git a/src/chrome/src/agent/page-feedback.js b/src/chrome/src/agent/page-feedback.js
index 17830cc81..c8c3315cc 100644
--- a/src/chrome/src/agent/page-feedback.js
+++ b/src/chrome/src/agent/page-feedback.js
@@ -25,11 +25,16 @@ const userIntervention = events => events.some(event => event?.source === 'user'
const UNKNOWN_ATTRIBUTION_LIMIT = 4;
const unknownAttribution = new WeakMap();
-// Viewing gestures (scroll, selection, pointer/key activity) cannot change the
-// content behind a read-only Ask answer. Clicks, input, navigation and DOM
-// changes they cause are reported separately and still invalidate it.
-const askRelevantFeedback = events => events.filter(event => !(event?.source === 'user'
- && ['scroll', 'selection', 'activity'].includes(event.kind)));
+// A read-only Ask answer is about the page as the person asked about it. What
+// they do there while it is being written (scrolling, selecting, clicking,
+// typing, and the page's changes from those), and any scroll or viewport
+// resize, cannot make it stale, so an answer already shown stays. Their
+// navigation of the page to another address still does, and the page's own
+// changes are weighed as before.
+const mainFrameNavigation = event => event?.kind === 'navigation'
+ && !(Number.isSafeInteger(event.frameId) && event.frameId > 0);
+const askRelevantFeedback = events => events.filter(event => !['scroll', 'selection', 'resize'].includes(event?.kind)
+ && (event?.source !== 'user' || mainFrameNavigation(event)));
function automaticAnswerFeedback(events) {
const relevant = askRelevantFeedback(events);
diff --git a/src/firefox/src/agent/page-feedback.js b/src/firefox/src/agent/page-feedback.js
index 17830cc81..c8c3315cc 100644
--- a/src/firefox/src/agent/page-feedback.js
+++ b/src/firefox/src/agent/page-feedback.js
@@ -25,11 +25,16 @@ const userIntervention = events => events.some(event => event?.source === 'user'
const UNKNOWN_ATTRIBUTION_LIMIT = 4;
const unknownAttribution = new WeakMap();
-// Viewing gestures (scroll, selection, pointer/key activity) cannot change the
-// content behind a read-only Ask answer. Clicks, input, navigation and DOM
-// changes they cause are reported separately and still invalidate it.
-const askRelevantFeedback = events => events.filter(event => !(event?.source === 'user'
- && ['scroll', 'selection', 'activity'].includes(event.kind)));
+// A read-only Ask answer is about the page as the person asked about it. What
+// they do there while it is being written (scrolling, selecting, clicking,
+// typing, and the page's changes from those), and any scroll or viewport
+// resize, cannot make it stale, so an answer already shown stays. Their
+// navigation of the page to another address still does, and the page's own
+// changes are weighed as before.
+const mainFrameNavigation = event => event?.kind === 'navigation'
+ && !(Number.isSafeInteger(event.frameId) && event.frameId > 0);
+const askRelevantFeedback = events => events.filter(event => !['scroll', 'selection', 'resize'].includes(event?.kind)
+ && (event?.source !== 'user' || mainFrameNavigation(event)));
function automaticAnswerFeedback(events) {
const relevant = askRelevantFeedback(events);
diff --git a/test/ask-completion-churn.mjs b/test/ask-completion-churn.mjs
index ee31e0bdf..778840d65 100644
--- a/test/ask-completion-churn.mjs
+++ b/test/ask-completion-churn.mjs
@@ -162,7 +162,7 @@ for (const build of ['chrome', 'firefox']) {
assert.deepEqual(f.reads, [], 'An independent reply needs no repeated page refresh.');
} finally { f.clean(); }
});
- for (const change of ['model-steering', 'scope-steering', 'scope-document', 'scope-provider', 'final-user', 'scope-candidate', 'scope-ignored-steering']) {
+ for (const change of ['model-steering', 'scope-steering', 'scope-document', 'scope-provider', 'scope-candidate', 'scope-ignored-steering']) {
test(`${build}: ${streaming ? 'stream' : 'chat'} ${response} cannot retain stale authority after ${change}`, async () => {
const f = fixture(Agent, { streaming, response, change });
try {
@@ -173,6 +173,15 @@ for (const build of ['chrome', 'firefox']) {
} finally { f.clean(); }
});
}
+ // The person typing on the page while the answer is checked does not make
+ // it stale: the answer is delivered once instead of being written again.
+ test(`${build}: ${streaming ? 'stream' : 'chat'} ${response} is kept when the person types on the page during the final check`, async () => {
+ const f = fixture(Agent, { streaming, response, change: 'final-user' });
+ try {
+ assert.equal(await f.run(), f.old);
+ assert.equal(f.counts().mainCalls, 1);
+ } finally { f.clean(); }
+ });
test(`${build}: ${streaming ? 'stream' : 'chat'} ${response} still refreshes a page-dependent answer`, async () => {
const f = fixture(Agent, { streaming, response, change: 'dependent', dependent: true });
try {
diff --git a/test/feedback-ask-viewing.mjs b/test/feedback-ask-viewing.mjs
index 91839d91b..7d4b54a37 100644
--- a/test/feedback-ask-viewing.mjs
+++ b/test/feedback-ask-viewing.mjs
@@ -1,6 +1,7 @@
// Real Agent loop with mocked browser APIs (unit level, both builds): a
-// read-only Ask answer survives viewing gestures that cannot change page
-// content; content-changing user activity and Act decisions stay strict.
+// read-only Ask answer survives what the person does on the page while it is
+// written (viewing, clicking, typing) and scrolls or resizes from anywhere;
+// a navigation of the page to another address, and Act decisions, stay strict.
import assert from 'node:assert/strict';
import { test } from 'node:test';
@@ -68,14 +69,21 @@ function makeAgent(Agent, respond) {
}
const VIEWING = {
- scroll: { kind: 'scroll', source: 'user', target: 'html', viewport: { x: 0, y: 400 } },
- selection: { kind: 'selection', source: 'user', target: 'p' },
- wheel_or_key: { kind: 'activity', source: 'user', target: 'div#list' },
+ 'the person scrolling': { kind: 'scroll', source: 'user', target: 'html', viewport: { x: 0, y: 400 } },
+ 'the person selecting text': { kind: 'selection', source: 'user', target: 'p' },
+ 'the person using the wheel or keys': { kind: 'activity', source: 'user', target: 'div#list' },
+ // What the person does on the page while the answer is written, as in
+ // the WhatsApp trace: they typed a draft and clicked around.
+ 'the person clicking': { kind: 'click', source: 'user', target: 'button#sort' },
+ 'the person typing': { kind: 'input', source: 'user', target: 'input#filter' },
+ 'the page changing from their typing': { kind: 'dom', source: 'user', target: 'div#composer' },
+ // A page that scrolls itself, such as a chat showing a new message, and a
+ // resized viewport show the same content.
+ 'the page scrolling itself': { kind: 'scroll', source: 'unknown', target: 'div#messages', viewport: { x: 0, y: 900 } },
+ 'the viewport resizing': { kind: 'resize', source: 'unknown', target: 'viewport', viewport: { width: 900, height: 700 } },
};
const CHANGING = {
- click: { kind: 'click', source: 'user', target: 'button#sort' },
- input: { kind: 'input', source: 'user', target: 'input#filter' },
- navigation: { kind: 'navigation', source: 'user' },
+ 'the person navigating to another address': { kind: 'navigation', source: 'user' },
};
const emit = (agent, tab, event) => event.kind === 'navigation'
? agent._queuePageFeedback(tab, { ...event, frameId: 0, before: PAGE_URL, after: PAGE_URL + '?sorted' })
@@ -87,7 +95,7 @@ for (const build of ['chrome', 'firefox']) {
for (const [name, event] of [...Object.entries(VIEWING), ...Object.entries(CHANGING)]) {
const survives = name in VIEWING;
- test(`${build}: a streamed Ask answer ${survives ? 'survives' : 'is regenerated after'} user ${name}`, async () => {
+ test(`${build}: a streamed Ask answer ${survives ? 'survives' : 'is regenerated after'} ${name}`, async () => {
const tab = nextTab++, updates = [];
let calls = 0;
const agent = makeAgent(Agent, (owner, streamed) => {
@@ -99,13 +107,15 @@ for (const build of ['chrome', 'firefox']) {
{ detachedRequestId: 'ask-' + tab, interactiveChat: true, askStreamingEnabled: true });
assert.equal(calls, survives ? 1 : 2);
assert.equal(result, survives ? ANSWER : 'Regenerated: ' + ANSWER);
- assert.equal(retracted(updates), !survives, survives ? 'A viewing gesture must not retract a visible answer' : 'Changed content invalidates it');
+ assert.equal(retracted(updates), !survives, survives ? 'What the person does on the page must not retract a visible answer' : 'A navigation invalidates it');
assert.equal(agent._pageFeedbackRuns.size, 0);
});
}
- for (const streaming of [false, true]) for (const [name, event] of [['scroll', VIEWING.scroll], ['click', CHANGING.click]]) {
- test(`${build}: ${streaming ? 'stream' : 'chat'} Ask done summary ${name === 'scroll' ? 'survives' : 'is reconsidered after'} user ${name}`, async () => {
+ for (const streaming of [false, true]) for (const [name, event] of [['the person scrolling', VIEWING['the person scrolling']],
+ ['the person clicking', VIEWING['the person clicking']], ...Object.entries(CHANGING)]) {
+ const survives = name in VIEWING;
+ test(`${build}: ${streaming ? 'stream' : 'chat'} Ask done summary ${survives ? 'survives' : 'is reconsidered after'} ${name}`, async () => {
const tab = nextTab++, delivered = [];
let calls = 0;
const agent = makeAgent(Agent, owner => {
@@ -118,8 +128,8 @@ for (const build of ['chrome', 'firefox']) {
const options = { detachedRequestId: 'ask-done-' + tab, askStreamingEnabled: false };
const result = streaming ? await agent.processMessageStream(tab, 'Which product is cheapest?', () => {}, 'ask', options)
: await agent.processMessage(tab, 'Which product is cheapest?', () => {}, 'ask', [], options);
- assert.equal(calls, name === 'scroll' ? 1 : 2);
- assert.deepEqual(delivered, [name === 'scroll' ? ANSWER : 'Fresh: ' + ANSWER]);
+ assert.equal(calls, survives ? 1 : 2);
+ assert.deepEqual(delivered, [survives ? ANSWER : 'Fresh: ' + ANSWER]);
assert.equal(result, delivered[0]);
});
}
@@ -129,7 +139,7 @@ for (const build of ['chrome', 'firefox']) {
let calls = 0;
const agent = makeAgent(Agent, owner => {
calls++;
- if (calls === 1) emit(owner, tab, VIEWING.scroll);
+ if (calls === 1) emit(owner, tab, VIEWING['the person scrolling']);
return calls <= 2 ? { toolCalls: [{ id: 'read-' + calls, function: { name: 'extract_data', arguments: '{"type":"headings"}' } }] }
: { toolCalls: [{ id: 'finished', function: { name: 'done', arguments: JSON.stringify({ summary: ANSWER, outcome: 'success' }) } }] };
});
diff --git a/test/page-feedback-progress.mjs b/test/page-feedback-progress.mjs
index 76ed01ae1..c7a8c7005 100644
--- a/test/page-feedback-progress.mjs
+++ b/test/page-feedback-progress.mjs
@@ -380,7 +380,38 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(agent._pageFeedbackRuns.size, 0);
});
}
- for (const response of ['done', 'prose']) for (const change of ['human_input', 'unknown', 'navigation', 'style', 'frame', 'task_steering', 'document', 'mode_change']) {
+ // The person typing on the page while an Ask answer is written does not
+ // make the answer stale: it is delivered once, not written again.
+ for (const response of ['done', 'prose']) {
+ test(`${build}: ${streaming ? 'stream' : 'chat'} Ask ${response} is kept after the person types on the page`, async () => {
+ const tab = nextTab++, delivered = [];
+ let agent, send, requests = 0;
+ const next = async () => {
+ assert.equal(++requests, 1, 'The answer is not written again');
+ send({ kind: 'input', source: 'user' });
+ return response === 'done' ? call('answer', 'done', { summary: 'The answer' }) : { content: 'The answer' };
+ };
+ agent = makeAgent(Agent, next);
+ agent._enrichUserMessageWithCurrentPage = async (_tab, _messages, content) => {
+ send = bind(agent, tab); return { role: 'user', content };
+ };
+ agent.executeTool = async (_tab, name, args) => {
+ if (name === 'get_accessibility_tree') return { success: true, pageContent: 'article "Context" [ref_1]' };
+ assert.equal(name, 'done');
+ delivered.push(args.summary);
+ return { success: true, done: true, summary: args.summary };
+ };
+ const options = { detachedRequestId: 'ask-kept-run', askStreamingEnabled: true };
+ const result = streaming
+ ? await agent.processMessageStream(tab, 'Read the current question', () => {}, 'ask', options)
+ : await agent.processMessage(tab, 'Read the current question', () => {}, 'ask', [], options);
+ assert.equal(result, 'The answer');
+ assert.equal(requests, 1);
+ assert.deepEqual(delivered, response === 'done' ? ['The answer'] : []);
+ assert.equal(agent._pageFeedbackRuns.size, 0);
+ });
+ }
+ for (const response of ['done', 'prose']) for (const change of ['unknown', 'navigation', 'style', 'frame', 'task_steering', 'document', 'mode_change']) {
test(`${build}: ${streaming ? 'stream' : 'chat'} Ask ${response} is reconsidered after ${change}`, async () => {
const tab = nextTab++, updates = [], delivered = [];
let agent, send, requests = 0;
diff --git a/test/quality/ask-person-activity-mv3.mjs b/test/quality/ask-person-activity-mv3.mjs
new file mode 100644
index 000000000..052dc8309
--- /dev/null
+++ b/test/quality/ask-person-activity-mv3.mjs
@@ -0,0 +1,170 @@
+import assert from 'node:assert/strict';
+import fs from 'node:fs/promises';
+import http from 'node:http';
+import os from 'node:os';
+import path from 'node:path';
+import { chromium } from 'playwright';
+
+// The WhatsApp trace: in Ask mode the person asked what to reply, and while
+// the answer was being written they typed a draft into the chat's composer,
+// clicked and scrolled. The answer appeared and vanished twice before a third
+// one stayed. Through the installed MV3 extension, with real page events from
+// real input: the answer that is being written stays, and is written once.
+// The page and the model are owned local fixtures; nothing leaves the host.
+const out = path.resolve(process.env.WEBBRAIN_QUALITY_ARTIFACTS || 'ci/artifacts/quality-audit-2026-10-15/ask-person-activity-mv3');
+await fs.mkdir(out, { recursive: true });
+const textContent = content => typeof content === 'string' ? content : Array.isArray(content)
+ ? content.filter(block => block?.type === 'text').map(block => block.text || '').join('\n') : '';
+const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
+const deferred = () => { let resolve; const promise = new Promise(done => { resolve = done; }); return { promise, resolve }; };
+const question = 'Owned Ask person activity. What should I reply to the last message here?';
+const answer = 'You could reply: "Thanks, 70,000 works for me if the insulation is included." OWNED-ASK-PERSON-ANSWER';
+const chatHtml = `<!doctype html><meta charset="utf-8"><title>Owned chat</title>
+<style>body{font:16px sans-serif;margin:0;display:flex;flex-direction:column;height:100vh}
+#messages{flex:1;overflow:auto;padding:16px}#messages p{margin:0 0 12px;padding:8px;background:#eef;border-radius:6px;width:60%}
+footer{display:flex;gap:8px;padding:12px;border-bottom:1px solid #ccc}#composer{flex:1;min-height:40px;border:1px solid #888;padding:8px}</style>
+<footer><div id="composer" role="textbox" contenteditable="true" aria-label="Type a message"></div><button id="attach" type="button" aria-label="Attach">+</button></footer>
+<main id="messages" aria-label="Messages"><p id="last">Last message: 70,000 for the whole job.</p>
+${Array.from({ length: 30 }, (_, index) => `<p>Earlier message ${index + 1}: the balcony and the roof.</p>`).join('')}</main>
+<script>
+// Like a chat app, the page reacts to typing: a typing hint appears.
+const hint=document.createElement('div');hint.id='hint';document.body.prepend(hint);
+document.querySelector('#composer').addEventListener('input',()=>{hint.textContent='Draft: '+document.querySelector('#composer').textContent.length+' characters';});
+document.querySelector('#attach').addEventListener('click',()=>{hint.textContent='Attach menu opened';});
+</script>`;
+
+const calls = [], network = [], runtimeErrors = [];
+const mainReached = deferred(), releaseMain = deferred();
+const server = http.createServer(async (request, response) => {
+ try {
+ const url = new URL(request.url, 'http://owned.local');
+ if (url.pathname === '/chat') { response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); response.end(chatHtml); return; }
+ if (url.pathname === '/favicon.ico') { response.writeHead(204); response.end(); return; }
+ assert.equal(url.pathname, '/v1/chat/completions');
+ let raw = ''; for await (const chunk of request) raw += chunk;
+ const input = JSON.parse(raw), system = textContent(input.messages[0]?.content);
+ if (input.messages?.length === 1 && input.messages[0].content === 'Hi' && !input.tools?.length) {
+ response.writeHead(200, { 'Content-Type': 'application/json' });
+ response.end(JSON.stringify({ choices: [{ message: { role: 'assistant', content: 'Hi' }, finish_reason: 'stop' }], usage: { prompt_tokens: 1, completion_tokens: 1 } }));
+ return;
+ }
+ const stage = system.startsWith('You classify whether one proposed terminal WebBrain Ask answer') ? 'scope'
+ : system.startsWith('You classify whether a WebBrain Ask-mode answer') ? 'handoff' : 'main';
+ const record = { stage, stream: input.stream === true, at: Date.now() };
+ calls.push(record);
+ let content;
+ if (stage === 'scope') content = JSON.stringify({ pageIndependent: false });
+ else if (stage === 'handoff') content = '{"mode_handoff":"none"}';
+ else {
+ assert.ok(JSON.stringify(input.messages).includes('Owned Ask person activity'), 'Only the owned question reaches the model');
+ // The model takes its time, as in the trace; the person keeps using the page.
+ if (calls.filter(call => call.stage === 'main').length === 1) { mainReached.resolve(); await releaseMain.promise; }
+ content = answer;
+ }
+ if (input.stream) {
+ response.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', Connection: 'keep-alive' });
+ const half = Math.floor(content.length / 2);
+ for (const part of [content.slice(0, half), content.slice(half)]) {
+ response.write('data: ' + JSON.stringify({ choices: [{ index: 0, delta: { content: part }, finish_reason: null }] }) + '\n\n');
+ await delay(30);
+ }
+ response.write('data: ' + JSON.stringify({ choices: [{ index: 0, delta: {}, finish_reason: 'stop' }], usage: { prompt_tokens: 100, completion_tokens: 30 } }) + '\n\n');
+ response.end('data: [DONE]\n\n');
+ } else {
+ response.writeHead(200, { 'Content-Type': 'application/json' });
+ response.end(JSON.stringify({ choices: [{ message: { role: 'assistant', content }, finish_reason: 'stop' }], usage: { prompt_tokens: 100, completion_tokens: 30 } }));
+ }
+ } catch (error) {
+ runtimeErrors.push(error.message);
+ if (!response.headersSent) response.writeHead(500, { 'Content-Type': 'application/json' });
+ response.end(JSON.stringify({ error: { message: error.message } }));
+ }
+});
+await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
+const origin = `http://127.0.0.1:${server.address().port}`;
+const profile = await fs.mkdtemp(path.join(os.tmpdir(), 'webbrain-ask-person-'));
+let context;
+try {
+ const extension = path.join(profile, 'extension'); await fs.cp(path.resolve('src/chrome'), extension, { recursive: true });
+ context = await chromium.launchPersistentContext(path.join(profile, 'user'), { headless: true, channel: 'chromium',
+ args: [`--disable-extensions-except=${extension}`, `--load-extension=${extension}`, '--disable-background-networking', '--disable-sync'] });
+ await context.route('**/*', route => {
+ const url = new URL(route.request().url());
+ if (url.protocol === 'chrome-extension:' || url.origin === origin) return route.continue();
+ network.push(url.hostname); return route.abort();
+ });
+ const worker = context.serviceWorkers()[0] || await context.waitForEvent('serviceworker', { timeout: 30000 });
+ const extensionId = new URL(worker.url()).host;
+ const settings = await context.newPage(); await settings.goto(`chrome-extension://${extensionId}/src/ui/settings.html`);
+ const message = (page, action, data = {}) => page.evaluate(({ action, data }) => chrome.runtime.sendMessage({ target: 'background', action, ...data }), { action, data });
+ await settings.evaluate(() => chrome.storage.local.set({ helpImproveWebBrain: false, userMemoryEnabled: false,
+ planBeforeActMode: 'off', planBeforeAct: false, planReviewMode: 'never', screenshotFallback: false, autoScreenshot: 'off',
+ maxAgentSteps: 6, systemOneEnabled: false, tracingEnabled: true, losslessTrace: true, agentAllowLocalNetwork: true,
+ askBeforeConsequentialActions: false, openaiAskStreamingEnabled: true, contextWindowMode: 'full' }));
+ assert.equal((await message(settings, 'update_provider', { providerId: 'openrouter', config: { apiKey: 'owned-loopback-fake-key',
+ baseUrl: `${origin}/v1`, model: 'openai/gpt-5.4-mini', contextWindow: 128000, enabled: true, supportsAskStreaming: true,
+ supportsVision: false, visionMode: 'off' } })).ok, true);
+ assert.equal((await message(settings, 'set_active_provider', { providerId: 'openrouter' })).ok, true);
+ const panel = await context.newPage(); await panel.goto(`chrome-extension://${extensionId}/src/ui/sidepanel.html`);
+ await panel.evaluate(() => {
+ window.ownedRun = { finished: false }; window.ownedEvents = [];
+ chrome.runtime.onMessage.addListener(event => { if (event.action === 'agent_update' || event.action === 'run_complete') ownedEvents.push(event); });
+ });
+ const page = await context.newPage();
+ await page.goto(`${origin}/chat`);
+ const tabId = await settings.evaluate(async url => (await chrome.tabs.query({})).find(tab => tab.url === url)?.id, page.url());
+ assert.ok(tabId);
+ const requestId = 'owned-ask-person-activity';
+ await panel.evaluate(({ requestId, tabId, text }) => {
+ chrome.runtime.sendMessage({ target: 'background', action: 'chat', requestId, tabId, text, mode: 'ask', locale: 'en' })
+ .then(result => { window.ownedRun = { finished: true, result }; })
+ .catch(error => { window.ownedRun = { finished: true, error: error.message }; });
+ }, { requestId, tabId, text: question });
+ await Promise.race([mainReached.promise, delay(45000).then(() => { throw new Error('The answer was never requested.'); })]);
+ // The person keeps using the chat: they click into the composer, type a
+ // draft, open a menu and scroll the messages, as real input.
+ await page.bringToFront();
+ await page.click('#composer');
+ await page.keyboard.type('bi de bana sorumluluk', { delay: 20 });
+ await page.click('#attach');
+ await page.mouse.move(300, 200);
+ await page.mouse.wheel(0, -600);
+ await page.click('#last');
+ await delay(1500);
+ releaseMain.resolve();
+ await panel.waitForFunction(() => window.ownedRun.finished, null, { timeout: 45000 });
+ const run = await panel.evaluate(() => window.ownedRun);
+ const events = await panel.evaluate(id => ownedEvents.filter(event => event.requestId === id), requestId);
+ const current = await message(panel, 'agent_run_state', { tabId, requestId });
+ const draft = await page.evaluate(() => document.querySelector('#composer').textContent);
+ const descriptor = await message(panel, 'export_traces', { tabId, full: true });
+ const decisions = descriptor?.ok ? await panel.evaluate(async ({ sessionId, extensionId }) => {
+ const recorder = await import(`chrome-extension://${extensionId}/src/trace/recorder.js`);
+ const runs = await recorder.listRuns({ conversationId: sessionId });
+ const all = await Promise.all(runs.map(item => recorder.getRunEvents(item.runId)));
+ return all.flat().filter(event => event.kind === 'note' && event.data?.note === 'page_feedback_decision').map(event => event.data.extra);
+ }, { sessionId: descriptor.sessionId, extensionId }) : [];
+ const retracted = events.filter(event => event.type === 'text' && event.data?.replace === true && event.data?.content === '');
+ const main = calls.filter(call => call.stage === 'main');
+ const evidence = { run, calls, current: { running: current?.running, finalContent: current?.runUi?.finalContent, status: current?.runUi?.status },
+ retracted: retracted.length, decisions, draft, network, runtimeErrors };
+ await fs.writeFile(path.join(out, 'evidence.json'), JSON.stringify(evidence, null, 2));
+ assert.deepEqual(runtimeErrors, []);
+ assert.equal(draft, 'bi de bana sorumluluk', 'The person really typed into the page');
+ assert.ok(decisions.some(decision => (decision.context?.feedback?.observed?.events || []).some(event => event.source === 'user')),
+ `The person's activity reached WebBrain as page feedback: ${JSON.stringify(decisions)}`);
+ assert.equal(main.length, 1, `The answer was written once, not again after the person's activity: ${JSON.stringify(calls)}`);
+ assert.equal(retracted.length, 0, 'The answer being shown was never taken back');
+ assert.equal(run.error, undefined);
+ assert.equal(run.result?.content, answer);
+ assert.equal(current?.running, false);
+ console.log(JSON.stringify({ passed: true, installedMV3: true, mainCalls: main.length, retracted: retracted.length,
+ decisions: decisions.map(decision => `${decision.stage}:${decision.disposition}`), blockedNetwork: network.length }));
+} finally {
+ releaseMain.resolve();
+ await context?.close();
+ await new Promise(resolve => server.close(resolve));
+ const resolved = await fs.realpath(profile);
+ if (!path.basename(resolved).startsWith('webbrain-ask-person-')) throw new Error('Unexpected temporary profile path.');
+ await fs.rm(resolved, { recursive: true, force: true });
+}