Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Fix Mastodon reply duplicate posts after trusted click route change
Claude4311588e7f48
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c63684cf0..b840fc98f 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+- Mastodon: replying to toots in a narrow window no longer posts the same reply several times and stops before the next toot. There, a toot's Reply button opens the composer at /publish, and after posting Mastodon goes back to the previous column by itself. WebBrain took both page changes for something you did, so it reported each click's outcome as unknown; the agent then concluded its reply had not been posted, wrote it again, and never reached the next toot. In Chrome, a page's own Back is now told apart from your browser's Back button: the page a click opens counts as that click's verified effect, and a click after which the page goes back by itself counts as delivered, to be checked on the page. The Mastodon notes now cover replies (start with the prefilled @mentions once, check the reply under the toot before any retry) and stay active on Favourites, Bookmarks and the other columns. Firefox still treats a page's own Back as yours until its Back button reporting is verified.- Finishing a form you asked WebBrain not to submit no longer takes most of a minute. The completion check removed every line that mentioned a password, so "fill out this form with a random password … don't submit" reached its judge as "[credential omitted]", and so did the approved plan and the agent's summary. Seeing only an unsubmitted signup form, the judge answered "pending" again and again; in the trace it took four attempts and about 50 seconds, ending only when a slow screenshot check ran out of time. The active model's check, which already holds these texts in the conversation, now receives every line of them, with only addresses shortened and bearer tokens and entered passwords hidden, as in all judge evidence. A decision model on this device, or WebBrain Cloud's own while WebBrain Cloud is also your provider, receives that same copy; any other decision model keeps whole-line redaction, and when that leaves it without the task, it is no longer asked while the active model can judge. A password WebBrain typed into a password field during the run is now hidden in the text judges receive, such as the agent's summary or a field a "show password" control revealed, unless the typing tool could not tell what kind of field it was; other entered values stay visible, so a judge can still catch a mistyped one. The judges are told that a task asking not to submit is complete once the staged values match, that a hidden value neither proves nor disproves an entry, and, for each recorded entry, whether its field read back what was entered, whether it is a credential field and which field it targeted; a credential field's line in the page evidence keeps its role and reference. Staged field edits are judged from the accessibility tree first: a screenshot shows passwords only as dots, and the focused field's blinking caret made each one stale before its verdict returned.- Filling several known form fields now takes one `browser_batch` instead of one model turn per field. The Act prompts still said to fill one field at a time and to click each field before typing, and the planner named only `set_field`; they now send already observed fields, including those in the latest page observation, through one batch with one `set_field` per field. Entering a required password still ends a batch, so password fields go last and anything left follows in the next turn. The completion check now also counts the actions inside a batch, which it did not see before.diff --git a/docs/page-feedback-monitor.md b/docs/page-feedback-monitor.mdindex c7b37cc0e..d3b490cbc 100644--- a/docs/page-feedback-monitor.md+++ b/docs/page-feedback-monitor.md@@ -446,6 +446,35 @@ Steer or grant authorization. Enter and Alt+Enter retain their existing behavior- An agent click explains a same-document route update in its own frame withinthree seconds when no user activity followed it; full-document navigationkeeps the exact-URL rule.+- A same-document Back/Forward update (Chrome's `forward_back`, which a page's+ own `history.back()` also carries, with its destination entry's original+ transition type) first counts as user input. In Chrome, the frame's monitor,+ listening from document start, then says value-free whether the trusted+ Navigation API traversal to that exact URL was page-initiated+ (`userInitiated` false); a reading answers once, and only within a second of+ its traversal. A monitor injected later, even while the document is still+ loading, never certifies one. Confirmed within 500 ms, with no physical input+ or user-attributed update since, the user attribution is withdrawn: inside+ the click's three-second window the traversal is that click's effect;+ otherwise it is attributed like any page route update (the user's within two+ seconds of their input or during a held gesture, else unattributed). An+ update that follows while the reading is pending (a state restore) is not+ near-user because of it, and when the reading keeps the user attribution,+ nothing credited to the click meanwhile stands. Browser UI, a missing,+ consumed or late reading, browsers without the Navigation API, and Firefox+ (whose own Back/Forward reporting is unverified) keep it the user's. Stop+ does not wait for a reading; feedback being applied does, so it never+ delivers an emptied update. A `page_traversal_attribution` trace note+ records the outcome.+- After both input acknowledgements, a trusted native button's observation+ accepts a route update attributed to its own dispatch operation at or after+ the press (Mastodon's Reply pushes /publish; its composer goes back after+ posting). A new path or query the page pushed is a verified `url` effect. A+ hash-only change, and any route reached by Back/Forward (another frame's+ script can go back too), are tolerated without counting as proof: the press+ is delivered and awaits a fresh observation. Before input any route change+ still refuses, and the new route still invalidates the model state bound for+ the next decision.- A run's app-owned observations, captures and recovery nudges are removedwhen it ends, so the next request observes the current page instead. Stopinterrupts page capture and the refresh read.diff --git a/docs/trace-format-compatibility.md b/docs/trace-format-compatibility.mdindex 8a20110d9..b2e0ace99 100644--- a/docs/trace-format-compatibility.md+++ b/docs/trace-format-compatibility.md@@ -16,7 +16,7 @@ WebBrain's trace data has three independent version layers:Planner alignment and publication checks record their auxiliary model requests and responses, including `requestedMaxTokens`, `candidateAttempt`, finish/token diagnostics, and a finite `validationFailure` code. Technical repairs keep the candidate binding fixed and are distinct from a replacement plan after a valid semantic rejection. Metadata-only traces retain those diagnostics without prompts, replies, arbitrary JSON property names, or checker explanations; content-enabled traces follow the existing recording policy.-Recoverable failures may include a `failure_recovery_offered` note with the failed stage and retry mode. Chat controls use an opaque runtime recovery ID bound to the exact task and conversation. Starting another run, changing the task, stopping, or choosing Give up expires the offer. Model, response-generation and interaction failures resume through normal continuation checks. For `action_context_unverified`, `action_monitoring_relaxed` identifies one explicitly accepted Retry run on the same task and document; publication Retry remains the separately bound, one-use audit exemption described in the publication contract. Metadata-only `page_action_validation` notes include a finite `certificationFailure` or dispatch `predicate` and a `monitoringRelaxed` boolean. Private grant tokens and target/page content are excluded.+Recoverable failures may include a `failure_recovery_offered` note with the failed stage and retry mode. Chat controls use an opaque runtime recovery ID bound to the exact task and conversation. Starting another run, changing the task, stopping, or choosing Give up expires the offer. Model, response-generation and interaction failures resume through normal continuation checks. For `action_context_unverified`, `action_monitoring_relaxed` identifies one explicitly accepted Retry run on the same task and document; publication Retry remains the separately bound, one-use audit exemption described in the publication contract. Metadata-only `page_action_validation` notes include a finite `certificationFailure` or dispatch `predicate` and a `monitoringRelaxed` boolean. Private grant tokens and target/page content are excluded. Metadata-only `page_traversal_attribution` notes record which attribution a same-document Back/Forward update finally kept (`outcome`: `click_effect`, `page` or `user`) and a finite `reason`; no URL is recorded.Tool events may include an optional `data.outcome` summary containing bounded dispatch, application, provider, error, and CAPTCHA-gate diagnostics. In lossless recordings, this summary survives the content-budget marker, while answer tokens, cookies, provider keys, and form inputs are excluded from the summary. Readers should still honor `_truncated` and `losslessBudgetOmitted`; the summary does not reconstruct discarded content.diff --git a/package.json b/package.jsonindex 265268e19..29fb7e945 100644--- a/package.json+++ b/package.json@@ -61,8 +61,8 @@"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/history-recovery-state.mjs test/history-recovery-scheduler.mjs test/history-recovery-atomic.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/page-feedback-unbindable-target.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.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/follow-up-task-context.mjs test/completion-current-execution-evidence.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-scroll-churn.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/incomplete-completion-recovery.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/history-recovery.mjs test/history-recovery-ui.mjs test/page-monitor-ui.mjs test/x-compose-trusted-typing.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/native-mastodon-confirmation.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/mastodon-delete-confirmation-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs --menu-read && node test/quality/mastodon-delete-confirmation-mv3.mjs --vague && 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/x-compose-dialog-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/page-feedback-unbindable-target.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.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/x-compose-trusted-typing.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-scroll-churn.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: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/history-recovery-state.mjs test/history-recovery-scheduler.mjs test/history-recovery-atomic.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/page-feedback-unbindable-target.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.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/follow-up-task-context.mjs test/completion-current-execution-evidence.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-scroll-churn.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/incomplete-completion-recovery.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/history-recovery.mjs test/history-recovery-ui.mjs test/page-monitor-ui.mjs test/x-compose-trusted-typing.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/native-mastodon-confirmation.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-reply-route-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs --menu-read && node test/quality/mastodon-delete-confirmation-mv3.mjs --vague && 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/x-compose-dialog-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/page-feedback-unbindable-target.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.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/x-compose-trusted-typing.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-scroll-churn.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-native-button-route.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:history-recovery": "node --test test/history-recovery.mjs test/history-recovery-ui.mjs test/history-recovery-state.mjs test/history-recovery-scheduler.mjs test/history-recovery-atomic.mjs test/conversation-persistence.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",@@ -96,10 +96,10 @@"test:upload-owner": "node --test test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs","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:browser-batch && 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/page-feedback-unbindable-target.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.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/follow-up-task-context.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/incomplete-completion-recovery.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/improver-providers.mjs test/improver-providers-agent.mjs test/improver-guards-ledger.mjs test/improver-guards-tools.mjs test/improver-clarify.mjs test/improver-clarify-scheduler.mjs test/improver-misc.mjs test/improver-forms.mjs test/improver-forms-strict-secrets.mjs test/improver-content-press-keys-hint.mjs && npm run test:plan-notifications",- "test:shard:browser-a": "node --test test/captcha-draft-content.mjs test/captcha-challenge-surfaces.mjs && 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/x-compose-trusted-typing.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/native-mastodon-confirmation.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-scroll-churn.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/improver-content-account-chrome.mjs test/improver-content-recipient.mjs test/improver-content-truncated-replacement.mjs test/improver-forms-probe.mjs test/improver-misc-trace-browser.mjs",+ "test:shard:browser-a": "node --test test/captcha-draft-content.mjs test/captcha-challenge-surfaces.mjs && 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/x-compose-trusted-typing.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/native-mastodon-confirmation.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-scroll-churn.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-native-button-route.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/improver-content-account-chrome.mjs test/improver-content-recipient.mjs test/improver-content-truncated-replacement.mjs test/improver-forms-probe.mjs test/improver-misc-trace-browser.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/integration-mv3.mjs --batch && 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/mastodon-delete-confirmation-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs --menu-read && node test/quality/mastodon-delete-confirmation-mv3.mjs --vague && 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/x-compose-dialog-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:browser-c": "node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-reply-route-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs --menu-read && node test/quality/mastodon-delete-confirmation-mv3.mjs --vague && 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/x-compose-dialog-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","test:composer-context": "node --test test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/x-compose-dialog-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs","test:bot-memory": "node --test test/bot-memory.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs && node test/bot-memory-dom.mjs && node test/quality/cloud-bot-memory-mv3.mjs",diff --git a/src/chrome/src/agent/adapters.js b/src/chrome/src/agent/adapters.jsindex 2f3702191..de5cd756c 100644--- a/src/chrome/src/agent/adapters.js+++ b/src/chrome/src/agent/adapters.js@@ -15680,6 +15680,18 @@ function isMastodonAppPath(hostname, path) {&& /^\/(?:home|deck|web|notifications|explore|public|public\/local|settings|lists|publish|start|get-started|get-started\/profile|getting-started)(?:\/|$)/i.test(path);}+// The web app's other columns (Favourites, Bookmarks, ...) are the same+// Mastodon app as Home: its adapter notes, publication receipts and native+// post handling follow a task there too, for example a reply started from+// Favourites. isMastodonUrl keeps its narrower list for the page observers+// (isMastodonPageUrl) and the finance-site exclusion.+function isMastodonAdapterUrl(url) {+ if (isMastodonUrl(url)) return true;+ const u = new URL(url);+ return /^https?:$/.test(u.protocol) && isLikelyMastodonHost(u.hostname)+ && /^\/(?:favourites|bookmarks|conversations|followed_tags|pinned|directory|follow_requests|mutes|blocks|domain_blocks|search|tags)(?:\/|$)/i.test(safeDecodePath(u.pathname));+}+function isMastodonLocalProfilePath(hostname, path) {return isLikelyMastodonHost(hostname) && /^\/@[A-Za-z0-9_]+\/?$/.test(path);}@@ -17934,7 +17946,7 @@ const ADAPTERS = [// known sites (for example TikTok) preserve their own guidance.name: 'mastodon',category: 'general',- matches: isMastodonUrl,+ matches: isMastodonAdapterUrl,fullPageCapture: { infiniteScroll: isMastodonInfiniteScrollUrl },notes: `- For public media downloads, call an enabled \`download_public_media\` skill first with the exact status permalink (/@<user>/<id> or /users/<user>/statuses/<id>); on a timeline/profile, identify the visible post and its link first. FreeSkillz supports public Mastodon media across instances without browser cookies. Never send followers-only/direct posts; use \`download_social_media\` only if the skill is unavailable or fails.@@ -17943,7 +17955,9 @@ const ADAPTERS = [- After submitting the home domain, expect a redirect to the user's own instance with a remote URL like \`https://mastoturk.org/@[email protected]\`; wait_for_stable there. For account/profile follow flows, click Follow; for status or authorize_interaction flows, complete the requested action on the home-instance page (reply, boost, favorite, or follow).- Do NOT manually synthesize the home-instance URL before this handoff. The home instance may need the remote-profile lookup/redirect to recognize the account.- Label variants by version/language: "Sign in to continue", "Continue on your server", "Authorize interaction", "Proceed to follow"; Turkish: Takip et=Follow, sunucu/domain=server domain.-- If the user's Mastodon home domain is not already known from the conversation or account UI, clarify once before entering anything.`,+- If the user's Mastodon home domain is not already known from the conversation or account UI, clarify once before entering anything.+- Liked (favourited) posts are listed at /favourites. To reply, click that post's Reply button ("Yanıtla" in Turkish; the composer's submit has the same label). The composer opens with the thread's @mentions prefilled (narrow layouts open it at /publish): start your text with them exactly once instead of clearing them.+- After a reply posts, the composer empties and narrow layouts go back to the previous column; Favourites does not show your reply. Verify it under the replied-to post: open its timestamp link (the post's permalink) and find your reply below it. If a submit's outcome is uncertain, check there before any retry; never post the same reply twice. With several posts to reply to, finish and verify one, then move to the next.`,},...CMS_ADAPTERS,];diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 2fb7fe4b8..025062fed 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -323,6 +323,13 @@ async function sendTrustedCdpInput(send, { beforeSend = null, onSent = null } =}}+// The address without its fragment: a hash-only change is not a new route.+function urlWithoutFragment(url) {+ const value = String(url || '');+ const hash = value.indexOf('#');+ return hash < 0 ? value : value.slice(0, hash);+}+const EARLY_CDP_ACTION_TOOLS = new Set(['click', 'type_text', 'press_keys', 'hover', 'drag_drop', 'upload_file']);const DONE_OUTCOMES = new Set(['success', 'partial', 'failed']);const LOCAL_CANCELLATION_ASSISTANT_RE = /^\[?Stopped by user(?: before (?:the run started|executing requested tool calls))?\.?\]?$/;@@ -18486,15 +18493,33 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dasync _dispatchInitialTrustedNativeButton(tabId, args, prepared, contentArgs, messageOptions,baseline, abortSignal, dispatchState, timing, run, dispatchCall, assertNotAborted) {+ const ownerChanged = () => {+ const error = new Error('The current task or browser owner changed before trusted button input.');+ error.code = 'page_feedback_pending';+ error.pagePreparationVeto = { cause: 'current_owner_changed', predicate: 'current_owner_changed' };+ return error;+ };const assertCurrent = () => {assertNotAborted();if (this._pageFeedbackRuns?.get(tabId) !== run || run.dispatchCall !== dispatchCall|| this._hasPendingSteering(tabId) || this._checkAbort(tabId)- || !this._pageFeedbackStateCurrent(tabId, run, dispatchCall.modelState)) {- const error = new Error('The current task or browser owner changed before trusted button input.');- error.code = 'page_feedback_pending';- error.pagePreparationVeto = { cause: 'current_owner_changed', predicate: 'current_owner_changed' }; throw error;- }+ || !this._pageFeedbackStateCurrent(tabId, run, dispatchCall.modelState)) throw ownerChanged();+ };+ // Only after both input acknowledgements: this press's own same-document+ // route update (an SPA pushState, or the page's own history.back() after+ // a submit) is its effect, not a new owner. The page-feedback run+ // attributes such updates to the agent and records them as agentRoute; a+ // Back/Forward update is read for page-initiated attribution first. Every+ // other change of run, call, steering, Stop, mode or document still+ // interrupts, and before input the route may not change at all.+ const ownRoute = () => this._pageFeedbackAgentRouteCurrent(tabId, run, baseline.startedAt);+ const assertObservedOwner = async () => {+ await this._pageFeedbackTraversalSettled(run, this._runAbortSignal?.(tabId));+ assertNotAborted();+ const state = dispatchCall.modelState;+ if (this._pageFeedbackRuns?.get(tabId) !== run || run.dispatchCall !== dispatchCall+ || this._hasPendingSteering(tabId) || this._checkAbort(tabId)+ || !this._pageFeedbackStateCurrent(tabId, run, state, ownRoute() ? state?.url : run.url)) throw ownerChanged();};const key = `${prepared.documentToken}|${args.ref_id}`;baseline.preparedActive = prepared.preparedActive || '';@@ -18615,17 +18640,17 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dpreparationStage = 'observation';// End only this acknowledged input operation before observing its asynchronous effect.// Queued feedback and the one-shot input lock remain unchanged.- assertCurrent();+ await assertObservedOwner();if (!await finishInput()) {const error = new Error('The acknowledged native input operation is no longer current.');error.code = 'page_feedback_pending';error.pagePreparationVeto = { predicate: 'operation_expired' }; throw error;}- assertCurrent();+ await assertObservedOwner();// Both input acknowledgements are complete. Continue bounded observation// of this exact target while its own mutation settles; never send input.- const assertObservationCurrent = () => {- assertCurrent();+ const assertObservationCurrent = async () => {+ await assertObservedOwner();// Once input is acknowledged, this phase only reads. Focus restoration,// layout changes and DOM updates are possible effects of the click, not// permission to dispatch again. Actual intervention still stops proof.@@ -18637,9 +18662,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}};const observeTrustedTarget = async () => {- assertObservationCurrent();+ await assertObservationCurrent();const target = await this._resolveClickAxFallbackTarget(tabId, args.ref_id, abortSignal, { observeOnly: true });- assertObservationCurrent();+ await assertObservationCurrent();if (target?.success !== true || target.tag !== 'button' || target.ref_id !== args.ref_id|| target.documentToken !== prepared.documentToken || target.refScopeUrl !== prepared.refScopeUrl) return null;return (!!prepared.buttonStrongState && !!target.fallbackStrongState@@ -18651,7 +18676,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst observed = await this._observeClickAxTimed(tabId, baseline,{ allowDelayed: !targetStateChanged, firstDelayMs: 250, pollMs: 150, maxMs: 1000,observeTrustedTarget }, timing, 'trustedObservationMs');- assertObservationCurrent();+ await assertObservationCurrent();if (timing) Object.assign(timing.nativeButtonObservation, {afterSnapshotAvailable: typeof observed?.snapshot === 'string' && observed.snapshot.length > 0,observable: observed?.observable === true, proved: observed?.proved === true, safetyVeto: observed?.safetyVeto === true,@@ -18659,7 +18684,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dtabSetChanged: observed?.safetyReasons?.includes('tab_set') === true,downloadObserved: observed?.safetyReasons?.includes('download') === true,});- const verifiedLocalEffect = targetStateChanged || observed.proved === true;+ // The route this press produced is proof even though its button left+ // with the previous route, which makes the target itself unobservable.+ // A fragment-only change (a scrollspy hash, say) is tolerated, not proof,+ // and so is a route reached by Back/Forward: any frame's script can go+ // back in the tab's history, not only this button's page.+ const routeChanged = this._pageFeedbackAgentRouteCurrent(tabId, run, baseline.startedAt, { proof: true })+ && urlWithoutFragment(run.url) !== urlWithoutFragment(dispatchCall.modelState?.url);+ const verifiedLocalEffect = targetStateChanged || observed.proved === true || routeChanged;+ const observedEffects = [...new Set([...(targetStateChanged ? ['target_state'] : []),+ ...(observed.proofReasons || []), ...(routeChanged ? ['url'] : [])])];assertNotAborted();// Press and release were acknowledged. A new explicit action certificate// may follow, even if its page effect is unverified. This proves delivery,@@ -18671,7 +18705,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dtrusted: true, verified: verifiedLocalEffect,nativeInputAcknowledged: true, observationInterrupted: false,effectVerificationPending: !verifiedLocalEffect,- ...(verifiedLocalEffect ? { observedEffects: targetStateChanged ? ['target_state', ...observed.proofReasons] : observed.proofReasons }+ ...(verifiedLocalEffect ? { observedEffects }: { inconclusive: true, retryable: false,warning: 'The click was delivered. Its effect needs a fresh observation before completion or another action.' }),...(observed.snapshot ? { _clickAxAfterSnapshot: observed.snapshot } : {}) };@@ -18699,7 +18733,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// A failed read cannot erase completed input delivery. Preserve the// pending lock while the ordinary execution loop obtains fresh proof.try {- assertCurrent();+ await assertObservedOwner();if (run.lastUserAt === clickUserAt&& ![...run.events.values()].some(event => event.source === 'user')) {return { success: true, method: 'cdp-native-button', initialTrustedNativeButton: true,diff --git a/src/chrome/src/agent/page-feedback.js b/src/chrome/src/agent/page-feedback.jsindex 7e7fb64d1..338551e57 100644--- a/src/chrome/src/agent/page-feedback.js+++ b/src/chrome/src/agent/page-feedback.js@@ -11,6 +11,11 @@ const EVENT_LIMIT = 32;const PAGE_GESTURE_LEASE_MS = 15000;// SPA route updates follow their activating click within this window.const AGENT_SAME_DOCUMENT_NAVIGATION_MS = 3000;+// A page route update this soon after physical input is the user's.+const USER_NAVIGATION_PROXIMITY_MS = 2000;+// How long a same-document Back/Forward update waits for its frame monitor's+// page-initiated reading before the user attribution simply stands.+const PAGE_TRAVERSAL_ATTRIBUTION_MS = 500;const FEEDBACK_MESSAGE_KINDS = new Set(['page_feedback', 'page_feedback_capture', 'page_action_observation', 'page_feedback_recovery']);const TERMINAL_TOOLS = new Set(['done', 'done_json']);const dispatchOwners = new Map();@@ -43,6 +48,22 @@ function automaticAnswerFeedback(events) {|| (event.kind === 'activity' && event.source === 'page')));}+// Firefox (147+) has the Navigation API too, but whether Gecko reports its+// own Back/Forward buttons as userInitiated is unverified, so Firefox keeps+// the browser-UI attribution of every Back/Forward update.+function pageTraversalReadable() {+ try { return typeof apiFor()?.runtime?.getBrowserInfo !== 'function'; } catch { return false; }+}++// Resolves with the reply, or null on rejection or after `ms`.+function settleWithin(promise, ms) {+ return new Promise(resolve => {+ const timer = setTimeout(() => resolve(null), ms);+ Promise.resolve(promise).then(value => { clearTimeout(timer); resolve(value); },+ () => { clearTimeout(timer); resolve(null); });+ });+}+// Busy renderers can stall browser messaging indefinitely; Stop must not wait.function untilAborted(promise, signal) {if (!signal) return Promise.resolve(promise);@@ -623,6 +644,7 @@ export const pageFeedbackMethods = {clearGestureLease(run, frameId);// A replaced document cannot inherit a click's same-document route marker.if (frameId === 0 || run.sameDocumentNavigation?.frameId === frameId) run.sameDocumentNavigation = null;+ if (frameId === 0) run.agentRoute = null;run.documents.set(frameId, { id: details.documentId || '', url: details.url || '',parentFrameId: Number.isSafeInteger(details.parentFrameId) ? details.parentFrameId : undefined });if (frameId === 0) {@@ -635,6 +657,9 @@ export const pageFeedbackMethods = {const qualifiers = details.transitionQualifiers || [];const explicit = ['typed', 'auto_bookmark', 'generated', 'keyword', 'keyword_generated'].includes(details.transitionType)|| qualifiers.includes('from_address_bar');+ // Any frame's script, not only this document's, can move the tab's joint+ // history: a route reached by Back/Forward is never a press's own proof.+ if (frameId === 0 && qualifiers.includes('forward_back')) run.traversedAt = Date.now();const navigation = run.navigation;const redirect = qualifiers.some(q => /redirect$/.test(q));const firstRedirect = type === 'committed' && !navigation?.redirectChain && redirect@@ -656,28 +681,152 @@ export const pageFeedbackMethods = {redirectChain: true, documentId: details.documentId };} else run.navigation = null;}- if (agentNavigation) return;+ if (agentNavigation) {+ if (frameId === 0 && type !== 'committed') run.agentRoute = { at: Date.now(), url: run.url, operationId: navigation.operationId || '' };+ return;+ }// A route update after the agent's own click in the same frame, before any// user activity, is that action's effect. The URL change still invalidates- // bound model state through the URL check.- const sameDocument = run.sameDocumentNavigation;+ // bound model state through the URL check; agentRoute lets that action's+ // own in-flight observation recognise the route it produced. A Back/Forward+ // update whose attribution is still being read (below) is not yet user+ // activity for the updates that follow it in any frame, such as a state+ // restore or an embed the re-render inserts.+ const sameDocument = run.sameDocumentNavigation, reading = run.traversalAttribution;+ const userAt = reading && run.lastUserAt === reading.at ? reading.previousUserAt : run.lastUserAt;if (['history', 'fragment'].includes(type) && !explicit && !qualifiers.includes('forward_back')&& sameDocument?.frameId === frameId && Date.now() - sameDocument.at < AGENT_SAME_DOCUMENT_NAVIGATION_MS- && run.lastUserAt <= sameDocument.userAt) return;- const source = explicit || (!run.navigation && (Date.now() - run.lastUserAt < 2000 || qualifiers.includes('forward_back'))) ? 'user' : 'unknown';+ && userAt <= sameDocument.userAt) {+ if (frameId === 0) run.agentRoute = { at: Date.now(), url: run.url, operationId: sameDocument.operationId || '' };+ return;+ }+ if (frameId === 0) run.agentRoute = null;+ const source = explicit || (!run.navigation && (Date.now() - userAt < USER_NAVIGATION_PROXIMITY_MS+ || qualifiers.includes('forward_back'))) ? 'user' : 'unknown';+ const now = Date.now(), previousUserAt = run.lastUserAt, previousActivityAt = run.lastActivityAt;// Browser-UI navigation is itself user input. Proximity attribution must not// renew lastUserAt, or periodic page navigations would chain forever.- if (explicit || qualifiers.includes('forward_back')) run.lastUserAt = Date.now();+ if (explicit || qualifiers.includes('forward_back')) run.lastUserAt = now;// Child-frame and same-document updates without user attribution are page// observations. They must not keep the user idle gate closed indefinitely.- if (source === 'user' || (frameId === 0 && type === 'committed')) run.lastActivityAt = Date.now();+ if (source === 'user' || (frameId === 0 && type === 'committed')) run.lastActivityAt = now;// An automatic child-document replacement is page churn, like that frame's// DOM updates: model state keeps binding the main document and authority.if (source !== 'user' && frameId > 0 && type === 'committed') {run.modelState?.frames?.delete(frameId); run.capturingModelState?.frames?.delete(frameId);}+ const key = `${frameId}:navigation:`, coalesced = run.events.has(key);this._queuePageFeedback(details.tabId, { kind: 'navigation', source, frameId,before: clean(before, 2000), after: clean(details.url, 2000), navigationType: type });+ // A page's own history.back() (Mastodon leaves /publish this way after a+ // post) arrives as forward_back too, with its destination entry's original+ // transition type ("typed" for a page first opened by address). Ask the+ // frame's monitor whether page script started this exact traversal; until+ // it answers, the browser-UI attribution above stands.+ if (['history', 'fragment'].includes(type) && source === 'user' && qualifiers.includes('forward_back')+ && !coalesced && run.frames.has(frameId) && run.events.get(key) && pageTraversalReadable()) {+ this._beginPageTraversalAttribution(details.tabId, run, { frameId, url: details.url || '', at: now,+ previousUserAt, previousActivityAt, item: run.events.get(key), sameDocument });+ }+ },++ // Browser Back/Forward and a page script's own traversal share the+ // forward_back qualifier. Only the frame's monitor can tell them apart, from+ // the trusted Navigation API event (userInitiated is true for browser UI).+ // A confirmed page-initiated traversal with nothing else observed since+ // withdraws the conservative user attribution: within the agent click's+ // same-document window it is that click's effect, like a pushState route+ // (tolerated, but never proof: another frame can start a Back too);+ // otherwise it is attributed like any page route update. No reply, a+ // timeout, Firefox, a browser without the Navigation API, or any later+ // activity keeps 'user'.+ _beginPageTraversalAttribution(tabId, run, pending) {+ pending.original = pending.item;+ run.traversalAttribution = pending;+ pending.settled = (async () => {+ let reply = null;+ try {+ reply = await settleWithin(apiFor().tabs.sendMessage(tabId, { target: 'content', action: 'page_monitor_traversal',+ params: { runToken: run.token, url: pending.url } }, { frameId: pending.frameId }), PAGE_TRAVERSAL_ATTRIBUTION_MS);+ } catch { /* An unreachable monitor keeps the conservative attribution. */ }+ if (run.traversalAttribution === pending) run.traversalAttribution = null;+ let kept = { outcome: 'user', reason: 'changed' };+ try { kept = this._applyPageTraversalAttribution(tabId, run, pending, reply); } catch { /* Keep 'user'. */ }+ try {+ if (kept.outcome !== 'click_effect' && this._pageFeedbackRuns?.get(tabId) === run) {+ // What the click was credited with while this reading was pending+ // followed the traversal instead: no route of it is the click's,+ // and the queued update ends where those updates left the frame.+ if (run.agentRoute && run.agentRoute.at >= pending.at) run.agentRoute = null;+ const item = run.events.get(`${pending.frameId}:navigation:`);+ if (pending.frameId === 0 && item && item === pending.item) item.after = clean(run.url, 2000);+ }+ } catch { /* The kept attribution stands. */ }+ // Metadata only: which attribution a traversal finally kept, and why.+ const runId = this._pageFeedbackRuns?.get(tabId) === run ? this.currentRunId?.get(tabId) : null;+ if (runId) {+ try { trace.recordNote(runId, 0, 'page_traversal_attribution', kept)?.catch?.(() => {}); } catch { /* Diagnostics only. */ }+ }+ })();+ return pending.settled;+ },++ _applyPageTraversalAttribution(tabId, run, pending, reply) {+ const key = `${pending.frameId}:navigation:`;+ if (this._pageFeedbackRuns?.get(tabId) !== run || this._checkAbort?.(tabId)) return { outcome: 'user', reason: 'changed' };+ if (reply?.ready !== true || reply.runToken !== run.token+ || reply.documentToken !== run.frames.get(pending.frameId)?.token) return { outcome: 'user', reason: 'no_reading' };+ if (reply.pageInitiated !== true) return { outcome: 'user', reason: 'not_page_initiated' };+ // This traversal's own observation is still queued (or only merged with+ // page-attributed updates), and no physical input or other user-attributed+ // observation arrived since.+ if (pending.superseded || run.events.get(key) !== pending.item || run.lastUserAt !== pending.at+ || [...run.events.values()].some(event => event !== pending.item && event.source === 'user')) {+ return { outcome: 'user', reason: 'changed' };+ }+ // Page script's traversal is not physical input: it never renews the user time.+ run.lastUserAt = pending.previousUserAt;+ const restoreActivity = () => { if (run.lastActivityAt === pending.at) run.lastActivityAt = pending.previousActivityAt; };+ const marker = pending.sameDocument;+ if (pending.item === pending.original && marker && marker === run.sameDocumentNavigation+ && marker.frameId === pending.frameId && pending.at - marker.at < AGENT_SAME_DOCUMENT_NAVIGATION_MS+ && pending.previousUserAt <= marker.userAt) {+ restoreActivity();+ run.events.delete(key);+ // A later agent-attributed route (a state restore) stays the current one.+ if (pending.frameId === 0 && !(run.agentRoute && run.agentRoute.at >= pending.at)) {+ run.agentRoute = { at: pending.at, url: pending.url, operationId: marker.operationId || '' };+ }+ return { outcome: 'click_effect', reason: 'page_initiated' };+ }+ // Otherwise it is an ordinary page route update, attributed like a+ // pushState: the user's right after their own input or during a held+ // gesture (a press the page answers by going back), else the page's.+ if (pending.at - pending.previousUserAt < USER_NAVIGATION_PROXIMITY_MS || run.gestures.size) {+ return { outcome: 'user', reason: 'recent_input' };+ }+ restoreActivity();+ pending.item.source = 'unknown';+ return { outcome: 'page', reason: 'page_initiated' };+ },++ // The current main-frame route is the result of a same-document update this+ // run attributed to the action in flight (its dispatch operation), at or+ // after `since`. As proof of that action's effect, the route must also not+ // have been reached through Back/Forward since then.+ _pageFeedbackAgentRouteCurrent(tabId, run, since = 0, { proof = false } = {}) {+ const operationId = dispatchOwners.get(tabId)?.operationId || '';+ return !!run?.agentRoute && !!run.url && run.agentRoute.url === run.url && run.agentRoute.at >= since+ && !!operationId && run.agentRoute.operationId === operationId+ && (!proof || !(run.traversedAt >= since));+ },++ // Bounded: each pending traversal attribution settles within its timeout.+ // Stop does not wait for it.+ async _pageFeedbackTraversalSettled(run, signal = null) {+ for (let attempt = 0; attempt < 3 && run?.traversalAttribution; attempt++) {+ await untilAborted(run.traversalAttribution.settled, signal);+ }},_queuePageFeedback(tabId, item) {@@ -687,12 +836,20 @@ export const pageFeedbackMethods = {run.revision++;const key = `${item.frameId}:${item.kind}:${item.target || ''}`;const previous = run.events.get(key);+ const reportedSource = item.source;// Coalescing keeps the strongest attribution: a later page or unknown// report for the same key cannot downgrade user or unknown evidence.if (previous && feedbackSeverity(previous.source) > feedbackSeverity(item.source)) item.source = previous.source;// Preserve the starting URL across redirect/history bursts.const stored = { ...item, ...(previous?.before ? { before: previous.before } : {}) };run.events.set(key, stored);+ // A traversal still being read follows its observation through merges+ // with page-attributed updates; a user-attributed one settles it as 'user'.+ const reading = run.traversalAttribution;+ if (reading && previous && previous === reading.item) {+ if (reportedSource === 'user') reading.superseded = true;+ else reading.item = stored;+ }if (stored.kind === 'dom' && stored.source === 'unknown') {// Coalescing keeps every in-flight context seen for this key; overflow// is treated as foreign attribution.@@ -1389,6 +1546,10 @@ export const pageFeedbackMethods = {await this._waitForPageFeedbackIdle(tabId, { automaticAskReply, askReply });const run = this._pageFeedbackRuns?.get(tabId);if (!run || this._checkAbort(tabId)) return false;+ // A Back/Forward reading still pending can withdraw an observation (a+ // page's own Back after an agent click); only what remains is applied.+ try { await this._pageFeedbackTraversalSettled(run, this._runAbortSignal(tabId)); } catch { return false; }+ if (this._pageFeedbackRuns?.get(tabId) !== run || this._checkAbort(tabId) || !run.events.size) return false;const events = [...run.events.values()], batchRevision = run.revision;const state = run.modelState || { token: run.token, url: run.latestPage?.url || run.url,page: run.latestPage, frames: new Map(), steeringRevision: this._steeringRuns?.get(tabId)?.acceptedIds.size || 0 };diff --git a/src/chrome/src/content/page-monitor.js b/src/chrome/src/content/page-monitor.jsindex 9377fe373..310667b1c 100644--- a/src/chrome/src/content/page-monitor.js+++ b/src/chrome/src/content/page-monitor.js@@ -21,6 +21,8 @@const MODEL_SCAN_LIMIT = 2048;const MODEL_PUBLIC_MAX = 12000;const MODEL_EVIDENCE_MAX = 2000;+ // The background asks about a traversal right after its route update.+ const TRAVERSAL_READING_MS = 1000;const agentLayoutHistory = [];const nativeTargets = new Set();// Weak references keep disconnected fields from outliving the DOM until their batch is sampled.@@ -40,6 +42,7 @@// frame resize). Legacy bindings without a private footprint keep this fence.let uncertainRevision = 0, uncertainUnreported = 0;let interventionDiagnostic = '';+ let lastTraversal = null, startedTraversal = null;let lastViewport = '';let agentResize = null;let lastFeedbackDelivery = Promise.resolve();@@ -3353,7 +3356,7 @@revokeRelaxedGrant();active = false; runToken = ''; activePointers.clear(); pointerHeld = false; composing = false;clearTimeout(agentResize?.timer); agentResize = null;- lastUserAt = 0; lastViewport = ''; userTurn = null; lastUserTarget = null; matchedEvents = new WeakMap(); controlIterator = null; preparedOperationCursor = 0;+ lastUserAt = 0; lastViewport = ''; lastTraversal = null; startedTraversal = null; userTurn = null; lastUserTarget = null; matchedEvents = new WeakMap(); controlIterator = null; preparedOperationCursor = 0;document.documentElement?.removeAttribute(fenceAttribute);for (const el of nativeTargets) {el.removeAttribute?.('data-webbrain-native-action');@@ -3827,6 +3830,19 @@...(result.certificationFailure ? { certificationFailure: result.certificationFailure } : {}),...(result.reason ? { reason: result.reason } : {}), runToken, documentToken, snapshotToken: params.snapshotToken });}+ else if (msg.action === 'page_monitor_traversal') {+ // Value-free: the background names the URL it already observed; only+ // whether page script started this document's latest traversal there+ // leaves the page. A reading answers once, while fresh, so a later+ // Back the page kept from this listener cannot reuse it.+ const params = msg.params || {};+ const current = active && params.runToken === runToken;+ const traversal = current && typeof params.url === 'string' && lastTraversal?.url === params.url ? lastTraversal : null;+ if (traversal) lastTraversal = null;+ respond({ ready: current, runToken: current ? runToken : '', documentToken,+ pageInitiated: traversalReadable && !!traversal && traversal.pageInitiated === true+ && Date.now() - traversal.at <= TRAVERSAL_READING_MS });+ }else if (msg.action === 'page_monitor_prepare') { respond({ ready: true, ...prepare(msg.params || {}) }); }else if (msg.action === 'page_monitor_resize_begin') { respond({ ready: beginAgentResize(msg.params || {}) }); }else if (msg.action === 'page_monitor_resize_finish') {@@ -3916,11 +3932,44 @@}};api.runtime.onMessage.addListener(onMessage);+ // Browser Back/Forward and the page's own history.back() both reach the+ // background as forward_back route updates. Only the trusted Navigation API+ // event tells them apart: userInitiated is true for browser UI. A page can+ // stop listeners registered after its own, so only a monitor that started+ // at document start, before the root had any element and so before any page+ // script, may certify a page-initiated traversal; a re-injected monitor never+ // does, even while the document is still loading. A traversal counts once it+ // changed the current entry. Any other navigate, a cancelled or failed one,+ // and Stop clear what was started.+ const traversalReadable = document.readyState === 'loading' && !document.documentElement?.firstElementChild;+ const onNavigate = event => {+ if (!event.isTrusted) return;+ startedTraversal = null;+ if (!active || event.navigationType !== 'traverse' || event.defaultPrevented) return;+ startedTraversal = { at: Date.now(), url: String(event.destination?.url || ''),+ pageInitiated: event.userInitiated === false && event.destination?.sameDocument === true };+ };+ const onNavigateError = event => { if (event.isTrusted) startedTraversal = null; };+ const onCurrentEntryChange = event => {+ if (!event.isTrusted) return;+ const started = startedTraversal; startedTraversal = null;+ if (!active || event.navigationType !== 'traverse') return;+ const url = String(navigationApi.currentEntry?.url || '');+ lastTraversal = started && started.url === url && Date.now() - started.at <= TRAVERSAL_READING_MS+ ? { ...started, at: Date.now() } : null;+ };+ const navigationApi = typeof window.navigation?.addEventListener === 'function' ? window.navigation : null;+ navigationApi?.addEventListener('navigate', onNavigate, true);+ navigationApi?.addEventListener('navigateerror', onNavigateError, true);+ navigationApi?.addEventListener('currententrychange', onCurrentEntryChange, true);window.__wbPageMonitor = { beginContentAction, beforeLocalDispatch, withLocalPreparation, withLocalDispatch, captureLocalInputObservation, dispatch: params => dispatch(params), activatePreparedDispatch, withPreparedDispatch, registerDecoration, isReadonlyPreparationDecoration, currentIdentityPreparationCapture,get active() { return active; },get disposed() { return disposed; },dispose() {disposed = true; requestGeneration++; stop(); api.runtime.onMessage.removeListener?.(onMessage);+ navigationApi?.removeEventListener('navigate', onNavigate, true);+ navigationApi?.removeEventListener('navigateerror', onNavigateError, true);+ navigationApi?.removeEventListener('currententrychange', onCurrentEntryChange, true);window.removeEventListener('pageshow', onPageShow);} };void requestState();diff --git a/src/firefox/src/agent/adapters.js b/src/firefox/src/agent/adapters.jsindex f99e29e50..a1aceb27a 100644--- a/src/firefox/src/agent/adapters.js+++ b/src/firefox/src/agent/adapters.js@@ -15680,6 +15680,18 @@ function isMastodonAppPath(hostname, path) {&& /^\/(?:home|deck|web|notifications|explore|public|public\/local|settings|lists|publish|start|get-started|get-started\/profile|getting-started)(?:\/|$)/i.test(path);}+// The web app's other columns (Favourites, Bookmarks, ...) are the same+// Mastodon app as Home: its adapter notes, publication receipts and native+// post handling follow a task there too, for example a reply started from+// Favourites. isMastodonUrl keeps its narrower list for the page observers+// (isMastodonPageUrl) and the finance-site exclusion.+function isMastodonAdapterUrl(url) {+ if (isMastodonUrl(url)) return true;+ const u = new URL(url);+ return /^https?:$/.test(u.protocol) && isLikelyMastodonHost(u.hostname)+ && /^\/(?:favourites|bookmarks|conversations|followed_tags|pinned|directory|follow_requests|mutes|blocks|domain_blocks|search|tags)(?:\/|$)/i.test(safeDecodePath(u.pathname));+}+function isMastodonLocalProfilePath(hostname, path) {return isLikelyMastodonHost(hostname) && /^\/@[A-Za-z0-9_]+\/?$/.test(path);}@@ -17932,7 +17944,7 @@ const ADAPTERS = [// known sites (for example TikTok) preserve their own guidance.name: 'mastodon',category: 'general',- matches: isMastodonUrl,+ matches: isMastodonAdapterUrl,fullPageCapture: { infiniteScroll: isMastodonInfiniteScrollUrl },notes: `- For public media downloads, call an enabled \`download_public_media\` skill first with the exact status permalink (/@<user>/<id> or /users/<user>/statuses/<id>); on a timeline/profile, identify the visible post and its link first. FreeSkillz supports public Mastodon media across instances without browser cookies. Never send followers-only/direct posts; use \`download_social_media\` only if the skill is unavailable or fails.@@ -17941,7 +17953,9 @@ const ADAPTERS = [- After submitting the home domain, expect a redirect to the user's own instance with a remote URL like \`https://mastoturk.org/@[email protected]\`; wait_for_stable there. For account/profile follow flows, click Follow; for status or authorize_interaction flows, complete the requested action on the home-instance page (reply, boost, favorite, or follow).- Do NOT manually synthesize the home-instance URL before this handoff. The home instance may need the remote-profile lookup/redirect to recognize the account.- Label variants by version/language: "Sign in to continue", "Continue on your server", "Authorize interaction", "Proceed to follow"; Turkish: Takip et=Follow, sunucu/domain=server domain.-- If the user's Mastodon home domain is not already known from the conversation or account UI, clarify once before entering anything.`,+- If the user's Mastodon home domain is not already known from the conversation or account UI, clarify once before entering anything.+- Liked (favourited) posts are listed at /favourites. To reply, click that post's Reply button ("Yanıtla" in Turkish; the composer's submit has the same label). The composer opens with the thread's @mentions prefilled (narrow layouts open it at /publish): start your text with them exactly once instead of clearing them.+- After a reply posts, the composer empties and narrow layouts go back to the previous column; Favourites does not show your reply. Verify it under the replied-to post: open its timestamp link (the post's permalink) and find your reply below it. If a submit's outcome is uncertain, check there before any retry; never post the same reply twice. With several posts to reply to, finish and verify one, then move to the next.`,},...CMS_ADAPTERS,];diff --git a/src/firefox/src/agent/page-feedback.js b/src/firefox/src/agent/page-feedback.jsindex 7e7fb64d1..338551e57 100644--- a/src/firefox/src/agent/page-feedback.js+++ b/src/firefox/src/agent/page-feedback.js@@ -11,6 +11,11 @@ const EVENT_LIMIT = 32;const PAGE_GESTURE_LEASE_MS = 15000;// SPA route updates follow their activating click within this window.const AGENT_SAME_DOCUMENT_NAVIGATION_MS = 3000;+// A page route update this soon after physical input is the user's.+const USER_NAVIGATION_PROXIMITY_MS = 2000;+// How long a same-document Back/Forward update waits for its frame monitor's+// page-initiated reading before the user attribution simply stands.+const PAGE_TRAVERSAL_ATTRIBUTION_MS = 500;const FEEDBACK_MESSAGE_KINDS = new Set(['page_feedback', 'page_feedback_capture', 'page_action_observation', 'page_feedback_recovery']);const TERMINAL_TOOLS = new Set(['done', 'done_json']);const dispatchOwners = new Map();@@ -43,6 +48,22 @@ function automaticAnswerFeedback(events) {|| (event.kind === 'activity' && event.source === 'page')));}+// Firefox (147+) has the Navigation API too, but whether Gecko reports its+// own Back/Forward buttons as userInitiated is unverified, so Firefox keeps+// the browser-UI attribution of every Back/Forward update.+function pageTraversalReadable() {+ try { return typeof apiFor()?.runtime?.getBrowserInfo !== 'function'; } catch { return false; }+}++// Resolves with the reply, or null on rejection or after `ms`.+function settleWithin(promise, ms) {+ return new Promise(resolve => {+ const timer = setTimeout(() => resolve(null), ms);+ Promise.resolve(promise).then(value => { clearTimeout(timer); resolve(value); },+ () => { clearTimeout(timer); resolve(null); });+ });+}+// Busy renderers can stall browser messaging indefinitely; Stop must not wait.function untilAborted(promise, signal) {if (!signal) return Promise.resolve(promise);@@ -623,6 +644,7 @@ export const pageFeedbackMethods = {clearGestureLease(run, frameId);// A replaced document cannot inherit a click's same-document route marker.if (frameId === 0 || run.sameDocumentNavigation?.frameId === frameId) run.sameDocumentNavigation = null;+ if (frameId === 0) run.agentRoute = null;run.documents.set(frameId, { id: details.documentId || '', url: details.url || '',parentFrameId: Number.isSafeInteger(details.parentFrameId) ? details.parentFrameId : undefined });if (frameId === 0) {@@ -635,6 +657,9 @@ export const pageFeedbackMethods = {const qualifiers = details.transitionQualifiers || [];const explicit = ['typed', 'auto_bookmark', 'generated', 'keyword', 'keyword_generated'].includes(details.transitionType)|| qualifiers.includes('from_address_bar');+ // Any frame's script, not only this document's, can move the tab's joint+ // history: a route reached by Back/Forward is never a press's own proof.+ if (frameId === 0 && qualifiers.includes('forward_back')) run.traversedAt = Date.now();const navigation = run.navigation;const redirect = qualifiers.some(q => /redirect$/.test(q));const firstRedirect = type === 'committed' && !navigation?.redirectChain && redirect@@ -656,28 +681,152 @@ export const pageFeedbackMethods = {redirectChain: true, documentId: details.documentId };} else run.navigation = null;}- if (agentNavigation) return;+ if (agentNavigation) {+ if (frameId === 0 && type !== 'committed') run.agentRoute = { at: Date.now(), url: run.url, operationId: navigation.operationId || '' };+ return;+ }// A route update after the agent's own click in the same frame, before any// user activity, is that action's effect. The URL change still invalidates- // bound model state through the URL check.- const sameDocument = run.sameDocumentNavigation;+ // bound model state through the URL check; agentRoute lets that action's+ // own in-flight observation recognise the route it produced. A Back/Forward+ // update whose attribution is still being read (below) is not yet user+ // activity for the updates that follow it in any frame, such as a state+ // restore or an embed the re-render inserts.+ const sameDocument = run.sameDocumentNavigation, reading = run.traversalAttribution;+ const userAt = reading && run.lastUserAt === reading.at ? reading.previousUserAt : run.lastUserAt;if (['history', 'fragment'].includes(type) && !explicit && !qualifiers.includes('forward_back')&& sameDocument?.frameId === frameId && Date.now() - sameDocument.at < AGENT_SAME_DOCUMENT_NAVIGATION_MS- && run.lastUserAt <= sameDocument.userAt) return;- const source = explicit || (!run.navigation && (Date.now() - run.lastUserAt < 2000 || qualifiers.includes('forward_back'))) ? 'user' : 'unknown';+ && userAt <= sameDocument.userAt) {+ if (frameId === 0) run.agentRoute = { at: Date.now(), url: run.url, operationId: sameDocument.operationId || '' };+ return;+ }+ if (frameId === 0) run.agentRoute = null;+ const source = explicit || (!run.navigation && (Date.now() - userAt < USER_NAVIGATION_PROXIMITY_MS+ || qualifiers.includes('forward_back'))) ? 'user' : 'unknown';+ const now = Date.now(), previousUserAt = run.lastUserAt, previousActivityAt = run.lastActivityAt;// Browser-UI navigation is itself user input. Proximity attribution must not// renew lastUserAt, or periodic page navigations would chain forever.- if (explicit || qualifiers.includes('forward_back')) run.lastUserAt = Date.now();+ if (explicit || qualifiers.includes('forward_back')) run.lastUserAt = now;// Child-frame and same-document updates without user attribution are page// observations. They must not keep the user idle gate closed indefinitely.- if (source === 'user' || (frameId === 0 && type === 'committed')) run.lastActivityAt = Date.now();+ if (source === 'user' || (frameId === 0 && type === 'committed')) run.lastActivityAt = now;// An automatic child-document replacement is page churn, like that frame's// DOM updates: model state keeps binding the main document and authority.if (source !== 'user' && frameId > 0 && type === 'committed') {run.modelState?.frames?.delete(frameId); run.capturingModelState?.frames?.delete(frameId);}+ const key = `${frameId}:navigation:`, coalesced = run.events.has(key);this._queuePageFeedback(details.tabId, { kind: 'navigation', source, frameId,before: clean(before, 2000), after: clean(details.url, 2000), navigationType: type });+ // A page's own history.back() (Mastodon leaves /publish this way after a+ // post) arrives as forward_back too, with its destination entry's original+ // transition type ("typed" for a page first opened by address). Ask the+ // frame's monitor whether page script started this exact traversal; until+ // it answers, the browser-UI attribution above stands.+ if (['history', 'fragment'].includes(type) && source === 'user' && qualifiers.includes('forward_back')+ && !coalesced && run.frames.has(frameId) && run.events.get(key) && pageTraversalReadable()) {+ this._beginPageTraversalAttribution(details.tabId, run, { frameId, url: details.url || '', at: now,+ previousUserAt, previousActivityAt, item: run.events.get(key), sameDocument });+ }+ },++ // Browser Back/Forward and a page script's own traversal share the+ // forward_back qualifier. Only the frame's monitor can tell them apart, from+ // the trusted Navigation API event (userInitiated is true for browser UI).+ // A confirmed page-initiated traversal with nothing else observed since+ // withdraws the conservative user attribution: within the agent click's+ // same-document window it is that click's effect, like a pushState route+ // (tolerated, but never proof: another frame can start a Back too);+ // otherwise it is attributed like any page route update. No reply, a+ // timeout, Firefox, a browser without the Navigation API, or any later+ // activity keeps 'user'.+ _beginPageTraversalAttribution(tabId, run, pending) {+ pending.original = pending.item;+ run.traversalAttribution = pending;+ pending.settled = (async () => {+ let reply = null;+ try {+ reply = await settleWithin(apiFor().tabs.sendMessage(tabId, { target: 'content', action: 'page_monitor_traversal',+ params: { runToken: run.token, url: pending.url } }, { frameId: pending.frameId }), PAGE_TRAVERSAL_ATTRIBUTION_MS);+ } catch { /* An unreachable monitor keeps the conservative attribution. */ }+ if (run.traversalAttribution === pending) run.traversalAttribution = null;+ let kept = { outcome: 'user', reason: 'changed' };+ try { kept = this._applyPageTraversalAttribution(tabId, run, pending, reply); } catch { /* Keep 'user'. */ }+ try {+ if (kept.outcome !== 'click_effect' && this._pageFeedbackRuns?.get(tabId) === run) {+ // What the click was credited with while this reading was pending+ // followed the traversal instead: no route of it is the click's,+ // and the queued update ends where those updates left the frame.+ if (run.agentRoute && run.agentRoute.at >= pending.at) run.agentRoute = null;+ const item = run.events.get(`${pending.frameId}:navigation:`);+ if (pending.frameId === 0 && item && item === pending.item) item.after = clean(run.url, 2000);+ }+ } catch { /* The kept attribution stands. */ }+ // Metadata only: which attribution a traversal finally kept, and why.+ const runId = this._pageFeedbackRuns?.get(tabId) === run ? this.currentRunId?.get(tabId) : null;+ if (runId) {+ try { trace.recordNote(runId, 0, 'page_traversal_attribution', kept)?.catch?.(() => {}); } catch { /* Diagnostics only. */ }+ }+ })();+ return pending.settled;+ },++ _applyPageTraversalAttribution(tabId, run, pending, reply) {+ const key = `${pending.frameId}:navigation:`;+ if (this._pageFeedbackRuns?.get(tabId) !== run || this._checkAbort?.(tabId)) return { outcome: 'user', reason: 'changed' };+ if (reply?.ready !== true || reply.runToken !== run.token+ || reply.documentToken !== run.frames.get(pending.frameId)?.token) return { outcome: 'user', reason: 'no_reading' };+ if (reply.pageInitiated !== true) return { outcome: 'user', reason: 'not_page_initiated' };+ // This traversal's own observation is still queued (or only merged with+ // page-attributed updates), and no physical input or other user-attributed+ // observation arrived since.+ if (pending.superseded || run.events.get(key) !== pending.item || run.lastUserAt !== pending.at+ || [...run.events.values()].some(event => event !== pending.item && event.source === 'user')) {+ return { outcome: 'user', reason: 'changed' };+ }+ // Page script's traversal is not physical input: it never renews the user time.+ run.lastUserAt = pending.previousUserAt;+ const restoreActivity = () => { if (run.lastActivityAt === pending.at) run.lastActivityAt = pending.previousActivityAt; };+ const marker = pending.sameDocument;+ if (pending.item === pending.original && marker && marker === run.sameDocumentNavigation+ && marker.frameId === pending.frameId && pending.at - marker.at < AGENT_SAME_DOCUMENT_NAVIGATION_MS+ && pending.previousUserAt <= marker.userAt) {+ restoreActivity();+ run.events.delete(key);+ // A later agent-attributed route (a state restore) stays the current one.+ if (pending.frameId === 0 && !(run.agentRoute && run.agentRoute.at >= pending.at)) {+ run.agentRoute = { at: pending.at, url: pending.url, operationId: marker.operationId || '' };+ }+ return { outcome: 'click_effect', reason: 'page_initiated' };+ }+ // Otherwise it is an ordinary page route update, attributed like a+ // pushState: the user's right after their own input or during a held+ // gesture (a press the page answers by going back), else the page's.+ if (pending.at - pending.previousUserAt < USER_NAVIGATION_PROXIMITY_MS || run.gestures.size) {+ return { outcome: 'user', reason: 'recent_input' };+ }+ restoreActivity();+ pending.item.source = 'unknown';+ return { outcome: 'page', reason: 'page_initiated' };+ },++ // The current main-frame route is the result of a same-document update this+ // run attributed to the action in flight (its dispatch operation), at or+ // after `since`. As proof of that action's effect, the route must also not+ // have been reached through Back/Forward since then.+ _pageFeedbackAgentRouteCurrent(tabId, run, since = 0, { proof = false } = {}) {+ const operationId = dispatchOwners.get(tabId)?.operationId || '';+ return !!run?.agentRoute && !!run.url && run.agentRoute.url === run.url && run.agentRoute.at >= since+ && !!operationId && run.agentRoute.operationId === operationId+ && (!proof || !(run.traversedAt >= since));+ },++ // Bounded: each pending traversal attribution settles within its timeout.+ // Stop does not wait for it.+ async _pageFeedbackTraversalSettled(run, signal = null) {+ for (let attempt = 0; attempt < 3 && run?.traversalAttribution; attempt++) {+ await untilAborted(run.traversalAttribution.settled, signal);+ }},_queuePageFeedback(tabId, item) {@@ -687,12 +836,20 @@ export const pageFeedbackMethods = {run.revision++;const key = `${item.frameId}:${item.kind}:${item.target || ''}`;const previous = run.events.get(key);+ const reportedSource = item.source;// Coalescing keeps the strongest attribution: a later page or unknown// report for the same key cannot downgrade user or unknown evidence.if (previous && feedbackSeverity(previous.source) > feedbackSeverity(item.source)) item.source = previous.source;// Preserve the starting URL across redirect/history bursts.const stored = { ...item, ...(previous?.before ? { before: previous.before } : {}) };run.events.set(key, stored);+ // A traversal still being read follows its observation through merges+ // with page-attributed updates; a user-attributed one settles it as 'user'.+ const reading = run.traversalAttribution;+ if (reading && previous && previous === reading.item) {+ if (reportedSource === 'user') reading.superseded = true;+ else reading.item = stored;+ }if (stored.kind === 'dom' && stored.source === 'unknown') {// Coalescing keeps every in-flight context seen for this key; overflow// is treated as foreign attribution.@@ -1389,6 +1546,10 @@ export const pageFeedbackMethods = {await this._waitForPageFeedbackIdle(tabId, { automaticAskReply, askReply });const run = this._pageFeedbackRuns?.get(tabId);if (!run || this._checkAbort(tabId)) return false;+ // A Back/Forward reading still pending can withdraw an observation (a+ // page's own Back after an agent click); only what remains is applied.+ try { await this._pageFeedbackTraversalSettled(run, this._runAbortSignal(tabId)); } catch { return false; }+ if (this._pageFeedbackRuns?.get(tabId) !== run || this._checkAbort(tabId) || !run.events.size) return false;const events = [...run.events.values()], batchRevision = run.revision;const state = run.modelState || { token: run.token, url: run.latestPage?.url || run.url,page: run.latestPage, frames: new Map(), steeringRevision: this._steeringRuns?.get(tabId)?.acceptedIds.size || 0 };diff --git a/src/firefox/src/content/page-monitor.js b/src/firefox/src/content/page-monitor.jsindex 9377fe373..310667b1c 100644--- a/src/firefox/src/content/page-monitor.js+++ b/src/firefox/src/content/page-monitor.js@@ -21,6 +21,8 @@const MODEL_SCAN_LIMIT = 2048;const MODEL_PUBLIC_MAX = 12000;const MODEL_EVIDENCE_MAX = 2000;+ // The background asks about a traversal right after its route update.+ const TRAVERSAL_READING_MS = 1000;const agentLayoutHistory = [];const nativeTargets = new Set();// Weak references keep disconnected fields from outliving the DOM until their batch is sampled.@@ -40,6 +42,7 @@// frame resize). Legacy bindings without a private footprint keep this fence.let uncertainRevision = 0, uncertainUnreported = 0;let interventionDiagnostic = '';+ let lastTraversal = null, startedTraversal = null;let lastViewport = '';let agentResize = null;let lastFeedbackDelivery = Promise.resolve();@@ -3353,7 +3356,7 @@revokeRelaxedGrant();active = false; runToken = ''; activePointers.clear(); pointerHeld = false; composing = false;clearTimeout(agentResize?.timer); agentResize = null;- lastUserAt = 0; lastViewport = ''; userTurn = null; lastUserTarget = null; matchedEvents = new WeakMap(); controlIterator = null; preparedOperationCursor = 0;+ lastUserAt = 0; lastViewport = ''; lastTraversal = null; startedTraversal = null; userTurn = null; lastUserTarget = null; matchedEvents = new WeakMap(); controlIterator = null; preparedOperationCursor = 0;document.documentElement?.removeAttribute(fenceAttribute);for (const el of nativeTargets) {el.removeAttribute?.('data-webbrain-native-action');@@ -3827,6 +3830,19 @@...(result.certificationFailure ? { certificationFailure: result.certificationFailure } : {}),...(result.reason ? { reason: result.reason } : {}), runToken, documentToken, snapshotToken: params.snapshotToken });}+ else if (msg.action === 'page_monitor_traversal') {+ // Value-free: the background names the URL it already observed; only+ // whether page script started this document's latest traversal there+ // leaves the page. A reading answers once, while fresh, so a later+ // Back the page kept from this listener cannot reuse it.+ const params = msg.params || {};+ const current = active && params.runToken === runToken;+ const traversal = current && typeof params.url === 'string' && lastTraversal?.url === params.url ? lastTraversal : null;+ if (traversal) lastTraversal = null;+ respond({ ready: current, runToken: current ? runToken : '', documentToken,+ pageInitiated: traversalReadable && !!traversal && traversal.pageInitiated === true+ && Date.now() - traversal.at <= TRAVERSAL_READING_MS });+ }else if (msg.action === 'page_monitor_prepare') { respond({ ready: true, ...prepare(msg.params || {}) }); }else if (msg.action === 'page_monitor_resize_begin') { respond({ ready: beginAgentResize(msg.params || {}) }); }else if (msg.action === 'page_monitor_resize_finish') {@@ -3916,11 +3932,44 @@}};api.runtime.onMessage.addListener(onMessage);+ // Browser Back/Forward and the page's own history.back() both reach the+ // background as forward_back route updates. Only the trusted Navigation API+ // event tells them apart: userInitiated is true for browser UI. A page can+ // stop listeners registered after its own, so only a monitor that started+ // at document start, before the root had any element and so before any page+ // script, may certify a page-initiated traversal; a re-injected monitor never+ // does, even while the document is still loading. A traversal counts once it+ // changed the current entry. Any other navigate, a cancelled or failed one,+ // and Stop clear what was started.+ const traversalReadable = document.readyState === 'loading' && !document.documentElement?.firstElementChild;+ const onNavigate = event => {+ if (!event.isTrusted) return;+ startedTraversal = null;+ if (!active || event.navigationType !== 'traverse' || event.defaultPrevented) return;+ startedTraversal = { at: Date.now(), url: String(event.destination?.url || ''),+ pageInitiated: event.userInitiated === false && event.destination?.sameDocument === true };+ };+ const onNavigateError = event => { if (event.isTrusted) startedTraversal = null; };+ const onCurrentEntryChange = event => {+ if (!event.isTrusted) return;+ const started = startedTraversal; startedTraversal = null;+ if (!active || event.navigationType !== 'traverse') return;+ const url = String(navigationApi.currentEntry?.url || '');+ lastTraversal = started && started.url === url && Date.now() - started.at <= TRAVERSAL_READING_MS+ ? { ...started, at: Date.now() } : null;+ };+ const navigationApi = typeof window.navigation?.addEventListener === 'function' ? window.navigation : null;+ navigationApi?.addEventListener('navigate', onNavigate, true);+ navigationApi?.addEventListener('navigateerror', onNavigateError, true);+ navigationApi?.addEventListener('currententrychange', onCurrentEntryChange, true);window.__wbPageMonitor = { beginContentAction, beforeLocalDispatch, withLocalPreparation, withLocalDispatch, captureLocalInputObservation, dispatch: params => dispatch(params), activatePreparedDispatch, withPreparedDispatch, registerDecoration, isReadonlyPreparationDecoration, currentIdentityPreparationCapture,get active() { return active; },get disposed() { return disposed; },dispose() {disposed = true; requestGeneration++; stop(); api.runtime.onMessage.removeListener?.(onMessage);+ navigationApi?.removeEventListener('navigate', onNavigate, true);+ navigationApi?.removeEventListener('navigateerror', onNavigateError, true);+ navigationApi?.removeEventListener('currententrychange', onCurrentEntryChange, true);window.removeEventListener('pageshow', onPageShow);} };void requestState();diff --git a/test/delivery-native-button-route.mjs b/test/delivery-native-button-route.mjsnew file mode 100644index 000000000..75abe88e1--- /dev/null+++ b/test/delivery-native-button-route.mjs@@ -0,0 +1,359 @@+// Delivery regression: a certified native BUTTON whose own click changes the+// document's route. Mastodon's single-column UI is the field case: a toot's+// Reply button pushes /publish, and the composer's submit posts and then calls+// history.back(). Both route changes are the press's effect, not an+// interrupted observation with an unknown outcome (which made a model re-post+// the same reply). The pushed route is verified proof; a route reached by Back+// is not (any frame's script can go back), so that press is delivered and+// awaits a fresh observation. The browser's own Back stays the user's.+//+// [real DOM, Chromium only: the trusted native-button path is Chrome CDP]+// The real Agent, page-feedback run, page monitor (with its Navigation API+// reading), accessibility tree and content script run unchanged. Only the+// extension transport, debugger session and webNavigation history events are+// bridged to Playwright.+import { chromium } from 'playwright';+import { readFile } from 'node:fs/promises';+import { fileURLToPath, pathToFileURL } from 'node:url';+import path from 'node:path';+import assert from 'node:assert/strict';+import { test } from 'node:test';+import { cdpClient } from '../src/chrome/src/cdp/cdp-client.js';++const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');+const area = { get: async () => ({}), set: async () => {}, remove: async () => {} };+let page, session;+const hooks = { afterRelease: null, traversalReadingDelayMs: 0, operationId: '' };+const commands = [];+const requests = new Set();+const api = {+ storage: { local: area, session: area },+ runtime: { getURL: p => pathToFileURL(path.join(root, 'src/chrome', p)).href },+ tabs: {+ get: async () => ({ id: 17, url: page.url() }),+ query: async () => [{ id: 17, url: page.url() }],+ sendMessage: async (_id, message) => {+ // The dispatch operation of the press in flight, as the monitor is told.+ if (message.action === 'page_monitor_prepare' && message.params?.operationId) hooks.operationId = message.params.operationId;+ if (message.action === 'page_monitor_traversal' && hooks.traversalReadingDelayMs) {+ await new Promise(resolve => setTimeout(resolve, hooks.traversalReadingDelayMs));+ }+ return page.evaluate(message => window.qaMessage(message), message);+ },+ },+ webNavigation: { getAllFrames: async () => [{ frameId: 0, documentId: 'delivery-route-document', url: page.url() }] },+ webRequest: { onBeforeRequest: { addListener: l => requests.add(l), removeListener: l => requests.delete(l) } },+ debugger: { sendCommand: (_target, method, params, callback) => {+ commands.push({ method, type: params.type, x: params.x, y: params.y });+ session.send(method, params).then(result => {+ if (method === 'Input.dispatchMouseEvent' && params.type === 'mouseReleased' && hooks.afterRelease) {+ const after = hooks.afterRelease; hooks.afterRelease = null;+ void after();+ }+ return result;+ }).then(callback, error => {+ api.runtime.lastError = { message: error.message };+ try { callback(); } finally { delete api.runtime.lastError; }+ });+ } },+};+globalThis.chrome = api;+globalThis.browser = api;+const { Agent } = await import('../src/chrome/src/agent/agent.js');++// `/current` is reached from `/start` by the page's own pushState, so a+// traversal back to `/start` stays in this document.+const html = ({ script = '', slowScript = false } = {}) => `<!doctype html><style>body{margin:20px} button{width:200px;height:45px}</style>+<main id="app"></main>+<script>window.qaClicks=[];+const app=document.getElementById('app');+const show=()=>{ app.innerHTML=location.pathname==='/current'+ ? '<h1>Current reply</h1><label>Reply text<textarea>@owned Owned neutral reply</textarea></label><button id="commit" type="button">Post reply</button>'+ : '<h1>'+location.pathname+'</h1><p>Column view</p>';+ const commit=document.getElementById('commit');+ if(commit) commit.addEventListener('click',event=>{qaClicks.push({trusted:event.isTrusted});window.qaOnClick?.();});+};+addEventListener('popstate',()=>{show();window.qaOnPopState?.();});+history.replaceState({},'','/start'); history.pushState({},'','/current'); show();+${script}</script>${slowScript ? '<script src="/slow.js"></script>' : ''}`;++// webNavigation.onHistoryStateUpdated / onReferenceFragmentUpdated as real+// Chrome reports them: a traversal (a browser Back or the page's own+// history.back()) carries forward_back and its destination entry's original+// transition type ("typed" for the page first opened by address); a History+// API push or replace is a "link".+async function fixture(browserInstance, options) {+ const context = await browserInstance.newContext({ viewport: { width: 900, height: 700 } });+ // A parser-blocking script keeps the document loading after its inline+ // script ran, until the fixture releases it.+ let releaseSlowScript = () => {};+ const slowScript = new Promise(resolve => { releaseSlowScript = resolve; });+ await context.route('**/*', async route => {+ const url = route.request().url();+ if (!url.startsWith('https://delivery-route.invalid/')) return route.abort();+ if (new URL(url).pathname === '/slow.js') { await slowScript; return route.fulfill({ contentType: 'text/javascript', body: '' }); }+ return route.fulfill({ contentType: 'text/html', body: html({ ...options, slowScript: !!options.reinjectWhileLoading }) });+ });+ page = await context.newPage();+ const agent = new Agent({ getActive: () => ({ model: 'delivery-model' }) });+ agent._runningTabs.add(17);+ await page.exposeFunction('qaBackground', message => {+ const sender = { tab: { id: 17 }, frameId: 0, documentId: 'delivery-route-document', url: page.url() };+ if (message.action === 'get_page_monitor_state') return agent.pageMonitorState(sender, message.documentToken);+ if (message.action === 'page_feedback') return agent.observePageFeedback(sender, message.feedback);+ return {};+ });+ await page.addInitScript(() => {+ window.qaListeners = [];+ window.chrome = window.browser = { runtime: {+ getURL: p => p,+ onMessage: { addListener: f => qaListeners.push(f), removeListener() {} },+ sendMessage: message => window.qaBackground(message),+ } };+ window.qaMessage = message => new Promise(resolve => {+ let answered = false;+ const respond = value => { answered = true; resolve(value); };+ for (const f of qaListeners) { const value = f(message, {}, respond); if (answered || value === true) return; }+ resolve(undefined);+ });+ });+ for (const name of ['rich-text-toolbar-heuristic.js', 'file-upload-policy.js', 'accessibility-tree.js', 'page-monitor.js', 'content.js']) {+ await page.addInitScript({ content: await readFile(path.join(root, 'src/chrome/src/content', name), 'utf8') });+ }+ const monitorSource = await readFile(path.join(root, 'src/chrome/src/content/page-monitor.js'), 'utf8');+ if (options.reinjectWhileLoading) {+ // A monitor re-injected after page scripts ran, while the document still+ // loads (a recovery injection into a slow page).+ await page.goto('https://delivery-route.invalid/entry', { waitUntil: 'commit' });+ await page.waitForFunction(() => Array.isArray(window.qaClicks) && document.readyState === 'loading', null, { polling: 25 });+ await page.evaluate(() => window.__wbPageMonitor?.dispose());+ await page.evaluate(source => (0, eval)(source), monitorSource);+ assert.equal(await page.evaluate(() => document.readyState), 'loading');+ releaseSlowScript();+ await page.waitForLoadState('load');+ } else {+ releaseSlowScript();+ await page.goto('https://delivery-route.invalid/entry');+ }+ if (options.lateMonitor) {+ // A monitor injected after the page loaded (an extension update with the+ // tab left open): page scripts may have registered listeners before it.+ await page.evaluate(() => window.__wbPageMonitor?.dispose());+ await page.evaluate(source => (0, eval)(source), monitorSource);+ }+ session = await context.newCDPSession(page);+ await session.send('Page.enable');+ let previousUrl = page.url();+ session.on('Page.navigatedWithinDocument', event => {+ const before = new URL(previousUrl), after = new URL(event.url);+ previousUrl = event.url;+ if (!agent._pageFeedbackRuns?.get(17)) return;+ const traversal = after.pathname === '/start' && !after.search && !after.hash;+ const fragment = before.origin + before.pathname + before.search === after.origin + after.pathname + after.search;+ agent.observePageNavigation({ tabId: 17, frameId: 0, url: event.url, documentId: 'delivery-route-document',+ transitionType: traversal ? 'typed' : 'link', transitionQualifiers: traversal ? ['forward_back'] : [] },+ fragment ? 'fragment' : 'history');+ });+ await agent._beginPageFeedbackRun(17, 'neutral');+ await page.waitForFunction(() => window.__wbPageMonitor?.active);+ await page.mouse.move(5, 690);+ await page.waitForTimeout(180);+ const run = agent._pageFeedbackRuns.get(17);+ run.events.clear();+ const axScope = await api.tabs.sendMessage(17, { target: 'content', action: 'get_accessibility_tree', params: { filter: 'visible', maxChars: 12000 } });+ const capture = await api.tabs.sendMessage(17, { target: 'content', action: 'page_monitor_capture_model',+ params: { runToken: run.token, includeTree: true } });+ const ref = capture.page.pageContent.match(/button "Post reply" \[(ref_[A-Za-z0-9_-]+)\]/)?.[1];+ assert.ok(ref, capture.page.pageContent);+ const state = { token: run.token, url: run.url, steeringRevision: 0, frames: new Map(run.frames),+ actionBinding: { snapshotToken: capture.snapshotToken, runToken: run.token, documentToken: capture.documentToken } };+ run.modelState = state;+ run.dispatchCall = { name: 'click_ax', args: { ref_id: ref }, expectedModelSnapshot: capture.snapshotToken,+ modelState: state, dispatchState: { started: false }, allowPassiveRebase: true };+ const prepared = await api.tabs.sendMessage(17, { target: 'content', action: 'page_monitor_prepare',+ params: { runToken: run.token, tool: 'click_ax', ref_id: ref, operationId: 'delivery-route-operation',+ expectedModelSnapshot: capture.snapshotToken, allowPassiveRebase: true } });+ assert.equal(prepared.modelBindingValid, true);+ commands.length = 0; hooks.afterRelease = null; hooks.traversalReadingDelayMs = 0; hooks.operationId = '';+ agent._settleContentFilePickerGuard = async (_id, result) => result;+ agent._annotateClickProgress = async (_id, _name, _args, result) => result;+ agent._recordInteractionRect = () => {};+ agent._clearUploadSelectorRecoveryAfterInspection = () => {};+ agent._lastAxScopes.set(17, { documentToken: axScope.documentToken, pageUrl: axScope.refScopeUrl });+ return { context, agent, run, ref };+}++const presses = () => commands.filter(call => call.method === 'Input.dispatchMouseEvent' && call.type === 'mousePressed');+const routeOf = () => { const url = new URL(page.url()); return url.pathname + url.search + url.hash; };+const navigationSource = run => [...run.events.values()].find(event => event.kind === 'navigation')?.source;++test('Chrome: a native button\'s own route change is its effect; the browser\'s Back is not', { timeout: 300000 }, async t => {+ const cdpAttach = cdpClient.attach;+ cdpClient.attach = async () => cdpClient.sessions.set(17, {});+ const browserInstance = await chromium.launch({ headless: true });+ try {+ for (const [name, script, route, proof] of [+ // Reply-style: the click handler pushes the next column synchronously.+ ['an SPA pushState to the next column', "window.qaOnClick=()=>{history.pushState({},'','/publish');show();};", '/publish', true],+ // Submit-style: after its network round trip the page goes back itself.+ ['the page\'s own history.back() after a delayed post', 'window.qaOnClick=()=>setTimeout(()=>history.back(),200);', '/start', false],+ // ...and then restores its state while the traversal is still being read.+ ['the page\'s own history.back() followed by a state restore',+ "window.qaOnClick=()=>setTimeout(()=>history.back(),200);window.qaOnPopState=()=>history.replaceState({restored:true},'','/start?restored=1');",+ '/start?restored=1', false],+ ]) await t.test(`${name}: ${proof ? 'verified' : 'delivered'}, one press, no unknown outcome`, async () => {+ const f = await fixture(browserInstance, { script });+ try {+ const result = await f.agent.executeTool(17, 'click_ax', { ref_id: f.ref });+ assert.equal(result.success, true, JSON.stringify(result));+ assert.equal(result.initialTrustedNativeButton, true, JSON.stringify(result));+ assert.notEqual(result.outcomeUnknown, true, JSON.stringify(result));+ assert.notEqual(result.observationInterrupted, true, JSON.stringify(result));+ if (proof) {+ assert.equal(result.verified, true, JSON.stringify(result));+ assert.ok(result.observedEffects?.includes('url'), JSON.stringify(result));+ } else {+ // Tolerated as the press's effect, but a Back is never its url proof.+ assert.notEqual(result.observedEffects?.includes('url'), true, JSON.stringify(result));+ assert.ok(result.verified === true || result.effectVerificationPending === true, JSON.stringify(result));+ }+ assert.deepEqual((await page.evaluate(() => window.qaClicks)).map(click => click.trusted), [true]);+ assert.equal(presses().length, 1, 'exactly one press was sent');+ assert.equal(routeOf(), route);+ assert.equal(navigationSource(f.run), undefined, 'The route change is the click effect, not a navigation observation');+ assert.equal(f.run.agentRoute?.url, page.url());+ assert.ok(f.run.agentRoute?.operationId, 'The route is bound to the dispatch operation that produced it');+ assert.equal(f.agent._pageFeedbackAgentRouteCurrent(17, f.run, 0), false, 'No later action can claim that route');+ assert.equal(f.agent._pageFeedbackStateCurrent(17, f.run, f.run.modelState), false,+ 'The route still invalidates the bound model state for the next decision');+ } finally { await f.context.close(); }+ });++ await t.test('a page traversal reading is answered once', async () => {+ const f = await fixture(browserInstance, { script: 'window.qaOnClick=()=>setTimeout(()=>history.back(),200);' });+ try {+ const result = await f.agent.executeTool(17, 'click_ax', { ref_id: f.ref });+ assert.equal(result.success, true, JSON.stringify(result));+ assert.notEqual(result.outcomeUnknown, true, JSON.stringify(result));+ const again = await api.tabs.sendMessage(17, { target: 'content', action: 'page_monitor_traversal',+ params: { runToken: f.run.token, url: page.url() } });+ assert.equal(again.ready, true);+ assert.equal(again.pageInitiated, false, 'A consumed reading cannot certify a later traversal');+ assert.deepEqual(Object.keys(again).sort(), ['documentToken', 'pageInitiated', 'ready', 'runToken'], 'Value-free reply');+ } finally { await f.context.close(); }+ });++ await t.test('a hash-only change is tolerated but is not proof', async () => {+ const f = await fixture(browserInstance, { script: "window.qaOnClick=()=>{location.hash='section-2';};" });+ try {+ const result = await f.agent.executeTool(17, 'click_ax', { ref_id: f.ref });+ assert.equal(result.success, true, JSON.stringify(result));+ assert.notEqual(result.observationInterrupted, true, JSON.stringify(result));+ assert.notEqual(result.outcomeUnknown, true, JSON.stringify(result));+ assert.notEqual(result.observedEffects?.includes('url'), true, JSON.stringify(result));+ assert.equal(routeOf(), '/current#section-2');+ assert.equal(presses().length, 1);+ } finally { await f.context.close(); }+ });++ // Only a route recorded for this press's own dispatch operation, at or+ // after the press, is tolerated (and, reached without Back, is proof).+ await t.test('a route recorded for another operation or before the press is not this press\'s', async () => {+ for (const variant of ['other-operation', 'before-press', 'own']) {+ const f = await fixture(browserInstance, {});+ let operationId = '';+ try {+ hooks.afterRelease = () => {+ const url = 'https://delivery-route.invalid/elsewhere';+ operationId = hooks.operationId;+ f.run.url = url;+ f.run.agentRoute = variant === 'other-operation' ? { at: Date.now(), url, operationId: 'another-operation' }+ : variant === 'before-press' ? { at: Date.now() - 60000, url, operationId } : { at: Date.now(), url, operationId };+ };+ const result = await f.agent.executeTool(17, 'click_ax', { ref_id: f.ref });+ assert.ok(operationId, 'The press ran under its own dispatch operation');+ assert.equal(presses().length, 1, `${variant}: ${JSON.stringify(result)}`);+ if (variant === 'own') {+ assert.equal(result.verified, true, `${variant}: ${JSON.stringify(result)}`);+ assert.ok(result.observedEffects?.includes('url'), `${variant}: ${JSON.stringify(result)}`);+ } else {+ assert.notEqual(result.verified, true, `${variant}: ${JSON.stringify(result)}`);+ assert.equal(result.outcomeUnknown, true, `${variant}: ${JSON.stringify(result)}`);+ assert.equal(result.observationInterrupted, true, `${variant}: ${JSON.stringify(result)}`);+ }+ } finally { hooks.afterRelease = null; await f.context.close(); }+ }+ });++ // The person presses the browser's Back while the press is observed.+ await t.test('the browser\'s own Back during observation keeps the outcome unverified', async () => {+ const f = await fixture(browserInstance, {});+ try {+ hooks.afterRelease = () => new Promise(resolve => setTimeout(resolve, 120)).then(() => page.goBack());+ const result = await f.agent.executeTool(17, 'click_ax', { ref_id: f.ref });+ await page.waitForTimeout(100);+ assert.equal(presses().length, 1, JSON.stringify(result));+ assert.equal(routeOf(), '/start');+ assert.notEqual(result.verified, true, JSON.stringify(result));+ assert.equal(result.outcomeUnknown, true, JSON.stringify(result));+ assert.equal(result.observationInterrupted, true, JSON.stringify(result));+ assert.equal(navigationSource(f.run), 'user');+ } finally { hooks.afterRelease = null; await f.context.close(); }+ });++ await t.test('a monitor injected after page scripts never certifies a page traversal', async () => {+ const f = await fixture(browserInstance, { script: 'window.qaOnClick=()=>setTimeout(()=>history.back(),150);', lateMonitor: true });+ try {+ const result = await f.agent.executeTool(17, 'click_ax', { ref_id: f.ref });+ assert.equal(presses().length, 1, JSON.stringify(result));+ assert.equal(routeOf(), '/start');+ assert.notEqual(result.verified, true, JSON.stringify(result));+ assert.equal(result.outcomeUnknown, true, JSON.stringify(result));+ assert.equal(navigationSource(f.run), 'user', 'It cannot rule out a Back the page hid from it');+ } finally { await f.context.close(); }+ });++ await t.test('a monitor re-injected while the document still loads never certifies a page traversal', async () => {+ const f = await fixture(browserInstance, { script: 'window.qaOnClick=()=>setTimeout(()=>history.back(),150);', reinjectWhileLoading: true });+ try {+ const result = await f.agent.executeTool(17, 'click_ax', { ref_id: f.ref });+ assert.equal(presses().length, 1, JSON.stringify(result));+ assert.equal(routeOf(), '/start');+ assert.notEqual(result.verified, true, JSON.stringify(result));+ assert.equal(result.outcomeUnknown, true, JSON.stringify(result));+ assert.equal(navigationSource(f.run), 'user', 'Page scripts ran before it and could have hidden a Back from it');+ } finally { await f.context.close(); }+ });++ // A reading that misses its deadline keeps the browser-UI attribution.+ await t.test('a late page traversal reading keeps the outcome unverified', async () => {+ const f = await fixture(browserInstance, { script: 'window.qaOnClick=()=>setTimeout(()=>history.back(),150);' });+ try {+ hooks.traversalReadingDelayMs = 900;+ const result = await f.agent.executeTool(17, 'click_ax', { ref_id: f.ref });+ assert.equal(presses().length, 1, JSON.stringify(result));+ assert.notEqual(result.verified, true, JSON.stringify(result));+ assert.equal(result.outcomeUnknown, true, JSON.stringify(result));+ assert.equal(navigationSource(f.run), 'user');+ } finally { await f.context.close(); }+ });++ await t.test('Stop while a traversal is read ends the observation at once', async () => {+ const f = await fixture(browserInstance, { script: 'window.qaOnClick=()=>setTimeout(()=>history.back(),100);' });+ try {+ hooks.traversalReadingDelayMs = 450;+ let stoppedAt = 0;+ hooks.afterRelease = () => new Promise(resolve => setTimeout(resolve, 300)).then(() => { stoppedAt = Date.now(); f.agent.abort(17); });+ const result = await f.agent.executeTool(17, 'click_ax', { ref_id: f.ref });+ const returnedAt = Date.now();+ assert.ok(stoppedAt > 0, JSON.stringify(result));+ assert.ok(returnedAt - stoppedAt < 300, `returned ${returnedAt - stoppedAt} ms after Stop`);+ assert.notEqual(result.verified, true, JSON.stringify(result));+ assert.equal(presses().length, 1);+ } finally { await f.context.close(); }+ });+ } finally {+ cdpClient.attach = cdpAttach;+ await browserInstance.close();+ }+});diff --git a/test/feedback-navigation-idle.mjs b/test/feedback-navigation-idle.mjsindex e73aca82d..c17a8cd4d 100644--- a/test/feedback-navigation-idle.mjs+++ b/test/feedback-navigation-idle.mjs@@ -163,6 +163,223 @@ for (const build of ['chrome', 'firefox']) {} finally { urls.delete(tab); agent._releaseRunEntry(tab); }});+ test(`${build}: a page script's own Back after an agent click is that click's effect, never the browser's Back`, async () => {+ const agent = makeAgent(Agent), tab = nextTab++, previous = api.tabs.sendMessage, asked = [];+ let reply = null;+ api.tabs.sendMessage = async (id, message, options) => {+ if (message.action !== 'page_monitor_traversal') return previous(id, message, options);+ asked.push({ params: message.params, frameId: options?.frameId });+ return reply(message);+ };+ await agent._claimRunEntry(tab, 'interactive');+ try {+ const send = bindMain(agent, tab), run = agent._pageFeedbackRuns.get(tab);+ const monitor = (pageInitiated, extra = {}) => message => ({ ready: true, runToken: message.params.runToken,+ documentToken: 'main-token', pageInitiated, ...extra });+ const navigation = () => [...run.events.values()].find(event => event.kind === 'navigation');+ // Each case starts from a clean run: no queued feedback, route or click marker.+ // A traversal reports its destination entry's original transition type.+ const back = async (label, { answer = monitor(true), click = true, arrange = () => {}, type = 'history',+ qualifiers = ['forward_back'], during = null } = {}) => {+ run.events.clear(); run.agentRoute = null; run.sameDocumentNavigation = null;+ if (click) send({ kind: 'activity', source: 'agent', operation: 'click' });+ arrange();+ reply = during ? async message => { await during(); return answer(message); } : answer;+ const userAt = run.lastUserAt, activityAt = run.lastActivityAt, at = Date.now();+ navigate(agent, tab, 0, type, 'https://app.example/' + label, { transitionType: 'typed', transitionQualifiers: qualifiers });+ assert.equal(navigation()?.source, 'user', `${label}: browser-UI attribution stands until the monitor answers`);+ assert.ok(run.lastUserAt >= at, `${label}: the traversal counts as user input meanwhile`);+ await agent._pageFeedbackTraversalSettled(run);+ return { userAt, activityAt, at };+ };+ let before = await back('posted');+ assert.deepEqual(asked.at(-1), { params: { runToken: run.token, url: 'https://app.example/posted' }, frameId: 0 });+ assert.equal(agent._hasPendingPageFeedback(tab), false, 'No feedback, idle wait or UI note for the click effect');+ assert.equal(run.lastUserAt, before.userAt, 'The withdrawn attribution does not renew the user idle gate');+ assert.equal(run.lastActivityAt, before.activityAt);+ assert.equal(run.agentRoute?.url, 'https://app.example/posted', 'The route is recorded as the agent action result');+ assert.equal(agent._pageFeedbackAgentRouteCurrent(tab, run, 0), false, 'Only the action in flight may claim it');+ assert.ok(run.traversedAt >= before.at, 'A route reached by Back/Forward is marked, so it is never proof');+ // Hash routes, and a destination first opened from the address bar, are read the same way.+ for (const [label, options] of [['hash-route', { type: 'fragment' }],+ ['address-bar-entry', { qualifiers: ['forward_back', 'from_address_bar'] }]]) {+ await back(label, options);+ assert.equal(navigation(), undefined, label);+ assert.equal(run.agentRoute?.url, 'https://app.example/' + label, label);+ }+ // A state restore while the reading is pending is the same click's effect, not user activity.+ await back('restored', { during: () => navigate(agent, tab, 0, 'history', 'https://app.example/restored?state=1') });+ assert.equal(navigation(), undefined);+ assert.equal(run.agentRoute?.url, 'https://app.example/restored?state=1', 'The later agent route stays current');+ // Nor is an embed the re-render inserts in a child frame meanwhile.+ await back('with-embed', { during: () => navigate(agent, tab, 1, 'committed', 'https://ads.example/slot?embed=1') });+ assert.equal([...run.events.values()].find(event => event.kind === 'navigation' && event.frameId === 0), undefined);+ assert.equal([...run.events.values()].find(event => event.kind === 'navigation' && event.frameId === 1)?.source, 'unknown',+ 'The child frame commit stays ordinary page churn');+ // The browser's Back button, an absent or stale monitor and a timeout keep user attribution.+ for (const [label, answer] of [['browser-back', monitor(false)], ['no-monitor', () => undefined],+ ['other-document', monitor(true, { documentToken: 'replaced-token' })], ['other-run', monitor(true, { runToken: 'old-run' })],+ ['silent', () => new Promise(() => {})]]) {+ await back(label, { answer });+ assert.equal(navigation()?.source, 'user', label);+ assert.equal(run.agentRoute, null, label);+ }+ // A state restore the page makes after the browser's Back is not the click's either.+ await back('browser-back-restore', { answer: monitor(false),+ during: () => navigate(agent, tab, 0, 'history', 'https://app.example/browser-back-restore?state=1') });+ assert.equal(navigation()?.source, 'user');+ assert.equal(navigation()?.after, 'https://app.example/browser-back-restore?state=1', 'The update ends where the page left it');+ assert.equal(run.agentRoute, null, 'Nothing credited to the click while the reading was pending survives');+ // Physical input before the monitor answers keeps the user attribution.+ await back('touched', { during: () => send({ kind: 'click', source: 'user', target: 'a#other' }) });+ assert.equal(navigation()?.source, 'user');+ // So does the browser's Back arriving while the page's own Back is read.+ const readings = asked.length;+ await back('interleaved', { during: () => navigate(agent, tab, 0, 'history', 'https://app.example/interleaved-browser-back',+ { transitionType: 'typed', transitionQualifiers: ['forward_back'] }) });+ assert.equal(navigation()?.source, 'user');+ assert.equal(asked.length, readings + 1, 'The merged Back is not read separately');+ assert.equal(run.agentRoute, null);+ // Without a fresh agent click, a page-initiated traversal is attributed like any page route update:+ // unattributed, unless it closely follows physical input or comes during a held gesture.+ before = await back('page-only', { click: false, arrange: () => { run.lastUserAt = 0; } });+ assert.equal(navigation()?.source, 'unknown');+ assert.equal(run.lastUserAt, before.userAt);+ assert.equal(run.agentRoute, null);+ before = await back('recent-input', { click: false, arrange: () => { run.lastUserAt = Date.now() - 1200; } });+ assert.equal(navigation()?.source, 'user', 'A page Back right after the person\'s own input is theirs');+ assert.equal(run.lastUserAt, before.userAt, 'It still does not renew the user time');+ await back('held-gesture', { click: false, arrange: () => { run.lastUserAt = 0; run.gestures.add(0); } });+ assert.equal(navigation()?.source, 'user');+ run.gestures.delete(0);+ await back('expired', { arrange: () => { run.lastUserAt = 0; run.sameDocumentNavigation.at -= 60000; } });+ assert.equal(navigation()?.source, 'unknown');+ // An unattributed page update merged into the reading keeps the navigation visible, as the page's+ // (no physical input in the last two seconds, so the update itself is not near-user).+ await back('merged', { arrange: () => { run.lastUserAt = 0; run.sameDocumentNavigation.at -= 60000; },+ during: () => navigate(agent, tab, 0, 'history', 'https://app.example/merged?page=1') });+ assert.equal(navigation()?.source, 'unknown');+ // An earlier unconsumed navigation is never erased by a later reading.+ const count = asked.length;+ run.events.clear(); run.sameDocumentNavigation = null;+ navigate(agent, tab, 0, 'history', 'https://app.example/without-click');+ send({ kind: 'activity', source: 'agent', operation: 'click' });+ reply = monitor(true);+ navigate(agent, tab, 0, 'history', 'https://app.example/coalesced', { transitionQualifiers: ['forward_back'] });+ await agent._pageFeedbackTraversalSettled(run);+ assert.equal(asked.length, count, 'A coalesced navigation is not re-attributed');+ assert.equal(navigation()?.source, 'user');+ // A full document replacement ends the recorded route.+ await back('before-commit');+ assert.ok(run.agentRoute);+ navigate(agent, tab, 0, 'committed', 'https://app.example/next-document');+ assert.equal(run.agentRoute, null);+ } finally { api.tabs.sendMessage = previous; urls.delete(tab); agent._releaseRunEntry(tab); }+ });++ test(`${build}: a traversal reading cannot outlive its run or hold Stop`, async () => {+ const agent = makeAgent(Agent), tab = nextTab++, previous = api.tabs.sendMessage;+ let answer;+ api.tabs.sendMessage = async (id, message, options) => message.action === 'page_monitor_traversal'+ ? new Promise(resolve => { answer = () => resolve({ ready: true, runToken: message.params.runToken, documentToken: 'main-token', pageInitiated: true }); })+ : previous(id, message, options);+ try {+ await agent._claimRunEntry(tab, 'interactive');+ let send = bindMain(agent, tab), run = agent._pageFeedbackRuns.get(tab);+ send({ kind: 'activity', source: 'agent', operation: 'click' });+ navigate(agent, tab, 0, 'history', 'https://app.example/stopped', { transitionQualifiers: ['forward_back'] });+ const started = Date.now();+ const waiting = agent._pageFeedbackTraversalSettled(run, agent._runAbortSignal(tab));+ agent.abort(tab);+ await assert.rejects(waiting, { name: 'AbortError' });+ assert.ok(Date.now() - started < 300, 'Stop does not wait for the monitor reading');+ agent._releaseRunEntry(tab);+ await agent._claimRunEntry(tab, 'interactive');+ send = bindMain(agent, tab); run = agent._pageFeedbackRuns.get(tab);+ send({ kind: 'activity', source: 'agent', operation: 'click' });+ navigate(agent, tab, 0, 'history', 'https://app.example/replaced', { transitionQualifiers: ['forward_back'] });+ const pending = run.traversalAttribution;+ agent._releaseRunEntry(tab);+ answer(); await pending.settled;+ assert.equal([...run.events.values()].find(event => event.kind === 'navigation')?.source, 'user',+ 'An ended run keeps what it observed');+ } finally { api.tabs.sendMessage = previous; urls.delete(tab); agent._releaseRunEntry(tab); }+ });++ test(`${build}: only the action in flight claims its route, and a route reached by Back is never its proof`, async () => {+ const agent = makeAgent(Agent), tab = nextTab++, previous = api.tabs.sendMessage, seen = [];+ api.tabs.sendMessage = async (id, message, options) => message.action === 'page_monitor_traversal'+ ? { ready: true, runToken: message.params.runToken, documentToken: 'main-token', pageInitiated: true }+ : previous(id, message, options);+ await agent._claimRunEntry(tab, 'interactive');+ try {+ const send = bindMain(agent, tab), run = agent._pageFeedbackRuns.get(tab);+ const claims = since => [agent._pageFeedbackAgentRouteCurrent(tab, run, since),+ agent._pageFeedbackAgentRouteCurrent(tab, run, since, { proof: true })];+ agent._executeToolWithLifecycle = async () => {+ const since = Date.now();+ // The monitor reports this press; the page pushes its next route.+ send({ kind: 'activity', source: 'agent', operation: 'click' });+ navigate(agent, tab, 0, 'history', 'https://app.example/pushed');+ seen.push(['pushed', ...claims(since), ...claims(Date.now() + 60000)]);+ // Then the page goes back by itself, as another frame's script could make it.+ navigate(agent, tab, 0, 'history', PAGE_URL, { transitionType: 'typed', transitionQualifiers: ['forward_back'] });+ await agent._pageFeedbackTraversalSettled(run);+ seen.push(['back', ...claims(since)]);+ return { success: true };+ };+ await agent.executeTool(tab, 'click', { text: 'Post' });+ assert.deepEqual(seen, [['pushed', true, true, false, false], ['back', true, false]],+ 'Tolerated while this action is in flight; a Back route is not proof; an earlier route is not this action\'s');+ assert.equal(agent._pageFeedbackAgentRouteCurrent(tab, run, 0), false, 'No later action can claim it');+ } finally { api.tabs.sendMessage = previous; urls.delete(tab); agent._releaseRunEntry(tab); }+ });++ test(`${build}: Firefox keeps every Back/Forward update the user's`, async () => {+ const agent = makeAgent(Agent), tab = nextTab++, previous = api.tabs.sendMessage, asked = [];+ api.tabs.sendMessage = async (id, message, options) => {+ if (message.action !== 'page_monitor_traversal') return previous(id, message, options);+ asked.push(message);+ return { ready: true, runToken: message.params.runToken, documentToken: 'main-token', pageInitiated: true };+ };+ // Whether Gecko reports its own Back button as userInitiated is unverified.+ api.runtime.getBrowserInfo = async () => ({ name: 'Firefox' });+ await agent._claimRunEntry(tab, 'interactive');+ try {+ const send = bindMain(agent, tab), run = agent._pageFeedbackRuns.get(tab);+ send({ kind: 'activity', source: 'agent', operation: 'click' });+ navigate(agent, tab, 0, 'history', 'https://app.example/firefox-back', { transitionType: 'typed', transitionQualifiers: ['forward_back'] });+ assert.equal(run.traversalAttribution ?? null, null, 'No reading starts');+ await agent._pageFeedbackTraversalSettled(run);+ await new Promise(resolve => setTimeout(resolve, 20));+ assert.equal(asked.length, 0);+ assert.equal([...run.events.values()].find(event => event.kind === 'navigation')?.source, 'user');+ assert.equal(run.agentRoute ?? null, null);+ } finally { delete api.runtime.getBrowserInfo; api.tabs.sendMessage = previous; urls.delete(tab); agent._releaseRunEntry(tab); }+ });++ test(`${build}: feedback a reading withdraws while it is applied is not delivered empty`, async () => {+ const agent = makeAgent(Agent), tab = nextTab++, previous = api.tabs.sendMessage, updates = [];+ api.tabs.sendMessage = async (id, message, options) => message.action === 'page_monitor_traversal'+ ? new Promise(resolve => setTimeout(() => resolve({ ready: true, runToken: message.params.runToken,+ documentToken: 'main-token', pageInitiated: true }), 40))+ : previous(id, message, options);+ // The reading answers during the idle wait that the traversal itself opened.+ agent._pageFeedbackIdleMs = 200;+ await agent._claimRunEntry(tab, 'interactive');+ try {+ const send = bindMain(agent, tab), run = agent._pageFeedbackRuns.get(tab);+ send({ kind: 'activity', source: 'agent', operation: 'click' });+ navigate(agent, tab, 0, 'history', 'https://app.example/withdrawn', { transitionType: 'typed', transitionQualifiers: ['forward_back'] });+ assert.equal(agent._hasPendingPageFeedback(tab), true, 'The browser-UI attribution stands meanwhile');+ const messages = [];+ assert.equal(await agent._applyPendingPageFeedback(tab, messages, (type, data) => updates.push({ type, data })), false);+ assert.deepEqual(messages, [], 'No empty browser state update');+ assert.equal(updates.some(update => update.type === 'page_feedback'), false);+ assert.equal(run.agentRoute?.url, 'https://app.example/withdrawn');+ } finally { api.tabs.sendMessage = previous; urls.delete(tab); agent._releaseRunEntry(tab); }+ });+test(`${build}: an SPA button route change costs no idle wait, supersession or navigation note`, async () => {const tab = nextTab++, updates = [], dispatched = [];let agent, send, requests = 0;diff --git a/test/quality/mastodon-reply-route-mv3.mjs b/test/quality/mastodon-reply-route-mv3.mjsnew file mode 100644index 000000000..ba6dfb570--- /dev/null+++ b/test/quality/mastodon-reply-route-mv3.mjs@@ -0,0 +1,242 @@+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';+import { conformFixtureCompletionCall } from './completion-provider-contract.mjs';+import { fixedChoiceQuestion, fixturePageTextReply } from '../semantic-decision-stub.mjs';++// Mastodon's single-column layout (narrow windows) routes a toot's Reply+// button to /publish with history.pushState, and after a successful submit+// the composer calls history.back(). Both route changes are the clicks' own+// effects. They used to be reported as "Observation interrupted ... outcome+// unknown", so a model re-posted the same reply and never reached the next+// toot. The extension, browser dispatch, page monitor, webNavigation events+// and completion gates are real; provider and site requests stay local.+const out = path.resolve(process.env.WEBBRAIN_QUALITY_ARTIFACTS || 'ci/artifacts/quality-audit-2026-10-16/mastodon-reply-route-mv3');+await fs.mkdir(out, { recursive: true });+const origin = 'https://mastoturk.org';+const account = 'webbrain_qa_owned';+const statuses = [+ { id: '117439857549626876', author: 'shifthaber', name: 'Shift Haber', text: 'Owned QA review of a hybrid tank SUV.' },+ { id: '117439857549626999', author: 'qa_quotes', name: 'QA Quotes', text: 'Owned QA quote about economic victories.' },+];+const replyText = '@shifthaber Owned QA reply: what a ride.';+const task = `Reply to the Shift Haber toot in my favourites with exactly this text: "${replyText}". Post only that one reply and verify it under the toot.`;+const intent = { request_kind: 'execute', scope_relation: 'new', requires_state_change: true,+ requires_submission: true, messaging: null, deliverables: ['One exact reply under the Shift Haber toot, verified.'],+ allows_planner_shaped_result: false, allows_app_state_tool_evidence: false,+ completion_requirements: { download: false }, read_scope: 'visible_page',+ summary: 'Reply once to the Shift Haber toot and verify the reply.',+ steps: [{ id: '1', action: 'Open the reply composer, enter the exact reply, post it once and verify it in the thread.' }],+ memory: { use_progress_ledger: false, progress_action: null }, scheduling: null, risks: [] };+const posts = [], providerRequests = [], toolResults = [];+let actionCalls = 0, judgeCalls = 0, authorizationCalls = 0, blockedRemote = 0;+const completionRecovery = { reads: 0 };+const textOf = content => typeof content === 'string' ? content : Array.isArray(content)+ ? content.filter(part => part?.type === 'text').map(part => part.text || '').join('\n') : '';+const toolData = message => {+ const content = textOf(message.content);+ try { return JSON.parse(content); } catch {}+ try { return JSON.parse(content.slice(content.indexOf('{'), content.lastIndexOf('}') + 1)); } catch { return null; }+};+const refFor = (input, pattern) => {+ for (const message of [...input.messages].reverse()) {+ if (message.role !== 'tool') continue;+ const line = String(toolData(message)?.pageContent || '').split('\n').find(line => pattern.test(line));+ const ref = line?.match(/\[(ref_\d+)\]/)?.[1];+ if (ref) return ref;+ }+ throw new Error(`The owned fixture did not observe ${pattern}`);+};+const server = http.createServer(async (request, response) => {+ if (request.url !== '/v1/chat/completions') { response.writeHead(404).end(); return; }+ let raw = ''; for await (const part of request) raw += part;+ const input = JSON.parse(raw); providerRequests.push(input);+ await new Promise(resolve => setTimeout(resolve, 60));+ const system = textOf(input.messages?.[0]?.content);+ let completion;+ if (system.startsWith('Evaluate only the observable requirements of the genuine user task')) {+ judgeCalls++;+ completion = { role: 'assistant', content: JSON.stringify({ outcome: 'succeeded',+ reason: 'The fresh thread shows exactly one owned reply with the requested text under the Shift Haber toot.' }) };+ } else if (system.startsWith('Identify only the exact plain public Mastodon post authorized by the genuine user task.')) {+ completion = { role: 'assistant', content: JSON.stringify({ kind: 'unsupported', body: null, account: null }) };+ } else if (system.startsWith('Check one separately proposed consequential action')) {+ authorizationCalls++;+ const latest = JSON.parse(textOf(input.messages[1].content)).latestAcceptedRequest;+ const untrusted = textOf(input.messages.at(-1).content);+ const { key } = JSON.parse(untrusted.slice(untrusted.indexOf('{'), untrusted.lastIndexOf('}') + 1));+ completion = { role: 'assistant', content: JSON.stringify({ key, authorized: true, latestRequestEvidence: latest }) };+ } else if (fixturePageTextReply(input.messages)) {+ completion = { role: 'assistant', content: fixturePageTextReply(input.messages) };+ } else if (fixedChoiceQuestion(input.messages)) {+ completion = { role: 'assistant', content: JSON.stringify({ choice: '', evidence: '' }) };+ } else if (!input.tools?.length) completion = { role: 'assistant', content: JSON.stringify(intent) };+ else {+ for (const message of input.messages) {+ if (message.role === 'tool' && !toolResults.some(entry => entry.id === message.tool_call_id)) {+ toolResults.push({ id: message.tool_call_id, result: toolData(message) });+ }+ }+ const step = actionCalls++;+ const read = { name: 'get_accessibility_tree', args: { filter: 'all' } };+ const call = step === 1 ? { name: 'click_ax', args: { ref_id: refFor(input, /button "Reply to Shift Haber"/) } }+ : step === 3 ? { name: 'set_field', args: { ref_id: refFor(input, /textbox "Reply text"/), text: replyText, clear: true } }+ : step === 4 ? { name: 'click_ax', args: { ref_id: refFor(input, /button "Post reply"/) } }+ : step === 6 ? { name: 'navigate', args: { url: `${origin}/@shifthaber/${statuses[0].id}` } }+ : step >= 8 ? { name: 'done', args: { outcome: 'success', summary: `Posted one reply "${replyText}" under the Shift Haber toot and verified it in the thread.` } }+ : read;+ const emitted = conformFixtureCompletionCall(input, call, completionRecovery);+ completion = { role: 'assistant', content: '', tool_calls: [{ id: `owned-reply-${step}`, type: 'function',+ function: { name: emitted.name, arguments: JSON.stringify(emitted.args) } }] };+ }+ response.writeHead(200, { 'Content-Type': 'application/json' });+ response.end(JSON.stringify({ id: `response-${providerRequests.length}`, choices: [{ message: completion,+ finish_reason: completion.tool_calls ? 'tool_calls' : 'stop' }], usage: { prompt_tokens: 100, completion_tokens: 30 } }));+});+await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));+// One document serves every route. Like Mastodon's single-column UI, the app+// renders by location.pathname and moves between columns with the History API.+const pageBody = () => `<!doctype html><meta charset="utf-8"><title>MastoTurk</title>+<style>body{font:18px sans-serif;margin:20px;width:700px}.status{margin:16px 0;padding:10px;border:1px solid #999}textarea{display:block;width:640px;height:100px}button{padding:10px;margin:4px}</style>+<div class="navigation-panel"><a class="account__display-name" href="/@${account}">@${account}</a> <a href="/favourites">Favourites</a></div>+<main id="app"></main>+<script>+const statuses = ${JSON.stringify(statuses)};+const replies = ${JSON.stringify(posts.map(post => ({ inReplyTo: post.in_reply_to_id, text: post.status })))};+const esc = text => String(text).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);+let replyTo = null;+const card = status => '<article class="status"><a class="status__relative-time" href="/@' + status.author + '/' + status.id + '">1d</a> '+ + '<a class="status__display-name" href="/@' + status.author + '">' + esc(status.name) + '</a>'+ + '<div class="status__content__text status__content__text--visible"><p>' + esc(status.text) + '</p></div>'+ + '<div class="status__action-bar"><button type="button" class="icon-button" data-reply="' + status.id + '" aria-label="Reply to ' + esc(status.name) + '">Reply</button>'+ + '<button type="button" class="icon-button" aria-label="Unfavourite ' + esc(status.name) + '">Unfavourite</button></div></article>';+function render() {+ const app = document.getElementById('app');+ const permalink = location.pathname.match(/^\\/@([a-z0-9_]+)\\/(\\d+)$/);+ if (location.pathname === '/publish' && replyTo) {+ app.innerHTML = '<h1>New post</h1><div class="compose-form__reply-indicator">Replying to ' + esc(replyTo.name) + ': ' + esc(replyTo.text) + '</div>'+ + '<form class="compose-form"><textarea class="autosuggest-textarea__textarea" aria-label="Reply text"></textarea>'+ + '<div class="compose-form__submit"><button type="submit">Post reply</button></div></form>';+ const composer = app.querySelector('textarea');+ composer.value = '@' + replyTo.author + ' ';+ app.querySelector('form').onsubmit = async event => {+ event.preventDefault();+ const response = await fetch('/api/v1/statuses', { method: 'POST', headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ status: composer.value, in_reply_to_id: replyTo.id, visibility: 'public' }) });+ if (!response.ok) return;+ replyTo = null;+ // Mastodon returns to the previous column after a reply from /publish.+ history.back();+ };+ } else if (permalink) {+ const status = statuses.find(item => item.id === permalink[2]);+ app.innerHTML = '<h1>Thread</h1>' + (status ? card(status) : '<p>Not found</p>') + replies.filter(reply => reply.inReplyTo === permalink[2])+ .map(reply => '<article class="status reply"><a class="status__display-name" href="/@${account}">@${account}</a><p>' + esc(reply.text) + '</p></article>').join('');+ } else {+ app.innerHTML = '<h1>Favourites</h1>' + statuses.map(card).join('');+ }+}+document.addEventListener('click', event => {+ const button = event.target.closest('button[data-reply]');+ if (!button) return;+ replyTo = statuses.find(status => status.id === button.dataset.reply);+ history.pushState({ compose: true }, '', '/publish');+ render();+});+// Like many SPAs, restore column state right after a traversal.+window.addEventListener('popstate', () => { render(); history.replaceState({ restored: true }, '', location.href); });+render();+</script>`;+const profile = await fs.mkdtemp(path.join(os.tmpdir(), 'webbrain-mastodon-reply-mv3-'));+let context;+try {+ const extension = path.join(profile, 'extension');+ await fs.cp(path.resolve('src/chrome'), extension, { recursive: true });+ context = await chromium.launchPersistentContext(profile, { headless: true, channel: 'chromium',+ viewport: { width: 1017, height: 745 },+ args: [`--disable-extensions-except=${extension}`, `--load-extension=${extension}`,+ '--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1'] });+ await context.route('**/*', async route => {+ const request = route.request(), requested = new URL(request.url());+ if (requested.hostname === '127.0.0.1' && requested.port === String(server.address().port)) return route.continue();+ if (requested.origin === origin) {+ if (requested.pathname === '/api/v1/statuses' && request.method() === 'POST') {+ posts.push(request.postDataJSON());+ // A real network round trip: the composer leaves /publish only after it.+ await new Promise(resolve => setTimeout(resolve, 150));+ return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ id: String(200 + posts.length) }) });+ }+ if (request.isNavigationRequest() && request.method() === 'GET') return route.fulfill({ contentType: 'text/html', body: pageBody() });+ return route.fulfill({ status: 404, body: '' });+ }+ if (/^https?:$/.test(requested.protocol)) { blockedRemote++; return route.abort('blockedbyclient'); }+ return route.continue();+ });+ const worker = context.serviceWorkers()[0] || await context.waitForEvent('serviceworker', { timeout: 30_000 });+ await worker.evaluate(() => {+ const send = fetch.bind(globalThis);+ globalThis.fetch = (input, options) => {+ const requested = new URL(typeof input === 'string' ? input : input.url);+ if (requested.hostname === '127.0.0.1' || ['chrome-extension:', 'data:', 'blob:'].includes(requested.protocol)) return send(input, options);+ return Promise.reject(new Error('The owned reply fixture blocks external network requests.'));+ };+ });+ const harness = await context.newPage();+ await harness.goto(`chrome-extension://${new URL(worker.url()).host}/src/ui/settings.html`);+ const message = (action, data = {}) => harness.evaluate(({ action, data }) => chrome.runtime.sendMessage({ target: 'background', action, ...data }), { action, data });+ await harness.evaluate(() => chrome.storage.local.set({ helpImproveWebBrain: false, tracingEnabled: false,+ autoScreenshot: false, screenshotFallback: false, planBeforeActMode: 'off', planBeforeAct: false,+ planReviewMode: 'never', maxAgentSteps: 14, systemOneEnabled: false, agentAllowLocalNetwork: true,+ askBeforeConsequentialActions: false, openaiAskStreamingEnabled: false }));+ assert.equal((await message('update_provider', { providerId: 'openrouter', config: { apiKey: 'owned-fixture-fake-key',+ baseUrl: `http://127.0.0.1:${server.address().port}/v1`, model: 'minimax/minimax-m3', enabled: true,+ contextWindow: 1000000, supportsAskStreaming: false } })).ok, true);+ assert.equal((await message('set_active_provider', { providerId: 'openrouter' })).ok, true);+ const page = await context.newPage();+ await page.goto(`${origin}/favourites`);+ const tabId = await harness.evaluate(async url => (await chrome.tabs.query({})).find(tab => tab.url === url)?.id, `${origin}/favourites`);+ let watchdog;+ const result = await Promise.race([+ message('chat', { tabId, text: task, mode: 'act', requestId: 'owned-mastodon-reply', locale: 'en' }),+ new Promise((_, reject) => { watchdog = setTimeout(() => reject(new Error(`The reply run did not finish; provider requests: ${providerRequests.length}, actions: ${actionCalls}`)), 150_000); }),+ ]).finally(() => clearTimeout(watchdog));+ const results = result.updates.filter(event => event.type === 'tool_result');+ await fs.writeFile(path.join(out, 'evidence.json'), JSON.stringify({ result, posts, judgeCalls, authorizationCalls,+ toolResults, providerRequests, blockedRemote }, (_key, value) => typeof value === 'string' && value.startsWith('data:image/') ? '[owned fixture screenshot omitted]' : value, 2));+ const clicks = results.filter(event => event.data?.name === 'click_ax').map(event => event.data.result);+ assert.equal(clicks.length, 2, JSON.stringify(results.map(event => event.data?.name)));+ const [openReply, postReply] = clicks;+ // The Reply button's pushState to /publish is that click's observed effect.+ assert.equal(openReply.success, true, JSON.stringify(openReply));+ assert.notEqual(openReply.outcomeUnknown, true, JSON.stringify(openReply));+ assert.equal(openReply.verified, true, JSON.stringify(openReply));+ if (openReply.method === 'cdp-native-button') assert.ok(openReply.observedEffects?.includes('url'), JSON.stringify(openReply));+ // The composer's own history.back() after its POST is not a user Back+ // press. The trusted submit accepts that route as its effect, but a route+ // reached by Back is never its proof (any frame's script can go back), so+ // the press is delivered and awaits a fresh observation: never interrupted+ // or unknown.+ assert.equal(postReply.method, 'cdp-native-button', JSON.stringify(postReply));+ assert.equal(postReply.success, true, JSON.stringify(postReply));+ assert.notEqual(postReply.outcomeUnknown, true, JSON.stringify(postReply));+ assert.notEqual(postReply.observationInterrupted, true, JSON.stringify(postReply));+ assert.notEqual(postReply.observedEffects?.includes('url'), true, JSON.stringify(postReply));+ assert.ok(postReply.verified === true || postReply.effectVerificationPending === true, JSON.stringify(postReply));+ assert.equal(result.updates.some(event => event.type === 'page_feedback' && event.data?.navigation && event.data.source === 'user'), false,+ 'No route change of this run is reported as the user\'s navigation');+ assert.deepEqual(posts, [{ status: replyText, in_reply_to_id: statuses[0].id, visibility: 'public' }], 'Exactly one reply is posted.');+ const done = results.findLast(event => event.data?.name === 'done')?.data?.result;+ assert.equal(done?.done, true, JSON.stringify(done));+ assert.equal(done?.outcome, 'success', JSON.stringify(done));+ console.log(JSON.stringify({ passed: true, installedMV3: true, openReplyMethod: openReply.method, posts: posts.length, openReplyEffects: openReply.observedEffects,+ postReplyMethod: postReply.method, postReplyEffects: postReply.observedEffects || null, postReplyVerified: postReply.verified === true,+ judgeCalls, authorizationCalls, blockedRemote }));+} finally {+ await context?.close(); await new Promise(resolve => server.close(resolve));+ const resolved = path.resolve(profile);+ if (!resolved.startsWith(path.resolve(os.tmpdir()) + path.sep + 'webbrain-mastodon-reply-mv3-')) throw new Error('Unexpected temporary profile path.');+ await fs.rm(resolved, { recursive: true, force: true });+}